From 9bbdef224ddfa9e237b05a682b3ff12ea49beb65 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 15 Jul 2023 09:23:48 -0400 Subject: [PATCH] Project cleanup pre merge. --- README.md | 17 +- src/discord/ChatChannel.java | 2 +- src/discord/DiscordAccount.java | 2 + src/discord/MagicBot.java | 297 +- src/discord/handlers/ChatChannelHandler.java | 9 +- src/discord/handlers/DevRequestHandler.java | 27 +- .../handlers/RegisterAccountHandler.java | 18 +- .../handlers/StatusRequestHandler.java | 2 +- src/discord/handlers/TrashRequestHandler.java | 2 +- src/engine/Enum.java | 5576 ++++---- src/engine/InterestManagement/HeightMap.java | 334 +- .../InterestManagement/InterestManager.java | 246 +- src/engine/InterestManagement/RealmMap.java | 2 +- src/engine/InterestManagement/WorldGrid.java | 552 +- src/engine/ai/MobileFSM.java | 135 +- src/engine/ai/MobileFSMManager.java | 7 +- src/engine/ai/utilities/CombatUtilities.java | 2 +- src/engine/core/ControlledRunnable.java | 305 +- src/engine/db/archive/BaneRecord.java | 504 +- src/engine/db/archive/CharacterRecord.java | 3 +- src/engine/db/archive/CityRecord.java | 205 +- src/engine/db/archive/DataRecord.java | 1 - src/engine/db/archive/DataWarehouse.java | 44 +- src/engine/db/archive/GuildRecord.java | 311 +- src/engine/db/archive/MineRecord.java | 6 +- src/engine/db/archive/PvpRecord.java | 417 +- src/engine/db/archive/RealmRecord.java | 7 +- src/engine/db/handlers/dbBoonHandler.java | 36 +- .../db/handlers/dbCSSessionHandler.java | 124 +- .../db/handlers/dbCharacterSkillHandler.java | 204 +- src/engine/db/handlers/dbContractHandler.java | 208 +- .../db/handlers/dbEffectsBaseHandler.java | 500 +- src/engine/db/handlers/dbItemBaseHandler.java | 226 +- .../db/handlers/dbWarehouseHandler.java | 748 +- src/engine/db/handlers/dbZoneHandler.java | 150 +- src/engine/devcmd/AbstractDevCmd.java | 124 +- src/engine/devcmd/cmds/AddBuildingCmd.java | 192 +- src/engine/devcmd/cmds/AddGoldCmd.java | 83 +- src/engine/devcmd/cmds/AddMobCmd.java | 155 +- src/engine/devcmd/cmds/AddNPCCmd.java | 159 +- src/engine/devcmd/cmds/ApplyBonusCmd.java | 248 +- src/engine/devcmd/cmds/ApplyStatModCmd.java | 215 +- .../devcmd/cmds/AuditFailedItemsCmd.java | 209 +- src/engine/devcmd/cmds/AuditHeightMapCmd.java | 55 +- src/engine/devcmd/cmds/AuditMobsCmd.java | 151 +- src/engine/devcmd/cmds/BoundsCmd.java | 106 +- src/engine/devcmd/cmds/ChangeNameCmd.java | 182 +- src/engine/devcmd/cmds/CombatMessageCmd.java | 57 +- src/engine/devcmd/cmds/CreateItemCmd.java | 57 +- src/engine/devcmd/cmds/DebugCmd.java | 205 +- src/engine/devcmd/cmds/DebugMeleeSyncCmd.java | 69 +- src/engine/devcmd/cmds/DecachePlayerCmd.java | 48 +- src/engine/devcmd/cmds/DespawnCmd.java | 91 +- src/engine/devcmd/cmds/DistanceCmd.java | 85 +- src/engine/devcmd/cmds/EffectCmd.java | 62 +- src/engine/devcmd/cmds/EnchantCmd.java | 133 +- src/engine/devcmd/cmds/FindBuildingsCmd.java | 164 +- src/engine/devcmd/cmds/FlashMsgCmd.java | 65 +- src/engine/devcmd/cmds/GateInfoCmd.java | 127 +- src/engine/devcmd/cmds/GetBankCmd.java | 34 +- src/engine/devcmd/cmds/GetCacheCountCmd.java | 24 +- src/engine/devcmd/cmds/GetHeightCmd.java | 41 +- src/engine/devcmd/cmds/GetMemoryCmd.java | 71 +- src/engine/devcmd/cmds/GetMobBaseLoot.java | 41 +- src/engine/devcmd/cmds/GetOffsetCmd.java | 79 +- .../devcmd/cmds/GetRuneDropRateCmd.java | 33 +- src/engine/devcmd/cmds/GetVaultCmd.java | 32 +- src/engine/devcmd/cmds/GetZoneCmd.java | 71 +- src/engine/devcmd/cmds/GetZoneMobsCmd.java | 116 +- src/engine/devcmd/cmds/GotoBoundsCmd.java | 159 +- src/engine/devcmd/cmds/GotoCmd.java | 307 +- src/engine/devcmd/cmds/GotoObj.java | 151 +- src/engine/devcmd/cmds/HeartbeatCmd.java | 35 +- src/engine/devcmd/cmds/HelpCmd.java | 34 +- src/engine/devcmd/cmds/HotzoneCmd.java | 2 +- src/engine/devcmd/cmds/InfoCmd.java | 1001 +- src/engine/devcmd/cmds/JumpCmd.java | 124 +- src/engine/devcmd/cmds/MBDropCmd.java | 156 +- src/engine/devcmd/cmds/MakeBaneCmd.java | 339 +- src/engine/devcmd/cmds/MakeItemCmd.java | 442 +- src/engine/devcmd/cmds/NetDebugCmd.java | 114 +- src/engine/devcmd/cmds/PrintBankCmd.java | 90 +- src/engine/devcmd/cmds/PrintBonusesCmd.java | 125 +- src/engine/devcmd/cmds/PrintEquipCmd.java | 146 +- src/engine/devcmd/cmds/PrintInventoryCmd.java | 175 +- src/engine/devcmd/cmds/PrintLocationCmd.java | 69 +- src/engine/devcmd/cmds/PrintPowersCmd.java | 72 +- src/engine/devcmd/cmds/PrintResistsCmd.java | 92 +- src/engine/devcmd/cmds/PrintSkillsCmd.java | 78 +- src/engine/devcmd/cmds/PrintStatsCmd.java | 256 +- src/engine/devcmd/cmds/PrintVaultCmd.java | 90 +- src/engine/devcmd/cmds/PullCmd.java | 140 +- src/engine/devcmd/cmds/PurgeObjectsCmd.java | 417 +- src/engine/devcmd/cmds/RealmInfoCmd.java | 83 +- src/engine/devcmd/cmds/RebootCmd.java | 42 +- src/engine/devcmd/cmds/RegionCmd.java | 103 +- src/engine/devcmd/cmds/RemoveBaneCmd.java | 65 +- src/engine/devcmd/cmds/RemoveObjectCmd.java | 464 +- src/engine/devcmd/cmds/RenameCmd.java | 88 +- src/engine/devcmd/cmds/ResetLevelCmd.java | 37 +- src/engine/devcmd/cmds/RotateCmd.java | 442 +- src/engine/devcmd/cmds/SetAICmd.java | 190 +- src/engine/devcmd/cmds/SetAdminRuneCmd.java | 100 +- src/engine/devcmd/cmds/SetBaneActiveCmd.java | 95 +- src/engine/devcmd/cmds/SetBaseClassCmd.java | 72 +- .../devcmd/cmds/SetBuildingAltitudeCmd.java | 81 +- .../devcmd/cmds/SetForceRenameCityCmd.java | 55 +- src/engine/devcmd/cmds/SetGuildCmd.java | 120 +- src/engine/devcmd/cmds/SetHealthCmd.java | 69 +- src/engine/devcmd/cmds/SetInvulCmd.java | 129 +- src/engine/devcmd/cmds/SetLevelCmd.java | 90 +- src/engine/devcmd/cmds/SetMaintCmd.java | 49 +- src/engine/devcmd/cmds/SetManaCmd.java | 78 +- src/engine/devcmd/cmds/SetNpcEquipSetCmd.java | 164 +- src/engine/devcmd/cmds/SetNpcMobbaseCmd.java | 79 +- src/engine/devcmd/cmds/SetNpcNameCmd.java | 72 +- src/engine/devcmd/cmds/SetOwnerCmd.java | 139 +- .../devcmd/cmds/SetPromotionClassCmd.java | 88 +- src/engine/devcmd/cmds/SetRankCmd.java | 240 +- src/engine/devcmd/cmds/SetRuneCmd.java | 94 +- src/engine/devcmd/cmds/SetStaminaCmd.java | 69 +- src/engine/devcmd/cmds/SetSubRaceCmd.java | 351 +- src/engine/devcmd/cmds/ShowOffsetCmd.java | 69 +- src/engine/devcmd/cmds/SlotTestCmd.java | 93 +- src/engine/devcmd/cmds/SplatMobCmd.java | 189 +- src/engine/devcmd/cmds/SqlDebugCmd.java | 114 +- src/engine/devcmd/cmds/SummonCmd.java | 173 +- src/engine/devcmd/cmds/SysMsgCmd.java | 70 +- src/engine/devcmd/cmds/TeleportModeCmd.java | 68 +- .../devcmd/cmds/UnloadFurnitureCmd.java | 95 +- src/engine/devcmd/cmds/ZoneInfoCmd.java | 235 +- src/engine/devcmd/cmds/aiInfoCmd.java | 30 +- src/engine/devcmd/cmds/convertLoc.java | 49 +- src/engine/devcmd/cmds/simulateBootyCmd.java | 22 +- .../exception/FactoryBuildException.java | 26 +- src/engine/exception/MBServerException.java | 32 +- src/engine/exception/MsgSendException.java | 28 +- .../exception/SerializationException.java | 28 +- src/engine/gameManager/BuildingManager.java | 109 +- src/engine/gameManager/ChatManager.java | 69 +- src/engine/gameManager/CombatManager.java | 304 +- src/engine/gameManager/ConfigManager.java | 9 +- src/engine/gameManager/DbManager.java | 553 +- src/engine/gameManager/DevCmdManager.java | 395 +- src/engine/gameManager/GroupManager.java | 21 +- src/engine/gameManager/GuildManager.java | 332 +- .../gameManager/MaintenanceManager.java | 2 +- src/engine/gameManager/MovementManager.java | 895 +- src/engine/gameManager/NPCManager.java | 1 - src/engine/gameManager/PowersManager.java | 5232 ++++---- src/engine/gameManager/SessionManager.java | 509 +- src/engine/gameManager/SimulationManager.java | 341 +- src/engine/gameManager/TradeManager.java | 74 +- src/engine/job/AbstractJob.java | 258 +- src/engine/job/AbstractJobStatistics.java | 202 +- src/engine/job/AbstractScheduleJob.java | 22 +- src/engine/job/ClassJobStatistics.java | 8 +- src/engine/job/JobContainer.java | 118 +- src/engine/job/JobManager.java | 406 +- src/engine/job/JobPool.java | 530 +- src/engine/job/JobScheduler.java | 300 +- src/engine/job/JobWorker.java | 178 +- src/engine/jobs/AbstractEffectJob.java | 266 +- src/engine/jobs/ActivateBaneJob.java | 4 +- src/engine/jobs/AttackJob.java | 45 +- src/engine/jobs/BasicScheduledJob.java | 166 +- src/engine/jobs/BonusCalcJob.java | 2 +- src/engine/jobs/CSessionCleanupJob.java | 20 +- src/engine/jobs/ChantJob.java | 143 +- src/engine/jobs/CloseGateJob.java | 42 +- src/engine/jobs/DamageOverTimeJob.java | 134 +- src/engine/jobs/DatabaseUpdateJob.java | 77 +- src/engine/jobs/DeferredPowerJob.java | 118 +- src/engine/jobs/DoorCloseJob.java | 10 +- src/engine/jobs/EndFearJob.java | 14 +- src/engine/jobs/FinishSpireEffectJob.java | 6 +- src/engine/jobs/FinishSummonsJob.java | 84 +- src/engine/jobs/LoadEffectsJob.java | 36 +- src/engine/jobs/LogoutCharacterJob.java | 10 +- src/engine/jobs/PersistentAoeJob.java | 123 +- src/engine/jobs/RefreshGroupJob.java | 16 +- src/engine/jobs/RemoveCorpseJob.java | 4 +- src/engine/jobs/SiegeSpireWithdrawlJob.java | 115 +- src/engine/jobs/SummonSendJob.java | 8 +- src/engine/jobs/TeleportJob.java | 10 +- src/engine/jobs/TrackJob.java | 34 +- src/engine/jobs/TransferStatOTJob.java | 104 +- src/engine/jobs/UpdateGroupJob.java | 8 +- src/engine/jobs/UpgradeBuildingJob.java | 50 +- src/engine/jobs/UpgradeNPCJob.java | 56 +- src/engine/jobs/UseItemJob.java | 2 +- src/engine/loot/LootManager.java | 191 +- src/engine/math/Bounds.java | 953 +- src/engine/math/FastMath.java | 1266 +- src/engine/math/Matrix3f.java | 2327 ++-- src/engine/math/Matrix4f.java | 3435 +++-- src/engine/math/Quaternion.java | 2386 ++-- src/engine/math/Vector2f.java | 1211 +- src/engine/math/Vector3f.java | 2182 ++-- src/engine/math/Vector3fImmutable.java | 993 +- src/engine/net/AbstractConnection.java | 777 +- src/engine/net/AbstractConnectionManager.java | 1342 +- src/engine/net/AbstractNetMsg.java | 41 +- src/engine/net/ByteBufferReader.java | 638 +- src/engine/net/ByteBufferWriter.java | 316 +- src/engine/net/CheckNetMsgFactoryJob.java | 68 +- src/engine/net/Dispatch.java | 72 +- src/engine/net/DispatchMessage.java | 386 +- src/engine/net/ItemProductionManager.java | 157 +- src/engine/net/ItemQueue.java | 106 +- src/engine/net/MessageDispatcher.java | 114 +- src/engine/net/NetMsgFactory.java | 776 +- src/engine/net/NetMsgStat.java | 6 +- src/engine/net/Network.java | 2 +- .../net/client/ClientAuthenticator.java | 52 +- src/engine/net/client/ClientConnection.java | 630 +- src/engine/net/client/ClientMessagePump.java | 3595 +++--- src/engine/net/client/Protocol.java | 5 +- .../handlers/AbandonAssetMsgHandler.java | 335 +- .../handlers/AbstractClientMsgHandler.java | 43 +- .../handlers/AcceptInviteToGuildHandler.java | 105 +- .../handlers/AcceptSubInviteHandler.java | 106 +- .../handlers/ActivateNPCMsgHandler.java | 154 +- .../handlers/AllianceChangeMsgHandler.java | 176 +- .../handlers/AllyEnemyListMsgHandler.java | 69 +- .../handlers/ArcLoginNotifyMsgHandler.java | 176 +- .../ArcMineWindowAvailableTimeHandler.java | 2 +- .../handlers/ArcSiegeSpireMsgHandler.java | 140 +- .../ArcViewAssetTransactionsMsgHandler.java | 6 +- .../handlers/AssetSupportMsgHandler.java | 311 +- .../handlers/BanishUnbanishHandler.java | 187 +- .../client/handlers/BreakFealtyHandler.java | 225 +- .../handlers/ChangeAltitudeHandler.java | 314 +- .../handlers/ChangeGuildLeaderHandler.java | 151 +- .../client/handlers/ChangeRankHandler.java | 25 +- .../handlers/ChannelMuteMsgHandler.java | 140 +- .../client/handlers/CityChoiceMsgHandler.java | 64 +- .../net/client/handlers/CityDataHandler.java | 8 +- .../client/handlers/ClaimAssetMsgHandler.java | 192 +- .../handlers/ClaimGuildTreeMsgHandler.java | 234 +- .../handlers/DestroyBuildingHandler.java | 124 +- .../client/handlers/DisbandGroupHandler.java | 2 +- .../client/handlers/DisbandGuildHandler.java | 114 +- .../client/handlers/DismissGuildHandler.java | 11 +- .../handlers/DoorTryOpenMsgHandler.java | 16 +- .../client/handlers/FriendAcceptHandler.java | 98 +- .../client/handlers/FriendDeclineHandler.java | 74 +- .../client/handlers/FriendRequestHandler.java | 82 +- .../net/client/handlers/FurnitureHandler.java | 48 +- .../client/handlers/GroupInviteHandler.java | 136 +- .../handlers/GroupInviteResponseHandler.java | 12 +- .../client/handlers/GroupUpdateHandler.java | 6 +- .../client/handlers/GuildControlHandler.java | 64 +- .../handlers/GuildCreationCloseHandler.java | 14 +- .../GuildCreationFinalizeHandler.java | 167 +- .../handlers/GuildCreationOptionsHandler.java | 26 +- .../net/client/handlers/GuildInfoHandler.java | 66 +- .../net/client/handlers/GuildListHandler.java | 28 +- .../client/handlers/GuildUnknownHandler.java | 14 +- .../handlers/HirelingServiceMsgHandler.java | 106 +- .../client/handlers/InviteToGuildHandler.java | 176 +- .../client/handlers/InviteToSubHandler.java | 150 +- .../handlers/ItemProductionMsgHandler.java | 696 +- .../KeepAliveServerClientHandler.java | 53 +- .../client/handlers/LeaveGroupHandler.java | 2 +- .../client/handlers/LeaveGuildHandler.java | 68 +- .../handlers/LockUnlockDoorMsgHandler.java | 10 +- .../handlers/LoginToGameServerMsgHandler.java | 142 +- .../client/handlers/MOTDCommitHandler.java | 106 +- .../net/client/handlers/MOTDEditHandler.java | 78 +- .../handlers/ManageCityAssetMsgHandler.java | 643 +- .../client/handlers/MerchantMsgHandler.java | 685 +- .../handlers/MineWindowChangeHandler.java | 116 +- .../handlers/MinionTrainingMsgHandler.java | 515 +- .../client/handlers/MoveToPointHandler.java | 2 +- .../handlers/ObjectActionMsgHandler.java | 978 +- .../OpenFriendsCondemnListMsgHandler.java | 653 +- .../client/handlers/PlaceAssetMsgHandler.java | 2053 ++- .../handlers/RecommendNationMsgHandler.java | 79 +- .../client/handlers/RemoveFriendHandler.java | 75 +- .../handlers/RepairBuildingMsgHandler.java | 128 +- .../handlers/RequestBallListHandler.java | 55 +- .../handlers/RequestEnterWorldHandler.java | 216 +- .../handlers/RequestGuildListHandler.java | 34 +- .../client/handlers/SendBallEntryHandler.java | 55 +- .../client/handlers/SwearInGuildHandler.java | 12 +- .../net/client/handlers/SwearInHandler.java | 69 +- .../client/handlers/TaxCityMsgHandler.java | 156 +- .../handlers/TaxResourcesMsgHandler.java | 61 +- .../handlers/ToggleGroupSplitHandler.java | 14 +- .../handlers/TransferAssetMsgHandler.java | 150 +- .../TransferGoldToFromBuildingMsgHandler.java | 114 +- .../handlers/UpdateFriendStatusHandler.java | 109 +- .../handlers/UpgradeAssetMsgHandler.java | 185 +- .../net/client/msg/AbandonAssetMsg.java | 12 +- .../net/client/msg/AcceptFriendMsg.java | 83 +- .../net/client/msg/AcceptTradeRequestMsg.java | 64 +- .../client/msg/AckBankWindowOpenedMsg.java | 41 +- .../net/client/msg/ActivateNPCMessage.java | 51 +- .../net/client/msg/AddFriendMessage.java | 85 +- .../client/msg/AddGoldToTradeWindowMsg.java | 6 +- .../client/msg/AddItemToTradeWindowMsg.java | 47 +- .../net/client/msg/AllianceChangeMsg.java | 236 +- .../net/client/msg/AllyEnemyListMsg.java | 135 +- .../client/msg/ApplyBuildingEffectMsg.java | 178 +- src/engine/net/client/msg/ApplyEffectMsg.java | 98 +- src/engine/net/client/msg/ApplyRuneMsg.java | 728 +- .../net/client/msg/ArcLoginNotifyMsg.java | 249 +- .../msg/ArcMineChangeProductionMsg.java | 4 +- .../msg/ArcMineWindowAvailableTimeMsg.java | 168 +- .../client/msg/ArcMineWindowChangeMsg.java | 12 +- .../net/client/msg/ArcOwnedMinesListMsg.java | 4 +- .../net/client/msg/ArcSiegeSpireMsg.java | 7 +- .../msg/ArcViewAssetTransactionsMsg.java | 245 +- .../net/client/msg/AssetSupportMsg.java | 51 +- src/engine/net/client/msg/AttackCmdMsg.java | 28 +- src/engine/net/client/msg/BuyFromNPCMsg.java | 233 +- .../net/client/msg/BuyFromNPCWindowMsg.java | 475 +- .../net/client/msg/ChangeAltitudeMsg.java | 250 +- .../net/client/msg/ChangeGuildLeaderMsg.java | 54 +- src/engine/net/client/msg/ChatFilterMsg.java | 16 +- src/engine/net/client/msg/CityAssetMsg.java | 271 +- src/engine/net/client/msg/CityChoiceMsg.java | 169 +- src/engine/net/client/msg/CityDataMsg.java | 86 +- src/engine/net/client/msg/CityZoneMsg.java | 264 +- src/engine/net/client/msg/ClaimAssetMsg.java | 92 +- .../net/client/msg/ClaimGuildTreeMsg.java | 667 +- src/engine/net/client/msg/ClientNetMsg.java | 90 +- .../net/client/msg/CloseTradeWindowMsg.java | 115 +- .../net/client/msg/CommitToTradeMsg.java | 132 +- .../net/client/msg/ConfirmPromoteMsg.java | 5 +- .../net/client/msg/DeclineFriendMsg.java | 83 +- src/engine/net/client/msg/DeleteItemMsg.java | 102 +- .../net/client/msg/DestroyBuildingMsg.java | 92 +- src/engine/net/client/msg/DoorTryOpenMsg.java | 210 +- src/engine/net/client/msg/DropGoldMsg.java | 245 +- .../net/client/msg/EnterWorldReceivedMsg.java | 74 +- src/engine/net/client/msg/ErrorPopupMsg.java | 555 +- .../net/client/msg/FriendRequestMsg.java | 83 +- src/engine/net/client/msg/FurnitureMsg.java | 471 +- .../net/client/msg/GrantExperienceMsg.java | 20 +- .../net/client/msg/GuildTreeStatusMsg.java | 34 +- .../net/client/msg/HirelingServiceMsg.java | 129 +- .../net/client/msg/HotzoneChangeMsg.java | 13 +- src/engine/net/client/msg/IgnoreListMsg.java | 4 +- src/engine/net/client/msg/IgnoreMsg.java | 4 +- .../client/msg/InvalidTradeRequestMsg.java | 138 +- src/engine/net/client/msg/ItemEffectMsg.java | 487 +- .../net/client/msg/ItemHealthUpdateMsg.java | 94 +- .../net/client/msg/ItemProductionMsg.java | 1069 +- .../client/msg/KeepAliveServerClientMsg.java | 130 +- .../net/client/msg/LeaderboardMessage.java | 153 +- src/engine/net/client/msg/LeaveWorldMsg.java | 60 +- .../net/client/msg/LoadCharacterMsg.java | 232 +- .../net/client/msg/LoadStructureMsg.java | 158 +- .../net/client/msg/LockUnlockDoorMsg.java | 180 +- .../net/client/msg/LoginToGameServerMsg.java | 169 +- src/engine/net/client/msg/LootMsg.java | 478 +- .../net/client/msg/LootWindowRequestMsg.java | 182 +- .../net/client/msg/LootWindowResponseMsg.java | 162 +- .../net/client/msg/ManageCityAssetsMsg.java | 1650 ++- src/engine/net/client/msg/ManageNPCMsg.java | 2669 ++-- src/engine/net/client/msg/MerchantMsg.java | 406 +- .../net/client/msg/MinionTrainingMessage.java | 354 +- .../client/msg/ModifyCommitToTradeMsg.java | 221 +- .../net/client/msg/ModifyHealthKillMsg.java | 429 +- .../net/client/msg/ModifyHealthMsg.java | 457 +- src/engine/net/client/msg/ModifyStatMsg.java | 142 +- .../net/client/msg/MoveCorrectionMsg.java | 408 +- src/engine/net/client/msg/MoveToPointMsg.java | 561 +- .../net/client/msg/ObjectActionMsg.java | 179 +- .../client/msg/OpenFriendsCondemnListMsg.java | 1673 ++- .../net/client/msg/OpenTradeWindowMsg.java | 116 +- src/engine/net/client/msg/OpenVaultMsg.java | 91 +- src/engine/net/client/msg/OrderNPCMsg.java | 349 +- .../client/msg/PassiveMessageTriggerMsg.java | 74 +- .../net/client/msg/PerformActionMsg.java | 542 +- src/engine/net/client/msg/PetAttackMsg.java | 90 +- src/engine/net/client/msg/PetCmdMsg.java | 82 +- src/engine/net/client/msg/PetMsg.java | 192 +- .../net/client/msg/PetitionReceivedMsg.java | 502 +- src/engine/net/client/msg/PlaceAssetMsg.java | 840 +- .../net/client/msg/PowerProjectileMsg.java | 102 +- .../net/client/msg/PromptRecallMsg.java | 74 +- src/engine/net/client/msg/RandomMsg.java | 147 +- .../net/client/msg/RecommendNationMsg.java | 101 +- .../net/client/msg/RecvSummonsRequestMsg.java | 182 +- .../net/client/msg/RecyclePowerMsg.java | 80 +- src/engine/net/client/msg/RefineMsg.java | 424 +- .../net/client/msg/RefinerScreenMsg.java | 194 +- .../net/client/msg/RejectTradeRequestMsg.java | 168 +- .../net/client/msg/RemoveFriendMessage.java | 85 +- .../net/client/msg/RepairBuildingMsg.java | 165 +- src/engine/net/client/msg/RepairMsg.java | 360 +- .../net/client/msg/ReqBankInventoryMsg.java | 106 +- .../client/msg/RequestBallListMessage.java | 96 +- .../net/client/msg/RequestEnterWorldMsg.java | 87 +- src/engine/net/client/msg/RespawnMsg.java | 160 +- .../net/client/msg/RespondLeaveWorldMsg.java | 60 +- .../net/client/msg/RotateObjectMsg.java | 77 +- src/engine/net/client/msg/SafeModeMsg.java | 90 +- src/engine/net/client/msg/ScaleObjectMsg.java | 158 +- src/engine/net/client/msg/SelectCityMsg.java | 141 +- src/engine/net/client/msg/SellToNPCMsg.java | 176 +- .../net/client/msg/SellToNPCWindowMsg.java | 500 +- .../net/client/msg/SendBallEntryMessage.java | 177 +- .../net/client/msg/SendOwnPlayerMsg.java | 190 +- .../net/client/msg/SendSummonsRequestMsg.java | 172 +- src/engine/net/client/msg/ServerInfoMsg.java | 101 +- .../net/client/msg/SetCombatModeMsg.java | 122 +- .../net/client/msg/SetObjectValueMsg.java | 152 +- .../net/client/msg/ShowBankInventoryMsg.java | 110 +- src/engine/net/client/msg/ShowMsg.java | 238 +- .../net/client/msg/ShowVaultInventoryMsg.java | 117 +- src/engine/net/client/msg/SocialMsg.java | 307 +- .../net/client/msg/StuckCommandMsg.java | 60 +- src/engine/net/client/msg/SyncMessage.java | 241 +- .../net/client/msg/TargetObjectMsg.java | 106 +- .../net/client/msg/TargetedActionMsg.java | 625 +- src/engine/net/client/msg/TaxCityMsg.java | 131 +- .../net/client/msg/TaxResourcesMsg.java | 192 +- .../client/msg/TeleportRepledgeListMsg.java | 129 +- .../net/client/msg/TeleportToPointMsg.java | 392 +- .../client/msg/TerritoryChangeMessage.java | 135 +- .../net/client/msg/ToggleCombatMsg.java | 128 +- .../client/msg/ToggleLfgRecruitingMsg.java | 150 +- .../net/client/msg/ToggleSitStandMsg.java | 128 +- src/engine/net/client/msg/TrackArrowMsg.java | 80 +- src/engine/net/client/msg/TrackWindowMsg.java | 247 +- .../net/client/msg/TradeRequestMsg.java | 202 +- src/engine/net/client/msg/TrainMsg.java | 600 +- src/engine/net/client/msg/TrainerInfoMsg.java | 162 +- .../net/client/msg/TransferAssetMsg.java | 160 +- .../net/client/msg/TransferBuildingMsg.java | 156 +- .../TransferGoldFromInventoryToVaultMsg.java | 147 +- .../TransferGoldFromVaultToInventoryMsg.java | 208 +- .../msg/TransferGoldToFromBuildingMsg.java | 238 +- .../TransferItemFromBankToInventoryMsg.java | 383 +- .../TransferItemFromEquipToInventoryMsg.java | 131 +- .../TransferItemFromInventoryToBankMsg.java | 383 +- .../TransferItemFromInventoryToEquipMsg.java | 388 +- .../TransferItemFromInventoryToVaultMsg.java | 351 +- .../TransferItemFromVaultToInventoryMsg.java | 343 +- .../net/client/msg/UncommitToTradeMsg.java | 132 +- src/engine/net/client/msg/Unknown1Msg.java | 102 +- src/engine/net/client/msg/UnknownMsg.java | 263 +- .../net/client/msg/UnloadObjectsMsg.java | 130 +- .../client/msg/UpdateCharOrMobMessage.java | 327 +- .../client/msg/UpdateClientAlliancesMsg.java | 106 +- .../net/client/msg/UpdateEffectsMsg.java | 108 +- .../client/msg/UpdateFriendStatusMessage.java | 102 +- src/engine/net/client/msg/UpdateGoldMsg.java | 95 +- .../net/client/msg/UpdateInventoryMsg.java | 168 +- .../net/client/msg/UpdateObjectMsg.java | 226 +- src/engine/net/client/msg/UpdateStateMsg.java | 372 +- .../net/client/msg/UpdateTradeWindowMsg.java | 132 +- src/engine/net/client/msg/UpdateVaultMsg.java | 78 +- .../net/client/msg/UpgradeAssetMessage.java | 134 +- src/engine/net/client/msg/UseCharterMsg.java | 134 +- .../net/client/msg/VendorDialogMsg.java | 1738 ++- .../net/client/msg/ViewResourcesMessage.java | 339 +- .../net/client/msg/VisualUpdateMessage.java | 90 +- src/engine/net/client/msg/WhoRequestMsg.java | 167 +- src/engine/net/client/msg/WhoResponseMsg.java | 477 +- src/engine/net/client/msg/WorldDataMsg.java | 206 +- src/engine/net/client/msg/WorldRealmMsg.java | 86 +- .../net/client/msg/chat/AbstractChatMsg.java | 314 +- .../net/client/msg/chat/ChatCSRMsg.java | 92 +- .../net/client/msg/chat/ChatCityMsg.java | 110 +- .../net/client/msg/chat/ChatGlobalMsg.java | 116 +- .../net/client/msg/chat/ChatGroupMsg.java | 90 +- .../net/client/msg/chat/ChatGuildMsg.java | 250 +- src/engine/net/client/msg/chat/ChatICMsg.java | 211 +- .../net/client/msg/chat/ChatInfoMsg.java | 76 +- .../net/client/msg/chat/ChatLeaderMsg.java | 246 +- .../net/client/msg/chat/ChatPvPMsg.java | 111 +- .../net/client/msg/chat/ChatSayMsg.java | 109 +- .../net/client/msg/chat/ChatShoutMsg.java | 98 +- .../client/msg/chat/ChatSystemChannelMsg.java | 268 +- .../net/client/msg/chat/ChatSystemMsg.java | 338 +- .../net/client/msg/chat/ChatTellMsg.java | 261 +- .../client/msg/chat/GuildEnterWorldMsg.java | 425 +- .../msg/commands/ClientAdminCommandMsg.java | 134 +- .../msg/group/AppointGroupLeaderMsg.java | 210 +- .../net/client/msg/group/DisbandGroupMsg.java | 80 +- .../client/msg/group/FormationFollowMsg.java | 174 +- .../net/client/msg/group/GroupInviteMsg.java | 387 +- .../msg/group/GroupInviteResponseMsg.java | 197 +- .../net/client/msg/group/GroupUpdateMsg.java | 39 +- .../net/client/msg/group/LeaveGroupMsg.java | 197 +- .../client/msg/group/RemoveFromGroupMsg.java | 210 +- .../client/msg/group/ToggleGroupSplitMsg.java | 87 +- .../msg/guild/AcceptInviteToGuildMsg.java | 11 +- .../client/msg/guild/AcceptSubInviteMsg.java | 200 +- .../client/msg/guild/BanishUnbanishMsg.java | 79 +- .../net/client/msg/guild/BreakFealtyMsg.java | 76 +- .../net/client/msg/guild/ChangeRankMsg.java | 16 +- .../net/client/msg/guild/DisbandGuildMsg.java | 71 +- .../net/client/msg/guild/DismissGuildMsg.java | 110 +- .../net/client/msg/guild/GuildControlMsg.java | 429 +- .../msg/guild/GuildCreationCloseMsg.java | 80 +- .../msg/guild/GuildCreationFinalizeMsg.java | 18 +- .../msg/guild/GuildCreationOptionsMsg.java | 239 +- .../net/client/msg/guild/GuildInfoMsg.java | 737 +- .../net/client/msg/guild/GuildListMsg.java | 286 +- .../net/client/msg/guild/GuildUnknownMsg.java | 73 +- .../client/msg/guild/InviteToGuildMsg.java | 328 +- .../net/client/msg/guild/InviteToSubMsg.java | 355 +- .../net/client/msg/guild/LeaveGuildMsg.java | 162 +- .../net/client/msg/guild/MOTDCommitMsg.java | 173 +- src/engine/net/client/msg/guild/MOTDMsg.java | 218 +- .../net/client/msg/guild/ReqGuildListMsg.java | 67 +- .../client/msg/guild/SendGuildEntryMsg.java | 157 +- .../net/client/msg/guild/SwearInGuildMsg.java | 111 +- .../net/client/msg/guild/SwearInMsg.java | 197 +- .../client/msg/login/CharSelectScreenMsg.java | 519 +- .../client/msg/login/ClientLoginInfoMsg.java | 474 +- .../msg/login/CommitNewCharacterMsg.java | 832 +- .../client/msg/login/DeleteCharacterMsg.java | 8 +- .../msg/login/GameServerIPRequestMsg.java | 81 +- .../msg/login/GameServerIPResponseMsg.java | 112 +- .../net/client/msg/login/InvalidNameMsg.java | 112 +- .../net/client/msg/login/LoginErrorMsg.java | 89 +- .../net/client/msg/login/ServerStatusMsg.java | 104 +- .../net/client/msg/login/VersionInfoMsg.java | 89 +- src/engine/objects/AbstractCharacter.java | 3789 +++--- src/engine/objects/AbstractGameObject.java | 398 +- .../objects/AbstractIntelligenceAgent.java | 419 +- src/engine/objects/AbstractWorldObject.java | 1171 +- src/engine/objects/Account.java | 606 +- src/engine/objects/Bane.java | 360 +- src/engine/objects/BaseClass.java | 392 +- src/engine/objects/Blueprint.java | 1039 +- src/engine/objects/Boon.java | 61 +- src/engine/objects/BootySetEntry.java | 38 +- src/engine/objects/Building.java | 2494 ++-- src/engine/objects/BuildingFriends.java | 72 +- src/engine/objects/BuildingLocation.java | 201 +- src/engine/objects/BuildingRegions.java | 536 +- src/engine/objects/CharacterItemManager.java | 4522 ++++--- src/engine/objects/CharacterPower.java | 1158 +- src/engine/objects/CharacterRune.java | 366 +- src/engine/objects/CharacterSkill.java | 2425 ++-- src/engine/objects/CharacterTitle.java | 202 +- src/engine/objects/City.java | 2172 ++-- src/engine/objects/Colliders.java | 72 +- src/engine/objects/Condemned.java | 111 +- src/engine/objects/Contract.java | 550 +- src/engine/objects/Corpse.java | 739 +- src/engine/objects/Effect.java | 1244 +- src/engine/objects/EffectsResourceCosts.java | 85 +- src/engine/objects/EnchantmentBase.java | 150 +- src/engine/objects/Experience.java | 830 +- src/engine/objects/Formation.java | 204 +- src/engine/objects/Group.java | 264 +- src/engine/objects/Guild.java | 580 +- src/engine/objects/GuildAlliances.java | 166 +- src/engine/objects/GuildCondemn.java | 79 +- src/engine/objects/GuildHistory.java | 129 +- src/engine/objects/GuildStatusController.java | 229 +- src/engine/objects/GuildTag.java | 134 +- src/engine/objects/Heraldry.java | 299 +- src/engine/objects/Item.java | 2761 ++-- src/engine/objects/ItemBase.java | 1778 +-- src/engine/objects/ItemContainer.java | 158 +- src/engine/objects/ItemFactory.java | 2072 ++- src/engine/objects/Kit.java | 792 +- src/engine/objects/LevelDefault.java | 97 +- src/engine/objects/LootRow.java | 96 +- src/engine/objects/LootTable.java | 1956 ++- src/engine/objects/MaxSkills.java | 87 +- src/engine/objects/MenuOption.java | 81 +- src/engine/objects/MeshBounds.java | 56 +- src/engine/objects/Mine.java | 4 +- src/engine/objects/MineProduction.java | 132 +- src/engine/objects/Mob.java | 27 +- src/engine/objects/MobBase.java | 549 +- src/engine/objects/MobBaseEffects.java | 66 +- src/engine/objects/MobBaseStats.java | 119 +- src/engine/objects/MobEquipment.java | 674 +- src/engine/objects/MobLoot.java | 729 +- src/engine/objects/MobLootBase.java | 56 +- src/engine/objects/NPC.java | 2498 ++-- src/engine/objects/NPCProfits.java | 169 +- src/engine/objects/NPCRune.java | 193 +- src/engine/objects/Nation.java | 203 +- src/engine/objects/PlayerBonuses.java | 933 +- src/engine/objects/PlayerCharacter.java | 10769 ++++++++-------- src/engine/objects/PlayerFriends.java | 195 +- src/engine/objects/Portal.java | 128 +- src/engine/objects/PowerGrant.java | 217 +- src/engine/objects/PowerReq.java | 330 +- src/engine/objects/PowersBaseAttribute.java | 78 +- .../objects/PreparedStatementShared.java | 2227 ++-- src/engine/objects/ProducedItem.java | 365 +- src/engine/objects/PromotionClass.java | 358 +- src/engine/objects/Race.java | 610 +- src/engine/objects/Realm.java | 700 +- src/engine/objects/Regions.java | 696 +- src/engine/objects/Resists.java | 1039 +- src/engine/objects/Resource.java | 91 +- src/engine/objects/RuneBase.java | 378 +- src/engine/objects/RuneBaseAttribute.java | 164 +- src/engine/objects/RuneBaseEffect.java | 97 +- src/engine/objects/Runegate.java | 130 +- src/engine/objects/Shrine.java | 590 +- src/engine/objects/SkillReq.java | 93 +- src/engine/objects/SkillsBase.java | 268 +- src/engine/objects/SkillsBaseAttribute.java | 106 +- src/engine/objects/StaticColliders.java | 160 +- src/engine/objects/Transaction.java | 133 +- src/engine/objects/VendorDialog.java | 106 +- src/engine/objects/Warehouse.java | 2519 ++-- src/engine/objects/Zone.java | 624 +- src/engine/pooling/ByteBufferPool.java | 82 +- src/engine/pooling/ConnectionPool.java | 78 +- src/engine/pooling/LinkedObjectPool.java | 244 +- .../pooling/MultisizeByteBufferPool.java | 332 +- src/engine/pooling/ObjectPool.java | 351 +- src/engine/pooling/Poolable.java | 2 +- src/engine/powers/ActionsBase.java | 481 +- src/engine/powers/DamageShield.java | 56 +- src/engine/powers/EffectsBase.java | 1482 ++- src/engine/powers/FailCondition.java | 192 +- src/engine/powers/PowerPrereq.java | 169 +- src/engine/powers/PowersBase.java | 1205 +- src/engine/powers/RangeBasedAwo.java | 156 +- .../AbstractEffectModifier.java | 187 +- .../AdjustAboveDmgCapEffectModifier.java | 59 +- .../AmbidexterityEffectModifier.java | 33 +- .../ArmorPiercingEffectModifier.java | 45 +- .../AttackDelayEffectModifier.java | 53 +- .../AttributeEffectModifier.java | 73 +- .../BlackMantleEffectModifier.java | 61 +- .../BladeTrailsEffectModifier.java | 29 +- .../effectmodifiers/BlockEffectModifier.java | 53 +- .../BlockedPowerTypeEffectModifier.java | 81 +- .../CannotAttackEffectModifier.java | 43 +- .../CannotCastEffectModifier.java | 39 +- .../CannotMoveEffectModifier.java | 43 +- .../CannotTrackEffectModifier.java | 33 +- .../CharmedEffectModifier.java | 29 +- ...onstrainedAmbidexterityEffectModifier.java | 33 +- .../effectmodifiers/DCVEffectModifier.java | 69 +- .../effectmodifiers/DREffectModifier.java | 78 +- .../DamageCapEffectModifier.java | 53 +- .../DamageShieldEffectModifier.java | 74 +- .../effectmodifiers/DodgeEffectModifier.java | 69 +- .../DurabilityEffectModifier.java | 43 +- .../ExclusiveDamageCapEffectModifier.java | 51 +- .../effectmodifiers/FadeEffectModifier.java | 29 +- .../effectmodifiers/FlyEffectModifier.java | 33 +- .../effectmodifiers/HealthEffectModifier.java | 581 +- .../HealthFullEffectModifier.java | 69 +- .../HealthRecoverRateEffectModifier.java | 57 +- .../IgnoreDamageCapEffectModifier.java | 53 +- .../IgnorePassiveDefenseEffectModifier.java | 33 +- .../ImmuneToAttackEffectModifier.java | 33 +- .../ImmuneToEffectModifier.java | 33 +- .../ImmuneToPowersEffectModifier.java | 43 +- .../InvisibleEffectModifier.java | 86 +- .../ItemNameEffectModifier.java | 201 +- .../effectmodifiers/ManaEffectModifier.java | 376 +- .../ManaFullEffectModifier.java | 69 +- .../ManaRecoverRateEffectModifier.java | 53 +- .../MaxDamageEffectModifier.java | 78 +- .../MeleeDamageEffectModifier.java | 69 +- .../MinDamageEffectModifier.java | 78 +- .../effectmodifiers/NoModEffectModifier.java | 67 +- .../effectmodifiers/OCVEffectModifier.java | 69 +- .../effectmodifiers/ParryEffectModifier.java | 69 +- .../PassiveDefenseEffectModifier.java | 69 +- .../PowerCostEffectModifier.java | 69 +- .../PowerCostHealthEffectModifier.java | 29 +- .../PowerDamageEffectModifier.java | 69 +- .../ProtectionFromEffectModifier.java | 47 +- .../ResistanceEffectModifier.java | 69 +- .../ScaleHeightEffectModifier.java | 29 +- .../ScaleWidthEffectModifier.java | 29 +- .../ScanRangeEffectModifier.java | 69 +- .../SeeInvisibleEffectModifier.java | 47 +- .../SilencedEffectModifier.java | 43 +- .../effectmodifiers/SkillEffectModifier.java | 69 +- .../effectmodifiers/SlayEffectModifier.java | 69 +- .../effectmodifiers/SpeedEffectModifier.java | 69 +- .../SpireBlockEffectModifier.java | 33 +- .../StaminaEffectModifier.java | 372 +- .../StaminaFullEffectModifier.java | 69 +- .../StaminaRecoverRateEffectModifier.java | 57 +- .../StunnedEffectModifier.java | 55 +- .../effectmodifiers/ValueEffectModifier.java | 29 +- .../WeaponProcEffectModifier.java | 35 +- .../WeaponRangeEffectModifier.java | 71 +- .../WeaponSpeedEffectModifier.java | 57 +- .../poweractions/AbstractPowerAction.java | 549 +- .../poweractions/ApplyEffectPowerAction.java | 431 +- .../poweractions/ApplyEffectsPowerAction.java | 194 +- .../powers/poweractions/BlockPowerAction.java | 28 +- .../powers/poweractions/CharmPowerAction.java | 68 +- .../poweractions/ClaimMinePowerAction.java | 58 +- .../poweractions/ClearAggroPowerAction.java | 35 +- .../ClearNearbyAggroPowerAction.java | 30 +- .../poweractions/ConfusionPowerAction.java | 28 +- .../poweractions/CreateMobPowerAction.java | 198 +- .../DamageOverTimePowerAction.java | 116 +- .../DeferredPowerPowerAction.java | 132 +- .../poweractions/DirectDamagePowerAction.java | 130 +- .../powers/poweractions/FearPowerAction.java | 76 +- .../powers/poweractions/InvisPowerAction.java | 102 +- .../poweractions/MobRecallPowerAction.java | 51 +- .../poweractions/OpenGatePowerAction.java | 136 +- .../powers/poweractions/PeekPowerAction.java | 151 +- .../poweractions/RecallPowerAction.java | 107 +- .../poweractions/RemoveEffectPowerAction.java | 73 +- .../poweractions/ResurrectPowerAction.java | 28 +- .../RunegateTeleportPowerAction.java | 116 +- .../poweractions/SetItemFlagPowerAction.java | 54 +- .../poweractions/SimpleDamagePowerAction.java | 38 +- .../poweractions/SpireDisablePowerAction.java | 85 +- .../powers/poweractions/StealPowerAction.java | 252 +- .../poweractions/SummonPowerAction.java | 66 +- .../poweractions/TeleportPowerAction.java | 124 +- .../powers/poweractions/TrackPowerAction.java | 198 +- .../TransferStatOTPowerAction.java | 80 +- .../poweractions/TransferStatPowerAction.java | 527 +- .../poweractions/TransformPowerAction.java | 88 +- .../poweractions/TreeChokePowerAction.java | 28 +- src/engine/server/MBServerStatics.java | 834 +- src/engine/server/login/LoginServer.java | 203 +- .../server/login/LoginServerMsgHandler.java | 36 +- src/engine/session/CSSession.java | 203 +- src/engine/session/Session.java | 100 +- src/engine/session/SessionID.java | 66 +- src/engine/util/ByteAnalyzer.java | 412 +- src/engine/util/ByteBufferUtils.java | 363 +- src/engine/util/ByteUtils.java | 272 +- src/engine/util/Hasher.java | 254 +- src/engine/util/KeyCloneAudit.java | 10 +- src/engine/util/MapLoader.java | 18 +- src/engine/util/MiscUtils.java | 34 +- src/engine/util/StringUtils.java | 243 +- src/engine/util/ThreadUtils.java | 46 +- src/engine/workthreads/DestroyCityThread.java | 160 +- .../workthreads/DisconnectTrashTask.java | 25 +- src/engine/workthreads/PurgeOprhans.java | 2 +- .../workthreads/TransferCityThread.java | 6 +- .../workthreads/WarehousePushThread.java | 705 +- 747 files changed, 105538 insertions(+), 107034 deletions(-) diff --git a/README.md b/README.md index c83b332d..3468187d 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,23 @@ ![Logo](https://magicbane.com/images/MBLogo.jpg) # Magicbane Open-Source MMO Project + ### *The Community written Shadowbane emulator* + [Magicbane](http://www.magicbane.com)
[Public Repository](http://repo.magicbane.com)
-> Magicbane is an emulator for the long dead but much beloved Ubisoft MMO, [Shadowbane](https://en.wikipedia.org/wiki/Shadowbane). -The project was founded in 2013 with the concept of free availability of gameplay; players unencumbered by any factor other than a desire to again play a game they once loved. A game where the developers do not play is guaranteed to be the fairest game. +> Magicbane is an emulator for the long dead but much beloved Ubisoft +> MMO, [Shadowbane](https://en.wikipedia.org/wiki/Shadowbane). +> The project was founded in 2013 with the concept of free availability of gameplay; players unencumbered by any factor +> other than a desire to again play a game they once loved. A game where the developers do not play is guaranteed to be +> the fairest game. -The Magicbane Team has wanted to open source Shadowbane for half a decade. We are excited to now finally have the opportunity, along with some new technology, to truly democratize Shadowbane. +The Magicbane Team has wanted to open source Shadowbane for half a decade. We are excited to now finally have the +opportunity, along with some new technology, to truly democratize Shadowbane. - Written in some 80k lines of Java 8 and bash. - Project with real infrastructure; Production and development servers supporting multiple containerized apps. @@ -20,11 +26,12 @@ The Magicbane Team has wanted to open source Shadowbane for half a decade. We a ## Contributing -- Project is released under an MIT license. Please see the LICENSE file. +- Project is released under an MIT license. Please see the LICENSE file. - Inbound == Outbound. - IntelliJ is the supported IDE. - Write code today see it running on the Magicbane production server tomorrow. ## Support -Documentation is available through the Magicbane [Wiki](http://repo.magicbane.com/MagicBane/Server/wiki) and [Discord server](www.magicbane.com). \ No newline at end of file +Documentation is available through the Magicbane [Wiki](http://repo.magicbane.com/MagicBane/Server/wiki) +and [Discord server](www.magicbane.com). \ No newline at end of file diff --git a/src/discord/ChatChannel.java b/src/discord/ChatChannel.java index 1540dfce..a67e31fe 100644 --- a/src/discord/ChatChannel.java +++ b/src/discord/ChatChannel.java @@ -24,7 +24,7 @@ public enum ChatChannel { ADMINLOG("MB_MAGICBOT_ADMINLOG"); public final String configName; - public long channelID; + public long channelID; public TextChannel textChannel; ChatChannel(String configName) { diff --git a/src/discord/DiscordAccount.java b/src/discord/DiscordAccount.java index 0b3d6b77..fce59a4b 100644 --- a/src/discord/DiscordAccount.java +++ b/src/discord/DiscordAccount.java @@ -7,6 +7,7 @@ // www.magicbane.com package discord; + import engine.Enum; import java.time.LocalDateTime; @@ -18,6 +19,7 @@ public class DiscordAccount { public LocalDateTime registrationDate; public LocalDateTime lastUpdateRequest; public byte isDiscordAdmin; + public DiscordAccount() { } diff --git a/src/discord/MagicBot.java b/src/discord/MagicBot.java index fe5a6150..1e496c17 100644 --- a/src/discord/MagicBot.java +++ b/src/discord/MagicBot.java @@ -37,32 +37,32 @@ import java.util.regex.Pattern; import static discord.ChatChannel.ADMINLOG; /* -* MagicBot is many things to Magicbane... -* -* -Project Mascot -* -Customer service and administration bot -* -Benevolent dictator -* -Investment manager. -* -* MagicBot will never beg you for money. He is a very -* responsible robot. He was varnished but never garnished. -* MagicBot does not for to overclock himself. His chips -* will therefore never overcook. -* MagicBot will never be a pitiful robot trying for to use -* you as emotional support human. -* -* MagicBot is just not that sort of robot and Magicbane -* just isn't that sort of project. -* -* MagicBot runs a Shaodowbane emulator not a Second Life emulator. -* -*/ + * MagicBot is many things to Magicbane... + * + * -Project Mascot + * -Customer service and administration bot + * -Benevolent dictator + * -Investment manager. + * + * MagicBot will never beg you for money. He is a very + * responsible robot. He was varnished but never garnished. + * MagicBot does not for to overclock himself. His chips + * will therefore never overcook. + * MagicBot will never be a pitiful robot trying for to use + * you as emotional support human. + * + * MagicBot is just not that sort of robot and Magicbane + * just isn't that sort of project. + * + * MagicBot runs a Shaodowbane emulator not a Second Life emulator. + * + */ public class MagicBot extends ListenerAdapter { - public static JDA jda; - public static Database database; public static final Pattern accountNameRegex = Pattern.compile("^[\\p{Alnum}]{6,20}$"); public static final Pattern passwordRegex = Pattern.compile("^[\\p{Alnum}]{6,20}$"); + public static JDA jda; + public static Database database; public static long discordServerID; public static long discordRoleID; @@ -126,12 +126,136 @@ public class MagicBot extends ListenerAdapter { Runnable adminLogRunnable = () -> SendAdminLogUpdates(); ScheduledExecutorService exec = Executors.newScheduledThreadPool(1); - exec.scheduleAtFixedRate(adminLogRunnable , 0, 1, TimeUnit.MINUTES); + exec.scheduleAtFixedRate(adminLogRunnable, 0, 1, TimeUnit.MINUTES); Logger.info("***MAGICBOT IS RUNNING***"); } + public static void sendResponse(MessageReceivedEvent event, String responseContent) { + + // Send a formatted MagicBot response to a Discord user + + String discordUserName; + MessageChannel channel; + + // Exit if discord is offline + + if (jda.getStatus().equals(JDA.Status.CONNECTED) == false) + return; + + discordUserName = event.getAuthor().getName(); + channel = event.getMessage().getChannel(); + + channel.sendMessage( + "```\n" + "Hello Player " + discordUserName + "\n\n" + + responseContent + "\n\n" + + RobotSpeak.getRobotSpeak() + "\n```").queue(); + } + + public static boolean isAdminEvent(MessageReceivedEvent event) { + + String discordAccountID = event.getAuthor().getId(); + List discordAccounts; + DiscordAccount discordAccount; + + // Note that database errors will cause this to return false. + // After the database is offline Avail status must be set + // to true before any subsequent admin commands will function. + + if (Database.online == false) + return false; + + discordAccounts = database.getDiscordAccounts(discordAccountID); + + if (discordAccounts.isEmpty()) + return false; + + discordAccount = discordAccounts.get(0); + return (discordAccount.isDiscordAdmin == 1); + } + + public static String generatePassword(int length) { + + String ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + StringBuilder passwordBuilder = new StringBuilder(length); + Random random = new Random(); + + // Generate alphanumeric password of a given length. + // Could not find a good method of generating a password + // based upon a given regex. + + for (int i = 0; i < length; i++) + passwordBuilder.append(ALPHABET.charAt(random.nextInt(ALPHABET.length()))); + + return new String(passwordBuilder); + } + + public static String readLogFile(String filePath, int lineCount) { + + ProcessBuilder builder = new ProcessBuilder("/bin/bash", "-c", "tail -n " + lineCount + " " + filePath); + builder.redirectErrorStream(true); + Process process = null; + String line = null; + String logOutput = ""; + + try { + process = builder.start(); + + InputStream is = process.getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + + while ((line = reader.readLine()) != null) { + logOutput += line + "\n"; + } + + } catch (IOException e) { + Logger.error(e.toString()); + return "Error while reading logfile"; + } + + return logOutput; + } + + private static void junkbot(String command, String[] inString) { + + String outString; + Writer fileWriter; + + if (inString == null) + return; + ; + + outString = command + String.join(" ", inString); + outString += "\n"; + + try { + fileWriter = new BufferedWriter(new FileWriter("junkbot.txt", true)); + fileWriter.append(outString); + fileWriter.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static void SendAdminLogUpdates() { + HashMap adminEvents = database.getAdminEvents(); + + for (int adminEvent : adminEvents.keySet()) { + + // Set event as read + database.setAdminEventAsRead(adminEvent); + String outString = + "```\n" + "Hello Players \n\n" + + adminEvents.get(adminEvent) + "\n\n" + + RobotSpeak.getRobotSpeak() + "\n```"; + + if (ADMINLOG.textChannel.canTalk()) + ADMINLOG.textChannel.sendMessage(outString).queue(); + + } + } + @Override public void onMessageReceived(MessageReceivedEvent event) { @@ -142,7 +266,8 @@ public class MagicBot extends ListenerAdapter { // Early exit if message sent to us by another bot or ourselves. - if (event.getAuthor().isBot()) return; + if (event.getAuthor().isBot()) + return; // Extract message and origin channel from event @@ -247,49 +372,6 @@ public class MagicBot extends ListenerAdapter { } } - public static void sendResponse(MessageReceivedEvent event, String responseContent) { - - // Send a formatted MagicBot response to a Discord user - - String discordUserName; - MessageChannel channel; - - // Exit if discord is offline - - if (jda.getStatus().equals(JDA.Status.CONNECTED) == false) - return; - - discordUserName = event.getAuthor().getName(); - channel = event.getMessage().getChannel(); - - channel.sendMessage( - "```\n" + "Hello Player " + discordUserName + "\n\n" + - responseContent + "\n\n" + - RobotSpeak.getRobotSpeak() + "\n```").queue(); - } - - public static boolean isAdminEvent(MessageReceivedEvent event) { - - String discordAccountID = event.getAuthor().getId(); - List discordAccounts; - DiscordAccount discordAccount; - - // Note that database errors will cause this to return false. - // After the database is offline Avail status must be set - // to true before any subsequent admin commands will function. - - if (Database.online == false) - return false; - - discordAccounts = database.getDiscordAccounts(discordAccountID); - - if (discordAccounts.isEmpty()) - return false; - - discordAccount = discordAccounts.get(0); - return (discordAccount.isDiscordAdmin == 1); - } - public void handleHelpRequest(MessageReceivedEvent event) { // Help is kept here in the main class instead of a handler as a @@ -322,85 +404,4 @@ public class MagicBot extends ListenerAdapter { "#trash /detail/flush"; sendResponse(event, helpString); } - - public static String generatePassword(int length) { - - String ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - StringBuilder passwordBuilder = new StringBuilder(length); - Random random = new Random(); - - // Generate alphanumeric password of a given length. - // Could not find a good method of generating a password - // based upon a given regex. - - for (int i = 0; i < length; i++) - passwordBuilder.append(ALPHABET.charAt(random.nextInt(ALPHABET.length()))); - - return new String(passwordBuilder); - } - - public static String readLogFile(String filePath, int lineCount) { - - ProcessBuilder builder = new ProcessBuilder("/bin/bash", "-c", "tail -n " + lineCount + " " + filePath); - builder.redirectErrorStream(true); - Process process = null; - String line = null; - String logOutput = ""; - - try { - process = builder.start(); - - InputStream is = process.getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(is)); - - while ((line = reader.readLine()) != null) { - logOutput += line + "\n"; - } - - } catch (IOException e) { - Logger.error(e.toString()); - return "Error while reading logfile"; - } - - return logOutput; - } - - private static void junkbot(String command, String[] inString) { - - String outString; - Writer fileWriter; - - if (inString == null) - return; - ; - - outString = command + String.join(" ", inString); - outString += "\n"; - - try { - fileWriter = new BufferedWriter(new FileWriter("junkbot.txt", true)); - fileWriter.append(outString); - fileWriter.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - private static void SendAdminLogUpdates() { - HashMap adminEvents = database.getAdminEvents(); - - for (int adminEvent : adminEvents.keySet()) { - - // Set event as read - database.setAdminEventAsRead(adminEvent); - String outString = - "```\n" + "Hello Players \n\n" + - adminEvents.get(adminEvent) + "\n\n" + - RobotSpeak.getRobotSpeak() + "\n```"; - - if (ADMINLOG.textChannel.canTalk()) - ADMINLOG.textChannel.sendMessage(outString).queue(); - - } - } } diff --git a/src/discord/handlers/ChatChannelHandler.java b/src/discord/handlers/ChatChannelHandler.java index 4f86b184..67697dab 100644 --- a/src/discord/handlers/ChatChannelHandler.java +++ b/src/discord/handlers/ChatChannelHandler.java @@ -39,10 +39,11 @@ public class ChatChannelHandler { if (chatText.startsWith("-r ")) outString = - "```\n" + "Hello Players \n\n" + - chatText.substring(3) + "\n\n" + - RobotSpeak.getRobotSpeak() + "\n```"; - else outString = chatText; + "```\n" + "Hello Players \n\n" + + chatText.substring(3) + "\n\n" + + RobotSpeak.getRobotSpeak() + "\n```"; + else + outString = chatText; // Write string to changelog channel diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index c73ea898..f5c73ba2 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -40,7 +40,7 @@ public class DevRequestHandler { switch (serverCommand) { - case "build" : + case "build": commandString = "./mbdevbuild.sh"; break; case "restart": @@ -61,11 +61,11 @@ public class DevRequestHandler { case "help": MagicBot.sendResponse(event, "#dev build (blank==master) \n" + - "#dev shutdown (Shutdown dev server)\n" + - "#dev restart (Restarts the server)\n"+ - "#dev debug (Restarts server in debug mode)\n" + - "#dev console # (Displays # lines from console)\n" + - "#dev lastout (Displays output from last command) \n"); + "#dev shutdown (Shutdown dev server)\n" + + "#dev restart (Restarts the server)\n" + + "#dev debug (Restarts server in debug mode)\n" + + "#dev console # (Displays # lines from console)\n" + + "#dev lastout (Displays output from last command) \n"); return; default: break; @@ -77,18 +77,19 @@ public class DevRequestHandler { } processBuilder = new ProcessBuilder("/bin/sh", "-c", commandString + " " + commandArgument + " > devLastOut"); - logString = String.join(" ",processBuilder.command().toArray(new String[0])); + logString = String.join(" ", processBuilder.command().toArray(new String[0])); try { - processBuilder.start(); - } catch (IOException e) { - Logger.info(e.toString()); - } + processBuilder.start(); + } catch (IOException e) { + Logger.info(e.toString()); + } MagicBot.sendResponse(event, "Executed on dev: " + logString + "\n" + - "Use #dev lastout to view results"); + "Use #dev lastout to view results"); + + } - } private static String getLastOutput() { String outString = null; diff --git a/src/discord/handlers/RegisterAccountHandler.java b/src/discord/handlers/RegisterAccountHandler.java index eef45cf3..8daf6a84 100644 --- a/src/discord/handlers/RegisterAccountHandler.java +++ b/src/discord/handlers/RegisterAccountHandler.java @@ -56,18 +56,18 @@ public class RegisterAccountHandler { return; } - // Validate account name with regex + // Validate account name with regex - accountName = args[0].replaceAll("\\s+", ""); + accountName = args[0].replaceAll("\\s+", ""); - if (MagicBot.accountNameRegex.matcher(accountName).matches() == false) { + if (MagicBot.accountNameRegex.matcher(accountName).matches() == false) { - MagicBot.sendResponse(event, - "Your supplied account name does not compute.\n" + - "Account names must satisfy following regex:\n" + - "^[\\p{Alnum}]{6,20}$"); - return; - } + MagicBot.sendResponse(event, + "Your supplied account name does not compute.\n" + + "Account names must satisfy following regex:\n" + + "^[\\p{Alnum}]{6,20}$"); + return; + } if (accountName.equalsIgnoreCase("accountname")) { MagicBot.sendResponse(event, diff --git a/src/discord/handlers/StatusRequestHandler.java b/src/discord/handlers/StatusRequestHandler.java index 1ea836c6..173196ef 100644 --- a/src/discord/handlers/StatusRequestHandler.java +++ b/src/discord/handlers/StatusRequestHandler.java @@ -24,7 +24,7 @@ public class StatusRequestHandler { outString = "Server Status: "; if (LoginServer.isPortInUse(Integer.parseInt(ConfigManager.MB_WORLD_PORT.getValue()))) - outString += "ONLINE\n"; + outString += "ONLINE\n"; else outString += "OFFLINE\n"; diff --git a/src/discord/handlers/TrashRequestHandler.java b/src/discord/handlers/TrashRequestHandler.java index 79da4ae9..fe053060 100644 --- a/src/discord/handlers/TrashRequestHandler.java +++ b/src/discord/handlers/TrashRequestHandler.java @@ -48,7 +48,7 @@ public class TrashRequestHandler { // Anounce event in septic tank channel - outString = "```\n" + trashCount + " Player Character were for to deleted due to verified cheatings. \n\n"; + outString = "```\n" + trashCount + " Player Character were for to deleted due to verified cheatings. \n\n"; outString += MagicBot.database.getTrashList() + "\n\n"; outString += RobotSpeak.getRobotInsult() + "\n```"; diff --git a/src/engine/Enum.java b/src/engine/Enum.java index b42d18ef..251c105d 100644 --- a/src/engine/Enum.java +++ b/src/engine/Enum.java @@ -37,2770 +37,2770 @@ import java.util.concurrent.ThreadLocalRandom; public class Enum { - public enum MobFlagType implements EnumBitSetHelper { - AGGRESSIVE, - CANROAM, - CALLSFORHELP, - RESPONDSTOCALLSFORHELP, - HUMANOID, - UNDEAD, - BEAST, - DRAGON, - RAT, - SENTINEL, - } - - public enum MonsterType implements EnumBitSetHelper { - Aelfborn, - All, - Animal, - Aracoix, - Celestial, - Centaur, - Construct, - CSR, - Dragon, - Dwarf, - Elf, - Giant, - Goblin, - Grave, - HalfGiant, - Human, - Infernal, - Insect, - Irekei, - Minotaur, - Monster, - NecroPet, - NPC, - Pet, - Plant, - Rat, - Reptile, - Shade, - Siege, - Summoned, - Troll, - Undead, - Nephilim, - Vampire, - SiegeEngineer; - - } - - public enum CharacterSex { - MALE, - FEMALE, - FUZZY, - OTHER; - } - - public enum RaceType { - - // RaceRuneID / AggroType, isFemale - - AELFMALE(2000, MonsterType.Aelfborn, RunSpeed.STANDARD, CharacterSex.MALE, 1.05f), - AELFFEMALE(2001, MonsterType.Aelfborn, RunSpeed.STANDARD, CharacterSex.FEMALE, 1.05f), - ARACOIXMALE(2002, MonsterType.Aracoix, RunSpeed.STANDARD, CharacterSex.MALE, 1), - ARACOIXFEMALE(2003, MonsterType.Aracoix, RunSpeed.STANDARD, CharacterSex.FEMALE, 1), - CENTAURMALE(2004, MonsterType.Centaur, RunSpeed.CENTAUR, CharacterSex.MALE, 1.2f), - CENTAURFEMALE(2005, MonsterType.Centaur, RunSpeed.CENTAUR, CharacterSex.FEMALE, 1.2f), - DWARFMALE(2006, MonsterType.Dwarf, RunSpeed.STANDARD, CharacterSex.MALE, 0.80000001f), - ELFMALE(2008, MonsterType.Elf, RunSpeed.STANDARD, CharacterSex.MALE, 1.4f), - ELFFEMALE(2009, MonsterType.Elf, RunSpeed.STANDARD, CharacterSex.FEMALE, 1.1f), - HALFGIANTMALE(2010, MonsterType.HalfGiant, RunSpeed.STANDARD, CharacterSex.MALE, 1.15f), - HUMANMALE(2011, MonsterType.Human, RunSpeed.STANDARD, CharacterSex.MALE, 1), - HUMANFEMALE(2012, MonsterType.Human, RunSpeed.STANDARD, CharacterSex.FEMALE, 1), - IREKEIMALE(2013, MonsterType.Irekei, RunSpeed.STANDARD, CharacterSex.MALE, 1.1f), - IREKEIFEMALE(2014, MonsterType.Irekei, RunSpeed.STANDARD, CharacterSex.FEMALE, 1.1f), - SHADEMALE(2015, MonsterType.Shade, RunSpeed.STANDARD, CharacterSex.MALE, 1), - SHADEFEMALE(2016, MonsterType.Shade, RunSpeed.STANDARD, CharacterSex.FEMALE, 1), - MINOMALE(2017, MonsterType.Minotaur, RunSpeed.MINOTAUR, CharacterSex.MALE, 1.3f), - ARCHONMALE(2018, MonsterType.Celestial, RunSpeed.STANDARD, CharacterSex.MALE, 1), - HALEGIANTOLDMALE(2019, MonsterType.HalfGiant, RunSpeed.STANDARD, CharacterSex.MALE, 1.15f), - CSRFEMALE(2020, MonsterType.CSR, RunSpeed.STANDARD, CharacterSex.FEMALE, 0.66000003f), - CSRMALE(2021, MonsterType.CSR, RunSpeed.STANDARD, CharacterSex.MALE, 1), - NEPHMALE(2025, MonsterType.Nephilim, RunSpeed.STANDARD, CharacterSex.MALE, 1.1f), - NEPHFEMALE(2026, MonsterType.Nephilim, RunSpeed.STANDARD, CharacterSex.FEMALE, 1.1f), - HALFGIANTFEMALE(2027, MonsterType.HalfGiant, RunSpeed.STANDARD, CharacterSex.FEMALE, 1.15f), - VAMPMALE(2028, MonsterType.Vampire, RunSpeed.STANDARD, CharacterSex.MALE, 1), - VAMPFEMALE(2029, MonsterType.Vampire, RunSpeed.STANDARD, CharacterSex.FEMALE, 1); - - @SuppressWarnings("unchecked") - private static HashMap _raceTypeByID = new HashMap<>(); - - int runeID; - private MonsterType monsterType; - private CharacterSex characterSex; - private RunSpeed runSpeed; - private float scaleHeight; - - RaceType(int runeID, MonsterType aggroType, RunSpeed runspeed, CharacterSex characterSex, float scaleHeight) { - this.runeID = runeID; - this.monsterType = aggroType; - this.runSpeed = runspeed; - this.characterSex = characterSex; - this.scaleHeight = scaleHeight; - } - - public static RaceType getRaceTypebyRuneID(int runeID) { - return _raceTypeByID.get(runeID); - } - - public static void initRaceTypeTables() { - - for (RaceType raceType : RaceType.values()) { - _raceTypeByID.put(raceType.runeID, raceType); - } - } - - public int getRuneID() { - return this.runeID; - } - - public float getScaleHeight() { - return this.scaleHeight; - } - - public MonsterType getMonsterType() { - return monsterType; - } - - public RunSpeed getRunSpeed() { - return runSpeed; - } - - public CharacterSex getCharacterSex() { - return characterSex; - } - } - - public enum RunSpeed { - - SENTINEL(0, 0, 0, 0, 0, 0, 0), - STANDARD(6.1900001f, 13.97f, 4.2199998f, 13.97f, 6.3299999f, 18.379999f, 6.5f), - CENTAUR(6.1900001f, 16.940001f, 5.5500002f, 16.940001f, 6.3299999f, 18.379999f, 6.5f), - MINOTAUR(6.6300001f, 15.95f, 4.2199998f, 15.95f, 6.3299999f, 18.379999f, 6.5f); - - private float walkStandard; - private float walkCombat; - private float runStandard; - private float runCombat; - private float swim; - private float flyRun; - private float flyWalk; - - RunSpeed(float walkStandard, float runStandard, float walkCombat, float runCombat, float flyWalk, float flyRun, float swim) { - this.walkStandard = walkStandard; - this.walkCombat = walkCombat; - this.runStandard = runStandard; - this.runCombat = runCombat; - this.swim = swim; - this.flyRun = flyRun; - this.flyWalk = flyWalk; - } - - - public float getWalkStandard() { - return walkStandard; - } - - public float getWalkCombat() { - return walkCombat; - } - - public float getRunStandard() { - return runStandard; - } - - public float getRunCombat() { - return runCombat; - } - - public float getFlyRun() { - return flyRun; - } - - - public float getFlyWalk() { - return flyWalk; - } - - } - - public enum FriendListType { - - VIEWHERALDRY(1), - ADDHERALDRY(4), - REMOVEHERALDRY(6), - DEALTHS(7), - KILLS(9), - VIEWCONDEMN(11), - ADDCONDEMN(14), - REMOVECONDEMN(15), - TOGGLEACTIVE(17), - REVERSEKOS(19), - VIEWFRIENDS(25), - TOITEM(23), - ADDFRIEND(28), - REMOVEFRIEND(30); - - private final int listType; - - FriendListType(int listType) { - this.listType = listType; - } - - public static FriendListType getListTypeByID(int listType) { - - FriendListType outType = null; - - for (FriendListType friendListType : FriendListType.values()) { - if (friendListType.listType == listType) - outType = friendListType; - } - return outType; - } - - } - - public enum DispatchChannel { - PRIMARY(0), - SECONDARY(1); - - private final int channelID; - - DispatchChannel(int channelID) { - this.channelID = channelID; - } - - public int getChannelID() { - return this.channelID; - } - - } - - public enum PvpHistoryType { - KILLS, - DEATHS; - } - - public enum ChatMessageType { - ERROR, - INFO, - MOTD; - } - - public enum DataRecordType { - PVP, - CHARACTER, - BANE, - GUILD, - CITY, - ZONE, - REALM, - MINE; - } - - public enum RecordEventType { - CREATE, // Shared with city/guild - DISBAND, - DESTROY, // City events - CAPTURE, - TRANSFER, - PENDING, - DEFEND, - LOST; // Realm event - } - - public enum CharterType { - FEUDAL(-600065291, 5060000), - MERCANTILE(-15978914, 5060400), - BELLIGERENT(762228431, 5060800); - - private int charterID; - private int meshID; - - CharterType(int charterID, int meshID) { - this.charterID = charterID; - this.meshID = meshID; - } - - public static CharterType getCharterTypeByID(int charterID) { - CharterType outType = null; - - for (CharterType charterType : CharterType.values()) { - if (charterType.charterID == charterID) - outType = charterType; - } - return outType; - } - - public int getMeshID() { - return meshID; - } - } - - - public enum ChatChannelType { - SYSTEM(1), - FLASH(2), - COMMANDER(3), - NATION(5), - LEADER(6), - SHOUT(7), - INFO(10), - GUILD(12), - INNERCOUNCIL(13), - GROUP(14), - CITY(15), - SAY(16), - EMOTE(17), - TELL(19), - COMBAT(20); - - private final int channelID; - - ChatChannelType(int channelID) { - this.channelID = channelID; - } - - public int getChannelID() { - return this.channelID; - } - } - - public enum OwnerType { - Npc, - PlayerCharacter, - Account, - Mob; - } - - public enum SiegePhase { - ERRANT, - CHALLENGE, - STANDOFF, - WAR, - CEASEFIRE; - } - - public enum SiegeResult { - PENDING, - DEFEND, - DESTROY, - CAPTURE; - } - - public enum TaxType { - PROFIT, - WEEKLY, - NONE; - - } - - public enum Ruins { - - ESTRAGOTH(569), - KARFELL(570), - MORELAN(571), - REGARS(572), - HALLOS(573), - WESTERMORE(574), - EYWAN(575), - CAER(576); - - private final int zoneUUID; - - Ruins(int uuid) { - this.zoneUUID = uuid; - } - - public static Ruins getRandomRuin() { - - Ruins ruins; - - ruins = Ruins.values()[ThreadLocalRandom.current() - .nextInt(Ruins.values().length)]; - - return ruins; - } - - public Vector3fImmutable getLocation() { - - Zone ruinZone; - Vector3fImmutable spawnLocation; - - // Send to SDR if so configured - - if (ConfigManager.MB_USE_RUINS.getValue().equalsIgnoreCase("true")) { - ruinZone = ZoneManager.getZoneByUUID(this.zoneUUID); - spawnLocation = Vector3fImmutable.getRandomPointOnCircle(ruinZone.getLoc(), 30); - } else { - ruinZone = ZoneManager.getZoneByName("sea dog's rest"); - - // 14001 does not have a banestone to bind at - - if (ruinZone.getLoadNum() == 14001) - spawnLocation = Vector3fImmutable.getRandomPointOnCircle(ruinZone.getLoc(), 30); - else - spawnLocation = Vector3fImmutable.getRandomPointOnCircle(ruinZone.getLoc() - .add(new Vector3fImmutable(-196.016f, 2.812f, 203.621f)), 30); - } - - - return spawnLocation; - } - - } - - public enum Guards { - - HumanArcher(13.97f, 13.97f, 6.19f, 4.2199998f, 18.38f, 6.33f, 6.5f), - HumanGuard(13.97f, 13.97f, 6.19f, 4.2199998f, 18.38f, 6.33f, 6.5f), - HumanMage(13.97f, 13.97f, 6.19f, 4.2199998f, 18.38f, 6.33f, 6.5f), - UndeadArcher(14.67f, 14.67f, 6.5f, 4.44f, 18.38f, 6.33f, 6.5f), - UndeadGuard(14.67f, 14.67f, 6.5f, 4.44f, 18.38f, 6.33f, 6.5f), - UndeadMage(14.67f, 14.67f, 6.5f, 4.44f, 18.38f, 6.33f, 6.5f); - - private final float runSpeed; - private final float runCombatSpeed; - private final float walkSpeed; - private final float walkCombatSpeed; - private final float fly; - private final float flyWalk; - private final float swim; - - Guards(float runSpeed, float runCombatSpeed, float walkSpeed, float walkCombatSpeed, float fly, float flyWalk, float swim) { - this.runSpeed = runSpeed; - this.runCombatSpeed = runCombatSpeed; - this.walkSpeed = walkSpeed; - this.walkCombatSpeed = walkCombatSpeed; - this.fly = fly; - this.flyWalk = flyWalk; - this.swim = swim; - } - - public float getRunSpeed() { - return runSpeed; - } - - public float getRunCombatSpeed() { - return runCombatSpeed; - } - - public float getWalkSpeed() { - return walkSpeed; - } - - public float getWalkCombatSpeed() { - return walkCombatSpeed; - } - - public float getFly() { - return fly; - } - - public float getSwim() { - return swim; - } - - public float getFlyWalk() { - return flyWalk; - } - } - - public enum PortalType { - - EARTH(6f, 19.5f, 128), - AIR(-6f, 19.5f, 256), - FIRE(15f, 7.5f, 512), - WATER(-15f, 8.5f, 1024), - SPIRIT(0, 10.5f, 2048), - CHAOS(22f, 3.5f, 8192), - OBLIV(0f, 42f, 16384), - MERCHANT(-22f, 4.5f, 4096), - FORBID(0.0f, 0.0f, 0); - - public final Vector2f offset; - public final int effectFlag; - - PortalType(float offsetX, float offsetY, int effectFlag) { - - this.offset = new Vector2f(offsetX, offsetY); - this.effectFlag = effectFlag; - - } - } - - - // Enum for ItemBase flags - - public enum ItemType { - DECORATION(0), - WEAPON(1), - ARMOR(2), - HAIR(3), - GOLD(4), - RUNE(5), - SCROLL(5), - BOOK(6), - COMMANDROD(7), - POTION(8), - TEARS(8), - KEY(9), - GUILDCHARTER(10), - JEWELRY(13), - WINE(16), - ALEJUG(17), - DEED(19), - CONTRACT(20), - PET(21), - FURNITURE(25), - BEDROLL(26), - FARMABLE(27), - WATERBUCKET(30), - GIFT(31), - OFFERING(33), - RESOURCE(34), - REALMCHARTER(35); - - private final static HashMap _typeLookup = new HashMap<>(); - private final int _value; - - ItemType(int value) { - this._value = value; - } - - public static ItemType getByValue(int value) { - - ItemType outType = ItemType.DECORATION; - - if (_typeLookup.isEmpty()) { - - for (ItemType itemType : ItemType.values()) { - _typeLookup.put(itemType._value, itemType); - } - } - - if (_typeLookup.containsKey(value)) - outType = _typeLookup.get(value); - - return outType; - } - - /** - * @return the _value - */ - public int getValue() { - return _value; - } - - } - // Enum to derive effects for active spires from blueprintUUID - - public enum SpireType { - - WATCHFUL(1800100, (1 << 23), -1139520957), - GROUNDING(1800400, (1 << 24), -1733819072), - BINDING(1800700, (1 << 25), -1971545187), - WARDING(1801000, (1 << 26), 2122002462), - GUILEFUL(1801300, (1 << 27), -1378972677), - BALEFUL(1801600, -1, 1323012132), - ARCANE(1801900, (1 << 30), 1323888676), - WOUNDING(1802200, (1 << 10), 1357392095), - WEARYING(1802500, (1 << 10), 1350838495), - CONFUSING(1802800, (1 << 10), 1358702815), - CHILLING(1803100, (1 << 1), 1332155165), - SEARING(1803400, (1 << 2), -1401744610), - THUNDERING(1803700, (1 << 3), -443544829), - UNHOLY(1804000, (1 << 4), 1330320167), - BEFUDDLING(1804300, (1 << 5), 1489317547), - WRATHFUL(1804600, (1 << 6), 165160210), - SPITEFUL(1804900, (1 << 7), 1238906779), - ENFEEBLING(1805200, (1 << 8), -908578401), - CONFOUNDING(1805500, (1 << 9), 165165842), - DISTRACTING(1805800, (1 << 10), 1238906697), - WOLFPACK(1806100, (1 << 4), 416932375); - - private final int blueprintUUID; - private final int effectFlag; - private final int token; - - SpireType(int blueprint, int flag, int token) { - this.blueprintUUID = blueprint; - this.effectFlag = flag; - this.token = token; - } - - public static SpireType getByBlueprintUUID(int uuid) { - - SpireType outType = SpireType.GROUNDING; - - for (SpireType spireType : SpireType.values()) { - - if (spireType.blueprintUUID == uuid) { - outType = spireType; - return outType; - } - - } - - return outType; - } - - public int getBlueprintUUID() { - return blueprintUUID; - } - - public int getEffectFlag() { - return effectFlag; - } - - public int getToken() { - return token; - } - - public EffectsBase getEffectBase() { - return PowersManager.getEffectByToken(token); - } - - } - - public enum TransactionType { - MAINTENANCE(43), - WITHDRAWL(80), - DEPOSIT(82), - MINE(81), - MIGRATION(83), - PLAYERREWARD(84), - TAXRESOURCE(85), - TAXRESOURCEDEPOSIT(86); - - private final int ID; - - TransactionType(int ID) { - this.ID = ID; - } - - public int getID() { - return ID; - } - } - - public enum TargetColor { - - White, - Green, - Cyan, - Blue, - Yellow, - Orange, - Red; - - public static TargetColor getCon(AbstractCharacter source, - AbstractCharacter target) { - return getCon(source.getLevel(), target.getLevel()); - } - - public static TargetColor getCon(short sourceLevel, short targetLevel) { - if (targetLevel > (sourceLevel + 2)) - return Red; - else if (targetLevel == (sourceLevel + 2)) - return Orange; - else if (targetLevel == (sourceLevel + 1)) - return Yellow; - - short lowestBlue = (short) (sourceLevel - (((sourceLevel / 5)) + 2)); - - if (lowestBlue <= targetLevel) - return Blue; - else if (lowestBlue - 1 <= targetLevel) - return Cyan; - else if (lowestBlue - 2 <= targetLevel) - return Green; - return White; - } - } - - public enum DamageType { - None, - Crush, - Slash, - Siege, - Pierce, - Magic, - Bleed, - Poison, - Mental, - Holy, - Unholy, - Lightning, - Fire, - Cold, - Healing, - Acid, - Disease, - Unknown, - // these added for immunities - Attack, - Powers, - Combat, - Spires, - Snare, - Stun, - Blind, - Root, - Fear, - Charm, - PowerBlock, - DeBuff, - Powerblock, - Steel, - Drain; - - public static DamageType GetDamageType(String modName) { - DamageType damageType; - if (modName.isEmpty()) - return DamageType.None; - - try { - damageType = DamageType.valueOf(modName.replace(",", "")); - } catch (Exception e) { - Logger.error(e); - return DamageType.None; - } - return damageType; - } - } - - - public enum SourceType { - None, - Abjuration, - Acid, - AntiSiege, - Archery, - Axe, - Bardsong, - Beastcraft, - Benediction, - BladeWeaving, - Bleed, - Blind, - Block, - Bloodcraft, - Bow, - Buff, - Channeling, - Charm, - Cold, - COLD, - Constitution, - Corruption, - Crossbow, - Crush, - Dagger, - DaggerMastery, - DeBuff, - Dexterity, - Disease, - Dodge, - Dragon, - Drain, - Earth, - Effect, - Exorcism, - Fear, - Fire, - FIRE, - Fly, - Giant, - GreatAxeMastery, - GreatSwordMastery, - Hammer, - Heal, - Healing, - Holy, - HOLY, - ImmuneToAttack, - ImmuneToPowers, - Intelligence, - Invisible, - Lightning, - LIGHTNING, - Liturgy, - Magic, - MAGIC, - Mental, - MENTAL, - NatureLore, - Necromancy, - Parry, - Pierce, - Poison, - POISON, - PoleArm, - Powerblock, - Rat, - ResistDeBuff, - Restoration, - Root, - Shadowmastery, - Siege, - Slash, - Snare, - Sorcery, - Spear, - SpearMastery, - Spirit, - Staff, - Stormcalling, - Strength, - Stun, - Summon, - Sword, - SwordMastery, - Thaumaturgy, - Theurgy, - Transform, - UnarmedCombat, - UnarmedCombatMastery, - Unholy, - UNHOLY, - Unknown, - Warding, - Warlockry, - WayoftheGaana, - WearArmorHeavy, - WearArmorLight, - WearArmorMedium, - Wereform, - Athletics, - AxeMastery, - Bargaining, - BladeMastery, - FlameCalling, - GreatHammerMastery, - HammerMastery, - Leadership, - PoleArmMastery, - Running, - StaffMastery, - Throwing, - Toughness, - WayoftheWolf, - WayoftheRat, - WayoftheBear, - Orthanatos, - SunDancing, - //Power categories. - AE, - AEDAMAGE, - BEHAVIOR, - BLESSING, - BOONCLASS, - BOONRACE, - BREAKFLY, - BUFF, - CHANT, - DAMAGE, - DEBUFF, - DISPEL, - FLIGHT, - GROUPBUFF, - GROUPHEAL, - HEAL, - INVIS, - MOVE, - RECALL, - SPECIAL, - SPIREDISABLE, - SPIREPROOFTELEPORT, - STANCE, - STUN, - SUMMON, - TELEPORT, - THIEF, - TRACK, - TRANSFORM, - VAMPDRAIN, - WEAPON, - Wizardry; - - public static SourceType GetSourceType(String modName) { - SourceType returnMod; - if (modName.isEmpty()) - return SourceType.None; - - try { - returnMod = SourceType.valueOf(modName.replace(",", "")); - } catch (Exception e) { - Logger.error(modName); - Logger.error(e); - return SourceType.None; - } - return returnMod; - } - } - - public enum EffectSourceType { - None, - AttackSpeedBuff, - Bleeding, - Blind, - Buff, - Chant, - Charm, - Cold, - Combat, - ConstitutionBuff, - Crush, - DamageShield, - DeathShroud, - DeBuff, - Disease, - Drain, - Earth, - Effect, - Fear, - Fire, - Flight, - Fortitude, - Heal, - Holy, - Invisibility, - Invulnerability, - Lightning, - Magic, - Mental, - Multielement, - PetBuff, - Pierce, - Poison, - Powerblock, - RecoveryManaBuff, - ResistDeBuff, - Root, - Siege, - SiegeBuff, - SiegeDamage, - Silence, - Slash, - Snare, - Stance, - Stun, - Summon, - Transform, - Unholy, - Wereform, - WereformATRBuff, - WereformConBuff, - WereformDexBuff, - WereformHPRecBuff, - WereformMoveBuff, - WereformPhysResBuff, - WereformSPRecBuff, - WereformStrBuff; - - public static EffectSourceType GetEffectSourceType(String modName) { - EffectSourceType returnMod; - if (modName.isEmpty()) - return EffectSourceType.None; - - try { - returnMod = EffectSourceType.valueOf(modName.replace(",", "")); - } catch (Exception e) { - Logger.error(e); - return EffectSourceType.None; - } - return returnMod; - } - } - - public enum StackType { - None, - AggRangeDeBuff, - ArcheryPrecisionBuff, - AttackDebuff, - AttackSpeedBuff, - AttackSpeedDeBuff, - AttackValueBuff, - AttackValueDebuff, - AttrCONBuff, - AttrCONDebuff, - AttrDEXBuff, - AttrINTBuff, - AttrSPRBuff, - AttrSTRBuff, - Bleeding, - Blindness, - BluntResistanceDebuff, - BMHealing, - Charm, - ClassBoon, - Confusion, - DamageAbsorber, - DamageDebuff, - DamageModifierBuff, - DamageShield, - DeathShroud, - DefenseBuff, - DefenseBuffGroup, - DefenseDebuff, - DetectInvis, - DrainImmunity, - ElementalDeBuff, - EnchantWeapon, - Fear, - Flight, - Frenzy, - GroupHeal, - HealingBuff, - HealOverTime, - HealResBuff, - HealthPotion, - IgnoreStack, - Invisible, - ManaPotion, - MangonelFire, - MeleeDamageDeBuff, - MeleeDeBuff, - MoveBuff, - MoveDebuff, - NoFear, - NoPassiveDefense, - NoPowerBlock, - NoPowerInhibitor, - NoRecall, - NoSnare, - NoStun, - NoTrack, - PassiveDefense, - PersAttrSPRBuff, - PetBuff, - PierceResistanceDebuff, - PoisonBuchinine, - PoisonGalpa, - PoisonGorgonsVenom, - PoisonMagusbane, - PoisonPellegorn, - PowerBlock, - PowerCostBuff, - PowerDamageModifierBuff, - PowerInhibitor, - PrecisionBuff, - Protection, - RaceBoon, - RecoveryHealthBuff, - RecoveryHealthDeBuff, - RecoveryManaBuff, - RecoveryManaDeBuff, - RecoveryStaminaBuff, - RecoveryStaminaDeBuff, - ResistanceBuff, - ResistanceDeBuff, - ResistanceDebuff, - Root, - SafeMode, - SelfOneAttrBuff, - SelfThreeAttrBuff, - SelfTwoAttrBuff, - SiegeDebuff, - SiegeWeaponBuff, - Silence, - SkillDebuff, - SlashResistanceDebuff, - Snare, - StackableAttrCONBuff, - StackableAttrDEXBuff, - StackableAttrSTRBuff, - StackableDefenseBuff, - StackableRecoveryHealthBuff, - StackableRecoveryStaminaBuff, - StaminaPotion, - StanceA, - StanceB, - Stun, - Track, - Transform, - WeaponMove; - - public static StackType GetStackType(String modName) { - StackType stackType; - if (modName.isEmpty()) - return StackType.None; - - try { - stackType = StackType.valueOf(modName.replace(",", "")); - } catch (Exception e) { - Logger.error(modName); - Logger.error(e); - return StackType.None; - } - return stackType; - } - } - - public enum ModType { - None, - AdjustAboveDmgCap, - Ambidexterity, - AnimOverride, - ArmorPiercing, - AttackDelay, - Attr, - BlackMantle, - BladeTrails, - Block, - BlockedPowerType, - CannotAttack, - CannotCast, - CannotMove, - CannotTrack, - Charmed, - ConstrainedAmbidexterity, - DamageCap, - DamageShield, - DCV, - Dodge, - DR, - Durability, - ExclusiveDamageCap, - Fade, - Fly, - Health, - HealthFull, - HealthRecoverRate, - IgnoreDamageCap, - IgnorePassiveDefense, - ImmuneTo, - ImmuneToAttack, - ImmuneToPowers, - Invisible, - ItemName, - Mana, - ManaFull, - ManaRecoverRate, - MaxDamage, - MeleeDamageModifier, - MinDamage, - NoMod, - OCV, - Parry, - PassiveDefense, - PowerCost, - PowerCostHealth, - PowerDamageModifier, - ProtectionFrom, - Resistance, - ScaleHeight, - ScaleWidth, - ScanRange, - SeeInvisible, - Silenced, - Skill, - Slay, - Speed, - SpireBlock, - Stamina, - StaminaFull, - StaminaRecoverRate, - Stunned, - Value, - WeaponProc, - WeaponRange, - WeaponSpeed; - - public static ModType GetModType(String modName) { - ModType modType; - if (modName.isEmpty()) - return ModType.None; - - try { - modType = ModType.valueOf(modName.replace(",", "")); - } catch (Exception e) { - Logger.error(e); - return ModType.None; - } - return modType; - } - } - - public enum MovementState { - - IDLE, - SITTING, - RUNNING, - FLYING, - SWIMMING; - } - - public enum DoorState { - - OPEN, - CLOSED, - LOCKED, - UNLOCKED; - } - - // Used with stored procedure GET_UID_ENUM() for - // type tests against objects not yet loaded into the game. - public enum DbObjectType { - - INVALID, - ACCOUNT, - BUILDING, - CHARACTER, - CITY, - CONTAINER, - GUILD, - ITEM, - MINE, - MOB, - NPC, - SHRINE, - WORLDSERVER, - ZONE, - WAREHOUSE; - } - - ; - - /** - * Enumeration of Building Protection Status stored in the database as a - * mysql enumfield. WARNING: This enumeration is fragile. Do not rename. Do - * not reorder. - */ - public enum ProtectionState { - - NONE, - PROTECTED, - UNDERSIEGE, - CEASEFIRE, - CONTRACT, - DESTROYED, - PENDING, - NPC; - } - - ; - - public enum CharacterSkills { - - Archery((1L << 1), -529201545, 20), - Athletics((1L << 2), -327713877, 15), - AxeMastery((1L << 3), 1103042709, 20), - Axe((1L << 4), 73505, 1), - Bardsong((1L << 5), 454246953, 10), - Bargaining((1L << 6), 372927577, 10), - Beastcraft((1L << 7), 56772766, 10), - Benediction((1L << 8), 1464998706, 1), - BladeMastery((1L << 9), -59908956, 20), - BladeWeaving((1L << 10), -1839362429, 20), - Block((1L << 11), 76592546, 3), - Bow((1L << 12), 87490, 1), - Channeling((1L << 13), -1899060872, 20), - Crossbow((1L << 14), 1092138184, 1), - DaggerMastery((1L << 15), -1549224741, 20), - Dagger((1L << 16), -1603103740, 1), - Dodge((1L << 17), 74619332, 5), - FlameCalling((1L << 18), -1839578206, 20), - GreatAxeMastery((1L << 19), 1427003458, 20), - GreatHammerMastery((1L << 20), -309659310, 20), - GreatSwordMastery((1L << 21), 2054956946, 20), - HammerMastery((1L << 22), -1548903209, 20), - Hammer((1L << 23), -1602765816, 1), - Leadership((1L << 24), 1618560984, 20), - Liturgy((1L << 25), -888415974, 10), - NatureLore((1L << 26), -1911171474, 10), - Parry((1L << 27), 95961104, 5), - PoleArmMastery((1L << 28), -1432303709, 20), - PoleArm((1L << 29), -1037845588, 1), - Restoration((1L << 30), -504697054, 1), - Running((1L << 31), 1488335491, 10), - Shadowmastery((1L << 32), 1389222957, 10), - Sorcery((1L << 33), -529481275, 1), - SpearMastery((1L << 34), -48279755, 20), - Spear((1L << 35), 83992115, 1), - StaffMastery((1L << 36), -61022283, 20), - Staff((1L << 37), 71438003, 1), - Stormcalling((1L << 38), -532064061, 10), - SwordMastery((1L << 39), -59316267, 20), - Sword((1L << 40), 73938643, 1), - Thaumaturgy((1L << 41), -2020131447, 10), - Theurgy((1L << 42), -888431326, 10), - Throwing((1L << 43), 391562015, 20), - Toughness((1L << 44), -660435875, 10), - UnarmedCombatMastery((1L << 45), 1692733771, 20), - UnarmedCombat((1L << 46), -1094332856, 1), - Warding((1L << 47), 1488142342, 1), - Warlockry((1L << 48), 1121393557, 10), - WayoftheGaana((1L << 49), -1954832975, 10), - WearArmorHeavy((1L << 50), 1112121635, 15), - WearArmorLight((1L << 51), 38031547, 1), - WearArmorMedium((1L << 52), 468015203, 5), - Wizardry((1L << 53), 218227659, 10), - Corruption((1L << 54), -1519268706, 10), - Abjuration((1L << 55), -2029900484, 10), - WayoftheWolf((1L << 56), 1668913067, 20), - WayoftheRat((1L << 57), -2114353637, 20), - WayoftheBear((1L << 58), -906390863, 20), - Orthanatos((1L << 59), -666929185, 20), - Bloodcraft((1L << 60), 40661438, 10), - Exorcism((1L << 61), 1444427097, 10), - Necromancy((1L << 62), -556571154, 10), - SunDancing((1L << 63), 22329752, 20); - - private long flag; - private int token; - private int reqLvl; - - CharacterSkills(long flag, int token, int reqLvl) { - this.flag = flag; - this.token = token; - this.reqLvl = reqLvl; - } - - public static CharacterSkills GetCharacterSkillByToken(int token) { - for (CharacterSkills skill : CharacterSkills.values()) { - if (skill.token == token) - return skill; - } - - Logger.info("Returned No Skill for token " + token + ". Defaulting to Axe"); - return CharacterSkills.Axe; - } - - public long getFlag() { - return flag; - } - - public void setFlag(long flag) { - this.flag = flag; - } - - public int getReqLvl() { - return this.reqLvl; - } - - public int getToken() { - return token; - } - - public void setToken(int token) { - this.token = token; - } - } - - ; - - public enum GuildHistoryType { - JOIN(1), - LEAVE(4), - BANISHED(3), - CREATE(7), - DISBAND(5); - private final int type; - - GuildHistoryType(int type) { - this.type = type; - } - - public int getType() { - return type; - } - } - - public enum SexType { - NONE, - MALE, - FEMALE; - } - - public enum ClassType { - FIGHTER, - HEALER, - ROGUE, - MAGE; - } - - public enum PromoteType { - Assassin(SexType.NONE), - Barbarian(SexType.NONE), - Bard(SexType.NONE), - Channeler(SexType.NONE), - Confessor(SexType.NONE), - Crusader(SexType.NONE), - Doomsayer(SexType.NONE), - Druid(SexType.NONE), - Fury(SexType.FEMALE), - Huntress(SexType.FEMALE), - Prelate(SexType.NONE), - Priest(SexType.NONE), - Ranger(SexType.NONE), - Scout(SexType.NONE), - Sentinel(SexType.NONE), - Templar(SexType.NONE), - Thief(SexType.NONE), - Warlock(SexType.MALE), - Warrior(SexType.NONE), - Wizard(SexType.NONE), - Nightstalker(SexType.NONE), - Necromancer(SexType.NONE), - ; - - private SexType sexRestriction; - - PromoteType(SexType sexRestriction) { - this.sexRestriction = sexRestriction; - } - - public SexType getSexRestriction() { - return sexRestriction; - } - } - - public enum ShrineType { - - Aelfborn(1701900, -75506007, true), - Aracoix(1703100, -563708986, true), - Centaur(1704000, 521645243, true), - Dwarf(1708500, -2000467257, true), - Elf(1703400, 1254603001, true), - HalfGiant(1709100, 349844468, true), - Human(1702200, 281172391, true), - Irekei(1702800, -764988442, true), - Minotaur(1704600, 549787579, true), - Nephilim(1701000, -655183799, true), - Shade(1700100, 1724071104, true), - Assassin(1700400, 1989015892, false), - Barbarian(1708800, 9157124, false), - Bard(1704300, 80190554, false), - Channeler(1702500, 5658278, false), - Confessor(1707600, 1871658719, false), - Crusader(1706700, -187454619, false), - Doomsayer(1700700, -993659433, false), - Druid(1701600, -926740122, false), - Fury(1705500, 214401375, false), - Huntress(1704900, 970312892, false), - Prelate(1707000, -225200922, false), - Priest(1705200, -535691898, false), - Ranger(1701300, 604716986, false), - Scout(1706100, -1497297486, false), - Sentinel(1707300, -184898375, false), - Templar(1707900, 826673315, false), - Thief(1708200, 1757633920, false), - Warlock(1706400, 1003385946, false), - Warrior(1703700, 931048026, false), - Wizard(1705800, 777115928, false), - Nightstalker(1709400, 373174890, false), - Necromancer(1709700, -319294505, false), - Vampire(1710000, 1049274530, true); - - private final int blueprintUUID; - private final int powerToken; - private final ArrayList shrines = new ArrayList<>(); - private final boolean isRace; - - ShrineType(int blueprintUUID, int powerToken, boolean isRace) { - this.blueprintUUID = blueprintUUID; - this.powerToken = powerToken; - this.isRace = isRace; - - } - - public int getBlueprintUUID() { - return blueprintUUID; - } - - public int getPowerToken() { - return powerToken; - } - - public ArrayList getShrinesCopy() { - ArrayList copyShrines = new ArrayList<>(); - copyShrines.addAll(shrines); - Collections.sort(copyShrines); - return copyShrines; - } - - public final void addShrineToServerList(Shrine shrine) { - synchronized (shrines) { - shrines.add(shrine); - } - } - - public final void RemoveShrineFromServerList(Shrine shrine) { - synchronized (shrines) { - shrines.remove(shrine); - } - } - - public boolean isRace() { - return isRace; - } - } - - public enum GuildState { - - Errant(0), - Sworn(4), - Protectorate(6), - Petitioner(2), - Province(8), - Nation(5), - Sovereign(7); - - private final int stateID; - - GuildState(int stateID) { - this.stateID = stateID; - } - - public int getStateID() { - return stateID; - } - - } - - - // Building group enumeration. - // This is used to drive linear equations to calculate - // structure hp, ranking times and such from within - // the BuildingBlueprint class. - // - // It is also used as a bitvector flag in the npc - // building slot mechanics. - - public enum BuildingGroup implements EnumBitSetHelper { - NONE(0, 0), - TOL(64f, 64f), - BARRACK(32f, 64f), - CHURCH(64f, 64f), - FORGE(32f, 64f), - SPIRE(16f, 16f), - GENERICNOUPGRADE(16f, 16f), - WALLSTRAIGHT(16f, 64), - WALLCORNER(64f, 64f), - SMALLGATE(64f, 64), - ARTYTOWER(64f, 64), - SIEGETENT(32f, 32f), - BANESTONE(16f, 16f), - MINE(16f, 16f), - WAREHOUSE(32f, 32f), - SHRINE(16f, 16f), - RUNEGATE(64f, 64f), - AMAZONHALL(64f, 64f), - CATHEDRAL(64f, 64f), - GREATHALL(64f, 64f), - KEEP(64f, 64f), - THIEFHALL(64f, 24f), - TEMPLEHALL(64f, 64f), - WIZARDHALL(64f, 64f), - ELVENHALL(64f, 64f), - ELVENSANCTUM(64f, 64f), - IREKEIHALL(64f, 64f), - FORESTHALL(64f, 64f), - MAGICSHOP(32f, 32f), - BULWARK(32f, 32f), - SHACK(16f, 16f), - INN(64f, 32f), - TAILOR(32f, 32f), - VILLA(64f, 32f), - ESTATE(64f, 64f), - FORTRESS(64f, 64f), - CITADEL(64f, 64f), - WALLSTRAIGHTTOWER(16f, 64), - WALLSTAIRS(64, 64); - - private final Vector2f extents; - - BuildingGroup(float extentX, float extentY) { - this.extents = new Vector2f(extentX, extentY); - } - - public Vector2f getExtents() { - return extents; - } - - } - - public enum UpdateType { - ALL, - MOVEMENT, - REGEN, - FLIGHT, - LOCATION, - MOVEMENTSTATE; - } - - public enum ServerType { - WORLDSERVER, - LOGINSERVER, - NONE; - } - - public enum ChatChannel implements EnumBitSetHelper { - System, - Announce, - Unknown, - Commander, - Address, - Nation, - Leader, - Shout, - Siege, - Territory, - Info, - CSR, - Guild, - InnerCouncil, - Group, - City, - Say, - Emote, - Social, - Tell, - Combat, - Powers, - Snoop, - Debug, - Global, - Trade, - PVP, - Mine, - Alert, - Assassin, - Barbarian, - Bard, - Channeler, - Confessor, - Crusader, - Doomsayer, - Druid, - Fury, - Huntress, - Necromancer, - Nightstalker, - Prelate, - Priest, - Ranger, - Scout, - Sentinel, - Templar, - Thief, - Warlock, - Warrior, - Wizard; - - } - - public enum AllianceType { - RecommendedAlly, - RecommendedEnemy, - Ally, - Enemy; - } - - public enum FriendStatus { - Available, - Away, - Busy; - } - - public enum ProfitType { - - - BuyNormal("buy_normal"), - BuyGuild("buy_guild"), - BuyNation("buy_nation"), - SellNormal("sell_normal"), - SellGuild("sell_guild"), - SellNation("sell_nation"); - - public String dbField; - - private ProfitType(String dbField) { - this.dbField = dbField; - } - } - - public enum GameObjectType { - - /* - * These will be used as the 4 high bytes in the application protocol's - * long CompositeID field and when tracking an AbstractGameObject's type - * from within the code. The low 4 bytes will be used as the Object's - * UUID - */ - unknown, - Account, - AccountIP, - ActiveEffect, - ArmorBase, - BaseClass, - BeardStyle, - BlockedIP, - Building, - BuildingLocation, - BuildingModelBase, - CharacterPower, - CharacterPowers, - CharacterRune, - CharacterSkill, - City, - Contract, - Corpse, - CSSession, - EffectsResourceCosts, - EnchantmentBase, - GenericItemBase, - Group, - Guild, - GuildAllianceEnemy, - GuildBanish, - GuildCharacterKOS, - GuildGuildKOS, - GuildTableList, - HairStyle, - Item, - ItemContainer, - ItemEnchantment, - JewelryBase, - Kit, - MenuOption, - Mine, - Mob, - MobBase, - MobEquipment, - MobLoot, - MobType, - NPC, - NPCClassRune, - NPCClassRuneThree, - NPCClassRuneTwo, - NPCExtraRune, - NPCRaceRune, - NPCRune, - NPCShopkeeperRune, - NPCTrainerRune, - Nation, - PlayerCharacter, - PlayerInfo, - PowerGrant, - PowerReq, - PowersBase, - PowersBaseAttribute, - PromotionClass, - Race, - RuneBase, - RuneBaseAttribute, - RuneBaseEffect, - SkillReq, - SkillsBase, - SkillsBaseAttribute, - MobileBooty, - StrongBox, - Trigger, - ValidRaceBeardStyle, - ValidRaceClassCombo, - ValidRaceHairStyle, - VendorDialog, - Warehouse, - WeaponBase, - WorldServerInfo, - WorldServerInfoSnapshot, - Shrine, - Zone, - Transaction; - } - - public enum ContainerType { - BANK, - INVENTORY, - VAULT; - } - - ; - - public enum CompoundCurveType { - DefaultFlat(0), - DefaultSlope(1), - DefaultSlopeDown(-1), - SL0001Up(0.01), - SL0003Up(0.03), - SL0005Up(0.05), - SL0006Up(0.06), - SL0007Up(0.07), - SL0008Up(0.08), - SL0010Up(0.10), - SL0011Up(0.11), - SL0012Up(0.12), - SL0013Up(0.13), - SL0014Up(0.14), - SL00143U(0.143), - SL0015Up(0.15), - SL0016Up(0.16), - SL0019Up(0.19), - SL0020Up(0.20), - SL0021Up(0.21), - SL0022Up(0.22), - SL0023Up(0.23), - SL0024Up(0.24), - SL0025Up(0.25), - SL0026Up(0.26), - SL0028Up(0.28), - SL0030Up(0.30), - SL0031Up(0.31), - SL0032Up(0.32), - SL0033Up(0.33), - SL0034Up(0.34), - SL0035Up(0.35), - SL0037Up(0.37), - SL0038Up(0.38), - SL0039Up(0.39), - SL0040Up(0.40), - SL0041Up(0.41), - SL0042Up(0.42), - SL0043Up(0.43), - SL0044Up(0.44), - SL0045Up(0.45), - SL0046Up(0.46), - SL0047Up(0.47), - SL0048Up(0.48), - SL0050Up(0.50), - SL0051Up(0.51), - SL0053Up(0.53), - SL0054Up(0.54), - SL0055Up(0.55), - SL0056Up(0.56), - SL0057Up(0.57), - SL0058Up(0.58), - SL0060Up(0.60), - SL0061Up(0.61), - SL0063Up(0.63), - SL0064Up(0.64), - SL0065Up(0.65), - SL0066Up(0.66), - SL0067Up(0.67), - SL0068Up(0.68), - SL0069Up(0.69), - SL0070Up(0.70), - SL0071Up(0.71), - SL0073Up(0.73), - SL0074Up(0.74), - SL0075Up(0.75), - SL0076Up(0.76), - SL0077Up(0.77), - SL0079Up(0.79), - SL0080Up(0.80), - SL0081Up(0.81), - SL0082Up(0.82), - SL0083Up(0.83), - SL0084Up(0.84), - SL0085Up(0.85), - SL0087Up(0.87), - SL0088Up(0.88), - SL0089Up(0.89), - SL0090Up(0.90), - SL0092Up(0.92), - SL0098Up(0.98), - SL0100Up(1.00), - SL0106Up(1.06), - SL0109Up(1.09), - SL0112Up(1.12), - SL0113Up(1.13), - SL0115Up(1.15), - SL0116Up(1.16), - SL0122Up(1.22), - SL0123Up(1.23), - SL0125Up(1.25), - SL0128Up(1.28), - SL0130Up(1.30), - SL0135Up(1.35), - SL0140Up(1.40), - SL0143Up(1.43), - SL0145Up(1.45), - SL0150Up(1.50), - SL0154Up(1.54), - SL0163Up(1.63), - SL0166Up(1.66), - SL0175Up(1.75), - SL0188Up(1.88), - SL0190Up(1.90), - SL0200Up(2.00), - SL0222Up(2.22), - SL0225Up(2.25), - SL0235Up(2.35), - SL0238Up(2.38), - SL0250Up(2.50), - SL0260Up(2.60), - SL0263Up(2.63), - SL0275Up(2.75), - SL0280Up(2.80), - SL0300Up(3.00), - SL0308Up(3.08), - SL0312Up(3.12), - SL0350Up(3.50), - SL0357Up(3.57), - SL0360Up(3.60), - SL0375Up(3.75), - SL0380Up(3.80), - SL0385Up(3.85), - SL0400Up(4.00), - SL0410Up(4.10), - SL0429Up(4.29), - SL0450Up(4.50), - SL0460Up(4.60), - SL0480Up(4.80), - SL0500Up(5.00), - SL0510Up(5.10), - SL0550Up(5.50), - SL0600Up(6.00), - SL0643Up(6.43), - SL0714Up(7.14), - SL0750Up(7.50), - SL0790Up(7.90), - SL0800Up(8.00), - SL0900Up(9.00), - SL1000Up(10.00), - SL1050Up(10.50), - SL1100Up(11.00), - SL1125Up(11.25), - SL1200Up(12.00), - SL1282Up(12.82), - SL1300Up(13.00), - SL1350Up(13.50), - SL1400Up(14.00), - SL1500Up(15.00), - SL1579Up(15.79), - SL2000Up(20.00), - SL2100Up(21.00), - SL2500Up(25.00), - SL2521Up(25.21), - SL3000Up(30.00), - SL4000Up(40.00), - SL5000Up(50.00), - SL6000Up(60.00), - SL7500Up(75.00), - SL8000Up(80.00), - SL12000Up(120.00), - SL14000Up(140.00), - SL30000Up(300.00), - SL66600Up(666.00), - SL71500Up(715.00), - SL00003Down(-0.003), - SL0001Down(-0.01), - SL0003Down(-0.03), - SL0004Down(-0.04), - SL0005Down(-0.05), - SL0006Down(-0.06), - SL0007Down(-0.07), - SL00075Down(-0.075), - SL0008Down(-0.08), - SL0009Down(-0.09), - SL0010Down(-0.10), - SL0011Down(-0.11), - SL0012Down(-0.12), - SL0013Down(-0.13), - SL00125Down(-0.125), - SL0014Down(-0.14), - SL0015Down(-0.15), - SL0016Down(-0.16), - SL0017Down(-0.17), - SL00175Down(-0.175), - SL0018Down(-0.18), - SL0019Down(-0.19), - SL0020Down(-0.20), - SL0023Down(-0.23), - SL0024Down(-0.24), - SL0025Down(-0.25), - SL0027Down(-0.27), - SL0028Down(-0.28), - SL0029Down(-0.29), - SL0030Down(-0.30), - SL0032Down(-0.32), - SL0033Down(-0.33), - SL0035Down(-0.35), - SL0038Down(-0.38), - SL0040Down(-0.40), - SL0044Down(-0.44), - SL0045Down(-0.45), - SL0050Down(-0.50), - SL0055Down(-0.55), - SL0060Down(-0.60), - SL0062Down(-0.62), - SL0063Down(-0.63), - SL0064Down(-0.64), - SL0066Down(-0.66), - SL0069Down(-0.69), - SL0071Down(-0.71), - SL0075Down(-0.75), - SL0077Down(-0.77), - SL0079Down(-0.79), - SL0080Down(-0.80), - SL0090Down(-0.90), - SL0100Down(-1.00), - SL0113Down(-1.13), - SL0120Down(-1.20), - SL0125Down(-1.25), - SL0128Down(-1.28), - SL0130Down(-1.30), - SL0135Down(-1.35), - SL0150Down(-1.50), - SL0175Down(-1.75), - SL0188Down(-1.88), - SL0200Down(-2.00), - SL0225Down(-2.25), - SL0250Down(-2.50), - SL0263Down(-2.63), - SL0300Down(-3.00), - SL0357Down(-3.57), - SL0385Down(-3.85), - SL0429Down(-4.29), - SL0450Down(-4.50), - SL0500Down(-5.00), - SL0550Down(-5.50), - SL0600Down(-6.00), - SL0643Down(-6.43), - SL0714Down(-7.14), - SL0750Down(-7.50), - SL0790Down(-7.90), - SL0800Down(-8.00), - SL1000Down(-10.00), - SL1050Down(-10.50), - SL1200Down(-12.00), - SL1350Down(-13.50), - SL1500Down(-15.00), - SL1579Down(-15.79), - SL2000Down(-20.00), - SL2400Down(-24.00), - SL2500Down(-25.00), - SL3000Down(-30.00), - SL4500Down(-45.00), - SL7500Down(-75.00), - SIVL0005(0.005), - SIVL0008(0.008), - SIVL0009(0.009), - SIVL0010(0.010), - SIVL0012(0.012), - SIVL0013(0.013), - SIVL0014(0.014), - SIVL0015(0.015), - SIVL0016(0.016), - SIVL0017(0.017), - SIVL0019(0.019), - SIVL0020(0.020), - SIVL0021(0.021), - SIVL0022(0.022), - SIVL0023(0.023), - SIVL0024(0.024), - SIVL0025(0.025), - SIVL0026(0.026), - SIVL0027(0.027), - SIVL0029(0.029), - SIVL0030(0.030), - SIVL0031(0.031), - SIVL0032(0.032), - SIVL0033(0.033), - SIVL0034(0.034), - SIVL0035(0.035), - SIVL0036(0.036), - SIVL0038(0.038), - SIVL0040(0.040), - SIVL0044(0.044), - SIVL0046(0.046), - SIVL0048(0.048), - SIVL0055(0.055), - SIVL0056(0.056), - SIVL0057(0.057), - SIVL0058(0.058), - SIVL0060(0.060), - SIVL0061(0.061), - SIVL0066(0.066), - SIVL0067(0.067), - SIVL0075(0.075), - SIVL0078(0.078), - SIVL0130(0.130), - SIVL0150(0.150), - SIVL0205(0.205), - SIVL0220(0.220), - SIVL0243(0.243), - SIVL0360(0.360); - - private final double value; - - private CompoundCurveType(double value) { - - this.value = value; - } - - public double getValue() { - return value; - } - } - - public enum PowerFailCondition { - - Attack, - AttackSwing, - Cast, - CastSpell, - EquipChange, - Logout, - Move, - NewCharm, - Sit, - TakeDamage, - TerritoryClaim, - UnEquip; - } - - public enum PowerSubType { - Amount, - Ramp, - UseAddFormula, - DamageType1, - DamageType2, - DamageType3, - Cancel; - } - - public enum PowerCategoryType { - NONE, - WEAPON, - BUFF, - DEBUFF, - SPECIAL, - DAMAGE, - DISPEL, - INVIS, - STUN, - TELEPORT, - HEAL, - VAMPDRAIN, - BLESSING, - BOONRACE, - BOONCLASS, - BEHAVIOR, - CHANT, - GROUPBUFF, - MOVE, - FLIGHT, - GROUPHEAL, - AEDAMAGE, - BREAKFLY, - AE, - TRANSFORM, - TRACK, - SUMMON, - STANCE, - RECALL, - SPIREPROOFTELEPORT, - SPIREDISABLE, - THIEF; - } - - public enum PowerTargetType { - - SELF, - PCMOBILE, - PET, - MOBILE, - PC, - WEAPON, - GUILDLEADER, - BUILDING, - GROUP, - ARMORWEAPONJEWELRY, - CORPSE, - JEWELRY, - WEAPONARMOR, - ARMOR, - ITEM; - } - - public enum objectMaskType { - PLAYER, - MOB, - PET, - CORPSE, - BUILDING, - UNDEAD, - BEAST, - HUMANOID, - NPC, - IAGENT, - DRAGON, - RAT, - SIEGE, - CITY, - ZONE; - - public static EnumSet AGGRO = EnumSet.of(PLAYER, PET); - public static EnumSet MOBILE = EnumSet.of(PLAYER, MOB, PET); - public static EnumSet STATIC = EnumSet.of(CORPSE, BUILDING, NPC); - - } - - public enum ItemContainerType { - NONE, - INVENTORY, - EQUIPPED, - BANK, - VAULT, - FORGE, - WAREHOUSE; - } - - public enum ItemSlotType implements EnumBitSetHelper { - RHELD, - LHELD, - HELM, - CHEST, - SLEEVES, - HANDS, - RRING, - LRING, - AMULET, - LEGS, - FEET, - CLOAK, - SHIN, - UPLEGS, - UPARM, - WINGS, - BEARD, - HAIR; - } - - public enum CityBoundsType { - - GRID(640), - ZONE(875), - PLACEMENT(1050); - - public final float extents; - - CityBoundsType(float extents) { - this.extents = extents; - } - } - - public enum GuildType { - NONE("None", new String[][]{{"None"}}, new String[]{"Thearchy", "Common Rule", "Theocracy", "Republic Rule"}), - CATHEDRAL("Church of the All-Father", new String[][]{ - {"Acolyte", "Acolyte"}, - {"Catechist"}, - {"Deacon", "Deaconess"}, - {"Priest", "Priestess"}, - {"High Priest", "High Priestess"}, - {"Bishop", "Bishop"}, - {"Lord Cardinal", "Lady Cardinal"}, - {"Patriarch", "Matriarch"}}, - new String[]{"Thearchy", "Common Rule", "Theocracy", "Republic Rule"}), - MILITARY("Military", new String[][]{ - {"Recruit"}, - {"Footman"}, - {"Corporal"}, - {"Sergeant"}, - {"Lieutenant"}, - {"Captain"}, - {"General"}, - {"Lord Marshall", "Lady Marshall"}}, - new String[]{"Autocracy", "Common Rule", "Council Rule", "Militocracy"}), - TEMPLE("Temple of the Cleansing Flame", new String[][]{ - {"Aspirant"}, - {"Novice"}, - {"Initiate"}, - {"Inquisitor"}, - {"Jannisary"}, - {"Tribune"}, - {"Lictor"}, - {"Justiciar"}, - {"Pontifex", "Pontifectrix"}}, - new String[]{"Despot Rule", "Common Rule", "Protectorship", "Republic Rule"}), - BARBARIAN("Barbarian Clan", new String[][]{ - {"Barbarian"}, - {"Skald"}, - {"Raider"}, - {"Karl"}, - {"Jarl"}, - {"Chieftain"}, - {"Thane"}}, - new String[]{"Chiefdom", "Common Rule", "Council Rule", "Republic Rule"}), - RANGER("Ranger's Brotherhood", new String[][]{ - {"Yeoman"}, - {"Pathfinder"}, - {"Tracker"}, - {"Seeker"}, - {"Protector"}, - {"Guardian"}, - {"Lord Protector", "Lady Protector"}}, - new String[]{"Despot Rule", "Collectivism", "Council Rule", "Republic Rule"}), - AMAZON("Amazon Temple", new String[][]{ - {"Amazon Thrall", "Amazon"}, - {"Amazon Slave", "Amazon Warrior"}, - {"Amazon Servant", "Amazon Chieftess"}, - {"Amazon Consort", "Amazon Princess"}, - {"Amazon Seneschal", "Majestrix"}, - {"Amazon Regent", "Imperatrix"}}, - new String[]{"Despot Rule", "Common Rule", "Gynarchy", "Gynocracy"}), - NOBLE("Noble House", new String[][]{ - {"Serf"}, - {"Vassal"}, - {"Exultant"}, - {"Lord", "Lady"}, - {"Baron", "Baroness"}, - {"Count", "Countess"}, - {"Duke", "Duchess"}, - {"King", "Queen"}, - {"Emperor", "Empress"}}, - new String[]{"Monarchy", "Common Rule", "Feodality", "Republic"}), - WIZARD("Wizard's Conclave", new String[][]{ - {"Apprentice"}, - {"Neophyte"}, - {"Adeptus Minor"}, - {"Adeptus Major"}, - {"Magus"}, - {"High Magus"}, - {"Archmagus"}}, - new String[]{"Despot Rule", "Common Rule", "Council Rule", "Magocracy"}), - MERCENARY("Mercenary Company", new String[][]{ - {"Soldier"}, - {"Man-at-Arms"}, - {"Veteran"}, - {"Myrmidon"}, - {"Captain"}, - {"Commander"}, - {"High Commander"}, - {"Warlord"}}, - new String[]{"Magistrature", "Mob Law", "Council Rule", "Republic Rule"}), - THIEVES("Thieve's Den", new String[][]{ - {"Urchin"}, - {"Footpad"}, - {"Grifter"}, - {"Burglar"}, - {"Collector"}, - {"Naster Thief"}, - {"Treasurer"}, - {"Grandmaster Thief"}, - {"Grandfather"}}, - new String[]{"Despot Rule", "Common Rule", "Oligarchy", "Republic Rule"}), - DWARF("Dwarf Hold", new String[][]{ - {"Citizen"}, - {"Master"}, - {"Councilor"}, - {"Thane"}, - {"Great Thane"}, - {"High Thane"}}, - new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), - HIGHCOURT("High Court", new String[][]{ - {"Eccekebe"}, - {"Saedulor"}, - {"Hodrimarth"}, - {"Mandrae"}, - {"Imaelin"}, - {"Thaelostor", "Thaelostril"}, - {"Dar Thaelostor", "Dar Thaelostril"}, - {"Aglaeron"}, - {"Ellestor", "Elestril"}}, - new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), - VIRAKT("Virakt", new String[][]{ - {"Jov'uus"}, - {"Urikhan"}, - {"Irkhan"}, - {"Khal'usht"}, - {"Arkhalar"}, - {"Khal'uvho"}, - {"Khar'uus"}, - {"Kryqh'khalin"}}, - new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), - BRIALIA("Coven of Brialia", new String[][]{ // Unknown Rank names - {"Devotee"}, - {"Initiated"}, - {"Witch of the First"}, - {"Witch of the Second"}, - {"Witch of the Third"}, - {"Elder"}, - {"Hierophant"}, - {"Witch King", "Witch Queen"}}, - new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), - UNHOLY("Unholy Legion", new String[][]{ // Unknown Rank names - {"Footman"}, - {"Fell Legionaire"}, - {"Fell Centurion"}, - {"Dark Captain"}, - {"Dark Commander"}, - {"Dark Master", "Dark Mistress"}, - {"Dread Master", "Dread Mistress"}, - {"Dread Lord", "Dread Lady"}}, - new String[]{"Despot Rule", "Despot Rule", "Council Rule", "Republic Rule"}), - SCOURGE("Cult of the Scourge", new String[][]{ - {"Thrall"}, - {"Mudir"}, - {"Dark Brother", "Dark Sister"}, - {"Hand of the Dark"}, - {"Dark Father", "Dark Mother"}}, - new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), - PIRATE("Pirate Crew", new String[][]{ - {"Midshipman", "Midshipwoman"}, - {"Sailor"}, - {"Third Mat"}, - {"Second Mat"}, - {"First Mate"}, - {"Captain"}}, - new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), - HERALD("Academy of Heralds", new String[][]{ - {"Pupil"}, - {"Scribe"}, - {"Recorder"}, - {"Scrivener"}, - {"Chronicler"}, - {"Scholar"}, - {"Archivist"}, - {"Loremaster"}}, - new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), - CENTAUR("Centaur Cohort", new String[][]{ - {"Hoplite"}, - {"Peltast"}, - {"Myrmidon"}, - {"Myrmidon"}, - {"Cataphract"}, - {"Septenrion"}, - {"Praetorian"}, - {"Paragon"}}, - new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), - KHREE("Aracoix Kh'ree", new String[][]{ - {"Duriacor"}, - {"Exarch"}, - {"Tetrarch"}, - {"Dimarch"}, - {"Elnarch"}, - {"Illiarch"}, - {"Tellotharch"}, - {"Erentar"}, - {"Araceos"}, - {"Hierarch"}}, - - new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}); - - private final String name; - private final String[][] ranks; //Stored Rank#->Gender(M,F) - private final String[] leadershipTypes; - - GuildType(String name, String[][] ranks, String[] leadershipTypes) { - this.name = name; - this.ranks = ranks; - this.leadershipTypes = leadershipTypes; - } - - public static GuildType getGuildTypeFromCharter(ItemBase itemBase) { - - GuildType charterType; - - // Must be a valid charter object - - if (itemBase.getType().equals(ItemType.GUILDCHARTER) == false) - return GuildType.NONE; //No guild Type - - // No switches on long in java. Cast to int - // when refactor to long uuid's. Loss won't matter - // with values this small. - - switch (itemBase.getUUID()) { - - case 559: - charterType = GuildType.CATHEDRAL; - break; - case 560: - charterType = GuildType.MILITARY; - break; - case 561: - charterType = GuildType.TEMPLE; - break; - case 562: - charterType = GuildType.BARBARIAN; - break; - case 563: - charterType = GuildType.RANGER; - break; - case 564: - charterType = GuildType.AMAZON; - break; - case 565: - charterType = GuildType.NOBLE; - break; - case 566: - charterType = GuildType.WIZARD; - break; - case 567: - charterType = GuildType.MERCENARY; - break; - case 568: - charterType = GuildType.THIEVES; - break; - case 569: - charterType = GuildType.DWARF; - break; - case 570: - charterType = GuildType.HIGHCOURT; - break; - case 571: - charterType = GuildType.VIRAKT; - break; - case 572: - charterType = GuildType.SCOURGE; - break; - case 573: - charterType = GuildType.KHREE; - break; - case 574: - charterType = GuildType.CENTAUR; - break; - case 575: - charterType = GuildType.UNHOLY; - break; - case 576: - charterType = GuildType.PIRATE; - break; - case 577: - charterType = GuildType.BRIALIA; - break; - - default: - charterType = GuildType.HERALD; - } - - return charterType; - } - - public static GuildType getGuildTypeFromInt(int i) { - return GuildType.values()[i]; - } - - public String getCharterName() { - return this.name; - } - - public int getNumberOfRanks() { - return ranks.length; - } - - public String getRankForGender(int rank, boolean male) { - if (ranks.length < rank) { - return ""; - } - - if (ranks[rank].length != 1 && !male) { - return ranks[rank][1]; - } - return ranks[rank][0]; - } - - public String getLeadershipType(int i) { - return leadershipTypes[i]; - } - - } - - public enum MinionClass { - MELEE, - ARCHER, - MAGE; - } - - public enum MinionType { - AELFBORNGUARD(951, 1637, MinionClass.MELEE, "Guard", "Aelfborn"), - AELFBORNMAGE(952, 1635, MinionClass.MAGE, "Adept", "Aelfborn"), - AMAZONGUARD(1500, 1670, MinionClass.MELEE, "Guard", "Amazon"), - AMAZONMAGE(1502, 1638, MinionClass.MAGE, "Fury", "Amazon"), - ARACOIXGUARD(1600, 1672, MinionClass.MELEE, "Guard", "Aracoix"), //used guard captain equipset. - ARACOIXMAGE(1602, 885, MinionClass.MAGE, "Adept", "Aracoix"), - CENTAURGUARD(1650, 1642, MinionClass.MELEE, "Guard", "Centaur"), - CENTAURMAGE(1652, 1640, MinionClass.MAGE, "Druid", "Centaur"), - DWARVENARCHER(845, 1644, MinionClass.ARCHER, "Marksman", "Dwarven"), - DWARVENGUARD(1050, 1666, MinionClass.MELEE, "Guard", "Dwarven"), - DWARVENMAGE(1052, 1643, MinionClass.MAGE, "War Priest", "Dwarven"), - ELFGUARD(1180, 1671, MinionClass.MELEE, "Guard", "Elven"), //old 1645 - ELFMAGE(1182, 1667, MinionClass.MAGE, "Adept", "Elven"), - FORESTGUARD(1550, 1668, MinionClass.MELEE, "Guard", "Forest"), //captain changed to guard equipset - FORESTMAGE(1552, 436, MinionClass.MAGE, "Adept", "Forest"), - HOLYGUARD(1525, 1658, MinionClass.MELEE, "Guard", "Holy Church"), - HOLYMAGE(1527, 1646, MinionClass.MAGE, "Prelate", "Holy Church"), - HUMANARCHER(846, 1654, MinionClass.ARCHER, "Archer", "Human"), - HUMANGUARD(840, 1665, MinionClass.MELEE, "Guard", "Human"), - HUMANMAGE(848, 1655, MinionClass.MAGE, "Adept", "Human"), - IREKEIGUARD(1350, 1659, MinionClass.MELEE, "Guard", "Irekei"), - IREKEIMAGE(1352, 1660, MinionClass.MAGE, "Adept", "Irekei"), - MINOTAURARCHER(1701, 0, MinionClass.ARCHER, "Archer", "Minotaur"), - MINOTAURGUARD(1700, 1673, MinionClass.MELEE, "Guard", "Minotaur"), - NORTHMANGUARD(1250, 1669, MinionClass.MELEE, "Guard", "Northman"), - NORTHMANMAGE(1252, 1650, MinionClass.MAGE, "Runecaster", "Northman"), - SHADEGUARD(1450, 1662, MinionClass.MELEE, "Guard", "Shade"), - SHADEMAGE(1452, 1664, MinionClass.MAGE, "Adept", "Shade"), - TEMPLARGUARD(841, 1564, MinionClass.MELEE, "Marksman", "Templar"), - TEMPLEGUARD(1575, 1652, MinionClass.MELEE, "Guard", "Temple"), - TEMPLEMAGE(1577, 1656, MinionClass.MAGE, "Confessor", "Temple"), - UNDEADGUARD(980100, 1674, MinionClass.MELEE, "Guard", "Undead"), - UNDEADMAGE(980102, 1675, MinionClass.MAGE, "Adept", "Undead"), - WEREWOLFGUARD(980104, 0, MinionClass.MELEE, "Guard", "Werewolf"), - WEREBEARGUARD(980103, 0, MinionClass.MELEE, "Guard", "Werebear"); - public static HashMap ContractToMinionMap = new HashMap<>(); - private final int captainContractID; - private final int equipSetID; - private final MinionClass minionClass; - private final String name; - private final String race; - - MinionType(int captainContractID, int equipSetID, MinionClass minionClass, String name, String race) { - - this.captainContractID = captainContractID; - this.equipSetID = equipSetID; - this.minionClass = minionClass; - this.name = name; - this.race = race; - - } - - public static void InitializeMinions() { - - for (MinionType minionType : MinionType.values()) - ContractToMinionMap.put(minionType.captainContractID, minionType); - } - - public String getName() { - return name; - } - - public String getRace() { - return race; - } - - } - - public enum GridObjectType { - STATIC, - DYNAMIC; - } - - public enum SupportMsgType { - NONE(0), - PROTECT(1), - UNPROTECT(3), - VIEWUNPROTECTED(4), - REMOVETAX(6), - ACCEPTTAX(7), - CONFIRMPROTECT(8); - - public static HashMap typeLookup = new HashMap<>(); - private final int type; - - SupportMsgType(int messageType) { - this.type = messageType; - - } - - public static void InitializeSupportMsgType() { - - for (SupportMsgType supportMsgType : SupportMsgType.values()) - typeLookup.put(supportMsgType.type, supportMsgType); - } - } - - public enum ResourceType implements EnumBitSetHelper { - - STONE(1580000), - TRUESTEEL(1580001), - IRON(1580002), - ADAMANT(1580003), - LUMBER(1580004), - OAK(1580005), - BRONZEWOOD(1580006), - MANDRAKE(1580007), - COAL(1580008), - AGATE(1580009), - DIAMOND(1580010), - ONYX(1580011), - AZOTH(1580012), - ORICHALK(1580013), - ANTIMONY(1580014), - SULFUR(1580015), - QUICKSILVER(1580016), - GALVOR(1580017), - WORMWOOD(1580018), - OBSIDIAN(1580019), - BLOODSTONE(1580020), - MITHRIL(1580021), - GOLD(7); - - public static HashMap resourceLookup = new HashMap<>(); - public int itemID; - - ResourceType(int itemID) { - this.itemID = itemID; - } - - public static void InitializeResourceTypes() { - - for (ResourceType resourceType : ResourceType.values()) - resourceLookup.put(resourceType.itemID, resourceType); - } - } - - public enum PowerActionType { - ApplyEffect, - ApplyEffects, - Block, - Charm, - ClaimMine, - ClearAggro, - ClearNearbyAggro, - Confusion, - CreateMob, - DamageOverTime, - DeferredPower, - DirectDamage, - Invis, - MobRecall, - Peek, - Recall, - RemoveEffect, - Resurrect, - RunegateTeleport, - SetItemFlag, - SimpleDamage, - SpireDisable, - Steal, - Summon, - Teleport, - Track, - TransferStat, - TransferStatOT, - Transform, - TreeChoke - } - - public enum AccountStatus { - BANNED, - ACTIVE, - ADMIN; - } - - public enum MobBehaviourType { - None(null, false, false, false, false, false), - //Power - Power(null, false, true, true, true, false), - PowerHelpee(Power, false, true, true, false, true), - PowerHelpeeWimpy(Power, true, false, true, false, false), - PowerGrouperWimpy(Power, true, false, true, false, false), - PowerAggro(Power, false, true, true, false, true), - PowerAggroHelpee(Power, false, true, true, false, true), - //Aggro - Aggro(null, false, true, true, true, false), - AggroHelpee(Aggro, false, true, true, false, true), + public enum MobFlagType implements EnumBitSetHelper { + AGGRESSIVE, + CANROAM, + CALLSFORHELP, + RESPONDSTOCALLSFORHELP, + HUMANOID, + UNDEAD, + BEAST, + DRAGON, + RAT, + SENTINEL, + } + + public enum MonsterType implements EnumBitSetHelper { + Aelfborn, + All, + Animal, + Aracoix, + Celestial, + Centaur, + Construct, + CSR, + Dragon, + Dwarf, + Elf, + Giant, + Goblin, + Grave, + HalfGiant, + Human, + Infernal, + Insect, + Irekei, + Minotaur, + Monster, + NecroPet, + NPC, + Pet, + Plant, + Rat, + Reptile, + Shade, + Siege, + Summoned, + Troll, + Undead, + Nephilim, + Vampire, + SiegeEngineer; + + } + + public enum CharacterSex { + MALE, + FEMALE, + FUZZY, + OTHER; + } + + public enum RaceType { + + // RaceRuneID / AggroType, isFemale + + AELFMALE(2000, MonsterType.Aelfborn, RunSpeed.STANDARD, CharacterSex.MALE, 1.05f), + AELFFEMALE(2001, MonsterType.Aelfborn, RunSpeed.STANDARD, CharacterSex.FEMALE, 1.05f), + ARACOIXMALE(2002, MonsterType.Aracoix, RunSpeed.STANDARD, CharacterSex.MALE, 1), + ARACOIXFEMALE(2003, MonsterType.Aracoix, RunSpeed.STANDARD, CharacterSex.FEMALE, 1), + CENTAURMALE(2004, MonsterType.Centaur, RunSpeed.CENTAUR, CharacterSex.MALE, 1.2f), + CENTAURFEMALE(2005, MonsterType.Centaur, RunSpeed.CENTAUR, CharacterSex.FEMALE, 1.2f), + DWARFMALE(2006, MonsterType.Dwarf, RunSpeed.STANDARD, CharacterSex.MALE, 0.80000001f), + ELFMALE(2008, MonsterType.Elf, RunSpeed.STANDARD, CharacterSex.MALE, 1.4f), + ELFFEMALE(2009, MonsterType.Elf, RunSpeed.STANDARD, CharacterSex.FEMALE, 1.1f), + HALFGIANTMALE(2010, MonsterType.HalfGiant, RunSpeed.STANDARD, CharacterSex.MALE, 1.15f), + HUMANMALE(2011, MonsterType.Human, RunSpeed.STANDARD, CharacterSex.MALE, 1), + HUMANFEMALE(2012, MonsterType.Human, RunSpeed.STANDARD, CharacterSex.FEMALE, 1), + IREKEIMALE(2013, MonsterType.Irekei, RunSpeed.STANDARD, CharacterSex.MALE, 1.1f), + IREKEIFEMALE(2014, MonsterType.Irekei, RunSpeed.STANDARD, CharacterSex.FEMALE, 1.1f), + SHADEMALE(2015, MonsterType.Shade, RunSpeed.STANDARD, CharacterSex.MALE, 1), + SHADEFEMALE(2016, MonsterType.Shade, RunSpeed.STANDARD, CharacterSex.FEMALE, 1), + MINOMALE(2017, MonsterType.Minotaur, RunSpeed.MINOTAUR, CharacterSex.MALE, 1.3f), + ARCHONMALE(2018, MonsterType.Celestial, RunSpeed.STANDARD, CharacterSex.MALE, 1), + HALEGIANTOLDMALE(2019, MonsterType.HalfGiant, RunSpeed.STANDARD, CharacterSex.MALE, 1.15f), + CSRFEMALE(2020, MonsterType.CSR, RunSpeed.STANDARD, CharacterSex.FEMALE, 0.66000003f), + CSRMALE(2021, MonsterType.CSR, RunSpeed.STANDARD, CharacterSex.MALE, 1), + NEPHMALE(2025, MonsterType.Nephilim, RunSpeed.STANDARD, CharacterSex.MALE, 1.1f), + NEPHFEMALE(2026, MonsterType.Nephilim, RunSpeed.STANDARD, CharacterSex.FEMALE, 1.1f), + HALFGIANTFEMALE(2027, MonsterType.HalfGiant, RunSpeed.STANDARD, CharacterSex.FEMALE, 1.15f), + VAMPMALE(2028, MonsterType.Vampire, RunSpeed.STANDARD, CharacterSex.MALE, 1), + VAMPFEMALE(2029, MonsterType.Vampire, RunSpeed.STANDARD, CharacterSex.FEMALE, 1); + + @SuppressWarnings("unchecked") + private static HashMap _raceTypeByID = new HashMap<>(); + + int runeID; + private MonsterType monsterType; + private CharacterSex characterSex; + private RunSpeed runSpeed; + private float scaleHeight; + + RaceType(int runeID, MonsterType aggroType, RunSpeed runspeed, CharacterSex characterSex, float scaleHeight) { + this.runeID = runeID; + this.monsterType = aggroType; + this.runSpeed = runspeed; + this.characterSex = characterSex; + this.scaleHeight = scaleHeight; + } + + public static RaceType getRaceTypebyRuneID(int runeID) { + return _raceTypeByID.get(runeID); + } + + public static void initRaceTypeTables() { + + for (RaceType raceType : RaceType.values()) { + _raceTypeByID.put(raceType.runeID, raceType); + } + } + + public int getRuneID() { + return this.runeID; + } + + public float getScaleHeight() { + return this.scaleHeight; + } + + public MonsterType getMonsterType() { + return monsterType; + } + + public RunSpeed getRunSpeed() { + return runSpeed; + } + + public CharacterSex getCharacterSex() { + return characterSex; + } + } + + public enum RunSpeed { + + SENTINEL(0, 0, 0, 0, 0, 0, 0), + STANDARD(6.1900001f, 13.97f, 4.2199998f, 13.97f, 6.3299999f, 18.379999f, 6.5f), + CENTAUR(6.1900001f, 16.940001f, 5.5500002f, 16.940001f, 6.3299999f, 18.379999f, 6.5f), + MINOTAUR(6.6300001f, 15.95f, 4.2199998f, 15.95f, 6.3299999f, 18.379999f, 6.5f); + + private float walkStandard; + private float walkCombat; + private float runStandard; + private float runCombat; + private float swim; + private float flyRun; + private float flyWalk; + + RunSpeed(float walkStandard, float runStandard, float walkCombat, float runCombat, float flyWalk, float flyRun, float swim) { + this.walkStandard = walkStandard; + this.walkCombat = walkCombat; + this.runStandard = runStandard; + this.runCombat = runCombat; + this.swim = swim; + this.flyRun = flyRun; + this.flyWalk = flyWalk; + } + + + public float getWalkStandard() { + return walkStandard; + } + + public float getWalkCombat() { + return walkCombat; + } + + public float getRunStandard() { + return runStandard; + } + + public float getRunCombat() { + return runCombat; + } + + public float getFlyRun() { + return flyRun; + } + + + public float getFlyWalk() { + return flyWalk; + } + + } + + public enum FriendListType { + + VIEWHERALDRY(1), + ADDHERALDRY(4), + REMOVEHERALDRY(6), + DEALTHS(7), + KILLS(9), + VIEWCONDEMN(11), + ADDCONDEMN(14), + REMOVECONDEMN(15), + TOGGLEACTIVE(17), + REVERSEKOS(19), + VIEWFRIENDS(25), + TOITEM(23), + ADDFRIEND(28), + REMOVEFRIEND(30); + + private final int listType; + + FriendListType(int listType) { + this.listType = listType; + } + + public static FriendListType getListTypeByID(int listType) { + + FriendListType outType = null; + + for (FriendListType friendListType : FriendListType.values()) { + if (friendListType.listType == listType) + outType = friendListType; + } + return outType; + } + + } + + public enum DispatchChannel { + PRIMARY(0), + SECONDARY(1); + + private final int channelID; + + DispatchChannel(int channelID) { + this.channelID = channelID; + } + + public int getChannelID() { + return this.channelID; + } + + } + + public enum PvpHistoryType { + KILLS, + DEATHS; + } + + public enum ChatMessageType { + ERROR, + INFO, + MOTD; + } + + public enum DataRecordType { + PVP, + CHARACTER, + BANE, + GUILD, + CITY, + ZONE, + REALM, + MINE; + } + + public enum RecordEventType { + CREATE, // Shared with city/guild + DISBAND, + DESTROY, // City events + CAPTURE, + TRANSFER, + PENDING, + DEFEND, + LOST; // Realm event + } + + public enum CharterType { + FEUDAL(-600065291, 5060000), + MERCANTILE(-15978914, 5060400), + BELLIGERENT(762228431, 5060800); + + private int charterID; + private int meshID; + + CharterType(int charterID, int meshID) { + this.charterID = charterID; + this.meshID = meshID; + } + + public static CharterType getCharterTypeByID(int charterID) { + CharterType outType = null; + + for (CharterType charterType : CharterType.values()) { + if (charterType.charterID == charterID) + outType = charterType; + } + return outType; + } + + public int getMeshID() { + return meshID; + } + } + + + public enum ChatChannelType { + SYSTEM(1), + FLASH(2), + COMMANDER(3), + NATION(5), + LEADER(6), + SHOUT(7), + INFO(10), + GUILD(12), + INNERCOUNCIL(13), + GROUP(14), + CITY(15), + SAY(16), + EMOTE(17), + TELL(19), + COMBAT(20); + + private final int channelID; + + ChatChannelType(int channelID) { + this.channelID = channelID; + } + + public int getChannelID() { + return this.channelID; + } + } + + public enum OwnerType { + Npc, + PlayerCharacter, + Account, + Mob; + } + + public enum SiegePhase { + ERRANT, + CHALLENGE, + STANDOFF, + WAR, + CEASEFIRE; + } + + public enum SiegeResult { + PENDING, + DEFEND, + DESTROY, + CAPTURE; + } + + public enum TaxType { + PROFIT, + WEEKLY, + NONE; + + } + + public enum Ruins { + + ESTRAGOTH(569), + KARFELL(570), + MORELAN(571), + REGARS(572), + HALLOS(573), + WESTERMORE(574), + EYWAN(575), + CAER(576); + + private final int zoneUUID; + + Ruins(int uuid) { + this.zoneUUID = uuid; + } + + public static Ruins getRandomRuin() { + + Ruins ruins; + + ruins = Ruins.values()[ThreadLocalRandom.current() + .nextInt(Ruins.values().length)]; + + return ruins; + } + + public Vector3fImmutable getLocation() { + + Zone ruinZone; + Vector3fImmutable spawnLocation; + + // Send to SDR if so configured + + if (ConfigManager.MB_USE_RUINS.getValue().equalsIgnoreCase("true")) { + ruinZone = ZoneManager.getZoneByUUID(this.zoneUUID); + spawnLocation = Vector3fImmutable.getRandomPointOnCircle(ruinZone.getLoc(), 30); + } else { + ruinZone = ZoneManager.getZoneByName("sea dog's rest"); + + // 14001 does not have a banestone to bind at + + if (ruinZone.getLoadNum() == 14001) + spawnLocation = Vector3fImmutable.getRandomPointOnCircle(ruinZone.getLoc(), 30); + else + spawnLocation = Vector3fImmutable.getRandomPointOnCircle(ruinZone.getLoc() + .add(new Vector3fImmutable(-196.016f, 2.812f, 203.621f)), 30); + } + + + return spawnLocation; + } + + } + + public enum Guards { + + HumanArcher(13.97f, 13.97f, 6.19f, 4.2199998f, 18.38f, 6.33f, 6.5f), + HumanGuard(13.97f, 13.97f, 6.19f, 4.2199998f, 18.38f, 6.33f, 6.5f), + HumanMage(13.97f, 13.97f, 6.19f, 4.2199998f, 18.38f, 6.33f, 6.5f), + UndeadArcher(14.67f, 14.67f, 6.5f, 4.44f, 18.38f, 6.33f, 6.5f), + UndeadGuard(14.67f, 14.67f, 6.5f, 4.44f, 18.38f, 6.33f, 6.5f), + UndeadMage(14.67f, 14.67f, 6.5f, 4.44f, 18.38f, 6.33f, 6.5f); + + private final float runSpeed; + private final float runCombatSpeed; + private final float walkSpeed; + private final float walkCombatSpeed; + private final float fly; + private final float flyWalk; + private final float swim; + + Guards(float runSpeed, float runCombatSpeed, float walkSpeed, float walkCombatSpeed, float fly, float flyWalk, float swim) { + this.runSpeed = runSpeed; + this.runCombatSpeed = runCombatSpeed; + this.walkSpeed = walkSpeed; + this.walkCombatSpeed = walkCombatSpeed; + this.fly = fly; + this.flyWalk = flyWalk; + this.swim = swim; + } + + public float getRunSpeed() { + return runSpeed; + } + + public float getRunCombatSpeed() { + return runCombatSpeed; + } + + public float getWalkSpeed() { + return walkSpeed; + } + + public float getWalkCombatSpeed() { + return walkCombatSpeed; + } + + public float getFly() { + return fly; + } + + public float getSwim() { + return swim; + } + + public float getFlyWalk() { + return flyWalk; + } + } + + public enum PortalType { + + EARTH(6f, 19.5f, 128), + AIR(-6f, 19.5f, 256), + FIRE(15f, 7.5f, 512), + WATER(-15f, 8.5f, 1024), + SPIRIT(0, 10.5f, 2048), + CHAOS(22f, 3.5f, 8192), + OBLIV(0f, 42f, 16384), + MERCHANT(-22f, 4.5f, 4096), + FORBID(0.0f, 0.0f, 0); + + public final Vector2f offset; + public final int effectFlag; + + PortalType(float offsetX, float offsetY, int effectFlag) { + + this.offset = new Vector2f(offsetX, offsetY); + this.effectFlag = effectFlag; + + } + } + + + // Enum for ItemBase flags + + public enum ItemType { + DECORATION(0), + WEAPON(1), + ARMOR(2), + HAIR(3), + GOLD(4), + RUNE(5), + SCROLL(5), + BOOK(6), + COMMANDROD(7), + POTION(8), + TEARS(8), + KEY(9), + GUILDCHARTER(10), + JEWELRY(13), + WINE(16), + ALEJUG(17), + DEED(19), + CONTRACT(20), + PET(21), + FURNITURE(25), + BEDROLL(26), + FARMABLE(27), + WATERBUCKET(30), + GIFT(31), + OFFERING(33), + RESOURCE(34), + REALMCHARTER(35); + + private final static HashMap _typeLookup = new HashMap<>(); + private final int _value; + + ItemType(int value) { + this._value = value; + } + + public static ItemType getByValue(int value) { + + ItemType outType = ItemType.DECORATION; + + if (_typeLookup.isEmpty()) { + + for (ItemType itemType : ItemType.values()) { + _typeLookup.put(itemType._value, itemType); + } + } + + if (_typeLookup.containsKey(value)) + outType = _typeLookup.get(value); + + return outType; + } + + /** + * @return the _value + */ + public int getValue() { + return _value; + } + + } + // Enum to derive effects for active spires from blueprintUUID + + public enum SpireType { + + WATCHFUL(1800100, (1 << 23), -1139520957), + GROUNDING(1800400, (1 << 24), -1733819072), + BINDING(1800700, (1 << 25), -1971545187), + WARDING(1801000, (1 << 26), 2122002462), + GUILEFUL(1801300, (1 << 27), -1378972677), + BALEFUL(1801600, -1, 1323012132), + ARCANE(1801900, (1 << 30), 1323888676), + WOUNDING(1802200, (1 << 10), 1357392095), + WEARYING(1802500, (1 << 10), 1350838495), + CONFUSING(1802800, (1 << 10), 1358702815), + CHILLING(1803100, (1 << 1), 1332155165), + SEARING(1803400, (1 << 2), -1401744610), + THUNDERING(1803700, (1 << 3), -443544829), + UNHOLY(1804000, (1 << 4), 1330320167), + BEFUDDLING(1804300, (1 << 5), 1489317547), + WRATHFUL(1804600, (1 << 6), 165160210), + SPITEFUL(1804900, (1 << 7), 1238906779), + ENFEEBLING(1805200, (1 << 8), -908578401), + CONFOUNDING(1805500, (1 << 9), 165165842), + DISTRACTING(1805800, (1 << 10), 1238906697), + WOLFPACK(1806100, (1 << 4), 416932375); + + private final int blueprintUUID; + private final int effectFlag; + private final int token; + + SpireType(int blueprint, int flag, int token) { + this.blueprintUUID = blueprint; + this.effectFlag = flag; + this.token = token; + } + + public static SpireType getByBlueprintUUID(int uuid) { + + SpireType outType = SpireType.GROUNDING; + + for (SpireType spireType : SpireType.values()) { + + if (spireType.blueprintUUID == uuid) { + outType = spireType; + return outType; + } + + } + + return outType; + } + + public int getBlueprintUUID() { + return blueprintUUID; + } + + public int getEffectFlag() { + return effectFlag; + } + + public int getToken() { + return token; + } + + public EffectsBase getEffectBase() { + return PowersManager.getEffectByToken(token); + } + + } + + public enum TransactionType { + MAINTENANCE(43), + WITHDRAWL(80), + DEPOSIT(82), + MINE(81), + MIGRATION(83), + PLAYERREWARD(84), + TAXRESOURCE(85), + TAXRESOURCEDEPOSIT(86); + + private final int ID; + + TransactionType(int ID) { + this.ID = ID; + } + + public int getID() { + return ID; + } + } + + public enum TargetColor { + + White, + Green, + Cyan, + Blue, + Yellow, + Orange, + Red; + + public static TargetColor getCon(AbstractCharacter source, + AbstractCharacter target) { + return getCon(source.getLevel(), target.getLevel()); + } + + public static TargetColor getCon(short sourceLevel, short targetLevel) { + if (targetLevel > (sourceLevel + 2)) + return Red; + else if (targetLevel == (sourceLevel + 2)) + return Orange; + else if (targetLevel == (sourceLevel + 1)) + return Yellow; + + short lowestBlue = (short) (sourceLevel - (((sourceLevel / 5)) + 2)); + + if (lowestBlue <= targetLevel) + return Blue; + else if (lowestBlue - 1 <= targetLevel) + return Cyan; + else if (lowestBlue - 2 <= targetLevel) + return Green; + return White; + } + } + + public enum DamageType { + None, + Crush, + Slash, + Siege, + Pierce, + Magic, + Bleed, + Poison, + Mental, + Holy, + Unholy, + Lightning, + Fire, + Cold, + Healing, + Acid, + Disease, + Unknown, + // these added for immunities + Attack, + Powers, + Combat, + Spires, + Snare, + Stun, + Blind, + Root, + Fear, + Charm, + PowerBlock, + DeBuff, + Powerblock, + Steel, + Drain; + + public static DamageType GetDamageType(String modName) { + DamageType damageType; + if (modName.isEmpty()) + return DamageType.None; + + try { + damageType = DamageType.valueOf(modName.replace(",", "")); + } catch (Exception e) { + Logger.error(e); + return DamageType.None; + } + return damageType; + } + } + + + public enum SourceType { + None, + Abjuration, + Acid, + AntiSiege, + Archery, + Axe, + Bardsong, + Beastcraft, + Benediction, + BladeWeaving, + Bleed, + Blind, + Block, + Bloodcraft, + Bow, + Buff, + Channeling, + Charm, + Cold, + COLD, + Constitution, + Corruption, + Crossbow, + Crush, + Dagger, + DaggerMastery, + DeBuff, + Dexterity, + Disease, + Dodge, + Dragon, + Drain, + Earth, + Effect, + Exorcism, + Fear, + Fire, + FIRE, + Fly, + Giant, + GreatAxeMastery, + GreatSwordMastery, + Hammer, + Heal, + Healing, + Holy, + HOLY, + ImmuneToAttack, + ImmuneToPowers, + Intelligence, + Invisible, + Lightning, + LIGHTNING, + Liturgy, + Magic, + MAGIC, + Mental, + MENTAL, + NatureLore, + Necromancy, + Parry, + Pierce, + Poison, + POISON, + PoleArm, + Powerblock, + Rat, + ResistDeBuff, + Restoration, + Root, + Shadowmastery, + Siege, + Slash, + Snare, + Sorcery, + Spear, + SpearMastery, + Spirit, + Staff, + Stormcalling, + Strength, + Stun, + Summon, + Sword, + SwordMastery, + Thaumaturgy, + Theurgy, + Transform, + UnarmedCombat, + UnarmedCombatMastery, + Unholy, + UNHOLY, + Unknown, + Warding, + Warlockry, + WayoftheGaana, + WearArmorHeavy, + WearArmorLight, + WearArmorMedium, + Wereform, + Athletics, + AxeMastery, + Bargaining, + BladeMastery, + FlameCalling, + GreatHammerMastery, + HammerMastery, + Leadership, + PoleArmMastery, + Running, + StaffMastery, + Throwing, + Toughness, + WayoftheWolf, + WayoftheRat, + WayoftheBear, + Orthanatos, + SunDancing, + //Power categories. + AE, + AEDAMAGE, + BEHAVIOR, + BLESSING, + BOONCLASS, + BOONRACE, + BREAKFLY, + BUFF, + CHANT, + DAMAGE, + DEBUFF, + DISPEL, + FLIGHT, + GROUPBUFF, + GROUPHEAL, + HEAL, + INVIS, + MOVE, + RECALL, + SPECIAL, + SPIREDISABLE, + SPIREPROOFTELEPORT, + STANCE, + STUN, + SUMMON, + TELEPORT, + THIEF, + TRACK, + TRANSFORM, + VAMPDRAIN, + WEAPON, + Wizardry; + + public static SourceType GetSourceType(String modName) { + SourceType returnMod; + if (modName.isEmpty()) + return SourceType.None; + + try { + returnMod = SourceType.valueOf(modName.replace(",", "")); + } catch (Exception e) { + Logger.error(modName); + Logger.error(e); + return SourceType.None; + } + return returnMod; + } + } + + public enum EffectSourceType { + None, + AttackSpeedBuff, + Bleeding, + Blind, + Buff, + Chant, + Charm, + Cold, + Combat, + ConstitutionBuff, + Crush, + DamageShield, + DeathShroud, + DeBuff, + Disease, + Drain, + Earth, + Effect, + Fear, + Fire, + Flight, + Fortitude, + Heal, + Holy, + Invisibility, + Invulnerability, + Lightning, + Magic, + Mental, + Multielement, + PetBuff, + Pierce, + Poison, + Powerblock, + RecoveryManaBuff, + ResistDeBuff, + Root, + Siege, + SiegeBuff, + SiegeDamage, + Silence, + Slash, + Snare, + Stance, + Stun, + Summon, + Transform, + Unholy, + Wereform, + WereformATRBuff, + WereformConBuff, + WereformDexBuff, + WereformHPRecBuff, + WereformMoveBuff, + WereformPhysResBuff, + WereformSPRecBuff, + WereformStrBuff; + + public static EffectSourceType GetEffectSourceType(String modName) { + EffectSourceType returnMod; + if (modName.isEmpty()) + return EffectSourceType.None; + + try { + returnMod = EffectSourceType.valueOf(modName.replace(",", "")); + } catch (Exception e) { + Logger.error(e); + return EffectSourceType.None; + } + return returnMod; + } + } + + public enum StackType { + None, + AggRangeDeBuff, + ArcheryPrecisionBuff, + AttackDebuff, + AttackSpeedBuff, + AttackSpeedDeBuff, + AttackValueBuff, + AttackValueDebuff, + AttrCONBuff, + AttrCONDebuff, + AttrDEXBuff, + AttrINTBuff, + AttrSPRBuff, + AttrSTRBuff, + Bleeding, + Blindness, + BluntResistanceDebuff, + BMHealing, + Charm, + ClassBoon, + Confusion, + DamageAbsorber, + DamageDebuff, + DamageModifierBuff, + DamageShield, + DeathShroud, + DefenseBuff, + DefenseBuffGroup, + DefenseDebuff, + DetectInvis, + DrainImmunity, + ElementalDeBuff, + EnchantWeapon, + Fear, + Flight, + Frenzy, + GroupHeal, + HealingBuff, + HealOverTime, + HealResBuff, + HealthPotion, + IgnoreStack, + Invisible, + ManaPotion, + MangonelFire, + MeleeDamageDeBuff, + MeleeDeBuff, + MoveBuff, + MoveDebuff, + NoFear, + NoPassiveDefense, + NoPowerBlock, + NoPowerInhibitor, + NoRecall, + NoSnare, + NoStun, + NoTrack, + PassiveDefense, + PersAttrSPRBuff, + PetBuff, + PierceResistanceDebuff, + PoisonBuchinine, + PoisonGalpa, + PoisonGorgonsVenom, + PoisonMagusbane, + PoisonPellegorn, + PowerBlock, + PowerCostBuff, + PowerDamageModifierBuff, + PowerInhibitor, + PrecisionBuff, + Protection, + RaceBoon, + RecoveryHealthBuff, + RecoveryHealthDeBuff, + RecoveryManaBuff, + RecoveryManaDeBuff, + RecoveryStaminaBuff, + RecoveryStaminaDeBuff, + ResistanceBuff, + ResistanceDeBuff, + ResistanceDebuff, + Root, + SafeMode, + SelfOneAttrBuff, + SelfThreeAttrBuff, + SelfTwoAttrBuff, + SiegeDebuff, + SiegeWeaponBuff, + Silence, + SkillDebuff, + SlashResistanceDebuff, + Snare, + StackableAttrCONBuff, + StackableAttrDEXBuff, + StackableAttrSTRBuff, + StackableDefenseBuff, + StackableRecoveryHealthBuff, + StackableRecoveryStaminaBuff, + StaminaPotion, + StanceA, + StanceB, + Stun, + Track, + Transform, + WeaponMove; + + public static StackType GetStackType(String modName) { + StackType stackType; + if (modName.isEmpty()) + return StackType.None; + + try { + stackType = StackType.valueOf(modName.replace(",", "")); + } catch (Exception e) { + Logger.error(modName); + Logger.error(e); + return StackType.None; + } + return stackType; + } + } + + public enum ModType { + None, + AdjustAboveDmgCap, + Ambidexterity, + AnimOverride, + ArmorPiercing, + AttackDelay, + Attr, + BlackMantle, + BladeTrails, + Block, + BlockedPowerType, + CannotAttack, + CannotCast, + CannotMove, + CannotTrack, + Charmed, + ConstrainedAmbidexterity, + DamageCap, + DamageShield, + DCV, + Dodge, + DR, + Durability, + ExclusiveDamageCap, + Fade, + Fly, + Health, + HealthFull, + HealthRecoverRate, + IgnoreDamageCap, + IgnorePassiveDefense, + ImmuneTo, + ImmuneToAttack, + ImmuneToPowers, + Invisible, + ItemName, + Mana, + ManaFull, + ManaRecoverRate, + MaxDamage, + MeleeDamageModifier, + MinDamage, + NoMod, + OCV, + Parry, + PassiveDefense, + PowerCost, + PowerCostHealth, + PowerDamageModifier, + ProtectionFrom, + Resistance, + ScaleHeight, + ScaleWidth, + ScanRange, + SeeInvisible, + Silenced, + Skill, + Slay, + Speed, + SpireBlock, + Stamina, + StaminaFull, + StaminaRecoverRate, + Stunned, + Value, + WeaponProc, + WeaponRange, + WeaponSpeed; + + public static ModType GetModType(String modName) { + ModType modType; + if (modName.isEmpty()) + return ModType.None; + + try { + modType = ModType.valueOf(modName.replace(",", "")); + } catch (Exception e) { + Logger.error(e); + return ModType.None; + } + return modType; + } + } + + public enum MovementState { + + IDLE, + SITTING, + RUNNING, + FLYING, + SWIMMING; + } + + public enum DoorState { + + OPEN, + CLOSED, + LOCKED, + UNLOCKED; + } + + // Used with stored procedure GET_UID_ENUM() for + // type tests against objects not yet loaded into the game. + public enum DbObjectType { + + INVALID, + ACCOUNT, + BUILDING, + CHARACTER, + CITY, + CONTAINER, + GUILD, + ITEM, + MINE, + MOB, + NPC, + SHRINE, + WORLDSERVER, + ZONE, + WAREHOUSE; + } + + ; + + /** + * Enumeration of Building Protection Status stored in the database as a + * mysql enumfield. WARNING: This enumeration is fragile. Do not rename. Do + * not reorder. + */ + public enum ProtectionState { + + NONE, + PROTECTED, + UNDERSIEGE, + CEASEFIRE, + CONTRACT, + DESTROYED, + PENDING, + NPC; + } + + ; + + public enum CharacterSkills { + + Archery((1L << 1), -529201545, 20), + Athletics((1L << 2), -327713877, 15), + AxeMastery((1L << 3), 1103042709, 20), + Axe((1L << 4), 73505, 1), + Bardsong((1L << 5), 454246953, 10), + Bargaining((1L << 6), 372927577, 10), + Beastcraft((1L << 7), 56772766, 10), + Benediction((1L << 8), 1464998706, 1), + BladeMastery((1L << 9), -59908956, 20), + BladeWeaving((1L << 10), -1839362429, 20), + Block((1L << 11), 76592546, 3), + Bow((1L << 12), 87490, 1), + Channeling((1L << 13), -1899060872, 20), + Crossbow((1L << 14), 1092138184, 1), + DaggerMastery((1L << 15), -1549224741, 20), + Dagger((1L << 16), -1603103740, 1), + Dodge((1L << 17), 74619332, 5), + FlameCalling((1L << 18), -1839578206, 20), + GreatAxeMastery((1L << 19), 1427003458, 20), + GreatHammerMastery((1L << 20), -309659310, 20), + GreatSwordMastery((1L << 21), 2054956946, 20), + HammerMastery((1L << 22), -1548903209, 20), + Hammer((1L << 23), -1602765816, 1), + Leadership((1L << 24), 1618560984, 20), + Liturgy((1L << 25), -888415974, 10), + NatureLore((1L << 26), -1911171474, 10), + Parry((1L << 27), 95961104, 5), + PoleArmMastery((1L << 28), -1432303709, 20), + PoleArm((1L << 29), -1037845588, 1), + Restoration((1L << 30), -504697054, 1), + Running((1L << 31), 1488335491, 10), + Shadowmastery((1L << 32), 1389222957, 10), + Sorcery((1L << 33), -529481275, 1), + SpearMastery((1L << 34), -48279755, 20), + Spear((1L << 35), 83992115, 1), + StaffMastery((1L << 36), -61022283, 20), + Staff((1L << 37), 71438003, 1), + Stormcalling((1L << 38), -532064061, 10), + SwordMastery((1L << 39), -59316267, 20), + Sword((1L << 40), 73938643, 1), + Thaumaturgy((1L << 41), -2020131447, 10), + Theurgy((1L << 42), -888431326, 10), + Throwing((1L << 43), 391562015, 20), + Toughness((1L << 44), -660435875, 10), + UnarmedCombatMastery((1L << 45), 1692733771, 20), + UnarmedCombat((1L << 46), -1094332856, 1), + Warding((1L << 47), 1488142342, 1), + Warlockry((1L << 48), 1121393557, 10), + WayoftheGaana((1L << 49), -1954832975, 10), + WearArmorHeavy((1L << 50), 1112121635, 15), + WearArmorLight((1L << 51), 38031547, 1), + WearArmorMedium((1L << 52), 468015203, 5), + Wizardry((1L << 53), 218227659, 10), + Corruption((1L << 54), -1519268706, 10), + Abjuration((1L << 55), -2029900484, 10), + WayoftheWolf((1L << 56), 1668913067, 20), + WayoftheRat((1L << 57), -2114353637, 20), + WayoftheBear((1L << 58), -906390863, 20), + Orthanatos((1L << 59), -666929185, 20), + Bloodcraft((1L << 60), 40661438, 10), + Exorcism((1L << 61), 1444427097, 10), + Necromancy((1L << 62), -556571154, 10), + SunDancing((1L << 63), 22329752, 20); + + private long flag; + private int token; + private int reqLvl; + + CharacterSkills(long flag, int token, int reqLvl) { + this.flag = flag; + this.token = token; + this.reqLvl = reqLvl; + } + + public static CharacterSkills GetCharacterSkillByToken(int token) { + for (CharacterSkills skill : CharacterSkills.values()) { + if (skill.token == token) + return skill; + } + + Logger.info("Returned No Skill for token " + token + ". Defaulting to Axe"); + return CharacterSkills.Axe; + } + + public long getFlag() { + return flag; + } + + public void setFlag(long flag) { + this.flag = flag; + } + + public int getReqLvl() { + return this.reqLvl; + } + + public int getToken() { + return token; + } + + public void setToken(int token) { + this.token = token; + } + } + + ; + + public enum GuildHistoryType { + JOIN(1), + LEAVE(4), + BANISHED(3), + CREATE(7), + DISBAND(5); + private final int type; + + GuildHistoryType(int type) { + this.type = type; + } + + public int getType() { + return type; + } + } + + public enum SexType { + NONE, + MALE, + FEMALE; + } + + public enum ClassType { + FIGHTER, + HEALER, + ROGUE, + MAGE; + } + + public enum PromoteType { + Assassin(SexType.NONE), + Barbarian(SexType.NONE), + Bard(SexType.NONE), + Channeler(SexType.NONE), + Confessor(SexType.NONE), + Crusader(SexType.NONE), + Doomsayer(SexType.NONE), + Druid(SexType.NONE), + Fury(SexType.FEMALE), + Huntress(SexType.FEMALE), + Prelate(SexType.NONE), + Priest(SexType.NONE), + Ranger(SexType.NONE), + Scout(SexType.NONE), + Sentinel(SexType.NONE), + Templar(SexType.NONE), + Thief(SexType.NONE), + Warlock(SexType.MALE), + Warrior(SexType.NONE), + Wizard(SexType.NONE), + Nightstalker(SexType.NONE), + Necromancer(SexType.NONE), + ; + + private SexType sexRestriction; + + PromoteType(SexType sexRestriction) { + this.sexRestriction = sexRestriction; + } + + public SexType getSexRestriction() { + return sexRestriction; + } + } + + public enum ShrineType { + + Aelfborn(1701900, -75506007, true), + Aracoix(1703100, -563708986, true), + Centaur(1704000, 521645243, true), + Dwarf(1708500, -2000467257, true), + Elf(1703400, 1254603001, true), + HalfGiant(1709100, 349844468, true), + Human(1702200, 281172391, true), + Irekei(1702800, -764988442, true), + Minotaur(1704600, 549787579, true), + Nephilim(1701000, -655183799, true), + Shade(1700100, 1724071104, true), + Assassin(1700400, 1989015892, false), + Barbarian(1708800, 9157124, false), + Bard(1704300, 80190554, false), + Channeler(1702500, 5658278, false), + Confessor(1707600, 1871658719, false), + Crusader(1706700, -187454619, false), + Doomsayer(1700700, -993659433, false), + Druid(1701600, -926740122, false), + Fury(1705500, 214401375, false), + Huntress(1704900, 970312892, false), + Prelate(1707000, -225200922, false), + Priest(1705200, -535691898, false), + Ranger(1701300, 604716986, false), + Scout(1706100, -1497297486, false), + Sentinel(1707300, -184898375, false), + Templar(1707900, 826673315, false), + Thief(1708200, 1757633920, false), + Warlock(1706400, 1003385946, false), + Warrior(1703700, 931048026, false), + Wizard(1705800, 777115928, false), + Nightstalker(1709400, 373174890, false), + Necromancer(1709700, -319294505, false), + Vampire(1710000, 1049274530, true); + + private final int blueprintUUID; + private final int powerToken; + private final ArrayList shrines = new ArrayList<>(); + private final boolean isRace; + + ShrineType(int blueprintUUID, int powerToken, boolean isRace) { + this.blueprintUUID = blueprintUUID; + this.powerToken = powerToken; + this.isRace = isRace; + + } + + public int getBlueprintUUID() { + return blueprintUUID; + } + + public int getPowerToken() { + return powerToken; + } + + public ArrayList getShrinesCopy() { + ArrayList copyShrines = new ArrayList<>(); + copyShrines.addAll(shrines); + Collections.sort(copyShrines); + return copyShrines; + } + + public final void addShrineToServerList(Shrine shrine) { + synchronized (shrines) { + shrines.add(shrine); + } + } + + public final void RemoveShrineFromServerList(Shrine shrine) { + synchronized (shrines) { + shrines.remove(shrine); + } + } + + public boolean isRace() { + return isRace; + } + } + + public enum GuildState { + + Errant(0), + Sworn(4), + Protectorate(6), + Petitioner(2), + Province(8), + Nation(5), + Sovereign(7); + + private final int stateID; + + GuildState(int stateID) { + this.stateID = stateID; + } + + public int getStateID() { + return stateID; + } + + } + + + // Building group enumeration. + // This is used to drive linear equations to calculate + // structure hp, ranking times and such from within + // the BuildingBlueprint class. + // + // It is also used as a bitvector flag in the npc + // building slot mechanics. + + public enum BuildingGroup implements EnumBitSetHelper { + NONE(0, 0), + TOL(64f, 64f), + BARRACK(32f, 64f), + CHURCH(64f, 64f), + FORGE(32f, 64f), + SPIRE(16f, 16f), + GENERICNOUPGRADE(16f, 16f), + WALLSTRAIGHT(16f, 64), + WALLCORNER(64f, 64f), + SMALLGATE(64f, 64), + ARTYTOWER(64f, 64), + SIEGETENT(32f, 32f), + BANESTONE(16f, 16f), + MINE(16f, 16f), + WAREHOUSE(32f, 32f), + SHRINE(16f, 16f), + RUNEGATE(64f, 64f), + AMAZONHALL(64f, 64f), + CATHEDRAL(64f, 64f), + GREATHALL(64f, 64f), + KEEP(64f, 64f), + THIEFHALL(64f, 24f), + TEMPLEHALL(64f, 64f), + WIZARDHALL(64f, 64f), + ELVENHALL(64f, 64f), + ELVENSANCTUM(64f, 64f), + IREKEIHALL(64f, 64f), + FORESTHALL(64f, 64f), + MAGICSHOP(32f, 32f), + BULWARK(32f, 32f), + SHACK(16f, 16f), + INN(64f, 32f), + TAILOR(32f, 32f), + VILLA(64f, 32f), + ESTATE(64f, 64f), + FORTRESS(64f, 64f), + CITADEL(64f, 64f), + WALLSTRAIGHTTOWER(16f, 64), + WALLSTAIRS(64, 64); + + private final Vector2f extents; + + BuildingGroup(float extentX, float extentY) { + this.extents = new Vector2f(extentX, extentY); + } + + public Vector2f getExtents() { + return extents; + } + + } + + public enum UpdateType { + ALL, + MOVEMENT, + REGEN, + FLIGHT, + LOCATION, + MOVEMENTSTATE; + } + + public enum ServerType { + WORLDSERVER, + LOGINSERVER, + NONE; + } + + public enum ChatChannel implements EnumBitSetHelper { + System, + Announce, + Unknown, + Commander, + Address, + Nation, + Leader, + Shout, + Siege, + Territory, + Info, + CSR, + Guild, + InnerCouncil, + Group, + City, + Say, + Emote, + Social, + Tell, + Combat, + Powers, + Snoop, + Debug, + Global, + Trade, + PVP, + Mine, + Alert, + Assassin, + Barbarian, + Bard, + Channeler, + Confessor, + Crusader, + Doomsayer, + Druid, + Fury, + Huntress, + Necromancer, + Nightstalker, + Prelate, + Priest, + Ranger, + Scout, + Sentinel, + Templar, + Thief, + Warlock, + Warrior, + Wizard; + + } + + public enum AllianceType { + RecommendedAlly, + RecommendedEnemy, + Ally, + Enemy; + } + + public enum FriendStatus { + Available, + Away, + Busy; + } + + public enum ProfitType { + + + BuyNormal("buy_normal"), + BuyGuild("buy_guild"), + BuyNation("buy_nation"), + SellNormal("sell_normal"), + SellGuild("sell_guild"), + SellNation("sell_nation"); + + public String dbField; + + private ProfitType(String dbField) { + this.dbField = dbField; + } + } + + public enum GameObjectType { + + /* + * These will be used as the 4 high bytes in the application protocol's + * long CompositeID field and when tracking an AbstractGameObject's type + * from within the code. The low 4 bytes will be used as the Object's + * UUID + */ + unknown, + Account, + AccountIP, + ActiveEffect, + ArmorBase, + BaseClass, + BeardStyle, + BlockedIP, + Building, + BuildingLocation, + BuildingModelBase, + CharacterPower, + CharacterPowers, + CharacterRune, + CharacterSkill, + City, + Contract, + Corpse, + CSSession, + EffectsResourceCosts, + EnchantmentBase, + GenericItemBase, + Group, + Guild, + GuildAllianceEnemy, + GuildBanish, + GuildCharacterKOS, + GuildGuildKOS, + GuildTableList, + HairStyle, + Item, + ItemContainer, + ItemEnchantment, + JewelryBase, + Kit, + MenuOption, + Mine, + Mob, + MobBase, + MobEquipment, + MobLoot, + MobType, + NPC, + NPCClassRune, + NPCClassRuneThree, + NPCClassRuneTwo, + NPCExtraRune, + NPCRaceRune, + NPCRune, + NPCShopkeeperRune, + NPCTrainerRune, + Nation, + PlayerCharacter, + PlayerInfo, + PowerGrant, + PowerReq, + PowersBase, + PowersBaseAttribute, + PromotionClass, + Race, + RuneBase, + RuneBaseAttribute, + RuneBaseEffect, + SkillReq, + SkillsBase, + SkillsBaseAttribute, + MobileBooty, + StrongBox, + Trigger, + ValidRaceBeardStyle, + ValidRaceClassCombo, + ValidRaceHairStyle, + VendorDialog, + Warehouse, + WeaponBase, + WorldServerInfo, + WorldServerInfoSnapshot, + Shrine, + Zone, + Transaction; + } + + public enum ContainerType { + BANK, + INVENTORY, + VAULT; + } + + ; + + public enum CompoundCurveType { + DefaultFlat(0), + DefaultSlope(1), + DefaultSlopeDown(-1), + SL0001Up(0.01), + SL0003Up(0.03), + SL0005Up(0.05), + SL0006Up(0.06), + SL0007Up(0.07), + SL0008Up(0.08), + SL0010Up(0.10), + SL0011Up(0.11), + SL0012Up(0.12), + SL0013Up(0.13), + SL0014Up(0.14), + SL00143U(0.143), + SL0015Up(0.15), + SL0016Up(0.16), + SL0019Up(0.19), + SL0020Up(0.20), + SL0021Up(0.21), + SL0022Up(0.22), + SL0023Up(0.23), + SL0024Up(0.24), + SL0025Up(0.25), + SL0026Up(0.26), + SL0028Up(0.28), + SL0030Up(0.30), + SL0031Up(0.31), + SL0032Up(0.32), + SL0033Up(0.33), + SL0034Up(0.34), + SL0035Up(0.35), + SL0037Up(0.37), + SL0038Up(0.38), + SL0039Up(0.39), + SL0040Up(0.40), + SL0041Up(0.41), + SL0042Up(0.42), + SL0043Up(0.43), + SL0044Up(0.44), + SL0045Up(0.45), + SL0046Up(0.46), + SL0047Up(0.47), + SL0048Up(0.48), + SL0050Up(0.50), + SL0051Up(0.51), + SL0053Up(0.53), + SL0054Up(0.54), + SL0055Up(0.55), + SL0056Up(0.56), + SL0057Up(0.57), + SL0058Up(0.58), + SL0060Up(0.60), + SL0061Up(0.61), + SL0063Up(0.63), + SL0064Up(0.64), + SL0065Up(0.65), + SL0066Up(0.66), + SL0067Up(0.67), + SL0068Up(0.68), + SL0069Up(0.69), + SL0070Up(0.70), + SL0071Up(0.71), + SL0073Up(0.73), + SL0074Up(0.74), + SL0075Up(0.75), + SL0076Up(0.76), + SL0077Up(0.77), + SL0079Up(0.79), + SL0080Up(0.80), + SL0081Up(0.81), + SL0082Up(0.82), + SL0083Up(0.83), + SL0084Up(0.84), + SL0085Up(0.85), + SL0087Up(0.87), + SL0088Up(0.88), + SL0089Up(0.89), + SL0090Up(0.90), + SL0092Up(0.92), + SL0098Up(0.98), + SL0100Up(1.00), + SL0106Up(1.06), + SL0109Up(1.09), + SL0112Up(1.12), + SL0113Up(1.13), + SL0115Up(1.15), + SL0116Up(1.16), + SL0122Up(1.22), + SL0123Up(1.23), + SL0125Up(1.25), + SL0128Up(1.28), + SL0130Up(1.30), + SL0135Up(1.35), + SL0140Up(1.40), + SL0143Up(1.43), + SL0145Up(1.45), + SL0150Up(1.50), + SL0154Up(1.54), + SL0163Up(1.63), + SL0166Up(1.66), + SL0175Up(1.75), + SL0188Up(1.88), + SL0190Up(1.90), + SL0200Up(2.00), + SL0222Up(2.22), + SL0225Up(2.25), + SL0235Up(2.35), + SL0238Up(2.38), + SL0250Up(2.50), + SL0260Up(2.60), + SL0263Up(2.63), + SL0275Up(2.75), + SL0280Up(2.80), + SL0300Up(3.00), + SL0308Up(3.08), + SL0312Up(3.12), + SL0350Up(3.50), + SL0357Up(3.57), + SL0360Up(3.60), + SL0375Up(3.75), + SL0380Up(3.80), + SL0385Up(3.85), + SL0400Up(4.00), + SL0410Up(4.10), + SL0429Up(4.29), + SL0450Up(4.50), + SL0460Up(4.60), + SL0480Up(4.80), + SL0500Up(5.00), + SL0510Up(5.10), + SL0550Up(5.50), + SL0600Up(6.00), + SL0643Up(6.43), + SL0714Up(7.14), + SL0750Up(7.50), + SL0790Up(7.90), + SL0800Up(8.00), + SL0900Up(9.00), + SL1000Up(10.00), + SL1050Up(10.50), + SL1100Up(11.00), + SL1125Up(11.25), + SL1200Up(12.00), + SL1282Up(12.82), + SL1300Up(13.00), + SL1350Up(13.50), + SL1400Up(14.00), + SL1500Up(15.00), + SL1579Up(15.79), + SL2000Up(20.00), + SL2100Up(21.00), + SL2500Up(25.00), + SL2521Up(25.21), + SL3000Up(30.00), + SL4000Up(40.00), + SL5000Up(50.00), + SL6000Up(60.00), + SL7500Up(75.00), + SL8000Up(80.00), + SL12000Up(120.00), + SL14000Up(140.00), + SL30000Up(300.00), + SL66600Up(666.00), + SL71500Up(715.00), + SL00003Down(-0.003), + SL0001Down(-0.01), + SL0003Down(-0.03), + SL0004Down(-0.04), + SL0005Down(-0.05), + SL0006Down(-0.06), + SL0007Down(-0.07), + SL00075Down(-0.075), + SL0008Down(-0.08), + SL0009Down(-0.09), + SL0010Down(-0.10), + SL0011Down(-0.11), + SL0012Down(-0.12), + SL0013Down(-0.13), + SL00125Down(-0.125), + SL0014Down(-0.14), + SL0015Down(-0.15), + SL0016Down(-0.16), + SL0017Down(-0.17), + SL00175Down(-0.175), + SL0018Down(-0.18), + SL0019Down(-0.19), + SL0020Down(-0.20), + SL0023Down(-0.23), + SL0024Down(-0.24), + SL0025Down(-0.25), + SL0027Down(-0.27), + SL0028Down(-0.28), + SL0029Down(-0.29), + SL0030Down(-0.30), + SL0032Down(-0.32), + SL0033Down(-0.33), + SL0035Down(-0.35), + SL0038Down(-0.38), + SL0040Down(-0.40), + SL0044Down(-0.44), + SL0045Down(-0.45), + SL0050Down(-0.50), + SL0055Down(-0.55), + SL0060Down(-0.60), + SL0062Down(-0.62), + SL0063Down(-0.63), + SL0064Down(-0.64), + SL0066Down(-0.66), + SL0069Down(-0.69), + SL0071Down(-0.71), + SL0075Down(-0.75), + SL0077Down(-0.77), + SL0079Down(-0.79), + SL0080Down(-0.80), + SL0090Down(-0.90), + SL0100Down(-1.00), + SL0113Down(-1.13), + SL0120Down(-1.20), + SL0125Down(-1.25), + SL0128Down(-1.28), + SL0130Down(-1.30), + SL0135Down(-1.35), + SL0150Down(-1.50), + SL0175Down(-1.75), + SL0188Down(-1.88), + SL0200Down(-2.00), + SL0225Down(-2.25), + SL0250Down(-2.50), + SL0263Down(-2.63), + SL0300Down(-3.00), + SL0357Down(-3.57), + SL0385Down(-3.85), + SL0429Down(-4.29), + SL0450Down(-4.50), + SL0500Down(-5.00), + SL0550Down(-5.50), + SL0600Down(-6.00), + SL0643Down(-6.43), + SL0714Down(-7.14), + SL0750Down(-7.50), + SL0790Down(-7.90), + SL0800Down(-8.00), + SL1000Down(-10.00), + SL1050Down(-10.50), + SL1200Down(-12.00), + SL1350Down(-13.50), + SL1500Down(-15.00), + SL1579Down(-15.79), + SL2000Down(-20.00), + SL2400Down(-24.00), + SL2500Down(-25.00), + SL3000Down(-30.00), + SL4500Down(-45.00), + SL7500Down(-75.00), + SIVL0005(0.005), + SIVL0008(0.008), + SIVL0009(0.009), + SIVL0010(0.010), + SIVL0012(0.012), + SIVL0013(0.013), + SIVL0014(0.014), + SIVL0015(0.015), + SIVL0016(0.016), + SIVL0017(0.017), + SIVL0019(0.019), + SIVL0020(0.020), + SIVL0021(0.021), + SIVL0022(0.022), + SIVL0023(0.023), + SIVL0024(0.024), + SIVL0025(0.025), + SIVL0026(0.026), + SIVL0027(0.027), + SIVL0029(0.029), + SIVL0030(0.030), + SIVL0031(0.031), + SIVL0032(0.032), + SIVL0033(0.033), + SIVL0034(0.034), + SIVL0035(0.035), + SIVL0036(0.036), + SIVL0038(0.038), + SIVL0040(0.040), + SIVL0044(0.044), + SIVL0046(0.046), + SIVL0048(0.048), + SIVL0055(0.055), + SIVL0056(0.056), + SIVL0057(0.057), + SIVL0058(0.058), + SIVL0060(0.060), + SIVL0061(0.061), + SIVL0066(0.066), + SIVL0067(0.067), + SIVL0075(0.075), + SIVL0078(0.078), + SIVL0130(0.130), + SIVL0150(0.150), + SIVL0205(0.205), + SIVL0220(0.220), + SIVL0243(0.243), + SIVL0360(0.360); + + private final double value; + + private CompoundCurveType(double value) { + + this.value = value; + } + + public double getValue() { + return value; + } + } + + public enum PowerFailCondition { + + Attack, + AttackSwing, + Cast, + CastSpell, + EquipChange, + Logout, + Move, + NewCharm, + Sit, + TakeDamage, + TerritoryClaim, + UnEquip; + } + + public enum PowerSubType { + Amount, + Ramp, + UseAddFormula, + DamageType1, + DamageType2, + DamageType3, + Cancel; + } + + public enum PowerCategoryType { + NONE, + WEAPON, + BUFF, + DEBUFF, + SPECIAL, + DAMAGE, + DISPEL, + INVIS, + STUN, + TELEPORT, + HEAL, + VAMPDRAIN, + BLESSING, + BOONRACE, + BOONCLASS, + BEHAVIOR, + CHANT, + GROUPBUFF, + MOVE, + FLIGHT, + GROUPHEAL, + AEDAMAGE, + BREAKFLY, + AE, + TRANSFORM, + TRACK, + SUMMON, + STANCE, + RECALL, + SPIREPROOFTELEPORT, + SPIREDISABLE, + THIEF; + } + + public enum PowerTargetType { + + SELF, + PCMOBILE, + PET, + MOBILE, + PC, + WEAPON, + GUILDLEADER, + BUILDING, + GROUP, + ARMORWEAPONJEWELRY, + CORPSE, + JEWELRY, + WEAPONARMOR, + ARMOR, + ITEM; + } + + public enum objectMaskType { + PLAYER, + MOB, + PET, + CORPSE, + BUILDING, + UNDEAD, + BEAST, + HUMANOID, + NPC, + IAGENT, + DRAGON, + RAT, + SIEGE, + CITY, + ZONE; + + public static EnumSet AGGRO = EnumSet.of(PLAYER, PET); + public static EnumSet MOBILE = EnumSet.of(PLAYER, MOB, PET); + public static EnumSet STATIC = EnumSet.of(CORPSE, BUILDING, NPC); + + } + + public enum ItemContainerType { + NONE, + INVENTORY, + EQUIPPED, + BANK, + VAULT, + FORGE, + WAREHOUSE; + } + + public enum ItemSlotType implements EnumBitSetHelper { + RHELD, + LHELD, + HELM, + CHEST, + SLEEVES, + HANDS, + RRING, + LRING, + AMULET, + LEGS, + FEET, + CLOAK, + SHIN, + UPLEGS, + UPARM, + WINGS, + BEARD, + HAIR; + } + + public enum CityBoundsType { + + GRID(640), + ZONE(875), + PLACEMENT(1050); + + public final float extents; + + CityBoundsType(float extents) { + this.extents = extents; + } + } + + public enum GuildType { + NONE("None", new String[][]{{"None"}}, new String[]{"Thearchy", "Common Rule", "Theocracy", "Republic Rule"}), + CATHEDRAL("Church of the All-Father", new String[][]{ + {"Acolyte", "Acolyte"}, + {"Catechist"}, + {"Deacon", "Deaconess"}, + {"Priest", "Priestess"}, + {"High Priest", "High Priestess"}, + {"Bishop", "Bishop"}, + {"Lord Cardinal", "Lady Cardinal"}, + {"Patriarch", "Matriarch"}}, + new String[]{"Thearchy", "Common Rule", "Theocracy", "Republic Rule"}), + MILITARY("Military", new String[][]{ + {"Recruit"}, + {"Footman"}, + {"Corporal"}, + {"Sergeant"}, + {"Lieutenant"}, + {"Captain"}, + {"General"}, + {"Lord Marshall", "Lady Marshall"}}, + new String[]{"Autocracy", "Common Rule", "Council Rule", "Militocracy"}), + TEMPLE("Temple of the Cleansing Flame", new String[][]{ + {"Aspirant"}, + {"Novice"}, + {"Initiate"}, + {"Inquisitor"}, + {"Jannisary"}, + {"Tribune"}, + {"Lictor"}, + {"Justiciar"}, + {"Pontifex", "Pontifectrix"}}, + new String[]{"Despot Rule", "Common Rule", "Protectorship", "Republic Rule"}), + BARBARIAN("Barbarian Clan", new String[][]{ + {"Barbarian"}, + {"Skald"}, + {"Raider"}, + {"Karl"}, + {"Jarl"}, + {"Chieftain"}, + {"Thane"}}, + new String[]{"Chiefdom", "Common Rule", "Council Rule", "Republic Rule"}), + RANGER("Ranger's Brotherhood", new String[][]{ + {"Yeoman"}, + {"Pathfinder"}, + {"Tracker"}, + {"Seeker"}, + {"Protector"}, + {"Guardian"}, + {"Lord Protector", "Lady Protector"}}, + new String[]{"Despot Rule", "Collectivism", "Council Rule", "Republic Rule"}), + AMAZON("Amazon Temple", new String[][]{ + {"Amazon Thrall", "Amazon"}, + {"Amazon Slave", "Amazon Warrior"}, + {"Amazon Servant", "Amazon Chieftess"}, + {"Amazon Consort", "Amazon Princess"}, + {"Amazon Seneschal", "Majestrix"}, + {"Amazon Regent", "Imperatrix"}}, + new String[]{"Despot Rule", "Common Rule", "Gynarchy", "Gynocracy"}), + NOBLE("Noble House", new String[][]{ + {"Serf"}, + {"Vassal"}, + {"Exultant"}, + {"Lord", "Lady"}, + {"Baron", "Baroness"}, + {"Count", "Countess"}, + {"Duke", "Duchess"}, + {"King", "Queen"}, + {"Emperor", "Empress"}}, + new String[]{"Monarchy", "Common Rule", "Feodality", "Republic"}), + WIZARD("Wizard's Conclave", new String[][]{ + {"Apprentice"}, + {"Neophyte"}, + {"Adeptus Minor"}, + {"Adeptus Major"}, + {"Magus"}, + {"High Magus"}, + {"Archmagus"}}, + new String[]{"Despot Rule", "Common Rule", "Council Rule", "Magocracy"}), + MERCENARY("Mercenary Company", new String[][]{ + {"Soldier"}, + {"Man-at-Arms"}, + {"Veteran"}, + {"Myrmidon"}, + {"Captain"}, + {"Commander"}, + {"High Commander"}, + {"Warlord"}}, + new String[]{"Magistrature", "Mob Law", "Council Rule", "Republic Rule"}), + THIEVES("Thieve's Den", new String[][]{ + {"Urchin"}, + {"Footpad"}, + {"Grifter"}, + {"Burglar"}, + {"Collector"}, + {"Naster Thief"}, + {"Treasurer"}, + {"Grandmaster Thief"}, + {"Grandfather"}}, + new String[]{"Despot Rule", "Common Rule", "Oligarchy", "Republic Rule"}), + DWARF("Dwarf Hold", new String[][]{ + {"Citizen"}, + {"Master"}, + {"Councilor"}, + {"Thane"}, + {"Great Thane"}, + {"High Thane"}}, + new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), + HIGHCOURT("High Court", new String[][]{ + {"Eccekebe"}, + {"Saedulor"}, + {"Hodrimarth"}, + {"Mandrae"}, + {"Imaelin"}, + {"Thaelostor", "Thaelostril"}, + {"Dar Thaelostor", "Dar Thaelostril"}, + {"Aglaeron"}, + {"Ellestor", "Elestril"}}, + new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), + VIRAKT("Virakt", new String[][]{ + {"Jov'uus"}, + {"Urikhan"}, + {"Irkhan"}, + {"Khal'usht"}, + {"Arkhalar"}, + {"Khal'uvho"}, + {"Khar'uus"}, + {"Kryqh'khalin"}}, + new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), + BRIALIA("Coven of Brialia", new String[][]{ // Unknown Rank names + {"Devotee"}, + {"Initiated"}, + {"Witch of the First"}, + {"Witch of the Second"}, + {"Witch of the Third"}, + {"Elder"}, + {"Hierophant"}, + {"Witch King", "Witch Queen"}}, + new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), + UNHOLY("Unholy Legion", new String[][]{ // Unknown Rank names + {"Footman"}, + {"Fell Legionaire"}, + {"Fell Centurion"}, + {"Dark Captain"}, + {"Dark Commander"}, + {"Dark Master", "Dark Mistress"}, + {"Dread Master", "Dread Mistress"}, + {"Dread Lord", "Dread Lady"}}, + new String[]{"Despot Rule", "Despot Rule", "Council Rule", "Republic Rule"}), + SCOURGE("Cult of the Scourge", new String[][]{ + {"Thrall"}, + {"Mudir"}, + {"Dark Brother", "Dark Sister"}, + {"Hand of the Dark"}, + {"Dark Father", "Dark Mother"}}, + new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), + PIRATE("Pirate Crew", new String[][]{ + {"Midshipman", "Midshipwoman"}, + {"Sailor"}, + {"Third Mat"}, + {"Second Mat"}, + {"First Mate"}, + {"Captain"}}, + new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), + HERALD("Academy of Heralds", new String[][]{ + {"Pupil"}, + {"Scribe"}, + {"Recorder"}, + {"Scrivener"}, + {"Chronicler"}, + {"Scholar"}, + {"Archivist"}, + {"Loremaster"}}, + new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), + CENTAUR("Centaur Cohort", new String[][]{ + {"Hoplite"}, + {"Peltast"}, + {"Myrmidon"}, + {"Myrmidon"}, + {"Cataphract"}, + {"Septenrion"}, + {"Praetorian"}, + {"Paragon"}}, + new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), + KHREE("Aracoix Kh'ree", new String[][]{ + {"Duriacor"}, + {"Exarch"}, + {"Tetrarch"}, + {"Dimarch"}, + {"Elnarch"}, + {"Illiarch"}, + {"Tellotharch"}, + {"Erentar"}, + {"Araceos"}, + {"Hierarch"}}, + + new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}); + + private final String name; + private final String[][] ranks; //Stored Rank#->Gender(M,F) + private final String[] leadershipTypes; + + GuildType(String name, String[][] ranks, String[] leadershipTypes) { + this.name = name; + this.ranks = ranks; + this.leadershipTypes = leadershipTypes; + } + + public static GuildType getGuildTypeFromCharter(ItemBase itemBase) { + + GuildType charterType; + + // Must be a valid charter object + + if (itemBase.getType().equals(ItemType.GUILDCHARTER) == false) + return GuildType.NONE; //No guild Type + + // No switches on long in java. Cast to int + // when refactor to long uuid's. Loss won't matter + // with values this small. + + switch (itemBase.getUUID()) { + + case 559: + charterType = GuildType.CATHEDRAL; + break; + case 560: + charterType = GuildType.MILITARY; + break; + case 561: + charterType = GuildType.TEMPLE; + break; + case 562: + charterType = GuildType.BARBARIAN; + break; + case 563: + charterType = GuildType.RANGER; + break; + case 564: + charterType = GuildType.AMAZON; + break; + case 565: + charterType = GuildType.NOBLE; + break; + case 566: + charterType = GuildType.WIZARD; + break; + case 567: + charterType = GuildType.MERCENARY; + break; + case 568: + charterType = GuildType.THIEVES; + break; + case 569: + charterType = GuildType.DWARF; + break; + case 570: + charterType = GuildType.HIGHCOURT; + break; + case 571: + charterType = GuildType.VIRAKT; + break; + case 572: + charterType = GuildType.SCOURGE; + break; + case 573: + charterType = GuildType.KHREE; + break; + case 574: + charterType = GuildType.CENTAUR; + break; + case 575: + charterType = GuildType.UNHOLY; + break; + case 576: + charterType = GuildType.PIRATE; + break; + case 577: + charterType = GuildType.BRIALIA; + break; + + default: + charterType = GuildType.HERALD; + } + + return charterType; + } + + public static GuildType getGuildTypeFromInt(int i) { + return GuildType.values()[i]; + } + + public String getCharterName() { + return this.name; + } + + public int getNumberOfRanks() { + return ranks.length; + } + + public String getRankForGender(int rank, boolean male) { + if (ranks.length < rank) { + return ""; + } + + if (ranks[rank].length != 1 && !male) { + return ranks[rank][1]; + } + return ranks[rank][0]; + } + + public String getLeadershipType(int i) { + return leadershipTypes[i]; + } + + } + + public enum MinionClass { + MELEE, + ARCHER, + MAGE; + } + + public enum MinionType { + AELFBORNGUARD(951, 1637, MinionClass.MELEE, "Guard", "Aelfborn"), + AELFBORNMAGE(952, 1635, MinionClass.MAGE, "Adept", "Aelfborn"), + AMAZONGUARD(1500, 1670, MinionClass.MELEE, "Guard", "Amazon"), + AMAZONMAGE(1502, 1638, MinionClass.MAGE, "Fury", "Amazon"), + ARACOIXGUARD(1600, 1672, MinionClass.MELEE, "Guard", "Aracoix"), //used guard captain equipset. + ARACOIXMAGE(1602, 885, MinionClass.MAGE, "Adept", "Aracoix"), + CENTAURGUARD(1650, 1642, MinionClass.MELEE, "Guard", "Centaur"), + CENTAURMAGE(1652, 1640, MinionClass.MAGE, "Druid", "Centaur"), + DWARVENARCHER(845, 1644, MinionClass.ARCHER, "Marksman", "Dwarven"), + DWARVENGUARD(1050, 1666, MinionClass.MELEE, "Guard", "Dwarven"), + DWARVENMAGE(1052, 1643, MinionClass.MAGE, "War Priest", "Dwarven"), + ELFGUARD(1180, 1671, MinionClass.MELEE, "Guard", "Elven"), //old 1645 + ELFMAGE(1182, 1667, MinionClass.MAGE, "Adept", "Elven"), + FORESTGUARD(1550, 1668, MinionClass.MELEE, "Guard", "Forest"), //captain changed to guard equipset + FORESTMAGE(1552, 436, MinionClass.MAGE, "Adept", "Forest"), + HOLYGUARD(1525, 1658, MinionClass.MELEE, "Guard", "Holy Church"), + HOLYMAGE(1527, 1646, MinionClass.MAGE, "Prelate", "Holy Church"), + HUMANARCHER(846, 1654, MinionClass.ARCHER, "Archer", "Human"), + HUMANGUARD(840, 1665, MinionClass.MELEE, "Guard", "Human"), + HUMANMAGE(848, 1655, MinionClass.MAGE, "Adept", "Human"), + IREKEIGUARD(1350, 1659, MinionClass.MELEE, "Guard", "Irekei"), + IREKEIMAGE(1352, 1660, MinionClass.MAGE, "Adept", "Irekei"), + MINOTAURARCHER(1701, 0, MinionClass.ARCHER, "Archer", "Minotaur"), + MINOTAURGUARD(1700, 1673, MinionClass.MELEE, "Guard", "Minotaur"), + NORTHMANGUARD(1250, 1669, MinionClass.MELEE, "Guard", "Northman"), + NORTHMANMAGE(1252, 1650, MinionClass.MAGE, "Runecaster", "Northman"), + SHADEGUARD(1450, 1662, MinionClass.MELEE, "Guard", "Shade"), + SHADEMAGE(1452, 1664, MinionClass.MAGE, "Adept", "Shade"), + TEMPLARGUARD(841, 1564, MinionClass.MELEE, "Marksman", "Templar"), + TEMPLEGUARD(1575, 1652, MinionClass.MELEE, "Guard", "Temple"), + TEMPLEMAGE(1577, 1656, MinionClass.MAGE, "Confessor", "Temple"), + UNDEADGUARD(980100, 1674, MinionClass.MELEE, "Guard", "Undead"), + UNDEADMAGE(980102, 1675, MinionClass.MAGE, "Adept", "Undead"), + WEREWOLFGUARD(980104, 0, MinionClass.MELEE, "Guard", "Werewolf"), + WEREBEARGUARD(980103, 0, MinionClass.MELEE, "Guard", "Werebear"); + public static HashMap ContractToMinionMap = new HashMap<>(); + private final int captainContractID; + private final int equipSetID; + private final MinionClass minionClass; + private final String name; + private final String race; + + MinionType(int captainContractID, int equipSetID, MinionClass minionClass, String name, String race) { + + this.captainContractID = captainContractID; + this.equipSetID = equipSetID; + this.minionClass = minionClass; + this.name = name; + this.race = race; + + } + + public static void InitializeMinions() { + + for (MinionType minionType : MinionType.values()) + ContractToMinionMap.put(minionType.captainContractID, minionType); + } + + public String getName() { + return name; + } + + public String getRace() { + return race; + } + + } + + public enum GridObjectType { + STATIC, + DYNAMIC; + } + + public enum SupportMsgType { + NONE(0), + PROTECT(1), + UNPROTECT(3), + VIEWUNPROTECTED(4), + REMOVETAX(6), + ACCEPTTAX(7), + CONFIRMPROTECT(8); + + public static HashMap typeLookup = new HashMap<>(); + private final int type; + + SupportMsgType(int messageType) { + this.type = messageType; + + } + + public static void InitializeSupportMsgType() { + + for (SupportMsgType supportMsgType : SupportMsgType.values()) + typeLookup.put(supportMsgType.type, supportMsgType); + } + } + + public enum ResourceType implements EnumBitSetHelper { + + STONE(1580000), + TRUESTEEL(1580001), + IRON(1580002), + ADAMANT(1580003), + LUMBER(1580004), + OAK(1580005), + BRONZEWOOD(1580006), + MANDRAKE(1580007), + COAL(1580008), + AGATE(1580009), + DIAMOND(1580010), + ONYX(1580011), + AZOTH(1580012), + ORICHALK(1580013), + ANTIMONY(1580014), + SULFUR(1580015), + QUICKSILVER(1580016), + GALVOR(1580017), + WORMWOOD(1580018), + OBSIDIAN(1580019), + BLOODSTONE(1580020), + MITHRIL(1580021), + GOLD(7); + + public static HashMap resourceLookup = new HashMap<>(); + public int itemID; + + ResourceType(int itemID) { + this.itemID = itemID; + } + + public static void InitializeResourceTypes() { + + for (ResourceType resourceType : ResourceType.values()) + resourceLookup.put(resourceType.itemID, resourceType); + } + } + + public enum PowerActionType { + ApplyEffect, + ApplyEffects, + Block, + Charm, + ClaimMine, + ClearAggro, + ClearNearbyAggro, + Confusion, + CreateMob, + DamageOverTime, + DeferredPower, + DirectDamage, + Invis, + MobRecall, + Peek, + Recall, + RemoveEffect, + Resurrect, + RunegateTeleport, + SetItemFlag, + SimpleDamage, + SpireDisable, + Steal, + Summon, + Teleport, + Track, + TransferStat, + TransferStatOT, + Transform, + TreeChoke + } + + public enum AccountStatus { + BANNED, + ACTIVE, + ADMIN; + } + + public enum MobBehaviourType { + None(null, false, false, false, false, false), + //Power + Power(null, false, true, true, true, false), + PowerHelpee(Power, false, true, true, false, true), + PowerHelpeeWimpy(Power, true, false, true, false, false), + PowerGrouperWimpy(Power, true, false, true, false, false), + PowerAggro(Power, false, true, true, false, true), + PowerAggroHelpee(Power, false, true, true, false, true), + //Aggro + Aggro(null, false, true, true, true, false), + AggroHelpee(Aggro, false, true, true, false, true), AggroHelpeeWimpy(Aggro, true, false, true, false, false), AggroGrouperWimpy(Aggro, true, false, true, false, false), //Spell @@ -2811,30 +2811,30 @@ public class Enum { SpellAggro(Spell, false, true, true, false, true), SpellAggroHelpee(Spell, false, true, true, false, true), SpellAggroHelpeeWimpy(Spell, true, false, true, false, false), - SpellAggroHelpeeEpic(Spell, false, true, true, false, true), - SpellAggroGrouperWimpy(Spell, true, false, true, false, false), - //Independent Types - SimpleStandingGuard(null, false, false, false, false, false), - Pet1(null, false, false, true, false, false), - Simple(null, false, false, true, false, false), - Helpee(null, false, true, true, false, true), - HelpeeWimpy(null, true, false, true, false, false), - GuardCaptain(null, false, true, true, false, false), - GuardMinion(GuardCaptain, false, true, true, false, false), - GuardWallArcher(null, false, true, false, false, false), - Wanderer(null, false, true, true, false, false), - HamletGuard(null, false, true, false, false, false), - AggroWanderer(null, false, false, true, false, false); - - private static HashMap _behaviourTypes = new HashMap<>(); - public MobBehaviourType BehaviourHelperType; - public boolean isWimpy; - public boolean isAgressive; - public boolean canRoam; - public boolean callsForHelp; - public boolean respondsToCallForHelp; - - MobBehaviourType(MobBehaviourType helpeebehaviourType, boolean wimpy, boolean agressive, boolean canroam, boolean callsforhelp, boolean respondstocallforhelp) { + SpellAggroHelpeeEpic(Spell, false, true, true, false, true), + SpellAggroGrouperWimpy(Spell, true, false, true, false, false), + //Independent Types + SimpleStandingGuard(null, false, false, false, false, false), + Pet1(null, false, false, true, false, false), + Simple(null, false, false, true, false, false), + Helpee(null, false, true, true, false, true), + HelpeeWimpy(null, true, false, true, false, false), + GuardCaptain(null, false, true, true, false, false), + GuardMinion(GuardCaptain, false, true, true, false, false), + GuardWallArcher(null, false, true, false, false, false), + Wanderer(null, false, true, true, false, false), + HamletGuard(null, false, true, false, false, false), + AggroWanderer(null, false, false, true, false, false); + + private static HashMap _behaviourTypes = new HashMap<>(); + public MobBehaviourType BehaviourHelperType; + public boolean isWimpy; + public boolean isAgressive; + public boolean canRoam; + public boolean callsForHelp; + public boolean respondsToCallForHelp; + + MobBehaviourType(MobBehaviourType helpeebehaviourType, boolean wimpy, boolean agressive, boolean canroam, boolean callsforhelp, boolean respondstocallforhelp) { this.BehaviourHelperType = helpeebehaviourType; this.isWimpy = wimpy; this.isAgressive = agressive; diff --git a/src/engine/InterestManagement/HeightMap.java b/src/engine/InterestManagement/HeightMap.java index e7272dba..3909028d 100644 --- a/src/engine/InterestManagement/HeightMap.java +++ b/src/engine/InterestManagement/HeightMap.java @@ -100,7 +100,7 @@ public class HeightMap { float numOfBuckets = this.heightmapImage.getWidth() - 1; float calculatedWidth = this.fullExtentsX / numOfBuckets; this.bucketWidthX = calculatedWidth; - this.bucketWidthY = this.bucketWidthX; // This makes no sense. + this.bucketWidthY = this.bucketWidthX; // This makes no sense. // Generate pixel array from image data @@ -142,7 +142,7 @@ public class HeightMap { this.bucketWidthX = 1; this.bucketWidthY = 1; - this.pixelColorValues = new int[this.fullExtentsX + 1][this.fullExtentsY+1]; + this.pixelColorValues = new int[this.fullExtentsX + 1][this.fullExtentsY + 1]; for (int y = 0; y <= this.fullExtentsY; y++) { for (int x = 0; x <= this.fullExtentsX; x++) { @@ -153,7 +153,7 @@ public class HeightMap { HeightMap.heightmapByLoadNum.put(this.zoneLoadID, this); } - + public HeightMap(Zone zone) { this.heightMapID = 999999; @@ -180,7 +180,7 @@ public class HeightMap { this.bucketWidthX = 1; this.bucketWidthY = 1; - this.pixelColorValues = new int[this.fullExtentsX+1][this.fullExtentsY+1]; + this.pixelColorValues = new int[this.fullExtentsX + 1][this.fullExtentsY + 1]; for (int y = 0; y <= this.fullExtentsY; y++) { for (int x = 0; x <= this.fullExtentsX; x++) { @@ -197,95 +197,13 @@ public class HeightMap { HeightMap.PlayerCityHeightMap = new HeightMap(); } - + public static void GenerateCustomHeightMap(Zone zone) { HeightMap heightMap = new HeightMap(zone); - - HeightMap.heightmapByLoadNum.put(zone.getLoadNum(), heightMap); - - } - - public Vector2f getGridSquare(Vector2f zoneLoc) { - - if (zoneLoc.x < 0) - zoneLoc.setX(0); - if (zoneLoc.x > this.fullExtentsX - 1) - zoneLoc.setX((this.fullExtentsX - 1) + .9999999f); - - if (zoneLoc.y < 0) - zoneLoc.setY(0); - - if (zoneLoc.y > this.fullExtentsY - 1) - zoneLoc.setY((this.fullExtentsY - 1) + .9999999f); - - float xBucket = (zoneLoc.x / this.bucketWidthX); - float yBucket = (zoneLoc.y / this.bucketWidthY); - - return new Vector2f(xBucket, yBucket); - } - - public float getInterpolatedTerrainHeight(Vector2f zoneLoc) { - - Vector2f gridSquare; - - if (zoneLoc.x < 0 || zoneLoc.x > this.fullExtentsX) - return -1; - - if (zoneLoc.y < 0 || zoneLoc.y > this.fullExtentsY) - return -1; - - int maxX = (int) (this.fullExtentsX / this.bucketWidthX); - int maxY = (int) (this.fullExtentsY / this.bucketWidthY); - - //flip the Y so it grabs from the bottom left instead of top left. - //zoneLoc.setY(maxZoneHeight - zoneLoc.y); - - gridSquare = getGridSquare(zoneLoc); - - int gridX = (int) gridSquare.x; - int gridY = (int) (gridSquare.y); - - if (gridX > maxX) - gridX = maxX; - if (gridY > maxY) - gridY = maxY; - - float offsetX = (gridSquare.x - gridX); - float offsetY = gridSquare.y - gridY; - - //get height of the 4 vertices. - - float topLeftHeight = 0; - float topRightHeight = 0; - float bottomLeftHeight = 0; - float bottomRightHeight = 0; - - int nextY = gridY +1; - int nextX = gridX + 1; - - if (nextY > maxY) - nextY = gridY; - - if (nextX > maxX) - nextX = gridX; - - topLeftHeight = pixelColorValues[gridX][gridY]; - topRightHeight = pixelColorValues[nextX][gridY]; - bottomLeftHeight = pixelColorValues[gridX][nextY]; - bottomRightHeight = pixelColorValues[nextX][nextY]; - - float interpolatedHeight; - - interpolatedHeight = topRightHeight * (1 - offsetY) * (offsetX); - interpolatedHeight += (bottomRightHeight * offsetY * offsetX); - interpolatedHeight += (bottomLeftHeight * (1 - offsetX) * offsetY); - interpolatedHeight += (topLeftHeight * (1 - offsetX) * (1 - offsetY)); - - interpolatedHeight *= (float) this.maxHeight / 256; // Scale height + HeightMap.heightmapByLoadNum.put(zone.getLoadNum(), heightMap); - return interpolatedHeight; } public static Zone getNextZoneWithTerrain(Zone zone) { @@ -505,48 +423,6 @@ public class HeightMap { return realWorldAltitude; } - public float getInterpolatedTerrainHeight(Vector3fImmutable zoneLoc3f) { - - Vector2f zoneLoc = new Vector2f(zoneLoc3f.x, zoneLoc3f.z); - - Vector2f gridSquare; - - if (zoneLoc.x < 0 || zoneLoc.x > this.fullExtentsX) - return -1; - - if (zoneLoc.y < 0 || zoneLoc.y > this.fullExtentsY) - return -1; - - //flip the Y so it grabs from the bottom left instead of top left. - //zoneLoc.setY(maxZoneHeight - zoneLoc.y); - - gridSquare = getGridSquare(zoneLoc); - - int gridX = (int) gridSquare.x; - int gridY = (int) (gridSquare.y); - - float offsetX = (gridSquare.x - gridX); - float offsetY = gridSquare.y - gridY; - - //get height of the 4 vertices. - - float topLeftHeight = pixelColorValues[gridX][gridY]; - float topRightHeight = pixelColorValues[gridX + 1][gridY]; - float bottomLeftHeight = pixelColorValues[gridX][gridY + 1]; - float bottomRightHeight = pixelColorValues[gridX + 1][gridY + 1]; - - float interpolatedHeight; - - interpolatedHeight = topRightHeight * (1 - offsetY) * (offsetX); - interpolatedHeight += (bottomRightHeight * offsetY * offsetX); - interpolatedHeight += (bottomLeftHeight * (1 - offsetX) * offsetY); - interpolatedHeight += (topLeftHeight * (1 - offsetX) * (1 - offsetY)); - - interpolatedHeight *= (float) this.maxHeight / 256; // Scale height - - return interpolatedHeight; - } - public static float getOutsetHeight(float interpolatedAltitude, Zone zone, Vector3fImmutable worldLocation) { Vector2f parentLoc; @@ -620,24 +496,6 @@ public class HeightMap { return outsetALt; } - private void generatePixelData() { - - Color color; - - // Generate altitude lookup table for this heightmap - - this.pixelColorValues = new int[this.heightmapImage.getWidth()][this.heightmapImage.getHeight()]; - - for (int y = 0; y < this.heightmapImage.getHeight(); y++) { - for (int x = 0; x < this.heightmapImage.getWidth(); x++) { - - color = new Color(this.heightmapImage.getRGB(x, y)); - pixelColorValues[x][y] = color.getRed(); - } - } - - } - public static Vector2f getGridOffset(Vector2f gridSquare) { int floorX = (int) gridSquare.x; @@ -647,11 +505,6 @@ public class HeightMap { } - public float getScaledHeightForColor(float color) { - - return (color / 256) * this.maxHeight; - } - public static void loadAlHeightMaps() { // Load the heightmaps into staging hashmap keyed by HashMapID @@ -661,17 +514,175 @@ public class HeightMap { //generate static player city heightmap. HeightMap.GeneratePlayerCityHeightMap(); - - + + // Clear all heightmap image data as it's no longer needed. for (HeightMap heightMap : HeightMap.heightmapByLoadNum.values()) { heightMap.heightmapImage = null; } - + Logger.info(HeightMap.heightmapByLoadNum.size() + " Heightmaps cached."); } + public static boolean isLocUnderwater(Vector3fImmutable currentLoc) { + + float localAltitude = HeightMap.getWorldHeight(currentLoc); + Zone zone = ZoneManager.findSmallestZone(currentLoc); + + if (localAltitude < zone.getSeaLevel()) + return true; + + return false; + } + + public Vector2f getGridSquare(Vector2f zoneLoc) { + + if (zoneLoc.x < 0) + zoneLoc.setX(0); + + if (zoneLoc.x > this.fullExtentsX - 1) + zoneLoc.setX((this.fullExtentsX - 1) + .9999999f); + + if (zoneLoc.y < 0) + zoneLoc.setY(0); + + if (zoneLoc.y > this.fullExtentsY - 1) + zoneLoc.setY((this.fullExtentsY - 1) + .9999999f); + + float xBucket = (zoneLoc.x / this.bucketWidthX); + float yBucket = (zoneLoc.y / this.bucketWidthY); + + return new Vector2f(xBucket, yBucket); + } + + public float getInterpolatedTerrainHeight(Vector2f zoneLoc) { + + Vector2f gridSquare; + + if (zoneLoc.x < 0 || zoneLoc.x > this.fullExtentsX) + return -1; + + if (zoneLoc.y < 0 || zoneLoc.y > this.fullExtentsY) + return -1; + + int maxX = (int) (this.fullExtentsX / this.bucketWidthX); + int maxY = (int) (this.fullExtentsY / this.bucketWidthY); + + //flip the Y so it grabs from the bottom left instead of top left. + //zoneLoc.setY(maxZoneHeight - zoneLoc.y); + + gridSquare = getGridSquare(zoneLoc); + + int gridX = (int) gridSquare.x; + int gridY = (int) (gridSquare.y); + + if (gridX > maxX) + gridX = maxX; + if (gridY > maxY) + gridY = maxY; + + float offsetX = (gridSquare.x - gridX); + float offsetY = gridSquare.y - gridY; + + //get height of the 4 vertices. + + float topLeftHeight = 0; + float topRightHeight = 0; + float bottomLeftHeight = 0; + float bottomRightHeight = 0; + + int nextY = gridY + 1; + int nextX = gridX + 1; + + if (nextY > maxY) + nextY = gridY; + + if (nextX > maxX) + nextX = gridX; + + topLeftHeight = pixelColorValues[gridX][gridY]; + topRightHeight = pixelColorValues[nextX][gridY]; + bottomLeftHeight = pixelColorValues[gridX][nextY]; + bottomRightHeight = pixelColorValues[nextX][nextY]; + + float interpolatedHeight; + + interpolatedHeight = topRightHeight * (1 - offsetY) * (offsetX); + interpolatedHeight += (bottomRightHeight * offsetY * offsetX); + interpolatedHeight += (bottomLeftHeight * (1 - offsetX) * offsetY); + interpolatedHeight += (topLeftHeight * (1 - offsetX) * (1 - offsetY)); + + interpolatedHeight *= (float) this.maxHeight / 256; // Scale height + + return interpolatedHeight; + } + + public float getInterpolatedTerrainHeight(Vector3fImmutable zoneLoc3f) { + + Vector2f zoneLoc = new Vector2f(zoneLoc3f.x, zoneLoc3f.z); + + Vector2f gridSquare; + + if (zoneLoc.x < 0 || zoneLoc.x > this.fullExtentsX) + return -1; + + if (zoneLoc.y < 0 || zoneLoc.y > this.fullExtentsY) + return -1; + + //flip the Y so it grabs from the bottom left instead of top left. + //zoneLoc.setY(maxZoneHeight - zoneLoc.y); + + gridSquare = getGridSquare(zoneLoc); + + int gridX = (int) gridSquare.x; + int gridY = (int) (gridSquare.y); + + float offsetX = (gridSquare.x - gridX); + float offsetY = gridSquare.y - gridY; + + //get height of the 4 vertices. + + float topLeftHeight = pixelColorValues[gridX][gridY]; + float topRightHeight = pixelColorValues[gridX + 1][gridY]; + float bottomLeftHeight = pixelColorValues[gridX][gridY + 1]; + float bottomRightHeight = pixelColorValues[gridX + 1][gridY + 1]; + + float interpolatedHeight; + + interpolatedHeight = topRightHeight * (1 - offsetY) * (offsetX); + interpolatedHeight += (bottomRightHeight * offsetY * offsetX); + interpolatedHeight += (bottomLeftHeight * (1 - offsetX) * offsetY); + interpolatedHeight += (topLeftHeight * (1 - offsetX) * (1 - offsetY)); + + interpolatedHeight *= (float) this.maxHeight / 256; // Scale height + + return interpolatedHeight; + } + + private void generatePixelData() { + + Color color; + + // Generate altitude lookup table for this heightmap + + this.pixelColorValues = new int[this.heightmapImage.getWidth()][this.heightmapImage.getHeight()]; + + for (int y = 0; y < this.heightmapImage.getHeight(); y++) { + for (int x = 0; x < this.heightmapImage.getWidth(); x++) { + + color = new Color(this.heightmapImage.getRGB(x, y)); + pixelColorValues[x][y] = color.getRed(); + } + } + + } + + public float getScaledHeightForColor(float color) { + + return (color / 256) * this.maxHeight; + } + public float getBucketWidthX() { return bucketWidthX; } @@ -692,15 +703,4 @@ public class HeightMap { return seaLevel; } - public static boolean isLocUnderwater(Vector3fImmutable currentLoc) { - - float localAltitude = HeightMap.getWorldHeight(currentLoc); - Zone zone = ZoneManager.findSmallestZone(currentLoc); - - if (localAltitude < zone.getSeaLevel()) - return true; - - return false; - } - } diff --git a/src/engine/InterestManagement/InterestManager.java b/src/engine/InterestManagement/InterestManager.java index 24291887..e0252eff 100644 --- a/src/engine/InterestManagement/InterestManager.java +++ b/src/engine/InterestManagement/InterestManager.java @@ -38,14 +38,128 @@ public enum InterestManager implements Runnable { private static long lastTime; private static boolean keepGoing = true; - public void shutdown() { - this.keepGoing = false; - } - InterestManager() { Logger.info(" Interest Management thread is running."); } + public static void forceLoad(AbstractWorldObject awo) { + + AbstractNetMsg msg = null; + LoadStructureMsg lsm; + LoadCharacterMsg lcm; + NPC npc; + Corpse corpse; + HashSet toUpdate; + + switch (awo.getObjectType()) { + case Building: + lsm = new LoadStructureMsg(); + lsm.addObject((Building) awo); + msg = lsm; + break; + case Corpse: + corpse = (Corpse) awo; + lcm = new LoadCharacterMsg(corpse, false); + msg = lcm; + break; + case NPC: + npc = (NPC) awo; + lcm = new LoadCharacterMsg(npc, false); + msg = lcm; + break; + default: + return; + } + + toUpdate = WorldGrid.getObjectsInRangePartial(awo.getLoc(), MBServerStatics.CHARACTER_LOAD_RANGE, MBServerStatics.MASK_PLAYER); + + boolean send; + + for (AbstractWorldObject tar : toUpdate) { + PlayerCharacter player = (PlayerCharacter) tar; + HashSet loadedStaticObjects = player.getLoadedStaticObjects(); + send = false; + + if (!loadedStaticObjects.contains(awo)) { + loadedStaticObjects.add(awo); + send = true; + } + + if (send) { + + Dispatch dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + } + } + } + + public static void HandleSpecialUnload(Building building, ClientConnection origin) { + + if (Regions.FurnitureRegionMap.get(building.getObjectUUID()) == null) + return; + + Regions buildingRegion = Regions.FurnitureRegionMap.get(building.getObjectUUID()); + + if (!buildingRegion.isOutside()) + return; + + MoveToPointMsg moveMsg = new MoveToPointMsg(building); + + if (origin != null) + origin.sendMsg(moveMsg); + } + + public static void reloadCharacter(AbstractCharacter absChar) { + + UnloadObjectsMsg uom = new UnloadObjectsMsg(); + uom.addObject(absChar); + LoadCharacterMsg lcm = new LoadCharacterMsg(absChar, false); + + HashSet toSend = WorldGrid.getObjectsInRangePartial(absChar.getLoc(), MBServerStatics.CHARACTER_LOAD_RANGE, + MBServerStatics.MASK_PLAYER); + + PlayerCharacter pc = null; + + if (absChar.getObjectType().equals(GameObjectType.PlayerCharacter)) + pc = (PlayerCharacter) absChar; + + for (AbstractWorldObject awo : toSend) { + + PlayerCharacter pcc = (PlayerCharacter) awo; + + if (pcc == null) + continue; + + ClientConnection cc = SessionManager.getClientConnection(pcc); + + if (cc == null) + continue; + + if (pcc.getObjectUUID() == absChar.getObjectUUID()) + continue; + + else { + if (pc != null) + if (pcc.getSeeInvis() < pc.getHidden()) + continue; + + if (!cc.sendMsg(uom)) { + String classType = uom.getClass().getSimpleName(); + Logger.error("Failed to send message "); + } + + if (!cc.sendMsg(lcm)) { + String classType = lcm.getClass().getSimpleName(); + Logger.error("Failed to send message"); + } + } + } + } + + public void shutdown() { + this.keepGoing = false; + } + @Override public void run() { beginLoadJob(); @@ -84,6 +198,9 @@ public enum InterestManager implements Runnable { return dur; } + // Forces the loading of static objects (corpses and buildings). + // Needed to override threshold limits on loading statics + private void updateAllPlayers() { // get all players @@ -341,7 +458,7 @@ public enum InterestManager implements Runnable { awonpc.playerAgroMap.put(player.getObjectUUID(), false); //MobileFSM.setAwake(awonpc, false); - ((Mob)awonpc).setCombatTarget(null); + ((Mob) awonpc).setCombatTarget(null); // IVarController.setVariable(awonpc, "IntelligenceDisableDelay", (double) (System.currentTimeMillis() + 5000)); // awonpc.enableIntelligence(); lcm = new LoadCharacterMsg(awonpc, PlayerCharacter.hideNonAscii()); @@ -358,7 +475,7 @@ public enum InterestManager implements Runnable { if (awonpc.isMob()) //MobileFSM.setAwake(awonpc, false); - ((Mob)awonpc).setCombatTarget(null); + ((Mob) awonpc).setCombatTarget(null); // IVarController.setVariable(awonpc, "IntelligenceDisableDelay", (double) (System.currentTimeMillis() + 5000)); // awonpc.enableIntelligence(); lcm = new LoadCharacterMsg(awonpc, PlayerCharacter.hideNonAscii()); @@ -385,76 +502,6 @@ public enum InterestManager implements Runnable { //JobScheduler.getInstance().scheduleJob(new LoadEffectsJob(players, origin), MBServerStatics.LOAD_OBJECT_DELAY); } - // Forces the loading of static objects (corpses and buildings). - // Needed to override threshold limits on loading statics - - public static void forceLoad(AbstractWorldObject awo) { - - AbstractNetMsg msg = null; - LoadStructureMsg lsm; - LoadCharacterMsg lcm; - NPC npc; - Corpse corpse; - HashSet toUpdate; - - switch (awo.getObjectType()) { - case Building: - lsm = new LoadStructureMsg(); - lsm.addObject((Building) awo); - msg = lsm; - break; - case Corpse: - corpse = (Corpse) awo; - lcm = new LoadCharacterMsg(corpse, false); - msg = lcm; - break; - case NPC: - npc = (NPC) awo; - lcm = new LoadCharacterMsg(npc, false); - msg = lcm; - break; - default: - return; - } - - toUpdate = WorldGrid.getObjectsInRangePartial(awo.getLoc(), MBServerStatics.CHARACTER_LOAD_RANGE, MBServerStatics.MASK_PLAYER); - - boolean send; - - for (AbstractWorldObject tar : toUpdate) { - PlayerCharacter player = (PlayerCharacter) tar; - HashSet loadedStaticObjects = player.getLoadedStaticObjects(); - send = false; - - if (!loadedStaticObjects.contains(awo)) { - loadedStaticObjects.add(awo); - send = true; - } - - if (send) { - - Dispatch dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - } - } - } - - public static void HandleSpecialUnload(Building building, ClientConnection origin) { - - if (Regions.FurnitureRegionMap.get(building.getObjectUUID()) == null) - return; - - Regions buildingRegion = Regions.FurnitureRegionMap.get(building.getObjectUUID()); - - if (!buildingRegion.isOutside()) - return; - - MoveToPointMsg moveMsg = new MoveToPointMsg(building); - - if (origin != null) - origin.sendMsg(moveMsg); - } - public synchronized void HandleLoadForEnterWorld(PlayerCharacter player) { if (player == null) @@ -504,51 +551,4 @@ public enum InterestManager implements Runnable { Logger.error("InterestManager.updateAllMobilePlayers: " + player.getObjectUUID(), e); } } - - public static void reloadCharacter(AbstractCharacter absChar) { - - UnloadObjectsMsg uom = new UnloadObjectsMsg(); - uom.addObject(absChar); - LoadCharacterMsg lcm = new LoadCharacterMsg(absChar, false); - - HashSet toSend = WorldGrid.getObjectsInRangePartial(absChar.getLoc(), MBServerStatics.CHARACTER_LOAD_RANGE, - MBServerStatics.MASK_PLAYER); - - PlayerCharacter pc = null; - - if (absChar.getObjectType().equals(GameObjectType.PlayerCharacter)) - pc = (PlayerCharacter) absChar; - - for (AbstractWorldObject awo : toSend) { - - PlayerCharacter pcc = (PlayerCharacter) awo; - - if (pcc == null) - continue; - - ClientConnection cc = SessionManager.getClientConnection(pcc); - - if (cc == null) - continue; - - if (pcc.getObjectUUID() == absChar.getObjectUUID()) - continue; - - else { - if (pc != null) - if (pcc.getSeeInvis() < pc.getHidden()) - continue; - - if (!cc.sendMsg(uom)) { - String classType = uom.getClass().getSimpleName(); - Logger.error("Failed to send message "); - } - - if (!cc.sendMsg(lcm)) { - String classType = lcm.getClass().getSimpleName(); - Logger.error("Failed to send message"); - } - } - } - } } \ No newline at end of file diff --git a/src/engine/InterestManagement/RealmMap.java b/src/engine/InterestManagement/RealmMap.java index 9bb8de96..4c08f6bf 100644 --- a/src/engine/InterestManagement/RealmMap.java +++ b/src/engine/InterestManagement/RealmMap.java @@ -36,8 +36,8 @@ public enum RealmMap { // Spatial hashmap. Used for determining which Realm // a player is currently located within. - public static int[][] _realmImageMap; private static final HashMap _rgbToIDMap = new HashMap<>(); + public static int[][] _realmImageMap; public static int getRealmIDByColor(Color color) { diff --git a/src/engine/InterestManagement/WorldGrid.java b/src/engine/InterestManagement/WorldGrid.java index af932325..2eb71a40 100644 --- a/src/engine/InterestManagement/WorldGrid.java +++ b/src/engine/InterestManagement/WorldGrid.java @@ -25,177 +25,177 @@ import java.util.concurrent.ConcurrentHashMap; public class WorldGrid { - - public static ConcurrentHashMap[][] DynamicGridMap; - public static ConcurrentHashMap[][] StaticGridMap; - private static float dynamicBucketScale = 0.00390625f; // 256 bucket size, 1/256 - private static float staticBucketScale = 0.00390625f; - public static void startLoadJob() { - - Thread loadJobThread; - - - loadJobThread = new Thread(InterestManager.INTERESTMANAGER); - loadJobThread.setName("InterestManager"); - loadJobThread.start(); - } - - public static boolean moveWorldObject(AbstractWorldObject awo, Vector3fImmutable location) { - awo.setLoc(location); - return true; - } - - public static HashSet getInRange(Vector3f loc, double r) { - HashSet outbound = new HashSet<>(); - return outbound; - } - - public static HashSet getObjectsInRangePartial(Vector3fImmutable loc, double r, int mask) { - HashSet outbound = new HashSet<>(); - float scale; - - if ((mask & MBServerStatics.MASK_STATIC) != 0) - scale = WorldGrid.staticBucketScale; - else - scale = WorldGrid.dynamicBucketScale; - int gridX = (int) Math.abs(loc.x * scale); - int gridZ = (int)Math.abs(loc.z * scale); - int bucketSize = (int) (r *scale) + 1; - //start at top left most corner to scan. - int startingX = gridX - bucketSize; - int startingZ = gridZ + bucketSize; - - - - int limitX = Math.abs((int) (MBServerStatics.MAX_WORLD_WIDTH *scale)); - int limitZ = Math.abs((int) (MBServerStatics.MAX_WORLD_HEIGHT *scale)); //LimitZ is negative, remember to flip sign. - - if (startingX < 0) - startingX = 0; - - if (startingZ < 0) - startingZ = 0; - - if (startingX > limitX) - startingX = limitX; - - if (startingZ > limitZ) - startingZ = limitZ; - - int endX = startingX + (bucketSize * 2); - int endZ = startingZ - (bucketSize * 2); - - if (endX < 0) - endX = 0; - - if (endZ < 0) - endZ = 0; - - if (endX > limitX) - endX = limitX; - - if (endZ > limitZ) - endZ = limitZ; - - int auditMob = 0; - for (int x = startingX;x<=endX;x++){ - for (int z = startingZ;z >= endZ;z--){ - - ConcurrentHashMap gridMap; - - if ((MBServerStatics.MASK_STATIC & mask) != 0) - gridMap = WorldGrid.StaticGridMap[x][z]; - else - gridMap = WorldGrid.DynamicGridMap[x][z]; - for (AbstractWorldObject gridObject: gridMap.values()){ - if ((gridObject.getObjectTypeMask() & mask) == 0) - continue; - if (gridObject.getLoc().distanceSquared2D(loc) <= FastMath.sqr(r)) - outbound.add(gridObject); - } - } - } - return outbound; - } - - public static HashSet getObjectsInRangePartialNecroPets(Vector3fImmutable loc, double r) { - HashSet outbound = new HashSet<>(); - return outbound; - } - - public static HashSet getObjectsInRangeContains(Vector3fImmutable loc, double r, int mask) { - HashSet outbound = getObjectsInRangePartial(loc,r,mask); - return outbound; - } - - public static HashSet getObjectsInRangePartial(AbstractWorldObject awo, double range, int mask) { - return getObjectsInRangePartial(awo.getLoc(), range, mask); - } - - - public static void InitializeGridObjects(){ - - int dynamicWidth = (int) Math.abs(MBServerStatics.MAX_WORLD_WIDTH *WorldGrid.dynamicBucketScale); - int dynamicHeight = (int) Math.abs(MBServerStatics.MAX_WORLD_HEIGHT*WorldGrid.dynamicBucketScale); - - int staticWidth = (int) Math.abs(MBServerStatics.MAX_WORLD_WIDTH *WorldGrid.staticBucketScale); - int staticHeight = (int) Math.abs(MBServerStatics.MAX_WORLD_HEIGHT*WorldGrid.staticBucketScale); - WorldGrid.DynamicGridMap = new ConcurrentHashMap[dynamicWidth+ 1][dynamicHeight + 1]; - WorldGrid.StaticGridMap = new ConcurrentHashMap[staticWidth + 1][staticHeight + 1]; - //create new hash maps for each bucket - for (int x = 0; x<= staticWidth; x++) - for (int y = 0; y<= staticHeight; y++){ - WorldGrid.StaticGridMap[x][y] = new ConcurrentHashMap(); - } - - for (int x = 0; x<= dynamicWidth; x++) - for (int y = 0; y<= dynamicHeight; y++){ - WorldGrid.DynamicGridMap[x][y] = new ConcurrentHashMap(); - } - - } - - public static void RemoveWorldObject(AbstractWorldObject gridObject){ - - if (gridObject == null) - return; - AbstractWorldObject.RemoveFromWorldGrid(gridObject); - } - - public static boolean addObject(AbstractWorldObject gridObject, float x, float z){ - - if (gridObject == null) - return false; - - if (x > MBServerStatics.MAX_WORLD_WIDTH) - return false; - - if (z < MBServerStatics.MAX_WORLD_HEIGHT) - return false; - - if (x < 0) - return false; - if (z > 0) - return false; - - int gridX; - int gridZ; - - if (gridObject.getGridObjectType().equals(GridObjectType.STATIC)){ - gridX = Math.abs((int) (x *WorldGrid.staticBucketScale)); - gridZ = Math.abs((int) (z*WorldGrid.staticBucketScale)); - }else{ - gridX = Math.abs((int) (x *WorldGrid.dynamicBucketScale)); - gridZ = Math.abs((int) (z*WorldGrid.dynamicBucketScale)); - } - - - WorldGrid.RemoveWorldObject(gridObject); - - return AbstractWorldObject.AddToWorldGrid(gridObject, gridX, gridZ); - - - } + + public static ConcurrentHashMap[][] DynamicGridMap; + public static ConcurrentHashMap[][] StaticGridMap; + private static float dynamicBucketScale = 0.00390625f; // 256 bucket size, 1/256 + private static float staticBucketScale = 0.00390625f; + + public static void startLoadJob() { + + Thread loadJobThread; + + + loadJobThread = new Thread(InterestManager.INTERESTMANAGER); + loadJobThread.setName("InterestManager"); + loadJobThread.start(); + } + + public static boolean moveWorldObject(AbstractWorldObject awo, Vector3fImmutable location) { + awo.setLoc(location); + return true; + } + + public static HashSet getInRange(Vector3f loc, double r) { + HashSet outbound = new HashSet<>(); + return outbound; + } + + public static HashSet getObjectsInRangePartial(Vector3fImmutable loc, double r, int mask) { + HashSet outbound = new HashSet<>(); + float scale; + + if ((mask & MBServerStatics.MASK_STATIC) != 0) + scale = WorldGrid.staticBucketScale; + else + scale = WorldGrid.dynamicBucketScale; + int gridX = (int) Math.abs(loc.x * scale); + int gridZ = (int) Math.abs(loc.z * scale); + int bucketSize = (int) (r * scale) + 1; + //start at top left most corner to scan. + int startingX = gridX - bucketSize; + int startingZ = gridZ + bucketSize; + + + int limitX = Math.abs((int) (MBServerStatics.MAX_WORLD_WIDTH * scale)); + int limitZ = Math.abs((int) (MBServerStatics.MAX_WORLD_HEIGHT * scale)); //LimitZ is negative, remember to flip sign. + + if (startingX < 0) + startingX = 0; + + if (startingZ < 0) + startingZ = 0; + + if (startingX > limitX) + startingX = limitX; + + if (startingZ > limitZ) + startingZ = limitZ; + + int endX = startingX + (bucketSize * 2); + int endZ = startingZ - (bucketSize * 2); + + if (endX < 0) + endX = 0; + + if (endZ < 0) + endZ = 0; + + if (endX > limitX) + endX = limitX; + + if (endZ > limitZ) + endZ = limitZ; + + int auditMob = 0; + for (int x = startingX; x <= endX; x++) { + for (int z = startingZ; z >= endZ; z--) { + + ConcurrentHashMap gridMap; + + if ((MBServerStatics.MASK_STATIC & mask) != 0) + gridMap = WorldGrid.StaticGridMap[x][z]; + else + gridMap = WorldGrid.DynamicGridMap[x][z]; + for (AbstractWorldObject gridObject : gridMap.values()) { + if ((gridObject.getObjectTypeMask() & mask) == 0) + continue; + if (gridObject.getLoc().distanceSquared2D(loc) <= FastMath.sqr(r)) + outbound.add(gridObject); + } + } + } + return outbound; + } + + public static HashSet getObjectsInRangePartialNecroPets(Vector3fImmutable loc, double r) { + HashSet outbound = new HashSet<>(); + return outbound; + } + + public static HashSet getObjectsInRangeContains(Vector3fImmutable loc, double r, int mask) { + HashSet outbound = getObjectsInRangePartial(loc, r, mask); + return outbound; + } + + public static HashSet getObjectsInRangePartial(AbstractWorldObject awo, double range, int mask) { + return getObjectsInRangePartial(awo.getLoc(), range, mask); + } + + + public static void InitializeGridObjects() { + + int dynamicWidth = (int) Math.abs(MBServerStatics.MAX_WORLD_WIDTH * WorldGrid.dynamicBucketScale); + int dynamicHeight = (int) Math.abs(MBServerStatics.MAX_WORLD_HEIGHT * WorldGrid.dynamicBucketScale); + + int staticWidth = (int) Math.abs(MBServerStatics.MAX_WORLD_WIDTH * WorldGrid.staticBucketScale); + int staticHeight = (int) Math.abs(MBServerStatics.MAX_WORLD_HEIGHT * WorldGrid.staticBucketScale); + WorldGrid.DynamicGridMap = new ConcurrentHashMap[dynamicWidth + 1][dynamicHeight + 1]; + WorldGrid.StaticGridMap = new ConcurrentHashMap[staticWidth + 1][staticHeight + 1]; + //create new hash maps for each bucket + for (int x = 0; x <= staticWidth; x++) + for (int y = 0; y <= staticHeight; y++) { + WorldGrid.StaticGridMap[x][y] = new ConcurrentHashMap(); + } + + for (int x = 0; x <= dynamicWidth; x++) + for (int y = 0; y <= dynamicHeight; y++) { + WorldGrid.DynamicGridMap[x][y] = new ConcurrentHashMap(); + } + + } + + public static void RemoveWorldObject(AbstractWorldObject gridObject) { + + if (gridObject == null) + return; + AbstractWorldObject.RemoveFromWorldGrid(gridObject); + } + + public static boolean addObject(AbstractWorldObject gridObject, float x, float z) { + + if (gridObject == null) + return false; + + if (x > MBServerStatics.MAX_WORLD_WIDTH) + return false; + + if (z < MBServerStatics.MAX_WORLD_HEIGHT) + return false; + + if (x < 0) + return false; + if (z > 0) + return false; + + int gridX; + int gridZ; + + if (gridObject.getGridObjectType().equals(GridObjectType.STATIC)) { + gridX = Math.abs((int) (x * WorldGrid.staticBucketScale)); + gridZ = Math.abs((int) (z * WorldGrid.staticBucketScale)); + } else { + gridX = Math.abs((int) (x * WorldGrid.dynamicBucketScale)); + gridZ = Math.abs((int) (z * WorldGrid.dynamicBucketScale)); + } + + + WorldGrid.RemoveWorldObject(gridObject); + + return AbstractWorldObject.AddToWorldGrid(gridObject, gridX, gridZ); + + + } public static void unloadObject(AbstractWorldObject awo) { @@ -204,109 +204,109 @@ public class WorldGrid { DispatchMessage.sendToAllInRange(awo, uom); } - public static void loadObject(AbstractWorldObject awo) { - - LoadStructureMsg lsm; - LoadCharacterMsg lcm; - - switch (awo.getObjectType()) { - case Building: - lsm = new LoadStructureMsg(); - lsm.addObject((Building)awo); - DispatchMessage.sendToAllInRange(awo, lsm); - break; - case NPC: - lcm = new LoadCharacterMsg((NPC) awo, false); - DispatchMessage.sendToAllInRange(awo, lcm); - break; - case Mob: - lcm = new LoadCharacterMsg((Mob) awo, false); - DispatchMessage.sendToAllInRange(awo, lcm); - break; - default: - // *** Refactor: Log error? - break; - } - } - - public static void loadObject(AbstractWorldObject awo, ClientConnection origin) { - - LoadStructureMsg lsm; - LoadCharacterMsg lcm; - - switch (awo.getObjectType()) { - - case Building: - lsm = new LoadStructureMsg(); - lsm.addObject((Building)awo); - DispatchMessage.sendToAllInRange(awo, lsm); - break; - case NPC: - lcm = new LoadCharacterMsg((NPC) awo, false); - DispatchMessage.sendToAllInRange(awo, lcm); - break; - case Mob: - lcm = new LoadCharacterMsg((Mob) awo, false); - DispatchMessage.sendToAllInRange(awo, lcm); - break; - case PlayerCharacter: - lcm = new LoadCharacterMsg((PlayerCharacter) awo, false); - DispatchMessage.sendToAllInRange(awo, lcm); - break; - default: - // *** Refactor: Log error? - break; - } - } - - public static void unloadObject(AbstractWorldObject awo, - ClientConnection origin) { - UnloadObjectsMsg uom = new UnloadObjectsMsg(); - uom.addObject(awo); - DispatchMessage.sendToAllInRange(awo, uom); - } - - public static void addObject(AbstractWorldObject awo, PlayerCharacter pc) { - if (pc == null || awo == null) - return; - ClientConnection origin = pc.getClientConnection(); - if (origin == null) - return; - loadObject(awo, origin); - } - - public static void removeObject(AbstractWorldObject awo, PlayerCharacter pc) { - if (pc == null || awo == null) - return; - ClientConnection origin = pc.getClientConnection(); - if (origin == null) - return; - unloadObject(awo, origin); - } - - public static void updateObject(AbstractWorldObject awo, PlayerCharacter pc) { - if (pc == null || awo == null) - return; - ClientConnection origin = pc.getClientConnection(); - if (origin == null) - return; - unloadObject(awo, origin); - loadObject(awo, origin); - } - - public static void updateObject(AbstractWorldObject awo) { - if (awo == null) - return; - unloadObject(awo); - loadObject(awo); - } - - /* - * - */ - public static void removeObject(AbstractWorldObject awo) { - if (awo == null) - return; - unloadObject(awo); - } + public static void loadObject(AbstractWorldObject awo) { + + LoadStructureMsg lsm; + LoadCharacterMsg lcm; + + switch (awo.getObjectType()) { + case Building: + lsm = new LoadStructureMsg(); + lsm.addObject((Building) awo); + DispatchMessage.sendToAllInRange(awo, lsm); + break; + case NPC: + lcm = new LoadCharacterMsg((NPC) awo, false); + DispatchMessage.sendToAllInRange(awo, lcm); + break; + case Mob: + lcm = new LoadCharacterMsg((Mob) awo, false); + DispatchMessage.sendToAllInRange(awo, lcm); + break; + default: + // *** Refactor: Log error? + break; + } + } + + public static void loadObject(AbstractWorldObject awo, ClientConnection origin) { + + LoadStructureMsg lsm; + LoadCharacterMsg lcm; + + switch (awo.getObjectType()) { + + case Building: + lsm = new LoadStructureMsg(); + lsm.addObject((Building) awo); + DispatchMessage.sendToAllInRange(awo, lsm); + break; + case NPC: + lcm = new LoadCharacterMsg((NPC) awo, false); + DispatchMessage.sendToAllInRange(awo, lcm); + break; + case Mob: + lcm = new LoadCharacterMsg((Mob) awo, false); + DispatchMessage.sendToAllInRange(awo, lcm); + break; + case PlayerCharacter: + lcm = new LoadCharacterMsg((PlayerCharacter) awo, false); + DispatchMessage.sendToAllInRange(awo, lcm); + break; + default: + // *** Refactor: Log error? + break; + } + } + + public static void unloadObject(AbstractWorldObject awo, + ClientConnection origin) { + UnloadObjectsMsg uom = new UnloadObjectsMsg(); + uom.addObject(awo); + DispatchMessage.sendToAllInRange(awo, uom); + } + + public static void addObject(AbstractWorldObject awo, PlayerCharacter pc) { + if (pc == null || awo == null) + return; + ClientConnection origin = pc.getClientConnection(); + if (origin == null) + return; + loadObject(awo, origin); + } + + public static void removeObject(AbstractWorldObject awo, PlayerCharacter pc) { + if (pc == null || awo == null) + return; + ClientConnection origin = pc.getClientConnection(); + if (origin == null) + return; + unloadObject(awo, origin); + } + + public static void updateObject(AbstractWorldObject awo, PlayerCharacter pc) { + if (pc == null || awo == null) + return; + ClientConnection origin = pc.getClientConnection(); + if (origin == null) + return; + unloadObject(awo, origin); + loadObject(awo, origin); + } + + public static void updateObject(AbstractWorldObject awo) { + if (awo == null) + return; + unloadObject(awo); + loadObject(awo); + } + + /* + * + */ + public static void removeObject(AbstractWorldObject awo) { + if (awo == null) + return; + unloadObject(awo); + } } diff --git a/src/engine/ai/MobileFSM.java b/src/engine/ai/MobileFSM.java index 34a357ee..7e10ea4d 100644 --- a/src/engine/ai/MobileFSM.java +++ b/src/engine/ai/MobileFSM.java @@ -6,6 +6,7 @@ // Magicbane Emulator Project © 2013 - 2022 // www.magicbane.com package engine.ai; + import engine.Enum; import engine.Enum.DispatchChannel; import engine.InterestManagement.WorldGrid; @@ -22,12 +23,15 @@ import engine.objects.*; import engine.powers.ActionsBase; import engine.powers.PowersBase; import engine.server.MBServerStatics; + import java.util.ArrayList; import java.util.HashSet; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadLocalRandom; + import static engine.math.FastMath.sqr; + public class MobileFSM { private static void AttackTarget(Mob mob, AbstractWorldObject target) { if (mob == null) @@ -36,8 +40,8 @@ public class MobileFSM { mob.setCombatTarget(null); return; } - if(target.getObjectType() == Enum.GameObjectType.PlayerCharacter && canCast(mob)){ - if(MobCast(mob)){ + if (target.getObjectType() == Enum.GameObjectType.PlayerCharacter && canCast(mob)) { + if (MobCast(mob)) { return; } } @@ -58,8 +62,9 @@ public class MobileFSM { break; } } + public static void AttackPlayer(Mob mob, PlayerCharacter target) { - if(!mob.canSee(target)){ + if (!mob.canSee(target)) { mob.setCombatTarget(null); return; } @@ -100,6 +105,7 @@ public class MobileFSM { } } } + public static void AttackBuilding(Mob mob, Building target) { if (target.getRank() == -1 || !target.isVulnerable() || BuildingManager.getBuildingFromCache(target.getObjectUUID()) == null) { mob.setCombatTarget(null); @@ -140,6 +146,7 @@ public class MobileFSM { DispatchMessage.dispatchMsgToInterestArea(mob, ppm, DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); } } + public static void AttackMob(Mob mob, Mob target) { if (mob.getRange() >= 30 && mob.isMoving()) return; @@ -166,6 +173,7 @@ public class MobileFSM { mob.setLastAttackTime(System.currentTimeMillis() + attackDelay); } } + private static void Patrol(Mob mob) { //make sure mob is out of combat stance if (mob.isCombat() && mob.getCombatTarget() == null) { @@ -174,7 +182,7 @@ public class MobileFSM { rwss.setPlayer(mob); DispatchMessage.sendToAllInRange(mob, rwss); } - int patrolDelay = ThreadLocalRandom.current().nextInt((int)(MobileFSMManager.AI_PATROL_DIVISOR * 0.5f), MobileFSMManager.AI_PATROL_DIVISOR) + MobileFSMManager.AI_PATROL_DIVISOR; + int patrolDelay = ThreadLocalRandom.current().nextInt((int) (MobileFSMManager.AI_PATROL_DIVISOR * 0.5f), MobileFSMManager.AI_PATROL_DIVISOR) + MobileFSMManager.AI_PATROL_DIVISOR; if (mob.stopPatrolTime + (patrolDelay * 1000) > System.currentTimeMillis()) //early exit while waiting to patrol again return; @@ -183,18 +191,18 @@ public class MobileFSM { Building barracks = mob.building; if (barracks != null && barracks.patrolPoints != null && !barracks.getPatrolPoints().isEmpty()) { mob.patrolPoints = barracks.patrolPoints; - } else{ + } else { randomGuardPatrolPoint(mob); return; } } - if (mob.lastPatrolPointIndex > mob.patrolPoints.size() - 1) { - mob.lastPatrolPointIndex = 0; - } + if (mob.lastPatrolPointIndex > mob.patrolPoints.size() - 1) { + mob.lastPatrolPointIndex = 0; + } mob.destination = mob.patrolPoints.get(mob.lastPatrolPointIndex); mob.lastPatrolPointIndex += 1; MovementUtilities.aiMove(mob, mob.destination, true); - if(mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal()){ + if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal()) { for (Entry minion : mob.siegeMinionMap.entrySet()) { //make sure mob is out of combat stance if (minion.getKey().despawned == false) { @@ -214,6 +222,7 @@ public class MobileFSM { } } } + public static boolean canCast(Mob mob) { // Performs validation to determine if a // mobile in the proper state to cast. @@ -221,7 +230,7 @@ public class MobileFSM { return false; if (mob.mobPowers.isEmpty()) return false; - if(!mob.canSee((PlayerCharacter) mob.getCombatTarget())){ + if (!mob.canSee((PlayerCharacter) mob.getCombatTarget())) { mob.setCombatTarget(null); return false; } @@ -229,6 +238,7 @@ public class MobileFSM { mob.nextCastTime = System.currentTimeMillis(); return mob.nextCastTime <= System.currentTimeMillis(); } + public static boolean MobCast(Mob mob) { // Method picks a random spell from a mobile's list of powers // and casts it on the current target (or itself). Validation @@ -261,7 +271,7 @@ public class MobileFSM { int powerRank = mob.mobPowers.get(powerToken); PowersBase mobPower = PowersManager.getPowerByToken(powerToken); //check for hit-roll - if(mobPower.requiresHitRoll) { + if (mobPower.requiresHitRoll) { if (CombatUtilities.triggerDefense(mob, mob.getCombatTarget())) { return false; } @@ -286,11 +296,12 @@ public class MobileFSM { msg.setUnknown04(2); PowersManager.finishUseMobPower(msg, mob, 0, 0); // Default minimum seconds between cast = 10 - mob.nextCastTime = System.currentTimeMillis() + mobPower.getCooldown() + (MobileFSMManager.AI_POWER_DIVISOR * 1000); + mob.nextCastTime = System.currentTimeMillis() + mobPower.getCooldown() + (MobileFSMManager.AI_POWER_DIVISOR * 1000); return true; } return false; } + public static void MobCallForHelp(Mob mob) { boolean callGotResponse = false; if (mob.nextCallForHelp == 0) { @@ -311,6 +322,7 @@ public class MobileFSM { //wait 60 seconds to call for help again mob.nextCallForHelp = System.currentTimeMillis() + 60000; } + public static void DetermineAction(Mob mob) { if (mob == null) return; @@ -321,10 +333,10 @@ public class MobileFSM { } if (mob.despawned && mob.isPlayerGuard) { //override for guards - if(mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardMinion.ordinal()){ - if(mob.npcOwner.isAlive() == false || ((Mob)mob.npcOwner).despawned == true){ + if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardMinion.ordinal()) { + if (mob.npcOwner.isAlive() == false || ((Mob) mob.npcOwner).despawned == true) { //minions don't respawn while guard captain is dead - if(mob.isAlive() == false) { + if (mob.isAlive() == false) { mob.deathTime = System.currentTimeMillis(); return; } @@ -351,7 +363,7 @@ public class MobileFSM { } mob.updateLocation(); CheckToSendMobHome(mob); - if(mob.combatTarget != null && mob.combatTarget.isAlive() == false){ + if (mob.combatTarget != null && mob.combatTarget.isAlive() == false) { mob.setCombatTarget(null); } switch (mob.BehaviourType) { @@ -375,6 +387,7 @@ public class MobileFSM { break; } } + private static void CheckForAggro(Mob aiAgent) { //looks for and sets mobs combatTarget if (!aiAgent.isAlive()) @@ -405,10 +418,11 @@ public class MobileFSM { } } } + private static void CheckMobMovement(Mob mob) { if (!MovementUtilities.canMove(mob)) return; - switch(mob.BehaviourType){ + switch (mob.BehaviourType) { case Pet1: if (!mob.playerAgroMap.containsKey(mob.getOwner().getObjectUUID())) { //mob no longer has its owner loaded, translocate pet to owner @@ -425,27 +439,28 @@ public class MobileFSM { chaseTarget(mob); break; case GuardMinion: - if (!mob.npcOwner.isAlive() || ((Mob)mob.npcOwner).despawned) + if (!mob.npcOwner.isAlive() || ((Mob) mob.npcOwner).despawned) randomGuardPatrolPoint(mob); - else{ - if(mob.getCombatTarget() != null){ + else { + if (mob.getCombatTarget() != null) { chaseTarget(mob); } } break; default: if (mob.getCombatTarget() == null) { - if(!mob.isMoving()) { + if (!mob.isMoving()) { Patrol(mob); - } else{ + } else { mob.stopPatrolTime = System.currentTimeMillis(); } - }else { + } else { chaseTarget(mob); } break; } } + private static void CheckForRespawn(Mob aiAgent) { if (aiAgent.deathTime == 0) { aiAgent.setDeathTime(System.currentTimeMillis()); @@ -479,14 +494,15 @@ public class MobileFSM { aiAgent.respawn(); } } + public static void CheckForAttack(Mob mob) { //checks if mob can attack based on attack timer and range if (mob.isAlive() == false) return; - if(mob.getCombatTarget() == null){ + if (mob.getCombatTarget() == null) { return; } - if (mob.getCombatTarget().getObjectType().equals(Enum.GameObjectType.PlayerCharacter) && MovementUtilities.inRangeDropAggro(mob, (PlayerCharacter)mob.getCombatTarget()) == false) { + if (mob.getCombatTarget().getObjectType().equals(Enum.GameObjectType.PlayerCharacter) && MovementUtilities.inRangeDropAggro(mob, (PlayerCharacter) mob.getCombatTarget()) == false) { mob.setCombatTarget(null); if (mob.isCombat()) { mob.setCombat(false); @@ -505,18 +521,18 @@ public class MobileFSM { if (System.currentTimeMillis() > mob.getLastAttackTime()) AttackTarget(mob, mob.getCombatTarget()); } + private static void CheckToSendMobHome(Mob mob) { - if(mob.BehaviourType.isAgressive) { - if(mob.isPlayerGuard()) - { - if(mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal()){ + if (mob.BehaviourType.isAgressive) { + if (mob.isPlayerGuard()) { + if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal()) { CheckForPlayerGuardAggro(mob); } } else { CheckForAggro(mob); } } - if(mob.getCombatTarget() != null && CombatUtilities.inRange2D(mob,mob.getCombatTarget(), MobileFSMManager.AI_BASE_AGGRO_RANGE * 0.5f)){ + if (mob.getCombatTarget() != null && CombatUtilities.inRange2D(mob, mob.getCombatTarget(), MobileFSMManager.AI_BASE_AGGRO_RANGE * 0.5f)) { return; } if (mob.isPlayerGuard() && !mob.despawned) { @@ -525,7 +541,7 @@ public class MobileFSM { PowersBase recall = PowersManager.getPowerByToken(-1994153779); PowersManager.useMobPower(mob, mob, recall, 40); mob.setCombatTarget(null); - if(mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal() && mob.isAlive()){ + if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal() && mob.isAlive()) { //guard captain pulls his minions home with him for (Entry minion : mob.siegeMinionMap.entrySet()) { PowersManager.useMobPower(minion.getKey(), minion.getKey(), recall, 40); @@ -533,20 +549,20 @@ public class MobileFSM { } } } - } - else if(MovementUtilities.inRangeOfBindLocation(mob) == false) { + } else if (MovementUtilities.inRangeOfBindLocation(mob) == false) { PowersBase recall = PowersManager.getPowerByToken(-1994153779); PowersManager.useMobPower(mob, mob, recall, 40); mob.setCombatTarget(null); for (Entry playerEntry : mob.playerAgroMap.entrySet()) { - PlayerCharacter.getFromCache((int)playerEntry.getKey()).setHateValue(0); + PlayerCharacter.getFromCache((int) playerEntry.getKey()).setHateValue(0); } } } + private static void chaseTarget(Mob mob) { mob.updateMovementState(); - if(mob.playerAgroMap.containsKey(mob.getCombatTarget().getObjectUUID()) == false){ + if (mob.playerAgroMap.containsKey(mob.getCombatTarget().getObjectUUID()) == false) { mob.setCombatTarget(null); return; } @@ -560,6 +576,7 @@ public class MobileFSM { } } } + private static void SafeGuardAggro(Mob mob) { HashSet awoList = WorldGrid.getObjectsInRangePartial(mob, 100, MBServerStatics.MASK_MOB); for (AbstractWorldObject awoMob : awoList) { @@ -575,49 +592,55 @@ public class MobileFSM { mob.setCombatTarget(aggroMob); } } + public static void GuardCaptainLogic(Mob mob) { if (mob.getCombatTarget() == null) CheckForPlayerGuardAggro(mob); CheckMobMovement(mob); CheckForAttack(mob); } + public static void GuardMinionLogic(Mob mob) { if (!mob.npcOwner.isAlive() && mob.getCombatTarget() == null) { CheckForPlayerGuardAggro(mob); } - if(mob.npcOwner.getCombatTarget() != null) + if (mob.npcOwner.getCombatTarget() != null) mob.setCombatTarget(mob.npcOwner.getCombatTarget()); - else + else mob.setCombatTarget(null); CheckMobMovement(mob); CheckForAttack(mob); } + public static void GuardWallArcherLogic(Mob mob) { if (mob.getCombatTarget() == null) CheckForPlayerGuardAggro(mob); else CheckForAttack(mob); } + private static void PetLogic(Mob mob) { if (mob.getCombatTarget() != null && !mob.getCombatTarget().isAlive()) mob.setCombatTarget(null); if (MovementUtilities.canMove(mob) && mob.BehaviourType.canRoam) CheckMobMovement(mob); - CheckForAttack(mob); + CheckForAttack(mob); } + private static void HamletGuardLogic(Mob mob) { if (mob.getCombatTarget() == null) { //safehold guard SafeGuardAggro(mob); - } else{ - if(mob.combatTarget.isAlive() == false){ + } else { + if (mob.combatTarget.isAlive() == false) { SafeGuardAggro(mob); } } - CheckForAttack(mob); + CheckForAttack(mob); } + private static void DefaultLogic(Mob mob) { - if(mob.getObjectUUID() == 40548){ + if (mob.getObjectUUID() == 40548) { int thing = 0; } //check for players that can be aggroed if mob is agressive and has no target @@ -643,6 +666,7 @@ public class MobileFSM { if (!mob.BehaviourType.isWimpy && !mob.isMoving() && mob.combatTarget != null) CheckForAttack(mob); } + public static void CheckForPlayerGuardAggro(Mob mob) { //looks for and sets mobs combatTarget if (!mob.isAlive()) @@ -673,14 +697,15 @@ public class MobileFSM { } } } + public static Boolean GuardCanAggro(Mob mob, PlayerCharacter target) { if (mob.getGuild().getNation().equals(target.getGuild().getNation())) return false; if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardMinion.ordinal()) { - if(((Mob)mob.npcOwner).building.getCity().cityOutlaws.contains(target.getObjectUUID()) == true){ + if (((Mob) mob.npcOwner).building.getCity().cityOutlaws.contains(target.getObjectUUID()) == true) { return true; } - } else if(mob.building.getCity().cityOutlaws.contains(target.getObjectUUID()) == true){ + } else if (mob.building.getCity().cityOutlaws.contains(target.getObjectUUID()) == true) { return true; } //first check condemn list for aggro allowed (allies button is checked) @@ -697,7 +722,7 @@ public class MobileFSM { return false; } return true; - } else{ + } else { //allies button is not checked for (Entry entry : ZoneManager.getCityAtLocation(mob.getLoc()).getTOL().getCondemned().entrySet()) { if (entry.getValue().getPlayerUID() == target.getObjectUUID() && entry.getValue().isActive()) @@ -713,7 +738,8 @@ public class MobileFSM { } return false; } - public static void randomGuardPatrolPoint(Mob mob){ + + public static void randomGuardPatrolPoint(Mob mob) { if (mob.isMoving() == true) { //early exit for a mob who is already moving to a patrol point //while mob moving, update lastPatrolTime so that when they stop moving the 10 second timer can begin @@ -728,9 +754,9 @@ public class MobileFSM { float xPoint = ThreadLocalRandom.current().nextInt(400) - 200; float zPoint = ThreadLocalRandom.current().nextInt(400) - 200; Vector3fImmutable TreePos = mob.getGuild().getOwnedCity().getLoc(); - mob.destination = new Vector3fImmutable(TreePos.x + xPoint,TreePos.y,TreePos.z + zPoint); + mob.destination = new Vector3fImmutable(TreePos.x + xPoint, TreePos.y, TreePos.z + zPoint); MovementUtilities.aiMove(mob, mob.destination, true); - if(mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal()){ + if (mob.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardCaptain.ordinal()) { for (Entry minion : mob.siegeMinionMap.entrySet()) { //make sure mob is out of combat stance if (minion.getKey().despawned == false) { @@ -750,18 +776,19 @@ public class MobileFSM { } } } - public static AbstractWorldObject ChangeTargetFromHateValue(Mob mob){ + + public static AbstractWorldObject ChangeTargetFromHateValue(Mob mob) { float CurrentHateValue = 0; - if(mob.getCombatTarget() != null && mob.getCombatTarget().getObjectType().equals(Enum.GameObjectType.PlayerCharacter)){ - CurrentHateValue = ((PlayerCharacter)mob.getCombatTarget()).getHateValue(); + if (mob.getCombatTarget() != null && mob.getCombatTarget().getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { + CurrentHateValue = ((PlayerCharacter) mob.getCombatTarget()).getHateValue(); } AbstractWorldObject mostHatedTarget = null; for (Entry playerEntry : mob.playerAgroMap.entrySet()) { - PlayerCharacter potentialTarget = PlayerCharacter.getFromCache((int)playerEntry.getKey()); - if(potentialTarget.equals(mob.getCombatTarget())){ + PlayerCharacter potentialTarget = PlayerCharacter.getFromCache((int) playerEntry.getKey()); + if (potentialTarget.equals(mob.getCombatTarget())) { continue; } - if(potentialTarget != null && potentialTarget.getHateValue() > CurrentHateValue && MovementUtilities.inRangeToAggro(mob, potentialTarget)){ + if (potentialTarget != null && potentialTarget.getHateValue() > CurrentHateValue && MovementUtilities.inRangeToAggro(mob, potentialTarget)) { CurrentHateValue = potentialTarget.getHateValue(); mostHatedTarget = potentialTarget; } diff --git a/src/engine/ai/MobileFSMManager.java b/src/engine/ai/MobileFSMManager.java index f99308b3..4733567e 100644 --- a/src/engine/ai/MobileFSMManager.java +++ b/src/engine/ai/MobileFSMManager.java @@ -25,9 +25,6 @@ public class MobileFSMManager { private static final MobileFSMManager INSTANCE = new MobileFSMManager(); public static Duration executionTime = Duration.ofNanos(1); public static Duration executionMax = Duration.ofNanos(1); - private volatile boolean alive; - private long timeOfKill = -1; - //AI variables moved form mb_server_statics public static int AI_BASE_AGGRO_RANGE = 60; public static int AI_DROP_AGGRO_RANGE = 60; @@ -36,7 +33,9 @@ public class MobileFSMManager { public static int AI_THREAD_SLEEP = 1000; public static int AI_PATROL_DIVISOR = 15; public static int AI_POWER_DIVISOR = 20; - public static float AI_MAX_ANGLE = 10f; + public static float AI_MAX_ANGLE = 10f; + private volatile boolean alive; + private long timeOfKill = -1; private MobileFSMManager() { diff --git a/src/engine/ai/utilities/CombatUtilities.java b/src/engine/ai/utilities/CombatUtilities.java index a5d3bd9e..abc35db2 100644 --- a/src/engine/ai/utilities/CombatUtilities.java +++ b/src/engine/ai/utilities/CombatUtilities.java @@ -405,7 +405,7 @@ public class CombatUtilities { float dmgMultiplier = 1 + agent.getBonuses().getFloatPercentAll(ModType.MeleeDamageModifier, SourceType.None); double min = agent.getMinDamageHandOne(); double max = agent.getMaxDamageHandOne(); - if(agent.getEquip().get(1) != null) { + if (agent.getEquip().get(1) != null) { if (agent.getEquip().get(1).getItemBase() != null) { dt = agent.getEquip().get(1).getItemBase().getDamageType(); min = agent.getMinDamageHandOne(); diff --git a/src/engine/core/ControlledRunnable.java b/src/engine/core/ControlledRunnable.java index d9d8bf4a..0dde32ed 100644 --- a/src/engine/core/ControlledRunnable.java +++ b/src/engine/core/ControlledRunnable.java @@ -14,161 +14,160 @@ import org.pmw.tinylog.Logger; import java.util.ArrayList; /** - * + * */ public abstract class ControlledRunnable implements Runnable { - protected boolean runCmd = false; - protected boolean runStatus = false; - private Thread thisThread; - private final String threadName; - - public ControlledRunnable(String threadName) { - super(); - this.threadName = threadName; - ControlledRunnable.runnables.add(this); - } - - /* - * Main loop - */ - - /** - * This is the method called when ControlledRunnable.thisThread.start() is - * called. - */ - @Override - public void run() { - if (this._preRun() == false) { - return; - } - - this.runStatus = true; - - if (this._Run() == false) { - return; - } - - if (this._postRun() == false) { - return; - } - - this.runStatus = false; - } - - /** - * _preRun() is called prior to the call to _Run(), but after _startup() - * - * @return - */ - protected abstract boolean _preRun(); - - /** - * _Run() is called after _startup() and contains should contain the main - * loop. - * - * @return - */ - protected abstract boolean _Run(); - - /** - * _postRun() is called after _Run() exits, not necessarily before - * _shutdown() - * - * @return - */ - protected abstract boolean _postRun(); - - /* - * Control - */ - - /** - * startup() initializes the internal thread, sets the runCMD to true, and - * calls _startup() prior to starting of the internal Thread. - */ - public void startup() { - - this.thisThread = new Thread(this, this.threadName); - this.runCmd = true; - this._startup(); - this.thisThread.start(); - } - - /** - * This method is called just before ControlledRunnable.thisThread.start() - * is called. - */ - protected abstract void _startup(); - - /** - * This method is called to request a shutdown of the runnable. - */ - public void shutdown() { - this.runCmd = false; - this._shutdown(); - } - - /** - * This method is called just after ControlledRunnable.runCmd is set to - * False. - */ - protected abstract void _shutdown(); - - /* - * Getters n setters - */ - public boolean getRunCmd() { - return runCmd; - } - - public boolean getRunStatus() { - return runStatus; - } - - /* - * Blockers - */ - public void blockTillRunStatus(boolean status) { - while (this.runStatus != status) { - try { - System.out.println("BLOCKING"); - Thread.sleep(25L); - } catch (InterruptedException e) { - Logger.debug( e.getMessage()); - - break; - } - } - } - - /** - * @return the thisThread - */ - protected Thread getThisThread() { - return thisThread; - } - - /** - * @return the threadName - */ - public String getThreadName() { - return threadName; - } - - /* - * Instance monitoring and tools - */ - - // Runnable tracking - private static final ArrayList runnables = new ArrayList<>(); - - public static void shutdownAllRunnables() { - for (ControlledRunnable cr : ControlledRunnable.runnables) { - //Use Direct logging since JobManager is a runnable. + // Runnable tracking + private static final ArrayList runnables = new ArrayList<>(); + private final String threadName; + protected boolean runCmd = false; + protected boolean runStatus = false; + private Thread thisThread; + + /* + * Main loop + */ + + public ControlledRunnable(String threadName) { + super(); + this.threadName = threadName; + ControlledRunnable.runnables.add(this); + } + + public static void shutdownAllRunnables() { + for (ControlledRunnable cr : ControlledRunnable.runnables) { + //Use Direct logging since JobManager is a runnable. Logger.info("ControlledRunnable", - "Sending Shutdown cmd to: " + cr.threadName); - cr.shutdown(); - } - } + "Sending Shutdown cmd to: " + cr.threadName); + cr.shutdown(); + } + } + + /** + * This is the method called when ControlledRunnable.thisThread.start() is + * called. + */ + @Override + public void run() { + if (this._preRun() == false) { + return; + } + + this.runStatus = true; + + if (this._Run() == false) { + return; + } + + if (this._postRun() == false) { + return; + } + + this.runStatus = false; + } + + /** + * _preRun() is called prior to the call to _Run(), but after _startup() + * + * @return + */ + protected abstract boolean _preRun(); + + /* + * Control + */ + + /** + * _Run() is called after _startup() and contains should contain the main + * loop. + * + * @return + */ + protected abstract boolean _Run(); + + /** + * _postRun() is called after _Run() exits, not necessarily before + * _shutdown() + * + * @return + */ + protected abstract boolean _postRun(); + + /** + * startup() initializes the internal thread, sets the runCMD to true, and + * calls _startup() prior to starting of the internal Thread. + */ + public void startup() { + + this.thisThread = new Thread(this, this.threadName); + this.runCmd = true; + this._startup(); + this.thisThread.start(); + } + + /** + * This method is called just before ControlledRunnable.thisThread.start() + * is called. + */ + protected abstract void _startup(); + + /** + * This method is called to request a shutdown of the runnable. + */ + public void shutdown() { + this.runCmd = false; + this._shutdown(); + } + + /** + * This method is called just after ControlledRunnable.runCmd is set to + * False. + */ + protected abstract void _shutdown(); + + /* + * Getters n setters + */ + public boolean getRunCmd() { + return runCmd; + } + + public boolean getRunStatus() { + return runStatus; + } + + /* + * Blockers + */ + public void blockTillRunStatus(boolean status) { + while (this.runStatus != status) { + try { + System.out.println("BLOCKING"); + Thread.sleep(25L); + } catch (InterruptedException e) { + Logger.debug(e.getMessage()); + + break; + } + } + } + + /* + * Instance monitoring and tools + */ + + /** + * @return the thisThread + */ + protected Thread getThisThread() { + return thisThread; + } + + /** + * @return the threadName + */ + public String getThreadName() { + return threadName; + } } diff --git a/src/engine/db/archive/BaneRecord.java b/src/engine/db/archive/BaneRecord.java index 27f6507f..700c4a2d 100644 --- a/src/engine/db/archive/BaneRecord.java +++ b/src/engine/db/archive/BaneRecord.java @@ -25,360 +25,358 @@ import static engine.Enum.RecordEventType; public class BaneRecord extends DataRecord { - private static final LinkedBlockingQueue recordPool = new LinkedBlockingQueue<>(); - private RecordEventType eventType; - private String cityHash; - private String cityName; - private String cityGuildHash; - private String cityNationHash; - private String baneDropperHash; - private String baneGuildHash; - private String baneNationHash; - private DateTime baneLiveTime; - private DateTime baneDropTime; + private static final LinkedBlockingQueue recordPool = new LinkedBlockingQueue<>(); + private RecordEventType eventType; + private String cityHash; + private String cityName; + private String cityGuildHash; + private String cityNationHash; + private String baneDropperHash; + private String baneGuildHash; + private String baneNationHash; + private DateTime baneLiveTime; + private DateTime baneDropTime; - private BaneRecord(Bane bane) { - this.recordType = Enum.DataRecordType.BANE; - this.eventType = RecordEventType.PENDING; - } + private BaneRecord(Bane bane) { + this.recordType = Enum.DataRecordType.BANE; + this.eventType = RecordEventType.PENDING; + } - public static BaneRecord borrow(Bane bane, RecordEventType eventType) { - BaneRecord baneRecord; + public static BaneRecord borrow(Bane bane, RecordEventType eventType) { + BaneRecord baneRecord; - baneRecord = recordPool.poll(); + baneRecord = recordPool.poll(); - if (baneRecord == null) { - baneRecord = new BaneRecord(bane); - baneRecord.eventType = eventType; - } - else { - baneRecord.recordType = Enum.DataRecordType.BANE; - baneRecord.eventType = eventType; + if (baneRecord == null) { + baneRecord = new BaneRecord(bane); + baneRecord.eventType = eventType; + } else { + baneRecord.recordType = Enum.DataRecordType.BANE; + baneRecord.eventType = eventType; - } + } - baneRecord.cityHash = bane.getCity().getHash(); - baneRecord.cityName = bane.getCity().getCityName(); - baneRecord.cityGuildHash = bane.getCity().getGuild().getHash(); - baneRecord.cityNationHash = bane.getCity().getGuild().getNation().getHash(); + baneRecord.cityHash = bane.getCity().getHash(); + baneRecord.cityName = bane.getCity().getCityName(); + baneRecord.cityGuildHash = bane.getCity().getGuild().getHash(); + baneRecord.cityNationHash = bane.getCity().getGuild().getNation().getHash(); - if (bane.getOwner() == null) { - baneRecord.baneDropperHash = "ERRANT"; - baneRecord.baneGuildHash = "ERRANT"; - baneRecord.baneNationHash = "ERRANT"; - } - else { - baneRecord.baneDropperHash = DataWarehouse.hasher.encrypt(bane.getOwner().getObjectUUID()); // getPlayerCharacter didn't check hash first? OMFG + if (bane.getOwner() == null) { + baneRecord.baneDropperHash = "ERRANT"; + baneRecord.baneGuildHash = "ERRANT"; + baneRecord.baneNationHash = "ERRANT"; + } else { + baneRecord.baneDropperHash = DataWarehouse.hasher.encrypt(bane.getOwner().getObjectUUID()); // getPlayerCharacter didn't check hash first? OMFG - baneRecord.baneGuildHash = bane.getOwner().getGuild().getHash(); - baneRecord.baneNationHash = bane.getOwner().getGuild().getNation().getHash(); + baneRecord.baneGuildHash = bane.getOwner().getGuild().getHash(); + baneRecord.baneNationHash = bane.getOwner().getGuild().getNation().getHash(); - baneRecord.baneLiveTime = bane.getLiveDate(); - baneRecord.baneDropTime = bane.getPlacementDate(); - } + baneRecord.baneLiveTime = bane.getLiveDate(); + baneRecord.baneDropTime = bane.getPlacementDate(); + } - return baneRecord; - } + return baneRecord; + } - public static PreparedStatement buildBanePushStatement(Connection connection, ResultSet rs) throws SQLException { + public static PreparedStatement buildBanePushStatement(Connection connection, ResultSet rs) throws SQLException { - PreparedStatement outStatement = null; - String queryString = "INSERT INTO `warehouse_banehistory` (`event_number`, `city_id`, `city_name`, `char_id`, `offGuild_id`, `offNat_id`, `defGuild_id`, `defNat_id`, `dropDatetime`, `liveDateTime`, `resolution`) VALUES(?,?,?,?,?,?,?,?,?,?,?)"; - java.util.Date sqlDateTime; + PreparedStatement outStatement = null; + String queryString = "INSERT INTO `warehouse_banehistory` (`event_number`, `city_id`, `city_name`, `char_id`, `offGuild_id`, `offNat_id`, `defGuild_id`, `defNat_id`, `dropDatetime`, `liveDateTime`, `resolution`) VALUES(?,?,?,?,?,?,?,?,?,?,?)"; + java.util.Date sqlDateTime; - outStatement = connection.prepareStatement(queryString); + outStatement = connection.prepareStatement(queryString); - // Bind record data + // Bind record data - outStatement.setInt(1, rs.getInt("event_number")); - outStatement.setString(2, rs.getString("city_id")); - outStatement.setString(3, rs.getString("city_name")); - outStatement.setString(4, rs.getString("char_id")); - outStatement.setString(5, rs.getString("offGuild_id")); - outStatement.setString(6, rs.getString("offNat_id")); - outStatement.setString(7, rs.getString("defGuild_id")); - outStatement.setString(8, rs.getString("defNat_id")); + outStatement.setInt(1, rs.getInt("event_number")); + outStatement.setString(2, rs.getString("city_id")); + outStatement.setString(3, rs.getString("city_name")); + outStatement.setString(4, rs.getString("char_id")); + outStatement.setString(5, rs.getString("offGuild_id")); + outStatement.setString(6, rs.getString("offNat_id")); + outStatement.setString(7, rs.getString("defGuild_id")); + outStatement.setString(8, rs.getString("defNat_id")); - sqlDateTime = rs.getTimestamp("dropDatetime"); + sqlDateTime = rs.getTimestamp("dropDatetime"); - if (sqlDateTime == null) - outStatement.setNull(9, Types.DATE); - else - outStatement.setTimestamp(9, rs.getTimestamp("dropDatetime")); + if (sqlDateTime == null) + outStatement.setNull(9, Types.DATE); + else + outStatement.setTimestamp(9, rs.getTimestamp("dropDatetime")); - sqlDateTime = rs.getTimestamp("dropDatetime"); + sqlDateTime = rs.getTimestamp("dropDatetime"); - if (sqlDateTime == null) - outStatement.setNull(10, Types.DATE); - else - outStatement.setTimestamp(10, rs.getTimestamp("liveDateTime")); + if (sqlDateTime == null) + outStatement.setNull(10, Types.DATE); + else + outStatement.setTimestamp(10, rs.getTimestamp("liveDateTime")); - outStatement.setString(11, rs.getString("resolution")); + outStatement.setString(11, rs.getString("resolution")); - return outStatement; - } + return outStatement; + } - public static PreparedStatement buildBaneQueryStatement(Connection connection) throws SQLException { + public static PreparedStatement buildBaneQueryStatement(Connection connection) throws SQLException { - PreparedStatement outStatement = null; - String queryString = "SELECT * FROM `warehouse_banehistory` WHERE `event_number` > ?"; - outStatement = connection.prepareStatement(queryString); - outStatement.setInt(1, WarehousePushThread.baneIndex); - return outStatement; - } + PreparedStatement outStatement = null; + String queryString = "SELECT * FROM `warehouse_banehistory` WHERE `event_number` > ?"; + outStatement = connection.prepareStatement(queryString); + outStatement.setInt(1, WarehousePushThread.baneIndex); + return outStatement; + } - public static DateTime getLastBaneDateTime(City city) { + public static DateTime getLastBaneDateTime(City city) { - DateTime outDateTime = null; + DateTime outDateTime = null; - try (Connection connection = DbManager.getConnection(); - PreparedStatement statement = buildDateTimeQueryStatement(connection, city); - ResultSet rs = statement.executeQuery()) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = buildDateTimeQueryStatement(connection, city); + ResultSet rs = statement.executeQuery()) { - while (rs.next()) { + while (rs.next()) { - outDateTime = new DateTime(rs.getTimestamp("endDatetime")); + outDateTime = new DateTime(rs.getTimestamp("endDatetime")); - } + } - } catch (SQLException e) { - Logger.error(e.toString()); - } + } catch (SQLException e) { + Logger.error(e.toString()); + } - return outDateTime; - } + return outDateTime; + } - private static PreparedStatement buildDateTimeQueryStatement (Connection connection, City city) throws SQLException { - PreparedStatement outStatement; - String queryString = "SELECT `endDatetime` FROM `warehouse_banehistory` WHERE `city_id` = ? ORDER BY `endDatetime` DESC LIMIT 1"; - outStatement = connection.prepareStatement(queryString); - outStatement.setString(1, city.getHash()); - return outStatement; + private static PreparedStatement buildDateTimeQueryStatement(Connection connection, City city) throws SQLException { + PreparedStatement outStatement; + String queryString = "SELECT `endDatetime` FROM `warehouse_banehistory` WHERE `city_id` = ? ORDER BY `endDatetime` DESC LIMIT 1"; + outStatement = connection.prepareStatement(queryString); + outStatement.setString(1, city.getHash()); + return outStatement; - } + } - public static void updateLiveDate(Bane bane, DateTime dateTime) { + public static void updateLiveDate(Bane bane, DateTime dateTime) { - if (bane == null) - return; + if (bane == null) + return; - try (Connection connection = DbManager.getConnection(); - PreparedStatement statement = buildUpdateLiveDateStatement(connection, bane, dateTime)) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = buildUpdateLiveDateStatement(connection, bane, dateTime)) { - statement.execute(); + statement.execute(); - } catch (SQLException e) { - Logger.error(e.toString()); - } - } + } catch (SQLException e) { + Logger.error(e.toString()); + } + } - private static PreparedStatement buildUpdateLiveDateStatement(Connection connection, Bane bane, DateTime dateTime) throws SQLException { + private static PreparedStatement buildUpdateLiveDateStatement(Connection connection, Bane bane, DateTime dateTime) throws SQLException { - PreparedStatement outStatement = null; - String queryString = "UPDATE `warehouse_banehistory` SET `liveDatetime` = ?, `dirty` = 1 WHERE `city_id` = ? AND `resolution` = 'PENDING'"; + PreparedStatement outStatement = null; + String queryString = "UPDATE `warehouse_banehistory` SET `liveDatetime` = ?, `dirty` = 1 WHERE `city_id` = ? AND `resolution` = 'PENDING'"; - outStatement = connection.prepareStatement(queryString); - outStatement.setTimestamp(1, new java.sql.Timestamp(dateTime.getMillis())); - outStatement.setString(2, bane.getCity().getHash()); + outStatement = connection.prepareStatement(queryString); + outStatement.setTimestamp(1, new java.sql.Timestamp(dateTime.getMillis())); + outStatement.setString(2, bane.getCity().getHash()); - return outStatement; - } + return outStatement; + } - private static PreparedStatement buildUpdateResolutionStatement(Connection connection, Bane bane, RecordEventType eventType) throws SQLException { + private static PreparedStatement buildUpdateResolutionStatement(Connection connection, Bane bane, RecordEventType eventType) throws SQLException { - PreparedStatement outStatement = null; - String queryString = "UPDATE `warehouse_banehistory` SET `endDatetime` = ?, `resolution` = ?, `dirty` = 1 WHERE `city_id` = ? AND `resolution` = 'PENDING'"; + PreparedStatement outStatement = null; + String queryString = "UPDATE `warehouse_banehistory` SET `endDatetime` = ?, `resolution` = ?, `dirty` = 1 WHERE `city_id` = ? AND `resolution` = 'PENDING'"; - outStatement = connection.prepareStatement(queryString); - outStatement.setTimestamp(1, Timestamp.valueOf(LocalDateTime.now())); - outStatement.setString(2, eventType.name()); - outStatement.setString(3, bane.getCity().getHash()); + outStatement = connection.prepareStatement(queryString); + outStatement.setTimestamp(1, Timestamp.valueOf(LocalDateTime.now())); + outStatement.setString(2, eventType.name()); + outStatement.setString(3, bane.getCity().getHash()); - return outStatement; - } + return outStatement; + } - public static void updateResolution(Bane bane, RecordEventType eventType) { + public static void updateResolution(Bane bane, RecordEventType eventType) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement statement = buildUpdateResolutionStatement(connection, bane, eventType)) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = buildUpdateResolutionStatement(connection, bane, eventType)) { - statement.execute(); + statement.execute(); - } catch (SQLException e) { - Logger.error(e.toString()); - } - } + } catch (SQLException e) { + Logger.error(e.toString()); + } + } - public static String getBaneHistoryString() { + public static String getBaneHistoryString() { - String outString; - String queryString; - String dividerString; - String newLine = System.getProperty("line.separator"); - outString = "[LUA_BANES() DATA WAREHOUSE]" + newLine; - dividerString = "--------------------------------" + newLine; - queryString = "CALL `baneHistory`()"; + String outString; + String queryString; + String dividerString; + String newLine = System.getProperty("line.separator"); + outString = "[LUA_BANES() DATA WAREHOUSE]" + newLine; + dividerString = "--------------------------------" + newLine; + queryString = "CALL `baneHistory`()"; - try (Connection connection = DbManager.getConnection(); - PreparedStatement statement = connection.prepareCall(queryString); - ResultSet rs = statement.executeQuery()) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = connection.prepareCall(queryString); + ResultSet rs = statement.executeQuery()) { - while (rs.next()) { + while (rs.next()) { - outString += "Magicbane unresolved banes: " + rs.getInt("PENDING") + '/' + rs.getInt("TOTAL") + newLine; - outString += dividerString; - outString += "Bane Resolution History" + newLine; - outString += dividerString; + outString += "Magicbane unresolved banes: " + rs.getInt("PENDING") + '/' + rs.getInt("TOTAL") + newLine; + outString += dividerString; + outString += "Bane Resolution History" + newLine; + outString += dividerString; - outString += "Destruction: " + rs.getInt("DESTROY") + newLine; - outString += "Capture: " + rs.getInt("CAPTURE") + newLine; - outString += "Defended: " + rs.getInt("DEFEND") + newLine; - } + outString += "Destruction: " + rs.getInt("DESTROY") + newLine; + outString += "Capture: " + rs.getInt("CAPTURE") + newLine; + outString += "Defended: " + rs.getInt("DEFEND") + newLine; + } - } catch (SQLException e) { - e.printStackTrace(); - } - return outString; - } + } catch (SQLException e) { + e.printStackTrace(); + } + return outString; + } - public static void updateDirtyRecords() { + public static void updateDirtyRecords() { - String queryString = "SELECT * FROM `warehouse_banehistory` where `dirty` = 1"; + String queryString = "SELECT * FROM `warehouse_banehistory` where `dirty` = 1"; - // Reset character delta + // Reset character delta - WarehousePushThread.baneDelta = 0; + WarehousePushThread.baneDelta = 0; - try (Connection localConnection = DbManager.getConnection(); - PreparedStatement statement = localConnection.prepareStatement(queryString, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); // Make this an updatable result set as we'll reset the dirty flag as we go along - ResultSet rs = statement.executeQuery()) { + try (Connection localConnection = DbManager.getConnection(); + PreparedStatement statement = localConnection.prepareStatement(queryString, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); // Make this an updatable result set as we'll reset the dirty flag as we go along + ResultSet rs = statement.executeQuery()) { - while (rs.next()) { + while (rs.next()) { - // Only update the index and dirty flag - // if the remote database update succeeded + // Only update the index and dirty flag + // if the remote database update succeeded - if (updateDirtyRecord(rs) == true) - WarehousePushThread.baneDelta++; - else - continue; + if (updateDirtyRecord(rs) == true) + WarehousePushThread.baneDelta++; + else + continue; - // Reset the dirty flag in the local database + // Reset the dirty flag in the local database - rs.updateInt("dirty", 0); - rs.updateRow(); - } + rs.updateInt("dirty", 0); + rs.updateRow(); + } - } catch (SQLException e) { - Logger.error( e.toString()); - } - } + } catch (SQLException e) { + Logger.error(e.toString()); + } + } - private static boolean updateDirtyRecord(ResultSet rs) { + private static boolean updateDirtyRecord(ResultSet rs) { - try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection(); - PreparedStatement statement = buildUpdateDirtyStatement(remoteConnection, rs)) { + try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection(); + PreparedStatement statement = buildUpdateDirtyStatement(remoteConnection, rs)) { - statement.execute(); - return true; - } catch (SQLException e) { - Logger.error( e.toString()); - return false; - } - } + statement.execute(); + return true; + } catch (SQLException e) { + Logger.error(e.toString()); + return false; + } + } - private static PreparedStatement buildUpdateDirtyStatement(Connection connection, ResultSet rs) throws SQLException { + private static PreparedStatement buildUpdateDirtyStatement(Connection connection, ResultSet rs) throws SQLException { - PreparedStatement outStatement; - String queryString = "UPDATE `warehouse_banehistory` SET `liveDateTime` = ?, `endDateTime` = ?, `resolution` = ? WHERE `event_number` = ?"; - java.util.Date sqlDateTime; + PreparedStatement outStatement; + String queryString = "UPDATE `warehouse_banehistory` SET `liveDateTime` = ?, `endDateTime` = ?, `resolution` = ? WHERE `event_number` = ?"; + java.util.Date sqlDateTime; - outStatement = connection.prepareStatement(queryString); + outStatement = connection.prepareStatement(queryString); - // Bind record data + // Bind record data - sqlDateTime = rs.getTimestamp("liveDateTime"); + sqlDateTime = rs.getTimestamp("liveDateTime"); - if (sqlDateTime == null) - outStatement.setNull(1, Types.DATE); - else - outStatement.setTimestamp(1, rs.getTimestamp("liveDateTime")); + if (sqlDateTime == null) + outStatement.setNull(1, Types.DATE); + else + outStatement.setTimestamp(1, rs.getTimestamp("liveDateTime")); - sqlDateTime = rs.getTimestamp("endDateTime"); + sqlDateTime = rs.getTimestamp("endDateTime"); - if (sqlDateTime == null) - outStatement.setNull(2, Types.DATE); - else - outStatement.setTimestamp(2, rs.getTimestamp("endDateTime")); + if (sqlDateTime == null) + outStatement.setNull(2, Types.DATE); + else + outStatement.setTimestamp(2, rs.getTimestamp("endDateTime")); - outStatement.setString(3, rs.getString("resolution")); - outStatement.setInt(4, rs.getInt("event_number")); + outStatement.setString(3, rs.getString("resolution")); + outStatement.setInt(4, rs.getInt("event_number")); - return outStatement; - } + return outStatement; + } - void reset() { - this.cityHash = null; - this.cityGuildHash = null; - this.cityNationHash = null; - this.baneDropperHash = null; - this.baneGuildHash = null; - this.baneNationHash = null; - this.baneLiveTime = null; - } + void reset() { + this.cityHash = null; + this.cityGuildHash = null; + this.cityNationHash = null; + this.baneDropperHash = null; + this.baneGuildHash = null; + this.baneNationHash = null; + this.baneLiveTime = null; + } - public void release() { - this.reset(); - recordPool.add(this); - } + public void release() { + this.reset(); + recordPool.add(this); + } - public void write() { + public void write() { - try (Connection connection = DbManager.getConnection(); - PreparedStatement statement = buildBaneInsertStatement(connection)) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = buildBaneInsertStatement(connection)) { - statement.execute(); + statement.execute(); - } catch (SQLException e) { - Logger.error(e.toString()); - } + } catch (SQLException e) { + Logger.error(e.toString()); + } - } + } - private PreparedStatement buildBaneInsertStatement(Connection connection) throws SQLException { + private PreparedStatement buildBaneInsertStatement(Connection connection) throws SQLException { - PreparedStatement outStatement = null; - String queryString = "INSERT INTO `warehouse_banehistory` (`city_id`, `city_name`, `char_id`, `offGuild_id`, `offNat_id`, `defGuild_id`, `defNat_id`, `dropDatetime`, `liveDateTime`, `resolution`) VALUES(?,?,?,?,?,?,?,?,?,?)"; + PreparedStatement outStatement = null; + String queryString = "INSERT INTO `warehouse_banehistory` (`city_id`, `city_name`, `char_id`, `offGuild_id`, `offNat_id`, `defGuild_id`, `defNat_id`, `dropDatetime`, `liveDateTime`, `resolution`) VALUES(?,?,?,?,?,?,?,?,?,?)"; - outStatement = connection.prepareStatement(queryString); + outStatement = connection.prepareStatement(queryString); - outStatement.setString(1, this.cityHash); - outStatement.setString(2, this.cityName); - outStatement.setString(3, this.baneDropperHash); - outStatement.setString(4, this.baneGuildHash); - outStatement.setString(5, this.baneNationHash); - outStatement.setString(6, this.cityGuildHash); - outStatement.setString(7, this.cityNationHash); + outStatement.setString(1, this.cityHash); + outStatement.setString(2, this.cityName); + outStatement.setString(3, this.baneDropperHash); + outStatement.setString(4, this.baneGuildHash); + outStatement.setString(5, this.baneNationHash); + outStatement.setString(6, this.cityGuildHash); + outStatement.setString(7, this.cityNationHash); - if (this.baneDropTime == null) - outStatement.setNull(8, java.sql.Types.DATE); - else - outStatement.setTimestamp(8, new java.sql.Timestamp(this.baneDropTime.getMillis())); + if (this.baneDropTime == null) + outStatement.setNull(8, java.sql.Types.DATE); + else + outStatement.setTimestamp(8, new java.sql.Timestamp(this.baneDropTime.getMillis())); - if (this.baneLiveTime == null) - outStatement.setNull(9, java.sql.Types.DATE); - else - outStatement.setTimestamp(9, new java.sql.Timestamp(this.baneLiveTime.getMillis())); + if (this.baneLiveTime == null) + outStatement.setNull(9, java.sql.Types.DATE); + else + outStatement.setTimestamp(9, new java.sql.Timestamp(this.baneLiveTime.getMillis())); - outStatement.setString(10, this.eventType.name()); + outStatement.setString(10, this.eventType.name()); - return outStatement; - } + return outStatement; + } } // END CLASS diff --git a/src/engine/db/archive/CharacterRecord.java b/src/engine/db/archive/CharacterRecord.java index 157c6d71..7b329d32 100644 --- a/src/engine/db/archive/CharacterRecord.java +++ b/src/engine/db/archive/CharacterRecord.java @@ -44,8 +44,7 @@ public class CharacterRecord extends DataRecord { if (characterRecord == null) { characterRecord = new CharacterRecord(player); - } - else { + } else { characterRecord.recordType = Enum.DataRecordType.CHARACTER; characterRecord.player = player; diff --git a/src/engine/db/archive/CityRecord.java b/src/engine/db/archive/CityRecord.java index 785cf405..099ddf7d 100644 --- a/src/engine/db/archive/CityRecord.java +++ b/src/engine/db/archive/CityRecord.java @@ -19,144 +19,143 @@ import java.util.concurrent.LinkedBlockingQueue; public class CityRecord extends DataRecord { - private static final LinkedBlockingQueue recordPool = new LinkedBlockingQueue<>(); - private Enum.RecordEventType eventType; - private City city; - private String cityHash; - private String cityGuildHash; - private String cityName; - private String cityMotto; - private float locX; - private float locY; - private String zoneHash; - private java.time.LocalDateTime establishedDatetime; + private static final LinkedBlockingQueue recordPool = new LinkedBlockingQueue<>(); + private Enum.RecordEventType eventType; + private City city; + private String cityHash; + private String cityGuildHash; + private String cityName; + private String cityMotto; + private float locX; + private float locY; + private String zoneHash; + private java.time.LocalDateTime establishedDatetime; - private CityRecord(City city) { - this.recordType = Enum.DataRecordType.CITY; - this.city = city; - this.eventType = Enum.RecordEventType.CREATE; + private CityRecord(City city) { + this.recordType = Enum.DataRecordType.CITY; + this.city = city; + this.eventType = Enum.RecordEventType.CREATE; - } + } - public static CityRecord borrow(City city, Enum.RecordEventType eventType) { - CityRecord cityRecord; + public static CityRecord borrow(City city, Enum.RecordEventType eventType) { + CityRecord cityRecord; - cityRecord = recordPool.poll(); + cityRecord = recordPool.poll(); - if (cityRecord == null) { - cityRecord = new CityRecord(city); - cityRecord.eventType = eventType; - } - else { - cityRecord.recordType = Enum.DataRecordType.CITY; - cityRecord.eventType = eventType; - cityRecord.city = city; + if (cityRecord == null) { + cityRecord = new CityRecord(city); + cityRecord.eventType = eventType; + } else { + cityRecord.recordType = Enum.DataRecordType.CITY; + cityRecord.eventType = eventType; + cityRecord.city = city; - } + } - if (cityRecord.city.getHash() == null) - cityRecord.city.setHash(DataWarehouse.hasher.encrypt(cityRecord.city.getObjectUUID())); + if (cityRecord.city.getHash() == null) + cityRecord.city.setHash(DataWarehouse.hasher.encrypt(cityRecord.city.getObjectUUID())); - cityRecord.cityHash = cityRecord.city.getHash(); + cityRecord.cityHash = cityRecord.city.getHash(); - cityRecord.cityName = cityRecord.city.getCityName(); - cityRecord.cityMotto = cityRecord.city.getMotto(); + cityRecord.cityName = cityRecord.city.getCityName(); + cityRecord.cityMotto = cityRecord.city.getMotto(); - cityRecord.cityGuildHash = cityRecord.city.getGuild().getHash(); + cityRecord.cityGuildHash = cityRecord.city.getGuild().getHash(); - cityRecord.locX = cityRecord.city.getTOL().getLoc().x; - cityRecord.locY = -cityRecord.city.getTOL().getLoc().z; // flip sign on 'y' coordinate + cityRecord.locX = cityRecord.city.getTOL().getLoc().x; + cityRecord.locY = -cityRecord.city.getTOL().getLoc().z; // flip sign on 'y' coordinate - cityRecord.zoneHash = cityRecord.city.getParent().getHash(); + cityRecord.zoneHash = cityRecord.city.getParent().getHash(); - if (cityRecord.eventType.equals(Enum.RecordEventType.CREATE)) - cityRecord.establishedDatetime = cityRecord.city.established; - else - cityRecord.establishedDatetime = java.time.LocalDateTime.now(); + if (cityRecord.eventType.equals(Enum.RecordEventType.CREATE)) + cityRecord.establishedDatetime = cityRecord.city.established; + else + cityRecord.establishedDatetime = java.time.LocalDateTime.now(); - return cityRecord; - } + return cityRecord; + } - public static PreparedStatement buildCityPushStatement(Connection connection, ResultSet rs) throws SQLException { + public static PreparedStatement buildCityPushStatement(Connection connection, ResultSet rs) throws SQLException { - PreparedStatement outStatement = null; - String queryString = "INSERT INTO `warehouse_cityhistory` (`event_number`, `city_id`, `city_name`, `city_motto`, `guild_id`, `loc_x`, `loc_y`, `zone_id`, `eventType`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?,?)"; - outStatement = connection.prepareStatement(queryString); + PreparedStatement outStatement = null; + String queryString = "INSERT INTO `warehouse_cityhistory` (`event_number`, `city_id`, `city_name`, `city_motto`, `guild_id`, `loc_x`, `loc_y`, `zone_id`, `eventType`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?,?)"; + outStatement = connection.prepareStatement(queryString); - // Bind record data + // Bind record data - outStatement.setInt(1, rs.getInt("event_number")); - outStatement.setString(2, rs.getString("city_id")); - outStatement.setString(3, rs.getString("city_name")); - outStatement.setString(4, rs.getString("city_motto")); - outStatement.setString(5, rs.getString("guild_id")); + outStatement.setInt(1, rs.getInt("event_number")); + outStatement.setString(2, rs.getString("city_id")); + outStatement.setString(3, rs.getString("city_name")); + outStatement.setString(4, rs.getString("city_motto")); + outStatement.setString(5, rs.getString("guild_id")); - outStatement.setFloat(6, rs.getFloat("loc_x")); - outStatement.setFloat(7, rs.getFloat("loc_y")); - outStatement.setString(8, rs.getString("zone_id")); - outStatement.setString(9, rs.getString("eventType")); - outStatement.setTimestamp(10, rs.getTimestamp("datetime")); + outStatement.setFloat(6, rs.getFloat("loc_x")); + outStatement.setFloat(7, rs.getFloat("loc_y")); + outStatement.setString(8, rs.getString("zone_id")); + outStatement.setString(9, rs.getString("eventType")); + outStatement.setTimestamp(10, rs.getTimestamp("datetime")); - return outStatement; - } + return outStatement; + } - public static PreparedStatement buildCityQueryStatement(Connection connection) throws SQLException { + public static PreparedStatement buildCityQueryStatement(Connection connection) throws SQLException { - PreparedStatement outStatement = null; - String queryString = "SELECT * FROM `warehouse_cityhistory` WHERE `event_number` > ?"; - outStatement = connection.prepareStatement(queryString); - outStatement.setInt(1, WarehousePushThread.cityIndex); - return outStatement; - } + PreparedStatement outStatement = null; + String queryString = "SELECT * FROM `warehouse_cityhistory` WHERE `event_number` > ?"; + outStatement = connection.prepareStatement(queryString); + outStatement.setInt(1, WarehousePushThread.cityIndex); + return outStatement; + } - void reset() { - this.city = null; - this.cityHash = null; - this.cityGuildHash = null; - this.cityMotto = null; - this.zoneHash = null; - this.establishedDatetime = null; + void reset() { + this.city = null; + this.cityHash = null; + this.cityGuildHash = null; + this.cityMotto = null; + this.zoneHash = null; + this.establishedDatetime = null; - } + } - public void release() { - this.reset(); - recordPool.add(this); - } + public void release() { + this.reset(); + recordPool.add(this); + } - public void write() { + public void write() { - try (Connection connection = DbManager.getConnection(); - PreparedStatement statement = this.buildCityInsertStatement(connection)) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = this.buildCityInsertStatement(connection)) { - statement.execute(); + statement.execute(); - } catch (SQLException e) { - e.printStackTrace(); - } - } + } catch (SQLException e) { + e.printStackTrace(); + } + } - private PreparedStatement buildCityInsertStatement(Connection connection) throws SQLException { + private PreparedStatement buildCityInsertStatement(Connection connection) throws SQLException { - PreparedStatement outStatement = null; - String queryString = "INSERT INTO `warehouse_cityhistory` (`city_id`, `city_name`, `city_motto`, `guild_id`, `loc_x`, `loc_y`, `zone_id`, `eventType`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?)"; + PreparedStatement outStatement = null; + String queryString = "INSERT INTO `warehouse_cityhistory` (`city_id`, `city_name`, `city_motto`, `guild_id`, `loc_x`, `loc_y`, `zone_id`, `eventType`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?)"; - outStatement = connection.prepareStatement(queryString); + outStatement = connection.prepareStatement(queryString); - // Bind character data + // Bind character data - outStatement.setString(1, this.cityHash); - outStatement.setString(2, this.cityName); - outStatement.setString(3, this.cityMotto); - outStatement.setString(4, this.cityGuildHash); + outStatement.setString(1, this.cityHash); + outStatement.setString(2, this.cityName); + outStatement.setString(3, this.cityMotto); + outStatement.setString(4, this.cityGuildHash); - outStatement.setFloat(5, this.locX); - outStatement.setFloat(6, this.locY); - outStatement.setString(7, this.zoneHash); - outStatement.setString(8, this.eventType.name()); - outStatement.setTimestamp(9, Timestamp.valueOf(this.establishedDatetime)); + outStatement.setFloat(5, this.locX); + outStatement.setFloat(6, this.locY); + outStatement.setString(7, this.zoneHash); + outStatement.setString(8, this.eventType.name()); + outStatement.setTimestamp(9, Timestamp.valueOf(this.establishedDatetime)); - return outStatement; - } + return outStatement; + } } diff --git a/src/engine/db/archive/DataRecord.java b/src/engine/db/archive/DataRecord.java index a86dd3a3..acba35e7 100644 --- a/src/engine/db/archive/DataRecord.java +++ b/src/engine/db/archive/DataRecord.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.db.archive; import engine.Enum; diff --git a/src/engine/db/archive/DataWarehouse.java b/src/engine/db/archive/DataWarehouse.java index 8ba3b744..d8055409 100644 --- a/src/engine/db/archive/DataWarehouse.java +++ b/src/engine/db/archive/DataWarehouse.java @@ -35,12 +35,12 @@ public class DataWarehouse implements Runnable { // If WarehousePush is disabled // then early exit - if ( ConfigManager.MB_WORLD_WAREHOUSE_PUSH.getValue().equalsIgnoreCase("false")) { + if (ConfigManager.MB_WORLD_WAREHOUSE_PUSH.getValue().equalsIgnoreCase("false")) { Logger.info("Warehouse Remote Connection disabled along with push"); return; } - Logger.info( "Configuring remote Database Connection Pool..."); + Logger.info("Configuring remote Database Connection Pool..."); configureRemoteConnectionPool(); } @@ -188,6 +188,24 @@ public class DataWarehouse implements Runnable { return false; } + private static void configureRemoteConnectionPool() { + + HikariConfig config = new HikariConfig(); + + config.setMaximumPoolSize(1); // Only the server talks to remote, so yeah. + config.setJdbcUrl(ConfigManager.MB_WAREHOUSE_ADDR.getValue()); + config.setUsername(ConfigManager.MB_WAREHOUSE_USER.getValue()); + config.setPassword(ConfigManager.MB_WAREHOUSE_PASS.getValue()); + config.addDataSourceProperty("characterEncoding", "utf8"); + config.addDataSourceProperty("cachePrepStmts", "true"); + config.addDataSourceProperty("prepStmtCacheSize", "250"); + config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); + + remoteConnectionPool = new HikariDataSource(config); // setup the connection pool + + Logger.info("remote warehouse connection configured"); + } + public void run() { // Working variable set @@ -201,7 +219,7 @@ public class DataWarehouse implements Runnable { RealmRecord realmRecord; MineRecord mineRecord; - Logger.info( "DataWarehouse is running."); + Logger.info("DataWarehouse is running."); while (true) { @@ -261,7 +279,7 @@ public class DataWarehouse implements Runnable { mineRecord.release(); break; default: - Logger.error( "Unhandled record type"); + Logger.error("Unhandled record type"); break; } // end switch @@ -269,22 +287,4 @@ public class DataWarehouse implements Runnable { } } - private static void configureRemoteConnectionPool() { - - HikariConfig config = new HikariConfig(); - - config.setMaximumPoolSize(1); // Only the server talks to remote, so yeah. - config.setJdbcUrl(ConfigManager.MB_WAREHOUSE_ADDR.getValue()); - config.setUsername(ConfigManager.MB_WAREHOUSE_USER.getValue()); - config.setPassword(ConfigManager.MB_WAREHOUSE_PASS.getValue()); - config.addDataSourceProperty("characterEncoding", "utf8"); - config.addDataSourceProperty("cachePrepStmts", "true"); - config.addDataSourceProperty("prepStmtCacheSize", "250"); - config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); - - remoteConnectionPool = new HikariDataSource(config); // setup the connection pool - - Logger.info("remote warehouse connection configured"); - } - } diff --git a/src/engine/db/archive/GuildRecord.java b/src/engine/db/archive/GuildRecord.java index ec141cea..9447fd54 100644 --- a/src/engine/db/archive/GuildRecord.java +++ b/src/engine/db/archive/GuildRecord.java @@ -26,144 +26,139 @@ import java.util.concurrent.LinkedBlockingQueue; public class GuildRecord extends DataRecord { - private static final LinkedBlockingQueue recordPool = new LinkedBlockingQueue<>(); - private Enum.RecordEventType eventType; - private Guild guild; - public String guildHash; - private String guildName; - private String charterName; - private String GLHash; - private String guildMotto; - private int bgIcon; - private int bgColour1; - private int bgColour2; - private int fgIcon; - private int fgColour; - public int guildID; - - private java.time.LocalDateTime eventDatetime; - - public static HashMap GuildRecordCache = null; - - private GuildRecord(Guild guild) { - this.recordType = Enum.DataRecordType.GUILD; - this.guild = guild; - this.eventType = Enum.RecordEventType.CREATE; - } - - - - public GuildRecord(ResultSet rs) throws SQLException { - super(); - this.eventType = RecordEventType.valueOf(rs.getString("eventType")); - this.guildHash = rs.getString("guild_id"); - this.guildName = rs.getString("guild_name"); - this.charterName = rs.getString("charter"); - GLHash = rs.getString("guild_founder"); - this.guildMotto = rs.getString("guild_motto"); - this.bgIcon = rs.getInt("bgicon"); - this.bgColour1 = rs.getInt("bgcoloura"); - this.bgColour2 = rs.getInt("bgcolourb"); - this.fgIcon = rs.getInt("fgicon"); - this.fgColour = rs.getInt("fgcolour"); - - java.sql.Timestamp eventTimeStamp = rs.getTimestamp("upgradeDate"); - - if (eventTimeStamp != null) - this.eventDatetime = LocalDateTime.ofInstant(eventTimeStamp.toInstant(), ZoneId.systemDefault()); - } - - - - public static GuildRecord borrow(Guild guild, Enum.RecordEventType eventType) { - GuildRecord guildRecord; - //add - guildRecord = recordPool.poll(); - - if (guildRecord == null) { - guildRecord = new GuildRecord(guild); - guildRecord.eventType = eventType; - } - else { - guildRecord.guild = guild; - guildRecord.recordType = Enum.DataRecordType.GUILD; - guildRecord.eventType = eventType; - - } - - guildRecord.guildHash = guildRecord.guild.getHash(); - guildRecord.guildID = guildRecord.guild.getObjectUUID(); - guildRecord.guildName = guildRecord.guild.getName(); - guildRecord.charterName = Enum.GuildType.getGuildTypeFromInt(guildRecord.guild.getCharter()).getCharterName(); - - guildRecord.GLHash = DataWarehouse.hasher.encrypt(guildRecord.guild.getGuildLeaderUUID()); - - guildRecord.guildMotto = guildRecord.guild.getMotto(); - guildRecord.bgIcon = guildRecord.guild.getBgDesign(); - guildRecord.bgColour1 = guildRecord.guild.getBgc1(); - guildRecord.bgColour2 = guildRecord.guild.getBgc2(); - guildRecord.fgIcon = guildRecord.guild.getSymbol(); - guildRecord.fgColour = guildRecord.guild.getSc(); - - if (guild.getOwnedCity() != null) - guildRecord.eventDatetime = guild.getOwnedCity().established; - else - guildRecord.eventDatetime = LocalDateTime.now(); - - return guildRecord; - } - - public static PreparedStatement buildGuildPushStatement(Connection connection, ResultSet rs) throws SQLException { - - PreparedStatement outStatement = null; - String queryString = "INSERT INTO `warehouse_guildhistory` (`event_number`, `guild_id`, `guild_name`, `guild_motto`, `guild_founder`, `charter`, `bgicon`, `bgcoloura`, `bgcolourb`, `fgicon`, `fgcolour`, `eventtype`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)"; - - outStatement = connection.prepareStatement(queryString); - - // Bind record data - - outStatement.setInt(1, rs.getInt("event_number")); - outStatement.setString(2, rs.getString("guild_id")); - outStatement.setString(3, rs.getString("guild_name")); - outStatement.setString(4, rs.getString("guild_motto")); - outStatement.setString(5, rs.getString("guild_founder")); - outStatement.setString(6, rs.getString("charter")); - outStatement.setInt(7, rs.getInt("bgicon")); - outStatement.setInt(8, rs.getInt("bgcoloura")); - outStatement.setInt(9, rs.getInt("bgcolourb")); - outStatement.setInt(10, rs.getInt("fgicon")); - outStatement.setInt(11, rs.getInt("fgcolour")); - outStatement.setString(12, rs.getString("eventtype")); - outStatement.setTimestamp(13, rs.getTimestamp("datetime")); - - return outStatement; - } - - public static PreparedStatement buildGuildQueryStatement(Connection connection) throws SQLException { - - PreparedStatement outStatement = null; - String queryString = "SELECT * FROM `warehouse_guildhistory` WHERE `event_number` > ?"; - outStatement = connection.prepareStatement(queryString); - outStatement.setInt(1, WarehousePushThread.guildIndex); - return outStatement; - } - - void reset() { - - this.guild = null; - this.guildHash = null; - this.GLHash = null; - this.guildMotto = null; - this.charterName = null; - this.eventDatetime = null; - } - - public void release() { - this.reset(); - recordPool.add(this); - } + private static final LinkedBlockingQueue recordPool = new LinkedBlockingQueue<>(); + public static HashMap GuildRecordCache = null; + public String guildHash; + public int guildID; + private Enum.RecordEventType eventType; + private Guild guild; + private String guildName; + private String charterName; + private String GLHash; + private String guildMotto; + private int bgIcon; + private int bgColour1; + private int bgColour2; + private int fgIcon; + private int fgColour; + private java.time.LocalDateTime eventDatetime; + + private GuildRecord(Guild guild) { + this.recordType = Enum.DataRecordType.GUILD; + this.guild = guild; + this.eventType = Enum.RecordEventType.CREATE; + } + + + public GuildRecord(ResultSet rs) throws SQLException { + super(); + this.eventType = RecordEventType.valueOf(rs.getString("eventType")); + this.guildHash = rs.getString("guild_id"); + this.guildName = rs.getString("guild_name"); + this.charterName = rs.getString("charter"); + GLHash = rs.getString("guild_founder"); + this.guildMotto = rs.getString("guild_motto"); + this.bgIcon = rs.getInt("bgicon"); + this.bgColour1 = rs.getInt("bgcoloura"); + this.bgColour2 = rs.getInt("bgcolourb"); + this.fgIcon = rs.getInt("fgicon"); + this.fgColour = rs.getInt("fgcolour"); + + java.sql.Timestamp eventTimeStamp = rs.getTimestamp("upgradeDate"); + + if (eventTimeStamp != null) + this.eventDatetime = LocalDateTime.ofInstant(eventTimeStamp.toInstant(), ZoneId.systemDefault()); + } + + + public static GuildRecord borrow(Guild guild, Enum.RecordEventType eventType) { + GuildRecord guildRecord; + //add + guildRecord = recordPool.poll(); + + if (guildRecord == null) { + guildRecord = new GuildRecord(guild); + guildRecord.eventType = eventType; + } else { + guildRecord.guild = guild; + guildRecord.recordType = Enum.DataRecordType.GUILD; + guildRecord.eventType = eventType; + + } + + guildRecord.guildHash = guildRecord.guild.getHash(); + guildRecord.guildID = guildRecord.guild.getObjectUUID(); + guildRecord.guildName = guildRecord.guild.getName(); + guildRecord.charterName = Enum.GuildType.getGuildTypeFromInt(guildRecord.guild.getCharter()).getCharterName(); + + guildRecord.GLHash = DataWarehouse.hasher.encrypt(guildRecord.guild.getGuildLeaderUUID()); + + guildRecord.guildMotto = guildRecord.guild.getMotto(); + guildRecord.bgIcon = guildRecord.guild.getBgDesign(); + guildRecord.bgColour1 = guildRecord.guild.getBgc1(); + guildRecord.bgColour2 = guildRecord.guild.getBgc2(); + guildRecord.fgIcon = guildRecord.guild.getSymbol(); + guildRecord.fgColour = guildRecord.guild.getSc(); + + if (guild.getOwnedCity() != null) + guildRecord.eventDatetime = guild.getOwnedCity().established; + else + guildRecord.eventDatetime = LocalDateTime.now(); + + return guildRecord; + } + + public static PreparedStatement buildGuildPushStatement(Connection connection, ResultSet rs) throws SQLException { - public void write() { + PreparedStatement outStatement = null; + String queryString = "INSERT INTO `warehouse_guildhistory` (`event_number`, `guild_id`, `guild_name`, `guild_motto`, `guild_founder`, `charter`, `bgicon`, `bgcoloura`, `bgcolourb`, `fgicon`, `fgcolour`, `eventtype`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)"; + + outStatement = connection.prepareStatement(queryString); + + // Bind record data + + outStatement.setInt(1, rs.getInt("event_number")); + outStatement.setString(2, rs.getString("guild_id")); + outStatement.setString(3, rs.getString("guild_name")); + outStatement.setString(4, rs.getString("guild_motto")); + outStatement.setString(5, rs.getString("guild_founder")); + outStatement.setString(6, rs.getString("charter")); + outStatement.setInt(7, rs.getInt("bgicon")); + outStatement.setInt(8, rs.getInt("bgcoloura")); + outStatement.setInt(9, rs.getInt("bgcolourb")); + outStatement.setInt(10, rs.getInt("fgicon")); + outStatement.setInt(11, rs.getInt("fgcolour")); + outStatement.setString(12, rs.getString("eventtype")); + outStatement.setTimestamp(13, rs.getTimestamp("datetime")); + + return outStatement; + } + + public static PreparedStatement buildGuildQueryStatement(Connection connection) throws SQLException { + + PreparedStatement outStatement = null; + String queryString = "SELECT * FROM `warehouse_guildhistory` WHERE `event_number` > ?"; + outStatement = connection.prepareStatement(queryString); + outStatement.setInt(1, WarehousePushThread.guildIndex); + return outStatement; + } + + void reset() { + + this.guild = null; + this.guildHash = null; + this.GLHash = null; + this.guildMotto = null; + this.charterName = null; + this.eventDatetime = null; + } + + public void release() { + this.reset(); + recordPool.add(this); + } + + public void write() { try (Connection connection = DbManager.getConnection(); PreparedStatement statement = this.buildGuildInsertStatement(connection)) { @@ -176,33 +171,33 @@ public class GuildRecord extends DataRecord { } - private PreparedStatement buildGuildInsertStatement(Connection connection) throws SQLException { + private PreparedStatement buildGuildInsertStatement(Connection connection) throws SQLException { - PreparedStatement outStatement = null; - String queryString = "INSERT INTO `warehouse_guildhistory` (`guild_id`, `guild_name`, `guild_motto`, `guild_founder`, `charter`, `bgicon`, `bgcoloura`, `bgcolourb`, `fgicon`, `fgcolour`, `eventtype`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)"; + PreparedStatement outStatement = null; + String queryString = "INSERT INTO `warehouse_guildhistory` (`guild_id`, `guild_name`, `guild_motto`, `guild_founder`, `charter`, `bgicon`, `bgcoloura`, `bgcolourb`, `fgicon`, `fgcolour`, `eventtype`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)"; - outStatement = connection.prepareStatement(queryString); + outStatement = connection.prepareStatement(queryString); - // Bind character data + // Bind character data - outStatement.setString(1, this.guildHash); - outStatement.setString(2, this.guildName); - outStatement.setString(3, this.guildMotto); - outStatement.setString(4, this.GLHash); - outStatement.setString(5, this.charterName); + outStatement.setString(1, this.guildHash); + outStatement.setString(2, this.guildName); + outStatement.setString(3, this.guildMotto); + outStatement.setString(4, this.GLHash); + outStatement.setString(5, this.charterName); - outStatement.setInt(6, this.bgIcon); - outStatement.setInt(7, this.bgColour1); - outStatement.setInt(8, this.bgColour2); - outStatement.setInt(9, this.fgIcon); - outStatement.setInt(10, this.fgColour); - outStatement.setString(11, this.eventType.name()); - outStatement.setTimestamp(12, new java.sql.Timestamp( this.eventDatetime.atZone(ZoneId.systemDefault()) - .toInstant().toEpochMilli())); + outStatement.setInt(6, this.bgIcon); + outStatement.setInt(7, this.bgColour1); + outStatement.setInt(8, this.bgColour2); + outStatement.setInt(9, this.fgIcon); + outStatement.setInt(10, this.fgColour); + outStatement.setString(11, this.eventType.name()); + outStatement.setTimestamp(12, new java.sql.Timestamp(this.eventDatetime.atZone(ZoneId.systemDefault()) + .toInstant().toEpochMilli())); + + return outStatement; + } - return outStatement; - } - // public static void InitializeGuildRecords(){ // GuildRecord.GuildRecordCache = DbManager.GuildQueries.GET_WAREHOUSE_GUILD_HISTORY(); // } diff --git a/src/engine/db/archive/MineRecord.java b/src/engine/db/archive/MineRecord.java index dbc236c0..25c151bd 100644 --- a/src/engine/db/archive/MineRecord.java +++ b/src/engine/db/archive/MineRecord.java @@ -47,8 +47,7 @@ public class MineRecord extends DataRecord { if (mineRecord == null) { mineRecord = new MineRecord(); mineRecord.eventType = eventType; - } - else { + } else { mineRecord.recordType = Enum.DataRecordType.MINE; mineRecord.eventType = eventType; } @@ -58,8 +57,7 @@ public class MineRecord extends DataRecord { if (character.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { player = (PlayerCharacter) character; mineRecord.charHash = player.getHash(); - } - else + } else mineRecord.charHash = character.getName(); DataWarehouse.hasher.encrypt(0); diff --git a/src/engine/db/archive/PvpRecord.java b/src/engine/db/archive/PvpRecord.java index 56734977..bfe3652e 100644 --- a/src/engine/db/archive/PvpRecord.java +++ b/src/engine/db/archive/PvpRecord.java @@ -28,286 +28,285 @@ import static engine.Enum.PvpHistoryType; public class PvpRecord extends DataRecord { - private static final LinkedBlockingQueue recordPool = new LinkedBlockingQueue<>(); + private static final LinkedBlockingQueue recordPool = new LinkedBlockingQueue<>(); - private PlayerCharacter player; - private PlayerCharacter victim; - private Vector3fImmutable location; - private boolean pvpExp; + private PlayerCharacter player; + private PlayerCharacter victim; + private Vector3fImmutable location; + private boolean pvpExp; - private PvpRecord(PlayerCharacter player, PlayerCharacter victim, Vector3fImmutable location, boolean pvpExp) { - this.recordType = DataRecordType.PVP; - this.player = player; - this.victim = victim; - this.location = new Vector3fImmutable(location); - this.pvpExp = pvpExp; - } + private PvpRecord(PlayerCharacter player, PlayerCharacter victim, Vector3fImmutable location, boolean pvpExp) { + this.recordType = DataRecordType.PVP; + this.player = player; + this.victim = victim; + this.location = new Vector3fImmutable(location); + this.pvpExp = pvpExp; + } - public static PvpRecord borrow(PlayerCharacter player, PlayerCharacter victim, Vector3fImmutable location, boolean pvpExp) { + public static PvpRecord borrow(PlayerCharacter player, PlayerCharacter victim, Vector3fImmutable location, boolean pvpExp) { - PvpRecord pvpRecord; + PvpRecord pvpRecord; - pvpRecord = recordPool.poll(); + pvpRecord = recordPool.poll(); - if (pvpRecord == null) { - pvpRecord = new PvpRecord(player, victim, location, pvpExp); - } - else { - pvpRecord.recordType = DataRecordType.PVP; - pvpRecord.player = player; - pvpRecord.victim = victim; - pvpRecord.location = new Vector3fImmutable(location); - pvpRecord.pvpExp = pvpExp; - } + if (pvpRecord == null) { + pvpRecord = new PvpRecord(player, victim, location, pvpExp); + } else { + pvpRecord.recordType = DataRecordType.PVP; + pvpRecord.player = player; + pvpRecord.victim = victim; + pvpRecord.location = new Vector3fImmutable(location); + pvpRecord.pvpExp = pvpExp; + } - return pvpRecord; - } + return pvpRecord; + } - private static PreparedStatement buildHistoryStatement(Connection connection, int charUUID, PvpHistoryType historyType) throws SQLException { + private static PreparedStatement buildHistoryStatement(Connection connection, int charUUID, PvpHistoryType historyType) throws SQLException { - PreparedStatement outStatement = null; - String queryString = ""; + PreparedStatement outStatement = null; + String queryString = ""; - switch (historyType) { - case KILLS: - queryString = "SELECT DISTINCT `victim_id`, `datetime` FROM warehouse_pvphistory where char_id = ? " + - "ORDER BY `datetime` DESC LIMIT 10"; - break; - case DEATHS: - queryString = "SELECT DISTINCT `char_id`,`datetime` FROM warehouse_pvphistory where `victim_id` = ? " + - "ORDER BY `datetime` DESC LIMIT 10"; - break; - } + switch (historyType) { + case KILLS: + queryString = "SELECT DISTINCT `victim_id`, `datetime` FROM warehouse_pvphistory where char_id = ? " + + "ORDER BY `datetime` DESC LIMIT 10"; + break; + case DEATHS: + queryString = "SELECT DISTINCT `char_id`,`datetime` FROM warehouse_pvphistory where `victim_id` = ? " + + "ORDER BY `datetime` DESC LIMIT 10"; + break; + } - outStatement = connection.prepareStatement(queryString); - outStatement.setString(1, DataWarehouse.hasher.encrypt(charUUID)); + outStatement = connection.prepareStatement(queryString); + outStatement.setString(1, DataWarehouse.hasher.encrypt(charUUID)); - return outStatement; - } + return outStatement; + } - public static LinkedList getCharacterPvPHistory(int charUUID, PvpHistoryType historyType) { + public static LinkedList getCharacterPvPHistory(int charUUID, PvpHistoryType historyType) { - // Member variable declaration + // Member variable declaration - LinkedList outList = new LinkedList<>(); + LinkedList outList = new LinkedList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement statement = buildHistoryStatement(connection, charUUID, historyType); - ResultSet rs = statement.executeQuery()) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = buildHistoryStatement(connection, charUUID, historyType); + ResultSet rs = statement.executeQuery()) { - while (rs.next()) { + while (rs.next()) { - switch (historyType) { - case KILLS: - outList.add((int) DataWarehouse.hasher.decrypt(rs.getString("victim_id"))[0]); - break; - case DEATHS: - outList.add((int) DataWarehouse.hasher.decrypt(rs.getString("char_id"))[0]); - break; - } - } - } catch (SQLException e) { - e.printStackTrace(); - } - return outList; - } + switch (historyType) { + case KILLS: + outList.add((int) DataWarehouse.hasher.decrypt(rs.getString("victim_id"))[0]); + break; + case DEATHS: + outList.add((int) DataWarehouse.hasher.decrypt(rs.getString("char_id"))[0]); + break; + } + } + } catch (SQLException e) { + e.printStackTrace(); + } + return outList; + } - private static PreparedStatement buildLuaHistoryQueryStatement(Connection connection, int charUUID) throws SQLException { + private static PreparedStatement buildLuaHistoryQueryStatement(Connection connection, int charUUID) throws SQLException { - PreparedStatement outStatement = null; - String queryString = "CALL `pvpHistory`(?)"; + PreparedStatement outStatement = null; + String queryString = "CALL `pvpHistory`(?)"; - outStatement = connection.prepareStatement(queryString); - outStatement.setString(1, DataWarehouse.hasher.encrypt(charUUID)); + outStatement = connection.prepareStatement(queryString); + outStatement.setString(1, DataWarehouse.hasher.encrypt(charUUID)); - return outStatement; - } + return outStatement; + } - public static String getPvpHistoryString(int charUUID) { + public static String getPvpHistoryString(int charUUID) { - String outString; - String dividerString; + String outString; + String dividerString; - String newLine = System.getProperty("line.separator"); + String newLine = System.getProperty("line.separator"); - outString = "[LUA_PVP() DATA WAREHOUSE]" + newLine; - dividerString = "--------------------------------" + newLine; + outString = "[LUA_PVP() DATA WAREHOUSE]" + newLine; + dividerString = "--------------------------------" + newLine; - try (Connection connection = DbManager.getConnection(); - PreparedStatement statement = buildLuaHistoryQueryStatement(connection, charUUID); - ResultSet rs = statement.executeQuery()) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = buildLuaHistoryQueryStatement(connection, charUUID); + ResultSet rs = statement.executeQuery()) { - while (rs.next()) { + while (rs.next()) { - int killCount; - int deathCount; - float killRatio; + int killCount; + int deathCount; + float killRatio; - outString += "Total Magicbane murdered souls: " + rs.getInt("TOTALDEATHS") + newLine; - outString += dividerString; - outString += String.format("%-8s %-8s %-8s %-8s %n", "Period", "Kills", "Deaths", "K/D"); - outString += dividerString; + outString += "Total Magicbane murdered souls: " + rs.getInt("TOTALDEATHS") + newLine; + outString += dividerString; + outString += String.format("%-8s %-8s %-8s %-8s %n", "Period", "Kills", "Deaths", "K/D"); + outString += dividerString; - killCount = rs.getInt("KILLCOUNT"); - deathCount = rs.getInt("DEATHCOUNT"); - - if (deathCount == 0) - killRatio = (float) killCount; - else - killRatio = (float) killCount / deathCount; + killCount = rs.getInt("KILLCOUNT"); + deathCount = rs.getInt("DEATHCOUNT"); + + if (deathCount == 0) + killRatio = (float) killCount; + else + killRatio = (float) killCount / deathCount; - try { - outString += String.format("%-8s %-8d %-8d %.2f %n", "Total", killCount, deathCount, killRatio); + try { + outString += String.format("%-8s %-8d %-8d %.2f %n", "Total", killCount, deathCount, killRatio); - killCount = rs.getInt("DAILYKILLS"); - deathCount = rs.getInt("DAILYDEATHS"); + killCount = rs.getInt("DAILYKILLS"); + deathCount = rs.getInt("DAILYDEATHS"); - if (deathCount == 0) - killRatio = (float) killCount; - else - killRatio = (float) killCount / deathCount; + if (deathCount == 0) + killRatio = (float) killCount; + else + killRatio = (float) killCount / deathCount; - outString += String.format("%-8s %-8d %-8d %.2f %n", "24hrs", killCount, deathCount, killRatio); + outString += String.format("%-8s %-8d %-8d %.2f %n", "24hrs", killCount, deathCount, killRatio); - killCount = rs.getInt("HOURLYKILLS"); - deathCount = rs.getInt("HOURLYDEATHS"); + killCount = rs.getInt("HOURLYKILLS"); + deathCount = rs.getInt("HOURLYDEATHS"); - if (deathCount == 0) - killRatio = (float) killCount; - else - killRatio = (float) killCount / deathCount; + if (deathCount == 0) + killRatio = (float) killCount; + else + killRatio = (float) killCount / deathCount; - outString += String.format("%-8s %-8d %-8d %.2f %n", "1hr", killCount, deathCount, killRatio); - } catch (Exception e) { - Logger.error(e.toString()); - } - } - } catch (SQLException e) { - e.printStackTrace(); - } + outString += String.format("%-8s %-8d %-8d %.2f %n", "1hr", killCount, deathCount, killRatio); + } catch (Exception e) { + Logger.error(e.toString()); + } + } + } catch (SQLException e) { + e.printStackTrace(); + } - return outString; - } + return outString; + } - public static PreparedStatement buildPvpPushStatement(Connection connection, ResultSet rs) throws SQLException { + public static PreparedStatement buildPvpPushStatement(Connection connection, ResultSet rs) throws SQLException { - PreparedStatement outStatement = null; - String queryString = "INSERT INTO `warehouse_pvphistory` (`event_number`, `char_id`, `char_guild_id`, `char_nation_id`, `char_level`," + - " `victim_id`, `victim_guild_id`, `victim_nation_id`, `victim_level`," + - " `zone_id`, `zone_name`, `loc_x`, `loc_y`, `gave_exp`, `datetime`) " + - " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + PreparedStatement outStatement = null; + String queryString = "INSERT INTO `warehouse_pvphistory` (`event_number`, `char_id`, `char_guild_id`, `char_nation_id`, `char_level`," + + " `victim_id`, `victim_guild_id`, `victim_nation_id`, `victim_level`," + + " `zone_id`, `zone_name`, `loc_x`, `loc_y`, `gave_exp`, `datetime`) " + + " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - outStatement = connection.prepareStatement(queryString); + outStatement = connection.prepareStatement(queryString); - // Bind record data + // Bind record data - outStatement.setInt(1, rs.getInt("event_number")); - outStatement.setString(2, rs.getString("char_id")); - outStatement.setString(3, rs.getString("char_guild_id")); - outStatement.setString(4, rs.getString("char_nation_id")); - outStatement.setInt(5, rs.getInt("char_level")); + outStatement.setInt(1, rs.getInt("event_number")); + outStatement.setString(2, rs.getString("char_id")); + outStatement.setString(3, rs.getString("char_guild_id")); + outStatement.setString(4, rs.getString("char_nation_id")); + outStatement.setInt(5, rs.getInt("char_level")); - // Bind victim data + // Bind victim data - outStatement.setString(6, rs.getString("victim_id")); - outStatement.setString(7, rs.getString("victim_guild_id")); - outStatement.setString(8, rs.getString("victim_nation_id")); - outStatement.setInt(9, rs.getInt("victim_level")); + outStatement.setString(6, rs.getString("victim_id")); + outStatement.setString(7, rs.getString("victim_guild_id")); + outStatement.setString(8, rs.getString("victim_nation_id")); + outStatement.setInt(9, rs.getInt("victim_level")); - outStatement.setString(10, rs.getString("zone_id")); - outStatement.setString(11, rs.getString("zone_name")); - outStatement.setFloat(12, rs.getFloat("loc_x")); - outStatement.setFloat(13, rs.getFloat("loc_y")); - outStatement.setBoolean(14, rs.getBoolean("gave_exp")); - outStatement.setTimestamp(15, rs.getTimestamp("datetime")); + outStatement.setString(10, rs.getString("zone_id")); + outStatement.setString(11, rs.getString("zone_name")); + outStatement.setFloat(12, rs.getFloat("loc_x")); + outStatement.setFloat(13, rs.getFloat("loc_y")); + outStatement.setBoolean(14, rs.getBoolean("gave_exp")); + outStatement.setTimestamp(15, rs.getTimestamp("datetime")); - return outStatement; - } + return outStatement; + } - public static PreparedStatement buildPvpQueryStatement(Connection connection) throws SQLException { + public static PreparedStatement buildPvpQueryStatement(Connection connection) throws SQLException { - PreparedStatement outStatement = null; - String queryString = "SELECT * FROM `warehouse_pvphistory` WHERE `event_number` > ?"; - outStatement = connection.prepareStatement(queryString); - outStatement.setInt(1, WarehousePushThread.pvpIndex); - return outStatement; - } + PreparedStatement outStatement = null; + String queryString = "SELECT * FROM `warehouse_pvphistory` WHERE `event_number` > ?"; + outStatement = connection.prepareStatement(queryString); + outStatement.setInt(1, WarehousePushThread.pvpIndex); + return outStatement; + } - void reset() { - this.player = null; - this.victim = null; - this.location = Vector3fImmutable.ZERO; - pvpExp = false; - } + void reset() { + this.player = null; + this.victim = null; + this.location = Vector3fImmutable.ZERO; + pvpExp = false; + } - public void release() { - this.reset(); - recordPool.add(this); - } + public void release() { + this.reset(); + recordPool.add(this); + } - private PreparedStatement buildPvPInsertStatement(Connection connection) throws SQLException { + private PreparedStatement buildPvPInsertStatement(Connection connection) throws SQLException { - Guild charGuild; - Guild victimGuild; - Zone zone; - PreparedStatement outStatement = null; + Guild charGuild; + Guild victimGuild; + Zone zone; + PreparedStatement outStatement = null; - String queryString = "INSERT INTO `warehouse_pvphistory` (`char_id`, `char_guild_id`, `char_nation_id`, `char_level`," + - " `victim_id`, `victim_guild_id`, `victim_nation_id`, `victim_level`," + - " `zone_id`, `zone_name`, `loc_x`, `loc_y`, `gave_exp`, `datetime`) " + - " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + String queryString = "INSERT INTO `warehouse_pvphistory` (`char_id`, `char_guild_id`, `char_nation_id`, `char_level`," + + " `victim_id`, `victim_guild_id`, `victim_nation_id`, `victim_level`," + + " `zone_id`, `zone_name`, `loc_x`, `loc_y`, `gave_exp`, `datetime`) " + + " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - outStatement = connection.prepareStatement(queryString); + outStatement = connection.prepareStatement(queryString); - charGuild = this.player.getGuild(); - victimGuild = this.victim.getGuild(); + charGuild = this.player.getGuild(); + victimGuild = this.victim.getGuild(); - // Use a proxy in the situation where a char guild is null (errant) + // Use a proxy in the situation where a char guild is null (errant) - - // Retrieve the zone name where the PvP event occurred - zone = ZoneManager.findSmallestZone(this.location); + // Retrieve the zone name where the PvP event occurred - outStatement.setString(1, DataWarehouse.hasher.encrypt(this.player.getObjectUUID())); - outStatement.setString(2, DataWarehouse.hasher.encrypt(charGuild.getObjectUUID())); - outStatement.setString(3, DataWarehouse.hasher.encrypt(charGuild.getNation().getObjectUUID())); - outStatement.setInt(4, this.player.getLevel()); + zone = ZoneManager.findSmallestZone(this.location); - // Bind victim data + outStatement.setString(1, DataWarehouse.hasher.encrypt(this.player.getObjectUUID())); + outStatement.setString(2, DataWarehouse.hasher.encrypt(charGuild.getObjectUUID())); + outStatement.setString(3, DataWarehouse.hasher.encrypt(charGuild.getNation().getObjectUUID())); + outStatement.setInt(4, this.player.getLevel()); - outStatement.setString(5, DataWarehouse.hasher.encrypt(this.victim.getObjectUUID())); - outStatement.setString(6, DataWarehouse.hasher.encrypt(victimGuild.getObjectUUID())); - outStatement.setString(7, DataWarehouse.hasher.encrypt(victimGuild.getNation().getObjectUUID())); - outStatement.setInt(8, this.victim.getLevel()); + // Bind victim data - outStatement.setString(9, DataWarehouse.hasher.encrypt(zone.getObjectUUID())); - outStatement.setString(10, zone.getName()); - outStatement.setFloat(11, this.location.getX()); - outStatement.setFloat(12, -this.location.getZ()); // flip sign on 'y' coordinate - outStatement.setBoolean(13, this.pvpExp); - outStatement.setTimestamp(14, Timestamp.valueOf(LocalDateTime.now())); + outStatement.setString(5, DataWarehouse.hasher.encrypt(this.victim.getObjectUUID())); + outStatement.setString(6, DataWarehouse.hasher.encrypt(victimGuild.getObjectUUID())); + outStatement.setString(7, DataWarehouse.hasher.encrypt(victimGuild.getNation().getObjectUUID())); + outStatement.setInt(8, this.victim.getLevel()); - return outStatement; - } + outStatement.setString(9, DataWarehouse.hasher.encrypt(zone.getObjectUUID())); + outStatement.setString(10, zone.getName()); + outStatement.setFloat(11, this.location.getX()); + outStatement.setFloat(12, -this.location.getZ()); // flip sign on 'y' coordinate + outStatement.setBoolean(13, this.pvpExp); + outStatement.setTimestamp(14, Timestamp.valueOf(LocalDateTime.now())); + return outStatement; + } - public void write() { - try (Connection connection = DbManager.getConnection(); - PreparedStatement statement = buildPvPInsertStatement(connection)) { + public void write() { - statement.execute(); + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = buildPvPInsertStatement(connection)) { - } catch (SQLException e) { - Logger.error(e.toString()); - } + statement.execute(); - // Warehouse record for this pvp event written if code path reaches here. - // Time to update the respective kill counters. + } catch (SQLException e) { + Logger.error(e.toString()); + } - CharacterRecord.advanceKillCounter(this.player); - CharacterRecord.advanceDeathCounter(this.victim); + // Warehouse record for this pvp event written if code path reaches here. + // Time to update the respective kill counters. - } + CharacterRecord.advanceKillCounter(this.player); + CharacterRecord.advanceDeathCounter(this.victim); + + } } diff --git a/src/engine/db/archive/RealmRecord.java b/src/engine/db/archive/RealmRecord.java index 957858e5..b93ed553 100644 --- a/src/engine/db/archive/RealmRecord.java +++ b/src/engine/db/archive/RealmRecord.java @@ -44,8 +44,7 @@ public class RealmRecord extends DataRecord { if (realmRecord == null) { realmRecord = new RealmRecord(realm); realmRecord.eventType = eventType; - } - else { + } else { realmRecord.recordType = Enum.DataRecordType.REALM; realmRecord.eventType = eventType; realmRecord.realm = realm; @@ -57,7 +56,7 @@ public class RealmRecord extends DataRecord { realmRecord.charterType = Enum.CharterType.getCharterTypeByID(realmRecord.realm.getCharterType()).name(); if (realmRecord.eventType.equals(Enum.RecordEventType.CAPTURE)) - realmRecord.eventDateTime = realm.ruledSince; + realmRecord.eventDateTime = realm.ruledSince; else realmRecord.eventDateTime = LocalDateTime.now(); @@ -122,7 +121,7 @@ public class RealmRecord extends DataRecord { outStatement.setString(4, cityHash); outStatement.setString(5, guildHash); outStatement.setString(6, eventType.name()); - outStatement.setTimestamp(7, Timestamp.valueOf(this.eventDateTime)); + outStatement.setTimestamp(7, Timestamp.valueOf(this.eventDateTime)); return outStatement; } diff --git a/src/engine/db/handlers/dbBoonHandler.java b/src/engine/db/handlers/dbBoonHandler.java index 02951d4a..3c16ca82 100644 --- a/src/engine/db/handlers/dbBoonHandler.java +++ b/src/engine/db/handlers/dbBoonHandler.java @@ -21,31 +21,31 @@ import java.util.ArrayList; public class dbBoonHandler extends dbHandlerBase { - public dbBoonHandler() { - } + public dbBoonHandler() { + } - public ArrayList GET_BOON_AMOUNTS_FOR_ITEMBASE(int itemBaseUUID) { + public ArrayList GET_BOON_AMOUNTS_FOR_ITEMBASE(int itemBaseUUID) { - ArrayList boons = new ArrayList<>(); - Boon thisBoon; + ArrayList boons = new ArrayList<>(); + Boon thisBoon; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_item_boons` WHERE `itemBaseID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_item_boons` WHERE `itemBaseID` = ?")) { - preparedStatement.setInt(1, itemBaseUUID); + preparedStatement.setInt(1, itemBaseUUID); - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { - thisBoon = new Boon(rs); - boons.add(thisBoon); - } + while (rs.next()) { + thisBoon = new Boon(rs); + boons.add(thisBoon); + } - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return boons; - } + return boons; + } } diff --git a/src/engine/db/handlers/dbCSSessionHandler.java b/src/engine/db/handlers/dbCSSessionHandler.java index ae6cc04f..5516c733 100644 --- a/src/engine/db/handlers/dbCSSessionHandler.java +++ b/src/engine/db/handlers/dbCSSessionHandler.java @@ -24,91 +24,91 @@ import java.sql.SQLException; public class dbCSSessionHandler extends dbHandlerBase { - public dbCSSessionHandler() { - this.localClass = CSSession.class; - this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } + public dbCSSessionHandler() { + this.localClass = CSSession.class; + this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); + } - public boolean ADD_CSSESSION(String secKey, Account acc, InetAddress inet, String machineID) { + public boolean ADD_CSSESSION(String secKey, Account acc, InetAddress inet, String machineID) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_session` (`secretKey`, `accountID`, `discordAccount`, `sessionIP`, machineID) VALUES (?,?,?,INET_ATON(?),?)")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_session` (`secretKey`, `accountID`, `discordAccount`, `sessionIP`, machineID) VALUES (?,?,?,INET_ATON(?),?)")) { - preparedStatement.setString(1, secKey); - preparedStatement.setLong(2, acc.getObjectUUID()); - preparedStatement.setString(3, acc.discordAccount); - preparedStatement.setString(4, StringUtils.InetAddressToClientString(inet)); - preparedStatement.setString(5, machineID); + preparedStatement.setString(1, secKey); + preparedStatement.setLong(2, acc.getObjectUUID()); + preparedStatement.setString(3, acc.discordAccount); + preparedStatement.setString(4, StringUtils.InetAddressToClientString(inet)); + preparedStatement.setString(5, machineID); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean DELETE_UNUSED_CSSESSION(String secKey) { + public boolean DELETE_UNUSED_CSSESSION(String secKey) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_session` WHERE `secretKey`=? && `characterID` IS NULL")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_session` WHERE `secretKey`=? && `characterID` IS NULL")) { - preparedStatement.setString(1, secKey); - return (preparedStatement.executeUpdate() > 0); + preparedStatement.setString(1, secKey); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean DELETE_CSSESSION(String secKey) { + public boolean DELETE_CSSESSION(String secKey) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_session` WHERE `secretKey`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_session` WHERE `secretKey`=?")) { - preparedStatement.setString(1, secKey); - return (preparedStatement.executeUpdate() > 0); + preparedStatement.setString(1, secKey); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean UPDATE_CSSESSION(String secKey, int charID) { + public boolean UPDATE_CSSESSION(String secKey, int charID) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_session` SET `characterID`=? WHERE `secretKey`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_session` SET `characterID`=? WHERE `secretKey`=?")) { - preparedStatement.setInt(1, charID); - preparedStatement.setString(2, secKey); + preparedStatement.setInt(1, charID); + preparedStatement.setString(2, secKey); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public CSSession GET_CSSESSION(String secKey) { + public CSSession GET_CSSESSION(String secKey) { - CSSession css = null; + CSSession css = null; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `accountID`, `characterID`, `machineID` FROM `dyn_session` WHERE `secretKey`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `accountID`, `characterID`, `machineID` FROM `dyn_session` WHERE `secretKey`=?")) { - preparedStatement.setString(1, secKey); - ResultSet rs = preparedStatement.executeQuery(); + preparedStatement.setString(1, secKey); + 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")); + if (rs.next()) + css = new CSSession(secKey, DbManager.AccountQueries.GET_ACCOUNT(rs.getInt("accountID")), PlayerCharacter.getPlayerCharacter(rs.getInt("characterID")), rs.getString("machineID")); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return css; - } + return css; + } } diff --git a/src/engine/db/handlers/dbCharacterSkillHandler.java b/src/engine/db/handlers/dbCharacterSkillHandler.java index beb9b5bf..49e88952 100644 --- a/src/engine/db/handlers/dbCharacterSkillHandler.java +++ b/src/engine/db/handlers/dbCharacterSkillHandler.java @@ -22,152 +22,152 @@ import java.util.concurrent.ConcurrentHashMap; public class dbCharacterSkillHandler extends dbHandlerBase { - public dbCharacterSkillHandler() { - this.localClass = CharacterSkill.class; - this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } + public dbCharacterSkillHandler() { + this.localClass = CharacterSkill.class; + this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); + } - public CharacterSkill ADD_SKILL(CharacterSkill toAdd) { + public CharacterSkill ADD_SKILL(CharacterSkill toAdd) { - CharacterSkill characterSkill = null; + CharacterSkill characterSkill = null; - if (CharacterSkill.GetOwner(toAdd) == null || toAdd.getSkillsBase() == null) { - Logger.error("dbCharacterSkillHandler.ADD_SKILL", toAdd.getObjectUUID() + " missing owner or skillsBase"); - return null; - } + if (CharacterSkill.GetOwner(toAdd) == null || toAdd.getSkillsBase() == null) { + Logger.error("dbCharacterSkillHandler.ADD_SKILL", toAdd.getObjectUUID() + " missing owner or skillsBase"); + return null; + } - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_skill` (`CharacterID`, `skillsBaseID`, `trains`) VALUES (?, ?, ?);", Statement.RETURN_GENERATED_KEYS)) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_skill` (`CharacterID`, `skillsBaseID`, `trains`) VALUES (?, ?, ?);", Statement.RETURN_GENERATED_KEYS)) { - preparedStatement.setLong(1, CharacterSkill.GetOwner(toAdd).getObjectUUID()); - preparedStatement.setInt(2, toAdd.getSkillsBase().getObjectUUID()); - preparedStatement.setInt(3, toAdd.getNumTrains()); + preparedStatement.setLong(1, CharacterSkill.GetOwner(toAdd).getObjectUUID()); + preparedStatement.setInt(2, toAdd.getSkillsBase().getObjectUUID()); + preparedStatement.setInt(3, toAdd.getNumTrains()); - preparedStatement.executeUpdate(); - ResultSet rs = preparedStatement.getGeneratedKeys(); + preparedStatement.executeUpdate(); + ResultSet rs = preparedStatement.getGeneratedKeys(); - if (rs.next()) - characterSkill = GET_SKILL(rs.getInt(1)); + if (rs.next()) + characterSkill = GET_SKILL(rs.getInt(1)); - } catch (SQLException e) { - Logger.error(e); - } - return characterSkill; - } + } catch (SQLException e) { + Logger.error(e); + } + return characterSkill; + } - public boolean DELETE_SKILL(final int objectUUID) { + public boolean DELETE_SKILL(final int objectUUID) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_skill` WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_skill` WHERE `UID` = ?")) { - preparedStatement.setLong(1, objectUUID); + preparedStatement.setLong(1, objectUUID); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public CharacterSkill GET_SKILL(final int objectUUID) { + public CharacterSkill GET_SKILL(final int objectUUID) { - CharacterSkill characterSkill = (CharacterSkill) DbManager.getFromCache(Enum.GameObjectType.CharacterSkill, objectUUID); + CharacterSkill characterSkill = (CharacterSkill) DbManager.getFromCache(Enum.GameObjectType.CharacterSkill, objectUUID); - if (characterSkill != null) - return characterSkill; + if (characterSkill != null) + return characterSkill; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_skill` WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_skill` WHERE `UID` = ?")) { - preparedStatement.setInt(1, objectUUID); - ResultSet rs = preparedStatement.executeQuery(); + preparedStatement.setInt(1, objectUUID); + ResultSet rs = preparedStatement.executeQuery(); - characterSkill = (CharacterSkill) getObjectFromRs(rs); + characterSkill = (CharacterSkill) getObjectFromRs(rs); - } catch (SQLException e) { - Logger.error(e); - } - return characterSkill; - } + } catch (SQLException e) { + Logger.error(e); + } + return characterSkill; + } - public ConcurrentHashMap GET_SKILLS_FOR_CHARACTER(final AbstractCharacter ac) { + public ConcurrentHashMap GET_SKILLS_FOR_CHARACTER(final AbstractCharacter ac) { - ConcurrentHashMap characterSkills = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + ConcurrentHashMap characterSkills = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - if (ac == null || (!(ac.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)))) - return characterSkills; + if (ac == null || (!(ac.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)))) + return characterSkills; - PlayerCharacter playerCharacter = (PlayerCharacter) ac; - int characterId = playerCharacter.getObjectUUID(); + PlayerCharacter playerCharacter = (PlayerCharacter) ac; + int characterId = playerCharacter.getObjectUUID(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_skill` WHERE `CharacterID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_skill` WHERE `CharacterID` = ?")) { - preparedStatement.setInt(1, characterId); + preparedStatement.setInt(1, characterId); - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { - CharacterSkill cs = new CharacterSkill(rs, playerCharacter); - if (cs.getSkillsBase() != null) - characterSkills.put(cs.getSkillsBase().getName(), cs); - } + while (rs.next()) { + CharacterSkill cs = new CharacterSkill(rs, playerCharacter); + if (cs.getSkillsBase() != null) + characterSkills.put(cs.getSkillsBase().getName(), cs); + } - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return characterSkills; - } + return characterSkills; + } - public void UPDATE_TRAINS(final CharacterSkill characterSkill) { + public void UPDATE_TRAINS(final CharacterSkill characterSkill) { - if (!characterSkill.isTrained()) - return; + if (!characterSkill.isTrained()) + return; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_skill` SET `trains`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_skill` SET `trains`=? WHERE `UID` = ?")) { - preparedStatement.setShort(1, (short) characterSkill.getNumTrains()); - preparedStatement.setLong(2, characterSkill.getObjectUUID()); + preparedStatement.setShort(1, (short) characterSkill.getNumTrains()); + preparedStatement.setLong(2, characterSkill.getObjectUUID()); - if (preparedStatement.executeUpdate() != 0) - characterSkill.syncTrains(); + if (preparedStatement.executeUpdate() != 0) + characterSkill.syncTrains(); - } catch (SQLException e) { - Logger.error(e); - } - } + } catch (SQLException e) { + Logger.error(e); + } + } - public void updateDatabase(final CharacterSkill characterSkill) { + public void updateDatabase(final CharacterSkill characterSkill) { - if (characterSkill.getSkillsBase() == null) { - Logger.error("Failed to find skillsBase for Skill " + characterSkill.getObjectUUID()); - return; - } + if (characterSkill.getSkillsBase() == null) { + Logger.error("Failed to find skillsBase for Skill " + characterSkill.getObjectUUID()); + return; + } - if (CharacterSkill.GetOwner(characterSkill) == null) { - Logger.error("Failed to find owner for Skill " + characterSkill.getObjectUUID()); - return; - } + if (CharacterSkill.GetOwner(characterSkill) == null) { + Logger.error("Failed to find owner for Skill " + characterSkill.getObjectUUID()); + return; + } - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_skill` SET `skillsBaseID`=?, `CharacterID`=?, `trains`=? WHERE `UID`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_skill` SET `skillsBaseID`=?, `CharacterID`=?, `trains`=? WHERE `UID`=?")) { - preparedStatement.setInt(1, characterSkill.getSkillsBase().getObjectUUID()); - preparedStatement.setInt(2, CharacterSkill.GetOwner(characterSkill).getObjectUUID()); - preparedStatement.setShort(3, (short) characterSkill.getNumTrains()); - preparedStatement.setLong(4, characterSkill.getObjectUUID()); + preparedStatement.setInt(1, characterSkill.getSkillsBase().getObjectUUID()); + preparedStatement.setInt(2, CharacterSkill.GetOwner(characterSkill).getObjectUUID()); + preparedStatement.setShort(3, (short) characterSkill.getNumTrains()); + preparedStatement.setLong(4, characterSkill.getObjectUUID()); - if (preparedStatement.executeUpdate() != 0) - characterSkill.syncTrains(); + if (preparedStatement.executeUpdate() != 0) + characterSkill.syncTrains(); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - } + } } diff --git a/src/engine/db/handlers/dbContractHandler.java b/src/engine/db/handlers/dbContractHandler.java index 7f543cd3..323b349d 100644 --- a/src/engine/db/handlers/dbContractHandler.java +++ b/src/engine/db/handlers/dbContractHandler.java @@ -23,146 +23,146 @@ import java.sql.SQLException; public class dbContractHandler extends dbHandlerBase { - public dbContractHandler() { - this.localClass = Contract.class; - this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } + public dbContractHandler() { + this.localClass = Contract.class; + this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); + } - public Contract GET_CONTRACT(final int objectUUID) { + public Contract GET_CONTRACT(final int objectUUID) { - Contract contract = (Contract) DbManager.getFromCache(Enum.GameObjectType.Contract, objectUUID); + Contract contract = (Contract) DbManager.getFromCache(Enum.GameObjectType.Contract, objectUUID); - if (contract != null) - return contract; + if (contract != null) + return contract; - if (objectUUID == 0) - return null; + if (objectUUID == 0) + return null; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_contract` WHERE `ID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_contract` WHERE `ID` = ?")) { - preparedStatement.setInt(1, objectUUID); + preparedStatement.setInt(1, objectUUID); - ResultSet rs = preparedStatement.executeQuery(); - contract = (Contract) getObjectFromRs(rs); + ResultSet rs = preparedStatement.executeQuery(); + contract = (Contract) getObjectFromRs(rs); - } catch (SQLException e) { - Logger.error(e); - } - return contract; - } + } catch (SQLException e) { + Logger.error(e); + } + return contract; + } - public void LOAD_CONTRACT_INVENTORY(final Contract contract) { + public void LOAD_CONTRACT_INVENTORY(final Contract contract) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_inventoryset` WHERE `inventorySet` = ?;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_inventoryset` WHERE `inventorySet` = ?;")) { - preparedStatement.setInt(1, contract.inventorySet); + preparedStatement.setInt(1, contract.inventorySet); - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { + while (rs.next()) { - //handle item base - int itemBaseID = rs.getInt("itembaseID"); + //handle item base + int itemBaseID = rs.getInt("itembaseID"); - ItemBase ib = ItemBase.getItemBase(itemBaseID); + ItemBase ib = ItemBase.getItemBase(itemBaseID); - if (ib != null) { + if (ib != null) { - MobEquipment me = new MobEquipment(ib, 0, 0); - contract.getSellInventory().add(me); + MobEquipment me = new MobEquipment(ib, 0, 0); + contract.getSellInventory().add(me); - //handle magic effects - String prefix = rs.getString("prefix"); - int pRank = rs.getInt("pRank"); - String suffix = rs.getString("suffix"); - int sRank = rs.getInt("sRank"); + //handle magic effects + String prefix = rs.getString("prefix"); + int pRank = rs.getInt("pRank"); + String suffix = rs.getString("suffix"); + int sRank = rs.getInt("sRank"); - if (prefix != null) { - me.setPrefix(prefix, pRank); - me.setIsID(true); - } + if (prefix != null) { + me.setPrefix(prefix, pRank); + me.setIsID(true); + } - if (suffix != null) { - me.setSuffix(suffix, sRank); - me.setIsID(true); - } + if (suffix != null) { + me.setSuffix(suffix, sRank); + me.setIsID(true); + } - } - } - } catch (SQLException e) { - Logger.error(e); - } - } + } + } + } catch (SQLException e) { + Logger.error(e); + } + } - public void LOAD_SELL_LIST_FOR_CONTRACT(final Contract contract) { + public void LOAD_SELL_LIST_FOR_CONTRACT(final Contract contract) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_contract_selltype` WHERE `contractID` = ?;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_contract_selltype` WHERE `contractID` = ?;")) { - preparedStatement.setInt(1, contract.getObjectUUID()); + preparedStatement.setInt(1, contract.getObjectUUID()); - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { + while (rs.next()) { - int type = rs.getInt("type"); - int value = rs.getInt("value"); + int type = rs.getInt("type"); + int value = rs.getInt("value"); - switch (type) { - case 1: - contract.getBuyItemType().add(value); - break; - case 2: - contract.getBuySkillToken().add(value); - break; - case 3: - contract.getBuyUnknownToken().add(value); - break; - } - } - } catch (SQLException e) { - Logger.error(e); - } - } + switch (type) { + case 1: + contract.getBuyItemType().add(value); + break; + case 2: + contract.getBuySkillToken().add(value); + break; + case 3: + contract.getBuyUnknownToken().add(value); + break; + } + } + } catch (SQLException e) { + Logger.error(e); + } + } - public boolean updateAllowedBuildings(final Contract con, final long slotbitvalue) { + public boolean updateAllowedBuildings(final Contract con, final long slotbitvalue) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_npc_contract` SET `allowedBuildingTypeID`=? WHERE `contractID`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_npc_contract` SET `allowedBuildingTypeID`=? WHERE `contractID`=?")) { - preparedStatement.setLong(1, slotbitvalue); - preparedStatement.setInt(2, con.getContractID()); + preparedStatement.setLong(1, slotbitvalue); + preparedStatement.setInt(2, con.getContractID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateDatabase(final Contract con) { + public boolean updateDatabase(final Contract con) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_npc_contract` SET `contractID`=?, `name`=?, " - + "`mobbaseID`=?, `classID`=?, vendorDialog=?, iconID=?, allowedBuildingTypeID=? WHERE `ID`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_npc_contract` SET `contractID`=?, `name`=?, " + + "`mobbaseID`=?, `classID`=?, vendorDialog=?, iconID=?, allowedBuildingTypeID=? WHERE `ID`=?")) { - preparedStatement.setInt(1, con.getContractID()); - preparedStatement.setString(2, con.getName()); - preparedStatement.setInt(3, con.getMobbaseID()); - preparedStatement.setInt(4, con.getClassID()); - preparedStatement.setInt(5, (con.getVendorDialog() != null) ? con.getVendorDialog().getObjectUUID() : 0); - preparedStatement.setInt(6, con.getIconID()); - preparedStatement.setInt(8, con.getObjectUUID()); - preparedStatement.setLong(7, con.getAllowedBuildings().toLong()); + preparedStatement.setInt(1, con.getContractID()); + preparedStatement.setString(2, con.getName()); + preparedStatement.setInt(3, con.getMobbaseID()); + preparedStatement.setInt(4, con.getClassID()); + preparedStatement.setInt(5, (con.getVendorDialog() != null) ? con.getVendorDialog().getObjectUUID() : 0); + preparedStatement.setInt(6, con.getIconID()); + preparedStatement.setInt(8, con.getObjectUUID()); + preparedStatement.setLong(7, con.getAllowedBuildings().toLong()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } } diff --git a/src/engine/db/handlers/dbEffectsBaseHandler.java b/src/engine/db/handlers/dbEffectsBaseHandler.java index de60587c..4836ec6e 100644 --- a/src/engine/db/handlers/dbEffectsBaseHandler.java +++ b/src/engine/db/handlers/dbEffectsBaseHandler.java @@ -27,277 +27,277 @@ public class dbEffectsBaseHandler extends dbHandlerBase { public dbEffectsBaseHandler() { - } + } - public static ArrayList getAllEffectsBase() { + public static ArrayList getAllEffectsBase() { - ArrayList effectList = new ArrayList<>(); + ArrayList effectList = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement prepareStatement = connection.prepareStatement("SELECT * FROM static_power_effectbase ORDER BY `IDString` DESC")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement prepareStatement = connection.prepareStatement("SELECT * FROM static_power_effectbase ORDER BY `IDString` DESC")) { - ResultSet rs = prepareStatement.executeQuery(); + ResultSet rs = prepareStatement.executeQuery(); - while (rs.next()) { - EffectsBase effectBase = new EffectsBase(rs); - effectList.add(effectBase); - } - } catch (SQLException e) { - Logger.error(e.toString()); - } + while (rs.next()) { + EffectsBase effectBase = new EffectsBase(rs); + effectList.add(effectBase); + } + } catch (SQLException e) { + Logger.error(e.toString()); + } - return effectList; - } + return effectList; + } - public static void cacheAllEffectModifiers() { + public static void cacheAllEffectModifiers() { - String IDString; - AbstractEffectModifier abstractEffectModifier = null; + String IDString; + AbstractEffectModifier abstractEffectModifier = null; - try (Connection connection = DbManager.getConnection(); - PreparedStatement prepareStatement = connection.prepareStatement("SELECT * FROM static_power_effectmod")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement prepareStatement = connection.prepareStatement("SELECT * FROM static_power_effectmod")) { - ResultSet rs = prepareStatement.executeQuery(); + ResultSet rs = prepareStatement.executeQuery(); - while (rs.next()) { + while (rs.next()) { - IDString = rs.getString("IDString"); - EffectsBase effectBase = PowersManager.getEffectByIDString(IDString); - Enum.ModType modifier = Enum.ModType.GetModType(rs.getString("modType")); + IDString = rs.getString("IDString"); + EffectsBase effectBase = PowersManager.getEffectByIDString(IDString); + Enum.ModType modifier = Enum.ModType.GetModType(rs.getString("modType")); - //combine item prefix and suffix effect modifiers + //combine item prefix and suffix effect modifiers - abstractEffectModifier = getCombinedModifiers(abstractEffectModifier, rs, effectBase, modifier); + abstractEffectModifier = getCombinedModifiers(abstractEffectModifier, rs, effectBase, modifier); - if (abstractEffectModifier != null) { + if (abstractEffectModifier != null) { - if (EffectsBase.modifiersMap.containsKey(effectBase.getIDString()) == false) - EffectsBase.modifiersMap.put(effectBase.getIDString(), new HashSet<>()); + if (EffectsBase.modifiersMap.containsKey(effectBase.getIDString()) == false) + EffectsBase.modifiersMap.put(effectBase.getIDString(), new HashSet<>()); - EffectsBase.modifiersMap.get(effectBase.getIDString()).add(abstractEffectModifier); + EffectsBase.modifiersMap.get(effectBase.getIDString()).add(abstractEffectModifier); - } + } - } + } - } catch (Exception e) { - Logger.error(e); - } + } catch (Exception e) { + Logger.error(e); + } - } + } - private static AbstractEffectModifier getCombinedModifiers(AbstractEffectModifier abstractEffectModifier, ResultSet rs, EffectsBase effectBase, Enum.ModType modifier) throws SQLException { - switch (modifier) { - case AdjustAboveDmgCap: - abstractEffectModifier = new AdjustAboveDmgCapEffectModifier(rs); - break; - case Ambidexterity: - abstractEffectModifier = new AmbidexterityEffectModifier(rs); - break; - case AnimOverride: - break; - case ArmorPiercing: - abstractEffectModifier = new ArmorPiercingEffectModifier(rs); - break; - case AttackDelay: - abstractEffectModifier = new AttackDelayEffectModifier(rs); - break; - case Attr: - abstractEffectModifier = new AttributeEffectModifier(rs); - break; - case BlackMantle: - abstractEffectModifier = new BlackMantleEffectModifier(rs); - break; - case BladeTrails: - abstractEffectModifier = new BladeTrailsEffectModifier(rs); - break; - case Block: - abstractEffectModifier = new BlockEffectModifier(rs); - break; - case BlockedPowerType: - abstractEffectModifier = new BlockedPowerTypeEffectModifier(rs); - break; - case CannotAttack: - abstractEffectModifier = new CannotAttackEffectModifier(rs); - break; - case CannotCast: - abstractEffectModifier = new CannotCastEffectModifier(rs); - break; - case CannotMove: - abstractEffectModifier = new CannotMoveEffectModifier(rs); - break; - case CannotTrack: - abstractEffectModifier = new CannotTrackEffectModifier(rs); - break; - case Charmed: - abstractEffectModifier = new CharmedEffectModifier(rs); - break; - case ConstrainedAmbidexterity: - abstractEffectModifier = new ConstrainedAmbidexterityEffectModifier(rs); - break; - case DamageCap: - abstractEffectModifier = new DamageCapEffectModifier(rs); - break; - case DamageShield: - abstractEffectModifier = new DamageShieldEffectModifier(rs); - break; - case DCV: - abstractEffectModifier = new DCVEffectModifier(rs); - break; - case Dodge: - abstractEffectModifier = new DodgeEffectModifier(rs); - break; - case DR: - abstractEffectModifier = new DREffectModifier(rs); - break; - case Durability: - abstractEffectModifier = new DurabilityEffectModifier(rs); - break; - case ExclusiveDamageCap: - abstractEffectModifier = new ExclusiveDamageCapEffectModifier(rs); - break; - case Fade: - abstractEffectModifier = new FadeEffectModifier(rs); - break; - case Fly: - abstractEffectModifier = new FlyEffectModifier(rs); - break; - case Health: - abstractEffectModifier = new HealthEffectModifier(rs); - break; - case HealthFull: - abstractEffectModifier = new HealthFullEffectModifier(rs); - break; - case HealthRecoverRate: - abstractEffectModifier = new HealthRecoverRateEffectModifier(rs); - break; - case IgnoreDamageCap: - abstractEffectModifier = new IgnoreDamageCapEffectModifier(rs); - break; - case IgnorePassiveDefense: - abstractEffectModifier = new IgnorePassiveDefenseEffectModifier(rs); - break; - case ImmuneTo: - abstractEffectModifier = new ImmuneToEffectModifier(rs); - break; - case ImmuneToAttack: - abstractEffectModifier = new ImmuneToAttackEffectModifier(rs); - break; - case ImmuneToPowers: - abstractEffectModifier = new ImmuneToPowersEffectModifier(rs); - break; - case Invisible: - abstractEffectModifier = new InvisibleEffectModifier(rs); - break; - case ItemName: - abstractEffectModifier = new ItemNameEffectModifier(rs); - if (((ItemNameEffectModifier) abstractEffectModifier).name.isEmpty()) - break; - if (effectBase != null) - effectBase.setName((((ItemNameEffectModifier) abstractEffectModifier).name)); - break; - case Mana: - abstractEffectModifier = new ManaEffectModifier(rs); - break; - case ManaFull: - abstractEffectModifier = new ManaFullEffectModifier(rs); - break; - case ManaRecoverRate: - abstractEffectModifier = new ManaRecoverRateEffectModifier(rs); - break; - case MaxDamage: - abstractEffectModifier = new MaxDamageEffectModifier(rs); - break; - case MeleeDamageModifier: - abstractEffectModifier = new MeleeDamageEffectModifier(rs); - break; - case MinDamage: - abstractEffectModifier = new MinDamageEffectModifier(rs); - break; - case NoMod: - abstractEffectModifier = new NoModEffectModifier(rs); - break; - case OCV: - abstractEffectModifier = new OCVEffectModifier(rs); - break; - case Parry: - abstractEffectModifier = new ParryEffectModifier(rs); - break; - case PassiveDefense: - abstractEffectModifier = new PassiveDefenseEffectModifier(rs); - break; - case PowerCost: - abstractEffectModifier = new PowerCostEffectModifier(rs); - break; - case PowerCostHealth: - abstractEffectModifier = new PowerCostHealthEffectModifier(rs); - break; - case PowerDamageModifier: - abstractEffectModifier = new PowerDamageEffectModifier(rs); - break; - case ProtectionFrom: - abstractEffectModifier = new ProtectionFromEffectModifier(rs); - break; - case Resistance: - abstractEffectModifier = new ResistanceEffectModifier(rs); - break; - case ScaleHeight: - abstractEffectModifier = new ScaleHeightEffectModifier(rs); - break; - case ScaleWidth: - abstractEffectModifier = new ScaleWidthEffectModifier(rs); - break; - case ScanRange: - abstractEffectModifier = new ScanRangeEffectModifier(rs); - break; - case SeeInvisible: - abstractEffectModifier = new SeeInvisibleEffectModifier(rs); - break; - case Silenced: - abstractEffectModifier = new SilencedEffectModifier(rs); - break; - case Skill: - abstractEffectModifier = new SkillEffectModifier(rs); - break; - case Slay: - abstractEffectModifier = new SlayEffectModifier(rs); - break; - case Speed: - abstractEffectModifier = new SpeedEffectModifier(rs); - break; - case SpireBlock: - abstractEffectModifier = new SpireBlockEffectModifier(rs); - break; - case Stamina: - abstractEffectModifier = new StaminaEffectModifier(rs); - break; - case StaminaFull: - abstractEffectModifier = new StaminaFullEffectModifier(rs); - break; - case StaminaRecoverRate: - abstractEffectModifier = new StaminaRecoverRateEffectModifier(rs); - break; - case Stunned: - abstractEffectModifier = new StunnedEffectModifier(rs); - break; - case Value: - abstractEffectModifier = new ValueEffectModifier(rs); - if (effectBase != null) { - ValueEffectModifier valueEffect = (ValueEffectModifier) abstractEffectModifier; - effectBase.setValue(valueEffect.minMod); - } - break; - case WeaponProc: - abstractEffectModifier = new WeaponProcEffectModifier(rs); - break; - case WeaponRange: - abstractEffectModifier = new WeaponRangeEffectModifier(rs); - break; - case WeaponSpeed: - abstractEffectModifier = new WeaponSpeedEffectModifier(rs); - break; + private static AbstractEffectModifier getCombinedModifiers(AbstractEffectModifier abstractEffectModifier, ResultSet rs, EffectsBase effectBase, Enum.ModType modifier) throws SQLException { + switch (modifier) { + case AdjustAboveDmgCap: + abstractEffectModifier = new AdjustAboveDmgCapEffectModifier(rs); + break; + case Ambidexterity: + abstractEffectModifier = new AmbidexterityEffectModifier(rs); + break; + case AnimOverride: + break; + case ArmorPiercing: + abstractEffectModifier = new ArmorPiercingEffectModifier(rs); + break; + case AttackDelay: + abstractEffectModifier = new AttackDelayEffectModifier(rs); + break; + case Attr: + abstractEffectModifier = new AttributeEffectModifier(rs); + break; + case BlackMantle: + abstractEffectModifier = new BlackMantleEffectModifier(rs); + break; + case BladeTrails: + abstractEffectModifier = new BladeTrailsEffectModifier(rs); + break; + case Block: + abstractEffectModifier = new BlockEffectModifier(rs); + break; + case BlockedPowerType: + abstractEffectModifier = new BlockedPowerTypeEffectModifier(rs); + break; + case CannotAttack: + abstractEffectModifier = new CannotAttackEffectModifier(rs); + break; + case CannotCast: + abstractEffectModifier = new CannotCastEffectModifier(rs); + break; + case CannotMove: + abstractEffectModifier = new CannotMoveEffectModifier(rs); + break; + case CannotTrack: + abstractEffectModifier = new CannotTrackEffectModifier(rs); + break; + case Charmed: + abstractEffectModifier = new CharmedEffectModifier(rs); + break; + case ConstrainedAmbidexterity: + abstractEffectModifier = new ConstrainedAmbidexterityEffectModifier(rs); + break; + case DamageCap: + abstractEffectModifier = new DamageCapEffectModifier(rs); + break; + case DamageShield: + abstractEffectModifier = new DamageShieldEffectModifier(rs); + break; + case DCV: + abstractEffectModifier = new DCVEffectModifier(rs); + break; + case Dodge: + abstractEffectModifier = new DodgeEffectModifier(rs); + break; + case DR: + abstractEffectModifier = new DREffectModifier(rs); + break; + case Durability: + abstractEffectModifier = new DurabilityEffectModifier(rs); + break; + case ExclusiveDamageCap: + abstractEffectModifier = new ExclusiveDamageCapEffectModifier(rs); + break; + case Fade: + abstractEffectModifier = new FadeEffectModifier(rs); + break; + case Fly: + abstractEffectModifier = new FlyEffectModifier(rs); + break; + case Health: + abstractEffectModifier = new HealthEffectModifier(rs); + break; + case HealthFull: + abstractEffectModifier = new HealthFullEffectModifier(rs); + break; + case HealthRecoverRate: + abstractEffectModifier = new HealthRecoverRateEffectModifier(rs); + break; + case IgnoreDamageCap: + abstractEffectModifier = new IgnoreDamageCapEffectModifier(rs); + break; + case IgnorePassiveDefense: + abstractEffectModifier = new IgnorePassiveDefenseEffectModifier(rs); + break; + case ImmuneTo: + abstractEffectModifier = new ImmuneToEffectModifier(rs); + break; + case ImmuneToAttack: + abstractEffectModifier = new ImmuneToAttackEffectModifier(rs); + break; + case ImmuneToPowers: + abstractEffectModifier = new ImmuneToPowersEffectModifier(rs); + break; + case Invisible: + abstractEffectModifier = new InvisibleEffectModifier(rs); + break; + case ItemName: + abstractEffectModifier = new ItemNameEffectModifier(rs); + if (((ItemNameEffectModifier) abstractEffectModifier).name.isEmpty()) + break; + if (effectBase != null) + effectBase.setName((((ItemNameEffectModifier) abstractEffectModifier).name)); + break; + case Mana: + abstractEffectModifier = new ManaEffectModifier(rs); + break; + case ManaFull: + abstractEffectModifier = new ManaFullEffectModifier(rs); + break; + case ManaRecoverRate: + abstractEffectModifier = new ManaRecoverRateEffectModifier(rs); + break; + case MaxDamage: + abstractEffectModifier = new MaxDamageEffectModifier(rs); + break; + case MeleeDamageModifier: + abstractEffectModifier = new MeleeDamageEffectModifier(rs); + break; + case MinDamage: + abstractEffectModifier = new MinDamageEffectModifier(rs); + break; + case NoMod: + abstractEffectModifier = new NoModEffectModifier(rs); + break; + case OCV: + abstractEffectModifier = new OCVEffectModifier(rs); + break; + case Parry: + abstractEffectModifier = new ParryEffectModifier(rs); + break; + case PassiveDefense: + abstractEffectModifier = new PassiveDefenseEffectModifier(rs); + break; + case PowerCost: + abstractEffectModifier = new PowerCostEffectModifier(rs); + break; + case PowerCostHealth: + abstractEffectModifier = new PowerCostHealthEffectModifier(rs); + break; + case PowerDamageModifier: + abstractEffectModifier = new PowerDamageEffectModifier(rs); + break; + case ProtectionFrom: + abstractEffectModifier = new ProtectionFromEffectModifier(rs); + break; + case Resistance: + abstractEffectModifier = new ResistanceEffectModifier(rs); + break; + case ScaleHeight: + abstractEffectModifier = new ScaleHeightEffectModifier(rs); + break; + case ScaleWidth: + abstractEffectModifier = new ScaleWidthEffectModifier(rs); + break; + case ScanRange: + abstractEffectModifier = new ScanRangeEffectModifier(rs); + break; + case SeeInvisible: + abstractEffectModifier = new SeeInvisibleEffectModifier(rs); + break; + case Silenced: + abstractEffectModifier = new SilencedEffectModifier(rs); + break; + case Skill: + abstractEffectModifier = new SkillEffectModifier(rs); + break; + case Slay: + abstractEffectModifier = new SlayEffectModifier(rs); + break; + case Speed: + abstractEffectModifier = new SpeedEffectModifier(rs); + break; + case SpireBlock: + abstractEffectModifier = new SpireBlockEffectModifier(rs); + break; + case Stamina: + abstractEffectModifier = new StaminaEffectModifier(rs); + break; + case StaminaFull: + abstractEffectModifier = new StaminaFullEffectModifier(rs); + break; + case StaminaRecoverRate: + abstractEffectModifier = new StaminaRecoverRateEffectModifier(rs); + break; + case Stunned: + abstractEffectModifier = new StunnedEffectModifier(rs); + break; + case Value: + abstractEffectModifier = new ValueEffectModifier(rs); + if (effectBase != null) { + ValueEffectModifier valueEffect = (ValueEffectModifier) abstractEffectModifier; + effectBase.setValue(valueEffect.minMod); + } + break; + case WeaponProc: + abstractEffectModifier = new WeaponProcEffectModifier(rs); + break; + case WeaponRange: + abstractEffectModifier = new WeaponRangeEffectModifier(rs); + break; + case WeaponSpeed: + abstractEffectModifier = new WeaponSpeedEffectModifier(rs); + break; - } - return abstractEffectModifier; - } + } + return abstractEffectModifier; + } } diff --git a/src/engine/db/handlers/dbItemBaseHandler.java b/src/engine/db/handlers/dbItemBaseHandler.java index 61ebfdc5..62e249d8 100644 --- a/src/engine/db/handlers/dbItemBaseHandler.java +++ b/src/engine/db/handlers/dbItemBaseHandler.java @@ -25,152 +25,152 @@ public class dbItemBaseHandler extends dbHandlerBase { public dbItemBaseHandler() { - } + } - public void LOAD_BAKEDINSTATS(ItemBase itemBase) { + public void LOAD_BAKEDINSTATS(ItemBase itemBase) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_item_bakedinstat` WHERE `itemID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_item_bakedinstat` WHERE `itemID` = ?")) { - preparedStatement.setInt(1, itemBase.getUUID()); - ResultSet rs = preparedStatement.executeQuery(); + preparedStatement.setInt(1, itemBase.getUUID()); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { - if (rs.getBoolean("fromUse")) - itemBase.getUsedStats().put(rs.getInt("token"), rs.getInt("numTrains")); - else - itemBase.getBakedInStats().put(rs.getInt("token"), rs.getInt("numTrains")); - } - } catch (SQLException e) { - Logger.error(e); - } - } + while (rs.next()) { + if (rs.getBoolean("fromUse")) + itemBase.getUsedStats().put(rs.getInt("token"), rs.getInt("numTrains")); + else + itemBase.getBakedInStats().put(rs.getInt("token"), rs.getInt("numTrains")); + } + } catch (SQLException e) { + Logger.error(e); + } + } - public void LOAD_ANIMATIONS(ItemBase itemBase) { + public void LOAD_ANIMATIONS(ItemBase itemBase) { - ArrayList tempList = new ArrayList<>(); - ArrayList tempListOff = new ArrayList<>(); + ArrayList tempList = new ArrayList<>(); + ArrayList tempListOff = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_itembase_animations` WHERE `itemBaseUUID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_itembase_animations` WHERE `itemBaseUUID` = ?")) { - preparedStatement.setInt(1, itemBase.getUUID()); - ResultSet rs = preparedStatement.executeQuery(); + preparedStatement.setInt(1, itemBase.getUUID()); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { - int animation = rs.getInt("animation"); - boolean rightHand = rs.getBoolean("rightHand"); + while (rs.next()) { + int animation = rs.getInt("animation"); + boolean rightHand = rs.getBoolean("rightHand"); - if (rightHand) - tempList.add(animation); - else - tempListOff.add(animation); - } - } catch (SQLException e) { - Logger.error(e); - } + if (rightHand) + tempList.add(animation); + else + tempListOff.add(animation); + } + } catch (SQLException e) { + Logger.error(e); + } - itemBase.setAnimations(tempList); - itemBase.setOffHandAnimations(tempListOff); - } + itemBase.setAnimations(tempList); + itemBase.setOffHandAnimations(tempListOff); + } - public void LOAD_ALL_ITEMBASES() { + public void LOAD_ALL_ITEMBASES() { - ItemBase itemBase; - int recordsRead = 0; + ItemBase itemBase; + int recordsRead = 0; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_itembase")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_itembase")) { - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { - recordsRead++; - itemBase = new ItemBase(rs); - ItemBase.addToCache(itemBase); - } + while (rs.next()) { + recordsRead++; + itemBase = new ItemBase(rs); + ItemBase.addToCache(itemBase); + } - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - Logger.info("read: " + recordsRead + " cached: " + ItemBase.getUUIDCache().size()); - } + Logger.info("read: " + recordsRead + " cached: " + ItemBase.getUUIDCache().size()); + } - public HashMap> LOAD_RUNES_FOR_NPC_AND_MOBS() { + public HashMap> LOAD_RUNES_FOR_NPC_AND_MOBS() { - HashMap> runeSets = new HashMap<>(); - int runeSetID; - int runeBaseID; - int recordsRead = 0; + HashMap> runeSets = new HashMap<>(); + int runeSetID; + int runeBaseID; + int recordsRead = 0; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_npc_runeSet")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_npc_runeSet")) { - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { + while (rs.next()) { - recordsRead++; + recordsRead++; - runeSetID = rs.getInt("runeSet"); - runeBaseID = rs.getInt("runeBase"); + runeSetID = rs.getInt("runeSet"); + runeBaseID = rs.getInt("runeBase"); - if (runeSets.get(runeSetID) == null) { - ArrayList runeList = new ArrayList<>(); - runeList.add(runeBaseID); - runeSets.put(runeSetID, runeList); - } else { - ArrayList runeList = runeSets.get(runeSetID); - runeList.add(runeSetID); - runeSets.put(runeSetID, runeList); - } - } + if (runeSets.get(runeSetID) == null) { + ArrayList runeList = new ArrayList<>(); + runeList.add(runeBaseID); + runeSets.put(runeSetID, runeList); + } else { + ArrayList runeList = runeSets.get(runeSetID); + runeList.add(runeSetID); + runeSets.put(runeSetID, runeList); + } + } - } catch (SQLException e) { - Logger.error(e); - return runeSets; - } + } catch (SQLException e) { + Logger.error(e); + return runeSets; + } - Logger.info("read: " + recordsRead + " cached: " + runeSets.size()); - return runeSets; - } - - public HashMap> LOAD_BOOTY_FOR_MOBS() { - - HashMap> bootySets = new HashMap<>(); - BootySetEntry bootySetEntry; - int bootySetID; - int recordsRead = 0; + Logger.info("read: " + recordsRead + " cached: " + runeSets.size()); + return runeSets; + } + + public HashMap> LOAD_BOOTY_FOR_MOBS() { + + HashMap> bootySets = new HashMap<>(); + BootySetEntry bootySetEntry; + int bootySetID; + int recordsRead = 0; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_npc_bootySet")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_npc_bootySet")) { - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { + while (rs.next()) { - recordsRead++; + recordsRead++; - bootySetID = rs.getInt("bootySet"); - bootySetEntry = new BootySetEntry(rs); + bootySetID = rs.getInt("bootySet"); + bootySetEntry = new BootySetEntry(rs); - if (bootySets.get(bootySetID) == null) { - ArrayList bootyList = new ArrayList<>(); - bootyList.add(bootySetEntry); - bootySets.put(bootySetID, bootyList); - } else { - ArrayList bootyList = bootySets.get(bootySetID); - bootyList.add(bootySetEntry); - bootySets.put(bootySetID, bootyList); - } - } - } catch (SQLException e) { - Logger.error(e); - return bootySets; - } + if (bootySets.get(bootySetID) == null) { + ArrayList bootyList = new ArrayList<>(); + bootyList.add(bootySetEntry); + bootySets.put(bootySetID, bootyList); + } else { + ArrayList bootyList = bootySets.get(bootySetID); + bootyList.add(bootySetEntry); + bootySets.put(bootySetID, bootyList); + } + } + } catch (SQLException e) { + Logger.error(e); + return bootySets; + } - Logger.info("read: " + recordsRead + " cached: " + bootySets.size()); - return bootySets; - } + Logger.info("read: " + recordsRead + " cached: " + bootySets.size()); + return bootySets; + } } diff --git a/src/engine/db/handlers/dbWarehouseHandler.java b/src/engine/db/handlers/dbWarehouseHandler.java index 216aea87..419268f6 100644 --- a/src/engine/db/handlers/dbWarehouseHandler.java +++ b/src/engine/db/handlers/dbWarehouseHandler.java @@ -28,529 +28,529 @@ import java.util.concurrent.ConcurrentHashMap; public class dbWarehouseHandler extends dbHandlerBase { - private static final ConcurrentHashMap columns = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - - public dbWarehouseHandler() { - this.localClass = Warehouse.class; - this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - - } - - public static void addObject(ArrayList list, ResultSet rs) throws SQLException { - String type = rs.getString("type"); - switch (type) { - case "building": - Building building = new Building(rs); - DbManager.addToCache(building); - list.add(building); - break; - case "warehouse": - Warehouse warehouse = new Warehouse(rs); - DbManager.addToCache(warehouse); - list.add(warehouse); - break; - } - } - - public ArrayList CREATE_WAREHOUSE(int parentZoneID, int OwnerUUID, String name, int meshUUID, - Vector3fImmutable location, float meshScale, int currentHP, - ProtectionState protectionState, int currentGold, int rank, - DateTime upgradeDate, int blueprintUUID, float w, float rotY) { + private static final ConcurrentHashMap columns = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + + public dbWarehouseHandler() { + this.localClass = Warehouse.class; + this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); + + } + + public static void addObject(ArrayList list, ResultSet rs) throws SQLException { + String type = rs.getString("type"); + switch (type) { + case "building": + Building building = new Building(rs); + DbManager.addToCache(building); + list.add(building); + break; + case "warehouse": + Warehouse warehouse = new Warehouse(rs); + DbManager.addToCache(warehouse); + list.add(warehouse); + break; + } + } + + public ArrayList CREATE_WAREHOUSE(int parentZoneID, int OwnerUUID, String name, int meshUUID, + Vector3fImmutable location, float meshScale, int currentHP, + ProtectionState protectionState, int currentGold, int rank, + DateTime upgradeDate, int blueprintUUID, float w, float rotY) { - ArrayList warehouseList = new ArrayList<>(); + ArrayList warehouseList = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("CALL `WAREHOUSE_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ,? ,? ,?, ?);")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("CALL `WAREHOUSE_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ,? ,? ,?, ?);")) { - preparedStatement.setInt(1, parentZoneID); - preparedStatement.setInt(2, OwnerUUID); - preparedStatement.setString(3, name); - preparedStatement.setInt(4, meshUUID); - preparedStatement.setFloat(5, location.x); - preparedStatement.setFloat(6, location.y); - preparedStatement.setFloat(7, location.z); - preparedStatement.setFloat(8, meshScale); - preparedStatement.setInt(9, currentHP); - preparedStatement.setString(10, protectionState.name()); - preparedStatement.setInt(11, currentGold); - preparedStatement.setInt(12, rank); + preparedStatement.setInt(1, parentZoneID); + preparedStatement.setInt(2, OwnerUUID); + preparedStatement.setString(3, name); + preparedStatement.setInt(4, meshUUID); + preparedStatement.setFloat(5, location.x); + preparedStatement.setFloat(6, location.y); + preparedStatement.setFloat(7, location.z); + preparedStatement.setFloat(8, meshScale); + preparedStatement.setInt(9, currentHP); + preparedStatement.setString(10, protectionState.name()); + preparedStatement.setInt(11, currentGold); + preparedStatement.setInt(12, rank); - if (upgradeDate != null) - preparedStatement.setTimestamp(13, new java.sql.Timestamp(upgradeDate.getMillis())); - else - preparedStatement.setNull(13, java.sql.Types.DATE); + if (upgradeDate != null) + preparedStatement.setTimestamp(13, new java.sql.Timestamp(upgradeDate.getMillis())); + else + preparedStatement.setNull(13, java.sql.Types.DATE); - preparedStatement.setInt(14, blueprintUUID); - preparedStatement.setFloat(15, w); - preparedStatement.setFloat(16, rotY); + preparedStatement.setInt(14, blueprintUUID); + preparedStatement.setFloat(15, w); + preparedStatement.setFloat(16, rotY); - preparedStatement.execute(); - ResultSet rs = preparedStatement.getResultSet(); + preparedStatement.execute(); + ResultSet rs = preparedStatement.getResultSet(); - while (rs.next()) - addObject(warehouseList, rs); + while (rs.next()) + addObject(warehouseList, rs); - while (preparedStatement.getMoreResults()) { - rs = preparedStatement.getResultSet(); + while (preparedStatement.getMoreResults()) { + rs = preparedStatement.getResultSet(); - while (rs.next()) - addObject(warehouseList, rs); - } - } catch (SQLException e) { - Logger.error(e); - } + while (rs.next()) + addObject(warehouseList, rs); + } + } catch (SQLException e) { + Logger.error(e); + } - return warehouseList; - } + return warehouseList; + } - public boolean updateLocks(final Warehouse wh, long locks) { + public boolean updateLocks(final Warehouse wh, long locks) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_locks`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_locks`=? WHERE `UID` = ?")) { - preparedStatement.setLong(1, locks); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setLong(1, locks); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateGold(final Warehouse wh, int amount) { + public boolean updateGold(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_gold`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_gold`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateStone(final Warehouse wh, int amount) { + public boolean updateStone(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_stone`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_stone`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateTruesteel(final Warehouse wh, int amount) { + public boolean updateTruesteel(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_truesteel`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_truesteel`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateIron(final Warehouse wh, int amount) { + public boolean updateIron(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_iron`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_iron`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateAdamant(final Warehouse wh, int amount) { + public boolean updateAdamant(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_adamant`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_adamant`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateLumber(final Warehouse wh, int amount) { + public boolean updateLumber(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_lumber`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_lumber`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateOak(final Warehouse wh, int amount) { + public boolean updateOak(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_oak`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_oak`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateBronzewood(final Warehouse wh, int amount) { + public boolean updateBronzewood(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_bronzewood`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_bronzewood`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateMandrake(final Warehouse wh, int amount) { + public boolean updateMandrake(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_mandrake`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_mandrake`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateCoal(final Warehouse wh, int amount) { + public boolean updateCoal(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_coal`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_coal`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateAgate(final Warehouse wh, int amount) { + public boolean updateAgate(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_agate`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_agate`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateDiamond(final Warehouse wh, int amount) { + public boolean updateDiamond(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_diamond`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_diamond`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateOnyx(final Warehouse wh, int amount) { + public boolean updateOnyx(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_onyx`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_onyx`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateAzoth(final Warehouse wh, int amount) { + public boolean updateAzoth(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_azoth`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_azoth`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateOrichalk(final Warehouse wh, int amount) { + public boolean updateOrichalk(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_orichalk`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_orichalk`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateAntimony(final Warehouse wh, int amount) { + public boolean updateAntimony(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_antimony`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_antimony`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateSulfur(final Warehouse wh, int amount) { + public boolean updateSulfur(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_sulfur`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_sulfur`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateQuicksilver(final Warehouse wh, int amount) { + public boolean updateQuicksilver(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_quicksilver`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_quicksilver`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateGalvor(final Warehouse wh, int amount) { + public boolean updateGalvor(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_galvor`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_galvor`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateWormwood(final Warehouse wh, int amount) { + public boolean updateWormwood(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_wormwood`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_wormwood`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateObsidian(final Warehouse wh, int amount) { + public boolean updateObsidian(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_obsidian`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_obsidian`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateBloodstone(final Warehouse wh, int amount) { + public boolean updateBloodstone(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_bloodstone`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_bloodstone`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean updateMithril(final Warehouse wh, int amount) { + public boolean updateMithril(final Warehouse wh, int amount) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_mithril`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_mithril`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(1, amount); + preparedStatement.setInt(2, wh.getUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean CREATE_TRANSACTION(int warehouseBuildingID, GameObjectType targetType, int targetUUID, TransactionType transactionType, Resource resource, int amount, DateTime date) { + public boolean CREATE_TRANSACTION(int warehouseBuildingID, GameObjectType targetType, int targetUUID, TransactionType transactionType, Resource resource, int amount, DateTime date) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_warehouse_transactions` (`warehouseUID`, `targetType`,`targetUID`, `type`,`resource`,`amount`,`date` ) VALUES (?,?,?,?,?,?,?)")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_warehouse_transactions` (`warehouseUID`, `targetType`,`targetUID`, `type`,`resource`,`amount`,`date` ) VALUES (?,?,?,?,?,?,?)")) { - preparedStatement.setInt(1, amount); - preparedStatement.setLong(1, warehouseBuildingID); - preparedStatement.setString(2, targetType.name()); - preparedStatement.setLong(3, targetUUID); - preparedStatement.setString(4, transactionType.name()); - preparedStatement.setString(5, resource.name()); - preparedStatement.setInt(6, amount); - preparedStatement.setTimestamp(7, new java.sql.Timestamp(date.getMillis())); + preparedStatement.setInt(1, amount); + preparedStatement.setLong(1, warehouseBuildingID); + preparedStatement.setString(2, targetType.name()); + preparedStatement.setLong(3, targetUUID); + preparedStatement.setString(4, transactionType.name()); + preparedStatement.setString(5, resource.name()); + preparedStatement.setInt(6, amount); + preparedStatement.setTimestamp(7, new java.sql.Timestamp(date.getMillis())); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public ArrayList GET_TRANSACTIONS_FOR_WAREHOUSE(final int warehouseUUID) { + public ArrayList GET_TRANSACTIONS_FOR_WAREHOUSE(final int warehouseUUID) { - ArrayList transactionsList = new ArrayList<>(); + ArrayList transactionsList = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_warehouse_transactions WHERE `warehouseUID` = ?;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_warehouse_transactions WHERE `warehouseUID` = ?;")) { - preparedStatement.setInt(1, warehouseUUID); + preparedStatement.setInt(1, warehouseUUID); - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { - Transaction transactions = new Transaction(rs); - transactionsList.add(transactions); - } + while (rs.next()) { + Transaction transactions = new Transaction(rs); + transactionsList.add(transactions); + } - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return transactionsList; - } + return transactionsList; + } - public void LOAD_ALL_WAREHOUSES() { + public void LOAD_ALL_WAREHOUSES() { - Warehouse warehouse; + Warehouse warehouse; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_warehouse`.*, `object`.`parent`, `object`.`type` FROM `object` LEFT JOIN `obj_warehouse` ON `object`.`UID` = `obj_warehouse`.`UID` WHERE `object`.`type` = 'warehouse';")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_warehouse`.*, `object`.`parent`, `object`.`type` FROM `object` LEFT JOIN `obj_warehouse` ON `object`.`UID` = `obj_warehouse`.`UID` WHERE `object`.`type` = 'warehouse';")) { - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { - warehouse = new Warehouse(rs); - warehouse.runAfterLoad(); - warehouse.loadAllTransactions(); - } + while (rs.next()) { + warehouse = new Warehouse(rs); + warehouse.runAfterLoad(); + warehouse.loadAllTransactions(); + } - } catch (SQLException e) { - Logger.error(e); - } - } + } catch (SQLException e) { + Logger.error(e); + } + } } diff --git a/src/engine/db/handlers/dbZoneHandler.java b/src/engine/db/handlers/dbZoneHandler.java index 8b6b603f..84abc1a7 100644 --- a/src/engine/db/handlers/dbZoneHandler.java +++ b/src/engine/db/handlers/dbZoneHandler.java @@ -24,107 +24,107 @@ import java.util.ArrayList; public class dbZoneHandler extends dbHandlerBase { - public dbZoneHandler() { - this.localClass = Zone.class; - this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } + public dbZoneHandler() { + this.localClass = Zone.class; + this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); + } - public ArrayList GET_ALL_NODES(Zone zone) { - ArrayList wsmList = new ArrayList<>(); - wsmList.addAll(zone.getNodes()); - if (zone.absX == 0.0f) { - zone.absX = zone.getXCoord(); - } - if (zone.absY == 0.0f) { - zone.absY = zone.getYCoord(); - } - if (zone.absZ == 0.0f) { - zone.absZ = zone.getZCoord(); - } - for (Zone child : zone.getNodes()) { - child.absX = child.getXCoord() + zone.absX; - child.absY = child.getYCoord() + zone.absY; - child.absZ = child.getZCoord() + zone.absZ; - wsmList.addAll(this.GET_ALL_NODES(child)); - } - return wsmList; - } + public ArrayList GET_ALL_NODES(Zone zone) { + ArrayList wsmList = new ArrayList<>(); + wsmList.addAll(zone.getNodes()); + if (zone.absX == 0.0f) { + zone.absX = zone.getXCoord(); + } + if (zone.absY == 0.0f) { + zone.absY = zone.getYCoord(); + } + if (zone.absZ == 0.0f) { + zone.absZ = zone.getZCoord(); + } + for (Zone child : zone.getNodes()) { + child.absX = child.getXCoord() + zone.absX; + child.absY = child.getYCoord() + zone.absY; + child.absZ = child.getZCoord() + zone.absZ; + wsmList.addAll(this.GET_ALL_NODES(child)); + } + return wsmList; + } - public Zone GET_BY_UID(long ID) { + public Zone GET_BY_UID(long ID) { - Zone zone = (Zone) DbManager.getFromCache(Enum.GameObjectType.Zone, (int) ID); + Zone zone = (Zone) DbManager.getFromCache(Enum.GameObjectType.Zone, (int) ID); - if (zone != null) - return zone; + if (zone != null) + return zone; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_zone`.*, `object`.`parent` FROM `object` INNER JOIN `obj_zone` ON `obj_zone`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_zone`.*, `object`.`parent` FROM `object` INNER JOIN `obj_zone` ON `obj_zone`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) { - preparedStatement.setLong(1, ID); + preparedStatement.setLong(1, ID); - ResultSet rs = preparedStatement.executeQuery(); - zone = (Zone) getObjectFromRs(rs); + ResultSet rs = preparedStatement.executeQuery(); + zone = (Zone) getObjectFromRs(rs); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return zone; - } + return zone; + } - public ArrayList GET_MAP_NODES(final int objectUUID) { + public ArrayList GET_MAP_NODES(final int objectUUID) { - ArrayList zoneList = new ArrayList<>(); + ArrayList zoneList = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_zone`.*, `object`.`parent` FROM `object` INNER JOIN `obj_zone` ON `obj_zone`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_zone`.*, `object`.`parent` FROM `object` INNER JOIN `obj_zone` ON `obj_zone`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;")) { - preparedStatement.setLong(1, objectUUID); + preparedStatement.setLong(1, objectUUID); - ResultSet rs = preparedStatement.executeQuery(); - zoneList = getObjectsFromRs(rs, 2000); + ResultSet rs = preparedStatement.executeQuery(); + zoneList = getObjectsFromRs(rs, 2000); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return zoneList; - } + return zoneList; + } - public void LOAD_ZONE_EXTENTS() { + public void LOAD_ZONE_EXTENTS() { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_zone_size`;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_zone_size`;")) { - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { - Vector2f zoneSize = new Vector2f(); - int loadNum = rs.getInt("loadNum"); - zoneSize.x = rs.getFloat("xRadius"); - zoneSize.y = rs.getFloat("zRadius"); - ZoneManager._zone_size_data.put(loadNum, zoneSize); - } + while (rs.next()) { + Vector2f zoneSize = new Vector2f(); + int loadNum = rs.getInt("loadNum"); + zoneSize.x = rs.getFloat("xRadius"); + zoneSize.y = rs.getFloat("zRadius"); + ZoneManager._zone_size_data.put(loadNum, zoneSize); + } - } catch (SQLException e) { - Logger.error(e); - } - } + } catch (SQLException e) { + Logger.error(e); + } + } - public boolean DELETE_ZONE(final Zone zone) { + public boolean DELETE_ZONE(final Zone zone) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ? AND `type` = 'zone'")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ? AND `type` = 'zone'")) { - preparedStatement.setInt(1, zone.getObjectUUID()); + preparedStatement.setInt(1, zone.getObjectUUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return false; - } + return false; + } } diff --git a/src/engine/devcmd/AbstractDevCmd.java b/src/engine/devcmd/AbstractDevCmd.java index 75a54683..ae2364b6 100644 --- a/src/engine/devcmd/AbstractDevCmd.java +++ b/src/engine/devcmd/AbstractDevCmd.java @@ -29,13 +29,67 @@ public abstract class AbstractDevCmd { this.rsult = ""; } + /* + * Misc tools/helpers + */ + protected static Building getTargetAsBuilding(PlayerCharacter pc) { + int targetType = pc.getLastTargetType().ordinal(); + int targetID = pc.getLastTargetID(); + if (targetType == GameObjectType.Building.ordinal()) { + Building b = (Building) DbManager + .getFromCache(GameObjectType.Building, targetID); + if (b == null) { + ChatManager.chatSystemError( + pc, + "Command Failed. Could not find building of ID " + + targetID); + return null; + } + return b; + } else { + return null; + } + } + + protected static Mob getTargetAsMob(PlayerCharacter pc) { + int targetType = pc.getLastTargetType().ordinal(); + int targetID = pc.getLastTargetID(); + if (targetType == GameObjectType.Mob.ordinal()) { + Mob b = Mob.getMob(targetID); + if (b == null) { + ChatManager.chatSystemError(pc, + "Command Failed. Could not find Mob of ID " + targetID); + return null; + } + return b; + } else { + return null; + } + } + + protected static NPC getTargetAsNPC(PlayerCharacter pc) { + int targetType = pc.getLastTargetType().ordinal(); + int targetID = pc.getLastTargetID(); + if (targetType == GameObjectType.NPC.ordinal()) { + NPC b = NPC.getFromCache(targetID); + if (b == null) { + ChatManager.chatSystemError(pc, + "Command Failed. Could not find NPC of ID " + targetID); + return null; + } + return b; + } else { + return null; + } + } + /** * This function is called by the DevCmdManager. Method splits argString * into a String array and then calls the subclass specific _doCmd method. */ public void doCmd(PlayerCharacter pcSender, String argString, - AbstractGameObject target) { + AbstractGameObject target) { String[] args = argString.split(" "); if (pcSender == null) { @@ -52,7 +106,7 @@ public abstract class AbstractDevCmd { } protected abstract void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target); + AbstractGameObject target); /** * Returns the string sent to the client that displays how to use this @@ -89,22 +143,22 @@ public abstract class AbstractDevCmd { this.cmdStrings.add(lowercase); } - public void setTarget(AbstractGameObject ago) { - this.tr = ago; - } - public AbstractGameObject getTarget() { return this.tr; } - public void setResult(String result) { - this.rsult = result; + public void setTarget(AbstractGameObject ago) { + this.tr = ago; } public String getResult() { return this.rsult; } + public void setResult(String result) { + this.rsult = result; + } + /* * Helper functions */ @@ -124,58 +178,4 @@ public abstract class AbstractDevCmd { ChatManager.chatSystemInfo(pc, msgText); } - /* - * Misc tools/helpers - */ - protected static Building getTargetAsBuilding(PlayerCharacter pc) { - int targetType = pc.getLastTargetType().ordinal(); - int targetID = pc.getLastTargetID(); - if (targetType == GameObjectType.Building.ordinal()) { - Building b = (Building) DbManager - .getFromCache(GameObjectType.Building, targetID); - if (b == null) { - ChatManager.chatSystemError( - pc, - "Command Failed. Could not find building of ID " - + targetID); - return null; - } - return b; - } else { - return null; - } - } - - protected static Mob getTargetAsMob(PlayerCharacter pc) { - int targetType = pc.getLastTargetType().ordinal(); - int targetID = pc.getLastTargetID(); - if (targetType == GameObjectType.Mob.ordinal()) { - Mob b = Mob.getMob(targetID); - if (b == null) { - ChatManager.chatSystemError(pc, - "Command Failed. Could not find Mob of ID " + targetID); - return null; - } - return b; - } else { - return null; - } - } - - protected static NPC getTargetAsNPC(PlayerCharacter pc) { - int targetType = pc.getLastTargetType().ordinal(); - int targetID = pc.getLastTargetID(); - if (targetType == GameObjectType.NPC.ordinal()) { - NPC b = NPC.getFromCache(targetID); - if (b == null) { - ChatManager.chatSystemError(pc, - "Command Failed. Could not find NPC of ID " + targetID); - return null; - } - return b; - } else { - return null; - } - } - } diff --git a/src/engine/devcmd/cmds/AddBuildingCmd.java b/src/engine/devcmd/cmds/AddBuildingCmd.java index 50e371ff..537faab1 100644 --- a/src/engine/devcmd/cmds/AddBuildingCmd.java +++ b/src/engine/devcmd/cmds/AddBuildingCmd.java @@ -22,106 +22,106 @@ import engine.server.MBServerStatics; public class AddBuildingCmd extends AbstractDevCmd { - public AddBuildingCmd() { + public AddBuildingCmd() { super("addbuilding"); // super("addbuilding", MBServerStatics.ACCESS_GROUP_DESIGNER_UP, 0, false, true); this.addCmdString("building"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - - // Arg Count Check - if (words.length != 2) { - this.sendUsage(pc); - return; - } - - int ID; - int rank; - Blueprint blueprint; - - try { - ID = Integer.parseInt(words[0]); - rank = Integer.parseInt(words[1]); - } catch (Exception e) { - throwbackError(pc, "Invalid addBuilding Command. Need Building ID and rank."); - return; // NaN - } - if (ID < 1) { - throwbackError(pc, - "Invalid addBuilding Command. Invalid Building ID."); - return; - } - Vector3f rot = new Vector3f(0.0f, 0.0f, 0.0f); - float w = 1f; - Zone zone = ZoneManager.findSmallestZone(pc.getLoc()); - - if (zone == null) { - throwbackError(pc, "Failed to find zone to place building in."); - return; - } - - blueprint = Blueprint.getBlueprint(ID); - - if ((blueprint != null) && (rank > blueprint.getMaxRank())) { - throwbackError(pc, rank + " is not a valid rank for this building"); - return; - } - - Building likeBuilding = DbManager.BuildingQueries.GET_BUILDING_BY_MESH(ID); - - if (likeBuilding != null) { - rot = likeBuilding.getRot(); - w = likeBuilding.getw(); - } - - String buildingName = ""; - int blueprintUUID = 0; - - Vector3fImmutable localLoc = ZoneManager.worldToLocal(pc.getLoc(), zone); - - if (localLoc == null) - return; - - if (blueprint != null) { - buildingName = blueprint.getName(); - blueprintUUID = blueprint.getBlueprintUUID(); - } - - Building building = DbManager.BuildingQueries. - CREATE_BUILDING( - zone.getObjectUUID(), 0, buildingName, ID, - localLoc, 1.0f, 0, ProtectionState.PROTECTED, 0, rank, - null, blueprintUUID, w, rot.y); - - - if (building == null) { - throwbackError(pc, "Failed to add building."); - return; - } - - building.setRot(rot); - building.setw(w); - - building.setObjectTypeMask(MBServerStatics.MASK_BUILDING); - WorldGrid.addObject(building, pc); - ChatManager.chatSayInfo(pc, - "Building with ID " + building.getObjectUUID() + " added"); - - this.setResult(String.valueOf(building.getObjectUUID())); - - } - - @Override - protected String _getHelpString() { - return "Creates a building of type 'buildingID' at the location your character is standing."; - } - - @Override - protected String _getUsageString() { - return "' /addbuilding buildingID rank' || ' /building buildingID rank'"; - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + + // Arg Count Check + if (words.length != 2) { + this.sendUsage(pc); + return; + } + + int ID; + int rank; + Blueprint blueprint; + + try { + ID = Integer.parseInt(words[0]); + rank = Integer.parseInt(words[1]); + } catch (Exception e) { + throwbackError(pc, "Invalid addBuilding Command. Need Building ID and rank."); + return; // NaN + } + if (ID < 1) { + throwbackError(pc, + "Invalid addBuilding Command. Invalid Building ID."); + return; + } + Vector3f rot = new Vector3f(0.0f, 0.0f, 0.0f); + float w = 1f; + Zone zone = ZoneManager.findSmallestZone(pc.getLoc()); + + if (zone == null) { + throwbackError(pc, "Failed to find zone to place building in."); + return; + } + + blueprint = Blueprint.getBlueprint(ID); + + if ((blueprint != null) && (rank > blueprint.getMaxRank())) { + throwbackError(pc, rank + " is not a valid rank for this building"); + return; + } + + Building likeBuilding = DbManager.BuildingQueries.GET_BUILDING_BY_MESH(ID); + + if (likeBuilding != null) { + rot = likeBuilding.getRot(); + w = likeBuilding.getw(); + } + + String buildingName = ""; + int blueprintUUID = 0; + + Vector3fImmutable localLoc = ZoneManager.worldToLocal(pc.getLoc(), zone); + + if (localLoc == null) + return; + + if (blueprint != null) { + buildingName = blueprint.getName(); + blueprintUUID = blueprint.getBlueprintUUID(); + } + + Building building = DbManager.BuildingQueries. + CREATE_BUILDING( + zone.getObjectUUID(), 0, buildingName, ID, + localLoc, 1.0f, 0, ProtectionState.PROTECTED, 0, rank, + null, blueprintUUID, w, rot.y); + + + if (building == null) { + throwbackError(pc, "Failed to add building."); + return; + } + + building.setRot(rot); + building.setw(w); + + building.setObjectTypeMask(MBServerStatics.MASK_BUILDING); + WorldGrid.addObject(building, pc); + ChatManager.chatSayInfo(pc, + "Building with ID " + building.getObjectUUID() + " added"); + + this.setResult(String.valueOf(building.getObjectUUID())); + + } + + @Override + protected String _getHelpString() { + return "Creates a building of type 'buildingID' at the location your character is standing."; + } + + @Override + protected String _getUsageString() { + return "' /addbuilding buildingID rank' || ' /building buildingID rank'"; + } } diff --git a/src/engine/devcmd/cmds/AddGoldCmd.java b/src/engine/devcmd/cmds/AddGoldCmd.java index 2d339821..e998fc5b 100644 --- a/src/engine/devcmd/cmds/AddGoldCmd.java +++ b/src/engine/devcmd/cmds/AddGoldCmd.java @@ -17,61 +17,60 @@ import engine.objects.PlayerCharacter; /** * @author Eighty - * */ public class AddGoldCmd extends AbstractDevCmd { - public AddGoldCmd() { + public AddGoldCmd() { super("addgold"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - if (words.length != 1) { - this.sendUsage(pc); - return; - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + if (words.length != 1) { + this.sendUsage(pc); + return; + } - Item gold = pc.getCharItemManager().getGoldInventory(); - int curAmt; - if (gold == null) - curAmt = 0; - else - curAmt = gold.getNumOfItems(); + Item gold = pc.getCharItemManager().getGoldInventory(); + int curAmt; + if (gold == null) + curAmt = 0; + else + curAmt = gold.getNumOfItems(); - int amt; - try { - amt = Integer.parseInt(words[0]); - } catch (NumberFormatException e) { - throwbackError(pc, "Quantity must be a number, " + words[0] + " is invalid"); - return; - } - if (amt < 1 || amt > 10000000) { - throwbackError(pc, "Quantity must be between 1 and 10000000 (10 million)"); - return; - } else if ((curAmt + amt) > 10000000) { - throwbackError(pc, "This would place your inventory over 10,000,000 gold."); - return; - } + int amt; + try { + amt = Integer.parseInt(words[0]); + } catch (NumberFormatException e) { + throwbackError(pc, "Quantity must be a number, " + words[0] + " is invalid"); + return; + } + if (amt < 1 || amt > 10000000) { + throwbackError(pc, "Quantity must be between 1 and 10000000 (10 million)"); + return; + } else if ((curAmt + amt) > 10000000) { + throwbackError(pc, "This would place your inventory over 10,000,000 gold."); + return; + } - if (!pc.getCharItemManager().addGoldToInventory(amt, true)) { - throwbackError(pc, "Failed to add gold to inventory"); - return; - } + if (!pc.getCharItemManager().addGoldToInventory(amt, true)) { + throwbackError(pc, "Failed to add gold to inventory"); + return; + } - ChatManager.chatSayInfo(pc, amt + " gold added to inventory"); - pc.getCharItemManager().updateInventory(); - } + ChatManager.chatSayInfo(pc, amt + " gold added to inventory"); + pc.getCharItemManager().updateInventory(); + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "adds gold to inventory"; - } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /addGold quantity'"; - } + } } diff --git a/src/engine/devcmd/cmds/AddMobCmd.java b/src/engine/devcmd/cmds/AddMobCmd.java index 89f7d6fa..ac2fbfa8 100644 --- a/src/engine/devcmd/cmds/AddMobCmd.java +++ b/src/engine/devcmd/cmds/AddMobCmd.java @@ -20,92 +20,91 @@ import org.pmw.tinylog.Logger; /** * @author Eighty - * */ public class AddMobCmd extends AbstractDevCmd { - public AddMobCmd() { + public AddMobCmd() { super("mob"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - if (words.length != 1) { - this.sendUsage(pc); - return; - } - - Zone zone = ZoneManager.findSmallestZone(pc.getLoc()); - - if (words[0].equals("all")){ - - for (AbstractGameObject mobbaseAGO: DbManager.getList(GameObjectType.MobBase)){ - MobBase mb = (MobBase)mobbaseAGO; - int loadID = mb.getObjectUUID(); - Mob mob = Mob.createMob( loadID, Vector3fImmutable.getRandomPointInCircle(pc.getLoc(), 100), - null, true, zone, null,0, "", 1); - if (mob != null) { - mob.updateDatabase(); - this.setResult(String.valueOf(mob.getDBID())); - } else { - throwbackError(pc, "Failed to create mob of type " + loadID); - Logger.error( "Failed to create mob of type " - + loadID); - } - } - return; - } - - - int loadID; - try { - loadID = Integer.parseInt(words[0]); - } catch (NumberFormatException e) { - throwbackError(pc, "Supplied type " + words[0] - + " failed to parse to an Integer"); - return; - } catch (Exception e) { - throwbackError(pc, - "An unknown exception occurred when trying to use mob command for type " - + words[0]); - return; // NaN - } - - - if (zone == null) { - throwbackError(pc, "Failed to find zone to place mob in."); - return; - } - - if (zone.isPlayerCity()) { - throwbackError(pc, "Cannot use ./mob on Player cities. Try ./servermob instead."); - return; - } - - - Mob mob = Mob.createMob( loadID, pc.getLoc(), - null, true, zone, null,0, "", 1); - if (mob != null) { - mob.updateDatabase(); - ChatManager.chatSayInfo(pc, - "Mob with ID " + mob.getDBID() + " added"); - this.setResult(String.valueOf(mob.getDBID())); - } else { - throwbackError(pc, "Failed to create mob of type " + loadID); - Logger.error("Failed to create mob of type " - + loadID); - } - } - - @Override - protected String _getHelpString() { + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + if (words.length != 1) { + this.sendUsage(pc); + return; + } + + Zone zone = ZoneManager.findSmallestZone(pc.getLoc()); + + if (words[0].equals("all")) { + + for (AbstractGameObject mobbaseAGO : DbManager.getList(GameObjectType.MobBase)) { + MobBase mb = (MobBase) mobbaseAGO; + int loadID = mb.getObjectUUID(); + Mob mob = Mob.createMob(loadID, Vector3fImmutable.getRandomPointInCircle(pc.getLoc(), 100), + null, true, zone, null, 0, "", 1); + if (mob != null) { + mob.updateDatabase(); + this.setResult(String.valueOf(mob.getDBID())); + } else { + throwbackError(pc, "Failed to create mob of type " + loadID); + Logger.error("Failed to create mob of type " + + loadID); + } + } + return; + } + + + int loadID; + try { + loadID = Integer.parseInt(words[0]); + } catch (NumberFormatException e) { + throwbackError(pc, "Supplied type " + words[0] + + " failed to parse to an Integer"); + return; + } catch (Exception e) { + throwbackError(pc, + "An unknown exception occurred when trying to use mob command for type " + + words[0]); + return; // NaN + } + + + if (zone == null) { + throwbackError(pc, "Failed to find zone to place mob in."); + return; + } + + if (zone.isPlayerCity()) { + throwbackError(pc, "Cannot use ./mob on Player cities. Try ./servermob instead."); + return; + } + + + Mob mob = Mob.createMob(loadID, pc.getLoc(), + null, true, zone, null, 0, "", 1); + if (mob != null) { + mob.updateDatabase(); + ChatManager.chatSayInfo(pc, + "Mob with ID " + mob.getDBID() + " added"); + this.setResult(String.valueOf(mob.getDBID())); + } else { + throwbackError(pc, "Failed to create mob of type " + loadID); + Logger.error("Failed to create mob of type " + + loadID); + } + } + + @Override + protected String _getHelpString() { return "Creates a Mob of type 'mobID' at the location your character is standing"; - } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /mob mobID'"; - } + } } diff --git a/src/engine/devcmd/cmds/AddNPCCmd.java b/src/engine/devcmd/cmds/AddNPCCmd.java index a5bd5c87..e01ef111 100644 --- a/src/engine/devcmd/cmds/AddNPCCmd.java +++ b/src/engine/devcmd/cmds/AddNPCCmd.java @@ -18,91 +18,90 @@ import org.pmw.tinylog.Logger; /** * @author Eighty - * */ public class AddNPCCmd extends AbstractDevCmd { - public AddNPCCmd() { + public AddNPCCmd() { super("npc"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - int contractID; - String name = ""; - int level = 0; - - if (words.length < 2) { - this.sendUsage(pc); - return; - } - try { - contractID = Integer.parseInt(words[0]); - level = Integer.parseInt(words[1]); - - for (int i = 2; i < words.length; i++) { - name += words[i]; - if (i + 1 < words.length) - name += ""; - } - - } catch (NumberFormatException e) { - throwbackError(pc, - "Failed to parse supplied contractID or level to an Integer."); - return; // NaN - } - - Contract contract = DbManager.ContractQueries.GET_CONTRACT(contractID); - - if (contract == null || level < 1 || level > 75) { - throwbackError(pc, - "Invalid addNPC Command. Need contract ID, and level"); - return; // NaN - } - - // Pick a random name - if (name.isEmpty()) - name = NPCManager.getPirateName(contract.getMobbaseID()); - - Zone zone = ZoneManager.findSmallestZone(pc.getLoc()); - - if (zone == null) { - throwbackError(pc, "Failed to find zone to place npc in."); - return; - } - - if (target != null) - if (target.getObjectType() == GameObjectType.Building){ - Building parentBuilding = (Building)target; - BuildingManager.addHirelingForWorld(parentBuilding, pc, parentBuilding.getLoc(), parentBuilding.getParentZone(), contract, level); - return; - } - - NPC npc = NPC.createNPC(name, contractID, - pc.getLoc(), null, true, zone, (short) level, null); - - if (npc != null) { - WorldGrid.addObject(npc, pc); - ChatManager.chatSayInfo(pc, - "NPC with ID " + npc.getDBID() + " added"); - this.setResult(String.valueOf(npc.getDBID())); - } else { - throwbackError(pc, "Failed to create npc of contract type " - + contractID); - Logger.error( - "Failed to create npc of contract type " + contractID); - } - } - - @Override - protected String _getHelpString() { - return "Creates an NPC of type 'npcID' at the location your character is standing"; - } - - @Override - protected String _getUsageString() { - return "' /npc npcID level name'"; - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + int contractID; + String name = ""; + int level = 0; + + if (words.length < 2) { + this.sendUsage(pc); + return; + } + try { + contractID = Integer.parseInt(words[0]); + level = Integer.parseInt(words[1]); + + for (int i = 2; i < words.length; i++) { + name += words[i]; + if (i + 1 < words.length) + name += ""; + } + + } catch (NumberFormatException e) { + throwbackError(pc, + "Failed to parse supplied contractID or level to an Integer."); + return; // NaN + } + + Contract contract = DbManager.ContractQueries.GET_CONTRACT(contractID); + + if (contract == null || level < 1 || level > 75) { + throwbackError(pc, + "Invalid addNPC Command. Need contract ID, and level"); + return; // NaN + } + + // Pick a random name + if (name.isEmpty()) + name = NPCManager.getPirateName(contract.getMobbaseID()); + + Zone zone = ZoneManager.findSmallestZone(pc.getLoc()); + + if (zone == null) { + throwbackError(pc, "Failed to find zone to place npc in."); + return; + } + + if (target != null) + if (target.getObjectType() == GameObjectType.Building) { + Building parentBuilding = (Building) target; + BuildingManager.addHirelingForWorld(parentBuilding, pc, parentBuilding.getLoc(), parentBuilding.getParentZone(), contract, level); + return; + } + + NPC npc = NPC.createNPC(name, contractID, + pc.getLoc(), null, true, zone, (short) level, null); + + if (npc != null) { + WorldGrid.addObject(npc, pc); + ChatManager.chatSayInfo(pc, + "NPC with ID " + npc.getDBID() + " added"); + this.setResult(String.valueOf(npc.getDBID())); + } else { + throwbackError(pc, "Failed to create npc of contract type " + + contractID); + Logger.error( + "Failed to create npc of contract type " + contractID); + } + } + + @Override + protected String _getHelpString() { + return "Creates an NPC of type 'npcID' at the location your character is standing"; + } + + @Override + protected String _getUsageString() { + return "' /npc npcID level name'"; + } } diff --git a/src/engine/devcmd/cmds/ApplyBonusCmd.java b/src/engine/devcmd/cmds/ApplyBonusCmd.java index 76234e1c..898332fc 100644 --- a/src/engine/devcmd/cmds/ApplyBonusCmd.java +++ b/src/engine/devcmd/cmds/ApplyBonusCmd.java @@ -26,133 +26,131 @@ import java.util.HashSet; public class ApplyBonusCmd extends AbstractDevCmd { - public ApplyBonusCmd() { - super("applybonus"); - } - - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] words, - AbstractGameObject target) { - - String action = words[0]; - - PowerActionType actionType = null; - - HashMap> appliedMods = new HashMap<>(); - - try{ - - if (action.equals("all") == false) - for (PowerActionType powerActionType : PowerActionType.values()){ - if (powerActionType.name().equalsIgnoreCase(action) == false) - continue; - actionType = powerActionType; - break; - } - - }catch(Exception e){ - this.throwbackError(pcSender, "Invalid power Action type for " + action); - this.throwbackInfo(pcSender, "Valid Types : " + this.getActionTypes()); - return; - } - if (action.equals("all") == false) - if (actionType == null){ - this.throwbackError(pcSender, "Invalid power Action type for " + action); - this.throwbackInfo(pcSender, "Valid Types : " + this.getActionTypes()); - return; - } - - - for (PowersBase pb : PowersManager.powersBaseByIDString.values()){ - if (pb.getActions() == null || pb.getActions().isEmpty()) - continue; - - for (ActionsBase ab: pb.getActions()){ - if (ab.getPowerAction() == null) - continue; - if (action.equals("all") == false) - if (ab.getPowerAction().getType().equalsIgnoreCase(action) == false) - continue; - String effect1 = ""; - String effect2 = ""; - ChatManager.chatSystemInfo(pcSender,"Applying Power " + pb.getName() + " : " +pb.getDescription()); - if (ab.getPowerAction().getEffectsBase() == null){ - - try { - PowersManager.runPowerAction(pcSender, pcSender, pcSender.getLoc(), ab, 1, pb); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - ThreadUtils.sleep(500); - continue; - } - - - if (ab.getPowerAction().getEffectsBase().getModifiers() == null || ab.getPowerAction().getEffectsBase().getModifiers().isEmpty()){ - try { - PowersManager.runPowerAction(pcSender, pcSender, pcSender.getLoc(), ab, 1, pb); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - continue; - } - - boolean run = true; - for (AbstractEffectModifier mod : ab.getPowerAction().getEffectsBase().getModifiers()){ - if (appliedMods.containsKey(mod.modType.name()) == false){ - appliedMods.put(mod.modType.name(), new HashSet<>()); - } - + public ApplyBonusCmd() { + super("applybonus"); + } + + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] words, + AbstractGameObject target) { + + String action = words[0]; + + PowerActionType actionType = null; + + HashMap> appliedMods = new HashMap<>(); + + try { + + if (action.equals("all") == false) + for (PowerActionType powerActionType : PowerActionType.values()) { + if (powerActionType.name().equalsIgnoreCase(action) == false) + continue; + actionType = powerActionType; + break; + } + + } catch (Exception e) { + this.throwbackError(pcSender, "Invalid power Action type for " + action); + this.throwbackInfo(pcSender, "Valid Types : " + this.getActionTypes()); + return; + } + if (action.equals("all") == false) + if (actionType == null) { + this.throwbackError(pcSender, "Invalid power Action type for " + action); + this.throwbackInfo(pcSender, "Valid Types : " + this.getActionTypes()); + return; + } + + + for (PowersBase pb : PowersManager.powersBaseByIDString.values()) { + if (pb.getActions() == null || pb.getActions().isEmpty()) + continue; + + for (ActionsBase ab : pb.getActions()) { + if (ab.getPowerAction() == null) + continue; + if (action.equals("all") == false) + if (ab.getPowerAction().getType().equalsIgnoreCase(action) == false) + continue; + String effect1 = ""; + String effect2 = ""; + ChatManager.chatSystemInfo(pcSender, "Applying Power " + pb.getName() + " : " + pb.getDescription()); + if (ab.getPowerAction().getEffectsBase() == null) { + + try { + PowersManager.runPowerAction(pcSender, pcSender, pcSender.getLoc(), ab, 1, pb); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + ThreadUtils.sleep(500); + continue; + } + + + if (ab.getPowerAction().getEffectsBase().getModifiers() == null || ab.getPowerAction().getEffectsBase().getModifiers().isEmpty()) { + try { + PowersManager.runPowerAction(pcSender, pcSender, pcSender.getLoc(), ab, 1, pb); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + continue; + } + + boolean run = true; + for (AbstractEffectModifier mod : ab.getPowerAction().getEffectsBase().getModifiers()) { + if (appliedMods.containsKey(mod.modType.name()) == false) { + appliedMods.put(mod.modType.name(), new HashSet<>()); + } + // if (appliedMods.get(mod.modType.name()).contains(mod.sourceType.name())){ // continue; // } - - appliedMods.get(mod.modType.name()).add(mod.sourceType.name()); - try{ - try { - PowersManager.runPowerAction(pcSender, pcSender, pcSender.getLoc(), ab, 1, pb); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - }catch(Exception e){ - Logger.error(e); - } - break; - - - - - } - - } - } - } - - - @Override - protected String _getUsageString() { - return "' /bounds'"; - } - - @Override - protected String _getHelpString() { - return "Audits all the mobs in a zone."; - - } - - private String getActionTypes(){ - String output = ""; - - for (PowerActionType actionType : PowerActionType.values()){ - output += actionType.name() + " | "; - - } - - return output.substring(0, output.length() -3); - } + + appliedMods.get(mod.modType.name()).add(mod.sourceType.name()); + try { + try { + PowersManager.runPowerAction(pcSender, pcSender, pcSender.getLoc(), ab, 1, pb); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } catch (Exception e) { + Logger.error(e); + } + break; + + + } + + } + } + } + + + @Override + protected String _getUsageString() { + return "' /bounds'"; + } + + @Override + protected String _getHelpString() { + return "Audits all the mobs in a zone."; + + } + + private String getActionTypes() { + String output = ""; + + for (PowerActionType actionType : PowerActionType.values()) { + output += actionType.name() + " | "; + + } + + return output.substring(0, output.length() - 3); + } } diff --git a/src/engine/devcmd/cmds/ApplyStatModCmd.java b/src/engine/devcmd/cmds/ApplyStatModCmd.java index 21bf52ab..c2797ce6 100644 --- a/src/engine/devcmd/cmds/ApplyStatModCmd.java +++ b/src/engine/devcmd/cmds/ApplyStatModCmd.java @@ -21,129 +21,124 @@ import engine.powers.PowersBase; import java.util.ArrayList; /** - * * @author Eighty - * */ public class ApplyStatModCmd extends AbstractDevCmd { - public ApplyStatModCmd() { + private static int cnt = 0; + + public ApplyStatModCmd() { super("applystatmod"); } - private static int cnt = 0; - - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - if(args.length < 1) { - // if(args.length < 2) { - this.sendUsage(pcSender); - return; - } + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] args, + AbstractGameObject target) { + if (args.length < 1) { + // if(args.length < 2) { + this.sendUsage(pcSender); + return; + } - if(!(target instanceof AbstractCharacter)) { - this.sendHelp(pcSender); - return; - } + if (!(target instanceof AbstractCharacter)) { + this.sendHelp(pcSender); + return; + } this.setTarget(pcSender); //for logging - int spellID; - int powerAction = 0; - if (args[0].toLowerCase().contains("all")){ - - int amount = 0; - if (args.length == 1) { - amount = ApplyStatModCmd.cnt; - ApplyStatModCmd.cnt++; - } else { - amount = Integer.valueOf(args[1]); - ApplyStatModCmd.cnt = amount+1; - } - - - ArrayList pbList = new ArrayList<>(); - pbList.add(PowersManager.getPowerByToken(429047968)); - pbList.add(PowersManager.getPowerByToken(429768864)); - pbList.add(PowersManager.getPowerByToken(428458144)); - pbList.add(PowersManager.getPowerByToken(428677994)); - pbList.add(PowersManager.getPowerByToken(431874079)); - pbList.add(PowersManager.getPowerByToken(431081336)); - - - - - - for (PowersBase pb:pbList){ - if(amount <= 0) { - if (pb.getToken() ==428677994) - powerAction = 1; - PowersManager.removeEffect(pcSender, pb.getActions().get(powerAction), false, false); - continue; - } else if(amount > 9999 || amount < 21) { - ChatManager.chatSystemInfo(pcSender, "Amount must be between 21 and 9999 inclusive."); - return; - } - - if (pb.getToken() ==428677994){ - PowersManager.removeEffect(pcSender, pb.getActions().get(powerAction), false, false); - PowersManager.runPowerAction(pcSender, pcSender, Vector3fImmutable.ZERO, pb.getActions().get(powerAction), amount - 20, pb); - } - if (pb.getToken() ==428677994) - powerAction = 1; - PowersManager.removeEffect(pcSender, pb.getActions().get(powerAction), false, false); - PowersManager.runPowerAction(pcSender, pcSender, Vector3fImmutable.ZERO, pb.getActions().get(powerAction), amount - 20, pb); - } - return; - } - if(args[0].toLowerCase().contains("con")) { - spellID = 429047968; //Blessing of Health - } else if(args[0].toLowerCase().contains("str")) { - spellID = 429768864; //Blessing of Might - } else if(args[0].toLowerCase().contains("dex")) { - spellID = 428458144; //Blessing of Dexterity - } else if(args[0].toLowerCase().contains("int")) { - spellID = 428677994; //Bard Spi - TODO - powerAction = 1; - } else if(args[0].toLowerCase().contains("spi")) { - spellID = 428677994; //Bard Spi - } else{ - ChatManager.chatSystemInfo(pcSender, "No valid stat found."); - return; - } - - PowersBase pb = PowersManager.getPowerByToken(spellID); - - int amount = 0; - if (args.length == 1) { - amount = ApplyStatModCmd.cnt; - ApplyStatModCmd.cnt++; - } else { - amount = Integer.valueOf(args[1]); - ApplyStatModCmd.cnt = amount+1; - } - // int amount = Integer.valueOf(args[1]); - if(amount <= 0) { - PowersManager.removeEffect(pcSender, pb.getActions().get(powerAction), false, false); - return; - } else if(amount > 9999 || amount < 21) { - ChatManager.chatSystemInfo(pcSender, "Amount must be between 21 and 9999 inclusive."); - return; - } - - PowersManager.removeEffect(pcSender, pb.getActions().get(powerAction), false, false); - PowersManager.runPowerAction(pcSender, pcSender, Vector3fImmutable.ZERO, pb.getActions().get(powerAction), amount - 20, pb); - } - - @Override - protected String _getUsageString() { + int spellID; + int powerAction = 0; + if (args[0].toLowerCase().contains("all")) { + + int amount = 0; + if (args.length == 1) { + amount = ApplyStatModCmd.cnt; + ApplyStatModCmd.cnt++; + } else { + amount = Integer.valueOf(args[1]); + ApplyStatModCmd.cnt = amount + 1; + } + + + ArrayList pbList = new ArrayList<>(); + pbList.add(PowersManager.getPowerByToken(429047968)); + pbList.add(PowersManager.getPowerByToken(429768864)); + pbList.add(PowersManager.getPowerByToken(428458144)); + pbList.add(PowersManager.getPowerByToken(428677994)); + pbList.add(PowersManager.getPowerByToken(431874079)); + pbList.add(PowersManager.getPowerByToken(431081336)); + + + for (PowersBase pb : pbList) { + if (amount <= 0) { + if (pb.getToken() == 428677994) + powerAction = 1; + PowersManager.removeEffect(pcSender, pb.getActions().get(powerAction), false, false); + continue; + } else if (amount > 9999 || amount < 21) { + ChatManager.chatSystemInfo(pcSender, "Amount must be between 21 and 9999 inclusive."); + return; + } + + if (pb.getToken() == 428677994) { + PowersManager.removeEffect(pcSender, pb.getActions().get(powerAction), false, false); + PowersManager.runPowerAction(pcSender, pcSender, Vector3fImmutable.ZERO, pb.getActions().get(powerAction), amount - 20, pb); + } + if (pb.getToken() == 428677994) + powerAction = 1; + PowersManager.removeEffect(pcSender, pb.getActions().get(powerAction), false, false); + PowersManager.runPowerAction(pcSender, pcSender, Vector3fImmutable.ZERO, pb.getActions().get(powerAction), amount - 20, pb); + } + return; + } + if (args[0].toLowerCase().contains("con")) { + spellID = 429047968; //Blessing of Health + } else if (args[0].toLowerCase().contains("str")) { + spellID = 429768864; //Blessing of Might + } else if (args[0].toLowerCase().contains("dex")) { + spellID = 428458144; //Blessing of Dexterity + } else if (args[0].toLowerCase().contains("int")) { + spellID = 428677994; //Bard Spi - TODO + powerAction = 1; + } else if (args[0].toLowerCase().contains("spi")) { + spellID = 428677994; //Bard Spi + } else { + ChatManager.chatSystemInfo(pcSender, "No valid stat found."); + return; + } + + PowersBase pb = PowersManager.getPowerByToken(spellID); + + int amount = 0; + if (args.length == 1) { + amount = ApplyStatModCmd.cnt; + ApplyStatModCmd.cnt++; + } else { + amount = Integer.valueOf(args[1]); + ApplyStatModCmd.cnt = amount + 1; + } + // int amount = Integer.valueOf(args[1]); + if (amount <= 0) { + PowersManager.removeEffect(pcSender, pb.getActions().get(powerAction), false, false); + return; + } else if (amount > 9999 || amount < 21) { + ChatManager.chatSystemInfo(pcSender, "Amount must be between 21 and 9999 inclusive."); + return; + } + + PowersManager.removeEffect(pcSender, pb.getActions().get(powerAction), false, false); + PowersManager.runPowerAction(pcSender, pcSender, Vector3fImmutable.ZERO, pb.getActions().get(powerAction), amount - 20, pb); + } + + @Override + protected String _getUsageString() { return "' /applystatmod [trains]'"; - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "You must be targeting a player!"; - } + } } diff --git a/src/engine/devcmd/cmds/AuditFailedItemsCmd.java b/src/engine/devcmd/cmds/AuditFailedItemsCmd.java index 216e05fb..e92e0b87 100644 --- a/src/engine/devcmd/cmds/AuditFailedItemsCmd.java +++ b/src/engine/devcmd/cmds/AuditFailedItemsCmd.java @@ -20,111 +20,108 @@ import org.pmw.tinylog.Logger; public class AuditFailedItemsCmd extends AbstractDevCmd { - public AuditFailedItemsCmd() { - super("faileditems"); - } - - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] words, - AbstractGameObject target) { - - - - if (ItemProductionManager.FailedItems.isEmpty()) - return; - - Logger.info("Auditing Item production Failed Items"); - - String newLine = "\r\n"; - String auditFailedItem = "Failed Item Name | Prefix | Suffix | NPC | Contract | Player | "; - - for (ProducedItem failedItem: ItemProductionManager.FailedItems){ - - String npcName = ""; - String playerName =""; - String contractName = ""; - - String prefix = ""; - String suffix = ""; - String itemName = ""; - NPC npc = NPC.getFromCache(failedItem.getNpcUID()); - - if (npc == null){ - npcName = "null"; - contractName = "null"; - }else{ - npcName = npc.getName(); - if (npc.getContract() != null) - contractName = npc.getContract().getName(); - } - - PlayerCharacter roller = PlayerCharacter.getFromCache(failedItem.getPlayerID()); - - if (roller == null) - playerName = "null"; - else - playerName = roller.getName(); - - ItemBase ib = ItemBase.getItemBase(failedItem.getItemBaseID()); - - if (ib != null){ - itemName = ib.getName(); - } - - if (failedItem.isRandom() == false){ - if (failedItem.getPrefix().isEmpty() == false){ - AbstractPowerAction pa = PowersManager.getPowerActionByIDString(failedItem.getPrefix()); - if (pa != null){ - for (AbstractEffectModifier aem : pa.getEffectsBase().getModifiers()){ - if (aem.modType.equals(ModType.ItemName)){ - prefix = aem.getString1(); - break; - } - } - } - - } - - if (failedItem.getSuffix().isEmpty() == false){ - AbstractPowerAction pa = PowersManager.getPowerActionByIDString(failedItem.getSuffix()); - if (pa != null){ - for (AbstractEffectModifier aem : pa.getEffectsBase().getModifiers()){ - if (aem.modType.equals(ModType.ItemName)){ - suffix = aem.getString1(); - break; - } - } - } - - } - - }else{ - prefix = "random"; - } - - - - - auditFailedItem += newLine; - auditFailedItem += itemName + " | "+prefix + " | "+suffix + " | "+ failedItem.getNpcUID() + ":" +npcName + " | "+contractName + " | "+failedItem.getPlayerID() + ":" +playerName; - - } - Logger.info(auditFailedItem); - ItemProductionManager.FailedItems.clear(); - - - } - - - @Override - protected String _getUsageString() { - return "' /bounds'"; - } - - @Override - protected String _getHelpString() { - return "Audits all the mobs in a zone."; - - } + public AuditFailedItemsCmd() { + super("faileditems"); + } + + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] words, + AbstractGameObject target) { + + + if (ItemProductionManager.FailedItems.isEmpty()) + return; + + Logger.info("Auditing Item production Failed Items"); + + String newLine = "\r\n"; + String auditFailedItem = "Failed Item Name | Prefix | Suffix | NPC | Contract | Player | "; + + for (ProducedItem failedItem : ItemProductionManager.FailedItems) { + + String npcName = ""; + String playerName = ""; + String contractName = ""; + + String prefix = ""; + String suffix = ""; + String itemName = ""; + NPC npc = NPC.getFromCache(failedItem.getNpcUID()); + + if (npc == null) { + npcName = "null"; + contractName = "null"; + } else { + npcName = npc.getName(); + if (npc.getContract() != null) + contractName = npc.getContract().getName(); + } + + PlayerCharacter roller = PlayerCharacter.getFromCache(failedItem.getPlayerID()); + + if (roller == null) + playerName = "null"; + else + playerName = roller.getName(); + + ItemBase ib = ItemBase.getItemBase(failedItem.getItemBaseID()); + + if (ib != null) { + itemName = ib.getName(); + } + + if (failedItem.isRandom() == false) { + if (failedItem.getPrefix().isEmpty() == false) { + AbstractPowerAction pa = PowersManager.getPowerActionByIDString(failedItem.getPrefix()); + if (pa != null) { + for (AbstractEffectModifier aem : pa.getEffectsBase().getModifiers()) { + if (aem.modType.equals(ModType.ItemName)) { + prefix = aem.getString1(); + break; + } + } + } + + } + + if (failedItem.getSuffix().isEmpty() == false) { + AbstractPowerAction pa = PowersManager.getPowerActionByIDString(failedItem.getSuffix()); + if (pa != null) { + for (AbstractEffectModifier aem : pa.getEffectsBase().getModifiers()) { + if (aem.modType.equals(ModType.ItemName)) { + suffix = aem.getString1(); + break; + } + } + } + + } + + } else { + prefix = "random"; + } + + + auditFailedItem += newLine; + auditFailedItem += itemName + " | " + prefix + " | " + suffix + " | " + failedItem.getNpcUID() + ":" + npcName + " | " + contractName + " | " + failedItem.getPlayerID() + ":" + playerName; + + } + Logger.info(auditFailedItem); + ItemProductionManager.FailedItems.clear(); + + + } + + + @Override + protected String _getUsageString() { + return "' /bounds'"; + } + + @Override + protected String _getHelpString() { + return "Audits all the mobs in a zone."; + + } } diff --git a/src/engine/devcmd/cmds/AuditHeightMapCmd.java b/src/engine/devcmd/cmds/AuditHeightMapCmd.java index 74e9005a..66e6d1ed 100644 --- a/src/engine/devcmd/cmds/AuditHeightMapCmd.java +++ b/src/engine/devcmd/cmds/AuditHeightMapCmd.java @@ -20,52 +20,51 @@ import engine.objects.Zone; public class AuditHeightMapCmd extends AbstractDevCmd { - public AuditHeightMapCmd() { + public AuditHeightMapCmd() { super("auditheightmap"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] words, - AbstractGameObject target) { + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] words, + AbstractGameObject target) { - int count = Integer.parseInt(words[0]); - long start = System.currentTimeMillis(); - for (int i = 0; i= count) { + plusplus++; + throwbackInfo(pcSender, zoneMicro.getName() + " at location " + zoneMicro.getLoc().toString() + " has " + size + " mobs. "); + System.out.println(zoneMicro.getName() + " at location " + zoneMicro.getLoc().toString() + " has " + size + " mobs. "); + } + + + } + throwbackInfo(pcSender, " there are " + plusplus + " zones with at least " + count + " mobs in each."); + } + return; + } + if (words.length > 1) { + this.sendUsage(pcSender); + return; + } else if (words.length == 1) { + int uuid; + try { + uuid = Integer.parseInt(words[0]); + zone = ZoneManager.getZoneByUUID(uuid); + } catch (NumberFormatException e) { + zone = ZoneManager.findSmallestZone(pcSender.getLoc()); + } + } else + zone = ZoneManager.findSmallestZone(pcSender.getLoc()); + + if (zone == null) { + throwbackError(pcSender, "Unable to find the zone"); + return; + } + + //get list of mobs for zone + + if (zone.zoneMobSet.isEmpty()) { + throwbackError(pcSender, "No mobs found for this zone."); + return; + } + + // ConcurrentHashMap spawnMap = Mob.getSpawnMap(); + //ConcurrentHashMap respawnMap = Mob.getRespawnMap(); + // ConcurrentHashMap despawnMap = Mob.getDespawnMap(); + + throwbackInfo(pcSender, zone.getName() + ", numMobs: " + zone.zoneMobSet.size()); + throwbackInfo(pcSender, "UUID, dbID, inRespawnMap, isAlive, activeAI, Loc"); + + + //mob not found in spawn map, check respawn + boolean inRespawn = false; - //get Zone to check mobs against - Zone zone; - - if (words.length == 2){ - if (words[0].equals("all")){ - int plusplus = 0; - int count = Integer.parseInt(words[1]); - for (Zone zoneMicro: ZoneManager.getAllZones()){ - int size = zoneMicro.zoneMobSet.size(); - - if (size >= count){ - plusplus++; - throwbackInfo(pcSender, zoneMicro.getName() + " at location " + zoneMicro.getLoc().toString() + " has " + size + " mobs. "); - System.out.println(zoneMicro.getName() + " at location " + zoneMicro.getLoc().toString() + " has " + size + " mobs. "); - } - - - } - throwbackInfo(pcSender," there are " +plusplus + " zones with at least " + count + " mobs in each."); - } - return; - } - if (words.length > 1) { - this.sendUsage(pcSender); - return; - } else if (words.length == 1) { - int uuid; - try { - uuid = Integer.parseInt(words[0]); - zone = ZoneManager.getZoneByUUID(uuid); - } catch (NumberFormatException e) { - zone = ZoneManager.findSmallestZone(pcSender.getLoc()); - } - } else - zone = ZoneManager.findSmallestZone(pcSender.getLoc()); - - if (zone == null) { - throwbackError(pcSender, "Unable to find the zone"); - return; - } - - //get list of mobs for zone - - if (zone.zoneMobSet.isEmpty()) { - throwbackError(pcSender, "No mobs found for this zone."); - return; - } - - // ConcurrentHashMap spawnMap = Mob.getSpawnMap(); - //ConcurrentHashMap respawnMap = Mob.getRespawnMap(); - // ConcurrentHashMap despawnMap = Mob.getDespawnMap(); - - throwbackInfo(pcSender, zone.getName() + ", numMobs: " + zone.zoneMobSet.size()); - throwbackInfo(pcSender, "UUID, dbID, inRespawnMap, isAlive, activeAI, Loc"); - - - - //mob not found in spawn map, check respawn - boolean inRespawn = false; - - - - } + } - @Override - protected String _getUsageString() { - return "' /auditmobs [zone.UUID]'"; - } + @Override + protected String _getUsageString() { + return "' /auditmobs [zone.UUID]'"; + } - @Override - protected String _getHelpString() { - return "Audits all the mobs in a zone."; + @Override + protected String _getHelpString() { + return "Audits all the mobs in a zone."; - } + } } diff --git a/src/engine/devcmd/cmds/BoundsCmd.java b/src/engine/devcmd/cmds/BoundsCmd.java index dc5e6835..e6a1a7aa 100644 --- a/src/engine/devcmd/cmds/BoundsCmd.java +++ b/src/engine/devcmd/cmds/BoundsCmd.java @@ -17,61 +17,61 @@ import engine.objects.PlayerCharacter; public class BoundsCmd extends AbstractDevCmd { - public BoundsCmd() { + public BoundsCmd() { super("bounds"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] words, - AbstractGameObject target) { - if (target == null || !target.getObjectType().equals(GameObjectType.Building)){ - this.throwbackError(pcSender, "No Building Selected"); - return; - } - - Building building = (Building)target; - - if (building.getBounds() == null){ - this.throwbackInfo(pcSender, "No valid Bounds for building UUID " + building.getObjectUUID()); - return; - } - float topLeftX = building.getLoc().x - building.getBounds().getHalfExtents().x; - float topLeftY = building.getLoc().z - building.getBounds().getHalfExtents().y; - - float topRightX = building.getLoc().x + building.getBounds().getHalfExtents().x; - float topRightY = building.getLoc().z - building.getBounds().getHalfExtents().y; - - float bottomLeftX = building.getLoc().x - building.getBounds().getHalfExtents().x; - float bottomLeftY = building.getLoc().z + building.getBounds().getHalfExtents().y; - - float bottomRightX = building.getLoc().x + building.getBounds().getHalfExtents().x; - float bottomRightY = building.getLoc().z + building.getBounds().getHalfExtents().y; - - String newLine = "\r\n "; - - String output = "Bounds Information for Building UUID " + building.getObjectUUID(); - output += newLine; - - output+= "Top Left : " + topLeftX + " , " + topLeftY + newLine; - output+= "Top Right : " + topRightX + " , " + topRightY + newLine; - output+= "Bottom Left : " + bottomLeftX + " , " + bottomLeftY + newLine; - output+= "Bottom Right : " + bottomRightX + " , " + bottomRightY + newLine; - - this.throwbackInfo(pcSender, output); - - - } - - - @Override - protected String _getUsageString() { - return "' /bounds'"; - } - - @Override - protected String _getHelpString() { - return "Audits all the mobs in a zone."; - - } + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] words, + AbstractGameObject target) { + if (target == null || !target.getObjectType().equals(GameObjectType.Building)) { + this.throwbackError(pcSender, "No Building Selected"); + return; + } + + Building building = (Building) target; + + if (building.getBounds() == null) { + this.throwbackInfo(pcSender, "No valid Bounds for building UUID " + building.getObjectUUID()); + return; + } + float topLeftX = building.getLoc().x - building.getBounds().getHalfExtents().x; + float topLeftY = building.getLoc().z - building.getBounds().getHalfExtents().y; + + float topRightX = building.getLoc().x + building.getBounds().getHalfExtents().x; + float topRightY = building.getLoc().z - building.getBounds().getHalfExtents().y; + + float bottomLeftX = building.getLoc().x - building.getBounds().getHalfExtents().x; + float bottomLeftY = building.getLoc().z + building.getBounds().getHalfExtents().y; + + float bottomRightX = building.getLoc().x + building.getBounds().getHalfExtents().x; + float bottomRightY = building.getLoc().z + building.getBounds().getHalfExtents().y; + + String newLine = "\r\n "; + + String output = "Bounds Information for Building UUID " + building.getObjectUUID(); + output += newLine; + + output += "Top Left : " + topLeftX + " , " + topLeftY + newLine; + output += "Top Right : " + topRightX + " , " + topRightY + newLine; + output += "Bottom Left : " + bottomLeftX + " , " + bottomLeftY + newLine; + output += "Bottom Right : " + bottomRightX + " , " + bottomRightY + newLine; + + this.throwbackInfo(pcSender, output); + + + } + + + @Override + protected String _getUsageString() { + return "' /bounds'"; + } + + @Override + protected String _getHelpString() { + return "Audits all the mobs in a zone."; + + } } diff --git a/src/engine/devcmd/cmds/ChangeNameCmd.java b/src/engine/devcmd/cmds/ChangeNameCmd.java index 3ef3e095..e8676bdd 100644 --- a/src/engine/devcmd/cmds/ChangeNameCmd.java +++ b/src/engine/devcmd/cmds/ChangeNameCmd.java @@ -19,96 +19,96 @@ import engine.util.MiscUtils; public class ChangeNameCmd extends AbstractDevCmd { - public ChangeNameCmd() { - super("changename"); - } - - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - Vector3fImmutable loc = null; - - // Arg Count Check - if (words.length < 2) { - this.sendUsage(pc); - return; - } - - String oldFirst = words[0]; - String newFirst = words[1]; - String newLast = ""; - if (words.length > 2) { - newLast = words[2]; - for (int i=3; i 50) { - this.throwbackError(pc, "Error: Last name is incorrect length. Must be no more than 50 characters"); - return; - } - - // Check if firstname is valid - if (MiscUtils.checkIfFirstNameInvalid(newFirst)) { - this.throwbackError(pc, "Error: First name is not allowed"); - return; - } - - - //get the world ID we're modifying for - - //test if first name is unique, unless new and old first name are equal. - if (!(oldFirst.equals(newFirst))) { - if (!DbManager.PlayerCharacterQueries.IS_CHARACTER_NAME_UNIQUE(newFirst)) { - this.throwbackError(pc, "Error: First name is not unique."); - return; - } - } - - //tests passed, update name in database - if (!DbManager.PlayerCharacterQueries.UPDATE_NAME(oldFirst, newFirst, newLast)) { - this.throwbackError(pc, "Error: Database failed to update the name."); - return; - } - - //Finally update player ingame - PlayerCharacter pcTar = null; - try { - pcTar = SessionManager - .getPlayerCharacterByLowerCaseName(words[0]); - pcTar.setFirstName(newFirst); - pcTar.setLastName(newLast); - this.setTarget(pcTar); //for logging - - //specify if last name is ascii characters only - String lastAscii = newLast.replaceAll("[^\\p{ASCII}]", ""); - pcTar.setAsciiLastName(lastAscii.equals(newLast)); - } catch (Exception e) { - this.throwbackError(pc, "Database was updated but ingame character failed to update."); - return; - } - - String out = oldFirst + " was changed to " + newFirst + (newLast.isEmpty() ? "." : (' ' + newLast + '.')); - this.throwbackInfo(pc, out); - - - } - - @Override - protected String _getHelpString() { - return "Changes the name of a player"; - } - - @Override - protected String _getUsageString() { - return "'./changename oldFirstName newFirstName newLastName'"; - } + public ChangeNameCmd() { + super("changename"); + } + + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + Vector3fImmutable loc = null; + + // Arg Count Check + if (words.length < 2) { + this.sendUsage(pc); + return; + } + + String oldFirst = words[0]; + String newFirst = words[1]; + String newLast = ""; + if (words.length > 2) { + newLast = words[2]; + for (int i = 3; i < words.length; i++) + newLast += ' ' + words[i]; + } + + //verify new name length + if (newFirst.length() < 3) { + this.throwbackError(pc, "Error: First name is incorrect length. Must be between 3 and 15 characters"); + return; + } + + //verify old name length + if (newLast.length() > 50) { + this.throwbackError(pc, "Error: Last name is incorrect length. Must be no more than 50 characters"); + return; + } + + // Check if firstname is valid + if (MiscUtils.checkIfFirstNameInvalid(newFirst)) { + this.throwbackError(pc, "Error: First name is not allowed"); + return; + } + + + //get the world ID we're modifying for + + //test if first name is unique, unless new and old first name are equal. + if (!(oldFirst.equals(newFirst))) { + if (!DbManager.PlayerCharacterQueries.IS_CHARACTER_NAME_UNIQUE(newFirst)) { + this.throwbackError(pc, "Error: First name is not unique."); + return; + } + } + + //tests passed, update name in database + if (!DbManager.PlayerCharacterQueries.UPDATE_NAME(oldFirst, newFirst, newLast)) { + this.throwbackError(pc, "Error: Database failed to update the name."); + return; + } + + //Finally update player ingame + PlayerCharacter pcTar = null; + try { + pcTar = SessionManager + .getPlayerCharacterByLowerCaseName(words[0]); + pcTar.setFirstName(newFirst); + pcTar.setLastName(newLast); + this.setTarget(pcTar); //for logging + + //specify if last name is ascii characters only + String lastAscii = newLast.replaceAll("[^\\p{ASCII}]", ""); + pcTar.setAsciiLastName(lastAscii.equals(newLast)); + } catch (Exception e) { + this.throwbackError(pc, "Database was updated but ingame character failed to update."); + return; + } + + String out = oldFirst + " was changed to " + newFirst + (newLast.isEmpty() ? "." : (' ' + newLast + '.')); + this.throwbackInfo(pc, out); + + + } + + @Override + protected String _getHelpString() { + return "Changes the name of a player"; + } + + @Override + protected String _getUsageString() { + return "'./changename oldFirstName newFirstName newLastName'"; + } } diff --git a/src/engine/devcmd/cmds/CombatMessageCmd.java b/src/engine/devcmd/cmds/CombatMessageCmd.java index f1847562..a3615e89 100644 --- a/src/engine/devcmd/cmds/CombatMessageCmd.java +++ b/src/engine/devcmd/cmds/CombatMessageCmd.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -27,44 +24,42 @@ import engine.objects.AbstractGameObject; import engine.objects.PlayerCharacter; /** - * * @author Eighty - * */ public class CombatMessageCmd extends AbstractDevCmd { - public CombatMessageCmd() { + public CombatMessageCmd() { super("cm"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - if (pcSender == null) - return; - if (args.length != 1) { - this.sendUsage(pcSender); - return; - } - int num = 0; - try { - num = Integer.parseInt(args[0]); - } catch (NumberFormatException e) { - throwbackError(pcSender, "Supplied message number " + args[0] + " failed to parse to an Integer"); - return; - } - TargetedActionMsg.un2cnt = num; - throwbackInfo(pcSender, "CombatMessage set to " + num); - } + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] args, + AbstractGameObject target) { + if (pcSender == null) + return; + if (args.length != 1) { + this.sendUsage(pcSender); + return; + } + int num = 0; + try { + num = Integer.parseInt(args[0]); + } catch (NumberFormatException e) { + throwbackError(pcSender, "Supplied message number " + args[0] + " failed to parse to an Integer"); + return; + } + TargetedActionMsg.un2cnt = num; + throwbackInfo(pcSender, "CombatMessage set to " + num); + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /cm [cmNumber]'"; - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Sets the combat message to the supplied integer value"; - } + } } diff --git a/src/engine/devcmd/cmds/CreateItemCmd.java b/src/engine/devcmd/cmds/CreateItemCmd.java index 2067a4dd..813f2b41 100644 --- a/src/engine/devcmd/cmds/CreateItemCmd.java +++ b/src/engine/devcmd/cmds/CreateItemCmd.java @@ -17,49 +17,48 @@ import engine.objects.PlayerCharacter; /** * @author Eighty - * */ public class CreateItemCmd extends AbstractDevCmd { - public CreateItemCmd() { + public CreateItemCmd() { super("createitem"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - if (words.length < 2) { - this.sendUsage(pc); - return; - } - int id; - id = ItemBase.getIDByName(words[0]); + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + if (words.length < 2) { + this.sendUsage(pc); + return; + } + int id; + id = ItemBase.getIDByName(words[0]); - if (id == 0) - id = Integer.parseInt(words[0]); - if (id == 7){ - this.throwbackInfo(pc, "use /addgold to add gold....."); - return; - } + if (id == 0) + id = Integer.parseInt(words[0]); + if (id == 7) { + this.throwbackInfo(pc, "use /addgold to add gold....."); + return; + } - int size = 1; + int size = 1; - if(words.length < 3) { - size = Integer.parseInt(words[1]); - } + if (words.length < 3) { + size = Integer.parseInt(words[1]); + } - ItemFactory.fillInventory(pc, id, size); + ItemFactory.fillInventory(pc, id, size); - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Fill your inventory with items"; - } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /createitem '"; - } + } } diff --git a/src/engine/devcmd/cmds/DebugCmd.java b/src/engine/devcmd/cmds/DebugCmd.java index 3a3f0110..ef1111c2 100644 --- a/src/engine/devcmd/cmds/DebugCmd.java +++ b/src/engine/devcmd/cmds/DebugCmd.java @@ -17,107 +17,106 @@ import engine.objects.PlayerCharacter; public class DebugCmd extends AbstractDevCmd { - - public DebugCmd() { - super("debug"); - // super("debug", MBServerStatics.ACCESS_GROUP_ALL_TEAM, 0, false, false); - } - - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - if (words.length < 2) { - this.sendUsage(pc); - return; - } - - if (pc == null) - return; - - //pc.setDebug must use bit sizes: 1, 2, 4, 8, 16, 32 - - String command = words[0].toLowerCase(); - boolean toggle = (words[1].toLowerCase().equals("on")) ? true : false; - - switch (command) { - case "magictrek": - pc.RUN_MAGICTREK = toggle; - - break; - case "combat": - pc.setDebug(64, toggle); - - break; - case "health": - toggleDebugTimer(pc, "Debug_Health", 1, 1000, toggle); - - break; - case "mana": - toggleDebugTimer(pc, "Debug_Mana", 2, 1000, toggle); - - break; - case "stamina": - toggleDebugTimer(pc, "Debug_Stamina", 3, 500, toggle); - - break; - case "spells": - pc.setDebug(16, toggle); - - break; - case "damageabsorber": - pc.setDebug(2, toggle); - - break; - case "recast": - case "recycle": - pc.setDebug(4, toggle); - - break; - case "seeinvis": - pc.setDebug(8, toggle); - - break; - case "movement": - pc.setDebug(1, toggle); - - break; - case "noaggro": - pc.setDebug(32, toggle); - - break; - // case "loot": - // MBServerStatics.debugLoot = toggle; - // break; - - default: - String output = "Debug for " + command + " not found."; - throwbackError(pc, output); - return; - } - - - setTarget(pc); //for logging - - String output = "Debug for " + command + " turned " + ((toggle) ? "on." : "off."); - throwbackInfo(pc, output); - } - - @Override - protected String _getHelpString() { - return "Runs debug commands"; - - } - - @Override - protected String _getUsageString() { - return "'./Debug command on/off'"; - } - - private static void toggleDebugTimer(PlayerCharacter pc, String name, int num, int duration, boolean toggle) { - if (toggle) { - DebugTimerJob dtj = new DebugTimerJob(pc, name, num, duration); - pc.renewTimer(name, dtj, duration); - } else - pc.cancelTimer(name); - } + public DebugCmd() { + super("debug"); + // super("debug", MBServerStatics.ACCESS_GROUP_ALL_TEAM, 0, false, false); + } + + private static void toggleDebugTimer(PlayerCharacter pc, String name, int num, int duration, boolean toggle) { + if (toggle) { + DebugTimerJob dtj = new DebugTimerJob(pc, name, num, duration); + pc.renewTimer(name, dtj, duration); + } else + pc.cancelTimer(name); + } + + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + if (words.length < 2) { + this.sendUsage(pc); + return; + } + + if (pc == null) + return; + + //pc.setDebug must use bit sizes: 1, 2, 4, 8, 16, 32 + + String command = words[0].toLowerCase(); + boolean toggle = (words[1].toLowerCase().equals("on")) ? true : false; + + switch (command) { + case "magictrek": + pc.RUN_MAGICTREK = toggle; + + break; + case "combat": + pc.setDebug(64, toggle); + + break; + case "health": + toggleDebugTimer(pc, "Debug_Health", 1, 1000, toggle); + + break; + case "mana": + toggleDebugTimer(pc, "Debug_Mana", 2, 1000, toggle); + + break; + case "stamina": + toggleDebugTimer(pc, "Debug_Stamina", 3, 500, toggle); + + break; + case "spells": + pc.setDebug(16, toggle); + + break; + case "damageabsorber": + pc.setDebug(2, toggle); + + break; + case "recast": + case "recycle": + pc.setDebug(4, toggle); + + break; + case "seeinvis": + pc.setDebug(8, toggle); + + break; + case "movement": + pc.setDebug(1, toggle); + + break; + case "noaggro": + pc.setDebug(32, toggle); + + break; + // case "loot": + // MBServerStatics.debugLoot = toggle; + // break; + + default: + String output = "Debug for " + command + " not found."; + throwbackError(pc, output); + return; + } + + + setTarget(pc); //for logging + + String output = "Debug for " + command + " turned " + ((toggle) ? "on." : "off."); + throwbackInfo(pc, output); + } + + @Override + protected String _getHelpString() { + return "Runs debug commands"; + + } + + @Override + protected String _getUsageString() { + return "'./Debug command on/off'"; + } } diff --git a/src/engine/devcmd/cmds/DebugMeleeSyncCmd.java b/src/engine/devcmd/cmds/DebugMeleeSyncCmd.java index baa189dc..ff97a168 100644 --- a/src/engine/devcmd/cmds/DebugMeleeSyncCmd.java +++ b/src/engine/devcmd/cmds/DebugMeleeSyncCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.devcmd.AbstractDevCmd; @@ -17,42 +16,42 @@ import engine.objects.PlayerCharacter; public class DebugMeleeSyncCmd extends AbstractDevCmd { - public DebugMeleeSyncCmd() { + public DebugMeleeSyncCmd() { super("debugmeleesync"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - // Arg Count Check - if (words.length != 1) { - this.sendUsage(pc); - return; - } - - String s = words[0].toLowerCase(); - - if (s.equals("on")) { - pc.setDebug(64, true); - ChatManager.chatSayInfo(pc, "Melee Sync Debug ON"); - } else if (s.equals("off")) { - pc.setDebug(64, false); - ChatManager.chatSayInfo(pc, "Melee Sync Debug OFF"); - } else { - this.sendUsage(pc); - } - } - - @Override - protected String _getHelpString() { - return "Turns on/off melee sync debugging."; - - } - - @Override - protected String _getUsageString() { - return "'./debugmeleesync on|off'"; - - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + // Arg Count Check + if (words.length != 1) { + this.sendUsage(pc); + return; + } + + String s = words[0].toLowerCase(); + + if (s.equals("on")) { + pc.setDebug(64, true); + ChatManager.chatSayInfo(pc, "Melee Sync Debug ON"); + } else if (s.equals("off")) { + pc.setDebug(64, false); + ChatManager.chatSayInfo(pc, "Melee Sync Debug OFF"); + } else { + this.sendUsage(pc); + } + } + + @Override + protected String _getHelpString() { + return "Turns on/off melee sync debugging."; + + } + + @Override + protected String _getUsageString() { + return "'./debugmeleesync on|off'"; + + } } diff --git a/src/engine/devcmd/cmds/DecachePlayerCmd.java b/src/engine/devcmd/cmds/DecachePlayerCmd.java index ef9caf4f..d4e006e2 100644 --- a/src/engine/devcmd/cmds/DecachePlayerCmd.java +++ b/src/engine/devcmd/cmds/DecachePlayerCmd.java @@ -20,35 +20,35 @@ import engine.objects.PlayerCharacter; */ public class DecachePlayerCmd extends AbstractDevCmd { - public DecachePlayerCmd() { + public DecachePlayerCmd() { super("decacheplayer"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - if(words.length < 1) { - this.sendUsage(pc); - } - - int objectUUID = Integer.parseInt(words[0]); - - if(DbManager.inCache(Enum.GameObjectType.PlayerCharacter, objectUUID)) { - this.setTarget(PlayerCharacter.getFromCache(objectUUID)); //for logging - PlayerCharacter.getFromCache(objectUUID).removeFromCache(); - } else { - this.sendHelp(pc); - } - } - - @Override - protected String _getHelpString() { + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + if (words.length < 1) { + this.sendUsage(pc); + } + + int objectUUID = Integer.parseInt(words[0]); + + if (DbManager.inCache(Enum.GameObjectType.PlayerCharacter, objectUUID)) { + this.setTarget(PlayerCharacter.getFromCache(objectUUID)); //for logging + PlayerCharacter.getFromCache(objectUUID).removeFromCache(); + } else { + this.sendHelp(pc); + } + } + + @Override + protected String _getHelpString() { return "No player found. Please make sure the table ID is correct."; - } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /decacheplayer '"; - } + } } diff --git a/src/engine/devcmd/cmds/DespawnCmd.java b/src/engine/devcmd/cmds/DespawnCmd.java index 18d54437..02f7ce98 100644 --- a/src/engine/devcmd/cmds/DespawnCmd.java +++ b/src/engine/devcmd/cmds/DespawnCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.Enum.GameObjectType; @@ -18,56 +17,50 @@ import engine.objects.PlayerCharacter; public class DespawnCmd extends AbstractDevCmd { - public DespawnCmd() { + public DespawnCmd() { super("debugmob"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - - - - - - if (pc == null) { - return; - } - - - - - - Mob mob = null; - - if (target != null && target.getObjectType().equals(GameObjectType.Mob)) - mob = (Mob)target; - - if (mob == null) - mob = Mob.getFromCache(Integer.parseInt(words[1])); - - if (mob == null) - return; - - if (words[0].equalsIgnoreCase("respawn")){ - mob.respawn(); - this.throwbackInfo(pc, "Mob with ID " + mob.getObjectUUID() + " Respawned"); - }else if (words[0].equalsIgnoreCase("despawn")){ - mob.despawn(); - this.throwbackInfo(pc, "Mob with ID " + mob.getObjectUUID() + " Despawned"); - } - } - - @Override - protected String _getHelpString() { - return "Gets distance from a target."; - - } - - @Override - protected String _getUsageString() { - return "' /distance'"; - - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + + + if (pc == null) { + return; + } + + + Mob mob = null; + + if (target != null && target.getObjectType().equals(GameObjectType.Mob)) + mob = (Mob) target; + + if (mob == null) + mob = Mob.getFromCache(Integer.parseInt(words[1])); + + if (mob == null) + return; + + if (words[0].equalsIgnoreCase("respawn")) { + mob.respawn(); + this.throwbackInfo(pc, "Mob with ID " + mob.getObjectUUID() + " Respawned"); + } else if (words[0].equalsIgnoreCase("despawn")) { + mob.despawn(); + this.throwbackInfo(pc, "Mob with ID " + mob.getObjectUUID() + " Despawned"); + } + } + + @Override + protected String _getHelpString() { + return "Gets distance from a target."; + + } + + @Override + protected String _getUsageString() { + return "' /distance'"; + + } } diff --git a/src/engine/devcmd/cmds/DistanceCmd.java b/src/engine/devcmd/cmds/DistanceCmd.java index 458531c2..81e02c3f 100644 --- a/src/engine/devcmd/cmds/DistanceCmd.java +++ b/src/engine/devcmd/cmds/DistanceCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.devcmd.AbstractDevCmd; @@ -18,51 +17,49 @@ import engine.objects.PlayerCharacter; public class DistanceCmd extends AbstractDevCmd { - public DistanceCmd() { + public DistanceCmd() { super("distance"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - - - - - // Arg Count Check - if (words.length != 1) { - this.sendUsage(pc); - return; - } - if (pc == null) { - return; - } - - if (target == null || !(target instanceof AbstractWorldObject)) { - throwbackError(pc, "No target found."); - return; - } - - AbstractWorldObject awoTarget = (AbstractWorldObject)target; - - Vector3fImmutable pcLoc = pc.getLoc(); - Vector3fImmutable tarLoc = awoTarget.getLoc(); - String out = "Distance: " + pcLoc.distance(tarLoc) + - "\r\nYour Loc: " + pcLoc.x + 'x' + pcLoc.y + 'x' + pcLoc.z + - "\r\nTarget Loc: " + tarLoc.x + 'x' + tarLoc.y + 'x' + tarLoc.z; - throwbackInfo(pc, out); - } - - @Override - protected String _getHelpString() { - return "Gets distance from a target."; - - } - - @Override - protected String _getUsageString() { - return "' /distance'"; - - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + + + // Arg Count Check + if (words.length != 1) { + this.sendUsage(pc); + return; + } + if (pc == null) { + return; + } + + if (target == null || !(target instanceof AbstractWorldObject)) { + throwbackError(pc, "No target found."); + return; + } + + AbstractWorldObject awoTarget = (AbstractWorldObject) target; + + Vector3fImmutable pcLoc = pc.getLoc(); + Vector3fImmutable tarLoc = awoTarget.getLoc(); + String out = "Distance: " + pcLoc.distance(tarLoc) + + "\r\nYour Loc: " + pcLoc.x + 'x' + pcLoc.y + 'x' + pcLoc.z + + "\r\nTarget Loc: " + tarLoc.x + 'x' + tarLoc.y + 'x' + tarLoc.z; + throwbackInfo(pc, out); + } + + @Override + protected String _getHelpString() { + return "Gets distance from a target."; + + } + + @Override + protected String _getUsageString() { + return "' /distance'"; + + } } diff --git a/src/engine/devcmd/cmds/EffectCmd.java b/src/engine/devcmd/cmds/EffectCmd.java index 74733945..8ad9ca8d 100644 --- a/src/engine/devcmd/cmds/EffectCmd.java +++ b/src/engine/devcmd/cmds/EffectCmd.java @@ -17,47 +17,45 @@ import engine.objects.PlayerCharacter; import engine.powers.EffectsBase; /** - * * @author Eighty - * */ public class EffectCmd extends AbstractDevCmd { - public EffectCmd() { + public EffectCmd() { super("effect"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - int ID = 0; - int token = 0; - - if (args.length != 2) { - this.sendUsage(pcSender); - return; - } - ID = Integer.parseInt(args[0]); - token = Integer.parseInt(args[1]); - - EffectsBase eb = PowersManager.setEffectToken(ID, token); - if (eb == null) { - throwbackError(pcSender, "Unable to find EffectsBase " + ID - + " to modify."); - return; - } - ChatManager.chatSayInfo(pcSender, - "EffectsBase with ID " + ID + " changed token to " + token); - } - - @Override - protected String _getUsageString() { + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] args, + AbstractGameObject target) { + int ID = 0; + int token = 0; + + if (args.length != 2) { + this.sendUsage(pcSender); + return; + } + ID = Integer.parseInt(args[0]); + token = Integer.parseInt(args[1]); + + EffectsBase eb = PowersManager.setEffectToken(ID, token); + if (eb == null) { + throwbackError(pcSender, "Unable to find EffectsBase " + ID + + " to modify."); + return; + } + ChatManager.chatSayInfo(pcSender, + "EffectsBase with ID " + ID + " changed token to " + token); + } + + @Override + protected String _getUsageString() { return "' /effect EffectsBaseID Token'"; - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Temporarily places the effect token with the corresponding EffectsBase on the server"; - } + } } diff --git a/src/engine/devcmd/cmds/EnchantCmd.java b/src/engine/devcmd/cmds/EnchantCmd.java index b6f2247c..1f23ae86 100644 --- a/src/engine/devcmd/cmds/EnchantCmd.java +++ b/src/engine/devcmd/cmds/EnchantCmd.java @@ -14,75 +14,74 @@ import engine.objects.*; public class EnchantCmd extends AbstractDevCmd { - public EnchantCmd() { + public EnchantCmd() { super("enchant"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - int rank = 0; - if (words.length < 1) { - this.sendUsage(pc); - return; - } - - - try{ - rank = Integer.parseInt(words[0]); - }catch(Exception e){ - - } - - - - Item item; - if (target == null || target instanceof Item) - item = (Item) target; - else { - throwbackError(pc, "Must have an item targeted"); - return; - } - - CharacterItemManager cim = pc.getCharItemManager(); - if (cim == null) { - throwbackError(pc, "Unable to find the character item manager for player " + pc.getFirstName() + '.'); - return; - } - - if (words[0].equals("clear")) { - item.clearEnchantments(); - cim.updateInventory(); - this.setResult(String.valueOf(item.getObjectUUID())); - } else { - int cnt = words.length; - for (int i=1;i container = WorldGrid.getObjectsInRangePartial( - searchPt, range, MBServerStatics.MASK_BUILDING); - - s += "Found " + container.size(); - s += " buildings within " + range; - s += " units of [" + searchPt.toString() + ']'; - throwbackInfo(pc, s); - - int index = 0; - for (AbstractWorldObject awo : container) { - Building b = (Building) awo; - - s = index + ")"; - s += " ObjectID: " + awo.getObjectUUID() + ']'; - s += " -> Name: " + b.getSimpleName(); - if (b.getBlueprint() == null) { - s += " No Blueprint"; - } else { - s += " Blueprint UUID: " + b.getBlueprint().getMeshForRank(0); - } - s += "[" + ((Building) awo).getBlueprintUUID() + ']'; - - throwbackInfo(pc, s); - ++index; - } - - } catch (NumberFormatException e) { - this.throwbackError(pc, "Supplied data: '" + words - + "' failed to parse to a Float."); - } catch (Exception e) { - this.throwbackError(pc, - "An unknown exception occurred while attempting to findBuildings with data: '" - + words + '\''); - } - } - - @Override - protected String _getHelpString() { - return "Sets your character's Mana to 'amount'"; - } - - @Override - protected String _getUsageString() { - return "' /findBuildings [lat long] [range]'"; - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + try { + Vector3fImmutable searchPt = pc.getLoc(); + float range = 50.0f; + + // Arg Count Check + // Valid arg count is 0,1,2,3 + if (words.length == 0) { + // Use Player's loc and default range + + } else if (words.length == 1) { + // Use Player's loc and specified range + range = Float.valueOf(words[0]); + + } else if (words.length == 2) { + // Use specified loc and default range + searchPt = new Vector3fImmutable(Float.valueOf(words[0]), + searchPt.y, + Float.valueOf(words[1])); + + } else if (words.length == 3) { + // Use specified loc and specified range + searchPt = new Vector3fImmutable(Float.valueOf(words[0]), + searchPt.y, + Float.valueOf(words[1])); + range = Float.valueOf(words[2]); + + } else { + this.sendUsage(pc); + return; + } + + String s = ""; + + HashSet container = WorldGrid.getObjectsInRangePartial( + searchPt, range, MBServerStatics.MASK_BUILDING); + + s += "Found " + container.size(); + s += " buildings within " + range; + s += " units of [" + searchPt.toString() + ']'; + throwbackInfo(pc, s); + + int index = 0; + for (AbstractWorldObject awo : container) { + Building b = (Building) awo; + + s = index + ")"; + s += " ObjectID: " + awo.getObjectUUID() + ']'; + s += " -> Name: " + b.getSimpleName(); + if (b.getBlueprint() == null) { + s += " No Blueprint"; + } else { + s += " Blueprint UUID: " + b.getBlueprint().getMeshForRank(0); + } + s += "[" + ((Building) awo).getBlueprintUUID() + ']'; + + throwbackInfo(pc, s); + ++index; + } + + } catch (NumberFormatException e) { + this.throwbackError(pc, "Supplied data: '" + words + + "' failed to parse to a Float."); + } catch (Exception e) { + this.throwbackError(pc, + "An unknown exception occurred while attempting to findBuildings with data: '" + + words + '\''); + } + } + + @Override + protected String _getHelpString() { + return "Sets your character's Mana to 'amount'"; + } + + @Override + protected String _getUsageString() { + return "' /findBuildings [lat long] [range]'"; + } } diff --git a/src/engine/devcmd/cmds/FlashMsgCmd.java b/src/engine/devcmd/cmds/FlashMsgCmd.java index e500ca74..66565b62 100644 --- a/src/engine/devcmd/cmds/FlashMsgCmd.java +++ b/src/engine/devcmd/cmds/FlashMsgCmd.java @@ -15,54 +15,51 @@ import engine.objects.AbstractGameObject; import engine.objects.PlayerCharacter; /** - * * @author Eighty - * */ public class FlashMsgCmd extends AbstractDevCmd { - public FlashMsgCmd() { + public FlashMsgCmd() { super("flash"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - if (args.length != 1 || args[0].isEmpty()) { - this.sendUsage(pcSender); - return; - } - ChatManager.chatSystemFlash(args[0]); - } + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] args, + AbstractGameObject target) { + if (args.length != 1 || args[0].isEmpty()) { + this.sendUsage(pcSender); + return; + } + ChatManager.chatSystemFlash(args[0]); + } - /** - * This function is called by the DevCmdManager. Override to avoid splitting - * argString into String array, since flash displays full String as message, - * then calls the subclass specific _doCmd method. - * - */ + /** + * This function is called by the DevCmdManager. Override to avoid splitting + * argString into String array, since flash displays full String as message, + * then calls the subclass specific _doCmd method. + */ - @Override - public void doCmd(PlayerCharacter pcSender, String argString, - AbstractGameObject target) { - String[] args = new String[1]; - args[0] = argString; + @Override + public void doCmd(PlayerCharacter pcSender, String argString, + AbstractGameObject target) { + String[] args = new String[1]; + args[0] = argString; - if (pcSender == null) { - return; - } + if (pcSender == null) { + return; + } - this._doCmd(pcSender, args, target); - } + this._doCmd(pcSender, args, target); + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /flash message'"; - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Flashes system message to all players"; - } + } } diff --git a/src/engine/devcmd/cmds/GateInfoCmd.java b/src/engine/devcmd/cmds/GateInfoCmd.java index bba5164d..700f2928 100644 --- a/src/engine/devcmd/cmds/GateInfoCmd.java +++ b/src/engine/devcmd/cmds/GateInfoCmd.java @@ -7,79 +7,78 @@ import engine.math.Vector3fImmutable; import engine.objects.*; public class GateInfoCmd extends AbstractDevCmd { - - public GateInfoCmd() { + + public GateInfoCmd() { super("gateinfo"); } - // AbstractDevCmd Overridden methods - - @Override - protected void _doCmd(PlayerCharacter player, String[] args, - AbstractGameObject target) { - - Building targetBuilding; - String outString; - Runegate runeGate; - Blueprint blueprint; - String newline = "\r\n "; - targetBuilding = (Building)target; - - if (targetBuilding.getObjectType() != GameObjectType.Building) { - throwbackInfo(player, "GateInfo: target must be a Building"); - throwbackInfo(player, "Found" + targetBuilding.getObjectType().toString()); - return; - } - - blueprint = Blueprint._meshLookup.get(targetBuilding.getMeshUUID()); - - if (blueprint == null || - (blueprint.getBuildingGroup() != BuildingGroup.RUNEGATE)){ - throwbackInfo(player, "showgate: target must be a Runegate"); - return; - } - - - runeGate = Runegate._runegates.get(targetBuilding.getObjectUUID()); - - outString = "RungateType: " + runeGate.gateBuilding.getName(); - outString += newline; - - outString += "Portal State:"; - outString += newline; - - for (Portal portal : runeGate.getPortals()) { - - outString += "Portal: " + portal.portalType.name(); - outString += " Active: " + portal.isActive(); - outString += " Dest: " + portal.targetGate.getName(); - outString += newline; - outString += " Origin: " + portal.getPortalLocation().x + 'x'; - outString += " " + portal.getPortalLocation().y + 'y'; - outString += newline; - - Vector3fImmutable offset = portal.getPortalLocation().subtract(targetBuilding.getLoc()); - outString += " Offset: " + offset.x + "x " + offset.z + 'y'; - outString += newline; - outString += newline; - - } - outString += newline; - throwbackInfo(player, outString); + // AbstractDevCmd Overridden methods + + @Override + protected void _doCmd(PlayerCharacter player, String[] args, + AbstractGameObject target) { + + Building targetBuilding; + String outString; + Runegate runeGate; + Blueprint blueprint; + String newline = "\r\n "; + targetBuilding = (Building) target; + + if (targetBuilding.getObjectType() != GameObjectType.Building) { + throwbackInfo(player, "GateInfo: target must be a Building"); + throwbackInfo(player, "Found" + targetBuilding.getObjectType().toString()); + return; + } + + blueprint = Blueprint._meshLookup.get(targetBuilding.getMeshUUID()); + + if (blueprint == null || + (blueprint.getBuildingGroup() != BuildingGroup.RUNEGATE)) { + throwbackInfo(player, "showgate: target must be a Runegate"); + return; + } + + + runeGate = Runegate._runegates.get(targetBuilding.getObjectUUID()); + + outString = "RungateType: " + runeGate.gateBuilding.getName(); + outString += newline; + + outString += "Portal State:"; + outString += newline; + + for (Portal portal : runeGate.getPortals()) { + + outString += "Portal: " + portal.portalType.name(); + outString += " Active: " + portal.isActive(); + outString += " Dest: " + portal.targetGate.getName(); + outString += newline; + outString += " Origin: " + portal.getPortalLocation().x + 'x'; + outString += " " + portal.getPortalLocation().y + 'y'; + outString += newline; + + Vector3fImmutable offset = portal.getPortalLocation().subtract(targetBuilding.getLoc()); + outString += " Offset: " + offset.x + "x " + offset.z + 'y'; + outString += newline; + outString += newline; + } + outString += newline; + throwbackInfo(player, outString); + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Displays a runegate's gate status"; - } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "/gateinfo \n"; - } + } + - - } diff --git a/src/engine/devcmd/cmds/GetBankCmd.java b/src/engine/devcmd/cmds/GetBankCmd.java index 55e1e871..65e4c466 100644 --- a/src/engine/devcmd/cmds/GetBankCmd.java +++ b/src/engine/devcmd/cmds/GetBankCmd.java @@ -17,36 +17,36 @@ import engine.objects.AbstractGameObject; import engine.objects.PlayerCharacter; /** - * * @author Eighty - * */ public class GetBankCmd extends AbstractDevCmd { - public GetBankCmd() { + public GetBankCmd() { super("getbank"); } - @Override + @Override protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - if (pcSender == null) return; + AbstractGameObject target) { + if (pcSender == null) + return; - ClientConnection cc = SessionManager.getClientConnection(pcSender); - if (cc == null) return; + ClientConnection cc = SessionManager.getClientConnection(pcSender); + if (cc == null) + return; - VendorDialogMsg.getBank(pcSender, null, cc); - this.setTarget(pcSender); //for logging - } + VendorDialogMsg.getBank(pcSender, null, cc); + this.setTarget(pcSender); //for logging + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /getbank'"; - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Opens bank window"; - } + } } diff --git a/src/engine/devcmd/cmds/GetCacheCountCmd.java b/src/engine/devcmd/cmds/GetCacheCountCmd.java index 29840336..eaea4c14 100644 --- a/src/engine/devcmd/cmds/GetCacheCountCmd.java +++ b/src/engine/devcmd/cmds/GetCacheCountCmd.java @@ -16,25 +16,25 @@ import engine.objects.PlayerCharacter; public class GetCacheCountCmd extends AbstractDevCmd { - public GetCacheCountCmd() { + public GetCacheCountCmd() { super("getcachecount"); this.addCmdString("getcachecount"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - DbManager.printCacheCount(pcSender); - } + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] args, + AbstractGameObject target) { + DbManager.printCacheCount(pcSender); + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /getcachecount'"; - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Get a count of the objects in the cache"; - } + } } diff --git a/src/engine/devcmd/cmds/GetHeightCmd.java b/src/engine/devcmd/cmds/GetHeightCmd.java index 6f94f457..8254a47f 100644 --- a/src/engine/devcmd/cmds/GetHeightCmd.java +++ b/src/engine/devcmd/cmds/GetHeightCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.InterestManagement.HeightMap; @@ -41,7 +40,7 @@ public class GetHeightCmd extends AbstractDevCmd { Zone zone = ZoneManager.findSmallestZone(pc.getLoc()); this.throwbackInfo(pc, "Water Level : " + zone.getSeaLevel()); - this.throwbackInfo(pc, "Character Water Level Above : " + (pc.getCharacterHeight() + height - zone.getSeaLevel()) ); + this.throwbackInfo(pc, "Character Water Level Above : " + (pc.getCharacterHeight() + height - zone.getSeaLevel())); if (end) return; @@ -62,9 +61,9 @@ public class GetHeightCmd extends AbstractDevCmd { //find the next parents heightmap if the currentzone heightmap is null. - while (heightMap == null){ + while (heightMap == null) { - if (currentZone == ZoneManager.getSeaFloor()){ + if (currentZone == ZoneManager.getSeaFloor()) { this.throwbackInfo(pc, "Could not find a heightmap to get height."); break; } @@ -76,9 +75,9 @@ public class GetHeightCmd extends AbstractDevCmd { } - if ( (heightMap == null) || (currentZone == ZoneManager.getSeaFloor()) ) { - this.throwbackInfo(pc, currentZone.getName() + " has no heightmap " ); - this.throwbackInfo(pc, "Current altitude: " + currentZone.absY ); + if ((heightMap == null) || (currentZone == ZoneManager.getSeaFloor())) { + this.throwbackInfo(pc, currentZone.getName() + " has no heightmap "); + this.throwbackInfo(pc, "Current altitude: " + currentZone.absY); return; } @@ -88,8 +87,6 @@ public class GetHeightCmd extends AbstractDevCmd { this.throwbackInfo(pc, "SeaFloor Local : " + seaFloorLocalLoc.x + " , " + seaFloorLocalLoc.y); - - this.throwbackInfo(pc, "Local Zone Location : " + zoneLoc.x + " , " + zoneLoc.y); Vector3fImmutable localLocFromCenter = ZoneManager.worldToLocal(pc.getLoc(), currentZone); Vector3fImmutable parentLocFromCenter = ZoneManager.worldToLocal(pc.getLoc(), currentZone.getParent()); @@ -99,10 +96,11 @@ public class GetHeightCmd extends AbstractDevCmd { Vector2f parentZoneLoc = ZoneManager.worldToZoneSpace(pc.getLoc(), currentZone.getParent()); this.throwbackInfo(pc, "Parent Zone Location from Bottom Left : " + parentZoneLoc); - if ((parentZone != null ) && (parentZone.getHeightMap() != null)) { + if ((parentZone != null) && (parentZone.getHeightMap() != null)) { parentLoc = ZoneManager.worldToZoneSpace(pc.getLoc(), parentZone); - parentGrid = parentZone.getHeightMap().getGridSquare( parentLoc); - } else parentGrid = new Vector2f(-1,-1); + parentGrid = parentZone.getHeightMap().getGridSquare(parentLoc); + } else + parentGrid = new Vector2f(-1, -1); gridSquare = heightMap.getGridSquare(zoneLoc); gridOffset = HeightMap.getGridOffset(gridSquare); @@ -110,7 +108,7 @@ public class GetHeightCmd extends AbstractDevCmd { float interaltitude = currentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc); this.throwbackInfo(pc, currentZone.getName()); - this.throwbackInfo(pc, "Current Grid Square: " + gridSquare.x + " , " + gridSquare.y ); + this.throwbackInfo(pc, "Current Grid Square: " + gridSquare.x + " , " + gridSquare.y); this.throwbackInfo(pc, "Grid Offset: " + gridOffset.x + " , " + gridOffset.y); this.throwbackInfo(pc, "Parent Grid: " + parentGrid.x + " , " + parentGrid.y); @@ -126,15 +124,15 @@ public class GetHeightCmd extends AbstractDevCmd { float realWorldAltitude = interaltitude + currentZone.getWorldAltitude(); //OUTSET - if (parentZone != null){ + if (parentZone != null) { float parentXRadius = currentZone.getBounds().getHalfExtents().x; float parentZRadius = currentZone.getBounds().getHalfExtents().y; float offsetX = Math.abs((localLocFromCenter.x / parentXRadius)); float offsetZ = Math.abs((localLocFromCenter.z / parentZRadius)); - float bucketScaleX = 100/parentXRadius; - float bucketScaleZ = 200/parentZRadius; + float bucketScaleX = 100 / parentXRadius; + float bucketScaleZ = 200 / parentZRadius; float outsideGridSizeX = 1 - bucketScaleX; //32/256 float outsideGridSizeZ = 1 - bucketScaleZ; @@ -143,7 +141,7 @@ public class GetHeightCmd extends AbstractDevCmd { double scale; - if (offsetX > outsideGridSizeX && offsetX > offsetZ){ + if (offsetX > outsideGridSizeX && offsetX > offsetZ) { weight = (offsetX - outsideGridSizeX) / bucketScaleX; scale = Math.atan2((.5 - weight) * 3.1415927, 1); @@ -164,7 +162,7 @@ public class GetHeightCmd extends AbstractDevCmd { outsetALt += currentZone.getParent().getAbsY(); realWorldAltitude = outsetALt; - }else if (offsetZ > outsideGridSizeZ){ + } else if (offsetZ > outsideGridSizeZ) { weight = (offsetZ - outsideGridSizeZ) / bucketScaleZ; scale = Math.atan2((.5 - weight) * 3.1415927, 1); @@ -184,8 +182,6 @@ public class GetHeightCmd extends AbstractDevCmd { realWorldAltitude = outsetALt; - - } } @@ -196,7 +192,7 @@ public class GetHeightCmd extends AbstractDevCmd { strMod += 1f; float radius = 0; - switch (pc.getRaceID()){ + switch (pc.getRaceID()) { case 2017: radius = 3.1415927f; case 2000: @@ -210,14 +206,11 @@ public class GetHeightCmd extends AbstractDevCmd { strMod -= .5f; - realWorldAltitude += strMod; this.throwbackInfo(pc, "interpolated height with World: " + realWorldAltitude); - - } @Override diff --git a/src/engine/devcmd/cmds/GetMemoryCmd.java b/src/engine/devcmd/cmds/GetMemoryCmd.java index d6b1a0a8..795c19b7 100644 --- a/src/engine/devcmd/cmds/GetMemoryCmd.java +++ b/src/engine/devcmd/cmds/GetMemoryCmd.java @@ -15,43 +15,44 @@ import engine.objects.PlayerCharacter; public class GetMemoryCmd extends AbstractDevCmd { - public GetMemoryCmd() { + public GetMemoryCmd() { super("getmemory"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] words, - AbstractGameObject target) { - if (pcSender == null) return; - - String hSize = getMemoryOutput(Runtime.getRuntime().totalMemory()); - String mhSize = getMemoryOutput(Runtime.getRuntime().maxMemory()); - String fhSize = getMemoryOutput(Runtime.getRuntime().freeMemory()); - - String out = "Heap Size: " + hSize + ", Max Heap Size: " + mhSize + ", Free Heap Size: " + fhSize; - throwbackInfo(pcSender, out); - } - - public static String getMemoryOutput(long memory) { - String out = ""; - if (memory > 1073741824) - return (memory / 1073741824) + "GB"; - else if (memory > 1048576) - return (memory / 1048576) + "MB"; - else if (memory > 1024) - return (memory / 1048576) + "KB"; - else - return memory + "B"; - } - - @Override - protected String _getUsageString() { - return "' /getmemory'"; - } - - @Override - protected String _getHelpString() { - return "lists memory usage"; - } + public static String getMemoryOutput(long memory) { + String out = ""; + if (memory > 1073741824) + return (memory / 1073741824) + "GB"; + else if (memory > 1048576) + return (memory / 1048576) + "MB"; + else if (memory > 1024) + return (memory / 1048576) + "KB"; + else + return memory + "B"; + } + + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] words, + AbstractGameObject target) { + if (pcSender == null) + return; + + String hSize = getMemoryOutput(Runtime.getRuntime().totalMemory()); + String mhSize = getMemoryOutput(Runtime.getRuntime().maxMemory()); + String fhSize = getMemoryOutput(Runtime.getRuntime().freeMemory()); + + String out = "Heap Size: " + hSize + ", Max Heap Size: " + mhSize + ", Free Heap Size: " + fhSize; + throwbackInfo(pcSender, out); + } + + @Override + protected String _getUsageString() { + return "' /getmemory'"; + } + + @Override + protected String _getHelpString() { + return "lists memory usage"; + } } diff --git a/src/engine/devcmd/cmds/GetMobBaseLoot.java b/src/engine/devcmd/cmds/GetMobBaseLoot.java index 3ecce72f..edd450a6 100644 --- a/src/engine/devcmd/cmds/GetMobBaseLoot.java +++ b/src/engine/devcmd/cmds/GetMobBaseLoot.java @@ -18,42 +18,41 @@ import engine.objects.PlayerCharacter; /** * @author Eighty - * */ public class GetMobBaseLoot extends AbstractDevCmd { - public GetMobBaseLoot() { + public GetMobBaseLoot() { super("mobbaseloot"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - if (target.getObjectType() != GameObjectType.Mob){ - this.throwbackError(pc, "Must be targeting a Valid Mob For this Command."); - return; - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + if (target.getObjectType() != GameObjectType.Mob) { + this.throwbackError(pc, "Must be targeting a Valid Mob For this Command."); + return; + } - Mob mob = (Mob)target; - for (MobLootBase mlb : MobLootBase.MobLootSet.get(mob.getMobBase().getLoadID())){ + Mob mob = (Mob) target; + for (MobLootBase mlb : MobLootBase.MobLootSet.get(mob.getMobBase().getLoadID())) { - this.throwbackInfo(pc, "LootTable11 = " + mlb.getLootTableID() + "\rn "); - this.throwbackInfo(pc, "Chance = " + mlb.getChance() + "\rn "); + this.throwbackInfo(pc, "LootTable11 = " + mlb.getLootTableID() + "\rn "); + this.throwbackInfo(pc, "Chance = " + mlb.getChance() + "\rn "); - } + } - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Copies a Mob of type 'mobID' with optional new name"; - } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /mob mobID [name]'"; - } + } } diff --git a/src/engine/devcmd/cmds/GetOffsetCmd.java b/src/engine/devcmd/cmds/GetOffsetCmd.java index 515b5d3f..46c75b14 100644 --- a/src/engine/devcmd/cmds/GetOffsetCmd.java +++ b/src/engine/devcmd/cmds/GetOffsetCmd.java @@ -17,47 +17,48 @@ import engine.objects.Zone; public class GetOffsetCmd extends AbstractDevCmd { - public GetOffsetCmd() { + public GetOffsetCmd() { super("getoffset"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] words, - AbstractGameObject target) { - if (pcSender == null) return; - - Zone zone = null; - try { - int loadID = Integer.parseInt(words[0]); - zone = ZoneManager.getZoneByZoneID(loadID); - if (zone == null) { - throwbackError(pcSender, "Error: can't find the zone of ID " + loadID + '.'); - return; - } - } catch (Exception e) { - zone = ZoneManager.findSmallestZone(pcSender.getLoc()); - } - - if (zone == null) { - throwbackError(pcSender, "Error: can't find the zone you're in."); - return; - } - - float difX = pcSender.getLoc().x - zone.absX; - float difY = pcSender.getLoc().y - zone.absY; - float difZ = pcSender.getLoc().z - zone.absZ; - - throwbackInfo(pcSender, zone.getName() + ": (x: " + difX + ", y: " + difY + ", z: " + difZ + ')'); - } - - @Override - protected String _getUsageString() { - return "'./getoffset [zoneID]'"; - } - - @Override - protected String _getHelpString() { - return "lists offset from center of zone"; - } + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] words, + AbstractGameObject target) { + if (pcSender == null) + return; + + Zone zone = null; + try { + int loadID = Integer.parseInt(words[0]); + zone = ZoneManager.getZoneByZoneID(loadID); + if (zone == null) { + throwbackError(pcSender, "Error: can't find the zone of ID " + loadID + '.'); + return; + } + } catch (Exception e) { + zone = ZoneManager.findSmallestZone(pcSender.getLoc()); + } + + if (zone == null) { + throwbackError(pcSender, "Error: can't find the zone you're in."); + return; + } + + float difX = pcSender.getLoc().x - zone.absX; + float difY = pcSender.getLoc().y - zone.absY; + float difZ = pcSender.getLoc().z - zone.absZ; + + throwbackInfo(pcSender, zone.getName() + ": (x: " + difX + ", y: " + difY + ", z: " + difZ + ')'); + } + + @Override + protected String _getUsageString() { + return "'./getoffset [zoneID]'"; + } + + @Override + protected String _getHelpString() { + return "lists offset from center of zone"; + } } diff --git a/src/engine/devcmd/cmds/GetRuneDropRateCmd.java b/src/engine/devcmd/cmds/GetRuneDropRateCmd.java index 7dea4c5c..300fe6df 100644 --- a/src/engine/devcmd/cmds/GetRuneDropRateCmd.java +++ b/src/engine/devcmd/cmds/GetRuneDropRateCmd.java @@ -16,27 +16,28 @@ import engine.objects.PlayerCharacter; public class GetRuneDropRateCmd extends AbstractDevCmd { - public GetRuneDropRateCmd() { + public GetRuneDropRateCmd() { super("getrunedroprate"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] words, - AbstractGameObject target) { - if (pcSender == null) return; + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] words, + AbstractGameObject target) { + if (pcSender == null) + return; - String out = "Depracated"; - throwbackInfo(pcSender, out); - } + String out = "Depracated"; + throwbackInfo(pcSender, out); + } - @Override - protected String _getUsageString() { - return "' /getrunedroprate'"; - } + @Override + protected String _getUsageString() { + return "' /getrunedroprate'"; + } - @Override - protected String _getHelpString() { - return "lists drop rates for runes and contracts in non-hotzone."; - } + @Override + protected String _getHelpString() { + return "lists drop rates for runes and contracts in non-hotzone."; + } } diff --git a/src/engine/devcmd/cmds/GetVaultCmd.java b/src/engine/devcmd/cmds/GetVaultCmd.java index df50846e..c480f761 100644 --- a/src/engine/devcmd/cmds/GetVaultCmd.java +++ b/src/engine/devcmd/cmds/GetVaultCmd.java @@ -18,30 +18,32 @@ import engine.objects.PlayerCharacter; public class GetVaultCmd extends AbstractDevCmd { - public GetVaultCmd() { + public GetVaultCmd() { super("getvault"); } - @Override + @Override protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - if (pcSender == null) return; + AbstractGameObject target) { + if (pcSender == null) + return; - ClientConnection cc = SessionManager.getClientConnection(pcSender); - if (cc == null) return; + ClientConnection cc = SessionManager.getClientConnection(pcSender); + if (cc == null) + return; - VendorDialogMsg.getVault(pcSender, null, cc); - this.setTarget(pcSender); //for logging - } + VendorDialogMsg.getVault(pcSender, null, cc); + this.setTarget(pcSender); //for logging + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /getvault'"; - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Opens account vault"; - } + } } diff --git a/src/engine/devcmd/cmds/GetZoneCmd.java b/src/engine/devcmd/cmds/GetZoneCmd.java index bab3ae9d..dc7c3693 100644 --- a/src/engine/devcmd/cmds/GetZoneCmd.java +++ b/src/engine/devcmd/cmds/GetZoneCmd.java @@ -19,48 +19,49 @@ import java.util.ArrayList; public class GetZoneCmd extends AbstractDevCmd { - public GetZoneCmd() { + public GetZoneCmd() { super("getzone"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] words, - AbstractGameObject target) { - if (pcSender == null) return; + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] words, + AbstractGameObject target) { + if (pcSender == null) + return; - if (words.length != 1) { - this.sendUsage(pcSender); - return; - } + if (words.length != 1) { + this.sendUsage(pcSender); + return; + } - ArrayList allIn = new ArrayList<>(); - switch (words[0].toLowerCase()) { - case "all": - throwbackInfo(pcSender, "All zones currently in"); - allIn = ZoneManager.getAllZonesIn(pcSender.getLoc()); - break; - case "smallest": - throwbackInfo(pcSender, "Smallest zone currently in"); - Zone zone = ZoneManager.findSmallestZone(pcSender.getLoc()); - allIn.add(zone); - break; - default: - this.sendUsage(pcSender); - return; - } + ArrayList allIn = new ArrayList<>(); + switch (words[0].toLowerCase()) { + case "all": + throwbackInfo(pcSender, "All zones currently in"); + allIn = ZoneManager.getAllZonesIn(pcSender.getLoc()); + break; + case "smallest": + throwbackInfo(pcSender, "Smallest zone currently in"); + Zone zone = ZoneManager.findSmallestZone(pcSender.getLoc()); + allIn.add(zone); + break; + default: + this.sendUsage(pcSender); + return; + } - for (Zone zone : allIn) - throwbackInfo(pcSender, zone.getName() + "; UUID: " + zone.getObjectUUID() + ", loadNum: " + zone.getLoadNum()); - } + for (Zone zone : allIn) + throwbackInfo(pcSender, zone.getName() + "; UUID: " + zone.getObjectUUID() + ", loadNum: " + zone.getLoadNum()); + } - @Override - protected String _getUsageString() { - return "' /getzone smallest/all'"; - } + @Override + protected String _getUsageString() { + return "' /getzone smallest/all'"; + } - @Override - protected String _getHelpString() { - return "lists what zones a player is in"; - } + @Override + protected String _getHelpString() { + return "lists what zones a player is in"; + } } diff --git a/src/engine/devcmd/cmds/GetZoneMobsCmd.java b/src/engine/devcmd/cmds/GetZoneMobsCmd.java index f069ef20..aea5761f 100644 --- a/src/engine/devcmd/cmds/GetZoneMobsCmd.java +++ b/src/engine/devcmd/cmds/GetZoneMobsCmd.java @@ -18,65 +18,67 @@ import engine.objects.Zone; public class GetZoneMobsCmd extends AbstractDevCmd { - public GetZoneMobsCmd() { + public GetZoneMobsCmd() { super("getzonemobs"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] words, - AbstractGameObject target) { - if (pcSender == null) return; - - int loadID = 0; - if (words.length == 1) { - try { - loadID = Integer.parseInt(words[0]); - } catch (Exception e) {} - } - - //find the zone - Zone zone = null; - if (loadID != 0) { - zone = ZoneManager.getZoneByZoneID(loadID); - if (zone == null) - zone = ZoneManager.getZoneByUUID(loadID); - } else - zone = ZoneManager.findSmallestZone(pcSender.getLoc()); - - if (zone == null) { - if (loadID != 0) - throwbackError(pcSender, "Error: can't find the zone of ID " + loadID + '.'); - else - throwbackError(pcSender, "Error: can't find the zone you are in."); - return; - } - - //get all mobs for the zone - - throwbackInfo(pcSender, zone.getName() + " (" + zone.getLoadNum() + ") " + zone.getObjectUUID()); - - for (Mob m : zone.zoneMobSet) { - - if (m != null) { - String out = m.getName() + '(' + m.getDBID() + "): "; - if (m.isAlive()) - out += m.getLoc().x + "x" + m.getLoc().z + "; isAlive: " + m.isAlive(); - else - out += " isAlive: " + m.isAlive(); - throwbackInfo(pcSender, out); - } else - throwbackInfo(pcSender, "Unknown (" + m.getDBID() + "): not loaded"); - } - } - - @Override - protected String _getUsageString() { - return "' /getzonemobs [zoneID]'"; - } - - @Override - protected String _getHelpString() { - return "lists all mobs for a zone"; - } + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] words, + AbstractGameObject target) { + if (pcSender == null) + return; + + int loadID = 0; + if (words.length == 1) { + try { + loadID = Integer.parseInt(words[0]); + } catch (Exception e) { + } + } + + //find the zone + Zone zone = null; + if (loadID != 0) { + zone = ZoneManager.getZoneByZoneID(loadID); + if (zone == null) + zone = ZoneManager.getZoneByUUID(loadID); + } else + zone = ZoneManager.findSmallestZone(pcSender.getLoc()); + + if (zone == null) { + if (loadID != 0) + throwbackError(pcSender, "Error: can't find the zone of ID " + loadID + '.'); + else + throwbackError(pcSender, "Error: can't find the zone you are in."); + return; + } + + //get all mobs for the zone + + throwbackInfo(pcSender, zone.getName() + " (" + zone.getLoadNum() + ") " + zone.getObjectUUID()); + + for (Mob m : zone.zoneMobSet) { + + if (m != null) { + String out = m.getName() + '(' + m.getDBID() + "): "; + if (m.isAlive()) + out += m.getLoc().x + "x" + m.getLoc().z + "; isAlive: " + m.isAlive(); + else + out += " isAlive: " + m.isAlive(); + throwbackInfo(pcSender, out); + } else + throwbackInfo(pcSender, "Unknown (" + m.getDBID() + "): not loaded"); + } + } + + @Override + protected String _getUsageString() { + return "' /getzonemobs [zoneID]'"; + } + + @Override + protected String _getHelpString() { + return "lists all mobs for a zone"; + } } diff --git a/src/engine/devcmd/cmds/GotoBoundsCmd.java b/src/engine/devcmd/cmds/GotoBoundsCmd.java index ae10766b..67004d26 100644 --- a/src/engine/devcmd/cmds/GotoBoundsCmd.java +++ b/src/engine/devcmd/cmds/GotoBoundsCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.Enum.GameObjectType; @@ -19,90 +18,90 @@ import engine.objects.PlayerCharacter; public class GotoBoundsCmd extends AbstractDevCmd { - public GotoBoundsCmd() { + public GotoBoundsCmd() { super("gotobounds"); } - @Override - protected void _doCmd(PlayerCharacter player, String[] words, - AbstractGameObject target) { - - String corner = words[0]; - Vector3fImmutable targetLoc = Vector3fImmutable.ZERO; - - if (target == null || !target.getObjectType().equals(GameObjectType.Building)){ - this.throwbackError(player, "No Building Selected"); - return; - } - - Building building = (Building)target; - - if (building.getBounds() == null){ - this.throwbackInfo(player, "No valid Bounds for building UUID " + building.getObjectUUID()); - return; - } - float x = building.getBounds().getHalfExtents().x; - float z = building.getBounds().getHalfExtents().y; - - if (building.getBlueprint() != null){ - x = building.getBlueprint().getExtents().x; - z = building.getBlueprint().getExtents().y; - } - - float topLeftX = building.getLoc().x - x; - float topLeftY = building.getLoc().z -z; - - float topRightX = building.getLoc().x + x; - float topRightY = building.getLoc().z - z; - - float bottomLeftX = building.getLoc().x - x; - float bottomLeftY = building.getLoc().z + z; - - float bottomRightX = building.getLoc().x +x; - float bottomRightY = building.getLoc().z + z; - - - switch (corner){ - case "topleft": - targetLoc = new Vector3fImmutable(topLeftX, 0, topLeftY); - break; - case "topright": - targetLoc = new Vector3fImmutable(topRightX, 0, topRightY); - break; - case "bottomleft": - targetLoc = new Vector3fImmutable(bottomLeftX, 0, bottomLeftY); - break; - case "bottomright": - targetLoc = new Vector3fImmutable(bottomRightX, 0, bottomRightY); - break; - default: - this.throwbackInfo(player, "wrong corner name. use topleft , topright , bottomleft , bottomright"); - return; - - } - - targetLoc = Vector3fImmutable.transform(building.getLoc(),targetLoc , building.getBounds().getRotationDegrees()); - - // Teleport player - - if (targetLoc == Vector3fImmutable.ZERO) { - this.throwbackError(player, "Failed to locate UUID"); - return; - } - - player.teleport(targetLoc); - - } - - @Override - protected String _getHelpString() { + @Override + protected void _doCmd(PlayerCharacter player, String[] words, + AbstractGameObject target) { + + String corner = words[0]; + Vector3fImmutable targetLoc = Vector3fImmutable.ZERO; + + if (target == null || !target.getObjectType().equals(GameObjectType.Building)) { + this.throwbackError(player, "No Building Selected"); + return; + } + + Building building = (Building) target; + + if (building.getBounds() == null) { + this.throwbackInfo(player, "No valid Bounds for building UUID " + building.getObjectUUID()); + return; + } + float x = building.getBounds().getHalfExtents().x; + float z = building.getBounds().getHalfExtents().y; + + if (building.getBlueprint() != null) { + x = building.getBlueprint().getExtents().x; + z = building.getBlueprint().getExtents().y; + } + + float topLeftX = building.getLoc().x - x; + float topLeftY = building.getLoc().z - z; + + float topRightX = building.getLoc().x + x; + float topRightY = building.getLoc().z - z; + + float bottomLeftX = building.getLoc().x - x; + float bottomLeftY = building.getLoc().z + z; + + float bottomRightX = building.getLoc().x + x; + float bottomRightY = building.getLoc().z + z; + + + switch (corner) { + case "topleft": + targetLoc = new Vector3fImmutable(topLeftX, 0, topLeftY); + break; + case "topright": + targetLoc = new Vector3fImmutable(topRightX, 0, topRightY); + break; + case "bottomleft": + targetLoc = new Vector3fImmutable(bottomLeftX, 0, bottomLeftY); + break; + case "bottomright": + targetLoc = new Vector3fImmutable(bottomRightX, 0, bottomRightY); + break; + default: + this.throwbackInfo(player, "wrong corner name. use topleft , topright , bottomleft , bottomright"); + return; + + } + + targetLoc = Vector3fImmutable.transform(building.getLoc(), targetLoc, building.getBounds().getRotationDegrees()); + + // Teleport player + + if (targetLoc == Vector3fImmutable.ZERO) { + this.throwbackError(player, "Failed to locate UUID"); + return; + } + + player.teleport(targetLoc); + + } + + @Override + protected String _getHelpString() { return "Teleports player to a UUID"; - } + } - @Override - protected String _getUsageString() { - return "' /gotoobj '"; + @Override + protected String _getUsageString() { + return "' /gotoobj '"; - } + } } diff --git a/src/engine/devcmd/cmds/GotoCmd.java b/src/engine/devcmd/cmds/GotoCmd.java index 3825ae4a..95ab5f93 100644 --- a/src/engine/devcmd/cmds/GotoCmd.java +++ b/src/engine/devcmd/cmds/GotoCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.Enum.GameObjectType; @@ -22,161 +21,161 @@ import java.util.concurrent.ThreadLocalRandom; public class GotoCmd extends AbstractDevCmd { - public GotoCmd() { + public GotoCmd() { super("goto"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - Vector3fImmutable loc = null; - - // Arg Count Check - - - if (target != null && words[0].isEmpty()){ - AbstractWorldObject targetAgo = (AbstractWorldObject)target; - pc.teleport(targetAgo.getLoc()); - return; - } - - if (words[0].isEmpty()){ - this.sendUsage(pc); - return; - } - - if (words[0].equalsIgnoreCase("playground")){ - if (target instanceof AbstractCharacter){ - loc = new Vector3fImmutable(63276,0,-54718); - } - - if (loc != null) - pc.teleport(loc); - - return; - } - - if (words[0].equalsIgnoreCase("coc")){ - if (target instanceof AbstractCharacter){ - loc = new Vector3fImmutable(98561.656f,0,-13353.778f); - } - - if (loc != null) - pc.teleport(loc); - - return; - } - - String cityName = ""; - for (String partial: words){ - cityName += partial + ' '; - } - - cityName = cityName.substring(0, cityName.length() - 1); - - for (AbstractGameObject cityAgo: DbManager.getList(GameObjectType.City)){ - City city = (City)cityAgo; - if (city == null) - continue; - if (!city.getCityName().equalsIgnoreCase(cityName)) - continue; - Zone zone = city.getParent(); - if (zone != null){ - if (zone.isNPCCity() || zone.isPlayerCity()) - loc = Vector3fImmutable.getRandomPointOnCircle(zone.getLoc(), MBServerStatics.TREE_TELEPORT_RADIUS); - else - loc = zone.getLoc(); - - int random = ThreadLocalRandom.current().nextInt(5); - if (random == 1) - break; - } - } - - if (loc == null){ - for (AbstractGameObject zoneAgo: DbManager.getList(GameObjectType.Zone)){ - Zone zone = (Zone)zoneAgo; - if (zone == null) - continue; - if (!zone.getName().equalsIgnoreCase(cityName)) - continue; - if (zone != null){ - if (zone.isNPCCity() || zone.isPlayerCity()) - loc = Vector3fImmutable.getRandomPointOnCircle(zone.getLoc(), MBServerStatics.TREE_TELEPORT_RADIUS); - else - loc = zone.getLoc(); - - int random = ThreadLocalRandom.current().nextInt(5); - if (random == 1) - break; - } - } - } - if (loc == null && words.length == 1){ - - try { - PlayerCharacter pcDest = SessionManager - .getPlayerCharacterByLowerCaseName(words[0]); - if (pcDest == null){ - this.throwbackError(pc, "Player or Zone not found by name: " - + words[0]); - this.throwbackInfo(pc, "If you have spaces in the zone name, replace them with '_'"); - return; - } - - if (pcDest.getCombinedName().equals(pc.getCombinedName())) { - this - .throwbackError(pc, - "Cannot goto yourself. Well, you can, but you wont go anywhere."); - return; - } - - loc = pcDest.getLoc(); - } catch (Exception e) { - this.throwbackError(pc, - "An unknown exception occurred while attempting to goto a character named '" - + words[0] + '\''); - return; - } - - } - if (loc == null) { // lat lon mode - if (words.length != 2) { - throwbackError(pc, this.getUsageString()); - return; - } - float lat = 0.0f, lon = 0.0f; - String latLong = '\'' + words[0] + ", " + words[1] + '\''; - - try { - lat = Float.parseFloat(words[0]); - lon = Float.parseFloat(words[1]); - loc = new Vector3fImmutable(lat, 0f, -lon); - } catch (NumberFormatException e) { - this.throwbackError(pc, "Supplied LatLong: " + latLong - + " failed to parse to Floats"); - return; - - } catch (Exception e) { - this.throwbackError(pc, - "An unknown exception occurred while attempting to goto LatLong of " - + latLong); - return; - } - } - if (loc != null) { - pc.teleport(loc); - } - } - - @Override - protected String _getHelpString() { - return "Alters your characters position TO 'lat' and 'long', or TO the position of 'characterName'. This does not transport you BY 'lat' and 'long', but rather TO 'lat' and 'long' "; - } - - @Override - protected String _getUsageString() { - return "'[ /goto lat lon] || [ /goto characterName] || [/goto zoneName \replace spaces with `_`]`"; - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + Vector3fImmutable loc = null; + + // Arg Count Check + + + if (target != null && words[0].isEmpty()) { + AbstractWorldObject targetAgo = (AbstractWorldObject) target; + pc.teleport(targetAgo.getLoc()); + return; + } + + if (words[0].isEmpty()) { + this.sendUsage(pc); + return; + } + + if (words[0].equalsIgnoreCase("playground")) { + if (target instanceof AbstractCharacter) { + loc = new Vector3fImmutable(63276, 0, -54718); + } + + if (loc != null) + pc.teleport(loc); + + return; + } + + if (words[0].equalsIgnoreCase("coc")) { + if (target instanceof AbstractCharacter) { + loc = new Vector3fImmutable(98561.656f, 0, -13353.778f); + } + + if (loc != null) + pc.teleport(loc); + + return; + } + + String cityName = ""; + for (String partial : words) { + cityName += partial + ' '; + } + + cityName = cityName.substring(0, cityName.length() - 1); + + for (AbstractGameObject cityAgo : DbManager.getList(GameObjectType.City)) { + City city = (City) cityAgo; + if (city == null) + continue; + if (!city.getCityName().equalsIgnoreCase(cityName)) + continue; + Zone zone = city.getParent(); + if (zone != null) { + if (zone.isNPCCity() || zone.isPlayerCity()) + loc = Vector3fImmutable.getRandomPointOnCircle(zone.getLoc(), MBServerStatics.TREE_TELEPORT_RADIUS); + else + loc = zone.getLoc(); + + int random = ThreadLocalRandom.current().nextInt(5); + if (random == 1) + break; + } + } + + if (loc == null) { + for (AbstractGameObject zoneAgo : DbManager.getList(GameObjectType.Zone)) { + Zone zone = (Zone) zoneAgo; + if (zone == null) + continue; + if (!zone.getName().equalsIgnoreCase(cityName)) + continue; + if (zone != null) { + if (zone.isNPCCity() || zone.isPlayerCity()) + loc = Vector3fImmutable.getRandomPointOnCircle(zone.getLoc(), MBServerStatics.TREE_TELEPORT_RADIUS); + else + loc = zone.getLoc(); + + int random = ThreadLocalRandom.current().nextInt(5); + if (random == 1) + break; + } + } + } + if (loc == null && words.length == 1) { + + try { + PlayerCharacter pcDest = SessionManager + .getPlayerCharacterByLowerCaseName(words[0]); + if (pcDest == null) { + this.throwbackError(pc, "Player or Zone not found by name: " + + words[0]); + this.throwbackInfo(pc, "If you have spaces in the zone name, replace them with '_'"); + return; + } + + if (pcDest.getCombinedName().equals(pc.getCombinedName())) { + this + .throwbackError(pc, + "Cannot goto yourself. Well, you can, but you wont go anywhere."); + return; + } + + loc = pcDest.getLoc(); + } catch (Exception e) { + this.throwbackError(pc, + "An unknown exception occurred while attempting to goto a character named '" + + words[0] + '\''); + return; + } + + } + if (loc == null) { // lat lon mode + if (words.length != 2) { + throwbackError(pc, this.getUsageString()); + return; + } + float lat = 0.0f, lon = 0.0f; + String latLong = '\'' + words[0] + ", " + words[1] + '\''; + + try { + lat = Float.parseFloat(words[0]); + lon = Float.parseFloat(words[1]); + loc = new Vector3fImmutable(lat, 0f, -lon); + } catch (NumberFormatException e) { + this.throwbackError(pc, "Supplied LatLong: " + latLong + + " failed to parse to Floats"); + return; + + } catch (Exception e) { + this.throwbackError(pc, + "An unknown exception occurred while attempting to goto LatLong of " + + latLong); + return; + } + } + if (loc != null) { + pc.teleport(loc); + } + } + + @Override + protected String _getHelpString() { + return "Alters your characters position TO 'lat' and 'long', or TO the position of 'characterName'. This does not transport you BY 'lat' and 'long', but rather TO 'lat' and 'long' "; + } + + @Override + protected String _getUsageString() { + return "'[ /goto lat lon] || [ /goto characterName] || [/goto zoneName \replace spaces with `_`]`"; + } } diff --git a/src/engine/devcmd/cmds/GotoObj.java b/src/engine/devcmd/cmds/GotoObj.java index 2b535564..e6e69b8c 100644 --- a/src/engine/devcmd/cmds/GotoObj.java +++ b/src/engine/devcmd/cmds/GotoObj.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.Enum; @@ -18,86 +17,86 @@ import engine.objects.*; public class GotoObj extends AbstractDevCmd { - public GotoObj() { + public GotoObj() { super("gotoobj"); } - @Override - protected void _doCmd(PlayerCharacter player, String[] words, - AbstractGameObject target) { - - int uuid; - Vector3fImmutable targetLoc = Vector3fImmutable.ZERO; - Enum.DbObjectType objectType; - - try { - uuid = Integer.parseInt(words[0]); - } catch (NumberFormatException e) { - this.throwbackError(player, "Failed to parse UUID" + e.toString()); - return; - } - - objectType = DbManager.BuildingQueries.GET_UID_ENUM(uuid); - - switch (objectType) { - - case NPC: - NPC npc = (NPC) DbManager.getFromCache(Enum.GameObjectType.NPC, uuid); - - if (npc != null) - targetLoc = npc.getLoc(); - break; - case MOB: - Mob mob = (Mob) DbManager.getFromCache(Enum.GameObjectType.Mob, uuid); - - if (mob != null) - targetLoc = mob.getLoc(); - break; - case CHARACTER: - PlayerCharacter playerCharacter = (PlayerCharacter) DbManager.getFromCache(Enum.GameObjectType.PlayerCharacter, uuid); - - if (playerCharacter != null) - targetLoc = playerCharacter.getLoc(); - break; - case BUILDING: - Building building = (Building) DbManager.getFromCache(Enum.GameObjectType.Building, uuid); - - if (building != null) - targetLoc = building.getLoc(); - break; - case ZONE: - Zone zone = (Zone) DbManager.getFromCache(Enum.GameObjectType.Zone, uuid); - - if (zone != null) - targetLoc = zone.getLoc(); - break; - case CITY: - City city = (City) DbManager.getFromCache(Enum.GameObjectType.City, uuid); - - if (city != null) - targetLoc = city.getLoc(); - break; - } - // Teleport player - - if (targetLoc == Vector3fImmutable.ZERO) { - this.throwbackError(player, "Failed to locate UUID"); - return; - } - - player.teleport(targetLoc); - - } - - @Override - protected String _getHelpString() { + @Override + protected void _doCmd(PlayerCharacter player, String[] words, + AbstractGameObject target) { + + int uuid; + Vector3fImmutable targetLoc = Vector3fImmutable.ZERO; + Enum.DbObjectType objectType; + + try { + uuid = Integer.parseInt(words[0]); + } catch (NumberFormatException e) { + this.throwbackError(player, "Failed to parse UUID" + e.toString()); + return; + } + + objectType = DbManager.BuildingQueries.GET_UID_ENUM(uuid); + + switch (objectType) { + + case NPC: + NPC npc = (NPC) DbManager.getFromCache(Enum.GameObjectType.NPC, uuid); + + if (npc != null) + targetLoc = npc.getLoc(); + break; + case MOB: + Mob mob = (Mob) DbManager.getFromCache(Enum.GameObjectType.Mob, uuid); + + if (mob != null) + targetLoc = mob.getLoc(); + break; + case CHARACTER: + PlayerCharacter playerCharacter = (PlayerCharacter) DbManager.getFromCache(Enum.GameObjectType.PlayerCharacter, uuid); + + if (playerCharacter != null) + targetLoc = playerCharacter.getLoc(); + break; + case BUILDING: + Building building = (Building) DbManager.getFromCache(Enum.GameObjectType.Building, uuid); + + if (building != null) + targetLoc = building.getLoc(); + break; + case ZONE: + Zone zone = (Zone) DbManager.getFromCache(Enum.GameObjectType.Zone, uuid); + + if (zone != null) + targetLoc = zone.getLoc(); + break; + case CITY: + City city = (City) DbManager.getFromCache(Enum.GameObjectType.City, uuid); + + if (city != null) + targetLoc = city.getLoc(); + break; + } + // Teleport player + + if (targetLoc == Vector3fImmutable.ZERO) { + this.throwbackError(player, "Failed to locate UUID"); + return; + } + + player.teleport(targetLoc); + + } + + @Override + protected String _getHelpString() { return "Teleports player to a UUID"; - } + } - @Override - protected String _getUsageString() { - return "' /gotoobj '"; + @Override + protected String _getUsageString() { + return "' /gotoobj '"; - } + } } diff --git a/src/engine/devcmd/cmds/HeartbeatCmd.java b/src/engine/devcmd/cmds/HeartbeatCmd.java index 4a8584cb..84afaba6 100644 --- a/src/engine/devcmd/cmds/HeartbeatCmd.java +++ b/src/engine/devcmd/cmds/HeartbeatCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.ai.MobileFSMManager; @@ -18,30 +17,30 @@ import engine.objects.PlayerCharacter; public class HeartbeatCmd extends AbstractDevCmd { - public HeartbeatCmd() { + public HeartbeatCmd() { super("heartbeat"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { - this.throwbackInfo(pc, "Heartbeat : " + SimulationManager.executionTime.toMillis() + "ms"); - this.throwbackInfo(pc, "Heartbeat Max: " + SimulationManager.executionMax.toMillis() + "ms"); + this.throwbackInfo(pc, "Heartbeat : " + SimulationManager.executionTime.toMillis() + "ms"); + this.throwbackInfo(pc, "Heartbeat Max: " + SimulationManager.executionMax.toMillis() + "ms"); - this.throwbackInfo(pc, "FSM: " + MobileFSMManager.executionTime.toMillis() + "ms"); - this.throwbackInfo(pc, "FSM max: " + MobileFSMManager.executionMax.toMillis() + "ms"); + this.throwbackInfo(pc, "FSM: " + MobileFSMManager.executionTime.toMillis() + "ms"); + this.throwbackInfo(pc, "FSM max: " + MobileFSMManager.executionMax.toMillis() + "ms"); - } + } - @Override - protected String _getHelpString() { - return "Displays simulation metrics"; - } + @Override + protected String _getHelpString() { + return "Displays simulation metrics"; + } - @Override - protected String _getUsageString() { - return "' ./heartbeat"; - } + @Override + protected String _getUsageString() { + return "' ./heartbeat"; + } } diff --git a/src/engine/devcmd/cmds/HelpCmd.java b/src/engine/devcmd/cmds/HelpCmd.java index 4c3d49f0..b0fe83e3 100644 --- a/src/engine/devcmd/cmds/HelpCmd.java +++ b/src/engine/devcmd/cmds/HelpCmd.java @@ -16,14 +16,14 @@ import engine.objects.PlayerCharacter; public class HelpCmd extends AbstractDevCmd { - public HelpCmd() { - super("help"); - this.addCmdString("list"); - } - - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { + public HelpCmd() { + super("help"); + this.addCmdString("list"); + } + + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] args, + AbstractGameObject target) { if (pcSender == null) return; if (pcSender.getAccount() == null) @@ -42,18 +42,18 @@ public class HelpCmd extends AbstractDevCmd { first = charLimit; charLimit += 500; last = charLimit; - } - this.throwbackInfo(pcSender, commands.substring(first)); - } + } + this.throwbackInfo(pcSender, commands.substring(first)); + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /help' || ' /list'"; - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Displays help info and lists all commands accessible for the player's access level."; - } + } } diff --git a/src/engine/devcmd/cmds/HotzoneCmd.java b/src/engine/devcmd/cmds/HotzoneCmd.java index 5a8bb7b5..2aa88f14 100644 --- a/src/engine/devcmd/cmds/HotzoneCmd.java +++ b/src/engine/devcmd/cmds/HotzoneCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.devcmd.AbstractDevCmd; @@ -63,6 +62,7 @@ public class HotzoneCmd extends AbstractDevCmd { return; } + @Override protected String _getHelpString() { return "Use no arguments to see the current hotzone or \"random\" to change it randomly."; diff --git a/src/engine/devcmd/cmds/InfoCmd.java b/src/engine/devcmd/cmds/InfoCmd.java index 926af745..6a95992b 100644 --- a/src/engine/devcmd/cmds/InfoCmd.java +++ b/src/engine/devcmd/cmds/InfoCmd.java @@ -26,515 +26,514 @@ import java.util.concurrent.ConcurrentHashMap; /** * @author - * */ public class InfoCmd extends AbstractDevCmd { - public InfoCmd() { - super("info"); - } - - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - // Arg Count Check - if (words.length != 1) { - this.sendUsage(pc); - return; - } - if (pc == null) { - return; - } - - String newline = "\r\n "; - - try { - int targetID = Integer.parseInt(words[0]); - Building b = BuildingManager.getBuilding(targetID); - if (b == null) - throwbackError(pc, "Building with ID " + targetID - + " not found"); - else - target = b; - } catch (Exception e) { - } - - if (target == null) { - throwbackError(pc, "Target is unknown or of an invalid type." - + newline + "Type ID: 0x" - + pc.getLastTargetType().toString() - + " Table ID: " + pc.getLastTargetID()); - return; - } - - - GameObjectType objType = target.getObjectType(); - int objectUUID = target.getObjectUUID(); - String output; - - output = "Target Information:" + newline; - output += StringUtils.addWS("UUID: " + objectUUID, 20); - output += newline; - output += "Type: " + target.getClass().getSimpleName(); - output += " [0x" + objType.toString() + ']'; - - if (target instanceof AbstractWorldObject) { - AbstractWorldObject targetAWO = (AbstractWorldObject) target; - Vector3fImmutable targetLoc = targetAWO.getLoc(); - output += newline; - output += StringUtils.addWS("Lat: " + targetLoc.x, 20); - output += "Lon: " + -targetLoc.z; - output += newline; - output += StringUtils.addWS("Alt: " + targetLoc.y, 20); - output += newline; - output += "Rot: " + targetAWO.getRot().y; - output += newline; - double radian = 0; - - - if (targetAWO.getBounds() != null && targetAWO.getBounds().getQuaternion() != null) - radian = targetAWO.getBounds().getQuaternion().angleY; - int degrees = (int) Math.toDegrees(radian); - - - output += "Degrees: " + degrees; - output += newline; - } - - switch (objType) { - case Building: - Building targetBuilding = (Building) target; - output += StringUtils.addWS("Lac: " - + targetBuilding.getw(), 20); - output += "Blueprint : "; - output += targetBuilding.getBlueprintUUID(); - output += newline; - - output += " MeshUUID : "; - output += targetBuilding.getMeshUUID(); - output += newline; - - if (targetBuilding.getBlueprintUUID() != 0) - output += ' ' + targetBuilding.getBlueprint().getName(); - - output += newline; - output += targetBuilding.getBlueprint() != null ? targetBuilding.getBlueprint().getBuildingGroup().name(): " no building group"; - - output += newline; - output += "EffectFlags: " + targetBuilding.getEffectFlags(); - output += newline; - output += StringUtils.addWS("rank: " + targetBuilding.getRank(), - 20); - output += "HP: " + targetBuilding.getHealth() + '/' - + targetBuilding.getMaxHitPoints(); - output += newline; - output += "Scale: (" + targetBuilding.getMeshScale().getX(); - output += ", " + targetBuilding.getMeshScale().getY(); - output += ", " + targetBuilding.getMeshScale().getZ() + ')'; - output += newline; - output += "Owner UID: " + targetBuilding.getOwnerUUID(); - output += (targetBuilding.isOwnerIsNPC() ? " (NPC)" : " (PC)"); - output += newline; - output += "ProtectionState: " + targetBuilding.getProtectionState().name(); - output += newline; - - if (targetBuilding.getUpgradeDateTime() != null) { - output += targetBuilding.getUpgradeDateTime().toString(); - output += newline; - } - - Guild guild = targetBuilding.getGuild(); - Guild nation = null; - String guildId = "-1"; - String nationId = "-1"; - String gTag = ""; - String nTag = ""; - - if (guild != null) { - int id = guild.getObjectUUID(); - - if (id == 0) { - guildId = id + " [" + guild.hashCode() + ']'; - } else - guildId = Integer.toString(id); - - gTag = guild.getGuildTag().summarySentence(); - nation = guild.getNation(); - - if (nation != null) { - id = nation.getObjectUUID(); - if (id == 0) { - nationId = id + " [" + nation.hashCode() + ']'; - } else { - nationId = Integer.toString(id); - } - nTag = nation.getGuildTag().summarySentence(); - } - } - output += StringUtils.addWS("Guild UID: " + guildId, 20); - - if (gTag.length() > 0) - output += "Guild crest: " + gTag; - - output += newline; - output += StringUtils.addWS("Nation UID: " + nationId, 20); - - if (nTag.length() > 0) { - output += "Nation crest: " + nTag; - } - - output+= newline; - - - if (targetBuilding.getBlueprint() != null){ - - if(targetBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.MINE){ - Mine mine = Mine.getMineFromTower(targetBuilding.getObjectUUID()); - - if (mine != null){ - output+= newline; - output+= "Mine active: " + mine.getIsActive(); - output+= newline; - output+= "Was claimed: " + mine.wasClaimed; - output+= newline; - output+= "Mine Type: "+mine.getMineType().name; - output+= newline; - output+= "Expansion : " + mine.isExpansion(); - output+= newline; - output+= "Production type: " +mine.getProduction().name(); - - } - } - output += newline; - - if (targetBuilding.maintDateTime != null){ - output += targetBuilding.maintDateTime.toString(); - output+= newline; - } - } - - output += "Reserve : " + targetBuilding.reserve; - output+= newline; - output += "Strongbox : " + targetBuilding.getStrongboxValue(); - output+= newline; - - // List hirelings - - if (targetBuilding.getHirelings().isEmpty() == false) { - - output += newline; - output += "Hirelings List: name / slot / floor"; - - for (AbstractCharacter npc : targetBuilding.getHirelings().keySet()) { - - if (npc.getObjectType() != GameObjectType.NPC) - continue; - output += newline + npc.getName() + " slot " + targetBuilding.getHirelings().get(npc); - output += newline + "location " + npc.getLoc(); - } - } - - ArrayList tempList = BuildingRegions._staticRegions.get(targetBuilding.getMeshUUID()); - output+= newline; - output+= "Building Regions: Size - " + tempList.size(); - output+= newline; - output+= "Building Regions from Bounds: Size - " + targetBuilding.getBounds().getRegions().size(); - output+= newline; - - for (Regions regions: targetBuilding.getBounds().getRegions()){ - //TODO ADD REGION INFO - } - - break; - case PlayerCharacter: - output += newline; - PlayerCharacter targetPC = (PlayerCharacter) target; - output += StringUtils.addWS("Name: " + targetPC.getName(), 20); - output += newline; - output += "InSession : " + SessionManager.getPlayerCharacterByID(target.getObjectUUID()) != null ? " true " : " false"; - output += newline; - output += "RaceType: " + targetPC.getRace().getRaceType().name(); - output += newline; - output += "Race: " + targetPC.getRace().getName(); - output += newline; - output += "Safe:" + targetPC.inSafeZone(); - output+= newline; - output+= "Experience : " + targetPC.getExp(); + public InfoCmd() { + super("info"); + } + + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + // Arg Count Check + if (words.length != 1) { + this.sendUsage(pc); + return; + } + if (pc == null) { + return; + } + + String newline = "\r\n "; + + try { + int targetID = Integer.parseInt(words[0]); + Building b = BuildingManager.getBuilding(targetID); + if (b == null) + throwbackError(pc, "Building with ID " + targetID + + " not found"); + else + target = b; + } catch (Exception e) { + } + + if (target == null) { + throwbackError(pc, "Target is unknown or of an invalid type." + + newline + "Type ID: 0x" + + pc.getLastTargetType().toString() + + " Table ID: " + pc.getLastTargetID()); + return; + } + + + GameObjectType objType = target.getObjectType(); + int objectUUID = target.getObjectUUID(); + String output; + + output = "Target Information:" + newline; + output += StringUtils.addWS("UUID: " + objectUUID, 20); + output += newline; + output += "Type: " + target.getClass().getSimpleName(); + output += " [0x" + objType.toString() + ']'; + + if (target instanceof AbstractWorldObject) { + AbstractWorldObject targetAWO = (AbstractWorldObject) target; + Vector3fImmutable targetLoc = targetAWO.getLoc(); output += newline; - output += "OverFlowExperience : " + targetPC.getOverFlowEXP(); + output += StringUtils.addWS("Lat: " + targetLoc.x, 20); + output += "Lon: " + -targetLoc.z; output += newline; - output += StringUtils.addWS("Level: " - + targetPC.getLevel() + " (" + - TargetColor.getCon(targetPC, pc).toString() + ')', 20); + output += StringUtils.addWS("Alt: " + targetLoc.y, 20); + output += newline; + output += "Rot: " + targetAWO.getRot().y; + output += newline; + double radian = 0; - Account acpc = SessionManager.getAccount(pc); - Account ac = SessionManager.getAccount(targetPC); - if (acpc != null && ac != null) { - output += "Account ID: " + ac.getObjectUUID(); - output += newline; - output += "Access Level: " + ac.status.name(); - } else - output += "Account ID: UNKNOWN"; + if (targetAWO.getBounds() != null && targetAWO.getBounds().getQuaternion() != null) + radian = targetAWO.getBounds().getQuaternion().angleY; + int degrees = (int) Math.toDegrees(radian); + + output += "Degrees: " + degrees; output += newline; - output += "Inventory Weight:" + (targetPC.getCharItemManager().getInventoryWeight() + targetPC.getCharItemManager().getEquipWeight()); - output += newline; - output += "Max Inventory Weight:" + ((int) targetPC.statStrBase * 3); - output += newline; - output += "ALTITUDE :"+ targetPC.getAltitude(); - output += newline; - output += "BuildingID :"+ targetPC.getInBuildingID(); - output += newline; - output += "inBuilding :"+ targetPC.getInBuilding(); - output += newline; - output += "inFloor :"+ targetPC.getInFloorID(); - output += newline; - - BaseClass baseClass = targetPC.getBaseClass(); - - if (baseClass != null) - output += StringUtils.addWS("Class: " + baseClass.getName(), 20); - else - output += StringUtils.addWS("", 20); - - PromotionClass promotionClass = targetPC.getPromotionClass(); - if (promotionClass != null) { - output += "Pro. Class: " + promotionClass.getName(); - } else { - output += "Pro. Class: "; - } - - output += newline; - output += "====Guild Info===="; - output += newline; - - if (targetPC.getGuild() != null){ - output += "Name: " + targetPC.getGuild().getName(); - output += newline; - output += "State: " + targetPC.getGuild().getGuildState(); - output += newline; - output += "Realms Owned:" +targetPC.getGuild().getRealmsOwned(); - output += newline; - output += "====Nation===="; - output += newline; - output += "Nation Name: " + targetPC.getGuild().getNation().getName(); - output += newline; - output += "Nation State: " + targetPC.getGuild().getNation().getGuildState(); - output += newline; - output += "Realms Owned:" +targetPC.getGuild().getNation().getRealmsOwned(); - output += newline; - output += "Guild Rank:" +(GuildStatusController.getRank(targetPC.getGuildStatus()) + targetPC.getGuild().getRealmsOwnedFlag()); - } - - output += newline; - output += "Movement State: " + targetPC.getMovementState().name(); - output += newline; - output += "Movement Speed: " + targetPC.getSpeed(); - - output += "Altitude : " + targetPC.getLoc().y; - - output += "Swimming : " + targetPC.isSwimming(); - output += newline; - output += "isMoving : " + targetPC.isMoving(); - - break; - - case NPC: - NPC targetNPC = (NPC) target; - output += "databaseID: " + targetNPC.getDBID() + newline; - output += "Name: " + targetNPC.getName(); - output += newline; - output += StringUtils.addWS("Level: " + targetNPC.getLevel(), 20); - - MobBase mobBase; - - if (targetNPC.getContract() == null) - mobBase = targetNPC.getMobBase(); - else - mobBase = MobBase.getMobBase(targetNPC.getContract().getMobbaseID()); - - if (mobBase != null) { - output += "Mobbbase: " + mobBase.getObjectUUID(); - output += newline; - output += "Flags: " + mobBase.getFlags().toString(); - } - - output += newline; - output += "Spawn: (" + targetNPC.getBindLoc().getX(); - output += ", " + targetNPC.getBindLoc().getY(); - output += ", " + targetNPC.getBindLoc().getZ() + ')'; - output += newline; - output += "ContractID: " + targetNPC.getContractID(); - output += newline; - output += "InventorySet: " + targetNPC.getContract().inventorySet; - output += newline; - output += targetNPC.getContract().getAllowedBuildings().toString(); - output += newline; - output += "Extra Rune: " + targetNPC.getContract().getExtraRune(); - - output += newline; - output += "isTrainer: " + targetNPC.getContract().isTrainer(); - output += newline; - output += "Buy Cost: " + targetNPC.getBuyPercent(); - output += "\tSell Cost: " + targetNPC.getSellPercent(); - output += newline; - output += "fromInit: " + targetNPC.isStatic(); - output += newline; - if (mobBase != null) { - output += newline; - output += "Slottable: " + targetNPC.getContract().getAllowedBuildings().toString(); - output += newline; - output += "EquipSet: " + targetNPC.getEquipmentSetID(); - output += newline; - output += "Parent Zone LoadNum : " + targetNPC.getParentZone().getLoadNum(); - - } - - if (targetNPC.region != null) { - output += newline; - output += "Region found: " + "Building : " + targetNPC.region.parentBuildingID + newline; - output += "building level : " + targetNPC.region.level + newline; - output += "building room : " + targetNPC.region.room + newline; - } else { - output += newline; - output += "No region was found."; - } - - if (targetNPC.getBuilding() != null) { - output += newline; - output += "Building : " + targetNPC.getBuilding(); - } else { - output += newline; - output += "No building found."; - } - break; - case Mob: - Mob targetMob = (Mob) target; - output += "databaseID: " + targetMob.getDBID() + newline; - output += "Name: " + targetMob.getName(); - output += newline; - output += StringUtils.addWS("Level: " + targetMob.getLevel(), 20); - mobBase = targetMob.getMobBase(); - if (mobBase != null) - output += "RaceID: " + mobBase.getObjectUUID(); - else - output += "RaceID: " + targetMob.getLoadID(); - output += newline; - try { - output += "notEnemy: " + targetMob.notEnemy.toString(); - output += newline; - output += "enemy: " + targetMob.enemy.toString(); - output += newline; - } - catch(Exception ex){ - //who cares its info - } - output += "Spawn: (" + targetMob.getBindLoc().getX(); - output += ", " + targetMob.getBindLoc().getY(); - output += ", " + targetMob.getBindLoc().getZ() + ')'; - output += newline; - if (targetMob.isPet()) { - output += "isPet: true"; - output+= newline; - if (targetMob.isSummonedPet()) - output += "isSummonedPet: true"; - else output += "isSummonedPet: false"; - PlayerCharacter owner = targetMob.getOwner(); - if (owner != null) - output += " owner: " + owner.getObjectUUID(); - output += newline; - output += "assist: " + targetMob.assist() + " resting: " + targetMob.isSit(); - output += newline; - } - if (targetMob.getMobBase() != null) { - output += "Mobbase: " + targetMob.getMobBase().getObjectUUID(); - output += newline; - output += "Flags: " + targetMob.getMobBase().getFlags().toString(); - output += newline; - - } - if (targetMob.isMob()) { - output += "SpawnRadius: " + targetMob.getSpawnRadius(); - output += newline; - output += "Spawn Timer: " + targetMob.getSpawnTimeAsString(); - output += newline; - } - output += StringUtils.addWS("isAlive: " - + targetMob.isAlive(), 20); - output += newline; - //output += "Mob State: " + targetMob.state.name(); - - output += newline; - output += "Speed : " + targetMob.getSpeed(); - output += newline; - output += "EquipSet: " + targetMob.equipmentSetID; - output += newline; - try { - output += "Parent Zone LoadNum : " + targetMob.getParentZone().getLoadNum(); - } catch(Exception ex){ - //who cares - } - output += newline; - output += "isMoving : " + targetMob.isMoving(); - if (targetMob.region != null) { - output += newline; - output += "BuildingID : " + targetMob.region.parentBuildingID; - output += "building level : " + targetMob.region.level; - output += "building room : " + targetMob.region.room; - } - if (targetMob.building != null) { - output += "Building Name: " + targetMob.building.getName() + newline; - output += "BuildingID : " + targetMob.building + newline; - output += "Bind Loc : " + targetMob.getBindLoc() + newline; - output += "Curr Loc : " + targetMob.getLoc() + newline; - }else{ - output += newline; - output += "No building found."; - } - break; - case Item: //intentional passthrough - case MobLoot: - Item item = (Item) target; - ItemBase itemBase = item.getItemBase(); - output += StringUtils.addWS("ItemBase: " + itemBase.getUUID(), 20); - output += "Weight: " + itemBase.getWeight(); - output += newline; - DecimalFormat df = new DecimalFormat("###,###,###,###,##0"); - output += StringUtils.addWS("Qty: " - + df.format(item.getNumOfItems()), 20); - output += "Charges: " + item.getChargesRemaining() - + '/' + item.getChargesMax(); - output += newline; - output += "Name: " + itemBase.getName(); - output += newline; - output += item.getContainerInfo(); - - throwbackInfo(pc, output); - - output = "Effects:" + newline; - ConcurrentHashMap effects = item.getEffects(); - for (String name : effects.keySet()) { - Effect eff = effects.get(name); - output+= eff.getEffectsBase().getIDString(); - output+= newline; - // output += eff.getEffectToken() + (eff.bakedInStat() ? " (baked in)" : "") + newline; - } - - break; - } - - throwbackInfo(pc, output); - } - - @Override - protected String _getHelpString() { - return "Gets information on an Object."; - } - - @Override - protected String _getUsageString() { - return "' /info targetID'"; - } + } + + switch (objType) { + case Building: + Building targetBuilding = (Building) target; + output += StringUtils.addWS("Lac: " + + targetBuilding.getw(), 20); + output += "Blueprint : "; + output += targetBuilding.getBlueprintUUID(); + output += newline; + + output += " MeshUUID : "; + output += targetBuilding.getMeshUUID(); + output += newline; + + if (targetBuilding.getBlueprintUUID() != 0) + output += ' ' + targetBuilding.getBlueprint().getName(); + + output += newline; + output += targetBuilding.getBlueprint() != null ? targetBuilding.getBlueprint().getBuildingGroup().name() : " no building group"; + + output += newline; + output += "EffectFlags: " + targetBuilding.getEffectFlags(); + output += newline; + output += StringUtils.addWS("rank: " + targetBuilding.getRank(), + 20); + output += "HP: " + targetBuilding.getHealth() + '/' + + targetBuilding.getMaxHitPoints(); + output += newline; + output += "Scale: (" + targetBuilding.getMeshScale().getX(); + output += ", " + targetBuilding.getMeshScale().getY(); + output += ", " + targetBuilding.getMeshScale().getZ() + ')'; + output += newline; + output += "Owner UID: " + targetBuilding.getOwnerUUID(); + output += (targetBuilding.isOwnerIsNPC() ? " (NPC)" : " (PC)"); + output += newline; + output += "ProtectionState: " + targetBuilding.getProtectionState().name(); + output += newline; + + if (targetBuilding.getUpgradeDateTime() != null) { + output += targetBuilding.getUpgradeDateTime().toString(); + output += newline; + } + + Guild guild = targetBuilding.getGuild(); + Guild nation = null; + String guildId = "-1"; + String nationId = "-1"; + String gTag = ""; + String nTag = ""; + + if (guild != null) { + int id = guild.getObjectUUID(); + + if (id == 0) { + guildId = id + " [" + guild.hashCode() + ']'; + } else + guildId = Integer.toString(id); + + gTag = guild.getGuildTag().summarySentence(); + nation = guild.getNation(); + + if (nation != null) { + id = nation.getObjectUUID(); + if (id == 0) { + nationId = id + " [" + nation.hashCode() + ']'; + } else { + nationId = Integer.toString(id); + } + nTag = nation.getGuildTag().summarySentence(); + } + } + output += StringUtils.addWS("Guild UID: " + guildId, 20); + + if (gTag.length() > 0) + output += "Guild crest: " + gTag; + + output += newline; + output += StringUtils.addWS("Nation UID: " + nationId, 20); + + if (nTag.length() > 0) { + output += "Nation crest: " + nTag; + } + + output += newline; + + + if (targetBuilding.getBlueprint() != null) { + + if (targetBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.MINE) { + Mine mine = Mine.getMineFromTower(targetBuilding.getObjectUUID()); + + if (mine != null) { + output += newline; + output += "Mine active: " + mine.getIsActive(); + output += newline; + output += "Was claimed: " + mine.wasClaimed; + output += newline; + output += "Mine Type: " + mine.getMineType().name; + output += newline; + output += "Expansion : " + mine.isExpansion(); + output += newline; + output += "Production type: " + mine.getProduction().name(); + + } + } + output += newline; + + if (targetBuilding.maintDateTime != null) { + output += targetBuilding.maintDateTime.toString(); + output += newline; + } + } + + output += "Reserve : " + targetBuilding.reserve; + output += newline; + output += "Strongbox : " + targetBuilding.getStrongboxValue(); + output += newline; + + // List hirelings + + if (targetBuilding.getHirelings().isEmpty() == false) { + + output += newline; + output += "Hirelings List: name / slot / floor"; + + for (AbstractCharacter npc : targetBuilding.getHirelings().keySet()) { + + if (npc.getObjectType() != GameObjectType.NPC) + continue; + output += newline + npc.getName() + " slot " + targetBuilding.getHirelings().get(npc); + output += newline + "location " + npc.getLoc(); + } + } + + ArrayList tempList = BuildingRegions._staticRegions.get(targetBuilding.getMeshUUID()); + output += newline; + output += "Building Regions: Size - " + tempList.size(); + output += newline; + output += "Building Regions from Bounds: Size - " + targetBuilding.getBounds().getRegions().size(); + output += newline; + + for (Regions regions : targetBuilding.getBounds().getRegions()) { + //TODO ADD REGION INFO + } + + break; + case PlayerCharacter: + output += newline; + PlayerCharacter targetPC = (PlayerCharacter) target; + output += StringUtils.addWS("Name: " + targetPC.getName(), 20); + output += newline; + output += "InSession : " + SessionManager.getPlayerCharacterByID(target.getObjectUUID()) != null ? " true " : " false"; + output += newline; + output += "RaceType: " + targetPC.getRace().getRaceType().name(); + output += newline; + output += "Race: " + targetPC.getRace().getName(); + output += newline; + output += "Safe:" + targetPC.inSafeZone(); + output += newline; + output += "Experience : " + targetPC.getExp(); + output += newline; + output += "OverFlowExperience : " + targetPC.getOverFlowEXP(); + output += newline; + output += StringUtils.addWS("Level: " + + targetPC.getLevel() + " (" + + TargetColor.getCon(targetPC, pc).toString() + ')', 20); + + Account acpc = SessionManager.getAccount(pc); + Account ac = SessionManager.getAccount(targetPC); + + if (acpc != null && ac != null) { + output += "Account ID: " + ac.getObjectUUID(); + output += newline; + output += "Access Level: " + ac.status.name(); + } else + output += "Account ID: UNKNOWN"; + + output += newline; + output += "Inventory Weight:" + (targetPC.getCharItemManager().getInventoryWeight() + targetPC.getCharItemManager().getEquipWeight()); + output += newline; + output += "Max Inventory Weight:" + ((int) targetPC.statStrBase * 3); + output += newline; + output += "ALTITUDE :" + targetPC.getAltitude(); + output += newline; + output += "BuildingID :" + targetPC.getInBuildingID(); + output += newline; + output += "inBuilding :" + targetPC.getInBuilding(); + output += newline; + output += "inFloor :" + targetPC.getInFloorID(); + output += newline; + + BaseClass baseClass = targetPC.getBaseClass(); + + if (baseClass != null) + output += StringUtils.addWS("Class: " + baseClass.getName(), 20); + else + output += StringUtils.addWS("", 20); + + PromotionClass promotionClass = targetPC.getPromotionClass(); + if (promotionClass != null) { + output += "Pro. Class: " + promotionClass.getName(); + } else { + output += "Pro. Class: "; + } + + output += newline; + output += "====Guild Info===="; + output += newline; + + if (targetPC.getGuild() != null) { + output += "Name: " + targetPC.getGuild().getName(); + output += newline; + output += "State: " + targetPC.getGuild().getGuildState(); + output += newline; + output += "Realms Owned:" + targetPC.getGuild().getRealmsOwned(); + output += newline; + output += "====Nation===="; + output += newline; + output += "Nation Name: " + targetPC.getGuild().getNation().getName(); + output += newline; + output += "Nation State: " + targetPC.getGuild().getNation().getGuildState(); + output += newline; + output += "Realms Owned:" + targetPC.getGuild().getNation().getRealmsOwned(); + output += newline; + output += "Guild Rank:" + (GuildStatusController.getRank(targetPC.getGuildStatus()) + targetPC.getGuild().getRealmsOwnedFlag()); + } + + output += newline; + output += "Movement State: " + targetPC.getMovementState().name(); + output += newline; + output += "Movement Speed: " + targetPC.getSpeed(); + + output += "Altitude : " + targetPC.getLoc().y; + + output += "Swimming : " + targetPC.isSwimming(); + output += newline; + output += "isMoving : " + targetPC.isMoving(); + + break; + + case NPC: + NPC targetNPC = (NPC) target; + output += "databaseID: " + targetNPC.getDBID() + newline; + output += "Name: " + targetNPC.getName(); + output += newline; + output += StringUtils.addWS("Level: " + targetNPC.getLevel(), 20); + + MobBase mobBase; + + if (targetNPC.getContract() == null) + mobBase = targetNPC.getMobBase(); + else + mobBase = MobBase.getMobBase(targetNPC.getContract().getMobbaseID()); + + if (mobBase != null) { + output += "Mobbbase: " + mobBase.getObjectUUID(); + output += newline; + output += "Flags: " + mobBase.getFlags().toString(); + } + + output += newline; + output += "Spawn: (" + targetNPC.getBindLoc().getX(); + output += ", " + targetNPC.getBindLoc().getY(); + output += ", " + targetNPC.getBindLoc().getZ() + ')'; + output += newline; + output += "ContractID: " + targetNPC.getContractID(); + output += newline; + output += "InventorySet: " + targetNPC.getContract().inventorySet; + output += newline; + output += targetNPC.getContract().getAllowedBuildings().toString(); + output += newline; + output += "Extra Rune: " + targetNPC.getContract().getExtraRune(); + + output += newline; + output += "isTrainer: " + targetNPC.getContract().isTrainer(); + output += newline; + output += "Buy Cost: " + targetNPC.getBuyPercent(); + output += "\tSell Cost: " + targetNPC.getSellPercent(); + output += newline; + output += "fromInit: " + targetNPC.isStatic(); + output += newline; + if (mobBase != null) { + output += newline; + output += "Slottable: " + targetNPC.getContract().getAllowedBuildings().toString(); + output += newline; + output += "EquipSet: " + targetNPC.getEquipmentSetID(); + output += newline; + output += "Parent Zone LoadNum : " + targetNPC.getParentZone().getLoadNum(); + + } + + if (targetNPC.region != null) { + output += newline; + output += "Region found: " + "Building : " + targetNPC.region.parentBuildingID + newline; + output += "building level : " + targetNPC.region.level + newline; + output += "building room : " + targetNPC.region.room + newline; + } else { + output += newline; + output += "No region was found."; + } + + if (targetNPC.getBuilding() != null) { + output += newline; + output += "Building : " + targetNPC.getBuilding(); + } else { + output += newline; + output += "No building found."; + } + break; + case Mob: + Mob targetMob = (Mob) target; + output += "databaseID: " + targetMob.getDBID() + newline; + output += "Name: " + targetMob.getName(); + output += newline; + output += StringUtils.addWS("Level: " + targetMob.getLevel(), 20); + mobBase = targetMob.getMobBase(); + if (mobBase != null) + output += "RaceID: " + mobBase.getObjectUUID(); + else + output += "RaceID: " + targetMob.getLoadID(); + output += newline; + try { + output += "notEnemy: " + targetMob.notEnemy.toString(); + output += newline; + output += "enemy: " + targetMob.enemy.toString(); + output += newline; + } catch (Exception ex) { + //who cares its info + } + output += "Spawn: (" + targetMob.getBindLoc().getX(); + output += ", " + targetMob.getBindLoc().getY(); + output += ", " + targetMob.getBindLoc().getZ() + ')'; + output += newline; + if (targetMob.isPet()) { + output += "isPet: true"; + output += newline; + if (targetMob.isSummonedPet()) + output += "isSummonedPet: true"; + else + output += "isSummonedPet: false"; + PlayerCharacter owner = targetMob.getOwner(); + if (owner != null) + output += " owner: " + owner.getObjectUUID(); + output += newline; + output += "assist: " + targetMob.assist() + " resting: " + targetMob.isSit(); + output += newline; + } + if (targetMob.getMobBase() != null) { + output += "Mobbase: " + targetMob.getMobBase().getObjectUUID(); + output += newline; + output += "Flags: " + targetMob.getMobBase().getFlags().toString(); + output += newline; + + } + if (targetMob.isMob()) { + output += "SpawnRadius: " + targetMob.getSpawnRadius(); + output += newline; + output += "Spawn Timer: " + targetMob.getSpawnTimeAsString(); + output += newline; + } + output += StringUtils.addWS("isAlive: " + + targetMob.isAlive(), 20); + output += newline; + //output += "Mob State: " + targetMob.state.name(); + + output += newline; + output += "Speed : " + targetMob.getSpeed(); + output += newline; + output += "EquipSet: " + targetMob.equipmentSetID; + output += newline; + try { + output += "Parent Zone LoadNum : " + targetMob.getParentZone().getLoadNum(); + } catch (Exception ex) { + //who cares + } + output += newline; + output += "isMoving : " + targetMob.isMoving(); + if (targetMob.region != null) { + output += newline; + output += "BuildingID : " + targetMob.region.parentBuildingID; + output += "building level : " + targetMob.region.level; + output += "building room : " + targetMob.region.room; + } + if (targetMob.building != null) { + output += "Building Name: " + targetMob.building.getName() + newline; + output += "BuildingID : " + targetMob.building + newline; + output += "Bind Loc : " + targetMob.getBindLoc() + newline; + output += "Curr Loc : " + targetMob.getLoc() + newline; + } else { + output += newline; + output += "No building found."; + } + break; + case Item: //intentional passthrough + case MobLoot: + Item item = (Item) target; + ItemBase itemBase = item.getItemBase(); + output += StringUtils.addWS("ItemBase: " + itemBase.getUUID(), 20); + output += "Weight: " + itemBase.getWeight(); + output += newline; + DecimalFormat df = new DecimalFormat("###,###,###,###,##0"); + output += StringUtils.addWS("Qty: " + + df.format(item.getNumOfItems()), 20); + output += "Charges: " + item.getChargesRemaining() + + '/' + item.getChargesMax(); + output += newline; + output += "Name: " + itemBase.getName(); + output += newline; + output += item.getContainerInfo(); + + throwbackInfo(pc, output); + + output = "Effects:" + newline; + ConcurrentHashMap effects = item.getEffects(); + for (String name : effects.keySet()) { + Effect eff = effects.get(name); + output += eff.getEffectsBase().getIDString(); + output += newline; + // output += eff.getEffectToken() + (eff.bakedInStat() ? " (baked in)" : "") + newline; + } + + break; + } + + throwbackInfo(pc, output); + } + + @Override + protected String _getHelpString() { + return "Gets information on an Object."; + } + + @Override + protected String _getUsageString() { + return "' /info targetID'"; + } } diff --git a/src/engine/devcmd/cmds/JumpCmd.java b/src/engine/devcmd/cmds/JumpCmd.java index c85ff0a6..7da57eb3 100644 --- a/src/engine/devcmd/cmds/JumpCmd.java +++ b/src/engine/devcmd/cmds/JumpCmd.java @@ -16,70 +16,70 @@ import engine.objects.PlayerCharacter; public class JumpCmd extends AbstractDevCmd { - public JumpCmd() { + public JumpCmd() { super("jump"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - // Arg Count Check - if (words.length != 2) { - this.sendUsage(pc); - return; - } - - //test - - if (words[0].equalsIgnoreCase("face")){ - - try { - float range = Float.parseFloat(words[1]); - Vector3fImmutable newLoc = pc.getFaceDir().scaleAdd(range, pc.getLoc()); - pc.teleport(newLoc); - - - } catch (NumberFormatException e) { - this.throwbackError(pc, "" - + " failed to parse to Floats"); - return; - - } - return; - } - float lat = 0.0f, lon = 0.0f; - String latLong = '\'' + words[0] + ", " + words[1] + '\''; - - try { - lat = Float.parseFloat(words[0]); - lon = Float.parseFloat(words[1]); - - } catch (NumberFormatException e) { - this.throwbackError(pc, "Supplied LatLong: " + latLong - + " failed to parse to Floats"); - return; - - } catch (Exception e) { - this.throwbackError(pc, - "An unknown exception occurred while attempting to jump to LatLong of " - + latLong); - return; - } - - Vector3fImmutable loc = pc.getLoc(); - loc = loc.add(lat, 0f, -lon); - pc.teleport(loc); - } - - @Override - protected String _getHelpString() { - return "Alters your characters position by 'lat' and 'long'. This does not transport you TO 'lat' and 'long', but rather BY 'lat' and 'long' "; - - } - - @Override - protected String _getUsageString() { - return "' /jump lat long'"; - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + // Arg Count Check + if (words.length != 2) { + this.sendUsage(pc); + return; + } + + //test + + if (words[0].equalsIgnoreCase("face")) { + + try { + float range = Float.parseFloat(words[1]); + Vector3fImmutable newLoc = pc.getFaceDir().scaleAdd(range, pc.getLoc()); + pc.teleport(newLoc); + + + } catch (NumberFormatException e) { + this.throwbackError(pc, "" + + " failed to parse to Floats"); + return; + + } + return; + } + float lat = 0.0f, lon = 0.0f; + String latLong = '\'' + words[0] + ", " + words[1] + '\''; + + try { + lat = Float.parseFloat(words[0]); + lon = Float.parseFloat(words[1]); + + } catch (NumberFormatException e) { + this.throwbackError(pc, "Supplied LatLong: " + latLong + + " failed to parse to Floats"); + return; + + } catch (Exception e) { + this.throwbackError(pc, + "An unknown exception occurred while attempting to jump to LatLong of " + + latLong); + return; + } + + Vector3fImmutable loc = pc.getLoc(); + loc = loc.add(lat, 0f, -lon); + pc.teleport(loc); + } + + @Override + protected String _getHelpString() { + return "Alters your characters position by 'lat' and 'long'. This does not transport you TO 'lat' and 'long', but rather BY 'lat' and 'long' "; + + } + + @Override + protected String _getUsageString() { + return "' /jump lat long'"; + } } diff --git a/src/engine/devcmd/cmds/MBDropCmd.java b/src/engine/devcmd/cmds/MBDropCmd.java index 89957656..5e5bfbe8 100644 --- a/src/engine/devcmd/cmds/MBDropCmd.java +++ b/src/engine/devcmd/cmds/MBDropCmd.java @@ -16,119 +16,117 @@ import engine.objects.LootTable; import engine.objects.PlayerCharacter; /** - * * @author Eighty - * */ public class MBDropCmd extends AbstractDevCmd { - public MBDropCmd() { + public MBDropCmd() { super("mbdrop"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - String newline = "\r\n "; - if (args.length != 1){ - this.sendUsage(pcSender); - this.sendHelp(pcSender); - return; - } + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] args, + AbstractGameObject target) { + String newline = "\r\n "; + if (args.length != 1) { + this.sendUsage(pcSender); + this.sendHelp(pcSender); + return; + } - String output = ""; - switch (args[0].toLowerCase()){ - case "clear": + String output = ""; + switch (args[0].toLowerCase()) { + case "clear": - LootTable.contractCount = 0; - LootTable.dropCount = 0; - LootTable.glassCount = 0; - LootTable.runeCount = 0; - LootTable.rollCount = 0; - LootTable.resourceCount = 0; + LootTable.contractCount = 0; + LootTable.dropCount = 0; + LootTable.glassCount = 0; + LootTable.runeCount = 0; + LootTable.rollCount = 0; + LootTable.resourceCount = 0; - LootTable.contractDroppedMap.clear(); - LootTable.glassDroppedMap.clear(); - LootTable.itemsDroppedMap.clear(); - LootTable.resourceDroppedMap.clear(); - LootTable.runeDroppedMap.clear(); - break; - case "all": - output = LootTable.dropCount + " items - ITEM NAME : DROP COUNT" + newline; - for (ItemBase ib: LootTable.itemsDroppedMap.keySet()){ + LootTable.contractDroppedMap.clear(); + LootTable.glassDroppedMap.clear(); + LootTable.itemsDroppedMap.clear(); + LootTable.resourceDroppedMap.clear(); + LootTable.runeDroppedMap.clear(); + break; + case "all": + output = LootTable.dropCount + " items - ITEM NAME : DROP COUNT" + newline; + for (ItemBase ib : LootTable.itemsDroppedMap.keySet()) { - int dropCount = LootTable.itemsDroppedMap.get(ib); - output += ib.getName() + " : " + dropCount + newline; + int dropCount = LootTable.itemsDroppedMap.get(ib); + output += ib.getName() + " : " + dropCount + newline; - } - break; - case "resource": - output = LootTable.resourceCount + " Resources - ITEM NAME : DROP COUNT" + newline; - for (ItemBase ib: LootTable.resourceDroppedMap.keySet()){ + } + break; + case "resource": + output = LootTable.resourceCount + " Resources - ITEM NAME : DROP COUNT" + newline; + for (ItemBase ib : LootTable.resourceDroppedMap.keySet()) { - int dropCount = LootTable.resourceDroppedMap.get(ib); - output += ib.getName() + " : " + dropCount + newline; + int dropCount = LootTable.resourceDroppedMap.get(ib); + output += ib.getName() + " : " + dropCount + newline; - } + } - break; - case "rune": + break; + case "rune": - output = LootTable.runeCount + " Runes - ITEM NAME : DROP COUNT" + newline; - for (ItemBase ib: LootTable.runeDroppedMap.keySet()){ + output = LootTable.runeCount + " Runes - ITEM NAME : DROP COUNT" + newline; + for (ItemBase ib : LootTable.runeDroppedMap.keySet()) { - int dropCount = LootTable.runeDroppedMap.get(ib); - output += ib.getName() + " : " + dropCount + newline; + int dropCount = LootTable.runeDroppedMap.get(ib); + output += ib.getName() + " : " + dropCount + newline; - } - break; - case "contract": + } + break; + case "contract": - output = LootTable.contractCount + " Contracts - ITEM NAME : DROP COUNT" + newline; - for (ItemBase ib: LootTable.contractDroppedMap.keySet()){ + output = LootTable.contractCount + " Contracts - ITEM NAME : DROP COUNT" + newline; + for (ItemBase ib : LootTable.contractDroppedMap.keySet()) { - int dropCount = LootTable.contractDroppedMap.get(ib); - output += ib.getName() + " : " + dropCount + newline; + int dropCount = LootTable.contractDroppedMap.get(ib); + output += ib.getName() + " : " + dropCount + newline; - } - break; + } + break; - case "glass": + case "glass": - output = LootTable.glassCount + " Glass - ITEM NAME : DROP COUNT" + newline; - for (ItemBase ib: LootTable.glassDroppedMap.keySet()){ + output = LootTable.glassCount + " Glass - ITEM NAME : DROP COUNT" + newline; + for (ItemBase ib : LootTable.glassDroppedMap.keySet()) { - int dropCount = LootTable.glassDroppedMap.get(ib); - output += ib.getName() + " : " + dropCount + newline; - } - break; + int dropCount = LootTable.glassDroppedMap.get(ib); + output += ib.getName() + " : " + dropCount + newline; + } + break; - case "chance": - float chance = (float)LootTable.dropCount/(float)LootTable.rollCount * 100; - output = LootTable.dropCount + " out of " + LootTable.rollCount + " items Dropped. chance = " + chance + '%'; + case "chance": + float chance = (float) LootTable.dropCount / (float) LootTable.rollCount * 100; + output = LootTable.dropCount + " out of " + LootTable.rollCount + " items Dropped. chance = " + chance + '%'; - break; + break; - default: - this.sendUsage(pcSender); - this.sendHelp(pcSender); - return; - } + default: + this.sendUsage(pcSender); + this.sendHelp(pcSender); + return; + } - this.throwbackInfo(pcSender, output); + this.throwbackInfo(pcSender, output); - } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /mbdrop all/resource/rune/contract/glass/chance/clear"; - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Lists drops for server since a reboot. All lists all items and drops. chance is the overall chance items drop from mobs on server. (not including Equipment)"; - } + } } diff --git a/src/engine/devcmd/cmds/MakeBaneCmd.java b/src/engine/devcmd/cmds/MakeBaneCmd.java index 85f17c0e..e4328ec0 100644 --- a/src/engine/devcmd/cmds/MakeBaneCmd.java +++ b/src/engine/devcmd/cmds/MakeBaneCmd.java @@ -23,193 +23,190 @@ import org.pmw.tinylog.Logger; /** * @author Eighty - * */ public class MakeBaneCmd extends AbstractDevCmd { - public MakeBaneCmd() { + public MakeBaneCmd() { super("makebane"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - if (words.length < 1 || words.length > 2) { - this.sendUsage(pc); - return; - } - - int attackerID = 0; - int rank = 8; - - if (words.length == 2) { - try { - attackerID = Integer.parseInt(words[0]); - rank = Integer.parseInt(words[1]); - } catch (NumberFormatException e) { - throwbackError(pc, "AttackerGuildID must be a number, " + words[0] + " is invalid"); - return; - } - } else if (words.length == 1) { - if (target == null) { - throwbackError(pc, "No target specified"); - return; - } - - if (!(target instanceof PlayerCharacter)) { - throwbackError(pc, "Target is not a player"); - return; - } - attackerID = target.getObjectUUID(); - - try { - rank = Integer.parseInt(words[0]); - } catch (NumberFormatException e) { - throwbackError(pc, "Rank must be specified, 1 through 8"); - return; - } - } - - if (rank < 1 || rank > 8) { - throwbackError(pc, "Rank must be 1 through 8"); - return; - } - - PlayerCharacter player = PlayerCharacter.getPlayerCharacter(attackerID); - - - - - if (player.getGuild().isEmptyGuild()) { - throwbackError(pc, "Errant's can not place banes"); - return; - } - - AbstractCharacter attackerAGL = Guild.GetGL(player.getGuild()); - - if (attackerAGL == null) { - throwbackError(pc, "No guild leader found for attacking guild."); - return; - } - - if (!(attackerAGL instanceof PlayerCharacter)) { - throwbackError(pc, "Attacking guild leader is an NPC."); - return; - } - - if (player.getGuild().isNPCGuild()) { - throwbackError(pc, "The guild used is an npc guild. They can not bane."); - return; - } - - // if (player.getGuild().getOwnedCity() != null) { - // throwbackError(pc, "The attacking guild already has a city."); - // return; - // } - - Zone zone = ZoneManager.findSmallestZone(pc.getLoc()); - - if (zone == null) { - throwbackError(pc, "Unable to find the zone you're in."); - return; - } - - if (!zone.isPlayerCity()) { - throwbackError(pc, "This is not a player city."); - return; - } - - City city = City.getCity(zone.getPlayerCityUUID()); - if (city == null) { - throwbackError(pc, "Unable to find the city associated with this zone."); - return; - } - - if (city.getTOL() == null) { - throwbackError(pc, "Unable to find the tree of life for this city."); - return; - } - - if (city.getBane() != null) { - throwbackError(pc, "This city is already baned."); - return; - } - - if (Bane.getBaneByAttackerGuild(player.getGuild()) != null) { - throwbackError(pc, "This guild is already baning someone."); - return; - } - - Blueprint blueprint = Blueprint.getBlueprint(24300); - - if (blueprint == null) { - throwbackError(pc, "Unable to find building set for banestone."); - return; - } - - Vector3f rot = new Vector3f(0, 0, 0); - - // *** Refactor : Overlap test goes here - - //Let's drop a banestone! - Vector3fImmutable localLocation = ZoneManager.worldToLocal(pc.getLoc(), zone); + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + if (words.length < 1 || words.length > 2) { + this.sendUsage(pc); + return; + } + + int attackerID = 0; + int rank = 8; + + if (words.length == 2) { + try { + attackerID = Integer.parseInt(words[0]); + rank = Integer.parseInt(words[1]); + } catch (NumberFormatException e) { + throwbackError(pc, "AttackerGuildID must be a number, " + words[0] + " is invalid"); + return; + } + } else if (words.length == 1) { + if (target == null) { + throwbackError(pc, "No target specified"); + return; + } + + if (!(target instanceof PlayerCharacter)) { + throwbackError(pc, "Target is not a player"); + return; + } + attackerID = target.getObjectUUID(); + + try { + rank = Integer.parseInt(words[0]); + } catch (NumberFormatException e) { + throwbackError(pc, "Rank must be specified, 1 through 8"); + return; + } + } + + if (rank < 1 || rank > 8) { + throwbackError(pc, "Rank must be 1 through 8"); + return; + } + + PlayerCharacter player = PlayerCharacter.getPlayerCharacter(attackerID); + + + if (player.getGuild().isEmptyGuild()) { + throwbackError(pc, "Errant's can not place banes"); + return; + } + + AbstractCharacter attackerAGL = Guild.GetGL(player.getGuild()); + + if (attackerAGL == null) { + throwbackError(pc, "No guild leader found for attacking guild."); + return; + } + + if (!(attackerAGL instanceof PlayerCharacter)) { + throwbackError(pc, "Attacking guild leader is an NPC."); + return; + } + + if (player.getGuild().isNPCGuild()) { + throwbackError(pc, "The guild used is an npc guild. They can not bane."); + return; + } + + // if (player.getGuild().getOwnedCity() != null) { + // throwbackError(pc, "The attacking guild already has a city."); + // return; + // } + + Zone zone = ZoneManager.findSmallestZone(pc.getLoc()); + + if (zone == null) { + throwbackError(pc, "Unable to find the zone you're in."); + return; + } + + if (!zone.isPlayerCity()) { + throwbackError(pc, "This is not a player city."); + return; + } + + City city = City.getCity(zone.getPlayerCityUUID()); + if (city == null) { + throwbackError(pc, "Unable to find the city associated with this zone."); + return; + } + + if (city.getTOL() == null) { + throwbackError(pc, "Unable to find the tree of life for this city."); + return; + } + + if (city.getBane() != null) { + throwbackError(pc, "This city is already baned."); + return; + } + + if (Bane.getBaneByAttackerGuild(player.getGuild()) != null) { + throwbackError(pc, "This guild is already baning someone."); + return; + } + + Blueprint blueprint = Blueprint.getBlueprint(24300); + + if (blueprint == null) { + throwbackError(pc, "Unable to find building set for banestone."); + return; + } + + Vector3f rot = new Vector3f(0, 0, 0); + + // *** Refactor : Overlap test goes here + + //Let's drop a banestone! + Vector3fImmutable localLocation = ZoneManager.worldToLocal(pc.getLoc(), zone); + + if (localLocation == null) { + ChatManager.chatSystemError(pc, "Failed to convert world location to zone location. Contact a CCR."); + Logger.info("Failed to Convert World coordinates to local zone coordinates"); + return; + } + + Building stone = DbManager.BuildingQueries.CREATE_BUILDING( + zone.getObjectUUID(), pc.getObjectUUID(), blueprint.getName(), blueprint.getBlueprintUUID(), + localLocation, 1.0f, blueprint.getMaxHealth(rank), ProtectionState.PROTECTED, 0, rank, + null, blueprint.getBlueprintUUID(), 1, 0.0f); + + if (stone == null) { + ChatManager.chatSystemError(pc, "Failed to create banestone."); + return; + } + stone.addEffectBit((1 << 19)); + stone.setRank((byte) rank); + stone.setMaxHitPoints(blueprint.getMaxHealth(stone.getRank())); + stone.setCurrentHitPoints(stone.getMaxHitPoints()); + BuildingManager.setUpgradeDateTime(stone, null, 0); - if (localLocation == null){ - ChatManager.chatSystemError(pc, "Failed to convert world location to zone location. Contact a CCR."); - Logger.info("Failed to Convert World coordinates to local zone coordinates"); - return; - } + //Make the bane - Building stone = DbManager.BuildingQueries.CREATE_BUILDING( - zone.getObjectUUID(), pc.getObjectUUID(), blueprint.getName(), blueprint.getBlueprintUUID(), - localLocation, 1.0f, blueprint.getMaxHealth(rank), ProtectionState.PROTECTED, 0, rank, - null, blueprint.getBlueprintUUID(), 1, 0.0f); + Bane bane = Bane.makeBane(player, city, stone); - if (stone == null) { - ChatManager.chatSystemError(pc, "Failed to create banestone."); - return; - } - stone.addEffectBit((1 << 19)); - stone.setRank((byte) rank); - stone.setMaxHitPoints( blueprint.getMaxHealth(stone.getRank())); - stone.setCurrentHitPoints(stone.getMaxHitPoints()); - BuildingManager.setUpgradeDateTime(stone, null, 0); + if (bane == null) { + + //delete bane stone, failed to make bane object + DbManager.BuildingQueries.DELETE_FROM_DATABASE(stone); - //Make the bane + throwbackError(pc, "Failed to create bane."); + return; + } + + WorldGrid.addObject(stone, pc); - Bane bane = Bane.makeBane(player, city, stone); + //Add baned effect to TOL + city.getTOL().addEffectBit((1 << 16)); + city.getTOL().updateEffects(); - if (bane == null) { - - //delete bane stone, failed to make bane object - DbManager.BuildingQueries.DELETE_FROM_DATABASE(stone); + Vector3fImmutable movePlayerOutsideStone = player.getLoc(); + movePlayerOutsideStone = movePlayerOutsideStone.setX(movePlayerOutsideStone.x + 10); + movePlayerOutsideStone = movePlayerOutsideStone.setZ(movePlayerOutsideStone.z + 10); + player.teleport(movePlayerOutsideStone); - throwbackError(pc, "Failed to create bane."); - return; - } - - WorldGrid.addObject(stone, pc); - - //Add baned effect to TOL - city.getTOL().addEffectBit((1 << 16)); - city.getTOL().updateEffects(); - - Vector3fImmutable movePlayerOutsideStone = player.getLoc(); - movePlayerOutsideStone = movePlayerOutsideStone.setX(movePlayerOutsideStone.x + 10); - movePlayerOutsideStone = movePlayerOutsideStone.setZ(movePlayerOutsideStone.z + 10); - player.teleport(movePlayerOutsideStone); - - throwbackInfo(pc, "The city has been succesfully baned."); - } + throwbackInfo(pc, "The city has been succesfully baned."); + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Creates an bane."; - } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "'./makebane playerUUID baneRank'"; - } + } } diff --git a/src/engine/devcmd/cmds/MakeItemCmd.java b/src/engine/devcmd/cmds/MakeItemCmd.java index 3bdd2384..835cdb27 100644 --- a/src/engine/devcmd/cmds/MakeItemCmd.java +++ b/src/engine/devcmd/cmds/MakeItemCmd.java @@ -21,236 +21,234 @@ import java.util.ArrayList; /** * @author Eighty - * */ public class MakeItemCmd extends AbstractDevCmd { - public MakeItemCmd() { + public MakeItemCmd() { super("makeitem"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - - if (words[0].equals("resources")){ - for (int ibID : Warehouse.getMaxResources().keySet()){ - if (ibID == 7) - continue; - - ItemBase ib = ItemBase.getItemBase(ibID); - - short weight = ib.getWeight(); - if (!pc.getCharItemManager().hasRoomInventory(weight)) { - throwbackError(pc, "Not enough room in inventory for any more of this item"); - - pc.getCharItemManager().updateInventory(); - return; - } - - boolean worked = false; - Item item = new Item(ib, pc.getObjectUUID(), - OwnerType.PlayerCharacter, (byte)0, (byte)0, (short)ib.getDurability(), (short)ib.getDurability(), - true, false, ItemContainerType.INVENTORY, (byte) 0, - new ArrayList<>(),""); - - item.setNumOfItems(Warehouse.getMaxResources().get(ibID)); - - try { - item = DbManager.ItemQueries.ADD_ITEM(item); - worked = true; - } catch (Exception e) { - throwbackError(pc, "DB error 1: Unable to create item. " + e.getMessage()); - return; - } - - if (item == null || !worked) { - throwbackError(pc, "DB error 2: Unable to create item."); - return; - } - - - - //add item to inventory - pc.getCharItemManager().addItemToInventory(item); - } - return; - } - if (words.length < 3 || words.length > 5) { - this.sendUsage(pc); - return; - } - - int quantity = 1; - if (words.length > 3) { - try { - quantity = Integer.parseInt(words[3]); - } catch (NumberFormatException e) { - throwbackError(pc, "Quantity must be a number, " + words[3] + " is invalid"); - return; - } - if (quantity < 1 || quantity > 100) - quantity = 1; - } - - int numItems = 1; - if (words.length > 4) { - try { - numItems = Integer.parseInt(words[4]); - } catch (NumberFormatException e) { - throwbackError(pc, "numResources must be a number, " + words[4] + " is invalid"); - return; - } - numItems = (numItems < 1) ? 1 : numItems; - numItems = (numItems > 5000) ? 5000 : numItems; - } - - int itembaseID; - try { - itembaseID = Integer.parseInt(words[0]); - } catch (NumberFormatException e) { - itembaseID = ItemBase.getIDByName(words[0].toLowerCase()); - if (itembaseID == 0) { - throwbackError(pc, "Supplied type " + words[0] - + " failed to parse to an Integer"); - return; - } - } catch (Exception e) { - throwbackError(pc, - "An unknown exception occurred when trying to use createitem command for type " - + words[0]); - return; // NaN - } - - if (itembaseID == 7) { - this.throwbackInfo(pc, "use /addgold to add gold."); - return; - } - - String prefix = ""; - String suffix = ""; - - if (!(words[1].equals("0"))) { - prefix = words[1]; - if (!(prefix.substring(0, 4).equals("PRE-"))) - prefix = EffectsBase.getItemEffectsByName(prefix.toLowerCase()); - if (!(prefix.substring(0, 4).equals("PRE-"))) { - throwbackError(pc, "Invalid Prefix. Prefix must consist of PRE-001 to PRE-334 or 0 for no Prefix."); - return; - } - - boolean validInt = false; - try { - int num = Integer.parseInt(prefix.substring(4, 7)); - if (num > 0 && num < 335) - validInt = true; - } catch (Exception e) { - throwbackError(pc, "error parsing number " + prefix); - } - if (!validInt) { - throwbackError(pc, "Invalid Prefix. Prefix must consist of PRE-001 to PRE-334 or 0 for no Prefix."); - return; - } - } - - if (!(words[2].equals("0"))) { - suffix = words[2]; - - if (!(suffix.substring(0, 4).equals("SUF-"))) - suffix = EffectsBase.getItemEffectsByName(suffix.toLowerCase()); - if (!(suffix.substring(0, 4).equals("SUF-"))) { - throwbackError(pc, "Invalid Suffix. Suffix must consist of SUF-001 to SUF-328 or 0 for no Suffix."); - return; - } - - boolean validInt = false; - try { - int num = Integer.parseInt(suffix.substring(4, 7)); - if (num > 0 && num < 329) - validInt = true; - } catch (Exception e) { - throwbackError(pc, "error parsing number " + suffix); - } - if (!validInt) { - throwbackError(pc, "Invalid Suffix. Suffix must consist of SUF-001 to SUF-328 or 0 for no Suffix."); - return; - } - } - ItemBase ib = ItemBase.getItemBase(itembaseID); - if (ib == null) { - throwbackError(pc, "Unable to find itembase of ID " + itembaseID); - return; - } - - if ((numItems > 1) - && (ib.getType().equals(ItemType.RESOURCE) == false) - && (ib.getType().equals(ItemType.OFFERING)) == false) - numItems = 1; - - CharacterItemManager cim = pc.getCharItemManager(); - if (cim == null) { - throwbackError(pc, "Unable to find the character item manager for player " + pc.getFirstName() + '.'); - return; - } - - byte charges = (byte) ib.getNumCharges(); - short dur = (short) ib.getDurability(); - - String result = ""; - for (int i = 0; i < quantity; i++) { - short weight = ib.getWeight(); - if (!cim.hasRoomInventory(weight)) { - throwbackError(pc, "Not enough room in inventory for any more of this item. " + i + " produced."); - if (i > 0) - cim.updateInventory(); - return; - } - - boolean worked = false; - Item item = new Item(ib, pc.getObjectUUID(), - OwnerType.PlayerCharacter, charges, charges, dur, dur, - true, false, ItemContainerType.INVENTORY, (byte) 0, - new ArrayList<>(),""); - if (numItems > 1) - item.setNumOfItems(numItems); - - try { - item = DbManager.ItemQueries.ADD_ITEM(item); - worked = true; - } catch (Exception e) { - throwbackError(pc, "DB error 1: Unable to create item. " + e.getMessage()); - return; - } - - if (item == null || !worked) { - throwbackError(pc, "DB error 2: Unable to create item."); - return; - } - - //create prefix - if (!prefix.isEmpty()) - item.addPermanentEnchantmentForDev(prefix, 0); - - //create suffix - if (!suffix.isEmpty()) - item.addPermanentEnchantmentForDev(suffix, 0); - - //add item to inventory - cim.addItemToInventory(item); - result += " " + item.getObjectUUID(); - } - this.setResult(result); - cim.updateInventory(); - } - - @Override - protected String _getHelpString() { + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + + if (words[0].equals("resources")) { + for (int ibID : Warehouse.getMaxResources().keySet()) { + if (ibID == 7) + continue; + + ItemBase ib = ItemBase.getItemBase(ibID); + + short weight = ib.getWeight(); + if (!pc.getCharItemManager().hasRoomInventory(weight)) { + throwbackError(pc, "Not enough room in inventory for any more of this item"); + + pc.getCharItemManager().updateInventory(); + return; + } + + boolean worked = false; + Item item = new Item(ib, pc.getObjectUUID(), + OwnerType.PlayerCharacter, (byte) 0, (byte) 0, (short) ib.getDurability(), (short) ib.getDurability(), + true, false, ItemContainerType.INVENTORY, (byte) 0, + new ArrayList<>(), ""); + + item.setNumOfItems(Warehouse.getMaxResources().get(ibID)); + + try { + item = DbManager.ItemQueries.ADD_ITEM(item); + worked = true; + } catch (Exception e) { + throwbackError(pc, "DB error 1: Unable to create item. " + e.getMessage()); + return; + } + + if (item == null || !worked) { + throwbackError(pc, "DB error 2: Unable to create item."); + return; + } + + + //add item to inventory + pc.getCharItemManager().addItemToInventory(item); + } + return; + } + if (words.length < 3 || words.length > 5) { + this.sendUsage(pc); + return; + } + + int quantity = 1; + if (words.length > 3) { + try { + quantity = Integer.parseInt(words[3]); + } catch (NumberFormatException e) { + throwbackError(pc, "Quantity must be a number, " + words[3] + " is invalid"); + return; + } + if (quantity < 1 || quantity > 100) + quantity = 1; + } + + int numItems = 1; + if (words.length > 4) { + try { + numItems = Integer.parseInt(words[4]); + } catch (NumberFormatException e) { + throwbackError(pc, "numResources must be a number, " + words[4] + " is invalid"); + return; + } + numItems = (numItems < 1) ? 1 : numItems; + numItems = (numItems > 5000) ? 5000 : numItems; + } + + int itembaseID; + try { + itembaseID = Integer.parseInt(words[0]); + } catch (NumberFormatException e) { + itembaseID = ItemBase.getIDByName(words[0].toLowerCase()); + if (itembaseID == 0) { + throwbackError(pc, "Supplied type " + words[0] + + " failed to parse to an Integer"); + return; + } + } catch (Exception e) { + throwbackError(pc, + "An unknown exception occurred when trying to use createitem command for type " + + words[0]); + return; // NaN + } + + if (itembaseID == 7) { + this.throwbackInfo(pc, "use /addgold to add gold."); + return; + } + + String prefix = ""; + String suffix = ""; + + if (!(words[1].equals("0"))) { + prefix = words[1]; + if (!(prefix.substring(0, 4).equals("PRE-"))) + prefix = EffectsBase.getItemEffectsByName(prefix.toLowerCase()); + if (!(prefix.substring(0, 4).equals("PRE-"))) { + throwbackError(pc, "Invalid Prefix. Prefix must consist of PRE-001 to PRE-334 or 0 for no Prefix."); + return; + } + + boolean validInt = false; + try { + int num = Integer.parseInt(prefix.substring(4, 7)); + if (num > 0 && num < 335) + validInt = true; + } catch (Exception e) { + throwbackError(pc, "error parsing number " + prefix); + } + if (!validInt) { + throwbackError(pc, "Invalid Prefix. Prefix must consist of PRE-001 to PRE-334 or 0 for no Prefix."); + return; + } + } + + if (!(words[2].equals("0"))) { + suffix = words[2]; + + if (!(suffix.substring(0, 4).equals("SUF-"))) + suffix = EffectsBase.getItemEffectsByName(suffix.toLowerCase()); + if (!(suffix.substring(0, 4).equals("SUF-"))) { + throwbackError(pc, "Invalid Suffix. Suffix must consist of SUF-001 to SUF-328 or 0 for no Suffix."); + return; + } + + boolean validInt = false; + try { + int num = Integer.parseInt(suffix.substring(4, 7)); + if (num > 0 && num < 329) + validInt = true; + } catch (Exception e) { + throwbackError(pc, "error parsing number " + suffix); + } + if (!validInt) { + throwbackError(pc, "Invalid Suffix. Suffix must consist of SUF-001 to SUF-328 or 0 for no Suffix."); + return; + } + } + ItemBase ib = ItemBase.getItemBase(itembaseID); + if (ib == null) { + throwbackError(pc, "Unable to find itembase of ID " + itembaseID); + return; + } + + if ((numItems > 1) + && (ib.getType().equals(ItemType.RESOURCE) == false) + && (ib.getType().equals(ItemType.OFFERING)) == false) + numItems = 1; + + CharacterItemManager cim = pc.getCharItemManager(); + if (cim == null) { + throwbackError(pc, "Unable to find the character item manager for player " + pc.getFirstName() + '.'); + return; + } + + byte charges = (byte) ib.getNumCharges(); + short dur = (short) ib.getDurability(); + + String result = ""; + for (int i = 0; i < quantity; i++) { + short weight = ib.getWeight(); + if (!cim.hasRoomInventory(weight)) { + throwbackError(pc, "Not enough room in inventory for any more of this item. " + i + " produced."); + if (i > 0) + cim.updateInventory(); + return; + } + + boolean worked = false; + Item item = new Item(ib, pc.getObjectUUID(), + OwnerType.PlayerCharacter, charges, charges, dur, dur, + true, false, ItemContainerType.INVENTORY, (byte) 0, + new ArrayList<>(), ""); + if (numItems > 1) + item.setNumOfItems(numItems); + + try { + item = DbManager.ItemQueries.ADD_ITEM(item); + worked = true; + } catch (Exception e) { + throwbackError(pc, "DB error 1: Unable to create item. " + e.getMessage()); + return; + } + + if (item == null || !worked) { + throwbackError(pc, "DB error 2: Unable to create item."); + return; + } + + //create prefix + if (!prefix.isEmpty()) + item.addPermanentEnchantmentForDev(prefix, 0); + + //create suffix + if (!suffix.isEmpty()) + item.addPermanentEnchantmentForDev(suffix, 0); + + //add item to inventory + cim.addItemToInventory(item); + result += " " + item.getObjectUUID(); + } + this.setResult(result); + cim.updateInventory(); + } + + @Override + protected String _getHelpString() { return "Creates an item of type 'itembaseID' with a prefix and suffix"; - } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "'./makeitem itembaseID PrefixID SuffixID [quantity] [numResources]'"; - } + } } diff --git a/src/engine/devcmd/cmds/NetDebugCmd.java b/src/engine/devcmd/cmds/NetDebugCmd.java index 065ff18d..202dc7b8 100644 --- a/src/engine/devcmd/cmds/NetDebugCmd.java +++ b/src/engine/devcmd/cmds/NetDebugCmd.java @@ -6,81 +6,79 @@ import engine.objects.PlayerCharacter; import engine.server.MBServerStatics; /** - * @author - * Summary: Devcmd to toggle logging of application protocol messages - * + * @author Summary: Devcmd to toggle logging of application protocol messages */ - + public class NetDebugCmd extends AbstractDevCmd { // Instance variables - - - public NetDebugCmd() { + + + public NetDebugCmd() { super("netdebug"); } - - // AbstractDevCmd Overridden methods - - @Override - protected void _doCmd(PlayerCharacter pc, String[] args, - AbstractGameObject target) { - - Boolean debugState = false; - - if(validateUserInput(args) == false) { - this.sendUsage(pc); - return; - } - - // Arguments have been validated use argument to set debug state - - switch (args[0]) { - case "on": - debugState = true; - break; - case "off": - debugState = false; - break; - default: - break; - } - - MBServerStatics.DEBUG_PROTOCOL = debugState; - - // Send results to user - throwbackInfo(pc, "Network debug state: " + debugState.toString()); - } - - @Override - protected String _getHelpString() { - return "Toggles sending network messages to log"; - } - @Override - protected String _getUsageString() { - return "/netdebug on|off"; - } + // AbstractDevCmd Overridden methods - // Class methods - - private static boolean validateUserInput(String[] userInput) { + private static boolean validateUserInput(String[] userInput) { int stringIndex; String commandSet = "onoff"; - + // incorrect number of arguments test - + if (userInput.length != 1) - return false; + return false; // Validate arguments - + stringIndex = commandSet.indexOf(userInput[0].toLowerCase()); - return stringIndex != -1; + return stringIndex != -1; + } + + @Override + protected void _doCmd(PlayerCharacter pc, String[] args, + AbstractGameObject target) { + + Boolean debugState = false; + + if (validateUserInput(args) == false) { + this.sendUsage(pc); + return; } - - + + // Arguments have been validated use argument to set debug state + + switch (args[0]) { + case "on": + debugState = true; + break; + case "off": + debugState = false; + break; + default: + break; + } + + MBServerStatics.DEBUG_PROTOCOL = debugState; + + // Send results to user + throwbackInfo(pc, "Network debug state: " + debugState.toString()); + } + + @Override + protected String _getHelpString() { + return "Toggles sending network messages to log"; + } + + // Class methods + + @Override + protected String _getUsageString() { + return "/netdebug on|off"; + } + + } diff --git a/src/engine/devcmd/cmds/PrintBankCmd.java b/src/engine/devcmd/cmds/PrintBankCmd.java index 981d4014..7074af52 100644 --- a/src/engine/devcmd/cmds/PrintBankCmd.java +++ b/src/engine/devcmd/cmds/PrintBankCmd.java @@ -16,58 +16,58 @@ import java.util.ArrayList; public class PrintBankCmd extends AbstractDevCmd { - public PrintBankCmd() { - super("printbank"); - } + public PrintBankCmd() { + super("printbank"); + } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { - AbstractWorldObject tar; - String name; - String type = "PlayerCharacter"; + AbstractWorldObject tar; + String name; + String type = "PlayerCharacter"; - if (target != null) { - if (target instanceof AbstractCharacter) { - tar = (AbstractCharacter) target; - name = ((AbstractCharacter) tar).getFirstName(); - } else { - tar = pc; - name = ((AbstractCharacter) tar).getFirstName(); - } - } else { - tar = pc; - name = ((AbstractCharacter) tar).getFirstName(); - } + if (target != null) { + if (target instanceof AbstractCharacter) { + tar = (AbstractCharacter) target; + name = ((AbstractCharacter) tar).getFirstName(); + } else { + tar = pc; + name = ((AbstractCharacter) tar).getFirstName(); + } + } else { + tar = pc; + name = ((AbstractCharacter) tar).getFirstName(); + } - if (!(tar instanceof PlayerCharacter)) { - throwbackError(pc, "Must target player"); - return; - } + if (!(tar instanceof PlayerCharacter)) { + throwbackError(pc, "Must target player"); + return; + } - CharacterItemManager cim = ((AbstractCharacter)tar).getCharItemManager(); - ArrayList list = cim.getBank(); - throwbackInfo(pc, "Bank for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')'); - for (Item item : list) { - throwbackInfo(pc, " " + item.getItemBase().getName() + ", count: " + item.getNumOfItems()); - } - Item gold = cim.getGoldBank(); - if (gold != null) - throwbackInfo(pc, " Gold, count: " + gold.getNumOfItems()); - else - throwbackInfo(pc, " NULL Gold"); - } + CharacterItemManager cim = ((AbstractCharacter) tar).getCharItemManager(); + ArrayList list = cim.getBank(); + throwbackInfo(pc, "Bank for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')'); + for (Item item : list) { + throwbackInfo(pc, " " + item.getItemBase().getName() + ", count: " + item.getNumOfItems()); + } + Item gold = cim.getGoldBank(); + if (gold != null) + throwbackInfo(pc, " Gold, count: " + gold.getNumOfItems()); + else + throwbackInfo(pc, " NULL Gold"); + } - @Override - protected String _getHelpString() { - return "Returns the player's current bank"; - } + @Override + protected String _getHelpString() { + return "Returns the player's current bank"; + } - @Override - protected String _getUsageString() { - return "' /printbank'"; - } + @Override + protected String _getUsageString() { + return "' /printbank'"; + } } diff --git a/src/engine/devcmd/cmds/PrintBonusesCmd.java b/src/engine/devcmd/cmds/PrintBonusesCmd.java index b425ec45..e642b712 100644 --- a/src/engine/devcmd/cmds/PrintBonusesCmd.java +++ b/src/engine/devcmd/cmds/PrintBonusesCmd.java @@ -17,75 +17,74 @@ import engine.powers.effectmodifiers.AbstractEffectModifier; public class PrintBonusesCmd extends AbstractDevCmd { - public PrintBonusesCmd() { - super("printbonuses"); - // super("printbonuses", MBServerStatics.ACCESS_LEVEL_ADMIN); - } + public PrintBonusesCmd() { + super("printbonuses"); + // super("printbonuses", MBServerStatics.ACCESS_LEVEL_ADMIN); + } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { - AbstractWorldObject tar; - String name; - String type = "PlayerCharacter"; - if (target != null) - if (target instanceof Item) { - type = "Item"; - tar = (Item) target; - name = ((Item) tar).getItemBase().getName(); - } else if (target instanceof AbstractCharacter) { - tar = (AbstractCharacter) target; - name = ((AbstractCharacter) tar).getFirstName(); - } else { - tar = pc; - name = ((AbstractCharacter) tar).getFirstName(); - } - else { - tar = pc; - name = ((AbstractCharacter) tar).getFirstName(); - } + AbstractWorldObject tar; + String name; + String type = "PlayerCharacter"; + if (target != null) + if (target instanceof Item) { + type = "Item"; + tar = (Item) target; + name = ((Item) tar).getItemBase().getName(); + } else if (target instanceof AbstractCharacter) { + tar = (AbstractCharacter) target; + name = ((AbstractCharacter) tar).getFirstName(); + } else { + tar = pc; + name = ((AbstractCharacter) tar).getFirstName(); + } + else { + tar = pc; + name = ((AbstractCharacter) tar).getFirstName(); + } - //Get name and type - if (tar instanceof Mob) { - Mob mob = (Mob) tar; - MobBase mb = mob.getMobBase(); - if (mb != null) - name = mb.getFirstName(); - type = "Mob"; - } else if (tar instanceof NPC) { - NPC npc = (NPC) tar; - Contract contract = npc.getContract(); - if (contract != null) - if (contract.isTrainer()) - name = tar.getName() + ", " + contract.getName(); - else - name = tar.getName() + " the " + contract.getName(); - type = "NPC"; - } + //Get name and type + if (tar instanceof Mob) { + Mob mob = (Mob) tar; + MobBase mb = mob.getMobBase(); + if (mb != null) + name = mb.getFirstName(); + type = "Mob"; + } else if (tar instanceof NPC) { + NPC npc = (NPC) tar; + Contract contract = npc.getContract(); + if (contract != null) + if (contract.isTrainer()) + name = tar.getName() + ", " + contract.getName(); + else + name = tar.getName() + " the " + contract.getName(); + type = "NPC"; + } - if (tar.getObjectType() == GameObjectType.Item) { - Item targetItem = (Item) tar; + if (tar.getObjectType() == GameObjectType.Item) { + Item targetItem = (Item) tar; - if (targetItem.getBonuses() != null) - for (AbstractEffectModifier targetName : targetItem.getBonuses().keySet()) { - ChatManager.chatSystemInfo(pc, " " + targetName.modType.name() + "-" + targetName.sourceType.name() + ": " + targetItem.getBonuses().get(name)); - } - } else if (((AbstractCharacter)tar).getBonuses() != null) { - ((AbstractCharacter)tar).getBonuses().printBonusesToClient(pc); - } - else - throwbackInfo(pc, "Bonuses for " + type + ' ' + name + " not found"); - } + if (targetItem.getBonuses() != null) + for (AbstractEffectModifier targetName : targetItem.getBonuses().keySet()) { + ChatManager.chatSystemInfo(pc, " " + targetName.modType.name() + "-" + targetName.sourceType.name() + ": " + targetItem.getBonuses().get(name)); + } + } else if (((AbstractCharacter) tar).getBonuses() != null) { + ((AbstractCharacter) tar).getBonuses().printBonusesToClient(pc); + } else + throwbackInfo(pc, "Bonuses for " + type + ' ' + name + " not found"); + } - @Override - protected String _getHelpString() { - return "Returns the player's current bonuses"; - } + @Override + protected String _getHelpString() { + return "Returns the player's current bonuses"; + } - @Override - protected String _getUsageString() { - return "' /printbonuses'"; - } + @Override + protected String _getUsageString() { + return "' /printbonuses'"; + } } diff --git a/src/engine/devcmd/cmds/PrintEquipCmd.java b/src/engine/devcmd/cmds/PrintEquipCmd.java index 284ff49e..2bf192fe 100644 --- a/src/engine/devcmd/cmds/PrintEquipCmd.java +++ b/src/engine/devcmd/cmds/PrintEquipCmd.java @@ -17,86 +17,86 @@ import java.util.concurrent.ConcurrentHashMap; public class PrintEquipCmd extends AbstractDevCmd { - public PrintEquipCmd() { - super("printequip"); - } + public PrintEquipCmd() { + super("printequip"); + } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { - AbstractWorldObject tar; - String name; - String type = "PlayerCharacter"; - if (target != null) { - if (target instanceof AbstractCharacter) { - tar = (AbstractCharacter) target; - name = ((AbstractCharacter) tar).getFirstName(); - } else { - tar = pc; - name = ((AbstractCharacter) tar).getFirstName(); - } - } else { - tar = pc; - name = ((AbstractCharacter) tar).getFirstName(); - } + AbstractWorldObject tar; + String name; + String type = "PlayerCharacter"; + if (target != null) { + if (target instanceof AbstractCharacter) { + tar = (AbstractCharacter) target; + name = ((AbstractCharacter) tar).getFirstName(); + } else { + tar = pc; + name = ((AbstractCharacter) tar).getFirstName(); + } + } else { + tar = pc; + name = ((AbstractCharacter) tar).getFirstName(); + } - //Get name and type - if (tar instanceof Mob) { - Mob mob = (Mob) tar; - MobBase mb = mob.getMobBase(); - if (mb != null) - name = mb.getFirstName(); - type = "Mob"; - } else if (tar instanceof NPC) { - NPC npc = (NPC) tar; - Contract contract = npc.getContract(); - if (contract != null) { - if (contract.isTrainer()) - name = tar.getName() + ", " + contract.getName(); - else - name = tar.getName() + " the " + contract.getName(); - } - type = "NPC"; - } + //Get name and type + if (tar instanceof Mob) { + Mob mob = (Mob) tar; + MobBase mb = mob.getMobBase(); + if (mb != null) + name = mb.getFirstName(); + type = "Mob"; + } else if (tar instanceof NPC) { + NPC npc = (NPC) tar; + Contract contract = npc.getContract(); + if (contract != null) { + if (contract.isTrainer()) + name = tar.getName() + ", " + contract.getName(); + else + name = tar.getName() + " the " + contract.getName(); + } + type = "NPC"; + } - if (tar.getObjectType() == GameObjectType.Mob){ - Mob tarMob = (Mob)tar; - throwbackInfo(pc, "Equip for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')'); - for (int slot:tarMob.getEquip().keySet()){ - MobEquipment equip = tarMob.getEquip().get(slot); - throwbackInfo(pc, equip.getItemBase().getUUID() + " : " + equip.getItemBase().getName() + ", slot: " + slot); - } - return; - } + if (tar.getObjectType() == GameObjectType.Mob) { + Mob tarMob = (Mob) tar; + throwbackInfo(pc, "Equip for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')'); + for (int slot : tarMob.getEquip().keySet()) { + MobEquipment equip = tarMob.getEquip().get(slot); + throwbackInfo(pc, equip.getItemBase().getUUID() + " : " + equip.getItemBase().getName() + ", slot: " + slot); + } + return; + } - if (tar.getObjectType() == GameObjectType.NPC){ - NPC tarMob = (NPC)tar; - throwbackInfo(pc, "Equip for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')'); - for (int slot:tarMob.getEquip().keySet()){ - MobEquipment equip = tarMob.getEquip().get(slot); - throwbackInfo(pc,equip.getItemBase().getUUID() + " : " + equip.getItemBase().getName() + ", slot: " + slot); - } - return; - } + if (tar.getObjectType() == GameObjectType.NPC) { + NPC tarMob = (NPC) tar; + throwbackInfo(pc, "Equip for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')'); + for (int slot : tarMob.getEquip().keySet()) { + MobEquipment equip = tarMob.getEquip().get(slot); + throwbackInfo(pc, equip.getItemBase().getUUID() + " : " + equip.getItemBase().getName() + ", slot: " + slot); + } + return; + } - CharacterItemManager cim = ((AbstractCharacter)tar).getCharItemManager(); - ConcurrentHashMap list = cim.getEquipped(); - throwbackInfo(pc, "Equip for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')'); - for (Integer slot : list.keySet()) { - Item item = list.get(slot); - throwbackInfo(pc, " " + item.getItemBase().getName() + ", slot: " + slot); - } - } + CharacterItemManager cim = ((AbstractCharacter) tar).getCharItemManager(); + ConcurrentHashMap list = cim.getEquipped(); + throwbackInfo(pc, "Equip for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')'); + for (Integer slot : list.keySet()) { + Item item = list.get(slot); + throwbackInfo(pc, " " + item.getItemBase().getName() + ", slot: " + slot); + } + } - @Override - protected String _getHelpString() { - return "Returns the player's current equipment"; - } + @Override + protected String _getHelpString() { + return "Returns the player's current equipment"; + } - @Override - protected String _getUsageString() { - return "' /printequip'"; - } + @Override + protected String _getUsageString() { + return "' /printequip'"; + } } diff --git a/src/engine/devcmd/cmds/PrintInventoryCmd.java b/src/engine/devcmd/cmds/PrintInventoryCmd.java index c151b923..5535f22e 100644 --- a/src/engine/devcmd/cmds/PrintInventoryCmd.java +++ b/src/engine/devcmd/cmds/PrintInventoryCmd.java @@ -18,92 +18,93 @@ import java.util.ArrayList; public class PrintInventoryCmd extends AbstractDevCmd { - public PrintInventoryCmd() { - super("printinventory"); - } - - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - - if (target == null || (!(target instanceof AbstractCharacter) && !(target instanceof Corpse))) { - target = pc; - } - - - String type = target.getClass().getSimpleName(); - String name = ""; - ArrayList inventory = null; - Item gold = null; - DecimalFormat df = new DecimalFormat("###,###,###,##0"); - - if (target instanceof AbstractCharacter) { - AbstractCharacter tar = (AbstractCharacter)target; - - name = tar.getFirstName(); - - if (tar instanceof Mob) { - Mob mob = (Mob) tar; - MobBase mb = mob.getMobBase(); - if (mb != null) { - name = mb.getFirstName(); - } - } else if (tar instanceof NPC) { - NPC npc = (NPC) tar; - Contract contract = npc.getContract(); - if (contract != null) { - if (contract.isTrainer()) { - name = tar.getName() + ", " + contract.getName(); - } else { - name = tar.getName() + " the " + contract.getName(); - } - } - } - - CharacterItemManager cim = tar.getCharItemManager(); - inventory = cim.getInventory(); //this list can contain gold when tar is a PC that is dead - gold = cim.getGoldInventory(); - throwbackInfo(pc, " Weight : " + (cim.getInventoryWeight() + cim.getEquipWeight())); - } else if (target instanceof Corpse) { - Corpse corpse = (Corpse) target; - name = "of " + corpse.getName(); - inventory = corpse.getInventory(); - } - - throwbackInfo(pc, "Inventory for " + type + ' ' + name + " (" + target.getObjectUUID() + ')'); - - int goldCount = 0; - - for (Item item : inventory) { - if (item.getItemBase().getType().equals(ItemType.GOLD) == false) { - String chargeInfo = ""; - byte chargeMax = item.getChargesMax(); - if (chargeMax > 0) { - byte charges = item.getChargesRemaining(); - chargeInfo = " charges: " + charges + '/' + chargeMax; - } - throwbackInfo(pc, " " + item.getItemBase().getName() + ", count: " + item.getNumOfItems() + chargeInfo); - } else goldCount += item.getNumOfItems(); - } - if (gold != null) { - goldCount += gold.getNumOfItems(); - } - - if (goldCount > 0 || gold != null) { - throwbackInfo(pc, " Gold, count: " + df.format(goldCount)); - } else { - throwbackInfo(pc, " NULL Gold"); - } - } - - @Override - protected String _getHelpString() { - return "Returns the player's current inventory"; - } - - @Override - protected String _getUsageString() { - return "' /printinventory'"; - } + public PrintInventoryCmd() { + super("printinventory"); + } + + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + + if (target == null || (!(target instanceof AbstractCharacter) && !(target instanceof Corpse))) { + target = pc; + } + + + String type = target.getClass().getSimpleName(); + String name = ""; + ArrayList inventory = null; + Item gold = null; + DecimalFormat df = new DecimalFormat("###,###,###,##0"); + + if (target instanceof AbstractCharacter) { + AbstractCharacter tar = (AbstractCharacter) target; + + name = tar.getFirstName(); + + if (tar instanceof Mob) { + Mob mob = (Mob) tar; + MobBase mb = mob.getMobBase(); + if (mb != null) { + name = mb.getFirstName(); + } + } else if (tar instanceof NPC) { + NPC npc = (NPC) tar; + Contract contract = npc.getContract(); + if (contract != null) { + if (contract.isTrainer()) { + name = tar.getName() + ", " + contract.getName(); + } else { + name = tar.getName() + " the " + contract.getName(); + } + } + } + + CharacterItemManager cim = tar.getCharItemManager(); + inventory = cim.getInventory(); //this list can contain gold when tar is a PC that is dead + gold = cim.getGoldInventory(); + throwbackInfo(pc, " Weight : " + (cim.getInventoryWeight() + cim.getEquipWeight())); + } else if (target instanceof Corpse) { + Corpse corpse = (Corpse) target; + name = "of " + corpse.getName(); + inventory = corpse.getInventory(); + } + + throwbackInfo(pc, "Inventory for " + type + ' ' + name + " (" + target.getObjectUUID() + ')'); + + int goldCount = 0; + + for (Item item : inventory) { + if (item.getItemBase().getType().equals(ItemType.GOLD) == false) { + String chargeInfo = ""; + byte chargeMax = item.getChargesMax(); + if (chargeMax > 0) { + byte charges = item.getChargesRemaining(); + chargeInfo = " charges: " + charges + '/' + chargeMax; + } + throwbackInfo(pc, " " + item.getItemBase().getName() + ", count: " + item.getNumOfItems() + chargeInfo); + } else + goldCount += item.getNumOfItems(); + } + if (gold != null) { + goldCount += gold.getNumOfItems(); + } + + if (goldCount > 0 || gold != null) { + throwbackInfo(pc, " Gold, count: " + df.format(goldCount)); + } else { + throwbackInfo(pc, " NULL Gold"); + } + } + + @Override + protected String _getHelpString() { + return "Returns the player's current inventory"; + } + + @Override + protected String _getUsageString() { + return "' /printinventory'"; + } } diff --git a/src/engine/devcmd/cmds/PrintLocationCmd.java b/src/engine/devcmd/cmds/PrintLocationCmd.java index e8ce418d..053ea33e 100644 --- a/src/engine/devcmd/cmds/PrintLocationCmd.java +++ b/src/engine/devcmd/cmds/PrintLocationCmd.java @@ -16,52 +16,51 @@ import engine.objects.Regions; /** * @author Eighty - * */ public class PrintLocationCmd extends AbstractDevCmd { - public PrintLocationCmd() { - super("printloc"); - } + public PrintLocationCmd() { + super("printloc"); + } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { - PlayerCharacter tar; + PlayerCharacter tar; - if (target != null && target instanceof PlayerCharacter) - tar = (PlayerCharacter) target; - else - tar = pc; + if (target != null && target instanceof PlayerCharacter) + tar = (PlayerCharacter) target; + else + tar = pc; - throwbackInfo(pc, "Server location for " + tar.getFirstName()); - if (tar.getLoc() != null) { - throwbackInfo(pc, "Lat: " + tar.getLoc().getX()); - throwbackInfo(pc, "Lon: " + -tar.getLoc().getZ()); - throwbackInfo(pc, "Alt: " + tar.getLoc().getY()); - if (pc.region != null) { - this.throwbackInfo(pc, "Player Region Slope Position : " + Regions.SlopeLerpPercent(pc, pc.region)); - this.throwbackInfo(pc, "Region Slope Magnitude : " + Regions.GetMagnitudeOfRegionSlope(pc.region)); - this.throwbackInfo(pc, "Player Region Slope Magnitude : " + Regions.GetMagnitudeOfPlayerOnRegionSlope(pc.region, pc)); - } else { - this.throwbackInfo(pc, "No Region Found for player."); - } + throwbackInfo(pc, "Server location for " + tar.getFirstName()); + if (tar.getLoc() != null) { + throwbackInfo(pc, "Lat: " + tar.getLoc().getX()); + throwbackInfo(pc, "Lon: " + -tar.getLoc().getZ()); + throwbackInfo(pc, "Alt: " + tar.getLoc().getY()); + if (pc.region != null) { + this.throwbackInfo(pc, "Player Region Slope Position : " + Regions.SlopeLerpPercent(pc, pc.region)); + this.throwbackInfo(pc, "Region Slope Magnitude : " + Regions.GetMagnitudeOfRegionSlope(pc.region)); + this.throwbackInfo(pc, "Player Region Slope Magnitude : " + Regions.GetMagnitudeOfPlayerOnRegionSlope(pc.region, pc)); + } else { + this.throwbackInfo(pc, "No Region Found for player."); + } - } else { - throwbackInfo(pc, "Server location for " + tar.getFirstName() - + " not found"); - } - } + } else { + throwbackInfo(pc, "Server location for " + tar.getFirstName() + + " not found"); + } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Returns the player's current location according to the server"; - } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /printloc'"; - } + } } diff --git a/src/engine/devcmd/cmds/PrintPowersCmd.java b/src/engine/devcmd/cmds/PrintPowersCmd.java index 8c9fa980..0264439e 100644 --- a/src/engine/devcmd/cmds/PrintPowersCmd.java +++ b/src/engine/devcmd/cmds/PrintPowersCmd.java @@ -19,50 +19,50 @@ import java.util.concurrent.ConcurrentHashMap; public class PrintPowersCmd extends AbstractDevCmd { - public PrintPowersCmd() { - super("printpowers"); - // super("printpowers", MBServerStatics.ACCESS_LEVEL_ADMIN); - } + public PrintPowersCmd() { + super("printpowers"); + // super("printpowers", MBServerStatics.ACCESS_LEVEL_ADMIN); + } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { - PlayerCharacter tar; + PlayerCharacter tar; - if (target != null && target instanceof PlayerCharacter) - tar = (PlayerCharacter) target; - else - tar = pc; + if (target != null && target instanceof PlayerCharacter) + tar = (PlayerCharacter) target; + else + tar = pc; - throwbackInfo(pc, "Server powers for " + tar.getFirstName()); + throwbackInfo(pc, "Server powers for " + tar.getFirstName()); - ConcurrentHashMap powers = tar.getPowers(); - if (powers != null) { - throwbackInfo(pc, - "Power(token): Trains; TrainsGranted; MaxTrains"); - for (CharacterPower power : powers.values()) { - PowersBase pb = power.getPower(); - if (pb != null) { - throwbackInfo(pc, " " + pb.getName() + '(' - + pb.getToken() + "): " - + power.getTrains() + "; " - + power.getGrantedTrains() + "; " - + pb.getMaxTrains()); - } - } - } else - throwbackInfo(pc, "Powers not found for player"); - } + ConcurrentHashMap powers = tar.getPowers(); + if (powers != null) { + throwbackInfo(pc, + "Power(token): Trains; TrainsGranted; MaxTrains"); + for (CharacterPower power : powers.values()) { + PowersBase pb = power.getPower(); + if (pb != null) { + throwbackInfo(pc, " " + pb.getName() + '(' + + pb.getToken() + "): " + + power.getTrains() + "; " + + power.getGrantedTrains() + "; " + + pb.getMaxTrains()); + } + } + } else + throwbackInfo(pc, "Powers not found for player"); + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Returns the player's current granted powers"; - } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /printpowers'"; - } + } } diff --git a/src/engine/devcmd/cmds/PrintResistsCmd.java b/src/engine/devcmd/cmds/PrintResistsCmd.java index 49a9e0e1..2bcfbf46 100644 --- a/src/engine/devcmd/cmds/PrintResistsCmd.java +++ b/src/engine/devcmd/cmds/PrintResistsCmd.java @@ -14,58 +14,58 @@ import engine.objects.*; public class PrintResistsCmd extends AbstractDevCmd { - public PrintResistsCmd() { - super("printresists"); - // super("printresists", MBServerStatics.ACCESS_LEVEL_ADMIN); - } + public PrintResistsCmd() { + super("printresists"); + // super("printresists", MBServerStatics.ACCESS_LEVEL_ADMIN); + } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { - AbstractCharacter tar; + AbstractCharacter tar; - if (target != null && target instanceof AbstractCharacter) { - tar = (AbstractCharacter) target; - } else - tar = pc; + if (target != null && target instanceof AbstractCharacter) { + tar = (AbstractCharacter) target; + } else + tar = pc; - //Get name and type - String type = "PlayerCharacter"; - String name = tar.getFirstName(); - if (tar instanceof Mob) { - Mob mob = (Mob) tar; - MobBase mb = mob.getMobBase(); - if (mb != null) - name = mb.getFirstName(); - type = "Mob"; - } else if (tar instanceof NPC) { - NPC npc = (NPC) tar; - Contract contract = npc.getContract(); - if (contract != null) { - if (contract.isTrainer()) - name = tar.getName() + ", " + contract.getName(); - else - name = tar.getName() + " the " + contract.getName(); - } - type = "NPC"; - } + //Get name and type + String type = "PlayerCharacter"; + String name = tar.getFirstName(); + if (tar instanceof Mob) { + Mob mob = (Mob) tar; + MobBase mb = mob.getMobBase(); + if (mb != null) + name = mb.getFirstName(); + type = "Mob"; + } else if (tar instanceof NPC) { + NPC npc = (NPC) tar; + Contract contract = npc.getContract(); + if (contract != null) { + if (contract.isTrainer()) + name = tar.getName() + ", " + contract.getName(); + else + name = tar.getName() + " the " + contract.getName(); + } + type = "NPC"; + } - throwbackInfo(pc, "Server resists for " + type + ' ' + name); - if (tar.getResists() != null) { - tar.getResists().printResistsToClient(pc); - } else - throwbackInfo(pc, "Resists for " + type + ' ' + name + " not found"); - } + throwbackInfo(pc, "Server resists for " + type + ' ' + name); + if (tar.getResists() != null) { + tar.getResists().printResistsToClient(pc); + } else + throwbackInfo(pc, "Resists for " + type + ' ' + name + " not found"); + } - @Override - protected String _getHelpString() { - return "Returns the player's current resists"; - } + @Override + protected String _getHelpString() { + return "Returns the player's current resists"; + } - @Override - protected String _getUsageString() { - return "' /printresists'"; - } + @Override + protected String _getUsageString() { + return "' /printresists'"; + } } diff --git a/src/engine/devcmd/cmds/PrintSkillsCmd.java b/src/engine/devcmd/cmds/PrintSkillsCmd.java index 6ab5068a..51fbe1bc 100644 --- a/src/engine/devcmd/cmds/PrintSkillsCmd.java +++ b/src/engine/devcmd/cmds/PrintSkillsCmd.java @@ -17,50 +17,50 @@ import java.util.concurrent.ConcurrentHashMap; public class PrintSkillsCmd extends AbstractDevCmd { - public PrintSkillsCmd() { - super("printskills"); - // super("printskills", MBServerStatics.ACCESS_LEVEL_ADMIN); - } + public PrintSkillsCmd() { + super("printskills"); + // super("printskills", MBServerStatics.ACCESS_LEVEL_ADMIN); + } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { - AbstractCharacter tar = null; + AbstractCharacter tar = null; - if (target != null && target instanceof PlayerCharacter) - tar = (PlayerCharacter) target; - else if (target.getObjectType() == GameObjectType.Mob) - tar = (Mob) target; - else - tar = pc; + if (target != null && target instanceof PlayerCharacter) + tar = (PlayerCharacter) target; + else if (target.getObjectType() == GameObjectType.Mob) + tar = (Mob) target; + else + tar = pc; - throwbackInfo(pc, "Server skills for " + tar.getFirstName()); - ConcurrentHashMap skills = tar.getSkills(); - if (skills != null) { - throwbackInfo(pc, - "Skills Name: Trains; Base(Trains); ModBase(Trains)"); - for (CharacterSkill skill : skills.values()) { - throwbackInfo(pc, " " + skill.getName() + ": " - + skill.getNumTrains() + "; " - + skill.getBaseAmountBeforeMods() + " (" - + skill.getModifiedAmountBeforeMods() + "); " - + skill.getBaseAmount() + " (" - + skill.getModifiedAmount() + '(' - + skill.getTotalSkillPercet() + " )"); - } - } else - throwbackInfo(pc, "Skills not found for player"); - } + throwbackInfo(pc, "Server skills for " + tar.getFirstName()); + ConcurrentHashMap skills = tar.getSkills(); + if (skills != null) { + throwbackInfo(pc, + "Skills Name: Trains; Base(Trains); ModBase(Trains)"); + for (CharacterSkill skill : skills.values()) { + throwbackInfo(pc, " " + skill.getName() + ": " + + skill.getNumTrains() + "; " + + skill.getBaseAmountBeforeMods() + " (" + + skill.getModifiedAmountBeforeMods() + "); " + + skill.getBaseAmount() + " (" + + skill.getModifiedAmount() + '(' + + skill.getTotalSkillPercet() + " )"); + } + } else + throwbackInfo(pc, "Skills not found for player"); + } - @Override - protected String _getHelpString() { - return "Returns the player's current skills"; - } + @Override + protected String _getHelpString() { + return "Returns the player's current skills"; + } - @Override - protected String _getUsageString() { - return "' /printskills'"; - } + @Override + protected String _getUsageString() { + return "' /printskills'"; + } } diff --git a/src/engine/devcmd/cmds/PrintStatsCmd.java b/src/engine/devcmd/cmds/PrintStatsCmd.java index aee35228..1b6b30ca 100644 --- a/src/engine/devcmd/cmds/PrintStatsCmd.java +++ b/src/engine/devcmd/cmds/PrintStatsCmd.java @@ -20,135 +20,133 @@ import java.util.HashMap; public class PrintStatsCmd extends AbstractDevCmd { - public PrintStatsCmd() { - super("printstats"); - // super("printstats", MBServerStatics.ACCESS_LEVEL_ADMIN); - } - - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - - AbstractCharacter tar; - - if (target != null && target instanceof AbstractCharacter) { - tar = (AbstractCharacter) target; - - if (tar instanceof PlayerCharacter) { - printStatsPlayer(pc, (PlayerCharacter) tar); - this.setTarget(tar); //for logging - } else if (tar instanceof Mob) - printStatsMob(pc, (Mob) tar); - else if (tar instanceof NPC) - printStatsNPC(pc, (NPC) tar); - } - } - - public void printStatsPlayer(PlayerCharacter pc, PlayerCharacter tar) { - String newline = "\r\n "; - String out = "Server stats for Player " + tar.getFirstName() + newline; - out += "Unused Stats: " + tar.getUnusedStatPoints() + newline; - out += "Stats Base (Modified)" + newline; + public PrintStatsCmd() { + super("printstats"); + // super("printstats", MBServerStatics.ACCESS_LEVEL_ADMIN); + } + + public static ItemBase getWeaponBase(int slot, HashMap equip) { + if (equip.containsKey(slot)) { + MobEquipment item = equip.get(slot); + if (item != null && item.getItemBase() != null) { + return item.getItemBase(); + } + } + return null; + } + + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + + AbstractCharacter tar; + + if (target != null && target instanceof AbstractCharacter) { + tar = (AbstractCharacter) target; + + if (tar instanceof PlayerCharacter) { + printStatsPlayer(pc, (PlayerCharacter) tar); + this.setTarget(tar); //for logging + } else if (tar instanceof Mob) + printStatsMob(pc, (Mob) tar); + else if (tar instanceof NPC) + printStatsNPC(pc, (NPC) tar); + } + } + + public void printStatsPlayer(PlayerCharacter pc, PlayerCharacter tar) { + String newline = "\r\n "; + String out = "Server stats for Player " + tar.getFirstName() + newline; + out += "Unused Stats: " + tar.getUnusedStatPoints() + newline; + out += "Stats Base (Modified)" + newline; out += " Str: " + (int) tar.statStrBase + " (" + tar.getStatStrCurrent() + ')' + ", maxStr: " + tar.getStrMax() + newline; - out += " Dex: " + (int) tar.statDexBase + " (" + tar.getStatDexCurrent() + ')' + ", maxDex: " + tar.getDexMax() + newline; - out += " Con: " + (int) tar.statConBase + " (" + tar.getStatConCurrent() + ')' + ", maxCon: " + tar.getConMax() + newline; - out += " Int: " + (int) tar.statIntBase + " (" + tar.getStatIntCurrent() + ')' + ", maxInt: " + tar.getIntMax() + newline; - out += " Spi: " + (int) tar.statSpiBase + " (" + tar.getStatSpiCurrent() + ')' + ", maxSpi: " + tar.getSpiMax() + newline; - throwbackInfo(pc, out); - out = "Health: " + tar.getHealth() + ", maxHealth: " + tar.getHealthMax() + newline; - out += "Mana: " + tar.getMana() + ", maxMana: " + tar.getManaMax() + newline; - out += "Stamina: " + tar.getStamina() + ", maxStamina: " + tar.getStaminaMax() + newline; - out += "Defense: " + tar.getDefenseRating() + newline; - out += "Main Hand: atr: " + tar.getAtrHandOne() + ", damage: " + tar.getMinDamageHandOne() + " to " + tar.getMaxDamageHandOne() + ", speed: " + tar.getSpeedHandOne() + newline; - out += "Off Hand: atr: " + tar.getAtrHandTwo() + ", damage: " + tar.getMinDamageHandTwo() + " to " + tar.getMaxDamageHandTwo() + ", speed: " + tar.getSpeedHandTwo() + newline; - out += "isAlive: " + tar.isAlive() + ", Combat: " + tar.isCombat() + newline; - throwbackInfo(pc, out); - } - - public void printStatsMob(PlayerCharacter pc, Mob tar) { - MobBase mb = tar.getMobBase(); - if (mb == null) - return; - - - - String newline = "\r\n "; - String out = "Server stats for Mob " + mb.getFirstName() + newline; - out += "Stats Base (Modified)" + newline; - out += " Str: " + tar.getStatStrCurrent() + " (" + tar.getStatStrCurrent() + ')' + newline; - out += " Dex: " + tar.getStatDexCurrent() + " (" + tar.getStatDexCurrent() + ')' + ", maxDex: " + tar.getStatDexCurrent() + newline; - out += " Con: " + tar.getStatConCurrent() + " (" + tar.getStatConCurrent() + ')' + ", maxCon: " + tar.getStatConCurrent() + newline; - out += " Int: " + tar.getStatIntCurrent() + " (" + tar.getStatIntCurrent() + ')' + ", maxInt: " + tar.getStatIntCurrent() + newline; - out += " Spi: " + tar.getStatSpiCurrent() + " (" + tar.getStatSpiCurrent() + ')' + ", maxSpi: " + tar.getStatSpiCurrent() + newline; - - out += "Health: " + tar.getHealth() + ", maxHealth: " + tar.getHealthMax() + newline; - out += "Mana: " + tar.getMana() + ", maxMana: " + tar.getManaMax() + newline; - out += "Stamina: " + tar.getStamina() + ", maxStamina: " + tar.getStaminaMax() + newline; - out += "Defense: " + tar.getDefenseRating() + newline; - - //get weapons - HashMap equip = tar.getEquip(); - ItemBase main = null; - - if (equip != null) - main = getWeaponBase(1, equip); - ItemBase off = null; - - if (equip != null) - getWeaponBase(2, equip); - if (main == null && off == null) { - out += "Main Hand: atr: " + tar.getAtrHandOne() + ", damage: " + tar.getMinDamageHandOne() + " to " + tar.getMaxDamageHandOne() + ", speed: " + tar.getSpeedHandOne() + ", range: 6" + newline; - } else { - if (main != null) - out += "Main Hand: atr: " + tar.getAtrHandOne() + ", damage: " + tar.getMinDamageHandOne() + " to " + tar.getMaxDamageHandOne() + ", speed: " + tar.getSpeedHandOne() + ", range: " + main.getRange() + newline; - if (off != null) - out += "Main Hand: atr: " + tar.getAtrHandTwo() + ", damage: " + tar.getMinDamageHandTwo() + " to " + tar.getMaxDamageHandTwo() + ", speed: " + tar.getSpeedHandTwo() + ", range: " + off.getRange() + newline; - } - out += "isAlive: " + tar.isAlive() + ", Combat: " + tar.isCombat() + newline; - - throwbackInfo(pc, out); - } - - public void printStatsNPC(PlayerCharacter pc, NPC tar) { - Contract contract = tar.getContract(); - if (contract == null) - return; - - String newline = "\r\n "; - - String name; - if (contract != null) { - if (contract.isTrainer()) - name = tar.getName() + ", " + contract.getName(); - else - name = tar.getName() + " the " + contract.getName(); - } else - name = tar.getName(); - String out = "Server stats for NPC " + name + newline; - out += "Sell Percent: " + tar.getSellPercent() + ", Buy Percent: " + tar.getBuyPercent() + newline; - - throwbackInfo(pc, out); - } - - public static ItemBase getWeaponBase(int slot, HashMap equip) { - if (equip.containsKey(slot)) { - MobEquipment item = equip.get(slot); - if (item != null && item.getItemBase() != null) { - return item.getItemBase(); - } - } - return null; - } - - - @Override - protected String _getHelpString() { - return "Returns the player's current stats"; - } - - @Override - protected String _getUsageString() { - return "' /printstats'"; - } + out += " Dex: " + (int) tar.statDexBase + " (" + tar.getStatDexCurrent() + ')' + ", maxDex: " + tar.getDexMax() + newline; + out += " Con: " + (int) tar.statConBase + " (" + tar.getStatConCurrent() + ')' + ", maxCon: " + tar.getConMax() + newline; + out += " Int: " + (int) tar.statIntBase + " (" + tar.getStatIntCurrent() + ')' + ", maxInt: " + tar.getIntMax() + newline; + out += " Spi: " + (int) tar.statSpiBase + " (" + tar.getStatSpiCurrent() + ')' + ", maxSpi: " + tar.getSpiMax() + newline; + throwbackInfo(pc, out); + out = "Health: " + tar.getHealth() + ", maxHealth: " + tar.getHealthMax() + newline; + out += "Mana: " + tar.getMana() + ", maxMana: " + tar.getManaMax() + newline; + out += "Stamina: " + tar.getStamina() + ", maxStamina: " + tar.getStaminaMax() + newline; + out += "Defense: " + tar.getDefenseRating() + newline; + out += "Main Hand: atr: " + tar.getAtrHandOne() + ", damage: " + tar.getMinDamageHandOne() + " to " + tar.getMaxDamageHandOne() + ", speed: " + tar.getSpeedHandOne() + newline; + out += "Off Hand: atr: " + tar.getAtrHandTwo() + ", damage: " + tar.getMinDamageHandTwo() + " to " + tar.getMaxDamageHandTwo() + ", speed: " + tar.getSpeedHandTwo() + newline; + out += "isAlive: " + tar.isAlive() + ", Combat: " + tar.isCombat() + newline; + throwbackInfo(pc, out); + } + + public void printStatsMob(PlayerCharacter pc, Mob tar) { + MobBase mb = tar.getMobBase(); + if (mb == null) + return; + + + String newline = "\r\n "; + String out = "Server stats for Mob " + mb.getFirstName() + newline; + out += "Stats Base (Modified)" + newline; + out += " Str: " + tar.getStatStrCurrent() + " (" + tar.getStatStrCurrent() + ')' + newline; + out += " Dex: " + tar.getStatDexCurrent() + " (" + tar.getStatDexCurrent() + ')' + ", maxDex: " + tar.getStatDexCurrent() + newline; + out += " Con: " + tar.getStatConCurrent() + " (" + tar.getStatConCurrent() + ')' + ", maxCon: " + tar.getStatConCurrent() + newline; + out += " Int: " + tar.getStatIntCurrent() + " (" + tar.getStatIntCurrent() + ')' + ", maxInt: " + tar.getStatIntCurrent() + newline; + out += " Spi: " + tar.getStatSpiCurrent() + " (" + tar.getStatSpiCurrent() + ')' + ", maxSpi: " + tar.getStatSpiCurrent() + newline; + + out += "Health: " + tar.getHealth() + ", maxHealth: " + tar.getHealthMax() + newline; + out += "Mana: " + tar.getMana() + ", maxMana: " + tar.getManaMax() + newline; + out += "Stamina: " + tar.getStamina() + ", maxStamina: " + tar.getStaminaMax() + newline; + out += "Defense: " + tar.getDefenseRating() + newline; + + //get weapons + HashMap equip = tar.getEquip(); + ItemBase main = null; + + if (equip != null) + main = getWeaponBase(1, equip); + ItemBase off = null; + + if (equip != null) + getWeaponBase(2, equip); + if (main == null && off == null) { + out += "Main Hand: atr: " + tar.getAtrHandOne() + ", damage: " + tar.getMinDamageHandOne() + " to " + tar.getMaxDamageHandOne() + ", speed: " + tar.getSpeedHandOne() + ", range: 6" + newline; + } else { + if (main != null) + out += "Main Hand: atr: " + tar.getAtrHandOne() + ", damage: " + tar.getMinDamageHandOne() + " to " + tar.getMaxDamageHandOne() + ", speed: " + tar.getSpeedHandOne() + ", range: " + main.getRange() + newline; + if (off != null) + out += "Main Hand: atr: " + tar.getAtrHandTwo() + ", damage: " + tar.getMinDamageHandTwo() + " to " + tar.getMaxDamageHandTwo() + ", speed: " + tar.getSpeedHandTwo() + ", range: " + off.getRange() + newline; + } + out += "isAlive: " + tar.isAlive() + ", Combat: " + tar.isCombat() + newline; + + throwbackInfo(pc, out); + } + + public void printStatsNPC(PlayerCharacter pc, NPC tar) { + Contract contract = tar.getContract(); + if (contract == null) + return; + + String newline = "\r\n "; + + String name; + if (contract != null) { + if (contract.isTrainer()) + name = tar.getName() + ", " + contract.getName(); + else + name = tar.getName() + " the " + contract.getName(); + } else + name = tar.getName(); + String out = "Server stats for NPC " + name + newline; + out += "Sell Percent: " + tar.getSellPercent() + ", Buy Percent: " + tar.getBuyPercent() + newline; + + throwbackInfo(pc, out); + } + + @Override + protected String _getHelpString() { + return "Returns the player's current stats"; + } + + @Override + protected String _getUsageString() { + return "' /printstats'"; + } } diff --git a/src/engine/devcmd/cmds/PrintVaultCmd.java b/src/engine/devcmd/cmds/PrintVaultCmd.java index 7ddc411d..b949f18d 100644 --- a/src/engine/devcmd/cmds/PrintVaultCmd.java +++ b/src/engine/devcmd/cmds/PrintVaultCmd.java @@ -16,57 +16,57 @@ import java.util.ArrayList; public class PrintVaultCmd extends AbstractDevCmd { - public PrintVaultCmd() { - super("printvault"); - } + public PrintVaultCmd() { + super("printvault"); + } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { - AbstractWorldObject tar; - String name; - String type = "PlayerCharacter"; - if (target != null) { - if (target instanceof AbstractCharacter) { - tar = (AbstractCharacter) target; - name = ((AbstractCharacter) tar).getFirstName(); - } else { - tar = pc; - name = ((AbstractCharacter) tar).getFirstName(); - } - } else { - tar = pc; - name = ((AbstractCharacter) tar).getFirstName(); - } + AbstractWorldObject tar; + String name; + String type = "PlayerCharacter"; + if (target != null) { + if (target instanceof AbstractCharacter) { + tar = (AbstractCharacter) target; + name = ((AbstractCharacter) tar).getFirstName(); + } else { + tar = pc; + name = ((AbstractCharacter) tar).getFirstName(); + } + } else { + tar = pc; + name = ((AbstractCharacter) tar).getFirstName(); + } - if (!(tar instanceof PlayerCharacter)) { - throwbackError(pc, "Must target player"); - return; - } + if (!(tar instanceof PlayerCharacter)) { + throwbackError(pc, "Must target player"); + return; + } - CharacterItemManager cim = ((AbstractCharacter)tar).getCharItemManager(); - ArrayList list = cim.getVault(); - throwbackInfo(pc, "Vault for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')'); - for (Item item : list) { - throwbackInfo(pc, " " + item.getItemBase().getName() + ", count: " + item.getNumOfItems()); - } - Item gold = cim.getGoldVault(); - if (gold != null) - throwbackInfo(pc, " Gold, count: " + gold.getNumOfItems()); - else - throwbackInfo(pc, " NULL Gold"); - } + CharacterItemManager cim = ((AbstractCharacter) tar).getCharItemManager(); + ArrayList list = cim.getVault(); + throwbackInfo(pc, "Vault for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')'); + for (Item item : list) { + throwbackInfo(pc, " " + item.getItemBase().getName() + ", count: " + item.getNumOfItems()); + } + Item gold = cim.getGoldVault(); + if (gold != null) + throwbackInfo(pc, " Gold, count: " + gold.getNumOfItems()); + else + throwbackInfo(pc, " NULL Gold"); + } - @Override - protected String _getHelpString() { - return "Returns the player's current vault"; - } + @Override + protected String _getHelpString() { + return "Returns the player's current vault"; + } - @Override - protected String _getUsageString() { - return "' /printvault'"; - } + @Override + protected String _getUsageString() { + return "' /printvault'"; + } } diff --git a/src/engine/devcmd/cmds/PullCmd.java b/src/engine/devcmd/cmds/PullCmd.java index 16c4f4d4..0b26d16b 100644 --- a/src/engine/devcmd/cmds/PullCmd.java +++ b/src/engine/devcmd/cmds/PullCmd.java @@ -8,97 +8,95 @@ import engine.math.Vector3fImmutable; import engine.objects.*; /** - * - * @author - * Dev command to move mobile and it's spawn location + * @author Dev command to move mobile and it's spawn location * to the player's current location */ public class PullCmd extends AbstractDevCmd { - public PullCmd() { + public PullCmd() { super("pull"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - - Mob targetMobile; - Vector3fImmutable targetLoc; - Zone serverZone; - - if (validateUserInput(pcSender, target, args) == false) { - this.sendUsage(pcSender); - return; - } - - targetLoc = pcSender.getLoc(); - serverZone = ZoneManager.findSmallestZone(targetLoc); - switch (target.getObjectType()) { - case Mob: - MoveMobile((Mob) target, pcSender, targetLoc, serverZone); - break; - case Building: - MoveBuilding((Building) target, pcSender, targetLoc, serverZone); - break; - case NPC: - MoveNPC((NPC) target, pcSender, targetLoc, serverZone); - } - } - - @Override - protected String _getUsageString() { - return "/pull"; - } + private static void MoveMobile(Mob targetMobile, PlayerCharacter pcSender, Vector3fImmutable newLoc, Zone serverZone) { - @Override - protected String _getHelpString() { - return "Moves mobile (and spawn) to player's location"; - } + Vector3fImmutable localCoords; + + localCoords = ZoneManager.worldToLocal(newLoc, serverZone); - private boolean validateUserInput(PlayerCharacter pcSender, AbstractGameObject currTarget, String[] userInput) { + DbManager.MobQueries.MOVE_MOB(targetMobile.getObjectUUID(), serverZone.getObjectUUID(), localCoords.x, localCoords.y, localCoords.z); + targetMobile.setBindLoc(newLoc); + targetMobile.setLoc(newLoc); + targetMobile.refresh(); + } - // No target - if (currTarget == null) { - throwbackError(pcSender, "Requires a Mobile be targeted"); - return false; - } - return true; - } + private static void MoveBuilding(Building targetBuilding, PlayerCharacter pcSender, Vector3fImmutable newLoc, Zone serverZone) { - private static void MoveMobile(Mob targetMobile, PlayerCharacter pcSender, Vector3fImmutable newLoc, Zone serverZone) { + Vector3fImmutable localCoords; - Vector3fImmutable localCoords; + localCoords = ZoneManager.worldToLocal(newLoc, serverZone); - localCoords = ZoneManager.worldToLocal(newLoc, serverZone); + DbManager.BuildingQueries.MOVE_BUILDING(targetBuilding.getObjectUUID(), serverZone.getObjectUUID(), localCoords.x, localCoords.y, localCoords.z); + targetBuilding.setLoc(newLoc); + targetBuilding.getBounds().setBounds(targetBuilding); + targetBuilding.refresh(true); + } - DbManager.MobQueries.MOVE_MOB(targetMobile.getObjectUUID(), serverZone.getObjectUUID(), localCoords.x, localCoords.y, localCoords.z); - targetMobile.setBindLoc(newLoc); - targetMobile.setLoc(newLoc); - targetMobile.refresh(); - } + private static void MoveNPC(NPC targetNPC, PlayerCharacter pcSender, Vector3fImmutable newLoc, Zone serverZone) { - private static void MoveBuilding(Building targetBuilding, PlayerCharacter pcSender, Vector3fImmutable newLoc, Zone serverZone) { + Vector3fImmutable localCoords; - Vector3fImmutable localCoords; + localCoords = ZoneManager.worldToLocal(newLoc, serverZone); - localCoords = ZoneManager.worldToLocal(newLoc, serverZone); + DbManager.NPCQueries.MOVE_NPC(targetNPC.getObjectUUID(), serverZone.getObjectUUID(), localCoords.x, localCoords.y, localCoords.z); + targetNPC.setBindLoc(newLoc); + targetNPC.setLoc(newLoc); + WorldGrid.updateObject(targetNPC, pcSender); + } - DbManager.BuildingQueries.MOVE_BUILDING(targetBuilding.getObjectUUID(), serverZone.getObjectUUID(), localCoords.x, localCoords.y, localCoords.z); - targetBuilding.setLoc(newLoc); - targetBuilding.getBounds().setBounds(targetBuilding); - targetBuilding.refresh(true); - } + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] args, + AbstractGameObject target) { + + Mob targetMobile; + Vector3fImmutable targetLoc; + Zone serverZone; + + if (validateUserInput(pcSender, target, args) == false) { + this.sendUsage(pcSender); + return; + } + + targetLoc = pcSender.getLoc(); + serverZone = ZoneManager.findSmallestZone(targetLoc); + switch (target.getObjectType()) { + case Mob: + MoveMobile((Mob) target, pcSender, targetLoc, serverZone); + break; + case Building: + MoveBuilding((Building) target, pcSender, targetLoc, serverZone); + break; + case NPC: + MoveNPC((NPC) target, pcSender, targetLoc, serverZone); + } + } - private static void MoveNPC(NPC targetNPC, PlayerCharacter pcSender, Vector3fImmutable newLoc, Zone serverZone) { + @Override + protected String _getUsageString() { + return "/pull"; + } - Vector3fImmutable localCoords; + @Override + protected String _getHelpString() { + return "Moves mobile (and spawn) to player's location"; + } - localCoords = ZoneManager.worldToLocal(newLoc, serverZone); + private boolean validateUserInput(PlayerCharacter pcSender, AbstractGameObject currTarget, String[] userInput) { - DbManager.NPCQueries.MOVE_NPC(targetNPC.getObjectUUID(), serverZone.getObjectUUID(), localCoords.x, localCoords.y, localCoords.z); - targetNPC.setBindLoc(newLoc); - targetNPC.setLoc(newLoc); - WorldGrid.updateObject(targetNPC, pcSender); - } + // No target + if (currTarget == null) { + throwbackError(pcSender, "Requires a Mobile be targeted"); + return false; + } + return true; + } } diff --git a/src/engine/devcmd/cmds/PurgeObjectsCmd.java b/src/engine/devcmd/cmds/PurgeObjectsCmd.java index 13545c84..7a022384 100644 --- a/src/engine/devcmd/cmds/PurgeObjectsCmd.java +++ b/src/engine/devcmd/cmds/PurgeObjectsCmd.java @@ -18,50 +18,48 @@ import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; /** - * @author - * Summary: Game designer utility command to purge all - objects of a given type within a supplied range + * @author Summary: Game designer utility command to purge all + * objects of a given type within a supplied range */ public class PurgeObjectsCmd extends AbstractDevCmd { - // Instance variables + // Instance variables - private Vector3fImmutable _currentLocation; - private float _targetRange; - private int _targetMask; + private Vector3fImmutable _currentLocation; + private float _targetRange; + private int _targetMask; - // Concurrency support + // Concurrency support - private ReadWriteLock lock = new ReentrantReadWriteLock(); + private ReadWriteLock lock = new ReentrantReadWriteLock(); - // Constructor + // Constructor - public PurgeObjectsCmd() { + public PurgeObjectsCmd() { super("purge"); } - private static void PurgeWalls(Zone zone, PlayerCharacter pc){ + private static void PurgeWalls(Zone zone, PlayerCharacter pc) { if (!zone.isPlayerCity()) return; - for (Building building: zone.zoneBuildingSet){ + for (Building building : zone.zoneBuildingSet) { if (!BuildingManager.IsWallPiece(building)) continue; - for (AbstractCharacter ac: building.getHirelings().keySet()){ + for (AbstractCharacter ac : building.getHirelings().keySet()) { NPC npc = null; Mob mobA = null; if (ac.getObjectType() == GameObjectType.NPC) - npc = (NPC)ac; + npc = (NPC) ac; else if (ac.getObjectType() == GameObjectType.Mob) - mobA = (Mob)ac; + mobA = (Mob) ac; - - if (npc != null){ - for (Mob mob: npc.getSiegeMinionMap().keySet()){ + if (npc != null) { + for (Mob mob : npc.getSiegeMinionMap().keySet()) { WorldGrid.RemoveWorldObject(mob); WorldGrid.removeObject(mob, pc); //Mob.getRespawnMap().remove(mob); @@ -72,8 +70,8 @@ public class PurgeObjectsCmd extends AbstractDevCmd { DbManager.removeFromCache(GameObjectType.NPC, npc.getObjectUUID()); WorldGrid.RemoveWorldObject(npc); - }else if (mobA != null){ - for (Mob mob: mobA.getSiegeMinionMap().keySet()){ + } else if (mobA != null) { + for (Mob mob : mobA.getSiegeMinionMap().keySet()) { WorldGrid.RemoveWorldObject(mob); WorldGrid.removeObject(mob, pc); //Mob.getRespawnMap().remove(mob); @@ -100,216 +98,215 @@ public class PurgeObjectsCmd extends AbstractDevCmd { // AbstractDevCmd Overridden methods - @Override - protected void _doCmd(PlayerCharacter pc, String[] args, - AbstractGameObject target) { + private static boolean validateUserInput(String[] userInput) { - // Grab write lock due to use of instance variables + int stringIndex; + String commandSet = "npcmobmeshall"; - lock.writeLock().lock(); + // incorrect number of arguments test - try { - - if (args[0].toLowerCase().equals("walls")){ - Zone zone = ZoneManager.findSmallestZone(pc.getLoc()); - - PurgeWalls(zone, pc); - return; - } + if (userInput.length != 2) + return false; - if(validateUserInput(args) == false) { - this.sendUsage(pc); - return; - } + // Test of game object type argument - parseUserInput(args); + stringIndex = commandSet.indexOf(userInput[0].toLowerCase()); - // Arguments have been validated and parsed at this point - // Build array of requested objects + if (stringIndex == -1) + return false; - _currentLocation = pc.getLoc(); + // Test if range argument can convert to a float - HashSet objectList = - WorldGrid.getObjectsInRangePartial(_currentLocation, _targetRange, _targetMask); + try { + Float.parseFloat(userInput[1]); + } catch (NumberFormatException | NullPointerException e) { + return false; + } - // Iterate through array and remove objects from game world and database + // User input passes validation - for (AbstractWorldObject awo : objectList) { + return true; + } - switch(awo.getObjectType()) { - case Building: - removeBuilding(pc, (Building) awo); - break; - case NPC: - removeNPC(pc, (NPC) awo); - break; - case Mob: - removeMob(pc, (Mob) awo); - break; - default: - break; - } - } + private static void removeBuilding(PlayerCharacter pc, Building building) { - // Send results to user - throwbackInfo(pc, "Purge: " + objectList.size() + " objects were removed in range " + _targetRange); - }catch(Exception e){ - Logger.error(e); - } + if ((building.getBlueprintUUID() != 0) && + (building.getBlueprint().getBuildingGroup() == BuildingGroup.TOL)) + return; + if ((building.getBlueprintUUID() != 0) && + (building.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE)) + Shrine.RemoveShrineFromCacheByBuilding(building); + + if ((building.getBlueprint() != null) && (building.getBlueprint().getBuildingGroup() == BuildingGroup.SPIRE)) + building.disableSpire(false); + + for (AbstractCharacter ac : building.getHirelings().keySet()) { + NPC npc = null; + Mob mobA = null; + + if (ac.getObjectType() == GameObjectType.NPC) + npc = (NPC) ac; + else if (ac.getObjectType() == GameObjectType.Mob) + mobA = (Mob) ac; + + + if (npc != null) { + for (Mob mob : npc.getSiegeMinionMap().keySet()) { + WorldGrid.RemoveWorldObject(mob); + WorldGrid.removeObject(mob, pc); + //Mob.getRespawnMap().remove(mob); + if (mob.getParentZone() != null) + mob.getParentZone().zoneMobSet.remove(mob); + } + DbManager.NPCQueries.DELETE_NPC(npc); + DbManager.removeFromCache(Enum.GameObjectType.NPC, + npc.getObjectUUID()); + WorldGrid.RemoveWorldObject(npc); + } else if (mobA != null) { + for (Mob mob : mobA.getSiegeMinionMap().keySet()) { + WorldGrid.RemoveWorldObject(mob); + WorldGrid.removeObject(mob, pc); + //Mob.getRespawnMap().remove(mob); + if (mob.getParentZone() != null) + mob.getParentZone().zoneMobSet.remove(mob); + } + DbManager.MobQueries.DELETE_MOB(mobA); + DbManager.removeFromCache(Enum.GameObjectType.Mob, + mobA.getObjectUUID()); + WorldGrid.RemoveWorldObject(mobA); + } - // Release Reentrant lock + } - finally { - lock.writeLock().unlock(); - } - } - @Override - protected String _getHelpString() { - return "Purges game objects within range"; - } + DbManager.BuildingQueries.DELETE_FROM_DATABASE(building); + DbManager.removeFromCache(building); + WorldGrid.RemoveWorldObject(building); + WorldGrid.removeObject(building, pc); + } - @Override - protected String _getUsageString() { - return "/purge [npc|mob|mesh|all] [range <= 200]"; - } + private static void removeNPC(PlayerCharacter pc, NPC npc) { + DbManager.NPCQueries.DELETE_NPC(npc); + DbManager.removeFromCache(npc); + WorldGrid.RemoveWorldObject(npc); + WorldGrid.removeObject(npc, pc); + } - // Class methods + // Class methods - private static boolean validateUserInput(String[] userInput) { + private static void removeMob(PlayerCharacter pc, Mob mob) { + mob.setLoc(Vector3fImmutable.ZERO); //Move it off the plane.. + mob.setBindLoc(Vector3fImmutable.ZERO); //Reset the bind loc.. + //mob.setHealth(-1, pc); //Kill it! + + DbManager.MobQueries.DELETE_MOB(mob); + DbManager.removeFromCache(mob); + WorldGrid.RemoveWorldObject(mob); + WorldGrid.removeObject(mob, pc); + } + + @Override + protected void _doCmd(PlayerCharacter pc, String[] args, + AbstractGameObject target) { + + // Grab write lock due to use of instance variables + + lock.writeLock().lock(); + + try { + + if (args[0].toLowerCase().equals("walls")) { + Zone zone = ZoneManager.findSmallestZone(pc.getLoc()); + + PurgeWalls(zone, pc); + return; + } + + if (validateUserInput(args) == false) { + this.sendUsage(pc); + return; + } - int stringIndex; - String commandSet = "npcmobmeshall"; - - // incorrect number of arguments test - - if (userInput.length != 2) - return false; - - // Test of game object type argument + parseUserInput(args); - stringIndex = commandSet.indexOf(userInput[0].toLowerCase()); + // Arguments have been validated and parsed at this point + // Build array of requested objects - if (stringIndex == -1) - return false; - - // Test if range argument can convert to a float + _currentLocation = pc.getLoc(); - try { - Float.parseFloat(userInput[1]); } - catch (NumberFormatException | NullPointerException e) { - return false; - } - - // User input passes validation - - return true; - } - - private void parseUserInput(String[] userInput) { - - _targetMask = 0; - _targetRange = 0f; - - // Build mask from user input - - switch (userInput[0].toLowerCase()) { - case "npc": - _targetMask = MBServerStatics.MASK_NPC; - break; - case "mob": - _targetMask = MBServerStatics.MASK_MOB; - break; - case "mesh": - _targetMask = MBServerStatics.MASK_BUILDING; - break; - case "all": - _targetMask = MBServerStatics.MASK_NPC | MBServerStatics.MASK_MOB | MBServerStatics.MASK_BUILDING; - break; - default: - break; - } - - // Parse second argument into range parameter. Cap at 200 units. - - _targetRange = Float.parseFloat(userInput[1]); - _targetRange = Math.min(_targetRange, 200f); - } - - private static void removeBuilding(PlayerCharacter pc, Building building) { - - if ((building.getBlueprintUUID() != 0) && - (building.getBlueprint().getBuildingGroup() == BuildingGroup.TOL)) - return; - if ((building.getBlueprintUUID() != 0) && - (building.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE)) - Shrine.RemoveShrineFromCacheByBuilding(building); - - if ((building.getBlueprint() != null) && (building.getBlueprint().getBuildingGroup() == BuildingGroup.SPIRE)) - building.disableSpire(false); - - for (AbstractCharacter ac: building.getHirelings().keySet()){ - NPC npc = null; - Mob mobA = null; - - if (ac.getObjectType() == GameObjectType.NPC) - npc = (NPC)ac; - else if (ac.getObjectType() == GameObjectType.Mob) - mobA = (Mob)ac; - - - - if (npc != null){ - for (Mob mob: npc.getSiegeMinionMap().keySet()){ - WorldGrid.RemoveWorldObject(mob); - WorldGrid.removeObject(mob, pc); - //Mob.getRespawnMap().remove(mob); - if (mob.getParentZone() != null) - mob.getParentZone().zoneMobSet.remove(mob); - } - DbManager.NPCQueries.DELETE_NPC(npc); - DbManager.removeFromCache(Enum.GameObjectType.NPC, - npc.getObjectUUID()); - WorldGrid.RemoveWorldObject(npc); - }else if (mobA != null){ - for (Mob mob: mobA.getSiegeMinionMap().keySet()){ - WorldGrid.RemoveWorldObject(mob); - WorldGrid.removeObject(mob, pc); - //Mob.getRespawnMap().remove(mob); - if (mob.getParentZone() != null) - mob.getParentZone().zoneMobSet.remove(mob); - } - DbManager.MobQueries.DELETE_MOB(mobA); - DbManager.removeFromCache(Enum.GameObjectType.Mob, - mobA.getObjectUUID()); - WorldGrid.RemoveWorldObject(mobA); - } - - } - - - DbManager.BuildingQueries.DELETE_FROM_DATABASE(building); - DbManager.removeFromCache(building); - WorldGrid.RemoveWorldObject(building); - WorldGrid.removeObject(building, pc); - } - - private static void removeNPC(PlayerCharacter pc, NPC npc) { - DbManager.NPCQueries.DELETE_NPC(npc); - DbManager.removeFromCache(npc); - WorldGrid.RemoveWorldObject(npc); - WorldGrid.removeObject(npc, pc); - } - - private static void removeMob(PlayerCharacter pc, Mob mob) { - mob.setLoc(Vector3fImmutable.ZERO); //Move it off the plane.. - mob.setBindLoc(Vector3fImmutable.ZERO); //Reset the bind loc.. - //mob.setHealth(-1, pc); //Kill it! - - DbManager.MobQueries.DELETE_MOB(mob); - DbManager.removeFromCache(mob); - WorldGrid.RemoveWorldObject(mob); - WorldGrid.removeObject(mob, pc); - } + HashSet objectList = + WorldGrid.getObjectsInRangePartial(_currentLocation, _targetRange, _targetMask); + + // Iterate through array and remove objects from game world and database + + for (AbstractWorldObject awo : objectList) { + + switch (awo.getObjectType()) { + case Building: + removeBuilding(pc, (Building) awo); + break; + case NPC: + removeNPC(pc, (NPC) awo); + break; + case Mob: + removeMob(pc, (Mob) awo); + break; + default: + break; + } + } + + // Send results to user + throwbackInfo(pc, "Purge: " + objectList.size() + " objects were removed in range " + _targetRange); + } catch (Exception e) { + Logger.error(e); + } + + // Release Reentrant lock + + finally { + lock.writeLock().unlock(); + } + } + + @Override + protected String _getHelpString() { + return "Purges game objects within range"; + } + + @Override + protected String _getUsageString() { + return "/purge [npc|mob|mesh|all] [range <= 200]"; + } + + private void parseUserInput(String[] userInput) { + + _targetMask = 0; + _targetRange = 0f; + + // Build mask from user input + + switch (userInput[0].toLowerCase()) { + case "npc": + _targetMask = MBServerStatics.MASK_NPC; + break; + case "mob": + _targetMask = MBServerStatics.MASK_MOB; + break; + case "mesh": + _targetMask = MBServerStatics.MASK_BUILDING; + break; + case "all": + _targetMask = MBServerStatics.MASK_NPC | MBServerStatics.MASK_MOB | MBServerStatics.MASK_BUILDING; + break; + default: + break; + } + + // Parse second argument into range parameter. Cap at 200 units. + + _targetRange = Float.parseFloat(userInput[1]); + _targetRange = Math.min(_targetRange, 200f); + } } diff --git a/src/engine/devcmd/cmds/RealmInfoCmd.java b/src/engine/devcmd/cmds/RealmInfoCmd.java index 5c22d4a2..21c29e8d 100644 --- a/src/engine/devcmd/cmds/RealmInfoCmd.java +++ b/src/engine/devcmd/cmds/RealmInfoCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; @@ -21,68 +20,68 @@ import engine.objects.Zone; public class RealmInfoCmd extends AbstractDevCmd { - public RealmInfoCmd() { + public RealmInfoCmd() { super("realminfo"); } - @Override - protected void _doCmd(PlayerCharacter playerCharacter, String[] words, - AbstractGameObject target) { + @Override + protected void _doCmd(PlayerCharacter playerCharacter, String[] words, + AbstractGameObject target) { - Zone serverZone; - Realm serverRealm; - int realmID; - String outString = ""; + Zone serverZone; + Realm serverRealm; + int realmID; + String outString = ""; - if (playerCharacter == null) - return; + if (playerCharacter == null) + return; - serverZone = ZoneManager.findSmallestZone(playerCharacter.getLoc()); + serverZone = ZoneManager.findSmallestZone(playerCharacter.getLoc()); - if (serverZone == null) { - throwbackError(playerCharacter, "Zone not found"); - return; - } + if (serverZone == null) { + throwbackError(playerCharacter, "Zone not found"); + return; + } - realmID = RealmMap.getRealmIDAtLocation(playerCharacter.getLoc()); + realmID = RealmMap.getRealmIDAtLocation(playerCharacter.getLoc()); - String newline = "\r\n "; + String newline = "\r\n "; - outString = newline; - outString += "Realm: " + realmID + "("; + outString = newline; + outString += "Realm: " + realmID + "("; - serverRealm = Realm.getRealm(realmID); + serverRealm = Realm.getRealm(realmID); - if (serverRealm == null) - outString += "SeaFloor"; - else - outString += serverRealm.getRealmName(); + if (serverRealm == null) + outString += "SeaFloor"; + else + outString += serverRealm.getRealmName(); - outString += ")"; - outString += newline; + outString += ")"; + outString += newline; - outString += " Zone: " + serverZone.getName(); + outString += " Zone: " + serverZone.getName(); - outString += newline; + outString += newline; - if (serverZone.getParent() != null) - outString += " Parent: " + serverZone.getParent().getName(); - else - outString += "Parent: NONE"; + if (serverZone.getParent() != null) + outString += " Parent: " + serverZone.getParent().getName(); + else + outString += "Parent: NONE"; - outString += newline; + outString += newline; - throwbackInfo(playerCharacter, outString); - } + throwbackInfo(playerCharacter, outString); + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Returns info on realm."; - } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /info targetID'"; - } + } } diff --git a/src/engine/devcmd/cmds/RebootCmd.java b/src/engine/devcmd/cmds/RebootCmd.java index 2fe01c44..879125b3 100644 --- a/src/engine/devcmd/cmds/RebootCmd.java +++ b/src/engine/devcmd/cmds/RebootCmd.java @@ -6,43 +6,41 @@ import engine.objects.PlayerCharacter; import org.pmw.tinylog.Logger; /** - * @author - * Summary: Devcmd to reboot server - * + * @author Summary: Devcmd to reboot server */ public class RebootCmd extends AbstractDevCmd { - // Instance variables + // Instance variables - public RebootCmd() { + public RebootCmd() { super("reboot"); } - // AbstractDevCmd Overridden methods + // AbstractDevCmd Overridden methods - @Override - protected void _doCmd(PlayerCharacter pc, String[] args, - AbstractGameObject target) { + @Override + protected void _doCmd(PlayerCharacter pc, String[] args, + AbstractGameObject target) { - try { - Runtime rt = Runtime.getRuntime(); - rt.exec("./mbrestart.sh"); - } catch (java.io.IOException err) { - Logger.info( err.getMessage()); - } + try { + Runtime rt = Runtime.getRuntime(); + rt.exec("./mbrestart.sh"); + } catch (java.io.IOException err) { + Logger.info(err.getMessage()); + } - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Reboot server"; - } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "./reboot"; - } + } } diff --git a/src/engine/devcmd/cmds/RegionCmd.java b/src/engine/devcmd/cmds/RegionCmd.java index 928bcdfb..ca19fd25 100644 --- a/src/engine/devcmd/cmds/RegionCmd.java +++ b/src/engine/devcmd/cmds/RegionCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.devcmd.AbstractDevCmd; @@ -18,62 +17,62 @@ import java.lang.reflect.Field; public class RegionCmd extends AbstractDevCmd { - public RegionCmd() { + public RegionCmd() { super("region"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { if (pc.region == null) { - this.throwbackInfo(pc, "No Region Found."); - return; - } - - - String newLine = System.getProperty("line.separator"); - String result = ""; - result += (pc.region.getClass().getSimpleName()); - result += (" {"); - result+=(newLine); - Field[] fields = pc.region.getClass().getDeclaredFields(); - - //print field names paired with their values - for ( Field field : fields ) { - field.setAccessible(true); - result+=(" "); - try { - - if(field.getName().contains("Furniture")) - continue; - result+=( field.getName()); - result+=(": "); - //requires access to private field: - result += (field.get(pc.region).toString()); - } catch ( IllegalAccessException ex ) { - System.out.println(ex); - } - result.trim(); - result+=(newLine); - } - result+=("}"); - - this.throwbackInfo(pc, result.toString()); - - - } - - @Override - protected String _getHelpString() { - return "Temporarily Changes SubRace"; - } - - @Override - protected String _getUsageString() { - return "' /setBuildingCollidables add/remove 'add creates a collision line.' needs 4 integers. startX, endX, startY, endY"; - - } + this.throwbackInfo(pc, "No Region Found."); + return; + } + + + String newLine = System.getProperty("line.separator"); + String result = ""; + result += (pc.region.getClass().getSimpleName()); + result += (" {"); + result += (newLine); + Field[] fields = pc.region.getClass().getDeclaredFields(); + + //print field names paired with their values + for (Field field : fields) { + field.setAccessible(true); + result += (" "); + try { + + if (field.getName().contains("Furniture")) + continue; + result += (field.getName()); + result += (": "); + //requires access to private field: + result += (field.get(pc.region).toString()); + } catch (IllegalAccessException ex) { + System.out.println(ex); + } + result.trim(); + result += (newLine); + } + result += ("}"); + + this.throwbackInfo(pc, result.toString()); + + + } + + @Override + protected String _getHelpString() { + return "Temporarily Changes SubRace"; + } + + @Override + protected String _getUsageString() { + return "' /setBuildingCollidables add/remove 'add creates a collision line.' needs 4 integers. startX, endX, startY, endY"; + + } } diff --git a/src/engine/devcmd/cmds/RemoveBaneCmd.java b/src/engine/devcmd/cmds/RemoveBaneCmd.java index 98de9f90..31994552 100644 --- a/src/engine/devcmd/cmds/RemoveBaneCmd.java +++ b/src/engine/devcmd/cmds/RemoveBaneCmd.java @@ -16,55 +16,54 @@ import engine.objects.*; /** * @author Eighty - * */ public class RemoveBaneCmd extends AbstractDevCmd { - public RemoveBaneCmd() { + public RemoveBaneCmd() { super("removebane"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { - Zone zone = ZoneManager.findSmallestZone(pc.getLoc()); + Zone zone = ZoneManager.findSmallestZone(pc.getLoc()); - if (zone == null) { - throwbackError(pc, "Unable to find the zone you're in."); - return; - } + if (zone == null) { + throwbackError(pc, "Unable to find the zone you're in."); + return; + } - if (!zone.isPlayerCity()) { - throwbackError(pc, "This is not a player city."); - return; - } + if (!zone.isPlayerCity()) { + throwbackError(pc, "This is not a player city."); + return; + } - City city = City.getCity(zone.getPlayerCityUUID()); - if (city == null) { - throwbackError(pc, "Unable to find the city associated with this zone."); - return; - } + City city = City.getCity(zone.getPlayerCityUUID()); + if (city == null) { + throwbackError(pc, "Unable to find the city associated with this zone."); + return; + } - Bane bane = city.getBane(); - if (bane == null) { - throwbackError(pc, "Could not find bane to remove."); - return; - } + Bane bane = city.getBane(); + if (bane == null) { + throwbackError(pc, "Could not find bane to remove."); + return; + } - bane.endBane(SiegeResult.DEFEND); + bane.endBane(SiegeResult.DEFEND); - throwbackInfo(pc, "The bane has been removed."); - } + throwbackInfo(pc, "The bane has been removed."); + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Removes a bane from the city grid you're standing on."; - } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "'./removebane'"; - } + } } diff --git a/src/engine/devcmd/cmds/RemoveObjectCmd.java b/src/engine/devcmd/cmds/RemoveObjectCmd.java index 4979205f..6d13d2b1 100644 --- a/src/engine/devcmd/cmds/RemoveObjectCmd.java +++ b/src/engine/devcmd/cmds/RemoveObjectCmd.java @@ -26,240 +26,240 @@ import engine.objects.*; */ public class RemoveObjectCmd extends AbstractDevCmd { - public RemoveObjectCmd() { - //set to Player access level so it can be run by non-admins on production. - //Actual access level is set in _doCmd. - super("remove"); - this.addCmdString("delete"); - } - - @Override - protected void _doCmd(PlayerCharacter player, String[] words, AbstractGameObject target) { - - int targetID; - DbObjectType targetObjType; - Building targetBuilding; - NPC targetNPC; - Mob targetMob; - - if (target == null && words.length != 1) { - this.sendUsage(player); - return; - } - - // Delete the targeted building - - if (target != null) { - - switch (target.getObjectType()) { - - case Building: - removeBuilding(player, (Building) target); - break; - case NPC: - removeNPC(player, (NPC) target); - break; - case Mob: - removeMob(player, (Mob) target); - break; - default: - throwbackError(player, "Target " + target.getObjectType() - + " is not a valid object type"); - break; - } - return; - } - - // Attempt to delete object based upon parsed UUID from input - - // Parse Target UUID - - try { - targetID = Integer.parseInt(words[0]); - } catch (NumberFormatException e) { - throwbackError(player, "Supplied object ID " + words[0] - + " failed to parse to an Integer"); - return; - } - - // Determine object type of given UUID - - targetObjType = DbManager.BuildingQueries.GET_UID_ENUM(targetID); - - // Process accordingly - - switch (targetObjType) { - case BUILDING: - targetBuilding = BuildingManager.getBuilding(targetID); - removeBuilding(player, targetBuilding); - break; - case NPC: - targetNPC = NPC.getNPC(targetID); - removeNPC(player, targetNPC); - break; - case MOB: - targetMob = Mob.getMob(targetID); - removeMob(player, targetMob); - break; - default: - throwbackError(player, "Invalid UUID: Not found in database"); - break; - } - - } - - @Override - protected String _getHelpString() { + public RemoveObjectCmd() { + //set to Player access level so it can be run by non-admins on production. + //Actual access level is set in _doCmd. + super("remove"); + this.addCmdString("delete"); + } + + @Override + protected void _doCmd(PlayerCharacter player, String[] words, AbstractGameObject target) { + + int targetID; + DbObjectType targetObjType; + Building targetBuilding; + NPC targetNPC; + Mob targetMob; + + if (target == null && words.length != 1) { + this.sendUsage(player); + return; + } + + // Delete the targeted building + + if (target != null) { + + switch (target.getObjectType()) { + + case Building: + removeBuilding(player, (Building) target); + break; + case NPC: + removeNPC(player, (NPC) target); + break; + case Mob: + removeMob(player, (Mob) target); + break; + default: + throwbackError(player, "Target " + target.getObjectType() + + " is not a valid object type"); + break; + } + return; + } + + // Attempt to delete object based upon parsed UUID from input + + // Parse Target UUID + + try { + targetID = Integer.parseInt(words[0]); + } catch (NumberFormatException e) { + throwbackError(player, "Supplied object ID " + words[0] + + " failed to parse to an Integer"); + return; + } + + // Determine object type of given UUID + + targetObjType = DbManager.BuildingQueries.GET_UID_ENUM(targetID); + + // Process accordingly + + switch (targetObjType) { + case BUILDING: + targetBuilding = BuildingManager.getBuilding(targetID); + removeBuilding(player, targetBuilding); + break; + case NPC: + targetNPC = NPC.getNPC(targetID); + removeNPC(player, targetNPC); + break; + case MOB: + targetMob = Mob.getMob(targetID); + removeMob(player, targetMob); + break; + default: + throwbackError(player, "Invalid UUID: Not found in database"); + break; + } + + } + + @Override + protected String _getHelpString() { return "Removes targeted or specified object"; - } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /remove [objectID]' || ' /delete [objectID]'"; - } - - private void removeBuilding(PlayerCharacter pc, Building building) { - - Zone currentZone = ZoneManager.findSmallestZone(pc.getLoc()); - - if (currentZone == null) { - this.throwbackError(pc, "Could not locate zone for player."); - return; - } - - if ((building.getBlueprint() != null) && (building.getBlueprint().getBuildingGroup() == BuildingGroup.SPIRE)) - building.disableSpire(false); - - if ((building.getBlueprint() != null) && (building.getBlueprint().getBuildingGroup() == BuildingGroup.WAREHOUSE)){ - City city =City.getCity(building.getParentZone().getPlayerCityUUID()); - if (city != null){ - city.setWarehouseBuildingID(0); - } - Warehouse.warehouseByBuildingUUID.remove(building.getObjectUUID()); - } - - - //remove cached shrines. - if ((building.getBlueprintUUID() != 0) - && (building.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE)) - Shrine.RemoveShrineFromCacheByBuilding(building); - - for (AbstractCharacter ac : building.getHirelings().keySet()) { - NPC npc = null; - Mob mobA = null; - - if (ac.getObjectType() == GameObjectType.NPC) - npc = (NPC)ac; - else if (ac.getObjectType() == GameObjectType.Mob) - mobA = (Mob)ac; - - if (npc != null){ - for (Mob mob : npc.getSiegeMinionMap().keySet()) { - WorldGrid.RemoveWorldObject(mob); - WorldGrid.removeObject(mob, pc); - //Mob.getRespawnMap().remove(mob); - if (mob.getParentZone() != null) - mob.getParentZone().zoneMobSet.remove(mob); - } - DbManager.NPCQueries.DELETE_NPC(npc); - DbManager.removeFromCache(npc); - WorldGrid.RemoveWorldObject(npc); - WorldGrid.removeObject(npc, pc); - }else if (mobA != null){ - for (Mob mob : mobA.getSiegeMinionMap().keySet()) { - WorldGrid.RemoveWorldObject(mob); - WorldGrid.removeObject(mob, pc); - //Mob.getRespawnMap().remove(mob); - if (mob.getParentZone() != null) - mob.getParentZone().zoneMobSet.remove(mob); - } - DbManager.MobQueries.DELETE_MOB(mobA); - DbManager.removeFromCache(mobA); - WorldGrid.RemoveWorldObject(mobA); - WorldGrid.removeObject(mobA, pc); - } - - - } - Zone zone = building.getParentZone(); - DbManager.BuildingQueries.DELETE_FROM_DATABASE(building); - DbManager.removeFromCache(building); - zone.zoneBuildingSet.remove(building); - if(building.getBlueprint() != null && building.getBlueprint().getBuildingGroup().equals(BuildingGroup.BARRACK)){ - building.RemoveFromBarracksList(); - } - WorldGrid.RemoveWorldObject(building); - WorldGrid.removeObject(building, pc); - - ChatManager.chatSayInfo(pc, - "Building with ID " + building.getObjectUUID() + " removed"); - this.setResult(String.valueOf(building.getObjectUUID())); - } - - private void removeNPC(PlayerCharacter pc, NPC npc) { - - Zone currentZone = ZoneManager.findSmallestZone(pc.getLoc()); - if (currentZone == null) { - this.throwbackError(pc, "Could not locate zone for player."); - return; - } - - // Remove npc from hirelings list. - - if (npc.building != null) - npc.building.getHirelings().remove(npc); - - for (Mob mob : npc.getSiegeMinionMap().keySet()) { - WorldGrid.RemoveWorldObject(mob); - WorldGrid.removeObject(mob, pc); - if (mob.getParentZone() != null) - mob.getParentZone().zoneMobSet.remove(mob); - } - - DbManager.NPCQueries.DELETE_NPC(npc); - DbManager.removeFromCache(npc); - WorldGrid.RemoveWorldObject(npc); - WorldGrid.removeObject(npc, pc); - ChatManager.chatSayInfo(pc, - "NPC with ID " + npc.getDBID() + " removed"); - this.setResult(String.valueOf(npc.getDBID())); - } - - private void removeMob(PlayerCharacter pc, Mob mob) { - - Zone currentZone = ZoneManager.findSmallestZone(pc.getLoc()); - - if (currentZone == null) { - this.throwbackError(pc, "Could not locate zone for player."); - return; - } - - if (mob.getParentZone() != null && mob.getParentZone() != currentZone && !mob.isPet() && !mob.isNecroPet()) { - this.throwbackError(pc, "Error 376954: Could not Remove Mob.Mob is not in the same zone as player."); - return; - } - - // Remove npc from hirelings list. - - if (mob.building != null) - mob.building.getHirelings().remove(mob); - - mob.setLoc(Vector3fImmutable.ZERO); //Move it off the plane.. - mob.setBindLoc(Vector3fImmutable.ZERO); //Reset the bind loc.. - //mob.setHealth(-1, pc); //Kill it! - - DbManager.MobQueries.DELETE_MOB(mob); - - DbManager.removeFromCache(mob); - WorldGrid.RemoveWorldObject(mob); - WorldGrid.removeObject(mob, pc); - - if (mob.getParentZone() != null) - mob.getParentZone().zoneMobSet.remove(mob); - - ChatManager.chatSayInfo(pc, - "Mob with ID " + mob.getDBID() + " removed"); - this.setResult(String.valueOf(mob.getDBID())); - } + } + + private void removeBuilding(PlayerCharacter pc, Building building) { + + Zone currentZone = ZoneManager.findSmallestZone(pc.getLoc()); + + if (currentZone == null) { + this.throwbackError(pc, "Could not locate zone for player."); + return; + } + + if ((building.getBlueprint() != null) && (building.getBlueprint().getBuildingGroup() == BuildingGroup.SPIRE)) + building.disableSpire(false); + + if ((building.getBlueprint() != null) && (building.getBlueprint().getBuildingGroup() == BuildingGroup.WAREHOUSE)) { + City city = City.getCity(building.getParentZone().getPlayerCityUUID()); + if (city != null) { + city.setWarehouseBuildingID(0); + } + Warehouse.warehouseByBuildingUUID.remove(building.getObjectUUID()); + } + + + //remove cached shrines. + if ((building.getBlueprintUUID() != 0) + && (building.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE)) + Shrine.RemoveShrineFromCacheByBuilding(building); + + for (AbstractCharacter ac : building.getHirelings().keySet()) { + NPC npc = null; + Mob mobA = null; + + if (ac.getObjectType() == GameObjectType.NPC) + npc = (NPC) ac; + else if (ac.getObjectType() == GameObjectType.Mob) + mobA = (Mob) ac; + + if (npc != null) { + for (Mob mob : npc.getSiegeMinionMap().keySet()) { + WorldGrid.RemoveWorldObject(mob); + WorldGrid.removeObject(mob, pc); + //Mob.getRespawnMap().remove(mob); + if (mob.getParentZone() != null) + mob.getParentZone().zoneMobSet.remove(mob); + } + DbManager.NPCQueries.DELETE_NPC(npc); + DbManager.removeFromCache(npc); + WorldGrid.RemoveWorldObject(npc); + WorldGrid.removeObject(npc, pc); + } else if (mobA != null) { + for (Mob mob : mobA.getSiegeMinionMap().keySet()) { + WorldGrid.RemoveWorldObject(mob); + WorldGrid.removeObject(mob, pc); + //Mob.getRespawnMap().remove(mob); + if (mob.getParentZone() != null) + mob.getParentZone().zoneMobSet.remove(mob); + } + DbManager.MobQueries.DELETE_MOB(mobA); + DbManager.removeFromCache(mobA); + WorldGrid.RemoveWorldObject(mobA); + WorldGrid.removeObject(mobA, pc); + } + + + } + Zone zone = building.getParentZone(); + DbManager.BuildingQueries.DELETE_FROM_DATABASE(building); + DbManager.removeFromCache(building); + zone.zoneBuildingSet.remove(building); + if (building.getBlueprint() != null && building.getBlueprint().getBuildingGroup().equals(BuildingGroup.BARRACK)) { + building.RemoveFromBarracksList(); + } + WorldGrid.RemoveWorldObject(building); + WorldGrid.removeObject(building, pc); + + ChatManager.chatSayInfo(pc, + "Building with ID " + building.getObjectUUID() + " removed"); + this.setResult(String.valueOf(building.getObjectUUID())); + } + + private void removeNPC(PlayerCharacter pc, NPC npc) { + + Zone currentZone = ZoneManager.findSmallestZone(pc.getLoc()); + if (currentZone == null) { + this.throwbackError(pc, "Could not locate zone for player."); + return; + } + + // Remove npc from hirelings list. + + if (npc.building != null) + npc.building.getHirelings().remove(npc); + + for (Mob mob : npc.getSiegeMinionMap().keySet()) { + WorldGrid.RemoveWorldObject(mob); + WorldGrid.removeObject(mob, pc); + if (mob.getParentZone() != null) + mob.getParentZone().zoneMobSet.remove(mob); + } + + DbManager.NPCQueries.DELETE_NPC(npc); + DbManager.removeFromCache(npc); + WorldGrid.RemoveWorldObject(npc); + WorldGrid.removeObject(npc, pc); + ChatManager.chatSayInfo(pc, + "NPC with ID " + npc.getDBID() + " removed"); + this.setResult(String.valueOf(npc.getDBID())); + } + + private void removeMob(PlayerCharacter pc, Mob mob) { + + Zone currentZone = ZoneManager.findSmallestZone(pc.getLoc()); + + if (currentZone == null) { + this.throwbackError(pc, "Could not locate zone for player."); + return; + } + + if (mob.getParentZone() != null && mob.getParentZone() != currentZone && !mob.isPet() && !mob.isNecroPet()) { + this.throwbackError(pc, "Error 376954: Could not Remove Mob.Mob is not in the same zone as player."); + return; + } + + // Remove npc from hirelings list. + + if (mob.building != null) + mob.building.getHirelings().remove(mob); + + mob.setLoc(Vector3fImmutable.ZERO); //Move it off the plane.. + mob.setBindLoc(Vector3fImmutable.ZERO); //Reset the bind loc.. + //mob.setHealth(-1, pc); //Kill it! + + DbManager.MobQueries.DELETE_MOB(mob); + + DbManager.removeFromCache(mob); + WorldGrid.RemoveWorldObject(mob); + WorldGrid.removeObject(mob, pc); + + if (mob.getParentZone() != null) + mob.getParentZone().zoneMobSet.remove(mob); + + ChatManager.chatSayInfo(pc, + "Mob with ID " + mob.getDBID() + " removed"); + this.setResult(String.valueOf(mob.getDBID())); + } } diff --git a/src/engine/devcmd/cmds/RenameCmd.java b/src/engine/devcmd/cmds/RenameCmd.java index 73db6a24..d1d31edb 100644 --- a/src/engine/devcmd/cmds/RenameCmd.java +++ b/src/engine/devcmd/cmds/RenameCmd.java @@ -18,64 +18,62 @@ import engine.objects.NPC; import engine.objects.PlayerCharacter; /** - * * @author Eighty - * */ public class RenameCmd extends AbstractDevCmd { - public RenameCmd() { + public RenameCmd() { super("rename"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - if (args.length < 1) { - this.sendUsage(pcSender); - return; - } - if (args[0].isEmpty()) { - throwbackError(pcSender, "Invalid rename Command. must specify a name."); - return; - } - NPC npc = null; - Building building = null; - - if (target != null) { - if (target instanceof NPC) - npc = (NPC) target; - else if (target instanceof Building) - building = (Building)target; - } else - npc = getTargetAsNPC(pcSender); - if (npc != null) { - DbManager.NPCQueries.SET_PROPERTY(npc, "npc_name", args[0]); - String name = args[0]; - name = name.replaceAll("_", " "); - - npc.setName(name); + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] args, + AbstractGameObject target) { + if (args.length < 1) { + this.sendUsage(pcSender); + return; + } + if (args[0].isEmpty()) { + throwbackError(pcSender, "Invalid rename Command. must specify a name."); + return; + } + NPC npc = null; + Building building = null; - this.setResult(String.valueOf(npc.getDBID())); + if (target != null) { + if (target instanceof NPC) + npc = (NPC) target; + else if (target instanceof Building) + building = (Building) target; + } else + npc = getTargetAsNPC(pcSender); + if (npc != null) { + DbManager.NPCQueries.SET_PROPERTY(npc, "npc_name", args[0]); + String name = args[0]; + name = name.replaceAll("_", " "); + + npc.setName(name); + + this.setResult(String.valueOf(npc.getDBID())); // npc.updateDatabase(); - WorldGrid.updateObject(npc, pcSender); - } else if (building != null){ - String name = args[0]; - name = name.replaceAll("_", " "); - building.setName(name); - } - throwbackError(pcSender, "Invalid rename Command. must target an npc."); - } + WorldGrid.updateObject(npc, pcSender); + } else if (building != null) { + String name = args[0]; + name = name.replaceAll("_", " "); + building.setName(name); + } + throwbackError(pcSender, "Invalid rename Command. must target an npc."); + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /rename npcName'"; - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Renames an NPC."; - } + } } diff --git a/src/engine/devcmd/cmds/ResetLevelCmd.java b/src/engine/devcmd/cmds/ResetLevelCmd.java index ef3dc496..aa6d1ef2 100644 --- a/src/engine/devcmd/cmds/ResetLevelCmd.java +++ b/src/engine/devcmd/cmds/ResetLevelCmd.java @@ -5,32 +5,31 @@ import engine.objects.AbstractGameObject; import engine.objects.PlayerCharacter; public class ResetLevelCmd extends AbstractDevCmd { - - public ResetLevelCmd() { + + public ResetLevelCmd() { super("resetlevel"); } - // AbstractDevCmd Overridden methods - - @Override - protected void _doCmd(PlayerCharacter player, String[] args, - AbstractGameObject target) { - - player.ResetLevel(Short.parseShort(args[0])); - } - - @Override - protected String _getHelpString() { + // AbstractDevCmd Overridden methods + + @Override + protected void _doCmd(PlayerCharacter player, String[] args, + AbstractGameObject target) { + + player.ResetLevel(Short.parseShort(args[0])); + } + + @Override + protected String _getHelpString() { return "Resets character level to `level`. All training points are reset. Player must relog for changes to update."; - } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "/resetlevel "; - } + } + - - } diff --git a/src/engine/devcmd/cmds/RotateCmd.java b/src/engine/devcmd/cmds/RotateCmd.java index c6dc7c73..fe25ad35 100644 --- a/src/engine/devcmd/cmds/RotateCmd.java +++ b/src/engine/devcmd/cmds/RotateCmd.java @@ -20,232 +20,232 @@ import engine.objects.*; public class RotateCmd extends AbstractDevCmd { - public RotateCmd() { + public RotateCmd() { super("rotate"); this.addCmdString("rot"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - if (target == null && (words.length != 2) ) { - this.sendUsage(pc); - return; - } - - - if (words.length == 3){ - try{ - - }catch(Exception e){ - - } - } - - - float rot; - if (target != null && words.length == 1) { - - try { - if (words[0].equalsIgnoreCase("face")){ - this.rotateFace(pc, target); - return; - } - - rot = Float.parseFloat(words[0]); - } catch (NumberFormatException e) { - throwbackError(pc, "Supplied rotation " + words[0] - + " failed to parse to a Float"); - return; - } catch (Exception e) { - throwbackError(pc, - "Invalid Rotate Command. Need Rotation specified."); - return; - } - - Vector3f rotation = new Vector3f(0f, rot, 0f); - - if (target instanceof Building) - rotateBuilding(pc, (Building) target, rotation, rot,false); - else if (target instanceof NPC) - rotateNPC(pc, (NPC) target, rotation,false); - else if (target instanceof Mob) - rotateMob(pc, (Mob) target, rotation,false); - else - throwbackError(pc, "Target " + target.getObjectType() - + " is not a valid object type"); - } else { - - int id = 0; - if (words.length == 2) { - try { - id = Integer.parseInt(words[0]); - - if (words[1].equalsIgnoreCase("face")){ - - Building b; - if (id != 0) - b = BuildingManager.getBuilding(id); - else - b = getTargetAsBuilding(pc); - if (b != null) { - rotateFace(pc, b); - return; - } - - // building failed, try npc - NPC npc; - if (id != 0) - npc = NPC.getNPC(id); - else - npc = getTargetAsNPC(pc); - if (npc != null) { - rotateFace(pc, npc); - return; - } - - // NPC failed, try mob - Mob mob; - if (id != 0) - mob = Mob.getMob(id); - else - mob = getTargetAsMob(pc); - if (mob != null) { - rotateFace(pc, mob); - return; - } - throwbackError(pc, "Nothing found to rotate."); - return; - } - rot = Float.parseFloat(words[1]); - } catch (NumberFormatException e) { - throwbackError(pc, "Supplied arguments " + words[0] + ' ' - + words[1] + " failed to parse"); - return; - } catch (Exception e) { - throwbackError(pc, - "Invalid Rotate Command. Need Rotation specified."); - return; // NaN - } - } else { - try { - rot = Float.parseFloat(words[0]); - } catch (NumberFormatException e) { - throwbackError(pc, "Supplied rotation " + words[0] - + " failed to parse to a Float"); - return; - } catch (Exception e) { - throwbackError(pc, - "Invalid Rotate Command. Need Rotation specified."); - return; // NaN - } - } - - Vector3f rotation = new Vector3f(0f, rot, 0f); - - Building b; - if (id != 0) - b = BuildingManager.getBuilding(id); - else - b = getTargetAsBuilding(pc); - if (b != null) { - rotateBuilding(pc, b, rotation, rot,false); - return; - } - - // building failed, try npc - NPC npc; - if (id != 0) - npc = NPC.getNPC(id); - else - npc = getTargetAsNPC(pc); - if (npc != null) { - rotateNPC(pc, npc, rotation,false); - return; - } - - // NPC failed, try mob - Mob mob; - if (id != 0) - mob = Mob.getMob(id); - else - mob = getTargetAsMob(pc); - if (mob != null) { - rotateMob(pc, mob, rotation,false); - return; - } - throwbackError(pc, "Nothing found to rotate."); - } - } - - @Override - protected String _getHelpString() { + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + if (target == null && (words.length != 2)) { + this.sendUsage(pc); + return; + } + + + if (words.length == 3) { + try { + + } catch (Exception e) { + + } + } + + + float rot; + if (target != null && words.length == 1) { + + try { + if (words[0].equalsIgnoreCase("face")) { + this.rotateFace(pc, target); + return; + } + + rot = Float.parseFloat(words[0]); + } catch (NumberFormatException e) { + throwbackError(pc, "Supplied rotation " + words[0] + + " failed to parse to a Float"); + return; + } catch (Exception e) { + throwbackError(pc, + "Invalid Rotate Command. Need Rotation specified."); + return; + } + + Vector3f rotation = new Vector3f(0f, rot, 0f); + + if (target instanceof Building) + rotateBuilding(pc, (Building) target, rotation, rot, false); + else if (target instanceof NPC) + rotateNPC(pc, (NPC) target, rotation, false); + else if (target instanceof Mob) + rotateMob(pc, (Mob) target, rotation, false); + else + throwbackError(pc, "Target " + target.getObjectType() + + " is not a valid object type"); + } else { + + int id = 0; + if (words.length == 2) { + try { + id = Integer.parseInt(words[0]); + + if (words[1].equalsIgnoreCase("face")) { + + Building b; + if (id != 0) + b = BuildingManager.getBuilding(id); + else + b = getTargetAsBuilding(pc); + if (b != null) { + rotateFace(pc, b); + return; + } + + // building failed, try npc + NPC npc; + if (id != 0) + npc = NPC.getNPC(id); + else + npc = getTargetAsNPC(pc); + if (npc != null) { + rotateFace(pc, npc); + return; + } + + // NPC failed, try mob + Mob mob; + if (id != 0) + mob = Mob.getMob(id); + else + mob = getTargetAsMob(pc); + if (mob != null) { + rotateFace(pc, mob); + return; + } + throwbackError(pc, "Nothing found to rotate."); + return; + } + rot = Float.parseFloat(words[1]); + } catch (NumberFormatException e) { + throwbackError(pc, "Supplied arguments " + words[0] + ' ' + + words[1] + " failed to parse"); + return; + } catch (Exception e) { + throwbackError(pc, + "Invalid Rotate Command. Need Rotation specified."); + return; // NaN + } + } else { + try { + rot = Float.parseFloat(words[0]); + } catch (NumberFormatException e) { + throwbackError(pc, "Supplied rotation " + words[0] + + " failed to parse to a Float"); + return; + } catch (Exception e) { + throwbackError(pc, + "Invalid Rotate Command. Need Rotation specified."); + return; // NaN + } + } + + Vector3f rotation = new Vector3f(0f, rot, 0f); + + Building b; + if (id != 0) + b = BuildingManager.getBuilding(id); + else + b = getTargetAsBuilding(pc); + if (b != null) { + rotateBuilding(pc, b, rotation, rot, false); + return; + } + + // building failed, try npc + NPC npc; + if (id != 0) + npc = NPC.getNPC(id); + else + npc = getTargetAsNPC(pc); + if (npc != null) { + rotateNPC(pc, npc, rotation, false); + return; + } + + // NPC failed, try mob + Mob mob; + if (id != 0) + mob = Mob.getMob(id); + else + mob = getTargetAsMob(pc); + if (mob != null) { + rotateMob(pc, mob, rotation, false); + return; + } + throwbackError(pc, "Nothing found to rotate."); + } + } + + @Override + protected String _getHelpString() { return "Rotates targeted or specified object"; - } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /rotate [objectID] rotation' || ' /rot [objectID] rotation'"; - } - - private void rotateBuilding(PlayerCharacter pc, Building building, Vector3f rot, float orig, boolean faceDirection) { - if (!faceDirection) - rot.set(0.0f, (float)Math.sin(Math.toRadians(orig)/2), 0.0f); - building.setRot(rot); - building.setw( (float) Math.abs(Math.cos(Math.toRadians(orig)/2)) ); - building.getBounds().setBounds(building); - WorldGrid.updateObject(building, pc); - DbManager.BuildingQueries.SET_PROPERTY(building, "rotY", building.getRot().getY()); - DbManager.BuildingQueries.SET_PROPERTY(building, "w", building.getw()); - ChatManager.chatSayInfo(pc, - "Building with ID " + building.getObjectUUID() + " rotated"); - } - - private void rotateNPC(PlayerCharacter pc, NPC npc, Vector3f rot,boolean faceDirection) { - npc.setRot(rot); - DbManager.NPCQueries.SET_PROPERTY(npc, "npc_rotation", rot.y); - WorldGrid.updateObject(npc, pc); - //no rotation for npc's in db currently - ChatManager.chatSayInfo(pc, - "NPC with ID " + npc.getObjectUUID() + " rotated"); - } - - private void rotateMob(PlayerCharacter pc, Mob mob, Vector3f rot,boolean faceDirection) { - mob.setRot(rot); - DbManager.MobQueries.SET_PROPERTY(mob, "mob_rotation", rot.y); - WorldGrid.updateObject(mob, pc); - //no rotation for mobs's in db currently - ChatManager.chatSayInfo(pc, - "Mob with ID " + mob.getObjectUUID() + " rotated"); - } - - private void rotateFace(PlayerCharacter pc, AbstractGameObject target){ - AbstractWorldObject awo = (AbstractWorldObject)target; - if (awo == null) - return; - Vector3fImmutable buildingLoc = awo.getLoc(); - Vector3fImmutable playerLoc = pc.getLoc(); - - Vector3fImmutable faceDirection = playerLoc.subtract2D(buildingLoc); - - float rotangle = faceDirection.getRotation(); - - float rot = (float) Math.toDegrees(rotangle); - - if (rot > 180) - rot*=-1; - - Vector3f buildingrotation = new Vector3f(0f, rot, 0f); - Vector3f rotation = new Vector3f(0f, rotangle, 0f); - if (target instanceof Building) - rotateBuilding(pc, (Building) target, buildingrotation, rot,false); - else if (target instanceof NPC) - rotateNPC(pc, (NPC) target, rotation,true); - else if (target instanceof Mob) - rotateMob(pc, (Mob) target, rotation,true); - else - throwbackError(pc, "Target " + target.getObjectType() - + " is not a valid object type"); - - } + } + + private void rotateBuilding(PlayerCharacter pc, Building building, Vector3f rot, float orig, boolean faceDirection) { + if (!faceDirection) + rot.set(0.0f, (float) Math.sin(Math.toRadians(orig) / 2), 0.0f); + building.setRot(rot); + building.setw((float) Math.abs(Math.cos(Math.toRadians(orig) / 2))); + building.getBounds().setBounds(building); + WorldGrid.updateObject(building, pc); + DbManager.BuildingQueries.SET_PROPERTY(building, "rotY", building.getRot().getY()); + DbManager.BuildingQueries.SET_PROPERTY(building, "w", building.getw()); + ChatManager.chatSayInfo(pc, + "Building with ID " + building.getObjectUUID() + " rotated"); + } + + private void rotateNPC(PlayerCharacter pc, NPC npc, Vector3f rot, boolean faceDirection) { + npc.setRot(rot); + DbManager.NPCQueries.SET_PROPERTY(npc, "npc_rotation", rot.y); + WorldGrid.updateObject(npc, pc); + //no rotation for npc's in db currently + ChatManager.chatSayInfo(pc, + "NPC with ID " + npc.getObjectUUID() + " rotated"); + } + + private void rotateMob(PlayerCharacter pc, Mob mob, Vector3f rot, boolean faceDirection) { + mob.setRot(rot); + DbManager.MobQueries.SET_PROPERTY(mob, "mob_rotation", rot.y); + WorldGrid.updateObject(mob, pc); + //no rotation for mobs's in db currently + ChatManager.chatSayInfo(pc, + "Mob with ID " + mob.getObjectUUID() + " rotated"); + } + + private void rotateFace(PlayerCharacter pc, AbstractGameObject target) { + AbstractWorldObject awo = (AbstractWorldObject) target; + if (awo == null) + return; + Vector3fImmutable buildingLoc = awo.getLoc(); + Vector3fImmutable playerLoc = pc.getLoc(); + + Vector3fImmutable faceDirection = playerLoc.subtract2D(buildingLoc); + + float rotangle = faceDirection.getRotation(); + + float rot = (float) Math.toDegrees(rotangle); + + if (rot > 180) + rot *= -1; + + Vector3f buildingrotation = new Vector3f(0f, rot, 0f); + Vector3f rotation = new Vector3f(0f, rotangle, 0f); + if (target instanceof Building) + rotateBuilding(pc, (Building) target, buildingrotation, rot, false); + else if (target instanceof NPC) + rotateNPC(pc, (NPC) target, rotation, true); + else if (target instanceof Mob) + rotateMob(pc, (Mob) target, rotation, true); + else + throwbackError(pc, "Target " + target.getObjectType() + + " is not a valid object type"); + + } } \ No newline at end of file diff --git a/src/engine/devcmd/cmds/SetAICmd.java b/src/engine/devcmd/cmds/SetAICmd.java index 603307e6..7a30899d 100644 --- a/src/engine/devcmd/cmds/SetAICmd.java +++ b/src/engine/devcmd/cmds/SetAICmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.ai.MobileFSMManager; @@ -19,111 +18,110 @@ import engine.server.MBServerStatics; /** * @author Steve - * */ public class SetAICmd extends AbstractDevCmd { - public SetAICmd() { + public SetAICmd() { super("setAI"); this.addCmdString("ai"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - if (words.length < 2){ - this.sendUsage(pc); - return; - } - - int amount; + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + if (words.length < 2) { + this.sendUsage(pc); + return; + } + + int amount; - try{ - amount = Integer.valueOf(words[1]); - }catch (NumberFormatException e) { - this.throwbackError(pc, "Failed to parse amount"); - return; - } - - switch(words[0]){ - case "angle" : - float angle = Float.parseFloat(words[1]); - - MobileFSMManager.AI_MAX_ANGLE = angle; - break; - case "aggrorange": - MobileFSMManager.AI_BASE_AGGRO_RANGE = amount; - DbManager.MobBaseQueries.UPDATE_AI_DEFAULTS(); - this.throwbackInfo(pc, "Aggro Range is now set to " + amount); - break; - case "dropaggrorange": - MobileFSMManager.AI_DROP_AGGRO_RANGE = amount; - DbManager.MobBaseQueries.UPDATE_AI_DEFAULTS(); - this.throwbackInfo(pc, "Drop Aggro Range is now set to " + amount); - break; - case "patroldivisor": - MobileFSMManager.AI_PATROL_DIVISOR = amount; - DbManager.MobBaseQueries.UPDATE_AI_DEFAULTS(); - this.throwbackInfo(pc, "Patrol Chance is now set to " + amount); - break; - case "pulse": - if (amount < 500){ - this.throwbackError(pc, "pulse amount must be greather than 500 to execute."); - return; - } - MobileFSMManager.AI_PULSE_MOB_THRESHOLD = amount; - this.throwbackInfo(pc, "Pulse is now set to " + amount); - break; - case "sleepthread": - if (amount < 500){ - this.throwbackError(pc, "sleep amount must be greather than 500 to execute."); - return; - } - MobileFSMManager.AI_THREAD_SLEEP = amount; - this.throwbackInfo(pc, "Thread Sleep is now set to " + amount); - break; - case "recallrange": - MobileFSMManager.AI_RECALL_RANGE = amount; - DbManager.MobBaseQueries.UPDATE_AI_DEFAULTS(); - this.throwbackInfo(pc, "Recall Range is now set to " + amount); - break; - case "powerdivisor": - MobileFSMManager.AI_POWER_DIVISOR = amount; - DbManager.MobBaseQueries.UPDATE_AI_DEFAULTS(); - this.throwbackInfo(pc, "Power Divisor is now set to " + amount); - break; - case "losehate": - MBServerStatics.PLAYER_HATE_DELIMITER = amount; - break; - case "hatemodcombat": - MBServerStatics.PLAYER_COMBAT_HATE_MODIFIER = amount; - default: - this.throwbackError(pc, words[0] + " is not a valid AI Command."); - break; - } - } + try { + amount = Integer.valueOf(words[1]); + } catch (NumberFormatException e) { + this.throwbackError(pc, "Failed to parse amount"); + return; + } - @Override - protected String _getHelpString() { - String help = "Modifies Mob AI Statics. Commands:"; - help += "\n AGGRORANGE: Sets the range when a mob will aggro it's target. Aggro range is currently " + MobileFSMManager.AI_BASE_AGGRO_RANGE; - help += "\n DROPAGGRORANGE: Sets the range when a mob will drop aggro from it's target. Drop aggro range is currently " + MobileFSMManager.AI_DROP_AGGRO_RANGE; - help += "\n PATROLDIVISOR: Sets the Patrol Divisor for Mob AI. Setting this will give a 1/[amount] chance to parol the area. Patrol Chance is currently 1/" + MobileFSMManager.AI_PATROL_DIVISOR; - help += "\n PULSE: sets how often to run mob's AI. Measured in MS. Pulse is currently " + MobileFSMManager.AI_PULSE_MOB_THRESHOLD + "ms."; - help += "\n SLEEPTHREAD: Sets how long to sleep the AI for ALL mobs.Thread sleep is currently " + MobileFSMManager.AI_THREAD_SLEEP + "ms."; - help += "\n RECALLRANGE: Sets the range of a mob to recall back to it's bind location. Recall range is currently " + MobileFSMManager.AI_RECALL_RANGE; - help += "\n POWERDIVISOR: Sets the Power Divisor for Mob AI.Setting this will give a 1/[amount] chance to use power on a player. Power Divisor is currently " + MobileFSMManager.AI_POWER_DIVISOR; - help += "\n LOSEHATE: Sets the amount per second to reduce hate amount for player while they are idle. Hate Delimiter is currently " + MBServerStatics.PLAYER_HATE_DELIMITER; - help += "\n HATEMODCOMBAT: sets the modifier for Hate value for Combat. Hate Value is `Damage *[HATEMODCOMBAT]`.Hate Mod Combat is currently " + MBServerStatics.PLAYER_COMBAT_HATE_MODIFIER; + switch (words[0]) { + case "angle": + float angle = Float.parseFloat(words[1]); + + MobileFSMManager.AI_MAX_ANGLE = angle; + break; + case "aggrorange": + MobileFSMManager.AI_BASE_AGGRO_RANGE = amount; + DbManager.MobBaseQueries.UPDATE_AI_DEFAULTS(); + this.throwbackInfo(pc, "Aggro Range is now set to " + amount); + break; + case "dropaggrorange": + MobileFSMManager.AI_DROP_AGGRO_RANGE = amount; + DbManager.MobBaseQueries.UPDATE_AI_DEFAULTS(); + this.throwbackInfo(pc, "Drop Aggro Range is now set to " + amount); + break; + case "patroldivisor": + MobileFSMManager.AI_PATROL_DIVISOR = amount; + DbManager.MobBaseQueries.UPDATE_AI_DEFAULTS(); + this.throwbackInfo(pc, "Patrol Chance is now set to " + amount); + break; + case "pulse": + if (amount < 500) { + this.throwbackError(pc, "pulse amount must be greather than 500 to execute."); + return; + } + MobileFSMManager.AI_PULSE_MOB_THRESHOLD = amount; + this.throwbackInfo(pc, "Pulse is now set to " + amount); + break; + case "sleepthread": + if (amount < 500) { + this.throwbackError(pc, "sleep amount must be greather than 500 to execute."); + return; + } + MobileFSMManager.AI_THREAD_SLEEP = amount; + this.throwbackInfo(pc, "Thread Sleep is now set to " + amount); + break; + case "recallrange": + MobileFSMManager.AI_RECALL_RANGE = amount; + DbManager.MobBaseQueries.UPDATE_AI_DEFAULTS(); + this.throwbackInfo(pc, "Recall Range is now set to " + amount); + break; + case "powerdivisor": + MobileFSMManager.AI_POWER_DIVISOR = amount; + DbManager.MobBaseQueries.UPDATE_AI_DEFAULTS(); + this.throwbackInfo(pc, "Power Divisor is now set to " + amount); + break; + case "losehate": + MBServerStatics.PLAYER_HATE_DELIMITER = amount; + break; + case "hatemodcombat": + MBServerStatics.PLAYER_COMBAT_HATE_MODIFIER = amount; + default: + this.throwbackError(pc, words[0] + " is not a valid AI Command."); + break; + } + } - return help; - } + @Override + protected String _getHelpString() { + String help = "Modifies Mob AI Statics. Commands:"; + help += "\n AGGRORANGE: Sets the range when a mob will aggro it's target. Aggro range is currently " + MobileFSMManager.AI_BASE_AGGRO_RANGE; + help += "\n DROPAGGRORANGE: Sets the range when a mob will drop aggro from it's target. Drop aggro range is currently " + MobileFSMManager.AI_DROP_AGGRO_RANGE; + help += "\n PATROLDIVISOR: Sets the Patrol Divisor for Mob AI. Setting this will give a 1/[amount] chance to parol the area. Patrol Chance is currently 1/" + MobileFSMManager.AI_PATROL_DIVISOR; + help += "\n PULSE: sets how often to run mob's AI. Measured in MS. Pulse is currently " + MobileFSMManager.AI_PULSE_MOB_THRESHOLD + "ms."; + help += "\n SLEEPTHREAD: Sets how long to sleep the AI for ALL mobs.Thread sleep is currently " + MobileFSMManager.AI_THREAD_SLEEP + "ms."; + help += "\n RECALLRANGE: Sets the range of a mob to recall back to it's bind location. Recall range is currently " + MobileFSMManager.AI_RECALL_RANGE; + help += "\n POWERDIVISOR: Sets the Power Divisor for Mob AI.Setting this will give a 1/[amount] chance to use power on a player. Power Divisor is currently " + MobileFSMManager.AI_POWER_DIVISOR; + help += "\n LOSEHATE: Sets the amount per second to reduce hate amount for player while they are idle. Hate Delimiter is currently " + MBServerStatics.PLAYER_HATE_DELIMITER; + help += "\n HATEMODCOMBAT: sets the modifier for Hate value for Combat. Hate Value is `Damage *[HATEMODCOMBAT]`.Hate Mod Combat is currently " + MBServerStatics.PLAYER_COMBAT_HATE_MODIFIER; - @Override - protected String _getUsageString() { - String usage = "' /setai `command` `amount` `"; - usage += '\n' + _getHelpString(); - return usage; - } + return help; + } + + @Override + protected String _getUsageString() { + String usage = "' /setai `command` `amount` `"; + usage += '\n' + _getHelpString(); + return usage; + } } diff --git a/src/engine/devcmd/cmds/SetAdminRuneCmd.java b/src/engine/devcmd/cmds/SetAdminRuneCmd.java index 039a0b91..f8df7016 100644 --- a/src/engine/devcmd/cmds/SetAdminRuneCmd.java +++ b/src/engine/devcmd/cmds/SetAdminRuneCmd.java @@ -17,70 +17,68 @@ import engine.objects.CharacterRune; import engine.objects.PlayerCharacter; /** - * * @author Eighty - * */ public class SetAdminRuneCmd extends AbstractDevCmd { - public SetAdminRuneCmd() { + public SetAdminRuneCmd() { super("setadminrune"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - int runeID = 0; - boolean add = true; - try { - runeID = Integer.parseInt(args[0]); - if (args.length > 1) - add = (args[1].toLowerCase().equals("false")) ? false : true; - } catch (NumberFormatException e) { - this.sendUsage(pcSender); - return; - } - if (runeID < 2901 || runeID > 2911) { - throwbackError(pcSender, - "Invalid setrune Command. must specify an ID between 2901 and 2911."); - return; - } + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] args, + AbstractGameObject target) { + int runeID = 0; + boolean add = true; + try { + runeID = Integer.parseInt(args[0]); + if (args.length > 1) + add = (args[1].toLowerCase().equals("false")) ? false : true; + } catch (NumberFormatException e) { + this.sendUsage(pcSender); + return; + } + if (runeID < 2901 || runeID > 2911) { + throwbackError(pcSender, + "Invalid setrune Command. must specify an ID between 2901 and 2911."); + return; + } - if(!(target instanceof PlayerCharacter)) { - target = pcSender; - } + if (!(target instanceof PlayerCharacter)) { + target = pcSender; + } - boolean worked = false; - if (add) { - worked = CharacterRune.grantRune((PlayerCharacter) target, runeID); - if (worked) - ChatManager.chatSayInfo(pcSender, - "rune of ID " + runeID + " added"); - else - throwbackError(pcSender, "Failed to add the rune of type " - + runeID); - } else { - worked = CharacterRune.removeRune((PlayerCharacter) target, runeID); - if (worked) { - ChatManager.chatSayInfo(pcSender, - "rune of ID " + runeID + " removed"); - InterestManager.reloadCharacter(pcSender); - } else - throwbackError(pcSender, "Failed to remove the rune of type " - + runeID); - } - this.setTarget(target); //for logging + boolean worked = false; + if (add) { + worked = CharacterRune.grantRune((PlayerCharacter) target, runeID); + if (worked) + ChatManager.chatSayInfo(pcSender, + "rune of ID " + runeID + " added"); + else + throwbackError(pcSender, "Failed to add the rune of type " + + runeID); + } else { + worked = CharacterRune.removeRune((PlayerCharacter) target, runeID); + if (worked) { + ChatManager.chatSayInfo(pcSender, + "rune of ID " + runeID + " removed"); + InterestManager.reloadCharacter(pcSender); + } else + throwbackError(pcSender, "Failed to remove the rune of type " + + runeID); + } + this.setTarget(target); //for logging - } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /setrune runeID [true/false]'"; - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Grant or remove the rune with the specified runeID"; - } + } } diff --git a/src/engine/devcmd/cmds/SetBaneActiveCmd.java b/src/engine/devcmd/cmds/SetBaneActiveCmd.java index 1dabfc7d..eb24655b 100644 --- a/src/engine/devcmd/cmds/SetBaneActiveCmd.java +++ b/src/engine/devcmd/cmds/SetBaneActiveCmd.java @@ -15,66 +15,65 @@ import engine.objects.*; /** * @author Eighty - * */ public class SetBaneActiveCmd extends AbstractDevCmd { - public SetBaneActiveCmd() { + public SetBaneActiveCmd() { super("setbaneactive"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - if (words.length != 1) { - this.sendUsage(pc); - return; - } - - boolean setActive = false; - if (words[0].equals("true")) - setActive = true; - - Zone zone = ZoneManager.findSmallestZone(pc.getLoc()); - - if (zone == null) { - throwbackError(pc, "Unable to find the zone you're in."); - return; - } - - if (!zone.isPlayerCity()) { - throwbackError(pc, "This is not a player city."); - return; - } - - City city = City.getCity(zone.getPlayerCityUUID()); - if (city == null) { - throwbackError(pc, "Unable to find the city associated with this zone."); - return; - } - - Bane bane = city.getBane(); - if (bane == null) { - throwbackError(pc, "Could not find bane to modify."); - return; - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + if (words.length != 1) { + this.sendUsage(pc); + return; + } + + boolean setActive = false; + if (words[0].equals("true")) + setActive = true; + + Zone zone = ZoneManager.findSmallestZone(pc.getLoc()); + + if (zone == null) { + throwbackError(pc, "Unable to find the zone you're in."); + return; + } + + if (!zone.isPlayerCity()) { + throwbackError(pc, "This is not a player city."); + return; + } + + City city = City.getCity(zone.getPlayerCityUUID()); + if (city == null) { + throwbackError(pc, "Unable to find the city associated with this zone."); + return; + } + + Bane bane = city.getBane(); + if (bane == null) { + throwbackError(pc, "Could not find bane to modify."); + return; + } bane.getCity().protectionEnforced = !setActive; - if (setActive) - throwbackInfo(pc, "The bane has been set active."); - else - throwbackInfo(pc, "The bane has been set inactive."); - } + if (setActive) + throwbackInfo(pc, "The bane has been set active."); + else + throwbackInfo(pc, "The bane has been set inactive."); + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Sets a bane active or deactivates a bane."; - } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "'./setbaneactive true|false'"; - } + } } diff --git a/src/engine/devcmd/cmds/SetBaseClassCmd.java b/src/engine/devcmd/cmds/SetBaseClassCmd.java index 0c589c7a..be99f8de 100644 --- a/src/engine/devcmd/cmds/SetBaseClassCmd.java +++ b/src/engine/devcmd/cmds/SetBaseClassCmd.java @@ -17,48 +17,48 @@ import engine.objects.PlayerCharacter; public class SetBaseClassCmd extends AbstractDevCmd { - public SetBaseClassCmd() { + public SetBaseClassCmd() { super("setBaseClass"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - // Arg Count Check - if (words.length != 1) { - this.sendUsage(pc); - return; - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + // Arg Count Check + if (words.length != 1) { + this.sendUsage(pc); + return; + } - int classID = 0; - try { - classID = Integer.parseInt(words[0]); - } catch (Exception e) { - throwbackError(pc, - "Invalid setBaseClass Command. must specify an ID between 2500 and 2503."); - return; - } - if (classID < 2500 || classID > 2503) { - throwbackError(pc, - "Invalid setBaseClass Command. must specify an ID between 2500 and 2503."); - return; - } - pc.setBaseClass(classID); - this.setTarget(pc); //for logging - ChatManager.chatSayInfo(pc, - "BaseClass changed to " + classID); - InterestManager.reloadCharacter(pc); + int classID = 0; + try { + classID = Integer.parseInt(words[0]); + } catch (Exception e) { + throwbackError(pc, + "Invalid setBaseClass Command. must specify an ID between 2500 and 2503."); + return; + } + if (classID < 2500 || classID > 2503) { + throwbackError(pc, + "Invalid setBaseClass Command. must specify an ID between 2500 and 2503."); + return; + } + pc.setBaseClass(classID); + this.setTarget(pc); //for logging + ChatManager.chatSayInfo(pc, + "BaseClass changed to " + classID); + InterestManager.reloadCharacter(pc); - } + } - @Override - protected String _getHelpString() { - return "Sets your character's BaseClass to 'id'"; - } + @Override + protected String _getHelpString() { + return "Sets your character's BaseClass to 'id'"; + } - @Override - protected String _getUsageString() { - return "' /setBaseClass id'"; - } + @Override + protected String _getUsageString() { + return "' /setBaseClass id'"; + } } diff --git a/src/engine/devcmd/cmds/SetBuildingAltitudeCmd.java b/src/engine/devcmd/cmds/SetBuildingAltitudeCmd.java index 441aec15..48386d00 100644 --- a/src/engine/devcmd/cmds/SetBuildingAltitudeCmd.java +++ b/src/engine/devcmd/cmds/SetBuildingAltitudeCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.Enum.GameObjectType; @@ -22,7 +21,7 @@ import engine.objects.PlayerCharacter; public class SetBuildingAltitudeCmd extends AbstractDevCmd { - public SetBuildingAltitudeCmd() { + public SetBuildingAltitudeCmd() { super("setbuildingaltitude"); this.addCmdString("buildingaltitude"); } @@ -52,56 +51,56 @@ public class SetBuildingAltitudeCmd extends AbstractDevCmd { } @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - // Arg Count Check - if (words.length != 1) { - this.sendUsage(pc); - return; - } + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + // Arg Count Check + if (words.length != 1) { + this.sendUsage(pc); + return; + } - if (target.getObjectType() != GameObjectType.Building){ - this.sendUsage(pc); - return; - } + if (target.getObjectType() != GameObjectType.Building) { + this.sendUsage(pc); + return; + } - Building targetBuilding = (Building)target; + Building targetBuilding = (Building) target; - float altitude = 0; - try { - altitude = Float.parseFloat(words[0]); + float altitude = 0; + try { + altitude = Float.parseFloat(words[0]); - if (!UpdateBuildingAltitude(targetBuilding, targetBuilding.getStatAlt() + altitude)){ - this.throwbackError(pc, "Failed to update building altitude"); - return; - } + if (!UpdateBuildingAltitude(targetBuilding, targetBuilding.getStatAlt() + altitude)) { + this.throwbackError(pc, "Failed to update building altitude"); + return; + } - WorldGrid.updateObject(targetBuilding); + WorldGrid.updateObject(targetBuilding); - this.setTarget(pc); //for logging + this.setTarget(pc); //for logging - // Update all surrounding clients. + // Update all surrounding clients. - } catch (NumberFormatException e) { - this.throwbackError(pc, "Supplied data: " + words[0] - + " failed to parse to an Integer."); - } catch (Exception e) { - this.throwbackError(pc, - "An unknown exception occurred while attempting to setSlot to " - + words[0]); - } - } + } catch (NumberFormatException e) { + this.throwbackError(pc, "Supplied data: " + words[0] + + " failed to parse to an Integer."); + } catch (Exception e) { + this.throwbackError(pc, + "An unknown exception occurred while attempting to setSlot to " + + words[0]); + } + } - @Override - protected String _getHelpString() { - return "Sets slot position for an NPC to 'slot'"; - } + @Override + protected String _getHelpString() { + return "Sets slot position for an NPC to 'slot'"; + } - @Override - protected String _getUsageString() { - return "' /changeslot slot'"; - } + @Override + protected String _getUsageString() { + return "' /changeslot slot'"; + } } diff --git a/src/engine/devcmd/cmds/SetForceRenameCityCmd.java b/src/engine/devcmd/cmds/SetForceRenameCityCmd.java index 6e592155..3fded48b 100644 --- a/src/engine/devcmd/cmds/SetForceRenameCityCmd.java +++ b/src/engine/devcmd/cmds/SetForceRenameCityCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.devcmd.AbstractDevCmd; @@ -20,35 +19,35 @@ import engine.objects.Zone; public class SetForceRenameCityCmd extends AbstractDevCmd { - public SetForceRenameCityCmd() { + public SetForceRenameCityCmd() { super("forcerename"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - - Zone zone = ZoneManager.findSmallestZone(pc.getLoc()); - if (zone == null) - return; - boolean rename = words[0].equalsIgnoreCase("true") ? true : false; - if (zone.getPlayerCityUUID() == 0) - return; - City city = City.getCity(zone.getPlayerCityUUID()); - if (city == null) - return; - city.setForceRename(rename); - - } - - @Override - protected String _getHelpString() { - return "Temporarily Changes SubRace"; - } - - @Override - protected String _getUsageString() { - return "' /subrace mobBaseID"; - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + + Zone zone = ZoneManager.findSmallestZone(pc.getLoc()); + if (zone == null) + return; + boolean rename = words[0].equalsIgnoreCase("true") ? true : false; + if (zone.getPlayerCityUUID() == 0) + return; + City city = City.getCity(zone.getPlayerCityUUID()); + if (city == null) + return; + city.setForceRename(rename); + + } + + @Override + protected String _getHelpString() { + return "Temporarily Changes SubRace"; + } + + @Override + protected String _getUsageString() { + return "' /subrace mobBaseID"; + } } diff --git a/src/engine/devcmd/cmds/SetGuildCmd.java b/src/engine/devcmd/cmds/SetGuildCmd.java index b46282ec..d869081b 100644 --- a/src/engine/devcmd/cmds/SetGuildCmd.java +++ b/src/engine/devcmd/cmds/SetGuildCmd.java @@ -10,96 +10,94 @@ import engine.objects.NPC; import engine.objects.PlayerCharacter; /** - * - * @author - * Dev command to set the guild of targeted npc. + * @author Dev command to set the guild of targeted npc. * Argument is a valid guild UID */ public class SetGuildCmd extends AbstractDevCmd { - - public SetGuildCmd() { + + public SetGuildCmd() { super("setguild"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] args, + AbstractGameObject target) { NPC targetNPC; Guild targetGuild; - - if(validateUserInput(pcSender, target, args) == false) { - this.sendUsage(pcSender); - return; - } - + + if (validateUserInput(pcSender, target, args) == false) { + this.sendUsage(pcSender); + return; + } + // Valid arguments, attempt to set guild of NPC. - + targetNPC = getTargetAsNPC(pcSender); targetGuild = Guild.getGuild(Integer.parseInt(args[0])); - + DbManager.NPCQueries.SET_PROPERTY(targetNPC, "npc_guildID", args[0]); targetNPC.setGuild(targetGuild); - + // Refresh loaded game object - + WorldGrid.updateObject(targetNPC, pcSender); - - } - @Override - protected String _getUsageString() { + } + + @Override + protected String _getUsageString() { return "' /setguild [UID]"; - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Assigns NPC to a given guild"; - } - - private boolean validateUserInput(PlayerCharacter pcSender, AbstractGameObject currTarget, String[] userInput) { - + } + + private boolean validateUserInput(PlayerCharacter pcSender, AbstractGameObject currTarget, String[] userInput) { + Guild tempGuild; - + // Incorrect number of arguments - + if (userInput.length != 1) - return false; + return false; // No target - - if (currTarget == null) { - throwbackError(pcSender, "Requires an NPC be targeted"); - return false; - } - + + if (currTarget == null) { + throwbackError(pcSender, "Requires an NPC be targeted"); + return false; + } + // Target must be an NPC - - if (currTarget.getObjectType() != GameObjectType.NPC) { - throwbackError(pcSender, "Invalid object. Must be an NPC"); - return false; - } - + + if (currTarget.getObjectType() != GameObjectType.NPC) { + throwbackError(pcSender, "Invalid object. Must be an NPC"); + return false; + } + // Argument must parse as a int. - - try { - Integer.parseInt(userInput[0]); } - catch (NumberFormatException | NullPointerException e) { - return false; + + try { + Integer.parseInt(userInput[0]); + } catch (NumberFormatException | NullPointerException e) { + return false; } - - // Argument must return a valid guild - - tempGuild = Guild.getGuild(Integer.parseInt(userInput[0])); - - if (tempGuild == null) { - throwbackError(pcSender, "Invalid Guild UID"); - return false; - } - - + + // Argument must return a valid guild + + tempGuild = Guild.getGuild(Integer.parseInt(userInput[0])); + + if (tempGuild == null) { + throwbackError(pcSender, "Invalid Guild UID"); + return false; + } + + return true; -} + } } diff --git a/src/engine/devcmd/cmds/SetHealthCmd.java b/src/engine/devcmd/cmds/SetHealthCmd.java index 81ef3064..3ee2763b 100644 --- a/src/engine/devcmd/cmds/SetHealthCmd.java +++ b/src/engine/devcmd/cmds/SetHealthCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.Enum.DispatchChannel; @@ -20,48 +19,48 @@ import engine.server.MBServerStatics; public class SetHealthCmd extends AbstractDevCmd { - public SetHealthCmd() { + public SetHealthCmd() { super("setHealth"); this.addCmdString("health"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - // Arg Count Check - if (words.length != 1) { - this.sendUsage(pc); - return; - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + // Arg Count Check + if (words.length != 1) { + this.sendUsage(pc); + return; + } - float amount = 0.0f; - try { - amount = Float.parseFloat(words[0]); - pc.modifyHealth(amount, pc, false); - this.setTarget(pc); //for logging + float amount = 0.0f; + try { + amount = Float.parseFloat(words[0]); + pc.modifyHealth(amount, pc, false); + this.setTarget(pc); //for logging - // Update all surrounding clients. - TargetedActionMsg cmm = new TargetedActionMsg(pc); - DispatchMessage.dispatchMsgToInterestArea(pc, cmm, DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + // Update all surrounding clients. + TargetedActionMsg cmm = new TargetedActionMsg(pc); + DispatchMessage.dispatchMsgToInterestArea(pc, cmm, DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - } catch (NumberFormatException e) { - this.throwbackError(pc, "Supplied data: " + words[0] - + " failed to parse to a Float."); - } catch (Exception e) { - this.throwbackError(pc, - "An unknown exception occurred while attempting to setHealth to " - + words[0]); - } - } + } catch (NumberFormatException e) { + this.throwbackError(pc, "Supplied data: " + words[0] + + " failed to parse to a Float."); + } catch (Exception e) { + this.throwbackError(pc, + "An unknown exception occurred while attempting to setHealth to " + + words[0]); + } + } - @Override - protected String _getHelpString() { - return "Sets your character's health to 'amount'"; - } + @Override + protected String _getHelpString() { + return "Sets your character's health to 'amount'"; + } - @Override - protected String _getUsageString() { - return "' /setHealth amount'"; - } + @Override + protected String _getUsageString() { + return "' /setHealth amount'"; + } } diff --git a/src/engine/devcmd/cmds/SetInvulCmd.java b/src/engine/devcmd/cmds/SetInvulCmd.java index a9f952a7..f26df9e4 100644 --- a/src/engine/devcmd/cmds/SetInvulCmd.java +++ b/src/engine/devcmd/cmds/SetInvulCmd.java @@ -20,72 +20,73 @@ import engine.objects.PlayerCharacter; public class SetInvulCmd extends AbstractDevCmd { - public SetInvulCmd() { + public SetInvulCmd() { super("setinvul"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] words, - AbstractGameObject target) { - if (pcSender == null) return; - - if (words.length != 1) { - this.sendUsage(pcSender); - return; - } - - boolean invul; - switch (words[0].toLowerCase()) { - case "true": - invul = true; - break; - case "false": - invul = false; - break; - default: - this.sendUsage(pcSender); - return; - } - - if (target == null || !(target instanceof Building)) { - throwbackError(pcSender, "No building targeted"); - return; - } - - Building b = (Building) target; - - // if strucutre is a TOL then we're modifying the protection - // status of the entire city - - if ( (b.getBlueprint() != null) && - (b.getBlueprint().getBuildingGroup().equals(Enum.BuildingGroup.TOL))) { - - City city; - - city = b.getCity(); - city.protectionEnforced = !city.protectionEnforced; - throwbackInfo(pcSender, "City protection contracts enforced: " + city.protectionEnforced); - return; - } - - if (invul) { - - b.setProtectionState(ProtectionState.PROTECTED); - throwbackInfo(pcSender, "The targetted building is now invulnerable."); - return; - } - b.setProtectionState(ProtectionState.NONE); - throwbackInfo(pcSender, "The targetted building is no longer invulernable."); - } - - @Override - protected String _getUsageString() { - return "'./setInvul true|false'"; - } - - @Override - protected String _getHelpString() { - return "Turns invulernability on or off for building"; - } + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] words, + AbstractGameObject target) { + if (pcSender == null) + return; + + if (words.length != 1) { + this.sendUsage(pcSender); + return; + } + + boolean invul; + switch (words[0].toLowerCase()) { + case "true": + invul = true; + break; + case "false": + invul = false; + break; + default: + this.sendUsage(pcSender); + return; + } + + if (target == null || !(target instanceof Building)) { + throwbackError(pcSender, "No building targeted"); + return; + } + + Building b = (Building) target; + + // if strucutre is a TOL then we're modifying the protection + // status of the entire city + + if ((b.getBlueprint() != null) && + (b.getBlueprint().getBuildingGroup().equals(Enum.BuildingGroup.TOL))) { + + City city; + + city = b.getCity(); + city.protectionEnforced = !city.protectionEnforced; + throwbackInfo(pcSender, "City protection contracts enforced: " + city.protectionEnforced); + return; + } + + if (invul) { + + b.setProtectionState(ProtectionState.PROTECTED); + throwbackInfo(pcSender, "The targetted building is now invulnerable."); + return; + } + b.setProtectionState(ProtectionState.NONE); + throwbackInfo(pcSender, "The targetted building is no longer invulernable."); + } + + @Override + protected String _getUsageString() { + return "'./setInvul true|false'"; + } + + @Override + protected String _getHelpString() { + return "Turns invulernability on or off for building"; + } } diff --git a/src/engine/devcmd/cmds/SetLevelCmd.java b/src/engine/devcmd/cmds/SetLevelCmd.java index aabedc40..47be4ff6 100644 --- a/src/engine/devcmd/cmds/SetLevelCmd.java +++ b/src/engine/devcmd/cmds/SetLevelCmd.java @@ -17,57 +17,57 @@ import engine.objects.PlayerCharacter; public class SetLevelCmd extends AbstractDevCmd { - public SetLevelCmd() { - super("setLevel"); - } + public SetLevelCmd() { + super("setLevel"); + } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - // Arg Count Check - if (words.length != 1) { - this.sendUsage(pc); - return; - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + // Arg Count Check + if (words.length != 1) { + this.sendUsage(pc); + return; + } - PlayerCharacter tar; - if (target != null) { - if (target instanceof PlayerCharacter) - tar = (PlayerCharacter) target; - else - tar = pc; - } else - tar = pc; + PlayerCharacter tar; + if (target != null) { + if (target instanceof PlayerCharacter) + tar = (PlayerCharacter) target; + else + tar = pc; + } else + tar = pc; - int level = 0; - try { - level = Integer.parseInt(words[0]); - } catch (NumberFormatException e) { - this.sendUsage(pc); - return; - } - if (level < 1 || level > 75) { - this.sendHelp(pc); - return; - } + int level = 0; + try { + level = Integer.parseInt(words[0]); + } catch (NumberFormatException e) { + this.sendUsage(pc); + return; + } + if (level < 1 || level > 75) { + this.sendHelp(pc); + return; + } - if (level > 10 && pc.getPromotionClass() == null) - level = 10; + if (level > 10 && pc.getPromotionClass() == null) + level = 10; - tar.setLevel((short) level); - this.setTarget(tar); //for logging - ChatManager.chatSayInfo(pc, tar.getFirstName() + " level changed to " + level); - InterestManager.reloadCharacter(tar); - } + tar.setLevel((short) level); + this.setTarget(tar); //for logging + ChatManager.chatSayInfo(pc, tar.getFirstName() + " level changed to " + level); + InterestManager.reloadCharacter(tar); + } - @Override - protected String _getHelpString() { - return "Sets your character's level to 'amount'. 'amount' must be between 1-75"; - } + @Override + protected String _getHelpString() { + return "Sets your character's level to 'amount'. 'amount' must be between 1-75"; + } - @Override - protected String _getUsageString() { - return "' /setLevel amount'"; - } + @Override + protected String _getUsageString() { + return "' /setLevel amount'"; + } } diff --git a/src/engine/devcmd/cmds/SetMaintCmd.java b/src/engine/devcmd/cmds/SetMaintCmd.java index e81832e4..85346322 100644 --- a/src/engine/devcmd/cmds/SetMaintCmd.java +++ b/src/engine/devcmd/cmds/SetMaintCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.Enum; @@ -22,40 +21,40 @@ import java.time.LocalDateTime; public class SetMaintCmd extends AbstractDevCmd { - public SetMaintCmd() { + public SetMaintCmd() { super("setMaint"); this.addCmdString("setmaint"); } - @Override - protected void _doCmd(PlayerCharacter player, String[] words, - AbstractGameObject target) { + @Override + protected void _doCmd(PlayerCharacter player, String[] words, + AbstractGameObject target) { - if (!target.getObjectType().equals(Enum.GameObjectType.Building)) { - ChatManager.chatSayInfo(player, "Target is not a valid building"); - return; - } + if (!target.getObjectType().equals(Enum.GameObjectType.Building)) { + ChatManager.chatSayInfo(player, "Target is not a valid building"); + return; + } - Building targetBuilding = (Building)target; + Building targetBuilding = (Building) target; - if (targetBuilding.getProtectionState().equals(Enum.ProtectionState.NPC)) { - ChatManager.chatSayInfo(player, "Target is not a valid building"); - return; - } + if (targetBuilding.getProtectionState().equals(Enum.ProtectionState.NPC)) { + ChatManager.chatSayInfo(player, "Target is not a valid building"); + return; + } - MaintenanceManager.setMaintDateTime(targetBuilding, LocalDateTime.now().minusDays(1).withHour(13).withMinute(0).withSecond(0).withNano(0)); - ChatManager.chatSayInfo(player, "Maint will run for UUID: " + targetBuilding.getObjectUUID()); - } + MaintenanceManager.setMaintDateTime(targetBuilding, LocalDateTime.now().minusDays(1).withHour(13).withMinute(0).withSecond(0).withNano(0)); + ChatManager.chatSayInfo(player, "Maint will run for UUID: " + targetBuilding.getObjectUUID()); + } - @Override - protected String _getHelpString() { - return "Sets the Rank of either the targets object or the object specified by ID."; - } + @Override + protected String _getHelpString() { + return "Sets the Rank of either the targets object or the object specified by ID."; + } - @Override - protected String _getUsageString() { - return "' /setrank ID rank' || ' /setrank rank' || ' /rank ID rank' || ' /rank rank'"; - } + @Override + protected String _getUsageString() { + return "' /setrank ID rank' || ' /setrank rank' || ' /rank ID rank' || ' /rank rank'"; + } } diff --git a/src/engine/devcmd/cmds/SetManaCmd.java b/src/engine/devcmd/cmds/SetManaCmd.java index 47e059a3..3988e2a3 100644 --- a/src/engine/devcmd/cmds/SetManaCmd.java +++ b/src/engine/devcmd/cmds/SetManaCmd.java @@ -9,48 +9,48 @@ import engine.server.MBServerStatics; public class SetManaCmd extends AbstractDevCmd { - public SetManaCmd() { + public SetManaCmd() { super("setMana"); this.addCmdString("mana"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - // Arg Count Check - if (words.length != 1) { - this.sendUsage(pc); - return; - } - - float amount = 0.0f; - try { - amount = Float.parseFloat(words[0]); - pc.setMana(amount, pc); - this.setTarget(pc); //for logging - - //Update all surrounding clients. - NOT for Mana? - TargetedActionMsg cmm = new TargetedActionMsg(pc); - DispatchMessage.dispatchMsgToInterestArea(pc, cmm, engine.Enum.DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - - } catch (NumberFormatException e) { - this.throwbackError(pc, "Supplied data: " + words[0] - + " failed to parse to a Float."); - } catch (Exception e) { - this.throwbackError(pc, - "An unknown exception occurred while attempting to setMana to " - + words[0]); - } - } - - @Override - protected String _getHelpString() { - return "Sets your character's Mana to 'amount'"; - } - - @Override - protected String _getUsageString() { - return "' /setMana amount'"; - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + // Arg Count Check + if (words.length != 1) { + this.sendUsage(pc); + return; + } + + float amount = 0.0f; + try { + amount = Float.parseFloat(words[0]); + pc.setMana(amount, pc); + this.setTarget(pc); //for logging + + //Update all surrounding clients. - NOT for Mana? + TargetedActionMsg cmm = new TargetedActionMsg(pc); + DispatchMessage.dispatchMsgToInterestArea(pc, cmm, engine.Enum.DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + + } catch (NumberFormatException e) { + this.throwbackError(pc, "Supplied data: " + words[0] + + " failed to parse to a Float."); + } catch (Exception e) { + this.throwbackError(pc, + "An unknown exception occurred while attempting to setMana to " + + words[0]); + } + } + + @Override + protected String _getHelpString() { + return "Sets your character's Mana to 'amount'"; + } + + @Override + protected String _getUsageString() { + return "' /setMana amount'"; + } } diff --git a/src/engine/devcmd/cmds/SetNpcEquipSetCmd.java b/src/engine/devcmd/cmds/SetNpcEquipSetCmd.java index d4b2dd67..844d6613 100644 --- a/src/engine/devcmd/cmds/SetNpcEquipSetCmd.java +++ b/src/engine/devcmd/cmds/SetNpcEquipSetCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.Enum.GameObjectType; @@ -20,119 +19,118 @@ import engine.objects.PlayerCharacter; public class SetNpcEquipSetCmd extends AbstractDevCmd { - public static int lastEquipSetID = 0; - public SetNpcEquipSetCmd() { + public static int lastEquipSetID = 0; + + public SetNpcEquipSetCmd() { super("setEquipSet"); this.addCmdString("equipset"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - // Arg Count Check - if (words.length != 1) { - this.sendUsage(pc); - return; - } - - if (target.getObjectType() != GameObjectType.NPC){ - this.sendUsage(pc); - return; - } - - NPC npc = (NPC)target; + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + // Arg Count Check + if (words.length != 1) { + this.sendUsage(pc); + return; + } - if (words[0].equalsIgnoreCase("next")){ + if (target.getObjectType() != GameObjectType.NPC) { + this.sendUsage(pc); + return; + } - if (SetNpcEquipSetCmd.lastEquipSetID >= 1222) - SetNpcEquipSetCmd.lastEquipSetID = 1; - else - SetNpcEquipSetCmd.lastEquipSetID++; + NPC npc = (NPC) target; - boolean complete = false; + if (words[0].equalsIgnoreCase("next")) { - while (complete == false){ - complete = NPC.UpdateEquipSetID(npc, SetNpcEquipSetCmd.lastEquipSetID); + if (SetNpcEquipSetCmd.lastEquipSetID >= 1222) + SetNpcEquipSetCmd.lastEquipSetID = 1; + else + SetNpcEquipSetCmd.lastEquipSetID++; - if (!complete){ - SetNpcEquipSetCmd.lastEquipSetID++; - if (SetNpcEquipSetCmd.lastEquipSetID >= 1222) - SetNpcEquipSetCmd.lastEquipSetID = 1; - } - } + boolean complete = false; - if (complete){ - npc.equip = MobBase.loadEquipmentSet(npc.getEquipmentSetID()); - WorldGrid.updateObject(npc); - this.throwbackInfo(pc, "Equipment Set Changed to " + SetNpcEquipSetCmd.lastEquipSetID ); - } + while (complete == false) { + complete = NPC.UpdateEquipSetID(npc, SetNpcEquipSetCmd.lastEquipSetID); + if (!complete) { + SetNpcEquipSetCmd.lastEquipSetID++; + if (SetNpcEquipSetCmd.lastEquipSetID >= 1222) + SetNpcEquipSetCmd.lastEquipSetID = 1; + } + } + if (complete) { + npc.equip = MobBase.loadEquipmentSet(npc.getEquipmentSetID()); + WorldGrid.updateObject(npc); + this.throwbackInfo(pc, "Equipment Set Changed to " + SetNpcEquipSetCmd.lastEquipSetID); + } - return; - } - if (words[0].equalsIgnoreCase("last")){ + return; + } - if (SetNpcEquipSetCmd.lastEquipSetID <= 1) - SetNpcEquipSetCmd.lastEquipSetID = 1222; - else - SetNpcEquipSetCmd.lastEquipSetID--; + if (words[0].equalsIgnoreCase("last")) { - boolean complete = false; + if (SetNpcEquipSetCmd.lastEquipSetID <= 1) + SetNpcEquipSetCmd.lastEquipSetID = 1222; + else + SetNpcEquipSetCmd.lastEquipSetID--; - while (complete == false){ - complete = NPC.UpdateEquipSetID(npc, SetNpcEquipSetCmd.lastEquipSetID); + boolean complete = false; - if (!complete){ - SetNpcEquipSetCmd.lastEquipSetID--; - if (SetNpcEquipSetCmd.lastEquipSetID <= 1) - SetNpcEquipSetCmd.lastEquipSetID = 1222; - } + while (complete == false) { + complete = NPC.UpdateEquipSetID(npc, SetNpcEquipSetCmd.lastEquipSetID); - } + if (!complete) { + SetNpcEquipSetCmd.lastEquipSetID--; + if (SetNpcEquipSetCmd.lastEquipSetID <= 1) + SetNpcEquipSetCmd.lastEquipSetID = 1222; + } - if (complete){ - this.throwbackInfo(pc, "Equipment Set Changed to " + SetNpcEquipSetCmd.lastEquipSetID ); - npc.equip = MobBase.loadEquipmentSet(npc.getEquipmentSetID()); - WorldGrid.updateObject(npc); - } + } + if (complete) { + this.throwbackInfo(pc, "Equipment Set Changed to " + SetNpcEquipSetCmd.lastEquipSetID); + npc.equip = MobBase.loadEquipmentSet(npc.getEquipmentSetID()); + WorldGrid.updateObject(npc); + } - return; - } + return; + } - int equipSetID = 0; + int equipSetID = 0; - try{ - equipSetID = Integer.parseInt(words[0]); - }catch(Exception e){ - this.throwbackError(pc, e.getMessage()); - } + try { + equipSetID = Integer.parseInt(words[0]); + } catch (Exception e) { + this.throwbackError(pc, e.getMessage()); + } - if (!NPC.UpdateEquipSetID(npc, equipSetID)){ - this.throwbackError(pc, "Unable to find Equipset for ID " + equipSetID ); - return; - } + if (!NPC.UpdateEquipSetID(npc, equipSetID)) { + this.throwbackError(pc, "Unable to find Equipset for ID " + equipSetID); + return; + } - SetNpcEquipSetCmd.lastEquipSetID = equipSetID; - npc.equip = MobBase.loadEquipmentSet(npc.getEquipmentSetID()); - WorldGrid.updateObject(npc); + SetNpcEquipSetCmd.lastEquipSetID = equipSetID; + npc.equip = MobBase.loadEquipmentSet(npc.getEquipmentSetID()); + WorldGrid.updateObject(npc); - this.throwbackInfo(pc, "Equipment Set Changed to " + equipSetID ); + this.throwbackInfo(pc, "Equipment Set Changed to " + equipSetID); - } + } - @Override - protected String _getHelpString() { - return "Sets slot position for an NPC to 'slot'"; - } + @Override + protected String _getHelpString() { + return "Sets slot position for an NPC to 'slot'"; + } - @Override - protected String _getUsageString() { - return "' /changeslot slot'"; - } + @Override + protected String _getUsageString() { + return "' /changeslot slot'"; + } } diff --git a/src/engine/devcmd/cmds/SetNpcMobbaseCmd.java b/src/engine/devcmd/cmds/SetNpcMobbaseCmd.java index 07002761..4b5c708f 100644 --- a/src/engine/devcmd/cmds/SetNpcMobbaseCmd.java +++ b/src/engine/devcmd/cmds/SetNpcMobbaseCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.Enum.GameObjectType; @@ -20,48 +19,48 @@ import engine.objects.PlayerCharacter; public class SetNpcMobbaseCmd extends AbstractDevCmd { - public SetNpcMobbaseCmd() { + public SetNpcMobbaseCmd() { super("setmobbase"); this.addCmdString("npcmobbase"); } - @Override - protected void _doCmd(PlayerCharacter player, String[] words, - AbstractGameObject target) { - - // Arg Count Check - if (words.length != 1) { - this.sendUsage(player); - return; - } - - if (target.getObjectType() != GameObjectType.NPC){ - this.sendUsage(player); - return; - } - - NPC npc = (NPC)target; - - int mobBaseID = Integer.parseInt(words[0]); - - if (MobBase.getMobBase(mobBaseID) == null){ - this.throwbackError(player, "Cannot find Mobbase for ID " + mobBaseID); - return; - } - NPC.UpdateRaceID(npc, mobBaseID); - - WorldGrid.updateObject(npc); - - } - - @Override - protected String _getHelpString() { - return "Sets mobbase override for an NPC"; - } - - @Override - protected String _getUsageString() { - return "' /setmobbase mobBaseID'"; - } + @Override + protected void _doCmd(PlayerCharacter player, String[] words, + AbstractGameObject target) { + + // Arg Count Check + if (words.length != 1) { + this.sendUsage(player); + return; + } + + if (target.getObjectType() != GameObjectType.NPC) { + this.sendUsage(player); + return; + } + + NPC npc = (NPC) target; + + int mobBaseID = Integer.parseInt(words[0]); + + if (MobBase.getMobBase(mobBaseID) == null) { + this.throwbackError(player, "Cannot find Mobbase for ID " + mobBaseID); + return; + } + NPC.UpdateRaceID(npc, mobBaseID); + + WorldGrid.updateObject(npc); + + } + + @Override + protected String _getHelpString() { + return "Sets mobbase override for an NPC"; + } + + @Override + protected String _getUsageString() { + return "' /setmobbase mobBaseID'"; + } } diff --git a/src/engine/devcmd/cmds/SetNpcNameCmd.java b/src/engine/devcmd/cmds/SetNpcNameCmd.java index 2e05ae2c..d670db67 100644 --- a/src/engine/devcmd/cmds/SetNpcNameCmd.java +++ b/src/engine/devcmd/cmds/SetNpcNameCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.Enum.GameObjectType; @@ -19,44 +18,45 @@ import engine.objects.PlayerCharacter; public class SetNpcNameCmd extends AbstractDevCmd { - public static int lastEquipSetID = 0; - public SetNpcNameCmd() { + public static int lastEquipSetID = 0; + + public SetNpcNameCmd() { super("setNPCName"); this.addCmdString("npcname"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - // Arg Count Check - if (words.length != 1) { - this.sendUsage(pc); - return; - } - - if (target.getObjectType() != GameObjectType.NPC){ - this.sendUsage(pc); - return; - } - - NPC npc = (NPC)target; - - String name = words[0]; - - NPC.UpdateName(npc, name); - - WorldGrid.updateObject(npc); - - } - - @Override - protected String _getHelpString() { - return "Sets slot position for an NPC to 'slot'"; - } - - @Override - protected String _getUsageString() { - return "' /changeslot slot'"; - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + // Arg Count Check + if (words.length != 1) { + this.sendUsage(pc); + return; + } + + if (target.getObjectType() != GameObjectType.NPC) { + this.sendUsage(pc); + return; + } + + NPC npc = (NPC) target; + + String name = words[0]; + + NPC.UpdateName(npc, name); + + WorldGrid.updateObject(npc); + + } + + @Override + protected String _getHelpString() { + return "Sets slot position for an NPC to 'slot'"; + } + + @Override + protected String _getUsageString() { + return "' /changeslot slot'"; + } } diff --git a/src/engine/devcmd/cmds/SetOwnerCmd.java b/src/engine/devcmd/cmds/SetOwnerCmd.java index f07241bf..f7753db2 100644 --- a/src/engine/devcmd/cmds/SetOwnerCmd.java +++ b/src/engine/devcmd/cmds/SetOwnerCmd.java @@ -8,111 +8,110 @@ import engine.objects.*; /** - * - * @author - * Dev command to set the owner of targeted building. + * @author Dev command to set the owner of targeted building. * Argument is a valid guild UID */ public class SetOwnerCmd extends AbstractDevCmd { - Building _targetBuilding = null; - DbObjectType _newOwnerType; - AbstractCharacter outOwner; + Building _targetBuilding = null; + DbObjectType _newOwnerType; + AbstractCharacter outOwner; - public SetOwnerCmd() { + public SetOwnerCmd() { super("setowner"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - - if(validateUserInput(pcSender, target, args) == false) { - this.sendUsage(pcSender); - return; - } - + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] args, + AbstractGameObject target) { + + if (validateUserInput(pcSender, target, args) == false) { + this.sendUsage(pcSender); + return; + } + // Valid arguments, attempt to set owner of Building. - + _targetBuilding = getTargetAsBuilding(pcSender); // if it's a tol change ownership of the city if (_targetBuilding.getBlueprint() != null && - _targetBuilding.getBlueprint().getBuildingGroup().equals(engine.Enum.BuildingGroup.TOL)) { + _targetBuilding.getBlueprint().getBuildingGroup().equals(engine.Enum.BuildingGroup.TOL)) { City city = _targetBuilding.getCity(); if (city != null) { city.claim(outOwner); - return; } + return; + } } _targetBuilding.setOwner(outOwner); - + DbManager.BuildingQueries.SET_PROPERTY(_targetBuilding, "ownerUUID", args[0]); - + _targetBuilding.refreshGuild(); - - } - @Override - protected String _getUsageString() { + } + + @Override + protected String _getUsageString() { return "' /setowner [UID]"; - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Assigns new owner to building"; - } - - private boolean validateUserInput(PlayerCharacter pcSender, AbstractGameObject currTarget, String[] userInput) { - + } + + private boolean validateUserInput(PlayerCharacter pcSender, AbstractGameObject currTarget, String[] userInput) { + // Incorrect number of arguments - + if (userInput.length != 1) - return false; + return false; // No target - - if (currTarget == null) { - throwbackError(pcSender, "Requires a Building to be targeted"); - return false; - } - + + if (currTarget == null) { + throwbackError(pcSender, "Requires a Building to be targeted"); + return false; + } + // Target must be an Building - - if (currTarget.getObjectType() != GameObjectType.Building) { - throwbackError(pcSender, "Invalid target. Must be a Building"); - return false; - } - + + if (currTarget.getObjectType() != GameObjectType.Building) { + throwbackError(pcSender, "Invalid target. Must be a Building"); + return false; + } + // Argument must parse to a long. - - try { - Long.parseLong(userInput[0]); } - catch (NumberFormatException | NullPointerException e) { - return false; + + try { + Long.parseLong(userInput[0]); + } catch (NumberFormatException | NullPointerException e) { + return false; + } + + // Argument must return a valid NPC or PlayerCharacter + + _newOwnerType = DbManager.BuildingQueries.GET_UID_ENUM(Long.parseLong(userInput[0])); + + switch (_newOwnerType) { + case NPC: + outOwner = (AbstractCharacter) DbManager.getObject(GameObjectType.NPC, Integer.parseInt(userInput[0])); + break; + case CHARACTER: + outOwner = (AbstractCharacter) DbManager.getObject(GameObjectType.PlayerCharacter, Integer.parseInt(userInput[0])); + break; + } + + if (outOwner == null) { + throwbackError(pcSender, "Invalid Owner UID"); + return false; } - - // Argument must return a valid NPC or PlayerCharacter - - _newOwnerType = DbManager.BuildingQueries.GET_UID_ENUM(Long.parseLong(userInput[0])); - - switch (_newOwnerType) { - case NPC: - outOwner = (AbstractCharacter)DbManager.getObject(GameObjectType.NPC, Integer.parseInt(userInput[0])); - break; - case CHARACTER: - outOwner = (AbstractCharacter)DbManager.getObject(GameObjectType.PlayerCharacter, Integer.parseInt(userInput[0])); - break; - } - if (outOwner == null) { - throwbackError(pcSender, "Invalid Owner UID"); - return false; - } - return true; -} + } } diff --git a/src/engine/devcmd/cmds/SetPromotionClassCmd.java b/src/engine/devcmd/cmds/SetPromotionClassCmd.java index 88239ab2..f8776786 100644 --- a/src/engine/devcmd/cmds/SetPromotionClassCmd.java +++ b/src/engine/devcmd/cmds/SetPromotionClassCmd.java @@ -13,60 +13,60 @@ import engine.server.MBServerStatics; public class SetPromotionClassCmd extends AbstractDevCmd { - public SetPromotionClassCmd() { + public SetPromotionClassCmd() { super("setPromotionClass"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - // Arg Count Check - if (words.length != 1) { - this.sendUsage(pc); - return; - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + // Arg Count Check + if (words.length != 1) { + this.sendUsage(pc); + return; + } - int classID = 0; - try { - classID = Integer.parseInt(words[0]); - } catch (Exception e) { - throwbackError(pc, - "Invalid setPromotionClass Command. must specify an ID between 2504 and 2526."); - return; - } - if (classID < 2504 || classID > 2526 || classID == 2522) { - throwbackError(pc, - "Invalid setPromotionClass Command. must specify an ID between 2504 and 2526."); - return; - } - pc.setPromotionClass(classID); - ChatManager.chatSayInfo(pc, - "PromotionClass changed to " + classID); - InterestManager.reloadCharacter(pc); - this.setTarget(pc); //for logging + int classID = 0; + try { + classID = Integer.parseInt(words[0]); + } catch (Exception e) { + throwbackError(pc, + "Invalid setPromotionClass Command. must specify an ID between 2504 and 2526."); + return; + } + if (classID < 2504 || classID > 2526 || classID == 2522) { + throwbackError(pc, + "Invalid setPromotionClass Command. must specify an ID between 2504 and 2526."); + return; + } + pc.setPromotionClass(classID); + ChatManager.chatSayInfo(pc, + "PromotionClass changed to " + classID); + InterestManager.reloadCharacter(pc); + this.setTarget(pc); //for logging - // recalculate all bonuses/formulas/skills/powers - pc.recalculate(); + // recalculate all bonuses/formulas/skills/powers + pc.recalculate(); - // send the rune application to the clients + // send the rune application to the clients - PromotionClass promo = pc.getPromotionClass(); - if (promo != null) { - ApplyRuneMsg arm = new ApplyRuneMsg(pc.getObjectType().ordinal(), pc.getObjectUUID(), promo.getObjectUUID(), promo.getObjectType().ordinal(), promo.getObjectUUID(), true); - DispatchMessage.dispatchMsgToInterestArea(pc, arm, DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - } + PromotionClass promo = pc.getPromotionClass(); + if (promo != null) { + ApplyRuneMsg arm = new ApplyRuneMsg(pc.getObjectType().ordinal(), pc.getObjectUUID(), promo.getObjectUUID(), promo.getObjectType().ordinal(), promo.getObjectUUID(), true); + DispatchMessage.dispatchMsgToInterestArea(pc, arm, DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + } - } + } - @Override - protected String _getHelpString() { - return "Sets your character's PromotionClass to 'ID'"; - } + @Override + protected String _getHelpString() { + return "Sets your character's PromotionClass to 'ID'"; + } - @Override - protected String _getUsageString() { - return "' /setPromotionClass id'"; - } + @Override + protected String _getUsageString() { + return "' /setPromotionClass id'"; + } } diff --git a/src/engine/devcmd/cmds/SetRankCmd.java b/src/engine/devcmd/cmds/SetRankCmd.java index 6e7a43a4..614701c4 100644 --- a/src/engine/devcmd/cmds/SetRankCmd.java +++ b/src/engine/devcmd/cmds/SetRankCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.InterestManagement.WorldGrid; @@ -18,125 +17,124 @@ import engine.objects.*; public class SetRankCmd extends AbstractDevCmd { - public SetRankCmd() { - super("setRank"); - this.addCmdString("setrank"); - this.addCmdString("rank"); - } - - @Override - protected void _doCmd(PlayerCharacter player, String[] words, - AbstractGameObject target) { - - int targetRank; - int uuid = 0; - - if (words.length == 2) { - try { - uuid = Integer.parseInt(words[0]); - targetRank = Integer.parseInt(words[1]); - } catch (NumberFormatException e) { - this.sendUsage(player); - return; // NaN - } - } else if (words.length == 1) { - try { - targetRank = Integer.parseInt(words[0]); - } catch (NumberFormatException e) { - this.sendUsage(player); - return; // NaN - } - } else { - this.sendUsage(player); - return; - } - - if (target != null){ - switch(target.getObjectType()){ - case Building: - Building targetBuilding = (Building)target; - Blueprint blueprint = targetBuilding.getBlueprint(); - - if (blueprint == null) { - targetBuilding.setRank(targetRank); - ChatManager.chatSayInfo(player, "Building ranked without blueprint" + targetBuilding.getObjectUUID()); - return; - } - - if (targetRank > blueprint.getMaxRank()) { - throwbackError(player, "Attempt to set Invalid Rank" + targetBuilding.getObjectUUID()); - return; - } - - // Set the current targetRank - int lastMeshID = targetBuilding.getMeshUUID(); - targetBuilding.setRank(targetRank); - - ChatManager.chatSayInfo(player, "Rank set for building with ID " + targetBuilding.getObjectUUID() + " to rank " + targetRank); - break; - case NPC: - NPC toRank = (NPC)target; - toRank.setRank(targetRank * 10); - toRank.setUpgradeDateTime(null); - WorldGrid.updateObject(toRank); - break; - case Mob: - Mob toRankCaptain = (Mob)target; - if (toRankCaptain.getContract() != null){ - toRankCaptain.setRank(targetRank * 10); - Mob.setUpgradeDateTime(toRankCaptain, null); - WorldGrid.updateObject(toRankCaptain); - } - - break; - } - - }else{ - Building targetBuilding = null; - if (uuid != 0) - targetBuilding = BuildingManager.getBuilding(uuid); - - if (targetBuilding == null) { - throwbackError(player, "Unable to find building."); - return; - } - - Blueprint blueprint = targetBuilding.getBlueprint(); - - if (blueprint == null) { - throwbackError(player, "Attempt to rank building without blueprint" + targetBuilding.getObjectUUID()); - return; - } - - if (targetRank > blueprint.getMaxRank()) { - throwbackError(player, "Attempt to set Invalid Rank" + targetBuilding.getObjectUUID()); - return; - } - - // Set the current targetRank - int lastMeshID = targetBuilding.getMeshUUID(); - targetBuilding.setRank(targetRank); - - if (lastMeshID != targetBuilding.getMeshUUID()) - targetBuilding.refresh(true); - else - targetBuilding.refresh(false); - - ChatManager.chatSayInfo(player, "Rank set for building with ID " + targetBuilding.getObjectUUID() + " to rank " + targetRank); - } - - - - } - - @Override - protected String _getHelpString() { - return "Sets the Rank of either the targets object or the object specified by ID."; - } - - @Override - protected String _getUsageString() { - return "' /setrank ID rank' || ' /setrank rank' || ' /rank ID rank' || ' /rank rank'"; - } + public SetRankCmd() { + super("setRank"); + this.addCmdString("setrank"); + this.addCmdString("rank"); + } + + @Override + protected void _doCmd(PlayerCharacter player, String[] words, + AbstractGameObject target) { + + int targetRank; + int uuid = 0; + + if (words.length == 2) { + try { + uuid = Integer.parseInt(words[0]); + targetRank = Integer.parseInt(words[1]); + } catch (NumberFormatException e) { + this.sendUsage(player); + return; // NaN + } + } else if (words.length == 1) { + try { + targetRank = Integer.parseInt(words[0]); + } catch (NumberFormatException e) { + this.sendUsage(player); + return; // NaN + } + } else { + this.sendUsage(player); + return; + } + + if (target != null) { + switch (target.getObjectType()) { + case Building: + Building targetBuilding = (Building) target; + Blueprint blueprint = targetBuilding.getBlueprint(); + + if (blueprint == null) { + targetBuilding.setRank(targetRank); + ChatManager.chatSayInfo(player, "Building ranked without blueprint" + targetBuilding.getObjectUUID()); + return; + } + + if (targetRank > blueprint.getMaxRank()) { + throwbackError(player, "Attempt to set Invalid Rank" + targetBuilding.getObjectUUID()); + return; + } + + // Set the current targetRank + int lastMeshID = targetBuilding.getMeshUUID(); + targetBuilding.setRank(targetRank); + + ChatManager.chatSayInfo(player, "Rank set for building with ID " + targetBuilding.getObjectUUID() + " to rank " + targetRank); + break; + case NPC: + NPC toRank = (NPC) target; + toRank.setRank(targetRank * 10); + toRank.setUpgradeDateTime(null); + WorldGrid.updateObject(toRank); + break; + case Mob: + Mob toRankCaptain = (Mob) target; + if (toRankCaptain.getContract() != null) { + toRankCaptain.setRank(targetRank * 10); + Mob.setUpgradeDateTime(toRankCaptain, null); + WorldGrid.updateObject(toRankCaptain); + } + + break; + } + + } else { + Building targetBuilding = null; + if (uuid != 0) + targetBuilding = BuildingManager.getBuilding(uuid); + + if (targetBuilding == null) { + throwbackError(player, "Unable to find building."); + return; + } + + Blueprint blueprint = targetBuilding.getBlueprint(); + + if (blueprint == null) { + throwbackError(player, "Attempt to rank building without blueprint" + targetBuilding.getObjectUUID()); + return; + } + + if (targetRank > blueprint.getMaxRank()) { + throwbackError(player, "Attempt to set Invalid Rank" + targetBuilding.getObjectUUID()); + return; + } + + // Set the current targetRank + int lastMeshID = targetBuilding.getMeshUUID(); + targetBuilding.setRank(targetRank); + + if (lastMeshID != targetBuilding.getMeshUUID()) + targetBuilding.refresh(true); + else + targetBuilding.refresh(false); + + ChatManager.chatSayInfo(player, "Rank set for building with ID " + targetBuilding.getObjectUUID() + " to rank " + targetRank); + } + + + } + + @Override + protected String _getHelpString() { + return "Sets the Rank of either the targets object or the object specified by ID."; + } + + @Override + protected String _getUsageString() { + return "' /setrank ID rank' || ' /setrank rank' || ' /rank ID rank' || ' /rank rank'"; + } } diff --git a/src/engine/devcmd/cmds/SetRuneCmd.java b/src/engine/devcmd/cmds/SetRuneCmd.java index 99bd3b2d..1379ab35 100644 --- a/src/engine/devcmd/cmds/SetRuneCmd.java +++ b/src/engine/devcmd/cmds/SetRuneCmd.java @@ -17,64 +17,62 @@ import engine.objects.CharacterRune; import engine.objects.PlayerCharacter; /** - * * @author Eighty - * */ public class SetRuneCmd extends AbstractDevCmd { - public SetRuneCmd() { + public SetRuneCmd() { super("setRune"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - int runeID = 0; - boolean add = true; - try { - runeID = Integer.parseInt(args[0]); - if (args.length > 1) - add = (args[1].toLowerCase().equals("false")) ? false : true; - } catch (NumberFormatException e) { - this.sendUsage(pcSender); - return; - } - if (runeID < 3001 || runeID > 3049) { - throwbackError(pcSender, - "Invalid setrune Command. must specify an ID between 3001 and 3048."); - return; - } - boolean worked = false; - if (add) { - worked = CharacterRune.grantRune(pcSender, runeID); - if (worked) - ChatManager.chatSayInfo(pcSender, - "rune of ID " + runeID + " added"); - else - throwbackError(pcSender, "Failed to add the rune of type " - + runeID); - } else { - worked = CharacterRune.removeRune(pcSender, runeID); - if (worked) { - ChatManager.chatSayInfo(pcSender, - "rune of ID " + runeID + " removed"); - InterestManager.reloadCharacter(pcSender); - } else - throwbackError(pcSender, "Failed to remove the rune of type " - + runeID); - } - this.setTarget(pcSender); //for logging - } + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] args, + AbstractGameObject target) { + int runeID = 0; + boolean add = true; + try { + runeID = Integer.parseInt(args[0]); + if (args.length > 1) + add = (args[1].toLowerCase().equals("false")) ? false : true; + } catch (NumberFormatException e) { + this.sendUsage(pcSender); + return; + } + if (runeID < 3001 || runeID > 3049) { + throwbackError(pcSender, + "Invalid setrune Command. must specify an ID between 3001 and 3048."); + return; + } + boolean worked = false; + if (add) { + worked = CharacterRune.grantRune(pcSender, runeID); + if (worked) + ChatManager.chatSayInfo(pcSender, + "rune of ID " + runeID + " added"); + else + throwbackError(pcSender, "Failed to add the rune of type " + + runeID); + } else { + worked = CharacterRune.removeRune(pcSender, runeID); + if (worked) { + ChatManager.chatSayInfo(pcSender, + "rune of ID " + runeID + " removed"); + InterestManager.reloadCharacter(pcSender); + } else + throwbackError(pcSender, "Failed to remove the rune of type " + + runeID); + } + this.setTarget(pcSender); //for logging + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /setrune runeID [true/false]'"; - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Grant or remove the rune with the specified runeID"; - } + } } diff --git a/src/engine/devcmd/cmds/SetStaminaCmd.java b/src/engine/devcmd/cmds/SetStaminaCmd.java index e0cde8e7..d760a1cc 100644 --- a/src/engine/devcmd/cmds/SetStaminaCmd.java +++ b/src/engine/devcmd/cmds/SetStaminaCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.Enum.DispatchChannel; @@ -21,48 +20,48 @@ import engine.server.MBServerStatics; public class SetStaminaCmd extends AbstractDevCmd { - public SetStaminaCmd() { + public SetStaminaCmd() { super("setStamina"); this.addCmdString("stamina"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - // Arg Count Check - if (words.length != 1) { - this.sendUsage(pc); - return; - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + // Arg Count Check + if (words.length != 1) { + this.sendUsage(pc); + return; + } - float amount = 0.0f; - try { - amount = Float.parseFloat(words[0]); - pc.setStamina(amount, pc); - this.setTarget(pc); //for logging + float amount = 0.0f; + try { + amount = Float.parseFloat(words[0]); + pc.setStamina(amount, pc); + this.setTarget(pc); //for logging - // Update all surrounding clients. - TargetedActionMsg cmm = new TargetedActionMsg(pc); - DispatchMessage.dispatchMsgToInterestArea(pc, cmm, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + // Update all surrounding clients. + TargetedActionMsg cmm = new TargetedActionMsg(pc); + DispatchMessage.dispatchMsgToInterestArea(pc, cmm, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - } catch (NumberFormatException e) { - this.throwbackError(pc, "Supplied data: " + words[0] - + " failed to parse to a Float."); - } catch (Exception e) { - this.throwbackError(pc, - "An unknown exception occurred while attempting to setStamina to " - + words[0]); - } - } + } catch (NumberFormatException e) { + this.throwbackError(pc, "Supplied data: " + words[0] + + " failed to parse to a Float."); + } catch (Exception e) { + this.throwbackError(pc, + "An unknown exception occurred while attempting to setStamina to " + + words[0]); + } + } - @Override - protected String _getHelpString() { - return "Sets your character's Stamina to 'amount'"; - } + @Override + protected String _getHelpString() { + return "Sets your character's Stamina to 'amount'"; + } - @Override - protected String _getUsageString() { - return "' /setStamina amount'"; - } + @Override + protected String _getUsageString() { + return "' /setStamina amount'"; + } } diff --git a/src/engine/devcmd/cmds/SetSubRaceCmd.java b/src/engine/devcmd/cmds/SetSubRaceCmd.java index 78227780..4ad42ffc 100644 --- a/src/engine/devcmd/cmds/SetSubRaceCmd.java +++ b/src/engine/devcmd/cmds/SetSubRaceCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; @@ -20,190 +19,178 @@ import engine.objects.*; public class SetSubRaceCmd extends AbstractDevCmd { - public SetSubRaceCmd() { + public SetSubRaceCmd() { super("setSubRace"); this.addCmdString("subrace"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - - if (target instanceof AbstractCharacter){ - - if (words[0].equals("race")){ - if (target.getObjectType() != GameObjectType.PlayerCharacter) - return; - PlayerCharacter player = (PlayerCharacter)target; - int raceID = Integer.parseInt(words[1]); - player.setSubRaceID(raceID); - if (raceID == 0) - raceID = player.getRaceID(); - UpdateCharOrMobMessage ucm = new UpdateCharOrMobMessage(player, 1,raceID); - DispatchMessage.sendToAllInRange(player, ucm); - return; - } - if (words[0].equals("all")){ - for (int i = 15999; i< 16337;i++){ - ApplyBuildingEffectMsg applyBuildingEffectMsg = new ApplyBuildingEffectMsg(4, 0, target.getObjectType().ordinal(), target.getObjectUUID(), i); - DispatchMessage.sendToAllInRange((AbstractWorldObject) target, applyBuildingEffectMsg); - try { - Thread.sleep(500); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - }else{ - ApplyBuildingEffectMsg applyBuildingEffectMsg = new ApplyBuildingEffectMsg(4, 0, target.getObjectType().ordinal(), target.getObjectUUID(), Integer.parseInt(words[0])); - DispatchMessage.sendToAllInRange((AbstractWorldObject) target, applyBuildingEffectMsg); - } - - return; - } - - Building building = (Building)target; - - building.removeAllVisualEffects(); - building.addEffectBit(1<(), new ArrayList<>(), null, true); - // pc.getClientConnection().sendMsg(updateInventoryMsg); - - //pc.getCharItemManager().updateInventory(); - - - - // Mob mob = (Mob)target; - // - // if (mob == null) - // return; - // - // MobLoot mobLoot = new MobLoot(mob, ItemBase.getItemBase(Integer.parseInt(words[0])), false); - // - // mob.getCharItemManager().addItemToInventory(mobLoot); - - - - - // if (target.getObjectType() != GameObjectType.Building) - // return; - // - // Building warehouseBuilding = (Building)target; - // - // if (Warehouse.warehouseByBuildingUUID.get(warehouseBuilding.getObjectUUID()) == null) - // return; - // - // Warehouse warehouse = Warehouse.warehouseByBuildingUUID.get(warehouseBuilding.getObjectUUID()); - // - // for (int ibID: Warehouse.getMaxResources().keySet()){ - // ItemBase ib = ItemBase.getItemBase(ibID); - // warehouse.depositFromMine(null, ib, Warehouse.getMaxResources().get(ibID)); - // } - - - // int raceID = Integer.parseInt(words[0]); - // - // UpdateCharOrMobMessage ucm = new UpdateCharOrMobMessage(pc, raceID); - // - // pc.getClientConnection().sendMsg(ucm); - - // LoadCharacterMsg lcm = new LoadCharacterMsg((AbstractCharacter)null,false); - // try { - // DispatchMessage.sendToAllInRange(pc, lcm); - // } catch (MsgSendException e) { - // // TODO Auto-generated catch block - // e.printStackTrace(); - // } - // ModifyHealthMsg mhm =new ModifyHealthMsg(pc, pc, -50f, 0f, 0f, 0, null, 9999, 0); - // mhm.setOmitFromChat(1); - // pc.getClientConnection().sendMsg(mhm); - // - // int temp = 0; - // boolean start = false; - // - // for (EffectsBase eb: EffectsBase.getAllEffectsBase()){ - // - // - // - // if (!pc.getClientConnection().isConnected()){ - // Logger.info("", "PLAYER DC!" + eb.getIDString()); - // break; - // } - // - // eb = PowersManager.getEffectByIDString("WLR-018A"); - // - // - // NoTimeJob ntj = new NoTimeJob(pc, "NONE", eb, 40); - // pc.addEffect(String.valueOf(eb.getUUID()), 1000, ntj, eb, 40); - // eb.sendEffectNoPower(ntj, 1000, pc.getClientConnection()); - // - // ThreadUtils.sleep(500); - // pc.clearEffects(); - // - // //WorldServer.updateObject((AbstractWorldObject)target, pc); - // this.throwbackInfo(pc, eb.getIDString()); - // break; - // //ThreadUtils.sleep(500); - // - // } - - - - - - - - - - // for (EffectsBase eb : EffectsBase.getAllEffectsBase()){ - // if (eb.getToken() == 0) - // continue; - // int token = eb.getToken(); - // ApplyEffectMsg pum = new ApplyEffectMsg(); - // pum.setEffectID(token); - // pum.setSourceType(pc.getObjectType().ordinal()); - // pum.setSourceID(pc.getObjectUUID()); - // pum.setTargetType(pc.getObjectType().ordinal()); - // pum.setTargetID(pc.getObjectUUID()); - // pum.setNumTrains(40); - // pum.setDuration(-1); - //// pum.setDuration((pb.isChant()) ? (int)pb.getChantDuration() : ab.getDurationInSeconds(trains)); - // pum.setPowerUsedID(0); - // // pum.setPowerUsedName("Inflict Poison"); - // this.throwbackInfo(pc, eb.getName() + "Token = " + eb.getToken()); - // pc.getClientConnection().sendMsg(pum); - // ThreadUtils.sleep(200); - // } - // - - // UpdateObjectMsg uom = new UpdateObjectMsg(pc, 4); - // try { - // Location.sendToAllInRange(pc, uom); - // } catch (MsgSendException e) { - // // TODO Auto-generated catch block - // e.printStackTrace(); - // } - - - - - } - - @Override - protected String _getHelpString() { - return "Temporarily Changes SubRace"; - } - - @Override - protected String _getUsageString() { - return "' /subrace mobBaseID"; - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + + if (target instanceof AbstractCharacter) { + + if (words[0].equals("race")) { + if (target.getObjectType() != GameObjectType.PlayerCharacter) + return; + PlayerCharacter player = (PlayerCharacter) target; + int raceID = Integer.parseInt(words[1]); + player.setSubRaceID(raceID); + if (raceID == 0) + raceID = player.getRaceID(); + UpdateCharOrMobMessage ucm = new UpdateCharOrMobMessage(player, 1, raceID); + DispatchMessage.sendToAllInRange(player, ucm); + return; + } + if (words[0].equals("all")) { + for (int i = 15999; i < 16337; i++) { + ApplyBuildingEffectMsg applyBuildingEffectMsg = new ApplyBuildingEffectMsg(4, 0, target.getObjectType().ordinal(), target.getObjectUUID(), i); + DispatchMessage.sendToAllInRange((AbstractWorldObject) target, applyBuildingEffectMsg); + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + } else { + ApplyBuildingEffectMsg applyBuildingEffectMsg = new ApplyBuildingEffectMsg(4, 0, target.getObjectType().ordinal(), target.getObjectUUID(), Integer.parseInt(words[0])); + DispatchMessage.sendToAllInRange((AbstractWorldObject) target, applyBuildingEffectMsg); + } + + return; + } + + Building building = (Building) target; + + building.removeAllVisualEffects(); + building.addEffectBit(1 << Integer.parseInt(words[0])); + building.updateEffects(); + //63535 38751 + // Zone zone = ZoneManager.findSmallestZone(pc.getLoc()); + // //CityZoneMsg czm = new CityZoneMsg(3, zone.getLoc().x, zone.getLoc().y, zone.getLoc().z, "balls", zone, 0, 0); + // pc.getClientConnection().sendMsg(new DeleteItemMsg(zone.getObjectType().ordinal(), zone.getObjectUUID())); + + // UpdateInventoryMsg updateInventoryMsg = new UpdateInventoryMsg(new ArrayList<>(), new ArrayList<>(), null, true); + // pc.getClientConnection().sendMsg(updateInventoryMsg); + + //pc.getCharItemManager().updateInventory(); + + + // Mob mob = (Mob)target; + // + // if (mob == null) + // return; + // + // MobLoot mobLoot = new MobLoot(mob, ItemBase.getItemBase(Integer.parseInt(words[0])), false); + // + // mob.getCharItemManager().addItemToInventory(mobLoot); + + + // if (target.getObjectType() != GameObjectType.Building) + // return; + // + // Building warehouseBuilding = (Building)target; + // + // if (Warehouse.warehouseByBuildingUUID.get(warehouseBuilding.getObjectUUID()) == null) + // return; + // + // Warehouse warehouse = Warehouse.warehouseByBuildingUUID.get(warehouseBuilding.getObjectUUID()); + // + // for (int ibID: Warehouse.getMaxResources().keySet()){ + // ItemBase ib = ItemBase.getItemBase(ibID); + // warehouse.depositFromMine(null, ib, Warehouse.getMaxResources().get(ibID)); + // } + + + // int raceID = Integer.parseInt(words[0]); + // + // UpdateCharOrMobMessage ucm = new UpdateCharOrMobMessage(pc, raceID); + // + // pc.getClientConnection().sendMsg(ucm); + + // LoadCharacterMsg lcm = new LoadCharacterMsg((AbstractCharacter)null,false); + // try { + // DispatchMessage.sendToAllInRange(pc, lcm); + // } catch (MsgSendException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } + // ModifyHealthMsg mhm =new ModifyHealthMsg(pc, pc, -50f, 0f, 0f, 0, null, 9999, 0); + // mhm.setOmitFromChat(1); + // pc.getClientConnection().sendMsg(mhm); + // + // int temp = 0; + // boolean start = false; + // + // for (EffectsBase eb: EffectsBase.getAllEffectsBase()){ + // + // + // + // if (!pc.getClientConnection().isConnected()){ + // Logger.info("", "PLAYER DC!" + eb.getIDString()); + // break; + // } + // + // eb = PowersManager.getEffectByIDString("WLR-018A"); + // + // + // NoTimeJob ntj = new NoTimeJob(pc, "NONE", eb, 40); + // pc.addEffect(String.valueOf(eb.getUUID()), 1000, ntj, eb, 40); + // eb.sendEffectNoPower(ntj, 1000, pc.getClientConnection()); + // + // ThreadUtils.sleep(500); + // pc.clearEffects(); + // + // //WorldServer.updateObject((AbstractWorldObject)target, pc); + // this.throwbackInfo(pc, eb.getIDString()); + // break; + // //ThreadUtils.sleep(500); + // + // } + + + // for (EffectsBase eb : EffectsBase.getAllEffectsBase()){ + // if (eb.getToken() == 0) + // continue; + // int token = eb.getToken(); + // ApplyEffectMsg pum = new ApplyEffectMsg(); + // pum.setEffectID(token); + // pum.setSourceType(pc.getObjectType().ordinal()); + // pum.setSourceID(pc.getObjectUUID()); + // pum.setTargetType(pc.getObjectType().ordinal()); + // pum.setTargetID(pc.getObjectUUID()); + // pum.setNumTrains(40); + // pum.setDuration(-1); + //// pum.setDuration((pb.isChant()) ? (int)pb.getChantDuration() : ab.getDurationInSeconds(trains)); + // pum.setPowerUsedID(0); + // // pum.setPowerUsedName("Inflict Poison"); + // this.throwbackInfo(pc, eb.getName() + "Token = " + eb.getToken()); + // pc.getClientConnection().sendMsg(pum); + // ThreadUtils.sleep(200); + // } + // + + // UpdateObjectMsg uom = new UpdateObjectMsg(pc, 4); + // try { + // Location.sendToAllInRange(pc, uom); + // } catch (MsgSendException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } + + + } + + @Override + protected String _getHelpString() { + return "Temporarily Changes SubRace"; + } + + @Override + protected String _getUsageString() { + return "' /subrace mobBaseID"; + } } diff --git a/src/engine/devcmd/cmds/ShowOffsetCmd.java b/src/engine/devcmd/cmds/ShowOffsetCmd.java index 45fc2ae6..55b0a0fe 100644 --- a/src/engine/devcmd/cmds/ShowOffsetCmd.java +++ b/src/engine/devcmd/cmds/ShowOffsetCmd.java @@ -8,50 +8,49 @@ import engine.objects.Building; import engine.objects.PlayerCharacter; public class ShowOffsetCmd extends AbstractDevCmd { - - public ShowOffsetCmd() { + + public ShowOffsetCmd() { super("showoffset"); } - // AbstractDevCmd Overridden methods - - @Override - protected void _doCmd(PlayerCharacter pc, String[] args, - AbstractGameObject target) { - - - Building targetBuilding; - String outString; - Vector3fImmutable offset; - - String newline = "\r\n "; - targetBuilding = (Building)target; - - if (targetBuilding.getObjectType() != GameObjectType.Building) { - throwbackInfo(pc, "showgate: target must be an Building"); - return; - } - - offset = pc.getLoc().subtract(targetBuilding.getLoc()); - - outString = "Location: " + pc.getLoc().x + "x " + pc.getLoc().z + 'y'; - outString += newline; - outString += "Offset: " + offset.x + "x " + offset.y + 'y'; - throwbackInfo(pc, outString); + // AbstractDevCmd Overridden methods + + @Override + protected void _doCmd(PlayerCharacter pc, String[] args, + AbstractGameObject target) { + + + Building targetBuilding; + String outString; + Vector3fImmutable offset; + + String newline = "\r\n "; + targetBuilding = (Building) target; + + if (targetBuilding.getObjectType() != GameObjectType.Building) { + throwbackInfo(pc, "showgate: target must be an Building"); + return; } - @Override - protected String _getHelpString() { + offset = pc.getLoc().subtract(targetBuilding.getLoc()); + + outString = "Location: " + pc.getLoc().x + "x " + pc.getLoc().z + 'y'; + outString += newline; + outString += "Offset: " + offset.x + "x " + offset.y + 'y'; + throwbackInfo(pc, outString); + } + + @Override + protected String _getHelpString() { return "Shows offset to current building"; - } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "Shows offset to current building"; - } + } + - - } diff --git a/src/engine/devcmd/cmds/SlotTestCmd.java b/src/engine/devcmd/cmds/SlotTestCmd.java index 6fbac8a9..3da13617 100644 --- a/src/engine/devcmd/cmds/SlotTestCmd.java +++ b/src/engine/devcmd/cmds/SlotTestCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.Enum.GameObjectType; @@ -21,75 +20,75 @@ import java.util.ArrayList; public class SlotTestCmd extends AbstractDevCmd { - public SlotTestCmd() { + public SlotTestCmd() { super("slottest"); } - @Override - protected void _doCmd(PlayerCharacter playerCharacter, String[] args, - AbstractGameObject target) { + @Override + protected void _doCmd(PlayerCharacter playerCharacter, String[] args, + AbstractGameObject target) { - ArrayList buildingLocations; - String outString = "Available Slots\r\n"; + ArrayList buildingLocations; + String outString = "Available Slots\r\n"; - if (target == null) - return; + if (target == null) + return; - if (target.getObjectType() != GameObjectType.Building) - return; + if (target.getObjectType() != GameObjectType.Building) + return; - Building building = (Building) target; + Building building = (Building) target; - buildingLocations = BuildingManager._slotLocations.get(building.meshUUID); + buildingLocations = BuildingManager._slotLocations.get(building.meshUUID); - if (buildingLocations == null) { - outString = "No slot information for mesh: " + building.meshUUID; - ChatManager.chatSystemInfo(playerCharacter, outString); - return; - } + if (buildingLocations == null) { + outString = "No slot information for mesh: " + building.meshUUID; + ChatManager.chatSystemInfo(playerCharacter, outString); + return; + } - // Goto slot location + // Goto slot location - if (args[0].isEmpty() == false) { + if (args[0].isEmpty() == false) { - int slot = Integer.parseInt(args[0]); - Vector3fImmutable slotLocation; - 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); - return; - } + int slot = Integer.parseInt(args[0]); + Vector3fImmutable slotLocation; + 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); + return; + } - for (BuildingLocation buildingLocation : BuildingManager._slotLocations.get(building.meshUUID)) - outString += buildingLocation.getSlot() + buildingLocation.getLocation().toString() + "\r\n"; + for (BuildingLocation buildingLocation : BuildingManager._slotLocations.get(building.meshUUID)) + outString += buildingLocation.getSlot() + buildingLocation.getLocation().toString() + "\r\n"; - outString += "\r\nNext Available Slot: " + BuildingManager.getAvailableSlot(building); + outString += "\r\nNext Available Slot: " + BuildingManager.getAvailableSlot(building); - if (building.getHirelings().isEmpty() == false) { + if (building.getHirelings().isEmpty() == false) { - outString += "\r\n\r\n"; - outString += "Hirelings List:"; + outString += "\r\n\r\n"; + outString += "Hirelings List:"; - for (AbstractCharacter hireling : building.getHirelings().keySet()) - outString += "\r\n" + hireling.getName() + " slot : " + building.getHirelings().get(hireling); + for (AbstractCharacter hireling : building.getHirelings().keySet()) + outString += "\r\n" + hireling.getName() + " slot : " + building.getHirelings().get(hireling); - } + } - ChatManager.chatSystemInfo(playerCharacter,outString); + ChatManager.chatSystemInfo(playerCharacter, outString); - } + } - @Override - protected String _getHelpString() { - return "Displays slot information for building"; - } + @Override + protected String _getHelpString() { + return "Displays slot information for building"; + } - @Override - protected String _getUsageString() { - return "./slottest n"; + @Override + protected String _getUsageString() { + return "./slottest n"; - } + } } diff --git a/src/engine/devcmd/cmds/SplatMobCmd.java b/src/engine/devcmd/cmds/SplatMobCmd.java index 4f924c0f..cb429b99 100644 --- a/src/engine/devcmd/cmds/SplatMobCmd.java +++ b/src/engine/devcmd/cmds/SplatMobCmd.java @@ -12,155 +12,154 @@ import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; /** - * @author - * Summary: Game designer utility command to create multiple - * mobiles of a given UUID within a supplied range + * @author Summary: Game designer utility command to create multiple + * mobiles of a given UUID within a supplied range */ public class SplatMobCmd extends AbstractDevCmd { - // Instance variables + // Instance variables - private int _mobileUUID; - private int _mobileCount; - private float _targetRange; - private Vector3fImmutable _currentLocation; + private int _mobileUUID; + private int _mobileCount; + private float _targetRange; + private Vector3fImmutable _currentLocation; - // Concurrency support + // Concurrency support - private ReadWriteLock lock = new ReentrantReadWriteLock(); + private ReadWriteLock lock = new ReentrantReadWriteLock(); - // Constructor + // Constructor - public SplatMobCmd() { + public SplatMobCmd() { super("splatmob"); } - // AbstractDevCmd Overridden methods + // AbstractDevCmd Overridden methods - @Override - protected void _doCmd(PlayerCharacter pc, String[] args, - AbstractGameObject target) { + private static boolean validateUserInput(String[] userInput) { - // Member variables + // incorrect number of arguments test - Vector3fImmutable mobileLocation; - Mob mobile; - Zone serverZone; + if (userInput.length != 3) + return false; - // Concurrency write lock due to instance variable usage + // Test for UUID conversion to int - lock.writeLock().lock(); + try { + Integer.parseInt(userInput[0]); + } catch (NumberFormatException | NullPointerException e) { + return false; + } - try { - // Validate user input + // Test for Number of Mobs conversion to int - if(validateUserInput(args) == false) { - this.sendUsage(pc); - return; - } + try { + Integer.parseInt(userInput[1]); + } catch (NumberFormatException | NullPointerException e) { + return false; + } - // Parse user input + // Test if range argument can convert to a float - parseUserInput(args); + try { + Float.parseFloat(userInput[2]); + } catch (NumberFormatException | NullPointerException e) { + return false; + } - // Arguments have been validated and parsed at this point - // Begin creating mobiles + return true; + } - _currentLocation = pc.getLoc(); - serverZone = ZoneManager.findSmallestZone(_currentLocation); + @Override + protected void _doCmd(PlayerCharacter pc, String[] args, + AbstractGameObject target) { - for(int i=0;i<_mobileCount;i++) { + // Member variables - mobile = Mob.createMob(_mobileUUID, - Vector3fImmutable.getRandomPointInCircle(_currentLocation, _targetRange), - null, true, serverZone,null,0, "", 1); + Vector3fImmutable mobileLocation; + Mob mobile; + Zone serverZone; - if (mobile != null) { - mobile.updateDatabase(); - } - } + // Concurrency write lock due to instance variable usage - } // End Try Block + lock.writeLock().lock(); - // Release Reentrant lock + try { - finally { - lock.writeLock().unlock(); - } - } + // Validate user input - @Override - protected String _getHelpString() { - return "Spawns multiple mobiles with a given range"; - } + if (validateUserInput(args) == false) { + this.sendUsage(pc); + return; + } - @Override - protected String _getUsageString() { - return "/splatmob UUID [Count <= 100] [range <= 1200]"; - } + // Parse user input - // Class methods + parseUserInput(args); - private static boolean validateUserInput(String[] userInput) { + // Arguments have been validated and parsed at this point + // Begin creating mobiles - // incorrect number of arguments test + _currentLocation = pc.getLoc(); + serverZone = ZoneManager.findSmallestZone(_currentLocation); - if (userInput.length != 3) - return false; + for (int i = 0; i < _mobileCount; i++) { - // Test for UUID conversion to int + mobile = Mob.createMob(_mobileUUID, + Vector3fImmutable.getRandomPointInCircle(_currentLocation, _targetRange), + null, true, serverZone, null, 0, "", 1); - try { - Integer.parseInt(userInput[0]); } - catch (NumberFormatException | NullPointerException e) { - return false; - } + if (mobile != null) { + mobile.updateDatabase(); + } + } + } // End Try Block - // Test for Number of Mobs conversion to int + // Release Reentrant lock - try { - Integer.parseInt(userInput[1]); } - catch (NumberFormatException | NullPointerException e) { - return false; - } + finally { + lock.writeLock().unlock(); + } + } - // Test if range argument can convert to a float + @Override + protected String _getHelpString() { + return "Spawns multiple mobiles with a given range"; + } - try { - Float.parseFloat(userInput[2]); } - catch (NumberFormatException | NullPointerException e) { - return false; - } + // Class methods - return true; - } + @Override + protected String _getUsageString() { + return "/splatmob UUID [Count <= 100] [range <= 1200]"; + } - private void parseUserInput(String[] userInput) { + private void parseUserInput(String[] userInput) { - // Clear previous values + // Clear previous values - _mobileUUID = 0; - _mobileCount = 0; - _targetRange = 0f; + _mobileUUID = 0; + _mobileCount = 0; + _targetRange = 0f; - // Parse first argument into mobile UID. + // Parse first argument into mobile UID. - _mobileUUID = Integer.parseInt(userInput[0]); + _mobileUUID = Integer.parseInt(userInput[0]); - // Parse second argument into mobile count. Cap at 100 mobs. + // Parse second argument into mobile count. Cap at 100 mobs. - _mobileCount = Integer.parseInt(userInput[1]); - _mobileCount = Math.min(_mobileCount, 100); + _mobileCount = Integer.parseInt(userInput[1]); + _mobileCount = Math.min(_mobileCount, 100); - // Parse third argument into range. Cap at 200 units. + // Parse third argument into range. Cap at 200 units. - _targetRange = Float.parseFloat(userInput[2]); - _targetRange = Math.min(_targetRange, 1200f); + _targetRange = Float.parseFloat(userInput[2]); + _targetRange = Math.min(_targetRange, 1200f); - } + } } \ No newline at end of file diff --git a/src/engine/devcmd/cmds/SqlDebugCmd.java b/src/engine/devcmd/cmds/SqlDebugCmd.java index 18087692..5e9b9a28 100644 --- a/src/engine/devcmd/cmds/SqlDebugCmd.java +++ b/src/engine/devcmd/cmds/SqlDebugCmd.java @@ -6,81 +6,79 @@ import engine.objects.PlayerCharacter; import engine.server.MBServerStatics; /** - * @author - * Summary: Devcmd to toggle logging of mysql statements - * + * @author Summary: Devcmd to toggle logging of mysql statements */ - + public class SqlDebugCmd extends AbstractDevCmd { // Instance variables - - - public SqlDebugCmd() { + + + public SqlDebugCmd() { super("sqldebug"); } - - // AbstractDevCmd Overridden methods - - @Override - protected void _doCmd(PlayerCharacter pc, String[] args, - AbstractGameObject target) { - - Boolean debugState = false; - - if(validateUserInput(args) == false) { - this.sendUsage(pc); - return; - } - - // Arguments have been validated use argument to set debug state - - switch (args[0]) { - case "on": - debugState = true; - break; - case "off": - debugState = false; - break; - default: - break; - } - - MBServerStatics.DB_ENABLE_QUERY_OUTPUT = debugState; - - // Send results to user - throwbackInfo(pc, "SQL debug state: " + debugState.toString()); - } - - @Override - protected String _getHelpString() { - return "Toggles sending SQL statements to log"; - } - @Override - protected String _getUsageString() { - return "/sqldebug on|off"; - } + // AbstractDevCmd Overridden methods - // Class methods - - private static boolean validateUserInput(String[] userInput) { + private static boolean validateUserInput(String[] userInput) { int stringIndex; String commandSet = "onoff"; - + // incorrect number of arguments test - + if (userInput.length != 1) - return false; + return false; // Validate arguments - + stringIndex = commandSet.indexOf(userInput[0].toLowerCase()); - return stringIndex != -1; + return stringIndex != -1; + } + + @Override + protected void _doCmd(PlayerCharacter pc, String[] args, + AbstractGameObject target) { + + Boolean debugState = false; + + if (validateUserInput(args) == false) { + this.sendUsage(pc); + return; } - - + + // Arguments have been validated use argument to set debug state + + switch (args[0]) { + case "on": + debugState = true; + break; + case "off": + debugState = false; + break; + default: + break; + } + + MBServerStatics.DB_ENABLE_QUERY_OUTPUT = debugState; + + // Send results to user + throwbackInfo(pc, "SQL debug state: " + debugState.toString()); + } + + @Override + protected String _getHelpString() { + return "Toggles sending SQL statements to log"; + } + + // Class methods + + @Override + protected String _getUsageString() { + return "/sqldebug on|off"; + } + + } diff --git a/src/engine/devcmd/cmds/SummonCmd.java b/src/engine/devcmd/cmds/SummonCmd.java index c0a1c7d1..184903ca 100644 --- a/src/engine/devcmd/cmds/SummonCmd.java +++ b/src/engine/devcmd/cmds/SummonCmd.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.devcmd.AbstractDevCmd; @@ -21,94 +20,94 @@ import engine.objects.Zone; public class SummonCmd extends AbstractDevCmd { - public SummonCmd() { + public SummonCmd() { super("summon"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] args, - AbstractGameObject target) { - // Arg Count Check - if (args.length != 1) { - this.sendUsage(pc); - return; - } - PlayerCharacter pcToSummon = null; - - - if (args[0].equalsIgnoreCase("all")){ - for (PlayerCharacter toSummon: SessionManager.getAllActivePlayerCharacters()){ - Zone zone = ZoneManager.findSmallestZone(pc.getLoc()); - String location = "Somewhere"; - if (zone != null) - location = zone.getName(); - RecvSummonsRequestMsg rsrm = new RecvSummonsRequestMsg(pc.getObjectType().ordinal(), pc.getObjectUUID(), pc.getFirstName(), - location, false); - toSummon.getClientConnection().sendMsg(rsrm); - - } - return; - } - // 1-9 numeric digits, must be playerID - if (args[0].matches("\\d{1,9}?")) { - try { - int playerID = Integer.parseInt(args[0]); - pcToSummon = SessionManager - .getPlayerCharacterByID(playerID); - - if (pcToSummon == null) { - this.throwbackError(pc, "Character not found by ID: " - + playerID); - return; - } - } catch (NumberFormatException e) { - this.throwbackError(pc, "Supplied ID: '" + args[0] - + "' failed to parse to an INT"); - return; - - } catch (Exception e) { - this.throwbackError(pc, - "An unknown exception occurred while attempting to summon '" - + args[0] + "'by ID"); - return; - } - - } else { // player name - try { - pcToSummon = SessionManager - .getPlayerCharacterByLowerCaseName(args[0]); - if (pcToSummon == null) { - this.throwbackError(pc, "Character not found by name: " - + args[0]); - return; - } - } catch (Exception e) { - this.throwbackError(pc, - "An unknown exception occurred while attempting to summon '" - + args[0] + "'by name"); - return; - } - } - this.setTarget(pcToSummon); //for logging - - Vector3fImmutable loc = pc.getLoc(); - pcToSummon.teleport(loc); - - this.throwbackInfo(pc, "Player " + pcToSummon.getCombinedName() - + " has been summoned to your location."); - this.throwbackInfo(pcToSummon, - "You have been transported to another location."); - } - - @Override - protected String _getHelpString() { - return "Summons 'character' TO your current position. Can summon by character's first name or by the character's characterID."; - - } - - @Override - protected String _getUsageString() { - return "' /summon characterName' || ' /summon characterID'"; - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] args, + AbstractGameObject target) { + // Arg Count Check + if (args.length != 1) { + this.sendUsage(pc); + return; + } + PlayerCharacter pcToSummon = null; + + + if (args[0].equalsIgnoreCase("all")) { + for (PlayerCharacter toSummon : SessionManager.getAllActivePlayerCharacters()) { + Zone zone = ZoneManager.findSmallestZone(pc.getLoc()); + String location = "Somewhere"; + if (zone != null) + location = zone.getName(); + RecvSummonsRequestMsg rsrm = new RecvSummonsRequestMsg(pc.getObjectType().ordinal(), pc.getObjectUUID(), pc.getFirstName(), + location, false); + toSummon.getClientConnection().sendMsg(rsrm); + + } + return; + } + // 1-9 numeric digits, must be playerID + if (args[0].matches("\\d{1,9}?")) { + try { + int playerID = Integer.parseInt(args[0]); + pcToSummon = SessionManager + .getPlayerCharacterByID(playerID); + + if (pcToSummon == null) { + this.throwbackError(pc, "Character not found by ID: " + + playerID); + return; + } + } catch (NumberFormatException e) { + this.throwbackError(pc, "Supplied ID: '" + args[0] + + "' failed to parse to an INT"); + return; + + } catch (Exception e) { + this.throwbackError(pc, + "An unknown exception occurred while attempting to summon '" + + args[0] + "'by ID"); + return; + } + + } else { // player name + try { + pcToSummon = SessionManager + .getPlayerCharacterByLowerCaseName(args[0]); + if (pcToSummon == null) { + this.throwbackError(pc, "Character not found by name: " + + args[0]); + return; + } + } catch (Exception e) { + this.throwbackError(pc, + "An unknown exception occurred while attempting to summon '" + + args[0] + "'by name"); + return; + } + } + this.setTarget(pcToSummon); //for logging + + Vector3fImmutable loc = pc.getLoc(); + pcToSummon.teleport(loc); + + this.throwbackInfo(pc, "Player " + pcToSummon.getCombinedName() + + " has been summoned to your location."); + this.throwbackInfo(pcToSummon, + "You have been transported to another location."); + } + + @Override + protected String _getHelpString() { + return "Summons 'character' TO your current position. Can summon by character's first name or by the character's characterID."; + + } + + @Override + protected String _getUsageString() { + return "' /summon characterName' || ' /summon characterID'"; + } } diff --git a/src/engine/devcmd/cmds/SysMsgCmd.java b/src/engine/devcmd/cmds/SysMsgCmd.java index 4004655e..3b619b86 100644 --- a/src/engine/devcmd/cmds/SysMsgCmd.java +++ b/src/engine/devcmd/cmds/SysMsgCmd.java @@ -15,53 +15,53 @@ import engine.objects.AbstractGameObject; import engine.objects.PlayerCharacter; /** - * + * */ public class SysMsgCmd extends AbstractDevCmd { - public SysMsgCmd() { + public SysMsgCmd() { super("sysmsg"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - if (args.length != 1 || args[0].isEmpty()) { - this.sendUsage(pcSender); - return; - } - String text = "[System Admin Message]: " + args[0]; - ChatManager.chatSystemChannel(text); - } + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] args, + AbstractGameObject target) { + if (args.length != 1 || args[0].isEmpty()) { + this.sendUsage(pcSender); + return; + } + String text = "[System Admin Message]: " + args[0]; + ChatManager.chatSystemChannel(text); + } - /** - * This function is called by the DevCmdManager. Override to avoid splitting - * argString into String array, since sysmsg displays full String as - * message, then calls the subclass specific _doCmd method. - */ + /** + * This function is called by the DevCmdManager. Override to avoid splitting + * argString into String array, since sysmsg displays full String as + * message, then calls the subclass specific _doCmd method. + */ - @Override - public void doCmd(PlayerCharacter pcSender, String argString, - AbstractGameObject target) { - String[] args = new String[1]; - args[0] = argString; + @Override + public void doCmd(PlayerCharacter pcSender, String argString, + AbstractGameObject target) { + String[] args = new String[1]; + args[0] = argString; - if (pcSender == null) { - return; - } + if (pcSender == null) { + return; + } - this._doCmd(pcSender, args, target); - } + this._doCmd(pcSender, args, target); + } - @Override - protected String _getUsageString() { - return "' /sysmsg message'"; - } + @Override + protected String _getUsageString() { + return "' /sysmsg message'"; + } - @Override - protected String _getHelpString() { - return "Send system message in chat window to all players"; - } + @Override + protected String _getHelpString() { + return "Send system message in chat window to all players"; + } } diff --git a/src/engine/devcmd/cmds/TeleportModeCmd.java b/src/engine/devcmd/cmds/TeleportModeCmd.java index 630f3824..89bac199 100644 --- a/src/engine/devcmd/cmds/TeleportModeCmd.java +++ b/src/engine/devcmd/cmds/TeleportModeCmd.java @@ -15,42 +15,42 @@ import engine.objects.PlayerCharacter; public class TeleportModeCmd extends AbstractDevCmd { - public TeleportModeCmd() { + public TeleportModeCmd() { super("teleportMode"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - boolean newTeleportMode = false; - if (words.length == 0) { // toggle - newTeleportMode = !pc.isTeleportMode(); - - } else if (words[0].equalsIgnoreCase("on")) { - newTeleportMode = true; - - } else if (words[0].equalsIgnoreCase("off")) { - newTeleportMode = false; - - } else { - this.sendUsage(pc); - return; - } - pc.setTeleportMode(newTeleportMode); - this.setTarget(pc); //for logging - String output = (newTeleportMode ? "on" : "off"); - - throwbackInfo(pc, "Teleport mode is now '" + output + "'."); - } - - @Override - protected String _getHelpString() { - return "'on' enables teleport mode, 'off' disables. No arguments to the /teleportMode command will toggle the setting."; - } - - @Override - protected String _getUsageString() { - return "' /teleportMode [on | off]'"; - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { + boolean newTeleportMode = false; + if (words.length == 0) { // toggle + newTeleportMode = !pc.isTeleportMode(); + + } else if (words[0].equalsIgnoreCase("on")) { + newTeleportMode = true; + + } else if (words[0].equalsIgnoreCase("off")) { + newTeleportMode = false; + + } else { + this.sendUsage(pc); + return; + } + pc.setTeleportMode(newTeleportMode); + this.setTarget(pc); //for logging + String output = (newTeleportMode ? "on" : "off"); + + throwbackInfo(pc, "Teleport mode is now '" + output + "'."); + } + + @Override + protected String _getHelpString() { + return "'on' enables teleport mode, 'off' disables. No arguments to the /teleportMode command will toggle the setting."; + } + + @Override + protected String _getUsageString() { + return "' /teleportMode [on | off]'"; + } } diff --git a/src/engine/devcmd/cmds/UnloadFurnitureCmd.java b/src/engine/devcmd/cmds/UnloadFurnitureCmd.java index 4197a800..e926ccbc 100644 --- a/src/engine/devcmd/cmds/UnloadFurnitureCmd.java +++ b/src/engine/devcmd/cmds/UnloadFurnitureCmd.java @@ -21,82 +21,81 @@ import engine.objects.PlayerCharacter; /** * @author - * */ public class UnloadFurnitureCmd extends AbstractDevCmd { - public UnloadFurnitureCmd() { + public UnloadFurnitureCmd() { super("furniture"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { - if (target.getObjectType() != GameObjectType.Building){ - this.throwbackError(pc, "Must be targeting a building to load/unload furniture."); - return; - } - if (words[0].equalsIgnoreCase("unload")){ + if (target.getObjectType() != GameObjectType.Building) { + this.throwbackError(pc, "Must be targeting a building to load/unload furniture."); + return; + } + if (words[0].equalsIgnoreCase("unload")) { - UnloadObjectsMsg uom = new UnloadObjectsMsg(); - for (AbstractWorldObject awo: pc.getLoadedStaticObjects()){ - if (awo.getObjectType() != GameObjectType.Building) - continue; + UnloadObjectsMsg uom = new UnloadObjectsMsg(); + for (AbstractWorldObject awo : pc.getLoadedStaticObjects()) { + if (awo.getObjectType() != GameObjectType.Building) + continue; - Building awoBuilding = (Building)awo; + Building awoBuilding = (Building) awo; if (!awoBuilding.isFurniture) - continue; + continue; - if (awoBuilding.parentBuildingID != target.getObjectUUID()) - continue; - - MoveToPointMsg msg = new MoveToPointMsg(awoBuilding); - pc.getClientConnection().sendMsg(msg); + if (awoBuilding.parentBuildingID != target.getObjectUUID()) + continue; - uom.addObject(awoBuilding); + MoveToPointMsg msg = new MoveToPointMsg(awoBuilding); + pc.getClientConnection().sendMsg(msg); + uom.addObject(awoBuilding); - } - pc.getClientConnection().sendMsg(uom); + } - }else if (words[0].equalsIgnoreCase("load")){ - LoadStructureMsg lsm = new LoadStructureMsg(); + pc.getClientConnection().sendMsg(uom); - for (AbstractWorldObject awo: pc.getLoadedStaticObjects()){ - if (awo.getObjectType() != GameObjectType.Building) - continue; + } else if (words[0].equalsIgnoreCase("load")) { + LoadStructureMsg lsm = new LoadStructureMsg(); - Building awoBuilding = (Building)awo; + for (AbstractWorldObject awo : pc.getLoadedStaticObjects()) { + if (awo.getObjectType() != GameObjectType.Building) + continue; + + Building awoBuilding = (Building) awo; if (!awoBuilding.isFurniture) - continue; + continue; - if (awoBuilding.parentBuildingID != target.getObjectUUID()) - continue; + if (awoBuilding.parentBuildingID != target.getObjectUUID()) + continue; - lsm.addObject(awoBuilding); + lsm.addObject(awoBuilding); - } + } - pc.getClientConnection().sendMsg(lsm); + pc.getClientConnection().sendMsg(lsm); - } - } + } + } - @Override - protected String _getHelpString() { - String help = "Enchants an item with a prefix and suffix"; - return help; - } + @Override + protected String _getHelpString() { + String help = "Enchants an item with a prefix and suffix"; + return help; + } - @Override - protected String _getUsageString() { - String usage = "' /enchant clear/Enchant1 Enchant2 Enchant3 ...'"; - return usage; - } + @Override + protected String _getUsageString() { + String usage = "' /enchant clear/Enchant1 Enchant2 Enchant3 ...'"; + return usage; + } } diff --git a/src/engine/devcmd/cmds/ZoneInfoCmd.java b/src/engine/devcmd/cmds/ZoneInfoCmd.java index 0cc7c2f2..09f03b83 100644 --- a/src/engine/devcmd/cmds/ZoneInfoCmd.java +++ b/src/engine/devcmd/cmds/ZoneInfoCmd.java @@ -22,129 +22,128 @@ import java.util.ArrayList; /** * @author - * */ public class ZoneInfoCmd extends AbstractDevCmd { - public ZoneInfoCmd() { + public ZoneInfoCmd() { super("zoneinfo"); } - @Override - protected void _doCmd(PlayerCharacter player, String[] words, - AbstractGameObject target) { - // Arg Count Check - Zone zone = null; - - if (player == null) { - throwbackError(player, "Unable to find the pc making the request."); - return; - } - - try { - int targetID = Integer.parseInt(words[0]); - - //try get zone by objectUUID - zone = ZoneManager.getZoneByUUID(targetID); - - //that failed, try get by zoneID - if (zone == null) - zone = ZoneManager.getZoneByZoneID(targetID); - - //no zone found, so fail - if (zone == null) { - throwbackError(player, "Zone with ID " + targetID + "not found"); - return; - } - } catch (Exception e) { - zone = ZoneManager.findSmallestZone(player.getLoc()); - } - - if (zone == null) { - throwbackError(player, "Zone not found"); - return; - } - - String newline = "\r\n "; - - - int objectUUID = zone.getObjectUUID(); - String output; - - output = "Target Information:" + newline; - output += StringUtils.addWS("UUID: " + objectUUID, 20); - output += newline; - output += "name: " + zone.getName(); - output += newline; - output += "loadNum: " + zone.getLoadNum(); - if (zone.getParent() != null) { - output += StringUtils.addWS(", parent: " + zone.getParent().getObjectUUID(), 30); - output += "Parentabs: x: " + zone.getParent().getAbsX() + ", y: " + zone.getParent().getAbsY() + ", z: " + zone.getParent().getAbsZ(); - - } else - output += StringUtils.addWS(", parent: none", 30); - output += newline; - output += "absLoc: x: " + zone.getAbsX() + ", y: " + zone.getAbsY() + ", z: " + zone.getAbsZ(); - output += newline; - output += "offset: x: " + zone.getXCoord() + ", y: " + zone.getYCoord() + ", z: " + zone.getZCoord(); - output += newline; - output += "radius: x: " + zone.getBounds().getHalfExtents().x + ", z: " + zone.getBounds().getHalfExtents().y; - output += newline; - - if (zone.getHeightMap() != null){ - output += "HeightMap ID: " + zone.getHeightMap().getHeightMapID(); - output += newline; - output += "Bucket Width X : " + zone.getHeightMap().getBucketWidthX(); - output += newline; - output += "Bucket Width Y : " + zone.getHeightMap().getBucketWidthY(); - - } - output += "radius: x: " + zone.getBounds().getHalfExtents().x + ", z: " + zone.getBounds().getHalfExtents().y; - output += newline; - // output += "minLvl = " + zone.getMinLvl() + " | maxLvl = " + zone.getMaxLvl(); - output += newline; - output += "Sea Level = " +zone.getSeaLevel(); - output += newline; - output += "World Altitude = " + zone.getWorldAltitude(); - throwbackInfo(player, output); - - City city = ZoneManager.getCityAtLocation(player.getLoc()); - - output += newline; - output += (city == null)? "None" : city.getParent().getName(); - - if (city != null ) { - - if (city.isLocationOnCityGrid(player.getLoc())) - output += " (Grid)"; - else if (city.isLocationOnCityZone(player.getLoc())) - output += " (Zone)"; - else if (city.isLocationWithinSiegeBounds(player.getLoc())) - output += " (Siege)"; - } else { - output = "children:"; - - ArrayList nodes = zone.getNodes(); - - if (nodes.isEmpty()) - output += " none"; - - for (Zone child : nodes) { - output += newline; - output += child.getName() + " (" + child.getLoadNum() + ')'; - } - } - throwbackInfo(player, output); - } - - @Override - protected String _getHelpString() { - return "Gets information on an Object."; - } - - @Override - protected String _getUsageString() { - return "' /info targetID'"; - } + @Override + protected void _doCmd(PlayerCharacter player, String[] words, + AbstractGameObject target) { + // Arg Count Check + Zone zone = null; + + if (player == null) { + throwbackError(player, "Unable to find the pc making the request."); + return; + } + + try { + int targetID = Integer.parseInt(words[0]); + + //try get zone by objectUUID + zone = ZoneManager.getZoneByUUID(targetID); + + //that failed, try get by zoneID + if (zone == null) + zone = ZoneManager.getZoneByZoneID(targetID); + + //no zone found, so fail + if (zone == null) { + throwbackError(player, "Zone with ID " + targetID + "not found"); + return; + } + } catch (Exception e) { + zone = ZoneManager.findSmallestZone(player.getLoc()); + } + + if (zone == null) { + throwbackError(player, "Zone not found"); + return; + } + + String newline = "\r\n "; + + + int objectUUID = zone.getObjectUUID(); + String output; + + output = "Target Information:" + newline; + output += StringUtils.addWS("UUID: " + objectUUID, 20); + output += newline; + output += "name: " + zone.getName(); + output += newline; + output += "loadNum: " + zone.getLoadNum(); + if (zone.getParent() != null) { + output += StringUtils.addWS(", parent: " + zone.getParent().getObjectUUID(), 30); + output += "Parentabs: x: " + zone.getParent().getAbsX() + ", y: " + zone.getParent().getAbsY() + ", z: " + zone.getParent().getAbsZ(); + + } else + output += StringUtils.addWS(", parent: none", 30); + output += newline; + output += "absLoc: x: " + zone.getAbsX() + ", y: " + zone.getAbsY() + ", z: " + zone.getAbsZ(); + output += newline; + output += "offset: x: " + zone.getXCoord() + ", y: " + zone.getYCoord() + ", z: " + zone.getZCoord(); + output += newline; + output += "radius: x: " + zone.getBounds().getHalfExtents().x + ", z: " + zone.getBounds().getHalfExtents().y; + output += newline; + + if (zone.getHeightMap() != null) { + output += "HeightMap ID: " + zone.getHeightMap().getHeightMapID(); + output += newline; + output += "Bucket Width X : " + zone.getHeightMap().getBucketWidthX(); + output += newline; + output += "Bucket Width Y : " + zone.getHeightMap().getBucketWidthY(); + + } + output += "radius: x: " + zone.getBounds().getHalfExtents().x + ", z: " + zone.getBounds().getHalfExtents().y; + output += newline; + // output += "minLvl = " + zone.getMinLvl() + " | maxLvl = " + zone.getMaxLvl(); + output += newline; + output += "Sea Level = " + zone.getSeaLevel(); + output += newline; + output += "World Altitude = " + zone.getWorldAltitude(); + throwbackInfo(player, output); + + City city = ZoneManager.getCityAtLocation(player.getLoc()); + + output += newline; + output += (city == null) ? "None" : city.getParent().getName(); + + if (city != null) { + + if (city.isLocationOnCityGrid(player.getLoc())) + output += " (Grid)"; + else if (city.isLocationOnCityZone(player.getLoc())) + output += " (Zone)"; + else if (city.isLocationWithinSiegeBounds(player.getLoc())) + output += " (Siege)"; + } else { + output = "children:"; + + ArrayList nodes = zone.getNodes(); + + if (nodes.isEmpty()) + output += " none"; + + for (Zone child : nodes) { + output += newline; + output += child.getName() + " (" + child.getLoadNum() + ')'; + } + } + throwbackInfo(player, output); + } + + @Override + protected String _getHelpString() { + return "Gets information on an Object."; + } + + @Override + protected String _getUsageString() { + return "' /info targetID'"; + } } diff --git a/src/engine/devcmd/cmds/aiInfoCmd.java b/src/engine/devcmd/cmds/aiInfoCmd.java index 5987e0b1..3f1c3869 100644 --- a/src/engine/devcmd/cmds/aiInfoCmd.java +++ b/src/engine/devcmd/cmds/aiInfoCmd.java @@ -9,25 +9,19 @@ package engine.devcmd.cmds; -import engine.Enum.BuildingGroup; import engine.Enum.GameObjectType; -import engine.Enum.TargetColor; import engine.devcmd.AbstractDevCmd; import engine.gameManager.BuildingManager; -import engine.gameManager.SessionManager; -import engine.math.Vector3fImmutable; -import engine.objects.*; -import engine.util.StringUtils; +import engine.objects.AbstractGameObject; +import engine.objects.Building; +import engine.objects.Mob; +import engine.objects.PlayerCharacter; -import java.text.DecimalFormat; -import java.util.ArrayList; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; /** * @author - * */ public class aiInfoCmd extends AbstractDevCmd { @@ -73,17 +67,17 @@ public class aiInfoCmd extends AbstractDevCmd { int objectUUID = target.getObjectUUID(); String output; - if(objType != GameObjectType.Mob){ + if (objType != GameObjectType.Mob) { output = "Please Select A Mob For AI Info" + newline; } else { Mob mob = (Mob) target; output = "Mob AI Information:" + newline; output += mob.getName() + newline; - if(mob.BehaviourType != null) { + if (mob.BehaviourType != null) { output += "BehaviourType: " + mob.BehaviourType.toString() + newline; - if(mob.BehaviourType.BehaviourHelperType != null) { + if (mob.BehaviourType.BehaviourHelperType != null) { output += "Behaviour Helper Type: " + mob.BehaviourType.BehaviourHelperType.toString() + newline; - } else{ + } else { output += "Behaviour Helper Type: NULL" + newline; } output += "Wimpy: " + mob.BehaviourType.isWimpy + newline; @@ -91,18 +85,18 @@ public class aiInfoCmd extends AbstractDevCmd { output += "Can Roam: " + mob.BehaviourType.canRoam + newline; output += "Calls For Help: " + mob.BehaviourType.callsForHelp + newline; output += "Responds To Call For Help: " + mob.BehaviourType.respondsToCallForHelp + newline; - } else{ + } else { output += "BehaviourType: NULL" + newline; } output += "Aggro Range: " + mob.getAggroRange() + newline; output += "Player Aggro Map Size: " + mob.playerAgroMap.size() + newline; - if(mob.playerAgroMap.size() > 0){ + if (mob.playerAgroMap.size() > 0) { output += "Players Loaded:" + newline; } - for(Map.Entry entry : mob.playerAgroMap.entrySet()){ + for (Map.Entry entry : mob.playerAgroMap.entrySet()) { output += "Player ID: " + entry.getKey() + " Is Safemode: " + entry.getValue() + newline; } - if(mob.getCombatTarget() != null) + if (mob.getCombatTarget() != null) output += "Current Target: " + mob.getCombatTarget().getName() + newline; else output += "Current Target: NULL" + newline; diff --git a/src/engine/devcmd/cmds/convertLoc.java b/src/engine/devcmd/cmds/convertLoc.java index 8190c6ee..e794e3fd 100644 --- a/src/engine/devcmd/cmds/convertLoc.java +++ b/src/engine/devcmd/cmds/convertLoc.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.devcmd.cmds; import engine.Enum.GameObjectType; @@ -21,42 +20,40 @@ import engine.objects.PlayerCharacter; public class convertLoc extends AbstractDevCmd { - public convertLoc() { + public convertLoc() { super("convertLoc"); } - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - - - if (target == null){ - Vector3fImmutable convertLoc = ZoneManager.findSmallestZone(pc.getLoc()).getLoc().subtract(pc.getLoc()); - ChatManager.chatSystemInfo(pc, Vector3fImmutable.toString(convertLoc)); - return; - } + @Override + protected void _doCmd(PlayerCharacter pc, String[] words, + AbstractGameObject target) { - if (target.getObjectType() != GameObjectType.Building) - return; - Building toConvert = (Building)target; - Vector3fImmutable convertedLoc = ZoneManager.convertWorldToLocal(toConvert, pc.getLoc()); - ChatManager.chatSystemInfo(pc, Vector3fImmutable.toString(convertedLoc)); + if (target == null) { + Vector3fImmutable convertLoc = ZoneManager.findSmallestZone(pc.getLoc()).getLoc().subtract(pc.getLoc()); + ChatManager.chatSystemInfo(pc, Vector3fImmutable.toString(convertLoc)); + return; + } + if (target.getObjectType() != GameObjectType.Building) + return; + Building toConvert = (Building) target; + Vector3fImmutable convertedLoc = ZoneManager.convertWorldToLocal(toConvert, pc.getLoc()); + ChatManager.chatSystemInfo(pc, Vector3fImmutable.toString(convertedLoc)); - } + } - @Override - protected String _getHelpString() { - return "Temporarily Changes SubRace"; - } + @Override + protected String _getHelpString() { + return "Temporarily Changes SubRace"; + } - @Override - protected String _getUsageString() { - return "' /setBuildingCollidables add/remove 'add creates a collision line.' needs 4 integers. startX, endX, startY, endY"; + @Override + protected String _getUsageString() { + return "' /setBuildingCollidables add/remove 'add creates a collision line.' needs 4 integers. startX, endX, startY, endY"; - } + } } diff --git a/src/engine/devcmd/cmds/simulateBootyCmd.java b/src/engine/devcmd/cmds/simulateBootyCmd.java index e1688e63..c6eed230 100644 --- a/src/engine/devcmd/cmds/simulateBootyCmd.java +++ b/src/engine/devcmd/cmds/simulateBootyCmd.java @@ -2,11 +2,13 @@ package engine.devcmd.cmds; import engine.Enum; import engine.devcmd.AbstractDevCmd; -import engine.gameManager.*; +import engine.gameManager.BuildingManager; +import engine.gameManager.NPCManager; import engine.objects.*; + import java.util.ArrayList; -public class simulateBootyCmd extends AbstractDevCmd { +public class simulateBootyCmd extends AbstractDevCmd { public simulateBootyCmd() { super("simulatebooty"); } @@ -70,7 +72,7 @@ public class simulateBootyCmd extends AbstractDevCmd { int maxRollRange = (mob.getLevel() * 2) + 120 + (mob.getParentZone().maxLvl * 2); output += "Roll Range: " + minRollRange + " - " + maxRollRange + newline; output += "Special Loot:" + newline; - if(mob.bootySet != 0) { + if (mob.bootySet != 0) { for (BootySetEntry entry : NPCManager._bootySetMap.get(mob.bootySet)) { ItemBase item = ItemBase.getItemBase(entry.itemBase); if (item != null) { @@ -108,14 +110,14 @@ public class simulateBootyCmd extends AbstractDevCmd { GlassItems.add(lootItem); } else { OtherDrops.add(lootItem); - if(lootItem.getName().toLowerCase().contains("crimson") || lootItem.getName().toLowerCase().contains("vorgrim") ||lootItem.getName().toLowerCase().contains("bell")){ + if (lootItem.getName().toLowerCase().contains("crimson") || lootItem.getName().toLowerCase().contains("vorgrim") || lootItem.getName().toLowerCase().contains("bell")) { output += lootItem.getName() + newline; } } break; default: OtherDrops.add(lootItem); - if(lootItem.getName().toLowerCase().contains("crimson") || lootItem.getName().toLowerCase().contains("vorgrim") ||lootItem.getName().toLowerCase().contains("bell")){ + if (lootItem.getName().toLowerCase().contains("crimson") || lootItem.getName().toLowerCase().contains("vorgrim") || lootItem.getName().toLowerCase().contains("bell")) { output += lootItem.getName() + newline; } break; @@ -126,20 +128,20 @@ public class simulateBootyCmd extends AbstractDevCmd { } } int respawnTime = mob.getMobBase().getSpawnTime(); - if(mob.spawnTime > 0){ + if (mob.spawnTime > 0) { respawnTime = mob.spawnTime; } output += "MobBase BootySet: " + mob.getMobBase().bootySet + newline; output += "Mob BootySet: " + mob.bootySet + newline; output += "Tables Rolled On: " + newline; - for(BootySetEntry entry : NPCManager._bootySetMap.get(mob.getMobBase().bootySet)){ + for (BootySetEntry entry : NPCManager._bootySetMap.get(mob.getMobBase().bootySet)) { output += "[" + entry.bootyType + "] " + entry.lootTable + newline; } output += "Time Required To Gain Simulated Booty: " + respawnTime * 100 + " Seconds" + newline; output += "GLASS DROPS: " + GlassItems.size() + newline; - output += "RUNE DROPS: " + Runes.size()+ newline; - output += "CONTRACTS DROPS: " + Contracts.size()+ newline; - output += "RESOURCE DROPS: " + Resources.size()+ newline; + output += "RUNE DROPS: " + Runes.size() + newline; + output += "CONTRACTS DROPS: " + Contracts.size() + newline; + output += "RESOURCE DROPS: " + Resources.size() + newline; output += "OFFERINGS DROPPED: " + Offerings.size() + newline; output += "OTHER ITEMS DROPPED: " + OtherDrops.size() + newline; output += "FAILED ROLLS: " + failures + newline; diff --git a/src/engine/exception/FactoryBuildException.java b/src/engine/exception/FactoryBuildException.java index e0293036..319bf2ba 100644 --- a/src/engine/exception/FactoryBuildException.java +++ b/src/engine/exception/FactoryBuildException.java @@ -11,22 +11,22 @@ package engine.exception; public class FactoryBuildException extends MBServerException { - private static final long serialVersionUID = 2331961867931593523L; + private static final long serialVersionUID = 2331961867931593523L; - public FactoryBuildException() { - super(); - } + public FactoryBuildException() { + super(); + } - public FactoryBuildException(String arg0, Throwable arg1) { - super(arg0, arg1); - } + public FactoryBuildException(String arg0, Throwable arg1) { + super(arg0, arg1); + } - public FactoryBuildException(String arg0) { - super(arg0); - } + public FactoryBuildException(String arg0) { + super(arg0); + } - public FactoryBuildException(Throwable arg0) { - super(arg0); - } + public FactoryBuildException(Throwable arg0) { + super(arg0); + } } diff --git a/src/engine/exception/MBServerException.java b/src/engine/exception/MBServerException.java index 3ede5360..3bd77543 100644 --- a/src/engine/exception/MBServerException.java +++ b/src/engine/exception/MBServerException.java @@ -13,26 +13,26 @@ import org.pmw.tinylog.Logger; public abstract class MBServerException extends Exception { - private static final long serialVersionUID = 3878845236025977250L; + private static final long serialVersionUID = 3878845236025977250L; - public MBServerException() { - super(); - } + public MBServerException() { + super(); + } - public MBServerException(String arg0, Throwable arg1) { - super(arg0, arg1); - } + public MBServerException(String arg0, Throwable arg1) { + super(arg0, arg1); + } - public MBServerException(String arg0) { - super(arg0); - } + public MBServerException(String arg0) { + super(arg0); + } - public MBServerException(Throwable arg0) { - super(arg0); - } + public MBServerException(Throwable arg0) { + super(arg0); + } - public void logException(String origin) { - Logger.error(origin, this.getClass().getSimpleName() + "(1): " + this.getMessage()); + public void logException(String origin) { + Logger.error(origin, this.getClass().getSimpleName() + "(1): " + this.getMessage()); - } + } } diff --git a/src/engine/exception/MsgSendException.java b/src/engine/exception/MsgSendException.java index b84fcd33..f789402f 100644 --- a/src/engine/exception/MsgSendException.java +++ b/src/engine/exception/MsgSendException.java @@ -7,25 +7,25 @@ // www.magicbane.com - package engine.exception; +package engine.exception; public class MsgSendException extends MBServerException { - private static final long serialVersionUID = 6927044139998382254L; + private static final long serialVersionUID = 6927044139998382254L; - public MsgSendException() { - super(); - } + public MsgSendException() { + super(); + } - public MsgSendException(String arg0, Throwable arg1) { - super(arg0, arg1); - } + public MsgSendException(String arg0, Throwable arg1) { + super(arg0, arg1); + } - public MsgSendException(String arg0) { - super(arg0); - } + public MsgSendException(String arg0) { + super(arg0); + } - public MsgSendException(Throwable arg0) { - super(arg0); - } + public MsgSendException(Throwable arg0) { + super(arg0); + } } diff --git a/src/engine/exception/SerializationException.java b/src/engine/exception/SerializationException.java index 0dd0066c..2381e619 100644 --- a/src/engine/exception/SerializationException.java +++ b/src/engine/exception/SerializationException.java @@ -7,25 +7,25 @@ // www.magicbane.com - package engine.exception; +package engine.exception; public class SerializationException extends MBServerException { - private static final long serialVersionUID = 6927044139998382254L; + private static final long serialVersionUID = 6927044139998382254L; - public SerializationException() { - super(); - } + public SerializationException() { + super(); + } - public SerializationException(String arg0, Throwable arg1) { - super(arg0, arg1); - } + public SerializationException(String arg0, Throwable arg1) { + super(arg0, arg1); + } - public SerializationException(String arg0) { - super(arg0); - } + public SerializationException(String arg0) { + super(arg0); + } - public SerializationException(Throwable arg0) { - super(arg0); - } + public SerializationException(Throwable arg0) { + super(arg0); + } } diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index b5ee8e94..b945c5a5 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.gameManager; import engine.Enum; @@ -315,7 +314,7 @@ public enum BuildingManager { for (AbstractCharacter slottedNPC : building.getHirelings().keySet()) { if (slottedNPC.getObjectType() == Enum.GameObjectType.NPC) - ((NPC)slottedNPC).remove(); + ((NPC) slottedNPC).remove(); else if (slottedNPC.getObjectType() == Enum.GameObjectType.Mob) NPCManager.removeMobileFromBuilding(((Mob) slottedNPC), building); } @@ -493,7 +492,7 @@ public enum BuildingManager { NPC npc = null; - npc = NPC.createNPC(pirateName, NpcID.getObjectUUID(), NpcLoc, null, false, zone, (short)rank, building); + npc = NPC.createNPC(pirateName, NpcID.getObjectUUID(), NpcLoc, null, false, zone, (short) rank, building); if (npc == null) return false; @@ -519,7 +518,8 @@ public enum BuildingManager { if (item.getChargesRemaining() > 0) rank = item.getChargesRemaining() * 10; - else rank = 10; + else + rank = 10; Mob mob; NPC npc; @@ -595,10 +595,10 @@ public enum BuildingManager { public static boolean IsOwner(Building building, PlayerCharacter player) { if (building == null || player == null) return false; - + if (building.getOwner() == null) - return false; - + return false; + return building.getOwner().getObjectUUID() == player.getObjectUUID(); @@ -650,54 +650,53 @@ public enum BuildingManager { } return null; } - - public static Vector3fImmutable GetBindLocationForBuilding(Building building){ - - Vector3fImmutable bindLoc = null; - - if (building == null) - return Enum.Ruins.getRandomRuin().getLocation(); - - - bindLoc = building.getLoc(); - - - float radius = Bounds.meshBoundsCache.get(building.getMeshUUID()).radius; - if ( building.getRank() == 8){ - bindLoc = building.getStuckLocation(); - if (bindLoc != null) - return bindLoc; - } - - float x = bindLoc.getX(); - float z = bindLoc.getZ(); - float offset = ((ThreadLocalRandom.current().nextFloat() * 2) - 1) * radius; - int direction = ThreadLocalRandom.current().nextInt(4); - - switch (direction) { - case 0: - x += radius; - z += offset; - break; - case 1: - x += offset; - z -= radius; - break; - case 2: - x -= radius; - z += offset; - break; - case 3: - x += offset; - z += radius; - break; - } - bindLoc = new Vector3fImmutable(x, bindLoc.getY(), z); - - return bindLoc; - - - + + public static Vector3fImmutable GetBindLocationForBuilding(Building building) { + + Vector3fImmutable bindLoc = null; + + if (building == null) + return Enum.Ruins.getRandomRuin().getLocation(); + + + bindLoc = building.getLoc(); + + + float radius = Bounds.meshBoundsCache.get(building.getMeshUUID()).radius; + if (building.getRank() == 8) { + bindLoc = building.getStuckLocation(); + if (bindLoc != null) + return bindLoc; + } + + float x = bindLoc.getX(); + float z = bindLoc.getZ(); + float offset = ((ThreadLocalRandom.current().nextFloat() * 2) - 1) * radius; + int direction = ThreadLocalRandom.current().nextInt(4); + + switch (direction) { + case 0: + x += radius; + z += offset; + break; + case 1: + x += offset; + z -= radius; + break; + case 2: + x -= radius; + z += offset; + break; + case 3: + x += offset; + z += radius; + break; + } + bindLoc = new Vector3fImmutable(x, bindLoc.getY(), z); + + return bindLoc; + + } } diff --git a/src/engine/gameManager/ChatManager.java b/src/engine/gameManager/ChatManager.java index 10c502e3..496cfb6c 100644 --- a/src/engine/gameManager/ChatManager.java +++ b/src/engine/gameManager/ChatManager.java @@ -47,6 +47,7 @@ public enum ChatManager { private static final String FLOOD_USER_ERROR = "You talk too much!"; private static final String SILENCED = "You find yourself mute!"; private static final String UNKNOWN_COMMAND = "No such command."; + /** * This method used when handling a ChatMsg received from the network. */ @@ -107,8 +108,8 @@ public enum ChatManager { ChatManager.chatIC(pc, (ChatICMsg) msg); return; case LEADERCHANNELMESSAGE: - ChatManager.chatGlobal(pc, msg.getMessage(), isFlood); - return; + ChatManager.chatGlobal(pc, msg.getMessage(), isFlood); + return; case GLOBALCHANNELMESSAGE: case CHATPVP: case CHATCITY: @@ -199,7 +200,7 @@ public enum ChatManager { } if (ChatManager.isVersionRequest(text) == true) { - sendSystemMessage(pcSender, ConfigManager.MB_WORLD_GREETING.getValue()); + sendSystemMessage(pcSender, ConfigManager.MB_WORLD_GREETING.getValue()); return; } @@ -247,7 +248,7 @@ public enum ChatManager { * Shout */ public static void chatShout(AbstractWorldObject sender, String text, - boolean isFlood) { + boolean isFlood) { PlayerCharacter pcSender = null; @@ -267,34 +268,34 @@ public enum ChatManager { DispatchMessage.dispatchMsgToInterestArea(pcSender, msg, engine.Enum.DispatchChannel.SECONDARY, MBServerStatics.SHOUT_RANGE, true, true); } - + public static void chatGlobal(PlayerCharacter sender, String text, - boolean isFlood) { + boolean isFlood) { -PlayerCharacter pcSender = null; + PlayerCharacter pcSender = null; -if (sender.getObjectType().equals(GameObjectType.PlayerCharacter)) -pcSender = (PlayerCharacter) sender; + if (sender.getObjectType().equals(GameObjectType.PlayerCharacter)) + pcSender = (PlayerCharacter) sender; -if (isFlood) { -ChatManager.chatSayError(pcSender, FLOOD_USER_ERROR); -return; -} + if (isFlood) { + ChatManager.chatSayError(pcSender, FLOOD_USER_ERROR); + return; + } -if (pcSender != null && testSilenced(pcSender)) -return; + if (pcSender != null && testSilenced(pcSender)) + return; // Make the Message -ChatGlobalMsg msg = new ChatGlobalMsg(sender, text); -DispatchMessage.dispatchMsgToAll(sender, msg, true); + ChatGlobalMsg msg = new ChatGlobalMsg(sender, text); + DispatchMessage.dispatchMsgToAll(sender, msg, true); -} + } /* * Tell */ public static void chatTell(AbstractWorldObject sender, String recipient, - String text, boolean isFlood) { + String text, boolean isFlood) { if (text.isEmpty()) return; @@ -323,7 +324,7 @@ DispatchMessage.dispatchMsgToAll(sender, msg, true); } public static void chatTell(AbstractWorldObject sender, - AbstractWorldObject recipient, String text) { + AbstractWorldObject recipient, String text) { PlayerCharacter pcSender = null; @@ -538,7 +539,7 @@ DispatchMessage.dispatchMsgToAll(sender, msg, true); } public static void GuildEnterWorldMsg(PlayerCharacter sender, - ClientConnection origin) { + ClientConnection origin) { // Verify sender has PlayerCharacter if (sender == null) return; @@ -643,7 +644,7 @@ DispatchMessage.dispatchMsgToAll(sender, msg, true); ChatManager.chatSystemSend(senderList, textToThief, 1, 2); if (target != null && !textToVictim.isEmpty()) { - HashSet victimList = new HashSet<>(); + HashSet victimList = new HashSet<>(); victimList.add(target); ChatManager.chatSystemSend(victimList, textToVictim, 1, 2); } @@ -774,7 +775,7 @@ DispatchMessage.dispatchMsgToAll(sender, msg, true); } public static void chatGroupInfoCanSee(PlayerCharacter pc, String text) { - HashSet distroList = null; + HashSet distroList = null; Group group = GroupManager.getGroup(pc); if (group != null) { @@ -838,7 +839,7 @@ DispatchMessage.dispatchMsgToAll(sender, msg, true); // Send Info Message to guild channel based on guild public static void chatGuildInfo(Guild guild, String text) { - HashSet distroList = null; + HashSet distroList = null; if (guild != null) distroList = ChatManager.getGuildList(guild, null); ChatManager.chatSystemSend(distroList, text, 12, 2); @@ -846,7 +847,7 @@ DispatchMessage.dispatchMsgToAll(sender, msg, true); public static void chatSystemMOTD(PlayerCharacter sender, String text, int channel, int messageType) { - HashSet distroList = ChatManager.getOwnPlayer(sender); + HashSet distroList = ChatManager.getOwnPlayer(sender); ChatManager.chatSystemSend(distroList, text, channel, messageType); } @@ -857,7 +858,7 @@ DispatchMessage.dispatchMsgToAll(sender, msg, true); } public static void chatInfo(String text) { - HashSet distroList = ChatManager.getAllPlayers(null); + HashSet distroList = ChatManager.getAllPlayers(null); chatSystemSend(distroList, text, 1, 2); } @@ -871,7 +872,7 @@ DispatchMessage.dispatchMsgToAll(sender, msg, true); public static void chatSystem(PlayerCharacter sender, String text, int channel, int messageType) { - HashSet distroList = null; + HashSet distroList = null; if (channel == 1) // System Channel Message distroList = ChatManager.getAllPlayers(sender); @@ -924,7 +925,7 @@ DispatchMessage.dispatchMsgToAll(sender, msg, true); public static void chatSystemGuild(Guild sender, String text, int channel, int messageType) { - HashSet distroList = null; + HashSet distroList = null; if (channel == 5) { // Nation Channel, get Nation list if (sender != null) { @@ -976,7 +977,7 @@ DispatchMessage.dispatchMsgToAll(sender, msg, true); // Get distroList for guild public static HashSet getGuildList(Guild guild, PlayerCharacter source) { - HashSet distroList = new HashSet<>(); + HashSet distroList = new HashSet<>(); for (PlayerCharacter playerCharacter : SessionManager.getAllActivePlayerCharacters()) { @@ -992,7 +993,7 @@ DispatchMessage.dispatchMsgToAll(sender, msg, true); // Get distroList for guild IC's public static HashSet getGuildICList(Guild guild, PlayerCharacter source) { - HashSet distroList = new HashSet<>(); + HashSet distroList = new HashSet<>(); for (PlayerCharacter pc : SessionManager.getAllActivePlayerCharacters()) { @@ -1008,7 +1009,7 @@ DispatchMessage.dispatchMsgToAll(sender, msg, true); // Get distroList for group public static HashSet getGroupList(Group group, PlayerCharacter source) { - HashSet distroList = new HashSet<>(); + HashSet distroList = new HashSet<>(); Set players = group.getMembers(); for (PlayerCharacter pc : players) { if (source != null && pc.isIgnoringPlayer(source)) @@ -1020,7 +1021,7 @@ DispatchMessage.dispatchMsgToAll(sender, msg, true); // Get distroList for nation public static HashSet getNationList(Guild nation, PlayerCharacter source) { - HashSet distroList = new HashSet<>(); + HashSet distroList = new HashSet<>(); for (PlayerCharacter pc : SessionManager.getAllActivePlayerCharacters()) { @@ -1056,7 +1057,7 @@ DispatchMessage.dispatchMsgToAll(sender, msg, true); // Get distroList for all players public static HashSet getAllPlayers(PlayerCharacter source) { - HashSet distroList = new HashSet<>(); + HashSet distroList = new HashSet<>(); for (PlayerCharacter pc : SessionManager.getAllActivePlayerCharacters()) { if (source != null && pc.isIgnoringPlayer(source)) continue; // dont add if recip has ignored source @@ -1218,7 +1219,7 @@ DispatchMessage.dispatchMsgToAll(sender, msg, true); else if (cmd.compareTo("getinfo") == 0) devCmd = "info"; else if (devCmd.isEmpty()) { - Logger.info( "Unhandled admin command was used: /" + Logger.info("Unhandled admin command was used: /" + cmd); return; } diff --git a/src/engine/gameManager/CombatManager.java b/src/engine/gameManager/CombatManager.java index fae77eb0..843d7824 100644 --- a/src/engine/gameManager/CombatManager.java +++ b/src/engine/gameManager/CombatManager.java @@ -9,7 +9,6 @@ package engine.gameManager; import engine.Enum.*; -import engine.ai.MobileFSM; import engine.exception.MsgSendException; import engine.job.JobContainer; import engine.job.JobScheduler; @@ -28,7 +27,6 @@ import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; import java.util.HashSet; -import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadLocalRandom; @@ -38,6 +36,8 @@ public enum CombatManager { COMBATMANAGER; + public static int animation = 0; + /** * Message sent by player to attack something. */ @@ -60,7 +60,7 @@ public enum CombatManager { //source must match player this account belongs to if (player.getObjectUUID() != msg.getSourceID() || player.getObjectType().ordinal() != msg.getSourceType()) { - Logger.error("Msg Source ID " + msg.getSourceID() + " Does not Match Player ID " + player.getObjectUUID() ); + Logger.error("Msg Source ID " + msg.getSourceID() + " Does not Match Player ID " + player.getObjectUUID()); return; } @@ -73,7 +73,7 @@ public enum CombatManager { target = BuildingManager.getBuildingFromCache(msg.getTargetID()); } else if (targetType == GameObjectType.Mob.ordinal()) { target = Mob.getFromCache(msg.getTargetID()); - }else{ + } else { player.setCombatTarget(null); return; //not valid type to attack } @@ -137,7 +137,7 @@ public enum CombatManager { } } City playerCity = ZoneManager.getCityAtLocation(playerCharacter.getLoc()); - if( playerCity != null && playerCity.getGuild().getNation().equals(playerCharacter.getGuild().getNation()) == false && playerCity.cityOutlaws.contains(playerCharacter.getObjectUUID()) == false) + if (playerCity != null && playerCity.getGuild().getNation().equals(playerCharacter.getGuild().getNation()) == false && playerCity.cityOutlaws.contains(playerCharacter.getObjectUUID()) == false) playerCity.cityOutlaws.add(playerCharacter.getObjectUUID()); } @@ -173,7 +173,7 @@ public enum CombatManager { pet.setCombatTarget(null); return; //not valid type to attack } - + if (pet.equals(target)) return; @@ -184,10 +184,9 @@ public enum CombatManager { return; - //set sources target pet.setCombatTarget(target); - // setFirstHitCombatTarget(player,target); + // setFirstHitCombatTarget(player,target); //put in combat if not already if (!pet.isCombat()) @@ -292,10 +291,10 @@ public enum CombatManager { AbstractWorldObject target = abstractCharacter.getCombatTarget(); - if (target == null){ + if (target == null) { return 0; } - + //target must be valid type if (AbstractWorldObject.IsAbstractCharacter(target)) { @@ -303,11 +302,9 @@ public enum CombatManager { //must be alive, attackable and in World if (!tar.isAlive()) { return 0; - } - else if (tar.isSafeMode()) { + } else if (tar.isSafeMode()) { return 0; - } - else if (!tar.isActive()) { + } else if (!tar.isActive()) { return 0; } @@ -327,8 +324,7 @@ public enum CombatManager { } } } - } - else if (target.getObjectType().equals(GameObjectType.Building)) { + } else if (target.getObjectType().equals(GameObjectType.Building)) { Building tar = (Building) target; // Cannot attack an invuln building @@ -337,16 +333,14 @@ public enum CombatManager { return 0; } - } - else { + } else { return 0; //only characters and buildings may be attacked } //source must be in world and alive if (!abstractCharacter.isActive()) { return 0; - } - else if (!abstractCharacter.isAlive()) { + } else if (!abstractCharacter.isAlive()) { return 0; } @@ -384,13 +378,11 @@ public enum CombatManager { ItemBase wb = null; if (weapon == null) { isWeapon = false; - } - else { + } else { ItemBase ib = weapon.getItemBase(); if (ib == null || !ib.getType().equals(ItemType.WEAPON)) { isWeapon = false; - } - else { + } else { wb = ib; } } @@ -405,17 +397,14 @@ public enum CombatManager { ItemBase ib = weaponOff.getItemBase(); if (ib == null || !ib.getType().equals(ItemType.WEAPON)) { hasNoWeapon = true; - } - else { + } else { // debugCombat(ac, "mainhand, weapon in other hand"); return 1; //no need to attack with this hand } - } - else { + } else { hasNoWeapon = true; } - } - else { + } else { if (equipped.get(MBServerStatics.SLOT_MAINHAND) == null) { // debgCombat(ac, "offhand, weapon in other hand"); return 1; //no need to attack with this hand @@ -439,8 +428,7 @@ public enum CombatManager { // debugCombat(ac, "Not enough stamina to attack"); attackFailure = true; } - } - else if (abstractCharacter.getStamina() < wb.getWeight()) { + } else if (abstractCharacter.getStamina() < wb.getWeight()) { // debugCombat(ac, "Not enough stamina to attack"); attackFailure = true; } @@ -453,7 +441,7 @@ public enum CombatManager { // } //see if attacker is stunned. If so, stop here bonus = abstractCharacter.getBonuses(); - if (bonus != null && bonus.getBool(ModType.Stunned,SourceType.None)) { + if (bonus != null && bonus.getBool(ModType.Stunned, SourceType.None)) { // debugCombat(ac, "Cannot attack while stunned"); attackFailure = true; } @@ -462,13 +450,12 @@ public enum CombatManager { float range; if (hasNoWeapon) { range = MBServerStatics.NO_WEAPON_RANGE; - } - else { + } else { range = getWeaponRange(wb); - if (bonus != null){ + if (bonus != null) { float buffRange = 1; - buffRange += bonus.getFloat(ModType.WeaponRange, SourceType.None) *.01f; - range*= buffRange; + buffRange += bonus.getFloat(ModType.WeaponRange, SourceType.None) * .01f; + range *= buffRange; } } @@ -504,8 +491,7 @@ public enum CombatManager { if (!attackFailure) { if (hasNoWeapon || abstractCharacter.getObjectType().equals(GameObjectType.Mob)) { createTimer(abstractCharacter, slot, 20, true); //2 second for no weapon - } - else { + } else { int wepSpeed = (int) (wb.getSpeed()); if (weapon != null && weapon.getBonusPercent(ModType.WeaponSpeed, SourceType.None) != 0f) //add weapon speed bonus { @@ -525,14 +511,13 @@ public enum CombatManager { return 0; attack(abstractCharacter, target, weapon, wb, (slot == MBServerStatics.SLOT_MAINHAND) ? true : false); - } - else { + } else { // changed this to half a second to make combat attempts more aggressive than movement sync createTimer(abstractCharacter, slot, 5, false); //0.5 second timer if attack fails //System.out.println("Attack attempt failed"); } - } catch(Exception e) { + } catch (Exception e) { return 0; } return 2; @@ -576,7 +561,7 @@ public enum CombatManager { job = JobScheduler.getInstance().scheduleJob(aj, (time * 100)); timers.put("Attack" + slot, job); } else { - Logger.error( "Unable to find Timers for Character " + ac.getObjectUUID()); + Logger.error("Unable to find Timers for Character " + ac.getObjectUUID()); } } @@ -601,8 +586,7 @@ public enum CombatManager { atr = ac.getAtrHandOne(); minDamage = ac.getMinDamageHandOne(); maxDamage = ac.getMaxDamageHandOne(); - } - else { + } else { atr = ac.getAtrHandTwo(); minDamage = ac.getMinDamageHandTwo(); maxDamage = ac.getMaxDamageHandTwo(); @@ -612,20 +596,20 @@ public enum CombatManager { if (target.getObjectTypeMask() == MBServerStatics.MASK_RAT) tarIsRat = true; - else if (target.getObjectType() == GameObjectType.PlayerCharacter){ - PlayerCharacter pTar = (PlayerCharacter)target; - for (Effect eff: pTar.getEffects().values()){ - if (eff.getPowerToken() == 429513599 || eff.getPowerToken() == 429415295){ + else if (target.getObjectType() == GameObjectType.PlayerCharacter) { + PlayerCharacter pTar = (PlayerCharacter) target; + for (Effect eff : pTar.getEffects().values()) { + if (eff.getPowerToken() == 429513599 || eff.getPowerToken() == 429415295) { tarIsRat = true; } } } //Dont think we need to do this anymore. - if (tarIsRat){ + if (tarIsRat) { //strip away current % dmg buffs then add with rat % - if (ac.getBonuses().getFloatPercentAll(ModType.Slay, SourceType.Rat) != 0){ - + if (ac.getBonuses().getFloatPercentAll(ModType.Slay, SourceType.Rat) != 0) { + float percent = 1 + ac.getBonuses().getFloatPercentAll(ModType.Slay, SourceType.Rat); @@ -640,8 +624,7 @@ public enum CombatManager { //subtract stamina if (wb == null) { ac.modifyStamina(-0.5f, ac, true); - } - else { + } else { float stam = wb.getWeight() / 3; stam = (stam < 1) ? 1 : stam; ac.modifyStamina(-(stam), ac, true); @@ -655,8 +638,7 @@ public enum CombatManager { if (target.getObjectType().equals(GameObjectType.PlayerCharacter) && target.getObjectUUID() != ac.getObjectUUID() && ac.getObjectType() == GameObjectType.PlayerCharacter) { ac.setTimeStamp("LastCombatPlayer", System.currentTimeMillis()); ((PlayerCharacter) target).setTimeStamp("LastCombatPlayer", System.currentTimeMillis()); - } - else { + } else { ac.setTimeStamp("LastCombatMob", System.currentTimeMillis()); } @@ -665,20 +647,20 @@ public enum CombatManager { //Get defense for target float defense; if (target.getObjectType().equals(GameObjectType.Building)) { - - if (BuildingManager.getBuildingFromCache(target.getObjectUUID()) == null){ + + if (BuildingManager.getBuildingFromCache(target.getObjectUUID()) == null) { ac.setCombatTarget(null); return; } defense = 0; - Building building = (Building)target; - if (building.getParentZone() != null && building.getParentZone().isPlayerCity()){ + Building building = (Building) target; + if (building.getParentZone() != null && building.getParentZone().isPlayerCity()) { - if (System.currentTimeMillis() > building.getTimeStamp("CallForHelp")){ + if (System.currentTimeMillis() > building.getTimeStamp("CallForHelp")) { building.getTimestamps().put("CallForHelp", System.currentTimeMillis() + 15000); int count = 0; - for (Mob mob:building.getParentZone().zoneMobSet){ + for (Mob mob : building.getParentZone().zoneMobSet) { if (!mob.isPlayerGuard()) continue; if (mob.getCombatTarget() != null) @@ -694,11 +676,10 @@ public enum CombatManager { count++; mob.setCombatTarget(ac); - } + } } } - } - else { + } else { AbstractCharacter tar = (AbstractCharacter) target; defense = tar.getDefenseRating(); //Handle target attacking back if in combat and has no other target @@ -712,11 +693,9 @@ public enum CombatManager { float dif = atr - defense; if (dif > 100) { chance = 94; - } - else if (dif < -100) { + } else if (dif < -100) { chance = 4; - } - else { + } else { chance = (int) ((0.45 * dif) + 49); } @@ -755,11 +734,11 @@ public enum CombatManager { dpj.attack(target, attackRange); if (dpj.getPower() != null && (dpj.getPowerToken() == -1851459567 || dpj.getPowerToken() == -1851489518)) - ((PlayerCharacter)ac).setWeaponPower(dpj); + ((PlayerCharacter) ac).setWeaponPower(dpj); } } //check to apply second backstab. - if (ac.getObjectType().equals(GameObjectType.PlayerCharacter) && !mainHand){ + if (ac.getObjectType().equals(GameObjectType.PlayerCharacter) && !mainHand) { dpj = ((PlayerCharacter) ac).getWeaponPower(); if (dpj != null && dpj.getPower() != null && (dpj.getPowerToken() == -1851459567 || dpj.getPowerToken() == -1851489518)) { float attackRange = getWeaponRange(wb); @@ -780,7 +759,7 @@ public enum CombatManager { if (!target.isAlive()) return; - sendPassiveDefenseMessage(ac, wb, target, MBServerStatics.COMBAT_SEND_BLOCK, dpj,mainHand); + sendPassiveDefenseMessage(ac, wb, target, MBServerStatics.COMBAT_SEND_BLOCK, dpj, mainHand); passiveFired = true; } @@ -789,7 +768,7 @@ public enum CombatManager { if (canTestParry(ac, target) && testPassive(ac, tarAc, "Parry")) { if (!target.isAlive()) return; - sendPassiveDefenseMessage(ac, wb, target, MBServerStatics.COMBAT_SEND_PARRY, dpj,mainHand); + sendPassiveDefenseMessage(ac, wb, target, MBServerStatics.COMBAT_SEND_PARRY, dpj, mainHand); passiveFired = true; } } @@ -804,7 +783,7 @@ public enum CombatManager { if (!target.isAlive()) return; - sendPassiveDefenseMessage(ac, wb, target, MBServerStatics.COMBAT_SEND_DODGE, dpj,mainHand); + sendPassiveDefenseMessage(ac, wb, target, MBServerStatics.COMBAT_SEND_DODGE, dpj, mainHand); passiveFired = true; } } @@ -827,11 +806,9 @@ public enum CombatManager { DamageType damageType; if (wb != null) { damageType = wb.getDamageType(); - } - else if (ac.getObjectType().equals(GameObjectType.Mob) && ((Mob) ac).isSiege()) { + } else if (ac.getObjectType().equals(GameObjectType.Mob) && ((Mob) ac).isSiege()) { damageType = DamageType.Siege; - } - else { + } else { damageType = DamageType.Crush; } @@ -842,14 +819,13 @@ public enum CombatManager { if (tarAc != null) { resists = tarAc.getResists(); - } - else if (target.getObjectType().equals(GameObjectType.Building)) { + } else if (target.getObjectType().equals(GameObjectType.Building)) { resists = ((Building) target).getResists(); } //make sure target is not immune to damage type; if (resists != null && resists.immuneTo(damageType)) { - sendCombatMessage(ac, target, 0f, wb, dpj,mainHand); + sendCombatMessage(ac, target, 0f, wb, dpj, mainHand); return; } @@ -865,8 +841,7 @@ public enum CombatManager { if (wb != null) { damage = calculateDamage(ac, tarAc, minDamage, maxDamage, damageType, resists); - } - else { + } else { damage = calculateDamage(ac, tarAc, minDamage, maxDamage, damageType, resists); } @@ -887,10 +862,9 @@ public enum CombatManager { if (tarAc.getHealth() > 0) d = tarAc.modifyHealth(-damage, ac, false); - } - else if (target.getObjectType().equals(GameObjectType.Building)) { - - if (BuildingManager.getBuildingFromCache(target.getObjectUUID()) == null){ + } else if (target.getObjectType().equals(GameObjectType.Building)) { + + if (BuildingManager.getBuildingFromCache(target.getObjectUUID()) == null) { ac.setCombatTarget(null); return; } @@ -910,7 +884,7 @@ public enum CombatManager { //test double death fix if (d != 0) { - sendCombatMessage(ac, target, damage, wb, dpj,mainHand); //send damage message + sendCombatMessage(ac, target, damage, wb, dpj, mainHand); //send damage message } errorTrack = 14; @@ -945,8 +919,7 @@ public enum CombatManager { if (ac.isAlive() && tarAc != null && tarAc.isAlive()) { handleDamageShields(ac, tarAc, damage); } - } - else { + } else { int animationOverride = 0; // Apply Weapon power effect if any. // don't try to apply twice if dual wielding. @@ -958,9 +931,8 @@ public enum CombatManager { PowersBase wp = dpj.getPower(); if (wp.requiresHitRoll() == false) { float attackRange = getWeaponRange(wb); - dpj.attack(target,attackRange); - } - else { + dpj.attack(target, attackRange); + } else { ((PlayerCharacter) ac).setWeaponPower(null); } @@ -973,7 +945,7 @@ public enum CombatManager { errorTrack = 17; //miss, Send miss message - sendCombatMessage(ac, target, 0f, wb, dpj,mainHand); + sendCombatMessage(ac, target, 0f, wb, dpj, mainHand); //if attacker is player, set last attack timestamp if (ac.getObjectType().equals(GameObjectType.PlayerCharacter)) { @@ -1026,7 +998,6 @@ public enum CombatManager { return false; - Item tarOff = tarItem.getItemFromEquipped(2); @@ -1060,7 +1031,7 @@ public enum CombatManager { //Damage is calculated twice to average a more central point float damage = ThreadLocalRandom.current().nextFloat() * range; - damage = (damage + (ThreadLocalRandom.current().nextFloat() * range)) *.5f; + damage = (damage + (ThreadLocalRandom.current().nextFloat() * range)) * .5f; //put it back between min and max damage += minDamage; @@ -1075,29 +1046,29 @@ public enum CombatManager { private static void sendPassiveDefenseMessage(AbstractCharacter source, ItemBase wb, AbstractWorldObject target, int passiveType, DeferredPowerJob dpj, boolean mainHand) { - int swingAnimation = getSwingAnimation(wb, dpj,mainHand); + int swingAnimation = getSwingAnimation(wb, dpj, mainHand); - if (dpj != null){ - if(PowersManager.AnimationOverrides.containsKey(dpj.getAction().getEffectID())) + if (dpj != null) { + if (PowersManager.AnimationOverrides.containsKey(dpj.getAction().getEffectID())) swingAnimation = PowersManager.AnimationOverrides.get(dpj.getAction().getEffectID()); } - TargetedActionMsg cmm = new TargetedActionMsg(source,swingAnimation, target, passiveType); + TargetedActionMsg cmm = new TargetedActionMsg(source, swingAnimation, target, passiveType); DispatchMessage.sendToAllInRange(target, cmm); } private static void sendCombatMessage(AbstractCharacter source, AbstractWorldObject target, float damage, ItemBase wb, DeferredPowerJob dpj, boolean mainHand) { - int swingAnimation = getSwingAnimation(wb, dpj,mainHand); + int swingAnimation = getSwingAnimation(wb, dpj, mainHand); - if (dpj != null){ - if(PowersManager.AnimationOverrides.containsKey(dpj.getAction().getEffectID())) + if (dpj != null) { + if (PowersManager.AnimationOverrides.containsKey(dpj.getAction().getEffectID())) swingAnimation = PowersManager.AnimationOverrides.get(dpj.getAction().getEffectID()); } - if (source.getObjectType() == GameObjectType.PlayerCharacter){ - for (Effect eff: source.getEffects().values()){ - if (eff.getPower() != null && (eff.getPower().getToken() == 429506943 || eff.getPower().getToken() == 429408639 || eff.getPower().getToken() == 429513599 ||eff.getPower().getToken() == 429415295)) + if (source.getObjectType() == GameObjectType.PlayerCharacter) { + for (Effect eff : source.getEffects().values()) { + if (eff.getPower() != null && (eff.getPower().getToken() == 429506943 || eff.getPower().getToken() == 429408639 || eff.getPower().getToken() == 429513599 || eff.getPower().getToken() == 429415295)) swingAnimation = 0; } } @@ -1105,8 +1076,6 @@ public enum CombatManager { DispatchMessage.sendToAllInRange(target, cmm); } - public static int animation = 0; - public static int getSwingAnimation(ItemBase wb, DeferredPowerJob dpj, boolean mainHand) { int token = 0; if (dpj != null) { @@ -1125,57 +1094,56 @@ public enum CombatManager { if (wb == null) { return 75; } - if (mainHand){ - if (wb.getAnimations().size() > 0){ + if (mainHand) { + if (wb.getAnimations().size() > 0) { int animation = wb.getAnimations().get(0); int random = ThreadLocalRandom.current().nextInt(wb.getAnimations().size()); - try{ + try { animation = wb.getAnimations().get(random); return animation; - }catch(Exception e){ - Logger.error( e.getMessage()); + } catch (Exception e) { + Logger.error(e.getMessage()); return wb.getAnimations().get(0); } - }else if (wb.getOffHandAnimations().size() > 0){ + } else if (wb.getOffHandAnimations().size() > 0) { int animation = wb.getOffHandAnimations().get(0); int random = ThreadLocalRandom.current().nextInt(wb.getOffHandAnimations().size()); - try{ + try { animation = wb.getOffHandAnimations().get(random); return animation; - }catch(Exception e){ - Logger.error( e.getMessage()); + } catch (Exception e) { + Logger.error(e.getMessage()); return wb.getOffHandAnimations().get(0); } } - }else{ - if (wb.getOffHandAnimations().size() > 0){ + } else { + if (wb.getOffHandAnimations().size() > 0) { int animation = wb.getOffHandAnimations().get(0); int random = ThreadLocalRandom.current().nextInt(wb.getOffHandAnimations().size()); - try{ + try { animation = wb.getOffHandAnimations().get(random); return animation; - }catch(Exception e){ - Logger.error( e.getMessage()); + } catch (Exception e) { + Logger.error(e.getMessage()); return wb.getOffHandAnimations().get(0); } - }else - if (wb.getAnimations().size() > 0){ - int animation = wb.getAnimations().get(0); - int random = ThreadLocalRandom.current().nextInt(wb.getAnimations().size()); - try{ - animation = wb.getAnimations().get(random); - return animation; - }catch(Exception e){ - Logger.error( e.getMessage()); - return wb.getAnimations().get(0); - - } + } else if (wb.getAnimations().size() > 0) { + int animation = wb.getAnimations().get(0); + int random = ThreadLocalRandom.current().nextInt(wb.getAnimations().size()); + try { + animation = wb.getAnimations().get(random); + return animation; + } catch (Exception e) { + Logger.error(e.getMessage()); + return wb.getAnimations().get(0); } + + } } @@ -1290,7 +1258,7 @@ public enum CombatManager { UpdateStateMsg rwss = new UpdateStateMsg(); rwss.setPlayer(pc); - DispatchMessage.dispatchMsgToInterestArea(pc, rwss, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true,false); + DispatchMessage.dispatchMsgToInterestArea(pc, rwss, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); } public static boolean NotInRange(AbstractCharacter ac, AbstractWorldObject target, float range) { @@ -1313,16 +1281,16 @@ public enum CombatManager { if (ac.equals(tarAc)) { return; } - + if (tarAc.isMoving() && tarAc.getObjectType().equals(GameObjectType.PlayerCharacter)) return; - + if (!tarAc.isAlive() || !ac.isAlive()) return; boolean isCombat = tarAc.isCombat(); //If target in combat and has no target, then attack back AbstractWorldObject awoCombTar = tarAc.getCombatTarget(); - if ((tarAc.isCombat() && awoCombTar == null) || (isCombat && awoCombTar != null && (!awoCombTar.isAlive() ||tarAc.isCombat() && NotInRange(tarAc, awoCombTar, tarAc.getRange()))) || (tarAc != null && tarAc.getObjectType() == GameObjectType.Mob && ((Mob) tarAc).isSiege())) { + if ((tarAc.isCombat() && awoCombTar == null) || (isCombat && awoCombTar != null && (!awoCombTar.isAlive() || tarAc.isCombat() && NotInRange(tarAc, awoCombTar, tarAc.getRange()))) || (tarAc != null && tarAc.getObjectType() == GameObjectType.Mob && ((Mob) tarAc).isSiege())) { // we are in combat with no valid target if (tarAc.getObjectType().equals(GameObjectType.PlayerCharacter)) { PlayerCharacter pc = (PlayerCharacter) tarAc; @@ -1341,7 +1309,7 @@ public enum CombatManager { Mob pet = ((PlayerCharacter) tarAc).getPet(); if (pet != null && pet.assist() && pet.getCombatTarget() == null) { pet.setCombatTarget(ac); - } + } } //Handle Mob Retaliate. @@ -1353,7 +1321,7 @@ public enum CombatManager { return; retaliater.setCombatTarget(ac); - } + } } public static void handleDamageShields(AbstractCharacter ac, AbstractCharacter target, float damage) { @@ -1385,7 +1353,7 @@ public enum CombatManager { //apply Damage back ac.modifyHealth(-total, target, true); - TargetedActionMsg cmm = new TargetedActionMsg(ac,ac, total, 0); + TargetedActionMsg cmm = new TargetedActionMsg(ac, ac, total, 0); DispatchMessage.sendToAllInRange(target, cmm); } @@ -1395,32 +1363,32 @@ public enum CombatManager { public static float calcHitBox(AbstractWorldObject ac) { //TODO Figure out how Str Affects HitBox float hitBox = 1; - switch(ac.getObjectType()){ - case PlayerCharacter: - PlayerCharacter pc = (PlayerCharacter)ac; - if (MBServerStatics.COMBAT_TARGET_HITBOX_DEBUG) { - Logger.info("Hit box radius for " + pc.getFirstName() + " is " + ((int) pc.statStrBase / 20f)); - } - hitBox = 1.5f + (int) ((PlayerCharacter) ac).statStrBase / 20f; - break; - - case Mob: - Mob mob = (Mob)ac; - if (MBServerStatics.COMBAT_TARGET_HITBOX_DEBUG) - Logger.info( "Hit box radius for " + mob.getFirstName() - + " is " + ((Mob) ac).getMobBase().getHitBoxRadius()); - - hitBox = ((Mob) ac).getMobBase().getHitBoxRadius(); - break; - case Building: - Building building = (Building)ac; - if (building.getBlueprint() == null) - return 32; - hitBox = Math.max(building.getBlueprint().getBuildingGroup().getExtents().x, - building.getBlueprint().getBuildingGroup().getExtents().y); - if (MBServerStatics.COMBAT_TARGET_HITBOX_DEBUG) - Logger.info( "Hit box radius for " + building.getName() + " is " + hitBox); - break; + switch (ac.getObjectType()) { + case PlayerCharacter: + PlayerCharacter pc = (PlayerCharacter) ac; + if (MBServerStatics.COMBAT_TARGET_HITBOX_DEBUG) { + Logger.info("Hit box radius for " + pc.getFirstName() + " is " + ((int) pc.statStrBase / 20f)); + } + hitBox = 1.5f + (int) ((PlayerCharacter) ac).statStrBase / 20f; + break; + + case Mob: + Mob mob = (Mob) ac; + if (MBServerStatics.COMBAT_TARGET_HITBOX_DEBUG) + Logger.info("Hit box radius for " + mob.getFirstName() + + " is " + ((Mob) ac).getMobBase().getHitBoxRadius()); + + hitBox = ((Mob) ac).getMobBase().getHitBoxRadius(); + break; + case Building: + Building building = (Building) ac; + if (building.getBlueprint() == null) + return 32; + hitBox = Math.max(building.getBlueprint().getBuildingGroup().getExtents().x, + building.getBlueprint().getBuildingGroup().getExtents().y); + if (MBServerStatics.COMBAT_TARGET_HITBOX_DEBUG) + Logger.info("Hit box radius for " + building.getName() + " is " + hitBox); + break; } return hitBox; diff --git a/src/engine/gameManager/ConfigManager.java b/src/engine/gameManager/ConfigManager.java index e51282f0..75fffdf4 100644 --- a/src/engine/gameManager/ConfigManager.java +++ b/src/engine/gameManager/ConfigManager.java @@ -132,8 +132,11 @@ public enum ConfigManager { // Get the value associated with this enumeration - public String getValue() { - return configMap.get(this.name()); + public String getValue() { + return configMap.get(this.name()); + } + + public void setValue(String value) { + configMap.put(this.name(), value); } - public void setValue(String value) { configMap.put(this.name(), value); } } diff --git a/src/engine/gameManager/DbManager.java b/src/engine/gameManager/DbManager.java index 94282831..a2e2522f 100644 --- a/src/engine/gameManager/DbManager.java +++ b/src/engine/gameManager/DbManager.java @@ -25,304 +25,299 @@ import java.util.EnumMap; import java.util.concurrent.ConcurrentHashMap; public enum DbManager { - DBMANAGER; + DBMANAGER; + + public static final dbAccountHandler AccountQueries = new dbAccountHandler(); + public static final dbBaneHandler BaneQueries = new dbBaneHandler(); + + //Local Object Caching + public static final dbBaseClassHandler BaseClassQueries = new dbBaseClassHandler(); + public static final dbBuildingHandler BuildingQueries = new dbBuildingHandler(); + public static final dbBuildingLocationHandler BuildingLocationQueries = new dbBuildingLocationHandler(); + public static final dbCharacterPowerHandler CharacterPowerQueries = new dbCharacterPowerHandler(); + public static final dbCharacterRuneHandler CharacterRuneQueries = new dbCharacterRuneHandler(); + public static final dbCharacterSkillHandler CharacterSkillQueries = new dbCharacterSkillHandler(); + public static final dbCityHandler CityQueries = new dbCityHandler(); + public static final dbContractHandler ContractQueries = new dbContractHandler(); + public static final dbWarehouseHandler WarehouseQueries = new dbWarehouseHandler(); + + // Omg refactor this out, somebody! + public static final dbCSSessionHandler CSSessionQueries = new dbCSSessionHandler(); + public static final dbEnchantmentHandler EnchantmentQueries = new dbEnchantmentHandler(); + public static final dbEffectsResourceCostHandler EffectsResourceCostsQueries = new dbEffectsResourceCostHandler(); + public static final dbGuildHandler GuildQueries = new dbGuildHandler(); + public static final dbItemHandler ItemQueries = new dbItemHandler(); + public static final dbItemBaseHandler ItemBaseQueries = new dbItemBaseHandler(); + public static final dbKitHandler KitQueries = new dbKitHandler(); + public static final dbLootTableHandler LootQueries = new dbLootTableHandler(); + public static final dbMenuHandler MenuQueries = new dbMenuHandler(); + public static final dbMineHandler MineQueries = new dbMineHandler(); + public static final dbMobHandler MobQueries = new dbMobHandler(); + public static final dbMobBaseHandler MobBaseQueries = new dbMobBaseHandler(); + public static final dbNPCHandler NPCQueries = new dbNPCHandler(); + public static final dbPlayerCharacterHandler PlayerCharacterQueries = new dbPlayerCharacterHandler(); + public static final dbPromotionClassHandler PromotionQueries = new dbPromotionClassHandler(); + public static final dbRaceHandler RaceQueries = new dbRaceHandler(); + public static final dbResistHandler ResistQueries = new dbResistHandler(); + public static final dbRuneBaseAttributeHandler RuneBaseAttributeQueries = new dbRuneBaseAttributeHandler(); + public static final dbRuneBaseEffectHandler RuneBaseEffectQueries = new dbRuneBaseEffectHandler(); + public static final dbRuneBaseHandler RuneBaseQueries = new dbRuneBaseHandler(); + public static final dbSkillBaseHandler SkillsBaseQueries = new dbSkillBaseHandler(); + public static final dbSkillReqHandler SkillReqQueries = new dbSkillReqHandler(); + public static final dbVendorDialogHandler VendorDialogQueries = new dbVendorDialogHandler(); + public static final dbZoneHandler ZoneQueries = new dbZoneHandler(); + public static final dbRealmHandler RealmQueries = new dbRealmHandler(); + public static final dbBlueprintHandler BlueprintQueries = new dbBlueprintHandler(); + public static final dbBoonHandler BoonQueries = new dbBoonHandler(); + public static final dbShrineHandler ShrineQueries = new dbShrineHandler(); + public static final dbHeightMapHandler HeightMapQueries = new dbHeightMapHandler(); + public static final dbRunegateHandler RunegateQueries = new dbRunegateHandler(); + private static final EnumMap> objectCache = new EnumMap<>(GameObjectType.class); + public static Hasher hasher; + private static HikariDataSource connectionPool = null; + + public static AbstractGameObject getObject(GameObjectType objectType, int objectUUID) { + + AbstractGameObject outObject = null; + + switch (objectType) { + case PlayerCharacter: + outObject = PlayerCharacter.getPlayerCharacter(objectUUID); + break; + case NPC: + outObject = NPC.getNPC(objectUUID); + break; + case Mob: + outObject = Mob.getFromCache(objectUUID); + break; + case Building: + outObject = BuildingManager.getBuilding(objectUUID); + break; + case Guild: + outObject = Guild.getGuild(objectUUID); + break; + case Item: + outObject = Item.getFromCache(objectUUID); + break; + case MobLoot: + outObject = MobLoot.getFromCache(objectUUID); + break; + case City: + outObject = City.getCity(objectUUID); + break; + default: + Logger.error("Attempt to retrieve nonexistant " + objectType + + " from object cache."); + break; + + } + + return outObject; + } + + public static boolean inCache(GameObjectType gameObjectType, int uuid) { + + if (objectCache.get(gameObjectType) == null) + return false; + + return (objectCache.get(gameObjectType).containsKey(uuid)); + + } + + public static AbstractGameObject getFromCache(GameObjectType gameObjectType, int uuid) { + + if (objectCache.get(gameObjectType) == null) + return null; + + return objectCache.get(gameObjectType).get(uuid); + + } + + public static void removeFromCache(GameObjectType gameObjectType, int uuid) { + + AbstractGameObject abstractGameObject; + + if (objectCache.get(gameObjectType) == null) + return; + + abstractGameObject = objectCache.get(gameObjectType).get(uuid); + + if (abstractGameObject == null) + return; + + removeFromCache(abstractGameObject); + + } + + public static void removeFromCache(AbstractGameObject abstractGameObject) { + + if (abstractGameObject == null) + return; + + if (objectCache.get(abstractGameObject.getObjectType()) == null) + return; + + // Remove object from game cache + + objectCache.get(abstractGameObject.getObjectType()).remove(abstractGameObject.getObjectUUID()); + + // Release bounds as we're dispensing with this object. + + if (abstractGameObject instanceof AbstractWorldObject) { + AbstractWorldObject abstractWorldObject = (AbstractWorldObject) abstractGameObject; + + if (abstractWorldObject.getBounds() != null) { + abstractWorldObject.getBounds().release(); + abstractWorldObject.setBounds(null); + } + } - private static HikariDataSource connectionPool = null; + } - public static Hasher hasher; + public static boolean addToCache(AbstractGameObject gameObject) { - //Local Object Caching + boolean isWorldServer = ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER); - private static final EnumMap> objectCache = new EnumMap<>(GameObjectType.class); + if (!isWorldServer) { + if (MBServerStatics.SKIP_CACHE_LOGIN) + return true; + if (MBServerStatics.SKIP_CACHE_LOGIN_PLAYER + && (gameObject.getObjectType() == GameObjectType.PlayerCharacter)) + return true; + if (MBServerStatics.SKIP_CACHE_LOGIN_ITEM && + (gameObject.getObjectType() == GameObjectType.Item)) + return true; + } - public static AbstractGameObject getObject(GameObjectType objectType, int objectUUID) { + // First time this object type has been cached. Create the hashmap. - AbstractGameObject outObject = null; + if (objectCache.get(gameObject.getObjectType()) == null) { - switch (objectType) { - case PlayerCharacter: - outObject = PlayerCharacter.getPlayerCharacter(objectUUID); - break; - case NPC: - outObject = NPC.getNPC(objectUUID); - break; - case Mob: - outObject = Mob.getFromCache(objectUUID); - break; - case Building: - outObject = BuildingManager.getBuilding(objectUUID); - break; - case Guild: - outObject = Guild.getGuild(objectUUID); - break; - case Item: - outObject = Item.getFromCache(objectUUID); - break; - case MobLoot: - outObject = MobLoot.getFromCache(objectUUID); - break; - case City: - outObject = City.getCity(objectUUID); - break; - default: - Logger.error("Attempt to retrieve nonexistant " + objectType + - " from object cache." ); - break; + int initialCapacity; - } + // Provide initial sizing hints - return outObject; - } + switch (gameObject.getObjectType()) { + case Building: + initialCapacity = 46900; + break; + case Mob: + initialCapacity = 11700; + break; + case NPC: + initialCapacity = 900; + break; + case Zone: + initialCapacity = 1070; + break; + case Account: + initialCapacity = 10000; + break; + case Guild: + initialCapacity = 100; + break; + case ItemContainer: + initialCapacity = 100; + break; + case Item: + initialCapacity = 1000; + break; + case MobLoot: + initialCapacity = 10000; + break; + case PlayerCharacter: + initialCapacity = 100; + break; + default: + initialCapacity = 100; // Lookup api default should be ok for small maps + break; + } + objectCache.put(gameObject.getObjectType(), new ConcurrentHashMap<>(initialCapacity)); + } + // Add the object to the cache. This will overwrite the current map entry. - public static boolean inCache(GameObjectType gameObjectType, int uuid) { + objectCache.get(gameObject.getObjectType()).put(gameObject.getObjectUUID(), gameObject); - if (objectCache.get(gameObjectType) == null) - return false; + return true; + } - return (objectCache.get(gameObjectType).containsKey(uuid)); + public static java.util.Collection getList(GameObjectType gameObjectType) { - } + if (objectCache.get(gameObjectType) == null) + return null; - public static AbstractGameObject getFromCache(GameObjectType gameObjectType, int uuid) { + return objectCache.get(gameObjectType).values(); + } - if (objectCache.get(gameObjectType) == null) - return null; + public static PreparedStatement prepareStatement(String sql) throws SQLException { + return getConnection().prepareStatement(sql, 1); + } - return objectCache.get(gameObjectType).get(uuid); + public static ConcurrentHashMap getMap( + GameObjectType gameObjectType) { - } + if (objectCache.get(gameObjectType) == null) + return null; + + return objectCache.get(gameObjectType); + + } + + public static void printCacheCount(PlayerCharacter pc) { + ChatManager.chatSystemInfo(pc, "Cache Lists"); + + for (GameObjectType gameObjectType : GameObjectType.values()) { + + if (objectCache.get(gameObjectType) == null) + continue; + + String ret = gameObjectType.name() + ": " + objectCache.get(gameObjectType).size(); + ChatManager.chatSystemInfo(pc, ret + '\n'); + } + } + + /** + * @return the conn + */ + //XXX I think we have a severe resource leak here! No one is putting the connections back! + public static Connection getConnection() { + try { + return DbManager.connectionPool.getConnection(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + public static void configureConnectionPool() { + + HikariConfig config = new HikariConfig(); + + int connectionCount = (Runtime.getRuntime().availableProcessors() * 2) + 1; + config.setMaximumPoolSize(connectionCount); + + config.setJdbcUrl("jdbc:mysql://" + ConfigManager.MB_DATABASE_ADDRESS.getValue() + + ":" + ConfigManager.MB_DATABASE_PORT.getValue() + "/" + + ConfigManager.MB_DATABASE_NAME.getValue()); + config.setUsername(ConfigManager.MB_DATABASE_USER.getValue()); + config.setPassword(ConfigManager.MB_DATABASE_PASS.getValue()); + + // Must be set lower than SQL server connection lifetime! + + config.addDataSourceProperty("maxLifetime", "3600000"); + + config.addDataSourceProperty("characterEncoding", "utf8"); + + config.addDataSourceProperty("useServerPrepStmts", "true"); + config.addDataSourceProperty("cachePrepStmts", "true"); + config.addDataSourceProperty("prepStmtCacheSize", "500"); + config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); - public static void removeFromCache(GameObjectType gameObjectType, int uuid) { + config.addDataSourceProperty("leakDetectionThreshold", "5000"); + config.addDataSourceProperty("cacheServerConfiguration", "true"); - AbstractGameObject abstractGameObject; + connectionPool = new HikariDataSource(config); // setup the connection pool - if (objectCache.get(gameObjectType) == null) - return; - - abstractGameObject = objectCache.get(gameObjectType).get(uuid); - - if (abstractGameObject == null) - return; - - removeFromCache(abstractGameObject); - - } - - public static void removeFromCache(AbstractGameObject abstractGameObject) { - - if (abstractGameObject == null) - return; - - if (objectCache.get(abstractGameObject.getObjectType()) == null) - return; - - // Remove object from game cache - - objectCache.get(abstractGameObject.getObjectType()).remove(abstractGameObject.getObjectUUID()); - - // Release bounds as we're dispensing with this object. - - if (abstractGameObject instanceof AbstractWorldObject) { - AbstractWorldObject abstractWorldObject = (AbstractWorldObject)abstractGameObject; - - if (abstractWorldObject.getBounds() != null) { - abstractWorldObject.getBounds().release(); - abstractWorldObject.setBounds(null); - } - } - - } - - public static boolean addToCache(AbstractGameObject gameObject) { - - boolean isWorldServer = ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER); - - if (!isWorldServer) { - if (MBServerStatics.SKIP_CACHE_LOGIN) - return true; - if (MBServerStatics.SKIP_CACHE_LOGIN_PLAYER - && (gameObject.getObjectType() == GameObjectType.PlayerCharacter)) - return true; - if (MBServerStatics.SKIP_CACHE_LOGIN_ITEM && - (gameObject.getObjectType() == GameObjectType.Item)) - return true; - } - - // First time this object type has been cached. Create the hashmap. - - if (objectCache.get(gameObject.getObjectType()) == null) { - - int initialCapacity; - - // Provide initial sizing hints - - switch (gameObject.getObjectType()) { - case Building: - initialCapacity = 46900; - break; - case Mob: - initialCapacity = 11700; - break; - case NPC: - initialCapacity = 900; - break; - case Zone: - initialCapacity = 1070; - break; - case Account: - initialCapacity = 10000; - break; - case Guild: - initialCapacity = 100; - break; - case ItemContainer: - initialCapacity = 100; - break; - case Item: - initialCapacity = 1000; - break; - case MobLoot: - initialCapacity = 10000; - break; - case PlayerCharacter: - initialCapacity = 100; - break; - default: - initialCapacity = 100; // Lookup api default should be ok for small maps - break; - } - objectCache.put(gameObject.getObjectType(), new ConcurrentHashMap<>(initialCapacity)); - } - - // Add the object to the cache. This will overwrite the current map entry. - - objectCache.get(gameObject.getObjectType()).put(gameObject.getObjectUUID(), gameObject); - - return true; - } - - public static java.util.Collection getList(GameObjectType gameObjectType) { - - if (objectCache.get(gameObjectType) == null) - return null; - - return objectCache.get(gameObjectType).values(); - } - - public static PreparedStatement prepareStatement(String sql) throws SQLException { - return getConnection().prepareStatement(sql, 1); - } - - // Omg refactor this out, somebody! - - public static ConcurrentHashMap getMap( - GameObjectType gameObjectType) { - - if (objectCache.get(gameObjectType) == null) - return null; - - return objectCache.get(gameObjectType); - - } - - public static void printCacheCount(PlayerCharacter pc) { - ChatManager.chatSystemInfo(pc, "Cache Lists"); - - for (GameObjectType gameObjectType : GameObjectType.values()) { - - if (objectCache.get(gameObjectType) == null) - continue; - - String ret = gameObjectType.name() + ": " + objectCache.get(gameObjectType).size(); - ChatManager.chatSystemInfo(pc, ret + '\n'); - } - } - - /** - * @return the conn - */ - //XXX I think we have a severe resource leak here! No one is putting the connections back! - public static Connection getConnection() { - try { - return DbManager.connectionPool.getConnection(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - public static final dbAccountHandler AccountQueries = new dbAccountHandler(); - public static final dbBaneHandler BaneQueries = new dbBaneHandler(); - public static final dbBaseClassHandler BaseClassQueries = new dbBaseClassHandler(); - public static final dbBuildingHandler BuildingQueries = new dbBuildingHandler(); - public static final dbBuildingLocationHandler BuildingLocationQueries = new dbBuildingLocationHandler(); - public static final dbCharacterPowerHandler CharacterPowerQueries = new dbCharacterPowerHandler(); - public static final dbCharacterRuneHandler CharacterRuneQueries = new dbCharacterRuneHandler(); - public static final dbCharacterSkillHandler CharacterSkillQueries = new dbCharacterSkillHandler(); - public static final dbCityHandler CityQueries = new dbCityHandler(); - public static final dbContractHandler ContractQueries = new dbContractHandler(); - public static final dbWarehouseHandler WarehouseQueries = new dbWarehouseHandler(); - public static final dbCSSessionHandler CSSessionQueries = new dbCSSessionHandler(); - public static final dbEnchantmentHandler EnchantmentQueries = new dbEnchantmentHandler(); - public static final dbEffectsResourceCostHandler EffectsResourceCostsQueries = new dbEffectsResourceCostHandler(); - public static final dbGuildHandler GuildQueries = new dbGuildHandler(); - public static final dbItemHandler ItemQueries = new dbItemHandler(); - public static final dbItemBaseHandler ItemBaseQueries = new dbItemBaseHandler(); - public static final dbKitHandler KitQueries = new dbKitHandler(); - public static final dbLootTableHandler LootQueries = new dbLootTableHandler(); - public static final dbMenuHandler MenuQueries = new dbMenuHandler(); - public static final dbMineHandler MineQueries = new dbMineHandler(); - public static final dbMobHandler MobQueries = new dbMobHandler(); - public static final dbMobBaseHandler MobBaseQueries = new dbMobBaseHandler(); - public static final dbNPCHandler NPCQueries = new dbNPCHandler(); - public static final dbPlayerCharacterHandler PlayerCharacterQueries = new dbPlayerCharacterHandler(); - public static final dbPromotionClassHandler PromotionQueries = new dbPromotionClassHandler(); - public static final dbRaceHandler RaceQueries = new dbRaceHandler(); - public static final dbResistHandler ResistQueries = new dbResistHandler(); - public static final dbRuneBaseAttributeHandler RuneBaseAttributeQueries = new dbRuneBaseAttributeHandler(); - public static final dbRuneBaseEffectHandler RuneBaseEffectQueries = new dbRuneBaseEffectHandler(); - public static final dbRuneBaseHandler RuneBaseQueries = new dbRuneBaseHandler(); - public static final dbSkillBaseHandler SkillsBaseQueries = new dbSkillBaseHandler(); - public static final dbSkillReqHandler SkillReqQueries = new dbSkillReqHandler(); - public static final dbVendorDialogHandler VendorDialogQueries = new dbVendorDialogHandler(); - public static final dbZoneHandler ZoneQueries = new dbZoneHandler(); - public static final dbRealmHandler RealmQueries = new dbRealmHandler(); - public static final dbBlueprintHandler BlueprintQueries = new dbBlueprintHandler(); - public static final dbBoonHandler BoonQueries = new dbBoonHandler(); - public static final dbShrineHandler ShrineQueries = new dbShrineHandler(); - public static final dbHeightMapHandler HeightMapQueries = new dbHeightMapHandler(); - - public static final dbRunegateHandler RunegateQueries = new dbRunegateHandler(); - - public static void configureConnectionPool() { - - HikariConfig config = new HikariConfig(); - - int connectionCount = (Runtime.getRuntime().availableProcessors() * 2) + 1; - config.setMaximumPoolSize(connectionCount); - - config.setJdbcUrl("jdbc:mysql://" + ConfigManager.MB_DATABASE_ADDRESS.getValue() + - ":" + ConfigManager.MB_DATABASE_PORT.getValue() + "/" + - ConfigManager.MB_DATABASE_NAME.getValue()); - config.setUsername(ConfigManager.MB_DATABASE_USER.getValue()); - config.setPassword(ConfigManager.MB_DATABASE_PASS.getValue()); - - // Must be set lower than SQL server connection lifetime! - - config.addDataSourceProperty("maxLifetime", "3600000"); - - config.addDataSourceProperty("characterEncoding", "utf8"); - - config.addDataSourceProperty("useServerPrepStmts", "true"); - config.addDataSourceProperty("cachePrepStmts", "true"); - config.addDataSourceProperty("prepStmtCacheSize", "500"); - config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); - - config.addDataSourceProperty("leakDetectionThreshold", "5000"); - config.addDataSourceProperty("cacheServerConfiguration", "true"); - - connectionPool = new HikariDataSource(config); // setup the connection pool - - Logger.info("Database configured with " + connectionCount + " connections"); - } + Logger.info("Database configured with " + connectionCount + " connections"); + } } diff --git a/src/engine/gameManager/DevCmdManager.java b/src/engine/gameManager/DevCmdManager.java index 7c68d2f7..8aae245e 100644 --- a/src/engine/gameManager/DevCmdManager.java +++ b/src/engine/gameManager/DevCmdManager.java @@ -22,202 +22,203 @@ import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; public enum DevCmdManager { - DEV_CMD_MANAGER; - - public static ConcurrentHashMap devCmds; - - DevCmdManager() { - init(); - } - - public static void init() { - DevCmdManager.devCmds = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - DevCmdManager.registerCommands(); - } - - /** - * - */ - private static void registerCommands() { - - // Player - DevCmdManager.registerDevCmd(new DistanceCmd());; - DevCmdManager.registerDevCmd(new HelpCmd()); - DevCmdManager.registerDevCmd(new GetZoneCmd()); - DevCmdManager.registerDevCmd(new GetZoneMobsCmd()); - DevCmdManager.registerDevCmd(new PrintBankCmd()); - DevCmdManager.registerDevCmd(new PrintEquipCmd()); - DevCmdManager.registerDevCmd(new PrintInventoryCmd()); - DevCmdManager.registerDevCmd(new PrintVaultCmd()); - DevCmdManager.registerDevCmd(new PrintStatsCmd()); - DevCmdManager.registerDevCmd(new PrintSkillsCmd()); - DevCmdManager.registerDevCmd(new PrintPowersCmd()); - DevCmdManager.registerDevCmd(new PrintBonusesCmd()); - DevCmdManager.registerDevCmd(new PrintResistsCmd()); - DevCmdManager.registerDevCmd(new PrintLocationCmd()); - DevCmdManager.registerDevCmd(new InfoCmd()); - DevCmdManager.registerDevCmd(new aiInfoCmd()); - DevCmdManager.registerDevCmd(new simulateBootyCmd()); - DevCmdManager.registerDevCmd(new GetHeightCmd()); - - // Tester - DevCmdManager.registerDevCmd(new JumpCmd()); - DevCmdManager.registerDevCmd(new GotoCmd()); - DevCmdManager.registerDevCmd(new SummonCmd()); - DevCmdManager.registerDevCmd(new SetHealthCmd()); - DevCmdManager.registerDevCmd(new SetManaCmd()); - DevCmdManager.registerDevCmd(new SetStaminaCmd()); - DevCmdManager.registerDevCmd(new FindBuildingsCmd()); - DevCmdManager.registerDevCmd(new TeleportModeCmd()); - DevCmdManager.registerDevCmd(new SetLevelCmd()); - DevCmdManager.registerDevCmd(new SetBaseClassCmd()); - DevCmdManager.registerDevCmd(new SetPromotionClassCmd()); - DevCmdManager.registerDevCmd(new EffectCmd()); - DevCmdManager.registerDevCmd(new SetRuneCmd()); - DevCmdManager.registerDevCmd(new GetOffsetCmd()); - DevCmdManager.registerDevCmd(new DebugCmd()); - DevCmdManager.registerDevCmd(new AddGoldCmd()); - DevCmdManager.registerDevCmd(new ZoneInfoCmd()); - DevCmdManager.registerDevCmd(new DebugMeleeSyncCmd()); - DevCmdManager.registerDevCmd(new HotzoneCmd()); - DevCmdManager.registerDevCmd(new MineActiveCmd()); - // Dev - DevCmdManager.registerDevCmd(new ApplyStatModCmd()); - DevCmdManager.registerDevCmd(new AddBuildingCmd()); - DevCmdManager.registerDevCmd(new AddNPCCmd()); - DevCmdManager.registerDevCmd(new AddMobCmd()); - DevCmdManager.registerDevCmd(new RemoveObjectCmd()); - DevCmdManager.registerDevCmd(new RotateCmd()); - DevCmdManager.registerDevCmd(new FlashMsgCmd()); - DevCmdManager.registerDevCmd(new SysMsgCmd()); - DevCmdManager.registerDevCmd(new GetBankCmd()); - DevCmdManager.registerDevCmd(new GetVaultCmd()); - DevCmdManager.registerDevCmd(new CombatMessageCmd()); - DevCmdManager.registerDevCmd(new RenameCmd()); - DevCmdManager.registerDevCmd(new CreateItemCmd()); - DevCmdManager.registerDevCmd(new GetMemoryCmd()); - DevCmdManager.registerDevCmd(new SetRankCmd()); - DevCmdManager.registerDevCmd(new MakeBaneCmd()); - DevCmdManager.registerDevCmd(new RemoveBaneCmd()); - DevCmdManager.registerDevCmd(new SetBaneActiveCmd()); - DevCmdManager.registerDevCmd(new SetAdminRuneCmd()); - DevCmdManager.registerDevCmd(new SetInvulCmd()); - DevCmdManager.registerDevCmd(new MakeItemCmd()); - DevCmdManager.registerDevCmd(new EnchantCmd()); - DevCmdManager.registerDevCmd(new SetSubRaceCmd()); - // Admin - DevCmdManager.registerDevCmd(new GetCacheCountCmd()); - DevCmdManager.registerDevCmd(new GetRuneDropRateCmd()); - DevCmdManager.registerDevCmd(new DecachePlayerCmd()); - DevCmdManager.registerDevCmd(new AuditMobsCmd()); - DevCmdManager.registerDevCmd(new ChangeNameCmd()); - DevCmdManager.registerDevCmd(new SetGuildCmd()); - DevCmdManager.registerDevCmd(new SetOwnerCmd()); - DevCmdManager.registerDevCmd(new NetDebugCmd()); - DevCmdManager.registerDevCmd(new SqlDebugCmd()); - DevCmdManager.registerDevCmd(new PullCmd()); - DevCmdManager.registerDevCmd(new PurgeObjectsCmd()); - DevCmdManager.registerDevCmd(new SplatMobCmd()); - DevCmdManager.registerDevCmd(new SlotNpcCmd()); - DevCmdManager.registerDevCmd(new SetAICmd()); - DevCmdManager.registerDevCmd(new GateInfoCmd()); - DevCmdManager.registerDevCmd(new ShowOffsetCmd()); - DevCmdManager.registerDevCmd(new RealmInfoCmd()); - DevCmdManager.registerDevCmd(new RebootCmd()); - DevCmdManager.registerDevCmd(new SetMineTypeCmd()); - DevCmdManager.registerDevCmd(new SetMineExpansion()); - DevCmdManager.registerDevCmd(new SetForceRenameCityCmd()); - DevCmdManager.registerDevCmd(new GotoObj()); - DevCmdManager.registerDevCmd(new convertLoc()); - DevCmdManager.registerDevCmd(new GetMobBaseLoot()); - DevCmdManager.registerDevCmd(new MBDropCmd()); - DevCmdManager.registerDevCmd(new AuditHeightMapCmd()); - DevCmdManager.registerDevCmd(new UnloadFurnitureCmd()); - DevCmdManager.registerDevCmd(new SetNpcEquipSetCmd()); - DevCmdManager.registerDevCmd(new SetBuildingAltitudeCmd()); - DevCmdManager.registerDevCmd(new ResetLevelCmd()); - DevCmdManager.registerDevCmd(new HeartbeatCmd()); - DevCmdManager.registerDevCmd(new SetNpcNameCmd()); - DevCmdManager.registerDevCmd(new SetNpcMobbaseCmd()); - DevCmdManager.registerDevCmd(new DespawnCmd()); - DevCmdManager.registerDevCmd(new BoundsCmd()); - DevCmdManager.registerDevCmd(new GotoBoundsCmd()); - DevCmdManager.registerDevCmd(new RegionCmd()); - DevCmdManager.registerDevCmd(new SetMaintCmd()); - DevCmdManager.registerDevCmd(new ApplyBonusCmd()); - DevCmdManager.registerDevCmd(new AuditFailedItemsCmd()); - DevCmdManager.registerDevCmd(new SlotTestCmd()); - - } - - private static void registerDevCmd(AbstractDevCmd cmd) { - ArrayList cmdStrings = cmd.getCmdStrings(); - for (String cmdString : cmdStrings) { - DevCmdManager.devCmds.put(cmdString, cmd); - } - } - - public static AbstractDevCmd getDevCmd(String cmd) { - String lowercase = cmd.toLowerCase(); - return DevCmdManager.devCmds.get(lowercase); - } - - public static boolean handleDevCmd(PlayerCharacter pcSender, String cmd, - String argString, AbstractGameObject target) { - - if (pcSender == null) { - return false; - } - - Account a = SessionManager.getAccount(pcSender); - - if (a == null) { - return false; - } - - AbstractDevCmd adc = DevCmdManager.getDevCmd(cmd); - - if (adc == null) { - return false; - } - - //kill any commands not available to everyone on production server - //only admin level can run dev commands on production - - if (a.status.equals(Enum.AccountStatus.ADMIN) == false) { - Logger.info("Account " + a.getUname() + "attempted to use dev command " + cmd); - return false; - } - - // TODO add a job here to separate calling thread form executing thread? - // Log - - String accName = a.getUname(); - String pcName = pcSender.getCombinedName(); - String logString = pcName + '(' + accName - + ") '"; - logString += cmd + ' ' + argString + '\''; - Logger.info( logString); - DbManager.AccountQueries.WRITE_ADMIN_LOG(pcName, "COMMAND: " + cmd + " " + argString); - - // execute command; - try { - adc.doCmd(pcSender, argString, target); - } catch (Exception e) { - Logger.error(e.toString()); - e.printStackTrace(); - } - - return true; - } - - public static String getCmdsForAccessLevel() { - String out = ""; - - for (Entry e : DevCmdManager.devCmds.entrySet()) - out += e.getKey() + ", "; - - return out; - } + DEV_CMD_MANAGER; + + public static ConcurrentHashMap devCmds; + + DevCmdManager() { + init(); + } + + public static void init() { + DevCmdManager.devCmds = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + DevCmdManager.registerCommands(); + } + + /** + * + */ + private static void registerCommands() { + + // Player + DevCmdManager.registerDevCmd(new DistanceCmd()); + ; + DevCmdManager.registerDevCmd(new HelpCmd()); + DevCmdManager.registerDevCmd(new GetZoneCmd()); + DevCmdManager.registerDevCmd(new GetZoneMobsCmd()); + DevCmdManager.registerDevCmd(new PrintBankCmd()); + DevCmdManager.registerDevCmd(new PrintEquipCmd()); + DevCmdManager.registerDevCmd(new PrintInventoryCmd()); + DevCmdManager.registerDevCmd(new PrintVaultCmd()); + DevCmdManager.registerDevCmd(new PrintStatsCmd()); + DevCmdManager.registerDevCmd(new PrintSkillsCmd()); + DevCmdManager.registerDevCmd(new PrintPowersCmd()); + DevCmdManager.registerDevCmd(new PrintBonusesCmd()); + DevCmdManager.registerDevCmd(new PrintResistsCmd()); + DevCmdManager.registerDevCmd(new PrintLocationCmd()); + DevCmdManager.registerDevCmd(new InfoCmd()); + DevCmdManager.registerDevCmd(new aiInfoCmd()); + DevCmdManager.registerDevCmd(new simulateBootyCmd()); + DevCmdManager.registerDevCmd(new GetHeightCmd()); + + // Tester + DevCmdManager.registerDevCmd(new JumpCmd()); + DevCmdManager.registerDevCmd(new GotoCmd()); + DevCmdManager.registerDevCmd(new SummonCmd()); + DevCmdManager.registerDevCmd(new SetHealthCmd()); + DevCmdManager.registerDevCmd(new SetManaCmd()); + DevCmdManager.registerDevCmd(new SetStaminaCmd()); + DevCmdManager.registerDevCmd(new FindBuildingsCmd()); + DevCmdManager.registerDevCmd(new TeleportModeCmd()); + DevCmdManager.registerDevCmd(new SetLevelCmd()); + DevCmdManager.registerDevCmd(new SetBaseClassCmd()); + DevCmdManager.registerDevCmd(new SetPromotionClassCmd()); + DevCmdManager.registerDevCmd(new EffectCmd()); + DevCmdManager.registerDevCmd(new SetRuneCmd()); + DevCmdManager.registerDevCmd(new GetOffsetCmd()); + DevCmdManager.registerDevCmd(new DebugCmd()); + DevCmdManager.registerDevCmd(new AddGoldCmd()); + DevCmdManager.registerDevCmd(new ZoneInfoCmd()); + DevCmdManager.registerDevCmd(new DebugMeleeSyncCmd()); + DevCmdManager.registerDevCmd(new HotzoneCmd()); + DevCmdManager.registerDevCmd(new MineActiveCmd()); + // Dev + DevCmdManager.registerDevCmd(new ApplyStatModCmd()); + DevCmdManager.registerDevCmd(new AddBuildingCmd()); + DevCmdManager.registerDevCmd(new AddNPCCmd()); + DevCmdManager.registerDevCmd(new AddMobCmd()); + DevCmdManager.registerDevCmd(new RemoveObjectCmd()); + DevCmdManager.registerDevCmd(new RotateCmd()); + DevCmdManager.registerDevCmd(new FlashMsgCmd()); + DevCmdManager.registerDevCmd(new SysMsgCmd()); + DevCmdManager.registerDevCmd(new GetBankCmd()); + DevCmdManager.registerDevCmd(new GetVaultCmd()); + DevCmdManager.registerDevCmd(new CombatMessageCmd()); + DevCmdManager.registerDevCmd(new RenameCmd()); + DevCmdManager.registerDevCmd(new CreateItemCmd()); + DevCmdManager.registerDevCmd(new GetMemoryCmd()); + DevCmdManager.registerDevCmd(new SetRankCmd()); + DevCmdManager.registerDevCmd(new MakeBaneCmd()); + DevCmdManager.registerDevCmd(new RemoveBaneCmd()); + DevCmdManager.registerDevCmd(new SetBaneActiveCmd()); + DevCmdManager.registerDevCmd(new SetAdminRuneCmd()); + DevCmdManager.registerDevCmd(new SetInvulCmd()); + DevCmdManager.registerDevCmd(new MakeItemCmd()); + DevCmdManager.registerDevCmd(new EnchantCmd()); + DevCmdManager.registerDevCmd(new SetSubRaceCmd()); + // Admin + DevCmdManager.registerDevCmd(new GetCacheCountCmd()); + DevCmdManager.registerDevCmd(new GetRuneDropRateCmd()); + DevCmdManager.registerDevCmd(new DecachePlayerCmd()); + DevCmdManager.registerDevCmd(new AuditMobsCmd()); + DevCmdManager.registerDevCmd(new ChangeNameCmd()); + DevCmdManager.registerDevCmd(new SetGuildCmd()); + DevCmdManager.registerDevCmd(new SetOwnerCmd()); + DevCmdManager.registerDevCmd(new NetDebugCmd()); + DevCmdManager.registerDevCmd(new SqlDebugCmd()); + DevCmdManager.registerDevCmd(new PullCmd()); + DevCmdManager.registerDevCmd(new PurgeObjectsCmd()); + DevCmdManager.registerDevCmd(new SplatMobCmd()); + DevCmdManager.registerDevCmd(new SlotNpcCmd()); + DevCmdManager.registerDevCmd(new SetAICmd()); + DevCmdManager.registerDevCmd(new GateInfoCmd()); + DevCmdManager.registerDevCmd(new ShowOffsetCmd()); + DevCmdManager.registerDevCmd(new RealmInfoCmd()); + DevCmdManager.registerDevCmd(new RebootCmd()); + DevCmdManager.registerDevCmd(new SetMineTypeCmd()); + DevCmdManager.registerDevCmd(new SetMineExpansion()); + DevCmdManager.registerDevCmd(new SetForceRenameCityCmd()); + DevCmdManager.registerDevCmd(new GotoObj()); + DevCmdManager.registerDevCmd(new convertLoc()); + DevCmdManager.registerDevCmd(new GetMobBaseLoot()); + DevCmdManager.registerDevCmd(new MBDropCmd()); + DevCmdManager.registerDevCmd(new AuditHeightMapCmd()); + DevCmdManager.registerDevCmd(new UnloadFurnitureCmd()); + DevCmdManager.registerDevCmd(new SetNpcEquipSetCmd()); + DevCmdManager.registerDevCmd(new SetBuildingAltitudeCmd()); + DevCmdManager.registerDevCmd(new ResetLevelCmd()); + DevCmdManager.registerDevCmd(new HeartbeatCmd()); + DevCmdManager.registerDevCmd(new SetNpcNameCmd()); + DevCmdManager.registerDevCmd(new SetNpcMobbaseCmd()); + DevCmdManager.registerDevCmd(new DespawnCmd()); + DevCmdManager.registerDevCmd(new BoundsCmd()); + DevCmdManager.registerDevCmd(new GotoBoundsCmd()); + DevCmdManager.registerDevCmd(new RegionCmd()); + DevCmdManager.registerDevCmd(new SetMaintCmd()); + DevCmdManager.registerDevCmd(new ApplyBonusCmd()); + DevCmdManager.registerDevCmd(new AuditFailedItemsCmd()); + DevCmdManager.registerDevCmd(new SlotTestCmd()); + + } + + private static void registerDevCmd(AbstractDevCmd cmd) { + ArrayList cmdStrings = cmd.getCmdStrings(); + for (String cmdString : cmdStrings) { + DevCmdManager.devCmds.put(cmdString, cmd); + } + } + + public static AbstractDevCmd getDevCmd(String cmd) { + String lowercase = cmd.toLowerCase(); + return DevCmdManager.devCmds.get(lowercase); + } + + public static boolean handleDevCmd(PlayerCharacter pcSender, String cmd, + String argString, AbstractGameObject target) { + + if (pcSender == null) { + return false; + } + + Account a = SessionManager.getAccount(pcSender); + + if (a == null) { + return false; + } + + AbstractDevCmd adc = DevCmdManager.getDevCmd(cmd); + + if (adc == null) { + return false; + } + + //kill any commands not available to everyone on production server + //only admin level can run dev commands on production + + if (a.status.equals(Enum.AccountStatus.ADMIN) == false) { + Logger.info("Account " + a.getUname() + "attempted to use dev command " + cmd); + return false; + } + + // TODO add a job here to separate calling thread form executing thread? + // Log + + String accName = a.getUname(); + String pcName = pcSender.getCombinedName(); + String logString = pcName + '(' + accName + + ") '"; + logString += cmd + ' ' + argString + '\''; + Logger.info(logString); + DbManager.AccountQueries.WRITE_ADMIN_LOG(pcName, "COMMAND: " + cmd + " " + argString); + + // execute command; + try { + adc.doCmd(pcSender, argString, target); + } catch (Exception e) { + Logger.error(e.toString()); + e.printStackTrace(); + } + + return true; + } + + public static String getCmdsForAccessLevel() { + String out = ""; + + for (Entry e : DevCmdManager.devCmds.entrySet()) + out += e.getKey() + ", "; + + return out; + } } diff --git a/src/engine/gameManager/GroupManager.java b/src/engine/gameManager/GroupManager.java index a451d4c9..fad20eda 100644 --- a/src/engine/gameManager/GroupManager.java +++ b/src/engine/gameManager/GroupManager.java @@ -304,7 +304,7 @@ public enum GroupManager { public static boolean goldSplit(PlayerCharacter pc, Item item, ClientConnection origin, AbstractWorldObject tar) { if (item == null || pc == null || tar == null || item.getItemBase() == null) { - Logger.error( "null something"); + Logger.error("null something"); return false; } @@ -321,7 +321,7 @@ public enum GroupManager { //get group members - for (PlayerCharacter groupMember: group.getMembers()){ + for (PlayerCharacter groupMember : group.getMembers()) { if (pc.getLoc().distanceSquared2D(groupMember.getLoc()) > MBServerStatics.CHARACTER_LOAD_RANGE * MBServerStatics.CHARACTER_LOAD_RANGE) continue; @@ -343,27 +343,24 @@ public enum GroupManager { int dif = total - (size * amount); if (AbstractWorldObject.IsAbstractCharacter(tar)) { - } - else if (tar.getObjectType().equals(Enum.GameObjectType.Corpse)) { + } else if (tar.getObjectType().equals(Enum.GameObjectType.Corpse)) { Corpse corpse = (Corpse) tar; corpse.getInventory().remove(item); - } - else { + } else { Logger.error("target not corpse or character"); return false; } - if (item.getObjectType() == Enum.GameObjectType.MobLoot){ - if (tar.getObjectType() == Enum.GameObjectType.Mob){ - ((Mob)tar).getCharItemManager().delete(item); - }else + if (item.getObjectType() == Enum.GameObjectType.MobLoot) { + if (tar.getObjectType() == Enum.GameObjectType.Mob) { + ((Mob) tar).getCharItemManager().delete(item); + } else item.setNumOfItems(0); - }else + } else item.setNumOfItems(0); for (PlayerCharacter splitPlayer : playersSplit) { - int amt = (group.isGroupLead(splitPlayer)) ? (amount + dif) : amount; if (amt > 0) splitPlayer.getCharItemManager().addGoldToInventory(amt, false); diff --git a/src/engine/gameManager/GuildManager.java b/src/engine/gameManager/GuildManager.java index 75ea7afc..e6b285ae 100644 --- a/src/engine/gameManager/GuildManager.java +++ b/src/engine/gameManager/GuildManager.java @@ -19,188 +19,186 @@ import engine.net.client.msg.guild.GuildInfoMsg; import engine.objects.*; import org.joda.time.DateTime; -public enum GuildManager { +public enum GuildManager { - GUILDMANAGER; + GUILDMANAGER; - //Guild Error Message - public static final int FAILURE_TO_SWEAR_GUILD = 45; //45: Failure to swear guild - public static final int MUST_LEAVE_GUILD = 75;//75: You must leave your current guild before you can repledge - public static final int NO_CHARTER_FOUND = 148; //148: Unable to find a matching petition to complete guild creation - public static final int PROFANE_NAME = 149; //149: Guild name fails profanity check - public static final int PROFANE_MOTTO = 150; //150: Guild motto fails profanity check - public static final int UNIQUE_NAME = 151;//151: Guild name is not unique - public static final int UNIQUE_CREST = 152;//152: Guild crest is not unique - public static final int CREST_RESERVED = 153; //153: Guild crest is reserved - public static final int CREST_COLOR_ERROR = 154; //154: All three crest colors cannot be the same + //Guild Error Message + public static final int FAILURE_TO_SWEAR_GUILD = 45; //45: Failure to swear guild + public static final int MUST_LEAVE_GUILD = 75;//75: You must leave your current guild before you can repledge + public static final int NO_CHARTER_FOUND = 148; //148: Unable to find a matching petition to complete guild creation + public static final int PROFANE_NAME = 149; //149: Guild name fails profanity check + public static final int PROFANE_MOTTO = 150; //150: Guild motto fails profanity check + public static final int UNIQUE_NAME = 151;//151: Guild name is not unique + public static final int UNIQUE_CREST = 152;//152: Guild crest is not unique + public static final int CREST_RESERVED = 153; //153: Guild crest is reserved + public static final int CREST_COLOR_ERROR = 154; //154: All three crest colors cannot be the same - public static boolean joinGuild(PlayerCharacter pc, Guild guild, GuildHistoryType historyType) { - return joinGuild(pc, guild, 0, historyType); - } + public static boolean joinGuild(PlayerCharacter pc, Guild guild, GuildHistoryType historyType) { + return joinGuild(pc, guild, 0, historyType); + } - //Used when repledging - public static boolean joinGuild(PlayerCharacter pc, Guild guild, int cityID, GuildHistoryType historyType) { - return joinGuild(pc, guild, cityID, true,historyType); - } + //Used when repledging + public static boolean joinGuild(PlayerCharacter pc, Guild guild, int cityID, GuildHistoryType historyType) { + return joinGuild(pc, guild, cityID, true, historyType); + } - public static boolean joinGuild(PlayerCharacter playerCharacter, Guild guild, int cityID, boolean fromTeleportScreen, GuildHistoryType historyType) { + public static boolean joinGuild(PlayerCharacter playerCharacter, Guild guild, int cityID, boolean fromTeleportScreen, GuildHistoryType historyType) { - // Member variable delcaration + // Member variable delcaration - ClientConnection origin; - AcceptInviteToGuildMsg msg; - Dispatch dispatch; + ClientConnection origin; + AcceptInviteToGuildMsg msg; + Dispatch dispatch; - if (playerCharacter == null || guild == null) - return false; + if (playerCharacter == null || guild == null) + return false; - // Member variable assignment + // Member variable assignment - origin = SessionManager.getClientConnection(playerCharacter); + origin = SessionManager.getClientConnection(playerCharacter); - if (origin == null) - return false; + if (origin == null) + return false; - if (playerCharacter.getGuild().isEmptyGuild() == false && GuildStatusController.isGuildLeader(playerCharacter.getGuildStatus())) - return false; + if (playerCharacter.getGuild().isEmptyGuild() == false && GuildStatusController.isGuildLeader(playerCharacter.getGuildStatus())) + return false; - if (playerCharacter.getGuild() != null && playerCharacter.getGuild().isGuildLeader(playerCharacter.getObjectUUID())) - return false; + if (playerCharacter.getGuild() != null && playerCharacter.getGuild().isGuildLeader(playerCharacter.getObjectUUID())) + return false; - if (playerCharacter.getGuild() != null && !playerCharacter.getGuild().isEmptyGuild()){ - if (DbManager.GuildQueries.ADD_TO_GUILDHISTORY(playerCharacter.getGuildUUID(), playerCharacter, DateTime.now(), GuildHistoryType.LEAVE)){ - GuildHistory guildHistory = new GuildHistory(playerCharacter.getGuildUUID(),playerCharacter.getGuild().getName(),DateTime.now(), GuildHistoryType.LEAVE) ; - playerCharacter.getGuildHistory().add(guildHistory); - } - } + if (playerCharacter.getGuild() != null && !playerCharacter.getGuild().isEmptyGuild()) { + if (DbManager.GuildQueries.ADD_TO_GUILDHISTORY(playerCharacter.getGuildUUID(), playerCharacter, DateTime.now(), GuildHistoryType.LEAVE)) { + GuildHistory guildHistory = new GuildHistory(playerCharacter.getGuildUUID(), playerCharacter.getGuild().getName(), DateTime.now(), GuildHistoryType.LEAVE); + playerCharacter.getGuildHistory().add(guildHistory); + } + } - playerCharacter.setInnerCouncil(false); - playerCharacter.setGuildLeader(false); - playerCharacter.setGuild(guild); - - // Cleanup guild stuff - playerCharacter.resetGuildStatuses(); - - // send success message to client - if (fromTeleportScreen && guild.isNPCGuild()) - playerCharacter.setFullMember(true); - - msg = new AcceptInviteToGuildMsg(guild.getObjectUUID(), 1, 0); - - if (fromTeleportScreen) { - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } - if (DbManager.GuildQueries.ADD_TO_GUILDHISTORY(guild.getObjectUUID(), playerCharacter, DateTime.now(), historyType)){ - GuildHistory guildHistory = new GuildHistory(guild.getObjectUUID(),guild.getName(),DateTime.now(), historyType) ; - playerCharacter.getGuildHistory().add(guildHistory); - } - - DispatchMessage.sendToAllInRange(playerCharacter, new GuildInfoMsg(playerCharacter, guild, 2)); - - // Send guild join message - ChatManager.chatGuildInfo(playerCharacter, - playerCharacter.getFirstName() + " has joined the guild"); - - playerCharacter.incVer(); - - return true; - // TODO update player to world - } - - public static void enterWorldMOTD(PlayerCharacter pc) { - - Guild guild; - Guild nation; - - if (pc == null) { - return; - } - - guild = pc.getGuild(); - - if (guild == null || guild.getObjectUUID() == 0) // Don't send to errant - return; - - // Send Guild MOTD - String motd = guild.getMOTD(); - if (motd.length() > 0) { - ChatManager.chatGuildMOTD(pc, motd); - } - - // Send Nation MOTD - nation = guild.getNation(); - - if (nation != null) { - if (nation.getObjectUUID() != 0) { // Don't send to errant nation - motd = nation.getMOTD(); - if (motd.length() > 0) { - ChatManager.chatNationMOTD(pc, motd); - } - } - } + playerCharacter.setInnerCouncil(false); + playerCharacter.setGuildLeader(false); + playerCharacter.setGuild(guild); - // Send IC MOTD if player is IC - if (GuildStatusController.isInnerCouncil(pc.getGuildStatus())) { - motd = guild.getICMOTD(); - if (motd.length() > 0) { - ChatManager.chatICMOTD(pc, motd); - } - } - } - - //Updates the bind point for everyone in guild - - public static void updateAllGuildBinds(Guild guild, City city) { - - if (guild == null) - return; - - int cityID = (city != null) ? city.getObjectUUID() : 0; - - - - //update binds ingame - - - for (PlayerCharacter playerCharacter : Guild.GuildRoster(guild)) { - boolean updateBindBuilding = false; - - Building oldBoundBuilding = BuildingManager.getBuildingFromCache(playerCharacter.getBindBuildingID()); - - if (oldBoundBuilding == null || oldBoundBuilding.getBlueprint() == null || oldBoundBuilding.getBlueprint().getBuildingGroup().equals(BuildingGroup.TOL)) - updateBindBuilding = true; - - - - if (updateBindBuilding){ - Building bindBuilding = null; - if (city != null) - if (city.getTOL() != null) - bindBuilding = city.getTOL(); - - if (bindBuilding == null) - bindBuilding = PlayerCharacter.getBindBuildingForGuild(playerCharacter); - - playerCharacter.setBindBuildingID(bindBuilding != null ? bindBuilding.getObjectUUID() : 0); - } - - - } - } - - //This updates tags for all online players in a guild. - public static void updateAllGuildTags(Guild guild) { - - if (guild == null) - return; - - for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) { - - if (player.getGuild().equals(guild)) - DispatchMessage.sendToAllInRange(player, new GuildInfoMsg(player , guild, 2)); - - } - } + // Cleanup guild stuff + playerCharacter.resetGuildStatuses(); + + // send success message to client + if (fromTeleportScreen && guild.isNPCGuild()) + playerCharacter.setFullMember(true); + + msg = new AcceptInviteToGuildMsg(guild.getObjectUUID(), 1, 0); + + if (fromTeleportScreen) { + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } + if (DbManager.GuildQueries.ADD_TO_GUILDHISTORY(guild.getObjectUUID(), playerCharacter, DateTime.now(), historyType)) { + GuildHistory guildHistory = new GuildHistory(guild.getObjectUUID(), guild.getName(), DateTime.now(), historyType); + playerCharacter.getGuildHistory().add(guildHistory); + } + + DispatchMessage.sendToAllInRange(playerCharacter, new GuildInfoMsg(playerCharacter, guild, 2)); + + // Send guild join message + ChatManager.chatGuildInfo(playerCharacter, + playerCharacter.getFirstName() + " has joined the guild"); + + playerCharacter.incVer(); + + return true; + // TODO update player to world + } + + public static void enterWorldMOTD(PlayerCharacter pc) { + + Guild guild; + Guild nation; + + if (pc == null) { + return; + } + + guild = pc.getGuild(); + + if (guild == null || guild.getObjectUUID() == 0) // Don't send to errant + return; + + // Send Guild MOTD + String motd = guild.getMOTD(); + if (motd.length() > 0) { + ChatManager.chatGuildMOTD(pc, motd); + } + + // Send Nation MOTD + nation = guild.getNation(); + + if (nation != null) { + if (nation.getObjectUUID() != 0) { // Don't send to errant nation + motd = nation.getMOTD(); + if (motd.length() > 0) { + ChatManager.chatNationMOTD(pc, motd); + } + } + } + + // Send IC MOTD if player is IC + if (GuildStatusController.isInnerCouncil(pc.getGuildStatus())) { + motd = guild.getICMOTD(); + if (motd.length() > 0) { + ChatManager.chatICMOTD(pc, motd); + } + } + } + + //Updates the bind point for everyone in guild + + public static void updateAllGuildBinds(Guild guild, City city) { + + if (guild == null) + return; + + int cityID = (city != null) ? city.getObjectUUID() : 0; + + + //update binds ingame + + + for (PlayerCharacter playerCharacter : Guild.GuildRoster(guild)) { + boolean updateBindBuilding = false; + + Building oldBoundBuilding = BuildingManager.getBuildingFromCache(playerCharacter.getBindBuildingID()); + + if (oldBoundBuilding == null || oldBoundBuilding.getBlueprint() == null || oldBoundBuilding.getBlueprint().getBuildingGroup().equals(BuildingGroup.TOL)) + updateBindBuilding = true; + + + if (updateBindBuilding) { + Building bindBuilding = null; + if (city != null) + if (city.getTOL() != null) + bindBuilding = city.getTOL(); + + if (bindBuilding == null) + bindBuilding = PlayerCharacter.getBindBuildingForGuild(playerCharacter); + + playerCharacter.setBindBuildingID(bindBuilding != null ? bindBuilding.getObjectUUID() : 0); + } + + + } + } + + //This updates tags for all online players in a guild. + public static void updateAllGuildTags(Guild guild) { + + if (guild == null) + return; + + for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) { + + if (player.getGuild().equals(guild)) + DispatchMessage.sendToAllInRange(player, new GuildInfoMsg(player, guild, 2)); + + } + } } diff --git a/src/engine/gameManager/MaintenanceManager.java b/src/engine/gameManager/MaintenanceManager.java index 2cc15cf7..f92d531e 100644 --- a/src/engine/gameManager/MaintenanceManager.java +++ b/src/engine/gameManager/MaintenanceManager.java @@ -122,7 +122,7 @@ public enum MaintenanceManager { //no maintenance if day of week doesnt match - if(LocalDateTime.now().getDayOfWeek().ordinal() != building.maintDateTime.getDayOfWeek().ordinal()){ + if (LocalDateTime.now().getDayOfWeek().ordinal() != building.maintDateTime.getDayOfWeek().ordinal()) { continue; } // Add building to maintenance queue diff --git a/src/engine/gameManager/MovementManager.java b/src/engine/gameManager/MovementManager.java index d5e30fce..f38b502e 100644 --- a/src/engine/gameManager/MovementManager.java +++ b/src/engine/gameManager/MovementManager.java @@ -32,474 +32,469 @@ import static engine.math.FastMath.sqr; public enum MovementManager { - MOVEMENTMANAGER; - - private static final String changeAltitudeTimerJobName = "ChangeHeight"; - private static final String flightTimerJobName = "Flight"; - - public static void sendOOS(PlayerCharacter pc) { - pc.setWalkMode(true); - MovementManager.sendRWSSMsg(pc); - } - - public static void sendRWSSMsg(AbstractCharacter ac) { - - if (!ac.isAlive()) - return; - UpdateStateMsg rssm = new UpdateStateMsg(); - rssm.setPlayer(ac); - if (ac.getObjectType() == GameObjectType.PlayerCharacter) - DispatchMessage.dispatchMsgToInterestArea(ac, rssm, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - else - DispatchMessage.sendToAllInRange(ac, rssm); - } - - /* - * Sets the first combat target for the AbstractCharacter. Used to clear the - * combat - * target upon each move, unless something has set the firstHitCombatTarget - * Also used to determine the size of a monster's hitbox - */ - public static void movement(MoveToPointMsg msg, AbstractCharacter toMove) throws MsgSendException { - - // check for stun/root - if (!toMove.isAlive()) - return; - - if (toMove.getObjectType().equals(GameObjectType.PlayerCharacter)){ - if (((PlayerCharacter)toMove).isCasting()) - ((PlayerCharacter)toMove).update(); - } - - - - toMove.setIsCasting(false); - toMove.setItemCasting(false); - - if (toMove.getBonuses().getBool(ModType.Stunned, SourceType.None) || toMove.getBonuses().getBool(ModType.CannotMove, SourceType.None)) { - return; - } - - if (msg.getEndLat() > MBServerStatics.MAX_WORLD_WIDTH) - msg.setEndLat((float) MBServerStatics.MAX_WORLD_WIDTH); - - if (msg.getEndLon() < MBServerStatics.MAX_WORLD_HEIGHT){ - msg.setEndLon((float) MBServerStatics.MAX_WORLD_HEIGHT); - } - + MOVEMENTMANAGER; + + private static final String changeAltitudeTimerJobName = "ChangeHeight"; + private static final String flightTimerJobName = "Flight"; + + public static void sendOOS(PlayerCharacter pc) { + pc.setWalkMode(true); + MovementManager.sendRWSSMsg(pc); + } + + public static void sendRWSSMsg(AbstractCharacter ac) { + + if (!ac.isAlive()) + return; + UpdateStateMsg rssm = new UpdateStateMsg(); + rssm.setPlayer(ac); + if (ac.getObjectType() == GameObjectType.PlayerCharacter) + DispatchMessage.dispatchMsgToInterestArea(ac, rssm, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + else + DispatchMessage.sendToAllInRange(ac, rssm); + } + + /* + * Sets the first combat target for the AbstractCharacter. Used to clear the + * combat + * target upon each move, unless something has set the firstHitCombatTarget + * Also used to determine the size of a monster's hitbox + */ + public static void movement(MoveToPointMsg msg, AbstractCharacter toMove) throws MsgSendException { + + // check for stun/root + if (!toMove.isAlive()) + return; + + if (toMove.getObjectType().equals(GameObjectType.PlayerCharacter)) { + if (((PlayerCharacter) toMove).isCasting()) + ((PlayerCharacter) toMove).update(); + } + + + toMove.setIsCasting(false); + toMove.setItemCasting(false); + + if (toMove.getBonuses().getBool(ModType.Stunned, SourceType.None) || toMove.getBonuses().getBool(ModType.CannotMove, SourceType.None)) { + return; + } + + if (msg.getEndLat() > MBServerStatics.MAX_WORLD_WIDTH) + msg.setEndLat((float) MBServerStatics.MAX_WORLD_WIDTH); + + if (msg.getEndLon() < MBServerStatics.MAX_WORLD_HEIGHT) { + msg.setEndLon((float) MBServerStatics.MAX_WORLD_HEIGHT); + } + // if (msg.getEndLat() < 0) // msg.setEndLat(0); // // if (msg.getEndLon() > 0) // msg.setEndLon(0); - - - - - - if (!toMove.isMoving()) - toMove.resetLastSetLocUpdate(); - else - toMove.update(); - - // Update movement for the player - - - // else if (toMove.getObjectType() == GameObjectType.Mob) - // ((Mob)toMove).updateLocation(); - // get start and end locations for the move - Vector3fImmutable startLocation = new Vector3fImmutable(msg.getStartLat(), msg.getStartAlt(), msg.getStartLon()); - Vector3fImmutable endLocation = new Vector3fImmutable(msg.getEndLat(), msg.getEndAlt(), msg.getEndLon()); - - // if (toMove.getObjectType() == GameObjectType.PlayerCharacter) - // if (msg.getEndAlt() == 0 && msg.getTargetID() == 0){ - // MovementManager.sendRWSSMsg(toMove); - // } - - //If in Building, let's see if we need to Fix - - // if inside a building, convert both locations from the building local reference frame to the world reference frame - - if (msg.getTargetID() > 0) { - Building building = BuildingManager.getBuildingFromCache(msg.getTargetID()); - if (building != null) { - - Vector3fImmutable convertLocEnd = new Vector3fImmutable(ZoneManager.convertLocalToWorld(building, endLocation)); - // if (!Bounds.collide(convertLocEnd, b) || !b.loadObjectsInside()) { - // toMove.setInBuilding(-1); - // toMove.setInFloorID(-1); - // toMove.setInBuildingID(0); - // } - // else { - toMove.setInBuilding(msg.getInBuilding()); - toMove.setInFloorID(msg.getUnknown01()); - toMove.setInBuildingID(msg.getTargetID()); - msg.setStartCoord(ZoneManager.convertWorldToLocal(building, toMove.getLoc())); - - if (toMove.getObjectType() == GameObjectType.PlayerCharacter) { - if (convertLocEnd.distanceSquared2D(toMove.getLoc()) > 6000 * 6000) { - - Logger.info( "ENDLOC:" + convertLocEnd.x + ',' + convertLocEnd.y + ',' + convertLocEnd.z + - ',' + "GETLOC:" + toMove.getLoc().x + ',' + toMove.getLoc().y + ',' + toMove.getLoc().z + " Name " + ((PlayerCharacter) toMove).getCombinedName()); - toMove.teleport(toMove.getLoc()); - - return; - } - } - - startLocation = toMove.getLoc(); - endLocation = convertLocEnd; - - } else { - - toMove.setInBuilding(-1); - toMove.setInFloorID(-1); - toMove.setInBuildingID(0); - //SYNC PLAYER - toMove.teleport(toMove.getLoc()); - return; - } - - } else { - toMove.setInBuildingID(0); - toMove.setInFloorID(-1); - toMove.setInBuilding(-1); - msg.setStartCoord(toMove.getLoc()); - } - - //make sure we set the correct player. - msg.setSourceType(toMove.getObjectType().ordinal()); - msg.setSourceID(toMove.getObjectUUID()); - - //if player in region, modify location to local location of building. set target to building. - if (toMove.region != null) { - Building regionBuilding = Regions.GetBuildingForRegion(toMove.region); - if (regionBuilding != null) { - msg.setStartCoord(ZoneManager.convertWorldToLocal(Regions.GetBuildingForRegion(toMove.region), toMove.getLoc())); - msg.setEndCoord(ZoneManager.convertWorldToLocal(regionBuilding, endLocation)); - msg.setInBuilding(toMove.region.level); - msg.setUnknown01(toMove.region.room); - msg.setTargetType(GameObjectType.Building.ordinal()); - msg.setTargetID(regionBuilding.getObjectUUID()); - } - - } else { - toMove.setInBuildingID(0); - toMove.setInFloorID(-1); - toMove.setInBuilding(-1); - msg.setStartCoord(toMove.getLoc()); - msg.setEndCoord(endLocation); - msg.setTargetType(0); - msg.setTargetID(0); - } - - //checks sync between character and server, if out of sync, teleport player to original position and return. - if (toMove.getObjectType() == GameObjectType.PlayerCharacter) { - boolean startLocInSync = checkSync(toMove, startLocation, toMove.getLoc()); - - if (!startLocInSync){ - syncLoc(toMove, toMove.getLoc(), startLocInSync); - return; - } - - } - - // set direction, based on the current location which has just been sync'd - // with the client and the calc'd destination - toMove.setFaceDir(endLocation.subtract2D(toMove.getLoc()).normalize()); - - boolean collide = false; - if (toMove.getObjectType().equals(GameObjectType.PlayerCharacter)) { - Vector3fImmutable collidePoint = Bounds.PlayerBuildingCollisionPoint((PlayerCharacter)toMove, toMove.getLoc(), endLocation); - - if (collidePoint != null) { - msg.setEndCoord(collidePoint); - endLocation = collidePoint; - collide = true; - } - - } - - if (toMove.getObjectType() == GameObjectType.PlayerCharacter && ((PlayerCharacter) toMove).isTeleportMode()) { - toMove.teleport(endLocation); - return; - } - - // move to end location, this can interrupt the current move - toMove.setEndLoc(endLocation); - - // ChatManager.chatSystemInfo((PlayerCharacter)toMove, "Moving to " + Vector3fImmutable.toString(endLocation)); - - // make sure server knows player is not sitting - toMove.setSit(false); - - // cancel any effects that break upon movement - toMove.cancelOnMove(); - - //cancel any attacks for manual move. - if ((toMove.getObjectType() == GameObjectType.PlayerCharacter) && msg.getUnknown02() == 0) - toMove.setCombatTarget(null); - - - // If it's not a player moving just send the message - - if ((toMove.getObjectType() == GameObjectType.PlayerCharacter) == false) { - DispatchMessage.sendToAllInRange(toMove, msg); - return; - } - - // If it's a player who is moving then we need to handle characters - // who should see the message via group follow - - PlayerCharacter player = (PlayerCharacter) toMove; - - player.setTimeStamp("lastMoveGate", System.currentTimeMillis()); - - if (collide) - DispatchMessage.dispatchMsgToInterestArea(player, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - else - DispatchMessage.dispatchMsgToInterestArea(player, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); - - - // Handle formation movement if needed - - if (player.getFollow() == false) - return; - - - City cityObject = null; - Zone serverZone = null; - - serverZone = ZoneManager.findSmallestZone(player.getLoc()); - cityObject = (City) DbManager.getFromCache(GameObjectType.City, serverZone.getPlayerCityUUID()); - - // Do not send group messages if player is on grid - - if (cityObject != null) - return; - - // If player is not in a group we can exit here - - Group group = GroupManager.getGroup(player); - if (group == null) - return; - - // Echo group movement messages - if (group.getGroupLead().getObjectUUID() == player.getObjectUUID()) - moveGroup(player, player.getClientConnection(), msg); - - } + if (!toMove.isMoving()) + toMove.resetLastSetLocUpdate(); + else + toMove.update(); + + // Update movement for the player + + + // else if (toMove.getObjectType() == GameObjectType.Mob) + // ((Mob)toMove).updateLocation(); + // get start and end locations for the move + Vector3fImmutable startLocation = new Vector3fImmutable(msg.getStartLat(), msg.getStartAlt(), msg.getStartLon()); + Vector3fImmutable endLocation = new Vector3fImmutable(msg.getEndLat(), msg.getEndAlt(), msg.getEndLon()); + + // if (toMove.getObjectType() == GameObjectType.PlayerCharacter) + // if (msg.getEndAlt() == 0 && msg.getTargetID() == 0){ + // MovementManager.sendRWSSMsg(toMove); + // } + + //If in Building, let's see if we need to Fix + + // if inside a building, convert both locations from the building local reference frame to the world reference frame + + if (msg.getTargetID() > 0) { + Building building = BuildingManager.getBuildingFromCache(msg.getTargetID()); + if (building != null) { + + Vector3fImmutable convertLocEnd = new Vector3fImmutable(ZoneManager.convertLocalToWorld(building, endLocation)); + // if (!Bounds.collide(convertLocEnd, b) || !b.loadObjectsInside()) { + // toMove.setInBuilding(-1); + // toMove.setInFloorID(-1); + // toMove.setInBuildingID(0); + // } + // else { + toMove.setInBuilding(msg.getInBuilding()); + toMove.setInFloorID(msg.getUnknown01()); + toMove.setInBuildingID(msg.getTargetID()); + msg.setStartCoord(ZoneManager.convertWorldToLocal(building, toMove.getLoc())); + + if (toMove.getObjectType() == GameObjectType.PlayerCharacter) { + if (convertLocEnd.distanceSquared2D(toMove.getLoc()) > 6000 * 6000) { + + Logger.info("ENDLOC:" + convertLocEnd.x + ',' + convertLocEnd.y + ',' + convertLocEnd.z + + ',' + "GETLOC:" + toMove.getLoc().x + ',' + toMove.getLoc().y + ',' + toMove.getLoc().z + " Name " + ((PlayerCharacter) toMove).getCombinedName()); + toMove.teleport(toMove.getLoc()); + + return; + } + } + + startLocation = toMove.getLoc(); + endLocation = convertLocEnd; + + } else { + + toMove.setInBuilding(-1); + toMove.setInFloorID(-1); + toMove.setInBuildingID(0); + //SYNC PLAYER + toMove.teleport(toMove.getLoc()); + return; + } + + } else { + toMove.setInBuildingID(0); + toMove.setInFloorID(-1); + toMove.setInBuilding(-1); + msg.setStartCoord(toMove.getLoc()); + } + + //make sure we set the correct player. + msg.setSourceType(toMove.getObjectType().ordinal()); + msg.setSourceID(toMove.getObjectUUID()); + + //if player in region, modify location to local location of building. set target to building. + if (toMove.region != null) { + Building regionBuilding = Regions.GetBuildingForRegion(toMove.region); + if (regionBuilding != null) { + msg.setStartCoord(ZoneManager.convertWorldToLocal(Regions.GetBuildingForRegion(toMove.region), toMove.getLoc())); + msg.setEndCoord(ZoneManager.convertWorldToLocal(regionBuilding, endLocation)); + msg.setInBuilding(toMove.region.level); + msg.setUnknown01(toMove.region.room); + msg.setTargetType(GameObjectType.Building.ordinal()); + msg.setTargetID(regionBuilding.getObjectUUID()); + } + + } else { + toMove.setInBuildingID(0); + toMove.setInFloorID(-1); + toMove.setInBuilding(-1); + msg.setStartCoord(toMove.getLoc()); + msg.setEndCoord(endLocation); + msg.setTargetType(0); + msg.setTargetID(0); + } + + //checks sync between character and server, if out of sync, teleport player to original position and return. + if (toMove.getObjectType() == GameObjectType.PlayerCharacter) { + boolean startLocInSync = checkSync(toMove, startLocation, toMove.getLoc()); + + if (!startLocInSync) { + syncLoc(toMove, toMove.getLoc(), startLocInSync); + return; + } + + } + + // set direction, based on the current location which has just been sync'd + // with the client and the calc'd destination + toMove.setFaceDir(endLocation.subtract2D(toMove.getLoc()).normalize()); + + boolean collide = false; + if (toMove.getObjectType().equals(GameObjectType.PlayerCharacter)) { + Vector3fImmutable collidePoint = Bounds.PlayerBuildingCollisionPoint((PlayerCharacter) toMove, toMove.getLoc(), endLocation); + + if (collidePoint != null) { + msg.setEndCoord(collidePoint); + endLocation = collidePoint; + collide = true; + } + + } + + if (toMove.getObjectType() == GameObjectType.PlayerCharacter && ((PlayerCharacter) toMove).isTeleportMode()) { + toMove.teleport(endLocation); + return; + } + + // move to end location, this can interrupt the current move + toMove.setEndLoc(endLocation); + + // ChatManager.chatSystemInfo((PlayerCharacter)toMove, "Moving to " + Vector3fImmutable.toString(endLocation)); + + // make sure server knows player is not sitting + toMove.setSit(false); + + // cancel any effects that break upon movement + toMove.cancelOnMove(); + + //cancel any attacks for manual move. + if ((toMove.getObjectType() == GameObjectType.PlayerCharacter) && msg.getUnknown02() == 0) + toMove.setCombatTarget(null); + + + // If it's not a player moving just send the message + + if ((toMove.getObjectType() == GameObjectType.PlayerCharacter) == false) { + DispatchMessage.sendToAllInRange(toMove, msg); + return; + } + + // If it's a player who is moving then we need to handle characters + // who should see the message via group follow + + PlayerCharacter player = (PlayerCharacter) toMove; + + player.setTimeStamp("lastMoveGate", System.currentTimeMillis()); + + if (collide) + DispatchMessage.dispatchMsgToInterestArea(player, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + else + DispatchMessage.dispatchMsgToInterestArea(player, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); + + + // Handle formation movement if needed + + if (player.getFollow() == false) + return; + + + City cityObject = null; + Zone serverZone = null; + + serverZone = ZoneManager.findSmallestZone(player.getLoc()); + cityObject = (City) DbManager.getFromCache(GameObjectType.City, serverZone.getPlayerCityUUID()); + + // Do not send group messages if player is on grid + + if (cityObject != null) + return; + + // If player is not in a group we can exit here + + Group group = GroupManager.getGroup(player); + + if (group == null) + return; + + // Echo group movement messages + + if (group.getGroupLead().getObjectUUID() == player.getObjectUUID()) + moveGroup(player, player.getClientConnection(), msg); + + } - /** - * compare client and server location to verify that the two are in sync - * - * @param ac the player character - * @param clientLoc location as reported by the client - * @param serverLoc location known to the server - * @return true if the two are in sync - */ - private static boolean checkSync(AbstractCharacter ac, Vector3fImmutable clientLoc, Vector3fImmutable serverLoc) { + /** + * compare client and server location to verify that the two are in sync + * + * @param ac the player character + * @param clientLoc location as reported by the client + * @param serverLoc location known to the server + * @return true if the two are in sync + */ + private static boolean checkSync(AbstractCharacter ac, Vector3fImmutable clientLoc, Vector3fImmutable serverLoc) { - float desyncDist = clientLoc.distanceSquared2D(serverLoc); + float desyncDist = clientLoc.distanceSquared2D(serverLoc); - // desync logging - if (MBServerStatics.MOVEMENT_SYNC_DEBUG) - if (desyncDist > MBServerStatics.MOVEMENT_DESYNC_TOLERANCE * MBServerStatics.MOVEMENT_DESYNC_TOLERANCE) - // our current location server side is a calc of last known loc + direction + speed and known time of last update - Logger.debug("Movement out of sync for " + ac.getFirstName() - + ", Server Loc: " + serverLoc.getX() + ' ' + serverLoc.getZ() - + " , Client loc: " + clientLoc.getX() + ' ' + clientLoc.getZ() - + " desync distance " + desyncDist - + " moving=" + ac.isMoving()); - else - Logger.debug( "Movement sync is good - desyncDist = " + desyncDist); + // desync logging + if (MBServerStatics.MOVEMENT_SYNC_DEBUG) + if (desyncDist > MBServerStatics.MOVEMENT_DESYNC_TOLERANCE * MBServerStatics.MOVEMENT_DESYNC_TOLERANCE) + // our current location server side is a calc of last known loc + direction + speed and known time of last update + Logger.debug("Movement out of sync for " + ac.getFirstName() + + ", Server Loc: " + serverLoc.getX() + ' ' + serverLoc.getZ() + + " , Client loc: " + clientLoc.getX() + ' ' + clientLoc.getZ() + + " desync distance " + desyncDist + + " moving=" + ac.isMoving()); + else + Logger.debug("Movement sync is good - desyncDist = " + desyncDist); - if (ac.getDebug(1) && ac.getObjectType().equals(GameObjectType.PlayerCharacter)) - if (desyncDist > MBServerStatics.MOVEMENT_DESYNC_TOLERANCE * MBServerStatics.MOVEMENT_DESYNC_TOLERANCE) { - PlayerCharacter pc = (PlayerCharacter) ac; - ChatManager.chatSystemInfo(pc, - "Movement out of sync for " + ac.getFirstName() - + ", Server Loc: " + serverLoc.getX() + ' ' + serverLoc.getZ() - + " , Client loc: " + clientLoc.getX() + ' ' + clientLoc.getZ() - + " desync distance " + desyncDist - + " moving=" + ac.isMoving()); - } + if (ac.getDebug(1) && ac.getObjectType().equals(GameObjectType.PlayerCharacter)) + if (desyncDist > MBServerStatics.MOVEMENT_DESYNC_TOLERANCE * MBServerStatics.MOVEMENT_DESYNC_TOLERANCE) { + PlayerCharacter pc = (PlayerCharacter) ac; + ChatManager.chatSystemInfo(pc, + "Movement out of sync for " + ac.getFirstName() + + ", Server Loc: " + serverLoc.getX() + ' ' + serverLoc.getZ() + + " , Client loc: " + clientLoc.getX() + ' ' + clientLoc.getZ() + + " desync distance " + desyncDist + + " moving=" + ac.isMoving()); + } - // return indicator that the two are in sync or not - return (desyncDist < 100f * 100f); + // return indicator that the two are in sync or not + return (desyncDist < 100f * 100f); - } + } + public static void finishChangeAltitude(AbstractCharacter ac, float targetAlt) { - public static void finishChangeAltitude(AbstractCharacter ac, float targetAlt) { + if (ac.getObjectType().equals(GameObjectType.PlayerCharacter) == false) + return; - if (ac.getObjectType().equals(GameObjectType.PlayerCharacter) == false) - return; + //reset the getLoc timer before we clear other timers + // otherwise the next call to getLoc will not be correct + ac.resetLastSetLocUpdate(); - //reset the getLoc timer before we clear other timers - // otherwise the next call to getLoc will not be correct - ac.resetLastSetLocUpdate(); + // call getLoc once as it processes loc to the ms + Vector3fImmutable curLoc = ac.getLoc(); - // call getLoc once as it processes loc to the ms - Vector3fImmutable curLoc = ac.getLoc(); + if (MBServerStatics.MOVEMENT_SYNC_DEBUG) + Logger.info("Finished Alt change, setting the end location to " + + ac.getEndLoc().getX() + ' ' + ac.getEndLoc().getZ() + + " moving=" + ac.isMoving() + + " and current location is " + curLoc.getX() + ' ' + curLoc.getZ()); - if (MBServerStatics.MOVEMENT_SYNC_DEBUG) - Logger.info("Finished Alt change, setting the end location to " - + ac.getEndLoc().getX() + ' ' + ac.getEndLoc().getZ() - + " moving=" + ac.isMoving() - + " and current location is " + curLoc.getX() + ' ' + curLoc.getZ()); - - if (ac.getDebug(1) && ac.getObjectType().equals(GameObjectType.PlayerCharacter)) - ChatManager.chatSystemInfo((PlayerCharacter) ac, "Finished Alt change, setting the end location to " + ac.getEndLoc().getX() + ' ' + ac.getEndLoc().getZ() + " moving=" + ac.isMoving() + " and current location is " + curLoc.getX() + ' ' + curLoc.getZ()); - - //Send run/walk/sit/stand to tell the client we are flying / landing etc - ac.update(); - ac.stopMovement(ac.getLoc()); - if (ac.isAlive()) - MovementManager.sendRWSSMsg(ac); - - //Check collision again - } - - - // Handle formation movement in group - - public static void moveGroup(PlayerCharacter pc, ClientConnection origin, MoveToPointMsg msg) throws MsgSendException { - // get forward vector - Vector3f faceDir = new Vector3f(pc.getFaceDir().x, 0, pc.getFaceDir().z).normalize(); - // get perpendicular vector - Vector3f crossDir = new Vector3f(faceDir.z, 0, -faceDir.x); - - //get source loc with altitude - Vector3f sLoc = new Vector3f(pc.getLoc().x, pc.getAltitude(), pc.getLoc().z); - - Group group = GroupManager.getGroup(pc); - Set members = group.getMembers(); - int pos = 0; - for (PlayerCharacter member : members) { - - if (member == null) - continue; - if (member.getObjectUUID() == pc.getObjectUUID()) - continue; - - MoveToPointMsg groupMsg = new MoveToPointMsg(msg); - - // Verify group member should be moved - - pos++; - if (member.getFollow() != true) - continue; - - //get member loc with altitude, then range against source loc - Vector3f mLoc = new Vector3f(member.getLoc().x, member.getAltitude(), member.getLoc().z); - - if (sLoc.distanceSquared2D(mLoc) > sqr(MBServerStatics.FORMATION_RANGE)) - continue; - - //don't move if player has taken damage from another player in last 60 seconds - long lastAttacked = System.currentTimeMillis() - pc.getLastPlayerAttackTime(); - if (lastAttacked < 60000) - continue; - - if (!member.isAlive()) - continue; - - //don't move if player is stunned or rooted - PlayerBonuses bonus = member.getBonuses(); - if (bonus.getBool(ModType.Stunned, SourceType.None) || bonus.getBool(ModType.CannotMove, SourceType.None)) - continue; - - member.update(); - - - // All checks passed, let's move the player - // First get the offset position - Vector3f offset = Formation.getOffset(group.getFormation(), pos); - Vector3fImmutable destination = pc.getEndLoc(); - // offset forwards or backwards - destination = destination.add(faceDir.mult(offset.z)); - // offset left or right - destination = destination.add(crossDir.mult(offset.x)); - // ArrayList awoList = WorldGrid.INSTANCE.getObjectsInRangePartial(member, member.getLoc().distance2D(destination) +1000, MBServerStatics.MASK_BUILDING); - // - // boolean skip = false; - // - // for (AbstractWorldObject awo: awoList){ - // Building building = (Building)awo; - // - // if (building.getBounds() != null){ - // if (Bounds.collide(building, member.getLoc(), destination)){ - // skip = true; - // break; - // } - // - // } - // - // } - // - // if (skip) - // continue; - // if (member.isMoving()) - // member.stopMovement(); - - // Update player speed to match group lead speed and make standing - if (member.isSit() || (member.isWalk() != pc.isWalk())) { - member.setSit(false); - member.setWalkMode(pc.isWalk()); - MovementManager.sendRWSSMsg(member); - } - - //cancel any effects that break upon movement - member.cancelOnMove(); - - // send movement for other players to see - groupMsg.setSourceID(member.getObjectUUID()); - groupMsg.setStartCoord(member.getLoc()); - groupMsg.setEndCoord(destination); - groupMsg.clearTarget(); - DispatchMessage.sendToAllInRange(member, groupMsg); - - // update group member - member.setFaceDir(destination.subtract2D(member.getLoc()).normalize()); - member.setEndLoc(destination); - } - } - - public static void translocate(AbstractCharacter teleporter, Vector3fImmutable targetLoc, Regions region) { - - - if (targetLoc == null) - return; - - Vector3fImmutable oldLoc = new Vector3fImmutable(teleporter.getLoc()); - - teleporter.stopMovement(targetLoc); - teleporter.setRegion(region); - - //mobs ignore region sets for now. - if (teleporter.getObjectType().equals(GameObjectType.Mob)){ - teleporter.setInBuildingID(0); - teleporter.setInBuilding(-1); - teleporter.setInFloorID(-1); - TeleportToPointMsg msg = new TeleportToPointMsg(teleporter, targetLoc.getX(), targetLoc.getY(), targetLoc.getZ(), 0, -1, -1); - DispatchMessage.dispatchMsgToInterestArea(oldLoc, teleporter, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); - return; - } - TeleportToPointMsg msg = new TeleportToPointMsg(teleporter, targetLoc.getX(), targetLoc.getY(), targetLoc.getZ(), 0, -1, -1); - //we shouldnt need to send teleport message to new area, as loadjob should pick it up. - // DispatchMessage.dispatchMsgToInterestArea(teleporter, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - DispatchMessage.dispatchMsgToInterestArea(oldLoc, teleporter, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - - if (teleporter.getObjectType().equals(GameObjectType.PlayerCharacter)) - InterestManager.INTERESTMANAGER.HandleLoadForTeleport((PlayerCharacter)teleporter); - - } - - private static void syncLoc(AbstractCharacter ac, Vector3fImmutable clientLoc, boolean useClientLoc) { - ac.teleport(ac.getLoc()); - } + if (ac.getDebug(1) && ac.getObjectType().equals(GameObjectType.PlayerCharacter)) + ChatManager.chatSystemInfo((PlayerCharacter) ac, "Finished Alt change, setting the end location to " + ac.getEndLoc().getX() + ' ' + ac.getEndLoc().getZ() + " moving=" + ac.isMoving() + " and current location is " + curLoc.getX() + ' ' + curLoc.getZ()); + + //Send run/walk/sit/stand to tell the client we are flying / landing etc + ac.update(); + ac.stopMovement(ac.getLoc()); + if (ac.isAlive()) + MovementManager.sendRWSSMsg(ac); + + //Check collision again + } + + + // Handle formation movement in group + + public static void moveGroup(PlayerCharacter pc, ClientConnection origin, MoveToPointMsg msg) throws MsgSendException { + // get forward vector + Vector3f faceDir = new Vector3f(pc.getFaceDir().x, 0, pc.getFaceDir().z).normalize(); + // get perpendicular vector + Vector3f crossDir = new Vector3f(faceDir.z, 0, -faceDir.x); + + //get source loc with altitude + Vector3f sLoc = new Vector3f(pc.getLoc().x, pc.getAltitude(), pc.getLoc().z); + + Group group = GroupManager.getGroup(pc); + Set members = group.getMembers(); + int pos = 0; + for (PlayerCharacter member : members) { + + if (member == null) + continue; + if (member.getObjectUUID() == pc.getObjectUUID()) + continue; + + MoveToPointMsg groupMsg = new MoveToPointMsg(msg); + + // Verify group member should be moved + + pos++; + if (member.getFollow() != true) + continue; + + //get member loc with altitude, then range against source loc + Vector3f mLoc = new Vector3f(member.getLoc().x, member.getAltitude(), member.getLoc().z); + + if (sLoc.distanceSquared2D(mLoc) > sqr(MBServerStatics.FORMATION_RANGE)) + continue; + + //don't move if player has taken damage from another player in last 60 seconds + long lastAttacked = System.currentTimeMillis() - pc.getLastPlayerAttackTime(); + if (lastAttacked < 60000) + continue; + + if (!member.isAlive()) + continue; + + //don't move if player is stunned or rooted + PlayerBonuses bonus = member.getBonuses(); + if (bonus.getBool(ModType.Stunned, SourceType.None) || bonus.getBool(ModType.CannotMove, SourceType.None)) + continue; + + member.update(); + + + // All checks passed, let's move the player + // First get the offset position + Vector3f offset = Formation.getOffset(group.getFormation(), pos); + Vector3fImmutable destination = pc.getEndLoc(); + // offset forwards or backwards + destination = destination.add(faceDir.mult(offset.z)); + // offset left or right + destination = destination.add(crossDir.mult(offset.x)); + // ArrayList awoList = WorldGrid.INSTANCE.getObjectsInRangePartial(member, member.getLoc().distance2D(destination) +1000, MBServerStatics.MASK_BUILDING); + // + // boolean skip = false; + // + // for (AbstractWorldObject awo: awoList){ + // Building building = (Building)awo; + // + // if (building.getBounds() != null){ + // if (Bounds.collide(building, member.getLoc(), destination)){ + // skip = true; + // break; + // } + // + // } + // + // } + // + // if (skip) + // continue; + // if (member.isMoving()) + // member.stopMovement(); + + // Update player speed to match group lead speed and make standing + if (member.isSit() || (member.isWalk() != pc.isWalk())) { + member.setSit(false); + member.setWalkMode(pc.isWalk()); + MovementManager.sendRWSSMsg(member); + } + + //cancel any effects that break upon movement + member.cancelOnMove(); + + // send movement for other players to see + groupMsg.setSourceID(member.getObjectUUID()); + groupMsg.setStartCoord(member.getLoc()); + groupMsg.setEndCoord(destination); + groupMsg.clearTarget(); + DispatchMessage.sendToAllInRange(member, groupMsg); + + // update group member + member.setFaceDir(destination.subtract2D(member.getLoc()).normalize()); + member.setEndLoc(destination); + } + } + + public static void translocate(AbstractCharacter teleporter, Vector3fImmutable targetLoc, Regions region) { + + + if (targetLoc == null) + return; + + Vector3fImmutable oldLoc = new Vector3fImmutable(teleporter.getLoc()); + + teleporter.stopMovement(targetLoc); + teleporter.setRegion(region); + + //mobs ignore region sets for now. + if (teleporter.getObjectType().equals(GameObjectType.Mob)) { + teleporter.setInBuildingID(0); + teleporter.setInBuilding(-1); + teleporter.setInFloorID(-1); + TeleportToPointMsg msg = new TeleportToPointMsg(teleporter, targetLoc.getX(), targetLoc.getY(), targetLoc.getZ(), 0, -1, -1); + DispatchMessage.dispatchMsgToInterestArea(oldLoc, teleporter, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); + return; + } + TeleportToPointMsg msg = new TeleportToPointMsg(teleporter, targetLoc.getX(), targetLoc.getY(), targetLoc.getZ(), 0, -1, -1); + //we shouldnt need to send teleport message to new area, as loadjob should pick it up. + // DispatchMessage.dispatchMsgToInterestArea(teleporter, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + DispatchMessage.dispatchMsgToInterestArea(oldLoc, teleporter, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + + if (teleporter.getObjectType().equals(GameObjectType.PlayerCharacter)) + InterestManager.INTERESTMANAGER.HandleLoadForTeleport((PlayerCharacter) teleporter); + + } + + private static void syncLoc(AbstractCharacter ac, Vector3fImmutable clientLoc, boolean useClientLoc) { + ac.teleport(ac.getLoc()); + } } diff --git a/src/engine/gameManager/NPCManager.java b/src/engine/gameManager/NPCManager.java index ea79c58f..448aa587 100644 --- a/src/engine/gameManager/NPCManager.java +++ b/src/engine/gameManager/NPCManager.java @@ -199,7 +199,6 @@ public enum NPCManager { } - public static void removeSiegeMinions(Mob mobile) { for (Mob toRemove : mobile.siegeMinionMap.keySet()) { diff --git a/src/engine/gameManager/PowersManager.java b/src/engine/gameManager/PowersManager.java index 59a4aa36..5cdd14f5 100644 --- a/src/engine/gameManager/PowersManager.java +++ b/src/engine/gameManager/PowersManager.java @@ -44,411 +44,408 @@ import static engine.math.FastMath.sqr; public enum PowersManager { - POWERMANAGER; + POWERMANAGER; - public static HashMap powersBaseByIDString = new HashMap<>(); - public static HashMap powersBaseByToken = new HashMap<>(); - public static HashMap effectsBaseByIDString = new HashMap<>(); - public static HashMap effectsBaseByToken = new HashMap<>(); - public static HashMap powerActionsByIDString = new HashMap<>(); - public static HashMap powerActionsByID = new HashMap<>(); - public static HashMap ActionTokenByIDString = new HashMap<>(); - public static HashMap modifiersByToken = new HashMap<>(); - public static HashMap AnimationOverrides = new HashMap<>(); - private static JobScheduler js; - public static HashMap> AllMobPowers = new HashMap<>(); - - public static void initPowersManager(boolean fullPowersLoad) { - - if (fullPowersLoad) - PowersManager.InitializePowers(); - else - PowersManager.InitializeLoginPowers(); - - PowersManager.js = JobScheduler.getInstance(); - - } - - private PowersManager() { - - } - - public static PowersBase getPowerByToken(int token) { - return PowersManager.powersBaseByToken.get(token); - } - - public static PowersBase getPowerByIDString(String IDString) { - return PowersManager.powersBaseByIDString.get(IDString); - } - - public static EffectsBase getEffectByIDString(String IDString) { - return PowersManager.effectsBaseByIDString.get(IDString); - } - - public static AbstractPowerAction getPowerActionByID(Integer id) { - return PowersManager.powerActionsByID.get(id); - } - - public static AbstractPowerAction getPowerActionByIDString(String IDString) { - return PowersManager.powerActionsByIDString.get(IDString); - } - - public static EffectsBase getEffectByToken(int token) { - return PowersManager.effectsBaseByToken.get(token); - } - - // This pre-loads only PowersBase for login - public static void InitializeLoginPowers() { - - // get all PowersBase - ArrayList pbList = dbSkillReqHandler.getAllPowersBase(); - - for (PowersBase pb : pbList) { - if (pb.getToken() != 0) - PowersManager.powersBaseByToken.put(pb.getToken(), pb); - } - } - - // This pre-loads all powers and effects - public static void InitializePowers() { - - // Add EffectsBase - ArrayList ebList = dbEffectsBaseHandler.getAllEffectsBase(); - - for (EffectsBase eb : ebList) { - PowersManager.effectsBaseByToken.put(eb.getToken(), eb); - PowersManager.effectsBaseByIDString.put(eb.getIDString(), eb); - - } - - // Add Fail Conditions - EffectsBase.getFailConditions(PowersManager.effectsBaseByIDString); - - // Add Modifiers to Effects - dbEffectsBaseHandler.cacheAllEffectModifiers(); - - // Add Source Types to Effects - PowersManager.addAllSourceTypes(); - PowersManager.addAllAnimationOverrides(); - - // Add PowerActions - AbstractPowerAction.getAllPowerActions(PowersManager.powerActionsByIDString, PowersManager.powerActionsByID, PowersManager.effectsBaseByIDString); - - // Load valid Item Flags - // AbstractPowerAction.loadValidItemFlags(PowersManager.powerActionsByIDString); - - // get all PowersBase - ArrayList pbList = dbSkillReqHandler.getAllPowersBase(); - for (PowersBase pb : pbList) { - if (pb.getToken() != 0) { - PowersManager.powersBaseByIDString.put(pb.getIDString(), pb); - PowersManager.powersBaseByToken.put(pb.getToken(), pb); - } - } - - // Add Power Prereqs - PowerPrereq.getAllPowerPrereqs(PowersManager.powersBaseByIDString); - // Add Fail Conditions - dbSkillReqHandler.getFailConditions(PowersManager.powersBaseByIDString); - // Add Actions Base - ActionsBase.getActionsBase(PowersManager.powersBaseByIDString, - PowersManager.powerActionsByIDString); - - } - - private static void addAllSourceTypes() { - PreparedStatementShared ps = null; - try { - ps = new PreparedStatementShared("SELECT * FROM static_power_sourcetype"); - ResultSet rs = ps.executeQuery(); - String IDString, source; - while (rs.next()) { - IDString = rs.getString("IDString"); - int token = DbManager.hasher.SBStringHash(IDString); - - - source = rs.getString("source").replace("-", "").trim(); - EffectSourceType effectSourceType = EffectSourceType.GetEffectSourceType(source); - - if (EffectsBase.effectSourceTypeMap.containsKey(token) == false) - EffectsBase.effectSourceTypeMap.put(token, new HashSet<>()); - - EffectsBase.effectSourceTypeMap.get(token).add(effectSourceType); - } - rs.close(); - } catch (Exception e) { - Logger.error( e); - } finally { - ps.release(); - } - } - - private static void addAllAnimationOverrides() { - PreparedStatementShared ps = null; - try { - ps = new PreparedStatementShared("SELECT * FROM static_power_animation_override"); - ResultSet rs = ps.executeQuery(); - String IDString; - int animation; - while (rs.next()) { - IDString = rs.getString("IDString"); - - EffectsBase eb = PowersManager.getEffectByIDString(IDString); - if (eb != null) - IDString = eb.getIDString(); - - animation = rs.getInt("animation"); - PowersManager.AnimationOverrides.put(IDString, animation); - - } - rs.close(); - } catch (Exception e) { - Logger.error( e); - } finally { - ps.release(); - } - } - - public static EffectsBase setEffectToken(int ID, int token) { - for (EffectsBase eb : PowersManager.effectsBaseByIDString.values()) { - if (eb.getUUID() == ID) { - eb.setToken(token); - return eb; - } - } - return null; - } - - public static void usePower(final PerformActionMsg msg, ClientConnection origin, - boolean sendCastToSelf) { - - if (usePowerA(msg, origin, sendCastToSelf)) { - // Cast failed for some reason, reset timer - - RecyclePowerMsg recyclePowerMsg = new RecyclePowerMsg(msg.getPowerUsedID()); - Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), recyclePowerMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - - // Send Fail to cast message - PlayerCharacter pc = SessionManager - .getPlayerCharacter(origin); - - if (pc != null) { - sendPowerMsg(pc, 2, msg); - if (pc.isCasting()){ - pc.update(); - } - - pc.setIsCasting(false); - } - - } - } - - public static void useMobPower(Mob caster, AbstractCharacter target, PowersBase pb, int rank) { - - PerformActionMsg msg = createPowerMsg(pb, rank, caster, target); - msg.setUnknown04(1); - - if (useMobPowerA(msg, caster)) { - //sendMobPowerMsg(caster,2,msg); //Lol wtf was i thinking sending msg's to mobs... ZZZZ - } - } - - public static boolean usePowerA(final PerformActionMsg msg, ClientConnection origin, - boolean sendCastToSelf) { - PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter( - origin); - if (playerCharacter == null) - return false; - - boolean CSRCast = false; - - - if (MBServerStatics.POWERS_DEBUG) { - ChatManager.chatSayInfo( - playerCharacter, - "Using Power: " + Integer.toHexString(msg.getPowerUsedID()) - + " (" + msg.getPowerUsedID() + ')'); - Logger.info( "Using Power: " - + Integer.toHexString(msg.getPowerUsedID()) + " (" - + msg.getPowerUsedID() + ')'); - } - - //Sending recycle message to player if died while casting. - if (!playerCharacter.isAlive() && msg.getPowerUsedID() != 428589216) { //succor - - RecyclePowerMsg recyclePowerMsg = new RecyclePowerMsg(msg.getPowerUsedID()); - Dispatch dispatch = Dispatch.borrow(playerCharacter, recyclePowerMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - - return false; - } - - - - - // if (!pc.getPowers().contains(msg.getPowerUsedID())) { - // sendPowerMsg(pc, 10, msg); - // return false; - // } - // verify recycle timer is not active for power, skip for a CSR - if (playerCharacter.getRecycleTimers().containsKey(msg.getPowerUsedID()) && !playerCharacter.isCSR()) { - // ChatManager.chatSayInfo(pc, "Recycle timer not finished!"); - - Logger.warn("usePowerA(): Cheat attempted? '" + msg.getPowerUsedID() + "' recycle timer not finished " + playerCharacter.getName()); - return false; - } - - // get power - PowersBase pb = PowersManager.powersBaseByToken.get(msg.getPowerUsedID()); - if (pb == null) { - ChatManager.chatSayInfo(playerCharacter, - "This power is not implemented yet."); - - // Logger.error("usePowerA(): Power '" + - // msg.getPowerUsedID() - // + "' was not found on powersBaseByToken map."); - return true; - // return false; - } - - if (playerCharacter.getLastPower() != null) - return true; - - //Check if Power Target is allowed to cast. - - - // Check powers for normal users - if (playerCharacter.getPowers() == null || !playerCharacter.getPowers().containsKey(msg.getPowerUsedID())) - if (!playerCharacter.isCSR()) { - if (!MBServerStatics.POWERS_DEBUG) { - // ChatManager.chatSayInfo(pc, "You may not cast that spell!"); - - Logger.info("usePowerA(): Cheat attempted? '" + msg.getPowerUsedID() + "' was not associated with " + playerCharacter.getName()); - return true; - } - } else - CSRCast = true; - - // get numTrains for power - int trains = msg.getNumTrains(); - - // can't go over the max trains for the power, unless CSR - if (trains > pb.getMaxTrains() && !playerCharacter.isCSR()) { - trains = pb.getMaxTrains(); - msg.setNumTrains(trains); - } - - // can't go over total trains by player - if (playerCharacter.getPowers() != null && playerCharacter.getPowers().containsKey(msg.getPowerUsedID())) { - CharacterPower cp = playerCharacter.getPowers().get(msg.getPowerUsedID()); - if (cp != null) { - int tot = cp.getTotalTrains(); - if (tot == 0 && !playerCharacter.isCSR()) - return false; - if (trains != tot && !playerCharacter.isCSR()) { - trains = tot; - msg.setNumTrains(trains); - } - } - } - - // get recycle time in ms - int time = pb.getRecycleTime(trains); - - // verify player is in correct mode (combat/nonCombat) - if (playerCharacter.isCombat()) { - if (!pb.allowedInCombat()) - // ChatManager.chatPowerError(pc, - // "This power is not allowed in combat mode."); - return true; - } else if (!pb.allowedOutOfCombat()) - // ChatManager.chatPowerError(pc, - // "You must be in combat mode to use this power."); - return true; - - // verify player is not stunned or prohibited from casting - PlayerBonuses bonus = playerCharacter.getBonuses(); -SourceType sourceType = SourceType.GetSourceType(pb.getCategory()); - if (bonus != null && (bonus.getBool(ModType.Stunned,SourceType.None) || bonus.getBool(ModType.CannotCast, SourceType.None) || bonus.getBool(ModType.BlockedPowerType, sourceType))) - return true; - - // if moving make sure spell valid for movement - Vector3fImmutable endLoc = playerCharacter.getEndLoc(); - - - if (!pb.canCastWhileMoving()) - if (playerCharacter.isMoving()){ - - // if movement left is less then 1 seconds worth then let cast - // go through. - float distanceLeftSquared = endLoc.distanceSquared2D(playerCharacter.getLoc()); - - if (distanceLeftSquared > sqr(playerCharacter.getSpeed())) - return true; - } - // if flying, make sure spell valid for flying. - // if (pc.getAltitude() > 0) - // if (!pb.canCastWhileFlying()) - // return true; - - int targetLiveCounter = -1; - - // get target based on targetType; - if (pb.targetFromLastTarget() || pb.targetPet()) // use msg's target - if (pb.isAOE()) { - if (!pb.usePointBlank()) { - AbstractWorldObject target = getTarget(msg); - - - - if (target != null && target.getObjectType() == GameObjectType.Building && !pb.targetBuilding()) { - PowersManager.sendPowerMsg(playerCharacter, 9, new PerformActionMsg(msg)); - return true; - } - - if (target == null) { - if (playerCharacter.getLoc().distanceSquared2D(msg.getTargetLoc()) > sqr(pb - .getRange())) - return true; - } else if (verifyInvalidRange(playerCharacter, target, pb.getRange())) - // pc.getLoc().distance(target.getLoc()) > - // pb.getRange()) - return true; - - - } - } else { - // get target - AbstractWorldObject target = getTarget(msg); - - if (target == null) - return true; - - if (!target.isAlive() && target.getObjectType().equals(GameObjectType.Building) == false && msg.getPowerUsedID() != 428589216) - return true; - - float range = pb.getRange(); - // verify target is in range - - - if (verifyInvalidRange(playerCharacter, target, range)) - // (pc.getLoc().distance(target.getLoc()) > pb.getRange()) { - // TODO send message that target is out of range - return true; - - // verify target is valid type - if (!validateTarget(target, playerCharacter, pb)) - return true; - - - if (AbstractWorldObject.IsAbstractCharacter(target)) - targetLiveCounter = ((AbstractCharacter) target).getLiveCounter(); - } - - // verify regular player can cast spell, otherwise authenticate - if (!pb.regularPlayerCanCast()) { + public static HashMap powersBaseByIDString = new HashMap<>(); + public static HashMap powersBaseByToken = new HashMap<>(); + public static HashMap effectsBaseByIDString = new HashMap<>(); + public static HashMap effectsBaseByToken = new HashMap<>(); + public static HashMap powerActionsByIDString = new HashMap<>(); + public static HashMap powerActionsByID = new HashMap<>(); + public static HashMap ActionTokenByIDString = new HashMap<>(); + public static HashMap modifiersByToken = new HashMap<>(); + public static HashMap AnimationOverrides = new HashMap<>(); + public static HashMap> AllMobPowers = new HashMap<>(); + private static JobScheduler js; + + private PowersManager() { + + } + + public static void initPowersManager(boolean fullPowersLoad) { + + if (fullPowersLoad) + PowersManager.InitializePowers(); + else + PowersManager.InitializeLoginPowers(); + + PowersManager.js = JobScheduler.getInstance(); + + } + + public static PowersBase getPowerByToken(int token) { + return PowersManager.powersBaseByToken.get(token); + } + + public static PowersBase getPowerByIDString(String IDString) { + return PowersManager.powersBaseByIDString.get(IDString); + } + + public static EffectsBase getEffectByIDString(String IDString) { + return PowersManager.effectsBaseByIDString.get(IDString); + } + + public static AbstractPowerAction getPowerActionByID(Integer id) { + return PowersManager.powerActionsByID.get(id); + } + + public static AbstractPowerAction getPowerActionByIDString(String IDString) { + return PowersManager.powerActionsByIDString.get(IDString); + } + + public static EffectsBase getEffectByToken(int token) { + return PowersManager.effectsBaseByToken.get(token); + } + + // This pre-loads only PowersBase for login + public static void InitializeLoginPowers() { + + // get all PowersBase + ArrayList pbList = dbSkillReqHandler.getAllPowersBase(); + + for (PowersBase pb : pbList) { + if (pb.getToken() != 0) + PowersManager.powersBaseByToken.put(pb.getToken(), pb); + } + } + + // This pre-loads all powers and effects + public static void InitializePowers() { + + // Add EffectsBase + ArrayList ebList = dbEffectsBaseHandler.getAllEffectsBase(); + + for (EffectsBase eb : ebList) { + PowersManager.effectsBaseByToken.put(eb.getToken(), eb); + PowersManager.effectsBaseByIDString.put(eb.getIDString(), eb); + + } + + // Add Fail Conditions + EffectsBase.getFailConditions(PowersManager.effectsBaseByIDString); + + // Add Modifiers to Effects + dbEffectsBaseHandler.cacheAllEffectModifiers(); + + // Add Source Types to Effects + PowersManager.addAllSourceTypes(); + PowersManager.addAllAnimationOverrides(); + + // Add PowerActions + AbstractPowerAction.getAllPowerActions(PowersManager.powerActionsByIDString, PowersManager.powerActionsByID, PowersManager.effectsBaseByIDString); + + // Load valid Item Flags + // AbstractPowerAction.loadValidItemFlags(PowersManager.powerActionsByIDString); + + // get all PowersBase + ArrayList pbList = dbSkillReqHandler.getAllPowersBase(); + for (PowersBase pb : pbList) { + if (pb.getToken() != 0) { + PowersManager.powersBaseByIDString.put(pb.getIDString(), pb); + PowersManager.powersBaseByToken.put(pb.getToken(), pb); + } + } + + // Add Power Prereqs + PowerPrereq.getAllPowerPrereqs(PowersManager.powersBaseByIDString); + // Add Fail Conditions + dbSkillReqHandler.getFailConditions(PowersManager.powersBaseByIDString); + // Add Actions Base + ActionsBase.getActionsBase(PowersManager.powersBaseByIDString, + PowersManager.powerActionsByIDString); + + } + + private static void addAllSourceTypes() { + PreparedStatementShared ps = null; + try { + ps = new PreparedStatementShared("SELECT * FROM static_power_sourcetype"); + ResultSet rs = ps.executeQuery(); + String IDString, source; + while (rs.next()) { + IDString = rs.getString("IDString"); + int token = DbManager.hasher.SBStringHash(IDString); + + + source = rs.getString("source").replace("-", "").trim(); + EffectSourceType effectSourceType = EffectSourceType.GetEffectSourceType(source); + + if (EffectsBase.effectSourceTypeMap.containsKey(token) == false) + EffectsBase.effectSourceTypeMap.put(token, new HashSet<>()); + + EffectsBase.effectSourceTypeMap.get(token).add(effectSourceType); + } + rs.close(); + } catch (Exception e) { + Logger.error(e); + } finally { + ps.release(); + } + } + + private static void addAllAnimationOverrides() { + PreparedStatementShared ps = null; + try { + ps = new PreparedStatementShared("SELECT * FROM static_power_animation_override"); + ResultSet rs = ps.executeQuery(); + String IDString; + int animation; + while (rs.next()) { + IDString = rs.getString("IDString"); + + EffectsBase eb = PowersManager.getEffectByIDString(IDString); + if (eb != null) + IDString = eb.getIDString(); + + animation = rs.getInt("animation"); + PowersManager.AnimationOverrides.put(IDString, animation); + + } + rs.close(); + } catch (Exception e) { + Logger.error(e); + } finally { + ps.release(); + } + } + + public static EffectsBase setEffectToken(int ID, int token) { + for (EffectsBase eb : PowersManager.effectsBaseByIDString.values()) { + if (eb.getUUID() == ID) { + eb.setToken(token); + return eb; + } + } + return null; + } + + public static void usePower(final PerformActionMsg msg, ClientConnection origin, + boolean sendCastToSelf) { + + if (usePowerA(msg, origin, sendCastToSelf)) { + // Cast failed for some reason, reset timer + + RecyclePowerMsg recyclePowerMsg = new RecyclePowerMsg(msg.getPowerUsedID()); + Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), recyclePowerMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + + // Send Fail to cast message + PlayerCharacter pc = SessionManager + .getPlayerCharacter(origin); + + if (pc != null) { + sendPowerMsg(pc, 2, msg); + if (pc.isCasting()) { + pc.update(); + } + + pc.setIsCasting(false); + } + + } + } + + public static void useMobPower(Mob caster, AbstractCharacter target, PowersBase pb, int rank) { + + PerformActionMsg msg = createPowerMsg(pb, rank, caster, target); + msg.setUnknown04(1); + + if (useMobPowerA(msg, caster)) { + //sendMobPowerMsg(caster,2,msg); //Lol wtf was i thinking sending msg's to mobs... ZZZZ + } + } + + public static boolean usePowerA(final PerformActionMsg msg, ClientConnection origin, + boolean sendCastToSelf) { + PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter( + origin); + if (playerCharacter == null) + return false; + + boolean CSRCast = false; + + + if (MBServerStatics.POWERS_DEBUG) { + ChatManager.chatSayInfo( + playerCharacter, + "Using Power: " + Integer.toHexString(msg.getPowerUsedID()) + + " (" + msg.getPowerUsedID() + ')'); + Logger.info("Using Power: " + + Integer.toHexString(msg.getPowerUsedID()) + " (" + + msg.getPowerUsedID() + ')'); + } + + //Sending recycle message to player if died while casting. + if (!playerCharacter.isAlive() && msg.getPowerUsedID() != 428589216) { //succor + + RecyclePowerMsg recyclePowerMsg = new RecyclePowerMsg(msg.getPowerUsedID()); + Dispatch dispatch = Dispatch.borrow(playerCharacter, recyclePowerMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + + return false; + } + + + // if (!pc.getPowers().contains(msg.getPowerUsedID())) { + // sendPowerMsg(pc, 10, msg); + // return false; + // } + // verify recycle timer is not active for power, skip for a CSR + if (playerCharacter.getRecycleTimers().containsKey(msg.getPowerUsedID()) && !playerCharacter.isCSR()) { + // ChatManager.chatSayInfo(pc, "Recycle timer not finished!"); + + Logger.warn("usePowerA(): Cheat attempted? '" + msg.getPowerUsedID() + "' recycle timer not finished " + playerCharacter.getName()); + return false; + } + + // get power + PowersBase pb = PowersManager.powersBaseByToken.get(msg.getPowerUsedID()); + if (pb == null) { + ChatManager.chatSayInfo(playerCharacter, + "This power is not implemented yet."); + + // Logger.error("usePowerA(): Power '" + + // msg.getPowerUsedID() + // + "' was not found on powersBaseByToken map."); + return true; + // return false; + } + + if (playerCharacter.getLastPower() != null) + return true; + + //Check if Power Target is allowed to cast. + + + // Check powers for normal users + if (playerCharacter.getPowers() == null || !playerCharacter.getPowers().containsKey(msg.getPowerUsedID())) + if (!playerCharacter.isCSR()) { + if (!MBServerStatics.POWERS_DEBUG) { + // ChatManager.chatSayInfo(pc, "You may not cast that spell!"); + + Logger.info("usePowerA(): Cheat attempted? '" + msg.getPowerUsedID() + "' was not associated with " + playerCharacter.getName()); + return true; + } + } else + CSRCast = true; + + // get numTrains for power + int trains = msg.getNumTrains(); + + // can't go over the max trains for the power, unless CSR + if (trains > pb.getMaxTrains() && !playerCharacter.isCSR()) { + trains = pb.getMaxTrains(); + msg.setNumTrains(trains); + } + + // can't go over total trains by player + if (playerCharacter.getPowers() != null && playerCharacter.getPowers().containsKey(msg.getPowerUsedID())) { + CharacterPower cp = playerCharacter.getPowers().get(msg.getPowerUsedID()); + if (cp != null) { + int tot = cp.getTotalTrains(); + if (tot == 0 && !playerCharacter.isCSR()) + return false; + if (trains != tot && !playerCharacter.isCSR()) { + trains = tot; + msg.setNumTrains(trains); + } + } + } + + // get recycle time in ms + int time = pb.getRecycleTime(trains); + + // verify player is in correct mode (combat/nonCombat) + if (playerCharacter.isCombat()) { + if (!pb.allowedInCombat()) + // ChatManager.chatPowerError(pc, + // "This power is not allowed in combat mode."); + return true; + } else if (!pb.allowedOutOfCombat()) + // ChatManager.chatPowerError(pc, + // "You must be in combat mode to use this power."); + return true; + + // verify player is not stunned or prohibited from casting + PlayerBonuses bonus = playerCharacter.getBonuses(); + SourceType sourceType = SourceType.GetSourceType(pb.getCategory()); + if (bonus != null && (bonus.getBool(ModType.Stunned, SourceType.None) || bonus.getBool(ModType.CannotCast, SourceType.None) || bonus.getBool(ModType.BlockedPowerType, sourceType))) + return true; + + // if moving make sure spell valid for movement + Vector3fImmutable endLoc = playerCharacter.getEndLoc(); + + + if (!pb.canCastWhileMoving()) + if (playerCharacter.isMoving()) { + + // if movement left is less then 1 seconds worth then let cast + // go through. + float distanceLeftSquared = endLoc.distanceSquared2D(playerCharacter.getLoc()); + + if (distanceLeftSquared > sqr(playerCharacter.getSpeed())) + return true; + } + // if flying, make sure spell valid for flying. + // if (pc.getAltitude() > 0) + // if (!pb.canCastWhileFlying()) + // return true; + + int targetLiveCounter = -1; + + // get target based on targetType; + if (pb.targetFromLastTarget() || pb.targetPet()) // use msg's target + if (pb.isAOE()) { + if (!pb.usePointBlank()) { + AbstractWorldObject target = getTarget(msg); + + + if (target != null && target.getObjectType() == GameObjectType.Building && !pb.targetBuilding()) { + PowersManager.sendPowerMsg(playerCharacter, 9, new PerformActionMsg(msg)); + return true; + } + + if (target == null) { + if (playerCharacter.getLoc().distanceSquared2D(msg.getTargetLoc()) > sqr(pb + .getRange())) + return true; + } else if (verifyInvalidRange(playerCharacter, target, pb.getRange())) + // pc.getLoc().distance(target.getLoc()) > + // pb.getRange()) + return true; + + + } + } else { + // get target + AbstractWorldObject target = getTarget(msg); + + if (target == null) + return true; + + if (!target.isAlive() && target.getObjectType().equals(GameObjectType.Building) == false && msg.getPowerUsedID() != 428589216) + return true; + + float range = pb.getRange(); + // verify target is in range + + + if (verifyInvalidRange(playerCharacter, target, range)) + // (pc.getLoc().distance(target.getLoc()) > pb.getRange()) { + // TODO send message that target is out of range + return true; + + // verify target is valid type + if (!validateTarget(target, playerCharacter, pb)) + return true; + + + if (AbstractWorldObject.IsAbstractCharacter(target)) + targetLiveCounter = ((AbstractCharacter) target).getLiveCounter(); + } + + // verify regular player can cast spell, otherwise authenticate + if (!pb.regularPlayerCanCast()) { Account a = SessionManager.getAccount(playerCharacter); if (a.status.equals(AccountStatus.ADMIN) == false) { Logger.warn("Player '" + playerCharacter.getName() @@ -457,2355 +454,2350 @@ SourceType sourceType = SourceType.GetSourceType(pb.getCategory()); } } - // verify player has proper effects applied to use power - if (pb.getEffectPrereqs().size() > 0 && playerCharacter.getEffects() != null) { - - boolean passed = false; - for (PowerPrereq pp : pb.getEffectPrereqs()) { - - EffectsBase eb = PowersManager.getEffectByIDString(pp.getEffect()); - - if (playerCharacter.containsEffect(eb.getToken())) { - passed = true; - break; - } - } - - if (!passed) - return true; - } - - //verify player has proper equipment to use power - if (pb.getEquipPrereqs().size() > 0) { - - boolean passed = false; - - for (PowerPrereq pp : pb.getEquipPrereqs()) { - - int slot = pp.mainHand() ? MBServerStatics.SLOT_MAINHAND : MBServerStatics.SLOT_OFFHAND; - - if (playerCharacter.validEquip(slot, pp.getMessage())) { - passed = true; //should have item in slot - break; - } else if (!pp.isRequired()) { - passed = true; //should not have item in slot - break; - } - } - if (!passed) - return true; - } - - // TODO if target immune to powers, cancel unless aoe - // Also make sure No.ImmuneToPowers is false for target - // if there's a different power waiting to finish, stop here - - - //get power cost and calculate any power cost modifiers - float cost = pb.getCost(trains); - - if (playerCharacter.isCSR()) - cost = 0; - - if (bonus != null) - cost *= (1 + bonus.getFloatPercentAll(ModType.PowerCost, SourceType.None)); - - if (playerCharacter.getAltitude() > 0) - cost *= 1.5f; - - // Verify player can afford to use power - //CCR toons dont use cost - - if (!playerCharacter.isCSR()){ - if (cost > 0) - if ((playerCharacter.getObjectTypeMask() & MBServerStatics.MASK_UNDEAD) != 0) - if (playerCharacter.getHealth() <= cost) - return true; - else { - playerCharacter.modifyHealth(-cost, playerCharacter, true); - ModifyHealthMsg mhm = new ModifyHealthMsg(playerCharacter, playerCharacter, -cost, - 0f, 0f, 0, null, - 9999, 0); - mhm.setOmitFromChat(1); - DispatchMessage.dispatchMsgToInterestArea(playerCharacter, mhm, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - } - else if (pb.useMana()) - if (playerCharacter.getMana() < cost) - return true; - else - playerCharacter.modifyMana(-cost, playerCharacter, true); - else if (pb.useStamina()) - if (playerCharacter.getStamina() < cost) - return true; - else - playerCharacter.modifyStamina(-cost, playerCharacter, true); - else if (playerCharacter.getHealth() <= cost) - return true; - else - playerCharacter.modifyHealth(-cost, playerCharacter, true); - } - - - // Validity checks passed, move on to casting spell - //get caster's live counter - int casterLiveCounter = playerCharacter.getLiveCounter(); - - // run recycle job for when cast is available again, don't bother adding the timer for CSRs - if (time > 0) { - FinishRecycleTimeJob frtj = new FinishRecycleTimeJob(playerCharacter, msg); - playerCharacter.getRecycleTimers().put(msg.getPowerUsedID(), js.scheduleJob(frtj, time)); - } else { - // else send recycle message to unlock power - RecyclePowerMsg recyclePowerMsg = new RecyclePowerMsg(msg.getPowerUsedID()); - Dispatch dispatch = Dispatch.borrow(playerCharacter, recyclePowerMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - } - - //what the fuck? + // verify player has proper effects applied to use power + if (pb.getEffectPrereqs().size() > 0 && playerCharacter.getEffects() != null) { + + boolean passed = false; + for (PowerPrereq pp : pb.getEffectPrereqs()) { + + EffectsBase eb = PowersManager.getEffectByIDString(pp.getEffect()); + + if (playerCharacter.containsEffect(eb.getToken())) { + passed = true; + break; + } + } + + if (!passed) + return true; + } + + //verify player has proper equipment to use power + if (pb.getEquipPrereqs().size() > 0) { + + boolean passed = false; + + for (PowerPrereq pp : pb.getEquipPrereqs()) { + + int slot = pp.mainHand() ? MBServerStatics.SLOT_MAINHAND : MBServerStatics.SLOT_OFFHAND; + + if (playerCharacter.validEquip(slot, pp.getMessage())) { + passed = true; //should have item in slot + break; + } else if (!pp.isRequired()) { + passed = true; //should not have item in slot + break; + } + } + if (!passed) + return true; + } + + // TODO if target immune to powers, cancel unless aoe + // Also make sure No.ImmuneToPowers is false for target + // if there's a different power waiting to finish, stop here + + + //get power cost and calculate any power cost modifiers + float cost = pb.getCost(trains); + + if (playerCharacter.isCSR()) + cost = 0; + + if (bonus != null) + cost *= (1 + bonus.getFloatPercentAll(ModType.PowerCost, SourceType.None)); + + if (playerCharacter.getAltitude() > 0) + cost *= 1.5f; + + // Verify player can afford to use power + //CCR toons dont use cost + + if (!playerCharacter.isCSR()) { + if (cost > 0) + if ((playerCharacter.getObjectTypeMask() & MBServerStatics.MASK_UNDEAD) != 0) + if (playerCharacter.getHealth() <= cost) + return true; + else { + playerCharacter.modifyHealth(-cost, playerCharacter, true); + ModifyHealthMsg mhm = new ModifyHealthMsg(playerCharacter, playerCharacter, -cost, + 0f, 0f, 0, null, + 9999, 0); + mhm.setOmitFromChat(1); + DispatchMessage.dispatchMsgToInterestArea(playerCharacter, mhm, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + } + else if (pb.useMana()) + if (playerCharacter.getMana() < cost) + return true; + else + playerCharacter.modifyMana(-cost, playerCharacter, true); + else if (pb.useStamina()) + if (playerCharacter.getStamina() < cost) + return true; + else + playerCharacter.modifyStamina(-cost, playerCharacter, true); + else if (playerCharacter.getHealth() <= cost) + return true; + else + playerCharacter.modifyHealth(-cost, playerCharacter, true); + } + + + // Validity checks passed, move on to casting spell + //get caster's live counter + int casterLiveCounter = playerCharacter.getLiveCounter(); + + // run recycle job for when cast is available again, don't bother adding the timer for CSRs + if (time > 0) { + FinishRecycleTimeJob frtj = new FinishRecycleTimeJob(playerCharacter, msg); + playerCharacter.getRecycleTimers().put(msg.getPowerUsedID(), js.scheduleJob(frtj, time)); + } else { + // else send recycle message to unlock power + RecyclePowerMsg recyclePowerMsg = new RecyclePowerMsg(msg.getPowerUsedID()); + Dispatch dispatch = Dispatch.borrow(playerCharacter, recyclePowerMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + } + + //what the fuck? // // Send cast to other players // if ((playerCharacter.getObjectTypeMask() & MBServerStatics.MASK_UNDEAD) != 0) // msg.setUnknown04(2); // Vampire Race, use health? // else // msg.setUnknown04(1); // Regular Race, use mana? - int tr = msg.getNumTrains(); - DispatchMessage.dispatchMsgToInterestArea(playerCharacter, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, sendCastToSelf, false); - - //Make new msg.. - PerformActionMsg copyMsg = new PerformActionMsg(msg); - copyMsg.setNumTrains(tr); - - // make person casting stand up if spell (unless they're casting a chant which does not make them stand up) - if (pb.isSpell() && !pb.isChant() && playerCharacter.isSit()) { - playerCharacter.update(); - playerCharacter.setSit(false); - UpdateStateMsg updateStateMsg = new UpdateStateMsg(playerCharacter); - DispatchMessage.dispatchMsgToInterestArea(playerCharacter, updateStateMsg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - - } - - // update cast (use skill) fail condition - playerCharacter.cancelOnCast(); - - // update castSpell (use spell) fail condition if spell - if (pb.isSpell()) - playerCharacter.cancelOnSpell(); - - // get cast time in ms. - time = pb.getCastTime(trains); - - // set player is casting for regens - - - if (time > 100){ - playerCharacter.update(); - playerCharacter.setIsCasting(true); - } - - - playerCharacter.setLastMovementState(playerCharacter.getMovementState()); - // update used power timer - playerCharacter.setLastUsedPowerTime(); - - // run timer job to end cast - if (time < 1) // run immediately - finishUsePower(copyMsg, playerCharacter, casterLiveCounter, targetLiveCounter); - else { - UsePowerJob upj = new UsePowerJob(playerCharacter, copyMsg, copyMsg.getPowerUsedID(), pb, casterLiveCounter, targetLiveCounter); - JobContainer jc = js.scheduleJob(upj, time); - - // make lastPower - playerCharacter.setLastPower(jc); - } - - if (CSRCast) - Logger.info("CSR " + playerCharacter.getName() + " cast power " + msg.getPowerUsedID() + '.'); - - return false; - } - - public static void testPowers(ByteBufferWriter writer) { - writer.putInt(powersBaseByToken.size()); - for (int token : powersBaseByToken.keySet()) { - writer.putInt(token); - writer.putInt(40); - } - } - - public static boolean useMobPowerA(PerformActionMsg msg, Mob caster) { - if (caster == null) - return false; - - - if (!caster.isAlive() && msg.getPowerUsedID() != 428589216) //succor - return false; - - // get power - PowersBase pb = PowersManager.powersBaseByToken.get(msg.getPowerUsedID()); - if (pb == null) - return true; - - // Check powers for normal users - // get numTrains for power - int trains = msg.getNumTrains(); - - // can't go over the max trains for the power, unless CSR - // can't go over total trains by player - // get recycle time in ms - int time = pb.getRecycleTime(trains); - - // verify player is in correct mode (combat/nonCombat) - // verify player is not stunned or prohibited from casting - PlayerBonuses bonus = caster.getBonuses(); - SourceType sourceType = SourceType.GetSourceType(pb.getCategory()); - if (bonus != null && (bonus.getBool(ModType.Stunned, SourceType.None) || bonus.getBool(ModType.CannotCast, SourceType.None) || bonus.getBool(ModType.BlockedPowerType, sourceType))) - return true; - - // if moving make sure spell valid for movement - // if flying, make sure spell valid for flying. - // if (pc.getAltitude() > 0) - // if (!pb.canCastWhileFlying()) - // return true; - int targetLiveCounter = -1; - - // get target based on targetType; - if (pb.targetFromLastTarget() || pb.targetPet()) // use msg's target - if (pb.isAOE()) { - if (!pb.usePointBlank()) { - AbstractWorldObject target = getTarget(msg); - - - if (target == null) { - - if (caster.getLoc().distanceSquared2D(msg.getTargetLoc()) > sqr(pb - .getRange())) - return true; - } else if (verifyInvalidRange(caster, target, pb.getRange())) - // pc.getLoc().distance(target.getLoc()) > - // pb.getRange()) - return true; - } - } else { - // get target - AbstractWorldObject target = getTarget(msg); - - if (target == null) - return true; - - // verify target is in range - if (verifyInvalidRange(caster, target, pb.getRange())) - // (pc.getLoc().distance(target.getLoc()) > pb.getRange()) { - // TODO send message that target is out of range - return true; - - // verify target is valid type - if (AbstractWorldObject.IsAbstractCharacter(target)) - targetLiveCounter = ((AbstractCharacter) target).getLiveCounter(); - } - - // TODO if target immune to powers, cancel unless aoe - // Also make sure No.ImmuneToPowers is false for target - // if there's a different power waiting to finish, stop here - if (caster.getLastMobPowerToken() != 0) - return true; - - //get power cost and calculate any power cost modifiers - // Validity checks passed, move on to casting spell - //get caster's live counter - int casterLiveCounter = caster.getLiveCounter(); - - // run recycle job for when cast is available again, don't bother adding the timer for CSRs - // Send cast to other players - if (caster.getObjectTypeMask() == MBServerStatics.MASK_UNDEAD) - msg.setUnknown05(0); // Regular Race, use mana? - else - msg.setUnknown05(0); - - int tr = msg.getNumTrains(); - - msg.setNumTrains(9999); - - DispatchMessage.sendToAllInRange(caster, msg); - DispatchMessage.sendToAllInRange(caster, msg); - - msg.setNumTrains(tr); - - // make person casting stand up if spell (unless they're casting a chant which does not make them stand up) - // update cast (use skill) fail condition - caster.cancelOnCast(); - - // update castSpell (use spell) fail condition if spell - if (pb.isSpell()) - caster.cancelOnSpell(); - - // get cast time in ms. - time = pb.getCastTime(trains); - - // set player is casting for regens - caster.setIsCasting(true); - caster.setLastMobPowerToken(pb.getToken()); - - // run timer job to end cast - if (time < 1 || pb.getToken() == -1994153779){ - // run immediately - finishUseMobPower(msg, caster, casterLiveCounter, targetLiveCounter); - caster.setLastMobPowerToken(0); - } - - else { - caster.setLastMobPowerToken(pb.getToken()); - caster.setTimeStamp("FinishCast", System.currentTimeMillis() + (pb.getCastTime(trains))); - } - // finishUseMobPower(msg, caster, casterLiveCounter, targetLiveCounter); // UseMobPowerJob upj = new UseMobPowerJob(caster, msg, msg.getPowerUsedID(), pb, casterLiveCounter, targetLiveCounter); - // JobContainer jc = js.scheduleJob(upj, time); - // // make lastPower - - - return false; - } - - // called when a spell finishes casting. perform actions - public static void finishUsePower(final PerformActionMsg msg, PlayerCharacter playerCharacter, int casterLiveCounter, int targetLiveCounter) { - - PerformActionMsg performActionMsg; - Dispatch dispatch; - - if (playerCharacter == null || msg == null) - return; - - if (playerCharacter.isCasting()){ - playerCharacter.update(); - playerCharacter.updateStamRegen(-100); - } - - playerCharacter.resetLastSetLocUpdate(); - playerCharacter.setIsCasting(false); - // can't go over total trains by player + int tr = msg.getNumTrains(); + DispatchMessage.dispatchMsgToInterestArea(playerCharacter, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, sendCastToSelf, false); + //Make new msg.. + PerformActionMsg copyMsg = new PerformActionMsg(msg); + copyMsg.setNumTrains(tr); - if (!playerCharacter.isAlive() || playerCharacter.getLiveCounter() != casterLiveCounter) { - playerCharacter.clearLastPower(); - finishRecycleTime(msg.getPowerUsedID(), playerCharacter, true); + // make person casting stand up if spell (unless they're casting a chant which does not make them stand up) + if (pb.isSpell() && !pb.isChant() && playerCharacter.isSit()) { + playerCharacter.update(); + playerCharacter.setSit(false); + UpdateStateMsg updateStateMsg = new UpdateStateMsg(playerCharacter); + DispatchMessage.dispatchMsgToInterestArea(playerCharacter, updateStateMsg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + } - // Let's do good OO. Clone message don't modify it. + // update cast (use skill) fail condition + playerCharacter.cancelOnCast(); - performActionMsg = new PerformActionMsg(msg); - performActionMsg.setNumTrains(9999); - performActionMsg.setUnknown04(2); + // update castSpell (use spell) fail condition if spell + if (pb.isSpell()) + playerCharacter.cancelOnSpell(); - dispatch = Dispatch.borrow(playerCharacter, performActionMsg); - DispatchMessage.dispatchMsgToInterestArea(playerCharacter, performActionMsg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - return; - } + // get cast time in ms. + time = pb.getCastTime(trains); - // set player is not casting for regens + // set player is casting for regens - // clear power. - playerCharacter.clearLastPower(); + if (time > 100) { + playerCharacter.update(); + playerCharacter.setIsCasting(true); + } - PowersBase pb = PowersManager.powersBaseByToken.get(msg.getPowerUsedID()); - if (pb == null) { - Logger.error( - "finishUsePower(): Power '" + msg.getPowerUsedID() - + "' was not found on powersBaseByToken map."); - return; - } + playerCharacter.setLastMovementState(playerCharacter.getMovementState()); + // update used power timer + playerCharacter.setLastUsedPowerTime(); - int trains = msg.getNumTrains(); + // run timer job to end cast + if (time < 1) // run immediately + finishUsePower(copyMsg, playerCharacter, casterLiveCounter, targetLiveCounter); + else { + UsePowerJob upj = new UsePowerJob(playerCharacter, copyMsg, copyMsg.getPowerUsedID(), pb, casterLiveCounter, targetLiveCounter); + JobContainer jc = js.scheduleJob(upj, time); - // update used power timer - playerCharacter.setLastUsedPowerTime(); + // make lastPower + playerCharacter.setLastPower(jc); + } - // verify player is not stunned or power type is blocked - PlayerBonuses bonus = playerCharacter.getBonuses(); + if (CSRCast) + Logger.info("CSR " + playerCharacter.getName() + " cast power " + msg.getPowerUsedID() + '.'); - if (bonus != null) { - if (bonus.getBool(ModType.Stunned, SourceType.None)) - return; - - SourceType sourceType = SourceType.GetSourceType(pb.getCategory()); - if (bonus.getBool(ModType.BlockedPowerType, sourceType)) { - finishRecycleTime(msg.getPowerUsedID(), playerCharacter, true); - return; - } - } + return false; + } - // get target loc - Vector3fImmutable targetLoc = msg.getTargetLoc(); + public static void testPowers(ByteBufferWriter writer) { + writer.putInt(powersBaseByToken.size()); + for (int token : powersBaseByToken.keySet()) { + writer.putInt(token); + writer.putInt(40); + } + } + + public static boolean useMobPowerA(PerformActionMsg msg, Mob caster) { + if (caster == null) + return false; + + + if (!caster.isAlive() && msg.getPowerUsedID() != 428589216) //succor + return false; + + // get power + PowersBase pb = PowersManager.powersBaseByToken.get(msg.getPowerUsedID()); + if (pb == null) + return true; + + // Check powers for normal users + // get numTrains for power + int trains = msg.getNumTrains(); + + // can't go over the max trains for the power, unless CSR + // can't go over total trains by player + // get recycle time in ms + int time = pb.getRecycleTime(trains); + + // verify player is in correct mode (combat/nonCombat) + // verify player is not stunned or prohibited from casting + PlayerBonuses bonus = caster.getBonuses(); + SourceType sourceType = SourceType.GetSourceType(pb.getCategory()); + if (bonus != null && (bonus.getBool(ModType.Stunned, SourceType.None) || bonus.getBool(ModType.CannotCast, SourceType.None) || bonus.getBool(ModType.BlockedPowerType, sourceType))) + return true; + + // if moving make sure spell valid for movement + // if flying, make sure spell valid for flying. + // if (pc.getAltitude() > 0) + // if (!pb.canCastWhileFlying()) + // return true; + int targetLiveCounter = -1; + + // get target based on targetType; + if (pb.targetFromLastTarget() || pb.targetPet()) // use msg's target + if (pb.isAOE()) { + if (!pb.usePointBlank()) { + AbstractWorldObject target = getTarget(msg); + + + if (target == null) { + + if (caster.getLoc().distanceSquared2D(msg.getTargetLoc()) > sqr(pb + .getRange())) + return true; + } else if (verifyInvalidRange(caster, target, pb.getRange())) + // pc.getLoc().distance(target.getLoc()) > + // pb.getRange()) + return true; + } + } else { + // get target + AbstractWorldObject target = getTarget(msg); + + if (target == null) + return true; + + // verify target is in range + if (verifyInvalidRange(caster, target, pb.getRange())) + // (pc.getLoc().distance(target.getLoc()) > pb.getRange()) { + // TODO send message that target is out of range + return true; + + // verify target is valid type + if (AbstractWorldObject.IsAbstractCharacter(target)) + targetLiveCounter = ((AbstractCharacter) target).getLiveCounter(); + } + + // TODO if target immune to powers, cancel unless aoe + // Also make sure No.ImmuneToPowers is false for target + // if there's a different power waiting to finish, stop here + if (caster.getLastMobPowerToken() != 0) + return true; + + //get power cost and calculate any power cost modifiers + // Validity checks passed, move on to casting spell + //get caster's live counter + int casterLiveCounter = caster.getLiveCounter(); + // run recycle job for when cast is available again, don't bother adding the timer for CSRs + // Send cast to other players + if (caster.getObjectTypeMask() == MBServerStatics.MASK_UNDEAD) + msg.setUnknown05(0); // Regular Race, use mana? + else + msg.setUnknown05(0); - if (pb.targetFromLastTarget() || pb.targetPet()) // use msg's target - if (pb.isAOE()) { - if (!pb.usePointBlank()) { - AbstractWorldObject mainTarget = getTarget(msg); + int tr = msg.getNumTrains(); - float speedRange = 0; - if (AbstractWorldObject.IsAbstractCharacter(mainTarget)) { - speedRange = ((AbstractCharacter) mainTarget).getSpeed() * (pb.getCastTime(trains) * .001f); - } + msg.setNumTrains(9999); - if (mainTarget != null && mainTarget.getObjectType() == GameObjectType.Building && !pb.targetBuilding()) { - PowersManager.sendPowerMsg(playerCharacter, 8, new PerformActionMsg(msg)); - return; - } + DispatchMessage.sendToAllInRange(caster, msg); + DispatchMessage.sendToAllInRange(caster, msg); - if (mainTarget == null) { + msg.setNumTrains(tr); - if (playerCharacter.getLoc().distanceSquared2D(msg.getTargetLoc()) > sqr(pb - .getRange())) { - sendPowerMsg(playerCharacter, 8, msg); - return; - } - } else if (verifyInvalidRange(playerCharacter, mainTarget, speedRange + pb.getRange())) { + // make person casting stand up if spell (unless they're casting a chant which does not make them stand up) + // update cast (use skill) fail condition + caster.cancelOnCast(); - sendPowerMsg(playerCharacter, 8, msg); - return; - } - } - } else { + // update castSpell (use spell) fail condition if spell + if (pb.isSpell()) + caster.cancelOnSpell(); - // get target - AbstractWorldObject mainTarget = getTarget(msg); + // get cast time in ms. + time = pb.getCastTime(trains); - if (mainTarget == null) - return; + // set player is casting for regens + caster.setIsCasting(true); + caster.setLastMobPowerToken(pb.getToken()); + + // run timer job to end cast + if (time < 1 || pb.getToken() == -1994153779) { + // run immediately + finishUseMobPower(msg, caster, casterLiveCounter, targetLiveCounter); + caster.setLastMobPowerToken(0); + } else { + caster.setLastMobPowerToken(pb.getToken()); + caster.setTimeStamp("FinishCast", System.currentTimeMillis() + (pb.getCastTime(trains))); + } + // finishUseMobPower(msg, caster, casterLiveCounter, targetLiveCounter); // UseMobPowerJob upj = new UseMobPowerJob(caster, msg, msg.getPowerUsedID(), pb, casterLiveCounter, targetLiveCounter); + // JobContainer jc = js.scheduleJob(upj, time); + // // make lastPower - float speedRange = 0; - if (AbstractWorldObject.IsAbstractCharacter(mainTarget)) { - speedRange = ((AbstractCharacter) mainTarget).getSpeed() * (pb.getCastTime(trains) * .001f); - } - float range = pb.getRange() + speedRange; - + return false; + } - if (verifyInvalidRange(playerCharacter, mainTarget, range)) { + // called when a spell finishes casting. perform actions + public static void finishUsePower(final PerformActionMsg msg, PlayerCharacter playerCharacter, int casterLiveCounter, int targetLiveCounter) { - sendPowerMsg(playerCharacter, 8, msg); - return; - } - // (pc.getLoc().distance(target.getLoc()) > pb.getRange()) { - // TODO send message that target is out of range + PerformActionMsg performActionMsg; + Dispatch dispatch; + if (playerCharacter == null || msg == null) + return; - } + if (playerCharacter.isCasting()) { + playerCharacter.update(); + playerCharacter.updateStamRegen(-100); + } - if (targetLoc.x == 0f || targetLoc.z == 0f) { - AbstractWorldObject tar = getTarget(msg); - if (tar != null) - targetLoc = tar.getLoc(); - } + playerCharacter.resetLastSetLocUpdate(); + playerCharacter.setIsCasting(false); + // can't go over total trains by player - // get list of targets - HashSet allTargets = getAllTargets( - getTarget(msg), msg.getTargetLoc(), playerCharacter, pb); + if (!playerCharacter.isAlive() || playerCharacter.getLiveCounter() != casterLiveCounter) { + playerCharacter.clearLastPower(); + finishRecycleTime(msg.getPowerUsedID(), playerCharacter, true); + + + // Let's do good OO. Clone message don't modify it. + + performActionMsg = new PerformActionMsg(msg); + performActionMsg.setNumTrains(9999); + performActionMsg.setUnknown04(2); + + dispatch = Dispatch.borrow(playerCharacter, performActionMsg); + DispatchMessage.dispatchMsgToInterestArea(playerCharacter, performActionMsg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + return; + } + + // set player is not casting for regens + + + // clear power. + playerCharacter.clearLastPower(); + + PowersBase pb = PowersManager.powersBaseByToken.get(msg.getPowerUsedID()); + + if (pb == null) { + Logger.error( + "finishUsePower(): Power '" + msg.getPowerUsedID() + + "' was not found on powersBaseByToken map."); + return; + } + + int trains = msg.getNumTrains(); - // no targets found. send error message + // update used power timer + playerCharacter.setLastUsedPowerTime(); - if (allTargets.size() == 0) { - sendPowerMsg(playerCharacter, 9, msg); - return; - } + // verify player is not stunned or power type is blocked + PlayerBonuses bonus = playerCharacter.getBonuses(); - playerCharacter.setHateValue(pb.getHateValue(trains)); + if (bonus != null) { + if (bonus.getBool(ModType.Stunned, SourceType.None)) + return; - //Send Cast Message. + SourceType sourceType = SourceType.GetSourceType(pb.getCategory()); + if (bonus.getBool(ModType.BlockedPowerType, sourceType)) { + finishRecycleTime(msg.getPowerUsedID(), playerCharacter, true); + return; + } + } + + // get target loc + Vector3fImmutable targetLoc = msg.getTargetLoc(); + + + if (pb.targetFromLastTarget() || pb.targetPet()) // use msg's target + if (pb.isAOE()) { + if (!pb.usePointBlank()) { + AbstractWorldObject mainTarget = getTarget(msg); + + float speedRange = 0; + if (AbstractWorldObject.IsAbstractCharacter(mainTarget)) { + speedRange = ((AbstractCharacter) mainTarget).getSpeed() * (pb.getCastTime(trains) * .001f); + } + + if (mainTarget != null && mainTarget.getObjectType() == GameObjectType.Building && !pb.targetBuilding()) { + PowersManager.sendPowerMsg(playerCharacter, 8, new PerformActionMsg(msg)); + return; + } + + if (mainTarget == null) { + + if (playerCharacter.getLoc().distanceSquared2D(msg.getTargetLoc()) > sqr(pb + .getRange())) { + sendPowerMsg(playerCharacter, 8, msg); + return; + } + } else if (verifyInvalidRange(playerCharacter, mainTarget, speedRange + pb.getRange())) { + + sendPowerMsg(playerCharacter, 8, msg); + return; + } + } + } else { + + // get target + AbstractWorldObject mainTarget = getTarget(msg); + + if (mainTarget == null) + return; + + float speedRange = 0; + if (AbstractWorldObject.IsAbstractCharacter(mainTarget)) { + speedRange = ((AbstractCharacter) mainTarget).getSpeed() * (pb.getCastTime(trains) * .001f); + } + float range = pb.getRange() + speedRange; + + + if (verifyInvalidRange(playerCharacter, mainTarget, range)) { + + sendPowerMsg(playerCharacter, 8, msg); + return; + } + // (pc.getLoc().distance(target.getLoc()) > pb.getRange()) { + // TODO send message that target is out of range + + + } + + if (targetLoc.x == 0f || targetLoc.z == 0f) { + AbstractWorldObject tar = getTarget(msg); + if (tar != null) + targetLoc = tar.getLoc(); + } + + + // get list of targets + HashSet allTargets = getAllTargets( + getTarget(msg), msg.getTargetLoc(), playerCharacter, pb); + + // no targets found. send error message + + if (allTargets.size() == 0) { + sendPowerMsg(playerCharacter, 9, msg); + return; + } + + playerCharacter.setHateValue(pb.getHateValue(trains)); + + //Send Cast Message. // PerformActionMsg castMsg = new PerformActionMsg(msg); // castMsg.setNumTrains(9999); // castMsg.setUnknown04(3); // DispatchMessage.dispatchMsgToInterestArea(playerCharacter, castMsg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); // - boolean msgCasted = false; - - for (AbstractWorldObject target : allTargets) { - - if (target == null) - continue; - - //Hacky Pyschic healing cross heal - - //make sure target hasn't respawned since we began casting - //skip this if liveCounter = -1 (from aoe) - - if (targetLiveCounter != -1) - if (AbstractWorldObject.IsAbstractCharacter(target)) - if (targetLiveCounter != ((AbstractCharacter) target).getLiveCounter()) - continue; - - if (!target.isAlive() && target.getObjectType() != GameObjectType.Building && pb.getToken() != 428589216 && pb.getToken() != 429425915) - continue; - - //make sure mob is awake to respond. - //if (target instanceof AbstractIntelligenceAgent) - //((AbstractIntelligenceAgent)target).enableIntelligence(); - // If Hit roll required, test hit - - boolean miss = false; - if (pb.requiresHitRoll() && !pb.isWeaponPower() && testAttack(playerCharacter, target, pb, msg)) { - miss = true; - //aggro mob even on a miss - if (target.getObjectType() == GameObjectType.Mob) { - Mob mobTarget = (Mob) target; - if (pb.isHarmful()) - mobTarget.handleDirectAggro(playerCharacter); - } - continue; - } - if (target.getObjectType() == GameObjectType.Mob) { - Mob mobTarget = (Mob) target; - if (pb.isHarmful()) - mobTarget.handleDirectAggro(playerCharacter); - } - //Power is aiding a target, handle aggro if combat target is a Mob. - if (!pb.isHarmful() && target.getObjectType() == GameObjectType.PlayerCharacter) { - PlayerCharacter pcTarget = (PlayerCharacter) target; - if (!pb.isHarmful()) - Mob.HandleAssistedAggro(playerCharacter, pcTarget); - } - - // update target of used power timer - - if (pb.isHarmful()) - if (target.getObjectType().equals(GameObjectType.PlayerCharacter) && target.getObjectUUID() != playerCharacter.getObjectUUID()) { - - ((PlayerCharacter) target).setLastTargetOfUsedPowerTime(); - ((PlayerCharacter) target).setTimeStamp("LastCombatPlayer", System.currentTimeMillis()); - playerCharacter.setTimeStamp("LastCombatPlayer", System.currentTimeMillis()); - } - - - //Player didn't miss power, send finish cast. Miss cast already sent. - - - // finally Apply actions - for (ActionsBase ab : pb.getActions()) { - // get numTrains for power, skip action if invalid - - if (trains < ab.getMinTrains() || trains > ab.getMaxTrains()) - continue; - // If something blocks the action, then stop - - if (ab.blocked(target, pb, trains)) { - - PowersManager.sendEffectMsg(playerCharacter, 5, ab, pb); - continue; - } - - // TODO handle overwrite stack order here - String stackType = ab.getStackType(); - stackType = (stackType.equals("IgnoreStack")) ? Integer.toString(ab.getUUID()) : stackType; - // if (!stackType.equals("IgnoreStack")) { - if (target.getEffects().containsKey(stackType)) { - // remove any existing power that overrides - Effect ef = target.getEffects().get(stackType); - AbstractEffectJob effect = null; - if (ef != null) { - JobContainer jc = ef.getJobContainer(); - if (jc != null) - effect = (AbstractEffectJob) jc.getJob(); - } - ActionsBase overwrite = effect.getAction(); - - if (overwrite == null) { - Logger.error("NULL ACTION FOR POWER " + effect.getPowerToken()); - continue; - } - - if (ab.getStackOrder() < overwrite.getStackOrder()) - continue; // not high enough to overwrite - else if (ab.getStackOrder() > overwrite.getStackOrder()) { - effect.setNoOverwrite(true); - removeEffect(target, overwrite, true, false); - } else if (ab.getStackOrder() == overwrite.getStackOrder()) - if (ab.greaterThanEqual() - && (trains >= effect.getTrains())) { - effect.setNoOverwrite(true); - removeEffect(target, overwrite, true, false); - } - - else if (ab.always()) - removeEffect(target, overwrite, true, false); - else if (ab.greaterThan() - && (trains > effect.getTrains())) { - effect.setNoOverwrite(true); - removeEffect(target, overwrite, true, false); - } else if (ab.greaterThan() && pb.getToken() == effect.getPowerToken()) - removeEffect(target, overwrite, true, false); - - else - continue; // trains not high enough to overwrite - - } - - // } - - - runPowerAction(playerCharacter, target, targetLoc, ab, trains, pb); - if (!miss && !msgCasted){ - PerformActionMsg castMsg = new PerformActionMsg(msg); - castMsg.setNumTrains(9999); - castMsg.setUnknown04(2); - DispatchMessage.dispatchMsgToInterestArea(playerCharacter, castMsg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - msgCasted = true; - } - } - } - - if ( !msgCasted){ - PerformActionMsg castMsg = new PerformActionMsg(msg); - castMsg.setNumTrains(9999); - castMsg.setUnknown04(2); - DispatchMessage.dispatchMsgToInterestArea(playerCharacter, castMsg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - msgCasted = true; - } - - //Handle chant - if (pb != null && pb.isChant()) - for (ActionsBase ab : pb.getActions()) { - AbstractPowerAction pa = ab.getPowerAction(); - if (pa != null) - if (pb.getToken() != 428950414 && pb.getToken() != 428884878) - pa.handleChant(playerCharacter, playerCharacter, targetLoc, trains, ab, pb); - else if (PowersManager.getTarget(msg) != null && PowersManager.getTarget(msg).isAlive()) - pa.handleChant(playerCharacter, PowersManager.getTarget(msg), targetLoc, trains, ab, pb); - else - pa.handleChant(playerCharacter, null, targetLoc, trains, ab, pb); - } - - - - - - //DispatchMessage.dispatchMsgToInterestArea(playerCharacter, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - - - } - - public static void finishUseMobPower(PerformActionMsg msg, Mob caster, int casterLiveCounter, int targetLiveCounter) { - - if (caster == null || msg == null) - return; - - if (!caster.isAlive() || caster.getLiveCounter() != casterLiveCounter) - return; - - // set player is not casting for regens - caster.setIsCasting(false); - - - PowersBase pb = PowersManager.powersBaseByToken.get(msg.getPowerUsedID()); - // clear power. - caster.setLastMobPowerToken(0); - - if (pb == null) { - Logger.error( - "finishUsePower(): Power '" + msg.getPowerUsedID() - + "' was not found on powersBaseByToken map."); - return; - } - - int trains = msg.getNumTrains(); - - // update used power timer - // verify player is not stunned or power type is blocked - PlayerBonuses bonus = caster.getBonuses(); - if (bonus != null) { - if (bonus.getBool(ModType.Stunned,SourceType.None)) - return; - SourceType sourceType = SourceType.GetSourceType(pb.getCategory()); - if (bonus.getBool(ModType.BlockedPowerType, sourceType)) - return; - } - - msg.setNumTrains(9999); - msg.setUnknown04(2); - DispatchMessage.sendToAllInRange(caster, msg); - - // get target loc - Vector3fImmutable targetLoc = msg.getTargetLoc(); - if (targetLoc.x == 0f || targetLoc.z == 0f) { - AbstractWorldObject tar = getTarget(msg); - if (tar != null) - targetLoc = tar.getLoc(); - } - - // get list of targets - HashSet allTargets = getAllTargets( - getTarget(msg), msg.getTargetLoc(), caster, pb); - for (AbstractWorldObject target : allTargets) { - - if (target == null) - continue; - - - //make sure target hasn't respawned since we began casting - //skip this if liveCounter = -1 (from aoe) - if (targetLiveCounter != -1) - if (AbstractWorldObject.IsAbstractCharacter(target)) - if (targetLiveCounter != ((AbstractCharacter) target).getLiveCounter()) - continue; - - //make sure mob is awake to respond. - //if (target instanceof AbstractIntelligenceAgent) - //((AbstractIntelligenceAgent)target).enableIntelligence(); - // If Hit roll required, test hit - if (pb.requiresHitRoll() && !pb.isWeaponPower() && testAttack(caster, target, pb, msg)) - //aggro mob even on a miss - continue; - - // update target of used power timer - - if (target.getObjectType().equals(GameObjectType.PlayerCharacter)) { - - ((PlayerCharacter) target).setLastTargetOfUsedPowerTime(); - ((PlayerCharacter) target).setTimeStamp("LastCombatPlayer", System.currentTimeMillis()); - } - - - // finally Apply actions - for (ActionsBase ab : pb.getActions()) { - // get numTrains for power, skip action if invalid - - if (trains < ab.getMinTrains() || trains > ab.getMaxTrains()) - continue; - // If something blocks the action, then stop - - if (ab.blocked(target, pb, trains)) - continue; - // TODO handle overwrite stack order here - String stackType = ab.getStackType(); - stackType = (stackType.equals("IgnoreStack")) ? Integer.toString(ab.getUUID()) : stackType; - // if (!stackType.equals("IgnoreStack")) { - if (target.getEffects().containsKey(stackType)) { - // remove any existing power that overrides - Effect ef = target.getEffects().get(stackType); - AbstractEffectJob effect = null; - if (ef != null) { - JobContainer jc = ef.getJobContainer(); - if (jc != null) - effect = (AbstractEffectJob) jc.getJob(); - } - ActionsBase overwrite = effect.getAction(); - - if (overwrite == null){ - Logger.error("NULL ACTION FOR EFFECT " + effect.getPowerToken()); - continue; - } - if (ab.getStackOrder() < overwrite.getStackOrder()) - continue; // not high enough to overwrite - else if (ab.getStackOrder() > overwrite.getStackOrder()) { - effect.setNoOverwrite(true); - removeEffect(target, overwrite, true, false); - } else if (ab.getStackOrder() == overwrite.getStackOrder()) - if (ab.greaterThanEqual() - && (trains >= effect.getTrains())) { - effect.setNoOverwrite(true); - removeEffect(target, overwrite, true, false); - } else if (ab.always()) - removeEffect(target, overwrite, true, false); - else if (ab.greaterThan() - && (trains > effect.getTrains())) { - effect.setNoOverwrite(true); - removeEffect(target, overwrite, true, false); - } else if (ab.greaterThan() && pb.getToken() == effect.getPowerToken()) - removeEffect(target, overwrite, true, false); - - else - continue; // trains not high enough to overwrite - } - - // } - runPowerAction(caster, target, targetLoc, ab, trains, pb); - } - } - - //Handle chant - if (pb != null && pb.isChant()) - for (ActionsBase ab : pb.getActions()) { - AbstractPowerAction pa = ab.getPowerAction(); - if (pa != null) - pa.handleChant(caster, caster, targetLoc, trains, ab, pb); - } - - // TODO echo power use to everyone else - msg.setNumTrains(9999); - msg.setUnknown04(2); - DispatchMessage.sendToAllInRange(caster, msg); - - } - - // *** Refactor : Wtf is this mess? - - private static boolean validMonsterType(AbstractWorldObject target, PowersBase pb) { - - if (pb == null || target == null) - return false; - - String mtp = pb.getMonsterTypePrereq(); - - if (mtp.length() == 0) - return true; - - if (target.getObjectType().equals(GameObjectType.PlayerCharacter)) { - - PlayerCharacter pc = (PlayerCharacter) target; - int raceID = 0; - - if (pc.getRace() != null) - raceID = pc.getRace().getRaceRuneID(); - - switch (mtp) { - case "Shade": - return raceID == 2015 || raceID == 2016; - case "Elf": - return raceID == 2008 || raceID == 2009; - case "Dwarf": - return raceID == 2006; - case "Aracoix": - return raceID == 2002 || raceID == 2003; - case "Irekei": - return raceID == 2013 || raceID == 2014; - case "Vampire": - return raceID == 2028 || raceID == 2029; - } - } else if (target.getObjectType().equals(GameObjectType.Mob)) { - Mob mob = (Mob) target; - - if (pb.targetMob() && !mob.isMob() && !mob.isSiege()) - return false; - else if (pb.targetPet() && !mob.isPet() && !mob.isSiege()) - return false; - - switch (mtp) { - case "Animal": - if ((mob.getObjectTypeMask() & MBServerStatics.MASK_BEAST) == 0) - return false; - break; - case "NPC": - if ((mob.getObjectTypeMask() & MBServerStatics.MASK_HUMANOID) == 0) - return false; - break; - case "Rat": - if ((mob.getObjectTypeMask() & MBServerStatics.MASK_RAT) == 0) - return false; - break; - case "Siege": - if (!mob.isSiege()) - return false; - break; - case "Undead": - if ((mob.getObjectTypeMask() & MBServerStatics.MASK_UNDEAD) == 0) - return false; - break; - } - return true; - } else return target.getObjectType().equals(GameObjectType.Building) && mtp.equals("Siege"); - return false; - } - - public static void summon(SendSummonsRequestMsg msg, ClientConnection origin) { - PlayerCharacter pc = SessionManager.getPlayerCharacter( - origin); - if (pc == null) - return; - - PlayerCharacter target = SessionManager - .getPlayerCharacterByLowerCaseName(msg.getTargetName()); - if (target == null || target.equals(pc) || target.isCombat()) { - - if (target == null) // Player not found. Send not found message - ChatManager.chatInfoError(pc, - "Cannot find that player to summon."); - else if (target.isCombat()) - ChatManager.chatInfoError(pc, - "Cannot summon player in combat."); - // else trying to summon self, just fail - - // recycle summon - sendRecyclePower(msg.getPowerToken(), origin); - - // TODO: client already subtracted 200 mana.. need to correct it - // end cast - PerformActionMsg pam = new PerformActionMsg(msg.getPowerToken(), - msg.getTrains(), msg.getSourceType(), msg.getSourceID(), 0, - 0, 0f, 0f, 0f, 1, 0); - sendPowerMsg(pc, 2, pam); - - return; - } - - PerformActionMsg pam = new PerformActionMsg(msg.getPowerToken(), msg - .getTrains(), msg.getSourceType(), msg.getSourceID(), target - .getObjectType().ordinal(), target.getObjectUUID(), 0f, 0f, 0f, 1, 0); - - // Client removes 200 mana on summon use.. so don't send message to self - target.addSummoner(pc.getObjectUUID(), System.currentTimeMillis() + MBServerStatics.FOURTYFIVE_SECONDS); - usePower(pam, origin, false); - } - - public static void recvSummon(RecvSummonsRequestMsg msg, ClientConnection origin) { - PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); - if (pc == null) - return; - - PlayerCharacter source = PlayerCharacter.getFromCache(msg.getSourceID()); - if (source == null) - return; - - long tooLate = pc.getSummoner(source.getObjectUUID()); - if (tooLate < System.currentTimeMillis()) { - ChatManager.chatInfoError(pc, "You waited too long to " + (msg.accepted() ? "accept" : "decline") + " the summons."); - pc.removeSummoner(source.getObjectUUID()); - return; - } - - if (pc.getBonuses() != null && pc.getBonuses().getBool(ModType.BlockedPowerType, SourceType.SUMMON)) { - ErrorPopupMsg.sendErrorMsg(pc, "You have been blocked from receiving summons!"); - ErrorPopupMsg.sendErrorMsg(source, "Target is blocked from receiving summons!"); - pc.removeSummoner(source.getObjectUUID()); - return; - } - pc.removeSummoner(source.getObjectUUID()); - - // Handle Accepting or Denying a summons. - // set timer based on summon type. - boolean wentThrough = false; - if (msg.accepted()) - // summons accepted, let's move the player if within time - if (source.isAlive()) { - - // //make sure summons handled in time - ConcurrentHashMap timers = source.getTimers(); - // if (timers == null || !timers.containsKey("SummonSend")) { - // ChatManager.chatInfoError(pc, "You waited too long to " + (msg.accepted() ? "accept" : "decline") + " the summons."); - // return; - // } - - // // clear last summons accept timer - // timers.get("SummonSend").cancelJob(); - //timers.remove("SummonSend"); - // cancel any other summons waiting - timers = pc.getTimers(); - if (timers != null && timers.containsKey("Summon")) - timers.get("Summon").cancelJob(); - - // get time to wait before summons goes through - BaseClass base = source.getBaseClass(); - PromotionClass promo = source.getPromotionClass(); - int duration; - - - //determine if in combat with another player - - - //comment out this block to disable combat timer - // if (lastAttacked < 60000) { - // if (pc.inSafeZone()) //player in safe zone, no need for combat timer - // combat = false; - // else if (source.inSafeZone()) //summoner in safe zone, apply combat timer - // combat = true; - // else if ((source.getLoc().distance2D(pc.getLoc())) > 6144f) - // combat = true; //more than 1.5x width of zone, not tactical summons - // } + boolean msgCasted = false; + + for (AbstractWorldObject target : allTargets) { + + if (target == null) + continue; + + //Hacky Pyschic healing cross heal + + //make sure target hasn't respawned since we began casting + //skip this if liveCounter = -1 (from aoe) + + if (targetLiveCounter != -1) + if (AbstractWorldObject.IsAbstractCharacter(target)) + if (targetLiveCounter != ((AbstractCharacter) target).getLiveCounter()) + continue; + + if (!target.isAlive() && target.getObjectType() != GameObjectType.Building && pb.getToken() != 428589216 && pb.getToken() != 429425915) + continue; + + //make sure mob is awake to respond. + //if (target instanceof AbstractIntelligenceAgent) + //((AbstractIntelligenceAgent)target).enableIntelligence(); + // If Hit roll required, test hit + + boolean miss = false; + if (pb.requiresHitRoll() && !pb.isWeaponPower() && testAttack(playerCharacter, target, pb, msg)) { + miss = true; + //aggro mob even on a miss + if (target.getObjectType() == GameObjectType.Mob) { + Mob mobTarget = (Mob) target; + if (pb.isHarmful()) + mobTarget.handleDirectAggro(playerCharacter); + } + continue; + } + if (target.getObjectType() == GameObjectType.Mob) { + Mob mobTarget = (Mob) target; + if (pb.isHarmful()) + mobTarget.handleDirectAggro(playerCharacter); + } + //Power is aiding a target, handle aggro if combat target is a Mob. + if (!pb.isHarmful() && target.getObjectType() == GameObjectType.PlayerCharacter) { + PlayerCharacter pcTarget = (PlayerCharacter) target; + if (!pb.isHarmful()) + Mob.HandleAssistedAggro(playerCharacter, pcTarget); + } + + // update target of used power timer + + if (pb.isHarmful()) + if (target.getObjectType().equals(GameObjectType.PlayerCharacter) && target.getObjectUUID() != playerCharacter.getObjectUUID()) { + + ((PlayerCharacter) target).setLastTargetOfUsedPowerTime(); + ((PlayerCharacter) target).setTimeStamp("LastCombatPlayer", System.currentTimeMillis()); + playerCharacter.setTimeStamp("LastCombatPlayer", System.currentTimeMillis()); + } + + + //Player didn't miss power, send finish cast. Miss cast already sent. + + + // finally Apply actions + for (ActionsBase ab : pb.getActions()) { + // get numTrains for power, skip action if invalid + + if (trains < ab.getMinTrains() || trains > ab.getMaxTrains()) + continue; + // If something blocks the action, then stop + + if (ab.blocked(target, pb, trains)) { + + PowersManager.sendEffectMsg(playerCharacter, 5, ab, pb); + continue; + } + + // TODO handle overwrite stack order here + String stackType = ab.getStackType(); + stackType = (stackType.equals("IgnoreStack")) ? Integer.toString(ab.getUUID()) : stackType; + // if (!stackType.equals("IgnoreStack")) { + if (target.getEffects().containsKey(stackType)) { + // remove any existing power that overrides + Effect ef = target.getEffects().get(stackType); + AbstractEffectJob effect = null; + if (ef != null) { + JobContainer jc = ef.getJobContainer(); + if (jc != null) + effect = (AbstractEffectJob) jc.getJob(); + } + ActionsBase overwrite = effect.getAction(); + + if (overwrite == null) { + Logger.error("NULL ACTION FOR POWER " + effect.getPowerToken()); + continue; + } + + if (ab.getStackOrder() < overwrite.getStackOrder()) + continue; // not high enough to overwrite + else if (ab.getStackOrder() > overwrite.getStackOrder()) { + effect.setNoOverwrite(true); + removeEffect(target, overwrite, true, false); + } else if (ab.getStackOrder() == overwrite.getStackOrder()) + if (ab.greaterThanEqual() + && (trains >= effect.getTrains())) { + effect.setNoOverwrite(true); + removeEffect(target, overwrite, true, false); + } else if (ab.always()) + removeEffect(target, overwrite, true, false); + else if (ab.greaterThan() + && (trains > effect.getTrains())) { + effect.setNoOverwrite(true); + removeEffect(target, overwrite, true, false); + } else if (ab.greaterThan() && pb.getToken() == effect.getPowerToken()) + removeEffect(target, overwrite, true, false); + + else + continue; // trains not high enough to overwrite + + } + + // } + + + runPowerAction(playerCharacter, target, targetLoc, ab, trains, pb); + if (!miss && !msgCasted) { + PerformActionMsg castMsg = new PerformActionMsg(msg); + castMsg.setNumTrains(9999); + castMsg.setUnknown04(2); + DispatchMessage.dispatchMsgToInterestArea(playerCharacter, castMsg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + msgCasted = true; + } + } + } + + if (!msgCasted) { + PerformActionMsg castMsg = new PerformActionMsg(msg); + castMsg.setNumTrains(9999); + castMsg.setUnknown04(2); + DispatchMessage.dispatchMsgToInterestArea(playerCharacter, castMsg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + msgCasted = true; + } + + //Handle chant + if (pb != null && pb.isChant()) + for (ActionsBase ab : pb.getActions()) { + AbstractPowerAction pa = ab.getPowerAction(); + if (pa != null) + if (pb.getToken() != 428950414 && pb.getToken() != 428884878) + pa.handleChant(playerCharacter, playerCharacter, targetLoc, trains, ab, pb); + else if (PowersManager.getTarget(msg) != null && PowersManager.getTarget(msg).isAlive()) + pa.handleChant(playerCharacter, PowersManager.getTarget(msg), targetLoc, trains, ab, pb); + else + pa.handleChant(playerCharacter, null, targetLoc, trains, ab, pb); + } + + + //DispatchMessage.dispatchMsgToInterestArea(playerCharacter, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + + + } + + public static void finishUseMobPower(PerformActionMsg msg, Mob caster, int casterLiveCounter, int targetLiveCounter) { + + if (caster == null || msg == null) + return; + + if (!caster.isAlive() || caster.getLiveCounter() != casterLiveCounter) + return; + + // set player is not casting for regens + caster.setIsCasting(false); + + + PowersBase pb = PowersManager.powersBaseByToken.get(msg.getPowerUsedID()); + // clear power. + caster.setLastMobPowerToken(0); + + if (pb == null) { + Logger.error( + "finishUsePower(): Power '" + msg.getPowerUsedID() + + "' was not found on powersBaseByToken map."); + return; + } + + int trains = msg.getNumTrains(); + + // update used power timer + // verify player is not stunned or power type is blocked + PlayerBonuses bonus = caster.getBonuses(); + if (bonus != null) { + if (bonus.getBool(ModType.Stunned, SourceType.None)) + return; + SourceType sourceType = SourceType.GetSourceType(pb.getCategory()); + if (bonus.getBool(ModType.BlockedPowerType, sourceType)) + return; + } + + msg.setNumTrains(9999); + msg.setUnknown04(2); + DispatchMessage.sendToAllInRange(caster, msg); + + // get target loc + Vector3fImmutable targetLoc = msg.getTargetLoc(); + if (targetLoc.x == 0f || targetLoc.z == 0f) { + AbstractWorldObject tar = getTarget(msg); + if (tar != null) + targetLoc = tar.getLoc(); + } + + // get list of targets + HashSet allTargets = getAllTargets( + getTarget(msg), msg.getTargetLoc(), caster, pb); + for (AbstractWorldObject target : allTargets) { + + if (target == null) + continue; + + + //make sure target hasn't respawned since we began casting + //skip this if liveCounter = -1 (from aoe) + if (targetLiveCounter != -1) + if (AbstractWorldObject.IsAbstractCharacter(target)) + if (targetLiveCounter != ((AbstractCharacter) target).getLiveCounter()) + continue; + + //make sure mob is awake to respond. + //if (target instanceof AbstractIntelligenceAgent) + //((AbstractIntelligenceAgent)target).enableIntelligence(); + // If Hit roll required, test hit + if (pb.requiresHitRoll() && !pb.isWeaponPower() && testAttack(caster, target, pb, msg)) + //aggro mob even on a miss + continue; + + // update target of used power timer + + if (target.getObjectType().equals(GameObjectType.PlayerCharacter)) { + + ((PlayerCharacter) target).setLastTargetOfUsedPowerTime(); + ((PlayerCharacter) target).setTimeStamp("LastCombatPlayer", System.currentTimeMillis()); + } + + + // finally Apply actions + for (ActionsBase ab : pb.getActions()) { + // get numTrains for power, skip action if invalid + + if (trains < ab.getMinTrains() || trains > ab.getMaxTrains()) + continue; + // If something blocks the action, then stop + + if (ab.blocked(target, pb, trains)) + continue; + // TODO handle overwrite stack order here + String stackType = ab.getStackType(); + stackType = (stackType.equals("IgnoreStack")) ? Integer.toString(ab.getUUID()) : stackType; + // if (!stackType.equals("IgnoreStack")) { + if (target.getEffects().containsKey(stackType)) { + // remove any existing power that overrides + Effect ef = target.getEffects().get(stackType); + AbstractEffectJob effect = null; + if (ef != null) { + JobContainer jc = ef.getJobContainer(); + if (jc != null) + effect = (AbstractEffectJob) jc.getJob(); + } + ActionsBase overwrite = effect.getAction(); + + if (overwrite == null) { + Logger.error("NULL ACTION FOR EFFECT " + effect.getPowerToken()); + continue; + } + if (ab.getStackOrder() < overwrite.getStackOrder()) + continue; // not high enough to overwrite + else if (ab.getStackOrder() > overwrite.getStackOrder()) { + effect.setNoOverwrite(true); + removeEffect(target, overwrite, true, false); + } else if (ab.getStackOrder() == overwrite.getStackOrder()) + if (ab.greaterThanEqual() + && (trains >= effect.getTrains())) { + effect.setNoOverwrite(true); + removeEffect(target, overwrite, true, false); + } else if (ab.always()) + removeEffect(target, overwrite, true, false); + else if (ab.greaterThan() + && (trains > effect.getTrains())) { + effect.setNoOverwrite(true); + removeEffect(target, overwrite, true, false); + } else if (ab.greaterThan() && pb.getToken() == effect.getPowerToken()) + removeEffect(target, overwrite, true, false); + + else + continue; // trains not high enough to overwrite + } + + // } + runPowerAction(caster, target, targetLoc, ab, trains, pb); + } + } + + //Handle chant + if (pb != null && pb.isChant()) + for (ActionsBase ab : pb.getActions()) { + AbstractPowerAction pa = ab.getPowerAction(); + if (pa != null) + pa.handleChant(caster, caster, targetLoc, trains, ab, pb); + } + + // TODO echo power use to everyone else + msg.setNumTrains(9999); + msg.setUnknown04(2); + DispatchMessage.sendToAllInRange(caster, msg); + + } + + // *** Refactor : Wtf is this mess? + + private static boolean validMonsterType(AbstractWorldObject target, PowersBase pb) { + + if (pb == null || target == null) + return false; + + String mtp = pb.getMonsterTypePrereq(); + + if (mtp.length() == 0) + return true; + + if (target.getObjectType().equals(GameObjectType.PlayerCharacter)) { + + PlayerCharacter pc = (PlayerCharacter) target; + int raceID = 0; + + if (pc.getRace() != null) + raceID = pc.getRace().getRaceRuneID(); + + switch (mtp) { + case "Shade": + return raceID == 2015 || raceID == 2016; + case "Elf": + return raceID == 2008 || raceID == 2009; + case "Dwarf": + return raceID == 2006; + case "Aracoix": + return raceID == 2002 || raceID == 2003; + case "Irekei": + return raceID == 2013 || raceID == 2014; + case "Vampire": + return raceID == 2028 || raceID == 2029; + } + } else if (target.getObjectType().equals(GameObjectType.Mob)) { + Mob mob = (Mob) target; + + if (pb.targetMob() && !mob.isMob() && !mob.isSiege()) + return false; + else if (pb.targetPet() && !mob.isPet() && !mob.isSiege()) + return false; + + switch (mtp) { + case "Animal": + if ((mob.getObjectTypeMask() & MBServerStatics.MASK_BEAST) == 0) + return false; + break; + case "NPC": + if ((mob.getObjectTypeMask() & MBServerStatics.MASK_HUMANOID) == 0) + return false; + break; + case "Rat": + if ((mob.getObjectTypeMask() & MBServerStatics.MASK_RAT) == 0) + return false; + break; + case "Siege": + if (!mob.isSiege()) + return false; + break; + case "Undead": + if ((mob.getObjectTypeMask() & MBServerStatics.MASK_UNDEAD) == 0) + return false; + break; + } + return true; + } else + return target.getObjectType().equals(GameObjectType.Building) && mtp.equals("Siege"); + return false; + } + + public static void summon(SendSummonsRequestMsg msg, ClientConnection origin) { + PlayerCharacter pc = SessionManager.getPlayerCharacter( + origin); + if (pc == null) + return; + + PlayerCharacter target = SessionManager + .getPlayerCharacterByLowerCaseName(msg.getTargetName()); + if (target == null || target.equals(pc) || target.isCombat()) { + + if (target == null) // Player not found. Send not found message + ChatManager.chatInfoError(pc, + "Cannot find that player to summon."); + else if (target.isCombat()) + ChatManager.chatInfoError(pc, + "Cannot summon player in combat."); + // else trying to summon self, just fail + + // recycle summon + sendRecyclePower(msg.getPowerToken(), origin); + + // TODO: client already subtracted 200 mana.. need to correct it + // end cast + PerformActionMsg pam = new PerformActionMsg(msg.getPowerToken(), + msg.getTrains(), msg.getSourceType(), msg.getSourceID(), 0, + 0, 0f, 0f, 0f, 1, 0); + sendPowerMsg(pc, 2, pam); + + return; + } + + PerformActionMsg pam = new PerformActionMsg(msg.getPowerToken(), msg + .getTrains(), msg.getSourceType(), msg.getSourceID(), target + .getObjectType().ordinal(), target.getObjectUUID(), 0f, 0f, 0f, 1, 0); + + // Client removes 200 mana on summon use.. so don't send message to self + target.addSummoner(pc.getObjectUUID(), System.currentTimeMillis() + MBServerStatics.FOURTYFIVE_SECONDS); + usePower(pam, origin, false); + } + + public static void recvSummon(RecvSummonsRequestMsg msg, ClientConnection origin) { + PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); + if (pc == null) + return; + + PlayerCharacter source = PlayerCharacter.getFromCache(msg.getSourceID()); + if (source == null) + return; + + long tooLate = pc.getSummoner(source.getObjectUUID()); + if (tooLate < System.currentTimeMillis()) { + ChatManager.chatInfoError(pc, "You waited too long to " + (msg.accepted() ? "accept" : "decline") + " the summons."); + pc.removeSummoner(source.getObjectUUID()); + return; + } + + if (pc.getBonuses() != null && pc.getBonuses().getBool(ModType.BlockedPowerType, SourceType.SUMMON)) { + ErrorPopupMsg.sendErrorMsg(pc, "You have been blocked from receiving summons!"); + ErrorPopupMsg.sendErrorMsg(source, "Target is blocked from receiving summons!"); + pc.removeSummoner(source.getObjectUUID()); + return; + } + pc.removeSummoner(source.getObjectUUID()); + + // Handle Accepting or Denying a summons. + // set timer based on summon type. + boolean wentThrough = false; + if (msg.accepted()) + // summons accepted, let's move the player if within time + if (source.isAlive()) { + + // //make sure summons handled in time + ConcurrentHashMap timers = source.getTimers(); + // if (timers == null || !timers.containsKey("SummonSend")) { + // ChatManager.chatInfoError(pc, "You waited too long to " + (msg.accepted() ? "accept" : "decline") + " the summons."); + // return; + // } + + // // clear last summons accept timer + // timers.get("SummonSend").cancelJob(); + //timers.remove("SummonSend"); + // cancel any other summons waiting + timers = pc.getTimers(); + if (timers != null && timers.containsKey("Summon")) + timers.get("Summon").cancelJob(); + + // get time to wait before summons goes through + BaseClass base = source.getBaseClass(); + PromotionClass promo = source.getPromotionClass(); + int duration; + + + //determine if in combat with another player + + + //comment out this block to disable combat timer + // if (lastAttacked < 60000) { + // if (pc.inSafeZone()) //player in safe zone, no need for combat timer + // combat = false; + // else if (source.inSafeZone()) //summoner in safe zone, apply combat timer + // combat = true; + // else if ((source.getLoc().distance2D(pc.getLoc())) > 6144f) + // combat = true; //more than 1.5x width of zone, not tactical summons + // } if (promo != null && promo.getObjectUUID() == 2519) - duration = 10000; // Priest summons, 10 seconds - else if (base != null && base.getObjectUUID() == 2501) - duration = 15000; // Healer Summons, 15 seconds - else - duration = 45000; // Belgosh Summons, 45 seconds - - - // Teleport to summoners location - FinishSummonsJob fsj = new FinishSummonsJob(source, pc); - JobContainer jc = JobScheduler.getInstance().scheduleJob(fsj, - duration); - if (timers != null) - timers.put("Summon", jc); - wentThrough = true; - } - - // Summons failed - if (!wentThrough) - // summons refused. Let's be nice and reset recycle timer - if (source != null) { - - // Send summons refused Message - ErrorPopupMsg.sendErrorPopup(source, 29); - - // recycle summons power - //finishRecycleTime(428523680, source, true); - } - } - - public static void trackWindow(TrackWindowMsg msg, ClientConnection origin) { - - PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter( - origin); - - if (playerCharacter == null) - return; - - if (MBServerStatics.POWERS_DEBUG) { - ChatManager.chatSayInfo( - playerCharacter, - "Using Power: " + Integer.toHexString(msg.getPowerToken()) - + " (" + msg.getPowerToken() + ')'); - Logger.info( "Using Power: " - + Integer.toHexString(msg.getPowerToken()) + " (" - + msg.getPowerToken() + ')'); - } - - // get track power used - PowersBase pb = PowersManager.powersBaseByToken.get(msg.getPowerToken()); - - if (pb == null || !pb.isTrack()) - return; - - //check track threshold timer to prevent spam - long currentTime = System.currentTimeMillis(); - long timestamp = playerCharacter.getTimeStamp("trackWindow"); - long dif = currentTime - timestamp; - if (dif < MBServerStatics.TRACK_WINDOW_THRESHOLD) - return; - playerCharacter.setTimeStamp("trackWindow", currentTime); - - ArrayList ablist = pb.getActions(); - if (ablist == null) - return; - - TrackPowerAction tpa = null; - for (ActionsBase ab : ablist) { - AbstractPowerAction apa = ab.getPowerAction(); - if (apa != null && apa instanceof TrackPowerAction) - tpa = (TrackPowerAction) apa; - } - if (tpa == null) - return; - - // Check powers for normal users - if (playerCharacter.getPowers() == null || !playerCharacter.getPowers().containsKey(msg.getPowerToken())) - if (!playerCharacter.isCSR()) - if (!MBServerStatics.POWERS_DEBUG) { - // ChatManager.chatSayInfo(pc, "You may not cast that spell!"); - // this.logEXPLOIT("usePowerA(): Cheat attempted? '" + msg.getPowerToken() + "' was not associated with " + pc.getName()); - return; - } - - // Get search mask for track - int mask = 0; - if (pb.targetPlayer()) - if (tpa.trackVampire()) // track vampires - mask = MBServerStatics.MASK_PLAYER | MBServerStatics.MASK_UNDEAD; - else - // track all players - mask = MBServerStatics.MASK_PLAYER; - else if (pb.targetCorpse()) // track corpses - mask = MBServerStatics.MASK_CORPSE; - else if (tpa.trackNPC()) // Track NPCs - mask = MBServerStatics.MASK_NPC; - else if (tpa.trackUndead()) // Track Undead - mask = MBServerStatics.MASK_MOB | MBServerStatics.MASK_UNDEAD; - else - // Track All - mask = MBServerStatics.MASK_MOB | MBServerStatics.MASK_NPC; - - // Find characters in range - HashSet allTargets; - allTargets = WorldGrid.getObjectsInRangeContains(playerCharacter.getLoc(), - pb.getRange(), mask); - - //remove anyone who can't be tracked - Iterator it = allTargets.iterator(); - while (it.hasNext()) { - AbstractWorldObject awo = it.next(); - if (awo == null) - continue; - else if (!awo.isAlive()) - it.remove(); - else if (awo.getObjectType().equals(GameObjectType.PlayerCharacter)) { - PlayerBonuses bonus = ((PlayerCharacter) awo).getBonuses(); - if (bonus != null && bonus.getBool(ModType.CannotTrack, SourceType.None)) - it.remove(); - } - } - - // get max charcters for window - int maxTargets = 20; - PromotionClass promo = playerCharacter.getPromotionClass(); - if (promo != null) { - int tableID = promo.getObjectUUID(); - if (tableID == 2512 || tableID == 2514 || tableID == 2515) - maxTargets = 40; - } - - // create list of characters - HashSet trackChars = RangeBasedAwo.getTrackList( - allTargets, playerCharacter, maxTargets); - - TrackWindowMsg trackWindowMsg = new TrackWindowMsg(msg); - - // send track window - trackWindowMsg.setSource(playerCharacter); - trackWindowMsg.setCharacters(trackChars); - - Dispatch dispatch = Dispatch.borrow(playerCharacter, trackWindowMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - } - - private static void sendRecyclePower(int token, ClientConnection origin) { - RecyclePowerMsg recyclePowerMsg = new RecyclePowerMsg(token); - - Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), recyclePowerMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - - } - - public static boolean verifyInvalidRange(AbstractCharacter ac, - AbstractWorldObject target, float range) { - Vector3fImmutable sl = ac.getLoc(); - Vector3fImmutable tl = target.getLoc(); - if (target.getObjectType().equals(GameObjectType.Item)) { - - Item item = (Item) target; - AbstractGameObject owner = item.getOwner(); - - if (owner == null || owner.getObjectType().equals(GameObjectType.Account)) - return true; - - if (owner.getObjectType().equals(GameObjectType.PlayerCharacter) || owner.getObjectType().equals(GameObjectType.Mob)) { - AbstractCharacter acOwner = (AbstractCharacter) owner; - CharacterItemManager itemMan = acOwner.getCharItemManager(); - if (itemMan == null) - return true; - if (itemMan.inventoryContains(item)) { - tl = acOwner.getLoc(); - return !(sl.distanceSquared(tl) <= sqr(range)); - } - return true; - } - return true; - } - - range += (calcHitBox(ac) + calcHitBox(target)); - - - float distanceToTarget = sl.distanceSquared(tl);//distance to center of target - - return distanceToTarget > range * range; - - } - - public static float calcHitBox(AbstractWorldObject ac) { - //TODO Figure out how Str Affects HitBox - float hitBox = 1; - switch (ac.getObjectType()) { - case PlayerCharacter: - PlayerCharacter pc = (PlayerCharacter) ac; - if (MBServerStatics.COMBAT_TARGET_HITBOX_DEBUG) - Logger.info( "Hit box radius for " + pc.getFirstName() + " is " + ((int) pc.statStrBase / 200f)); - hitBox = 2f + (int) ((PlayerCharacter) ac).statStrBase / 50f; - break; - - case Mob: - Mob mob = (Mob) ac; - if (MBServerStatics.COMBAT_TARGET_HITBOX_DEBUG) - Logger.info( "Hit box radius for " + mob.getFirstName() - + " is " + ((Mob) ac).getMobBase().getHitBoxRadius()); - - hitBox = ((Mob) ac).getMobBase().getHitBoxRadius(); - break; - case Building: - Building building = (Building) ac; - if (building.getBlueprint() == null) - return 32; - hitBox = Math.max(building.getBlueprint().getBuildingGroup().getExtents().x, - building.getBlueprint().getBuildingGroup().getExtents().y); - if (MBServerStatics.COMBAT_TARGET_HITBOX_DEBUG) - Logger.info("Hit box radius for " + building.getName() + " is " + hitBox); - break; - - } - return hitBox; - } - - // Apply a power based on it's IDString - public static void applyPower(AbstractCharacter ac, AbstractWorldObject target, - Vector3fImmutable targetLoc, String ID, int trains, boolean fromItem) { - if (ac == null || target == null || !ac.isAlive()) - return; - PowersBase pb = powersBaseByIDString.get(ID); - if (pb == null) { - Logger.error( - "applyPower(): Got NULL on powersBaseByIDString table lookup for: " - + ID); - return; - } - applyPowerA(ac, target, targetLoc, pb, trains, fromItem); - } - - // Apply a power based on it's Token - public static void applyPower(AbstractCharacter ac, AbstractWorldObject target, - Vector3fImmutable targetLoc, int token, int trains, boolean fromItem) { - if (ac == null || target == null) - return; - - //Don't apply power if ac is dead, unless death shroud or safe mode - if (!ac.isAlive()) - if (!(token == -1661758934 || token == 1672601862)) - return; - - PowersBase pb = powersBaseByToken.get(token); - if (pb == null) { - Logger.error( - "applyPower(): Got NULL on powersBaseByToken table lookup for: " - + token); - return; - } - applyPowerA(ac, target, targetLoc, pb, trains, fromItem); - } - - private static void applyPowerA(AbstractCharacter ac, AbstractWorldObject target, - Vector3fImmutable targetLoc, PowersBase pb, int trains, - boolean fromItem) { - int time = pb.getCastTime(trains); - if (!fromItem) - finishApplyPowerA(ac, target, targetLoc, pb, trains, false); - else if (time == 0) - finishApplyPower(ac, target, targetLoc, pb, trains, ac.getLiveCounter()); - else { - - ac.setItemCasting(true); - int tarType = (target == null) ? 0 : target.getObjectType().ordinal(); - int tarID = (target == null) ? 0 : target.getObjectUUID(); - - // start the action animation - PerformActionMsg msg = new PerformActionMsg(pb.getToken(), - trains, ac.getObjectType().ordinal(), ac.getObjectUUID(), tarType, tarID, 0, - 0, 0, 1, 0); - DispatchMessage.sendToAllInRange(target, msg); - - - ConcurrentHashMap timers = ac.getTimers(); - - if (timers.containsKey(Integer.toString(pb.getToken()))) { - JobContainer jc = timers.get(Integer.toString(pb.getToken())); - if (jc != null) - jc.cancelJob(); - } - - // // clear any other items being used - // JobContainer jc = ac.getLastItem(); - // if (jc != null) { - // jc.cancelJob(); - // ac.clearLastItem(); - // } - // run timer job to end cast - UseItemJob uij = new UseItemJob(ac, target, pb, trains, ac.getLiveCounter()); - JobContainer jc = js.scheduleJob(uij, time); - - // make lastItem - timers.put(Integer.toString(pb.getToken()), jc); - } - } - - public static void finishApplyPower(AbstractCharacter ac, - AbstractWorldObject target, Vector3fImmutable targetLoc, - PowersBase pb, int trains, int liveCounter) { - - if (ac != null) - ac.setItemCasting(false); - if (ac == null || target == null || pb == null) - return; - - ac.clearTimer(Integer.toString(pb.getToken())); - if (liveCounter == ac.getLiveCounter()) - finishApplyPowerA(ac, target, targetLoc, pb, trains, false); - } - - public static void finishApplyPowerA(AbstractCharacter ac, - AbstractWorldObject target, Vector3fImmutable targetLoc, - PowersBase pb, int trains, boolean fromChant) { - // finally Apply actions - ArrayList actions = pb.getActions(); - for (ActionsBase ab : actions) { - // get numTrains for power, skip action if invalid - if (trains < ab.getMinTrains() || trains > ab.getMaxTrains()) - continue; - // If something blocks the action, then stop - if (ab.blocked(target, pb, trains)) - // sendPowerMsg(pc, 5, msg); - continue; - // TODO handle overwrite stack order here - String stackType = ab.getStackType(); - stackType = (stackType.equals("IgnoreStack")) ? Integer.toString(ab.getUUID()) : stackType; - if (target.getEffects().containsKey(stackType)) { - // remove any existing power that overrides - Effect ef = target.getEffects().get(stackType); - AbstractEffectJob effect = null; - if (ef != null) { - JobContainer jc = ef.getJobContainer(); - if (jc != null) - effect = (AbstractEffectJob) jc.getJob(); - } - ActionsBase overwrite = effect.getAction(); - PowersBase pbOverwrite = effect.getPower(); - if (pbOverwrite != null && pbOverwrite.equals(pb) - && (trains >= effect.getTrains())) - removeEffect(target, overwrite, true, fromChant); - else if (ab.getStackOrder() < overwrite.getStackOrder()) - continue; // not high enough to overwrite - else if (ab.getStackOrder() > overwrite.getStackOrder()) - removeEffect(target, overwrite, true, false); - else if (ab.getStackOrder() == overwrite.getStackOrder()) - if (ab.greaterThanEqual() - && (trains >= effect.getTrains())) - removeEffect(target, overwrite, true, false); - else if (ab.always()) - removeEffect(target, overwrite, true, false); - else if (ab.greaterThan() - && (trains > effect.getTrains())) - removeEffect(target, overwrite, true, false); - else if (ab.greaterThan() && pb.getToken() == effect.getPowerToken()) - removeEffect(target, overwrite, true, false); - else - continue; // trains not high enough to overwrite - } - if (fromChant) - targetLoc = Vector3fImmutable.ZERO; - runPowerAction(ac, target, targetLoc, ab, trains, pb); - } - - //Handle chant - if (pb != null && pb.isChant()) - for (ActionsBase ab : pb.getActions()) { - AbstractPowerAction pa = ab.getPowerAction(); - if (pa != null) - pa.handleChant(ac, target, targetLoc, trains, ab, pb); - } - - // for chants, only send the animation if the character is not is not moving or casting - boolean doAnimation = true; - - if (target.getObjectType().equals(GameObjectType.PlayerCharacter)) { - PlayerCharacter pc = (PlayerCharacter) target; - if (pb != null && pb.isChant() && (pc.isMoving() || pc.isCasting())) - doAnimation = false; - } - - if (pb.getToken() == 428950414) - doAnimation = true; - - if (doAnimation) { - PerformActionMsg msg = new PerformActionMsg(pb.getToken(), 9999, ac - .getObjectType().ordinal(), ac.getObjectUUID(), target.getObjectType().ordinal(), - target.getObjectUUID(), 0, 0, 0, 2, 0); - - DispatchMessage.sendToAllInRange(ac, msg); - - } - } - - public static void runPowerAction(AbstractCharacter source, - AbstractWorldObject awo, Vector3fImmutable targetLoc, - ActionsBase ab, int trains, PowersBase pb) { - AbstractPowerAction pa = ab.getPowerAction(); - if (pa == null) { - Logger.error( - "runPowerAction(): PowerAction not found of IDString: " - + ab.getEffectID()); - return; - } - pa.startAction(source, awo, targetLoc, trains, ab, pb); - } - - public static void runPowerAction(AbstractCharacter source, - AbstractWorldObject awo, Vector3fImmutable targetLoc, - ActionsBase ab, int trains, PowersBase pb, int duration) { - AbstractPowerAction pa = ab.getPowerAction(); - if (pa == null) { - Logger.error( - "runPowerAction(): PowerAction not found of IDString: " - + ab.getEffectID()); - return; - } - pa.startAction(source, awo, targetLoc, trains, ab, pb, duration); - } - - public static HashSet getAllTargets( - AbstractWorldObject target, Vector3fImmutable tl, - PlayerCharacter pc, PowersBase pb) { - HashSet allTargets; - if (pb.isAOE()) { - Vector3fImmutable targetLoc = null; - if (pb.usePointBlank()) { - targetLoc = pc.getLoc(); - } else { - if (target != null) { - targetLoc = target.getLoc(); - } else { - targetLoc = tl; - try{ - targetLoc = targetLoc.setY(HeightMap.getWorldHeight(targetLoc)); //on ground - }catch (Exception e){ - Logger.error(e); - targetLoc = tl; - } - - } - } - - if (targetLoc.x == 0f || targetLoc.z == 0f) - return new HashSet<>(); // invalid loc, - // return - // nothing - - //first find targets in range quickly with QTree - if (pb.targetPlayer() && pb.targetMob()) - // Player and mobs - allTargets = WorldGrid.getObjectsInRangePartial( - targetLoc, pb.getRadius(), MBServerStatics.MASK_MOBILE); - else if (pb.targetPlayer()) - // Player only - allTargets = WorldGrid.getObjectsInRangePartial( - targetLoc, pb.getRadius(), MBServerStatics.MASK_PLAYER); - else if (pb.targetMob()) - // Mob only - allTargets = WorldGrid.getObjectsInRangePartial( - targetLoc, pb.getRadius(), MBServerStatics.MASK_MOB - | MBServerStatics.MASK_PET); - else if (pb.targetPet()) - //Pet only - allTargets = WorldGrid.getObjectsInRangePartial( - targetLoc, pb.getRadius(), MBServerStatics.MASK_PET); - else if (pb.targetNecroPet()) - allTargets = WorldGrid.getObjectsInRangePartialNecroPets( - targetLoc, pb.getRadius()); - else - allTargets = WorldGrid.getObjectsInRangePartial( - targetLoc, pb.getRadius(), 0); - - // cleanup self, group and nation targets if needed - Iterator awolist = allTargets.iterator(); - while (awolist.hasNext()) { - AbstractWorldObject awo = awolist.next(); - if (awo == null) { - awolist.remove(); // won't hit a null - continue; - } - - //see if targets are within 3D range of each other - Vector3fImmutable tloc = awo.getLoc(); - - if (tloc.distanceSquared(targetLoc) > sqr(pb.getRadius())) { - awolist.remove(); // too far away - continue; - } - - if (pb.isCasterFriendly() && pc.equals(awo)) { - awolist.remove(); // won't hit self - continue; - } - - if (!awo.isAlive()) { - awolist.remove(); // too far away - continue; - } - - if (awo.getObjectType().equals(GameObjectType.PlayerCharacter)) { - - PlayerCharacter pcc = (PlayerCharacter) awo; - - if (pb.isGroupFriendly() && GroupManager.getGroup(pc) != null && GroupManager.getGroup(pcc) != null) - if (GroupManager.getGroup(pc).equals(GroupManager.getGroup(pcc))) { - awolist.remove(); // Won't hit group members - continue; - } - if (pb.isNationFriendly() && pc.getGuild() != null && - pc.getGuild().getNation() != null && pcc.getGuild() != null && - pc.getGuild().getNation() != null) - if (pc.getGuild().getNation().equals(pcc.getGuild().getNation())) { - awolist.remove(); // Won't hit nation members - continue; - } - - // Remove players for non-friendly spells in safe zone - if (pb.isHarmful() && (pcc.inSafeZone() || pc.inSafeZone())) { - awolist.remove(); - continue; - } - } - } - // Trim list down to max size closest targets, limited by max - // Player/Mob amounts - allTargets = RangeBasedAwo.getSortedList(allTargets, targetLoc, pb - .getMaxNumPlayerTargets(), pb.getMaxNumMobTargets()); - } else if (pb.targetGroup()) { - - if (GroupManager.getGroup(pc) != null) { - allTargets = WorldGrid.getObjectsInRangePartial(pc - .getLoc(), pb.getRange(), MBServerStatics.MASK_PLAYER); - Iterator awolist = allTargets.iterator(); - while (awolist.hasNext()) { - - AbstractWorldObject awo = awolist.next(); - - if (!(awo.getObjectType().equals(GameObjectType.PlayerCharacter))) { - awolist.remove(); // remove non players if there are any - continue; - } - PlayerCharacter pcc = (PlayerCharacter) awo; - - if (GroupManager.getGroup(pcc) == null) - awolist.remove(); // remove players not in a group - else if (!GroupManager.getGroup(pcc).equals(GroupManager.getGroup(pc))) - awolist.remove(); // remove if not same group - - } - } else { - allTargets = new HashSet<>(); - allTargets.add(pc); // no group, use only self - } - } else { - allTargets = new HashSet<>(); - if (pb.targetSelf()) - allTargets.add(pc); - else if (pb.targetFromLastTarget()) - allTargets.add(target); - else if (pb.targetFromNearbyMobs()) - allTargets.add(target); // need better way to do this later - else - // targetByName - allTargets.add(target); // need to get name later - // can't target self if caster friendly - if (pb.isCasterFriendly() && allTargets.contains(pc)) - allTargets.remove(0); - } - - Iterator awolist = allTargets.iterator(); - while (awolist.hasNext()) { - AbstractWorldObject awo = awolist.next(); - - //See if target is valid type - if (!validMonsterType(awo, pb)) { - awolist.remove(); - continue; - } - - if (awo != null && awo.getObjectType().equals(GameObjectType.PlayerCharacter)) { - - // Remove players who are in safe mode - PlayerCharacter pcc = (PlayerCharacter) awo; - PlayerBonuses bonuses = pcc.getBonuses(); - - if (bonuses != null && bonuses.getBool(ModType.ImmuneToPowers, SourceType.None)) { - awolist.remove(); - continue; - } - - //remove if power is harmful and caster or target is in safe zone - if (pb.isHarmful() && (pcc.inSafeZone() || pc.inSafeZone())) { - awolist.remove(); - continue; - } - } - } - - // verify target has proper effects applied to receive power - if (pb.getTargetEffectPrereqs().size() > 0) { - Iterator it = allTargets.iterator(); - while (it.hasNext()) { - boolean passed = false; - AbstractWorldObject awo = it.next(); - if (awo.getEffects() != null) { - for (PowerPrereq pp : pb.getTargetEffectPrereqs()) { - EffectsBase eb = PowersManager.getEffectByIDString(pp.getEffect()); - if (awo.containsEffect(eb.getToken())) { - passed = true; - break; - } - } - if (!passed) - it.remove(); - } else - it.remove(); //awo is missing it's effects list - } - } - return allTargets; - } - - public static HashSet getAllTargets( - AbstractWorldObject target, Vector3fImmutable tl, - AbstractCharacter caster, PowersBase pb) { - HashSet allTargets; - if (pb.isAOE()) { - Vector3fImmutable targetLoc = tl; - if (pb.usePointBlank()) { - targetLoc = caster.getLoc(); - } else { - if (target != null) { - targetLoc = target.getLoc(); - } else { - targetLoc = tl; - try{ - targetLoc = targetLoc.setY(HeightMap.getWorldHeight(targetLoc)); //on ground - }catch (Exception e){ - Logger.error(e); - } - - } - } - - if (targetLoc.x == 0f || targetLoc.z == 0f) - return new HashSet<>(); // invalid loc, - - //first find targets in range quickly with QTree - if (pb.targetPlayer() && pb.targetMob()) - // Player and mobs - allTargets = WorldGrid.getObjectsInRangePartial( - targetLoc, pb.getRadius(), MBServerStatics.MASK_MOBILE); - else if (pb.targetPlayer()) - // Player only - allTargets = WorldGrid.getObjectsInRangePartial( - targetLoc, pb.getRadius(), MBServerStatics.MASK_PLAYER); - else if (pb.targetMob()) - // Mob only - allTargets = WorldGrid.getObjectsInRangePartial( - targetLoc, pb.getRadius(), MBServerStatics.MASK_MOB - | MBServerStatics.MASK_PET); - else if (pb.targetPet()) - //Pet only - allTargets = WorldGrid.getObjectsInRangePartial( - targetLoc, pb.getRadius(), MBServerStatics.MASK_PET); - else if (pb.targetNecroPet()) - allTargets = WorldGrid.getObjectsInRangePartialNecroPets( - targetLoc, pb.getRadius()); - else - allTargets = WorldGrid.getObjectsInRangePartial( - targetLoc, pb.getRadius(), 0); - - // cleanup self, group and nation targets if needed - Iterator awolist = allTargets.iterator(); - while (awolist.hasNext()) { - AbstractWorldObject awo = awolist.next(); - if (awo == null) { - awolist.remove(); // won't hit a null - continue; - } - - //see if targets are within 3D range of each other - Vector3fImmutable tloc = awo.getLoc(); - - if (tloc.distanceSquared(targetLoc) > sqr(pb.getRadius())) { - awolist.remove(); // too far away - continue; - } - - if (pb.isCasterFriendly() && caster.equals(awo)) { - awolist.remove(); // won't hit self - continue; - } - - if (awo.getObjectType() == GameObjectType.Mob) { - awolist.remove(); // Won't hit other mobs. - continue; - } - } - // Trim list down to max size closest targets, limited by max - // Player/Mob amounts - allTargets = RangeBasedAwo.getSortedList(allTargets, targetLoc, pb - .getMaxNumPlayerTargets(), pb.getMaxNumMobTargets()); - } else if (pb.targetGroup()) { - allTargets = new HashSet<>(); - allTargets.add(caster); // no group, use only self - } else { - allTargets = new HashSet<>(); - if (pb.targetSelf()) - allTargets.add(caster); - else if (pb.targetFromLastTarget()) - allTargets.add(target); - else if (pb.targetFromNearbyMobs()) - allTargets.add(target); // need better way to do this later - else - // targetByName - allTargets.add(target); // need to get name later - // can't target self if caster friendly - if (pb.isCasterFriendly() && allTargets.contains(caster)) - allTargets.remove(caster); - } - - Iterator awolist = allTargets.iterator(); - while (awolist.hasNext()) { - AbstractWorldObject awo = awolist.next(); - - //See if target is valid type - if (!validMonsterType(awo, pb)) { - awolist.remove(); - continue; - } - - if (awo != null && awo.getObjectType().equals(GameObjectType.PlayerCharacter)) { - // Remove players who are in safe mode - PlayerCharacter pcc = (PlayerCharacter) awo; - PlayerBonuses bonuses = pcc.getBonuses(); - if (bonuses != null && bonuses.getBool(ModType.ImmuneToPowers, SourceType.None)) { - awolist.remove(); - continue; - } - } - } - - // verify target has proper effects applied to receive power - if (pb.getTargetEffectPrereqs().size() > 0) { - Iterator it = allTargets.iterator(); - while (it.hasNext()) { - boolean passed = false; - AbstractWorldObject awo = it.next(); - if (awo.getEffects() != null) { - for (PowerPrereq pp : pb.getTargetEffectPrereqs()) { - EffectsBase eb = PowersManager.getEffectByIDString(pp.getEffect()); - if (awo.containsEffect(eb.getToken())) { - passed = true; - break; - } - } - if (!passed) - it.remove(); - } else - it.remove(); //awo is missing it's effects list - } - } - return allTargets; - } - - // removes an effect before time is finished - public static void removeEffect(AbstractWorldObject awo, ActionsBase toRemove, - boolean overwrite, boolean fromChant) { - if (toRemove == null) - return; - - String stackType = toRemove.getStackType(); - stackType = (stackType.equals("IgnoreStack")) ? Integer - .toString(toRemove.getUUID()) : stackType; - if (fromChant) { - Effect eff = awo.getEffects().get(stackType); - if (eff != null) - eff.cancelJob(true); - } else - awo.cancelEffect(stackType, overwrite); - } - - // removes an effect when timer finishes - public static void finishEffectTime(AbstractWorldObject source, - AbstractWorldObject awo, ActionsBase toRemove, int trains) { - if (awo == null || toRemove == null) - return; - - // remove effect from player - String stackType = toRemove.getStackType(); - if (stackType.equals("IgnoreStack")) - stackType = Integer.toString(toRemove.getUUID()); - awo.endEffect(stackType); - } - - // removes an effect when timer is canceled - public static void cancelEffectTime(AbstractWorldObject source, - AbstractWorldObject awo, PowersBase pb, EffectsBase eb, - ActionsBase toRemove, int trains, AbstractEffectJob efj) { - if (awo == null || pb == null || eb == null || toRemove == null) - return; - eb.endEffect(source, awo, trains, pb, efj); - } - - // called when cooldown ends letting player cast next spell - public static void finishCooldownTime(PerformActionMsg msg, PlayerCharacter pc) { - // clear spell so player can cast again - // if (pc != null) - // pc.clearLastPower(); - } - - // called when recycle time ends letting player cast spell again - public static void finishRecycleTime(PerformActionMsg msg, PlayerCharacter pc, - boolean canceled) { - finishRecycleTime(msg.getPowerUsedID(), pc, canceled); - } - - public static void finishRecycleTime(int token, PlayerCharacter pc, - boolean canceled) { - if (pc == null) - return; - - ConcurrentHashMap recycleTimers = pc - .getRecycleTimers(); - // clear recycle time - if (recycleTimers != null) - if (recycleTimers.containsKey(token)) { - if (canceled) { - JobContainer jc = recycleTimers.get(token); - if (jc != null) - jc.cancelJob(); - } - recycleTimers.remove(token); - } - - // send recycle message to unlock power - - RecyclePowerMsg recyclePowerMsg = new RecyclePowerMsg(token); - Dispatch dispatch = Dispatch.borrow(pc, recyclePowerMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - - } - - // Called when a fail condition is met by player - // such as moving, taking damage, ect. - - public static void cancelUseLastPower(PlayerCharacter pc) { - - if (pc == null) - return; - - // set player is not casting for regens - if (pc.isCasting()){ - pc.update(); - } - pc.setIsCasting(false); - - UsePowerJob lastPower = null; - JobContainer jc = pc.getLastPower(); - - if (jc != null) - lastPower = ((UsePowerJob) jc.getJob()); - - if (lastPower == null) - return; - - // clear recycle timer - int token = lastPower.getToken(); - - if (pc.getRecycleTimers().contains(token)) - finishRecycleTime(token, pc, true); - - // pc.getRecycleTimers().remove(token); - // Cancel power - js.cancelScheduledJob(lastPower); - - // clear last power - pc.clearLastPower(); - - } - - private static AbstractWorldObject getTarget(PerformActionMsg msg) { - - int type = msg.getTargetType(); - int UUID = msg.getTargetID(); - - if (type == -1 || type == 0 || UUID == -1 || UUID == 0) - return null; - - return (AbstractWorldObject) DbManager.getObject(GameObjectType.values()[type], UUID); - } - - public static boolean testAttack(PlayerCharacter pc, AbstractWorldObject awo, - PowersBase pb, PerformActionMsg msg) { - // Get defense for target - float atr = CharacterSkill.getATR(pc, pb.getSkillName()); - float defense; - - if (AbstractWorldObject.IsAbstractCharacter(awo)) { - AbstractCharacter tar = (AbstractCharacter) awo; - defense = tar.getDefenseRating(); - } else - defense = 0f; - // Get hit chance - - if (pc.getDebug(16)) { - String smsg = "ATR: " + atr + ", Defense: " + defense; - ChatManager.chatSystemInfo(pc, smsg); - } - - int chance; - - if (atr > defense || defense == 0) - chance = 94; - else { - float dif = atr / defense; - if (dif <= 0.8f) - chance = 4; - else - chance = ((int) (450 * (dif - 0.8f)) + 4); - } - - // calculate hit/miss - int roll = ThreadLocalRandom.current().nextInt(100); - - boolean disable = true; - if (roll < chance) { - // Hit, check if dodge kicked in - if (awo instanceof AbstractCharacter) { - AbstractCharacter tarAc = (AbstractCharacter) awo; - // Handle Dodge passive - if (testPassive(pc, tarAc, "Dodge")) { - // Dodge fired, send dodge message - PerformActionMsg dodgeMsg = new PerformActionMsg(msg); - dodgeMsg.setTargetType(awo.getObjectType().ordinal()); - dodgeMsg.setTargetID(awo.getObjectUUID()); - sendPowerMsg(pc, 4, dodgeMsg); - return true; - } - } - return false; - } else { - // Miss. Send miss message - PerformActionMsg missMsg = new PerformActionMsg(msg); - - missMsg.setTargetType(awo.getObjectType().ordinal()); - missMsg.setTargetID(awo.getObjectUUID()); - sendPowerMsg(pc, 3, missMsg); - return true; - } - } - - public static boolean testAttack(Mob caster, AbstractWorldObject awo, - PowersBase pb, PerformActionMsg msg) { - // Get defense for target - float atr = 2000; - float defense; - - if (AbstractWorldObject.IsAbstractCharacter(awo)) { - AbstractCharacter tar = (AbstractCharacter) awo; - defense = tar.getDefenseRating(); - } else - defense = 0f; - // Get hit chance - - int chance; - - if (atr > defense || defense == 0) - chance = 94; - else { - float dif = atr / defense; - if (dif <= 0.8f) - chance = 4; - else - chance = ((int) (450 * (dif - 0.8f)) + 4); - } - - // calculate hit/miss - int roll = ThreadLocalRandom.current().nextInt(100); - - if (roll < chance) { - // Hit, check if dodge kicked in - if (AbstractWorldObject.IsAbstractCharacter(awo)) { - AbstractCharacter tarAc = (AbstractCharacter) awo; - // Handle Dodge passive - return testPassive(caster, tarAc, "Dodge"); - } - return false; - } else - return true; - } - - public static void sendPowerMsg(PlayerCharacter playerCharacter, int type, PerformActionMsg msg) { - - if (playerCharacter == null) - return; - - msg.setUnknown05(type); - - switch (type) { - case 3: - case 4: - msg.setUnknown04(2); - DispatchMessage.dispatchMsgToInterestArea(playerCharacter, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - break; - default: - msg.setUnknown04(1); - Dispatch dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - } - } - - public static void sendEffectMsg(PlayerCharacter pc, int type, ActionsBase ab, PowersBase pb) { - - if (pc == null) - return; - - try { - - EffectsBase eb = PowersManager.effectsBaseByIDString.get(ab.getEffectID()); - - if (eb == null) - return; - - ApplyEffectMsg aem = new ApplyEffectMsg(pc, pc, 0, eb.getToken(), 9, pb.getToken(), pb.getName()); - aem.setUnknown03(type); - DispatchMessage.dispatchMsgToInterestArea(pc, aem, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - - - } catch (Exception e) { - Logger.error( e.getMessage()); - } - - } - - public static void sendEffectMsg(PlayerCharacter pc, int type, EffectsBase eb) { - - if (pc == null) - return; - try { - - if (eb == null) - return; - ApplyEffectMsg aem = new ApplyEffectMsg(pc, pc, 0, eb.getToken(), 0, eb.getToken(), ""); - aem.setUnknown03(type); - aem.setUnknown05(1); - - DispatchMessage.dispatchMsgToInterestArea(pc, aem, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - - - } catch (Exception e) { - Logger.error( e.getMessage()); - } - - } - - public static void sendMobPowerMsg(Mob mob, int type, PerformActionMsg msg) { - - msg.setUnknown05(type); - switch (type) { - case 3: - case 4: - DispatchMessage.sendToAllInRange(mob, msg); - - } - } - - private static boolean testPassive(AbstractCharacter source, - AbstractCharacter target, String type) { - - float chance = target.getPassiveChance(type, source.getLevel(), false); - - if (chance == 0f) - return false; - - // max 75% chance of passive to fire - if (chance > 75f) - chance = 75f; - - int roll = ThreadLocalRandom.current().nextInt(100); - // Passive fired - // TODO send message - // Passive did not fire - return roll < chance; - } - - private static boolean validateTarget(AbstractWorldObject target, - PlayerCharacter pc, PowersBase pb) { + duration = 10000; // Priest summons, 10 seconds + else if (base != null && base.getObjectUUID() == 2501) + duration = 15000; // Healer Summons, 15 seconds + else + duration = 45000; // Belgosh Summons, 45 seconds + + + // Teleport to summoners location + FinishSummonsJob fsj = new FinishSummonsJob(source, pc); + JobContainer jc = JobScheduler.getInstance().scheduleJob(fsj, + duration); + if (timers != null) + timers.put("Summon", jc); + wentThrough = true; + } + + // Summons failed + if (!wentThrough) + // summons refused. Let's be nice and reset recycle timer + if (source != null) { + + // Send summons refused Message + ErrorPopupMsg.sendErrorPopup(source, 29); + + // recycle summons power + //finishRecycleTime(428523680, source, true); + } + } + + public static void trackWindow(TrackWindowMsg msg, ClientConnection origin) { + + PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter( + origin); + + if (playerCharacter == null) + return; + + if (MBServerStatics.POWERS_DEBUG) { + ChatManager.chatSayInfo( + playerCharacter, + "Using Power: " + Integer.toHexString(msg.getPowerToken()) + + " (" + msg.getPowerToken() + ')'); + Logger.info("Using Power: " + + Integer.toHexString(msg.getPowerToken()) + " (" + + msg.getPowerToken() + ')'); + } + + // get track power used + PowersBase pb = PowersManager.powersBaseByToken.get(msg.getPowerToken()); + + if (pb == null || !pb.isTrack()) + return; + + //check track threshold timer to prevent spam + long currentTime = System.currentTimeMillis(); + long timestamp = playerCharacter.getTimeStamp("trackWindow"); + long dif = currentTime - timestamp; + if (dif < MBServerStatics.TRACK_WINDOW_THRESHOLD) + return; + playerCharacter.setTimeStamp("trackWindow", currentTime); + + ArrayList ablist = pb.getActions(); + if (ablist == null) + return; + + TrackPowerAction tpa = null; + for (ActionsBase ab : ablist) { + AbstractPowerAction apa = ab.getPowerAction(); + if (apa != null && apa instanceof TrackPowerAction) + tpa = (TrackPowerAction) apa; + } + if (tpa == null) + return; + + // Check powers for normal users + if (playerCharacter.getPowers() == null || !playerCharacter.getPowers().containsKey(msg.getPowerToken())) + if (!playerCharacter.isCSR()) + if (!MBServerStatics.POWERS_DEBUG) { + // ChatManager.chatSayInfo(pc, "You may not cast that spell!"); + // this.logEXPLOIT("usePowerA(): Cheat attempted? '" + msg.getPowerToken() + "' was not associated with " + pc.getName()); + return; + } + + // Get search mask for track + int mask = 0; + if (pb.targetPlayer()) + if (tpa.trackVampire()) // track vampires + mask = MBServerStatics.MASK_PLAYER | MBServerStatics.MASK_UNDEAD; + else + // track all players + mask = MBServerStatics.MASK_PLAYER; + else if (pb.targetCorpse()) // track corpses + mask = MBServerStatics.MASK_CORPSE; + else if (tpa.trackNPC()) // Track NPCs + mask = MBServerStatics.MASK_NPC; + else if (tpa.trackUndead()) // Track Undead + mask = MBServerStatics.MASK_MOB | MBServerStatics.MASK_UNDEAD; + else + // Track All + mask = MBServerStatics.MASK_MOB | MBServerStatics.MASK_NPC; + + // Find characters in range + HashSet allTargets; + allTargets = WorldGrid.getObjectsInRangeContains(playerCharacter.getLoc(), + pb.getRange(), mask); + + //remove anyone who can't be tracked + Iterator it = allTargets.iterator(); + while (it.hasNext()) { + AbstractWorldObject awo = it.next(); + if (awo == null) + continue; + else if (!awo.isAlive()) + it.remove(); + else if (awo.getObjectType().equals(GameObjectType.PlayerCharacter)) { + PlayerBonuses bonus = ((PlayerCharacter) awo).getBonuses(); + if (bonus != null && bonus.getBool(ModType.CannotTrack, SourceType.None)) + it.remove(); + } + } + + // get max charcters for window + int maxTargets = 20; + PromotionClass promo = playerCharacter.getPromotionClass(); + if (promo != null) { + int tableID = promo.getObjectUUID(); + if (tableID == 2512 || tableID == 2514 || tableID == 2515) + maxTargets = 40; + } + + // create list of characters + HashSet trackChars = RangeBasedAwo.getTrackList( + allTargets, playerCharacter, maxTargets); + + TrackWindowMsg trackWindowMsg = new TrackWindowMsg(msg); + + // send track window + trackWindowMsg.setSource(playerCharacter); + trackWindowMsg.setCharacters(trackChars); + + Dispatch dispatch = Dispatch.borrow(playerCharacter, trackWindowMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + } + + private static void sendRecyclePower(int token, ClientConnection origin) { + RecyclePowerMsg recyclePowerMsg = new RecyclePowerMsg(token); + + Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), recyclePowerMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + + } + + public static boolean verifyInvalidRange(AbstractCharacter ac, + AbstractWorldObject target, float range) { + Vector3fImmutable sl = ac.getLoc(); + Vector3fImmutable tl = target.getLoc(); + if (target.getObjectType().equals(GameObjectType.Item)) { + + Item item = (Item) target; + AbstractGameObject owner = item.getOwner(); + + if (owner == null || owner.getObjectType().equals(GameObjectType.Account)) + return true; + + if (owner.getObjectType().equals(GameObjectType.PlayerCharacter) || owner.getObjectType().equals(GameObjectType.Mob)) { + AbstractCharacter acOwner = (AbstractCharacter) owner; + CharacterItemManager itemMan = acOwner.getCharItemManager(); + if (itemMan == null) + return true; + if (itemMan.inventoryContains(item)) { + tl = acOwner.getLoc(); + return !(sl.distanceSquared(tl) <= sqr(range)); + } + return true; + } + return true; + } + + range += (calcHitBox(ac) + calcHitBox(target)); + + + float distanceToTarget = sl.distanceSquared(tl);//distance to center of target + + return distanceToTarget > range * range; + + } + + public static float calcHitBox(AbstractWorldObject ac) { + //TODO Figure out how Str Affects HitBox + float hitBox = 1; + switch (ac.getObjectType()) { + case PlayerCharacter: + PlayerCharacter pc = (PlayerCharacter) ac; + if (MBServerStatics.COMBAT_TARGET_HITBOX_DEBUG) + Logger.info("Hit box radius for " + pc.getFirstName() + " is " + ((int) pc.statStrBase / 200f)); + hitBox = 2f + (int) ((PlayerCharacter) ac).statStrBase / 50f; + break; + + case Mob: + Mob mob = (Mob) ac; + if (MBServerStatics.COMBAT_TARGET_HITBOX_DEBUG) + Logger.info("Hit box radius for " + mob.getFirstName() + + " is " + ((Mob) ac).getMobBase().getHitBoxRadius()); + + hitBox = ((Mob) ac).getMobBase().getHitBoxRadius(); + break; + case Building: + Building building = (Building) ac; + if (building.getBlueprint() == null) + return 32; + hitBox = Math.max(building.getBlueprint().getBuildingGroup().getExtents().x, + building.getBlueprint().getBuildingGroup().getExtents().y); + if (MBServerStatics.COMBAT_TARGET_HITBOX_DEBUG) + Logger.info("Hit box radius for " + building.getName() + " is " + hitBox); + break; + + } + return hitBox; + } + + // Apply a power based on it's IDString + public static void applyPower(AbstractCharacter ac, AbstractWorldObject target, + Vector3fImmutable targetLoc, String ID, int trains, boolean fromItem) { + if (ac == null || target == null || !ac.isAlive()) + return; + PowersBase pb = powersBaseByIDString.get(ID); + if (pb == null) { + Logger.error( + "applyPower(): Got NULL on powersBaseByIDString table lookup for: " + + ID); + return; + } + applyPowerA(ac, target, targetLoc, pb, trains, fromItem); + } + + // Apply a power based on it's Token + public static void applyPower(AbstractCharacter ac, AbstractWorldObject target, + Vector3fImmutable targetLoc, int token, int trains, boolean fromItem) { + if (ac == null || target == null) + return; + + //Don't apply power if ac is dead, unless death shroud or safe mode + if (!ac.isAlive()) + if (!(token == -1661758934 || token == 1672601862)) + return; + + PowersBase pb = powersBaseByToken.get(token); + if (pb == null) { + Logger.error( + "applyPower(): Got NULL on powersBaseByToken table lookup for: " + + token); + return; + } + applyPowerA(ac, target, targetLoc, pb, trains, fromItem); + } + + private static void applyPowerA(AbstractCharacter ac, AbstractWorldObject target, + Vector3fImmutable targetLoc, PowersBase pb, int trains, + boolean fromItem) { + int time = pb.getCastTime(trains); + if (!fromItem) + finishApplyPowerA(ac, target, targetLoc, pb, trains, false); + else if (time == 0) + finishApplyPower(ac, target, targetLoc, pb, trains, ac.getLiveCounter()); + else { + + ac.setItemCasting(true); + int tarType = (target == null) ? 0 : target.getObjectType().ordinal(); + int tarID = (target == null) ? 0 : target.getObjectUUID(); + + // start the action animation + PerformActionMsg msg = new PerformActionMsg(pb.getToken(), + trains, ac.getObjectType().ordinal(), ac.getObjectUUID(), tarType, tarID, 0, + 0, 0, 1, 0); + DispatchMessage.sendToAllInRange(target, msg); + + + ConcurrentHashMap timers = ac.getTimers(); + + if (timers.containsKey(Integer.toString(pb.getToken()))) { + JobContainer jc = timers.get(Integer.toString(pb.getToken())); + if (jc != null) + jc.cancelJob(); + } + + // // clear any other items being used + // JobContainer jc = ac.getLastItem(); + // if (jc != null) { + // jc.cancelJob(); + // ac.clearLastItem(); + // } + // run timer job to end cast + UseItemJob uij = new UseItemJob(ac, target, pb, trains, ac.getLiveCounter()); + JobContainer jc = js.scheduleJob(uij, time); + + // make lastItem + timers.put(Integer.toString(pb.getToken()), jc); + } + } + + public static void finishApplyPower(AbstractCharacter ac, + AbstractWorldObject target, Vector3fImmutable targetLoc, + PowersBase pb, int trains, int liveCounter) { + + if (ac != null) + ac.setItemCasting(false); + if (ac == null || target == null || pb == null) + return; + + ac.clearTimer(Integer.toString(pb.getToken())); + if (liveCounter == ac.getLiveCounter()) + finishApplyPowerA(ac, target, targetLoc, pb, trains, false); + } + + public static void finishApplyPowerA(AbstractCharacter ac, + AbstractWorldObject target, Vector3fImmutable targetLoc, + PowersBase pb, int trains, boolean fromChant) { + // finally Apply actions + ArrayList actions = pb.getActions(); + for (ActionsBase ab : actions) { + // get numTrains for power, skip action if invalid + if (trains < ab.getMinTrains() || trains > ab.getMaxTrains()) + continue; + // If something blocks the action, then stop + if (ab.blocked(target, pb, trains)) + // sendPowerMsg(pc, 5, msg); + continue; + // TODO handle overwrite stack order here + String stackType = ab.getStackType(); + stackType = (stackType.equals("IgnoreStack")) ? Integer.toString(ab.getUUID()) : stackType; + if (target.getEffects().containsKey(stackType)) { + // remove any existing power that overrides + Effect ef = target.getEffects().get(stackType); + AbstractEffectJob effect = null; + if (ef != null) { + JobContainer jc = ef.getJobContainer(); + if (jc != null) + effect = (AbstractEffectJob) jc.getJob(); + } + ActionsBase overwrite = effect.getAction(); + PowersBase pbOverwrite = effect.getPower(); + if (pbOverwrite != null && pbOverwrite.equals(pb) + && (trains >= effect.getTrains())) + removeEffect(target, overwrite, true, fromChant); + else if (ab.getStackOrder() < overwrite.getStackOrder()) + continue; // not high enough to overwrite + else if (ab.getStackOrder() > overwrite.getStackOrder()) + removeEffect(target, overwrite, true, false); + else if (ab.getStackOrder() == overwrite.getStackOrder()) + if (ab.greaterThanEqual() + && (trains >= effect.getTrains())) + removeEffect(target, overwrite, true, false); + else if (ab.always()) + removeEffect(target, overwrite, true, false); + else if (ab.greaterThan() + && (trains > effect.getTrains())) + removeEffect(target, overwrite, true, false); + else if (ab.greaterThan() && pb.getToken() == effect.getPowerToken()) + removeEffect(target, overwrite, true, false); + else + continue; // trains not high enough to overwrite + } + if (fromChant) + targetLoc = Vector3fImmutable.ZERO; + runPowerAction(ac, target, targetLoc, ab, trains, pb); + } + + //Handle chant + if (pb != null && pb.isChant()) + for (ActionsBase ab : pb.getActions()) { + AbstractPowerAction pa = ab.getPowerAction(); + if (pa != null) + pa.handleChant(ac, target, targetLoc, trains, ab, pb); + } + + // for chants, only send the animation if the character is not is not moving or casting + boolean doAnimation = true; + + if (target.getObjectType().equals(GameObjectType.PlayerCharacter)) { + PlayerCharacter pc = (PlayerCharacter) target; + if (pb != null && pb.isChant() && (pc.isMoving() || pc.isCasting())) + doAnimation = false; + } + + if (pb.getToken() == 428950414) + doAnimation = true; - //group target. uses pbaoe rules - if (pb.targetGroup()) - return true; + if (doAnimation) { + PerformActionMsg msg = new PerformActionMsg(pb.getToken(), 9999, ac + .getObjectType().ordinal(), ac.getObjectUUID(), target.getObjectType().ordinal(), + target.getObjectUUID(), 0, 0, 0, 2, 0); - // target is player - else if ((target.getObjectTypeMask() & MBServerStatics.MASK_PLAYER) != 0) { - if (pb.targetPlayer()) - if (pb.isGroupOnly()) { //single target group only power - PlayerCharacter trg = (PlayerCharacter) target; - - if (GroupManager.getGroup(trg) != null && GroupManager.getGroup(pc) != null) - if (GroupManager.getGroup(trg).getObjectUUID() == GroupManager.getGroup(pc).getObjectUUID()) - return true; // both in same group, good to go - return trg != null && pc.getObjectUUID() == trg.getObjectUUID(); - } else - return true; // can target player, good to go. - else if (target.getObjectUUID() == pc.getObjectUUID() && pb.targetSelf()) - return true; // can target self, good to go - else if (pb.targetCorpse()) { - //target is dead player - PlayerCharacter trg = (PlayerCharacter) target; - return !trg.isAlive(); - } else { - PlayerCharacter trg = (PlayerCharacter) target; + DispatchMessage.sendToAllInRange(ac, msg); - if (pb.targetGroup()) - if (GroupManager.getGroup(trg) != null && GroupManager.getGroup(pc) != null) - if (GroupManager.getGroup(trg).getObjectUUID() == GroupManager.getGroup(pc) - .getObjectUUID()) - return true; // both in same group, good to go - if (pb.targetGuildLeader()) - if (pc.getGuild() != null) - if (pc.getGuild().getGuildLeaderUUID() == trg.getObjectUUID()) - return true; // can hit guild leader, good to go - } - String outmsg = "Invalid Target"; - ChatManager.chatSystemInfo(pc, outmsg); - return false; // can't target player, stop here - } // target is mob - else if ((target.getObjectTypeMask() & MBServerStatics.MASK_MOB) != 0) - return pb.targetMob(); + } + } + + public static void runPowerAction(AbstractCharacter source, + AbstractWorldObject awo, Vector3fImmutable targetLoc, + ActionsBase ab, int trains, PowersBase pb) { + AbstractPowerAction pa = ab.getPowerAction(); + if (pa == null) { + Logger.error( + "runPowerAction(): PowerAction not found of IDString: " + + ab.getEffectID()); + return; + } + pa.startAction(source, awo, targetLoc, trains, ab, pb); + } + + public static void runPowerAction(AbstractCharacter source, + AbstractWorldObject awo, Vector3fImmutable targetLoc, + ActionsBase ab, int trains, PowersBase pb, int duration) { + AbstractPowerAction pa = ab.getPowerAction(); + if (pa == null) { + Logger.error( + "runPowerAction(): PowerAction not found of IDString: " + + ab.getEffectID()); + return; + } + pa.startAction(source, awo, targetLoc, trains, ab, pb, duration); + } + + public static HashSet getAllTargets( + AbstractWorldObject target, Vector3fImmutable tl, + PlayerCharacter pc, PowersBase pb) { + HashSet allTargets; + if (pb.isAOE()) { + Vector3fImmutable targetLoc = null; + if (pb.usePointBlank()) { + targetLoc = pc.getLoc(); + } else { + if (target != null) { + targetLoc = target.getLoc(); + } else { + targetLoc = tl; + try { + targetLoc = targetLoc.setY(HeightMap.getWorldHeight(targetLoc)); //on ground + } catch (Exception e) { + Logger.error(e); + targetLoc = tl; + } + + } + } - // target is pet - else if ((target.getObjectTypeMask() & MBServerStatics.MASK_PET) != 0) - return pb.targetPet(); + if (targetLoc.x == 0f || targetLoc.z == 0f) + return new HashSet<>(); // invalid loc, + // return + // nothing + + //first find targets in range quickly with QTree + if (pb.targetPlayer() && pb.targetMob()) + // Player and mobs + allTargets = WorldGrid.getObjectsInRangePartial( + targetLoc, pb.getRadius(), MBServerStatics.MASK_MOBILE); + else if (pb.targetPlayer()) + // Player only + allTargets = WorldGrid.getObjectsInRangePartial( + targetLoc, pb.getRadius(), MBServerStatics.MASK_PLAYER); + else if (pb.targetMob()) + // Mob only + allTargets = WorldGrid.getObjectsInRangePartial( + targetLoc, pb.getRadius(), MBServerStatics.MASK_MOB + | MBServerStatics.MASK_PET); + else if (pb.targetPet()) + //Pet only + allTargets = WorldGrid.getObjectsInRangePartial( + targetLoc, pb.getRadius(), MBServerStatics.MASK_PET); + else if (pb.targetNecroPet()) + allTargets = WorldGrid.getObjectsInRangePartialNecroPets( + targetLoc, pb.getRadius()); + else + allTargets = WorldGrid.getObjectsInRangePartial( + targetLoc, pb.getRadius(), 0); + + // cleanup self, group and nation targets if needed + Iterator awolist = allTargets.iterator(); + while (awolist.hasNext()) { + AbstractWorldObject awo = awolist.next(); + if (awo == null) { + awolist.remove(); // won't hit a null + continue; + } + + //see if targets are within 3D range of each other + Vector3fImmutable tloc = awo.getLoc(); + + if (tloc.distanceSquared(targetLoc) > sqr(pb.getRadius())) { + awolist.remove(); // too far away + continue; + } + + if (pb.isCasterFriendly() && pc.equals(awo)) { + awolist.remove(); // won't hit self + continue; + } + + if (!awo.isAlive()) { + awolist.remove(); // too far away + continue; + } + + if (awo.getObjectType().equals(GameObjectType.PlayerCharacter)) { + + PlayerCharacter pcc = (PlayerCharacter) awo; + + if (pb.isGroupFriendly() && GroupManager.getGroup(pc) != null && GroupManager.getGroup(pcc) != null) + if (GroupManager.getGroup(pc).equals(GroupManager.getGroup(pcc))) { + awolist.remove(); // Won't hit group members + continue; + } + if (pb.isNationFriendly() && pc.getGuild() != null && + pc.getGuild().getNation() != null && pcc.getGuild() != null && + pc.getGuild().getNation() != null) + if (pc.getGuild().getNation().equals(pcc.getGuild().getNation())) { + awolist.remove(); // Won't hit nation members + continue; + } + + // Remove players for non-friendly spells in safe zone + if (pb.isHarmful() && (pcc.inSafeZone() || pc.inSafeZone())) { + awolist.remove(); + continue; + } + } + } + // Trim list down to max size closest targets, limited by max + // Player/Mob amounts + allTargets = RangeBasedAwo.getSortedList(allTargets, targetLoc, pb + .getMaxNumPlayerTargets(), pb.getMaxNumMobTargets()); + } else if (pb.targetGroup()) { + + if (GroupManager.getGroup(pc) != null) { + allTargets = WorldGrid.getObjectsInRangePartial(pc + .getLoc(), pb.getRange(), MBServerStatics.MASK_PLAYER); + Iterator awolist = allTargets.iterator(); + while (awolist.hasNext()) { + + AbstractWorldObject awo = awolist.next(); + + if (!(awo.getObjectType().equals(GameObjectType.PlayerCharacter))) { + awolist.remove(); // remove non players if there are any + continue; + } + PlayerCharacter pcc = (PlayerCharacter) awo; + + if (GroupManager.getGroup(pcc) == null) + awolist.remove(); // remove players not in a group + else if (!GroupManager.getGroup(pcc).equals(GroupManager.getGroup(pc))) + awolist.remove(); // remove if not same group + + } + } else { + allTargets = new HashSet<>(); + allTargets.add(pc); // no group, use only self + } + } else { + allTargets = new HashSet<>(); + if (pb.targetSelf()) + allTargets.add(pc); + else if (pb.targetFromLastTarget()) + allTargets.add(target); + else if (pb.targetFromNearbyMobs()) + allTargets.add(target); // need better way to do this later + else + // targetByName + allTargets.add(target); // need to get name later + // can't target self if caster friendly + if (pb.isCasterFriendly() && allTargets.contains(pc)) + allTargets.remove(0); + } - // target is Building - else if ((target.getObjectTypeMask() & MBServerStatics.MASK_BUILDING) != 0) - return pb.targetBuilding(); + Iterator awolist = allTargets.iterator(); + while (awolist.hasNext()) { + AbstractWorldObject awo = awolist.next(); - else if (target.getObjectType().equals(GameObjectType.Item)) { - Item item = (Item) target; - if (pb.targetItem()) - return true; - // TODO add these checks later - else if (pb.targetArmor() && item.getItemBase().getType().equals(ItemType.ARMOR)) - return true; - else if (pb.targetJewelry() && item.getItemBase().getType().equals(ItemType.JEWELRY)) - return true; - else return pb.targetWeapon() && item.getItemBase().getType().equals(ItemType.WEAPON); - } // How did we get here? all valid targets have been covered - else - return false; - } + //See if target is valid type + if (!validMonsterType(awo, pb)) { + awolist.remove(); + continue; + } - /* - * Cancel spell upon actions - */ - public static void cancelOnAttack(AbstractCharacter ac) { - ac.cancelTimer("Stuck"); - } + if (awo != null && awo.getObjectType().equals(GameObjectType.PlayerCharacter)) { - public static void cancelOnAttackSwing(AbstractCharacter ac) { - } + // Remove players who are in safe mode + PlayerCharacter pcc = (PlayerCharacter) awo; + PlayerBonuses bonuses = pcc.getBonuses(); - public static void cancelOnCast(AbstractCharacter ac) { + if (bonuses != null && bonuses.getBool(ModType.ImmuneToPowers, SourceType.None)) { + awolist.remove(); + continue; + } - } + //remove if power is harmful and caster or target is in safe zone + if (pb.isHarmful() && (pcc.inSafeZone() || pc.inSafeZone())) { + awolist.remove(); + continue; + } + } + } - public static void cancelOnSpell(AbstractCharacter ac) { + // verify target has proper effects applied to receive power + if (pb.getTargetEffectPrereqs().size() > 0) { + Iterator it = allTargets.iterator(); + while (it.hasNext()) { + boolean passed = false; + AbstractWorldObject awo = it.next(); + if (awo.getEffects() != null) { + for (PowerPrereq pp : pb.getTargetEffectPrereqs()) { + EffectsBase eb = PowersManager.getEffectByIDString(pp.getEffect()); + if (awo.containsEffect(eb.getToken())) { + passed = true; + break; + } + } + if (!passed) + it.remove(); + } else + it.remove(); //awo is missing it's effects list + } + } + return allTargets; + } + + public static HashSet getAllTargets( + AbstractWorldObject target, Vector3fImmutable tl, + AbstractCharacter caster, PowersBase pb) { + HashSet allTargets; + if (pb.isAOE()) { + Vector3fImmutable targetLoc = tl; + if (pb.usePointBlank()) { + targetLoc = caster.getLoc(); + } else { + if (target != null) { + targetLoc = target.getLoc(); + } else { + targetLoc = tl; + try { + targetLoc = targetLoc.setY(HeightMap.getWorldHeight(targetLoc)); //on ground + } catch (Exception e) { + Logger.error(e); + } + + } + } - PowersBase power = getLastPower(ac); + if (targetLoc.x == 0f || targetLoc.z == 0f) + return new HashSet<>(); // invalid loc, + + //first find targets in range quickly with QTree + if (pb.targetPlayer() && pb.targetMob()) + // Player and mobs + allTargets = WorldGrid.getObjectsInRangePartial( + targetLoc, pb.getRadius(), MBServerStatics.MASK_MOBILE); + else if (pb.targetPlayer()) + // Player only + allTargets = WorldGrid.getObjectsInRangePartial( + targetLoc, pb.getRadius(), MBServerStatics.MASK_PLAYER); + else if (pb.targetMob()) + // Mob only + allTargets = WorldGrid.getObjectsInRangePartial( + targetLoc, pb.getRadius(), MBServerStatics.MASK_MOB + | MBServerStatics.MASK_PET); + else if (pb.targetPet()) + //Pet only + allTargets = WorldGrid.getObjectsInRangePartial( + targetLoc, pb.getRadius(), MBServerStatics.MASK_PET); + else if (pb.targetNecroPet()) + allTargets = WorldGrid.getObjectsInRangePartialNecroPets( + targetLoc, pb.getRadius()); + else + allTargets = WorldGrid.getObjectsInRangePartial( + targetLoc, pb.getRadius(), 0); + + // cleanup self, group and nation targets if needed + Iterator awolist = allTargets.iterator(); + while (awolist.hasNext()) { + AbstractWorldObject awo = awolist.next(); + if (awo == null) { + awolist.remove(); // won't hit a null + continue; + } + + //see if targets are within 3D range of each other + Vector3fImmutable tloc = awo.getLoc(); + + if (tloc.distanceSquared(targetLoc) > sqr(pb.getRadius())) { + awolist.remove(); // too far away + continue; + } + + if (pb.isCasterFriendly() && caster.equals(awo)) { + awolist.remove(); // won't hit self + continue; + } + + if (awo.getObjectType() == GameObjectType.Mob) { + awolist.remove(); // Won't hit other mobs. + continue; + } + } + // Trim list down to max size closest targets, limited by max + // Player/Mob amounts + allTargets = RangeBasedAwo.getSortedList(allTargets, targetLoc, pb + .getMaxNumPlayerTargets(), pb.getMaxNumMobTargets()); + } else if (pb.targetGroup()) { + allTargets = new HashSet<>(); + allTargets.add(caster); // no group, use only self + } else { + allTargets = new HashSet<>(); + if (pb.targetSelf()) + allTargets.add(caster); + else if (pb.targetFromLastTarget()) + allTargets.add(target); + else if (pb.targetFromNearbyMobs()) + allTargets.add(target); // need better way to do this later + else + // targetByName + allTargets.add(target); // need to get name later + // can't target self if caster friendly + if (pb.isCasterFriendly() && allTargets.contains(caster)) + allTargets.remove(caster); + } - if (power != null && power.cancelOnCastSpell()) - cancelPower(ac, false); - ac.cancelLastChant(); - } + Iterator awolist = allTargets.iterator(); + while (awolist.hasNext()) { + AbstractWorldObject awo = awolist.next(); - public static void cancelOnEquipChange(AbstractCharacter ac) { + //See if target is valid type + if (!validMonsterType(awo, pb)) { + awolist.remove(); + continue; + } - } + if (awo != null && awo.getObjectType().equals(GameObjectType.PlayerCharacter)) { + // Remove players who are in safe mode + PlayerCharacter pcc = (PlayerCharacter) awo; + PlayerBonuses bonuses = pcc.getBonuses(); + if (bonuses != null && bonuses.getBool(ModType.ImmuneToPowers, SourceType.None)) { + awolist.remove(); + continue; + } + } + } - public static void cancelOnLogout(AbstractCharacter ac) { + // verify target has proper effects applied to receive power + if (pb.getTargetEffectPrereqs().size() > 0) { + Iterator it = allTargets.iterator(); + while (it.hasNext()) { + boolean passed = false; + AbstractWorldObject awo = it.next(); + if (awo.getEffects() != null) { + for (PowerPrereq pp : pb.getTargetEffectPrereqs()) { + EffectsBase eb = PowersManager.getEffectByIDString(pp.getEffect()); + if (awo.containsEffect(eb.getToken())) { + passed = true; + break; + } + } + if (!passed) + it.remove(); + } else + it.remove(); //awo is missing it's effects list + } + } + return allTargets; + } + + // removes an effect before time is finished + public static void removeEffect(AbstractWorldObject awo, ActionsBase toRemove, + boolean overwrite, boolean fromChant) { + if (toRemove == null) + return; + + String stackType = toRemove.getStackType(); + stackType = (stackType.equals("IgnoreStack")) ? Integer + .toString(toRemove.getUUID()) : stackType; + if (fromChant) { + Effect eff = awo.getEffects().get(stackType); + if (eff != null) + eff.cancelJob(true); + } else + awo.cancelEffect(stackType, overwrite); + } + + // removes an effect when timer finishes + public static void finishEffectTime(AbstractWorldObject source, + AbstractWorldObject awo, ActionsBase toRemove, int trains) { + if (awo == null || toRemove == null) + return; + + // remove effect from player + String stackType = toRemove.getStackType(); + if (stackType.equals("IgnoreStack")) + stackType = Integer.toString(toRemove.getUUID()); + awo.endEffect(stackType); + } + + // removes an effect when timer is canceled + public static void cancelEffectTime(AbstractWorldObject source, + AbstractWorldObject awo, PowersBase pb, EffectsBase eb, + ActionsBase toRemove, int trains, AbstractEffectJob efj) { + if (awo == null || pb == null || eb == null || toRemove == null) + return; + eb.endEffect(source, awo, trains, pb, efj); + } + + // called when cooldown ends letting player cast next spell + public static void finishCooldownTime(PerformActionMsg msg, PlayerCharacter pc) { + // clear spell so player can cast again + // if (pc != null) + // pc.clearLastPower(); + } + + // called when recycle time ends letting player cast spell again + public static void finishRecycleTime(PerformActionMsg msg, PlayerCharacter pc, + boolean canceled) { + finishRecycleTime(msg.getPowerUsedID(), pc, canceled); + } + + public static void finishRecycleTime(int token, PlayerCharacter pc, + boolean canceled) { + if (pc == null) + return; + + ConcurrentHashMap recycleTimers = pc + .getRecycleTimers(); + // clear recycle time + if (recycleTimers != null) + if (recycleTimers.containsKey(token)) { + if (canceled) { + JobContainer jc = recycleTimers.get(token); + if (jc != null) + jc.cancelJob(); + } + recycleTimers.remove(token); + } - } + // send recycle message to unlock power - public static void cancelOnMove(AbstractCharacter ac) { + RecyclePowerMsg recyclePowerMsg = new RecyclePowerMsg(token); + Dispatch dispatch = Dispatch.borrow(pc, recyclePowerMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - PowersBase power = getLastPower(ac); + } - if (power != null && !power.canCastWhileMoving()) - cancelPower(ac, false); + // Called when a fail condition is met by player + // such as moving, taking damage, ect. - //cancel items - cancelItems(ac, true, false); - ac.cancelTimer("Stuck"); - } - - + public static void cancelUseLastPower(PlayerCharacter pc) { - public static void cancelOnNewCharm(AbstractCharacter ac) { + if (pc == null) + return; - } + // set player is not casting for regens + if (pc.isCasting()) { + pc.update(); + } + pc.setIsCasting(false); - public static void cancelOnSit(AbstractCharacter ac) { - cancelPower(ac, false); // Always cancel casts on sit - } + UsePowerJob lastPower = null; + JobContainer jc = pc.getLastPower(); - public static void cancelOnTakeDamage(AbstractCharacter ac) { + if (jc != null) + lastPower = ((UsePowerJob) jc.getJob()); - PowersBase power = getLastPower(ac); + if (lastPower == null) + return; - if (power != null && power.cancelOnTakeDamage()) - cancelPower(ac, true); - cancelItems(ac, false, true); - ac.cancelTimer("Stuck"); - } + // clear recycle timer + int token = lastPower.getToken(); - public static void cancelOnTerritoryClaim(AbstractCharacter ac) { + if (pc.getRecycleTimers().contains(token)) + finishRecycleTime(token, pc, true); - } + // pc.getRecycleTimers().remove(token); + // Cancel power + js.cancelScheduledJob(lastPower); - public static void cancelOnUnEquip(AbstractCharacter ac) { + // clear last power + pc.clearLastPower(); - } + } - public static void cancelOnStun(AbstractCharacter ac) { + private static AbstractWorldObject getTarget(PerformActionMsg msg) { - } + int type = msg.getTargetType(); + int UUID = msg.getTargetID(); - private static PowersBase getLastPower(AbstractCharacter ac) { - if (ac == null) - return null; + if (type == -1 || type == 0 || UUID == -1 || UUID == 0) + return null; - JobContainer jc = ac.getLastPower(); + return (AbstractWorldObject) DbManager.getObject(GameObjectType.values()[type], UUID); + } - if (jc == null) - return null; + public static boolean testAttack(PlayerCharacter pc, AbstractWorldObject awo, + PowersBase pb, PerformActionMsg msg) { + // Get defense for target + float atr = CharacterSkill.getATR(pc, pb.getSkillName()); + float defense; - AbstractJob aj = jc.getJob(); + if (AbstractWorldObject.IsAbstractCharacter(awo)) { + AbstractCharacter tar = (AbstractCharacter) awo; + defense = tar.getDefenseRating(); + } else + defense = 0f; + // Get hit chance - if (aj == null) - return null; + if (pc.getDebug(16)) { + String smsg = "ATR: " + atr + ", Defense: " + defense; + ChatManager.chatSystemInfo(pc, smsg); + } - if (aj instanceof UsePowerJob) { - UsePowerJob upj = (UsePowerJob) aj; - return upj.getPowersBase(); - } - return null; - } + int chance; - private static PowersBase getLastItem(AbstractCharacter ac) { + if (atr > defense || defense == 0) + chance = 94; + else { + float dif = atr / defense; + if (dif <= 0.8f) + chance = 4; + else + chance = ((int) (450 * (dif - 0.8f)) + 4); + } - if (ac == null) - return null; + // calculate hit/miss + int roll = ThreadLocalRandom.current().nextInt(100); + + boolean disable = true; + if (roll < chance) { + // Hit, check if dodge kicked in + if (awo instanceof AbstractCharacter) { + AbstractCharacter tarAc = (AbstractCharacter) awo; + // Handle Dodge passive + if (testPassive(pc, tarAc, "Dodge")) { + // Dodge fired, send dodge message + PerformActionMsg dodgeMsg = new PerformActionMsg(msg); + dodgeMsg.setTargetType(awo.getObjectType().ordinal()); + dodgeMsg.setTargetID(awo.getObjectUUID()); + sendPowerMsg(pc, 4, dodgeMsg); + return true; + } + } + return false; + } else { + // Miss. Send miss message + PerformActionMsg missMsg = new PerformActionMsg(msg); + + missMsg.setTargetType(awo.getObjectType().ordinal()); + missMsg.setTargetID(awo.getObjectUUID()); + sendPowerMsg(pc, 3, missMsg); + return true; + } + } + + public static boolean testAttack(Mob caster, AbstractWorldObject awo, + PowersBase pb, PerformActionMsg msg) { + // Get defense for target + float atr = 2000; + float defense; + + if (AbstractWorldObject.IsAbstractCharacter(awo)) { + AbstractCharacter tar = (AbstractCharacter) awo; + defense = tar.getDefenseRating(); + } else + defense = 0f; + // Get hit chance + + int chance; + + if (atr > defense || defense == 0) + chance = 94; + else { + float dif = atr / defense; + if (dif <= 0.8f) + chance = 4; + else + chance = ((int) (450 * (dif - 0.8f)) + 4); + } - JobContainer jc = ac.getLastItem(); + // calculate hit/miss + int roll = ThreadLocalRandom.current().nextInt(100); - if (jc == null) - return null; + if (roll < chance) { + // Hit, check if dodge kicked in + if (AbstractWorldObject.IsAbstractCharacter(awo)) { + AbstractCharacter tarAc = (AbstractCharacter) awo; + // Handle Dodge passive + return testPassive(caster, tarAc, "Dodge"); + } + return false; + } else + return true; + } + + public static void sendPowerMsg(PlayerCharacter playerCharacter, int type, PerformActionMsg msg) { + + if (playerCharacter == null) + return; + + msg.setUnknown05(type); + + switch (type) { + case 3: + case 4: + msg.setUnknown04(2); + DispatchMessage.dispatchMsgToInterestArea(playerCharacter, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + break; + default: + msg.setUnknown04(1); + Dispatch dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + } + } - AbstractJob aj = jc.getJob(); + public static void sendEffectMsg(PlayerCharacter pc, int type, ActionsBase ab, PowersBase pb) { - if (aj == null) - return null; + if (pc == null) + return; - if (aj instanceof UseItemJob) { - UseItemJob uij = (UseItemJob) aj; - return uij.getPowersBase(); - } - return null; - } + try { - //cancels last casted power - private static void cancelPower(AbstractCharacter ac, boolean cancelCastAnimation) { + EffectsBase eb = PowersManager.effectsBaseByIDString.get(ab.getEffectID()); - if (ac == null) - return; + if (eb == null) + return; - JobContainer jc = ac.getLastPower(); + ApplyEffectMsg aem = new ApplyEffectMsg(pc, pc, 0, eb.getToken(), 9, pb.getToken(), pb.getName()); + aem.setUnknown03(type); + DispatchMessage.dispatchMsgToInterestArea(pc, aem, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - if (jc == null) - return; - AbstractJob aj = jc.getJob(); + } catch (Exception e) { + Logger.error(e.getMessage()); + } - if (aj == null) - return; + } - if (aj instanceof AbstractScheduleJob) - ((AbstractScheduleJob) aj).cancelJob(); + public static void sendEffectMsg(PlayerCharacter pc, int type, EffectsBase eb) { - ac.clearLastPower(); + if (pc == null) + return; + try { - //clear cast animation for everyone in view range - if (aj instanceof UsePowerJob && cancelCastAnimation) { + if (eb == null) + return; + ApplyEffectMsg aem = new ApplyEffectMsg(pc, pc, 0, eb.getToken(), 0, eb.getToken(), ""); + aem.setUnknown03(type); + aem.setUnknown05(1); - PerformActionMsg pam = ((UsePowerJob) aj).getMsg(); + DispatchMessage.dispatchMsgToInterestArea(pc, aem, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + + + } catch (Exception e) { + Logger.error(e.getMessage()); + } - if (pam != null) { - pam.setNumTrains(9999); - pam.setUnknown04(2); - DispatchMessage.sendToAllInRange(ac, pam); - } - } - } + } - public static PerformActionMsg createPowerMsg(PowersBase pb, int trains, AbstractCharacter source, AbstractCharacter target) { - return new PerformActionMsg(pb.getToken(), trains, source.getObjectType().ordinal(), source.getObjectUUID(), target.getObjectType().ordinal(), target.getObjectUUID(), target.getLoc().x, target.getLoc().y, target.getLoc().z, 0, 0); + public static void sendMobPowerMsg(Mob mob, int type, PerformActionMsg msg) { - } + msg.setUnknown05(type); + switch (type) { + case 3: + case 4: + DispatchMessage.sendToAllInRange(mob, msg); + + } + } + + private static boolean testPassive(AbstractCharacter source, + AbstractCharacter target, String type) { + + float chance = target.getPassiveChance(type, source.getLevel(), false); + + if (chance == 0f) + return false; + + // max 75% chance of passive to fire + if (chance > 75f) + chance = 75f; + + int roll = ThreadLocalRandom.current().nextInt(100); + // Passive fired + // TODO send message + // Passive did not fire + return roll < chance; + } + + private static boolean validateTarget(AbstractWorldObject target, + PlayerCharacter pc, PowersBase pb) { + + //group target. uses pbaoe rules + if (pb.targetGroup()) + return true; + + // target is player + else if ((target.getObjectTypeMask() & MBServerStatics.MASK_PLAYER) != 0) { + if (pb.targetPlayer()) + if (pb.isGroupOnly()) { //single target group only power + PlayerCharacter trg = (PlayerCharacter) target; + + if (GroupManager.getGroup(trg) != null && GroupManager.getGroup(pc) != null) + if (GroupManager.getGroup(trg).getObjectUUID() == GroupManager.getGroup(pc).getObjectUUID()) + return true; // both in same group, good to go + return trg != null && pc.getObjectUUID() == trg.getObjectUUID(); + } else + return true; // can target player, good to go. + else if (target.getObjectUUID() == pc.getObjectUUID() && pb.targetSelf()) + return true; // can target self, good to go + else if (pb.targetCorpse()) { + //target is dead player + PlayerCharacter trg = (PlayerCharacter) target; + return !trg.isAlive(); + } else { + PlayerCharacter trg = (PlayerCharacter) target; + + if (pb.targetGroup()) + if (GroupManager.getGroup(trg) != null && GroupManager.getGroup(pc) != null) + if (GroupManager.getGroup(trg).getObjectUUID() == GroupManager.getGroup(pc) + .getObjectUUID()) + return true; // both in same group, good to go + if (pb.targetGuildLeader()) + if (pc.getGuild() != null) + if (pc.getGuild().getGuildLeaderUUID() == trg.getObjectUUID()) + return true; // can hit guild leader, good to go + } + String outmsg = "Invalid Target"; + ChatManager.chatSystemInfo(pc, outmsg); + return false; // can't target player, stop here + } // target is mob + else if ((target.getObjectTypeMask() & MBServerStatics.MASK_MOB) != 0) + return pb.targetMob(); + + // target is pet + else if ((target.getObjectTypeMask() & MBServerStatics.MASK_PET) != 0) + return pb.targetPet(); + + // target is Building + else if ((target.getObjectTypeMask() & MBServerStatics.MASK_BUILDING) != 0) + return pb.targetBuilding(); + + else if (target.getObjectType().equals(GameObjectType.Item)) { + Item item = (Item) target; + if (pb.targetItem()) + return true; + // TODO add these checks later + else if (pb.targetArmor() && item.getItemBase().getType().equals(ItemType.ARMOR)) + return true; + else if (pb.targetJewelry() && item.getItemBase().getType().equals(ItemType.JEWELRY)) + return true; + else + return pb.targetWeapon() && item.getItemBase().getType().equals(ItemType.WEAPON); + } // How did we get here? all valid targets have been covered + else + return false; + } - //cancels any casts from using an item + /* + * Cancel spell upon actions + */ + public static void cancelOnAttack(AbstractCharacter ac) { + ac.cancelTimer("Stuck"); + } - private static void cancelItems(AbstractCharacter ac, boolean cancelOnMove, boolean cancelOnTakeDamage) { - JobContainer jc; - AbstractJob aj; - ConcurrentHashMap timers; - UseItemJob uij; - PowersBase pb; - AbstractWorldObject target; + public static void cancelOnAttackSwing(AbstractCharacter ac) { + } - if (ac == null) - return; + public static void cancelOnCast(AbstractCharacter ac) { - timers = ac.getTimers(); + } - if (timers == null) - return; + public static void cancelOnSpell(AbstractCharacter ac) { - for (String name : timers.keySet()) { + PowersBase power = getLastPower(ac); - jc = timers.get(name); + if (power != null && power.cancelOnCastSpell()) + cancelPower(ac, false); + ac.cancelLastChant(); + } - if (jc == null) - continue; + public static void cancelOnEquipChange(AbstractCharacter ac) { - aj = jc.getJob(); + } - if (aj != null && aj instanceof UseItemJob) { - uij = (UseItemJob) aj; - pb = uij.getPowersBase(); + public static void cancelOnLogout(AbstractCharacter ac) { - if (pb == null) - continue; + } - if (!pb.canCastWhileMoving() && cancelOnMove) { - uij.cancelJob(); - timers.remove(name); - continue; - } + public static void cancelOnMove(AbstractCharacter ac) { - if ((pb.cancelOnTakeDamage() == false) && - (cancelOnTakeDamage == false)) - continue; + PowersBase power = getLastPower(ac); - uij.cancelJob(); - timers.remove(name); + if (power != null && !power.canCastWhileMoving()) + cancelPower(ac, false); - //clear cast animation for everyone in view range - target = uij.getTarget(); + //cancel items + cancelItems(ac, true, false); + ac.cancelTimer("Stuck"); + } - if (target != null) { - PerformActionMsg pam = new PerformActionMsg(pb.getToken(), 9999, ac - .getObjectType().ordinal(), ac.getObjectUUID(), target.getObjectType().ordinal(), - target.getObjectUUID(), 0, 0, 0, 2, 0); - DispatchMessage.sendToAllInRange(ac, pam); - } - } - } - } - public static void LoadAllMobPowers(){ + public static void cancelOnNewCharm(AbstractCharacter ac) { - int count = 0; + } - for(AbstractGameObject mobBaseAgo : DbManager.getList(GameObjectType.MobBase)){ + public static void cancelOnSit(AbstractCharacter ac) { + cancelPower(ac, false); // Always cancel casts on sit + } - int mobBaseID = ((MobBase) mobBaseAgo).getLoadID(); + public static void cancelOnTakeDamage(AbstractCharacter ac) { - HashMap powersList = DbManager.MobBaseQueries.LOAD_STATIC_POWERS(mobBaseID); + PowersBase power = getLastPower(ac); - if (powersList.isEmpty()) - continue;; + if (power != null && power.cancelOnTakeDamage()) + cancelPower(ac, true); + cancelItems(ac, false, true); + ac.cancelTimer("Stuck"); + } - AllMobPowers.put(mobBaseID, powersList); - count ++; - } + public static void cancelOnTerritoryClaim(AbstractCharacter ac) { + + } + + public static void cancelOnUnEquip(AbstractCharacter ac) { + + } + + public static void cancelOnStun(AbstractCharacter ac) { + + } + + private static PowersBase getLastPower(AbstractCharacter ac) { + if (ac == null) + return null; + + JobContainer jc = ac.getLastPower(); + + if (jc == null) + return null; + + AbstractJob aj = jc.getJob(); + + if (aj == null) + return null; + + if (aj instanceof UsePowerJob) { + UsePowerJob upj = (UsePowerJob) aj; + return upj.getPowersBase(); + } + return null; + } + + private static PowersBase getLastItem(AbstractCharacter ac) { + + if (ac == null) + return null; + + JobContainer jc = ac.getLastItem(); + + if (jc == null) + return null; + + AbstractJob aj = jc.getJob(); + + if (aj == null) + return null; + + if (aj instanceof UseItemJob) { + UseItemJob uij = (UseItemJob) aj; + return uij.getPowersBase(); + } + return null; + } + + //cancels last casted power + private static void cancelPower(AbstractCharacter ac, boolean cancelCastAnimation) { + + if (ac == null) + return; + + JobContainer jc = ac.getLastPower(); + + if (jc == null) + return; + + AbstractJob aj = jc.getJob(); + + if (aj == null) + return; + + if (aj instanceof AbstractScheduleJob) + ((AbstractScheduleJob) aj).cancelJob(); + + ac.clearLastPower(); + + //clear cast animation for everyone in view range + if (aj instanceof UsePowerJob && cancelCastAnimation) { + + PerformActionMsg pam = ((UsePowerJob) aj).getMsg(); + + if (pam != null) { + pam.setNumTrains(9999); + pam.setUnknown04(2); + DispatchMessage.sendToAllInRange(ac, pam); + } + } + } + + public static PerformActionMsg createPowerMsg(PowersBase pb, int trains, AbstractCharacter source, AbstractCharacter target) { + return new PerformActionMsg(pb.getToken(), trains, source.getObjectType().ordinal(), source.getObjectUUID(), target.getObjectType().ordinal(), target.getObjectUUID(), target.getLoc().x, target.getLoc().y, target.getLoc().z, 0, 0); + + } + + //cancels any casts from using an item + + private static void cancelItems(AbstractCharacter ac, boolean cancelOnMove, boolean cancelOnTakeDamage) { + JobContainer jc; + AbstractJob aj; + ConcurrentHashMap timers; + UseItemJob uij; + PowersBase pb; + AbstractWorldObject target; + + if (ac == null) + return; + + timers = ac.getTimers(); + + if (timers == null) + return; + + for (String name : timers.keySet()) { + + jc = timers.get(name); + + if (jc == null) + continue; + + aj = jc.getJob(); + + if (aj != null && aj instanceof UseItemJob) { + uij = (UseItemJob) aj; + pb = uij.getPowersBase(); + + if (pb == null) + continue; + + if (!pb.canCastWhileMoving() && cancelOnMove) { + uij.cancelJob(); + timers.remove(name); + continue; + } + + if ((pb.cancelOnTakeDamage() == false) && + (cancelOnTakeDamage == false)) + continue; + + uij.cancelJob(); + timers.remove(name); + + //clear cast animation for everyone in view range + target = uij.getTarget(); + + if (target != null) { + PerformActionMsg pam = new PerformActionMsg(pb.getToken(), 9999, ac + .getObjectType().ordinal(), ac.getObjectUUID(), target.getObjectType().ordinal(), + target.getObjectUUID(), 0, 0, 0, 2, 0); + DispatchMessage.sendToAllInRange(ac, pam); + + } + } + } + } + + public static void LoadAllMobPowers() { + + int count = 0; + + for (AbstractGameObject mobBaseAgo : DbManager.getList(GameObjectType.MobBase)) { + + int mobBaseID = ((MobBase) mobBaseAgo).getLoadID(); + + HashMap powersList = DbManager.MobBaseQueries.LOAD_STATIC_POWERS(mobBaseID); + + if (powersList.isEmpty()) + continue; + ; + + AllMobPowers.put(mobBaseID, powersList); + count++; + } - Logger.info("Powers loaded for " + count + " Mobbases/"); - } + Logger.info("Powers loaded for " + count + " Mobbases/"); + } } diff --git a/src/engine/gameManager/SessionManager.java b/src/engine/gameManager/SessionManager.java index 10682986..d7032bca 100644 --- a/src/engine/gameManager/SessionManager.java +++ b/src/engine/gameManager/SessionManager.java @@ -25,265 +25,262 @@ import java.util.concurrent.ConcurrentHashMap; public enum SessionManager { - SESSIONMANAGER; - - // TODO add session activity timestamping & timeout monitors - - private static ConcurrentHashMap sessionIDtoSession = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_HIGH); - private static ConcurrentHashMap pcToSession = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_HIGH); - private static ConcurrentHashMap accountToSession = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_HIGH); - private static ConcurrentHashMap connToSession = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_HIGH); - public static int _maxPopulation = 0; - - // 0 = login server - // 1 = gateway server - // 2 = all other servers - private static int crossServerBehavior = 2; - - public static Session getNewSession(SessionID sesID, Account a, ClientConnection c) { - Session ses = new Session(sesID, a, c); - - SessionManager.sessionIDtoSession.put(sesID, ses); - SessionManager.accountToSession.put(a, ses); - SessionManager.connToSession.put(c, ses); - - if (crossServerBehavior == 0) - if (!CSSession.addCrossServerSession(ByteUtils.byteArrayToSafeStringHex(c.getSecretKeyBytes()), a, c.getSocketChannel() - .socket().getInetAddress(), c.machineID)) - Logger.warn("Failed to create cross server session: " + a.getUname()); - - return ses; - } - - public static Session getNewSession(Account a, ClientConnection c) { - SessionID sesID = c.getSessionID(); - return SessionManager.getNewSession(sesID, a, c); - } - - - public static void cSessionCleanup(String key) { - if (!CSSession.deleteCrossServerSession(key)) - Logger.warn( - "Failed to remove cross server session for key: " + key); - } - - public static void remSession(Session s) { - - if (s == null) { - return; - } - - SessionManager.remSessionID(s); - SessionManager.remAccount(s); - SessionManager.remClientConnection(s); - SessionManager.remPlayerCharacter(s); - - //TODO LATER fix - s.setAccount(null); - s.setConn(null); - s.setPlayerCharacter(null); - s.setSessionID(null); - } - - /* - * Get Sessions - */ - public static Session getSession(SessionID id) { - return SessionManager.sessionIDtoSession.get(id); - } - - public static Session getSession(PlayerCharacter pc) { - return SessionManager.pcToSession.get(pc); - } - - public static Session getSession(Account a) { - return SessionManager.accountToSession.get(a); - } - - public static Session getSession(ClientConnection cc) { - return SessionManager.connToSession.get(cc); - } - - /* - * Get Connections - */ - public static ClientConnection getClientConnection(SessionID id) { - Session s = SessionManager.getSession(id); - return (s == null) ? null : s.getConn(); - } - - public static ClientConnection getClientConnection(PlayerCharacter pc) { - Session s = SessionManager.getSession(pc); - return (s == null) ? null : s.getConn(); - } - - public static ClientConnection getClientConnection(Account a) { - Session s = SessionManager.getSession(a); - return (s == null) ? null : s.getConn(); - } - - /* - * Get PlayerCharacter - */ - public static PlayerCharacter getPlayerCharacter(SessionID id) { - Session s = SessionManager.getSession(id); - return (s == null) ? null : s.getPlayerCharacter(); - } - - public static PlayerCharacter getPlayerCharacter(ClientConnection conn) { - Session s = SessionManager.getSession(conn); - return (s == null) ? null : s.getPlayerCharacter(); - } - - public static PlayerCharacter getPlayerCharacter(Account a) { - Session s = SessionManager.getSession(a); - return (s == null) ? null : s.getPlayerCharacter(); - } - - /* - * Get Account - */ - public static Account getAccount(SessionID id) { - Session s = SessionManager.getSession(id); - return (s == null) ? null : s.getAccount(); - } - - public static Account getAccount(ClientConnection conn) { - Session s = SessionManager.getSession(conn); - return (s == null) ? null : s.getAccount(); - } - - public static Account getAccount(PlayerCharacter pc) { - Session s = SessionManager.getSession(pc); - return (s == null) ? null : s.getAccount(); - } - - public static void setPlayerCharacter(Session s, PlayerCharacter pc) { - SessionManager.pcToSession.put(pc, s); - s.setPlayerCharacter(pc); - - // Update max player - SessionManager._maxPopulation = Math.max(_maxPopulation, SessionManager.pcToSession.size()); - - } - - public static void remPlayerCharacter(Session s) { - if (s.getPlayerCharacter() != null) { - SessionManager.pcToSession.remove(s.getPlayerCharacter()); - s.setPlayerCharacter(null); - } - } - - protected static void remAccount(Session s) { - if (s.getAccount() != null) { - SessionManager.accountToSession.remove(s.getAccount()); - s.setAccount(null); - } - } - - protected static void remSessionID(Session s) { - - if (s.getSessionID() != null) { - SessionManager.sessionIDtoSession.remove(s.getSessionID()); - s.setSessionID(null); - } - } - - protected static void remClientConnection(Session s) { - if (s.getConn() != null) { - SessionManager.connToSession.remove(s.getConn()); - s.setConn(null); - } - } - - - - /* - * Utils - */ - - public static void setCrossServerBehavior(int type) { - crossServerBehavior = type; - } - - /** - * - * @return a new HashSet object so the caller cannot - * modify the internal Set - */ - public static Collection getAllActiveClientConnections() { - return SessionManager.connToSession.keySet(); - } - - /** - * - * @return a new HashSet object so the caller cannot modify - * the internal Set - */ - public static Collection getAllActivePlayerCharacters() { - - return SessionManager.pcToSession.keySet(); - } - - public static Collection getAllActivePlayers() { - - return SessionManager.pcToSession.keySet(); - } - - public static int getActivePlayerCharacterCount() { - - return SessionManager.pcToSession.keySet().size(); - } - - public static ArrayList getActivePCsInGuildID(int id) { - ArrayList pcs = new ArrayList<>(); - - for (PlayerCharacter pc : SessionManager.getAllActivePlayerCharacters()) { - Guild g = pc.getGuild(); - if (g != null && g.getObjectUUID() == id) { - pcs.add(pc); - } - } - - return pcs; - } - - public static PlayerCharacter getPlayerCharacterByLowerCaseName(String name) { - - String queryName = name.toLowerCase(); - - for (PlayerCharacter playerCharacter : SessionManager.getAllActivePlayerCharacters()) { - - if ((playerCharacter.getFirstName().toLowerCase()).equals(queryName)) { - return playerCharacter; - } - } - return null; - } - - public static PlayerCharacter getPlayerCharacterByID(int UUID) { - - for (PlayerCharacter playerCharacter : SessionManager.getAllActivePlayerCharacters()) { - - if (playerCharacter.getObjectUUID() == UUID) { - return playerCharacter; - } - } - return null; - } + SESSIONMANAGER; + + // TODO add session activity timestamping & timeout monitors + + public static int _maxPopulation = 0; + private static ConcurrentHashMap sessionIDtoSession = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_HIGH); + private static ConcurrentHashMap pcToSession = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_HIGH); + private static ConcurrentHashMap accountToSession = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_HIGH); + private static ConcurrentHashMap connToSession = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_HIGH); + // 0 = login server + // 1 = gateway server + // 2 = all other servers + private static int crossServerBehavior = 2; + + public static Session getNewSession(SessionID sesID, Account a, ClientConnection c) { + Session ses = new Session(sesID, a, c); + + SessionManager.sessionIDtoSession.put(sesID, ses); + SessionManager.accountToSession.put(a, ses); + SessionManager.connToSession.put(c, ses); + + if (crossServerBehavior == 0) + if (!CSSession.addCrossServerSession(ByteUtils.byteArrayToSafeStringHex(c.getSecretKeyBytes()), a, c.getSocketChannel() + .socket().getInetAddress(), c.machineID)) + Logger.warn("Failed to create cross server session: " + a.getUname()); + + return ses; + } + + public static Session getNewSession(Account a, ClientConnection c) { + SessionID sesID = c.getSessionID(); + return SessionManager.getNewSession(sesID, a, c); + } + + + public static void cSessionCleanup(String key) { + if (!CSSession.deleteCrossServerSession(key)) + Logger.warn( + "Failed to remove cross server session for key: " + key); + } + + public static void remSession(Session s) { + + if (s == null) { + return; + } + + SessionManager.remSessionID(s); + SessionManager.remAccount(s); + SessionManager.remClientConnection(s); + SessionManager.remPlayerCharacter(s); + + //TODO LATER fix + s.setAccount(null); + s.setConn(null); + s.setPlayerCharacter(null); + s.setSessionID(null); + } + + /* + * Get Sessions + */ + public static Session getSession(SessionID id) { + return SessionManager.sessionIDtoSession.get(id); + } + + public static Session getSession(PlayerCharacter pc) { + return SessionManager.pcToSession.get(pc); + } + + public static Session getSession(Account a) { + return SessionManager.accountToSession.get(a); + } + + public static Session getSession(ClientConnection cc) { + return SessionManager.connToSession.get(cc); + } + + /* + * Get Connections + */ + public static ClientConnection getClientConnection(SessionID id) { + Session s = SessionManager.getSession(id); + return (s == null) ? null : s.getConn(); + } + + public static ClientConnection getClientConnection(PlayerCharacter pc) { + Session s = SessionManager.getSession(pc); + return (s == null) ? null : s.getConn(); + } + + public static ClientConnection getClientConnection(Account a) { + Session s = SessionManager.getSession(a); + return (s == null) ? null : s.getConn(); + } + + /* + * Get PlayerCharacter + */ + public static PlayerCharacter getPlayerCharacter(SessionID id) { + Session s = SessionManager.getSession(id); + return (s == null) ? null : s.getPlayerCharacter(); + } + + public static PlayerCharacter getPlayerCharacter(ClientConnection conn) { + Session s = SessionManager.getSession(conn); + return (s == null) ? null : s.getPlayerCharacter(); + } + + public static PlayerCharacter getPlayerCharacter(Account a) { + Session s = SessionManager.getSession(a); + return (s == null) ? null : s.getPlayerCharacter(); + } + + /* + * Get Account + */ + public static Account getAccount(SessionID id) { + Session s = SessionManager.getSession(id); + return (s == null) ? null : s.getAccount(); + } + + public static Account getAccount(ClientConnection conn) { + Session s = SessionManager.getSession(conn); + return (s == null) ? null : s.getAccount(); + } + + public static Account getAccount(PlayerCharacter pc) { + Session s = SessionManager.getSession(pc); + return (s == null) ? null : s.getAccount(); + } + + public static void setPlayerCharacter(Session s, PlayerCharacter pc) { + SessionManager.pcToSession.put(pc, s); + s.setPlayerCharacter(pc); + + // Update max player + SessionManager._maxPopulation = Math.max(_maxPopulation, SessionManager.pcToSession.size()); + + } + + public static void remPlayerCharacter(Session s) { + if (s.getPlayerCharacter() != null) { + SessionManager.pcToSession.remove(s.getPlayerCharacter()); + s.setPlayerCharacter(null); + } + } + + protected static void remAccount(Session s) { + if (s.getAccount() != null) { + SessionManager.accountToSession.remove(s.getAccount()); + s.setAccount(null); + } + } + + protected static void remSessionID(Session s) { + + if (s.getSessionID() != null) { + SessionManager.sessionIDtoSession.remove(s.getSessionID()); + s.setSessionID(null); + } + } + + protected static void remClientConnection(Session s) { + if (s.getConn() != null) { + SessionManager.connToSession.remove(s.getConn()); + s.setConn(null); + } + } + + + + /* + * Utils + */ + + public static void setCrossServerBehavior(int type) { + crossServerBehavior = type; + } + + /** + * @return a new HashSet object so the caller cannot + * modify the internal Set + */ + public static Collection getAllActiveClientConnections() { + return SessionManager.connToSession.keySet(); + } + + /** + * @return a new HashSet object so the caller cannot modify + * the internal Set + */ + public static Collection getAllActivePlayerCharacters() { + + return SessionManager.pcToSession.keySet(); + } + + public static Collection getAllActivePlayers() { + + return SessionManager.pcToSession.keySet(); + } - public static Collection getAllActiveAccounts() { - return SessionManager.accountToSession.keySet(); - } + public static int getActivePlayerCharacterCount() { - public static Account getAccountByID(int UUID) { + return SessionManager.pcToSession.keySet().size(); + } - for (Account acc : SessionManager.getAllActiveAccounts()) { + public static ArrayList getActivePCsInGuildID(int id) { + ArrayList pcs = new ArrayList<>(); - if (acc.getObjectUUID() == UUID) - return acc; + for (PlayerCharacter pc : SessionManager.getAllActivePlayerCharacters()) { + Guild g = pc.getGuild(); + if (g != null && g.getObjectUUID() == id) { + pcs.add(pc); + } + } - } - return null; - } + return pcs; + } + + public static PlayerCharacter getPlayerCharacterByLowerCaseName(String name) { + + String queryName = name.toLowerCase(); + + for (PlayerCharacter playerCharacter : SessionManager.getAllActivePlayerCharacters()) { + + if ((playerCharacter.getFirstName().toLowerCase()).equals(queryName)) { + return playerCharacter; + } + } + return null; + } + + public static PlayerCharacter getPlayerCharacterByID(int UUID) { + + for (PlayerCharacter playerCharacter : SessionManager.getAllActivePlayerCharacters()) { + + if (playerCharacter.getObjectUUID() == UUID) { + return playerCharacter; + } + } + return null; + } + + public static Collection getAllActiveAccounts() { + return SessionManager.accountToSession.keySet(); + } + + public static Account getAccountByID(int UUID) { + + for (Account acc : SessionManager.getAllActiveAccounts()) { + + if (acc.getObjectUUID() == UUID) + return acc; + + } + return null; + } } diff --git a/src/engine/gameManager/SimulationManager.java b/src/engine/gameManager/SimulationManager.java index 9cff43a1..ccdcb007 100644 --- a/src/engine/gameManager/SimulationManager.java +++ b/src/engine/gameManager/SimulationManager.java @@ -30,197 +30,194 @@ import java.util.Collection; */ public enum SimulationManager { - SERVERHEARTBEAT; - - private static SimulationManager instance = null; - - private static final long CITY_PULSE = 2000; - private static final long RUNEGATE_PULSE = 3000; - private static final long UPDATE_PULSE = 1000; - private static final long FlIGHT_PULSE = 100; - - private long _cityPulseTime = System.currentTimeMillis() + CITY_PULSE; - private long _runegatePulseTime = System.currentTimeMillis() - + RUNEGATE_PULSE; - private long _updatePulseTime = System.currentTimeMillis() + UPDATE_PULSE; - private long _flightPulseTime = System.currentTimeMillis() + FlIGHT_PULSE; - - public static Duration executionTime = Duration.ofNanos(1); - public static Duration executionMax = Duration.ofNanos(1); - - private SimulationManager() { - - // don't allow instantiation. - } - - public static String getPopulationString() { - - String popString = ""; - - try (Connection connection = DbManager.getConnection(); - PreparedStatement getPopString = connection.prepareStatement("CALL GET_POPULATION_STRING()");) { - - ResultSet rs = getPopString.executeQuery(); - - if (rs.next()) - popString = rs.getString("popstring"); - - } catch (SQLException e) { - Logger.error(e.toString()); - } - - return popString; - } - - /* - * Update the simulation. *** Important: Whatever you do in here, do it damn - * quick! - */ - public void tick() { - - /* - * As we're on the main thread we must be sure to catch any possible - * errors. - * - * IF something does occur, disable that particular heartbeat. Better - * runegates stop working than the game itself! - */ - - Instant startTime = Instant.now(); - - try { - if ((_flightPulseTime != 0) - && (System.currentTimeMillis() > _flightPulseTime)) - pulseFlight(); - } catch (Exception e) { - Logger.error( - "Fatal error in City Pulse: DISABLED. Error Message : " - + e.getMessage()); - } - try { - - if ((_updatePulseTime != 0) - && (System.currentTimeMillis() > _updatePulseTime)) - pulseUpdate(); - } catch (Exception e) { - Logger.error( - "Fatal error in Update Pulse: DISABLED"); - // _runegatePulseTime = 0; - } - - try { - if ((_runegatePulseTime != 0) - && (System.currentTimeMillis() > _runegatePulseTime)) - pulseRunegates(); - } catch (Exception e) { - Logger.error( - "Fatal error in Runegate Pulse: DISABLED"); - _runegatePulseTime = 0; - } - - try { - if ((_cityPulseTime != 0) - && (System.currentTimeMillis() > _cityPulseTime)) - pulseCities(); - } catch (Exception e) { - Logger.error( - "Fatal error in City Pulse: DISABLED. Error Message : " - + e.getMessage()); - e.printStackTrace(); - - } - - SimulationManager.executionTime = Duration.between(startTime, Instant.now()); - - if (executionTime.compareTo(executionMax) > 0) - executionMax = executionTime; - } - - /* - * Mainline simulation update method: handles movement and regen for all - * player characters - */ - - private void pulseUpdate() { - - Collection playerList; - - playerList = DbManager.getList(GameObjectType.PlayerCharacter); - - // Call update() on each player in game - - if (playerList == null) - return; - - for (AbstractGameObject ago : playerList) { - PlayerCharacter player = (PlayerCharacter)ago; - - if (player == null) - continue; - player.update(); - } + SERVERHEARTBEAT; + + private static final long CITY_PULSE = 2000; + private static final long RUNEGATE_PULSE = 3000; + private static final long UPDATE_PULSE = 1000; + private static final long FlIGHT_PULSE = 100; + public static Duration executionTime = Duration.ofNanos(1); + public static Duration executionMax = Duration.ofNanos(1); + private static SimulationManager instance = null; + private long _cityPulseTime = System.currentTimeMillis() + CITY_PULSE; + private long _runegatePulseTime = System.currentTimeMillis() + + RUNEGATE_PULSE; + private long _updatePulseTime = System.currentTimeMillis() + UPDATE_PULSE; + private long _flightPulseTime = System.currentTimeMillis() + FlIGHT_PULSE; + + private SimulationManager() { + + // don't allow instantiation. + } + + public static String getPopulationString() { + + String popString = ""; + + try (Connection connection = DbManager.getConnection(); + PreparedStatement getPopString = connection.prepareStatement("CALL GET_POPULATION_STRING()");) { + + ResultSet rs = getPopString.executeQuery(); + + if (rs.next()) + popString = rs.getString("popstring"); + + } catch (SQLException e) { + Logger.error(e.toString()); + } + + return popString; + } + + /* + * Update the simulation. *** Important: Whatever you do in here, do it damn + * quick! + */ + public void tick() { + + /* + * As we're on the main thread we must be sure to catch any possible + * errors. + * + * IF something does occur, disable that particular heartbeat. Better + * runegates stop working than the game itself! + */ + + Instant startTime = Instant.now(); + + try { + if ((_flightPulseTime != 0) + && (System.currentTimeMillis() > _flightPulseTime)) + pulseFlight(); + } catch (Exception e) { + Logger.error( + "Fatal error in City Pulse: DISABLED. Error Message : " + + e.getMessage()); + } + try { + + if ((_updatePulseTime != 0) + && (System.currentTimeMillis() > _updatePulseTime)) + pulseUpdate(); + } catch (Exception e) { + Logger.error( + "Fatal error in Update Pulse: DISABLED"); + // _runegatePulseTime = 0; + } + + try { + if ((_runegatePulseTime != 0) + && (System.currentTimeMillis() > _runegatePulseTime)) + pulseRunegates(); + } catch (Exception e) { + Logger.error( + "Fatal error in Runegate Pulse: DISABLED"); + _runegatePulseTime = 0; + } + + try { + if ((_cityPulseTime != 0) + && (System.currentTimeMillis() > _cityPulseTime)) + pulseCities(); + } catch (Exception e) { + Logger.error( + "Fatal error in City Pulse: DISABLED. Error Message : " + + e.getMessage()); + e.printStackTrace(); + + } + + SimulationManager.executionTime = Duration.between(startTime, Instant.now()); + + if (executionTime.compareTo(executionMax) > 0) + executionMax = executionTime; + } + + /* + * Mainline simulation update method: handles movement and regen for all + * player characters + */ + + private void pulseUpdate() { + + Collection playerList; + + playerList = DbManager.getList(GameObjectType.PlayerCharacter); + + // Call update() on each player in game + + if (playerList == null) + return; + + for (AbstractGameObject ago : playerList) { + PlayerCharacter player = (PlayerCharacter) ago; + + if (player == null) + continue; + player.update(); + } _updatePulseTime = System.currentTimeMillis() + 500; - } - - private void pulseFlight() { + } + + private void pulseFlight() { + + Collection playerList; + + playerList = DbManager.getList(GameObjectType.PlayerCharacter); - Collection playerList; + // Call update() on each player in game - playerList = DbManager.getList(GameObjectType.PlayerCharacter); + if (playerList == null) + return; - // Call update() on each player in game + for (AbstractGameObject ago : playerList) { + PlayerCharacter player = (PlayerCharacter) ago; - if (playerList == null) - return; + if (player == null) + continue; - for (AbstractGameObject ago : playerList) { - PlayerCharacter player = (PlayerCharacter)ago; - if (player == null) - continue; - - - player.updateFlight(); - } + player.updateFlight(); + } _flightPulseTime = System.currentTimeMillis() + FlIGHT_PULSE; - } + } - private void pulseCities() { + private void pulseCities() { - City city; + City city; - // *** Refactor: Need a list cached somewhere as it doesn't change very - // often at all. Have a cityListIsDirty boolean that gets set if it - // needs an update. Will speed up this method a great deal. + // *** Refactor: Need a list cached somewhere as it doesn't change very + // often at all. Have a cityListIsDirty boolean that gets set if it + // needs an update. Will speed up this method a great deal. - Collection cityList = DbManager.getList(Enum.GameObjectType.City); + Collection cityList = DbManager.getList(Enum.GameObjectType.City); - if (cityList == null) { - Logger.info( "City List null"); - return; - } + if (cityList == null) { + Logger.info("City List null"); + return; + } - for (AbstractGameObject cityObject : cityList) { - city = (City) cityObject; - city.onEnter(); - } + for (AbstractGameObject cityObject : cityList) { + city = (City) cityObject; + city.onEnter(); + } - _cityPulseTime = System.currentTimeMillis() + CITY_PULSE; - } + _cityPulseTime = System.currentTimeMillis() + CITY_PULSE; + } - /* - * Method runs proximity collision detection for all active portals on the - * game's Runegates - */ - private void pulseRunegates() { + /* + * Method runs proximity collision detection for all active portals on the + * game's Runegates + */ + private void pulseRunegates() { - for (Runegate runegate : Runegate._runegates.values()) { - runegate.collidePortals(); - } + for (Runegate runegate : Runegate._runegates.values()) { + runegate.collidePortals(); + } - _runegatePulseTime = System.currentTimeMillis() + RUNEGATE_PULSE; + _runegatePulseTime = System.currentTimeMillis() + RUNEGATE_PULSE; - } + } } diff --git a/src/engine/gameManager/TradeManager.java b/src/engine/gameManager/TradeManager.java index b202007d..15d6e2df 100644 --- a/src/engine/gameManager/TradeManager.java +++ b/src/engine/gameManager/TradeManager.java @@ -24,10 +24,10 @@ public enum TradeManager { public static void tradeRequest(TradeRequestMsg msg, ClientConnection origin) { PlayerCharacter source = origin.getPlayerCharacter(); - + if (source == null) - return; - + return; + source.getCharItemManager().tradeRequest(msg); } @@ -36,17 +36,17 @@ public enum TradeManager { public static void acceptTradeRequest(AcceptTradeRequestMsg msg, ClientConnection origin) { PlayerCharacter source = origin.getPlayerCharacter(); - + if (source == null) - return; - + return; + try { - source.getCharItemManager().acceptTradeRequest(msg); - } catch (Exception e) { - Logger.error(e); - // TODO Auto-generated catch block - } - + source.getCharItemManager().acceptTradeRequest(msg); + } catch (Exception e) { + Logger.error(e); + // TODO Auto-generated catch block + } + } public static void rejectTradeRequest(RejectTradeRequestMsg msg, ClientConnection origin) { @@ -54,16 +54,16 @@ public enum TradeManager { } public static void addItemToTradeWindow(AddItemToTradeWindowMsg msg, ClientConnection origin) { - - + + PlayerCharacter source = origin.getPlayerCharacter(); if (source == null || !source.isAlive()) return; - try{ + try { source.getCharItemManager().addItemToTradeWindow(msg); - }catch(Exception e){ - Logger.error(e); + } catch (Exception e) { + Logger.error(e); } } @@ -74,18 +74,17 @@ public enum TradeManager { if (source == null || !source.isAlive()) return; - - + CharacterItemManager sourceItemMan = source.getCharItemManager(); if (sourceItemMan == null) return; - - try{ + + try { sourceItemMan.addGoldToTradeWindow(msg); - }catch(Exception e){ - Logger.error(e); + } catch (Exception e) { + Logger.error(e); } } @@ -102,11 +101,11 @@ public enum TradeManager { return; try { - sourceItemMan.commitToTrade(msg); - } catch (Exception e) { - // TODO Auto-generated catch block - Logger.error(e); - } + sourceItemMan.commitToTrade(msg); + } catch (Exception e) { + // TODO Auto-generated catch block + Logger.error(e); + } } public static void uncommitToTrade(UncommitToTradeMsg msg, ClientConnection origin) { @@ -120,17 +119,16 @@ public enum TradeManager { if (sourceItemMan == null) return; - + try { - sourceItemMan.uncommitToTrade(msg); - } catch (Exception e) { - // TODO Auto-generated catch block - Logger.error(e); - } + sourceItemMan.uncommitToTrade(msg); + } catch (Exception e) { + // TODO Auto-generated catch block + Logger.error(e); + } } - public static void closeTradeWindow(CloseTradeWindowMsg msg, ClientConnection origin) { @@ -145,10 +143,10 @@ public enum TradeManager { return; try { - sourceItemMan.closeTradeWindow(msg, true); + sourceItemMan.closeTradeWindow(msg, true); } catch (Exception e) { - // TODO Auto-generated catch block - Logger.error(e); + // TODO Auto-generated catch block + Logger.error(e); } } diff --git a/src/engine/job/AbstractJob.java b/src/engine/job/AbstractJob.java index 72ff2c58..3d2ed162 100644 --- a/src/engine/job/AbstractJob.java +++ b/src/engine/job/AbstractJob.java @@ -17,135 +17,137 @@ import java.util.concurrent.atomic.AtomicReference; /** * Provides mandatory base implementation for all 'Job's'. - * - * @author + * + * @author */ public abstract class AbstractJob implements Runnable { - public enum JobRunStatus { - CREATED, RUNNING, FINISHED; - }; - - public enum JobCompletionStatus { - NOTCOMPLETEDYET, SUCCESS, SUCCESSWITHERRORS, FAIL; - }; - - /** - * Keep fields private. All access through getters n setters for Thread - * Safety. - */ - private JobRunStatus runStatus; - private JobCompletionStatus completeStatus; - private UUID uuid = null; - - private final AtomicReference workerID; - private static final String DEFAULT_WORKERID = "UNPROCESSED_JOB"; - - private long submitTime = 0L; - private long startTime = 0L; - private long stopTime = 0L; - - public AbstractJob() { - //Tests against DEFAULT_WORKERID to ensure single execution - this.workerID = new AtomicReference<>(DEFAULT_WORKERID); - this.runStatus = JobRunStatus.RUNNING; - this.completeStatus = JobCompletionStatus.NOTCOMPLETEDYET; - this.uuid = UUID.randomUUID(); - } - - @Override - public void run() { - - if(workerID.get().equals(DEFAULT_WORKERID)) { - Logger.warn("FIX ME! Job ran through 'run()' directly. Use executeJob(String) instead."); - } - - this.markStartRunTime(); - - this.setRunStatus(JobRunStatus.RUNNING); - try { - this.doJob(); - } catch (Exception e) { - Logger.error(e); - } - - this.setRunStatus(JobRunStatus.FINISHED); - - this.markStopRunTime(); - } - - protected abstract void doJob(); - - public void executeJob(String threadName) { - this.workerID.set(threadName); - this.run(); - } - - protected void setRunStatus(JobRunStatus status) { - synchronized (this.runStatus) { - this.runStatus = status; - } - } - - public JobRunStatus getRunStatus() { - synchronized (this.runStatus) { - return runStatus; - } - } - - protected void setCompletionStatus(JobCompletionStatus status) { - synchronized (this.completeStatus) { - this.completeStatus = status; - } - } - - public JobCompletionStatus getCompletionStatus() { - synchronized (this.completeStatus) { - return completeStatus; - } - } - - protected void setJobId(UUID id) { - synchronized (this.uuid) { - this.uuid = id; - } - } - - public UUID getJobId() { - synchronized (this.uuid) { - return uuid; - } - } - - public String getWorkerID() { - return workerID.get(); - } - - /* - * Time markers - */ - - protected void markSubmitTime() { - this.submitTime = System.currentTimeMillis()-2; - } - - protected void markStartRunTime() { - this.startTime = System.currentTimeMillis()-1; - } - - protected void markStopRunTime() { - this.stopTime = System.currentTimeMillis(); - } - - public final long getSubmitTime() { - return submitTime; - } - - public final long getStartTime() { - return startTime; - } - - public final long getStopTime() { - return stopTime; - } + private static final String DEFAULT_WORKERID = "UNPROCESSED_JOB"; + + ; + private final AtomicReference workerID; + + ; + /** + * Keep fields private. All access through getters n setters for Thread + * Safety. + */ + private JobRunStatus runStatus; + private JobCompletionStatus completeStatus; + private UUID uuid = null; + private long submitTime = 0L; + private long startTime = 0L; + private long stopTime = 0L; + + public AbstractJob() { + //Tests against DEFAULT_WORKERID to ensure single execution + this.workerID = new AtomicReference<>(DEFAULT_WORKERID); + this.runStatus = JobRunStatus.RUNNING; + this.completeStatus = JobCompletionStatus.NOTCOMPLETEDYET; + this.uuid = UUID.randomUUID(); + } + + @Override + public void run() { + + if (workerID.get().equals(DEFAULT_WORKERID)) { + Logger.warn("FIX ME! Job ran through 'run()' directly. Use executeJob(String) instead."); + } + + this.markStartRunTime(); + + this.setRunStatus(JobRunStatus.RUNNING); + try { + this.doJob(); + } catch (Exception e) { + Logger.error(e); + } + + this.setRunStatus(JobRunStatus.FINISHED); + + this.markStopRunTime(); + } + + protected abstract void doJob(); + + public void executeJob(String threadName) { + this.workerID.set(threadName); + this.run(); + } + + public JobRunStatus getRunStatus() { + synchronized (this.runStatus) { + return runStatus; + } + } + + protected void setRunStatus(JobRunStatus status) { + synchronized (this.runStatus) { + this.runStatus = status; + } + } + + public JobCompletionStatus getCompletionStatus() { + synchronized (this.completeStatus) { + return completeStatus; + } + } + + protected void setCompletionStatus(JobCompletionStatus status) { + synchronized (this.completeStatus) { + this.completeStatus = status; + } + } + + public UUID getJobId() { + synchronized (this.uuid) { + return uuid; + } + } + + protected void setJobId(UUID id) { + synchronized (this.uuid) { + this.uuid = id; + } + } + + public String getWorkerID() { + return workerID.get(); + } + + protected void markSubmitTime() { + this.submitTime = System.currentTimeMillis() - 2; + } + + protected void markStartRunTime() { + this.startTime = System.currentTimeMillis() - 1; + } + + /* + * Time markers + */ + + protected void markStopRunTime() { + this.stopTime = System.currentTimeMillis(); + } + + public final long getSubmitTime() { + return submitTime; + } + + public final long getStartTime() { + return startTime; + } + + public final long getStopTime() { + return stopTime; + } + + public enum JobRunStatus { + CREATED, RUNNING, FINISHED; + } + + public enum JobCompletionStatus { + NOTCOMPLETEDYET, SUCCESS, SUCCESSWITHERRORS, FAIL; + } } diff --git a/src/engine/job/AbstractJobStatistics.java b/src/engine/job/AbstractJobStatistics.java index be5a6e4a..b88c02e7 100644 --- a/src/engine/job/AbstractJobStatistics.java +++ b/src/engine/job/AbstractJobStatistics.java @@ -11,108 +11,108 @@ package engine.job; public abstract class AbstractJobStatistics { - private String objectName; - private long totalServiceTime = 0L; - private long totalQueueTime = 0L; - private long executions = 0L; - private long maxServiceTime = 0L; - private long minServiceTime = 0L; - private long minQueueTime = 0L; - private long maxQueueTime = 0L; - - - public AbstractJobStatistics() { - this.objectName = "Unknown"; - } - - public AbstractJobStatistics(String objectName) { - this.objectName = objectName; - } - - public void setObjectName (String objectName) { - this.objectName = objectName; - } - - public String getObjectName () { - return this.objectName; - } - - public long getExecutions() { - return this.executions; - } - - public long getTotalServiceTime() { - return this.totalServiceTime; - } - - public long getTotalQueueTime() { - return this.totalQueueTime; - } - - public long getAvgQueueTime() { - if (this.executions > 0L && this.totalQueueTime > 0L) - return this.totalQueueTime / this.executions; - else - return 0L; - } - - public long getAvgServiceTime() { - if (this.executions > 0L && this.totalServiceTime > 0L) - return this.totalServiceTime / this.executions; - else - return 0L; - } - - public long getMinServiceTime() { - return this.minServiceTime; - } - - public long getMinQueueTime() { - return this.minQueueTime; - } - - public long getMaxServiceTime() { - return this.maxServiceTime; - } - - public long getMaxQueueTime() { - return this.maxQueueTime; - } - - public void incrExecutions() { - this.executions++; - } - - public void addServiceTime(long svcTime) { - this.totalServiceTime += svcTime; - this.incrExecutions(); - if (svcTime > this.maxServiceTime) - this.maxServiceTime = svcTime; - if (svcTime < this.minServiceTime || this.minServiceTime == 0L) - this.minServiceTime = svcTime; - - } - - public void addQueueTime(long queueTime) { - this.totalQueueTime += queueTime; - this.incrExecutions(); - if (queueTime > this.maxQueueTime) - this.maxQueueTime = queueTime; - if (queueTime < this.minQueueTime || this.minQueueTime == 0L) - this.minQueueTime = queueTime; - - } - - public String asString() { + private String objectName; + private long totalServiceTime = 0L; + private long totalQueueTime = 0L; + private long executions = 0L; + private long maxServiceTime = 0L; + private long minServiceTime = 0L; + private long minQueueTime = 0L; + private long maxQueueTime = 0L; + + + public AbstractJobStatistics() { + this.objectName = "Unknown"; + } + + public AbstractJobStatistics(String objectName) { + this.objectName = objectName; + } + + public String getObjectName() { + return this.objectName; + } + + public void setObjectName(String objectName) { + this.objectName = objectName; + } + + public long getExecutions() { + return this.executions; + } + + public long getTotalServiceTime() { + return this.totalServiceTime; + } + + public long getTotalQueueTime() { + return this.totalQueueTime; + } + + public long getAvgQueueTime() { + if (this.executions > 0L && this.totalQueueTime > 0L) + return this.totalQueueTime / this.executions; + else + return 0L; + } + + public long getAvgServiceTime() { + if (this.executions > 0L && this.totalServiceTime > 0L) + return this.totalServiceTime / this.executions; + else + return 0L; + } + + public long getMinServiceTime() { + return this.minServiceTime; + } + + public long getMinQueueTime() { + return this.minQueueTime; + } + + public long getMaxServiceTime() { + return this.maxServiceTime; + } + + public long getMaxQueueTime() { + return this.maxQueueTime; + } + + public void incrExecutions() { + this.executions++; + } + + public void addServiceTime(long svcTime) { + this.totalServiceTime += svcTime; + this.incrExecutions(); + if (svcTime > this.maxServiceTime) + this.maxServiceTime = svcTime; + if (svcTime < this.minServiceTime || this.minServiceTime == 0L) + this.minServiceTime = svcTime; + + } + + public void addQueueTime(long queueTime) { + this.totalQueueTime += queueTime; + this.incrExecutions(); + if (queueTime > this.maxQueueTime) + this.maxQueueTime = queueTime; + if (queueTime < this.minQueueTime || this.minQueueTime == 0L) + this.minQueueTime = queueTime; + + } + + public String asString() { return this.objectName + " execs=" + this.executions + " avg_svc_ms=" + this.getAvgServiceTime() + - " min_svc_ms=" + this.minServiceTime + " max_svc_ms=" + this.maxServiceTime + - " avg_q_ms=" + this.getAvgQueueTime() + " min_q_ms=" + this.minQueueTime + - " max_q_ms=" + this.maxQueueTime; - } - - public String asChatMsg() { + " min_svc_ms=" + this.minServiceTime + " max_svc_ms=" + this.maxServiceTime + + " avg_q_ms=" + this.getAvgQueueTime() + " min_q_ms=" + this.minQueueTime + + " max_q_ms=" + this.maxQueueTime; + } + + public String asChatMsg() { return this.objectName + "=>" + this.executions + ',' + this.getAvgServiceTime() + '/' + this.minServiceTime + - '/' + this.maxServiceTime + " "+ this.getAvgQueueTime() + '/' + + '/' + this.maxServiceTime + " " + this.getAvgQueueTime() + '/' + this.minQueueTime + '/' + this.maxQueueTime + '\n'; - } + } } diff --git a/src/engine/job/AbstractScheduleJob.java b/src/engine/job/AbstractScheduleJob.java index c33ae9ae..3ba8a494 100644 --- a/src/engine/job/AbstractScheduleJob.java +++ b/src/engine/job/AbstractScheduleJob.java @@ -7,22 +7,22 @@ // www.magicbane.com - package engine.job; +package engine.job; public abstract class AbstractScheduleJob extends AbstractJob { - public AbstractScheduleJob() { - super(); - } + public AbstractScheduleJob() { + super(); + } - @Override - protected abstract void doJob(); + @Override + protected abstract void doJob(); - public void cancelJob() { - JobScheduler.getInstance().cancelScheduledJob(this); - _cancelJob(); - } + public void cancelJob() { + JobScheduler.getInstance().cancelScheduledJob(this); + _cancelJob(); + } - protected abstract void _cancelJob(); + protected abstract void _cancelJob(); } diff --git a/src/engine/job/ClassJobStatistics.java b/src/engine/job/ClassJobStatistics.java index be283ab5..e27d9878 100644 --- a/src/engine/job/ClassJobStatistics.java +++ b/src/engine/job/ClassJobStatistics.java @@ -11,9 +11,9 @@ package engine.job; public class ClassJobStatistics extends AbstractJobStatistics { - public ClassJobStatistics (String className) { - super(className); - } + public ClassJobStatistics(String className) { + super(className); + } + - } diff --git a/src/engine/job/JobContainer.java b/src/engine/job/JobContainer.java index 56048b5c..181e85cd 100644 --- a/src/engine/job/JobContainer.java +++ b/src/engine/job/JobContainer.java @@ -12,73 +12,73 @@ package engine.job; public class JobContainer implements Comparable { - final AbstractJob job; - final long timeOfExecution; - final boolean noTimer; + final AbstractJob job; + final long timeOfExecution; + final boolean noTimer; - JobContainer(AbstractJob job, long timeOfExecution) { - if (job == null) { - throw new IllegalArgumentException("No 'null' jobs allowed."); - } - this.job = job; - this.timeOfExecution = timeOfExecution; - this.noTimer = false; - } + JobContainer(AbstractJob job, long timeOfExecution) { + if (job == null) { + throw new IllegalArgumentException("No 'null' jobs allowed."); + } + this.job = job; + this.timeOfExecution = timeOfExecution; + this.noTimer = false; + } - public JobContainer(AbstractJob job) { - if (job == null) { - throw new IllegalArgumentException("No 'null' jobs allowed."); - } - this.job = job; - this.timeOfExecution = Long.MAX_VALUE; - this.noTimer = true; - } + public JobContainer(AbstractJob job) { + if (job == null) { + throw new IllegalArgumentException("No 'null' jobs allowed."); + } + this.job = job; + this.timeOfExecution = Long.MAX_VALUE; + this.noTimer = true; + } - public AbstractJob getJob() { - return job; - } + public AbstractJob getJob() { + return job; + } - public boolean noTimer() { - return noTimer; - } + public boolean noTimer() { + return noTimer; + } - public long timeOfExection() { - return this.timeOfExecution; - } + public long timeOfExection() { + return this.timeOfExecution; + } - public int timeToExecutionLeft() { - if (JobScheduler.getInstance().isAlive()) { - int timeLeft = (int) (timeOfExecution - System.currentTimeMillis()); - if (timeLeft < 0) - timeLeft = 0; - return timeLeft; - } else - return (int) (timeOfExecution - JobScheduler.getInstance().getTimeOfKill()); - } + public int timeToExecutionLeft() { + if (JobScheduler.getInstance().isAlive()) { + int timeLeft = (int) (timeOfExecution - System.currentTimeMillis()); + if (timeLeft < 0) + timeLeft = 0; + return timeLeft; + } else + return (int) (timeOfExecution - JobScheduler.getInstance().getTimeOfKill()); + } - @Override - public int compareTo(JobContainer compared) { - if (timeOfExecution < compared.timeOfExecution) { - return -1; - } - if (timeOfExecution > compared.timeOfExecution) { - return 1; - } - return 0; - } + @Override + public int compareTo(JobContainer compared) { + if (timeOfExecution < compared.timeOfExecution) { + return -1; + } + if (timeOfExecution > compared.timeOfExecution) { + return 1; + } + return 0; + } - @Override - public boolean equals(Object obj) { - return job.equals(((JobContainer) obj).job); - } + @Override + public boolean equals(Object obj) { + return job.equals(((JobContainer) obj).job); + } - @Override - public int hashCode() { - return job.hashCode(); - } + @Override + public int hashCode() { + return job.hashCode(); + } - public void cancelJob() { - if (job != null && job instanceof AbstractScheduleJob) - ((AbstractScheduleJob)job).cancelJob(); - } + public void cancelJob() { + if (job != null && job instanceof AbstractScheduleJob) + ((AbstractScheduleJob) job).cancelJob(); + } } diff --git a/src/engine/job/JobManager.java b/src/engine/job/JobManager.java index 36612f7f..da40b030 100644 --- a/src/engine/job/JobManager.java +++ b/src/engine/job/JobManager.java @@ -25,208 +25,206 @@ import java.util.concurrent.ConcurrentHashMap; */ public class JobManager extends ControlledRunnable { - /* - * Singleton implementation. - */ - private static volatile JobManager INSTANCE; - public static JobManager getInstance() { - if (JobManager.INSTANCE == null) { - synchronized (JobManager.class) { - if (JobManager.INSTANCE == null) { - JobManager.INSTANCE = new JobManager(); - JobManager.INSTANCE.startup(); - } - } - } - return JobManager.INSTANCE; - } - - /* - * Class implementation - */ - - private final ArrayList jobPoolList = new ArrayList<>(); - private final ConcurrentHashMap jobQueueMapping= new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_HIGH); - - private boolean shutdownNowFlag = false; - - private JobManager() { - super("JobManager"); - - // create the initial job pools with the correct sizes - // based on the number of array elements in the initial_jo_workers - // definition in Statisc - - if (MBServerStatics.INITIAL_JOBPOOL_WORKERS != null && MBServerStatics.INITIAL_JOBPOOL_WORKERS.length >0 ) { - for (int i=0; i required"; - } - - public String resetJobs() { - // moves all jobs to the P1 queue - this.jobQueueMapping.clear(); - return "All Jobs reset onto P1 queue"; - } - - public String showJobs() { - String out = ""; - Iterator jmi = this.jobQueueMapping.keySet().iterator(); - - while (jmi.hasNext()) { - String jmiKey = jmi.next(); - out += jmiKey + ' ' + this.jobQueueMapping.get(jmiKey).getJobPoolID() + '\n'; - } - return out; - } - - public ArrayList getJobPoolList() { - - return this.jobPoolList; - } - - public String modifyJobPoolWorkers(String jobPoolID, String maxWorkers) { - - try { - // parse string into an int - Integer jid = Integer.parseInt(jobPoolID); - Integer mw = Integer.parseInt(maxWorkers); - for (JobPool jp : this.jobPoolList) { - if (jp.getJobPoolID() == jid) { - // change the number of workers - return jp.setMaxWorkers(mw); - } - } - - } catch (NumberFormatException e) { - return "Invalid parameters required"; - } - - return "Invalid parameters required"; - } + /* + * Singleton implementation. + */ + private static volatile JobManager INSTANCE; + private final ArrayList jobPoolList = new ArrayList<>(); + + /* + * Class implementation + */ + private final ConcurrentHashMap jobQueueMapping = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_HIGH); + private boolean shutdownNowFlag = false; + + private JobManager() { + super("JobManager"); + + // create the initial job pools with the correct sizes + // based on the number of array elements in the initial_jo_workers + // definition in Statisc + + if (MBServerStatics.INITIAL_JOBPOOL_WORKERS != null && MBServerStatics.INITIAL_JOBPOOL_WORKERS.length > 0) { + for (int i = 0; i < MBServerStatics.INITIAL_JOBPOOL_WORKERS.length; i++) { + JobPool jp = new JobPool(i, MBServerStatics.INITIAL_JOBPOOL_WORKERS[i]); + this.jobPoolList.add(jp); + Logger.info("Adding JobPool_" + jp.getJobPoolID() + " with " + MBServerStatics.INITIAL_JOBPOOL_WORKERS[i] + " workers"); + } + } else { + // not defined or empty in statics so just create 1 JobPool with 25 workers + System.out.println("Creating 1 pool called 0"); + JobPool jp = new JobPool(0, 25); + this.jobPoolList.add(jp); + Logger.info("Adding JobPool_" + jp.getJobPoolID() + " with 25 workers"); + } + + JobScheduler.getInstance(); + + // if you want any jobs to default onto a given queue put it here + // otherwise everything goes on the P1 queue by default + + } + + public static JobManager getInstance() { + if (JobManager.INSTANCE == null) { + synchronized (JobManager.class) { + if (JobManager.INSTANCE == null) { + JobManager.INSTANCE = new JobManager(); + JobManager.INSTANCE.startup(); + } + } + } + return JobManager.INSTANCE; + } + + /** + * Submit a job to be processed by the JobManager. There is no guarantee + * that the job will be executed immediately. + * + * @param aj AbstractJob to be submitted. + * @return boolean value indicating whether the job was submitted or not. + */ + public boolean submitJob(AbstractJob aj) { + + if (jobQueueMapping.containsKey(aj.getClass().getSimpleName())) { + return this.jobQueueMapping.get(aj.getClass().getSimpleName()).submitJob(aj); + } else { + return this.jobPoolList.get(0).submitJob(aj); + } + } + + + private void auditAllWorkers() { + + for (JobPool jp : this.jobPoolList) { + jp.auditWorkers(); + } + } + + @Override + protected boolean _Run() { + // This thread is to be used to JM internal monitoring. + + // Startup workers: + this.auditAllWorkers(); + ThreadUtils.sleep(MBServerStatics.JOBMANAGER_INTERNAL_MONITORING_INTERVAL_MS * 2); + + this.runStatus = true; + + // Monitoring loop + while (this.runCmd) { + this.auditAllWorkers(); + ThreadUtils.sleep(MBServerStatics.JOBMANAGER_INTERNAL_MONITORING_INTERVAL_MS); + } + + // No new submissions + for (JobPool jp : this.jobPoolList) { + jp.setBlockNewSubmissions(true); + } + + if (this.shutdownNowFlag == false) { + // shutdown each pool + for (JobPool jp : this.jobPoolList) { + jp.shutdown(); + } + } else { + // Emergency Stop each pool + for (JobPool jp : this.jobPoolList) { + jp.emergencyStop(); + } + } + this.runStatus = false; + Logger.info("JM Shutdown"); + return true; + } + + @Override + protected boolean _postRun() { + return true; + } + + @Override + protected boolean _preRun() { + return true; + } + + @Override + protected void _shutdown() { + Logger.info("JM Shutdown Requested"); + JobScheduler.getInstance().shutdown(); + } + + @Override + protected void _startup() { + Logger.info("JM Starting up... "); + } + + public void shutdownNow() { + this.shutdownNowFlag = true; + this.shutdown(); + } + + public String moveJob(String simpleClassName, String jobPoolID) { + // moves a job to a different queue + + try { + // parse string into an int + Integer i = Integer.parseInt(jobPoolID); + for (JobPool jp : this.jobPoolList) { + if (jp.getJobPoolID() == i) { + // move the job to the new queue + this.jobQueueMapping.put(simpleClassName, jp); + return simpleClassName + " moved to JobPool ID " + jp.getJobPoolID(); + } + } + + } catch (NumberFormatException e) { + return "jobPoolID is not a valid number"; + } + + //Verify jobpool ID + return "Invalid parameters required"; + } + + public String resetJobs() { + // moves all jobs to the P1 queue + this.jobQueueMapping.clear(); + return "All Jobs reset onto P1 queue"; + } + + public String showJobs() { + String out = ""; + Iterator jmi = this.jobQueueMapping.keySet().iterator(); + + while (jmi.hasNext()) { + String jmiKey = jmi.next(); + out += jmiKey + ' ' + this.jobQueueMapping.get(jmiKey).getJobPoolID() + '\n'; + } + return out; + } + + public ArrayList getJobPoolList() { + + return this.jobPoolList; + } + + public String modifyJobPoolWorkers(String jobPoolID, String maxWorkers) { + + try { + // parse string into an int + Integer jid = Integer.parseInt(jobPoolID); + Integer mw = Integer.parseInt(maxWorkers); + for (JobPool jp : this.jobPoolList) { + if (jp.getJobPoolID() == jid) { + // change the number of workers + return jp.setMaxWorkers(mw); + } + } + + } catch (NumberFormatException e) { + return "Invalid parameters required"; + } + + return "Invalid parameters required"; + } } diff --git a/src/engine/job/JobPool.java b/src/engine/job/JobPool.java index fc874407..9a96d59b 100644 --- a/src/engine/job/JobPool.java +++ b/src/engine/job/JobPool.java @@ -25,271 +25,271 @@ import java.util.concurrent.LinkedBlockingQueue; public class JobPool { - int jobPoolID; - int maxWorkers; - int nextWorkerID; - private final LinkedBlockingQueue jobWaitQueue = new LinkedBlockingQueue<>(); - private final LinkedBlockingQueue jobWorkerQueue = new LinkedBlockingQueue<>(); - private final ArrayList jobWorkerList = new ArrayList<>(); - private final LinkedBlockingQueue jobRunList = new LinkedBlockingQueue<>(); - private boolean blockNewSubmissions = false; - - public JobPool(int id, int workers) { - this.jobPoolID = id; - - // default to 1 unless workers parameter is higher - int actualWorkers = 1; - if (workers > 1) - actualWorkers = workers; - - this.maxWorkers = actualWorkers; - for (int i=0;i q) { - HashMap ch = new HashMap<>(); - int cnt = 0; - - - // iterate through the linked queue and get every item - // putting classname and incrementing the value each time in the hashmap - Iterator wi = q.iterator(); - - while (cnt < q.size() && wi.hasNext()) { - AbstractJob aj = wi.next(); - if (ch.containsKey(aj.getClass().getSimpleName())) { - int newValue = ch.get(aj.getClass().getSimpleName()) + 1; - ch.put(aj.getClass().getSimpleName(), newValue); - } else { - ch.put(aj.getClass().getSimpleName(), 1); - } - cnt++; - } - - // iterate through the hashmap outputting the classname and number of jobs - Iterator i = ch.keySet().iterator(); - String out = ""; - while(i.hasNext()) { - Object key = i.next(); - out += "JobPoolID_" + this.jobPoolID + ' ' + key.toString() + "=>" + ch.get(key) + '\n'; - } - if (out.isEmpty()) - return "No Jobs on queue\n"; - else - return out; - } - - public void auditWorkers() { - - if(!MBServerStatics.ENABLE_AUDIT_JOB_WORKERS) { - return; - } - ArrayList problemJobs = new ArrayList<>(); - - // Checked for stalled Workers - Iterator it = jobWorkerList.iterator(); - - while (it.hasNext()) { - JobWorker jw = it.next(); - AbstractJob curJob = jw.getCurrentJob(); - - if (curJob != null) { // Has a job - - if (JobPool.isExemptJobFromAudit(curJob)) { - continue; - } - - // Determine whether the job is being executed or waiting to - // start; - - if (curJob.getStartTime() <= 0) { - // Waiting to start - long diff = System.currentTimeMillis() - curJob.getSubmitTime(); - - if (diff >= MBServerStatics.JOB_STALL_THRESHOLD_MS) { - Logger.warn("Job did not start within threshold. Stopping worker#" + jw.getWorkerId() + " JobData:" - + curJob.toString()); - jw.EmergencyStop(); - problemJobs.add(jw.getCurrentJob()); - it.remove(); - } // end if (diff >= - - } else if (curJob.getStopTime() <= 0L) { - // is executing it - long diff = System.currentTimeMillis() - curJob.getStartTime(); - - if (diff >= MBServerStatics.JOB_STALL_THRESHOLD_MS) { - Logger.warn("Job execution time exceeded threshold(" + diff + "). Stopping worker#" + jw.getWorkerId() + " JobData:" - + curJob.toString()); - jw.EmergencyStop(); - problemJobs.add(jw.getCurrentJob()); - it.remove(); - } // end if (diff >= - } // end if(curJob.getStopTime() - } // end if(curJob != null) - } // end While - - // Check Worker Count and add workers as necessary; - int workerCount = jobWorkerList.size(); - - int maxThreads = this.maxWorkers; - - - // no pool can go below a single thread - if (maxThreads < 1) - maxThreads = 1; - - while (workerCount != maxThreads) { - Logger.info("Resizing JobPool " + this.jobPoolID + " from " + workerCount + " to " + maxThreads); - - if (workerCount < maxThreads) { - this.startWorker(this.getNextWorkerID()); - - - if (jobWorkerList.size() <= workerCount) { - // Something didnt work correctly - Logger.warn("auditWorkers() failed to add a new JobWorker to JobPool " + this.jobPoolID + ". Worker count " + workerCount + " Worker pool size " + jobWorkerList.size() + " Aborting Audit."); - return; - } - - } else if (workerCount > maxThreads) { - synchronized(this.jobWorkerList) { - Logger.warn("Reducing workers in JobPool " + this.jobPoolID + " Worker Count: " + workerCount + " to Max threads: " + maxThreads); - // pick a worker off the list and shut it down - - JobWorker toRemove = null; - int loopTries = 5; - do { - //Infinite loop could be bad.. - toRemove = jobWorkerQueue.poll(); - } while (toRemove == null && --loopTries >= 0); - - //remove it from the list - toRemove.shutdown(); - jobWorkerList.remove(toRemove); - } - } - - // update value for next loop pass - workerCount = jobWorkerList.size(); - } - - } - - private static boolean isExemptJobFromAudit(AbstractJob aj) { - // If the job is any of the following classes, exempt it from auditWorkers - if (aj instanceof ConnectionMonitorJob) { - return true; - } else - return aj instanceof CheckNetMsgFactoryJob || aj instanceof AttackJob || aj instanceof UsePowerJob; + private final LinkedBlockingQueue jobWaitQueue = new LinkedBlockingQueue<>(); + private final LinkedBlockingQueue jobWorkerQueue = new LinkedBlockingQueue<>(); + private final ArrayList jobWorkerList = new ArrayList<>(); + private final LinkedBlockingQueue jobRunList = new LinkedBlockingQueue<>(); + int jobPoolID; + int maxWorkers; + int nextWorkerID; + private boolean blockNewSubmissions = false; + + public JobPool(int id, int workers) { + this.jobPoolID = id; + + // default to 1 unless workers parameter is higher + int actualWorkers = 1; + if (workers > 1) + actualWorkers = workers; + + this.maxWorkers = actualWorkers; + for (int i = 0; i < actualWorkers; i++) { + this.startWorker(i); + } + + this.nextWorkerID = this.maxWorkers; + + + } + + private static boolean isExemptJobFromAudit(AbstractJob aj) { + // If the job is any of the following classes, exempt it from auditWorkers + if (aj instanceof ConnectionMonitorJob) { + return true; + } else + return aj instanceof CheckNetMsgFactoryJob || aj instanceof AttackJob || aj instanceof UsePowerJob; + + } + + private int getNextWorkerID() { + return this.nextWorkerID++; + + + } + + public int getJobPoolID() { + return this.jobPoolID; + } + + public void setBlockNewSubmissions(boolean blocked) { + this.blockNewSubmissions = blocked; + } + + public boolean submitJob(AbstractJob aj) { + + if (blockNewSubmissions) { + Logger.warn("A '" + aj.getClass().getSimpleName() + "' job was submitted, but submissions are currently blocked."); + return false; + } + + aj.markSubmitTime(); + jobWaitQueue.add(aj); + + // keep notifying workers if the wait queue has items + // commented out as the price of polling the wait queue + // size while it is being updated out-weighs the gain + // for not just blindly waking all workers + // unless we have a stupidly large pool vs CPU threads + + JobWorker jw = jobWorkerQueue.poll(); + if (jw != null) { + synchronized (jw) { + jw.notify(); + } + } + + return true; + } + + private void startWorker(int workerID) { + + // check we dont already have a jobWorker with that ID + synchronized (this.jobWorkerList) { + for (JobWorker jwi : this.jobWorkerList) { + if (jwi.getWorkerId() == workerID) { + Logger.error("Attempt to create worker with ID " + workerID + " failed in JobPool " + jobPoolID + " as worker ID already exists"); + return; + } + } + } + + // ID is unique, create worker + JobWorker jw; + jw = new JobWorker(workerID, this.jobPoolID, this.jobWaitQueue, this.jobWorkerQueue); + + synchronized (this.jobWorkerList) { + //Adds to the overall list.. + jobWorkerList.add(jw); + } + + //Returns to the free worker queue.. + jw.startup(); + } + + private String getQueueByClassAsString(Queue q) { + HashMap ch = new HashMap<>(); + int cnt = 0; + + + // iterate through the linked queue and get every item + // putting classname and incrementing the value each time in the hashmap + Iterator wi = q.iterator(); + + while (cnt < q.size() && wi.hasNext()) { + AbstractJob aj = wi.next(); + if (ch.containsKey(aj.getClass().getSimpleName())) { + int newValue = ch.get(aj.getClass().getSimpleName()) + 1; + ch.put(aj.getClass().getSimpleName(), newValue); + } else { + ch.put(aj.getClass().getSimpleName(), 1); + } + cnt++; + } + + // iterate through the hashmap outputting the classname and number of jobs + Iterator i = ch.keySet().iterator(); + String out = ""; + while (i.hasNext()) { + Object key = i.next(); + out += "JobPoolID_" + this.jobPoolID + ' ' + key.toString() + "=>" + ch.get(key) + '\n'; + } + if (out.isEmpty()) + return "No Jobs on queue\n"; + else + return out; + } + + public void auditWorkers() { + + if (!MBServerStatics.ENABLE_AUDIT_JOB_WORKERS) { + return; + } + ArrayList problemJobs = new ArrayList<>(); + + // Checked for stalled Workers + Iterator it = jobWorkerList.iterator(); + + while (it.hasNext()) { + JobWorker jw = it.next(); + AbstractJob curJob = jw.getCurrentJob(); + + if (curJob != null) { // Has a job + + if (JobPool.isExemptJobFromAudit(curJob)) { + continue; + } + + // Determine whether the job is being executed or waiting to + // start; + + if (curJob.getStartTime() <= 0) { + // Waiting to start + long diff = System.currentTimeMillis() - curJob.getSubmitTime(); + + if (diff >= MBServerStatics.JOB_STALL_THRESHOLD_MS) { + Logger.warn("Job did not start within threshold. Stopping worker#" + jw.getWorkerId() + " JobData:" + + curJob.toString()); + jw.EmergencyStop(); + problemJobs.add(jw.getCurrentJob()); + it.remove(); + } // end if (diff >= + + } else if (curJob.getStopTime() <= 0L) { + // is executing it + long diff = System.currentTimeMillis() - curJob.getStartTime(); + + if (diff >= MBServerStatics.JOB_STALL_THRESHOLD_MS) { + Logger.warn("Job execution time exceeded threshold(" + diff + "). Stopping worker#" + jw.getWorkerId() + " JobData:" + + curJob.toString()); + jw.EmergencyStop(); + problemJobs.add(jw.getCurrentJob()); + it.remove(); + } // end if (diff >= + } // end if(curJob.getStopTime() + } // end if(curJob != null) + } // end While + + // Check Worker Count and add workers as necessary; + int workerCount = jobWorkerList.size(); + + int maxThreads = this.maxWorkers; + + + // no pool can go below a single thread + if (maxThreads < 1) + maxThreads = 1; + + while (workerCount != maxThreads) { + Logger.info("Resizing JobPool " + this.jobPoolID + " from " + workerCount + " to " + maxThreads); + + if (workerCount < maxThreads) { + this.startWorker(this.getNextWorkerID()); + + + if (jobWorkerList.size() <= workerCount) { + // Something didnt work correctly + Logger.warn("auditWorkers() failed to add a new JobWorker to JobPool " + this.jobPoolID + ". Worker count " + workerCount + " Worker pool size " + jobWorkerList.size() + " Aborting Audit."); + return; + } + + } else if (workerCount > maxThreads) { + synchronized (this.jobWorkerList) { + Logger.warn("Reducing workers in JobPool " + this.jobPoolID + " Worker Count: " + workerCount + " to Max threads: " + maxThreads); + // pick a worker off the list and shut it down + + JobWorker toRemove = null; + int loopTries = 5; + do { + //Infinite loop could be bad.. + toRemove = jobWorkerQueue.poll(); + } while (toRemove == null && --loopTries >= 0); + + //remove it from the list + toRemove.shutdown(); + jobWorkerList.remove(toRemove); + } + } + + // update value for next loop pass + workerCount = jobWorkerList.size(); + } + + } + + public void shutdown() { + synchronized (this.jobWorkerList) { + for (JobWorker jw : this.jobWorkerList) + jw.shutdown(); + } + } + + public void emergencyStop() { + synchronized (this.jobWorkerList) { + for (JobWorker jw : this.jobWorkerList) + jw.EmergencyStop(); + } + } + + public String getRunningQueueByClassAsString() { + return this.getQueueByClassAsString(this.jobRunList); + } + + public String getWaitQueueByClassAsString() { + return this.getQueueByClassAsString(this.jobWaitQueue); + } + + + // used by devcmds + public String setMaxWorkers(int maxWorkers) { + + if (maxWorkers > 0 && maxWorkers < 101) { + this.maxWorkers = maxWorkers; + // audit workers reduces the cap + this.auditWorkers(); + return "Max workers set to " + maxWorkers + " for JobPool_" + this.jobPoolID; + } else { + return "Max workers not set, value must be from 1-100"; + } } - - public void shutdown() { - synchronized(this.jobWorkerList) { - for (JobWorker jw : this.jobWorkerList) - jw.shutdown(); - } - } - - public void emergencyStop() { - synchronized(this.jobWorkerList) { - for (JobWorker jw : this.jobWorkerList) - jw.EmergencyStop(); - } - } - - public String getRunningQueueByClassAsString() { - return this.getQueueByClassAsString(this.jobRunList); - } - - public String getWaitQueueByClassAsString () { - return this.getQueueByClassAsString(this.jobWaitQueue); - } - - - // used by devcmds - public String setMaxWorkers (int maxWorkers) { - - if (maxWorkers > 0 && maxWorkers < 101) { - this.maxWorkers = maxWorkers; - // audit workers reduces the cap - this.auditWorkers(); - return "Max workers set to " + maxWorkers + " for JobPool_" + this.jobPoolID; - } else { - return "Max workers not set, value must be from 1-100"; - } - - } } diff --git a/src/engine/job/JobScheduler.java b/src/engine/job/JobScheduler.java index 4ba503d6..11699764 100644 --- a/src/engine/job/JobScheduler.java +++ b/src/engine/job/JobScheduler.java @@ -16,154 +16,154 @@ import java.util.PriorityQueue; public class JobScheduler { - private static final JobScheduler INSTANCE = new JobScheduler(); - - private final PriorityQueue jobs; - private volatile boolean alive; - private long timeOfKill = -1; - - public static JobScheduler getInstance() { - return INSTANCE; - } - - private JobScheduler() { - jobs = new PriorityQueue<>(MBServerStatics.SCHEDULER_INITIAL_CAPACITY); - Runnable worker = new Runnable() { - @Override - public void run() { - execution(); - } - }; - - alive = true; - - Thread t = new Thread(worker, "JobScheduler"); - t.start(); - } - - /** - * This function schedules a job to execute in timeToExecution - * milliseconds from now. - * - * @param job - * @param timeToExecution - * @return - */ - public JobContainer scheduleJob(AbstractJob job, int timeToExecution) { - long timeOfExecution = System.currentTimeMillis() + timeToExecution; - JobContainer container = new JobContainer(job, timeOfExecution); - - synchronized (jobs) { - jobs.offer(container); - jobs.notify(); - } - - return container; - } - - /** - * This function schedules a job to execute at the absolute time of - * timeOfExecution (milliseconds). - * - * @param job - * @param timeOfExecution - * @return - */ - public JobContainer scheduleJob(AbstractJob job, long timeOfExecution) { - JobContainer container = new JobContainer(job, timeOfExecution); - - synchronized (jobs) { - jobs.offer(container); - jobs.notify(); - } - - return container; - } - - public boolean cancelScheduledJob(JobContainer container) { - return cancelScheduledJob(container.getJob()); - } - - public boolean cancelScheduledJob(AbstractJob job) { - JobContainer container = new JobContainer(job, -1); - - boolean success = false; - synchronized (jobs) { - success = jobs.remove(container); - jobs.notify(); - } - - return success; - } - - /** - * Stops the jobScheduler - */ - public void shutdown() { - if (alive) { - alive = false; - timeOfKill = System.currentTimeMillis(); - synchronized (jobs) { - jobs.notify(); - } - } - } - - public JobContainer pollNextJobContainer() { - if (alive) { - throw new IllegalStateException("Can't poll jobs from a live scheduler."); - } - - synchronized (jobs) { - return jobs.poll(); - } - } - - public long getTimeOfKill() { - return this.timeOfKill; - } - - public boolean isAlive() { - return this.alive; - } - - private void execution() { - long duration; - JobContainer container; - int compensation = MBServerStatics.SCHEDULER_EXECUTION_TIME_COMPENSATION; - - while (alive) { - synchronized (jobs) { - container = jobs.peek(); - if (container == null) { - // queue is empty, wait until notified (which happens after - // a new job is offered) - try { - jobs.wait(0); - } catch (InterruptedException ie) { - // do nothing - } - } else { - duration = container.timeOfExecution - System.currentTimeMillis(); - if (duration < compensation) { - jobs.poll(); - } else { - // enforce new loop - container = null; - - // sleep until the head job execution time - try { - jobs.wait(duration); - } catch (InterruptedException ie) { - // do nothing - } - } - } - } - - if (container != null) { - JobManager.getInstance().submitJob(container.job); - } - } - } + private static final JobScheduler INSTANCE = new JobScheduler(); + + private final PriorityQueue jobs; + private volatile boolean alive; + private long timeOfKill = -1; + + private JobScheduler() { + jobs = new PriorityQueue<>(MBServerStatics.SCHEDULER_INITIAL_CAPACITY); + Runnable worker = new Runnable() { + @Override + public void run() { + execution(); + } + }; + + alive = true; + + Thread t = new Thread(worker, "JobScheduler"); + t.start(); + } + + public static JobScheduler getInstance() { + return INSTANCE; + } + + /** + * This function schedules a job to execute in timeToExecution + * milliseconds from now. + * + * @param job + * @param timeToExecution + * @return + */ + public JobContainer scheduleJob(AbstractJob job, int timeToExecution) { + long timeOfExecution = System.currentTimeMillis() + timeToExecution; + JobContainer container = new JobContainer(job, timeOfExecution); + + synchronized (jobs) { + jobs.offer(container); + jobs.notify(); + } + + return container; + } + + /** + * This function schedules a job to execute at the absolute time of + * timeOfExecution (milliseconds). + * + * @param job + * @param timeOfExecution + * @return + */ + public JobContainer scheduleJob(AbstractJob job, long timeOfExecution) { + JobContainer container = new JobContainer(job, timeOfExecution); + + synchronized (jobs) { + jobs.offer(container); + jobs.notify(); + } + + return container; + } + + public boolean cancelScheduledJob(JobContainer container) { + return cancelScheduledJob(container.getJob()); + } + + public boolean cancelScheduledJob(AbstractJob job) { + JobContainer container = new JobContainer(job, -1); + + boolean success = false; + synchronized (jobs) { + success = jobs.remove(container); + jobs.notify(); + } + + return success; + } + + /** + * Stops the jobScheduler + */ + public void shutdown() { + if (alive) { + alive = false; + timeOfKill = System.currentTimeMillis(); + synchronized (jobs) { + jobs.notify(); + } + } + } + + public JobContainer pollNextJobContainer() { + if (alive) { + throw new IllegalStateException("Can't poll jobs from a live scheduler."); + } + + synchronized (jobs) { + return jobs.poll(); + } + } + + public long getTimeOfKill() { + return this.timeOfKill; + } + + public boolean isAlive() { + return this.alive; + } + + private void execution() { + long duration; + JobContainer container; + int compensation = MBServerStatics.SCHEDULER_EXECUTION_TIME_COMPENSATION; + + while (alive) { + synchronized (jobs) { + container = jobs.peek(); + if (container == null) { + // queue is empty, wait until notified (which happens after + // a new job is offered) + try { + jobs.wait(0); + } catch (InterruptedException ie) { + // do nothing + } + } else { + duration = container.timeOfExecution - System.currentTimeMillis(); + if (duration < compensation) { + jobs.poll(); + } else { + // enforce new loop + container = null; + + // sleep until the head job execution time + try { + jobs.wait(duration); + } catch (InterruptedException ie) { + // do nothing + } + } + } + } + + if (container != null) { + JobManager.getInstance().submitJob(container.job); + } + } + } } diff --git a/src/engine/job/JobWorker.java b/src/engine/job/JobWorker.java index 2fc24c4d..e6a13ca9 100644 --- a/src/engine/job/JobWorker.java +++ b/src/engine/job/JobWorker.java @@ -16,94 +16,94 @@ import java.util.Queue; public class JobWorker extends ControlledRunnable { - private final int workerId; - - private final Queue jobWaitQueue; - private final Queue jobWorkerList; - - private AbstractJob currentJob; - - public JobWorker(final int workerID, int priorityQueue, - Queue jobWaitQueue, - Queue jobWorkerList) { - super("JobWorker_" + priorityQueue + '_' + workerID); - - workerId = workerID; - this.jobWaitQueue = jobWaitQueue; - this.jobWorkerList = jobWorkerList; - } - - @Override - protected boolean _Run() { - - while (this.runCmd) { - // Access to Queue is synchronized internal to JobManager - this.currentJob = this.jobWaitQueue.poll(); - - if (this.currentJob == null) { - try { - // use self as MUTEX - synchronized (this) { - this.jobWorkerList.add(this); - this.wait(); - } - - } catch (InterruptedException e) { - Logger.error(this.getThreadName(), e.getClass() - .getSimpleName() - + ": " + e.getMessage()); - break; - - } - } else { - - // execute the new job.. - this.currentJob.executeJob(this.getThreadName()); - this.currentJob = null; - } - - } - return true; - } - - @Override - protected boolean _postRun() { - return true; - } - - @Override - protected boolean _preRun() { - return true; - } - - @Override - protected void _shutdown() { - } - - @Override - protected void _startup() { - //this.logDirectINFO(this.getThreadName(), "Starting up..."); - } - - public final int getWorkerId() { - return workerId; - } - - public final AbstractJob getCurrentJob() { - return currentJob; - } - - public final boolean hasCurrentJob() { + private final int workerId; + + private final Queue jobWaitQueue; + private final Queue jobWorkerList; + + private AbstractJob currentJob; + + public JobWorker(final int workerID, int priorityQueue, + Queue jobWaitQueue, + Queue jobWorkerList) { + super("JobWorker_" + priorityQueue + '_' + workerID); + + workerId = workerID; + this.jobWaitQueue = jobWaitQueue; + this.jobWorkerList = jobWorkerList; + } + + @Override + protected boolean _Run() { + + while (this.runCmd) { + // Access to Queue is synchronized internal to JobManager + this.currentJob = this.jobWaitQueue.poll(); + + if (this.currentJob == null) { + try { + // use self as MUTEX + synchronized (this) { + this.jobWorkerList.add(this); + this.wait(); + } + + } catch (InterruptedException e) { + Logger.error(this.getThreadName(), e.getClass() + .getSimpleName() + + ": " + e.getMessage()); + break; + + } + } else { + + // execute the new job.. + this.currentJob.executeJob(this.getThreadName()); + this.currentJob = null; + } + + } + return true; + } + + @Override + protected boolean _postRun() { + return true; + } + + @Override + protected boolean _preRun() { + return true; + } + + @Override + protected void _shutdown() { + } + + @Override + protected void _startup() { + //this.logDirectINFO(this.getThreadName(), "Starting up..."); + } + + public final int getWorkerId() { + return workerId; + } + + public final AbstractJob getCurrentJob() { + return currentJob; + } + + public final boolean hasCurrentJob() { return (currentJob != null); - } - - protected void EmergencyStop() { - this.runCmd = false; - String out = "Stack Trace"; - for(StackTraceElement e : this.getThisThread().getStackTrace()) { - out += " -> " + e.toString(); - } - Logger.info(out); - this.getThisThread().interrupt(); - } + } + + protected void EmergencyStop() { + this.runCmd = false; + String out = "Stack Trace"; + for (StackTraceElement e : this.getThisThread().getStackTrace()) { + out += " -> " + e.toString(); + } + Logger.info(out); + this.getThisThread().interrupt(); + } } diff --git a/src/engine/jobs/AbstractEffectJob.java b/src/engine/jobs/AbstractEffectJob.java index eaafb760..4197dcfb 100644 --- a/src/engine/jobs/AbstractEffectJob.java +++ b/src/engine/jobs/AbstractEffectJob.java @@ -7,7 +7,7 @@ // www.magicbane.com - package engine.jobs; +package engine.jobs; import engine.job.AbstractScheduleJob; import engine.objects.AbstractWorldObject; @@ -18,135 +18,137 @@ import engine.powers.PowersBase; public abstract class AbstractEffectJob extends AbstractScheduleJob { - protected String stackType; - protected AbstractWorldObject target; - protected AbstractWorldObject source; - protected int trains; - protected ActionsBase action; - protected PowersBase power; - protected EffectsBase eb; - protected boolean skipSendEffect=false; - protected boolean skipApplyEffect=false; - protected boolean isChant=false; - protected boolean skipCancelEffect=false; - private boolean noOverwrite; - private int effectSourceType = 0; - private int effectSourceID = 0; - - public AbstractEffectJob(AbstractWorldObject source, AbstractWorldObject target, String stackType, int trains, ActionsBase action, PowersBase power, EffectsBase eb) { - super(); - this.source = source; - this.target = target; - this.stackType = stackType; - this.trains = trains; - this.action = action; - this.power = power; - this.eb = eb; - } - - @Override - protected abstract void doJob(); - @Override - protected abstract void _cancelJob(); - - public String getStackType() { - return this.stackType; - } - - public AbstractWorldObject getTarget() { - return this.target; - } - - public AbstractWorldObject getSource() { - return this.target; - } - - public int getTrains() { - return this.trains; - } - - public ActionsBase getAction() { - return this.action; - } - - public PowersBase getPower() { - return this.power; - } - - public int getPowerToken() { - if (this.power == null) - return 0; - return this.power.getToken(); - } - - public EffectsBase getEffect() { - return this.eb; - } - - public boolean skipSendEffect() { - return this.skipSendEffect; - } - - public void setSkipSendEffect(boolean value) { - this.skipSendEffect = value; - } - - public boolean skipApplyEffect() { - return this.skipApplyEffect; - } - - public void setSkipApplyEffect(boolean value) { - this.skipApplyEffect = value; - } - - public boolean skipCancelEffect() { - return this.skipCancelEffect; - } - - public void setSkipCancelEffect(boolean value) { - this.skipCancelEffect = value; - } - - public boolean isChant() { - return this.isChant; - } - - public void setChant(boolean value) { - this.isChant = value; - } - - public void endEffect() { - if (this.eb == null) - return; - this.eb.endEffect(this.source, this.target, this.trains, this.power, this); - } - - public void endEffectNoPower() { - if (this.eb == null) - return; - this.eb.endEffectNoPower(this.trains,this); - } - public boolean isNoOverwrite() { - return noOverwrite; - } - - public void setNoOverwrite(boolean noOverwrite) { - this.noOverwrite = noOverwrite; - } - - public int getEffectSourceType() { - return effectSourceType; - } - - public void setEffectSourceType(int effectSourceType) { - this.effectSourceType = effectSourceType; - } - - public int getEffectSourceID() { - return effectSourceID; - } - - public void setEffectSourceID(int effectSourceID) { - this.effectSourceID = effectSourceID; - } + protected String stackType; + protected AbstractWorldObject target; + protected AbstractWorldObject source; + protected int trains; + protected ActionsBase action; + protected PowersBase power; + protected EffectsBase eb; + protected boolean skipSendEffect = false; + protected boolean skipApplyEffect = false; + protected boolean isChant = false; + protected boolean skipCancelEffect = false; + private boolean noOverwrite; + private int effectSourceType = 0; + private int effectSourceID = 0; + + public AbstractEffectJob(AbstractWorldObject source, AbstractWorldObject target, String stackType, int trains, ActionsBase action, PowersBase power, EffectsBase eb) { + super(); + this.source = source; + this.target = target; + this.stackType = stackType; + this.trains = trains; + this.action = action; + this.power = power; + this.eb = eb; + } + + @Override + protected abstract void doJob(); + + @Override + protected abstract void _cancelJob(); + + public String getStackType() { + return this.stackType; + } + + public AbstractWorldObject getTarget() { + return this.target; + } + + public AbstractWorldObject getSource() { + return this.target; + } + + public int getTrains() { + return this.trains; + } + + public ActionsBase getAction() { + return this.action; + } + + public PowersBase getPower() { + return this.power; + } + + public int getPowerToken() { + if (this.power == null) + return 0; + return this.power.getToken(); + } + + public EffectsBase getEffect() { + return this.eb; + } + + public boolean skipSendEffect() { + return this.skipSendEffect; + } + + public void setSkipSendEffect(boolean value) { + this.skipSendEffect = value; + } + + public boolean skipApplyEffect() { + return this.skipApplyEffect; + } + + public void setSkipApplyEffect(boolean value) { + this.skipApplyEffect = value; + } + + public boolean skipCancelEffect() { + return this.skipCancelEffect; + } + + public void setSkipCancelEffect(boolean value) { + this.skipCancelEffect = value; + } + + public boolean isChant() { + return this.isChant; + } + + public void setChant(boolean value) { + this.isChant = value; + } + + public void endEffect() { + if (this.eb == null) + return; + this.eb.endEffect(this.source, this.target, this.trains, this.power, this); + } + + public void endEffectNoPower() { + if (this.eb == null) + return; + this.eb.endEffectNoPower(this.trains, this); + } + + public boolean isNoOverwrite() { + return noOverwrite; + } + + public void setNoOverwrite(boolean noOverwrite) { + this.noOverwrite = noOverwrite; + } + + public int getEffectSourceType() { + return effectSourceType; + } + + public void setEffectSourceType(int effectSourceType) { + this.effectSourceType = effectSourceType; + } + + public int getEffectSourceID() { + return effectSourceID; + } + + public void setEffectSourceID(int effectSourceID) { + this.effectSourceID = effectSourceID; + } } diff --git a/src/engine/jobs/ActivateBaneJob.java b/src/engine/jobs/ActivateBaneJob.java index ee5df670..65d3cd94 100644 --- a/src/engine/jobs/ActivateBaneJob.java +++ b/src/engine/jobs/ActivateBaneJob.java @@ -40,7 +40,7 @@ public class ActivateBaneJob extends AbstractScheduleJob { if (city.getBane() == null) { - Logger.info( "No bane found for " + city.getCityName()); + Logger.info("No bane found for " + city.getCityName()); return; } @@ -65,7 +65,7 @@ public class ActivateBaneJob extends AbstractScheduleJob { ChatSystemMsg msg = new ChatSystemMsg(null, "[Bane Channel] The Banecircle placed by " + city.getBane().getOwner().getGuild().getName() + " is now active! Buildings are now vulnerable to damage!"); msg.setMessageType(4); // Error message msg.setChannel(ChatChannelType.SYSTEM.getChannelID()); - + DispatchMessage.dispatchMsgToAll(msg); } diff --git a/src/engine/jobs/AttackJob.java b/src/engine/jobs/AttackJob.java index 3e3ba607..affed880 100644 --- a/src/engine/jobs/AttackJob.java +++ b/src/engine/jobs/AttackJob.java @@ -7,7 +7,7 @@ // www.magicbane.com - package engine.jobs; +package engine.jobs; import engine.gameManager.CombatManager; import engine.job.AbstractJob; @@ -15,25 +15,26 @@ import engine.objects.AbstractCharacter; public class AttackJob extends AbstractJob { - private final AbstractCharacter source; - private final int slot; - private final boolean success; - - public AttackJob(AbstractCharacter source, int slot, boolean success) { - super(); - this.source = source; - this.slot = slot; - this.success = success; - } - - @Override - protected void doJob() { - CombatManager.doCombat(this.source, slot); - } - - public boolean success() { - return this.success; - } - protected void _cancelJob() { - } + private final AbstractCharacter source; + private final int slot; + private final boolean success; + + public AttackJob(AbstractCharacter source, int slot, boolean success) { + super(); + this.source = source; + this.slot = slot; + this.success = success; + } + + @Override + protected void doJob() { + CombatManager.doCombat(this.source, slot); + } + + public boolean success() { + return this.success; + } + + protected void _cancelJob() { + } } \ No newline at end of file diff --git a/src/engine/jobs/BasicScheduledJob.java b/src/engine/jobs/BasicScheduledJob.java index e4bb8fb2..5c29fe7f 100644 --- a/src/engine/jobs/BasicScheduledJob.java +++ b/src/engine/jobs/BasicScheduledJob.java @@ -22,105 +22,93 @@ import java.lang.reflect.Method; *

* Intended to be used with the {@link JobScheduler}, a BasicScheduledJob will * hold a reference to an execution method. - * + * * @author Burfo **/ public class BasicScheduledJob extends AbstractJob { - private Method execution; - private Object referenceObject; + private Method execution; + private Object referenceObject; - /** - * Generates a new BasicScheduledJob that executes a static method that has - * no parameters. - * - * @param methodName - * Name of the static method to execute, such as "myMethod" - * - * @param methodClass - * The class in which {@code methodName} exists - */ - public BasicScheduledJob(String methodName, Class methodClass) { - this(methodName, methodClass, null); - } + /** + * Generates a new BasicScheduledJob that executes a static method that has + * no parameters. + * + * @param methodName Name of the static method to execute, such as "myMethod" + * @param methodClass The class in which {@code methodName} exists + */ + public BasicScheduledJob(String methodName, Class methodClass) { + this(methodName, methodClass, null); + } - /** - * Generates a new BasicScheduledJob that executes an instance method that - * has no parameters. - * - * @param methodName - * Name of the instance method to execute, such as "myMethod" - * - * @param methodClass - * The class in which {@code methodName} exists - * - * @param referenceObject - * Instance of {@code methodClass} against which {@code - * methodName} should be executed - */ - @SuppressWarnings("unchecked") - public BasicScheduledJob(String methodName, Class methodClass, Object referenceObject) { - super(); - Method method = null; - try { - method = methodClass.getMethod(methodName); - } catch (SecurityException e) { - Logger.error( e); - } catch (NoSuchMethodException e) { - Logger.error( e); - } - setData(method, null); - } + /** + * Generates a new BasicScheduledJob that executes an instance method that + * has no parameters. + * + * @param methodName Name of the instance method to execute, such as "myMethod" + * @param methodClass The class in which {@code methodName} exists + * @param referenceObject Instance of {@code methodClass} against which {@code + * methodName} should be executed + */ + @SuppressWarnings("unchecked") + public BasicScheduledJob(String methodName, Class methodClass, Object referenceObject) { + super(); + Method method = null; + try { + method = methodClass.getMethod(methodName); + } catch (SecurityException e) { + Logger.error(e); + } catch (NoSuchMethodException e) { + Logger.error(e); + } + setData(method, null); + } - /** - * Generates a new BasicScheduledJob that executes a static method that has - * no parameters. - * - * @param executionMethod - * Reference to the static method to execute - */ - public BasicScheduledJob(Method executionMethod) { - this(executionMethod, null); - } + /** + * Generates a new BasicScheduledJob that executes a static method that has + * no parameters. + * + * @param executionMethod Reference to the static method to execute + */ + public BasicScheduledJob(Method executionMethod) { + this(executionMethod, null); + } - /** - * Generates a new BasicScheduledJob that executes an instance method that - * has no parameters. - * - * @param executionMethod - * Reference to the static method to execute - * - * @param referenceObject - * Instanciated object against which {@code executionMethod} - * should be executed - */ - public BasicScheduledJob(Method executionMethod, Object referenceObject) { - super(); - setData(executionMethod, referenceObject); - } + /** + * Generates a new BasicScheduledJob that executes an instance method that + * has no parameters. + * + * @param executionMethod Reference to the static method to execute + * @param referenceObject Instanciated object against which {@code executionMethod} + * should be executed + */ + public BasicScheduledJob(Method executionMethod, Object referenceObject) { + super(); + setData(executionMethod, referenceObject); + } - private void setData(Method executionMethod, Object referenceObject) { - this.execution = executionMethod; - this.referenceObject = referenceObject; - if (execution == null) { - Logger.error("BasicScheduledJob instanciated with no execution method."); - } - } + private void setData(Method executionMethod, Object referenceObject) { + this.execution = executionMethod; + this.referenceObject = referenceObject; + if (execution == null) { + Logger.error("BasicScheduledJob instanciated with no execution method."); + } + } - @Override - protected void doJob() { - if (execution == null) { - Logger.error( "BasicScheduledJob executed with nothing to execute."); - return; - } + @Override + protected void doJob() { + if (execution == null) { + Logger.error("BasicScheduledJob executed with nothing to execute."); + return; + } - try { - execution.invoke(referenceObject); - } catch (IllegalArgumentException | IllegalAccessException e) { - Logger.error( "BasicScheduledJob execution failed. Method: " + execution.toString(), e); - } catch (InvocationTargetException e) { - Logger.error( "BasicScheduledJob execution failed. " + "Method: " + execution.toString(), e); - } - } + try { + execution.invoke(referenceObject); + } catch (IllegalArgumentException | IllegalAccessException e) { + Logger.error("BasicScheduledJob execution failed. Method: " + execution.toString(), e); + } catch (InvocationTargetException e) { + Logger.error("BasicScheduledJob execution failed. " + "Method: " + execution.toString(), e); + } + } } diff --git a/src/engine/jobs/BonusCalcJob.java b/src/engine/jobs/BonusCalcJob.java index 2fdaf060..0aa3e514 100644 --- a/src/engine/jobs/BonusCalcJob.java +++ b/src/engine/jobs/BonusCalcJob.java @@ -25,7 +25,7 @@ public class BonusCalcJob extends AbstractJob { protected void doJob() { if (this.ac != null) { this.ac.applyBonuses(); - + } } } diff --git a/src/engine/jobs/CSessionCleanupJob.java b/src/engine/jobs/CSessionCleanupJob.java index df591aab..38002471 100644 --- a/src/engine/jobs/CSessionCleanupJob.java +++ b/src/engine/jobs/CSessionCleanupJob.java @@ -7,22 +7,22 @@ // www.magicbane.com - package engine.jobs; +package engine.jobs; import engine.gameManager.SessionManager; import engine.job.AbstractJob; public class CSessionCleanupJob extends AbstractJob { - private final String secKey; + private final String secKey; - public CSessionCleanupJob(String key) { - super(); - this.secKey = key; - } + public CSessionCleanupJob(String key) { + super(); + this.secKey = key; + } - @Override - protected void doJob() { - SessionManager.cSessionCleanup(secKey); - } + @Override + protected void doJob() { + SessionManager.cSessionCleanup(secKey); + } } diff --git a/src/engine/jobs/ChantJob.java b/src/engine/jobs/ChantJob.java index 2c3de86e..cfb2bfb7 100644 --- a/src/engine/jobs/ChantJob.java +++ b/src/engine/jobs/ChantJob.java @@ -27,77 +27,76 @@ import java.util.HashSet; public class ChantJob extends AbstractEffectJob { - private final AbstractEffectJob aej; - private int iteration = 0; - - public ChantJob(AbstractWorldObject source, AbstractWorldObject target, String stackType, int trains, ActionsBase action, PowersBase power, EffectsBase eb, AbstractEffectJob aej) { - super(source, target, stackType, trains, action, power, eb); - this.aej = aej; - } - - @Override - protected void doJob() { - if (this.aej == null || this.source == null || this.target == null || this.action == null || this.power == null || this.source == null || this.eb == null) - return; - PlayerBonuses bonuses = null; - - //if player isnt in game, do not run chant. - if (this.source.getObjectType().equals(GameObjectType.PlayerCharacter)){ - if (SessionManager.getPlayerCharacterByID(this.source.getObjectUUID()) == null) - return; - } - if (AbstractWorldObject.IsAbstractCharacter(source)) - bonuses = ((AbstractCharacter)source).getBonuses(); - if (!this.source.isAlive()) { - PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); - if (AbstractWorldObject.IsAbstractCharacter(source)) - ((AbstractCharacter)source).cancelLastChant(); - } else if (bonuses != null && bonuses.getBool(ModType.Silenced, SourceType.None)) { - PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); - if (AbstractWorldObject.IsAbstractCharacter(source)) - ((AbstractCharacter)source).cancelLastChant(); - } - else if (AbstractWorldObject.IsAbstractCharacter(source) && ((AbstractCharacter)source).isSit()){ - return; - }else if (this.iteration < this.power.getChantIterations() && AbstractWorldObject.IsAbstractCharacter(source)) { - this.skipSendEffect = true; - this.iteration++; - - // *** Refactor holy wtf batman - - String stackType = action.getStackType(); - stackType = (stackType.equals("IgnoreStack")) ? Integer.toString(action.getUUID()) : stackType; - - HashSet awolist = null; - if (this.source instanceof PlayerCharacter) - awolist = PowersManager.getAllTargets(this.source, this.source.getLoc(), (PlayerCharacter)this.source, this.power); - else - awolist = new HashSet<>(); - for (AbstractWorldObject awo : awolist) { - - if (awo == null) - continue; - - PowersManager.finishApplyPowerA((AbstractCharacter) this.source, awo, awo.getLoc(), this.power, this.trains, true); - - } - - if (AbstractWorldObject.IsAbstractCharacter(source)) - //handle invul - if(power.getUUID() != 334) - ((AbstractCharacter)this.source).setLastChant((int)(this.power.getChantDuration()) * 1000, this); - else - ((AbstractCharacter)this.source).setLastChant((int)(this.power.getChantDuration()) * 1000, this); - } else { - PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); - if (AbstractWorldObject.IsAbstractCharacter(source)) { - ((AbstractCharacter)source).cancelLastChant(); - } - } - } - - @Override - protected void _cancelJob() { - } + private final AbstractEffectJob aej; + private int iteration = 0; + + public ChantJob(AbstractWorldObject source, AbstractWorldObject target, String stackType, int trains, ActionsBase action, PowersBase power, EffectsBase eb, AbstractEffectJob aej) { + super(source, target, stackType, trains, action, power, eb); + this.aej = aej; + } + + @Override + protected void doJob() { + if (this.aej == null || this.source == null || this.target == null || this.action == null || this.power == null || this.source == null || this.eb == null) + return; + PlayerBonuses bonuses = null; + + //if player isnt in game, do not run chant. + if (this.source.getObjectType().equals(GameObjectType.PlayerCharacter)) { + if (SessionManager.getPlayerCharacterByID(this.source.getObjectUUID()) == null) + return; + } + if (AbstractWorldObject.IsAbstractCharacter(source)) + bonuses = ((AbstractCharacter) source).getBonuses(); + if (!this.source.isAlive()) { + PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); + if (AbstractWorldObject.IsAbstractCharacter(source)) + ((AbstractCharacter) source).cancelLastChant(); + } else if (bonuses != null && bonuses.getBool(ModType.Silenced, SourceType.None)) { + PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); + if (AbstractWorldObject.IsAbstractCharacter(source)) + ((AbstractCharacter) source).cancelLastChant(); + } else if (AbstractWorldObject.IsAbstractCharacter(source) && ((AbstractCharacter) source).isSit()) { + return; + } else if (this.iteration < this.power.getChantIterations() && AbstractWorldObject.IsAbstractCharacter(source)) { + this.skipSendEffect = true; + this.iteration++; + + // *** Refactor holy wtf batman + + String stackType = action.getStackType(); + stackType = (stackType.equals("IgnoreStack")) ? Integer.toString(action.getUUID()) : stackType; + + HashSet awolist = null; + if (this.source instanceof PlayerCharacter) + awolist = PowersManager.getAllTargets(this.source, this.source.getLoc(), (PlayerCharacter) this.source, this.power); + else + awolist = new HashSet<>(); + for (AbstractWorldObject awo : awolist) { + + if (awo == null) + continue; + + PowersManager.finishApplyPowerA((AbstractCharacter) this.source, awo, awo.getLoc(), this.power, this.trains, true); + + } + + if (AbstractWorldObject.IsAbstractCharacter(source)) + //handle invul + if (power.getUUID() != 334) + ((AbstractCharacter) this.source).setLastChant((int) (this.power.getChantDuration()) * 1000, this); + else + ((AbstractCharacter) this.source).setLastChant((int) (this.power.getChantDuration()) * 1000, this); + } else { + PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); + if (AbstractWorldObject.IsAbstractCharacter(source)) { + ((AbstractCharacter) source).cancelLastChant(); + } + } + } + + @Override + protected void _cancelJob() { + } } diff --git a/src/engine/jobs/CloseGateJob.java b/src/engine/jobs/CloseGateJob.java index 2418835e..46168b76 100644 --- a/src/engine/jobs/CloseGateJob.java +++ b/src/engine/jobs/CloseGateJob.java @@ -7,7 +7,7 @@ // www.magicbane.com - package engine.jobs; +package engine.jobs; import engine.Enum; import engine.Enum.PortalType; @@ -15,32 +15,32 @@ import engine.job.AbstractScheduleJob; import engine.objects.Building; import engine.objects.Runegate; import org.pmw.tinylog.Logger; - + public class CloseGateJob extends AbstractScheduleJob { - private final Building building; - private final Enum.PortalType portalType; + private final Building building; + private final Enum.PortalType portalType; + + public CloseGateJob(Building building, PortalType portalType) { - public CloseGateJob(Building building, PortalType portalType) { + super(); + this.building = building; + this.portalType = portalType; + } - super(); - this.building = building; - this.portalType = portalType; - } + @Override + protected void doJob() { - @Override - protected void doJob() { - - if (building == null) { - Logger.error("Rungate building was null"); - return; - } + if (building == null) { + Logger.error("Rungate building was null"); + return; + } - Runegate._runegates.get(building.getObjectUUID()).deactivatePortal(portalType); - } + Runegate._runegates.get(building.getObjectUUID()).deactivatePortal(portalType); + } - @Override - protected void _cancelJob() { - } + @Override + protected void _cancelJob() { + } } diff --git a/src/engine/jobs/DamageOverTimeJob.java b/src/engine/jobs/DamageOverTimeJob.java index 3470842a..eaa4d25f 100644 --- a/src/engine/jobs/DamageOverTimeJob.java +++ b/src/engine/jobs/DamageOverTimeJob.java @@ -22,71 +22,71 @@ import engine.powers.poweractions.DamageOverTimePowerAction; public class DamageOverTimeJob extends AbstractEffectJob { - private final DamageOverTimePowerAction dot; - private int iteration = 0; - private int liveCounter = 0; - - public DamageOverTimeJob(AbstractWorldObject source, AbstractWorldObject target, String stackType, int trains, ActionsBase action, PowersBase power, EffectsBase eb, DamageOverTimePowerAction dot) { - super(source, target, stackType, trains, action, power, eb); - - this.dot = dot; - if (this.target != null && AbstractWorldObject.IsAbstractCharacter(target)) - this.liveCounter = ((AbstractCharacter)target).getLiveCounter(); - - this.iteration = action.getDurationInSeconds(trains) / this.dot.getNumIterations(); - } - - @Override - protected void doJob() { - if (this.target.getObjectType().equals(GameObjectType.Building) - && ((Building)this.target).isVulnerable() == false) { - _cancelJob(); - return; - } - - - if (this.dot == null || this.target == null || this.action == null || this.source == null || this.eb == null) - return; - if (AbstractWorldObject.IsAbstractCharacter(target) && ((AbstractCharacter)this.target).getLiveCounter() != liveCounter){ - PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); - return; - } - if (!this.target.isAlive()){ - PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); - return; - } - - this.iteration--; - - if (this.iteration < 0){ - PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); - return; - } - this.skipSendEffect = true; - String stackType = action.getStackType(); - if (stackType.equals("IgnoreStack")) - this.target.addEffect(Integer.toString(action.getUUID()), getTickLength(), this, this.eb, this.trains); - else - this.target.addEffect(stackType, getTickLength(), this, this.eb, this.trains); - if (AbstractWorldObject.IsAbstractCharacter(source)) - eb.startEffect((AbstractCharacter)this.source, this.target, this.trains, this); - } - - @Override - protected void _cancelJob() { - PowersManager.cancelEffectTime(this.source, this.target, this.power, this.eb, this.action, this.trains, this); - } - - public int getIteration() { - return this.iteration; - } - - public int getTickLength() { - return this.dot.getNumIterations() * 1000; - } - - public int inc() { - this.iteration++; - return this.iteration; - } + private final DamageOverTimePowerAction dot; + private int iteration = 0; + private int liveCounter = 0; + + public DamageOverTimeJob(AbstractWorldObject source, AbstractWorldObject target, String stackType, int trains, ActionsBase action, PowersBase power, EffectsBase eb, DamageOverTimePowerAction dot) { + super(source, target, stackType, trains, action, power, eb); + + this.dot = dot; + if (this.target != null && AbstractWorldObject.IsAbstractCharacter(target)) + this.liveCounter = ((AbstractCharacter) target).getLiveCounter(); + + this.iteration = action.getDurationInSeconds(trains) / this.dot.getNumIterations(); + } + + @Override + protected void doJob() { + if (this.target.getObjectType().equals(GameObjectType.Building) + && ((Building) this.target).isVulnerable() == false) { + _cancelJob(); + return; + } + + + if (this.dot == null || this.target == null || this.action == null || this.source == null || this.eb == null) + return; + if (AbstractWorldObject.IsAbstractCharacter(target) && ((AbstractCharacter) this.target).getLiveCounter() != liveCounter) { + PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); + return; + } + if (!this.target.isAlive()) { + PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); + return; + } + + this.iteration--; + + if (this.iteration < 0) { + PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); + return; + } + this.skipSendEffect = true; + String stackType = action.getStackType(); + if (stackType.equals("IgnoreStack")) + this.target.addEffect(Integer.toString(action.getUUID()), getTickLength(), this, this.eb, this.trains); + else + this.target.addEffect(stackType, getTickLength(), this, this.eb, this.trains); + if (AbstractWorldObject.IsAbstractCharacter(source)) + eb.startEffect((AbstractCharacter) this.source, this.target, this.trains, this); + } + + @Override + protected void _cancelJob() { + PowersManager.cancelEffectTime(this.source, this.target, this.power, this.eb, this.action, this.trains, this); + } + + public int getIteration() { + return this.iteration; + } + + public int getTickLength() { + return this.dot.getNumIterations() * 1000; + } + + public int inc() { + this.iteration++; + return this.iteration; + } } diff --git a/src/engine/jobs/DatabaseUpdateJob.java b/src/engine/jobs/DatabaseUpdateJob.java index 18e3dd61..fa45cf44 100644 --- a/src/engine/jobs/DatabaseUpdateJob.java +++ b/src/engine/jobs/DatabaseUpdateJob.java @@ -7,7 +7,7 @@ // www.magicbane.com - package engine.jobs; +package engine.jobs; import engine.Enum.GameObjectType; import engine.gameManager.DbManager; @@ -18,48 +18,47 @@ import engine.objects.PlayerCharacter; public class DatabaseUpdateJob extends AbstractScheduleJob { - private final AbstractGameObject ago; - private final String type; + private final AbstractGameObject ago; + private final String type; - public DatabaseUpdateJob(AbstractGameObject ago, String type) { - super(); - this.ago = ago; - this.type = type; - } + public DatabaseUpdateJob(AbstractGameObject ago, String type) { + super(); + this.ago = ago; + this.type = type; + } - @Override - protected void doJob() { - if (this.ago == null) - return; - ago.removeDatabaseJob(this.type, false); - - if (ago.getObjectType().equals(GameObjectType.PlayerCharacter)) { - - PlayerCharacter pc = (PlayerCharacter) ago; - - switch (this.type) { - case "Skills": - pc.updateSkillsAndPowersToDatabase(); - break; - case "Stats": - DbManager.PlayerCharacterQueries.UPDATE_CHARACTER_STATS(pc); - break; - case "EXP": - DbManager.PlayerCharacterQueries.UPDATE_CHARACTER_EXPERIENCE(pc); - break; - } + @Override + protected void doJob() { + if (this.ago == null) + return; + ago.removeDatabaseJob(this.type, false); - } - else if (ago instanceof Building) { - Building b = (Building) ago; - if (this.type.equals("health")) - DbManager.BuildingQueries.UPDATE_BUILDING_HEALTH(b.getObjectUUID(), (int)(b.getHealth())); - } + if (ago.getObjectType().equals(GameObjectType.PlayerCharacter)) { - } + PlayerCharacter pc = (PlayerCharacter) ago; - @Override - protected void _cancelJob() { - } + switch (this.type) { + case "Skills": + pc.updateSkillsAndPowersToDatabase(); + break; + case "Stats": + DbManager.PlayerCharacterQueries.UPDATE_CHARACTER_STATS(pc); + break; + case "EXP": + DbManager.PlayerCharacterQueries.UPDATE_CHARACTER_EXPERIENCE(pc); + break; + } + + } else if (ago instanceof Building) { + Building b = (Building) ago; + if (this.type.equals("health")) + DbManager.BuildingQueries.UPDATE_BUILDING_HEALTH(b.getObjectUUID(), (int) (b.getHealth())); + } + + } + + @Override + protected void _cancelJob() { + } } diff --git a/src/engine/jobs/DeferredPowerJob.java b/src/engine/jobs/DeferredPowerJob.java index 17ffefa6..6cd6973f 100644 --- a/src/engine/jobs/DeferredPowerJob.java +++ b/src/engine/jobs/DeferredPowerJob.java @@ -24,86 +24,84 @@ import engine.powers.poweractions.DeferredPowerPowerAction; public class DeferredPowerJob extends AbstractEffectJob { - private final DeferredPowerPowerAction def; + private final DeferredPowerPowerAction def; - public DeferredPowerJob(AbstractWorldObject source, AbstractWorldObject target, String stackType, int trains, ActionsBase action, PowersBase power, EffectsBase eb, DeferredPowerPowerAction def) { - super(source, target, stackType, trains, action, power, eb); - this.def = def; - } + public DeferredPowerJob(AbstractWorldObject source, AbstractWorldObject target, String stackType, int trains, ActionsBase action, PowersBase power, EffectsBase eb, DeferredPowerPowerAction def) { + super(source, target, stackType, trains, action, power, eb); + this.def = def; + } - public DeferredPowerJob(AbstractWorldObject source, AbstractWorldObject target, String stackType, int trains, ActionsBase action, PowersBase power, EffectsBase eb, ApplyEffectPowerAction def) { - super(source, target, stackType, trains, action, power, eb); - this.def = null; - } + public DeferredPowerJob(AbstractWorldObject source, AbstractWorldObject target, String stackType, int trains, ActionsBase action, PowersBase power, EffectsBase eb, ApplyEffectPowerAction def) { + super(source, target, stackType, trains, action, power, eb); + this.def = null; + } - @Override - protected void doJob() { - //Power ended with no attack, cancel weapon power boost - if (this.source != null && this.source instanceof PlayerCharacter) { - ((PlayerCharacter) this.source).setWeaponPower(null); - } - PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); - } + @Override + protected void doJob() { + //Power ended with no attack, cancel weapon power boost + if (this.source != null && this.source instanceof PlayerCharacter) { + ((PlayerCharacter) this.source).setWeaponPower(null); + } + PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); + } - @Override - protected void _cancelJob() { - //Attack happened. - PowersManager.cancelEffectTime(this.source, this.target, this.power, this.eb, this.action, this.trains, this); - } + @Override + protected void _cancelJob() { + //Attack happened. + PowersManager.cancelEffectTime(this.source, this.target, this.power, this.eb, this.action, this.trains, this); + } - public void attack(AbstractWorldObject tar, float attackRange) { + public void attack(AbstractWorldObject tar, float attackRange) { - if (this.source == null) - return; + if (this.source == null) + return; - if (!AbstractWorldObject.IsAbstractCharacter(tar)) - return; + if (!AbstractWorldObject.IsAbstractCharacter(tar)) + return; - if (this.power == null) - return; + if (this.power == null) + return; - switch(this.source.getObjectType()){ + switch (this.source.getObjectType()) { - case PlayerCharacter: + case PlayerCharacter: - if (def == null) { - //No powers applied, just reset weapon power. - ((PlayerCharacter) this.source).setWeaponPower(null); - return; - } - float powerRange = this.power.getWeaponRange(); + if (def == null) { + //No powers applied, just reset weapon power. + ((PlayerCharacter) this.source).setWeaponPower(null); + return; + } + float powerRange = this.power.getWeaponRange(); - // Wtf? Method returns TRUE if rage test fails? Seriously? + // Wtf? Method returns TRUE if rage test fails? Seriously? - //DO valid range check ONLY for weapon powers with range less than attack range. - if (attackRange > powerRange) - if (CombatManager.NotInRange((AbstractCharacter)this.source, tar, powerRange)) - return; + //DO valid range check ONLY for weapon powers with range less than attack range. + if (attackRange > powerRange) + if (CombatManager.NotInRange((AbstractCharacter) this.source, tar, powerRange)) + return; - //Range check passed, apply power and clear weapon power. - ((PlayerCharacter) this.source).setWeaponPower(null); + //Range check passed, apply power and clear weapon power. + ((PlayerCharacter) this.source).setWeaponPower(null); - //weapon powers with no deferedpoweraction have null Def, but still have bonuses applied already and will finish here. + //weapon powers with no deferedpoweraction have null Def, but still have bonuses applied already and will finish here. + PowersManager.applyPower((AbstractCharacter) this.source, tar, Vector3fImmutable.ZERO, def.getDeferredPowerID(), this.trains, false); + PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); + break; + case Mob: + ((Mob) this.source).setWeaponPower(null); + if (def == null) { + return; + } + PowersManager.applyPower((AbstractCharacter) this.source, tar, Vector3fImmutable.ZERO, def.getDeferredPowerID(), this.trains, false); + PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); + break; - PowersManager.applyPower((AbstractCharacter) this.source, tar, Vector3fImmutable.ZERO, def.getDeferredPowerID(), this.trains, false); - PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); - break; - case Mob: - ((Mob) this.source).setWeaponPower(null); - if (def == null) { - return; - } + } - PowersManager.applyPower((AbstractCharacter) this.source, tar, Vector3fImmutable.ZERO, def.getDeferredPowerID(), this.trains, false); - PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); - break; - - } - - } + } } diff --git a/src/engine/jobs/DoorCloseJob.java b/src/engine/jobs/DoorCloseJob.java index 1614fa96..44e50b21 100644 --- a/src/engine/jobs/DoorCloseJob.java +++ b/src/engine/jobs/DoorCloseJob.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -19,7 +16,6 @@ // www.magicbane.com - package engine.jobs; import engine.Enum.DoorState; @@ -48,10 +44,10 @@ public class DoorCloseJob extends AbstractScheduleJob { if (this.building == null) return; - doorNumber = Blueprint.getDoorNumberbyMesh(this.door); + doorNumber = Blueprint.getDoorNumberbyMesh(this.door); + + this.building.setDoorState(doorNumber, DoorState.CLOSED); - this.building.setDoorState(doorNumber, DoorState.CLOSED); - DoorTryOpenMsg msg = new DoorTryOpenMsg(door, this.building.getObjectUUID(), 0, (byte) 0); DispatchMessage.sendToAllInRange(building, msg); diff --git a/src/engine/jobs/EndFearJob.java b/src/engine/jobs/EndFearJob.java index 981ebd31..fef762d5 100644 --- a/src/engine/jobs/EndFearJob.java +++ b/src/engine/jobs/EndFearJob.java @@ -23,23 +23,23 @@ public class EndFearJob extends AbstractEffectJob { @Override protected void doJob() { - + //cancel fear for mob. - + if (this.target == null || (!(this.target instanceof Mob))) return; - + ((Mob) this.target).setFearedObject(null); } @Override protected void _cancelJob() { - + //cancel fear for mob. - - if (this.target == null || (!(this.target instanceof Mob))) + + if (this.target == null || (!(this.target instanceof Mob))) return; - + ((Mob) this.target).setFearedObject(null); } } diff --git a/src/engine/jobs/FinishSpireEffectJob.java b/src/engine/jobs/FinishSpireEffectJob.java index 09e6b147..d4b895e1 100644 --- a/src/engine/jobs/FinishSpireEffectJob.java +++ b/src/engine/jobs/FinishSpireEffectJob.java @@ -21,12 +21,12 @@ public class FinishSpireEffectJob extends AbstractEffectJob { @Override protected void doJob() { - + PlayerCharacter pc = (PlayerCharacter) target; - + if (pc == null) return; - + pc.endEffectNoPower(Integer.toString(eb.getUUID())); } diff --git a/src/engine/jobs/FinishSummonsJob.java b/src/engine/jobs/FinishSummonsJob.java index a375de8f..0ee0fc68 100644 --- a/src/engine/jobs/FinishSummonsJob.java +++ b/src/engine/jobs/FinishSummonsJob.java @@ -21,61 +21,61 @@ import java.util.concurrent.ConcurrentHashMap; public class FinishSummonsJob extends AbstractScheduleJob { - PlayerCharacter source; - PlayerCharacter target; + PlayerCharacter source; + PlayerCharacter target; - public FinishSummonsJob(PlayerCharacter source, PlayerCharacter target) { - super(); - this.source = source; - this.target = target; - } + public FinishSummonsJob(PlayerCharacter source, PlayerCharacter target) { + super(); + this.source = source; + this.target = target; + } - @Override - protected void doJob() { + @Override + protected void doJob() { - if (this.target == null) - return; + if (this.target == null) + return; - //clear summon timer + //clear summon timer - ConcurrentHashMap timers = this.target.getTimers(); + ConcurrentHashMap timers = this.target.getTimers(); - if (timers != null && timers.containsKey("Summon")) - timers.remove("Summon"); + if (timers != null && timers.containsKey("Summon")) + timers.remove("Summon"); - if (this.source == null || !this.source.isAlive() || !this.target.isAlive()) - return; + if (this.source == null || !this.source.isAlive() || !this.target.isAlive()) + return; - // cannot summon a player in combat - if (this.target.isCombat()) { + // cannot summon a player in combat + if (this.target.isCombat()) { - ErrorPopupMsg.sendErrorMsg(this.source, "Cannot summon player in combat."); + ErrorPopupMsg.sendErrorMsg(this.source, "Cannot summon player in combat."); - PowersManager.finishRecycleTime(428523680, this.source, false); - return; - } + PowersManager.finishRecycleTime(428523680, this.source, false); + return; + } - if (this.target.getBonuses() != null && this.target.getBonuses().getBool(ModType.BlockedPowerType, SourceType.SUMMON)) { - ErrorPopupMsg.sendErrorMsg(this.target, "You have been blocked from receiving summons!"); - ErrorPopupMsg.sendErrorMsg(this.source, "Target is blocked from receiving summons!"); - return; - } + if (this.target.getBonuses() != null && this.target.getBonuses().getBool(ModType.BlockedPowerType, SourceType.SUMMON)) { + ErrorPopupMsg.sendErrorMsg(this.target, "You have been blocked from receiving summons!"); + ErrorPopupMsg.sendErrorMsg(this.source, "Target is blocked from receiving summons!"); + return; + } - if (this.source.region != null) - this.target.setRegion(this.source.region); - //teleport target to source - target.teleport(source.getLoc()); - } + if (this.source.region != null) + this.target.setRegion(this.source.region); + //teleport target to source + target.teleport(source.getLoc()); + } - @Override - protected void _cancelJob() { - } + @Override + protected void _cancelJob() { + } - public PlayerCharacter getSource() { - return this.source; - } + public PlayerCharacter getSource() { + return this.source; + } - public PlayerCharacter getTarget() { - return this.target; - } + public PlayerCharacter getTarget() { + return this.target; + } } diff --git a/src/engine/jobs/LoadEffectsJob.java b/src/engine/jobs/LoadEffectsJob.java index f21ad973..4ad1ecb8 100644 --- a/src/engine/jobs/LoadEffectsJob.java +++ b/src/engine/jobs/LoadEffectsJob.java @@ -18,31 +18,31 @@ import java.util.ArrayList; public class LoadEffectsJob extends AbstractJob { - ArrayList acsToLoad; - ClientConnection originToSend; + ArrayList acsToLoad; + ClientConnection originToSend; - public LoadEffectsJob(ArrayList acsToLoad, ClientConnection origin) { - this.acsToLoad = acsToLoad; - this.originToSend = origin; + public LoadEffectsJob(ArrayList acsToLoad, ClientConnection origin) { + this.acsToLoad = acsToLoad; + this.originToSend = origin; - } + } - @Override - protected void doJob() { - if (this.originToSend == null) { - return; - } + @Override + protected void doJob() { + if (this.originToSend == null) { + return; + } - for (AbstractWorldObject awo : this.acsToLoad) { + for (AbstractWorldObject awo : this.acsToLoad) { - if (AbstractWorldObject.IsAbstractCharacter(awo)) { - AbstractCharacter acToLoad = (AbstractCharacter) awo; - acToLoad.sendAllEffects(this.originToSend); + if (AbstractWorldObject.IsAbstractCharacter(awo)) { + AbstractCharacter acToLoad = (AbstractCharacter) awo; + acToLoad.sendAllEffects(this.originToSend); - } + } - } + } - } + } } diff --git a/src/engine/jobs/LogoutCharacterJob.java b/src/engine/jobs/LogoutCharacterJob.java index cfdf60d2..3be22f07 100644 --- a/src/engine/jobs/LogoutCharacterJob.java +++ b/src/engine/jobs/LogoutCharacterJob.java @@ -29,9 +29,9 @@ public class LogoutCharacterJob extends AbstractScheduleJob { server.logoutCharacter(this.pc); } - @Override - protected void _cancelJob() { - // TODO Auto-generated method stub - - } + @Override + protected void _cancelJob() { + // TODO Auto-generated method stub + + } } diff --git a/src/engine/jobs/PersistentAoeJob.java b/src/engine/jobs/PersistentAoeJob.java index 33e7827c..68465274 100644 --- a/src/engine/jobs/PersistentAoeJob.java +++ b/src/engine/jobs/PersistentAoeJob.java @@ -24,87 +24,86 @@ import java.util.HashSet; public class PersistentAoeJob extends AbstractEffectJob { - private final AbstractEffectJob aej; - private int iteration = 0; - private Vector3fImmutable targetLoc; - private Vector3fImmutable lastLoc; + private final AbstractEffectJob aej; + private int iteration = 0; + private Vector3fImmutable targetLoc; + private Vector3fImmutable lastLoc; - public PersistentAoeJob(AbstractWorldObject source, AbstractWorldObject target, String stackType, int trains, ActionsBase action, PowersBase power, EffectsBase eb, AbstractEffectJob aej, Vector3fImmutable targetLoc) { - super(source, target, stackType, trains, action, power, eb); - this.aej = aej; - if (target != null && this.target.getObjectType() == GameObjectType.PlayerCharacter) - this.targetLoc = this.target.getLoc(); - else - this.targetLoc = targetLoc; - this.lastLoc = targetLoc; - } + public PersistentAoeJob(AbstractWorldObject source, AbstractWorldObject target, String stackType, int trains, ActionsBase action, PowersBase power, EffectsBase eb, AbstractEffectJob aej, Vector3fImmutable targetLoc) { + super(source, target, stackType, trains, action, power, eb); + this.aej = aej; + if (target != null && this.target.getObjectType() == GameObjectType.PlayerCharacter) + this.targetLoc = this.target.getLoc(); + else + this.targetLoc = targetLoc; + this.lastLoc = targetLoc; + } - @Override - protected void doJob() { + @Override + protected void doJob() { - if (this.aej == null || this.source == null || this.action == null || this.power == null || this.source == null || this.eb == null) - return; + if (this.aej == null || this.source == null || this.action == null || this.power == null || this.source == null || this.eb == null) + return; - if (!this.source.isAlive()) - PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); - else if (this.iteration < this.power.getChantIterations()) { + if (!this.source.isAlive()) + PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); + else if (this.iteration < this.power.getChantIterations()) { - this.skipSendEffect = true; - this.iteration++; + this.skipSendEffect = true; + this.iteration++; - if (this.target != null){ - this.lastLoc = this.target.getLoc(); - this.targetLoc = this.target.getLoc(); - } + if (this.target != null) { + this.lastLoc = this.target.getLoc(); + this.targetLoc = this.target.getLoc(); + } - String stackType = action.getStackType(); - stackType = (stackType.equals("IgnoreStack")) ? Integer.toString(action.getUUID()) : stackType; - HashSet awolist = null; + String stackType = action.getStackType(); + stackType = (stackType.equals("IgnoreStack")) ? Integer.toString(action.getUUID()) : stackType; + HashSet awolist = null; - if (this.source instanceof PlayerCharacter) - awolist = PowersManager.getAllTargets(null, this.targetLoc, (PlayerCharacter) this.source, this.power); - else - awolist = new HashSet<>(); - PerformActionMsg msg = new PerformActionMsg(power.getToken(), 9999, source - .getObjectType().ordinal(), source.getObjectUUID(), source.getObjectType().ordinal(), - source.getObjectUUID(), 0, 0, 0, 2, 0); + if (this.source instanceof PlayerCharacter) + awolist = PowersManager.getAllTargets(null, this.targetLoc, (PlayerCharacter) this.source, this.power); + else + awolist = new HashSet<>(); + PerformActionMsg msg = new PerformActionMsg(power.getToken(), 9999, source + .getObjectType().ordinal(), source.getObjectUUID(), source.getObjectType().ordinal(), + source.getObjectUUID(), 0, 0, 0, 2, 0); - for (AbstractWorldObject awo : awolist) { + for (AbstractWorldObject awo : awolist) { - //judge the defense of the target + //judge the defense of the target + if (awo == null + || PowersManager.testAttack((PlayerCharacter) this.source, awo, this.power, msg)) + continue; - if (awo == null - || PowersManager.testAttack((PlayerCharacter) this.source, awo, this.power, msg)) - continue; + PowersManager.finishApplyPowerA((AbstractCharacter) this.source, awo, this.targetLoc, this.power, this.trains, true); + if (this.target != null && !this.target.isAlive()) { + this.target = null; + } - PowersManager.finishApplyPowerA((AbstractCharacter) this.source, awo, this.targetLoc, this.power, this.trains, true); - if (this.target != null && !this.target.isAlive()){ - this.target = null; - } + } + if (AbstractWorldObject.IsAbstractCharacter(source)) + ((AbstractCharacter) this.source).addPersistantAoe(stackType, (int) (this.power.getChantDuration() * 1000), this, this.eb, this.trains); + } else + PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); + } - } - if (AbstractWorldObject.IsAbstractCharacter(source)) - ((AbstractCharacter) this.source).addPersistantAoe(stackType, (int) (this.power.getChantDuration() * 1000), this, this.eb, this.trains); - } else - PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); - } + @Override + protected void _cancelJob() { + } - @Override - protected void _cancelJob() { - } + public int getIteration() { + return this.iteration; + } - public int getIteration() { - return this.iteration; - } - - public int inc() { - this.iteration++; - return this.iteration; - } + public int inc() { + this.iteration++; + return this.iteration; + } } diff --git a/src/engine/jobs/RefreshGroupJob.java b/src/engine/jobs/RefreshGroupJob.java index 9d27abff..fcc7c9c9 100644 --- a/src/engine/jobs/RefreshGroupJob.java +++ b/src/engine/jobs/RefreshGroupJob.java @@ -18,10 +18,10 @@ import engine.objects.PlayerCharacter; public class RefreshGroupJob extends AbstractJob { private final PlayerCharacter pc; + private final boolean wholeGroup; private ClientConnection origin; private Group grp; private PlayerCharacter pcToRefresh; - private final boolean wholeGroup; public RefreshGroupJob(PlayerCharacter pc, PlayerCharacter pcToRefresh) { super(); @@ -52,21 +52,21 @@ public class RefreshGroupJob extends AbstractJob { } if (wholeGroup) { - + // refresh everyone in the group including me // check that we are in the same group as when we submitted the job - + if (GroupManager.getGroup(pc) != null && GroupManager.getGroup(pc) == grp) { - - // refresh pc's group list for just the one player that needed refreshing - + + // refresh pc's group list for just the one player that needed refreshing + GroupManager.RefreshMyGroupList(pc, origin); GroupManager.RefreshOthersGroupList(pc); } return; - } - + } + // only refresh the single player if (this.pcToRefresh == null) return; diff --git a/src/engine/jobs/RemoveCorpseJob.java b/src/engine/jobs/RemoveCorpseJob.java index ff4d1fbf..78bf73bd 100644 --- a/src/engine/jobs/RemoveCorpseJob.java +++ b/src/engine/jobs/RemoveCorpseJob.java @@ -23,10 +23,10 @@ public class RemoveCorpseJob extends AbstractScheduleJob { @Override protected void doJob() { - + if (this.corpse != null) Corpse.removeCorpse(corpse, true); - + } @Override diff --git a/src/engine/jobs/SiegeSpireWithdrawlJob.java b/src/engine/jobs/SiegeSpireWithdrawlJob.java index cd2bbf79..dbd270af 100644 --- a/src/engine/jobs/SiegeSpireWithdrawlJob.java +++ b/src/engine/jobs/SiegeSpireWithdrawlJob.java @@ -17,62 +17,61 @@ import org.pmw.tinylog.Logger; public class SiegeSpireWithdrawlJob extends AbstractScheduleJob { - private Building spire = null; - - public SiegeSpireWithdrawlJob(Building spire) { - super(); - this.spire = spire; - } - - @Override - protected void doJob() { - - if (spire == null) - return; - - // Early exit if someone disabled the spire - - if (!spire.isSpireIsActive()) - return; - - City buildingCity = spire.getCity(); - - if (buildingCity == null) - return; - - - - buildingCity.transactionLock.writeLock().lock(); - try{ - - // If the spire runs out of money, disable it. - //*** Refactor: 5000 every 30 seconds? Wtf? - - if (!spire.hasFunds(5000)){ - spire.disableSpire(true); - return; - } - if (spire.getStrongboxValue() < 5000) { - spire.disableSpire(true); - return; - } - - // Deduct the activation cost from the strongbox and resubmit the job - - if (!spire.transferGold(-5000,false)) - return; - JobContainer jc = JobScheduler.getInstance().scheduleJob(new SiegeSpireWithdrawlJob(spire), 300000); - spire.getTimers().put("SpireWithdrawl", jc); - - }catch(Exception e){ - Logger.error(e); - }finally{ - buildingCity.transactionLock.writeLock().unlock(); - } - - } - - @Override - protected void _cancelJob() { - } + private Building spire = null; + + public SiegeSpireWithdrawlJob(Building spire) { + super(); + this.spire = spire; + } + + @Override + protected void doJob() { + + if (spire == null) + return; + + // Early exit if someone disabled the spire + + if (!spire.isSpireIsActive()) + return; + + City buildingCity = spire.getCity(); + + if (buildingCity == null) + return; + + + buildingCity.transactionLock.writeLock().lock(); + try { + + // If the spire runs out of money, disable it. + //*** Refactor: 5000 every 30 seconds? Wtf? + + if (!spire.hasFunds(5000)) { + spire.disableSpire(true); + return; + } + if (spire.getStrongboxValue() < 5000) { + spire.disableSpire(true); + return; + } + + // Deduct the activation cost from the strongbox and resubmit the job + + if (!spire.transferGold(-5000, false)) + return; + JobContainer jc = JobScheduler.getInstance().scheduleJob(new SiegeSpireWithdrawlJob(spire), 300000); + spire.getTimers().put("SpireWithdrawl", jc); + + } catch (Exception e) { + Logger.error(e); + } finally { + buildingCity.transactionLock.writeLock().unlock(); + } + + } + + @Override + protected void _cancelJob() { + } } diff --git a/src/engine/jobs/SummonSendJob.java b/src/engine/jobs/SummonSendJob.java index ff237410..0e5951a4 100644 --- a/src/engine/jobs/SummonSendJob.java +++ b/src/engine/jobs/SummonSendJob.java @@ -28,14 +28,14 @@ public class SummonSendJob extends AbstractScheduleJob { @Override protected void doJob() { - - if (this.source == null) + + if (this.source == null) return; //clear summon send timer ConcurrentHashMap timers = this.source.getTimers(); - - if (timers != null && timers.containsKey("SummonSend")) + + if (timers != null && timers.containsKey("SummonSend")) timers.remove("SummonSend"); } diff --git a/src/engine/jobs/TeleportJob.java b/src/engine/jobs/TeleportJob.java index 7f1d43aa..0bb94f8e 100644 --- a/src/engine/jobs/TeleportJob.java +++ b/src/engine/jobs/TeleportJob.java @@ -23,8 +23,8 @@ public class TeleportJob extends AbstractScheduleJob { private final NPC npc; private final PlayerCharacter pc; private final Vector3fImmutable loc; - private int oldLiveCounter; private final boolean setSafeMode; + private int oldLiveCounter; public TeleportJob(PlayerCharacter pc, NPC npc, Vector3fImmutable loc, ClientConnection origin, boolean setSafeMode) { super(); @@ -40,23 +40,23 @@ public class TeleportJob extends AbstractScheduleJob { @Override protected void doJob() { - + if (this.pc == null || this.npc == null || this.origin == null) return; if (!pc.isAlive() || this.oldLiveCounter != pc.getLiveCounter()) return; - + if (pc.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) { ErrorPopupMsg.sendErrorPopup(pc, 114); return; } pc.teleport(loc); - + if (this.setSafeMode) pc.setSafeMode(); - + } @Override diff --git a/src/engine/jobs/TrackJob.java b/src/engine/jobs/TrackJob.java index f46921b2..066292b4 100644 --- a/src/engine/jobs/TrackJob.java +++ b/src/engine/jobs/TrackJob.java @@ -36,33 +36,33 @@ public class TrackJob extends AbstractEffectJob { @Override protected void doJob() { - + if (this.tpa == null || this.target == null || this.action == null || this.source == null || this.eb == null || !(this.source instanceof PlayerCharacter)) return; - if (this.target.isAlive() == false) { + if (this.target.isAlive() == false) { sendTrackArrow(Float.intBitsToFloat(0x7E967699)); PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); return; } - - String stackType = action.getStackType(); - float distanceSquared = this.target.getLoc().distanceSquared2D(this.source.getLoc()); + String stackType = action.getStackType(); + + float distanceSquared = this.target.getLoc().distanceSquared2D(this.source.getLoc()); + + int speed; - int speed; - - if (distanceSquared < sqr(MBServerStatics.TRACK_ARROW_FAST_RANGE)) - speed = MBServerStatics.TRACK_ARROW_SENSITIVITY_FAST; - else - speed = MBServerStatics.TRACK_ARROW_SENSITIVITY; + if (distanceSquared < sqr(MBServerStatics.TRACK_ARROW_FAST_RANGE)) + speed = MBServerStatics.TRACK_ARROW_SENSITIVITY_FAST; + else + speed = MBServerStatics.TRACK_ARROW_SENSITIVITY; - this.source.addEffect(stackType, speed, this, this.eb, this.trains); + this.source.addEffect(stackType, speed, this, this.eb, this.trains); - Vector3fImmutable dir = this.target.getLoc().subtract2D(this.source.getLoc()); - dir = dir.normalize(); + Vector3fImmutable dir = this.target.getLoc().subtract2D(this.source.getLoc()); + dir = dir.normalize(); - sendTrackArrow(dir.getRotation()); + sendTrackArrow(dir.getRotation()); } @@ -73,7 +73,7 @@ public class TrackJob extends AbstractEffectJob { } private void sendTrackArrow(float rotation) { - + if (this.source != null && this.source instanceof PlayerCharacter) { PlayerCharacter pc = (PlayerCharacter) this.source; @@ -87,6 +87,6 @@ public class TrackJob extends AbstractEffectJob { DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); } -} + } } diff --git a/src/engine/jobs/TransferStatOTJob.java b/src/engine/jobs/TransferStatOTJob.java index 62d54a6f..e4fa31ac 100644 --- a/src/engine/jobs/TransferStatOTJob.java +++ b/src/engine/jobs/TransferStatOTJob.java @@ -19,56 +19,56 @@ import engine.powers.poweractions.TransferStatOTPowerAction; public class TransferStatOTJob extends AbstractEffectJob { - private final TransferStatOTPowerAction dot; - private int iteration = 0; - - public TransferStatOTJob(AbstractWorldObject source, AbstractWorldObject target, String stackType, int trains, ActionsBase action, PowersBase power, EffectsBase eb, TransferStatOTPowerAction dot) { - super(source, target, stackType, trains, action, power, eb); - this.dot = dot; - this.iteration = action.getDurationInSeconds(trains) / this.dot.getNumIterations(); - } - - @Override - protected void doJob() { - if (this.dot == null || this.target == null || this.action == null || this.source == null || this.eb == null || this.action == null || this.power == null) - return; - if (!this.target.isAlive()){ - PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); - return; - } - - iteration--; - - if (iteration < 0){ - PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); - return; - } - - this.skipSendEffect = true; - - String stackType = action.getStackType(); - stackType = (stackType.equals("IgnoreStack")) ? Integer.toString(action.getUUID()) : stackType; - this.target.addEffect(stackType, getTickLength(), this, this.eb, this.trains); - if (AbstractWorldObject.IsAbstractCharacter(source)) - this.dot.runAction((AbstractCharacter)this.source, this.target, this.trains, this.action, this.power); - - } - - @Override - protected void _cancelJob() { - PowersManager.cancelEffectTime(this.source, this.target, this.power, this.eb, this.action, this.trains, this); - } - - public int getIteration() { - return this.iteration; - } - - public int getTickLength() { - return this.dot.getNumIterations() * 1000; - } - - public int inc() { - this.iteration++; - return this.iteration; - } + private final TransferStatOTPowerAction dot; + private int iteration = 0; + + public TransferStatOTJob(AbstractWorldObject source, AbstractWorldObject target, String stackType, int trains, ActionsBase action, PowersBase power, EffectsBase eb, TransferStatOTPowerAction dot) { + super(source, target, stackType, trains, action, power, eb); + this.dot = dot; + this.iteration = action.getDurationInSeconds(trains) / this.dot.getNumIterations(); + } + + @Override + protected void doJob() { + if (this.dot == null || this.target == null || this.action == null || this.source == null || this.eb == null || this.action == null || this.power == null) + return; + if (!this.target.isAlive()) { + PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); + return; + } + + iteration--; + + if (iteration < 0) { + PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains); + return; + } + + this.skipSendEffect = true; + + String stackType = action.getStackType(); + stackType = (stackType.equals("IgnoreStack")) ? Integer.toString(action.getUUID()) : stackType; + this.target.addEffect(stackType, getTickLength(), this, this.eb, this.trains); + if (AbstractWorldObject.IsAbstractCharacter(source)) + this.dot.runAction((AbstractCharacter) this.source, this.target, this.trains, this.action, this.power); + + } + + @Override + protected void _cancelJob() { + PowersManager.cancelEffectTime(this.source, this.target, this.power, this.eb, this.action, this.trains, this); + } + + public int getIteration() { + return this.iteration; + } + + public int getTickLength() { + return this.dot.getNumIterations() * 1000; + } + + public int inc() { + this.iteration++; + return this.iteration; + } } diff --git a/src/engine/jobs/UpdateGroupJob.java b/src/engine/jobs/UpdateGroupJob.java index db391898..5d31f0a3 100644 --- a/src/engine/jobs/UpdateGroupJob.java +++ b/src/engine/jobs/UpdateGroupJob.java @@ -27,19 +27,19 @@ public class UpdateGroupJob extends AbstractScheduleJob { @Override protected void doJob() { - + if (this.group == null) return; - + PlayerCharacter lead = group.getGroupLead(); - + if (lead == null) return; try { GroupManager.RefreshWholeGroupList(lead, lead.getClientConnection(), this.group); } catch (Exception e) { - Logger.error( e); + Logger.error(e); } JobScheduler.getInstance().scheduleJob(this, MBServerStatics.UPDATE_GROUP_RATE); diff --git a/src/engine/jobs/UpgradeBuildingJob.java b/src/engine/jobs/UpgradeBuildingJob.java index 510308e6..c9032af9 100644 --- a/src/engine/jobs/UpgradeBuildingJob.java +++ b/src/engine/jobs/UpgradeBuildingJob.java @@ -11,45 +11,43 @@ import org.pmw.tinylog.Logger; */ public class UpgradeBuildingJob extends AbstractScheduleJob { - private final Building rankingBuilding; + private final Building rankingBuilding; - public UpgradeBuildingJob(Building building) { - super(); - this.rankingBuilding = building; + public UpgradeBuildingJob(Building building) { + super(); + this.rankingBuilding = building; - } + } - @Override - protected void doJob() { + @Override + protected void doJob() { + // Must have a building to rank! - // Must have a building to rank! + if (rankingBuilding == null) { + Logger.error("Attempting to rank null building"); + return; + } - if (rankingBuilding == null) { - Logger.error("Attempting to rank null building"); - return; - } + // Make sure the building is currently set to upgrade + // (Duplicate job sanity check) - // Make sure the building is currently set to upgrade - // (Duplicate job sanity check) + if (rankingBuilding.isRanking() == false) + return; - if (rankingBuilding.isRanking() == false) - return; + // SetCurrentRank also changes the mesh and maxhp + // accordingly for buildings with blueprints - // SetCurrentRank also changes the mesh and maxhp - // accordingly for buildings with blueprints + rankingBuilding.setRank(rankingBuilding.getRank() + 1); - rankingBuilding.setRank(rankingBuilding.getRank() + 1); + // Reload the object - // Reload the object + } - - } - - @Override - protected void _cancelJob() { - } + @Override + protected void _cancelJob() { + } } diff --git a/src/engine/jobs/UpgradeNPCJob.java b/src/engine/jobs/UpgradeNPCJob.java index 23d0c5fb..d080746c 100644 --- a/src/engine/jobs/UpgradeNPCJob.java +++ b/src/engine/jobs/UpgradeNPCJob.java @@ -18,47 +18,45 @@ import engine.objects.NPC; public class UpgradeNPCJob extends AbstractScheduleJob { - private final AbstractCharacter rankingAC; - boolean success; + private final AbstractCharacter rankingAC; + boolean success; - public UpgradeNPCJob(AbstractCharacter ac) { - super(); - this.rankingAC = ac; - } + public UpgradeNPCJob(AbstractCharacter ac) { + super(); + this.rankingAC = ac; + } - @Override - protected void doJob() { + @Override + protected void doJob() { - int newRank; + int newRank; - if (this.rankingAC.getObjectType() == GameObjectType.NPC){ + if (this.rankingAC.getObjectType() == GameObjectType.NPC) { - if (this.rankingAC == null) //NPC could've been removed... - return; - newRank = (this.rankingAC.getRank() * 10) + 10; - - + if (this.rankingAC == null) //NPC could've been removed... + return; + newRank = (this.rankingAC.getRank() * 10) + 10; - ((NPC)this.rankingAC).setRank(newRank); - ((NPC)this.rankingAC).setUpgradeDateTime(null); - }else if (this.rankingAC.getObjectType() == GameObjectType.Mob){ - if (this.rankingAC == null) //NPC could've been removed... - return; - newRank = (this.rankingAC.getRank() * 10) + 10; + ((NPC) this.rankingAC).setRank(newRank); + ((NPC) this.rankingAC).setUpgradeDateTime(null); + } else if (this.rankingAC.getObjectType() == GameObjectType.Mob) { + if (this.rankingAC == null) //NPC could've been removed... + return; + newRank = (this.rankingAC.getRank() * 10) + 10; - ((Mob)this.rankingAC).setRank(newRank); - Mob.setUpgradeDateTime((Mob)this.rankingAC, null); - WorldGrid.updateObject(this.rankingAC); + ((Mob) this.rankingAC).setRank(newRank); + Mob.setUpgradeDateTime((Mob) this.rankingAC, null); + WorldGrid.updateObject(this.rankingAC); - } + } - } + } - @Override - protected void _cancelJob() { - } + @Override + protected void _cancelJob() { + } } diff --git a/src/engine/jobs/UseItemJob.java b/src/engine/jobs/UseItemJob.java index 5f2be44b..008e74a7 100644 --- a/src/engine/jobs/UseItemJob.java +++ b/src/engine/jobs/UseItemJob.java @@ -40,7 +40,7 @@ public class UseItemJob extends AbstractScheduleJob { @Override protected void _cancelJob() { - this.ac.setItemCasting(false); + this.ac.setItemCasting(false); } public PowersBase getPowersBase() { diff --git a/src/engine/loot/LootManager.java b/src/engine/loot/LootManager.java index db8fcb0f..f83acd7c 100644 --- a/src/engine/loot/LootManager.java +++ b/src/engine/loot/LootManager.java @@ -16,11 +16,11 @@ import engine.gameManager.ZoneManager; import engine.net.DispatchMessage; import engine.net.client.msg.chat.ChatSystemMsg; import engine.objects.*; + import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; -import java.util.Map; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; @@ -30,12 +30,14 @@ import java.util.concurrent.ThreadLocalRandom; public class LootManager { //new tables - private static final HashMap generalItemTables = new HashMap<>(); - private static final HashMap itemTables = new HashMap<>(); - private static final HashMap modTypeTables = new HashMap<>(); - private static final HashMap modTables = new HashMap<>(); + private static final HashMap generalItemTables = new HashMap<>(); + private static final HashMap itemTables = new HashMap<>(); + private static final HashMap modTypeTables = new HashMap<>(); + private static final HashMap modTables = new HashMap<>(); + + private LootManager() { + } - private LootManager() {} // Bootstrap routine to load loot data from database public static void loadLootData() { DbManager.LootQueries.LOAD_ALL_LOOTGROUPS(); @@ -43,7 +45,8 @@ public class LootManager { DbManager.LootQueries.LOAD_ALL_MODGROUPS(); DbManager.LootQueries.LOAD_ALL_MODTABLES(); } - public static void GenerateMobLoot(Mob mob, boolean fromDeath){ + + public static void GenerateMobLoot(Mob mob, boolean fromDeath) { //determine if mob is in hotzone boolean inHotzone = ZoneManager.inHotZone(mob.getLoc()); //get multiplier form config manager @@ -53,14 +56,14 @@ public class LootManager { multiplier = Float.parseFloat(ConfigManager.MB_HOTZONE_DROP_RATE.getValue()); } //iterate the booty sets - if(mob.getMobBase().bootySet != 0 && NPCManager._bootySetMap.containsKey(mob.getMobBase().bootySet)) { + if (mob.getMobBase().bootySet != 0 && NPCManager._bootySetMap.containsKey(mob.getMobBase().bootySet)) { RunBootySet(NPCManager._bootySetMap.get(mob.getMobBase().bootySet), mob, multiplier, inHotzone, fromDeath); } - if(mob.bootySet != 0) { + if (mob.bootySet != 0) { RunBootySet(NPCManager._bootySetMap.get(mob.bootySet), mob, multiplier, inHotzone, fromDeath); } //lastly, check mobs inventory for godly or disc runes to send a server announcement - if(!fromDeath) { + if (!fromDeath) { for (Item it : mob.getInventory()) { ItemBase ib = it.getItemBase(); if (ib.isDiscRune() || ib.getName().toLowerCase().contains("of the gods")) { @@ -72,16 +75,17 @@ public class LootManager { } } } + private static void RunBootySet(ArrayList entries, Mob mob, float multiplier, boolean inHotzone, boolean fromDeath) { - if(fromDeath){ + if (fromDeath) { //do equipment here - if (mob.getEquip() != null){ - for (MobEquipment me : mob.getEquip().values()){ + if (mob.getEquip() != null) { + for (MobEquipment me : mob.getEquip().values()) { if (me.getDropChance() == 0) continue; float equipmentRoll = ThreadLocalRandom.current().nextFloat(); float dropChance = me.getDropChance(); - if (equipmentRoll < dropChance * multiplier){ + if (equipmentRoll < dropChance * multiplier) { MobLoot ml = new MobLoot(mob, me.getItemBase(), false); mob.getCharItemManager().addItemToInventory(ml); } @@ -131,170 +135,185 @@ public class LootManager { } } } - public static MobLoot getGenTableItem(int genTableID, Mob mob){ - if(genTableID == 0 ||mob == null || generalItemTables.containsKey(genTableID) == false){ + + public static MobLoot getGenTableItem(int genTableID, Mob mob) { + if (genTableID == 0 || mob == null || generalItemTables.containsKey(genTableID) == false) { return null; } MobLoot outItem; int roll = new Random().nextInt(101); GenTableRow selectedRow = generalItemTables.get(genTableID).getRowForRange(roll); - if(selectedRow == null) { - return null; + if (selectedRow == null) { + return null; } int itemTableId = selectedRow.itemTableID; int minRollRange = mob.getLevel() + roll + mob.getParentZone().minLvl; //add 20 to max roll range to make dwarven HA and Sage possible int maxRollRange = (mob.getLevel() * 2) + roll + 20 + (mob.getParentZone().maxLvl * 2); - if(maxRollRange > 320){ + if (maxRollRange > 320) { maxRollRange = 320; } - int roll2 = new Random().nextInt(maxRollRange- minRollRange) + minRollRange; + int roll2 = new Random().nextInt(maxRollRange - minRollRange) + minRollRange; ItemTableRow tableRow = itemTables.get(itemTableId).getRowForRange(roll2); - if(tableRow == null){ + if (tableRow == null) { return null; } int itemUUID = tableRow.cacheID; - if(itemUUID == 0){ + if (itemUUID == 0) { return null; } - if(ItemBase.getItemBase(itemUUID).getType().ordinal() == Enum.ItemType.RESOURCE.ordinal()){ + if (ItemBase.getItemBase(itemUUID).getType().ordinal() == Enum.ItemType.RESOURCE.ordinal()) { int amount = ThreadLocalRandom.current().nextInt(tableRow.maxSpawn - tableRow.minSpawn) + tableRow.minSpawn; - return new MobLoot(mob, ItemBase.getItemBase(itemUUID),amount, false); + return new MobLoot(mob, ItemBase.getItemBase(itemUUID), amount, false); } outItem = new MobLoot(mob, ItemBase.getItemBase(itemUUID), false); Enum.ItemType outType = outItem.getItemBase().getType(); - if(outType.ordinal() == Enum.ItemType.WEAPON.ordinal() || outType.ordinal() == Enum.ItemType.ARMOR.ordinal() || outType.ordinal() == Enum.ItemType.JEWELRY.ordinal()) { - if(outItem.getItemBase().isGlass() == false) { - ModTypeTable prefixTable = modTypeTables.get(selectedRow.pModTable); - ModTypeTable suffixTable = modTypeTables.get(selectedRow.sModTable); - if (modTables.get(prefixTable.getRowForRange(100).modTableID) != null) { - ModTable prefixModTable = modTables.get(prefixTable.getRowForRange(100).modTableID); - ModTableRow prefixMod = prefixModTable.getRowForRange(new Random().nextInt(maxRollRange) + minRollRange); - if (prefixMod != null && prefixMod.action.length() > 0) { - outItem.setPrefix(prefixMod.action); - outItem.addPermanentEnchantment(prefixMod.action, 0, prefixMod.level, true); - } - } - if (modTables.get(suffixTable.getRowForRange(100).modTableID) != null) { - ModTable suffixModTable = modTables.get(suffixTable.getRowForRange(100).modTableID); - ModTableRow suffixMod = suffixModTable.getRowForRange(new Random().nextInt(maxRollRange) + minRollRange); - if (suffixMod != null && suffixMod.action.length() > 0) { - outItem.setSuffix(suffixMod.action); - outItem.addPermanentEnchantment(suffixMod.action, 0, suffixMod.level, true); - } - } - } + if (outType.ordinal() == Enum.ItemType.WEAPON.ordinal() || outType.ordinal() == Enum.ItemType.ARMOR.ordinal() || outType.ordinal() == Enum.ItemType.JEWELRY.ordinal()) { + if (outItem.getItemBase().isGlass() == false) { + ModTypeTable prefixTable = modTypeTables.get(selectedRow.pModTable); + ModTypeTable suffixTable = modTypeTables.get(selectedRow.sModTable); + if (modTables.get(prefixTable.getRowForRange(100).modTableID) != null) { + ModTable prefixModTable = modTables.get(prefixTable.getRowForRange(100).modTableID); + ModTableRow prefixMod = prefixModTable.getRowForRange(new Random().nextInt(maxRollRange) + minRollRange); + if (prefixMod != null && prefixMod.action.length() > 0) { + outItem.setPrefix(prefixMod.action); + outItem.addPermanentEnchantment(prefixMod.action, 0, prefixMod.level, true); + } + } + if (modTables.get(suffixTable.getRowForRange(100).modTableID) != null) { + ModTable suffixModTable = modTables.get(suffixTable.getRowForRange(100).modTableID); + ModTableRow suffixMod = suffixModTable.getRowForRange(new Random().nextInt(maxRollRange) + minRollRange); + if (suffixMod != null && suffixMod.action.length() > 0) { + outItem.setSuffix(suffixMod.action); + outItem.addPermanentEnchantment(suffixMod.action, 0, suffixMod.level, true); + } + } + } } return outItem; } - public static void AddGenTableRow(int tableID,GenTableRow row){ - if(!generalItemTables.containsKey(tableID)){ + + public static void AddGenTableRow(int tableID, GenTableRow row) { + if (!generalItemTables.containsKey(tableID)) { //create the new table GenTable gt = new GenTable(); gt.rows.add(row); - generalItemTables.put(tableID,gt); - } else{ + generalItemTables.put(tableID, gt); + } else { //add row to existing table GenTable toAdd = generalItemTables.get(tableID); toAdd.rows.add(row); } } - public static void AddItemTableRow(int tableID, ItemTableRow row){ - if(!itemTables.containsKey(tableID)){ + + public static void AddItemTableRow(int tableID, ItemTableRow row) { + if (!itemTables.containsKey(tableID)) { //create the new table ItemTable it = new ItemTable(); it.rows.add(row); - itemTables.put(tableID,it); - } else{ + itemTables.put(tableID, it); + } else { //add row to existing table ItemTable toAdd = itemTables.get(tableID); toAdd.rows.add(row); } } - public static void AddModTypeTableRow(int tableID, ModTypeTableRow row){ - if(!modTypeTables.containsKey(tableID)){ + + public static void AddModTypeTableRow(int tableID, ModTypeTableRow row) { + if (!modTypeTables.containsKey(tableID)) { //create the new table ModTypeTable mtt = new ModTypeTable(); mtt.rows.add(row); - modTypeTables.put(tableID,mtt); - } else{ + modTypeTables.put(tableID, mtt); + } else { //add row to existing table ModTypeTable toAdd = modTypeTables.get(tableID); toAdd.rows.add(row); } } - public static void AddModTableRow(int tableID,ModTableRow row){ - if(!modTables.containsKey(tableID)){ + + public static void AddModTableRow(int tableID, ModTableRow row) { + if (!modTables.containsKey(tableID)) { //create the new table ModTable mt = new ModTable(); mt.rows.add(row); - modTables.put(tableID,mt); - } else{ + modTables.put(tableID, mt); + } else { //add row to existing table ModTable toAdd = modTables.get(tableID); toAdd.rows.add(row); } } - public static class GenTable{ + + public static class GenTable { public ArrayList rows = new ArrayList(); - public GenTableRow getRowForRange(int roll){ + + public GenTableRow getRowForRange(int roll) { GenTableRow outRow = null; - for(GenTableRow iteration : this.rows){ - if(roll >= iteration.minRoll && roll <= iteration.maxRoll){ + for (GenTableRow iteration : this.rows) { + if (roll >= iteration.minRoll && roll <= iteration.maxRoll) { outRow = iteration; } } return outRow; } } - public static class ItemTable{ + + public static class ItemTable { public ArrayList rows = new ArrayList(); - public ItemTableRow getRowForRange(int roll){ - if(roll > 320){ + + public ItemTableRow getRowForRange(int roll) { + if (roll > 320) { roll = 320; } ItemTableRow outRow = null; - for(ItemTableRow iteration : this.rows){ - if(roll >= iteration.minRoll && roll <= iteration.maxRoll){ + for (ItemTableRow iteration : this.rows) { + if (roll >= iteration.minRoll && roll <= iteration.maxRoll) { outRow = iteration; } } return outRow; } } - public static class ModTypeTable{ + + public static class ModTypeTable { public ArrayList rows = new ArrayList(); - public ModTypeTableRow getRowForRange(int roll){ + + public ModTypeTableRow getRowForRange(int roll) { ModTypeTableRow outRow = null; - for(ModTypeTableRow iteration : this.rows){ - if(roll >= iteration.minRoll && roll <= iteration.maxRoll){ + for (ModTypeTableRow iteration : this.rows) { + if (roll >= iteration.minRoll && roll <= iteration.maxRoll) { return iteration; } } return outRow; } } - public static class ModTable{ + + public static class ModTable { public ArrayList rows = new ArrayList(); - public ModTableRow getRowForRange(int roll){ - if(roll > 320){ + + public ModTableRow getRowForRange(int roll) { + if (roll > 320) { roll = 320; } ModTableRow outRow = null; - for(ModTableRow iteration : this.rows){ - if(roll >= iteration.minRoll && roll <= iteration.maxRoll){ + for (ModTableRow iteration : this.rows) { + if (roll >= iteration.minRoll && roll <= iteration.maxRoll) { outRow = iteration; } } return outRow; } } - public static class GenTableRow{ + + public static class GenTableRow { public int minRoll; public int maxRoll; public int itemTableID; public int pModTable; public int sModTable; + public GenTableRow(ResultSet rs) throws SQLException { this.minRoll = rs.getInt("minRoll"); this.maxRoll = rs.getInt("maxRoll"); @@ -303,12 +322,14 @@ public class LootManager { this.sModTable = rs.getInt("sModTableID"); } } - public static class ItemTableRow{ + + public static class ItemTableRow { public int minRoll; public int maxRoll; public int cacheID; public int minSpawn; public int maxSpawn; + public ItemTableRow(ResultSet rs) throws SQLException { this.minRoll = rs.getInt("minRoll"); this.maxRoll = rs.getInt("maxRoll"); @@ -318,10 +339,12 @@ public class LootManager { } } - public static class ModTypeTableRow{ + + public static class ModTypeTableRow { public int minRoll; public int maxRoll; public int modTableID; + public ModTypeTableRow(ResultSet rs) throws SQLException { this.minRoll = rs.getInt("minRoll"); this.maxRoll = rs.getInt("maxRoll"); @@ -329,11 +352,13 @@ public class LootManager { } } - public static class ModTableRow{ + + public static class ModTableRow { public int minRoll; public int maxRoll; public String action; public int level; + public ModTableRow(ResultSet rs) throws SQLException { this.minRoll = rs.getInt("minRoll"); this.maxRoll = rs.getInt("maxRoll"); diff --git a/src/engine/math/Bounds.java b/src/engine/math/Bounds.java index 08d40e32..04998e1c 100644 --- a/src/engine/math/Bounds.java +++ b/src/engine/math/Bounds.java @@ -30,554 +30,537 @@ import java.util.concurrent.LinkedBlockingQueue; public class Bounds { - private static final LinkedBlockingQueue boundsPool = new LinkedBlockingQueue<>(); - public static HashMap meshBoundsCache = new HashMap<>(); + private static final LinkedBlockingQueue boundsPool = new LinkedBlockingQueue<>(); + public static HashMap meshBoundsCache = new HashMap<>(); - private Vector2f origin = new Vector2f(); - private Vector2f halfExtents = new Vector2f(); - private float rotation; - private float rotationDegrees = 0; - private Quaternion quaternion; - private boolean flipExtents; + private Vector2f origin = new Vector2f(); + private Vector2f halfExtents = new Vector2f(); + private float rotation; + private float rotationDegrees = 0; + private Quaternion quaternion; + private boolean flipExtents; - private ArrayList regions = new ArrayList<>(); - private ArrayList colliders = new ArrayList<>(); + private ArrayList regions = new ArrayList<>(); + private ArrayList colliders = new ArrayList<>(); - // Default constructor + // Default constructor - public Bounds() { + public Bounds() { - origin.zero(); - halfExtents.zero(); - rotation = 0.0f; - flipExtents = false; - } + origin.zero(); + halfExtents.zero(); + rotation = 0.0f; + flipExtents = false; + } + + public static Bounds borrow() { + Bounds outBounds; + + outBounds = boundsPool.poll(); + + if (outBounds == null) + outBounds = new Bounds(); + + return outBounds; + } + + // Identity Bounds at location + public static void zero(Bounds bounds) { + bounds.origin.zero(); + bounds.halfExtents.zero(); + bounds.rotation = 0.0f; + bounds.flipExtents = false; + } + + public static boolean collide(Vector3fImmutable location, Bounds targetBounds) { + + if (targetBounds == null) + return false; + + boolean collisionState = false; + Bounds identityBounds = Bounds.borrow(); + identityBounds.setBounds(location); + + collisionState = collide(targetBounds, identityBounds, 0.0f); + identityBounds.release(); + return collisionState; + } + + public static boolean collide(Vector3fImmutable location, Building targetBuilding) { + + boolean collisionState = false; + Bounds targetBounds = targetBuilding.getBounds(); + + if (targetBounds == null) + return false; + Bounds identityBounds = Bounds.borrow(); + identityBounds.setBounds(location); + + collisionState = collide(targetBounds, identityBounds, 0.1f); + identityBounds.release(); + return collisionState; + } + + public static boolean collide(Bounds sourceBounds, Bounds targetBounds, float threshold) { + + float deltaX; + float deltaY; + float extentX; + float extentY; + float sourceExtentX; + float sourceExtentY; + float targetExtentX; + float targetExtentY; + + deltaX = Math.abs(sourceBounds.origin.x - targetBounds.origin.x); + deltaY = Math.abs(sourceBounds.origin.y - targetBounds.origin.y); + + if (sourceBounds.flipExtents) { + sourceExtentX = sourceBounds.halfExtents.y; + sourceExtentY = sourceBounds.halfExtents.x; + } else { + sourceExtentX = sourceBounds.halfExtents.x; + sourceExtentY = sourceBounds.halfExtents.y; + } + if (targetBounds.flipExtents) { + targetExtentX = targetBounds.halfExtents.y; + targetExtentY = targetBounds.halfExtents.x; + } else { + targetExtentX = targetBounds.halfExtents.x; + targetExtentY = targetBounds.halfExtents.y; + } + + extentX = sourceExtentX + targetExtentX; + extentY = sourceExtentY + targetExtentY; + + // Return false on overlapping edge cases + if ((Math.abs(deltaX + threshold) < extentX)) + if ((Math.abs(deltaY + threshold) < extentY)) + return true; + + return false; + + } + + public static boolean collide(PlacementInfo sourceInfo, Building targetBuilding) { + + Bounds sourceBounds; + Bounds targetBounds; + + boolean collisionState = false; + + // Early exit sanity check. Can't quite collide against nothing + + if ((sourceInfo == null) || (targetBuilding == null)) + return false; + + sourceBounds = Bounds.borrow(); + sourceBounds.setBounds(sourceInfo); + + // WARNING: DO NOT EVER RELEASE THESE WORLDOBJECT BOUNDS + // THEY ARE NOT IMMUTABLE + + targetBounds = targetBuilding.getBounds(); + + // If target building has no bounds, we certainly cannot collide. + // Note: We remove and release bounds objects to the pool when + // buildings are destroyed. + + if (targetBounds == null) + return false; + + collisionState = collide(sourceBounds, targetBounds, .1f); + + // Release bounds and return collision state + + sourceBounds.release(); + return collisionState; + } + + public static boolean collide(Bounds bounds, Vector3fImmutable start, Vector3fImmutable end) { + boolean collide = false; + for (Colliders collider : bounds.colliders) { + + collide = linesTouching(collider.startX, collider.startY, collider.endX, collider.endY, start.x, start.z, end.x, end.z); + + if (collide) + break; + + + } + + return collide; + } + + //used for wall collision with players. + public static Vector3fImmutable PlayerBuildingCollisionPoint(PlayerCharacter player, Vector3fImmutable start, Vector3fImmutable end) { + Vector3fImmutable collidePoint = null; + + //player can fly over walls when at max altitude. skip collision checks. + if (player.getAltitude() >= 60) + return null; + + + float distance = player.getLoc().distance2D(end); + // Players should not be able to move more than 2000 units at a time, stop them dead in their tracks if they do. (hacks) + if (distance > 2000) + return player.getLoc(); + + + HashSet awoList = WorldGrid.getObjectsInRangePartial(player, distance + 1000, MBServerStatics.MASK_BUILDING); + float collideDistance = 0; + float lastDistance = -1; + + + for (AbstractWorldObject awo : awoList) { + + Building building = (Building) awo; + + + //player is inside building region, skip collision check. we only do collision from the outside. + if (player.region != null && player.region.parentBuildingID == building.getObjectUUID()) + continue; + if (building.getBounds().colliders == null) + continue; + + for (Colliders collider : building.getBounds().colliders) { + + //links are what link together buildings, allow players to run through them only if they are in a building already. + if (collider.isLink() && player.region != null) + continue; + if (collider.getDoorID() != 0 && building.isDoorOpen(collider.getDoorID())) + continue; + + Vector3fImmutable tempCollidePoint = lineIntersection(collider.startX, collider.startY, collider.endX, collider.endY, start.x, start.z, end.x, end.z); + + //didnt collide, skip distance checks. + if (tempCollidePoint == null) + continue; + + //first collision detection, inititialize all variables. + if (lastDistance == -1) { + collideDistance = start.distance2D(tempCollidePoint); + lastDistance = collideDistance; + collidePoint = tempCollidePoint; + } else + //get closest collide point. + collideDistance = start.distance2D(tempCollidePoint); + + if (collideDistance < lastDistance) { + lastDistance = collideDistance; + collidePoint = tempCollidePoint; + } + } + } + + + // + if (collidePoint != null) { + + if (collideDistance >= 2) + collidePoint = player.getFaceDir().scaleAdd(-2f, new Vector3fImmutable((float) collidePoint.getX(), end.y, (float) collidePoint.getZ())); + else + collidePoint = player.getLoc(); + } + + + return collidePoint; + } - public static Bounds borrow() { - Bounds outBounds; + public static boolean linesTouching(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { + float denominator = ((x2 - x1) * (y4 - y3)) - ((y2 - y1) * (x4 - x3)); + float numerator1 = ((y1 - y3) * (x4 - x3)) - ((x1 - x3) * (y4 - y3)); + float numerator2 = ((y1 - y3) * (x2 - x1)) - ((x1 - x3) * (y2 - y1)); - outBounds = boundsPool.poll(); + // Detect coincident lines (has a problem, read below) + if (denominator == 0) + return numerator1 == 0 && numerator2 == 0; - if (outBounds == null) - outBounds = new Bounds(); + float r = numerator1 / denominator; + float s = numerator2 / denominator; - return outBounds; - } + return (r >= 0 && r <= 1) && (s >= 0 && s <= 1); + } - public void release() { - Bounds.zero(this); - boundsPool.add(this); + public static Vector3fImmutable lineIntersection(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { - } + // calculate the distance to intersection point + float uA = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / ((y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1)); + float uB = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / ((y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1)); - public void setBounds(Vector2f origin, Vector2f extents, float rotation) { + // if uA and uB are between 0-1, lines are colliding + if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1) { + return new Vector3fImmutable(x1 + (uA * (x2 - x1)), 0, y1 + (uA * (y2 - y1))); + } + return null; + } - this.origin.set(origin); - this.halfExtents.set(extents); - this.rotation = rotation; - - this.flipExtents = Bounds.calculateFlipExtents(this); + private static boolean calculateFlipExtents(Bounds bounds) { - } + int degrees; + double radian = 0; + if (bounds.quaternion != null) { + radian = bounds.quaternion.angleY; + } - public void setBounds(PlacementInfo sourceInfo) { + degrees = (int) Math.toDegrees(radian); + bounds.rotationDegrees = degrees; + if (degrees < 0) + degrees += 360; + return (degrees >= 85 && degrees <= 95) || + (degrees >= 265 && degrees <= 275); - Blueprint sourceBlueprint; + } - sourceBlueprint = Blueprint.getBlueprint(sourceInfo.getBlueprintUUID()); - this.origin.set(sourceInfo.getLoc().x, sourceInfo.getLoc().z); - this.halfExtents.set(sourceBlueprint.getExtents()); - - this.quaternion = new Quaternion(sourceInfo.getRot().x, sourceInfo.getRot().y,sourceInfo.getRot().z,sourceInfo.getW()); - this.rotation = sourceInfo.getRot().y; - this.flipExtents = Bounds.calculateFlipExtents(this); + public static Vector3f getRotatedPoint(Vector3f point, float centerX, float centerZ, float angle) { - } + //TRANSLATE TO ORIGIN + float x1 = point.getX() - centerX; + float y1 = point.getZ() - centerZ; - public void setBounds(Bounds sourceBounds) { + //APPLY ROTATION + float temp_x1 = (float) (x1 * Math.cos(angle) - y1 * Math.sin(angle)); + float temp_z1 = (float) (x1 * Math.sin(angle) + y1 * Math.cos(angle)); - origin.set(sourceBounds.origin); - halfExtents.set(sourceBounds.halfExtents); - this.rotation = sourceBounds.rotation; - this.flipExtents = sourceBounds.flipExtents; + temp_x1 += centerX; + temp_z1 += centerZ; - } + return new Vector3f(temp_x1, point.y, temp_z1); - public void setBounds(AbstractCharacter sourcePlayer) { + } - this.origin.set(sourcePlayer.getLoc().x, sourcePlayer.getLoc().z); - this.halfExtents.set(.5f, .5f); - this.rotation = 0; - this.flipExtents = false; + public void release() { + Bounds.zero(this); + boundsPool.add(this); - } + } - public void setBounds(Vector3fImmutable sourceLocation) { + // Method detects overlap of two given Bounds objects. + // Just your generic AABB collision algorythm. - this.origin.set(sourceLocation.x, sourceLocation.z); - this.halfExtents.set(.5f, .5f); - this.rotation = 0; - this.flipExtents = false; + public void setBounds(Vector2f origin, Vector2f extents, float rotation) { - } + this.origin.set(origin); + this.halfExtents.set(extents); + this.rotation = rotation; - public void setBounds(Vector3fImmutable sourceLocation, float halfExtent) { + this.flipExtents = Bounds.calculateFlipExtents(this); - this.origin.set(sourceLocation.x, sourceLocation.z); - this.halfExtents.set(halfExtent, halfExtent); - this.rotation = 0; - this.flipExtents = false; + } + + public void setBounds(PlacementInfo sourceInfo) { + + Blueprint sourceBlueprint; + + sourceBlueprint = Blueprint.getBlueprint(sourceInfo.getBlueprintUUID()); + this.origin.set(sourceInfo.getLoc().x, sourceInfo.getLoc().z); + this.halfExtents.set(sourceBlueprint.getExtents()); - } + this.quaternion = new Quaternion(sourceInfo.getRot().x, sourceInfo.getRot().y, sourceInfo.getRot().z, sourceInfo.getW()); + this.rotation = sourceInfo.getRot().y; + this.flipExtents = Bounds.calculateFlipExtents(this); - public void setBounds(Building building) { + } + + public void setBounds(Bounds sourceBounds) { - Blueprint blueprint; - MeshBounds meshBounds; - int halfExtentX; - int halfExtentY; - // Need a blueprint for proper bounds + origin.set(sourceBounds.origin); + halfExtents.set(sourceBounds.halfExtents); + this.rotation = sourceBounds.rotation; + this.flipExtents = sourceBounds.flipExtents; - blueprint = building.getBlueprint(); - - this.quaternion = new Quaternion(building.getRot().x, building.getRot().y,building.getRot().z,building.getw()); + } - // Calculate Bounds for non-blueprint objects + public void setBounds(AbstractCharacter sourcePlayer) { - if (blueprint == null) { + this.origin.set(sourcePlayer.getLoc().x, sourcePlayer.getLoc().z); + this.halfExtents.set(.5f, .5f); + this.rotation = 0; + this.flipExtents = false; - // If a mesh is a non-blueprint structure then we calculate - // it's bounding box based upon defaults from original source - // lookup. + } + + public void setBounds(Vector3fImmutable sourceLocation) { + + this.origin.set(sourceLocation.x, sourceLocation.z); + this.halfExtents.set(.5f, .5f); + this.rotation = 0; + this.flipExtents = false; + + } + + public void setBounds(Vector3fImmutable sourceLocation, float halfExtent) { + + this.origin.set(sourceLocation.x, sourceLocation.z); + this.halfExtents.set(halfExtent, halfExtent); + this.rotation = 0; + this.flipExtents = false; + + } + + public void setBounds(Building building) { + + Blueprint blueprint; + MeshBounds meshBounds; + int halfExtentX; + int halfExtentY; + // Need a blueprint for proper bounds + + blueprint = building.getBlueprint(); + + this.quaternion = new Quaternion(building.getRot().x, building.getRot().y, building.getRot().z, building.getw()); + + // Calculate Bounds for non-blueprint objects + + if (blueprint == null) { + + // If a mesh is a non-blueprint structure then we calculate + // it's bounding box based upon defaults from original source + // lookup. meshBounds = meshBoundsCache.get(building.getMeshUUID()); - this.origin.set(building.getLoc().x, building.getLoc().z); - + this.origin.set(building.getLoc().x, building.getLoc().z); + // Magicbane uses half halfExtents - if (meshBounds == null){ - halfExtentX = 1; - halfExtentY = 1; - }else{ - - float halfExtent = Math.max((meshBounds.maxX - meshBounds.minX)/2, (meshBounds.maxZ - meshBounds.minZ) /2); - halfExtentX = Math.round(halfExtent); - halfExtentY = Math.round(halfExtent); + if (meshBounds == null) { + halfExtentX = 1; + halfExtentY = 1; + } else { + + float halfExtent = Math.max((meshBounds.maxX - meshBounds.minX) / 2, (meshBounds.maxZ - meshBounds.minZ) / 2); + halfExtentX = Math.round(halfExtent); + halfExtentY = Math.round(halfExtent); } - - // The rotation is reset after the new aabb is calculated. - - this.rotation = building.getRot().y; + + // The rotation is reset after the new aabb is calculated. + + this.rotation = building.getRot().y; // Caclculate and set the new half halfExtents for the rotated bounding box - // and reset the rotation to 0 for this bounds. - this.halfExtents.set(halfExtentX, (halfExtentY)); - this.rotation = 0; - - this.setRegions(building); - this.setColliders(building); - return; - } + // and reset the rotation to 0 for this bounds. + this.halfExtents.set(halfExtentX, (halfExtentY)); + this.rotation = 0; + + this.setRegions(building); + this.setColliders(building); + return; + } - this.origin.set(building.getLoc().x, building.getLoc().z); - this.rotation = building.getRot().y; - this.halfExtents.set(blueprint.getExtents()); - this.flipExtents = Bounds.calculateFlipExtents(this); + this.origin.set(building.getLoc().x, building.getLoc().z); + this.rotation = building.getRot().y; + this.halfExtents.set(blueprint.getExtents()); + this.flipExtents = Bounds.calculateFlipExtents(this); - - this.setRegions(building); - this.setColliders(building); - } + this.setRegions(building); + this.setColliders(building); + } + + public void modify(float x, float y, float extents) { + this.origin.x = x; + this.origin.y = y; + this.halfExtents.x = extents; + this.halfExtents.y = extents; + } + /** + * @return the origin + */ + public Vector2f getOrigin() { + return origin; + } + /** + * @return the halfExtents + */ + public Vector2f getHalfExtents() { + return halfExtents; + } + /** + * @return the rotation + */ + public float getRotation() { + return rotation; + } + /** + * @param rotation the rotation to set + */ + public void setRotation(float rotation) { + this.rotation = rotation; + } - // Identity Bounds at location - public static void zero(Bounds bounds) { - bounds.origin.zero(); - bounds.halfExtents.zero(); - bounds.rotation = 0.0f; - bounds.flipExtents = false; - } + public void setColliders(Building building) { + //Collidables are for player movement collision + ArrayList tempList = StaticColliders._staticColliders.get(building.getMeshUUID()); - public static boolean collide(Vector3fImmutable location, Bounds targetBounds) { - - if (targetBounds == null) - return false; + ArrayList tempColliders = new ArrayList<>(); + if (tempList != null) { - boolean collisionState = false; - Bounds identityBounds = Bounds.borrow(); - identityBounds.setBounds(location); + for (StaticColliders staticCollider : tempList) { - collisionState = collide(targetBounds, identityBounds, 0.0f); - identityBounds.release(); - return collisionState; - } + ArrayList regionPoints = new ArrayList<>(); + Vector3f colliderStart = new Vector3f(staticCollider.getStartX(), 0, staticCollider.getStartY()); + Vector3f colliderEnd = new Vector3f(staticCollider.getEndX(), 0, staticCollider.getEndY()); + Vector3f worldStart = ZoneManager.convertLocalToWorld(building, colliderStart, this); + Vector3f worldEnd = ZoneManager.convertLocalToWorld(building, colliderEnd, this); + tempColliders.add(new Colliders(worldStart.x, worldStart.z, worldEnd.x, worldEnd.z, staticCollider.getDoorID(), staticCollider.isLink())); + } - public static boolean collide(Vector3fImmutable location, Building targetBuilding) { + } - boolean collisionState = false; - Bounds targetBounds = targetBuilding.getBounds(); - - if (targetBounds == null) - return false; - Bounds identityBounds = Bounds.borrow(); - identityBounds.setBounds(location); - collisionState = collide(targetBounds, identityBounds, 0.1f); - identityBounds.release(); - return collisionState; - } + this.colliders = tempColliders; + } - public static boolean collide(Bounds sourceBounds, Bounds targetBounds, float threshold) { - - float deltaX; - float deltaY; - float extentX; - float extentY; - float sourceExtentX; - float sourceExtentY; - float targetExtentX; - float targetExtentY; - - deltaX = Math.abs(sourceBounds.origin.x - targetBounds.origin.x); - deltaY = Math.abs(sourceBounds.origin.y - targetBounds.origin.y); - - if (sourceBounds.flipExtents) { - sourceExtentX = sourceBounds.halfExtents.y; - sourceExtentY = sourceBounds.halfExtents.x; - } - else { - sourceExtentX = sourceBounds.halfExtents.x; - sourceExtentY = sourceBounds.halfExtents.y; - } - if (targetBounds.flipExtents) { - targetExtentX = targetBounds.halfExtents.y; - targetExtentY = targetBounds.halfExtents.x; - } - else { - targetExtentX = targetBounds.halfExtents.x; - targetExtentY = targetBounds.halfExtents.y; - } - - extentX = sourceExtentX + targetExtentX; - extentY = sourceExtentY + targetExtentY; - - // Return false on overlapping edge cases - if ((Math.abs(deltaX + threshold) < extentX)) - if ((Math.abs(deltaY + threshold) < extentY)) - return true; - - return false; - - } - - // Method detects overlap of two given Bounds objects. - // Just your generic AABB collision algorythm. - - public static boolean collide(PlacementInfo sourceInfo, Building targetBuilding) { - - Bounds sourceBounds; - Bounds targetBounds; - - boolean collisionState = false; - - // Early exit sanity check. Can't quite collide against nothing - - if ((sourceInfo == null) || (targetBuilding == null)) - return false; - - sourceBounds = Bounds.borrow(); - sourceBounds.setBounds(sourceInfo); - - // WARNING: DO NOT EVER RELEASE THESE WORLDOBJECT BOUNDS - // THEY ARE NOT IMMUTABLE - - targetBounds = targetBuilding.getBounds(); - - // If target building has no bounds, we certainly cannot collide. - // Note: We remove and release bounds objects to the pool when - // buildings are destroyed. - - if (targetBounds == null) - return false; - - collisionState = collide(sourceBounds, targetBounds,.1f); - - // Release bounds and return collision state - - sourceBounds.release(); - return collisionState; - } - - public static boolean collide(Bounds bounds, Vector3fImmutable start, Vector3fImmutable end) { - boolean collide = false; - for (Colliders collider: bounds.colliders) { - - collide = linesTouching(collider.startX, collider.startY, collider.endX,collider.endY, start.x, start.z, end.x,end.z); - - if (collide) - break; - - - } - - return collide; - } - - //used for wall collision with players. - public static Vector3fImmutable PlayerBuildingCollisionPoint(PlayerCharacter player, Vector3fImmutable start, Vector3fImmutable end) { - Vector3fImmutable collidePoint = null; - - //player can fly over walls when at max altitude. skip collision checks. - if (player.getAltitude() >= 60) - return null; - - - float distance = player.getLoc().distance2D(end); - // Players should not be able to move more than 2000 units at a time, stop them dead in their tracks if they do. (hacks) - if (distance > 2000) - return player.getLoc(); - - - - HashSet awoList = WorldGrid.getObjectsInRangePartial(player, distance + 1000, MBServerStatics.MASK_BUILDING); - float collideDistance = 0; - float lastDistance = -1; - - - for (AbstractWorldObject awo : awoList) { - - Building building = (Building)awo; - - - - //player is inside building region, skip collision check. we only do collision from the outside. - if (player.region != null && player.region.parentBuildingID == building.getObjectUUID()) - continue; - if (building.getBounds().colliders == null) - continue; - - for (Colliders collider: building.getBounds().colliders) { - - //links are what link together buildings, allow players to run through them only if they are in a building already. - if (collider.isLink() && player.region != null) - continue; - if (collider.getDoorID() != 0 && building.isDoorOpen(collider.getDoorID())) - continue; - - Vector3fImmutable tempCollidePoint = lineIntersection(collider.startX, collider.startY, collider.endX,collider.endY, start.x, start.z, end.x,end.z); - - //didnt collide, skip distance checks. - if (tempCollidePoint == null) - continue; - - //first collision detection, inititialize all variables. - if (lastDistance == -1) { - collideDistance = start.distance2D(tempCollidePoint); - lastDistance = collideDistance; - collidePoint = tempCollidePoint; - }else - //get closest collide point. - collideDistance = start.distance2D(tempCollidePoint); - - if (collideDistance < lastDistance) { - lastDistance = collideDistance; - collidePoint = tempCollidePoint; - } - } - } - - - - // - if (collidePoint != null) { - - if(collideDistance >= 2) - collidePoint = player.getFaceDir().scaleAdd(-2f, new Vector3fImmutable((float) collidePoint.getX(), end.y, (float) collidePoint.getZ())); - else - collidePoint = player.getLoc(); - } - - - return collidePoint; - } - - public static boolean linesTouching(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { - float denominator = ((x2 - x1) * (y4 - y3)) - ((y2 - y1) * (x4 - x3)); - float numerator1 = ((y1 - y3) * (x4 - x3)) - ((x1 - x3) * (y4 - y3)); - float numerator2 = ((y1 - y3) * (x2 - x1)) - ((x1 - x3) * (y2 - y1)); - - // Detect coincident lines (has a problem, read below) - if (denominator == 0) return numerator1 == 0 && numerator2 == 0; - - float r = numerator1 / denominator; - float s = numerator2 / denominator; - - return (r >= 0 && r <= 1) && (s >= 0 && s <= 1); - } - - public static Vector3fImmutable lineIntersection(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { - - // calculate the distance to intersection point - float uA = ((x4-x3)*(y1-y3) - (y4-y3)*(x1-x3)) / ((y4-y3)*(x2-x1) - (x4-x3)*(y2-y1)); - float uB = ((x2-x1)*(y1-y3) - (y2-y1)*(x1-x3)) / ((y4-y3)*(x2-x1) - (x4-x3)*(y2-y1)); - - // if uA and uB are between 0-1, lines are colliding - if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1) { - return new Vector3fImmutable(x1 + (uA * (x2-x1)),0, y1 + (uA * (y2-y1))); - } - return null; - } - - - - private static boolean calculateFlipExtents(Bounds bounds) { - - int degrees; - double radian =0; - if (bounds.quaternion != null){ - radian = bounds.quaternion.angleY; - } - - degrees = (int) Math.toDegrees(radian); - bounds.rotationDegrees = degrees; - if (degrees < 0) - degrees += 360; - return (degrees >= 85 && degrees <= 95) || - (degrees >= 265 && degrees <= 275); + public ArrayList getRegions() { + return regions; + } + + public void setRegions(Building building) { + //Collidables are for player movement collision + ArrayList tempList = BuildingRegions._staticRegions.get(building.getMeshUUID()); + + ArrayList tempRegions = new ArrayList<>(); + if (tempList != null) { + + for (BuildingRegions buildingRegion : tempList) { + + ArrayList regionPoints = new ArrayList<>(); + + Vector3f centerPoint = ZoneManager.convertLocalToWorld(building, buildingRegion.center, this); + for (Vector3f point : buildingRegion.getRegionPoints()) { + Vector3f rotatedPoint = ZoneManager.convertLocalToWorld(building, point, this); + regionPoints.add(rotatedPoint); + } + tempRegions.add(new Regions(regionPoints, buildingRegion.getLevel(), buildingRegion.getRoom(), buildingRegion.isOutside(), buildingRegion.isExitRegion(), buildingRegion.isStairs(), centerPoint, building.getObjectUUID())); + } + + } + + this.regions = tempRegions; + } + + public void setRegions(ArrayList regions) { + this.regions = regions; + } + + public float getRotationDegrees() { + return rotationDegrees; + } + + public boolean isFlipExtents() { + return flipExtents; } - public void modify(float x, float y, float extents) { - this.origin.x = x; - this.origin.y = y; - this.halfExtents.x = extents; - this.halfExtents.y = extents; - } - - - /** - * @return the origin - */ - public Vector2f getOrigin() { - return origin; - } - - /** - * @return the halfExtents - */ - public Vector2f getHalfExtents() { - return halfExtents; - } - - /** - * @return the rotation - */ - public float getRotation() { - return rotation; - } - - /** - * @param rotation the rotation to set - */ - public void setRotation(float rotation) { - this.rotation = rotation; - } - - - - - public void setRegions(Building building ){ - //Collidables are for player movement collision - ArrayList tempList = BuildingRegions._staticRegions.get(building.getMeshUUID()); - - ArrayList tempRegions = new ArrayList<>(); - if (tempList != null){ - - for (BuildingRegions buildingRegion:tempList){ - - ArrayList regionPoints = new ArrayList<>(); - - Vector3f centerPoint = ZoneManager.convertLocalToWorld(building, buildingRegion.center, this); - for (Vector3f point: buildingRegion.getRegionPoints()){ - Vector3f rotatedPoint = ZoneManager.convertLocalToWorld(building, point,this); - regionPoints.add(rotatedPoint); - } - tempRegions.add(new Regions(regionPoints, buildingRegion.getLevel(),buildingRegion.getRoom(),buildingRegion.isOutside(),buildingRegion.isExitRegion(), buildingRegion.isStairs(), centerPoint,building.getObjectUUID())); - } - - } - - - this.regions = tempRegions; - } - - public void setColliders(Building building ){ - //Collidables are for player movement collision - ArrayList tempList = StaticColliders._staticColliders.get(building.getMeshUUID()); - - ArrayList tempColliders = new ArrayList<>(); - if (tempList != null){ - - for (StaticColliders staticCollider :tempList){ - - ArrayList regionPoints = new ArrayList<>(); - - Vector3f colliderStart = new Vector3f(staticCollider.getStartX(), 0, staticCollider.getStartY()); - Vector3f colliderEnd = new Vector3f(staticCollider.getEndX(), 0, staticCollider.getEndY()); - Vector3f worldStart = ZoneManager.convertLocalToWorld(building, colliderStart, this); - Vector3f worldEnd = ZoneManager.convertLocalToWorld(building, colliderEnd, this); - tempColliders.add(new Colliders(worldStart.x, worldStart.z, worldEnd.x, worldEnd.z, staticCollider.getDoorID(), staticCollider.isLink())); - } - - } - - - this.colliders = tempColliders; - } - - public ArrayList getRegions() { - return regions; - } - - public void setRegions(ArrayList regions) { - this.regions = regions; - } - - public static Vector3f getRotatedPoint(Vector3f point, float centerX, float centerZ, float angle){ - - //TRANSLATE TO ORIGIN - float x1 = point.getX() - centerX; - float y1 = point.getZ() - centerZ; - - //APPLY ROTATION - float temp_x1 = (float) (x1 * Math.cos(angle) - y1 * Math.sin(angle)); - float temp_z1 = (float) (x1 * Math.sin(angle) + y1 * Math.cos(angle)); - - temp_x1 += centerX; - temp_z1 += centerZ; - - return new Vector3f(temp_x1,point.y,temp_z1); - - } - - - public float getRotationDegrees() { - return rotationDegrees; - } - - public boolean isFlipExtents() { - return flipExtents; - } - - public Quaternion getQuaternion() { - return quaternion; - } + public Quaternion getQuaternion() { + return quaternion; + } } diff --git a/src/engine/math/FastMath.java b/src/engine/math/FastMath.java index 067ef617..c82f90e3 100644 --- a/src/engine/math/FastMath.java +++ b/src/engine/math/FastMath.java @@ -6,7 +6,7 @@ // Magicbane Emulator Project © 2013 - 2022 // www.magicbane.com - package engine.math; +package engine.math; import java.util.Calendar; import java.util.concurrent.ThreadLocalRandom; @@ -21,648 +21,626 @@ import java.util.concurrent.ThreadLocalRandom; final public class FastMath { - private FastMath() { - } - - /** A "close to zero" double epsilon value for use */ - public static final double DBL_EPSILON = 2.220446049250313E-16d; - - /** A "close to zero" float epsilon value for use */ - public static final float FLT_EPSILON = 1.1920928955078125E-7f; - - /** A "close to zero" float epsilon value for use */ - public static final float ZERO_TOLERANCE = 0.0001f; - - public static final float ONE_THIRD = 1f / 3f; - - /** The value PI as a float. (180 degrees) */ - public static final float PI = (float) Math.PI; - - /** The value 2PI as a float. (360 degrees) */ - public static final float TWO_PI = 2.0f * PI; - - /** The value PI/2 as a float. (90 degrees) */ - public static final float HALF_PI = 0.5f * PI; - - /** The value PI/4 as a float. (45 degrees) */ - public static final float QUARTER_PI = 0.25f * PI; - - /** The value 1/PI as a float. */ - public static final float INV_PI = 1.0f / PI; - - /** The value 1/(2PI) as a float. */ - public static final float INV_TWO_PI = 1.0f / TWO_PI; - - /** A value to multiply a degree value by, to convert it to radians. */ - public static final float DEG_TO_RAD = PI / 180.0f; - - /** A value to multiply a radian value by, to convert it to degrees. */ - public static final float RAD_TO_DEG = 180.0f / PI; - - /** - * Returns true if the number is a power of 2 (2,4,8,16...) - * - * A good implementation found on the Java boards. note: a number is a power - * of two if and only if it is the smallest number with that number of - * significant bits. Therefore, if you subtract 1, you know that the new - * number will have fewer bits, so ANDing the original number with anything - * less than it will give 0. - * - * @param number - * The number to test. - * @return True if it is a power of two. - */ - public static boolean isPowerOfTwo(int number) { - return (number > 0) && (number & (number - 1)) == 0; - } - - public static int nearestPowerOfTwo(int number) { - return (int) Math.pow(2, Math.ceil(Math.log(number) / Math.log(2))); - } - - public static boolean between(float i, float minValueInclusive, float maxValueInclusive) { - return (i >= minValueInclusive && i <= maxValueInclusive); - } - - /** - * Linear interpolation from startValue to endValue by the given percent. - * Basically: ((1 - percent) * startValue) + (percent * endValue) - * - * @param percent - * Percent value to use. - * @param startValue - * Begining value. 0% of f - * @param endValue - * ending value. 100% of f - * @return The interpolated value between startValue and endValue. - */ - public static float LERP(float percent, float startValue, float endValue) { - if (startValue == endValue) - return startValue; - return ((1 - percent) * startValue) + (percent * endValue); - } - - /** - * Returns the arc cosine of an angle given in radians.
- * Special cases: - *

    - *
  • If fValue is smaller than -1, then the result is PI. - *
  • If the argument is greater than 1, then the result is 0. - *
- * - * @param fValue - * The angle, in radians. - * @return fValue's acos - * @see java.lang.Math#acos(double) - */ - public static float acos(float fValue) { - if (-1.0f < fValue) { - if (fValue < 1.0f) - return (float) Math.acos(fValue); - - return 0.0f; - } - - return PI; - } - - /** - * Returns the arc sine of an angle given in radians.
- * Special cases: - *
    - *
  • If fValue is smaller than -1, then the result is -HALF_PI. - *
  • If the argument is greater than 1, then the result is HALF_PI. - *
- * - * @param fValue - * The angle, in radians. - * @return fValue's asin - * @see java.lang.Math#asin(double) - */ - public static float asin(float fValue) { - if (-1.0f < fValue) { - if (fValue < 1.0f) - return (float) Math.asin(fValue); - - return HALF_PI; - } - - return -HALF_PI; - } - - /** - * Returns the arc tangent of an angle given in radians.
- * - * @param fValue - * The angle, in radians. - * @return fValue's asin - * @see java.lang.Math#atan(double) - */ - public static float atan(float fValue) { - return (float) Math.atan(fValue); - } - - /** - * A direct call to Math.atan2. - * - * @param fY - * @param fX - * @return Math.atan2(fY,fX) - * @see java.lang.Math#atan2(double, double) - */ - public static float atan2(float fY, float fX) { - return (float) Math.atan2(fY, fX); - } - - /** - * Rounds a fValue up. A call to Math.ceil - * - * @param fValue - * The value. - * @return The fValue rounded up - * @see java.lang.Math#ceil(double) - */ - public static float ceil(float fValue) { - return (float) Math.ceil(fValue); - } - - /** - * Fast Trig functions for x86. This forces the trig functiosn to stay - * within the safe area on the x86 processor (-45 degrees to +45 degrees) - * The results may be very slightly off from what the Math and StrictMath - * trig functions give due to rounding in the angle reduction but it will be - * very very close. - * - */ - public static float reduceSinAngle(float radians) { - radians %= TWO_PI; // put us in -2PI to +2PI space - if (Math.abs(radians) > PI) { // put us in -PI to +PI space + /** + * A "close to zero" double epsilon value for use + */ + public static final double DBL_EPSILON = 2.220446049250313E-16d; + /** + * A "close to zero" float epsilon value for use + */ + public static final float FLT_EPSILON = 1.1920928955078125E-7f; + /** + * A "close to zero" float epsilon value for use + */ + public static final float ZERO_TOLERANCE = 0.0001f; + public static final float ONE_THIRD = 1f / 3f; + /** + * The value PI as a float. (180 degrees) + */ + public static final float PI = (float) Math.PI; + /** + * The value 2PI as a float. (360 degrees) + */ + public static final float TWO_PI = 2.0f * PI; + /** + * The value 1/(2PI) as a float. + */ + public static final float INV_TWO_PI = 1.0f / TWO_PI; + /** + * The value PI/2 as a float. (90 degrees) + */ + public static final float HALF_PI = 0.5f * PI; + + /** + * The value PI/4 as a float. (45 degrees) + */ + public static final float QUARTER_PI = 0.25f * PI; + + /** + * The value 1/PI as a float. + */ + public static final float INV_PI = 1.0f / PI; + /** + * A value to multiply a degree value by, to convert it to radians. + */ + public static final float DEG_TO_RAD = PI / 180.0f; + /** + * A value to multiply a radian value by, to convert it to degrees. + */ + public static final float RAD_TO_DEG = 180.0f / PI; + + private FastMath() { + } + + /** + * Returns true if the number is a power of 2 (2,4,8,16...) + *

+ * A good implementation found on the Java boards. note: a number is a power + * of two if and only if it is the smallest number with that number of + * significant bits. Therefore, if you subtract 1, you know that the new + * number will have fewer bits, so ANDing the original number with anything + * less than it will give 0. + * + * @param number The number to test. + * @return True if it is a power of two. + */ + public static boolean isPowerOfTwo(int number) { + return (number > 0) && (number & (number - 1)) == 0; + } + + public static int nearestPowerOfTwo(int number) { + return (int) Math.pow(2, Math.ceil(Math.log(number) / Math.log(2))); + } + + public static boolean between(float i, float minValueInclusive, float maxValueInclusive) { + return (i >= minValueInclusive && i <= maxValueInclusive); + } + + /** + * Linear interpolation from startValue to endValue by the given percent. + * Basically: ((1 - percent) * startValue) + (percent * endValue) + * + * @param percent Percent value to use. + * @param startValue Begining value. 0% of f + * @param endValue ending value. 100% of f + * @return The interpolated value between startValue and endValue. + */ + public static float LERP(float percent, float startValue, float endValue) { + if (startValue == endValue) + return startValue; + return ((1 - percent) * startValue) + (percent * endValue); + } + + /** + * Returns the arc cosine of an angle given in radians.
+ * Special cases: + *

    + *
  • If fValue is smaller than -1, then the result is PI. + *
  • If the argument is greater than 1, then the result is 0. + *
+ * + * @param fValue The angle, in radians. + * @return fValue's acos + * @see java.lang.Math#acos(double) + */ + public static float acos(float fValue) { + if (-1.0f < fValue) { + if (fValue < 1.0f) + return (float) Math.acos(fValue); + + return 0.0f; + } + + return PI; + } + + /** + * Returns the arc sine of an angle given in radians.
+ * Special cases: + *
    + *
  • If fValue is smaller than -1, then the result is -HALF_PI. + *
  • If the argument is greater than 1, then the result is HALF_PI. + *
+ * + * @param fValue The angle, in radians. + * @return fValue's asin + * @see java.lang.Math#asin(double) + */ + public static float asin(float fValue) { + if (-1.0f < fValue) { + if (fValue < 1.0f) + return (float) Math.asin(fValue); + + return HALF_PI; + } + + return -HALF_PI; + } + + /** + * Returns the arc tangent of an angle given in radians.
+ * + * @param fValue The angle, in radians. + * @return fValue's asin + * @see java.lang.Math#atan(double) + */ + public static float atan(float fValue) { + return (float) Math.atan(fValue); + } + + /** + * A direct call to Math.atan2. + * + * @param fY + * @param fX + * @return Math.atan2(fY, fX) + * @see java.lang.Math#atan2(double, double) + */ + public static float atan2(float fY, float fX) { + return (float) Math.atan2(fY, fX); + } + + /** + * Rounds a fValue up. A call to Math.ceil + * + * @param fValue The value. + * @return The fValue rounded up + * @see java.lang.Math#ceil(double) + */ + public static float ceil(float fValue) { + return (float) Math.ceil(fValue); + } + + /** + * Fast Trig functions for x86. This forces the trig functiosn to stay + * within the safe area on the x86 processor (-45 degrees to +45 degrees) + * The results may be very slightly off from what the Math and StrictMath + * trig functions give due to rounding in the angle reduction but it will be + * very very close. + */ + public static float reduceSinAngle(float radians) { + radians %= TWO_PI; // put us in -2PI to +2PI space + if (Math.abs(radians) > PI) { // put us in -PI to +PI space radians -= (TWO_PI); - } - if (Math.abs(radians) > HALF_PI) {// put us in -PI/2 to +PI/2 space - radians = PI - radians; - } - - return radians; - } - - /** - * Returns sine of a value. - * - * @param fValue - * The value to sine, in radians. - * @return The sine of fValue. - * @see java.lang.Math#sin(double) - */ - public static float sin(float fValue) { - fValue = reduceSinAngle(fValue); // limits angle to between -PI/2 and - // +PI/2 - if (Math.abs(fValue) <= Math.PI / 4) { - return (float) Math.sin(fValue); - } - - return (float) Math.cos(Math.PI / 2 - fValue); - } - - /** - * Returns cos of a value. - * - * @param fValue - * The value to cosine, in radians. - * @return The cosine of fValue. - * @see java.lang.Math#cos(double) - */ - public static float cos(float fValue) { - return sin(fValue + HALF_PI); - } - - /** - * Returns E^fValue - * - * @param fValue - * Value to raise to a power. - * @return The value E^fValue - * @see java.lang.Math#exp(double) - */ - public static float exp(float fValue) { - return (float) Math.exp(fValue); - } - - /** - * Returns Absolute value of a float. - * - * @param fValue - * The value to abs. - * @return The abs of the value. - * @see java.lang.Math#abs(float) - */ - public static float abs(float fValue) { - if (fValue < 0) - return -fValue; - return fValue; - } - - /** - * Returns a number rounded down. - * - * @param fValue - * The value to round - * @return The given number rounded down - * @see java.lang.Math#floor(double) - */ - public static float floor(float fValue) { - return (float) Math.floor(fValue); - } - - /** - * Returns 1/sqrt(fValue) - * - * @param fValue - * The value to process. - * @return 1/sqrt(fValue) - * @see java.lang.Math#sqrt(double) - */ - public static float invSqrt(float fValue) { - return (float) (1.0f / Math.sqrt(fValue)); - } - - /** - * Returns the log base E of a value. - * - * @param fValue - * The value to Logger.getInstance(). - * @return The log of fValue base E - * @see java.lang.Math#log(double) - */ - public static float log(float fValue) { - return (float) Math.log(fValue); - } - - /** - * Returns the logarithm of value with given base, calculated as - * log(value)/log(base), so that pow(base, return)==value (contributed by - * vear) - * - * @param value - * The value to Logger.getInstance(). - * @param base - * Base of logarithm. - * @return The logarithm of value with given base - */ - public static float log(float value, float base) { - return (float) (Math.log(value) / Math.log(base)); - } - - /** - * Returns a number raised to an exponent power. fBase^fExponent - * - * @param fBase - * The base value (IE 2) - * @param fExponent - * The exponent value (IE 3) - * @return base raised to exponent (IE 8) - * @see java.lang.Math#pow(double, double) - */ - public static float pow(float fBase, float fExponent) { - return (float) Math.pow(fBase, fExponent); - } - - /** - * Returns the value squared. fValue ^ 2 - * - * @param fValue - * The vaule to square. - * @return The square of the given value. - */ - public static float sqr(float fValue) { - return fValue * fValue; - } - - public static double sqr(double fValue) { - return fValue * fValue; - } - - /** - * Returns the square root of a given value. - * - * @param fValue - * The value to sqrt. - * @return The square root of the given value. - * @see java.lang.Math#sqrt(double) - */ - public static float sqrt(float fValue) { - return (float) Math.sqrt(fValue); - } - - /** - * Returns the tangent of a value. If USE_FAST_TRIG is enabled, an - * approximate value is returned. Otherwise, a direct value is used. - * - * @param fValue - * The value to tangent, in radians. - * @return The tangent of fValue. - * @see java.lang.Math#tan(double) - */ - public static float tan(float fValue) { - return (float) Math.tan(fValue); - } - - /** - * Returns 1 if the number is positive, -1 if the number is negative, and 0 - * otherwise - * - * @param iValue - * The integer to examine. - * @return The integer's sign. - */ - public static int sign(int iValue) { - if (iValue > 0) - return 1; - - if (iValue < 0) - return -1; - - return 0; - } - - /** - * Returns 1 if the number is positive, -1 if the number is negative, and 0 - * otherwise - * - * @param fValue - * The float to examine. - * @return The float's sign. - */ - public static float sign(float fValue) { - return Math.signum(fValue); - } - - /** - * Given 3 points in a 2d plane, this function computes if the points going - * from A-B-C are moving counter clock wise. - * - * @param p0 - * Point 0. - * @param p1 - * Point 1. - * @param p2 - * Point 2. - * @return 1 If they are CCW, -1 if they are not CCW, 0 if p2 is between p0 - * and p1. - */ - public static int counterClockwise(Vector2f p0, Vector2f p1, Vector2f p2) { - float dx1, dx2, dy1, dy2; - dx1 = p1.x - p0.x; - dy1 = p1.y - p0.y; - dx2 = p2.x - p0.x; - dy2 = p2.y - p0.y; - if (dx1 * dy2 > dy1 * dx2) - return 1; - if (dx1 * dy2 < dy1 * dx2) - return -1; - if ((dx1 * dx2 < 0) || (dy1 * dy2 < 0)) - return -1; - if ((dx1 * dx1 + dy1 * dy1) < (dx2 * dx2 + dy2 * dy2)) - return 1; - return 0; - } - - /** - * Test if a point is inside a triangle. 1 if the point is on the ccw side, - * -1 if the point is on the cw side, and 0 if it is on neither. - * - * @param t0 - * First point of the triangle. - * @param t1 - * Second point of the triangle. - * @param t2 - * Third point of the triangle. - * @param p - * The point to test. - * @return Value 1 or -1 if inside triangle, 0 otherwise. - */ - public static int pointInsideTriangle(Vector2f t0, Vector2f t1, - Vector2f t2, Vector2f p) { - int val1 = counterClockwise(t0, t1, p); - if (val1 == 0) - return 1; - int val2 = counterClockwise(t1, t2, p); - if (val2 == 0) - return 1; - if (val2 != val1) - return 0; - int val3 = counterClockwise(t2, t0, p); - if (val3 == 0) - return 1; - if (val3 != val1) - return 0; - return val3; - } - - /** - * Returns the determinant of a 4x4 matrix. - */ - public static float determinant(double m00, double m01, double m02, - double m03, double m10, double m11, double m12, double m13, - double m20, double m21, double m22, double m23, double m30, - double m31, double m32, double m33) { - - double det01 = m20 * m31 - m21 * m30; - double det02 = m20 * m32 - m22 * m30; - double det03 = m20 * m33 - m23 * m30; - double det12 = m21 * m32 - m22 * m31; - double det13 = m21 * m33 - m23 * m31; - double det23 = m22 * m33 - m23 * m32; - return (float) (m00 * (m11 * det23 - m12 * det13 + m13 * det12) - m01 - * (m10 * det23 - m12 * det03 + m13 * det02) + m02 - * (m10 * det13 - m11 * det03 + m13 * det01) - m03 - * (m10 * det12 - m11 * det02 + m12 * det01)); - } - - /** - * Converts a point from Spherical coordinates to Cartesian (using positive - * Y as up) and stores the results in the store var. - */ - public static Vector3f sphericalToCartesian(Vector3f sphereCoords, - Vector3f store) { - store.y = sphereCoords.x * FastMath.sin(sphereCoords.z); - float a = sphereCoords.x * FastMath.cos(sphereCoords.z); - store.x = a * FastMath.cos(sphereCoords.y); - store.z = a * FastMath.sin(sphereCoords.y); - - return store; - } - - /** - * Converts a point from Cartesian coordinates (using positive Y as up) to - * Spherical and stores the results in the store var. (Radius, Azimuth, - * Polar) - */ - public static Vector3f cartesianToSpherical(Vector3f cartCoords, - Vector3f store) { - if (cartCoords.x == 0) - cartCoords.x = FastMath.FLT_EPSILON; - store.x = FastMath - .sqrt((cartCoords.x * cartCoords.x) - + (cartCoords.y * cartCoords.y) - + (cartCoords.z * cartCoords.z)); - store.y = FastMath.atan(cartCoords.z / cartCoords.x); - if (cartCoords.x < 0) - store.y += FastMath.PI; - store.z = FastMath.asin(cartCoords.y / store.x); - return store; - } - - /** - * Converts a point from Spherical coordinates to Cartesian (using positive - * Z as up) and stores the results in the store var. - */ - public static Vector3f sphericalToCartesianZ(Vector3f sphereCoords, - Vector3f store) { - store.z = sphereCoords.x * FastMath.sin(sphereCoords.z); - float a = sphereCoords.x * FastMath.cos(sphereCoords.z); - store.x = a * FastMath.cos(sphereCoords.y); - store.y = a * FastMath.sin(sphereCoords.y); - - return store; - } - - /** - * Converts a point from Cartesian coordinates (using positive Z as up) to - * Spherical and stores the results in the store var. (Radius, Azimuth, - * Polar) - */ - public static Vector3f cartesianZToSpherical(Vector3f cartCoords, - Vector3f store) { - if (cartCoords.x == 0) - cartCoords.x = FastMath.FLT_EPSILON; - store.x = FastMath - .sqrt((cartCoords.x * cartCoords.x) - + (cartCoords.y * cartCoords.y) - + (cartCoords.z * cartCoords.z)); - store.z = FastMath.atan(cartCoords.z / cartCoords.x); - if (cartCoords.x < 0) - store.z += FastMath.PI; - store.y = FastMath.asin(cartCoords.y / store.x); - return store; - } - - /** - * Takes an value and expresses it in terms of min to max. - * - * @param val - * - the angle to normalize (in radians) - * @return the normalized angle (also in radians) - */ - public static float normalize(float val, float min, float max) { - if (Float.isInfinite(val) || Float.isNaN(val)) - return 0f; - float range = max - min; - while (val > max) - val -= range; - while (val < min) - val += range; - return val; - } - - /** - * @param x - * the value whose sign is to be adjusted. - * @param y - * the value whose sign is to be used. - * @return x with its sign changed to match the sign of y. - */ - public static float copysign(float x, float y) { - if (y >= 0 && x <= -0) - return -x; - else if (y < 0 && x >= 0) - return -x; - else - return x; - } - - /** - * Take a float input and clamp it between min and max. - * - * @param input - * @param min - * @param max - * @return clamped input - */ - public static float clamp(float input, float min, float max) { - return (input < min) ? min : (input > max) ? max : input; - } - - - /** - * Return a random 2D vector - * this needs checked - */ - public static Vector3fImmutable randomVector2D() { - float x = ((ThreadLocalRandom.current().nextFloat() * 2) - 1); - float z = ((ThreadLocalRandom.current().nextFloat() * 2) - 1); - Vector3fImmutable ret = new Vector3fImmutable(x, 0, z); - return ret.normalize(); - } - - /** - * Turns a String into an Integer hash that the client will recognize. - * - * @param s - * The String to hash - * @return the Integer hash - */ - public static int hash(String s) { - int out = 0, pad = 0; - for(char c : s.toCharArray()) { - if(c == ' ' || c == '\\') { - pad += 5; - continue; - } - if(c > 0x40 && c < 0x60) - out ^= _rotl((byte) 0x60, pad); - out ^= _rotl((byte) (c & 0xDF), pad); - pad += 5; - } - return out; - } - - /** - * Utility function for making hashes - */ - private static int _rotl(int value, int shift) { - if ((shift &= 31) == 0) - return value; - return (value << shift) | (value >> (32 - shift)); - } - - /** - * Gets number of seconds until next hours - */ - - public static int secondsUntilNextHour() { - Calendar cal = Calendar.getInstance(); - int minute = cal.get(Calendar.MINUTE); - int second = cal.get(Calendar.SECOND); - return 3600 - (minute * 60) - second; - } - - public static float area(float x1, float y1, float x2, float y2, float x3, float y3){ - return (float) Math.abs((x1*(y2-y3) + x2*(y3-y1)+ x3*(y1-y2))/2.0); //Change to *.5? - } - - public static float GetDegrees(float yRot){ - double radian = Math.asin(yRot); - float degrees = (float) Math.toDegrees(radian); - - degrees *=2; - return degrees; - } - - public static float degreesToW(float degrees){ - return (float) Math.abs(Math.cos(Math.toRadians(degrees)/2)); - } - public static float degreesToYRotation(float degrees){ - return (float)Math.sin(Math.toRadians(degrees)/2); - } + } + if (Math.abs(radians) > HALF_PI) {// put us in -PI/2 to +PI/2 space + radians = PI - radians; + } + + return radians; + } + + /** + * Returns sine of a value. + * + * @param fValue The value to sine, in radians. + * @return The sine of fValue. + * @see java.lang.Math#sin(double) + */ + public static float sin(float fValue) { + fValue = reduceSinAngle(fValue); // limits angle to between -PI/2 and + // +PI/2 + if (Math.abs(fValue) <= Math.PI / 4) { + return (float) Math.sin(fValue); + } + + return (float) Math.cos(Math.PI / 2 - fValue); + } + + /** + * Returns cos of a value. + * + * @param fValue The value to cosine, in radians. + * @return The cosine of fValue. + * @see java.lang.Math#cos(double) + */ + public static float cos(float fValue) { + return sin(fValue + HALF_PI); + } + + /** + * Returns E^fValue + * + * @param fValue Value to raise to a power. + * @return The value E^fValue + * @see java.lang.Math#exp(double) + */ + public static float exp(float fValue) { + return (float) Math.exp(fValue); + } + + /** + * Returns Absolute value of a float. + * + * @param fValue The value to abs. + * @return The abs of the value. + * @see java.lang.Math#abs(float) + */ + public static float abs(float fValue) { + if (fValue < 0) + return -fValue; + return fValue; + } + + /** + * Returns a number rounded down. + * + * @param fValue The value to round + * @return The given number rounded down + * @see java.lang.Math#floor(double) + */ + public static float floor(float fValue) { + return (float) Math.floor(fValue); + } + + /** + * Returns 1/sqrt(fValue) + * + * @param fValue The value to process. + * @return 1/sqrt(fValue) + * @see java.lang.Math#sqrt(double) + */ + public static float invSqrt(float fValue) { + return (float) (1.0f / Math.sqrt(fValue)); + } + + /** + * Returns the log base E of a value. + * + * @param fValue The value to Logger.getInstance(). + * @return The log of fValue base E + * @see java.lang.Math#log(double) + */ + public static float log(float fValue) { + return (float) Math.log(fValue); + } + + /** + * Returns the logarithm of value with given base, calculated as + * log(value)/log(base), so that pow(base, return)==value (contributed by + * vear) + * + * @param value The value to Logger.getInstance(). + * @param base Base of logarithm. + * @return The logarithm of value with given base + */ + public static float log(float value, float base) { + return (float) (Math.log(value) / Math.log(base)); + } + + /** + * Returns a number raised to an exponent power. fBase^fExponent + * + * @param fBase The base value (IE 2) + * @param fExponent The exponent value (IE 3) + * @return base raised to exponent (IE 8) + * @see java.lang.Math#pow(double, double) + */ + public static float pow(float fBase, float fExponent) { + return (float) Math.pow(fBase, fExponent); + } + + /** + * Returns the value squared. fValue ^ 2 + * + * @param fValue The vaule to square. + * @return The square of the given value. + */ + public static float sqr(float fValue) { + return fValue * fValue; + } + + public static double sqr(double fValue) { + return fValue * fValue; + } + + /** + * Returns the square root of a given value. + * + * @param fValue The value to sqrt. + * @return The square root of the given value. + * @see java.lang.Math#sqrt(double) + */ + public static float sqrt(float fValue) { + return (float) Math.sqrt(fValue); + } + + /** + * Returns the tangent of a value. If USE_FAST_TRIG is enabled, an + * approximate value is returned. Otherwise, a direct value is used. + * + * @param fValue The value to tangent, in radians. + * @return The tangent of fValue. + * @see java.lang.Math#tan(double) + */ + public static float tan(float fValue) { + return (float) Math.tan(fValue); + } + + /** + * Returns 1 if the number is positive, -1 if the number is negative, and 0 + * otherwise + * + * @param iValue The integer to examine. + * @return The integer's sign. + */ + public static int sign(int iValue) { + if (iValue > 0) + return 1; + + if (iValue < 0) + return -1; + + return 0; + } + + /** + * Returns 1 if the number is positive, -1 if the number is negative, and 0 + * otherwise + * + * @param fValue The float to examine. + * @return The float's sign. + */ + public static float sign(float fValue) { + return Math.signum(fValue); + } + + /** + * Given 3 points in a 2d plane, this function computes if the points going + * from A-B-C are moving counter clock wise. + * + * @param p0 Point 0. + * @param p1 Point 1. + * @param p2 Point 2. + * @return 1 If they are CCW, -1 if they are not CCW, 0 if p2 is between p0 + * and p1. + */ + public static int counterClockwise(Vector2f p0, Vector2f p1, Vector2f p2) { + float dx1, dx2, dy1, dy2; + dx1 = p1.x - p0.x; + dy1 = p1.y - p0.y; + dx2 = p2.x - p0.x; + dy2 = p2.y - p0.y; + if (dx1 * dy2 > dy1 * dx2) + return 1; + if (dx1 * dy2 < dy1 * dx2) + return -1; + if ((dx1 * dx2 < 0) || (dy1 * dy2 < 0)) + return -1; + if ((dx1 * dx1 + dy1 * dy1) < (dx2 * dx2 + dy2 * dy2)) + return 1; + return 0; + } + + /** + * Test if a point is inside a triangle. 1 if the point is on the ccw side, + * -1 if the point is on the cw side, and 0 if it is on neither. + * + * @param t0 First point of the triangle. + * @param t1 Second point of the triangle. + * @param t2 Third point of the triangle. + * @param p The point to test. + * @return Value 1 or -1 if inside triangle, 0 otherwise. + */ + public static int pointInsideTriangle(Vector2f t0, Vector2f t1, + Vector2f t2, Vector2f p) { + int val1 = counterClockwise(t0, t1, p); + if (val1 == 0) + return 1; + int val2 = counterClockwise(t1, t2, p); + if (val2 == 0) + return 1; + if (val2 != val1) + return 0; + int val3 = counterClockwise(t2, t0, p); + if (val3 == 0) + return 1; + if (val3 != val1) + return 0; + return val3; + } + + /** + * Returns the determinant of a 4x4 matrix. + */ + public static float determinant(double m00, double m01, double m02, + double m03, double m10, double m11, double m12, double m13, + double m20, double m21, double m22, double m23, double m30, + double m31, double m32, double m33) { + + double det01 = m20 * m31 - m21 * m30; + double det02 = m20 * m32 - m22 * m30; + double det03 = m20 * m33 - m23 * m30; + double det12 = m21 * m32 - m22 * m31; + double det13 = m21 * m33 - m23 * m31; + double det23 = m22 * m33 - m23 * m32; + return (float) (m00 * (m11 * det23 - m12 * det13 + m13 * det12) - m01 + * (m10 * det23 - m12 * det03 + m13 * det02) + m02 + * (m10 * det13 - m11 * det03 + m13 * det01) - m03 + * (m10 * det12 - m11 * det02 + m12 * det01)); + } + + /** + * Converts a point from Spherical coordinates to Cartesian (using positive + * Y as up) and stores the results in the store var. + */ + public static Vector3f sphericalToCartesian(Vector3f sphereCoords, + Vector3f store) { + store.y = sphereCoords.x * FastMath.sin(sphereCoords.z); + float a = sphereCoords.x * FastMath.cos(sphereCoords.z); + store.x = a * FastMath.cos(sphereCoords.y); + store.z = a * FastMath.sin(sphereCoords.y); + + return store; + } + + /** + * Converts a point from Cartesian coordinates (using positive Y as up) to + * Spherical and stores the results in the store var. (Radius, Azimuth, + * Polar) + */ + public static Vector3f cartesianToSpherical(Vector3f cartCoords, + Vector3f store) { + if (cartCoords.x == 0) + cartCoords.x = FastMath.FLT_EPSILON; + store.x = FastMath + .sqrt((cartCoords.x * cartCoords.x) + + (cartCoords.y * cartCoords.y) + + (cartCoords.z * cartCoords.z)); + store.y = FastMath.atan(cartCoords.z / cartCoords.x); + if (cartCoords.x < 0) + store.y += FastMath.PI; + store.z = FastMath.asin(cartCoords.y / store.x); + return store; + } + + /** + * Converts a point from Spherical coordinates to Cartesian (using positive + * Z as up) and stores the results in the store var. + */ + public static Vector3f sphericalToCartesianZ(Vector3f sphereCoords, + Vector3f store) { + store.z = sphereCoords.x * FastMath.sin(sphereCoords.z); + float a = sphereCoords.x * FastMath.cos(sphereCoords.z); + store.x = a * FastMath.cos(sphereCoords.y); + store.y = a * FastMath.sin(sphereCoords.y); + + return store; + } + + /** + * Converts a point from Cartesian coordinates (using positive Z as up) to + * Spherical and stores the results in the store var. (Radius, Azimuth, + * Polar) + */ + public static Vector3f cartesianZToSpherical(Vector3f cartCoords, + Vector3f store) { + if (cartCoords.x == 0) + cartCoords.x = FastMath.FLT_EPSILON; + store.x = FastMath + .sqrt((cartCoords.x * cartCoords.x) + + (cartCoords.y * cartCoords.y) + + (cartCoords.z * cartCoords.z)); + store.z = FastMath.atan(cartCoords.z / cartCoords.x); + if (cartCoords.x < 0) + store.z += FastMath.PI; + store.y = FastMath.asin(cartCoords.y / store.x); + return store; + } + + /** + * Takes an value and expresses it in terms of min to max. + * + * @param val - the angle to normalize (in radians) + * @return the normalized angle (also in radians) + */ + public static float normalize(float val, float min, float max) { + if (Float.isInfinite(val) || Float.isNaN(val)) + return 0f; + float range = max - min; + while (val > max) + val -= range; + while (val < min) + val += range; + return val; + } + + /** + * @param x the value whose sign is to be adjusted. + * @param y the value whose sign is to be used. + * @return x with its sign changed to match the sign of y. + */ + public static float copysign(float x, float y) { + if (y >= 0 && x <= -0) + return -x; + else if (y < 0 && x >= 0) + return -x; + else + return x; + } + + /** + * Take a float input and clamp it between min and max. + * + * @param input + * @param min + * @param max + * @return clamped input + */ + public static float clamp(float input, float min, float max) { + return (input < min) ? min : (input > max) ? max : input; + } + + + /** + * Return a random 2D vector + * this needs checked + */ + public static Vector3fImmutable randomVector2D() { + float x = ((ThreadLocalRandom.current().nextFloat() * 2) - 1); + float z = ((ThreadLocalRandom.current().nextFloat() * 2) - 1); + Vector3fImmutable ret = new Vector3fImmutable(x, 0, z); + return ret.normalize(); + } + + /** + * Turns a String into an Integer hash that the client will recognize. + * + * @param s The String to hash + * @return the Integer hash + */ + public static int hash(String s) { + int out = 0, pad = 0; + for (char c : s.toCharArray()) { + if (c == ' ' || c == '\\') { + pad += 5; + continue; + } + if (c > 0x40 && c < 0x60) + out ^= _rotl((byte) 0x60, pad); + out ^= _rotl((byte) (c & 0xDF), pad); + pad += 5; + } + return out; + } + + /** + * Utility function for making hashes + */ + private static int _rotl(int value, int shift) { + if ((shift &= 31) == 0) + return value; + return (value << shift) | (value >> (32 - shift)); + } + + /** + * Gets number of seconds until next hours + */ + + public static int secondsUntilNextHour() { + Calendar cal = Calendar.getInstance(); + int minute = cal.get(Calendar.MINUTE); + int second = cal.get(Calendar.SECOND); + return 3600 - (minute * 60) - second; + } + + public static float area(float x1, float y1, float x2, float y2, float x3, float y3) { + return (float) Math.abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0); //Change to *.5? + } + + public static float GetDegrees(float yRot) { + double radian = Math.asin(yRot); + float degrees = (float) Math.toDegrees(radian); + + degrees *= 2; + return degrees; + } + + public static float degreesToW(float degrees) { + return (float) Math.abs(Math.cos(Math.toRadians(degrees) / 2)); + } + + public static float degreesToYRotation(float degrees) { + return (float) Math.sin(Math.toRadians(degrees) / 2); + } } \ No newline at end of file diff --git a/src/engine/math/Matrix3f.java b/src/engine/math/Matrix3f.java index f0e1efe8..b147f835 100644 --- a/src/engine/math/Matrix3f.java +++ b/src/engine/math/Matrix3f.java @@ -6,7 +6,7 @@ // Magicbane Emulator Project © 2013 - 2022 // www.magicbane.com - package engine.math; +package engine.math; import org.pmw.tinylog.Logger; @@ -18,1203 +18,1138 @@ import java.nio.FloatBuffer; * internally and is accessible via the get and set methods. Convenience methods * are used for matrix operations as well as generating a matrix from a given * set of values. - * */ public class Matrix3f { - public float m00, m01, m02; - public float m10, m11, m12; - public float m20, m21, m22; - - /** - * Constructor instantiates a new Matrix3f object. The initial - * values for the matrix is that of the identity matrix. - * - */ - public Matrix3f() { - loadIdentity(); - } - - /** - * constructs a matrix with the given values. - * - * @param m00 - * 0x0 in the matrix. - * @param m01 - * 0x1 in the matrix. - * @param m02 - * 0x2 in the matrix. - * @param m10 - * 1x0 in the matrix. - * @param m11 - * 1x1 in the matrix. - * @param m12 - * 1x2 in the matrix. - * @param m20 - * 2x0 in the matrix. - * @param m21 - * 2x1 in the matrix. - * @param m22 - * 2x2 in the matrix. - */ - public Matrix3f(float m00, float m01, float m02, float m10, float m11, - float m12, float m20, float m21, float m22) { - - this.m00 = m00; - this.m01 = m01; - this.m02 = m02; - this.m10 = m10; - this.m11 = m11; - this.m12 = m12; - this.m20 = m20; - this.m21 = m21; - this.m22 = m22; - } - - /** - * Copy constructor that creates a new Matrix3f object that is - * the same as the provided matrix. - * - * @param mat - * the matrix to copy. - */ - public Matrix3f(Matrix3f mat) { - copy(mat); - } - - /** - * copy transfers the contents of a given matrix to this - * matrix. If a null matrix is supplied, this matrix is set to the identity - * matrix. - * - * @param matrix - * the matrix to copy. - */ - public void copy(Matrix3f matrix) { - if (null == matrix) { - loadIdentity(); - } else { - m00 = matrix.m00; - m01 = matrix.m01; - m02 = matrix.m02; - m10 = matrix.m10; - m11 = matrix.m11; - m12 = matrix.m12; - m20 = matrix.m20; - m21 = matrix.m21; - m22 = matrix.m22; - } - } - - /** - * get retrieves a value from the matrix at the given position. - * If the position is invalid a Exception is thrown. - * - * @param i - * the row index. - * @param j - * the column index. - * @return the value at (i, j). - * @throws Exception - */ - public float get(int i, int j) throws Exception { - switch (i) { - case 0: - switch (j) { - case 0: - return m00; - case 1: - return m01; - case 2: - return m02; - } - case 1: - switch (j) { - case 0: - return m10; - case 1: - return m11; - case 2: - return m12; - } - case 2: - switch (j) { - case 0: - return m20; - case 1: - return m21; - case 2: - return m22; - } - } - throw new Exception("Invalid indices into matrix."); - } - - /** - * get(float[]) returns the matrix in row-major or column-major - * order. - * - * @param data - * The array to return the data into. This array can be 9 or 16 - * floats in size. Only the upper 3x3 are assigned to in the case - * of a 16 element array. - * @param rowMajor - * True for row major storage in the array (translation in - * elements 3, 7, 11 for a 4x4), false for column major - * (translation in elements 12, 13, 14 for a 4x4). - * @throws Exception - */ - public void get(float[] data, boolean rowMajor) throws Exception { - if (data.length == 9) { - if (rowMajor) { - data[0] = m00; - data[1] = m01; - data[2] = m02; - data[3] = m10; - data[4] = m11; - data[5] = m12; - data[6] = m20; - data[7] = m21; - data[8] = m22; - } else { - data[0] = m00; - data[1] = m10; - data[2] = m20; - data[3] = m01; - data[4] = m11; - data[5] = m21; - data[6] = m02; - data[7] = m12; - data[8] = m22; - } - } else if (data.length == 16) { - if (rowMajor) { - data[0] = m00; - data[1] = m01; - data[2] = m02; - data[4] = m10; - data[5] = m11; - data[6] = m12; - data[8] = m20; - data[9] = m21; - data[10] = m22; - } else { - data[0] = m00; - data[1] = m10; - data[2] = m20; - data[4] = m01; - data[5] = m11; - data[6] = m21; - data[8] = m02; - data[9] = m12; - data[10] = m22; - } - } else { - throw new Exception("Array size must be 9 or 16 in Matrix3f.get()."); - } - } - - /** - * getColumn returns one of three columns specified by the - * parameter. This column is returned as a Vector3f object. - * - * @param i - * the column to retrieve. Must be between 0 and 2. - * @return the column specified by the index. - * @throws Exception - */ - public Vector3f getColumn(int i) throws Exception { - return getColumn(i, null); - } - - /** - * getColumn returns one of three columns specified by the - * parameter. This column is returned as a Vector3f object. - * - * @param i - * the column to retrieve. Must be between 0 and 2. - * @param store - * the vector object to store the result in. if null, a new one - * is created. - * @return the column specified by the index. - * @throws Exception - */ - public Vector3f getColumn(int i, Vector3f store) throws Exception { - if (store == null) - store = new Vector3f(); - switch (i) { - case 0: - store.x = m00; - store.y = m10; - store.z = m20; - break; - case 1: - store.x = m01; - store.y = m11; - store.z = m21; - break; - case 2: - store.x = m02; - store.y = m12; - store.z = m22; - break; - default: - throw new Exception("Invalid column index. " + i); - } - return store; - } - - /** - * getColumn returns one of three rows as specified by the - * parameter. This row is returned as a Vector3f object. - * - * @param i - * the row to retrieve. Must be between 0 and 2. - * @return the row specified by the index. - * @throws Exception - */ - public Vector3f getRow(int i) throws Exception { - return getRow(i, null); - } - - /** - * getRow returns one of three rows as specified by the - * parameter. This row is returned as a Vector3f object. - * - * @param i - * the row to retrieve. Must be between 0 and 2. - * @param store - * the vector object to store the result in. if null, a new one - * is created. - * @return the row specified by the index. - * @throws Exception - */ - public Vector3f getRow(int i, Vector3f store) throws Exception { - if (store == null) - store = new Vector3f(); - switch (i) { - case 0: - store.x = m00; - store.y = m01; - store.z = m02; - break; - case 1: - store.x = m10; - store.y = m11; - store.z = m12; - break; - case 2: - store.x = m20; - store.y = m21; - store.z = m22; - break; - default: - throw new Exception("Invalid row index. " + i); - } - return store; - } - - /** - * fillFloatBuffer fills a FloatBuffer object with the matrix - * data. - * - * @param fb - * the buffer to fill, starting at current position. Must have - * room for 9 more floats. - * @return matrix data as a FloatBuffer. (position is advanced by 9 and any - * limit set is not changed). - */ - public FloatBuffer fillFloatBuffer(FloatBuffer fb) { - fb.put(m00).put(m01).put(m02); - fb.put(m10).put(m11).put(m12); - fb.put(m20).put(m21).put(m22); - return fb; - } - - /** - * - * setColumn sets a particular column of this matrix to that - * represented by the provided vector. - * - * @param i - * the column to set. - * @param column - * the data to set. - * @throws Exception - */ - public void setColumn(int i, Vector3f column) throws Exception { - - if (column == null) { - return; - } - switch (i) { - case 0: - m00 = column.x; - m10 = column.y; - m20 = column.z; - break; - case 1: - m01 = column.x; - m11 = column.y; - m21 = column.z; - break; - case 2: - m02 = column.x; - m12 = column.y; - m22 = column.z; - break; - default: - throw new Exception("Invalid column index. " + i); - } - } - - /** - * - * setRow sets a particular row of this matrix to that - * represented by the provided vector. - * - * @param i - * the row to set. - * @param row - * the data to set. - * @throws Exception - */ - public void setRow(int i, Vector3f row) throws Exception { - - if (row == null) { - return; - } - switch (i) { - case 0: - m00 = row.x; - m01 = row.y; - m02 = row.z; - break; - case 1: - m10 = row.x; - m11 = row.y; - m12 = row.z; - break; - case 2: - m20 = row.x; - m21 = row.y; - m22 = row.z; - break; - default: - throw new Exception("Invalid row index. " + i); - } - } - - /** - * set places a given value into the matrix at the given - * position. If the position is invalid a Exception is thrown. - * - * @param i - * the row index. - * @param j - * the column index. - * @param value - * the value for (i, j). - * @throws Exception - */ - public void set(int i, int j, float value) throws Exception { - switch (i) { - case 0: - switch (j) { - case 0: - m00 = value; - return; - case 1: - m01 = value; - return; - case 2: - m02 = value; - return; - } - case 1: - switch (j) { - case 0: - m10 = value; - return; - case 1: - m11 = value; - return; - case 2: - m12 = value; - return; - } - case 2: - switch (j) { - case 0: - m20 = value; - return; - case 1: - m21 = value; - return; - case 2: - m22 = value; - return; - } - } - throw new Exception("Invalid indices into matrix."); - } - - /** - * - * set sets the values of the matrix to those supplied by the - * 3x3 two dimenion array. - * - * @param matrix - * the new values of the matrix. - * @throws Exception - * if the array is not of size 9. - */ - public void set(float[][] matrix) throws Exception { - if (matrix.length != 3 || matrix[0].length != 3) { - throw new Exception("Array must be of size 9."); - } - - m00 = matrix[0][0]; - m01 = matrix[0][1]; - m02 = matrix[0][2]; - m10 = matrix[1][0]; - m11 = matrix[1][1]; - m12 = matrix[1][2]; - m20 = matrix[2][0]; - m21 = matrix[2][1]; - m22 = matrix[2][2]; - } - - /** - * Recreate Matrix using the provided axis. - * - * @param uAxis - * Vector3f - * @param vAxis - * Vector3f - * @param wAxis - * Vector3f - */ - public void fromAxes(Vector3f uAxis, Vector3f vAxis, Vector3f wAxis) { - m00 = uAxis.x; - m10 = uAxis.y; - m20 = uAxis.z; - - m01 = vAxis.x; - m11 = vAxis.y; - m21 = vAxis.z; - - m02 = wAxis.x; - m12 = wAxis.y; - m22 = wAxis.z; - } - - /** - * set sets the values of this matrix from an array of values - * assuming that the data is rowMajor order; - * - * @param matrix - * the matrix to set the value to. - * @throws Exception - */ - public void set(float[] matrix) throws Exception { - set(matrix, true); - } - - /** - * set sets the values of this matrix from an array of values; - * - * @param matrix - * the matrix to set the value to. - * @param rowMajor - * whether the incoming data is in row or column major order. - */ - public void set(float[] matrix, boolean rowMajor) throws Exception { - if (matrix.length != 9) - throw new Exception("Array must be of size 9."); - - if (rowMajor) { - m00 = matrix[0]; - m01 = matrix[1]; - m02 = matrix[2]; - m10 = matrix[3]; - m11 = matrix[4]; - m12 = matrix[5]; - m20 = matrix[6]; - m21 = matrix[7]; - m22 = matrix[8]; - } else { - m00 = matrix[0]; - m01 = matrix[3]; - m02 = matrix[6]; - m10 = matrix[1]; - m11 = matrix[4]; - m12 = matrix[7]; - m20 = matrix[2]; - m21 = matrix[5]; - m22 = matrix[8]; - } - } - - /** - * - * set defines the values of the matrix based on a supplied - * Quaternion. It should be noted that all previous values will - * be overridden. - * - * @param quaternion - * the quaternion to create a rotational matrix from. - */ - public void set(Quaternion quaternion) { - quaternion.toRotationMatrix(this); - } - - /** - * loadIdentity sets this matrix to the identity matrix. Where - * all values are zero except those along the diagonal which are one. - * - */ - public void loadIdentity() { - m01 = m02 = m10 = m12 = m20 = m21 = 0; - m00 = m11 = m22 = 1; - } - - /** - * @return true if this matrix is identity - */ - public boolean isIdentity() { - return (m00 == 1 && m01 == 0 && m02 == 0) - && (m10 == 0 && m11 == 1 && m12 == 0) - && (m20 == 0 && m21 == 0 && m22 == 1); - } - - /** - * fromAngleAxis sets this matrix4f to the values specified by - * an angle and an axis of rotation. This method creates an object, so use - * fromAngleNormalAxis if your axis is already normalized. - * - * @param angle - * the angle to rotate (in radians). - * @param axis - * the axis of rotation. - */ - public void fromAngleAxis(float angle, Vector3f axis) { - Vector3f normAxis = axis.normalize(); - fromAngleNormalAxis(angle, normAxis); - } - - /** - * fromAngleNormalAxis sets this matrix4f to the values - * specified by an angle and a normalized axis of rotation. - * - * @param angle - * the angle to rotate (in radians). - * @param axis - * the axis of rotation (already normalized). - */ - public void fromAngleNormalAxis(float angle, Vector3f axis) { - float fCos = FastMath.cos(angle); - float fSin = FastMath.sin(angle); - float fOneMinusCos = ((float) 1.0) - fCos; - float fX2 = axis.x * axis.x; - float fY2 = axis.y * axis.y; - float fZ2 = axis.z * axis.z; - float fXYM = axis.x * axis.y * fOneMinusCos; - float fXZM = axis.x * axis.z * fOneMinusCos; - float fYZM = axis.y * axis.z * fOneMinusCos; - float fXSin = axis.x * fSin; - float fYSin = axis.y * fSin; - float fZSin = axis.z * fSin; - - m00 = fX2 * fOneMinusCos + fCos; - m01 = fXYM - fZSin; - m02 = fXZM + fYSin; - m10 = fXYM + fZSin; - m11 = fY2 * fOneMinusCos + fCos; - m12 = fYZM - fXSin; - m20 = fXZM - fYSin; - m21 = fYZM + fXSin; - m22 = fZ2 * fOneMinusCos + fCos; - } - - /** - * mult multiplies this matrix by a given matrix. The result - * matrix is returned as a new object. If the given matrix is null, a null - * matrix is returned. - * - * @param mat - * the matrix to multiply this matrix by. - * @return the result matrix. - */ - public Matrix3f mult(Matrix3f mat) { - return mult(mat, null); - } - - /** - * mult multiplies this matrix by a given matrix. The result - * matrix is returned as a new object. - * - * @param mat - * the matrix to multiply this matrix by. - * @param product - * the matrix to store the result in. if null, a new matrix3f is - * created. It is safe for mat and product to be the same object. - * @return a matrix3f object containing the result of this operation - */ - public Matrix3f mult(Matrix3f mat, Matrix3f product) { - - float temp00, temp01, temp02; - float temp10, temp11, temp12; - float temp20, temp21, temp22; - - if (product == null) - product = new Matrix3f(); - temp00 = m00 * mat.m00 + m01 * mat.m10 + m02 * mat.m20; - temp01 = m00 * mat.m01 + m01 * mat.m11 + m02 * mat.m21; - temp02 = m00 * mat.m02 + m01 * mat.m12 + m02 * mat.m22; - temp10 = m10 * mat.m00 + m11 * mat.m10 + m12 * mat.m20; - temp11 = m10 * mat.m01 + m11 * mat.m11 + m12 * mat.m21; - temp12 = m10 * mat.m02 + m11 * mat.m12 + m12 * mat.m22; - temp20 = m20 * mat.m00 + m21 * mat.m10 + m22 * mat.m20; - temp21 = m20 * mat.m01 + m21 * mat.m11 + m22 * mat.m21; - temp22 = m20 * mat.m02 + m21 * mat.m12 + m22 * mat.m22; - - product.m00 = temp00; - product.m01 = temp01; - product.m02 = temp02; - product.m10 = temp10; - product.m11 = temp11; - product.m12 = temp12; - product.m20 = temp20; - product.m21 = temp21; - product.m22 = temp22; - - return product; - } - - /** - * mult multiplies this matrix by a given Vector3f - * object. The result vector is returned. If the given vector is null, null - * will be returned. - * - * @param vec - * the vector to multiply this matrix by. - * @return the result vector. - */ - public Vector3f mult(Vector3f vec) { - return mult(vec, null); - } - - /** - * Multiplies this 3x3 matrix by the 1x3 Vector vec and stores the result in - * product. - * - * @param vec - * The Vector3f to multiply. - * @param product - * The Vector3f to store the result, it is safe for this to be - * the same as vec. - * @return The given product vector. - */ - public Vector3f mult(Vector3f vec, Vector3f product) { - - if (null == product) { - product = new Vector3f(); - } - - float x = vec.x; - float y = vec.y; - float z = vec.z; - - product.x = m00 * x + m01 * y + m02 * z; - product.y = m10 * x + m11 * y + m12 * z; - product.z = m20 * x + m21 * y + m22 * z; - return product; - } - - /** - * multLocal multiplies this matrix internally by a given float - * scale factor. - * - * @param scale - * the value to scale by. - * @return this Matrix3f - */ - public Matrix3f multLocal(float scale) { - m00 *= scale; - m01 *= scale; - m02 *= scale; - m10 *= scale; - m11 *= scale; - m12 *= scale; - m20 *= scale; - m21 *= scale; - m22 *= scale; - return this; - } - - /** - * multLocal multiplies this matrix by a given - * Vector3f object. The result vector is stored inside the - * passed vector, then returned . If the given vector is null, null will be - * returned. - * - * @param vec - * the vector to multiply this matrix by. - * @return The passed vector after multiplication - */ - public Vector3f multLocal(Vector3f vec) { - if (vec == null) - return null; - float x = vec.x; - float y = vec.y; - vec.x = m00 * x + m01 * y + m02 * vec.z; - vec.y = m10 * x + m11 * y + m12 * vec.z; - vec.z = m20 * x + m21 * y + m22 * vec.z; - return vec; - } - - /** - * mult multiplies this matrix by a given matrix. The result - * matrix is saved in the current matrix. If the given matrix is null, - * nothing happens. The current matrix is returned. This is equivalent to - * this*=mat - * - * @param mat - * the matrix to multiply this matrix by. - * @return This matrix, after the multiplication - */ - public Matrix3f multLocal(Matrix3f mat) { - - return mult(mat, this); - } - - /** - * Transposes this matrix in place. Returns this matrix for chaining - * - * @return This matrix after transpose - * @throws Exception - */ - public Matrix3f transposeLocal() throws Exception { - float[] tmp = new float[9]; - get(tmp, false); - set(tmp, true); - return this; - } - - /** - * Inverts this matrix as a new Matrix3f. - * - * @return The new inverse matrix - */ - public Matrix3f invert() { - return invert(null); - } - - /** - * Inverts this matrix and stores it in the given store. - * - * @return The store - */ - public Matrix3f invert(Matrix3f store) { - if (store == null) - store = new Matrix3f(); - - float det = determinant(); - if (FastMath.abs(det) <= 0) - return store.zero(); - - store.m00 = m11 * m22 - m12 * m21; - store.m01 = m02 * m21 - m01 * m22; - store.m02 = m01 * m12 - m02 * m11; - store.m10 = m12 * m20 - m10 * m22; - store.m11 = m00 * m22 - m02 * m20; - store.m12 = m02 * m10 - m00 * m12; - store.m20 = m10 * m21 - m11 * m20; - store.m21 = m01 * m20 - m00 * m21; - store.m22 = m00 * m11 - m01 * m10; - - store.multLocal(1f / det); - return store; - } - - /** - * Inverts this matrix locally. - * - * @return this - */ - public Matrix3f invertLocal() { - float det = determinant(); - if (FastMath.abs(det) <= FastMath.FLT_EPSILON) - return zero(); - - float f00 = m11 * m22 - m12 * m21; - float f01 = m02 * m21 - m01 * m22; - float f02 = m01 * m12 - m02 * m11; - float f10 = m12 * m20 - m10 * m22; - float f11 = m00 * m22 - m02 * m20; - float f12 = m02 * m10 - m00 * m12; - float f20 = m10 * m21 - m11 * m20; - float f21 = m01 * m20 - m00 * m21; - float f22 = m00 * m11 - m01 * m10; - - m00 = f00; - m01 = f01; - m02 = f02; - m10 = f10; - m11 = f11; - m12 = f12; - m20 = f20; - m21 = f21; - m22 = f22; - - multLocal(1f / det); - return this; - } - - /** - * Returns a new matrix representing the adjoint of this matrix. - * - * @return The adjoint matrix - */ - public Matrix3f adjoint() { - return adjoint(null); - } - - /** - * Places the adjoint of this matrix in store (creates store if null.) - * - * @param store - * The matrix to store the result in. If null, a new matrix is - * created. - * @return store - */ - public Matrix3f adjoint(Matrix3f store) { - if (store == null) - store = new Matrix3f(); - - store.m00 = m11 * m22 - m12 * m21; - store.m01 = m02 * m21 - m01 * m22; - store.m02 = m01 * m12 - m02 * m11; - store.m10 = m12 * m20 - m10 * m22; - store.m11 = m00 * m22 - m02 * m20; - store.m12 = m02 * m10 - m00 * m12; - store.m20 = m10 * m21 - m11 * m20; - store.m21 = m01 * m20 - m00 * m21; - store.m22 = m00 * m11 - m01 * m10; - - return store; - } - - /** - * determinant generates the determinate of this matrix. - * - * @return the determinate - */ - public float determinant() { - float fCo00 = m11 * m22 - m12 * m21; - float fCo10 = m12 * m20 - m10 * m22; - float fCo20 = m10 * m21 - m11 * m20; + public float m00, m01, m02; + public float m10, m11, m12; + public float m20, m21, m22; + + /** + * Constructor instantiates a new Matrix3f object. The initial + * values for the matrix is that of the identity matrix. + */ + public Matrix3f() { + loadIdentity(); + } + + /** + * constructs a matrix with the given values. + * + * @param m00 0x0 in the matrix. + * @param m01 0x1 in the matrix. + * @param m02 0x2 in the matrix. + * @param m10 1x0 in the matrix. + * @param m11 1x1 in the matrix. + * @param m12 1x2 in the matrix. + * @param m20 2x0 in the matrix. + * @param m21 2x1 in the matrix. + * @param m22 2x2 in the matrix. + */ + public Matrix3f(float m00, float m01, float m02, float m10, float m11, + float m12, float m20, float m21, float m22) { + + this.m00 = m00; + this.m01 = m01; + this.m02 = m02; + this.m10 = m10; + this.m11 = m11; + this.m12 = m12; + this.m20 = m20; + this.m21 = m21; + this.m22 = m22; + } + + /** + * Copy constructor that creates a new Matrix3f object that is + * the same as the provided matrix. + * + * @param mat the matrix to copy. + */ + public Matrix3f(Matrix3f mat) { + copy(mat); + } + + static boolean equalIdentity(Matrix3f mat) { + if (Math.abs(mat.m00 - 1) > 1e-4) + return false; + if (Math.abs(mat.m11 - 1) > 1e-4) + return false; + if (Math.abs(mat.m22 - 1) > 1e-4) + return false; + + if (Math.abs(mat.m01) > 1e-4) + return false; + if (Math.abs(mat.m02) > 1e-4) + return false; + + if (Math.abs(mat.m10) > 1e-4) + return false; + if (Math.abs(mat.m12) > 1e-4) + return false; + + if (Math.abs(mat.m20) > 1e-4) + return false; + return !(Math.abs(mat.m21) > 1e-4); + } + + /** + * copy transfers the contents of a given matrix to this + * matrix. If a null matrix is supplied, this matrix is set to the identity + * matrix. + * + * @param matrix the matrix to copy. + */ + public void copy(Matrix3f matrix) { + if (null == matrix) { + loadIdentity(); + } else { + m00 = matrix.m00; + m01 = matrix.m01; + m02 = matrix.m02; + m10 = matrix.m10; + m11 = matrix.m11; + m12 = matrix.m12; + m20 = matrix.m20; + m21 = matrix.m21; + m22 = matrix.m22; + } + } + + /** + * get retrieves a value from the matrix at the given position. + * If the position is invalid a Exception is thrown. + * + * @param i the row index. + * @param j the column index. + * @return the value at (i, j). + * @throws Exception + */ + public float get(int i, int j) throws Exception { + switch (i) { + case 0: + switch (j) { + case 0: + return m00; + case 1: + return m01; + case 2: + return m02; + } + case 1: + switch (j) { + case 0: + return m10; + case 1: + return m11; + case 2: + return m12; + } + case 2: + switch (j) { + case 0: + return m20; + case 1: + return m21; + case 2: + return m22; + } + } + throw new Exception("Invalid indices into matrix."); + } + + /** + * get(float[]) returns the matrix in row-major or column-major + * order. + * + * @param data The array to return the data into. This array can be 9 or 16 + * floats in size. Only the upper 3x3 are assigned to in the case + * of a 16 element array. + * @param rowMajor True for row major storage in the array (translation in + * elements 3, 7, 11 for a 4x4), false for column major + * (translation in elements 12, 13, 14 for a 4x4). + * @throws Exception + */ + public void get(float[] data, boolean rowMajor) throws Exception { + if (data.length == 9) { + if (rowMajor) { + data[0] = m00; + data[1] = m01; + data[2] = m02; + data[3] = m10; + data[4] = m11; + data[5] = m12; + data[6] = m20; + data[7] = m21; + data[8] = m22; + } else { + data[0] = m00; + data[1] = m10; + data[2] = m20; + data[3] = m01; + data[4] = m11; + data[5] = m21; + data[6] = m02; + data[7] = m12; + data[8] = m22; + } + } else if (data.length == 16) { + if (rowMajor) { + data[0] = m00; + data[1] = m01; + data[2] = m02; + data[4] = m10; + data[5] = m11; + data[6] = m12; + data[8] = m20; + data[9] = m21; + data[10] = m22; + } else { + data[0] = m00; + data[1] = m10; + data[2] = m20; + data[4] = m01; + data[5] = m11; + data[6] = m21; + data[8] = m02; + data[9] = m12; + data[10] = m22; + } + } else { + throw new Exception("Array size must be 9 or 16 in Matrix3f.get()."); + } + } + + /** + * getColumn returns one of three columns specified by the + * parameter. This column is returned as a Vector3f object. + * + * @param i the column to retrieve. Must be between 0 and 2. + * @return the column specified by the index. + * @throws Exception + */ + public Vector3f getColumn(int i) throws Exception { + return getColumn(i, null); + } + + /** + * getColumn returns one of three columns specified by the + * parameter. This column is returned as a Vector3f object. + * + * @param i the column to retrieve. Must be between 0 and 2. + * @param store the vector object to store the result in. if null, a new one + * is created. + * @return the column specified by the index. + * @throws Exception + */ + public Vector3f getColumn(int i, Vector3f store) throws Exception { + if (store == null) + store = new Vector3f(); + switch (i) { + case 0: + store.x = m00; + store.y = m10; + store.z = m20; + break; + case 1: + store.x = m01; + store.y = m11; + store.z = m21; + break; + case 2: + store.x = m02; + store.y = m12; + store.z = m22; + break; + default: + throw new Exception("Invalid column index. " + i); + } + return store; + } + + /** + * getColumn returns one of three rows as specified by the + * parameter. This row is returned as a Vector3f object. + * + * @param i the row to retrieve. Must be between 0 and 2. + * @return the row specified by the index. + * @throws Exception + */ + public Vector3f getRow(int i) throws Exception { + return getRow(i, null); + } + + /** + * getRow returns one of three rows as specified by the + * parameter. This row is returned as a Vector3f object. + * + * @param i the row to retrieve. Must be between 0 and 2. + * @param store the vector object to store the result in. if null, a new one + * is created. + * @return the row specified by the index. + * @throws Exception + */ + public Vector3f getRow(int i, Vector3f store) throws Exception { + if (store == null) + store = new Vector3f(); + switch (i) { + case 0: + store.x = m00; + store.y = m01; + store.z = m02; + break; + case 1: + store.x = m10; + store.y = m11; + store.z = m12; + break; + case 2: + store.x = m20; + store.y = m21; + store.z = m22; + break; + default: + throw new Exception("Invalid row index. " + i); + } + return store; + } + + /** + * fillFloatBuffer fills a FloatBuffer object with the matrix + * data. + * + * @param fb the buffer to fill, starting at current position. Must have + * room for 9 more floats. + * @return matrix data as a FloatBuffer. (position is advanced by 9 and any + * limit set is not changed). + */ + public FloatBuffer fillFloatBuffer(FloatBuffer fb) { + fb.put(m00).put(m01).put(m02); + fb.put(m10).put(m11).put(m12); + fb.put(m20).put(m21).put(m22); + return fb; + } + + /** + * setColumn sets a particular column of this matrix to that + * represented by the provided vector. + * + * @param i the column to set. + * @param column the data to set. + * @throws Exception + */ + public void setColumn(int i, Vector3f column) throws Exception { + + if (column == null) { + return; + } + switch (i) { + case 0: + m00 = column.x; + m10 = column.y; + m20 = column.z; + break; + case 1: + m01 = column.x; + m11 = column.y; + m21 = column.z; + break; + case 2: + m02 = column.x; + m12 = column.y; + m22 = column.z; + break; + default: + throw new Exception("Invalid column index. " + i); + } + } + + /** + * setRow sets a particular row of this matrix to that + * represented by the provided vector. + * + * @param i the row to set. + * @param row the data to set. + * @throws Exception + */ + public void setRow(int i, Vector3f row) throws Exception { + + if (row == null) { + return; + } + switch (i) { + case 0: + m00 = row.x; + m01 = row.y; + m02 = row.z; + break; + case 1: + m10 = row.x; + m11 = row.y; + m12 = row.z; + break; + case 2: + m20 = row.x; + m21 = row.y; + m22 = row.z; + break; + default: + throw new Exception("Invalid row index. " + i); + } + } + + /** + * set places a given value into the matrix at the given + * position. If the position is invalid a Exception is thrown. + * + * @param i the row index. + * @param j the column index. + * @param value the value for (i, j). + * @throws Exception + */ + public void set(int i, int j, float value) throws Exception { + switch (i) { + case 0: + switch (j) { + case 0: + m00 = value; + return; + case 1: + m01 = value; + return; + case 2: + m02 = value; + return; + } + case 1: + switch (j) { + case 0: + m10 = value; + return; + case 1: + m11 = value; + return; + case 2: + m12 = value; + return; + } + case 2: + switch (j) { + case 0: + m20 = value; + return; + case 1: + m21 = value; + return; + case 2: + m22 = value; + return; + } + } + throw new Exception("Invalid indices into matrix."); + } + + /** + * set sets the values of the matrix to those supplied by the + * 3x3 two dimenion array. + * + * @param matrix the new values of the matrix. + * @throws Exception if the array is not of size 9. + */ + public void set(float[][] matrix) throws Exception { + if (matrix.length != 3 || matrix[0].length != 3) { + throw new Exception("Array must be of size 9."); + } + + m00 = matrix[0][0]; + m01 = matrix[0][1]; + m02 = matrix[0][2]; + m10 = matrix[1][0]; + m11 = matrix[1][1]; + m12 = matrix[1][2]; + m20 = matrix[2][0]; + m21 = matrix[2][1]; + m22 = matrix[2][2]; + } + + /** + * Recreate Matrix using the provided axis. + * + * @param uAxis Vector3f + * @param vAxis Vector3f + * @param wAxis Vector3f + */ + public void fromAxes(Vector3f uAxis, Vector3f vAxis, Vector3f wAxis) { + m00 = uAxis.x; + m10 = uAxis.y; + m20 = uAxis.z; + + m01 = vAxis.x; + m11 = vAxis.y; + m21 = vAxis.z; + + m02 = wAxis.x; + m12 = wAxis.y; + m22 = wAxis.z; + } + + /** + * set sets the values of this matrix from an array of values + * assuming that the data is rowMajor order; + * + * @param matrix the matrix to set the value to. + * @throws Exception + */ + public void set(float[] matrix) throws Exception { + set(matrix, true); + } + + /** + * set sets the values of this matrix from an array of values; + * + * @param matrix the matrix to set the value to. + * @param rowMajor whether the incoming data is in row or column major order. + */ + public void set(float[] matrix, boolean rowMajor) throws Exception { + if (matrix.length != 9) + throw new Exception("Array must be of size 9."); + + if (rowMajor) { + m00 = matrix[0]; + m01 = matrix[1]; + m02 = matrix[2]; + m10 = matrix[3]; + m11 = matrix[4]; + m12 = matrix[5]; + m20 = matrix[6]; + m21 = matrix[7]; + m22 = matrix[8]; + } else { + m00 = matrix[0]; + m01 = matrix[3]; + m02 = matrix[6]; + m10 = matrix[1]; + m11 = matrix[4]; + m12 = matrix[7]; + m20 = matrix[2]; + m21 = matrix[5]; + m22 = matrix[8]; + } + } + + /** + * set defines the values of the matrix based on a supplied + * Quaternion. It should be noted that all previous values will + * be overridden. + * + * @param quaternion the quaternion to create a rotational matrix from. + */ + public void set(Quaternion quaternion) { + quaternion.toRotationMatrix(this); + } + + /** + * loadIdentity sets this matrix to the identity matrix. Where + * all values are zero except those along the diagonal which are one. + */ + public void loadIdentity() { + m01 = m02 = m10 = m12 = m20 = m21 = 0; + m00 = m11 = m22 = 1; + } + + /** + * @return true if this matrix is identity + */ + public boolean isIdentity() { + return (m00 == 1 && m01 == 0 && m02 == 0) + && (m10 == 0 && m11 == 1 && m12 == 0) + && (m20 == 0 && m21 == 0 && m22 == 1); + } + + /** + * fromAngleAxis sets this matrix4f to the values specified by + * an angle and an axis of rotation. This method creates an object, so use + * fromAngleNormalAxis if your axis is already normalized. + * + * @param angle the angle to rotate (in radians). + * @param axis the axis of rotation. + */ + public void fromAngleAxis(float angle, Vector3f axis) { + Vector3f normAxis = axis.normalize(); + fromAngleNormalAxis(angle, normAxis); + } + + /** + * fromAngleNormalAxis sets this matrix4f to the values + * specified by an angle and a normalized axis of rotation. + * + * @param angle the angle to rotate (in radians). + * @param axis the axis of rotation (already normalized). + */ + public void fromAngleNormalAxis(float angle, Vector3f axis) { + float fCos = FastMath.cos(angle); + float fSin = FastMath.sin(angle); + float fOneMinusCos = ((float) 1.0) - fCos; + float fX2 = axis.x * axis.x; + float fY2 = axis.y * axis.y; + float fZ2 = axis.z * axis.z; + float fXYM = axis.x * axis.y * fOneMinusCos; + float fXZM = axis.x * axis.z * fOneMinusCos; + float fYZM = axis.y * axis.z * fOneMinusCos; + float fXSin = axis.x * fSin; + float fYSin = axis.y * fSin; + float fZSin = axis.z * fSin; + + m00 = fX2 * fOneMinusCos + fCos; + m01 = fXYM - fZSin; + m02 = fXZM + fYSin; + m10 = fXYM + fZSin; + m11 = fY2 * fOneMinusCos + fCos; + m12 = fYZM - fXSin; + m20 = fXZM - fYSin; + m21 = fYZM + fXSin; + m22 = fZ2 * fOneMinusCos + fCos; + } + + /** + * mult multiplies this matrix by a given matrix. The result + * matrix is returned as a new object. If the given matrix is null, a null + * matrix is returned. + * + * @param mat the matrix to multiply this matrix by. + * @return the result matrix. + */ + public Matrix3f mult(Matrix3f mat) { + return mult(mat, null); + } + + /** + * mult multiplies this matrix by a given matrix. The result + * matrix is returned as a new object. + * + * @param mat the matrix to multiply this matrix by. + * @param product the matrix to store the result in. if null, a new matrix3f is + * created. It is safe for mat and product to be the same object. + * @return a matrix3f object containing the result of this operation + */ + public Matrix3f mult(Matrix3f mat, Matrix3f product) { + + float temp00, temp01, temp02; + float temp10, temp11, temp12; + float temp20, temp21, temp22; + + if (product == null) + product = new Matrix3f(); + temp00 = m00 * mat.m00 + m01 * mat.m10 + m02 * mat.m20; + temp01 = m00 * mat.m01 + m01 * mat.m11 + m02 * mat.m21; + temp02 = m00 * mat.m02 + m01 * mat.m12 + m02 * mat.m22; + temp10 = m10 * mat.m00 + m11 * mat.m10 + m12 * mat.m20; + temp11 = m10 * mat.m01 + m11 * mat.m11 + m12 * mat.m21; + temp12 = m10 * mat.m02 + m11 * mat.m12 + m12 * mat.m22; + temp20 = m20 * mat.m00 + m21 * mat.m10 + m22 * mat.m20; + temp21 = m20 * mat.m01 + m21 * mat.m11 + m22 * mat.m21; + temp22 = m20 * mat.m02 + m21 * mat.m12 + m22 * mat.m22; + + product.m00 = temp00; + product.m01 = temp01; + product.m02 = temp02; + product.m10 = temp10; + product.m11 = temp11; + product.m12 = temp12; + product.m20 = temp20; + product.m21 = temp21; + product.m22 = temp22; + + return product; + } + + /** + * mult multiplies this matrix by a given Vector3f + * object. The result vector is returned. If the given vector is null, null + * will be returned. + * + * @param vec the vector to multiply this matrix by. + * @return the result vector. + */ + public Vector3f mult(Vector3f vec) { + return mult(vec, null); + } + + /** + * Multiplies this 3x3 matrix by the 1x3 Vector vec and stores the result in + * product. + * + * @param vec The Vector3f to multiply. + * @param product The Vector3f to store the result, it is safe for this to be + * the same as vec. + * @return The given product vector. + */ + public Vector3f mult(Vector3f vec, Vector3f product) { + + if (null == product) { + product = new Vector3f(); + } + + float x = vec.x; + float y = vec.y; + float z = vec.z; + + product.x = m00 * x + m01 * y + m02 * z; + product.y = m10 * x + m11 * y + m12 * z; + product.z = m20 * x + m21 * y + m22 * z; + return product; + } + + /** + * multLocal multiplies this matrix internally by a given float + * scale factor. + * + * @param scale the value to scale by. + * @return this Matrix3f + */ + public Matrix3f multLocal(float scale) { + m00 *= scale; + m01 *= scale; + m02 *= scale; + m10 *= scale; + m11 *= scale; + m12 *= scale; + m20 *= scale; + m21 *= scale; + m22 *= scale; + return this; + } + + /** + * multLocal multiplies this matrix by a given + * Vector3f object. The result vector is stored inside the + * passed vector, then returned . If the given vector is null, null will be + * returned. + * + * @param vec the vector to multiply this matrix by. + * @return The passed vector after multiplication + */ + public Vector3f multLocal(Vector3f vec) { + if (vec == null) + return null; + float x = vec.x; + float y = vec.y; + vec.x = m00 * x + m01 * y + m02 * vec.z; + vec.y = m10 * x + m11 * y + m12 * vec.z; + vec.z = m20 * x + m21 * y + m22 * vec.z; + return vec; + } + + /** + * mult multiplies this matrix by a given matrix. The result + * matrix is saved in the current matrix. If the given matrix is null, + * nothing happens. The current matrix is returned. This is equivalent to + * this*=mat + * + * @param mat the matrix to multiply this matrix by. + * @return This matrix, after the multiplication + */ + public Matrix3f multLocal(Matrix3f mat) { + + return mult(mat, this); + } + + /** + * Transposes this matrix in place. Returns this matrix for chaining + * + * @return This matrix after transpose + * @throws Exception + */ + public Matrix3f transposeLocal() throws Exception { + float[] tmp = new float[9]; + get(tmp, false); + set(tmp, true); + return this; + } + + /** + * Inverts this matrix as a new Matrix3f. + * + * @return The new inverse matrix + */ + public Matrix3f invert() { + return invert(null); + } + + /** + * Inverts this matrix and stores it in the given store. + * + * @return The store + */ + public Matrix3f invert(Matrix3f store) { + if (store == null) + store = new Matrix3f(); + + float det = determinant(); + if (FastMath.abs(det) <= 0) + return store.zero(); + + store.m00 = m11 * m22 - m12 * m21; + store.m01 = m02 * m21 - m01 * m22; + store.m02 = m01 * m12 - m02 * m11; + store.m10 = m12 * m20 - m10 * m22; + store.m11 = m00 * m22 - m02 * m20; + store.m12 = m02 * m10 - m00 * m12; + store.m20 = m10 * m21 - m11 * m20; + store.m21 = m01 * m20 - m00 * m21; + store.m22 = m00 * m11 - m01 * m10; + + store.multLocal(1f / det); + return store; + } + + /** + * Inverts this matrix locally. + * + * @return this + */ + public Matrix3f invertLocal() { + float det = determinant(); + if (FastMath.abs(det) <= FastMath.FLT_EPSILON) + return zero(); + + float f00 = m11 * m22 - m12 * m21; + float f01 = m02 * m21 - m01 * m22; + float f02 = m01 * m12 - m02 * m11; + float f10 = m12 * m20 - m10 * m22; + float f11 = m00 * m22 - m02 * m20; + float f12 = m02 * m10 - m00 * m12; + float f20 = m10 * m21 - m11 * m20; + float f21 = m01 * m20 - m00 * m21; + float f22 = m00 * m11 - m01 * m10; + + m00 = f00; + m01 = f01; + m02 = f02; + m10 = f10; + m11 = f11; + m12 = f12; + m20 = f20; + m21 = f21; + m22 = f22; + + multLocal(1f / det); + return this; + } + + /** + * Returns a new matrix representing the adjoint of this matrix. + * + * @return The adjoint matrix + */ + public Matrix3f adjoint() { + return adjoint(null); + } + + /** + * Places the adjoint of this matrix in store (creates store if null.) + * + * @param store The matrix to store the result in. If null, a new matrix is + * created. + * @return store + */ + public Matrix3f adjoint(Matrix3f store) { + if (store == null) + store = new Matrix3f(); + + store.m00 = m11 * m22 - m12 * m21; + store.m01 = m02 * m21 - m01 * m22; + store.m02 = m01 * m12 - m02 * m11; + store.m10 = m12 * m20 - m10 * m22; + store.m11 = m00 * m22 - m02 * m20; + store.m12 = m02 * m10 - m00 * m12; + store.m20 = m10 * m21 - m11 * m20; + store.m21 = m01 * m20 - m00 * m21; + store.m22 = m00 * m11 - m01 * m10; + + return store; + } + + /** + * determinant generates the determinate of this matrix. + * + * @return the determinate + */ + public float determinant() { + float fCo00 = m11 * m22 - m12 * m21; + float fCo10 = m12 * m20 - m10 * m22; + float fCo20 = m10 * m21 - m11 * m20; return m00 * fCo00 + m01 * fCo10 + m02 * fCo20; - } - - /** - * Sets all of the values in this matrix to zero. - * - * @return this matrix - */ - public Matrix3f zero() { - m00 = m01 = m02 = m10 = m11 = m12 = m20 = m21 = m22 = 0.0f; - return this; - } - - /** - * add adds the values of a parameter matrix to this matrix. - * - * @param mat - * the matrix to add to this. - */ - public void add(Matrix3f mat) { - m00 += mat.m00; - m01 += mat.m01; - m02 += mat.m02; - m10 += mat.m10; - m11 += mat.m11; - m12 += mat.m12; - m20 += mat.m20; - m21 += mat.m21; - m22 += mat.m22; - } - - /** - * transpose locally transposes this Matrix. This is - * inconsistent with general value vs local semantics, but is preserved for - * backwards compatibility. Use transposeNew() to transpose to a new object - * (value). - * - * @return this object for chaining. - * @throws Exception - */ - public Matrix3f transpose() throws Exception { - return transposeLocal(); - } - - /** - * transposeNew returns a transposed version of this matrix. - * - * @return The new Matrix3f object. - */ - public Matrix3f transposeNew() { + } + + /** + * Sets all of the values in this matrix to zero. + * + * @return this matrix + */ + public Matrix3f zero() { + m00 = m01 = m02 = m10 = m11 = m12 = m20 = m21 = m22 = 0.0f; + return this; + } + + /** + * add adds the values of a parameter matrix to this matrix. + * + * @param mat the matrix to add to this. + */ + public void add(Matrix3f mat) { + m00 += mat.m00; + m01 += mat.m01; + m02 += mat.m02; + m10 += mat.m10; + m11 += mat.m11; + m12 += mat.m12; + m20 += mat.m20; + m21 += mat.m21; + m22 += mat.m22; + } + + /** + * transpose locally transposes this Matrix. This is + * inconsistent with general value vs local semantics, but is preserved for + * backwards compatibility. Use transposeNew() to transpose to a new object + * (value). + * + * @return this object for chaining. + * @throws Exception + */ + public Matrix3f transpose() throws Exception { + return transposeLocal(); + } + + /** + * transposeNew returns a transposed version of this matrix. + * + * @return The new Matrix3f object. + */ + public Matrix3f transposeNew() { return new Matrix3f(m00, m10, m20, m01, m11, m21, m02, m12, m22); - } - - /** - * toString returns the string representation of this object. - * It is in a format of a 3x3 matrix. For example, an identity matrix would - * be represented by the following string. com.jme.math.Matrix3f
- * [
- * 1.0 0.0 0.0
- * 0.0 1.0 0.0
- * 0.0 0.0 1.0
- * ]
- * - * @return the string representation of this object. - */ - @Override - public String toString() { - StringBuffer result = new StringBuffer("com.jme.math.Matrix3f\n[\n"); - result.append(' '); - result.append(m00); - result.append(" "); - result.append(m01); - result.append(" "); - result.append(m02); - result.append(" \n"); - result.append(' '); - result.append(m10); - result.append(" "); - result.append(m11); - result.append(" "); - result.append(m12); - result.append(" \n"); - result.append(' '); - result.append(m20); - result.append(" "); - result.append(m21); - result.append(" "); - result.append(m22); - result.append(" \n]"); - return result.toString(); - } - - /** - * - * hashCode returns the hash code value as an integer and is - * supported for the benefit of hashing based collection classes such as - * Hashtable, HashMap, HashSet etc. - * - * @return the hashcode for this instance of Matrix4f. - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - int hash = 37; - hash = 37 * hash + Float.floatToIntBits(m00); - hash = 37 * hash + Float.floatToIntBits(m01); - hash = 37 * hash + Float.floatToIntBits(m02); - - hash = 37 * hash + Float.floatToIntBits(m10); - hash = 37 * hash + Float.floatToIntBits(m11); - hash = 37 * hash + Float.floatToIntBits(m12); - - hash = 37 * hash + Float.floatToIntBits(m20); - hash = 37 * hash + Float.floatToIntBits(m21); - hash = 37 * hash + Float.floatToIntBits(m22); - - return hash; - } - - /** - * are these two matrices the same? they are is they both have the same mXX - * values. - * - * @param o - * the object to compare for equality - * @return true if they are equal - */ - @Override - public boolean equals(Object o) { - if (!(o instanceof Matrix3f) || o == null) { - return false; - } - - if (this == o) { - return true; - } - - Matrix3f comp = (Matrix3f) o; - if (Float.compare(m00, comp.m00) != 0) - return false; - if (Float.compare(m01, comp.m01) != 0) - return false; - if (Float.compare(m02, comp.m02) != 0) - return false; - - if (Float.compare(m10, comp.m10) != 0) - return false; - if (Float.compare(m11, comp.m11) != 0) - return false; - if (Float.compare(m12, comp.m12) != 0) - return false; - - if (Float.compare(m20, comp.m20) != 0) - return false; - if (Float.compare(m21, comp.m21) != 0) - return false; - return Float.compare(m22, comp.m22) == 0; - } - - /** - * A function for creating a rotation matrix that rotates a vector called - * "start" into another vector called "end". - * - * @param start - * normalized non-zero starting vector - * @param end - * normalized non-zero ending vector - * @throws Exception - * @see "Tomas Miller, John Hughes \"Efficiently Building a Matrix to Rotate - * \ One Vector to Another\" Journal of Graphics Tools, 4(4):1-4, 1999" - */ - public void fromStartEndVectors(Vector3f start, Vector3f end) - throws Exception { - Vector3f v = new Vector3f(); - float e, h, f; - - start.cross(end, v); - e = start.dot(end); - f = (e < 0) ? -e : e; - - // if "from" and "to" vectors are nearly parallel - if (f > 1.0f - FastMath.ZERO_TOLERANCE) { - Vector3f u = new Vector3f(); - Vector3f x = new Vector3f(); - float c1, c2, c3; /* coefficients for later use */ - int i, j; - - x.x = (start.x > 0.0) ? start.x : -start.x; - x.y = (start.y > 0.0) ? start.y : -start.y; - x.z = (start.z > 0.0) ? start.z : -start.z; - - if (x.x < x.y) { - if (x.x < x.z) { - x.x = 1.0f; - x.y = x.z = 0.0f; - } else { - x.z = 1.0f; - x.x = x.y = 0.0f; - } - } else { - if (x.y < x.z) { - x.y = 1.0f; - x.x = x.z = 0.0f; - } else { - x.z = 1.0f; - x.x = x.y = 0.0f; - } - } - - u.x = x.x - start.x; - u.y = x.y - start.y; - u.z = x.z - start.z; - v.x = x.x - end.x; - v.y = x.y - end.y; - v.z = x.z - end.z; - - c1 = 2.0f / u.dot(u); - c2 = 2.0f / v.dot(v); - c3 = c1 * c2 * u.dot(v); - - for (i = 0; i < 3; i++) { - for (j = 0; j < 3; j++) { - float val = -c1 * u.get(i) * u.get(j) - c2 * v.get(i) - * v.get(j) + c3 * v.get(i) * u.get(j); - set(i, j, val); - } - float val = get(i, i); - set(i, i, val + 1.0f); - } - } else { - // the most common case, unless "start"="end", or "start"=-"end" - float hvx, hvz, hvxy, hvxz, hvyz; - h = 1.0f / (1.0f + e); - hvx = h * v.x; - hvz = h * v.z; - hvxy = hvx * v.y; - hvxz = hvx * v.z; - hvyz = hvz * v.y; - set(0, 0, e + hvx * v.x); - set(0, 1, hvxy - v.z); - set(0, 2, hvxz + v.y); - - set(1, 0, hvxy + v.z); - set(1, 1, e + h * v.y * v.y); - set(1, 2, hvyz - v.x); - - set(2, 0, hvxz - v.y); - set(2, 1, hvyz + v.x); - set(2, 2, e + hvz * v.z); - } - } - - /** - * scale scales the operation performed by this matrix on a - * per-component basis. - * - * @param scale - * The scale applied to each of the X, Y and Z output values. - */ - public void scale(Vector3f scale) { - m00 *= scale.x; - m10 *= scale.x; - m20 *= scale.x; - m01 *= scale.y; - m11 *= scale.y; - m21 *= scale.y; - m02 *= scale.z; - m12 *= scale.z; - m22 *= scale.z; - } - - static boolean equalIdentity(Matrix3f mat) { - if (Math.abs(mat.m00 - 1) > 1e-4) - return false; - if (Math.abs(mat.m11 - 1) > 1e-4) - return false; - if (Math.abs(mat.m22 - 1) > 1e-4) - return false; - - if (Math.abs(mat.m01) > 1e-4) - return false; - if (Math.abs(mat.m02) > 1e-4) - return false; - - if (Math.abs(mat.m10) > 1e-4) - return false; - if (Math.abs(mat.m12) > 1e-4) - return false; - - if (Math.abs(mat.m20) > 1e-4) - return false; - return !(Math.abs(mat.m21) > 1e-4); - } - - @Override - public Matrix3f clone() { - try { - return (Matrix3f) super.clone(); - } catch (CloneNotSupportedException e) { - Logger.error( e); - throw new AssertionError(); // can not happen - } - } + } + + /** + * toString returns the string representation of this object. + * It is in a format of a 3x3 matrix. For example, an identity matrix would + * be represented by the following string. com.jme.math.Matrix3f
+ * [
+ * 1.0 0.0 0.0
+ * 0.0 1.0 0.0
+ * 0.0 0.0 1.0
+ * ]
+ * + * @return the string representation of this object. + */ + @Override + public String toString() { + StringBuffer result = new StringBuffer("com.jme.math.Matrix3f\n[\n"); + result.append(' '); + result.append(m00); + result.append(" "); + result.append(m01); + result.append(" "); + result.append(m02); + result.append(" \n"); + result.append(' '); + result.append(m10); + result.append(" "); + result.append(m11); + result.append(" "); + result.append(m12); + result.append(" \n"); + result.append(' '); + result.append(m20); + result.append(" "); + result.append(m21); + result.append(" "); + result.append(m22); + result.append(" \n]"); + return result.toString(); + } + + /** + * hashCode returns the hash code value as an integer and is + * supported for the benefit of hashing based collection classes such as + * Hashtable, HashMap, HashSet etc. + * + * @return the hashcode for this instance of Matrix4f. + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + int hash = 37; + hash = 37 * hash + Float.floatToIntBits(m00); + hash = 37 * hash + Float.floatToIntBits(m01); + hash = 37 * hash + Float.floatToIntBits(m02); + + hash = 37 * hash + Float.floatToIntBits(m10); + hash = 37 * hash + Float.floatToIntBits(m11); + hash = 37 * hash + Float.floatToIntBits(m12); + + hash = 37 * hash + Float.floatToIntBits(m20); + hash = 37 * hash + Float.floatToIntBits(m21); + hash = 37 * hash + Float.floatToIntBits(m22); + + return hash; + } + + /** + * are these two matrices the same? they are is they both have the same mXX + * values. + * + * @param o the object to compare for equality + * @return true if they are equal + */ + @Override + public boolean equals(Object o) { + if (!(o instanceof Matrix3f) || o == null) { + return false; + } + + if (this == o) { + return true; + } + + Matrix3f comp = (Matrix3f) o; + if (Float.compare(m00, comp.m00) != 0) + return false; + if (Float.compare(m01, comp.m01) != 0) + return false; + if (Float.compare(m02, comp.m02) != 0) + return false; + + if (Float.compare(m10, comp.m10) != 0) + return false; + if (Float.compare(m11, comp.m11) != 0) + return false; + if (Float.compare(m12, comp.m12) != 0) + return false; + + if (Float.compare(m20, comp.m20) != 0) + return false; + if (Float.compare(m21, comp.m21) != 0) + return false; + return Float.compare(m22, comp.m22) == 0; + } + + /** + * A function for creating a rotation matrix that rotates a vector called + * "start" into another vector called "end". + * + * @param start normalized non-zero starting vector + * @param end normalized non-zero ending vector + * @throws Exception + * @see "Tomas Miller, John Hughes \"Efficiently Building a Matrix to Rotate + * \ One Vector to Another\" Journal of Graphics Tools, 4(4):1-4, 1999" + */ + public void fromStartEndVectors(Vector3f start, Vector3f end) + throws Exception { + Vector3f v = new Vector3f(); + float e, h, f; + + start.cross(end, v); + e = start.dot(end); + f = (e < 0) ? -e : e; + + // if "from" and "to" vectors are nearly parallel + if (f > 1.0f - FastMath.ZERO_TOLERANCE) { + Vector3f u = new Vector3f(); + Vector3f x = new Vector3f(); + float c1, c2, c3; /* coefficients for later use */ + int i, j; + + x.x = (start.x > 0.0) ? start.x : -start.x; + x.y = (start.y > 0.0) ? start.y : -start.y; + x.z = (start.z > 0.0) ? start.z : -start.z; + + if (x.x < x.y) { + if (x.x < x.z) { + x.x = 1.0f; + x.y = x.z = 0.0f; + } else { + x.z = 1.0f; + x.x = x.y = 0.0f; + } + } else { + if (x.y < x.z) { + x.y = 1.0f; + x.x = x.z = 0.0f; + } else { + x.z = 1.0f; + x.x = x.y = 0.0f; + } + } + + u.x = x.x - start.x; + u.y = x.y - start.y; + u.z = x.z - start.z; + v.x = x.x - end.x; + v.y = x.y - end.y; + v.z = x.z - end.z; + + c1 = 2.0f / u.dot(u); + c2 = 2.0f / v.dot(v); + c3 = c1 * c2 * u.dot(v); + + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + float val = -c1 * u.get(i) * u.get(j) - c2 * v.get(i) + * v.get(j) + c3 * v.get(i) * u.get(j); + set(i, j, val); + } + float val = get(i, i); + set(i, i, val + 1.0f); + } + } else { + // the most common case, unless "start"="end", or "start"=-"end" + float hvx, hvz, hvxy, hvxz, hvyz; + h = 1.0f / (1.0f + e); + hvx = h * v.x; + hvz = h * v.z; + hvxy = hvx * v.y; + hvxz = hvx * v.z; + hvyz = hvz * v.y; + set(0, 0, e + hvx * v.x); + set(0, 1, hvxy - v.z); + set(0, 2, hvxz + v.y); + + set(1, 0, hvxy + v.z); + set(1, 1, e + h * v.y * v.y); + set(1, 2, hvyz - v.x); + + set(2, 0, hvxz - v.y); + set(2, 1, hvyz + v.x); + set(2, 2, e + hvz * v.z); + } + } + + /** + * scale scales the operation performed by this matrix on a + * per-component basis. + * + * @param scale The scale applied to each of the X, Y and Z output values. + */ + public void scale(Vector3f scale) { + m00 *= scale.x; + m10 *= scale.x; + m20 *= scale.x; + m01 *= scale.y; + m11 *= scale.y; + m21 *= scale.y; + m02 *= scale.z; + m12 *= scale.z; + m22 *= scale.z; + } + + @Override + public Matrix3f clone() { + try { + return (Matrix3f) super.clone(); + } catch (CloneNotSupportedException e) { + Logger.error(e); + throw new AssertionError(); // can not happen + } + } } \ No newline at end of file diff --git a/src/engine/math/Matrix4f.java b/src/engine/math/Matrix4f.java index e0b18b00..197d2b09 100644 --- a/src/engine/math/Matrix4f.java +++ b/src/engine/math/Matrix4f.java @@ -18,1774 +18,1693 @@ import java.nio.FloatBuffer; * This matrix is intended for use in a translation and rotational capacity. It * provides convenience methods for creating the matrix from a multitude of * sources. - * + *

* Matrices are stored assuming column vectors on the right, with the * translation in the rightmost column. Element numbering is row,column, so m03 * is the zeroth row, third column, which is the "x" translation part. This * means that the implicit storage order is column major. However, the get() and * set() functions on float arrays default to row major order! - * */ -public class Matrix4f{ - - public float m00, m01, m02, m03; - - public float m10, m11, m12, m13; - - public float m20, m21, m22, m23; - - public float m30, m31, m32, m33; - - /** - * Constructor instantiates a new Matrix that is set to the - * identity matrix. - * - */ - public Matrix4f() { - loadIdentity(); - } - - /** - * constructs a matrix with the given values. - */ - public Matrix4f(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, - float m22, float m23, float m30, float m31, float m32, float m33) { - - this.m00 = m00; - this.m01 = m01; - this.m02 = m02; - this.m03 = m03; - this.m10 = m10; - this.m11 = m11; - this.m12 = m12; - this.m13 = m13; - this.m20 = m20; - this.m21 = m21; - this.m22 = m22; - this.m23 = m23; - this.m30 = m30; - this.m31 = m31; - this.m32 = m32; - this.m33 = m33; - } - - /** - * Create a new Matrix4f, given data in column-major format. - * - * @param array - * An array of 16 floats in column-major format (translation in - * elements 12, 13 and 14). - * @throws Exception - */ - public Matrix4f(float[] array) throws Exception { - set(array, false); - } - - /** - * Constructor instantiates a new Matrix that is set to the - * provided matrix. This constructor copies a given Matrix. If the provided - * matrix is null, the constructor sets the matrix to the identity. - * - * @param mat - * the matrix to copy. - */ - public Matrix4f(Matrix4f mat) { - copy(mat); - } - - /** - * copy transfers the contents of a given matrix to this - * matrix. If a null matrix is supplied, this matrix is set to the identity - * matrix. - * - * @param matrix - * the matrix to copy. - */ - public void copy(Matrix4f matrix) { - if (null == matrix) { - loadIdentity(); - } else { - m00 = matrix.m00; - m01 = matrix.m01; - m02 = matrix.m02; - m03 = matrix.m03; - m10 = matrix.m10; - m11 = matrix.m11; - m12 = matrix.m12; - m13 = matrix.m13; - m20 = matrix.m20; - m21 = matrix.m21; - m22 = matrix.m22; - m23 = matrix.m23; - m30 = matrix.m30; - m31 = matrix.m31; - m32 = matrix.m32; - m33 = matrix.m33; - } - } - - /** - * get retrieves the values of this object into a float array - * in row-major order. - * - * @param matrix - * the matrix to set the values into. - * @throws Exception - */ - public void get(float[] matrix) throws Exception { - get(matrix, true); - } - - /** - * set retrieves the values of this object into a float array. - * - * @param matrix - * the matrix to set the values into. - * @param rowMajor - * whether the outgoing data is in row or column major order. - * @throws Exception - */ - public void get(float[] matrix, boolean rowMajor) throws Exception { - if (matrix.length != 16) - throw new Exception("Array must be of size 16."); - - if (rowMajor) { - matrix[0] = m00; - matrix[1] = m01; - matrix[2] = m02; - matrix[3] = m03; - matrix[4] = m10; - matrix[5] = m11; - matrix[6] = m12; - matrix[7] = m13; - matrix[8] = m20; - matrix[9] = m21; - matrix[10] = m22; - matrix[11] = m23; - matrix[12] = m30; - matrix[13] = m31; - matrix[14] = m32; - matrix[15] = m33; - } else { - matrix[0] = m00; - matrix[4] = m01; - matrix[8] = m02; - matrix[12] = m03; - matrix[1] = m10; - matrix[5] = m11; - matrix[9] = m12; - matrix[13] = m13; - matrix[2] = m20; - matrix[6] = m21; - matrix[10] = m22; - matrix[14] = m23; - matrix[3] = m30; - matrix[7] = m31; - matrix[11] = m32; - matrix[15] = m33; - } - } - - /** - * get retrieves a value from the matrix at the given position. - * If the position is invalid a Exception is thrown. - * - * @param i - * the row index. - * @param j - * the column index. - * @return the value at (i, j). - * @throws Exception - */ - public float get(int i, int j) throws Exception { - switch (i) { - case 0: - switch (j) { - case 0: - return m00; - case 1: - return m01; - case 2: - return m02; - case 3: - return m03; - } - case 1: - switch (j) { - case 0: - return m10; - case 1: - return m11; - case 2: - return m12; - case 3: - return m13; - } - case 2: - switch (j) { - case 0: - return m20; - case 1: - return m21; - case 2: - return m22; - case 3: - return m23; - } - case 3: - switch (j) { - case 0: - return m30; - case 1: - return m31; - case 2: - return m32; - case 3: - return m33; - } - } - - throw new Exception("Invalid indices into matrix."); - } - - /** - * getColumn returns one of three columns specified by the - * parameter. This column is returned as a float array of length 4. - * - * @param i - * the column to retrieve. Must be between 0 and 3. - * @return the column specified by the index. - * @throws Exception - */ - public float[] getColumn(int i) throws Exception { - return getColumn(i, null); - } - - /** - * getColumn returns one of three columns specified by the - * parameter. This column is returned as a float[4]. - * - * @param i - * the column to retrieve. Must be between 0 and 3. - * @param store - * the float array to store the result in. if null, a new one is - * created. - * @return the column specified by the index. - */ - public float[] getColumn(int i, float[] store) throws Exception { - if (store == null) - store = new float[4]; - switch (i) { - case 0: - store[0] = m00; - store[1] = m10; - store[2] = m20; - store[3] = m30; - break; - case 1: - store[0] = m01; - store[1] = m11; - store[2] = m21; - store[3] = m31; - break; - case 2: - store[0] = m02; - store[1] = m12; - store[2] = m22; - store[3] = m32; - break; - case 3: - store[0] = m03; - store[1] = m13; - store[2] = m23; - store[3] = m33; - break; - default: - throw new Exception("Invalid column index. " + i); - } - return store; - } - - /** - * - * setColumn sets a particular column of this matrix to that - * represented by the provided vector. - * - * @param i - * the column to set. - * @param column - * the data to set. - */ - public void setColumn(int i, float[] column) throws Exception { - - if (column == null) { - return; - } - switch (i) { - case 0: - m00 = column[0]; - m10 = column[1]; - m20 = column[2]; - m30 = column[3]; - break; - case 1: - m01 = column[0]; - m11 = column[1]; - m21 = column[2]; - m31 = column[3]; - break; - case 2: - m02 = column[0]; - m12 = column[1]; - m22 = column[2]; - m32 = column[3]; - break; - case 3: - m03 = column[0]; - m13 = column[1]; - m23 = column[2]; - m33 = column[3]; - break; - default: - throw new Exception("Invalid column index. " + i); - } - } - - /** - * set places a given value into the matrix at the given - * position. If the position is invalid a Exception is thrown. - * - * @param i - * the row index. - * @param j - * the column index. - * @param value - * the value for (i, j). - */ - public void set(int i, int j, float value) throws Exception { - switch (i) { - case 0: - switch (j) { - case 0: - m00 = value; - return; - case 1: - m01 = value; - return; - case 2: - m02 = value; - return; - case 3: - m03 = value; - return; - } - case 1: - switch (j) { - case 0: - m10 = value; - return; - case 1: - m11 = value; - return; - case 2: - m12 = value; - return; - case 3: - m13 = value; - return; - } - case 2: - switch (j) { - case 0: - m20 = value; - return; - case 1: - m21 = value; - return; - case 2: - m22 = value; - return; - case 3: - m23 = value; - return; - } - case 3: - switch (j) { - case 0: - m30 = value; - return; - case 1: - m31 = value; - return; - case 2: - m32 = value; - return; - case 3: - m33 = value; - return; - } - } - throw new Exception("Invalid indices into matrix."); - } - - /** - * set sets the values of this matrix from an array of values. - * - * @param matrix - * the matrix to set the value to. - * @throws Exception - * if the array is not of size 16. - */ - public void set(float[][] matrix) throws Exception { - if (matrix.length != 4 || matrix[0].length != 4) { - throw new Exception("Array must be of size 16."); - } - - m00 = matrix[0][0]; - m01 = matrix[0][1]; - m02 = matrix[0][2]; - m03 = matrix[0][3]; - m10 = matrix[1][0]; - m11 = matrix[1][1]; - m12 = matrix[1][2]; - m13 = matrix[1][3]; - m20 = matrix[2][0]; - m21 = matrix[2][1]; - m22 = matrix[2][2]; - m23 = matrix[2][3]; - m30 = matrix[3][0]; - m31 = matrix[3][1]; - m32 = matrix[3][2]; - m33 = matrix[3][3]; - } - - /** - * set sets the values of this matrix from another matrix. - * - * @param matrix - * the matrix to read the value from. - */ - public Matrix4f set(Matrix4f matrix) { - m00 = matrix.m00; - m01 = matrix.m01; - m02 = matrix.m02; - m03 = matrix.m03; - m10 = matrix.m10; - m11 = matrix.m11; - m12 = matrix.m12; - m13 = matrix.m13; - m20 = matrix.m20; - m21 = matrix.m21; - m22 = matrix.m22; - m23 = matrix.m23; - m30 = matrix.m30; - m31 = matrix.m31; - m32 = matrix.m32; - m33 = matrix.m33; - return this; - } - - /** - * set sets the values of this matrix from an array of values - * assuming that the data is rowMajor order; - * - * @param matrix - * the matrix to set the value to. - * @throws Exception - */ - public void set(float[] matrix) throws Exception { - set(matrix, true); - } - - /** - * set sets the values of this matrix from an array of values; - * - * @param matrix - * the matrix to set the value to. - * @param rowMajor - * whether the incoming data is in row or column major order. - * @throws Exception - */ - public void set(float[] matrix, boolean rowMajor) throws Exception { - if (matrix.length != 16) - throw new Exception("Array must be of size 16."); - - if (rowMajor) { - m00 = matrix[0]; - m01 = matrix[1]; - m02 = matrix[2]; - m03 = matrix[3]; - m10 = matrix[4]; - m11 = matrix[5]; - m12 = matrix[6]; - m13 = matrix[7]; - m20 = matrix[8]; - m21 = matrix[9]; - m22 = matrix[10]; - m23 = matrix[11]; - m30 = matrix[12]; - m31 = matrix[13]; - m32 = matrix[14]; - m33 = matrix[15]; - } else { - m00 = matrix[0]; - m01 = matrix[4]; - m02 = matrix[8]; - m03 = matrix[12]; - m10 = matrix[1]; - m11 = matrix[5]; - m12 = matrix[9]; - m13 = matrix[13]; - m20 = matrix[2]; - m21 = matrix[6]; - m22 = matrix[10]; - m23 = matrix[14]; - m30 = matrix[3]; - m31 = matrix[7]; - m32 = matrix[11]; - m33 = matrix[15]; - } - } - - public Matrix4f transpose() throws Exception { - float[] tmp = new float[16]; - get(tmp, true); +public class Matrix4f { + + public float m00, m01, m02, m03; + + public float m10, m11, m12, m13; + + public float m20, m21, m22, m23; + + public float m30, m31, m32, m33; + + /** + * Constructor instantiates a new Matrix that is set to the + * identity matrix. + */ + public Matrix4f() { + loadIdentity(); + } + + /** + * constructs a matrix with the given values. + */ + public Matrix4f(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, + float m22, float m23, float m30, float m31, float m32, float m33) { + + this.m00 = m00; + this.m01 = m01; + this.m02 = m02; + this.m03 = m03; + this.m10 = m10; + this.m11 = m11; + this.m12 = m12; + this.m13 = m13; + this.m20 = m20; + this.m21 = m21; + this.m22 = m22; + this.m23 = m23; + this.m30 = m30; + this.m31 = m31; + this.m32 = m32; + this.m33 = m33; + } + + /** + * Create a new Matrix4f, given data in column-major format. + * + * @param array An array of 16 floats in column-major format (translation in + * elements 12, 13 and 14). + * @throws Exception + */ + public Matrix4f(float[] array) throws Exception { + set(array, false); + } + + /** + * Constructor instantiates a new Matrix that is set to the + * provided matrix. This constructor copies a given Matrix. If the provided + * matrix is null, the constructor sets the matrix to the identity. + * + * @param mat the matrix to copy. + */ + public Matrix4f(Matrix4f mat) { + copy(mat); + } + + static boolean equalIdentity(Matrix4f mat) { + if (Math.abs(mat.m00 - 1) > 1e-4) + return false; + if (Math.abs(mat.m11 - 1) > 1e-4) + return false; + if (Math.abs(mat.m22 - 1) > 1e-4) + return false; + if (Math.abs(mat.m33 - 1) > 1e-4) + return false; + + if (Math.abs(mat.m01) > 1e-4) + return false; + if (Math.abs(mat.m02) > 1e-4) + return false; + if (Math.abs(mat.m03) > 1e-4) + return false; + + if (Math.abs(mat.m10) > 1e-4) + return false; + if (Math.abs(mat.m12) > 1e-4) + return false; + if (Math.abs(mat.m13) > 1e-4) + return false; + + if (Math.abs(mat.m20) > 1e-4) + return false; + if (Math.abs(mat.m21) > 1e-4) + return false; + if (Math.abs(mat.m23) > 1e-4) + return false; + + if (Math.abs(mat.m30) > 1e-4) + return false; + if (Math.abs(mat.m31) > 1e-4) + return false; + return !(Math.abs(mat.m32) > 1e-4); + } + + /** + * copy transfers the contents of a given matrix to this + * matrix. If a null matrix is supplied, this matrix is set to the identity + * matrix. + * + * @param matrix the matrix to copy. + */ + public void copy(Matrix4f matrix) { + if (null == matrix) { + loadIdentity(); + } else { + m00 = matrix.m00; + m01 = matrix.m01; + m02 = matrix.m02; + m03 = matrix.m03; + m10 = matrix.m10; + m11 = matrix.m11; + m12 = matrix.m12; + m13 = matrix.m13; + m20 = matrix.m20; + m21 = matrix.m21; + m22 = matrix.m22; + m23 = matrix.m23; + m30 = matrix.m30; + m31 = matrix.m31; + m32 = matrix.m32; + m33 = matrix.m33; + } + } + + /** + * get retrieves the values of this object into a float array + * in row-major order. + * + * @param matrix the matrix to set the values into. + * @throws Exception + */ + public void get(float[] matrix) throws Exception { + get(matrix, true); + } + + /** + * set retrieves the values of this object into a float array. + * + * @param matrix the matrix to set the values into. + * @param rowMajor whether the outgoing data is in row or column major order. + * @throws Exception + */ + public void get(float[] matrix, boolean rowMajor) throws Exception { + if (matrix.length != 16) + throw new Exception("Array must be of size 16."); + + if (rowMajor) { + matrix[0] = m00; + matrix[1] = m01; + matrix[2] = m02; + matrix[3] = m03; + matrix[4] = m10; + matrix[5] = m11; + matrix[6] = m12; + matrix[7] = m13; + matrix[8] = m20; + matrix[9] = m21; + matrix[10] = m22; + matrix[11] = m23; + matrix[12] = m30; + matrix[13] = m31; + matrix[14] = m32; + matrix[15] = m33; + } else { + matrix[0] = m00; + matrix[4] = m01; + matrix[8] = m02; + matrix[12] = m03; + matrix[1] = m10; + matrix[5] = m11; + matrix[9] = m12; + matrix[13] = m13; + matrix[2] = m20; + matrix[6] = m21; + matrix[10] = m22; + matrix[14] = m23; + matrix[3] = m30; + matrix[7] = m31; + matrix[11] = m32; + matrix[15] = m33; + } + } + + /** + * get retrieves a value from the matrix at the given position. + * If the position is invalid a Exception is thrown. + * + * @param i the row index. + * @param j the column index. + * @return the value at (i, j). + * @throws Exception + */ + public float get(int i, int j) throws Exception { + switch (i) { + case 0: + switch (j) { + case 0: + return m00; + case 1: + return m01; + case 2: + return m02; + case 3: + return m03; + } + case 1: + switch (j) { + case 0: + return m10; + case 1: + return m11; + case 2: + return m12; + case 3: + return m13; + } + case 2: + switch (j) { + case 0: + return m20; + case 1: + return m21; + case 2: + return m22; + case 3: + return m23; + } + case 3: + switch (j) { + case 0: + return m30; + case 1: + return m31; + case 2: + return m32; + case 3: + return m33; + } + } + + throw new Exception("Invalid indices into matrix."); + } + + /** + * getColumn returns one of three columns specified by the + * parameter. This column is returned as a float array of length 4. + * + * @param i the column to retrieve. Must be between 0 and 3. + * @return the column specified by the index. + * @throws Exception + */ + public float[] getColumn(int i) throws Exception { + return getColumn(i, null); + } + + /** + * getColumn returns one of three columns specified by the + * parameter. This column is returned as a float[4]. + * + * @param i the column to retrieve. Must be between 0 and 3. + * @param store the float array to store the result in. if null, a new one is + * created. + * @return the column specified by the index. + */ + public float[] getColumn(int i, float[] store) throws Exception { + if (store == null) + store = new float[4]; + switch (i) { + case 0: + store[0] = m00; + store[1] = m10; + store[2] = m20; + store[3] = m30; + break; + case 1: + store[0] = m01; + store[1] = m11; + store[2] = m21; + store[3] = m31; + break; + case 2: + store[0] = m02; + store[1] = m12; + store[2] = m22; + store[3] = m32; + break; + case 3: + store[0] = m03; + store[1] = m13; + store[2] = m23; + store[3] = m33; + break; + default: + throw new Exception("Invalid column index. " + i); + } + return store; + } + + /** + * setColumn sets a particular column of this matrix to that + * represented by the provided vector. + * + * @param i the column to set. + * @param column the data to set. + */ + public void setColumn(int i, float[] column) throws Exception { + + if (column == null) { + return; + } + switch (i) { + case 0: + m00 = column[0]; + m10 = column[1]; + m20 = column[2]; + m30 = column[3]; + break; + case 1: + m01 = column[0]; + m11 = column[1]; + m21 = column[2]; + m31 = column[3]; + break; + case 2: + m02 = column[0]; + m12 = column[1]; + m22 = column[2]; + m32 = column[3]; + break; + case 3: + m03 = column[0]; + m13 = column[1]; + m23 = column[2]; + m33 = column[3]; + break; + default: + throw new Exception("Invalid column index. " + i); + } + } + + /** + * set places a given value into the matrix at the given + * position. If the position is invalid a Exception is thrown. + * + * @param i the row index. + * @param j the column index. + * @param value the value for (i, j). + */ + public void set(int i, int j, float value) throws Exception { + switch (i) { + case 0: + switch (j) { + case 0: + m00 = value; + return; + case 1: + m01 = value; + return; + case 2: + m02 = value; + return; + case 3: + m03 = value; + return; + } + case 1: + switch (j) { + case 0: + m10 = value; + return; + case 1: + m11 = value; + return; + case 2: + m12 = value; + return; + case 3: + m13 = value; + return; + } + case 2: + switch (j) { + case 0: + m20 = value; + return; + case 1: + m21 = value; + return; + case 2: + m22 = value; + return; + case 3: + m23 = value; + return; + } + case 3: + switch (j) { + case 0: + m30 = value; + return; + case 1: + m31 = value; + return; + case 2: + m32 = value; + return; + case 3: + m33 = value; + return; + } + } + throw new Exception("Invalid indices into matrix."); + } + + /** + * set sets the values of this matrix from an array of values. + * + * @param matrix the matrix to set the value to. + * @throws Exception if the array is not of size 16. + */ + public void set(float[][] matrix) throws Exception { + if (matrix.length != 4 || matrix[0].length != 4) { + throw new Exception("Array must be of size 16."); + } + + m00 = matrix[0][0]; + m01 = matrix[0][1]; + m02 = matrix[0][2]; + m03 = matrix[0][3]; + m10 = matrix[1][0]; + m11 = matrix[1][1]; + m12 = matrix[1][2]; + m13 = matrix[1][3]; + m20 = matrix[2][0]; + m21 = matrix[2][1]; + m22 = matrix[2][2]; + m23 = matrix[2][3]; + m30 = matrix[3][0]; + m31 = matrix[3][1]; + m32 = matrix[3][2]; + m33 = matrix[3][3]; + } + + /** + * set sets the values of this matrix from another matrix. + * + * @param matrix the matrix to read the value from. + */ + public Matrix4f set(Matrix4f matrix) { + m00 = matrix.m00; + m01 = matrix.m01; + m02 = matrix.m02; + m03 = matrix.m03; + m10 = matrix.m10; + m11 = matrix.m11; + m12 = matrix.m12; + m13 = matrix.m13; + m20 = matrix.m20; + m21 = matrix.m21; + m22 = matrix.m22; + m23 = matrix.m23; + m30 = matrix.m30; + m31 = matrix.m31; + m32 = matrix.m32; + m33 = matrix.m33; + return this; + } + + /** + * set sets the values of this matrix from an array of values + * assuming that the data is rowMajor order; + * + * @param matrix the matrix to set the value to. + * @throws Exception + */ + public void set(float[] matrix) throws Exception { + set(matrix, true); + } + + /** + * set sets the values of this matrix from an array of values; + * + * @param matrix the matrix to set the value to. + * @param rowMajor whether the incoming data is in row or column major order. + * @throws Exception + */ + public void set(float[] matrix, boolean rowMajor) throws Exception { + if (matrix.length != 16) + throw new Exception("Array must be of size 16."); + + if (rowMajor) { + m00 = matrix[0]; + m01 = matrix[1]; + m02 = matrix[2]; + m03 = matrix[3]; + m10 = matrix[4]; + m11 = matrix[5]; + m12 = matrix[6]; + m13 = matrix[7]; + m20 = matrix[8]; + m21 = matrix[9]; + m22 = matrix[10]; + m23 = matrix[11]; + m30 = matrix[12]; + m31 = matrix[13]; + m32 = matrix[14]; + m33 = matrix[15]; + } else { + m00 = matrix[0]; + m01 = matrix[4]; + m02 = matrix[8]; + m03 = matrix[12]; + m10 = matrix[1]; + m11 = matrix[5]; + m12 = matrix[9]; + m13 = matrix[13]; + m20 = matrix[2]; + m21 = matrix[6]; + m22 = matrix[10]; + m23 = matrix[14]; + m30 = matrix[3]; + m31 = matrix[7]; + m32 = matrix[11]; + m33 = matrix[15]; + } + } + + public Matrix4f transpose() throws Exception { + float[] tmp = new float[16]; + get(tmp, true); return new Matrix4f(tmp); - } - - /** - * transpose locally transposes this Matrix. - * - * @return this object for chaining. - */ - public Matrix4f transposeLocal() { - float tmp = m01; - m01 = m10; - m10 = tmp; - - tmp = m02; - m02 = m20; - m20 = tmp; - - tmp = m03; - m03 = m30; - m30 = tmp; - - tmp = m12; - m12 = m21; - m21 = tmp; - - tmp = m13; - m13 = m31; - m31 = tmp; - - tmp = m23; - m23 = m32; - m32 = tmp; - - return this; - } - - /** - * fillFloatBuffer fills a FloatBuffer object with the matrix - * data. - * - * @param fb - * the buffer to fill, must be correct size - * @return matrix data as a FloatBuffer. - */ - public FloatBuffer fillFloatBuffer(FloatBuffer fb) { - return fillFloatBuffer(fb, false); - } - - /** - * fillFloatBuffer fills a FloatBuffer object with the matrix - * data. - * - * @param fb - * the buffer to fill, starting at current position. Must have - * room for 16 more floats. - * @param columnMajor - * if true, this buffer should be filled with column major data, - * otherwise it will be filled row major. - * @return matrix data as a FloatBuffer. (position is advanced by 16 and any - * limit set is not changed). - */ - public FloatBuffer fillFloatBuffer(FloatBuffer fb, boolean columnMajor) { - if (columnMajor) { - fb.put(m00).put(m10).put(m20).put(m30); - fb.put(m01).put(m11).put(m21).put(m31); - fb.put(m02).put(m12).put(m22).put(m32); - fb.put(m03).put(m13).put(m23).put(m33); - } else { - fb.put(m00).put(m01).put(m02).put(m03); - fb.put(m10).put(m11).put(m12).put(m13); - fb.put(m20).put(m21).put(m22).put(m23); - fb.put(m30).put(m31).put(m32).put(m33); - } - return fb; - } - - /** - * readFloatBuffer reads value for this matrix from a - * FloatBuffer. - * - * @param fb - * the buffer to read from, must be correct size - * @return this data as a FloatBuffer. - */ - public Matrix4f readFloatBuffer(FloatBuffer fb) { - return readFloatBuffer(fb, false); - } - - /** - * readFloatBuffer reads value for this matrix from a - * FloatBuffer. - * - * @param fb - * the buffer to read from, must be correct size - * @param columnMajor - * if true, this buffer should be filled with column major data, - * otherwise it will be filled row major. - * @return this data as a FloatBuffer. - */ - public Matrix4f readFloatBuffer(FloatBuffer fb, boolean columnMajor) { - - if (columnMajor) { - m00 = fb.get(); - m10 = fb.get(); - m20 = fb.get(); - m30 = fb.get(); - m01 = fb.get(); - m11 = fb.get(); - m21 = fb.get(); - m31 = fb.get(); - m02 = fb.get(); - m12 = fb.get(); - m22 = fb.get(); - m32 = fb.get(); - m03 = fb.get(); - m13 = fb.get(); - m23 = fb.get(); - m33 = fb.get(); - } else { - m00 = fb.get(); - m01 = fb.get(); - m02 = fb.get(); - m03 = fb.get(); - m10 = fb.get(); - m11 = fb.get(); - m12 = fb.get(); - m13 = fb.get(); - m20 = fb.get(); - m21 = fb.get(); - m22 = fb.get(); - m23 = fb.get(); - m30 = fb.get(); - m31 = fb.get(); - m32 = fb.get(); - m33 = fb.get(); - } - return this; - } - - /** - * Legacy wrapper. This name implies that an identity matrix is "loaded", - * but one is not. Instead, the elements of 'this' identity are set. - */ - public void loadIdentity() { - setIdentity(); - } - - /** - * Sets this matrix to the identity matrix, namely all zeros with ones along - * the diagonal. - * - */ - public void setIdentity() { - m01 = m02 = m03 = m10 = m12 = m13 = m20 = m21 = m23 = m30 = m31 = m32 = 0.0f; - m00 = m11 = m22 = m33 = 1.0f; - } - - /** - * fromAngleAxis sets this matrix4f to the values specified by - * an angle and an axis of rotation. This method creates an object, so use - * fromAngleNormalAxis if your axis is already normalized. - * - * @param angle - * the angle to rotate (in radians). - * @param axis - * the axis of rotation. - */ - public void fromAngleAxis(float angle, Vector3f axis) { - Vector3f normAxis = axis.normalize(); - fromAngleNormalAxis(angle, normAxis); - } - - /** - * fromAngleNormalAxis sets this matrix4f to the values - * specified by an angle and a normalized axis of rotation. - * - * @param angle - * the angle to rotate (in radians). - * @param axis - * the axis of rotation (already normalized). - */ - public void fromAngleNormalAxis(float angle, Vector3f axis) { - zero(); - m33 = 1; - - float fCos = FastMath.cos(angle); - float fSin = FastMath.sin(angle); - float fOneMinusCos = ((float) 1.0) - fCos; - float fX2 = axis.x * axis.x; - float fY2 = axis.y * axis.y; - float fZ2 = axis.z * axis.z; - float fXYM = axis.x * axis.y * fOneMinusCos; - float fXZM = axis.x * axis.z * fOneMinusCos; - float fYZM = axis.y * axis.z * fOneMinusCos; - float fXSin = axis.x * fSin; - float fYSin = axis.y * fSin; - float fZSin = axis.z * fSin; - - m00 = fX2 * fOneMinusCos + fCos; - m01 = fXYM - fZSin; - m02 = fXZM + fYSin; - m10 = fXYM + fZSin; - m11 = fY2 * fOneMinusCos + fCos; - m12 = fYZM - fXSin; - m20 = fXZM - fYSin; - m21 = fYZM + fXSin; - m22 = fZ2 * fOneMinusCos + fCos; - } - - /** - * mult multiplies this matrix by a scalar. - * - * @param scalar - * the scalar to multiply this matrix by. - */ - public void multLocal(float scalar) { - m00 *= scalar; - m01 *= scalar; - m02 *= scalar; - m03 *= scalar; - m10 *= scalar; - m11 *= scalar; - m12 *= scalar; - m13 *= scalar; - m20 *= scalar; - m21 *= scalar; - m22 *= scalar; - m23 *= scalar; - m30 *= scalar; - m31 *= scalar; - m32 *= scalar; - m33 *= scalar; - } - - public Matrix4f mult(float scalar) { - Matrix4f out = new Matrix4f(); - out.set(this); - out.multLocal(scalar); - return out; - } - - public Matrix4f mult(float scalar, Matrix4f store) { - store.set(this); - store.multLocal(scalar); - return store; - } - - /** - * mult multiplies this matrix with another matrix. The result - * matrix will then be returned. This matrix will be on the left hand side, - * while the parameter matrix will be on the right. - * - * @param in2 - * the matrix to multiply this matrix by. - * @return the resultant matrix - */ - public Matrix4f mult(Matrix4f in2) { - return mult(in2, null); - } - - /** - * mult multiplies this matrix with another matrix. The result - * matrix will then be returned. This matrix will be on the left hand side, - * while the parameter matrix will be on the right. - * - * @param in2 - * the matrix to multiply this matrix by. - * @param store - * where to store the result. It is safe for in2 and store to be - * the same object. - * @return the resultant matrix - */ - public Matrix4f mult(Matrix4f in2, Matrix4f store) { - if (store == null) - store = new Matrix4f(); - - float temp00, temp01, temp02, temp03; - float temp10, temp11, temp12, temp13; - float temp20, temp21, temp22, temp23; - float temp30, temp31, temp32, temp33; - - temp00 = m00 * in2.m00 + m01 * in2.m10 + m02 * in2.m20 + m03 * in2.m30; - temp01 = m00 * in2.m01 + m01 * in2.m11 + m02 * in2.m21 + m03 * in2.m31; - temp02 = m00 * in2.m02 + m01 * in2.m12 + m02 * in2.m22 + m03 * in2.m32; - temp03 = m00 * in2.m03 + m01 * in2.m13 + m02 * in2.m23 + m03 * in2.m33; - - temp10 = m10 * in2.m00 + m11 * in2.m10 + m12 * in2.m20 + m13 * in2.m30; - temp11 = m10 * in2.m01 + m11 * in2.m11 + m12 * in2.m21 + m13 * in2.m31; - temp12 = m10 * in2.m02 + m11 * in2.m12 + m12 * in2.m22 + m13 * in2.m32; - temp13 = m10 * in2.m03 + m11 * in2.m13 + m12 * in2.m23 + m13 * in2.m33; - - temp20 = m20 * in2.m00 + m21 * in2.m10 + m22 * in2.m20 + m23 * in2.m30; - temp21 = m20 * in2.m01 + m21 * in2.m11 + m22 * in2.m21 + m23 * in2.m31; - temp22 = m20 * in2.m02 + m21 * in2.m12 + m22 * in2.m22 + m23 * in2.m32; - temp23 = m20 * in2.m03 + m21 * in2.m13 + m22 * in2.m23 + m23 * in2.m33; - - temp30 = m30 * in2.m00 + m31 * in2.m10 + m32 * in2.m20 + m33 * in2.m30; - temp31 = m30 * in2.m01 + m31 * in2.m11 + m32 * in2.m21 + m33 * in2.m31; - temp32 = m30 * in2.m02 + m31 * in2.m12 + m32 * in2.m22 + m33 * in2.m32; - temp33 = m30 * in2.m03 + m31 * in2.m13 + m32 * in2.m23 + m33 * in2.m33; - - store.m00 = temp00; - store.m01 = temp01; - store.m02 = temp02; - store.m03 = temp03; - store.m10 = temp10; - store.m11 = temp11; - store.m12 = temp12; - store.m13 = temp13; - store.m20 = temp20; - store.m21 = temp21; - store.m22 = temp22; - store.m23 = temp23; - store.m30 = temp30; - store.m31 = temp31; - store.m32 = temp32; - store.m33 = temp33; - - return store; - } - - /** - * mult multiplies this matrix with another matrix. The results - * are stored internally and a handle to this matrix will then be returned. - * This matrix will be on the left hand side, while the parameter matrix - * will be on the right. - * - * @param in2 - * the matrix to multiply this matrix by. - * @return the resultant matrix - */ - public Matrix4f multLocal(Matrix4f in2) { - - return mult(in2, this); - } - - /** - * mult multiplies a vector about a rotation matrix. The - * resulting vector is returned as a new Vector3f. - * - * @param vec - * vec to multiply against. - * @return the rotated vector. - */ - public Vector3f mult(Vector3f vec) { - return mult(vec, null); - } - - /** - * mult multiplies a vector about a rotation matrix and adds - * translation. The resulting vector is returned. - * - * @param vec - * vec to multiply against. - * @param store - * a vector to store the result in. Created if null is passed. - * @return the rotated vector. - */ - public Vector3f mult(Vector3f vec, Vector3f store) { - if (store == null) - store = new Vector3f(); - - float vx = vec.x, vy = vec.y, vz = vec.z; - store.x = m00 * vx + m01 * vy + m02 * vz + m03; - store.y = m10 * vx + m11 * vy + m12 * vz + m13; - store.z = m20 * vx + m21 * vy + m22 * vz + m23; - - return store; - } - - /** - * mult multiplies a vector about a rotation matrix. The - * resulting vector is returned. - * - * @param vec - * vec to multiply against. - * @param store - * a vector to store the result in. created if null is passed. - * @return the rotated vector. - */ - public Vector3f multAcross(Vector3f vec, Vector3f store) { - if (null == vec) { - return null; - } - if (store == null) - store = new Vector3f(); - - float vx = vec.x, vy = vec.y, vz = vec.z; - store.x = m00 * vx + m10 * vy + m20 * vz + m30 * 1; - store.y = m01 * vx + m11 * vy + m21 * vz + m31 * 1; - store.z = m02 * vx + m12 * vy + m22 * vz + m32 * 1; - - return store; - } - - /** - * mult multiplies a quaternion about a matrix. The resulting - * vector is returned. - * - * @param vec - * vec to multiply against. - * @param store - * a quaternion to store the result in. created if null is - * passed. - * @return store = this * vec - */ - public Quaternion mult(Quaternion vec, Quaternion store) { - - if (null == vec) { - return null; - } - if (store == null) - store = new Quaternion(); - - float x = m00 * vec.x + m10 * vec.y + m20 * vec.z + m30 * vec.w; - float y = m01 * vec.x + m11 * vec.y + m21 * vec.z + m31 * vec.w; - float z = m02 * vec.x + m12 * vec.y + m22 * vec.z + m32 * vec.w; - float w = m03 * vec.x + m13 * vec.y + m23 * vec.z + m33 * vec.w; - store.x = x; - store.y = y; - store.z = z; - store.w = w; - - return store; - } - - /** - * mult multiplies an array of 4 floats against this rotation - * matrix. The results are stored directly in the array. (vec4f x mat4f) - * - * @param vec4f - * float array (size 4) to multiply against the matrix. - * @return the vec4f for chaining. - */ - public float[] mult(float[] vec4f) { - if (null == vec4f || vec4f.length != 4) { - return null; - } - - float x = vec4f[0], y = vec4f[1], z = vec4f[2], w = vec4f[3]; - - vec4f[0] = m00 * x + m01 * y + m02 * z + m03 * w; - vec4f[1] = m10 * x + m11 * y + m12 * z + m13 * w; - vec4f[2] = m20 * x + m21 * y + m22 * z + m23 * w; - vec4f[3] = m30 * x + m31 * y + m32 * z + m33 * w; - - return vec4f; - } - - /** - * mult multiplies an array of 4 floats against this rotation - * matrix. The results are stored directly in the array. (vec4f x mat4f) - * - * @param vec4f - * float array (size 4) to multiply against the matrix. - * @return the vec4f for chaining. - */ - public float[] multAcross(float[] vec4f) { - if (null == vec4f || vec4f.length != 4) { - return null; - } - - float x = vec4f[0], y = vec4f[1], z = vec4f[2], w = vec4f[3]; - - vec4f[0] = m00 * x + m10 * y + m20 * z + m30 * w; - vec4f[1] = m01 * x + m11 * y + m21 * z + m31 * w; - vec4f[2] = m02 * x + m12 * y + m22 * z + m32 * w; - vec4f[3] = m03 * x + m13 * y + m23 * z + m33 * w; - - return vec4f; - } - - /** - * Inverts this matrix as a new Matrix4f. - * - * @return The new inverse matrix - */ - public Matrix4f invert() { - return invert(null); - } - - /** - * Inverts this matrix and stores it in the given store. - * - * @return The store - */ - public Matrix4f invert(Matrix4f store) { - if (store == null) - store = new Matrix4f(); - - float fA0 = m00 * m11 - m01 * m10; - float fA1 = m00 * m12 - m02 * m10; - float fA2 = m00 * m13 - m03 * m10; - float fA3 = m01 * m12 - m02 * m11; - float fA4 = m01 * m13 - m03 * m11; - float fA5 = m02 * m13 - m03 * m12; - float fB0 = m20 * m31 - m21 * m30; - float fB1 = m20 * m32 - m22 * m30; - float fB2 = m20 * m33 - m23 * m30; - float fB3 = m21 * m32 - m22 * m31; - float fB4 = m21 * m33 - m23 * m31; - float fB5 = m22 * m33 - m23 * m32; - float fDet = fA0 * fB5 - fA1 * fB4 + fA2 * fB3 + fA3 * fB2 - fA4 * fB1 + fA5 * fB0; - - if (FastMath.abs(fDet) <= 0) - return store.zero(); - - store.m00 = +m11 * fB5 - m12 * fB4 + m13 * fB3; - store.m10 = -m10 * fB5 + m12 * fB2 - m13 * fB1; - store.m20 = +m10 * fB4 - m11 * fB2 + m13 * fB0; - store.m30 = -m10 * fB3 + m11 * fB1 - m12 * fB0; - store.m01 = -m01 * fB5 + m02 * fB4 - m03 * fB3; - store.m11 = +m00 * fB5 - m02 * fB2 + m03 * fB1; - store.m21 = -m00 * fB4 + m01 * fB2 - m03 * fB0; - store.m31 = +m00 * fB3 - m01 * fB1 + m02 * fB0; - store.m02 = +m31 * fA5 - m32 * fA4 + m33 * fA3; - store.m12 = -m30 * fA5 + m32 * fA2 - m33 * fA1; - store.m22 = +m30 * fA4 - m31 * fA2 + m33 * fA0; - store.m32 = -m30 * fA3 + m31 * fA1 - m32 * fA0; - store.m03 = -m21 * fA5 + m22 * fA4 - m23 * fA3; - store.m13 = +m20 * fA5 - m22 * fA2 + m23 * fA1; - store.m23 = -m20 * fA4 + m21 * fA2 - m23 * fA0; - store.m33 = +m20 * fA3 - m21 * fA1 + m22 * fA0; - - float fInvDet = 1.0f / fDet; - store.multLocal(fInvDet); - - return store; - } - - /** - * Inverts this matrix locally. - * - * @return this - */ - public Matrix4f invertLocal() { - - float fA0 = m00 * m11 - m01 * m10; - float fA1 = m00 * m12 - m02 * m10; - float fA2 = m00 * m13 - m03 * m10; - float fA3 = m01 * m12 - m02 * m11; - float fA4 = m01 * m13 - m03 * m11; - float fA5 = m02 * m13 - m03 * m12; - float fB0 = m20 * m31 - m21 * m30; - float fB1 = m20 * m32 - m22 * m30; - float fB2 = m20 * m33 - m23 * m30; - float fB3 = m21 * m32 - m22 * m31; - float fB4 = m21 * m33 - m23 * m31; - float fB5 = m22 * m33 - m23 * m32; - float fDet = fA0 * fB5 - fA1 * fB4 + fA2 * fB3 + fA3 * fB2 - fA4 * fB1 + fA5 * fB0; - - if (FastMath.abs(fDet) <= FastMath.FLT_EPSILON) - return zero(); - - float f00 = +m11 * fB5 - m12 * fB4 + m13 * fB3; - float f10 = -m10 * fB5 + m12 * fB2 - m13 * fB1; - float f20 = +m10 * fB4 - m11 * fB2 + m13 * fB0; - float f30 = -m10 * fB3 + m11 * fB1 - m12 * fB0; - float f01 = -m01 * fB5 + m02 * fB4 - m03 * fB3; - float f11 = +m00 * fB5 - m02 * fB2 + m03 * fB1; - float f21 = -m00 * fB4 + m01 * fB2 - m03 * fB0; - float f31 = +m00 * fB3 - m01 * fB1 + m02 * fB0; - float f02 = +m31 * fA5 - m32 * fA4 + m33 * fA3; - float f12 = -m30 * fA5 + m32 * fA2 - m33 * fA1; - float f22 = +m30 * fA4 - m31 * fA2 + m33 * fA0; - float f32 = -m30 * fA3 + m31 * fA1 - m32 * fA0; - float f03 = -m21 * fA5 + m22 * fA4 - m23 * fA3; - float f13 = +m20 * fA5 - m22 * fA2 + m23 * fA1; - float f23 = -m20 * fA4 + m21 * fA2 - m23 * fA0; - float f33 = +m20 * fA3 - m21 * fA1 + m22 * fA0; - - m00 = f00; - m01 = f01; - m02 = f02; - m03 = f03; - m10 = f10; - m11 = f11; - m12 = f12; - m13 = f13; - m20 = f20; - m21 = f21; - m22 = f22; - m23 = f23; - m30 = f30; - m31 = f31; - m32 = f32; - m33 = f33; - - float fInvDet = 1.0f / fDet; - multLocal(fInvDet); - - return this; - } - - /** - * Returns a new matrix representing the adjoint of this matrix. - * - * @return The adjoint matrix - */ - public Matrix4f adjoint() { - return adjoint(null); - } - - /** - * Places the adjoint of this matrix in store (creates store if null.) - * - * @param store - * The matrix to store the result in. If null, a new matrix is - * created. - * @return store - */ - public Matrix4f adjoint(Matrix4f store) { - if (store == null) - store = new Matrix4f(); - - float fA0 = m00 * m11 - m01 * m10; - float fA1 = m00 * m12 - m02 * m10; - float fA2 = m00 * m13 - m03 * m10; - float fA3 = m01 * m12 - m02 * m11; - float fA4 = m01 * m13 - m03 * m11; - float fA5 = m02 * m13 - m03 * m12; - float fB0 = m20 * m31 - m21 * m30; - float fB1 = m20 * m32 - m22 * m30; - float fB2 = m20 * m33 - m23 * m30; - float fB3 = m21 * m32 - m22 * m31; - float fB4 = m21 * m33 - m23 * m31; - float fB5 = m22 * m33 - m23 * m32; - - store.m00 = +m11 * fB5 - m12 * fB4 + m13 * fB3; - store.m10 = -m10 * fB5 + m12 * fB2 - m13 * fB1; - store.m20 = +m10 * fB4 - m11 * fB2 + m13 * fB0; - store.m30 = -m10 * fB3 + m11 * fB1 - m12 * fB0; - store.m01 = -m01 * fB5 + m02 * fB4 - m03 * fB3; - store.m11 = +m00 * fB5 - m02 * fB2 + m03 * fB1; - store.m21 = -m00 * fB4 + m01 * fB2 - m03 * fB0; - store.m31 = +m00 * fB3 - m01 * fB1 + m02 * fB0; - store.m02 = +m31 * fA5 - m32 * fA4 + m33 * fA3; - store.m12 = -m30 * fA5 + m32 * fA2 - m33 * fA1; - store.m22 = +m30 * fA4 - m31 * fA2 + m33 * fA0; - store.m32 = -m30 * fA3 + m31 * fA1 - m32 * fA0; - store.m03 = -m21 * fA5 + m22 * fA4 - m23 * fA3; - store.m13 = +m20 * fA5 - m22 * fA2 + m23 * fA1; - store.m23 = -m20 * fA4 + m21 * fA2 - m23 * fA0; - store.m33 = +m20 * fA3 - m21 * fA1 + m22 * fA0; - - return store; - } - - /** - * determinant generates the determinate of this matrix. - * - * @return the determinate - */ - public float determinant() { - float fA0 = m00 * m11 - m01 * m10; - float fA1 = m00 * m12 - m02 * m10; - float fA2 = m00 * m13 - m03 * m10; - float fA3 = m01 * m12 - m02 * m11; - float fA4 = m01 * m13 - m03 * m11; - float fA5 = m02 * m13 - m03 * m12; - float fB0 = m20 * m31 - m21 * m30; - float fB1 = m20 * m32 - m22 * m30; - float fB2 = m20 * m33 - m23 * m30; - float fB3 = m21 * m32 - m22 * m31; - float fB4 = m21 * m33 - m23 * m31; - float fB5 = m22 * m33 - m23 * m32; + } + + /** + * transpose locally transposes this Matrix. + * + * @return this object for chaining. + */ + public Matrix4f transposeLocal() { + float tmp = m01; + m01 = m10; + m10 = tmp; + + tmp = m02; + m02 = m20; + m20 = tmp; + + tmp = m03; + m03 = m30; + m30 = tmp; + + tmp = m12; + m12 = m21; + m21 = tmp; + + tmp = m13; + m13 = m31; + m31 = tmp; + + tmp = m23; + m23 = m32; + m32 = tmp; + + return this; + } + + /** + * fillFloatBuffer fills a FloatBuffer object with the matrix + * data. + * + * @param fb the buffer to fill, must be correct size + * @return matrix data as a FloatBuffer. + */ + public FloatBuffer fillFloatBuffer(FloatBuffer fb) { + return fillFloatBuffer(fb, false); + } + + /** + * fillFloatBuffer fills a FloatBuffer object with the matrix + * data. + * + * @param fb the buffer to fill, starting at current position. Must have + * room for 16 more floats. + * @param columnMajor if true, this buffer should be filled with column major data, + * otherwise it will be filled row major. + * @return matrix data as a FloatBuffer. (position is advanced by 16 and any + * limit set is not changed). + */ + public FloatBuffer fillFloatBuffer(FloatBuffer fb, boolean columnMajor) { + if (columnMajor) { + fb.put(m00).put(m10).put(m20).put(m30); + fb.put(m01).put(m11).put(m21).put(m31); + fb.put(m02).put(m12).put(m22).put(m32); + fb.put(m03).put(m13).put(m23).put(m33); + } else { + fb.put(m00).put(m01).put(m02).put(m03); + fb.put(m10).put(m11).put(m12).put(m13); + fb.put(m20).put(m21).put(m22).put(m23); + fb.put(m30).put(m31).put(m32).put(m33); + } + return fb; + } + + /** + * readFloatBuffer reads value for this matrix from a + * FloatBuffer. + * + * @param fb the buffer to read from, must be correct size + * @return this data as a FloatBuffer. + */ + public Matrix4f readFloatBuffer(FloatBuffer fb) { + return readFloatBuffer(fb, false); + } + + /** + * readFloatBuffer reads value for this matrix from a + * FloatBuffer. + * + * @param fb the buffer to read from, must be correct size + * @param columnMajor if true, this buffer should be filled with column major data, + * otherwise it will be filled row major. + * @return this data as a FloatBuffer. + */ + public Matrix4f readFloatBuffer(FloatBuffer fb, boolean columnMajor) { + + if (columnMajor) { + m00 = fb.get(); + m10 = fb.get(); + m20 = fb.get(); + m30 = fb.get(); + m01 = fb.get(); + m11 = fb.get(); + m21 = fb.get(); + m31 = fb.get(); + m02 = fb.get(); + m12 = fb.get(); + m22 = fb.get(); + m32 = fb.get(); + m03 = fb.get(); + m13 = fb.get(); + m23 = fb.get(); + m33 = fb.get(); + } else { + m00 = fb.get(); + m01 = fb.get(); + m02 = fb.get(); + m03 = fb.get(); + m10 = fb.get(); + m11 = fb.get(); + m12 = fb.get(); + m13 = fb.get(); + m20 = fb.get(); + m21 = fb.get(); + m22 = fb.get(); + m23 = fb.get(); + m30 = fb.get(); + m31 = fb.get(); + m32 = fb.get(); + m33 = fb.get(); + } + return this; + } + + /** + * Legacy wrapper. This name implies that an identity matrix is "loaded", + * but one is not. Instead, the elements of 'this' identity are set. + */ + public void loadIdentity() { + setIdentity(); + } + + /** + * Sets this matrix to the identity matrix, namely all zeros with ones along + * the diagonal. + */ + public void setIdentity() { + m01 = m02 = m03 = m10 = m12 = m13 = m20 = m21 = m23 = m30 = m31 = m32 = 0.0f; + m00 = m11 = m22 = m33 = 1.0f; + } + + /** + * fromAngleAxis sets this matrix4f to the values specified by + * an angle and an axis of rotation. This method creates an object, so use + * fromAngleNormalAxis if your axis is already normalized. + * + * @param angle the angle to rotate (in radians). + * @param axis the axis of rotation. + */ + public void fromAngleAxis(float angle, Vector3f axis) { + Vector3f normAxis = axis.normalize(); + fromAngleNormalAxis(angle, normAxis); + } + + /** + * fromAngleNormalAxis sets this matrix4f to the values + * specified by an angle and a normalized axis of rotation. + * + * @param angle the angle to rotate (in radians). + * @param axis the axis of rotation (already normalized). + */ + public void fromAngleNormalAxis(float angle, Vector3f axis) { + zero(); + m33 = 1; + + float fCos = FastMath.cos(angle); + float fSin = FastMath.sin(angle); + float fOneMinusCos = ((float) 1.0) - fCos; + float fX2 = axis.x * axis.x; + float fY2 = axis.y * axis.y; + float fZ2 = axis.z * axis.z; + float fXYM = axis.x * axis.y * fOneMinusCos; + float fXZM = axis.x * axis.z * fOneMinusCos; + float fYZM = axis.y * axis.z * fOneMinusCos; + float fXSin = axis.x * fSin; + float fYSin = axis.y * fSin; + float fZSin = axis.z * fSin; + + m00 = fX2 * fOneMinusCos + fCos; + m01 = fXYM - fZSin; + m02 = fXZM + fYSin; + m10 = fXYM + fZSin; + m11 = fY2 * fOneMinusCos + fCos; + m12 = fYZM - fXSin; + m20 = fXZM - fYSin; + m21 = fYZM + fXSin; + m22 = fZ2 * fOneMinusCos + fCos; + } + + /** + * mult multiplies this matrix by a scalar. + * + * @param scalar the scalar to multiply this matrix by. + */ + public void multLocal(float scalar) { + m00 *= scalar; + m01 *= scalar; + m02 *= scalar; + m03 *= scalar; + m10 *= scalar; + m11 *= scalar; + m12 *= scalar; + m13 *= scalar; + m20 *= scalar; + m21 *= scalar; + m22 *= scalar; + m23 *= scalar; + m30 *= scalar; + m31 *= scalar; + m32 *= scalar; + m33 *= scalar; + } + + public Matrix4f mult(float scalar) { + Matrix4f out = new Matrix4f(); + out.set(this); + out.multLocal(scalar); + return out; + } + + public Matrix4f mult(float scalar, Matrix4f store) { + store.set(this); + store.multLocal(scalar); + return store; + } + + /** + * mult multiplies this matrix with another matrix. The result + * matrix will then be returned. This matrix will be on the left hand side, + * while the parameter matrix will be on the right. + * + * @param in2 the matrix to multiply this matrix by. + * @return the resultant matrix + */ + public Matrix4f mult(Matrix4f in2) { + return mult(in2, null); + } + + /** + * mult multiplies this matrix with another matrix. The result + * matrix will then be returned. This matrix will be on the left hand side, + * while the parameter matrix will be on the right. + * + * @param in2 the matrix to multiply this matrix by. + * @param store where to store the result. It is safe for in2 and store to be + * the same object. + * @return the resultant matrix + */ + public Matrix4f mult(Matrix4f in2, Matrix4f store) { + if (store == null) + store = new Matrix4f(); + + float temp00, temp01, temp02, temp03; + float temp10, temp11, temp12, temp13; + float temp20, temp21, temp22, temp23; + float temp30, temp31, temp32, temp33; + + temp00 = m00 * in2.m00 + m01 * in2.m10 + m02 * in2.m20 + m03 * in2.m30; + temp01 = m00 * in2.m01 + m01 * in2.m11 + m02 * in2.m21 + m03 * in2.m31; + temp02 = m00 * in2.m02 + m01 * in2.m12 + m02 * in2.m22 + m03 * in2.m32; + temp03 = m00 * in2.m03 + m01 * in2.m13 + m02 * in2.m23 + m03 * in2.m33; + + temp10 = m10 * in2.m00 + m11 * in2.m10 + m12 * in2.m20 + m13 * in2.m30; + temp11 = m10 * in2.m01 + m11 * in2.m11 + m12 * in2.m21 + m13 * in2.m31; + temp12 = m10 * in2.m02 + m11 * in2.m12 + m12 * in2.m22 + m13 * in2.m32; + temp13 = m10 * in2.m03 + m11 * in2.m13 + m12 * in2.m23 + m13 * in2.m33; + + temp20 = m20 * in2.m00 + m21 * in2.m10 + m22 * in2.m20 + m23 * in2.m30; + temp21 = m20 * in2.m01 + m21 * in2.m11 + m22 * in2.m21 + m23 * in2.m31; + temp22 = m20 * in2.m02 + m21 * in2.m12 + m22 * in2.m22 + m23 * in2.m32; + temp23 = m20 * in2.m03 + m21 * in2.m13 + m22 * in2.m23 + m23 * in2.m33; + + temp30 = m30 * in2.m00 + m31 * in2.m10 + m32 * in2.m20 + m33 * in2.m30; + temp31 = m30 * in2.m01 + m31 * in2.m11 + m32 * in2.m21 + m33 * in2.m31; + temp32 = m30 * in2.m02 + m31 * in2.m12 + m32 * in2.m22 + m33 * in2.m32; + temp33 = m30 * in2.m03 + m31 * in2.m13 + m32 * in2.m23 + m33 * in2.m33; + + store.m00 = temp00; + store.m01 = temp01; + store.m02 = temp02; + store.m03 = temp03; + store.m10 = temp10; + store.m11 = temp11; + store.m12 = temp12; + store.m13 = temp13; + store.m20 = temp20; + store.m21 = temp21; + store.m22 = temp22; + store.m23 = temp23; + store.m30 = temp30; + store.m31 = temp31; + store.m32 = temp32; + store.m33 = temp33; + + return store; + } + + /** + * mult multiplies this matrix with another matrix. The results + * are stored internally and a handle to this matrix will then be returned. + * This matrix will be on the left hand side, while the parameter matrix + * will be on the right. + * + * @param in2 the matrix to multiply this matrix by. + * @return the resultant matrix + */ + public Matrix4f multLocal(Matrix4f in2) { + + return mult(in2, this); + } + + /** + * mult multiplies a vector about a rotation matrix. The + * resulting vector is returned as a new Vector3f. + * + * @param vec vec to multiply against. + * @return the rotated vector. + */ + public Vector3f mult(Vector3f vec) { + return mult(vec, null); + } + + /** + * mult multiplies a vector about a rotation matrix and adds + * translation. The resulting vector is returned. + * + * @param vec vec to multiply against. + * @param store a vector to store the result in. Created if null is passed. + * @return the rotated vector. + */ + public Vector3f mult(Vector3f vec, Vector3f store) { + if (store == null) + store = new Vector3f(); + + float vx = vec.x, vy = vec.y, vz = vec.z; + store.x = m00 * vx + m01 * vy + m02 * vz + m03; + store.y = m10 * vx + m11 * vy + m12 * vz + m13; + store.z = m20 * vx + m21 * vy + m22 * vz + m23; + + return store; + } + + /** + * mult multiplies a vector about a rotation matrix. The + * resulting vector is returned. + * + * @param vec vec to multiply against. + * @param store a vector to store the result in. created if null is passed. + * @return the rotated vector. + */ + public Vector3f multAcross(Vector3f vec, Vector3f store) { + if (null == vec) { + return null; + } + if (store == null) + store = new Vector3f(); + + float vx = vec.x, vy = vec.y, vz = vec.z; + store.x = m00 * vx + m10 * vy + m20 * vz + m30 * 1; + store.y = m01 * vx + m11 * vy + m21 * vz + m31 * 1; + store.z = m02 * vx + m12 * vy + m22 * vz + m32 * 1; + + return store; + } + + /** + * mult multiplies a quaternion about a matrix. The resulting + * vector is returned. + * + * @param vec vec to multiply against. + * @param store a quaternion to store the result in. created if null is + * passed. + * @return store = this * vec + */ + public Quaternion mult(Quaternion vec, Quaternion store) { + + if (null == vec) { + return null; + } + if (store == null) + store = new Quaternion(); + + float x = m00 * vec.x + m10 * vec.y + m20 * vec.z + m30 * vec.w; + float y = m01 * vec.x + m11 * vec.y + m21 * vec.z + m31 * vec.w; + float z = m02 * vec.x + m12 * vec.y + m22 * vec.z + m32 * vec.w; + float w = m03 * vec.x + m13 * vec.y + m23 * vec.z + m33 * vec.w; + store.x = x; + store.y = y; + store.z = z; + store.w = w; + + return store; + } + + /** + * mult multiplies an array of 4 floats against this rotation + * matrix. The results are stored directly in the array. (vec4f x mat4f) + * + * @param vec4f float array (size 4) to multiply against the matrix. + * @return the vec4f for chaining. + */ + public float[] mult(float[] vec4f) { + if (null == vec4f || vec4f.length != 4) { + return null; + } + + float x = vec4f[0], y = vec4f[1], z = vec4f[2], w = vec4f[3]; + + vec4f[0] = m00 * x + m01 * y + m02 * z + m03 * w; + vec4f[1] = m10 * x + m11 * y + m12 * z + m13 * w; + vec4f[2] = m20 * x + m21 * y + m22 * z + m23 * w; + vec4f[3] = m30 * x + m31 * y + m32 * z + m33 * w; + + return vec4f; + } + + /** + * mult multiplies an array of 4 floats against this rotation + * matrix. The results are stored directly in the array. (vec4f x mat4f) + * + * @param vec4f float array (size 4) to multiply against the matrix. + * @return the vec4f for chaining. + */ + public float[] multAcross(float[] vec4f) { + if (null == vec4f || vec4f.length != 4) { + return null; + } + + float x = vec4f[0], y = vec4f[1], z = vec4f[2], w = vec4f[3]; + + vec4f[0] = m00 * x + m10 * y + m20 * z + m30 * w; + vec4f[1] = m01 * x + m11 * y + m21 * z + m31 * w; + vec4f[2] = m02 * x + m12 * y + m22 * z + m32 * w; + vec4f[3] = m03 * x + m13 * y + m23 * z + m33 * w; + + return vec4f; + } + + /** + * Inverts this matrix as a new Matrix4f. + * + * @return The new inverse matrix + */ + public Matrix4f invert() { + return invert(null); + } + + /** + * Inverts this matrix and stores it in the given store. + * + * @return The store + */ + public Matrix4f invert(Matrix4f store) { + if (store == null) + store = new Matrix4f(); + + float fA0 = m00 * m11 - m01 * m10; + float fA1 = m00 * m12 - m02 * m10; + float fA2 = m00 * m13 - m03 * m10; + float fA3 = m01 * m12 - m02 * m11; + float fA4 = m01 * m13 - m03 * m11; + float fA5 = m02 * m13 - m03 * m12; + float fB0 = m20 * m31 - m21 * m30; + float fB1 = m20 * m32 - m22 * m30; + float fB2 = m20 * m33 - m23 * m30; + float fB3 = m21 * m32 - m22 * m31; + float fB4 = m21 * m33 - m23 * m31; + float fB5 = m22 * m33 - m23 * m32; + float fDet = fA0 * fB5 - fA1 * fB4 + fA2 * fB3 + fA3 * fB2 - fA4 * fB1 + fA5 * fB0; + + if (FastMath.abs(fDet) <= 0) + return store.zero(); + + store.m00 = +m11 * fB5 - m12 * fB4 + m13 * fB3; + store.m10 = -m10 * fB5 + m12 * fB2 - m13 * fB1; + store.m20 = +m10 * fB4 - m11 * fB2 + m13 * fB0; + store.m30 = -m10 * fB3 + m11 * fB1 - m12 * fB0; + store.m01 = -m01 * fB5 + m02 * fB4 - m03 * fB3; + store.m11 = +m00 * fB5 - m02 * fB2 + m03 * fB1; + store.m21 = -m00 * fB4 + m01 * fB2 - m03 * fB0; + store.m31 = +m00 * fB3 - m01 * fB1 + m02 * fB0; + store.m02 = +m31 * fA5 - m32 * fA4 + m33 * fA3; + store.m12 = -m30 * fA5 + m32 * fA2 - m33 * fA1; + store.m22 = +m30 * fA4 - m31 * fA2 + m33 * fA0; + store.m32 = -m30 * fA3 + m31 * fA1 - m32 * fA0; + store.m03 = -m21 * fA5 + m22 * fA4 - m23 * fA3; + store.m13 = +m20 * fA5 - m22 * fA2 + m23 * fA1; + store.m23 = -m20 * fA4 + m21 * fA2 - m23 * fA0; + store.m33 = +m20 * fA3 - m21 * fA1 + m22 * fA0; + + float fInvDet = 1.0f / fDet; + store.multLocal(fInvDet); + + return store; + } + + /** + * Inverts this matrix locally. + * + * @return this + */ + public Matrix4f invertLocal() { + + float fA0 = m00 * m11 - m01 * m10; + float fA1 = m00 * m12 - m02 * m10; + float fA2 = m00 * m13 - m03 * m10; + float fA3 = m01 * m12 - m02 * m11; + float fA4 = m01 * m13 - m03 * m11; + float fA5 = m02 * m13 - m03 * m12; + float fB0 = m20 * m31 - m21 * m30; + float fB1 = m20 * m32 - m22 * m30; + float fB2 = m20 * m33 - m23 * m30; + float fB3 = m21 * m32 - m22 * m31; + float fB4 = m21 * m33 - m23 * m31; + float fB5 = m22 * m33 - m23 * m32; + float fDet = fA0 * fB5 - fA1 * fB4 + fA2 * fB3 + fA3 * fB2 - fA4 * fB1 + fA5 * fB0; + + if (FastMath.abs(fDet) <= FastMath.FLT_EPSILON) + return zero(); + + float f00 = +m11 * fB5 - m12 * fB4 + m13 * fB3; + float f10 = -m10 * fB5 + m12 * fB2 - m13 * fB1; + float f20 = +m10 * fB4 - m11 * fB2 + m13 * fB0; + float f30 = -m10 * fB3 + m11 * fB1 - m12 * fB0; + float f01 = -m01 * fB5 + m02 * fB4 - m03 * fB3; + float f11 = +m00 * fB5 - m02 * fB2 + m03 * fB1; + float f21 = -m00 * fB4 + m01 * fB2 - m03 * fB0; + float f31 = +m00 * fB3 - m01 * fB1 + m02 * fB0; + float f02 = +m31 * fA5 - m32 * fA4 + m33 * fA3; + float f12 = -m30 * fA5 + m32 * fA2 - m33 * fA1; + float f22 = +m30 * fA4 - m31 * fA2 + m33 * fA0; + float f32 = -m30 * fA3 + m31 * fA1 - m32 * fA0; + float f03 = -m21 * fA5 + m22 * fA4 - m23 * fA3; + float f13 = +m20 * fA5 - m22 * fA2 + m23 * fA1; + float f23 = -m20 * fA4 + m21 * fA2 - m23 * fA0; + float f33 = +m20 * fA3 - m21 * fA1 + m22 * fA0; + + m00 = f00; + m01 = f01; + m02 = f02; + m03 = f03; + m10 = f10; + m11 = f11; + m12 = f12; + m13 = f13; + m20 = f20; + m21 = f21; + m22 = f22; + m23 = f23; + m30 = f30; + m31 = f31; + m32 = f32; + m33 = f33; + + float fInvDet = 1.0f / fDet; + multLocal(fInvDet); + + return this; + } + + /** + * Returns a new matrix representing the adjoint of this matrix. + * + * @return The adjoint matrix + */ + public Matrix4f adjoint() { + return adjoint(null); + } + + /** + * Places the adjoint of this matrix in store (creates store if null.) + * + * @param store The matrix to store the result in. If null, a new matrix is + * created. + * @return store + */ + public Matrix4f adjoint(Matrix4f store) { + if (store == null) + store = new Matrix4f(); + + float fA0 = m00 * m11 - m01 * m10; + float fA1 = m00 * m12 - m02 * m10; + float fA2 = m00 * m13 - m03 * m10; + float fA3 = m01 * m12 - m02 * m11; + float fA4 = m01 * m13 - m03 * m11; + float fA5 = m02 * m13 - m03 * m12; + float fB0 = m20 * m31 - m21 * m30; + float fB1 = m20 * m32 - m22 * m30; + float fB2 = m20 * m33 - m23 * m30; + float fB3 = m21 * m32 - m22 * m31; + float fB4 = m21 * m33 - m23 * m31; + float fB5 = m22 * m33 - m23 * m32; + + store.m00 = +m11 * fB5 - m12 * fB4 + m13 * fB3; + store.m10 = -m10 * fB5 + m12 * fB2 - m13 * fB1; + store.m20 = +m10 * fB4 - m11 * fB2 + m13 * fB0; + store.m30 = -m10 * fB3 + m11 * fB1 - m12 * fB0; + store.m01 = -m01 * fB5 + m02 * fB4 - m03 * fB3; + store.m11 = +m00 * fB5 - m02 * fB2 + m03 * fB1; + store.m21 = -m00 * fB4 + m01 * fB2 - m03 * fB0; + store.m31 = +m00 * fB3 - m01 * fB1 + m02 * fB0; + store.m02 = +m31 * fA5 - m32 * fA4 + m33 * fA3; + store.m12 = -m30 * fA5 + m32 * fA2 - m33 * fA1; + store.m22 = +m30 * fA4 - m31 * fA2 + m33 * fA0; + store.m32 = -m30 * fA3 + m31 * fA1 - m32 * fA0; + store.m03 = -m21 * fA5 + m22 * fA4 - m23 * fA3; + store.m13 = +m20 * fA5 - m22 * fA2 + m23 * fA1; + store.m23 = -m20 * fA4 + m21 * fA2 - m23 * fA0; + store.m33 = +m20 * fA3 - m21 * fA1 + m22 * fA0; + + return store; + } + + /** + * determinant generates the determinate of this matrix. + * + * @return the determinate + */ + public float determinant() { + float fA0 = m00 * m11 - m01 * m10; + float fA1 = m00 * m12 - m02 * m10; + float fA2 = m00 * m13 - m03 * m10; + float fA3 = m01 * m12 - m02 * m11; + float fA4 = m01 * m13 - m03 * m11; + float fA5 = m02 * m13 - m03 * m12; + float fB0 = m20 * m31 - m21 * m30; + float fB1 = m20 * m32 - m22 * m30; + float fB2 = m20 * m33 - m23 * m30; + float fB3 = m21 * m32 - m22 * m31; + float fB4 = m21 * m33 - m23 * m31; + float fB5 = m22 * m33 - m23 * m32; return fA0 * fB5 - fA1 * fB4 + fA2 * fB3 + fA3 * fB2 - fA4 * fB1 + fA5 * fB0; - } - - /** - * Sets all of the values in this matrix to zero. - * - * @return this matrix - */ - public Matrix4f zero() { - m00 = m01 = m02 = m03 = m10 = m11 = m12 = m13 = m20 = m21 = m22 = m23 = m30 = m31 = m32 = m33 = 0.0f; - return this; - } - - public Matrix4f add(Matrix4f mat) { - Matrix4f result = new Matrix4f(); - result.m00 = this.m00 + mat.m00; - result.m01 = this.m01 + mat.m01; - result.m02 = this.m02 + mat.m02; - result.m03 = this.m03 + mat.m03; - result.m10 = this.m10 + mat.m10; - result.m11 = this.m11 + mat.m11; - result.m12 = this.m12 + mat.m12; - result.m13 = this.m13 + mat.m13; - result.m20 = this.m20 + mat.m20; - result.m21 = this.m21 + mat.m21; - result.m22 = this.m22 + mat.m22; - result.m23 = this.m23 + mat.m23; - result.m30 = this.m30 + mat.m30; - result.m31 = this.m31 + mat.m31; - result.m32 = this.m32 + mat.m32; - result.m33 = this.m33 + mat.m33; - return result; - } - - /** - * add adds the values of a parameter matrix to this matrix. - * - * @param mat - * the matrix to add to this. - */ - public void addLocal(Matrix4f mat) { - m00 += mat.m00; - m01 += mat.m01; - m02 += mat.m02; - m03 += mat.m03; - m10 += mat.m10; - m11 += mat.m11; - m12 += mat.m12; - m13 += mat.m13; - m20 += mat.m20; - m21 += mat.m21; - m22 += mat.m22; - m23 += mat.m23; - m30 += mat.m30; - m31 += mat.m31; - m32 += mat.m32; - m33 += mat.m33; - } - - public Vector3f toTranslationVector() { - return new Vector3f(m03, m13, m23); - } - - public void toTranslationVector(Vector3f vector) { - vector.set(m03, m13, m23); - } - - public Quaternion toRotationQuat() { - Quaternion quat = new Quaternion(); - quat.fromRotationMatrix(toRotationMatrix()); - return quat; - } - - public void toRotationQuat(Quaternion q) { - q.fromRotationMatrix(toRotationMatrix()); - } - - public Matrix3f toRotationMatrix() { - return new Matrix3f(m00, m01, m02, m10, m11, m12, m20, m21, m22); - - } - - public void toRotationMatrix(Matrix3f mat) { - mat.m00 = m00; - mat.m01 = m01; - mat.m02 = m02; - mat.m10 = m10; - mat.m11 = m11; - mat.m12 = m12; - mat.m20 = m20; - mat.m21 = m21; - mat.m22 = m22; - - } - - /** - * setTranslation will set the matrix's translation values. - * - * @param translation - * the new values for the translation. - * @throws Exception - * if translation is not size 3. - */ - public void setTranslation(float[] translation) throws Exception { - if (translation.length != 3) { - throw new Exception("Translation size must be 3."); - } - m03 = translation[0]; - m13 = translation[1]; - m23 = translation[2]; - } - - /** - * setTranslation will set the matrix's translation values. - * - * @param x - * value of the translation on the x axis - * @param y - * value of the translation on the y axis - * @param z - * value of the translation on the z axis - */ - public void setTranslation(float x, float y, float z) { - m03 = x; - m13 = y; - m23 = z; - } - - /** - * setTranslation will set the matrix's translation values. - * - * @param translation - * the new values for the translation. - */ - public void setTranslation(Vector3f translation) { - m03 = translation.x; - m13 = translation.y; - m23 = translation.z; - } - - /** - * setInverseTranslation will set the matrix's inverse - * translation values. - * - * @param translation - * the new values for the inverse translation. - * @throws Exception - * if translation is not size 3. - */ - public void setInverseTranslation(float[] translation) throws Exception { - if (translation.length != 3) { - throw new Exception("Translation size must be 3."); - } - m03 = -translation[0]; - m13 = -translation[1]; - m23 = -translation[2]; - } - - /** - * angleRotation sets this matrix to that of a rotation about - * three axes (x, y, z). Where each axis has a specified rotation in - * degrees. These rotations are expressed in a single Vector3f - * object. - * - * @param angles - * the angles to rotate. - */ - public void angleRotation(Vector3f angles) { - float angle; - float sr, sp, sy, cr, cp, cy; - - angle = (angles.z * FastMath.DEG_TO_RAD); - sy = FastMath.sin(angle); - cy = FastMath.cos(angle); - angle = (angles.y * FastMath.DEG_TO_RAD); - sp = FastMath.sin(angle); - cp = FastMath.cos(angle); - angle = (angles.x * FastMath.DEG_TO_RAD); - sr = FastMath.sin(angle); - cr = FastMath.cos(angle); - - // matrix = (Z * Y) * X - m00 = cp * cy; - m10 = cp * sy; - m20 = -sp; - m01 = sr * sp * cy + cr * -sy; - m11 = sr * sp * sy + cr * cy; - m21 = sr * cp; - m02 = (cr * sp * cy + -sr * -sy); - m12 = (cr * sp * sy + -sr * cy); - m22 = cr * cp; - m03 = 0.0f; - m13 = 0.0f; - m23 = 0.0f; - } - - /** - * setRotationQuaternion builds a rotation from a - * Quaternion. - * - * @param quat - * the quaternion to build the rotation from. - * @throws NullPointerException - * if quat is null. - */ - public void setRotationQuaternion(Quaternion quat) { - quat.toRotationMatrix(this); - } - - /** - * setInverseRotationRadians builds an inverted rotation from - * Euler angles that are in radians. - * - * @param angles - * the Euler angles in radians. - * @throws Exception - * if angles is not size 3. - */ - public void setInverseRotationRadians(float[] angles) throws Exception { - if (angles.length != 3) { - throw new Exception("Angles must be of size 3."); - } - double cr = FastMath.cos(angles[0]); - double sr = FastMath.sin(angles[0]); - double cp = FastMath.cos(angles[1]); - double sp = FastMath.sin(angles[1]); - double cy = FastMath.cos(angles[2]); - double sy = FastMath.sin(angles[2]); - - m00 = (float) (cp * cy); - m10 = (float) (cp * sy); - m20 = (float) (-sp); - - double srsp = sr * sp; - double crsp = cr * sp; - - m01 = (float) (srsp * cy - cr * sy); - m11 = (float) (srsp * sy + cr * cy); - m21 = (float) (sr * cp); - - m02 = (float) (crsp * cy + sr * sy); - m12 = (float) (crsp * sy - sr * cy); - m22 = (float) (cr * cp); - } - - /** - * setInverseRotationDegrees builds an inverted rotation from - * Euler angles that are in degrees. - * - * @param angles - * the Euler angles in degrees. - * @throws Exception - * if angles is not size 3. - */ - public void setInverseRotationDegrees(float[] angles) throws Exception { - if (angles.length != 3) { - throw new Exception("Angles must be of size 3."); - } - float vec[] = new float[3]; - vec[0] = (angles[0] * FastMath.RAD_TO_DEG); - vec[1] = (angles[1] * FastMath.RAD_TO_DEG); - vec[2] = (angles[2] * FastMath.RAD_TO_DEG); - setInverseRotationRadians(vec); - } - - /** - * - * inverseTranslateVect translates a given Vector3f by the - * translation part of this matrix. - * - * @param vec - * the Vector3f data to be translated. - * @throws Exception - * if the size of the Vector3f is not 3. - */ - public void inverseTranslateVect(float[] vec) throws Exception { - if (vec.length != 3) { - throw new Exception("vec must be of size 3."); - } + } + + /** + * Sets all of the values in this matrix to zero. + * + * @return this matrix + */ + public Matrix4f zero() { + m00 = m01 = m02 = m03 = m10 = m11 = m12 = m13 = m20 = m21 = m22 = m23 = m30 = m31 = m32 = m33 = 0.0f; + return this; + } + + public Matrix4f add(Matrix4f mat) { + Matrix4f result = new Matrix4f(); + result.m00 = this.m00 + mat.m00; + result.m01 = this.m01 + mat.m01; + result.m02 = this.m02 + mat.m02; + result.m03 = this.m03 + mat.m03; + result.m10 = this.m10 + mat.m10; + result.m11 = this.m11 + mat.m11; + result.m12 = this.m12 + mat.m12; + result.m13 = this.m13 + mat.m13; + result.m20 = this.m20 + mat.m20; + result.m21 = this.m21 + mat.m21; + result.m22 = this.m22 + mat.m22; + result.m23 = this.m23 + mat.m23; + result.m30 = this.m30 + mat.m30; + result.m31 = this.m31 + mat.m31; + result.m32 = this.m32 + mat.m32; + result.m33 = this.m33 + mat.m33; + return result; + } + + /** + * add adds the values of a parameter matrix to this matrix. + * + * @param mat the matrix to add to this. + */ + public void addLocal(Matrix4f mat) { + m00 += mat.m00; + m01 += mat.m01; + m02 += mat.m02; + m03 += mat.m03; + m10 += mat.m10; + m11 += mat.m11; + m12 += mat.m12; + m13 += mat.m13; + m20 += mat.m20; + m21 += mat.m21; + m22 += mat.m22; + m23 += mat.m23; + m30 += mat.m30; + m31 += mat.m31; + m32 += mat.m32; + m33 += mat.m33; + } + + public Vector3f toTranslationVector() { + return new Vector3f(m03, m13, m23); + } + + public void toTranslationVector(Vector3f vector) { + vector.set(m03, m13, m23); + } + + public Quaternion toRotationQuat() { + Quaternion quat = new Quaternion(); + quat.fromRotationMatrix(toRotationMatrix()); + return quat; + } + + public void toRotationQuat(Quaternion q) { + q.fromRotationMatrix(toRotationMatrix()); + } + + public Matrix3f toRotationMatrix() { + return new Matrix3f(m00, m01, m02, m10, m11, m12, m20, m21, m22); + + } + + public void toRotationMatrix(Matrix3f mat) { + mat.m00 = m00; + mat.m01 = m01; + mat.m02 = m02; + mat.m10 = m10; + mat.m11 = m11; + mat.m12 = m12; + mat.m20 = m20; + mat.m21 = m21; + mat.m22 = m22; + + } + + /** + * setTranslation will set the matrix's translation values. + * + * @param translation the new values for the translation. + * @throws Exception if translation is not size 3. + */ + public void setTranslation(float[] translation) throws Exception { + if (translation.length != 3) { + throw new Exception("Translation size must be 3."); + } + m03 = translation[0]; + m13 = translation[1]; + m23 = translation[2]; + } + + /** + * setTranslation will set the matrix's translation values. + * + * @param x value of the translation on the x axis + * @param y value of the translation on the y axis + * @param z value of the translation on the z axis + */ + public void setTranslation(float x, float y, float z) { + m03 = x; + m13 = y; + m23 = z; + } + + /** + * setTranslation will set the matrix's translation values. + * + * @param translation the new values for the translation. + */ + public void setTranslation(Vector3f translation) { + m03 = translation.x; + m13 = translation.y; + m23 = translation.z; + } + + /** + * setInverseTranslation will set the matrix's inverse + * translation values. + * + * @param translation the new values for the inverse translation. + * @throws Exception if translation is not size 3. + */ + public void setInverseTranslation(float[] translation) throws Exception { + if (translation.length != 3) { + throw new Exception("Translation size must be 3."); + } + m03 = -translation[0]; + m13 = -translation[1]; + m23 = -translation[2]; + } + + /** + * angleRotation sets this matrix to that of a rotation about + * three axes (x, y, z). Where each axis has a specified rotation in + * degrees. These rotations are expressed in a single Vector3f + * object. + * + * @param angles the angles to rotate. + */ + public void angleRotation(Vector3f angles) { + float angle; + float sr, sp, sy, cr, cp, cy; + + angle = (angles.z * FastMath.DEG_TO_RAD); + sy = FastMath.sin(angle); + cy = FastMath.cos(angle); + angle = (angles.y * FastMath.DEG_TO_RAD); + sp = FastMath.sin(angle); + cp = FastMath.cos(angle); + angle = (angles.x * FastMath.DEG_TO_RAD); + sr = FastMath.sin(angle); + cr = FastMath.cos(angle); + + // matrix = (Z * Y) * X + m00 = cp * cy; + m10 = cp * sy; + m20 = -sp; + m01 = sr * sp * cy + cr * -sy; + m11 = sr * sp * sy + cr * cy; + m21 = sr * cp; + m02 = (cr * sp * cy + -sr * -sy); + m12 = (cr * sp * sy + -sr * cy); + m22 = cr * cp; + m03 = 0.0f; + m13 = 0.0f; + m23 = 0.0f; + } + + /** + * setRotationQuaternion builds a rotation from a + * Quaternion. + * + * @param quat the quaternion to build the rotation from. + * @throws NullPointerException if quat is null. + */ + public void setRotationQuaternion(Quaternion quat) { + quat.toRotationMatrix(this); + } + + /** + * setInverseRotationRadians builds an inverted rotation from + * Euler angles that are in radians. + * + * @param angles the Euler angles in radians. + * @throws Exception if angles is not size 3. + */ + public void setInverseRotationRadians(float[] angles) throws Exception { + if (angles.length != 3) { + throw new Exception("Angles must be of size 3."); + } + double cr = FastMath.cos(angles[0]); + double sr = FastMath.sin(angles[0]); + double cp = FastMath.cos(angles[1]); + double sp = FastMath.sin(angles[1]); + double cy = FastMath.cos(angles[2]); + double sy = FastMath.sin(angles[2]); + + m00 = (float) (cp * cy); + m10 = (float) (cp * sy); + m20 = (float) (-sp); + + double srsp = sr * sp; + double crsp = cr * sp; + + m01 = (float) (srsp * cy - cr * sy); + m11 = (float) (srsp * sy + cr * cy); + m21 = (float) (sr * cp); + + m02 = (float) (crsp * cy + sr * sy); + m12 = (float) (crsp * sy - sr * cy); + m22 = (float) (cr * cp); + } + + /** + * setInverseRotationDegrees builds an inverted rotation from + * Euler angles that are in degrees. + * + * @param angles the Euler angles in degrees. + * @throws Exception if angles is not size 3. + */ + public void setInverseRotationDegrees(float[] angles) throws Exception { + if (angles.length != 3) { + throw new Exception("Angles must be of size 3."); + } + float vec[] = new float[3]; + vec[0] = (angles[0] * FastMath.RAD_TO_DEG); + vec[1] = (angles[1] * FastMath.RAD_TO_DEG); + vec[2] = (angles[2] * FastMath.RAD_TO_DEG); + setInverseRotationRadians(vec); + } + + /** + * inverseTranslateVect translates a given Vector3f by the + * translation part of this matrix. + * + * @param vec the Vector3f data to be translated. + * @throws Exception if the size of the Vector3f is not 3. + */ + public void inverseTranslateVect(float[] vec) throws Exception { + if (vec.length != 3) { + throw new Exception("vec must be of size 3."); + } vec[0] -= m03; vec[1] -= m13; vec[2] -= m23; - } - - /** - * - * inverseTranslateVect translates a given Vector3f by the - * translation part of this matrix. - * - * @param data - * the Vector3f to be translated. - * @throws Exception - * if the size of the Vector3f is not 3. - */ - public void inverseTranslateVect(Vector3f data) { - data.x -= m03; - data.y -= m13; - data.z -= m23; - } - - /** - * - * inverseTranslateVect translates a given Vector3f by the - * translation part of this matrix. - * - * @param data - * the Vector3f to be translated. - * @throws Exception - * if the size of the Vector3f is not 3. - */ - public void translateVect(Vector3f data) { - data.x += m03; - data.y += m13; - data.z += m23; - } - - /** - * - * inverseRotateVect rotates a given Vector3f by the rotation - * part of this matrix. - * - * @param vec - * the Vector3f to be rotated. - */ - public void inverseRotateVect(Vector3f vec) { - float vx = vec.x, vy = vec.y, vz = vec.z; - - vec.x = vx * m00 + vy * m10 + vz * m20; - vec.y = vx * m01 + vy * m11 + vz * m21; - vec.z = vx * m02 + vy * m12 + vz * m22; - } - - public void rotateVect(Vector3f vec) { - float vx = vec.x, vy = vec.y, vz = vec.z; - - vec.x = vx * m00 + vy * m01 + vz * m02; - vec.y = vx * m10 + vy * m11 + vz * m12; - vec.z = vx * m20 + vy * m21 + vz * m22; - } - - /** - * toString returns the string representation of this object. - * It is in a format of a 4x4 matrix. For example, an identity matrix would - * be represented by the following string. com.jme.math.Matrix3f
- * [
- * 1.0 0.0 0.0 0.0
- * 0.0 1.0 0.0 0.0
- * 0.0 0.0 1.0 0.0
- * 0.0 0.0 0.0 1.0
- * ]
- * - * @return the string representation of this object. - */ - @Override - public String toString() { - StringBuffer result = new StringBuffer("com.jme.math.Matrix4f\n[\n"); - result.append(' '); - result.append(m00); - result.append(" "); - result.append(m01); - result.append(" "); - result.append(m02); - result.append(" "); - result.append(m03); - result.append(" \n"); - result.append(' '); - result.append(m10); - result.append(" "); - result.append(m11); - result.append(" "); - result.append(m12); - result.append(" "); - result.append(m13); - result.append(" \n"); - result.append(' '); - result.append(m20); - result.append(" "); - result.append(m21); - result.append(" "); - result.append(m22); - result.append(" "); - result.append(m23); - result.append(" \n"); - result.append(' '); - result.append(m30); - result.append(" "); - result.append(m31); - result.append(" "); - result.append(m32); - result.append(" "); - result.append(m33); - result.append(" \n]"); - return result.toString(); - } - - /** - * - * hashCode returns the hash code value as an integer and is - * supported for the benefit of hashing based collection classes such as - * Hashtable, HashMap, HashSet etc. - * - * @return the hashcode for this instance of Matrix4f. - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - int hash = 37; - hash = 37 * hash + Float.floatToIntBits(m00); - hash = 37 * hash + Float.floatToIntBits(m01); - hash = 37 * hash + Float.floatToIntBits(m02); - hash = 37 * hash + Float.floatToIntBits(m03); - - hash = 37 * hash + Float.floatToIntBits(m10); - hash = 37 * hash + Float.floatToIntBits(m11); - hash = 37 * hash + Float.floatToIntBits(m12); - hash = 37 * hash + Float.floatToIntBits(m13); - - hash = 37 * hash + Float.floatToIntBits(m20); - hash = 37 * hash + Float.floatToIntBits(m21); - hash = 37 * hash + Float.floatToIntBits(m22); - hash = 37 * hash + Float.floatToIntBits(m23); - - hash = 37 * hash + Float.floatToIntBits(m30); - hash = 37 * hash + Float.floatToIntBits(m31); - hash = 37 * hash + Float.floatToIntBits(m32); - hash = 37 * hash + Float.floatToIntBits(m33); - - return hash; - } - - /** - * are these two matrices the same? they are is they both have the same mXX - * values. - * - * @param o - * the object to compare for equality - * @return true if they are equal - */ - @Override - public boolean equals(Object o) { - if (!(o instanceof Matrix4f) || o == null) { - return false; - } - - if (this == o) { - return true; - } - - Matrix4f comp = (Matrix4f) o; - if (Float.compare(m00, comp.m00) != 0) - return false; - if (Float.compare(m01, comp.m01) != 0) - return false; - if (Float.compare(m02, comp.m02) != 0) - return false; - if (Float.compare(m03, comp.m03) != 0) - return false; - - if (Float.compare(m10, comp.m10) != 0) - return false; - if (Float.compare(m11, comp.m11) != 0) - return false; - if (Float.compare(m12, comp.m12) != 0) - return false; - if (Float.compare(m13, comp.m13) != 0) - return false; - - if (Float.compare(m20, comp.m20) != 0) - return false; - if (Float.compare(m21, comp.m21) != 0) - return false; - if (Float.compare(m22, comp.m22) != 0) - return false; - if (Float.compare(m23, comp.m23) != 0) - return false; - - if (Float.compare(m30, comp.m30) != 0) - return false; - if (Float.compare(m31, comp.m31) != 0) - return false; - if (Float.compare(m32, comp.m32) != 0) - return false; - return Float.compare(m33, comp.m33) == 0; - } - - /** - * @return true if this matrix is identity - */ - public boolean isIdentity() { - return (m00 == 1 && m01 == 0 && m02 == 0 && m03 == 0) && (m10 == 0 && m11 == 1 && m12 == 0 && m13 == 0) - && (m20 == 0 && m21 == 0 && m22 == 1 && m23 == 0) && (m30 == 0 && m31 == 0 && m32 == 0 && m33 == 1); - } - - /** - * Apply a scale to this matrix. - * - * @param scale - * the scale to apply - */ - public void scale(Vector3f scale) { - m00 *= scale.getX(); - m10 *= scale.getX(); - m20 *= scale.getX(); - m30 *= scale.getX(); - m01 *= scale.getY(); - m11 *= scale.getY(); - m21 *= scale.getY(); - m31 *= scale.getY(); - m02 *= scale.getZ(); - m12 *= scale.getZ(); - m22 *= scale.getZ(); - m32 *= scale.getZ(); - } - - static boolean equalIdentity(Matrix4f mat) { - if (Math.abs(mat.m00 - 1) > 1e-4) - return false; - if (Math.abs(mat.m11 - 1) > 1e-4) - return false; - if (Math.abs(mat.m22 - 1) > 1e-4) - return false; - if (Math.abs(mat.m33 - 1) > 1e-4) - return false; - - if (Math.abs(mat.m01) > 1e-4) - return false; - if (Math.abs(mat.m02) > 1e-4) - return false; - if (Math.abs(mat.m03) > 1e-4) - return false; - - if (Math.abs(mat.m10) > 1e-4) - return false; - if (Math.abs(mat.m12) > 1e-4) - return false; - if (Math.abs(mat.m13) > 1e-4) - return false; - - if (Math.abs(mat.m20) > 1e-4) - return false; - if (Math.abs(mat.m21) > 1e-4) - return false; - if (Math.abs(mat.m23) > 1e-4) - return false; - - if (Math.abs(mat.m30) > 1e-4) - return false; - if (Math.abs(mat.m31) > 1e-4) - return false; - return !(Math.abs(mat.m32) > 1e-4); - } - - // XXX: This tests more solid than converting the q to a matrix and - // multiplying... why? - public void multLocal(Quaternion rotation) { - Vector3f axis = new Vector3f(); - float angle = rotation.toAngleAxis(axis); - Matrix4f matrix4f = new Matrix4f(); - matrix4f.fromAngleAxis(angle, axis); - multLocal(matrix4f); - } - - @Override - public Matrix4f clone() { - try { - return (Matrix4f) super.clone(); - } catch (CloneNotSupportedException e) { - Logger.error( e); - throw new AssertionError(); // can not happen - } - } + } + + /** + * inverseTranslateVect translates a given Vector3f by the + * translation part of this matrix. + * + * @param data the Vector3f to be translated. + * @throws Exception if the size of the Vector3f is not 3. + */ + public void inverseTranslateVect(Vector3f data) { + data.x -= m03; + data.y -= m13; + data.z -= m23; + } + + /** + * inverseTranslateVect translates a given Vector3f by the + * translation part of this matrix. + * + * @param data the Vector3f to be translated. + * @throws Exception if the size of the Vector3f is not 3. + */ + public void translateVect(Vector3f data) { + data.x += m03; + data.y += m13; + data.z += m23; + } + + /** + * inverseRotateVect rotates a given Vector3f by the rotation + * part of this matrix. + * + * @param vec the Vector3f to be rotated. + */ + public void inverseRotateVect(Vector3f vec) { + float vx = vec.x, vy = vec.y, vz = vec.z; + + vec.x = vx * m00 + vy * m10 + vz * m20; + vec.y = vx * m01 + vy * m11 + vz * m21; + vec.z = vx * m02 + vy * m12 + vz * m22; + } + + public void rotateVect(Vector3f vec) { + float vx = vec.x, vy = vec.y, vz = vec.z; + + vec.x = vx * m00 + vy * m01 + vz * m02; + vec.y = vx * m10 + vy * m11 + vz * m12; + vec.z = vx * m20 + vy * m21 + vz * m22; + } + + /** + * toString returns the string representation of this object. + * It is in a format of a 4x4 matrix. For example, an identity matrix would + * be represented by the following string. com.jme.math.Matrix3f
+ * [
+ * 1.0 0.0 0.0 0.0
+ * 0.0 1.0 0.0 0.0
+ * 0.0 0.0 1.0 0.0
+ * 0.0 0.0 0.0 1.0
+ * ]
+ * + * @return the string representation of this object. + */ + @Override + public String toString() { + StringBuffer result = new StringBuffer("com.jme.math.Matrix4f\n[\n"); + result.append(' '); + result.append(m00); + result.append(" "); + result.append(m01); + result.append(" "); + result.append(m02); + result.append(" "); + result.append(m03); + result.append(" \n"); + result.append(' '); + result.append(m10); + result.append(" "); + result.append(m11); + result.append(" "); + result.append(m12); + result.append(" "); + result.append(m13); + result.append(" \n"); + result.append(' '); + result.append(m20); + result.append(" "); + result.append(m21); + result.append(" "); + result.append(m22); + result.append(" "); + result.append(m23); + result.append(" \n"); + result.append(' '); + result.append(m30); + result.append(" "); + result.append(m31); + result.append(" "); + result.append(m32); + result.append(" "); + result.append(m33); + result.append(" \n]"); + return result.toString(); + } + + /** + * hashCode returns the hash code value as an integer and is + * supported for the benefit of hashing based collection classes such as + * Hashtable, HashMap, HashSet etc. + * + * @return the hashcode for this instance of Matrix4f. + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + int hash = 37; + hash = 37 * hash + Float.floatToIntBits(m00); + hash = 37 * hash + Float.floatToIntBits(m01); + hash = 37 * hash + Float.floatToIntBits(m02); + hash = 37 * hash + Float.floatToIntBits(m03); + + hash = 37 * hash + Float.floatToIntBits(m10); + hash = 37 * hash + Float.floatToIntBits(m11); + hash = 37 * hash + Float.floatToIntBits(m12); + hash = 37 * hash + Float.floatToIntBits(m13); + + hash = 37 * hash + Float.floatToIntBits(m20); + hash = 37 * hash + Float.floatToIntBits(m21); + hash = 37 * hash + Float.floatToIntBits(m22); + hash = 37 * hash + Float.floatToIntBits(m23); + + hash = 37 * hash + Float.floatToIntBits(m30); + hash = 37 * hash + Float.floatToIntBits(m31); + hash = 37 * hash + Float.floatToIntBits(m32); + hash = 37 * hash + Float.floatToIntBits(m33); + + return hash; + } + + /** + * are these two matrices the same? they are is they both have the same mXX + * values. + * + * @param o the object to compare for equality + * @return true if they are equal + */ + @Override + public boolean equals(Object o) { + if (!(o instanceof Matrix4f) || o == null) { + return false; + } + + if (this == o) { + return true; + } + + Matrix4f comp = (Matrix4f) o; + if (Float.compare(m00, comp.m00) != 0) + return false; + if (Float.compare(m01, comp.m01) != 0) + return false; + if (Float.compare(m02, comp.m02) != 0) + return false; + if (Float.compare(m03, comp.m03) != 0) + return false; + + if (Float.compare(m10, comp.m10) != 0) + return false; + if (Float.compare(m11, comp.m11) != 0) + return false; + if (Float.compare(m12, comp.m12) != 0) + return false; + if (Float.compare(m13, comp.m13) != 0) + return false; + + if (Float.compare(m20, comp.m20) != 0) + return false; + if (Float.compare(m21, comp.m21) != 0) + return false; + if (Float.compare(m22, comp.m22) != 0) + return false; + if (Float.compare(m23, comp.m23) != 0) + return false; + + if (Float.compare(m30, comp.m30) != 0) + return false; + if (Float.compare(m31, comp.m31) != 0) + return false; + if (Float.compare(m32, comp.m32) != 0) + return false; + return Float.compare(m33, comp.m33) == 0; + } + + /** + * @return true if this matrix is identity + */ + public boolean isIdentity() { + return (m00 == 1 && m01 == 0 && m02 == 0 && m03 == 0) && (m10 == 0 && m11 == 1 && m12 == 0 && m13 == 0) + && (m20 == 0 && m21 == 0 && m22 == 1 && m23 == 0) && (m30 == 0 && m31 == 0 && m32 == 0 && m33 == 1); + } + + /** + * Apply a scale to this matrix. + * + * @param scale the scale to apply + */ + public void scale(Vector3f scale) { + m00 *= scale.getX(); + m10 *= scale.getX(); + m20 *= scale.getX(); + m30 *= scale.getX(); + m01 *= scale.getY(); + m11 *= scale.getY(); + m21 *= scale.getY(); + m31 *= scale.getY(); + m02 *= scale.getZ(); + m12 *= scale.getZ(); + m22 *= scale.getZ(); + m32 *= scale.getZ(); + } + + // XXX: This tests more solid than converting the q to a matrix and + // multiplying... why? + public void multLocal(Quaternion rotation) { + Vector3f axis = new Vector3f(); + float angle = rotation.toAngleAxis(axis); + Matrix4f matrix4f = new Matrix4f(); + matrix4f.fromAngleAxis(angle, axis); + multLocal(matrix4f); + } + + @Override + public Matrix4f clone() { + try { + return (Matrix4f) super.clone(); + } catch (CloneNotSupportedException e) { + Logger.error(e); + throw new AssertionError(); // can not happen + } + } } diff --git a/src/engine/math/Quaternion.java b/src/engine/math/Quaternion.java index d5016a86..e2f5efa2 100644 --- a/src/engine/math/Quaternion.java +++ b/src/engine/math/Quaternion.java @@ -20,1245 +20,1167 @@ import java.io.ObjectOutput; * hypercomplex numbers. Quaternions extends a rotation in three dimensions to a * rotation in four dimensions. This avoids "gimbal lock" and allows for smooth * continuous rotation. - * + * * Quaternion is defined by four floating point numbers: {x y z w}. - * */ public class Quaternion { - public float x, y, z, w; - public float angleX, angleY,angleZ; - - /** - * Constructor instantiates a new Quaternion object - * initializing all values to zero, except w which is initialized to 1. - * - */ - public Quaternion() { - x = 0; - y = 0; - z = 0; - w = 1; - } - - /** - * Constructor instantiates a new Quaternion object from the - * given list of parameters. - * - * @param x - * the x value of the quaternion. - * @param y - * the y value of the quaternion. - * @param z - * the z value of the quaternion. - * @param w - * the w value of the quaternion. - */ - public Quaternion(float x, float y, float z, float w) { - this.x = x; - this.y = y; - this.z = z; - this.w = w; - float[] angles = new float[3]; - angles = this.toAngles(angles); - angleX = angles[0]; - angleY = angles[1]; - angleZ = angles[2]; - } - - /** - * sets the data in a Quaternion object from the given list of - * parameters. - * - * @param x - * the x value of the quaternion. - * @param y - * the y value of the quaternion. - * @param z - * the z value of the quaternion. - * @param w - * the w value of the quaternion. - */ - public void set(float x, float y, float z, float w) { - this.x = x; - this.y = y; - this.z = z; - this.w = w; - } - - /** - * Sets the data in this Quaternion object to be equal to the - * passed Quaternion object. The values are copied producing a - * new object. - * - * @param q - * The Quaternion to copy values from. - * @return this for chaining - */ - public Quaternion set(Quaternion q) { - this.x = q.x; - this.y = q.y; - this.z = q.z; - this.w = q.w; - return this; - } - - /** - * Constructor instantiates a new Quaternion object from a - * collection of rotation angles. - * - * @param angles - * the angles of rotation (x, y, z) that will define the - * Quaternion. - */ - public Quaternion(float[] angles) { - fromAngles(angles); - } - - /** - * Constructor instantiates a new Quaternion object from an - * interpolation between two other quaternions. - * - * @param q1 - * the first quaternion. - * @param q2 - * the second quaternion. - * @param interp - * the amount to interpolate between the two quaternions. - */ - public Quaternion(Quaternion q1, Quaternion q2, float interp) { - slerp(q1, q2, interp); - } - - /** - * Constructor instantiates a new Quaternion object from an - * existing quaternion, creating a copy. - * - * @param q - * the quaternion to copy. - */ - public Quaternion(Quaternion q) { - this.x = q.x; - this.y = q.y; - this.z = q.z; - this.w = q.w; - } - - /** - * Sets this Quaternion to {0, 0, 0, 1}. Same as calling set(0,0,0,1). - */ - public void loadIdentity() { - x = y = z = 0; - w = 1; - } - - /** - * @return true if this Quaternion is {0,0,0,1} - */ - public boolean isIdentity() { + private static final Vector3f tmpYaxis = new Vector3f(); + private static final Vector3f tmpZaxis = new Vector3f(); + private static final Vector3f tmpXaxis = new Vector3f(); + public float x, y, z, w; + public float angleX, angleY, angleZ; + + /** + * Constructor instantiates a new Quaternion object + * initializing all values to zero, except w which is initialized to 1. + */ + public Quaternion() { + x = 0; + y = 0; + z = 0; + w = 1; + } + + /** + * Constructor instantiates a new Quaternion object from the + * given list of parameters. + * + * @param x the x value of the quaternion. + * @param y the y value of the quaternion. + * @param z the z value of the quaternion. + * @param w the w value of the quaternion. + */ + public Quaternion(float x, float y, float z, float w) { + this.x = x; + this.y = y; + this.z = z; + this.w = w; + float[] angles = new float[3]; + angles = this.toAngles(angles); + angleX = angles[0]; + angleY = angles[1]; + angleZ = angles[2]; + } + + /** + * Constructor instantiates a new Quaternion object from a + * collection of rotation angles. + * + * @param angles the angles of rotation (x, y, z) that will define the + * Quaternion. + */ + public Quaternion(float[] angles) { + fromAngles(angles); + } + + /** + * Constructor instantiates a new Quaternion object from an + * interpolation between two other quaternions. + * + * @param q1 the first quaternion. + * @param q2 the second quaternion. + * @param interp the amount to interpolate between the two quaternions. + */ + public Quaternion(Quaternion q1, Quaternion q2, float interp) { + slerp(q1, q2, interp); + } + + /** + * Constructor instantiates a new Quaternion object from an + * existing quaternion, creating a copy. + * + * @param q the quaternion to copy. + */ + public Quaternion(Quaternion q) { + this.x = q.x; + this.y = q.y; + this.z = q.z; + this.w = q.w; + } + + /** + * sets the data in a Quaternion object from the given list of + * parameters. + * + * @param x the x value of the quaternion. + * @param y the y value of the quaternion. + * @param z the z value of the quaternion. + * @param w the w value of the quaternion. + */ + public void set(float x, float y, float z, float w) { + this.x = x; + this.y = y; + this.z = z; + this.w = w; + } + + /** + * Sets the data in this Quaternion object to be equal to the + * passed Quaternion object. The values are copied producing a + * new object. + * + * @param q The Quaternion to copy values from. + * @return this for chaining + */ + public Quaternion set(Quaternion q) { + this.x = q.x; + this.y = q.y; + this.z = q.z; + this.w = q.w; + return this; + } + + /** + * Sets this Quaternion to {0, 0, 0, 1}. Same as calling set(0,0,0,1). + */ + public void loadIdentity() { + x = y = z = 0; + w = 1; + } + + /** + * @return true if this Quaternion is {0,0,0,1} + */ + public boolean isIdentity() { return x == 0 && y == 0 && z == 0 && w == 1; - } - - /** - * fromAngles builds a quaternion from the Euler rotation - * angles (y,r,p). - * - * @param angles - * the Euler angles of rotation (in radians). - */ - public void fromAngles(float[] angles) { - if (angles.length != 3) - throw new IllegalArgumentException( - "Angles array must have three elements"); - - fromAngles(angles[0], angles[1], angles[2]); - } - - /** - * fromAngles builds a Quaternion from the Euler rotation - * angles (y,r,p). Note that we are applying in order: roll, pitch, yaw but - * we've ordered them in x, y, and z for convenience. See: - * http://www.euclideanspace - * .com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm - * - * @param yaw - * the Euler yaw of rotation (in radians). (aka Bank, often rot - * around x) - * @param roll - * the Euler roll of rotation (in radians). (aka Heading, often - * rot around y) - * @param pitch - * the Euler pitch of rotation (in radians). (aka Attitude, often - * rot around z) - */ - public Quaternion fromAngles(float yaw, float roll, float pitch) { - float angle; - float sinRoll, sinPitch, sinYaw, cosRoll, cosPitch, cosYaw; - angle = pitch * 0.5f; - sinPitch = FastMath.sin(angle); - cosPitch = FastMath.cos(angle); - angle = roll * 0.5f; - sinRoll = FastMath.sin(angle); - cosRoll = FastMath.cos(angle); - angle = yaw * 0.5f; - sinYaw = FastMath.sin(angle); - cosYaw = FastMath.cos(angle); - - // variables used to reduce multiplication calls. - float cosRollXcosPitch = cosRoll * cosPitch; - float sinRollXsinPitch = sinRoll * sinPitch; - float cosRollXsinPitch = cosRoll * sinPitch; - float sinRollXcosPitch = sinRoll * cosPitch; - - w = (cosRollXcosPitch * cosYaw - sinRollXsinPitch * sinYaw); - x = (cosRollXcosPitch * sinYaw + sinRollXsinPitch * cosYaw); - y = (sinRollXcosPitch * cosYaw + cosRollXsinPitch * sinYaw); - z = (cosRollXsinPitch * cosYaw - sinRollXcosPitch * sinYaw); - - normalize(); - return this; - } - - /** - * toAngles returns this quaternion converted to Euler rotation - * angles (yaw,roll,pitch).
- * See http://www.euclideanspace.com/maths/geometry/rotations/conversions/ - * quaternionToEuler/index.htm - * - * @param angles - * the float[] in which the angles should be stored, or null if - * you want a new float[] to be created - * @return the float[] in which the angles are stored. - */ - public float[] toAngles(float[] angles) { - if (angles == null) - angles = new float[3]; - else if (angles.length != 3) - throw new IllegalArgumentException( - "Angles array must have three elements"); - - float sqw = w * w; - float sqx = x * x; - float sqy = y * y; - float sqz = z * z; - float unit = sqx + sqy + sqz + sqw; // if normalized is one, otherwise - // is correction factor - float test = x * y + z * w; - if (test > 0.499 * unit) { // singularity at north pole - angles[1] = 2 * FastMath.atan2(x, w); - angles[2] = FastMath.HALF_PI; - angles[0] = 0; - } else if (test < -0.499 * unit) { // singularity at south pole - angles[1] = -2 * FastMath.atan2(x, w); - angles[2] = -FastMath.HALF_PI; - angles[0] = 0; - } else { - angles[1] = FastMath.atan2(2 * y * w - 2 * x * z, sqx - sqy - sqz - + sqw); // roll or heading - angles[2] = FastMath.asin(2 * test / unit); // pitch or attitude - angles[0] = FastMath.atan2(2 * x * w - 2 * y * z, -sqx + sqy - sqz - + sqw); // yaw or bank - } - return angles; - } - - /** - * - * fromRotationMatrix generates a quaternion from a supplied - * matrix. This matrix is assumed to be a rotational matrix. - * - * @param matrix - * the matrix that defines the rotation. - */ - public Quaternion fromRotationMatrix(Matrix3f matrix) { - return fromRotationMatrix(matrix.m00, matrix.m01, matrix.m02, - matrix.m10, matrix.m11, matrix.m12, matrix.m20, matrix.m21, - matrix.m22); - } - - public Quaternion fromRotationMatrix(float m00, float m01, float m02, - float m10, float m11, float m12, float m20, float m21, float m22) { - // Use the Graphics Gems code, from - // ftp://ftp.cis.upenn.edu/pub/graphics/shoemake/quatut.ps.Z - // *NOT* the "Matrix and Quaternions FAQ", which has errors! - - // the trace is the sum of the diagonal elements; see - // http://mathworld.wolfram.com/MatrixTrace.html - float t = m00 + m11 + m22; - - // we protect the division by s by ensuring that s>=1 - if (t >= 0) { // |w| >= .5 - float s = FastMath.sqrt(t + 1); // |s|>=1 ... - w = 0.5f * s; - s = 0.5f / s; // so this division isn't bad - x = (m21 - m12) * s; - y = (m02 - m20) * s; - z = (m10 - m01) * s; - } else if ((m00 > m11) && (m00 > m22)) { - float s = FastMath.sqrt(1.0f + m00 - m11 - m22); // |s|>=1 - x = s * 0.5f; // |x| >= .5 - s = 0.5f / s; - y = (m10 + m01) * s; - z = (m02 + m20) * s; - w = (m21 - m12) * s; - } else if (m11 > m22) { - float s = FastMath.sqrt(1.0f + m11 - m00 - m22); // |s|>=1 - y = s * 0.5f; // |y| >= .5 - s = 0.5f / s; - x = (m10 + m01) * s; - z = (m21 + m12) * s; - w = (m02 - m20) * s; - } else { - float s = FastMath.sqrt(1.0f + m22 - m00 - m11); // |s|>=1 - z = s * 0.5f; // |z| >= .5 - s = 0.5f / s; - x = (m02 + m20) * s; - y = (m21 + m12) * s; - w = (m10 - m01) * s; - } - - return this; - } - - /** - * toRotationMatrix converts this quaternion to a rotational - * matrix. Note: the result is created from a normalized version of this - * quat. - * - * @return the rotation matrix representation of this quaternion. - */ - public Matrix3f toRotationMatrix() { - Matrix3f matrix = new Matrix3f(); - return toRotationMatrix(matrix); - } - - /** - * toRotationMatrix converts this quaternion to a rotational - * matrix. The result is stored in result. - * - * @param result - * The Matrix3f to store the result in. - * @return the rotation matrix representation of this quaternion. - */ - public Matrix3f toRotationMatrix(Matrix3f result) { - - float norm = norm(); - // we explicitly test norm against one here, saving a division - // at the cost of a test and branch. Is it worth it? - float s = (norm == 1f) ? 2f : (norm > 0f) ? 2f / norm : 0; - - // compute xs/ys/zs first to save 6 multiplications, since xs/ys/zs - // will be used 2-4 times each. - float xs = x * s; - float ys = y * s; - float zs = z * s; - float xx = x * xs; - float xy = x * ys; - float xz = x * zs; - float xw = w * xs; - float yy = y * ys; - float yz = y * zs; - float yw = w * ys; - float zz = z * zs; - float zw = w * zs; - - // using s=2/norm (instead of 1/norm) saves 9 multiplications by 2 here - result.m00 = 1 - (yy + zz); - result.m01 = (xy - zw); - result.m02 = (xz + yw); - result.m10 = (xy + zw); - result.m11 = 1 - (xx + zz); - result.m12 = (yz - xw); - result.m20 = (xz - yw); - result.m21 = (yz + xw); - result.m22 = 1 - (xx + yy); - - return result; - } - - /** - * toRotationMatrix converts this quaternion to a rotational - * matrix. The result is stored in result. 4th row and 4th column values are - * untouched. Note: the result is created from a normalized version of this - * quat. - * - * @param result - * The Matrix4f to store the result in. - * @return the rotation matrix representation of this quaternion. - */ - public Matrix4f toRotationMatrix(Matrix4f result) { - - float norm = norm(); - // we explicitly test norm against one here, saving a division - // at the cost of a test and branch. Is it worth it? - float s = (norm == 1f) ? 2f : (norm > 0f) ? 2f / norm : 0; - - // compute xs/ys/zs first to save 6 multiplications, since xs/ys/zs - // will be used 2-4 times each. - float xs = x * s; - float ys = y * s; - float zs = z * s; - float xx = x * xs; - float xy = x * ys; - float xz = x * zs; - float xw = w * xs; - float yy = y * ys; - float yz = y * zs; - float yw = w * ys; - float zz = z * zs; - float zw = w * zs; - - // using s=2/norm (instead of 1/norm) saves 9 multiplications by 2 here - result.m00 = 1 - (yy + zz); - result.m01 = (xy - zw); - result.m02 = (xz + yw); - result.m10 = (xy + zw); - result.m11 = 1 - (xx + zz); - result.m12 = (yz - xw); - result.m20 = (xz - yw); - result.m21 = (yz + xw); - result.m22 = 1 - (xx + yy); - - return result; - } - - /** - * getRotationColumn returns one of three columns specified by - * the parameter. This column is returned as a Vector3f object. - * - * @param i - * the column to retrieve. Must be between 0 and 2. - * @return the column specified by the index. - * @throws Exception - */ - public Vector3f getRotationColumn(int i) throws Exception { - return getRotationColumn(i, null); - } - - /** - * getRotationColumn returns one of three columns specified by - * the parameter. This column is returned as a Vector3f object. - * The value is retrieved as if this quaternion was first normalized. - * - * @param i - * the column to retrieve. Must be between 0 and 2. - * @param store - * the vector object to store the result in. if null, a new one - * is created. - * @return the column specified by the index. - * @throws Exception - */ - public Vector3f getRotationColumn(int i, Vector3f store) throws Exception { - if (store == null) - store = new Vector3f(); - - float norm = norm(); - if (norm != 1.0f) { - norm = FastMath.invSqrt(norm); - } - - float xx = x * x * norm; - float xy = x * y * norm; - float xz = x * z * norm; - float xw = x * w * norm; - float yy = y * y * norm; - float yz = y * z * norm; - float yw = y * w * norm; - float zz = z * z * norm; - float zw = z * w * norm; - - switch (i) { - case 0: - store.x = 1 - 2 * (yy + zz); - store.y = 2 * (xy + zw); - store.z = 2 * (xz - yw); - break; - case 1: - store.x = 2 * (xy - zw); - store.y = 1 - 2 * (xx + zz); - store.z = 2 * (yz + xw); - break; - case 2: - store.x = 2 * (xz + yw); - store.y = 2 * (yz - xw); - store.z = 1 - 2 * (xx + yy); - break; - default: - throw new Exception("Invalid column index. " + i); - } - - return store; - } - - /** - * fromAngleAxis sets this quaternion to the values specified - * by an angle and an axis of rotation. This method creates an object, so - * use fromAngleNormalAxis if your axis is already normalized. - * - * @param angle - * the angle to rotate (in radians). - * @param axis - * the axis of rotation. - * @return this quaternion - */ - public Quaternion fromAngleAxis(float angle, Vector3f axis) { - Vector3f normAxis = axis.normalize(); - fromAngleNormalAxis(angle, normAxis); - return this; - } - - /** - * fromAngleNormalAxis sets this quaternion to the values - * specified by an angle and a normalized axis of rotation. - * - * @param angle - * the angle to rotate (in radians). - * @param axis - * the axis of rotation (already normalized). - */ - public Quaternion fromAngleNormalAxis(float angle, Vector3f axis) { - if (axis.x == 0 && axis.y == 0 && axis.z == 0) { - loadIdentity(); - } else { - float halfAngle = 0.5f * angle; - float sin = FastMath.sin(halfAngle); - w = FastMath.cos(halfAngle); - x = sin * axis.x; - y = sin * axis.y; - z = sin * axis.z; - } - return this; - } - - /** - * toAngleAxis sets a given angle and axis to that represented - * by the current quaternion. The values are stored as following: The axis - * is provided as a parameter and built by the method, the angle is returned - * as a float. - * - * @param axisStore - * the object we'll store the computed axis in. - * @return the angle of rotation in radians. - */ - public float toAngleAxis(Vector3f axisStore) { - float sqrLength = x * x + y * y + z * z; - float angle; - if (sqrLength == 0.0f) { - angle = 0.0f; - if (axisStore != null) { - axisStore.x = 1.0f; - axisStore.y = 0.0f; - axisStore.z = 0.0f; - } - } else { - angle = (2.0f * FastMath.acos(w)); - if (axisStore != null) { - float invLength = (1.0f / FastMath.sqrt(sqrLength)); - axisStore.x = x * invLength; - axisStore.y = y * invLength; - axisStore.z = z * invLength; - } - } - - return angle; - } - - /** - * slerp sets this quaternion's value as an interpolation - * between two other quaternions. - * - * @param q1 - * the first quaternion. - * @param q2 - * the second quaternion. - * @param t - * the amount to interpolate between the two quaternions. - */ - public Quaternion slerp(Quaternion q1, Quaternion q2, float t) { - // Create a local quaternion to store the interpolated quaternion - if (q1.x == q2.x && q1.y == q2.y && q1.z == q2.z && q1.w == q2.w) { - this.set(q1); - return this; - } - - float result = (q1.x * q2.x) + (q1.y * q2.y) + (q1.z * q2.z) - + (q1.w * q2.w); - - if (result < 0.0f) { - // Negate the second quaternion and the result of the dot product - q2.x = -q2.x; - q2.y = -q2.y; - q2.z = -q2.z; - q2.w = -q2.w; - result = -result; - } - - // Set the first and second scale for the interpolation - float scale0 = 1 - t; - float scale1 = t; - - // Check if the angle between the 2 quaternions was big enough to - // warrant such calculations - if ((1 - result) > 0.1f) {// Get the angle between the 2 quaternions, - // and then store the sin() of that angle - float theta = FastMath.acos(result); - float invSinTheta = 1f / FastMath.sin(theta); - - // Calculate the scale for q1 and q2, according to the angle and - // it's sine value - scale0 = FastMath.sin((1 - t) * theta) * invSinTheta; - scale1 = FastMath.sin((t * theta)) * invSinTheta; - } - - // Calculate the x, y, z and w values for the quaternion by using a - // special - // form of linear interpolation for quaternions. - this.x = (scale0 * q1.x) + (scale1 * q2.x); - this.y = (scale0 * q1.y) + (scale1 * q2.y); - this.z = (scale0 * q1.z) + (scale1 * q2.z); - this.w = (scale0 * q1.w) + (scale1 * q2.w); - - // Return the interpolated quaternion - return this; - } - - /** - * Sets the values of this quaternion to the slerp from itself to q2 by - * changeAmnt - * - * @param q2 - * Final interpolation value - * @param changeAmnt - * The amount difference - */ - public void slerp(Quaternion q2, float changeAmnt) { - if (this.x == q2.x && this.y == q2.y && this.z == q2.z - && this.w == q2.w) { - return; - } - - float result = (this.x * q2.x) + (this.y * q2.y) + (this.z * q2.z) - + (this.w * q2.w); - - if (result < 0.0f) { - // Negate the second quaternion and the result of the dot product - q2.x = -q2.x; - q2.y = -q2.y; - q2.z = -q2.z; - q2.w = -q2.w; - result = -result; - } - - // Set the first and second scale for the interpolation - float scale0 = 1 - changeAmnt; - float scale1 = changeAmnt; - - // Check if the angle between the 2 quaternions was big enough to - // warrant such calculations - if ((1 - result) > 0.1f) { - // Get the angle between the 2 quaternions, and then store the sin() - // of that angle - float theta = FastMath.acos(result); - float invSinTheta = 1f / FastMath.sin(theta); - - // Calculate the scale for q1 and q2, according to the angle and - // it's sine value - scale0 = FastMath.sin((1 - changeAmnt) * theta) * invSinTheta; - scale1 = FastMath.sin((changeAmnt * theta)) * invSinTheta; - } - - // Calculate the x, y, z and w values for the quaternion by using a - // special - // form of linear interpolation for quaternions. - this.x = (scale0 * this.x) + (scale1 * q2.x); - this.y = (scale0 * this.y) + (scale1 * q2.y); - this.z = (scale0 * this.z) + (scale1 * q2.z); - this.w = (scale0 * this.w) + (scale1 * q2.w); - } - - /** - * add adds the values of this quaternion to those of the - * parameter quaternion. The result is returned as a new quaternion. - * - * @param q - * the quaternion to add to this. - * @return the new quaternion. - */ - public Quaternion add(Quaternion q) { - return new Quaternion(x + q.x, y + q.y, z + q.z, w + q.w); - } - - /** - * add adds the values of this quaternion to those of the - * parameter quaternion. The result is stored in this Quaternion. - * - * @param q - * the quaternion to add to this. - * @return This Quaternion after addition. - */ - public Quaternion addLocal(Quaternion q) { - this.x += q.x; - this.y += q.y; - this.z += q.z; - this.w += q.w; - return this; - } - - /** - * subtract subtracts the values of the parameter quaternion - * from those of this quaternion. The result is returned as a new - * quaternion. - * - * @param q - * the quaternion to subtract from this. - * @return the new quaternion. - */ - public Quaternion subtract(Quaternion q) { - return new Quaternion(x - q.x, y - q.y, z - q.z, w - q.w); - } - - /** - * subtract subtracts the values of the parameter quaternion - * from those of this quaternion. The result is stored in this Quaternion. - * - * @param q - * the quaternion to subtract from this. - * @return This Quaternion after subtraction. - */ - public Quaternion subtractLocal(Quaternion q) { - this.x -= q.x; - this.y -= q.y; - this.z -= q.z; - this.w -= q.w; - return this; - } - - /** - * mult multiplies this quaternion by a parameter quaternion. - * The result is returned as a new quaternion. It should be noted that - * quaternion multiplication is not cummulative so q * p != p * q. - * - * @param q - * the quaternion to multiply this quaternion by. - * @return the new quaternion. - */ - public Quaternion mult(Quaternion q) { - return mult(q, null); - } - - /** - * mult multiplies this quaternion by a parameter quaternion - * (q). 'this' is not modified. It should be noted that quaternion - * multiplication is not cummulative so q * p != p * q. - * - * It IS safe for q and res to be the same object. - * - * @param q - * the quaternion to multiply this quaternion by. - * @param res - * the quaternion to store the result in (may be null). If - * non-null, the input values of 'res' will be ignored and - * replaced. - * @return If specified res is null, then a new Quaternion; otherwise - * returns the populated 'res'. - */ - public Quaternion mult(Quaternion q, Quaternion res) { - if (res == null) - res = new Quaternion(); - float qw = q.w, qx = q.x, qy = q.y, qz = q.z; - res.x = x * qw + y * qz - z * qy + w * qx; - res.y = -x * qz + y * qw + z * qx + w * qy; - res.z = x * qy - y * qx + z * qw + w * qz; - res.w = -x * qx - y * qy - z * qz + w * qw; - - float[] angles = new float[3]; - angles = res.toAngles(angles); - res.angleX = angles[0]; - res.angleY = angles[1]; - res.angleZ = angles[2]; - return res; - } - - /** - * apply multiplies this quaternion by a parameter matrix - * internally. - * - * @param matrix - * the matrix to apply to this quaternion. - */ - public void apply(Matrix3f matrix) { - float oldX = x, oldY = y, oldZ = z, oldW = w; - fromRotationMatrix(matrix); - float tempX = x, tempY = y, tempZ = z, tempW = w; - - x = oldX * tempW + oldY * tempZ - oldZ * tempY + oldW * tempX; - y = -oldX * tempZ + oldY * tempW + oldZ * tempX + oldW * tempY; - z = oldX * tempY - oldY * tempX + oldZ * tempW + oldW * tempZ; - w = -oldX * tempX - oldY * tempY - oldZ * tempZ + oldW * tempW; - } - - /** - * - * fromAxes creates a Quaternion that represents - * the coordinate system defined by three axes. These axes are assumed to be - * orthogonal and no error checking is applied. Thus, the user must insure - * that the three axes being provided indeed represents a proper right - * handed coordinate system. - * - * @param axis - * the array containing the three vectors representing the - * coordinate system. - */ - public Quaternion fromAxes(Vector3f[] axis) { - if (axis.length != 3) - throw new IllegalArgumentException( - "Axis array must have three elements"); - return fromAxes(axis[0], axis[1], axis[2]); - } - - /** - * - * fromAxes creates a Quaternion that represents - * the coordinate system defined by three axes. These axes are assumed to be - * orthogonal and no error checking is applied. Thus, the user must insure - * that the three axes being provided indeed represents a proper right - * handed coordinate system. - * - * @param xAxis - * vector representing the x-axis of the coordinate system. - * @param yAxis - * vector representing the y-axis of the coordinate system. - * @param zAxis - * vector representing the z-axis of the coordinate system. - */ - public Quaternion fromAxes(Vector3f xAxis, Vector3f yAxis, Vector3f zAxis) { - return fromRotationMatrix(xAxis.x, yAxis.x, zAxis.x, xAxis.y, yAxis.y, - zAxis.y, xAxis.z, yAxis.z, zAxis.z); - } - - /** - * - * toAxes takes in an array of three vectors. Each vector - * corresponds to an axis of the coordinate system defined by the quaternion - * rotation. - * - * @param axis - * the array of vectors to be filled. - * @throws Exception - */ - public void toAxes(Vector3f axis[]) throws Exception { - Matrix3f tempMat = toRotationMatrix(); - axis[0] = tempMat.getColumn(0, axis[0]); - axis[1] = tempMat.getColumn(1, axis[1]); - axis[2] = tempMat.getColumn(2, axis[2]); - } - - /** - * mult multiplies this quaternion by a parameter vector. The - * result is returned as a new vector. 'this' is not modified. - * - * @param v - * the vector to multiply this quaternion by. - * @return the new vector. - */ - public Vector3f mult(Vector3f v) { - return mult(v, null); - } - - /** - * mult multiplies this quaternion by a parameter vector. The - * result is stored in the supplied vector This method is very poorly named, - * since the specified vector is modified and, contrary to the other *Local - * methods in this and other jME classes, 'this' remains unchanged. - * - * @param v - * the vector which this Quaternion multiplies. - * @return v - */ - public Vector3f multLocal(Vector3f v) { - float tempX, tempY; - tempX = w * w * v.x + 2 * y * w * v.z - 2 * z * w * v.y + x * x * v.x - + 2 * y * x * v.y + 2 * z * x * v.z - z * z * v.x - y * y * v.x; - tempY = 2 * x * y * v.x + y * y * v.y + 2 * z * y * v.z + 2 * w * z - * v.x - z * z * v.y + w * w * v.y - 2 * x * w * v.z - x * x - * v.y; - v.z = 2 * x * z * v.x + 2 * y * z * v.y + z * z * v.z - 2 * w * y * v.x - - y * y * v.z + 2 * w * x * v.y - x * x * v.z + w * w * v.z; - v.x = tempX; - v.y = tempY; - return v; - } - - /** - * Multiplies this Quaternion by the supplied quaternion. The result is - * stored in this Quaternion, which is also returned for chaining. Similar - * to this *= q. - * - * @param q - * The Quaternion to multiply this one by. - * @return This Quaternion, after multiplication. - */ - public Quaternion multLocal(Quaternion q) { - float x1 = x * q.w + y * q.z - z * q.y + w * q.x; - float y1 = -x * q.z + y * q.w + z * q.x + w * q.y; - float z1 = x * q.y - y * q.x + z * q.w + w * q.z; - w = -x * q.x - y * q.y - z * q.z + w * q.w; - x = x1; - y = y1; - z = z1; - return this; - } - - /** - * Multiplies this Quaternion by the supplied quaternion. The result is - * stored in this Quaternion, which is also returned for chaining. Similar - * to this *= q. - * - * @param qx - * - quat x value - * @param qy - * - quat y value - * @param qz - * - quat z value - * @param qw - * - quat w value - * - * @return This Quaternion, after multiplication. - */ - public Quaternion multLocal(float qx, float qy, float qz, float qw) { - float x1 = x * qw + y * qz - z * qy + w * qx; - float y1 = -x * qz + y * qw + z * qx + w * qy; - float z1 = x * qy - y * qx + z * qw + w * qz; - w = -x * qx - y * qy - z * qz + w * qw; - x = x1; - y = y1; - z = z1; - return this; - } - - /** - * mult multiplies this quaternion by a parameter vector. The - * result is returned as a new vector. 'this' is not modified. - * - * @param v - * the vector to multiply this quaternion by. - * @param store - * the vector to store the result in. It IS safe for v and store - * to be the same object. - * @return the result vector. - */ - public Vector3f mult(Vector3f v, Vector3f store) { - if (store == null) - store = new Vector3f(); - if (v.x == 0 && v.y == 0 && v.z == 0) { - store.set(0, 0, 0); - } else { - float vx = v.x, vy = v.y, vz = v.z; - store.x = w * w * vx + 2 * y * w * vz - 2 * z * w * vy + x * x * vx - + 2 * y * x * vy + 2 * z * x * vz - z * z * vx - y * y * vx; - store.y = 2 * x * y * vx + y * y * vy + 2 * z * y * vz + 2 * w * z - * vx - z * z * vy + w * w * vy - 2 * x * w * vz - x * x - * vy; - store.z = 2 * x * z * vx + 2 * y * z * vy + z * z * vz - 2 * w * y - * vx - y * y * vz + 2 * w * x * vy - x * x * vz + w * w - * vz; - } - return store; - } - - /** - * mult multiplies this quaternion by a parameter scalar. The - * result is returned as a new quaternion. - * - * @param scalar - * the quaternion to multiply this quaternion by. - * @return the new quaternion. - */ - public Quaternion mult(float scalar) { - return new Quaternion(scalar * x, scalar * y, scalar * z, scalar * w); - } - - /** - * mult multiplies this quaternion by a parameter scalar. The - * result is stored locally. - * - * @param scalar - * the quaternion to multiply this quaternion by. - * @return this. - */ - public Quaternion multLocal(float scalar) { - w *= scalar; - x *= scalar; - y *= scalar; - z *= scalar; - return this; - } - - /** - * dot calculates and returns the dot product of this - * quaternion with that of the parameter quaternion. - * - * @param q - * the quaternion to calculate the dot product of. - * @return the dot product of this and the parameter quaternion. - */ - public float dot(Quaternion q) { - return w * q.w + x * q.x + y * q.y + z * q.z; - } - - /** - * norm returns the norm of this quaternion. This is the dot - * product of this quaternion with itself. - * - * @return the norm of the quaternion. - */ - public float norm() { - return w * w + x * x + y * y + z * z; - } - - /** - * normalize normalizes the current Quaternion - */ - public void normalize() { - float n = FastMath.invSqrt(norm()); - x *= n; - y *= n; - z *= n; - w *= n; - } - - /** - * inverse returns the inverse of this quaternion as a new - * quaternion. If this quaternion does not have an inverse (if its normal is - * 0 or less), then null is returned. - * - * @return the inverse of this quaternion or null if the inverse does not - * exist. - */ - public Quaternion inverse() { - float norm = norm(); - if (norm > 0.0) { - float invNorm = 1.0f / norm; - return new Quaternion(-x * invNorm, -y * invNorm, -z * invNorm, w - * invNorm); - } - // return an invalid result to flag the error - return null; - } - - /** - * inverse calculates the inverse of this quaternion and - * returns this quaternion after it is calculated. If this quaternion does - * not have an inverse (if it's norma is 0 or less), nothing happens - * - * @return the inverse of this quaternion - */ - public Quaternion inverseLocal() { - float norm = norm(); - if (norm > 0.0) { - float invNorm = 1.0f / norm; - x *= -invNorm; - y *= -invNorm; - z *= -invNorm; - w *= invNorm; - } - return this; - } - - /** - * negate inverts the values of the quaternion. - * - */ - public void negate() { - x *= -1; - y *= -1; - z *= -1; - w *= -1; - } - - /** - * equals determines if two quaternions are logically equal, - * that is, if the values of (x, y, z, w) are the same for both quaternions. - * - * @param o - * the object to compare for equality - * @return true if they are equal, false otherwise. - */ - @Override - public boolean equals(Object o) { - if (!(o instanceof Quaternion)) { - return false; - } - - if (this == o) { - return true; - } - - Quaternion comp = (Quaternion) o; - if (Float.compare(x, comp.x) != 0) - return false; - if (Float.compare(y, comp.y) != 0) - return false; - if (Float.compare(z, comp.z) != 0) - return false; + } + + /** + * fromAngles builds a quaternion from the Euler rotation + * angles (y,r,p). + * + * @param angles the Euler angles of rotation (in radians). + */ + public void fromAngles(float[] angles) { + if (angles.length != 3) + throw new IllegalArgumentException( + "Angles array must have three elements"); + + fromAngles(angles[0], angles[1], angles[2]); + } + + /** + * fromAngles builds a Quaternion from the Euler rotation + * angles (y,r,p). Note that we are applying in order: roll, pitch, yaw but + * we've ordered them in x, y, and z for convenience. See: + * http://www.euclideanspace + * .com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm + * + * @param yaw the Euler yaw of rotation (in radians). (aka Bank, often rot + * around x) + * @param roll the Euler roll of rotation (in radians). (aka Heading, often + * rot around y) + * @param pitch the Euler pitch of rotation (in radians). (aka Attitude, often + * rot around z) + */ + public Quaternion fromAngles(float yaw, float roll, float pitch) { + float angle; + float sinRoll, sinPitch, sinYaw, cosRoll, cosPitch, cosYaw; + angle = pitch * 0.5f; + sinPitch = FastMath.sin(angle); + cosPitch = FastMath.cos(angle); + angle = roll * 0.5f; + sinRoll = FastMath.sin(angle); + cosRoll = FastMath.cos(angle); + angle = yaw * 0.5f; + sinYaw = FastMath.sin(angle); + cosYaw = FastMath.cos(angle); + + // variables used to reduce multiplication calls. + float cosRollXcosPitch = cosRoll * cosPitch; + float sinRollXsinPitch = sinRoll * sinPitch; + float cosRollXsinPitch = cosRoll * sinPitch; + float sinRollXcosPitch = sinRoll * cosPitch; + + w = (cosRollXcosPitch * cosYaw - sinRollXsinPitch * sinYaw); + x = (cosRollXcosPitch * sinYaw + sinRollXsinPitch * cosYaw); + y = (sinRollXcosPitch * cosYaw + cosRollXsinPitch * sinYaw); + z = (cosRollXsinPitch * cosYaw - sinRollXcosPitch * sinYaw); + + normalize(); + return this; + } + + /** + * toAngles returns this quaternion converted to Euler rotation + * angles (yaw,roll,pitch).
+ * See http://www.euclideanspace.com/maths/geometry/rotations/conversions/ + * quaternionToEuler/index.htm + * + * @param angles the float[] in which the angles should be stored, or null if + * you want a new float[] to be created + * @return the float[] in which the angles are stored. + */ + public float[] toAngles(float[] angles) { + if (angles == null) + angles = new float[3]; + else if (angles.length != 3) + throw new IllegalArgumentException( + "Angles array must have three elements"); + + float sqw = w * w; + float sqx = x * x; + float sqy = y * y; + float sqz = z * z; + float unit = sqx + sqy + sqz + sqw; // if normalized is one, otherwise + // is correction factor + float test = x * y + z * w; + if (test > 0.499 * unit) { // singularity at north pole + angles[1] = 2 * FastMath.atan2(x, w); + angles[2] = FastMath.HALF_PI; + angles[0] = 0; + } else if (test < -0.499 * unit) { // singularity at south pole + angles[1] = -2 * FastMath.atan2(x, w); + angles[2] = -FastMath.HALF_PI; + angles[0] = 0; + } else { + angles[1] = FastMath.atan2(2 * y * w - 2 * x * z, sqx - sqy - sqz + + sqw); // roll or heading + angles[2] = FastMath.asin(2 * test / unit); // pitch or attitude + angles[0] = FastMath.atan2(2 * x * w - 2 * y * z, -sqx + sqy - sqz + + sqw); // yaw or bank + } + return angles; + } + + /** + * fromRotationMatrix generates a quaternion from a supplied + * matrix. This matrix is assumed to be a rotational matrix. + * + * @param matrix the matrix that defines the rotation. + */ + public Quaternion fromRotationMatrix(Matrix3f matrix) { + return fromRotationMatrix(matrix.m00, matrix.m01, matrix.m02, + matrix.m10, matrix.m11, matrix.m12, matrix.m20, matrix.m21, + matrix.m22); + } + + public Quaternion fromRotationMatrix(float m00, float m01, float m02, + float m10, float m11, float m12, float m20, float m21, float m22) { + // Use the Graphics Gems code, from + // ftp://ftp.cis.upenn.edu/pub/graphics/shoemake/quatut.ps.Z + // *NOT* the "Matrix and Quaternions FAQ", which has errors! + + // the trace is the sum of the diagonal elements; see + // http://mathworld.wolfram.com/MatrixTrace.html + float t = m00 + m11 + m22; + + // we protect the division by s by ensuring that s>=1 + if (t >= 0) { // |w| >= .5 + float s = FastMath.sqrt(t + 1); // |s|>=1 ... + w = 0.5f * s; + s = 0.5f / s; // so this division isn't bad + x = (m21 - m12) * s; + y = (m02 - m20) * s; + z = (m10 - m01) * s; + } else if ((m00 > m11) && (m00 > m22)) { + float s = FastMath.sqrt(1.0f + m00 - m11 - m22); // |s|>=1 + x = s * 0.5f; // |x| >= .5 + s = 0.5f / s; + y = (m10 + m01) * s; + z = (m02 + m20) * s; + w = (m21 - m12) * s; + } else if (m11 > m22) { + float s = FastMath.sqrt(1.0f + m11 - m00 - m22); // |s|>=1 + y = s * 0.5f; // |y| >= .5 + s = 0.5f / s; + x = (m10 + m01) * s; + z = (m21 + m12) * s; + w = (m02 - m20) * s; + } else { + float s = FastMath.sqrt(1.0f + m22 - m00 - m11); // |s|>=1 + z = s * 0.5f; // |z| >= .5 + s = 0.5f / s; + x = (m02 + m20) * s; + y = (m21 + m12) * s; + w = (m10 - m01) * s; + } + + return this; + } + + /** + * toRotationMatrix converts this quaternion to a rotational + * matrix. Note: the result is created from a normalized version of this + * quat. + * + * @return the rotation matrix representation of this quaternion. + */ + public Matrix3f toRotationMatrix() { + Matrix3f matrix = new Matrix3f(); + return toRotationMatrix(matrix); + } + + /** + * toRotationMatrix converts this quaternion to a rotational + * matrix. The result is stored in result. + * + * @param result The Matrix3f to store the result in. + * @return the rotation matrix representation of this quaternion. + */ + public Matrix3f toRotationMatrix(Matrix3f result) { + + float norm = norm(); + // we explicitly test norm against one here, saving a division + // at the cost of a test and branch. Is it worth it? + float s = (norm == 1f) ? 2f : (norm > 0f) ? 2f / norm : 0; + + // compute xs/ys/zs first to save 6 multiplications, since xs/ys/zs + // will be used 2-4 times each. + float xs = x * s; + float ys = y * s; + float zs = z * s; + float xx = x * xs; + float xy = x * ys; + float xz = x * zs; + float xw = w * xs; + float yy = y * ys; + float yz = y * zs; + float yw = w * ys; + float zz = z * zs; + float zw = w * zs; + + // using s=2/norm (instead of 1/norm) saves 9 multiplications by 2 here + result.m00 = 1 - (yy + zz); + result.m01 = (xy - zw); + result.m02 = (xz + yw); + result.m10 = (xy + zw); + result.m11 = 1 - (xx + zz); + result.m12 = (yz - xw); + result.m20 = (xz - yw); + result.m21 = (yz + xw); + result.m22 = 1 - (xx + yy); + + return result; + } + + /** + * toRotationMatrix converts this quaternion to a rotational + * matrix. The result is stored in result. 4th row and 4th column values are + * untouched. Note: the result is created from a normalized version of this + * quat. + * + * @param result The Matrix4f to store the result in. + * @return the rotation matrix representation of this quaternion. + */ + public Matrix4f toRotationMatrix(Matrix4f result) { + + float norm = norm(); + // we explicitly test norm against one here, saving a division + // at the cost of a test and branch. Is it worth it? + float s = (norm == 1f) ? 2f : (norm > 0f) ? 2f / norm : 0; + + // compute xs/ys/zs first to save 6 multiplications, since xs/ys/zs + // will be used 2-4 times each. + float xs = x * s; + float ys = y * s; + float zs = z * s; + float xx = x * xs; + float xy = x * ys; + float xz = x * zs; + float xw = w * xs; + float yy = y * ys; + float yz = y * zs; + float yw = w * ys; + float zz = z * zs; + float zw = w * zs; + + // using s=2/norm (instead of 1/norm) saves 9 multiplications by 2 here + result.m00 = 1 - (yy + zz); + result.m01 = (xy - zw); + result.m02 = (xz + yw); + result.m10 = (xy + zw); + result.m11 = 1 - (xx + zz); + result.m12 = (yz - xw); + result.m20 = (xz - yw); + result.m21 = (yz + xw); + result.m22 = 1 - (xx + yy); + + return result; + } + + /** + * getRotationColumn returns one of three columns specified by + * the parameter. This column is returned as a Vector3f object. + * + * @param i the column to retrieve. Must be between 0 and 2. + * @return the column specified by the index. + * @throws Exception + */ + public Vector3f getRotationColumn(int i) throws Exception { + return getRotationColumn(i, null); + } + + /** + * getRotationColumn returns one of three columns specified by + * the parameter. This column is returned as a Vector3f object. + * The value is retrieved as if this quaternion was first normalized. + * + * @param i the column to retrieve. Must be between 0 and 2. + * @param store the vector object to store the result in. if null, a new one + * is created. + * @return the column specified by the index. + * @throws Exception + */ + public Vector3f getRotationColumn(int i, Vector3f store) throws Exception { + if (store == null) + store = new Vector3f(); + + float norm = norm(); + if (norm != 1.0f) { + norm = FastMath.invSqrt(norm); + } + + float xx = x * x * norm; + float xy = x * y * norm; + float xz = x * z * norm; + float xw = x * w * norm; + float yy = y * y * norm; + float yz = y * z * norm; + float yw = y * w * norm; + float zz = z * z * norm; + float zw = z * w * norm; + + switch (i) { + case 0: + store.x = 1 - 2 * (yy + zz); + store.y = 2 * (xy + zw); + store.z = 2 * (xz - yw); + break; + case 1: + store.x = 2 * (xy - zw); + store.y = 1 - 2 * (xx + zz); + store.z = 2 * (yz + xw); + break; + case 2: + store.x = 2 * (xz + yw); + store.y = 2 * (yz - xw); + store.z = 1 - 2 * (xx + yy); + break; + default: + throw new Exception("Invalid column index. " + i); + } + + return store; + } + + /** + * fromAngleAxis sets this quaternion to the values specified + * by an angle and an axis of rotation. This method creates an object, so + * use fromAngleNormalAxis if your axis is already normalized. + * + * @param angle the angle to rotate (in radians). + * @param axis the axis of rotation. + * @return this quaternion + */ + public Quaternion fromAngleAxis(float angle, Vector3f axis) { + Vector3f normAxis = axis.normalize(); + fromAngleNormalAxis(angle, normAxis); + return this; + } + + /** + * fromAngleNormalAxis sets this quaternion to the values + * specified by an angle and a normalized axis of rotation. + * + * @param angle the angle to rotate (in radians). + * @param axis the axis of rotation (already normalized). + */ + public Quaternion fromAngleNormalAxis(float angle, Vector3f axis) { + if (axis.x == 0 && axis.y == 0 && axis.z == 0) { + loadIdentity(); + } else { + float halfAngle = 0.5f * angle; + float sin = FastMath.sin(halfAngle); + w = FastMath.cos(halfAngle); + x = sin * axis.x; + y = sin * axis.y; + z = sin * axis.z; + } + return this; + } + + /** + * toAngleAxis sets a given angle and axis to that represented + * by the current quaternion. The values are stored as following: The axis + * is provided as a parameter and built by the method, the angle is returned + * as a float. + * + * @param axisStore the object we'll store the computed axis in. + * @return the angle of rotation in radians. + */ + public float toAngleAxis(Vector3f axisStore) { + float sqrLength = x * x + y * y + z * z; + float angle; + if (sqrLength == 0.0f) { + angle = 0.0f; + if (axisStore != null) { + axisStore.x = 1.0f; + axisStore.y = 0.0f; + axisStore.z = 0.0f; + } + } else { + angle = (2.0f * FastMath.acos(w)); + if (axisStore != null) { + float invLength = (1.0f / FastMath.sqrt(sqrLength)); + axisStore.x = x * invLength; + axisStore.y = y * invLength; + axisStore.z = z * invLength; + } + } + + return angle; + } + + /** + * slerp sets this quaternion's value as an interpolation + * between two other quaternions. + * + * @param q1 the first quaternion. + * @param q2 the second quaternion. + * @param t the amount to interpolate between the two quaternions. + */ + public Quaternion slerp(Quaternion q1, Quaternion q2, float t) { + // Create a local quaternion to store the interpolated quaternion + if (q1.x == q2.x && q1.y == q2.y && q1.z == q2.z && q1.w == q2.w) { + this.set(q1); + return this; + } + + float result = (q1.x * q2.x) + (q1.y * q2.y) + (q1.z * q2.z) + + (q1.w * q2.w); + + if (result < 0.0f) { + // Negate the second quaternion and the result of the dot product + q2.x = -q2.x; + q2.y = -q2.y; + q2.z = -q2.z; + q2.w = -q2.w; + result = -result; + } + + // Set the first and second scale for the interpolation + float scale0 = 1 - t; + float scale1 = t; + + // Check if the angle between the 2 quaternions was big enough to + // warrant such calculations + if ((1 - result) > 0.1f) {// Get the angle between the 2 quaternions, + // and then store the sin() of that angle + float theta = FastMath.acos(result); + float invSinTheta = 1f / FastMath.sin(theta); + + // Calculate the scale for q1 and q2, according to the angle and + // it's sine value + scale0 = FastMath.sin((1 - t) * theta) * invSinTheta; + scale1 = FastMath.sin((t * theta)) * invSinTheta; + } + + // Calculate the x, y, z and w values for the quaternion by using a + // special + // form of linear interpolation for quaternions. + this.x = (scale0 * q1.x) + (scale1 * q2.x); + this.y = (scale0 * q1.y) + (scale1 * q2.y); + this.z = (scale0 * q1.z) + (scale1 * q2.z); + this.w = (scale0 * q1.w) + (scale1 * q2.w); + + // Return the interpolated quaternion + return this; + } + + /** + * Sets the values of this quaternion to the slerp from itself to q2 by + * changeAmnt + * + * @param q2 Final interpolation value + * @param changeAmnt The amount difference + */ + public void slerp(Quaternion q2, float changeAmnt) { + if (this.x == q2.x && this.y == q2.y && this.z == q2.z + && this.w == q2.w) { + return; + } + + float result = (this.x * q2.x) + (this.y * q2.y) + (this.z * q2.z) + + (this.w * q2.w); + + if (result < 0.0f) { + // Negate the second quaternion and the result of the dot product + q2.x = -q2.x; + q2.y = -q2.y; + q2.z = -q2.z; + q2.w = -q2.w; + result = -result; + } + + // Set the first and second scale for the interpolation + float scale0 = 1 - changeAmnt; + float scale1 = changeAmnt; + + // Check if the angle between the 2 quaternions was big enough to + // warrant such calculations + if ((1 - result) > 0.1f) { + // Get the angle between the 2 quaternions, and then store the sin() + // of that angle + float theta = FastMath.acos(result); + float invSinTheta = 1f / FastMath.sin(theta); + + // Calculate the scale for q1 and q2, according to the angle and + // it's sine value + scale0 = FastMath.sin((1 - changeAmnt) * theta) * invSinTheta; + scale1 = FastMath.sin((changeAmnt * theta)) * invSinTheta; + } + + // Calculate the x, y, z and w values for the quaternion by using a + // special + // form of linear interpolation for quaternions. + this.x = (scale0 * this.x) + (scale1 * q2.x); + this.y = (scale0 * this.y) + (scale1 * q2.y); + this.z = (scale0 * this.z) + (scale1 * q2.z); + this.w = (scale0 * this.w) + (scale1 * q2.w); + } + + /** + * add adds the values of this quaternion to those of the + * parameter quaternion. The result is returned as a new quaternion. + * + * @param q the quaternion to add to this. + * @return the new quaternion. + */ + public Quaternion add(Quaternion q) { + return new Quaternion(x + q.x, y + q.y, z + q.z, w + q.w); + } + + /** + * add adds the values of this quaternion to those of the + * parameter quaternion. The result is stored in this Quaternion. + * + * @param q the quaternion to add to this. + * @return This Quaternion after addition. + */ + public Quaternion addLocal(Quaternion q) { + this.x += q.x; + this.y += q.y; + this.z += q.z; + this.w += q.w; + return this; + } + + /** + * subtract subtracts the values of the parameter quaternion + * from those of this quaternion. The result is returned as a new + * quaternion. + * + * @param q the quaternion to subtract from this. + * @return the new quaternion. + */ + public Quaternion subtract(Quaternion q) { + return new Quaternion(x - q.x, y - q.y, z - q.z, w - q.w); + } + + /** + * subtract subtracts the values of the parameter quaternion + * from those of this quaternion. The result is stored in this Quaternion. + * + * @param q the quaternion to subtract from this. + * @return This Quaternion after subtraction. + */ + public Quaternion subtractLocal(Quaternion q) { + this.x -= q.x; + this.y -= q.y; + this.z -= q.z; + this.w -= q.w; + return this; + } + + /** + * mult multiplies this quaternion by a parameter quaternion. + * The result is returned as a new quaternion. It should be noted that + * quaternion multiplication is not cummulative so q * p != p * q. + * + * @param q the quaternion to multiply this quaternion by. + * @return the new quaternion. + */ + public Quaternion mult(Quaternion q) { + return mult(q, null); + } + + /** + * mult multiplies this quaternion by a parameter quaternion + * (q). 'this' is not modified. It should be noted that quaternion + * multiplication is not cummulative so q * p != p * q. + *

+ * It IS safe for q and res to be the same object. + * + * @param q the quaternion to multiply this quaternion by. + * @param res the quaternion to store the result in (may be null). If + * non-null, the input values of 'res' will be ignored and + * replaced. + * @return If specified res is null, then a new Quaternion; otherwise + * returns the populated 'res'. + */ + public Quaternion mult(Quaternion q, Quaternion res) { + if (res == null) + res = new Quaternion(); + float qw = q.w, qx = q.x, qy = q.y, qz = q.z; + res.x = x * qw + y * qz - z * qy + w * qx; + res.y = -x * qz + y * qw + z * qx + w * qy; + res.z = x * qy - y * qx + z * qw + w * qz; + res.w = -x * qx - y * qy - z * qz + w * qw; + + float[] angles = new float[3]; + angles = res.toAngles(angles); + res.angleX = angles[0]; + res.angleY = angles[1]; + res.angleZ = angles[2]; + return res; + } + + /** + * apply multiplies this quaternion by a parameter matrix + * internally. + * + * @param matrix the matrix to apply to this quaternion. + */ + public void apply(Matrix3f matrix) { + float oldX = x, oldY = y, oldZ = z, oldW = w; + fromRotationMatrix(matrix); + float tempX = x, tempY = y, tempZ = z, tempW = w; + + x = oldX * tempW + oldY * tempZ - oldZ * tempY + oldW * tempX; + y = -oldX * tempZ + oldY * tempW + oldZ * tempX + oldW * tempY; + z = oldX * tempY - oldY * tempX + oldZ * tempW + oldW * tempZ; + w = -oldX * tempX - oldY * tempY - oldZ * tempZ + oldW * tempW; + } + + /** + * fromAxes creates a Quaternion that represents + * the coordinate system defined by three axes. These axes are assumed to be + * orthogonal and no error checking is applied. Thus, the user must insure + * that the three axes being provided indeed represents a proper right + * handed coordinate system. + * + * @param axis the array containing the three vectors representing the + * coordinate system. + */ + public Quaternion fromAxes(Vector3f[] axis) { + if (axis.length != 3) + throw new IllegalArgumentException( + "Axis array must have three elements"); + return fromAxes(axis[0], axis[1], axis[2]); + } + + /** + * fromAxes creates a Quaternion that represents + * the coordinate system defined by three axes. These axes are assumed to be + * orthogonal and no error checking is applied. Thus, the user must insure + * that the three axes being provided indeed represents a proper right + * handed coordinate system. + * + * @param xAxis vector representing the x-axis of the coordinate system. + * @param yAxis vector representing the y-axis of the coordinate system. + * @param zAxis vector representing the z-axis of the coordinate system. + */ + public Quaternion fromAxes(Vector3f xAxis, Vector3f yAxis, Vector3f zAxis) { + return fromRotationMatrix(xAxis.x, yAxis.x, zAxis.x, xAxis.y, yAxis.y, + zAxis.y, xAxis.z, yAxis.z, zAxis.z); + } + + /** + * toAxes takes in an array of three vectors. Each vector + * corresponds to an axis of the coordinate system defined by the quaternion + * rotation. + * + * @param axis the array of vectors to be filled. + * @throws Exception + */ + public void toAxes(Vector3f axis[]) throws Exception { + Matrix3f tempMat = toRotationMatrix(); + axis[0] = tempMat.getColumn(0, axis[0]); + axis[1] = tempMat.getColumn(1, axis[1]); + axis[2] = tempMat.getColumn(2, axis[2]); + } + + /** + * mult multiplies this quaternion by a parameter vector. The + * result is returned as a new vector. 'this' is not modified. + * + * @param v the vector to multiply this quaternion by. + * @return the new vector. + */ + public Vector3f mult(Vector3f v) { + return mult(v, null); + } + + /** + * mult multiplies this quaternion by a parameter vector. The + * result is stored in the supplied vector This method is very poorly named, + * since the specified vector is modified and, contrary to the other *Local + * methods in this and other jME classes, 'this' remains unchanged. + * + * @param v the vector which this Quaternion multiplies. + * @return v + */ + public Vector3f multLocal(Vector3f v) { + float tempX, tempY; + tempX = w * w * v.x + 2 * y * w * v.z - 2 * z * w * v.y + x * x * v.x + + 2 * y * x * v.y + 2 * z * x * v.z - z * z * v.x - y * y * v.x; + tempY = 2 * x * y * v.x + y * y * v.y + 2 * z * y * v.z + 2 * w * z + * v.x - z * z * v.y + w * w * v.y - 2 * x * w * v.z - x * x + * v.y; + v.z = 2 * x * z * v.x + 2 * y * z * v.y + z * z * v.z - 2 * w * y * v.x + - y * y * v.z + 2 * w * x * v.y - x * x * v.z + w * w * v.z; + v.x = tempX; + v.y = tempY; + return v; + } + + /** + * Multiplies this Quaternion by the supplied quaternion. The result is + * stored in this Quaternion, which is also returned for chaining. Similar + * to this *= q. + * + * @param q The Quaternion to multiply this one by. + * @return This Quaternion, after multiplication. + */ + public Quaternion multLocal(Quaternion q) { + float x1 = x * q.w + y * q.z - z * q.y + w * q.x; + float y1 = -x * q.z + y * q.w + z * q.x + w * q.y; + float z1 = x * q.y - y * q.x + z * q.w + w * q.z; + w = -x * q.x - y * q.y - z * q.z + w * q.w; + x = x1; + y = y1; + z = z1; + return this; + } + + /** + * Multiplies this Quaternion by the supplied quaternion. The result is + * stored in this Quaternion, which is also returned for chaining. Similar + * to this *= q. + * + * @param qx - quat x value + * @param qy - quat y value + * @param qz - quat z value + * @param qw - quat w value + * @return This Quaternion, after multiplication. + */ + public Quaternion multLocal(float qx, float qy, float qz, float qw) { + float x1 = x * qw + y * qz - z * qy + w * qx; + float y1 = -x * qz + y * qw + z * qx + w * qy; + float z1 = x * qy - y * qx + z * qw + w * qz; + w = -x * qx - y * qy - z * qz + w * qw; + x = x1; + y = y1; + z = z1; + return this; + } + + /** + * mult multiplies this quaternion by a parameter vector. The + * result is returned as a new vector. 'this' is not modified. + * + * @param v the vector to multiply this quaternion by. + * @param store the vector to store the result in. It IS safe for v and store + * to be the same object. + * @return the result vector. + */ + public Vector3f mult(Vector3f v, Vector3f store) { + if (store == null) + store = new Vector3f(); + if (v.x == 0 && v.y == 0 && v.z == 0) { + store.set(0, 0, 0); + } else { + float vx = v.x, vy = v.y, vz = v.z; + store.x = w * w * vx + 2 * y * w * vz - 2 * z * w * vy + x * x * vx + + 2 * y * x * vy + 2 * z * x * vz - z * z * vx - y * y * vx; + store.y = 2 * x * y * vx + y * y * vy + 2 * z * y * vz + 2 * w * z + * vx - z * z * vy + w * w * vy - 2 * x * w * vz - x * x + * vy; + store.z = 2 * x * z * vx + 2 * y * z * vy + z * z * vz - 2 * w * y + * vx - y * y * vz + 2 * w * x * vy - x * x * vz + w * w + * vz; + } + return store; + } + + /** + * mult multiplies this quaternion by a parameter scalar. The + * result is returned as a new quaternion. + * + * @param scalar the quaternion to multiply this quaternion by. + * @return the new quaternion. + */ + public Quaternion mult(float scalar) { + return new Quaternion(scalar * x, scalar * y, scalar * z, scalar * w); + } + + /** + * mult multiplies this quaternion by a parameter scalar. The + * result is stored locally. + * + * @param scalar the quaternion to multiply this quaternion by. + * @return this. + */ + public Quaternion multLocal(float scalar) { + w *= scalar; + x *= scalar; + y *= scalar; + z *= scalar; + return this; + } + + /** + * dot calculates and returns the dot product of this + * quaternion with that of the parameter quaternion. + * + * @param q the quaternion to calculate the dot product of. + * @return the dot product of this and the parameter quaternion. + */ + public float dot(Quaternion q) { + return w * q.w + x * q.x + y * q.y + z * q.z; + } + + /** + * norm returns the norm of this quaternion. This is the dot + * product of this quaternion with itself. + * + * @return the norm of the quaternion. + */ + public float norm() { + return w * w + x * x + y * y + z * z; + } + + /** + * normalize normalizes the current Quaternion + */ + public void normalize() { + float n = FastMath.invSqrt(norm()); + x *= n; + y *= n; + z *= n; + w *= n; + } + + /** + * inverse returns the inverse of this quaternion as a new + * quaternion. If this quaternion does not have an inverse (if its normal is + * 0 or less), then null is returned. + * + * @return the inverse of this quaternion or null if the inverse does not + * exist. + */ + public Quaternion inverse() { + float norm = norm(); + if (norm > 0.0) { + float invNorm = 1.0f / norm; + return new Quaternion(-x * invNorm, -y * invNorm, -z * invNorm, w + * invNorm); + } + // return an invalid result to flag the error + return null; + } + + /** + * inverse calculates the inverse of this quaternion and + * returns this quaternion after it is calculated. If this quaternion does + * not have an inverse (if it's norma is 0 or less), nothing happens + * + * @return the inverse of this quaternion + */ + public Quaternion inverseLocal() { + float norm = norm(); + if (norm > 0.0) { + float invNorm = 1.0f / norm; + x *= -invNorm; + y *= -invNorm; + z *= -invNorm; + w *= invNorm; + } + return this; + } + + /** + * negate inverts the values of the quaternion. + */ + public void negate() { + x *= -1; + y *= -1; + z *= -1; + w *= -1; + } + + /** + * equals determines if two quaternions are logically equal, + * that is, if the values of (x, y, z, w) are the same for both quaternions. + * + * @param o the object to compare for equality + * @return true if they are equal, false otherwise. + */ + @Override + public boolean equals(Object o) { + if (!(o instanceof Quaternion)) { + return false; + } + + if (this == o) { + return true; + } + + Quaternion comp = (Quaternion) o; + if (Float.compare(x, comp.x) != 0) + return false; + if (Float.compare(y, comp.y) != 0) + return false; + if (Float.compare(z, comp.z) != 0) + return false; return Float.compare(w, comp.w) == 0; } - /** - * - * hashCode returns the hash code value as an integer and is - * supported for the benefit of hashing based collection classes such as - * Hashtable, HashMap, HashSet etc. - * - * @return the hashcode for this instance of Quaternion. - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - int hash = 37; - hash = 37 * hash + Float.floatToIntBits(x); - hash = 37 * hash + Float.floatToIntBits(y); - hash = 37 * hash + Float.floatToIntBits(z); - hash = 37 * hash + Float.floatToIntBits(w); - return hash; - - } - - /** - * readExternal builds a quaternion from an - * ObjectInput object.
- * NOTE: Used with serialization. Not to be called manually. - * - * @param in - * the ObjectInput value to read from. - * @throws IOException - * if the ObjectInput value has problems reading a float. - * @see java.io.Externalizable - */ - public void readExternal(ObjectInput in) throws IOException { - x = in.readFloat(); - y = in.readFloat(); - z = in.readFloat(); - w = in.readFloat(); - } - - /** - * writeExternal writes this quaternion out to a - * ObjectOutput object. NOTE: Used with serialization. Not to - * be called manually. - * - * @param out - * the object to write to. - * @throws IOException - * if writing to the ObjectOutput fails. - * @see java.io.Externalizable - */ - public void writeExternal(ObjectOutput out) throws IOException { - out.writeFloat(x); - out.writeFloat(y); - out.writeFloat(z); - out.writeFloat(w); - } - - private static final Vector3f tmpYaxis = new Vector3f(); - private static final Vector3f tmpZaxis = new Vector3f(); - private static final Vector3f tmpXaxis = new Vector3f(); - - /** - * lookAt is a convienence method for auto-setting the - * quaternion based on a direction and an up vector. It computes the - * rotation to transform the z-axis to point into 'direction' and the y-axis - * to 'up'. - * - * @param direction - * where to look at in terms of local coordinates - * @param up - * a vector indicating the local up direction. (typically {0, 1, - * 0} in jME.) - */ - public void lookAt(Vector3f direction, Vector3f up) { - tmpZaxis.set(direction).normalizeLocal(); - tmpXaxis.set(up).crossLocal(direction).normalizeLocal(); - tmpYaxis.set(direction).crossLocal(tmpXaxis).normalizeLocal(); - fromAxes(tmpXaxis, tmpYaxis, tmpZaxis); - } - - /** - * @return A new quaternion that describes a rotation that would point you - * in the exact opposite direction of this Quaternion. - */ - public Quaternion opposite() { - return opposite(null); - } - - /** - * @param store - * A Quaternion to store our result in. If null, a new one is - * created. - * @return The store quaternion (or a new Quaterion, if store is null) that - * describes a rotation that would point you in the exact opposite - * direction of this Quaternion. - */ - public Quaternion opposite(Quaternion store) { - if (store == null) - store = new Quaternion(); - - Vector3f axis = new Vector3f(); - float angle = toAngleAxis(axis); - - store.fromAngleAxis(FastMath.PI + angle, axis); - return store; - } - - /** - * @return This Quaternion, altered to describe a rotation that would point - * you in the exact opposite direction of where it is pointing - * currently. - */ - public Quaternion oppositeLocal() { - return opposite(this); - } - - @Override - public Quaternion clone() { - try { - return (Quaternion) super.clone(); - } catch (CloneNotSupportedException e) { - Logger.error( e); - throw new AssertionError(); // can not happen - } - } - - public float getX() { - return x; - } - - public void setX(float x) { - this.x = x; - } - - public float getY() { - return y; - } - - public void setY(float y) { - this.y = y; - } - - public float getZ() { - return z; - } - - public void setZ(float z) { - this.z = z; - } - - public float getW() { - return w; - } - - public void setW(float w) { - this.w = w; - } + /** + * hashCode returns the hash code value as an integer and is + * supported for the benefit of hashing based collection classes such as + * Hashtable, HashMap, HashSet etc. + * + * @return the hashcode for this instance of Quaternion. + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + int hash = 37; + hash = 37 * hash + Float.floatToIntBits(x); + hash = 37 * hash + Float.floatToIntBits(y); + hash = 37 * hash + Float.floatToIntBits(z); + hash = 37 * hash + Float.floatToIntBits(w); + return hash; + + } + + /** + * readExternal builds a quaternion from an + * ObjectInput object.
+ * NOTE: Used with serialization. Not to be called manually. + * + * @param in the ObjectInput value to read from. + * @throws IOException if the ObjectInput value has problems reading a float. + * @see java.io.Externalizable + */ + public void readExternal(ObjectInput in) throws IOException { + x = in.readFloat(); + y = in.readFloat(); + z = in.readFloat(); + w = in.readFloat(); + } + + /** + * writeExternal writes this quaternion out to a + * ObjectOutput object. NOTE: Used with serialization. Not to + * be called manually. + * + * @param out the object to write to. + * @throws IOException if writing to the ObjectOutput fails. + * @see java.io.Externalizable + */ + public void writeExternal(ObjectOutput out) throws IOException { + out.writeFloat(x); + out.writeFloat(y); + out.writeFloat(z); + out.writeFloat(w); + } + + /** + * lookAt is a convienence method for auto-setting the + * quaternion based on a direction and an up vector. It computes the + * rotation to transform the z-axis to point into 'direction' and the y-axis + * to 'up'. + * + * @param direction where to look at in terms of local coordinates + * @param up a vector indicating the local up direction. (typically {0, 1, + * 0} in jME.) + */ + public void lookAt(Vector3f direction, Vector3f up) { + tmpZaxis.set(direction).normalizeLocal(); + tmpXaxis.set(up).crossLocal(direction).normalizeLocal(); + tmpYaxis.set(direction).crossLocal(tmpXaxis).normalizeLocal(); + fromAxes(tmpXaxis, tmpYaxis, tmpZaxis); + } + + /** + * @return A new quaternion that describes a rotation that would point you + * in the exact opposite direction of this Quaternion. + */ + public Quaternion opposite() { + return opposite(null); + } + + /** + * @param store A Quaternion to store our result in. If null, a new one is + * created. + * @return The store quaternion (or a new Quaterion, if store is null) that + * describes a rotation that would point you in the exact opposite + * direction of this Quaternion. + */ + public Quaternion opposite(Quaternion store) { + if (store == null) + store = new Quaternion(); + + Vector3f axis = new Vector3f(); + float angle = toAngleAxis(axis); + + store.fromAngleAxis(FastMath.PI + angle, axis); + return store; + } + + /** + * @return This Quaternion, altered to describe a rotation that would point + * you in the exact opposite direction of where it is pointing + * currently. + */ + public Quaternion oppositeLocal() { + return opposite(this); + } + + @Override + public Quaternion clone() { + try { + return (Quaternion) super.clone(); + } catch (CloneNotSupportedException e) { + Logger.error(e); + throw new AssertionError(); // can not happen + } + } + + public float getX() { + return x; + } + + public void setX(float x) { + this.x = x; + } + + public float getY() { + return y; + } + + public void setY(float y) { + this.y = y; + } + + public float getZ() { + return z; + } + + public void setZ(float z) { + this.z = z; + } + + public float getW() { + return w; + } + + public void setW(float w) { + this.w = w; + } } diff --git a/src/engine/math/Vector2f.java b/src/engine/math/Vector2f.java index 06281efc..d69e593e 100644 --- a/src/engine/math/Vector2f.java +++ b/src/engine/math/Vector2f.java @@ -10,226 +10,58 @@ package engine.math; /** * Vector2f defines a Vector for a two float value vector. - * */ public class Vector2f { - /** - * the x value of the vector. - */ - public float x; - /** - * the y value of the vector. - */ - public float y; - - /** - * Creates a Vector2f with the given initial x and y values. - * - * @param x - * The x value of this Vector2f. - * @param y - * The y value of this Vector2f. - */ - public Vector2f(float x, float y) { - this.x = x; - this.y = y; - } - - /** - * Creates a Vector2f with x and y set to 0. Equivalent to Vector2f(0,0). - */ - public Vector2f() { - x = y = 0; - } - - /** - * Creates a new Vector2f that contains the passed vector's information - * - * @param vector2f - * The vector to copy - */ - public Vector2f(Vector2f vector2f) { - this.x = vector2f.x; - this.y = vector2f.y; - } - - /** - * set the x and y values of the vector - * - * @param x - * the x value of the vector. - * @param y - * the y value of the vector. - * @return this vector - */ - public Vector2f set(float x, float y) { - this.x = x; - this.y = y; - return this; - } - - /** - * set the x and y values of the vector from another vector - * - * @param vec - * the vector to copy from - * @return this vector - */ - public Vector2f set(Vector2f vec) { - this.x = vec.x; - this.y = vec.y; - return this; - } - - /** - * add adds a provided vector to this vector creating a - * resultant vector which is returned. If the provided vector is null, null - * is returned. - * - * @param vec - * the vector to add to this. - * @return the resultant vector. - */ - public Vector2f add(Vector2f vec) { - if (null == vec) { - return null; - } - return new Vector2f(x + vec.x, y + vec.y); - } - - /** - * addLocal adds a provided vector to this vector internally, - * and returns a handle to this vector for easy chaining of calls. If the - * provided vector is null, null is returned. - * - * @param vec - * the vector to add to this vector. - * @return this - */ - public Vector2f addLocal(Vector2f vec) { - if (null == vec) { - return null; - } - x += vec.x; - y += vec.y; - return this; - } - - /** - * addLocal adds the provided values to this vector internally, - * and returns a handle to this vector for easy chaining of calls. - * - * @param addX - * value to add to x - * @param addY - * value to add to y - * @return this - */ - public Vector2f addLocal(float addX, float addY) { - x += addX; - y += addY; - return this; - } - - /** - * add adds this vector by vec and stores the - * result in result. - * - * @param vec - * The vector to add. - * @param result - * The vector to store the result in. - * @return The result vector, after adding. - */ - public Vector2f add(Vector2f vec, Vector2f result) { - if (null == vec) { - return null; - } - if (result == null) - result = new Vector2f(); - result.x = x + vec.x; - result.y = y + vec.y; - return result; - } - - /** - * dot calculates the dot product of this vector with a - * provided vector. If the provided vector is null, 0 is returned. - * - * @param vec - * the vector to dot with this vector. - * @return the resultant dot product of this vector and a given vector. - */ - public float dot(Vector2f vec) { - if (null == vec) { - return 0; - } - return x * vec.x + y * vec.y; - } - - /** - * cross calculates the cross product of this vector with a - * parameter vector v. - * - * @param v - * the vector to take the cross product of with this. - * @return the cross product vector. - */ - public Vector3f cross(Vector2f v) { - return new Vector3f(0, 0, determinant(v)); - } - - public float determinant(Vector2f v) { - return (x * v.y) - (y * v.x); - } - - /** - * Sets this vector to the interpolation by changeAmnt from this to the - * finalVec this=(1-changeAmnt)*this + changeAmnt * finalVec - * - * @param finalVec - * The final vector to interpolate towards - * @param changeAmnt - * An amount between 0.0 - 1.0 representing a percentage change - * from this towards finalVec - */ - public void interpolate(Vector2f finalVec, float changeAmnt) { - this.x = (1 - changeAmnt) * this.x + changeAmnt * finalVec.x; - this.y = (1 - changeAmnt) * this.y + changeAmnt * finalVec.y; - } - - /** - * Sets this vector to the interpolation by changeAmnt from beginVec to - * finalVec this=(1-changeAmnt)*beginVec + changeAmnt * finalVec - * - * @param beginVec - * The begining vector (delta=0) - * @param finalVec - * The final vector to interpolate towards (delta=1) - * @param changeAmnt - * An amount between 0.0 - 1.0 representing a precentage change - * from beginVec towards finalVec - */ - public void interpolate(Vector2f beginVec, Vector2f finalVec, - float changeAmnt) { - this.x = (1 - changeAmnt) * beginVec.x + changeAmnt * finalVec.x; - this.y = (1 - changeAmnt) * beginVec.y + changeAmnt * finalVec.y; - } - - /** - * Check a vector... if it is null or its floats are NaN or infinite, return - * false. Else return true. - * - * @param vector - * the vector to check - * @return true or false as stated above. - */ - public static boolean isValidVector(Vector2f vector) { - if (vector == null) - return false; - if (Float.isNaN(vector.x) || Float.isNaN(vector.y)) - return false; + /** + * the x value of the vector. + */ + public float x; + /** + * the y value of the vector. + */ + public float y; + + /** + * Creates a Vector2f with the given initial x and y values. + * + * @param x The x value of this Vector2f. + * @param y The y value of this Vector2f. + */ + public Vector2f(float x, float y) { + this.x = x; + this.y = y; + } + + /** + * Creates a Vector2f with x and y set to 0. Equivalent to Vector2f(0,0). + */ + public Vector2f() { + x = y = 0; + } + + /** + * Creates a new Vector2f that contains the passed vector's information + * + * @param vector2f The vector to copy + */ + public Vector2f(Vector2f vector2f) { + this.x = vector2f.x; + this.y = vector2f.y; + } + + /** + * Check a vector... if it is null or its floats are NaN or infinite, return + * false. Else return true. + * + * @param vector the vector to check + * @return true or false as stated above. + */ + public static boolean isValidVector(Vector2f vector) { + if (vector == null) + return false; + if (Float.isNaN(vector.x) || Float.isNaN(vector.y)) + return false; return !Float.isInfinite(vector.x) && !Float.isInfinite(vector.y); } @@ -239,424 +71,551 @@ public class Vector2f { (vector.y == 0); } - /** - * length calculates the magnitude of this vector. - * - * @return the length or magnitude of the vector. - */ - public float length() { - return FastMath.sqrt(lengthSquared()); - } - - /** - * lengthSquared calculates the squared value of the magnitude - * of the vector. - * - * @return the magnitude squared of the vector. - */ - public float lengthSquared() { - return x * x + y * y; - } - - /** - * distanceSquared calculates the distance squared between this - * vector and vector v. - * - * @param v - * the second vector to determine the distance squared. - * @return the distance squared between the two vectors. - */ - public float distanceSquared(Vector2f v) { - double dx = x - v.x; - double dy = y - v.y; - return (float) (dx * dx + dy * dy); - } - - /** - * distanceSquared calculates the distance squared between this - * vector and vector v. - * - * @return the distance squared between the two vectors. - */ - public float distanceSquared(float otherX, float otherY) { - double dx = x - otherX; - double dy = y - otherY; - return (float) (dx * dx + dy * dy); - } - - /** - * distance calculates the distance between this vector and - * vector v. - * - * @param v - * the second vector to determine the distance. - * @return the distance between the two vectors. - */ - public float distance(Vector2f v) { - return FastMath.sqrt(distanceSquared(v)); - } - - /** - * mult multiplies this vector by a scalar. The resultant - * vector is returned. - * - * @param scalar - * the value to multiply this vector by. - * @return the new vector. - */ - public Vector2f mult(float scalar) { - return new Vector2f(x * scalar, y * scalar); - } - - /** - * multLocal multiplies this vector by a scalar internally, and - * returns a handle to this vector for easy chaining of calls. - * - * @param scalar - * the value to multiply this vector by. - * @return this - */ - public Vector2f multLocal(float scalar) { - x *= scalar; - y *= scalar; - return this; - } - - /** - * multLocal multiplies a provided vector to this vector - * internally, and returns a handle to this vector for easy chaining of - * calls. If the provided vector is null, null is returned. - * - * @param vec - * the vector to mult to this vector. - * @return this - */ - public Vector2f multLocal(Vector2f vec) { - if (null == vec) { - return null; - } - x *= vec.x; - y *= vec.y; - return this; - } - - /** - * Multiplies this Vector2f's x and y by the scalar and stores the result in - * product. The result is returned for chaining. Similar to - * product=this*scalar; - * - * @param scalar - * The scalar to multiply by. - * @param product - * The vector2f to store the result in. - * @return product, after multiplication. - */ - public Vector2f mult(float scalar, Vector2f product) { - if (null == product) { - product = new Vector2f(); - } - - product.x = x * scalar; - product.y = y * scalar; - return product; - } - - /** - * divide divides the values of this vector by a scalar and - * returns the result. The values of this vector remain untouched. - * - * @param scalar - * the value to divide this vectors attributes by. - * @return the result Vector. - */ - public Vector2f divide(float scalar) { - return new Vector2f(x / scalar, y / scalar); - } - - /** - * divideLocal divides this vector by a scalar internally, and - * returns a handle to this vector for easy chaining of calls. Dividing by - * zero will result in an exception. - * - * @param scalar - * the value to divides this vector by. - * @return this - */ - public Vector2f divideLocal(float scalar) { - x /= scalar; - y /= scalar; - return this; - } - - /** - * negate returns the negative of this vector. All values are - * negated and set to a new vector. - * - * @return the negated vector. - */ - public Vector2f negate() { - return new Vector2f(-x, -y); - } - - /** - * negateLocal negates the internal values of this vector. - * - * @return this. - */ - public Vector2f negateLocal() { - x = -x; - y = -y; - return this; - } - - /** - * subtract subtracts the values of a given vector from those - * of this vector creating a new vector object. If the provided vector is - * null, an exception is thrown. - * - * @param vec - * the vector to subtract from this vector. - * @return the result vector. - */ - public Vector2f subtract(Vector2f vec) { - return subtract(vec, null); - } - - /** - * subtract subtracts the values of a given vector from those - * of this vector storing the result in the given vector object. If the - * provided vector is null, an exception is thrown. - * - * @param vec - * the vector to subtract from this vector. - * @param store - * the vector to store the result in. It is safe for this to be - * the same as vec. If null, a new vector is created. - * @return the result vector. - */ - public Vector2f subtract(Vector2f vec, Vector2f store) { - if (store == null) - store = new Vector2f(); - store.x = x - vec.x; - store.y = y - vec.y; - return store; - } - - /** - * subtract subtracts the given x,y values from those of this - * vector creating a new vector object. - * - * @param valX - * value to subtract from x - * @param valY - * value to subtract from y - * @return this - */ - public Vector2f subtract(float valX, float valY) { - return new Vector2f(x - valX, y - valY); - } - - /** - * subtractLocal subtracts a provided vector to this vector - * internally, and returns a handle to this vector for easy chaining of - * calls. If the provided vector is null, null is returned. - * - * @param vec - * the vector to subtract - * @return this - */ - public Vector2f subtractLocal(Vector2f vec) { - if (null == vec) { - return null; - } - x -= vec.x; - y -= vec.y; - return this; - } - - /** - * subtractLocal subtracts the provided values from this vector - * internally, and returns a handle to this vector for easy chaining of - * calls. - * - * @param valX - * value to subtract from x - * @param valY - * value to subtract from y - * @return this - */ - public Vector2f subtractLocal(float valX, float valY) { - x -= valX; - y -= valY; - return this; - } - - /** - * normalize returns the unit vector of this vector. - * - * @return unit vector of this vector. - */ - public Vector2f normalize() { - float length = length(); - if (length != 0) { - return divide(length); - } - - return divide(1); - } - - /** - * normalizeLocal makes this vector into a unit vector of - * itself. - * - * @return this. - */ - public Vector2f normalizeLocal() { - float length = length(); - if (length != 0) { - return divideLocal(length); - } - - return divideLocal(1); - } - - /** - * smallestAngleBetween returns (in radians) the minimum angle - * between two vectors. It is assumed that both this vector and the given - * vector are unit vectors (iow, normalized). - * - * @param otherVector - * a unit vector to find the angle against - * @return the angle in radians. - */ - public float smallestAngleBetween(Vector2f otherVector) { - float dotProduct = dot(otherVector); + + /** + * set the x and y values of the vector + * + * @param x the x value of the vector. + * @param y the y value of the vector. + * @return this vector + */ + public Vector2f set(float x, float y) { + this.x = x; + this.y = y; + return this; + } + + /** + * set the x and y values of the vector from another vector + * + * @param vec the vector to copy from + * @return this vector + */ + public Vector2f set(Vector2f vec) { + this.x = vec.x; + this.y = vec.y; + return this; + } + + /** + * add adds a provided vector to this vector creating a + * resultant vector which is returned. If the provided vector is null, null + * is returned. + * + * @param vec the vector to add to this. + * @return the resultant vector. + */ + public Vector2f add(Vector2f vec) { + if (null == vec) { + return null; + } + return new Vector2f(x + vec.x, y + vec.y); + } + + /** + * addLocal adds a provided vector to this vector internally, + * and returns a handle to this vector for easy chaining of calls. If the + * provided vector is null, null is returned. + * + * @param vec the vector to add to this vector. + * @return this + */ + public Vector2f addLocal(Vector2f vec) { + if (null == vec) { + return null; + } + x += vec.x; + y += vec.y; + return this; + } + + /** + * addLocal adds the provided values to this vector internally, + * and returns a handle to this vector for easy chaining of calls. + * + * @param addX value to add to x + * @param addY value to add to y + * @return this + */ + public Vector2f addLocal(float addX, float addY) { + x += addX; + y += addY; + return this; + } + + /** + * add adds this vector by vec and stores the + * result in result. + * + * @param vec The vector to add. + * @param result The vector to store the result in. + * @return The result vector, after adding. + */ + public Vector2f add(Vector2f vec, Vector2f result) { + if (null == vec) { + return null; + } + if (result == null) + result = new Vector2f(); + result.x = x + vec.x; + result.y = y + vec.y; + return result; + } + + /** + * dot calculates the dot product of this vector with a + * provided vector. If the provided vector is null, 0 is returned. + * + * @param vec the vector to dot with this vector. + * @return the resultant dot product of this vector and a given vector. + */ + public float dot(Vector2f vec) { + if (null == vec) { + return 0; + } + return x * vec.x + y * vec.y; + } + + /** + * cross calculates the cross product of this vector with a + * parameter vector v. + * + * @param v the vector to take the cross product of with this. + * @return the cross product vector. + */ + public Vector3f cross(Vector2f v) { + return new Vector3f(0, 0, determinant(v)); + } + + public float determinant(Vector2f v) { + return (x * v.y) - (y * v.x); + } + + /** + * Sets this vector to the interpolation by changeAmnt from this to the + * finalVec this=(1-changeAmnt)*this + changeAmnt * finalVec + * + * @param finalVec The final vector to interpolate towards + * @param changeAmnt An amount between 0.0 - 1.0 representing a percentage change + * from this towards finalVec + */ + public void interpolate(Vector2f finalVec, float changeAmnt) { + this.x = (1 - changeAmnt) * this.x + changeAmnt * finalVec.x; + this.y = (1 - changeAmnt) * this.y + changeAmnt * finalVec.y; + } + + /** + * Sets this vector to the interpolation by changeAmnt from beginVec to + * finalVec this=(1-changeAmnt)*beginVec + changeAmnt * finalVec + * + * @param beginVec The begining vector (delta=0) + * @param finalVec The final vector to interpolate towards (delta=1) + * @param changeAmnt An amount between 0.0 - 1.0 representing a precentage change + * from beginVec towards finalVec + */ + public void interpolate(Vector2f beginVec, Vector2f finalVec, + float changeAmnt) { + this.x = (1 - changeAmnt) * beginVec.x + changeAmnt * finalVec.x; + this.y = (1 - changeAmnt) * beginVec.y + changeAmnt * finalVec.y; + } + + /** + * length calculates the magnitude of this vector. + * + * @return the length or magnitude of the vector. + */ + public float length() { + return FastMath.sqrt(lengthSquared()); + } + + /** + * lengthSquared calculates the squared value of the magnitude + * of the vector. + * + * @return the magnitude squared of the vector. + */ + public float lengthSquared() { + return x * x + y * y; + } + + /** + * distanceSquared calculates the distance squared between this + * vector and vector v. + * + * @param v the second vector to determine the distance squared. + * @return the distance squared between the two vectors. + */ + public float distanceSquared(Vector2f v) { + double dx = x - v.x; + double dy = y - v.y; + return (float) (dx * dx + dy * dy); + } + + /** + * distanceSquared calculates the distance squared between this + * vector and vector v. + * + * @return the distance squared between the two vectors. + */ + public float distanceSquared(float otherX, float otherY) { + double dx = x - otherX; + double dy = y - otherY; + return (float) (dx * dx + dy * dy); + } + + /** + * distance calculates the distance between this vector and + * vector v. + * + * @param v the second vector to determine the distance. + * @return the distance between the two vectors. + */ + public float distance(Vector2f v) { + return FastMath.sqrt(distanceSquared(v)); + } + + /** + * mult multiplies this vector by a scalar. The resultant + * vector is returned. + * + * @param scalar the value to multiply this vector by. + * @return the new vector. + */ + public Vector2f mult(float scalar) { + return new Vector2f(x * scalar, y * scalar); + } + + /** + * multLocal multiplies this vector by a scalar internally, and + * returns a handle to this vector for easy chaining of calls. + * + * @param scalar the value to multiply this vector by. + * @return this + */ + public Vector2f multLocal(float scalar) { + x *= scalar; + y *= scalar; + return this; + } + + /** + * multLocal multiplies a provided vector to this vector + * internally, and returns a handle to this vector for easy chaining of + * calls. If the provided vector is null, null is returned. + * + * @param vec the vector to mult to this vector. + * @return this + */ + public Vector2f multLocal(Vector2f vec) { + if (null == vec) { + return null; + } + x *= vec.x; + y *= vec.y; + return this; + } + + /** + * Multiplies this Vector2f's x and y by the scalar and stores the result in + * product. The result is returned for chaining. Similar to + * product=this*scalar; + * + * @param scalar The scalar to multiply by. + * @param product The vector2f to store the result in. + * @return product, after multiplication. + */ + public Vector2f mult(float scalar, Vector2f product) { + if (null == product) { + product = new Vector2f(); + } + + product.x = x * scalar; + product.y = y * scalar; + return product; + } + + /** + * divide divides the values of this vector by a scalar and + * returns the result. The values of this vector remain untouched. + * + * @param scalar the value to divide this vectors attributes by. + * @return the result Vector. + */ + public Vector2f divide(float scalar) { + return new Vector2f(x / scalar, y / scalar); + } + + /** + * divideLocal divides this vector by a scalar internally, and + * returns a handle to this vector for easy chaining of calls. Dividing by + * zero will result in an exception. + * + * @param scalar the value to divides this vector by. + * @return this + */ + public Vector2f divideLocal(float scalar) { + x /= scalar; + y /= scalar; + return this; + } + + /** + * negate returns the negative of this vector. All values are + * negated and set to a new vector. + * + * @return the negated vector. + */ + public Vector2f negate() { + return new Vector2f(-x, -y); + } + + /** + * negateLocal negates the internal values of this vector. + * + * @return this. + */ + public Vector2f negateLocal() { + x = -x; + y = -y; + return this; + } + + /** + * subtract subtracts the values of a given vector from those + * of this vector creating a new vector object. If the provided vector is + * null, an exception is thrown. + * + * @param vec the vector to subtract from this vector. + * @return the result vector. + */ + public Vector2f subtract(Vector2f vec) { + return subtract(vec, null); + } + + /** + * subtract subtracts the values of a given vector from those + * of this vector storing the result in the given vector object. If the + * provided vector is null, an exception is thrown. + * + * @param vec the vector to subtract from this vector. + * @param store the vector to store the result in. It is safe for this to be + * the same as vec. If null, a new vector is created. + * @return the result vector. + */ + public Vector2f subtract(Vector2f vec, Vector2f store) { + if (store == null) + store = new Vector2f(); + store.x = x - vec.x; + store.y = y - vec.y; + return store; + } + + /** + * subtract subtracts the given x,y values from those of this + * vector creating a new vector object. + * + * @param valX value to subtract from x + * @param valY value to subtract from y + * @return this + */ + public Vector2f subtract(float valX, float valY) { + return new Vector2f(x - valX, y - valY); + } + + /** + * subtractLocal subtracts a provided vector to this vector + * internally, and returns a handle to this vector for easy chaining of + * calls. If the provided vector is null, null is returned. + * + * @param vec the vector to subtract + * @return this + */ + public Vector2f subtractLocal(Vector2f vec) { + if (null == vec) { + return null; + } + x -= vec.x; + y -= vec.y; + return this; + } + + /** + * subtractLocal subtracts the provided values from this vector + * internally, and returns a handle to this vector for easy chaining of + * calls. + * + * @param valX value to subtract from x + * @param valY value to subtract from y + * @return this + */ + public Vector2f subtractLocal(float valX, float valY) { + x -= valX; + y -= valY; + return this; + } + + /** + * normalize returns the unit vector of this vector. + * + * @return unit vector of this vector. + */ + public Vector2f normalize() { + float length = length(); + if (length != 0) { + return divide(length); + } + + return divide(1); + } + + /** + * normalizeLocal makes this vector into a unit vector of + * itself. + * + * @return this. + */ + public Vector2f normalizeLocal() { + float length = length(); + if (length != 0) { + return divideLocal(length); + } + + return divideLocal(1); + } + + /** + * smallestAngleBetween returns (in radians) the minimum angle + * between two vectors. It is assumed that both this vector and the given + * vector are unit vectors (iow, normalized). + * + * @param otherVector a unit vector to find the angle against + * @return the angle in radians. + */ + public float smallestAngleBetween(Vector2f otherVector) { + float dotProduct = dot(otherVector); return FastMath.acos(dotProduct); - } - - /** - * angleBetween returns (in radians) the angle required to - * rotate a ray represented by this vector to lie colinear to a ray - * described by the given vector. It is assumed that both this vector and - * the given vector are unit vectors (iow, normalized). - * - * @param otherVector - * the "destination" unit vector - * @return the angle in radians. - */ - public float angleBetween(Vector2f otherVector) { + } + + /** + * angleBetween returns (in radians) the angle required to + * rotate a ray represented by this vector to lie colinear to a ray + * described by the given vector. It is assumed that both this vector and + * the given vector are unit vectors (iow, normalized). + * + * @param otherVector the "destination" unit vector + * @return the angle in radians. + */ + public float angleBetween(Vector2f otherVector) { return FastMath.atan2(otherVector.y, otherVector.x) - FastMath.atan2(y, x); - } - - public float getX() { - return x; - } - - public void setX(float x) { - this.x = x; - } - - public float getY() { - return y; - } - - public void setY(float y) { - this.y = y; - } - - /** - * getAngle returns (in radians) the angle represented by this - * Vector2f as expressed by a conversion from rectangular coordinates ( - * xy) to polar coordinates - * (r, theta). - * - * @return the angle in radians. [-pi, pi) - */ - public float getAngle() { - return -FastMath.atan2(y, x); - } - - /** - * zero resets this vector's data to zero internally. - */ - public void zero() { - x = y = 0; - } - - @Override - public Vector2f clone() { - try { - return (Vector2f) super.clone(); - } catch (CloneNotSupportedException e) { - throw new AssertionError(); // can not happen - } - } - - /** - * Saves this Vector2f into the given float[] object. - * - * @param floats - * The float[] to take this Vector2f. If null, a new float[2] is - * created. - * @return The array, with X, Y float values in that order - */ - public float[] toArray(float[] floats) { - if (floats == null) { - floats = new float[2]; - } - floats[0] = x; - floats[1] = y; - return floats; - } - - /** - * are these two vectors the same? they are is they both have the same x and - * y values. - * - * @param o - * the object to compare for equality - * @return true if they are equal - */ - @Override - public boolean equals(Object o) { - if (!(o instanceof Vector2f)) { - return false; - } - - if (this == o) { - return true; - } - - Vector2f comp = (Vector2f) o; - if (Float.compare(x, comp.x) != 0) - return false; + } + + public float getX() { + return x; + } + + public void setX(float x) { + this.x = x; + } + + public float getY() { + return y; + } + + public void setY(float y) { + this.y = y; + } + + /** + * getAngle returns (in radians) the angle represented by this + * Vector2f as expressed by a conversion from rectangular coordinates ( + * xy) to polar coordinates + * (r, theta). + * + * @return the angle in radians. [-pi, pi) + */ + public float getAngle() { + return -FastMath.atan2(y, x); + } + + /** + * zero resets this vector's data to zero internally. + */ + public void zero() { + x = y = 0; + } + + @Override + public Vector2f clone() { + try { + return (Vector2f) super.clone(); + } catch (CloneNotSupportedException e) { + throw new AssertionError(); // can not happen + } + } + + /** + * Saves this Vector2f into the given float[] object. + * + * @param floats The float[] to take this Vector2f. If null, a new float[2] is + * created. + * @return The array, with X, Y float values in that order + */ + public float[] toArray(float[] floats) { + if (floats == null) { + floats = new float[2]; + } + floats[0] = x; + floats[1] = y; + return floats; + } + + /** + * are these two vectors the same? they are is they both have the same x and + * y values. + * + * @param o the object to compare for equality + * @return true if they are equal + */ + @Override + public boolean equals(Object o) { + if (!(o instanceof Vector2f)) { + return false; + } + + if (this == o) { + return true; + } + + Vector2f comp = (Vector2f) o; + if (Float.compare(x, comp.x) != 0) + return false; return Float.compare(y, comp.y) == 0; } - public void rotateAroundOrigin(float angle, boolean cw) { - if (cw) - angle = -angle; - float newX = FastMath.cos(angle) * x - FastMath.sin(angle) * y; - float newY = FastMath.sin(angle) * x + FastMath.cos(angle) * y; - x = newX; - y = newY; - } + public void rotateAroundOrigin(float angle, boolean cw) { + if (cw) + angle = -angle; + float newX = FastMath.cos(angle) * x - FastMath.sin(angle) * y; + float newY = FastMath.sin(angle) * x + FastMath.cos(angle) * y; + x = newX; + y = newY; + } - public synchronized float getLat() { - return x; - } + public synchronized float getLat() { + return x; + } - public synchronized float getLong() { - return y; - } + public synchronized void setLat(float lat) { + this.x = lat; + } - public synchronized void setLat(float lat) { - this.x = lat; - } + public synchronized float getLong() { + return y; + } - public synchronized void setLong(float lon) { - this.y = lon; - } + public synchronized void setLong(float lon) { + this.y = lon; + } } diff --git a/src/engine/math/Vector3f.java b/src/engine/math/Vector3f.java index 06d95d19..98af001c 100644 --- a/src/engine/math/Vector3f.java +++ b/src/engine/math/Vector3f.java @@ -18,1171 +18,1075 @@ import java.io.ObjectOutput; * Vector3f can represent any three dimensional value, such as a * vertex, a normal, etc. Utility methods are also included to aid in * mathematical calculations. - * */ public class Vector3f { - public final static Vector3f ZERO = new Vector3f(0, 0, 0); - - public final static Vector3f UNIT_X = new Vector3f(1, 0, 0); - public final static Vector3f UNIT_Y = new Vector3f(0, 1, 0); - public final static Vector3f UNIT_Z = new Vector3f(0, 0, 1); - public final static Vector3f UNIT_XYZ = new Vector3f(1, 1, 1); - - /** - * the x value of the vector. - */ - public float x; - - /** - * the y value of the vector. - */ - public float y; - - /** - * the z value of the vector. - */ - public float z; - - /** - * Constructor instantiates a new Vector3f with default values - * of (0,0,0). - * - */ - public Vector3f() { - x = y = z = 0.0f; - } - - /** - * Constructor instantiates a new Vector3f with provides - * values. - * - * @param x - * the x value of the vector. - * @param y - * the y value of the vector. - * @param z - * the z value of the vector. - */ - public Vector3f(float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - } - - public Vector3f(Vector3fImmutable original) { - this.x = original.x; - this.y = original.y; - this.z = original.z; - } - - /** - * Constructor instantiates a new Vector3f that is a copy of - * the provided vector - * - * @param copy - * The Vector3f to copy - */ - public Vector3f(Vector3f copy) { - this.set(copy); - } - - /** - * set sets the x,y,z values of the vector based on passed - * parameters. - * - * @param x - * the x value of the vector. - * @param y - * the y value of the vector. - * @param z - * the z value of the vector. - * @return this vector - */ - public Vector3f set(float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - return this; - } - - /** - * set sets the x,y,z values of the vector by copying the - * supplied vector. - * - * @param vect - * the vector to copy. - * @return this vector - */ - public Vector3f set(Vector3f vect) { - this.x = vect.x; - this.y = vect.y; - this.z = vect.z; - return this; - } - - /** - * - * add adds a provided vector to this vector creating a - * resultant vector which is returned. If the provided vector is null, null - * is returned. - * - * Neither 'this' nor 'vec' are modified. - * - * @param vec - * the vector to add to this. - * @return the resultant vector. - */ - public Vector3f add(Vector3f vec) { - if (null == vec) { - return null; - } - return new Vector3f(x + vec.x, y + vec.y, z + vec.z); - } - - /** - * - * add adds the values of a provided vector storing the values - * in the supplied vector. - * - * @param vec - * the vector to add to this - * @param result - * the vector to store the result in - * @return result returns the supplied result vector. - */ - public Vector3f add(Vector3f vec, Vector3f result) { - result.x = x + vec.x; - result.y = y + vec.y; - result.z = z + vec.z; - return result; - } - - /** - * addLocal adds a provided vector to this vector internally, - * and returns a handle to this vector for easy chaining of calls. If the - * provided vector is null, null is returned. - * - * @param vec - * the vector to add to this vector. - * @return this - */ - public Vector3f addLocal(Vector3f vec) { - if (null == vec) { - return null; - } - x += vec.x; - y += vec.y; - z += vec.z; - return this; - } - - /** - * - * add adds the provided values to this vector, creating a new - * vector that is then returned. - * - * @param addX - * the x value to add. - * @param addY - * the y value to add. - * @param addZ - * the z value to add. - * @return the result vector. - */ - public Vector3f add(float addX, float addY, float addZ) { - return new Vector3f(x + addX, y + addY, z + addZ); - } - - /** - * addLocal adds the provided values to this vector internally, - * and returns a handle to this vector for easy chaining of calls. - * - * @param addX - * value to add to x - * @param addY - * value to add to y - * @param addZ - * value to add to z - * @return this - */ - public Vector3f addLocal(float addX, float addY, float addZ) { - x += addX; - y += addY; - z += addZ; - return this; - } - - /** - * - * scaleAdd multiplies this vector by a scalar then adds the - * given Vector3f. - * - * @param scalar - * the value to multiply this vector by. - * @param add - * the value to add - */ - public void scaleAdd(float scalar, Vector3f add) { - x = x * scalar + add.x; - y = y * scalar + add.y; - z = z * scalar + add.z; - } - - /** - * - * scaleAdd multiplies the given vector by a scalar then adds - * the given vector. - * - * @param scalar - * the value to multiply this vector by. - * @param mult - * the value to multiply the scalar by - * @param add - * the value to add - */ - public void scaleAdd(float scalar, Vector3f mult, Vector3f add) { - this.x = mult.x * scalar + add.x; - this.y = mult.y * scalar + add.y; - this.z = mult.z * scalar + add.z; - } - - /** - * - * dot calculates the dot product of this vector with a - * provided vector. If the provided vector is null, 0 is returned. - * - * @param vec - * the vector to dot with this vector. - * @return the resultant dot product of this vector and a given vector. - */ - public float dot(Vector3f vec) { - if (null == vec) { - return 0; - } - return x * vec.x + y * vec.y + z * vec.z; - } - - /** - * Returns a new vector which is the cross product of this vector with the - * specified vector. - *

- * Neither 'this' nor v are modified. The starting value of 'result' - *

- * - * @param v - * the vector to take the cross product of with this. - * @return the cross product vector. - */ - public Vector3f cross(Vector3f v) { - return cross(v, null); - } - - /** - * cross calculates the cross product of this vector with a - * parameter vector v. The result is stored in result - *

- * Neither 'this' nor v are modified. The starting value of 'result' (if - * any) is ignored. - *

- * - * @param v - * the vector to take the cross product of with this. - * @param result - * the vector to store the cross product result. - * @return result, after receiving the cross product vector. - */ - public Vector3f cross(Vector3f v, Vector3f result) { - return cross(v.x, v.y, v.z, result); - } - - /** - * cross calculates the cross product of this vector with a - * Vector comprised of the specified other* elements. The result is stored - * in result, without modifying either 'this' or the 'other*' - * values. - * - * @param otherX - * x component of the vector to take the cross product of with - * this. - * @param otherY - * y component of the vector to take the cross product of with - * this. - * @param otherZ - * z component of the vector to take the cross product of with - * this. - * @param result - * the vector to store the cross product result. - * @return result, after receiving the cross product vector. - */ - public Vector3f cross(float otherX, float otherY, float otherZ, Vector3f result) { - if (result == null) - result = new Vector3f(); - float resX = ((y * otherZ) - (z * otherY)); - float resY = ((z * otherX) - (x * otherZ)); - float resZ = ((x * otherY) - (y * otherX)); - result.set(resX, resY, resZ); - return result; - } - - /** - * crossLocal calculates the cross product of this vector with - * a parameter vector v. - * - * @param v - * the vector to take the cross product of with this. - * @return this. - */ - public Vector3f crossLocal(Vector3f v) { - return crossLocal(v.x, v.y, v.z); - } - - /** - * crossLocal calculates the cross product of this vector with - * a parameter vector v. - * - * @param otherX - * x component of the vector to take the cross product of with - * this. - * @param otherY - * y component of the vector to take the cross product of with - * this. - * @param otherZ - * z component of the vector to take the cross product of with - * this. - * @return this. - */ - public Vector3f crossLocal(float otherX, float otherY, float otherZ) { - float tempx = (y * otherZ) - (z * otherY); - float tempy = (z * otherX) - (x * otherZ); - z = (x * otherY) - (y * otherX); - x = tempx; - y = tempy; - return this; - } - - /** - * length calculates the magnitude of this vector. - * - * @return the length or magnitude of the vector. - */ - public float length() { - return FastMath.sqrt(lengthSquared()); - } - - /** - * lengthSquared calculates the squared value of the magnitude - * of the vector. - * - * @return the magnitude squared of the vector. - */ - public float lengthSquared() { - return x * x + y * y + z * z; - } - - /** - * distanceSquared calculates the distance squared between this - * vector and vector v. - * - * @param v - * the second vector to determine the distance squared. - * @return the distance squared between the two vectors. - */ - public float distanceSquared(Vector3f v) { - double dx = x - v.x; - double dy = y - v.y; - double dz = z - v.z; - return (float) (dx * dx + dy * dy + dz * dz); - } - - public float distanceSquared2D(Vector3f v) { - double dx = x - v.x; - double dz = z - v.z; - return (float) (dx * dx + dz * dz); - } - - /** - * distance calculates the distance between this vector and - * vector v. - * - * @param v - * the second vector to determine the distance. - * @return the distance between the two vectors. - */ - public float distance(Vector3f v) { - return FastMath.sqrt(distanceSquared(v)); - } - - public float distance2D(Vector3f v) { - return FastMath.sqrt(distanceSquared2D(v)); - } - - /** - * mult multiplies this vector by a scalar. The resultant - * vector is returned. "this" is not modified. - * - * @param scalar - * the value to multiply this vector by. - * @return the new vector. - */ - public Vector3f mult(float scalar) { - return new Vector3f(x * scalar, y * scalar, z * scalar); - } - - /** - * - * mult multiplies this vector by a scalar. The resultant - * vector is supplied as the second parameter and returned. "this" is not - * modified. - * - * @param scalar - * the scalar to multiply this vector by. - * @param product - * the product to store the result in. - * @return product - */ - public Vector3f mult(float scalar, Vector3f product) { - if (null == product) { - product = new Vector3f(); - } - - product.x = x * scalar; - product.y = y * scalar; - product.z = z * scalar; - return product; - } - - /** - * multLocal multiplies this vector by a scalar internally, and - * returns a handle to this vector for easy chaining of calls. - * - * @param scalar - * the value to multiply this vector by. - * @return this - */ - public Vector3f multLocal(float scalar) { - x *= scalar; - y *= scalar; - z *= scalar; - return this; - } - - /** - * multLocal multiplies a provided vector to this vector - * internally, and returns a handle to this vector for easy chaining of - * calls. If the provided vector is null, null is returned. The provided - * 'vec' is not modified. - * - * @param vec - * the vector to mult to this vector. - * @return this - */ - public Vector3f multLocal(Vector3f vec) { - if (null == vec) { - return null; - } - x *= vec.x; - y *= vec.y; - z *= vec.z; - return this; - } - - /** - * Returns a new Vector instance comprised of elements which are the product - * of the corresponding vector elements. (N.b. this is not a cross product). - *

- * Neither 'this' nor 'vec' are modified. - *

- * - * @param vec - * the vector to mult to this vector. - */ - public Vector3f mult(Vector3f vec) { - if (null == vec) { - return null; - } - return mult(vec, null); - } - - /** - * Multiplies a provided 'vec' vector with this vector. If the specified - * 'store' is null, then a new Vector instance is returned. Otherwise, - * 'store' with replaced values will be returned, to facilitate chaining. - *

- *

- *'This' is not modified; and the starting value of 'store' (if any) is - * ignored (and over-written). - *

- * The resultant Vector is comprised of elements which are the product of - * the corresponding vector elements. (N.b. this is not a cross product). - *

- * - * @param vec - * the vector to mult to this vector. - * @param store - * result vector (null to create a new vector) - * @return 'store', or a new Vector3f - */ - public Vector3f mult(Vector3f vec, Vector3f store) { - if (null == vec) { - return null; - } - if (store == null) - store = new Vector3f(); - return store.set(x * vec.x, y * vec.y, z * vec.z); - } - - /** - * divide divides the values of this vector by a scalar and - * returns the result. The values of this vector remain untouched. - * - * @param scalar - * the value to divide this vectors attributes by. - * @return the result Vector. - */ - public Vector3f divide(float scalar) { - scalar = 1f / scalar; - return new Vector3f(x * scalar, y * scalar, z * scalar); - } - - /** - * divideLocal divides this vector by a scalar internally, and - * returns a handle to this vector for easy chaining of calls. Dividing by - * zero will result in an exception. - * - * @param scalar - * the value to divides this vector by. - * @return this - */ - public Vector3f divideLocal(float scalar) { - scalar = 1f / scalar; - x *= scalar; - y *= scalar; - z *= scalar; - return this; - } - - /** - * divide divides the values of this vector by a scalar and - * returns the result. The values of this vector remain untouched. - * - * @param scalar - * the value to divide this vectors attributes by. - * @return the result Vector. - */ - public Vector3f divide(Vector3f scalar) { - return new Vector3f(x / scalar.x, y / scalar.y, z / scalar.z); - } - - /** - * divideLocal divides this vector by a scalar internally, and - * returns a handle to this vector for easy chaining of calls. Dividing by - * zero will result in an exception. - * - * @param scalar - * the value to divides this vector by. - * @return this - */ - public Vector3f divideLocal(Vector3f scalar) { - x /= scalar.x; - y /= scalar.y; - z /= scalar.z; - return this; - } - - /** - * - * negate returns the negative of this vector. All values are - * negated and set to a new vector. - * - * @return the negated vector. - */ - public Vector3f negate() { - return new Vector3f(-x, -y, -z); - } - - /** - * - * negateLocal negates the internal values of this vector. - * - * @return this. - */ - public Vector3f negateLocal() { - x = -x; - y = -y; - z = -z; - return this; - } - - /** - * - * subtract subtracts the values of a given vector from those - * of this vector creating a new vector object. If the provided vector is - * null, null is returned. - * - * @param vec - * the vector to subtract from this vector. - * @return the result vector. - */ - public Vector3f subtract(Vector3f vec) { - return new Vector3f(x - vec.x, y - vec.y, z - vec.z); - } - - public Vector3f subtract2D(Vector3f vec) { - return new Vector3f(x - vec.x, 0, z - vec.z); - } - - /** - * subtractLocal subtracts a provided vector to this vector - * internally, and returns a handle to this vector for easy chaining of - * calls. If the provided vector is null, null is returned. - * - * @param vec - * the vector to subtract - * @return this - */ - public Vector3f subtractLocal(Vector3f vec) { - if (null == vec) { - return null; - } - x -= vec.x; - y -= vec.y; - z -= vec.z; - return this; - } - - /** - * - * subtract - * - * @param vec - * the vector to subtract from this - * @param result - * the vector to store the result in - * @return result - */ - public Vector3f subtract(Vector3f vec, Vector3f result) { - if (result == null) { - result = new Vector3f(); - } - result.x = x - vec.x; - result.y = y - vec.y; - result.z = z - vec.z; - return result; - } - - /** - * - * subtract subtracts the provided values from this vector, - * creating a new vector that is then returned. - * - * @param subtractX - * the x value to subtract. - * @param subtractY - * the y value to subtract. - * @param subtractZ - * the z value to subtract. - * @return the result vector. - */ - public Vector3f subtract(float subtractX, float subtractY, float subtractZ) { - return new Vector3f(x - subtractX, y - subtractY, z - subtractZ); - } - - /** - * subtractLocal subtracts the provided values from this vector - * internally, and returns a handle to this vector for easy chaining of - * calls. - * - * @param subtractX - * the x value to subtract. - * @param subtractY - * the y value to subtract. - * @param subtractZ - * the z value to subtract. - * @return this - */ - public Vector3f subtractLocal(float subtractX, float subtractY, float subtractZ) { - x -= subtractX; - y -= subtractY; - z -= subtractZ; - return this; - } - - /** - * normalize returns the unit vector of this vector. - * - * @return unit vector of this vector. - */ - public Vector3f normalize() { - float length = length(); - if (length != 0) { - return divide(length); - } - - return divide(1); - } - - /** - * normalizeLocal makes this vector into a unit vector of - * itself. - * - * @return this. - */ - public Vector3f normalizeLocal() { - float length = length(); - if (length != 0) { - return divideLocal(length); - } - - return this; - } - - /** - * zero resets this vector's data to zero internally. - */ - public void zero() { - x = y = z = 0; - } - - /** - * angleBetween returns (in radians) the angle between two - * vectors. It is assumed that both this vector and the given vector are - * unit vectors (iow, normalized). - * - * @param otherVector - * a unit vector to find the angle against - * @return the angle in radians. - */ - public float angleBetween(Vector3f otherVector) { - float dotProduct = dot(otherVector); - return FastMath.acos(dotProduct); - } - - /** - * Sets this vector to the interpolation by changeAmnt from this to the - * finalVec this=(1-changeAmnt)*this + changeAmnt * finalVec - * - * @param finalVec - * The final vector to interpolate towards - * @param changeAmnt - * An amount between 0.0 - 1.0 representing a percentage change - * from this towards finalVec - */ - public void interpolate(Vector3f finalVec, float changeAmnt) { - this.x = (1 - changeAmnt) * this.x + changeAmnt * finalVec.x; - this.y = (1 - changeAmnt) * this.y + changeAmnt * finalVec.y; - this.z = (1 - changeAmnt) * this.z + changeAmnt * finalVec.z; - } - - - public Vector3f lerp(Vector3f finalVec, float changeAmnt) { - float x = (1 - changeAmnt) * this.x + changeAmnt * finalVec.x; - float y = (1 - changeAmnt) * this.y + changeAmnt * finalVec.y; - float z = (1 - changeAmnt) * this.z + changeAmnt * finalVec.z; - return new Vector3f(x,y,z); - } - - /** - * Sets this vector to the interpolation by changeAmnt from beginVec to - * finalVec this=(1-changeAmnt)*beginVec + changeAmnt * finalVec - * - * @param beginVec - * the beginning vector (changeAmnt=0) - * @param finalVec - * The final vector to interpolate towards - * @param changeAmnt - * An amount between 0.0 - 1.0 representing a percentage change - * from beginVec towards finalVec - */ - public void interpolate(Vector3f beginVec, Vector3f finalVec, float changeAmnt) { - this.x = (1 - changeAmnt) * beginVec.x + changeAmnt * finalVec.x; - this.y = (1 - changeAmnt) * beginVec.y + changeAmnt * finalVec.y; - this.z = (1 - changeAmnt) * beginVec.z + changeAmnt * finalVec.z; - } - - /** - * Check a vector... if it is null or its floats are NaN or infinite, return - * false. Else return true. - * - * @param vector - * the vector to check - * @return true or false as stated above. - */ - public static boolean isValidVector(Vector3f vector) { - if (vector == null) - return false; - if (Float.isNaN(vector.x) || Float.isNaN(vector.y) || Float.isNaN(vector.z)) - return false; + public final static Vector3f ZERO = new Vector3f(0, 0, 0); + + public final static Vector3f UNIT_X = new Vector3f(1, 0, 0); + public final static Vector3f UNIT_Y = new Vector3f(0, 1, 0); + public final static Vector3f UNIT_Z = new Vector3f(0, 0, 1); + public final static Vector3f UNIT_XYZ = new Vector3f(1, 1, 1); + + /** + * the x value of the vector. + */ + public float x; + + /** + * the y value of the vector. + */ + public float y; + + /** + * the z value of the vector. + */ + public float z; + + /** + * Constructor instantiates a new Vector3f with default values + * of (0,0,0). + */ + public Vector3f() { + x = y = z = 0.0f; + } + + /** + * Constructor instantiates a new Vector3f with provides + * values. + * + * @param x the x value of the vector. + * @param y the y value of the vector. + * @param z the z value of the vector. + */ + public Vector3f(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + } + + public Vector3f(Vector3fImmutable original) { + this.x = original.x; + this.y = original.y; + this.z = original.z; + } + + /** + * Constructor instantiates a new Vector3f that is a copy of + * the provided vector + * + * @param copy The Vector3f to copy + */ + public Vector3f(Vector3f copy) { + this.set(copy); + } + + /** + * Check a vector... if it is null or its floats are NaN or infinite, return + * false. Else return true. + * + * @param vector the vector to check + * @return true or false as stated above. + */ + public static boolean isValidVector(Vector3f vector) { + if (vector == null) + return false; + if (Float.isNaN(vector.x) || Float.isNaN(vector.y) || Float.isNaN(vector.z)) + return false; return !Float.isInfinite(vector.x) && !Float.isInfinite(vector.y) && !Float.isInfinite(vector.z); } - public static void generateOrthonormalBasis(Vector3f u, Vector3f v, Vector3f w) { - w.normalizeLocal(); - generateComplementBasis(u, v, w); - } - - public static void generateComplementBasis(Vector3f u, Vector3f v, Vector3f w) { - float fInvLength; - - if (FastMath.abs(w.x) >= FastMath.abs(w.y)) { - // w.x or w.z is the largest magnitude component, swap them - fInvLength = FastMath.invSqrt(w.x * w.x + w.z * w.z); - u.x = -w.z * fInvLength; - u.y = 0.0f; - u.z = +w.x * fInvLength; - v.x = w.y * u.z; - v.y = w.z * u.x - w.x * u.z; - v.z = -w.y * u.x; - } else { - // w.y or w.z is the largest magnitude component, swap them - fInvLength = FastMath.invSqrt(w.y * w.y + w.z * w.z); - u.x = 0.0f; - u.y = +w.z * fInvLength; - u.z = -w.y * fInvLength; - v.x = w.y * u.z - w.z * u.y; - v.y = -w.x * u.z; - v.z = w.x * u.y; - } - } - - @Override - public Vector3f clone() { - try { - return (Vector3f) super.clone(); - } catch (CloneNotSupportedException e) { - throw new AssertionError(); // can not happen - } - } - - /** - * Saves this Vector3f into the given float[] object. - * - * @param floats - * The float[] to take this Vector3f. If null, a new float[3] is - * created. - * @return The array, with X, Y, Z float values in that order - */ - public float[] toArray(float[] floats) { - if (floats == null) { - floats = new float[3]; - } - floats[0] = x; - floats[1] = y; - floats[2] = z; - return floats; - } - - /** - * are these two vectors the same? they are is they both have the same x,y, - * and z values. - * - * @param o - * the object to compare for equality - * @return true if they are equal - */ - @Override - public boolean equals(Object o) { - if (!(o instanceof Vector3f)) { - return false; - } - - if (this == o) { - return true; - } - - Vector3f comp = (Vector3f) o; - if (Float.compare(x, comp.x) != 0) - return false; - if (Float.compare(y, comp.y) != 0) - return false; + public static void generateOrthonormalBasis(Vector3f u, Vector3f v, Vector3f w) { + w.normalizeLocal(); + generateComplementBasis(u, v, w); + } + + public static void generateComplementBasis(Vector3f u, Vector3f v, Vector3f w) { + float fInvLength; + + if (FastMath.abs(w.x) >= FastMath.abs(w.y)) { + // w.x or w.z is the largest magnitude component, swap them + fInvLength = FastMath.invSqrt(w.x * w.x + w.z * w.z); + u.x = -w.z * fInvLength; + u.y = 0.0f; + u.z = +w.x * fInvLength; + v.x = w.y * u.z; + v.y = w.z * u.x - w.x * u.z; + v.z = -w.y * u.x; + } else { + // w.y or w.z is the largest magnitude component, swap them + fInvLength = FastMath.invSqrt(w.y * w.y + w.z * w.z); + u.x = 0.0f; + u.y = +w.z * fInvLength; + u.z = -w.y * fInvLength; + v.x = w.y * u.z - w.z * u.y; + v.y = -w.x * u.z; + v.z = w.x * u.y; + } + } + + /** + * Returns the 2D face direction from rotation. + * + * @param rotation Rotation in radians + */ + public static Vector3f getFaceDir(float rotation) { + return new Vector3f(FastMath.sin(rotation), 0f, FastMath.cos(rotation)); + } + + /** + * Returns the 2D cross direction (perpendicular face direction) from rotation. + * + * @param rotation Rotation in radians + */ + public static Vector3f getCrossDir(float rotation) { + return new Vector3f(FastMath.cos(rotation), 0f, FastMath.sin(rotation)); + } + + public static Vector3f rotateAroundPoint(Vector3f origin, Vector3f point, double angle) { + + float angleRadians; + double modifiedAngle; + + // Convert angle to radians + + modifiedAngle = angle; + + if (angle < 0) + modifiedAngle = 360 + modifiedAngle; + + angleRadians = (float) Math.toRadians(modifiedAngle); + + return rotateAroundPoint(origin, point, angleRadians); + } + + public static Vector3f rotateAroundPoint(Vector3f origin, Vector3f point, float radians) { + + Vector3f outVector; + Vector3f directionVector; + Quaternion angleRotation; + + // Build direction vector relative to origin + + directionVector = new Vector3f(point.subtract(origin)); + + // Build quaternion rotation + + angleRotation = new Quaternion().fromAngleAxis(radians, new Vector3f(0, 1, 0)); + + // Apply rotation to direction vector + + directionVector = angleRotation.mult(directionVector); + + // Translate from origin back to new rotated point + + outVector = origin.add(directionVector); + + return outVector; + + } + + public static Vector3f min(Vector3f vectorA, Vector3f vectorB) { + + return new Vector3f(Math.min(vectorA.x, vectorB.x), + Math.min(vectorA.y, vectorB.y), + Math.min(vectorA.z, vectorB.z)); + } + + public static Vector3f max(Vector3f vectorA, Vector3f vectorB) { + + return new Vector3f(Math.max(vectorA.x, vectorB.x), + Math.max(vectorA.y, vectorB.y), + Math.max(vectorA.z, vectorB.z)); + } + + public static Vector3f rotateAroundPoint(Vector3f origin, Vector3f point, Quaternion angleRotation) { + + Vector3f outVector; + Vector3f directionVector; + // Build direction vector relative to origin + directionVector = new Vector3f(point.subtract(origin)); + directionVector = angleRotation.mult(directionVector); + + // Translate from origin back to new rotated point + + outVector = origin.add(directionVector); + + return outVector; + + } + + /** + * set sets the x,y,z values of the vector based on passed + * parameters. + * + * @param x the x value of the vector. + * @param y the y value of the vector. + * @param z the z value of the vector. + * @return this vector + */ + public Vector3f set(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + return this; + } + + /** + * set sets the x,y,z values of the vector by copying the + * supplied vector. + * + * @param vect the vector to copy. + * @return this vector + */ + public Vector3f set(Vector3f vect) { + this.x = vect.x; + this.y = vect.y; + this.z = vect.z; + return this; + } + + /** + * add adds a provided vector to this vector creating a + * resultant vector which is returned. If the provided vector is null, null + * is returned. + *

+ * Neither 'this' nor 'vec' are modified. + * + * @param vec the vector to add to this. + * @return the resultant vector. + */ + public Vector3f add(Vector3f vec) { + if (null == vec) { + return null; + } + return new Vector3f(x + vec.x, y + vec.y, z + vec.z); + } + + /** + * add adds the values of a provided vector storing the values + * in the supplied vector. + * + * @param vec the vector to add to this + * @param result the vector to store the result in + * @return result returns the supplied result vector. + */ + public Vector3f add(Vector3f vec, Vector3f result) { + result.x = x + vec.x; + result.y = y + vec.y; + result.z = z + vec.z; + return result; + } + + /** + * addLocal adds a provided vector to this vector internally, + * and returns a handle to this vector for easy chaining of calls. If the + * provided vector is null, null is returned. + * + * @param vec the vector to add to this vector. + * @return this + */ + public Vector3f addLocal(Vector3f vec) { + if (null == vec) { + return null; + } + x += vec.x; + y += vec.y; + z += vec.z; + return this; + } + + /** + * add adds the provided values to this vector, creating a new + * vector that is then returned. + * + * @param addX the x value to add. + * @param addY the y value to add. + * @param addZ the z value to add. + * @return the result vector. + */ + public Vector3f add(float addX, float addY, float addZ) { + return new Vector3f(x + addX, y + addY, z + addZ); + } + + /** + * addLocal adds the provided values to this vector internally, + * and returns a handle to this vector for easy chaining of calls. + * + * @param addX value to add to x + * @param addY value to add to y + * @param addZ value to add to z + * @return this + */ + public Vector3f addLocal(float addX, float addY, float addZ) { + x += addX; + y += addY; + z += addZ; + return this; + } + + /** + * scaleAdd multiplies this vector by a scalar then adds the + * given Vector3f. + * + * @param scalar the value to multiply this vector by. + * @param add the value to add + */ + public void scaleAdd(float scalar, Vector3f add) { + x = x * scalar + add.x; + y = y * scalar + add.y; + z = z * scalar + add.z; + } + + /** + * scaleAdd multiplies the given vector by a scalar then adds + * the given vector. + * + * @param scalar the value to multiply this vector by. + * @param mult the value to multiply the scalar by + * @param add the value to add + */ + public void scaleAdd(float scalar, Vector3f mult, Vector3f add) { + this.x = mult.x * scalar + add.x; + this.y = mult.y * scalar + add.y; + this.z = mult.z * scalar + add.z; + } + + /** + * dot calculates the dot product of this vector with a + * provided vector. If the provided vector is null, 0 is returned. + * + * @param vec the vector to dot with this vector. + * @return the resultant dot product of this vector and a given vector. + */ + public float dot(Vector3f vec) { + if (null == vec) { + return 0; + } + return x * vec.x + y * vec.y + z * vec.z; + } + + /** + * Returns a new vector which is the cross product of this vector with the + * specified vector. + *

+ * Neither 'this' nor v are modified. The starting value of 'result' + *

+ * + * @param v the vector to take the cross product of with this. + * @return the cross product vector. + */ + public Vector3f cross(Vector3f v) { + return cross(v, null); + } + + /** + * cross calculates the cross product of this vector with a + * parameter vector v. The result is stored in result + *

+ * Neither 'this' nor v are modified. The starting value of 'result' (if + * any) is ignored. + *

+ * + * @param v the vector to take the cross product of with this. + * @param result the vector to store the cross product result. + * @return result, after receiving the cross product vector. + */ + public Vector3f cross(Vector3f v, Vector3f result) { + return cross(v.x, v.y, v.z, result); + } + + /** + * cross calculates the cross product of this vector with a + * Vector comprised of the specified other* elements. The result is stored + * in result, without modifying either 'this' or the 'other*' + * values. + * + * @param otherX x component of the vector to take the cross product of with + * this. + * @param otherY y component of the vector to take the cross product of with + * this. + * @param otherZ z component of the vector to take the cross product of with + * this. + * @param result the vector to store the cross product result. + * @return result, after receiving the cross product vector. + */ + public Vector3f cross(float otherX, float otherY, float otherZ, Vector3f result) { + if (result == null) + result = new Vector3f(); + float resX = ((y * otherZ) - (z * otherY)); + float resY = ((z * otherX) - (x * otherZ)); + float resZ = ((x * otherY) - (y * otherX)); + result.set(resX, resY, resZ); + return result; + } + + /** + * crossLocal calculates the cross product of this vector with + * a parameter vector v. + * + * @param v the vector to take the cross product of with this. + * @return this. + */ + public Vector3f crossLocal(Vector3f v) { + return crossLocal(v.x, v.y, v.z); + } + + /** + * crossLocal calculates the cross product of this vector with + * a parameter vector v. + * + * @param otherX x component of the vector to take the cross product of with + * this. + * @param otherY y component of the vector to take the cross product of with + * this. + * @param otherZ z component of the vector to take the cross product of with + * this. + * @return this. + */ + public Vector3f crossLocal(float otherX, float otherY, float otherZ) { + float tempx = (y * otherZ) - (z * otherY); + float tempy = (z * otherX) - (x * otherZ); + z = (x * otherY) - (y * otherX); + x = tempx; + y = tempy; + return this; + } + + /** + * length calculates the magnitude of this vector. + * + * @return the length or magnitude of the vector. + */ + public float length() { + return FastMath.sqrt(lengthSquared()); + } + + /** + * lengthSquared calculates the squared value of the magnitude + * of the vector. + * + * @return the magnitude squared of the vector. + */ + public float lengthSquared() { + return x * x + y * y + z * z; + } + + /** + * distanceSquared calculates the distance squared between this + * vector and vector v. + * + * @param v the second vector to determine the distance squared. + * @return the distance squared between the two vectors. + */ + public float distanceSquared(Vector3f v) { + double dx = x - v.x; + double dy = y - v.y; + double dz = z - v.z; + return (float) (dx * dx + dy * dy + dz * dz); + } + + public float distanceSquared2D(Vector3f v) { + double dx = x - v.x; + double dz = z - v.z; + return (float) (dx * dx + dz * dz); + } + + /** + * distance calculates the distance between this vector and + * vector v. + * + * @param v the second vector to determine the distance. + * @return the distance between the two vectors. + */ + public float distance(Vector3f v) { + return FastMath.sqrt(distanceSquared(v)); + } + + public float distance2D(Vector3f v) { + return FastMath.sqrt(distanceSquared2D(v)); + } + + /** + * mult multiplies this vector by a scalar. The resultant + * vector is returned. "this" is not modified. + * + * @param scalar the value to multiply this vector by. + * @return the new vector. + */ + public Vector3f mult(float scalar) { + return new Vector3f(x * scalar, y * scalar, z * scalar); + } + + /** + * mult multiplies this vector by a scalar. The resultant + * vector is supplied as the second parameter and returned. "this" is not + * modified. + * + * @param scalar the scalar to multiply this vector by. + * @param product the product to store the result in. + * @return product + */ + public Vector3f mult(float scalar, Vector3f product) { + if (null == product) { + product = new Vector3f(); + } + + product.x = x * scalar; + product.y = y * scalar; + product.z = z * scalar; + return product; + } + + /** + * multLocal multiplies this vector by a scalar internally, and + * returns a handle to this vector for easy chaining of calls. + * + * @param scalar the value to multiply this vector by. + * @return this + */ + public Vector3f multLocal(float scalar) { + x *= scalar; + y *= scalar; + z *= scalar; + return this; + } + + /** + * multLocal multiplies a provided vector to this vector + * internally, and returns a handle to this vector for easy chaining of + * calls. If the provided vector is null, null is returned. The provided + * 'vec' is not modified. + * + * @param vec the vector to mult to this vector. + * @return this + */ + public Vector3f multLocal(Vector3f vec) { + if (null == vec) { + return null; + } + x *= vec.x; + y *= vec.y; + z *= vec.z; + return this; + } + + /** + * Returns a new Vector instance comprised of elements which are the product + * of the corresponding vector elements. (N.b. this is not a cross product). + *

+ * Neither 'this' nor 'vec' are modified. + *

+ * + * @param vec the vector to mult to this vector. + */ + public Vector3f mult(Vector3f vec) { + if (null == vec) { + return null; + } + return mult(vec, null); + } + + /** + * Multiplies a provided 'vec' vector with this vector. If the specified + * 'store' is null, then a new Vector instance is returned. Otherwise, + * 'store' with replaced values will be returned, to facilitate chaining. + *

+ *

+ * 'This' is not modified; and the starting value of 'store' (if any) is + * ignored (and over-written). + *

+ * The resultant Vector is comprised of elements which are the product of + * the corresponding vector elements. (N.b. this is not a cross product). + *

+ * + * @param vec the vector to mult to this vector. + * @param store result vector (null to create a new vector) + * @return 'store', or a new Vector3f + */ + public Vector3f mult(Vector3f vec, Vector3f store) { + if (null == vec) { + return null; + } + if (store == null) + store = new Vector3f(); + return store.set(x * vec.x, y * vec.y, z * vec.z); + } + + /** + * divide divides the values of this vector by a scalar and + * returns the result. The values of this vector remain untouched. + * + * @param scalar the value to divide this vectors attributes by. + * @return the result Vector. + */ + public Vector3f divide(float scalar) { + scalar = 1f / scalar; + return new Vector3f(x * scalar, y * scalar, z * scalar); + } + + /** + * divideLocal divides this vector by a scalar internally, and + * returns a handle to this vector for easy chaining of calls. Dividing by + * zero will result in an exception. + * + * @param scalar the value to divides this vector by. + * @return this + */ + public Vector3f divideLocal(float scalar) { + scalar = 1f / scalar; + x *= scalar; + y *= scalar; + z *= scalar; + return this; + } + + /** + * divide divides the values of this vector by a scalar and + * returns the result. The values of this vector remain untouched. + * + * @param scalar the value to divide this vectors attributes by. + * @return the result Vector. + */ + public Vector3f divide(Vector3f scalar) { + return new Vector3f(x / scalar.x, y / scalar.y, z / scalar.z); + } + + /** + * divideLocal divides this vector by a scalar internally, and + * returns a handle to this vector for easy chaining of calls. Dividing by + * zero will result in an exception. + * + * @param scalar the value to divides this vector by. + * @return this + */ + public Vector3f divideLocal(Vector3f scalar) { + x /= scalar.x; + y /= scalar.y; + z /= scalar.z; + return this; + } + + /** + * negate returns the negative of this vector. All values are + * negated and set to a new vector. + * + * @return the negated vector. + */ + public Vector3f negate() { + return new Vector3f(-x, -y, -z); + } + + /** + * negateLocal negates the internal values of this vector. + * + * @return this. + */ + public Vector3f negateLocal() { + x = -x; + y = -y; + z = -z; + return this; + } + + /** + * subtract subtracts the values of a given vector from those + * of this vector creating a new vector object. If the provided vector is + * null, null is returned. + * + * @param vec the vector to subtract from this vector. + * @return the result vector. + */ + public Vector3f subtract(Vector3f vec) { + return new Vector3f(x - vec.x, y - vec.y, z - vec.z); + } + + public Vector3f subtract2D(Vector3f vec) { + return new Vector3f(x - vec.x, 0, z - vec.z); + } + + /** + * subtractLocal subtracts a provided vector to this vector + * internally, and returns a handle to this vector for easy chaining of + * calls. If the provided vector is null, null is returned. + * + * @param vec the vector to subtract + * @return this + */ + public Vector3f subtractLocal(Vector3f vec) { + if (null == vec) { + return null; + } + x -= vec.x; + y -= vec.y; + z -= vec.z; + return this; + } + + /** + * subtract + * + * @param vec the vector to subtract from this + * @param result the vector to store the result in + * @return result + */ + public Vector3f subtract(Vector3f vec, Vector3f result) { + if (result == null) { + result = new Vector3f(); + } + result.x = x - vec.x; + result.y = y - vec.y; + result.z = z - vec.z; + return result; + } + + /** + * subtract subtracts the provided values from this vector, + * creating a new vector that is then returned. + * + * @param subtractX the x value to subtract. + * @param subtractY the y value to subtract. + * @param subtractZ the z value to subtract. + * @return the result vector. + */ + public Vector3f subtract(float subtractX, float subtractY, float subtractZ) { + return new Vector3f(x - subtractX, y - subtractY, z - subtractZ); + } + + /** + * subtractLocal subtracts the provided values from this vector + * internally, and returns a handle to this vector for easy chaining of + * calls. + * + * @param subtractX the x value to subtract. + * @param subtractY the y value to subtract. + * @param subtractZ the z value to subtract. + * @return this + */ + public Vector3f subtractLocal(float subtractX, float subtractY, float subtractZ) { + x -= subtractX; + y -= subtractY; + z -= subtractZ; + return this; + } + + /** + * normalize returns the unit vector of this vector. + * + * @return unit vector of this vector. + */ + public Vector3f normalize() { + float length = length(); + if (length != 0) { + return divide(length); + } + + return divide(1); + } + + /** + * normalizeLocal makes this vector into a unit vector of + * itself. + * + * @return this. + */ + public Vector3f normalizeLocal() { + float length = length(); + if (length != 0) { + return divideLocal(length); + } + + return this; + } + + /** + * zero resets this vector's data to zero internally. + */ + public void zero() { + x = y = z = 0; + } + + /** + * angleBetween returns (in radians) the angle between two + * vectors. It is assumed that both this vector and the given vector are + * unit vectors (iow, normalized). + * + * @param otherVector a unit vector to find the angle against + * @return the angle in radians. + */ + public float angleBetween(Vector3f otherVector) { + float dotProduct = dot(otherVector); + return FastMath.acos(dotProduct); + } + + /** + * Sets this vector to the interpolation by changeAmnt from this to the + * finalVec this=(1-changeAmnt)*this + changeAmnt * finalVec + * + * @param finalVec The final vector to interpolate towards + * @param changeAmnt An amount between 0.0 - 1.0 representing a percentage change + * from this towards finalVec + */ + public void interpolate(Vector3f finalVec, float changeAmnt) { + this.x = (1 - changeAmnt) * this.x + changeAmnt * finalVec.x; + this.y = (1 - changeAmnt) * this.y + changeAmnt * finalVec.y; + this.z = (1 - changeAmnt) * this.z + changeAmnt * finalVec.z; + } + + public Vector3f lerp(Vector3f finalVec, float changeAmnt) { + float x = (1 - changeAmnt) * this.x + changeAmnt * finalVec.x; + float y = (1 - changeAmnt) * this.y + changeAmnt * finalVec.y; + float z = (1 - changeAmnt) * this.z + changeAmnt * finalVec.z; + return new Vector3f(x, y, z); + } + + /** + * Sets this vector to the interpolation by changeAmnt from beginVec to + * finalVec this=(1-changeAmnt)*beginVec + changeAmnt * finalVec + * + * @param beginVec the beginning vector (changeAmnt=0) + * @param finalVec The final vector to interpolate towards + * @param changeAmnt An amount between 0.0 - 1.0 representing a percentage change + * from beginVec towards finalVec + */ + public void interpolate(Vector3f beginVec, Vector3f finalVec, float changeAmnt) { + this.x = (1 - changeAmnt) * beginVec.x + changeAmnt * finalVec.x; + this.y = (1 - changeAmnt) * beginVec.y + changeAmnt * finalVec.y; + this.z = (1 - changeAmnt) * beginVec.z + changeAmnt * finalVec.z; + } + + @Override + public Vector3f clone() { + try { + return (Vector3f) super.clone(); + } catch (CloneNotSupportedException e) { + throw new AssertionError(); // can not happen + } + } + + /** + * Saves this Vector3f into the given float[] object. + * + * @param floats The float[] to take this Vector3f. If null, a new float[3] is + * created. + * @return The array, with X, Y, Z float values in that order + */ + public float[] toArray(float[] floats) { + if (floats == null) { + floats = new float[3]; + } + floats[0] = x; + floats[1] = y; + floats[2] = z; + return floats; + } + + /** + * are these two vectors the same? they are is they both have the same x,y, + * and z values. + * + * @param o the object to compare for equality + * @return true if they are equal + */ + @Override + public boolean equals(Object o) { + if (!(o instanceof Vector3f)) { + return false; + } + + if (this == o) { + return true; + } + + Vector3f comp = (Vector3f) o; + if (Float.compare(x, comp.x) != 0) + return false; + if (Float.compare(y, comp.y) != 0) + return false; return Float.compare(z, comp.z) == 0; } - /** - * hashCode returns a unique code for this vector object based - * on it's values. If two vectors are logically equivalent, they will return - * the same hash code value. - * - * @return the hash code value of this vector. - */ - @Override - public int hashCode() { - int hash = 37; - hash += 37 * hash + Float.floatToIntBits(x); - hash += 37 * hash + Float.floatToIntBits(y); - hash += 37 * hash + Float.floatToIntBits(z); - return hash; - } - - /** - * Used with serialization. Not to be called manually. - * - * @param in - * input - * @throws IOException - * @throws ClassNotFoundException - * @see java.io.Externalizable - */ - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - x = in.readFloat(); - y = in.readFloat(); - z = in.readFloat(); - } - - /** - * Used with serialization. Not to be called manually. - * - * @param out - * output - * @throws IOException - * @see java.io.Externalizable - */ - public void writeExternal(ObjectOutput out) throws IOException { - out.writeFloat(x); - out.writeFloat(y); - out.writeFloat(z); - } - - public float getX() { - return x; - } - - public void setX(float x) { - this.x = x; - } - - public float getY() { - return y; - } - - public void setY(float y) { - this.y = y; - } - - public float getZ() { - return z; - } - - public void setZ(float z) { - this.z = z; - } - - /** - * @param index - * @return x value if index == 0, y value if index == 1 or z value if index - * == 2 - * @throws IllegalArgumentException - * if index is not one of 0, 1, 2. - */ - public float get(int index) { - switch (index) { - case 0: - return x; - case 1: - return y; - case 2: - return z; - } - throw new IllegalArgumentException("index must be either 0, 1 or 2"); - } - - /** - * @param index - * which field index in this vector to set. - * @param value - * to set to one of x, y or z. - * @throws IllegalArgumentException - * if index is not one of 0, 1, 2. - */ - public void set(int index, float value) { - switch (index) { - case 0: - x = value; - return; - case 1: - y = value; - return; - case 2: - z = value; - return; - } - throw new IllegalArgumentException("index must be either 0, 1 or 2"); - } - - /** - * Gets an offset from this position based on rotation around Y(up/down)-axis. - * - * @param rotation - * Rotation in radians - * @param xOffset - * Amount to offset along x axis (left negative, right positive) - * @param yOffset - * Amount to offset along y axis (down negative, up positive) - * @param zOffset - * Amount to offset along z axis (backwards negative, forwards positive) - * @param invertZ - * whether to invert the z axis - */ - public Vector3f getOffset(float rotation, float xOffset, float yOffset, float zOffset, boolean invertZ) { - float sin = FastMath.sin(rotation); - float cos = FastMath.cos(rotation); - Vector3f faceDir = new Vector3f(sin, 0f, cos); - Vector3f crossDir = new Vector3f(cos, 0f, sin); - faceDir.multLocal(zOffset); - crossDir.multLocal(xOffset); - if (invertZ) { - faceDir.z = -faceDir.z; - crossDir.z = -crossDir.z; - } - Vector3f loc = new Vector3f(this); - loc.addLocal(faceDir); - loc.addLocal(crossDir); - loc.y += yOffset; - return loc; - } - - /** - * Returns the 2D face direction from rotation. - * - * @param rotation - * Rotation in radians - */ - public static Vector3f getFaceDir(float rotation) { - return new Vector3f(FastMath.sin(rotation), 0f, FastMath.cos(rotation)); - } - - /** - * Returns the 2D cross direction (perpendicular face direction) from rotation. - * - * @param rotation - * Rotation in radians - */ - public static Vector3f getCrossDir(float rotation) { - return new Vector3f(FastMath.cos(rotation), 0f, FastMath.sin(rotation)); - } - - /** - * Returns the 2D rotation (around Y-axis) in radians. - * - * @return - */ - public float getRotation() { - return 3.14f + FastMath.atan2(-x, -z); - } - - /** - * Gets the XYZ component of this Vector3f - * - * @return - */ - public Vector2f getLatLong() { - return new Vector2f(this.x, this.z); - } - - public synchronized float getLat() { - return x; - } - - public synchronized float getLong() { - return z; - } - - public synchronized float getAlt() { - return y; - } - - public synchronized void setLat(float lat) { - this.x = lat; - } - - public synchronized void setLong(float lon) { - this.z = lon; - } - - public synchronized void setAlt(float alt) { - this.y = alt; - } - - public static Vector3f rotateAroundPoint(Vector3f origin, Vector3f point, double angle) { - - float angleRadians; - double modifiedAngle; - - // Convert angle to radians - - modifiedAngle = angle; - - if (angle < 0) - modifiedAngle = 360 + modifiedAngle; - - angleRadians = (float) Math.toRadians(modifiedAngle); - - return rotateAroundPoint(origin, point, angleRadians); - } - - public static Vector3f rotateAroundPoint(Vector3f origin, Vector3f point, float radians) { - - Vector3f outVector; - Vector3f directionVector; - Quaternion angleRotation; - - // Build direction vector relative to origin - - directionVector = new Vector3f(point.subtract(origin)); + /** + * hashCode returns a unique code for this vector object based + * on it's values. If two vectors are logically equivalent, they will return + * the same hash code value. + * + * @return the hash code value of this vector. + */ + @Override + public int hashCode() { + int hash = 37; + hash += 37 * hash + Float.floatToIntBits(x); + hash += 37 * hash + Float.floatToIntBits(y); + hash += 37 * hash + Float.floatToIntBits(z); + return hash; + } + + /** + * Used with serialization. Not to be called manually. + * + * @param in input + * @throws IOException + * @throws ClassNotFoundException + * @see java.io.Externalizable + */ + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + x = in.readFloat(); + y = in.readFloat(); + z = in.readFloat(); + } - // Build quaternion rotation + /** + * Used with serialization. Not to be called manually. + * + * @param out output + * @throws IOException + * @see java.io.Externalizable + */ + public void writeExternal(ObjectOutput out) throws IOException { + out.writeFloat(x); + out.writeFloat(y); + out.writeFloat(z); + } - angleRotation = new Quaternion().fromAngleAxis(radians, new Vector3f(0,1,0)); + public float getX() { + return x; + } - // Apply rotation to direction vector + public void setX(float x) { + this.x = x; + } - directionVector = angleRotation.mult(directionVector); + public float getY() { + return y; + } - // Translate from origin back to new rotated point + public void setY(float y) { + this.y = y; + } - outVector = origin.add(directionVector); + public float getZ() { + return z; + } - return outVector; + public void setZ(float z) { + this.z = z; + } - } + /** + * @param index + * @return x value if index == 0, y value if index == 1 or z value if index + * == 2 + * @throws IllegalArgumentException if index is not one of 0, 1, 2. + */ + public float get(int index) { + switch (index) { + case 0: + return x; + case 1: + return y; + case 2: + return z; + } + throw new IllegalArgumentException("index must be either 0, 1 or 2"); + } - @Override - public String toString() { - String out = ""; - out += "x=" + x + ", "; - out += "y=" + y + ", "; - out += "z=" + z; - return out; - } + /** + * @param index which field index in this vector to set. + * @param value to set to one of x, y or z. + * @throws IllegalArgumentException if index is not one of 0, 1, 2. + */ + public void set(int index, float value) { + switch (index) { + case 0: + x = value; + return; + case 1: + y = value; + return; + case 2: + z = value; + return; + } + throw new IllegalArgumentException("index must be either 0, 1 or 2"); + } - public static Vector3f min(Vector3f vectorA, Vector3f vectorB) { + /** + * Gets an offset from this position based on rotation around Y(up/down)-axis. + * + * @param rotation Rotation in radians + * @param xOffset Amount to offset along x axis (left negative, right positive) + * @param yOffset Amount to offset along y axis (down negative, up positive) + * @param zOffset Amount to offset along z axis (backwards negative, forwards positive) + * @param invertZ whether to invert the z axis + */ + public Vector3f getOffset(float rotation, float xOffset, float yOffset, float zOffset, boolean invertZ) { + float sin = FastMath.sin(rotation); + float cos = FastMath.cos(rotation); + Vector3f faceDir = new Vector3f(sin, 0f, cos); + Vector3f crossDir = new Vector3f(cos, 0f, sin); + faceDir.multLocal(zOffset); + crossDir.multLocal(xOffset); + if (invertZ) { + faceDir.z = -faceDir.z; + crossDir.z = -crossDir.z; + } + Vector3f loc = new Vector3f(this); + loc.addLocal(faceDir); + loc.addLocal(crossDir); + loc.y += yOffset; + return loc; + } - return new Vector3f(Math.min(vectorA.x, vectorB.x), - Math.min(vectorA.y, vectorB.y), - Math.min(vectorA.z, vectorB.z)); - } + /** + * Returns the 2D rotation (around Y-axis) in radians. + * + * @return + */ + public float getRotation() { + return 3.14f + FastMath.atan2(-x, -z); + } - public static Vector3f max(Vector3f vectorA, Vector3f vectorB) { + /** + * Gets the XYZ component of this Vector3f + * + * @return + */ + public Vector2f getLatLong() { + return new Vector2f(this.x, this.z); + } - return new Vector3f(Math.max(vectorA.x, vectorB.x), - Math.max(vectorA.y, vectorB.y), - Math.max(vectorA.z, vectorB.z)); - } - - public static Vector3f rotateAroundPoint(Vector3f origin, Vector3f point,Quaternion angleRotation) { + public synchronized float getLat() { + return x; + } + + public synchronized void setLat(float lat) { + this.x = lat; + } - Vector3f outVector; - Vector3f directionVector; - // Build direction vector relative to origin - directionVector = new Vector3f(point.subtract(origin)); - directionVector = angleRotation.mult(directionVector); + public synchronized float getLong() { + return z; + } - // Translate from origin back to new rotated point + public synchronized void setLong(float lon) { + this.z = lon; + } - outVector = origin.add(directionVector); + public synchronized float getAlt() { + return y; + } - return outVector; + public synchronized void setAlt(float alt) { + this.y = alt; + } - } + @Override + public String toString() { + String out = ""; + out += "x=" + x + ", "; + out += "y=" + y + ", "; + out += "z=" + z; + return out; + } } diff --git a/src/engine/math/Vector3fImmutable.java b/src/engine/math/Vector3fImmutable.java index 5e9bd32b..4c5bf4ad 100644 --- a/src/engine/math/Vector3fImmutable.java +++ b/src/engine/math/Vector3fImmutable.java @@ -17,579 +17,576 @@ import static engine.math.FastMath.sqr; public class Vector3fImmutable { - public final float x, y, z; - - public Vector3fImmutable() { - x = y = z = 0.0f; - } - - public Vector3fImmutable(float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - } - - public Vector3fImmutable(Vector3f original) { - this.x = original.x; - this.y = original.y; - this.z = original.z; - } - - public Vector3fImmutable(Vector3fImmutable original) { - this.x = original.x; - this.y = original.y; - this.z = original.z; - } - - public boolean isInsideCircle(Vector3fImmutable circleCenter, float radius) { - - return (circleCenter.distanceSquared2D(this) < sqr(radius)); - } - - public Vector3fImmutable add(Vector3f vec) { - if (null == vec) - return null; - return new Vector3fImmutable(x + vec.x, y + vec.y, z + vec.z); - } - - public Vector3fImmutable add(Vector3fImmutable vec) { - if (null == vec) - return null; - return new Vector3fImmutable(x + vec.x, y + vec.y, z + vec.z); - } - - public Vector3fImmutable add(float x, float y, float z) { - return new Vector3fImmutable(this.x + x, this.y + y, this.z + z); - } - - public Vector3fImmutable scaleAdd(float scalar, Vector3fImmutable add) { - return new Vector3fImmutable(x * scalar + add.x, y * scalar + add.y , z - * scalar + add.z); - } - - public static Vector3fImmutable scaleAdd(float scalar, Vector3fImmutable mult, - Vector3fImmutable add) { - return new Vector3fImmutable(mult.x * scalar + add.x, mult.y * scalar - + add.y, mult.z * scalar + add.z); - } - - public float dot(Vector3fImmutable vec) { - if (null == vec) { - return 0.0f; - } - - return x * vec.x + y * vec.y + z * vec.z; - } - - public float dot2D(Vector3fImmutable vec) { - if (null == vec) { - return 0.0f; - } - - return x * vec.x + z * vec.z; - } - - public Vector3fImmutable cross(Vector3fImmutable v) { - return cross(v.x, v.y, v.z); - } - - public Vector3fImmutable cross(float x, float y, float z) { - return new Vector3fImmutable(this.y * z - this.z * y, this.z * x - - this.x * z, this.x * y - this.y * x); - } - - public float length() { - return FastMath.sqrt(lengthSquared()); - } - - public float lengthSquared() { - return x * x + y * y + z * z; - } - - public float distanceSquared(Vector3fImmutable v) { - double dx = x - v.x; - double dy = y - v.y; - double dz = z - v.z; - return (float) (dx * dx + dy * dy + dz * dz); - } - - public float magnitude() { - return FastMath.sqrt(sqrMagnitude()); - } - - public float sqrMagnitude() { - return x * x + y * y + z * z; - } - - public Vector3fImmutable moveTowards (Vector3fImmutable target, float maxDistanceDelta) - { - Vector3fImmutable outVector; - - Vector3fImmutable direction = target.subtract2D(this); - float magnitude = direction.magnitude(); - - if (magnitude <= maxDistanceDelta || magnitude == 0f) - { - return target; - } - - outVector = direction.divide(magnitude).mult(maxDistanceDelta); - outVector = this.add(outVector); - return outVector; - } - - public float distanceSquared2D(Vector3fImmutable v) { - double dx = x - v.x; - double dz = z - v.z; - return (float) (dx * dx + dz * dz); - } - - public float distance(Vector3fImmutable v) { - return FastMath.sqrt(distanceSquared(v)); - } - - public float distance2D(Vector3fImmutable v) { - return FastMath.sqrt(distanceSquared2D(v)); - } - - public Vector3fImmutable mult(float scalar) { - return new Vector3fImmutable(x * scalar, y * scalar, z * scalar); - } - - public Vector3fImmutable mult(Vector3fImmutable vec) { - if (null == vec) { - return null; - } - - return new Vector3fImmutable(x * vec.x, y * vec.y, z * vec.z); - } - - public Vector3fImmutable divide(float scalar) { - scalar = 1f / scalar; - return new Vector3fImmutable(x * scalar, y * scalar, z * scalar); - } - - public Vector3fImmutable divide(Vector3fImmutable scalar) { - return new Vector3fImmutable(x / scalar.x, y / scalar.y, z / scalar.z); - } - - public Vector3fImmutable negate() { - return new Vector3fImmutable(-x, -y, -z); - } - - public Vector3fImmutable subtract(Vector3fImmutable vec) { - return new Vector3fImmutable(x - vec.x, y - vec.y, z - vec.z); - } - - public Vector3fImmutable subtract2D(Vector3fImmutable vec) { - return new Vector3fImmutable(x - vec.x, 0, z - vec.z); - } - - public Vector3fImmutable subtract(float x, float y, float z) { - return new Vector3fImmutable(this.x - x, this.y - y, this.z - z); - } - - public Vector3fImmutable normalize() { - float length = length(); - if (length != 0) { - return divide(length); - } - - return divide(1); - } - - public float angleBetween(Vector3fImmutable otherVector) { - float dotProduct = dot(otherVector); - return FastMath.acos(dotProduct); - } - - public float angleBetween2D(Vector3fImmutable otherVector) { - float dotProduct = dot(otherVector); - return FastMath.acos(dotProduct); - } - - public Vector3fImmutable interpolate(Vector3f finalVec, float changeAmnt) { - return new Vector3fImmutable((1 - changeAmnt) * this.x + changeAmnt - * finalVec.x, (1 - changeAmnt) * this.y + changeAmnt - * finalVec.y, (1 - changeAmnt) * this.z + changeAmnt - * finalVec.z); - } - - public Vector3fImmutable interpolate(Vector3fImmutable finalVec, float changeAmnt) { - return new Vector3fImmutable((1 - changeAmnt) * this.x + changeAmnt - * finalVec.x, (1 - changeAmnt) * this.y + changeAmnt - * finalVec.y, (1 - changeAmnt) * this.z + changeAmnt - * finalVec.z); - } - - - public static boolean isValidVector(Vector3fImmutable vector) { - if (vector == null) - return false; - if (Float.isNaN(vector.x) || Float.isNaN(vector.y) - || Float.isNaN(vector.z)) - return false; - return !Float.isInfinite(vector.x) && !Float.isInfinite(vector.y) - && !Float.isInfinite(vector.z); - } - - @Override - public Vector3fImmutable clone() throws CloneNotSupportedException { - return (Vector3fImmutable) super.clone(); - } - - public float[] toArray(float[] floats) { - if (floats == null) { - floats = new float[3]; - } - floats[0] = x; - floats[1] = y; - floats[2] = z; - return floats; - } - - @Override - public boolean equals(Object o) { - if (!(o instanceof Vector3fImmutable)) { - return false; - } - - if (this == o) { - return true; - } - - Vector3fImmutable comp = (Vector3fImmutable) o; - if (Float.compare(x, comp.x) != 0) - return false; - if (Float.compare(y, comp.y) != 0) - return false; - return Float.compare(z, comp.z) == 0; - } - - @Override - public int hashCode() { - int hash = 37; - hash += 37 * hash + Float.floatToIntBits(x); - hash += 37 * hash + Float.floatToIntBits(y); - hash += 37 * hash + Float.floatToIntBits(z); - return hash; - } - - public static Vector3fImmutable readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - return new Vector3fImmutable(in.readFloat(), in.readFloat(), in - .readFloat()); - } - - public void writeExternal(ObjectOutput out) throws IOException { - out.writeFloat(x); - out.writeFloat(y); - out.writeFloat(z); - } - - public Vector3fImmutable getOffset(float rotation, float xOffset, float yOffset, float zOffset, boolean invertZ) { - float sin = FastMath.sin(rotation); - float cos = FastMath.cos(rotation); - Vector3f faceDir = new Vector3f(sin, 0f, cos); - Vector3f crossDir = new Vector3f(cos, 0f, sin); - faceDir.multLocal(zOffset); - crossDir.multLocal(xOffset); - if (invertZ) { - faceDir.z = -faceDir.z; - crossDir.z = -crossDir.z; - } - Vector3f loc = new Vector3f(this); - loc.addLocal(faceDir); - loc.addLocal(crossDir); - loc.y += yOffset; - return new Vector3fImmutable(loc); - } - - public float getX() { - return x; - } - - public float getY() { - return y; - } - - public float getZ() { - return z; - } - - public float get(int index) { - switch (index) { - case 0: - return x; - case 1: - return y; - case 2: - return z; - } - throw new IllegalArgumentException("index must be either 0, 1 or 2"); - } - - public Vector2f getLatLong() { - return new Vector2f(this.x, this.z); - } - - public synchronized float getLat() { - return x; - } - - public synchronized float getLong() { - return z; - } - - public synchronized float getAlt() { - return y; - } - - public Vector3fImmutable setX(float x) { - return new Vector3fImmutable(x, y, z); - } - - public Vector3fImmutable setY(float y) { - return new Vector3fImmutable(x, y, z); - } - - public Vector3fImmutable setZ(float z) { - return new Vector3fImmutable(x, y, z); - } + public static final Vector3fImmutable ZERO = new Vector3fImmutable(0, 0, 0); + public final float x, y, z; - public float getRotation() { - return 3.14f + FastMath.atan2(-x, -z); - } - public boolean inRange2D(Vector3fImmutable otherVec, float range){ - float distance = this.distanceSquared2D(otherVec); - return !(distance > range * range); - } + public Vector3fImmutable() { + x = y = z = 0.0f; + } - public static String toString(Vector3fImmutable vector) { + public Vector3fImmutable(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + } - return vector.toString(); - } + public Vector3fImmutable(Vector3f original) { + this.x = original.x; + this.y = original.y; + this.z = original.z; + } - @Override - public String toString() { + public Vector3fImmutable(Vector3fImmutable original) { + this.x = original.x; + this.y = original.y; + this.z = original.z; + } - String outString; + public static Vector3fImmutable scaleAdd(float scalar, Vector3fImmutable mult, + Vector3fImmutable add) { + return new Vector3fImmutable(mult.x * scalar + add.x, mult.y * scalar + + add.y, mult.z * scalar + add.z); + } - outString = "(" + this.x + '/' + this.y + '/' + this.z; - return outString; + public static boolean isValidVector(Vector3fImmutable vector) { + if (vector == null) + return false; + if (Float.isNaN(vector.x) || Float.isNaN(vector.y) + || Float.isNaN(vector.z)) + return false; + return !Float.isInfinite(vector.x) && !Float.isInfinite(vector.y) + && !Float.isInfinite(vector.z); + } - } + public static Vector3fImmutable readExternal(ObjectInput in) + throws IOException, ClassNotFoundException { + return new Vector3fImmutable(in.readFloat(), in.readFloat(), in + .readFloat()); + } - public String toString2D() { + public static String toString(Vector3fImmutable vector) { - String outString; + return vector.toString(); + } - outString = "( " + (int)this.x + " , " + (int)(this.z *-1) +" )"; - return outString; + public static Vector3fImmutable ClosestPointOnLine(Vector3fImmutable lineStart, Vector3fImmutable lineEnd, Vector3fImmutable sourcePoint) { - } + Vector3fImmutable closestPoint; + Vector3fImmutable lineStartToTarget; + Vector3fImmutable lineDirection; + float lineLength; + float dotProduct; - public static Vector3fImmutable ClosestPointOnLine(Vector3fImmutable lineStart, Vector3fImmutable lineEnd, Vector3fImmutable sourcePoint) { + lineStartToTarget = sourcePoint.subtract(lineStart); + lineDirection = lineEnd.subtract(lineStart).normalize(); + lineLength = lineStart.distance2D(lineEnd); - Vector3fImmutable closestPoint; - Vector3fImmutable lineStartToTarget; - Vector3fImmutable lineDirection; - float lineLength; - float dotProduct; + dotProduct = lineDirection.dot(lineStartToTarget); - lineStartToTarget = sourcePoint.subtract(lineStart); - lineDirection = lineEnd.subtract(lineStart).normalize(); - lineLength = lineStart.distance2D(lineEnd); + if (dotProduct <= 0) + return lineStart; - dotProduct = lineDirection.dot(lineStartToTarget); + if (dotProduct >= lineLength) + return lineEnd; - if (dotProduct <= 0) - return lineStart; + // Project the point by advancing it along the line from + // the starting point. - if (dotProduct >= lineLength) - return lineEnd; + closestPoint = lineDirection.mult(dotProduct); + closestPoint = lineStart.add(closestPoint); - // Project the point by advancing it along the line from - // the starting point. + return closestPoint; + } - closestPoint = lineDirection.mult(dotProduct); - closestPoint = lineStart.add(closestPoint); + public static Vector3fImmutable rotateAroundPoint(Vector3fImmutable origin, Vector3fImmutable point, int angle) { - return closestPoint; - } + float angleRadians; + int modifiedAngle; - public Vector3fImmutable ClosestPointOnLine(Vector3fImmutable lineStart, Vector3fImmutable lineEnd) { + // Convert angle to radians - Vector3fImmutable closestPoint; - Vector3fImmutable lineStartToTarget; - Vector3fImmutable lineDirection; - float lineLength; - float dotProduct; + modifiedAngle = angle; - lineStartToTarget = this.subtract(lineStart); - lineDirection = lineEnd.subtract(lineStart).normalize(); - lineLength = lineStart.distance2D(lineEnd); + if (angle < 0) + modifiedAngle = 360 + modifiedAngle; - dotProduct = lineDirection.dot(lineStartToTarget); + angleRadians = (float) Math.toRadians(modifiedAngle); - if (dotProduct <= 0) - return lineStart; + return rotateAroundPoint(origin, point, angleRadians); + } - if (dotProduct >= lineLength) - return lineEnd; + public static Vector3fImmutable rotateAroundPoint(Vector3fImmutable origin, Vector3fImmutable point, float radians) { - // Project the point by advancing it along the line from - // the starting point. + Vector3fImmutable outVector; + Vector3f directionVector; + Quaternion angleRotation; - closestPoint = lineDirection.mult(dotProduct); - closestPoint = lineStart.add(closestPoint); + // Build direction vector relative to origin - return closestPoint; - } + directionVector = new Vector3f(point.subtract(origin)); - public static Vector3fImmutable rotateAroundPoint(Vector3fImmutable origin, Vector3fImmutable point, int angle) { + // Build quaternion rotation - float angleRadians; - int modifiedAngle; + angleRotation = new Quaternion().fromAngleAxis(radians, new Vector3f(0, 1, 0)); + // Apply rotation to direction vector - // Convert angle to radians + directionVector = angleRotation.mult(directionVector); - modifiedAngle = angle; + // Translate from origin back to new rotated point - if (angle < 0) - modifiedAngle = 360 + modifiedAngle; + outVector = origin.add(directionVector); - angleRadians = (float) Math.toRadians(modifiedAngle); + return outVector; - return rotateAroundPoint(origin, point, angleRadians); - } + } - public static Vector3fImmutable rotateAroundPoint(Vector3fImmutable origin, Vector3fImmutable point, float radians) { + public static Vector3fImmutable rotateAroundPoint(Vector3fImmutable origin, Vector3fImmutable point, Quaternion angleRotation) { - Vector3fImmutable outVector; - Vector3f directionVector; - Quaternion angleRotation; + Vector3fImmutable outVector; + Vector3f directionVector; + // Build direction vector relative to origin + directionVector = new Vector3f(point.subtract(origin)); - // Build direction vector relative to origin + // Build quaternion rotation - directionVector = new Vector3f(point.subtract(origin)); - // Build quaternion rotation + // Apply rotation to direction vector - angleRotation = new Quaternion().fromAngleAxis(radians, new Vector3f(0,1,0)); - // Apply rotation to direction vector - directionVector = angleRotation.mult(directionVector); + directionVector = angleRotation.mult(directionVector); - // Translate from origin back to new rotated point + // Translate from origin back to new rotated point - outVector = origin.add(directionVector); + outVector = origin.add(directionVector); - return outVector; + return outVector; - } - - public static Vector3fImmutable rotateAroundPoint(Vector3fImmutable origin, Vector3fImmutable point,Quaternion angleRotation) { + } - Vector3fImmutable outVector; - Vector3f directionVector; - // Build direction vector relative to origin - directionVector = new Vector3f(point.subtract(origin)); + public static Vector3fImmutable rotateAroundPoint(Vector3fImmutable origin, Vector3fImmutable point, float w, Vector3f axis) { - // Build quaternion rotation + Vector3fImmutable outVector; + Vector3f directionVector; + Quaternion angleRotation; + // Build direction vector relative to origin - // Apply rotation to direction vector - + directionVector = new Vector3f(point.subtract(origin)); - directionVector = angleRotation.mult(directionVector); + // Build quaternion rotation - // Translate from origin back to new rotated point + angleRotation = new Quaternion().fromAngleAxis(w, axis); + // Apply rotation to direction vector - outVector = origin.add(directionVector); + directionVector = angleRotation.mult(directionVector); - return outVector; + // Translate from origin back to new rotated point - } - - public static Vector3fImmutable rotateAroundPoint(Vector3fImmutable origin, Vector3fImmutable point, float w, Vector3f axis) { + outVector = origin.add(directionVector); - Vector3fImmutable outVector; - Vector3f directionVector; - Quaternion angleRotation; + return outVector; - // Build direction vector relative to origin + } - directionVector = new Vector3f(point.subtract(origin)); + public static Vector3fImmutable getRandomPointInCircle(Vector3fImmutable origin, float radius) { + // Member variables - // Build quaternion rotation + float targetAngle; + float targetRadius; + Vector3fImmutable targetPosition; - angleRotation = new Quaternion().fromAngleAxis(w, axis); - // Apply rotation to direction vector + targetAngle = (float) (ThreadLocalRandom.current().nextFloat() * Math.PI * 2); + targetRadius = (float) (Math.sqrt(ThreadLocalRandom.current().nextFloat()) * radius); + targetPosition = new Vector3fImmutable((float) (origin.x + targetRadius * Math.cos(targetAngle)), origin.y, (float) (origin.z + targetRadius * Math.sin(targetAngle))); + return targetPosition; + } - directionVector = angleRotation.mult(directionVector); + public static Vector3fImmutable getLocBetween(Vector3fImmutable start, Vector3fImmutable end) { + // Member variables - // Translate from origin back to new rotated point + Vector3fImmutable faceDirection = end.subtract(start).normalize(); + float distance = end.distance(start) * .5f; + return faceDirection.scaleAdd(distance, start); + } - outVector = origin.add(directionVector); + public static Vector3fImmutable getRandomPointOnCircle(Vector3fImmutable origin, float radius) { - return outVector; + // Member variables - } + int randomAngle; + Vector3fImmutable targetPosition; - public static Vector3fImmutable getRandomPointInCircle(Vector3fImmutable origin, float radius) { - // Member variables + randomAngle = ThreadLocalRandom.current().nextInt(360); - float targetAngle; - float targetRadius; - Vector3fImmutable targetPosition; + targetPosition = new Vector3fImmutable((float) (origin.x + radius * Math.cos(randomAngle)), origin.y, (float) (origin.z + radius * Math.sin(randomAngle))); + return targetPosition; + } - targetAngle = (float) (ThreadLocalRandom.current().nextFloat() * Math.PI * 2); - targetRadius = (float) (Math.sqrt(ThreadLocalRandom.current().nextFloat()) * radius); - targetPosition = new Vector3fImmutable((float) (origin.x + targetRadius * Math.cos(targetAngle)), origin.y, (float) (origin.z + targetRadius * Math.sin(targetAngle))); - return targetPosition; - } - - public static Vector3fImmutable getLocBetween(Vector3fImmutable start, Vector3fImmutable end) { - // Member variables + public static Vector3fImmutable transform(Vector3fImmutable origin, Vector3fImmutable point, float angle) { - Vector3fImmutable faceDirection = end.subtract(start).normalize(); - float distance = end.distance(start) * .5f; - return faceDirection.scaleAdd(distance, start); - } + //TRANSLATE TO ORIGIN + float x1 = point.x - origin.x; + float y1 = point.z - origin.z; - public static Vector3fImmutable getRandomPointOnCircle(Vector3fImmutable origin, float radius) { + //APPLY ROTATION + float temp_x1 = (float) (x1 * Math.cos(angle) - y1 * Math.sin(angle)); + float temp_z1 = (float) (x1 * Math.sin(angle) + y1 * Math.cos(angle)); + + temp_x1 += origin.x; + temp_z1 += origin.z; + + return new Vector3fImmutable(temp_x1, point.y, temp_z1); + } - // Member variables + public boolean isInsideCircle(Vector3fImmutable circleCenter, float radius) { + + return (circleCenter.distanceSquared2D(this) < sqr(radius)); + } + + public Vector3fImmutable add(Vector3f vec) { + if (null == vec) + return null; + return new Vector3fImmutable(x + vec.x, y + vec.y, z + vec.z); + } + + public Vector3fImmutable add(Vector3fImmutable vec) { + if (null == vec) + return null; + return new Vector3fImmutable(x + vec.x, y + vec.y, z + vec.z); + } + + public Vector3fImmutable add(float x, float y, float z) { + return new Vector3fImmutable(this.x + x, this.y + y, this.z + z); + } + + public Vector3fImmutable scaleAdd(float scalar, Vector3fImmutable add) { + return new Vector3fImmutable(x * scalar + add.x, y * scalar + add.y, z + * scalar + add.z); + } + + public float dot(Vector3fImmutable vec) { + if (null == vec) { + return 0.0f; + } + + return x * vec.x + y * vec.y + z * vec.z; + } + + public float dot2D(Vector3fImmutable vec) { + if (null == vec) { + return 0.0f; + } + + return x * vec.x + z * vec.z; + } + + public Vector3fImmutable cross(Vector3fImmutable v) { + return cross(v.x, v.y, v.z); + } + + public Vector3fImmutable cross(float x, float y, float z) { + return new Vector3fImmutable(this.y * z - this.z * y, this.z * x + - this.x * z, this.x * y - this.y * x); + } + + public float length() { + return FastMath.sqrt(lengthSquared()); + } + + public float lengthSquared() { + return x * x + y * y + z * z; + } + + public float distanceSquared(Vector3fImmutable v) { + double dx = x - v.x; + double dy = y - v.y; + double dz = z - v.z; + return (float) (dx * dx + dy * dy + dz * dz); + } + + public float magnitude() { + return FastMath.sqrt(sqrMagnitude()); + } + + public float sqrMagnitude() { + return x * x + y * y + z * z; + } + + public Vector3fImmutable moveTowards(Vector3fImmutable target, float maxDistanceDelta) { + Vector3fImmutable outVector; + + Vector3fImmutable direction = target.subtract2D(this); + float magnitude = direction.magnitude(); + + if (magnitude <= maxDistanceDelta || magnitude == 0f) { + return target; + } + + outVector = direction.divide(magnitude).mult(maxDistanceDelta); + outVector = this.add(outVector); + return outVector; + } + + public float distanceSquared2D(Vector3fImmutable v) { + double dx = x - v.x; + double dz = z - v.z; + return (float) (dx * dx + dz * dz); + } + + public float distance(Vector3fImmutable v) { + return FastMath.sqrt(distanceSquared(v)); + } + + public float distance2D(Vector3fImmutable v) { + return FastMath.sqrt(distanceSquared2D(v)); + } + + public Vector3fImmutable mult(float scalar) { + return new Vector3fImmutable(x * scalar, y * scalar, z * scalar); + } + + public Vector3fImmutable mult(Vector3fImmutable vec) { + if (null == vec) { + return null; + } + + return new Vector3fImmutable(x * vec.x, y * vec.y, z * vec.z); + } + + public Vector3fImmutable divide(float scalar) { + scalar = 1f / scalar; + return new Vector3fImmutable(x * scalar, y * scalar, z * scalar); + } + + public Vector3fImmutable divide(Vector3fImmutable scalar) { + return new Vector3fImmutable(x / scalar.x, y / scalar.y, z / scalar.z); + } + + public Vector3fImmutable negate() { + return new Vector3fImmutable(-x, -y, -z); + } + + public Vector3fImmutable subtract(Vector3fImmutable vec) { + return new Vector3fImmutable(x - vec.x, y - vec.y, z - vec.z); + } + + public Vector3fImmutable subtract2D(Vector3fImmutable vec) { + return new Vector3fImmutable(x - vec.x, 0, z - vec.z); + } + + public Vector3fImmutable subtract(float x, float y, float z) { + return new Vector3fImmutable(this.x - x, this.y - y, this.z - z); + } + + public Vector3fImmutable normalize() { + float length = length(); + if (length != 0) { + return divide(length); + } + + return divide(1); + } + + public float angleBetween(Vector3fImmutable otherVector) { + float dotProduct = dot(otherVector); + return FastMath.acos(dotProduct); + } + + public float angleBetween2D(Vector3fImmutable otherVector) { + float dotProduct = dot(otherVector); + return FastMath.acos(dotProduct); + } + + public Vector3fImmutable interpolate(Vector3f finalVec, float changeAmnt) { + return new Vector3fImmutable((1 - changeAmnt) * this.x + changeAmnt + * finalVec.x, (1 - changeAmnt) * this.y + changeAmnt + * finalVec.y, (1 - changeAmnt) * this.z + changeAmnt + * finalVec.z); + } + + public Vector3fImmutable interpolate(Vector3fImmutable finalVec, float changeAmnt) { + return new Vector3fImmutable((1 - changeAmnt) * this.x + changeAmnt + * finalVec.x, (1 - changeAmnt) * this.y + changeAmnt + * finalVec.y, (1 - changeAmnt) * this.z + changeAmnt + * finalVec.z); + } + + @Override + public Vector3fImmutable clone() throws CloneNotSupportedException { + return (Vector3fImmutable) super.clone(); + } + + public float[] toArray(float[] floats) { + if (floats == null) { + floats = new float[3]; + } + floats[0] = x; + floats[1] = y; + floats[2] = z; + return floats; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof Vector3fImmutable)) { + return false; + } + + if (this == o) { + return true; + } + + Vector3fImmutable comp = (Vector3fImmutable) o; + if (Float.compare(x, comp.x) != 0) + return false; + if (Float.compare(y, comp.y) != 0) + return false; + return Float.compare(z, comp.z) == 0; + } + + @Override + public int hashCode() { + int hash = 37; + hash += 37 * hash + Float.floatToIntBits(x); + hash += 37 * hash + Float.floatToIntBits(y); + hash += 37 * hash + Float.floatToIntBits(z); + return hash; + } + + public void writeExternal(ObjectOutput out) throws IOException { + out.writeFloat(x); + out.writeFloat(y); + out.writeFloat(z); + } + + public Vector3fImmutable getOffset(float rotation, float xOffset, float yOffset, float zOffset, boolean invertZ) { + float sin = FastMath.sin(rotation); + float cos = FastMath.cos(rotation); + Vector3f faceDir = new Vector3f(sin, 0f, cos); + Vector3f crossDir = new Vector3f(cos, 0f, sin); + faceDir.multLocal(zOffset); + crossDir.multLocal(xOffset); + if (invertZ) { + faceDir.z = -faceDir.z; + crossDir.z = -crossDir.z; + } + Vector3f loc = new Vector3f(this); + loc.addLocal(faceDir); + loc.addLocal(crossDir); + loc.y += yOffset; + return new Vector3fImmutable(loc); + } + + public float getX() { + return x; + } + + public Vector3fImmutable setX(float x) { + return new Vector3fImmutable(x, y, z); + } + + public float getY() { + return y; + } + + public Vector3fImmutable setY(float y) { + return new Vector3fImmutable(x, y, z); + } + + public float getZ() { + return z; + } + + public Vector3fImmutable setZ(float z) { + return new Vector3fImmutable(x, y, z); + } + + public float get(int index) { + switch (index) { + case 0: + return x; + case 1: + return y; + case 2: + return z; + } + throw new IllegalArgumentException("index must be either 0, 1 or 2"); + } + + public Vector2f getLatLong() { + return new Vector2f(this.x, this.z); + } + + public synchronized float getLat() { + return x; + } + + public synchronized float getLong() { + return z; + } + + public synchronized float getAlt() { + return y; + } + + public float getRotation() { + return 3.14f + FastMath.atan2(-x, -z); + } + + public boolean inRange2D(Vector3fImmutable otherVec, float range) { + float distance = this.distanceSquared2D(otherVec); + return !(distance > range * range); + } + + @Override + public String toString() { + + String outString; + + outString = "(" + this.x + '/' + this.y + '/' + this.z; + return outString; + + } + + public String toString2D() { + + String outString; + + outString = "( " + (int) this.x + " , " + (int) (this.z * -1) + " )"; + return outString; + + } + + public Vector3fImmutable ClosestPointOnLine(Vector3fImmutable lineStart, Vector3fImmutable lineEnd) { - int randomAngle; - Vector3fImmutable targetPosition; + Vector3fImmutable closestPoint; + Vector3fImmutable lineStartToTarget; + Vector3fImmutable lineDirection; + float lineLength; + float dotProduct; - randomAngle = ThreadLocalRandom.current().nextInt(360); + lineStartToTarget = this.subtract(lineStart); + lineDirection = lineEnd.subtract(lineStart).normalize(); + lineLength = lineStart.distance2D(lineEnd); - targetPosition = new Vector3fImmutable((float) (origin.x + radius * Math.cos(randomAngle)), origin.y, (float) (origin.z + radius * Math.sin(randomAngle))); - return targetPosition; - } + dotProduct = lineDirection.dot(lineStartToTarget); - public static final Vector3fImmutable ZERO = new Vector3fImmutable(0,0,0); - - public static Vector3fImmutable transform(Vector3fImmutable origin,Vector3fImmutable point, float angle){ - - //TRANSLATE TO ORIGIN - float x1 = point.x - origin.x; - float y1 = point.z - origin.z; + if (dotProduct <= 0) + return lineStart; + + if (dotProduct >= lineLength) + return lineEnd; + + // Project the point by advancing it along the line from + // the starting point. + + closestPoint = lineDirection.mult(dotProduct); + closestPoint = lineStart.add(closestPoint); + + return closestPoint; + } - //APPLY ROTATION - float temp_x1 = (float) (x1 * Math.cos(angle) - y1 * Math.sin(angle)); - float temp_z1 = (float) (x1 * Math.sin(angle) + y1 * Math.cos(angle)); - - temp_x1 += origin.x; - temp_z1 += origin.z; - - return new Vector3fImmutable(temp_x1,point.y,temp_z1); - } - public float Lerp(Vector3fImmutable dest, float lerpFactor) - { - return dest.subtract(this).mult(lerpFactor).add(this).y; - } + public float Lerp(Vector3fImmutable dest, float lerpFactor) { + return dest.subtract(this).mult(lerpFactor).add(this).y; + } } diff --git a/src/engine/net/AbstractConnection.java b/src/engine/net/AbstractConnection.java index 30d34ca8..8fb86d11 100644 --- a/src/engine/net/AbstractConnection.java +++ b/src/engine/net/AbstractConnection.java @@ -26,400 +26,387 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.ReentrantLock; public abstract class AbstractConnection implements -NetMsgHandler { - - private static final String error01 = "A byte buffer is being free()ed that is not of the size stored in ByteBufferPool. Size: %1%"; - private static final String error02 = "(IP=%1%): Socket has reached the maximum outbound buffer length of %2%. Moving on while we wait for data to be sent."; - - protected final SocketChannel sockChan; - protected final AbstractConnectionManager connMan; - protected final NetMsgFactory factory; - - protected long lastMsgTime = System.currentTimeMillis(); - protected long lastKeepAliveTime = System.currentTimeMillis(); - protected long lastOpcode = -1; - - protected ConcurrentLinkedQueue outbox = new ConcurrentLinkedQueue<>(); - protected ByteBuffer outBuf = null; - - protected final AtomicBoolean execTask = new AtomicBoolean(false); - - protected ConcurrentHashMap cacheList; - - protected final ReentrantLock writeLock = new ReentrantLock(); - protected final ReentrantLock readLock = new ReentrantLock(); - protected long nextWriteTime = 0L; - protected Protocol lastProtocol = Protocol.NONE; - protected static final long SOCKET_FULL_WRITE_DELAY = 50L; //wait one second to write on full socket - - //Opcode tracking - - private static final int OPCODEHASH = 1016; //Opcodes are unique modulo this number as of 11/21/10 - - public AbstractConnection(AbstractConnectionManager connMan, - SocketChannel sockChan, boolean clientMode) { - this.connMan = connMan; - this.sockChan = sockChan; - this.factory = new NetMsgFactory(this); - - } - - public void disconnect() { - try { - this.sockChan.close(); - } catch (IOException e) { - Logger.error(e.toString()); - } - } - - /** - * Serializes AbstractNetMsg msg into a ByteBuffer, then queues that - * ByteBuffer for sending on this AbstractConnection's SocketChannel. - * - * @param msg - * - AbstractNetMsg to be sent. - * @return boolean status if queue is successful or not. On false return, - * the field lastError will be set. - */ - public final boolean sendMsg(AbstractNetMsg msg) { - // Logger.info("Send: " + msg.getSimpleClassName()); - try { - return this._sendMsg(msg); - - } catch (Exception e) { // Catch-all - Logger.error(e); - return false; - } - } - - /** - * Serializes AbstractNetMsg msg into a ByteBuffer, then queues that - * ByteBuffer for sending on this AbstractConnection's SocketChannel. This - * internal function is required to be overridden by subclasses. - * - * @param msg - * - AbstractNetMsg to be sent. - * @return boolean status if queue is successful or not. On false return, - * the field lastError will be set. - */ - protected abstract boolean _sendMsg(AbstractNetMsg msg); - - /** - * Queues ByteBuffer bb for sending on this AbstractConnection's - * SocketChannel. - * - * @param bb - * - ByteBuffer to be sent. - * @return boolean status if queue is successful or not. On false return, - * the field lastError will be set. - */ - public final boolean sendBB(ByteBuffer bb) { - - if (bb == null) - return false; - try { - return this._sendBB(bb); - } catch (Exception e) { // Catch-all - Logger.error(e); - e.printStackTrace(); - return false; - } - } - - /** - * Queues ByteBuffer bb for sending on this AbstractConnection's - * SocketChannel. This internal function is designed to be overrideable by - * subclasses if needed. - * - * @param bb - * - ByteBuffer to be sent. - * @return boolean status if queue is successful or not. On false return, - * the field lastError will be set. - */ - protected boolean _sendBB(ByteBuffer bb) { - this.outbox.add(bb); - this.connMan.sendStart(this.sockChan); - return true; - } - - /** - * Move data off the socketChannel's buffer and into the Connection's - * internal NetMsgFactory. - */ - // FIXME the int return value on this means nothing! Clean it up! - protected int read() { - - if (readLock.tryLock()) - try { - - if (this.sockChan.isOpen() == false) { - Logger.info("Sock channel closed. Disconnecting " + this.getRemoteAddressAndPortAsString()); - this.disconnect(); - return 0; - } - - // get socket buffer sized buffer from multipool - ByteBuffer bb = Network.byteBufferPool.getBuffer(16); - - int totalBytesRead = 0; - int lastRead; - do { - try { - bb.clear(); - lastRead = this.sockChan.read(bb); - - // On EOF on the SocketChannel, disconnect. - if (lastRead <= -1) { - Logger.info(" EOF on Socket Channel " + this.getRemoteAddressAndPortAsString()); - this.disconnect(); - break; - } - - if (lastRead == 0) - continue; - - synchronized (this.factory) { - this.factory.addData(bb); - } - this.checkInternalFactory(); - - totalBytesRead += lastRead; - - } catch (NotYetConnectedException e) { - Logger.error(e.toString()); - break; - - } catch (ClosedChannelException e) { - Logger.error(e.toString()); - this.disconnect(); - break; - - } catch (IOException e) { - if (!e.getMessage().startsWith( - "An existing connection was forcibly closed")) - Logger.error(e.toString()); - this.disconnect(); - break; - - } catch (Exception e) { - Logger.error(e.toString()); - break; - } - } while (lastRead > 0); - - // put buffer back into multipool - Network.byteBufferPool.putBuffer(bb); - - this.checkInternalFactory(); - return totalBytesRead; - - } finally { - readLock.unlock(); - } - else { - Logger.debug("Another thread already has a read lock! Skipping."); - return 0; - } - } - - /** - * Move data off the Connection's buffer and into the SocketChannel's - * Buffer. - */ - protected boolean writeAll() { - - //intentional delay if socket is full. Give the socket a chance to clear out. - if (System.currentTimeMillis() < this.nextWriteTime) - return false; - - if (writeLock.tryLock()) - try { - String s = ""; - int written = 0; - - boolean allSentOK = true, bufferDoubled = false; - - while (this.outbox.peek() != null) { - ByteBuffer bb = this.outbox.peek(); - - int toSend = bb.position(); - - try { - bb.flip(); - written = this.sockChan.write(bb); - - // Logger.debug("Using a BB with cap of: " + bb.capacity() - // + ". toSend: " + toSend + ", written: " + written); - if (written != toSend) - bb.compact(); // Clean up in case not all gets sent - - if (toSend == written) { - // Actually remove it from the queue - this.outbox.poll(); - - // Pool it - Network.byteBufferPool.putBuffer(bb); - continue; - - } else - if (written == 0) { - //Socket full, let's delay the next write on socket. - this.nextWriteTime = System.currentTimeMillis() + AbstractConnection.SOCKET_FULL_WRITE_DELAY; - - int currentBufferSize = this.sockChan.socket() - .getSendBufferSize(); - - if (!bufferDoubled && currentBufferSize <= Network.INITIAL_SOCKET_BUFFER_SIZE) { - this.doubleSocketSendBufferSize(); - bufferDoubled = true; - } else { - - // s = error02; - // s = s.replaceAll("%1%", this - // .getRemoteAddressAndPortAsString() + ":" + - // this.printLastOpcodes()); - // s = s.replaceAll("%2%", currentBufferSize + ""); - // this.warn(s); - - allSentOK = false; - break; - } - } - - } catch (ClosedChannelException e) { - // Catches AsynchronousCloseException, - // and ClosedByInterruptException - Logger.error(e); - break; - - } catch (Exception e) { - // Catches NotYetConnectedException - // and IOException - Logger.error(e); - this.disconnect(); - break; - } - - } - return allSentOK; - } finally { - writeLock.unlock(); - } - else { - Logger.debug("Another thread already has a write lock! Skipping."); - return false; - } - } - - private boolean doubleSocketSendBufferSize() { - String s; - try { - int currentSize = this.sockChan.socket().getSendBufferSize(); - int newSize = currentSize << 1; - - this.sockChan.socket().setSendBufferSize(newSize); - - // s = "(IP=" + this.getRemoteAddressAndPortAsString() + "): "; - // s += this.printLastOpcodes(); - // s += "Socket has reached the maximum outbound buffer length of "; - // s += currentSize + ". Attempting to double the outbound buffer size."; - // - // this.warn(s); - return true; - } catch (SocketException e) { - Logger.error( e.toString()); - return false; - } - } - - public boolean isConnected() { - return this.sockChan.isConnected(); - } - - public boolean isOpen() { - return this.sockChan.isOpen(); - } - - /* - * Getters n Setters - */ - public SocketChannel getSocketChannel() { - return this.sockChan; - } - - public final void checkInternalFactory() { - CheckNetMsgFactoryJob j = new CheckNetMsgFactoryJob(this); - JobManager.getInstance().submitJob(j); - } - - public NetMsgFactory getFactory() { - return factory; - } - - public String getRemoteAddressAndPortAsString() { - String out = ""; - - if (this.sockChan == null) - out += "NotConnected"; - else if (this.sockChan.socket() == null) - out += "NotConnected"; - else if (this.sockChan.socket().getRemoteSocketAddress() == null) - out += "NotConnected"; - else - out += this.sockChan.socket().getRemoteSocketAddress().toString(); - - return out; - } - - public String getLocalAddressAndPortAsString() { - String out = ""; - - if (this.sockChan == null) - out += "NotConnected"; - else if (this.sockChan.socket() == null) - out += "NotConnected"; - else if (this.sockChan.socket().getRemoteSocketAddress() == null) - out += "NotConnected"; - else { - out += this.sockChan.socket().getLocalSocketAddress().toString(); - out += ":"; - out += this.sockChan.socket().getLocalPort(); - } - - return out; - } - - /** - * Gives the Connection a chance to act on a msg prior to sending it to the - * provided NetMsgHandler - * - */ - @Override - public abstract boolean handleClientMsg(ClientNetMsg msg); - - protected long getLastMsgTime() { - return this.lastMsgTime; - } - - protected void setLastMsgTime() { - // TODO Consider making this a static to latest system time - this.lastMsgTime = System.currentTimeMillis(); - } - - protected long getLastKeepAliveTime() { - return this.lastKeepAliveTime; - } - - protected void setLastKeepAliveTime() { - this.lastKeepAliveTime = System.currentTimeMillis(); - } - - public long getLastOpcode() { - return lastOpcode; - } - - public void setLastOpcode(long lastOpcode) { - this.lastOpcode = lastOpcode; - } + NetMsgHandler { + + protected static final long SOCKET_FULL_WRITE_DELAY = 50L; //wait one second to write on full socket + private static final String error01 = "A byte buffer is being free()ed that is not of the size stored in ByteBufferPool. Size: %1%"; + private static final String error02 = "(IP=%1%): Socket has reached the maximum outbound buffer length of %2%. Moving on while we wait for data to be sent."; + private static final int OPCODEHASH = 1016; //Opcodes are unique modulo this number as of 11/21/10 + protected final SocketChannel sockChan; + protected final AbstractConnectionManager connMan; + protected final NetMsgFactory factory; + protected final AtomicBoolean execTask = new AtomicBoolean(false); + protected final ReentrantLock writeLock = new ReentrantLock(); + protected final ReentrantLock readLock = new ReentrantLock(); + protected long lastMsgTime = System.currentTimeMillis(); + protected long lastKeepAliveTime = System.currentTimeMillis(); + protected long lastOpcode = -1; + protected ConcurrentLinkedQueue outbox = new ConcurrentLinkedQueue<>(); + protected ByteBuffer outBuf = null; + protected ConcurrentHashMap cacheList; + protected long nextWriteTime = 0L; + + //Opcode tracking + protected Protocol lastProtocol = Protocol.NONE; + + public AbstractConnection(AbstractConnectionManager connMan, + SocketChannel sockChan, boolean clientMode) { + this.connMan = connMan; + this.sockChan = sockChan; + this.factory = new NetMsgFactory(this); + + } + + public void disconnect() { + try { + this.sockChan.close(); + } catch (IOException e) { + Logger.error(e.toString()); + } + } + + /** + * Serializes AbstractNetMsg msg into a ByteBuffer, then queues that + * ByteBuffer for sending on this AbstractConnection's SocketChannel. + * + * @param msg - AbstractNetMsg to be sent. + * @return boolean status if queue is successful or not. On false return, + * the field lastError will be set. + */ + public final boolean sendMsg(AbstractNetMsg msg) { + // Logger.info("Send: " + msg.getSimpleClassName()); + try { + return this._sendMsg(msg); + + } catch (Exception e) { // Catch-all + Logger.error(e); + return false; + } + } + + /** + * Serializes AbstractNetMsg msg into a ByteBuffer, then queues that + * ByteBuffer for sending on this AbstractConnection's SocketChannel. This + * internal function is required to be overridden by subclasses. + * + * @param msg - AbstractNetMsg to be sent. + * @return boolean status if queue is successful or not. On false return, + * the field lastError will be set. + */ + protected abstract boolean _sendMsg(AbstractNetMsg msg); + + /** + * Queues ByteBuffer bb for sending on this AbstractConnection's + * SocketChannel. + * + * @param bb - ByteBuffer to be sent. + * @return boolean status if queue is successful or not. On false return, + * the field lastError will be set. + */ + public final boolean sendBB(ByteBuffer bb) { + + if (bb == null) + return false; + try { + return this._sendBB(bb); + } catch (Exception e) { // Catch-all + Logger.error(e); + e.printStackTrace(); + return false; + } + } + + /** + * Queues ByteBuffer bb for sending on this AbstractConnection's + * SocketChannel. This internal function is designed to be overrideable by + * subclasses if needed. + * + * @param bb - ByteBuffer to be sent. + * @return boolean status if queue is successful or not. On false return, + * the field lastError will be set. + */ + protected boolean _sendBB(ByteBuffer bb) { + this.outbox.add(bb); + this.connMan.sendStart(this.sockChan); + return true; + } + + /** + * Move data off the socketChannel's buffer and into the Connection's + * internal NetMsgFactory. + */ + // FIXME the int return value on this means nothing! Clean it up! + protected int read() { + + if (readLock.tryLock()) + try { + + if (this.sockChan.isOpen() == false) { + Logger.info("Sock channel closed. Disconnecting " + this.getRemoteAddressAndPortAsString()); + this.disconnect(); + return 0; + } + + // get socket buffer sized buffer from multipool + ByteBuffer bb = Network.byteBufferPool.getBuffer(16); + + int totalBytesRead = 0; + int lastRead; + do { + try { + bb.clear(); + lastRead = this.sockChan.read(bb); + + // On EOF on the SocketChannel, disconnect. + if (lastRead <= -1) { + Logger.info(" EOF on Socket Channel " + this.getRemoteAddressAndPortAsString()); + this.disconnect(); + break; + } + + if (lastRead == 0) + continue; + + synchronized (this.factory) { + this.factory.addData(bb); + } + this.checkInternalFactory(); + + totalBytesRead += lastRead; + + } catch (NotYetConnectedException e) { + Logger.error(e.toString()); + break; + + } catch (ClosedChannelException e) { + Logger.error(e.toString()); + this.disconnect(); + break; + + } catch (IOException e) { + if (!e.getMessage().startsWith( + "An existing connection was forcibly closed")) + Logger.error(e.toString()); + this.disconnect(); + break; + + } catch (Exception e) { + Logger.error(e.toString()); + break; + } + } while (lastRead > 0); + + // put buffer back into multipool + Network.byteBufferPool.putBuffer(bb); + + this.checkInternalFactory(); + return totalBytesRead; + + } finally { + readLock.unlock(); + } + else { + Logger.debug("Another thread already has a read lock! Skipping."); + return 0; + } + } + + /** + * Move data off the Connection's buffer and into the SocketChannel's + * Buffer. + */ + protected boolean writeAll() { + + //intentional delay if socket is full. Give the socket a chance to clear out. + if (System.currentTimeMillis() < this.nextWriteTime) + return false; + + if (writeLock.tryLock()) + try { + String s = ""; + int written = 0; + + boolean allSentOK = true, bufferDoubled = false; + + while (this.outbox.peek() != null) { + ByteBuffer bb = this.outbox.peek(); + + int toSend = bb.position(); + + try { + bb.flip(); + written = this.sockChan.write(bb); + + // Logger.debug("Using a BB with cap of: " + bb.capacity() + // + ". toSend: " + toSend + ", written: " + written); + if (written != toSend) + bb.compact(); // Clean up in case not all gets sent + + if (toSend == written) { + // Actually remove it from the queue + this.outbox.poll(); + + // Pool it + Network.byteBufferPool.putBuffer(bb); + continue; + + } else if (written == 0) { + //Socket full, let's delay the next write on socket. + this.nextWriteTime = System.currentTimeMillis() + AbstractConnection.SOCKET_FULL_WRITE_DELAY; + + int currentBufferSize = this.sockChan.socket() + .getSendBufferSize(); + + if (!bufferDoubled && currentBufferSize <= Network.INITIAL_SOCKET_BUFFER_SIZE) { + this.doubleSocketSendBufferSize(); + bufferDoubled = true; + } else { + + // s = error02; + // s = s.replaceAll("%1%", this + // .getRemoteAddressAndPortAsString() + ":" + + // this.printLastOpcodes()); + // s = s.replaceAll("%2%", currentBufferSize + ""); + // this.warn(s); + + allSentOK = false; + break; + } + } + + } catch (ClosedChannelException e) { + // Catches AsynchronousCloseException, + // and ClosedByInterruptException + Logger.error(e); + break; + + } catch (Exception e) { + // Catches NotYetConnectedException + // and IOException + Logger.error(e); + this.disconnect(); + break; + } + + } + return allSentOK; + } finally { + writeLock.unlock(); + } + else { + Logger.debug("Another thread already has a write lock! Skipping."); + return false; + } + } + + private boolean doubleSocketSendBufferSize() { + String s; + try { + int currentSize = this.sockChan.socket().getSendBufferSize(); + int newSize = currentSize << 1; + + this.sockChan.socket().setSendBufferSize(newSize); + + // s = "(IP=" + this.getRemoteAddressAndPortAsString() + "): "; + // s += this.printLastOpcodes(); + // s += "Socket has reached the maximum outbound buffer length of "; + // s += currentSize + ". Attempting to double the outbound buffer size."; + // + // this.warn(s); + return true; + } catch (SocketException e) { + Logger.error(e.toString()); + return false; + } + } + + public boolean isConnected() { + return this.sockChan.isConnected(); + } + + public boolean isOpen() { + return this.sockChan.isOpen(); + } + + /* + * Getters n Setters + */ + public SocketChannel getSocketChannel() { + return this.sockChan; + } + + public final void checkInternalFactory() { + CheckNetMsgFactoryJob j = new CheckNetMsgFactoryJob(this); + JobManager.getInstance().submitJob(j); + } + + public NetMsgFactory getFactory() { + return factory; + } + + public String getRemoteAddressAndPortAsString() { + String out = ""; + + if (this.sockChan == null) + out += "NotConnected"; + else if (this.sockChan.socket() == null) + out += "NotConnected"; + else if (this.sockChan.socket().getRemoteSocketAddress() == null) + out += "NotConnected"; + else + out += this.sockChan.socket().getRemoteSocketAddress().toString(); + + return out; + } + + public String getLocalAddressAndPortAsString() { + String out = ""; + + if (this.sockChan == null) + out += "NotConnected"; + else if (this.sockChan.socket() == null) + out += "NotConnected"; + else if (this.sockChan.socket().getRemoteSocketAddress() == null) + out += "NotConnected"; + else { + out += this.sockChan.socket().getLocalSocketAddress().toString(); + out += ":"; + out += this.sockChan.socket().getLocalPort(); + } + + return out; + } + + /** + * Gives the Connection a chance to act on a msg prior to sending it to the + * provided NetMsgHandler + */ + @Override + public abstract boolean handleClientMsg(ClientNetMsg msg); + + protected long getLastMsgTime() { + return this.lastMsgTime; + } + + protected void setLastMsgTime() { + // TODO Consider making this a static to latest system time + this.lastMsgTime = System.currentTimeMillis(); + } + + protected long getLastKeepAliveTime() { + return this.lastKeepAliveTime; + } + + protected void setLastKeepAliveTime() { + this.lastKeepAliveTime = System.currentTimeMillis(); + } + + public long getLastOpcode() { + return lastOpcode; + } + + public void setLastOpcode(long lastOpcode) { + this.lastOpcode = lastOpcode; + } } diff --git a/src/engine/net/AbstractConnectionManager.java b/src/engine/net/AbstractConnectionManager.java index 22f6bd5e..0810fbb7 100644 --- a/src/engine/net/AbstractConnectionManager.java +++ b/src/engine/net/AbstractConnectionManager.java @@ -24,526 +24,523 @@ import java.util.concurrent.ConcurrentLinkedQueue; public abstract class AbstractConnectionManager extends ControlledRunnable { - private final Selector selector; - private final ServerSocketChannel listenChannel; - private final ConcurrentLinkedQueue chngReqs = new ConcurrentLinkedQueue<>(); - - /* - * - */ - public AbstractConnectionManager(String nodeName, InetAddress hostAddress, - int port) throws IOException { - super(nodeName); - - this.selector = SelectorProvider.provider().openSelector(); - - // Create a new non-blocking Server channel - this.listenChannel = ServerSocketChannel.open(); - this.listenChannel.configureBlocking(false); - - // Bind - InetSocketAddress isa = new InetSocketAddress(hostAddress, port); - this.listenChannel.socket().bind(isa); - - Logger.info(this.getLocalNodeName() + " Configured to listen: " - + isa.getAddress().toString() + ':' + port); - - // register an interest in Accepting new connections. - SelectionKey sk = this.listenChannel.register(this.selector, SelectionKey.OP_ACCEPT); - sk.attach(this); - } - - /* - * ControlledRunnable implementations - */ - @Override - protected void _startup() { - } - - @Override - protected void _shutdown() { - this.selector.wakeup(); - this.disconnectAll(); - this.selector.wakeup(); - } - - @Override - protected boolean _preRun() { - this.runStatus = true; - return true; - } - - @Override - protected boolean _Run() { - while (this.runCmd) { - try { - this.runLoopHook(); - - this.processChangeRequests(); - this.auditSocketChannelToConnectionMap(); - this.selector.select(250L); - this.processNewEvents(); - - } catch (Exception e) { - Logger.error(e.toString()); - } - } - return true; - } - - @Override - protected boolean _postRun() { - - this.runStatus = false; - - this.disconnectAll(); - - try { - this.selector.close(); - } catch (IOException e) { - Logger.error( e.toString()); - } - - return true; - } - - /** - * Hook for subclasses to use. - * - */ - protected void runLoopHook() { - } - - /* - * Accept / New Connection FNs - */ - private AbstractConnection acceptNewConnection(final SelectionKey key) - throws IOException { - - this.preAcceptNewConnectionHook(key); - - // Cancel incoming connections if server isn't set to listen - if (this.listenChannel == null || this.listenChannel.isOpen() == false) { - key.cancel(); - return null; - } - - // For an accept to be pending, the key contains a reference to the - // ServerSocketChannel - ServerSocketChannel ssc = (ServerSocketChannel) key.channel(); - - // Get SocketChannel - SocketChannel sockChan = ssc.accept(); - sockChan.configureBlocking(false); - - //Configure the Socket - Socket socket = sockChan.socket(); - socket.setSendBufferSize(Network.INITIAL_SOCKET_BUFFER_SIZE); - socket.setReceiveBufferSize(Network.INITIAL_SOCKET_BUFFER_SIZE); - socket.setTcpNoDelay(MBServerStatics.TCP_NO_DELAY_DEFAULT); - - //Register with the selector - SelectionKey sk = sockChan.register(this.selector, SelectionKey.OP_READ); - if (sk == null) { - Logger.error("FIX ME! NULL SELECTION KEY!"); - return null; - } - - //Initialize Connection - AbstractConnection ac = this.getNewIncomingConnection(sockChan); - sk.attach(ac); - - this.postAcceptNewConnectionHook(ac); - return ac; - } - - /** - * Hook for subclasses to use. - * - * @param key - */ - protected void preAcceptNewConnectionHook(SelectionKey key) { - } - - /** - * Hook for subclasses to use. - * - * @param ac - */ - protected void postAcceptNewConnectionHook(AbstractConnection ac) { - } - - protected abstract AbstractConnection getNewIncomingConnection(SocketChannel sockChan); - - protected abstract AbstractConnection getNewOutgoingConnection(SocketChannel sockChan); - - /* - * Disconnect / Destroy Connection FNs - */ - protected boolean disconnect(final SelectionKey key) { - - this.disconnect((AbstractConnection) key.attachment()); - - key.attach(null); - key.cancel(); - return key.isValid(); - } - - protected boolean disconnect(final AbstractConnection c) { - if (c == null) - return false; - - c.disconnect(); - - return c.getSocketChannel().isConnected(); - } - - protected void disconnectAll() { - synchronized (this.selector.keys()) { - for (SelectionKey sk : this.selector.keys()) { - if (sk.channel() instanceof SocketChannel) - disconnect(sk); - } - } - } - - /* - * Data IO - */ - - /* - * WRITE SEQUENCE - */ - /** - * Submits a request to set this Connection to WRITE mode. - * - */ - protected void sendStart(final SocketChannel sockChan) { - synchronized (this.chngReqs) { - // Indicate we want the interest ops set changed - this.chngReqs.add(new ChangeRequest(sockChan, ChangeType.CHANGEOPS, SelectionKey.OP_WRITE)); - } - - this.selector.wakeup(); - } - - /** - * - * @param key - * @return Boolean indication emit success. - */ - protected boolean sendFinish(final SelectionKey key) { - SocketChannel sockChan = (SocketChannel) key.channel(); - - // Check to see if the SocketChannel the selector offered up - // is null. - if (sockChan == null) { - Logger.error(": null sockChannel."); - this.disconnect(key); - return false; - } - - AbstractConnection c = (AbstractConnection) key.attachment(); - - if (c == null) { - Logger.error(": null Connection."); - this.disconnect(key); - return false; - } - - // long startTime = System.currentTimeMillis(); - boolean allSent = c.writeAll(); - - // if ((System.currentTimeMillis() - startTime) > 20) - // this.logDirectWARNING(c.getRemoteAddressAndPortAsString() + " took " + (System.currentTimeMillis() - startTime) + "ms to handle!"); - - // If all was written, switch back to Read Mode. - if (allSent || !c.isConnected()) { - - // Indicate we want the interest ops set changed - ChangeRequest chReq = new ChangeRequest(c.getSocketChannel(), ChangeType.CHANGEOPS, SelectionKey.OP_READ); - synchronized (this.chngReqs) { - this.chngReqs.add(chReq); - } - - this.selector.wakeup(); - } - return true; - } - - /* - * READ SEQUENCE - */ - /** - * - * @param key - * @return Boolean indication of success. - */ - private boolean receive(final SelectionKey key) { - SocketChannel sockChan = (SocketChannel) key.channel(); - - // Check to see if the SocketChannel the selector offered up - // is null. - if (sockChan == null) { - Logger.error("null sockChannel."); - this.disconnect(key); - return false; - } - - AbstractConnection c = (AbstractConnection) key.attachment(); - - if (c == null) { - Logger.error("null Connection."); - this.disconnect(key); - return false; - } - - c.read(); - - return true; - } - - /* - * Main Loop And Loop Controls - */ - private void processChangeRequests() { - SelectionKey selKey = null; - ChangeRequest sccr = null; - ChangeType change = null; - SocketChannel sockChan = null; - - synchronized (this.chngReqs) { - Iterator it = this.chngReqs.iterator(); - while (it.hasNext()) { - sccr = it.next(); - - if (sccr == null) { - it.remove(); - continue; - } - - change = sccr.getChangeType(); - sockChan = sccr.getSocketChannel(); - - switch (change) { - case CHANGEOPS: - selKey = sockChan.keyFor(this.selector); - - if (selKey == null || selKey.isValid() == false) - continue; - - selKey.interestOps(sccr.getOps()); - break; - - case REGISTER: - try { - sockChan.register(this.selector, sccr.getOps()); - - } catch (ClosedChannelException e) { - // TODO Should a closed channel be logged or just - // cleaned up? - // Logger.error(this.getLocalNodeName(), e); - } - break; - } - } - this.chngReqs.clear(); - } - } - - private void processNewEvents() { - SelectionKey thisKey = null; - Iterator selectedKeys = null; - JobManager jm = JobManager.getInstance(); - - selectedKeys = this.selector.selectedKeys().iterator(); - - if (selectedKeys.hasNext() == false) - return; - - while (selectedKeys.hasNext()) { - thisKey = selectedKeys.next(); - - //To shake out any issues - if (thisKey.attachment() == null) - Logger.error("Found null attachment! PANIC!"); - - if (thisKey.attachment() instanceof AbstractConnection) - if (((AbstractConnection) thisKey.attachment()).execTask.get() == true) - continue; - - selectedKeys.remove(); - - try { - if (thisKey.isValid() == false) - break; // Changed from continue - else if (thisKey.isAcceptable()) - this.acceptNewConnection(thisKey); - else if (thisKey.isReadable()) - jm.submitJob(new ReadOperationHander(thisKey)); - else if (thisKey.isWritable()) - jm.submitJob(new WriteOperationHander(thisKey)); - else if (thisKey.isConnectable()) - this.finishConnectingTo(thisKey); - else - Logger.error("Unhandled keystate: " + thisKey.toString()); - } catch (CancelledKeyException cke) { - Logger.error(this.getLocalNodeName(), cke); - this.disconnect(thisKey); - - } catch (IOException e) { - Logger.error(this.getLocalNodeName(), e); - } - } - } - - protected void connectTo(String host, int port) { - try { - this.connectTo(InetAddress.getByName(host), port); - } catch (UnknownHostException e) { - Logger.error(this.getLocalNodeName(), e); - } - } - - protected void connectTo(InetAddress host, int port) { - try { - this.startConnectingTo(host, port); - this.selector.wakeup(); - } catch (IOException e) { - Logger.error(this.getLocalNodeName(), e); - } - } - - protected final void startConnectingTo(InetAddress host, int port) - throws IOException { - // Create a non-blocking socket channel - SocketChannel sockChan = SocketChannel.open(); - sockChan.configureBlocking(false); - sockChan.socket().setSendBufferSize(Network.INITIAL_SOCKET_BUFFER_SIZE); - sockChan.socket().setReceiveBufferSize(Network.INITIAL_SOCKET_BUFFER_SIZE); - - // Make a new Connection object - this.getNewOutgoingConnection(sockChan); - - // Kick off connection establishment - sockChan.connect(new InetSocketAddress(host, port)); - - synchronized (this.chngReqs) { - this.chngReqs.add(new ChangeRequest(sockChan, ChangeType.REGISTER, SelectionKey.OP_CONNECT)); - } - - this.selector.wakeup(); - } - - private void finishConnectingTo(SelectionKey key) throws IOException { - this.preFinishConnectingToHook(key); - - // Get sockChan - SocketChannel sockChan = (SocketChannel) key.channel(); - - // Get AbstractConnection - AbstractConnection ac = (AbstractConnection) key.attachment(); - - if (sockChan == null) { - Logger.error(this.getLocalNodeName(), "null socketChannel"); - this.disconnect(key); - return; - } - - if (ac == null) { - Logger.error(this.getLocalNodeName(), "null AbstractConnection"); - this.disconnect(key); - return; - } - - // Finish the connection. If the connection operation failed - // this will raise an IOException. - try { - sockChan.finishConnect(); - } catch (IOException e) { - if (e.getMessage().startsWith("Connection refused:") - || e.getMessage().startsWith( - "An existing connection was forcibly closed")) { - // eat this type of IOException - } else - Logger.error(this.getLocalNodeName(), e); - - // Cancel the channel's registration with our selector - key.cancel(); - return; - } - - Socket socket = sockChan.socket(); - Logger.debug("Connected to: " - + socket.getInetAddress() + ':' - + socket.getPort()); - - sockChan.configureBlocking(false); - sockChan.register(this.selector, SelectionKey.OP_READ); - - this.postFinishConnectingToHook(ac); - } - - /** - * Hook for subclasses to use. - * - * @param key - */ - protected void preFinishConnectingToHook(SelectionKey key) { - } - - /** - * Hook for subclasses to use. - * - * @param ac - */ - protected void postFinishConnectingToHook(AbstractConnection ac) { - } - - public final String getLocalNodeName() { - return this.getThreadName(); - } - - /** - * Removes the mapping that contains the key 'sockChan' - * - * @param sockChan - */ - private long lastAuditTime = 0; - - protected int auditSocketChannelToConnectionMap() { - long startTime = System.currentTimeMillis(); - int numberOfItemsToProcess = 0; - - if (lastAuditTime + MBServerStatics.TIMEOUT_CHECKS_TIMER_MS > startTime) - return -1; - - synchronized (this.selector.keys()) { - for (SelectionKey sk : this.selector.keys()) { - if (!(sk.channel() instanceof SocketChannel)) - continue; - - SocketChannel sockChan = (SocketChannel) sk.channel(); - AbstractConnection conn = (AbstractConnection) sk.attachment(); - - if (sockChan == null) - continue; - - if (!sockChan.isOpen()) { - numberOfItemsToProcess++; - Logger.info("sockChan closed. Disconnecting.."); - disconnect(sk); - continue; - } - - if (conn == null) { - numberOfItemsToProcess++; - Logger.info("Connection is null, Disconnecting."); - disconnect(sk); - continue; - } - - //removed keep alive timeout. Believe failmu used this for disconnecting players on force quit, but a closed socket will already disconnect. + private final Selector selector; + private final ServerSocketChannel listenChannel; + private final ConcurrentLinkedQueue chngReqs = new ConcurrentLinkedQueue<>(); + /** + * Removes the mapping that contains the key 'sockChan' + * + * @param sockChan + */ + private long lastAuditTime = 0; + + /* + * + */ + public AbstractConnectionManager(String nodeName, InetAddress hostAddress, + int port) throws IOException { + super(nodeName); + + this.selector = SelectorProvider.provider().openSelector(); + + // Create a new non-blocking Server channel + this.listenChannel = ServerSocketChannel.open(); + this.listenChannel.configureBlocking(false); + + // Bind + InetSocketAddress isa = new InetSocketAddress(hostAddress, port); + this.listenChannel.socket().bind(isa); + + Logger.info(this.getLocalNodeName() + " Configured to listen: " + + isa.getAddress().toString() + ':' + port); + + // register an interest in Accepting new connections. + SelectionKey sk = this.listenChannel.register(this.selector, SelectionKey.OP_ACCEPT); + sk.attach(this); + } + + /* + * ControlledRunnable implementations + */ + @Override + protected void _startup() { + } + + @Override + protected void _shutdown() { + this.selector.wakeup(); + this.disconnectAll(); + this.selector.wakeup(); + } + + @Override + protected boolean _preRun() { + this.runStatus = true; + return true; + } + + @Override + protected boolean _Run() { + while (this.runCmd) { + try { + this.runLoopHook(); + + this.processChangeRequests(); + this.auditSocketChannelToConnectionMap(); + this.selector.select(250L); + this.processNewEvents(); + + } catch (Exception e) { + Logger.error(e.toString()); + } + } + return true; + } + + @Override + protected boolean _postRun() { + + this.runStatus = false; + + this.disconnectAll(); + + try { + this.selector.close(); + } catch (IOException e) { + Logger.error(e.toString()); + } + + return true; + } + + /** + * Hook for subclasses to use. + */ + protected void runLoopHook() { + } + + /* + * Accept / New Connection FNs + */ + private AbstractConnection acceptNewConnection(final SelectionKey key) + throws IOException { + + this.preAcceptNewConnectionHook(key); + + // Cancel incoming connections if server isn't set to listen + if (this.listenChannel == null || this.listenChannel.isOpen() == false) { + key.cancel(); + return null; + } + + // For an accept to be pending, the key contains a reference to the + // ServerSocketChannel + ServerSocketChannel ssc = (ServerSocketChannel) key.channel(); + + // Get SocketChannel + SocketChannel sockChan = ssc.accept(); + sockChan.configureBlocking(false); + + //Configure the Socket + Socket socket = sockChan.socket(); + socket.setSendBufferSize(Network.INITIAL_SOCKET_BUFFER_SIZE); + socket.setReceiveBufferSize(Network.INITIAL_SOCKET_BUFFER_SIZE); + socket.setTcpNoDelay(MBServerStatics.TCP_NO_DELAY_DEFAULT); + + //Register with the selector + SelectionKey sk = sockChan.register(this.selector, SelectionKey.OP_READ); + if (sk == null) { + Logger.error("FIX ME! NULL SELECTION KEY!"); + return null; + } + + //Initialize Connection + AbstractConnection ac = this.getNewIncomingConnection(sockChan); + sk.attach(ac); + + this.postAcceptNewConnectionHook(ac); + return ac; + } + + /** + * Hook for subclasses to use. + * + * @param key + */ + protected void preAcceptNewConnectionHook(SelectionKey key) { + } + + /** + * Hook for subclasses to use. + * + * @param ac + */ + protected void postAcceptNewConnectionHook(AbstractConnection ac) { + } + + protected abstract AbstractConnection getNewIncomingConnection(SocketChannel sockChan); + + protected abstract AbstractConnection getNewOutgoingConnection(SocketChannel sockChan); + + /* + * Disconnect / Destroy Connection FNs + */ + protected boolean disconnect(final SelectionKey key) { + + this.disconnect((AbstractConnection) key.attachment()); + + key.attach(null); + key.cancel(); + return key.isValid(); + } + + protected boolean disconnect(final AbstractConnection c) { + if (c == null) + return false; + + c.disconnect(); + + return c.getSocketChannel().isConnected(); + } + + /* + * Data IO + */ + + /* + * WRITE SEQUENCE + */ + + protected void disconnectAll() { + synchronized (this.selector.keys()) { + for (SelectionKey sk : this.selector.keys()) { + if (sk.channel() instanceof SocketChannel) + disconnect(sk); + } + } + } + + /** + * Submits a request to set this Connection to WRITE mode. + */ + protected void sendStart(final SocketChannel sockChan) { + synchronized (this.chngReqs) { + // Indicate we want the interest ops set changed + this.chngReqs.add(new ChangeRequest(sockChan, ChangeType.CHANGEOPS, SelectionKey.OP_WRITE)); + } + + this.selector.wakeup(); + } + + /* + * READ SEQUENCE + */ + + /** + * @param key + * @return Boolean indication emit success. + */ + protected boolean sendFinish(final SelectionKey key) { + SocketChannel sockChan = (SocketChannel) key.channel(); + + // Check to see if the SocketChannel the selector offered up + // is null. + if (sockChan == null) { + Logger.error(": null sockChannel."); + this.disconnect(key); + return false; + } + + AbstractConnection c = (AbstractConnection) key.attachment(); + + if (c == null) { + Logger.error(": null Connection."); + this.disconnect(key); + return false; + } + + // long startTime = System.currentTimeMillis(); + boolean allSent = c.writeAll(); + + // if ((System.currentTimeMillis() - startTime) > 20) + // this.logDirectWARNING(c.getRemoteAddressAndPortAsString() + " took " + (System.currentTimeMillis() - startTime) + "ms to handle!"); + + // If all was written, switch back to Read Mode. + if (allSent || !c.isConnected()) { + + // Indicate we want the interest ops set changed + ChangeRequest chReq = new ChangeRequest(c.getSocketChannel(), ChangeType.CHANGEOPS, SelectionKey.OP_READ); + synchronized (this.chngReqs) { + this.chngReqs.add(chReq); + } + + this.selector.wakeup(); + } + return true; + } + + /** + * @param key + * @return Boolean indication of success. + */ + private boolean receive(final SelectionKey key) { + SocketChannel sockChan = (SocketChannel) key.channel(); + + // Check to see if the SocketChannel the selector offered up + // is null. + if (sockChan == null) { + Logger.error("null sockChannel."); + this.disconnect(key); + return false; + } + + AbstractConnection c = (AbstractConnection) key.attachment(); + + if (c == null) { + Logger.error("null Connection."); + this.disconnect(key); + return false; + } + + c.read(); + + return true; + } + + /* + * Main Loop And Loop Controls + */ + private void processChangeRequests() { + SelectionKey selKey = null; + ChangeRequest sccr = null; + ChangeType change = null; + SocketChannel sockChan = null; + + synchronized (this.chngReqs) { + Iterator it = this.chngReqs.iterator(); + while (it.hasNext()) { + sccr = it.next(); + + if (sccr == null) { + it.remove(); + continue; + } + + change = sccr.getChangeType(); + sockChan = sccr.getSocketChannel(); + + switch (change) { + case CHANGEOPS: + selKey = sockChan.keyFor(this.selector); + + if (selKey == null || selKey.isValid() == false) + continue; + + selKey.interestOps(sccr.getOps()); + break; + + case REGISTER: + try { + sockChan.register(this.selector, sccr.getOps()); + + } catch (ClosedChannelException e) { + // TODO Should a closed channel be logged or just + // cleaned up? + // Logger.error(this.getLocalNodeName(), e); + } + break; + } + } + this.chngReqs.clear(); + } + } + + private void processNewEvents() { + SelectionKey thisKey = null; + Iterator selectedKeys = null; + JobManager jm = JobManager.getInstance(); + + selectedKeys = this.selector.selectedKeys().iterator(); + + if (selectedKeys.hasNext() == false) + return; + + while (selectedKeys.hasNext()) { + thisKey = selectedKeys.next(); + + //To shake out any issues + if (thisKey.attachment() == null) + Logger.error("Found null attachment! PANIC!"); + + if (thisKey.attachment() instanceof AbstractConnection) + if (((AbstractConnection) thisKey.attachment()).execTask.get() == true) + continue; + + selectedKeys.remove(); + + try { + if (thisKey.isValid() == false) + break; // Changed from continue + else if (thisKey.isAcceptable()) + this.acceptNewConnection(thisKey); + else if (thisKey.isReadable()) + jm.submitJob(new ReadOperationHander(thisKey)); + else if (thisKey.isWritable()) + jm.submitJob(new WriteOperationHander(thisKey)); + else if (thisKey.isConnectable()) + this.finishConnectingTo(thisKey); + else + Logger.error("Unhandled keystate: " + thisKey.toString()); + } catch (CancelledKeyException cke) { + Logger.error(this.getLocalNodeName(), cke); + this.disconnect(thisKey); + + } catch (IOException e) { + Logger.error(this.getLocalNodeName(), e); + } + } + } + + protected void connectTo(String host, int port) { + try { + this.connectTo(InetAddress.getByName(host), port); + } catch (UnknownHostException e) { + Logger.error(this.getLocalNodeName(), e); + } + } + + protected void connectTo(InetAddress host, int port) { + try { + this.startConnectingTo(host, port); + this.selector.wakeup(); + } catch (IOException e) { + Logger.error(this.getLocalNodeName(), e); + } + } + + protected final void startConnectingTo(InetAddress host, int port) + throws IOException { + // Create a non-blocking socket channel + SocketChannel sockChan = SocketChannel.open(); + sockChan.configureBlocking(false); + sockChan.socket().setSendBufferSize(Network.INITIAL_SOCKET_BUFFER_SIZE); + sockChan.socket().setReceiveBufferSize(Network.INITIAL_SOCKET_BUFFER_SIZE); + + // Make a new Connection object + this.getNewOutgoingConnection(sockChan); + + // Kick off connection establishment + sockChan.connect(new InetSocketAddress(host, port)); + + synchronized (this.chngReqs) { + this.chngReqs.add(new ChangeRequest(sockChan, ChangeType.REGISTER, SelectionKey.OP_CONNECT)); + } + + this.selector.wakeup(); + } + + private void finishConnectingTo(SelectionKey key) throws IOException { + this.preFinishConnectingToHook(key); + + // Get sockChan + SocketChannel sockChan = (SocketChannel) key.channel(); + + // Get AbstractConnection + AbstractConnection ac = (AbstractConnection) key.attachment(); + + if (sockChan == null) { + Logger.error(this.getLocalNodeName(), "null socketChannel"); + this.disconnect(key); + return; + } + + if (ac == null) { + Logger.error(this.getLocalNodeName(), "null AbstractConnection"); + this.disconnect(key); + return; + } + + // Finish the connection. If the connection operation failed + // this will raise an IOException. + try { + sockChan.finishConnect(); + } catch (IOException e) { + if (e.getMessage().startsWith("Connection refused:") + || e.getMessage().startsWith( + "An existing connection was forcibly closed")) { + // eat this type of IOException + } else + Logger.error(this.getLocalNodeName(), e); + + // Cancel the channel's registration with our selector + key.cancel(); + return; + } + + Socket socket = sockChan.socket(); + Logger.debug("Connected to: " + + socket.getInetAddress() + ':' + + socket.getPort()); + + sockChan.configureBlocking(false); + sockChan.register(this.selector, SelectionKey.OP_READ); + + this.postFinishConnectingToHook(ac); + } + + /** + * Hook for subclasses to use. + * + * @param key + */ + protected void preFinishConnectingToHook(SelectionKey key) { + } + + /** + * Hook for subclasses to use. + * + * @param ac + */ + protected void postFinishConnectingToHook(AbstractConnection ac) { + } + + public final String getLocalNodeName() { + return this.getThreadName(); + } + + protected int auditSocketChannelToConnectionMap() { + long startTime = System.currentTimeMillis(); + int numberOfItemsToProcess = 0; + + if (lastAuditTime + MBServerStatics.TIMEOUT_CHECKS_TIMER_MS > startTime) + return -1; + + synchronized (this.selector.keys()) { + for (SelectionKey sk : this.selector.keys()) { + if (!(sk.channel() instanceof SocketChannel)) + continue; + + SocketChannel sockChan = (SocketChannel) sk.channel(); + AbstractConnection conn = (AbstractConnection) sk.attachment(); + + if (sockChan == null) + continue; + + if (!sockChan.isOpen()) { + numberOfItemsToProcess++; + Logger.info("sockChan closed. Disconnecting.."); + disconnect(sk); + continue; + } + + if (conn == null) { + numberOfItemsToProcess++; + Logger.info("Connection is null, Disconnecting."); + disconnect(sk); + continue; + } + + //removed keep alive timeout. Believe failmu used this for disconnecting players on force quit, but a closed socket will already disconnect. // if (conn.getLastKeepAliveTime() + MBServerStatics.KEEPALIVE_TIMEOUT_MS < startTime) { // numberOfItemsToProcess++; // Logger.info("Keep alive Disconnecting " + conn.getRemoteAddressAndPortAsString()); @@ -551,158 +548,157 @@ public abstract class AbstractConnectionManager extends ControlledRunnable { // continue; // } - if (conn.getLastMsgTime() + MBServerStatics.AFK_TIMEOUT_MS < startTime) { - numberOfItemsToProcess++; - Logger.info("AFK TIMEOUT Disconnecting " + conn.getRemoteAddressAndPortAsString()); - conn.disconnect(); - } - } - } - - if (numberOfItemsToProcess != 0) - Logger.info( "Cleaned " - + numberOfItemsToProcess - + " dead connections in " - + (System.currentTimeMillis() - startTime) - + " millis."); - - lastAuditTime = System.currentTimeMillis(); - return numberOfItemsToProcess; - } - - /* - * - */ - protected static enum ChangeType { - - REGISTER, CHANGEOPS - } - - private class ChangeRequest { - - private final SocketChannel sockChan; - private final ChangeType changeType; - private final Integer ops; - - public ChangeRequest(SocketChannel sockChan, ChangeType changeType, - int ops) { - this.sockChan = sockChan; - this.changeType = changeType; - this.ops = ops; - } - - public SocketChannel getSocketChannel() { - synchronized (this.sockChan) { - return this.sockChan; - } - } - - public ChangeType getChangeType() { - synchronized (this.changeType) { - return this.changeType; - } - } - - public int getOps() { - synchronized (this.ops) { - return this.ops; - } - } - } - - public int getConnectionSize() { - if (this.selector == null) - return -1; - if (this.selector.keys() == null) - return -1; - return this.selector.keys().size(); - } - - /** - * Returns the port on which this socket is listening. - * - * @return the port number to which this socket is listening or -1 if the - * socket is not bound yet. - * - */ - public int getListeningPort() { - if (this.listenChannel == null) - return -1; - if (this.listenChannel.socket() == null) - return -1; - return this.listenChannel.socket().getLocalPort(); - } - - /** - * Returns the address of the endpoint this socket is bound to, or null if - * it is not bound yet. - * - * @return a SocketAddress representing the local endpoint of this socket, - * or null if it is not bound yet. - */ - public SocketAddress getListeningAddress() { - if (this.listenChannel == null) - return null; - if (this.listenChannel.socket() == null) - return null; - return this.listenChannel.socket().getLocalSocketAddress(); - } - - private class ReadOperationHander extends AbstractJob { - - private final SelectionKey sk; - private final AbstractConnection ac; - private final boolean runStatus; - - public ReadOperationHander(final SelectionKey sk) { - this.sk = sk; - - if (sk.attachment() instanceof AbstractConnection) { - this.ac = (AbstractConnection) sk.attachment(); - this.runStatus = this.ac.execTask.compareAndSet(false, true); - } else { - this.ac = null; - this.runStatus = false; - Logger.error("Passed selection key did not have a corresponding Connection!(Read)"); - } - } - - @Override - protected void doJob() { - if (runStatus) { - this.ac.connMan.receive(sk); - this.ac.execTask.compareAndSet(true, false); - } - } - } - - private class WriteOperationHander extends AbstractJob { - - private final SelectionKey sk; - private final AbstractConnection ac; - private final boolean runStatus; - - public WriteOperationHander(final SelectionKey sk) { - this.sk = sk; - - if (sk.attachment() instanceof AbstractConnection) { - this.ac = (AbstractConnection) sk.attachment(); - this.runStatus = this.ac.execTask.compareAndSet(false, true); - } else { - this.runStatus = false; - this.ac = null; - Logger.error("Passed selection key did not have a corresponding Connection!(Write)"); - } - - } - - @Override - protected void doJob() { - if (runStatus) { - this.ac.connMan.sendFinish(sk); - this.ac.execTask.compareAndSet(true, false); - } - } - } + if (conn.getLastMsgTime() + MBServerStatics.AFK_TIMEOUT_MS < startTime) { + numberOfItemsToProcess++; + Logger.info("AFK TIMEOUT Disconnecting " + conn.getRemoteAddressAndPortAsString()); + conn.disconnect(); + } + } + } + + if (numberOfItemsToProcess != 0) + Logger.info("Cleaned " + + numberOfItemsToProcess + + " dead connections in " + + (System.currentTimeMillis() - startTime) + + " millis."); + + lastAuditTime = System.currentTimeMillis(); + return numberOfItemsToProcess; + } + + public int getConnectionSize() { + if (this.selector == null) + return -1; + if (this.selector.keys() == null) + return -1; + return this.selector.keys().size(); + } + + /** + * Returns the port on which this socket is listening. + * + * @return the port number to which this socket is listening or -1 if the + * socket is not bound yet. + */ + public int getListeningPort() { + if (this.listenChannel == null) + return -1; + if (this.listenChannel.socket() == null) + return -1; + return this.listenChannel.socket().getLocalPort(); + } + + /** + * Returns the address of the endpoint this socket is bound to, or null if + * it is not bound yet. + * + * @return a SocketAddress representing the local endpoint of this socket, + * or null if it is not bound yet. + */ + public SocketAddress getListeningAddress() { + if (this.listenChannel == null) + return null; + if (this.listenChannel.socket() == null) + return null; + return this.listenChannel.socket().getLocalSocketAddress(); + } + + /* + * + */ + protected static enum ChangeType { + + REGISTER, CHANGEOPS + } + + private class ChangeRequest { + + private final SocketChannel sockChan; + private final ChangeType changeType; + private final Integer ops; + + public ChangeRequest(SocketChannel sockChan, ChangeType changeType, + int ops) { + this.sockChan = sockChan; + this.changeType = changeType; + this.ops = ops; + } + + public SocketChannel getSocketChannel() { + synchronized (this.sockChan) { + return this.sockChan; + } + } + + public ChangeType getChangeType() { + synchronized (this.changeType) { + return this.changeType; + } + } + + public int getOps() { + synchronized (this.ops) { + return this.ops; + } + } + } + + private class ReadOperationHander extends AbstractJob { + + private final SelectionKey sk; + private final AbstractConnection ac; + private final boolean runStatus; + + public ReadOperationHander(final SelectionKey sk) { + this.sk = sk; + + if (sk.attachment() instanceof AbstractConnection) { + this.ac = (AbstractConnection) sk.attachment(); + this.runStatus = this.ac.execTask.compareAndSet(false, true); + } else { + this.ac = null; + this.runStatus = false; + Logger.error("Passed selection key did not have a corresponding Connection!(Read)"); + } + } + + @Override + protected void doJob() { + if (runStatus) { + this.ac.connMan.receive(sk); + this.ac.execTask.compareAndSet(true, false); + } + } + } + + private class WriteOperationHander extends AbstractJob { + + private final SelectionKey sk; + private final AbstractConnection ac; + private final boolean runStatus; + + public WriteOperationHander(final SelectionKey sk) { + this.sk = sk; + + if (sk.attachment() instanceof AbstractConnection) { + this.ac = (AbstractConnection) sk.attachment(); + this.runStatus = this.ac.execTask.compareAndSet(false, true); + } else { + this.runStatus = false; + this.ac = null; + Logger.error("Passed selection key did not have a corresponding Connection!(Write)"); + } + + } + + @Override + protected void doJob() { + if (runStatus) { + this.ac.connMan.sendFinish(sk); + this.ac.execTask.compareAndSet(true, false); + } + } + } } diff --git a/src/engine/net/AbstractNetMsg.java b/src/engine/net/AbstractNetMsg.java index 1e8e9c1f..eb7e7095 100644 --- a/src/engine/net/AbstractNetMsg.java +++ b/src/engine/net/AbstractNetMsg.java @@ -24,15 +24,13 @@ import java.util.concurrent.ConcurrentHashMap; * MBServer Server Suite components. Note that since the NetMsgs sent to/from * the SBClient do NOT include a MsgLen or DataLen parameter, special * serialization/deserialization must be implemented. - * */ public abstract class AbstractNetMsg { + private static ConcurrentHashMap stats = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_HIGH); protected final Protocol protocolMsg; private AbstractConnection origin; - private static ConcurrentHashMap stats = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_HIGH); - /** * This is the general purpose constructor. * @@ -64,8 +62,7 @@ public abstract class AbstractNetMsg { * @param reader */ protected AbstractNetMsg(Protocol protocolMsg, AbstractConnection origin, - ByteBufferReader reader) - { + ByteBufferReader reader) { this.protocolMsg = protocolMsg; this.origin = origin; @@ -77,6 +74,13 @@ public abstract class AbstractNetMsg { } } + private static void allocHeader(ByteBufferWriter writer, int bytes) { + byte zero = 0; // prevents the int->byte cast + for (int h = 0; h < bytes; ++h) { + writer.put(zero); + } + } + /** * Deserializes the subclass specific items from the supplied * ByteBufferReader @@ -115,7 +119,7 @@ public abstract class AbstractNetMsg { int upperPow = lowerPow + 4; ByteBuffer bb = null; - + int startPos = 0; ByteBufferWriter writer = null; @@ -148,7 +152,7 @@ public abstract class AbstractNetMsg { } catch (BufferOverflowException boe) { Logger.error("BufferSize PowerOfTwo: " + i - + " is too small for " + protocolMsg != null? protocolMsg.name() : this.getClass().getName() + ", trying again with " + (i + 1)); + + " is too small for " + protocolMsg != null ? protocolMsg.name() : this.getClass().getName() + ", trying again with " + (i + 1)); //Return buffer. @@ -158,38 +162,31 @@ public abstract class AbstractNetMsg { } catch (Exception e) { //Return buffer. - Logger.error(e); - e.printStackTrace(); + Logger.error(e); + e.printStackTrace(); Network.byteBufferPool.putBuffer(bb); return null; } - // This shouldn't throw any errors since this part of the BB has + // This shouldn't throw any errors since this part of the BB has // already been allocated this.writeHeaderAt(startPos, writer); return writer.getBb(); } - // If we get here, its not a successful serialization and lastError + // If we get here, its not a successful serialization and lastError // should be set return null; } - private static void allocHeader(ByteBufferWriter writer, int bytes) { - byte zero = 0; // prevents the int->byte cast - for (int h = 0; h < bytes; ++h) { - writer.put(zero); - } - } - /** * Function allows for setting other than default initial Buffer size for * the Serializer. Override and return the size of the buffer in power of * two bytes. - * + *

* Example, if you would like a buffer of 65535, then return 16 from this * value since 2^16 = 65535 * @@ -210,10 +207,8 @@ public abstract class AbstractNetMsg { * Forces subclasses to implement how to write its own header into a * byteBuffer * - * @param startPos - * - starting position for the header write - * @param writer - * - ByteBufferWriter to write the header to. + * @param startPos - starting position for the header write + * @param writer - ByteBufferWriter to write the header to. */ protected abstract void writeHeaderAt(int startPos, ByteBufferWriter writer); diff --git a/src/engine/net/ByteBufferReader.java b/src/engine/net/ByteBufferReader.java index f5bb71b1..10a77a8f 100644 --- a/src/engine/net/ByteBufferReader.java +++ b/src/engine/net/ByteBufferReader.java @@ -21,350 +21,352 @@ import java.util.UUID; public class ByteBufferReader { - private final ByteBuffer bb; - private final boolean endianFlip; - - /** - * Helper class for getting structured information out of a ByteBuffer - * easily. ByteBuffer passed in is copied to an internal ByteBuffer. - * bbin must have the position attribute at the end of the - * data to be copied over, since bbin.flip() is called in this - * constructor. - * - * @param bbin - * @param endianFlip - */ - public ByteBufferReader(ByteBuffer bbin, boolean endianFlip) { - super(); - - // Copy supplied BB. - this.bb = ByteBuffer.allocate(bbin.position()); //FIXME Do we want to get this from pool? - bbin.flip(); - this.bb.put(bbin); - - // prepare bb for reading - this.bb.flip(); - - this.endianFlip = endianFlip; - } - - /* - * Getters - */ - - /** - * @return - * @see java.nio.ByteBuffer#get() - */ - public byte get() { - return bb.get(); - } - - public void get(byte[] ba) { - this.bb.get(ba); - } - - /** - * @return - * @see java.nio.ByteBuffer#getChar() - */ - public char getChar() { - char x = bb.getChar(); - if (this.endianFlip) { - x = Character.reverseBytes(x); - } - return x; - } - - /** - * @return - * @see java.nio.ByteBuffer#getDouble() - */ - public double getDouble() { - double x = 0; - if (this.endianFlip) { - x = bb.order(ByteOrder.LITTLE_ENDIAN).getDouble(); - bb.order(ByteOrder.BIG_ENDIAN); - } else { - x = bb.getDouble(); - } - return x; - } - - /** - * @return - * @see java.nio.ByteBuffer#getFloat() - */ - public float getFloat() { - float x = 0; - if (this.endianFlip) { - x = bb.order(ByteOrder.LITTLE_ENDIAN).getFloat(); - bb.order(ByteOrder.BIG_ENDIAN); - } else { - x = bb.getFloat(); - } - return x; - } - - /** - * @return - * @see java.nio.ByteBuffer#getInt() - */ - public int getInt() { - int x = bb.getInt(); - if (this.endianFlip) { - x = Integer.reverseBytes(x); - } - return x; - } - - /** - * @return - * @see java.nio.ByteBuffer#getLong() - */ - public long getLong() { - long x = bb.getLong(); - if (this.endianFlip) { - x = Long.reverseBytes(x); - } - return x; - } - - /** - * @return - * @see java.nio.ByteBuffer#getShort() - */ - public short getShort() { - short x = bb.getShort(); - if (this.endianFlip) { - x = Short.reverseBytes(x); - } - return x; - } - - public final String getString() { - if (this.endianFlip) { - return ByteBufferUtils.getString(this.bb, true, false); - } else { - return ByteBufferUtils.getString(this.bb, false, false); - } - } - - public final String getSmallString() { - if (this.endianFlip) { - return ByteBufferUtils.getString(this.bb, true, true); - } else { - return ByteBufferUtils.getString(this.bb, false, true); - } - } - - public final String getHexString() { - if (this.endianFlip) { - return ByteBufferUtils.getHexString(this.bb, true); - } else { - return ByteBufferUtils.getHexString(this.bb); - } - } - - public final String getUnicodeString() { - if (this.endianFlip) { - return ByteBufferUtils.getUnicodeString(this.bb, true); - } else { - return ByteBufferUtils.getUnicodeString(this.bb); - } - } - - public String get1ByteAsHexString() { - return getBytesAsHexStringCommon(new byte[1]); - } - - public String get2BytesAsHexString() { - return getBytesAsHexStringCommon(new byte[2]); - } - - public String get4BytesAsHexString() { - return getBytesAsHexStringCommon(new byte[4]); - } - - public String get8BytesAsHexString() { - return getBytesAsHexStringCommon(new byte[8]); - } - - private String getBytesAsHexStringCommon(byte[] ba) { - this.bb.get(ba); - if (this.endianFlip) { - return ByteUtils.byteArrayToStringHex(ByteUtils - .switchByteArrayEndianness(ba)); - } else { - return ByteUtils.byteArrayToStringHex(ba); - } - } - - public Vector3f getVector3f() { - Vector3f out = new Vector3f(); - if (this.endianFlip) { - out.x = Float - .intBitsToFloat(Integer.reverseBytes(this.bb.getInt())); - out.y = Float - .intBitsToFloat(Integer.reverseBytes(this.bb.getInt())); - out.z = Float - .intBitsToFloat(Integer.reverseBytes(this.bb.getInt())); - } else { - out.x = this.bb.getFloat(); - out.y = this.bb.getFloat(); - out.z = this.bb.getFloat(); - } - return out; - } - - public Vector3fImmutable getVector3fImmutable() { - Vector3fImmutable out; - if (this.endianFlip) { - out = new Vector3fImmutable(Float.intBitsToFloat(Integer - .reverseBytes(this.bb.getInt())), Float - .intBitsToFloat(Integer.reverseBytes(this.bb.getInt())), - Float - .intBitsToFloat(Integer.reverseBytes(this.bb - .getInt()))); - } else { - out = new Vector3fImmutable(this.bb.getFloat(), this.bb.getFloat(), - this.bb.getFloat()); - } - return out; - } - - public final UUID getUUID() { - final byte[] buffer = new byte[16]; - this.bb.get(buffer); - - long msb = 0; - long lsb = 0; - - for (int i = 0; i < 8; i++) { - msb = (msb << 8) | (buffer[i] & 0xff); - } - - for (int i = 8; i < 16; i++) { - lsb = (lsb << 8) | (buffer[i] & 0xff); - } + private final ByteBuffer bb; + private final boolean endianFlip; + + /** + * Helper class for getting structured information out of a ByteBuffer + * easily. ByteBuffer passed in is copied to an internal ByteBuffer. + * bbin must have the position attribute at the end of the + * data to be copied over, since bbin.flip() is called in this + * constructor. + * + * @param bbin + * @param endianFlip + */ + public ByteBufferReader(ByteBuffer bbin, boolean endianFlip) { + super(); + + // Copy supplied BB. + this.bb = ByteBuffer.allocate(bbin.position()); //FIXME Do we want to get this from pool? + bbin.flip(); + this.bb.put(bbin); + + // prepare bb for reading + this.bb.flip(); + + this.endianFlip = endianFlip; + } + + /* + * Getters + */ + + /** + * @return + * @see java.nio.ByteBuffer#get() + */ + public byte get() { + return bb.get(); + } + + public void get(byte[] ba) { + this.bb.get(ba); + } + + /** + * @return + * @see java.nio.ByteBuffer#getChar() + */ + public char getChar() { + char x = bb.getChar(); + if (this.endianFlip) { + x = Character.reverseBytes(x); + } + return x; + } + + /** + * @return + * @see java.nio.ByteBuffer#getDouble() + */ + public double getDouble() { + double x = 0; + if (this.endianFlip) { + x = bb.order(ByteOrder.LITTLE_ENDIAN).getDouble(); + bb.order(ByteOrder.BIG_ENDIAN); + } else { + x = bb.getDouble(); + } + return x; + } + + /** + * @return + * @see java.nio.ByteBuffer#getFloat() + */ + public float getFloat() { + float x = 0; + if (this.endianFlip) { + x = bb.order(ByteOrder.LITTLE_ENDIAN).getFloat(); + bb.order(ByteOrder.BIG_ENDIAN); + } else { + x = bb.getFloat(); + } + return x; + } + + /** + * @return + * @see java.nio.ByteBuffer#getInt() + */ + public int getInt() { + int x = bb.getInt(); + if (this.endianFlip) { + x = Integer.reverseBytes(x); + } + return x; + } + + /** + * @return + * @see java.nio.ByteBuffer#getLong() + */ + public long getLong() { + long x = bb.getLong(); + if (this.endianFlip) { + x = Long.reverseBytes(x); + } + return x; + } + + /** + * @return + * @see java.nio.ByteBuffer#getShort() + */ + public short getShort() { + short x = bb.getShort(); + if (this.endianFlip) { + x = Short.reverseBytes(x); + } + return x; + } + + public final String getString() { + if (this.endianFlip) { + return ByteBufferUtils.getString(this.bb, true, false); + } else { + return ByteBufferUtils.getString(this.bb, false, false); + } + } + + public final String getSmallString() { + if (this.endianFlip) { + return ByteBufferUtils.getString(this.bb, true, true); + } else { + return ByteBufferUtils.getString(this.bb, false, true); + } + } + + public final String getHexString() { + if (this.endianFlip) { + return ByteBufferUtils.getHexString(this.bb, true); + } else { + return ByteBufferUtils.getHexString(this.bb); + } + } + + public final String getUnicodeString() { + if (this.endianFlip) { + return ByteBufferUtils.getUnicodeString(this.bb, true); + } else { + return ByteBufferUtils.getUnicodeString(this.bb); + } + } + + public String get1ByteAsHexString() { + return getBytesAsHexStringCommon(new byte[1]); + } + + public String get2BytesAsHexString() { + return getBytesAsHexStringCommon(new byte[2]); + } + + public String get4BytesAsHexString() { + return getBytesAsHexStringCommon(new byte[4]); + } + + public String get8BytesAsHexString() { + return getBytesAsHexStringCommon(new byte[8]); + } + + private String getBytesAsHexStringCommon(byte[] ba) { + this.bb.get(ba); + if (this.endianFlip) { + return ByteUtils.byteArrayToStringHex(ByteUtils + .switchByteArrayEndianness(ba)); + } else { + return ByteUtils.byteArrayToStringHex(ba); + } + } + + public Vector3f getVector3f() { + Vector3f out = new Vector3f(); + if (this.endianFlip) { + out.x = Float + .intBitsToFloat(Integer.reverseBytes(this.bb.getInt())); + out.y = Float + .intBitsToFloat(Integer.reverseBytes(this.bb.getInt())); + out.z = Float + .intBitsToFloat(Integer.reverseBytes(this.bb.getInt())); + } else { + out.x = this.bb.getFloat(); + out.y = this.bb.getFloat(); + out.z = this.bb.getFloat(); + } + return out; + } + + public Vector3fImmutable getVector3fImmutable() { + Vector3fImmutable out; + if (this.endianFlip) { + out = new Vector3fImmutable(Float.intBitsToFloat(Integer + .reverseBytes(this.bb.getInt())), Float + .intBitsToFloat(Integer.reverseBytes(this.bb.getInt())), + Float + .intBitsToFloat(Integer.reverseBytes(this.bb + .getInt()))); + } else { + out = new Vector3fImmutable(this.bb.getFloat(), this.bb.getFloat(), + this.bb.getFloat()); + } + return out; + } + + public final UUID getUUID() { + final byte[] buffer = new byte[16]; + this.bb.get(buffer); + + long msb = 0; + long lsb = 0; + + for (int i = 0; i < 8; i++) { + msb = (msb << 8) | (buffer[i] & 0xff); + } + + for (int i = 8; i < 16; i++) { + lsb = (lsb << 8) | (buffer[i] & 0xff); + } return new UUID(msb, lsb); - } + } - - /* - * Monitors - */ - public byte monitorByte(byte expectedValue, String label) { - return this.monitorByte(expectedValue, label, false); - } + /* + * Monitors + */ - public byte monitorByte(byte expectedValue, String label, boolean peek) { + public byte monitorByte(byte expectedValue, String label) { + return this.monitorByte(expectedValue, label, false); + } + + public byte monitorByte(byte expectedValue, String label, boolean peek) { // if (x != expectedValue) { // Logger.info("MonitorTrip: " + label + ". Expected: " // + expectedValue + " Got: " + x); // } - return this.get(); - } + return this.get(); + } - public short monitorShort(short expectedValue, String label) { - return this.monitorShort(expectedValue, label, false); - } + public short monitorShort(short expectedValue, String label) { + return this.monitorShort(expectedValue, label, false); + } - public short monitorShort(short expectedValue, String label, boolean peek) { + public short monitorShort(short expectedValue, String label, boolean peek) { // if (x != expectedValue) { // Logger.info("MonitorTrip: " + label + ". Expected: " // + expectedValue + " Got: " + x); // } - return this.getShort(); - } + return this.getShort(); + } - public int monitorInt(int expectedValue, String label) { - return this.monitorInt(expectedValue, label, false); - } + public int monitorInt(int expectedValue, String label) { + return this.monitorInt(expectedValue, label, false); + } - public int monitorInt(int expectedValue, String label, boolean peek) { + public int monitorInt(int expectedValue, String label, boolean peek) { // if (x != expectedValue) { // Logger.info("MonitorTrip: " + label + ". Expected: " // + expectedValue + " Got: " + x); // } - return this.getInt(); - } + return this.getInt(); + } - public long monitorLong(long expectedValue, String label) { - return this.monitorLong(expectedValue, label, false); - } + public long monitorLong(long expectedValue, String label) { + return this.monitorLong(expectedValue, label, false); + } - public long monitorLong(long expectedValue, String label, boolean peek) { + public long monitorLong(long expectedValue, String label, boolean peek) { // if (x != expectedValue) { // Logger.info("MonitorTrip: " + label + ". Expected: " // + expectedValue + " Got: " + x); // } - return this.getLong(); - } - - /* - * ByteBuffer delegates - */ - - /** - * @return - * @see java.nio.Buffer#hasRemaining() - */ - public final boolean hasRemaining() { - return bb.hasRemaining(); - } - - /** - * @return - * @see java.nio.Buffer#limit() - */ - public final int limit() { - return bb.limit(); - } - - /** - * @return - * @see java.nio.Buffer#position() - */ - public final int position() { - return bb.position(); - } - public final Buffer position(int newPosition){ - return bb.position(newPosition); - } - /** - * @return - * @see java.nio.Buffer#remaining() - */ - public final int remaining() { - return bb.remaining(); - } - - /* - * Status getters - */ - - protected ByteBuffer getBb() { - return bb; - } - - protected boolean isEndianFlip() { - return endianFlip; - } - - public String getByteArray() { - String ret = ""; - if (this.bb == null) - return ret; - byte[] bbyte = bb.array(); - if (bbyte == null) - return ret; - for (int i=0;i>> 8 * (7 - i)); - } - - for (int i = 8; i < 16; i++) { - buffer[i] = (byte) (lsb >>> 8 * (7 - i)); - } - - this.bb.put(buffer); - } - - /** - * @return - * @see java.nio.Buffer#hasRemaining() - */ - public final boolean hasRemaining() { - return bb.hasRemaining(); - } - - /** - * @return - * @see java.nio.Buffer#limit() - */ - public final int limit() { - return bb.limit(); - } - - /** - * @return - * @see java.nio.Buffer#position() - */ - public final int position() { - return bb.position(); - } - - /** - * @return - * @see java.nio.Buffer#remaining() - */ - public final int remaining() { - return bb.remaining(); - } - - /* - * Getters - */ - - public synchronized ByteBuffer getBb() { - return this.bb; - } + bbin.flip(); + this.bb.put(bbin); + } + } + + public synchronized void putBB(ByteBuffer bb) { + synchronized (bb) { + bb.flip(); + this.bb.put(bb); + } + } + + public synchronized void putIntAt(int value, int position) { + // mark end position + int endPosition = this.position(); + + // go back to the desired position + this.bb.position(position); + + // Write in the value: + this.putInt(value); + + // now go back to end: + this.bb.position(endPosition); + } + + public synchronized void putVector3f(Vector3f x) { + this.bb.putFloat(x.x); + this.bb.putFloat(x.y); + this.bb.putFloat(x.z); + } + + public synchronized void putVector3f(Vector3fImmutable x) { + this.bb.putFloat(x.x); + this.bb.putFloat(x.y); + this.bb.putFloat(x.z); + } + + public synchronized void putUUID(final UUID uuid) { + final long msb = uuid.getMostSignificantBits(); + final long lsb = uuid.getLeastSignificantBits(); + final byte[] buffer = new byte[16]; + + for (int i = 0; i < 8; i++) { + buffer[i] = (byte) (msb >>> 8 * (7 - i)); + } + + for (int i = 8; i < 16; i++) { + buffer[i] = (byte) (lsb >>> 8 * (7 - i)); + } + + this.bb.put(buffer); + } + + /** + * @return + * @see java.nio.Buffer#hasRemaining() + */ + public final boolean hasRemaining() { + return bb.hasRemaining(); + } + + /** + * @return + * @see java.nio.Buffer#limit() + */ + public final int limit() { + return bb.limit(); + } + + /** + * @return + * @see java.nio.Buffer#position() + */ + public final int position() { + return bb.position(); + } + + /** + * @return + * @see java.nio.Buffer#remaining() + */ + public final int remaining() { + return bb.remaining(); + } + + /* + * Getters + */ + + public synchronized ByteBuffer getBb() { + return this.bb; + } } diff --git a/src/engine/net/CheckNetMsgFactoryJob.java b/src/engine/net/CheckNetMsgFactoryJob.java index 4f67417a..5f93b596 100644 --- a/src/engine/net/CheckNetMsgFactoryJob.java +++ b/src/engine/net/CheckNetMsgFactoryJob.java @@ -15,39 +15,39 @@ import org.pmw.tinylog.Logger; public class CheckNetMsgFactoryJob extends AbstractJob { - private final AbstractConnection conn; - - public CheckNetMsgFactoryJob(AbstractConnection conn) { - super(); - this.conn = conn; - } - - @Override - protected void doJob() { - NetMsgFactory factory = conn.getFactory(); - - // Make any/all msg possible - factory.parseBuffer(); - - // get and route. - AbstractNetMsg msg = factory.getMsg(); - while (msg != null) { - - // Conditionally check to see if origin is set. - if (msg.getOrigin() == null) { - Logger.warn(msg.getClass().getSimpleName() + " had a NULL for its 'origin'."); - msg.setOrigin(this.conn); - } - - if (msg instanceof engine.net.client.msg.ClientNetMsg) { - ConfigManager.handler.handleClientMsg((ClientNetMsg) msg); - - } else { - Logger.error("Unrouteable message of type '" + msg.getClass().getSimpleName() + '\''); - } - - msg = factory.getMsg(); - } - } + private final AbstractConnection conn; + + public CheckNetMsgFactoryJob(AbstractConnection conn) { + super(); + this.conn = conn; + } + + @Override + protected void doJob() { + NetMsgFactory factory = conn.getFactory(); + + // Make any/all msg possible + factory.parseBuffer(); + + // get and route. + AbstractNetMsg msg = factory.getMsg(); + while (msg != null) { + + // Conditionally check to see if origin is set. + if (msg.getOrigin() == null) { + Logger.warn(msg.getClass().getSimpleName() + " had a NULL for its 'origin'."); + msg.setOrigin(this.conn); + } + + if (msg instanceof engine.net.client.msg.ClientNetMsg) { + ConfigManager.handler.handleClientMsg((ClientNetMsg) msg); + + } else { + Logger.error("Unrouteable message of type '" + msg.getClass().getSimpleName() + '\''); + } + + msg = factory.getMsg(); + } + } } diff --git a/src/engine/net/Dispatch.java b/src/engine/net/Dispatch.java index d095f08b..ebbdb4de 100644 --- a/src/engine/net/Dispatch.java +++ b/src/engine/net/Dispatch.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -19,7 +16,6 @@ // www.magicbane.com - package engine.net; import engine.objects.PlayerCharacter; @@ -35,40 +31,40 @@ import static engine.net.MessageDispatcher.itemPoolSize; public class Dispatch { private static final ConcurrentLinkedQueue dispatchPool = new ConcurrentLinkedQueue<>(); - - public PlayerCharacter player; - public AbstractNetMsg msg; - - public Dispatch(PlayerCharacter player, AbstractNetMsg msg) { + + public PlayerCharacter player; + public AbstractNetMsg msg; + + public Dispatch(PlayerCharacter player, AbstractNetMsg msg) { this.player = player; - this.msg = msg; -} - - public void reset() { - this.player = null; - this.msg = null; - } - - public static Dispatch borrow(PlayerCharacter player, AbstractNetMsg msg) { - - Dispatch dispatch; - - dispatch = dispatchPool.poll(); - - if (dispatch == null) { - dispatch = new Dispatch(player, msg); - } else { - dispatch.player = player; - dispatch.msg = msg; - itemPoolSize.decrement(); - } - - return dispatch; - } - - public void release() { - this.reset(); - dispatchPool.add(this); - itemPoolSize.increment(); + this.msg = msg; + } + + public static Dispatch borrow(PlayerCharacter player, AbstractNetMsg msg) { + + Dispatch dispatch; + + dispatch = dispatchPool.poll(); + + if (dispatch == null) { + dispatch = new Dispatch(player, msg); + } else { + dispatch.player = player; + dispatch.msg = msg; + itemPoolSize.decrement(); } + + return dispatch; + } + + public void reset() { + this.player = null; + this.msg = null; + } + + public void release() { + this.reset(); + dispatchPool.add(this); + itemPoolSize.increment(); + } } diff --git a/src/engine/net/DispatchMessage.java b/src/engine/net/DispatchMessage.java index 626aac47..65fcc87f 100644 --- a/src/engine/net/DispatchMessage.java +++ b/src/engine/net/DispatchMessage.java @@ -33,280 +33,280 @@ import static engine.net.MessageDispatcher.maxRecipients; public class DispatchMessage { - public static void startMessagePump() { + public static void startMessagePump() { - Thread messageDispatcher; - messageDispatcher = new Thread(new MessageDispatcher()); + Thread messageDispatcher; + messageDispatcher = new Thread(new MessageDispatcher()); - messageDispatcher.setName("MessageDispatcher"); - messageDispatcher.start(); - } + messageDispatcher.setName("MessageDispatcher"); + messageDispatcher.start(); + } - public static void sendToAllInRange(AbstractWorldObject obj, - AbstractNetMsg msg){ + public static void sendToAllInRange(AbstractWorldObject obj, + AbstractNetMsg msg) { - if (obj == null) - return; + if (obj == null) + return; - if (obj.getObjectType() == GameObjectType.PlayerCharacter || obj.getObjectType() == GameObjectType.Mob || obj.getObjectType() == GameObjectType.NPC || obj.getObjectType() == GameObjectType.Corpse) - dispatchMsgToInterestArea(obj, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - else - dispatchMsgToInterestArea(obj ,msg, DispatchChannel.PRIMARY, MBServerStatics.STRUCTURE_LOAD_RANGE, false, false); + if (obj.getObjectType() == GameObjectType.PlayerCharacter || obj.getObjectType() == GameObjectType.Mob || obj.getObjectType() == GameObjectType.NPC || obj.getObjectType() == GameObjectType.Corpse) + dispatchMsgToInterestArea(obj, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + else + dispatchMsgToInterestArea(obj, msg, DispatchChannel.PRIMARY, MBServerStatics.STRUCTURE_LOAD_RANGE, false, false); - } + } - // Dispatches a message to a playercharacter's interest area - // Method includes handling of exclusion rules for visibility, self, etc. + // Dispatches a message to a playercharacter's interest area + // Method includes handling of exclusion rules for visibility, self, etc. - public static void dispatchMsgToInterestArea(AbstractWorldObject sourceObject, AbstractNetMsg msg, DispatchChannel dispatchChannel, int interestRange, boolean sendToSelf, boolean useIgnore) { + public static void dispatchMsgToInterestArea(AbstractWorldObject sourceObject, AbstractNetMsg msg, DispatchChannel dispatchChannel, int interestRange, boolean sendToSelf, boolean useIgnore) { - Dispatch messageDispatch; - HashSet gridList; - PlayerCharacter gridPlayer; - AbstractWorldObject dispatchSource; - PlayerCharacter sourcePlayer = null; - long recipientCount = 0; + Dispatch messageDispatch; + HashSet gridList; + PlayerCharacter gridPlayer; + AbstractWorldObject dispatchSource; + PlayerCharacter sourcePlayer = null; + long recipientCount = 0; - if (sourceObject == null) - return; + if (sourceObject == null) + return; - // If the source of the message is a structure, item or player - // setup our method variables accordingly. + // If the source of the message is a structure, item or player + // setup our method variables accordingly. - switch (sourceObject.getObjectType()) { - case Item: - dispatchSource = (AbstractWorldObject) ((Item) sourceObject).getOwner(); - break; - case PlayerCharacter: - dispatchSource = sourceObject; - sourcePlayer = (PlayerCharacter)sourceObject; - if (sourcePlayer.getClientConnection() != null && sendToSelf){ - Dispatch dispatch = Dispatch.borrow(sourcePlayer, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - } + switch (sourceObject.getObjectType()) { + case Item: + dispatchSource = (AbstractWorldObject) ((Item) sourceObject).getOwner(); + break; + case PlayerCharacter: + dispatchSource = sourceObject; + sourcePlayer = (PlayerCharacter) sourceObject; + if (sourcePlayer.getClientConnection() != null && sendToSelf) { + Dispatch dispatch = Dispatch.borrow(sourcePlayer, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + } - break; - default: - dispatchSource = sourceObject; - } + break; + default: + dispatchSource = sourceObject; + } - gridList = WorldGrid.getObjectsInRangePartial(dispatchSource.getLoc(), interestRange, MBServerStatics.MASK_PLAYER); + gridList = WorldGrid.getObjectsInRangePartial(dispatchSource.getLoc(), interestRange, MBServerStatics.MASK_PLAYER); - for (AbstractWorldObject gridObject : gridList) { + for (AbstractWorldObject gridObject : gridList) { - gridPlayer = (PlayerCharacter)gridObject; + gridPlayer = (PlayerCharacter) gridObject; - // Apply filter options if source of dispatch is a player + // Apply filter options if source of dispatch is a player - if ((dispatchSource.getObjectType() == GameObjectType.PlayerCharacter) && - (sourcePlayer != null)) { + if ((dispatchSource.getObjectType() == GameObjectType.PlayerCharacter) && + (sourcePlayer != null)) { - if (gridPlayer.getObjectUUID() == sourcePlayer.getObjectUUID()) - continue; + if (gridPlayer.getObjectUUID() == sourcePlayer.getObjectUUID()) + continue; - if ((useIgnore == true) && (gridPlayer.isIgnoringPlayer(sourcePlayer) == true)) - continue; + if ((useIgnore == true) && (gridPlayer.isIgnoringPlayer(sourcePlayer) == true)) + continue; - if(gridPlayer.canSee(sourcePlayer) == false) - continue; - } + if (gridPlayer.canSee(sourcePlayer) == false) + continue; + } - messageDispatch = Dispatch.borrow(gridPlayer, msg); - MessageDispatcher.send(messageDispatch, dispatchChannel); - recipientCount++; - } + messageDispatch = Dispatch.borrow(gridPlayer, msg); + MessageDispatcher.send(messageDispatch, dispatchChannel); + recipientCount++; + } - // Update metrics + // Update metrics - if (recipientCount > maxRecipients[dispatchChannel.getChannelID()]) - maxRecipients[dispatchChannel.getChannelID()] = recipientCount; + if (recipientCount > maxRecipients[dispatchChannel.getChannelID()]) + maxRecipients[dispatchChannel.getChannelID()] = recipientCount; - dispatchCount[dispatchChannel.getChannelID()].increment(); - } + dispatchCount[dispatchChannel.getChannelID()].increment(); + } - public static void dispatchMsgToInterestArea(Vector3fImmutable targetLoc,AbstractWorldObject sourceObject, AbstractNetMsg msg, DispatchChannel dispatchChannel, int interestRange, boolean sendToSelf, boolean useIgnore) { + public static void dispatchMsgToInterestArea(Vector3fImmutable targetLoc, AbstractWorldObject sourceObject, AbstractNetMsg msg, DispatchChannel dispatchChannel, int interestRange, boolean sendToSelf, boolean useIgnore) { - Dispatch messageDispatch; - HashSet gridList; - PlayerCharacter gridPlayer; - AbstractWorldObject dispatchSource; - PlayerCharacter sourcePlayer = null; - long recipientCount = 0; + Dispatch messageDispatch; + HashSet gridList; + PlayerCharacter gridPlayer; + AbstractWorldObject dispatchSource; + PlayerCharacter sourcePlayer = null; + long recipientCount = 0; - if (sourceObject == null) - return; + if (sourceObject == null) + return; - // If the source of the message is a structure, item or player - // setup our method variables accordingly. + // If the source of the message is a structure, item or player + // setup our method variables accordingly. - switch (sourceObject.getObjectType()) { - case Item: - dispatchSource = (AbstractWorldObject) ((Item) sourceObject).getOwner(); - break; - case PlayerCharacter: - dispatchSource = sourceObject; - sourcePlayer = (PlayerCharacter)sourceObject; + switch (sourceObject.getObjectType()) { + case Item: + dispatchSource = (AbstractWorldObject) ((Item) sourceObject).getOwner(); + break; + case PlayerCharacter: + dispatchSource = sourceObject; + sourcePlayer = (PlayerCharacter) sourceObject; - if (sourcePlayer.getClientConnection() != null && sendToSelf){ - Dispatch dispatch = Dispatch.borrow(sourcePlayer, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - } + if (sourcePlayer.getClientConnection() != null && sendToSelf) { + Dispatch dispatch = Dispatch.borrow(sourcePlayer, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + } - break; - default: - dispatchSource = sourceObject; - } + break; + default: + dispatchSource = sourceObject; + } - gridList = WorldGrid.getObjectsInRangePartial(targetLoc, interestRange, MBServerStatics.MASK_PLAYER); + gridList = WorldGrid.getObjectsInRangePartial(targetLoc, interestRange, MBServerStatics.MASK_PLAYER); - for (AbstractWorldObject gridObject : gridList) { + for (AbstractWorldObject gridObject : gridList) { - gridPlayer = (PlayerCharacter)gridObject; + gridPlayer = (PlayerCharacter) gridObject; - // Apply filter options if source of dispatch is a player + // Apply filter options if source of dispatch is a player - if ((dispatchSource.getObjectType() == GameObjectType.PlayerCharacter) && - (sourcePlayer != null)) { + if ((dispatchSource.getObjectType() == GameObjectType.PlayerCharacter) && + (sourcePlayer != null)) { - if (gridPlayer.getObjectUUID() == sourcePlayer.getObjectUUID()) - continue; + if (gridPlayer.getObjectUUID() == sourcePlayer.getObjectUUID()) + continue; - if ((useIgnore == true) && (gridPlayer.isIgnoringPlayer(sourcePlayer) == true)) - continue; + if ((useIgnore == true) && (gridPlayer.isIgnoringPlayer(sourcePlayer) == true)) + continue; - if(gridPlayer.canSee(sourcePlayer) == false) - continue; - } + if (gridPlayer.canSee(sourcePlayer) == false) + continue; + } - messageDispatch = Dispatch.borrow(gridPlayer, msg); - MessageDispatcher.send(messageDispatch, dispatchChannel); - recipientCount++; - } + messageDispatch = Dispatch.borrow(gridPlayer, msg); + MessageDispatcher.send(messageDispatch, dispatchChannel); + recipientCount++; + } - // Update metrics + // Update metrics - if (recipientCount > maxRecipients[dispatchChannel.getChannelID()]) - maxRecipients[dispatchChannel.getChannelID()] = recipientCount; + if (recipientCount > maxRecipients[dispatchChannel.getChannelID()]) + maxRecipients[dispatchChannel.getChannelID()] = recipientCount; - dispatchCount[dispatchChannel.getChannelID()].increment(); - } + dispatchCount[dispatchChannel.getChannelID()].increment(); + } - // Sends a message to all players in the game + // Sends a message to all players in the game - public static void dispatchMsgToAll(AbstractNetMsg msg) { + public static void dispatchMsgToAll(AbstractNetMsg msg) { - Dispatch messageDispatch; - long recipientCount = 0; + Dispatch messageDispatch; + long recipientCount = 0; - // Send message to nobody? No thanks! + // Send message to nobody? No thanks! - if (SessionManager.getAllActivePlayerCharacters().isEmpty()) - return; + if (SessionManager.getAllActivePlayerCharacters().isEmpty()) + return; - // Messages to all we will default to the secondary dispatch - // delivery channel. They are generally large, or inconsequential. + // Messages to all we will default to the secondary dispatch + // delivery channel. They are generally large, or inconsequential. - for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) { - messageDispatch = Dispatch.borrow(player, msg); - MessageDispatcher.send(messageDispatch, DispatchChannel.SECONDARY); - recipientCount++; - } + for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) { + messageDispatch = Dispatch.borrow(player, msg); + MessageDispatcher.send(messageDispatch, DispatchChannel.SECONDARY); + recipientCount++; + } - // Update metrics + // Update metrics - if (recipientCount > maxRecipients[DispatchChannel.SECONDARY.getChannelID()]) - maxRecipients[DispatchChannel.SECONDARY.getChannelID()] = recipientCount; + if (recipientCount > maxRecipients[DispatchChannel.SECONDARY.getChannelID()]) + maxRecipients[DispatchChannel.SECONDARY.getChannelID()] = recipientCount; - dispatchCount[DispatchChannel.SECONDARY.getChannelID()].increment(); + dispatchCount[DispatchChannel.SECONDARY.getChannelID()].increment(); - } - - public static void dispatchMsgToAll(PlayerCharacter source, AbstractNetMsg msg, boolean ignore) { + } - Dispatch messageDispatch; - long recipientCount = 0; + public static void dispatchMsgToAll(PlayerCharacter source, AbstractNetMsg msg, boolean ignore) { - // Send message to nobody? No thanks! + Dispatch messageDispatch; + long recipientCount = 0; - if (SessionManager.getAllActivePlayerCharacters().isEmpty()) - return; + // Send message to nobody? No thanks! - // Messages to all we will default to the secondary dispatch - // delivery channel. They are generally large, or inconsequential. + if (SessionManager.getAllActivePlayerCharacters().isEmpty()) + return; - for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) { - - if (ignore && player.isIgnoringPlayer(source)) - continue; - - messageDispatch = Dispatch.borrow(player, msg); - MessageDispatcher.send(messageDispatch, DispatchChannel.SECONDARY); - recipientCount++; - } + // Messages to all we will default to the secondary dispatch + // delivery channel. They are generally large, or inconsequential. - // Update metrics + for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) { - if (recipientCount > maxRecipients[DispatchChannel.SECONDARY.getChannelID()]) - maxRecipients[DispatchChannel.SECONDARY.getChannelID()] = recipientCount; + if (ignore && player.isIgnoringPlayer(source)) + continue; - dispatchCount[DispatchChannel.SECONDARY.getChannelID()].increment(); + messageDispatch = Dispatch.borrow(player, msg); + MessageDispatcher.send(messageDispatch, DispatchChannel.SECONDARY); + recipientCount++; + } - } + // Update metrics - // Sends a message to an arbitrary distribution list + if (recipientCount > maxRecipients[DispatchChannel.SECONDARY.getChannelID()]) + maxRecipients[DispatchChannel.SECONDARY.getChannelID()] = recipientCount; - public static void dispatchMsgDispatch(Dispatch messageDispatch, DispatchChannel dispatchChannel) { - - if (messageDispatch == null){ - Logger.info("DISPATCH Null for DispatchMessage!"); - return; - } + dispatchCount[DispatchChannel.SECONDARY.getChannelID()].increment(); - // No need to serialize an empty list + } - if (messageDispatch.player == null){ - Logger.info("Player Null for Dispatch!"); - messageDispatch.release(); - return; - } - + // Sends a message to an arbitrary distribution list - MessageDispatcher.send(messageDispatch, dispatchChannel); + public static void dispatchMsgDispatch(Dispatch messageDispatch, DispatchChannel dispatchChannel) { - dispatchCount[dispatchChannel.getChannelID()].increment(); + if (messageDispatch == null) { + Logger.info("DISPATCH Null for DispatchMessage!"); + return; + } - } + // No need to serialize an empty list - protected static void serializeDispatch(Dispatch messageDispatch) { - ClientConnection connection; + if (messageDispatch.player == null) { + Logger.info("Player Null for Dispatch!"); + messageDispatch.release(); + return; + } - if (messageDispatch.player == null){ - Logger.info("Player null in serializeDispatch"); - messageDispatch.release(); - return; - } - connection = messageDispatch.player.getClientConnection(); + MessageDispatcher.send(messageDispatch, dispatchChannel); - if ((connection == null) || (connection.isConnected() == false)) { - messageDispatch.release(); - return; - } + dispatchCount[dispatchChannel.getChannelID()].increment(); - if (messageDispatch.msg == null) { - Logger.error("null message sent to " + messageDispatch.player.getName()); - messageDispatch.release(); - return; - } + } - if (!connection.sendMsg(messageDispatch.msg)) - Logger.error(messageDispatch.msg.getProtocolMsg() + " failed sending to " + messageDispatch.player.getName()); + protected static void serializeDispatch(Dispatch messageDispatch) { + ClientConnection connection; - messageDispatch.release(); - } + if (messageDispatch.player == null) { + Logger.info("Player null in serializeDispatch"); + messageDispatch.release(); + return; + } + + connection = messageDispatch.player.getClientConnection(); + + if ((connection == null) || (connection.isConnected() == false)) { + messageDispatch.release(); + return; + } + + if (messageDispatch.msg == null) { + Logger.error("null message sent to " + messageDispatch.player.getName()); + messageDispatch.release(); + return; + } + + if (!connection.sendMsg(messageDispatch.msg)) + Logger.error(messageDispatch.msg.getProtocolMsg() + " failed sending to " + messageDispatch.player.getName()); + + messageDispatch.release(); + } } diff --git a/src/engine/net/ItemProductionManager.java b/src/engine/net/ItemProductionManager.java index adf379d2..0d2cb0c8 100644 --- a/src/engine/net/ItemProductionManager.java +++ b/src/engine/net/ItemProductionManager.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -33,104 +30,47 @@ import java.util.concurrent.atomic.LongAdder; * Thread blocks until MagicBane dispatch messages are * enqueued then processes them in FIFO order. The collection * is thread safe. - * + *

* Any large messages not time sensitive such as load object * sent to more than a single individual should be spawned * individually on a DispatchMessageThread. */ - public enum ItemProductionManager implements Runnable { - ITEMPRODUCTIONMANAGER; - - - // Instance variables - - private ItemQueue itemQueue; + ITEMPRODUCTIONMANAGER; - private long nextFailedItemAudit; - - // Class variables + + // Instance variables @SuppressWarnings("unchecked") // Cannot have arrays of generics in java. private static final DelayQueue producedQueue = new DelayQueue<>(); + public static volatile long[] messageCount = new long[DispatchChannel.values().length]; + + // Class variables + public static LongAdder[] dispatchCount = new LongAdder[DispatchChannel.values().length]; + - // Performance metrics - - public static volatile long[] messageCount = new long[DispatchChannel.values().length]; - public static LongAdder[] dispatchCount = new LongAdder[DispatchChannel.values().length]; - public static volatile long[] maxRecipients = new long[DispatchChannel.values().length]; - public static LongAdder dispatchPoolSize = new LongAdder(); - + public static volatile long[] maxRecipients = new long[DispatchChannel.values().length]; + public static LongAdder dispatchPoolSize = new LongAdder(); public static HashSet FailedItems = new HashSet<>(); - public Thread itemProductionThread = null; - - // Thread constructor - - - public void startMessagePump() { + private ItemQueue itemQueue; + private long nextFailedItemAudit; - itemProductionThread = new Thread(this); - itemProductionThread.setName("ItemProductionManager"); - - } - - public void initialize(){ - itemProductionThread.start(); - } - + // Thread constructor public static void send(ItemQueue item) { - + // Don't queue up empty dispatches! - + if (item == null) - return; - + return; + producedQueue.add(item); - - } - - @Override - public void run() { - - - while (true) { - try { - - this.itemQueue = producedQueue.take(); - - if (this.itemQueue == null){ - return; - } - - if (this.itemQueue != null) { - if (this.itemQueue.item == null){ - this.itemQueue.release(); - return; - } - - - boolean created = this.itemQueue.item.finishProduction(); - - if (!created) - FailedItems.add(this.itemQueue.item); - - this.itemQueue.release(); - - - } - - - } catch (Exception e) { - Logger.error(e); - } - } } public static String getNetstatString() { @@ -139,17 +79,66 @@ public enum ItemProductionManager implements Runnable { String newLine = System.getProperty("line.separator"); outString = "[LUA_NETSTA()]" + newLine; outString += "poolSize: " + dispatchPoolSize.longValue() + '\n'; - + for (DispatchChannel dispatchChannel : DispatchChannel.values()) { - + outString += "Channel: " + dispatchChannel.name() + '\n'; - outString += "Dispatches: " + dispatchCount[dispatchChannel.getChannelID()].longValue()+ '\n'; + outString += "Dispatches: " + dispatchCount[dispatchChannel.getChannelID()].longValue() + '\n'; outString += "Messages: " + messageCount[dispatchChannel.getChannelID()] + '\n'; outString += "maxRecipients: " + maxRecipients[dispatchChannel.getChannelID()] + '\n'; } return outString; } - - // For Debugging: - //Logger.error("MessageDispatcher", messageDispatch.msg.getOpcodeAsString() + " sent to " + messageDispatch.playerList.size() + " players"); + + public void startMessagePump() { + + itemProductionThread = new Thread(this); + itemProductionThread.setName("ItemProductionManager"); + } + + public void initialize() { + itemProductionThread.start(); + } + + @Override + public void run() { + + + while (true) { + try { + + this.itemQueue = producedQueue.take(); + + if (this.itemQueue == null) { + return; + } + + if (this.itemQueue != null) { + if (this.itemQueue.item == null) { + this.itemQueue.release(); + return; + } + + + boolean created = this.itemQueue.item.finishProduction(); + + if (!created) + FailedItems.add(this.itemQueue.item); + + this.itemQueue.release(); + + + } + + + } catch (Exception e) { + Logger.error(e); + } + + } + } + + // For Debugging: + //Logger.error("MessageDispatcher", messageDispatch.msg.getOpcodeAsString() + " sent to " + messageDispatch.playerList.size() + " players"); +} diff --git a/src/engine/net/ItemQueue.java b/src/engine/net/ItemQueue.java index ee0b160f..c95dea2e 100644 --- a/src/engine/net/ItemQueue.java +++ b/src/engine/net/ItemQueue.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -19,7 +16,6 @@ // www.magicbane.com - package engine.net; import engine.objects.ProducedItem; @@ -37,63 +33,63 @@ import static engine.net.MessageDispatcher.itemPoolSize; public class ItemQueue implements Delayed { private static final ConcurrentLinkedQueue itemPool = new ConcurrentLinkedQueue<>(); - + public ProducedItem item; public long delayTime; - - - public ItemQueue(ProducedItem item, long delayTime) { - this.item = item; - this.delayTime = System.currentTimeMillis() + delayTime; - -} - - public void reset() { - this.item = null; - this.delayTime = 0; - } - - public static ItemQueue borrow(ProducedItem item, long delayTime) { - ItemQueue itemQueue; - - itemQueue = itemPool.poll(); - if (itemQueue == null) { + public ItemQueue(ProducedItem item, long delayTime) { + this.item = item; + this.delayTime = System.currentTimeMillis() + delayTime; + + } + + public static ItemQueue borrow(ProducedItem item, long delayTime) { + + ItemQueue itemQueue; + + itemQueue = itemPool.poll(); + + if (itemQueue == null) { itemQueue = new ItemQueue(item, delayTime); - } else { - itemQueue.item = item; - itemQueue.delayTime = System.currentTimeMillis() + delayTime; - itemPoolSize.decrement(); - } - - return itemQueue; + } else { + itemQueue.item = item; + itemQueue.delayTime = System.currentTimeMillis() + delayTime; + itemPoolSize.decrement(); + } + + return itemQueue; + } + + public void reset() { + this.item = null; + this.delayTime = 0; + } + + public void release() { + this.reset(); + itemPool.add(this); + itemPoolSize.increment(); + } + + @Override + public int compareTo(Delayed another) { + ItemQueue anotherTask = (ItemQueue) another; + + if (this.delayTime < anotherTask.delayTime) { + return -1; } - - public void release() { - this.reset(); - itemPool.add(this); - itemPoolSize.increment(); + + if (this.delayTime > anotherTask.delayTime) { + return 1; } - @Override - public int compareTo(Delayed another) { - ItemQueue anotherTask = (ItemQueue) another; - - if (this.delayTime < anotherTask.delayTime) { - return -1; - } - - if (this.delayTime > anotherTask.delayTime) { - return 1; - } - - return 0; - } - - @Override - public long getDelay(TimeUnit unit) { - long difference = delayTime - System.currentTimeMillis(); - return unit.convert(difference, TimeUnit.MILLISECONDS); - } + return 0; + } + + @Override + public long getDelay(TimeUnit unit) { + long difference = delayTime - System.currentTimeMillis(); + return unit.convert(difference, TimeUnit.MILLISECONDS); + } } diff --git a/src/engine/net/MessageDispatcher.java b/src/engine/net/MessageDispatcher.java index 123a3730..c804a4ea 100644 --- a/src/engine/net/MessageDispatcher.java +++ b/src/engine/net/MessageDispatcher.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -33,7 +30,7 @@ import java.util.regex.Pattern; * Thread blocks until MagicBane dispatch messages are * enqueued then processes them in FIFO order. The collection * is thread safe. - * + *

* Any large messages not time sensitive such as load object * sent to more than a single individual should be spawned * individually on a DispatchMessageThread. @@ -42,77 +39,91 @@ import java.util.regex.Pattern; public class MessageDispatcher implements Runnable { // Instance variables - - private Dispatch messageDispatch; - private final Pattern filterPattern; // Unused, but just in case - - // Class variables @SuppressWarnings("unchecked") // Cannot have arrays of generics in java. private static final ConcurrentLinkedQueue[] _messageQueue = new ConcurrentLinkedQueue[DispatchChannel.values().length]; - private static final LinkedBlockingQueue _blockingQueue = new LinkedBlockingQueue<>(); - + + // Class variables + public static volatile long[] messageCount = new long[DispatchChannel.values().length]; + public static LongAdder[] dispatchCount = new LongAdder[DispatchChannel.values().length]; + // Performance metrics - - public static volatile long[] messageCount = new long[DispatchChannel.values().length]; - public static LongAdder[] dispatchCount = new LongAdder[DispatchChannel.values().length]; - public static volatile long[] maxRecipients = new long[DispatchChannel.values().length]; - public static LongAdder itemPoolSize = new LongAdder(); - + public static volatile long[] maxRecipients = new long[DispatchChannel.values().length]; + public static LongAdder itemPoolSize = new LongAdder(); + private final Pattern filterPattern; // Unused, but just in case + private Dispatch messageDispatch; + // Thread constructor - + public MessageDispatcher() { // Create new FIFO queues for this network thread - + for (DispatchChannel dispatchChannel : DispatchChannel.values()) { _messageQueue[dispatchChannel.getChannelID()] = new ConcurrentLinkedQueue<>(); dispatchCount[dispatchChannel.getChannelID()] = new LongAdder(); } - + filterPattern = Pattern.compile("[^\\p{ASCII}]"); - Logger.info( " Dispatcher thread has started!"); - + Logger.info(" Dispatcher thread has started!"); + } public static void send(Dispatch messageDispatch, DispatchChannel dispatchChannel) { - + // Don't queue up empty dispatches! - + if (messageDispatch.player == null) return; - + _messageQueue[dispatchChannel.getChannelID()].add(messageDispatch); _blockingQueue.add(true); - + // Update performance metrics - + messageCount[dispatchChannel.getChannelID()]++; - + } - + + public static String getNetstatString() { + + String outString = null; + String newLine = System.getProperty("line.separator"); + outString = "[LUA_NETSTA()]" + newLine; + outString += "poolSize: " + itemPoolSize.longValue() + '\n'; + + for (DispatchChannel dispatchChannel : DispatchChannel.values()) { + + outString += "Channel: " + dispatchChannel.name() + '\n'; + outString += "Dispatches: " + dispatchCount[dispatchChannel.getChannelID()].longValue() + '\n'; + outString += "Messages: " + messageCount[dispatchChannel.getChannelID()] + '\n'; + outString += "maxRecipients: " + maxRecipients[dispatchChannel.getChannelID()] + '\n'; + } + return outString; + } + @Override public void run() { - + boolean shouldBlock; - + while (true) { try { - + shouldBlock = true; - + for (DispatchChannel dispatchChannel : DispatchChannel.values()) { - + this.messageDispatch = _messageQueue[dispatchChannel.getChannelID()].poll(); - + if (this.messageDispatch != null) { - DispatchMessage.serializeDispatch(this.messageDispatch); - shouldBlock = false; - } - + DispatchMessage.serializeDispatch(this.messageDispatch); + shouldBlock = false; + } + } - + if (shouldBlock == true) shouldBlock = _blockingQueue.take(); @@ -123,23 +134,6 @@ public class MessageDispatcher implements Runnable { } } - public static String getNetstatString() { - - String outString = null; - String newLine = System.getProperty("line.separator"); - outString = "[LUA_NETSTA()]" + newLine; - outString += "poolSize: " + itemPoolSize.longValue() + '\n'; - - for (DispatchChannel dispatchChannel : DispatchChannel.values()) { - - outString += "Channel: " + dispatchChannel.name() + '\n'; - outString += "Dispatches: " + dispatchCount[dispatchChannel.getChannelID()].longValue()+ '\n'; - outString += "Messages: " + messageCount[dispatchChannel.getChannelID()] + '\n'; - outString += "maxRecipients: " + maxRecipients[dispatchChannel.getChannelID()] + '\n'; - } - return outString; - } - - // For Debugging: - //Logger.error("MessageDispatcher", messageDispatch.msg.getOpcodeAsString() + " sent to " + messageDispatch.playerList.size() + " players"); - } + // For Debugging: + //Logger.error("MessageDispatcher", messageDispatch.msg.getOpcodeAsString() + " sent to " + messageDispatch.playerList.size() + " players"); +} diff --git a/src/engine/net/NetMsgFactory.java b/src/engine/net/NetMsgFactory.java index 7d205f3a..c1cbba91 100644 --- a/src/engine/net/NetMsgFactory.java +++ b/src/engine/net/NetMsgFactory.java @@ -27,399 +27,391 @@ import java.util.HashMap; public class NetMsgFactory { - // NetMsg Opcode to Constructor List - private static final HashMap netMsgDefinitions = new HashMap<>(); - - // Standardize the error strings - private static String ALL_GOOD_JUST_NOT_ENOUGH_BYTES = "Not enough Bytes"; - private static String DESERIALIZATION_FAILURE = "Deserialization Failure"; - private static String UNIMPLEMENTED_OPCODE = "Unimplemented Opcode"; - private static String UNKNOWN_OPCODE = "Unknown Opcode"; - - protected ByteBuffer internalBuffer; - private final ArrayList msgOutbox; - - private boolean enableFloodControl; - private boolean bypassFloodControl; // temp bypass - private boolean floodControlTripped; - - private static final int FLOOD_CONTROL_TRIP_SETPOINT = 1000; - private int badOpcodeCount; - private final AbstractConnection owner; - private int lastMsgPosition = 0; - - public NetMsgFactory(AbstractConnection origin, boolean enableFloodControl) { - this.internalBuffer = Network.byteBufferPool.getBuffer(18); //256k buffer - - this.bypassFloodControl = false; - this.msgOutbox = new ArrayList<>(); - this.enableFloodControl = enableFloodControl; - this.floodControlTripped = false; - this.owner = origin; - } - - public NetMsgFactory(AbstractConnection origin) { - this(origin, true); - } - - public final void addData(byte[] ba) { - // Dont use prefab BB's here, since sizeof(ba) is unknown. - ByteBuffer bb = ByteBuffer.wrap(ba); - bb.position(bb.capacity()); - this.addData(bb); - } - - public final void addData(ByteBuffer newData) { - synchronized (this.internalBuffer) { - - int newCapacity = this.internalBuffer.position() + newData.position(); - - if (newCapacity >= this.internalBuffer.capacity()) { - //Resize!!!! - Logger.warn( - "Bytebuffer is being be Resized."); - - //Get a newer, bigger BB - ByteBuffer newBB = Network.byteBufferPool.getBufferToFit((int) (newCapacity * 1.5)); - - //Copy old data in - this.internalBuffer.flip(); - newBB.put(this.internalBuffer); - - //Get a handle on old BB - ByteBuffer oldBB = this.internalBuffer; - - //install new BB - this.internalBuffer = newBB; - - //Return old BB - Network.byteBufferPool.putBuffer(oldBB); - } - - synchronized (newData) { - // Copy over the data. - newData.flip(); - - try { - this.internalBuffer.put(newData); - } catch (Exception e) { - Logger.error( e.toString()); - // TODO figure out how to handle this error. - } - } - } - } - - public void parseBuffer() { - // Check flood control first - if (this.floodControlTripped) - // this.conn.disconnect(); - return; - - // MBServer.jobMan.submitJob(new ParseBufferJob(this)); - this._parseBuffer(); - } - - /** - * This function makes a copy of the current internal byte buffer and loads - * the copy into a ByteBufferReader. It is copied so that the Factory can - * continue to accumulate data on the internal buffer from the - * socketChannels. The ByteBufferReader is then used in an attempt to build - * an AbstractNetMsg subclass based on protocolMsg. If a message is successfully - * built, the bytes used are removed from the Factory's internal byte - * buffer. - * - * @return - * @throws Exception - */ - protected void _parseBuffer() { - synchronized (this.internalBuffer) { - while (this.internalBuffer.position() > 0) { - // Check flood control first - if (this.floodControlTripped) - break; - - ByteBufferReader reader = null; - - // Check to see if the minimum amount of data is here: - if (this.internalBuffer.position() < 4) - // nothing wrong, just not enough info yet. - break; - - // copy internal buffer into a reader - reader = new ByteBufferReader(this.internalBuffer, false); - - // Reset the limit to the capacity - this.internalBuffer.limit(this.internalBuffer.capacity()); - - try { - AbstractNetMsg msg = this.tryBuild(owner, reader); - - // error, null messages are being returned on unhandled - // opcodes - // for some reason - if (msg == null) - throw new FactoryBuildException(UNIMPLEMENTED_OPCODE); - - - - if (owner.getClass().equals(ClientConnection.class)){ - ClientConnection client = (ClientConnection)owner; - client.setLastOpcode(msg.getProtocolMsg().opcode); - } - - - - - // Logger.debug("Adding a " + msg.getSimpleClassName() - // + " to the outbox."); - this.addMsgToOutBox(msg); - - this.dropLeadingBytesFromBuffer(reader.position()); - this.bypassFloodControl = false; - - } catch (FactoryBuildException e) { - String error = e.getMessage(); - int readerPos = reader.position(); - - if (error.equals(ALL_GOOD_JUST_NOT_ENOUGH_BYTES)){ - break; - } - // no worries, just break. - - else if (error.equals(DESERIALIZATION_FAILURE)) { - // Lop readerPos bytes off the buffer. - this.dropLeadingBytesFromBuffer(readerPos); - - // Lets bypass flood control for now. - this.bypassFloodControl = true; - continue; - - } else if (error.equals(UNIMPLEMENTED_OPCODE)) { - - if (owner.lastProtocol != null && owner.lastProtocol.constructor == null){ - this.dropLeadingBytesFromBuffer(readerPos); - this.bypassFloodControl = true; - continue; - } - - // Lop readerPos bytes off the buffer. - if (reader.position() >= 4) - reader.position(reader.position() - 4); - int newPosition = Protocol.FindNextValidOpcode(reader); - this.dropLeadingBytesFromBuffer(newPosition); - // Lets bypass flood control for now. - this.bypassFloodControl = true; - - continue; - - } else if (error.equals(UNKNOWN_OPCODE)) { - - if (owner.lastProtocol != null && owner.lastProtocol.constructor == null){ - this.dropLeadingBytesFromBuffer(readerPos); - this.bypassFloodControl = true; - continue; - } - // We don't know what this is or how long, so dump the - // first - // byte and try again - if (reader.position() >= 4) - reader.position(reader.position() - 4); - int newPosition = Protocol.FindNextValidOpcode(reader); - this.dropLeadingBytesFromBuffer(newPosition); - // Lets bypass flood control for now. - this.bypassFloodControl = true; - - continue; - } - } catch (Exception e) { - // TODO FIX THIS!!!! + // NetMsg Opcode to Constructor List + private static final HashMap netMsgDefinitions = new HashMap<>(); + private static final int FLOOD_CONTROL_TRIP_SETPOINT = 1000; + // Standardize the error strings + private static String ALL_GOOD_JUST_NOT_ENOUGH_BYTES = "Not enough Bytes"; + private static String DESERIALIZATION_FAILURE = "Deserialization Failure"; + private static String UNIMPLEMENTED_OPCODE = "Unimplemented Opcode"; + private static String UNKNOWN_OPCODE = "Unknown Opcode"; + private final ArrayList msgOutbox; + private final AbstractConnection owner; + protected ByteBuffer internalBuffer; + private boolean enableFloodControl; + private boolean bypassFloodControl; // temp bypass + private boolean floodControlTripped; + private int badOpcodeCount; + private int lastMsgPosition = 0; + + public NetMsgFactory(AbstractConnection origin, boolean enableFloodControl) { + this.internalBuffer = Network.byteBufferPool.getBuffer(18); //256k buffer + + this.bypassFloodControl = false; + this.msgOutbox = new ArrayList<>(); + this.enableFloodControl = enableFloodControl; + this.floodControlTripped = false; + this.owner = origin; + } + + public NetMsgFactory(AbstractConnection origin) { + this(origin, true); + } + + public static String getByteArray(ByteBufferReader reader) { + String ret = ""; + if (reader == null) + return ret; + + ByteBuffer bb = reader.getBb(); + if (bb == null) + return ret; + + int length = bb.limit(); // - bb.position(); + ByteBuffer temp = bb.duplicate(); + temp.position(bb.limit()); + temp.flip(); + for (int i = 0; i < length; i++) { + ret += Integer.toString((temp.get() & 0xff) + 0x100, 16).substring(1).toUpperCase(); + } + return ret; + } + + @SuppressWarnings("unchecked") + private static AbstractNetMsg getNewInstanceOf(int opcode, + AbstractConnection origin, ByteBufferReader reader) { + try { + + Protocol protocolMsg = Protocol.getByOpcode(opcode); + + if (protocolMsg == Protocol.NONE) { + + String errorString = DateTime.now().toString() + origin.lastProtocol.name(); + + int errorCode = errorString.hashCode(); + + + if (origin instanceof ClientConnection) { + PlayerCharacter player = ((ClientConnection) origin).getPlayerCharacter(); + if (player != null) { +// if (MBServerStatics.worldServerName.equals("Grief")) + Logger.error("Invalid protocol msg for player " + player.getFirstName() + " : " + opcode + " lastopcode: " + origin.lastProtocol.name() + " Error Code : " + errorCode); + } else + Logger.error("Invalid protocol msg : " + opcode + " lastopcode: " + origin.lastProtocol.name() + " Error Code : " + errorCode); + + } + + return null; + } + origin.lastProtocol = protocolMsg; + + if (protocolMsg.constructor == null) { + return null; + } + + + Constructor constructor = protocolMsg.constructor; + + if (constructor == null) + return null; + + Object[] myArgs = new Object[2]; + myArgs[0] = origin; + myArgs[1] = reader; + + Object object = constructor.newInstance(myArgs); + + if (object instanceof engine.net.AbstractNetMsg) + return (AbstractNetMsg) object; + + } catch (IllegalAccessException | IllegalArgumentException | InstantiationException | + ExceptionInInitializerError e) { + Logger.error(e); + + } catch (InvocationTargetException e) { + if (e.getCause() != null + && e.getCause().getClass() == BufferUnderflowException.class) + throw new BufferUnderflowException(); + Logger.error(e); + } + return null; + } + + public final void addData(byte[] ba) { + // Dont use prefab BB's here, since sizeof(ba) is unknown. + ByteBuffer bb = ByteBuffer.wrap(ba); + bb.position(bb.capacity()); + this.addData(bb); + } + + public final void addData(ByteBuffer newData) { + synchronized (this.internalBuffer) { + + int newCapacity = this.internalBuffer.position() + newData.position(); + + if (newCapacity >= this.internalBuffer.capacity()) { + //Resize!!!! + Logger.warn( + "Bytebuffer is being be Resized."); + + //Get a newer, bigger BB + ByteBuffer newBB = Network.byteBufferPool.getBufferToFit((int) (newCapacity * 1.5)); + + //Copy old data in + this.internalBuffer.flip(); + newBB.put(this.internalBuffer); + + //Get a handle on old BB + ByteBuffer oldBB = this.internalBuffer; + + //install new BB + this.internalBuffer = newBB; + + //Return old BB + Network.byteBufferPool.putBuffer(oldBB); + } + + synchronized (newData) { + // Copy over the data. + newData.flip(); + + try { + this.internalBuffer.put(newData); + } catch (Exception e) { + Logger.error(e.toString()); + // TODO figure out how to handle this error. + } + } + } + } + + public void parseBuffer() { + // Check flood control first + if (this.floodControlTripped) + // this.conn.disconnect(); + return; + + // MBServer.jobMan.submitJob(new ParseBufferJob(this)); + this._parseBuffer(); + } + + /** + * This function makes a copy of the current internal byte buffer and loads + * the copy into a ByteBufferReader. It is copied so that the Factory can + * continue to accumulate data on the internal buffer from the + * socketChannels. The ByteBufferReader is then used in an attempt to build + * an AbstractNetMsg subclass based on protocolMsg. If a message is successfully + * built, the bytes used are removed from the Factory's internal byte + * buffer. + * + * @return + * @throws Exception + */ + protected void _parseBuffer() { + synchronized (this.internalBuffer) { + while (this.internalBuffer.position() > 0) { + // Check flood control first + if (this.floodControlTripped) + break; + + ByteBufferReader reader = null; + + // Check to see if the minimum amount of data is here: + if (this.internalBuffer.position() < 4) + // nothing wrong, just not enough info yet. + break; + + // copy internal buffer into a reader + reader = new ByteBufferReader(this.internalBuffer, false); + + // Reset the limit to the capacity + this.internalBuffer.limit(this.internalBuffer.capacity()); + + try { + AbstractNetMsg msg = this.tryBuild(owner, reader); + + // error, null messages are being returned on unhandled + // opcodes + // for some reason + if (msg == null) + throw new FactoryBuildException(UNIMPLEMENTED_OPCODE); + + + if (owner.getClass().equals(ClientConnection.class)) { + ClientConnection client = (ClientConnection) owner; + client.setLastOpcode(msg.getProtocolMsg().opcode); + } + + + // Logger.debug("Adding a " + msg.getSimpleClassName() + // + " to the outbox."); + this.addMsgToOutBox(msg); + + this.dropLeadingBytesFromBuffer(reader.position()); + this.bypassFloodControl = false; + + } catch (FactoryBuildException e) { + String error = e.getMessage(); + int readerPos = reader.position(); + + if (error.equals(ALL_GOOD_JUST_NOT_ENOUGH_BYTES)) { + break; + } + // no worries, just break. + + else if (error.equals(DESERIALIZATION_FAILURE)) { + // Lop readerPos bytes off the buffer. + this.dropLeadingBytesFromBuffer(readerPos); + + // Lets bypass flood control for now. + this.bypassFloodControl = true; + continue; + + } else if (error.equals(UNIMPLEMENTED_OPCODE)) { + + if (owner.lastProtocol != null && owner.lastProtocol.constructor == null) { + this.dropLeadingBytesFromBuffer(readerPos); + this.bypassFloodControl = true; + continue; + } + + // Lop readerPos bytes off the buffer. + if (reader.position() >= 4) + reader.position(reader.position() - 4); + int newPosition = Protocol.FindNextValidOpcode(reader); + this.dropLeadingBytesFromBuffer(newPosition); + // Lets bypass flood control for now. + this.bypassFloodControl = true; + + continue; + + } else if (error.equals(UNKNOWN_OPCODE)) { + + if (owner.lastProtocol != null && owner.lastProtocol.constructor == null) { + this.dropLeadingBytesFromBuffer(readerPos); + this.bypassFloodControl = true; + continue; + } + // We don't know what this is or how long, so dump the + // first + // byte and try again + if (reader.position() >= 4) + reader.position(reader.position() - 4); + int newPosition = Protocol.FindNextValidOpcode(reader); + this.dropLeadingBytesFromBuffer(newPosition); + // Lets bypass flood control for now. + this.bypassFloodControl = true; + + continue; + } + } catch (Exception e) { + // TODO FIX THIS!!!! // Logger.error( e); - }// end catch - - } // end while loop - } - }// end fn - - public AbstractNetMsg tryBuild(AbstractConnection origin, - ByteBufferReader reader) throws FactoryBuildException { - try { - - // Get the protocolMsg - int opcode = reader.getInt(); - // String ocHex = StringUtils.toHexString(protocolMsg); - - if (MBServerStatics.PRINT_INCOMING_OPCODES) - try { - Logger.info( "Incoming protocolMsg: " - + Protocol.getByOpcode(opcode).name() + " " + Integer.toHexString(opcode) + ", size: " + reader.getBb().limit() + "; " + getByteArray(reader)); - } catch (Exception e) { - Logger.error( e); - } - - return NetMsgFactory.getNewInstanceOf(opcode, origin, reader); - - } catch (BufferUnderflowException e) { - // This is okay. it indicates that we recognized the protocolMsg, but - // there isn't enough information in - // the reader to complete the NetMsg deserialization - throw new FactoryBuildException(ALL_GOOD_JUST_NOT_ENOUGH_BYTES); - - } - } - - public static String getByteArray(ByteBufferReader reader) { - String ret = ""; - if (reader == null) - return ret; - - ByteBuffer bb = reader.getBb(); - if (bb == null) - return ret; - - int length = bb.limit(); // - bb.position(); - ByteBuffer temp = bb.duplicate(); - temp.position(bb.limit()); - temp.flip(); - for (int i = 0; i < length; i++) { - ret += Integer.toString((temp.get() & 0xff) + 0x100, 16).substring(1).toUpperCase(); - } - return ret; - } - - private void incrBadOpcodeCount() { - // keeping this a nested if for Troubleshooting/clarity - if (this.enableFloodControl == true) - if (this.bypassFloodControl == false) { - ++this.badOpcodeCount; - - - - if (this.badOpcodeCount >= FLOOD_CONTROL_TRIP_SETPOINT){ - if (this.owner != null){ - if (this.owner instanceof ClientConnection){ - ClientConnection client = (ClientConnection) this.owner; - if (client.getPlayerCharacter() != null){ - ChatManager.chatSystemError(client.getPlayerCharacter(),"TRIPPED Flood Control! PLEASE RELOG!"); - Logger.info( client.getPlayerCharacter().getName() + " Tripped Flood Control!" + this.badOpcodeCount); - } - - } - } - this.floodControlTripped = true; - }else{ - if (this.owner != null){ - if (this.owner instanceof ClientConnection){ - ClientConnection client = (ClientConnection) this.owner; - if (client.getPlayerCharacter() != null){ - ChatManager.chatSystemError(client.getPlayerCharacter(),"Client sending bad messages. bad message Count " + this.badOpcodeCount); - Logger.info( client.getPlayerCharacter().getName() + " has been caught sending bad opcodes. Bad Opcode Count " + this.badOpcodeCount); - } - - } - - - } - } - - } - } - - protected final void dropLeadingBytesFromBuffer(int numberOfBytes) { - this.internalBuffer.limit(this.internalBuffer.position()); - this.internalBuffer.position(numberOfBytes); - this.internalBuffer.compact(); // Compact - } - - protected boolean addMsgToOutBox(AbstractNetMsg msg) { - synchronized (this.msgOutbox) { - return msgOutbox.add(msg); - } - } - - public AbstractNetMsg getMsg() { - synchronized (this.msgOutbox) { - if (this.msgOutbox.isEmpty()) - return null; - return msgOutbox.remove(0); - } - } - - public boolean hasMsg() { - synchronized (this.msgOutbox) { - return !msgOutbox.isEmpty(); - } - } - - public boolean hasData() { - synchronized (this.internalBuffer) { - return (this.internalBuffer.position() != 0); - } - } - - @SuppressWarnings("unchecked") - private static AbstractNetMsg getNewInstanceOf(int opcode, - AbstractConnection origin, ByteBufferReader reader) { - try { - - Protocol protocolMsg = Protocol.getByOpcode(opcode); - - if (protocolMsg == Protocol.NONE){ - - String errorString = DateTime.now().toString() + origin.lastProtocol.name(); - - int errorCode = errorString.hashCode(); - - - if (origin instanceof ClientConnection){ - PlayerCharacter player = ((ClientConnection)origin).getPlayerCharacter(); - if (player != null){ -// if (MBServerStatics.worldServerName.equals("Grief")) - Logger.error("Invalid protocol msg for player " + player.getFirstName() + " : " + opcode + " lastopcode: " + origin.lastProtocol.name() + " Error Code : " + errorCode); - }else - Logger.error("Invalid protocol msg : " + opcode + " lastopcode: " + origin.lastProtocol.name() + " Error Code : " + errorCode); - - } - - return null; - } - origin.lastProtocol = protocolMsg; - - if (protocolMsg.constructor == null){ - return null; - } - - - - Constructor constructor = protocolMsg.constructor; - - if (constructor == null) - return null; - - Object[] myArgs = new Object[2]; - myArgs[0] = origin; - myArgs[1] = reader; - - Object object = constructor.newInstance(myArgs); - - if (object instanceof engine.net.AbstractNetMsg) - return (AbstractNetMsg) object; - - } catch (IllegalAccessException | IllegalArgumentException | InstantiationException | ExceptionInInitializerError e) { - Logger.error( e); - - } catch (InvocationTargetException e) { - if (e.getCause() != null - && e.getCause().getClass() == BufferUnderflowException.class) - throw new BufferUnderflowException(); - Logger.error(e); - } - return null; - } - - public ByteBuffer getInternalBuffer() { - return internalBuffer; - } + }// end catch + + } // end while loop + } + }// end fn + + public AbstractNetMsg tryBuild(AbstractConnection origin, + ByteBufferReader reader) throws FactoryBuildException { + try { + + // Get the protocolMsg + int opcode = reader.getInt(); + // String ocHex = StringUtils.toHexString(protocolMsg); + + if (MBServerStatics.PRINT_INCOMING_OPCODES) + try { + Logger.info("Incoming protocolMsg: " + + Protocol.getByOpcode(opcode).name() + " " + Integer.toHexString(opcode) + ", size: " + reader.getBb().limit() + "; " + getByteArray(reader)); + } catch (Exception e) { + Logger.error(e); + } + + return NetMsgFactory.getNewInstanceOf(opcode, origin, reader); + + } catch (BufferUnderflowException e) { + // This is okay. it indicates that we recognized the protocolMsg, but + // there isn't enough information in + // the reader to complete the NetMsg deserialization + throw new FactoryBuildException(ALL_GOOD_JUST_NOT_ENOUGH_BYTES); + + } + } + + private void incrBadOpcodeCount() { + // keeping this a nested if for Troubleshooting/clarity + if (this.enableFloodControl == true) + if (this.bypassFloodControl == false) { + ++this.badOpcodeCount; + + + if (this.badOpcodeCount >= FLOOD_CONTROL_TRIP_SETPOINT) { + if (this.owner != null) { + if (this.owner instanceof ClientConnection) { + ClientConnection client = (ClientConnection) this.owner; + if (client.getPlayerCharacter() != null) { + ChatManager.chatSystemError(client.getPlayerCharacter(), "TRIPPED Flood Control! PLEASE RELOG!"); + Logger.info(client.getPlayerCharacter().getName() + " Tripped Flood Control!" + this.badOpcodeCount); + } + + } + } + this.floodControlTripped = true; + } else { + if (this.owner != null) { + if (this.owner instanceof ClientConnection) { + ClientConnection client = (ClientConnection) this.owner; + if (client.getPlayerCharacter() != null) { + ChatManager.chatSystemError(client.getPlayerCharacter(), "Client sending bad messages. bad message Count " + this.badOpcodeCount); + Logger.info(client.getPlayerCharacter().getName() + " has been caught sending bad opcodes. Bad Opcode Count " + this.badOpcodeCount); + } + + } + + + } + } + + } + } + + protected final void dropLeadingBytesFromBuffer(int numberOfBytes) { + this.internalBuffer.limit(this.internalBuffer.position()); + this.internalBuffer.position(numberOfBytes); + this.internalBuffer.compact(); // Compact + } + + protected boolean addMsgToOutBox(AbstractNetMsg msg) { + synchronized (this.msgOutbox) { + return msgOutbox.add(msg); + } + } + + public AbstractNetMsg getMsg() { + synchronized (this.msgOutbox) { + if (this.msgOutbox.isEmpty()) + return null; + return msgOutbox.remove(0); + } + } + + public boolean hasMsg() { + synchronized (this.msgOutbox) { + return !msgOutbox.isEmpty(); + } + } + + public boolean hasData() { + synchronized (this.internalBuffer) { + return (this.internalBuffer.position() != 0); + } + } + + public ByteBuffer getInternalBuffer() { + return internalBuffer; + } } diff --git a/src/engine/net/NetMsgStat.java b/src/engine/net/NetMsgStat.java index f54e3b29..eef4b0b2 100644 --- a/src/engine/net/NetMsgStat.java +++ b/src/engine/net/NetMsgStat.java @@ -26,10 +26,10 @@ public class NetMsgStat { private final AtomicInteger countOverMax = new AtomicInteger(); public NetMsgStat(Protocol protocolMsg, int startSize) { - + if (startSize < 10) startSize = 10; - + if (startSize > 30) startSize = 30; @@ -57,7 +57,7 @@ public class NetMsgStat { if (this.max.get() < i) this.max.set(i); - + if (i <= avg) this.countUnderAverage.incrementAndGet(); else if (i < this.max.get()) diff --git a/src/engine/net/Network.java b/src/engine/net/Network.java index 7bef5e73..28502505 100644 --- a/src/engine/net/Network.java +++ b/src/engine/net/Network.java @@ -21,7 +21,7 @@ public class Network { public static final MultisizeByteBufferPool byteBufferPool = new MultisizeByteBufferPool(); public static void init() { - //Force a few to be created. + //Force a few to be created. //Small (2^10-15) for (int a = 10; a < 16; ++a) { diff --git a/src/engine/net/client/ClientAuthenticator.java b/src/engine/net/client/ClientAuthenticator.java index dd36f503..937ac747 100644 --- a/src/engine/net/client/ClientAuthenticator.java +++ b/src/engine/net/client/ClientAuthenticator.java @@ -30,12 +30,23 @@ import java.security.*; public class ClientAuthenticator { + private static final byte P_Bytes[] = {(byte) 0xFB, (byte) 0x46, (byte) 0x56, (byte) 0xB4, (byte) 0xBE, (byte) 0x81, (byte) 0xA4, + (byte) 0x2C, (byte) 0x37, (byte) 0xC4, (byte) 0xA2, (byte) 0x61, (byte) 0x4A, (byte) 0xAC, (byte) 0x65, (byte) 0x90, + (byte) 0x31, (byte) 0xB6, (byte) 0x83, (byte) 0x26, (byte) 0x63, (byte) 0x94, (byte) 0x08, (byte) 0x95, (byte) 0x56, + (byte) 0x8D, (byte) 0x5E, (byte) 0xBF, (byte) 0x94, (byte) 0x10, (byte) 0x5A, (byte) 0x37, (byte) 0xB6, (byte) 0x82, + (byte) 0x1A, (byte) 0x75, (byte) 0x2B, (byte) 0xF1, (byte) 0x94, (byte) 0xB7, (byte) 0x7E, (byte) 0x56, (byte) 0xC6, + (byte) 0xD1, (byte) 0xF5, (byte) 0x18, (byte) 0xE1, (byte) 0xA5, (byte) 0x13, (byte) 0x9E, (byte) 0xC1, (byte) 0x85, + (byte) 0x98, (byte) 0xB7, (byte) 0x32, (byte) 0xDB, (byte) 0x38, (byte) 0x09, (byte) 0x1A, (byte) 0xF8, (byte) 0x5C, + (byte) 0xDA, (byte) 0x4F, (byte) 0x9F, (byte) 0x67, (byte) 0x93, (byte) 0x72, (byte) 0x8F, (byte) 0x75, (byte) 0x4F, + (byte) 0x0B, (byte) 0xBD, (byte) 0x69, (byte) 0x61, (byte) 0x97, (byte) 0x1F, (byte) 0xEE, (byte) 0xFB, (byte) 0x5B, + (byte) 0xB0, (byte) 0x85, (byte) 0xC4, (byte) 0x27, (byte) 0x7E, (byte) 0x41, (byte) 0x42, (byte) 0xC2, (byte) 0xF1, + (byte) 0xDA, (byte) 0x64, (byte) 0x8F, (byte) 0x4E, (byte) 0x28, (byte) 0xFD, (byte) 0x2A, (byte) 0x63}; + private static final BigInteger P = new BigInteger(1, P_Bytes); + private static final BigInteger G = BigInteger.valueOf(5); private final AbstractConnection origin; - private ByteBuffer buffer = ByteBuffer.allocate(100); private byte[] secretKeyBytes = new byte[16]; private SecretKeySpec BFKey; - private Cipher cipher; private byte[] iVecEnc = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; private byte[] iVecDec = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; @@ -75,7 +86,7 @@ public class ClientAuthenticator { private void calcKeys(AbstractConnection origin, byte[] clientPublicKeyBytes) { try { - // get the forwarded client public key, in byte[] form. + // get the forwarded client public key, in byte[] form. // Convert client public key to a BigInteger BigInteger clientPublicKeyBI = new BigInteger(1, clientPublicKeyBytes); @@ -128,14 +139,14 @@ public class ClientAuthenticator { try { read = origin.getSocketChannel().read(this.buffer); } catch (IOException e) { - if (e.getLocalizedMessage() != null && !e.getLocalizedMessage().equals(MBServerStatics.EXISTING_CONNECTION_CLOSED) && !e.getLocalizedMessage().equals(MBServerStatics.RESET_BY_PEER)) - Logger.error(e); - origin.disconnect(); - return 0; + if (e.getLocalizedMessage() != null && !e.getLocalizedMessage().equals(MBServerStatics.EXISTING_CONNECTION_CLOSED) && !e.getLocalizedMessage().equals(MBServerStatics.RESET_BY_PEER)) + Logger.error(e); + origin.disconnect(); + return 0; } if (read == -1) { - Logger.info("EOF on Socket Channel, Disconnecting " + origin.getLocalAddressAndPortAsString()); + Logger.info("EOF on Socket Channel, Disconnecting " + origin.getLocalAddressAndPortAsString()); origin.disconnect(); return read; } @@ -143,7 +154,7 @@ public class ClientAuthenticator { this.totalRead += read; if (this.totalRead > 100) - Logger.error( "Possible Spam warning: " + Logger.error("Possible Spam warning: " + origin.getSocketChannel().socket().toString()); // Not all arrived yet, so wait for more @@ -168,7 +179,7 @@ public class ClientAuthenticator { // Calculate Blowfish Secret Key and make ciphers streams. this.BFKey = new SecretKeySpec(this.secretKeyBytes, "Blowfish"); - // Initialize cipher and Ivecs. + // Initialize cipher and Ivecs. // Ivecs must be run through the cipher once // to prep the cipher for cfb mode. this.cipher = Cipher.getInstance("Blowfish/ECB/NoPadding"); @@ -217,7 +228,7 @@ public class ClientAuthenticator { //Line up the iVecEncOffset.. fall through is intentional if (iVecEncOffset != 0) if ((this.iVecEncOffset + dataIn.limit()) < 8) { - //This handles cases where the net msg + offset won't reach 8 bytes total + //This handles cases where the net msg + offset won't reach 8 bytes total //prevents BufferUnderflowException in small net messages. - int newEncOffset = this.iVecEncOffset + dataIn.limit(); for (int i = this.iVecEncOffset; i < newEncOffset; i++) { @@ -337,8 +348,8 @@ public class ClientAuthenticator { this.iVecDecOffset = 0; } } - - + + } } catch (Exception e) { Logger.error("ClientAuth.decrypt()" + e); @@ -363,19 +374,4 @@ public class ClientAuthenticator { return initialized; } - private static final byte P_Bytes[] = {(byte) 0xFB, (byte) 0x46, (byte) 0x56, (byte) 0xB4, (byte) 0xBE, (byte) 0x81, (byte) 0xA4, - (byte) 0x2C, (byte) 0x37, (byte) 0xC4, (byte) 0xA2, (byte) 0x61, (byte) 0x4A, (byte) 0xAC, (byte) 0x65, (byte) 0x90, - (byte) 0x31, (byte) 0xB6, (byte) 0x83, (byte) 0x26, (byte) 0x63, (byte) 0x94, (byte) 0x08, (byte) 0x95, (byte) 0x56, - (byte) 0x8D, (byte) 0x5E, (byte) 0xBF, (byte) 0x94, (byte) 0x10, (byte) 0x5A, (byte) 0x37, (byte) 0xB6, (byte) 0x82, - (byte) 0x1A, (byte) 0x75, (byte) 0x2B, (byte) 0xF1, (byte) 0x94, (byte) 0xB7, (byte) 0x7E, (byte) 0x56, (byte) 0xC6, - (byte) 0xD1, (byte) 0xF5, (byte) 0x18, (byte) 0xE1, (byte) 0xA5, (byte) 0x13, (byte) 0x9E, (byte) 0xC1, (byte) 0x85, - (byte) 0x98, (byte) 0xB7, (byte) 0x32, (byte) 0xDB, (byte) 0x38, (byte) 0x09, (byte) 0x1A, (byte) 0xF8, (byte) 0x5C, - (byte) 0xDA, (byte) 0x4F, (byte) 0x9F, (byte) 0x67, (byte) 0x93, (byte) 0x72, (byte) 0x8F, (byte) 0x75, (byte) 0x4F, - (byte) 0x0B, (byte) 0xBD, (byte) 0x69, (byte) 0x61, (byte) 0x97, (byte) 0x1F, (byte) 0xEE, (byte) 0xFB, (byte) 0x5B, - (byte) 0xB0, (byte) 0x85, (byte) 0xC4, (byte) 0x27, (byte) 0x7E, (byte) 0x41, (byte) 0x42, (byte) 0xC2, (byte) 0xF1, - (byte) 0xDA, (byte) 0x64, (byte) 0x8F, (byte) 0x4E, (byte) 0x28, (byte) 0xFD, (byte) 0x2A, (byte) 0x63}; - - private static final BigInteger P = new BigInteger(1, P_Bytes); - private static final BigInteger G = BigInteger.valueOf(5); - } diff --git a/src/engine/net/client/ClientConnection.java b/src/engine/net/client/ClientConnection.java index 0ca889be..ad113a6a 100644 --- a/src/engine/net/client/ClientConnection.java +++ b/src/engine/net/client/ClientConnection.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.net.client; import engine.Enum; @@ -35,320 +34,317 @@ import java.util.concurrent.locks.ReentrantLock; public class ClientConnection extends AbstractConnection { - // Enumeration of a message's origin for logging purposes - private enum MessageSource { - - SOURCE_CLIENT, - SOURCE_SERVER - } - - private byte cryptoInitTries = 0; - protected SessionID sessionID = null; - private final ClientAuthenticator crypto; - private final String clientIpAddress; - public String machineID; - public long guildtreespam = 0; - public long ordernpcspam = 0; - public ReentrantLock trainLock = new ReentrantLock(); - public ReentrantLock sellLock = new ReentrantLock(); - public ReentrantLock buyLock = new ReentrantLock(); - - public boolean desyncDebug = false; - - public byte[] lastByteBuffer; - - public ClientConnection(ClientConnectionManager connMan, - SocketChannel sockChan) { - super(connMan, sockChan, true); - this.crypto = new ClientAuthenticator(this); - - this.clientIpAddress = sockChan.socket().getRemoteSocketAddress() - .toString().replace("/", "").split(":")[0]; - } - - @Override - protected boolean _sendMsg(AbstractNetMsg msg) { - try { - msg.setOrigin(this); - ByteBuffer bb = msg.serialize(); - - // Application protocol logging toggled via - // DevCmd: netdebug on|off - - if (MBServerStatics.DEBUG_PROTOCOL) - applicationProtocolLogger(msg, MessageSource.SOURCE_SERVER); - - boolean retval = this.sendBB(bb); - Network.byteBufferPool.putBuffer(bb);//return here. - - return retval; - - } catch (Exception e) { // Catch-all - Logger.error(e); - return false; - } - } - - /** - * Sending a NetMsg to the client involves NOT including a dataLen parameter - * and also involves encrypting the data. - * - */ - @Override - protected boolean _sendBB(ByteBuffer bb) { - boolean useCrypto = this.crypto.initialized(); - boolean retVal; - - // Logger.debug("useCrypto: " + useCrypto + ". bb.cap(): " + - // bb.capacity()); - if (useCrypto == false) - retVal = super._sendBB(bb); - else { - if (bb == null) - Logger.error("Incoming bb is null"); - ByteBuffer encrypted = Network.byteBufferPool.getBufferToFit(bb.capacity()); - if (encrypted == null) - Logger.error("Encrypted bb is null"); - this.crypto.encrypt(bb, encrypted); - retVal = super._sendBB(encrypted); - } - - return retVal; - } - - /** - * Receiving data from a client involves the initial Crypto Key Exchange, - * waiting for a complete NetMsg to arrive using an accumulation factory and - * decrypting the data. - */ - //FIXME the int return value on this means nothing! Clean it up! - @Override - protected int read() { - - if (readLock.tryLock()) - try { - - // First and foremost, check to see if we the Crypto is initted yet - if (!this.crypto.initialized()) - this.crypto.initialize(this); - - if (!this.crypto.initialized()) { - ++this.cryptoInitTries; - if (this.cryptoInitTries >= MBServerStatics.MAX_CRYPTO_INIT_TRIES) { - Logger.info("Failed to initialize after " - + MBServerStatics.MAX_CRYPTO_INIT_TRIES - + " tries. Disconnecting."); - this.disconnect(); - } - return 0; - } - - // check to see if SessionID == null; - if (this.sessionID == null) - this.sessionID = new SessionID(this.crypto.getSecretKeyBytes()); - - // Get ByteBuffers out of pool. - ByteBuffer bb = Network.byteBufferPool.getBuffer(16); - ByteBuffer decrypted = Network.byteBufferPool.getBuffer(16); - // ByteBuffer bb = ByteBuffer.allocate(1024 * 4); - - int totalBytesRead = 0; - int lastRead = 0; - do { - try { - bb.clear(); - decrypted.clear(); - lastRead = this.sockChan.read(bb); - // On EOF on the SocketChannel, disconnect. - if (lastRead <= -1) { - this.disconnect(); - break; - } - - if (lastRead == 0) - continue; - - // ByteBuffer decrypted = ByteBuffer.allocate(lastRead); - this.crypto.decrypt(bb, decrypted); - this.factory.addData(decrypted); - - - this.checkInternalFactory(); - - totalBytesRead += lastRead; - - - } catch (NotYetConnectedException e) { - Logger.error(e.getLocalizedMessage()); - totalBytesRead = -1; // Set error retVal - break; - - } catch (ClosedChannelException e) { - // TODO Should a closed channel be logged or just cleaned up? - // this.logEXCEPTION(e); - this.disconnect(); - totalBytesRead = -1; // Set error retVal - break; - - } catch (IOException e) { - if ( e.getLocalizedMessage() != null && (!e.getLocalizedMessage().equals(MBServerStatics.EXISTING_CONNECTION_CLOSED) && !e.getLocalizedMessage().equals(MBServerStatics.RESET_BY_PEER))){ - Logger.info("Error Reading message opcode " + this.lastOpcode); - Logger.error(e); - } - this.disconnect(); - totalBytesRead = -1; // Set error retVal - break; - - } catch (Exception e){ - Logger.info("Error Reading message opcode " + this.lastOpcode); - Logger.error(e); - totalBytesRead = -1; // Set error retVal - this.disconnect(); - break; - } - } - - while (lastRead > 0); - - Network.byteBufferPool.putBuffer(bb); - Network.byteBufferPool.putBuffer(decrypted); - - return totalBytesRead; - - } finally { - readLock.unlock(); - } - else { - Logger.debug("Another thread already has a read lock! Skipping."); - return 0; - } - } - - @Override - public void disconnect() { - super.disconnect(); - try { - - if (ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER)) - ConfigManager.worldServer.removeClient(this); - else - ConfigManager.loginServer.removeClient(this); - - // TODO There has to be a more direct way to do this... - SessionManager.remSession( - SessionManager.getSession(sessionID)); - } catch (NullPointerException e) { - Logger - .error( - "Tried to remove improperly initialized session. Skipping." + - e); - } - } - - public void forceDisconnect() { - super.disconnect(); - } - - /* - * Getters n setters - */ - - public SessionID getSessionID() { - return sessionID; - } - - public byte[] getSecretKeyBytes() { - return this.crypto.getSecretKeyBytes(); - } - - /* - * Convenience getters for SessionManager - */ - public Account getAccount() { - return SessionManager.getAccount(this); - } - - public PlayerCharacter getPlayerCharacter() { - return SessionManager.getPlayerCharacter(this); - } - - @Override - public boolean handleClientMsg(ClientNetMsg msg) { - - Protocol protocolMsg = msg.getProtocolMsg(); - - switch (protocolMsg) { - case KEEPALIVESERVERCLIENT: - this.setLastKeepAliveTime(); - break; - // case ClientOpcodes.OpenVault: - // case ClientOpcodes.Random: - // case ClientOpcodes.DoorTryOpen: - // case ClientOpcodes.SetSelectedObect: - // case ClientOpcodes.MoveObjectToContainer: - // case ClientOpcodes.ToggleSitStand: - // case ClientOpcodes.SocialChannel: - // case ClientOpcodes.OpenFriendsCondemnList: - case SELLOBJECT: - this.setLastMsgTime(); - break; - case MOVETOPOINT: - case ARCCOMBATMODEATTACKING: - this.setLastMsgTime(); - break; - default: - this.setLastMsgTime(); - break; - } - - // Application protocol logging toggled via - // DevCmd: netdebug on|off - - if (MBServerStatics.DEBUG_PROTOCOL) - applicationProtocolLogger(msg, MessageSource.SOURCE_CLIENT); - - return ConfigManager.handler.handleClientMsg(msg); // *** Refactor : Null check then call - } - // Method logs detailed information about application - // protocol traffic. Toggled at runtime via the - // DevCmd netdebug on|off - - private void applicationProtocolLogger(AbstractNetMsg msg, MessageSource origin) { - - String outString = ""; - PlayerCharacter tempPlayer = null; - - // Log the protocolMsg - if (origin == MessageSource.SOURCE_CLIENT) - outString = " Incoming protocolMsg: "; - else - outString = " Outgoing protocolMsg: "; - - Logger.info(outString - + Integer.toHexString(msg.getProtocolMsg().opcode) - + '/' + msg.getProtocolMsg()); - - // Dump message contents using reflection - tempPlayer = this.getPlayerCharacter(); - outString = ""; - outString += (tempPlayer == null) ? "PlayerUnknown" : tempPlayer.getFirstName() + ' ' - + msg.toString(); - Logger.info(outString); - } - - public void kickToLogin(int errCode, String message) { - - LoginErrorMsg lom = new LoginErrorMsg(errCode, message); - - if (!sendMsg(lom)) - Logger.error("Failed to send message"); // TODO Do we just accept this failure to send Msg? - - DisconnectJob dj = new DisconnectJob(this); - JobScheduler.getInstance().scheduleJob(dj, 250); - - } - - public final String getClientIpAddress() { - return this.clientIpAddress; - } + private final ClientAuthenticator crypto; + private final String clientIpAddress; + public String machineID; + public long guildtreespam = 0; + public long ordernpcspam = 0; + public ReentrantLock trainLock = new ReentrantLock(); + public ReentrantLock sellLock = new ReentrantLock(); + public ReentrantLock buyLock = new ReentrantLock(); + public boolean desyncDebug = false; + public byte[] lastByteBuffer; + protected SessionID sessionID = null; + private byte cryptoInitTries = 0; + + public ClientConnection(ClientConnectionManager connMan, + SocketChannel sockChan) { + super(connMan, sockChan, true); + this.crypto = new ClientAuthenticator(this); + + this.clientIpAddress = sockChan.socket().getRemoteSocketAddress() + .toString().replace("/", "").split(":")[0]; + } + + @Override + protected boolean _sendMsg(AbstractNetMsg msg) { + try { + msg.setOrigin(this); + ByteBuffer bb = msg.serialize(); + + // Application protocol logging toggled via + // DevCmd: netdebug on|off + + if (MBServerStatics.DEBUG_PROTOCOL) + applicationProtocolLogger(msg, MessageSource.SOURCE_SERVER); + + boolean retval = this.sendBB(bb); + Network.byteBufferPool.putBuffer(bb);//return here. + + return retval; + + } catch (Exception e) { // Catch-all + Logger.error(e); + return false; + } + } + + /** + * Sending a NetMsg to the client involves NOT including a dataLen parameter + * and also involves encrypting the data. + */ + @Override + protected boolean _sendBB(ByteBuffer bb) { + boolean useCrypto = this.crypto.initialized(); + boolean retVal; + + // Logger.debug("useCrypto: " + useCrypto + ". bb.cap(): " + + // bb.capacity()); + if (useCrypto == false) + retVal = super._sendBB(bb); + else { + if (bb == null) + Logger.error("Incoming bb is null"); + ByteBuffer encrypted = Network.byteBufferPool.getBufferToFit(bb.capacity()); + if (encrypted == null) + Logger.error("Encrypted bb is null"); + this.crypto.encrypt(bb, encrypted); + retVal = super._sendBB(encrypted); + } + + return retVal; + } + + /** + * Receiving data from a client involves the initial Crypto Key Exchange, + * waiting for a complete NetMsg to arrive using an accumulation factory and + * decrypting the data. + */ + //FIXME the int return value on this means nothing! Clean it up! + @Override + protected int read() { + + if (readLock.tryLock()) + try { + + // First and foremost, check to see if we the Crypto is initted yet + if (!this.crypto.initialized()) + this.crypto.initialize(this); + + if (!this.crypto.initialized()) { + ++this.cryptoInitTries; + if (this.cryptoInitTries >= MBServerStatics.MAX_CRYPTO_INIT_TRIES) { + Logger.info("Failed to initialize after " + + MBServerStatics.MAX_CRYPTO_INIT_TRIES + + " tries. Disconnecting."); + this.disconnect(); + } + return 0; + } + + // check to see if SessionID == null; + if (this.sessionID == null) + this.sessionID = new SessionID(this.crypto.getSecretKeyBytes()); + + // Get ByteBuffers out of pool. + ByteBuffer bb = Network.byteBufferPool.getBuffer(16); + ByteBuffer decrypted = Network.byteBufferPool.getBuffer(16); + // ByteBuffer bb = ByteBuffer.allocate(1024 * 4); + + int totalBytesRead = 0; + int lastRead = 0; + do { + try { + bb.clear(); + decrypted.clear(); + lastRead = this.sockChan.read(bb); + // On EOF on the SocketChannel, disconnect. + if (lastRead <= -1) { + this.disconnect(); + break; + } + + if (lastRead == 0) + continue; + + // ByteBuffer decrypted = ByteBuffer.allocate(lastRead); + this.crypto.decrypt(bb, decrypted); + this.factory.addData(decrypted); + + + this.checkInternalFactory(); + + totalBytesRead += lastRead; + + + } catch (NotYetConnectedException e) { + Logger.error(e.getLocalizedMessage()); + totalBytesRead = -1; // Set error retVal + break; + + } catch (ClosedChannelException e) { + // TODO Should a closed channel be logged or just cleaned up? + // this.logEXCEPTION(e); + this.disconnect(); + totalBytesRead = -1; // Set error retVal + break; + + } catch (IOException e) { + if (e.getLocalizedMessage() != null && (!e.getLocalizedMessage().equals(MBServerStatics.EXISTING_CONNECTION_CLOSED) && !e.getLocalizedMessage().equals(MBServerStatics.RESET_BY_PEER))) { + Logger.info("Error Reading message opcode " + this.lastOpcode); + Logger.error(e); + } + this.disconnect(); + totalBytesRead = -1; // Set error retVal + break; + + } catch (Exception e) { + Logger.info("Error Reading message opcode " + this.lastOpcode); + Logger.error(e); + totalBytesRead = -1; // Set error retVal + this.disconnect(); + break; + } + } + + while (lastRead > 0); + + Network.byteBufferPool.putBuffer(bb); + Network.byteBufferPool.putBuffer(decrypted); + + return totalBytesRead; + + } finally { + readLock.unlock(); + } + else { + Logger.debug("Another thread already has a read lock! Skipping."); + return 0; + } + } + + @Override + public void disconnect() { + super.disconnect(); + try { + + if (ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER)) + ConfigManager.worldServer.removeClient(this); + else + ConfigManager.loginServer.removeClient(this); + + // TODO There has to be a more direct way to do this... + SessionManager.remSession( + SessionManager.getSession(sessionID)); + } catch (NullPointerException e) { + Logger + .error( + "Tried to remove improperly initialized session. Skipping." + + e); + } + } + + public void forceDisconnect() { + super.disconnect(); + } + + public SessionID getSessionID() { + return sessionID; + } + + /* + * Getters n setters + */ + + public byte[] getSecretKeyBytes() { + return this.crypto.getSecretKeyBytes(); + } + + /* + * Convenience getters for SessionManager + */ + public Account getAccount() { + return SessionManager.getAccount(this); + } + + public PlayerCharacter getPlayerCharacter() { + return SessionManager.getPlayerCharacter(this); + } + + @Override + public boolean handleClientMsg(ClientNetMsg msg) { + + Protocol protocolMsg = msg.getProtocolMsg(); + + switch (protocolMsg) { + case KEEPALIVESERVERCLIENT: + this.setLastKeepAliveTime(); + break; + // case ClientOpcodes.OpenVault: + // case ClientOpcodes.Random: + // case ClientOpcodes.DoorTryOpen: + // case ClientOpcodes.SetSelectedObect: + // case ClientOpcodes.MoveObjectToContainer: + // case ClientOpcodes.ToggleSitStand: + // case ClientOpcodes.SocialChannel: + // case ClientOpcodes.OpenFriendsCondemnList: + case SELLOBJECT: + this.setLastMsgTime(); + break; + case MOVETOPOINT: + case ARCCOMBATMODEATTACKING: + this.setLastMsgTime(); + break; + default: + this.setLastMsgTime(); + break; + } + + // Application protocol logging toggled via + // DevCmd: netdebug on|off + + if (MBServerStatics.DEBUG_PROTOCOL) + applicationProtocolLogger(msg, MessageSource.SOURCE_CLIENT); + + return ConfigManager.handler.handleClientMsg(msg); // *** Refactor : Null check then call + } + + private void applicationProtocolLogger(AbstractNetMsg msg, MessageSource origin) { + + String outString = ""; + PlayerCharacter tempPlayer = null; + + // Log the protocolMsg + if (origin == MessageSource.SOURCE_CLIENT) + outString = " Incoming protocolMsg: "; + else + outString = " Outgoing protocolMsg: "; + + Logger.info(outString + + Integer.toHexString(msg.getProtocolMsg().opcode) + + '/' + msg.getProtocolMsg()); + + // Dump message contents using reflection + tempPlayer = this.getPlayerCharacter(); + outString = ""; + outString += (tempPlayer == null) ? "PlayerUnknown" : tempPlayer.getFirstName() + ' ' + + msg.toString(); + Logger.info(outString); + } + // Method logs detailed information about application + // protocol traffic. Toggled at runtime via the + // DevCmd netdebug on|off + + public void kickToLogin(int errCode, String message) { + + LoginErrorMsg lom = new LoginErrorMsg(errCode, message); + + if (!sendMsg(lom)) + Logger.error("Failed to send message"); // TODO Do we just accept this failure to send Msg? + + DisconnectJob dj = new DisconnectJob(this); + JobScheduler.getInstance().scheduleJob(dj, 250); + + } + + public final String getClientIpAddress() { + return this.clientIpAddress; + } + + // Enumeration of a message's origin for logging purposes + private enum MessageSource { + + SOURCE_CLIENT, + SOURCE_SERVER + } } diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 0f749d0e..f274f185 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.net.client; import engine.Enum.*; @@ -48,2082 +47,2054 @@ import static engine.math.FastMath.sqr; public class ClientMessagePump implements NetMsgHandler { - // Instance variable declaration - - private final WorldServer server; - - public ClientMessagePump(WorldServer server) { - super(); - this.server = server; - } - - /* - * Incoming client protocol message are processed here - */ - - @Override - public boolean handleClientMsg(ClientNetMsg msg) { - - if (msg == null) { - Logger.error("handleClientMsg", "Recieved null msg. Returning."); - return false; - } - - ClientConnection origin; - Protocol protocolMsg = Protocol.NONE; - Session s; - - try { - - // Try registered opcodes first as we take a hatchet to this GodObject - - AbstractClientMsgHandler msgHandler = msg.getProtocolMsg().handler; - - if (msgHandler != null) - return msgHandler.handleNetMsg(msg); - - // Any remaining opcodes fall through and are routed - // through this ungodly switch of doom. - - origin = (ClientConnection) msg.getOrigin(); - s = SessionManager.getSession(origin); - - protocolMsg = msg.getProtocolMsg(); - - switch (protocolMsg) { - case SETSELECTEDOBECT: - ClientMessagePump.targetObject((TargetObjectMsg) msg, origin); - break; - - /* - * Chat - */ - - // Simplify by fall through. Route in ChatManager - case CHATSAY: - case CHATSHOUT: - case CHATTELL: - case CHATGUILD: - case CHATGROUP: - case CHATPVP: - case CHATIC: - case CHATCITY: - case CHATINFO: - case SYSTEMBROADCASTCHANNEL: - case CHATCSR: - case SYSTEMCHANNEL: - case GLOBALCHANNELMESSAGE: - case LEADERCHANNELMESSAGE: - ChatManager.handleChatMsg(s, (AbstractChatMsg) msg); - break; - case UPDATESTATE: - UpdateStateMsg rwss = (UpdateStateMsg) msg; - runWalkSitStand(rwss, origin); - break; - case ACTIVATECHARTER: - UseCharterMsg ucm = (UseCharterMsg) msg; - ucm.setUnknown02(1); - ucm.configure(); - Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), ucm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - break; - case CHECKUNIQUEGUILD: - break; - case CREATEPETITION: - break; - case CANCELGUILDCREATION: - break; - case LEAVEREQUEST: - origin.disconnect(); - break; - case POWER: - PowersManager.usePower((PerformActionMsg) msg, origin, false); - break; - case REQUESTMELEEATTACK: - CombatManager.setAttackTarget((AttackCmdMsg) msg, origin); - break; - case READYTOENTER: - break; - case OPENVAULT: - break; - case WHOREQUEST: - WhoRequest((WhoRequestMsg) msg, origin); - break; - case CLIENTADMINCOMMAND: - ChatManager.HandleClientAdminCmd((ClientAdminCommandMsg) msg, origin); - break; - case SOCIALCHANNEL: - social((SocialMsg) msg, origin); - break; - case COMBATMODE: - CombatManager.toggleCombat((ToggleCombatMsg) msg, origin); - break; - case ARCCOMBATMODEATTACKING: - CombatManager.toggleCombat((SetCombatModeMsg) msg, origin); - break; - case MODIFYGUILDSTATE: - ToggleLfgRecruitingMsg tlrm = (ToggleLfgRecruitingMsg) msg; - toggleLfgRecruiting(tlrm, origin); - break; - case TOGGLESITSTAND: - ToggleSitStandMsg tssm = (ToggleSitStandMsg) msg; - toggleSitStand(tssm, origin); - break; - case GUILDTREESTATUS: - GuildTreeStatusMsg((GuildTreeStatusMsg) msg, origin); - break; - case CUSTOMERPETITION: - Logger.info("CCR Petition received: " + msg.toString()); - // TODO need to send something back to client - // TODO what to do with petition? - break; - case IGNORE: - ((IgnoreMsg) msg).handleRequest(origin); - break; - case UNEQUIP: - TransferItemFromEquipToInventory((TransferItemFromEquipToInventoryMsg) msg, origin); - break; - case EQUIP: - TransferItemFromInventoryToEquip((TransferItemFromInventoryToEquipMsg) msg, origin); - break; - case DELETEOBJECT: - DeleteItem((DeleteItemMsg) msg, origin); - break; - case VIEWRESOURCES: - ViewResourcesMessage((ViewResourcesMessage) msg, origin); - break; - case RAISEATTR: - modifyStat((ModifyStatMsg) msg, origin); - break; - case COSTTOOPENBANK: - ackBankWindowOpened((AckBankWindowOpenedMsg) msg, origin); - break; - case RESETAFTERDEATH: - respawn((RespawnMsg) msg, origin); - break; - case REQUESTCONTENTS: - lootWindowRequest((LootWindowRequestMsg) msg, origin); - break; - case MOVEOBJECTTOCONTAINER: - loot((LootMsg) msg, origin); - break; - case SHOWCOMBATINFO: - show((ShowMsg) msg, origin); - break; - case TRANSFERITEMTOBANK: - transferItemFromInventoryToBank((TransferItemFromInventoryToBankMsg) msg, origin); - break; - case TRANSFERITEMFROMBANK: - transferItemFromBankToInventory((TransferItemFromBankToInventoryMsg) msg, origin); - break; - case TRANSFERITEMFROMVAULTTOINVENTORY: - transferItemFromVaultToInventory((TransferItemFromVaultToInventoryMsg) msg, origin); - break; - case ITEMTOVAULT: - transferItemFromInventoryToVault((TransferItemFromInventoryToVaultMsg) msg, origin); - break; - case TRANSFERGOLDFROMVAULTTOINVENTORY: - transferGoldFromVaultToInventory((TransferGoldFromVaultToInventoryMsg) msg, origin); - break; - case GOLDTOVAULT: - transferGoldFromInventoryToVault((TransferGoldFromInventoryToVaultMsg) msg, origin); - break; - case REQUESTTOTRADE: - TradeManager.tradeRequest((TradeRequestMsg) msg, origin); - break; - case REQUESTTRADEOK: - TradeManager.acceptTradeRequest((AcceptTradeRequestMsg) msg, origin); - break; - case REQUESTTRADECANCEL: - TradeManager.rejectTradeRequest((RejectTradeRequestMsg) msg, origin); - break; - case TRADEADDOBJECT: - TradeManager.addItemToTradeWindow((AddItemToTradeWindowMsg) msg, origin); - break; - case TRADEADDGOLD: - TradeManager.addGoldToTradeWindow((AddGoldToTradeWindowMsg) msg, origin); - break; - case TRADECONFIRM: - TradeManager.commitToTrade((CommitToTradeMsg) msg, origin); - break; - case TRADEUNCONFIRM: - TradeManager.uncommitToTrade((UncommitToTradeMsg) msg, origin); - break; - case TRADECLOSE: - TradeManager.closeTradeWindow((CloseTradeWindowMsg) msg, origin); - break; - case ARCREQUESTTRADEBUSY: - TradeManager.invalidTradeRequest((InvalidTradeRequestMsg) msg); - break; - case VENDORDIALOG: - VendorDialogMsg.replyDialog((VendorDialogMsg) msg, origin); - break; - case SHOPLIST: - openBuyFromNPCWindow((BuyFromNPCWindowMsg) msg, origin); - break; - case BUYFROMNPC: - buyFromNPC((BuyFromNPCMsg) msg, origin); - break; - case SHOPINFO: - openSellToNPCWindow((SellToNPCWindowMsg) msg, origin); - break; - case SELLOBJECT: - sellToNPC((SellToNPCMsg) msg, origin); - break; - case REPAIROBJECT: - Repair((RepairMsg) msg, origin); - break; - case TRAINERLIST: - WorldServer.trainerInfo((TrainerInfoMsg) msg, origin); - break; - case ARCUNTRAINLIST: - WorldServer.refinerScreen((RefinerScreenMsg) msg, origin); - break; - case TRAINSKILL: - TrainMsg.train((TrainMsg) msg, origin); - break; - case ARCUNTRAINABILITY: - RefineMsg.refine((RefineMsg) msg, origin); - break; - case POWERTARGNAME: - PowersManager.summon((SendSummonsRequestMsg) msg, origin); - break; - case ARCSUMMON: - PowersManager.recvSummon((RecvSummonsRequestMsg) msg, origin); - break; - case ARCTRACKINGLIST: - PowersManager.trackWindow((TrackWindowMsg) msg, origin); - break; - case STUCK: - stuck(origin); - break; - case RANDOM: - ClientMessagePump.randomRoll((RandomMsg) msg, origin); - break; - case ARCPETATTACK: - petAttack((PetAttackMsg) msg, origin); - break; - case ARCPETCMD: - petCmd((PetCmdMsg) msg, origin); - break; - case MANAGENPC: - ManageNPCCmd((ManageNPCMsg) msg, origin); - break; - case ARCPROMPTRECALL: - HandlePromptRecall((PromptRecallMsg) msg, origin); - break; - case CHANNELMUTE: - break; - case KEEPALIVESERVERCLIENT: - break; - case UNKNOWN: - break; - - case CONFIRMPROMOTE: - break; - - default: - String ocHex = StringUtils.toHexString(protocolMsg.opcode); - Logger.error("Cannot handle Opcode: " + ocHex + " " + protocolMsg.name()); - return false; - - } - - } catch (MsgSendException | SQLException e) { - Logger.error("handler for " + protocolMsg + " failed: " + e); - return false; - } - - return true; - } - - // *** Refactor need to figure this out. - // Commented out for some reson or another. - - //TODO what is this used for? - private void ManageNPCCmd(ManageNPCMsg msg, ClientConnection origin) { - - } - - private static void WhoRequest(WhoRequestMsg msg, ClientConnection origin) { - - // Handle /who request - PlayerCharacter pc = origin.getPlayerCharacter(); - - if (pc == null) - return; - - if (pc.getTimeStamp("WHO") > System.currentTimeMillis()) { - ErrorPopupMsg.sendErrorMsg(pc, "Who too fast! Please wait 3 seconds."); - return; - } - - WhoResponseMsg.HandleResponse(msg.getSet(), msg.getFilterType(), msg.getFilter(), origin); - pc.getTimestamps().put("WHO", System.currentTimeMillis() + 3000); - } - - private static void runWalkSitStand(UpdateStateMsg msg, ClientConnection origin) throws MsgSendException { - PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); - if (pc == null) - return; - - pc.update(); - if (msg.getSpeed() == 2) - pc.setWalkMode(false); - else - pc.setWalkMode(true); - DispatchMessage.dispatchMsgToInterestArea(pc, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - } - - private static void toggleLfgRecruiting(ToggleLfgRecruitingMsg msg, ClientConnection origin) throws MsgSendException { - PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); - if (pc == null) - return; - int num = msg.toggleLfgRecruiting(); - if (num == 1) - pc.toggleLFGroup(); - else if (num == 2) - pc.toggleLFGuild(); - else if (num == 3) - pc.toggleRecruiting(); - UpdateStateMsg rwss = new UpdateStateMsg(); - rwss.setPlayer(pc); - DispatchMessage.dispatchMsgToInterestArea(pc, rwss, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - } - - private static void toggleSitStand(ToggleSitStandMsg msg, ClientConnection origin) throws MsgSendException { - PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); - if (pc == null) - return; - - pc.update(); - - pc.setSit(msg.toggleSitStand()); - - // cancel effects that break on sit - if (pc.isSit()) { - pc.setCombat(false); - pc.cancelOnSit(); - } - - UpdateStateMsg rwss = new UpdateStateMsg(); - if (pc.isSit()) { - pc.setCombat(false); - rwss.setAware(1); - } - rwss.setPlayer(pc); - - DispatchMessage.dispatchMsgToInterestArea(pc, rwss, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - } - - private static void targetObject(TargetObjectMsg msg, ClientConnection origin) { - PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); - if (pc == null) - return; - - // TODO improve this later. hacky way to make sure player ingame is - // active. - - if (!pc.isActive()) - pc.setActive(true); - - pc.setLastTarget(GameObjectType.values()[msg.getTargetType()], msg.getTargetID()); - } - - private static void social(SocialMsg msg, ClientConnection origin) throws MsgSendException { - PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); - if (pc == null) - return; - DispatchMessage.dispatchMsgToInterestArea(pc, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, true); - } - - private static void TransferItemFromEquipToInventory(TransferItemFromEquipToInventoryMsg msg, ClientConnection origin) { - PlayerCharacter pc = origin.getPlayerCharacter(); - if (pc == null) - return; - - CharacterItemManager itemManager = pc.getCharItemManager(); - if (itemManager == null) - return; - - int slot = msg.getSlotNumber(); - - Item i = itemManager.getItemFromEquipped(slot); - if (i == null) - return; - - if (!itemManager.doesCharOwnThisItem(i.getObjectUUID())) - return; - - //dupe check - if (!i.validForEquip(origin, pc, itemManager)) - return; - - if (i.containerType == ItemContainerType.EQUIPPED) - itemManager.moveItemToInventory(i); - - int ItemType = i.getObjectType().ordinal(); - int ItemID = i.getObjectUUID(); - for (String name : i.getEffects().keySet()) { - Effect eff = i.getEffects().get(name); - if (eff == null) - return; - ApplyEffectMsg pum = new ApplyEffectMsg(); - pum.setEffectID(eff.getEffectToken()); - pum.setSourceType(pc.getObjectType().ordinal()); - pum.setSourceID(pc.getObjectUUID()); - pum.setTargetType(pc.getObjectType().ordinal()); - pum.setTargetID(pc.getObjectUUID()); - pum.setNumTrains(eff.getTrains()); - pum.setUnknown05(1); - pum.setUnknown02(2); - pum.setUnknown06((byte) 1); - pum.setEffectSourceType(ItemType); - pum.setEffectSourceID(ItemID); - pum.setDuration(-1); - - - DispatchMessage.dispatchMsgToInterestArea(pc, pum, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);; - - } - // Update player formulas - pc.applyBonuses(); - DispatchMessage.dispatchMsgToInterestArea(pc, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); - - } - - //call this if the transfer fails server side to kick the item back to inventory from equip - private void forceTransferFromInventoryToEquip(TransferItemFromEquipToInventoryMsg msg, ClientConnection origin, String reason) { - //TODO add this later - //PATCHED CODEZZ - } - - private static void TransferItemFromInventoryToEquip(TransferItemFromInventoryToEquipMsg msg, ClientConnection origin) { - PlayerCharacter pc = origin.getPlayerCharacter(); - if (pc == null) - return; - - CharacterItemManager itemManager = pc.getCharItemManager(); - if (itemManager == null) { - forceTransferFromEquipToInventory(msg, origin, "Can't find your item manager"); - return; - } - - int uuid = msg.getUUID(); - int slot = msg.getSlotNumber(); - //System.out.println("loading to slot: " + slot); - - Item i = itemManager.getItemByUUID(uuid); - - if (i == null) { - forceTransferFromEquipToInventory(msg, origin, "Item not found in your item manager"); - return; - } - - if (!itemManager.doesCharOwnThisItem(i.getObjectUUID())) { - forceTransferFromEquipToInventory(msg, origin, "You do not own this item"); - return; - } - - //dupe check - if (!i.validForInventory(origin, pc, itemManager)) - return; - - if (i.containerType == ItemContainerType.INVENTORY) { - if (!itemManager.equipItem(i, (byte) slot)) { - forceTransferFromEquipToInventory(msg, origin, "Failed to transfer item."); - return; - } - } - else { - forceTransferFromEquipToInventory(msg, origin, "This item is not in your inventory"); - return; - } - - // Update player formulas - pc.applyBonuses(); - DispatchMessage.dispatchMsgToInterestArea(pc, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); + // Instance variable declaration + + private final WorldServer server; + + public ClientMessagePump(WorldServer server) { + super(); + this.server = server; + } + + /* + * Incoming client protocol message are processed here + */ + + private static void WhoRequest(WhoRequestMsg msg, ClientConnection origin) { + + // Handle /who request + PlayerCharacter pc = origin.getPlayerCharacter(); + + if (pc == null) + return; + + if (pc.getTimeStamp("WHO") > System.currentTimeMillis()) { + ErrorPopupMsg.sendErrorMsg(pc, "Who too fast! Please wait 3 seconds."); + return; + } + + WhoResponseMsg.HandleResponse(msg.getSet(), msg.getFilterType(), msg.getFilter(), origin); + pc.getTimestamps().put("WHO", System.currentTimeMillis() + 3000); + } + + // *** Refactor need to figure this out. + // Commented out for some reson or another. + + private static void runWalkSitStand(UpdateStateMsg msg, ClientConnection origin) throws MsgSendException { + PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); + if (pc == null) + return; + + pc.update(); + if (msg.getSpeed() == 2) + pc.setWalkMode(false); + else + pc.setWalkMode(true); + DispatchMessage.dispatchMsgToInterestArea(pc, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + } + + private static void toggleLfgRecruiting(ToggleLfgRecruitingMsg msg, ClientConnection origin) throws MsgSendException { + PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); + if (pc == null) + return; + int num = msg.toggleLfgRecruiting(); + if (num == 1) + pc.toggleLFGroup(); + else if (num == 2) + pc.toggleLFGuild(); + else if (num == 3) + pc.toggleRecruiting(); + UpdateStateMsg rwss = new UpdateStateMsg(); + rwss.setPlayer(pc); + DispatchMessage.dispatchMsgToInterestArea(pc, rwss, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + } + + private static void toggleSitStand(ToggleSitStandMsg msg, ClientConnection origin) throws MsgSendException { + PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); + if (pc == null) + return; + + pc.update(); + + pc.setSit(msg.toggleSitStand()); + + // cancel effects that break on sit + if (pc.isSit()) { + pc.setCombat(false); + pc.cancelOnSit(); + } + + UpdateStateMsg rwss = new UpdateStateMsg(); + if (pc.isSit()) { + pc.setCombat(false); + rwss.setAware(1); + } + rwss.setPlayer(pc); + + DispatchMessage.dispatchMsgToInterestArea(pc, rwss, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + } + + private static void targetObject(TargetObjectMsg msg, ClientConnection origin) { + PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); + if (pc == null) + return; + + // TODO improve this later. hacky way to make sure player ingame is + // active. + + if (!pc.isActive()) + pc.setActive(true); + + pc.setLastTarget(GameObjectType.values()[msg.getTargetType()], msg.getTargetID()); + } + + private static void social(SocialMsg msg, ClientConnection origin) throws MsgSendException { + PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); + if (pc == null) + return; + DispatchMessage.dispatchMsgToInterestArea(pc, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, true); + } + + private static void TransferItemFromEquipToInventory(TransferItemFromEquipToInventoryMsg msg, ClientConnection origin) { + PlayerCharacter pc = origin.getPlayerCharacter(); + if (pc == null) + return; + + CharacterItemManager itemManager = pc.getCharItemManager(); + if (itemManager == null) + return; + + int slot = msg.getSlotNumber(); + + Item i = itemManager.getItemFromEquipped(slot); + if (i == null) + return; + + if (!itemManager.doesCharOwnThisItem(i.getObjectUUID())) + return; + + //dupe check + if (!i.validForEquip(origin, pc, itemManager)) + return; + + if (i.containerType == ItemContainerType.EQUIPPED) + itemManager.moveItemToInventory(i); + + int ItemType = i.getObjectType().ordinal(); + int ItemID = i.getObjectUUID(); + for (String name : i.getEffects().keySet()) { + Effect eff = i.getEffects().get(name); + if (eff == null) + return; + ApplyEffectMsg pum = new ApplyEffectMsg(); + pum.setEffectID(eff.getEffectToken()); + pum.setSourceType(pc.getObjectType().ordinal()); + pum.setSourceID(pc.getObjectUUID()); + pum.setTargetType(pc.getObjectType().ordinal()); + pum.setTargetID(pc.getObjectUUID()); + pum.setNumTrains(eff.getTrains()); + pum.setUnknown05(1); + pum.setUnknown02(2); + pum.setUnknown06((byte) 1); + pum.setEffectSourceType(ItemType); + pum.setEffectSourceID(ItemID); + pum.setDuration(-1); + + + DispatchMessage.dispatchMsgToInterestArea(pc, pum, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + ; + + } + // Update player formulas + pc.applyBonuses(); + DispatchMessage.dispatchMsgToInterestArea(pc, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); + + } + + private static void TransferItemFromInventoryToEquip(TransferItemFromInventoryToEquipMsg msg, ClientConnection origin) { + PlayerCharacter pc = origin.getPlayerCharacter(); + if (pc == null) + return; + + CharacterItemManager itemManager = pc.getCharItemManager(); + if (itemManager == null) { + forceTransferFromEquipToInventory(msg, origin, "Can't find your item manager"); + return; + } + + int uuid = msg.getUUID(); + int slot = msg.getSlotNumber(); + //System.out.println("loading to slot: " + slot); + + Item i = itemManager.getItemByUUID(uuid); + + if (i == null) { + forceTransferFromEquipToInventory(msg, origin, "Item not found in your item manager"); + return; + } + + if (!itemManager.doesCharOwnThisItem(i.getObjectUUID())) { + forceTransferFromEquipToInventory(msg, origin, "You do not own this item"); + return; + } + + //dupe check + if (!i.validForInventory(origin, pc, itemManager)) + return; + + if (i.containerType == ItemContainerType.INVENTORY) { + if (!itemManager.equipItem(i, (byte) slot)) { + forceTransferFromEquipToInventory(msg, origin, "Failed to transfer item."); + return; + } + } else { + forceTransferFromEquipToInventory(msg, origin, "This item is not in your inventory"); + return; + } + + // Update player formulas + pc.applyBonuses(); + DispatchMessage.dispatchMsgToInterestArea(pc, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); + + + for (String name : i.getEffects().keySet()) { + Effect eff = i.getEffects().get(name); + if (eff == null) + return; + + ApplyEffectMsg pum = new ApplyEffectMsg(); + pum.setEffectID(eff.getEffectToken()); + pum.setSourceType(pc.getObjectType().ordinal()); + pum.setSourceID(pc.getObjectUUID()); + pum.setTargetType(pc.getObjectType().ordinal()); + pum.setTargetID(pc.getObjectUUID()); + pum.setNumTrains(eff.getTrains()); + pum.setUnknown05(1); + pum.setUnknown06((byte) 1); + pum.setEffectSourceType(i.getObjectType().ordinal()); + pum.setEffectSourceID(i.getObjectUUID()); + pum.setDuration(-1); + + DispatchMessage.dispatchMsgToInterestArea(pc, pum, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); + ; + } + } + + //call this if the transfer fails server side to kick the item back to inventory from equip + private static void forceTransferFromEquipToInventory(TransferItemFromInventoryToEquipMsg msg, ClientConnection origin, String reason) { + + PlayerCharacter pc = origin.getPlayerCharacter(); + + if (pc == null) + return; + + TransferItemFromEquipToInventoryMsg back = new TransferItemFromEquipToInventoryMsg(pc, msg.getSlotNumber()); + Dispatch dispatch = Dispatch.borrow(pc, back); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + ChatManager.chatInfoError(pc, "Can't equip item: " + reason); + } + + public static Boolean NPCVaultBankRangeCheck(PlayerCharacter pc, ClientConnection origin, String bankorvault) { + + if (pc == null) + return false; + + NPC npc = pc.getLastNPCDialog(); + + if (npc == null) + return false; + + // System.out.println(npc.getContract().getName()); + // last npc must be either a banker or vault keeper + + if (bankorvault.equals("vault")) { + if (npc.getContract().getContractID() != 861) + return false; + } else + // assuming banker + + if (!npc.getContract().getName().equals("Bursar")) + return false; + + if (pc.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) { + ErrorPopupMsg.sendErrorPopup(pc, 14); + return false; + } else + return true; + + } + + private static void transferItemFromInventoryToBank(TransferItemFromInventoryToBankMsg msg, ClientConnection origin) { + + PlayerCharacter player = origin.getPlayerCharacter(); + Dispatch dispatch; + + if (player == null) + return; + + if (!NPCVaultBankRangeCheck(player, origin, "bank")) + return; + + CharacterItemManager itemManager = player.getCharItemManager(); + + if (itemManager == null) + return; + + if (itemManager.getBankWeight() > 500) { + ErrorPopupMsg.sendErrorPopup(player, 21); + return; + } + + int uuid = msg.getUUID(); + + Item item = itemManager.getItemByUUID(uuid); + + if (item == null) + return; + + //dupe check WTF CHECK BUT NO LOGGING? + + if (!item.validForInventory(origin, player, itemManager)) + return; + + if (item.containerType == ItemContainerType.INVENTORY && itemManager.isBankOpen()) + if (item.getItemBase().getType().equals(engine.Enum.ItemType.GOLD)) { + if (!itemManager.moveGoldToBank(item, msg.getNumItems())) + return; + UpdateGoldMsg goldMes = new UpdateGoldMsg(player); + goldMes.configure(); + + dispatch = Dispatch.borrow(player, goldMes); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + } else { + + if (!itemManager.hasRoomBank(item.getItemBase().getWeight())) + return; + + if (!itemManager.moveItemToBank(item)) + return; + + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + } + } + + private static void transferItemFromBankToInventory(TransferItemFromBankToInventoryMsg msg, ClientConnection origin) { + + PlayerCharacter player = origin.getPlayerCharacter(); + Dispatch dispatch; + + if (player == null) + return; + + if (!NPCVaultBankRangeCheck(player, origin, "bank")) + return; + + CharacterItemManager itemManager = player.getCharItemManager(); + + if (itemManager == null) + return; + + int uuid = msg.getUUID(); + + Item item = itemManager.getItemByUUID(uuid); + + if (item == null) + return; + + //dupe check + // WTF Checking but not logging? + + if (!item.validForBank(origin, player, itemManager)) + return; + + if (item.containerType == ItemContainerType.BANK && itemManager.isBankOpen() == false) + return; + + if (item.getItemBase().getType().equals(engine.Enum.ItemType.GOLD)) { + + if (!itemManager.moveGoldToInventory(item, msg.getNumItems())) + return; + + UpdateGoldMsg goldMes = new UpdateGoldMsg(player); + goldMes.configure(); + + dispatch = Dispatch.borrow(player, goldMes); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + return; + } + + // Not gold, process update here + + if (!itemManager.hasRoomInventory(item.getItemBase().getWeight())) + return; + + if (itemManager.moveItemToInventory(item) == false) + return; + + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + } + + private static void transferItemFromVaultToInventory(TransferItemFromVaultToInventoryMsg msg, ClientConnection origin) { + + PlayerCharacter player = origin.getPlayerCharacter(); + Dispatch dispatch; + + if (player == null) + return; + + if (player.getAccount() == null) + return; + player.getAccount().transferItemFromVaultToInventory(msg, origin); + + + } + + //call this if the transfer fails server side to kick the item back to inventory from vault + public static void forceTransferFromInventoryToVault(TransferItemFromVaultToInventoryMsg msg, ClientConnection origin, String reason) { + + PlayerCharacter player = origin.getPlayerCharacter(); + Dispatch dispatch; + + if (player == null) + return; + + TransferItemFromInventoryToVaultMsg back = new TransferItemFromInventoryToVaultMsg(msg); + dispatch = Dispatch.borrow(player, back); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + ChatManager.chatInfoError(player, "Can't transfer to inventory: " + reason); + } + + private static void transferItemFromInventoryToVault(TransferItemFromInventoryToVaultMsg msg, ClientConnection origin) { + + PlayerCharacter player = origin.getPlayerCharacter(); + Dispatch dispatch; + + if (player == null) + return; + + if (player.getAccount() == null) + return; + player.getAccount().transferItemFromInventoryToVault(msg, origin); + + } + + //call this if the transfer fails server side to kick the item back to vault from inventory + public static void forceTransferFromVaultToInventory(TransferItemFromInventoryToVaultMsg msg, ClientConnection origin, String reason) { + + PlayerCharacter player = origin.getPlayerCharacter(); + Dispatch dispatch; + + if (player == null) + return; + + TransferItemFromVaultToInventoryMsg back = new TransferItemFromVaultToInventoryMsg(msg); + dispatch = Dispatch.borrow(player, back); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + ChatManager.chatInfoError(player, "Can't transfer to vault: " + reason); + } + + private static void transferGoldFromVaultToInventory(TransferGoldFromVaultToInventoryMsg msg, ClientConnection origin) { + PlayerCharacter player = origin.getPlayerCharacter(); - for (String name : i.getEffects().keySet()) { - Effect eff = i.getEffects().get(name); - if (eff == null) - return; - - ApplyEffectMsg pum = new ApplyEffectMsg(); - pum.setEffectID(eff.getEffectToken()); - pum.setSourceType(pc.getObjectType().ordinal()); - pum.setSourceID(pc.getObjectUUID()); - pum.setTargetType(pc.getObjectType().ordinal()); - pum.setTargetID(pc.getObjectUUID()); - pum.setNumTrains(eff.getTrains()); - pum.setUnknown05(1); - pum.setUnknown06((byte) 1); - pum.setEffectSourceType(i.getObjectType().ordinal()); - pum.setEffectSourceID(i.getObjectUUID()); - pum.setDuration(-1); - - DispatchMessage.dispatchMsgToInterestArea(pc, pum, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false);; - } - } - //call this if the transfer fails server side to kick the item back to inventory from equip - private static void forceTransferFromEquipToInventory(TransferItemFromInventoryToEquipMsg msg, ClientConnection origin, String reason) { + if (player == null) + return; - PlayerCharacter pc = origin.getPlayerCharacter(); + Account account = player.getAccount(); - if (pc == null) - return; + if (account == null) + return; - TransferItemFromEquipToInventoryMsg back = new TransferItemFromEquipToInventoryMsg(pc, msg.getSlotNumber()); - Dispatch dispatch = Dispatch.borrow(pc, back); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + account.transferGoldFromVaultToInventory(msg, origin); + } - ChatManager.chatInfoError(pc, "Can't equip item: " + reason); - } + private static void transferGoldFromInventoryToVault(TransferGoldFromInventoryToVaultMsg msg, ClientConnection origin) { - public static Boolean NPCVaultBankRangeCheck(PlayerCharacter pc, ClientConnection origin, String bankorvault) { + PlayerCharacter player = origin.getPlayerCharacter(); + Dispatch dispatch; - if (pc == null) - return false; + if (player == null) + return; - NPC npc = pc.getLastNPCDialog(); + Account account = player.getAccount(); - if (npc == null) - return false; + if (account == null) + return; - // System.out.println(npc.getContract().getName()); - // last npc must be either a banker or vault keeper + account.transferGoldFromInventoryToVault(msg, origin); - if (bankorvault.equals("vault")) { - if (npc.getContract().getContractID() != 861) - return false; - } - else - // assuming banker + } - if (!npc.getContract().getName().equals("Bursar")) - return false; + private static void DeleteItem(DeleteItemMsg msg, ClientConnection origin) { - if (pc.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) { - ErrorPopupMsg.sendErrorPopup(pc, 14); - return false; - } else - return true; + CharacterItemManager itemManager = origin.getPlayerCharacter().getCharItemManager(); + int uuid = msg.getUUID(); - } - private static void transferItemFromInventoryToBank(TransferItemFromInventoryToBankMsg msg, ClientConnection origin) { + PlayerCharacter sourcePlayer = origin.getPlayerCharacter(); - PlayerCharacter player = origin.getPlayerCharacter(); - Dispatch dispatch; + if (sourcePlayer == null) + return; - if (player == null) - return; + if (!sourcePlayer.isAlive()) + return; - if (!NPCVaultBankRangeCheck(player, origin, "bank")) - return; + Item i = Item.getFromCache(msg.getUUID()); - CharacterItemManager itemManager = player.getCharItemManager(); + if (i == null) + return; - if (itemManager == null) - return; + if (!itemManager.doesCharOwnThisItem(i.getObjectUUID())) + return; - if (itemManager.getBankWeight() > 500) { - ErrorPopupMsg.sendErrorPopup(player, 21); - return; - } + if (!itemManager.inventoryContains(i)) + return; - int uuid = msg.getUUID(); + if (i.isCanDestroy()) + if (itemManager.delete(i) == true) { + Dispatch dispatch = Dispatch.borrow(sourcePlayer, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + } - Item item = itemManager.getItemByUUID(uuid); + } - if (item == null) - return; + private static void ackBankWindowOpened(AckBankWindowOpenedMsg msg, ClientConnection origin) { + // According to the Wiki, the client should not send this message. + // Log the instance to investigate, and modify Wiki accordingly. + Logger.error(msg.toString()); + } - //dupe check WTF CHECK BUT NO LOGGING? + private static void modifyStat(ModifyStatMsg msg, ClientConnection origin) { - if (!item.validForInventory(origin, player, itemManager)) - return; + PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); - if (item.containerType == ItemContainerType.INVENTORY && itemManager.isBankOpen()) - if (item.getItemBase().getType().equals(engine.Enum.ItemType.GOLD)) { - if (!itemManager.moveGoldToBank(item, msg.getNumItems())) - return; - UpdateGoldMsg goldMes = new UpdateGoldMsg(player); - goldMes.configure(); + if (pc == null) + return; - dispatch = Dispatch.borrow(player, goldMes); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + int type = msg.getType(); - } - else { + switch (type) { + case MBServerStatics.STAT_STR_ID: + pc.addStr(msg.getAmount()); + break; + case MBServerStatics.STAT_DEX_ID: + pc.addDex(msg.getAmount()); + break; + case MBServerStatics.STAT_CON_ID: + pc.addCon(msg.getAmount()); + break; + case MBServerStatics.STAT_INT_ID: + pc.addInt(msg.getAmount()); + break; + case MBServerStatics.STAT_SPI_ID: + pc.addSpi(msg.getAmount()); + break; + } + } - if (!itemManager.hasRoomBank(item.getItemBase().getWeight())) - return; + // called when player clicks respawn button + private static void respawn(RespawnMsg msg, ClientConnection origin) throws MsgSendException { - if (!itemManager.moveItemToBank(item)) - return; + PlayerCharacter sourcePlayer = SessionManager.getPlayerCharacter(origin); - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + if (sourcePlayer == null) + return; - } - } + if (msg.getObjectType() != sourcePlayer.getObjectType().ordinal() || msg.getObjectID() != sourcePlayer.getObjectUUID()) { + Logger.error("Player " + sourcePlayer.getObjectUUID() + " respawning character of id " + msg.getObjectType() + ' ' + + msg.getObjectID()); + return; + } - private static void transferItemFromBankToInventory(TransferItemFromBankToInventoryMsg msg, ClientConnection origin) { + if (sourcePlayer.isAlive()) { + Logger.error("Player " + sourcePlayer.getObjectUUID() + " respawning while alive"); + return; + } + // ResetAfterDeath player + sourcePlayer.respawnLock.writeLock().lock(); + try { + sourcePlayer.respawn(true, false, true); - PlayerCharacter player = origin.getPlayerCharacter(); - Dispatch dispatch; + } catch (Exception e) { + Logger.error(e); + } finally { + sourcePlayer.respawnLock.writeLock().unlock(); - if (player == null) - return; + } + // Echo ResetAfterDeath message back + msg.setPlayerHealth(sourcePlayer.getHealth()); + // TODO calculate any experience loss before this point + msg.setPlayerExp(sourcePlayer.getExp() + sourcePlayer.getOverFlowEXP()); + Dispatch dispatch = Dispatch.borrow(sourcePlayer, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + + MoveToPointMsg moveMsg = new MoveToPointMsg(); + moveMsg.setPlayer(sourcePlayer); + moveMsg.setStartCoord(sourcePlayer.getLoc()); + moveMsg.setEndCoord(sourcePlayer.getLoc()); + moveMsg.setInBuilding(-1); + moveMsg.setUnknown01(-1); + + dispatch = Dispatch.borrow(sourcePlayer, moveMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + + MovementManager.sendRWSSMsg(sourcePlayer); + + // refresh the whole group with what just happened + JobScheduler.getInstance().scheduleJob(new RefreshGroupJob(sourcePlayer), MBServerStatics.LOAD_OBJECT_DELAY); + } + + private static void lootWindowRequest(LootWindowRequestMsg msg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); + + if (pc == null) + return; + + if (!pc.isAlive()) + return; + + if (msg.getSourceType() != pc.getObjectType().ordinal() || msg.getSourceID() != pc.getObjectUUID()) { + Logger.error("Player " + pc.getObjectUUID() + " looting from character of id " + + msg.getSourceType() + ' ' + msg.getSourceID()); + return; + } + + if (pc.getAltitude() > 0) + return; + if (!pc.isAlive()) { + return; + } + + + LootWindowResponseMsg lwrm = null; + GameObjectType targetType = GameObjectType.values()[msg.getTargetType()]; + AbstractCharacter characterTarget = null; + Corpse corpseTarget = null; + + switch (targetType) { + case PlayerCharacter: + + characterTarget = PlayerCharacter.getFromCache(msg.getTargetID()); + if (characterTarget == null) + return; + if (characterTarget.isAlive()) + return; + if (pc.getLoc().distanceSquared2D(characterTarget.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { + ErrorPopupMsg.sendErrorMsg(pc, "You are too far away to loot this corpse."); + + Logger.info(pc.getFirstName() + " tried looting at " + pc.getLoc().distance2D(characterTarget.getLoc()) + " distance."); + return; + } + lwrm = new LootWindowResponseMsg(characterTarget.getObjectType().ordinal(), characterTarget.getObjectUUID(), characterTarget.getInventory(true)); + break; + case NPC: + characterTarget = NPC.getFromCache(msg.getTargetID()); + if (characterTarget == null) + return; + break; + case Mob: + characterTarget = Mob.getFromCache(msg.getTargetID()); + if ((characterTarget == null) || characterTarget.isAlive()) { + return; + } + + if (pc.getLoc().distanceSquared2D(characterTarget.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { + ErrorPopupMsg.sendErrorMsg(pc, "You are too far away to loot this corpse."); + + Logger.info(pc.getFirstName() + " tried looting at " + pc.getLoc().distance2D(characterTarget.getLoc()) + " distance."); + + if (!((Mob) characterTarget).isLootSync()) { + + ((Mob) characterTarget).setLootSync(true); + WorldGrid.updateObject(characterTarget, pc); + } + + + return; + } - if (!NPCVaultBankRangeCheck(player, origin, "bank")) - return; + lwrm = new LootWindowResponseMsg(characterTarget.getObjectType().ordinal(), characterTarget.getObjectUUID(), characterTarget.getInventory()); + break; + case Corpse: + corpseTarget = Corpse.getCorpse(msg.getTargetID()); - CharacterItemManager itemManager = player.getCharItemManager(); + if ((corpseTarget == null)) { + return; + } - if (itemManager == null) - return; + if (pc.getLoc().distanceSquared(corpseTarget.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { + ErrorPopupMsg.sendErrorMsg(pc, "You are too far away to loot this corpse."); - int uuid = msg.getUUID(); + Logger.info(pc.getFirstName() + " tried looting at " + pc.getLoc().distance2D(characterTarget.getLoc()) + " distance."); + return; + } + lwrm = new LootWindowResponseMsg(corpseTarget.getObjectType().ordinal(), msg.getTargetID(), corpseTarget.getInventory()); + break; + } - Item item = itemManager.getItemByUUID(uuid); + if (lwrm == null) + return; - if (item == null) - return; + DispatchMessage.dispatchMsgToInterestArea(pc, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); + Dispatch dispatch = Dispatch.borrow(pc, lwrm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - //dupe check - // WTF Checking but not logging? + } - if (!item.validForBank(origin, player, itemManager)) - return; + private static void loot(LootMsg msg, ClientConnection origin) throws MsgSendException { - if (item.containerType == ItemContainerType.BANK && itemManager.isBankOpen() == false) - return; + PlayerCharacter player = SessionManager.getPlayerCharacter(origin); + if (player == null) + return; - if (item.getItemBase().getType().equals(engine.Enum.ItemType.GOLD)) { + if (!player.isAlive()) + return; - if (!itemManager.moveGoldToInventory(item, msg.getNumItems())) - return; + Item item = msg.getItem(); - UpdateGoldMsg goldMes = new UpdateGoldMsg(player); - goldMes.configure(); + if (item == null) + return; - dispatch = Dispatch.borrow(player, goldMes); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + if (item.lootLock.tryLock()) { + try { + Item itemRet = null; + // get current owner + int targetType = msg.getTargetType(); + int targetID = msg.getTargetID(); - return; - } + if (targetType == GameObjectType.PlayerCharacter.ordinal() || targetType == GameObjectType.Mob.ordinal() || targetType == GameObjectType.Corpse.ordinal()) { + } else { //needed for getting contracts for some reason + targetType = msg.getSourceID2(); + targetID = msg.getUnknown01(); + } - // Not gold, process update here + //can't loot while flying + if (player.getAltitude() > 0) + return; - if (!itemManager.hasRoomInventory(item.getItemBase().getWeight())) - return; + AbstractCharacter tar = null; + Corpse corpse = null; - if (itemManager.moveItemToInventory(item) == false) - return; + if (targetType == GameObjectType.PlayerCharacter.ordinal() || targetType == GameObjectType.Mob.ordinal()) { - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + if (targetType == GameObjectType.PlayerCharacter.ordinal()) { + tar = PlayerCharacter.getFromCache(targetID); - } + if (tar == null) + return; - private static void transferItemFromVaultToInventory(TransferItemFromVaultToInventoryMsg msg, ClientConnection origin) { + if (player.getObjectUUID() != tar.getObjectUUID() && ((PlayerCharacter) tar).isInSafeZone()) + return; - PlayerCharacter player = origin.getPlayerCharacter(); - Dispatch dispatch; + } else if (targetType == GameObjectType.NPC.ordinal()) + tar = NPC.getFromCache(targetID); + else if (targetType == GameObjectType.Mob.ordinal()) + tar = Mob.getFromCache(targetID); + if (tar == null) + return; - if (player == null) - return; + if (tar.equals(player)) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot loot this item."); + return; + } - if (player.getAccount() == null) - return; - player.getAccount().transferItemFromVaultToInventory(msg, origin); + if (player.getLoc().distanceSquared2D(tar.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { + ErrorPopupMsg.sendErrorMsg(player, "You are too far away to loot this corpse."); - } + Logger.info(player.getFirstName() + " tried looting at " + player.getLoc().distance2D(tar.getLoc()) + " distance."); + return; + } - //call this if the transfer fails server side to kick the item back to inventory from vault - public static void forceTransferFromInventoryToVault(TransferItemFromVaultToInventoryMsg msg, ClientConnection origin, String reason) { + //can't loot from someone who is alive. + if (AbstractWorldObject.IsAbstractCharacter(tar)) { + if (tar.isAlive()) + return; + // Logger.error("WorldServer.loot", "Looting from live player"); + } - PlayerCharacter player = origin.getPlayerCharacter(); - Dispatch dispatch; + if (!GroupManager.goldSplit(player, item, origin, tar)) { - if (player == null) - return; + if (tar.getCharItemManager() != null) { - TransferItemFromInventoryToVaultMsg back = new TransferItemFromInventoryToVaultMsg(msg); - dispatch = Dispatch.borrow(player, back); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + itemRet = tar.getCharItemManager().lootItemFromMe(item, player, origin); - ChatManager.chatInfoError(player, "Can't transfer to inventory: " + reason); - } + //Take equipment off mob + if (tar.getObjectType() == GameObjectType.Mob && itemRet != null) { + Mob mobTarget = (Mob) tar; - private static void transferItemFromInventoryToVault(TransferItemFromInventoryToVaultMsg msg, ClientConnection origin) { + if (item != null && item.getObjectType() == GameObjectType.MobLoot) { - PlayerCharacter player = origin.getPlayerCharacter(); - Dispatch dispatch; + for (MobEquipment equip : mobTarget.getEquip().values()) { - if (player == null) - return; + TransferItemFromEquipToInventoryMsg back = new TransferItemFromEquipToInventoryMsg(mobTarget, equip.getSlot()); + DispatchMessage.dispatchMsgToInterestArea(mobTarget, back, DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); - if (player.getAccount() == null) - return; - player.getAccount().transferItemFromInventoryToVault(msg, origin); + LootMsg lootMsg = new LootMsg(0, 0, tar.getObjectType().ordinal(), tar.getObjectUUID(), equip); + Dispatch dispatch = Dispatch.borrow(player, lootMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + break; + } + } + } + } - } + } + } else if (targetType == GameObjectType.Corpse.ordinal()) { + corpse = Corpse.getCorpse(targetID); + if (corpse == null) + return; - //call this if the transfer fails server side to kick the item back to vault from inventory - public static void forceTransferFromVaultToInventory(TransferItemFromInventoryToVaultMsg msg, ClientConnection origin, String reason) { + if (player.getLoc().distanceSquared2D(corpse.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { + ErrorPopupMsg.sendErrorMsg(player, "You are too far away to loot this corpse."); - PlayerCharacter player = origin.getPlayerCharacter(); - Dispatch dispatch; + Logger.info(player.getFirstName() + " tried looting at " + player.getLoc().distance2D(corpse.getLoc()) + " distance."); + return; + } - if (player == null) - return; - TransferItemFromVaultToInventoryMsg back = new TransferItemFromVaultToInventoryMsg(msg); - dispatch = Dispatch.borrow(player, back); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + //can't loot other players in safe zone. + if (corpse.getBelongsToType() == GameObjectType.PlayerCharacter.ordinal()) { - ChatManager.chatInfoError(player, "Can't transfer to vault: " + reason); - } + if (player.getObjectUUID() == corpse.getBelongsToID()) + itemRet = corpse.lootItem(item, player); + else if (!GroupManager.goldSplit(player, item, origin, corpse)) { + itemRet = corpse.lootItem(item, player); - private static void transferGoldFromVaultToInventory(TransferGoldFromVaultToInventoryMsg msg, ClientConnection origin) { + } - PlayerCharacter player = origin.getPlayerCharacter(); + if (itemRet == null) + return; - if (player == null) - return; + if (item.getItemBase().getType().equals(engine.Enum.ItemType.GOLD)) { + // this is done to prevent the temporary goldItem item + // (from the mob) from appearing in player's inventory. + // It also updates the goldItem quantity display + UpdateGoldMsg updateTargetGold = null; - Account account = player.getAccount(); - if (account == null) - return; + if (corpse != null) + updateTargetGold = new UpdateGoldMsg(corpse); - account.transferGoldFromVaultToInventory(msg, origin); - } + updateTargetGold.configure(); + DispatchMessage.dispatchMsgToInterestArea(corpse, updateTargetGold, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); - private static void transferGoldFromInventoryToVault(TransferGoldFromInventoryToVaultMsg msg, ClientConnection origin) { + UpdateGoldMsg ugm = new UpdateGoldMsg(player); + ugm.configure(); + Dispatch dispatch = Dispatch.borrow(player, ugm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - PlayerCharacter player = origin.getPlayerCharacter(); - Dispatch dispatch; + // respond back loot message. Try sending to everyone. - if (player == null) - return; + } else { - Account account = player.getAccount(); + DispatchMessage.dispatchMsgToInterestArea(corpse, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, true); - if (account == null) - return; - account.transferGoldFromInventoryToVault(msg, origin); + //player.getCharItemManager().updateInventory(); + } - } + //TODO send group loot message if player is grouped and visible + Group group = GroupManager.getGroup(player); - private static void DeleteItem(DeleteItemMsg msg, ClientConnection origin) { + if (group != null && group.getSplitGold() && (item.getItemBase().getType().equals(engine.Enum.ItemType.GOLD) == false)) { + String name = item.getName(); + String text = player.getFirstName() + " has looted " + name + '.'; + ChatManager.chatGroupInfoCanSee(player, text); + } - CharacterItemManager itemManager = origin.getPlayerCharacter().getCharItemManager(); - int uuid = msg.getUUID(); + return; + } - PlayerCharacter sourcePlayer = origin.getPlayerCharacter(); + } else + return; - if (sourcePlayer == null) - return; - if (!sourcePlayer.isAlive()) - return; + if (itemRet == null) { + return; + } - Item i = Item.getFromCache(msg.getUUID()); + if (item.getItemBase().getType().equals(engine.Enum.ItemType.GOLD)) { + // this is done to prevent the temporary goldItem item + // (from the mob) from appearing in player's inventory. + // It also updates the goldItem quantity display + UpdateGoldMsg updateTargetGold = null; - if (i == null) - return; + if (tar != null) + updateTargetGold = new UpdateGoldMsg(tar); + else if (corpse != null) + updateTargetGold = new UpdateGoldMsg(corpse); - if (!itemManager.doesCharOwnThisItem(i.getObjectUUID())) - return; + updateTargetGold.configure(); + DispatchMessage.dispatchMsgToInterestArea(tar, updateTargetGold, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - if (!itemManager.inventoryContains(i)) - return; + UpdateGoldMsg ugm = new UpdateGoldMsg(player); + ugm.configure(); + Dispatch dispatch = Dispatch.borrow(player, ugm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - if (i.isCanDestroy()) - if (itemManager.delete(i) == true) { - Dispatch dispatch = Dispatch.borrow(sourcePlayer, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } + // respond back loot message. Try sending to everyone. - } + } else { + msg.setSourceType1(0); + msg.setSourceType2(0); + msg.setSourceID1(0); + msg.setSourceID2(0); + Dispatch dispatch = Dispatch.borrow(player, msg); + //DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + DispatchMessage.dispatchMsgToInterestArea(tar, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, true); + LootMsg newItemMsg = new LootMsg(GameObjectType.PlayerCharacter.ordinal(), player.getObjectUUID(), 0, 0, itemRet); + dispatch = Dispatch.borrow(player, newItemMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - private static void ackBankWindowOpened(AckBankWindowOpenedMsg msg, ClientConnection origin) { - // According to the Wiki, the client should not send this message. - // Log the instance to investigate, and modify Wiki accordingly. - Logger.error( msg.toString()); - } + //player.getCharItemManager().updateInventory(); + } - private static void modifyStat(ModifyStatMsg msg, ClientConnection origin) { + //TODO send group loot message if player is grouped and visible + Group group = GroupManager.getGroup(player); - PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); + if (group != null && group.getSplitGold() && (item.getItemBase().getType().equals(engine.Enum.ItemType.GOLD) == false)) { + String name = item.getName(); + String text = player.getFirstName() + " has looted " + name + '.'; + ChatManager.chatGroupInfoCanSee(player, text); + } + } catch (Exception e) { + Logger.info(e.getMessage()); + } finally { + item.lootLock.unlock(); + } + } - if (pc == null) - return; - int type = msg.getType(); + } - switch (type) { - case MBServerStatics.STAT_STR_ID: - pc.addStr(msg.getAmount()); - break; - case MBServerStatics.STAT_DEX_ID: - pc.addDex(msg.getAmount()); - break; - case MBServerStatics.STAT_CON_ID: - pc.addCon(msg.getAmount()); - break; - case MBServerStatics.STAT_INT_ID: - pc.addInt(msg.getAmount()); - break; - case MBServerStatics.STAT_SPI_ID: - pc.addSpi(msg.getAmount()); - break; - } - } + // called when player types /show + private static void show(ShowMsg msg, ClientConnection origin) throws MsgSendException { - + PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); - // called when player clicks respawn button - private static void respawn(RespawnMsg msg, ClientConnection origin) throws MsgSendException { - - PlayerCharacter sourcePlayer = SessionManager.getPlayerCharacter(origin); - - if (sourcePlayer == null) - return; - - if (msg.getObjectType() != sourcePlayer.getObjectType().ordinal() || msg.getObjectID() != sourcePlayer.getObjectUUID()) { - Logger.error( "Player " + sourcePlayer.getObjectUUID() + " respawning character of id " + msg.getObjectType() + ' ' - + msg.getObjectID()); - return; - } - - if (sourcePlayer.isAlive()) { - Logger.error( "Player " + sourcePlayer.getObjectUUID() + " respawning while alive"); - return; - } - // ResetAfterDeath player - sourcePlayer.respawnLock.writeLock().lock(); - try{ - sourcePlayer.respawn(true, false, true); - - }catch(Exception e){ - Logger.error(e); - }finally{ - sourcePlayer.respawnLock.writeLock().unlock(); - - } - // Echo ResetAfterDeath message back - msg.setPlayerHealth(sourcePlayer.getHealth()); - // TODO calculate any experience loss before this point - msg.setPlayerExp(sourcePlayer.getExp() + sourcePlayer.getOverFlowEXP()); - Dispatch dispatch = Dispatch.borrow(sourcePlayer, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - - MoveToPointMsg moveMsg = new MoveToPointMsg(); - moveMsg.setPlayer(sourcePlayer); - moveMsg.setStartCoord(sourcePlayer.getLoc()); - moveMsg.setEndCoord(sourcePlayer.getLoc()); - moveMsg.setInBuilding(-1); - moveMsg.setUnknown01(-1); - - dispatch = Dispatch.borrow(sourcePlayer, moveMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - - MovementManager.sendRWSSMsg(sourcePlayer); - - // refresh the whole group with what just happened - JobScheduler.getInstance().scheduleJob(new RefreshGroupJob(sourcePlayer), MBServerStatics.LOAD_OBJECT_DELAY); - } - - private static void lootWindowRequest(LootWindowRequestMsg msg, ClientConnection origin) throws MsgSendException { - - PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); - - if (pc == null) - return; - - if (!pc.isAlive()) - return; - - if (msg.getSourceType() != pc.getObjectType().ordinal() || msg.getSourceID() != pc.getObjectUUID()) { - Logger.error("Player " + pc.getObjectUUID() + " looting from character of id " - + msg.getSourceType() + ' ' + msg.getSourceID()); - return; - } - - if (pc.getAltitude() > 0) - return; - if (!pc.isAlive()) { - return; - } - - - LootWindowResponseMsg lwrm = null; - GameObjectType targetType = GameObjectType.values()[msg.getTargetType()]; - AbstractCharacter characterTarget = null; - Corpse corpseTarget = null; - - switch (targetType) { - case PlayerCharacter: - - characterTarget = PlayerCharacter.getFromCache(msg.getTargetID()); - if (characterTarget == null) - return; - if (characterTarget.isAlive()) - return; - if (pc.getLoc().distanceSquared2D(characterTarget.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)){ - ErrorPopupMsg.sendErrorMsg(pc, "You are too far away to loot this corpse."); - - Logger.info(pc.getFirstName() + " tried looting at " + pc.getLoc().distance2D(characterTarget.getLoc()) + " distance." ); - return; - } - lwrm = new LootWindowResponseMsg(characterTarget.getObjectType().ordinal(), characterTarget.getObjectUUID(), characterTarget.getInventory(true)); - break; - case NPC: - characterTarget = NPC.getFromCache(msg.getTargetID()); - if (characterTarget == null) - return; - break; - case Mob: - characterTarget = Mob.getFromCache(msg.getTargetID()); - if ((characterTarget == null) || characterTarget.isAlive()) { - return; - } - - if (pc.getLoc().distanceSquared2D(characterTarget.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)){ - ErrorPopupMsg.sendErrorMsg(pc, "You are too far away to loot this corpse."); - - Logger.info(pc.getFirstName() + " tried looting at " + pc.getLoc().distance2D(characterTarget.getLoc()) + " distance." ); - - if (!((Mob)characterTarget).isLootSync()){ - - ((Mob)characterTarget).setLootSync(true); - WorldGrid.updateObject(characterTarget, pc); - } - - - return; - } - - lwrm = new LootWindowResponseMsg(characterTarget.getObjectType().ordinal(), characterTarget.getObjectUUID(), characterTarget.getInventory()); - break; - case Corpse: - corpseTarget = Corpse.getCorpse(msg.getTargetID()); - - if ((corpseTarget == null)) { - return; - } - - if (pc.getLoc().distanceSquared(corpseTarget.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)){ - ErrorPopupMsg.sendErrorMsg(pc, "You are too far away to loot this corpse."); - - Logger.info(pc.getFirstName() + " tried looting at " + pc.getLoc().distance2D(characterTarget.getLoc()) + " distance." ); - return; - } - lwrm = new LootWindowResponseMsg(corpseTarget.getObjectType().ordinal(), msg.getTargetID(), corpseTarget.getInventory()); - break; - } + if (pc == null) + return; - if (lwrm == null) - return; + int targetType = msg.getTargetType(); + AbstractCharacter tar = null; - DispatchMessage.dispatchMsgToInterestArea(pc, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); - Dispatch dispatch = Dispatch.borrow(pc, lwrm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + if (targetType == GameObjectType.PlayerCharacter.ordinal()) + tar = PlayerCharacter.getFromCache(msg.getTargetID()); + else if (targetType == GameObjectType.NPC.ordinal()) + tar = NPC.getFromCache(msg.getTargetID()); + else if (targetType == GameObjectType.Mob.ordinal()) + tar = Mob.getFromCache(msg.getTargetID()); - } + if (tar == null || !tar.isAlive() || !tar.isActive()) + return; - private static void loot(LootMsg msg, ClientConnection origin) throws MsgSendException { + msg.setUnknown01(pc.getLoc()); + msg.setUnknown02(pc.getLoc()); + msg.setRange01(pc.getRange()); + msg.setUnknown03(tar.getLoc()); + msg.setUnknown04(tar.getLoc()); + msg.setRange01(tar.getRange()); - PlayerCharacter player = SessionManager.getPlayerCharacter(origin); - if (player == null) - return; + Dispatch dispatch = Dispatch.borrow(pc, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - if (!player.isAlive()) - return; + } - Item item = msg.getItem(); - - if (item == null) - return; - - if (item.lootLock.tryLock()) { - try { - Item itemRet = null; - // get current owner - int targetType = msg.getTargetType(); - int targetID = msg.getTargetID(); + private static void ViewResourcesMessage(ViewResourcesMessage msg, ClientConnection origin) throws SQLException { - if (targetType == GameObjectType.PlayerCharacter.ordinal() || targetType == GameObjectType.Mob.ordinal() || targetType == GameObjectType.Corpse.ordinal()) { - } - else { //needed for getting contracts for some reason - targetType = msg.getSourceID2(); - targetID = msg.getUnknown01(); - } - - //can't loot while flying - if (player.getAltitude() > 0) - return; - - AbstractCharacter tar = null; - Corpse corpse = null; - - if (targetType == GameObjectType.PlayerCharacter.ordinal() || targetType == GameObjectType.Mob.ordinal()) { - - if (targetType == GameObjectType.PlayerCharacter.ordinal()) { - tar = PlayerCharacter.getFromCache(targetID); - - if (tar == null) - return; - - if (player.getObjectUUID() != tar.getObjectUUID() && ((PlayerCharacter) tar).isInSafeZone()) - return; - - } - - else if (targetType == GameObjectType.NPC.ordinal()) - tar = NPC.getFromCache(targetID); - else if (targetType == GameObjectType.Mob.ordinal()) - tar = Mob.getFromCache(targetID); - if (tar == null) - return; - - if (tar.equals(player)){ - ErrorPopupMsg.sendErrorMsg(player, "Cannot loot this item."); - return; - } - + PlayerCharacter player = SessionManager.getPlayerCharacter(origin); - if (player.getLoc().distanceSquared2D(tar.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)){ - ErrorPopupMsg.sendErrorMsg(player, "You are too far away to loot this corpse."); + if (player == null) + return; - Logger.info( player.getFirstName() + " tried looting at " + player.getLoc().distance2D(tar.getLoc()) + " distance." ); - return; - } + Guild guild = player.getGuild(); + City city = guild.getOwnedCity(); - //can't loot from someone who is alive. - if (AbstractWorldObject.IsAbstractCharacter(tar)) { - if (tar.isAlive()) - return; - // Logger.error("WorldServer.loot", "Looting from live player"); - } - - if (!GroupManager.goldSplit(player, item, origin, tar)) { - - if (tar.getCharItemManager() != null) { + if (city == null) + return; - itemRet = tar.getCharItemManager().lootItemFromMe(item, player, origin); + Building warehouse = BuildingManager.getBuilding(city.getWarehouseBuildingID()); - //Take equipment off mob - if (tar.getObjectType() == GameObjectType.Mob && itemRet != null){ - Mob mobTarget = (Mob)tar; - - if (item != null && item.getObjectType() == GameObjectType.MobLoot){ - - for (MobEquipment equip: mobTarget.getEquip().values()){ + if (warehouse == null) + return; - TransferItemFromEquipToInventoryMsg back = new TransferItemFromEquipToInventoryMsg(mobTarget, equip.getSlot()); - DispatchMessage.dispatchMsgToInterestArea(mobTarget, back, DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); - - LootMsg lootMsg = new LootMsg(0,0,tar.getObjectType().ordinal(), tar.getObjectUUID(), equip); - Dispatch dispatch = Dispatch.borrow(player, lootMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - break; - } - } - } - } - - } - } - - else if (targetType == GameObjectType.Corpse.ordinal()) { - corpse = Corpse.getCorpse(targetID); - if (corpse == null) - return; - - if (player.getLoc().distanceSquared2D(corpse.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)){ - ErrorPopupMsg.sendErrorMsg(player, "You are too far away to loot this corpse."); - - Logger.info( player.getFirstName() + " tried looting at " + player.getLoc().distance2D(corpse.getLoc()) + " distance." ); - return; - } - - - //can't loot other players in safe zone. - if (corpse.getBelongsToType() == GameObjectType.PlayerCharacter.ordinal()){ - - if (player.getObjectUUID() == corpse.getBelongsToID()) - itemRet = corpse.lootItem(item, player); - else if (!GroupManager.goldSplit(player, item, origin, corpse)) { - itemRet = corpse.lootItem(item, player); - - } - - if (itemRet == null) - return; - - - if (item.getItemBase().getType().equals(engine.Enum.ItemType.GOLD)) { - // this is done to prevent the temporary goldItem item - // (from the mob) from appearing in player's inventory. - // It also updates the goldItem quantity display - UpdateGoldMsg updateTargetGold = null; - - - if (corpse != null) - updateTargetGold = new UpdateGoldMsg(corpse); - - updateTargetGold.configure(); - DispatchMessage.dispatchMsgToInterestArea(corpse, updateTargetGold, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); - - UpdateGoldMsg ugm = new UpdateGoldMsg(player); - ugm.configure(); - Dispatch dispatch = Dispatch.borrow(player, ugm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - // respond back loot message. Try sending to everyone. - - } - else { - - DispatchMessage.dispatchMsgToInterestArea(corpse, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, true); - - - //player.getCharItemManager().updateInventory(); - } - - //TODO send group loot message if player is grouped and visible - Group group = GroupManager.getGroup(player); - - if (group != null && group.getSplitGold() && (item.getItemBase().getType().equals(engine.Enum.ItemType.GOLD) == false)) { - String name = item.getName(); - String text = player.getFirstName() + " has looted " + name + '.'; - ChatManager.chatGroupInfoCanSee(player, text); - } - - return; - } - - - - } - else - return; - - - if (itemRet == null) { - return; - } - - if (item.getItemBase().getType().equals(engine.Enum.ItemType.GOLD)) { - // this is done to prevent the temporary goldItem item - // (from the mob) from appearing in player's inventory. - // It also updates the goldItem quantity display - UpdateGoldMsg updateTargetGold = null; - - if (tar != null) - updateTargetGold = new UpdateGoldMsg(tar); - else if (corpse != null) - updateTargetGold = new UpdateGoldMsg(corpse); - - updateTargetGold.configure(); - DispatchMessage.dispatchMsgToInterestArea(tar, updateTargetGold, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - - UpdateGoldMsg ugm = new UpdateGoldMsg(player); - ugm.configure(); - Dispatch dispatch = Dispatch.borrow(player, ugm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + ViewResourcesMessage vrm = new ViewResourcesMessage(player); + vrm.setWarehouseBuilding(warehouse); + vrm.setGuild(player.getGuild()); + vrm.configure(); - // respond back loot message. Try sending to everyone. + Dispatch dispatch = Dispatch.borrow(player, vrm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } - else { - msg.setSourceType1(0); - msg.setSourceType2(0); - msg.setSourceID1(0); - msg.setSourceID2(0); - Dispatch dispatch = Dispatch.borrow(player, msg); - //DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - DispatchMessage.dispatchMsgToInterestArea(tar, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, true); - LootMsg newItemMsg = new LootMsg(GameObjectType.PlayerCharacter.ordinal(), player.getObjectUUID(),0,0, itemRet); - dispatch = Dispatch.borrow(player, newItemMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + } - //player.getCharItemManager().updateInventory(); - } + private static void randomRoll(RandomMsg msg, ClientConnection origin) throws MsgSendException { - //TODO send group loot message if player is grouped and visible - Group group = GroupManager.getGroup(player); + PlayerCharacter source = origin.getPlayerCharacter(); - if (group != null && group.getSplitGold() && (item.getItemBase().getType().equals(engine.Enum.ItemType.GOLD) == false)) { - String name = item.getName(); - String text = player.getFirstName() + " has looted " + name + '.'; - ChatManager.chatGroupInfoCanSee(player, text); - } - } catch (Exception e) { - Logger.info( e.getMessage()); - } finally { - item.lootLock.unlock(); - } - } + if (source == null || !source.isAlive()) + return; + //2 second cooldown on random rolls + long lastRandom = source.getTimeStamp("RandomRoll"); - } + if (System.currentTimeMillis() - lastRandom < 2000) + return; + source.setTimeStamp("RandomRoll", System.currentTimeMillis()); - //returns true if looted item is goldItem and is split. Otherwise returns false + //handle random roll + int max = msg.getMax(); - // called when player types /show - private static void show(ShowMsg msg, ClientConnection origin) throws MsgSendException { + if (max > 0) + msg.setRoll(ThreadLocalRandom.current().nextInt(max) + 1); + else if (max < 0) { + max = 1 - max; + msg.setRoll((ThreadLocalRandom.current().nextInt(max) - max) + 1); + } - PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); + msg.setSourceType(source.getObjectType().ordinal()); + msg.setSourceID(source.getObjectUUID()); - if (pc == null) - return; + //send to all in range + DispatchMessage.dispatchMsgToInterestArea(source, msg, DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, true); + } - int targetType = msg.getTargetType(); - AbstractCharacter tar = null; + //returns true if looted item is goldItem and is split. Otherwise returns false - if (targetType == GameObjectType.PlayerCharacter.ordinal()) - tar = PlayerCharacter.getFromCache(msg.getTargetID()); - else if (targetType == GameObjectType.NPC.ordinal()) - tar = NPC.getFromCache(msg.getTargetID()); - else if (targetType == GameObjectType.Mob.ordinal()) - tar = Mob.getFromCache(msg.getTargetID()); + private static void stuck(ClientConnection origin) { - if (tar == null || !tar.isAlive() || !tar.isActive()) - return; + PlayerCharacter sourcePlayer = origin.getPlayerCharacter(); - msg.setUnknown01(pc.getLoc()); - msg.setUnknown02(pc.getLoc()); - msg.setRange01(pc.getRange()); - msg.setUnknown03(tar.getLoc()); - msg.setUnknown04(tar.getLoc()); - msg.setRange01(tar.getRange()); + if (sourcePlayer == null) + return; - Dispatch dispatch = Dispatch.borrow(pc, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + if (sourcePlayer.getTimers().containsKey("Stuck")) + return; - } + StuckJob sj = new StuckJob(sourcePlayer); + JobContainer jc = JobScheduler.getInstance().scheduleJob(sj, 10000); // Convert + ConcurrentHashMap timers = sourcePlayer.getTimers(); - private static void ViewResourcesMessage(ViewResourcesMessage msg, ClientConnection origin) throws SQLException { + if (timers != null) { + if (timers.containsKey("Stuck")) { + timers.get("Stuck").cancelJob(); + timers.remove("Stuck"); + } + timers.put("Stuck", jc); + } + } - PlayerCharacter player = SessionManager.getPlayerCharacter(origin); + private static void GuildTreeStatusMsg(GuildTreeStatusMsg msg, ClientConnection origin) throws SQLException { - if (player == null) - return; + PlayerCharacter player = SessionManager.getPlayerCharacter(origin); + Dispatch dispatch; - Guild guild = player.getGuild(); - City city = guild.getOwnedCity(); + if (player == null) + return; - if (city == null) - return; + if (origin.guildtreespam > System.currentTimeMillis()) { + return; + } + origin.guildtreespam = System.currentTimeMillis() + 5000; - Building warehouse = BuildingManager.getBuilding(city.getWarehouseBuildingID()); + Building b = BuildingManager.getBuildingFromCache(msg.getTargetID()); + if (b == null) + return; - if (warehouse == null) - return; + GuildTreeStatusMsg gtsm = new GuildTreeStatusMsg(b, player); + gtsm.configure(); - ViewResourcesMessage vrm = new ViewResourcesMessage(player); - vrm.setWarehouseBuilding(warehouse); - vrm.setGuild(player.getGuild()); - vrm.configure(); + dispatch = Dispatch.borrow(player, gtsm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + } - Dispatch dispatch = Dispatch.borrow(player, vrm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + private static void openSellToNPCWindow(SellToNPCWindowMsg msg, ClientConnection origin) { - } + PlayerCharacter sourcePlayer = SessionManager.getPlayerCharacter(origin); + Dispatch dispatch; - private static void randomRoll(RandomMsg msg, ClientConnection origin) throws MsgSendException { + if (sourcePlayer == null) + return; - PlayerCharacter source = origin.getPlayerCharacter(); + NPC npc = NPC.getFromCache(msg.getNPCID()); - if (source == null || !source.isAlive()) - return; + if (npc == null) + return; - //2 second cooldown on random rolls - long lastRandom = source.getTimeStamp("RandomRoll"); + // test within talking range - if (System.currentTimeMillis() - lastRandom < 2000) - return; - source.setTimeStamp("RandomRoll", System.currentTimeMillis()); + if (sourcePlayer.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) { + ErrorPopupMsg.sendErrorPopup(sourcePlayer, 14); + return; + } - //handle random roll - int max = msg.getMax(); + Contract con = npc.getContract(); - if (max > 0) - msg.setRoll(ThreadLocalRandom.current().nextInt(max) + 1); - else if (max < 0) { - max = 1 - max; - msg.setRoll((ThreadLocalRandom.current().nextInt(max) - max) + 1); - } + if (con == null) + return; + float bargain = sourcePlayer.getBargain(); - msg.setSourceType(source.getObjectType().ordinal()); - msg.setSourceID(source.getObjectUUID()); + float profit = npc.getBuyPercent(sourcePlayer) + bargain; - //send to all in range - DispatchMessage.dispatchMsgToInterestArea(source, msg, DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, true); - } + if (profit > 1) + profit = 1; - private static void stuck(ClientConnection origin) { + msg.setupOutput(); - PlayerCharacter sourcePlayer = origin.getPlayerCharacter(); + msg.setUnknown05(profit); + msg.setUnknown06(500000); //TODO set goldItem on npc later + msg.setItemType(con.getBuyItemType()); + msg.setSkillTokens(con.getBuySkillToken()); + msg.setUnknownArray(con.getBuyUnknownToken()); - if (sourcePlayer == null) - return; + dispatch = Dispatch.borrow(sourcePlayer, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - if (sourcePlayer.getTimers().containsKey("Stuck")) - return; + } - StuckJob sj = new StuckJob(sourcePlayer); - JobContainer jc = JobScheduler.getInstance().scheduleJob(sj, 10000); // Convert - ConcurrentHashMap timers = sourcePlayer.getTimers(); + private static void sellToNPC(SellToNPCMsg msg, ClientConnection origin) { - if (timers != null) { - if (timers.containsKey("Stuck")) { - timers.get("Stuck").cancelJob(); - timers.remove("Stuck"); - } - timers.put("Stuck", jc); - } - } + PlayerCharacter player = SessionManager.getPlayerCharacter(origin); + Dispatch dispatch; - private static void GuildTreeStatusMsg(GuildTreeStatusMsg msg, ClientConnection origin) throws SQLException { + if (player == null) + return; - PlayerCharacter player = SessionManager.getPlayerCharacter(origin); - Dispatch dispatch; + CharacterItemManager itemMan = player.getCharItemManager(); - if (player == null) - return; + if (itemMan == null) + return; - if (origin.guildtreespam > System.currentTimeMillis()) { - return; - } - origin.guildtreespam = System.currentTimeMillis() + 5000; + NPC npc = NPC.getFromCache(msg.getNPCID()); - Building b = BuildingManager.getBuildingFromCache(msg.getTargetID()); - if (b == null) - return; + if (npc == null) + return; - GuildTreeStatusMsg gtsm = new GuildTreeStatusMsg(b, player); - gtsm.configure(); + Item gold = itemMan.getGoldInventory(); - dispatch = Dispatch.borrow(player, gtsm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } + if (gold == null) + return; + if (origin.sellLock.tryLock()) { + try { + Item sell; + int cost = 0; - private static void openSellToNPCWindow(SellToNPCWindowMsg msg, ClientConnection origin) { - PlayerCharacter sourcePlayer = SessionManager.getPlayerCharacter(origin); - Dispatch dispatch; + if (npc.getCharItemManager().getInventoryCount() > 150) { + if (npc.getParentZone() != null && npc.getParentZone().getPlayerCityUUID() == 0) { + ArrayList inv = npc.getInventory(); + for (int i = 0; i < 20; i++) { + try { + Item toRemove = inv.get(i); + if (toRemove != null) + npc.getCharItemManager().delete(toRemove); + } catch (Exception e) { + break; + } - if (sourcePlayer == null) - return; + } + } - NPC npc = NPC.getFromCache(msg.getNPCID()); + } - if (npc == null) - return; + // Early exit sanity check - // test within talking range + if (msg.getItemType() == GameObjectType.Item.ordinal() == false) + return; - if (sourcePlayer.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) { - ErrorPopupMsg.sendErrorPopup(sourcePlayer, 14); - return; - } + sell = Item.getFromCache(msg.getItemID()); - Contract con = npc.getContract(); + if (sell == null) + return; - if (con == null) - return; - float bargain = sourcePlayer.getBargain(); - - float profit = npc.getBuyPercent(sourcePlayer) + bargain; - - if (profit > 1) - profit = 1; - - msg.setupOutput(); + //get item to sell - msg.setUnknown05(profit); - msg.setUnknown06(500000); //TODO set goldItem on npc later - msg.setItemType(con.getBuyItemType()); - msg.setSkillTokens(con.getBuySkillToken()); - msg.setUnknownArray(con.getBuyUnknownToken()); + ItemBase ib = sell.getItemBase(); - dispatch = Dispatch.borrow(sourcePlayer, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + if (ib == null) + return; - } + if (npc.getParentZone() != null && npc.getParentZone().getPlayerCityUUID() != 0) + if (!npc.getCharItemManager().hasRoomInventory(ib.getWeight())) { - private static void sellToNPC(SellToNPCMsg msg, ClientConnection origin) { + ErrorPopupMsg.sendErrorPopup(player, 21); + return; + } - PlayerCharacter player = SessionManager.getPlayerCharacter(origin); - Dispatch dispatch; + if (!sell.validForInventory(origin, player, itemMan)) + return; - if (player == null) - return; + //get goldItem cost to sell - CharacterItemManager itemMan = player.getCharItemManager(); - if (itemMan == null) - return; + cost = sell.getBaseValue(); + float bargain = player.getBargain(); - NPC npc = NPC.getFromCache(msg.getNPCID()); + float profit = npc.getBuyPercent(player) + bargain; - if (npc == null) - return; + if (profit > 1) + profit = 1; - Item gold = itemMan.getGoldInventory(); - if (gold == null) - return; + cost *= profit; - if (origin.sellLock.tryLock()) { - try { - Item sell; - int cost = 0; + if (gold.getNumOfItems() + cost > 10000000) { + return; + } + if (gold.getNumOfItems() + cost < 0) + return; - if (npc.getCharItemManager().getInventoryCount() > 150) { - if (npc.getParentZone() != null && npc.getParentZone().getPlayerCityUUID() == 0) { - ArrayList inv = npc.getInventory(); - for (int i = 0; i < 20; i++) { - try { - Item toRemove = inv.get(i); - if (toRemove != null) - npc.getCharItemManager().delete(toRemove); - } catch (Exception e) { - break; - } + //TODO make sure npc can buy item type + //test room available for item on npc - } - } + // if (!npc.isStatic() && npc.getCharItemManager().getInventoryCount() > 150) { + // // chatMan.chatSystemInfo(pc, "This vendor's inventory is full"); + // return; + // } - } + //make sure item is in player inventory - // Early exit sanity check + Building building = (!npc.isStatic()) ? npc.getBuilding() : null; - if (msg.getItemType() == GameObjectType.Item.ordinal() == false) - return; + if (building != null && building.getProtectionState().equals(ProtectionState.NPC)) + building = null; + if (npc.getParentZone().getPlayerCityUUID() == 0) + building = null; - sell = Item.getFromCache(msg.getItemID()); + //make sure npc can afford item - if (sell == null) - return; + if (building != null && !building.hasFunds(cost)) { + ErrorPopupMsg.sendErrorPopup(player, 17); + return; + } + if (building != null && (building.getStrongboxValue() - cost) < 0) { + ErrorPopupMsg.sendErrorPopup(player, 17); + return; + } - //get item to sell + //TODO transfer item and goldItem transfer should be handled together incase failure + //transfer the item - ItemBase ib = sell.getItemBase(); + if (!itemMan.sellToNPC(sell, npc)) + return; - if (ib == null) - return; + if (!itemMan.sellToNPC(building, cost, sell)) + return; - if (npc.getParentZone() != null && npc.getParentZone().getPlayerCityUUID() != 0) - if (!npc.getCharItemManager().hasRoomInventory(ib.getWeight())){ + //handle goldItem transfer - ErrorPopupMsg.sendErrorPopup(player, 21); - return; - } + if (sell == null) + return; - if (!sell.validForInventory(origin, player, itemMan)) - return; + // ***REFACTOR: SellToNpc sends this message, is this a duplicate? - //get goldItem cost to sell - - - cost = sell.getBaseValue(); - float bargain = player.getBargain(); - - float profit = npc.getBuyPercent(player) + bargain; - - if (profit > 1) - profit = 1; - - - - cost *= profit; + //update player's goldItem count + UpdateGoldMsg ugm = new UpdateGoldMsg(player); + ugm.configure(); - if (gold.getNumOfItems() + cost > 10000000) { - return; - } + dispatch = Dispatch.borrow(player, ugm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - if (gold.getNumOfItems() + cost < 0) - return; + //send the sell message back to update player + msg.setItemType(sell.getObjectType().ordinal()); + msg.setItemID(sell.getObjectUUID()); + msg.setUnknown01(cost); //not sure if this is correct - //TODO make sure npc can buy item type - //test room available for item on npc + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - // if (!npc.isStatic() && npc.getCharItemManager().getInventoryCount() > 150) { - // // chatMan.chatSystemInfo(pc, "This vendor's inventory is full"); - // return; - // } + } finally { + origin.sellLock.unlock(); + } + } else { + ErrorPopupMsg.sendErrorPopup(player, 12); + } + } - //make sure item is in player inventory + private static void openBuyFromNPCWindow(BuyFromNPCWindowMsg msg, ClientConnection origin) { - Building building = (!npc.isStatic()) ? npc.getBuilding() : null; + PlayerCharacter sourcePlayer = SessionManager.getPlayerCharacter(origin); + Dispatch dispatch; - if (building != null && building.getProtectionState().equals(ProtectionState.NPC)) - building = null; - if (npc.getParentZone().getPlayerCityUUID() == 0) - building = null; + if (sourcePlayer == null) + return; - //make sure npc can afford item + NPC npc = NPC.getFromCache(msg.getNpcID()); - if (building != null && !building.hasFunds(cost)){ - ErrorPopupMsg.sendErrorPopup(player, 17); - return; - } - if (building != null && (building.getStrongboxValue() - cost) < 0){ - ErrorPopupMsg.sendErrorPopup(player, 17); - return; - } + if (npc == null) + return; - //TODO transfer item and goldItem transfer should be handled together incase failure - //transfer the item + // test within talking range - if (!itemMan.sellToNPC(sell, npc)) - return; + if (sourcePlayer.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) { + ErrorPopupMsg.sendErrorPopup(sourcePlayer, 14); + return; + } - if (!itemMan.sellToNPC(building, cost, sell)) - return; + dispatch = Dispatch.borrow(sourcePlayer, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + } - //handle goldItem transfer + private static void buyFromNPC(BuyFromNPCMsg msg, ClientConnection origin) { - if (sell == null) - return; + PlayerCharacter sourcePlayer = SessionManager.getPlayerCharacter(origin); - // ***REFACTOR: SellToNpc sends this message, is this a duplicate? + if (sourcePlayer == null) + return; - //update player's goldItem count - UpdateGoldMsg ugm = new UpdateGoldMsg(player); - ugm.configure(); + if (origin.buyLock.tryLock()) { - dispatch = Dispatch.borrow(player, ugm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + try { + CharacterItemManager itemMan = sourcePlayer.getCharItemManager(); - //send the sell message back to update player - msg.setItemType(sell.getObjectType().ordinal()); - msg.setItemID(sell.getObjectUUID()); - msg.setUnknown01(cost); //not sure if this is correct + if (itemMan == null) + return; - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + NPC npc = NPC.getFromCache(msg.getNPCID()); - } finally { - origin.sellLock.unlock(); - } - } - else { - ErrorPopupMsg.sendErrorPopup(player, 12); - } - } - - private static void openBuyFromNPCWindow(BuyFromNPCWindowMsg msg, ClientConnection origin) { - - PlayerCharacter sourcePlayer = SessionManager.getPlayerCharacter(origin); - Dispatch dispatch; - - if (sourcePlayer == null) - return; - - NPC npc = NPC.getFromCache(msg.getNpcID()); - - if (npc == null) - return; - - // test within talking range - - if (sourcePlayer.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) { - ErrorPopupMsg.sendErrorPopup(sourcePlayer, 14); - return; - } + if (npc == null) + return; - dispatch = Dispatch.borrow(sourcePlayer, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } + Item gold = itemMan.getGoldInventory(); - private static void buyFromNPC(BuyFromNPCMsg msg, ClientConnection origin) { + if (gold == null) + return; - PlayerCharacter sourcePlayer = SessionManager.getPlayerCharacter(origin); + Item buy = null; - if (sourcePlayer == null) - return; + if (msg.getItemType() == GameObjectType.MobEquipment.ordinal()) { + ArrayList sellInventory = npc.getContract().getSellInventory(); + if (sellInventory == null) + return; + for (MobEquipment me : sellInventory) { + if (me.getObjectUUID() == msg.getItemID()) { + ItemBase ib = me.getItemBase(); + if (ib == null) + return; - if (origin.buyLock.tryLock()) { + //test room available for item + if (!itemMan.hasRoomInventory(ib.getWeight())) + return; - try { - CharacterItemManager itemMan = sourcePlayer.getCharItemManager(); + int cost = me.getMagicValue(); - if (itemMan == null) - return; + float bargain = sourcePlayer.getBargain(); - NPC npc = NPC.getFromCache(msg.getNPCID()); + float profit = npc.getSellPercent(sourcePlayer) - bargain; - if (npc == null) - return; + if (profit < 1) + profit = 1; - Item gold = itemMan.getGoldInventory(); - if (gold == null) - return; + cost *= profit; - Item buy = null; - - if (msg.getItemType() == GameObjectType.MobEquipment.ordinal()) { - ArrayList sellInventory = npc.getContract().getSellInventory(); - if (sellInventory == null) - return; - for (MobEquipment me : sellInventory) { - if (me.getObjectUUID() == msg.getItemID()) { - ItemBase ib = me.getItemBase(); - if (ib == null) - return; - - //test room available for item - if (!itemMan.hasRoomInventory(ib.getWeight())) - return; - - int cost = me.getMagicValue(); - - float bargain = sourcePlayer.getBargain(); - - float profit = npc.getSellPercent(sourcePlayer) - bargain; - - if (profit < 1) - profit = 1; - - - cost *= profit; - - - - - - - if (gold.getNumOfItems() - cost < 0) { - //dont' have enough goldItem exit! - // chatMan.chatSystemInfo(pc, "" + "You dont have enough gold."); - return; - } - - Building b = (!npc.isStatic()) ? npc.getBuilding() : null; - - if (b != null && b.getProtectionState().equals(ProtectionState.NPC)) - b = null; - int buildingDeposit = cost - me.getMagicValue(); - if (b != null && (b.getStrongboxValue() + buildingDeposit) > b.getMaxGold()) { - ErrorPopupMsg.sendErrorPopup(sourcePlayer, 206); - return; - } - - if (!itemMan.buyFromNPC(b, cost, buildingDeposit)) { - // chatMan.chatSystemInfo(pc, "" + "You Failed to buy the item."); - return; - } - - buy = Item.createItemForPlayer(sourcePlayer, ib); - - if (buy != null) { - me.transferEnchants(buy); - itemMan.addItemToInventory(buy); - //itemMan.updateInventory(); - } - } - } - } - else if (msg.getItemType() == GameObjectType.Item.ordinal()) { - - CharacterItemManager npcCim = npc.getCharItemManager(); - - if (npcCim == null) - return; - - buy = Item.getFromCache(msg.getItemID()); - - if (buy == null) - return; - - ItemBase ib = buy.getItemBase(); - - if (ib == null) - return; - - if (!npcCim.inventoryContains(buy)) - return; - - //test room available for item - if (!itemMan.hasRoomInventory(ib.getWeight())) - return; - - //TODO test cost and subtract goldItem - - //TODO CHnage this if we ever put NPc city npcs in buildings. - int cost = buy.getBaseValue(); - - if (buy.isID() || buy.isCustomValue()) - cost = buy.getMagicValue(); - - float bargain = sourcePlayer.getBargain(); - - float profit = npc.getSellPercent(sourcePlayer) - bargain; - - if (profit < 1) - profit = 1; - - if (!buy.isCustomValue()) - cost *= profit; - else - cost = buy.getValue(); - - - - if (gold.getNumOfItems() - cost < 0) { - ErrorPopupMsg.sendErrorPopup(sourcePlayer, 128); // Insufficient Gold - return; - } - - Building b = (!npc.isStatic()) ? npc.getBuilding() : null; - - if (b != null) - if (b.getProtectionState().equals(ProtectionState.NPC)) - b = null; - - int buildingDeposit = cost; - - if (b != null && (b.getStrongboxValue() + buildingDeposit) > b.getMaxGold()) { - ErrorPopupMsg.sendErrorPopup(sourcePlayer, 206); - return; - } - - if (!itemMan.buyFromNPC(b, cost, buildingDeposit)) { - ErrorPopupMsg.sendErrorPopup(sourcePlayer, 110); - return; - } - - if (buy != null) - itemMan.buyFromNPC(buy, npc); - - }else if (msg.getItemType() == GameObjectType.MobLoot.ordinal()) { - - CharacterItemManager npcCim = npc.getCharItemManager(); - - if (npcCim == null) - return; - - buy = MobLoot.getFromCache(msg.getItemID()); - if (buy == null) - return; + if (gold.getNumOfItems() - cost < 0) { + //dont' have enough goldItem exit! + // chatMan.chatSystemInfo(pc, "" + "You dont have enough gold."); + return; + } - ItemBase ib = buy.getItemBase(); + Building b = (!npc.isStatic()) ? npc.getBuilding() : null; - if (ib == null) - return; + if (b != null && b.getProtectionState().equals(ProtectionState.NPC)) + b = null; + int buildingDeposit = cost - me.getMagicValue(); + if (b != null && (b.getStrongboxValue() + buildingDeposit) > b.getMaxGold()) { + ErrorPopupMsg.sendErrorPopup(sourcePlayer, 206); + return; + } - if (!npcCim.inventoryContains(buy)) - return; + if (!itemMan.buyFromNPC(b, cost, buildingDeposit)) { + // chatMan.chatSystemInfo(pc, "" + "You Failed to buy the item."); + return; + } - //test room available for item - if (!itemMan.hasRoomInventory(ib.getWeight())) - return; + buy = Item.createItemForPlayer(sourcePlayer, ib); - //TODO test cost and subtract goldItem + if (buy != null) { + me.transferEnchants(buy); + itemMan.addItemToInventory(buy); + //itemMan.updateInventory(); + } + } + } + } else if (msg.getItemType() == GameObjectType.Item.ordinal()) { - //TODO CHnage this if we ever put NPc city npcs in buildings. + CharacterItemManager npcCim = npc.getCharItemManager(); - int cost = buy.getMagicValue(); - cost *= npc.getSellPercent(sourcePlayer); - + if (npcCim == null) + return; - if (gold.getNumOfItems() - cost < 0) { - ErrorPopupMsg.sendErrorPopup(sourcePlayer, 128); // Insufficient Gold - return; - } + buy = Item.getFromCache(msg.getItemID()); - Building b = (!npc.isStatic()) ? npc.getBuilding() : null; - - if (b != null && b.getProtectionState().equals(ProtectionState.NPC)) - b = null; - int buildingDeposit = cost; - - if (b != null && (b.getStrongboxValue() + buildingDeposit) > b.getMaxGold()) { - ErrorPopupMsg.sendErrorPopup(sourcePlayer, 206); - return; - } - - if (!itemMan.buyFromNPC(b, cost, buildingDeposit)) - return; - - if (buy != null) - itemMan.buyFromNPC(buy, npc); - - } - else - return; - - if (buy != null) { - - msg.setItem(buy); - //send the buy message back to update player - // msg.setItemType(buy.getObjectType().ordinal()); - // msg.setItemID(buy.getObjectUUID()); - Dispatch dispatch = Dispatch.borrow(sourcePlayer, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - itemMan.updateInventory(); - } - - } finally { - origin.buyLock.unlock(); - } - } - else { - ErrorPopupMsg.sendErrorPopup(origin.getPlayerCharacter(), 12); // All production slots taken - } - - } - - //Handle RepairObject Window and RepairObject Requests - - private static void Repair(RepairMsg msg, ClientConnection origin) { - - PlayerCharacter player = SessionManager.getPlayerCharacter(origin); - Dispatch dispatch; - - if (player == null) - return; - - NPC npc = NPC.getFromCache(msg.getNPCID()); + if (buy == null) + return; - if (npc == null) - return; + ItemBase ib = buy.getItemBase(); - if (msg.getMsgType() == 1) { //Open RepairObject Window + if (ib == null) + return; - if (player.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) { - ErrorPopupMsg.sendErrorPopup(player, 14); - return; - } + if (!npcCim.inventoryContains(buy)) + return; - //send open repair window response - msg.setRepairWindowAck(npc); - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + //test room available for item + if (!itemMan.hasRoomInventory(ib.getWeight())) + return; - } - else if (msg.getMsgType() == 0) { //Request RepairObject - - CharacterItemManager itemMan = player.getCharItemManager(); - - if (itemMan == null) - return; - - Item gold = itemMan.getGoldInventory(); - - if (gold == null) - return; - - Item toRepair = Item.getFromCache(msg.getItemID()); - - if (toRepair == null) - return; - - if (toRepair.getItemBase().isGlass()) - return; - - //make sure item is in player's inventory or equipment - if (!itemMan.inventoryContains(toRepair) && !itemMan.equippedContains(toRepair)) - return; - - //make sure item is damaged and not destroyed - short dur = toRepair.getDurabilityCurrent(); - short max = toRepair.getDurabilityMax(); - //account for durability modifications - float durMod = toRepair.getBonusPercent(ModType.Durability,SourceType.None); - max *= (1 + (durMod * 0.01f)); - if (dur >= max || dur < 1) { - //redundancy message to clear item from window in client - toRepair.setDurabilityCurrent(max); - msg.setupRepairAck(max - dur); - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return; - } - //TODO get cost to repair - int cost = (int) ((max - dur) * 80.1); - Building b = (!npc.isStatic()) ? npc.getBuilding() : null; - - if (b != null) - if (b.getProtectionState().equals(ProtectionState.NPC)) - b = null; - + //TODO test cost and subtract goldItem - if (b != null && (b.getStrongboxValue() + cost) > b.getMaxGold()) { - ErrorPopupMsg.sendErrorPopup(player, 206); - return; - } - - if (player.getCharItemManager().getGoldInventory().getNumOfItems() - cost < 0) - return; - - if (player.getCharItemManager().getGoldInventory().getNumOfItems() - cost > MBServerStatics.PLAYER_GOLD_LIMIT) - return; + //TODO CHnage this if we ever put NPc city npcs in buildings. + int cost = buy.getBaseValue(); - if (!itemMan.buyFromNPC(b, cost, cost)) { - ErrorPopupMsg.sendErrorPopup(player, 128); - return; - } + if (buy.isID() || buy.isCustomValue()) + cost = buy.getMagicValue(); - //update player's goldItem count - UpdateGoldMsg ugm = new UpdateGoldMsg(player); - ugm.configure(); - dispatch = Dispatch.borrow(player, ugm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - //update durability to database - if (!DbManager.ItemQueries.SET_DURABILITY(toRepair, max)) - return; - //repair the item - toRepair.setDurabilityCurrent(max); - //send repair msg - msg.setupRepairAck(max - dur); - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } - } - - protected static void petAttack(PetAttackMsg msg, ClientConnection conn) throws MsgSendException { + float bargain = sourcePlayer.getBargain(); - PlayerCharacter pc = SessionManager.getPlayerCharacter(conn); - - if (pc == null) - return; - - Mob pet = pc.getPet(); - - if (pet == null) - return; - - if (!pet.isAlive()) - return; - - if ((pc.inSafeZone()) - && (msg.getTargetType() == GameObjectType.PlayerCharacter.ordinal())) - return; - - CombatManager.setAttackTarget(msg, conn); - if (pet.getCombatTarget() == null) - return; - } - - protected static void petCmd(PetCmdMsg msg, ClientConnection conn) throws MsgSendException { - - PlayerCharacter pc = SessionManager.getPlayerCharacter(conn); - - if (pc == null) - return; - - Mob pet = pc.getPet(); - - if (pet == null) - return; - - if (!pet.isAlive()) - return; + float profit = npc.getSellPercent(sourcePlayer) - bargain; + + if (profit < 1) + profit = 1; + + if (!buy.isCustomValue()) + cost *= profit; + else + cost = buy.getValue(); + + + if (gold.getNumOfItems() - cost < 0) { + ErrorPopupMsg.sendErrorPopup(sourcePlayer, 128); // Insufficient Gold + return; + } + + Building b = (!npc.isStatic()) ? npc.getBuilding() : null; + + if (b != null) + if (b.getProtectionState().equals(ProtectionState.NPC)) + b = null; + + int buildingDeposit = cost; + + if (b != null && (b.getStrongboxValue() + buildingDeposit) > b.getMaxGold()) { + ErrorPopupMsg.sendErrorPopup(sourcePlayer, 206); + return; + } + + if (!itemMan.buyFromNPC(b, cost, buildingDeposit)) { + ErrorPopupMsg.sendErrorPopup(sourcePlayer, 110); + return; + } + + if (buy != null) + itemMan.buyFromNPC(buy, npc); + + } else if (msg.getItemType() == GameObjectType.MobLoot.ordinal()) { + + CharacterItemManager npcCim = npc.getCharItemManager(); + + if (npcCim == null) + return; + + buy = MobLoot.getFromCache(msg.getItemID()); + + if (buy == null) + return; + + ItemBase ib = buy.getItemBase(); + + if (ib == null) + return; + + if (!npcCim.inventoryContains(buy)) + return; + + //test room available for item + if (!itemMan.hasRoomInventory(ib.getWeight())) + return; + + //TODO test cost and subtract goldItem + + //TODO CHnage this if we ever put NPc city npcs in buildings. + + int cost = buy.getMagicValue(); + cost *= npc.getSellPercent(sourcePlayer); + + + if (gold.getNumOfItems() - cost < 0) { + ErrorPopupMsg.sendErrorPopup(sourcePlayer, 128); // Insufficient Gold + return; + } + + Building b = (!npc.isStatic()) ? npc.getBuilding() : null; + + if (b != null && b.getProtectionState().equals(ProtectionState.NPC)) + b = null; + int buildingDeposit = cost; + + if (b != null && (b.getStrongboxValue() + buildingDeposit) > b.getMaxGold()) { + ErrorPopupMsg.sendErrorPopup(sourcePlayer, 206); + return; + } + + if (!itemMan.buyFromNPC(b, cost, buildingDeposit)) + return; + + if (buy != null) + itemMan.buyFromNPC(buy, npc); + + } else + return; + + if (buy != null) { + + msg.setItem(buy); + //send the buy message back to update player + // msg.setItemType(buy.getObjectType().ordinal()); + // msg.setItemID(buy.getObjectUUID()); + Dispatch dispatch = Dispatch.borrow(sourcePlayer, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + itemMan.updateInventory(); + } + + } finally { + origin.buyLock.unlock(); + } + } else { + ErrorPopupMsg.sendErrorPopup(origin.getPlayerCharacter(), 12); // All production slots taken + } + + } + + private static void Repair(RepairMsg msg, ClientConnection origin) { + + PlayerCharacter player = SessionManager.getPlayerCharacter(origin); + Dispatch dispatch; + + if (player == null) + return; + + NPC npc = NPC.getFromCache(msg.getNPCID()); + + if (npc == null) + return; + + if (msg.getMsgType() == 1) { //Open RepairObject Window + + if (player.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) { + ErrorPopupMsg.sendErrorPopup(player, 14); + return; + } + + //send open repair window response + msg.setRepairWindowAck(npc); + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + } else if (msg.getMsgType() == 0) { //Request RepairObject + + CharacterItemManager itemMan = player.getCharItemManager(); + + if (itemMan == null) + return; + + Item gold = itemMan.getGoldInventory(); + + if (gold == null) + return; + + Item toRepair = Item.getFromCache(msg.getItemID()); + + if (toRepair == null) + return; + + if (toRepair.getItemBase().isGlass()) + return; + + //make sure item is in player's inventory or equipment + if (!itemMan.inventoryContains(toRepair) && !itemMan.equippedContains(toRepair)) + return; + + //make sure item is damaged and not destroyed + short dur = toRepair.getDurabilityCurrent(); + short max = toRepair.getDurabilityMax(); + //account for durability modifications + float durMod = toRepair.getBonusPercent(ModType.Durability, SourceType.None); + max *= (1 + (durMod * 0.01f)); + if (dur >= max || dur < 1) { + //redundancy message to clear item from window in client + toRepair.setDurabilityCurrent(max); + msg.setupRepairAck(max - dur); + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return; + } + //TODO get cost to repair + int cost = (int) ((max - dur) * 80.1); + Building b = (!npc.isStatic()) ? npc.getBuilding() : null; + + if (b != null) + if (b.getProtectionState().equals(ProtectionState.NPC)) + b = null; + + + if (b != null && (b.getStrongboxValue() + cost) > b.getMaxGold()) { + ErrorPopupMsg.sendErrorPopup(player, 206); + return; + } + + if (player.getCharItemManager().getGoldInventory().getNumOfItems() - cost < 0) + return; + + if (player.getCharItemManager().getGoldInventory().getNumOfItems() - cost > MBServerStatics.PLAYER_GOLD_LIMIT) + return; + + if (!itemMan.buyFromNPC(b, cost, cost)) { + ErrorPopupMsg.sendErrorPopup(player, 128); + return; + } + + //update player's goldItem count + UpdateGoldMsg ugm = new UpdateGoldMsg(player); + ugm.configure(); + dispatch = Dispatch.borrow(player, ugm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + //update durability to database + if (!DbManager.ItemQueries.SET_DURABILITY(toRepair, max)) + return; + //repair the item + toRepair.setDurabilityCurrent(max); + //send repair msg + msg.setupRepairAck(max - dur); + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + } + } + + protected static void petAttack(PetAttackMsg msg, ClientConnection conn) throws MsgSendException { + + PlayerCharacter pc = SessionManager.getPlayerCharacter(conn); + + if (pc == null) + return; + + Mob pet = pc.getPet(); + + if (pet == null) + return; + + if (!pet.isAlive()) + return; + + if ((pc.inSafeZone()) + && (msg.getTargetType() == GameObjectType.PlayerCharacter.ordinal())) + return; + + CombatManager.setAttackTarget(msg, conn); + if (pet.getCombatTarget() == null) + return; + } + + protected static void petCmd(PetCmdMsg msg, ClientConnection conn) throws MsgSendException { + + PlayerCharacter pc = SessionManager.getPlayerCharacter(conn); + + if (pc == null) + return; + + Mob pet = pc.getPet(); + + if (pet == null) + return; + + if (!pet.isAlive()) + return; //if (pet.state == STATE.Disabled) - // return; - - int type = msg.getType(); - - if (type == 1) { //stop attack - pet.setCombatTarget(null); - pc.setCombat(false); - - } - else if (type == 2) { //dismiss - pet.dismiss(); - pc.dismissPet(); - - if (pet.isAlive()) - WorldGrid.updateObject(pet); - } - else if (type == 3) //toggle assist - pet.toggleAssist(); - else if (type == 5) { //rest - boolean sit = (!(pet.isSit())); - pet.setSit(sit); - - // cancel effects that break on sit - if (pet.isSit()) - pet.cancelOnSit(); - - UpdateStateMsg rwss = new UpdateStateMsg(); - rwss.setPlayer(pet); - DispatchMessage.sendToAllInRange(pet, rwss); - } - } - - protected static void HandlePromptRecall(PromptRecallMsg msg, ClientConnection origin) throws MsgSendException { - - PlayerCharacter player = SessionManager.getPlayerCharacter(origin); - boolean recallAccepted; - - if (player == null) - return; - - boolean confirmed = msg.getConfirmed(); - - if (confirmed == true) { - long timeElapsed = System.currentTimeMillis() - player.getTimeStamp("PromptRecall"); - //send fail message - recallAccepted = timeElapsed < 15000; - } - else - recallAccepted = false; - - if (recallAccepted == true) { - //handle recall - long type = player.getTimeStamp("LastRecallType"); - - if (type == 1) { //recall to bind - player.teleport(player.getBindLoc()); - player.setSafeMode(); - } - else { //recall to rg - float dist = 9999999999f; - Building rg = null; - Vector3fImmutable rgLoc; - - for (Runegate runegate : Runegate._runegates.values()) { - - rgLoc = runegate.gateBuilding.getLoc(); - - float distanceSquaredToRunegate = player.getLoc().distanceSquared2D(rgLoc); - - if (distanceSquaredToRunegate < sqr(dist)) - rg = runegate.gateBuilding; - - } - - //nearest runegate found. teleport characterTarget - - if (rg != null) { - player.teleport(rg.getLoc()); - player.setSafeMode(); - } - } - } - } + // return; + + int type = msg.getType(); + + if (type == 1) { //stop attack + pet.setCombatTarget(null); + pc.setCombat(false); + + } else if (type == 2) { //dismiss + pet.dismiss(); + pc.dismissPet(); + + if (pet.isAlive()) + WorldGrid.updateObject(pet); + } else if (type == 3) //toggle assist + pet.toggleAssist(); + else if (type == 5) { //rest + boolean sit = (!(pet.isSit())); + pet.setSit(sit); + + // cancel effects that break on sit + if (pet.isSit()) + pet.cancelOnSit(); + + UpdateStateMsg rwss = new UpdateStateMsg(); + rwss.setPlayer(pet); + DispatchMessage.sendToAllInRange(pet, rwss); + } + } + + //Handle RepairObject Window and RepairObject Requests + + protected static void HandlePromptRecall(PromptRecallMsg msg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter player = SessionManager.getPlayerCharacter(origin); + boolean recallAccepted; + + if (player == null) + return; + + boolean confirmed = msg.getConfirmed(); + + if (confirmed == true) { + long timeElapsed = System.currentTimeMillis() - player.getTimeStamp("PromptRecall"); + //send fail message + recallAccepted = timeElapsed < 15000; + } else + recallAccepted = false; + + if (recallAccepted == true) { + //handle recall + long type = player.getTimeStamp("LastRecallType"); + + if (type == 1) { //recall to bind + player.teleport(player.getBindLoc()); + player.setSafeMode(); + } else { //recall to rg + float dist = 9999999999f; + Building rg = null; + Vector3fImmutable rgLoc; + + for (Runegate runegate : Runegate._runegates.values()) { + + rgLoc = runegate.gateBuilding.getLoc(); + + float distanceSquaredToRunegate = player.getLoc().distanceSquared2D(rgLoc); + + if (distanceSquaredToRunegate < sqr(dist)) + rg = runegate.gateBuilding; + + } + + //nearest runegate found. teleport characterTarget + + if (rg != null) { + player.teleport(rg.getLoc()); + player.setSafeMode(); + } + } + } + } + + @Override + public boolean handleClientMsg(ClientNetMsg msg) { + + if (msg == null) { + Logger.error("handleClientMsg", "Recieved null msg. Returning."); + return false; + } + + ClientConnection origin; + Protocol protocolMsg = Protocol.NONE; + Session s; + + try { + + // Try registered opcodes first as we take a hatchet to this GodObject + + AbstractClientMsgHandler msgHandler = msg.getProtocolMsg().handler; + + if (msgHandler != null) + return msgHandler.handleNetMsg(msg); + + // Any remaining opcodes fall through and are routed + // through this ungodly switch of doom. + + origin = (ClientConnection) msg.getOrigin(); + s = SessionManager.getSession(origin); + + protocolMsg = msg.getProtocolMsg(); + + switch (protocolMsg) { + case SETSELECTEDOBECT: + ClientMessagePump.targetObject((TargetObjectMsg) msg, origin); + break; + + /* + * Chat + */ + + // Simplify by fall through. Route in ChatManager + case CHATSAY: + case CHATSHOUT: + case CHATTELL: + case CHATGUILD: + case CHATGROUP: + case CHATPVP: + case CHATIC: + case CHATCITY: + case CHATINFO: + case SYSTEMBROADCASTCHANNEL: + case CHATCSR: + case SYSTEMCHANNEL: + case GLOBALCHANNELMESSAGE: + case LEADERCHANNELMESSAGE: + ChatManager.handleChatMsg(s, (AbstractChatMsg) msg); + break; + case UPDATESTATE: + UpdateStateMsg rwss = (UpdateStateMsg) msg; + runWalkSitStand(rwss, origin); + break; + case ACTIVATECHARTER: + UseCharterMsg ucm = (UseCharterMsg) msg; + ucm.setUnknown02(1); + ucm.configure(); + Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), ucm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + break; + case CHECKUNIQUEGUILD: + break; + case CREATEPETITION: + break; + case CANCELGUILDCREATION: + break; + case LEAVEREQUEST: + origin.disconnect(); + break; + case POWER: + PowersManager.usePower((PerformActionMsg) msg, origin, false); + break; + case REQUESTMELEEATTACK: + CombatManager.setAttackTarget((AttackCmdMsg) msg, origin); + break; + case READYTOENTER: + break; + case OPENVAULT: + break; + case WHOREQUEST: + WhoRequest((WhoRequestMsg) msg, origin); + break; + case CLIENTADMINCOMMAND: + ChatManager.HandleClientAdminCmd((ClientAdminCommandMsg) msg, origin); + break; + case SOCIALCHANNEL: + social((SocialMsg) msg, origin); + break; + case COMBATMODE: + CombatManager.toggleCombat((ToggleCombatMsg) msg, origin); + break; + case ARCCOMBATMODEATTACKING: + CombatManager.toggleCombat((SetCombatModeMsg) msg, origin); + break; + case MODIFYGUILDSTATE: + ToggleLfgRecruitingMsg tlrm = (ToggleLfgRecruitingMsg) msg; + toggleLfgRecruiting(tlrm, origin); + break; + case TOGGLESITSTAND: + ToggleSitStandMsg tssm = (ToggleSitStandMsg) msg; + toggleSitStand(tssm, origin); + break; + case GUILDTREESTATUS: + GuildTreeStatusMsg((GuildTreeStatusMsg) msg, origin); + break; + case CUSTOMERPETITION: + Logger.info("CCR Petition received: " + msg.toString()); + // TODO need to send something back to client + // TODO what to do with petition? + break; + case IGNORE: + ((IgnoreMsg) msg).handleRequest(origin); + break; + case UNEQUIP: + TransferItemFromEquipToInventory((TransferItemFromEquipToInventoryMsg) msg, origin); + break; + case EQUIP: + TransferItemFromInventoryToEquip((TransferItemFromInventoryToEquipMsg) msg, origin); + break; + case DELETEOBJECT: + DeleteItem((DeleteItemMsg) msg, origin); + break; + case VIEWRESOURCES: + ViewResourcesMessage((ViewResourcesMessage) msg, origin); + break; + case RAISEATTR: + modifyStat((ModifyStatMsg) msg, origin); + break; + case COSTTOOPENBANK: + ackBankWindowOpened((AckBankWindowOpenedMsg) msg, origin); + break; + case RESETAFTERDEATH: + respawn((RespawnMsg) msg, origin); + break; + case REQUESTCONTENTS: + lootWindowRequest((LootWindowRequestMsg) msg, origin); + break; + case MOVEOBJECTTOCONTAINER: + loot((LootMsg) msg, origin); + break; + case SHOWCOMBATINFO: + show((ShowMsg) msg, origin); + break; + case TRANSFERITEMTOBANK: + transferItemFromInventoryToBank((TransferItemFromInventoryToBankMsg) msg, origin); + break; + case TRANSFERITEMFROMBANK: + transferItemFromBankToInventory((TransferItemFromBankToInventoryMsg) msg, origin); + break; + case TRANSFERITEMFROMVAULTTOINVENTORY: + transferItemFromVaultToInventory((TransferItemFromVaultToInventoryMsg) msg, origin); + break; + case ITEMTOVAULT: + transferItemFromInventoryToVault((TransferItemFromInventoryToVaultMsg) msg, origin); + break; + case TRANSFERGOLDFROMVAULTTOINVENTORY: + transferGoldFromVaultToInventory((TransferGoldFromVaultToInventoryMsg) msg, origin); + break; + case GOLDTOVAULT: + transferGoldFromInventoryToVault((TransferGoldFromInventoryToVaultMsg) msg, origin); + break; + case REQUESTTOTRADE: + TradeManager.tradeRequest((TradeRequestMsg) msg, origin); + break; + case REQUESTTRADEOK: + TradeManager.acceptTradeRequest((AcceptTradeRequestMsg) msg, origin); + break; + case REQUESTTRADECANCEL: + TradeManager.rejectTradeRequest((RejectTradeRequestMsg) msg, origin); + break; + case TRADEADDOBJECT: + TradeManager.addItemToTradeWindow((AddItemToTradeWindowMsg) msg, origin); + break; + case TRADEADDGOLD: + TradeManager.addGoldToTradeWindow((AddGoldToTradeWindowMsg) msg, origin); + break; + case TRADECONFIRM: + TradeManager.commitToTrade((CommitToTradeMsg) msg, origin); + break; + case TRADEUNCONFIRM: + TradeManager.uncommitToTrade((UncommitToTradeMsg) msg, origin); + break; + case TRADECLOSE: + TradeManager.closeTradeWindow((CloseTradeWindowMsg) msg, origin); + break; + case ARCREQUESTTRADEBUSY: + TradeManager.invalidTradeRequest((InvalidTradeRequestMsg) msg); + break; + case VENDORDIALOG: + VendorDialogMsg.replyDialog((VendorDialogMsg) msg, origin); + break; + case SHOPLIST: + openBuyFromNPCWindow((BuyFromNPCWindowMsg) msg, origin); + break; + case BUYFROMNPC: + buyFromNPC((BuyFromNPCMsg) msg, origin); + break; + case SHOPINFO: + openSellToNPCWindow((SellToNPCWindowMsg) msg, origin); + break; + case SELLOBJECT: + sellToNPC((SellToNPCMsg) msg, origin); + break; + case REPAIROBJECT: + Repair((RepairMsg) msg, origin); + break; + case TRAINERLIST: + WorldServer.trainerInfo((TrainerInfoMsg) msg, origin); + break; + case ARCUNTRAINLIST: + WorldServer.refinerScreen((RefinerScreenMsg) msg, origin); + break; + case TRAINSKILL: + TrainMsg.train((TrainMsg) msg, origin); + break; + case ARCUNTRAINABILITY: + RefineMsg.refine((RefineMsg) msg, origin); + break; + case POWERTARGNAME: + PowersManager.summon((SendSummonsRequestMsg) msg, origin); + break; + case ARCSUMMON: + PowersManager.recvSummon((RecvSummonsRequestMsg) msg, origin); + break; + case ARCTRACKINGLIST: + PowersManager.trackWindow((TrackWindowMsg) msg, origin); + break; + case STUCK: + stuck(origin); + break; + case RANDOM: + ClientMessagePump.randomRoll((RandomMsg) msg, origin); + break; + case ARCPETATTACK: + petAttack((PetAttackMsg) msg, origin); + break; + case ARCPETCMD: + petCmd((PetCmdMsg) msg, origin); + break; + case MANAGENPC: + ManageNPCCmd((ManageNPCMsg) msg, origin); + break; + case ARCPROMPTRECALL: + HandlePromptRecall((PromptRecallMsg) msg, origin); + break; + case CHANNELMUTE: + break; + case KEEPALIVESERVERCLIENT: + break; + case UNKNOWN: + break; + + case CONFIRMPROMOTE: + break; + + default: + String ocHex = StringUtils.toHexString(protocolMsg.opcode); + Logger.error("Cannot handle Opcode: " + ocHex + " " + protocolMsg.name()); + return false; + + } + + } catch (MsgSendException | SQLException e) { + Logger.error("handler for " + protocolMsg + " failed: " + e); + return false; + } + + return true; + } + + //TODO what is this used for? + private void ManageNPCCmd(ManageNPCMsg msg, ClientConnection origin) { + + } + + //call this if the transfer fails server side to kick the item back to inventory from equip + private void forceTransferFromInventoryToEquip(TransferItemFromEquipToInventoryMsg msg, ClientConnection origin, String reason) { + //TODO add this later + //PATCHED CODEZZ + } } diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 19cc0e4e..700d55b2 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -252,9 +252,10 @@ public enum Protocol { UNKNOWN1(-263523523, Unknown1Msg.class, null), DROPGOLD(1461654160, DropGoldMsg.class, null); - public int opcode; + private static final HashMap _protocolMsgByOpcode = new HashMap<>(); private final Class message; private final Class handlerClass; + public int opcode; public Constructor constructor; public AbstractClientMsgHandler handler; @@ -286,8 +287,6 @@ public enum Protocol { } } - private static final HashMap _protocolMsgByOpcode = new HashMap<>(); - public static Protocol getByOpcode(int opcode) { Protocol protocol = _protocolMsgByOpcode.get(opcode); diff --git a/src/engine/net/client/handlers/AbandonAssetMsgHandler.java b/src/engine/net/client/handlers/AbandonAssetMsgHandler.java index 648b5e87..168afbf0 100644 --- a/src/engine/net/client/handlers/AbandonAssetMsgHandler.java +++ b/src/engine/net/client/handlers/AbandonAssetMsgHandler.java @@ -19,204 +19,199 @@ import org.pmw.tinylog.Logger; */ public class AbandonAssetMsgHandler extends AbstractClientMsgHandler { - // Instance variables - - public AbandonAssetMsgHandler() { - super(AbandonAssetMsg.class); - - } - - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - - // Member variable declaration - PlayerCharacter player; - Building building; - AbandonAssetMsg msg; - - // Member variable assignment - msg = (AbandonAssetMsg) baseMsg; - - player = origin.getPlayerCharacter(); - building = BuildingManager.getBuildingFromCache(msg.getUUID()); - - // Oops! *** Refactor: Log error - if ((player == null) || (building == null)) - return true; - - // Early exit if object is not owned by the player - if (building.getOwnerUUID() != player.getObjectUUID()) - return true; - - // Cannot abandon a building without a blueprint. - // Players do not own rocks or shrubbery. - if (building.getBlueprintUUID() == 0) - return true; - - // Players cannot abandon shrines - - if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE)) { - ErrorPopupMsg.sendErrorMsg(player, "Cannot for to abandon shrine!"); - return true; - } - - if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.MINE)) { - ErrorPopupMsg.sendErrorMsg(player, "Cannot abandon mine!"); - return true; - } - - if (Blueprint.isMeshWallPiece(building.getBlueprintUUID())) { - ErrorPopupMsg.sendErrorMsg(player, "Cannot for to abandon fortress asset!"); - return true; - } - - if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.BARRACK)) { - ErrorPopupMsg.sendErrorMsg(player, "Cannot for to abandon fortress asset!"); - return true; - } - - if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.BULWARK)) { - ErrorPopupMsg.sendErrorMsg(player, "Cannot for to abandon siege asset!"); - return true; - } - - if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.SIEGETENT)) { - ErrorPopupMsg.sendErrorMsg(player, "Cannot for to abandon siege asset!"); - return true; - } - - if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.BANESTONE)) { - ErrorPopupMsg.sendErrorMsg(player, "Cannot for to abandon banestone!"); - return true; - } - - // Trees require special handling beyond an individual building - if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.TOL)) - { - // CHECK IF GUILD HAS A BANE DROPPED - City city = ZoneManager.getCityAtLocation(building.getLoc()); - if(city.getGuild().getSubGuildList().isEmpty() == false) - { - //nations cant abandon their tree - ErrorPopupMsg.sendErrorMsg(player, "Nations Cannot Abandon Their Capital!"); - return true; - } - if(Bane.getBaneByAttackerGuild(city.getGuild()) != null) - { - ErrorPopupMsg.sendErrorMsg(player, "You Cannot Abandon Your Tree With An Active Siege!"); - return true; - } - - AbandonAllCityObjects(player, building); - } - else - AbandonSingleAsset(player, building); - - return true; - } - - private static void AbandonSingleAsset(PlayerCharacter sourcePlayer, + // Instance variables + + public AbandonAssetMsgHandler() { + super(AbandonAssetMsg.class); + + } + + private static void AbandonSingleAsset(PlayerCharacter sourcePlayer, Building targetBuilding) { - // Transfer the building asset ownership and refresh all clients + // Transfer the building asset ownership and refresh all clients - DbManager.BuildingQueries.CLEAR_FRIENDS_LIST(targetBuilding.getObjectUUID()); - targetBuilding.getFriends().clear(); + DbManager.BuildingQueries.CLEAR_FRIENDS_LIST(targetBuilding.getObjectUUID()); + targetBuilding.getFriends().clear(); - // Clear protection status but only if a seige building + // Clear protection status but only if a seige building if (targetBuilding.getBlueprint().getBuildingGroup().equals(BuildingGroup.BULWARK) || - targetBuilding.getBlueprint().getBuildingGroup().equals(BuildingGroup.SIEGETENT)) - targetBuilding.setProtectionState(Enum.ProtectionState.NONE); + targetBuilding.getBlueprint().getBuildingGroup().equals(BuildingGroup.SIEGETENT)) + targetBuilding.setProtectionState(Enum.ProtectionState.NONE); + + DbManager.BuildingQueries.CLEAR_CONDEMNED_LIST(targetBuilding.getObjectUUID()); + targetBuilding.getCondemned().clear(); + targetBuilding.setOwner(null); + targetBuilding.refreshGuild(); + + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + // Member variable declaration + PlayerCharacter player; + Building building; + AbandonAssetMsg msg; + + // Member variable assignment + msg = (AbandonAssetMsg) baseMsg; + + player = origin.getPlayerCharacter(); + building = BuildingManager.getBuildingFromCache(msg.getUUID()); + + // Oops! *** Refactor: Log error + if ((player == null) || (building == null)) + return true; + + // Early exit if object is not owned by the player + if (building.getOwnerUUID() != player.getObjectUUID()) + return true; + + // Cannot abandon a building without a blueprint. + // Players do not own rocks or shrubbery. + if (building.getBlueprintUUID() == 0) + return true; + + // Players cannot abandon shrines + + if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE)) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot for to abandon shrine!"); + return true; + } + + if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.MINE)) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot abandon mine!"); + return true; + } + + if (Blueprint.isMeshWallPiece(building.getBlueprintUUID())) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot for to abandon fortress asset!"); + return true; + } + + if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.BARRACK)) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot for to abandon fortress asset!"); + return true; + } + + if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.BULWARK)) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot for to abandon siege asset!"); + return true; + } + + if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.SIEGETENT)) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot for to abandon siege asset!"); + return true; + } + + if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.BANESTONE)) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot for to abandon banestone!"); + return true; + } + + // Trees require special handling beyond an individual building + if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.TOL)) { + // CHECK IF GUILD HAS A BANE DROPPED + City city = ZoneManager.getCityAtLocation(building.getLoc()); + if (city.getGuild().getSubGuildList().isEmpty() == false) { + //nations cant abandon their tree + ErrorPopupMsg.sendErrorMsg(player, "Nations Cannot Abandon Their Capital!"); + return true; + } + if (Bane.getBaneByAttackerGuild(city.getGuild()) != null) { + ErrorPopupMsg.sendErrorMsg(player, "You Cannot Abandon Your Tree With An Active Siege!"); + return true; + } + + AbandonAllCityObjects(player, building); + } else + AbandonSingleAsset(player, building); - DbManager.BuildingQueries.CLEAR_CONDEMNED_LIST(targetBuilding.getObjectUUID()); - targetBuilding.getCondemned().clear(); - targetBuilding.setOwner(null); - targetBuilding.refreshGuild(); + return true; + } - } + private void AbandonAllCityObjects(PlayerCharacter sourcePlayer, + Building targetBuilding) { + Guild sourceGuild; + Zone cityZone; - private void AbandonAllCityObjects(PlayerCharacter sourcePlayer, - Building targetBuilding) { - Guild sourceGuild; - Zone cityZone; + sourceGuild = sourcePlayer.getGuild(); - sourceGuild = sourcePlayer.getGuild(); + if (sourceGuild == null) + return; - if (sourceGuild == null) - return; + if (sourceGuild.getSubGuildList().size() > 0) { + ChatManager.chatCityError(sourcePlayer, "You Cannot abandon a nation city."); + return; + } - if (sourceGuild.getSubGuildList().size() > 0) { - ChatManager.chatCityError(sourcePlayer, "You Cannot abandon a nation city."); - return; - } - - - cityZone = ZoneManager.findSmallestZone(targetBuilding.getLoc()); + cityZone = ZoneManager.findSmallestZone(targetBuilding.getLoc()); - // Can't abandon a tree not within a player city zone - if (cityZone.isPlayerCity() == false) - return; - - if (targetBuilding.getCity() == null) - return; - - if (targetBuilding.getCity().getBane() != null){ - ErrorPopupMsg.sendErrorMsg(sourcePlayer, "Can't abandon Tree while a bane exists."); - return; - } + // Can't abandon a tree not within a player city zone + if (cityZone.isPlayerCity() == false) + return; - if (targetBuilding.getCity().hasBeenTransfered == true) { - ChatManager.chatCityError(sourcePlayer, "City can only be abandoned once per rebooting."); - return; - } + if (targetBuilding.getCity() == null) + return; - // Guild no longer owns his tree. - if (!DbManager.GuildQueries.SET_GUILD_OWNED_CITY(sourceGuild.getObjectUUID(), 0)) { - Logger.error("Failed to update Owned City to Database"); - return; - } + if (targetBuilding.getCity().getBane() != null) { + ErrorPopupMsg.sendErrorMsg(sourcePlayer, "Can't abandon Tree while a bane exists."); + return; + } + + if (targetBuilding.getCity().hasBeenTransfered == true) { + ChatManager.chatCityError(sourcePlayer, "City can only be abandoned once per rebooting."); + return; + } - sourceGuild.setCityUUID(0); - sourceGuild.setGuildState(GuildState.Errant); - sourceGuild.setNation(null); + // Guild no longer owns his tree. + if (!DbManager.GuildQueries.SET_GUILD_OWNED_CITY(sourceGuild.getObjectUUID(), 0)) { + Logger.error("Failed to update Owned City to Database"); + return; + } - // Transfer the city assets - TransferCityAssets(sourcePlayer, targetBuilding); + sourceGuild.setCityUUID(0); + sourceGuild.setGuildState(GuildState.Errant); + sourceGuild.setNation(null); + + // Transfer the city assets + TransferCityAssets(sourcePlayer, targetBuilding); - GuildManager.updateAllGuildTags(sourceGuild); - GuildManager.updateAllGuildBinds(sourceGuild, null); + GuildManager.updateAllGuildTags(sourceGuild); + GuildManager.updateAllGuildBinds(sourceGuild, null); - } + } - private void TransferCityAssets(PlayerCharacter sourcePlayer, - Building cityTOL) { + private void TransferCityAssets(PlayerCharacter sourcePlayer, + Building cityTOL) { - Zone cityZone; + Zone cityZone; - // Build list of buildings within this parent zone - cityZone = ZoneManager.findSmallestZone(cityTOL.getLoc()); + // Build list of buildings within this parent zone + cityZone = ZoneManager.findSmallestZone(cityTOL.getLoc()); - for (Building cityBuilding : cityZone.zoneBuildingSet) { + for (Building cityBuilding : cityZone.zoneBuildingSet) { - Blueprint cityBlueprint; - cityBlueprint = cityBuilding.getBlueprint(); + Blueprint cityBlueprint; + cityBlueprint = cityBuilding.getBlueprint(); - // Buildings without blueprints cannot be abandoned - if (cityBlueprint == null) - continue; + // Buildings without blueprints cannot be abandoned + if (cityBlueprint == null) + continue; - // Transfer ownership of valid city assets - if ((cityBlueprint.getBuildingGroup() == BuildingGroup.TOL) - || (cityBlueprint.getBuildingGroup() == BuildingGroup.SPIRE) - || (cityBlueprint.getBuildingGroup() == BuildingGroup.BARRACK) - || (cityBlueprint.isWallPiece()) - || (cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE)) - AbandonSingleAsset(sourcePlayer, cityBuilding); + // Transfer ownership of valid city assets + if ((cityBlueprint.getBuildingGroup() == BuildingGroup.TOL) + || (cityBlueprint.getBuildingGroup() == BuildingGroup.SPIRE) + || (cityBlueprint.getBuildingGroup() == BuildingGroup.BARRACK) + || (cityBlueprint.isWallPiece()) + || (cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE)) + AbandonSingleAsset(sourcePlayer, cityBuilding); - } + } - } + } } diff --git a/src/engine/net/client/handlers/AbstractClientMsgHandler.java b/src/engine/net/client/handlers/AbstractClientMsgHandler.java index fdc2153b..d3045e3d 100644 --- a/src/engine/net/client/handlers/AbstractClientMsgHandler.java +++ b/src/engine/net/client/handlers/AbstractClientMsgHandler.java @@ -10,24 +10,25 @@ import engine.net.client.msg.ClientNetMsg; */ public abstract class AbstractClientMsgHandler { - private final Class handler; - - public AbstractClientMsgHandler(Class handler) { - this.handler = handler; - } - - public boolean handleNetMsg(ClientNetMsg msg) { - - boolean executionSucceded; - - try { - executionSucceded = _handleNetMsg(msg, (ClientConnection) msg.getOrigin()); - } catch (MsgSendException e) { - e.printStackTrace(); - executionSucceded = false; - } - - return executionSucceded; - } - -protected abstract boolean _handleNetMsg(ClientNetMsg msg, ClientConnection origin) throws MsgSendException;} + private final Class handler; + + public AbstractClientMsgHandler(Class handler) { + this.handler = handler; + } + + public boolean handleNetMsg(ClientNetMsg msg) { + + boolean executionSucceded; + + try { + executionSucceded = _handleNetMsg(msg, (ClientConnection) msg.getOrigin()); + } catch (MsgSendException e) { + e.printStackTrace(); + executionSucceded = false; + } + + return executionSucceded; + } + + protected abstract boolean _handleNetMsg(ClientNetMsg msg, ClientConnection origin) throws MsgSendException; +} diff --git a/src/engine/net/client/handlers/AcceptInviteToGuildHandler.java b/src/engine/net/client/handlers/AcceptInviteToGuildHandler.java index 0b40f7a9..a14cba57 100644 --- a/src/engine/net/client/handlers/AcceptInviteToGuildHandler.java +++ b/src/engine/net/client/handlers/AcceptInviteToGuildHandler.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -43,80 +40,80 @@ import org.joda.time.DateTime; public class AcceptInviteToGuildHandler extends AbstractClientMsgHandler { - public AcceptInviteToGuildHandler() { - super(AcceptInviteToGuildMsg.class); - } + public AcceptInviteToGuildHandler() { + super(AcceptInviteToGuildMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - PlayerCharacter player; - AcceptInviteToGuildMsg msg; - Guild guild; + PlayerCharacter player; + AcceptInviteToGuildMsg msg; + Guild guild; - msg = (AcceptInviteToGuildMsg) baseMsg; + msg = (AcceptInviteToGuildMsg) baseMsg; - // get PlayerCharacter of person accepting invite + // get PlayerCharacter of person accepting invite - player = SessionManager.getPlayerCharacter(origin); + player = SessionManager.getPlayerCharacter(origin); - if (player == null) - return true; + if (player == null) + return true; - guild = (Guild) DbManager.getObject(GameObjectType.Guild, msg.getGuildUUID()); + guild = (Guild) DbManager.getObject(GameObjectType.Guild, msg.getGuildUUID()); - if (guild == null) - return true; + if (guild == null) + return true; - if (guild.getGuildType() == null){ - ErrorPopupMsg.sendErrorPopup(player, GuildManager.NO_CHARTER_FOUND); - return true; - } + if (guild.getGuildType() == null) { + ErrorPopupMsg.sendErrorPopup(player, GuildManager.NO_CHARTER_FOUND); + return true; + } - // verify they accepted for the correct guild + // verify they accepted for the correct guild - if (player.getLastGuildToInvite() != msg.getGuildUUID()) - return true; + if (player.getLastGuildToInvite() != msg.getGuildUUID()) + return true; - if ( (player.getGuild() != null) && - (player.getGuild().isEmptyGuild() == false)) { - ChatManager.chatGuildError(player, - "You already belongs to a guild!"); - return true; - } + if ((player.getGuild() != null) && + (player.getGuild().isEmptyGuild() == false)) { + ChatManager.chatGuildError(player, + "You already belongs to a guild!"); + return true; + } - // verify they are acceptable level for guild + // verify they are acceptable level for guild - if (player.getLevel() < guild.getRepledgeMin() || player.getLevel() > guild.getRepledgeMax()) - return true; + if (player.getLevel() < guild.getRepledgeMin() || player.getLevel() > guild.getRepledgeMax()) + return true; - // Add player to guild - player.setGuild(guild); + // Add player to guild + player.setGuild(guild); - // Cleanup guild stuff - player.resetGuildStatuses(); + // Cleanup guild stuff + player.resetGuildStatuses(); - Dispatch dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + Dispatch dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - DispatchMessage.sendToAllInRange(player, new GuildInfoMsg(player, guild, 2)); + DispatchMessage.sendToAllInRange(player, new GuildInfoMsg(player, guild, 2)); - player.incVer(); + player.incVer(); - //Add to guild History + //Add to guild History - if (player.getGuild() != null){ - if (DbManager.GuildQueries.ADD_TO_GUILDHISTORY(player.getGuildUUID(), player, DateTime.now(), GuildHistoryType.JOIN)){ - GuildHistory guildHistory = new GuildHistory(player.getGuildUUID(),player.getGuild().getName(),DateTime.now(), GuildHistoryType.JOIN) ; - player.getGuildHistory().add(guildHistory); - } - } + if (player.getGuild() != null) { + if (DbManager.GuildQueries.ADD_TO_GUILDHISTORY(player.getGuildUUID(), player, DateTime.now(), GuildHistoryType.JOIN)) { + GuildHistory guildHistory = new GuildHistory(player.getGuildUUID(), player.getGuild().getName(), DateTime.now(), GuildHistoryType.JOIN); + player.getGuildHistory().add(guildHistory); + } + } - // Send guild join message + // Send guild join message - ChatManager.chatGuildInfo(player, player.getFirstName() + " has joined the guild"); - return true; - } + ChatManager.chatGuildInfo(player, player.getFirstName() + " has joined the guild"); + return true; + } } diff --git a/src/engine/net/client/handlers/AcceptSubInviteHandler.java b/src/engine/net/client/handlers/AcceptSubInviteHandler.java index 38fbb3ef..d70b0b2e 100644 --- a/src/engine/net/client/handlers/AcceptSubInviteHandler.java +++ b/src/engine/net/client/handlers/AcceptSubInviteHandler.java @@ -30,77 +30,77 @@ import java.util.ArrayList; public class AcceptSubInviteHandler extends AbstractClientMsgHandler { - public AcceptSubInviteHandler() { - super(AcceptSubInviteMsg.class); - } + public AcceptSubInviteHandler() { + super(AcceptSubInviteMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - AcceptSubInviteMsg msg = (AcceptSubInviteMsg) baseMsg; - PlayerCharacter sourcePlayer; - Guild sourceGuild; - Guild targetGuild; - Dispatch dispatch; + AcceptSubInviteMsg msg = (AcceptSubInviteMsg) baseMsg; + PlayerCharacter sourcePlayer; + Guild sourceGuild; + Guild targetGuild; + Dispatch dispatch; - // get PlayerCharacter of person sending sub invite + // get PlayerCharacter of person sending sub invite - sourcePlayer = SessionManager.getPlayerCharacter(origin); + sourcePlayer = SessionManager.getPlayerCharacter(origin); - if (sourcePlayer == null) - return true; + if (sourcePlayer == null) + return true; - sourceGuild = sourcePlayer.getGuild(); - targetGuild = (Guild) DbManager.getObject(GameObjectType.Guild, msg.guildUUID()); + sourceGuild = sourcePlayer.getGuild(); + targetGuild = (Guild) DbManager.getObject(GameObjectType.Guild, msg.guildUUID()); - //must be source guild to sub to + //must be source guild to sub to - if (targetGuild == null) { - ErrorPopupMsg.sendErrorPopup(sourcePlayer, 45); // Failure to swear guild - return true; - } - if (sourceGuild == null) { - ErrorPopupMsg.sendErrorPopup(sourcePlayer, 45); // Failure to swear guild - return true; - } - - if (sourceGuild.equals(targetGuild)) - return true; + if (targetGuild == null) { + ErrorPopupMsg.sendErrorPopup(sourcePlayer, 45); // Failure to swear guild + return true; + } + if (sourceGuild == null) { + ErrorPopupMsg.sendErrorPopup(sourcePlayer, 45); // Failure to swear guild + return true; + } - if (GuildStatusController.isGuildLeader(sourcePlayer.getGuildStatus()) == false) { - ErrorPopupMsg.sendErrorMsg(sourcePlayer, "Only a guild leader can accept fealty!"); - return true; - } + if (sourceGuild.equals(targetGuild)) + return true; - //source guild is limited to 7 subs - //TODO this should be based on TOL rank + if (GuildStatusController.isGuildLeader(sourcePlayer.getGuildStatus()) == false) { + ErrorPopupMsg.sendErrorMsg(sourcePlayer, "Only a guild leader can accept fealty!"); + return true; + } - if (!targetGuild.canSubAGuild(sourceGuild)) { - ErrorPopupMsg.sendErrorPopup(sourcePlayer, 45); // Failure to swear guild - return true; - } + //source guild is limited to 7 subs + //TODO this should be based on TOL rank - //all tests passed, let's Handle code - //Update Target Guild State. + if (!targetGuild.canSubAGuild(sourceGuild)) { + ErrorPopupMsg.sendErrorPopup(sourcePlayer, 45); // Failure to swear guild + return true; + } - sourceGuild.upgradeGuildState(false); + //all tests passed, let's Handle code + //Update Target Guild State. - //Add sub so GuildMaster can Swear in. + sourceGuild.upgradeGuildState(false); - ArrayList subs = targetGuild.getSubGuildList(); - subs.add(sourceGuild); + //Add sub so GuildMaster can Swear in. - targetGuild.setGuildState(GuildState.Nation); + ArrayList subs = targetGuild.getSubGuildList(); + subs.add(sourceGuild); + targetGuild.setGuildState(GuildState.Nation); - //Let's send the message back. - msg.setUnknown02(1); - msg.setResponse("Your guild is now a " + sourceGuild.getGuildState().name() + '.'); - dispatch = Dispatch.borrow(sourcePlayer, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + //Let's send the message back. - ChatManager.chatSystemInfo(sourcePlayer, "Your guild is now a " + sourceGuild.getGuildState().name() + '.'); - return true; - } + msg.setUnknown02(1); + msg.setResponse("Your guild is now a " + sourceGuild.getGuildState().name() + '.'); + dispatch = Dispatch.borrow(sourcePlayer, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + ChatManager.chatSystemInfo(sourcePlayer, "Your guild is now a " + sourceGuild.getGuildState().name() + '.'); + return true; + } } diff --git a/src/engine/net/client/handlers/ActivateNPCMsgHandler.java b/src/engine/net/client/handlers/ActivateNPCMsgHandler.java index 7aaa4d87..0d2897bf 100644 --- a/src/engine/net/client/handlers/ActivateNPCMsgHandler.java +++ b/src/engine/net/client/handlers/ActivateNPCMsgHandler.java @@ -22,115 +22,115 @@ import java.util.ArrayList; */ public class ActivateNPCMsgHandler extends AbstractClientMsgHandler { - public ActivateNPCMsgHandler() { - super(ActivateNPCMessage.class); - } + public ActivateNPCMsgHandler() { + super(ActivateNPCMessage.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - ActivateNPCMessage msg; - PlayerCharacter player; - Building building; - Contract contract; - CharacterItemManager itemMan; - Zone zone; + ActivateNPCMessage msg; + PlayerCharacter player; + Building building; + Contract contract; + CharacterItemManager itemMan; + Zone zone; - msg = (ActivateNPCMessage) baseMsg; - player = SessionManager.getPlayerCharacter(origin); - building = BuildingManager.getBuildingFromCache(msg.buildingUUID()); + msg = (ActivateNPCMessage) baseMsg; + player = SessionManager.getPlayerCharacter(origin); + building = BuildingManager.getBuildingFromCache(msg.buildingUUID()); - if (player == null || building == null) - return false; + if (player == null || building == null) + return false; - ArrayList ItemLists = new ArrayList<>(); + ArrayList ItemLists = new ArrayList<>(); - // Filter hirelings by slot type + // Filter hirelings by slot type - for (Item hirelings : player.getInventory()) { - if (hirelings.getItemBase().getType().equals(ItemType.CONTRACT)) { + for (Item hirelings : player.getInventory()) { + if (hirelings.getItemBase().getType().equals(ItemType.CONTRACT)) { - contract = DbManager.ContractQueries.GET_CONTRACT(hirelings.getItemBase().getUUID()); + contract = DbManager.ContractQueries.GET_CONTRACT(hirelings.getItemBase().getUUID()); - if (contract == null) - continue; + if (contract == null) + continue; - if (contract.canSlotinBuilding(building)) - ItemLists.add(hirelings); - } - } + if (contract.canSlotinBuilding(building)) + ItemLists.add(hirelings); + } + } - if (msg.getUnknown01() == 1) { - //Request npc list to slot - ActivateNPCMessage anm = new ActivateNPCMessage(); - anm.setSize(ItemLists.size()); - anm.setItemList(ItemLists); - Dispatch dispatch = Dispatch.borrow(player, anm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } + if (msg.getUnknown01() == 1) { + //Request npc list to slot + ActivateNPCMessage anm = new ActivateNPCMessage(); + anm.setSize(ItemLists.size()); + anm.setItemList(ItemLists); + Dispatch dispatch = Dispatch.borrow(player, anm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } - if (msg.getUnknown01() == 0) { + if (msg.getUnknown01() == 0) { - //Slot npc + //Slot npc - if (building.getBlueprintUUID() == 0) { - ChatManager.chatSystemError(player, "Unable to load Blueprint for Building Mesh " + building.getMeshUUID()); - return false; - } + if (building.getBlueprintUUID() == 0) { + ChatManager.chatSystemError(player, "Unable to load Blueprint for Building Mesh " + building.getMeshUUID()); + return false; + } - if (building.getBlueprint().getMaxSlots() == building.getHirelings().size()) - return false; + if (building.getBlueprint().getMaxSlots() == building.getHirelings().size()) + return false; - Item contractItem = Item.getFromCache(msg.getContractItem()); + Item contractItem = Item.getFromCache(msg.getContractItem()); - if (contractItem == null) - return false; + if (contractItem == null) + return false; - if (!player.getCharItemManager().doesCharOwnThisItem(contractItem.getObjectUUID())) { - Logger.error(player.getName() + "has attempted to place Hireling : " + contractItem.getName() + "without a valid contract!"); - return false; - } + if (!player.getCharItemManager().doesCharOwnThisItem(contractItem.getObjectUUID())) { + Logger.error(player.getName() + "has attempted to place Hireling : " + contractItem.getName() + "without a valid contract!"); + return false; + } - itemMan = player.getCharItemManager(); + itemMan = player.getCharItemManager(); - zone = ZoneManager.findSmallestZone(building.getLoc()); + zone = ZoneManager.findSmallestZone(building.getLoc()); - if (zone == null) - return false; + if (zone == null) + return false; - contract = DbManager.ContractQueries.GET_CONTRACT(contractItem.getItemBase().getUUID()); + contract = DbManager.ContractQueries.GET_CONTRACT(contractItem.getItemBase().getUUID()); - if (contract == null) - return false; + if (contract == null) + return false; - // Check if contract can be slotted in this building + // Check if contract can be slotted in this building - if (contract.canSlotinBuilding(building) == false) - return false; + if (contract.canSlotinBuilding(building) == false) + return false; - if (!BuildingManager.addHireling(building, player, zone, contract, contractItem)) - return false; + if (!BuildingManager.addHireling(building, player, zone, contract, contractItem)) + return false; - itemMan.delete(contractItem); - itemMan.updateInventory(); + itemMan.delete(contractItem); + itemMan.updateInventory(); - ManageCityAssetsMsg mca1 = new ManageCityAssetsMsg(player, building); + ManageCityAssetsMsg mca1 = new ManageCityAssetsMsg(player, building); - mca1.actionType = 3; + mca1.actionType = 3; - mca1.setTargetType(building.getObjectType().ordinal()); - mca1.setTargetID(building.getObjectUUID()); - mca1.setTargetType3(building.getObjectType().ordinal()); - mca1.setTargetID3(building.getObjectUUID()); - mca1.setAssetName1(building.getName()); - mca1.setUnknown54(1); - Dispatch dispatch = Dispatch.borrow(player, mca1); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + mca1.setTargetType(building.getObjectType().ordinal()); + mca1.setTargetID(building.getObjectUUID()); + mca1.setTargetType3(building.getObjectType().ordinal()); + mca1.setTargetID3(building.getObjectUUID()); + mca1.setAssetName1(building.getName()); + mca1.setUnknown54(1); + Dispatch dispatch = Dispatch.borrow(player, mca1); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } + } - return true; - } + return true; + } } diff --git a/src/engine/net/client/handlers/AllianceChangeMsgHandler.java b/src/engine/net/client/handlers/AllianceChangeMsgHandler.java index db312f31..f56b8849 100644 --- a/src/engine/net/client/handlers/AllianceChangeMsgHandler.java +++ b/src/engine/net/client/handlers/AllianceChangeMsgHandler.java @@ -20,142 +20,134 @@ import engine.objects.PlayerCharacter; */ public class AllianceChangeMsgHandler extends AbstractClientMsgHandler { - public AllianceChangeMsgHandler() { - super(AllianceChangeMsg.class); - } + public AllianceChangeMsgHandler() { + super(AllianceChangeMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + private static void MakeEnemy(Guild fromGuild, Guild toGuild, AllianceChangeMsg msg, ClientConnection origin) { - // Member variable declaration + // Member variable declaration + Dispatch dispatch; - PlayerCharacter player; - AllianceChangeMsg msg; + // Member variable assignment + if (fromGuild == null) + return; - // Member variable assignment + if (toGuild == null) + return; - msg = (AllianceChangeMsg) baseMsg; + if (!Guild.sameGuild(origin.getPlayerCharacter().getGuild(), fromGuild)) { + msg.setMsgType(AllianceChangeMsg.ERROR_NOT_SAME_GUILD); + dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + return; + } - player = SessionManager.getPlayerCharacter(origin); + if (!GuildStatusController.isInnerCouncil(origin.getPlayerCharacter().getGuildStatus()) && !GuildStatusController.isGuildLeader(origin.getPlayerCharacter().getGuildStatus())) { + msg.setMsgType(AllianceChangeMsg.ERROR_NOT_AUTHORIZED); + dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + return; + } - if (player == null) - return true; + dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - Guild toGuild = null; - toGuild = Guild.getGuild(msg.getSourceGuildID()); - if (toGuild.isEmptyGuild()) - return true; + } - if (player.getGuild().isEmptyGuild()) - return true; + private static void makeAlly(Guild fromGuild, Guild toGuild, AllianceChangeMsg msg, ClientConnection origin) { + // Member variable declaration + Dispatch dispatch; + // Member variable assignment - switch (msg.getMsgType()){ - case AllianceChangeMsg.MAKE_ALLY: - case 1: //allyfromRecommended - player.getGuild().addGuildToAlliance(msg, AllianceType.Ally, toGuild, player); - break; - case AllianceChangeMsg.MAKE_ENEMY: - case 2: //enemy recommend - player.getGuild().addGuildToAlliance(msg, AllianceType.Enemy, toGuild, player); - break; - case 3: - case 5: - case 7: - player.getGuild().removeGuildFromAllAlliances(toGuild); - break; + if (fromGuild == null) + return; - } - msg.setMsgType(AllianceChangeMsg.INFO_SUCCESS); - Dispatch dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + if (toGuild == null) + return; + dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } + private static void removeFromAlliance(Guild fromGuild, Guild toGuild, AllianceChangeMsg msg, ClientConnection origin) { + // Member variable declaration + Dispatch dispatch; + // Member variable assignment - return true; + if (fromGuild == null) + return; - } + if (toGuild == null) + return; - private static void MakeEnemy(Guild fromGuild, Guild toGuild, AllianceChangeMsg msg, ClientConnection origin) { + dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - // Member variable declaration - Dispatch dispatch; - // Member variable assignment + } - if (fromGuild == null) - return; + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - if (toGuild == null) - return; + // Member variable declaration - if (!Guild.sameGuild(origin.getPlayerCharacter().getGuild(), fromGuild)){ - msg.setMsgType(AllianceChangeMsg.ERROR_NOT_SAME_GUILD); - dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - return; - } + PlayerCharacter player; + AllianceChangeMsg msg; - if (!GuildStatusController.isInnerCouncil(origin.getPlayerCharacter().getGuildStatus()) && !GuildStatusController.isGuildLeader(origin.getPlayerCharacter().getGuildStatus())){ - msg.setMsgType(AllianceChangeMsg.ERROR_NOT_AUTHORIZED); - dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - return; - } + // Member variable assignment - dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + msg = (AllianceChangeMsg) baseMsg; + player = SessionManager.getPlayerCharacter(origin); - } + if (player == null) + return true; - private static void makeAlly(Guild fromGuild, Guild toGuild, AllianceChangeMsg msg, ClientConnection origin) { - // Member variable declaration - Dispatch dispatch; + Guild toGuild = null; + toGuild = Guild.getGuild(msg.getSourceGuildID()); + if (toGuild.isEmptyGuild()) + return true; - // Member variable assignment + if (player.getGuild().isEmptyGuild()) + return true; - if (fromGuild == null) - return; - if (toGuild == null) - return; + switch (msg.getMsgType()) { + case AllianceChangeMsg.MAKE_ALLY: + case 1: //allyfromRecommended + player.getGuild().addGuildToAlliance(msg, AllianceType.Ally, toGuild, player); + break; + case AllianceChangeMsg.MAKE_ENEMY: + case 2: //enemy recommend + player.getGuild().addGuildToAlliance(msg, AllianceType.Enemy, toGuild, player); + break; + case 3: + case 5: + case 7: + player.getGuild().removeGuildFromAllAlliances(toGuild); + break; - dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } + msg.setMsgType(AllianceChangeMsg.INFO_SUCCESS); + Dispatch dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } - - private static void removeFromAlliance(Guild fromGuild, Guild toGuild, AllianceChangeMsg msg, ClientConnection origin) { - - // Member variable declaration - Dispatch dispatch; - - // Member variable assignment - - if (fromGuild == null) - return; - - if (toGuild == null) - return; - - dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - - } + return true; + } } diff --git a/src/engine/net/client/handlers/AllyEnemyListMsgHandler.java b/src/engine/net/client/handlers/AllyEnemyListMsgHandler.java index b13bde9b..18fc7b48 100644 --- a/src/engine/net/client/handlers/AllyEnemyListMsgHandler.java +++ b/src/engine/net/client/handlers/AllyEnemyListMsgHandler.java @@ -18,64 +18,61 @@ import engine.objects.PlayerCharacter; */ public class AllyEnemyListMsgHandler extends AbstractClientMsgHandler { - public AllyEnemyListMsgHandler() { - super(AllyEnemyListMsg.class); - } + public AllyEnemyListMsgHandler() { + super(AllyEnemyListMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + private static void showAllyEnemyList(Guild fromGuild, Guild toGuild, AllyEnemyListMsg msg, ClientConnection origin) { - // Member variable declaration + // Member variable declaration + Dispatch dispatch; - PlayerCharacter player; - AllyEnemyListMsg msg; + // Member variable assignment + if (fromGuild == null) + return; - // Member variable assignment + if (toGuild == null) + return; + dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - msg = (AllyEnemyListMsg) baseMsg; + // UpdateClientAlliancesMsg ucam = new UpdateClientAlliancesMsg(); + // + // dispatch = Dispatch.borrow(origin.getPlayerCharacter(), ucam); + // DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - player = SessionManager.getPlayerCharacter(origin); - if (player == null) - return true; + } + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - AllyEnemyListMsgHandler.showAllyEnemyList(player.getGuild(), Guild.getGuild(msg.getGuildID()), msg, origin); + // Member variable declaration + PlayerCharacter player; + AllyEnemyListMsg msg; + // Member variable assignment - // dispatch = Dispatch.borrow(player, baseMsg); - // DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + msg = (AllyEnemyListMsg) baseMsg; - return true; + player = SessionManager.getPlayerCharacter(origin); - } + if (player == null) + return true; - private static void showAllyEnemyList(Guild fromGuild, Guild toGuild, AllyEnemyListMsg msg, ClientConnection origin) { - // Member variable declaration - Dispatch dispatch; + AllyEnemyListMsgHandler.showAllyEnemyList(player.getGuild(), Guild.getGuild(msg.getGuildID()), msg, origin); - // Member variable assignment - if (fromGuild == null) - return; + // dispatch = Dispatch.borrow(player, baseMsg); + // DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - if (toGuild == null) - return; - dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - // UpdateClientAlliancesMsg ucam = new UpdateClientAlliancesMsg(); - // - // dispatch = Dispatch.borrow(origin.getPlayerCharacter(), ucam); - // DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - - } + return true; + } } diff --git a/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java b/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java index a7cf9de7..b9986be9 100644 --- a/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java +++ b/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java @@ -22,123 +22,123 @@ import org.pmw.tinylog.Logger; public class ArcLoginNotifyMsgHandler extends AbstractClientMsgHandler { - public ArcLoginNotifyMsgHandler() { - super(ArcLoginNotifyMsg.class); - } + public ArcLoginNotifyMsgHandler() { + super(ArcLoginNotifyMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - PlayerCharacter player = SessionManager.getPlayerCharacter(origin); + PlayerCharacter player = SessionManager.getPlayerCharacter(origin); - if (player == null) { - Logger.error(ConfigManager.MB_WORLD_NAME.getValue()+ ".EnterWorld", "Unable to find player for session"); - origin.kickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Player not found."); - return true; - } + if (player == null) { + Logger.error(ConfigManager.MB_WORLD_NAME.getValue() + ".EnterWorld", "Unable to find player for session"); + origin.kickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Player not found."); + return true; + } - // cancel logout Timer if exists - if (player.getTimers().containsKey("Logout")) { + // cancel logout Timer if exists + if (player.getTimers().containsKey("Logout")) { - JobScheduler.getInstance().cancelScheduledJob(player.getTimers().get("Logout")); - player.getTimers().remove("Logout"); - } - player.setTimeStamp("logout", 0); + JobScheduler.getInstance().cancelScheduledJob(player.getTimers().get("Logout")); + player.getTimers().remove("Logout"); + } + player.setTimeStamp("logout", 0); - // refresh group window if still in group for both this player - // and everyone else in the group + // refresh group window if still in group for both this player + // and everyone else in the group - if (GroupManager.getGroup(player) != null) { - GroupManager.RefreshMyGroupList(player, origin); - GroupManager.RefreshOthersGroupList(player); - } + if (GroupManager.getGroup(player) != null) { + GroupManager.RefreshMyGroupList(player, origin); + GroupManager.RefreshOthersGroupList(player); + } - player.setEnteredWorld(true); - // Set player active - player.resetRegenUpdateTime(); - player.setActive(true); + player.setEnteredWorld(true); + // Set player active + player.resetRegenUpdateTime(); + player.setActive(true); - //player.sendAllEffects(player.getClientConnection()); - // Send Enter world message to guild + //player.sendAllEffects(player.getClientConnection()); + // Send Enter world message to guild - ChatManager.GuildEnterWorldMsg(player, origin); + ChatManager.GuildEnterWorldMsg(player, origin); - // Send Guild, Nation and IC MOTD - GuildManager.enterWorldMOTD(player); - ChatManager.sendSystemMessage(player, ConfigManager.MB_WORLD_GREETING.getValue()); + // Send Guild, Nation and IC MOTD + GuildManager.enterWorldMOTD(player); + ChatManager.sendSystemMessage(player, ConfigManager.MB_WORLD_GREETING.getValue()); - // Set player mask for QT - if (player.getRace() != null && player.getRace().getToken() == -524731385) - player.setObjectTypeMask(MBServerStatics.MASK_PLAYER | MBServerStatics.MASK_UNDEAD); - else - player.setObjectTypeMask(MBServerStatics.MASK_PLAYER); + // Set player mask for QT + if (player.getRace() != null && player.getRace().getToken() == -524731385) + player.setObjectTypeMask(MBServerStatics.MASK_PLAYER | MBServerStatics.MASK_UNDEAD); + else + player.setObjectTypeMask(MBServerStatics.MASK_PLAYER); - // If player not already in world, then set them to bind loc and add - // to world + // If player not already in world, then set them to bind loc and add + // to world - if (player.newChar) - player.newChar = false; // TODO Fix safe mode + if (player.newChar) + player.newChar = false; // TODO Fix safe mode - // PowersManager.applyPower(player, player, new - // Vector3f(0f, 0f, 0f), -1661758934, 50, false); + // PowersManager.applyPower(player, player, new + // Vector3f(0f, 0f, 0f), -1661758934, 50, false); - // Add player to the QT for tracking + // Add player to the QT for tracking - player.setLoc(player.getLoc()); + player.setLoc(player.getLoc()); - //send online status to friends. - PlayerFriends.SendFriendsStatus(player, true); + //send online status to friends. + PlayerFriends.SendFriendsStatus(player, true); - // Handle too many simultaneous logins from the same forum account by disconnecting the other account(s) + // Handle too many simultaneous logins from the same forum account by disconnecting the other account(s) - Account thisAccount = SessionManager.getAccount(player); - int maxAccounts = MBServerStatics.MAX_ACTIVE_GAME_ACCOUNTS_PER_DISCORD_ACCOUNT; + Account thisAccount = SessionManager.getAccount(player); + int maxAccounts = MBServerStatics.MAX_ACTIVE_GAME_ACCOUNTS_PER_DISCORD_ACCOUNT; - if (maxAccounts > 0) { + if (maxAccounts > 0) { - int count = 1; - for (Account othAccount : SessionManager.getAllActiveAccounts()) { + int count = 1; + for (Account othAccount : SessionManager.getAllActiveAccounts()) { - if (othAccount.equals(thisAccount)) - continue; + if (othAccount.equals(thisAccount)) + continue; - if (thisAccount.discordAccount.equals(othAccount.discordAccount) == false) - continue; + if (thisAccount.discordAccount.equals(othAccount.discordAccount) == false) + continue; - count++; + count++; - if (count > maxAccounts) { - Session otherSession = SessionManager.getSession(othAccount); - if (otherSession != null) { - ClientConnection otherConn = otherSession.getConn(); - if (otherConn != null) { - ChatManager.chatSystemInfo(player, "Only 4 accounts may be used simultaneously. Account '" + othAccount.getUname() + "' has been disconnected."); - otherConn.disconnect(); - } - } - } - } - } + if (count > maxAccounts) { + Session otherSession = SessionManager.getSession(othAccount); + if (otherSession != null) { + ClientConnection otherConn = otherSession.getConn(); + if (otherConn != null) { + ChatManager.chatSystemInfo(player, "Only 4 accounts may be used simultaneously. Account '" + othAccount.getUname() + "' has been disconnected."); + otherConn.disconnect(); + } + } + } + } + } - player.setTimeStamp("logout", 0); + player.setTimeStamp("logout", 0); - if (player.getPet() != null) { - PetMsg pm = new PetMsg(5, player.getPet()); - Dispatch dispatch = Dispatch.borrow(player, pm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } + if (player.getPet() != null) { + PetMsg pm = new PetMsg(5, player.getPet()); + Dispatch dispatch = Dispatch.borrow(player, pm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + } - //Send current hotzone + //Send current hotzone - if (ZoneManager.hotZone != null) { - HotzoneChangeMsg hcm = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), ZoneManager.hotZone.getObjectUUID()); - Dispatch dispatch = Dispatch.borrow(player, hcm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } + if (ZoneManager.hotZone != null) { + HotzoneChangeMsg hcm = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), ZoneManager.hotZone.getObjectUUID()); + Dispatch dispatch = Dispatch.borrow(player, hcm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + } - if (player.getGuild() != null && !player.getGuild().isEmptyGuild()) { - Guild.UpdateClientAlliancesForPlayer(player); - } - return true; - } + if (player.getGuild() != null && !player.getGuild().isEmptyGuild()) { + Guild.UpdateClientAlliancesForPlayer(player); + } + return true; + } } \ No newline at end of file diff --git a/src/engine/net/client/handlers/ArcMineWindowAvailableTimeHandler.java b/src/engine/net/client/handlers/ArcMineWindowAvailableTimeHandler.java index d02e53d8..6b2bd0ee 100644 --- a/src/engine/net/client/handlers/ArcMineWindowAvailableTimeHandler.java +++ b/src/engine/net/client/handlers/ArcMineWindowAvailableTimeHandler.java @@ -29,7 +29,7 @@ public class ArcMineWindowAvailableTimeHandler extends AbstractClientMsgHandler @Override protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - ArcMineWindowAvailableTimeMsg msg = (ArcMineWindowAvailableTimeMsg) baseMsg; + ArcMineWindowAvailableTimeMsg msg = (ArcMineWindowAvailableTimeMsg) baseMsg; PlayerCharacter playerCharacter = origin.getPlayerCharacter(); Building treeOfLife = BuildingManager.getBuildingFromCache(msg.getBuildingUUID()); Dispatch dispatch; diff --git a/src/engine/net/client/handlers/ArcSiegeSpireMsgHandler.java b/src/engine/net/client/handlers/ArcSiegeSpireMsgHandler.java index 9c2b7ed0..322981ad 100644 --- a/src/engine/net/client/handlers/ArcSiegeSpireMsgHandler.java +++ b/src/engine/net/client/handlers/ArcSiegeSpireMsgHandler.java @@ -21,100 +21,100 @@ import org.pmw.tinylog.Logger; public class ArcSiegeSpireMsgHandler extends AbstractClientMsgHandler { - public ArcSiegeSpireMsgHandler() { - super(ArcSiegeSpireMsg.class); - } + public ArcSiegeSpireMsgHandler() { + super(ArcSiegeSpireMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - PlayerCharacter player; - Building spire; - ArcSiegeSpireMsg msg; + PlayerCharacter player; + Building spire; + ArcSiegeSpireMsg msg; - msg = (ArcSiegeSpireMsg) baseMsg; + msg = (ArcSiegeSpireMsg) baseMsg; - player = SessionManager.getPlayerCharacter(origin); + player = SessionManager.getPlayerCharacter(origin); - if (player == null) - return true; + if (player == null) + return true; - spire = (Building) DbManager.getObject(GameObjectType.Building, msg.getBuildingUUID()); + spire = (Building) DbManager.getObject(GameObjectType.Building, msg.getBuildingUUID()); - if (spire == null) - return true; + if (spire == null) + return true; - if (spire.getCity() == null) - return true; - - spire.getCity().transactionLock.writeLock().lock(); - - try{ - - - //can't activate a spire that's not rank 1. + if (spire.getCity() == null) + return true; - if (spire.getRank() < 1) - return true; + spire.getCity().transactionLock.writeLock().lock(); - // can't activate a spire without a city + try { - if (spire.getCity() == null) - return true; - // Must have management authority for the spire + //can't activate a spire that's not rank 1. - if ((player.getGuild().equals(spire.getGuild()) == false) - || (GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false) ) - return true; + if (spire.getRank() < 1) + return true; - // Handle case where spire is sabotaged + // can't activate a spire without a city - if (spire.getTimeStamp("DISABLED") > System.currentTimeMillis()) { - ErrorPopupMsg.sendErrorPopup(player, 174); //This siege spire cannot be toggled yet. - return true; - } + if (spire.getCity() == null) + return true; - // Handle case where spire's toggle delay hasn't yet passed + // Must have management authority for the spire - if (spire.getTimeStamp("TOGGLEDELAY") > System.currentTimeMillis()) { - ErrorPopupMsg.sendErrorPopup(player, 174); //This siege spire cannot be toggled yet. - return true; - } + if ((player.getGuild().equals(spire.getGuild()) == false) + || (GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false)) + return true; - // This protocol message is a toggle. If it's currently active then disable - // the spire. + // Handle case where spire is sabotaged - if (spire.isSpireIsActive()) { - spire.disableSpire(false); - return true; - } + if (spire.getTimeStamp("DISABLED") > System.currentTimeMillis()) { + ErrorPopupMsg.sendErrorPopup(player, 174); //This siege spire cannot be toggled yet. + return true; + } - // Must be enough gold on the spire to turn it on + // Handle case where spire's toggle delay hasn't yet passed - if (!spire.hasFunds(5000)){ - ErrorPopupMsg.sendErrorPopup(player, 127); // Not enough gold in strongbox - return true; - } + if (spire.getTimeStamp("TOGGLEDELAY") > System.currentTimeMillis()) { + ErrorPopupMsg.sendErrorPopup(player, 174); //This siege spire cannot be toggled yet. + return true; + } - if (spire.getStrongboxValue() < 5000) { - ErrorPopupMsg.sendErrorPopup(player, 127); // Not enough gold in strongbox - return true; - } + // This protocol message is a toggle. If it's currently active then disable + // the spire. - spire.transferGold(-5000,false); - spire.enableSpire(); + if (spire.isSpireIsActive()) { + spire.disableSpire(false); + return true; + } - // Spire is now enabled. Reset the toggle delay + // Must be enough gold on the spire to turn it on - spire.setTimeStamp("TOGGLEDELAY", System.currentTimeMillis() + (long) 10 * 60 * 1000); - }catch(Exception e){ - Logger.error(e); - }finally{ - spire.getCity().transactionLock.writeLock().unlock(); - } - return true; - - } + if (!spire.hasFunds(5000)) { + ErrorPopupMsg.sendErrorPopup(player, 127); // Not enough gold in strongbox + return true; + } + + if (spire.getStrongboxValue() < 5000) { + ErrorPopupMsg.sendErrorPopup(player, 127); // Not enough gold in strongbox + return true; + } + + spire.transferGold(-5000, false); + spire.enableSpire(); + + // Spire is now enabled. Reset the toggle delay + + spire.setTimeStamp("TOGGLEDELAY", System.currentTimeMillis() + (long) 10 * 60 * 1000); + } catch (Exception e) { + Logger.error(e); + } finally { + spire.getCity().transactionLock.writeLock().unlock(); + } + return true; + + } } diff --git a/src/engine/net/client/handlers/ArcViewAssetTransactionsMsgHandler.java b/src/engine/net/client/handlers/ArcViewAssetTransactionsMsgHandler.java index c2d0d952..468a3796 100644 --- a/src/engine/net/client/handlers/ArcViewAssetTransactionsMsgHandler.java +++ b/src/engine/net/client/handlers/ArcViewAssetTransactionsMsgHandler.java @@ -40,9 +40,9 @@ public class ArcViewAssetTransactionsMsgHandler extends AbstractClientMsgHandler Warehouse warehouse = Warehouse.warehouseByBuildingUUID.get(msg.getWarehouseID()); if (warehouse == null) - return true; - - newMsg = new ArcViewAssetTransactionsMsg(warehouse,msg); + return true; + + newMsg = new ArcViewAssetTransactionsMsg(warehouse, msg); newMsg.configure(); dispatch = Dispatch.borrow(player, newMsg); diff --git a/src/engine/net/client/handlers/AssetSupportMsgHandler.java b/src/engine/net/client/handlers/AssetSupportMsgHandler.java index 561aaa0f..444a6df8 100644 --- a/src/engine/net/client/handlers/AssetSupportMsgHandler.java +++ b/src/engine/net/client/handlers/AssetSupportMsgHandler.java @@ -20,221 +20,220 @@ import org.pmw.tinylog.Logger; */ public class AssetSupportMsgHandler extends AbstractClientMsgHandler { - public AssetSupportMsgHandler() { - super(AssetSupportMsg.class); - } + public AssetSupportMsgHandler() { + super(AssetSupportMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + private static void protectAsset(AssetSupportMsg msg, Building targetBuilding, NPC vendor, ClientConnection origin) { - // Member variable declaration + // Member variable declaration - PlayerCharacter player; - NPC vendor; - Building targetBuilding; - Dispatch dispatch; + Zone serverZone; + City serverCity; + ManageNPCMsg outMsg; + int protectionSlots; + Dispatch dispatch; - AssetSupportMsg msg; - CityAssetMsg outMsg; + // Member variable assignment - // Member variable assignment + if (targetBuilding == null) + return; - msg = (AssetSupportMsg) baseMsg; + serverZone = vendor.getParentZone(); - player = SessionManager.getPlayerCharacter(origin); + if (serverZone == null) + return; - if (player == null) - return true; + serverCity = City.GetCityFromCache(serverZone.getPlayerCityUUID()); - vendor = NPC.getFromCache(msg.getNpcID()); + if (serverCity == null) + return; - if (msg.getMessageType() !=6 && msg.getMessageType() != 7){ - if (vendor == null) - return true; + if (!serverCity.isLocationOnCityZone(targetBuilding.getLoc())) { + ErrorPopupMsg.sendErrorMsg(origin.getPlayerCharacter(), "Structura must be on city zone for to protect."); + return; + } - vendor.getBuilding(); + if ((serverCity.getTOL() == null) || (serverCity.getTOL().getRank() < 1)) + return; - if (vendor.getBuilding() == null) - return true; - } + if (serverCity.protectionEnforced == false) { + ErrorPopupMsg.sendErrorMsg(origin.getPlayerCharacter(), "Runemaster can not protect structura during bane!"); + return; + } + if (serverCity.getRuneMaster() == null) { + ErrorPopupMsg.sendErrorMsg(origin.getPlayerCharacter(), "Runemaster is needed for to protect structura!"); + return; + } - SupportMsgType supportType = SupportMsgType.typeLookup.get(msg.getMessageType()); + // Enforce runemaster protection limits - if (supportType == null) { - supportType = Enum.SupportMsgType.NONE; - Logger.error("No enumeration for support type" + msg.getMessageType()); - } - switch (supportType) { + protectionSlots = (2 * serverCity.getRuneMaster().getRank()) + 6; - case PROTECT: - targetBuilding = BuildingManager.getBuildingFromCache(msg.getProtectedBuildingID()); - protectAsset(msg,targetBuilding, vendor, origin); - break; - case UNPROTECT: - targetBuilding = BuildingManager.getBuildingFromCache(msg.getProtectedBuildingID()); - unprotectAsset(targetBuilding, vendor, origin); - break; - case VIEWUNPROTECTED: - outMsg = new CityAssetMsg(); - outMsg.setBuildingID(msg.getBuildingID()); - outMsg.configure(); + if (serverCity.getRuneMaster().getProtectedBuildings().size() >= + protectionSlots) { + ErrorPopupMsg.sendErrorMsg(origin.getPlayerCharacter(), "Runemaster can only protect " + protectionSlots + " structura!"); + return; + } - dispatch = Dispatch.borrow(player, outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - break; + if (msg.getWeeklyTax() != 0) { + if (!serverCity.getTOL().addProtectionTax(targetBuilding, origin.getPlayerCharacter(), TaxType.WEEKLY, msg.getWeeklyTax(), msg.getEnforceKOS() == 1 ? true : false)) { + ErrorPopupMsg.sendErrorMsg(origin.getPlayerCharacter(), "Failed to add taxes to building."); + return; + } + targetBuilding.setProtectionState(Enum.ProtectionState.PENDING); + } else if (msg.getProfitTax() != 0) { + if (!serverCity.getTOL().addProtectionTax(targetBuilding, origin.getPlayerCharacter(), TaxType.PROFIT, msg.getProfitTax(), msg.getEnforceKOS() == 1 ? true : false)) { + ErrorPopupMsg.sendErrorMsg(origin.getPlayerCharacter(), "Failed to add taxes to building."); + return; + } + targetBuilding.setProtectionState(Enum.ProtectionState.PENDING); + } else + targetBuilding.setProtectionState(Enum.ProtectionState.CONTRACT); - case REMOVETAX: - targetBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID()); - if (targetBuilding == null) - return true; + outMsg = new ManageNPCMsg(vendor); + dispatch = Dispatch.borrow(origin.getPlayerCharacter(), outMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } - targetBuilding.removeTaxes(); - unprotectAsset(targetBuilding, null, origin); + private static void unprotectAsset(Building targetBuilding, NPC vendor, ClientConnection origin) { - ManageCityAssetsMsg mca = new ManageCityAssetsMsg(origin.getPlayerCharacter(),targetBuilding); + if (targetBuilding == null) + return; - // Action TYPE - mca.actionType = 3; - mca.setTargetType(targetBuilding.getObjectType().ordinal()); - mca.setTargetID(targetBuilding.getObjectUUID()); - mca.setTargetType3(targetBuilding.getObjectType().ordinal()); - mca.setTargetID3(targetBuilding.getObjectUUID()); - mca.setAssetName1(targetBuilding.getName()); - mca.setUnknown54(1); - dispatch = Dispatch.borrow(player, mca); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - return true; + // Early exit if UUID < the last database derived building UUID. - case ACCEPTTAX: //AcceptTax + if (targetBuilding.getProtectionState() == Enum.ProtectionState.NPC) { + return; + } - targetBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID()); + if (targetBuilding.getProtectionState() == engine.Enum.ProtectionState.NONE) + return; - if (targetBuilding == null) - return true; + if (GuildStatusController.isInnerCouncil(origin.getPlayerCharacter().getGuildStatus()) == false) + return; - targetBuilding.acceptTaxes(); + targetBuilding.removeTaxes(); - mca = new ManageCityAssetsMsg(origin.getPlayerCharacter(),targetBuilding); + targetBuilding.setProtectionState(engine.Enum.ProtectionState.NONE); - // Action TYPE - mca.actionType = 3; - mca.setTargetType(targetBuilding.getObjectType().ordinal()); - mca.setTargetID(targetBuilding.getObjectUUID()); - mca.setTargetType3(targetBuilding.getObjectType().ordinal()); - mca.setTargetID3(targetBuilding.getObjectUUID()); - mca.setAssetName1(targetBuilding.getName()); - mca.setUnknown54(1); + } - dispatch = Dispatch.borrow(player, mca); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - return true; - } + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - dispatch = Dispatch.borrow(player, baseMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + // Member variable declaration - return true; + PlayerCharacter player; + NPC vendor; + Building targetBuilding; + Dispatch dispatch; - } + AssetSupportMsg msg; + CityAssetMsg outMsg; - private static void protectAsset(AssetSupportMsg msg, Building targetBuilding, NPC vendor, ClientConnection origin) { + // Member variable assignment - // Member variable declaration + msg = (AssetSupportMsg) baseMsg; - Zone serverZone; - City serverCity; - ManageNPCMsg outMsg; - int protectionSlots; - Dispatch dispatch; + player = SessionManager.getPlayerCharacter(origin); - // Member variable assignment + if (player == null) + return true; - if (targetBuilding == null) - return; + vendor = NPC.getFromCache(msg.getNpcID()); - serverZone = vendor.getParentZone(); + if (msg.getMessageType() != 6 && msg.getMessageType() != 7) { + if (vendor == null) + return true; - if (serverZone == null) - return; + vendor.getBuilding(); - serverCity = City.GetCityFromCache(serverZone.getPlayerCityUUID()); + if (vendor.getBuilding() == null) + return true; + } - if (serverCity == null) - return; - if (!serverCity.isLocationOnCityZone(targetBuilding.getLoc())){ - ErrorPopupMsg.sendErrorMsg(origin.getPlayerCharacter(), "Structura must be on city zone for to protect."); - return; - } + SupportMsgType supportType = SupportMsgType.typeLookup.get(msg.getMessageType()); - if ((serverCity.getTOL() == null)|| (serverCity.getTOL().getRank() < 1)) - return; + if (supportType == null) { + supportType = Enum.SupportMsgType.NONE; + Logger.error("No enumeration for support type" + msg.getMessageType()); + } + switch (supportType) { - if (serverCity.protectionEnforced == false) { - ErrorPopupMsg.sendErrorMsg(origin.getPlayerCharacter(), "Runemaster can not protect structura during bane!"); - return; - } + case PROTECT: + targetBuilding = BuildingManager.getBuildingFromCache(msg.getProtectedBuildingID()); + protectAsset(msg, targetBuilding, vendor, origin); + break; + case UNPROTECT: + targetBuilding = BuildingManager.getBuildingFromCache(msg.getProtectedBuildingID()); + unprotectAsset(targetBuilding, vendor, origin); + break; + case VIEWUNPROTECTED: + outMsg = new CityAssetMsg(); + outMsg.setBuildingID(msg.getBuildingID()); + outMsg.configure(); - if (serverCity.getRuneMaster() == null) { - ErrorPopupMsg.sendErrorMsg(origin.getPlayerCharacter(), "Runemaster is needed for to protect structura!"); - return; - } + dispatch = Dispatch.borrow(player, outMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + break; - // Enforce runemaster protection limits + case REMOVETAX: + targetBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID()); - protectionSlots = (2 * serverCity.getRuneMaster().getRank()) + 6; + if (targetBuilding == null) + return true; - if (serverCity.getRuneMaster().getProtectedBuildings().size() >= - protectionSlots) { - ErrorPopupMsg.sendErrorMsg(origin.getPlayerCharacter(), "Runemaster can only protect " + protectionSlots + " structura!"); - return; - } + targetBuilding.removeTaxes(); + unprotectAsset(targetBuilding, null, origin); - if (msg.getWeeklyTax() != 0){ - if (!serverCity.getTOL().addProtectionTax(targetBuilding, origin.getPlayerCharacter(), TaxType.WEEKLY, msg.getWeeklyTax(), msg.getEnforceKOS() == 1 ? true: false)){ - ErrorPopupMsg.sendErrorMsg(origin.getPlayerCharacter(), "Failed to add taxes to building."); - return; - } - targetBuilding.setProtectionState(Enum.ProtectionState.PENDING); - }else if (msg.getProfitTax() != 0){ - if (!serverCity.getTOL().addProtectionTax(targetBuilding, origin.getPlayerCharacter(), TaxType.PROFIT, msg.getProfitTax(), msg.getEnforceKOS() == 1 ? true: false)){ - ErrorPopupMsg.sendErrorMsg(origin.getPlayerCharacter(), "Failed to add taxes to building."); - return; - } - targetBuilding.setProtectionState(Enum.ProtectionState.PENDING); - }else - targetBuilding.setProtectionState(Enum.ProtectionState.CONTRACT); + ManageCityAssetsMsg mca = new ManageCityAssetsMsg(origin.getPlayerCharacter(), targetBuilding); + // Action TYPE + mca.actionType = 3; + mca.setTargetType(targetBuilding.getObjectType().ordinal()); + mca.setTargetID(targetBuilding.getObjectUUID()); + mca.setTargetType3(targetBuilding.getObjectType().ordinal()); + mca.setTargetID3(targetBuilding.getObjectUUID()); + mca.setAssetName1(targetBuilding.getName()); + mca.setUnknown54(1); + dispatch = Dispatch.borrow(player, mca); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + return true; + case ACCEPTTAX: //AcceptTax - outMsg = new ManageNPCMsg(vendor); - dispatch = Dispatch.borrow(origin.getPlayerCharacter(), outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } + targetBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID()); - private static void unprotectAsset(Building targetBuilding, NPC vendor, ClientConnection origin) { + if (targetBuilding == null) + return true; - if (targetBuilding == null) - return; + targetBuilding.acceptTaxes(); - // Early exit if UUID < the last database derived building UUID. + mca = new ManageCityAssetsMsg(origin.getPlayerCharacter(), targetBuilding); - if (targetBuilding.getProtectionState() == Enum.ProtectionState.NPC) { - return; - } + // Action TYPE + mca.actionType = 3; + mca.setTargetType(targetBuilding.getObjectType().ordinal()); + mca.setTargetID(targetBuilding.getObjectUUID()); + mca.setTargetType3(targetBuilding.getObjectType().ordinal()); + mca.setTargetID3(targetBuilding.getObjectUUID()); + mca.setAssetName1(targetBuilding.getName()); + mca.setUnknown54(1); - if (targetBuilding.getProtectionState() == engine.Enum.ProtectionState.NONE) - return; + dispatch = Dispatch.borrow(player, mca); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + return true; + } - if (GuildStatusController.isInnerCouncil(origin.getPlayerCharacter().getGuildStatus()) == false) - return; + dispatch = Dispatch.borrow(player, baseMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - targetBuilding.removeTaxes(); + return true; - targetBuilding.setProtectionState(engine.Enum.ProtectionState.NONE); - - } + } } diff --git a/src/engine/net/client/handlers/BanishUnbanishHandler.java b/src/engine/net/client/handlers/BanishUnbanishHandler.java index 1bc83365..e2a88482 100644 --- a/src/engine/net/client/handlers/BanishUnbanishHandler.java +++ b/src/engine/net/client/handlers/BanishUnbanishHandler.java @@ -30,100 +30,97 @@ import org.joda.time.DateTime; public class BanishUnbanishHandler extends AbstractClientMsgHandler { - public BanishUnbanishHandler() { - super(BanishUnbanishMsg.class); - } - - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - BanishUnbanishMsg msg = (BanishUnbanishMsg) baseMsg; - Dispatch dispatch; - - int target = msg.getTarget(); - PlayerCharacter source = origin.getPlayerCharacter(); - - if(source == null || source.getGuild().isEmptyGuild() || source.getGuild().getObjectUUID() == 0) - return true; - - if (GuildStatusController.isGuildLeader(source.getGuildStatus()) == false && GuildStatusController.isInnerCouncil(source.getGuildStatus()) == false) - return true; - - if (source.getObjectUUID() == target) { - ErrorPopupMsg.sendErrorPopup(source, 103); // You may not banish this char - return true; - } - - boolean success = false; - Guild guild = source.getGuild(); - PlayerCharacter realizedTarget = PlayerCharacter.getFromCache(target); - - if(realizedTarget != null) { - // Guild leader can't leave guild. must pass GL or disband - if ( GuildStatusController.isGuildLeader(realizedTarget.getGuildStatus()) == false) { - //ICs cannot banish other ICs - if (!(GuildStatusController.isInnerCouncil(realizedTarget.getGuildStatus()) && GuildStatusController.isGuildLeader(source.getGuildStatus()) == false)) { - success = true; - if (msg.getMsgType() == 1){ - if (!DbManager.GuildQueries.ADD_TO_BANISHED_FROM_GUILDLIST(guild.getObjectUUID(), realizedTarget.getObjectUUID())){ - ChatManager.chatGuildError(source, "Failed To unbanish " + realizedTarget.getName()); - return true; - } - guild.getBanishList().remove(realizedTarget); - } - - - else{ - - if (!DbManager.GuildQueries.ADD_TO_BANISHED_FROM_GUILDLIST(guild.getObjectUUID(), realizedTarget.getObjectUUID())){ - ChatManager.chatGuildError(source, "Failed To Banish " + realizedTarget.getName()); - return true; - } - guild.removePlayer(realizedTarget, GuildHistoryType.BANISHED); - guild.getBanishList().add(realizedTarget); //TODO we might encapsulate this a bit better; also not sure that a list of PC objects is really ideal - } - - } - } - } else { - if (guild.getGuildLeaderUUID() != target) { - PlayerCharacter toBanish = PlayerCharacter.getPlayerCharacter(target); - if (toBanish == null) - return true; - //already added previously. - if (SessionManager.getPlayerCharacterByID(toBanish.getObjectUUID()) != null) - return true; - - if(DbManager.GuildQueries.BANISH_FROM_GUILD_OFFLINE(target, GuildStatusController.isGuildLeader(source.getGuildStatus())) != 0) { - - success = true; - - //Set guild history - - if (DbManager.GuildQueries.ADD_TO_GUILDHISTORY(guild.getObjectUUID(), toBanish, DateTime.now(), GuildHistoryType.BANISHED)){ - GuildHistory guildHistory = new GuildHistory(toBanish.getGuildUUID(),toBanish.getGuild().getName(),DateTime.now(), GuildHistoryType.BANISHED) ; - toBanish.getGuildHistory().add(guildHistory); - } - } - } - } - - - if(success) { - //TODO re enable this once we get unbanish working!!!! - //DbManager.GuildQueries.ADD_TO_BANISHED_FROM_GUILDLIST(guild.getobjectUUID(), target); - - // Send left guild message to rest of guild - String targetName = PlayerCharacter.getFirstName(target); - ChatManager.chatGuildInfo(guild, - targetName + " has been banished from " + guild.getName() + '.'); - GuildListMsg guildListMsg = new GuildListMsg(guild); - dispatch = Dispatch.borrow(source, guildListMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } else { - ErrorPopupMsg.sendErrorPopup(source, 103); // You may not banish this char - } - return true; - - } + public BanishUnbanishHandler() { + super(BanishUnbanishMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + BanishUnbanishMsg msg = (BanishUnbanishMsg) baseMsg; + Dispatch dispatch; + + int target = msg.getTarget(); + PlayerCharacter source = origin.getPlayerCharacter(); + + if (source == null || source.getGuild().isEmptyGuild() || source.getGuild().getObjectUUID() == 0) + return true; + + if (GuildStatusController.isGuildLeader(source.getGuildStatus()) == false && GuildStatusController.isInnerCouncil(source.getGuildStatus()) == false) + return true; + + if (source.getObjectUUID() == target) { + ErrorPopupMsg.sendErrorPopup(source, 103); // You may not banish this char + return true; + } + + boolean success = false; + Guild guild = source.getGuild(); + PlayerCharacter realizedTarget = PlayerCharacter.getFromCache(target); + + if (realizedTarget != null) { + // Guild leader can't leave guild. must pass GL or disband + if (GuildStatusController.isGuildLeader(realizedTarget.getGuildStatus()) == false) { + //ICs cannot banish other ICs + if (!(GuildStatusController.isInnerCouncil(realizedTarget.getGuildStatus()) && GuildStatusController.isGuildLeader(source.getGuildStatus()) == false)) { + success = true; + if (msg.getMsgType() == 1) { + if (!DbManager.GuildQueries.ADD_TO_BANISHED_FROM_GUILDLIST(guild.getObjectUUID(), realizedTarget.getObjectUUID())) { + ChatManager.chatGuildError(source, "Failed To unbanish " + realizedTarget.getName()); + return true; + } + guild.getBanishList().remove(realizedTarget); + } else { + + if (!DbManager.GuildQueries.ADD_TO_BANISHED_FROM_GUILDLIST(guild.getObjectUUID(), realizedTarget.getObjectUUID())) { + ChatManager.chatGuildError(source, "Failed To Banish " + realizedTarget.getName()); + return true; + } + guild.removePlayer(realizedTarget, GuildHistoryType.BANISHED); + guild.getBanishList().add(realizedTarget); //TODO we might encapsulate this a bit better; also not sure that a list of PC objects is really ideal + } + + } + } + } else { + if (guild.getGuildLeaderUUID() != target) { + PlayerCharacter toBanish = PlayerCharacter.getPlayerCharacter(target); + if (toBanish == null) + return true; + //already added previously. + if (SessionManager.getPlayerCharacterByID(toBanish.getObjectUUID()) != null) + return true; + + if (DbManager.GuildQueries.BANISH_FROM_GUILD_OFFLINE(target, GuildStatusController.isGuildLeader(source.getGuildStatus())) != 0) { + + success = true; + + //Set guild history + + if (DbManager.GuildQueries.ADD_TO_GUILDHISTORY(guild.getObjectUUID(), toBanish, DateTime.now(), GuildHistoryType.BANISHED)) { + GuildHistory guildHistory = new GuildHistory(toBanish.getGuildUUID(), toBanish.getGuild().getName(), DateTime.now(), GuildHistoryType.BANISHED); + toBanish.getGuildHistory().add(guildHistory); + } + } + } + } + + + if (success) { + //TODO re enable this once we get unbanish working!!!! + //DbManager.GuildQueries.ADD_TO_BANISHED_FROM_GUILDLIST(guild.getobjectUUID(), target); + + // Send left guild message to rest of guild + String targetName = PlayerCharacter.getFirstName(target); + ChatManager.chatGuildInfo(guild, + targetName + " has been banished from " + guild.getName() + '.'); + GuildListMsg guildListMsg = new GuildListMsg(guild); + dispatch = Dispatch.borrow(source, guildListMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } else { + ErrorPopupMsg.sendErrorPopup(source, 103); // You may not banish this char + } + return true; + + } } diff --git a/src/engine/net/client/handlers/BreakFealtyHandler.java b/src/engine/net/client/handlers/BreakFealtyHandler.java index 7d9a393c..c713d7d6 100644 --- a/src/engine/net/client/handlers/BreakFealtyHandler.java +++ b/src/engine/net/client/handlers/BreakFealtyHandler.java @@ -31,161 +31,160 @@ import java.util.ArrayList; public class BreakFealtyHandler extends AbstractClientMsgHandler { - public BreakFealtyHandler() { - super(BreakFealtyMsg.class); - } + public BreakFealtyHandler() { + super(BreakFealtyMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - BreakFealtyMsg bfm; - PlayerCharacter player; - Guild toBreak; - Guild guild; - Dispatch dispatch; + BreakFealtyMsg bfm; + PlayerCharacter player; + Guild toBreak; + Guild guild; + Dispatch dispatch; - bfm = (BreakFealtyMsg) baseMsg; + bfm = (BreakFealtyMsg) baseMsg; - // get PlayerCharacter of person accepting invite + // get PlayerCharacter of person accepting invite - player = SessionManager.getPlayerCharacter( - origin); + player = SessionManager.getPlayerCharacter( + origin); - if (player == null) - return true; + if (player == null) + return true; - toBreak = (Guild) DbManager.getObject(GameObjectType.Guild, bfm.getGuildUUID()); + toBreak = (Guild) DbManager.getObject(GameObjectType.Guild, bfm.getGuildUUID()); - if (toBreak == null) { - ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occured. Please post details for to ensure transaction integrity"); - return true; - } + if (toBreak == null) { + ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occured. Please post details for to ensure transaction integrity"); + return true; + } - guild = player.getGuild(); + guild = player.getGuild(); - if (guild == null) { - ErrorPopupMsg.sendErrorMsg(player, "You do not belong to a guild!"); - return true; - } + if (guild == null) { + ErrorPopupMsg.sendErrorMsg(player, "You do not belong to a guild!"); + return true; + } - if (toBreak.isNPCGuild()){ - if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false) { - ErrorPopupMsg.sendErrorMsg(player, "Only guild leader can break fealty!"); - return true; - } + if (toBreak.isNPCGuild()) { + if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false) { + ErrorPopupMsg.sendErrorMsg(player, "Only guild leader can break fealty!"); + return true; + } - if (!DbManager.GuildQueries.UPDATE_PARENT(guild.getObjectUUID(), WorldServer.worldUUID)) { - ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - return true; - } + if (!DbManager.GuildQueries.UPDATE_PARENT(guild.getObjectUUID(), WorldServer.worldUUID)) { + ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + return true; + } - switch (guild.getGuildState()) { - case Sworn: - guild.setNation(null); - GuildManager.updateAllGuildTags(guild); - GuildManager.updateAllGuildBinds(guild, null); - break; - case Province: - guild.setNation(guild); - GuildManager.updateAllGuildTags(guild); - GuildManager.updateAllGuildBinds(guild, guild.getOwnedCity()); - break; - } + switch (guild.getGuildState()) { + case Sworn: + guild.setNation(null); + GuildManager.updateAllGuildTags(guild); + GuildManager.updateAllGuildBinds(guild, null); + break; + case Province: + guild.setNation(guild); + GuildManager.updateAllGuildTags(guild); + GuildManager.updateAllGuildBinds(guild, guild.getOwnedCity()); + break; + } - guild.downgradeGuildState(); + guild.downgradeGuildState(); - SendGuildEntryMsg msg = new SendGuildEntryMsg(player); - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + SendGuildEntryMsg msg = new SendGuildEntryMsg(player); + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - //Update Map. + //Update Map. - final Session s = SessionManager.getSession(player); + final Session s = SessionManager.getSession(player); - City.lastCityUpdate = System.currentTimeMillis(); + City.lastCityUpdate = System.currentTimeMillis(); - ArrayList guildMembers = SessionManager.getActivePCsInGuildID(guild.getObjectUUID()); + ArrayList guildMembers = SessionManager.getActivePCsInGuildID(guild.getObjectUUID()); - for (PlayerCharacter member : guildMembers) { - ChatManager.chatGuildInfo(member, guild.getName() + " has broke fealty from " + toBreak.getName() + '!'); - } + for (PlayerCharacter member : guildMembers) { + ChatManager.chatGuildInfo(member, guild.getName() + " has broke fealty from " + toBreak.getName() + '!'); + } - ArrayList breakFealtyMembers = SessionManager.getActivePCsInGuildID(toBreak.getObjectUUID()); + ArrayList breakFealtyMembers = SessionManager.getActivePCsInGuildID(toBreak.getObjectUUID()); - for (PlayerCharacter member : breakFealtyMembers) { - ChatManager.chatGuildInfo(member, guild.getName() + " has broken fealty from " + toBreak.getName() + '!'); - } + for (PlayerCharacter member : breakFealtyMembers) { + ChatManager.chatGuildInfo(member, guild.getName() + " has broken fealty from " + toBreak.getName() + '!'); + } - return true; + return true; - } + } - if (!toBreak.getSubGuildList().contains(guild)) { - ErrorPopupMsg.sendErrorMsg(player, "Failure to break fealty!"); - return true; - } + if (!toBreak.getSubGuildList().contains(guild)) { + ErrorPopupMsg.sendErrorMsg(player, "Failure to break fealty!"); + return true; + } - if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false) { - ErrorPopupMsg.sendErrorMsg(player, "Only guild leader can break fealty!"); - return true; - } + if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false) { + ErrorPopupMsg.sendErrorMsg(player, "Only guild leader can break fealty!"); + return true; + } - if (Bane.getBaneByAttackerGuild(guild) != null) - { - ErrorPopupMsg.sendErrorMsg(player, "You may break fealty with active bane!"); - return true; - } + if (Bane.getBaneByAttackerGuild(guild) != null) { + ErrorPopupMsg.sendErrorMsg(player, "You may break fealty with active bane!"); + return true; + } - if (!DbManager.GuildQueries.UPDATE_PARENT(guild.getObjectUUID(), WorldServer.worldUUID)) { - ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - return true; - } + if (!DbManager.GuildQueries.UPDATE_PARENT(guild.getObjectUUID(), WorldServer.worldUUID)) { + ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + return true; + } - switch (guild.getGuildState()) { - case Sworn: - guild.setNation(null); - GuildManager.updateAllGuildTags(guild); - GuildManager.updateAllGuildBinds(guild, null); - break; - case Province: - guild.setNation(guild); - GuildManager.updateAllGuildTags(guild); - GuildManager.updateAllGuildBinds(guild, guild.getOwnedCity()); - break; - } + switch (guild.getGuildState()) { + case Sworn: + guild.setNation(null); + GuildManager.updateAllGuildTags(guild); + GuildManager.updateAllGuildBinds(guild, null); + break; + case Province: + guild.setNation(guild); + GuildManager.updateAllGuildTags(guild); + GuildManager.updateAllGuildBinds(guild, guild.getOwnedCity()); + break; + } - guild.downgradeGuildState(); - toBreak.getSubGuildList().remove(guild); + guild.downgradeGuildState(); + toBreak.getSubGuildList().remove(guild); - if (toBreak.getSubGuildList().isEmpty()) - toBreak.downgradeGuildState(); + if (toBreak.getSubGuildList().isEmpty()) + toBreak.downgradeGuildState(); - SendGuildEntryMsg msg = new SendGuildEntryMsg(player); - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + SendGuildEntryMsg msg = new SendGuildEntryMsg(player); + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - //Update Map. + //Update Map. - final Session s = SessionManager.getSession(player); + final Session s = SessionManager.getSession(player); - City.lastCityUpdate = System.currentTimeMillis(); + City.lastCityUpdate = System.currentTimeMillis(); - ArrayList guildMembers = SessionManager.getActivePCsInGuildID(guild.getObjectUUID()); + ArrayList guildMembers = SessionManager.getActivePCsInGuildID(guild.getObjectUUID()); - for (PlayerCharacter member : guildMembers) { - ChatManager.chatGuildInfo(member, guild.getName() + " has broke fealty from " + toBreak.getName() + '!'); - } + for (PlayerCharacter member : guildMembers) { + ChatManager.chatGuildInfo(member, guild.getName() + " has broke fealty from " + toBreak.getName() + '!'); + } - ArrayList breakFealtyMembers = SessionManager.getActivePCsInGuildID(toBreak.getObjectUUID()); + ArrayList breakFealtyMembers = SessionManager.getActivePCsInGuildID(toBreak.getObjectUUID()); - for (PlayerCharacter member : breakFealtyMembers) { - ChatManager.chatGuildInfo(member, guild.getName() + " has broken fealty from " + toBreak.getName() + '!'); - } + for (PlayerCharacter member : breakFealtyMembers) { + ChatManager.chatGuildInfo(member, guild.getName() + " has broken fealty from " + toBreak.getName() + '!'); + } - return true; - } + return true; + } } diff --git a/src/engine/net/client/handlers/ChangeAltitudeHandler.java b/src/engine/net/client/handlers/ChangeAltitudeHandler.java index 9da70492..cdc2ea99 100644 --- a/src/engine/net/client/handlers/ChangeAltitudeHandler.java +++ b/src/engine/net/client/handlers/ChangeAltitudeHandler.java @@ -24,167 +24,157 @@ import org.pmw.tinylog.Logger; public class ChangeAltitudeHandler extends AbstractClientMsgHandler { - public ChangeAltitudeHandler() { - super(ChangeAltitudeMsg.class); - } - - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, - ClientConnection origin) throws MsgSendException { - - ChangeAltitudeMsg msg = (ChangeAltitudeMsg) baseMsg; - - PlayerCharacter pc = origin.getPlayerCharacter(); - if (pc == null) { - return false; - } - - if (!AbstractCharacter.CanFly(pc)) - return false; - - if (pc.isSwimming()) - return false; - if (pc.region != null && !pc.region.isOutside()) - return false; - - - - - - - - // Find out if we already have an altitude timer running and if so - // do not process more alt change requests - - if (pc.getTakeOffTime() != 0) - return false; - - - // remove all movement timers and jobs - //TODO: test if they can fly - - float targetAlt; - float amount = msg.getAmountToMove(); - if (amount != 10 && amount != 60) - return false; - if (pc.getAltitude() == 60 && msg.up()) - return true; - if (pc.getAltitude() == 0 && !msg.up()) - return true; - - pc.update(); - pc.stopMovement(pc.getLoc()); - msg.setStartAlt(pc.getAltitude()); - if (msg.up()) { - - pc.landingRegion = null; - if (pc.getAltitude() == 0){ - Regions upRegion = pc.region; - if (upRegion != null){ - float startAlt = 0; - Building regionBuilding = Regions.GetBuildingForRegion(upRegion); - if (upRegion != null) - startAlt = upRegion.lerpY(pc) - regionBuilding.getLoc().y; - float rounded = startAlt *.10f; - - rounded = ((int)rounded) * 10; - - if (rounded < 0) - rounded = 0; - - - msg.setStartAlt(startAlt); - targetAlt = rounded + amount; - - if (targetAlt > 60) - targetAlt = 60; - - pc.setAltitude(startAlt); - pc.setDesiredAltitude(targetAlt); - }else{ - msg.setStartAlt(pc.getAltitude()); - targetAlt = pc.getAltitude() + amount; - if (targetAlt > 60) - targetAlt = 60; - } - }else{ - msg.setStartAlt(pc.getAltitude()); - - targetAlt = pc.getAltitude() + amount; - if (targetAlt > 60) - targetAlt = 60; - } - - - } else { - msg.setStartAlt(pc.getAltitude()); - targetAlt = pc.getAltitude() - amount; - if (targetAlt < 0) - targetAlt = 0; - } - msg.setTargetAlt(targetAlt); - if (pc.getAltitude() < 1 && targetAlt > pc.getAltitude()) { - // char is on the ground and is about to start flight - if (pc.getStamina() < 10) { - return false; - } - } - - if (MBServerStatics.MOVEMENT_SYNC_DEBUG) { - Logger.info ("Changing Altitude, moving=" + pc.isMoving() + - " Current Loc " + pc.getLoc().getX() + ' ' + pc.getLoc().getZ() + - " End Loc " + pc.getEndLoc().getX() + ' ' + pc.getEndLoc().getZ()); - } - - if (msg.up()){ - pc.update(); - pc.setDesiredAltitude(targetAlt); - pc.setTakeOffTime(System.currentTimeMillis()); - } - - else{ - Regions region = PlayerCharacter.InsideBuildingRegionGoingDown(pc); - - - - if (region != null){ - float landingAltitude = 0; - Building building = Regions.GetBuildingForRegion(region); - if (building != null) - landingAltitude = region.lerpY(pc) - building.getLoc().y; - - if (landingAltitude >= targetAlt){ - pc.landingRegion = region; - pc.landingAltitude = landingAltitude; - pc.setDesiredAltitude(landingAltitude); - }else{ - pc.landingRegion = null; - pc.setDesiredAltitude(targetAlt); - } - - - }else - pc.setDesiredAltitude(targetAlt); - - pc.update(); - - - pc.setTakeOffTime(System.currentTimeMillis()); - } - - - - // Add timer for height change cooldown, this also tells getLoc we are not moving - //MovementManager.addChangeAltitudeTimer(pc, msg.getStartAlt(), msg.getTargetAlt(), (int)((MBServerStatics.HEIGHT_CHANGE_TIMER_MS * amount) + 100 ) ); - - // Add flight timer job to check stam and ground you when you run out - //MovementManager.addFlightTimer(pc, msg, MBServerStatics.FLY_FREQUENCY_MS); - //Send change altitude to all in range - DispatchMessage.dispatchMsgToInterestArea(pc, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - - - - return true; - } + public ChangeAltitudeHandler() { + super(ChangeAltitudeMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, + ClientConnection origin) throws MsgSendException { + + ChangeAltitudeMsg msg = (ChangeAltitudeMsg) baseMsg; + + PlayerCharacter pc = origin.getPlayerCharacter(); + if (pc == null) { + return false; + } + + if (!AbstractCharacter.CanFly(pc)) + return false; + + if (pc.isSwimming()) + return false; + if (pc.region != null && !pc.region.isOutside()) + return false; + + + // Find out if we already have an altitude timer running and if so + // do not process more alt change requests + + if (pc.getTakeOffTime() != 0) + return false; + + + // remove all movement timers and jobs + //TODO: test if they can fly + + float targetAlt; + float amount = msg.getAmountToMove(); + if (amount != 10 && amount != 60) + return false; + if (pc.getAltitude() == 60 && msg.up()) + return true; + if (pc.getAltitude() == 0 && !msg.up()) + return true; + + pc.update(); + pc.stopMovement(pc.getLoc()); + msg.setStartAlt(pc.getAltitude()); + if (msg.up()) { + + pc.landingRegion = null; + if (pc.getAltitude() == 0) { + Regions upRegion = pc.region; + if (upRegion != null) { + float startAlt = 0; + Building regionBuilding = Regions.GetBuildingForRegion(upRegion); + if (upRegion != null) + startAlt = upRegion.lerpY(pc) - regionBuilding.getLoc().y; + float rounded = startAlt * .10f; + + rounded = ((int) rounded) * 10; + + if (rounded < 0) + rounded = 0; + + + msg.setStartAlt(startAlt); + targetAlt = rounded + amount; + + if (targetAlt > 60) + targetAlt = 60; + + pc.setAltitude(startAlt); + pc.setDesiredAltitude(targetAlt); + } else { + msg.setStartAlt(pc.getAltitude()); + targetAlt = pc.getAltitude() + amount; + if (targetAlt > 60) + targetAlt = 60; + } + } else { + msg.setStartAlt(pc.getAltitude()); + + targetAlt = pc.getAltitude() + amount; + if (targetAlt > 60) + targetAlt = 60; + } + + + } else { + msg.setStartAlt(pc.getAltitude()); + targetAlt = pc.getAltitude() - amount; + if (targetAlt < 0) + targetAlt = 0; + } + msg.setTargetAlt(targetAlt); + if (pc.getAltitude() < 1 && targetAlt > pc.getAltitude()) { + // char is on the ground and is about to start flight + if (pc.getStamina() < 10) { + return false; + } + } + + if (MBServerStatics.MOVEMENT_SYNC_DEBUG) { + Logger.info("Changing Altitude, moving=" + pc.isMoving() + + " Current Loc " + pc.getLoc().getX() + ' ' + pc.getLoc().getZ() + + " End Loc " + pc.getEndLoc().getX() + ' ' + pc.getEndLoc().getZ()); + } + + if (msg.up()) { + pc.update(); + pc.setDesiredAltitude(targetAlt); + pc.setTakeOffTime(System.currentTimeMillis()); + } else { + Regions region = PlayerCharacter.InsideBuildingRegionGoingDown(pc); + + + if (region != null) { + float landingAltitude = 0; + Building building = Regions.GetBuildingForRegion(region); + if (building != null) + landingAltitude = region.lerpY(pc) - building.getLoc().y; + + if (landingAltitude >= targetAlt) { + pc.landingRegion = region; + pc.landingAltitude = landingAltitude; + pc.setDesiredAltitude(landingAltitude); + } else { + pc.landingRegion = null; + pc.setDesiredAltitude(targetAlt); + } + + + } else + pc.setDesiredAltitude(targetAlt); + + pc.update(); + + + pc.setTakeOffTime(System.currentTimeMillis()); + } + + + // Add timer for height change cooldown, this also tells getLoc we are not moving + //MovementManager.addChangeAltitudeTimer(pc, msg.getStartAlt(), msg.getTargetAlt(), (int)((MBServerStatics.HEIGHT_CHANGE_TIMER_MS * amount) + 100 ) ); + + // Add flight timer job to check stam and ground you when you run out + //MovementManager.addFlightTimer(pc, msg, MBServerStatics.FLY_FREQUENCY_MS); + //Send change altitude to all in range + DispatchMessage.dispatchMsgToInterestArea(pc, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + + + return true; + } } diff --git a/src/engine/net/client/handlers/ChangeGuildLeaderHandler.java b/src/engine/net/client/handlers/ChangeGuildLeaderHandler.java index 585f28a5..fe21996b 100644 --- a/src/engine/net/client/handlers/ChangeGuildLeaderHandler.java +++ b/src/engine/net/client/handlers/ChangeGuildLeaderHandler.java @@ -28,120 +28,113 @@ import engine.objects.PlayerCharacter; public class ChangeGuildLeaderHandler extends AbstractClientMsgHandler { - public ChangeGuildLeaderHandler() { - super(ChangeGuildLeaderMsg.class); - } + public ChangeGuildLeaderHandler() { + super(ChangeGuildLeaderMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - ChangeGuildLeaderMsg msg; - PlayerCharacter sourcePlayer; - PlayerCharacter targetPlayer; - City city; + ChangeGuildLeaderMsg msg; + PlayerCharacter sourcePlayer; + PlayerCharacter targetPlayer; + City city; - msg = (ChangeGuildLeaderMsg) baseMsg; - sourcePlayer = origin.getPlayerCharacter(); - if (sourcePlayer == null) - return true; - if (GuildStatusController.isGuildLeader(sourcePlayer.getGuildStatus()) == false) - return true; + msg = (ChangeGuildLeaderMsg) baseMsg; + sourcePlayer = origin.getPlayerCharacter(); + if (sourcePlayer == null) + return true; + if (GuildStatusController.isGuildLeader(sourcePlayer.getGuildStatus()) == false) + return true; + Guild glGuild = sourcePlayer.getGuild(); - Guild glGuild = sourcePlayer.getGuild(); + if (glGuild == null) + return true; - if (glGuild == null) - return true; + if (!glGuild.isGuildLeader(sourcePlayer.getObjectUUID())) + return true; + targetPlayer = (PlayerCharacter) DbManager.getObject(GameObjectType.PlayerCharacter, msg.getTargetID()); - if (!glGuild.isGuildLeader(sourcePlayer.getObjectUUID())) - return true; - targetPlayer = (PlayerCharacter) DbManager.getObject(GameObjectType.PlayerCharacter, msg.getTargetID()); + if (targetPlayer == null) + return true; - if (targetPlayer == null) - return true; + if (GuildStatusController.isGuildLeader(targetPlayer.getGuildStatus())) + return true; - if (GuildStatusController.isGuildLeader(targetPlayer.getGuildStatus())) - return true; + if (!Guild.sameGuild(sourcePlayer.getGuild(), targetPlayer.getGuild())) + return false; - if (!Guild.sameGuild(sourcePlayer.getGuild(),targetPlayer.getGuild())) - return false; + //updateSource will generate a new promote/demote screen for sourcePlayer + //updateTarget will sync guild info for the target and all players in range - //updateSource will generate a new promote/demote screen for sourcePlayer - //updateTarget will sync guild info for the target and all players in range + String targetName = null; + boolean isMale = true; + boolean updateTarget; + Enum.GuildType t = Enum.GuildType.getGuildTypeFromInt(sourcePlayer.getGuild().getCharter()); - String targetName = null; - boolean isMale = true; - boolean updateTarget; + if (!DbManager.GuildQueries.SET_GUILD_LEADER(targetPlayer.getObjectUUID(), glGuild.getObjectUUID())) { + ChatManager.chatGuildError(sourcePlayer, "Failed to change guild leader!"); + return false; + } - Enum.GuildType t = Enum.GuildType.getGuildTypeFromInt(sourcePlayer.getGuild().getCharter()); + glGuild.setGuildLeader(targetPlayer); - if (!DbManager.GuildQueries.SET_GUILD_LEADER(targetPlayer.getObjectUUID(), glGuild.getObjectUUID())){ - ChatManager.chatGuildError(sourcePlayer, "Failed to change guild leader!"); - return false; - } + if (glGuild.getOwnedCity() != null) { + city = glGuild.getOwnedCity(); + if (!city.transferGuildLeader(targetPlayer)) { + ChatManager.chatGuildError(sourcePlayer, "Failed to Transfer City Objects. Contact CCR!"); + return false; + } - glGuild.setGuildLeader(targetPlayer); + } + targetPlayer.setGuildLeader(true); + targetPlayer.setInnerCouncil(true); + targetPlayer.setFullMember(true); + targetPlayer.incVer(); + targetName = targetPlayer.getFirstName(); + updateTarget = true; - if (glGuild.getOwnedCity() != null){ - city = glGuild.getOwnedCity(); - if (!city.transferGuildLeader(targetPlayer)){ - ChatManager.chatGuildError(sourcePlayer, "Failed to Transfer City Objects. Contact CCR!"); - return false; - } - } + ChatManager.chatGuildInfo(sourcePlayer.getGuild(), + targetName + " has been promoted to " + + "guild leader!"); + //These values record a change, not the new value... - targetPlayer.setGuildLeader(true); - targetPlayer.setInnerCouncil(true); - targetPlayer.setFullMember(true); - targetPlayer.incVer(); - targetName = targetPlayer.getFirstName(); - updateTarget = true; + //updateOldGuildLeader + sourcePlayer.setInnerCouncil(true); + sourcePlayer.setFullMember(true); + sourcePlayer.setGuildLeader(false); + sourcePlayer.incVer(); + GuildInfoMsg guildInfoMsg = new GuildInfoMsg(sourcePlayer, sourcePlayer.getGuild(), 2); + Dispatch dispatch = Dispatch.borrow(sourcePlayer, guildInfoMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - ChatManager.chatGuildInfo(sourcePlayer.getGuild(), - targetName + " has been promoted to " - + "guild leader!"); + GuildListMsg guildListMsg = new GuildListMsg(sourcePlayer.getGuild()); - //These values record a change, not the new value... + dispatch = Dispatch.borrow(sourcePlayer, guildListMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + if (targetPlayer != null) { + if (updateTarget) + DispatchMessage.sendToAllInRange(targetPlayer, new GuildInfoMsg(targetPlayer, targetPlayer.getGuild(), 2)); + } - //updateOldGuildLeader - sourcePlayer.setInnerCouncil(true); - sourcePlayer.setFullMember(true); - sourcePlayer.setGuildLeader(false); - sourcePlayer.incVer(); - - GuildInfoMsg guildInfoMsg = new GuildInfoMsg(sourcePlayer, sourcePlayer.getGuild(), 2); - Dispatch dispatch = Dispatch.borrow(sourcePlayer, guildInfoMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + return true; - GuildListMsg guildListMsg = new GuildListMsg(sourcePlayer.getGuild()); - - dispatch = Dispatch.borrow(sourcePlayer, guildListMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - - - - if (targetPlayer != null) { - if (updateTarget) - DispatchMessage.sendToAllInRange(targetPlayer, new GuildInfoMsg(targetPlayer, targetPlayer.getGuild(), 2)); - } - - return true; - - } + } } diff --git a/src/engine/net/client/handlers/ChangeRankHandler.java b/src/engine/net/client/handlers/ChangeRankHandler.java index cc0de5ca..db4ee68c 100644 --- a/src/engine/net/client/handlers/ChangeRankHandler.java +++ b/src/engine/net/client/handlers/ChangeRankHandler.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -57,12 +54,12 @@ public class ChangeRankHandler extends AbstractClientMsgHandler { if (msg.getPlayerUUID() == 0) targetPlayer = sourcePlayer; - //updateSource will generate a new promote/demote screen for sourcePlayer + //updateSource will generate a new promote/demote screen for sourcePlayer //updateTarget will sync guild info for the target and all players in range - + boolean updateSource = false, updateTarget = false; - if (sourcePlayer == null ||GuildStatusController.isInnerCouncil(sourcePlayer.getGuildStatus()) == false) + if (sourcePlayer == null || GuildStatusController.isInnerCouncil(sourcePlayer.getGuildStatus()) == false) return true; if (targetPlayer != null && (targetPlayer.getGuild().equals(sourcePlayer.getGuild()) == false)) @@ -88,8 +85,8 @@ public class ChangeRankHandler extends AbstractClientMsgHandler { ChatManager.chatGuildInfo(sourcePlayer.getGuild(), targetName + " has been " - + ((msg.getNewRank() > msg.getPreviousRank()) ? "pro" : "de") + "moted to " - + t.getRankForGender(msg.getNewRank(), isMale) + '!'); + + ((msg.getNewRank() > msg.getPreviousRank()) ? "pro" : "de") + "moted to " + + t.getRankForGender(msg.getNewRank(), isMale) + '!'); updateSource = true; } @@ -117,10 +114,10 @@ public class ChangeRankHandler extends AbstractClientMsgHandler { taxUpdate = (GuildStatusController.isTaxCollector(targetPlayer.getGuildStatus()) != (msg.getTax() > 0)) && GuildStatusController.isGuildLeader(sourcePlayer.getGuildStatus()); //This logic branch only executes if targetPlayer has passed a null check... - if (icUpdate){ - targetPlayer.setInnerCouncil(msg.getIc() > 0); - targetPlayer.setFullMember(true); - targetPlayer.incVer(); + if (icUpdate) { + targetPlayer.setInnerCouncil(msg.getIc() > 0); + targetPlayer.setFullMember(true); + targetPlayer.incVer(); } if (recruitUpdate) @@ -136,8 +133,8 @@ public class ChangeRankHandler extends AbstractClientMsgHandler { if (icUpdate) { ChatManager.chatGuildInfo(sourcePlayer.getGuild(), (msg.getIc() > 0) - ? targetName + " has been appointed to the inner council." - : targetName + " is no longer a member of the inner council."); + ? targetName + " has been appointed to the inner council." + : targetName + " is no longer a member of the inner council."); updateSource = true; updateTarget = true; diff --git a/src/engine/net/client/handlers/ChannelMuteMsgHandler.java b/src/engine/net/client/handlers/ChannelMuteMsgHandler.java index ba6480d8..71d40686 100644 --- a/src/engine/net/client/handlers/ChannelMuteMsgHandler.java +++ b/src/engine/net/client/handlers/ChannelMuteMsgHandler.java @@ -20,104 +20,104 @@ import org.pmw.tinylog.Logger; */ public class ChannelMuteMsgHandler extends AbstractClientMsgHandler { - // Instance variables + // Instance variables - public ChannelMuteMsgHandler() { - super(ChatFilterMsg.class); + public ChannelMuteMsgHandler() { + super(ChatFilterMsg.class); - } + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + private static void AbandonSingleAsset(PlayerCharacter sourcePlayer, + Building targetBuilding) { - return true; - } + // Transfer the building asset ownership and refresh all clients - private static void AbandonSingleAsset(PlayerCharacter sourcePlayer, - Building targetBuilding) { + DbManager.BuildingQueries.CLEAR_FRIENDS_LIST(targetBuilding.getObjectUUID()); + targetBuilding.getFriends().clear(); - // Transfer the building asset ownership and refresh all clients + DbManager.BuildingQueries.CLEAR_CONDEMNED_LIST(targetBuilding.getObjectUUID()); + targetBuilding.getCondemned().clear(); + targetBuilding.setOwner(null); + targetBuilding.refreshGuild(); + } - DbManager.BuildingQueries.CLEAR_FRIENDS_LIST(targetBuilding.getObjectUUID()); - targetBuilding.getFriends().clear(); + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - DbManager.BuildingQueries.CLEAR_CONDEMNED_LIST(targetBuilding.getObjectUUID()); - targetBuilding.getCondemned().clear(); - targetBuilding.setOwner(null); - targetBuilding.refreshGuild(); - } + return true; + } - private void AbandonAllCityObjects(PlayerCharacter sourcePlayer, - Building targetBuilding) { - Guild sourceGuild; - Zone cityZone; + private void AbandonAllCityObjects(PlayerCharacter sourcePlayer, + Building targetBuilding) { + Guild sourceGuild; + Zone cityZone; - sourceGuild = sourcePlayer.getGuild(); + sourceGuild = sourcePlayer.getGuild(); - if (sourceGuild == null) - return; + if (sourceGuild == null) + return; - if (sourceGuild.getSubGuildList().size() > 0) { - ChatManager.chatCityError(sourcePlayer, "You Cannot abandon a nation city."); - return; - } + if (sourceGuild.getSubGuildList().size() > 0) { + ChatManager.chatCityError(sourcePlayer, "You Cannot abandon a nation city."); + return; + } - cityZone = ZoneManager.findSmallestZone(targetBuilding.getLoc()); + cityZone = ZoneManager.findSmallestZone(targetBuilding.getLoc()); - // Can't abandon a tree not within a player city zone - if (cityZone.isPlayerCity() == false) - return; + // Can't abandon a tree not within a player city zone + if (cityZone.isPlayerCity() == false) + return; - if (targetBuilding.getCity().hasBeenTransfered == true) { - ChatManager.chatCityError(sourcePlayer, "City can only be abandoned once per rebooting."); - return; - } + if (targetBuilding.getCity().hasBeenTransfered == true) { + ChatManager.chatCityError(sourcePlayer, "City can only be abandoned once per rebooting."); + return; + } - // Guild no longer owns his tree. - if (!DbManager.GuildQueries.SET_GUILD_OWNED_CITY(sourceGuild.getObjectUUID(), 0)) { - Logger.error( "Failed to update Owned City to Database"); - return; - } + // Guild no longer owns his tree. + if (!DbManager.GuildQueries.SET_GUILD_OWNED_CITY(sourceGuild.getObjectUUID(), 0)) { + Logger.error("Failed to update Owned City to Database"); + return; + } - sourceGuild.setCityUUID(0); - sourceGuild.setGuildState(GuildState.Errant); - sourceGuild.setNation(null); + sourceGuild.setCityUUID(0); + sourceGuild.setGuildState(GuildState.Errant); + sourceGuild.setNation(null); - // Transfer the city assets - TransferCityAssets(sourcePlayer, targetBuilding); + // Transfer the city assets + TransferCityAssets(sourcePlayer, targetBuilding); - GuildManager.updateAllGuildTags(sourceGuild); - GuildManager.updateAllGuildBinds(sourceGuild, null); + GuildManager.updateAllGuildTags(sourceGuild); + GuildManager.updateAllGuildBinds(sourceGuild, null); - } + } - private void TransferCityAssets(PlayerCharacter sourcePlayer, - Building cityTOL) { + private void TransferCityAssets(PlayerCharacter sourcePlayer, + Building cityTOL) { - Zone cityZone; + Zone cityZone; - // Build list of buildings within this parent zone - cityZone = ZoneManager.findSmallestZone(cityTOL.getLoc()); + // Build list of buildings within this parent zone + cityZone = ZoneManager.findSmallestZone(cityTOL.getLoc()); - for (Building cityBuilding : cityZone.zoneBuildingSet) { + for (Building cityBuilding : cityZone.zoneBuildingSet) { - Blueprint cityBlueprint; - cityBlueprint = cityBuilding.getBlueprint(); + Blueprint cityBlueprint; + cityBlueprint = cityBuilding.getBlueprint(); - // Buildings without blueprints cannot be abandoned - if (cityBlueprint == null) - continue; + // Buildings without blueprints cannot be abandoned + if (cityBlueprint == null) + continue; - // Transfer ownership of valid city assets - if ((cityBlueprint.getBuildingGroup() == BuildingGroup.TOL) - || (cityBlueprint.getBuildingGroup() == BuildingGroup.SPIRE) - || (cityBlueprint.getBuildingGroup() == BuildingGroup.BARRACK) - || (cityBlueprint.isWallPiece()) - || (cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE)) - AbandonSingleAsset(sourcePlayer, cityBuilding); + // Transfer ownership of valid city assets + if ((cityBlueprint.getBuildingGroup() == BuildingGroup.TOL) + || (cityBlueprint.getBuildingGroup() == BuildingGroup.SPIRE) + || (cityBlueprint.getBuildingGroup() == BuildingGroup.BARRACK) + || (cityBlueprint.isWallPiece()) + || (cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE)) + AbandonSingleAsset(sourcePlayer, cityBuilding); - } + } - } + } } diff --git a/src/engine/net/client/handlers/CityChoiceMsgHandler.java b/src/engine/net/client/handlers/CityChoiceMsgHandler.java index 7dd79a04..32b5686c 100644 --- a/src/engine/net/client/handlers/CityChoiceMsgHandler.java +++ b/src/engine/net/client/handlers/CityChoiceMsgHandler.java @@ -22,48 +22,48 @@ import engine.objects.PlayerCharacter; public class CityChoiceMsgHandler extends AbstractClientMsgHandler { - public CityChoiceMsgHandler() { - super(CityChoiceMsg.class); - } + public CityChoiceMsgHandler() { + super(CityChoiceMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - PlayerCharacter player = origin.getPlayerCharacter(); - Dispatch dispatch; + PlayerCharacter player = origin.getPlayerCharacter(); + Dispatch dispatch; - CityChoiceMsg msg = (CityChoiceMsg) baseMsg; + CityChoiceMsg msg = (CityChoiceMsg) baseMsg; - if (player == null) - return true; + if (player == null) + return true; - switch (msg.getMsgType()) { - case 5: - TeleportRepledgeListMsg trlm = new TeleportRepledgeListMsg(player, false); - trlm.configure(); - dispatch = Dispatch.borrow(player, trlm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - break; - case 3: - City city = City.getCity(msg.getCityID()); + switch (msg.getMsgType()) { + case 5: + TeleportRepledgeListMsg trlm = new TeleportRepledgeListMsg(player, false); + trlm.configure(); + dispatch = Dispatch.borrow(player, trlm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + break; + case 3: + City city = City.getCity(msg.getCityID()); - if (city == null) - return true; + if (city == null) + return true; - Guild cityGuild = city.getGuild(); + Guild cityGuild = city.getGuild(); - if (cityGuild == null) - return true; + if (cityGuild == null) + return true; - if (player.getLevel() < cityGuild.getRepledgeMin() || player.getLevel() > cityGuild.getRepledgeMax()) - return true; + if (player.getLevel() < cityGuild.getRepledgeMin() || player.getLevel() > cityGuild.getRepledgeMax()) + return true; - //if repledge, reguild the player but set his building now. + //if repledge, reguild the player but set his building now. - GuildManager.joinGuild(player, cityGuild, city.getObjectUUID(), Enum.GuildHistoryType.JOIN); - break; - } + GuildManager.joinGuild(player, cityGuild, city.getObjectUUID(), Enum.GuildHistoryType.JOIN); + break; + } - return true; - } + return true; + } } \ No newline at end of file diff --git a/src/engine/net/client/handlers/CityDataHandler.java b/src/engine/net/client/handlers/CityDataHandler.java index 928a6964..98ca60fb 100644 --- a/src/engine/net/client/handlers/CityDataHandler.java +++ b/src/engine/net/client/handlers/CityDataHandler.java @@ -64,10 +64,10 @@ public class CityDataHandler extends AbstractClientMsgHandler { // If the hotZone has changed then update the client's map accordingly. if (playerCharacter.getTimeStamp("hotzoneupdate") <= ZoneManager.hotZoneLastUpdate.toEpochMilli() && ZoneManager.hotZone != null) { - HotzoneChangeMsg hotzoneChangeMsg = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), ZoneManager.hotZone.getObjectUUID()); - dispatch = Dispatch.borrow(playerCharacter, hotzoneChangeMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - playerCharacter.setTimeStamp("hotzoneupdate", System.currentTimeMillis() - 100); + HotzoneChangeMsg hotzoneChangeMsg = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), ZoneManager.hotZone.getObjectUUID()); + dispatch = Dispatch.borrow(playerCharacter, hotzoneChangeMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + playerCharacter.setTimeStamp("hotzoneupdate", System.currentTimeMillis() - 100); } // Serialize the realms for this map diff --git a/src/engine/net/client/handlers/ClaimAssetMsgHandler.java b/src/engine/net/client/handlers/ClaimAssetMsgHandler.java index d1dfda7c..4d1cd6d0 100644 --- a/src/engine/net/client/handlers/ClaimAssetMsgHandler.java +++ b/src/engine/net/client/handlers/ClaimAssetMsgHandler.java @@ -37,103 +37,103 @@ public class ClaimAssetMsgHandler extends AbstractClientMsgHandler { // Instance variables private final ReentrantReadWriteLock claimLock = new ReentrantReadWriteLock(); - - public ClaimAssetMsgHandler() { - super(ClaimAssetMsg.class); - - } - - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - - // Member variable declaration - this.claimLock.writeLock().lock(); - - try{ - PlayerCharacter sourcePlayer; - Building targetBuilding; - Blueprint blueprint; - ClaimAssetMsg msg; - int targetUUID; - - msg = (ClaimAssetMsg) baseMsg; - targetUUID = msg.getUUID(); - - sourcePlayer = origin.getPlayerCharacter(); - targetBuilding = BuildingManager.getBuildingFromCache(targetUUID); - - // Oops! *** Refactor: Log error - - if ((sourcePlayer == null) || - (targetBuilding == null)) - return true; - - // Player must be reasonably close to building in order to claim - - if (sourcePlayer.getLoc().distanceSquared2D(targetBuilding.getLoc()) > sqr(100)) - return true; - - // Early exit if object to be claimed is not errant - - if (targetBuilding.getOwnerUUID() != 0) - return true; - - - // Early exit if UUID < the last database derived building UUID. - - if (targetBuilding.getProtectionState() == Enum.ProtectionState.NPC) { - return true; - } - - // Early exit if claiming player does not - // have a guild. - - // Errant players cannot claim - - if (sourcePlayer.getGuild().isEmptyGuild()) - return true; - - // Can't claim an object without a blueprint - - if (targetBuilding.getBlueprintUUID() == 0) - return true; - - blueprint = targetBuilding.getBlueprint(); - - //cant claim mine this way. - if (blueprint.getBuildingGroup() == BuildingGroup.MINE) - return true; - - // Players cannot claim shrines - - if ((targetBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE)) - return true; - - // Can't claim a tree if your guild already owns one - // *** Refactor : Send error to player here - - if ((sourcePlayer.getGuild().isNation()) && - (blueprint.getBuildingGroup() == BuildingGroup.TOL)) - return true; - - // Process the transfer of the building(s) - - if (blueprint.getBuildingGroup() == BuildingGroup.TOL) { - targetBuilding.getCity().claim(sourcePlayer); - - // Push transfer of city to data warehouse - CityRecord cityRecord = CityRecord.borrow(targetBuilding.getCity(), Enum.RecordEventType.TRANSFER); - DataWarehouse.pushToWarehouse(cityRecord); - - } else - targetBuilding.claim(sourcePlayer); - - } catch(Exception e){ - Logger.error("ClaimAssetMsgHandler", e.getMessage()); - }finally{ - this.claimLock.writeLock().unlock(); + + public ClaimAssetMsgHandler() { + super(ClaimAssetMsg.class); + + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + // Member variable declaration + this.claimLock.writeLock().lock(); + + try { + PlayerCharacter sourcePlayer; + Building targetBuilding; + Blueprint blueprint; + ClaimAssetMsg msg; + int targetUUID; + + msg = (ClaimAssetMsg) baseMsg; + targetUUID = msg.getUUID(); + + sourcePlayer = origin.getPlayerCharacter(); + targetBuilding = BuildingManager.getBuildingFromCache(targetUUID); + + // Oops! *** Refactor: Log error + + if ((sourcePlayer == null) || + (targetBuilding == null)) + return true; + + // Player must be reasonably close to building in order to claim + + if (sourcePlayer.getLoc().distanceSquared2D(targetBuilding.getLoc()) > sqr(100)) + return true; + + // Early exit if object to be claimed is not errant + + if (targetBuilding.getOwnerUUID() != 0) + return true; + + + // Early exit if UUID < the last database derived building UUID. + + if (targetBuilding.getProtectionState() == Enum.ProtectionState.NPC) { + return true; } - return true; + + // Early exit if claiming player does not + // have a guild. + + // Errant players cannot claim + + if (sourcePlayer.getGuild().isEmptyGuild()) + return true; + + // Can't claim an object without a blueprint + + if (targetBuilding.getBlueprintUUID() == 0) + return true; + + blueprint = targetBuilding.getBlueprint(); + + //cant claim mine this way. + if (blueprint.getBuildingGroup() == BuildingGroup.MINE) + return true; + + // Players cannot claim shrines + + if ((targetBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE)) + return true; + + // Can't claim a tree if your guild already owns one + // *** Refactor : Send error to player here + + if ((sourcePlayer.getGuild().isNation()) && + (blueprint.getBuildingGroup() == BuildingGroup.TOL)) + return true; + + // Process the transfer of the building(s) + + if (blueprint.getBuildingGroup() == BuildingGroup.TOL) { + targetBuilding.getCity().claim(sourcePlayer); + + // Push transfer of city to data warehouse + CityRecord cityRecord = CityRecord.borrow(targetBuilding.getCity(), Enum.RecordEventType.TRANSFER); + DataWarehouse.pushToWarehouse(cityRecord); + + } else + targetBuilding.claim(sourcePlayer); + + } catch (Exception e) { + Logger.error("ClaimAssetMsgHandler", e.getMessage()); + } finally { + this.claimLock.writeLock().unlock(); } + return true; + } } \ No newline at end of file diff --git a/src/engine/net/client/handlers/ClaimGuildTreeMsgHandler.java b/src/engine/net/client/handlers/ClaimGuildTreeMsgHandler.java index 388a9c8f..dad056fd 100644 --- a/src/engine/net/client/handlers/ClaimGuildTreeMsgHandler.java +++ b/src/engine/net/client/handlers/ClaimGuildTreeMsgHandler.java @@ -31,161 +31,161 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; */ public class ClaimGuildTreeMsgHandler extends AbstractClientMsgHandler { - // Instance variables + // Instance variables - private final ReentrantReadWriteLock claimLock = new ReentrantReadWriteLock(); - private static final int RENAME_TREE = 2; - private static final int BIND_TREE = 3; - private static final int OPEN_CITY = 4; - private static final int CLOSE_CITY = 5; + private static final int RENAME_TREE = 2; + private static final int BIND_TREE = 3; + private static final int OPEN_CITY = 4; + private static final int CLOSE_CITY = 5; + private final ReentrantReadWriteLock claimLock = new ReentrantReadWriteLock(); - public ClaimGuildTreeMsgHandler() { - super(ClaimGuildTreeMsg.class); - } + public ClaimGuildTreeMsgHandler() { + super(ClaimGuildTreeMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - // Member variable declaration - this.claimLock.writeLock().lock(); + // Member variable declaration + this.claimLock.writeLock().lock(); - try{ - PlayerCharacter sourcePlayer; - Building building; - Blueprint blueprint; - Zone playerZone= null; - City playerCity= null; - ClaimGuildTreeMsg msg; - int targetUUID; - Dispatch dispatch; + try { + PlayerCharacter sourcePlayer; + Building building; + Blueprint blueprint; + Zone playerZone = null; + City playerCity = null; + ClaimGuildTreeMsg msg; + int targetUUID; + Dispatch dispatch; - msg = (ClaimGuildTreeMsg) baseMsg; - targetUUID = msg.getTargetID(); + msg = (ClaimGuildTreeMsg) baseMsg; + targetUUID = msg.getTargetID(); - sourcePlayer = origin.getPlayerCharacter(); - building = BuildingManager.getBuildingFromCache(targetUUID); + sourcePlayer = origin.getPlayerCharacter(); + building = BuildingManager.getBuildingFromCache(targetUUID); - if (building != null) - playerZone = building.getParentZone(); + if (building != null) + playerZone = building.getParentZone(); - if (playerZone != null) - playerCity = City.getCity(playerZone.getPlayerCityUUID()); + if (playerZone != null) + playerCity = City.getCity(playerZone.getPlayerCityUUID()); - // Oops! *** Refactor: Log error - switch (msg.getMessageType()){ - case RENAME_TREE: - if ((sourcePlayer == null) || - (building == null) || playerZone == null ||playerCity == null) - return true; + // Oops! *** Refactor: Log error + switch (msg.getMessageType()) { + case RENAME_TREE: + if ((sourcePlayer == null) || + (building == null) || playerZone == null || playerCity == null) + return true; - // Early exit if object to be claimed is not errant + // Early exit if object to be claimed is not errant - if (building.getOwnerUUID() == 0) - return true; + if (building.getOwnerUUID() == 0) + return true; - // Errant players cannot rename + // Errant players cannot rename - if (sourcePlayer.getGuild().isEmptyGuild()) - return true; + if (sourcePlayer.getGuild().isEmptyGuild()) + return true; - // Can't rename an object without a blueprint + // Can't rename an object without a blueprint - if (building.getBlueprintUUID() == 0) - return true; + if (building.getBlueprintUUID() == 0) + return true; - blueprint = building.getBlueprint(); + blueprint = building.getBlueprint(); - //can only rename tree this way. - if (blueprint.getBuildingGroup() != BuildingGroup.TOL) - return true; + //can only rename tree this way. + if (blueprint.getBuildingGroup() != BuildingGroup.TOL) + return true; - //dont rename if guild is null - if (building.getGuild().isEmptyGuild()) - return true; + //dont rename if guild is null + if (building.getGuild().isEmptyGuild()) + return true; - if (!ManageCityAssetMsgHandler.playerCanManageNotFriends(sourcePlayer, building)) - return true; + if (!ManageCityAssetMsgHandler.playerCanManageNotFriends(sourcePlayer, building)) + return true; - if (!playerCity.renameCity(msg.getTreeName())){ - ChatManager.chatSystemError(sourcePlayer, "Failed to rename city!"); - return true; - } + if (!playerCity.renameCity(msg.getTreeName())) { + ChatManager.chatSystemError(sourcePlayer, "Failed to rename city!"); + return true; + } - GuildTreeStatusMsg gtsm = new GuildTreeStatusMsg(building,sourcePlayer); - gtsm.configure(); - dispatch = Dispatch.borrow(sourcePlayer, gtsm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + GuildTreeStatusMsg gtsm = new GuildTreeStatusMsg(building, sourcePlayer); + gtsm.configure(); + dispatch = Dispatch.borrow(sourcePlayer, gtsm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - CityZoneMsg czm = new CityZoneMsg(2,playerZone.getLoc().x, playerZone.getLoc().y, playerZone.getLoc().z, playerCity.getCityName(),playerZone, Enum.CityBoundsType.ZONE.extents, Enum.CityBoundsType.ZONE.extents); - DispatchMessage.dispatchMsgToAll(czm); + CityZoneMsg czm = new CityZoneMsg(2, playerZone.getLoc().x, playerZone.getLoc().y, playerZone.getLoc().z, playerCity.getCityName(), playerZone, Enum.CityBoundsType.ZONE.extents, Enum.CityBoundsType.ZONE.extents); + DispatchMessage.dispatchMsgToAll(czm); - break; - case BIND_TREE: + break; + case BIND_TREE: - Guild pcGuild = sourcePlayer.getGuild(); + Guild pcGuild = sourcePlayer.getGuild(); - //test tree is valid for binding, same guild or same nation - if (!Guild.sameNation(pcGuild, building.getGuild())) { + //test tree is valid for binding, same guild or same nation + if (!Guild.sameNation(pcGuild, building.getGuild())) { - return true; - } + return true; + } - if (building.getGuild().isEmptyGuild()) - return true; + if (building.getGuild().isEmptyGuild()) + return true; - //get bind city - Zone zone =building.getParentZone(); + //get bind city + Zone zone = building.getParentZone(); - if (zone == null) { - ErrorPopupMsg.sendErrorMsg(sourcePlayer, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - return true; - } + if (zone == null) { + ErrorPopupMsg.sendErrorMsg(sourcePlayer, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + return true; + } - if (playerCity == null && building.getGuild() != null) - playerCity = building.getGuild().getOwnedCity(); + if (playerCity == null && building.getGuild() != null) + playerCity = building.getGuild().getOwnedCity(); - if (playerCity == null) - return true; + if (playerCity == null) + return true; - - sourcePlayer.setBindBuildingID(building.getObjectUUID()); - dispatch = Dispatch.borrow(sourcePlayer, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - break; - case OPEN_CITY: - case CLOSE_CITY: - if ((sourcePlayer == null) || - (building == null) || playerZone == null ||playerCity == null) - return true; - if (!ManageCityAssetMsgHandler.playerCanManageNotFriends(sourcePlayer, building)) - return true; + sourcePlayer.setBindBuildingID(building.getObjectUUID()); + dispatch = Dispatch.borrow(sourcePlayer, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + break; + case OPEN_CITY: + case CLOSE_CITY: + if ((sourcePlayer == null) || + (building == null) || playerZone == null || playerCity == null) + return true; - boolean open = (msg.getMessageType() == OPEN_CITY); + if (!ManageCityAssetMsgHandler.playerCanManageNotFriends(sourcePlayer, building)) + return true; - if (!playerCity.openCity(open)){ - ErrorPopupMsg.sendErrorMsg(sourcePlayer, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - return true; - } + boolean open = (msg.getMessageType() == OPEN_CITY); - dispatch = Dispatch.borrow(sourcePlayer, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - break; - default: - break; - } + if (!playerCity.openCity(open)) { + ErrorPopupMsg.sendErrorMsg(sourcePlayer, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + return true; + } - } catch(Exception e){ - Logger.error( e.getMessage()); - }finally{ - try{ - this.claimLock.writeLock().unlock(); - }catch(Exception e){ - Logger.info("failClaimsync"); - } - } - return true; - } + dispatch = Dispatch.borrow(sourcePlayer, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + break; + default: + break; + } + + } catch (Exception e) { + Logger.error(e.getMessage()); + } finally { + try { + this.claimLock.writeLock().unlock(); + } catch (Exception e) { + Logger.info("failClaimsync"); + } + } + return true; + } } \ No newline at end of file diff --git a/src/engine/net/client/handlers/DestroyBuildingHandler.java b/src/engine/net/client/handlers/DestroyBuildingHandler.java index 0ece4fd4..18ce4d05 100644 --- a/src/engine/net/client/handlers/DestroyBuildingHandler.java +++ b/src/engine/net/client/handlers/DestroyBuildingHandler.java @@ -19,90 +19,90 @@ import engine.objects.*; public class DestroyBuildingHandler extends AbstractClientMsgHandler { - public DestroyBuildingHandler() { - super(DestroyBuildingMsg.class); - } + public DestroyBuildingHandler() { + super(DestroyBuildingMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - - PlayerCharacter pc = origin.getPlayerCharacter(); + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - DestroyBuildingMsg msg; - msg = (DestroyBuildingMsg) baseMsg; - Bane bane = null; - Blueprint blueprint; + PlayerCharacter pc = origin.getPlayerCharacter(); - int buildingUUID = msg.getUUID(); + DestroyBuildingMsg msg; + msg = (DestroyBuildingMsg) baseMsg; + Bane bane = null; + Blueprint blueprint; - Building building = BuildingManager.getBuildingFromCache(buildingUUID); -; - if (pc == null || building == null) - return true; + int buildingUUID = msg.getUUID(); - blueprint = building.getBlueprint(); - City city = building.getCity(); + Building building = BuildingManager.getBuildingFromCache(buildingUUID); + ; + if (pc == null || building == null) + return true; - // Can't destroy buildings without a blueprint. + blueprint = building.getBlueprint(); + City city = building.getCity(); - if (blueprint == null) - return true; + // Can't destroy buildings without a blueprint. - // Cannot destroy Oblivion database derived buildings. + if (blueprint == null) + return true; - if (building.getProtectionState() == Enum.ProtectionState.NPC) { - return true; - } + // Cannot destroy Oblivion database derived buildings. - if (!BuildingManager.PlayerCanControlNotOwner(building, pc)) - return true; + if (building.getProtectionState() == Enum.ProtectionState.NPC) { + return true; + } - // Can't delete siege assets during an active bane. + if (!BuildingManager.PlayerCanControlNotOwner(building, pc)) + return true; - if (city != null) - bane = city.getBane(); + // Can't delete siege assets during an active bane. - if ( bane != null && bane.getSiegePhase() == Enum.SiegePhase.WAR) { - ErrorPopupMsg.sendErrorPopup(pc, 171); - return true; - } + if (city != null) + bane = city.getBane(); - // Can't destroy a tree of life - if (blueprint.getBuildingGroup() == BuildingGroup.TOL) - return true; + if (bane != null && bane.getSiegePhase() == Enum.SiegePhase.WAR) { + ErrorPopupMsg.sendErrorPopup(pc, 171); + return true; + } - // Can't destroy a shrine - if (blueprint.getBuildingGroup() == BuildingGroup.SHRINE) - return true; + // Can't destroy a tree of life + if (blueprint.getBuildingGroup() == BuildingGroup.TOL) + return true; - // Cannot destroy mines outside of normal mine mechanics + // Can't destroy a shrine + if (blueprint.getBuildingGroup() == BuildingGroup.SHRINE) + return true; - if (blueprint.getBuildingGroup() == BuildingGroup.MINE) - return true; + // Cannot destroy mines outside of normal mine mechanics - // Cannot delete rungates + if (blueprint.getBuildingGroup() == BuildingGroup.MINE) + return true; - if (blueprint.getBuildingGroup() == BuildingGroup.RUNEGATE) - return true; + // Cannot delete rungates + if (blueprint.getBuildingGroup() == BuildingGroup.RUNEGATE) + return true; - // Turn off spire if destoying - if (blueprint.getBuildingGroup() == BuildingGroup.SPIRE) - building.disableSpire(true); - if (blueprint.getBuildingGroup() == BuildingGroup.WAREHOUSE) { - if (city != null) - city.setWarehouseBuildingID(0); - } + // Turn off spire if destoying + if (blueprint.getBuildingGroup() == BuildingGroup.SPIRE) + building.disableSpire(true); - building.setRank(-1); - WorldGrid.RemoveWorldObject(building); - WorldGrid.removeObject(building); - building.getParentZone().zoneBuildingSet.remove(building); - if(building.getBlueprint() != null && building.getBlueprint().getBuildingGroup().equals(BuildingGroup.BARRACK)){ - building.RemoveFromBarracksList(); - } - return true; - } + if (blueprint.getBuildingGroup() == BuildingGroup.WAREHOUSE) { + if (city != null) + city.setWarehouseBuildingID(0); + } + + building.setRank(-1); + WorldGrid.RemoveWorldObject(building); + WorldGrid.removeObject(building); + building.getParentZone().zoneBuildingSet.remove(building); + if (building.getBlueprint() != null && building.getBlueprint().getBuildingGroup().equals(BuildingGroup.BARRACK)) { + building.RemoveFromBarracksList(); + } + return true; + } } \ No newline at end of file diff --git a/src/engine/net/client/handlers/DisbandGroupHandler.java b/src/engine/net/client/handlers/DisbandGroupHandler.java index 5a749f50..7b0ca472 100644 --- a/src/engine/net/client/handlers/DisbandGroupHandler.java +++ b/src/engine/net/client/handlers/DisbandGroupHandler.java @@ -27,7 +27,7 @@ public class DisbandGroupHandler extends AbstractClientMsgHandler { @Override protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - + PlayerCharacter source = SessionManager.getPlayerCharacter(origin); if (source == null) { return false; diff --git a/src/engine/net/client/handlers/DisbandGuildHandler.java b/src/engine/net/client/handlers/DisbandGuildHandler.java index 016ac4b2..15e1fbd8 100644 --- a/src/engine/net/client/handlers/DisbandGuildHandler.java +++ b/src/engine/net/client/handlers/DisbandGuildHandler.java @@ -32,90 +32,90 @@ import engine.objects.PlayerCharacter; public class DisbandGuildHandler extends AbstractClientMsgHandler { - public DisbandGuildHandler() { - super(DisbandGuildMsg.class); - } + public DisbandGuildHandler() { + super(DisbandGuildMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - PlayerCharacter player; - Guild guild; - Dispatch dispatch; + PlayerCharacter player; + Guild guild; + Dispatch dispatch; - player = SessionManager.getPlayerCharacter(origin); + player = SessionManager.getPlayerCharacter(origin); - //don't allow non guild leaders to disband guild. + //don't allow non guild leaders to disband guild. - if (player == null || GuildStatusController.isGuildLeader(player.getGuildStatus()) == false) - return true; + if (player == null || GuildStatusController.isGuildLeader(player.getGuildStatus()) == false) + return true; - guild = player.getGuild(); + guild = player.getGuild(); - if (guild == null || guild.isEmptyGuild()) - return true; + if (guild == null || guild.isEmptyGuild()) + return true; - // Don't allow disbanding if a city is owned - // *** Refactor: We should allow this by abandoning the tree first. + // Don't allow disbanding if a city is owned + // *** Refactor: We should allow this by abandoning the tree first. - if (guild.getOwnedCity() != null) { - ErrorPopupMsg.sendErrorMsg(player, "You cannot disband a soverign guild!"); - return true; - } + if (guild.getOwnedCity() != null) { + ErrorPopupMsg.sendErrorMsg(player, "You cannot disband a soverign guild!"); + return true; + } - Bane guildBane = Bane.getBaneByAttackerGuild(guild); + Bane guildBane = Bane.getBaneByAttackerGuild(guild); - if (guildBane != null) { - ErrorPopupMsg.sendErrorMsg(player, "You cannot disband a guild with an active bane!"); - return true; - } + if (guildBane != null) { + ErrorPopupMsg.sendErrorMsg(player, "You cannot disband a guild with an active bane!"); + return true; + } - if (guild.getSubGuildList().size() > 0) { - ErrorPopupMsg.sendErrorMsg(player, "You cannot disband a nation!"); - return true; - } + if (guild.getSubGuildList().size() > 0) { + ErrorPopupMsg.sendErrorMsg(player, "You cannot disband a nation!"); + return true; + } - // Send message to guild (before kicking everyone out of it) + // Send message to guild (before kicking everyone out of it) - ChatManager.chatGuildInfo(guild, guild.getName() + " has been disbanded!"); + ChatManager.chatGuildInfo(guild, guild.getName() + " has been disbanded!"); - // Log event to data warehous + // Log event to data warehous - GuildRecord guildRecord = GuildRecord.borrow(guild, Enum.RecordEventType.DISBAND); - DataWarehouse.pushToWarehouse(guildRecord); + GuildRecord guildRecord = GuildRecord.borrow(guild, Enum.RecordEventType.DISBAND); + DataWarehouse.pushToWarehouse(guildRecord); - // Remove us as a subguild of our nation + // Remove us as a subguild of our nation - if (guild.getNation() != null && Guild.sameGuild(guild, guild.getNation()) == false && guild.getNation().isEmptyGuild() == false) - guild.getNation().removeSubGuild(guild); + if (guild.getNation() != null && Guild.sameGuild(guild, guild.getNation()) == false && guild.getNation().isEmptyGuild() == false) + guild.getNation().removeSubGuild(guild); - // Update all online guild players + // Update all online guild players - for (PlayerCharacter pcs : Guild.GuildRoster(guild)) { + for (PlayerCharacter pcs : Guild.GuildRoster(guild)) { - guild.removePlayer(pcs,GuildHistoryType.DISBAND); - } + guild.removePlayer(pcs, GuildHistoryType.DISBAND); + } - //Save Guild data + //Save Guild data - player.setGuildLeader(false); - player.setInnerCouncil(false); - guild.setGuildLeaderUUID(0); - guild.setNation(null); + player.setGuildLeader(false); + player.setInnerCouncil(false); + guild.setGuildLeaderUUID(0); + guild.setNation(null); - DbManager.GuildQueries.DELETE_GUILD(guild); + DbManager.GuildQueries.DELETE_GUILD(guild); - DbManager.removeFromCache(guild); - WorldGrid.removeObject(guild, player); + DbManager.removeFromCache(guild); + WorldGrid.removeObject(guild, player); - // Send message back to client + // Send message back to client - LeaveGuildMsg leaveGuildMsg = new LeaveGuildMsg(); - leaveGuildMsg.setMessage("You guild has been disbanded!"); - dispatch = Dispatch.borrow(player, leaveGuildMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + LeaveGuildMsg leaveGuildMsg = new LeaveGuildMsg(); + leaveGuildMsg.setMessage("You guild has been disbanded!"); + dispatch = Dispatch.borrow(player, leaveGuildMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - return true; - } + return true; + } } diff --git a/src/engine/net/client/handlers/DismissGuildHandler.java b/src/engine/net/client/handlers/DismissGuildHandler.java index b469ecac..a07054bf 100644 --- a/src/engine/net/client/handlers/DismissGuildHandler.java +++ b/src/engine/net/client/handlers/DismissGuildHandler.java @@ -54,31 +54,30 @@ public class DismissGuildHandler extends AbstractClientMsgHandler { toDismiss = (Guild) DbManager.getObject(GameObjectType.Guild, dismissMsg.getGuildID()); if (toDismiss == null) { - ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occured. Please post details for to ensure transaction integrity"); + ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occured. Please post details for to ensure transaction integrity"); return true; } nation = player.getGuild(); if (nation == null) { - ErrorPopupMsg.sendErrorMsg(player, "Nothing to disband, your guild is not a nation!"); + ErrorPopupMsg.sendErrorMsg(player, "Nothing to disband, your guild is not a nation!"); return true; } if (!nation.getSubGuildList().contains(toDismiss)) { - ErrorPopupMsg.sendErrorMsg(player, "You do not have authority to dismiss this guild!"); + ErrorPopupMsg.sendErrorMsg(player, "You do not have authority to dismiss this guild!"); return true; } if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false) { - ErrorPopupMsg.sendErrorMsg(player, "Only a guild leader can dismiss a subguild!"); + ErrorPopupMsg.sendErrorMsg(player, "Only a guild leader can dismiss a subguild!"); return true; } // Restriction on active bane desubbing - if (Bane.getBaneByAttackerGuild(toDismiss) != null) - { + if (Bane.getBaneByAttackerGuild(toDismiss) != null) { ErrorPopupMsg.sendErrorMsg(player, "You may not dismiss subguild with active bane!"); return true; } diff --git a/src/engine/net/client/handlers/DoorTryOpenMsgHandler.java b/src/engine/net/client/handlers/DoorTryOpenMsgHandler.java index 8fb76b03..990e974d 100644 --- a/src/engine/net/client/handlers/DoorTryOpenMsgHandler.java +++ b/src/engine/net/client/handlers/DoorTryOpenMsgHandler.java @@ -23,7 +23,7 @@ import java.util.HashSet; * @Author: * @Summary: Processes application protocol message which handle * open and close door requests to and from the client. - * + * */ public class DoorTryOpenMsgHandler extends AbstractClientMsgHandler { @@ -35,17 +35,17 @@ public class DoorTryOpenMsgHandler extends AbstractClientMsgHandler { protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { // Member variable declaration - + PlayerCharacter player; DoorTryOpenMsg msg; Building targetBuilding; int doorNumber; - + // Member variable assignment - - msg = (DoorTryOpenMsg)baseMsg; + + msg = (DoorTryOpenMsg) baseMsg; player = origin.getPlayerCharacter(); - targetBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingUUID()); + targetBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingUUID()); if (player == null || targetBuilding == null) { Logger.error("Player or Building returned NULL in OpenCloseDoor handling."); @@ -53,7 +53,7 @@ public class DoorTryOpenMsgHandler extends AbstractClientMsgHandler { } // Must be within x distance from door to manipulate it - + if (player.getLoc().distanceSquared2D(targetBuilding.getLoc()) > MBServerStatics.OPENCLOSEDOORDISTANCE * MBServerStatics.OPENCLOSEDOORDISTANCE) return true; @@ -77,7 +77,7 @@ public class DoorTryOpenMsgHandler extends AbstractClientMsgHandler { MBServerStatics.MASK_PLAYER); for (AbstractWorldObject awo : container) { - PlayerCharacter playerCharacter = (PlayerCharacter)awo; + PlayerCharacter playerCharacter = (PlayerCharacter) awo; Dispatch dispatch = Dispatch.borrow(playerCharacter, msg); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); } diff --git a/src/engine/net/client/handlers/FriendAcceptHandler.java b/src/engine/net/client/handlers/FriendAcceptHandler.java index 473d04d8..4212f2ea 100644 --- a/src/engine/net/client/handlers/FriendAcceptHandler.java +++ b/src/engine/net/client/handlers/FriendAcceptHandler.java @@ -25,54 +25,52 @@ import engine.objects.PlayerFriends; public class FriendAcceptHandler extends AbstractClientMsgHandler { - public FriendAcceptHandler() { - super(AcceptFriendMsg.class); - } - - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, - ClientConnection origin) throws MsgSendException { - - PlayerCharacter player = origin.getPlayerCharacter(); - - if (player == null) - return true; - - - AcceptFriendMsg msg = (AcceptFriendMsg)baseMsg; - - - HandleAcceptFriend(player,msg); - - return true; - } - - - - //change to Request - public static void HandleAcceptFriend(PlayerCharacter player, AcceptFriendMsg msg){ - PlayerCharacter sourceFriend = SessionManager.getPlayerCharacterByLowerCaseName(msg.sourceName); - - if (sourceFriend == null){ - ErrorPopupMsg.sendErrorMsg(player, "Could not find player " + msg.sourceName); - return; - } - - PlayerFriends.AddToFriends(sourceFriend.getObjectUUID(), player.getObjectUUID()); - PlayerFriends.AddToFriends(player.getObjectUUID(), sourceFriend.getObjectUUID()); - - - AddFriendMessage outMsg = new AddFriendMessage(player); - - Dispatch dispatch = Dispatch.borrow(sourceFriend, outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - outMsg = new AddFriendMessage(sourceFriend); - dispatch = Dispatch.borrow(player, outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - ChatManager.chatSystemInfo(sourceFriend, player.getFirstName() + " has agreed to be your friend."); - - } - + public FriendAcceptHandler() { + super(AcceptFriendMsg.class); + } + + //change to Request + public static void HandleAcceptFriend(PlayerCharacter player, AcceptFriendMsg msg) { + PlayerCharacter sourceFriend = SessionManager.getPlayerCharacterByLowerCaseName(msg.sourceName); + + if (sourceFriend == null) { + ErrorPopupMsg.sendErrorMsg(player, "Could not find player " + msg.sourceName); + return; + } + + PlayerFriends.AddToFriends(sourceFriend.getObjectUUID(), player.getObjectUUID()); + PlayerFriends.AddToFriends(player.getObjectUUID(), sourceFriend.getObjectUUID()); + + + AddFriendMessage outMsg = new AddFriendMessage(player); + + Dispatch dispatch = Dispatch.borrow(sourceFriend, outMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + outMsg = new AddFriendMessage(sourceFriend); + dispatch = Dispatch.borrow(player, outMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + ChatManager.chatSystemInfo(sourceFriend, player.getFirstName() + " has agreed to be your friend."); + + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, + ClientConnection origin) throws MsgSendException { + + PlayerCharacter player = origin.getPlayerCharacter(); + + if (player == null) + return true; + + + AcceptFriendMsg msg = (AcceptFriendMsg) baseMsg; + + + HandleAcceptFriend(player, msg); + + return true; + } + } diff --git a/src/engine/net/client/handlers/FriendDeclineHandler.java b/src/engine/net/client/handlers/FriendDeclineHandler.java index af72702a..eb57b3f4 100644 --- a/src/engine/net/client/handlers/FriendDeclineHandler.java +++ b/src/engine/net/client/handlers/FriendDeclineHandler.java @@ -22,42 +22,40 @@ import engine.objects.PlayerCharacter; public class FriendDeclineHandler extends AbstractClientMsgHandler { - public FriendDeclineHandler() { - super(DeclineFriendMsg.class); - } - - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, - ClientConnection origin) throws MsgSendException { - - PlayerCharacter player = origin.getPlayerCharacter(); - - if (player == null) - return true; - - - DeclineFriendMsg msg = (DeclineFriendMsg)baseMsg; - - - HandleDeclineFriend(player,msg); - - return true; - } - - - - //change to Request - public static void HandleDeclineFriend(PlayerCharacter player, DeclineFriendMsg msg){ - PlayerCharacter sourceFriend = SessionManager.getPlayerCharacterByLowerCaseName(msg.sourceName); - - if (sourceFriend == null){ - ErrorPopupMsg.sendErrorMsg(player, "Could not find player " + msg.sourceName); - return; - } - - Dispatch dispatch = Dispatch.borrow(sourceFriend, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - } - + public FriendDeclineHandler() { + super(DeclineFriendMsg.class); + } + + //change to Request + public static void HandleDeclineFriend(PlayerCharacter player, DeclineFriendMsg msg) { + PlayerCharacter sourceFriend = SessionManager.getPlayerCharacterByLowerCaseName(msg.sourceName); + + if (sourceFriend == null) { + ErrorPopupMsg.sendErrorMsg(player, "Could not find player " + msg.sourceName); + return; + } + + Dispatch dispatch = Dispatch.borrow(sourceFriend, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, + ClientConnection origin) throws MsgSendException { + + PlayerCharacter player = origin.getPlayerCharacter(); + + if (player == null) + return true; + + + DeclineFriendMsg msg = (DeclineFriendMsg) baseMsg; + + + HandleDeclineFriend(player, msg); + + return true; + } + } diff --git a/src/engine/net/client/handlers/FriendRequestHandler.java b/src/engine/net/client/handlers/FriendRequestHandler.java index 56e94914..48c5725a 100644 --- a/src/engine/net/client/handlers/FriendRequestHandler.java +++ b/src/engine/net/client/handlers/FriendRequestHandler.java @@ -23,47 +23,43 @@ import engine.objects.PlayerCharacter; public class FriendRequestHandler extends AbstractClientMsgHandler { - public FriendRequestHandler() { - super(FriendRequestMsg.class); - } - - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, - ClientConnection origin) throws MsgSendException { - - PlayerCharacter player = origin.getPlayerCharacter(); - - if (player == null) - return true; - - - FriendRequestMsg msg = (FriendRequestMsg)baseMsg; - - HandleRequestFriend(player,msg); - - return true; - } - - - - public static void HandleRequestFriend(PlayerCharacter player, FriendRequestMsg msg){ - PlayerCharacter targetFriend = SessionManager.getPlayerCharacterByLowerCaseName(msg.friendName); - - if (targetFriend == null){ - ErrorPopupMsg.sendErrorMsg(player, "Could not find player " + msg.friendName); - return; - } - - if (targetFriend.equals(player)) - return; - - - - - Dispatch dispatch = Dispatch.borrow(targetFriend, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - ChatManager.chatSystemInfo(player, "Your friend request has been sent."); - - } - + public FriendRequestHandler() { + super(FriendRequestMsg.class); + } + + public static void HandleRequestFriend(PlayerCharacter player, FriendRequestMsg msg) { + PlayerCharacter targetFriend = SessionManager.getPlayerCharacterByLowerCaseName(msg.friendName); + + if (targetFriend == null) { + ErrorPopupMsg.sendErrorMsg(player, "Could not find player " + msg.friendName); + return; + } + + if (targetFriend.equals(player)) + return; + + + Dispatch dispatch = Dispatch.borrow(targetFriend, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + ChatManager.chatSystemInfo(player, "Your friend request has been sent."); + + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, + ClientConnection origin) throws MsgSendException { + + PlayerCharacter player = origin.getPlayerCharacter(); + + if (player == null) + return true; + + + FriendRequestMsg msg = (FriendRequestMsg) baseMsg; + + HandleRequestFriend(player, msg); + + return true; + } + } diff --git a/src/engine/net/client/handlers/FurnitureHandler.java b/src/engine/net/client/handlers/FurnitureHandler.java index 65dce932..e7dc902d 100644 --- a/src/engine/net/client/handlers/FurnitureHandler.java +++ b/src/engine/net/client/handlers/FurnitureHandler.java @@ -20,29 +20,29 @@ import engine.objects.PlayerCharacter; public class FurnitureHandler extends AbstractClientMsgHandler { - public FurnitureHandler() { - super(FurnitureMsg.class); - } - - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, - ClientConnection origin) throws MsgSendException { - - FurnitureMsg msg = (FurnitureMsg) baseMsg; - - PlayerCharacter pc = origin.getPlayerCharacter(); - if (pc == null) { - return false; - } - - if (msg.getType() == 1) - msg.setType(2); - - if (msg.getType() == 3) - msg.setType(2); - Dispatch dispatch = Dispatch.borrow(pc, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - } + public FurnitureHandler() { + super(FurnitureMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, + ClientConnection origin) throws MsgSendException { + + FurnitureMsg msg = (FurnitureMsg) baseMsg; + + PlayerCharacter pc = origin.getPlayerCharacter(); + if (pc == null) { + return false; + } + + if (msg.getType() == 1) + msg.setType(2); + + if (msg.getType() == 3) + msg.setType(2); + Dispatch dispatch = Dispatch.borrow(pc, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + } } diff --git a/src/engine/net/client/handlers/GroupInviteHandler.java b/src/engine/net/client/handlers/GroupInviteHandler.java index 7f0916d0..bef9a198 100644 --- a/src/engine/net/client/handlers/GroupInviteHandler.java +++ b/src/engine/net/client/handlers/GroupInviteHandler.java @@ -25,102 +25,102 @@ import engine.objects.PlayerCharacter; public class GroupInviteHandler extends AbstractClientMsgHandler { - public GroupInviteHandler() { - super(GroupInviteMsg.class); - } + public GroupInviteHandler() { + super(GroupInviteMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, + private static Group createGroup(PlayerCharacter pc, ClientConnection origin) { - ClientConnection origin) throws MsgSendException { - GroupInviteMsg msg = (GroupInviteMsg) baseMsg; - PlayerCharacter source = SessionManager.getPlayerCharacter(origin); + if (pc == null) + return null; - if (source == null) - return false; + Group group = new Group(pc, GroupManager.incrGroupCount()); + group.addGroupMember(pc); + GroupManager.addNewGroup(group); - Group group = GroupManager.getGroup(source); + pc.setFollow(false); + // Send add self to group message + GroupUpdateMsg msg = new GroupUpdateMsg(); + msg.setGroup(group); + msg.setPlayer(pc); + msg.setMessageType(1); + Dispatch dispatch = Dispatch.borrow(pc, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - // Group is new, create it. + group.addUpdateGroupJob(); - if (group == null) - group = GroupInviteHandler.createGroup(source, origin); + return group; + } - if (group == null) - return false; + // this can only be called if you already know you are not in a group + // and have issued an invite - if (!group.isGroupLead(source)) // person doing invite must be group lead - return true; + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, - PlayerCharacter target = null; + ClientConnection origin) throws MsgSendException { + GroupInviteMsg msg = (GroupInviteMsg) baseMsg; + PlayerCharacter source = SessionManager.getPlayerCharacter(origin); - if (msg.getInvited() == 1) { // Use name for invite - target = SessionManager.getPlayerCharacterByLowerCaseName(msg.getName().toLowerCase()); - } else { // Use ID for invite - target = SessionManager.getPlayerCharacterByID(msg.getTargetID()); - } + if (source == null) + return false; - if (target == null) - return false; + Group group = GroupManager.getGroup(source); - // Client must be online + // Group is new, create it. - if (SessionManager.getClientConnection(target) == null) - return false; + if (group == null) + group = GroupInviteHandler.createGroup(source, origin); - if (source == target) // Inviting self, so we're done - return false; + if (group == null) + return false; + if (!group.isGroupLead(source)) // person doing invite must be group lead + return true; - //Skip invite if target is ignoring source + PlayerCharacter target = null; - if (target.isIgnoringPlayer(source)) - return false; + if (msg.getInvited() == 1) { // Use name for invite + target = SessionManager.getPlayerCharacterByLowerCaseName(msg.getName().toLowerCase()); + } else { // Use ID for invite + target = SessionManager.getPlayerCharacterByID(msg.getTargetID()); + } + if (target == null) + return false; - // dont block invites to people already in a group and - // dont check for pending invites, the client does it - // Send invite message to target + // Client must be online - msg.setSourceType(GameObjectType.PlayerCharacter.ordinal()); - msg.setSourceID(source.getObjectUUID()); - msg.setTargetType(0); - msg.setTargetID(0); - msg.setGroupType(GameObjectType.Group.ordinal()); - msg.setGroupID(group.getObjectUUID()); - msg.setInvited(1); - msg.setName(source.getFirstName()); + if (SessionManager.getClientConnection(target) == null) + return false; - Dispatch dispatch = Dispatch.borrow(target, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + if (source == target) // Inviting self, so we're done + return false; - return true; - } - // this can only be called if you already know you are not in a group - // and have issued an invite + //Skip invite if target is ignoring source - private static Group createGroup(PlayerCharacter pc, ClientConnection origin) { + if (target.isIgnoringPlayer(source)) + return false; - if (pc == null) - return null; - Group group = new Group(pc, GroupManager.incrGroupCount()); - group.addGroupMember(pc); - GroupManager.addNewGroup(group); + // dont block invites to people already in a group and + // dont check for pending invites, the client does it + // Send invite message to target - pc.setFollow(false); - // Send add self to group message - GroupUpdateMsg msg = new GroupUpdateMsg(); - msg.setGroup(group); - msg.setPlayer(pc); - msg.setMessageType(1); - Dispatch dispatch = Dispatch.borrow(pc, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + msg.setSourceType(GameObjectType.PlayerCharacter.ordinal()); + msg.setSourceID(source.getObjectUUID()); + msg.setTargetType(0); + msg.setTargetID(0); + msg.setGroupType(GameObjectType.Group.ordinal()); + msg.setGroupID(group.getObjectUUID()); + msg.setInvited(1); + msg.setName(source.getFirstName()); - group.addUpdateGroupJob(); + Dispatch dispatch = Dispatch.borrow(target, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - return group; - } + return true; + } } diff --git a/src/engine/net/client/handlers/GroupInviteResponseHandler.java b/src/engine/net/client/handlers/GroupInviteResponseHandler.java index 9f2f1611..a0706f06 100644 --- a/src/engine/net/client/handlers/GroupInviteResponseHandler.java +++ b/src/engine/net/client/handlers/GroupInviteResponseHandler.java @@ -34,7 +34,7 @@ public class GroupInviteResponseHandler extends AbstractClientMsgHandler { @Override protected boolean _handleNetMsg(ClientNetMsg baseMsg, - ClientConnection origin) throws MsgSendException { + ClientConnection origin) throws MsgSendException { GroupInviteResponseMsg msg = (GroupInviteResponseMsg) baseMsg; @@ -50,7 +50,7 @@ public class GroupInviteResponseHandler extends AbstractClientMsgHandler { if (currGroup != null) // if we are already in a group we are leaving it GroupManager.LeaveGroup(player); - // not sure we need to test for invites to wrong grp as only + // not sure we need to test for invites to wrong grp as only // 1 invite can be on screen at a time //if (invitesPending.get(player) != msg.getGroupID()) // Can't accept // invite to @@ -85,8 +85,8 @@ public class GroupInviteResponseHandler extends AbstractClientMsgHandler { groupUpdateMsg.setPlayer(groupMember); - Dispatch dispatch = Dispatch.borrow(player, groupUpdateMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + Dispatch dispatch = Dispatch.borrow(player, groupUpdateMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); } @@ -104,8 +104,8 @@ public class GroupInviteResponseHandler extends AbstractClientMsgHandler { KEYCLONEAUDIT.audit(player, group); - return true; - } + return true; + } } } diff --git a/src/engine/net/client/handlers/GroupUpdateHandler.java b/src/engine/net/client/handlers/GroupUpdateHandler.java index 944a3b5b..ad2a2d55 100644 --- a/src/engine/net/client/handlers/GroupUpdateHandler.java +++ b/src/engine/net/client/handlers/GroupUpdateHandler.java @@ -22,10 +22,10 @@ public class GroupUpdateHandler extends AbstractClientMsgHandler { @Override protected boolean _handleNetMsg(ClientNetMsg baseMsg, - ClientConnection origin) throws MsgSendException { + ClientConnection origin) throws MsgSendException { - //GroupUpdateMsg msg = (GroupUpdateMsg) baseMsg; - // not sure what to do with these as we spend our time sending them + //GroupUpdateMsg msg = (GroupUpdateMsg) baseMsg; + // not sure what to do with these as we spend our time sending them // to the whole group ourselves return true; } diff --git a/src/engine/net/client/handlers/GuildControlHandler.java b/src/engine/net/client/handlers/GuildControlHandler.java index 112b70d2..1654dbae 100644 --- a/src/engine/net/client/handlers/GuildControlHandler.java +++ b/src/engine/net/client/handlers/GuildControlHandler.java @@ -24,27 +24,27 @@ import engine.objects.PlayerCharacter; public class GuildControlHandler extends AbstractClientMsgHandler { - public GuildControlHandler() { - super(GuildControlMsg.class); - } - - // TODO Don't think this protocolMsg (0x3235E5EA) is actually player history. so - // take further look at it. - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - GuildControlMsg msg = (GuildControlMsg) baseMsg; + public GuildControlHandler() { + super(GuildControlMsg.class); + } + + // TODO Don't think this protocolMsg (0x3235E5EA) is actually player history. so + // take further look at it. + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + GuildControlMsg msg = (GuildControlMsg) baseMsg; Dispatch dispatch; - // until we know what it's for, just echo it back. - msg.setUnknown05((byte) 1); + // until we know what it's for, just echo it back. + msg.setUnknown05((byte) 1); - //Send a GuildList msg - if(msg.getUnknown01() == 1) { + //Send a GuildList msg + if (msg.getUnknown01() == 1) { - PlayerCharacter player = SessionManager.getPlayerCharacter(origin); - //TODO figure out why GL can't be changed and IC can't be banished - //Bounce back the rank options - msg.setGM((byte) (GuildStatusController.isGuildLeader(player.getGuildStatus()) ? 1 : 0)); + PlayerCharacter player = SessionManager.getPlayerCharacter(origin); + //TODO figure out why GL can't be changed and IC can't be banished + //Bounce back the rank options + msg.setGM((byte) (GuildStatusController.isGuildLeader(player.getGuildStatus()) ? 1 : 0)); dispatch = Dispatch.borrow(player, msg); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); @@ -52,23 +52,23 @@ public class GuildControlHandler extends AbstractClientMsgHandler { if (GuildStatusController.isInnerCouncil(player.getGuildStatus()) || GuildStatusController.isGuildLeader(player.getGuildStatus())) { dispatch = Dispatch.borrow(player, new GuildListMsg(player.getGuild())); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } else + } else ErrorPopupMsg.sendErrorMsg(player, "Only guild leader and inner council have such authority!"); - } else if(msg.getUnknown01() == 2) { - 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()); - - if(pc != null) { - dispatch = Dispatch.borrow(player,new GuildListMsg(pc)); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } - } - - return true; - } + } else if (msg.getUnknown01() == 2) { + 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()); + + if (pc != null) { + dispatch = Dispatch.borrow(player, new GuildListMsg(pc)); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } + } + + return true; + } } diff --git a/src/engine/net/client/handlers/GuildCreationCloseHandler.java b/src/engine/net/client/handlers/GuildCreationCloseHandler.java index f72edff8..3b99b92a 100644 --- a/src/engine/net/client/handlers/GuildCreationCloseHandler.java +++ b/src/engine/net/client/handlers/GuildCreationCloseHandler.java @@ -16,15 +16,15 @@ import engine.net.client.msg.guild.GuildCreationCloseMsg; public class GuildCreationCloseHandler extends AbstractClientMsgHandler { - public GuildCreationCloseHandler() { - super(GuildCreationCloseMsg.class); - } + public GuildCreationCloseHandler() { + super(GuildCreationCloseMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { // GuildCreationCloseMsg msg = (GuildCreationCloseMsg) baseMsg; // origin.sendMsg(msg); - return true; - } + return true; + } } diff --git a/src/engine/net/client/handlers/GuildCreationFinalizeHandler.java b/src/engine/net/client/handlers/GuildCreationFinalizeHandler.java index 1a45f229..d3d30b08 100644 --- a/src/engine/net/client/handlers/GuildCreationFinalizeHandler.java +++ b/src/engine/net/client/handlers/GuildCreationFinalizeHandler.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -46,114 +43,114 @@ import engine.util.StringUtils; public class GuildCreationFinalizeHandler extends AbstractClientMsgHandler { - public GuildCreationFinalizeHandler() { - super(GuildCreationFinalizeMsg.class); - } + public GuildCreationFinalizeHandler() { + super(GuildCreationFinalizeMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter player; + GuildCreationFinalizeMsg msg; + Enum.GuildType charterType; + Guild newGuild; + Guild playerGuild; + ItemBase itemBase; + Item charter; + Dispatch dispatch; - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + msg = (GuildCreationFinalizeMsg) baseMsg; - PlayerCharacter player; - GuildCreationFinalizeMsg msg; - Enum.GuildType charterType; - Guild newGuild; - Guild playerGuild; - ItemBase itemBase; - Item charter; - Dispatch dispatch; + player = SessionManager.getPlayerCharacter(origin); + playerGuild = player.getGuild(); - msg = (GuildCreationFinalizeMsg) baseMsg; + if (playerGuild.isEmptyGuild() == false && player.getGuild().getGuildLeaderUUID() == player.getObjectUUID()) { + ErrorPopupMsg.sendErrorPopup(player, GuildManager.MUST_LEAVE_GUILD); + return true; + } - player = SessionManager.getPlayerCharacter(origin); - playerGuild = player.getGuild(); + //Validate the Charter - if (playerGuild.isEmptyGuild() == false && player.getGuild().getGuildLeaderUUID() == player.getObjectUUID()) { - ErrorPopupMsg.sendErrorPopup(player, GuildManager.MUST_LEAVE_GUILD); - return true; - } + charter = msg.getCharter(); - //Validate the Charter + if (charter == null || charter.getOwnerType() != OwnerType.PlayerCharacter || charter.getOwnerID() != player.getObjectUUID()) { + ErrorPopupMsg.sendErrorPopup(player, GuildManager.NO_CHARTER_FOUND); + return true; + } - charter = msg.getCharter(); + itemBase = charter.getItemBase(); - if (charter == null || charter.getOwnerType() != OwnerType.PlayerCharacter || charter.getOwnerID() != player.getObjectUUID()) { - ErrorPopupMsg.sendErrorPopup(player, GuildManager.NO_CHARTER_FOUND); - return true; - } + // Item must be a valid charterType (type 10 in db) - itemBase = charter.getItemBase(); + if (itemBase == null || (itemBase.getType().equals(ItemType.GUILDCHARTER) == false)) { + ErrorPopupMsg.sendErrorPopup(player, GuildManager.NO_CHARTER_FOUND); + return true; + } - // Item must be a valid charterType (type 10 in db) + charterType = Enum.GuildType.getGuildTypeFromCharter(itemBase); - if (itemBase == null || (itemBase.getType().equals(ItemType.GUILDCHARTER) == false)) { - ErrorPopupMsg.sendErrorPopup(player, GuildManager.NO_CHARTER_FOUND); - return true; - } + if (charterType == null) { + ErrorPopupMsg.sendErrorPopup(player, GuildManager.NO_CHARTER_FOUND); + return true; + } - charterType = Enum.GuildType.getGuildTypeFromCharter(itemBase); + //Validate Guild Tags - if (charterType == null){ - ErrorPopupMsg.sendErrorPopup(player, GuildManager.NO_CHARTER_FOUND); - return true; - } + if (!msg.getGuildTag().isValid()) { + ErrorPopupMsg.sendErrorPopup(player, GuildManager.CREST_RESERVED); + return true; + } - //Validate Guild Tags + // Validation passes. Leave current guild and create new one. - if (!msg.getGuildTag().isValid()) { - ErrorPopupMsg.sendErrorPopup(player, GuildManager.CREST_RESERVED); - return true; - } + if (player.getGuild() != null && player.getGuild().isEmptyGuild() == false) + player.getGuild().removePlayer(player, GuildHistoryType.LEAVE); - // Validation passes. Leave current guild and create new one. + int leadershipType = ((msg.getICVoteFlag() << 1) | msg.getMemberVoteFlag()); - if (player.getGuild() != null && player.getGuild().isEmptyGuild() == false) - player.getGuild().removePlayer(player,GuildHistoryType.LEAVE); + newGuild = new Guild(msg.getName(), null, charterType.ordinal(), + charterType.getLeadershipType(leadershipType), msg.getGuildTag(), + StringUtils.truncate(msg.getMotto(), 120)); - int leadershipType = ((msg.getICVoteFlag() << 1) | msg.getMemberVoteFlag()); + newGuild.setGuildLeaderForCreate(player); - newGuild = new Guild( msg.getName(),null, charterType.ordinal(), - charterType.getLeadershipType(leadershipType), msg.getGuildTag(), - StringUtils.truncate(msg.getMotto(), 120)); + synchronized (this) { + if (!DbManager.GuildQueries.IS_NAME_UNIQUE(msg.getName())) { + ErrorPopupMsg.sendErrorPopup(player, GuildManager.UNIQUE_NAME); + return true; + } - newGuild.setGuildLeaderForCreate(player); + if (!DbManager.GuildQueries.IS_CREST_UNIQUE(msg.getGuildTag())) { + ErrorPopupMsg.sendErrorPopup(player, GuildManager.UNIQUE_CREST); + return true; + } - synchronized (this) { - if (!DbManager.GuildQueries.IS_NAME_UNIQUE(msg.getName())) { - ErrorPopupMsg.sendErrorPopup(player, GuildManager.UNIQUE_NAME); - return true; - } + newGuild = DbManager.GuildQueries.SAVE_TO_DATABASE(newGuild); + } - if (!DbManager.GuildQueries.IS_CREST_UNIQUE(msg.getGuildTag())) { - ErrorPopupMsg.sendErrorPopup(player, GuildManager.UNIQUE_CREST); - return true; - } + if (newGuild == null) { + ErrorPopupMsg.sendErrorPopup(player, GuildManager.FAILURE_TO_SWEAR_GUILD); + return true; + } - newGuild = DbManager.GuildQueries.SAVE_TO_DATABASE(newGuild); - } + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - if (newGuild == null) { - ErrorPopupMsg.sendErrorPopup(player, GuildManager.FAILURE_TO_SWEAR_GUILD); - return true; - } - - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + GuildManager.joinGuild(player, newGuild, GuildHistoryType.CREATE); - GuildManager.joinGuild(player, newGuild, GuildHistoryType.CREATE); - - newGuild.setGuildLeader(player); - player.setGuildLeader(true); - player.setInnerCouncil(true); - player.setFullMember(true); - player.setGuildTitle(charterType.getNumberOfRanks() - 1); - player.getCharItemManager().delete(charter); - player.getCharItemManager().updateInventory(); - player.incVer(); + newGuild.setGuildLeader(player); + player.setGuildLeader(true); + player.setInnerCouncil(true); + player.setFullMember(true); + player.setGuildTitle(charterType.getNumberOfRanks() - 1); + player.getCharItemManager().delete(charter); + player.getCharItemManager().updateInventory(); + player.incVer(); - DispatchMessage.sendToAllInRange(player, new GuildInfoMsg(player, newGuild, 2)); + DispatchMessage.sendToAllInRange(player, new GuildInfoMsg(player, newGuild, 2)); - ChatManager.chatSystemInfo(player, msg.getName() + " has arrived on Grief server!"); + ChatManager.chatSystemInfo(player, msg.getName() + " has arrived on Grief server!"); - return true; - } + return true; + } } diff --git a/src/engine/net/client/handlers/GuildCreationOptionsHandler.java b/src/engine/net/client/handlers/GuildCreationOptionsHandler.java index 6dbbb680..8b957be1 100644 --- a/src/engine/net/client/handlers/GuildCreationOptionsHandler.java +++ b/src/engine/net/client/handlers/GuildCreationOptionsHandler.java @@ -19,21 +19,21 @@ import engine.objects.PlayerCharacter; public class GuildCreationOptionsHandler extends AbstractClientMsgHandler { - public GuildCreationOptionsHandler() { - super(GuildCreationOptionsMsg.class); - } + public GuildCreationOptionsHandler() { + super(GuildCreationOptionsMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - GuildCreationOptionsMsg msg = (GuildCreationOptionsMsg) baseMsg; + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + GuildCreationOptionsMsg msg = (GuildCreationOptionsMsg) baseMsg; PlayerCharacter sourcePlayer = origin.getPlayerCharacter(); Dispatch dispatch; - if(msg.getScreenType() == 1) { - msg.setScreenType(3); - } else if(msg.getScreenType() == 2) { - msg.setScreenType(4); - } + if (msg.getScreenType() == 1) { + msg.setScreenType(3); + } else if (msg.getScreenType() == 2) { + msg.setScreenType(4); + } if (sourcePlayer == null) return true; @@ -41,7 +41,7 @@ public class GuildCreationOptionsHandler extends AbstractClientMsgHandler { dispatch = Dispatch.borrow(sourcePlayer, msg); DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - return true; - } + return true; + } } diff --git a/src/engine/net/client/handlers/GuildInfoHandler.java b/src/engine/net/client/handlers/GuildInfoHandler.java index 8e490a97..550cdd0a 100644 --- a/src/engine/net/client/handlers/GuildInfoHandler.java +++ b/src/engine/net/client/handlers/GuildInfoHandler.java @@ -21,47 +21,47 @@ import engine.objects.PlayerCharacter; public class GuildInfoHandler extends AbstractClientMsgHandler { - public GuildInfoHandler() { - super(GuildInfoMsg.class); - } + public GuildInfoHandler() { + super(GuildInfoMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - GuildInfoMsg msg = (GuildInfoMsg) baseMsg; + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + GuildInfoMsg msg = (GuildInfoMsg) baseMsg; Dispatch dispatch; - // get source player - PlayerCharacter sourcePlayer = SessionManager - .getPlayerCharacter(origin); + // get source player + PlayerCharacter sourcePlayer = SessionManager + .getPlayerCharacter(origin); - if (sourcePlayer == null) - return true; - - if(msg.getMsgType() == 1) { - dispatch = Dispatch.borrow(sourcePlayer, new GuildInfoMsg(sourcePlayer, sourcePlayer.getGuild(), 4)); + if (sourcePlayer == null) + return true; + + if (msg.getMsgType() == 1) { + dispatch = Dispatch.borrow(sourcePlayer, new GuildInfoMsg(sourcePlayer, sourcePlayer.getGuild(), 4)); DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - } else if(msg.getMsgType() == 5) { - - if(msg.getObjectType() == GameObjectType.PlayerCharacter.ordinal()) { - PlayerCharacter pc = PlayerCharacter.getPlayerCharacter(msg.getObjectID()); + } else if (msg.getMsgType() == 5) { + + if (msg.getObjectType() == GameObjectType.PlayerCharacter.ordinal()) { + PlayerCharacter pc = PlayerCharacter.getPlayerCharacter(msg.getObjectID()); dispatch = Dispatch.borrow(sourcePlayer, new GuildInfoMsg(pc, pc.getGuild(), 5)); DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - } else { - //TODO Change this to a null object when we make a null object. + } else { + //TODO Change this to a null object when we make a null object. - dispatch = Dispatch.borrow(sourcePlayer,new GuildInfoMsg(sourcePlayer, sourcePlayer.getGuild(), 1)); + dispatch = Dispatch.borrow(sourcePlayer, new GuildInfoMsg(sourcePlayer, sourcePlayer.getGuild(), 1)); DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - } - } - - // Send PromoteDemoteScreen info message response. 0x001D4DF6 - - // Send guild member list? 0x6949C720 - // GuildList(source, origin); - - // send 0x3235E5EA? See what that is - - return true; - } + } + } + + // Send PromoteDemoteScreen info message response. 0x001D4DF6 + + // Send guild member list? 0x6949C720 + // GuildList(source, origin); + + // send 0x3235E5EA? See what that is + + return true; + } } diff --git a/src/engine/net/client/handlers/GuildListHandler.java b/src/engine/net/client/handlers/GuildListHandler.java index f4eb052c..c3aea390 100644 --- a/src/engine/net/client/handlers/GuildListHandler.java +++ b/src/engine/net/client/handlers/GuildListHandler.java @@ -16,21 +16,21 @@ import engine.net.client.msg.guild.GuildListMsg; public class GuildListHandler extends AbstractClientMsgHandler { - public GuildListHandler() { - super(GuildListMsg.class); - } + public GuildListHandler() { + super(GuildListMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { // GuildListMsg msg = (GuildListMsg) baseMsg; - - // GuildListMsg msg = new GuildListMsg(origin); - // GuildTableList gtl = new GuildTableList(); - // gtl.setUUID(pc.getUUID()); gtl.setName(pc.getName()); - // msg.add(gtl); - // origin.sendMsg(msg); - - return true; - } + + // GuildListMsg msg = new GuildListMsg(origin); + // GuildTableList gtl = new GuildTableList(); + // gtl.setUUID(pc.getUUID()); gtl.setName(pc.getName()); + // msg.add(gtl); + // origin.sendMsg(msg); + + return true; + } } diff --git a/src/engine/net/client/handlers/GuildUnknownHandler.java b/src/engine/net/client/handlers/GuildUnknownHandler.java index c488e0cf..9657fa1d 100644 --- a/src/engine/net/client/handlers/GuildUnknownHandler.java +++ b/src/engine/net/client/handlers/GuildUnknownHandler.java @@ -16,14 +16,14 @@ import engine.net.client.msg.guild.GuildUnknownMsg; public class GuildUnknownHandler extends AbstractClientMsgHandler { - public GuildUnknownHandler() { - super(GuildUnknownMsg.class); - } + public GuildUnknownHandler() { + super(GuildUnknownMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { // GuildUnknownMsg msg = (GuildUnknownMsg) baseMsg; - return true; - } + return true; + } } diff --git a/src/engine/net/client/handlers/HirelingServiceMsgHandler.java b/src/engine/net/client/handlers/HirelingServiceMsgHandler.java index c5c90a70..44d9a6d2 100644 --- a/src/engine/net/client/handlers/HirelingServiceMsgHandler.java +++ b/src/engine/net/client/handlers/HirelingServiceMsgHandler.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -38,57 +35,56 @@ import engine.objects.PlayerCharacter; public class HirelingServiceMsgHandler extends AbstractClientMsgHandler { - public HirelingServiceMsgHandler() { - super(HirelingServiceMsg.class); - } - - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - - PlayerCharacter player; - HirelingServiceMsg msg; - - msg = (HirelingServiceMsg) baseMsg; - - // get PlayerCharacter of person accepting invite - - player = SessionManager.getPlayerCharacter(origin); - - if (player == null) - return true; - - switch (msg.messageType){ - case HirelingServiceMsg.SETREPAIRCOST: - Building building = BuildingManager.getBuildingFromCache(msg.buildingID); - - if (building == null) - return true; - - NPC npc = NPC.getFromCache(msg.npcID); - - if (npc == null) - return true; - - if (!BuildingManager.playerCanManage(player, building)) - return true; - - - - npc.setRepairCost(msg.repairCost); - ManageNPCMsg outMsg = new ManageNPCMsg(npc); - Dispatch dispatch = Dispatch.borrow(player, msg); - - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - dispatch = Dispatch.borrow(player, outMsg); - - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - break; - } - - - return true; - - - } + public HirelingServiceMsgHandler() { + super(HirelingServiceMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter player; + HirelingServiceMsg msg; + + msg = (HirelingServiceMsg) baseMsg; + + // get PlayerCharacter of person accepting invite + + player = SessionManager.getPlayerCharacter(origin); + + if (player == null) + return true; + + switch (msg.messageType) { + case HirelingServiceMsg.SETREPAIRCOST: + Building building = BuildingManager.getBuildingFromCache(msg.buildingID); + + if (building == null) + return true; + + NPC npc = NPC.getFromCache(msg.npcID); + + if (npc == null) + return true; + + if (!BuildingManager.playerCanManage(player, building)) + return true; + + + npc.setRepairCost(msg.repairCost); + ManageNPCMsg outMsg = new ManageNPCMsg(npc); + Dispatch dispatch = Dispatch.borrow(player, msg); + + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + dispatch = Dispatch.borrow(player, outMsg); + + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + break; + } + + + return true; + + + } } diff --git a/src/engine/net/client/handlers/InviteToGuildHandler.java b/src/engine/net/client/handlers/InviteToGuildHandler.java index 84123cca..cce00445 100644 --- a/src/engine/net/client/handlers/InviteToGuildHandler.java +++ b/src/engine/net/client/handlers/InviteToGuildHandler.java @@ -27,125 +27,123 @@ import engine.objects.PlayerCharacter; public class InviteToGuildHandler extends AbstractClientMsgHandler { - public InviteToGuildHandler() { - super(InviteToGuildMsg.class); - } + public InviteToGuildHandler() { + super(InviteToGuildMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - InviteToGuildMsg msg; - PlayerCharacter sourcePlayer; - PlayerCharacter targetPlayer; - Dispatch dispatch; + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + InviteToGuildMsg msg; + PlayerCharacter sourcePlayer; + PlayerCharacter targetPlayer; + Dispatch dispatch; - msg = (InviteToGuildMsg) baseMsg; + msg = (InviteToGuildMsg) baseMsg; - // First see if this is a refusal to another guild invite + // First see if this is a refusal to another guild invite - if (msg.getResponse() == 4) - return true; // Player refused invite + if (msg.getResponse() == 4) + return true; // Player refused invite - // get sourcePlayer player + // get sourcePlayer player - sourcePlayer = SessionManager.getPlayerCharacter(origin); + sourcePlayer = SessionManager.getPlayerCharacter(origin); - if (sourcePlayer == null) - return true; + if (sourcePlayer == null) + return true; - if (msg.getTargetUUID() == 0) { - // get targetPlayer player by name - targetPlayer = SessionManager.getPlayerCharacterByLowerCaseName(msg.getTargetName()); + if (msg.getTargetUUID() == 0) { + // get targetPlayer player by name + targetPlayer = SessionManager.getPlayerCharacterByLowerCaseName(msg.getTargetName()); - if (targetPlayer == null) { - ChatManager.chatGuildError(sourcePlayer, - "No such player exists!"); - return true; - } - } else - if (msg.getTargetType() == GameObjectType.PlayerCharacter.ordinal()) { + if (targetPlayer == null) { + ChatManager.chatGuildError(sourcePlayer, + "No such player exists!"); + return true; + } + } else if (msg.getTargetType() == GameObjectType.PlayerCharacter.ordinal()) { - targetPlayer = SessionManager.getPlayerCharacterByID(msg.getTargetUUID()); + targetPlayer = SessionManager.getPlayerCharacterByID(msg.getTargetUUID()); - if (targetPlayer == null) { - ChatManager.chatGuildError(sourcePlayer, - "No such player exists!"); - return true; - } - } else { - ChatManager.chatGuildError(sourcePlayer, - "You cannot invite that character!"); - return true; - } + if (targetPlayer == null) { + ChatManager.chatGuildError(sourcePlayer, + "No such player exists!"); + return true; + } + } else { + ChatManager.chatGuildError(sourcePlayer, + "You cannot invite that character!"); + return true; + } - // get sourcePlayer guild. Verify sourcePlayer player is in guild + // get sourcePlayer guild. Verify sourcePlayer player is in guild - if (sourcePlayer.getGuild().getObjectUUID() == 0 || sourcePlayer.getGuild().isEmptyGuild()) { - ChatManager.chatGuildError(sourcePlayer, - "You cannot invite someone for errant!"); - return true; - } + if (sourcePlayer.getGuild().getObjectUUID() == 0 || sourcePlayer.getGuild().isEmptyGuild()) { + ChatManager.chatGuildError(sourcePlayer, + "You cannot invite someone for errant!"); + return true; + } - Enum.GuildType guildType = Enum.GuildType.values()[sourcePlayer.getGuild().getCharter()]; + Enum.GuildType guildType = Enum.GuildType.values()[sourcePlayer.getGuild().getCharter()]; - if (guildType == null){ - ErrorPopupMsg.sendErrorPopup(sourcePlayer, GuildManager.NO_CHARTER_FOUND); - return true; - } + if (guildType == null) { + ErrorPopupMsg.sendErrorPopup(sourcePlayer, GuildManager.NO_CHARTER_FOUND); + return true; + } + // verify sourcePlayer player is full member so they can invite - // verify sourcePlayer player is full member so they can invite + if (GuildStatusController.isFullMember(sourcePlayer.getGuildStatus()) == false) { + ChatManager.chatGuildError(sourcePlayer, + "You do not have authority to invite!"); + return true; + } - if (GuildStatusController.isFullMember(sourcePlayer.getGuildStatus()) == false) { - ChatManager.chatGuildError(sourcePlayer, - "You do not have authority to invite!"); - return true; - } + //block invite is targetPlayer is ignoring sourcePlayer - //block invite is targetPlayer is ignoring sourcePlayer + if (targetPlayer.isIgnoringPlayer(sourcePlayer)) + return true; - if (targetPlayer.isIgnoringPlayer(sourcePlayer)) - return true; + if ((targetPlayer.getGuild().isEmptyGuild() == false)) { + ChatManager.chatGuildError(sourcePlayer, + targetPlayer.getFirstName() + " already belongs to a guild!"); + return true; + } - if ((targetPlayer.getGuild().isEmptyGuild() == false)) { - ChatManager.chatGuildError(sourcePlayer, - targetPlayer.getFirstName() + " already belongs to a guild!"); - return true; - } + // verify targetPlayer player is not on banish list - // verify targetPlayer player is not on banish list + if (sourcePlayer.getGuild().getBanishList().contains(targetPlayer)) { + ErrorPopupMsg.sendErrorPopup(sourcePlayer, 135);// Character is considered BANISHED by guild leadership + return true; + } - if (sourcePlayer.getGuild().getBanishList().contains(targetPlayer)) { - ErrorPopupMsg.sendErrorPopup(sourcePlayer, 135);// Character is considered BANISHED by guild leadership - return true; - } + //verify targetPlayer meets level requirements of guild - //verify targetPlayer meets level requirements of guild + if ((targetPlayer.getLevel() < sourcePlayer.getGuild().getRepledgeMin()) || targetPlayer.getLevel() > sourcePlayer.getGuild().getRepledgeMax()) { + ErrorPopupMsg.sendErrorPopup(sourcePlayer, 135);// you do not meet the level required for this SWORN guild + return true; + } - if ((targetPlayer.getLevel() < sourcePlayer.getGuild().getRepledgeMin()) || targetPlayer.getLevel() > sourcePlayer.getGuild().getRepledgeMax()) { - ErrorPopupMsg.sendErrorPopup(sourcePlayer, 135);// you do not meet the level required for this SWORN guild - return true; - } + targetPlayer.setLastGuildToInvite(sourcePlayer.getGuild().getObjectUUID()); - targetPlayer.setLastGuildToInvite(sourcePlayer.getGuild().getObjectUUID()); + // setup guild invite message to send to targetPlayer - // setup guild invite message to send to targetPlayer + msg.setSourceType(sourcePlayer.getObjectType().ordinal()); + msg.setSourceUUID(sourcePlayer.getObjectUUID()); + msg.setTargetType(targetPlayer.getObjectType().ordinal()); - msg.setSourceType(sourcePlayer.getObjectType().ordinal()); - msg.setSourceUUID(sourcePlayer.getObjectUUID()); - msg.setTargetType(targetPlayer.getObjectType().ordinal()); + msg.setTargetUUID(targetPlayer.getObjectUUID()); + msg.setGuildTag(sourcePlayer.getGuild().getGuildTag()); + msg.setGuildName(sourcePlayer.getGuild().getName()); + msg.setGuildType(sourcePlayer.getGuild().getObjectType().ordinal()); + msg.setGuildUUID(sourcePlayer.getGuild().getObjectUUID()); + msg.setTargetName(""); - msg.setTargetUUID(targetPlayer.getObjectUUID()); - msg.setGuildTag(sourcePlayer.getGuild().getGuildTag()); - msg.setGuildName(sourcePlayer.getGuild().getName()); - msg.setGuildType(sourcePlayer.getGuild().getObjectType().ordinal()); - msg.setGuildUUID(sourcePlayer.getGuild().getObjectUUID()); - msg.setTargetName(""); + dispatch = Dispatch.borrow(targetPlayer, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - dispatch = Dispatch.borrow(targetPlayer, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - return true; - } + return true; + } } diff --git a/src/engine/net/client/handlers/InviteToSubHandler.java b/src/engine/net/client/handlers/InviteToSubHandler.java index 78578a21..bab06111 100644 --- a/src/engine/net/client/handlers/InviteToSubHandler.java +++ b/src/engine/net/client/handlers/InviteToSubHandler.java @@ -27,107 +27,107 @@ import engine.objects.PlayerCharacter; public class InviteToSubHandler extends AbstractClientMsgHandler { - public InviteToSubHandler() { - super(InviteToSubMsg.class); - } + public InviteToSubHandler() { + super(InviteToSubMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + private static void sendChat(PlayerCharacter source, String msg) { + ChatManager.chatGuildError(source, msg); + } - PlayerCharacter source; - PlayerCharacter target; - Guild sourceGuild; - Guild targetGuild; - InviteToSubMsg msg = (InviteToSubMsg) baseMsg; - Dispatch dispatch; + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - source = SessionManager.getPlayerCharacter(origin); + PlayerCharacter source; + PlayerCharacter target; + Guild sourceGuild; + Guild targetGuild; + InviteToSubMsg msg = (InviteToSubMsg) baseMsg; + Dispatch dispatch; - if (source == null) - return true; + source = SessionManager.getPlayerCharacter(origin); - target = (PlayerCharacter) DbManager.getObject(GameObjectType.PlayerCharacter, msg.getTargetUUID()); + if (source == null) + return true; - if (target == null) { - ErrorPopupMsg.sendErrorMsg(source, "A Serious error has occured. Please post details for to ensure transaction integrity"); - return true; - } + target = (PlayerCharacter) DbManager.getObject(GameObjectType.PlayerCharacter, msg.getTargetUUID()); - //Ignore invites to sub if ignoring player + if (target == null) { + ErrorPopupMsg.sendErrorMsg(source, "A Serious error has occured. Please post details for to ensure transaction integrity"); + return true; + } - if (target.isIgnoringPlayer(source)) - return true; + //Ignore invites to sub if ignoring player - sourceGuild = source.getGuild(); - targetGuild = target.getGuild(); + if (target.isIgnoringPlayer(source)) + return true; - //source must be in guild + sourceGuild = source.getGuild(); + targetGuild = target.getGuild(); - if (sourceGuild == null) { - sendChat(source, "You must be in a guild to invite to sub."); - return true; - } + //source must be in guild - if (sourceGuild.isEmptyGuild()){ - sendChat(source, "You must be in a guild to invite to sub."); - return true; - } + if (sourceGuild == null) { + sendChat(source, "You must be in a guild to invite to sub."); + return true; + } - //source must be GL or IC + if (sourceGuild.isEmptyGuild()) { + sendChat(source, "You must be in a guild to invite to sub."); + return true; + } - if (GuildStatusController.isInnerCouncil(source.getGuildStatus()) == false) { - sendChat(source, "Only guild leadership can invite to sub."); - return true; - } + //source must be GL or IC - if (sourceGuild.getNation().isEmptyGuild()) - return true; + if (GuildStatusController.isInnerCouncil(source.getGuildStatus()) == false) { + sendChat(source, "Only guild leadership can invite to sub."); + return true; + } - //target must be in a guild + if (sourceGuild.getNation().isEmptyGuild()) + return true; - if (targetGuild == null) - return true; - - if (sourceGuild.equals(targetGuild)) - return true; + //target must be in a guild - //target must be GL or IC + if (targetGuild == null) + return true; - if (GuildStatusController.isInnerCouncil(target.getGuildStatus()) == false && GuildStatusController.isGuildLeader(target.getGuildStatus()) == false) { - sendChat(source, "Target player is not guild leadership."); - return true; - } + if (sourceGuild.equals(targetGuild)) + return true; - //Can't already be same nation or errant - //source guild is limited to 7 subs - //TODO this should be based on TOL rank + //target must be GL or IC + if (GuildStatusController.isInnerCouncil(target.getGuildStatus()) == false && GuildStatusController.isGuildLeader(target.getGuildStatus()) == false) { + sendChat(source, "Target player is not guild leadership."); + return true; + } - if (!sourceGuild.canSubAGuild(targetGuild)) { - sendChat(source, "This Guild can't be subbed."); - return true; - } + //Can't already be same nation or errant + //source guild is limited to 7 subs + //TODO this should be based on TOL rank - //all tests passed, let's send invite. - if (target.getClientConnection() != null) { - msg.setGuildTag(sourceGuild.getGuildTag()); - msg.setGuildName(sourceGuild.getName()); - msg.setGuildUUID(sourceGuild.getObjectUUID()); - msg.setUnknown02(1); + if (!sourceGuild.canSubAGuild(targetGuild)) { + sendChat(source, "This Guild can't be subbed."); + return true; + } - dispatch = Dispatch.borrow(target, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + //all tests passed, let's send invite. - } else { - sendChat(source, "Failed to send sub invite to target."); - return true; - } + if (target.getClientConnection() != null) { + msg.setGuildTag(sourceGuild.getGuildTag()); + msg.setGuildName(sourceGuild.getName()); + msg.setGuildUUID(sourceGuild.getObjectUUID()); + msg.setUnknown02(1); - return true; - } + dispatch = Dispatch.borrow(target, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - private static void sendChat(PlayerCharacter source, String msg) { - ChatManager.chatGuildError(source, msg); - } + } else { + sendChat(source, "Failed to send sub invite to target."); + return true; + } + + return true; + } } diff --git a/src/engine/net/client/handlers/ItemProductionMsgHandler.java b/src/engine/net/client/handlers/ItemProductionMsgHandler.java index f0848bf6..3134f939 100644 --- a/src/engine/net/client/handlers/ItemProductionMsgHandler.java +++ b/src/engine/net/client/handlers/ItemProductionMsgHandler.java @@ -34,488 +34,478 @@ import java.util.HashMap; */ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { - private static final int ACTION_PRODUCE = 1; - private static final int ACTION_JUNK = 2; - private static final int ACTION_RECYCLE = 3; - private static final int ACTION_COMPLETE = 4; - private static final int ACTION_DEPOSIT = 6; - private static final int ACTION_SETPRICE = 5; - private static final int ACTION_TAKE = 7; - private static final int ACTION_CONFIRM_SETPRICE = 9; // Unsure. Sent by client - private static final int ACTION_CONFIRM_DEPOSIT = 10; // Unsure. Sent by client - private static final int ACTION_CONFIRM_TAKE = 11; // Unsure. Sent by client + private static final int ACTION_PRODUCE = 1; + private static final int ACTION_JUNK = 2; + private static final int ACTION_RECYCLE = 3; + private static final int ACTION_COMPLETE = 4; + private static final int ACTION_DEPOSIT = 6; + private static final int ACTION_SETPRICE = 5; + private static final int ACTION_TAKE = 7; + private static final int ACTION_CONFIRM_SETPRICE = 9; // Unsure. Sent by client + private static final int ACTION_CONFIRM_DEPOSIT = 10; // Unsure. Sent by client + private static final int ACTION_CONFIRM_TAKE = 11; // Unsure. Sent by client - public ItemProductionMsgHandler() { - super(ItemProductionMsg.class); - } + public ItemProductionMsgHandler() { + super(ItemProductionMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + private static void setItemPrice(int itemType, int itemUUID, int itemPrice, NPC vendor, ClientConnection origin) { - // Member variable declaration - - PlayerCharacter player; - NPC vendorNPC; - ItemProductionMsg msg; - Dispatch dispatch; + Item targetItem; + ItemProductionMsg outMsg; + Dispatch dispatch; - // Member variable assignment + PlayerCharacter player = origin.getPlayerCharacter(); - msg = (ItemProductionMsg) baseMsg; - player = origin.getPlayerCharacter(); + if (player == null) + return; - if (player == null) - return true; - - // Grab reference to vendor we are interacting with - - vendorNPC = (NPC) DbManager.getObject(engine.Enum.GameObjectType.NPC, msg.getNpcUUID()); - - // Oops? - - if (vendorNPC == null) - return true; - - // Process Request - - switch (msg.getActionType()) { - - case ACTION_PRODUCE: - boolean isRandom = false; - if (msg.getUnknown03() != 0 && msg.getpToken() == 0 && msg.getsToken() == 0) - isRandom = true; - //Create Multiple Item Function.. Fill all empty slots - if (msg.isMultiple()){ - int emptySlots = vendorNPC.getRank() - vendorNPC.getRolling().size(); - if (emptySlots > 0){ - for (int i = 0;i 500) { + ErrorPopupMsg.sendErrorPopup(player, 21); + return; + } - // Method adds an item from the players inventory to the vendor. + if (!targetItem.validForInventory(origin, player, itemMan)) { + ErrorPopupMsg.sendErrorPopup(player, 19); + return; + } - private static void depositItem(int itemUUID, NPC vendor, ClientConnection origin) { + // Transfer item from player to vendor's inventory - Item targetItem; - ItemProductionMsg outMsg; - CharacterItemManager itemMan; - Dispatch dispatch; + if (!itemMan.sellToNPC(targetItem, vendor)) { + ErrorPopupMsg.sendErrorPopup(player, 109); + return; + } - PlayerCharacter player = origin.getPlayerCharacter(); - if (player == null) - return; + outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, ACTION_DEPOSIT, true); + dispatch = Dispatch.borrow(player, outMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - if (origin.sellLock.tryLock()) { - try { - targetItem = Item.getFromCache(itemUUID); + outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, ACTION_CONFIRM_DEPOSIT, true); + dispatch = Dispatch.borrow(player, outMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - if (targetItem == null) - return; + origin.getPlayerCharacter().getCharItemManager().updateInventory(); + } catch (Exception e) { + Logger.error(e); + } finally { + origin.sellLock.unlock(); + } - if (targetItem.getItemBase().getType() == ItemType.GOLD) - return; + } - if (!vendor.getCharItemManager().hasRoomInventory(targetItem.getItemBase().getWeight())){ - ErrorPopupMsg.sendErrorPopup(player, 21); - return; - } + } - itemMan = origin.getPlayerCharacter().getCharItemManager(); + // Method adds an item from the players inventory to the vendor. - if (itemMan == null) - return; + private static void completeItem(int itemUUID, NPC vendor, ClientConnection origin, ItemProductionMsg msg) { - if (vendor.getCharItemManager().getInventoryWeight() > 500) { - ErrorPopupMsg.sendErrorPopup(player, 21); - return; - } + Item targetItem; + ManageNPCMsg outMsg; + Dispatch dispatch; - if (!targetItem.validForInventory(origin, player, itemMan)){ - ErrorPopupMsg.sendErrorPopup(player, 19); - return; - } + PlayerCharacter player = origin.getPlayerCharacter(); - // Transfer item from player to vendor's inventory + if (player == null) + return; - if (!itemMan.sellToNPC(targetItem, vendor)){ - ErrorPopupMsg.sendErrorPopup(player, 109); - return; - } + if (origin.buyLock.tryLock()) { + try { + targetItem = Item.getFromCache(itemUUID); + if (targetItem == null) + return; - outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, ACTION_DEPOSIT, true); - dispatch = Dispatch.borrow(player, outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, ACTION_CONFIRM_DEPOSIT, true); - dispatch = Dispatch.borrow(player, outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + if (!vendor.getCharItemManager().forgeContains(targetItem, vendor)) + return; - origin.getPlayerCharacter().getCharItemManager().updateInventory(); - }catch (Exception e){ - Logger.error(e); - }finally { - origin.sellLock.unlock(); - } - - } - + boolean worked = DbManager.ItemQueries.UPDATE_FORGE_TO_INVENTORY(targetItem); + if (!worked) { + Guild guild = vendor.getGuild(); + if (guild == null) + return; + //ChatManager.chatGuildInfo(guild, "Failed to complete Item " + targetItem.getName()); + return; + } + targetItem.containerType = Enum.ItemContainerType.INVENTORY; + targetItem.setOwner(vendor); + vendor.getCharItemManager().addItemToInventory(targetItem); - } + vendor.removeItemFromForge(targetItem); - // Method completes an item that has been previously rolled - // adding it to the NPC's inventory + outMsg = new ManageNPCMsg(vendor); + outMsg.setMessageType(ACTION_PRODUCE); + dispatch = Dispatch.borrow(player, outMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } finally { + origin.buyLock.unlock(); + } + } + } - private static void completeItem(int itemUUID, NPC vendor, ClientConnection origin, ItemProductionMsg msg) { + // Method completes an item that has been previously rolled + // adding it to the NPC's inventory - Item targetItem; - ManageNPCMsg outMsg; - Dispatch dispatch; + private static void recycleItem(HashMap itemList, NPC vendor, ClientConnection origin) { - PlayerCharacter player = origin.getPlayerCharacter(); + Item targetItem; + ItemProductionMsg outMsg; + int totalValue = 0; + int currentStrongbox; + Dispatch dispatch; - if (player == null) - return; + if (vendor.getBuilding() == null) + return; - if (origin.buyLock.tryLock()) { - try { - targetItem = Item.getFromCache(itemUUID); + PlayerCharacter player = origin.getPlayerCharacter(); - if (targetItem == null) - return; + if (player == null) + return; + if (itemList == null) + return; - if (!vendor.getCharItemManager().forgeContains(targetItem, vendor)) - return; + if (origin.sellLock.tryLock()) { + try { - boolean worked = DbManager.ItemQueries.UPDATE_FORGE_TO_INVENTORY(targetItem); - if (!worked) { - Guild guild = vendor.getGuild(); - if (guild == null) - return; - //ChatManager.chatGuildInfo(guild, "Failed to complete Item " + targetItem.getName()); - return; - } - targetItem.containerType = Enum.ItemContainerType.INVENTORY; - targetItem.setOwner(vendor); - vendor.getCharItemManager().addItemToInventory(targetItem); + for (int itemUUID : itemList.keySet()) { + int itemValue = 0; - vendor.removeItemFromForge(targetItem); + int type = itemList.get(itemUUID); - outMsg = new ManageNPCMsg(vendor); - outMsg.setMessageType(ACTION_PRODUCE); - dispatch = Dispatch.borrow(player, outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } finally { - origin.buyLock.unlock(); - } - } - } + if (type == GameObjectType.Item.ordinal()) + targetItem = Item.getFromCache(itemUUID); + else + targetItem = MobLoot.getFromCache(itemUUID); - // Method handles recycling of an item + if (targetItem == null) + continue; - private static void recycleItem(HashMap itemList, NPC vendor, ClientConnection origin) { + if (targetItem.getItemBase().getType() == ItemType.GOLD) + return; - Item targetItem; - ItemProductionMsg outMsg; - int totalValue = 0; - int currentStrongbox; - Dispatch dispatch; + if (!vendor.getCharItemManager().doesCharOwnThisItem(targetItem.getObjectUUID())) + continue; + if (vendor.getCharItemManager().inventoryContains(targetItem) == false) + continue; - if (vendor.getBuilding() == null) - return; + itemValue = targetItem.getBaseValue(); - PlayerCharacter player = origin.getPlayerCharacter(); + if (vendor.getBuilding().getStrongboxValue() + itemValue > vendor.getBuilding().getMaxGold()) { + ErrorPopupMsg.sendErrorPopup(player, 201); + break; + } - if (player == null) - return; + switch (targetItem.getItemBase().getType()) { + case CONTRACT: + case GUILDCHARTER: + case DEED: + case REALMCHARTER: + case SCROLL: + case TEARS: + itemValue = 0; + continue; + } + totalValue += itemValue; + long start = System.currentTimeMillis(); + vendor.getCharItemManager().recycle(targetItem); + long end = System.currentTimeMillis(); + long timetook = end - start; - if (itemList == null) - return; - - if (origin.sellLock.tryLock()) { - try { + // ChatManager.chatSystemInfo(player, "Took " + timetook + " ms to finish"); + outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, ACTION_TAKE, true); + dispatch = Dispatch.borrow(origin.getPlayerCharacter(), outMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } - for (int itemUUID : itemList.keySet()) { - int itemValue = 0; + // Refund a portion of the gold - int type = itemList.get(itemUUID); + if (!vendor.getBuilding().transferGold(totalValue, false)) + return; - if (type == GameObjectType.Item.ordinal()) - targetItem = Item.getFromCache(itemUUID); - else - targetItem = MobLoot.getFromCache(itemUUID); - if (targetItem == null) - continue; + } catch (Exception e) { + Logger.error(e); + } finally { - if (targetItem.getItemBase().getType() == ItemType.GOLD) - return; + origin.sellLock.unlock(); + } - if (!vendor.getCharItemManager().doesCharOwnThisItem(targetItem.getObjectUUID())) - continue; - if (vendor.getCharItemManager().inventoryContains(targetItem) == false) - continue; + } - itemValue = targetItem.getBaseValue(); + // Refresh vendor's inventory to client - if (vendor.getBuilding().getStrongboxValue() + itemValue > vendor.getBuilding().getMaxGold()) { - ErrorPopupMsg.sendErrorPopup(player, 201); - break; - } + } - switch (targetItem.getItemBase().getType()) { - case CONTRACT: - case GUILDCHARTER: - case DEED: - case REALMCHARTER: - case SCROLL: - case TEARS: - itemValue = 0; - continue; - } - totalValue += itemValue; - long start = System.currentTimeMillis(); - vendor.getCharItemManager().recycle(targetItem); - long end = System.currentTimeMillis(); - long timetook = end - start; + // Method handles recycling of an item - // ChatManager.chatSystemInfo(player, "Took " + timetook + " ms to finish"); + private static void junkItem(int itemUUID, NPC vendor, ClientConnection origin) { - outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, ACTION_TAKE, true); + MobLoot targetItem; + ManageNPCMsg outMsg; + Dispatch dispatch; - dispatch = Dispatch.borrow(origin.getPlayerCharacter(), outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } + if (origin.sellLock.tryLock()) { + try { + targetItem = MobLoot.getFromCache(itemUUID); - // Refund a portion of the gold + PlayerCharacter player = origin.getPlayerCharacter(); - if (!vendor.getBuilding().transferGold(totalValue,false)) - return; - - + if (player == null) + return; - }catch (Exception e){ - Logger.error(e); - }finally { - - origin.sellLock.unlock(); - } + // Can't junk nothing! - } + if (targetItem == null) + return; - // Refresh vendor's inventory to client - } + if (!vendor.getCharItemManager().forgeContains(targetItem, vendor)) + return; - // Method junks an item that has been rolled but not completed + // Cannot junk items without a forge! - private static void junkItem(int itemUUID, NPC vendor, ClientConnection origin) { + if (vendor.getBuilding() == null) + return; - MobLoot targetItem; - ManageNPCMsg outMsg; - Dispatch dispatch; + // Delete the item and cancel any pending rolling timer jobs - if (origin.sellLock.tryLock()) { - try { - targetItem = MobLoot.getFromCache(itemUUID); + targetItem.recycle(vendor); + vendor.removeItemFromForge(targetItem); - PlayerCharacter player = origin.getPlayerCharacter(); + // Refresh vendor's inventory to client - if (player == null) - return; + outMsg = new ManageNPCMsg(vendor); + outMsg.setMessageType(1); + dispatch = Dispatch.borrow(player, outMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + ; + } finally { + origin.sellLock.unlock(); + } + } - // Can't junk nothing! + } - if (targetItem == null) - return; + // Method junks an item that has been rolled but not completed + private static void takeItem(HashMap itemList, NPC vendor, ClientConnection origin) { + Item targetItem; - if (!vendor.getCharItemManager().forgeContains(targetItem, vendor)) - return; - // Cannot junk items without a forge! + PlayerCharacter player = origin.getPlayerCharacter(); - if (vendor.getBuilding() == null) - return; + if (player == null) + return; - // Delete the item and cancel any pending rolling timer jobs - targetItem.recycle(vendor); - vendor.removeItemFromForge(targetItem); + for (int itemUUID : itemList.keySet()) { - // Refresh vendor's inventory to client + int type = itemList.get(itemUUID); + if (type == GameObjectType.Item.ordinal()) { + targetItem = Item.getFromCache(itemUUID); - outMsg = new ManageNPCMsg(vendor); - outMsg.setMessageType(1); - dispatch = Dispatch.borrow(player, outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - ; - } finally { - origin.sellLock.unlock(); - } - } + } else { + targetItem = MobLoot.getFromCache(itemUUID); - } + } - // Method removes item from an NPC's inventory and transferes it to a player + if (targetItem == null) + return; - private static void takeItem(HashMap itemList, NPC vendor, ClientConnection origin) { - Item targetItem; + if (targetItem.getItemBase().getType() == ItemType.GOLD) + return; + if (vendor.getCharItemManager().inventoryContains(targetItem) == false) + return; + if (player.getCharItemManager().hasRoomInventory(targetItem.getItemBase().getWeight()) == false) + return; - PlayerCharacter player = origin.getPlayerCharacter(); + player.getCharItemManager().buyFromNPC(targetItem, vendor); - if (player == null) - return; + } + player.getCharItemManager().updateInventory(); + // Update NPC inventory to client - for (int itemUUID : itemList.keySet()) { - int type = itemList.get(itemUUID); - if (type == GameObjectType.Item.ordinal()){ - targetItem = Item.getFromCache(itemUUID); + } - } - else{ - targetItem = MobLoot.getFromCache(itemUUID); + // Method removes item from an NPC's inventory and transferes it to a player - } + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - if (targetItem == null) - return; + // Member variable declaration + PlayerCharacter player; + NPC vendorNPC; + ItemProductionMsg msg; + Dispatch dispatch; - if (targetItem.getItemBase().getType() == ItemType.GOLD) - return; - if (vendor.getCharItemManager().inventoryContains(targetItem) == false) - return; + // Member variable assignment - if (player.getCharItemManager().hasRoomInventory(targetItem.getItemBase().getWeight()) == false) - return; + msg = (ItemProductionMsg) baseMsg; + player = origin.getPlayerCharacter(); - player.getCharItemManager().buyFromNPC(targetItem, vendor); + if (player == null) + return true; - } + // Grab reference to vendor we are interacting with - player.getCharItemManager().updateInventory(); + vendorNPC = (NPC) DbManager.getObject(engine.Enum.GameObjectType.NPC, msg.getNpcUUID()); - // Update NPC inventory to client + // Oops? + if (vendorNPC == null) + return true; - } + // Process Request - // Method handles rolling item requests from the client + switch (msg.getActionType()) { + + case ACTION_PRODUCE: + boolean isRandom = false; + if (msg.getUnknown03() != 0 && msg.getpToken() == 0 && msg.getsToken() == 0) + isRandom = true; + //Create Multiple Item Function.. Fill all empty slots + if (msg.isMultiple()) { + int emptySlots = vendorNPC.getRank() - vendorNPC.getRolling().size(); + if (emptySlots > 0) { + for (int i = 0; i < emptySlots; i++) { + vendorNPC.produceItem(player.getObjectUUID(), msg.getTotalProduction(), isRandom, msg.getpToken(), msg.getsToken(), msg.getName(), msg.getItemUUID()); + } + } + } else + vendorNPC.produceItem(player.getObjectUUID(), msg.getTotalProduction(), isRandom, msg.getpToken(), msg.getsToken(), msg.getName(), msg.getItemUUID()); + break; + case ACTION_JUNK: + junkItem(msg.getItemUUID(), vendorNPC, origin); + break; + case ACTION_RECYCLE: + recycleItem(msg.getItemIDtoTypeMap(), vendorNPC, origin); + msg.setActionType(7); + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + break; + case ACTION_COMPLETE: + + vendorNPC.completeItem(msg.getItemUUID()); + + // ManageNPCMsg outMsg = new ManageNPCMsg(vendorNPC); + // outMsg.setMessageType(1); + // + // dispatch = Dispatch.borrow(player, outMsg); + // DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + + break; + case ACTION_DEPOSIT: + depositItem(msg.getItemUUID(), vendorNPC, origin); + break; + case ACTION_SETPRICE: + setItemPrice(msg.getItemType(), msg.getItemUUID(), msg.getItemPrice(), vendorNPC, origin); + break; + case ACTION_TAKE: + takeItem(msg.getItemIDtoTypeMap(), vendorNPC, origin); + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + break; + + } + return true; + } + + // Method handles rolling item requests from the client } diff --git a/src/engine/net/client/handlers/KeepAliveServerClientHandler.java b/src/engine/net/client/handlers/KeepAliveServerClientHandler.java index 827590df..da80f487 100644 --- a/src/engine/net/client/handlers/KeepAliveServerClientHandler.java +++ b/src/engine/net/client/handlers/KeepAliveServerClientHandler.java @@ -17,32 +17,31 @@ import engine.objects.PlayerCharacter; public class KeepAliveServerClientHandler extends AbstractClientMsgHandler { - public KeepAliveServerClientHandler() { - super(KeepAliveServerClientMsg.class); - } - - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - - PlayerCharacter pc = origin.getPlayerCharacter(); - - - - // Member variable declaration - - KeepAliveServerClientMsg msg; - - // Member variable assignment - - msg = (KeepAliveServerClientMsg) baseMsg; - - - // Send ping to client - - Dispatch dispatch = Dispatch.borrow(pc, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - - return true; - } + public KeepAliveServerClientHandler() { + super(KeepAliveServerClientMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter pc = origin.getPlayerCharacter(); + + + // Member variable declaration + + KeepAliveServerClientMsg msg; + + // Member variable assignment + + msg = (KeepAliveServerClientMsg) baseMsg; + + + // Send ping to client + + Dispatch dispatch = Dispatch.borrow(pc, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + + return true; + } } \ No newline at end of file diff --git a/src/engine/net/client/handlers/LeaveGroupHandler.java b/src/engine/net/client/handlers/LeaveGroupHandler.java index e181dca0..52fb7615 100644 --- a/src/engine/net/client/handlers/LeaveGroupHandler.java +++ b/src/engine/net/client/handlers/LeaveGroupHandler.java @@ -23,7 +23,7 @@ public class LeaveGroupHandler extends AbstractClientMsgHandler { @Override protected boolean _handleNetMsg(ClientNetMsg baseMsg, - ClientConnection origin) throws MsgSendException { + ClientConnection origin) throws MsgSendException { GroupManager.LeaveGroup(origin); return true; } diff --git a/src/engine/net/client/handlers/LeaveGuildHandler.java b/src/engine/net/client/handlers/LeaveGuildHandler.java index a369faee..0483469e 100644 --- a/src/engine/net/client/handlers/LeaveGuildHandler.java +++ b/src/engine/net/client/handlers/LeaveGuildHandler.java @@ -25,53 +25,53 @@ import engine.objects.PlayerCharacter; public class LeaveGuildHandler extends AbstractClientMsgHandler { - public LeaveGuildHandler() { - super(LeaveGuildMsg.class); - } + public LeaveGuildHandler() { + super(LeaveGuildMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - LeaveGuildMsg msg = (LeaveGuildMsg) baseMsg; - Dispatch dispatch; + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + LeaveGuildMsg msg = (LeaveGuildMsg) baseMsg; + Dispatch dispatch; - // get PlayerCharacter of person leaving invite + // get PlayerCharacter of person leaving invite - PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter(origin); + PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter(origin); - if (playerCharacter == null) - return true; + if (playerCharacter == null) + return true; - // Guild leader can't leave guild. must pass GL or disband + // Guild leader can't leave guild. must pass GL or disband - if (GuildStatusController.isGuildLeader(playerCharacter.getGuildStatus())) { - msg.setMessage("You must switch leadership of your guild before leaving!"); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - return true; - } + if (GuildStatusController.isGuildLeader(playerCharacter.getGuildStatus())) { + msg.setMessage("You must switch leadership of your guild before leaving!"); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + return true; + } - // Release all mine claims + // Release all mine claims - Mine.releaseMineClaims(playerCharacter); + Mine.releaseMineClaims(playerCharacter); - // get old Guild - Guild oldGuild = playerCharacter.getGuild(); + // get old Guild + Guild oldGuild = playerCharacter.getGuild(); - if (oldGuild == null || oldGuild.isEmptyGuild()) { - return true; - } + if (oldGuild == null || oldGuild.isEmptyGuild()) { + return true; + } - // Send left guild message to rest of guild - ChatManager.chatGuildInfo(oldGuild, playerCharacter.getFirstName() + " has left the guild."); + // Send left guild message to rest of guild + ChatManager.chatGuildInfo(oldGuild, playerCharacter.getFirstName() + " has left the guild."); - oldGuild.removePlayer(playerCharacter, GuildHistoryType.LEAVE); + oldGuild.removePlayer(playerCharacter, GuildHistoryType.LEAVE); - // Send message back to client - msg.setMessage("You have left the guild."); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + // Send message back to client + msg.setMessage("You have left the guild."); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - return true; - } + return true; + } } diff --git a/src/engine/net/client/handlers/LockUnlockDoorMsgHandler.java b/src/engine/net/client/handlers/LockUnlockDoorMsgHandler.java index 367c6911..9269fda6 100644 --- a/src/engine/net/client/handlers/LockUnlockDoorMsgHandler.java +++ b/src/engine/net/client/handlers/LockUnlockDoorMsgHandler.java @@ -18,7 +18,7 @@ import org.pmw.tinylog.Logger; * @Author: * @Summary: Processes application protocol message which handle * lock and unlock door requests to and from the client. - * + * */ public class LockUnlockDoorMsgHandler extends AbstractClientMsgHandler { @@ -31,14 +31,14 @@ public class LockUnlockDoorMsgHandler extends AbstractClientMsgHandler { protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { // Member variable declarations - + PlayerCharacter player; Building targetBuilding; int doorNum; LockUnlockDoorMsg msg; // Member variable assignment - + msg = (LockUnlockDoorMsg) baseMsg; player = SessionManager.getPlayerCharacter(origin); targetBuilding = BuildingManager.getBuilding((int) msg.getTargetID()); @@ -59,9 +59,9 @@ public class LockUnlockDoorMsgHandler extends AbstractClientMsgHandler { doorNum = Blueprint.getDoorNumberbyMesh(msg.getDoorID()); // Debugging code - + // Logger.debug("DoorLockUnlock", "Door mesh: " + msg.getDoorID() + " Door number: " + doorNum); - + boolean stateChanged; if (targetBuilding.isDoorLocked(doorNum)) { diff --git a/src/engine/net/client/handlers/LoginToGameServerMsgHandler.java b/src/engine/net/client/handlers/LoginToGameServerMsgHandler.java index 70fe7662..7413ceb4 100644 --- a/src/engine/net/client/handlers/LoginToGameServerMsgHandler.java +++ b/src/engine/net/client/handlers/LoginToGameServerMsgHandler.java @@ -25,100 +25,100 @@ import org.pmw.tinylog.Logger; public class LoginToGameServerMsgHandler extends AbstractClientMsgHandler { - public LoginToGameServerMsgHandler() { - super(LoginToGameServerMsg.class); - } + public LoginToGameServerMsgHandler() { + super(LoginToGameServerMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - LoginToGameServerMsg msg = (LoginToGameServerMsg) baseMsg; + LoginToGameServerMsg msg = (LoginToGameServerMsg) baseMsg; - CSSession sessionInfo = CSSession.getCrossServerSession(msg.getSecKey()); + CSSession sessionInfo = CSSession.getCrossServerSession(msg.getSecKey()); - if (sessionInfo == null) { - Logger.error("Failed to validate session information from " + origin.getLocalAddressAndPortAsString()); - origin.kickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to validate session data"); - // TODO Evaluate if we need to delete CSSessions here. We couldn't - // find it before, why would this attempt be different? + if (sessionInfo == null) { + Logger.error("Failed to validate session information from " + origin.getLocalAddressAndPortAsString()); + origin.kickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to validate session data"); + // TODO Evaluate if we need to delete CSSessions here. We couldn't + // find it before, why would this attempt be different? - return true; - } + return true; + } - Account acc = sessionInfo.getAccount(); + Account acc = sessionInfo.getAccount(); - if (acc == null) { - String err = "Session returned NULL Account. Conn:" + origin.getLocalAddressAndPortAsString(); - Logger.error(err); - origin.kickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, err); - return true; - } + if (acc == null) { + String err = "Session returned NULL Account. Conn:" + origin.getLocalAddressAndPortAsString(); + Logger.error(err); + origin.kickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, err); + return true; + } - PlayerCharacter pc = sessionInfo.getPlayerCharacter(); + PlayerCharacter pc = sessionInfo.getPlayerCharacter(); - if (pc == null) { - String err = "Session returned NULL PlayerCharacter. Conn:" + origin.getLocalAddressAndPortAsString(); + if (pc == null) { + String err = "Session returned NULL PlayerCharacter. Conn:" + origin.getLocalAddressAndPortAsString(); - Logger.error(err); - origin.kickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, err); - return true; - } + Logger.error(err); + origin.kickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, err); + return true; + } - // If account is suspended, kick + // If account is suspended, kick - if (acc.status.equals(Enum.AccountStatus.BANNED)) { - origin.kickToLogin(MBServerStatics.LOGINERROR_NO_MORE_PLAYTIME_ON_ACCOUNT, "Account banned."); - return true; - } + if (acc.status.equals(Enum.AccountStatus.BANNED)) { + origin.kickToLogin(MBServerStatics.LOGINERROR_NO_MORE_PLAYTIME_ON_ACCOUNT, "Account banned."); + return true; + } - ClientConnection old = SessionManager.getClientConnection(acc); + ClientConnection old = SessionManager.getClientConnection(acc); - if (old != null) - if (old != origin) { - Logger.info("Disconnecting other client connection Using Same Account " + old.getRemoteAddressAndPortAsString()); - old.disconnect(); - } + if (old != null) + if (old != origin) { + Logger.info("Disconnecting other client connection Using Same Account " + old.getRemoteAddressAndPortAsString()); + old.disconnect(); + } - // Set machine ID here from CSS info - origin.machineID = sessionInfo.getMachineID(); + // Set machine ID here from CSS info + origin.machineID = sessionInfo.getMachineID(); - // Send response - msg.setSecKey(""); + // Send response + msg.setSecKey(""); - if (!origin.sendMsg(msg)) { - Logger.error("Failed to send message"); - origin.kickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send ValidateGameServer to client."); - return true; - } + if (!origin.sendMsg(msg)) { + Logger.error("Failed to send message"); + origin.kickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send ValidateGameServer to client."); + return true; + } - //# Why was this all changed? - // CLEAN UP OTHER INSTANCES OF THIS CHARACTER + //# Why was this all changed? + // CLEAN UP OTHER INSTANCES OF THIS CHARACTER - Session toKill = SessionManager.getSession(sessionInfo.getPlayerCharacter()); + Session toKill = SessionManager.getSession(sessionInfo.getPlayerCharacter()); - if (toKill != null) { - if (toKill.getConn() != null) { - LoginErrorMsg lom = new LoginErrorMsg(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "You may not login the same character twice!"); - ClientConnection conn = toKill.getConn(); - if (conn != null && !conn.sendMsg(lom)) - Logger.error("Failed to send message"); // TODO Do we just accept this failure to send Msg? - } - SessionManager.remSession(toKill); - WorldGrid.RemoveWorldObject(sessionInfo.getPlayerCharacter()); - } - Session s = SessionManager.getNewSession(sessionInfo.getAccount(), origin); - SessionManager.setPlayerCharacter(s, sessionInfo.getPlayerCharacter()); + if (toKill != null) { + if (toKill.getConn() != null) { + LoginErrorMsg lom = new LoginErrorMsg(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "You may not login the same character twice!"); + ClientConnection conn = toKill.getConn(); + if (conn != null && !conn.sendMsg(lom)) + Logger.error("Failed to send message"); // TODO Do we just accept this failure to send Msg? + } + SessionManager.remSession(toKill); + WorldGrid.RemoveWorldObject(sessionInfo.getPlayerCharacter()); + } + Session s = SessionManager.getNewSession(sessionInfo.getAccount(), origin); + SessionManager.setPlayerCharacter(s, sessionInfo.getPlayerCharacter()); - Logger.info("Login from Account: " + sessionInfo.getAccount().getUname() + " Character: " + - sessionInfo.getPlayerCharacter().getName() + " machineID: " + sessionInfo.getMachineID()); + Logger.info("Login from Account: " + sessionInfo.getAccount().getUname() + " Character: " + + sessionInfo.getPlayerCharacter().getName() + " machineID: " + sessionInfo.getMachineID()); - // Log Admin Login Event + // Log Admin Login Event - if (pc.getAccount().status.equals(Enum.AccountStatus.ADMIN)) - DbManager.AccountQueries.WRITE_ADMIN_LOG(pc.getCombinedName(), "ADMIN LOGIN"); + if (pc.getAccount().status.equals(Enum.AccountStatus.ADMIN)) + DbManager.AccountQueries.WRITE_ADMIN_LOG(pc.getCombinedName(), "ADMIN LOGIN"); - DbManager.AccountQueries.SET_ACCOUNT_LOGIN(sessionInfo.getAccount(), sessionInfo.getPlayerCharacter().getName(), origin.getClientIpAddress(), sessionInfo.getMachineID()); - return true; - } + DbManager.AccountQueries.SET_ACCOUNT_LOGIN(sessionInfo.getAccount(), sessionInfo.getPlayerCharacter().getName(), origin.getClientIpAddress(), sessionInfo.getMachineID()); + return true; + } } \ No newline at end of file diff --git a/src/engine/net/client/handlers/MOTDCommitHandler.java b/src/engine/net/client/handlers/MOTDCommitHandler.java index b5b0c084..fba1e435 100644 --- a/src/engine/net/client/handlers/MOTDCommitHandler.java +++ b/src/engine/net/client/handlers/MOTDCommitHandler.java @@ -23,60 +23,60 @@ import engine.objects.PlayerCharacter; public class MOTDCommitHandler extends AbstractClientMsgHandler { - public MOTDCommitHandler() { - super(MOTDCommitMsg.class); - } - - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - MOTDCommitMsg msg = (MOTDCommitMsg) baseMsg; - Dispatch dispatch; - - // get source player - PlayerCharacter sourcePlayer = SessionManager.getPlayerCharacter( - origin); - - if (sourcePlayer == null) - return true; - - int type = msg.getType(); - - if (type == 0 || type == 1 || type == 3) { - - if (GuildStatusController.isInnerCouncil(sourcePlayer.getGuildStatus()) == false) - return true; - - Guild guild = sourcePlayer.getGuild(); - - if (guild == null) - return true; - - if (type == 1) { // Guild MOTD - guild.setMOTD(msg.getMessage()); - ChatManager.chatGuildMOTD(sourcePlayer, msg.getMessage(), - true); - } else if (type == 3) { // IC MOTD - guild.setICMOTD(msg.getMessage()); - ChatManager - .chatICMOTD(sourcePlayer, msg.getMessage(), true); - } else if (type == 0) { // Nation MOTD - Guild nation = guild.getNation(); - if (nation == null) - return true; - if (nation.isNation()) { // only - // nation's - // primary guild can - // set nation motd - nation.setMOTD(msg.getMessage()); - ChatManager.chatNationMOTD(sourcePlayer, - msg.getMessage(), true); - } - } + public MOTDCommitHandler() { + super(MOTDCommitMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + MOTDCommitMsg msg = (MOTDCommitMsg) baseMsg; + Dispatch dispatch; + + // get source player + PlayerCharacter sourcePlayer = SessionManager.getPlayerCharacter( + origin); + + if (sourcePlayer == null) + return true; + + int type = msg.getType(); + + if (type == 0 || type == 1 || type == 3) { + + if (GuildStatusController.isInnerCouncil(sourcePlayer.getGuildStatus()) == false) + return true; + + Guild guild = sourcePlayer.getGuild(); + + if (guild == null) + return true; + + if (type == 1) { // Guild MOTD + guild.setMOTD(msg.getMessage()); + ChatManager.chatGuildMOTD(sourcePlayer, msg.getMessage(), + true); + } else if (type == 3) { // IC MOTD + guild.setICMOTD(msg.getMessage()); + ChatManager + .chatICMOTD(sourcePlayer, msg.getMessage(), true); + } else if (type == 0) { // Nation MOTD + Guild nation = guild.getNation(); + if (nation == null) + return true; + if (nation.isNation()) { // only + // nation's + // primary guild can + // set nation motd + nation.setMOTD(msg.getMessage()); + ChatManager.chatNationMOTD(sourcePlayer, + msg.getMessage(), true); + } + } dispatch = Dispatch.borrow(sourcePlayer, msg); DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - } - - return true; - } + } + + return true; + } } diff --git a/src/engine/net/client/handlers/MOTDEditHandler.java b/src/engine/net/client/handlers/MOTDEditHandler.java index f5d1436a..a9309021 100644 --- a/src/engine/net/client/handlers/MOTDEditHandler.java +++ b/src/engine/net/client/handlers/MOTDEditHandler.java @@ -25,59 +25,59 @@ import engine.objects.PlayerCharacter; public class MOTDEditHandler extends AbstractClientMsgHandler { - public MOTDEditHandler() { - super(MOTDMsg.class); - } + public MOTDEditHandler() { + super(MOTDMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - MOTDMsg msg = (MOTDMsg) baseMsg; + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + MOTDMsg msg = (MOTDMsg) baseMsg; Dispatch dispatch; - // get source player - PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter( - origin); + // get source player + PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter( + origin); - if (playerCharacter == null) - return true; + if (playerCharacter == null) + return true; - int type = msg.getType(); + int type = msg.getType(); - msg.setResponse((byte) 1); - if (type == 0 || type == 1 || type == 3) { - if (GuildStatusController.isInnerCouncil(playerCharacter.getGuildStatus()) == false) { - ErrorPopupMsg.sendErrorMsg(playerCharacter, "You do not have such authority!"); - return true; - } + msg.setResponse((byte) 1); + if (type == 0 || type == 1 || type == 3) { + if (GuildStatusController.isInnerCouncil(playerCharacter.getGuildStatus()) == false) { + ErrorPopupMsg.sendErrorMsg(playerCharacter, "You do not have such authority!"); + return true; + } - Guild guild = playerCharacter.getGuild(); + Guild guild = playerCharacter.getGuild(); - if (guild == null || guild.getObjectUUID() == 0) { + if (guild == null || guild.getObjectUUID() == 0) { LeaveGuildMsg leaveGuildMsg = new LeaveGuildMsg(); leaveGuildMsg.setMessage("You do not belong to a guild!"); dispatch = Dispatch.borrow(playerCharacter, leaveGuildMsg); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - return true; - } - - if (type == 1) // Guild MOTD - msg.setMessage(guild.getMOTD()); - else if (type == 3) // IC MOTD - msg.setMessage(guild.getICMOTD()); - else if (type == 0) { // Nation MOTD - Guild nation = guild.getNation(); - if (nation == null || !nation.isNation()) { - ErrorPopupMsg.sendErrorMsg(playerCharacter, "You do not have such authority!"); - return true; - } - msg.setMessage(nation.getMOTD()); - } + return true; + } + + if (type == 1) // Guild MOTD + msg.setMessage(guild.getMOTD()); + else if (type == 3) // IC MOTD + msg.setMessage(guild.getICMOTD()); + else if (type == 0) { // Nation MOTD + Guild nation = guild.getNation(); + if (nation == null || !nation.isNation()) { + ErrorPopupMsg.sendErrorMsg(playerCharacter, "You do not have such authority!"); + return true; + } + msg.setMessage(nation.getMOTD()); + } dispatch = Dispatch.borrow(playerCharacter, msg); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } - - return true; - } + } + + return true; + } } diff --git a/src/engine/net/client/handlers/ManageCityAssetMsgHandler.java b/src/engine/net/client/handlers/ManageCityAssetMsgHandler.java index 6928b207..e2b0af01 100644 --- a/src/engine/net/client/handlers/ManageCityAssetMsgHandler.java +++ b/src/engine/net/client/handlers/ManageCityAssetMsgHandler.java @@ -25,340 +25,335 @@ import org.joda.time.DateTime; */ public class ManageCityAssetMsgHandler extends AbstractClientMsgHandler { - public ManageCityAssetMsgHandler() { - super(ManageCityAssetsMsg.class); - } - - public static boolean playerCanManageNotFriends(PlayerCharacter player, Building building){ - - //Player Can only Control Building if player is in Same Guild as Building and is higher rank than IC. - - if (player == null) - return false; - - if (building.getRank() == -1) - return false; - - if (BuildingManager.IsOwner(building, player)) - return true; - - if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false && GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false) - return false; - - //Somehow guild leader check fails above? lets check if Player is true Guild GL. - if (building.getGuild() != null && building.getGuild().isGuildLeader(player.getObjectUUID())) - return true; - - return Guild.sameGuild(building.getGuild(), player.getGuild()); - - } - - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - - ManageCityAssetsMsg msg; - PlayerCharacter player; - ManageCityAssetsMsg outMsg; - Building building; - - msg = (ManageCityAssetsMsg) baseMsg; - - player = SessionManager.getPlayerCharacter(origin); - - if (player == null) - return true; - - building = BuildingManager.getBuildingFromCache(msg.getTargetID()); - - if (building == null){ - if (msg.actionType == 14) { - - Zone zone = ZoneManager.findSmallestZone(player.getLoc()); - - if (!zone.isPlayerCity()){ - ErrorPopupMsg.sendErrorMsg(player, "Unable to find city to command."); - return true; - } - - City city = City.GetCityFromCache(zone.getPlayerCityUUID()); - - if (city == null){ - ErrorPopupMsg.sendErrorMsg(player, "Unable to find city to command."); - return true; - } - - if (!city.getGuild().equals(player.getGuild())){ - ErrorPopupMsg.sendErrorMsg(player, "You are not in the correct guild to command this city."); - return true; - } - - if (!GuildStatusController.isInnerCouncil(player.getGuildStatus()) && !GuildStatusController.isGuildLeader(player.getGuildStatus())){ - ErrorPopupMsg.sendErrorMsg(player, "You must be an Inner Council or Guild leader to access city commands."); - return true; - } - ManageCityAssetsMsg mca = new ManageCityAssetsMsg(player, building); - mca.actionType = 15; - Dispatch dispatch = Dispatch.borrow(player, mca); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } - return true; - } - - outMsg = new ManageCityAssetsMsg(player, building); - - if (player.isSafeMode()){ - outMsg.actionType = 4; - outMsg.setTargetType(building.getObjectType().ordinal()); - outMsg.setTargetID(building.getObjectUUID()); - outMsg.setAssetName(building.getName()); - Dispatch dispatch = Dispatch.borrow(player, outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - } - - if (msg.actionType == 2 || msg.actionType == 22) { - - if (building.getBlueprint() != null && building.getBlueprint().getBuildingGroup() == engine.Enum.BuildingGroup.BANESTONE) { - - outMsg.actionType = 18; - outMsg.setTargetType(building.getObjectType().ordinal()); - outMsg.setTargetID(building.getObjectUUID()); - - } else if (BuildingManager.playerCanManage(player, building)) { //TODO allow Friends list. - configWindowState(player, building, outMsg); - outMsg.actionType = 3; - outMsg.setTargetType(building.getObjectType().ordinal()); - outMsg.setTargetID(building.getObjectUUID()); - outMsg.setTargetType3(building.getObjectType().ordinal()); - outMsg.setTargetID3(building.getObjectUUID()); - outMsg.setUnknown54(1); - - } else { - - if (building.getBlueprintUUID() != 0) - switch (building.getBlueprint().getBuildingGroup()) { - case SHRINE: - if (building.getRank() == -1) { - if (!Bounds.collide(player.getLoc(), building)) { - ErrorPopupMsg.sendErrorPopup(player, 64); - return true; - } - - Shrine shrine = Shrine.shrinesByBuildingUUID.get(building.getObjectUUID()); - - if (shrine == null) - return true; - - if (shrine.getFavors() == 0) { - ErrorPopupMsg.sendErrorPopup(player, 166); // There is no more favor in this shrine to loot - return true; - } - - BuildingManager.lootBuilding(player, building); - return true; - } - break; - case WAREHOUSE: - //TODO check - if (building.getRank() == -1) { - if (!Bounds.collide(player.getLoc(), building)) { - ErrorPopupMsg.sendErrorPopup(player, 64); - return true; - } - - Warehouse warehouse = Warehouse.warehouseByBuildingUUID.get(building.getObjectUUID()); - - if (warehouse == null) - return true; - - if (warehouse.isEmpty()) { - ErrorPopupMsg.sendErrorPopup(player, 167); // no more resources. - return true; - } - - BuildingManager.lootBuilding(player, building); - return true; - } - } - - if (building.getRank() == -1) - return true; - - AbstractCharacter owner = building.getOwner(); - - //no owner, send building info - if (owner == null) { - msg.actionType = 4; - - Dispatch dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - } - outMsg.actionType = 4; - outMsg.setTargetType(building.getObjectType().ordinal()); - outMsg.setTargetID(building.getObjectUUID()); - outMsg.setAssetName(building.getName()); - - } - Dispatch dispatch = Dispatch.borrow(player, outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - } - - if (msg.actionType == 13) { - outMsg.actionType = 13; - Dispatch dispatch = Dispatch.borrow(player, outMsg); + public ManageCityAssetMsgHandler() { + super(ManageCityAssetsMsg.class); + } + + public static boolean playerCanManageNotFriends(PlayerCharacter player, Building building) { + + //Player Can only Control Building if player is in Same Guild as Building and is higher rank than IC. + + if (player == null) + return false; + + if (building.getRank() == -1) + return false; + + if (BuildingManager.IsOwner(building, player)) + return true; + + if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false && GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false) + return false; + + //Somehow guild leader check fails above? lets check if Player is true Guild GL. + if (building.getGuild() != null && building.getGuild().isGuildLeader(player.getObjectUUID())) + return true; + + return Guild.sameGuild(building.getGuild(), player.getGuild()); + + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + ManageCityAssetsMsg msg; + PlayerCharacter player; + ManageCityAssetsMsg outMsg; + Building building; + + msg = (ManageCityAssetsMsg) baseMsg; + + player = SessionManager.getPlayerCharacter(origin); + + if (player == null) + return true; + + building = BuildingManager.getBuildingFromCache(msg.getTargetID()); + + if (building == null) { + if (msg.actionType == 14) { + + Zone zone = ZoneManager.findSmallestZone(player.getLoc()); + + if (!zone.isPlayerCity()) { + ErrorPopupMsg.sendErrorMsg(player, "Unable to find city to command."); + return true; + } + + City city = City.GetCityFromCache(zone.getPlayerCityUUID()); + + if (city == null) { + ErrorPopupMsg.sendErrorMsg(player, "Unable to find city to command."); + return true; + } + + if (!city.getGuild().equals(player.getGuild())) { + ErrorPopupMsg.sendErrorMsg(player, "You are not in the correct guild to command this city."); + return true; + } + + if (!GuildStatusController.isInnerCouncil(player.getGuildStatus()) && !GuildStatusController.isGuildLeader(player.getGuildStatus())) { + ErrorPopupMsg.sendErrorMsg(player, "You must be an Inner Council or Guild leader to access city commands."); + return true; + } + ManageCityAssetsMsg mca = new ManageCityAssetsMsg(player, building); + mca.actionType = 15; + Dispatch dispatch = Dispatch.borrow(player, mca); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + } + return true; + } + + outMsg = new ManageCityAssetsMsg(player, building); + + if (player.isSafeMode()) { + outMsg.actionType = 4; + outMsg.setTargetType(building.getObjectType().ordinal()); + outMsg.setTargetID(building.getObjectUUID()); + outMsg.setAssetName(building.getName()); + Dispatch dispatch = Dispatch.borrow(player, outMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + } + + if (msg.actionType == 2 || msg.actionType == 22) { + + if (building.getBlueprint() != null && building.getBlueprint().getBuildingGroup() == engine.Enum.BuildingGroup.BANESTONE) { + + outMsg.actionType = 18; + outMsg.setTargetType(building.getObjectType().ordinal()); + outMsg.setTargetID(building.getObjectUUID()); + + } else if (BuildingManager.playerCanManage(player, building)) { //TODO allow Friends list. + configWindowState(player, building, outMsg); + outMsg.actionType = 3; + outMsg.setTargetType(building.getObjectType().ordinal()); + outMsg.setTargetID(building.getObjectUUID()); + outMsg.setTargetType3(building.getObjectType().ordinal()); + outMsg.setTargetID3(building.getObjectUUID()); + outMsg.setUnknown54(1); + + } else { + + if (building.getBlueprintUUID() != 0) + switch (building.getBlueprint().getBuildingGroup()) { + case SHRINE: + if (building.getRank() == -1) { + if (!Bounds.collide(player.getLoc(), building)) { + ErrorPopupMsg.sendErrorPopup(player, 64); + return true; + } + + Shrine shrine = Shrine.shrinesByBuildingUUID.get(building.getObjectUUID()); + + if (shrine == null) + return true; + + if (shrine.getFavors() == 0) { + ErrorPopupMsg.sendErrorPopup(player, 166); // There is no more favor in this shrine to loot + return true; + } + + BuildingManager.lootBuilding(player, building); + return true; + } + break; + case WAREHOUSE: + //TODO check + if (building.getRank() == -1) { + if (!Bounds.collide(player.getLoc(), building)) { + ErrorPopupMsg.sendErrorPopup(player, 64); + return true; + } + + Warehouse warehouse = Warehouse.warehouseByBuildingUUID.get(building.getObjectUUID()); + + if (warehouse == null) + return true; + + if (warehouse.isEmpty()) { + ErrorPopupMsg.sendErrorPopup(player, 167); // no more resources. + return true; + } + + BuildingManager.lootBuilding(player, building); + return true; + } + } + + if (building.getRank() == -1) + return true; + + AbstractCharacter owner = building.getOwner(); + + //no owner, send building info + if (owner == null) { + msg.actionType = 4; + + Dispatch dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + } + outMsg.actionType = 4; + outMsg.setTargetType(building.getObjectType().ordinal()); + outMsg.setTargetID(building.getObjectUUID()); + outMsg.setAssetName(building.getName()); + + } + Dispatch dispatch = Dispatch.borrow(player, outMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + } + + if (msg.actionType == 13) { + outMsg.actionType = 13; + Dispatch dispatch = Dispatch.borrow(player, outMsg); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); return true; - } + } - - //Rename Building. + //Rename Building. - if (msg.actionType == 5) { + if (msg.actionType == 5) { - //TODO we need to check names before allowing - building.setName(msg.getAssetName()); - configWindowState(player, building, outMsg); + //TODO we need to check names before allowing + building.setName(msg.getAssetName()); + configWindowState(player, building, outMsg); - outMsg.actionType = 3; - outMsg.setTargetType(building.getObjectType().ordinal()); - outMsg.setTargetID(building.getObjectUUID()); - outMsg.setTargetType3(GameObjectType.Building.ordinal()); - outMsg.setTargetID3(building.getObjectUUID()); - outMsg.setAssetName1(building.getName()); - outMsg.setUnknown54(1); + outMsg.actionType = 3; + outMsg.setTargetType(building.getObjectType().ordinal()); + outMsg.setTargetID(building.getObjectUUID()); + outMsg.setTargetType3(GameObjectType.Building.ordinal()); + outMsg.setTargetID3(building.getObjectUUID()); + outMsg.setAssetName1(building.getName()); + outMsg.setUnknown54(1); Dispatch dispatch = Dispatch.borrow(player, outMsg); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - + + return true; + + //TOL, update city name also + //TODO update city and zone in database + //TODO update city map data in game server + } + + if (msg.actionType == 14) { + ManageCityAssetsMsg mca = new ManageCityAssetsMsg(player, building); + mca.actionType = 15; + Dispatch dispatch = Dispatch.borrow(player, mca); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); return true; + } - //TOL, update city name also - //TODO update city and zone in database - //TODO update city map data in game server - } - - if (msg.actionType == 14) { - ManageCityAssetsMsg mca = new ManageCityAssetsMsg(player, building); - mca.actionType = 15; - Dispatch dispatch = Dispatch.borrow(player, mca); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - } - - if (msg.actionType == 20) { - - Zone baneZone = building.getParentZone(); - - if (baneZone == null) - return true; - - City banedCity = City.getCity(baneZone.getPlayerCityUUID()); - - if (banedCity == null) - return true; - - Bane bane = banedCity.getBane(); - - if (bane == null || bane.getLiveDate() != null || player.getGuild() != banedCity.getGuild() || GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false) - return true; - - int baneHour = msg.getBaneHour(); - - if (baneHour < 16 || baneHour > 24) { - PlaceAssetMsg.sendPlaceAssetError(origin, 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - return true; - } - - DateTime baneLive = new DateTime(bane.getPlacementDate()); - baneLive = baneHour == 24 ? baneLive.plusDays(3) : baneLive.plusDays(2); - baneLive = baneHour == 24 ? baneLive.hourOfDay().setCopy(0) : baneLive.hourOfDay().setCopy(baneHour); - baneLive = baneLive.minuteOfHour().setCopy(0); - baneLive = baneLive.secondOfMinute().setCopy(1); - bane.setLiveDate(baneLive); - outMsg.actionType = 18; - - Dispatch dispatch = Dispatch.borrow(player, outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - } - return true; - } - - public void configWindowState(PlayerCharacter player, Building building, ManageCityAssetsMsg manageCityAssetsMsg) { - - // Tests to turn on upgrade button if a building is not - // at it's maximum allowed rank or currently ranking - - - // Owner is obviously allowed to upgrade his own buildings - - if (building.getOwner().equals(player)) { - - // Players cannot destroy or transfer a TOL. - - if (building.getBlueprint() == null){ - manageCityAssetsMsg.buttonDestroy = 0; - manageCityAssetsMsg.buttonTransfer = 0; - manageCityAssetsMsg.buttonAbandon = 0; - manageCityAssetsMsg.buttonUpgrade = 0; - } - else - if (building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.TOL) { - manageCityAssetsMsg.buttonDestroy = 0; - manageCityAssetsMsg.buttonTransfer = 0; - manageCityAssetsMsg.buttonAbandon = 1; - manageCityAssetsMsg.buttonUpgrade = 1; - } - else if (building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.MINE) { - manageCityAssetsMsg.buttonDestroy = 0; - manageCityAssetsMsg.buttonTransfer = 0; - manageCityAssetsMsg.buttonAbandon = 0; - manageCityAssetsMsg.buttonUpgrade = 0; // Cannot upgrade a mine - } - else{ - manageCityAssetsMsg.buttonDestroy = 1; - manageCityAssetsMsg.buttonTransfer = 1; - manageCityAssetsMsg.buttonAbandon = 1; - manageCityAssetsMsg.buttonUpgrade = 1; - } - } - - // Inner Council of the same guild can also upgrade - - if ((player.getGuild().equals(building.getGuild())) && - GuildStatusController.isInnerCouncil(player.getGuildStatus())) - manageCityAssetsMsg.buttonUpgrade = 1; - - // Disable upgrade button if at max rank. - - if (building.getBlueprint() == null) - manageCityAssetsMsg.buttonUpgrade = 0; - else - if (building.getRank() >= building.getBlueprint().getMaxRank()) - manageCityAssetsMsg.buttonUpgrade = 0;; - - // If a building is not protected we can exit here - - if (building.assetIsProtected() == false) - return; - - // Protection is displayed as "UNDER SIEGE" if - // an active bane is invalidating the protection - // contracts of the city. - - if ((building.getCity() != null) && - (building.getCity().protectionEnforced == false)) { - manageCityAssetsMsg.labelProtected = 0; - manageCityAssetsMsg.labelSiege = 1; - manageCityAssetsMsg.labelCeaseFire = 0; - return; - } - - // Building is currently protected by a TOL - - manageCityAssetsMsg.labelProtected = 1; - } + if (msg.actionType == 20) { + + Zone baneZone = building.getParentZone(); + + if (baneZone == null) + return true; + + City banedCity = City.getCity(baneZone.getPlayerCityUUID()); + + if (banedCity == null) + return true; + + Bane bane = banedCity.getBane(); + + if (bane == null || bane.getLiveDate() != null || player.getGuild() != banedCity.getGuild() || GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false) + return true; + + int baneHour = msg.getBaneHour(); + + if (baneHour < 16 || baneHour > 24) { + PlaceAssetMsg.sendPlaceAssetError(origin, 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + return true; + } + + DateTime baneLive = new DateTime(bane.getPlacementDate()); + baneLive = baneHour == 24 ? baneLive.plusDays(3) : baneLive.plusDays(2); + baneLive = baneHour == 24 ? baneLive.hourOfDay().setCopy(0) : baneLive.hourOfDay().setCopy(baneHour); + baneLive = baneLive.minuteOfHour().setCopy(0); + baneLive = baneLive.secondOfMinute().setCopy(1); + bane.setLiveDate(baneLive); + outMsg.actionType = 18; + + Dispatch dispatch = Dispatch.borrow(player, outMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + } + return true; + } + + public void configWindowState(PlayerCharacter player, Building building, ManageCityAssetsMsg manageCityAssetsMsg) { + + // Tests to turn on upgrade button if a building is not + // at it's maximum allowed rank or currently ranking + + + // Owner is obviously allowed to upgrade his own buildings + + if (building.getOwner().equals(player)) { + + // Players cannot destroy or transfer a TOL. + + if (building.getBlueprint() == null) { + manageCityAssetsMsg.buttonDestroy = 0; + manageCityAssetsMsg.buttonTransfer = 0; + manageCityAssetsMsg.buttonAbandon = 0; + manageCityAssetsMsg.buttonUpgrade = 0; + } else if (building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.TOL) { + manageCityAssetsMsg.buttonDestroy = 0; + manageCityAssetsMsg.buttonTransfer = 0; + manageCityAssetsMsg.buttonAbandon = 1; + manageCityAssetsMsg.buttonUpgrade = 1; + } else if (building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.MINE) { + manageCityAssetsMsg.buttonDestroy = 0; + manageCityAssetsMsg.buttonTransfer = 0; + manageCityAssetsMsg.buttonAbandon = 0; + manageCityAssetsMsg.buttonUpgrade = 0; // Cannot upgrade a mine + } else { + manageCityAssetsMsg.buttonDestroy = 1; + manageCityAssetsMsg.buttonTransfer = 1; + manageCityAssetsMsg.buttonAbandon = 1; + manageCityAssetsMsg.buttonUpgrade = 1; + } + } + + // Inner Council of the same guild can also upgrade + + if ((player.getGuild().equals(building.getGuild())) && + GuildStatusController.isInnerCouncil(player.getGuildStatus())) + manageCityAssetsMsg.buttonUpgrade = 1; + + // Disable upgrade button if at max rank. + + if (building.getBlueprint() == null) + manageCityAssetsMsg.buttonUpgrade = 0; + else if (building.getRank() >= building.getBlueprint().getMaxRank()) + manageCityAssetsMsg.buttonUpgrade = 0; + ; + + // If a building is not protected we can exit here + + if (building.assetIsProtected() == false) + return; + + // Protection is displayed as "UNDER SIEGE" if + // an active bane is invalidating the protection + // contracts of the city. + + if ((building.getCity() != null) && + (building.getCity().protectionEnforced == false)) { + manageCityAssetsMsg.labelProtected = 0; + manageCityAssetsMsg.labelSiege = 1; + manageCityAssetsMsg.labelCeaseFire = 0; + return; + } + + // Building is currently protected by a TOL + + manageCityAssetsMsg.labelProtected = 1; + } } diff --git a/src/engine/net/client/handlers/MerchantMsgHandler.java b/src/engine/net/client/handlers/MerchantMsgHandler.java index 9ce314c4..94490a72 100644 --- a/src/engine/net/client/handlers/MerchantMsgHandler.java +++ b/src/engine/net/client/handlers/MerchantMsgHandler.java @@ -26,440 +26,429 @@ import java.util.ArrayList; public class MerchantMsgHandler extends AbstractClientMsgHandler { - public MerchantMsgHandler() { - super(MerchantMsg.class); - } - - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - - // Member variable declaration - - MerchantMsg msg; - PlayerCharacter player; - NPC npc; - int msgType; - Building warehouse; - Dispatch dispatch; - - // Member variable assignment - - player = SessionManager.getPlayerCharacter(origin); - msg = (MerchantMsg) baseMsg; - npc = NPC.getNPC(msg.getNPCID()); - - // Early exit if something goes awry - - if ((player == null) || (npc == null)) - return true; - - // Player must be within talking range - - if (player.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) { - ErrorPopupMsg.sendErrorPopup(player, 14); - return true; - } - - // Process application protocol message - - msgType = msg.getType(); - - switch (msgType) { - case 3: - break; - case 5: - - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - requestSwearAsSubGuild(msg, origin, player, npc); - break; - case 10: - teleportRepledgeScreen(msg, origin, player, false, npc); - break; - case 11: - teleportRepledge(msg, origin, player, false, npc); - break; - case 12: - teleportRepledgeScreen(msg, origin, player, true, npc); - break; - case 13: - teleportRepledge(msg, origin, player, true, npc); - break; - case 14: - if (isHermit(npc)) - requestHermitBlessing(msg, origin, player, npc); - else - requestBoon(msg, origin, player, npc); - break; - case 15: - LeaderboardMessage lbm = new LeaderboardMessage(); - dispatch = Dispatch.borrow(player, lbm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - break; - case 16: - ViewResourcesMessage vrm = new ViewResourcesMessage(player); - warehouse = npc.getBuilding(); - vrm.setGuild(player.getGuild()); - vrm.setWarehouseBuilding(warehouse); - vrm.configure(); - dispatch = Dispatch.borrow(player, vrm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - break; - case 17: - Warehouse.warehouseWithdraw(msg, player, npc, origin); - break; - case 18: - Warehouse.warehouseDeposit(msg, player, npc, origin); - break; - case 19: - Warehouse.warehouseLock(msg, player, npc, origin); - break; - } + public MerchantMsgHandler() { + super(MerchantMsg.class); + } - return true; + private static void requestSwearAsSubGuild(MerchantMsg msg, ClientConnection origin, PlayerCharacter player, NPC npc) { - } + boolean Disabled = true; - private static void requestSwearAsSubGuild(MerchantMsg msg, ClientConnection origin, PlayerCharacter player, NPC npc) { + if (Disabled) { + ErrorPopupMsg.sendErrorMsg(player, "Swearing to Safeholds have been temporary disabled."); //Cannot sub as errant guild. + return; + } - boolean Disabled = true; + if (player.getGuild().isEmptyGuild()) { + ErrorPopupMsg.sendErrorMsg(player, "You do not belong to a guild!"); //Cannot sub as errant guild. + return; + } - if (Disabled){ - ErrorPopupMsg.sendErrorMsg(player, "Swearing to Safeholds have been temporary disabled."); //Cannot sub as errant guild. - return; - } - - if (player.getGuild().isEmptyGuild()){ - ErrorPopupMsg.sendErrorMsg(player, "You do not belong to a guild!"); //Cannot sub as errant guild. - return; - } + if (player.getGuild().getNation() != null && !player.getGuild().getNation().isEmptyGuild()) { + ErrorPopupMsg.sendErrorMsg(player, "You already belong to a nation!"); //Cannot sub as errant guild. + return; + } - if (player.getGuild().getNation() != null && !player.getGuild().getNation().isEmptyGuild()){ - ErrorPopupMsg.sendErrorMsg(player, "You already belong to a nation!"); //Cannot sub as errant guild. - return; - } + if (player.getGuild().getGuildLeaderUUID() != player.getObjectUUID()) { + ErrorPopupMsg.sendErrorMsg(player, "You must be a Guild Leader to Swear your guild as a Sub Guild!"); //Cannot sub as errant guild. + return; + } - if (player.getGuild().getGuildLeaderUUID() != player.getObjectUUID()){ - ErrorPopupMsg.sendErrorMsg(player, "You must be a Guild Leader to Swear your guild as a Sub Guild!"); //Cannot sub as errant guild. - return; - } + if (!GuildStatusController.isGuildLeader(player.getGuildStatus())) { + ErrorPopupMsg.sendErrorMsg(player, "You must be a Guild Leader to Swear your guild as a Sub Guild!"); //Cannot sub as errant guild. + return; + } - if (!GuildStatusController.isGuildLeader(player.getGuildStatus())){ - ErrorPopupMsg.sendErrorMsg(player, "You must be a Guild Leader to Swear your guild as a Sub Guild!"); //Cannot sub as errant guild. - return; - } - - if (!npc.getGuild().isNPCGuild()){ - ErrorPopupMsg.sendErrorMsg(player, "Runemaster does not belong to a safehold!"); //Cannot sub as errant guild. - return; - } + if (!npc.getGuild().isNPCGuild()) { + ErrorPopupMsg.sendErrorMsg(player, "Runemaster does not belong to a safehold!"); //Cannot sub as errant guild. + return; + } - if (npc.getGuild().getRepledgeMin() > player.getLevel()){ - ErrorPopupMsg.sendErrorMsg(player, "You are too low of a level to sub to this guild!"); //Cannot sub as errant guild. - return; - } + if (npc.getGuild().getRepledgeMin() > player.getLevel()) { + ErrorPopupMsg.sendErrorMsg(player, "You are too low of a level to sub to this guild!"); //Cannot sub as errant guild. + return; + } - if (npc.getGuild().getRepledgeMax() < 75){ - ErrorPopupMsg.sendErrorMsg(player, "Runemaster Guild Cannot Swear in your guild!"); //Cannot sub as errant guild. - return; - } + if (npc.getGuild().getRepledgeMax() < 75) { + ErrorPopupMsg.sendErrorMsg(player, "Runemaster Guild Cannot Swear in your guild!"); //Cannot sub as errant guild. + return; + } + if (!DbManager.GuildQueries.UPDATE_PARENT(player.getGuild().getObjectUUID(), npc.getGuild().getObjectUUID())) { + ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occured. Please post details for to ensure transaction integrity"); + return; + } + GuildManager.updateAllGuildBinds(player.getGuild(), npc.getGuild().getOwnedCity()); - if (!DbManager.GuildQueries.UPDATE_PARENT(player.getGuild().getObjectUUID(), npc.getGuild().getObjectUUID())) { - ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occured. Please post details for to ensure transaction integrity"); - return; - } + //update Guild state. + player.getGuild().setNation(npc.getGuild()); + GuildManager.updateAllGuildTags(player.getGuild()); - GuildManager.updateAllGuildBinds(player.getGuild(), npc.getGuild().getOwnedCity()); + //update state twice, errant to petitioner, to sworn. + player.getGuild().upgradeGuildState(false);//to petitioner + player.getGuild().upgradeGuildState(false);//to sworn + } - //update Guild state. - player.getGuild().setNation(npc.getGuild()); - GuildManager.updateAllGuildTags(player.getGuild()); + private static void requestHermitBlessing(MerchantMsg msg, ClientConnection origin, PlayerCharacter player, NPC npc) { - //update state twice, errant to petitioner, to sworn. - player.getGuild().upgradeGuildState(false);//to petitioner - player.getGuild().upgradeGuildState(false);//to sworn + Guild guild; + Realm realm; + City city; + Building tol; + // Validate player can obtain blessing + if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false) { + ErrorPopupMsg.sendErrorPopup(player, 173); // You must be the leader of a guild to receive a blessing + return; + } + guild = player.getGuild(); + city = guild.getOwnedCity(); + if (city == null) { + ErrorPopupMsg.sendErrorPopup(player, 179); // Only landed guilds may claim a territory + return; + } + tol = city.getTOL(); - } + if (tol.getRank() != 7) { + ErrorPopupMsg.sendErrorPopup(player, 181); // Your tree must be rank 7 before claiming a territory + return; + } + realm = RealmMap.getRealmForCity(city); + if (realm.getCanBeClaimed() == false) { + ErrorPopupMsg.sendErrorPopup(player, 180); // This territory cannot be ruled by anyone + return; + } - private static void requestHermitBlessing(MerchantMsg msg, ClientConnection origin, PlayerCharacter player, NPC npc) { + if (realm.isRuled() == true) { + ErrorPopupMsg.sendErrorPopup(player, 178); // This territory is already claimed + return; + } - Guild guild; - Realm realm; - City city; - Building tol; + // Everything should be good, apply boon for this hermit - // Validate player can obtain blessing + PowersManager.applyPower(player, player, player.getLoc(), getPowerforHermit(npc).getToken(), 40, false); - if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false) { - ErrorPopupMsg.sendErrorPopup(player, 173); // You must be the leader of a guild to receive a blessing - return; - } + } - guild = player.getGuild(); - city = guild.getOwnedCity(); + private static void requestBoon(MerchantMsg msg, ClientConnection origin, PlayerCharacter player, NPC npc) { - if (city == null) { - ErrorPopupMsg.sendErrorPopup(player, 179); // Only landed guilds may claim a territory - return; - } - tol = city.getTOL(); + Building shrineBuilding; + Shrine shrine; - if (tol.getRank() != 7) { - ErrorPopupMsg.sendErrorPopup(player, 181); // Your tree must be rank 7 before claiming a territory - return; - } + if (npc.getGuild() != player.getGuild()) + return; - realm = RealmMap.getRealmForCity(city); + shrineBuilding = npc.getBuilding(); - if (realm.getCanBeClaimed() == false) { - ErrorPopupMsg.sendErrorPopup(player, 180); // This territory cannot be ruled by anyone - return; - } + if (shrineBuilding == null) + return; - if (realm.isRuled() == true) { - ErrorPopupMsg.sendErrorPopup(player, 178); // This territory is already claimed - return; - } + if (shrineBuilding.getBlueprint() != null && shrineBuilding.getBlueprint().getBuildingGroup() != engine.Enum.BuildingGroup.SHRINE) + return; - // Everything should be good, apply boon for this hermit + if (shrineBuilding.getRank() == -1) + return; - PowersManager.applyPower(player, player, player.getLoc(), getPowerforHermit(npc).getToken(), 40, false); + shrine = Shrine.shrinesByBuildingUUID.get(shrineBuilding.getObjectUUID()); - } + if (shrine == null) + return; - private static void requestBoon(MerchantMsg msg, ClientConnection origin, PlayerCharacter player, NPC npc) { + if (shrine.getFavors() == 0) { + ErrorPopupMsg.sendErrorPopup(player, 172); + return; + } - Building shrineBuilding; - Shrine shrine; + //already haz boon. - if (npc.getGuild() != player.getGuild()) - return; + if (player.containsEffect(shrine.getShrineType().getPowerToken())) { + ErrorPopupMsg.sendErrorPopup(player, 199); + return; + } - shrineBuilding = npc.getBuilding(); + if (!Shrine.canTakeFavor(player, shrine)) + return; - if (shrineBuilding == null) - return; + if (!shrine.takeFavor(player)) + return; - if (shrineBuilding.getBlueprint() != null && shrineBuilding.getBlueprint().getBuildingGroup() != engine.Enum.BuildingGroup.SHRINE) - return; + PowersBase shrinePower = PowersManager.getPowerByToken(shrine.getShrineType().getPowerToken()); - if (shrineBuilding.getRank() == -1) - return; + if (shrinePower == null) { + ChatManager.chatSystemError(player, "FAILED TO APPLY POWER!"); + return; + } - shrine = Shrine.shrinesByBuildingUUID.get(shrineBuilding.getObjectUUID()); + int rank = shrine.getRank(); + //R8 trees always get atleast rank 2 boons. rank uses index, where 0 is first place, 1 is second, etc... + if (shrineBuilding.getCity() != null && shrineBuilding.getCity().getTOL() != null && shrineBuilding.getCity().getTOL().getRank() == 8) + if (rank != 0) + rank = 1; + int trains = 40 - (rank * 10); + if (trains < 0) + trains = 0; - if (shrine == null) - return; + //System.out.println(trains); + PowersManager.applyPower(player, player, player.getLoc(), shrinePower.getToken(), trains, false); + ChatManager.chatGuildInfo(player.getGuild(), player.getName() + " has recieved a boon costing " + 1 + " point of favor."); + shrineBuilding.addEffectBit(1000000 << 2); + shrineBuilding.updateEffects(); - if (shrine.getFavors() == 0) { - ErrorPopupMsg.sendErrorPopup(player, 172); - return; - } + //remove the effect so players loading shrines dont see the effect go off. + shrineBuilding.removeEffectBit(1000000 << 2); + } - //already haz boon. + private static void teleportRepledgeScreen(MerchantMsg msg, ClientConnection origin, PlayerCharacter pc, boolean isTeleport, NPC npc) { - if (player.containsEffect(shrine.getShrineType().getPowerToken())) { - ErrorPopupMsg.sendErrorPopup(player, 199); - return; - } + Dispatch dispatch; + TeleportRepledgeListMsg trlm; - if (!Shrine.canTakeFavor(player, shrine)) - return; + //verify npc is runemaster - if (!shrine.takeFavor(player)) - return; + Contract contract = npc.getContract(); - PowersBase shrinePower = PowersManager.getPowerByToken(shrine.getShrineType().getPowerToken()); + if (contract == null || !contract.isRuneMaster()) + return; - if (shrinePower == null) { - ChatManager.chatSystemError(player, "FAILED TO APPLY POWER!"); - return; - } + if (!isTeleport) + trlm = new TeleportRepledgeListMsg(pc, false); + else + trlm = new TeleportRepledgeListMsg(pc, true); - int rank = shrine.getRank(); - //R8 trees always get atleast rank 2 boons. rank uses index, where 0 is first place, 1 is second, etc... - if (shrineBuilding.getCity() != null && shrineBuilding.getCity().getTOL() != null && shrineBuilding.getCity().getTOL().getRank() == 8) - if (rank != 0) - rank = 1; - int trains = 40 - (rank * 10); - if (trains < 0) - trains = 0; + trlm.configure(); - //System.out.println(trains); - PowersManager.applyPower(player, player, player.getLoc(), shrinePower.getToken(), trains, false); - ChatManager.chatGuildInfo(player.getGuild(), player.getName() + " has recieved a boon costing " + 1 + " point of favor."); - shrineBuilding.addEffectBit(1000000 << 2); - shrineBuilding.updateEffects(); + dispatch = Dispatch.borrow(pc, trlm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } - //remove the effect so players loading shrines dont see the effect go off. - shrineBuilding.removeEffectBit(1000000 << 2); - } + private static void teleportRepledge(MerchantMsg msg, ClientConnection origin, PlayerCharacter player, boolean isTeleport, NPC npc) { - private static void teleportRepledgeScreen(MerchantMsg msg, ClientConnection origin, PlayerCharacter pc, boolean isTeleport, NPC npc) { + //verify npc is runemaster - Dispatch dispatch; - TeleportRepledgeListMsg trlm; + Contract contract = npc.getContract(); + Dispatch dispatch; - //verify npc is runemaster + if (contract == null || !contract.isRuneMaster()) + return; - Contract contract = npc.getContract(); + //get city to teleport/repledge to and verify valid - if (contract == null || !contract.isRuneMaster()) - return; + ArrayList cities; - if (!isTeleport) - trlm = new TeleportRepledgeListMsg(pc, false); - else - trlm = new TeleportRepledgeListMsg(pc, true); + City targetCity = null; - trlm.configure(); + if (isTeleport) + cities = City.getCitiesToTeleportTo(player); + else + cities = City.getCitiesToRepledgeTo(player); + for (City city : cities) { + if (city.getObjectUUID() == msg.getCityID()) { + targetCity = city; + break; + } + } - dispatch = Dispatch.borrow(pc, trlm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } + if (targetCity == null) + return; - private static void teleportRepledge(MerchantMsg msg, ClientConnection origin, PlayerCharacter player, boolean isTeleport, NPC npc) { + //verify level required to teleport or repledge - //verify npc is runemaster + Guild toGuild = targetCity.getGuild(); - Contract contract = npc.getContract(); - Dispatch dispatch; + if (toGuild != null) + if (isTeleport) { + if (player.getLevel() < toGuild.getTeleportMin() || player.getLevel() > toGuild.getTeleportMax()) + return; + } else if (player.getLevel() < toGuild.getRepledgeMin() || player.getLevel() > toGuild.getRepledgeMax()) + return; - if (contract == null || !contract.isRuneMaster()) - return; + boolean joinedGuild = false; - //get city to teleport/repledge to and verify valid + //if repledge, reguild the player - ArrayList cities; + if (!isTeleport) + joinedGuild = GuildManager.joinGuild(player, targetCity.getGuild(), targetCity.getObjectUUID(), GuildHistoryType.JOIN); - City targetCity = null; + int time; - if (isTeleport) - cities = City.getCitiesToTeleportTo(player); - else - cities = City.getCitiesToRepledgeTo(player); - for (City city : cities) { - if (city.getObjectUUID() == msg.getCityID()) { - targetCity = city; - break; - } - } + if (!isTeleport) //repledge + time = MBServerStatics.REPLEDGE_TIME_IN_SECONDS; + else + time = MBServerStatics.TELEPORT_TIME_IN_SECONDS; - if (targetCity == null) - return; + //resend message + msg.setTeleportTime(time); - //verify level required to teleport or repledge + if ((!isTeleport && joinedGuild) || (isTeleport)) { - Guild toGuild = targetCity.getGuild(); + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } - if (toGuild != null) - if (isTeleport) { - if (player.getLevel() < toGuild.getTeleportMin() || player.getLevel() > toGuild.getTeleportMax()) - return; - } - else if (player.getLevel() < toGuild.getRepledgeMin() || player.getLevel() > toGuild.getRepledgeMax()) - return; + //teleport player to city - boolean joinedGuild = false; + Vector3fImmutable teleportLoc; - //if repledge, reguild the player + if (targetCity.getTOL().getRank() == 8) + teleportLoc = targetCity.getTOL().getStuckLocation(); + else + teleportLoc = Vector3fImmutable.getRandomPointOnCircle(targetCity.getTOL().getLoc(), MBServerStatics.TREE_TELEPORT_RADIUS); - if (!isTeleport) - joinedGuild = GuildManager.joinGuild(player, targetCity.getGuild(), targetCity.getObjectUUID(), GuildHistoryType.JOIN); + if (time > 0) { + //TODO add timer to teleport + TeleportJob tj = new TeleportJob(player, npc, teleportLoc, origin, true); + JobScheduler.getInstance().scheduleJob(tj, time * 1000); + } else if (joinedGuild) { + player.teleport(teleportLoc); + player.setSafeMode(); + } + } - int time; + private static PowersBase getPowerforHermit(NPC npc) { - if (!isTeleport) //repledge - time = MBServerStatics.REPLEDGE_TIME_IN_SECONDS; - else - time = MBServerStatics.TELEPORT_TIME_IN_SECONDS; + int contractID; + PowersBase power; + Contract contract; - //resend message - msg.setTeleportTime(time); - - if ((!isTeleport && joinedGuild) || (isTeleport)) { - - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } - - //teleport player to city - - Vector3fImmutable teleportLoc; - - if (targetCity.getTOL().getRank() == 8) - teleportLoc = targetCity.getTOL().getStuckLocation(); - else - teleportLoc = Vector3fImmutable.getRandomPointOnCircle(targetCity.getTOL().getLoc(), MBServerStatics.TREE_TELEPORT_RADIUS); - - if (time > 0) { - //TODO add timer to teleport - TeleportJob tj = new TeleportJob(player, npc, teleportLoc, origin, true); - JobScheduler.getInstance().scheduleJob(tj, time * 1000); - } - else if (joinedGuild) { - player.teleport(teleportLoc); - player.setSafeMode(); - } - } - - private static PowersBase getPowerforHermit(NPC npc) { - - int contractID; - PowersBase power; - Contract contract; - - contract = npc.getContract(); - contractID = contract.getContractID(); - power = null; - - switch (contractID) { - case 435579: - power = PowersManager.getPowerByIDString("BLS-POWER"); - break; - case 435580: - power = PowersManager.getPowerByIDString("BLS-FORTUNE"); - break; - case 435581: - power = PowersManager.getPowerByIDString("BLS-WISDOM"); - break; - - } - return power; - } - - private static boolean isHermit(NPC npc) { - - int contractID; - boolean retValue = false; - - contractID = npc.getContractID(); - - switch (contractID) { - case 435579: - case 435580: - case 435581: - retValue = true; - break; - default: - break; - } - - return retValue; - } + contract = npc.getContract(); + contractID = contract.getContractID(); + power = null; + + switch (contractID) { + case 435579: + power = PowersManager.getPowerByIDString("BLS-POWER"); + break; + case 435580: + power = PowersManager.getPowerByIDString("BLS-FORTUNE"); + break; + case 435581: + power = PowersManager.getPowerByIDString("BLS-WISDOM"); + break; + + } + return power; + } + + private static boolean isHermit(NPC npc) { + + int contractID; + boolean retValue = false; + + contractID = npc.getContractID(); + + switch (contractID) { + case 435579: + case 435580: + case 435581: + retValue = true; + break; + default: + break; + } + + return retValue; + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + // Member variable declaration + + MerchantMsg msg; + PlayerCharacter player; + NPC npc; + int msgType; + Building warehouse; + Dispatch dispatch; + + // Member variable assignment + + player = SessionManager.getPlayerCharacter(origin); + msg = (MerchantMsg) baseMsg; + npc = NPC.getNPC(msg.getNPCID()); + + // Early exit if something goes awry + + if ((player == null) || (npc == null)) + return true; + + // Player must be within talking range + + if (player.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) { + ErrorPopupMsg.sendErrorPopup(player, 14); + return true; + } + + // Process application protocol message + + msgType = msg.getType(); + + switch (msgType) { + case 3: + break; + case 5: + + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + requestSwearAsSubGuild(msg, origin, player, npc); + break; + case 10: + teleportRepledgeScreen(msg, origin, player, false, npc); + break; + case 11: + teleportRepledge(msg, origin, player, false, npc); + break; + case 12: + teleportRepledgeScreen(msg, origin, player, true, npc); + break; + case 13: + teleportRepledge(msg, origin, player, true, npc); + break; + case 14: + if (isHermit(npc)) + requestHermitBlessing(msg, origin, player, npc); + else + requestBoon(msg, origin, player, npc); + break; + case 15: + LeaderboardMessage lbm = new LeaderboardMessage(); + dispatch = Dispatch.borrow(player, lbm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + break; + case 16: + ViewResourcesMessage vrm = new ViewResourcesMessage(player); + warehouse = npc.getBuilding(); + vrm.setGuild(player.getGuild()); + vrm.setWarehouseBuilding(warehouse); + vrm.configure(); + dispatch = Dispatch.borrow(player, vrm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + break; + case 17: + Warehouse.warehouseWithdraw(msg, player, npc, origin); + break; + case 18: + Warehouse.warehouseDeposit(msg, player, npc, origin); + break; + case 19: + Warehouse.warehouseLock(msg, player, npc, origin); + break; + } + + return true; + + } } \ No newline at end of file diff --git a/src/engine/net/client/handlers/MineWindowChangeHandler.java b/src/engine/net/client/handlers/MineWindowChangeHandler.java index a39f1c7b..5118088c 100644 --- a/src/engine/net/client/handlers/MineWindowChangeHandler.java +++ b/src/engine/net/client/handlers/MineWindowChangeHandler.java @@ -34,88 +34,88 @@ import java.time.LocalDateTime; public class MineWindowChangeHandler extends AbstractClientMsgHandler { - public MineWindowChangeHandler() { - super(ArcMineWindowChangeMsg.class); - } + public MineWindowChangeHandler() { + super(ArcMineWindowChangeMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter(origin); - ArcMineWindowChangeMsg mineWindowChangeMsg = (ArcMineWindowChangeMsg) baseMsg; - int newMineTime; + PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter(origin); + ArcMineWindowChangeMsg mineWindowChangeMsg = (ArcMineWindowChangeMsg) baseMsg; + int newMineTime; - if (playerCharacter == null) - return true; + if (playerCharacter == null) + return true; - Building treeOfLife = BuildingManager.getBuildingFromCache(mineWindowChangeMsg.getBuildingID()); + Building treeOfLife = BuildingManager.getBuildingFromCache(mineWindowChangeMsg.getBuildingID()); - if (treeOfLife == null) - return true; + if (treeOfLife == null) + return true; - if (treeOfLife.getBlueprintUUID() == 0) - return true; + if (treeOfLife.getBlueprintUUID() == 0) + return true; - if (treeOfLife.getBlueprint().getBuildingGroup() != Enum.BuildingGroup.TOL) - return true; + if (treeOfLife.getBlueprint().getBuildingGroup() != Enum.BuildingGroup.TOL) + return true; - Guild mineGuild = treeOfLife.getGuild(); + Guild mineGuild = treeOfLife.getGuild(); - if (mineGuild.isEmptyGuild()) - return true; + if (mineGuild.isEmptyGuild()) + return true; - if (!Guild.sameGuild(mineGuild, playerCharacter.getGuild())) - return true; //must be same guild + if (!Guild.sameGuild(mineGuild, playerCharacter.getGuild())) + return true; //must be same guild - if (GuildStatusController.isInnerCouncil(playerCharacter.getGuildStatus()) == false) // is this only GL? - return true; + if (GuildStatusController.isInnerCouncil(playerCharacter.getGuildStatus()) == false) // is this only GL? + return true; - newMineTime = mineWindowChangeMsg.getTime(); + newMineTime = mineWindowChangeMsg.getTime(); - // Sanity check for possible slider value + // Sanity check for possible slider value - if (newMineTime == 24) - newMineTime = 0; + if (newMineTime == 24) + newMineTime = 0; - // Enforce time restriction between WOO edits + // Enforce time restriction between WOO edits - if (mineGuild.wooWasModified) { - ErrorPopupMsg.sendErrorMsg(playerCharacter, "You can only modify your WOO once per day."); - return true; - } + if (mineGuild.wooWasModified) { + ErrorPopupMsg.sendErrorMsg(playerCharacter, "You can only modify your WOO once per day."); + return true; + } - //hodge podge sanity check to make sure they don't set it before early window and is not set at late window. + //hodge podge sanity check to make sure they don't set it before early window and is not set at late window. - if (newMineTime < MBServerStatics.MINE_EARLY_WINDOW && - newMineTime != MBServerStatics.MINE_LATE_WINDOW) { - ErrorPopupMsg.sendErrorMsg(playerCharacter, "Mine time is outside the NA Woo window."); - return true; - } + if (newMineTime < MBServerStatics.MINE_EARLY_WINDOW && + newMineTime != MBServerStatics.MINE_LATE_WINDOW) { + ErrorPopupMsg.sendErrorMsg(playerCharacter, "Mine time is outside the NA Woo window."); + return true; + } - // Cannot set a time to a window that has closed if mines are currently open. + // Cannot set a time to a window that has closed if mines are currently open. - if (LocalDateTime.now().getHour() >= MBServerStatics.MINE_EARLY_WINDOW && - LocalDateTime.now().getHour() != MBServerStatics.MINE_LATE_WINDOW) { + if (LocalDateTime.now().getHour() >= MBServerStatics.MINE_EARLY_WINDOW && + LocalDateTime.now().getHour() != MBServerStatics.MINE_LATE_WINDOW) { - if (newMineTime <= LocalDateTime.now().getHour()) - ErrorPopupMsg.sendErrorMsg(playerCharacter, "Cannot set mines to a previous window."); - return true; - } + if (newMineTime <= LocalDateTime.now().getHour()) + ErrorPopupMsg.sendErrorMsg(playerCharacter, "Cannot set mines to a previous window."); + return true; + } - // Update guild mine time + // Update guild mine time - if (!DbManager.GuildQueries.UPDATE_MINETIME(mineGuild.getObjectUUID(), newMineTime)) { - Logger.error("MineWindowChange", "Failed to update mine time for guild " + mineGuild.getObjectUUID()); - ChatManager.chatGuildError(playerCharacter, "Failed to update the mine time"); - return true; - } + if (!DbManager.GuildQueries.UPDATE_MINETIME(mineGuild.getObjectUUID(), newMineTime)) { + Logger.error("MineWindowChange", "Failed to update mine time for guild " + mineGuild.getObjectUUID()); + ChatManager.chatGuildError(playerCharacter, "Failed to update the mine time"); + return true; + } - mineGuild.setMineTime(newMineTime); - mineGuild.wooWasModified = true; + mineGuild.setMineTime(newMineTime); + mineGuild.wooWasModified = true; - ChatManager.chatGuildInfo(playerCharacter, "Mine time updated."); - - return true; - } + ChatManager.chatGuildInfo(playerCharacter, "Mine time updated."); + + return true; + } } \ No newline at end of file diff --git a/src/engine/net/client/handlers/MinionTrainingMsgHandler.java b/src/engine/net/client/handlers/MinionTrainingMsgHandler.java index 77c939b4..e2a431df 100644 --- a/src/engine/net/client/handlers/MinionTrainingMsgHandler.java +++ b/src/engine/net/client/handlers/MinionTrainingMsgHandler.java @@ -25,296 +25,295 @@ import java.util.HashMap; public class MinionTrainingMsgHandler extends AbstractClientMsgHandler { - public static HashMap> _minionsByCaptain = null; + public static HashMap> _minionsByCaptain = null; - public MinionTrainingMsgHandler() { - super(MinionTrainingMessage.class); - } + public MinionTrainingMsgHandler() { + super(MinionTrainingMessage.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - MinionTrainingMessage minionMsg = (MinionTrainingMessage) baseMsg; + MinionTrainingMessage minionMsg = (MinionTrainingMessage) baseMsg; - PlayerCharacter player = SessionManager.getPlayerCharacter(origin); + PlayerCharacter player = SessionManager.getPlayerCharacter(origin); - if (player == null) - return true; + if (player == null) + return true; - if (minionMsg.getNpcType() == Enum.GameObjectType.NPC.ordinal()){ + if (minionMsg.getNpcType() == Enum.GameObjectType.NPC.ordinal()) { - NPC npc = NPC.getFromCache(minionMsg.getNpcID()); + NPC npc = NPC.getFromCache(minionMsg.getNpcID()); - if (npc == null) - return true; + if (npc == null) + return true; - Building b = BuildingManager.getBuildingFromCache(minionMsg.getBuildingID()); + Building b = BuildingManager.getBuildingFromCache(minionMsg.getBuildingID()); - if (b == null) - return true; + if (b == null) + return true; - //clear minion + //clear minion - if (npc.minionLock.writeLock().tryLock()) { - try { - if (minionMsg.getType() == 2) { + if (npc.minionLock.writeLock().tryLock()) { + try { + if (minionMsg.getType() == 2) { - Mob toRemove = Mob.getFromCache(minionMsg.getUUID()); + Mob toRemove = Mob.getFromCache(minionMsg.getUUID()); - if (!npc.getSiegeMinionMap().containsKey(toRemove)) - return true; + if (!npc.getSiegeMinionMap().containsKey(toRemove)) + return true; npc.getSiegeMinionMap().remove(toRemove); - //toRemove.disableIntelligence(); - WorldGrid.RemoveWorldObject(toRemove); - - if (toRemove.getParentZone() != null) - toRemove.getParentZone().zoneMobSet.remove(toRemove); - - DbManager.removeFromCache(toRemove); - PlayerCharacter petOwner = toRemove.getOwner(); - - if (petOwner != null) { - petOwner.setPet(null); - toRemove.setOwner(null); - PetMsg petMsg = new PetMsg(5, null); - Dispatch dispatch = Dispatch.borrow(petOwner, petMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } - - // we Found the move to remove, lets break the for loop so it doesnt look for more. - - ManageCityAssetsMsg mca1 = new ManageCityAssetsMsg(player, b); - mca1.actionType = 3; - mca1.setTargetType(b.getObjectType().ordinal()); - mca1.setTargetID(b.getObjectUUID()); - - mca1.setTargetType3(npc.getObjectType().ordinal()); - mca1.setTargetID3(npc.getObjectUUID()); - mca1.setAssetName1(b.getName()); - mca1.setUnknown54(1); - - Dispatch dispatch = Dispatch.borrow(player, mca1); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - ManageNPCMsg mnm = new ManageNPCMsg(npc); - dispatch = Dispatch.borrow(player, mnm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - //Add Minion - } - else { - Zone zone = npc.getParentZone(); - - if (zone == null) - return true; - - int maxSlots = 3; - - if (npc.getContractID() == 842) - maxSlots = 1; - - if (npc.getSiegeMinionMap().size() == maxSlots) - return true; - - int mobBase; - - switch (minionMsg.getMinion()){ - case 9: - mobBase = 13171; - break; - case 2: - mobBase = 13758; - break; - case 3: - mobBase = 13757; - break; - case 4: - mobBase = 2111; - break; - case 5: - mobBase = 12402; - break; - case 6: - mobBase = 2113; - break; - default: - mobBase = minionMsg.getMinion(); - } - - if (mobBase == 0) - return true; - - Mob toCreate = Mob.createSiegeMob(npc,mobBase, npc.getGuild(), zone, b.getLoc(), (short) 1); - - if (toCreate == null) - return true; - - // toCreate.despawn(); - if (toCreate != null) { - toCreate.setSpawnTime(60 * 15); - Building building = BuildingManager.getBuilding(((MinionTrainingMessage) baseMsg).getBuildingID()); - int slot = ((NPC)toCreate.npcOwner).getSiegeMinionMap().get(toCreate); - Vector3fImmutable slotLocation; - toCreate.building = building; - toCreate.parentZone = zone; - BuildingLocation buildingLocation = BuildingManager._slotLocations.get(building.meshUUID).get(slot); - slotLocation = building.getLoc().add(buildingLocation.getLocation()); - toCreate.setBindLoc(slotLocation); - zone.zoneMobSet.add(toCreate); - MovementManager.translocate(toCreate,toCreate.getBindLoc(),toCreate.npcOwner.region); + //toRemove.disableIntelligence(); + WorldGrid.RemoveWorldObject(toRemove); + + if (toRemove.getParentZone() != null) + toRemove.getParentZone().zoneMobSet.remove(toRemove); + + DbManager.removeFromCache(toRemove); + PlayerCharacter petOwner = toRemove.getOwner(); + + if (petOwner != null) { + petOwner.setPet(null); + toRemove.setOwner(null); + PetMsg petMsg = new PetMsg(5, null); + Dispatch dispatch = Dispatch.borrow(petOwner, petMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + } + + // we Found the move to remove, lets break the for loop so it doesnt look for more. + + ManageCityAssetsMsg mca1 = new ManageCityAssetsMsg(player, b); + mca1.actionType = 3; + mca1.setTargetType(b.getObjectType().ordinal()); + mca1.setTargetID(b.getObjectUUID()); + + mca1.setTargetType3(npc.getObjectType().ordinal()); + mca1.setTargetID3(npc.getObjectUUID()); + mca1.setAssetName1(b.getName()); + mca1.setUnknown54(1); + + Dispatch dispatch = Dispatch.borrow(player, mca1); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + ManageNPCMsg mnm = new ManageNPCMsg(npc); + dispatch = Dispatch.borrow(player, mnm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + //Add Minion + } else { + Zone zone = npc.getParentZone(); + + if (zone == null) + return true; + + int maxSlots = 3; + + if (npc.getContractID() == 842) + maxSlots = 1; + + if (npc.getSiegeMinionMap().size() == maxSlots) + return true; + + int mobBase; + + switch (minionMsg.getMinion()) { + case 9: + mobBase = 13171; + break; + case 2: + mobBase = 13758; + break; + case 3: + mobBase = 13757; + break; + case 4: + mobBase = 2111; + break; + case 5: + mobBase = 12402; + break; + case 6: + mobBase = 2113; + break; + default: + mobBase = minionMsg.getMinion(); + } + + if (mobBase == 0) + return true; + + Mob toCreate = Mob.createSiegeMob(npc, mobBase, npc.getGuild(), zone, b.getLoc(), (short) 1); + + if (toCreate == null) + return true; + + // toCreate.despawn(); + if (toCreate != null) { + toCreate.setSpawnTime(60 * 15); + Building building = BuildingManager.getBuilding(((MinionTrainingMessage) baseMsg).getBuildingID()); + int slot = ((NPC) toCreate.npcOwner).getSiegeMinionMap().get(toCreate); + Vector3fImmutable slotLocation; + toCreate.building = building; + toCreate.parentZone = zone; + BuildingLocation buildingLocation = BuildingManager._slotLocations.get(building.meshUUID).get(slot); + slotLocation = building.getLoc().add(buildingLocation.getLocation()); + toCreate.setBindLoc(slotLocation); + zone.zoneMobSet.add(toCreate); + MovementManager.translocate(toCreate, toCreate.getBindLoc(), toCreate.npcOwner.region); } - } + } - ManageNPCMsg mnm = new ManageNPCMsg(npc); - mnm.setMessageType(1); - Dispatch dispatch = Dispatch.borrow(player, mnm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + ManageNPCMsg mnm = new ManageNPCMsg(npc); + mnm.setMessageType(1); + Dispatch dispatch = Dispatch.borrow(player, mnm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } finally { - npc.minionLock.writeLock().unlock(); - } - } + } finally { + npc.minionLock.writeLock().unlock(); + } + } - }else if (minionMsg.getNpcType() == Enum.GameObjectType.Mob.ordinal()){ + } else if (minionMsg.getNpcType() == Enum.GameObjectType.Mob.ordinal()) { - Mob npc = Mob.getFromCache(minionMsg.getNpcID()); + Mob npc = Mob.getFromCache(minionMsg.getNpcID()); - if (npc == null) - return true; + if (npc == null) + return true; - Building b = BuildingManager.getBuildingFromCache(minionMsg.getBuildingID()); + Building b = BuildingManager.getBuildingFromCache(minionMsg.getBuildingID()); - if (b == null) - return true; + if (b == null) + return true; - //clear minion + //clear minion - if (npc.minionLock.writeLock().tryLock()) { - try { - if (minionMsg.getType() == 2) { + if (npc.minionLock.writeLock().tryLock()) { + try { + if (minionMsg.getType() == 2) { - Mob toRemove = Mob.getFromCache(minionMsg.getUUID()); - if (!npc.getSiegeMinionMap().containsKey(toRemove)) - return true; + Mob toRemove = Mob.getFromCache(minionMsg.getUUID()); + if (!npc.getSiegeMinionMap().containsKey(toRemove)) + return true; - if (!DbManager.MobQueries.REMOVE_FROM_GUARDS(npc.getObjectUUID(), toRemove.getMobBaseID(), npc.getSiegeMinionMap().get(toRemove))) - return true; + if (!DbManager.MobQueries.REMOVE_FROM_GUARDS(npc.getObjectUUID(), toRemove.getMobBaseID(), npc.getSiegeMinionMap().get(toRemove))) + return true; npc.getSiegeMinionMap().remove(toRemove); - //toRemove.disableIntelligence(); - WorldGrid.RemoveWorldObject(toRemove); - - if (toRemove.getParentZone() != null) - toRemove.getParentZone().zoneMobSet.remove(toRemove); - - DbManager.removeFromCache(toRemove); - PlayerCharacter petOwner = toRemove.getOwner(); - - if (petOwner != null) { - petOwner.setPet(null); - toRemove.setOwner(null); - PetMsg petMsg = new PetMsg(5, null); - Dispatch dispatch = Dispatch.borrow(petOwner, petMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } - - // we Found the move to remove, lets break the for loop so it doesnt look for more. - - ManageCityAssetsMsg mca1 = new ManageCityAssetsMsg(player, b); - mca1.actionType = 3; - mca1.setTargetType(b.getObjectType().ordinal()); - mca1.setTargetID(b.getObjectUUID()); - - mca1.setTargetType3(npc.getObjectType().ordinal()); - mca1.setTargetID3(npc.getObjectUUID()); - mca1.setAssetName1(b.getName()); - mca1.setUnknown54(1); - - Dispatch dispatch = Dispatch.borrow(player, mca1); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);; - - ManageNPCMsg mnm = new ManageNPCMsg(npc); - dispatch = Dispatch.borrow(player, mnm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - //Add Minion - } - else { - Zone zone = npc.getParentZone(); - - if (zone == null) - return true; - - int maxSlots = 5; - - if (npc.getContract().getContractID() == 842)//artillery captain - maxSlots = 1; - if(npc.getContract().getContractID() == 910)//guard dogs - maxSlots = 0; - switch (npc.getRank()){ - case 1: - case 2: - maxSlots = 1; - break; - case 3: - maxSlots = 2; - break; - case 4: - case 5: - maxSlots = 3; - break; - case 6: - maxSlots = 4; - break; - case 7: - maxSlots = 5; - break; - } - - if (npc.getSiegeMinionMap().size() == maxSlots) - return true; - - int mobBase = npc.getMobBaseID(); - - if (mobBase == 0) - return true; - - String pirateName = NPCManager.getPirateName(mobBase); - - if (!DbManager.MobQueries.ADD_TO_GUARDS(npc.getObjectUUID(), mobBase, pirateName, npc.getSiegeMinionMap().size() + 1)) - return true; - - Mob toCreate = Mob.createGuardMob(npc, npc.getGuild(), zone, b.getLoc(), npc.getLevel(),pirateName); - - if (toCreate == null) - return true; - - // toCreate.despawn(); - if (toCreate != null) { - toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + MBServerStatics.FIFTEEN_MINUTES); - toCreate.setDeathTime(System.currentTimeMillis()); - toCreate.parentZone.zoneMobSet.add(toCreate); + //toRemove.disableIntelligence(); + WorldGrid.RemoveWorldObject(toRemove); + + if (toRemove.getParentZone() != null) + toRemove.getParentZone().zoneMobSet.remove(toRemove); + + DbManager.removeFromCache(toRemove); + PlayerCharacter petOwner = toRemove.getOwner(); + + if (petOwner != null) { + petOwner.setPet(null); + toRemove.setOwner(null); + PetMsg petMsg = new PetMsg(5, null); + Dispatch dispatch = Dispatch.borrow(petOwner, petMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); } - } - - ManageNPCMsg mnm = new ManageNPCMsg(npc); - mnm.setMessageType(1); - Dispatch dispatch = Dispatch.borrow(player, mnm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - }catch (Exception e){ - Logger.error(e); - }finally { - - npc.minionLock.writeLock().unlock(); - } - } - - } - return true; - } + + // we Found the move to remove, lets break the for loop so it doesnt look for more. + + ManageCityAssetsMsg mca1 = new ManageCityAssetsMsg(player, b); + mca1.actionType = 3; + mca1.setTargetType(b.getObjectType().ordinal()); + mca1.setTargetID(b.getObjectUUID()); + + mca1.setTargetType3(npc.getObjectType().ordinal()); + mca1.setTargetID3(npc.getObjectUUID()); + mca1.setAssetName1(b.getName()); + mca1.setUnknown54(1); + + Dispatch dispatch = Dispatch.borrow(player, mca1); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + ; + + ManageNPCMsg mnm = new ManageNPCMsg(npc); + dispatch = Dispatch.borrow(player, mnm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + //Add Minion + } else { + Zone zone = npc.getParentZone(); + + if (zone == null) + return true; + + int maxSlots = 5; + + if (npc.getContract().getContractID() == 842)//artillery captain + maxSlots = 1; + if (npc.getContract().getContractID() == 910)//guard dogs + maxSlots = 0; + switch (npc.getRank()) { + case 1: + case 2: + maxSlots = 1; + break; + case 3: + maxSlots = 2; + break; + case 4: + case 5: + maxSlots = 3; + break; + case 6: + maxSlots = 4; + break; + case 7: + maxSlots = 5; + break; + } + + if (npc.getSiegeMinionMap().size() == maxSlots) + return true; + + int mobBase = npc.getMobBaseID(); + + if (mobBase == 0) + return true; + + String pirateName = NPCManager.getPirateName(mobBase); + + if (!DbManager.MobQueries.ADD_TO_GUARDS(npc.getObjectUUID(), mobBase, pirateName, npc.getSiegeMinionMap().size() + 1)) + return true; + + Mob toCreate = Mob.createGuardMob(npc, npc.getGuild(), zone, b.getLoc(), npc.getLevel(), pirateName); + + if (toCreate == null) + return true; + + // toCreate.despawn(); + if (toCreate != null) { + toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + MBServerStatics.FIFTEEN_MINUTES); + toCreate.setDeathTime(System.currentTimeMillis()); + toCreate.parentZone.zoneMobSet.add(toCreate); + } + } + + ManageNPCMsg mnm = new ManageNPCMsg(npc); + mnm.setMessageType(1); + Dispatch dispatch = Dispatch.borrow(player, mnm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + } catch (Exception e) { + Logger.error(e); + } finally { + + npc.minionLock.writeLock().unlock(); + } + } + + } + return true; + } } \ No newline at end of file diff --git a/src/engine/net/client/handlers/MoveToPointHandler.java b/src/engine/net/client/handlers/MoveToPointHandler.java index f699b7b0..3c82d07b 100644 --- a/src/engine/net/client/handlers/MoveToPointHandler.java +++ b/src/engine/net/client/handlers/MoveToPointHandler.java @@ -24,7 +24,7 @@ public class MoveToPointHandler extends AbstractClientMsgHandler { @Override protected boolean _handleNetMsg(ClientNetMsg baseMsg, - ClientConnection origin) throws MsgSendException { + ClientConnection origin) throws MsgSendException { MoveToPointMsg msg = (MoveToPointMsg) baseMsg; PlayerCharacter pc = (origin != null) ? (origin.getPlayerCharacter()) : null; diff --git a/src/engine/net/client/handlers/ObjectActionMsgHandler.java b/src/engine/net/client/handlers/ObjectActionMsgHandler.java index 10de0018..0137b24d 100644 --- a/src/engine/net/client/handlers/ObjectActionMsgHandler.java +++ b/src/engine/net/client/handlers/ObjectActionMsgHandler.java @@ -29,541 +29,539 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; */ public class ObjectActionMsgHandler extends AbstractClientMsgHandler { - // Reentrant lock for dropping banes + // Reentrant lock for dropping banes - private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); - - public ObjectActionMsgHandler() { - super(ObjectActionMsg.class); - } - - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - - // Member variable declaration - ObjectActionMsg msg; - PlayerCharacter player; - CharacterItemManager itemMan; - ArrayList comps; - Dispatch dispatch; - boolean waterbucketBypass = false; - - // Member variable assignment - msg = (ObjectActionMsg) baseMsg; - player = SessionManager.getPlayerCharacter(origin); - - if (player == null) { - return true; - } - - itemMan = player.getCharItemManager(); - - if (itemMan == null) { - return true; - } - - comps = msg.getTargetCompID(); - - if (comps.isEmpty()) { - return true; - } - - long comp = comps.get(0); - - if (((int) comp) != 0) { - Item item = Item.getFromCache((int) comp); - - if (item == null) { - return true; - } - - //dupe check - if (!item.validForInventory(origin, player, itemMan)) { - return true; - } - - ItemBase ib = item.getItemBase(); - - if (ib == null) { - return true; - } - - if (itemMan.doesCharOwnThisItem(item.getObjectUUID())) { - - if (ib.isConsumable() || ib.getType() == ItemType.FARMABLE) { - - int uuid = ib.getUUID(); - int type = ib.getType().getValue(); - - switch (type) { - case 27: //Mithril repair - break; - case 10: //charters - //don't think they're handled here? - break; - case 19: //buildings - //Call add building screen here, ib.getUseID() get's building ID - - //if inside player city, center loc on tol. otherwise center on player. - Vector3fImmutable loc = player.getLoc(); - Zone zone = ZoneManager.findSmallestZone(player.getLoc()); - - if (zone != null) { - if (zone.isPlayerCity()) { - loc = zone.getLoc(); - } - } - - PlaceAssetMsg pam = new PlaceAssetMsg(); - pam.setActionType(2); - pam.setContractID(item.getObjectUUID()); - pam.setX(loc.getX() + 64); //offset grid from tol - pam.setY(loc.getY()); - pam.setZ(loc.getZ() + 64); //offset grid from tol - pam.addPlacementInfo(ib.getUseID()); - - dispatch = Dispatch.borrow(player, pam); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - //itemMan.consume(item); //temporary fix for dupe.. TODO Make Item Unusable after This message is sent. - break; - case 25: //furniture - //Call add furniture screen here. ib.getUseID() get's furniture ID - break; - case 33: - long shrineCompID = comps.get(1); - Building shrineBuilding = BuildingManager.getBuilding((int)shrineCompID); - if (shrineBuilding == null) { - return true; - } - if (shrineBuilding.getBlueprint() != null && shrineBuilding.getBlueprint().getBuildingGroup() != engine.Enum.BuildingGroup.SHRINE) { - return true; - } - - if (shrineBuilding.getRank() == -1) { - return true; - } - Shrine shrine = Shrine.shrinesByBuildingUUID.get(shrineBuilding.getObjectUUID()); - - if (shrine == null) { - return true; - } - - if (shrine.addFavor(player, item)) { - shrineBuilding.addEffectBit(1000000 << 2); - shrineBuilding.updateEffects(); - shrineBuilding.removeEffectBit(1000000 << 2); - } - break; - - case 35: - int charterType = 0; - switch (uuid) { - case 910020: - charterType = 762228431; - break; - case 910021: - charterType = -15978914; - break; - case 910022: - charterType = -600065291; - break; - } - if (claimRealm(player, charterType) == true) { - itemMan.consume(item); - } - break; - case 7: //rod of command - long compID = comps.get(1); - - int objectType = AbstractWorldObject.extractTypeID(compID).ordinal(); - Mob toCommand; - if (objectType == engine.Enum.GameObjectType.Mob.ordinal()) { - toCommand = Mob.getFromCache((int)compID); - } //Only Command Mob Types. - else { - return true; - } - - if (toCommand == null) { - return true; - } - - if (!toCommand.isSiege()) - return true; - - if (player.commandSiegeMinion(toCommand)) { - itemMan.consume(item); - } - break; - //ANNIVERSERY GIFT - case 31: - - - if (ib.getUUID() == 971012){ - int random = ThreadLocalRandom.current().nextInt(ItemBase.AnniverseryGifts.size()); - int annyID = ItemBase.AnniverseryGifts.get(random); - - ItemBase annyIB = ItemBase.getItemBase(annyID); - if (annyIB != null){ - Item gift = MobLoot.createItemForPlayer(player, annyIB); - if (gift != null){ - itemMan.addItemToInventory(gift); - itemMan.consume(item); - } - } - break; - } - - LootTable.CreateGamblerItem(item, player); - - - break; - - case 30: //water bucket - case 8: //potions, tears of saedron - - case 5: //runes, petition, warrant, scrolls - if (uuid > 3000 && uuid < 3050) { //Discipline Runes - if (ApplyRuneMsg.applyRune(uuid, origin, player)) { - itemMan.consume(item); - } - break; - } else if (uuid > 249999 && uuid < 250123) { //stat and mastery runes - if (ApplyRuneMsg.applyRune(uuid, origin, player)) { - itemMan.consume(item); - } - break; - } else if (uuid > 250114 && uuid < 250123) { //mastery runes - if (ApplyRuneMsg.applyRune(uuid, origin, player)) { - itemMan.consume(item); - } - break; - } else if (uuid > 252122 && uuid < 252128) { //mastery runes - if (ApplyRuneMsg.applyRune(uuid, origin, player)) { - itemMan.consume(item); - } - break; - } else if (uuid > 680069 && uuid < 680074) //Handle Charter, Deed, Petition, Warrant here - { - break; - } else if (uuid > 910010 && uuid < 910019) { - - int rank = uuid - 910010; - - if (rank < 1 || rank > 8) { - ChatManager.chatSystemError(player, "Invalid Rank for bane scroll!"); - return true; - } - // Only one banestone at a time - lock.writeLock().lock(); - - try { - if (Bane.summonBanestone(player, origin, rank) == true) - itemMan.consume(item); - } finally { - lock.writeLock().unlock(); - } - break; - } else if (uuid == 910010) { //tears of saedron - if (comps.size() > 1) { - removeRune(player, origin, comps.get(1).intValue()); - } - break; - } - - else if (item.getChargesRemaining() > 0) { - ArrayList tarList = msg.getTargetCompID(); - AbstractWorldObject target = player; - if (tarList.size() > 1) { - long tarID = tarList.get(1); - if (tarID != 0) { - AbstractGameObject tarAgo = AbstractGameObject.getFromTypeAndID(tarID); - if (tarAgo != null && tarAgo instanceof AbstractWorldObject) { - target = (AbstractWorldObject) tarAgo; - } - } - } - - // Bypass for waterbuckets - - // test character targeted - - if (ib.getUUID() == 910005) { - - // test for valid target type - if (target.getObjectType() == Enum.GameObjectType.PlayerCharacter) - waterbucketBypass = true; - else { - // test distance to structure - Building targetBuilding = (Building) target; - Bounds testBounds = Bounds.borrow(); - testBounds.setBounds(player.getLoc(), 25); - - if (Bounds.collide(targetBuilding.getBounds(), testBounds, .1f) == false) { - ChatManager.chatSystemError(player, "Not in range of structura for to heal!"); - return true; - } - } - - // Send piss bucket animation - - VisualUpdateMessage vum = new VisualUpdateMessage(player, 16323); - vum.configure(); - DispatchMessage.sendToAllInRange(player, vum); - } - - if (waterbucketBypass == false) - PowersManager.applyPower(player, target, Vector3fImmutable.ZERO, ib.getUseID(), ib.getUseAmount(), true); - - itemMan.consume(item); - } else //just remove the item at this point - itemMan.consume(item); - - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - player.cancelOnSpell(); - break; - default: //shouldn't be here, consume item - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - // itemMan.consume(item); - } - } - } else { - // TODO log item does not belong to player - // System.out.println("Item does not belong to player"); - // Cleanup duped item here - } - } - - return true; - } - - private static boolean claimRealm(PlayerCharacter player, int charterUUID) { - - Guild guild; - Realm realm; - City city; - Building tol; - float hPMod; - Warehouse warehouse; - boolean hasResources = true; - int resourceValue; - - if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false) { - ErrorPopupMsg.sendErrorPopup(player, 176); // Only guild leaders can claim a territory - return false; - } - - guild = player.getGuild(); - city = guild.getOwnedCity(); - - if (city == null) { - ErrorPopupMsg.sendErrorPopup(player, 179); // Only landed guilds may claim a territory - return false; - } - - if (city.isLocationOnCityGrid(player.getLoc()) == false) { - ErrorPopupMsg.sendErrorPopup(player, 186); // Your tree is not inside a territory! - return false; - } - - tol = city.getTOL(); - - if (tol.getRank() != 7) { - ErrorPopupMsg.sendErrorPopup(player, 181); // Your tree must be rank 7 before claiming a territory - return false; - } - - realm = RealmMap.getRealmForCity(city); - - if (realm.getCanBeClaimed() == false) { - ErrorPopupMsg.sendErrorPopup(player, 180); // This territory cannot be ruled by anyone - return false; - } - - if (realm.isRuled() == true) { - ErrorPopupMsg.sendErrorPopup(player, 178); // This territory is already claimed - return false; - } - - if (!Realm.HasAllBlessings(player)) { - ErrorPopupMsg.sendErrorPopup(player, 185); // You must seek the blessing of the three sages before you can rule - return false; - } - - // Must have the required resources in warehouse to claim realm - - warehouse = city.getWarehouse(); - - if (warehouse == null) { - ErrorPopupMsg.sendErrorPopup(player, 188); // You must have a warehouse to become a capital - return false; - } - - resourceValue = warehouse.getResources().get(Warehouse.goldIB); + private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); - if (resourceValue < 5000000) - hasResources = false; - - resourceValue = warehouse.getResources().get(Warehouse.stoneIB); - - if (resourceValue < 8000) - hasResources = false; + public ObjectActionMsgHandler() { + super(ObjectActionMsg.class); + } - resourceValue = warehouse.getResources().get(Warehouse.lumberIB); + private static boolean claimRealm(PlayerCharacter player, int charterUUID) { - if (resourceValue < 8000) - hasResources = false; + Guild guild; + Realm realm; + City city; + Building tol; + float hPMod; + Warehouse warehouse; + boolean hasResources = true; + int resourceValue; - resourceValue = warehouse.getResources().get(Warehouse.galvorIB); + if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false) { + ErrorPopupMsg.sendErrorPopup(player, 176); // Only guild leaders can claim a territory + return false; + } - if (resourceValue < 15) - hasResources = false; + guild = player.getGuild(); + city = guild.getOwnedCity(); - resourceValue = warehouse.getResources().get(Warehouse.wormwoodIB); + if (city == null) { + ErrorPopupMsg.sendErrorPopup(player, 179); // Only landed guilds may claim a territory + return false; + } - if (resourceValue < 15) - hasResources = false; + if (city.isLocationOnCityGrid(player.getLoc()) == false) { + ErrorPopupMsg.sendErrorPopup(player, 186); // Your tree is not inside a territory! + return false; + } - if (hasResources == false) { - ErrorPopupMsg.sendErrorPopup(player, 184); // Insufficient gold or resources to upgrade to capital - return false; - } + tol = city.getTOL(); - // Remove resources from warehouse before claiming realm + if (tol.getRank() != 7) { + ErrorPopupMsg.sendErrorPopup(player, 181); // Your tree must be rank 7 before claiming a territory + return false; + } - resourceValue = warehouse.getResources().get(Warehouse.goldIB); + realm = RealmMap.getRealmForCity(city); - if (DbManager.WarehouseQueries.updateGold(warehouse, resourceValue - 5000000) == true) { - warehouse.getResources().put(Warehouse.goldIB, resourceValue - 5000000); - warehouse.AddTransactionToWarehouse(engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.GOLD, 5000000); - } else { - Logger.error("gold update failed for warehouse of UUID:" + warehouse.getObjectUUID()); - return false; - } + if (realm.getCanBeClaimed() == false) { + ErrorPopupMsg.sendErrorPopup(player, 180); // This territory cannot be ruled by anyone + return false; + } - resourceValue = warehouse.getResources().get(Warehouse.stoneIB); + if (realm.isRuled() == true) { + ErrorPopupMsg.sendErrorPopup(player, 178); // This territory is already claimed + return false; + } - if (DbManager.WarehouseQueries.updateStone(warehouse, resourceValue - 8000) == true) { - warehouse.getResources().put(Warehouse.stoneIB, resourceValue - 8000); - warehouse.AddTransactionToWarehouse(engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.STONE, 8000); - } else { - Logger.error( "stone update failed for warehouse of UUID:" + warehouse.getObjectUUID()); - return false; - } + if (!Realm.HasAllBlessings(player)) { + ErrorPopupMsg.sendErrorPopup(player, 185); // You must seek the blessing of the three sages before you can rule + return false; + } - resourceValue = warehouse.getResources().get(Warehouse.lumberIB); + // Must have the required resources in warehouse to claim realm - if (DbManager.WarehouseQueries.updateLumber(warehouse, resourceValue - 8000) == true) { - warehouse.getResources().put(Warehouse.lumberIB, resourceValue - 8000); - warehouse.AddTransactionToWarehouse(engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.LUMBER, 8000); - } else { - Logger.error("lumber update failed for warehouse of UUID:" + warehouse.getObjectUUID()); - return false; - } + warehouse = city.getWarehouse(); - resourceValue = warehouse.getResources().get(Warehouse.galvorIB); + if (warehouse == null) { + ErrorPopupMsg.sendErrorPopup(player, 188); // You must have a warehouse to become a capital + return false; + } - if (DbManager.WarehouseQueries.updateGalvor(warehouse, resourceValue - 15) == true) { - warehouse.getResources().put(Warehouse.galvorIB, resourceValue - 15); - warehouse.AddTransactionToWarehouse(engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.GALVOR, 15); - } else { - Logger.error("galvor update failed for warehouse of UUID:" + warehouse.getObjectUUID()); - return false; - } + resourceValue = warehouse.getResources().get(Warehouse.goldIB); - resourceValue = warehouse.getResources().get(Warehouse.wormwoodIB); + if (resourceValue < 5000000) + hasResources = false; - if (DbManager.WarehouseQueries.updateWormwood(warehouse, resourceValue - 15) == true) { - warehouse.getResources().put(Warehouse.wormwoodIB, resourceValue - 15); - warehouse.AddTransactionToWarehouse(engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.WORMWOOD, 15); - } else { - Logger.error("wormwood update failed for warehouse of UUID:" + warehouse.getObjectUUID()); - return false; - } + resourceValue = warehouse.getResources().get(Warehouse.stoneIB); - realm.claimRealmForCity(city, charterUUID); + if (resourceValue < 8000) + hasResources = false; - tol.setRank(8); - WorldGrid.updateObject(tol); + resourceValue = warehouse.getResources().get(Warehouse.lumberIB); - for (Building building : city.getParent().zoneBuildingSet) { + if (resourceValue < 8000) + hasResources = false; - if (building.getBlueprintUUID() != 0) { + resourceValue = warehouse.getResources().get(Warehouse.galvorIB); - // TOL Health set through regular linear equation - if (building.getBlueprint().getBuildingGroup() == BuildingGroup.TOL) { - continue; - } + if (resourceValue < 15) + hasResources = false; - hPMod = (building.getMaxHitPoints() * Realm.getRealmHealthMod(city)); - building.setMaxHitPoints(building.getMaxHitPoints() + hPMod); - } - } + resourceValue = warehouse.getResources().get(Warehouse.wormwoodIB); - if (!guild.getNation().equals(guild)) { - guild.getNation().setRealmsOwned(guild.getNation().getRealmsOwned() + 1); - GuildManager.updateAllGuildTags(guild.getNation()); - } + if (resourceValue < 15) + hasResources = false; - guild.setRealmsOwned(guild.getRealmsOwned() + 1); - GuildManager.updateAllGuildTags(guild); + if (hasResources == false) { + ErrorPopupMsg.sendErrorPopup(player, 184); // Insufficient gold or resources to upgrade to capital + return false; + } - removeAllBlessings(player); + // Remove resources from warehouse before claiming realm - return true; + resourceValue = warehouse.getResources().get(Warehouse.goldIB); - } + if (DbManager.WarehouseQueries.updateGold(warehouse, resourceValue - 5000000) == true) { + warehouse.getResources().put(Warehouse.goldIB, resourceValue - 5000000); + warehouse.AddTransactionToWarehouse(engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.GOLD, 5000000); + } else { + Logger.error("gold update failed for warehouse of UUID:" + warehouse.getObjectUUID()); + return false; + } - private static void removeAllBlessings(PlayerCharacter player) { + resourceValue = warehouse.getResources().get(Warehouse.stoneIB); - PowersBase[] powers = new PowersBase[3]; + if (DbManager.WarehouseQueries.updateStone(warehouse, resourceValue - 8000) == true) { + warehouse.getResources().put(Warehouse.stoneIB, resourceValue - 8000); + warehouse.AddTransactionToWarehouse(engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.STONE, 8000); + } else { + Logger.error("stone update failed for warehouse of UUID:" + warehouse.getObjectUUID()); + return false; + } - powers[0] = PowersManager.getPowerByIDString("BLS-POWER"); - powers[1] = PowersManager.getPowerByIDString("BLS-FORTUNE"); - powers[2] = PowersManager.getPowerByIDString("BLS-WISDOM"); + resourceValue = warehouse.getResources().get(Warehouse.lumberIB); - for (PowersBase power : powers) { - PowersManager.removeEffect(player, power.getActions().get(0), true, false); - } + if (DbManager.WarehouseQueries.updateLumber(warehouse, resourceValue - 8000) == true) { + warehouse.getResources().put(Warehouse.lumberIB, resourceValue - 8000); + warehouse.AddTransactionToWarehouse(engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.LUMBER, 8000); + } else { + Logger.error("lumber update failed for warehouse of UUID:" + warehouse.getObjectUUID()); + return false; + } - } - // Handle activation of tears of seadron: Removes rune from player. + resourceValue = warehouse.getResources().get(Warehouse.galvorIB); - private static void removeRune(PlayerCharacter pc, ClientConnection origin, int runeID) { + if (DbManager.WarehouseQueries.updateGalvor(warehouse, resourceValue - 15) == true) { + warehouse.getResources().put(Warehouse.galvorIB, resourceValue - 15); + warehouse.AddTransactionToWarehouse(engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.GALVOR, 15); + } else { + Logger.error("galvor update failed for warehouse of UUID:" + warehouse.getObjectUUID()); + return false; + } - if (pc == null || origin == null) { - return; - } + resourceValue = warehouse.getResources().get(Warehouse.wormwoodIB); - //remove only if rune is discipline - if (runeID < 3001 || runeID > 3048) { - return; - } + if (DbManager.WarehouseQueries.updateWormwood(warehouse, resourceValue - 15) == true) { + warehouse.getResources().put(Warehouse.wormwoodIB, resourceValue - 15); + warehouse.AddTransactionToWarehouse(engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.WORMWOOD, 15); + } else { + Logger.error("wormwood update failed for warehouse of UUID:" + warehouse.getObjectUUID()); + return false; + } - //see if pc has rune - ArrayList runes = pc.getRunes(); + realm.claimRealmForCity(city, charterUUID); - if (runes == null) - return; + tol.setRank(8); + WorldGrid.updateObject(tol); - CharacterRune found = pc.getRune(runeID); + for (Building building : city.getParent().zoneBuildingSet) { - if (found == null) - return; + if (building.getBlueprintUUID() != 0) { - //TODO see if player needs to refine skills or powers first - //attempt remove rune from player + // TOL Health set through regular linear equation + if (building.getBlueprint().getBuildingGroup() == BuildingGroup.TOL) { + continue; + } - if (!CharacterRune.removeRune(pc, runeID)) - return; + hPMod = (building.getMaxHitPoints() * Realm.getRealmHealthMod(city)); + building.setMaxHitPoints(building.getMaxHitPoints() + hPMod); + } + } - //update client with removed rune. - ApplyRuneMsg arm = new ApplyRuneMsg(pc.getObjectType().ordinal(), pc.getObjectUUID(), runeID); - Dispatch dispatch = Dispatch.borrow(pc, arm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } + if (!guild.getNation().equals(guild)) { + guild.getNation().setRealmsOwned(guild.getNation().getRealmsOwned() + 1); + GuildManager.updateAllGuildTags(guild.getNation()); + } + + guild.setRealmsOwned(guild.getRealmsOwned() + 1); + GuildManager.updateAllGuildTags(guild); + + removeAllBlessings(player); + + return true; + + } + + private static void removeAllBlessings(PlayerCharacter player) { + + PowersBase[] powers = new PowersBase[3]; + + powers[0] = PowersManager.getPowerByIDString("BLS-POWER"); + powers[1] = PowersManager.getPowerByIDString("BLS-FORTUNE"); + powers[2] = PowersManager.getPowerByIDString("BLS-WISDOM"); + + for (PowersBase power : powers) { + PowersManager.removeEffect(player, power.getActions().get(0), true, false); + } + + } + + private static void removeRune(PlayerCharacter pc, ClientConnection origin, int runeID) { + + if (pc == null || origin == null) { + return; + } + + //remove only if rune is discipline + if (runeID < 3001 || runeID > 3048) { + return; + } + + //see if pc has rune + ArrayList runes = pc.getRunes(); + + if (runes == null) + return; + + CharacterRune found = pc.getRune(runeID); + + if (found == null) + return; + + //TODO see if player needs to refine skills or powers first + //attempt remove rune from player + + if (!CharacterRune.removeRune(pc, runeID)) + return; + + //update client with removed rune. + ApplyRuneMsg arm = new ApplyRuneMsg(pc.getObjectType().ordinal(), pc.getObjectUUID(), runeID); + Dispatch dispatch = Dispatch.borrow(pc, arm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + } + // Handle activation of tears of seadron: Removes rune from player. + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + // Member variable declaration + ObjectActionMsg msg; + PlayerCharacter player; + CharacterItemManager itemMan; + ArrayList comps; + Dispatch dispatch; + boolean waterbucketBypass = false; + + // Member variable assignment + msg = (ObjectActionMsg) baseMsg; + player = SessionManager.getPlayerCharacter(origin); + + if (player == null) { + return true; + } + + itemMan = player.getCharItemManager(); + + if (itemMan == null) { + return true; + } + + comps = msg.getTargetCompID(); + + if (comps.isEmpty()) { + return true; + } + + long comp = comps.get(0); + + if (((int) comp) != 0) { + Item item = Item.getFromCache((int) comp); + + if (item == null) { + return true; + } + + //dupe check + if (!item.validForInventory(origin, player, itemMan)) { + return true; + } + + ItemBase ib = item.getItemBase(); + + if (ib == null) { + return true; + } + + if (itemMan.doesCharOwnThisItem(item.getObjectUUID())) { + + if (ib.isConsumable() || ib.getType() == ItemType.FARMABLE) { + + int uuid = ib.getUUID(); + int type = ib.getType().getValue(); + + switch (type) { + case 27: //Mithril repair + break; + case 10: //charters + //don't think they're handled here? + break; + case 19: //buildings + //Call add building screen here, ib.getUseID() get's building ID + + //if inside player city, center loc on tol. otherwise center on player. + Vector3fImmutable loc = player.getLoc(); + Zone zone = ZoneManager.findSmallestZone(player.getLoc()); + + if (zone != null) { + if (zone.isPlayerCity()) { + loc = zone.getLoc(); + } + } + + PlaceAssetMsg pam = new PlaceAssetMsg(); + pam.setActionType(2); + pam.setContractID(item.getObjectUUID()); + pam.setX(loc.getX() + 64); //offset grid from tol + pam.setY(loc.getY()); + pam.setZ(loc.getZ() + 64); //offset grid from tol + pam.addPlacementInfo(ib.getUseID()); + + dispatch = Dispatch.borrow(player, pam); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + //itemMan.consume(item); //temporary fix for dupe.. TODO Make Item Unusable after This message is sent. + break; + case 25: //furniture + //Call add furniture screen here. ib.getUseID() get's furniture ID + break; + case 33: + long shrineCompID = comps.get(1); + Building shrineBuilding = BuildingManager.getBuilding((int) shrineCompID); + if (shrineBuilding == null) { + return true; + } + if (shrineBuilding.getBlueprint() != null && shrineBuilding.getBlueprint().getBuildingGroup() != engine.Enum.BuildingGroup.SHRINE) { + return true; + } + + if (shrineBuilding.getRank() == -1) { + return true; + } + Shrine shrine = Shrine.shrinesByBuildingUUID.get(shrineBuilding.getObjectUUID()); + + if (shrine == null) { + return true; + } + + if (shrine.addFavor(player, item)) { + shrineBuilding.addEffectBit(1000000 << 2); + shrineBuilding.updateEffects(); + shrineBuilding.removeEffectBit(1000000 << 2); + } + break; + + case 35: + int charterType = 0; + switch (uuid) { + case 910020: + charterType = 762228431; + break; + case 910021: + charterType = -15978914; + break; + case 910022: + charterType = -600065291; + break; + } + if (claimRealm(player, charterType) == true) { + itemMan.consume(item); + } + break; + case 7: //rod of command + long compID = comps.get(1); + + int objectType = AbstractWorldObject.extractTypeID(compID).ordinal(); + Mob toCommand; + if (objectType == engine.Enum.GameObjectType.Mob.ordinal()) { + toCommand = Mob.getFromCache((int) compID); + } //Only Command Mob Types. + else { + return true; + } + + if (toCommand == null) { + return true; + } + + if (!toCommand.isSiege()) + return true; + + if (player.commandSiegeMinion(toCommand)) { + itemMan.consume(item); + } + break; + //ANNIVERSERY GIFT + case 31: + + + if (ib.getUUID() == 971012) { + int random = ThreadLocalRandom.current().nextInt(ItemBase.AnniverseryGifts.size()); + int annyID = ItemBase.AnniverseryGifts.get(random); + + ItemBase annyIB = ItemBase.getItemBase(annyID); + if (annyIB != null) { + Item gift = MobLoot.createItemForPlayer(player, annyIB); + if (gift != null) { + itemMan.addItemToInventory(gift); + itemMan.consume(item); + } + } + break; + } + + LootTable.CreateGamblerItem(item, player); + + + break; + + case 30: //water bucket + case 8: //potions, tears of saedron + + case 5: //runes, petition, warrant, scrolls + if (uuid > 3000 && uuid < 3050) { //Discipline Runes + if (ApplyRuneMsg.applyRune(uuid, origin, player)) { + itemMan.consume(item); + } + break; + } else if (uuid > 249999 && uuid < 250123) { //stat and mastery runes + if (ApplyRuneMsg.applyRune(uuid, origin, player)) { + itemMan.consume(item); + } + break; + } else if (uuid > 250114 && uuid < 250123) { //mastery runes + if (ApplyRuneMsg.applyRune(uuid, origin, player)) { + itemMan.consume(item); + } + break; + } else if (uuid > 252122 && uuid < 252128) { //mastery runes + if (ApplyRuneMsg.applyRune(uuid, origin, player)) { + itemMan.consume(item); + } + break; + } else if (uuid > 680069 && uuid < 680074) //Handle Charter, Deed, Petition, Warrant here + { + break; + } else if (uuid > 910010 && uuid < 910019) { + + int rank = uuid - 910010; + + if (rank < 1 || rank > 8) { + ChatManager.chatSystemError(player, "Invalid Rank for bane scroll!"); + return true; + } + // Only one banestone at a time + lock.writeLock().lock(); + + try { + if (Bane.summonBanestone(player, origin, rank) == true) + itemMan.consume(item); + } finally { + lock.writeLock().unlock(); + } + break; + } else if (uuid == 910010) { //tears of saedron + if (comps.size() > 1) { + removeRune(player, origin, comps.get(1).intValue()); + } + break; + } else if (item.getChargesRemaining() > 0) { + ArrayList tarList = msg.getTargetCompID(); + AbstractWorldObject target = player; + if (tarList.size() > 1) { + long tarID = tarList.get(1); + if (tarID != 0) { + AbstractGameObject tarAgo = AbstractGameObject.getFromTypeAndID(tarID); + if (tarAgo != null && tarAgo instanceof AbstractWorldObject) { + target = (AbstractWorldObject) tarAgo; + } + } + } + + // Bypass for waterbuckets + + // test character targeted + + if (ib.getUUID() == 910005) { + + // test for valid target type + if (target.getObjectType() == Enum.GameObjectType.PlayerCharacter) + waterbucketBypass = true; + else { + // test distance to structure + Building targetBuilding = (Building) target; + Bounds testBounds = Bounds.borrow(); + testBounds.setBounds(player.getLoc(), 25); + + if (Bounds.collide(targetBuilding.getBounds(), testBounds, .1f) == false) { + ChatManager.chatSystemError(player, "Not in range of structura for to heal!"); + return true; + } + } + + // Send piss bucket animation + + VisualUpdateMessage vum = new VisualUpdateMessage(player, 16323); + vum.configure(); + DispatchMessage.sendToAllInRange(player, vum); + } + + if (waterbucketBypass == false) + PowersManager.applyPower(player, target, Vector3fImmutable.ZERO, ib.getUseID(), ib.getUseAmount(), true); + + itemMan.consume(item); + } else //just remove the item at this point + itemMan.consume(item); + + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + player.cancelOnSpell(); + break; + default: //shouldn't be here, consume item + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + // itemMan.consume(item); + } + } + } else { + // TODO log item does not belong to player + // System.out.println("Item does not belong to player"); + // Cleanup duped item here + } + } + + return true; + } } diff --git a/src/engine/net/client/handlers/OpenFriendsCondemnListMsgHandler.java b/src/engine/net/client/handlers/OpenFriendsCondemnListMsgHandler.java index 27fc4083..ccb93609 100644 --- a/src/engine/net/client/handlers/OpenFriendsCondemnListMsgHandler.java +++ b/src/engine/net/client/handlers/OpenFriendsCondemnListMsgHandler.java @@ -26,372 +26,371 @@ import java.util.ArrayList; public class OpenFriendsCondemnListMsgHandler extends AbstractClientMsgHandler { - public OpenFriendsCondemnListMsgHandler() { - super(OpenFriendsCondemnListMsg.class); - } - - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - - PlayerCharacter player = SessionManager.getPlayerCharacter(origin); - Building sourceBuilding; - OpenFriendsCondemnListMsg msg; - OpenFriendsCondemnListMsg openFriendsCondemnListMsg; - Enum.FriendListType friendListType; - Dispatch dispatch; - - if (player == null) - return true; - - msg = (OpenFriendsCondemnListMsg) baseMsg; - openFriendsCondemnListMsg = new OpenFriendsCondemnListMsg(msg); - friendListType = Enum.FriendListType.getListTypeByID(msg.getMessageType()); - - if (friendListType == null){ - Logger.error("Invalid FriendListType for messageType " + msg.getMessageType()); - return true; - } - - switch (friendListType) { - case VIEWHERALDRY: // Heraldry - - Heraldry.ValidateHeraldry(player.getObjectUUID()); - OpenFriendsCondemnListMsg outMsg = new OpenFriendsCondemnListMsg(msg); - outMsg.setOrigin(origin); - outMsg.setMessageType(2); - dispatch = Dispatch.borrow(player, outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - break; - - case ADDHERALDRY: - Heraldry.ValidateHeraldry(player.getObjectUUID()); - if (msg.getPlayerID() <= 0){ - //ErrorPopupMsg.sendErrorMsg(player, "Invalid Heraldry Object."); - return true; - } - AbstractCharacter toAdd = null; - if (msg.getPlayerType() == GameObjectType.PlayerCharacter.ordinal()) - toAdd = PlayerCharacter.getFromCache(msg.getPlayerID()); - else if (msg.getPlayerType() == GameObjectType.NPC.ordinal()) - toAdd = NPC.getFromCache(msg.getPlayerID()); - else if (msg.getPlayerType() == GameObjectType.Mob.ordinal()) - toAdd = Mob.getFromCache(msg.getPlayerID()); - else{ - ErrorPopupMsg.sendErrorMsg(player, "Invalid Heraldry Object."); - return true; - } - - if (toAdd == null){ - ErrorPopupMsg.sendErrorMsg(player, "Invalid Heraldry Object."); - return true; - } - - Heraldry.AddToHeraldy(player.getObjectUUID(), toAdd); - - - outMsg = new OpenFriendsCondemnListMsg(msg); - outMsg.setOrigin(origin); - outMsg.setMessageType(2); - dispatch = Dispatch.borrow(player, outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - break; - case REMOVEHERALDRY: - Heraldry.ValidateHeraldry(player.getObjectUUID()); - Heraldry.RemoveFromHeraldy(player.getObjectUUID(), msg.getPlayerID()); - - - outMsg = new OpenFriendsCondemnListMsg(msg); - outMsg.setOrigin(origin); - outMsg.setMessageType(2); - dispatch = Dispatch.borrow(player, outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - break; - - case DEALTHS: // Death List - openFriendsCondemnListMsg.updateMsg(8, new ArrayList<>(player.pvpDeaths)); - dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - break; - - case KILLS: // Kill List - openFriendsCondemnListMsg.updateMsg(10, new ArrayList<>(player.pvpKills)); - dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - break; - - case VIEWCONDEMN: - - sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID()); - - if (sourceBuilding == null) - return true; - - openFriendsCondemnListMsg = new OpenFriendsCondemnListMsg(12, sourceBuilding.getCondemned(), sourceBuilding.reverseKOS); - openFriendsCondemnListMsg.configure(); - dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - //msg.updateMsg(12, DbManager.GuildQueries.) - break; - //REMOVE CONDEMN - case REMOVECONDEMN: - - sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID()); - - if (sourceBuilding == null) - return true; - - if (!BuildingManager.PlayerCanControlNotOwner(sourceBuilding, player)) - return true; - - Condemned removeCondemn = sourceBuilding.getCondemned().get(msg.getRemoveFriendID()); - - if (removeCondemn == null) - return true; - - if (!DbManager.BuildingQueries.REMOVE_FROM_CONDEMNED_LIST(removeCondemn.getParent(), removeCondemn.getPlayerUID(), removeCondemn.getGuildUID(), removeCondemn.getFriendType())) - return true; - - sourceBuilding.getCondemned().remove(msg.getRemoveFriendID()); - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - break; - - case TOGGLEACTIVE: - - sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID()); - - if (sourceBuilding == null) - return true; - - if (!BuildingManager.PlayerCanControlNotOwner(sourceBuilding, player)) - return true; - - Condemned condemn = sourceBuilding.getCondemned().get(msg.getRemoveFriendID()); + public OpenFriendsCondemnListMsgHandler() { + super(OpenFriendsCondemnListMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter player = SessionManager.getPlayerCharacter(origin); + Building sourceBuilding; + OpenFriendsCondemnListMsg msg; + OpenFriendsCondemnListMsg openFriendsCondemnListMsg; + Enum.FriendListType friendListType; + Dispatch dispatch; + + if (player == null) + return true; + + msg = (OpenFriendsCondemnListMsg) baseMsg; + openFriendsCondemnListMsg = new OpenFriendsCondemnListMsg(msg); + friendListType = Enum.FriendListType.getListTypeByID(msg.getMessageType()); + + if (friendListType == null) { + Logger.error("Invalid FriendListType for messageType " + msg.getMessageType()); + return true; + } + + switch (friendListType) { + case VIEWHERALDRY: // Heraldry + + Heraldry.ValidateHeraldry(player.getObjectUUID()); + OpenFriendsCondemnListMsg outMsg = new OpenFriendsCondemnListMsg(msg); + outMsg.setOrigin(origin); + outMsg.setMessageType(2); + dispatch = Dispatch.borrow(player, outMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + break; + + case ADDHERALDRY: + Heraldry.ValidateHeraldry(player.getObjectUUID()); + if (msg.getPlayerID() <= 0) { + //ErrorPopupMsg.sendErrorMsg(player, "Invalid Heraldry Object."); + return true; + } + AbstractCharacter toAdd = null; + if (msg.getPlayerType() == GameObjectType.PlayerCharacter.ordinal()) + toAdd = PlayerCharacter.getFromCache(msg.getPlayerID()); + else if (msg.getPlayerType() == GameObjectType.NPC.ordinal()) + toAdd = NPC.getFromCache(msg.getPlayerID()); + else if (msg.getPlayerType() == GameObjectType.Mob.ordinal()) + toAdd = Mob.getFromCache(msg.getPlayerID()); + else { + ErrorPopupMsg.sendErrorMsg(player, "Invalid Heraldry Object."); + return true; + } - if (condemn == null) - return true; + if (toAdd == null) { + ErrorPopupMsg.sendErrorMsg(player, "Invalid Heraldry Object."); + return true; + } - condemn.setActive(msg.isReverseKOS()); - openFriendsCondemnListMsg.setReverseKOS(condemn.isActive()); - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - break; - case REVERSEKOS: + Heraldry.AddToHeraldy(player.getObjectUUID(), toAdd); - sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID()); + outMsg = new OpenFriendsCondemnListMsg(msg); + outMsg.setOrigin(origin); + outMsg.setMessageType(2); + dispatch = Dispatch.borrow(player, outMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - if (sourceBuilding == null) - return true; + break; + case REMOVEHERALDRY: + Heraldry.ValidateHeraldry(player.getObjectUUID()); + Heraldry.RemoveFromHeraldy(player.getObjectUUID(), msg.getPlayerID()); - if (!BuildingManager.PlayerCanControlNotOwner(sourceBuilding, player)) - return true; - if (!sourceBuilding.setReverseKOS(msg.isReverseKOS())) - return true; - break; + outMsg = new OpenFriendsCondemnListMsg(msg); + outMsg.setOrigin(origin); + outMsg.setMessageType(2); + dispatch = Dispatch.borrow(player, outMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - //ADD GUILD CONDEMN - case ADDCONDEMN: + break; - sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID()); + case DEALTHS: // Death List + openFriendsCondemnListMsg.updateMsg(8, new ArrayList<>(player.pvpDeaths)); + dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + break; - if (sourceBuilding == null) - return true; + case KILLS: // Kill List + openFriendsCondemnListMsg.updateMsg(10, new ArrayList<>(player.pvpKills)); + dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + break; - if (!BuildingManager.PlayerCanControlNotOwner(sourceBuilding, player)) - return true; + case VIEWCONDEMN: - switch (msg.getInviteType()) { - case 2: + sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID()); - if (msg.getPlayerID() == 0) - return true; - - if (msg.getPlayerType() != GameObjectType.PlayerCharacter.ordinal()) - return true; + if (sourceBuilding == null) + return true; - PlayerCharacter playerCharacter = PlayerCharacter.getFromCache(msg.getPlayerID()); + openFriendsCondemnListMsg = new OpenFriendsCondemnListMsg(12, sourceBuilding.getCondemned(), sourceBuilding.reverseKOS); + openFriendsCondemnListMsg.configure(); + dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - if (playerCharacter == null) - return true; + //msg.updateMsg(12, DbManager.GuildQueries.) + break; + //REMOVE CONDEMN + case REMOVECONDEMN: - if (Guild.sameNationExcludeErrant(sourceBuilding.getGuild(), playerCharacter.getGuild())) - return true; + sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID()); - if (sourceBuilding.getCondemned().containsKey(playerCharacter.getObjectUUID())) - return true; + if (sourceBuilding == null) + return true; - if (!DbManager.BuildingQueries.ADD_TO_CONDEMNLIST(sourceBuilding.getObjectUUID(), playerCharacter.getObjectUUID(), msg.getGuildID(), msg.getInviteType())) { - Logger.debug( "Failed to add Condemned: " + playerCharacter.getFirstName() + " to Building With UID " + sourceBuilding.getObjectUUID()); - return true; - } + if (!BuildingManager.PlayerCanControlNotOwner(sourceBuilding, player)) + return true; - sourceBuilding.getCondemned().put(playerCharacter.getObjectUUID(), new Condemned(playerCharacter.getObjectUUID(), sourceBuilding.getObjectUUID(), msg.getGuildID(), msg.getInviteType())); - break; - case 4: - if (msg.getGuildID() == 0) - return true; + Condemned removeCondemn = sourceBuilding.getCondemned().get(msg.getRemoveFriendID()); - if (sourceBuilding.getCondemned().containsKey(msg.getGuildID())) - return true; + if (removeCondemn == null) + return true; - Guild condemnedGuild = Guild.getGuild(msg.getGuildID()); + if (!DbManager.BuildingQueries.REMOVE_FROM_CONDEMNED_LIST(removeCondemn.getParent(), removeCondemn.getPlayerUID(), removeCondemn.getGuildUID(), removeCondemn.getFriendType())) + return true; - if (condemnedGuild == null) - return true; + sourceBuilding.getCondemned().remove(msg.getRemoveFriendID()); + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + break; - if (!DbManager.BuildingQueries.ADD_TO_CONDEMNLIST(sourceBuilding.getObjectUUID(), msg.getPlayerID(), condemnedGuild.getObjectUUID(), msg.getInviteType())) { - Logger.debug("Failed to add Condemned: " + condemnedGuild.getName() + " to Building With UID " + sourceBuilding.getObjectUUID()); - return true; - } + case TOGGLEACTIVE: - sourceBuilding.getCondemned().put(condemnedGuild.getObjectUUID(), new Condemned(msg.getPlayerID(), sourceBuilding.getObjectUUID(), condemnedGuild.getObjectUUID(), msg.getInviteType())); - break; - case 5: - if (msg.getNationID() == 0) - return true; + sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID()); - if (sourceBuilding.getCondemned().containsKey(msg.getNationID())) - return true; + if (sourceBuilding == null) + return true; - Guild condemnedNation = Guild.getGuild(msg.getNationID()); + if (!BuildingManager.PlayerCanControlNotOwner(sourceBuilding, player)) + return true; - if (condemnedNation == null) - return true; + Condemned condemn = sourceBuilding.getCondemned().get(msg.getRemoveFriendID()); - if (!DbManager.BuildingQueries.ADD_TO_CONDEMNLIST(sourceBuilding.getObjectUUID(), msg.getPlayerID(), condemnedNation.getObjectUUID(), msg.getInviteType())) { - Logger.debug( "Failed to add Condemned: " + condemnedNation.getName() + " to Building With UID " + sourceBuilding.getObjectUUID()); - return true; - } + if (condemn == null) + return true; - sourceBuilding.getCondemned().put(condemnedNation.getObjectUUID(), new Condemned(msg.getPlayerID(), sourceBuilding.getObjectUUID(), condemnedNation.getObjectUUID(), msg.getInviteType())); - break; + condemn.setActive(msg.isReverseKOS()); + openFriendsCondemnListMsg.setReverseKOS(condemn.isActive()); + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + break; + case REVERSEKOS: - } - openFriendsCondemnListMsg = new OpenFriendsCondemnListMsg(12, sourceBuilding.getCondemned(), sourceBuilding.reverseKOS); - openFriendsCondemnListMsg.configure(); - dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - break; + sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID()); - //ADD FRIEND BUILDING - case ADDFRIEND: - sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID()); + if (sourceBuilding == null) + return true; - if (sourceBuilding == null) - return true; + if (!BuildingManager.PlayerCanControlNotOwner(sourceBuilding, player)) + return true; - if (msg.getGuildID() == 0) - return true; + if (!sourceBuilding.setReverseKOS(msg.isReverseKOS())) + return true; + break; - if (!BuildingManager.PlayerCanControlNotOwner(sourceBuilding, player)) - return true; - - PlayerCharacter playerCharacter = null; + //ADD GUILD CONDEMN + case ADDCONDEMN: - + sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID()); - Guild guildInvited = Guild.getGuild(msg.getGuildID()); + if (sourceBuilding == null) + return true; - if (guildInvited == null) - return true; + if (!BuildingManager.PlayerCanControlNotOwner(sourceBuilding, player)) + return true; - //Check to see if the invited is already on the friends list. - switch (msg.getInviteType()) { - case 7: - playerCharacter = PlayerCharacter.getFromCache(msg.getPlayerID()); - if (playerCharacter == null) - return true; - if (sourceBuilding.getFriends().containsKey(playerCharacter.getObjectUUID())) - return true; - break; - case 8: - case 9: - if (sourceBuilding.getFriends().containsKey(guildInvited.getObjectUUID())) - return true; - break; - } - - if (!DbManager.BuildingQueries.ADD_TO_FRIENDS_LIST(sourceBuilding.getObjectUUID(), msg.getPlayerID(), guildInvited.getObjectUUID(), msg.getInviteType())) { - Logger.debug( "Failed to add Friend: " + playerCharacter.getFirstName() + " to Building With UID " + sourceBuilding.getObjectUUID()); - return true; - } - - switch (msg.getInviteType()) { - case 7: - sourceBuilding.getFriends().put(playerCharacter.getObjectUUID(), new BuildingFriends(playerCharacter.getObjectUUID(), sourceBuilding.getObjectUUID(), playerCharacter.getGuild().getObjectUUID(), 7)); - break; - case 8: - sourceBuilding.getFriends().put(guildInvited.getObjectUUID(), new BuildingFriends(msg.getPlayerID(), sourceBuilding.getObjectUUID(), guildInvited.getObjectUUID(), 8)); - break; - case 9: - sourceBuilding.getFriends().put(guildInvited.getObjectUUID(), new BuildingFriends(msg.getPlayerID(), sourceBuilding.getObjectUUID(), guildInvited.getObjectUUID(), 9)); - break; - } - - openFriendsCondemnListMsg = new OpenFriendsCondemnListMsg(26, sourceBuilding.getFriends()); - openFriendsCondemnListMsg.configure(); - - dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - break; - //REMOVE from friends list. - case REMOVEFRIEND: - sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID()); - - if (sourceBuilding == null) - return true; - - if (!BuildingManager.PlayerCanControlNotOwner(sourceBuilding, player)) - return true; - - BuildingFriends friend = sourceBuilding.getFriends().get(msg.getRemoveFriendID()); - - if (friend == null) - return true; + switch (msg.getInviteType()) { + case 2: - if (!DbManager.BuildingQueries.REMOVE_FROM_FRIENDS_LIST(sourceBuilding.getObjectUUID(), friend.getPlayerUID(), friend.getGuildUID(), friend.getFriendType())) { - Logger.debug( "Failed to remove Friend: " + msg.getRemoveFriendID() + " from Building With UID " + sourceBuilding.getObjectUUID()); - return true; - } - sourceBuilding.getFriends().remove(msg.getRemoveFriendID()); - - openFriendsCondemnListMsg = new OpenFriendsCondemnListMsg(26, sourceBuilding.getFriends()); - openFriendsCondemnListMsg.configure(); - dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - break; - //view Friends - case VIEWFRIENDS: - - Building building = BuildingManager.getBuildingFromCache(msg.getBuildingID()); - - if (building == null) - return true; - - if (!BuildingManager.PlayerCanControlNotOwner(building, player)) - return true; - - //this message is sent twice back????? - - openFriendsCondemnListMsg = new OpenFriendsCondemnListMsg(26, building.getFriends()); - openFriendsCondemnListMsg.configure(); - - - dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - break; - - default: - break; - } - return false; - } + if (msg.getPlayerID() == 0) + return true; + + if (msg.getPlayerType() != GameObjectType.PlayerCharacter.ordinal()) + return true; + + PlayerCharacter playerCharacter = PlayerCharacter.getFromCache(msg.getPlayerID()); + + if (playerCharacter == null) + return true; + + if (Guild.sameNationExcludeErrant(sourceBuilding.getGuild(), playerCharacter.getGuild())) + return true; + + if (sourceBuilding.getCondemned().containsKey(playerCharacter.getObjectUUID())) + return true; + + if (!DbManager.BuildingQueries.ADD_TO_CONDEMNLIST(sourceBuilding.getObjectUUID(), playerCharacter.getObjectUUID(), msg.getGuildID(), msg.getInviteType())) { + Logger.debug("Failed to add Condemned: " + playerCharacter.getFirstName() + " to Building With UID " + sourceBuilding.getObjectUUID()); + return true; + } + + sourceBuilding.getCondemned().put(playerCharacter.getObjectUUID(), new Condemned(playerCharacter.getObjectUUID(), sourceBuilding.getObjectUUID(), msg.getGuildID(), msg.getInviteType())); + break; + case 4: + if (msg.getGuildID() == 0) + return true; + + if (sourceBuilding.getCondemned().containsKey(msg.getGuildID())) + return true; + + Guild condemnedGuild = Guild.getGuild(msg.getGuildID()); + + if (condemnedGuild == null) + return true; + + if (!DbManager.BuildingQueries.ADD_TO_CONDEMNLIST(sourceBuilding.getObjectUUID(), msg.getPlayerID(), condemnedGuild.getObjectUUID(), msg.getInviteType())) { + Logger.debug("Failed to add Condemned: " + condemnedGuild.getName() + " to Building With UID " + sourceBuilding.getObjectUUID()); + return true; + } + + sourceBuilding.getCondemned().put(condemnedGuild.getObjectUUID(), new Condemned(msg.getPlayerID(), sourceBuilding.getObjectUUID(), condemnedGuild.getObjectUUID(), msg.getInviteType())); + break; + case 5: + if (msg.getNationID() == 0) + return true; + + if (sourceBuilding.getCondemned().containsKey(msg.getNationID())) + return true; + + Guild condemnedNation = Guild.getGuild(msg.getNationID()); + + if (condemnedNation == null) + return true; + + if (!DbManager.BuildingQueries.ADD_TO_CONDEMNLIST(sourceBuilding.getObjectUUID(), msg.getPlayerID(), condemnedNation.getObjectUUID(), msg.getInviteType())) { + Logger.debug("Failed to add Condemned: " + condemnedNation.getName() + " to Building With UID " + sourceBuilding.getObjectUUID()); + return true; + } + + sourceBuilding.getCondemned().put(condemnedNation.getObjectUUID(), new Condemned(msg.getPlayerID(), sourceBuilding.getObjectUUID(), condemnedNation.getObjectUUID(), msg.getInviteType())); + break; + + } + + openFriendsCondemnListMsg = new OpenFriendsCondemnListMsg(12, sourceBuilding.getCondemned(), sourceBuilding.reverseKOS); + openFriendsCondemnListMsg.configure(); + dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + break; + + //ADD FRIEND BUILDING + case ADDFRIEND: + sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID()); + + if (sourceBuilding == null) + return true; + + if (msg.getGuildID() == 0) + return true; + + if (!BuildingManager.PlayerCanControlNotOwner(sourceBuilding, player)) + return true; + + PlayerCharacter playerCharacter = null; + + + Guild guildInvited = Guild.getGuild(msg.getGuildID()); + + if (guildInvited == null) + return true; + + //Check to see if the invited is already on the friends list. + switch (msg.getInviteType()) { + case 7: + playerCharacter = PlayerCharacter.getFromCache(msg.getPlayerID()); + if (playerCharacter == null) + return true; + if (sourceBuilding.getFriends().containsKey(playerCharacter.getObjectUUID())) + return true; + break; + case 8: + case 9: + if (sourceBuilding.getFriends().containsKey(guildInvited.getObjectUUID())) + return true; + break; + } + + if (!DbManager.BuildingQueries.ADD_TO_FRIENDS_LIST(sourceBuilding.getObjectUUID(), msg.getPlayerID(), guildInvited.getObjectUUID(), msg.getInviteType())) { + Logger.debug("Failed to add Friend: " + playerCharacter.getFirstName() + " to Building With UID " + sourceBuilding.getObjectUUID()); + return true; + } + + switch (msg.getInviteType()) { + case 7: + sourceBuilding.getFriends().put(playerCharacter.getObjectUUID(), new BuildingFriends(playerCharacter.getObjectUUID(), sourceBuilding.getObjectUUID(), playerCharacter.getGuild().getObjectUUID(), 7)); + break; + case 8: + sourceBuilding.getFriends().put(guildInvited.getObjectUUID(), new BuildingFriends(msg.getPlayerID(), sourceBuilding.getObjectUUID(), guildInvited.getObjectUUID(), 8)); + break; + case 9: + sourceBuilding.getFriends().put(guildInvited.getObjectUUID(), new BuildingFriends(msg.getPlayerID(), sourceBuilding.getObjectUUID(), guildInvited.getObjectUUID(), 9)); + break; + } + + openFriendsCondemnListMsg = new OpenFriendsCondemnListMsg(26, sourceBuilding.getFriends()); + openFriendsCondemnListMsg.configure(); + + dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + break; + //REMOVE from friends list. + case REMOVEFRIEND: + sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID()); + + if (sourceBuilding == null) + return true; + + if (!BuildingManager.PlayerCanControlNotOwner(sourceBuilding, player)) + return true; + + BuildingFriends friend = sourceBuilding.getFriends().get(msg.getRemoveFriendID()); + + if (friend == null) + return true; + + if (!DbManager.BuildingQueries.REMOVE_FROM_FRIENDS_LIST(sourceBuilding.getObjectUUID(), friend.getPlayerUID(), friend.getGuildUID(), friend.getFriendType())) { + Logger.debug("Failed to remove Friend: " + msg.getRemoveFriendID() + " from Building With UID " + sourceBuilding.getObjectUUID()); + return true; + } + sourceBuilding.getFriends().remove(msg.getRemoveFriendID()); + + openFriendsCondemnListMsg = new OpenFriendsCondemnListMsg(26, sourceBuilding.getFriends()); + openFriendsCondemnListMsg.configure(); + dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + break; + //view Friends + case VIEWFRIENDS: + + Building building = BuildingManager.getBuildingFromCache(msg.getBuildingID()); + + if (building == null) + return true; + + if (!BuildingManager.PlayerCanControlNotOwner(building, player)) + return true; + + //this message is sent twice back????? + + openFriendsCondemnListMsg = new OpenFriendsCondemnListMsg(26, building.getFriends()); + openFriendsCondemnListMsg.configure(); + + + dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + break; + + default: + break; + } + return false; + } } \ No newline at end of file diff --git a/src/engine/net/client/handlers/PlaceAssetMsgHandler.java b/src/engine/net/client/handlers/PlaceAssetMsgHandler.java index 0ac8cf9c..a5956ebf 100644 --- a/src/engine/net/client/handlers/PlaceAssetMsgHandler.java +++ b/src/engine/net/client/handlers/PlaceAssetMsgHandler.java @@ -36,1343 +36,1342 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; */ public class PlaceAssetMsgHandler extends AbstractClientMsgHandler { - // Useful constants - // ActionType 1 = client request - // 2 = Server confirms open window - // 3 = Request to place asset - // 4 = Server confirms/close window - private static final int CLIENTREQ_UNKNOWN = 1; - private static final int SERVER_OPENWINDOW = 2; - private static final int CLIENTREQ_NEWBUILDING = 3; // Request to place asset - private static final int SERVER_CLOSEWINDOW = 4; + // Useful constants + // ActionType 1 = client request + // 2 = Server confirms open window + // 3 = Request to place asset + // 4 = Server confirms/close window + private static final int CLIENTREQ_UNKNOWN = 1; + private static final int SERVER_OPENWINDOW = 2; + private static final int CLIENTREQ_NEWBUILDING = 3; // Request to place asset + private static final int SERVER_CLOSEWINDOW = 4; - private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); + private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); - public PlaceAssetMsgHandler() { + public PlaceAssetMsgHandler() { - super(PlaceAssetMsg.class); + super(PlaceAssetMsg.class); - } + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - - // Member variable declaration - - PlaceAssetMsg msg; - Boolean buildingCreated; - - // Character location and session - - PlayerCharacter playerCharacter; - PlacementInfo buildingList; - Blueprint buildingBlueprint; - - // Tell compiler it's ok to trust us and parse - // what we need from the message structure - - msg = (PlaceAssetMsg) baseMsg; - - // Action type 3 is a client requesting to place an object - // For all other action types let's just early exit - - if (msg.getActionType() != CLIENTREQ_NEWBUILDING) - return true; - - // assign our character - - playerCharacter = SessionManager.getPlayerCharacter(origin); - - // We need to figure out what exactly the player is attempting - // to place, as some objects like tol/bane/walls are edge cases. - // So let's get the first item in their list. - - buildingList = msg.getFirstPlacementInfo(); - - // Early exit if null building list. - - if (buildingList == null) { - Logger.error("Player " + playerCharacter.getCombinedName() - + " null building list on deed use"); - PlaceAssetMsg.sendPlaceAssetError(origin, 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - closePlaceAssetWindow(origin); - return true; - } - - Item contract = null; - - for (Item inventoryItem : playerCharacter.getInventory()) { - if (inventoryItem.getItemBase().getUseID() == buildingList.getBlueprintUUID()) { - contract = inventoryItem; - break; - } - } - - // Grab the blueprint from the uuid in the message - - buildingBlueprint = Blueprint.getBlueprint(buildingList.getBlueprintUUID()); - - // Early exit if blueprint can't be retrieved for the object. - - if (buildingBlueprint == null) { - Logger.error("Player " + playerCharacter.getCombinedName() - + " null blueprint UUID: " + buildingList.getBlueprintUUID() + " on deed use"); - PlaceAssetMsg.sendPlaceAssetError(origin, 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - closePlaceAssetWindow(origin); - return true; - } - - // Let's now attempt to place the building - buildingCreated = false; - - // Many buildings have particular validation and - // post-creation cleanup requirements. - - boolean close = true; - lock.writeLock().lock(); - boolean isSiege = false; - try { - switch (buildingBlueprint.getBuildingGroup()) { - - case TOL: - if (contract == null) - break; - buildingCreated = placeTreeOfLife(playerCharacter, origin, msg); - break; - case WAREHOUSE: - if (contract == null) - break; - if (!playerCharacter.getCharItemManager().doesCharOwnThisItem(contract.getObjectUUID())) - break; - buildingCreated = placeWarehouse(playerCharacter, origin, msg); - break; - case SIEGETENT: - case BULWARK: - if (contract == null) - break; - if (!playerCharacter.getCharItemManager().doesCharOwnThisItem(contract.getObjectUUID())) - break; - buildingCreated = placeSiegeEquip(playerCharacter, origin, msg); - break; - case SPIRE: - if (contract == null) - break; - if (!playerCharacter.getCharItemManager().doesCharOwnThisItem(contract.getObjectUUID())) - break; - buildingCreated = placeSpire(playerCharacter, origin, msg); - break; - case SHRINE: - if (contract == null) - break; - if (!playerCharacter.getCharItemManager().doesCharOwnThisItem(contract.getObjectUUID())) - break; - buildingCreated = placeShrine(playerCharacter, origin, msg); - break; - case BARRACK: - if (contract == null) - break; - if (!playerCharacter.getCharItemManager().doesCharOwnThisItem(contract.getObjectUUID())) - break; - buildingCreated = placeBarrack(playerCharacter, origin, msg); - break; - case WALLSTRAIGHT: - case WALLCORNER: - case SMALLGATE: - case ARTYTOWER: - case WALLSTAIRS: - case WALLSTRAIGHTTOWER: - buildingCreated = placeCityWalls(playerCharacter, origin, msg); - close = false; - break; - default: - if (contract == null) - break; - if (!playerCharacter.getCharItemManager().doesCharOwnThisItem(contract.getObjectUUID())) - break; - buildingCreated = placeSingleBuilding(playerCharacter, origin, msg); - break; - } - } catch (Exception e) { - Logger.error("PlaceAssetHandler", e.getMessage()); - e.printStackTrace(); - } finally { - lock.writeLock().unlock(); - } - - // Update the player's last contract (What is this used for?) - - playerCharacter.setLastContract(msg.getContractID()); - - // Remove the appropriate deed. - if (buildingCreated == true) - if (contract != null) { - playerCharacter.getCharItemManager().delete(contract); - playerCharacter.getCharItemManager().updateInventory(); - } - - // Close the window. We're done! - //DONT CLOSE THE WINDOW IF WALL KTHANX - - if (close) - closePlaceAssetWindow(origin); - return true; - } - - // Default method: Validates and places all buildings that do not - // require special treatment in some fashion. - - private boolean placeSingleBuilding(PlayerCharacter playerCharacter, ClientConnection origin, PlaceAssetMsg msg) { - - PlacementInfo buildingList; - Zone serverZone; - - // Retrieve the building details we're placing - - buildingList = msg.getFirstPlacementInfo(); - - serverZone = ZoneManager.findSmallestZone(buildingList.getLoc()); - // Early exit if something went horribly wrong - // with locating the current or zone - - if (serverZone == null) { - Logger.error("Null zone in placeSingleBuilding"); - return false; - } - - // Method checks validation conditions arising when placing - // buildings. Player must be on a city grid, must be - // inner council of the city's guild, etc. - - if (validateBuildingPlacement(serverZone, msg, origin, playerCharacter, buildingList) == false) - return false; // Close window here? - - // Place the building - if (createStructure(playerCharacter, buildingList, serverZone) == null) { - PlaceAssetMsg.sendPlaceAssetError(origin, 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - return false; - } - - return true; - } + private static void closePlaceAssetWindow(ClientConnection origin) { - private boolean placeWarehouse(PlayerCharacter player, ClientConnection origin, PlaceAssetMsg msg) { + // Action type 4 is the server telling the client to + // close the asset placement window. + // This is believed to be a confirmation message to the client + PlaceAssetMsg pam = new PlaceAssetMsg(); + pam.setActionType(4); + Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), pam); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + } - Zone serverZone; - City cityObject; - PlacementInfo buildingList; + // Default method: Validates and places all buildings that do not + // require special treatment in some fashion. - // Retrieve the building details we're placing + private static boolean validateTreeOfLifePlacement(PlayerCharacter playerCharacter, Realm serverRealm, Zone serverZone, + ClientConnection origin, PlaceAssetMsg msg) { - buildingList = msg.getFirstPlacementInfo(); + PlacementInfo placementInfo = msg.getFirstPlacementInfo(); - // Setup working variables we'll need + // Your guild already owns a tree - serverZone = ZoneManager.findSmallestZone(buildingList.getLoc()); + if (playerCharacter.getGuild().getOwnedCity() != null) { + PlaceAssetMsg.sendPlaceAssetError(origin, 1, "Your guild already owns a tree!"); + return false; + } - // Early exit if something went horribly wrong + // Validate that the player is the leader of a guild - if (serverZone == null) - return false; + if (GuildStatusController.isGuildLeader(playerCharacter.getGuildStatus()) == false) { + PlaceAssetMsg.sendPlaceAssetError(origin, 10, ""); // Must be a guild leader + return false; + } - cityObject = City.getCity(serverZone.getPlayerCityUUID()); + // Validate that the player is the leader of a guild + // that is not currently Sovereign *** BUG? Doesn't look right. isGuildLeader()? - // Early exit if something went horribly wrong + if ((playerCharacter.getGuild().getGuildState() != GuildState.Sworn + || playerCharacter.getGuild().getGuildState() != GuildState.Errant) == false) { + PlaceAssetMsg.sendPlaceAssetError(origin, 17, ""); // Your is not an errant or soverign guild + return false; + } - if (cityObject == null){ - PlaceAssetMsg.sendPlaceAssetError(origin, 52, ""); - return false;} + // All trees must be placed within a continent. - // Method checks validation conditions arising when placing - // buildings. Player must be on a city grid, must be - // inner council of the city's guild, etc. + if (!serverZone.isContinent()) { - if (validateCityBuildingPlacement(serverZone, msg, origin, player, buildingList) == false) - return false; + PlaceAssetMsg.sendPlaceAssetError(origin, 69, ""); // Tree must be within a territory + return false; + } - if (cityObject.getWarehouse() != null) { - PlaceAssetMsg.sendPlaceAssetError(origin, 50, ""); //"You can only have one warehouse" - return false; - } + if (serverRealm == null || serverRealm.getCanPlaceCities() == false) { + PlaceAssetMsg.sendPlaceAssetError(origin, 57, playerCharacter.getName()); // No building may be placed within this territory + return false; + } - // Create the warehouse object and it's entry in the database + // Cannot place a tree underwater - if (createWarehouse(player, msg.getFirstPlacementInfo(), serverZone) == false) { - PlaceAssetMsg.sendPlaceAssetError(origin, 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - return false; - } + if (HeightMap.isLocUnderwater(placementInfo.getLoc())) { + PlaceAssetMsg.sendPlaceAssetError(origin, 6, ""); // Cannot place underwater + return false; + } - return true; - } + //Test city not too close to any other zone - private boolean placeSiegeEquip(PlayerCharacter player, ClientConnection origin, PlaceAssetMsg msg) { + if (!ZoneManager.validTreePlacementLoc(serverZone, placementInfo.getLoc().x, placementInfo.getLoc().z)) { + PlaceAssetMsg.sendPlaceAssetError(origin, 39, ""); // Too close to another tree + return false; + } - Zone serverZone; - Building siegeBuilding; - PlacementInfo buildingList; - City serverCity; - Bane bane; + // Validate that Realm is not at it's city limit - // Retrieve the building details we're placing + if (serverRealm.isRealmFull() == true) { + int numCities; + numCities = serverRealm.getNumCities(); + PlaceAssetMsg.sendPlaceAssetError(origin, 58, Integer.toString(numCities)); // This territory is full + return false; + } - buildingList = msg.getFirstPlacementInfo(); + return true; + } - // Setup working variables we'll need + private static boolean validateBuildingPlacement(Zone serverZone, PlaceAssetMsg msg, ClientConnection origin, PlayerCharacter player, PlacementInfo placementInfo) { - serverZone = ZoneManager.findSmallestZone(buildingList.getLoc()); + if (serverZone.isPlayerCity() == false) { + PlaceAssetMsg.sendPlaceAssetError(origin, 52, player.getName()); + return false; + } - // Early exit if something went horribly wrong - // with locating the current city and/or zone + City city = ZoneManager.getCityAtLocation(placementInfo.getLoc()); - if (serverZone == null) { - Logger.error("Error obtaining reference to zone"); - return false; - } + if (player.getGuild().equals(city.getGuild()) == false) { + PlaceAssetMsg.sendPlaceAssetError(origin, 40, player.getName()); + return false; + } - serverCity = ZoneManager.getCityAtLocation(buildingList.getLoc()); + if (city.isLocationOnCityGrid(placementInfo.getLoc()) == false) { + PlaceAssetMsg.sendPlaceAssetError(origin, 41, player.getName()); + return false; + } - // No valid player city found + // Retrieve the building details we're placing - if (serverCity == null || serverCity.getParent().isPlayerCity() == false) { - PlaceAssetMsg.sendPlaceAssetError(origin, 52, ""); // Cannot place outisde a guild zone - return false; - } + if (serverZone.isNPCCity() == true) { + PlaceAssetMsg.sendPlaceAssetError(origin, 15, ""); // Cannot place in a peace zone + return false; + } - // No bane no bow + // Errant guilds cannot place assets - bane = serverCity.getBane(); + if (player.getGuild().getGuildState() == GuildState.Errant) { + PlaceAssetMsg.sendPlaceAssetError(origin, 1, "Only sovereign or sworn guilds may place assets."); + return false; + } - if (bane == null) { - PlaceAssetMsg.sendPlaceAssetError(origin, 66, ""); // There is no bane circle to support this building of war - return false; - } + // Player must be GL or IC of a guild to place buildings. - // Must belong to either attacker or defenders. + if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false && GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false) { + PlaceAssetMsg.sendPlaceAssetError(origin, 10, ""); // You must be a guild leader + return false; + } - if ((player.getGuild().equals(serverCity.getBane().getOwner().getGuild()) == false) - && (player.getGuild().equals(serverCity.getGuild()) == false)) { - PlaceAssetMsg.sendPlaceAssetError(origin, 54, ""); // Must belong to attacker or defender - return false; - } + // Cannot place a building underwater - // Player must be GL or IC of the bane guild to place bow. + if (HeightMap.isLocUnderwater(placementInfo.getLoc())) { + PlaceAssetMsg.sendPlaceAssetError(origin, 6, ""); // Cannot place underwater + return false; + } - if(GuildStatusController.isGuildLeader(player.getGuildStatus()) == false - && GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false) - { - PlaceAssetMsg.sendPlaceAssetError(origin, 10, player.getName()); // You must be a guild leader to place this asset - return false; - } + // Players cannot place buildings in mob zones. - // Attackers cannot place on grid until bane is live + if ((serverZone.isMacroZone() == true) + || (serverZone.getParent().isMacroZone() == true)) { + PlaceAssetMsg.sendPlaceAssetError(origin, 57, player.getName()); // No building may be placed within this territory + return false; + } - if (bane.getSiegePhase() != SiegePhase.WAR && - player.getGuild().equals(serverCity.getBane().getOwner().getGuild()) && - serverCity.isLocationOnCityGrid(buildingList.getLoc())) { - PlaceAssetMsg.sendPlaceAssetError(origin, 53, player.getName()); // Buildings of war cannot be placed around a city grid unless there is an active bane - return false; - } + Realm serverRealm = RealmMap.getRealmAtLocation(player.getLoc()); - // If there is a bane placed, we limit bow placement to 2x the stone rank's worth of attacker assets - // and 1x the tree rank for defenders + // Cannot place buildings on seafloor or other restricted realms - if (validateSiegeLimits(player, origin, serverCity.getBane()) == false) - return false; - - // Collision check (Removes rubble side effect) - - if (placementCollisionCheck(serverZone, origin, buildingList)){ - PlaceAssetMsg.sendPlaceAssetError(origin, 3, ""); // Conflict between proposed assets - return false; - } + if (serverRealm == null || serverRealm.getCanPlaceCities() == false) { + PlaceAssetMsg.sendPlaceAssetError(origin, 57, player.getName()); // No building may be placed within this territory + return false; + } - // Create the siege Building - - siegeBuilding = createStructure(player, msg.getFirstPlacementInfo(), serverZone); - - // Oops something went really wrong + // Cannot place assets on a dead tree - if (siegeBuilding == null) - return false; - - // passes validation: can assign auto-protection to war asset + if ((serverZone.isPlayerCity()) + && (City.getCity(serverZone.getPlayerCityUUID()).getTOL().getRank() == -1)) { + PlaceAssetMsg.sendPlaceAssetError(origin, 1, "Cannot place asset on dead tree until world heals"); + return false; + } - siegeBuilding.setProtectionState(ProtectionState.PROTECTED); - - return true; - } + if (placementCollisionCheck(serverZone, origin, placementInfo)) { + PlaceAssetMsg.sendPlaceAssetError(origin, 3, ""); // Conflict between proposed assets + return false; + } - private boolean validateSiegeLimits(PlayerCharacter playerCharacter, ClientConnection origin, Bane bane) { + return true; + } - City serverCity = bane.getCity(); - HashSet awoList; - HashSet attackerBuildings = new HashSet<>(); - HashSet defenderBuildings = new HashSet<>(); - ; - int maxAttackerAssets = serverCity.getBane().getStone().getRank() * 2; - int maxDefenderAssets = serverCity.getRank(); - - // Count bow for attackers and defenders + private static boolean placementCollisionCheck(Zone serverZone, ClientConnection origin, PlacementInfo placementInfo) { + // Overlap check - awoList = WorldGrid.getObjectsInRangePartial(serverCity, 1000, MBServerStatics.MASK_BUILDING); + for (Building building : serverZone.zoneBuildingSet) { - for (AbstractWorldObject awo : awoList) { - Building building = (Building) awo; - - if (building.getBlueprint() != null) - if (!building.getBlueprint().isSiegeEquip()) - continue; - - if (!building.getLoc().isInsideCircle(serverCity.getLoc(), CityBoundsType.ZONE.extents)) - continue; - - if (building.getGuild() == null) - continue; - - if (building.getGuild().isEmptyGuild()) - continue; - - if (!building.getGuild().equals(serverCity.getGuild()) && !building.getGuild().equals(serverCity.getBane().getOwner().getGuild())) - continue; - if (building.getRank() < 0) { - continue; - } - if (building.getGuild().equals(serverCity.getGuild())) - defenderBuildings.add(building); - - if (building.getGuild().equals(serverCity.getBane().getOwner().getGuild())) - attackerBuildings.add(building); - - } - // Validate bane limits on siege assets - - if (playerCharacter.getGuild().equals(serverCity.getGuild())) { - //defender attempting to place asset - if (defenderBuildings.size() >= maxDefenderAssets) { - PlaceAssetMsg.sendPlaceAssetError(origin, 62, ""); - return false; - } - } - - if (playerCharacter.getGuild().equals(serverCity.getBane().getStone().getGuild())) { - //attacker attempting to place asset - if (attackerBuildings.size() >= maxAttackerAssets) { - PlaceAssetMsg.sendPlaceAssetError(origin, 61, ""); - return false; - } - } - - // Passed validation - - return true; - } - - - private boolean placeTreeOfLife(PlayerCharacter playerCharacter, ClientConnection origin, PlaceAssetMsg msg) { - - Realm serverRealm; - Zone serverZone; - ArrayList cityObjects; // MySql result set - HashMap cityObjectMap = new HashMap<>(); - PlacementInfo treeInfo; - Guild playerNation; - PlacementInfo treePlacement = msg.getFirstPlacementInfo(); - Building treeObject; - City cityObject; - Zone zoneObject; - - // Setup working variables we'll need - - serverRealm = RealmMap.getRealmAtLocation(treePlacement.getLoc()); - serverZone = ZoneManager.findSmallestZone(treePlacement.getLoc()); + if ((building.getBlueprintUUID() != 0) && (Bounds.collide(placementInfo, building) == true)) { - // Early exit if something went horribly wrong - // with locating the current realm and/or zone + // Ignore and remove from simulation if we are placing over rubble - if (serverRealm == null || serverZone == null) - return false; + if (building.getRank() == -1) { - // Method checks validation conditions arising when placing - // trees + if ((building.getBlueprintUUID() != 0) + && (building.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE)) { + Shrine.RemoveShrineFromCacheByBuilding(building); + if (building.getCity() != null) { - if (validateTreeOfLifePlacement(playerCharacter, serverRealm, serverZone, origin, msg) == false) - return false; + } + } - // Retrieve tree info for the w value it's passing. + building.removeFromCache(); + WorldGrid.RemoveWorldObject(building); + WorldGrid.removeObject(building); + building.getParentZone().zoneBuildingSet.remove(building); + if (building.getBlueprint() != null && building.getBlueprint().getBuildingGroup().equals(BuildingGroup.BARRACK)) { + building.RemoveFromBarracksList(); + } + continue; + } - treeInfo = msg.getFirstPlacementInfo(); - if (treeInfo == null) { - PlaceAssetMsg.sendPlaceAssetError(origin, 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - return false; - } + PlaceAssetMsg.sendPlaceAssetError(origin, 3, ""); // Conflict between proposed assets + return true; + } + } + return false; + } - Vector3fImmutable plantLoc = new Vector3fImmutable(treeInfo.getLoc().x, - HeightMap.getWorldHeight(treeInfo.getLoc()), - treeInfo.getLoc().z); + private static boolean validateCityBuildingPlacement(Zone serverZone, PlaceAssetMsg msg, ClientConnection origin, PlayerCharacter player, PlacementInfo buildingInfo) { - cityObjects = DbManager.CityQueries.CREATE_CITY(playerCharacter.getObjectUUID(), serverZone.getObjectUUID(), - serverRealm.getRealmID(), - plantLoc.x - serverZone.getAbsX(), plantLoc.y, - plantLoc.z - serverZone.getAbsZ(), treeInfo.getRot().y, treeInfo.getW(), playerCharacter.getGuild().getName(), LocalDateTime.now()); + // Perform shared common validation first - // Uh oh! - if (cityObjects == null || cityObjects.isEmpty()) { - PlaceAssetMsg.sendPlaceAssetError(origin, 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - return false; - } + if (validateBuildingPlacement(serverZone, msg, origin, player, buildingInfo) == false) + return false; - // Assign our worker variables after figuring out what - // is what in the result set. + // Must be a player city - for (AbstractGameObject gameObject : cityObjects) - cityObjectMap.put(gameObject.getObjectType(), gameObject); + if (serverZone.isPlayerCity() == false) { + PlaceAssetMsg.sendPlaceAssetError(origin, 41, player.getName()); // Cannot place outside a guild zone + return false; + } - treeObject = (Building) cityObjectMap.get(GameObjectType.Building); - treeObject.runAfterLoad();; - cityObject = (City) cityObjectMap.get(GameObjectType.City); - zoneObject = (Zone) cityObjectMap.get(GameObjectType.Zone); + //Test zone has a city object - // not allowed to plant a tree if ur not an errant guild. - // Desub from any previous nation. - // This should be done automatically in a method inside Guild *** Refactor - // Player is now a Sovereign guild, configure them as such. + City city = City.getCity(serverZone.getPlayerCityUUID()); - playerCharacter.getGuild().setNation(playerCharacter.getGuild()); - playerNation = playerCharacter.getGuild(); - playerNation.setGuildState(GuildState.Sovereign); + if (city == null) { + PlaceAssetMsg.sendPlaceAssetError(origin, 52, ""); //"no city to associate asset with" + return false; + } - // Link the zone with the city and then add - // to the appropriate hash tables and cache + // City assets must be placed on the city grid - zoneObject.setPlayerCity(true); + if (!city.isLocationOnCityGrid(buildingInfo.getLoc())) { + PlaceAssetMsg.sendPlaceAssetError(origin, 52, ""); + return false; + } - if (zoneObject.getParent() != null) - zoneObject.getParent().addNode(zoneObject); //add as child to parent + // Make sure it's not an errant tree - ZoneManager.addZone(zoneObject.getObjectUUID(), zoneObject); - ZoneManager.addPlayerCityZone(zoneObject); - serverZone.addNode(zoneObject); + if ((city.getGuild() == null || city.getGuild().isEmptyGuild() == true)) { + PlaceAssetMsg.sendPlaceAssetError(origin, 18, ""); //"There are no guild trees to be found" + return false; + } - zoneObject.generateWorldAltitude(); + //Test player is in correct guild to place buildings - cityObject.setParent(zoneObject); - cityObject.setObjectTypeMask(MBServerStatics.MASK_CITY); // *** Refactor : should have it already - //Link the tree of life with the new zone + if (!player.isCSR) + if (player.getGuild().getObjectUUID() != city.getGuild().getObjectUUID()) { + PlaceAssetMsg.sendPlaceAssetError(origin, 9, ""); //You must be a guild member to place this asset + return false; + } + return true; + } - treeObject.setObjectTypeMask(MBServerStatics.MASK_BUILDING); - treeObject.setParentZone(zoneObject); - MaintenanceManager.setMaintDateTime(treeObject, LocalDateTime.now().plusDays(7)); + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - // Update guild binds and tags - //load the new city on the clients + // Member variable declaration - CityZoneMsg czm = new CityZoneMsg(1, treeObject.getLoc().x, treeObject.getLoc().y, treeObject.getLoc().z, cityObject.getCityName(), zoneObject, Enum.CityBoundsType.ZONE.extents, Enum.CityBoundsType.ZONE.extents); - DispatchMessage.dispatchMsgToAll(czm); + PlaceAssetMsg msg; + Boolean buildingCreated; - GuildManager.updateAllGuildBinds(playerNation, cityObject); - GuildManager.updateAllGuildTags(playerNation); + // Character location and session - // Send all the cities to the clients? - // *** Refactor : figure out how to send like, one? + PlayerCharacter playerCharacter; + PlacementInfo buildingList; + Blueprint buildingBlueprint; + + // Tell compiler it's ok to trust us and parse + // what we need from the message structure + + msg = (PlaceAssetMsg) baseMsg; + + // Action type 3 is a client requesting to place an object + // For all other action types let's just early exit + + if (msg.getActionType() != CLIENTREQ_NEWBUILDING) + return true; + + // assign our character + + playerCharacter = SessionManager.getPlayerCharacter(origin); + + // We need to figure out what exactly the player is attempting + // to place, as some objects like tol/bane/walls are edge cases. + // So let's get the first item in their list. + + buildingList = msg.getFirstPlacementInfo(); + + // Early exit if null building list. + + if (buildingList == null) { + Logger.error("Player " + playerCharacter.getCombinedName() + + " null building list on deed use"); + PlaceAssetMsg.sendPlaceAssetError(origin, 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + closePlaceAssetWindow(origin); + return true; + } + + Item contract = null; + + for (Item inventoryItem : playerCharacter.getInventory()) { + if (inventoryItem.getItemBase().getUseID() == buildingList.getBlueprintUUID()) { + contract = inventoryItem; + break; + } + } + + // Grab the blueprint from the uuid in the message + + buildingBlueprint = Blueprint.getBlueprint(buildingList.getBlueprintUUID()); + + // Early exit if blueprint can't be retrieved for the object. + + if (buildingBlueprint == null) { + Logger.error("Player " + playerCharacter.getCombinedName() + + " null blueprint UUID: " + buildingList.getBlueprintUUID() + " on deed use"); + PlaceAssetMsg.sendPlaceAssetError(origin, 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + closePlaceAssetWindow(origin); + return true; + } + + // Let's now attempt to place the building + buildingCreated = false; + + // Many buildings have particular validation and + // post-creation cleanup requirements. + + boolean close = true; + lock.writeLock().lock(); + boolean isSiege = false; + try { + switch (buildingBlueprint.getBuildingGroup()) { + + case TOL: + if (contract == null) + break; + buildingCreated = placeTreeOfLife(playerCharacter, origin, msg); + break; + case WAREHOUSE: + if (contract == null) + break; + if (!playerCharacter.getCharItemManager().doesCharOwnThisItem(contract.getObjectUUID())) + break; + buildingCreated = placeWarehouse(playerCharacter, origin, msg); + break; + case SIEGETENT: + case BULWARK: + if (contract == null) + break; + if (!playerCharacter.getCharItemManager().doesCharOwnThisItem(contract.getObjectUUID())) + break; + buildingCreated = placeSiegeEquip(playerCharacter, origin, msg); + break; + case SPIRE: + if (contract == null) + break; + if (!playerCharacter.getCharItemManager().doesCharOwnThisItem(contract.getObjectUUID())) + break; + buildingCreated = placeSpire(playerCharacter, origin, msg); + break; + case SHRINE: + if (contract == null) + break; + if (!playerCharacter.getCharItemManager().doesCharOwnThisItem(contract.getObjectUUID())) + break; + buildingCreated = placeShrine(playerCharacter, origin, msg); + break; + case BARRACK: + if (contract == null) + break; + if (!playerCharacter.getCharItemManager().doesCharOwnThisItem(contract.getObjectUUID())) + break; + buildingCreated = placeBarrack(playerCharacter, origin, msg); + break; + case WALLSTRAIGHT: + case WALLCORNER: + case SMALLGATE: + case ARTYTOWER: + case WALLSTAIRS: + case WALLSTRAIGHTTOWER: + buildingCreated = placeCityWalls(playerCharacter, origin, msg); + close = false; + break; + default: + if (contract == null) + break; + if (!playerCharacter.getCharItemManager().doesCharOwnThisItem(contract.getObjectUUID())) + break; + buildingCreated = placeSingleBuilding(playerCharacter, origin, msg); + break; + } + } catch (Exception e) { + Logger.error("PlaceAssetHandler", e.getMessage()); + e.printStackTrace(); + } finally { + lock.writeLock().unlock(); + } + + // Update the player's last contract (What is this used for?) + + playerCharacter.setLastContract(msg.getContractID()); + + // Remove the appropriate deed. + if (buildingCreated == true) + if (contract != null) { + playerCharacter.getCharItemManager().delete(contract); + playerCharacter.getCharItemManager().updateInventory(); + } + + // Close the window. We're done! + //DONT CLOSE THE WINDOW IF WALL KTHANX + + if (close) + closePlaceAssetWindow(origin); + return true; + } + + private boolean placeSingleBuilding(PlayerCharacter playerCharacter, ClientConnection origin, PlaceAssetMsg msg) { + + PlacementInfo buildingList; + Zone serverZone; + + // Retrieve the building details we're placing + + buildingList = msg.getFirstPlacementInfo(); + + serverZone = ZoneManager.findSmallestZone(buildingList.getLoc()); + // Early exit if something went horribly wrong + // with locating the current or zone + + if (serverZone == null) { + Logger.error("Null zone in placeSingleBuilding"); + return false; + } + + // Method checks validation conditions arising when placing + // buildings. Player must be on a city grid, must be + // inner council of the city's guild, etc. + + if (validateBuildingPlacement(serverZone, msg, origin, playerCharacter, buildingList) == false) + return false; // Close window here? + + // Place the building + if (createStructure(playerCharacter, buildingList, serverZone) == null) { + PlaceAssetMsg.sendPlaceAssetError(origin, 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + return false; + } + + return true; + } + + private boolean placeWarehouse(PlayerCharacter player, ClientConnection origin, PlaceAssetMsg msg) { - City.lastCityUpdate = System.currentTimeMillis(); - WorldGrid.addObject(treeObject, playerCharacter); + Zone serverZone; + City cityObject; + PlacementInfo buildingList; - serverRealm.addCity(cityObject.getObjectUUID()); - playerNation.setCityUUID(cityObject.getObjectUUID()); + // Retrieve the building details we're placing - // Bypass warehouse entry if we're an admin + buildingList = msg.getFirstPlacementInfo(); - if (playerCharacter.getAccount().status.equals(AccountStatus.ADMIN)) - return true; + // Setup working variables we'll need - // Push this event to the data warehouse + serverZone = ZoneManager.findSmallestZone(buildingList.getLoc()); - CityRecord cityRecord = CityRecord.borrow(cityObject, RecordEventType.CREATE); - DataWarehouse.pushToWarehouse(cityRecord); + // Early exit if something went horribly wrong - return true; - } + if (serverZone == null) + return false; - private boolean placeSpire(PlayerCharacter playerCharacter, ClientConnection origin, PlaceAssetMsg msg) { + cityObject = City.getCity(serverZone.getPlayerCityUUID()); - Zone serverZone; - Building spireBuilding; - Blueprint blueprint; - City cityObject; - PlacementInfo buildingList; + // Early exit if something went horribly wrong - // Setup working variables we'll need + if (cityObject == null) { + PlaceAssetMsg.sendPlaceAssetError(origin, 52, ""); + return false; + } - buildingList = msg.getFirstPlacementInfo(); + // Method checks validation conditions arising when placing + // buildings. Player must be on a city grid, must be + // inner council of the city's guild, etc. - serverZone = ZoneManager.findSmallestZone(buildingList.getLoc()); + if (validateCityBuildingPlacement(serverZone, msg, origin, player, buildingList) == false) + return false; - // Early exit if something went horribly wrong - // with locating the current realm and/or city + if (cityObject.getWarehouse() != null) { + PlaceAssetMsg.sendPlaceAssetError(origin, 50, ""); //"You can only have one warehouse" + return false; + } - if (serverZone == null) - return false; + // Create the warehouse object and it's entry in the database - cityObject = City.getCity(serverZone.getPlayerCityUUID()); + if (createWarehouse(player, msg.getFirstPlacementInfo(), serverZone) == false) { + PlaceAssetMsg.sendPlaceAssetError(origin, 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + return false; + } - if (cityObject == null) - return false; + return true; + } - // Method checks validation conditions arising when placing - // buildings. Player must be on a city grid, must be - // inner council of the city's guild, etc. + private boolean placeSiegeEquip(PlayerCharacter player, ClientConnection origin, PlaceAssetMsg msg) { - if (validateCityBuildingPlacement(serverZone, msg, origin, playerCharacter, buildingList) == false) - return false; + Zone serverZone; + Building siegeBuilding; + PlacementInfo buildingList; + City serverCity; + Bane bane; - // Loop through all buildings in this city looking for a spire of the. - // same type we are placing. There can be only one of each type + // Retrieve the building details we're placing - int spireCount = 0; + buildingList = msg.getFirstPlacementInfo(); - blueprint = Blueprint.getBlueprint(msg.getFirstPlacementInfo().getBlueprintUUID()); + // Setup working variables we'll need - for (Building building : serverZone.zoneBuildingSet) { + serverZone = ZoneManager.findSmallestZone(buildingList.getLoc()); - if (building.getBlueprint().getBuildingGroup() == BuildingGroup.SPIRE) { + // Early exit if something went horribly wrong + // with locating the current city and/or zone - if (building.getBlueprintUUID() == blueprint.getMeshForRank(0)) { - PlaceAssetMsg.sendPlaceAssetError(origin, 46, ""); // "Spire of that type exists" - return false; - } - spireCount++; - } - } + if (serverZone == null) { + Logger.error("Error obtaining reference to zone"); + return false; + } - // Too many spires for this tree's rank? + serverCity = ZoneManager.getCityAtLocation(buildingList.getLoc()); - if (spireCount >= Blueprint.getMaxShrines(cityObject.getTOL().getRank())) { - PlaceAssetMsg.sendPlaceAssetError(origin, 45, ""); //Tree cannot support anymore spires - return false; - } + // No valid player city found - // Create the spire + if (serverCity == null || serverCity.getParent().isPlayerCity() == false) { + PlaceAssetMsg.sendPlaceAssetError(origin, 52, ""); // Cannot place outisde a guild zone + return false; + } - spireBuilding = createStructure(playerCharacter, msg.getFirstPlacementInfo(), serverZone); - return spireBuilding != null; - } + // No bane no bow - private boolean placeShrine(PlayerCharacter playerCharacter, ClientConnection origin, PlaceAssetMsg msg) { + bane = serverCity.getBane(); - Zone serverZone; - Blueprint blueprint; - City cityObject; - PlacementInfo buildingList; + if (bane == null) { + PlaceAssetMsg.sendPlaceAssetError(origin, 66, ""); // There is no bane circle to support this building of war + return false; + } - // Setup working variables we'll need - buildingList = msg.getFirstPlacementInfo(); + // Must belong to either attacker or defenders. - serverZone = ZoneManager.findSmallestZone(buildingList.getLoc()); + if ((player.getGuild().equals(serverCity.getBane().getOwner().getGuild()) == false) + && (player.getGuild().equals(serverCity.getGuild()) == false)) { + PlaceAssetMsg.sendPlaceAssetError(origin, 54, ""); // Must belong to attacker or defender + return false; + } - // Early exit if something went horribly wrong - // with locating the current realm and/or zone - if (serverZone == null) - return false; + // Player must be GL or IC of the bane guild to place bow. - // Method checks validation conditions arising when placing - // buildings. Player must be on a city grid, must be - // inner council of the city's guild, etc. + if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false + && GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false) { + PlaceAssetMsg.sendPlaceAssetError(origin, 10, player.getName()); // You must be a guild leader to place this asset + return false; + } - if (validateCityBuildingPlacement(serverZone, msg, origin, playerCharacter, buildingList) == false) - return false; + // Attackers cannot place on grid until bane is live - // Loop through all buildings in this city looking for a shrine of the. - // same type we are placing. There can be only one of each type + if (bane.getSiegePhase() != SiegePhase.WAR && + player.getGuild().equals(serverCity.getBane().getOwner().getGuild()) && + serverCity.isLocationOnCityGrid(buildingList.getLoc())) { + PlaceAssetMsg.sendPlaceAssetError(origin, 53, player.getName()); // Buildings of war cannot be placed around a city grid unless there is an active bane + return false; + } - int shrineCount = 0; + // If there is a bane placed, we limit bow placement to 2x the stone rank's worth of attacker assets + // and 1x the tree rank for defenders - cityObject = City.getCity(serverZone.getPlayerCityUUID()); + if (validateSiegeLimits(player, origin, serverCity.getBane()) == false) + return false; - // Cannot place shrine in abandoned city. Shrines must be owned - // by the tol owner not the person placing them. + // Collision check (Removes rubble side effect) - if (cityObject.getTOL().getOwnerUUID() == 0) { - PlaceAssetMsg.sendPlaceAssetError(origin, 42, ""); //Tree cannot support anymore shrines - return false; - } + if (placementCollisionCheck(serverZone, origin, buildingList)) { + PlaceAssetMsg.sendPlaceAssetError(origin, 3, ""); // Conflict between proposed assets + return false; + } - blueprint = Blueprint.getBlueprint(msg.getFirstPlacementInfo().getBlueprintUUID()); + // Create the siege Building - if (blueprint == null){ - return false; - } + siegeBuilding = createStructure(player, msg.getFirstPlacementInfo(), serverZone); - for (Building building : serverZone.zoneBuildingSet) { - if (building.getBlueprint() == null) - continue; + // Oops something went really wrong - if (building.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE) { - if (building.getBlueprintUUID() == blueprint.getMeshForRank(0)) { - PlaceAssetMsg.sendPlaceAssetError(origin, 43, ""); // "shrine of that type exists" - return false; - } - shrineCount++; - } - } + if (siegeBuilding == null) + return false; - // Too many shrines for this tree's rank? + // passes validation: can assign auto-protection to war asset - if (shrineCount >= Blueprint.getMaxShrines(cityObject.getTOL().getRank())) { - PlaceAssetMsg.sendPlaceAssetError(origin, 42, ""); //Tree cannot support anymore shrines - return false; - } + siegeBuilding.setProtectionState(ProtectionState.PROTECTED); - // Create the shrine + return true; + } - return createShrine((PlayerCharacter)cityObject.getTOL().getOwner(), msg.getFirstPlacementInfo(), serverZone); - } + private boolean validateSiegeLimits(PlayerCharacter playerCharacter, ClientConnection origin, Bane bane) { - private boolean placeBarrack(PlayerCharacter playerCharacter, ClientConnection origin, PlaceAssetMsg msg) { + City serverCity = bane.getCity(); + HashSet awoList; + HashSet attackerBuildings = new HashSet<>(); + HashSet defenderBuildings = new HashSet<>(); + ; + int maxAttackerAssets = serverCity.getBane().getStone().getRank() * 2; + int maxDefenderAssets = serverCity.getRank(); - Zone serverZone; - City cityObject; - PlacementInfo buildingList; + // Count bow for attackers and defenders - // Setup working variables we'll need - buildingList = msg.getFirstPlacementInfo(); + awoList = WorldGrid.getObjectsInRangePartial(serverCity, 1000, MBServerStatics.MASK_BUILDING); - serverZone = ZoneManager.findSmallestZone(buildingList.getLoc()); + for (AbstractWorldObject awo : awoList) { + Building building = (Building) awo; - // Early exit if something went horribly wrong - // with locating the current realm and/or zone + if (building.getBlueprint() != null) + if (!building.getBlueprint().isSiegeEquip()) + continue; - if (serverZone == null) - return false; + if (!building.getLoc().isInsideCircle(serverCity.getLoc(), CityBoundsType.ZONE.extents)) + continue; - // Method checks validation conditions arising when placing - // buildings. Player must be on a city grid, must be - // inner council of the city's guild, etc. + if (building.getGuild() == null) + continue; - if (validateCityBuildingPlacement(serverZone, msg, origin, playerCharacter, buildingList) == false) - return false; + if (building.getGuild().isEmptyGuild()) + continue; - // Loop through all buildings in this city counting barracks . + if (!building.getGuild().equals(serverCity.getGuild()) && !building.getGuild().equals(serverCity.getBane().getOwner().getGuild())) + continue; + if (building.getRank() < 0) { + continue; + } + if (building.getGuild().equals(serverCity.getGuild())) + defenderBuildings.add(building); - int barracksCount = 0; + if (building.getGuild().equals(serverCity.getBane().getOwner().getGuild())) + attackerBuildings.add(building); - cityObject = City.getCity(serverZone.getPlayerCityUUID()); + } + // Validate bane limits on siege assets - // Cannot place barracks in abandoned city. + if (playerCharacter.getGuild().equals(serverCity.getGuild())) { + //defender attempting to place asset + if (defenderBuildings.size() >= maxDefenderAssets) { + PlaceAssetMsg.sendPlaceAssetError(origin, 62, ""); + return false; + } + } - if (cityObject.getTOL().getOwnerUUID() == 0) { - PlaceAssetMsg.sendPlaceAssetError(origin, 42, ""); //Tree cannot support anymore shrines - return false; - } + if (playerCharacter.getGuild().equals(serverCity.getBane().getStone().getGuild())) { + //attacker attempting to place asset + if (attackerBuildings.size() >= maxAttackerAssets) { + PlaceAssetMsg.sendPlaceAssetError(origin, 61, ""); + return false; + } + } - for (Building building : serverZone.zoneBuildingSet) { - if (building.getBlueprint().getBuildingGroup() == BuildingGroup.BARRACK) - barracksCount++; - } + // Passed validation - // Too many shrines for this tree's rank? + return true; + } - if (barracksCount >= cityObject.getTOL().getRank()) { - PlaceAssetMsg.sendPlaceAssetError(origin, 47, ""); //Tree cannot support anymore shrines - return false; - } + private boolean placeTreeOfLife(PlayerCharacter playerCharacter, ClientConnection origin, PlaceAssetMsg msg) { - // Create the shrine + Realm serverRealm; + Zone serverZone; + ArrayList cityObjects; // MySql result set + HashMap cityObjectMap = new HashMap<>(); + PlacementInfo treeInfo; + Guild playerNation; + PlacementInfo treePlacement = msg.getFirstPlacementInfo(); + Building treeObject; + City cityObject; + Zone zoneObject; - return createBarracks((PlayerCharacter)cityObject.getTOL().getOwner(), msg.getFirstPlacementInfo(), serverZone); - } + // Setup working variables we'll need - private boolean placeCityWalls(PlayerCharacter player, ClientConnection origin, PlaceAssetMsg msg) { + serverRealm = RealmMap.getRealmAtLocation(treePlacement.getLoc()); + serverZone = ZoneManager.findSmallestZone(treePlacement.getLoc()); - // Member variables + // Early exit if something went horribly wrong + // with locating the current realm and/or zone - Zone serverZone; - City cityObject; - int placementCost = 0; - CharacterItemManager itemMan; - Item goldItem; - Building wallPiece; + if (serverRealm == null || serverZone == null) + return false; - // Setup working variables we'll need + // Method checks validation conditions arising when placing + // trees - serverZone = ZoneManager.findSmallestZone(player.getLoc()); + if (validateTreeOfLifePlacement(playerCharacter, serverRealm, serverZone, origin, msg) == false) + return false; - // Early exit if something went horribly wrong + // Retrieve tree info for the w value it's passing. - if (serverZone == null) - return false; + treeInfo = msg.getFirstPlacementInfo(); + if (treeInfo == null) { + PlaceAssetMsg.sendPlaceAssetError(origin, 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + return false; + } - if (player.getCharItemManager().getGoldTrading() > 0){ - ErrorPopupMsg.sendErrorPopup(player, 195); - return false; - } + Vector3fImmutable plantLoc = new Vector3fImmutable(treeInfo.getLoc().x, + HeightMap.getWorldHeight(treeInfo.getLoc()), + treeInfo.getLoc().z); + cityObjects = DbManager.CityQueries.CREATE_CITY(playerCharacter.getObjectUUID(), serverZone.getObjectUUID(), + serverRealm.getRealmID(), + plantLoc.x - serverZone.getAbsX(), plantLoc.y, + plantLoc.z - serverZone.getAbsZ(), treeInfo.getRot().y, treeInfo.getW(), playerCharacter.getGuild().getName(), LocalDateTime.now()); - // Method checks validation conditions arising when placing - // buildings. Player must be on a city grid, must be - // inner council of the city's guild, etc. + // Uh oh! + if (cityObjects == null || cityObjects.isEmpty()) { + PlaceAssetMsg.sendPlaceAssetError(origin, 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + return false; + } - if (validateCityBuildingPlacement(serverZone, msg, origin, player, msg.getFirstPlacementInfo()) == false) - return false; + // Assign our worker variables after figuring out what + // is what in the result set. - cityObject = City.getCity(serverZone.getPlayerCityUUID()); + for (AbstractGameObject gameObject : cityObjects) + cityObjectMap.put(gameObject.getObjectType(), gameObject); - // We need to be able to access how much gold a character is carrying + treeObject = (Building) cityObjectMap.get(GameObjectType.Building); + treeObject.runAfterLoad(); + ; + cityObject = (City) cityObjectMap.get(GameObjectType.City); + zoneObject = (Zone) cityObjectMap.get(GameObjectType.Zone); - itemMan = player.getCharItemManager(); + // not allowed to plant a tree if ur not an errant guild. + // Desub from any previous nation. + // This should be done automatically in a method inside Guild *** Refactor + // Player is now a Sovereign guild, configure them as such. - if (itemMan == null) + playerCharacter.getGuild().setNation(playerCharacter.getGuild()); + playerNation = playerCharacter.getGuild(); + playerNation.setGuildState(GuildState.Sovereign); - return false; + // Link the zone with the city and then add + // to the appropriate hash tables and cache - goldItem = itemMan.getGoldInventory(); + zoneObject.setPlayerCity(true); - // Grab list of walls we're placing + if (zoneObject.getParent() != null) + zoneObject.getParent().addNode(zoneObject); //add as child to parent - ArrayList walls = msg.getPlacementInfo(); + ZoneManager.addZone(zoneObject.getObjectUUID(), zoneObject); + ZoneManager.addPlayerCityZone(zoneObject); + serverZone.addNode(zoneObject); - // Character must be able to afford walls + zoneObject.generateWorldAltitude(); - for (PlacementInfo wall : walls) { - placementCost += PlaceAssetMsg.getWallCost(wall.getBlueprintUUID()); - } + cityObject.setParent(zoneObject); + cityObject.setObjectTypeMask(MBServerStatics.MASK_CITY); // *** Refactor : should have it already + //Link the tree of life with the new zone - // Early exit if not enough gold in character's inventory to place walls + treeObject.setObjectTypeMask(MBServerStatics.MASK_BUILDING); + treeObject.setParentZone(zoneObject); + MaintenanceManager.setMaintDateTime(treeObject, LocalDateTime.now().plusDays(7)); - if (placementCost > goldItem.getNumOfItems()) { - PlaceAssetMsg.sendPlaceAssetError(origin, 28, ""); // Not enough gold - return false; - } + // Update guild binds and tags + //load the new city on the clients - placementCost = 0; // reset placement cost for fix bug with wall pieces somethings not taking gold out if forced an error. + CityZoneMsg czm = new CityZoneMsg(1, treeObject.getLoc().x, treeObject.getLoc().y, treeObject.getLoc().z, cityObject.getCityName(), zoneObject, Enum.CityBoundsType.ZONE.extents, Enum.CityBoundsType.ZONE.extents); + DispatchMessage.dispatchMsgToAll(czm); + GuildManager.updateAllGuildBinds(playerNation, cityObject); + GuildManager.updateAllGuildTags(playerNation); - // Overlap check and wall deed verifications - for (PlacementInfo wall : walls) { + // Send all the cities to the clients? + // *** Refactor : figure out how to send like, one? - if (Blueprint.isMeshWallPiece(wall.getBlueprintUUID()) == false) { - PlaceAssetMsg.sendPlaceAssetError(origin, 48, ""); //"Assets (except walls) must be placed one at a time" - continue; - } + City.lastCityUpdate = System.currentTimeMillis(); + WorldGrid.addObject(treeObject, playerCharacter); - // Ignore wall pieces not on the city grid - if (cityObject.isLocationOnCityGrid(wall.getLoc()) == false) { - PlaceAssetMsg.sendPlaceAssetError(origin, 1, "Asset " + cityObject.getName() + " not on citygrid"); - continue; - } + serverRealm.addCity(cityObject.getObjectUUID()); + playerNation.setCityUUID(cityObject.getObjectUUID()); - // Does this wall collide with any other building? + // Bypass warehouse entry if we're an admin - for (Building building : serverZone.zoneBuildingSet) { + if (playerCharacter.getAccount().status.equals(AccountStatus.ADMIN)) + return true; + // Push this event to the data warehouse - //TODO Clean up collision with placementInfo. don't need to create the same placementinfo bounds for collision checks on each building. - if ((building.getBlueprintUUID() != 0) && (Bounds.collide(wall, building) == true)) { + CityRecord cityRecord = CityRecord.borrow(cityObject, RecordEventType.CREATE); + DataWarehouse.pushToWarehouse(cityRecord); - if (building.getRank() == -1) { - building.removeFromCache(); - WorldGrid.RemoveWorldObject(building); - WorldGrid.removeObject(building); - building.getParentZone().getParent().zoneBuildingSet.remove(building); - if(building.getBlueprint() != null && building.getBlueprint().getBuildingGroup().equals(BuildingGroup.BARRACK)){ - building.RemoveFromBarracksList(); - } - continue; - } - // remove gold from walls already placed before returning. + return true; + } - PlaceAssetMsg.sendPlaceAssetError(origin, 3, building.getName()); //"Conflict between assets" - return false; - } - } - placementCost = PlaceAssetMsg.getWallCost(wall.getBlueprintUUID()); + // Method validates the location we have selected for our new city - if (!itemMan.modifyInventoryGold(-placementCost)){ - ChatManager.chatSystemInfo(player, player.getFirstName() + " can't has free moneys! no for real.. Thor.. seriously... I didnt fix it because you getting laid isnt important enough for me."); - return false; - } - // Attempt to place wall piece + private boolean placeSpire(PlayerCharacter playerCharacter, ClientConnection origin, PlaceAssetMsg msg) { - wallPiece = createStructure(player, wall, serverZone); + Zone serverZone; + Building spireBuilding; + Blueprint blueprint; + City cityObject; + PlacementInfo buildingList; - if (wallPiece == null) { - PlaceAssetMsg.sendPlaceAssetError(origin, 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - continue; - } + // Setup working variables we'll need - // walls are auto protected - wallPiece.setProtectionState(ProtectionState.PROTECTED); - PlaceAssetMsg.sendPlaceAssetConfirmWall(origin,serverZone); + buildingList = msg.getFirstPlacementInfo(); - } + serverZone = ZoneManager.findSmallestZone(buildingList.getLoc()); - // Deduct gold from character's inventory + // Early exit if something went horribly wrong + // with locating the current realm and/or city + if (serverZone == null) + return false; - return true; - } + cityObject = City.getCity(serverZone.getPlayerCityUUID()); - private static void closePlaceAssetWindow(ClientConnection origin) { + if (cityObject == null) + return false; - // Action type 4 is the server telling the client to - // close the asset placement window. - // This is believed to be a confirmation message to the client - PlaceAssetMsg pam = new PlaceAssetMsg(); - pam.setActionType(4); - Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), pam); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } + // Method checks validation conditions arising when placing + // buildings. Player must be on a city grid, must be + // inner council of the city's guild, etc. - // Method validates the location we have selected for our new city + if (validateCityBuildingPlacement(serverZone, msg, origin, playerCharacter, buildingList) == false) + return false; - private static boolean validateTreeOfLifePlacement(PlayerCharacter playerCharacter, Realm serverRealm, Zone serverZone, - ClientConnection origin, PlaceAssetMsg msg) { + // Loop through all buildings in this city looking for a spire of the. + // same type we are placing. There can be only one of each type - PlacementInfo placementInfo = msg.getFirstPlacementInfo(); + int spireCount = 0; - // Your guild already owns a tree + blueprint = Blueprint.getBlueprint(msg.getFirstPlacementInfo().getBlueprintUUID()); - if (playerCharacter.getGuild().getOwnedCity() != null) { - PlaceAssetMsg.sendPlaceAssetError(origin, 1, "Your guild already owns a tree!"); - return false; - } + for (Building building : serverZone.zoneBuildingSet) { - // Validate that the player is the leader of a guild + if (building.getBlueprint().getBuildingGroup() == BuildingGroup.SPIRE) { - if (GuildStatusController.isGuildLeader(playerCharacter.getGuildStatus()) == false) { - PlaceAssetMsg.sendPlaceAssetError(origin, 10, ""); // Must be a guild leader - return false; - } + if (building.getBlueprintUUID() == blueprint.getMeshForRank(0)) { + PlaceAssetMsg.sendPlaceAssetError(origin, 46, ""); // "Spire of that type exists" + return false; + } + spireCount++; + } + } - // Validate that the player is the leader of a guild - // that is not currently Sovereign *** BUG? Doesn't look right. isGuildLeader()? + // Too many spires for this tree's rank? - if ((playerCharacter.getGuild().getGuildState() != GuildState.Sworn - || playerCharacter.getGuild().getGuildState() != GuildState.Errant) == false) { - PlaceAssetMsg.sendPlaceAssetError(origin, 17, ""); // Your is not an errant or soverign guild - return false; - } + if (spireCount >= Blueprint.getMaxShrines(cityObject.getTOL().getRank())) { + PlaceAssetMsg.sendPlaceAssetError(origin, 45, ""); //Tree cannot support anymore spires + return false; + } - // All trees must be placed within a continent. + // Create the spire - if (!serverZone.isContinent()) { + spireBuilding = createStructure(playerCharacter, msg.getFirstPlacementInfo(), serverZone); + return spireBuilding != null; + } - PlaceAssetMsg.sendPlaceAssetError(origin, 69, ""); // Tree must be within a territory - return false; - } + private boolean placeShrine(PlayerCharacter playerCharacter, ClientConnection origin, PlaceAssetMsg msg) { - if (serverRealm == null || serverRealm.getCanPlaceCities() == false) { - PlaceAssetMsg.sendPlaceAssetError(origin, 57, playerCharacter.getName()); // No building may be placed within this territory - return false; - } + Zone serverZone; + Blueprint blueprint; + City cityObject; + PlacementInfo buildingList; - // Cannot place a tree underwater + // Setup working variables we'll need + buildingList = msg.getFirstPlacementInfo(); - if (HeightMap.isLocUnderwater(placementInfo.getLoc())) { - PlaceAssetMsg.sendPlaceAssetError(origin, 6, ""); // Cannot place underwater - return false; - } + serverZone = ZoneManager.findSmallestZone(buildingList.getLoc()); - //Test city not too close to any other zone + // Early exit if something went horribly wrong + // with locating the current realm and/or zone + if (serverZone == null) + return false; - if (!ZoneManager.validTreePlacementLoc(serverZone, placementInfo.getLoc().x, placementInfo.getLoc().z)) { - PlaceAssetMsg.sendPlaceAssetError(origin, 39, ""); // Too close to another tree - return false; - } + // Method checks validation conditions arising when placing + // buildings. Player must be on a city grid, must be + // inner council of the city's guild, etc. - // Validate that Realm is not at it's city limit + if (validateCityBuildingPlacement(serverZone, msg, origin, playerCharacter, buildingList) == false) + return false; - if (serverRealm.isRealmFull() == true) { - int numCities; - numCities = serverRealm.getNumCities(); - PlaceAssetMsg.sendPlaceAssetError(origin, 58, Integer.toString(numCities)); // This territory is full - return false; - } + // Loop through all buildings in this city looking for a shrine of the. + // same type we are placing. There can be only one of each type - return true; - } + int shrineCount = 0; - private Building createStructure(PlayerCharacter playerCharacter, PlacementInfo buildingInfo, Zone currentZone) { + cityObject = City.getCity(serverZone.getPlayerCityUUID()); - Blueprint blueprint; - Building newMesh; - DateTime completionDate; - float vendorRotation; - float buildingRotation; + // Cannot place shrine in abandoned city. Shrines must be owned + // by the tol owner not the person placing them. - blueprint = Blueprint.getBlueprint(buildingInfo.getBlueprintUUID()); + if (cityObject.getTOL().getOwnerUUID() == 0) { + PlaceAssetMsg.sendPlaceAssetError(origin, 42, ""); //Tree cannot support anymore shrines + return false; + } - if (blueprint == null) { - Logger.error("CreateStructure: DB returned null blueprint."); - return null; - } + blueprint = Blueprint.getBlueprint(msg.getFirstPlacementInfo().getBlueprintUUID()); - // All siege buildings build in 15 minutes - if ((blueprint.getBuildingGroup().equals(BuildingGroup.SIEGETENT)) - || (blueprint.getBuildingGroup().equals(BuildingGroup.BULWARK))) - completionDate = DateTime.now().plusMinutes(15); - else - completionDate = DateTime.now().plusHours(blueprint.getRankTime(1)); + if (blueprint == null) { + return false; + } - Vector3fImmutable localLoc = new Vector3fImmutable(ZoneManager.worldToLocal(buildingInfo.getLoc(), currentZone)); + for (Building building : serverZone.zoneBuildingSet) { + if (building.getBlueprint() == null) + continue; - buildingRotation = buildingInfo.getRot().y; - vendorRotation = buildingInfo.getW(); + if (building.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE) { + if (building.getBlueprintUUID() == blueprint.getMeshForRank(0)) { + PlaceAssetMsg.sendPlaceAssetError(origin, 43, ""); // "shrine of that type exists" + return false; + } + shrineCount++; + } + } - // if W return is negative, this is a -90 rotation not a 90? + // Too many shrines for this tree's rank? - newMesh = DbManager.BuildingQueries.CREATE_BUILDING( - currentZone.getObjectUUID(), playerCharacter.getObjectUUID(), blueprint.getName(), blueprint.getMeshForRank(0), - localLoc, 1.0f, blueprint.getMaxHealth(0), ProtectionState.NONE, 0, 0, - completionDate, blueprint.getMeshForRank(0), vendorRotation, buildingRotation); + if (shrineCount >= Blueprint.getMaxShrines(cityObject.getTOL().getRank())) { + PlaceAssetMsg.sendPlaceAssetError(origin, 42, ""); //Tree cannot support anymore shrines + return false; + } - // Make sure we have a valid mesh - if (newMesh == null) { - Logger.error("CreateStructure: DB returned null object."); - return null; - } + // Create the shrine - newMesh.setObjectTypeMask(MBServerStatics.MASK_BUILDING); - MaintenanceManager.setMaintDateTime(newMesh, LocalDateTime.now().plusDays(7)); + return createShrine((PlayerCharacter) cityObject.getTOL().getOwner(), msg.getFirstPlacementInfo(), serverZone); + } - WorldGrid.addObject(newMesh, playerCharacter); - return newMesh; + private boolean placeBarrack(PlayerCharacter playerCharacter, ClientConnection origin, PlaceAssetMsg msg) { - } + Zone serverZone; + City cityObject; + PlacementInfo buildingList; - private boolean createShrine(PlayerCharacter player, PlacementInfo buildingInfo, Zone currentZone) { + // Setup working variables we'll need + buildingList = msg.getFirstPlacementInfo(); - Blueprint blueprint; - Building newMesh; - Shrine newShrine; - City city; - ShrineType shrineType; + serverZone = ZoneManager.findSmallestZone(buildingList.getLoc()); - if (player == null) - return false; + // Early exit if something went horribly wrong + // with locating the current realm and/or zone - blueprint = Blueprint.getBlueprint(buildingInfo.getBlueprintUUID()); + if (serverZone == null) + return false; - if (blueprint == null) { - Logger.error("CreateShrine: DB returned null blueprint."); - return false; - } + // Method checks validation conditions arising when placing + // buildings. Player must be on a city grid, must be + // inner council of the city's guild, etc. - shrineType = Shrine.getShrineTypeByBlueprintUUID(blueprint.getBlueprintUUID()); + if (validateCityBuildingPlacement(serverZone, msg, origin, playerCharacter, buildingList) == false) + return false; - city = City.getCity(currentZone.getPlayerCityUUID()); + // Loop through all buildings in this city counting barracks . - if (city == null) - return false; + int barracksCount = 0; - if (!city.isLocationOnCityGrid(buildingInfo.getLoc())) - return false; + cityObject = City.getCity(serverZone.getPlayerCityUUID()); - Vector3fImmutable localLoc = new Vector3fImmutable(ZoneManager.worldToLocal(buildingInfo.getLoc(), currentZone)); + // Cannot place barracks in abandoned city. - float buildingRotation = buildingInfo.getRot().y; - float vendorRotation = buildingInfo.getW(); + if (cityObject.getTOL().getOwnerUUID() == 0) { + PlaceAssetMsg.sendPlaceAssetError(origin, 42, ""); //Tree cannot support anymore shrines + return false; + } + for (Building building : serverZone.zoneBuildingSet) { + if (building.getBlueprint().getBuildingGroup() == BuildingGroup.BARRACK) + barracksCount++; + } - ArrayList shrineObjects = DbManager.ShrineQueries.CREATE_SHRINE( - currentZone.getObjectUUID(), player.getObjectUUID(), blueprint.getName(), blueprint.getMeshForRank(0), - localLoc, 1.0f, blueprint.getMaxHealth(0), ProtectionState.PROTECTED, 0, 0, - DateTime.now().plusHours(blueprint.getRankTime(1)), blueprint.getMeshForRank(0), vendorRotation, buildingRotation, shrineType.name()); + // Too many shrines for this tree's rank? - if (shrineObjects == null) { - PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - return false; - } + if (barracksCount >= cityObject.getTOL().getRank()) { + PlaceAssetMsg.sendPlaceAssetError(origin, 47, ""); //Tree cannot support anymore shrines + return false; + } - for (AbstractGameObject ago : shrineObjects) { + // Create the shrine - switch (ago.getObjectType()) { - case Building: - newMesh = (Building) ago; - newMesh.runAfterLoad(); - newMesh.setObjectTypeMask(MBServerStatics.MASK_BUILDING); - MaintenanceManager.setMaintDateTime(newMesh, LocalDateTime.now().plusDays(7)); - WorldGrid.addObject(newMesh, player); - break; - case Shrine: - newShrine = (Shrine) ago; - newShrine.getShrineType().addShrineToServerList(newShrine); - break; - default: - PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - break; - } - } + return createBarracks((PlayerCharacter) cityObject.getTOL().getOwner(), msg.getFirstPlacementInfo(), serverZone); + } - return true; - } + private boolean placeCityWalls(PlayerCharacter player, ClientConnection origin, PlaceAssetMsg msg) { - private boolean createBarracks(PlayerCharacter player, PlacementInfo buildingInfo, Zone currentZone) { + // Member variables - Blueprint blueprint; - Building newMesh; - Shrine newShrine; - City city; + Zone serverZone; + City cityObject; + int placementCost = 0; + CharacterItemManager itemMan; + Item goldItem; + Building wallPiece; - if (player == null) - return false; + // Setup working variables we'll need - blueprint = Blueprint.getBlueprint(buildingInfo.getBlueprintUUID()); + serverZone = ZoneManager.findSmallestZone(player.getLoc()); - if (blueprint == null) { - Logger.error("CreateShrine: DB returned null blueprint."); - return false; - } + // Early exit if something went horribly wrong - city = City.getCity(currentZone.getPlayerCityUUID()); + if (serverZone == null) + return false; - if (city == null) - return false; - if (!city.isLocationOnCityGrid(buildingInfo.getLoc())) - return false; + if (player.getCharItemManager().getGoldTrading() > 0) { + ErrorPopupMsg.sendErrorPopup(player, 195); + return false; + } - Vector3fImmutable localLoc = new Vector3fImmutable(ZoneManager.worldToLocal(buildingInfo.getLoc(), currentZone)); - float buildingRotation = buildingInfo.getRot().y; - float vendorRotation = buildingInfo.getW(); - DateTime completionDate = DateTime.now().plusHours(blueprint.getRankTime(1)); + // Method checks validation conditions arising when placing + // buildings. Player must be on a city grid, must be + // inner council of the city's guild, etc. + if (validateCityBuildingPlacement(serverZone, msg, origin, player, msg.getFirstPlacementInfo()) == false) + return false; - newMesh = DbManager.BuildingQueries.CREATE_BUILDING( - currentZone.getObjectUUID(), player.getObjectUUID(), blueprint.getName(), blueprint.getMeshForRank(0), - localLoc, 1.0f, blueprint.getMaxHealth(0), ProtectionState.PROTECTED, 0, 0, - completionDate, blueprint.getMeshForRank(0), vendorRotation, buildingRotation); + cityObject = City.getCity(serverZone.getPlayerCityUUID()); - // Make sure we have a valid mesh - if (newMesh == null) { - Logger.error("CreateStructure: DB returned null object."); - return false; - } + // We need to be able to access how much gold a character is carrying - newMesh.setObjectTypeMask(MBServerStatics.MASK_BUILDING); - MaintenanceManager.setMaintDateTime(newMesh, LocalDateTime.now().plusDays(7)); - WorldGrid.addObject(newMesh, player); + itemMan = player.getCharItemManager(); - return true; - } + if (itemMan == null) - private boolean createWarehouse(PlayerCharacter player, PlacementInfo buildingInfo, Zone currentZone) { + return false; - Blueprint blueprint; - Building newMesh = null; - ArrayList warehouseObjects; + goldItem = itemMan.getGoldInventory(); - blueprint = Blueprint.getBlueprint(buildingInfo.getBlueprintUUID()); + // Grab list of walls we're placing - if (blueprint == null) { - Logger.error("CreateWarehouse: DB returned null blueprint."); - return false; - } + ArrayList walls = msg.getPlacementInfo(); - Vector3fImmutable localLoc = new Vector3fImmutable(ZoneManager.worldToLocal(buildingInfo.getLoc(), currentZone)); + // Character must be able to afford walls - float buildingRotation = buildingInfo.getRot().y; - float vendorRotation = buildingInfo.getW(); + for (PlacementInfo wall : walls) { + placementCost += PlaceAssetMsg.getWallCost(wall.getBlueprintUUID()); + } - warehouseObjects = DbManager.WarehouseQueries.CREATE_WAREHOUSE( - currentZone.getObjectUUID(), player.getObjectUUID(), blueprint.getName(), blueprint.getMeshForRank(0), - localLoc, 1.0f, blueprint.getMaxHealth(0), ProtectionState.NONE, 0, 0, - DateTime.now().plusHours(blueprint.getRankTime(1)), blueprint.getMeshForRank(0), vendorRotation, buildingRotation); + // Early exit if not enough gold in character's inventory to place walls - if (warehouseObjects == null) { - PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - return false; - } + if (placementCost > goldItem.getNumOfItems()) { + PlaceAssetMsg.sendPlaceAssetError(origin, 28, ""); // Not enough gold + return false; + } - // Load the building into the simulation + placementCost = 0; // reset placement cost for fix bug with wall pieces somethings not taking gold out if forced an error. - for (AbstractGameObject ago : warehouseObjects) { - if (ago.getObjectType() == GameObjectType.Building) { - newMesh = (Building) ago; - newMesh.setObjectTypeMask(MBServerStatics.MASK_BUILDING); - MaintenanceManager.setMaintDateTime(newMesh, LocalDateTime.now().plusDays(7)); - WorldGrid.addObject(newMesh, player); - newMesh.runAfterLoad(); - } - else if (ago.getObjectType() == GameObjectType.Warehouse) { - Warehouse warehouse = (Warehouse) ago; - City city = City.getCity(currentZone.getPlayerCityUUID()); - if (city == null) - return true; - city.setWarehouseBuildingID(newMesh.getObjectUUID()); - Warehouse.warehouseByBuildingUUID.put(newMesh.getObjectUUID(), warehouse); - } - } + // Overlap check and wall deed verifications + for (PlacementInfo wall : walls) { - return true; - } + if (Blueprint.isMeshWallPiece(wall.getBlueprintUUID()) == false) { + PlaceAssetMsg.sendPlaceAssetError(origin, 48, ""); //"Assets (except walls) must be placed one at a time" + continue; + } - // Validates that player is able to place buildings + // Ignore wall pieces not on the city grid + if (cityObject.isLocationOnCityGrid(wall.getLoc()) == false) { + PlaceAssetMsg.sendPlaceAssetError(origin, 1, "Asset " + cityObject.getName() + " not on citygrid"); + continue; + } - private static boolean validateBuildingPlacement(Zone serverZone, PlaceAssetMsg msg, ClientConnection origin, PlayerCharacter player, PlacementInfo placementInfo) { + // Does this wall collide with any other building? - if (serverZone.isPlayerCity() == false) { - PlaceAssetMsg.sendPlaceAssetError(origin, 52, player.getName()); - return false; - } + for (Building building : serverZone.zoneBuildingSet) { - City city = ZoneManager.getCityAtLocation(placementInfo.getLoc()); - if (player.getGuild().equals(city.getGuild()) == false) { - PlaceAssetMsg.sendPlaceAssetError(origin, 40, player.getName()); - return false; - } + //TODO Clean up collision with placementInfo. don't need to create the same placementinfo bounds for collision checks on each building. + if ((building.getBlueprintUUID() != 0) && (Bounds.collide(wall, building) == true)) { - if (city.isLocationOnCityGrid(placementInfo.getLoc()) == false) { - PlaceAssetMsg.sendPlaceAssetError(origin, 41, player.getName()); - return false; - } + if (building.getRank() == -1) { + building.removeFromCache(); + WorldGrid.RemoveWorldObject(building); + WorldGrid.removeObject(building); + building.getParentZone().getParent().zoneBuildingSet.remove(building); + if (building.getBlueprint() != null && building.getBlueprint().getBuildingGroup().equals(BuildingGroup.BARRACK)) { + building.RemoveFromBarracksList(); + } + continue; + } + // remove gold from walls already placed before returning. - // Retrieve the building details we're placing + PlaceAssetMsg.sendPlaceAssetError(origin, 3, building.getName()); //"Conflict between assets" + return false; + } + } + placementCost = PlaceAssetMsg.getWallCost(wall.getBlueprintUUID()); - if (serverZone.isNPCCity() == true) { - PlaceAssetMsg.sendPlaceAssetError(origin, 15, ""); // Cannot place in a peace zone - return false; - } + if (!itemMan.modifyInventoryGold(-placementCost)) { + ChatManager.chatSystemInfo(player, player.getFirstName() + " can't has free moneys! no for real.. Thor.. seriously... I didnt fix it because you getting laid isnt important enough for me."); + return false; + } + // Attempt to place wall piece - // Errant guilds cannot place assets + wallPiece = createStructure(player, wall, serverZone); - if (player.getGuild().getGuildState() == GuildState.Errant) { - PlaceAssetMsg.sendPlaceAssetError(origin, 1, "Only sovereign or sworn guilds may place assets."); - return false; - } + if (wallPiece == null) { + PlaceAssetMsg.sendPlaceAssetError(origin, 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + continue; + } - // Player must be GL or IC of a guild to place buildings. + // walls are auto protected + wallPiece.setProtectionState(ProtectionState.PROTECTED); + PlaceAssetMsg.sendPlaceAssetConfirmWall(origin, serverZone); - if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false && GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false) { - PlaceAssetMsg.sendPlaceAssetError(origin, 10, ""); // You must be a guild leader - return false; - } + } - // Cannot place a building underwater + // Deduct gold from character's inventory - if (HeightMap.isLocUnderwater(placementInfo.getLoc())) { - PlaceAssetMsg.sendPlaceAssetError(origin, 6, ""); // Cannot place underwater - return false; - } - // Players cannot place buildings in mob zones. + return true; + } - if ((serverZone.isMacroZone() == true) - || (serverZone.getParent().isMacroZone() == true)) { - PlaceAssetMsg.sendPlaceAssetError(origin, 57, player.getName()); // No building may be placed within this territory - return false; - } + private Building createStructure(PlayerCharacter playerCharacter, PlacementInfo buildingInfo, Zone currentZone) { - Realm serverRealm = RealmMap.getRealmAtLocation(player.getLoc()); + Blueprint blueprint; + Building newMesh; + DateTime completionDate; + float vendorRotation; + float buildingRotation; - // Cannot place buildings on seafloor or other restricted realms + blueprint = Blueprint.getBlueprint(buildingInfo.getBlueprintUUID()); - if (serverRealm == null || serverRealm.getCanPlaceCities() == false) { - PlaceAssetMsg.sendPlaceAssetError(origin, 57, player.getName()); // No building may be placed within this territory - return false; - } + if (blueprint == null) { + Logger.error("CreateStructure: DB returned null blueprint."); + return null; + } - // Cannot place assets on a dead tree + // All siege buildings build in 15 minutes + if ((blueprint.getBuildingGroup().equals(BuildingGroup.SIEGETENT)) + || (blueprint.getBuildingGroup().equals(BuildingGroup.BULWARK))) + completionDate = DateTime.now().plusMinutes(15); + else + completionDate = DateTime.now().plusHours(blueprint.getRankTime(1)); - if ((serverZone.isPlayerCity()) - && (City.getCity(serverZone.getPlayerCityUUID()).getTOL().getRank() == -1)){ - PlaceAssetMsg.sendPlaceAssetError(origin, 1, "Cannot place asset on dead tree until world heals"); - return false; - } + Vector3fImmutable localLoc = new Vector3fImmutable(ZoneManager.worldToLocal(buildingInfo.getLoc(), currentZone)); - if (placementCollisionCheck(serverZone, origin, placementInfo)){ - PlaceAssetMsg.sendPlaceAssetError(origin, 3, ""); // Conflict between proposed assets - return false; - } + buildingRotation = buildingInfo.getRot().y; + vendorRotation = buildingInfo.getW(); - return true; - } + // if W return is negative, this is a -90 rotation not a 90? - private static boolean placementCollisionCheck(Zone serverZone, ClientConnection origin, PlacementInfo placementInfo) { - // Overlap check + newMesh = DbManager.BuildingQueries.CREATE_BUILDING( + currentZone.getObjectUUID(), playerCharacter.getObjectUUID(), blueprint.getName(), blueprint.getMeshForRank(0), + localLoc, 1.0f, blueprint.getMaxHealth(0), ProtectionState.NONE, 0, 0, + completionDate, blueprint.getMeshForRank(0), vendorRotation, buildingRotation); - for (Building building : serverZone.zoneBuildingSet) { + // Make sure we have a valid mesh + if (newMesh == null) { + Logger.error("CreateStructure: DB returned null object."); + return null; + } - if ((building.getBlueprintUUID() != 0) && (Bounds.collide(placementInfo, building) == true)) { + newMesh.setObjectTypeMask(MBServerStatics.MASK_BUILDING); + MaintenanceManager.setMaintDateTime(newMesh, LocalDateTime.now().plusDays(7)); - // Ignore and remove from simulation if we are placing over rubble + WorldGrid.addObject(newMesh, playerCharacter); + return newMesh; - if (building.getRank() == -1) { + } - if ((building.getBlueprintUUID() != 0) - && (building.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE)){ - Shrine.RemoveShrineFromCacheByBuilding(building); - if (building.getCity() != null){ + // Validates that player is able to place buildings - } - } + private boolean createShrine(PlayerCharacter player, PlacementInfo buildingInfo, Zone currentZone) { - building.removeFromCache(); - WorldGrid.RemoveWorldObject(building); - WorldGrid.removeObject(building); - building.getParentZone().zoneBuildingSet.remove(building); - if(building.getBlueprint() != null && building.getBlueprint().getBuildingGroup().equals(BuildingGroup.BARRACK)){ - building.RemoveFromBarracksList(); - } - continue; - } + Blueprint blueprint; + Building newMesh; + Shrine newShrine; + City city; + ShrineType shrineType; + if (player == null) + return false; - PlaceAssetMsg.sendPlaceAssetError(origin, 3, ""); // Conflict between proposed assets - return true; - } - } - return false; - } + blueprint = Blueprint.getBlueprint(buildingInfo.getBlueprintUUID()); - private static boolean validateCityBuildingPlacement(Zone serverZone, PlaceAssetMsg msg, ClientConnection origin, PlayerCharacter player, PlacementInfo buildingInfo) { + if (blueprint == null) { + Logger.error("CreateShrine: DB returned null blueprint."); + return false; + } - // Perform shared common validation first + shrineType = Shrine.getShrineTypeByBlueprintUUID(blueprint.getBlueprintUUID()); - if (validateBuildingPlacement(serverZone, msg, origin, player, buildingInfo) == false) - return false; + city = City.getCity(currentZone.getPlayerCityUUID()); - // Must be a player city + if (city == null) + return false; - if (serverZone.isPlayerCity() == false) { - PlaceAssetMsg.sendPlaceAssetError(origin, 41, player.getName()); // Cannot place outside a guild zone - return false; - } + if (!city.isLocationOnCityGrid(buildingInfo.getLoc())) + return false; - //Test zone has a city object + Vector3fImmutable localLoc = new Vector3fImmutable(ZoneManager.worldToLocal(buildingInfo.getLoc(), currentZone)); - City city = City.getCity(serverZone.getPlayerCityUUID()); + float buildingRotation = buildingInfo.getRot().y; + float vendorRotation = buildingInfo.getW(); - if (city == null) { - PlaceAssetMsg.sendPlaceAssetError(origin, 52, ""); //"no city to associate asset with" - return false; - } - // City assets must be placed on the city grid + ArrayList shrineObjects = DbManager.ShrineQueries.CREATE_SHRINE( + currentZone.getObjectUUID(), player.getObjectUUID(), blueprint.getName(), blueprint.getMeshForRank(0), + localLoc, 1.0f, blueprint.getMaxHealth(0), ProtectionState.PROTECTED, 0, 0, + DateTime.now().plusHours(blueprint.getRankTime(1)), blueprint.getMeshForRank(0), vendorRotation, buildingRotation, shrineType.name()); - if (!city.isLocationOnCityGrid(buildingInfo.getLoc())) { - PlaceAssetMsg.sendPlaceAssetError(origin, 52, ""); - return false; - } + if (shrineObjects == null) { + PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + return false; + } - // Make sure it's not an errant tree + for (AbstractGameObject ago : shrineObjects) { - if ( (city.getGuild() == null || city.getGuild().isEmptyGuild() == true)) { - PlaceAssetMsg.sendPlaceAssetError(origin, 18, ""); //"There are no guild trees to be found" - return false; - } + switch (ago.getObjectType()) { + case Building: + newMesh = (Building) ago; + newMesh.runAfterLoad(); + newMesh.setObjectTypeMask(MBServerStatics.MASK_BUILDING); + MaintenanceManager.setMaintDateTime(newMesh, LocalDateTime.now().plusDays(7)); + WorldGrid.addObject(newMesh, player); + break; + case Shrine: + newShrine = (Shrine) ago; + newShrine.getShrineType().addShrineToServerList(newShrine); + break; + default: + PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + break; + } + } - //Test player is in correct guild to place buildings + return true; + } - if (!player.isCSR) - if (player.getGuild().getObjectUUID() != city.getGuild().getObjectUUID()) { - PlaceAssetMsg.sendPlaceAssetError(origin, 9, ""); //You must be a guild member to place this asset - return false; - } - return true; - } + private boolean createBarracks(PlayerCharacter player, PlacementInfo buildingInfo, Zone currentZone) { + + Blueprint blueprint; + Building newMesh; + Shrine newShrine; + City city; + + if (player == null) + return false; + + blueprint = Blueprint.getBlueprint(buildingInfo.getBlueprintUUID()); + + if (blueprint == null) { + Logger.error("CreateShrine: DB returned null blueprint."); + return false; + } + + city = City.getCity(currentZone.getPlayerCityUUID()); + + if (city == null) + return false; + + if (!city.isLocationOnCityGrid(buildingInfo.getLoc())) + return false; + + Vector3fImmutable localLoc = new Vector3fImmutable(ZoneManager.worldToLocal(buildingInfo.getLoc(), currentZone)); + + float buildingRotation = buildingInfo.getRot().y; + float vendorRotation = buildingInfo.getW(); + DateTime completionDate = DateTime.now().plusHours(blueprint.getRankTime(1)); + + + newMesh = DbManager.BuildingQueries.CREATE_BUILDING( + currentZone.getObjectUUID(), player.getObjectUUID(), blueprint.getName(), blueprint.getMeshForRank(0), + localLoc, 1.0f, blueprint.getMaxHealth(0), ProtectionState.PROTECTED, 0, 0, + completionDate, blueprint.getMeshForRank(0), vendorRotation, buildingRotation); + + // Make sure we have a valid mesh + if (newMesh == null) { + Logger.error("CreateStructure: DB returned null object."); + return false; + } + + newMesh.setObjectTypeMask(MBServerStatics.MASK_BUILDING); + MaintenanceManager.setMaintDateTime(newMesh, LocalDateTime.now().plusDays(7)); + WorldGrid.addObject(newMesh, player); + + return true; + } + + private boolean createWarehouse(PlayerCharacter player, PlacementInfo buildingInfo, Zone currentZone) { + + Blueprint blueprint; + Building newMesh = null; + ArrayList warehouseObjects; + + blueprint = Blueprint.getBlueprint(buildingInfo.getBlueprintUUID()); + + if (blueprint == null) { + Logger.error("CreateWarehouse: DB returned null blueprint."); + return false; + } + + Vector3fImmutable localLoc = new Vector3fImmutable(ZoneManager.worldToLocal(buildingInfo.getLoc(), currentZone)); + + float buildingRotation = buildingInfo.getRot().y; + float vendorRotation = buildingInfo.getW(); + + warehouseObjects = DbManager.WarehouseQueries.CREATE_WAREHOUSE( + currentZone.getObjectUUID(), player.getObjectUUID(), blueprint.getName(), blueprint.getMeshForRank(0), + localLoc, 1.0f, blueprint.getMaxHealth(0), ProtectionState.NONE, 0, 0, + DateTime.now().plusHours(blueprint.getRankTime(1)), blueprint.getMeshForRank(0), vendorRotation, buildingRotation); + + if (warehouseObjects == null) { + PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + return false; + } + + // Load the building into the simulation + + for (AbstractGameObject ago : warehouseObjects) { + + if (ago.getObjectType() == GameObjectType.Building) { + newMesh = (Building) ago; + newMesh.setObjectTypeMask(MBServerStatics.MASK_BUILDING); + MaintenanceManager.setMaintDateTime(newMesh, LocalDateTime.now().plusDays(7)); + WorldGrid.addObject(newMesh, player); + newMesh.runAfterLoad(); + } else if (ago.getObjectType() == GameObjectType.Warehouse) { + Warehouse warehouse = (Warehouse) ago; + City city = City.getCity(currentZone.getPlayerCityUUID()); + if (city == null) + return true; + city.setWarehouseBuildingID(newMesh.getObjectUUID()); + Warehouse.warehouseByBuildingUUID.put(newMesh.getObjectUUID(), warehouse); + } + } + + return true; + } } \ No newline at end of file diff --git a/src/engine/net/client/handlers/RecommendNationMsgHandler.java b/src/engine/net/client/handlers/RecommendNationMsgHandler.java index 8912dea4..395bde19 100644 --- a/src/engine/net/client/handlers/RecommendNationMsgHandler.java +++ b/src/engine/net/client/handlers/RecommendNationMsgHandler.java @@ -19,72 +19,69 @@ import engine.objects.PlayerCharacter; */ public class RecommendNationMsgHandler extends AbstractClientMsgHandler { - public RecommendNationMsgHandler() { - super(RecommendNationMsg.class); - } + public RecommendNationMsgHandler() { + super(RecommendNationMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + private static void RecommendNation(Guild fromGuild, Guild toGuild, RecommendNationMsg msg, ClientConnection origin) { - // Member variable declaration + // Member variable declaration + Dispatch dispatch; - PlayerCharacter player; - RecommendNationMsg msg; + // Member variable assignment + if (fromGuild == null) + return; - // Member variable assignment + if (toGuild == null) + return; - msg = (RecommendNationMsg) baseMsg; + AllianceType allianceType; + if (msg.getAlly() == 1) + allianceType = AllianceType.RecommendedAlly; + else + allianceType = AllianceType.RecommendedEnemy; - player = SessionManager.getPlayerCharacter(origin); + if (!fromGuild.addGuildToAlliance(new AllianceChangeMsg(origin.getPlayerCharacter(), fromGuild.getObjectUUID(), toGuild.getObjectUUID(), (byte) 0, 0), allianceType, toGuild, origin.getPlayerCharacter())) + return; + String alliance = msg.getAlly() == 1 ? "ally" : "enemy"; - if (player == null) - return true; + ChatManager.chatGuildInfo(fromGuild, origin.getPlayerCharacter().getFirstName() + " has recommended " + toGuild.getName() + " as an " + alliance); + // dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); + // DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - RecommendNationMsgHandler.RecommendNation(player.getGuild(), Guild.getGuild(msg.getGuildID()), msg, origin); + } + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + // Member variable declaration - // dispatch = Dispatch.borrow(player, baseMsg); - // DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + PlayerCharacter player; + RecommendNationMsg msg; - return true; - } + // Member variable assignment - private static void RecommendNation(Guild fromGuild, Guild toGuild, RecommendNationMsg msg, ClientConnection origin) { + msg = (RecommendNationMsg) baseMsg; - // Member variable declaration - Dispatch dispatch; + player = SessionManager.getPlayerCharacter(origin); - // Member variable assignment + if (player == null) + return true; - if (fromGuild == null) - return; - if (toGuild == null) - return; + RecommendNationMsgHandler.RecommendNation(player.getGuild(), Guild.getGuild(msg.getGuildID()), msg, origin); - AllianceType allianceType; - if (msg.getAlly() == 1) - allianceType = AllianceType.RecommendedAlly; - else - allianceType = AllianceType.RecommendedEnemy; - if (!fromGuild.addGuildToAlliance(new AllianceChangeMsg(origin.getPlayerCharacter(),fromGuild.getObjectUUID(), toGuild.getObjectUUID(), (byte)0, 0), allianceType, toGuild, origin.getPlayerCharacter())) - return; - String alliance = msg.getAlly() == 1? "ally" : "enemy"; + // dispatch = Dispatch.borrow(player, baseMsg); + // DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - ChatManager.chatGuildInfo(fromGuild, origin.getPlayerCharacter().getFirstName() + " has recommended " + toGuild.getName() + " as an " + alliance ); - - // dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); - // DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - - } + return true; + } } diff --git a/src/engine/net/client/handlers/RemoveFriendHandler.java b/src/engine/net/client/handlers/RemoveFriendHandler.java index f17df1f4..85223ded 100644 --- a/src/engine/net/client/handlers/RemoveFriendHandler.java +++ b/src/engine/net/client/handlers/RemoveFriendHandler.java @@ -20,45 +20,42 @@ import engine.objects.PlayerCharacter; import engine.objects.PlayerFriends; - public class RemoveFriendHandler extends AbstractClientMsgHandler { - public RemoveFriendHandler() { - super(RemoveFriendMessage.class); - } - - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, - ClientConnection origin) throws MsgSendException { - - PlayerCharacter player = origin.getPlayerCharacter(); - - if (player == null) - return true; - - - RemoveFriendMessage msg = (RemoveFriendMessage)baseMsg; - - HandleRemoveFriend(player,msg); - - return true; - } - - - - public static void HandleRemoveFriend(PlayerCharacter player, RemoveFriendMessage msg){ - - //No friends in list. Early exit. - PlayerFriends.RemoveFromFriends(player.getObjectUUID(), msg.friendID); - PlayerFriends.RemoveFromFriends(msg.friendID, player.getObjectUUID()); - - Dispatch dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - msg = new RemoveFriendMessage(msg.friendID); - - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } - + public RemoveFriendHandler() { + super(RemoveFriendMessage.class); + } + + public static void HandleRemoveFriend(PlayerCharacter player, RemoveFriendMessage msg) { + + //No friends in list. Early exit. + PlayerFriends.RemoveFromFriends(player.getObjectUUID(), msg.friendID); + PlayerFriends.RemoveFromFriends(msg.friendID, player.getObjectUUID()); + + Dispatch dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + msg = new RemoveFriendMessage(msg.friendID); + + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, + ClientConnection origin) throws MsgSendException { + + PlayerCharacter player = origin.getPlayerCharacter(); + + if (player == null) + return true; + + + RemoveFriendMessage msg = (RemoveFriendMessage) baseMsg; + + HandleRemoveFriend(player, msg); + + return true; + } + } diff --git a/src/engine/net/client/handlers/RepairBuildingMsgHandler.java b/src/engine/net/client/handlers/RepairBuildingMsgHandler.java index 56085cf1..5cb747a8 100644 --- a/src/engine/net/client/handlers/RepairBuildingMsgHandler.java +++ b/src/engine/net/client/handlers/RepairBuildingMsgHandler.java @@ -24,116 +24,108 @@ import engine.objects.Zone; */ public class RepairBuildingMsgHandler extends AbstractClientMsgHandler { - public RepairBuildingMsgHandler() { - super(RepairBuildingMsg.class); - } + public RepairBuildingMsgHandler() { + super(RepairBuildingMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + private static void RepairBuilding(Building targetBuilding, ClientConnection origin, RepairBuildingMsg msg) { - // Member variable declaration + // Member variable declaration - PlayerCharacter player; - Building targetBuilding; - RepairBuildingMsg msg; + Zone serverZone; + Dispatch dispatch; + // Member variable assignment - // Member variable assignment + if (targetBuilding == null) + return; - msg = (RepairBuildingMsg) baseMsg; + if (!targetBuilding.hasFunds(BuildingManager.GetRepairCost(targetBuilding))) + return; - player = SessionManager.getPlayerCharacter(origin); + PlayerCharacter pc = origin.getPlayerCharacter(); - if (player == null) - return true; + serverZone = ZoneManager.findSmallestZone(pc.getLoc()); + if (serverZone.getPlayerCityUUID() == 0 && targetBuilding.getBlueprint() != null && targetBuilding.getBlueprint().getBuildingGroup() != BuildingGroup.MINE) + return; - switch (msg.getType()) { - case 0: - targetBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID()); - RepairBuilding(targetBuilding, origin, msg); - break; + City city = City.GetCityFromCache(serverZone.getPlayerCityUUID()); - // targetBuilding.createFurniture(item.getItemBase().getUseID(), 0, msg.getFurnitureLoc(), Vector3f.ZERO, 0, player); + if (city != null) { + if (city.getBane() != null && city.protectionEnforced == false) + return; + } - } + //cannot repair mines during 24/7 activity. + if (targetBuilding.getBlueprint() != null && targetBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.MINE) { + return; + } + int maxHP = (int) targetBuilding.getMaxHitPoints(); + int repairCost = BuildingManager.GetRepairCost(targetBuilding); + int missingHealth = (int) BuildingManager.GetMissingHealth(targetBuilding); - // dispatch = Dispatch.borrow(player, baseMsg); - // DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + if (!targetBuilding.transferGold(-repairCost, false)) + return; - return true; + targetBuilding.modifyHealth(BuildingManager.GetMissingHealth(targetBuilding), null); - } + UpdateObjectMsg uom = new UpdateObjectMsg(targetBuilding, 3); - private static void RepairBuilding(Building targetBuilding, ClientConnection origin, RepairBuildingMsg msg) { + dispatch = Dispatch.borrow(origin.getPlayerCharacter(), uom); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - // Member variable declaration - Zone serverZone; - Dispatch dispatch; + RepairBuildingMsg rbm = new RepairBuildingMsg(targetBuilding.getObjectUUID(), maxHP, missingHealth, repairCost, targetBuilding.getStrongboxValue()); - // Member variable assignment - if (targetBuilding == null) - return; + dispatch = Dispatch.borrow(origin.getPlayerCharacter(), rbm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } - if (!targetBuilding.hasFunds(BuildingManager.GetRepairCost(targetBuilding))) - return; + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - PlayerCharacter pc = origin.getPlayerCharacter(); + // Member variable declaration - serverZone = ZoneManager.findSmallestZone(pc.getLoc()); + PlayerCharacter player; + Building targetBuilding; + RepairBuildingMsg msg; - if (serverZone.getPlayerCityUUID() == 0 && targetBuilding.getBlueprint() != null && targetBuilding.getBlueprint().getBuildingGroup() != BuildingGroup.MINE) - return; + // Member variable assignment - City city = City.GetCityFromCache(serverZone.getPlayerCityUUID()); + msg = (RepairBuildingMsg) baseMsg; - if (city != null){ - if(city.getBane() != null && city.protectionEnforced == false) - return; + player = SessionManager.getPlayerCharacter(origin); - } + if (player == null) + return true; - //cannot repair mines during 24/7 activity. - if (targetBuilding.getBlueprint() != null && targetBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.MINE){ - return; - } + switch (msg.getType()) { + case 0: + targetBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID()); + RepairBuilding(targetBuilding, origin, msg); + break; + // targetBuilding.createFurniture(item.getItemBase().getUseID(), 0, msg.getFurnitureLoc(), Vector3f.ZERO, 0, player); + } - int maxHP = (int) targetBuilding.getMaxHitPoints(); - int repairCost = BuildingManager.GetRepairCost(targetBuilding); - int missingHealth = (int) BuildingManager.GetMissingHealth(targetBuilding); + // dispatch = Dispatch.borrow(player, baseMsg); + // DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - if (!targetBuilding.transferGold(-repairCost,false)) - return; - - targetBuilding.modifyHealth(BuildingManager.GetMissingHealth(targetBuilding), null); - - UpdateObjectMsg uom = new UpdateObjectMsg(targetBuilding,3); - - dispatch = Dispatch.borrow(origin.getPlayerCharacter(), uom); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - - - RepairBuildingMsg rbm = new RepairBuildingMsg( targetBuilding.getObjectUUID(), maxHP, missingHealth, repairCost, targetBuilding.getStrongboxValue()); - - - dispatch = Dispatch.borrow(origin.getPlayerCharacter(), rbm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } + return true; + } } diff --git a/src/engine/net/client/handlers/RequestBallListHandler.java b/src/engine/net/client/handlers/RequestBallListHandler.java index 357a45e0..aa206d64 100644 --- a/src/engine/net/client/handlers/RequestBallListHandler.java +++ b/src/engine/net/client/handlers/RequestBallListHandler.java @@ -14,34 +14,33 @@ import engine.net.client.ClientConnection; import engine.net.client.msg.ClientNetMsg; import engine.net.client.msg.RequestBallListMessage; import engine.objects.PlayerCharacter; + public class RequestBallListHandler extends AbstractClientMsgHandler { - public RequestBallListHandler() { - super(RequestBallListMessage.class); - } - - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, - ClientConnection origin) throws MsgSendException { - - PlayerCharacter player = origin.getPlayerCharacter(); - - if (player == null) - return true; - - - RequestBallListMessage msg = (RequestBallListMessage)baseMsg; - - HandleRequestBallList(player,msg); - - return true; - } - - - - public static void HandleRequestBallList(PlayerCharacter player, RequestBallListMessage msg){ - //currently not handled. - - } - + public RequestBallListHandler() { + super(RequestBallListMessage.class); + } + + public static void HandleRequestBallList(PlayerCharacter player, RequestBallListMessage msg) { + //currently not handled. + + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, + ClientConnection origin) throws MsgSendException { + + PlayerCharacter player = origin.getPlayerCharacter(); + + if (player == null) + return true; + + + RequestBallListMessage msg = (RequestBallListMessage) baseMsg; + + HandleRequestBallList(player, msg); + + return true; + } + } diff --git a/src/engine/net/client/handlers/RequestEnterWorldHandler.java b/src/engine/net/client/handlers/RequestEnterWorldHandler.java index 833d4156..18b48254 100644 --- a/src/engine/net/client/handlers/RequestEnterWorldHandler.java +++ b/src/engine/net/client/handlers/RequestEnterWorldHandler.java @@ -30,134 +30,134 @@ import org.pmw.tinylog.Logger; public class RequestEnterWorldHandler extends AbstractClientMsgHandler { - public RequestEnterWorldHandler() { - super(RequestEnterWorldMsg.class); - } + public RequestEnterWorldHandler() { + super(RequestEnterWorldMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - RequestEnterWorldMsg msg; + RequestEnterWorldMsg msg; - msg = (RequestEnterWorldMsg) baseMsg; + msg = (RequestEnterWorldMsg) baseMsg; - Session session = SessionManager.getSession(origin); + Session session = SessionManager.getSession(origin); - if (session == null) - return true; + if (session == null) + return true; - PlayerCharacter player = origin.getPlayerCharacter(); + PlayerCharacter player = origin.getPlayerCharacter(); - WorldGrid.RemoveWorldObject(player); - Dispatch dispatch; + WorldGrid.RemoveWorldObject(player); + Dispatch dispatch; - if (player == null) { - Logger.error("Unable to find player for session" + session.getSessionID()); - origin.kickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Player not found."); - return true; - } + if (player == null) { + Logger.error("Unable to find player for session" + session.getSessionID()); + origin.kickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Player not found."); + return true; + } - player.setEnteredWorld(false); + player.setEnteredWorld(false); - Account acc = SessionManager.getAccount(origin); + Account acc = SessionManager.getAccount(origin); if (acc.status.ordinal() < WorldServer.worldAccessLevel.ordinal() || MBServerStatics.blockLogin) { origin.disconnect(); return true; } - // Brand new character. Send the city select screen - - if (player.getLevel() == 1 && player.getBindBuildingID() == -1) { - SelectCityMsg scm = new SelectCityMsg(player, true); - dispatch = Dispatch.borrow(player, scm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - } - - player.resetRegenUpdateTime(); - - // Map Data - - try { - WorldDataMsg wdm = new WorldDataMsg(); - dispatch = Dispatch.borrow(player, wdm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - } catch (Exception e) { - // TODO Auto-generated catch block - Logger.error("WORLDDATAMESSAGE" + e.getMessage()); - } - - // Realm Data - - try { - WorldRealmMsg wrm = new WorldRealmMsg(); - dispatch = Dispatch.borrow(player, wrm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - } catch (Exception e) { - // TODO Auto-generated catch block - Logger.error("REALMMESSAGE" + e.getMessage()); - } - - // Object Data - CityDataMsg wom = new CityDataMsg(session, true); - dispatch = Dispatch.borrow(player, wom); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - - player.getTimestamps().put("EnterWorld", System.currentTimeMillis()); - - if (player.getLoc().equals(Vector3fImmutable.ZERO) || System.currentTimeMillis() > player.getTimeStamp("logout") + (15 * 60 * 1000)) { - player.stopMovement(player.getBindLoc()); - player.setSafeMode(); - player.updateLocation(); - player.setRegion(AbstractWorldObject.GetRegionByWorldObject(player)); - } - - player.setTimeStamp("logout", 0); - player.respawnLock.writeLock().lock(); - try{ - if (!player.isAlive()){ - Logger.info("respawning player on enter world."); - player.respawn(true, true,true); - } - - }catch (Exception e){ - Logger.error(e); - }finally{ - player.respawnLock.writeLock().unlock(); - } - - - player.resetDataAtLogin(); - - InterestManager.INTERESTMANAGER.HandleLoadForEnterWorld(player); - - // If this is a brand new character... - // when they enter world is a great time to write their - // character record to the data warehouse. - - if (player.getHash() == null) { - - if (DataWarehouse.recordExists(Enum.DataRecordType.CHARACTER, player.getObjectUUID()) == false) { - CharacterRecord characterRecord = CharacterRecord.borrow(player); - DataWarehouse.pushToWarehouse(characterRecord); - } - player.setHash(); - } + // Brand new character. Send the city select screen + + if (player.getLevel() == 1 && player.getBindBuildingID() == -1) { + SelectCityMsg scm = new SelectCityMsg(player, true); + dispatch = Dispatch.borrow(player, scm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + } + + player.resetRegenUpdateTime(); + + // Map Data + + try { + WorldDataMsg wdm = new WorldDataMsg(); + dispatch = Dispatch.borrow(player, wdm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + } catch (Exception e) { + // TODO Auto-generated catch block + Logger.error("WORLDDATAMESSAGE" + e.getMessage()); + } + + // Realm Data + + try { + WorldRealmMsg wrm = new WorldRealmMsg(); + dispatch = Dispatch.borrow(player, wrm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + } catch (Exception e) { + // TODO Auto-generated catch block + Logger.error("REALMMESSAGE" + e.getMessage()); + } + + // Object Data + CityDataMsg wom = new CityDataMsg(session, true); + dispatch = Dispatch.borrow(player, wom); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + + player.getTimestamps().put("EnterWorld", System.currentTimeMillis()); + + if (player.getLoc().equals(Vector3fImmutable.ZERO) || System.currentTimeMillis() > player.getTimeStamp("logout") + (15 * 60 * 1000)) { + player.stopMovement(player.getBindLoc()); + player.setSafeMode(); + player.updateLocation(); + player.setRegion(AbstractWorldObject.GetRegionByWorldObject(player)); + } + + player.setTimeStamp("logout", 0); + player.respawnLock.writeLock().lock(); + try { + if (!player.isAlive()) { + Logger.info("respawning player on enter world."); + player.respawn(true, true, true); + } + + } catch (Exception e) { + Logger.error(e); + } finally { + player.respawnLock.writeLock().unlock(); + } + + + player.resetDataAtLogin(); + + InterestManager.INTERESTMANAGER.HandleLoadForEnterWorld(player); + + // If this is a brand new character... + // when they enter world is a great time to write their + // character record to the data warehouse. + + if (player.getHash() == null) { + + if (DataWarehouse.recordExists(Enum.DataRecordType.CHARACTER, player.getObjectUUID()) == false) { + CharacterRecord characterRecord = CharacterRecord.borrow(player); + DataWarehouse.pushToWarehouse(characterRecord); + } + player.setHash(); + } // - // We will load the kill/death lists here as data is only pertinent - // to characters actually logged into the game. + // We will load the kill/death lists here as data is only pertinent + // to characters actually logged into the game. // - player.pvpKills = PvpRecord.getCharacterPvPHistory(player.getObjectUUID(), Enum.PvpHistoryType.KILLS); - player.pvpDeaths = PvpRecord.getCharacterPvPHistory(player.getObjectUUID(), Enum.PvpHistoryType.DEATHS); + player.pvpKills = PvpRecord.getCharacterPvPHistory(player.getObjectUUID(), Enum.PvpHistoryType.KILLS); + player.pvpDeaths = PvpRecord.getCharacterPvPHistory(player.getObjectUUID(), Enum.PvpHistoryType.DEATHS); - SendOwnPlayerMsg sopm = new SendOwnPlayerMsg(SessionManager.getSession(origin)); - dispatch = Dispatch.borrow(player, sopm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + SendOwnPlayerMsg sopm = new SendOwnPlayerMsg(SessionManager.getSession(origin)); + dispatch = Dispatch.borrow(player, sopm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - return true; - } + return true; + } - } +} diff --git a/src/engine/net/client/handlers/RequestGuildListHandler.java b/src/engine/net/client/handlers/RequestGuildListHandler.java index 5700cc0b..a559ef5c 100644 --- a/src/engine/net/client/handlers/RequestGuildListHandler.java +++ b/src/engine/net/client/handlers/RequestGuildListHandler.java @@ -26,30 +26,30 @@ import engine.objects.PlayerCharacter; public class RequestGuildListHandler extends AbstractClientMsgHandler { - public RequestGuildListHandler() { - super(ReqGuildListMsg.class); - } + public RequestGuildListHandler() { + super(ReqGuildListMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { Dispatch dispatch; - // get PlayerCharacter of person accepting invite - PlayerCharacter pc = SessionManager.getPlayerCharacter( - origin); - if (pc == null) - return true; - - if (GuildStatusController.isGuildLeader(pc.getGuildStatus()) == false){ - ErrorPopupMsg.sendErrorMsg(pc, "You do not have such authority!"); - } - SendGuildEntryMsg msg = new SendGuildEntryMsg(pc); + // get PlayerCharacter of person accepting invite + PlayerCharacter pc = SessionManager.getPlayerCharacter( + origin); + if (pc == null) + return true; + + if (GuildStatusController.isGuildLeader(pc.getGuildStatus()) == false) { + ErrorPopupMsg.sendErrorMsg(pc, "You do not have such authority!"); + } + SendGuildEntryMsg msg = new SendGuildEntryMsg(pc); dispatch = Dispatch.borrow(pc, msg); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - return true; - } + return true; + } } diff --git a/src/engine/net/client/handlers/SendBallEntryHandler.java b/src/engine/net/client/handlers/SendBallEntryHandler.java index 33ca1f9a..8ed595ee 100644 --- a/src/engine/net/client/handlers/SendBallEntryHandler.java +++ b/src/engine/net/client/handlers/SendBallEntryHandler.java @@ -14,34 +14,33 @@ import engine.net.client.ClientConnection; import engine.net.client.msg.ClientNetMsg; import engine.net.client.msg.SendBallEntryMessage; import engine.objects.PlayerCharacter; + public class SendBallEntryHandler extends AbstractClientMsgHandler { - public SendBallEntryHandler() { - super(SendBallEntryMessage.class); - } - - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, - ClientConnection origin) throws MsgSendException { - - PlayerCharacter player = origin.getPlayerCharacter(); - - if (player == null) - return true; - - - SendBallEntryMessage msg = (SendBallEntryMessage)baseMsg; - - HandleAddBall(player,msg); - - return true; - } - - - - public static void HandleAddBall(PlayerCharacter player, SendBallEntryMessage msg){ - //currently not handled. - - } - + public SendBallEntryHandler() { + super(SendBallEntryMessage.class); + } + + public static void HandleAddBall(PlayerCharacter player, SendBallEntryMessage msg) { + //currently not handled. + + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, + ClientConnection origin) throws MsgSendException { + + PlayerCharacter player = origin.getPlayerCharacter(); + + if (player == null) + return true; + + + SendBallEntryMessage msg = (SendBallEntryMessage) baseMsg; + + HandleAddBall(player, msg); + + return true; + } + } diff --git a/src/engine/net/client/handlers/SwearInGuildHandler.java b/src/engine/net/client/handlers/SwearInGuildHandler.java index a27029fa..8c5c6414 100644 --- a/src/engine/net/client/handlers/SwearInGuildHandler.java +++ b/src/engine/net/client/handlers/SwearInGuildHandler.java @@ -55,20 +55,20 @@ public class SwearInGuildHandler extends AbstractClientMsgHandler { targetGuild = (Guild) DbManager.getObject(GameObjectType.Guild, swearInMsg.getGuildUUID()); if (targetGuild == null) { - ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occured. Please post details for to ensure transaction integrity"); + ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occured. Please post details for to ensure transaction integrity"); return true; } nation = player.getGuild(); if (nation == null) { - ErrorPopupMsg.sendErrorMsg(player, "You do not belong to a guild!"); + ErrorPopupMsg.sendErrorMsg(player, "You do not belong to a guild!"); return true; } try { if (!nation.isNation()) { - ErrorPopupMsg.sendErrorMsg(player, "Your guild is not a nation!"); + ErrorPopupMsg.sendErrorMsg(player, "Your guild is not a nation!"); return true; } if (!nation.getSubGuildList().contains(targetGuild)) { @@ -81,7 +81,7 @@ public class SwearInGuildHandler extends AbstractClientMsgHandler { return true; } - if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false){ + if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false) { ErrorPopupMsg.sendErrorMsg(player, "Your do not have such authority!"); return true; } @@ -114,7 +114,7 @@ public class SwearInGuildHandler extends AbstractClientMsgHandler { dispatch = Dispatch.borrow(player, msg); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - City.lastCityUpdate = System.currentTimeMillis(); + City.lastCityUpdate = System.currentTimeMillis(); ArrayList guildMembers = SessionManager.getActivePCsInGuildID(nation.getObjectUUID()); @@ -128,7 +128,7 @@ public class SwearInGuildHandler extends AbstractClientMsgHandler { ChatManager.chatGuildInfo(member, "Your Guild has sword fealty to " + nation.getName() + '.'); } } catch (Exception e) { - Logger.error( e.getMessage()); + Logger.error(e.getMessage()); return true; } diff --git a/src/engine/net/client/handlers/SwearInHandler.java b/src/engine/net/client/handlers/SwearInHandler.java index fca29d69..2796bbaa 100644 --- a/src/engine/net/client/handlers/SwearInHandler.java +++ b/src/engine/net/client/handlers/SwearInHandler.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.net.client.handlers; import engine.Enum; @@ -27,53 +26,53 @@ import engine.objects.PlayerCharacter; public class SwearInHandler extends AbstractClientMsgHandler { - public SwearInHandler() { - super(SwearInMsg.class); - } + public SwearInHandler() { + super(SwearInMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - SwearInMsg msg = (SwearInMsg) baseMsg; + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + SwearInMsg msg = (SwearInMsg) baseMsg; Dispatch dispatch; - // get source player - PlayerCharacter source = SessionManager.getPlayerCharacter(origin); + // get source player + PlayerCharacter source = SessionManager.getPlayerCharacter(origin); - if (source == null) - return true; + if (source == null) + return true; - // get target player - PlayerCharacter target = SessionManager.getPlayerCharacterByID(msg.getTargetID()); + // get target player + PlayerCharacter target = SessionManager.getPlayerCharacterByID(msg.getTargetID()); - if (target == null) { - ChatManager.chatGuildError(source, - "No such character found!"); - return true; - } + if (target == null) { + ChatManager.chatGuildError(source, + "No such character found!"); + return true; + } - if(source.getGuild() != target.getGuild()) { - ChatManager.chatGuildError(source, - "That player is not a member of " + source.getGuild().getName()); - return true; - } + if (source.getGuild() != target.getGuild()) { + ChatManager.chatGuildError(source, + "That player is not a member of " + source.getGuild().getName()); + return true; + } - // Verify source has authority to swear in - if (GuildStatusController.isInnerCouncil(source.getGuildStatus()) == false) { - ErrorPopupMsg.sendErrorMsg(source, "Your do not have such authority!"); - return true; - } + // Verify source has authority to swear in + if (GuildStatusController.isInnerCouncil(source.getGuildStatus()) == false) { + ErrorPopupMsg.sendErrorMsg(source, "Your do not have such authority!"); + return true; + } - // Swear target in and send message to guild - target.setFullMember(true); - target.incVer(); + // Swear target in and send message to guild + target.setFullMember(true); + target.incVer(); - ChatManager.chatGuildInfo(source,target.getFirstName() + " has been sworn in as a full member!"); + ChatManager.chatGuildInfo(source, target.getFirstName() + " has been sworn in as a full member!"); dispatch = Dispatch.borrow(source, new GuildListMsg(source.getGuild())); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - DispatchMessage.sendToAllInRange(target, new GuildInfoMsg(target, target.getGuild(), 2)); + DispatchMessage.sendToAllInRange(target, new GuildInfoMsg(target, target.getGuild(), 2)); - return true; - } + return true; + } } diff --git a/src/engine/net/client/handlers/TaxCityMsgHandler.java b/src/engine/net/client/handlers/TaxCityMsgHandler.java index 895b132d..4b9a1ef2 100644 --- a/src/engine/net/client/handlers/TaxCityMsgHandler.java +++ b/src/engine/net/client/handlers/TaxCityMsgHandler.java @@ -20,89 +20,68 @@ import engine.objects.*; */ public class TaxCityMsgHandler extends AbstractClientMsgHandler { - public TaxCityMsgHandler() { - super(TaxCityMsg.class); - } + public TaxCityMsgHandler() { + super(TaxCityMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + private static boolean ViewTaxes(TaxCityMsg msg, PlayerCharacter player) { - // Member variable declaration + // Member variable declaration + Building building = BuildingManager.getBuildingFromCache(msg.getGuildID()); + Guild playerGuild = player.getGuild(); - PlayerCharacter player; - TaxCityMsg msg; + if (building == null) { + ErrorPopupMsg.sendErrorMsg(player, "Not a valid Building!"); + return true; + } - player = origin.getPlayerCharacter(); + City city = building.getCity(); + if (city == null) { + ErrorPopupMsg.sendErrorMsg(player, "This building does not belong to a city."); + return true; + } + if (city.getWarehouse() == null) { + ErrorPopupMsg.sendErrorMsg(player, "This city does not have a warehouse!"); + return true; + } - msg = (TaxCityMsg) baseMsg; - ViewTaxes(msg,player); + if (playerGuild == null || playerGuild.isEmptyGuild()) { + ErrorPopupMsg.sendErrorMsg(player, "You must belong to a guild to do that!"); + return true; + } + if (playerGuild.getOwnedCity() == null) { + ErrorPopupMsg.sendErrorMsg(player, "Your Guild needs to own a city!"); + return true; + } + if (playerGuild.getOwnedCity().getWarehouse() == null) { + ErrorPopupMsg.sendErrorMsg(player, "Your Guild needs to own a warehouse!"); + return true; + } - return true; - - } - - private static boolean ViewTaxes(TaxCityMsg msg, PlayerCharacter player) { - - // Member variable declaration - Building building = BuildingManager.getBuildingFromCache(msg.getGuildID()); - Guild playerGuild = player.getGuild(); - - if (building == null){ - ErrorPopupMsg.sendErrorMsg(player, "Not a valid Building!"); - return true; - } - - City city = building.getCity(); - if (city == null){ - ErrorPopupMsg.sendErrorMsg(player, "This building does not belong to a city."); - return true; - } - - if (city.getWarehouse() == null){ - ErrorPopupMsg.sendErrorMsg(player, "This city does not have a warehouse!"); - return true; - } - - - if (playerGuild == null || playerGuild.isEmptyGuild()){ - ErrorPopupMsg.sendErrorMsg(player, "You must belong to a guild to do that!"); - return true; - } - - if (playerGuild.getOwnedCity() == null){ - ErrorPopupMsg.sendErrorMsg(player, "Your Guild needs to own a city!"); - return true; - } - - if (playerGuild.getOwnedCity().getWarehouse() == null){ - ErrorPopupMsg.sendErrorMsg(player, "Your Guild needs to own a warehouse!"); - return true; - } - - if (playerGuild.getOwnedCity().getTOL() == null){ - ErrorPopupMsg.sendErrorMsg(player, "Cannot find Tree of Life for your city!"); - return true; - } + if (playerGuild.getOwnedCity().getTOL() == null) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot find Tree of Life for your city!"); + return true; + } // if (playerGuild.getOwnedCity().getTOL().getRank() != 8){ // ErrorPopupMsg.sendErrorMsg(player, "Your City needs to Own a realm!"); // return true; // } - if (playerGuild.getOwnedCity().getRealm() == null){ - ErrorPopupMsg.sendErrorMsg(player, "Cannot find realm for your city!"); - return true; - } - Realm targetRealm = RealmMap.getRealmForCity(city); + if (playerGuild.getOwnedCity().getRealm() == null) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot find realm for your city!"); + return true; + } + Realm targetRealm = RealmMap.getRealmForCity(city); - if (targetRealm == null){ - ErrorPopupMsg.sendErrorMsg(player, "Cannot find realm for city you are attempting to tax!"); - return true; - } + if (targetRealm == null) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot find realm for city you are attempting to tax!"); + return true; + } // if (targetRealm.getRulingCity() == null){ // ErrorPopupMsg.sendErrorMsg(player, "Realm Does not have a ruling city!"); @@ -120,35 +99,48 @@ public class TaxCityMsgHandler extends AbstractClientMsgHandler { // } - - - if (!GuildStatusController.isTaxCollector(player.getGuildStatus())){ - ErrorPopupMsg.sendErrorMsg(player, "You Must be a tax Collector!"); - return true; - } + if (!GuildStatusController.isTaxCollector(player.getGuildStatus())) { + ErrorPopupMsg.sendErrorMsg(player, "You Must be a tax Collector!"); + return true; + } // if (!city.isAfterTaxPeriod(DateTime.now(), player)) // return true; + ViewResourcesMessage vrm = new ViewResourcesMessage(player); + vrm.setGuild(building.getGuild()); + vrm.setWarehouseBuilding(BuildingManager.getBuildingFromCache(building.getCity().getWarehouse().getBuildingUID())); + vrm.configure(); + Dispatch dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + dispatch = Dispatch.borrow(player, vrm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + return true; + + + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + // Member variable declaration + + PlayerCharacter player; + TaxCityMsg msg; - ViewResourcesMessage vrm = new ViewResourcesMessage(player); - vrm.setGuild(building.getGuild()); - vrm.setWarehouseBuilding(BuildingManager.getBuildingFromCache(building.getCity().getWarehouse().getBuildingUID())); - vrm.configure(); - Dispatch dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - dispatch = Dispatch.borrow(player, vrm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - return true; + player = origin.getPlayerCharacter(); + msg = (TaxCityMsg) baseMsg; - } + ViewTaxes(msg, player); + return true; + } } diff --git a/src/engine/net/client/handlers/TaxResourcesMsgHandler.java b/src/engine/net/client/handlers/TaxResourcesMsgHandler.java index 2e4e0e90..b69a897b 100644 --- a/src/engine/net/client/handlers/TaxResourcesMsgHandler.java +++ b/src/engine/net/client/handlers/TaxResourcesMsgHandler.java @@ -17,57 +17,56 @@ import engine.objects.PlayerCharacter; */ public class TaxResourcesMsgHandler extends AbstractClientMsgHandler { - public TaxResourcesMsgHandler() { - super(TaxResourcesMsg.class); - } + public TaxResourcesMsgHandler() { + super(TaxResourcesMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + private static boolean TaxWarehouse(TaxResourcesMsg msg, PlayerCharacter player) { - // Member variable declaration + // Member variable declaration + Building building = BuildingManager.getBuildingFromCache(msg.getBuildingID()); - PlayerCharacter player; - TaxResourcesMsg msg; - player = origin.getPlayerCharacter(); - if (player == null) - return true; + if (building == null) { + ErrorPopupMsg.sendErrorMsg(player, "Not a valid Building!"); + return true; + } + City city = building.getCity(); + if (city == null) { + ErrorPopupMsg.sendErrorMsg(player, "This building does not belong to a city."); + return true; + } - msg = (TaxResourcesMsg) baseMsg; + city.TaxWarehouse(msg, player); - TaxWarehouse(msg,player); + return true; - return true; + } - } + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - private static boolean TaxWarehouse(TaxResourcesMsg msg, PlayerCharacter player) { + // Member variable declaration - // Member variable declaration - Building building = BuildingManager.getBuildingFromCache(msg.getBuildingID()); + PlayerCharacter player; + TaxResourcesMsg msg; + player = origin.getPlayerCharacter(); + if (player == null) + return true; - if (building == null){ - ErrorPopupMsg.sendErrorMsg(player, "Not a valid Building!"); - return true; - } - City city = building.getCity(); - if (city == null){ - ErrorPopupMsg.sendErrorMsg(player, "This building does not belong to a city."); - return true; - } + msg = (TaxResourcesMsg) baseMsg; - city.TaxWarehouse(msg, player); + TaxWarehouse(msg, player); - return true; + return true; - - } + } } diff --git a/src/engine/net/client/handlers/ToggleGroupSplitHandler.java b/src/engine/net/client/handlers/ToggleGroupSplitHandler.java index 39eefc2d..42ae05f4 100644 --- a/src/engine/net/client/handlers/ToggleGroupSplitHandler.java +++ b/src/engine/net/client/handlers/ToggleGroupSplitHandler.java @@ -28,21 +28,21 @@ public class ToggleGroupSplitHandler extends AbstractClientMsgHandler { @Override protected boolean _handleNetMsg(ClientNetMsg baseMsg, - ClientConnection origin) throws MsgSendException { + ClientConnection origin) throws MsgSendException { // Member variable declaration - + PlayerCharacter source; Group group; boolean split; - + source = SessionManager.getPlayerCharacter(origin); - + if (source == null) return false; group = GroupManager.getGroup(source); - + if (group == null) return false; @@ -59,10 +59,10 @@ public class ToggleGroupSplitHandler extends AbstractClientMsgHandler { group.sendUpdate(gum); // Send split message - + if (split) ChatManager.chatGroupInfo(source, "Treasure is now being split."); - else + else ChatManager.chatGroupInfo(source, "Treasure is no longer being split."); return false; diff --git a/src/engine/net/client/handlers/TransferAssetMsgHandler.java b/src/engine/net/client/handlers/TransferAssetMsgHandler.java index e0be0a85..a9ccdc4e 100644 --- a/src/engine/net/client/handlers/TransferAssetMsgHandler.java +++ b/src/engine/net/client/handlers/TransferAssetMsgHandler.java @@ -20,80 +20,80 @@ import engine.objects.PlayerCharacter; public class TransferAssetMsgHandler extends AbstractClientMsgHandler { - public TransferAssetMsgHandler() { - super(TransferAssetMsg.class); - } - - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - - TransferAssetMsg transferAssetMsg = (TransferAssetMsg) baseMsg; - - int Buildingid = transferAssetMsg.getObjectID(); - int BuildingType = transferAssetMsg.getObjectType(); //ToDue Later - int TargetID = transferAssetMsg.getTargetID(); - int TargetType = transferAssetMsg.getTargetType(); //ToDue later - - Building building = BuildingManager.getBuildingFromCache(Buildingid); - PlayerCharacter newOwner = PlayerCharacter.getFromCache(TargetID); - PlayerCharacter player = origin.getPlayerCharacter(); - - if (player == null || building == null || newOwner == null) - return true; - - Blueprint blueprint = building.getBlueprint(); - - if (blueprint == null) - return true; - - if (building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.MINE) { - ErrorPopupMsg.sendErrorMsg(player, "You cannot transfer a mine!"); - return true; - } - - // Players cannot transfer shrines - - if ((building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.SHRINE)) { - ErrorPopupMsg.sendErrorMsg(player, "Cannot for to transfer shrine!"); - return true; - } - - if (Blueprint.isMeshWallPiece(building.getBlueprintUUID())) { - ErrorPopupMsg.sendErrorMsg(player, "Cannot for to transfer fortress asset!"); - return true; - } - - if ((building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.BARRACK)) { - ErrorPopupMsg.sendErrorMsg(player, "Cannot for to transfer fortress asset!"); - return true; - } - - if ((building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.BULWARK)) { - ErrorPopupMsg.sendErrorMsg(player, "Cannot for to transfer siege asset!"); - return true; - } - - if ((building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.SIEGETENT)) { - ErrorPopupMsg.sendErrorMsg(player, "Cannot for to transfer siege asset!"); - return true; - } - - if ((building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.BANESTONE)) { - ErrorPopupMsg.sendErrorMsg(player, "Cannot for to transfer banestone!"); - return true; - } - if (building.getOwnerUUID() != player.getObjectUUID()) { - ChatManager.chatSystemError(player, "You do not own this asset."); - return true; - } - - if (building.getOwnerUUID() == newOwner.getObjectUUID()) { - ChatManager.chatSystemError(player, "You already own this asset."); - return true; - } - - building.setOwner(newOwner); - return true; - } + public TransferAssetMsgHandler() { + super(TransferAssetMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + TransferAssetMsg transferAssetMsg = (TransferAssetMsg) baseMsg; + + int Buildingid = transferAssetMsg.getObjectID(); + int BuildingType = transferAssetMsg.getObjectType(); //ToDue Later + int TargetID = transferAssetMsg.getTargetID(); + int TargetType = transferAssetMsg.getTargetType(); //ToDue later + + Building building = BuildingManager.getBuildingFromCache(Buildingid); + PlayerCharacter newOwner = PlayerCharacter.getFromCache(TargetID); + PlayerCharacter player = origin.getPlayerCharacter(); + + if (player == null || building == null || newOwner == null) + return true; + + Blueprint blueprint = building.getBlueprint(); + + if (blueprint == null) + return true; + + if (building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.MINE) { + ErrorPopupMsg.sendErrorMsg(player, "You cannot transfer a mine!"); + return true; + } + + // Players cannot transfer shrines + + if ((building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.SHRINE)) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot for to transfer shrine!"); + return true; + } + + if (Blueprint.isMeshWallPiece(building.getBlueprintUUID())) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot for to transfer fortress asset!"); + return true; + } + + if ((building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.BARRACK)) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot for to transfer fortress asset!"); + return true; + } + + if ((building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.BULWARK)) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot for to transfer siege asset!"); + return true; + } + + if ((building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.SIEGETENT)) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot for to transfer siege asset!"); + return true; + } + + if ((building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.BANESTONE)) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot for to transfer banestone!"); + return true; + } + if (building.getOwnerUUID() != player.getObjectUUID()) { + ChatManager.chatSystemError(player, "You do not own this asset."); + return true; + } + + if (building.getOwnerUUID() == newOwner.getObjectUUID()) { + ChatManager.chatSystemError(player, "You already own this asset."); + return true; + } + + building.setOwner(newOwner); + return true; + } } \ No newline at end of file diff --git a/src/engine/net/client/handlers/TransferGoldToFromBuildingMsgHandler.java b/src/engine/net/client/handlers/TransferGoldToFromBuildingMsgHandler.java index e5cc9aed..70ba7486 100644 --- a/src/engine/net/client/handlers/TransferGoldToFromBuildingMsgHandler.java +++ b/src/engine/net/client/handlers/TransferGoldToFromBuildingMsgHandler.java @@ -26,90 +26,90 @@ import org.pmw.tinylog.Logger; public class TransferGoldToFromBuildingMsgHandler extends AbstractClientMsgHandler { - public TransferGoldToFromBuildingMsgHandler() { - super(TransferGoldToFromBuildingMsg.class); - } + public TransferGoldToFromBuildingMsgHandler() { + super(TransferGoldToFromBuildingMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - PlayerCharacter player; - Building building; - CharacterItemManager itemMan; - Item goldItem; - TransferGoldToFromBuildingMsg msg; - Dispatch dispatch; + PlayerCharacter player; + Building building; + CharacterItemManager itemMan; + Item goldItem; + TransferGoldToFromBuildingMsg msg; + Dispatch dispatch; - player = SessionManager.getPlayerCharacter(origin); + player = SessionManager.getPlayerCharacter(origin); - if (player == null) - return true; + if (player == null) + return true; - msg = (TransferGoldToFromBuildingMsg) baseMsg; + msg = (TransferGoldToFromBuildingMsg) baseMsg; - building = BuildingManager.getBuildingFromCache(msg.getObjectID()); + building = BuildingManager.getBuildingFromCache(msg.getObjectID()); - if (building == null) - return true; + if (building == null) + return true; - if (msg.getDirection() == 2){ + if (msg.getDirection() == 2) { - if(!ManageCityAssetMsgHandler.playerCanManageNotFriends(player, building)) - return true; - if (building.setReserve(msg.getUnknown01(),player)){ - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } - - return true; - } + if (!ManageCityAssetMsgHandler.playerCanManageNotFriends(player, building)) + return true; + if (building.setReserve(msg.getUnknown01(), player)) { + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + } - // if (building.getTimeStamp(MBServerStatics.STRONGBOX_DELAY_STRING) > System.currentTimeMillis()){ - // ErrorPopupMsg.sendErrorMsg(player, MBServerStatics.STRONGBOX_DELAY_OUTPUT); - // return true; - // } + return true; + } - //building.getTimestamps().put(MBServerStatics.STRONGBOX_DELAY_STRING, System.currentTimeMillis() + MBServerStatics.ONE_MINUTE); + // if (building.getTimeStamp(MBServerStatics.STRONGBOX_DELAY_STRING) > System.currentTimeMillis()){ + // ErrorPopupMsg.sendErrorMsg(player, MBServerStatics.STRONGBOX_DELAY_OUTPUT); + // return true; + // } - itemMan = player.getCharItemManager(); + //building.getTimestamps().put(MBServerStatics.STRONGBOX_DELAY_STRING, System.currentTimeMillis() + MBServerStatics.ONE_MINUTE); - goldItem = itemMan.getGoldInventory(); + itemMan = player.getCharItemManager(); - if (goldItem == null) { - Logger.error("Could not access gold item"); - return true; - } + goldItem = itemMan.getGoldInventory(); + if (goldItem == null) { + Logger.error("Could not access gold item"); + return true; + } - // Update in-game gold values for player and building + // Update in-game gold values for player and building - try { + try { - if (!itemMan.transferGoldToFromBuilding(msg.getAmount(), building)) - return true; + if (!itemMan.transferGoldToFromBuilding(msg.getAmount(), building)) + return true; - UpdateGoldMsg ugm = new UpdateGoldMsg(player); - ugm.configure(); - dispatch = Dispatch.borrow(player, ugm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - // Refresh the player's inventory if it's currently open + UpdateGoldMsg ugm = new UpdateGoldMsg(player); + ugm.configure(); + dispatch = Dispatch.borrow(player, ugm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - // Refresh the tree's window to update strongbox + // Refresh the player's inventory if it's currently open + // Refresh the tree's window to update strongbox - msg.setAmount(building.getStrongboxValue()); - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } catch (Exception e) { - PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - } + msg.setAmount(building.getStrongboxValue()); + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - return true; - } + } catch (Exception e) { + PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + } + + return true; + } } diff --git a/src/engine/net/client/handlers/UpdateFriendStatusHandler.java b/src/engine/net/client/handlers/UpdateFriendStatusHandler.java index cba23748..90ae49f4 100644 --- a/src/engine/net/client/handlers/UpdateFriendStatusHandler.java +++ b/src/engine/net/client/handlers/UpdateFriendStatusHandler.java @@ -26,59 +26,58 @@ import java.util.HashSet; public class UpdateFriendStatusHandler extends AbstractClientMsgHandler { - public UpdateFriendStatusHandler() { - super(UpdateFriendStatusMessage.class); - } - - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, - ClientConnection origin) throws MsgSendException { - - PlayerCharacter player = origin.getPlayerCharacter(); - - if (player == null) - return true; - - - UpdateFriendStatusMessage msg = (UpdateFriendStatusMessage)baseMsg; - - - HandleUpdateFriend(player,msg); - - return true; - } - - - //change to Request - public static void HandleUpdateFriend(PlayerCharacter player, UpdateFriendStatusMessage msg){ - FriendStatus friendStatus = FriendStatus.Available; - - try { - friendStatus = FriendStatus.values()[msg.statusType]; - }catch (Exception e){ - Logger.error(e); - } - player.friendStatus = friendStatus; - SendUpdateToFriends(player); - } - - public static void SendUpdateToFriends(PlayerCharacter player){ - - HashSet friends = PlayerFriends.PlayerFriendsMap.get(player.getObjectUUID()); - - if (friends == null) - return; - - UpdateFriendStatusMessage outMsg = new UpdateFriendStatusMessage(player); - - for (int friendID : friends){ - PlayerCharacter playerFriend = SessionManager.getPlayerCharacterByID(friendID); - if (playerFriend == null) - return; - Dispatch dispatch = Dispatch.borrow(playerFriend, outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } - - - } + public UpdateFriendStatusHandler() { + super(UpdateFriendStatusMessage.class); + } + + //change to Request + public static void HandleUpdateFriend(PlayerCharacter player, UpdateFriendStatusMessage msg) { + FriendStatus friendStatus = FriendStatus.Available; + + try { + friendStatus = FriendStatus.values()[msg.statusType]; + } catch (Exception e) { + Logger.error(e); + } + player.friendStatus = friendStatus; + SendUpdateToFriends(player); + } + + public static void SendUpdateToFriends(PlayerCharacter player) { + + HashSet friends = PlayerFriends.PlayerFriendsMap.get(player.getObjectUUID()); + + if (friends == null) + return; + + UpdateFriendStatusMessage outMsg = new UpdateFriendStatusMessage(player); + + for (int friendID : friends) { + PlayerCharacter playerFriend = SessionManager.getPlayerCharacterByID(friendID); + if (playerFriend == null) + return; + Dispatch dispatch = Dispatch.borrow(playerFriend, outMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + } + + + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, + ClientConnection origin) throws MsgSendException { + + PlayerCharacter player = origin.getPlayerCharacter(); + + if (player == null) + return true; + + + UpdateFriendStatusMessage msg = (UpdateFriendStatusMessage) baseMsg; + + + HandleUpdateFriend(player, msg); + + return true; + } } diff --git a/src/engine/net/client/handlers/UpgradeAssetMsgHandler.java b/src/engine/net/client/handlers/UpgradeAssetMsgHandler.java index 3f3d0c9c..3638c2ec 100644 --- a/src/engine/net/client/handlers/UpgradeAssetMsgHandler.java +++ b/src/engine/net/client/handlers/UpgradeAssetMsgHandler.java @@ -25,130 +25,129 @@ import static engine.net.client.msg.ErrorPopupMsg.sendErrorPopup; */ public class UpgradeAssetMsgHandler extends AbstractClientMsgHandler { - // Constructor - public UpgradeAssetMsgHandler() { + // Constructor + public UpgradeAssetMsgHandler() { - super(UpgradeAssetMessage.class); - } + super(UpgradeAssetMessage.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - // Member variable declaration + // Member variable declaration - UpgradeAssetMessage msg; - ManageCityAssetsMsg outMsg; - PlayerCharacter player; - int buildingUUID; - Building buildingToRank; - LocalDateTime dateToUpgrade; - int nextRank; - int rankCost; - Dispatch dispatch; + UpgradeAssetMessage msg; + ManageCityAssetsMsg outMsg; + PlayerCharacter player; + int buildingUUID; + Building buildingToRank; + LocalDateTime dateToUpgrade; + int nextRank; + int rankCost; + Dispatch dispatch; - // Assign member variables + // Assign member variables - msg = (UpgradeAssetMessage) baseMsg; + msg = (UpgradeAssetMessage) baseMsg; - // Grab pointer to the requesting player + // Grab pointer to the requesting player - player = SessionManager.getPlayerCharacter(origin); + player = SessionManager.getPlayerCharacter(origin); - // Grab pointer to the building from the cache + // Grab pointer to the building from the cache - buildingUUID = msg.getBuildingUUID(); + buildingUUID = msg.getBuildingUUID(); - buildingToRank = (Building) DbManager.getObject(GameObjectType.Building, buildingUUID); + buildingToRank = (Building) DbManager.getObject(GameObjectType.Building, buildingUUID); - // Early exit if building not in cache. + // Early exit if building not in cache. - if (buildingToRank == null) { - Logger.error("Attempt to upgrade null building by " + player.getName()); - return true; - } + if (buildingToRank == null) { + Logger.error("Attempt to upgrade null building by " + player.getName()); + return true; + } - // Early exit for building that is already ranking + // Early exit for building that is already ranking - if (buildingToRank.isRanking()) { - Logger.error("Attempt to upgrade a building already ranking by " + player.getName()); - return true; - } + if (buildingToRank.isRanking()) { + Logger.error("Attempt to upgrade a building already ranking by " + player.getName()); + return true; + } - // Calculate and set time/cost to upgrade + // Calculate and set time/cost to upgrade - nextRank = (buildingToRank.getRank() + 1); + nextRank = (buildingToRank.getRank() + 1); - if (buildingToRank.getBlueprint() == null) - return true; - if (buildingToRank.getBlueprint().getMaxRank() < nextRank || nextRank == 8){ - ErrorPopupMsg.sendErrorMsg(player, "Building is already at it's Max rank."); - return true; - } + if (buildingToRank.getBlueprint() == null) + return true; + if (buildingToRank.getBlueprint().getMaxRank() < nextRank || nextRank == 8) { + ErrorPopupMsg.sendErrorMsg(player, "Building is already at it's Max rank."); + return true; + } - rankCost = buildingToRank.getBlueprint().getRankCost(nextRank); + rankCost = buildingToRank.getBlueprint().getRankCost(nextRank); - // SEND NOT ENOUGH GOLD ERROR + // SEND NOT ENOUGH GOLD ERROR - if (!buildingToRank.hasFunds(rankCost)){ - ErrorPopupMsg.sendErrorPopup(player, 127); // Not enough gold in strongbox - return true; - } + if (!buildingToRank.hasFunds(rankCost)) { + ErrorPopupMsg.sendErrorPopup(player, 127); // Not enough gold in strongbox + return true; + } - if (rankCost > buildingToRank.getStrongboxValue()) { - sendErrorPopup(player, 127); - return true; - } + if (rankCost > buildingToRank.getStrongboxValue()) { + sendErrorPopup(player, 127); + return true; + } - // Validation appears good. Let's now process the upgrade - - try { - if (buildingToRank.getCity() != null){ - buildingToRank.getCity().transactionLock.writeLock().lock(); - try{ - if (!buildingToRank.transferGold(-rankCost,false)) { - sendErrorPopup(player, 127); - return true; - } - }catch(Exception e){ - Logger.error(e); - }finally{ - buildingToRank.getCity().transactionLock.writeLock().unlock(); - } - }else - if (!buildingToRank.transferGold(-rankCost,false)) { - sendErrorPopup(player, 127); - return true; - } + // Validation appears good. Let's now process the upgrade - dateToUpgrade = LocalDateTime.now().plusHours(buildingToRank.getBlueprint().getRankTime(nextRank)); + try { + if (buildingToRank.getCity() != null) { + buildingToRank.getCity().transactionLock.writeLock().lock(); + try { + if (!buildingToRank.transferGold(-rankCost, false)) { + sendErrorPopup(player, 127); + return true; + } + } catch (Exception e) { + Logger.error(e); + } finally { + buildingToRank.getCity().transactionLock.writeLock().unlock(); + } + } else if (!buildingToRank.transferGold(-rankCost, false)) { + sendErrorPopup(player, 127); + return true; + } - BuildingManager.setUpgradeDateTime(buildingToRank, dateToUpgrade, 0); + dateToUpgrade = LocalDateTime.now().plusHours(buildingToRank.getBlueprint().getRankTime(nextRank)); - // Schedule upgrade job + BuildingManager.setUpgradeDateTime(buildingToRank, dateToUpgrade, 0); - BuildingManager.submitUpgradeJob(buildingToRank); + // Schedule upgrade job - // Refresh the client's manage asset window - // *** Refactor : We have some of these unknowns + BuildingManager.submitUpgradeJob(buildingToRank); - outMsg = new ManageCityAssetsMsg(player, buildingToRank); + // Refresh the client's manage asset window + // *** Refactor : We have some of these unknowns - // Action TYPE - outMsg.actionType = 3; - outMsg.setTargetType(buildingToRank.getObjectType().ordinal()); - outMsg.setTargetID(buildingToRank.getObjectUUID()); - outMsg.setTargetType3(buildingToRank.getObjectType().ordinal()); - outMsg.setTargetID3(buildingToRank.getObjectUUID()); - outMsg.setAssetName1(buildingToRank.getName()); - outMsg.setUnknown54(1); + outMsg = new ManageCityAssetsMsg(player, buildingToRank); - dispatch = Dispatch.borrow(player, outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + // Action TYPE + outMsg.actionType = 3; + outMsg.setTargetType(buildingToRank.getObjectType().ordinal()); + outMsg.setTargetID(buildingToRank.getObjectUUID()); + outMsg.setTargetType3(buildingToRank.getObjectType().ordinal()); + outMsg.setTargetID3(buildingToRank.getObjectUUID()); + outMsg.setAssetName1(buildingToRank.getName()); + outMsg.setUnknown54(1); - } catch (Exception e) { - PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - } + dispatch = Dispatch.borrow(player, outMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - return true; - } + } catch (Exception e) { + PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + } + + return true; + } } diff --git a/src/engine/net/client/msg/AbandonAssetMsg.java b/src/engine/net/client/msg/AbandonAssetMsg.java index 38bfb67e..51e1b19a 100644 --- a/src/engine/net/client/msg/AbandonAssetMsg.java +++ b/src/engine/net/client/msg/AbandonAssetMsg.java @@ -28,7 +28,7 @@ public class AbandonAssetMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public AbandonAssetMsg(AbstractConnection origin, ByteBufferReader reader){ + public AbandonAssetMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.ABANDONASSET, origin, reader); } @@ -36,7 +36,7 @@ public class AbandonAssetMsg extends ClientNetMsg { * Deserializes the subclass specific items from the supplied NetMsgReader. */ @Override - protected void _deserialize(ByteBufferReader reader) { + protected void _deserialize(ByteBufferReader reader) { this.pad = reader.getInt(); this.objectType = reader.getInt(); this.objectUUID = reader.getInt(); @@ -60,10 +60,6 @@ public class AbandonAssetMsg extends ClientNetMsg { this.objectType = value; } - public void setPad(int value) { - this.pad = value; - } - public int getUUID() { return objectUUID; @@ -72,4 +68,8 @@ public class AbandonAssetMsg extends ClientNetMsg { public int getPad() { return pad; } + + public void setPad(int value) { + this.pad = value; + } } diff --git a/src/engine/net/client/msg/AcceptFriendMsg.java b/src/engine/net/client/msg/AcceptFriendMsg.java index c0344689..b309e78e 100644 --- a/src/engine/net/client/msg/AcceptFriendMsg.java +++ b/src/engine/net/client/msg/AcceptFriendMsg.java @@ -15,51 +15,50 @@ import engine.objects.PlayerCharacter; public class AcceptFriendMsg extends ClientNetMsg { - public String sourceName; - public String friendName; + public String sourceName; + public String friendName; - /** - * This is the general purpose constructor. - */ - public AcceptFriendMsg(PlayerCharacter pc) { - super(Protocol.FRIENDACCEPT); - } + /** + * This is the general purpose constructor. + */ + public AcceptFriendMsg(PlayerCharacter pc) { + super(Protocol.FRIENDACCEPT); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public AcceptFriendMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.FRIENDACCEPT, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public AcceptFriendMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.FRIENDACCEPT, origin, reader); + } - /** - * Copy constructor - */ - public AcceptFriendMsg(AcceptFriendMsg msg) { - super(Protocol.FRIENDACCEPT); - } + /** + * Copy constructor + */ + public AcceptFriendMsg(AcceptFriendMsg msg) { + super(Protocol.FRIENDACCEPT); + } - - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - //Do we even want to try this? - this.sourceName = reader.getString(); //This is source name.. this friends list must never been updated since launch, not using IDS. - this.friendName = reader.getString(); - } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putString(this.sourceName); - writer.putString(this.friendName); - } + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + //Do we even want to try this? + this.sourceName = reader.getString(); //This is source name.. this friends list must never been updated since launch, not using IDS. + this.friendName = reader.getString(); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putString(this.sourceName); + writer.putString(this.friendName); + } } diff --git a/src/engine/net/client/msg/AcceptTradeRequestMsg.java b/src/engine/net/client/msg/AcceptTradeRequestMsg.java index 2e2f3344..e0f63f5e 100644 --- a/src/engine/net/client/msg/AcceptTradeRequestMsg.java +++ b/src/engine/net/client/msg/AcceptTradeRequestMsg.java @@ -29,7 +29,7 @@ public class AcceptTradeRequestMsg extends ClientNetMsg { private int playerID; private int targetType; private int targetID; - + /** * This is the general purpose constructor @@ -38,9 +38,9 @@ public class AcceptTradeRequestMsg extends ClientNetMsg { super(Protocol.REQUESTTRADEOK); this.unknown01 = unknown01; this.playerType = player.getObjectType().ordinal(); - this.playerID =player.getObjectUUID(); + this.playerID = player.getObjectUUID(); this.targetType = target.getObjectType().ordinal(); - this.targetID =target.getObjectUUID(); + this.targetID = target.getObjectUUID(); } /** @@ -49,8 +49,7 @@ public class AcceptTradeRequestMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public AcceptTradeRequestMsg(AbstractConnection origin, ByteBufferReader reader) - { + public AcceptTradeRequestMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.REQUESTTRADEOK, origin, reader); } @@ -58,14 +57,13 @@ public class AcceptTradeRequestMsg extends ClientNetMsg { * Deserializes the subclass specific items to the supplied NetMsgWriter. */ @Override - protected void _deserialize(ByteBufferReader reader) - { + protected void _deserialize(ByteBufferReader reader) { unknown01 = reader.getInt(); playerType = reader.getInt(); playerID = reader.getInt(); targetType = reader.getInt(); targetID = reader.getInt(); - + } /** @@ -95,39 +93,37 @@ public class AcceptTradeRequestMsg extends ClientNetMsg { this.unknown01 = unknown01; } - - - public int getPlayerType() { - return playerType; - } + public int getPlayerType() { + return playerType; + } - public void setPlayerType(int playerType) { - this.playerType = playerType; - } + public void setPlayerType(int playerType) { + this.playerType = playerType; + } - public int getPlayerID() { - return playerID; - } + public int getPlayerID() { + return playerID; + } - public void setPlayerID(int playerID) { - this.playerID = playerID; - } + public void setPlayerID(int playerID) { + this.playerID = playerID; + } - public int getTargetType() { - return targetType; - } + public int getTargetType() { + return targetType; + } - public void setTargetType(int targetType) { - this.targetType = targetType; - } + public void setTargetType(int targetType) { + this.targetType = targetType; + } - public int getTargetID() { - return targetID; - } + public int getTargetID() { + return targetID; + } - public void setTargetID(int targetID) { - this.targetID = targetID; - } + public void setTargetID(int targetID) { + this.targetID = targetID; + } } diff --git a/src/engine/net/client/msg/AckBankWindowOpenedMsg.java b/src/engine/net/client/msg/AckBankWindowOpenedMsg.java index c33d0a29..c3a98d35 100644 --- a/src/engine/net/client/msg/AckBankWindowOpenedMsg.java +++ b/src/engine/net/client/msg/AckBankWindowOpenedMsg.java @@ -24,9 +24,9 @@ import engine.objects.PlayerCharacter; */ public class AckBankWindowOpenedMsg extends ClientNetMsg { - private int playerType; - private int playerID; - private long unknown01; // possibly NPC ID? + private int playerType; + private int playerID; + private long unknown01; // possibly NPC ID? private long unknown02; /** @@ -46,7 +46,7 @@ public class AckBankWindowOpenedMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public AckBankWindowOpenedMsg(AbstractConnection origin, ByteBufferReader reader) { + public AckBankWindowOpenedMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.COSTTOOPENBANK, origin, reader); } @@ -54,9 +54,9 @@ public class AckBankWindowOpenedMsg extends ClientNetMsg { * Deserializes the subclass specific items to the supplied NetMsgWriter. */ @Override - protected void _deserialize(ByteBufferReader reader) { - playerType = reader.getInt(); - playerID = reader.getInt(); + protected void _deserialize(ByteBufferReader reader) { + playerType = reader.getInt(); + playerID = reader.getInt(); unknown01 = reader.getLong(); unknown02 = reader.getLong(); } @@ -66,25 +66,26 @@ public class AckBankWindowOpenedMsg extends ClientNetMsg { */ @Override protected void _serialize(ByteBufferWriter writer) throws SerializationException { - writer.putInt(playerType); - writer.putInt(playerID); + writer.putInt(playerType); + writer.putInt(playerID); writer.putLong(unknown01); writer.putLong(unknown02); } + public int getPlayerID() { - return playerID; - } + return playerID; + } - public void setPlayerID(int playerID) { - this.playerID = playerID; - } + public void setPlayerID(int playerID) { + this.playerID = playerID; + } - public int getPlayerType() { - return playerType; - } + public int getPlayerType() { + return playerType; + } - public void setPlayerType(int playerType) { - this.playerType = playerType; - } + public void setPlayerType(int playerType) { + this.playerType = playerType; + } } diff --git a/src/engine/net/client/msg/ActivateNPCMessage.java b/src/engine/net/client/msg/ActivateNPCMessage.java index 7a44e778..985acbf9 100644 --- a/src/engine/net/client/msg/ActivateNPCMessage.java +++ b/src/engine/net/client/msg/ActivateNPCMessage.java @@ -39,7 +39,6 @@ public class ActivateNPCMessage extends ClientNetMsg { /** * This is the general purpose constructor. - * */ public ActivateNPCMessage(ArrayList items) { super(Protocol.ACTIVATENPC); @@ -54,7 +53,7 @@ public class ActivateNPCMessage extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public ActivateNPCMessage(AbstractConnection origin, ByteBufferReader reader) { + public ActivateNPCMessage(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.ACTIVATENPC, origin, reader); } @@ -77,9 +76,9 @@ public class ActivateNPCMessage extends ClientNetMsg { } writer.putInt(this.size); for (Item item : this.ItemList) { - writer.putInt(item.getObjectType().ordinal()); - writer.putInt(item.getObjectUUID()); - + writer.putInt(item.getObjectType().ordinal()); + writer.putInt(item.getObjectUUID()); + } } @@ -87,7 +86,7 @@ public class ActivateNPCMessage extends ClientNetMsg { * Deserializes the subclass specific items from the supplied NetMsgReader. */ @Override - protected void _deserialize(ByteBufferReader reader) { + protected void _deserialize(ByteBufferReader reader) { unknown01 = reader.getInt(); unknown02 = reader.getInt(); reader.getInt(); // Object Type Padding @@ -108,50 +107,50 @@ public class ActivateNPCMessage extends ClientNetMsg { return unknown01; } + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + public int getUnknown02() { return unknown02; } + public void setUnknown02(int unknown02) { + this.unknown02 = unknown02; + } + public int getUnknown03() { return unknown03; } + public void setUnknown03(int unknown03) { + this.unknown03 = unknown03; + } + public int getContractItem() { return contractItem; } + public void setContractItem(int contractItem) { + this.contractItem = contractItem; + } + public int getUnknown05() { return unknown05; } - public int buildingUUID() { - return buildingUUID; + public void setUnknown05(int unknown05) { + this.unknown05 = unknown05; } - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; + public int buildingUUID() { + return buildingUUID; } public void setSize(int size) { this.size = size; } - public void setUnknown02(int unknown02) { - this.unknown02 = unknown02; - } - - public void setUnknown03(int unknown03) { - this.unknown03 = unknown03; - } - - public void setContractItem(int contractItem) { - this.contractItem = contractItem; - } - - public void setUnknown05(int unknown05) { - this.unknown05 = unknown05; - } - public void setItemList(ArrayList value) { this.ItemList = value; } diff --git a/src/engine/net/client/msg/AddFriendMessage.java b/src/engine/net/client/msg/AddFriendMessage.java index 9d8d33f1..f84010b5 100644 --- a/src/engine/net/client/msg/AddFriendMessage.java +++ b/src/engine/net/client/msg/AddFriendMessage.java @@ -16,52 +16,51 @@ import engine.objects.PlayerCharacter; public class AddFriendMessage extends ClientNetMsg { - public PlayerCharacter friend; + public PlayerCharacter friend; - /** - * This is the general purpose constructor. - */ - public AddFriendMessage(PlayerCharacter pc) { - super(Protocol.ADDFRIEND); - friend = pc; - } + /** + * This is the general purpose constructor. + */ + public AddFriendMessage(PlayerCharacter pc) { + super(Protocol.ADDFRIEND); + friend = pc; + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public AddFriendMessage(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ADDFRIEND, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public AddFriendMessage(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ADDFRIEND, origin, reader); + } - /** - * Copy constructor - */ - public AddFriendMessage(AddFriendMessage msg) { - super(Protocol.ADDFRIEND); - } + /** + * Copy constructor + */ + public AddFriendMessage(AddFriendMessage msg) { + super(Protocol.ADDFRIEND); + } - - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - //message is serialize only, no need for deserialize. - @Override - protected void _deserialize(ByteBufferReader reader) { - } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(GameObjectType.PlayerCharacter.ordinal()); - writer.putInt(friend.getObjectUUID()); - writer.putString(friend.getName()); - writer.putInt(0); //possibly available, busy, away? - writer.putInt(0); - } + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + //message is serialize only, no need for deserialize. + @Override + protected void _deserialize(ByteBufferReader reader) { + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(GameObjectType.PlayerCharacter.ordinal()); + writer.putInt(friend.getObjectUUID()); + writer.putString(friend.getName()); + writer.putInt(0); //possibly available, busy, away? + writer.putInt(0); + } } diff --git a/src/engine/net/client/msg/AddGoldToTradeWindowMsg.java b/src/engine/net/client/msg/AddGoldToTradeWindowMsg.java index 462d6334..ee1ab4ff 100644 --- a/src/engine/net/client/msg/AddGoldToTradeWindowMsg.java +++ b/src/engine/net/client/msg/AddGoldToTradeWindowMsg.java @@ -39,8 +39,7 @@ public class AddGoldToTradeWindowMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public AddGoldToTradeWindowMsg(AbstractConnection origin, ByteBufferReader reader) - { + public AddGoldToTradeWindowMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.TRADEADDGOLD, origin, reader); } @@ -48,8 +47,7 @@ public class AddGoldToTradeWindowMsg extends ClientNetMsg { * Deserializes the subclass specific items to the supplied NetMsgWriter. */ @Override - protected void _deserialize(ByteBufferReader reader) - { + protected void _deserialize(ByteBufferReader reader) { unknown01 = reader.getInt(); playerCompID = reader.getLong(); amount = reader.getInt(); diff --git a/src/engine/net/client/msg/AddItemToTradeWindowMsg.java b/src/engine/net/client/msg/AddItemToTradeWindowMsg.java index 5d420d70..c66c4b9b 100644 --- a/src/engine/net/client/msg/AddItemToTradeWindowMsg.java +++ b/src/engine/net/client/msg/AddItemToTradeWindowMsg.java @@ -24,7 +24,7 @@ public class AddItemToTradeWindowMsg extends ClientNetMsg { private int playerID; private int itemID; private int itemType; - + /** * This is the general purpose constructor @@ -44,8 +44,7 @@ public class AddItemToTradeWindowMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public AddItemToTradeWindowMsg(AbstractConnection origin, ByteBufferReader reader) - { + public AddItemToTradeWindowMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.TRADEADDOBJECT, origin, reader); } @@ -53,8 +52,7 @@ public class AddItemToTradeWindowMsg extends ClientNetMsg { * Deserializes the subclass specific items to the supplied NetMsgWriter. */ @Override - protected void _deserialize(ByteBufferReader reader) - { + protected void _deserialize(ByteBufferReader reader) { unknown01 = reader.getInt(); playerType = reader.getInt(); playerID = reader.getInt(); @@ -89,32 +87,29 @@ public class AddItemToTradeWindowMsg extends ClientNetMsg { this.unknown01 = unknown01; } - - - - public int getPlayerType() { - return playerType; - } + public int getPlayerType() { + return playerType; + } - public void setPlayerType(int playerType) { - this.playerType = playerType; - } + public void setPlayerType(int playerType) { + this.playerType = playerType; + } - public int getPlayerID() { - return playerID; - } + public int getPlayerID() { + return playerID; + } - public void setPlayerID(int playerID) { - this.playerID = playerID; - } + public void setPlayerID(int playerID) { + this.playerID = playerID; + } - public int getItemID() { - return itemID; - } + public int getItemID() { + return itemID; + } - public void setItemID(int itemID) { - this.itemID = itemID; - } + public void setItemID(int itemID) { + this.itemID = itemID; + } } diff --git a/src/engine/net/client/msg/AllianceChangeMsg.java b/src/engine/net/client/msg/AllianceChangeMsg.java index a1023b46..cab833c4 100644 --- a/src/engine/net/client/msg/AllianceChangeMsg.java +++ b/src/engine/net/client/msg/AllianceChangeMsg.java @@ -18,127 +18,123 @@ import engine.net.client.Protocol; import engine.objects.PlayerCharacter; - public class AllianceChangeMsg extends ClientNetMsg { - public final static int MAKE_ENEMY = 4; - public final static int MAKE_ALLY = 6; - public final static int REMOVE = 7; - public final static byte INFO_SUCCESS = 0; - public final static byte ERROR_NOT_RECOMMENDED = 1; - public final static byte ERROR_NOT_SAME_GUILD = 2; - public final static byte ERROR_NOT_AUTHORIZED = 4; - public final static byte ERROR_NOT_SAME_FACTION = 7; - public final static byte ERROR_TOO_MANY = 13; - public final static byte ERROR_TO0_EARLY = 14; - private byte msgType; - private int sourceGuildID; - private int targetGuildID; - private int secondsToWait; - private boolean ally; - - - public AllianceChangeMsg(PlayerCharacter player, int sourceGuildID,int targetGuildID, byte msgType, int secondsToWait) { - super(Protocol.ALLIANCECHANGE); - this.sourceGuildID = sourceGuildID; - this.targetGuildID = targetGuildID; - this.msgType = msgType; - this.secondsToWait = secondsToWait; - - } - - public AllianceChangeMsg() { - super(Protocol.ALLIANCECHANGE); - } - - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public AllianceChangeMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ALLIANCECHANGE, origin, reader); - } - //CALL THIS AFTER SANITY CHECKS AND BEFORE UPDATING HEALTH/GOLD. - - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.msgType = reader.get(); - - switch (this.msgType){ - case 1: - case 2: - case 3: - case MAKE_ENEMY: - case MAKE_ALLY: - case REMOVE: - case 5: - reader.getInt(); //source guild type; - this.sourceGuildID = reader.getInt(); - reader.getInt(); - this.targetGuildID = reader.getInt(); - break; - - - } - - - - - } - - - // Precache and configure this message before we serialize it - - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - writer.put(this.msgType); - if (this.msgType == ERROR_TO0_EARLY) - writer.putInt(this.secondsToWait); - writer.putInt(GameObjectType.Guild.ordinal()); - writer.putInt(this.sourceGuildID); - writer.putInt(GameObjectType.Guild.ordinal()); - writer.putInt(this.targetGuildID); - - - - } - - - public int getSecondsToWait() { - return secondsToWait; - } - - public void setSecondsToWait(int secondsToWait) { - this.secondsToWait = secondsToWait; - } - - public int getMsgType() { - return msgType; - } - - public int getSourceGuildID() { - return sourceGuildID; - } - - public int getTargetGuildID() { - return targetGuildID; - } + public final static int MAKE_ENEMY = 4; + public final static int MAKE_ALLY = 6; + public final static int REMOVE = 7; + public final static byte INFO_SUCCESS = 0; + public final static byte ERROR_NOT_RECOMMENDED = 1; + public final static byte ERROR_NOT_SAME_GUILD = 2; + public final static byte ERROR_NOT_AUTHORIZED = 4; + public final static byte ERROR_NOT_SAME_FACTION = 7; + public final static byte ERROR_TOO_MANY = 13; + public final static byte ERROR_TO0_EARLY = 14; + private byte msgType; + private int sourceGuildID; + private int targetGuildID; + private int secondsToWait; + private boolean ally; + + + public AllianceChangeMsg(PlayerCharacter player, int sourceGuildID, int targetGuildID, byte msgType, int secondsToWait) { + super(Protocol.ALLIANCECHANGE); + this.sourceGuildID = sourceGuildID; + this.targetGuildID = targetGuildID; + this.msgType = msgType; + this.secondsToWait = secondsToWait; + + } + + public AllianceChangeMsg() { + super(Protocol.ALLIANCECHANGE); + } + + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public AllianceChangeMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ALLIANCECHANGE, origin, reader); + } + //CALL THIS AFTER SANITY CHECKS AND BEFORE UPDATING HEALTH/GOLD. + + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.msgType = reader.get(); + + switch (this.msgType) { + case 1: + case 2: + case 3: + case MAKE_ENEMY: + case MAKE_ALLY: + case REMOVE: + case 5: + reader.getInt(); //source guild type; + this.sourceGuildID = reader.getInt(); + reader.getInt(); + this.targetGuildID = reader.getInt(); + break; + + + } + + + } + + + // Precache and configure this message before we serialize it + + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + writer.put(this.msgType); + if (this.msgType == ERROR_TO0_EARLY) + writer.putInt(this.secondsToWait); + writer.putInt(GameObjectType.Guild.ordinal()); + writer.putInt(this.sourceGuildID); + writer.putInt(GameObjectType.Guild.ordinal()); + writer.putInt(this.targetGuildID); + + + } + + + public int getSecondsToWait() { + return secondsToWait; + } + + public void setSecondsToWait(int secondsToWait) { + this.secondsToWait = secondsToWait; + } + + public int getMsgType() { + return msgType; + } + + public void setMsgType(byte msgType) { + this.msgType = msgType; + } + + public int getSourceGuildID() { + return sourceGuildID; + } - public boolean isAlly() { - return ally; - } + public int getTargetGuildID() { + return targetGuildID; + } - public void setMsgType(byte msgType) { - this.msgType = msgType; - } + public boolean isAlly() { + return ally; + } } diff --git a/src/engine/net/client/msg/AllyEnemyListMsg.java b/src/engine/net/client/msg/AllyEnemyListMsg.java index aa47bb9a..7e335049 100644 --- a/src/engine/net/client/msg/AllyEnemyListMsg.java +++ b/src/engine/net/client/msg/AllyEnemyListMsg.java @@ -21,102 +21,101 @@ import engine.objects.GuildTag; import engine.objects.PlayerCharacter; - public class AllyEnemyListMsg extends ClientNetMsg { - private int guildID; + private int guildID; - public AllyEnemyListMsg(PlayerCharacter player) { - super(Protocol.ALLYENEMYLIST); - this.guildID = player.getGuildUUID(); + public AllyEnemyListMsg(PlayerCharacter player) { + super(Protocol.ALLYENEMYLIST); + this.guildID = player.getGuildUUID(); - } + } - public AllyEnemyListMsg() { - super(Protocol.ALLYENEMYLIST); - } + public AllyEnemyListMsg() { + super(Protocol.ALLYENEMYLIST); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public AllyEnemyListMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ALLYENEMYLIST, origin, reader); - } - //CALL THIS AFTER SANITY CHECKS AND BEFORE UPDATING HEALTH/GOLD. + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public AllyEnemyListMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ALLYENEMYLIST, origin, reader); + } + //CALL THIS AFTER SANITY CHECKS AND BEFORE UPDATING HEALTH/GOLD. - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - reader.getInt(); - this.guildID = reader.getInt(); - } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.getInt(); + this.guildID = reader.getInt(); + } - // Precache and configure this message before we serialize it + // Precache and configure this message before we serialize it - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { - writer.putInt(GameObjectType.Guild.ordinal()); - writer.putInt(this.guildID); + writer.putInt(GameObjectType.Guild.ordinal()); + writer.putInt(this.guildID); - Guild guild = Guild.getGuild(this.guildID); + Guild guild = Guild.getGuild(this.guildID); - writer.putInt(guild.getAllyList().size()); + writer.putInt(guild.getAllyList().size()); - for (Guild ally: guild.getAllyList()){ - writer.putInt(GameObjectType.Guild.ordinal());//guildType - writer.putInt(ally.getObjectUUID());//GuildID - writer.putString(ally.getName()); - GuildTag._serializeForDisplay(ally.getGuildTag(),writer); - writer.put((byte)0); - } + for (Guild ally : guild.getAllyList()) { + writer.putInt(GameObjectType.Guild.ordinal());//guildType + writer.putInt(ally.getObjectUUID());//GuildID + writer.putString(ally.getName()); + GuildTag._serializeForDisplay(ally.getGuildTag(), writer); + writer.put((byte) 0); + } - writer.putInt(guild.getEnemyList().size()); + writer.putInt(guild.getEnemyList().size()); - for (Guild enemy: guild.getEnemyList()){ - writer.putInt(GameObjectType.Guild.ordinal());//guildType - writer.putInt(enemy.getObjectUUID());//GuildID - writer.putString(enemy.getName()); - GuildTag._serializeForDisplay(enemy.getGuildTag(),writer); - writer.put((byte)1); - } + for (Guild enemy : guild.getEnemyList()) { + writer.putInt(GameObjectType.Guild.ordinal());//guildType + writer.putInt(enemy.getObjectUUID());//GuildID + writer.putString(enemy.getName()); + GuildTag._serializeForDisplay(enemy.getGuildTag(), writer); + writer.put((byte) 1); + } - writer.putInt(guild.getRecommendList().size()); - for (Guild recommended: guild.getRecommendList()){ + writer.putInt(guild.getRecommendList().size()); + for (Guild recommended : guild.getRecommendList()) { - GuildAlliances guildAlliance = guild.guildAlliances.get(recommended.getObjectUUID()); - writer.putInt(GameObjectType.Guild.ordinal());//guildType - writer.putInt(recommended.getObjectUUID());//GuildID - writer.putString(recommended.getName()); - GuildTag._serializeForDisplay(recommended.getGuildTag(),writer); - writer.put((byte)1); // ? - writer.putString(guildAlliance.getRecommender()); // recommender name. - writer.put((byte) (guildAlliance.isAlly()?1:0)); //ally 1 enemy 0 + GuildAlliances guildAlliance = guild.guildAlliances.get(recommended.getObjectUUID()); + writer.putInt(GameObjectType.Guild.ordinal());//guildType + writer.putInt(recommended.getObjectUUID());//GuildID + writer.putString(recommended.getName()); + GuildTag._serializeForDisplay(recommended.getGuildTag(), writer); + writer.put((byte) 1); // ? + writer.putString(guildAlliance.getRecommender()); // recommender name. + writer.put((byte) (guildAlliance.isAlly() ? 1 : 0)); //ally 1 enemy 0 - } + } - writer.put((byte)1); + writer.put((byte) 1); - } + } - public int getGuildID() { - return guildID; - } + public int getGuildID() { + return guildID; + } } diff --git a/src/engine/net/client/msg/ApplyBuildingEffectMsg.java b/src/engine/net/client/msg/ApplyBuildingEffectMsg.java index 0aa953e0..f1b221fa 100644 --- a/src/engine/net/client/msg/ApplyBuildingEffectMsg.java +++ b/src/engine/net/client/msg/ApplyBuildingEffectMsg.java @@ -18,93 +18,93 @@ import engine.net.client.Protocol; public class ApplyBuildingEffectMsg extends ClientNetMsg { - protected int unknown01; - protected int unknown02; - protected int buildingType; - protected int buildingID; - protected int unknown03; - - /** - * This is the general purpose constructor. - */ - public ApplyBuildingEffectMsg() { - super(Protocol.VISUALUPDATE); - } - - public ApplyBuildingEffectMsg(int unknown01, int unknown02, int buildingType, int buildingID, int unknown03) { - super(Protocol.VISUALUPDATE); - this.unknown01 = unknown01; - this.unknown02 = unknown02; - this.buildingType = buildingType; - this.buildingID = buildingID; - this.unknown03 = unknown03; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ApplyBuildingEffectMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.VISUALUPDATE, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - if (this.unknown02 == 0){ - writer.putInt(this.unknown03); - writer.putInt(this.buildingType); - writer.putInt(this.buildingID); - writer.putInt(0); - return; - } - writer.putInt(this.buildingType); - writer.putInt(this.buildingID); - writer.putInt(this.unknown03); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - } - - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - public void setUnknown02(int unknown02) { - this.unknown02 = unknown02; - } - - public void setBuildingID(int buildingID) { - this.buildingID = buildingID; - } - - public void setUnknown03(int unknown03) { - this.unknown03 = unknown03; - } - - public int getUnknown01() { - return unknown01; - } - - public int getUnknown02() { - return unknown02; - } - - public int getBuildingID() { - return buildingID; - } - - public int getUnknown03() { - return unknown03; - } + protected int unknown01; + protected int unknown02; + protected int buildingType; + protected int buildingID; + protected int unknown03; + + /** + * This is the general purpose constructor. + */ + public ApplyBuildingEffectMsg() { + super(Protocol.VISUALUPDATE); + } + + public ApplyBuildingEffectMsg(int unknown01, int unknown02, int buildingType, int buildingID, int unknown03) { + super(Protocol.VISUALUPDATE); + this.unknown01 = unknown01; + this.unknown02 = unknown02; + this.buildingType = buildingType; + this.buildingID = buildingID; + this.unknown03 = unknown03; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ApplyBuildingEffectMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.VISUALUPDATE, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + if (this.unknown02 == 0) { + writer.putInt(this.unknown03); + writer.putInt(this.buildingType); + writer.putInt(this.buildingID); + writer.putInt(0); + return; + } + writer.putInt(this.buildingType); + writer.putInt(this.buildingID); + writer.putInt(this.unknown03); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + } + + public int getUnknown01() { + return unknown01; + } + + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + public int getUnknown02() { + return unknown02; + } + + public void setUnknown02(int unknown02) { + this.unknown02 = unknown02; + } + + public int getBuildingID() { + return buildingID; + } + + public void setBuildingID(int buildingID) { + this.buildingID = buildingID; + } + + public int getUnknown03() { + return unknown03; + } + + public void setUnknown03(int unknown03) { + this.unknown03 = unknown03; + } } diff --git a/src/engine/net/client/msg/ApplyEffectMsg.java b/src/engine/net/client/msg/ApplyEffectMsg.java index 1644c011..b0179ce6 100644 --- a/src/engine/net/client/msg/ApplyEffectMsg.java +++ b/src/engine/net/client/msg/ApplyEffectMsg.java @@ -63,7 +63,7 @@ public class ApplyEffectMsg extends ClientNetMsg { * This is the general purpose constructor. */ public ApplyEffectMsg(AbstractWorldObject source, AbstractWorldObject target, int numTrains, int effectID, int duration, - int powerUsedID, String powerUsedName) { + int powerUsedID, String powerUsedName) { super(Protocol.POWERACTION); this.numTrains = numTrains; this.effectID = effectID; @@ -99,7 +99,7 @@ public class ApplyEffectMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public ApplyEffectMsg(AbstractConnection origin, ByteBufferReader reader) { + public ApplyEffectMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.POWERACTION, origin, reader); } @@ -125,9 +125,7 @@ public class ApplyEffectMsg extends ClientNetMsg { if (this.unknown06 == (byte) 1) { writer.putInt(this.effectSourceType); writer.putInt(this.effectSourceID); - } - - else { + } else { writer.putInt(this.powerUsedID); } @@ -138,7 +136,7 @@ public class ApplyEffectMsg extends ClientNetMsg { * Deserializes the subclass specific items from the supplied NetMsgReader. */ @Override - protected void _deserialize(ByteBufferReader reader) { + protected void _deserialize(ByteBufferReader reader) { this.numTrains = reader.getInt(); this.effectID = reader.getInt(); @@ -162,86 +160,86 @@ public class ApplyEffectMsg extends ClientNetMsg { return this.numTrains; } - public int getEffectID() { - return this.effectID; - } - - public int getSourceType() { - return this.sourceType; - } - - public int getSourceID() { - return this.sourceID; - } - - public int getTargetType() { - return this.targetType; - } - - public int getTargetID() { - return this.targetID; - } - - public int getUnknown02() { - return this.unknown02; - } - - public int getUnknown03() { - return this.unknown03; - } - - public int getDuration() { - return this.duration; - } - - public int getUnknown05() { - return this.unknown05; - } - - public byte getUnknown06() { - return this.unknown06; - } - public void setNumTrains(int value) { this.numTrains = value; } + public int getEffectID() { + return this.effectID; + } + public void setEffectID(int value) { this.effectID = value; } + public int getSourceType() { + return this.sourceType; + } + public void setSourceType(int value) { this.sourceType = value; } + public int getSourceID() { + return this.sourceID; + } + public void setSourceID(int value) { this.sourceID = value; } + public int getTargetType() { + return this.targetType; + } + public void setTargetType(int value) { this.targetType = value; } + public int getTargetID() { + return this.targetID; + } + public void setTargetID(int value) { this.targetID = value; } + public int getUnknown02() { + return this.unknown02; + } + public void setUnknown02(int value) { this.unknown02 = value; } + public int getUnknown03() { + return this.unknown03; + } + public void setUnknown03(int value) { this.unknown03 = value; } + public int getDuration() { + return this.duration; + } + public void setDuration(int value) { this.duration = value; } + public int getUnknown05() { + return this.unknown05; + } + public void setUnknown05(int value) { this.unknown05 = value; } + public byte getUnknown06() { + return this.unknown06; + } + public void setUnknown06(byte value) { this.unknown06 = value; } @@ -255,10 +253,10 @@ public class ApplyEffectMsg extends ClientNetMsg { } public void setEffectSourceType(int effectSourceType) { - this.effectSourceType = effectSourceType; - } + this.effectSourceType = effectSourceType; + } public void setEffectSourceID(int effectSourceID) { - this.effectSourceID = effectSourceID; - } + this.effectSourceID = effectSourceID; + } } diff --git a/src/engine/net/client/msg/ApplyRuneMsg.java b/src/engine/net/client/msg/ApplyRuneMsg.java index 5850e67e..6c6b893f 100644 --- a/src/engine/net/client/msg/ApplyRuneMsg.java +++ b/src/engine/net/client/msg/ApplyRuneMsg.java @@ -26,368 +26,368 @@ import java.util.concurrent.ConcurrentHashMap; public class ApplyRuneMsg extends ClientNetMsg { - private int targetType; - private int targetID; - private int removeRuneBase; - private int runeBase; - private int runeType; - private int runeID; - private Boolean isPromo; - - /** - * This is the general purpose constructor. - */ - public ApplyRuneMsg(int targetType, int targetID, int runeBase, int runeType, int runeID, Boolean isPromo) { - super(Protocol.SETRUNE); - this.targetType = targetType; - this.targetID = targetID; - this.runeBase = runeBase; - this.runeType = runeType; - this.runeID = runeID; - this.isPromo = isPromo; - this.removeRuneBase = 0; - } - - public ApplyRuneMsg(int targetType, int targetID, int removeRuneBase) { - super(Protocol.SETRUNE); - this.targetType = targetType; - this.targetID = targetID; - this.runeBase = 0; - this.runeType = 0; - this.runeID = 0; - this.isPromo = false; - this.removeRuneBase = removeRuneBase; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ApplyRuneMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.SETRUNE, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.targetType); - writer.putInt(this.targetID); - writer.putInt(0); - writer.putInt(this.removeRuneBase); - writer.putInt(0); - writer.putInt(this.runeBase); - writer.putInt(this.runeType); - writer.putInt(this.runeID); - if (this.isPromo) { - writer.put((byte) 1); - } else { - writer.put((byte) 0); - } - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - reader.getInt(); - this.removeRuneBase = reader.getInt(); - reader.getInt(); - this.runeBase = reader.getInt(); - this.runeType = reader.getInt(); - this.runeID = reader.getInt(); - this.isPromo = (reader.get() == 1) ? true : false; - } - - public int getTargetType() { - return targetType; - } - - public void setTargetType(int value) { - this.targetType = value; - } - - public int getTargetID() { - return targetID; - } - - public void setTargetID(int value) { - this.targetID = value; - } - - public int getRuneID() { - return runeID; - } - - public void setRuneID(int value) { - this.runeID = value; - } - - public static boolean applyRune(int runeID, ClientConnection origin, PlayerCharacter playerCharacter) { - - RuneBase rb = RuneBase.getRuneBase(runeID); - Dispatch dispatch; - - if (playerCharacter == null || origin == null || rb == null) { - return false; - } - - //Check race is met - ConcurrentHashMap races = rb.getRace(); - if (races.size() > 0) { - int raceID = playerCharacter.getRaceID(); - boolean valid = false; - for (int validID : races.keySet()) { - if (validID == raceID) { - valid = true; - break; - } - } - if (!valid) { - return false; - } - } - - //Check base class is met - ConcurrentHashMap baseClasses = rb.getBaseClass(); - if (baseClasses.size() > 0) { - int baseClassID = playerCharacter.getBaseClassID(); - boolean valid = false; - for (int validID : baseClasses.keySet()) { - if (validID == baseClassID) { - valid = true; - break; - } - } - if (!valid) { - return false; - } - } - - //Check promotion class is met - ConcurrentHashMap promotionClasses = rb.getPromotionClass(); - if (promotionClasses.size() > 0) { - int promotionClassID = playerCharacter.getPromotionClassID(); - boolean valid = false; - for (int validID : promotionClasses.keySet()) { - if (validID == promotionClassID) { - valid = true; - break; - } - } - if (!valid) { - return false; - } - } - - //Check disciplines are met - ArrayList runes = playerCharacter.getRunes(); - ConcurrentHashMap disciplines = rb.getDiscipline(); - if (disciplines.size() > 0) { - for (CharacterRune cr : runes) { - int runeBaseID = cr.getRuneBaseID(); - for (Integer prohID : disciplines.keySet()) { - if (runeBaseID == prohID) { - return false; //Prohibited rune - } - } - } - } - - int discCount = 0; - for (CharacterRune cr : runes) { - int runeBaseID = cr.getRuneBaseID(); - //count number of discipline runes - if (runeBaseID > 3000 && runeBaseID < 3049) { - discCount++; - } - //see if rune is already applied - if (runeBaseID == runeID) { - return false; - } - } - - //Check level is met - if (playerCharacter.getLevel() < rb.getLevelRequired()) { - return false; - } - - int strTotal = 0; - int dexTotal = 0; - int conTotal = 0; - int intTotal = 0; - int spiTotal = 0; - int cost = 0; - - //Check any attributes are met - ArrayList attrs = rb.getAttrs(); - - if (rb.getAttrs() != null) - for (RuneBaseAttribute rba : attrs) { - int attrID = rba.getAttributeID(); - int mod = rba.getModValue(); - switch (attrID) { - case MBServerStatics.RUNE_COST_ATTRIBUTE_ID: - if (mod > playerCharacter.getUnusedStatPoints()) { - return false; - } - cost = mod; - break; - case MBServerStatics.RUNE_STR_MIN_NEEDED_ATTRIBUTE_ID: - if ((int) playerCharacter.statStrBase < mod) { - return false; - } - strTotal = mod; - break; - case MBServerStatics.RUNE_DEX_MIN_NEEDED_ATTRIBUTE_ID: - if ((int) playerCharacter.statDexBase < mod) { - return false; - } - dexTotal = mod; - break; - case MBServerStatics.RUNE_CON_MIN_NEEDED_ATTRIBUTE_ID: - if ((int) playerCharacter.statConBase < mod) { - return false; - } - conTotal = mod; - break; - case MBServerStatics.RUNE_INT_MIN_NEEDED_ATTRIBUTE_ID: - if ((int) playerCharacter.statIntBase < mod) { - return false; - } - intTotal = mod; - break; - case MBServerStatics.RUNE_SPI_MIN_NEEDED_ATTRIBUTE_ID: - if ((int) playerCharacter.statSpiBase < mod) { - return false; - } - spiTotal = mod; - break; - case MBServerStatics.RUNE_STR_ATTRIBUTE_ID: - strTotal += mod; - break; - case MBServerStatics.RUNE_DEX_ATTRIBUTE_ID: - dexTotal += mod; - break; - case MBServerStatics.RUNE_CON_ATTRIBUTE_ID: - conTotal += mod; - break; - case MBServerStatics.RUNE_INT_ATTRIBUTE_ID: - intTotal += mod; - break; - case MBServerStatics.RUNE_SPI_ATTRIBUTE_ID: - spiTotal += mod; - break; - } - } - - //Check if max number runes already reached - if (runes.size() > 12) { - return false; - } - - //if discipline, check number applied - if (isDiscipline(runeID)) { - if (playerCharacter.getLevel() < 70) { - if (discCount > 2) { - return false; - } - } else { - if (discCount > 3) { - return false; - } - } - } - - //Everything succeeded. Let's apply the rune - //Attempt add rune to database - CharacterRune runeWithoutID = new CharacterRune(rb, playerCharacter.getObjectUUID()); - CharacterRune cr; - try { - cr = DbManager.CharacterRuneQueries.ADD_CHARACTER_RUNE(runeWithoutID); - } catch (Exception e) { - cr = null; - Logger.error(e); - } - if (cr == null) { - return false; - } - - //remove any overridden runes from player - ArrayList overwrite = rb.getOverwrite(); - CharacterRune toRemove = null; - if (overwrite.size() > 0) { - for (int overwriteID : overwrite) { - toRemove = playerCharacter.removeRune(overwriteID); - } - } - - //add rune to player - playerCharacter.addRune(cr); - - // recalculate all bonuses/formulas/skills/powers - playerCharacter.recalculate(); - - //if overwriting a stat rune, add any amount granted from previous rune. - if (toRemove != null) { - RuneBase rbs = toRemove.getRuneBase(); - if (rbs != null && rbs.getObjectUUID() > 249999 && rbs.getObjectUUID() < 250045) { - //add any additional stats to match old amount - int dif = strTotal - (int) playerCharacter.statStrBase; - if (dif > 0 && strTotal < (int) playerCharacter.statStrMax) { - playerCharacter.addStr(dif); - } - dif = dexTotal - (int) playerCharacter.statDexBase; - if (dif > 0 && dexTotal < (int) playerCharacter.statDexMax) { - playerCharacter.addDex(dif); - } - dif = conTotal - (int) playerCharacter.statConBase; - if (dif > 0 && conTotal < (int) playerCharacter.statConMax) { - playerCharacter.addCon(dif); - } - dif = intTotal - (int) playerCharacter.statIntBase; - if (dif > 0 && intTotal < (int) playerCharacter.statIntMax) { - playerCharacter.addInt(dif); - } - dif = spiTotal - (int) playerCharacter.statSpiBase; - if (dif > 0 && spiTotal < (int) playerCharacter.statSpiMax) { - playerCharacter.addSpi(dif); - } - - // recalculate all bonuses/formulas/skills/powers - playerCharacter.recalculate(); - } - } - - if (cost > 0) { - ModifyStatMsg msm = new ModifyStatMsg((0 - cost), 0, 3); - dispatch = Dispatch.borrow(playerCharacter, msm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } - - //send apply rune message to client - ApplyRuneMsg arm = new ApplyRuneMsg(playerCharacter.getObjectType().ordinal(), playerCharacter.getObjectUUID(), runeID, cr.getObjectType().ordinal(), cr.getObjectUUID(), false); - dispatch = Dispatch.borrow(playerCharacter, arm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - - //alert them of success - ErrorPopupMsg.sendErrorPopup(playerCharacter, 160); - - //reapply bonuses - playerCharacter.applyBonuses(); - - return true; - } - - public static boolean isDiscipline(int runeID) { - - return runeID > 3000 && runeID < 3050; - } + private int targetType; + private int targetID; + private int removeRuneBase; + private int runeBase; + private int runeType; + private int runeID; + private Boolean isPromo; + + /** + * This is the general purpose constructor. + */ + public ApplyRuneMsg(int targetType, int targetID, int runeBase, int runeType, int runeID, Boolean isPromo) { + super(Protocol.SETRUNE); + this.targetType = targetType; + this.targetID = targetID; + this.runeBase = runeBase; + this.runeType = runeType; + this.runeID = runeID; + this.isPromo = isPromo; + this.removeRuneBase = 0; + } + + public ApplyRuneMsg(int targetType, int targetID, int removeRuneBase) { + super(Protocol.SETRUNE); + this.targetType = targetType; + this.targetID = targetID; + this.runeBase = 0; + this.runeType = 0; + this.runeID = 0; + this.isPromo = false; + this.removeRuneBase = removeRuneBase; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ApplyRuneMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SETRUNE, origin, reader); + } + + public static boolean applyRune(int runeID, ClientConnection origin, PlayerCharacter playerCharacter) { + + RuneBase rb = RuneBase.getRuneBase(runeID); + Dispatch dispatch; + + if (playerCharacter == null || origin == null || rb == null) { + return false; + } + + //Check race is met + ConcurrentHashMap races = rb.getRace(); + if (races.size() > 0) { + int raceID = playerCharacter.getRaceID(); + boolean valid = false; + for (int validID : races.keySet()) { + if (validID == raceID) { + valid = true; + break; + } + } + if (!valid) { + return false; + } + } + + //Check base class is met + ConcurrentHashMap baseClasses = rb.getBaseClass(); + if (baseClasses.size() > 0) { + int baseClassID = playerCharacter.getBaseClassID(); + boolean valid = false; + for (int validID : baseClasses.keySet()) { + if (validID == baseClassID) { + valid = true; + break; + } + } + if (!valid) { + return false; + } + } + + //Check promotion class is met + ConcurrentHashMap promotionClasses = rb.getPromotionClass(); + if (promotionClasses.size() > 0) { + int promotionClassID = playerCharacter.getPromotionClassID(); + boolean valid = false; + for (int validID : promotionClasses.keySet()) { + if (validID == promotionClassID) { + valid = true; + break; + } + } + if (!valid) { + return false; + } + } + + //Check disciplines are met + ArrayList runes = playerCharacter.getRunes(); + ConcurrentHashMap disciplines = rb.getDiscipline(); + if (disciplines.size() > 0) { + for (CharacterRune cr : runes) { + int runeBaseID = cr.getRuneBaseID(); + for (Integer prohID : disciplines.keySet()) { + if (runeBaseID == prohID) { + return false; //Prohibited rune + } + } + } + } + + int discCount = 0; + for (CharacterRune cr : runes) { + int runeBaseID = cr.getRuneBaseID(); + //count number of discipline runes + if (runeBaseID > 3000 && runeBaseID < 3049) { + discCount++; + } + //see if rune is already applied + if (runeBaseID == runeID) { + return false; + } + } + + //Check level is met + if (playerCharacter.getLevel() < rb.getLevelRequired()) { + return false; + } + + int strTotal = 0; + int dexTotal = 0; + int conTotal = 0; + int intTotal = 0; + int spiTotal = 0; + int cost = 0; + + //Check any attributes are met + ArrayList attrs = rb.getAttrs(); + + if (rb.getAttrs() != null) + for (RuneBaseAttribute rba : attrs) { + int attrID = rba.getAttributeID(); + int mod = rba.getModValue(); + switch (attrID) { + case MBServerStatics.RUNE_COST_ATTRIBUTE_ID: + if (mod > playerCharacter.getUnusedStatPoints()) { + return false; + } + cost = mod; + break; + case MBServerStatics.RUNE_STR_MIN_NEEDED_ATTRIBUTE_ID: + if ((int) playerCharacter.statStrBase < mod) { + return false; + } + strTotal = mod; + break; + case MBServerStatics.RUNE_DEX_MIN_NEEDED_ATTRIBUTE_ID: + if ((int) playerCharacter.statDexBase < mod) { + return false; + } + dexTotal = mod; + break; + case MBServerStatics.RUNE_CON_MIN_NEEDED_ATTRIBUTE_ID: + if ((int) playerCharacter.statConBase < mod) { + return false; + } + conTotal = mod; + break; + case MBServerStatics.RUNE_INT_MIN_NEEDED_ATTRIBUTE_ID: + if ((int) playerCharacter.statIntBase < mod) { + return false; + } + intTotal = mod; + break; + case MBServerStatics.RUNE_SPI_MIN_NEEDED_ATTRIBUTE_ID: + if ((int) playerCharacter.statSpiBase < mod) { + return false; + } + spiTotal = mod; + break; + case MBServerStatics.RUNE_STR_ATTRIBUTE_ID: + strTotal += mod; + break; + case MBServerStatics.RUNE_DEX_ATTRIBUTE_ID: + dexTotal += mod; + break; + case MBServerStatics.RUNE_CON_ATTRIBUTE_ID: + conTotal += mod; + break; + case MBServerStatics.RUNE_INT_ATTRIBUTE_ID: + intTotal += mod; + break; + case MBServerStatics.RUNE_SPI_ATTRIBUTE_ID: + spiTotal += mod; + break; + } + } + + //Check if max number runes already reached + if (runes.size() > 12) { + return false; + } + + //if discipline, check number applied + if (isDiscipline(runeID)) { + if (playerCharacter.getLevel() < 70) { + if (discCount > 2) { + return false; + } + } else { + if (discCount > 3) { + return false; + } + } + } + + //Everything succeeded. Let's apply the rune + //Attempt add rune to database + CharacterRune runeWithoutID = new CharacterRune(rb, playerCharacter.getObjectUUID()); + CharacterRune cr; + try { + cr = DbManager.CharacterRuneQueries.ADD_CHARACTER_RUNE(runeWithoutID); + } catch (Exception e) { + cr = null; + Logger.error(e); + } + if (cr == null) { + return false; + } + + //remove any overridden runes from player + ArrayList overwrite = rb.getOverwrite(); + CharacterRune toRemove = null; + if (overwrite.size() > 0) { + for (int overwriteID : overwrite) { + toRemove = playerCharacter.removeRune(overwriteID); + } + } + + //add rune to player + playerCharacter.addRune(cr); + + // recalculate all bonuses/formulas/skills/powers + playerCharacter.recalculate(); + + //if overwriting a stat rune, add any amount granted from previous rune. + if (toRemove != null) { + RuneBase rbs = toRemove.getRuneBase(); + if (rbs != null && rbs.getObjectUUID() > 249999 && rbs.getObjectUUID() < 250045) { + //add any additional stats to match old amount + int dif = strTotal - (int) playerCharacter.statStrBase; + if (dif > 0 && strTotal < (int) playerCharacter.statStrMax) { + playerCharacter.addStr(dif); + } + dif = dexTotal - (int) playerCharacter.statDexBase; + if (dif > 0 && dexTotal < (int) playerCharacter.statDexMax) { + playerCharacter.addDex(dif); + } + dif = conTotal - (int) playerCharacter.statConBase; + if (dif > 0 && conTotal < (int) playerCharacter.statConMax) { + playerCharacter.addCon(dif); + } + dif = intTotal - (int) playerCharacter.statIntBase; + if (dif > 0 && intTotal < (int) playerCharacter.statIntMax) { + playerCharacter.addInt(dif); + } + dif = spiTotal - (int) playerCharacter.statSpiBase; + if (dif > 0 && spiTotal < (int) playerCharacter.statSpiMax) { + playerCharacter.addSpi(dif); + } + + // recalculate all bonuses/formulas/skills/powers + playerCharacter.recalculate(); + } + } + + if (cost > 0) { + ModifyStatMsg msm = new ModifyStatMsg((0 - cost), 0, 3); + dispatch = Dispatch.borrow(playerCharacter, msm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } + + //send apply rune message to client + ApplyRuneMsg arm = new ApplyRuneMsg(playerCharacter.getObjectType().ordinal(), playerCharacter.getObjectUUID(), runeID, cr.getObjectType().ordinal(), cr.getObjectUUID(), false); + dispatch = Dispatch.borrow(playerCharacter, arm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + + //alert them of success + ErrorPopupMsg.sendErrorPopup(playerCharacter, 160); + + //reapply bonuses + playerCharacter.applyBonuses(); + + return true; + } + + public static boolean isDiscipline(int runeID) { + + return runeID > 3000 && runeID < 3050; + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.targetType); + writer.putInt(this.targetID); + writer.putInt(0); + writer.putInt(this.removeRuneBase); + writer.putInt(0); + writer.putInt(this.runeBase); + writer.putInt(this.runeType); + writer.putInt(this.runeID); + if (this.isPromo) { + writer.put((byte) 1); + } else { + writer.put((byte) 0); + } + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + reader.getInt(); + this.removeRuneBase = reader.getInt(); + reader.getInt(); + this.runeBase = reader.getInt(); + this.runeType = reader.getInt(); + this.runeID = reader.getInt(); + this.isPromo = (reader.get() == 1) ? true : false; + } + + public int getTargetType() { + return targetType; + } + + public void setTargetType(int value) { + this.targetType = value; + } + + public int getTargetID() { + return targetID; + } + + public void setTargetID(int value) { + this.targetID = value; + } + + public int getRuneID() { + return runeID; + } + + public void setRuneID(int value) { + this.runeID = value; + } } diff --git a/src/engine/net/client/msg/ArcLoginNotifyMsg.java b/src/engine/net/client/msg/ArcLoginNotifyMsg.java index 57266e55..fd4f48df 100644 --- a/src/engine/net/client/msg/ArcLoginNotifyMsg.java +++ b/src/engine/net/client/msg/ArcLoginNotifyMsg.java @@ -17,132 +17,127 @@ import engine.net.client.Protocol; public class ArcLoginNotifyMsg extends ClientNetMsg { - private int unknown01; - private int unknown02; - private int unknown03; - private short unknown04; - private byte unknown05; - - /** - * This is the general purpose constructor. - */ - public ArcLoginNotifyMsg() { - super(Protocol.ARCLOGINNOTIFY); - this.unknown01 = 0x40A5BDB0; - this.unknown02 = 0x342AA9F0; - this.unknown03 = 0; - this.unknown04 = (short) 0; - this.unknown05 = (byte) 0; - - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ArcLoginNotifyMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ARCLOGINNOTIFY, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - writer.putInt(this.unknown03); - writer.putShort(this.unknown04); - writer.put(this.unknown05); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - this.unknown03 = reader.getInt(); - this.unknown04 = reader.getShort(); - this.unknown05 = reader.get(); - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the unknown02 - */ - public int getUnknown02() { - return unknown02; - } - - /** - * @param unknown02 - * the unknown02 to set - */ - public void setUnknown02(int unknown02) { - this.unknown02 = unknown02; - } - - /** - * @return the unknown03 - */ - public int getUnknown03() { - return unknown03; - } - - /** - * @param unknown03 - * the unknown03 to set - */ - public void setUnknown03(int unknown03) { - this.unknown03 = unknown03; - } - - /** - * @return the unknown04 - */ - public short getUnknown04() { - return unknown04; - } - - /** - * @param unknown04 - * the unknown04 to set - */ - public void setUnknown04(short unknown04) { - this.unknown04 = unknown04; - } - - /** - * @return the unknown05 - */ - public byte getUnknown05() { - return unknown05; - } - - /** - * @param unknown05 - * the unknown05 to set - */ - public void setUnknown05(byte unknown05) { - this.unknown05 = unknown05; - } + private int unknown01; + private int unknown02; + private int unknown03; + private short unknown04; + private byte unknown05; + + /** + * This is the general purpose constructor. + */ + public ArcLoginNotifyMsg() { + super(Protocol.ARCLOGINNOTIFY); + this.unknown01 = 0x40A5BDB0; + this.unknown02 = 0x342AA9F0; + this.unknown03 = 0; + this.unknown04 = (short) 0; + this.unknown05 = (byte) 0; + + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ArcLoginNotifyMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ARCLOGINNOTIFY, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + writer.putInt(this.unknown03); + writer.putShort(this.unknown04); + writer.put(this.unknown05); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + this.unknown03 = reader.getInt(); + this.unknown04 = reader.getShort(); + this.unknown05 = reader.get(); + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the unknown02 + */ + public int getUnknown02() { + return unknown02; + } + + /** + * @param unknown02 the unknown02 to set + */ + public void setUnknown02(int unknown02) { + this.unknown02 = unknown02; + } + + /** + * @return the unknown03 + */ + public int getUnknown03() { + return unknown03; + } + + /** + * @param unknown03 the unknown03 to set + */ + public void setUnknown03(int unknown03) { + this.unknown03 = unknown03; + } + + /** + * @return the unknown04 + */ + public short getUnknown04() { + return unknown04; + } + + /** + * @param unknown04 the unknown04 to set + */ + public void setUnknown04(short unknown04) { + this.unknown04 = unknown04; + } + + /** + * @return the unknown05 + */ + public byte getUnknown05() { + return unknown05; + } + + /** + * @param unknown05 the unknown05 to set + */ + public void setUnknown05(byte unknown05) { + this.unknown05 = unknown05; + } } diff --git a/src/engine/net/client/msg/ArcMineChangeProductionMsg.java b/src/engine/net/client/msg/ArcMineChangeProductionMsg.java index f6f8a3aa..0799a9ce 100644 --- a/src/engine/net/client/msg/ArcMineChangeProductionMsg.java +++ b/src/engine/net/client/msg/ArcMineChangeProductionMsg.java @@ -27,7 +27,7 @@ public class ArcMineChangeProductionMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public ArcMineChangeProductionMsg(AbstractConnection origin, ByteBufferReader reader) { + public ArcMineChangeProductionMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.ARCMINECHANGEPRODUCTION, origin, reader); } @@ -35,7 +35,7 @@ public class ArcMineChangeProductionMsg extends ClientNetMsg { * Deserializes the subclass specific items from the supplied NetMsgReader. */ @Override - protected void _deserialize(ByteBufferReader reader) { + protected void _deserialize(ByteBufferReader reader) { this.mineID = reader.getInt(); this.resourceHash = reader.getInt(); } diff --git a/src/engine/net/client/msg/ArcMineWindowAvailableTimeMsg.java b/src/engine/net/client/msg/ArcMineWindowAvailableTimeMsg.java index ac95d4ef..249600cd 100644 --- a/src/engine/net/client/msg/ArcMineWindowAvailableTimeMsg.java +++ b/src/engine/net/client/msg/ArcMineWindowAvailableTimeMsg.java @@ -23,88 +23,88 @@ import org.joda.time.Seconds; public class ArcMineWindowAvailableTimeMsg extends ClientNetMsg { - private int buildingUUID; - private Building treeOfLife; - - private int currentMineHour; - private Seconds secondsLeft; - private DateTime lateTime; - private int late; - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ArcMineWindowAvailableTimeMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ARCMINEWINDOWAVAILABLETIME, origin, reader); - } - - public ArcMineWindowAvailableTimeMsg(Building treeOfLife, int timeLeft) { - super(Protocol.ARCMINEWINDOWAVAILABLETIME); - this.treeOfLife = treeOfLife; - this.buildingUUID = treeOfLife.getObjectUUID(); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); // Object type padding (We know it's a building) - this.buildingUUID = reader.getInt(); - reader.getInt(); - - } - - // Configures and pre-caches values for this message - // so everything is already available during serialisation. - - public void configure() { - - Guild guild; - guild = this.treeOfLife.getGuild(); - - if (guild != null) - currentMineHour = guild.getMineTime(); - - late = MBServerStatics.MINE_LATE_WINDOW; - lateTime = DateTime.now(); - - if (late == 0) - lateTime = lateTime.plusDays(1); - - lateTime = lateTime.hourOfDay().setCopy(late); - - late = ((late > 23) ? (late - 24) : late); - secondsLeft = Seconds.secondsBetween(DateTime.now(), lateTime); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - - writer.putInt(MBServerStatics.MINE_EARLY_WINDOW); //15); - writer.putInt(late); - writer.putInt(currentMineHour); - - writer.putInt(this.treeOfLife.getObjectType().ordinal()); - writer.putInt(this.treeOfLife.getObjectUUID()); - - writer.putInt((int)secondsLeft.getSeconds()); - } - - public int getBuildingUUID() { - return buildingUUID; - } - - public void setBuildingUUID(int buildingUUID) { - this.buildingUUID = buildingUUID; - } + private int buildingUUID; + private Building treeOfLife; + + private int currentMineHour; + private Seconds secondsLeft; + private DateTime lateTime; + private int late; + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ArcMineWindowAvailableTimeMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ARCMINEWINDOWAVAILABLETIME, origin, reader); + } + + public ArcMineWindowAvailableTimeMsg(Building treeOfLife, int timeLeft) { + super(Protocol.ARCMINEWINDOWAVAILABLETIME); + this.treeOfLife = treeOfLife; + this.buildingUUID = treeOfLife.getObjectUUID(); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); // Object type padding (We know it's a building) + this.buildingUUID = reader.getInt(); + reader.getInt(); + + } + + // Configures and pre-caches values for this message + // so everything is already available during serialisation. + + public void configure() { + + Guild guild; + guild = this.treeOfLife.getGuild(); + + if (guild != null) + currentMineHour = guild.getMineTime(); + + late = MBServerStatics.MINE_LATE_WINDOW; + lateTime = DateTime.now(); + + if (late == 0) + lateTime = lateTime.plusDays(1); + + lateTime = lateTime.hourOfDay().setCopy(late); + + late = ((late > 23) ? (late - 24) : late); + secondsLeft = Seconds.secondsBetween(DateTime.now(), lateTime); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + + writer.putInt(MBServerStatics.MINE_EARLY_WINDOW); //15); + writer.putInt(late); + writer.putInt(currentMineHour); + + writer.putInt(this.treeOfLife.getObjectType().ordinal()); + writer.putInt(this.treeOfLife.getObjectUUID()); + + writer.putInt((int) secondsLeft.getSeconds()); + } + + public int getBuildingUUID() { + return buildingUUID; + } + + public void setBuildingUUID(int buildingUUID) { + this.buildingUUID = buildingUUID; + } } diff --git a/src/engine/net/client/msg/ArcMineWindowChangeMsg.java b/src/engine/net/client/msg/ArcMineWindowChangeMsg.java index a6da69fe..f8b6d309 100644 --- a/src/engine/net/client/msg/ArcMineWindowChangeMsg.java +++ b/src/engine/net/client/msg/ArcMineWindowChangeMsg.java @@ -28,7 +28,7 @@ public class ArcMineWindowChangeMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public ArcMineWindowChangeMsg(AbstractConnection origin, ByteBufferReader reader) { + public ArcMineWindowChangeMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.ARCMINEWINDOWCHANGE, origin, reader); } @@ -36,7 +36,7 @@ public class ArcMineWindowChangeMsg extends ClientNetMsg { * Deserializes the subclass specific items from the supplied NetMsgReader. */ @Override - protected void _deserialize(ByteBufferReader reader) { + protected void _deserialize(ByteBufferReader reader) { this.time = reader.getInt(); this.buildingType = reader.getInt(); this.buildingID = reader.getInt(); @@ -56,14 +56,14 @@ public class ArcMineWindowChangeMsg extends ClientNetMsg { return this.time; } - public int getBuildingID() { - return this.buildingID; - } - public void setTime(int value) { this.time = value; } + public int getBuildingID() { + return this.buildingID; + } + public void setBuildingID(int value) { this.buildingID = value; } diff --git a/src/engine/net/client/msg/ArcOwnedMinesListMsg.java b/src/engine/net/client/msg/ArcOwnedMinesListMsg.java index a78b9cd1..202dc621 100644 --- a/src/engine/net/client/msg/ArcOwnedMinesListMsg.java +++ b/src/engine/net/client/msg/ArcOwnedMinesListMsg.java @@ -29,7 +29,7 @@ public class ArcOwnedMinesListMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public ArcOwnedMinesListMsg(AbstractConnection origin, ByteBufferReader reader) { + public ArcOwnedMinesListMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.ARCOWNEDMINESLIST, origin, reader); } @@ -37,7 +37,7 @@ public class ArcOwnedMinesListMsg extends ClientNetMsg { * Deserializes the subclass specific items from the supplied NetMsgReader. */ @Override - protected void _deserialize(ByteBufferReader reader) { + protected void _deserialize(ByteBufferReader reader) { reader.getInt(); } diff --git a/src/engine/net/client/msg/ArcSiegeSpireMsg.java b/src/engine/net/client/msg/ArcSiegeSpireMsg.java index 817e038c..2942fce6 100644 --- a/src/engine/net/client/msg/ArcSiegeSpireMsg.java +++ b/src/engine/net/client/msg/ArcSiegeSpireMsg.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.net.client.msg; @@ -28,7 +27,7 @@ public class ArcSiegeSpireMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public ArcSiegeSpireMsg(AbstractConnection origin, ByteBufferReader reader) { + public ArcSiegeSpireMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.ARCSIEGESPIRE, origin, reader); } @@ -40,7 +39,7 @@ public class ArcSiegeSpireMsg extends ClientNetMsg { * Deserializes the subclass specific items from the supplied NetMsgReader. */ @Override - protected void _deserialize(ByteBufferReader reader) { + protected void _deserialize(ByteBufferReader reader) { reader.getInt(); // object type padding this.buildingUUID = reader.getInt(); } @@ -56,5 +55,5 @@ public class ArcSiegeSpireMsg extends ClientNetMsg { public int getBuildingUUID() { return buildingUUID; } - + } diff --git a/src/engine/net/client/msg/ArcViewAssetTransactionsMsg.java b/src/engine/net/client/msg/ArcViewAssetTransactionsMsg.java index df827a11..af4cc873 100644 --- a/src/engine/net/client/msg/ArcViewAssetTransactionsMsg.java +++ b/src/engine/net/client/msg/ArcViewAssetTransactionsMsg.java @@ -23,128 +23,129 @@ import java.util.ArrayList; public class ArcViewAssetTransactionsMsg extends ClientNetMsg { - private int warehouseID; - private Warehouse warehouse; - private int transactionID; - private ArrayList transactions; - Building warehouseBuilding; - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ArcViewAssetTransactionsMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ARCVIEWASSETTRANSACTIONS, origin, reader); - } - - public ArcViewAssetTransactionsMsg(Warehouse warehouse, ArcViewAssetTransactionsMsg msg) { - super(Protocol.ARCVIEWASSETTRANSACTIONS); + Building warehouseBuilding; + private int warehouseID; + private Warehouse warehouse; + private int transactionID; + private ArrayList transactions; + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ArcViewAssetTransactionsMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ARCVIEWASSETTRANSACTIONS, origin, reader); + } + + public ArcViewAssetTransactionsMsg(Warehouse warehouse, ArcViewAssetTransactionsMsg msg) { + super(Protocol.ARCVIEWASSETTRANSACTIONS); this.warehouseID = msg.warehouseID; this.transactionID = msg.transactionID; - this.warehouse = warehouse; - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.transactionID = reader.getInt(); //some odd type? - this.warehouseID = reader.getInt(); - reader.getInt(); - } - - // Method pre-caches and configures values so they are - // available before we attempt serialization - - public void configure() { - - warehouseBuilding = BuildingManager.getBuilding(this.warehouse.getBuildingUID()); - transactions = new ArrayList<>(50); - - if (this.warehouse.getTransactions().size() > 150){ - transactions.addAll(this.warehouse.getTransactions().subList(this.warehouse.getTransactions().size() - 150, this.warehouse.getTransactions().size())); - }else - transactions = this.warehouse.getTransactions(); - - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - - writer.putInt(this.transactionID); - writer.putInt(this.warehouse.getBuildingUID()); - writer.putInt(transactions.size()); //list Size - - for (Transaction transaction:transactions){ - String name = "No Name"; - switch (transaction.getTargetType()){ - case Building: - Building building = BuildingManager.getBuildingFromCache(transaction.getTargetUUID()); - if (building != null) - name = building.getName(); - Mine mine = Mine.getMineFromTower(transaction.getTargetUUID()); - // - if (mine != null) - name = mine.getZoneName(); - - if (transaction.getTransactionType().equals(TransactionType.TAXRESOURCE) || transaction.getTransactionType().equals(TransactionType.TAXRESOURCEDEPOSIT)){ - City city = building.getCity(); - - if (city != null) - name = city.getCityName(); - } - - break; - case PlayerCharacter: - PlayerCharacter pc = PlayerCharacter.getPlayerCharacter(transaction.getTargetUUID()); - if (pc != null) - name = pc.getCombinedName(); - break; - case NPC: - NPC npc = NPC.getFromCache(transaction.getTargetUUID()); - if (npc != null){ - - if (npc.getBuilding() != null) - name = npc.getBuilding().getName(); - else - name = npc.getName(); - } - - - default: - break; - } - writer.putInt(transaction.getTargetType().ordinal()); //Type - writer.putInt(transaction.getTargetUUID()); //ID - writer.putString(name); //Name of depositer/withdrawler or mine name - writer.putInt(GameObjectType.Building.ordinal()); //Type - writer.putInt(warehouse.getBuildingUID()); //ID - writer.putString(warehouseBuilding.getName()); //warehouse - writer.putInt(transaction.getTransactionType().getID()); //79,80 withdrew, 81 mine produced, 82 deposit - writer.putInt(transaction.getAmount()); //amount - writer.putString(transaction.getResource().name().toLowerCase()); //item type - writer.putDateTime(transaction.getDate()); - } - - - //writer.putString("balls"); - } - - @Override - protected int getPowerOfTwoBufferSize() { - return (16); // 2^14 == 16384 - } - - public int getWarehouseID() { - return warehouseID; - } - public int getTransactionID() { - return transactionID; - } + this.warehouse = warehouse; + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.transactionID = reader.getInt(); //some odd type? + this.warehouseID = reader.getInt(); + reader.getInt(); + } + + // Method pre-caches and configures values so they are + // available before we attempt serialization + + public void configure() { + + warehouseBuilding = BuildingManager.getBuilding(this.warehouse.getBuildingUID()); + transactions = new ArrayList<>(50); + + if (this.warehouse.getTransactions().size() > 150) { + transactions.addAll(this.warehouse.getTransactions().subList(this.warehouse.getTransactions().size() - 150, this.warehouse.getTransactions().size())); + } else + transactions = this.warehouse.getTransactions(); + + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + + writer.putInt(this.transactionID); + writer.putInt(this.warehouse.getBuildingUID()); + writer.putInt(transactions.size()); //list Size + + for (Transaction transaction : transactions) { + String name = "No Name"; + switch (transaction.getTargetType()) { + case Building: + Building building = BuildingManager.getBuildingFromCache(transaction.getTargetUUID()); + if (building != null) + name = building.getName(); + Mine mine = Mine.getMineFromTower(transaction.getTargetUUID()); + // + if (mine != null) + name = mine.getZoneName(); + + if (transaction.getTransactionType().equals(TransactionType.TAXRESOURCE) || transaction.getTransactionType().equals(TransactionType.TAXRESOURCEDEPOSIT)) { + City city = building.getCity(); + + if (city != null) + name = city.getCityName(); + } + + break; + case PlayerCharacter: + PlayerCharacter pc = PlayerCharacter.getPlayerCharacter(transaction.getTargetUUID()); + if (pc != null) + name = pc.getCombinedName(); + break; + case NPC: + NPC npc = NPC.getFromCache(transaction.getTargetUUID()); + if (npc != null) { + + if (npc.getBuilding() != null) + name = npc.getBuilding().getName(); + else + name = npc.getName(); + } + + + default: + break; + } + writer.putInt(transaction.getTargetType().ordinal()); //Type + writer.putInt(transaction.getTargetUUID()); //ID + writer.putString(name); //Name of depositer/withdrawler or mine name + writer.putInt(GameObjectType.Building.ordinal()); //Type + writer.putInt(warehouse.getBuildingUID()); //ID + writer.putString(warehouseBuilding.getName()); //warehouse + writer.putInt(transaction.getTransactionType().getID()); //79,80 withdrew, 81 mine produced, 82 deposit + writer.putInt(transaction.getAmount()); //amount + writer.putString(transaction.getResource().name().toLowerCase()); //item type + writer.putDateTime(transaction.getDate()); + } + + + //writer.putString("balls"); + } + + @Override + protected int getPowerOfTwoBufferSize() { + return (16); // 2^14 == 16384 + } + + public int getWarehouseID() { + return warehouseID; + } + + public int getTransactionID() { + return transactionID; + } } diff --git a/src/engine/net/client/msg/AssetSupportMsg.java b/src/engine/net/client/msg/AssetSupportMsg.java index bf0864ab..540c1464 100644 --- a/src/engine/net/client/msg/AssetSupportMsg.java +++ b/src/engine/net/client/msg/AssetSupportMsg.java @@ -21,6 +21,7 @@ import org.pmw.tinylog.Logger; public class AssetSupportMsg extends ClientNetMsg { + public static int confirmProtect; private int npcType; private int npcID; private int buildingType; @@ -35,7 +36,6 @@ public class AssetSupportMsg extends ClientNetMsg { private int weeklyTax; private byte enforceKOS; private Enum.SupportMsgType supportMsgType; - public static int confirmProtect; /** @@ -182,27 +182,27 @@ public class AssetSupportMsg extends ClientNetMsg { writer.putInt(0); break; case CONFIRMPROTECT: - writer.putInt(this.buildingType); - writer.putInt(this.buildingID); - writer.putInt(this.npcType); - writer.putInt(this.npcID); - 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.put((byte)0); - writer.put((byte)0); - writer.put((byte)0); - - - break; + writer.putInt(this.buildingType); + writer.putInt(this.buildingID); + writer.putInt(this.npcType); + writer.putInt(this.npcID); + 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.put((byte) 0); + writer.put((byte) 0); + writer.put((byte) 0); + + + break; case UNPROTECT: writer.putInt(this.buildingType); writer.putInt(this.buildingID); @@ -238,10 +238,6 @@ public class AssetSupportMsg extends ClientNetMsg { this.objectType = value; } - public void setPad(int value) { - this.pad = value; - } - public int getUUID() { return objectUUID; } @@ -250,6 +246,9 @@ public class AssetSupportMsg extends ClientNetMsg { return pad; } + public void setPad(int value) { + this.pad = value; + } public int getMessageType() { return messageType; diff --git a/src/engine/net/client/msg/AttackCmdMsg.java b/src/engine/net/client/msg/AttackCmdMsg.java index ed5b398c..f2c41b4e 100644 --- a/src/engine/net/client/msg/AttackCmdMsg.java +++ b/src/engine/net/client/msg/AttackCmdMsg.java @@ -40,7 +40,7 @@ public class AttackCmdMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public AttackCmdMsg(AbstractConnection origin, ByteBufferReader reader) { + public AttackCmdMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.REQUESTMELEEATTACK, origin, reader); } @@ -59,7 +59,7 @@ public class AttackCmdMsg extends ClientNetMsg { * Deserializes the subclass specific items from the supplied NetMsgReader. */ @Override - protected void _deserialize(ByteBufferReader reader) { + protected void _deserialize(ByteBufferReader reader) { this.sourceType = reader.getInt(); this.sourceID = reader.getInt(); this.targetType = reader.getInt(); @@ -73,6 +73,10 @@ public class AttackCmdMsg extends ClientNetMsg { return sourceType; } + public void setSourceType(int value) { + this.sourceType = value; + } + /** * @return the sourceID */ @@ -80,6 +84,10 @@ public class AttackCmdMsg extends ClientNetMsg { return sourceID; } + public void setSourceID(int value) { + this.sourceID = value; + } + /** * @return the targetType */ @@ -87,6 +95,10 @@ public class AttackCmdMsg extends ClientNetMsg { return targetType; } + public void setTargetType(int value) { + this.targetType = value; + } + /** * @return the targetID */ @@ -94,18 +106,6 @@ public class AttackCmdMsg extends ClientNetMsg { return targetID; } - public void setSourceType(int value) { - this.sourceType = value; - } - - public void setSourceID(int value) { - this.sourceID = value; - } - - public void setTargetType(int value) { - this.targetType = value; - } - public void setTargetID(int value) { this.targetID = value; } diff --git a/src/engine/net/client/msg/BuyFromNPCMsg.java b/src/engine/net/client/msg/BuyFromNPCMsg.java index de63bd55..748ab1f8 100644 --- a/src/engine/net/client/msg/BuyFromNPCMsg.java +++ b/src/engine/net/client/msg/BuyFromNPCMsg.java @@ -19,121 +19,120 @@ import engine.objects.Item; public class BuyFromNPCMsg extends ClientNetMsg { - private int npcType; - private int npcID; - private int itemType; - private int itemID; - private byte unknown01; - private Item item; - - /** - * This is the general purpose constructor - */ - public BuyFromNPCMsg() { - super(Protocol.BUYFROMNPC); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public BuyFromNPCMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.BUYFROMNPC, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - this.npcType = reader.getInt(); - this.npcID = reader.getInt(); - this.itemType = reader.getInt(); - this.itemID = reader.getInt(); - this.unknown01 = reader.get(); - reader.get(); - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - - writer.putInt(this.npcType); - writer.putInt(this.npcID); - - if (this.item != null){ - writer.putInt(this.item.getObjectType().ordinal()); - writer.putInt(this.item.getObjectUUID()); - }else{ - writer.putInt(this.itemType); - writer.putInt(this.itemID); - } - - writer.put(this.unknown01); - if (item != null) { - writer.put((byte) 1); - Item.serializeForClientMsgWithoutSlot(item,writer); - } else { - writer.put((byte) 0); - } - } - - @Override - protected int getPowerOfTwoBufferSize() { - return (16); // 2^14 == 16384 - } - public int getNPCType() { - return this.npcType; - } - - public int getNPCID() { - return this.npcID; - } - - public int getItemType() { - return this.itemType; - } - - public int getItemID() { - return this.itemID; - } - - public byte getUnknown01() { - return this.unknown01; - } - - public void setNPCType(int value) { - this.npcType = value; - } - - public void setNPCID(int value) { - this.npcID = value; - } - - public void setItemType(int value) { - this.itemType = value; - } - - public void setItemID(int value) { - this.itemID = value; - } - - public void setUnknown01(byte value) { - this.unknown01 = value; - } - - public Item getItem() { - return item; - } - - public void setItem(Item item) { - this.item = item; - } + private int npcType; + private int npcID; + private int itemType; + private int itemID; + private byte unknown01; + private Item item; + + /** + * This is the general purpose constructor + */ + public BuyFromNPCMsg() { + super(Protocol.BUYFROMNPC); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public BuyFromNPCMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.BUYFROMNPC, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.npcType = reader.getInt(); + this.npcID = reader.getInt(); + this.itemType = reader.getInt(); + this.itemID = reader.getInt(); + this.unknown01 = reader.get(); + reader.get(); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + + writer.putInt(this.npcType); + writer.putInt(this.npcID); + + if (this.item != null) { + writer.putInt(this.item.getObjectType().ordinal()); + writer.putInt(this.item.getObjectUUID()); + } else { + writer.putInt(this.itemType); + writer.putInt(this.itemID); + } + + writer.put(this.unknown01); + if (item != null) { + writer.put((byte) 1); + Item.serializeForClientMsgWithoutSlot(item, writer); + } else { + writer.put((byte) 0); + } + } + + @Override + protected int getPowerOfTwoBufferSize() { + return (16); // 2^14 == 16384 + } + + public int getNPCType() { + return this.npcType; + } + + public void setNPCType(int value) { + this.npcType = value; + } + + public int getNPCID() { + return this.npcID; + } + + public void setNPCID(int value) { + this.npcID = value; + } + + public int getItemType() { + return this.itemType; + } + + public void setItemType(int value) { + this.itemType = value; + } + + public int getItemID() { + return this.itemID; + } + + public void setItemID(int value) { + this.itemID = value; + } + + public byte getUnknown01() { + return this.unknown01; + } + + public void setUnknown01(byte value) { + this.unknown01 = value; + } + + public Item getItem() { + return item; + } + + public void setItem(Item item) { + this.item = item; + } } diff --git a/src/engine/net/client/msg/BuyFromNPCWindowMsg.java b/src/engine/net/client/msg/BuyFromNPCWindowMsg.java index b54d6919..673d22d8 100644 --- a/src/engine/net/client/msg/BuyFromNPCWindowMsg.java +++ b/src/engine/net/client/msg/BuyFromNPCWindowMsg.java @@ -23,247 +23,238 @@ import java.util.ArrayList; public class BuyFromNPCWindowMsg extends ClientNetMsg { - private int unknown01; - private int npcType; - private int npcID; - private float unknown02; - private byte unknown03; - private int unknown04; - - /** - * This is the general purpose constructor - */ - public BuyFromNPCWindowMsg(int unknown01, int npcType, int npcID, - float unknown02, byte unknown03, int unknown04) { - super(Protocol.SHOPLIST); - this.unknown01 = unknown01; - this.npcType = npcType; - this.npcID = npcID; - this.unknown02 = unknown02; - this.unknown03 = unknown03; - this.unknown04 = unknown04; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public BuyFromNPCWindowMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.SHOPLIST, origin, reader); - } - - /** - * @see AbstractNetMsg#getPowerOfTwoBufferSize() - */ - @Override - protected int getPowerOfTwoBufferSize() { - // Larger size for historically larger opcodes - return (16); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - unknown01 = reader.getInt(); - npcType = reader.getInt(); - npcID = reader.getInt(); - unknown02 = reader.getFloat(); - unknown03 = reader.get(); - unknown04 = reader.getInt(); - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - - ClientConnection clientConnection = (ClientConnection) this.getOrigin(); - PlayerCharacter player = null; - - if (clientConnection != null) - player = clientConnection.getPlayerCharacter(); - - float sellPercent = 1; - - NPC npc = NPC.getFromCache(npcID); - CharacterItemManager man = null; - ArrayList inventory = null; - ArrayList sellInventory = null; - - if (npc != null) { - man = npc.getCharItemManager(); - Contract contract = npc.getContract(); - if (player != null){ - float barget = player.getBargain(); - float profit = npc.getSellPercent(player) - barget; - - if (profit < 1) - profit = 1; - - sellPercent = 1 * profit; - } - - else sellPercent = 1 * npc.getSellPercent(); - - if (contract != null) - sellInventory = contract.getSellInventory(); - } - - if (man != null) - inventory = man.getInventory(); - - writer.putInt(unknown01); - writer.putInt(npcType); - writer.putInt(npcID); - - writer.putFloat(sellPercent); //npc sell markup - - int size = 0; - - if (inventory != null) - size += inventory.size(); - - if (sellInventory != null) - size += sellInventory.size(); - - if (size == 0) { - writer.put((byte) 0); - writer.putInt(0); - return; - } - - writer.put((byte) 1); - - int ownerID = npc.getObjectUUID(); - int indexPosition = writer.position(); - writer.putInt(0); //placeholder for item cnt - int total = 0; - - //add generic sell inventory from contract - if (sellInventory != null) { - - for (MobEquipment mobEquipment : sellInventory) { - try { - MobEquipment.serializeForVendor(mobEquipment,writer, sellPercent); - } catch (SerializationException se) { - continue; - } - ++total; - } - } - - //add npc inventory - if (inventory != null) { - for (Item item : inventory) { - if (item.getOwnerID() != ownerID) - continue; - if (item.getItemBase().getType().equals(ItemType.GOLD)) { - if (item.getNumOfItems() == 0) - continue; - } - Item.serializeForClientMsgForVendorWithoutSlot(item,writer, sellPercent); - ++total; - } - } - writer.putIntAt(total, indexPosition); - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the unknown02 - */ - public float getUnknown02() { - return unknown02; - } - - /** - * @param unknown02 - * the unknown02 to set - */ - public void setUnknown02(float unknown02) { - this.unknown02 = unknown02; - } - - /** - * @return the unknown03 - */ - public byte getUnknown03() { - return unknown03; - } - - /** - * @param unknown03 - * the unknown03 to set - */ - public void setUnknown03(byte unknown03) { - this.unknown03 = unknown03; - } - - /** - * @return the unknown04 - */ - public int getUnknown04() { - return unknown04; - } - - /** - * @param unknown04 - * the unknown04 to set - */ - public void setUnknown04(int unknown04) { - this.unknown04 = unknown04; - } - - /** - * @return the npcType - */ - public int getNpcType() { - return npcType; - } - - /** - * @param npcType - * the npcType to set - */ - public void setNpcType(int npcType) { - this.npcType = npcType; - } - - /** - * @return the npcID - */ - public int getNpcID() { - return npcID; - } - - /** - * @param npcID - * the npcID to set - */ - public void setNpcID(int npcID) { - this.npcID = npcID; - } + private int unknown01; + private int npcType; + private int npcID; + private float unknown02; + private byte unknown03; + private int unknown04; + + /** + * This is the general purpose constructor + */ + public BuyFromNPCWindowMsg(int unknown01, int npcType, int npcID, + float unknown02, byte unknown03, int unknown04) { + super(Protocol.SHOPLIST); + this.unknown01 = unknown01; + this.npcType = npcType; + this.npcID = npcID; + this.unknown02 = unknown02; + this.unknown03 = unknown03; + this.unknown04 = unknown04; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public BuyFromNPCWindowMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SHOPLIST, origin, reader); + } + + /** + * @see AbstractNetMsg#getPowerOfTwoBufferSize() + */ + @Override + protected int getPowerOfTwoBufferSize() { + // Larger size for historically larger opcodes + return (16); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + unknown01 = reader.getInt(); + npcType = reader.getInt(); + npcID = reader.getInt(); + unknown02 = reader.getFloat(); + unknown03 = reader.get(); + unknown04 = reader.getInt(); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + + ClientConnection clientConnection = (ClientConnection) this.getOrigin(); + PlayerCharacter player = null; + + if (clientConnection != null) + player = clientConnection.getPlayerCharacter(); + + float sellPercent = 1; + + NPC npc = NPC.getFromCache(npcID); + CharacterItemManager man = null; + ArrayList inventory = null; + ArrayList sellInventory = null; + + if (npc != null) { + man = npc.getCharItemManager(); + Contract contract = npc.getContract(); + if (player != null) { + float barget = player.getBargain(); + float profit = npc.getSellPercent(player) - barget; + + if (profit < 1) + profit = 1; + + sellPercent = 1 * profit; + } else + sellPercent = 1 * npc.getSellPercent(); + + if (contract != null) + sellInventory = contract.getSellInventory(); + } + + if (man != null) + inventory = man.getInventory(); + + writer.putInt(unknown01); + writer.putInt(npcType); + writer.putInt(npcID); + + writer.putFloat(sellPercent); //npc sell markup + + int size = 0; + + if (inventory != null) + size += inventory.size(); + + if (sellInventory != null) + size += sellInventory.size(); + + if (size == 0) { + writer.put((byte) 0); + writer.putInt(0); + return; + } + + writer.put((byte) 1); + + int ownerID = npc.getObjectUUID(); + int indexPosition = writer.position(); + writer.putInt(0); //placeholder for item cnt + int total = 0; + + //add generic sell inventory from contract + if (sellInventory != null) { + + for (MobEquipment mobEquipment : sellInventory) { + try { + MobEquipment.serializeForVendor(mobEquipment, writer, sellPercent); + } catch (SerializationException se) { + continue; + } + ++total; + } + } + + //add npc inventory + if (inventory != null) { + for (Item item : inventory) { + if (item.getOwnerID() != ownerID) + continue; + if (item.getItemBase().getType().equals(ItemType.GOLD)) { + if (item.getNumOfItems() == 0) + continue; + } + Item.serializeForClientMsgForVendorWithoutSlot(item, writer, sellPercent); + ++total; + } + } + writer.putIntAt(total, indexPosition); + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the unknown02 + */ + public float getUnknown02() { + return unknown02; + } + + /** + * @param unknown02 the unknown02 to set + */ + public void setUnknown02(float unknown02) { + this.unknown02 = unknown02; + } + + /** + * @return the unknown03 + */ + public byte getUnknown03() { + return unknown03; + } + + /** + * @param unknown03 the unknown03 to set + */ + public void setUnknown03(byte unknown03) { + this.unknown03 = unknown03; + } + + /** + * @return the unknown04 + */ + public int getUnknown04() { + return unknown04; + } + + /** + * @param unknown04 the unknown04 to set + */ + public void setUnknown04(int unknown04) { + this.unknown04 = unknown04; + } + + /** + * @return the npcType + */ + public int getNpcType() { + return npcType; + } + + /** + * @param npcType the npcType to set + */ + public void setNpcType(int npcType) { + this.npcType = npcType; + } + + /** + * @return the npcID + */ + public int getNpcID() { + return npcID; + } + + /** + * @param npcID the npcID to set + */ + public void setNpcID(int npcID) { + this.npcID = npcID; + } } diff --git a/src/engine/net/client/msg/ChangeAltitudeMsg.java b/src/engine/net/client/msg/ChangeAltitudeMsg.java index bb527b15..924a7031 100644 --- a/src/engine/net/client/msg/ChangeAltitudeMsg.java +++ b/src/engine/net/client/msg/ChangeAltitudeMsg.java @@ -18,129 +18,129 @@ import engine.objects.PlayerCharacter; public class ChangeAltitudeMsg extends ClientNetMsg { - private int sourceType; - private int sourceID; - private boolean up; - private float startAlt; - private float targetAlt; - private float amountToMove; - private byte unknown01 = (byte) 0; - - /** - * This is the general purpose constructor. - */ - public ChangeAltitudeMsg() { - super(Protocol.CHANGEALTITUDE); - } - - public ChangeAltitudeMsg(int sourceType, int sourceID, boolean up, float startAlt, float targetAlt, float amountToMove) { - super(Protocol.CHANGEALTITUDE); - this.sourceType = sourceType; - this.sourceID = sourceID; - this.startAlt = startAlt; - this.targetAlt = targetAlt; - this.amountToMove = amountToMove; - this.up = up; - } - - public static ChangeAltitudeMsg GroundPlayerMsg(PlayerCharacter pc){ - - ChangeAltitudeMsg msg = new ChangeAltitudeMsg(pc.getObjectType().ordinal(),pc.getObjectUUID(),false,pc.getAltitude(),0,pc.getAltitude()); - return msg; - - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ChangeAltitudeMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CHANGEALTITUDE, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.put((this.up ? (byte) 1 : (byte) 0)); - writer.putFloat(this.startAlt); - writer.putFloat(this.targetAlt); - writer.putFloat(this.amountToMove); - writer.put((byte)0); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.up = (reader.get() == (byte) 1); - this.startAlt = reader.getFloat(); - this.targetAlt = reader.getFloat(); - this.amountToMove = reader.getFloat(); - this.unknown01 = reader.get(); - } - - public int getSourceType() { - return this.sourceType; - } - - public int getSourceID() { - return this.sourceID; - } - - public boolean up() { - return this.up; - } - - public float getStartAlt() { - return this.startAlt; - } - - public float getTargetAlt() { - return this.targetAlt; - } - - public float getAmountToMove() { - return this.amountToMove; - } - - public byte getUnknown01() { - return this.unknown01; - } - - public void setSourceType(int value) { - this.sourceType = value; - } - - public void setSourceID(int value) { - this.sourceID = value; - } - - public void setUp(boolean value) { - this.up = value; - } - - public void setStartAlt(float value) { - this.startAlt = value; - } - - public void setTargetAlt(float value) { - this.targetAlt = value; - } - - public void setAmountToMove(float value) { - this.amountToMove = value; - } - - public void setUnknown01(byte value) { - this.unknown01 = value; - } + private int sourceType; + private int sourceID; + private boolean up; + private float startAlt; + private float targetAlt; + private float amountToMove; + private byte unknown01 = (byte) 0; + + /** + * This is the general purpose constructor. + */ + public ChangeAltitudeMsg() { + super(Protocol.CHANGEALTITUDE); + } + + public ChangeAltitudeMsg(int sourceType, int sourceID, boolean up, float startAlt, float targetAlt, float amountToMove) { + super(Protocol.CHANGEALTITUDE); + this.sourceType = sourceType; + this.sourceID = sourceID; + this.startAlt = startAlt; + this.targetAlt = targetAlt; + this.amountToMove = amountToMove; + this.up = up; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ChangeAltitudeMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CHANGEALTITUDE, origin, reader); + } + + public static ChangeAltitudeMsg GroundPlayerMsg(PlayerCharacter pc) { + + ChangeAltitudeMsg msg = new ChangeAltitudeMsg(pc.getObjectType().ordinal(), pc.getObjectUUID(), false, pc.getAltitude(), 0, pc.getAltitude()); + return msg; + + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.put((this.up ? (byte) 1 : (byte) 0)); + writer.putFloat(this.startAlt); + writer.putFloat(this.targetAlt); + writer.putFloat(this.amountToMove); + writer.put((byte) 0); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.up = (reader.get() == (byte) 1); + this.startAlt = reader.getFloat(); + this.targetAlt = reader.getFloat(); + this.amountToMove = reader.getFloat(); + this.unknown01 = reader.get(); + } + + public int getSourceType() { + return this.sourceType; + } + + public void setSourceType(int value) { + this.sourceType = value; + } + + public int getSourceID() { + return this.sourceID; + } + + public void setSourceID(int value) { + this.sourceID = value; + } + + public boolean up() { + return this.up; + } + + public float getStartAlt() { + return this.startAlt; + } + + public void setStartAlt(float value) { + this.startAlt = value; + } + + public float getTargetAlt() { + return this.targetAlt; + } + + public void setTargetAlt(float value) { + this.targetAlt = value; + } + + public float getAmountToMove() { + return this.amountToMove; + } + + public void setAmountToMove(float value) { + this.amountToMove = value; + } + + public byte getUnknown01() { + return this.unknown01; + } + + public void setUnknown01(byte value) { + this.unknown01 = value; + } + + public void setUp(boolean value) { + this.up = value; + } } diff --git a/src/engine/net/client/msg/ChangeGuildLeaderMsg.java b/src/engine/net/client/msg/ChangeGuildLeaderMsg.java index 3491b9d6..38423144 100644 --- a/src/engine/net/client/msg/ChangeGuildLeaderMsg.java +++ b/src/engine/net/client/msg/ChangeGuildLeaderMsg.java @@ -19,16 +19,16 @@ import engine.net.client.Protocol; public class ChangeGuildLeaderMsg extends ClientNetMsg { - private int targetID; - - + private int targetID; + + /** * This constructor is used by NetMsgFactory. It attempts to deserialize the * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading * past the limit) then this constructor Throws that Exception to the * caller. */ - public ChangeGuildLeaderMsg(AbstractConnection origin, ByteBufferReader reader) { + public ChangeGuildLeaderMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.CHANGEGUILDLEADER, origin, reader); } @@ -36,14 +36,14 @@ public class ChangeGuildLeaderMsg extends ClientNetMsg { * Deserializes the subclass specific items from the supplied NetMsgReader. */ @Override - protected void _deserialize(ByteBufferReader reader) { - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - targetID = reader.getInt(); - reader.getInt(); - reader.get(); + protected void _deserialize(ByteBufferReader reader) { + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + targetID = reader.getInt(); + reader.getInt(); + reader.get(); } /** @@ -51,22 +51,22 @@ public class ChangeGuildLeaderMsg extends ClientNetMsg { */ @Override protected void _serialize(ByteBufferWriter writer) throws SerializationException { - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(GameObjectType.PlayerCharacter.ordinal()); - writer.putInt(targetID); - writer.put((byte)100); - writer.putInt(0); - - + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(GameObjectType.PlayerCharacter.ordinal()); + writer.putInt(targetID); + writer.put((byte) 100); + writer.putInt(0); + + } - public int getTargetID() { - return targetID; - } + public int getTargetID() { + return targetID; + } - public void setTargetID(int targetID) { - this.targetID = targetID; - } + public void setTargetID(int targetID) { + this.targetID = targetID; + } } diff --git a/src/engine/net/client/msg/ChatFilterMsg.java b/src/engine/net/client/msg/ChatFilterMsg.java index 593fb262..cd3e8bcd 100644 --- a/src/engine/net/client/msg/ChatFilterMsg.java +++ b/src/engine/net/client/msg/ChatFilterMsg.java @@ -37,7 +37,7 @@ public class ChatFilterMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public ChatFilterMsg(AbstractConnection origin, ByteBufferReader reader) { + public ChatFilterMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.CHANNELMUTE, origin, reader); } @@ -54,7 +54,7 @@ public class ChatFilterMsg extends ClientNetMsg { * Deserializes the subclass specific items from the supplied NetMsgReader. */ @Override - protected void _deserialize(ByteBufferReader reader) { + protected void _deserialize(ByteBufferReader reader) { this.channel = reader.getInt(); this.mute = reader.get(); } @@ -63,11 +63,11 @@ public class ChatFilterMsg extends ClientNetMsg { return this.channel; } - public byte getMute() { - return mute; - } + public byte getMute() { + return mute; + } - public void setMute(byte mute) { - this.mute = mute; - } + public void setMute(byte mute) { + this.mute = mute; + } } diff --git a/src/engine/net/client/msg/CityAssetMsg.java b/src/engine/net/client/msg/CityAssetMsg.java index 515794a1..e83a1830 100644 --- a/src/engine/net/client/msg/CityAssetMsg.java +++ b/src/engine/net/client/msg/CityAssetMsg.java @@ -28,192 +28,191 @@ import java.util.Set; public class CityAssetMsg extends ClientNetMsg { - Set allCityAssets; - Set canProtectAssets; - private int type; - private int buildingID; - private int size; - private int pad = 0; + Set allCityAssets; + Set canProtectAssets; + private int type; + private int buildingID; + private int size; + private int pad = 0; - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public CityAssetMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CITYASSET, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public CityAssetMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CITYASSET, origin, reader); + } - public CityAssetMsg() { - super(Protocol.CITYASSET); - } + public CityAssetMsg() { + super(Protocol.CITYASSET); + } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.type = reader.getInt(); - reader.getInt(); - this.buildingID = reader.getInt(); - reader.getInt(); + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.type = reader.getInt(); + reader.getInt(); + this.buildingID = reader.getInt(); + reader.getInt(); - } + } - @Override - protected int getPowerOfTwoBufferSize() { - // Larger size for historically larger opcodes - return (12); - } + @Override + protected int getPowerOfTwoBufferSize() { + // Larger size for historically larger opcodes + return (12); + } - // Precache and configure this message before we serialize it + // Precache and configure this message before we serialize it - public void configure() { + public void configure() { - Building tol; - Zone zone; - City city; + Building tol; + Zone zone; + City city; - canProtectAssets = new HashSet<>(); + canProtectAssets = new HashSet<>(); - tol = BuildingManager.getBuildingFromCache(this.buildingID); + tol = BuildingManager.getBuildingFromCache(this.buildingID); - if (tol == null) { - Logger.debug("TOL is null"); - return; - } + if (tol == null) { + Logger.debug("TOL is null"); + return; + } - zone = tol.getParentZone(); + zone = tol.getParentZone(); - if (zone == null) { - Logger.debug("Zone is null"); - return; - } + if (zone == null) { + Logger.debug("Zone is null"); + return; + } - city = City.getCity(zone.getPlayerCityUUID()); + city = City.getCity(zone.getPlayerCityUUID()); - if (city == null) { - Logger.debug( "Failed to load city data for Tree of life."); - return; - } + if (city == null) { + Logger.debug("Failed to load city data for Tree of life."); + return; + } - allCityAssets = zone.zoneBuildingSet; + allCityAssets = zone.zoneBuildingSet; - for (Building building : allCityAssets) { + for (Building building : allCityAssets) { - if (building.getBlueprint() == null) - continue; + if (building.getBlueprint() == null) + continue; - // Protected assets do not show up on list + // Protected assets do not show up on list - if (building.assetIsProtected() == true) - continue; + if (building.assetIsProtected() == true) + continue; - if (building.getProtectionState() == ProtectionState.PENDING) - continue; + if (building.getProtectionState() == ProtectionState.PENDING) + continue; - // Shouldn't need this but just in case + // Shouldn't need this but just in case - if (building.getBlueprint().isWallPiece()) - continue; + if (building.getBlueprint().isWallPiece()) + continue; - if (building.getBlueprint().getBuildingGroup().equals(Enum.BuildingGroup.TOL)) - continue; + if (building.getBlueprint().getBuildingGroup().equals(Enum.BuildingGroup.TOL)) + continue; - if (building.getBlueprint().getBuildingGroup().equals(Enum.BuildingGroup.BANESTONE)) - continue; + if (building.getBlueprint().getBuildingGroup().equals(Enum.BuildingGroup.BANESTONE)) + continue; - if (building.getBlueprint().getBuildingGroup().equals(Enum.BuildingGroup.SHRINE)) - continue; + if (building.getBlueprint().getBuildingGroup().equals(Enum.BuildingGroup.SHRINE)) + continue; - if (!city.isLocationOnCityGrid(building.getLoc())) - continue; + if (!city.isLocationOnCityGrid(building.getLoc())) + continue; - canProtectAssets.add(building); + canProtectAssets.add(building); - } + } - } + } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { - String buildingName; + String buildingName; - writer.putInt(0); - writer.putInt(0); + writer.putInt(0); + writer.putInt(0); - writer.putInt(GameObjectType.Building.ordinal()); - writer.putInt(this.buildingID); + writer.putInt(GameObjectType.Building.ordinal()); + writer.putInt(this.buildingID); - writer.putInt(canProtectAssets.size()); + writer.putInt(canProtectAssets.size()); - for (Building cityBuilding : canProtectAssets) { + for (Building cityBuilding : canProtectAssets) { - buildingName = cityBuilding.getName(); + buildingName = cityBuilding.getName(); - if (buildingName.isEmpty() && cityBuilding.getBlueprint() != null) { - buildingName = cityBuilding.getBlueprint().getName(); - } + if (buildingName.isEmpty() && cityBuilding.getBlueprint() != null) { + buildingName = cityBuilding.getBlueprint().getName(); + } - writer.putInt(cityBuilding.getObjectType().ordinal()); - writer.putInt(cityBuilding.getObjectUUID()); + writer.putInt(cityBuilding.getObjectType().ordinal()); + writer.putInt(cityBuilding.getObjectUUID()); - writer.putString(buildingName); - writer.putString(cityBuilding.getGuild().getName()); - writer.putInt(20);// \/ Temp \/ - writer.putInt(cityBuilding.getRank()); + writer.putString(buildingName); + writer.putString(cityBuilding.getGuild().getName()); + writer.putInt(20);// \/ Temp \/ + writer.putInt(cityBuilding.getRank()); - if (cityBuilding.getBlueprint() != null) { - writer.putInt(cityBuilding.getBlueprint().getIcon()); - } - else { - writer.putInt(0); - } - writer.putInt(7); //TODO identify these Guild tags?? - writer.putInt(17); - writer.putInt(14); - writer.putInt(14); - writer.putInt(98);// /\ Temp /\ + if (cityBuilding.getBlueprint() != null) { + writer.putInt(cityBuilding.getBlueprint().getIcon()); + } else { + writer.putInt(0); + } + writer.putInt(7); //TODO identify these Guild tags?? + writer.putInt(17); + writer.putInt(14); + writer.putInt(14); + writer.putInt(98);// /\ Temp /\ - } - } + } + } - public int getPad() { - return pad; - } + public int getPad() { + return pad; + } - public void setPad(int value) { - this.pad = value; - } + public void setPad(int value) { + this.pad = value; + } - public int getType() { - return type; - } + public int getType() { + return type; + } - public void setType(int type) { - this.type = type; - } + public void setType(int type) { + this.type = type; + } - public int getSize() { - return size; - } + public int getSize() { + return size; + } - public void setSize(int size) { - this.size = size; - } + public void setSize(int size) { + this.size = size; + } - public int getBuildingID() { - return buildingID; - } + public int getBuildingID() { + return buildingID; + } - public void setBuildingID(int buildingID) { - this.buildingID = buildingID; - } + public void setBuildingID(int buildingID) { + this.buildingID = buildingID; + } } diff --git a/src/engine/net/client/msg/CityChoiceMsg.java b/src/engine/net/client/msg/CityChoiceMsg.java index 5c43439c..1e89ec07 100644 --- a/src/engine/net/client/msg/CityChoiceMsg.java +++ b/src/engine/net/client/msg/CityChoiceMsg.java @@ -20,88 +20,89 @@ import engine.objects.PlayerCharacter; public class CityChoiceMsg extends ClientNetMsg { - private PlayerCharacter pc; - private boolean isTeleport; - private int msgType; - private int cityID; - - /** - * This is the general purpose constructor. - */ - public CityChoiceMsg(PlayerCharacter pc, boolean isTeleport) { - super(Protocol.CITYCHOICE); - this.pc = pc; - this.isTeleport = isTeleport; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public CityChoiceMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CITYCHOICE, origin, reader); - } - - /** - * Copy constructor - */ - public CityChoiceMsg(CityChoiceMsg msg) { - super(Protocol.CITYCHOICE); - this.pc = msg.pc; - this.isTeleport = msg.isTeleport; - } - - /** - * @see AbstractNetMsg#getPowerOfTwoBufferSize() - */ - @Override - protected int getPowerOfTwoBufferSize() { - // Larger size for historically larger opcodes - return (12); - } - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - //Do we even want to try this? - this.msgType = reader.getInt(); - reader.getInt(); - this.cityID = reader.getInt(); - reader.getInt(); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - - } - - public PlayerCharacter pc() { - return this.pc; - } - - public boolean isTeleport() { - return this.isTeleport; - } - - public void setPC(PlayerCharacter pc) { - this.pc = pc; - } - - public void setIsTeleport(boolean value) { - this.isTeleport = value; - } - - public int getMsgType() { - return msgType; - } - - public int getCityID() { - return cityID; - } + private PlayerCharacter pc; + private boolean isTeleport; + private int msgType; + private int cityID; + + /** + * This is the general purpose constructor. + */ + public CityChoiceMsg(PlayerCharacter pc, boolean isTeleport) { + super(Protocol.CITYCHOICE); + this.pc = pc; + this.isTeleport = isTeleport; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public CityChoiceMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CITYCHOICE, origin, reader); + } + + /** + * Copy constructor + */ + public CityChoiceMsg(CityChoiceMsg msg) { + super(Protocol.CITYCHOICE); + this.pc = msg.pc; + this.isTeleport = msg.isTeleport; + } + + /** + * @see AbstractNetMsg#getPowerOfTwoBufferSize() + */ + @Override + protected int getPowerOfTwoBufferSize() { + // Larger size for historically larger opcodes + return (12); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + //Do we even want to try this? + this.msgType = reader.getInt(); + reader.getInt(); + this.cityID = reader.getInt(); + reader.getInt(); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + + } + + public PlayerCharacter pc() { + return this.pc; + } + + public boolean isTeleport() { + return this.isTeleport; + } + + public void setPC(PlayerCharacter pc) { + this.pc = pc; + } + + public void setIsTeleport(boolean value) { + this.isTeleport = value; + } + + public int getMsgType() { + return msgType; + } + + public int getCityID() { + return cityID; + } } diff --git a/src/engine/net/client/msg/CityDataMsg.java b/src/engine/net/client/msg/CityDataMsg.java index c70ca624..f5f679e7 100644 --- a/src/engine/net/client/msg/CityDataMsg.java +++ b/src/engine/net/client/msg/CityDataMsg.java @@ -29,14 +29,12 @@ import java.util.concurrent.ConcurrentHashMap; public class CityDataMsg extends ClientNetMsg { - private Session s; - private final boolean forEnterWorld; - private static ByteBuffer cachedEnterWorld; - private static long cachedExpireTime; - public static final long wdComp = 0xFF00FF0000000003L; private static final byte ver = 1; - + private static ByteBuffer cachedEnterWorld; + private static long cachedExpireTime; + private final boolean forEnterWorld; + private Session s; private boolean updateCities = false; private boolean updateRunegates = false; private boolean updateMines = false; @@ -73,6 +71,44 @@ public class CityDataMsg extends ClientNetMsg { this.forEnterWorld = false; } + private static void attemptSerializeForEnterWorld(ByteBuffer bb) { + bb.clear(); + ByteBufferWriter temp = new ByteBufferWriter(bb); + temp.put((byte) 0); // PAD + + + ArrayList cityList = new ArrayList<>(); + ConcurrentHashMap map = DbManager.getMap(Enum.GameObjectType.City); + for (AbstractGameObject ago : map.values()) + + if (ago.getObjectType().equals(Enum.GameObjectType.City)) + cityList.add((City) ago); + + temp.putInt(cityList.size()); + + for (City city : cityList) + City.serializeForClientMsg(city, temp); + temp.put((byte) 0); // PAD + + // Serialize runegates + + temp.putInt(Runegate._runegates.values().size()); + + for (Runegate runegate : Runegate._runegates.values()) { + runegate._serializeForEnterWorld(temp); + } + + ArrayList mineList = new ArrayList<>(); + for (Mine toAdd : Mine.mineMap.keySet()) { + mineList.add(toAdd); + } + + temp.putInt(mineList.size()); + for (Mine mine : mineList) + Mine.serializeForClientMsg(mine, temp); + temp.put((byte) 0); // PAD + } + @Override protected int getPowerOfTwoBufferSize() { return (18); // 2^14 == 16384 @@ -183,44 +219,6 @@ public class CityDataMsg extends ClientNetMsg { } - private static void attemptSerializeForEnterWorld(ByteBuffer bb) { - bb.clear(); - ByteBufferWriter temp = new ByteBufferWriter(bb); - temp.put((byte) 0); // PAD - - - ArrayList cityList = new ArrayList<>(); - ConcurrentHashMap map = DbManager.getMap(Enum.GameObjectType.City); - for (AbstractGameObject ago : map.values()) - - if (ago.getObjectType().equals(Enum.GameObjectType.City)) - cityList.add((City) ago); - - temp.putInt(cityList.size()); - - for (City city : cityList) - City.serializeForClientMsg(city, temp); - temp.put((byte) 0); // PAD - - // Serialize runegates - - temp.putInt(Runegate._runegates.values().size()); - - for (Runegate runegate : Runegate._runegates.values()) { - runegate._serializeForEnterWorld(temp); - } - - ArrayList mineList = new ArrayList<>(); - for (Mine toAdd : Mine.mineMap.keySet()) { - mineList.add(toAdd); - } - - temp.putInt(mineList.size()); - for (Mine mine : mineList) - Mine.serializeForClientMsg(mine, temp); - temp.put((byte) 0); // PAD - } - /** * Deserializes the subclass specific items from the supplied NetMsgReader. */ diff --git a/src/engine/net/client/msg/CityZoneMsg.java b/src/engine/net/client/msg/CityZoneMsg.java index 41ea295e..80736b50 100644 --- a/src/engine/net/client/msg/CityZoneMsg.java +++ b/src/engine/net/client/msg/CityZoneMsg.java @@ -18,139 +18,137 @@ import engine.objects.Zone; public class CityZoneMsg extends ClientNetMsg { - private int messageType; //1 or 2 - private int zoneType; - private int zoneID; - private float locX; - private float locY; - private float locZ; - private String name; - private float radiusX; - private float radiusZ; - private int unknown01 = 0; - - /** - * This is the general purpose constructor. - */ - - public CityZoneMsg(int messageType, float locX, float locY, float locZ, String name, Zone zone, float radiusX, float radiusZ) { - super(Protocol.CITYZONE); - this.messageType = messageType; //only 1 or 2 used on message type - this.zoneType = GameObjectType.Zone.ordinal(); - this.zoneID = zone.getObjectUUID(); - this.locX = locX; - this.locY = locY; - this.locZ = locZ; - this.name = name; - this.radiusX = radiusX; - this.radiusZ = radiusZ; - this.unknown01 = 0; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public CityZoneMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.CITYZONE, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - - - writer.putInt(this.messageType); - - - //MSGTYPE 3 SERIALIZATION - if (this.messageType == 3){ - writer.putInt(1); - writer.putInt(this.zoneType); - writer.putInt(this.zoneID); - writer.putString("RuinedCity"); - writer.putString("Ruined"); - writer.putFloat(this.locX); - writer.putFloat(this.locY); - writer.putFloat(this.locZ); - writer.putInt(0); - return; - } - - - - //END SERIALIZIONTYPE 3 - - // writer.putInt(this.messageType); - if (this.messageType == 1){ - writer.putInt(this.zoneType); - writer.putInt(this.zoneID); - } - - writer.putFloat(this.locX); - writer.putFloat(this.locY); - writer.putFloat(this.locZ); - writer.putString(this.name); - if (this.messageType == 1) { - writer.putFloat(this.radiusX); - writer.putFloat(this.radiusZ); - } - writer.putInt(this.unknown01); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - // this.locX = reader.getFloat(); - // this.locY = reader.getFloat(); - // this.locZ = reader.getFloat(); - // this.name = reader.getString(); - // this.unknown01 = reader.getInt(); - } - - public float getLocX() { - return this.locX; - } - - public float getLocY() { - return this.locY; - } - - public float getLocZ() { - return this.locZ; - } - - public String getName() { - return this.name; - } - - public int getUnknown01() { - return this.unknown01; - } - - public void setLocX(float value) { - this.locX = value; - } - - public void setLocY(float value) { - this.locY = value; - } - - public void setLocZ(float value) { - this.locZ = value; - } - - public void setName(String value) { - this.name = value; - } - - public void setUnknown01(int value) { - this.unknown01 = value; - } + private int messageType; //1 or 2 + private int zoneType; + private int zoneID; + private float locX; + private float locY; + private float locZ; + private String name; + private float radiusX; + private float radiusZ; + private int unknown01 = 0; + + /** + * This is the general purpose constructor. + */ + + public CityZoneMsg(int messageType, float locX, float locY, float locZ, String name, Zone zone, float radiusX, float radiusZ) { + super(Protocol.CITYZONE); + this.messageType = messageType; //only 1 or 2 used on message type + this.zoneType = GameObjectType.Zone.ordinal(); + this.zoneID = zone.getObjectUUID(); + this.locX = locX; + this.locY = locY; + this.locZ = locZ; + this.name = name; + this.radiusX = radiusX; + this.radiusZ = radiusZ; + this.unknown01 = 0; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public CityZoneMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CITYZONE, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + + + writer.putInt(this.messageType); + + + //MSGTYPE 3 SERIALIZATION + if (this.messageType == 3) { + writer.putInt(1); + writer.putInt(this.zoneType); + writer.putInt(this.zoneID); + writer.putString("RuinedCity"); + writer.putString("Ruined"); + writer.putFloat(this.locX); + writer.putFloat(this.locY); + writer.putFloat(this.locZ); + writer.putInt(0); + return; + } + + + //END SERIALIZIONTYPE 3 + + // writer.putInt(this.messageType); + if (this.messageType == 1) { + writer.putInt(this.zoneType); + writer.putInt(this.zoneID); + } + + writer.putFloat(this.locX); + writer.putFloat(this.locY); + writer.putFloat(this.locZ); + writer.putString(this.name); + if (this.messageType == 1) { + writer.putFloat(this.radiusX); + writer.putFloat(this.radiusZ); + } + writer.putInt(this.unknown01); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + // this.locX = reader.getFloat(); + // this.locY = reader.getFloat(); + // this.locZ = reader.getFloat(); + // this.name = reader.getString(); + // this.unknown01 = reader.getInt(); + } + + public float getLocX() { + return this.locX; + } + + public void setLocX(float value) { + this.locX = value; + } + + public float getLocY() { + return this.locY; + } + + public void setLocY(float value) { + this.locY = value; + } + + public float getLocZ() { + return this.locZ; + } + + public void setLocZ(float value) { + this.locZ = value; + } + + public String getName() { + return this.name; + } + + public void setName(String value) { + this.name = value; + } + + public int getUnknown01() { + return this.unknown01; + } + + public void setUnknown01(int value) { + this.unknown01 = value; + } } diff --git a/src/engine/net/client/msg/ClaimAssetMsg.java b/src/engine/net/client/msg/ClaimAssetMsg.java index 16b77bfe..5e41afae 100644 --- a/src/engine/net/client/msg/ClaimAssetMsg.java +++ b/src/engine/net/client/msg/ClaimAssetMsg.java @@ -18,54 +18,56 @@ import engine.net.client.Protocol; public class ClaimAssetMsg extends ClientNetMsg { - private int pad; - private int objectType; - private int objectUUID; + private int pad; + private int objectType; + private int objectUUID; - public ClaimAssetMsg(int objectType, int objectUUID) { - super(Protocol.CLAIMASSET); - this.pad = 0; - this.objectType = objectType; - this.objectUUID = objectUUID; - } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ClaimAssetMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CLAIMASSET, origin, reader); - } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.pad = reader.getInt(); - this.objectType = reader.getInt(); - this.objectUUID = reader.getInt(); - } + public ClaimAssetMsg(int objectType, int objectUUID) { + super(Protocol.CLAIMASSET); + this.pad = 0; + this.objectType = objectType; + this.objectUUID = objectUUID; + } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - writer.putInt(this.pad); - writer.putInt(this.objectType); - writer.putInt(this.objectUUID); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ClaimAssetMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CLAIMASSET, origin, reader); + } - public int getObjectType() { - return objectType; - } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.pad = reader.getInt(); + this.objectType = reader.getInt(); + this.objectUUID = reader.getInt(); + } - public void setObjectType(int value) { - this.objectType = value; - } + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + writer.putInt(this.pad); + writer.putInt(this.objectType); + writer.putInt(this.objectUUID); + } - public int getUUID() { - return objectUUID; - } + public int getObjectType() { + return objectType; + } + + public void setObjectType(int value) { + this.objectType = value; + } + + public int getUUID() { + return objectUUID; + } } diff --git a/src/engine/net/client/msg/ClaimGuildTreeMsg.java b/src/engine/net/client/msg/ClaimGuildTreeMsg.java index 7661b6ef..de4d2767 100644 --- a/src/engine/net/client/msg/ClaimGuildTreeMsg.java +++ b/src/engine/net/client/msg/ClaimGuildTreeMsg.java @@ -23,347 +23,354 @@ import engine.net.client.Protocol; */ public class ClaimGuildTreeMsg extends ClientNetMsg { - // 2 = manage this asset. 20 = manage entire city - - private int messageType; - - private int targetType; - private int targetID; - - private int charter; - private int bgc1; - private int bgc2; - private int symbolColor; - private int bgDesign; - private int symbol; - private int unknown07; - private int unknown08; - private int unknown09; - private int unknown10; - private int unknown11; - - private String CityName; - private String OwnerName; - private String GuildName; - private int unknown12; - private byte UnkByte01; - private int unknown13; - private int unknown14; - private int unknown15; - private int unknown16; - private int unknown17; - private int unknown18; - - private byte UnkByte02; - private byte UnkByte03; - private byte UnkByte04; - private byte UnkByte05; - - private int unknown19; //Arraylist motto length? - private String motto; //motto Length 60 max? - public static final int RENAME_TREE = 2; - public static final int OPEN_CITY = 4; - public static final int CLOSE_CITY = 5; - private String treeName; + // 2 = manage this asset. 20 = manage entire city + + public static final int RENAME_TREE = 2; + public static final int OPEN_CITY = 4; + public static final int CLOSE_CITY = 5; + private int messageType; + private int targetType; + private int targetID; + private int charter; + private int bgc1; + private int bgc2; + private int symbolColor; + private int bgDesign; + private int symbol; + private int unknown07; + private int unknown08; + private int unknown09; + private int unknown10; + private int unknown11; + private String CityName; + private String OwnerName; + private String GuildName; + private int unknown12; + private byte UnkByte01; + private int unknown13; + private int unknown14; + private int unknown15; + private int unknown16; + private int unknown17; + private int unknown18; + private byte UnkByte02; + private byte UnkByte03; + private byte UnkByte04; + private byte UnkByte05; + private int unknown19; //Arraylist motto length? + private String motto; //motto Length 60 max? + private String treeName; // private int unknown01; + /** + * This is the general purpose constructor + */ + public ClaimGuildTreeMsg() { + super(Protocol.CLAIMGUILDTREE); + this.messageType = 0; + this.targetType = 0; + this.targetID = 0; + + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public ClaimGuildTreeMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CLAIMGUILDTREE, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.messageType = reader.getInt(); + switch (this.messageType) { + case OPEN_CITY: + case CLOSE_CITY: + targetType = reader.getInt(); + targetID = reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + break; + case RENAME_TREE: + targetType = reader.getInt(); + targetID = reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + this.treeName = reader.getString(); + break; + default: + targetType = reader.getInt(); + targetID = reader.getInt(); + reader.getInt(); + reader.getInt(); + this.treeName = reader.getString(); + break; + } + + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.messageType); + writer.putInt(this.targetType); + writer.putInt(this.targetID); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + if (this.messageType == RENAME_TREE) + writer.putString(this.treeName); + } + + /** + * @return the charter + */ + public int getcharter() { + return charter; + } + + + public int getbgc1() { + return bgc1; + } + + public int getbgc2() { + return bgc2; + } + + public int getsymbolColor() { + return symbolColor; + } + + public int getbgDesign() { + return bgDesign; + } + + public int getsymbol() { + return symbol; + } + + public int getUnknown07() { + return unknown07; + } + + public void setUnknown07(int unknown07) { + this.unknown07 = unknown07; + } + + public int getUnknown08() { + return unknown08; + } + + public void setUnknown08(int unknown08) { + this.unknown08 = unknown08; + } + + public int getUnknown09() { + return unknown09; + } + + public void setUnknown09(int unknown09) { + this.unknown09 = unknown09; + } + + public int getUnknown10() { + return unknown10; + } + + public void setUnknown10(int unknown10) { + this.unknown10 = unknown10; + } + + public int getUnknown11() { + return unknown11; + } + + public void setUnknown11(int unknown11) { + this.unknown11 = unknown11; + } + + public int getUnknown12() { + return unknown12; + } + + public void setUnknown12(int unknown12) { + this.unknown12 = unknown12; + } + + public int getUnknown13() { + return unknown13; + } + + public void setUnknown13(int unknown13) { + this.unknown13 = unknown13; + } + + public int getUnknown14() { + return unknown14; + } + + public void setUnknown14(int unknown14) { + this.unknown14 = unknown14; + } + + public int getUnknown15() { + return unknown15; + } + public void setUnknown15(int unknown15) { + this.unknown15 = unknown15; + } + public int getUnknown16() { + return unknown16; + } + public void setUnknown16(int unknown16) { + this.unknown16 = unknown16; + } + public int getUnknown17() { + return unknown17; + } + public void setUnknown17(int unknown17) { + this.unknown17 = unknown17; + } + public int getUnknown18() { + return unknown18; + } - /** - * This is the general purpose constructor - */ - public ClaimGuildTreeMsg() { - super(Protocol.CLAIMGUILDTREE); - this.messageType = 0; - this.targetType=0; - this.targetID = 0; - - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public ClaimGuildTreeMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.CLAIMGUILDTREE, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - this.messageType = reader.getInt(); - switch (this.messageType){ - case OPEN_CITY: - case CLOSE_CITY: - targetType = reader.getInt(); - targetID = reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - break; - case RENAME_TREE: - targetType = reader.getInt(); - targetID = reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - this.treeName = reader.getString(); - break; - default: - targetType = reader.getInt(); - targetID = reader.getInt(); - reader.getInt(); - reader.getInt(); - this.treeName = reader.getString(); - break; - } - - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer){ - writer.putInt(this.messageType); - writer.putInt(this.targetType); - writer.putInt(this.targetID); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - if (this.messageType == RENAME_TREE) - writer.putString(this.treeName); - } - - /** - * @return the charter - */ - public int getcharter() { - return charter; - } - - - - - public int getbgc1() { - return bgc1; - } - public int getbgc2() { - return bgc2; - } - public int getsymbolColor() { - return symbolColor; - } - public int getbgDesign() { - return bgDesign; - } - public int getsymbol() { - return symbol; - } - public int getUnknown07() { - return unknown07; - } - public int getUnknown08() { - return unknown08; - } - public int getUnknown09() { - return unknown09; - } - public int getUnknown10() { - return unknown10; - } - public int getUnknown11() { - return unknown11; - } - public int getUnknown12() { - return unknown12; - } - public int getUnknown13() { - return unknown13; - } - public int getUnknown14() { - return unknown14; - } - public int getUnknown15() { - return unknown15; - } - public int getUnknown16() { - return unknown16; - } - public int getUnknown17() { - return unknown17; - } - public int getUnknown18() { - return unknown18; - } - public int getUnknown19() { - return unknown19; - } - - - - - - - - - - public String getOwnerName() { - return OwnerName; - } - - public String getCityName() { - return CityName; - } - - public String getGuildName() { - return GuildName; - } - public void setcharter(int charter) { - this.charter = charter; - } - public void setbgc1 (int bgc1) { - this.bgc1 = bgc1; - } - public void setbgc2 (int bgc2) { - this.bgc2 = bgc2; - } - public void setsymbolColor (int symbolColor) { - this.symbolColor = symbolColor; - } - public void setbgDesign (int bgDesign) { - this.bgDesign = bgDesign; - } - public void setsymbol (int symbol) { - this.symbol = symbol; - } - public void setUnknown07 (int unknown07) { - this.unknown07 = unknown07; - } - public void setUnknown08 (int unknown08) { - this.unknown08 = unknown08; - } - public void setUnknown09 (int unknown09) { - this.unknown09 = unknown09; - } - public void setUnknown10 (int unknown10) { - this.unknown10 = unknown10; - } - public void setUnknown11 (int unknown11) { - this.unknown11 = unknown11; - } - public void setUnknown12 (int unknown12) { - this.unknown12 = unknown12; - } - public void setUnknown13 (int unknown13) { - this.unknown13 = unknown13; - } - public void setUnknown14 (int unknown14) { - this.unknown14 = unknown14; - } - public void setUnknown15 (int unknown15) { - this.unknown15 = unknown15; - } - public void setUnknown16 (int unknown16) { - this.unknown16 = unknown16; - } - public void setUnknown17 (int unknown17) { - this.unknown17 = unknown17; - } - public void setUnknown18 (int unknown18) { - this.unknown18 = unknown18; - } - public void setUnknown19 (int unknown19) { - this.unknown19 = unknown19; - } - - - - - public void setUnkByte01 (byte UnkByte01) { - this.UnkByte01 = UnkByte01; - } - public void setUnkByte02 (byte UnkByte02) { - this.UnkByte02 = UnkByte02; - } - public void setUnkByte03 (byte UnkByte03) { - this.UnkByte03 = UnkByte03; - } - public void setUnkByte04 (byte UnkByte04) { - this.UnkByte04 = UnkByte04; - } - - - public void setOwnerName(String OwnerName) { - this.OwnerName = OwnerName; - } - - public void setCityName(String CityName) { - this.CityName = CityName; - } - - public void setGuildName(String GuildName) { - this.GuildName = GuildName; - } - - - - public void setMotto(String motto) { - this.motto = motto; - } - - public String getMotto() { - return motto; - } - - - - public void setUnkByte05(byte unkByte05) { - UnkByte05 = unkByte05; - } - - public byte getUnkByte05() { - return UnkByte05; - } - - public void setMessageType(int value) { - this.messageType = value; - } - - public int getMessageType() { - return messageType; - } - - public int getTargetID() { - return targetID; - } - - public void setTargetID(int targetID) { - this.targetID = targetID; - } - - public int getTargetType() { - return targetType; - } - - public void setTargetType(int targetType) { - this.targetType = targetType; - } - - - public String getTreeName() { - return treeName; - } + public void setUnknown18(int unknown18) { + this.unknown18 = unknown18; + } + + public int getUnknown19() { + return unknown19; + } + + public void setUnknown19(int unknown19) { + this.unknown19 = unknown19; + } + + public String getOwnerName() { + return OwnerName; + } + + public void setOwnerName(String OwnerName) { + this.OwnerName = OwnerName; + } + + public String getCityName() { + return CityName; + } + + public void setCityName(String CityName) { + this.CityName = CityName; + } + + public String getGuildName() { + return GuildName; + } + + public void setGuildName(String GuildName) { + this.GuildName = GuildName; + } + + public void setcharter(int charter) { + this.charter = charter; + } + + public void setbgc1(int bgc1) { + this.bgc1 = bgc1; + } + + public void setbgc2(int bgc2) { + this.bgc2 = bgc2; + } + + public void setsymbolColor(int symbolColor) { + this.symbolColor = symbolColor; + } + + public void setbgDesign(int bgDesign) { + this.bgDesign = bgDesign; + } + + public void setsymbol(int symbol) { + this.symbol = symbol; + } + + public void setUnkByte01(byte UnkByte01) { + this.UnkByte01 = UnkByte01; + } + + public void setUnkByte02(byte UnkByte02) { + this.UnkByte02 = UnkByte02; + } + + public void setUnkByte03(byte UnkByte03) { + this.UnkByte03 = UnkByte03; + } + + public void setUnkByte04(byte UnkByte04) { + this.UnkByte04 = UnkByte04; + } + + public String getMotto() { + return motto; + } + + public void setMotto(String motto) { + this.motto = motto; + } + + public byte getUnkByte05() { + return UnkByte05; + } + + public void setUnkByte05(byte unkByte05) { + UnkByte05 = unkByte05; + } + + public int getMessageType() { + return messageType; + } + + public void setMessageType(int value) { + this.messageType = value; + } + + public int getTargetID() { + return targetID; + } + + public void setTargetID(int targetID) { + this.targetID = targetID; + } + + public int getTargetType() { + return targetType; + } + + public void setTargetType(int targetType) { + this.targetType = targetType; + } + + + public String getTreeName() { + return treeName; + } } diff --git a/src/engine/net/client/msg/ClientNetMsg.java b/src/engine/net/client/msg/ClientNetMsg.java index 22611e05..250d810c 100644 --- a/src/engine/net/client/msg/ClientNetMsg.java +++ b/src/engine/net/client/msg/ClientNetMsg.java @@ -19,55 +19,55 @@ import engine.net.client.Protocol; public abstract class ClientNetMsg extends AbstractNetMsg { - /** - * This is the general purpose constructor. - */ - protected ClientNetMsg(Protocol protocolMsg) { - super(protocolMsg); - } + /** + * This is the general purpose constructor. + */ + protected ClientNetMsg(Protocol protocolMsg) { + super(protocolMsg); + } - protected ClientNetMsg(Protocol protocolMsg, ClientNetMsg msg) { - super(protocolMsg, msg); - } + protected ClientNetMsg(Protocol protocolMsg, ClientNetMsg msg) { + super(protocolMsg, msg); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - protected ClientNetMsg(Protocol protocolMsg, AbstractConnection origin, - ByteBufferReader reader) { - super(protocolMsg, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + protected ClientNetMsg(Protocol protocolMsg, AbstractConnection origin, + ByteBufferReader reader) { + super(protocolMsg, origin, reader); + } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected abstract void _deserialize(ByteBufferReader reader) - ; + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected abstract void _deserialize(ByteBufferReader reader) + ; - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected abstract void _serialize(ByteBufferWriter writer) - throws SerializationException; + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected abstract void _serialize(ByteBufferWriter writer) + throws SerializationException; - /* - * return the header size of 4 for ClientMsgs - */ - @Override - protected int getHeaderSize() { - return 4; - } + /* + * return the header size of 4 for ClientMsgs + */ + @Override + protected int getHeaderSize() { + return 4; + } - /* - * Write in the header for ClientMsgs - */ - @Override - protected void writeHeaderAt(int startPos, ByteBufferWriter writer) { - writer.putIntAt(this.getProtocolMsg().opcode, startPos); - } + /* + * Write in the header for ClientMsgs + */ + @Override + protected void writeHeaderAt(int startPos, ByteBufferWriter writer) { + writer.putIntAt(this.getProtocolMsg().opcode, startPos); + } } diff --git a/src/engine/net/client/msg/CloseTradeWindowMsg.java b/src/engine/net/client/msg/CloseTradeWindowMsg.java index d93d0f12..322d9c4b 100644 --- a/src/engine/net/client/msg/CloseTradeWindowMsg.java +++ b/src/engine/net/client/msg/CloseTradeWindowMsg.java @@ -24,65 +24,62 @@ import engine.objects.AbstractGameObject; */ public class CloseTradeWindowMsg extends ClientNetMsg { - private int playerType; - private int playerID; - private int unknown01; - - /** - * This is the general purpose constructor - */ - public CloseTradeWindowMsg(AbstractGameObject player, int unknown01) { - super(Protocol.TRADECLOSE); - this.playerType = player.getObjectType().ordinal(); - this.playerID = player.getObjectUUID(); - this.unknown01 = unknown01; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public CloseTradeWindowMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.TRADECLOSE, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - playerType = reader.getInt(); - playerID = reader.getInt(); - unknown01 = reader.getInt(); - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - writer.putInt(playerType); - writer.putInt(playerID); - - writer.putInt(unknown01); - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - + private int playerType; + private int playerID; + private int unknown01; + + /** + * This is the general purpose constructor + */ + public CloseTradeWindowMsg(AbstractGameObject player, int unknown01) { + super(Protocol.TRADECLOSE); + this.playerType = player.getObjectType().ordinal(); + this.playerID = player.getObjectUUID(); + this.unknown01 = unknown01; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public CloseTradeWindowMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.TRADECLOSE, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + playerType = reader.getInt(); + playerID = reader.getInt(); + unknown01 = reader.getInt(); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putInt(playerType); + writer.putInt(playerID); + + writer.putInt(unknown01); + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } } diff --git a/src/engine/net/client/msg/CommitToTradeMsg.java b/src/engine/net/client/msg/CommitToTradeMsg.java index cb46281e..f0bd2e71 100644 --- a/src/engine/net/client/msg/CommitToTradeMsg.java +++ b/src/engine/net/client/msg/CommitToTradeMsg.java @@ -24,72 +24,70 @@ import engine.net.client.Protocol; */ public class CommitToTradeMsg extends ClientNetMsg { - private int unknown01; - private long playerCompID; - - /** - * This is the general purpose constructor - */ - public CommitToTradeMsg(int unknown01, long playerCompID) { - super(Protocol.TRADECONFIRM); - this.unknown01 = unknown01; - this.playerCompID = playerCompID; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public CommitToTradeMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.TRADECONFIRM, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - unknown01 = reader.getInt(); - playerCompID = reader.getLong(); - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - writer.putInt(unknown01); - writer.putLong(playerCompID); - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the playerCompID - */ - public long getPlayerCompID() { - return playerCompID; - } - - /** - * @param playerCompID the playerCompID to set - */ - public void setPlayerCompID(long playerCompID) { - this.playerCompID = playerCompID; - } + private int unknown01; + private long playerCompID; + + /** + * This is the general purpose constructor + */ + public CommitToTradeMsg(int unknown01, long playerCompID) { + super(Protocol.TRADECONFIRM); + this.unknown01 = unknown01; + this.playerCompID = playerCompID; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public CommitToTradeMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.TRADECONFIRM, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + unknown01 = reader.getInt(); + playerCompID = reader.getLong(); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putInt(unknown01); + writer.putLong(playerCompID); + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the playerCompID + */ + public long getPlayerCompID() { + return playerCompID; + } + + /** + * @param playerCompID the playerCompID to set + */ + public void setPlayerCompID(long playerCompID) { + this.playerCompID = playerCompID; + } } diff --git a/src/engine/net/client/msg/ConfirmPromoteMsg.java b/src/engine/net/client/msg/ConfirmPromoteMsg.java index 7532ff8c..0031d0e3 100644 --- a/src/engine/net/client/msg/ConfirmPromoteMsg.java +++ b/src/engine/net/client/msg/ConfirmPromoteMsg.java @@ -19,7 +19,6 @@ import engine.net.client.Protocol; public class ConfirmPromoteMsg extends ClientNetMsg { - /** * This is the general purpose constructor. * @@ -35,7 +34,7 @@ public class ConfirmPromoteMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public ConfirmPromoteMsg(AbstractConnection origin, ByteBufferReader reader) { + public ConfirmPromoteMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.CONFIRMPROMOTE, origin, reader); } @@ -50,6 +49,6 @@ public class ConfirmPromoteMsg extends ClientNetMsg { * Deserializes the subclass specific items from the supplied NetMsgReader. */ @Override - protected void _deserialize(ByteBufferReader reader) { + protected void _deserialize(ByteBufferReader reader) { } } diff --git a/src/engine/net/client/msg/DeclineFriendMsg.java b/src/engine/net/client/msg/DeclineFriendMsg.java index e0d2c6ce..d1d52f2c 100644 --- a/src/engine/net/client/msg/DeclineFriendMsg.java +++ b/src/engine/net/client/msg/DeclineFriendMsg.java @@ -15,51 +15,50 @@ import engine.objects.PlayerCharacter; public class DeclineFriendMsg extends ClientNetMsg { - public String sourceName; - public String friendName; + public String sourceName; + public String friendName; - /** - * This is the general purpose constructor. - */ - public DeclineFriendMsg(PlayerCharacter pc) { - super(Protocol.FRIENDDECLINE); - } + /** + * This is the general purpose constructor. + */ + public DeclineFriendMsg(PlayerCharacter pc) { + super(Protocol.FRIENDDECLINE); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public DeclineFriendMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.FRIENDDECLINE, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public DeclineFriendMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.FRIENDDECLINE, origin, reader); + } - /** - * Copy constructor - */ - public DeclineFriendMsg(DeclineFriendMsg msg) { - super(Protocol.FRIENDDECLINE); - } + /** + * Copy constructor + */ + public DeclineFriendMsg(DeclineFriendMsg msg) { + super(Protocol.FRIENDDECLINE); + } - - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - //Do we even want to try this? - this.sourceName = reader.getString(); //This is source name.. this friends list must never been updated since launch, not using IDS. - this.friendName = reader.getString(); - } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putString(this.sourceName); - writer.putString(this.friendName); - } + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + //Do we even want to try this? + this.sourceName = reader.getString(); //This is source name.. this friends list must never been updated since launch, not using IDS. + this.friendName = reader.getString(); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putString(this.sourceName); + writer.putString(this.friendName); + } } diff --git a/src/engine/net/client/msg/DeleteItemMsg.java b/src/engine/net/client/msg/DeleteItemMsg.java index ca273e19..fd6ea26d 100644 --- a/src/engine/net/client/msg/DeleteItemMsg.java +++ b/src/engine/net/client/msg/DeleteItemMsg.java @@ -18,62 +18,62 @@ import engine.net.client.Protocol; public class DeleteItemMsg extends ClientNetMsg { - private int type; - private int objectUUID; - private int unknown1, unknown2; + private int type; + private int objectUUID; + private int unknown1, unknown2; - public DeleteItemMsg(int type, int objectUUID) { - super(Protocol.DELETEOBJECT); - this.type = type; - this.objectUUID = objectUUID; - this.unknown1 = 0; - this.unknown2 = 0; - } + public DeleteItemMsg(int type, int objectUUID) { + super(Protocol.DELETEOBJECT); + this.type = type; + this.objectUUID = objectUUID; + this.unknown1 = 0; + this.unknown2 = 0; + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public DeleteItemMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.DELETEOBJECT, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public DeleteItemMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.DELETEOBJECT, origin, reader); + } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.type = reader.getInt(); - this.objectUUID = reader.getInt(); - this.unknown1 = reader.getInt(); - this.unknown2 = reader.getInt(); - } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.type = reader.getInt(); + this.objectUUID = reader.getInt(); + this.unknown1 = reader.getInt(); + this.unknown2 = reader.getInt(); + } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - writer.putInt(this.type); - writer.putInt(this.objectUUID); - writer.putInt(this.unknown1); - writer.putInt(this.unknown2); - } + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + writer.putInt(this.type); + writer.putInt(this.objectUUID); + writer.putInt(this.unknown1); + writer.putInt(this.unknown2); + } - /** - * @return the type - */ - public int getType() { - return type; - } + /** + * @return the type + */ + public int getType() { + return type; + } - /** - * @return the objectUUID - */ - public int getUUID() { - return objectUUID; - } + /** + * @return the objectUUID + */ + public int getUUID() { + return objectUUID; + } } diff --git a/src/engine/net/client/msg/DestroyBuildingMsg.java b/src/engine/net/client/msg/DestroyBuildingMsg.java index 844b2371..d5df7216 100644 --- a/src/engine/net/client/msg/DestroyBuildingMsg.java +++ b/src/engine/net/client/msg/DestroyBuildingMsg.java @@ -17,56 +17,58 @@ import engine.net.ByteBufferWriter; import engine.net.client.Protocol; public class DestroyBuildingMsg extends ClientNetMsg { - private int pad = 0; - private int objectType; - private int objectUUID; + private int pad = 0; + private int objectType; + private int objectUUID; - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public DestroyBuildingMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.DESTROYBUILDING, origin, reader); - } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.pad = reader.getInt(); - this.objectType = reader.getInt(); - this.objectUUID = reader.getInt();; - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public DestroyBuildingMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.DESTROYBUILDING, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - writer.putInt(this.pad); - writer.putInt(this.objectType); - writer.putInt(this.objectUUID); - } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.pad = reader.getInt(); + this.objectType = reader.getInt(); + this.objectUUID = reader.getInt(); + ; + } - public int getObjectType() { - return objectType; - } + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + writer.putInt(this.pad); + writer.putInt(this.objectType); + writer.putInt(this.objectUUID); + } - public void setObjectType(int value) { - this.objectType = value; - } + public int getObjectType() { + return objectType; + } - public void setPad(int value) { - this.pad = value; - } + public void setObjectType(int value) { + this.objectType = value; + } - public int getUUID() { - return objectUUID; - } + public int getUUID() { + return objectUUID; + } - public int getPad() { - return pad; - } + public int getPad() { + return pad; + } + + public void setPad(int value) { + this.pad = value; + } } diff --git a/src/engine/net/client/msg/DoorTryOpenMsg.java b/src/engine/net/client/msg/DoorTryOpenMsg.java index 6fb0fc36..8e9ef720 100644 --- a/src/engine/net/client/msg/DoorTryOpenMsg.java +++ b/src/engine/net/client/msg/DoorTryOpenMsg.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -19,9 +16,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -31,9 +25,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -43,7 +34,6 @@ // www.magicbane.com - package engine.net.client.msg; import engine.Enum.GameObjectType; @@ -55,104 +45,104 @@ import engine.net.client.Protocol; public class DoorTryOpenMsg extends ClientNetMsg { - private int unk1; - private int doorID; - private int buildingUUID; - private int playerUUID; - private byte toggle; - - /** - * This is the general purpose constructor. - */ - public DoorTryOpenMsg(int doorID, int targetID, int senderID, byte toggle) { - super(Protocol.DOORTRYOPEN); - this.unk1 = 0; - this.doorID = doorID; - this.buildingUUID = targetID; - this.playerUUID = senderID; - this.toggle = toggle; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public DoorTryOpenMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.DOORTRYOPEN, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - if (this.unk1 == 2) { - writer.putInt(2); - for (int i=0;i<6;i++) - writer.putInt(0); - writer.put((byte)0); - } else { - writer.putInt(0); //0 or 2. If 2 all other variables are 0 - writer.putInt(0); - writer.putInt(doorID); - writer.putInt(GameObjectType.Building.ordinal()); - writer.putInt(buildingUUID); - writer.putInt(GameObjectType.PlayerCharacter.ordinal()); - writer.putInt(playerUUID); - writer.put(toggle); - } - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.unk1 = reader.getInt(); - reader.getInt(); - this.doorID = reader.getInt(); - reader.getInt(); // type padding - this.buildingUUID = reader.getInt(); - reader.getInt(); // type padding - this.playerUUID = reader.getInt(); - this.toggle = reader.get(); - } - - /** - * @return the unknown1 - */ - public int getDoorID() { - return doorID; - } - - /** - * @return the buildingUUID - */ - public int getBuildingUUID() { - return buildingUUID; - } - - /** - * @return the playerUUID - */ - public int playerUUID() { - return playerUUID; - } - - /** - * @return the toggle - */ - public byte getToggle() { - return toggle; - } - - public int getUnk1() { - return this.unk1; - } - - public void setUnk1(int value) { - this.unk1 = value; - } + private int unk1; + private int doorID; + private int buildingUUID; + private int playerUUID; + private byte toggle; + + /** + * This is the general purpose constructor. + */ + public DoorTryOpenMsg(int doorID, int targetID, int senderID, byte toggle) { + super(Protocol.DOORTRYOPEN); + this.unk1 = 0; + this.doorID = doorID; + this.buildingUUID = targetID; + this.playerUUID = senderID; + this.toggle = toggle; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public DoorTryOpenMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.DOORTRYOPEN, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + if (this.unk1 == 2) { + writer.putInt(2); + for (int i = 0; i < 6; i++) + writer.putInt(0); + writer.put((byte) 0); + } else { + writer.putInt(0); //0 or 2. If 2 all other variables are 0 + writer.putInt(0); + writer.putInt(doorID); + writer.putInt(GameObjectType.Building.ordinal()); + writer.putInt(buildingUUID); + writer.putInt(GameObjectType.PlayerCharacter.ordinal()); + writer.putInt(playerUUID); + writer.put(toggle); + } + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.unk1 = reader.getInt(); + reader.getInt(); + this.doorID = reader.getInt(); + reader.getInt(); // type padding + this.buildingUUID = reader.getInt(); + reader.getInt(); // type padding + this.playerUUID = reader.getInt(); + this.toggle = reader.get(); + } + + /** + * @return the unknown1 + */ + public int getDoorID() { + return doorID; + } + + /** + * @return the buildingUUID + */ + public int getBuildingUUID() { + return buildingUUID; + } + + /** + * @return the playerUUID + */ + public int playerUUID() { + return playerUUID; + } + + /** + * @return the toggle + */ + public byte getToggle() { + return toggle; + } + + public int getUnk1() { + return this.unk1; + } + + public void setUnk1(int value) { + this.unk1 = value; + } } diff --git a/src/engine/net/client/msg/DropGoldMsg.java b/src/engine/net/client/msg/DropGoldMsg.java index f16b8c41..667916a5 100644 --- a/src/engine/net/client/msg/DropGoldMsg.java +++ b/src/engine/net/client/msg/DropGoldMsg.java @@ -17,130 +17,125 @@ import engine.net.client.Protocol; public class DropGoldMsg extends ClientNetMsg { - private int unknown01; - private int unknown02; - private int unknown03; - private short unknown04; - private byte unknown05; - - /** - * This is the general purpose constructor. - */ - public DropGoldMsg() { - super(Protocol.DROPGOLD); - this.unknown01 = 0x40A5BDB0; - this.unknown02 = 0x342AA9F0; - this.unknown03 = 0; - this.unknown04 = (short) 0; - this.unknown05 = (byte) 0; - - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public DropGoldMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.DROPGOLD, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - - reader.getInt(); - reader.get(); - - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the unknown02 - */ - public int getUnknown02() { - return unknown02; - } - - /** - * @param unknown02 - * the unknown02 to set - */ - public void setUnknown02(int unknown02) { - this.unknown02 = unknown02; - } - - /** - * @return the unknown03 - */ - public int getUnknown03() { - return unknown03; - } - - /** - * @param unknown03 - * the unknown03 to set - */ - public void setUnknown03(int unknown03) { - this.unknown03 = unknown03; - } - - /** - * @return the unknown04 - */ - public short getUnknown04() { - return unknown04; - } - - /** - * @param unknown04 - * the unknown04 to set - */ - public void setUnknown04(short unknown04) { - this.unknown04 = unknown04; - } - - /** - * @return the unknown05 - */ - public byte getUnknown05() { - return unknown05; - } - - /** - * @param unknown05 - * the unknown05 to set - */ - public void setUnknown05(byte unknown05) { - this.unknown05 = unknown05; - } + private int unknown01; + private int unknown02; + private int unknown03; + private short unknown04; + private byte unknown05; + + /** + * This is the general purpose constructor. + */ + public DropGoldMsg() { + super(Protocol.DROPGOLD); + this.unknown01 = 0x40A5BDB0; + this.unknown02 = 0x342AA9F0; + this.unknown03 = 0; + this.unknown04 = (short) 0; + this.unknown05 = (byte) 0; + + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public DropGoldMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.DROPGOLD, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + + reader.getInt(); + reader.get(); + + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the unknown02 + */ + public int getUnknown02() { + return unknown02; + } + + /** + * @param unknown02 the unknown02 to set + */ + public void setUnknown02(int unknown02) { + this.unknown02 = unknown02; + } + + /** + * @return the unknown03 + */ + public int getUnknown03() { + return unknown03; + } + + /** + * @param unknown03 the unknown03 to set + */ + public void setUnknown03(int unknown03) { + this.unknown03 = unknown03; + } + + /** + * @return the unknown04 + */ + public short getUnknown04() { + return unknown04; + } + + /** + * @param unknown04 the unknown04 to set + */ + public void setUnknown04(short unknown04) { + this.unknown04 = unknown04; + } + + /** + * @return the unknown05 + */ + public byte getUnknown05() { + return unknown05; + } + + /** + * @param unknown05 the unknown05 to set + */ + public void setUnknown05(byte unknown05) { + this.unknown05 = unknown05; + } } diff --git a/src/engine/net/client/msg/EnterWorldReceivedMsg.java b/src/engine/net/client/msg/EnterWorldReceivedMsg.java index 2845378c..b300a16a 100644 --- a/src/engine/net/client/msg/EnterWorldReceivedMsg.java +++ b/src/engine/net/client/msg/EnterWorldReceivedMsg.java @@ -18,41 +18,41 @@ import engine.net.client.Protocol; public class EnterWorldReceivedMsg extends ClientNetMsg { - /** - * This is the general purpose constructor. - */ - public EnterWorldReceivedMsg() { - super(Protocol.READYTOENTER); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public EnterWorldReceivedMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.READYTOENTER, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - return; - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - return; - } - - @Override - protected int getPowerOfTwoBufferSize() { - return 18; //65536 bytes for enter world. - } + /** + * This is the general purpose constructor. + */ + public EnterWorldReceivedMsg() { + super(Protocol.READYTOENTER); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public EnterWorldReceivedMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.READYTOENTER, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + return; + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + return; + } + + @Override + protected int getPowerOfTwoBufferSize() { + return 18; //65536 bytes for enter world. + } } diff --git a/src/engine/net/client/msg/ErrorPopupMsg.java b/src/engine/net/client/msg/ErrorPopupMsg.java index f9bac8f8..e56a2536 100644 --- a/src/engine/net/client/msg/ErrorPopupMsg.java +++ b/src/engine/net/client/msg/ErrorPopupMsg.java @@ -16,301 +16,300 @@ import engine.objects.PlayerCharacter; public class ErrorPopupMsg extends ClientNetMsg { - //1: Sorry, but that individual is not a banker - //2: Sorry, but you must be closer to the banker to access your account - //3: Sorry, but you have insufficient funds to access your acount - //4: The shop is closed - //5: You must come closer to shop - //6: You do not have enough money to purchase that - //7: You cannot carry that item - //8: The banker cannot carry that item - //9: You do not have that much gold to drop - //10: That item cannot be dropped - //11: You cannot drop what you do not have - //12: Sorry, but this container is locked - //13: Sorry, but this container is barred - //14: You must come closer to me - //15: You no longer have that item to sell - //16: I won't buy that kind of item - //17: I cannot afford that item - //18: You can't really afford that - //19: This item is gone from inventory - //20: Your resurection has been declined - //21: I cannot carry that weight - //22: You just dropped that item on the ground - //23: This corpse has no experience to return - //24: This player is not in world - //25: This player is not online - //26: You selected an invalid location - //27: You are dead. Try again when you are not so...well, dead - //28: Your target is dead and cannot be summoned - //29: Your summons has been declined - //30: That person cannot carry that item - //31: An unexpected error has occurred and the trade is being canceled - //32: You must choose a promotion class before gaining your next level. Speak to a class trainer - //33: Promotion failed - //34: Come back when you've gained more experience - //35: This hireling failed to buy the item - //36: I don't buy items - //37: I don't sell items - //38: You appear to be in a building normally - //39: There does not appear to be a building where you are - //40: I don't swear guilds - //41: I server no sovereign - //42: Your guild is not errant - //43: Members of your guild are too high in level - //44: You cannot afford this service - //45: Failure to swear guild - //46: Cannot swear under ruins - //47: Your guild is the wrong type to swear to this guild - //48: Hireling could not hire - //49: I do not hire - //50: This pet is gone - //51: You have successfully promoted to a new class - //52: You have successfully added a new discipline - //53: You no longer meet the level requirement to stay in this guild - //54: That item is too advanced - //55: All production slots are taken - //56: That enchantment is too advanced - //57: That formula is too advanced - //58: The formula is beyond the means of this facility - //59: This hireling does not have this formula - //60: Hireling does not possess that item! - //61: Hireling does not work with such items - //62: You may only trade with items in your inventory - //63: You must be within your building to do that - //64: You are too far from the building to do that - //65: I cannot enthrall creatures - //66: I cannot repledge you - //67: I cannot teleport you - //68: You have no valid thralls - //69: You have a thrall that I do not understand - //70: I cannot afford your thrall - //71: There are no cities to which you can repledge - //72: There are no cities to which you can teleport - //73: You are too low level to repledge - //74: You are too low level to teleport - //75: You must leave your current guild before you can repledge - //76: Failure to repledge - //77: Failure to teleport - //78: You do not meet the qualifications to join that city - //79: There are too many furniture items in this asset - //80: Attempting to add furniture to bad location - //81: This deed codes for a bad furniture prop - //82: Object is not an appropriate furniture deed - //83: Unable to find corresponding furniture on asset - //84: The chose game world is not valid <- will kick out of world - //85: The game world is temporarily unavailable <- will kick out of world - //86: The runegate is unnaffected by this power - //87: You are not powerful enough to activate this gate - //88: This runegate is already on - //89: You cannot unbanish this one until the timestamp expires - //90: You cannot trade while either you or the target is invisible - //91: You cannot trade while in combat mode - //92: That person is already engaged in a trade - //93: You must be closer to trade - //94: The trade was successful - //95: The trade was not successful - //96: The trade has failed because one of you would exceed your gold limit - //97: You must be closer to open that - //98: You cannot loot while flying - //99: Your target is not dead - //100: You cannot loot a trainer - //101: You cannot loot a shopkeeper - //102: You cannot loot a banker - //103: You cannot add this individual to the condemn list - //104: You cannot add the owner's guild to the condemn list - //105: You cannot add the owner's nation to the condemn list - //106: Failure to add to the condemn list - //107: Unable to find desired group - //108: Group is at maximum membership - //109: Failed to add item to hireling - //110: Failer to remove item from hireling - //111: This item cannot be removed from inventory - //112: Your account has no characters - //113: Failure to start support - //114: Cannot add another support - //115: This type of asset cannot receive protection - //116: This asset already has protection upon it - //117: Failure to remove support - //118: Failure to complete support - //119: Failure to reject support - //120: This asset is not a banecircle - //121: You are not a CSR who can advance banecircle stage - //122: Failure to advance banecircle stage - //123: You do not have the authority within your guild to modify this banecircle - //124: Banecircle cannot advance once in final stage - //125: Failure to repair Asset - //126: Asset does not require repair - //127: No gold in asset strongbox - //128: Insufficient funds for even one point of repair - //129: You cannot bond where you are killed-on-sight - //130: You cannot join where you are killed-on-sight - //131: You do not meet the level required for this SWORN guild - //132: You are already a member of this guild - //133: Your banishment from this guild has not yet been lifted - //134: Your QUIT status from this guild has not yet expired - //135: Character is considered BANISHED by guild leadership - //136: Your class is not allowed to teleport here - //137: You have no affiliation with this tree - //138: You can never join this type of tree - //139: You do not meet the safehold level requirement - //140: Ruined trees are invalid - //141: Unclaimed trees are invalid - //142: You are the wrong race for this city - //143: You are the wrong class for this city - //144: You are the wrong sex for this city - //145: You are too low level for this city - //146: You do not meet the level requirements for this city - //147: Tree must be rank 5 to open city - //148: Unable to find a matching petition to complete guild creation - //149: Guild name fails profanity check - //150: Guild motto fails profanity check - //151: Guild name is not unique - //152: Guild crest is not unique - //153: Guild crest is reserved - //154: All three crest colors cannot be the same - //155: Please choose another name - //156: You cannot bank and trade at the same time - //157: You must not move or engage in combat for 10 seconds before stuck will work - //158: Your gold has been dropped on the ground - //159: Merchant cannot purchase item without exceeding his reserve - //160: Rune succesfully applied - //161: You cannot apply that rune - //162: You rely too heavily on that rune to remove it - //163: This shrine does not take offerings of that type - //164: This hireling cannot grant boons - //165: This hireling cannot display the leaderboard - //166: There is no more favor in this shrine to loot - //167: There are no more resources in this warehouse to loot - //168: This boon is only for guild members belonging to this shrine - //169: You do not meet the race/class requirements for this boon - //170: This shrine is no longer capable of granting boons - //171: This asset cannot be destroyed during times of war - //172: This shrine has no favor - //173: You must be the leader of a guild to receive a blessing - //174: This siege spire cannot be toggled yet. Please try again later - //175: You cannot teleport into that zone at the moment - //176: Only guild leaders can claim a territory - //177: Your nation has already reached the maximum number of capitals - //178: This territory is already claimed - //179: Only landed guilds may claim a territory - //180: This territory cannot be ruled by anyone - //181: Your tree must be rank 7 before claiming a territory - //182: This realm is in turmoil and cannot be claimed yet - //183: You cannot rule a guild under a different faction then your parent guild - //184: Insufficient gold or resources to upgrade to capital - //185: You must seek the blessing of the three sages before you can rule - //186: Your tree is not inside a territory! - //187: This realm is in turmoil and cannot yet be claimed! - //188: You must have a warehouse to become a capital - //189: You are not the owner of this building - //190: This building cannot be upgraded further - //191: You don't have the required funds - //192: This building is already upgrading - //193: Production denied: This building must be protected to gain access to warehouse resources.. - //194: The operation failed because you reached your gold limit - //195: That player is currently busy completing the last trade. Try again in a few moments - //196: You are currently busy completing the last trade. Try again in a few moments - //197: You cannot join a guild whose nation has a guild that is currently involved in a siege - //198: You cannot repledge while you are involved in a siege - //199: You already have this boon - //200: Your vault cannot contain that item - //201: You can't put that much gold there - //202: You can't carry that much gold - //203: You don't have that much gold to transfer - //204: That item is not in the vault - //205: That item is not in the inventory - //206: This building can hold no more gold - private int message; - private String custom = ""; + //1: Sorry, but that individual is not a banker + //2: Sorry, but you must be closer to the banker to access your account + //3: Sorry, but you have insufficient funds to access your acount + //4: The shop is closed + //5: You must come closer to shop + //6: You do not have enough money to purchase that + //7: You cannot carry that item + //8: The banker cannot carry that item + //9: You do not have that much gold to drop + //10: That item cannot be dropped + //11: You cannot drop what you do not have + //12: Sorry, but this container is locked + //13: Sorry, but this container is barred + //14: You must come closer to me + //15: You no longer have that item to sell + //16: I won't buy that kind of item + //17: I cannot afford that item + //18: You can't really afford that + //19: This item is gone from inventory + //20: Your resurection has been declined + //21: I cannot carry that weight + //22: You just dropped that item on the ground + //23: This corpse has no experience to return + //24: This player is not in world + //25: This player is not online + //26: You selected an invalid location + //27: You are dead. Try again when you are not so...well, dead + //28: Your target is dead and cannot be summoned + //29: Your summons has been declined + //30: That person cannot carry that item + //31: An unexpected error has occurred and the trade is being canceled + //32: You must choose a promotion class before gaining your next level. Speak to a class trainer + //33: Promotion failed + //34: Come back when you've gained more experience + //35: This hireling failed to buy the item + //36: I don't buy items + //37: I don't sell items + //38: You appear to be in a building normally + //39: There does not appear to be a building where you are + //40: I don't swear guilds + //41: I server no sovereign + //42: Your guild is not errant + //43: Members of your guild are too high in level + //44: You cannot afford this service + //45: Failure to swear guild + //46: Cannot swear under ruins + //47: Your guild is the wrong type to swear to this guild + //48: Hireling could not hire + //49: I do not hire + //50: This pet is gone + //51: You have successfully promoted to a new class + //52: You have successfully added a new discipline + //53: You no longer meet the level requirement to stay in this guild + //54: That item is too advanced + //55: All production slots are taken + //56: That enchantment is too advanced + //57: That formula is too advanced + //58: The formula is beyond the means of this facility + //59: This hireling does not have this formula + //60: Hireling does not possess that item! + //61: Hireling does not work with such items + //62: You may only trade with items in your inventory + //63: You must be within your building to do that + //64: You are too far from the building to do that + //65: I cannot enthrall creatures + //66: I cannot repledge you + //67: I cannot teleport you + //68: You have no valid thralls + //69: You have a thrall that I do not understand + //70: I cannot afford your thrall + //71: There are no cities to which you can repledge + //72: There are no cities to which you can teleport + //73: You are too low level to repledge + //74: You are too low level to teleport + //75: You must leave your current guild before you can repledge + //76: Failure to repledge + //77: Failure to teleport + //78: You do not meet the qualifications to join that city + //79: There are too many furniture items in this asset + //80: Attempting to add furniture to bad location + //81: This deed codes for a bad furniture prop + //82: Object is not an appropriate furniture deed + //83: Unable to find corresponding furniture on asset + //84: The chose game world is not valid <- will kick out of world + //85: The game world is temporarily unavailable <- will kick out of world + //86: The runegate is unnaffected by this power + //87: You are not powerful enough to activate this gate + //88: This runegate is already on + //89: You cannot unbanish this one until the timestamp expires + //90: You cannot trade while either you or the target is invisible + //91: You cannot trade while in combat mode + //92: That person is already engaged in a trade + //93: You must be closer to trade + //94: The trade was successful + //95: The trade was not successful + //96: The trade has failed because one of you would exceed your gold limit + //97: You must be closer to open that + //98: You cannot loot while flying + //99: Your target is not dead + //100: You cannot loot a trainer + //101: You cannot loot a shopkeeper + //102: You cannot loot a banker + //103: You cannot add this individual to the condemn list + //104: You cannot add the owner's guild to the condemn list + //105: You cannot add the owner's nation to the condemn list + //106: Failure to add to the condemn list + //107: Unable to find desired group + //108: Group is at maximum membership + //109: Failed to add item to hireling + //110: Failer to remove item from hireling + //111: This item cannot be removed from inventory + //112: Your account has no characters + //113: Failure to start support + //114: Cannot add another support + //115: This type of asset cannot receive protection + //116: This asset already has protection upon it + //117: Failure to remove support + //118: Failure to complete support + //119: Failure to reject support + //120: This asset is not a banecircle + //121: You are not a CSR who can advance banecircle stage + //122: Failure to advance banecircle stage + //123: You do not have the authority within your guild to modify this banecircle + //124: Banecircle cannot advance once in final stage + //125: Failure to repair Asset + //126: Asset does not require repair + //127: No gold in asset strongbox + //128: Insufficient funds for even one point of repair + //129: You cannot bond where you are killed-on-sight + //130: You cannot join where you are killed-on-sight + //131: You do not meet the level required for this SWORN guild + //132: You are already a member of this guild + //133: Your banishment from this guild has not yet been lifted + //134: Your QUIT status from this guild has not yet expired + //135: Character is considered BANISHED by guild leadership + //136: Your class is not allowed to teleport here + //137: You have no affiliation with this tree + //138: You can never join this type of tree + //139: You do not meet the safehold level requirement + //140: Ruined trees are invalid + //141: Unclaimed trees are invalid + //142: You are the wrong race for this city + //143: You are the wrong class for this city + //144: You are the wrong sex for this city + //145: You are too low level for this city + //146: You do not meet the level requirements for this city + //147: Tree must be rank 5 to open city + //148: Unable to find a matching petition to complete guild creation + //149: Guild name fails profanity check + //150: Guild motto fails profanity check + //151: Guild name is not unique + //152: Guild crest is not unique + //153: Guild crest is reserved + //154: All three crest colors cannot be the same + //155: Please choose another name + //156: You cannot bank and trade at the same time + //157: You must not move or engage in combat for 10 seconds before stuck will work + //158: Your gold has been dropped on the ground + //159: Merchant cannot purchase item without exceeding his reserve + //160: Rune succesfully applied + //161: You cannot apply that rune + //162: You rely too heavily on that rune to remove it + //163: This shrine does not take offerings of that type + //164: This hireling cannot grant boons + //165: This hireling cannot display the leaderboard + //166: There is no more favor in this shrine to loot + //167: There are no more resources in this warehouse to loot + //168: This boon is only for guild members belonging to this shrine + //169: You do not meet the race/class requirements for this boon + //170: This shrine is no longer capable of granting boons + //171: This asset cannot be destroyed during times of war + //172: This shrine has no favor + //173: You must be the leader of a guild to receive a blessing + //174: This siege spire cannot be toggled yet. Please try again later + //175: You cannot teleport into that zone at the moment + //176: Only guild leaders can claim a territory + //177: Your nation has already reached the maximum number of capitals + //178: This territory is already claimed + //179: Only landed guilds may claim a territory + //180: This territory cannot be ruled by anyone + //181: Your tree must be rank 7 before claiming a territory + //182: This realm is in turmoil and cannot be claimed yet + //183: You cannot rule a guild under a different faction then your parent guild + //184: Insufficient gold or resources to upgrade to capital + //185: You must seek the blessing of the three sages before you can rule + //186: Your tree is not inside a territory! + //187: This realm is in turmoil and cannot yet be claimed! + //188: You must have a warehouse to become a capital + //189: You are not the owner of this building + //190: This building cannot be upgraded further + //191: You don't have the required funds + //192: This building is already upgrading + //193: Production denied: This building must be protected to gain access to warehouse resources.. + //194: The operation failed because you reached your gold limit + //195: That player is currently busy completing the last trade. Try again in a few moments + //196: You are currently busy completing the last trade. Try again in a few moments + //197: You cannot join a guild whose nation has a guild that is currently involved in a siege + //198: You cannot repledge while you are involved in a siege + //199: You already have this boon + //200: Your vault cannot contain that item + //201: You can't put that much gold there + //202: You can't carry that much gold + //203: You don't have that much gold to transfer + //204: That item is not in the vault + //205: That item is not in the inventory + //206: This building can hold no more gold + private int message; + private String custom = ""; - /** - * This is the general purpose constructor. - */ - public ErrorPopupMsg(int message) { - super(Protocol.STANDARDALERT); - this.message = message; - } + /** + * This is the general purpose constructor. + */ + public ErrorPopupMsg(int message) { + super(Protocol.STANDARDALERT); + this.message = message; + } - public ErrorPopupMsg(int message, String custom) { - super(Protocol.STANDARDALERT); - this.message = message; - this.custom = custom; - } + public ErrorPopupMsg(int message, String custom) { + super(Protocol.STANDARDALERT); + this.message = message; + this.custom = custom; + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ErrorPopupMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.STANDARDALERT, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ErrorPopupMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.STANDARDALERT, origin, reader); + } - /** - * Copy constructor - */ - public ErrorPopupMsg(ErrorPopupMsg msg) { - super(Protocol.STANDARDALERT); - this.message = msg.message; - } + /** + * Copy constructor + */ + public ErrorPopupMsg(ErrorPopupMsg msg) { + super(Protocol.STANDARDALERT); + this.message = msg.message; + } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.message = reader.getInt(); - reader.getInt(); - reader.getInt(); - } + /** + * @return unknown01 + */ - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.message); - writer.putString(this.custom); - writer.putInt(0); - } + // Popup Window with no title and arbitrary text. + // Find an Enum for generic ERROR or way to set perhaps? + public static void sendErrorMsg(PlayerCharacter player, String errorMessage) { - /** - * @return unknown01 - */ + if (player == null) + return; - // Popup Window with no title and arbitrary text. - // Find an Enum for generic ERROR or way to set perhaps? - public static void sendErrorMsg(PlayerCharacter player, String errorMessage) { + ErrorPopupMsg popupMessage; + Dispatch errorDispatch; - if (player == null) - return; + popupMessage = new ErrorPopupMsg(300, errorMessage); + errorDispatch = Dispatch.borrow(player, popupMessage); + DispatchMessage.dispatchMsgDispatch(errorDispatch, Enum.DispatchChannel.SECONDARY); - ErrorPopupMsg popupMessage; - Dispatch errorDispatch; + } - popupMessage = new ErrorPopupMsg(300, errorMessage); + public static void sendErrorPopup(PlayerCharacter player, int popupID) { - errorDispatch = Dispatch.borrow(player, popupMessage); - DispatchMessage.dispatchMsgDispatch(errorDispatch, Enum.DispatchChannel.SECONDARY); + ErrorPopupMsg errorPopup; + Dispatch errorDispatch; - } + if (player == null) + return; - public static void sendErrorPopup(PlayerCharacter player, int popupID) { + errorPopup = new ErrorPopupMsg(popupID); - ErrorPopupMsg errorPopup; - Dispatch errorDispatch; + errorDispatch = Dispatch.borrow(player, errorPopup); + DispatchMessage.dispatchMsgDispatch(errorDispatch, Enum.DispatchChannel.SECONDARY); + } - if (player == null) - return; + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.message = reader.getInt(); + reader.getInt(); + reader.getInt(); + } - errorPopup = new ErrorPopupMsg(popupID); - - errorDispatch = Dispatch.borrow(player, errorPopup); - DispatchMessage.dispatchMsgDispatch(errorDispatch, Enum.DispatchChannel.SECONDARY); - } + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.message); + writer.putString(this.custom); + writer.putInt(0); + } } diff --git a/src/engine/net/client/msg/FriendRequestMsg.java b/src/engine/net/client/msg/FriendRequestMsg.java index 6c2c1a2f..ad735157 100644 --- a/src/engine/net/client/msg/FriendRequestMsg.java +++ b/src/engine/net/client/msg/FriendRequestMsg.java @@ -15,51 +15,50 @@ import engine.objects.PlayerCharacter; public class FriendRequestMsg extends ClientNetMsg { - public String sourceName; - public String friendName; + public String sourceName; + public String friendName; - /** - * This is the general purpose constructor. - */ - public FriendRequestMsg(PlayerCharacter pc) { - super(Protocol.PLAYERFRIENDS); - } + /** + * This is the general purpose constructor. + */ + public FriendRequestMsg(PlayerCharacter pc) { + super(Protocol.PLAYERFRIENDS); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public FriendRequestMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.PLAYERFRIENDS, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public FriendRequestMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.PLAYERFRIENDS, origin, reader); + } - /** - * Copy constructor - */ - public FriendRequestMsg(FriendRequestMsg msg) { - super(Protocol.PLAYERFRIENDS); - } + /** + * Copy constructor + */ + public FriendRequestMsg(FriendRequestMsg msg) { + super(Protocol.PLAYERFRIENDS); + } - - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - //Do we even want to try this? - this.sourceName = reader.getString(); //This is source name.. this friends list must never been updated since launch, not using IDS. - this.friendName = reader.getString(); - } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putString(this.sourceName); - writer.putString(this.friendName); - } + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + //Do we even want to try this? + this.sourceName = reader.getString(); //This is source name.. this friends list must never been updated since launch, not using IDS. + this.friendName = reader.getString(); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putString(this.sourceName); + writer.putString(this.friendName); + } } diff --git a/src/engine/net/client/msg/FurnitureMsg.java b/src/engine/net/client/msg/FurnitureMsg.java index e496e75b..b68e42b0 100644 --- a/src/engine/net/client/msg/FurnitureMsg.java +++ b/src/engine/net/client/msg/FurnitureMsg.java @@ -20,130 +20,127 @@ import engine.net.client.Protocol; public class FurnitureMsg extends ClientNetMsg { - private int type; - private int buildingID; - private int size; - private int pad = 0; - private int itemID; - private Vector3fImmutable furnitureLoc; - private int floor; - private float rot; - private float w; - - - - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public FurnitureMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.FURNITURE, origin, reader); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.type = reader.getInt(); - reader.getInt(); - this.buildingID = reader.getInt(); - if (this.type == 3){ - reader.getInt(); - reader.getInt(); - reader.getInt(); + private int type; + private int buildingID; + private int size; + private int pad = 0; + private int itemID; + private Vector3fImmutable furnitureLoc; + private int floor; + private float rot; + private float w; + + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public FurnitureMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.FURNITURE, origin, reader); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.type = reader.getInt(); + reader.getInt(); + this.buildingID = reader.getInt(); + if (this.type == 3) { + reader.getInt(); + reader.getInt(); + reader.getInt(); this.itemID = reader.getInt(); this.furnitureLoc = reader.getVector3fImmutable(); reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - return; - - - } - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - - - } - - @Override - protected int getPowerOfTwoBufferSize() { - // Larger size for historically larger opcodes - return (15); - } - - - // Precache and configure this message before we serialize it - - public void configure() { - - - - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - if (this.type == 3 || this.type == 4){ - writer.putInt(this.type); - writer.putInt(GameObjectType.Building.ordinal()); - writer.putInt(this.buildingID); - writer.putInt(0); - writer.putInt(0); - writer.putInt(GameObjectType.Item.ordinal()); - writer.putInt(62280); - writer.putVector3f(this.furnitureLoc); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - return; - } - - - writer.putInt(2); //Type - writer.putInt(GameObjectType.Building.ordinal()); - writer.putInt(this.buildingID); - writer.putInt(GameObjectType.Building.ordinal()); - writer.putInt(this.buildingID); - writer.put((byte)1); - writer.putInt(1); - writer.putInt(GameObjectType.Item.ordinal()); - writer.putInt(62280); - writer.putInt(0); - - writer.putInt(1); - - writer.putInt(0); - writer.putInt(362003); - writer.putInt(GameObjectType.Item.ordinal()); - writer.putInt(62280); - - writer.putInt(GameObjectType.Building.ordinal()); - writer.putInt(this.buildingID); - - writer.putInt(0); - writer.putInt(0); - - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - - writer.put((byte)0); - - // writer.putInt(0); - //writer.putInt(0); - + reader.getInt(); + reader.getInt(); + reader.getInt(); + return; + + + } + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + + + } + + @Override + protected int getPowerOfTwoBufferSize() { + // Larger size for historically larger opcodes + return (15); + } + + + // Precache and configure this message before we serialize it + + public void configure() { + + + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + if (this.type == 3 || this.type == 4) { + writer.putInt(this.type); + writer.putInt(GameObjectType.Building.ordinal()); + writer.putInt(this.buildingID); + writer.putInt(0); + writer.putInt(0); + writer.putInt(GameObjectType.Item.ordinal()); + writer.putInt(62280); + writer.putVector3f(this.furnitureLoc); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + return; + } + + + writer.putInt(2); //Type + writer.putInt(GameObjectType.Building.ordinal()); + writer.putInt(this.buildingID); + writer.putInt(GameObjectType.Building.ordinal()); + writer.putInt(this.buildingID); + writer.put((byte) 1); + writer.putInt(1); + writer.putInt(GameObjectType.Item.ordinal()); + writer.putInt(62280); + writer.putInt(0); + + writer.putInt(1); + + writer.putInt(0); + writer.putInt(362003); + writer.putInt(GameObjectType.Item.ordinal()); + writer.putInt(62280); + + writer.putInt(GameObjectType.Building.ordinal()); + writer.putInt(this.buildingID); + + writer.putInt(0); + writer.putInt(0); + + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + + writer.put((byte) 0); + + // writer.putInt(0); + //writer.putInt(0); + // writer.putInt(1); // writer.putInt(GameObjectType.Building.ordinal()); // writer.putInt(62281); @@ -173,122 +170,120 @@ public class FurnitureMsg extends ClientNetMsg { // writer.putInt(0); // writer.put((byte)0); - - - - // else{ - // writer.putInt(building.getFurnitureList().size()); - // for (int furnitureID: building.getFurnitureList()){ - // Building furniture = Building.getBuildingFromCache(furnitureID); - // writer.putInt(GameObjectType.Building.ordinal()); - // writer.putInt(furniture.getObjectUUID()); - // 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.put((byte)0); - // } - - //} - - // else{ - // writer.putInt(building.getFurnitureList().size()); - // for (int furnitureID: building.getFurnitureList()){ - // Building furniture = Building.getBuildingFromCache(furnitureID); - // writer.putInt(GameObjectType.Building.ordinal()); - // writer.putInt(furniture.getObjectUUID()); - // 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.put((byte)0); - // } - // - // } - } - - public int getPad() { - return pad; - } - - public void setPad(int value) { - this.pad = value; - } - - public int getType() { - return type; - } - - public void setType(int type) { - this.type = type; - } - - public int getSize() { - return size; - } - - public void setSize(int size) { - this.size = size; - } - - public int getBuildingID() { - return buildingID; - } - - public void setBuildingID(int buildingID) { - this.buildingID = buildingID; - } - - public int getItemID() { - return itemID; - } - - public void setItemID(int itemID) { - this.itemID = itemID; - } - - public Vector3fImmutable getFurnitureLoc() { - return furnitureLoc; - } - - public void setFurnitureLoc(Vector3fImmutable furnitureLoc) { - this.furnitureLoc = furnitureLoc; - } - - public int getFloor() { - return floor; - } - - public void setFloor(int floor) { - this.floor = floor; - } - - public float getRot() { - return rot; - } - - public void setRot(float rot) { - this.rot = rot; - } - - public float getw() { - return w; - } - - public void setw(float w) { - this.w = w; - } + + // else{ + // writer.putInt(building.getFurnitureList().size()); + // for (int furnitureID: building.getFurnitureList()){ + // Building furniture = Building.getBuildingFromCache(furnitureID); + // writer.putInt(GameObjectType.Building.ordinal()); + // writer.putInt(furniture.getObjectUUID()); + // 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.put((byte)0); + // } + + //} + + // else{ + // writer.putInt(building.getFurnitureList().size()); + // for (int furnitureID: building.getFurnitureList()){ + // Building furniture = Building.getBuildingFromCache(furnitureID); + // writer.putInt(GameObjectType.Building.ordinal()); + // writer.putInt(furniture.getObjectUUID()); + // 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.put((byte)0); + // } + // + // } + } + + public int getPad() { + return pad; + } + + public void setPad(int value) { + this.pad = value; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + public int getBuildingID() { + return buildingID; + } + + public void setBuildingID(int buildingID) { + this.buildingID = buildingID; + } + + public int getItemID() { + return itemID; + } + + public void setItemID(int itemID) { + this.itemID = itemID; + } + + public Vector3fImmutable getFurnitureLoc() { + return furnitureLoc; + } + + public void setFurnitureLoc(Vector3fImmutable furnitureLoc) { + this.furnitureLoc = furnitureLoc; + } + + public int getFloor() { + return floor; + } + + public void setFloor(int floor) { + this.floor = floor; + } + + public float getRot() { + return rot; + } + + public void setRot(float rot) { + this.rot = rot; + } + + public float getw() { + return w; + } + + public void setw(float w) { + this.w = w; + } } diff --git a/src/engine/net/client/msg/GrantExperienceMsg.java b/src/engine/net/client/msg/GrantExperienceMsg.java index d9799a37..cdff6397 100644 --- a/src/engine/net/client/msg/GrantExperienceMsg.java +++ b/src/engine/net/client/msg/GrantExperienceMsg.java @@ -38,7 +38,7 @@ public class GrantExperienceMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public GrantExperienceMsg(AbstractConnection origin, ByteBufferReader reader) { + public GrantExperienceMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.EXPERIENCE, origin, reader); } @@ -57,7 +57,7 @@ public class GrantExperienceMsg extends ClientNetMsg { * ByteBufferReader. */ @Override - protected void _deserialize(ByteBufferReader reader) { + protected void _deserialize(ByteBufferReader reader) { reader.get(); this.xpGranted = reader.getInt(); this.objectType = reader.getInt(); @@ -78,22 +78,22 @@ public class GrantExperienceMsg extends ClientNetMsg { return this.xpGranted; } - public int getObjectType() { - return this.objectType; - } - - public int getObjectID() { - return this.objectID; - } - public void setXPGranted(int value) { this.xpGranted = value; } + public int getObjectType() { + return this.objectType; + } + public void setObjectType(int value) { this.objectType = value; } + public int getObjectID() { + return this.objectID; + } + public void setObjectID(int value) { this.objectID = value; } diff --git a/src/engine/net/client/msg/GuildTreeStatusMsg.java b/src/engine/net/client/msg/GuildTreeStatusMsg.java index 389d0711..f9c662d7 100644 --- a/src/engine/net/client/msg/GuildTreeStatusMsg.java +++ b/src/engine/net/client/msg/GuildTreeStatusMsg.java @@ -66,8 +66,7 @@ public class GuildTreeStatusMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public GuildTreeStatusMsg(AbstractConnection origin, ByteBufferReader reader) - { + public GuildTreeStatusMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.GUILDTREESTATUS, origin, reader); } @@ -75,8 +74,7 @@ public class GuildTreeStatusMsg extends ClientNetMsg { * Deserializes the subclass specific items to the supplied NetMsgWriter. */ @Override - protected void _deserialize(ByteBufferReader reader) - { + protected void _deserialize(ByteBufferReader reader) { targetType = reader.getInt(); targetID = reader.getInt(); @@ -99,7 +97,7 @@ public class GuildTreeStatusMsg extends ClientNetMsg { canAccess = this.canModify(); canBind = 0; - + if (player.getGuild() != null && this.treeOfLife.getGuild() != null && !this.treeOfLife.getGuild().isEmptyGuild() && player.getGuild().getNation() == this.treeOfLife.getGuild().getNation()) canBind = 1; @@ -110,20 +108,20 @@ public class GuildTreeStatusMsg extends ClientNetMsg { //accessType not 9 not null city if (accessType != 9) - if (this.treeOfLife.getGuild().getOwnedCity().isForceRename() && canAccess ) + if (this.treeOfLife.getGuild().getOwnedCity().isForceRename() && canAccess) accessType = 10; - else accessType = 8; + else + accessType = 8; cityZone = this.treeOfLife.getParentZone(); city = null; if (cityZone != null) - if (cityZone.isPlayerCity()) - city = City.GetCityFromCache(cityZone.getPlayerCityUUID()); - else - if (this.treeOfLife != null && this.treeOfLife.getGuild() != null) - city = this.treeOfLife.getGuild().getOwnedCity(); - + if (cityZone.isPlayerCity()) + city = City.GetCityFromCache(cityZone.getPlayerCityUUID()); + else if (this.treeOfLife != null && this.treeOfLife.getGuild() != null) + city = this.treeOfLife.getGuild().getOwnedCity(); + if (city == null) CityName = "None"; @@ -153,12 +151,12 @@ public class GuildTreeStatusMsg extends ClientNetMsg { if (canAccess) writer.putInt(accessType); - + else writer.putInt(9); - GuildTag._serializeForDisplay(cityGuildTag,writer); - GuildTag._serializeForDisplay(cityNationTag,writer); + GuildTag._serializeForDisplay(cityGuildTag, writer); + GuildTag._serializeForDisplay(cityNationTag, writer); writer.putString(CityName); writer.putString(GuildName); @@ -168,9 +166,9 @@ public class GuildTreeStatusMsg extends ClientNetMsg { writer.putInt(0); writer.putInt(0); if (city == null) - writer.putInt(0); + writer.putInt(0); else - writer.putInt(city.isOpen() ? 1 : 0); //check mark for open city + writer.putInt(city.isOpen() ? 1 : 0); //check mark for open city writer.putInt(0); writer.putInt(0); writer.put(canBind); diff --git a/src/engine/net/client/msg/HirelingServiceMsg.java b/src/engine/net/client/msg/HirelingServiceMsg.java index f60636ef..38202702 100644 --- a/src/engine/net/client/msg/HirelingServiceMsg.java +++ b/src/engine/net/client/msg/HirelingServiceMsg.java @@ -20,12 +20,11 @@ import engine.net.client.Protocol; public class HirelingServiceMsg extends ClientNetMsg { - public int npcID; - public int buildingID; - public int messageType; - public int repairCost; - - public static final int SETREPAIRCOST = 2; + public static final int SETREPAIRCOST = 2; + public int npcID; + public int buildingID; + public int messageType; + public int repairCost; /** * This is the general purpose constructor. @@ -42,7 +41,7 @@ public class HirelingServiceMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public HirelingServiceMsg(AbstractConnection origin, ByteBufferReader reader) { + public HirelingServiceMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.HIRELINGSERVICE, origin, reader); } @@ -51,72 +50,72 @@ public class HirelingServiceMsg extends ClientNetMsg { */ @Override protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.messageType); - switch (this.messageType){ - case SETREPAIRCOST: - this.writeSetRepairCost(writer); - break; - } + writer.putInt(this.messageType); + switch (this.messageType) { + case SETREPAIRCOST: + this.writeSetRepairCost(writer); + break; + } } /** * Deserializes the subclass specific items from the supplied NetMsgReader. */ @Override - protected void _deserialize(ByteBufferReader reader) { - this.messageType = reader.getInt(); - - switch (this.messageType){ - case SETREPAIRCOST: - this.readSetRepairCost(reader); - break; - - } + protected void _deserialize(ByteBufferReader reader) { + this.messageType = reader.getInt(); + + switch (this.messageType) { + case SETREPAIRCOST: + this.readSetRepairCost(reader); + break; + + } } - - private void readSetRepairCost(ByteBufferReader reader){ - reader.getInt(); //building type; - this.buildingID = reader.getInt(); - reader.getInt(); - this.npcID = reader.getInt(); - reader.getInt(); - reader.getInt(); //3 - this.repairCost = reader.getInt(); - reader.getInt(); - reader.getInt(); - + + private void readSetRepairCost(ByteBufferReader reader) { + reader.getInt(); //building type; + this.buildingID = reader.getInt(); + reader.getInt(); + this.npcID = reader.getInt(); + reader.getInt(); + reader.getInt(); //3 + this.repairCost = reader.getInt(); + reader.getInt(); + reader.getInt(); + } - - private void writeSetRepairCost(ByteBufferWriter writer){ - writer.putInt(GameObjectType.Building.ordinal()); - writer.putInt(this.buildingID); - writer.putInt(GameObjectType.NPC.ordinal()); - writer.putInt(this.npcID); - writer.putInt(0); - writer.putInt(3); - writer.putInt(this.repairCost); - writer.putInt(0); - writer.putInt(0); + + private void writeSetRepairCost(ByteBufferWriter writer) { + writer.putInt(GameObjectType.Building.ordinal()); + writer.putInt(this.buildingID); + writer.putInt(GameObjectType.NPC.ordinal()); + writer.putInt(this.npcID); + writer.putInt(0); + writer.putInt(3); + writer.putInt(this.repairCost); + writer.putInt(0); + writer.putInt(0); } - - private void writeTest(ByteBufferWriter writer){ - writer.putInt(GameObjectType.Building.ordinal()); - writer.putInt(this.buildingID); - writer.putInt(GameObjectType.NPC.ordinal()); - writer.putInt(this.npcID); - writer.putInt(3); - writer.putInt(1); - writer.putInt(1); - writer.putInt(GameObjectType.Building.ordinal()); - writer.putInt(this.buildingID); - writer.putInt(GameObjectType.NPC.ordinal()); - writer.putInt(this.npcID); - writer.putInt(0); - writer.putInt(0); - writer.putInt(3); - writer.putInt(1); - - writer.putInt(0); - + + private void writeTest(ByteBufferWriter writer) { + writer.putInt(GameObjectType.Building.ordinal()); + writer.putInt(this.buildingID); + writer.putInt(GameObjectType.NPC.ordinal()); + writer.putInt(this.npcID); + writer.putInt(3); + writer.putInt(1); + writer.putInt(1); + writer.putInt(GameObjectType.Building.ordinal()); + writer.putInt(this.buildingID); + writer.putInt(GameObjectType.NPC.ordinal()); + writer.putInt(this.npcID); + writer.putInt(0); + writer.putInt(0); + writer.putInt(3); + writer.putInt(1); + + writer.putInt(0); + } } diff --git a/src/engine/net/client/msg/HotzoneChangeMsg.java b/src/engine/net/client/msg/HotzoneChangeMsg.java index 9fc1a665..b779e3ac 100644 --- a/src/engine/net/client/msg/HotzoneChangeMsg.java +++ b/src/engine/net/client/msg/HotzoneChangeMsg.java @@ -49,8 +49,7 @@ public class HotzoneChangeMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public HotzoneChangeMsg(AbstractConnection origin, ByteBufferReader reader) - { + public HotzoneChangeMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.ARCHOTZONECHANGE, origin, reader); } @@ -68,7 +67,7 @@ public class HotzoneChangeMsg extends ClientNetMsg { * Deserializes the subclass specific items from the supplied NetMsgReader. */ @Override - protected void _deserialize(ByteBufferReader reader) { + protected void _deserialize(ByteBufferReader reader) { this.zoneType = reader.getInt(); this.zoneID = reader.getInt(); reader.getInt(); @@ -78,14 +77,14 @@ public class HotzoneChangeMsg extends ClientNetMsg { return this.zoneType; } - public int getZoneID() { - return this.zoneID; - } - public void setZoneType(int value) { this.zoneType = value; } + public int getZoneID() { + return this.zoneID; + } + public void setZoneID(int value) { this.zoneID = value; } diff --git a/src/engine/net/client/msg/IgnoreListMsg.java b/src/engine/net/client/msg/IgnoreListMsg.java index c7f75a03..cbfb0991 100644 --- a/src/engine/net/client/msg/IgnoreListMsg.java +++ b/src/engine/net/client/msg/IgnoreListMsg.java @@ -37,7 +37,7 @@ public class IgnoreListMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public IgnoreListMsg(AbstractConnection origin, ByteBufferReader reader) { + public IgnoreListMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.ARCIGNORELISTUPDATE, origin, reader); } @@ -60,7 +60,7 @@ public class IgnoreListMsg extends ClientNetMsg { * Deserializes the subclass specific items from the supplied NetMsgReader. */ @Override - protected void _deserialize(ByteBufferReader reader) { + protected void _deserialize(ByteBufferReader reader) { int size = reader.getInt(); for (int i = 0; i < size; i++) { this.names.add(reader.getString()); diff --git a/src/engine/net/client/msg/IgnoreMsg.java b/src/engine/net/client/msg/IgnoreMsg.java index c154df9c..644f8b45 100644 --- a/src/engine/net/client/msg/IgnoreMsg.java +++ b/src/engine/net/client/msg/IgnoreMsg.java @@ -41,7 +41,7 @@ public class IgnoreMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public IgnoreMsg(AbstractConnection origin, ByteBufferReader reader) { + public IgnoreMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.IGNORE, origin, reader); } @@ -59,7 +59,7 @@ public class IgnoreMsg extends ClientNetMsg { * Deserializes the subclass specific items from the supplied NetMsgReader. */ @Override - protected void _deserialize(ByteBufferReader reader) { + protected void _deserialize(ByteBufferReader reader) { unknown1 = reader.getInt(); unknown2 = reader.getInt(); nameToIgnore = reader.getUnicodeString(); diff --git a/src/engine/net/client/msg/InvalidTradeRequestMsg.java b/src/engine/net/client/msg/InvalidTradeRequestMsg.java index ade68c9a..4e97395b 100644 --- a/src/engine/net/client/msg/InvalidTradeRequestMsg.java +++ b/src/engine/net/client/msg/InvalidTradeRequestMsg.java @@ -24,75 +24,73 @@ import engine.objects.AbstractGameObject; public class InvalidTradeRequestMsg extends ClientNetMsg { - private int unknown01; - private int busyType; - private int busyID; - private int requesterType; - private int requesterID; - - /** - * This is the general purpose constructor - */ - public InvalidTradeRequestMsg(int unknown01, AbstractGameObject busy, AbstractGameObject requester) { - super(Protocol.ARCREQUESTTRADEBUSY); - this.busyType = busy.getObjectType().ordinal(); - this.busyID = busy.getObjectUUID(); - this.requesterType = requester.getObjectType().ordinal(); - this.requesterID = requester.getObjectUUID(); - this.unknown01 = unknown01; - - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public InvalidTradeRequestMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.ARCREQUESTTRADEBUSY, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - unknown01 = reader.getInt(); - busyType = reader.getInt(); - busyID = reader.getInt(); - requesterType = reader.getInt(); - requesterID = reader.getInt(); - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - writer.putInt(unknown01); - writer.putInt(busyType); - writer.putInt(busyID); - writer.putInt(requesterType); - writer.putInt(requesterID); - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - public int getRequesterID() { - return requesterID; - } + private int unknown01; + private int busyType; + private int busyID; + private int requesterType; + private int requesterID; + + /** + * This is the general purpose constructor + */ + public InvalidTradeRequestMsg(int unknown01, AbstractGameObject busy, AbstractGameObject requester) { + super(Protocol.ARCREQUESTTRADEBUSY); + this.busyType = busy.getObjectType().ordinal(); + this.busyID = busy.getObjectUUID(); + this.requesterType = requester.getObjectType().ordinal(); + this.requesterID = requester.getObjectUUID(); + this.unknown01 = unknown01; + + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public InvalidTradeRequestMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ARCREQUESTTRADEBUSY, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + unknown01 = reader.getInt(); + busyType = reader.getInt(); + busyID = reader.getInt(); + requesterType = reader.getInt(); + requesterID = reader.getInt(); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putInt(unknown01); + writer.putInt(busyType); + writer.putInt(busyID); + writer.putInt(requesterType); + writer.putInt(requesterID); + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + public int getRequesterID() { + return requesterID; + } } diff --git a/src/engine/net/client/msg/ItemEffectMsg.java b/src/engine/net/client/msg/ItemEffectMsg.java index c5348447..5408118c 100644 --- a/src/engine/net/client/msg/ItemEffectMsg.java +++ b/src/engine/net/client/msg/ItemEffectMsg.java @@ -18,246 +18,249 @@ import engine.objects.AbstractWorldObject; public class ItemEffectMsg extends ClientNetMsg { - protected int numTrains; - protected int effectID; - protected int sourceType; - protected int sourceID; - protected int targetType; - protected int targetID; - - protected int unknown02; - protected int unknown03; - protected int duration; - protected int unknown05; - protected byte unknown06; - protected int ItemType; - protected int powerTypeID; - protected String powerUsedName; - protected int itemID; - /** - * This is the general purpose constructor. - */ - public ItemEffectMsg() { - super(Protocol.POWERACTION); - this.numTrains = 0; - this.effectID = 0; - this.sourceType = 0; - this.sourceID = 0; - this.targetType = 0; - this.targetID = 0; - - this.unknown02 = 0; - this.unknown03 = 0; - this.duration = 0; - this.unknown05 = 0; - this.unknown06 = (byte) 0; - - this.ItemType = 0; - this.itemID = 0; - this.powerUsedName = ""; - } - - /** - * This is the general purpose constructor. - */ - public ItemEffectMsg(AbstractWorldObject source, AbstractWorldObject target, int numTrains, int effectID, int duration, - int powerUsedID, String powerUsedName) { - super(Protocol.POWERACTION); - this.numTrains = numTrains; - this.effectID = effectID; - - if (source != null) { - this.sourceType = source.getObjectType().ordinal(); - this.sourceID = source.getObjectUUID(); - } else { - this.sourceType = 0; - this.sourceID = 0; - } - - if (target != null) { - this.targetType = target.getObjectType().ordinal(); - this.targetID = target.getObjectUUID(); - } else { - this.targetType = 0; - this.targetID = 0; - } - this.unknown02 = 0; //0 = apply, 2= remove - this.unknown03 = 0; - this.duration = duration; - this.unknown05 = 0; //1 = remove item effect - this.unknown06 = (byte) 0; //1 = remove item effect - this.ItemType = powerUsedID; - this.itemID = 0; - this.powerUsedName = powerUsedName; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ItemEffectMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.POWERACTION, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.numTrains); - writer.putInt(this.effectID); - - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.putInt(this.targetType); - writer.putInt(this.targetID); - - writer.putInt(this.unknown02); - writer.putInt(this.unknown03); - writer.putInt(this.duration); - writer.putInt(this.unknown05); - writer.put(this.unknown06); - - writer.putInt(this.ItemType); - writer.putInt(this.itemID); - - writer.putString(this.powerUsedName); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.numTrains = reader.getInt(); - this.effectID = reader.getInt(); - - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - - this.unknown02 = reader.getInt(); - this.unknown03 = reader.getInt(); - this.duration = reader.getInt(); - this.unknown05 = reader.getInt(); - this.unknown06 = reader.get(); - - this.ItemType = reader.getInt(); - this.itemID = reader.getInt(); - - this.powerUsedName = reader.getString(); - } - - public int getNumTrains() { - return this.numTrains; - } - - public int getEffectID() { - return this.effectID; - } - - public int getSourceType() { - return this.sourceType; - } - - public int getSourceID() { - return this.sourceID; - } - - public int getTargetType() { - return this.targetType; - } - - public int getTargetID() { - return this.targetID; - } - - public int getUnknown02() { - return this.unknown02; - } - - public int getUnknown03() { - return this.unknown03; - } - - public int getDuration() { - return this.duration; - } - - public int getUnknown05() { - return this.unknown05; - } - - public byte getUnknown06() { - return this.unknown06; - } - - public int getItemType() { - return this.ItemType; - } - public int getItemID() { - return this.itemID; - } - - public String getPowerUsedName() { - return this.powerUsedName; - } - - public void setNumTrains(int value) { - this.numTrains = value; - } - - public void setEffectID(int value) { - this.effectID = value; - } - - public void setSourceType(int value) { - this.sourceType = value; - } - - public void setSourceID(int value) { - this.sourceID = value; - } - - public void setTargetType(int value) { - this.targetType = value; - } - - public void setTargetID(int value) { - this.targetID = value; - } - - public void setUnknown02(int value) { - this.unknown02 = value; - } - - public void setUnknown03(int value) { - this.unknown03 = value; - } - - public void setDuration(int value) { - this.duration = value; - } - - public void setUnknown05(int value) { - this.unknown05 = value; - } - - public void setUnknown06(byte value) { - this.unknown06 = value; - } - - public void setItemType(int value) { - this.ItemType = value; - } - public void setItemID(int value){ - this.itemID = value; - } - - public void setPowerUsedName(String value) { - this.powerUsedName = value; - } + protected int numTrains; + protected int effectID; + protected int sourceType; + protected int sourceID; + protected int targetType; + protected int targetID; + + protected int unknown02; + protected int unknown03; + protected int duration; + protected int unknown05; + protected byte unknown06; + protected int ItemType; + protected int powerTypeID; + protected String powerUsedName; + protected int itemID; + + /** + * This is the general purpose constructor. + */ + public ItemEffectMsg() { + super(Protocol.POWERACTION); + this.numTrains = 0; + this.effectID = 0; + this.sourceType = 0; + this.sourceID = 0; + this.targetType = 0; + this.targetID = 0; + + this.unknown02 = 0; + this.unknown03 = 0; + this.duration = 0; + this.unknown05 = 0; + this.unknown06 = (byte) 0; + + this.ItemType = 0; + this.itemID = 0; + this.powerUsedName = ""; + } + + /** + * This is the general purpose constructor. + */ + public ItemEffectMsg(AbstractWorldObject source, AbstractWorldObject target, int numTrains, int effectID, int duration, + int powerUsedID, String powerUsedName) { + super(Protocol.POWERACTION); + this.numTrains = numTrains; + this.effectID = effectID; + + if (source != null) { + this.sourceType = source.getObjectType().ordinal(); + this.sourceID = source.getObjectUUID(); + } else { + this.sourceType = 0; + this.sourceID = 0; + } + + if (target != null) { + this.targetType = target.getObjectType().ordinal(); + this.targetID = target.getObjectUUID(); + } else { + this.targetType = 0; + this.targetID = 0; + } + this.unknown02 = 0; //0 = apply, 2= remove + this.unknown03 = 0; + this.duration = duration; + this.unknown05 = 0; //1 = remove item effect + this.unknown06 = (byte) 0; //1 = remove item effect + this.ItemType = powerUsedID; + this.itemID = 0; + this.powerUsedName = powerUsedName; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ItemEffectMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.POWERACTION, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.numTrains); + writer.putInt(this.effectID); + + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.putInt(this.targetType); + writer.putInt(this.targetID); + + writer.putInt(this.unknown02); + writer.putInt(this.unknown03); + writer.putInt(this.duration); + writer.putInt(this.unknown05); + writer.put(this.unknown06); + + writer.putInt(this.ItemType); + writer.putInt(this.itemID); + + writer.putString(this.powerUsedName); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.numTrains = reader.getInt(); + this.effectID = reader.getInt(); + + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + + this.unknown02 = reader.getInt(); + this.unknown03 = reader.getInt(); + this.duration = reader.getInt(); + this.unknown05 = reader.getInt(); + this.unknown06 = reader.get(); + + this.ItemType = reader.getInt(); + this.itemID = reader.getInt(); + + this.powerUsedName = reader.getString(); + } + + public int getNumTrains() { + return this.numTrains; + } + + public void setNumTrains(int value) { + this.numTrains = value; + } + + public int getEffectID() { + return this.effectID; + } + + public void setEffectID(int value) { + this.effectID = value; + } + + public int getSourceType() { + return this.sourceType; + } + + public void setSourceType(int value) { + this.sourceType = value; + } + + public int getSourceID() { + return this.sourceID; + } + + public void setSourceID(int value) { + this.sourceID = value; + } + + public int getTargetType() { + return this.targetType; + } + + public void setTargetType(int value) { + this.targetType = value; + } + + public int getTargetID() { + return this.targetID; + } + + public void setTargetID(int value) { + this.targetID = value; + } + + public int getUnknown02() { + return this.unknown02; + } + + public void setUnknown02(int value) { + this.unknown02 = value; + } + + public int getUnknown03() { + return this.unknown03; + } + + public void setUnknown03(int value) { + this.unknown03 = value; + } + + public int getDuration() { + return this.duration; + } + + public void setDuration(int value) { + this.duration = value; + } + + public int getUnknown05() { + return this.unknown05; + } + + public void setUnknown05(int value) { + this.unknown05 = value; + } + + public byte getUnknown06() { + return this.unknown06; + } + + public void setUnknown06(byte value) { + this.unknown06 = value; + } + + public int getItemType() { + return this.ItemType; + } + + public void setItemType(int value) { + this.ItemType = value; + } + + public int getItemID() { + return this.itemID; + } + + public void setItemID(int value) { + this.itemID = value; + } + + public String getPowerUsedName() { + return this.powerUsedName; + } + + public void setPowerUsedName(String value) { + this.powerUsedName = value; + } } diff --git a/src/engine/net/client/msg/ItemHealthUpdateMsg.java b/src/engine/net/client/msg/ItemHealthUpdateMsg.java index fc7a5443..ba818e3d 100644 --- a/src/engine/net/client/msg/ItemHealthUpdateMsg.java +++ b/src/engine/net/client/msg/ItemHealthUpdateMsg.java @@ -18,59 +18,59 @@ import engine.net.client.Protocol; public class ItemHealthUpdateMsg extends ClientNetMsg { - private int slot; - private float newDurability; + private int slot; + private float newDurability; - /** - * This is the general purpose constructor. - */ - public ItemHealthUpdateMsg(int slot, float newDurability) { - super(Protocol.ITEMHEALTHUPDATE); - this.slot = slot; - this.newDurability = newDurability; - } + /** + * This is the general purpose constructor. + */ + public ItemHealthUpdateMsg(int slot, float newDurability) { + super(Protocol.ITEMHEALTHUPDATE); + this.slot = slot; + this.newDurability = newDurability; + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ItemHealthUpdateMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ITEMHEALTHUPDATE, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ItemHealthUpdateMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ITEMHEALTHUPDATE, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.slot); - writer.putFloat(this.newDurability); - } + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.slot); + writer.putFloat(this.newDurability); + } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.slot = reader.getInt(); - this.newDurability = reader.getFloat(); - } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.slot = reader.getInt(); + this.newDurability = reader.getFloat(); + } - public int getSlot() { - return this.slot; - } + public int getSlot() { + return this.slot; + } - public void setSlot(int value) { - this.slot = value; - } + public void setSlot(int value) { + this.slot = value; + } - public float getNewDurability() { - return this.newDurability; - } + public float getNewDurability() { + return this.newDurability; + } - public void setNewDurability(float value) { - this.newDurability = value; - } + public void setNewDurability(float value) { + this.newDurability = value; + } } diff --git a/src/engine/net/client/msg/ItemProductionMsg.java b/src/engine/net/client/msg/ItemProductionMsg.java index 96d6570d..dc7ed812 100644 --- a/src/engine/net/client/msg/ItemProductionMsg.java +++ b/src/engine/net/client/msg/ItemProductionMsg.java @@ -28,540 +28,541 @@ import java.util.HashMap; public class ItemProductionMsg extends ClientNetMsg { - private static final int ACTION_PRODUCE = 1; - private static final int ACTION_JUNK = 2; - private static final int ACTION_RECYCLE = 3; - private static final int ACTION_COMPLETE = 4; - private static final int ACTION_DEPOSIT = 6; - private static final int ACTION_SETPRICE = 5; - private static final int ACTION_TAKE = 7; - private static final int ACTION_CONFIRM_SETPRICE = 9; - private static final int ACTION_CONFIRM_DEPOSIT = 10; - private static final int ACTION_CONFIRM_TAKE = 11; // Unsure. Sent by client - private static final int ACTION_CONFIRM_PRODUCE = 8; - - private ArrayList ItemList; - private int size; - private int buildingUUID; - private int unknown01; - private int itemUUID; - private int itemType; - public void setItemUUID(int itemUUID) { - this.itemUUID = itemUUID; - } - - private int totalProduction; - private int unknown03; - private int pToken; - private int sToken; - private String name; - private int actionType; - private int npcUUID; - private boolean add; - private int itemPrice; - private boolean isMultiple; - - private HashMap itemIDtoTypeMap;; - - /** - * This is the general purpose constructor. - */ - - public ItemProductionMsg() { - super(Protocol.ITEMPRODUCTION); + private static final int ACTION_PRODUCE = 1; + private static final int ACTION_JUNK = 2; + private static final int ACTION_RECYCLE = 3; + private static final int ACTION_COMPLETE = 4; + private static final int ACTION_DEPOSIT = 6; + private static final int ACTION_SETPRICE = 5; + private static final int ACTION_TAKE = 7; + private static final int ACTION_CONFIRM_SETPRICE = 9; + private static final int ACTION_CONFIRM_DEPOSIT = 10; + private static final int ACTION_CONFIRM_TAKE = 11; // Unsure. Sent by client + private static final int ACTION_CONFIRM_PRODUCE = 8; + + private ArrayList ItemList; + private int size; + private int buildingUUID; + private int unknown01; + private int itemUUID; + private int itemType; + private int totalProduction; + private int unknown03; + private int pToken; + private int sToken; + private String name; + private int actionType; + private int npcUUID; + private boolean add; + private int itemPrice; + private boolean isMultiple; + private HashMap itemIDtoTypeMap; + + /** + * This is the general purpose constructor. + */ + + public ItemProductionMsg() { + super(Protocol.ITEMPRODUCTION); this.actionType = 0; this.size = 0; - this.buildingUUID = 0; - this.unknown01 = 0; - this.itemUUID = 0; - this.totalProduction = 0; - this.unknown03 = 0; - this.pToken = 0; - this.sToken = 0; - this.name = ""; - this.itemPrice = 0; - this.itemType = 0; - - } - - public ItemProductionMsg(Building building, NPC vendor, Item item, int actionType, boolean add) { - super(Protocol.ITEMPRODUCTION); - this.actionType = actionType; - this.size = 0; - this.buildingUUID = building.getObjectUUID(); - this.npcUUID = vendor.getObjectUUID(); - this.itemType = item.getObjectType().ordinal(); - this.itemUUID = item.getObjectUUID(); - this.unknown01 = 0; - this.totalProduction = 0; - this.unknown03 = 0; - this.pToken = 0; - this.sToken = 0; - this.name = ""; - this.add = add; - this.itemPrice = item.getValue(); - - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ItemProductionMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ITEMPRODUCTION, origin, reader); - - } - - /** - * @see AbstractNetMsg#getPowerOfTwoBufferSize() - */ - @Override - protected int getPowerOfTwoBufferSize() { - //Larger size for historically larger opcodes - return (16); // 2^16 == 64k - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - Building building = BuildingManager.getBuildingFromCache(this.buildingUUID); - if (building == null) - return; - // Common Header - - writer.putInt(this.actionType); - writer.putInt(GameObjectType.Building.ordinal()); - writer.putInt(this.buildingUUID); - writer.putInt(GameObjectType.NPC.ordinal()); - writer.putInt(this.npcUUID); - - switch (this.actionType) { - - case ACTION_CONFIRM_DEPOSIT: - writer.putInt(0); // Not item ordinal? - writer.putInt(0); // Not item uuid? - writer.putInt(1); - writer.putInt(0); - - if (!add) { - writer.put((byte) 1); - Item item = Item.getFromCache(this.itemUUID); - if (item != null) - Item.serializeForClientMsgWithoutSlot(item,writer); - writer.putInt(building.getStrongboxValue()); - writer.putInt(0); - writer.putInt(0); - writer.put((byte) 0); - break; - } - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.put((byte) 1); - Item item; - if (this.itemType == GameObjectType.Item.ordinal()) - item = Item.getFromCache(this.itemUUID); - else - item = MobLoot.getFromCache(this.itemUUID); - if (item != null) - Item.serializeForClientMsgWithoutSlot(item,writer); - writer.putInt(building.getStrongboxValue()); - writer.putInt(0); - writer.putInt(0); - writer.put((byte) 0); - break; - case ACTION_CONFIRM_TAKE: - writer.putInt(this.itemType); - writer.putInt(this.itemUUID); - writer.putInt(1); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.put((byte) 0); - break; - case ACTION_SETPRICE: - writer.putInt(this.itemType); - writer.putInt(this.itemUUID); - writer.putInt(1); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(this.itemPrice); // new price - writer.putInt(0); - writer.putInt(0); - writer.put((byte)0); - break; - case ACTION_CONFIRM_SETPRICE: - writer.putInt(this.itemType); - writer.putInt(this.itemUUID); - writer.putInt(1); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.put((byte)1); - writer.putInt(building.getStrongboxValue()); // new price - writer.putInt(0); - writer.putInt(0); - //writer.put((byte) 0); - break; - case ACTION_DEPOSIT: - writer.putInt(this.itemType); - writer.putInt(this.itemUUID); - writer.putInt(1); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.put((byte) 0); - break; - case ACTION_TAKE: - case ACTION_RECYCLE: - - writer.putInt(0); - writer.putInt(0); - writer.putInt(1); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.put((byte) 1); - writer.putInt(building.getStrongboxValue()); - - if (this.itemIDtoTypeMap != null){ - writer.putInt(this.itemIDtoTypeMap.size()); - - for (int itemID : this.itemIDtoTypeMap.keySet()) { - writer.putInt(this.itemIDtoTypeMap.get(itemID)); - writer.putInt(itemID); - } - - }else - writer.putInt(0); - - writer.putInt(0); - - break; - case ACTION_CONFIRM_PRODUCE: - writer.putInt(0); - writer.putInt(0); - writer.putInt(1); - MobLoot toRoll = MobLoot.getFromCache(this.itemUUID); - writer.putInt(-1497023830); - if (toRoll != null && toRoll.getPrefix() != null && !toRoll.getPrefix().isEmpty()){ - EffectsBase eb = PowersManager.getEffectByIDString(toRoll.getPrefix()); - if (eb == null) - this.pToken = 0; - else - this.pToken = eb.getToken(); - } - - if (toRoll != null && toRoll.getSuffix() != null && !toRoll.getSuffix().isEmpty()){ - EffectsBase eb = PowersManager.getEffectByIDString(toRoll.getSuffix()); - if (eb == null) - this.sToken = 0; - else - this.sToken = eb.getToken(); - } - if (toRoll.isRandom() == false || (toRoll != null && toRoll.isComplete())){ - writer.putInt(this.pToken); - writer.putInt(this.sToken); - }else{ - writer.putInt(0); - writer.putInt(0); - } - - writer.putString(toRoll.getCustomName());; - writer.putInt(GameObjectType.MobLoot.ordinal()); - writer.putInt(this.itemUUID); - writer.putInt(0); //items left to produce? - if (toRoll != null){ - writer.putInt(toRoll.getItemBaseID()); - writer.putInt(toRoll.getValue()); - } - else{ - writer.putInt(0); - writer.putInt(0); - } - - NPC vendor = NPC.getFromCache(this.npcUUID); - if (vendor != null){ - if (toRoll.isComplete()){ - writer.putInt(0); - writer.putInt(0); - }else{ - long timeLeft = toRoll.getDateToUpgrade() - System.currentTimeMillis(); - - timeLeft /=1000; - writer.putInt((int)timeLeft); - writer.putInt(vendor.getRollingTimeInSeconds(toRoll.getItemBaseID())); - } - - }else{ - writer.putInt(0); - writer.putInt(0); - } - if (toRoll.isComplete()) - writer.putInt(0); - else - writer.putInt(1); - writer.put((byte)0); - - if (toRoll != null && toRoll.isComplete()) - writer.put((byte)1); - else - writer.put((byte)0); - writer.put((byte)0); - writer.put((byte)1); - writer.putInt(vendor.getBuilding().getStrongboxValue()); - - writer.putInt(0); - writer.putInt(0); - //writer.putInt(0); //error popup - - break; - case ACTION_COMPLETE: - writer.putInt(this.itemType); - writer.putInt(this.itemUUID); - writer.putInt(this.totalProduction); - writer.putInt(this.unknown03); - writer.putInt(this.pToken); - writer.putInt(this.sToken); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.put((byte)0); - break; - case ACTION_JUNK: - writer.putInt(this.itemType); - writer.putInt(this.itemUUID); - writer.putInt(this.totalProduction); - writer.putInt(this.unknown03); - writer.putInt(this.pToken); - writer.putInt(this.sToken); - writer.putString(this.name); - writer.putInt(0); - writer.putInt(0); - writer.putShort((short)0); - writer.put((byte)0); - break; - default: - writer.putInt(0); - writer.putInt(1); - writer.putInt(0); - writer.putInt(0); - break; - } - - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - - // Common header - - this.actionType = reader.getInt(); - reader.getInt(); // Building type padding - this.buildingUUID = reader.getInt(); - reader.getInt(); // NPC type padding - this.npcUUID = reader.getInt(); - - switch (this.actionType) { - case ACTION_SETPRICE: - this.itemType = reader.getInt(); - this.itemUUID = reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - this.itemPrice = reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.get(); - break; - case ACTION_RECYCLE: - case ACTION_TAKE: - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.get(); - this.size = reader.getInt(); - HashMap tempIDs = new HashMap<>(); - for (int i = 0; i < this.size; i++) { - int type = reader.getInt(); // Item type padding - this.itemUUID = reader.getInt(); - tempIDs.put(this.itemUUID, type); - } - reader.getInt(); - this.itemIDtoTypeMap = tempIDs; - break; - case ACTION_DEPOSIT: - this.itemType = reader.getInt(); - this.itemUUID = reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.get(); - break; - case ACTION_JUNK: - this.itemType = reader.getInt(); - this.itemUUID = reader.getInt(); - this.totalProduction =reader.getInt(); - this.unknown03 = reader.getInt(); - this.pToken = reader.getInt(); - this.sToken = reader.getInt(); - this.name = reader.getString(); - reader.getInt(); - reader.getInt(); - reader.get(); - break; - default: - this.itemType = reader.getInt(); - this.itemUUID = reader.getInt(); - this.totalProduction =reader.getInt(); - this.unknown03 = reader.getInt(); - this.pToken = reader.getInt(); - this.sToken = reader.getInt(); - this.name = reader.getString(); - this.isMultiple = reader.getInt() != 0 ? true:false; - reader.getInt(); - - if (this.actionType == ACTION_COMPLETE || this.actionType == ACTION_JUNK) - reader.get(); - else - reader.getShort(); - break; - - } - } - - public int getItemType() { - return itemType; - } - - // TODO fix ArrayList Accessability. - public ArrayList getItemList() { - return this.ItemList; - } - - public void addItem(Long item) { - this.ItemList.add(item); - } - - public int getUnknown01() { - return unknown01; - } - - public int getTotalProduction() { - return totalProduction; - } - - public int getUnknown03() { - return unknown03; - } - - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - public void setTotalProduction(int unknown02) { - this.totalProduction = unknown02; - } - - public void setUnknown03(int unknown03) { - this.unknown03 = unknown03; - } - - public void setItemList(ArrayList value) { - this.ItemList = value; - } - - public int getItemUUID() { - return itemUUID; - } - - public void setpToken(int pToken) { - this.pToken = pToken; - } - - public int getpToken() { - return pToken; - } - - public void setsToken(int sToken) { - this.sToken = sToken; - } - - public int getsToken() { - return sToken; - } - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public int getSize() { - return size; - } - - public void setSize(int size) { - this.size = size; - } - - public int getActionType() { - return actionType; - } - - public final void setActionType(int actionType) { - this.actionType = actionType; - } - - public int getNpcUUID() { - return npcUUID; - } - - public HashMap getItemIDtoTypeMap() { - return itemIDtoTypeMap; - } - - /** - * @return the itemPrice - */ - public int getItemPrice() { - return itemPrice; - } - - public boolean isMultiple() { - return isMultiple; - } - - public void setMultiple(boolean isMultiple) { - this.isMultiple = isMultiple; - } + this.buildingUUID = 0; + this.unknown01 = 0; + this.itemUUID = 0; + this.totalProduction = 0; + this.unknown03 = 0; + this.pToken = 0; + this.sToken = 0; + this.name = ""; + this.itemPrice = 0; + this.itemType = 0; + + } + + ; + + public ItemProductionMsg(Building building, NPC vendor, Item item, int actionType, boolean add) { + super(Protocol.ITEMPRODUCTION); + this.actionType = actionType; + this.size = 0; + this.buildingUUID = building.getObjectUUID(); + this.npcUUID = vendor.getObjectUUID(); + this.itemType = item.getObjectType().ordinal(); + this.itemUUID = item.getObjectUUID(); + this.unknown01 = 0; + this.totalProduction = 0; + this.unknown03 = 0; + this.pToken = 0; + this.sToken = 0; + this.name = ""; + this.add = add; + this.itemPrice = item.getValue(); + + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ItemProductionMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ITEMPRODUCTION, origin, reader); + + } + + /** + * @see AbstractNetMsg#getPowerOfTwoBufferSize() + */ + @Override + protected int getPowerOfTwoBufferSize() { + //Larger size for historically larger opcodes + return (16); // 2^16 == 64k + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + Building building = BuildingManager.getBuildingFromCache(this.buildingUUID); + if (building == null) + return; + // Common Header + + writer.putInt(this.actionType); + writer.putInt(GameObjectType.Building.ordinal()); + writer.putInt(this.buildingUUID); + writer.putInt(GameObjectType.NPC.ordinal()); + writer.putInt(this.npcUUID); + + switch (this.actionType) { + + case ACTION_CONFIRM_DEPOSIT: + writer.putInt(0); // Not item ordinal? + writer.putInt(0); // Not item uuid? + writer.putInt(1); + writer.putInt(0); + + if (!add) { + writer.put((byte) 1); + Item item = Item.getFromCache(this.itemUUID); + if (item != null) + Item.serializeForClientMsgWithoutSlot(item, writer); + writer.putInt(building.getStrongboxValue()); + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 0); + break; + } + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 1); + Item item; + if (this.itemType == GameObjectType.Item.ordinal()) + item = Item.getFromCache(this.itemUUID); + else + item = MobLoot.getFromCache(this.itemUUID); + if (item != null) + Item.serializeForClientMsgWithoutSlot(item, writer); + writer.putInt(building.getStrongboxValue()); + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 0); + break; + case ACTION_CONFIRM_TAKE: + writer.putInt(this.itemType); + writer.putInt(this.itemUUID); + writer.putInt(1); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 0); + break; + case ACTION_SETPRICE: + writer.putInt(this.itemType); + writer.putInt(this.itemUUID); + writer.putInt(1); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(this.itemPrice); // new price + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 0); + break; + case ACTION_CONFIRM_SETPRICE: + writer.putInt(this.itemType); + writer.putInt(this.itemUUID); + writer.putInt(1); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 1); + writer.putInt(building.getStrongboxValue()); // new price + writer.putInt(0); + writer.putInt(0); + //writer.put((byte) 0); + break; + case ACTION_DEPOSIT: + writer.putInt(this.itemType); + writer.putInt(this.itemUUID); + writer.putInt(1); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 0); + break; + case ACTION_TAKE: + case ACTION_RECYCLE: + + writer.putInt(0); + writer.putInt(0); + writer.putInt(1); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 1); + writer.putInt(building.getStrongboxValue()); + + if (this.itemIDtoTypeMap != null) { + writer.putInt(this.itemIDtoTypeMap.size()); + + for (int itemID : this.itemIDtoTypeMap.keySet()) { + writer.putInt(this.itemIDtoTypeMap.get(itemID)); + writer.putInt(itemID); + } + + } else + writer.putInt(0); + + writer.putInt(0); + + break; + case ACTION_CONFIRM_PRODUCE: + writer.putInt(0); + writer.putInt(0); + writer.putInt(1); + MobLoot toRoll = MobLoot.getFromCache(this.itemUUID); + writer.putInt(-1497023830); + if (toRoll != null && toRoll.getPrefix() != null && !toRoll.getPrefix().isEmpty()) { + EffectsBase eb = PowersManager.getEffectByIDString(toRoll.getPrefix()); + if (eb == null) + this.pToken = 0; + else + this.pToken = eb.getToken(); + } + + if (toRoll != null && toRoll.getSuffix() != null && !toRoll.getSuffix().isEmpty()) { + EffectsBase eb = PowersManager.getEffectByIDString(toRoll.getSuffix()); + if (eb == null) + this.sToken = 0; + else + this.sToken = eb.getToken(); + } + if (toRoll.isRandom() == false || (toRoll != null && toRoll.isComplete())) { + writer.putInt(this.pToken); + writer.putInt(this.sToken); + } else { + writer.putInt(0); + writer.putInt(0); + } + + writer.putString(toRoll.getCustomName()); + ; + writer.putInt(GameObjectType.MobLoot.ordinal()); + writer.putInt(this.itemUUID); + writer.putInt(0); //items left to produce? + if (toRoll != null) { + writer.putInt(toRoll.getItemBaseID()); + writer.putInt(toRoll.getValue()); + } else { + writer.putInt(0); + writer.putInt(0); + } + + NPC vendor = NPC.getFromCache(this.npcUUID); + if (vendor != null) { + if (toRoll.isComplete()) { + writer.putInt(0); + writer.putInt(0); + } else { + long timeLeft = toRoll.getDateToUpgrade() - System.currentTimeMillis(); + + timeLeft /= 1000; + writer.putInt((int) timeLeft); + writer.putInt(vendor.getRollingTimeInSeconds(toRoll.getItemBaseID())); + } + + } else { + writer.putInt(0); + writer.putInt(0); + } + if (toRoll.isComplete()) + writer.putInt(0); + else + writer.putInt(1); + writer.put((byte) 0); + + if (toRoll != null && toRoll.isComplete()) + writer.put((byte) 1); + else + writer.put((byte) 0); + writer.put((byte) 0); + writer.put((byte) 1); + writer.putInt(vendor.getBuilding().getStrongboxValue()); + + writer.putInt(0); + writer.putInt(0); + //writer.putInt(0); //error popup + + break; + case ACTION_COMPLETE: + writer.putInt(this.itemType); + writer.putInt(this.itemUUID); + writer.putInt(this.totalProduction); + writer.putInt(this.unknown03); + writer.putInt(this.pToken); + writer.putInt(this.sToken); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 0); + break; + case ACTION_JUNK: + writer.putInt(this.itemType); + writer.putInt(this.itemUUID); + writer.putInt(this.totalProduction); + writer.putInt(this.unknown03); + writer.putInt(this.pToken); + writer.putInt(this.sToken); + writer.putString(this.name); + writer.putInt(0); + writer.putInt(0); + writer.putShort((short) 0); + writer.put((byte) 0); + break; + default: + writer.putInt(0); + writer.putInt(1); + writer.putInt(0); + writer.putInt(0); + break; + } + + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + + // Common header + + this.actionType = reader.getInt(); + reader.getInt(); // Building type padding + this.buildingUUID = reader.getInt(); + reader.getInt(); // NPC type padding + this.npcUUID = reader.getInt(); + + switch (this.actionType) { + case ACTION_SETPRICE: + this.itemType = reader.getInt(); + this.itemUUID = reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + this.itemPrice = reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.get(); + break; + case ACTION_RECYCLE: + case ACTION_TAKE: + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.get(); + this.size = reader.getInt(); + HashMap tempIDs = new HashMap<>(); + for (int i = 0; i < this.size; i++) { + int type = reader.getInt(); // Item type padding + this.itemUUID = reader.getInt(); + tempIDs.put(this.itemUUID, type); + } + reader.getInt(); + this.itemIDtoTypeMap = tempIDs; + break; + case ACTION_DEPOSIT: + this.itemType = reader.getInt(); + this.itemUUID = reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.get(); + break; + case ACTION_JUNK: + this.itemType = reader.getInt(); + this.itemUUID = reader.getInt(); + this.totalProduction = reader.getInt(); + this.unknown03 = reader.getInt(); + this.pToken = reader.getInt(); + this.sToken = reader.getInt(); + this.name = reader.getString(); + reader.getInt(); + reader.getInt(); + reader.get(); + break; + default: + this.itemType = reader.getInt(); + this.itemUUID = reader.getInt(); + this.totalProduction = reader.getInt(); + this.unknown03 = reader.getInt(); + this.pToken = reader.getInt(); + this.sToken = reader.getInt(); + this.name = reader.getString(); + this.isMultiple = reader.getInt() != 0 ? true : false; + reader.getInt(); + + if (this.actionType == ACTION_COMPLETE || this.actionType == ACTION_JUNK) + reader.get(); + else + reader.getShort(); + break; + + } + } + + public int getItemType() { + return itemType; + } + + // TODO fix ArrayList Accessability. + public ArrayList getItemList() { + return this.ItemList; + } + + public void setItemList(ArrayList value) { + this.ItemList = value; + } + + public void addItem(Long item) { + this.ItemList.add(item); + } + + public int getUnknown01() { + return unknown01; + } + + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + public int getTotalProduction() { + return totalProduction; + } + + public void setTotalProduction(int unknown02) { + this.totalProduction = unknown02; + } + + public int getUnknown03() { + return unknown03; + } + + public void setUnknown03(int unknown03) { + this.unknown03 = unknown03; + } + + public int getItemUUID() { + return itemUUID; + } + + public void setItemUUID(int itemUUID) { + this.itemUUID = itemUUID; + } + + public int getpToken() { + return pToken; + } + + public void setpToken(int pToken) { + this.pToken = pToken; + } + + public int getsToken() { + return sToken; + } + + public void setsToken(int sToken) { + this.sToken = sToken; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + public int getActionType() { + return actionType; + } + + public final void setActionType(int actionType) { + this.actionType = actionType; + } + + public int getNpcUUID() { + return npcUUID; + } + + public HashMap getItemIDtoTypeMap() { + return itemIDtoTypeMap; + } + + /** + * @return the itemPrice + */ + public int getItemPrice() { + return itemPrice; + } + + public boolean isMultiple() { + return isMultiple; + } + + public void setMultiple(boolean isMultiple) { + this.isMultiple = isMultiple; + } } diff --git a/src/engine/net/client/msg/KeepAliveServerClientMsg.java b/src/engine/net/client/msg/KeepAliveServerClientMsg.java index 17c35351..e674d1b5 100644 --- a/src/engine/net/client/msg/KeepAliveServerClientMsg.java +++ b/src/engine/net/client/msg/KeepAliveServerClientMsg.java @@ -18,69 +18,69 @@ import engine.net.client.Protocol; public class KeepAliveServerClientMsg extends ClientNetMsg { - private int firstData; // First 4 bytes - private int secondData; // Second 4 bytes - - private double timeLoggedIn; - private byte endData; // Last byte - - /** - * This is the general purpose constructor. - */ - public KeepAliveServerClientMsg(int firstData, int secondData, byte endData) { - super(Protocol.KEEPALIVESERVERCLIENT); - this.firstData = firstData; - this.secondData = secondData; - this.endData = endData; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public KeepAliveServerClientMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.KEEPALIVESERVERCLIENT, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putDouble(this.timeLoggedIn); - writer.put((byte)0); - //writer.putDouble(1000); - - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.timeLoggedIn = reader.getDouble(); - this.endData = reader.get(); - } - - public int getFirstData() { - return firstData; - } - - public int getSecondData() { - return secondData; - } - - public byte getEndData() { - return endData; - } - - public double getTimeLoggedIn() { - return timeLoggedIn; - } - - public void setTimeLoggedIn(double timeLoggedIn) { - this.timeLoggedIn = timeLoggedIn; - } + private int firstData; // First 4 bytes + private int secondData; // Second 4 bytes + + private double timeLoggedIn; + private byte endData; // Last byte + + /** + * This is the general purpose constructor. + */ + public KeepAliveServerClientMsg(int firstData, int secondData, byte endData) { + super(Protocol.KEEPALIVESERVERCLIENT); + this.firstData = firstData; + this.secondData = secondData; + this.endData = endData; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public KeepAliveServerClientMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.KEEPALIVESERVERCLIENT, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putDouble(this.timeLoggedIn); + writer.put((byte) 0); + //writer.putDouble(1000); + + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.timeLoggedIn = reader.getDouble(); + this.endData = reader.get(); + } + + public int getFirstData() { + return firstData; + } + + public int getSecondData() { + return secondData; + } + + public byte getEndData() { + return endData; + } + + public double getTimeLoggedIn() { + return timeLoggedIn; + } + + public void setTimeLoggedIn(double timeLoggedIn) { + this.timeLoggedIn = timeLoggedIn; + } } diff --git a/src/engine/net/client/msg/LeaderboardMessage.java b/src/engine/net/client/msg/LeaderboardMessage.java index 7dc992a0..3e2bc9ce 100644 --- a/src/engine/net/client/msg/LeaderboardMessage.java +++ b/src/engine/net/client/msg/LeaderboardMessage.java @@ -23,81 +23,82 @@ import engine.objects.Shrine; public class LeaderboardMessage extends ClientNetMsg { - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public LeaderboardMessage(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.LEADERBOARD, origin, reader); - } - - public LeaderboardMessage() { - super(Protocol.LEADERBOARD); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - - writer.putInt(ShrineType.values().length);//?? - - for (ShrineType shrineType : ShrineType.values()) { - writer.putInt(shrineType.ordinal()); - writer.putInt(shrineType.getShrinesCopy().size()); - int i = 0; - for (Shrine shrine : shrineType.getShrinesCopy()) { - i++; - writer.putInt(shrine.getFavors()); - Building shrineBuilding = BuildingManager.getBuilding(shrine.getBuildingID()); - if (shrineBuilding != null) { - Guild shrineGuild = shrineBuilding.getGuild(); - if (shrineGuild != null) { - writer.putInt(shrineGuild.getObjectType().ordinal()); - writer.putInt(shrineGuild.getObjectUUID()); - - GuildTag._serializeForDisplay(shrineGuild.getGuildTag(),writer); - writer.putString(shrineGuild.getName()); - } else { - writer.putLong(0); - writer.putInt(16); - writer.putInt(16); - writer.putInt(16); - writer.putInt(0); - writer.putInt(0); - writer.putString(""); - } - }else{ - 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.putString(shrineType.name()); - } - - } - @Override - protected int getPowerOfTwoBufferSize() { - return (14); // 2^14 == 16384 - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public LeaderboardMessage(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.LEADERBOARD, origin, reader); + } + + public LeaderboardMessage() { + super(Protocol.LEADERBOARD); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + + writer.putInt(ShrineType.values().length);//?? + + for (ShrineType shrineType : ShrineType.values()) { + writer.putInt(shrineType.ordinal()); + writer.putInt(shrineType.getShrinesCopy().size()); + int i = 0; + for (Shrine shrine : shrineType.getShrinesCopy()) { + i++; + writer.putInt(shrine.getFavors()); + Building shrineBuilding = BuildingManager.getBuilding(shrine.getBuildingID()); + if (shrineBuilding != null) { + Guild shrineGuild = shrineBuilding.getGuild(); + if (shrineGuild != null) { + writer.putInt(shrineGuild.getObjectType().ordinal()); + writer.putInt(shrineGuild.getObjectUUID()); + + GuildTag._serializeForDisplay(shrineGuild.getGuildTag(), writer); + writer.putString(shrineGuild.getName()); + } else { + writer.putLong(0); + writer.putInt(16); + writer.putInt(16); + writer.putInt(16); + writer.putInt(0); + writer.putInt(0); + writer.putString(""); + } + } else { + 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.putString(shrineType.name()); + } + + } + + @Override + protected int getPowerOfTwoBufferSize() { + return (14); // 2^14 == 16384 + } } diff --git a/src/engine/net/client/msg/LeaveWorldMsg.java b/src/engine/net/client/msg/LeaveWorldMsg.java index 62ab8bbc..0711c881 100644 --- a/src/engine/net/client/msg/LeaveWorldMsg.java +++ b/src/engine/net/client/msg/LeaveWorldMsg.java @@ -18,35 +18,35 @@ import engine.net.client.Protocol; public class LeaveWorldMsg extends ClientNetMsg { - /** - * This is the general purpose constructor. - */ - public LeaveWorldMsg() { - super(Protocol.LEAVEREQUEST); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public LeaveWorldMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.LEAVEREQUEST, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - } + /** + * This is the general purpose constructor. + */ + public LeaveWorldMsg() { + super(Protocol.LEAVEREQUEST); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public LeaveWorldMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.LEAVEREQUEST, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + } } diff --git a/src/engine/net/client/msg/LoadCharacterMsg.java b/src/engine/net/client/msg/LoadCharacterMsg.java index 8ba8a111..50399a6f 100644 --- a/src/engine/net/client/msg/LoadCharacterMsg.java +++ b/src/engine/net/client/msg/LoadCharacterMsg.java @@ -20,120 +20,120 @@ import engine.objects.Corpse; public class LoadCharacterMsg extends ClientNetMsg { - private AbstractCharacter absChar; - private Corpse corpse; - private boolean hideNonAscii; - - /** - * This is the general purpose constructor. - */ - public LoadCharacterMsg(AbstractCharacter ch, boolean laln) { - super(Protocol.LOADCHARACTER); - this.absChar = ch; - this.corpse = null; - this.hideNonAscii = laln; - } - - /** - * This is the general purpose constructor. - */ - public LoadCharacterMsg(Corpse corpse, boolean laln) { - super(Protocol.LOADCHARACTER); - this.corpse = corpse; - this.absChar = null; - this.hideNonAscii = laln; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public LoadCharacterMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.LOADCHARACTER, origin, reader); - } - - /** - * @see AbstractNetMsg#getPowerOfTwoBufferSize() - */ - @Override - protected int getPowerOfTwoBufferSize() { - //Larger size for historically larger opcodes - return (17); // 2^17 == 131,072 - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - - if (absChar != null) { - - if (absChar.region != null) { - writer.putInt(absChar.region.getLevel()); - writer.putInt(absChar.region.getRoom()); - } else { - writer.putInt(-1); - writer.putInt(-1); - } - - } else if (corpse != null){ - writer.putInt(-1); - writer.putInt(-1); - } - - if (corpse != null) { - writer.putInt(Float.floatToIntBits(corpse.getLoc().getX())); - writer.putInt(Float.floatToIntBits(corpse.getLoc().getY())); - writer.putInt(Float.floatToIntBits(corpse.getLoc().getZ())); - writer.put((byte) 0); - } else if (absChar != null) { - - writer.putFloat(absChar.getLoc().getX()); - writer.putFloat(absChar.getLoc().getY()); - writer.putFloat(absChar.getLoc().getZ()); - - if (absChar.isMoving()) { - writer.put((byte) 1); - writer.putFloat(absChar.getEndLoc().x); - writer.putFloat(absChar.getEndLoc().y); - writer.putFloat(absChar.getEndLoc().z); - } else - writer.put((byte) 0); - } else { - writer.put((byte) 0); - } - - if (corpse != null) - Corpse._serializeForClientMsg(corpse, writer, this.hideNonAscii); - else if (absChar != null) - AbstractCharacter.serializeForClientMsgOtherPlayer(this.absChar,writer, this.hideNonAscii); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - int unknown1 = reader.getInt(); - int unknown2 = reader.getInt(); - int unknown3 = reader.getInt(); - int unknown4 = reader.getInt(); - int unknown5 = reader.getInt(); - // TODO finish deserialization impl - } - - public AbstractCharacter getChar() { - return this.absChar; - } - - public void setChar(AbstractCharacter value) { - this.absChar = value; - } - - public void setCorpse(Corpse value) { - this.corpse = value; - } + private AbstractCharacter absChar; + private Corpse corpse; + private boolean hideNonAscii; + + /** + * This is the general purpose constructor. + */ + public LoadCharacterMsg(AbstractCharacter ch, boolean laln) { + super(Protocol.LOADCHARACTER); + this.absChar = ch; + this.corpse = null; + this.hideNonAscii = laln; + } + + /** + * This is the general purpose constructor. + */ + public LoadCharacterMsg(Corpse corpse, boolean laln) { + super(Protocol.LOADCHARACTER); + this.corpse = corpse; + this.absChar = null; + this.hideNonAscii = laln; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public LoadCharacterMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.LOADCHARACTER, origin, reader); + } + + /** + * @see AbstractNetMsg#getPowerOfTwoBufferSize() + */ + @Override + protected int getPowerOfTwoBufferSize() { + //Larger size for historically larger opcodes + return (17); // 2^17 == 131,072 + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + + if (absChar != null) { + + if (absChar.region != null) { + writer.putInt(absChar.region.getLevel()); + writer.putInt(absChar.region.getRoom()); + } else { + writer.putInt(-1); + writer.putInt(-1); + } + + } else if (corpse != null) { + writer.putInt(-1); + writer.putInt(-1); + } + + if (corpse != null) { + writer.putInt(Float.floatToIntBits(corpse.getLoc().getX())); + writer.putInt(Float.floatToIntBits(corpse.getLoc().getY())); + writer.putInt(Float.floatToIntBits(corpse.getLoc().getZ())); + writer.put((byte) 0); + } else if (absChar != null) { + + writer.putFloat(absChar.getLoc().getX()); + writer.putFloat(absChar.getLoc().getY()); + writer.putFloat(absChar.getLoc().getZ()); + + if (absChar.isMoving()) { + writer.put((byte) 1); + writer.putFloat(absChar.getEndLoc().x); + writer.putFloat(absChar.getEndLoc().y); + writer.putFloat(absChar.getEndLoc().z); + } else + writer.put((byte) 0); + } else { + writer.put((byte) 0); + } + + if (corpse != null) + Corpse._serializeForClientMsg(corpse, writer, this.hideNonAscii); + else if (absChar != null) + AbstractCharacter.serializeForClientMsgOtherPlayer(this.absChar, writer, this.hideNonAscii); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + int unknown1 = reader.getInt(); + int unknown2 = reader.getInt(); + int unknown3 = reader.getInt(); + int unknown4 = reader.getInt(); + int unknown5 = reader.getInt(); + // TODO finish deserialization impl + } + + public AbstractCharacter getChar() { + return this.absChar; + } + + public void setChar(AbstractCharacter value) { + this.absChar = value; + } + + public void setCorpse(Corpse value) { + this.corpse = value; + } } diff --git a/src/engine/net/client/msg/LoadStructureMsg.java b/src/engine/net/client/msg/LoadStructureMsg.java index 6584ef83..fe8014d2 100644 --- a/src/engine/net/client/msg/LoadStructureMsg.java +++ b/src/engine/net/client/msg/LoadStructureMsg.java @@ -22,83 +22,83 @@ import java.util.ArrayList; public class LoadStructureMsg extends ClientNetMsg { - private ArrayList structureList; - - /** - * This is the general purpose constructor. - */ - public LoadStructureMsg() { - this(new ArrayList<>()); - } - - /** - * This is the general purpose constructor. - * - * @param structures - */ - public LoadStructureMsg(ArrayList structures) { - super(Protocol.LOADSTRUCTURE); - this.structureList = structures; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public LoadStructureMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.LOADSTRUCTURE, origin, reader); - } - - /** - * @see AbstractNetMsg#getPowerOfTwoBufferSize() - */ - @Override - protected int getPowerOfTwoBufferSize() { - //Larger size for historically larger opcodes - return (18); // 2^16 == 64k - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - for (int i = 0; i < 4; i++) - writer.putInt(0); - - writer.putInt(this.structureList.size()); - - for (Building building:this.structureList){ - Building._serializeForClientMsg(building, writer); - } - writer.putInt(0); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - int size = reader.getInt(); - // TODO finish Deserialize impl - } - - // TODO fix ArrayList Accessability. - public ArrayList getStructureList() { - return this.structureList; - } - - public void addObject(Building obj) { - this.structureList.add(obj); - } - - public int size() { - return this.structureList.size(); - } + private ArrayList structureList; + + /** + * This is the general purpose constructor. + */ + public LoadStructureMsg() { + this(new ArrayList<>()); + } + + /** + * This is the general purpose constructor. + * + * @param structures + */ + public LoadStructureMsg(ArrayList structures) { + super(Protocol.LOADSTRUCTURE); + this.structureList = structures; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public LoadStructureMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.LOADSTRUCTURE, origin, reader); + } + + /** + * @see AbstractNetMsg#getPowerOfTwoBufferSize() + */ + @Override + protected int getPowerOfTwoBufferSize() { + //Larger size for historically larger opcodes + return (18); // 2^16 == 64k + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + for (int i = 0; i < 4; i++) + writer.putInt(0); + + writer.putInt(this.structureList.size()); + + for (Building building : this.structureList) { + Building._serializeForClientMsg(building, writer); + } + writer.putInt(0); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + int size = reader.getInt(); + // TODO finish Deserialize impl + } + + // TODO fix ArrayList Accessability. + public ArrayList getStructureList() { + return this.structureList; + } + + public void addObject(Building obj) { + this.structureList.add(obj); + } + + public int size() { + return this.structureList.size(); + } } diff --git a/src/engine/net/client/msg/LockUnlockDoorMsg.java b/src/engine/net/client/msg/LockUnlockDoorMsg.java index b99f5740..b644be14 100644 --- a/src/engine/net/client/msg/LockUnlockDoorMsg.java +++ b/src/engine/net/client/msg/LockUnlockDoorMsg.java @@ -18,96 +18,94 @@ import engine.net.client.Protocol; public class LockUnlockDoorMsg extends ClientNetMsg { - private int doorID; - private long targetID; - private int unk1; - private int unk2; - - /** - * This is the general purpose constructor. - */ - public LockUnlockDoorMsg() { - super(Protocol.LOCKUNLOCKDOOR); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public LockUnlockDoorMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.LOCKUNLOCKDOOR, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(0); - writer.putInt(doorID); - writer.putLong(targetID); - writer.putInt(unk1); - writer.putInt(unk2); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - reader.getInt(); - this.doorID = reader.getInt(); - this.targetID = reader.getLong(); - this.unk1 = reader.getInt(); - this.unk2 = reader.getInt(); - } - - /** - * @return the unknown1 - */ - public int getDoorID() { - return doorID; - } - - /** - * @param unknown1 - * the unknown1 to set - */ - public void setDoorID(int doorID) { - this.doorID = doorID; - } - - /** - * @return the targetID - */ - public long getTargetID() { - return targetID; - } - - /** - * @param targetID - * the targetID to set - */ - public void setTargetID(long targetID) { - this.targetID = targetID; - } - - public int getUnk1() { - return this.unk1; - } - - public void setUnk1(int value) { - this.unk1 = value; - } - - public int getUnk2() { - return this.unk2; - } - - public void setUnk2(int value) { - this.unk2 = value; - } + private int doorID; + private long targetID; + private int unk1; + private int unk2; + + /** + * This is the general purpose constructor. + */ + public LockUnlockDoorMsg() { + super(Protocol.LOCKUNLOCKDOOR); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public LockUnlockDoorMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.LOCKUNLOCKDOOR, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(0); + writer.putInt(doorID); + writer.putLong(targetID); + writer.putInt(unk1); + writer.putInt(unk2); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.getInt(); + this.doorID = reader.getInt(); + this.targetID = reader.getLong(); + this.unk1 = reader.getInt(); + this.unk2 = reader.getInt(); + } + + /** + * @return the unknown1 + */ + public int getDoorID() { + return doorID; + } + + /** + * @param unknown1 the unknown1 to set + */ + public void setDoorID(int doorID) { + this.doorID = doorID; + } + + /** + * @return the targetID + */ + public long getTargetID() { + return targetID; + } + + /** + * @param targetID the targetID to set + */ + public void setTargetID(long targetID) { + this.targetID = targetID; + } + + public int getUnk1() { + return this.unk1; + } + + public void setUnk1(int value) { + this.unk1 = value; + } + + public int getUnk2() { + return this.unk2; + } + + public void setUnk2(int value) { + this.unk2 = value; + } } diff --git a/src/engine/net/client/msg/LoginToGameServerMsg.java b/src/engine/net/client/msg/LoginToGameServerMsg.java index a25f8fc3..e77639aa 100644 --- a/src/engine/net/client/msg/LoginToGameServerMsg.java +++ b/src/engine/net/client/msg/LoginToGameServerMsg.java @@ -17,90 +17,87 @@ import engine.net.client.Protocol; public class LoginToGameServerMsg extends ClientNetMsg { - private String secKey; - private int Unknown01; - private int Unknown02; - - /** - * This is the general purpose constructor. - */ - public LoginToGameServerMsg() { - super(Protocol.LOGINTOGAMESERVER); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public LoginToGameServerMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.LOGINTOGAMESERVER, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putHexString(this.secKey); - writer.putInt(this.Unknown01); - writer.putInt(this.Unknown02); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.secKey = reader.getHexString(); - - this.Unknown01 = reader.monitorInt(1065353216, "ValidateGameServerMsg 01"); - this.Unknown02 = reader.monitorInt(1065353216, "ValidateGameServerMsg 02"); - } - - /** - * @return the secKey - */ - public String getSecKey() { - return secKey; - } - - /** - * @param secKey - * the secKey to set - */ - public void setSecKey(String secKey) { - this.secKey = secKey; - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return Unknown01; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - Unknown01 = unknown01; - } - - /** - * @return the unknown02 - */ - public int getUnknown02() { - return Unknown02; - } - - /** - * @param unknown02 - * the unknown02 to set - */ - public void setUnknown02(int unknown02) { - Unknown02 = unknown02; - } + private String secKey; + private int Unknown01; + private int Unknown02; + + /** + * This is the general purpose constructor. + */ + public LoginToGameServerMsg() { + super(Protocol.LOGINTOGAMESERVER); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public LoginToGameServerMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.LOGINTOGAMESERVER, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putHexString(this.secKey); + writer.putInt(this.Unknown01); + writer.putInt(this.Unknown02); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.secKey = reader.getHexString(); + + this.Unknown01 = reader.monitorInt(1065353216, "ValidateGameServerMsg 01"); + this.Unknown02 = reader.monitorInt(1065353216, "ValidateGameServerMsg 02"); + } + + /** + * @return the secKey + */ + public String getSecKey() { + return secKey; + } + + /** + * @param secKey the secKey to set + */ + public void setSecKey(String secKey) { + this.secKey = secKey; + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return Unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + Unknown01 = unknown01; + } + + /** + * @return the unknown02 + */ + public int getUnknown02() { + return Unknown02; + } + + /** + * @param unknown02 the unknown02 to set + */ + public void setUnknown02(int unknown02) { + Unknown02 = unknown02; + } } diff --git a/src/engine/net/client/msg/LootMsg.java b/src/engine/net/client/msg/LootMsg.java index ec81e181..f2b8d355 100644 --- a/src/engine/net/client/msg/LootMsg.java +++ b/src/engine/net/client/msg/LootMsg.java @@ -20,248 +20,248 @@ import engine.objects.MobEquipment; public class LootMsg extends ClientNetMsg { - private Item item; - private int sourceType1; - private int sourceID1; - private int targetType; - private int targetID; - private int sourceType2; - private int sourceID2; - - private int unknown01; - private int unknown02; - private int unknown03; - private int unknown04; - private int unknown05; - private byte unknown06 = (byte) 0; - private int unknown07; - private int unknown08; - - private MobEquipment mobEquipment = null; - - /** - * This is the general purpose constructor. - */ - public LootMsg(int sourceType, int sourceID, int targetType, int targetID, Item item) { - super(Protocol.MOVEOBJECTTOCONTAINER); - this.sourceType1 = sourceType; - this.sourceID1 = sourceID; - this.targetType = targetType; - this.targetID = targetID; - this.sourceType2 = sourceType; - this.sourceID2 = sourceID; - this.item = item; - this.unknown01 = 0; - this.unknown02 = 0; - this.unknown03 = 0; - this.unknown04 = 0; - this.unknown05 = 0; - this.unknown07 = 0; - this.unknown08 = 0; - } - - //for MobEquipment - - public LootMsg(int sourceType, int sourceID, int targetType, int targetID, MobEquipment mobEquipment) { - super(Protocol.MOVEOBJECTTOCONTAINER); - this.sourceType1 = sourceType; - this.sourceID1 = sourceID; - this.targetType = targetType; - this.targetID = targetID; - this.sourceType2 = sourceType; - this.sourceID2 = sourceID; - this.item = null; - this.mobEquipment = mobEquipment; - - this.unknown01 = 0; - this.unknown02 = 0; - this.unknown03 = 0; - this.unknown04 = 0; - this.unknown05 = 0; - this.unknown07 = 0; - this.unknown08 = 0; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public LootMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.MOVEOBJECTTOCONTAINER, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - - if (this.item != null) - Item.serializeForClientMsgWithoutSlot(this.item,writer); - else if (this.mobEquipment != null) - try { - MobEquipment._serializeForClientMsg(this.mobEquipment,writer, false); - } catch (SerializationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - writer.putInt(this.sourceType1); - writer.putInt(this.sourceID1); - writer.putInt(this.targetType); - writer.putInt(this.targetID); - writer.putInt(this.sourceType2); - writer.putInt(this.sourceID2); - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - writer.putInt(this.unknown03); - writer.putInt(this.unknown04); - writer.putInt(this.unknown05); - writer.put(this.unknown06); - writer.putInt(this.unknown07); - writer.putInt(this.unknown08); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.item = Item.deserializeFromClientMsg(reader, false); - this.sourceType1 = reader.getInt(); - this.sourceID1 = reader.getInt(); - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - this.sourceType2 = reader.getInt(); - this.sourceID2 = reader.getInt(); - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - this.unknown03 = reader.getInt(); - this.unknown04 = reader.getInt(); - this.unknown05 = reader.getInt(); - this.unknown06 = reader.get(); - this.unknown07 = reader.getInt(); - this.unknown08 = reader.getInt(); - } - - public int getSourceType1() { - return this.sourceType1; - } - - public int getSourceID1() { - return this.sourceID1; - } - - public int getTargetType() { - return this.targetType; - } - - public int getTargetID() { - return this.targetID; - } - - public int getSourceType2() { - return this.sourceType2; - } - - public int getSourceID2() { - return this.sourceID2; - } - - public int getUnknown01() { - return this.unknown01; - } - - public int getUnknown02() { - return this.unknown02; - } - - public int getUnknown03() { - return this.unknown03; - } - - public int getUnknown04() { - return this.unknown04; - } - - public int getUnknown05() { - return this.unknown05; - } - - public byte getUnknown06() { - return this.unknown06; - } - - public int getUnknown07() { - return this.unknown07; - } - - public int getUnknown08() { - return this.unknown08; - } - - public Item getItem() { - return this.item; - } - - public void setUnknown01(int value) { - this.unknown01 = value; - } - - public void setUnknown02(int value) { - this.unknown02 = value; - } - - public void setUnknown03(int value) { - this.unknown03 = value; - } - - public void setUnknown04(int value) { - this.unknown04 = value; - } - - public void setUnknown05(int value) { - this.unknown05 = value; - } - - public void setUnknown06(byte value) { - this.unknown06 = value; - } - - public void setUnknown07(int value) { - this.unknown07 = value; - } - - public void setUnknown08(int value) { - this.unknown08 = value; - } - - public void setSourceType1(int value) { - this.sourceType1 = value; - } - - public void setSourceID1(int value) { - this.sourceID1 = value; - } + private Item item; + private int sourceType1; + private int sourceID1; + private int targetType; + private int targetID; + private int sourceType2; + private int sourceID2; + + private int unknown01; + private int unknown02; + private int unknown03; + private int unknown04; + private int unknown05; + private byte unknown06 = (byte) 0; + private int unknown07; + private int unknown08; + + private MobEquipment mobEquipment = null; + + /** + * This is the general purpose constructor. + */ + public LootMsg(int sourceType, int sourceID, int targetType, int targetID, Item item) { + super(Protocol.MOVEOBJECTTOCONTAINER); + this.sourceType1 = sourceType; + this.sourceID1 = sourceID; + this.targetType = targetType; + this.targetID = targetID; + this.sourceType2 = sourceType; + this.sourceID2 = sourceID; + this.item = item; + this.unknown01 = 0; + this.unknown02 = 0; + this.unknown03 = 0; + this.unknown04 = 0; + this.unknown05 = 0; + this.unknown07 = 0; + this.unknown08 = 0; + } + + //for MobEquipment + + public LootMsg(int sourceType, int sourceID, int targetType, int targetID, MobEquipment mobEquipment) { + super(Protocol.MOVEOBJECTTOCONTAINER); + this.sourceType1 = sourceType; + this.sourceID1 = sourceID; + this.targetType = targetType; + this.targetID = targetID; + this.sourceType2 = sourceType; + this.sourceID2 = sourceID; + this.item = null; + this.mobEquipment = mobEquipment; + + this.unknown01 = 0; + this.unknown02 = 0; + this.unknown03 = 0; + this.unknown04 = 0; + this.unknown05 = 0; + this.unknown07 = 0; + this.unknown08 = 0; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public LootMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.MOVEOBJECTTOCONTAINER, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + + if (this.item != null) + Item.serializeForClientMsgWithoutSlot(this.item, writer); + else if (this.mobEquipment != null) + try { + MobEquipment._serializeForClientMsg(this.mobEquipment, writer, false); + } catch (SerializationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + writer.putInt(this.sourceType1); + writer.putInt(this.sourceID1); + writer.putInt(this.targetType); + writer.putInt(this.targetID); + writer.putInt(this.sourceType2); + writer.putInt(this.sourceID2); + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + writer.putInt(this.unknown03); + writer.putInt(this.unknown04); + writer.putInt(this.unknown05); + writer.put(this.unknown06); + writer.putInt(this.unknown07); + writer.putInt(this.unknown08); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.item = Item.deserializeFromClientMsg(reader, false); + this.sourceType1 = reader.getInt(); + this.sourceID1 = reader.getInt(); + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + this.sourceType2 = reader.getInt(); + this.sourceID2 = reader.getInt(); + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + this.unknown03 = reader.getInt(); + this.unknown04 = reader.getInt(); + this.unknown05 = reader.getInt(); + this.unknown06 = reader.get(); + this.unknown07 = reader.getInt(); + this.unknown08 = reader.getInt(); + } + + public int getSourceType1() { + return this.sourceType1; + } + + public void setSourceType1(int value) { + this.sourceType1 = value; + } + + public int getSourceID1() { + return this.sourceID1; + } + + public void setSourceID1(int value) { + this.sourceID1 = value; + } + + public int getTargetType() { + return this.targetType; + } + + public void setTargetType(int value) { + this.targetType = value; + } + + public int getTargetID() { + return this.targetID; + } + + public void setTargetID(int value) { + this.targetID = value; + } + + public int getSourceType2() { + return this.sourceType2; + } + + public void setSourceType2(int value) { + this.sourceType2 = value; + } + + public int getSourceID2() { + return this.sourceID2; + } + + public void setSourceID2(int value) { + this.sourceID2 = value; + } + + public int getUnknown01() { + return this.unknown01; + } + + public void setUnknown01(int value) { + this.unknown01 = value; + } + + public int getUnknown02() { + return this.unknown02; + } + + public void setUnknown02(int value) { + this.unknown02 = value; + } + + public int getUnknown03() { + return this.unknown03; + } + + public void setUnknown03(int value) { + this.unknown03 = value; + } + + public int getUnknown04() { + return this.unknown04; + } + + public void setUnknown04(int value) { + this.unknown04 = value; + } + + public int getUnknown05() { + return this.unknown05; + } + + public void setUnknown05(int value) { + this.unknown05 = value; + } + + public byte getUnknown06() { + return this.unknown06; + } + + public void setUnknown06(byte value) { + this.unknown06 = value; + } + + public int getUnknown07() { + return this.unknown07; + } - public void setTargetType(int value) { - this.targetType = value; - } + public void setUnknown07(int value) { + this.unknown07 = value; + } - public void setTargetID(int value) { - this.targetID = value; - } + public int getUnknown08() { + return this.unknown08; + } - public void setSourceType2(int value) { - this.sourceType2 = value; - } + public void setUnknown08(int value) { + this.unknown08 = value; + } - public void setSourceID2(int value) { - this.sourceID2 = value; - } + public Item getItem() { + return this.item; + } - public void setItem(Item value) { - this.item = value; - } + public void setItem(Item value) { + this.item = value; + } } diff --git a/src/engine/net/client/msg/LootWindowRequestMsg.java b/src/engine/net/client/msg/LootWindowRequestMsg.java index 5f92be1e..94832bec 100644 --- a/src/engine/net/client/msg/LootWindowRequestMsg.java +++ b/src/engine/net/client/msg/LootWindowRequestMsg.java @@ -17,96 +17,96 @@ import engine.net.client.Protocol; public class LootWindowRequestMsg extends ClientNetMsg { - private int sourceType; - private int sourceID; - private int targetType; - private int targetID; - - /** - * This is the general purpose constructor. - */ - public LootWindowRequestMsg(int sourceType, int sourceID, int targetType, int targetID) { - super(Protocol.REQUESTCONTENTS); - this.sourceType = sourceType; - this.sourceID = sourceID; - this.targetType = targetType; - this.targetID = targetID; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public LootWindowRequestMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.REQUESTCONTENTS, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.putInt(this.targetType); - writer.putInt(this.targetID); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - } - - /** - * @return the sourceType - */ - public int getSourceType() { - return sourceType; - } - - /** - * @return the sourceID - */ - public int getSourceID() { - return sourceID; - } - - /** - * @return the targetType - */ - public int getTargetType() { - return targetType; - } - - /** - * @return the targetID - */ - public int getTargetID() { - return targetID; - } - - public void setSourceType(int value) { - this.sourceType = value; - } - - public void setSourceID(int value) { - this.sourceID = value; - } - - public void setTargetType(int value) { - this.targetType = value; - } - - public void setTargetID(int value) { - this.targetID = value; - } + private int sourceType; + private int sourceID; + private int targetType; + private int targetID; + + /** + * This is the general purpose constructor. + */ + public LootWindowRequestMsg(int sourceType, int sourceID, int targetType, int targetID) { + super(Protocol.REQUESTCONTENTS); + this.sourceType = sourceType; + this.sourceID = sourceID; + this.targetType = targetType; + this.targetID = targetID; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public LootWindowRequestMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.REQUESTCONTENTS, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.putInt(this.targetType); + writer.putInt(this.targetID); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + } + + /** + * @return the sourceType + */ + public int getSourceType() { + return sourceType; + } + + public void setSourceType(int value) { + this.sourceType = value; + } + + /** + * @return the sourceID + */ + public int getSourceID() { + return sourceID; + } + + public void setSourceID(int value) { + this.sourceID = value; + } + + /** + * @return the targetType + */ + public int getTargetType() { + return targetType; + } + + public void setTargetType(int value) { + this.targetType = value; + } + + /** + * @return the targetID + */ + public int getTargetID() { + return targetID; + } + + public void setTargetID(int value) { + this.targetID = value; + } } diff --git a/src/engine/net/client/msg/LootWindowResponseMsg.java b/src/engine/net/client/msg/LootWindowResponseMsg.java index 408ae77c..c6d42530 100644 --- a/src/engine/net/client/msg/LootWindowResponseMsg.java +++ b/src/engine/net/client/msg/LootWindowResponseMsg.java @@ -21,85 +21,85 @@ import java.util.ArrayList; public class LootWindowResponseMsg extends ClientNetMsg { - private int targetType; - private int targetID; - private ArrayList inventory; - private int unknown01 = 45; - - /** - * This is the general purpose constructor. - */ - public LootWindowResponseMsg(int targetType, int targetID, ArrayList inventory) { - super(Protocol.WEIGHTINVENTORY); - this.targetType = targetType; - this.targetID = targetID; - this.inventory = inventory; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public LootWindowResponseMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.WEIGHTINVENTORY, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.put((byte) 1); - Item.putList(writer, this.inventory, false, this.targetID); - writer.putInt(this.unknown01); - writer.putInt(this.targetType); - writer.putInt(this.targetID); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - } - - public int getUnknown01() { - return this.unknown01; - } - - public int getTargetType() { - return targetType; - } - - public int getTargetID() { - return targetID; - } - - public ArrayList getInventory() { - return this.inventory; - } - - public void setUnknown01(int value) { - this.unknown01 = value; - } - - public void setTargetType(int value) { - this.targetType = value; - } - - public void setTargetID(int value) { - this.targetID = value; - } - - public void setInventory(ArrayList value) { - this.inventory = value; - } - - @Override - protected int getPowerOfTwoBufferSize() { - // Larger size for historically larger opcodes - return 17; // 2^15 == 32,768 - } + private int targetType; + private int targetID; + private ArrayList inventory; + private int unknown01 = 45; + + /** + * This is the general purpose constructor. + */ + public LootWindowResponseMsg(int targetType, int targetID, ArrayList inventory) { + super(Protocol.WEIGHTINVENTORY); + this.targetType = targetType; + this.targetID = targetID; + this.inventory = inventory; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public LootWindowResponseMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.WEIGHTINVENTORY, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.put((byte) 1); + Item.putList(writer, this.inventory, false, this.targetID); + writer.putInt(this.unknown01); + writer.putInt(this.targetType); + writer.putInt(this.targetID); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + } + + public int getUnknown01() { + return this.unknown01; + } + + public void setUnknown01(int value) { + this.unknown01 = value; + } + + public int getTargetType() { + return targetType; + } + + public void setTargetType(int value) { + this.targetType = value; + } + + public int getTargetID() { + return targetID; + } + + public void setTargetID(int value) { + this.targetID = value; + } + + public ArrayList getInventory() { + return this.inventory; + } + + public void setInventory(ArrayList value) { + this.inventory = value; + } + + @Override + protected int getPowerOfTwoBufferSize() { + // Larger size for historically larger opcodes + return 17; // 2^15 == 32,768 + } } diff --git a/src/engine/net/client/msg/ManageCityAssetsMsg.java b/src/engine/net/client/msg/ManageCityAssetsMsg.java index f02a1cb9..473082b2 100644 --- a/src/engine/net/client/msg/ManageCityAssetsMsg.java +++ b/src/engine/net/client/msg/ManageCityAssetsMsg.java @@ -31,840 +31,822 @@ import java.util.concurrent.ConcurrentHashMap; */ public class ManageCityAssetsMsg extends ClientNetMsg { - //messageType - //C->S 2: S->C: 0, 3, 4, 6 - //C->S 15: S->C: 15 - //C->S 14: S->C: 14 - //C->S ?: S->C: 10, 11, 16 - - //C->S 2 = manage this asset - // 20 = manage entire city - - //S->C, 0 = error message - // 3 = manage asset - // 4 = no access / building info - - public int actionType; - private int targetID; - private int targetType; - private int targetType1; - private int targetType2; - private int targetType3; - private int targetID1; - private int targetID2; - private int targetID3; - public String assetName; - private String AssetName1; - public String CityName; - private int rank; - private int symbol; - public int upgradeCost; - private int unknown04; - private int unknown05; - private int unknown06; - private int unknown07; - private int unknown14; - private int unknown15; - private int unknown16; - private int unknown17; - private int unknown54; - private int preName01; - - private byte UnkByte03; - private byte UnkByte04; - private int strongbox; - - private int baneHour; - private PlayerCharacter assetManager; - private Building asset; - public byte labelProtected; - public byte labelSiege; - public byte labelCeaseFire; - public byte buttonTransfer; - public byte buttonDestroy; - public byte buttonAbandon; - public byte buttonUpgrade; - - /** - * This is the general purpose constructor - */ - public ManageCityAssetsMsg() { - super(Protocol.MANAGECITYASSETS); - this.actionType = 0; - this.targetType = 0; - this.targetID = 0; - this.preName01 = 0; - this.assetName = ""; - this.CityName = ""; - this.rank = 0; - this.symbol = 0; - this.unknown04 = 0; - this.unknown06 = 0; - this.unknown07 = 0; - this.unknown14 = 0; - this.unknown15 = 0; - this.unknown16 = 0; - this.unknown17 = 0; - - this.strongbox = 0; - - this.targetType1 = 0; - this.targetType2 = 0; - this.targetType3 = 0; - - this.targetID1 = 0; - this.targetID2 = 0; - this.targetID3 = 0; - this.UnkByte03 = 0; - this.UnkByte04 = 0; - this.AssetName1 = ""; - this.unknown54 = 0; - this.strongbox = 0; - this.upgradeCost = 0; - - this.labelProtected = 0; - this.labelSiege = 0; - this.labelCeaseFire = 0; - this.buttonTransfer = 0; - this.buttonDestroy = 0; - this.buttonAbandon = 0; - this.buttonUpgrade = 0; - - } - - public ManageCityAssetsMsg(PlayerCharacter pc, Building asset) { - super(Protocol.MANAGECITYASSETS); - this.assetManager = pc; - this.asset = asset; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public ManageCityAssetsMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.MANAGECITYASSETS, origin, reader); - } - - public int getTargetID() { - return targetID; - } - - protected int getPowerOfTwoBufferSize() { - return (20); // 2^10 == 1024 - } - public void setTargetID(int targetID) { - this.targetID = targetID; - } - - public int getTargetType() { - return targetType; - } - - public void setTargetType(int targetType) { - this.targetType = targetType; - } - - public void setTargetType3(int targetType3) { - this.targetType3 = targetType3; - } - - public void setTargetID3(int targetID3) { - this.targetID3 = targetID3; - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - actionType = reader.getInt(); - targetType = reader.getInt(); - targetID = reader.getInt(); - if (this.actionType == 20) { - reader.getInt(); - this.baneHour = reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - - } else if (this.actionType == 5) { //rename building. - reader.getInt(); - assetName = reader.getString(); - for (int i = 0; i < 5; i++) - reader.getInt(); - } else if (this.actionType == 2) { - reader.getInt(); - this.strongbox = reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - - - }else{ - for (int i = 0; i < 6; i++) - reader.getInt(); - } - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.actionType); - - if (this.actionType == 2) { - writer.putInt(asset.getObjectType().ordinal()); - writer.putInt(asset.getObjectUUID()); - writer.putInt(0); - writer.putInt(asset.reserve); - writer.putInt(0); - return; - } - - if (this.actionType == 13) { - writer.putInt(asset.getObjectType().ordinal()); - writer.putInt(asset.getObjectUUID()); - writer.putInt(0); - writer.putInt(0); - writer.putInt(asset.getHirelings().size()); - for (AbstractCharacter hireling : asset.getHirelings().keySet()){ - if (!hireling.getObjectType().equals(GameObjectType.NPC)) - writer.putString(hireling.getName()); - else{ - NPC npc = (NPC)hireling; - if (!npc.getNameOverride().isEmpty()){ - writer.putString(npc.getNameOverride()); - }else - - if (npc.getContract() != null) { - if (npc.getContract().isTrainer()) { - writer.putString(npc.getName() + ", " + npc.getContract().getName()); - } else { - writer.putString(npc.getName() + " " + npc.getContract().getName()); - } - } else { - writer.putString(npc.getName()); - } - } - } - - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - } - - //Bane window - - if (this.actionType == 11) { - writer.putInt(asset.getObjectType().ordinal()); - writer.putInt(asset.getObjectUUID()); - for (int a = 0;a<5;a++) - writer.putInt(0); - - writer.putInt(asset.getHirelings().size()); - - for (AbstractCharacter npcHire : asset.getHirelings().keySet()) { - writer.putInt(npcHire.getObjectType().ordinal()); - writer.putInt(npcHire.getObjectUUID()); - if (npcHire.getObjectType() == GameObjectType.NPC) - writer.putString(((NPC)npcHire).getContract().getName()); - else - writer.putString("Guard Captain"); - - - writer.putString(npcHire.getName()); - writer.putInt(1); - writer.putInt(Blueprint.getNpcMaintCost(npcHire.getRank())); - if (npcHire.getObjectType() == GameObjectType.NPC) - writer.putInt(((NPC)npcHire).getContract().getIconID()); // Was 60 - else if (npcHire.getObjectType() == GameObjectType.Mob){ - writer.putInt(((Mob)npcHire).getContract().getIconID()); // Was 60 - } - else - writer.putInt(5); - writer.put((byte) 0); - writer.put((byte) 0); - writer.put((byte) 1); - writer.put((byte) 0); - writer.put((byte) 0); - } - return; - } - - if (this.actionType == 15) { - writer.putInt(1); - writer.putInt(1); - City city = null; - Zone playerZone = ZoneManager.findSmallestZone(assetManager.getLoc()); - Set buildings = ZoneManager.findSmallestZone(assetManager.getLoc()).zoneBuildingSet; - - Building tol = null; - if (playerZone.getPlayerCityUUID() != 0) - city = City.GetCityFromCache(playerZone.getPlayerCityUUID()); - - if (city != null) - tol = city.getTOL(); - - - - writer.putInt(0); // 1 + String = custom message, cant control assets. - writer.putInt(0); - writer.putInt(0); //array - - writer.putInt(buildings.size()); - - int i = 0; - for (Building building: buildings){ - - i++; - writer.putString(building.getName()); //ARRAY - writer.putInt(building.getObjectType().ordinal()); //? - writer.putInt(building.getObjectUUID()); //? - - writer.putInt(4); - writer.putInt(4); - - writer.put((byte)0); - writer.put((byte)0); - writer.put((byte)1); - writer.put((byte)1); - - //max distance to bypass clientside check. - float maxDistance = 2000; - - - writer.putFloat(maxDistance); - - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - - if (building.getPatrolPoints() != null){ - writer.putInt(building.getPatrolPoints().size()); - for (Vector3fImmutable patrolPoint: building.getPatrolPoints()){ - writer.putVector3f(patrolPoint); - } - }else{ - writer.putInt(0); - } - writer.putInt(0); //Sentry Point - - if (building.getBlueprint() != null && building.getBlueprint().getBuildingGroup() == BuildingGroup.BARRACK){ - writer.putInt(1); //Tab left Random Town? //Opens up 16 Bytes - writer.putInt(4); - writer.putInt(0); - writer.putInt(0); - writer.putInt(4); - }else - writer.putInt(0); - writer.putInt(0); //array with size 32 bytes. // Adds information of building - } - writer.putInt(0); //ARRAY - writer.putInt(0); - } - - if (this.actionType == 18) { - Zone zone = asset.getParentZone(); - - if (zone == null) - return; - - City banedCity = City.getCity(zone.getPlayerCityUUID()); - - if (banedCity == null) - return; - - Bane bane = banedCity.getBane(); - - if (bane == null) - return; - - Guild attackerGuild = bane.getOwner().getGuild(); - - if (attackerGuild == null) - return; - - writer.putInt(asset.getObjectType().ordinal()); - writer.putInt(asset.getObjectUUID()); - - writer.putInt(0); - writer.putString(attackerGuild.getName()); - writer.putString(Guild.GetGL(attackerGuild).getName()); - writer.putInt(bane.getSiegePhase().ordinal()); //1 challenge //2 standoff //3 war - writer.put((byte) 0); - - if (!bane.isAccepted() && this.assetManager.getGuild() == banedCity.getGuild() && GuildStatusController.isInnerCouncil(this.assetManager.getGuildStatus())) - writer.put((byte) 1); //canSetTime - else - writer.put((byte) 0); - - DateTime placedOn = bane.getLiveDate(); - - if (placedOn == null) - placedOn = new DateTime(DateTime.now()); - - //set Calander to date of bane live. - DateTime now = DateTime.now(); - DateTime defaultTime = new DateTime(bane.getPlacementDate()); - DateTime playerEnterWorldTime = new DateTime(this.assetManager.getTimeStamp("EnterWorld")); - Period period = new Period(playerEnterWorldTime.getMillis(), now.getMillis()); - int hoursLoggedIn = period.getHours(); - hoursLoggedIn = hoursLoggedIn < 0 ? 0 : hoursLoggedIn; - - defaultTime = defaultTime.plusDays(2); - defaultTime = defaultTime.hourOfDay().setCopy(22); - defaultTime = defaultTime.minuteOfHour().setCopy(0); - defaultTime = defaultTime.secondOfMinute().setCopy(0); - - long curTime = now.getMillis(); - long timeLeft = 0; - - if (bane.getLiveDate() != null) - timeLeft = bane.getLiveDate().getMillis() - curTime; - else - timeLeft = defaultTime.getMillis() - curTime + 1000; - - //DO not touch these. They are static formula's until i get the correct converter for SB Time. - - writer.put((byte) placedOn.dayOfMonth().get()); - writer.put((byte) placedOn.monthOfYear().get()); - writer.putInt(placedOn.year().get() - 1900); - writer.put((byte) 0); - writer.put((byte) 0); - writer.put((byte) 0); - - if (timeLeft < 0) - writer.putInt(0); - else - writer.putInt((int) timeLeft / 1000); // Time remaing until bane/Seconds - - if (attackerGuild.getGuildState() == GuildState.Sworn) - writer.putInt(4); //3 capture/errant,4 capture/sworn, 5 destroy/soveirgn. - else - writer.putInt(5); - - writer.put((byte) (16 - hoursLoggedIn)); // hour start - writer.put((byte) (24 - hoursLoggedIn)); // hour end - writer.put((byte) 2); - writer.putString(banedCity.getCityName()); - writer.putString(Guild.GetGL(bane.getOwner().getGuild()) != null ? Guild.GetGL(bane.getOwner().getGuild()).getName() : "No Guild Leader"); - GuildTag._serializeForDisplay(attackerGuild.getGuildTag(),writer); - GuildTag._serializeForDisplay(attackerGuild.getNation().getGuildTag(),writer); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - } - - if (this.actionType == 3) { - - writer.putInt(targetType); - writer.putInt(targetID); - - Guild nation = null; - Building building = BuildingManager.getBuildingFromCache(targetID); - Guild guild = building.getGuild(); - Zone zone = ZoneManager.findSmallestZone(building.getLoc()); - - writer.putInt(0);//unknown Might be to allow manager to open or not! - writer.putString(building.getName()); - - AbstractCharacter buildingOwner = building.getOwner(); - - if (buildingOwner == null) - writer.putString("Morloch"); - else - writer.putString(buildingOwner.getName()); - - if (zone == null) - writer.putString("Forlord"); - else - writer.putString(zone.getName()); - - writer.putString(building.getGuild().getName()); - - writer.putInt(building.getRank()); - - // Maintenance costs include resource if - // this structure is an R8 tree - - if (building.getRank() == 8) - writer.putInt(5); // Resources included - else - writer.putInt(1); // Gold only - - writer.putInt(2308551); //Gold - if (building.getBlueprint() == null) - writer.putInt(0); - else - writer.putInt(building.getBlueprint().getMaintCost(building.getRank())); // maint cost - - if (building.getRank() == 8) { - writer.putInt(74856115); // Stone - writer.putInt(1500); // maint cost - writer.putInt(-1603256692); // Lumber - writer.putInt(1500); // maint cost - writer.putInt(-1596311545); // Galvor - writer.putInt(5); // maint cost - writer.putInt(1532478436); // Wormwood - writer.putInt(5); // maint cost - } - - LocalDateTime maintDate = building.maintDateTime; - - if (maintDate == null) - maintDate = LocalDateTime.now(); - writer.putLocalDateTime(LocalDateTime.now()); // current time - - // utc offset? - writer.putInt((int)java.time.Duration.between(LocalDateTime.now(), maintDate).getSeconds()); // Seconds to maint date - - writer.putInt(building.getStrongboxValue()); - writer.putInt(building.reserve);//reserve Sets the buildings reserve display - writer.putInt(0);//prosperity under maintenance (wtf is prosperity?) - writer.putInt(10); - writer.putFloat((float) .1); - - if (this.buttonUpgrade == 1) { - if (building.getBlueprint() == null) - this.upgradeCost = Integer.MAX_VALUE; - else - if (building.getRank() == building.getBlueprint().getMaxRank()) - this.upgradeCost = Integer.MAX_VALUE; - else - this.upgradeCost = building.getBlueprint().getRankCost(Math.min(building.getRank() + 1, 7)); - - writer.putInt(this.upgradeCost); - } - else - writer.putInt(0); - - LocalDateTime uc = LocalDateTime.now(); - - if (building.getDateToUpgrade() != null) - uc = building.getDateToUpgrade(); - - long timeLeft = uc.atZone(ZoneId.systemDefault()) - .toInstant().toEpochMilli() - System.currentTimeMillis(); - long hour = timeLeft / 3600000; - long noHour = timeLeft - (hour * 3600000); - long minute = noHour / 60000; - long noMinute = noHour - (minute * 60000); - long second = noMinute / 1000; - - writer.put((byte) 0);//Has to do with repair time. A 1 here puts 23.9 hours in repair time A 2 here is 1.9 days - writer.put((byte) 0);//unknown - writer.putInt(0); //unknown - - if (LocalDateTime.now().isAfter(uc)) { - writer.put((byte) 0); - writer.put((byte) 0); - writer.put((byte) 0); - } - else { - writer.put((byte) (hour)); - writer.put((byte) minute); - writer.put((byte) second); - } - - if (timeLeft < 0) - writer.putInt(0); - else - writer.putInt((int) timeLeft); - - writer.putInt((int) building.getCurrentHitpoints()); - writer.putInt((int) building.getMaxHitPoints()); - writer.putInt(BuildingManager.GetRepairCost(building));//sets the repair cost. - writer.putInt(0);//unknown - - if (building.getBlueprint() == null) - writer.putInt(0); - else - writer.putInt(building.getBlueprint().getSlotsForRank(building.getRank())); - writer.put((byte) 1);//Has to do with removing update timer and putting in cost for upgrade - - writer.put(labelProtected); // 1 sets protection to invulnerable. - writer.put(labelSiege);// 1 sets the protection under siege - writer.put(labelCeaseFire); //0 with 1 set above sets to under siege // 1 with 1 set above sets protection status to under siege(cease fire) - - writer.put(buttonTransfer);// 1 enables the transfer asset button - writer.put(buttonDestroy);// 1 enables the destroy asset button - writer.put(buttonAbandon);// 1 here enables the abandon asset button - writer.put(buttonUpgrade); //disable upgrade building - - if (building.getBlueprint() == null) - writer.putInt(0); - else - writer.putInt(building.getBlueprint().getIcon()); //Symbol - - if (guild == null) { - for (int i = 0; i < 3; i++) - writer.putInt(16); - for (int i = 0; i < 2; i++) - writer.putInt(0); - } - else { - GuildTag._serializeForDisplay(guild.getGuildTag(),writer); - nation = guild.getNation(); - } - - if (nation == null) { - for (int i = 0; i < 3; i++) - writer.putInt(16); - for (int i = 0; i < 2; i++) - writer.putInt(0); - } - else { - GuildTag._serializeForDisplay(nation.getGuildTag(),writer); - } - writer.putInt(0); - writer.putInt(0); - writer.putInt(0);//1 makes it so manage window does not open. - - if (!building.assetIsProtected() && !building.getProtectionState().equals(ProtectionState.PENDING)){ - writer.putInt(0); - } - else{ - writer.putInt(1); //kos on/off? - writer.putInt(3); // was 3 - if (zone.getPlayerCityUUID() != 0 && asset.assetIsProtected()){ - writer.putInt(GameObjectType.Building.ordinal()); - writer.putInt(City.getCity(zone.getPlayerCityUUID()).getTOL().getObjectUUID()); - } - else{ - writer.putInt(0); - writer.putInt(0); - } - - writer.putInt(0); - writer.putInt(0); - - writer.putInt(targetType3); - writer.putInt(targetID3); - - - if (building.getProtectionState() == ProtectionState.PENDING) - writer.put((byte)1); //Accept or decline. - else - writer.put((byte)0); - - if (building.taxType == TaxType.NONE) - writer.put((byte)0); //? ?? - else if(building.taxDateTime != null) - writer.put((byte)1); - else - writer.put((byte)0); - - writer.putString(""); //tree of life protection tax - writer.putInt(0); //?? - writer.putInt(0); //?? - if (building.taxType == TaxType.NONE){ - writer.putInt(0); - writer.putInt(0); - }else if (building.taxType == TaxType.WEEKLY){ - writer.putInt(building.taxAmount); - writer.putInt(0); - }else{ - writer.putInt(0); - writer.putInt(building.taxAmount); - } - - - writer.put(building.enforceKOS ? (byte)1:0); //enforceKOS - writer.put((byte) 0); //? - writer.putInt(1); - } - - - - ConcurrentHashMap npcList = building.getHirelings(); - writer.putInt(npcList.size()); - if (npcList.size() > 0) { - for (AbstractCharacter npcHire : npcList.keySet()) { - writer.putInt(npcHire.getObjectType().ordinal()); - if (npcHire.getObjectType() == GameObjectType.Mob) - writer.putInt(((Mob)npcHire).getDBID()); - else - writer.putInt(npcHire.getObjectUUID()); - if (npcHire.getObjectType() == GameObjectType.NPC) { - writer.putString(((NPC) npcHire).getContract().getName()); - writer.putString(npcHire.getName()); - } - else if (npcHire.getObjectType() == GameObjectType.Mob) { - writer.putString(((Mob) npcHire).getContract().getName()); - if (((Mob) npcHire).getNameOverride().length() > 0) { - writer.putString(((Mob) npcHire).getNameOverride()); - } else { - writer.putString(npcHire.getName()); - } - }else - writer.putString("Error: Nothing Here"); - writer.putInt(npcHire.getRank()); - writer.putInt(Blueprint.getNpcMaintCost(npcHire.getRank())); - if (npcHire.getObjectType() == GameObjectType.NPC) - writer.putInt(((NPC)npcHire).getContract().getIconID()); // Was 60 - else if (npcHire.getObjectType() == GameObjectType.Mob) - writer.putInt(((Mob)npcHire).getContract().getIconID()); // Was 60 - - int contractID = 0; - - - if (npcHire.getObjectType() == GameObjectType.Mob) - contractID = ((Mob)npcHire).getContract().getContractID(); - else if (npcHire.getObjectType() == GameObjectType.NPC) - contractID = ((NPC)npcHire).getContract().getContractID(); - - if (contractID ==830){ - writer.putInt(24580); - } - else if (building.getBlueprint() != null && (building.getBlueprint().getBuildingGroup() == BuildingGroup.FORGE ||building.getBlueprint().getBuildingGroup() == BuildingGroup.MAGICSHOP||building.getBlueprint().getBuildingGroup() == BuildingGroup.TAILOR)){ - - writer.put((byte)0); - writer.put((byte)4); - writer.put((byte)128); - writer.put((byte)0); - - }else{ - writer.put((byte)0); - if (building.getBlueprint() != null && building.getBlueprint().getBuildingGroup() == BuildingGroup.BARRACK) - writer.put((byte)1); - else - writer.put((byte)0); - writer.put((byte)0); - writer.put((byte)0); - } - - - if (!npcHire.isAlive()){ - writer.put((byte) 1); // 1 SHOWs respawning - int respawnRemaining = (int)(((Mob)npcHire).deathTime + ((Mob)npcHire).spawnTime * 1000 - System.currentTimeMillis()) / 1000; - writer.putInt(respawnRemaining); // Seconds in respawn remaining. - writer.putInt(((Mob)npcHire).spawnTime); // max seconds for respawn - } - else - writer.put((byte)0); - - } - } - } - if (this.actionType == 4) { - writer.putInt(targetType); - writer.putInt(targetID); - Building building = BuildingManager.getBuildingFromCache(targetID); - - writer.putInt(preName01); - writer.putString(building.getName()); //assetName - writer.putString(building.getOwnerName()); //ownerName - writer.putString(building.getGuild().getName());//guild name - writer.putString(building.getCityName()); //City Name - writer.putInt(building.getRank()); - if (building.getBlueprint() == null) - writer.putInt(0); - else - writer.putInt(building.getBlueprint().getIcon()); - - //tags - GuildTag._serializeForDisplay(building.getGuild().getGuildTag(), writer); - GuildTag._serializeForDisplay(building.getGuild().getNation().getGuildTag(), writer); - - writer.putInt(unknown14); - writer.putInt(unknown15); - writer.putInt(unknown16); - writer.putInt(unknown17); - writer.putInt(0); // previously uninitialized unknown18 - } - } - - public int getRank() { - return rank; - } - - public void setRank(int rank) { - this.rank = rank; - } - - public int getSymbol() { - return symbol; - } - - public void setSymbol(int symbol) { - this.symbol = symbol; - } - - public int getUnknown04() { - return unknown04; - } - - public void setUnknown04(int unknown04) { - this.unknown04 = unknown04; - } - - public int getUnknown05() { - return unknown05; - } - - public void setUnknown05(int unknown05) { - this.unknown05 = unknown05; - } - - public int getUnknown06() { - return unknown06; - } - - public void setUnknown06(int unknown06) { - this.unknown06 = unknown06; - } - - public void setUnknown07(int unknown07) { - this.unknown07 = unknown07; - } - - public String getAssetName() { - return assetName; - } - - public void setAssetName(String AssetName) { - this.assetName = AssetName; - } - - public void setAssetName1(String AssetName1) { - this.AssetName1 = AssetName1; - } - - public String getCityName() { - return CityName; - } - - public void setUnknown54(int unknown54) { - this.unknown54 = unknown54; - } - - public int getStrongbox() { - return strongbox; - } - - public void setStrongbox(int strongbox) { - this.strongbox = strongbox; - } - - public int getBaneHour() { - return baneHour; - } - - public Building getAsset() { - return asset; - } - - public void setAsset(Building asset) { - this.asset = asset; - } + //messageType + //C->S 2: S->C: 0, 3, 4, 6 + //C->S 15: S->C: 15 + //C->S 14: S->C: 14 + //C->S ?: S->C: 10, 11, 16 + + //C->S 2 = manage this asset + // 20 = manage entire city + + //S->C, 0 = error message + // 3 = manage asset + // 4 = no access / building info + + public int actionType; + public String assetName; + public String CityName; + public int upgradeCost; + public byte labelProtected; + public byte labelSiege; + public byte labelCeaseFire; + public byte buttonTransfer; + public byte buttonDestroy; + public byte buttonAbandon; + public byte buttonUpgrade; + private int targetID; + private int targetType; + private int targetType1; + private int targetType2; + private int targetType3; + private int targetID1; + private int targetID2; + private int targetID3; + private String AssetName1; + private int rank; + private int symbol; + private int unknown04; + private int unknown05; + private int unknown06; + private int unknown07; + private int unknown14; + private int unknown15; + private int unknown16; + private int unknown17; + private int unknown54; + private int preName01; + private byte UnkByte03; + private byte UnkByte04; + private int strongbox; + private int baneHour; + private PlayerCharacter assetManager; + private Building asset; + + /** + * This is the general purpose constructor + */ + public ManageCityAssetsMsg() { + super(Protocol.MANAGECITYASSETS); + this.actionType = 0; + this.targetType = 0; + this.targetID = 0; + this.preName01 = 0; + this.assetName = ""; + this.CityName = ""; + this.rank = 0; + this.symbol = 0; + this.unknown04 = 0; + this.unknown06 = 0; + this.unknown07 = 0; + this.unknown14 = 0; + this.unknown15 = 0; + this.unknown16 = 0; + this.unknown17 = 0; + + this.strongbox = 0; + + this.targetType1 = 0; + this.targetType2 = 0; + this.targetType3 = 0; + + this.targetID1 = 0; + this.targetID2 = 0; + this.targetID3 = 0; + this.UnkByte03 = 0; + this.UnkByte04 = 0; + this.AssetName1 = ""; + this.unknown54 = 0; + this.strongbox = 0; + this.upgradeCost = 0; + + this.labelProtected = 0; + this.labelSiege = 0; + this.labelCeaseFire = 0; + this.buttonTransfer = 0; + this.buttonDestroy = 0; + this.buttonAbandon = 0; + this.buttonUpgrade = 0; + + } + + public ManageCityAssetsMsg(PlayerCharacter pc, Building asset) { + super(Protocol.MANAGECITYASSETS); + this.assetManager = pc; + this.asset = asset; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public ManageCityAssetsMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.MANAGECITYASSETS, origin, reader); + } + + public int getTargetID() { + return targetID; + } + + public void setTargetID(int targetID) { + this.targetID = targetID; + } + + protected int getPowerOfTwoBufferSize() { + return (20); // 2^10 == 1024 + } + + public int getTargetType() { + return targetType; + } + + public void setTargetType(int targetType) { + this.targetType = targetType; + } + + public void setTargetType3(int targetType3) { + this.targetType3 = targetType3; + } + + public void setTargetID3(int targetID3) { + this.targetID3 = targetID3; + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + actionType = reader.getInt(); + targetType = reader.getInt(); + targetID = reader.getInt(); + if (this.actionType == 20) { + reader.getInt(); + this.baneHour = reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + + } else if (this.actionType == 5) { //rename building. + reader.getInt(); + assetName = reader.getString(); + for (int i = 0; i < 5; i++) + reader.getInt(); + } else if (this.actionType == 2) { + reader.getInt(); + this.strongbox = reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + + + } else { + for (int i = 0; i < 6; i++) + reader.getInt(); + } + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.actionType); + + if (this.actionType == 2) { + writer.putInt(asset.getObjectType().ordinal()); + writer.putInt(asset.getObjectUUID()); + writer.putInt(0); + writer.putInt(asset.reserve); + writer.putInt(0); + return; + } + + if (this.actionType == 13) { + writer.putInt(asset.getObjectType().ordinal()); + writer.putInt(asset.getObjectUUID()); + writer.putInt(0); + writer.putInt(0); + writer.putInt(asset.getHirelings().size()); + for (AbstractCharacter hireling : asset.getHirelings().keySet()) { + if (!hireling.getObjectType().equals(GameObjectType.NPC)) + writer.putString(hireling.getName()); + else { + NPC npc = (NPC) hireling; + if (!npc.getNameOverride().isEmpty()) { + writer.putString(npc.getNameOverride()); + } else if (npc.getContract() != null) { + if (npc.getContract().isTrainer()) { + writer.putString(npc.getName() + ", " + npc.getContract().getName()); + } else { + writer.putString(npc.getName() + " " + npc.getContract().getName()); + } + } else { + writer.putString(npc.getName()); + } + } + } + + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + } + + //Bane window + + if (this.actionType == 11) { + writer.putInt(asset.getObjectType().ordinal()); + writer.putInt(asset.getObjectUUID()); + for (int a = 0; a < 5; a++) + writer.putInt(0); + + writer.putInt(asset.getHirelings().size()); + + for (AbstractCharacter npcHire : asset.getHirelings().keySet()) { + writer.putInt(npcHire.getObjectType().ordinal()); + writer.putInt(npcHire.getObjectUUID()); + if (npcHire.getObjectType() == GameObjectType.NPC) + writer.putString(((NPC) npcHire).getContract().getName()); + else + writer.putString("Guard Captain"); + + + writer.putString(npcHire.getName()); + writer.putInt(1); + writer.putInt(Blueprint.getNpcMaintCost(npcHire.getRank())); + if (npcHire.getObjectType() == GameObjectType.NPC) + writer.putInt(((NPC) npcHire).getContract().getIconID()); // Was 60 + else if (npcHire.getObjectType() == GameObjectType.Mob) { + writer.putInt(((Mob) npcHire).getContract().getIconID()); // Was 60 + } else + writer.putInt(5); + writer.put((byte) 0); + writer.put((byte) 0); + writer.put((byte) 1); + writer.put((byte) 0); + writer.put((byte) 0); + } + return; + } + + if (this.actionType == 15) { + writer.putInt(1); + writer.putInt(1); + City city = null; + Zone playerZone = ZoneManager.findSmallestZone(assetManager.getLoc()); + Set buildings = ZoneManager.findSmallestZone(assetManager.getLoc()).zoneBuildingSet; + + Building tol = null; + if (playerZone.getPlayerCityUUID() != 0) + city = City.GetCityFromCache(playerZone.getPlayerCityUUID()); + + if (city != null) + tol = city.getTOL(); + + + writer.putInt(0); // 1 + String = custom message, cant control assets. + writer.putInt(0); + writer.putInt(0); //array + + writer.putInt(buildings.size()); + + int i = 0; + for (Building building : buildings) { + + i++; + writer.putString(building.getName()); //ARRAY + writer.putInt(building.getObjectType().ordinal()); //? + writer.putInt(building.getObjectUUID()); //? + + writer.putInt(4); + writer.putInt(4); + + writer.put((byte) 0); + writer.put((byte) 0); + writer.put((byte) 1); + writer.put((byte) 1); + + //max distance to bypass clientside check. + float maxDistance = 2000; + + + writer.putFloat(maxDistance); + + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + + if (building.getPatrolPoints() != null) { + writer.putInt(building.getPatrolPoints().size()); + for (Vector3fImmutable patrolPoint : building.getPatrolPoints()) { + writer.putVector3f(patrolPoint); + } + } else { + writer.putInt(0); + } + writer.putInt(0); //Sentry Point + + if (building.getBlueprint() != null && building.getBlueprint().getBuildingGroup() == BuildingGroup.BARRACK) { + writer.putInt(1); //Tab left Random Town? //Opens up 16 Bytes + writer.putInt(4); + writer.putInt(0); + writer.putInt(0); + writer.putInt(4); + } else + writer.putInt(0); + writer.putInt(0); //array with size 32 bytes. // Adds information of building + } + writer.putInt(0); //ARRAY + writer.putInt(0); + } + + if (this.actionType == 18) { + Zone zone = asset.getParentZone(); + + if (zone == null) + return; + + City banedCity = City.getCity(zone.getPlayerCityUUID()); + + if (banedCity == null) + return; + + Bane bane = banedCity.getBane(); + + if (bane == null) + return; + + Guild attackerGuild = bane.getOwner().getGuild(); + + if (attackerGuild == null) + return; + + writer.putInt(asset.getObjectType().ordinal()); + writer.putInt(asset.getObjectUUID()); + + writer.putInt(0); + writer.putString(attackerGuild.getName()); + writer.putString(Guild.GetGL(attackerGuild).getName()); + writer.putInt(bane.getSiegePhase().ordinal()); //1 challenge //2 standoff //3 war + writer.put((byte) 0); + + if (!bane.isAccepted() && this.assetManager.getGuild() == banedCity.getGuild() && GuildStatusController.isInnerCouncil(this.assetManager.getGuildStatus())) + writer.put((byte) 1); //canSetTime + else + writer.put((byte) 0); + + DateTime placedOn = bane.getLiveDate(); + + if (placedOn == null) + placedOn = new DateTime(DateTime.now()); + + //set Calander to date of bane live. + DateTime now = DateTime.now(); + DateTime defaultTime = new DateTime(bane.getPlacementDate()); + DateTime playerEnterWorldTime = new DateTime(this.assetManager.getTimeStamp("EnterWorld")); + Period period = new Period(playerEnterWorldTime.getMillis(), now.getMillis()); + int hoursLoggedIn = period.getHours(); + hoursLoggedIn = hoursLoggedIn < 0 ? 0 : hoursLoggedIn; + + defaultTime = defaultTime.plusDays(2); + defaultTime = defaultTime.hourOfDay().setCopy(22); + defaultTime = defaultTime.minuteOfHour().setCopy(0); + defaultTime = defaultTime.secondOfMinute().setCopy(0); + + long curTime = now.getMillis(); + long timeLeft = 0; + + if (bane.getLiveDate() != null) + timeLeft = bane.getLiveDate().getMillis() - curTime; + else + timeLeft = defaultTime.getMillis() - curTime + 1000; + + //DO not touch these. They are static formula's until i get the correct converter for SB Time. + + writer.put((byte) placedOn.dayOfMonth().get()); + writer.put((byte) placedOn.monthOfYear().get()); + writer.putInt(placedOn.year().get() - 1900); + writer.put((byte) 0); + writer.put((byte) 0); + writer.put((byte) 0); + + if (timeLeft < 0) + writer.putInt(0); + else + writer.putInt((int) timeLeft / 1000); // Time remaing until bane/Seconds + + if (attackerGuild.getGuildState() == GuildState.Sworn) + writer.putInt(4); //3 capture/errant,4 capture/sworn, 5 destroy/soveirgn. + else + writer.putInt(5); + + writer.put((byte) (16 - hoursLoggedIn)); // hour start + writer.put((byte) (24 - hoursLoggedIn)); // hour end + writer.put((byte) 2); + writer.putString(banedCity.getCityName()); + writer.putString(Guild.GetGL(bane.getOwner().getGuild()) != null ? Guild.GetGL(bane.getOwner().getGuild()).getName() : "No Guild Leader"); + GuildTag._serializeForDisplay(attackerGuild.getGuildTag(), writer); + GuildTag._serializeForDisplay(attackerGuild.getNation().getGuildTag(), writer); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + } + + if (this.actionType == 3) { + + writer.putInt(targetType); + writer.putInt(targetID); + + Guild nation = null; + Building building = BuildingManager.getBuildingFromCache(targetID); + Guild guild = building.getGuild(); + Zone zone = ZoneManager.findSmallestZone(building.getLoc()); + + writer.putInt(0);//unknown Might be to allow manager to open or not! + writer.putString(building.getName()); + + AbstractCharacter buildingOwner = building.getOwner(); + + if (buildingOwner == null) + writer.putString("Morloch"); + else + writer.putString(buildingOwner.getName()); + + if (zone == null) + writer.putString("Forlord"); + else + writer.putString(zone.getName()); + + writer.putString(building.getGuild().getName()); + + writer.putInt(building.getRank()); + + // Maintenance costs include resource if + // this structure is an R8 tree + + if (building.getRank() == 8) + writer.putInt(5); // Resources included + else + writer.putInt(1); // Gold only + + writer.putInt(2308551); //Gold + if (building.getBlueprint() == null) + writer.putInt(0); + else + writer.putInt(building.getBlueprint().getMaintCost(building.getRank())); // maint cost + + if (building.getRank() == 8) { + writer.putInt(74856115); // Stone + writer.putInt(1500); // maint cost + writer.putInt(-1603256692); // Lumber + writer.putInt(1500); // maint cost + writer.putInt(-1596311545); // Galvor + writer.putInt(5); // maint cost + writer.putInt(1532478436); // Wormwood + writer.putInt(5); // maint cost + } + + LocalDateTime maintDate = building.maintDateTime; + + if (maintDate == null) + maintDate = LocalDateTime.now(); + writer.putLocalDateTime(LocalDateTime.now()); // current time + + // utc offset? + writer.putInt((int) java.time.Duration.between(LocalDateTime.now(), maintDate).getSeconds()); // Seconds to maint date + + writer.putInt(building.getStrongboxValue()); + writer.putInt(building.reserve);//reserve Sets the buildings reserve display + writer.putInt(0);//prosperity under maintenance (wtf is prosperity?) + writer.putInt(10); + writer.putFloat((float) .1); + + if (this.buttonUpgrade == 1) { + if (building.getBlueprint() == null) + this.upgradeCost = Integer.MAX_VALUE; + else if (building.getRank() == building.getBlueprint().getMaxRank()) + this.upgradeCost = Integer.MAX_VALUE; + else + this.upgradeCost = building.getBlueprint().getRankCost(Math.min(building.getRank() + 1, 7)); + + writer.putInt(this.upgradeCost); + } else + writer.putInt(0); + + LocalDateTime uc = LocalDateTime.now(); + + if (building.getDateToUpgrade() != null) + uc = building.getDateToUpgrade(); + + long timeLeft = uc.atZone(ZoneId.systemDefault()) + .toInstant().toEpochMilli() - System.currentTimeMillis(); + long hour = timeLeft / 3600000; + long noHour = timeLeft - (hour * 3600000); + long minute = noHour / 60000; + long noMinute = noHour - (minute * 60000); + long second = noMinute / 1000; + + writer.put((byte) 0);//Has to do with repair time. A 1 here puts 23.9 hours in repair time A 2 here is 1.9 days + writer.put((byte) 0);//unknown + writer.putInt(0); //unknown + + if (LocalDateTime.now().isAfter(uc)) { + writer.put((byte) 0); + writer.put((byte) 0); + writer.put((byte) 0); + } else { + writer.put((byte) (hour)); + writer.put((byte) minute); + writer.put((byte) second); + } + + if (timeLeft < 0) + writer.putInt(0); + else + writer.putInt((int) timeLeft); + + writer.putInt((int) building.getCurrentHitpoints()); + writer.putInt((int) building.getMaxHitPoints()); + writer.putInt(BuildingManager.GetRepairCost(building));//sets the repair cost. + writer.putInt(0);//unknown + + if (building.getBlueprint() == null) + writer.putInt(0); + else + writer.putInt(building.getBlueprint().getSlotsForRank(building.getRank())); + writer.put((byte) 1);//Has to do with removing update timer and putting in cost for upgrade + + writer.put(labelProtected); // 1 sets protection to invulnerable. + writer.put(labelSiege);// 1 sets the protection under siege + writer.put(labelCeaseFire); //0 with 1 set above sets to under siege // 1 with 1 set above sets protection status to under siege(cease fire) + + writer.put(buttonTransfer);// 1 enables the transfer asset button + writer.put(buttonDestroy);// 1 enables the destroy asset button + writer.put(buttonAbandon);// 1 here enables the abandon asset button + writer.put(buttonUpgrade); //disable upgrade building + + if (building.getBlueprint() == null) + writer.putInt(0); + else + writer.putInt(building.getBlueprint().getIcon()); //Symbol + + if (guild == null) { + for (int i = 0; i < 3; i++) + writer.putInt(16); + for (int i = 0; i < 2; i++) + writer.putInt(0); + } else { + GuildTag._serializeForDisplay(guild.getGuildTag(), writer); + nation = guild.getNation(); + } + + if (nation == null) { + for (int i = 0; i < 3; i++) + writer.putInt(16); + for (int i = 0; i < 2; i++) + writer.putInt(0); + } else { + GuildTag._serializeForDisplay(nation.getGuildTag(), writer); + } + writer.putInt(0); + writer.putInt(0); + writer.putInt(0);//1 makes it so manage window does not open. + + if (!building.assetIsProtected() && !building.getProtectionState().equals(ProtectionState.PENDING)) { + writer.putInt(0); + } else { + writer.putInt(1); //kos on/off? + writer.putInt(3); // was 3 + if (zone.getPlayerCityUUID() != 0 && asset.assetIsProtected()) { + writer.putInt(GameObjectType.Building.ordinal()); + writer.putInt(City.getCity(zone.getPlayerCityUUID()).getTOL().getObjectUUID()); + } else { + writer.putInt(0); + writer.putInt(0); + } + + writer.putInt(0); + writer.putInt(0); + + writer.putInt(targetType3); + writer.putInt(targetID3); + + + if (building.getProtectionState() == ProtectionState.PENDING) + writer.put((byte) 1); //Accept or decline. + else + writer.put((byte) 0); + + if (building.taxType == TaxType.NONE) + writer.put((byte) 0); //? ?? + else if (building.taxDateTime != null) + writer.put((byte) 1); + else + writer.put((byte) 0); + + writer.putString(""); //tree of life protection tax + writer.putInt(0); //?? + writer.putInt(0); //?? + if (building.taxType == TaxType.NONE) { + writer.putInt(0); + writer.putInt(0); + } else if (building.taxType == TaxType.WEEKLY) { + writer.putInt(building.taxAmount); + writer.putInt(0); + } else { + writer.putInt(0); + writer.putInt(building.taxAmount); + } + + + writer.put(building.enforceKOS ? (byte) 1 : 0); //enforceKOS + writer.put((byte) 0); //? + writer.putInt(1); + } + + + ConcurrentHashMap npcList = building.getHirelings(); + writer.putInt(npcList.size()); + if (npcList.size() > 0) { + for (AbstractCharacter npcHire : npcList.keySet()) { + writer.putInt(npcHire.getObjectType().ordinal()); + if (npcHire.getObjectType() == GameObjectType.Mob) + writer.putInt(((Mob) npcHire).getDBID()); + else + writer.putInt(npcHire.getObjectUUID()); + if (npcHire.getObjectType() == GameObjectType.NPC) { + writer.putString(((NPC) npcHire).getContract().getName()); + writer.putString(npcHire.getName()); + } else if (npcHire.getObjectType() == GameObjectType.Mob) { + writer.putString(((Mob) npcHire).getContract().getName()); + if (((Mob) npcHire).getNameOverride().length() > 0) { + writer.putString(((Mob) npcHire).getNameOverride()); + } else { + writer.putString(npcHire.getName()); + } + } else + writer.putString("Error: Nothing Here"); + writer.putInt(npcHire.getRank()); + writer.putInt(Blueprint.getNpcMaintCost(npcHire.getRank())); + if (npcHire.getObjectType() == GameObjectType.NPC) + writer.putInt(((NPC) npcHire).getContract().getIconID()); // Was 60 + else if (npcHire.getObjectType() == GameObjectType.Mob) + writer.putInt(((Mob) npcHire).getContract().getIconID()); // Was 60 + + int contractID = 0; + + + if (npcHire.getObjectType() == GameObjectType.Mob) + contractID = ((Mob) npcHire).getContract().getContractID(); + else if (npcHire.getObjectType() == GameObjectType.NPC) + contractID = ((NPC) npcHire).getContract().getContractID(); + + if (contractID == 830) { + writer.putInt(24580); + } else if (building.getBlueprint() != null && (building.getBlueprint().getBuildingGroup() == BuildingGroup.FORGE || building.getBlueprint().getBuildingGroup() == BuildingGroup.MAGICSHOP || building.getBlueprint().getBuildingGroup() == BuildingGroup.TAILOR)) { + + writer.put((byte) 0); + writer.put((byte) 4); + writer.put((byte) 128); + writer.put((byte) 0); + + } else { + writer.put((byte) 0); + if (building.getBlueprint() != null && building.getBlueprint().getBuildingGroup() == BuildingGroup.BARRACK) + writer.put((byte) 1); + else + writer.put((byte) 0); + writer.put((byte) 0); + writer.put((byte) 0); + } + + + if (!npcHire.isAlive()) { + writer.put((byte) 1); // 1 SHOWs respawning + int respawnRemaining = (int) (((Mob) npcHire).deathTime + ((Mob) npcHire).spawnTime * 1000 - System.currentTimeMillis()) / 1000; + writer.putInt(respawnRemaining); // Seconds in respawn remaining. + writer.putInt(((Mob) npcHire).spawnTime); // max seconds for respawn + } else + writer.put((byte) 0); + + } + } + } + if (this.actionType == 4) { + writer.putInt(targetType); + writer.putInt(targetID); + Building building = BuildingManager.getBuildingFromCache(targetID); + + writer.putInt(preName01); + writer.putString(building.getName()); //assetName + writer.putString(building.getOwnerName()); //ownerName + writer.putString(building.getGuild().getName());//guild name + writer.putString(building.getCityName()); //City Name + writer.putInt(building.getRank()); + if (building.getBlueprint() == null) + writer.putInt(0); + else + writer.putInt(building.getBlueprint().getIcon()); + + //tags + GuildTag._serializeForDisplay(building.getGuild().getGuildTag(), writer); + GuildTag._serializeForDisplay(building.getGuild().getNation().getGuildTag(), writer); + + writer.putInt(unknown14); + writer.putInt(unknown15); + writer.putInt(unknown16); + writer.putInt(unknown17); + writer.putInt(0); // previously uninitialized unknown18 + } + } + + public int getRank() { + return rank; + } + + public void setRank(int rank) { + this.rank = rank; + } + + public int getSymbol() { + return symbol; + } + + public void setSymbol(int symbol) { + this.symbol = symbol; + } + + public int getUnknown04() { + return unknown04; + } + + public void setUnknown04(int unknown04) { + this.unknown04 = unknown04; + } + + public int getUnknown05() { + return unknown05; + } + + public void setUnknown05(int unknown05) { + this.unknown05 = unknown05; + } + + public int getUnknown06() { + return unknown06; + } + + public void setUnknown06(int unknown06) { + this.unknown06 = unknown06; + } + + public void setUnknown07(int unknown07) { + this.unknown07 = unknown07; + } + + public String getAssetName() { + return assetName; + } + + public void setAssetName(String AssetName) { + this.assetName = AssetName; + } + + public void setAssetName1(String AssetName1) { + this.AssetName1 = AssetName1; + } + + public String getCityName() { + return CityName; + } + + public void setUnknown54(int unknown54) { + this.unknown54 = unknown54; + } + + public int getStrongbox() { + return strongbox; + } + + public void setStrongbox(int strongbox) { + this.strongbox = strongbox; + } + + public int getBaneHour() { + return baneHour; + } + + public Building getAsset() { + return asset; + } + + public void setAsset(Building asset) { + this.asset = asset; + } } diff --git a/src/engine/net/client/msg/ManageNPCMsg.java b/src/engine/net/client/msg/ManageNPCMsg.java index 46fd32fd..61fac72e 100644 --- a/src/engine/net/client/msg/ManageNPCMsg.java +++ b/src/engine/net/client/msg/ManageNPCMsg.java @@ -32,1476 +32,1463 @@ import java.util.concurrent.ConcurrentHashMap; */ public class ManageNPCMsg extends ClientNetMsg { - private int targetType; - private int targetID; - private int unknown03; - private int unknown04; - private int unknown05; - private int unknown06; - - private int unknown07; - private int unknown08; - private int unknown09; - private int unknown10; - private int unknown11; - private int buyNormal; - private int buyGuild; - private int buyNation; - private int sellNormal; - private int sellGuild; - private int sellNation; - - private String CityName; - private String OwnerName; - private String GuildName; - private int unknown12; - - private int unknown13; - private int unknown14; - private int unknown15; - private int unknown16; - private int unknown17; - private int unknown18; - - private int messageType; - - private int unknown19; //Arraylist motto length? - private String motto; //motto Length 60 max? - - private int unknown01; - - private int buildingID; - private int unknown20; - private int unknown21; - private int unknown22; - private int unknown23; - private int unknown24; - private int unknown25; - private int unknown26; - private int unknown28; - private int unknown30; - private int unknown31; - private int unknown32; - private int unknown33; - private int unknown34; - private int unknown35; - private int unknown36; - private int unknown37; - private int unknown38; - private int unknown39; - private int unknown40; - private int unknown41; - private int unknown42; - private int unknown43; - private int unknown44; - private int unknown45; - private int unknown46; - private int unknown47; - private int unknown48; - private int unknown49; - private int unknown50; - private int unknown51; - private int unknown52; - private int unknown53; - private int unknown54; - private int unknown55; - private int unknown56; - private int unknown57; - private int unknown58; - private int unknown59; - private int unknown60; - private int unknown61; - private int unknown62; - private int unknown63; - private int unknown64; - private int unknown65; - private int unknown66; - private int unknown67; - private int unknown68; - private int unknown69; - private int unknown70; - private int unknown71; - private int unknown72; - private int unknown73; - private int unknown74; - private int unknown75; - private int unknown76; - private int unknown77; - private int unknown78; - private int unknown79; - private int unknown80; - private int unknown81; - private int unknown82; - private int unknown83; - - /** - * This is the general purpose constructor - */ - public ManageNPCMsg(AbstractCharacter ac) { - super(Protocol.MANAGENPC); - this.targetType = ac.getObjectType().ordinal(); - this.targetID = ac.getObjectUUID(); - this.buyGuild = 26; //TODO pull all these from the NPC object - this.buyNation = 26; - this.buyNormal = 26; - this.sellGuild = 100; - this.sellNation = 100; - this.sellNormal = 100; - this.messageType = 1; //This seems to be the "update Hireling window" value flag - - //Unknown defaults... - this.unknown20 = 0; - this.unknown21 = 0; - this.unknown22 = 0; - this.unknown23 = 0; - this.unknown24 = 0; - this.unknown25 = 0; - this.unknown26 = 0; - this.unknown28 = 0; - this.unknown30 = 0; - this.unknown31 = 0; - this.unknown32 = 0; - this.unknown33 = 0; - this.unknown34 = 0; - this.unknown35 = 0; - this.unknown36 = 0; - this.unknown37 = 1;//1 - this.unknown38 = 0;//0 - this.unknown39 = 0;//0 - this.unknown40 = 1;//1 - this.unknown41 = 0;//0 - this.unknown42 = 1;//1 [Toggles tree icon in protection slots] - this.unknown43 = 0;//0 - this.unknown44 = 1;//1 - this.unknown45 = 0;//0 - this.unknown46 = 0;//0 - this.unknown47 = 0;//0 - this.unknown48 = 0;//0 - this.unknown49 = 0;//0 - this.unknown50 = 0;//0 - this.unknown51 = 0;//0 - this.unknown52 = 0;//0 - this.unknown53 = 0;//0 - this.unknown54 = 1;//1 - this.unknown55 = 0;//0 - this.unknown56 = 3;//3 - this.unknown57 = 3;//3 - this.unknown58 = 0;//0 - this.unknown59 = 5;//5 - this.unknown60 = 0;//0 - this.unknown61 = 0;//0 - this.unknown62 = 0;//0 - this.unknown63 = 64;//64 - this.unknown64 = 0;//0 - this.unknown65 = 0;//0 - this.unknown66 = 0;//0 - this.unknown67 = 0;//0 - this.unknown68 = 1;//1 - this.unknown69 = 1;//1 - this.unknown70 = 0;//0 - this.unknown71 = 1;//1 - this.unknown72 = 0; - this.unknown73 = 0; - this.unknown74 = 5; - this.unknown75 = 1; - this.unknown76 = 2; - this.unknown77 = 15; - this.unknown78 = 3; - this.unknown79 = 18; - this.unknown80 = 0; - this.unknown81 = 0; - this.unknown82 = 0; - this.unknown83 = 0; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ManageNPCMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.MANAGENPC, origin, reader); - } - - @Override - protected int getPowerOfTwoBufferSize() { - return (19); // 2^10 == 1024 - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - //TODO do we need to do anything here? Does the client ever send this message to the server? - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - - Period upgradePeriod; - int upgradePeriodInSeconds; - - try { - - - writer.putInt(messageType); //1 - if (messageType == 5) { - writer.putInt(unknown20);//0 - writer.putInt(targetType); - writer.putInt(targetID); - - writer.putInt(GameObjectType.Building.ordinal()); - writer.putInt(buildingID); - 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.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - - } else if (messageType == 1) { - NPC npc = null; - Mob mobA = null; - - if (this.targetType == GameObjectType.NPC.ordinal()) { - - npc = NPC.getFromCache(this.targetID); - - if (npc == null) { - Logger.error("Missing NPC of ID " + this.targetID); - return; - } - - Contract contract = null; - contract = npc.getContract(); - - if (contract == null) { - Logger.error("Missing contract for NPC " + this.targetID); - return; - } - - writer.putInt(0); //anything other than 0 seems to mess up the client - writer.putInt(targetType); - writer.putInt(targetID); - writer.putInt(0); //static.... - writer.putInt(0);//static.... - writer.putInt(Blueprint.getNpcMaintCost(npc.getRank())); // salary - - writer.putInt(npc.getUpgradeCost()); - - if (npc.isRanking() && npc.getUpgradeDateTime().isAfter(DateTime.now())) - upgradePeriod = new Period(DateTime.now(), npc.getUpgradeDateTime()); - else - upgradePeriod = new Period(0); - - writer.put((byte) upgradePeriod.getDays()); //for timer - writer.put((byte) unknown26);//unknown - writer.putInt(100); //unknown - - writer.put((byte) upgradePeriod.getHours()); //for timer - writer.put((byte) upgradePeriod.getMinutes()); //for timer - writer.put((byte) upgradePeriod.getSeconds()); //for timer - - if (npc.isRanking() && npc.getUpgradeDateTime().isAfter(DateTime.now())) - upgradePeriodInSeconds = Seconds.secondsBetween(DateTime.now(), npc.getUpgradeDateTime()).getSeconds(); - else - upgradePeriodInSeconds = 0; - - writer.putInt(upgradePeriodInSeconds); - - writer.put((byte) 0); - writer.put((byte) (npc.getRank() == 7 ? 0 : 1)); //0 will make the upgrade field show "N/A" - writer.put((byte) 0); - writer.put((byte) 0); - writer.putInt(0); - writer.putInt(10000); //no idea... - writer.put((byte) 0); - writer.put((byte) 0); - writer.put((byte) 0); - writer.putInt(0); - - NPCProfits profit = NPC.GetNPCProfits(npc); - - if (profit == null) - profit = NPCProfits.defaultProfits; - //adding .000000001 to match client. - int buyNormal = (int) ((profit.buyNormal + .000001f) * 100); - int buyGuild = (int) ((profit.buyGuild + .000001f) * 100); - int buyNation = (int) ((profit.buyNation + .000001f) * 100); - - int sellNormal = (int) ((profit.sellNormal + .000001f) * 100); - int sellGuild = (int) ((profit.sellGuild + .000001f) * 100); - int sellNation = (int) ((profit.sellNation + .000001f) * 100); - - writer.putInt(buyNormal); - writer.putInt(buyGuild); - writer.putInt(buyNation); - writer.putInt(sellNormal); - writer.putInt(sellGuild); - writer.putInt(sellNation); - - if (contract.isRuneMaster()) { - writer.putInt(0); //vendor slots - writer.putInt(0); //artillery slots - - //figure out number of protection slots based on building rank - int runemasterSlots = (2 * npc.getRank()) + 6; - - writer.putInt(runemasterSlots); - - for (int i = 0; i < 13; i++) { - writer.putInt(0); //statics - } - //some unknown list - writer.putInt(4); //list count - writer.putInt(17); - writer.putInt(2); - writer.putInt(12); - writer.putInt(23); - - writer.putInt(0); //static - writer.putInt(0); //static - - //TODO add runemaster list here - - ArrayList buildingList = npc.getProtectedBuildings(); - - writer.putInt(buildingList.size()); - - for (Building b : buildingList) { - writer.putInt(3); - writer.putInt(b.getObjectType().ordinal()); - writer.putInt(b.getObjectUUID()); - - writer.putInt(npc.getParentZone().getObjectType().ordinal()); - writer.putInt(npc.getParentZone().getObjectUUID()); - - writer.putLong(0); //TODO Identify what Comp this is suppose to be. - if (b.getProtectionState() == ProtectionState.PENDING) - writer.put((byte) 1); - else - writer.put((byte) 0); - writer.put((byte) 0); - writer.putString(b.getName()); - writer.putInt(1);//what? - writer.putInt(1);//what? - //taxType = b.getTaxType() - switch (b.taxType) { - case NONE: - writer.putInt(0); - writer.putInt(0); - break; - case WEEKLY: - writer.putInt(b.taxAmount); - writer.putInt(0); - break; - case PROFIT: - writer.putInt(0); - writer.putInt(b.taxAmount); - break; - - } - writer.put(b.enforceKOS ? (byte) 1 : 0); //ENFORCE KOS - writer.put((byte) 0); //?? - writer.putInt(1); - } - - writer.putInt(0); //artillery captain list - - } else if (contract.isArtilleryCaptain()) { - int slots = 1; - if (contract.getContractID() == 839) - slots = 3; - - - writer.putInt(0); //vendor slots - writer.putInt(slots); //artillery slots - writer.putInt(0); //runemaster slots - - for (int i = 0; i < 13; i++) { - writer.putInt(0); //statics - } - //some unknown list - writer.putInt(1); //list count - writer.putInt(16); - - writer.putInt(0); //static - writer.putInt(0); //static - writer.putInt(0); //runemaster list - - //artillery captain list - ConcurrentHashMap siegeMinions = npc.getSiegeMinionMap(); - writer.putInt(1 + siegeMinions.size()); - serializeBulwarkList(writer, 1); //Trebuchet - //serializeBulwarkList(writer, 2); //Ballista - - if (siegeMinions != null && siegeMinions.size() > 0) - - for (Mob mob : siegeMinions.keySet()) { - this.unknown83 = mob.getObjectUUID(); - writer.putInt(2); - writer.putInt(mob.getObjectType().ordinal()); - writer.putInt(this.unknown83); - writer.putInt(0); - writer.putInt(10); - writer.putInt(0); - writer.putInt(1); - writer.putInt(1); - - long curTime = System.currentTimeMillis() / 1000; - long upgradeTime = (mob.deathTime + (mob.spawnTime * 1000)) / 1000; - long timeLife = upgradeTime - curTime; - if (upgradeTime * 1000 > System.currentTimeMillis()) { - if(mob.npcOwner.isAlive()) { - writer.put((byte) 0);//shows respawning timer - writer.putInt(mob.spawnTime); - writer.putInt(mob.spawnTime); - writer.putInt((int) timeLife); //time remaining for mob that is dead - writer.putInt(0); - writer.put((byte) 0); - writer.putString(mob.getNameOverride().isEmpty() ? mob.getName() : mob.getNameOverride()); - writer.put((byte) 0); - } - else{ - writer.put((byte) 0);//shows respawning timer - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); //time remaining for mob that is dead - writer.putInt(0); - writer.put((byte) 0); - writer.putString(mob.getNameOverride().isEmpty() ? mob.getName() : mob.getNameOverride()); - writer.put((byte) 0); - } - } else { - //nothing required for countdown for a mob that is alive - writer.put((byte) 1);//shows "Standing By" - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.put((byte) 0); - writer.putString(mob.getNameOverride().isEmpty() ? mob.getName() : mob.getNameOverride()); - writer.put((byte) 0); - } - } - return; - - } else { - - if (Contract.NoSlots(npc.getContract())) - writer.putInt(0); - else - writer.putInt(npc.getRank()); //vendor slots - writer.putInt(0); //artilerist slots - writer.putInt(0); //runemaster slots - - writer.putInt(1); //is this static? - for (int i = 0; i < 4; i++) { - writer.putInt(0); //statics - } - //Begin Item list for creation. - writer.putInt(npc.getCanRoll().size()); - - for (Integer ib : npc.getCanRoll()) { - ItemBase item = ItemBase.getItemBase(ib); - writer.put((byte) 1); - writer.putInt(0); - writer.putInt(ib); //itemID - writer.putInt(item.getBaseValue()); - writer.putInt(600); - writer.put((byte) 1); - writer.put((byte) item.getModTable()); - writer.put((byte) item.getModTable()); - writer.put((byte) item.getModTable()); - writer.put((byte) item.getModTable());//EffectItemType - } - ArrayList itemList = npc.getRolling(); - - if (itemList.isEmpty()) - writer.putInt(0); - else { - if (itemList.size() < npc.getRank()) - writer.putInt(itemList.size()); - else - writer.putInt(npc.getRank()); - for (Item i : itemList) { - if (itemList.indexOf(i) >= npc.getRank()) - break; - ItemBase ib = i.getItemBase(); - writer.put((byte) 0); // ? Unknown45 - writer.putInt(i.getObjectType().ordinal()); - writer.putInt(i.getObjectUUID()); - - writer.putInt(0); - writer.putInt(i.getItemBaseID()); - writer.putInt(ib.getBaseValue()); - long curTime = System.currentTimeMillis() / 1000; - long upgradeTime = i.getDateToUpgrade() / 1000; - long timeLife = i.getDateToUpgrade() - System.currentTimeMillis(); - - timeLife /= 1000; - writer.putInt((int) timeLife); - writer.putInt(npc.getRollingTimeInSeconds(i.getItemBaseID())); - writer.putInt(1); - if (i.isComplete()) - writer.put((byte) 1); - else - writer.put((byte) 0); - - ArrayList effectsList = i.getEffectNames(); - EffectsBase prefix = null; - EffectsBase suffix = null; - - for (String effectName : effectsList) { - if (effectName.contains("PRE")) - prefix = PowersManager.getEffectByIDString(effectName); - if (effectName.contains("SUF")) - suffix = PowersManager.getEffectByIDString(effectName); - - } - - if ((prefix == null && suffix == null)) - writer.putInt(0); - else - writer.putInt(-1497023830); - if ((prefix != null && !i.isRandom()) || (prefix != null && i.isComplete())) - writer.putInt(prefix.getToken()); - else - writer.putInt(0); - if ((suffix != null && !i.isRandom()) || (suffix != null && i.isComplete())) - writer.putInt(suffix.getToken()); - else - writer.putInt(0); - writer.putString(i.getCustomName()); - } - } - - writer.putInt(0); - writer.putInt(0); - writer.putInt(1); - writer.putInt(0); - writer.putInt(3); - writer.putInt(3); - writer.putInt(0); - writer.putString("Repair items"); - writer.putString("percent"); - writer.putInt(npc.getRepairCost()); //cost for repair - writer.putInt(0); - //ArrayList modSuffixList = - ArrayList modPrefixList = npc.getModTypeTable(); - Integer mod = modPrefixList.get(0); - - if (mod != 0) { - writer.putInt(npc.getModTypeTable().size()); //Effects size - for (Integer mtp : npc.getModTypeTable()) { - - Integer imt = modPrefixList.indexOf(mtp); - writer.putInt(npc.getItemModTable().get(imt)); //? - writer.putInt(0); - writer.putInt(0); - writer.putFloat(2); - writer.putInt(0); - writer.putInt(1); - writer.putInt(2); - writer.putInt(0); - writer.putInt(1); - writer.put(npc.getItemModTable().get(imt)); - writer.put(npc.getItemModTable().get(imt)); - writer.put(npc.getItemModTable().get(imt)); - writer.put(npc.getItemModTable().get(imt));//writer.putInt(-916801465); effectItemType - writer.putInt(mtp); //prefix - Integer mts = modPrefixList.indexOf(mtp); - writer.putInt(npc.getModSuffixTable().get(mts)); //suffix - } - } else - writer.putInt(0); - ArrayList inventory = npc.getInventory(); - - - writer.putInt(inventory.size()); //placeholder for item cnt - - - for (Item i : inventory) { - - Item.serializeForClientMsgWithoutSlot(i, writer); - } - - - writer.putInt(0); - writer.putInt(5); - writer.putInt(1); - writer.putInt(2); - writer.putInt(15); - writer.putInt(3); - writer.putInt(18); - - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - } - - } else if (this.targetType == GameObjectType.Mob.ordinal()) { - - mobA = Mob.getFromCacheDBID(this.targetID); - if (mobA == null) { - Logger.error("Missing Mob of ID " + this.targetID); - return; - } - - if (mobA != null) { - Contract con = mobA.getContract(); - if (con == null) { - Logger.error("Missing contract for NPC " + this.targetID); - return; - } - - int maxSlots = 1; - - switch (mobA.getRank()) { - case 1: - case 2: - maxSlots = 1; - break; - case 3: - maxSlots = 2; - break; - case 4: - case 5: - maxSlots = 3; - break; - case 6: - maxSlots = 4; - break; - case 7: - maxSlots = 5; - break; - default: - maxSlots = 1; - - } - if (NPC.ISGuardCaptain(mobA.getContract().getContractID()) == false) { - maxSlots = 0; - } - writer.putInt(0); //anything other than 0 seems to mess up the client - writer.putInt(targetType); - writer.putInt(targetID); - writer.putInt(0); //static.... - writer.putInt(0);//static.... - writer.putInt(Blueprint.getNpcMaintCost(mobA.getRank())); // salary - - writer.putInt(Mob.getUpgradeCost(mobA)); - - if (mobA.isRanking() && mobA.getUpgradeDateTime().isAfter(DateTime.now())) - upgradePeriod = new Period(DateTime.now(), mobA.getUpgradeDateTime()); - else - upgradePeriod = new Period(0); - - writer.put((byte) upgradePeriod.getDays()); //for timer - writer.put((byte) unknown26);//unknown - writer.putInt(100); //unknown - - writer.put((byte) upgradePeriod.getHours()); //for timer - writer.put((byte) upgradePeriod.getMinutes()); //for timer - writer.put((byte) upgradePeriod.getSeconds()); //for timer - - if (mobA.isRanking() && mobA.getUpgradeDateTime().isAfter(DateTime.now())) - upgradePeriodInSeconds = Seconds.secondsBetween(DateTime.now(), mobA.getUpgradeDateTime()).getSeconds(); - else - upgradePeriodInSeconds = 0; - - writer.putInt(upgradePeriodInSeconds); - - - writer.put((byte) 0); - writer.put((byte) (mobA.getRank() == 7 ? 0 : 1)); //0 will make the upgrade field show "N/A" - writer.put((byte) 0); - writer.put((byte) 0); - writer.putInt(0); - writer.putInt(10000); //no idea... - writer.put((byte) 0); - writer.put((byte) 0); - writer.put((byte) 0); - writer.putInt(0); - - - NPCProfits profit = NPCProfits.defaultProfits; - - writer.putInt((int) (profit.buyNormal * 100)); - writer.putInt((int) (profit.buyGuild * 100)); - writer.putInt((int) (profit.buyNation * 100)); - writer.putInt((int) (profit.sellNormal * 100)); - writer.putInt((int) (profit.sellGuild * 100)); - writer.putInt((int) (profit.sellNation * 100)); - - writer.putInt(0); //vendor slots - writer.putInt(maxSlots); //artillery slots - writer.putInt(0); //runemaster slots - - for (int i = 0; i < 13; i++) { - writer.putInt(0); //statics - } - //some unknown list - writer.putInt(1); //list count - writer.putInt(16); - - writer.putInt(0); //static - writer.putInt(0); //static - writer.putInt(0); //runemaster list - - //artillery captain list - ConcurrentHashMap siegeMinions = mobA.getSiegeMinionMap(); - - - writer.putInt(siegeMinions.size() + 1); - serializeGuardList(writer, mobA.getContract().getContractID()); //Guard - - if (siegeMinions != null && siegeMinions.size() > 0) - - for (Mob mob : siegeMinions.keySet()) { - this.unknown83 = mob.getObjectUUID(); - writer.putInt(2); - writer.putInt(mob.getObjectType().ordinal()); - writer.putInt(this.unknown83); - writer.putInt(0); - writer.putInt(10); - writer.putInt(0); - writer.putInt(1); - writer.putInt(1); - - long curTime = System.currentTimeMillis() / 1000; - long upgradeTime = (mob.deathTime + (mob.spawnTime * 1000)) / 1000; - long timeLife = upgradeTime - curTime; - if (upgradeTime * 1000 > System.currentTimeMillis()) { - if(mob.npcOwner.isAlive()) { - writer.put((byte) 0);//shows respawning timer - writer.putInt(mob.spawnTime); - writer.putInt(mob.spawnTime); - writer.putInt((int) timeLife); //time remaining for mob that is dead - writer.putInt(0); - writer.put((byte) 0); - writer.putString(mob.getNameOverride().isEmpty() ? mob.getName() : mob.getNameOverride()); - writer.put((byte) 0); - } - else{ - writer.put((byte) 0);//shows respawning timer - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); //time remaining for mob that is dead - writer.putInt(0); - writer.put((byte) 0); - writer.putString(mob.getNameOverride().isEmpty() ? mob.getName() : mob.getNameOverride()); - writer.put((byte) 0); - } - } else { - //nothing required for countdown for a mob that is alive - writer.put((byte) 1);//shows "Standing By" - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.put((byte) 0); - writer.putString(mob.getNameOverride().isEmpty() ? mob.getName() : mob.getNameOverride()); - writer.put((byte) 0); - } - } - } - } - } - }catch(Exception e){ - e.printStackTrace(); - } - - - } - - - - //Serializes lists for Bulwarks - private static void serializeBulwarkList(ByteBufferWriter writer, int minion) { - int minionIndex; - - if (minion < 1 || minion > 3) - minionIndex = 1; - else - minionIndex = minion; - - writer.putInt(0); - for (int i = 0; i < 3; i++) { - writer.putInt(0); //static - } - writer.putInt(9); - writer.putInt(5); - writer.putInt(9); - writer.putInt(5); - writer.put((byte) 0); - - writer.putInt((minion == 1) ? 900 : 600); //roll time - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); //Array - writer.put((byte) 0); - - if (minion == 1) - writer.putString("Trebuchet"); - else if (minion == 2) - writer.putString("Ballista"); - else - writer.putString("Mangonel"); - writer.put((byte) 1); - writer.putString("A weapon suited to laying siege"); - } - - private static void serializeGuardList(ByteBufferWriter writer, int minion) { - - writer.putInt(1); - - for (int i = 0; i < 3; i++) - writer.putInt(0); //static - - writer.putInt(minion); - writer.putInt(1); - writer.putInt(minion); - writer.putInt(1); - writer.put((byte) 0); - - writer.putInt(600); //roll time - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); //Array - writer.put((byte) 0); - - MinionType minionType = MinionType.ContractToMinionMap.get(minion); - writer.putString(minionType != null ? minionType.getRace() + " " + minionType.getName() : "Minion Guard"); - writer.put((byte) 1); - writer.putString("A Guard To Protect Your City."); - } - - - - - - public String getCityName() { - return CityName; - } - - - public void setUnknown07(int unknown07) { - this.unknown07 = unknown07; - } - - - - public void setMotto(String motto) { - this.motto = motto; - } + private int targetType; + private int targetID; + private int unknown03; + private int unknown04; + private int unknown05; + private int unknown06; + + private int unknown07; + private int unknown08; + private int unknown09; + private int unknown10; + private int unknown11; + private int buyNormal; + private int buyGuild; + private int buyNation; + private int sellNormal; + private int sellGuild; + private int sellNation; + + private String CityName; + private String OwnerName; + private String GuildName; + private int unknown12; + + private int unknown13; + private int unknown14; + private int unknown15; + private int unknown16; + private int unknown17; + private int unknown18; + + private int messageType; + + private int unknown19; //Arraylist motto length? + private String motto; //motto Length 60 max? + + private int unknown01; + + private int buildingID; + private int unknown20; + private int unknown21; + private int unknown22; + private int unknown23; + private int unknown24; + private int unknown25; + private int unknown26; + private int unknown28; + private int unknown30; + private int unknown31; + private int unknown32; + private int unknown33; + private int unknown34; + private int unknown35; + private int unknown36; + private int unknown37; + private int unknown38; + private int unknown39; + private int unknown40; + private int unknown41; + private int unknown42; + private int unknown43; + private int unknown44; + private int unknown45; + private int unknown46; + private int unknown47; + private int unknown48; + private int unknown49; + private int unknown50; + private int unknown51; + private int unknown52; + private int unknown53; + private int unknown54; + private int unknown55; + private int unknown56; + private int unknown57; + private int unknown58; + private int unknown59; + private int unknown60; + private int unknown61; + private int unknown62; + private int unknown63; + private int unknown64; + private int unknown65; + private int unknown66; + private int unknown67; + private int unknown68; + private int unknown69; + private int unknown70; + private int unknown71; + private int unknown72; + private int unknown73; + private int unknown74; + private int unknown75; + private int unknown76; + private int unknown77; + private int unknown78; + private int unknown79; + private int unknown80; + private int unknown81; + private int unknown82; + private int unknown83; + + /** + * This is the general purpose constructor + */ + public ManageNPCMsg(AbstractCharacter ac) { + super(Protocol.MANAGENPC); + this.targetType = ac.getObjectType().ordinal(); + this.targetID = ac.getObjectUUID(); + this.buyGuild = 26; //TODO pull all these from the NPC object + this.buyNation = 26; + this.buyNormal = 26; + this.sellGuild = 100; + this.sellNation = 100; + this.sellNormal = 100; + this.messageType = 1; //This seems to be the "update Hireling window" value flag + + //Unknown defaults... + this.unknown20 = 0; + this.unknown21 = 0; + this.unknown22 = 0; + this.unknown23 = 0; + this.unknown24 = 0; + this.unknown25 = 0; + this.unknown26 = 0; + this.unknown28 = 0; + this.unknown30 = 0; + this.unknown31 = 0; + this.unknown32 = 0; + this.unknown33 = 0; + this.unknown34 = 0; + this.unknown35 = 0; + this.unknown36 = 0; + this.unknown37 = 1;//1 + this.unknown38 = 0;//0 + this.unknown39 = 0;//0 + this.unknown40 = 1;//1 + this.unknown41 = 0;//0 + this.unknown42 = 1;//1 [Toggles tree icon in protection slots] + this.unknown43 = 0;//0 + this.unknown44 = 1;//1 + this.unknown45 = 0;//0 + this.unknown46 = 0;//0 + this.unknown47 = 0;//0 + this.unknown48 = 0;//0 + this.unknown49 = 0;//0 + this.unknown50 = 0;//0 + this.unknown51 = 0;//0 + this.unknown52 = 0;//0 + this.unknown53 = 0;//0 + this.unknown54 = 1;//1 + this.unknown55 = 0;//0 + this.unknown56 = 3;//3 + this.unknown57 = 3;//3 + this.unknown58 = 0;//0 + this.unknown59 = 5;//5 + this.unknown60 = 0;//0 + this.unknown61 = 0;//0 + this.unknown62 = 0;//0 + this.unknown63 = 64;//64 + this.unknown64 = 0;//0 + this.unknown65 = 0;//0 + this.unknown66 = 0;//0 + this.unknown67 = 0;//0 + this.unknown68 = 1;//1 + this.unknown69 = 1;//1 + this.unknown70 = 0;//0 + this.unknown71 = 1;//1 + this.unknown72 = 0; + this.unknown73 = 0; + this.unknown74 = 5; + this.unknown75 = 1; + this.unknown76 = 2; + this.unknown77 = 15; + this.unknown78 = 3; + this.unknown79 = 18; + this.unknown80 = 0; + this.unknown81 = 0; + this.unknown82 = 0; + this.unknown83 = 0; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ManageNPCMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.MANAGENPC, origin, reader); + } + + //Serializes lists for Bulwarks + private static void serializeBulwarkList(ByteBufferWriter writer, int minion) { + int minionIndex; + + if (minion < 1 || minion > 3) + minionIndex = 1; + else + minionIndex = minion; + + writer.putInt(0); + for (int i = 0; i < 3; i++) { + writer.putInt(0); //static + } + writer.putInt(9); + writer.putInt(5); + writer.putInt(9); + writer.putInt(5); + writer.put((byte) 0); + + writer.putInt((minion == 1) ? 900 : 600); //roll time + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); //Array + writer.put((byte) 0); + + if (minion == 1) + writer.putString("Trebuchet"); + else if (minion == 2) + writer.putString("Ballista"); + else + writer.putString("Mangonel"); + writer.put((byte) 1); + writer.putString("A weapon suited to laying siege"); + } + + private static void serializeGuardList(ByteBufferWriter writer, int minion) { + + writer.putInt(1); + + for (int i = 0; i < 3; i++) + writer.putInt(0); //static + + writer.putInt(minion); + writer.putInt(1); + writer.putInt(minion); + writer.putInt(1); + writer.put((byte) 0); + + writer.putInt(600); //roll time + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); //Array + writer.put((byte) 0); + + MinionType minionType = MinionType.ContractToMinionMap.get(minion); + writer.putString(minionType != null ? minionType.getRace() + " " + minionType.getName() : "Minion Guard"); + writer.put((byte) 1); + writer.putString("A Guard To Protect Your City."); + } + + @Override + protected int getPowerOfTwoBufferSize() { + return (19); // 2^10 == 1024 + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + //TODO do we need to do anything here? Does the client ever send this message to the server? + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + + Period upgradePeriod; + int upgradePeriodInSeconds; + + try { + + + writer.putInt(messageType); //1 + if (messageType == 5) { + writer.putInt(unknown20);//0 + writer.putInt(targetType); + writer.putInt(targetID); + + writer.putInt(GameObjectType.Building.ordinal()); + writer.putInt(buildingID); + 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.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + + } else if (messageType == 1) { + NPC npc = null; + Mob mobA = null; + + if (this.targetType == GameObjectType.NPC.ordinal()) { + + npc = NPC.getFromCache(this.targetID); + + if (npc == null) { + Logger.error("Missing NPC of ID " + this.targetID); + return; + } + + Contract contract = null; + contract = npc.getContract(); + + if (contract == null) { + Logger.error("Missing contract for NPC " + this.targetID); + return; + } + + writer.putInt(0); //anything other than 0 seems to mess up the client + writer.putInt(targetType); + writer.putInt(targetID); + writer.putInt(0); //static.... + writer.putInt(0);//static.... + writer.putInt(Blueprint.getNpcMaintCost(npc.getRank())); // salary + + writer.putInt(npc.getUpgradeCost()); + + if (npc.isRanking() && npc.getUpgradeDateTime().isAfter(DateTime.now())) + upgradePeriod = new Period(DateTime.now(), npc.getUpgradeDateTime()); + else + upgradePeriod = new Period(0); + + writer.put((byte) upgradePeriod.getDays()); //for timer + writer.put((byte) unknown26);//unknown + writer.putInt(100); //unknown + + writer.put((byte) upgradePeriod.getHours()); //for timer + writer.put((byte) upgradePeriod.getMinutes()); //for timer + writer.put((byte) upgradePeriod.getSeconds()); //for timer + + if (npc.isRanking() && npc.getUpgradeDateTime().isAfter(DateTime.now())) + upgradePeriodInSeconds = Seconds.secondsBetween(DateTime.now(), npc.getUpgradeDateTime()).getSeconds(); + else + upgradePeriodInSeconds = 0; + + writer.putInt(upgradePeriodInSeconds); + + writer.put((byte) 0); + writer.put((byte) (npc.getRank() == 7 ? 0 : 1)); //0 will make the upgrade field show "N/A" + writer.put((byte) 0); + writer.put((byte) 0); + writer.putInt(0); + writer.putInt(10000); //no idea... + writer.put((byte) 0); + writer.put((byte) 0); + writer.put((byte) 0); + writer.putInt(0); + + NPCProfits profit = NPC.GetNPCProfits(npc); + + if (profit == null) + profit = NPCProfits.defaultProfits; + //adding .000000001 to match client. + int buyNormal = (int) ((profit.buyNormal + .000001f) * 100); + int buyGuild = (int) ((profit.buyGuild + .000001f) * 100); + int buyNation = (int) ((profit.buyNation + .000001f) * 100); + + int sellNormal = (int) ((profit.sellNormal + .000001f) * 100); + int sellGuild = (int) ((profit.sellGuild + .000001f) * 100); + int sellNation = (int) ((profit.sellNation + .000001f) * 100); + + writer.putInt(buyNormal); + writer.putInt(buyGuild); + writer.putInt(buyNation); + writer.putInt(sellNormal); + writer.putInt(sellGuild); + writer.putInt(sellNation); + + if (contract.isRuneMaster()) { + writer.putInt(0); //vendor slots + writer.putInt(0); //artillery slots + + //figure out number of protection slots based on building rank + int runemasterSlots = (2 * npc.getRank()) + 6; + + writer.putInt(runemasterSlots); + + for (int i = 0; i < 13; i++) { + writer.putInt(0); //statics + } + //some unknown list + writer.putInt(4); //list count + writer.putInt(17); + writer.putInt(2); + writer.putInt(12); + writer.putInt(23); + + writer.putInt(0); //static + writer.putInt(0); //static + + //TODO add runemaster list here + + ArrayList buildingList = npc.getProtectedBuildings(); + + writer.putInt(buildingList.size()); + + for (Building b : buildingList) { + writer.putInt(3); + writer.putInt(b.getObjectType().ordinal()); + writer.putInt(b.getObjectUUID()); + + writer.putInt(npc.getParentZone().getObjectType().ordinal()); + writer.putInt(npc.getParentZone().getObjectUUID()); + + writer.putLong(0); //TODO Identify what Comp this is suppose to be. + if (b.getProtectionState() == ProtectionState.PENDING) + writer.put((byte) 1); + else + writer.put((byte) 0); + writer.put((byte) 0); + writer.putString(b.getName()); + writer.putInt(1);//what? + writer.putInt(1);//what? + //taxType = b.getTaxType() + switch (b.taxType) { + case NONE: + writer.putInt(0); + writer.putInt(0); + break; + case WEEKLY: + writer.putInt(b.taxAmount); + writer.putInt(0); + break; + case PROFIT: + writer.putInt(0); + writer.putInt(b.taxAmount); + break; + + } + writer.put(b.enforceKOS ? (byte) 1 : 0); //ENFORCE KOS + writer.put((byte) 0); //?? + writer.putInt(1); + } + + writer.putInt(0); //artillery captain list + + } else if (contract.isArtilleryCaptain()) { + int slots = 1; + if (contract.getContractID() == 839) + slots = 3; + + + writer.putInt(0); //vendor slots + writer.putInt(slots); //artillery slots + writer.putInt(0); //runemaster slots + + for (int i = 0; i < 13; i++) { + writer.putInt(0); //statics + } + //some unknown list + writer.putInt(1); //list count + writer.putInt(16); + + writer.putInt(0); //static + writer.putInt(0); //static + writer.putInt(0); //runemaster list + + //artillery captain list + ConcurrentHashMap siegeMinions = npc.getSiegeMinionMap(); + writer.putInt(1 + siegeMinions.size()); + serializeBulwarkList(writer, 1); //Trebuchet + //serializeBulwarkList(writer, 2); //Ballista + + if (siegeMinions != null && siegeMinions.size() > 0) + + for (Mob mob : siegeMinions.keySet()) { + this.unknown83 = mob.getObjectUUID(); + writer.putInt(2); + writer.putInt(mob.getObjectType().ordinal()); + writer.putInt(this.unknown83); + writer.putInt(0); + writer.putInt(10); + writer.putInt(0); + writer.putInt(1); + writer.putInt(1); + + long curTime = System.currentTimeMillis() / 1000; + long upgradeTime = (mob.deathTime + (mob.spawnTime * 1000)) / 1000; + long timeLife = upgradeTime - curTime; + if (upgradeTime * 1000 > System.currentTimeMillis()) { + if (mob.npcOwner.isAlive()) { + writer.put((byte) 0);//shows respawning timer + writer.putInt(mob.spawnTime); + writer.putInt(mob.spawnTime); + writer.putInt((int) timeLife); //time remaining for mob that is dead + writer.putInt(0); + writer.put((byte) 0); + writer.putString(mob.getNameOverride().isEmpty() ? mob.getName() : mob.getNameOverride()); + writer.put((byte) 0); + } else { + writer.put((byte) 0);//shows respawning timer + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); //time remaining for mob that is dead + writer.putInt(0); + writer.put((byte) 0); + writer.putString(mob.getNameOverride().isEmpty() ? mob.getName() : mob.getNameOverride()); + writer.put((byte) 0); + } + } else { + //nothing required for countdown for a mob that is alive + writer.put((byte) 1);//shows "Standing By" + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 0); + writer.putString(mob.getNameOverride().isEmpty() ? mob.getName() : mob.getNameOverride()); + writer.put((byte) 0); + } + } + return; + + } else { + + if (Contract.NoSlots(npc.getContract())) + writer.putInt(0); + else + writer.putInt(npc.getRank()); //vendor slots + writer.putInt(0); //artilerist slots + writer.putInt(0); //runemaster slots + + writer.putInt(1); //is this static? + for (int i = 0; i < 4; i++) { + writer.putInt(0); //statics + } + //Begin Item list for creation. + writer.putInt(npc.getCanRoll().size()); + + for (Integer ib : npc.getCanRoll()) { + ItemBase item = ItemBase.getItemBase(ib); + writer.put((byte) 1); + writer.putInt(0); + writer.putInt(ib); //itemID + writer.putInt(item.getBaseValue()); + writer.putInt(600); + writer.put((byte) 1); + writer.put((byte) item.getModTable()); + writer.put((byte) item.getModTable()); + writer.put((byte) item.getModTable()); + writer.put((byte) item.getModTable());//EffectItemType + } + ArrayList itemList = npc.getRolling(); + + if (itemList.isEmpty()) + writer.putInt(0); + else { + if (itemList.size() < npc.getRank()) + writer.putInt(itemList.size()); + else + writer.putInt(npc.getRank()); + for (Item i : itemList) { + if (itemList.indexOf(i) >= npc.getRank()) + break; + ItemBase ib = i.getItemBase(); + writer.put((byte) 0); // ? Unknown45 + writer.putInt(i.getObjectType().ordinal()); + writer.putInt(i.getObjectUUID()); + + writer.putInt(0); + writer.putInt(i.getItemBaseID()); + writer.putInt(ib.getBaseValue()); + long curTime = System.currentTimeMillis() / 1000; + long upgradeTime = i.getDateToUpgrade() / 1000; + long timeLife = i.getDateToUpgrade() - System.currentTimeMillis(); + + timeLife /= 1000; + writer.putInt((int) timeLife); + writer.putInt(npc.getRollingTimeInSeconds(i.getItemBaseID())); + writer.putInt(1); + if (i.isComplete()) + writer.put((byte) 1); + else + writer.put((byte) 0); + + ArrayList effectsList = i.getEffectNames(); + EffectsBase prefix = null; + EffectsBase suffix = null; + + for (String effectName : effectsList) { + if (effectName.contains("PRE")) + prefix = PowersManager.getEffectByIDString(effectName); + if (effectName.contains("SUF")) + suffix = PowersManager.getEffectByIDString(effectName); + + } + + if ((prefix == null && suffix == null)) + writer.putInt(0); + else + writer.putInt(-1497023830); + if ((prefix != null && !i.isRandom()) || (prefix != null && i.isComplete())) + writer.putInt(prefix.getToken()); + else + writer.putInt(0); + if ((suffix != null && !i.isRandom()) || (suffix != null && i.isComplete())) + writer.putInt(suffix.getToken()); + else + writer.putInt(0); + writer.putString(i.getCustomName()); + } + } + + writer.putInt(0); + writer.putInt(0); + writer.putInt(1); + writer.putInt(0); + writer.putInt(3); + writer.putInt(3); + writer.putInt(0); + writer.putString("Repair items"); + writer.putString("percent"); + writer.putInt(npc.getRepairCost()); //cost for repair + writer.putInt(0); + //ArrayList modSuffixList = + ArrayList modPrefixList = npc.getModTypeTable(); + Integer mod = modPrefixList.get(0); + + if (mod != 0) { + writer.putInt(npc.getModTypeTable().size()); //Effects size + for (Integer mtp : npc.getModTypeTable()) { + + Integer imt = modPrefixList.indexOf(mtp); + writer.putInt(npc.getItemModTable().get(imt)); //? + writer.putInt(0); + writer.putInt(0); + writer.putFloat(2); + writer.putInt(0); + writer.putInt(1); + writer.putInt(2); + writer.putInt(0); + writer.putInt(1); + writer.put(npc.getItemModTable().get(imt)); + writer.put(npc.getItemModTable().get(imt)); + writer.put(npc.getItemModTable().get(imt)); + writer.put(npc.getItemModTable().get(imt));//writer.putInt(-916801465); effectItemType + writer.putInt(mtp); //prefix + Integer mts = modPrefixList.indexOf(mtp); + writer.putInt(npc.getModSuffixTable().get(mts)); //suffix + } + } else + writer.putInt(0); + ArrayList inventory = npc.getInventory(); + + + writer.putInt(inventory.size()); //placeholder for item cnt + + + for (Item i : inventory) { + + Item.serializeForClientMsgWithoutSlot(i, writer); + } + + + writer.putInt(0); + writer.putInt(5); + writer.putInt(1); + writer.putInt(2); + writer.putInt(15); + writer.putInt(3); + writer.putInt(18); + + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + } + + } else if (this.targetType == GameObjectType.Mob.ordinal()) { + + mobA = Mob.getFromCacheDBID(this.targetID); + if (mobA == null) { + Logger.error("Missing Mob of ID " + this.targetID); + return; + } + + if (mobA != null) { + Contract con = mobA.getContract(); + if (con == null) { + Logger.error("Missing contract for NPC " + this.targetID); + return; + } + + int maxSlots = 1; + + switch (mobA.getRank()) { + case 1: + case 2: + maxSlots = 1; + break; + case 3: + maxSlots = 2; + break; + case 4: + case 5: + maxSlots = 3; + break; + case 6: + maxSlots = 4; + break; + case 7: + maxSlots = 5; + break; + default: + maxSlots = 1; + + } + if (NPC.ISGuardCaptain(mobA.getContract().getContractID()) == false) { + maxSlots = 0; + } + writer.putInt(0); //anything other than 0 seems to mess up the client + writer.putInt(targetType); + writer.putInt(targetID); + writer.putInt(0); //static.... + writer.putInt(0);//static.... + writer.putInt(Blueprint.getNpcMaintCost(mobA.getRank())); // salary + + writer.putInt(Mob.getUpgradeCost(mobA)); + + if (mobA.isRanking() && mobA.getUpgradeDateTime().isAfter(DateTime.now())) + upgradePeriod = new Period(DateTime.now(), mobA.getUpgradeDateTime()); + else + upgradePeriod = new Period(0); + + writer.put((byte) upgradePeriod.getDays()); //for timer + writer.put((byte) unknown26);//unknown + writer.putInt(100); //unknown + + writer.put((byte) upgradePeriod.getHours()); //for timer + writer.put((byte) upgradePeriod.getMinutes()); //for timer + writer.put((byte) upgradePeriod.getSeconds()); //for timer + + if (mobA.isRanking() && mobA.getUpgradeDateTime().isAfter(DateTime.now())) + upgradePeriodInSeconds = Seconds.secondsBetween(DateTime.now(), mobA.getUpgradeDateTime()).getSeconds(); + else + upgradePeriodInSeconds = 0; + + writer.putInt(upgradePeriodInSeconds); + + + writer.put((byte) 0); + writer.put((byte) (mobA.getRank() == 7 ? 0 : 1)); //0 will make the upgrade field show "N/A" + writer.put((byte) 0); + writer.put((byte) 0); + writer.putInt(0); + writer.putInt(10000); //no idea... + writer.put((byte) 0); + writer.put((byte) 0); + writer.put((byte) 0); + writer.putInt(0); + + + NPCProfits profit = NPCProfits.defaultProfits; + + writer.putInt((int) (profit.buyNormal * 100)); + writer.putInt((int) (profit.buyGuild * 100)); + writer.putInt((int) (profit.buyNation * 100)); + writer.putInt((int) (profit.sellNormal * 100)); + writer.putInt((int) (profit.sellGuild * 100)); + writer.putInt((int) (profit.sellNation * 100)); + + writer.putInt(0); //vendor slots + writer.putInt(maxSlots); //artillery slots + writer.putInt(0); //runemaster slots + + for (int i = 0; i < 13; i++) { + writer.putInt(0); //statics + } + //some unknown list + writer.putInt(1); //list count + writer.putInt(16); + + writer.putInt(0); //static + writer.putInt(0); //static + writer.putInt(0); //runemaster list + + //artillery captain list + ConcurrentHashMap siegeMinions = mobA.getSiegeMinionMap(); + + + writer.putInt(siegeMinions.size() + 1); + serializeGuardList(writer, mobA.getContract().getContractID()); //Guard + + if (siegeMinions != null && siegeMinions.size() > 0) + + for (Mob mob : siegeMinions.keySet()) { + this.unknown83 = mob.getObjectUUID(); + writer.putInt(2); + writer.putInt(mob.getObjectType().ordinal()); + writer.putInt(this.unknown83); + writer.putInt(0); + writer.putInt(10); + writer.putInt(0); + writer.putInt(1); + writer.putInt(1); + + long curTime = System.currentTimeMillis() / 1000; + long upgradeTime = (mob.deathTime + (mob.spawnTime * 1000)) / 1000; + long timeLife = upgradeTime - curTime; + if (upgradeTime * 1000 > System.currentTimeMillis()) { + if (mob.npcOwner.isAlive()) { + writer.put((byte) 0);//shows respawning timer + writer.putInt(mob.spawnTime); + writer.putInt(mob.spawnTime); + writer.putInt((int) timeLife); //time remaining for mob that is dead + writer.putInt(0); + writer.put((byte) 0); + writer.putString(mob.getNameOverride().isEmpty() ? mob.getName() : mob.getNameOverride()); + writer.put((byte) 0); + } else { + writer.put((byte) 0);//shows respawning timer + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); //time remaining for mob that is dead + writer.putInt(0); + writer.put((byte) 0); + writer.putString(mob.getNameOverride().isEmpty() ? mob.getName() : mob.getNameOverride()); + writer.put((byte) 0); + } + } else { + //nothing required for countdown for a mob that is alive + writer.put((byte) 1);//shows "Standing By" + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 0); + writer.putString(mob.getNameOverride().isEmpty() ? mob.getName() : mob.getNameOverride()); + writer.put((byte) 0); + } + } + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + + } + + public String getCityName() { + return CityName; + } + + + public void setUnknown07(int unknown07) { + this.unknown07 = unknown07; + } + + public String getMotto() { + return motto; + } + + public void setMotto(String motto) { + this.motto = motto; + } + + public int getUnknown01() { + return unknown01; + } + + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + public int getUnknown03() { + return unknown03; + } + + public void setUnknown03(int unknown03) { + this.unknown03 = unknown03; + } + + public int getUnknown04() { + return unknown04; + } + + public void setUnknown04(int unknown04) { + this.unknown04 = unknown04; + } + + public int getUnknown05() { + return unknown05; + } + + public void setUnknown05(int unknown05) { + this.unknown05 = unknown05; + } + + public int getUnknown06() { + return unknown06; + } + + public void setUnknown06(int unknown06) { + this.unknown06 = unknown06; + } + + public int getBuyNormal() { + return buyNormal; + } + + public void setBuyNormal(int buyNormal) { + this.buyNormal = buyNormal; + } + + public int getBuyGuild() { + return buyGuild; + } + + public void setBuyGuild(int buyGuild) { + this.buyGuild = buyGuild; + } + + public int getBuyNation() { + return buyNation; + } + + public void setBuyNation(int buyNation) { + this.buyNation = buyNation; + } + + public int getSellNormal() { + return sellNormal; + } - public String getMotto() { - return motto; - } + public void setSellNormal(int sellNormal) { + this.sellNormal = sellNormal; + } - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } + public int getSellGuild() { + return sellGuild; + } - public int getUnknown01() { - return unknown01; - } + public void setSellGuild(int sellGuild) { + this.sellGuild = sellGuild; + } - public void setUnknown03(int unknown03) { - this.unknown03 = unknown03; - } + public int getSellNation() { + return sellNation; + } - public int getUnknown03() { - return unknown03; - } + public void setSellNation(int sellNation) { + this.sellNation = sellNation; + } - public void setUnknown04(int unknown04) { - this.unknown04 = unknown04; - } + public int getMessageType() { + return messageType; + } - public int getUnknown04() { - return unknown04; - } + public void setMessageType(int messageType) { + this.messageType = messageType; + } - public void setUnknown05(int unknown05) { - this.unknown05 = unknown05; - } + public int getBuildingID() { + return buildingID; + } - public int getUnknown05() { - return unknown05; - } + public void setBuildingID(int buildingID) { + this.buildingID = buildingID; + } - public void setUnknown06(int unknown06) { - this.unknown06 = unknown06; - } + public int getUnknown20() { + return unknown20; + } - public int getUnknown06() { - return unknown06; - } + public void setUnknown20(int unknown20) { + this.unknown20 = unknown20; + } - public int getBuyNormal() { - return buyNormal; - } + public int getUnknown21() { + return unknown21; + } - public void setBuyNormal(int buyNormal) { - this.buyNormal = buyNormal; - } + public void setUnknown21(int unknown21) { + this.unknown21 = unknown21; + } - public int getBuyGuild() { - return buyGuild; - } + public int getUnknown22() { + return unknown22; + } - public void setBuyGuild(int buyGuild) { - this.buyGuild = buyGuild; - } + public void setUnknown22(int unknown22) { + this.unknown22 = unknown22; + } - public int getBuyNation() { - return buyNation; - } + public int getUnknown23() { + return unknown23; + } - public void setBuyNation(int buyNation) { - this.buyNation = buyNation; - } + public void setUnknown23(int unknown23) { + this.unknown23 = unknown23; + } - public int getSellNormal() { - return sellNormal; - } + public int getUnknown24() { + return unknown24; + } - public void setSellNormal(int sellNormal) { - this.sellNormal = sellNormal; - } + public void setUnknown24(int unknown24) { + this.unknown24 = unknown24; + } - public int getSellGuild() { - return sellGuild; - } + public int getUnknown25() { + return unknown25; + } - public void setSellGuild(int sellGuild) { - this.sellGuild = sellGuild; - } + public void setUnknown25(int unknown25) { + this.unknown25 = unknown25; + } - public int getSellNation() { - return sellNation; - } + public int getUnknown26() { + return unknown26; + } - public void setSellNation(int sellNation) { - this.sellNation = sellNation; - } + public void setUnknown26(int unknown26) { + this.unknown26 = unknown26; + } - public int getMessageType() { - return messageType; - } + public int getUnknown28() { + return unknown28; + } - public void setMessageType(int messageType) { - this.messageType = messageType; - } + public void setUnknown28(int unknown28) { + this.unknown28 = unknown28; + } - public int getBuildingID() { - return buildingID; - } + public int getUnknown30() { + return unknown30; + } - public void setBuildingID(int buildingID) { - this.buildingID = buildingID; - } + public void setUnknown30(int unknown30) { + this.unknown30 = unknown30; + } - public int getUnknown20() { - return unknown20; - } + public int getUnknown31() { + return unknown31; + } - public void setUnknown20(int unknown20) { - this.unknown20 = unknown20; - } + public void setUnknown31(int unknown31) { + this.unknown31 = unknown31; + } - public int getUnknown21() { - return unknown21; - } + public int getUnknown32() { + return unknown32; + } - public void setUnknown21(int unknown21) { - this.unknown21 = unknown21; - } + public void setUnknown32(int unknown32) { + this.unknown32 = unknown32; + } - public int getUnknown22() { - return unknown22; - } + public int getUnknown33() { + return unknown33; + } - public void setUnknown22(int unknown22) { - this.unknown22 = unknown22; - } + public void setUnknown33(int unknown33) { + this.unknown33 = unknown33; + } - public int getUnknown23() { - return unknown23; - } + public int getUnknown34() { + return unknown34; + } - public void setUnknown23(int unknown23) { - this.unknown23 = unknown23; - } + public void setUnknown34(int unknown34) { + this.unknown34 = unknown34; + } - public int getUnknown24() { - return unknown24; - } + public int getUnknown35() { + return unknown35; + } - public void setUnknown24(int unknown24) { - this.unknown24 = unknown24; - } + public void setUnknown35(int unknown35) { + this.unknown35 = unknown35; + } - public int getUnknown25() { - return unknown25; - } + public int getUnknown36() { + return unknown36; + } - public void setUnknown25(int unknown25) { - this.unknown25 = unknown25; - } + public void setUnknown36(int unknown36) { + this.unknown36 = unknown36; + } - public int getUnknown26() { - return unknown26; - } + public int getUnknown37() { + return unknown37; + } - public void setUnknown26(int unknown26) { - this.unknown26 = unknown26; - } + public void setUnknown37(int unknown37) { + this.unknown37 = unknown37; + } - public int getUnknown28() { - return unknown28; - } + public int getUnknown38() { + return unknown38; + } - public void setUnknown28(int unknown28) { - this.unknown28 = unknown28; - } + public void setUnknown38(int unknown38) { + this.unknown38 = unknown38; + } - public int getUnknown30() { - return unknown30; - } + public int getUnknown39() { + return unknown39; + } - public void setUnknown30(int unknown30) { - this.unknown30 = unknown30; - } + public void setUnknown39(int unknown39) { + this.unknown39 = unknown39; + } - public int getUnknown31() { - return unknown31; - } + public int getUnknown40() { + return unknown40; + } - public void setUnknown31(int unknown31) { - this.unknown31 = unknown31; - } + public void setUnknown40(int unknown40) { + this.unknown40 = unknown40; + } - public int getUnknown32() { - return unknown32; - } + public int getUnknown41() { + return unknown41; + } - public void setUnknown32(int unknown32) { - this.unknown32 = unknown32; - } + public void setUnknown41(int unknown41) { + this.unknown41 = unknown41; + } - public int getUnknown33() { - return unknown33; - } + public int getUnknown42() { + return unknown42; + } - public void setUnknown33(int unknown33) { - this.unknown33 = unknown33; - } + public void setUnknown42(int unknown42) { + this.unknown42 = unknown42; + } - public int getUnknown34() { - return unknown34; - } + public int getUnknown44() { + return unknown44; + } - public void setUnknown34(int unknown34) { - this.unknown34 = unknown34; - } + public void setUnknown44(int unknown44) { + this.unknown44 = unknown44; + } - public int getUnknown35() { - return unknown35; - } + public int getUnknown43() { + return unknown43; + } - public void setUnknown35(int unknown35) { - this.unknown35 = unknown35; - } + public void setUnknown43(int unknown43) { + this.unknown43 = unknown43; + } - public int getUnknown36() { - return unknown36; - } + public int getUnknown45() { + return unknown45; + } - public void setUnknown36(int unknown36) { - this.unknown36 = unknown36; - } + public void setUnknown45(int unknown45) { + this.unknown45 = unknown45; + } - public int getUnknown37() { - return unknown37; - } + public int getUnknown46() { + return unknown46; + } - public void setUnknown37(int unknown37) { - this.unknown37 = unknown37; - } + public void setUnknown46(int unknown46) { + this.unknown46 = unknown46; + } - public int getUnknown38() { - return unknown38; - } + public int getUnknown47() { + return unknown47; + } - public void setUnknown38(int unknown38) { - this.unknown38 = unknown38; - } + public void setUnknown47(int unknown47) { + this.unknown47 = unknown47; + } - public int getUnknown39() { - return unknown39; - } + public int getUnknown48() { + return unknown48; + } - public void setUnknown39(int unknown39) { - this.unknown39 = unknown39; - } + public void setUnknown48(int unknown48) { + this.unknown48 = unknown48; + } - public int getUnknown40() { - return unknown40; - } + public int getUnknown49() { + return unknown49; + } - public void setUnknown40(int unknown40) { - this.unknown40 = unknown40; - } + public void setUnknown49(int unknown49) { + this.unknown49 = unknown49; + } - public int getUnknown41() { - return unknown41; - } + public int getUnknown50() { + return unknown50; + } - public void setUnknown41(int unknown41) { - this.unknown41 = unknown41; - } + public void setUnknown50(int unknown50) { + this.unknown50 = unknown50; + } - public int getUnknown42() { - return unknown42; - } + public int getUnknown51() { + return unknown51; + } - public void setUnknown42(int unknown42) { - this.unknown42 = unknown42; - } + public void setUnknown51(int unknown51) { + this.unknown51 = unknown51; + } - public int getUnknown44() { - return unknown44; - } + public int getUnknown52() { + return unknown52; + } - public void setUnknown44(int unknown44) { - this.unknown44 = unknown44; - } + public void setUnknown52(int unknown52) { + this.unknown52 = unknown52; + } - public int getUnknown43() { - return unknown43; - } + public int getUnknown53() { + return unknown53; + } - public void setUnknown43(int unknown43) { - this.unknown43 = unknown43; - } + public void setUnknown53(int unknown53) { + this.unknown53 = unknown53; + } - public int getUnknown45() { - return unknown45; - } + public int getUnknown54() { + return unknown54; + } - public void setUnknown45(int unknown45) { - this.unknown45 = unknown45; - } + public void setUnknown54(int unknown54) { + this.unknown54 = unknown54; + } - public int getUnknown46() { - return unknown46; - } + public int getUnknown55() { + return unknown55; + } - public void setUnknown46(int unknown46) { - this.unknown46 = unknown46; - } + public void setUnknown55(int unknown55) { + this.unknown55 = unknown55; + } - public int getUnknown47() { - return unknown47; - } + public int getUnknown56() { + return unknown56; + } - public void setUnknown47(int unknown47) { - this.unknown47 = unknown47; - } + public void setUnknown56(int unknown56) { + this.unknown56 = unknown56; + } - public int getUnknown48() { - return unknown48; - } + public int getUnknown57() { + return unknown57; + } - public void setUnknown48(int unknown48) { - this.unknown48 = unknown48; - } + public void setUnknown57(int unknown57) { + this.unknown57 = unknown57; + } - public int getUnknown49() { - return unknown49; - } + public int getUnknown58() { + return unknown58; + } - public void setUnknown49(int unknown49) { - this.unknown49 = unknown49; - } + public void setUnknown58(int unknown58) { + this.unknown58 = unknown58; + } - public int getUnknown50() { - return unknown50; - } + public int getUnknown59() { + return unknown59; + } - public void setUnknown50(int unknown50) { - this.unknown50 = unknown50; - } + public void setUnknown59(int unknown59) { + this.unknown59 = unknown59; + } - public int getUnknown51() { - return unknown51; - } + public int getUnknown60() { + return unknown60; + } - public void setUnknown51(int unknown51) { - this.unknown51 = unknown51; - } + public void setUnknown60(int unknown60) { + this.unknown60 = unknown60; + } - public int getUnknown52() { - return unknown52; - } + public int getUnknown61() { + return unknown61; + } - public void setUnknown52(int unknown52) { - this.unknown52 = unknown52; - } + public void setUnknown61(int unknown61) { + this.unknown61 = unknown61; + } - public int getUnknown53() { - return unknown53; - } + public int getUnknown62() { + return unknown62; + } - public void setUnknown53(int unknown53) { - this.unknown53 = unknown53; - } + public void setUnknown62(int unknown62) { + this.unknown62 = unknown62; + } - public int getUnknown54() { - return unknown54; - } + public int getUnknown63() { + return unknown63; + } - public void setUnknown54(int unknown54) { - this.unknown54 = unknown54; - } + public void setUnknown63(int unknown63) { + this.unknown63 = unknown63; + } - public int getUnknown55() { - return unknown55; - } + public int getUnknown64() { + return unknown64; + } - public void setUnknown55(int unknown55) { - this.unknown55 = unknown55; - } + public void setUnknown64(int unknown64) { + this.unknown64 = unknown64; + } - public int getUnknown56() { - return unknown56; - } + public int getUnknown65() { + return unknown65; + } - public void setUnknown56(int unknown56) { - this.unknown56 = unknown56; - } + public void setUnknown65(int unknown65) { + this.unknown65 = unknown65; + } - public int getUnknown57() { - return unknown57; - } + public int getUnknown66() { + return unknown66; + } - public void setUnknown57(int unknown57) { - this.unknown57 = unknown57; - } + public void setUnknown66(int unknown66) { + this.unknown66 = unknown66; + } - public int getUnknown58() { - return unknown58; - } + public int getUnknown67() { + return unknown67; + } - public void setUnknown58(int unknown58) { - this.unknown58 = unknown58; - } + public void setUnknown67(int unknown67) { + this.unknown67 = unknown67; + } - public int getUnknown59() { - return unknown59; - } + public int getUnknown68() { + return unknown68; + } - public void setUnknown59(int unknown59) { - this.unknown59 = unknown59; - } + public void setUnknown68(int unknown68) { + this.unknown68 = unknown68; + } - public int getUnknown60() { - return unknown60; - } + public int getUnknown69() { + return unknown69; + } - public void setUnknown60(int unknown60) { - this.unknown60 = unknown60; - } + public void setUnknown69(int unknown69) { + this.unknown69 = unknown69; + } - public int getUnknown61() { - return unknown61; - } + public int getUnknown70() { + return unknown70; + } - public void setUnknown61(int unknown61) { - this.unknown61 = unknown61; - } + public void setUnknown70(int unknown70) { + this.unknown70 = unknown70; + } - public int getUnknown62() { - return unknown62; - } + public int getUnknown71() { + return unknown71; + } - public void setUnknown62(int unknown62) { - this.unknown62 = unknown62; - } + public void setUnknown71(int unknown71) { + this.unknown71 = unknown71; + } - public int getUnknown63() { - return unknown63; - } + public int getUnknown72() { + return unknown72; + } - public void setUnknown63(int unknown63) { - this.unknown63 = unknown63; - } + public void setUnknown72(int unknown72) { + this.unknown72 = unknown72; + } - public int getUnknown64() { - return unknown64; - } + public int getUnknown73() { + return unknown73; + } - public void setUnknown64(int unknown64) { - this.unknown64 = unknown64; - } + public void setUnknown73(int unknown73) { + this.unknown73 = unknown73; + } - public int getUnknown65() { - return unknown65; - } + public int getUnknown74() { + return unknown74; + } - public void setUnknown65(int unknown65) { - this.unknown65 = unknown65; - } + public void setUnknown74(int unknown74) { + this.unknown74 = unknown74; + } - public int getUnknown66() { - return unknown66; - } + public int getUnknown75() { + return unknown75; + } - public void setUnknown66(int unknown66) { - this.unknown66 = unknown66; - } + public void setUnknown75(int unknown75) { + this.unknown75 = unknown75; + } - public int getUnknown67() { - return unknown67; - } + public int getUnknown76() { + return unknown76; + } - public void setUnknown67(int unknown67) { - this.unknown67 = unknown67; - } + public void setUnknown76(int unknown76) { + this.unknown76 = unknown76; + } - public int getUnknown68() { - return unknown68; - } + public int getUnknown77() { + return unknown77; + } - public void setUnknown68(int unknown68) { - this.unknown68 = unknown68; - } + public void setUnknown77(int unknown77) { + this.unknown77 = unknown77; + } - public int getUnknown69() { - return unknown69; - } + public int getUnknown78() { + return unknown78; + } - public void setUnknown69(int unknown69) { - this.unknown69 = unknown69; - } + public void setUnknown78(int unknown78) { + this.unknown78 = unknown78; + } - public int getUnknown70() { - return unknown70; - } + public int getUnknown79() { + return unknown79; + } - public void setUnknown70(int unknown70) { - this.unknown70 = unknown70; - } + public void setUnknown79(int unknown79) { + this.unknown79 = unknown79; + } - public int getUnknown71() { - return unknown71; - } + public int getTargetType() { + return targetType; + } - public void setUnknown71(int unknown71) { - this.unknown71 = unknown71; - } + public void setTargetType(int targetType) { + this.targetType = targetType; + } - public int getUnknown72() { - return unknown72; - } - - public void setUnknown72(int unknown72) { - this.unknown72 = unknown72; - } - - public int getUnknown73() { - return unknown73; - } - - public void setUnknown73(int unknown73) { - this.unknown73 = unknown73; - } - - public int getUnknown74() { - return unknown74; - } - - public void setUnknown74(int unknown74) { - this.unknown74 = unknown74; - } - - public int getUnknown75() { - return unknown75; - } - - public void setUnknown75(int unknown75) { - this.unknown75 = unknown75; - } - - public int getUnknown76() { - return unknown76; - } - - public void setUnknown76(int unknown76) { - this.unknown76 = unknown76; - } - - public int getUnknown77() { - return unknown77; - } - - public void setUnknown77(int unknown77) { - this.unknown77 = unknown77; - } - - public int getUnknown78() { - return unknown78; - } - - public void setUnknown78(int unknown78) { - this.unknown78 = unknown78; - } - - public int getUnknown79() { - return unknown79; - } - - public void setUnknown79(int unknown79) { - this.unknown79 = unknown79; - } - - public int getTargetType() { - return targetType; - } - - public void setTargetType(int targetType) { - this.targetType = targetType; - } - - public int getTargetID() { - return targetID; - } - - public void setTargetID(int targetID) { - this.targetID = targetID; - } + public int getTargetID() { + return targetID; + } + public void setTargetID(int targetID) { + this.targetID = targetID; + } } diff --git a/src/engine/net/client/msg/MerchantMsg.java b/src/engine/net/client/msg/MerchantMsg.java index 1510c493..d14d0692 100644 --- a/src/engine/net/client/msg/MerchantMsg.java +++ b/src/engine/net/client/msg/MerchantMsg.java @@ -18,211 +18,211 @@ import engine.net.client.Protocol; public class MerchantMsg extends ClientNetMsg { - private int type; - private int unknown01; - private int unknown02; - private int unknown03; - private int npcType; - private int npcID; - private int cityType; - private int cityID; - private int teleportTime; - private int unknown04; - private int itemType; - private int itemID; - private int amount; - private int hashID; - - /** - * This is the general purpose constructor. - */ - public MerchantMsg() { - super(Protocol.MERCHANT); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public MerchantMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.MERCHANT, origin, reader); - } - - /** - * Copy constructor - */ - public MerchantMsg(MerchantMsg msg) { - super(Protocol.MERCHANT); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.type = reader.getInt(); - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - this.unknown03 = reader.getInt(); - this.npcType = reader.getInt(); - this.npcID = reader.getInt(); - if (this.type == 11 || type == 13) { - this.cityType = reader.getInt(); - this.cityID = reader.getInt(); - this.teleportTime = reader.getInt(); - }else if(this.type == 18){ - this.itemType = reader.getInt(); - this.itemID = reader.getInt(); - this.amount = reader.getInt(); - }else if (this.type == 17){ - this.hashID = reader.getInt(); - this.amount = reader.getInt(); - }else if (this.type == 19){ - this.hashID = reader.getInt(); - }else { - - this.cityType = 0; - this.cityID = 0; - this.teleportTime = 0; - } - this.unknown04 = reader.getInt(); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.type); - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - writer.putInt(this.unknown03); - writer.putInt(this.npcType); - writer.putInt(this.npcID); - if (this.type == 11 || type == 13) { - writer.putInt(this.cityType); - writer.putInt(this.cityID); - writer.putInt(this.teleportTime); - } - writer.putInt(this.unknown04); - if (this.type == 5){ - writer.putInt(2097253); - writer.putInt(0); - } - - } - - public int getType() { - return this.type; - } - - public int getUnknown01() { - return this.unknown01; - } - - public int getUnknown02() { - return this.unknown02; - } - - public int getUnknown03() { - return this.unknown03; - } - - public int getNPCType() { - return this.npcType; - } - - public int getNPCID() { - return this.npcID; - } - - public int getCityType() { - return this.cityType; - } - - public int getCityID() { - return this.cityID; - } - - public int getTeleportTime() { - return this.teleportTime; - } - - public int getUnknown04() { - return this.unknown04; - } - - public void setType(int value) { - this.type = value; - } - - public void setUnknown01(int value) { - this.unknown01 = value; - } - - public void setUnknown02(int value) { - this.unknown02 = value; - } - - public void setUnknown03(int value) { - this.unknown03 = value; - } - - public void setNPCType(int value) { - this.npcType = value; - } - - public void setNPCID(int value) { - this.npcID = value; - } - - public void setCityType(int value) { - this.cityType = value; - } - - public void setCityID(int value) { - this.cityID = value; - } - - public void setTeleportTime(int value) { - this.teleportTime = value; - } - - public void setUnknown04(int value) { - this.unknown04 = value; - } - - public int getItemType() { - return itemType; - } - - public void setItemType(int itemType) { - this.itemType = itemType; - } - - public int getItemID() { - return itemID; - } - - public void setItemID(int itemID) { - this.itemID = itemID; - } + private int type; + private int unknown01; + private int unknown02; + private int unknown03; + private int npcType; + private int npcID; + private int cityType; + private int cityID; + private int teleportTime; + private int unknown04; + private int itemType; + private int itemID; + private int amount; + private int hashID; + + /** + * This is the general purpose constructor. + */ + public MerchantMsg() { + super(Protocol.MERCHANT); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public MerchantMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.MERCHANT, origin, reader); + } + + /** + * Copy constructor + */ + public MerchantMsg(MerchantMsg msg) { + super(Protocol.MERCHANT); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.type = reader.getInt(); + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + this.unknown03 = reader.getInt(); + this.npcType = reader.getInt(); + this.npcID = reader.getInt(); + if (this.type == 11 || type == 13) { + this.cityType = reader.getInt(); + this.cityID = reader.getInt(); + this.teleportTime = reader.getInt(); + } else if (this.type == 18) { + this.itemType = reader.getInt(); + this.itemID = reader.getInt(); + this.amount = reader.getInt(); + } else if (this.type == 17) { + this.hashID = reader.getInt(); + this.amount = reader.getInt(); + } else if (this.type == 19) { + this.hashID = reader.getInt(); + } else { + + this.cityType = 0; + this.cityID = 0; + this.teleportTime = 0; + } + this.unknown04 = reader.getInt(); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.type); + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + writer.putInt(this.unknown03); + writer.putInt(this.npcType); + writer.putInt(this.npcID); + if (this.type == 11 || type == 13) { + writer.putInt(this.cityType); + writer.putInt(this.cityID); + writer.putInt(this.teleportTime); + } + writer.putInt(this.unknown04); + if (this.type == 5) { + writer.putInt(2097253); + writer.putInt(0); + } + + } + + public int getType() { + return this.type; + } + + public void setType(int value) { + this.type = value; + } + + public int getUnknown01() { + return this.unknown01; + } + + public void setUnknown01(int value) { + this.unknown01 = value; + } + + public int getUnknown02() { + return this.unknown02; + } + + public void setUnknown02(int value) { + this.unknown02 = value; + } + + public int getUnknown03() { + return this.unknown03; + } + + public void setUnknown03(int value) { + this.unknown03 = value; + } + + public int getNPCType() { + return this.npcType; + } + + public void setNPCType(int value) { + this.npcType = value; + } + + public int getNPCID() { + return this.npcID; + } + + public void setNPCID(int value) { + this.npcID = value; + } + + public int getCityType() { + return this.cityType; + } + + public void setCityType(int value) { + this.cityType = value; + } + + public int getCityID() { + return this.cityID; + } + + public void setCityID(int value) { + this.cityID = value; + } + + public int getTeleportTime() { + return this.teleportTime; + } + + public void setTeleportTime(int value) { + this.teleportTime = value; + } + + public int getUnknown04() { + return this.unknown04; + } + + public void setUnknown04(int value) { + this.unknown04 = value; + } + + public int getItemType() { + return itemType; + } + + public void setItemType(int itemType) { + this.itemType = itemType; + } + + public int getItemID() { + return itemID; + } + + public void setItemID(int itemID) { + this.itemID = itemID; + } - public int getAmount() { - return amount; - } + public int getAmount() { + return amount; + } - public void setAmount(int amount) { - this.amount = amount; - } + public void setAmount(int amount) { + this.amount = amount; + } - public int getHashID() { - return hashID; - } + public int getHashID() { + return hashID; + } - public void setHashID(int hashID) { - this.hashID = hashID; - } + public void setHashID(int hashID) { + this.hashID = hashID; + } } diff --git a/src/engine/net/client/msg/MinionTrainingMessage.java b/src/engine/net/client/msg/MinionTrainingMessage.java index 7de521e5..507db953 100644 --- a/src/engine/net/client/msg/MinionTrainingMessage.java +++ b/src/engine/net/client/msg/MinionTrainingMessage.java @@ -17,179 +17,185 @@ import engine.net.ByteBufferWriter; import engine.net.client.Protocol; public class MinionTrainingMessage extends ClientNetMsg { - private int npcID; - private int npcType; - private int buildingID; - private int buildingType; - private int type; - private int pad = 0; - private int objectType; - private int objectUUID; - private boolean isTreb = false; - private boolean isMangonal = false; - private boolean isBallista = false; - private int minion; - private int mobType; - private int mobID; - - - - - - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public MinionTrainingMessage(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.MINIONTRAINING, origin, reader); - } - - public MinionTrainingMessage() { - super(Protocol.MINIONTRAINING); - } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.type = reader.getInt(); - if (this.type == 2){ - this.buildingType = reader.getInt(); - this.buildingID = reader.getInt(); - this.npcType = reader.getInt(); - this.npcID = reader.getInt(); - this.objectType = reader.getInt(); - this.objectUUID = reader.getInt(); - reader.getInt(); - reader.getInt(); - - }else{ - this.buildingType = reader.getInt(); - this.buildingID = reader.getInt(); - this.npcType = reader.getInt(); - this.npcID = reader.getInt(); - reader.getInt(); - this.minion = reader.getInt(); - if (this.minion == 1) - this.isTreb = true; - else if(this.minion == 2) - this.isBallista = true; - else if (this.minion == 3) - this.isMangonal = true; - reader.getInt(); - reader.getInt(); - } - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - - } - - public int getObjectType() { - return objectType; - } - - public void setObjectType(int value) { - this.objectType = value; - } - - public void setPad(int value) { - this.pad = value; - } - - public int getUUID() { - return objectUUID; - - } - - public int getPad() { - return pad; - } - - public int getType() { - return type; - } - public void setType(int type) { - this.type = type; - } - public boolean isTreb() { - return isTreb; - } - public void setTreb(boolean isTreb) { - this.isTreb = isTreb; - } - public boolean isMangonal() { - return isMangonal; - } - public void setMangonal(boolean isMangonal) { - this.isMangonal = isMangonal; - } - public boolean isBallista() { - return isBallista; - } - public void setBallista(boolean isBallista) { - this.isBallista = isBallista; - } - public int getMinion() { - return minion; - } - public void setMinion(int minion) { - this.minion = minion; - } - - public int getNpcID() { - return npcID; - } - - public void setNpcID(int npcID) { - this.npcID = npcID; - } - - public int getNpcType() { - return npcType; - } - - public void setNpcType(int npcType) { - this.npcType = npcType; - } - - public int getBuildingID() { - return buildingID; - } - - public void setBuildingID(int buildingID) { - this.buildingID = buildingID; - } - - public int getBuildingType() { - return buildingType; - } - - public void setBuildingType(int buildingType) { - this.buildingType = buildingType; - } - - public int getMobType() { - return mobType; - } - - public void setMobType(int mobType) { - this.mobType = mobType; - } - - public int getMobID() { - return mobID; - } - - public void setMobID(int mobID) { - this.mobID = mobID; - } + private int npcID; + private int npcType; + private int buildingID; + private int buildingType; + private int type; + private int pad = 0; + private int objectType; + private int objectUUID; + private boolean isTreb = false; + private boolean isMangonal = false; + private boolean isBallista = false; + private int minion; + private int mobType; + private int mobID; + + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public MinionTrainingMessage(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.MINIONTRAINING, origin, reader); + } + + public MinionTrainingMessage() { + super(Protocol.MINIONTRAINING); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.type = reader.getInt(); + if (this.type == 2) { + this.buildingType = reader.getInt(); + this.buildingID = reader.getInt(); + this.npcType = reader.getInt(); + this.npcID = reader.getInt(); + this.objectType = reader.getInt(); + this.objectUUID = reader.getInt(); + reader.getInt(); + reader.getInt(); + + } else { + this.buildingType = reader.getInt(); + this.buildingID = reader.getInt(); + this.npcType = reader.getInt(); + this.npcID = reader.getInt(); + reader.getInt(); + this.minion = reader.getInt(); + if (this.minion == 1) + this.isTreb = true; + else if (this.minion == 2) + this.isBallista = true; + else if (this.minion == 3) + this.isMangonal = true; + reader.getInt(); + reader.getInt(); + } + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + + } + + public int getObjectType() { + return objectType; + } + + public void setObjectType(int value) { + this.objectType = value; + } + + public int getUUID() { + return objectUUID; + + } + + public int getPad() { + return pad; + } + + public void setPad(int value) { + this.pad = value; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public boolean isTreb() { + return isTreb; + } + + public void setTreb(boolean isTreb) { + this.isTreb = isTreb; + } + + public boolean isMangonal() { + return isMangonal; + } + + public void setMangonal(boolean isMangonal) { + this.isMangonal = isMangonal; + } + + public boolean isBallista() { + return isBallista; + } + + public void setBallista(boolean isBallista) { + this.isBallista = isBallista; + } + + public int getMinion() { + return minion; + } + + public void setMinion(int minion) { + this.minion = minion; + } + + public int getNpcID() { + return npcID; + } + + public void setNpcID(int npcID) { + this.npcID = npcID; + } + + public int getNpcType() { + return npcType; + } + + public void setNpcType(int npcType) { + this.npcType = npcType; + } + + public int getBuildingID() { + return buildingID; + } + + public void setBuildingID(int buildingID) { + this.buildingID = buildingID; + } + + public int getBuildingType() { + return buildingType; + } + + public void setBuildingType(int buildingType) { + this.buildingType = buildingType; + } + + public int getMobType() { + return mobType; + } + + public void setMobType(int mobType) { + this.mobType = mobType; + } + + public int getMobID() { + return mobID; + } + + public void setMobID(int mobID) { + this.mobID = mobID; + } } diff --git a/src/engine/net/client/msg/ModifyCommitToTradeMsg.java b/src/engine/net/client/msg/ModifyCommitToTradeMsg.java index 9e2c1b06..dad76a06 100644 --- a/src/engine/net/client/msg/ModifyCommitToTradeMsg.java +++ b/src/engine/net/client/msg/ModifyCommitToTradeMsg.java @@ -24,122 +24,119 @@ import engine.objects.AbstractGameObject; */ public class ModifyCommitToTradeMsg extends ClientNetMsg { - private int playerType; - private int playerID; - private int targetType; - private int targetID; - private byte commit1; - private byte commit2; - - /** - * This is the general purpose constructor - */ - public ModifyCommitToTradeMsg(AbstractGameObject player, AbstractGameObject target, byte commit1, byte commit2) { - super(Protocol.TRADECONFIRMSTATUS); + private int playerType; + private int playerID; + private int targetType; + private int targetID; + private byte commit1; + private byte commit2; + + /** + * This is the general purpose constructor + */ + public ModifyCommitToTradeMsg(AbstractGameObject player, AbstractGameObject target, byte commit1, byte commit2) { + super(Protocol.TRADECONFIRMSTATUS); this.playerType = player.getObjectType().ordinal(); this.playerID = player.getObjectUUID(); this.targetType = target.getObjectType().ordinal(); this.targetID = target.getObjectUUID(); this.commit1 = commit1; - this.commit2 = commit2; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public ModifyCommitToTradeMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.TRADECONFIRMSTATUS, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - this.playerType = reader.getInt(); - this.playerID = reader.getInt(); - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - commit1 = reader.get(); - commit2 = reader.get(); - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - writer.putInt(playerType); - writer.putInt(playerID); - writer.putInt(targetType); - writer.putInt(targetID); - writer.put(commit1); - writer.put(commit2); - } - - - - /** - * @return the commit1 - */ - public byte getCommit1() { - return commit1; - } - - /** - * @param commit1 the commit1 to set - */ - public void setCommit1(byte commit1) { - this.commit1 = commit1; - } - - /** - * @return the commit2 - */ - public byte getCommit2() { - return commit2; - } - - /** - * @param commit2 the commit2 to set - */ - public void setCommit2(byte commit2) { - this.commit2 = commit2; - } - - public int getPlayerType() { - return playerType; - } - - public void setPlayerType(int playerType) { - this.playerType = playerType; - } - - public int getPlayerID() { - return playerID; - } - - public void setPlayerID(int playerID) { - this.playerID = playerID; - } - - public int getTargetType() { - return targetType; - } - - public void setTargetType(int targetType) { - this.targetType = targetType; - } - - public int getTargetID() { - return targetID; - } - - public void setTargetID(int targetID) { - this.targetID = targetID; - } + this.commit2 = commit2; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public ModifyCommitToTradeMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.TRADECONFIRMSTATUS, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.playerType = reader.getInt(); + this.playerID = reader.getInt(); + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + commit1 = reader.get(); + commit2 = reader.get(); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putInt(playerType); + writer.putInt(playerID); + writer.putInt(targetType); + writer.putInt(targetID); + writer.put(commit1); + writer.put(commit2); + } + + + /** + * @return the commit1 + */ + public byte getCommit1() { + return commit1; + } + + /** + * @param commit1 the commit1 to set + */ + public void setCommit1(byte commit1) { + this.commit1 = commit1; + } + + /** + * @return the commit2 + */ + public byte getCommit2() { + return commit2; + } + + /** + * @param commit2 the commit2 to set + */ + public void setCommit2(byte commit2) { + this.commit2 = commit2; + } + + public int getPlayerType() { + return playerType; + } + + public void setPlayerType(int playerType) { + this.playerType = playerType; + } + + public int getPlayerID() { + return playerID; + } + + public void setPlayerID(int playerID) { + this.playerID = playerID; + } + + public int getTargetType() { + return targetType; + } + + public void setTargetType(int targetType) { + this.targetType = targetType; + } + + public int getTargetID() { + return targetID; + } + + public void setTargetID(int targetID) { + this.targetID = targetID; + } } diff --git a/src/engine/net/client/msg/ModifyHealthKillMsg.java b/src/engine/net/client/msg/ModifyHealthKillMsg.java index 4e0e74dd..e0de0498 100644 --- a/src/engine/net/client/msg/ModifyHealthKillMsg.java +++ b/src/engine/net/client/msg/ModifyHealthKillMsg.java @@ -18,219 +18,218 @@ import engine.objects.AbstractCharacter; public class ModifyHealthKillMsg extends ClientNetMsg { - private int trains; - private int unknownID; //effectID - private int sourceType; - private int sourceID; - private int targetType; - private int targetID; - private int unknown02 = 0; //1 heal, 0 hurt? - private int unknown03 = 0; //0=normalCast, 1to4=powerFailed, 5=targetIsImmune, 6=targetResisted - private int unknown04 = -1; - private int unknown05 = 0; - private byte unknownByte = (byte) 0; //0 - private int powerID; - private String powerName; - private float health; - private float healthMod; - private float mana; - private float manaMod; - private float stamina; - private float staminaMod; - - /** - * This is the general purpose constructor. - */ - - public ModifyHealthKillMsg(AbstractCharacter source, AbstractCharacter target, float healthMod, float manaMod, float staminaMod, int powerID, String powerName, int trains, int effectID) { - super(Protocol.POWERACTIONDDDIE); - if (source != null) { - this.sourceType = source.getObjectType().ordinal(); - this.sourceID = source.getObjectUUID(); - } else { - this.sourceType = 0; - this.sourceID = 0; - } - if (target != null) { - this.targetType = target.getObjectType().ordinal(); - this.targetID = target.getObjectUUID(); - this.health = target.getCurrentHitpoints(); - this.healthMod = healthMod; - this.mana = target.getMana(); - this.manaMod = manaMod; - this.stamina = target.getStamina(); - this.staminaMod = staminaMod; - } else { - this.targetType = 0; - this.targetID = 0; - this.health = 0; - this.healthMod = 0; - this.mana = 0; - this.manaMod = 0; - this.stamina = 0; - this.staminaMod = 0; - } - this.unknownID = effectID; - this.trains = trains; - this.powerID = powerID; - this.powerName = powerName; - - this.unknown02 = 0; - } - - //called for kills - public ModifyHealthKillMsg(AbstractCharacter source, AbstractCharacter target, int powerID, String powerName, int trains, int effectID) { - super(Protocol.POWERACTIONDDDIE); - if (source != null) { - this.sourceType = source.getObjectType().ordinal(); - this.sourceID = source.getObjectUUID(); - } else { - this.sourceType = 0; - this.sourceID = 0; - } - if (target != null) { - this.targetType = target.getObjectType().ordinal(); - this.targetID = target.getObjectUUID(); - this.mana = target.getMana(); - this.stamina = target.getStamina(); - } else { - this.targetType = 0; - this.targetID = 0; - this.mana = 0f; - this.stamina = 0f; - } - this.health = -50f; - this.healthMod = 0f; - this.manaMod = 0f; - this.staminaMod = 0f; - this.unknown02 = 0; - this.unknownID = effectID; - this.trains = trains; - this.powerID = powerID; - this.powerName = powerName; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public ModifyHealthKillMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.POWERACTIONDDDIE, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.trains); - writer.putInt(this.unknownID); - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.putInt(this.targetType); - writer.putInt(this.targetID); - writer.putInt(this.unknown02); - writer.putInt(this.unknown03); - writer.putInt(this.unknown04); - writer.putInt(this.unknown05); - writer.put(this.unknownByte); - writer.putInt(this.powerID); - writer.putString(this.powerName); - writer.putFloat(this.health); - writer.putFloat(this.healthMod); - writer.putFloat(this.mana); - writer.putFloat(this.manaMod); - writer.putFloat(this.stamina); - writer.putFloat(this.staminaMod); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.trains = reader.getInt(); - this.unknownID = reader.getInt(); - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - this.unknown02 = reader.getInt(); - this.unknown03 = reader.getInt(); - this.unknown04 = reader.getInt(); - this.unknown05 = reader.getInt(); - this.unknownByte = reader.get(); - this.powerID = reader.getInt(); - this.powerName = reader.getString(); - this.health = reader.getFloat(); - this.healthMod = reader.getFloat(); - this.mana = reader.getFloat(); - this.manaMod = reader.getFloat(); - this.stamina = reader.getFloat(); - this.staminaMod = reader.getFloat(); - } - - /** - * @return the sourceType - */ - public int getSourceType() { - return sourceType; - } - - /** - * @return the sourceID - */ - public int getSourceID() { - return sourceID; - } - - /** - * @return the targetType - */ - public int getTargetType() { - return targetType; - } - - public float getHealthMod() { - return healthMod; - } - - public float getManaMod() { - return manaMod; - } - - public float getStaminaMod() { - return manaMod; - } - - /** - * @return the targetID - */ - public int getTargetID() { - return targetID; - } - - public void setSourceType(int value) { - this.sourceType = value; - } - - public void setSourceID(int value) { - this.sourceID = value; - } - - public void setTargetType(int value) { - this.targetType = value; - } - - public void setTargetID(int value) { - this.targetID = value; - } - - public void setUnknown02(int value) { - this.unknown02 = value; - } - - public void setUnknown03(int value) { - this.unknown03 = value; - } + private int trains; + private int unknownID; //effectID + private int sourceType; + private int sourceID; + private int targetType; + private int targetID; + private int unknown02 = 0; //1 heal, 0 hurt? + private int unknown03 = 0; //0=normalCast, 1to4=powerFailed, 5=targetIsImmune, 6=targetResisted + private int unknown04 = -1; + private int unknown05 = 0; + private byte unknownByte = (byte) 0; //0 + private int powerID; + private String powerName; + private float health; + private float healthMod; + private float mana; + private float manaMod; + private float stamina; + private float staminaMod; + + /** + * This is the general purpose constructor. + */ + + public ModifyHealthKillMsg(AbstractCharacter source, AbstractCharacter target, float healthMod, float manaMod, float staminaMod, int powerID, String powerName, int trains, int effectID) { + super(Protocol.POWERACTIONDDDIE); + if (source != null) { + this.sourceType = source.getObjectType().ordinal(); + this.sourceID = source.getObjectUUID(); + } else { + this.sourceType = 0; + this.sourceID = 0; + } + if (target != null) { + this.targetType = target.getObjectType().ordinal(); + this.targetID = target.getObjectUUID(); + this.health = target.getCurrentHitpoints(); + this.healthMod = healthMod; + this.mana = target.getMana(); + this.manaMod = manaMod; + this.stamina = target.getStamina(); + this.staminaMod = staminaMod; + } else { + this.targetType = 0; + this.targetID = 0; + this.health = 0; + this.healthMod = 0; + this.mana = 0; + this.manaMod = 0; + this.stamina = 0; + this.staminaMod = 0; + } + this.unknownID = effectID; + this.trains = trains; + this.powerID = powerID; + this.powerName = powerName; + + this.unknown02 = 0; + } + + //called for kills + public ModifyHealthKillMsg(AbstractCharacter source, AbstractCharacter target, int powerID, String powerName, int trains, int effectID) { + super(Protocol.POWERACTIONDDDIE); + if (source != null) { + this.sourceType = source.getObjectType().ordinal(); + this.sourceID = source.getObjectUUID(); + } else { + this.sourceType = 0; + this.sourceID = 0; + } + if (target != null) { + this.targetType = target.getObjectType().ordinal(); + this.targetID = target.getObjectUUID(); + this.mana = target.getMana(); + this.stamina = target.getStamina(); + } else { + this.targetType = 0; + this.targetID = 0; + this.mana = 0f; + this.stamina = 0f; + } + this.health = -50f; + this.healthMod = 0f; + this.manaMod = 0f; + this.staminaMod = 0f; + this.unknown02 = 0; + this.unknownID = effectID; + this.trains = trains; + this.powerID = powerID; + this.powerName = powerName; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public ModifyHealthKillMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.POWERACTIONDDDIE, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.trains); + writer.putInt(this.unknownID); + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.putInt(this.targetType); + writer.putInt(this.targetID); + writer.putInt(this.unknown02); + writer.putInt(this.unknown03); + writer.putInt(this.unknown04); + writer.putInt(this.unknown05); + writer.put(this.unknownByte); + writer.putInt(this.powerID); + writer.putString(this.powerName); + writer.putFloat(this.health); + writer.putFloat(this.healthMod); + writer.putFloat(this.mana); + writer.putFloat(this.manaMod); + writer.putFloat(this.stamina); + writer.putFloat(this.staminaMod); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.trains = reader.getInt(); + this.unknownID = reader.getInt(); + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + this.unknown02 = reader.getInt(); + this.unknown03 = reader.getInt(); + this.unknown04 = reader.getInt(); + this.unknown05 = reader.getInt(); + this.unknownByte = reader.get(); + this.powerID = reader.getInt(); + this.powerName = reader.getString(); + this.health = reader.getFloat(); + this.healthMod = reader.getFloat(); + this.mana = reader.getFloat(); + this.manaMod = reader.getFloat(); + this.stamina = reader.getFloat(); + this.staminaMod = reader.getFloat(); + } + + /** + * @return the sourceType + */ + public int getSourceType() { + return sourceType; + } + + public void setSourceType(int value) { + this.sourceType = value; + } + + /** + * @return the sourceID + */ + public int getSourceID() { + return sourceID; + } + + public void setSourceID(int value) { + this.sourceID = value; + } + + /** + * @return the targetType + */ + public int getTargetType() { + return targetType; + } + + public void setTargetType(int value) { + this.targetType = value; + } + + public float getHealthMod() { + return healthMod; + } + + public float getManaMod() { + return manaMod; + } + + public float getStaminaMod() { + return manaMod; + } + + /** + * @return the targetID + */ + public int getTargetID() { + return targetID; + } + + public void setTargetID(int value) { + this.targetID = value; + } + + public void setUnknown02(int value) { + this.unknown02 = value; + } + + public void setUnknown03(int value) { + this.unknown03 = value; + } } diff --git a/src/engine/net/client/msg/ModifyHealthMsg.java b/src/engine/net/client/msg/ModifyHealthMsg.java index 77d8d176..39a9a94b 100644 --- a/src/engine/net/client/msg/ModifyHealthMsg.java +++ b/src/engine/net/client/msg/ModifyHealthMsg.java @@ -19,254 +19,253 @@ import engine.objects.Building; public class ModifyHealthMsg extends ClientNetMsg { - private int trains; - private int unknownID; //effectID - private int sourceType; - private int sourceID; - private int targetType; - private int targetID; - private int omitFromChat = 0; //1 heal, 0 hurt? - private int unknown03 = 0; //0=normalCast, 1to4=powerFailed, 5=targetIsImmune, 6=targetResisted - private int unknown04 = -1; - private int unknown05 = 0; - private byte unknownByte = (byte) 0; //0 - private int powerID; - private String powerName; - private float health; - private float healthMod; - private float mana; - private float manaMod; - private float stamina; - private float staminaMod; + private int trains; + private int unknownID; //effectID + private int sourceType; + private int sourceID; + private int targetType; + private int targetID; + private int omitFromChat = 0; //1 heal, 0 hurt? + private int unknown03 = 0; //0=normalCast, 1to4=powerFailed, 5=targetIsImmune, 6=targetResisted + private int unknown04 = -1; + private int unknown05 = 0; + private byte unknownByte = (byte) 0; //0 + private int powerID; + private String powerName; + private float health; + private float healthMod; + private float mana; + private float manaMod; + private float stamina; + private float staminaMod; - /** - * This is the general purpose constructor. - */ - public ModifyHealthMsg(AbstractCharacter source, Building target, float healthMod, float manaMod, float staminaMod, int powerID, String powerName, int trains, int effectID) { - super(Protocol.POWERACTIONDD); - if (source != null) { - this.sourceType = source.getObjectType().ordinal(); - this.sourceID = source.getObjectUUID(); - } else { - this.sourceType = 0; - this.sourceID = 0; - } - if (target != null) { - this.targetType = target.getObjectType().ordinal(); - this.targetID = target.getObjectUUID(); - this.health = target.getCurrentHitpoints(); - this.healthMod = healthMod; - this.mana = 0; - this.manaMod = 0; - this.stamina = 0; - this.staminaMod = 0; - } else { - this.targetType = 0; - this.targetID = 0; - this.health = 0; - this.healthMod = 0; - this.mana = 0; - this.manaMod = 0; - this.stamina = 0; - this.staminaMod = 0; - } - this.unknownID = effectID; - this.trains = trains; - this.powerID = powerID; - this.powerName = powerName; + /** + * This is the general purpose constructor. + */ + public ModifyHealthMsg(AbstractCharacter source, Building target, float healthMod, float manaMod, float staminaMod, int powerID, String powerName, int trains, int effectID) { + super(Protocol.POWERACTIONDD); + if (source != null) { + this.sourceType = source.getObjectType().ordinal(); + this.sourceID = source.getObjectUUID(); + } else { + this.sourceType = 0; + this.sourceID = 0; + } + if (target != null) { + this.targetType = target.getObjectType().ordinal(); + this.targetID = target.getObjectUUID(); + this.health = target.getCurrentHitpoints(); + this.healthMod = healthMod; + this.mana = 0; + this.manaMod = 0; + this.stamina = 0; + this.staminaMod = 0; + } else { + this.targetType = 0; + this.targetID = 0; + this.health = 0; + this.healthMod = 0; + this.mana = 0; + this.manaMod = 0; + this.stamina = 0; + this.staminaMod = 0; + } + this.unknownID = effectID; + this.trains = trains; + this.powerID = powerID; + this.powerName = powerName; - this.omitFromChat = 0; - } + this.omitFromChat = 0; + } - public ModifyHealthMsg(AbstractCharacter source, AbstractCharacter target, float healthMod, float manaMod, float staminaMod, int powerID, String powerName, int trains, int effectID) { - super(Protocol.POWERACTIONDD); - if (source != null) { - this.sourceType = source.getObjectType().ordinal(); - this.sourceID = source.getObjectUUID(); - } else { - this.sourceType = 0; - this.sourceID = 0; - } - if (target != null) { - this.targetType = target.getObjectType().ordinal(); - this.targetID = target.getObjectUUID(); - this.health = target.getCurrentHitpoints(); - this.healthMod = healthMod; - this.mana = target.getMana(); - this.manaMod = manaMod; - this.stamina = target.getStamina(); - this.staminaMod = staminaMod; - } else { - this.targetType = 0; - this.targetID = 0; - this.health = 0; - this.healthMod = 0; - this.mana = 0; - this.manaMod = 0; - this.stamina = 0; - this.staminaMod = 0; - } - this.unknownID = effectID; - this.trains = trains; - this.powerID = powerID; - this.powerName = powerName; + public ModifyHealthMsg(AbstractCharacter source, AbstractCharacter target, float healthMod, float manaMod, float staminaMod, int powerID, String powerName, int trains, int effectID) { + super(Protocol.POWERACTIONDD); + if (source != null) { + this.sourceType = source.getObjectType().ordinal(); + this.sourceID = source.getObjectUUID(); + } else { + this.sourceType = 0; + this.sourceID = 0; + } + if (target != null) { + this.targetType = target.getObjectType().ordinal(); + this.targetID = target.getObjectUUID(); + this.health = target.getCurrentHitpoints(); + this.healthMod = healthMod; + this.mana = target.getMana(); + this.manaMod = manaMod; + this.stamina = target.getStamina(); + this.staminaMod = staminaMod; + } else { + this.targetType = 0; + this.targetID = 0; + this.health = 0; + this.healthMod = 0; + this.mana = 0; + this.manaMod = 0; + this.stamina = 0; + this.staminaMod = 0; + } + this.unknownID = effectID; + this.trains = trains; + this.powerID = powerID; + this.powerName = powerName; - this.omitFromChat = 0; - } + this.omitFromChat = 0; + } - //called for kills - public ModifyHealthMsg(AbstractCharacter source, AbstractCharacter target, int powerID, String powerName, int trains, int effectID) { - super(Protocol.POWERACTIONDD); - if (source != null) { - this.sourceType = source.getObjectType().ordinal(); - this.sourceID = source.getObjectUUID(); - } else { - this.sourceType = 0; - this.sourceID = 0; - } - if (target != null) { - this.targetType = target.getObjectType().ordinal(); - this.targetID = target.getObjectUUID(); - this.mana = target.getMana(); - this.stamina = target.getStamina(); - } else { - this.targetType = 0; - this.targetID = 0; - this.mana = 0f; - this.stamina = 0f; - } - this.health = -50f; - this.healthMod = 0f; - this.manaMod = 0f; - this.staminaMod = 0f; - this.omitFromChat = 0; - this.unknownID = effectID; - this.trains = trains; - this.powerID = powerID; - this.powerName = powerName; - } + //called for kills + public ModifyHealthMsg(AbstractCharacter source, AbstractCharacter target, int powerID, String powerName, int trains, int effectID) { + super(Protocol.POWERACTIONDD); + if (source != null) { + this.sourceType = source.getObjectType().ordinal(); + this.sourceID = source.getObjectUUID(); + } else { + this.sourceType = 0; + this.sourceID = 0; + } + if (target != null) { + this.targetType = target.getObjectType().ordinal(); + this.targetID = target.getObjectUUID(); + this.mana = target.getMana(); + this.stamina = target.getStamina(); + } else { + this.targetType = 0; + this.targetID = 0; + this.mana = 0f; + this.stamina = 0f; + } + this.health = -50f; + this.healthMod = 0f; + this.manaMod = 0f; + this.staminaMod = 0f; + this.omitFromChat = 0; + this.unknownID = effectID; + this.trains = trains; + this.powerID = powerID; + this.powerName = powerName; + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public ModifyHealthMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.POWERACTIONDD, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public ModifyHealthMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.POWERACTIONDD, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.trains); - writer.putInt(this.unknownID); - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.putInt(this.targetType); - writer.putInt(this.targetID); - writer.putInt(this.omitFromChat); - writer.putInt(this.unknown03); - writer.putInt(this.unknown04); - writer.putInt(this.unknown05); - writer.put(this.unknownByte); - writer.putInt(this.powerID); - writer.putString(this.powerName); - writer.putFloat(this.health); - writer.putFloat(this.healthMod); - writer.putFloat(this.mana); - writer.putFloat(this.manaMod); - writer.putFloat(this.stamina); - writer.putFloat(this.staminaMod); - } + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.trains); + writer.putInt(this.unknownID); + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.putInt(this.targetType); + writer.putInt(this.targetID); + writer.putInt(this.omitFromChat); + writer.putInt(this.unknown03); + writer.putInt(this.unknown04); + writer.putInt(this.unknown05); + writer.put(this.unknownByte); + writer.putInt(this.powerID); + writer.putString(this.powerName); + writer.putFloat(this.health); + writer.putFloat(this.healthMod); + writer.putFloat(this.mana); + writer.putFloat(this.manaMod); + writer.putFloat(this.stamina); + writer.putFloat(this.staminaMod); + } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.trains = reader.getInt(); - this.unknownID = reader.getInt(); - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - this.omitFromChat = reader.getInt(); - this.unknown03 = reader.getInt(); - this.unknown04 = reader.getInt(); - this.unknown05 = reader.getInt(); - this.unknownByte = reader.get(); - this.powerID = reader.getInt(); - this.powerName = reader.getString(); - this.health = reader.getFloat(); - this.healthMod = reader.getFloat(); - this.mana = reader.getFloat(); - this.manaMod = reader.getFloat(); - this.stamina = reader.getFloat(); - this.staminaMod = reader.getFloat(); - } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.trains = reader.getInt(); + this.unknownID = reader.getInt(); + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + this.omitFromChat = reader.getInt(); + this.unknown03 = reader.getInt(); + this.unknown04 = reader.getInt(); + this.unknown05 = reader.getInt(); + this.unknownByte = reader.get(); + this.powerID = reader.getInt(); + this.powerName = reader.getString(); + this.health = reader.getFloat(); + this.healthMod = reader.getFloat(); + this.mana = reader.getFloat(); + this.manaMod = reader.getFloat(); + this.stamina = reader.getFloat(); + this.staminaMod = reader.getFloat(); + } - /** - * @return the sourceType - */ - public int getSourceType() { - return sourceType; - } + /** + * @return the sourceType + */ + public int getSourceType() { + return sourceType; + } - /** - * @return the sourceID - */ - public int getSourceID() { - return sourceID; - } + public void setSourceType(int value) { + this.sourceType = value; + } - /** - * @return the targetType - */ - public int getTargetType() { - return targetType; - } + /** + * @return the sourceID + */ + public int getSourceID() { + return sourceID; + } - public float getHealthMod() { - return healthMod; - } + public void setSourceID(int value) { + this.sourceID = value; + } - public float getManaMod() { - return manaMod; - } + /** + * @return the targetType + */ + public int getTargetType() { + return targetType; + } - public float getStaminaMod() { - return manaMod; - } + public void setTargetType(int value) { + this.targetType = value; + } - /** - * @return the targetID - */ - public int getTargetID() { - return targetID; - } + public float getHealthMod() { + return healthMod; + } - public void setSourceType(int value) { - this.sourceType = value; - } + public float getManaMod() { + return manaMod; + } - public void setSourceID(int value) { - this.sourceID = value; - } + public float getStaminaMod() { + return manaMod; + } - public void setTargetType(int value) { - this.targetType = value; - } + /** + * @return the targetID + */ + public int getTargetID() { + return targetID; + } - public void setTargetID(int value) { - this.targetID = value; - } + public void setTargetID(int value) { + this.targetID = value; + } - public void setOmitFromChat(int value) { - this.omitFromChat = value; - } + public void setOmitFromChat(int value) { + this.omitFromChat = value; + } - public void setUnknown03(int value) { - this.unknown03 = value; - } + public void setUnknown03(int value) { + this.unknown03 = value; + } } diff --git a/src/engine/net/client/msg/ModifyStatMsg.java b/src/engine/net/client/msg/ModifyStatMsg.java index 7b5909ca..f01ff56c 100644 --- a/src/engine/net/client/msg/ModifyStatMsg.java +++ b/src/engine/net/client/msg/ModifyStatMsg.java @@ -17,75 +17,75 @@ import engine.net.client.Protocol; public class ModifyStatMsg extends ClientNetMsg { - private int amount; - private int type; - private int unknown01; - - /** - * This is the general purpose constructor. - */ - public ModifyStatMsg() { - super(Protocol.RAISEATTR); - } - - public ModifyStatMsg(int amount, int type, int unknown01) { - super(Protocol.RAISEATTR); - this.amount = amount; - this.type = type; - this.unknown01 = unknown01; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ModifyStatMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.RAISEATTR, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.amount); - writer.putInt(this.type); - writer.putInt(this.unknown01); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.amount = reader.getInt(); - this.type = reader.getInt(); - this.unknown01 = reader.getInt(); - } - - public int getAmount() { - return this.amount; - } - - public int getType() { - return this.type; - } - - public int getUnknown01() { - return this.unknown01; - } - - public void setAmount(int value) { - this.amount = value; - } - - public void setType(int value) { - this.type = value; - } - - public void setUnknown01(int value) { - this.unknown01 = value; - } + private int amount; + private int type; + private int unknown01; + + /** + * This is the general purpose constructor. + */ + public ModifyStatMsg() { + super(Protocol.RAISEATTR); + } + + public ModifyStatMsg(int amount, int type, int unknown01) { + super(Protocol.RAISEATTR); + this.amount = amount; + this.type = type; + this.unknown01 = unknown01; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ModifyStatMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.RAISEATTR, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.amount); + writer.putInt(this.type); + writer.putInt(this.unknown01); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.amount = reader.getInt(); + this.type = reader.getInt(); + this.unknown01 = reader.getInt(); + } + + public int getAmount() { + return this.amount; + } + + public void setAmount(int value) { + this.amount = value; + } + + public int getType() { + return this.type; + } + + public void setType(int value) { + this.type = value; + } + + public int getUnknown01() { + return this.unknown01; + } + + public void setUnknown01(int value) { + this.unknown01 = value; + } } diff --git a/src/engine/net/client/msg/MoveCorrectionMsg.java b/src/engine/net/client/msg/MoveCorrectionMsg.java index e527df67..67618bd8 100644 --- a/src/engine/net/client/msg/MoveCorrectionMsg.java +++ b/src/engine/net/client/msg/MoveCorrectionMsg.java @@ -19,208 +19,208 @@ import engine.objects.AbstractCharacter; public class MoveCorrectionMsg extends ClientNetMsg { - private int sourceType; - private int sourceID; - private float startLat; - private float startAlt; - private float startLon; - private float endLat; - private float endAlt; - private float endLon; - private int unknown01 = 2; - private int unknown02 = 0; - private int unknown03 = 0; - - /** - * This is the general purpose constructor. - */ - public MoveCorrectionMsg(AbstractCharacter ac, boolean teleport) { - super(Protocol.MOVECORRECTION); - this.sourceType = ac.getObjectType().ordinal(); - this.sourceID = ac.getObjectUUID(); - this.startLat = ac.getLoc().x; - this.startAlt = ac.getLoc().y; - this.startLon = ac.getLoc().z; - if (teleport){ - this.endLat = ac.getLoc().x; - this.endAlt = ac.getLoc().y; - this.endLon = ac.getLoc().z; - }else{ - if (ac.isMoving()){ - this.endLat = ac.getEndLoc().x; - this.endAlt = ac.getEndLoc().y; - this.endLon = ac.getEndLoc().z; - }else{ - this.endLat = ac.getLoc().x; - this.endAlt = ac.getLoc().y; - this.endLon = ac.getLoc().z; - } - } - - this.unknown01 = Float.floatToIntBits(ac.getAltitude()); - this.unknown02 =Float.floatToIntBits(ac.getAltitude()); - this.unknown03 = Float.floatToIntBits(ac.getAltitude()); - - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public MoveCorrectionMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.MOVECORRECTION, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - - writer.putFloat(this.startLat); - writer.putFloat(this.startAlt); - writer.putFloat(this.startLon); - - writer.putFloat(this.endLat); - writer.putFloat(this.endAlt); - writer.putFloat(this.endLon); - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - writer.putInt(this.unknown03); - - - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - - this.startLat = reader.getFloat(); - this.startAlt = reader.getFloat(); - this.startLon = reader.getFloat(); - - this.endLat = reader.getFloat(); - this.endAlt = reader.getFloat(); - this.endLon = reader.getFloat(); - - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - this.unknown03 = reader.getInt(); - - } - - public int getSourceType() { - return this.sourceType; - } - - public int getSourceID() { - return this.sourceID; - } - - public float getStartLat() { - return this.startLat; - } - - public float getStartLon() { - return this.startLon; - } - - public float getStartAlt() { - return this.startAlt; - } - - public float getEndLat() { - return this.endLat; - } - - public float getEndLon() { - return this.endLon; - } - - public float getEndAlt() { - return this.endAlt; - } - - public int getUnknown01() { - return this.unknown01; - } - - public int getUnknown02() { - return this.unknown01; - } - - public int getUnknown03() { - return this.unknown01; - } - - public void setSourceType(int value) { - this.sourceType = value; - } - - public void setSourceID(int value) { - this.sourceID = value; - } - - public void setStartLat(float value) { - this.startLat = value; - } - - public void setStartLon(float value) { - this.startLon = value; - } - - public void setStartAlt(float value) { - this.startAlt = value; - } - - public void setStartCoord(Vector3fImmutable value) { - this.startLat = value.x; - this.startAlt = value.y; - this.startLon = value.z; - } - - public void setEndLat(float value) { - this.endLat = value; - } - - public void setEndLon(float value) { - this.endLon = value; - } - - public void setEndAlt(float value) { - this.endAlt = value; - } - - public void setEndCoord(Vector3fImmutable value) { - this.endLat = value.x; - this.endAlt = value.y; - this.endLon = value.z; - } - - public void setUnknown01(int value) { - this.unknown01 = value; - } - - public void setUnknown02(int value) { - this.unknown02 = value; - } - - public void setUnknown03(int value) { - this.unknown03 = value; - } - - public void setPlayer(AbstractCharacter ac) { - this.sourceType = 85; - this.sourceID = ac.getObjectUUID(); - this.setStartCoord(ac.getLoc()); - this.setEndCoord(ac.getEndLoc()); - } + private int sourceType; + private int sourceID; + private float startLat; + private float startAlt; + private float startLon; + private float endLat; + private float endAlt; + private float endLon; + private int unknown01 = 2; + private int unknown02 = 0; + private int unknown03 = 0; + + /** + * This is the general purpose constructor. + */ + public MoveCorrectionMsg(AbstractCharacter ac, boolean teleport) { + super(Protocol.MOVECORRECTION); + this.sourceType = ac.getObjectType().ordinal(); + this.sourceID = ac.getObjectUUID(); + this.startLat = ac.getLoc().x; + this.startAlt = ac.getLoc().y; + this.startLon = ac.getLoc().z; + if (teleport) { + this.endLat = ac.getLoc().x; + this.endAlt = ac.getLoc().y; + this.endLon = ac.getLoc().z; + } else { + if (ac.isMoving()) { + this.endLat = ac.getEndLoc().x; + this.endAlt = ac.getEndLoc().y; + this.endLon = ac.getEndLoc().z; + } else { + this.endLat = ac.getLoc().x; + this.endAlt = ac.getLoc().y; + this.endLon = ac.getLoc().z; + } + } + + this.unknown01 = Float.floatToIntBits(ac.getAltitude()); + this.unknown02 = Float.floatToIntBits(ac.getAltitude()); + this.unknown03 = Float.floatToIntBits(ac.getAltitude()); + + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public MoveCorrectionMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.MOVECORRECTION, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + + writer.putFloat(this.startLat); + writer.putFloat(this.startAlt); + writer.putFloat(this.startLon); + + writer.putFloat(this.endLat); + writer.putFloat(this.endAlt); + writer.putFloat(this.endLon); + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + writer.putInt(this.unknown03); + + + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + + this.startLat = reader.getFloat(); + this.startAlt = reader.getFloat(); + this.startLon = reader.getFloat(); + + this.endLat = reader.getFloat(); + this.endAlt = reader.getFloat(); + this.endLon = reader.getFloat(); + + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + this.unknown03 = reader.getInt(); + + } + + public int getSourceType() { + return this.sourceType; + } + + public void setSourceType(int value) { + this.sourceType = value; + } + + public int getSourceID() { + return this.sourceID; + } + + public void setSourceID(int value) { + this.sourceID = value; + } + + public float getStartLat() { + return this.startLat; + } + + public void setStartLat(float value) { + this.startLat = value; + } + + public float getStartLon() { + return this.startLon; + } + + public void setStartLon(float value) { + this.startLon = value; + } + + public float getStartAlt() { + return this.startAlt; + } + + public void setStartAlt(float value) { + this.startAlt = value; + } + + public float getEndLat() { + return this.endLat; + } + + public void setEndLat(float value) { + this.endLat = value; + } + + public float getEndLon() { + return this.endLon; + } + + public void setEndLon(float value) { + this.endLon = value; + } + + public float getEndAlt() { + return this.endAlt; + } + + public void setEndAlt(float value) { + this.endAlt = value; + } + + public int getUnknown01() { + return this.unknown01; + } + + public void setUnknown01(int value) { + this.unknown01 = value; + } + + public int getUnknown02() { + return this.unknown01; + } + + public void setUnknown02(int value) { + this.unknown02 = value; + } + + public int getUnknown03() { + return this.unknown01; + } + + public void setUnknown03(int value) { + this.unknown03 = value; + } + + public void setStartCoord(Vector3fImmutable value) { + this.startLat = value.x; + this.startAlt = value.y; + this.startLon = value.z; + } + + public void setEndCoord(Vector3fImmutable value) { + this.endLat = value.x; + this.endAlt = value.y; + this.endLon = value.z; + } + + public void setPlayer(AbstractCharacter ac) { + this.sourceType = 85; + this.sourceID = ac.getObjectUUID(); + this.setStartCoord(ac.getLoc()); + this.setEndCoord(ac.getEndLoc()); + } } diff --git a/src/engine/net/client/msg/MoveToPointMsg.java b/src/engine/net/client/msg/MoveToPointMsg.java index 4a22fa01..4a6c08dd 100644 --- a/src/engine/net/client/msg/MoveToPointMsg.java +++ b/src/engine/net/client/msg/MoveToPointMsg.java @@ -21,285 +21,284 @@ import engine.objects.Building; public class MoveToPointMsg extends ClientNetMsg { - private int sourceType; - private int sourceID; - private float startLat; - private float startLon; - private float startAlt; - private float endLat; - private float endLon; - private float endAlt; - private int targetType; - private int targetID; - private int inBuilding; // 0=true, -1=false 0/1/2 = floor you are on - private int unknown01; - private byte unknown02; - private byte unknown03; - - /** - * This is the general purpose constructor. - */ - public MoveToPointMsg() { - super(Protocol.MOVETOPOINT); - } - - - - public MoveToPointMsg(MoveToPointMsg msg) { - super(Protocol.MOVETOPOINT); - this.sourceType = msg.sourceType; - this.sourceID = msg.sourceID; - this.startLat = msg.startLat; - this.startLon = msg.startLon; - this.startAlt = msg.startAlt; - this.endLat = msg.endLat; - this.endLon = msg.endLon; - this.endAlt = msg.endAlt; - this.targetType = msg.targetType; - this.targetID = msg.targetID; - this.inBuilding = msg.inBuilding; - this.unknown01 = msg.unknown01; - this.unknown02 = msg.unknown02; - this.unknown03 = msg.unknown03; - } - //Moving Furniture out of building to unload properly. //for outside regions only - public MoveToPointMsg(Building building) { - super(Protocol.MOVETOPOINT); - this.sourceType = building.getObjectType().ordinal(); - this.sourceID = building.getObjectUUID(); - this.startLat = building.getLoc().x; - this.startLon = building.getLoc().z; - this.startAlt = building.getLoc().y; - this.endLat = building.getLoc().x; - this.endLon = building.getLoc().z; - this.endAlt = building.getLoc().y; - this.targetType = 0; - this.targetID = 0; - this.inBuilding = -1; - this.unknown01 = -1; - this.unknown02 = 0; - this.unknown03 = 0; - } - - - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public MoveToPointMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.MOVETOPOINT, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - - writer.putFloat(this.startLat); - writer.putFloat(this.startAlt); - writer.putFloat(this.startLon); - - writer.putFloat(this.endLat); - writer.putFloat(this.endAlt); - writer.putFloat(this.endLon); - - writer.putInt(this.targetType); - writer.putInt(this.targetID); - - writer.putInt(this.inBuilding); - writer.putInt(this.unknown01); - - writer.put((byte)0); - writer.put((byte)0); - - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - - this.startLat = reader.getFloat(); - this.startAlt = reader.getFloat(); - this.startLon = reader.getFloat(); - - this.endLat = reader.getFloat(); - this.endAlt = reader.getFloat(); - this.endLon = reader.getFloat(); - - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - - this.inBuilding = reader.getInt(); - this.unknown01 = reader.getInt(); - - this.unknown02 = reader.get(); - this.unknown03 = reader.get(); - } - - public int getSourceType() { - return this.sourceType; - } - - public int getSourceID() { - return this.sourceID; - } - - public float getStartLat() { - return this.startLat; - } - - public float getStartLon() { - return this.startLon; - } - - public float getStartAlt() { - return this.startAlt; - } - - public float getEndLat() { - return this.endLat; - } - - public float getEndLon() { - return this.endLon; - } - - public float getEndAlt() { - return this.endAlt; - } - - public int getTargetType() { - return this.targetType; - } - - public int getTargetID() { - return this.targetID; - } - - public int getInBuilding() { - return this.inBuilding; - } - - public int getUnknown01() { - return this.unknown01; - } - - public void setSourceType(int value) { - this.sourceType = value; - } - - public void setSourceID(int value) { - this.sourceID = value; - } - - public void setStartLat(float value) { - this.startLat = value; - } - - public void setStartLon(float value) { - this.startLon = value; - } - - public void setStartAlt(float value) { - this.startAlt = value; - } - - public void setStartCoord(Vector3fImmutable value) { - this.startLat = value.x; - this.startAlt = value.y; - this.startLon = value.z; - } - - public void setEndLat(float value) { - this.endLat = value; - } - - public void setEndLon(float value) { - this.endLon = value; - } - - public void setEndAlt(float value) { - this.endAlt = value; - } - - public void setEndCoord(Vector3fImmutable value) { - this.endLat = value.x; - this.endAlt = value.y; - this.endLon = value.z; - } - - public void setTargetType(int value) { - this.targetType = value; - } - - public void setTargetID(int value) { - this.targetID = value; - } - - public void clearTarget() { - this.targetType = 0; - this.targetID = 0; - } - - public void setInBuilding(int value) { - this.inBuilding = value; - } - - public void setUnknown01(int value) { - this.unknown01 = value; - } - - public void setPlayer(AbstractCharacter ac) { - this.sourceType = ac.getObjectType().ordinal(); - this.sourceID = ac.getObjectUUID(); - this.setStartCoord(ac.getLoc()); - this.setEndCoord(ac.getEndLoc()); - this.targetType = 0; - this.targetID = 0; - this.inBuilding = ac.getInBuilding(); - this.unknown01 = ac.getInFloorID(); - - } - - public void setTarget(AbstractCharacter ac, Building target){ - if (target == null){ - this.setStartCoord(ac.getLoc()); - this.setEndCoord(ac.getEndLoc()); - this.targetType = 0; - this.targetID = 0; - this.inBuilding = -1; - this.unknown01 = -1; - }else{ - Vector3fImmutable convertLocStart = ZoneManager.convertWorldToLocal(target, ac.getLoc()); - Vector3fImmutable convertLocEnd = convertLocStart; - if (ac.isMoving()) - convertLocEnd = ZoneManager.convertWorldToLocal(target, ac.getEndLoc()); - - this.setStartCoord(convertLocStart); - this.setEndCoord(convertLocEnd); - this.targetType = GameObjectType.Building.ordinal(); - this.targetID = target.getObjectUUID(); - this.inBuilding = ac.getInBuilding(); - this.unknown01 = ac.getInFloorID(); - } - - } - - public int getUnknown03() { - return unknown03; - } - - public int getUnknown02() { - return unknown02; - } + private int sourceType; + private int sourceID; + private float startLat; + private float startLon; + private float startAlt; + private float endLat; + private float endLon; + private float endAlt; + private int targetType; + private int targetID; + private int inBuilding; // 0=true, -1=false 0/1/2 = floor you are on + private int unknown01; + private byte unknown02; + private byte unknown03; + + /** + * This is the general purpose constructor. + */ + public MoveToPointMsg() { + super(Protocol.MOVETOPOINT); + } + + + public MoveToPointMsg(MoveToPointMsg msg) { + super(Protocol.MOVETOPOINT); + this.sourceType = msg.sourceType; + this.sourceID = msg.sourceID; + this.startLat = msg.startLat; + this.startLon = msg.startLon; + this.startAlt = msg.startAlt; + this.endLat = msg.endLat; + this.endLon = msg.endLon; + this.endAlt = msg.endAlt; + this.targetType = msg.targetType; + this.targetID = msg.targetID; + this.inBuilding = msg.inBuilding; + this.unknown01 = msg.unknown01; + this.unknown02 = msg.unknown02; + this.unknown03 = msg.unknown03; + } + + //Moving Furniture out of building to unload properly. //for outside regions only + public MoveToPointMsg(Building building) { + super(Protocol.MOVETOPOINT); + this.sourceType = building.getObjectType().ordinal(); + this.sourceID = building.getObjectUUID(); + this.startLat = building.getLoc().x; + this.startLon = building.getLoc().z; + this.startAlt = building.getLoc().y; + this.endLat = building.getLoc().x; + this.endLon = building.getLoc().z; + this.endAlt = building.getLoc().y; + this.targetType = 0; + this.targetID = 0; + this.inBuilding = -1; + this.unknown01 = -1; + this.unknown02 = 0; + this.unknown03 = 0; + } + + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public MoveToPointMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.MOVETOPOINT, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + + writer.putFloat(this.startLat); + writer.putFloat(this.startAlt); + writer.putFloat(this.startLon); + + writer.putFloat(this.endLat); + writer.putFloat(this.endAlt); + writer.putFloat(this.endLon); + + writer.putInt(this.targetType); + writer.putInt(this.targetID); + + writer.putInt(this.inBuilding); + writer.putInt(this.unknown01); + + writer.put((byte) 0); + writer.put((byte) 0); + + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + + this.startLat = reader.getFloat(); + this.startAlt = reader.getFloat(); + this.startLon = reader.getFloat(); + + this.endLat = reader.getFloat(); + this.endAlt = reader.getFloat(); + this.endLon = reader.getFloat(); + + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + + this.inBuilding = reader.getInt(); + this.unknown01 = reader.getInt(); + + this.unknown02 = reader.get(); + this.unknown03 = reader.get(); + } + + public int getSourceType() { + return this.sourceType; + } + + public void setSourceType(int value) { + this.sourceType = value; + } + + public int getSourceID() { + return this.sourceID; + } + + public void setSourceID(int value) { + this.sourceID = value; + } + + public float getStartLat() { + return this.startLat; + } + + public void setStartLat(float value) { + this.startLat = value; + } + + public float getStartLon() { + return this.startLon; + } + + public void setStartLon(float value) { + this.startLon = value; + } + + public float getStartAlt() { + return this.startAlt; + } + + public void setStartAlt(float value) { + this.startAlt = value; + } + + public float getEndLat() { + return this.endLat; + } + + public void setEndLat(float value) { + this.endLat = value; + } + + public float getEndLon() { + return this.endLon; + } + + public void setEndLon(float value) { + this.endLon = value; + } + + public float getEndAlt() { + return this.endAlt; + } + + public void setEndAlt(float value) { + this.endAlt = value; + } + + public int getTargetType() { + return this.targetType; + } + + public void setTargetType(int value) { + this.targetType = value; + } + + public int getTargetID() { + return this.targetID; + } + + public void setTargetID(int value) { + this.targetID = value; + } + + public int getInBuilding() { + return this.inBuilding; + } + + public void setInBuilding(int value) { + this.inBuilding = value; + } + + public int getUnknown01() { + return this.unknown01; + } + + public void setUnknown01(int value) { + this.unknown01 = value; + } + + public void setStartCoord(Vector3fImmutable value) { + this.startLat = value.x; + this.startAlt = value.y; + this.startLon = value.z; + } + + public void setEndCoord(Vector3fImmutable value) { + this.endLat = value.x; + this.endAlt = value.y; + this.endLon = value.z; + } + + public void clearTarget() { + this.targetType = 0; + this.targetID = 0; + } + + public void setPlayer(AbstractCharacter ac) { + this.sourceType = ac.getObjectType().ordinal(); + this.sourceID = ac.getObjectUUID(); + this.setStartCoord(ac.getLoc()); + this.setEndCoord(ac.getEndLoc()); + this.targetType = 0; + this.targetID = 0; + this.inBuilding = ac.getInBuilding(); + this.unknown01 = ac.getInFloorID(); + + } + + public void setTarget(AbstractCharacter ac, Building target) { + if (target == null) { + this.setStartCoord(ac.getLoc()); + this.setEndCoord(ac.getEndLoc()); + this.targetType = 0; + this.targetID = 0; + this.inBuilding = -1; + this.unknown01 = -1; + } else { + Vector3fImmutable convertLocStart = ZoneManager.convertWorldToLocal(target, ac.getLoc()); + Vector3fImmutable convertLocEnd = convertLocStart; + if (ac.isMoving()) + convertLocEnd = ZoneManager.convertWorldToLocal(target, ac.getEndLoc()); + + this.setStartCoord(convertLocStart); + this.setEndCoord(convertLocEnd); + this.targetType = GameObjectType.Building.ordinal(); + this.targetID = target.getObjectUUID(); + this.inBuilding = ac.getInBuilding(); + this.unknown01 = ac.getInFloorID(); + } + + } + + public int getUnknown03() { + return unknown03; + } + + public int getUnknown02() { + return unknown02; + } } diff --git a/src/engine/net/client/msg/ObjectActionMsg.java b/src/engine/net/client/msg/ObjectActionMsg.java index c1a66dcd..44429666 100644 --- a/src/engine/net/client/msg/ObjectActionMsg.java +++ b/src/engine/net/client/msg/ObjectActionMsg.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -38,94 +35,92 @@ import java.util.ArrayList; */ public class ObjectActionMsg extends ClientNetMsg { - private int unknown01; - private int unknown02; - private ArrayList targetCompID; - - /** - * This is the general purpose constructor - */ - public ObjectActionMsg(int unknown01, int unknown02, ArrayList targetCompID) { - super(Protocol.OBJECTACTION); - this.unknown01 = unknown01; - this.unknown02 = unknown02; - this.targetCompID = targetCompID; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public ObjectActionMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.OBJECTACTION, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - if (targetCompID == null) - targetCompID = new ArrayList<>(); - unknown01 = reader.getInt(); - unknown02 = reader.getInt(); - for (int i=0; i getTargetCompID() { - return targetCompID; - } - - /** - * @param targetCompID the targetCompID to set - */ - public void setTargetCompID(ArrayList targetCompID) { - this.targetCompID = targetCompID; - } + private int unknown01; + private int unknown02; + private ArrayList targetCompID; + + /** + * This is the general purpose constructor + */ + public ObjectActionMsg(int unknown01, int unknown02, ArrayList targetCompID) { + super(Protocol.OBJECTACTION); + this.unknown01 = unknown01; + this.unknown02 = unknown02; + this.targetCompID = targetCompID; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public ObjectActionMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.OBJECTACTION, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + if (targetCompID == null) + targetCompID = new ArrayList<>(); + unknown01 = reader.getInt(); + unknown02 = reader.getInt(); + for (int i = 0; i < unknown01; i++) + targetCompID.add(reader.getLong()); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putInt(unknown01); + writer.putInt(unknown02); + for (int i = 0; i < unknown01; i++) + writer.putLong(targetCompID.get(i)); + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the unknown02 + */ + public int getUnknown02() { + return unknown02; + } + + /** + * @param unknown02 the unknown02 to set + */ + public void setUnknown02(int unknown02) { + this.unknown02 = unknown02; + } + + /** + * @return the targetCompID + */ + public ArrayList getTargetCompID() { + return targetCompID; + } + + /** + * @param targetCompID the targetCompID to set + */ + public void setTargetCompID(ArrayList targetCompID) { + this.targetCompID = targetCompID; + } } diff --git a/src/engine/net/client/msg/OpenFriendsCondemnListMsg.java b/src/engine/net/client/msg/OpenFriendsCondemnListMsg.java index b73dd300..f6eaefad 100644 --- a/src/engine/net/client/msg/OpenFriendsCondemnListMsg.java +++ b/src/engine/net/client/msg/OpenFriendsCondemnListMsg.java @@ -24,35 +24,35 @@ import java.util.concurrent.ConcurrentHashMap; public class OpenFriendsCondemnListMsg extends ClientNetMsg { - private int messageType; + private int messageType; private ArrayList characterList; - private int buildingType; - private int buildingID; - - private int playerType; - private int playerID; - private int guildID; - private int inviteType; - private ConcurrentHashMapfriends; - private int removeFriendType; - private int removeFriendID; - private boolean reverseKOS; //TODO Rename this for to fit ReverseKOS/Activate/deactive Condemned. - private ConcurrentHashMap guildCondemned; - private int nationID; - - public OpenFriendsCondemnListMsg(int messageType,ConcurrentHashMapfriends) { - super(Protocol.OPENFRIENDSCONDEMNLIST); - this.messageType = messageType; - this.friends = friends; - - } - - public OpenFriendsCondemnListMsg(int messageType,ConcurrentHashMap guildCondemned ,boolean reverse) { - super(Protocol.OPENFRIENDSCONDEMNLIST); - this.messageType = messageType; - this.guildCondemned = guildCondemned; - this.reverseKOS = reverse; - } + private int buildingType; + private int buildingID; + + private int playerType; + private int playerID; + private int guildID; + private int inviteType; + private ConcurrentHashMap friends; + private int removeFriendType; + private int removeFriendID; + private boolean reverseKOS; //TODO Rename this for to fit ReverseKOS/Activate/deactive Condemned. + private ConcurrentHashMap guildCondemned; + private int nationID; + + public OpenFriendsCondemnListMsg(int messageType, ConcurrentHashMap friends) { + super(Protocol.OPENFRIENDSCONDEMNLIST); + this.messageType = messageType; + this.friends = friends; + + } + + public OpenFriendsCondemnListMsg(int messageType, ConcurrentHashMap guildCondemned, boolean reverse) { + super(Protocol.OPENFRIENDSCONDEMNLIST); + this.messageType = messageType; + this.guildCondemned = guildCondemned; + this.reverseKOS = reverse; + } // clone @@ -74,6 +74,17 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg { this.characterList = openFriendsCondemnListMsg.characterList; } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public OpenFriendsCondemnListMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.OPENFRIENDSCONDEMNLIST, origin, reader); // openFriendsCondemnList =1239809615 + characterList = new ArrayList<>(); + } + public void configure() { // Pre-Cache all players and guild targets @@ -95,837 +106,823 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg { } } - - public void configureHeraldry(PlayerCharacter player){ - + + public void configureHeraldry(PlayerCharacter player) { + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public OpenFriendsCondemnListMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.OPENFRIENDSCONDEMNLIST, origin, reader); // openFriendsCondemnList =1239809615 - characterList = new ArrayList<>(); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.messageType); - - if (this.messageType == 2){ - this.showHeraldy(writer); - return; - } - - if (this.messageType == 4){ - this.writeAddHealrdy(writer); - return; - } - if (this.messageType == 26){ - showBuildingFriends(writer); - return; - } - - if (this.messageType == 12){ - this.showCondemnList(writer); - return; - } - - if (this.messageType == 15){ - this.removeCondemned(writer); - return; - } - if (this.messageType == 17){ - this.handleActivateCondemned(writer); - return; - } - - - - writer.putInt(0); - writer.putInt(this.characterList.size()); - writer.putInt(this.characterList.size()); - - for (Integer uuid : characterList) { + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.messageType); + + if (this.messageType == 2) { + this.showHeraldy(writer); + return; + } + + if (this.messageType == 4) { + this.writeAddHealrdy(writer); + return; + } + if (this.messageType == 26) { + showBuildingFriends(writer); + return; + } + + if (this.messageType == 12) { + this.showCondemnList(writer); + return; + } + + if (this.messageType == 15) { + this.removeCondemned(writer); + return; + } + if (this.messageType == 17) { + this.handleActivateCondemned(writer); + return; + } + + + writer.putInt(0); + writer.putInt(this.characterList.size()); + writer.putInt(this.characterList.size()); + + for (Integer uuid : characterList) { PlayerCharacter player = (PlayerCharacter) DbManager.getObject(GameObjectType.PlayerCharacter, uuid); if (player == null) continue; - writer.put((byte) 1); - writer.putInt(0); - writer.putInt(0); - writer.putInt(1); - writer.putInt(GameObjectType.PlayerCharacter.ordinal()); - writer.putInt(player.getObjectUUID()); - Guild guild = player.getGuild(); - Guild nation = null; - - if (guild != null) { - writer.putInt(guild.getObjectType().ordinal()); - writer.putInt(guild.getObjectUUID()); - nation = guild.getNation(); - if (nation != null) { - writer.putInt(nation.getObjectType().ordinal()); - writer.putInt(nation.getObjectUUID()); - } else { - writer.putInt(0); - writer.putInt(0); - } - } else { - for (int i=0;i<4;i++) - writer.putInt(0); - } - writer.putShort((short)0); - writer.put((byte)0); - writer.putString(player.getFirstName()); - - if (guild != null) { - GuildTag._serializeForDisplay(guild.getGuildTag(),writer); - } else { - writer.putInt(16); - writer.putInt(16); - writer.putInt(16); - writer.putInt(0); - writer.putInt(0); - } - if (nation != null) { - GuildTag._serializeForDisplay(nation.getGuildTag(),writer); - } else { - writer.putInt(16); - writer.putInt(16); - writer.putInt(16); - writer.putInt(0); - writer.putInt(0); - } - if (guild != null) - writer.putString(guild.getName()); - else - writer.putString("[No Guild]"); - if (nation != null) - writer.putString(nation.getName()); - else - writer.putString("[No Nation]"); - writer.putInt(0); - } - } - - private void readHandleToItem(ByteBufferReader reader){ - reader.getInt(); - reader.getInt(); - reader.getInt(); - - reader.getInt(); //object Type; - reader.getInt(); //objectID; - - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - } - - private void writeHandleToItem(ByteBufferWriter writer){ - } - - private void removeCondemned(ByteBufferWriter writer){ - writer.putInt(0); - writer.putInt(playerType); - writer.putInt(playerID); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(removeFriendType); - writer.putInt(removeFriendID); - writer.putInt(buildingType); - writer.putInt(buildingID); - writer.putInt(0); - writer.putInt(0); - writer.putShort((short) 0); - - } - - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.messageType = reader.getInt(); //25 on open of friends list // 28 friends list // 11 open condemned list // 14 Open condemned selection of (indivual, guild, nation) - - if (this.messageType == 1){ - this.viewHealrdy(reader); - return; - } - - if (this.messageType == 4){ - this.readAddHealrdy(reader); - return; - } - - if (this.messageType == 6){ - this.readRemoveHeraldry(reader); - return; - } - if (this.messageType == 11){ - this.ackBuildingFriends(reader); - reader.get(); - return; - } - - if (this.messageType == 14){ - this.addGuildCondemn(reader); - return; - } - if (this.messageType == 15){ - this.removeFriendList(reader); - reader.get(); - return; - } - - if (this.messageType == 17){ - this.handleActivateCondemned(reader); - return; - } - - if (this.messageType == 18){ - this.handleCondemnErrant(reader); - return; - } - - - if (this.messageType == 19){ - this.handleKOS(reader); - return; - } - - if (this.messageType == 23){ - this.readHandleToItem(reader); - return; - } - if (this.messageType == 28){ - addFriendsList(reader); - return; - } - if (this.messageType == 30){ - removeFriendList(reader); - return; - } - if (this.messageType == 25){ - ackBuildingFriends(reader); - return; - } - - reader.getInt(); - int size = reader.getInt(); - reader.getInt(); //size again - for (int i=0;i heraldryMap = Heraldry.HeraldyMap.get(player.getObjectUUID()); - - //send empty list if no heraldry - if (heraldryMap == null || heraldryMap.isEmpty()){ - writer.putInt(0); - return; - } - - - writer.putInt(heraldryMap.size()); - - for (int characterID : heraldryMap.keySet()){ - AbstractCharacter heraldryCharacter = null; - int characterType = heraldryMap.get(characterID); - if (characterType == GameObjectType.PlayerCharacter.ordinal()) - heraldryCharacter = PlayerCharacter.getFromCache(characterID); - else if (characterType == GameObjectType.NPC.ordinal()) - heraldryCharacter = NPC.getFromCache(characterID); - else if (characterType == GameObjectType.Mob.ordinal()) - heraldryCharacter = Mob.getFromCache(characterID); - - if (heraldryCharacter == null) - this.showNullHeraldryCharacter(writer); - else{ - writer.put((byte)1); - writer.putInt(heraldryCharacter.getObjectType().ordinal()); - writer.putInt(heraldryCharacter.getObjectUUID()); - - writer.putInt(9); - writer.putInt(heraldryCharacter.getObjectType().ordinal()); - writer.putInt(heraldryCharacter.getObjectUUID()); - - if (heraldryCharacter.getGuild() != null) { - writer.putInt(heraldryCharacter.getGuild().getObjectType().ordinal()); - writer.putInt(heraldryCharacter.getGuild().getObjectUUID()); - - if (!heraldryCharacter.getGuild().getNation().isEmptyGuild()) { - writer.putInt(heraldryCharacter.getGuild().getNation().getObjectType().ordinal()); - writer.putInt(heraldryCharacter.getGuild().getNation().getObjectUUID()); - }else{ - writer.putInt(0); - writer.putInt(0); - } - }else{ - writer.putLong(0); - writer.putLong(0); - } - writer.putShort((short)0); - writer.put((byte)0); - writer.putString(heraldryCharacter.getName()); - if (heraldryCharacter.getGuild() != null) - GuildTag._serializeForDisplay(heraldryCharacter.getGuild().getGuildTag(),writer); - else{ - writer.putInt(16); - writer.putInt(16); - writer.putInt(16); - writer.putInt(0); - writer.putInt(0); - } - writer.putInt(16); - writer.putInt(16); - writer.putInt(16); - writer.putInt(0); - writer.putInt(0); - if (heraldryCharacter.getGuild() == null){ - writer.putString("Errant"); - writer.putString("Errant"); - } - else{ - writer.putString(heraldryCharacter.getGuild().getName()); - if (heraldryCharacter.getGuild().getNation() == null) - writer.putString("Errant"); - else - writer.putString(heraldryCharacter.getGuild().getNation().getName()); - } - writer.putInt(0); - } - - } - - } - - private void readAddHealrdy(ByteBufferReader reader){ - reader.getInt(); - reader.getInt(); - this.playerType = reader.getInt(); //player object type; - this.playerID = reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - - reader.getInt(); - reader.getInt(); - reader.getInt(); - } - - private void writeAddHealrdy(ByteBufferWriter writer){ - writer.putInt(0); - writer.putInt(0); - writer.putInt(this.playerType); //player object type; - writer.putInt(this.playerID); - 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); - } - - public int getMessageType() { - return this.messageType; - } - - public ArrayList getList() { - return this.characterList; - } - - public void setMessageType(int value) { - this.messageType = value; - } - - public void setList(ArrayList value) { - this.characterList = value; - } - - public void updateMsg(int messageType, ArrayList list) { - this.messageType = messageType; - this.characterList = list; + + HashMap heraldryMap = Heraldry.HeraldyMap.get(player.getObjectUUID()); + + //send empty list if no heraldry + if (heraldryMap == null || heraldryMap.isEmpty()) { + writer.putInt(0); + return; + } + + + writer.putInt(heraldryMap.size()); + + for (int characterID : heraldryMap.keySet()) { + AbstractCharacter heraldryCharacter = null; + int characterType = heraldryMap.get(characterID); + if (characterType == GameObjectType.PlayerCharacter.ordinal()) + heraldryCharacter = PlayerCharacter.getFromCache(characterID); + else if (characterType == GameObjectType.NPC.ordinal()) + heraldryCharacter = NPC.getFromCache(characterID); + else if (characterType == GameObjectType.Mob.ordinal()) + heraldryCharacter = Mob.getFromCache(characterID); + + if (heraldryCharacter == null) + this.showNullHeraldryCharacter(writer); + else { + writer.put((byte) 1); + writer.putInt(heraldryCharacter.getObjectType().ordinal()); + writer.putInt(heraldryCharacter.getObjectUUID()); + + writer.putInt(9); + writer.putInt(heraldryCharacter.getObjectType().ordinal()); + writer.putInt(heraldryCharacter.getObjectUUID()); + + if (heraldryCharacter.getGuild() != null) { + writer.putInt(heraldryCharacter.getGuild().getObjectType().ordinal()); + writer.putInt(heraldryCharacter.getGuild().getObjectUUID()); + + if (!heraldryCharacter.getGuild().getNation().isEmptyGuild()) { + writer.putInt(heraldryCharacter.getGuild().getNation().getObjectType().ordinal()); + writer.putInt(heraldryCharacter.getGuild().getNation().getObjectUUID()); + } else { + writer.putInt(0); + writer.putInt(0); + } + } else { + writer.putLong(0); + writer.putLong(0); + } + writer.putShort((short) 0); + writer.put((byte) 0); + writer.putString(heraldryCharacter.getName()); + if (heraldryCharacter.getGuild() != null) + GuildTag._serializeForDisplay(heraldryCharacter.getGuild().getGuildTag(), writer); + else { + writer.putInt(16); + writer.putInt(16); + writer.putInt(16); + writer.putInt(0); + writer.putInt(0); + } + writer.putInt(16); + writer.putInt(16); + writer.putInt(16); + writer.putInt(0); + writer.putInt(0); + if (heraldryCharacter.getGuild() == null) { + writer.putString("Errant"); + writer.putString("Errant"); + } else { + writer.putString(heraldryCharacter.getGuild().getName()); + if (heraldryCharacter.getGuild().getNation() == null) + writer.putString("Errant"); + else + writer.putString(heraldryCharacter.getGuild().getNation().getName()); + } + writer.putInt(0); + } + + } + + } + + private void readAddHealrdy(ByteBufferReader reader) { + reader.getInt(); + reader.getInt(); + this.playerType = reader.getInt(); //player object type; + this.playerID = reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + + reader.getInt(); + reader.getInt(); + reader.getInt(); + } + + private void writeAddHealrdy(ByteBufferWriter writer) { + writer.putInt(0); + writer.putInt(0); + writer.putInt(this.playerType); //player object type; + writer.putInt(this.playerID); + 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); + } + + public int getMessageType() { + return this.messageType; + } + + public void setMessageType(int value) { + this.messageType = value; + } + + public ArrayList getList() { + return this.characterList; + } + + public void setList(ArrayList value) { + this.characterList = value; + } + + public void updateMsg(int messageType, ArrayList list) { + this.messageType = messageType; + this.characterList = list; this.configure(); - } + } - public int getInviteType() { - return inviteType; - } + public int getInviteType() { + return inviteType; + } public int getPlayerType() { - return playerType; - } + return playerType; + } - public void setPlayerType(int playerType) { - this.playerType = playerType; - } + public void setPlayerType(int playerType) { + this.playerType = playerType; + } - public int getPlayerID() { - return playerID; - } + public int getPlayerID() { + return playerID; + } - public void setPlayerID(int playerID) { - this.playerID = playerID; - } + public void setPlayerID(int playerID) { + this.playerID = playerID; + } + + public int getGuildID() { + return guildID; + } - public int getGuildID() { - return guildID; - } - - public int getNationID() { - return nationID; - } + public void setGuildID(int guildID) { + this.guildID = guildID; + } - public void setGuildID(int guildID) { - this.guildID = guildID; - } + public int getNationID() { + return nationID; + } public int getBuildingID() { - return buildingID; - } - - public void setBuildingID(int buildingID) { - this.buildingID = buildingID; - } - - public boolean isReverseKOS() { - return reverseKOS; - } - - public void setReverseKOS(boolean reverseKOS) { - this.reverseKOS = reverseKOS; - } - - - private void showNullHeraldryCharacter(ByteBufferWriter writer){ - writer.put((byte)1); - writer.putInt(0); - writer.putInt(0); - - writer.putInt(6); - writer.putInt(0); - writer.putInt(0); - - - writer.putLong(0); - writer.putLong(0); - writer.putShort((short)0); - writer.put((byte)0); - writer.putInt(0); - - writer.putInt(16); - writer.putInt(16); - writer.putInt(16); - writer.putInt(0); - writer.putInt(0); - writer.putInt(16); - writer.putInt(16); - writer.putInt(16); - writer.putInt(0); - writer.putInt(0); - - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - - } + return buildingID; + } + + public void setBuildingID(int buildingID) { + this.buildingID = buildingID; + } + + public boolean isReverseKOS() { + return reverseKOS; + } + + public void setReverseKOS(boolean reverseKOS) { + this.reverseKOS = reverseKOS; + } + + + private void showNullHeraldryCharacter(ByteBufferWriter writer) { + writer.put((byte) 1); + writer.putInt(0); + writer.putInt(0); + + writer.putInt(6); + writer.putInt(0); + writer.putInt(0); + + + writer.putLong(0); + writer.putLong(0); + writer.putShort((short) 0); + writer.put((byte) 0); + writer.putInt(0); + + writer.putInt(16); + writer.putInt(16); + writer.putInt(16); + writer.putInt(0); + writer.putInt(0); + writer.putInt(16); + writer.putInt(16); + writer.putInt(16); + writer.putInt(0); + writer.putInt(0); + + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + + } } diff --git a/src/engine/net/client/msg/OpenTradeWindowMsg.java b/src/engine/net/client/msg/OpenTradeWindowMsg.java index 6bc21d35..05af29b5 100644 --- a/src/engine/net/client/msg/OpenTradeWindowMsg.java +++ b/src/engine/net/client/msg/OpenTradeWindowMsg.java @@ -24,71 +24,69 @@ import engine.objects.AbstractGameObject; */ public class OpenTradeWindowMsg extends ClientNetMsg { - private int unknown01; - private int playerType; - private int playerID; - private int targetType; - private int targetID; - /** - * This is the general purpose constructor - */ - public OpenTradeWindowMsg(int unknown01, AbstractGameObject player, AbstractGameObject target) { - super(Protocol.INITIATETRADEHUDS); - this.unknown01 = unknown01; - this.playerType = player.getObjectType().ordinal(); - this.playerID = player.getObjectUUID(); - this.targetType = target.getObjectType().ordinal(); - this.targetID = target.getObjectUUID(); - } + private int unknown01; + private int playerType; + private int playerID; + private int targetType; + private int targetID; - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public OpenTradeWindowMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.INITIATETRADEHUDS, origin, reader); - } + /** + * This is the general purpose constructor + */ + public OpenTradeWindowMsg(int unknown01, AbstractGameObject player, AbstractGameObject target) { + super(Protocol.INITIATETRADEHUDS); + this.unknown01 = unknown01; + this.playerType = player.getObjectType().ordinal(); + this.playerID = player.getObjectUUID(); + this.targetType = target.getObjectType().ordinal(); + this.targetID = target.getObjectUUID(); + } - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - unknown01 = reader.getInt(); - playerType = reader.getInt(); - playerID = reader.getInt(); - targetType = reader.getInt(); - targetID = reader.getInt(); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public OpenTradeWindowMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.INITIATETRADEHUDS, origin, reader); + } - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - writer.putInt(unknown01); - writer.putInt(playerType); - writer.putInt(playerID); - writer.putInt(targetType); - writer.putInt(targetID); - } + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + unknown01 = reader.getInt(); + playerType = reader.getInt(); + playerID = reader.getInt(); + targetType = reader.getInt(); + targetID = reader.getInt(); + } - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putInt(unknown01); + writer.putInt(playerType); + writer.putInt(playerID); + writer.putInt(targetType); + writer.putInt(targetID); + } - /** - * @param unknown01 the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } } diff --git a/src/engine/net/client/msg/OpenVaultMsg.java b/src/engine/net/client/msg/OpenVaultMsg.java index 2ae03be3..61aca7e9 100644 --- a/src/engine/net/client/msg/OpenVaultMsg.java +++ b/src/engine/net/client/msg/OpenVaultMsg.java @@ -19,58 +19,59 @@ import engine.objects.AbstractGameObject; /** * Vault window opened + * * @author Eighty */ public class OpenVaultMsg extends ClientNetMsg { - private int playerType; - private int playerID; - private int npcType; - private int npcID; - + private int playerType; + private int playerID; + private int npcType; + private int npcID; - /** - * This is the general purpose constructor. - */ - public OpenVaultMsg(AbstractGameObject ago, AbstractGameObject target) { - super(Protocol.OPENVAULT); - this.playerType = ago.getObjectType().ordinal(); - this.playerID = ago.getObjectUUID(); - this.npcType = target.getObjectType().ordinal(); - this.npcID = target.getObjectUUID(); - - } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public OpenVaultMsg(AbstractConnection origin, - ByteBufferReader reader) { - super(Protocol.OPENVAULT, origin, reader); - } + /** + * This is the general purpose constructor. + */ + public OpenVaultMsg(AbstractGameObject ago, AbstractGameObject target) { + super(Protocol.OPENVAULT); + this.playerType = ago.getObjectType().ordinal(); + this.playerID = ago.getObjectUUID(); + this.npcType = target.getObjectType().ordinal(); + this.npcID = target.getObjectUUID(); - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - playerType = reader.getInt(); - playerID = reader.getInt(); - npcType = reader.getInt(); - npcID = reader.getInt(); - - } + } - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - writer.putInt(playerType); - writer.putInt(playerID); - writer.putInt(npcType); - writer.putInt(npcID); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public OpenVaultMsg(AbstractConnection origin, + ByteBufferReader reader) { + super(Protocol.OPENVAULT, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + playerType = reader.getInt(); + playerID = reader.getInt(); + npcType = reader.getInt(); + npcID = reader.getInt(); + + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putInt(playerType); + writer.putInt(playerID); + writer.putInt(npcType); + writer.putInt(npcID); + } } diff --git a/src/engine/net/client/msg/OrderNPCMsg.java b/src/engine/net/client/msg/OrderNPCMsg.java index fb4ab60f..ad933cc7 100644 --- a/src/engine/net/client/msg/OrderNPCMsg.java +++ b/src/engine/net/client/msg/OrderNPCMsg.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.net.client.msg; import engine.Enum.GameObjectType; @@ -21,182 +20,178 @@ import java.util.ArrayList; public class OrderNPCMsg extends ClientNetMsg { - // 2 = manage this asset. 20 = manage entire city - private int objectType; - private int npcUUID; - private int buildingUUID; - private int unknown02; - private ArrayList patrolPoints; - private ArrayList sentryPoints; - private int patrolSize; - private int sentrySize; - - private int actionType; - private float buySellPercent; - - /** - * This is the general purpose constructor - */ - public OrderNPCMsg() { - super(Protocol.ORDERNPC); - this.actionType = 0; - this.unknown02 = 0; - this.npcUUID = 0; - this.buildingUUID = 0; - - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public OrderNPCMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.ORDERNPC, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - actionType = reader.getInt(); - if (this.actionType == 28){ - this.handleCityCommand(reader); - return; - } - unknown02 = reader.getInt(); - this.objectType = reader.getInt(); // Object Type Padding - npcUUID = reader.getInt(); - reader.getInt(); // Object Type Padding - buildingUUID = reader.getInt(); - this.buySellPercent = reader.getFloat(); - if (actionType > 6 && actionType < 13) - reader.getInt(); - - - - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(actionType); - writer.putInt(unknown02); - writer.putInt(GameObjectType.NPC.ordinal()); - writer.putInt(npcUUID); - writer.putInt(GameObjectType.Building.ordinal()); - writer.putInt(buildingUUID); - writer.putFloat(this.buySellPercent); - writer.putInt(0); - - - } - - private void handleCityCommand(ByteBufferReader reader){ - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - this.buildingUUID = reader.getInt(); - reader.get(); - reader.get(); - reader.getInt(); - patrolSize = reader.getInt(); - if (patrolSize > 0){ - this.patrolPoints = new ArrayList<>(); - for (int i = 0;i 0){ - this.sentryPoints = new ArrayList<>(); - for (int i = 0;i getPatrolPoints() { - return patrolPoints; - } - - public ArrayList getSentryPoints() { - return sentryPoints; - } - - public int getPatrolSize() { - return patrolSize; - } - - public void setPatrolSize(int patrolSize) { - this.patrolSize = patrolSize; - } - - public int getSentrySize() { - return sentrySize; - } - - public void setSentrySize(int sentrySize) { - this.sentrySize = sentrySize; - } + // 2 = manage this asset. 20 = manage entire city + private int objectType; + private int npcUUID; + private int buildingUUID; + private int unknown02; + private ArrayList patrolPoints; + private ArrayList sentryPoints; + private int patrolSize; + private int sentrySize; + + private int actionType; + private float buySellPercent; + + /** + * This is the general purpose constructor + */ + public OrderNPCMsg() { + super(Protocol.ORDERNPC); + this.actionType = 0; + this.unknown02 = 0; + this.npcUUID = 0; + this.buildingUUID = 0; + + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public OrderNPCMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ORDERNPC, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + actionType = reader.getInt(); + if (this.actionType == 28) { + this.handleCityCommand(reader); + return; + } + unknown02 = reader.getInt(); + this.objectType = reader.getInt(); // Object Type Padding + npcUUID = reader.getInt(); + reader.getInt(); // Object Type Padding + buildingUUID = reader.getInt(); + this.buySellPercent = reader.getFloat(); + if (actionType > 6 && actionType < 13) + reader.getInt(); + + + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(actionType); + writer.putInt(unknown02); + writer.putInt(GameObjectType.NPC.ordinal()); + writer.putInt(npcUUID); + writer.putInt(GameObjectType.Building.ordinal()); + writer.putInt(buildingUUID); + writer.putFloat(this.buySellPercent); + writer.putInt(0); + + + } + + private void handleCityCommand(ByteBufferReader reader) { + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + this.buildingUUID = reader.getInt(); + reader.get(); + reader.get(); + reader.getInt(); + patrolSize = reader.getInt(); + if (patrolSize > 0) { + this.patrolPoints = new ArrayList<>(); + for (int i = 0; i < patrolSize; i++) { + float x = reader.getFloat(); + float y = reader.getFloat(); + float z = reader.getFloat(); + if (this.patrolPoints.size() < 4) + this.patrolPoints.add(new Vector3fImmutable(x, y, z)); + } + } + sentrySize = reader.getInt(); + if (sentrySize > 0) { + this.sentryPoints = new ArrayList<>(); + for (int i = 0; i < sentrySize; i++) { + float x = reader.getFloat(); + float y = reader.getFloat(); + float z = reader.getFloat(); + if (this.sentryPoints.size() < 4) + this.sentryPoints.add(new Vector3fImmutable(x, y, z)); + } + } + reader.getInt(); + reader.getInt(); + } + + /** + * @return the npcUUID + */ + public int getNpcUUID() { + return npcUUID; + } + + + public int getActionType() { + return actionType; + } + + + public int getBuildingUUID() { + return buildingUUID; + } + + /** + * @param buildingUUID the buildingUUID to set + */ + public void setBuildingUUID(int buildingUUID) { + this.buildingUUID = buildingUUID; + } + + public float getBuySellPercent() { + return buySellPercent; + } + + public void setBuySellPercent(float buySellPercent) { + this.buySellPercent = buySellPercent; + } + + public int getObjectType() { + return objectType; + } + + public void setObjectType(int objectType) { + this.objectType = objectType; + } + + public ArrayList getPatrolPoints() { + return patrolPoints; + } + + public ArrayList getSentryPoints() { + return sentryPoints; + } + + public int getPatrolSize() { + return patrolSize; + } + + public void setPatrolSize(int patrolSize) { + this.patrolSize = patrolSize; + } + + public int getSentrySize() { + return sentrySize; + } + + public void setSentrySize(int sentrySize) { + this.sentrySize = sentrySize; + } } diff --git a/src/engine/net/client/msg/PassiveMessageTriggerMsg.java b/src/engine/net/client/msg/PassiveMessageTriggerMsg.java index 8d32f498..87070bdf 100644 --- a/src/engine/net/client/msg/PassiveMessageTriggerMsg.java +++ b/src/engine/net/client/msg/PassiveMessageTriggerMsg.java @@ -18,48 +18,48 @@ import engine.net.client.Protocol; public class PassiveMessageTriggerMsg extends ClientNetMsg { - private byte animation; //not sure if it's animation, 0 or 1. + private byte animation; //not sure if it's animation, 0 or 1. - /** - * This is the general purpose constructor. - */ - public PassiveMessageTriggerMsg(byte animation) { - super(Protocol.PASSIVEMESSAGETRIGGER); - this.animation = animation; - } + /** + * This is the general purpose constructor. + */ + public PassiveMessageTriggerMsg(byte animation) { + super(Protocol.PASSIVEMESSAGETRIGGER); + this.animation = animation; + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public PassiveMessageTriggerMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.PASSIVEMESSAGETRIGGER, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public PassiveMessageTriggerMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.PASSIVEMESSAGETRIGGER, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.put(this.animation); - } + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.put(this.animation); + } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.animation = reader.get(); - } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.animation = reader.get(); + } - public byte getAnimation() { - return this.animation; - } + public byte getAnimation() { + return this.animation; + } - public void setAnimation(byte value) { - this.animation = value; - } + public void setAnimation(byte value) { + this.animation = value; + } } diff --git a/src/engine/net/client/msg/PerformActionMsg.java b/src/engine/net/client/msg/PerformActionMsg.java index c955fa32..0c838b09 100644 --- a/src/engine/net/client/msg/PerformActionMsg.java +++ b/src/engine/net/client/msg/PerformActionMsg.java @@ -19,280 +19,272 @@ import engine.net.client.Protocol; public class PerformActionMsg extends ClientNetMsg { - protected int powerUsedID; - protected int numTrains; - protected int sourceType; - protected int sourceID; - protected int targetType; - protected int targetID; - - protected float targetX; - protected float targetY; - protected float targetZ; - protected int unknown04; //1, 2, 6 - protected int unknown05; - - protected int realTrains; //not serialized. Used for mob AI tracking. - - /** - * This is the general purpose constructor. - */ - public PerformActionMsg() { - super(Protocol.POWER); - } - - public PerformActionMsg(int powerUsedID, int numTrains, int sourceType, int sourceID, int targetType, int targetID, float targetX, float targetY, float targetZ, int unknown04, int unknown05) { - super(Protocol.POWER); - this.powerUsedID = powerUsedID; - this.numTrains = numTrains; - this.sourceType = sourceType; - this.sourceID = sourceID; - this.targetType = targetType; - this.targetID = targetID; - this.targetX = targetX; - this.targetY = targetY; - this.targetZ = targetZ; - this.unknown04 = unknown04; - this.unknown05 = unknown05; - - this.realTrains = this.numTrains; - } - - - - public PerformActionMsg(PerformActionMsg msg) { - super(Protocol.POWER); - this.powerUsedID = msg.powerUsedID; - this.numTrains = msg.numTrains; - this.sourceType = msg.sourceType; - this.sourceID = msg.sourceID; - this.targetType = msg.targetType; - this.targetID = msg.targetID; - this.targetX = msg.targetX; - this.targetY = msg.targetY; - this.targetZ = msg.targetZ; - this.unknown04 = msg.unknown04; - this.unknown05 = msg.unknown05; - this.realTrains = msg.realTrains; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public PerformActionMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.POWER, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.powerUsedID); - writer.putInt(this.numTrains); - - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.putInt(this.targetType); - writer.putInt(this.targetID); - - writer.putFloat(this.targetX); - writer.putFloat(this.targetY); - writer.putFloat(this.targetZ); - writer.putInt(this.unknown04); - writer.putInt(this.unknown05); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.powerUsedID = reader.getInt(); - this.numTrains = reader.getInt(); - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - - this.targetX = reader.getFloat(); - this.targetY = reader.getFloat(); - this.targetZ = reader.getFloat(); - this.unknown04 = reader.getInt(); - this.unknown05 = reader.getInt(); //2=FailToCast, 3=Miss, 4=Dodge, 5=Immune, 6=resisted, 7=targetDead, 8=PowerInterupted, 9=NoValidTargets, 10=NotBeenGrantedPower - this.realTrains = this.numTrains; - } - - /** - * @return the powerUsedID - */ - public int getPowerUsedID() { - return powerUsedID; - } - - /** - * @param powerUsedID - * the powerUsedID to set - */ - public void setPowerUsedID(int powerUsedID) { - this.powerUsedID = powerUsedID; - } - - /** - * @return the numTrains - */ - public int getNumTrains() { - return numTrains; - } - - /** - * @param numTrains - * the numTrains to set - */ - public void setNumTrains(int numTrains) { - this.numTrains = numTrains; - } - - /** - * @return the sourceType - */ - public int getSourceType() { - return sourceType; - } - - /** - * @param sourceType - * the sourceType to set - */ - public void setSourceType(int sourceType) { - this.sourceType = sourceType; - } - - /** - * @return the sourceID - */ - public int getSourceID() { - return sourceID; - } - - /** - * @param sourceID - * the sourceID to set - */ - public void setSourceID(int sourceID) { - this.sourceID = sourceID; - } - - /** - * @return the targetType - */ - public int getTargetType() { - return targetType; - } - - /** - * @param targetType - * the targetType to set - */ - public void setTargetType(int targetType) { - this.targetType = targetType; - } - - /** - * @return the targetID - */ - public int getTargetID() { - return targetID; - } - - /** - * @param targetID - * the targetID to set - */ - public void setTargetID(int targetID) { - this.targetID = targetID; - } - - /** - * @return the unknown01 - */ - public float getTargetX() { - return targetX; - } - - /** + protected int powerUsedID; + protected int numTrains; + protected int sourceType; + protected int sourceID; + protected int targetType; + protected int targetID; + + protected float targetX; + protected float targetY; + protected float targetZ; + protected int unknown04; //1, 2, 6 + protected int unknown05; + + protected int realTrains; //not serialized. Used for mob AI tracking. + + /** + * This is the general purpose constructor. */ - public void setTargetX(float targetX) { - this.targetX = targetX; - } - - /** - * @return the unknown02 - */ - public float getTargetY() { - return targetY; - } - - public void setTargetY(float targetY) { - this.targetY = targetY; - } - - /** - * @return the unknown03 - */ - public float getTargetZ() { - return targetZ; - } - - - public void setTargetZ(float targetZ) { - this.targetZ = targetZ; - } - - public void setTargetLoc(Vector3f targetLoc) { - this.targetX = targetLoc.x; - this.targetY = targetLoc.y; - this.targetZ = targetLoc.z; - } - - public Vector3fImmutable getTargetLoc() { - return new Vector3fImmutable(this.targetX, this.targetY, this.targetZ); - } - - /** - * @return the unknown04 - */ - public int getUnknown04() { - return unknown04; - } - - /** - * @param unknown04 - * the unknown04 to set - */ - public void setUnknown04(int unknown04) { - this.unknown04 = unknown04; - } - - /** - * @return the unknown05 - */ - public int getUnknown05() { - return unknown05; - } - - /** - * @param unknown05 - * the unknown05 to set - */ - public void setUnknown05(int unknown05) { - this.unknown05 = unknown05; - } - - public int getRealTrains() { - return this.realTrains; - } + public PerformActionMsg() { + super(Protocol.POWER); + } + + public PerformActionMsg(int powerUsedID, int numTrains, int sourceType, int sourceID, int targetType, int targetID, float targetX, float targetY, float targetZ, int unknown04, int unknown05) { + super(Protocol.POWER); + this.powerUsedID = powerUsedID; + this.numTrains = numTrains; + this.sourceType = sourceType; + this.sourceID = sourceID; + this.targetType = targetType; + this.targetID = targetID; + this.targetX = targetX; + this.targetY = targetY; + this.targetZ = targetZ; + this.unknown04 = unknown04; + this.unknown05 = unknown05; + + this.realTrains = this.numTrains; + } + + + public PerformActionMsg(PerformActionMsg msg) { + super(Protocol.POWER); + this.powerUsedID = msg.powerUsedID; + this.numTrains = msg.numTrains; + this.sourceType = msg.sourceType; + this.sourceID = msg.sourceID; + this.targetType = msg.targetType; + this.targetID = msg.targetID; + this.targetX = msg.targetX; + this.targetY = msg.targetY; + this.targetZ = msg.targetZ; + this.unknown04 = msg.unknown04; + this.unknown05 = msg.unknown05; + this.realTrains = msg.realTrains; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public PerformActionMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.POWER, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.powerUsedID); + writer.putInt(this.numTrains); + + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.putInt(this.targetType); + writer.putInt(this.targetID); + + writer.putFloat(this.targetX); + writer.putFloat(this.targetY); + writer.putFloat(this.targetZ); + writer.putInt(this.unknown04); + writer.putInt(this.unknown05); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.powerUsedID = reader.getInt(); + this.numTrains = reader.getInt(); + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + + this.targetX = reader.getFloat(); + this.targetY = reader.getFloat(); + this.targetZ = reader.getFloat(); + this.unknown04 = reader.getInt(); + this.unknown05 = reader.getInt(); //2=FailToCast, 3=Miss, 4=Dodge, 5=Immune, 6=resisted, 7=targetDead, 8=PowerInterupted, 9=NoValidTargets, 10=NotBeenGrantedPower + this.realTrains = this.numTrains; + } + + /** + * @return the powerUsedID + */ + public int getPowerUsedID() { + return powerUsedID; + } + + /** + * @param powerUsedID the powerUsedID to set + */ + public void setPowerUsedID(int powerUsedID) { + this.powerUsedID = powerUsedID; + } + + /** + * @return the numTrains + */ + public int getNumTrains() { + return numTrains; + } + + /** + * @param numTrains the numTrains to set + */ + public void setNumTrains(int numTrains) { + this.numTrains = numTrains; + } + + /** + * @return the sourceType + */ + public int getSourceType() { + return sourceType; + } + + /** + * @param sourceType the sourceType to set + */ + public void setSourceType(int sourceType) { + this.sourceType = sourceType; + } + + /** + * @return the sourceID + */ + public int getSourceID() { + return sourceID; + } + + /** + * @param sourceID the sourceID to set + */ + public void setSourceID(int sourceID) { + this.sourceID = sourceID; + } + + /** + * @return the targetType + */ + public int getTargetType() { + return targetType; + } + + /** + * @param targetType the targetType to set + */ + public void setTargetType(int targetType) { + this.targetType = targetType; + } + + /** + * @return the targetID + */ + public int getTargetID() { + return targetID; + } + + /** + * @param targetID the targetID to set + */ + public void setTargetID(int targetID) { + this.targetID = targetID; + } + + /** + * @return the unknown01 + */ + public float getTargetX() { + return targetX; + } + + /** + * + */ + public void setTargetX(float targetX) { + this.targetX = targetX; + } + + /** + * @return the unknown02 + */ + public float getTargetY() { + return targetY; + } + + public void setTargetY(float targetY) { + this.targetY = targetY; + } + + /** + * @return the unknown03 + */ + public float getTargetZ() { + return targetZ; + } + + + public void setTargetZ(float targetZ) { + this.targetZ = targetZ; + } + + public Vector3fImmutable getTargetLoc() { + return new Vector3fImmutable(this.targetX, this.targetY, this.targetZ); + } + + public void setTargetLoc(Vector3f targetLoc) { + this.targetX = targetLoc.x; + this.targetY = targetLoc.y; + this.targetZ = targetLoc.z; + } + + /** + * @return the unknown04 + */ + public int getUnknown04() { + return unknown04; + } + + /** + * @param unknown04 the unknown04 to set + */ + public void setUnknown04(int unknown04) { + this.unknown04 = unknown04; + } + + /** + * @return the unknown05 + */ + public int getUnknown05() { + return unknown05; + } + + /** + * @param unknown05 the unknown05 to set + */ + public void setUnknown05(int unknown05) { + this.unknown05 = unknown05; + } + + public int getRealTrains() { + return this.realTrains; + } } diff --git a/src/engine/net/client/msg/PetAttackMsg.java b/src/engine/net/client/msg/PetAttackMsg.java index d25f029a..40ae985b 100644 --- a/src/engine/net/client/msg/PetAttackMsg.java +++ b/src/engine/net/client/msg/PetAttackMsg.java @@ -17,57 +17,57 @@ import engine.net.client.Protocol; public class PetAttackMsg extends ClientNetMsg { - private int targetType; - private int targetID; + private int targetType; + private int targetID; - /** - * This is the general purpose constructor. - */ - public PetAttackMsg() { - super(Protocol.ARCPETATTACK); - } + /** + * This is the general purpose constructor. + */ + public PetAttackMsg() { + super(Protocol.ARCPETATTACK); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public PetAttackMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ARCPETATTACK, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public PetAttackMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ARCPETATTACK, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.targetType); - writer.putInt(this.targetID); - } + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.targetType); + writer.putInt(this.targetID); + } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + } - public int getTargetType() { - return this.targetType; - } + public int getTargetType() { + return this.targetType; + } - public int getTargetID() { - return this.targetID; - } + public void setTargetType(int value) { + this.targetType = value; + } - public void setTargetType(int value) { - this.targetType = value; - } + public int getTargetID() { + return this.targetID; + } - public void setTargetID(int value) { - this.targetID = value; - } + public void setTargetID(int value) { + this.targetID = value; + } } diff --git a/src/engine/net/client/msg/PetCmdMsg.java b/src/engine/net/client/msg/PetCmdMsg.java index 79215389..64095719 100644 --- a/src/engine/net/client/msg/PetCmdMsg.java +++ b/src/engine/net/client/msg/PetCmdMsg.java @@ -17,52 +17,52 @@ import engine.net.client.Protocol; public class PetCmdMsg extends ClientNetMsg { - private int type; + private int type; - //1: stop attack - //2: dismiss - //3: toggle assist - //5: rest + //1: stop attack + //2: dismiss + //3: toggle assist + //5: rest - /** - * This is the general purpose constructor. - */ - public PetCmdMsg(int type) { - super(Protocol.ARCPETCMD); - this.type = type; - } + /** + * This is the general purpose constructor. + */ + public PetCmdMsg(int type) { + super(Protocol.ARCPETCMD); + this.type = type; + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public PetCmdMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ARCPETCMD, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public PetCmdMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ARCPETCMD, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(type); - } + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(type); + } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.type = reader.getInt(); - } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.type = reader.getInt(); + } - public int getType() { - return this.type; - } + public int getType() { + return this.type; + } - public void setType(int value) { - this.type = value; - } + public void setType(int value) { + this.type = value; + } } diff --git a/src/engine/net/client/msg/PetMsg.java b/src/engine/net/client/msg/PetMsg.java index eb681588..ca378aae 100644 --- a/src/engine/net/client/msg/PetMsg.java +++ b/src/engine/net/client/msg/PetMsg.java @@ -18,100 +18,100 @@ import engine.objects.Mob; public class PetMsg extends ClientNetMsg { - private int type; //5 or 6 - private Mob pet; - - /** - * This is the general purpose constructor. - */ - public PetMsg(int type, Mob pet) { - super(Protocol.PET); - if (this.type != 6) - this.type = 5; - this.pet = pet; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public PetMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.PET, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.type); - - if (this.pet != null) { - writer.putInt(pet.getObjectType().ordinal()); - writer.putInt(pet.getObjectUUID()); - } else { - writer.putInt(0); - writer.putInt(0); - } - - if (type == 6) { - writer.putInt(0); - } else if (type == 5) { - if (pet != null){ - writer.putInt((int)(pet.getCurrentHitpoints() / pet.getHealthMax())); //suspect %health left - writer.putInt((int)(pet.getMana() / pet.getManaMax())); //suspect %mana left - writer.putInt((int)(pet.getStamina() / pet.getStaminaMax())); //suspect %stamina left - writer.putString(pet.getName()); - writer.putInt(0); - writer.put((byte)0); - }else{ - writer.putInt(0); //suspect %health left - writer.putInt(0); //suspect %mana left - writer.putInt(0); //suspect %stamina left - writer.putString("No Pet"); - writer.putInt(0); - writer.put((byte)0); - } - - } - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.type = reader.getInt(); - reader.getInt(); - int petID = reader.getInt(); - this.pet = Mob.getFromCache(petID); - if (this.type == 5) { - reader.getInt(); - } else if (this.type == 6) { - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getString(); - reader.getInt(); - reader.get(); - } - } - - public int getType() { - return this.type; - } - - public Mob getPet() { - return this.pet; - } - - public void setType(int value) { - this.type = value; - } - - public void setPet(Mob value) { - this.pet = value; - } + private int type; //5 or 6 + private Mob pet; + + /** + * This is the general purpose constructor. + */ + public PetMsg(int type, Mob pet) { + super(Protocol.PET); + if (this.type != 6) + this.type = 5; + this.pet = pet; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public PetMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.PET, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.type); + + if (this.pet != null) { + writer.putInt(pet.getObjectType().ordinal()); + writer.putInt(pet.getObjectUUID()); + } else { + writer.putInt(0); + writer.putInt(0); + } + + if (type == 6) { + writer.putInt(0); + } else if (type == 5) { + if (pet != null) { + writer.putInt((int) (pet.getCurrentHitpoints() / pet.getHealthMax())); //suspect %health left + writer.putInt((int) (pet.getMana() / pet.getManaMax())); //suspect %mana left + writer.putInt((int) (pet.getStamina() / pet.getStaminaMax())); //suspect %stamina left + writer.putString(pet.getName()); + writer.putInt(0); + writer.put((byte) 0); + } else { + writer.putInt(0); //suspect %health left + writer.putInt(0); //suspect %mana left + writer.putInt(0); //suspect %stamina left + writer.putString("No Pet"); + writer.putInt(0); + writer.put((byte) 0); + } + + } + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.type = reader.getInt(); + reader.getInt(); + int petID = reader.getInt(); + this.pet = Mob.getFromCache(petID); + if (this.type == 5) { + reader.getInt(); + } else if (this.type == 6) { + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getString(); + reader.getInt(); + reader.get(); + } + } + + public int getType() { + return this.type; + } + + public void setType(int value) { + this.type = value; + } + + public Mob getPet() { + return this.pet; + } + + public void setPet(Mob value) { + this.pet = value; + } } diff --git a/src/engine/net/client/msg/PetitionReceivedMsg.java b/src/engine/net/client/msg/PetitionReceivedMsg.java index 0626ed88..4232a4e7 100644 --- a/src/engine/net/client/msg/PetitionReceivedMsg.java +++ b/src/engine/net/client/msg/PetitionReceivedMsg.java @@ -18,257 +18,253 @@ import engine.net.client.Protocol; public class PetitionReceivedMsg extends ClientNetMsg { - // TODO pull these statics out into SBEmuStatics.java - private static final int PETITION_NEW = 1; - private static final int PETITION_CANCEL = 2; - - private static final int TYPE_GENERAL_HELP = 1; - private static final int TYPE_FEEDBACK = 2; - private static final int TYPE_STUCK = 3; - private static final int TYPE_HARASSMENT = 4; - private static final int TYPE_EXPLOIT = 5; - private static final int TYPE_BUG = 6; - private static final int TYPE_GAME_STOPPER = 7; - private static final int TYPE_TECH_SUPPORT = 8; - - private static final int SUBTYPE_EXPLOIT_DUPE = 1; - private static final int SUBTYPE_EXPLOIT_LEVELING = 2; - private static final int SUBTYPE_EXPLOIT_SKILL_GAIN = 3; - private static final int SUBTYPE_EXPLOIT_KILLING = 4; - private static final int SUBTYPE_EXPLOIT_POLICY = 5; - private static final int SUBTYPE_EXPLOIT_OTHER = 6; - private static final int SUBTYPE_TECH_VIDEO = 7; - private static final int SUBTYPE_TECH_SOUND = 8; - private static final int SUBTYPE_TECH_NETWORK = 9; - private static final int SUBTYPE_TECH_OTHER = 10; - - private int petition; - private int unknown01; - private int unknown02; - private byte unknownByte01; - private int unknown03; - private int unknown04; - private int unknown05; - private int unknown06; - private int type; - private int subType; - private String compType; - private String language; - private int unknown07; - private String message; - - /** - * This is the general purpose constructor. - */ - public PetitionReceivedMsg() { - super(Protocol.CUSTOMERPETITION); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public PetitionReceivedMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CUSTOMERPETITION, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.petition); - if (this.petition == PETITION_NEW) { - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - writer.put(this.unknownByte01); - writer.putInt(this.unknown03); - writer.putInt(this.unknown04); - writer.putInt(this.unknown05); - writer.putInt(this.unknown06); - writer.putInt(this.type); - writer.putInt(this.subType); - writer.putString(this.compType); - writer.putString(this.language); - writer.putInt(this.unknown07); - writer.putUnicodeString(message); - } else if (this.petition == PETITION_CANCEL) { - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - writer.put(this.unknownByte01); - writer.putInt(this.unknown03); - writer.putInt(this.unknown04); - } - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - petition = reader.getInt(); - if (petition == PETITION_NEW) { - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - this.unknownByte01 = reader.get(); - this.unknown03 = reader.getInt(); - this.unknown04 = reader.getInt(); - this.unknown05 = reader.getInt(); - this.unknown06 = reader.getInt(); - this.type = reader.getInt(); - this.subType = reader.getInt(); - this.compType = reader.getString(); - this.language = reader.getString(); - this.unknown07 = reader.getInt(); - this.message = reader.getUnicodeString(); - } else if (petition == PETITION_CANCEL) { - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - this.unknownByte01 = reader.get(); - this.unknown03 = reader.getInt(); - this.unknown04 = reader.getInt(); - } - } - - /** - * @return the petition - */ - public int getPetition() { - return petition; - } - - /** - * @param petition - * the petition to set - */ - public void setPetition(int petition) { - this.petition = petition; - } - - /** - * @return the type - */ - public int getType() { - return type; - } - - /** - * @param type - * the type to set - */ - public void setType(int type) { - this.type = type; - } - - /** - * @return the subType - */ - public int getSubType() { - return subType; - } - - /** - * @param subType - * the subType to set - */ - public void setSubType(int subType) { - this.subType = subType; - } - - /** - * @return the message - */ - public String getMessage() { - return message; - } - - /** - * @param message - * the message to set - */ - public void setMessage(String message) { - this.message = message; - } - - public int getUnknown01() { - return this.unknown01; - } - - public void setUnknown01(int value) { - this.unknown01 = value; - } - - public int getUnknown02() { - return this.unknown02; - } - - public void setUnknown02(int value) { - this.unknown02 = value; - } - - public int getUnknown03() { - return this.unknown03; - } - - public void setUnknown03(int value) { - this.unknown03 = value; - } - - public int getUnknown04() { - return this.unknown04; - } - - public void setUnknown04(int value) { - this.unknown04 = value; - } - - public int getUnknown05() { - return this.unknown05; - } - - public void setUnknown05(int value) { - this.unknown05 = value; - } - - public int getUnknown06() { - return this.unknown06; - } - - public void setUnknown06(int value) { - this.unknown06 = value; - } - - public int getUnknown07() { - return this.unknown07; - } - - public void setUnknown07(int value) { - this.unknown07 = value; - } - - public byte getUnknownByte01() { - return this.unknownByte01; - } - - public void setUnknownByte01(byte value) { - this.unknownByte01 = value; - } - - public String getCompType() { - return this.compType; - } - - public void setCompType(String value) { - this.compType = value; - } - - public String getLanguage() { - return this.language; - } - - public void setLanguage(String value) { - this.language = value; - } + // TODO pull these statics out into SBEmuStatics.java + private static final int PETITION_NEW = 1; + private static final int PETITION_CANCEL = 2; + + private static final int TYPE_GENERAL_HELP = 1; + private static final int TYPE_FEEDBACK = 2; + private static final int TYPE_STUCK = 3; + private static final int TYPE_HARASSMENT = 4; + private static final int TYPE_EXPLOIT = 5; + private static final int TYPE_BUG = 6; + private static final int TYPE_GAME_STOPPER = 7; + private static final int TYPE_TECH_SUPPORT = 8; + + private static final int SUBTYPE_EXPLOIT_DUPE = 1; + private static final int SUBTYPE_EXPLOIT_LEVELING = 2; + private static final int SUBTYPE_EXPLOIT_SKILL_GAIN = 3; + private static final int SUBTYPE_EXPLOIT_KILLING = 4; + private static final int SUBTYPE_EXPLOIT_POLICY = 5; + private static final int SUBTYPE_EXPLOIT_OTHER = 6; + private static final int SUBTYPE_TECH_VIDEO = 7; + private static final int SUBTYPE_TECH_SOUND = 8; + private static final int SUBTYPE_TECH_NETWORK = 9; + private static final int SUBTYPE_TECH_OTHER = 10; + + private int petition; + private int unknown01; + private int unknown02; + private byte unknownByte01; + private int unknown03; + private int unknown04; + private int unknown05; + private int unknown06; + private int type; + private int subType; + private String compType; + private String language; + private int unknown07; + private String message; + + /** + * This is the general purpose constructor. + */ + public PetitionReceivedMsg() { + super(Protocol.CUSTOMERPETITION); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public PetitionReceivedMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CUSTOMERPETITION, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.petition); + if (this.petition == PETITION_NEW) { + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + writer.put(this.unknownByte01); + writer.putInt(this.unknown03); + writer.putInt(this.unknown04); + writer.putInt(this.unknown05); + writer.putInt(this.unknown06); + writer.putInt(this.type); + writer.putInt(this.subType); + writer.putString(this.compType); + writer.putString(this.language); + writer.putInt(this.unknown07); + writer.putUnicodeString(message); + } else if (this.petition == PETITION_CANCEL) { + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + writer.put(this.unknownByte01); + writer.putInt(this.unknown03); + writer.putInt(this.unknown04); + } + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + petition = reader.getInt(); + if (petition == PETITION_NEW) { + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + this.unknownByte01 = reader.get(); + this.unknown03 = reader.getInt(); + this.unknown04 = reader.getInt(); + this.unknown05 = reader.getInt(); + this.unknown06 = reader.getInt(); + this.type = reader.getInt(); + this.subType = reader.getInt(); + this.compType = reader.getString(); + this.language = reader.getString(); + this.unknown07 = reader.getInt(); + this.message = reader.getUnicodeString(); + } else if (petition == PETITION_CANCEL) { + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + this.unknownByte01 = reader.get(); + this.unknown03 = reader.getInt(); + this.unknown04 = reader.getInt(); + } + } + + /** + * @return the petition + */ + public int getPetition() { + return petition; + } + + /** + * @param petition the petition to set + */ + public void setPetition(int petition) { + this.petition = petition; + } + + /** + * @return the type + */ + public int getType() { + return type; + } + + /** + * @param type the type to set + */ + public void setType(int type) { + this.type = type; + } + + /** + * @return the subType + */ + public int getSubType() { + return subType; + } + + /** + * @param subType the subType to set + */ + public void setSubType(int subType) { + this.subType = subType; + } + + /** + * @return the message + */ + public String getMessage() { + return message; + } + + /** + * @param message the message to set + */ + public void setMessage(String message) { + this.message = message; + } + + public int getUnknown01() { + return this.unknown01; + } + + public void setUnknown01(int value) { + this.unknown01 = value; + } + + public int getUnknown02() { + return this.unknown02; + } + + public void setUnknown02(int value) { + this.unknown02 = value; + } + + public int getUnknown03() { + return this.unknown03; + } + + public void setUnknown03(int value) { + this.unknown03 = value; + } + + public int getUnknown04() { + return this.unknown04; + } + + public void setUnknown04(int value) { + this.unknown04 = value; + } + + public int getUnknown05() { + return this.unknown05; + } + + public void setUnknown05(int value) { + this.unknown05 = value; + } + + public int getUnknown06() { + return this.unknown06; + } + + public void setUnknown06(int value) { + this.unknown06 = value; + } + + public int getUnknown07() { + return this.unknown07; + } + + public void setUnknown07(int value) { + this.unknown07 = value; + } + + public byte getUnknownByte01() { + return this.unknownByte01; + } + + public void setUnknownByte01(byte value) { + this.unknownByte01 = value; + } + + public String getCompType() { + return this.compType; + } + + public void setCompType(String value) { + this.compType = value; + } + + public String getLanguage() { + return this.language; + } + + public void setLanguage(String value) { + this.language = value; + } } diff --git a/src/engine/net/client/msg/PlaceAssetMsg.java b/src/engine/net/client/msg/PlaceAssetMsg.java index 2ac5989f..c59bd23f 100644 --- a/src/engine/net/client/msg/PlaceAssetMsg.java +++ b/src/engine/net/client/msg/PlaceAssetMsg.java @@ -22,7 +22,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -public class PlaceAssetMsg extends ClientNetMsg { +public class PlaceAssetMsg extends ClientNetMsg { /* Client -> Server @@ -78,9 +78,9 @@ public class PlaceAssetMsg extends ClientNetMsg { //00000000 */ - //UseItem(C->S)->Type 2(S->C)->Type 1(C->S) <-close placement window, no response - //UseItem(C->S)->Type 2(S->C)->Type 3(C->S)->Type 0(S->C) <-Attempt place asset, with error response - //UseItem(C->S)->Type 2(S->C)->Type 3(C->S)->Type 4(S->C) <-Attempt place asset, with success response + //UseItem(C->S)->Type 2(S->C)->Type 1(C->S) <-close placement window, no response + //UseItem(C->S)->Type 2(S->C)->Type 3(C->S)->Type 0(S->C) <-Attempt place asset, with error response + //UseItem(C->S)->Type 2(S->C)->Type 3(C->S)->Type 4(S->C) <-Attempt place asset, with success response /* Error msg codes //1 "msg append here" <- what's in msg string. @@ -164,56 +164,64 @@ public class PlaceAssetMsg extends ClientNetMsg { //79 This tree cannot support more walls. */ - private static final Map wallToCost; - static { - Map map = new HashMap<>(); - map.put(454700, 100000); //Straight Outer Wall - map.put(1309900, 100000); //Irekei Outer Straight Wall - map.put(1348900, 100000); //Invorri Outer Straight Wall - map.put(454650, 150000); //Outer Wall with Stairs - map.put(455000, 150000); //Outer Wall with Tower - map.put(454550, 150000); //Outer Wall Gate - map.put(455700, 150000); //Small Gate House - map.put(1309600, 150000); //Irekei Outer Wall with Stairs - map.put(1309300, 150000); //Irekei Outer Wall Gate - map.put(1331200, 150000); //Elven Straight Outer Wall - map.put(1330900, 150000); //Elven Outer Wall with Stairs - map.put(1332100, 150000); //Elven Outer Wall with Tower - map.put(1330300, 150000); //Elven Outer Wall Gate - map.put(1348600, 150000); //Invorri Outer Wall with Stairs - map.put(1348300, 150000); //Invorri Outer Wall Gate - map.put(454750, 300000); //Concave Tower - map.put(458100, 300000); //Artillery Tower - map.put(455300, 300000); //Tower Junction - map.put(454800, 300000); //Convex Tower (inside corner) - map.put(1310200, 300000); //Irekei Concave Tower - map.put(5070800, 300000); //Irekei Artillery Tower - map.put(1310500, 300000); //Irekei Convex Tower - map.put(1330600, 300000); //Elven Gate House - map.put(1331500, 300000); //Elven Concave Tower - map.put(5070200, 300000); //Elven Artillery Tower - map.put(1332400, 300000); //Elven Tower Junction - map.put(1331800, 300000); //Elven Convex Tower - map.put(1349200, 300000); //Invorri Concave Tower - map.put(5071400, 300000); //Invorri Artillery Tower - map.put(1349500, 300000); //Invorri Convex Tower - wallToCost = Collections.unmodifiableMap(map); - } - private static final Map wallToUseId; - static { - Map map = new HashMap<>(); - ///Feudal Outer Walls - map.put(454700, 1); //Straight Outer Wall - map.put(454650, 1); //Outer Wall with Stairs - map.put(455000, 1); //Outer Wall with Tower - map.put(454550, 1); //Outer Wall Gate - map.put(455700, 1); //Small Gate House - map.put(454750, 1); //Concave Tower - map.put(458100, 1); //Artillery Tower - map.put(455300, 1); //Tower Junction - map.put(454800, 1); //Convex Tower (inside corner) - //map.put(1, 454000, 1); //Gate House (giant gatehouse) NOT USE IN GAME - //Feudal Inner Walls + private static final Map wallToCost; + private static final Map wallToUseId; + private static final Map> useIdToWallCostMaps; + private static final int NONE = 0; + private static final int CLIENTREQ_UNKNOWN = 1; + private static final int SERVER_OPENWINDOW = 2; + private static final int CLIENTREQ_NEWBUILDING = 3; // Request to place asset + private static final int SERVER_CLOSEWINDOW = 4; + + static { + Map map = new HashMap<>(); + map.put(454700, 100000); //Straight Outer Wall + map.put(1309900, 100000); //Irekei Outer Straight Wall + map.put(1348900, 100000); //Invorri Outer Straight Wall + map.put(454650, 150000); //Outer Wall with Stairs + map.put(455000, 150000); //Outer Wall with Tower + map.put(454550, 150000); //Outer Wall Gate + map.put(455700, 150000); //Small Gate House + map.put(1309600, 150000); //Irekei Outer Wall with Stairs + map.put(1309300, 150000); //Irekei Outer Wall Gate + map.put(1331200, 150000); //Elven Straight Outer Wall + map.put(1330900, 150000); //Elven Outer Wall with Stairs + map.put(1332100, 150000); //Elven Outer Wall with Tower + map.put(1330300, 150000); //Elven Outer Wall Gate + map.put(1348600, 150000); //Invorri Outer Wall with Stairs + map.put(1348300, 150000); //Invorri Outer Wall Gate + map.put(454750, 300000); //Concave Tower + map.put(458100, 300000); //Artillery Tower + map.put(455300, 300000); //Tower Junction + map.put(454800, 300000); //Convex Tower (inside corner) + map.put(1310200, 300000); //Irekei Concave Tower + map.put(5070800, 300000); //Irekei Artillery Tower + map.put(1310500, 300000); //Irekei Convex Tower + map.put(1330600, 300000); //Elven Gate House + map.put(1331500, 300000); //Elven Concave Tower + map.put(5070200, 300000); //Elven Artillery Tower + map.put(1332400, 300000); //Elven Tower Junction + map.put(1331800, 300000); //Elven Convex Tower + map.put(1349200, 300000); //Invorri Concave Tower + map.put(5071400, 300000); //Invorri Artillery Tower + map.put(1349500, 300000); //Invorri Convex Tower + wallToCost = Collections.unmodifiableMap(map); + } + + static { + Map map = new HashMap<>(); + ///Feudal Outer Walls + map.put(454700, 1); //Straight Outer Wall + map.put(454650, 1); //Outer Wall with Stairs + map.put(455000, 1); //Outer Wall with Tower + map.put(454550, 1); //Outer Wall Gate + map.put(455700, 1); //Small Gate House + map.put(454750, 1); //Concave Tower + map.put(458100, 1); //Artillery Tower + map.put(455300, 1); //Tower Junction + map.put(454800, 1); //Convex Tower (inside corner) + //map.put(1, 454000, 1); //Gate House (giant gatehouse) NOT USE IN GAME + //Feudal Inner Walls /* map.put(454100, 2); //Inner Archway map.put(454200, 2); //Inner Wall Corner @@ -225,369 +233,389 @@ public class PlaceAssetMsg extends ClientNetMsg { map.put(454900, 2); //Tower-Inner Wall Junction (T-South) stuck inside right map.put(454950, 2); //Tower-Inner Wall Junction (4-way) stuck inside */ - //Irekei Outer Walls - map.put(1309900, 3); //Irekei Outer Straight Wall - map.put(1309600, 3); //Irekei Outer Wall with Stairs - map.put(1309300, 3); //Irekei Outer Wall Gate - map.put(1310200, 3); //Irekei Concave Tower - map.put(5070800, 3); //Irekei Artillery Tower - map.put(1310500, 3); //Irekei Convex Tower - //Elven Outer Walls - map.put(1331200, 4); //Elven Straight Outer Wall - map.put(1330900, 4); //Elven Outer Wall with Stairs - map.put(1332100, 4); //Elven Outer Wall with Tower - map.put(1330300, 4); //Elven Outer Wall Gate - map.put(1330600, 4); //Elven Gate House - map.put(1331500, 4); //Elven Concave Tower - map.put(5070200, 4); //Elven Artillery Tower - map.put(1332400, 4); //Elven Tower Junction - map.put(1331800, 4); //Elven Convex Tower - //Invorri Outer Walls - map.put(1348900, 5); //Invorri Outer Straight Wall - map.put(1348600, 5); //Invorri Outer Wall with Stairs - map.put(1348300, 5); //Invorri Outer Wall Gate - map.put(1349200, 5); //Invorri Concave Tower - map.put(5071400, 5); //Invorri Artillery Tower - map.put(1349500, 5); //Invorri Convex Tower - wallToUseId = Collections.unmodifiableMap(map); - } - private static final Map> useIdToWallCostMaps; - static { - //autoloaded based on wallToUseId and wallToCost - Map> map = new HashMap<>(); - for (Map.Entry entry : wallToUseId.entrySet()) { - int wallId = entry.getKey(); - int useId = entry.getValue(); - int cost = 0; - Integer costCheck = wallToCost.get(wallId); - if (costCheck != null) { - cost = costCheck; - } else { - throw new Error("PlaceAssetMsg: WallId '" + wallId + "' has no cost in 'wallToCost' but exists in 'useIdToWall'."); - } - if (!map.containsKey(useId)) { - map.put(useId, new HashMap<>()); - } - map.get(useId).put(wallId, cost); - } - for (Map.Entry> entry : map.entrySet()) { - map.put(entry.getKey(), Collections.unmodifiableMap(entry.getValue())); - } - useIdToWallCostMaps = Collections.unmodifiableMap(map); - } - - private int actionType; //1,3 (recv), 0,2 (send) - private int msgID; //used on type 0, 0 on all other types - private String msg; //used on type 0 - private int contractType; //used on type 1 - private int contractID; //used on type 1 - private byte unknown01; //0x01 on type 2 (send city data). 0x00 otherwise - private float x; - private float y; - private float z; - private byte unknown02; //0x01 if data follow, 0x00 otherwise. Best guess - private ArrayList placementInfo; - - private static final int NONE = 0; - private static final int CLIENTREQ_UNKNOWN = 1; - private static final int SERVER_OPENWINDOW = 2; - private static final int CLIENTREQ_NEWBUILDING = 3; // Request to place asset - private static final int SERVER_CLOSEWINDOW = 4; - - /** - * This is the general purpose constructor. - */ - public PlaceAssetMsg() { - super(Protocol.PLACEASSET); - this.placementInfo = new ArrayList<>(); - this.actionType = SERVER_OPENWINDOW; - this.msgID = 0; - this.msg = ""; - this.contractType = 0; - this.contractID = 0; - this.unknown01 = (byte)0x00; - this.x = 0f; - this.y = 0f; - this.z = 0f; - this.unknown02 = (byte)0x01; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public PlaceAssetMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.PLACEASSET, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - - writer.putInt(this.actionType); - - if (this.actionType == NONE) { - writer.putInt(this.msgID); - if (this.msgID != 0) - writer.putString(this.msg); - } else if (this.actionType == SERVER_CLOSEWINDOW) { - //writer.putInt(1); //Qty of assets placed?? A 0 will crash the client. Any value >0 seems to do the same thing. - writer.putInt(0); - } else { - writer.putInt(0); - } - - writer.putInt(this.contractType); - writer.putInt(this.contractID); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putFloat(1f); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - - if (this.actionType == SERVER_OPENWINDOW || (this.actionType == NONE && this.msgID == 0) ) { - //send Place Asset Msg - writer.put((byte)0x01); - writer.putFloat(x); - writer.putFloat(y); - writer.putFloat(z); - for (int i=0;i<3;i++) - writer.putFloat(896); // city Bounds full extent. - for (int i=0;i<3;i++) - writer.putFloat(128); //grid dimensions - PlacementInfo pi = (this.placementInfo.size() > 0) ? this.placementInfo.get(0) : null; - int buildingID = (pi != null) ? pi.getBlueprintUUID() : 0; - if (buildingID == 24200){ - writer.putFloat(875); - writer.putFloat(875); - }else{ - writer.putFloat(576); - writer.putFloat(576); - } - - - - if (buildingID < 6) { - //place wall lists - writer.put((byte)0x01); - writer.putInt(0); - writer.putInt(0); - Map buildings = getBuildingList(buildingID); - writer.putInt(buildings.size()); - for (int bID : buildings.keySet()) { - writer.putInt(0); - writer.putInt(bID); - writer.putInt(buildings.get(bID)); - } - } else { - //send individual building - writer.put((byte)0x00); - writer.putInt(1); - writer.putInt(0); - writer.putInt(buildingID); - writer.putInt(1); - writer.putInt(0); - writer.putInt(0); - } - } else { - //Send Server response to client placing asset - writer.put((byte)0x00); - for (int i=0;i<11;i++) - writer.putFloat(0f); - writer.put((byte)0x00); - writer.putInt(0); - if (this.placementInfo == null) - writer.putInt(0); - else{ - writer.putInt(this.placementInfo.size()); - for (PlacementInfo placementInfo : this.placementInfo){ - writer.putInt(0); - writer.putInt(placementInfo.blueprintUUID); - writer.putVector3f(placementInfo.loc); - writer.putFloat(placementInfo.w); - writer.putVector3f(placementInfo.rot); - } - } - - writer.putInt(0); - } - } - - private static Map getBuildingList(int buildingID) { - if (useIdToWallCostMaps.containsKey(buildingID)) { - return useIdToWallCostMaps.get(buildingID); - } - return new HashMap<>(0); - } - - public static int getWallCost(int blueprintUUID) { - if (wallToCost.containsKey(blueprintUUID)) { - return wallToCost.get(blueprintUUID); - } - Logger.warn("Cost of Wall '" + blueprintUUID + "' was requested but no cost is configured for that wallId."); - return 0; - } - - public static void sendPlaceAssetError(ClientConnection origin, int errorID, String stringData) { - - PlaceAssetMsg outMsg; - - outMsg = new PlaceAssetMsg(); + //Irekei Outer Walls + map.put(1309900, 3); //Irekei Outer Straight Wall + map.put(1309600, 3); //Irekei Outer Wall with Stairs + map.put(1309300, 3); //Irekei Outer Wall Gate + map.put(1310200, 3); //Irekei Concave Tower + map.put(5070800, 3); //Irekei Artillery Tower + map.put(1310500, 3); //Irekei Convex Tower + //Elven Outer Walls + map.put(1331200, 4); //Elven Straight Outer Wall + map.put(1330900, 4); //Elven Outer Wall with Stairs + map.put(1332100, 4); //Elven Outer Wall with Tower + map.put(1330300, 4); //Elven Outer Wall Gate + map.put(1330600, 4); //Elven Gate House + map.put(1331500, 4); //Elven Concave Tower + map.put(5070200, 4); //Elven Artillery Tower + map.put(1332400, 4); //Elven Tower Junction + map.put(1331800, 4); //Elven Convex Tower + //Invorri Outer Walls + map.put(1348900, 5); //Invorri Outer Straight Wall + map.put(1348600, 5); //Invorri Outer Wall with Stairs + map.put(1348300, 5); //Invorri Outer Wall Gate + map.put(1349200, 5); //Invorri Concave Tower + map.put(5071400, 5); //Invorri Artillery Tower + map.put(1349500, 5); //Invorri Convex Tower + wallToUseId = Collections.unmodifiableMap(map); + } + + static { + //autoloaded based on wallToUseId and wallToCost + Map> map = new HashMap<>(); + for (Map.Entry entry : wallToUseId.entrySet()) { + int wallId = entry.getKey(); + int useId = entry.getValue(); + int cost = 0; + Integer costCheck = wallToCost.get(wallId); + if (costCheck != null) { + cost = costCheck; + } else { + throw new Error("PlaceAssetMsg: WallId '" + wallId + "' has no cost in 'wallToCost' but exists in 'useIdToWall'."); + } + if (!map.containsKey(useId)) { + map.put(useId, new HashMap<>()); + } + map.get(useId).put(wallId, cost); + } + for (Map.Entry> entry : map.entrySet()) { + map.put(entry.getKey(), Collections.unmodifiableMap(entry.getValue())); + } + useIdToWallCostMaps = Collections.unmodifiableMap(map); + } + + private int actionType; //1,3 (recv), 0,2 (send) + private int msgID; //used on type 0, 0 on all other types + private String msg; //used on type 0 + private int contractType; //used on type 1 + private int contractID; //used on type 1 + private byte unknown01; //0x01 on type 2 (send city data). 0x00 otherwise + private float x; + private float y; + private float z; + private byte unknown02; //0x01 if data follow, 0x00 otherwise. Best guess + private ArrayList placementInfo; + + /** + * This is the general purpose constructor. + */ + public PlaceAssetMsg() { + super(Protocol.PLACEASSET); + this.placementInfo = new ArrayList<>(); + this.actionType = SERVER_OPENWINDOW; + this.msgID = 0; + this.msg = ""; + this.contractType = 0; + this.contractID = 0; + this.unknown01 = (byte) 0x00; + this.x = 0f; + this.y = 0f; + this.z = 0f; + this.unknown02 = (byte) 0x01; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public PlaceAssetMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.PLACEASSET, origin, reader); + } + + private static Map getBuildingList(int buildingID) { + if (useIdToWallCostMaps.containsKey(buildingID)) { + return useIdToWallCostMaps.get(buildingID); + } + return new HashMap<>(0); + } + + public static int getWallCost(int blueprintUUID) { + if (wallToCost.containsKey(blueprintUUID)) { + return wallToCost.get(blueprintUUID); + } + Logger.warn("Cost of Wall '" + blueprintUUID + "' was requested but no cost is configured for that wallId."); + return 0; + } + + public static void sendPlaceAssetError(ClientConnection origin, int errorID, String stringData) { + + PlaceAssetMsg outMsg; + + outMsg = new PlaceAssetMsg(); outMsg.actionType = 0; outMsg.msgID = errorID; outMsg.msg = stringData; Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } - - public static void sendPlaceAssetConfirmWall(ClientConnection origin, Zone zone) { - - PlaceAssetMsg outMsg = new PlaceAssetMsg(); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } + + public static void sendPlaceAssetConfirmWall(ClientConnection origin, Zone zone) { + + PlaceAssetMsg outMsg = new PlaceAssetMsg(); outMsg.actionType = 0; outMsg.msgID = 0; outMsg.msg = ""; outMsg.x = zone.getLoc().x + 64; outMsg.y = zone.getLoc().y; outMsg.z = zone.getLoc().z + 64; - - Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.placementInfo = new ArrayList<>(); - this.actionType = reader.getInt(); - reader.getInt(); - this.contractType = reader.getInt(); - this.contractID = reader.getInt(); - for (int i=0; i<7; i++) - reader.getInt(); - reader.get(); - for (int i=0; i<11; i++) - reader.getInt(); - reader.get(); - reader.getInt(); - int placementInfo = reader.getInt(); - for (int i=0;i getPlacementInfo() { - return this.placementInfo; - } - public PlacementInfo getFirstPlacementInfo() { - if (this.placementInfo.size() > 0) - return this.placementInfo.get(0); - return null; - } - - public void setActionType(int value) { - this.actionType = value; - } - public void setMsgID(int value) { - this.msgID = value; - } - public void setMsg(String value) { - this.msg = value; - } - public void setContractType(int value) { - this.contractType = value; - } - public void setContractID(int value) { - this.contractID = value; - } - public void setUnknown01(byte value) { - this.unknown01 = value; - } - public void setX(float value) { - this.x = value; - } - public void setY(float value) { - this.y = value; - } - public void setZ(float value) { - this.z = value; - } - public void setUnknown02(byte value) { - this.unknown02 = value; - } - public void addPlacementInfo(int ID) { - PlacementInfo pi = new PlacementInfo(ID, 0f, 0f, 0f, 0f, 0f, 0f, 0f); - this.placementInfo.add(pi); - } - - public static class PlacementInfo { - int blueprintUUID; - Vector3fImmutable loc; - float w; - Vector3fImmutable rot; - public PlacementInfo(int blueprintUUID, float locX, float locY, float locZ, float w, float rotX, float rotY, float rotZ) { - this.blueprintUUID = blueprintUUID; - this.loc = new Vector3fImmutable(locX, locY, locZ); - this.w = w; - this.rot = new Vector3fImmutable(rotX, rotY, rotZ); - } - public int getBlueprintUUID() { - return this.blueprintUUID; - } - public Vector3fImmutable getLoc() { - return this.loc; - } - public float getW() { - return this.w; - } - public Vector3fImmutable getRot() { - return this.rot; - } - public void setLoc(Vector3fImmutable loc) { - this.loc = loc; - } - } + Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), outMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + + writer.putInt(this.actionType); + + if (this.actionType == NONE) { + writer.putInt(this.msgID); + if (this.msgID != 0) + writer.putString(this.msg); + } else if (this.actionType == SERVER_CLOSEWINDOW) { + //writer.putInt(1); //Qty of assets placed?? A 0 will crash the client. Any value >0 seems to do the same thing. + writer.putInt(0); + } else { + writer.putInt(0); + } + + writer.putInt(this.contractType); + writer.putInt(this.contractID); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putFloat(1f); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + + if (this.actionType == SERVER_OPENWINDOW || (this.actionType == NONE && this.msgID == 0)) { + //send Place Asset Msg + writer.put((byte) 0x01); + writer.putFloat(x); + writer.putFloat(y); + writer.putFloat(z); + for (int i = 0; i < 3; i++) + writer.putFloat(896); // city Bounds full extent. + for (int i = 0; i < 3; i++) + writer.putFloat(128); //grid dimensions + PlacementInfo pi = (this.placementInfo.size() > 0) ? this.placementInfo.get(0) : null; + int buildingID = (pi != null) ? pi.getBlueprintUUID() : 0; + if (buildingID == 24200) { + writer.putFloat(875); + writer.putFloat(875); + } else { + writer.putFloat(576); + writer.putFloat(576); + } + + + if (buildingID < 6) { + //place wall lists + writer.put((byte) 0x01); + writer.putInt(0); + writer.putInt(0); + Map buildings = getBuildingList(buildingID); + writer.putInt(buildings.size()); + for (int bID : buildings.keySet()) { + writer.putInt(0); + writer.putInt(bID); + writer.putInt(buildings.get(bID)); + } + } else { + //send individual building + writer.put((byte) 0x00); + writer.putInt(1); + writer.putInt(0); + writer.putInt(buildingID); + writer.putInt(1); + writer.putInt(0); + writer.putInt(0); + } + } else { + //Send Server response to client placing asset + writer.put((byte) 0x00); + for (int i = 0; i < 11; i++) + writer.putFloat(0f); + writer.put((byte) 0x00); + writer.putInt(0); + if (this.placementInfo == null) + writer.putInt(0); + else { + writer.putInt(this.placementInfo.size()); + for (PlacementInfo placementInfo : this.placementInfo) { + writer.putInt(0); + writer.putInt(placementInfo.blueprintUUID); + writer.putVector3f(placementInfo.loc); + writer.putFloat(placementInfo.w); + writer.putVector3f(placementInfo.rot); + } + } + + writer.putInt(0); + } + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.placementInfo = new ArrayList<>(); + this.actionType = reader.getInt(); + reader.getInt(); + this.contractType = reader.getInt(); + this.contractID = reader.getInt(); + for (int i = 0; i < 7; i++) + reader.getInt(); + reader.get(); + for (int i = 0; i < 11; i++) + reader.getInt(); + reader.get(); + reader.getInt(); + int placementInfo = reader.getInt(); + for (int i = 0; i < placementInfo; i++) { + reader.getInt(); + PlacementInfo pi = new PlacementInfo(reader.getInt(), reader.getFloat(), reader.getFloat(), + reader.getFloat(), reader.getFloat(), reader.getFloat(), reader.getFloat(), reader.getFloat()); + this.placementInfo.add(pi); + } + reader.getInt(); + } + + public int getActionType() { + return this.actionType; + } + + public void setActionType(int value) { + this.actionType = value; + } + + public int getID() { + return this.msgID; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String value) { + this.msg = value; + } + + public int getContractType() { + return this.contractType; + } + + public void setContractType(int value) { + this.contractType = value; + } + + public int getContractID() { + return this.contractID; + } + + public void setContractID(int value) { + this.contractID = value; + } + + public byte getUnknown01() { + return this.unknown01; + } + + public void setUnknown01(byte value) { + this.unknown01 = value; + } + + public float getX() { + return this.x; + } + + public void setX(float value) { + this.x = value; + } + + public float getY() { + return this.y; + } + + public void setY(float value) { + this.y = value; + } + + public float getZ() { + return this.z; + } + + public void setZ(float value) { + this.z = value; + } + + public byte getUnknown02() { + return this.unknown02; + } + + public void setUnknown02(byte value) { + this.unknown02 = value; + } + + public ArrayList getPlacementInfo() { + return this.placementInfo; + } + + public PlacementInfo getFirstPlacementInfo() { + if (this.placementInfo.size() > 0) + return this.placementInfo.get(0); + return null; + } + + public void setMsgID(int value) { + this.msgID = value; + } + + public void addPlacementInfo(int ID) { + PlacementInfo pi = new PlacementInfo(ID, 0f, 0f, 0f, 0f, 0f, 0f, 0f); + this.placementInfo.add(pi); + } + + public static class PlacementInfo { + int blueprintUUID; + Vector3fImmutable loc; + float w; + Vector3fImmutable rot; + + public PlacementInfo(int blueprintUUID, float locX, float locY, float locZ, float w, float rotX, float rotY, float rotZ) { + this.blueprintUUID = blueprintUUID; + this.loc = new Vector3fImmutable(locX, locY, locZ); + this.w = w; + this.rot = new Vector3fImmutable(rotX, rotY, rotZ); + } + + public int getBlueprintUUID() { + return this.blueprintUUID; + } + + public Vector3fImmutable getLoc() { + return this.loc; + } + + public void setLoc(Vector3fImmutable loc) { + this.loc = loc; + } + + public float getW() { + return this.w; + } + + public Vector3fImmutable getRot() { + return this.rot; + } + } } diff --git a/src/engine/net/client/msg/PowerProjectileMsg.java b/src/engine/net/client/msg/PowerProjectileMsg.java index 83a0c1d1..0a7f46c2 100644 --- a/src/engine/net/client/msg/PowerProjectileMsg.java +++ b/src/engine/net/client/msg/PowerProjectileMsg.java @@ -19,74 +19,74 @@ import engine.objects.AbstractWorldObject; public class PowerProjectileMsg extends ClientNetMsg { - private AbstractWorldObject source; - private AbstractWorldObject target; - private float range = 10; + private AbstractWorldObject source; + private AbstractWorldObject target; + private float range = 10; - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ - public PowerProjectileMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ARCPOWERPROJECTILE, origin, reader); - } + public PowerProjectileMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ARCPOWERPROJECTILE, origin, reader); + } - public PowerProjectileMsg() { - super(Protocol.ARCPOWERPROJECTILE); - } + public PowerProjectileMsg() { + super(Protocol.ARCPOWERPROJECTILE); + } - public PowerProjectileMsg(AbstractWorldObject source,AbstractWorldObject target) { - super(Protocol.ARCPOWERPROJECTILE); - this.source = source; - this.target = target; - } + public PowerProjectileMsg(AbstractWorldObject source, AbstractWorldObject target) { + super(Protocol.ARCPOWERPROJECTILE); + this.source = source; + this.target = target; + } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { - } + } - // Pre-cache and configure values so they are available when we serialize + // Pre-cache and configure values so they are available when we serialize - public void configure() { + public void configure() { - if (this.source == null) - return; + if (this.source == null) + return; - if (this.target == null) - return; + if (this.target == null) + return; - } + } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { - engine.math.Vector3fImmutable faceDir = this.source.getLoc().subtract2D(target.getLoc()).normalize(); - engine.math.Vector3fImmutable newLoc =faceDir.scaleAdd(range, target.getLoc()); + engine.math.Vector3fImmutable faceDir = this.source.getLoc().subtract2D(target.getLoc()).normalize(); + engine.math.Vector3fImmutable newLoc = faceDir.scaleAdd(range, target.getLoc()); - newLoc = newLoc.setY(newLoc.getY() + range); + newLoc = newLoc.setY(newLoc.getY() + range); - writer.putInt(this.source.getObjectType().ordinal()); - writer.putInt(this.source.getObjectUUID()); - writer.putVector3f(newLoc); + writer.putInt(this.source.getObjectType().ordinal()); + writer.putInt(this.source.getObjectUUID()); + writer.putVector3f(newLoc); - } + } - public float getRange() { - return range; - } + public float getRange() { + return range; + } - public void setRange(float range) { - this.range = range; - } + public void setRange(float range) { + this.range = range; + } } diff --git a/src/engine/net/client/msg/PromptRecallMsg.java b/src/engine/net/client/msg/PromptRecallMsg.java index 40e3bf26..d550bed4 100644 --- a/src/engine/net/client/msg/PromptRecallMsg.java +++ b/src/engine/net/client/msg/PromptRecallMsg.java @@ -17,43 +17,43 @@ import engine.net.client.Protocol; public class PromptRecallMsg extends ClientNetMsg { - private byte confirmation; - - /** - * This is the general purpose constructor. - */ - public PromptRecallMsg() { - super(Protocol.ARCPROMPTRECALL); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public PromptRecallMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ARCPROMPTRECALL, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.put((byte)0x01); // tried 0 and 1 - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.confirmation = reader.get(); - } - - public boolean getConfirmed() { + private byte confirmation; + + /** + * This is the general purpose constructor. + */ + public PromptRecallMsg() { + super(Protocol.ARCPROMPTRECALL); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public PromptRecallMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ARCPROMPTRECALL, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.put((byte) 0x01); // tried 0 and 1 + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.confirmation = reader.get(); + } + + public boolean getConfirmed() { return confirmation == 1; - } + } } \ No newline at end of file diff --git a/src/engine/net/client/msg/RandomMsg.java b/src/engine/net/client/msg/RandomMsg.java index e29d9932..e2b12421 100644 --- a/src/engine/net/client/msg/RandomMsg.java +++ b/src/engine/net/client/msg/RandomMsg.java @@ -17,78 +17,77 @@ import engine.net.client.Protocol; public class RandomMsg extends ClientNetMsg { - private int max; - private int roll; - private int sourceType; - private int sourceID; - - /** - * This is the general purpose constructor. - */ - - public RandomMsg() { - super(Protocol.RANDOM); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public RandomMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.RANDOM, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.max); - writer.putInt(this.roll); - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.max = reader.getInt(); - this.roll = reader.getInt(); - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - } - - public int getMax() { - return this.max; - } - - public int getRoll() { - return this.roll; - } - - public int getSourceType() { - return this.sourceType; - } - - public int getSourceID() { - return this.sourceID; - } - - public void setMax(int value) { - this.max = value; - } - - public void setRoll(int value) { - this.roll = value; - } - - public void setSourceType(int value) { - this.sourceType = value; - } - - public void setSourceID(int value) { - this.sourceID = value; - } + private int max; + private int roll; + private int sourceType; + private int sourceID; + + /** + * This is the general purpose constructor. + */ + + public RandomMsg() { + super(Protocol.RANDOM); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public RandomMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.RANDOM, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.max); + writer.putInt(this.roll); + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.max = reader.getInt(); + this.roll = reader.getInt(); + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + } + + public int getMax() { + return this.max; + } + + public void setMax(int value) { + this.max = value; + } + + public int getRoll() { + return this.roll; + } + + public void setRoll(int value) { + this.roll = value; + } + + public int getSourceType() { + return this.sourceType; + } + + public void setSourceType(int value) { + this.sourceType = value; + } + + public int getSourceID() { + return this.sourceID; + } + + public void setSourceID(int value) { + this.sourceID = value; + } } diff --git a/src/engine/net/client/msg/RecommendNationMsg.java b/src/engine/net/client/msg/RecommendNationMsg.java index 663e2797..f24ea4c1 100644 --- a/src/engine/net/client/msg/RecommendNationMsg.java +++ b/src/engine/net/client/msg/RecommendNationMsg.java @@ -18,75 +18,72 @@ import engine.net.client.Protocol; import engine.objects.PlayerCharacter; - public class RecommendNationMsg extends ClientNetMsg { - private int guildID; - private byte ally; - private byte enemy; - - + private int guildID; + private byte ally; + private byte enemy; - public RecommendNationMsg(PlayerCharacter player) { - super(Protocol.RECOMMENDNATION); + public RecommendNationMsg(PlayerCharacter player) { + super(Protocol.RECOMMENDNATION); - } + } - public RecommendNationMsg() { - super(Protocol.RECOMMENDNATION); - } + public RecommendNationMsg() { + super(Protocol.RECOMMENDNATION); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public RecommendNationMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.RECOMMENDNATION, origin, reader); - } - //CALL THIS AFTER SANITY CHECKS AND BEFORE UPDATING HEALTH/GOLD. + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public RecommendNationMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.RECOMMENDNATION, origin, reader); + } + //CALL THIS AFTER SANITY CHECKS AND BEFORE UPDATING HEALTH/GOLD. - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - reader.getInt(); - this.guildID = reader.getInt(); - this.ally = reader.get(); - this.enemy = reader.get(); - } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.getInt(); + this.guildID = reader.getInt(); + this.ally = reader.get(); + this.enemy = reader.get(); + } - // Precache and configure this message before we serialize it + // Precache and configure this message before we serialize it - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - writer.putInt(GameObjectType.Guild.ordinal()); - writer.putInt(guildID); - writer.put(this.ally); - writer.put(this.enemy); - } + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + writer.putInt(GameObjectType.Guild.ordinal()); + writer.putInt(guildID); + writer.put(this.ally); + writer.put(this.enemy); + } - public int getGuildID() { - return guildID; - } + public int getGuildID() { + return guildID; + } - public byte getAlly() { - return ally; - } + public byte getAlly() { + return ally; + } - public byte getEnemy() { - return enemy; - } + public byte getEnemy() { + return enemy; + } } diff --git a/src/engine/net/client/msg/RecvSummonsRequestMsg.java b/src/engine/net/client/msg/RecvSummonsRequestMsg.java index bb034063..2dd6d5d2 100644 --- a/src/engine/net/client/msg/RecvSummonsRequestMsg.java +++ b/src/engine/net/client/msg/RecvSummonsRequestMsg.java @@ -17,95 +17,95 @@ import engine.net.client.Protocol; public class RecvSummonsRequestMsg extends ClientNetMsg { - private int sourceType; - private int sourceID; - private String sourceName; - private String locationName; //where being summoned to - private boolean accepted; - - /** - * This is the general purpose constructor. - */ - public RecvSummonsRequestMsg(int sourceType, int sourceID, String sourceName, String locationName, boolean accepted) { - super(Protocol.ARCSUMMON); - this.sourceType = sourceType; - this.sourceID = sourceID; - this.sourceName = sourceName; - this.locationName = locationName; - this.accepted = accepted; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public RecvSummonsRequestMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ARCSUMMON, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.putString(this.sourceName); - writer.putString(this.locationName); - writer.put(this.accepted ? (byte)1 : (byte)0); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.sourceName = reader.getString(); - this.locationName = reader.getString(); - this.accepted = (reader.get() == 1) ? true : false; - } - - public int getSourceType() { - return this.sourceType; - } - - public int getSourceID() { - return this.sourceID; - } - - public String getSourceName() { - return this.sourceName; - } - - public String getLocationName() { - return this.locationName; - } - - public boolean accepted() { - return this.accepted; - } - - public void setSourceType(int value) { - this.sourceType = value; - } - - public void setSourceID(int value) { - this.sourceID = value; - } - - public void setSourceName(String value) { - this.sourceName = value; - } - - public void setLocationName(String value) { - this.locationName = value; - } - - public void setAccepted(boolean value) { - this.accepted = value; - } + private int sourceType; + private int sourceID; + private String sourceName; + private String locationName; //where being summoned to + private boolean accepted; + + /** + * This is the general purpose constructor. + */ + public RecvSummonsRequestMsg(int sourceType, int sourceID, String sourceName, String locationName, boolean accepted) { + super(Protocol.ARCSUMMON); + this.sourceType = sourceType; + this.sourceID = sourceID; + this.sourceName = sourceName; + this.locationName = locationName; + this.accepted = accepted; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public RecvSummonsRequestMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ARCSUMMON, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.putString(this.sourceName); + writer.putString(this.locationName); + writer.put(this.accepted ? (byte) 1 : (byte) 0); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.sourceName = reader.getString(); + this.locationName = reader.getString(); + this.accepted = (reader.get() == 1) ? true : false; + } + + public int getSourceType() { + return this.sourceType; + } + + public void setSourceType(int value) { + this.sourceType = value; + } + + public int getSourceID() { + return this.sourceID; + } + + public void setSourceID(int value) { + this.sourceID = value; + } + + public String getSourceName() { + return this.sourceName; + } + + public void setSourceName(String value) { + this.sourceName = value; + } + + public String getLocationName() { + return this.locationName; + } + + public void setLocationName(String value) { + this.locationName = value; + } + + public boolean accepted() { + return this.accepted; + } + + public void setAccepted(boolean value) { + this.accepted = value; + } } diff --git a/src/engine/net/client/msg/RecyclePowerMsg.java b/src/engine/net/client/msg/RecyclePowerMsg.java index 841efe4a..015e5164 100644 --- a/src/engine/net/client/msg/RecyclePowerMsg.java +++ b/src/engine/net/client/msg/RecyclePowerMsg.java @@ -18,45 +18,45 @@ import engine.net.client.Protocol; public class RecyclePowerMsg extends ClientNetMsg { - protected int token; - - public RecyclePowerMsg(int token) { - super(Protocol.RECYCLEPOWER); - this.token = token; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public RecyclePowerMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.RECYCLEPOWER, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.token); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.token = reader.getInt(); - } - - public int getToken() { - return this.token; - } - - public void setToken(int value) { - this.token = value; - } + protected int token; + + public RecyclePowerMsg(int token) { + super(Protocol.RECYCLEPOWER); + this.token = token; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public RecyclePowerMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.RECYCLEPOWER, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.token); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.token = reader.getInt(); + } + + public int getToken() { + return this.token; + } + + public void setToken(int value) { + this.token = value; + } } diff --git a/src/engine/net/client/msg/RefineMsg.java b/src/engine/net/client/msg/RefineMsg.java index cd0a2a47..81968961 100644 --- a/src/engine/net/client/msg/RefineMsg.java +++ b/src/engine/net/client/msg/RefineMsg.java @@ -22,219 +22,219 @@ import java.util.concurrent.ConcurrentHashMap; public class RefineMsg extends ClientNetMsg { - private int npcType; - private int npcID; - private int unknown01; - private int type; - private int token; - private int unknown02; - - /** - * This is the general purpose constructor. - */ - public RefineMsg() { - super(Protocol.ARCUNTRAINABILITY); - } - - public RefineMsg(int npcType, int npcID, int type, int token) { - super(Protocol.ARCUNTRAINABILITY); - this.npcType = npcType; - this.npcID = npcID; - this.unknown01 = 1; - this.type = type; - this.token = token; - this.unknown02 = 0; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public RefineMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ARCUNTRAINABILITY, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.npcType); - writer.putInt(this.npcID); - writer.putInt(this.unknown01); - writer.putInt(this.type); - writer.putInt(this.token); - writer.putInt(this.unknown02); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.npcType = reader.getInt(); - this.npcID = reader.getInt(); - this.unknown01 = reader.getInt(); - this.type = reader.getInt(); - this.token = reader.getInt(); - this.unknown02 = reader.getInt(); - } - - public int getNpcType() { - return this.npcType; - } - - public int getNpcID() { - return this.npcID; - } - - public int getUnknown01() { - return this.unknown01; - } - - public int getType() { - return this.type; - } - - public int getToken() { - return this.token; - } - - public int getUnknown02() { - return this.unknown02; - } - - public void setUnknown01(int value) { - this.unknown01 = value; - } - - public void setType(int value) { - this.type = value; - } - - public void setToken(int value) { - this.token = value; - } - - public void setUnknown02(int value) { - this.unknown02 = value; - } - - public static void refine(RefineMsg msg, ClientConnection origin) { - if (origin == null) - return; - PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); - if (pc == null) - return; + private int npcType; + private int npcID; + private int unknown01; + private int type; + private int token; + private int unknown02; + + /** + * This is the general purpose constructor. + */ + public RefineMsg() { + super(Protocol.ARCUNTRAINABILITY); + } + + public RefineMsg(int npcType, int npcID, int type, int token) { + super(Protocol.ARCUNTRAINABILITY); + this.npcType = npcType; + this.npcID = npcID; + this.unknown01 = 1; + this.type = type; + this.token = token; + this.unknown02 = 0; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public RefineMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ARCUNTRAINABILITY, origin, reader); + } + + public static void refine(RefineMsg msg, ClientConnection origin) { + if (origin == null) + return; + PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); + if (pc == null) + return; NPC npc = NPC.getFromCache(msg.npcID); - if (npc == null) - return; + if (npc == null) + return; int type = msg.type; int token = msg.token; - boolean worked = false; - boolean skillPower = true; - if (type == 0) { //refine skill - worked = refineSkill(origin, pc, token, msg); - } else if (type == 1) { //refine power - worked = refinePower(origin, pc, token, msg); - } else if (type == 2) { //refine stat - worked = refineStat(origin, pc, token, msg); - skillPower = false; - } - - if (worked) { - - //update player - pc.applyBonuses(); - pc.getCharItemManager().RemoveEquipmentFromLackOfSkill(pc, true); - - //echo refine message back - - Dispatch dispatch = Dispatch.borrow(pc, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - - // if (type == 0 && token == 1488335491){ - // dispatch = Dispatch.borrow(pc, msg); - // DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - // } - - //resend refine screen - - RefinerScreenMsg refinerScreenMsg = new RefinerScreenMsg(skillPower, npc.getSellPercent(pc)); //TODO set npc cost - dispatch = Dispatch.borrow(pc, refinerScreenMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - pc.recalculate(); - } - } - - private static boolean refineSkill(ClientConnection origin, PlayerCharacter pc, int token, RefineMsg msg) { - CharacterSkill skill = null; - ConcurrentHashMap skills = pc.getSkills(); - for (CharacterSkill sk : skills.values()) { - if (sk == null) - continue; - SkillsBase sb = sk.getSkillsBase(); - if (sb == null) - continue; - if (sb.getToken() == token) - skill = sk; - } - //check if player has skill to refine - if (skill == null) - return false; - //check there's a train to refine - if (skill.getNumTrains() < 1) - return false; - - //TODO verify if any skills have this as prereq - - //TODO verify if any powers have this as a prereq - //get all players powers - for(CharacterPower power : pc.getPowers().values()){ - ArrayList reqs = PowerReq.getPowerReqsForRune(power.getPowerID()); - for (PowerReq req : reqs) { - ConcurrentHashMap playerSkills = pc.getSkills(); - CharacterSkill playerSkill = playerSkills.get(token); - int currentSkillLevel = playerSkill.getTotalSkillPercet(); - if (token == req.getToken() && req.getLevel() == currentSkillLevel) { - return false; - } - } - } - - //refine skill - return skill.refine(pc); - } - - private static boolean refinePower(ClientConnection origin, PlayerCharacter pc, int token, RefineMsg msg) { - CharacterPower power = null; - ConcurrentHashMap powers = pc.getPowers(); - if (!powers.containsKey(token)) - return false; - power = powers.get(token); - if (power == null) - return false; - if (power.getTrains() < 1) - return false; - - //TODO verify if any powers have this as a prereq - - return power.refine(pc); - } - - private static boolean refineStat(ClientConnection origin, PlayerCharacter pc, int token, RefineMsg msg) { - if (token == MBServerStatics.STAT_STR_ID) - return pc.refineStr(); - if (token == MBServerStatics.STAT_DEX_ID) - return pc.refineDex(); - if (token == MBServerStatics.STAT_CON_ID) - return pc.refineCon(); - if (token == MBServerStatics.STAT_INT_ID) - return pc.refineInt(msg); - if (token == MBServerStatics.STAT_SPI_ID) - return pc.refineSpi(); - return false; - } + boolean worked = false; + boolean skillPower = true; + if (type == 0) { //refine skill + worked = refineSkill(origin, pc, token, msg); + } else if (type == 1) { //refine power + worked = refinePower(origin, pc, token, msg); + } else if (type == 2) { //refine stat + worked = refineStat(origin, pc, token, msg); + skillPower = false; + } + + if (worked) { + + //update player + pc.applyBonuses(); + pc.getCharItemManager().RemoveEquipmentFromLackOfSkill(pc, true); + + //echo refine message back + + Dispatch dispatch = Dispatch.borrow(pc, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + + // if (type == 0 && token == 1488335491){ + // dispatch = Dispatch.borrow(pc, msg); + // DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + // } + + //resend refine screen + + RefinerScreenMsg refinerScreenMsg = new RefinerScreenMsg(skillPower, npc.getSellPercent(pc)); //TODO set npc cost + dispatch = Dispatch.borrow(pc, refinerScreenMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + pc.recalculate(); + } + } + + private static boolean refineSkill(ClientConnection origin, PlayerCharacter pc, int token, RefineMsg msg) { + CharacterSkill skill = null; + ConcurrentHashMap skills = pc.getSkills(); + for (CharacterSkill sk : skills.values()) { + if (sk == null) + continue; + SkillsBase sb = sk.getSkillsBase(); + if (sb == null) + continue; + if (sb.getToken() == token) + skill = sk; + } + //check if player has skill to refine + if (skill == null) + return false; + //check there's a train to refine + if (skill.getNumTrains() < 1) + return false; + + //TODO verify if any skills have this as prereq + + //TODO verify if any powers have this as a prereq + //get all players powers + for (CharacterPower power : pc.getPowers().values()) { + ArrayList reqs = PowerReq.getPowerReqsForRune(power.getPowerID()); + for (PowerReq req : reqs) { + ConcurrentHashMap playerSkills = pc.getSkills(); + CharacterSkill playerSkill = playerSkills.get(token); + int currentSkillLevel = playerSkill.getTotalSkillPercet(); + if (token == req.getToken() && req.getLevel() == currentSkillLevel) { + return false; + } + } + } + + //refine skill + return skill.refine(pc); + } + + private static boolean refinePower(ClientConnection origin, PlayerCharacter pc, int token, RefineMsg msg) { + CharacterPower power = null; + ConcurrentHashMap powers = pc.getPowers(); + if (!powers.containsKey(token)) + return false; + power = powers.get(token); + if (power == null) + return false; + if (power.getTrains() < 1) + return false; + + //TODO verify if any powers have this as a prereq + + return power.refine(pc); + } + + private static boolean refineStat(ClientConnection origin, PlayerCharacter pc, int token, RefineMsg msg) { + if (token == MBServerStatics.STAT_STR_ID) + return pc.refineStr(); + if (token == MBServerStatics.STAT_DEX_ID) + return pc.refineDex(); + if (token == MBServerStatics.STAT_CON_ID) + return pc.refineCon(); + if (token == MBServerStatics.STAT_INT_ID) + return pc.refineInt(msg); + if (token == MBServerStatics.STAT_SPI_ID) + return pc.refineSpi(); + return false; + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.npcType); + writer.putInt(this.npcID); + writer.putInt(this.unknown01); + writer.putInt(this.type); + writer.putInt(this.token); + writer.putInt(this.unknown02); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.npcType = reader.getInt(); + this.npcID = reader.getInt(); + this.unknown01 = reader.getInt(); + this.type = reader.getInt(); + this.token = reader.getInt(); + this.unknown02 = reader.getInt(); + } + + public int getNpcType() { + return this.npcType; + } + + public int getNpcID() { + return this.npcID; + } + + public int getUnknown01() { + return this.unknown01; + } + + public void setUnknown01(int value) { + this.unknown01 = value; + } + + public int getType() { + return this.type; + } + + public void setType(int value) { + this.type = value; + } + + public int getToken() { + return this.token; + } + + public void setToken(int value) { + this.token = value; + } + + public int getUnknown02() { + return this.unknown02; + } + + public void setUnknown02(int value) { + this.unknown02 = value; + } } diff --git a/src/engine/net/client/msg/RefinerScreenMsg.java b/src/engine/net/client/msg/RefinerScreenMsg.java index 4895674a..54f5e8e3 100644 --- a/src/engine/net/client/msg/RefinerScreenMsg.java +++ b/src/engine/net/client/msg/RefinerScreenMsg.java @@ -17,101 +17,101 @@ import engine.net.client.Protocol; public class RefinerScreenMsg extends ClientNetMsg { - private int npcType; - private int npcID; - private int unknown01; //might be - 0: skills/powers, 2: stats - private float unknown02; //cost to refine - private int unknown03; - private int unknown04; - - /** - * This is the general purpose constructor. - */ - public RefinerScreenMsg(boolean skillPower, float cost) { - super(Protocol.ARCUNTRAINLIST); - if (skillPower) - this.unknown01 = 0; //skill/power screen - else - this.unknown01 = 2; //stat screen - this.unknown02 = cost; - this.unknown03 = 0; - this.unknown04 = 0; - } - - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public RefinerScreenMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ARCUNTRAINLIST, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.npcType); - writer.putInt(this.npcID); - writer.putInt(this.unknown01); - writer.putFloat(this.unknown02); - writer.putInt(this.unknown03); - writer.putInt(this.unknown04); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.npcType = reader.getInt(); - this.npcID = reader.getInt(); - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - this.unknown03 = reader.getInt(); - this.unknown04 = reader.getInt(); - } - - public int getNpcType() { - return this.npcType; - } - - public int getNpcID() { - return this.npcID; - } - - public int getUnknown01() { - return this.unknown01; - } - - public float getUnknown02() { - return this.unknown02; - } - - public int getUnknown03() { - return this.unknown03; - } - - public int getUnknown04() { - return this.unknown04; - } - - public void setUnknown01(int value) { - this.unknown01 = value; - } - - public void setUnknown02(int value) { - this.unknown02 = value; - } - - public void setUnknown03(int value) { - this.unknown03 = value; - } - - public void setUnknown04(int value) { - this.unknown04 = value; - } + private int npcType; + private int npcID; + private int unknown01; //might be - 0: skills/powers, 2: stats + private float unknown02; //cost to refine + private int unknown03; + private int unknown04; + + /** + * This is the general purpose constructor. + */ + public RefinerScreenMsg(boolean skillPower, float cost) { + super(Protocol.ARCUNTRAINLIST); + if (skillPower) + this.unknown01 = 0; //skill/power screen + else + this.unknown01 = 2; //stat screen + this.unknown02 = cost; + this.unknown03 = 0; + this.unknown04 = 0; + } + + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public RefinerScreenMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ARCUNTRAINLIST, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.npcType); + writer.putInt(this.npcID); + writer.putInt(this.unknown01); + writer.putFloat(this.unknown02); + writer.putInt(this.unknown03); + writer.putInt(this.unknown04); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.npcType = reader.getInt(); + this.npcID = reader.getInt(); + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + this.unknown03 = reader.getInt(); + this.unknown04 = reader.getInt(); + } + + public int getNpcType() { + return this.npcType; + } + + public int getNpcID() { + return this.npcID; + } + + public int getUnknown01() { + return this.unknown01; + } + + public void setUnknown01(int value) { + this.unknown01 = value; + } + + public float getUnknown02() { + return this.unknown02; + } + + public void setUnknown02(int value) { + this.unknown02 = value; + } + + public int getUnknown03() { + return this.unknown03; + } + + public void setUnknown03(int value) { + this.unknown03 = value; + } + + public int getUnknown04() { + return this.unknown04; + } + + public void setUnknown04(int value) { + this.unknown04 = value; + } } diff --git a/src/engine/net/client/msg/RejectTradeRequestMsg.java b/src/engine/net/client/msg/RejectTradeRequestMsg.java index 8b847e17..1305a3a6 100644 --- a/src/engine/net/client/msg/RejectTradeRequestMsg.java +++ b/src/engine/net/client/msg/RejectTradeRequestMsg.java @@ -24,90 +24,88 @@ import engine.net.client.Protocol; */ public class RejectTradeRequestMsg extends ClientNetMsg { - private int unknown01; //pad? - private long playerCompID; - private long targetCompID; - - /** - * This is the general purpose constructor - */ - public RejectTradeRequestMsg(int unknown01, long playerCompID, long targetCompID) { - super(Protocol.REQUESTTRADECANCEL); - this.unknown01 = unknown01; - this.playerCompID = playerCompID; - this.targetCompID = targetCompID; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public RejectTradeRequestMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.REQUESTTRADECANCEL, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - unknown01 = reader.getInt(); - playerCompID = reader.getLong(); - targetCompID = reader.getLong(); - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - writer.putInt(unknown01); - writer.putLong(playerCompID); - writer.putLong(targetCompID); - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the playerCompID - */ - public long getPlayerCompID() { - return playerCompID; - } - - /** - * @param playerCompID the playerCompID to set - */ - public void setPlayerCompID(long playerCompID) { - this.playerCompID = playerCompID; - } - - /** - * @return the targetCompID - */ - public long getTargetCompID() { - return targetCompID; - } - - /** - * @param targetCompID the targetCompID to set - */ - public void setTargetCompID(long targetCompID) { - this.targetCompID = targetCompID; - } + private int unknown01; //pad? + private long playerCompID; + private long targetCompID; + + /** + * This is the general purpose constructor + */ + public RejectTradeRequestMsg(int unknown01, long playerCompID, long targetCompID) { + super(Protocol.REQUESTTRADECANCEL); + this.unknown01 = unknown01; + this.playerCompID = playerCompID; + this.targetCompID = targetCompID; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public RejectTradeRequestMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.REQUESTTRADECANCEL, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + unknown01 = reader.getInt(); + playerCompID = reader.getLong(); + targetCompID = reader.getLong(); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putInt(unknown01); + writer.putLong(playerCompID); + writer.putLong(targetCompID); + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the playerCompID + */ + public long getPlayerCompID() { + return playerCompID; + } + + /** + * @param playerCompID the playerCompID to set + */ + public void setPlayerCompID(long playerCompID) { + this.playerCompID = playerCompID; + } + + /** + * @return the targetCompID + */ + public long getTargetCompID() { + return targetCompID; + } + + /** + * @param targetCompID the targetCompID to set + */ + public void setTargetCompID(long targetCompID) { + this.targetCompID = targetCompID; + } } diff --git a/src/engine/net/client/msg/RemoveFriendMessage.java b/src/engine/net/client/msg/RemoveFriendMessage.java index 7e96f4c7..47c30e02 100644 --- a/src/engine/net/client/msg/RemoveFriendMessage.java +++ b/src/engine/net/client/msg/RemoveFriendMessage.java @@ -15,53 +15,50 @@ import engine.net.client.Protocol; public class RemoveFriendMessage extends ClientNetMsg { - public int friendID; + public int friendID; - /** - * This is the general purpose constructor. - */ - public RemoveFriendMessage(int friendID) { - super(Protocol.REMOVEFRIEND); - this.friendID = friendID; - } + /** + * This is the general purpose constructor. + */ + public RemoveFriendMessage(int friendID) { + super(Protocol.REMOVEFRIEND); + this.friendID = friendID; + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public RemoveFriendMessage(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.REMOVEFRIEND, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public RemoveFriendMessage(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.REMOVEFRIEND, origin, reader); + } - /** - * Copy constructor - */ - public RemoveFriendMessage(RemoveFriendMessage msg) { - super(Protocol.REMOVEFRIEND); - } - - + /** + * Copy constructor + */ + public RemoveFriendMessage(RemoveFriendMessage msg) { + super(Protocol.REMOVEFRIEND); + } - - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - //Do we even want to try this? - reader.getInt(); - this.friendID = reader.getInt(); - } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(GameObjectType.PlayerCharacter.ordinal()); - writer.putInt(this.friendID); - } + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + //Do we even want to try this? + reader.getInt(); + this.friendID = reader.getInt(); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(GameObjectType.PlayerCharacter.ordinal()); + writer.putInt(this.friendID); + } } diff --git a/src/engine/net/client/msg/RepairBuildingMsg.java b/src/engine/net/client/msg/RepairBuildingMsg.java index a11cb39a..0cb99a56 100644 --- a/src/engine/net/client/msg/RepairBuildingMsg.java +++ b/src/engine/net/client/msg/RepairBuildingMsg.java @@ -19,87 +19,86 @@ import engine.net.client.Protocol; public class RepairBuildingMsg extends ClientNetMsg { - private int type; - private int buildingID; - private int maxHP; - private int missingHealth; - private int strongBox; - private int repairCost; - - - - public RepairBuildingMsg(int buildingID, int maxHP, int missingHealth,int repairCost,int strongBox) { - super(Protocol.REPAIRBUILDING); - this.buildingID = buildingID; - this.maxHP = maxHP; - this.missingHealth = missingHealth; - this.repairCost = repairCost; - this.strongBox = strongBox; - } - - public RepairBuildingMsg() { - super(Protocol.REPAIRBUILDING); - } - - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public RepairBuildingMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.REPAIRBUILDING, origin, reader); - } - //CALL THIS AFTER SANITY CHECKS AND BEFORE UPDATING HEALTH/GOLD. - - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.type = reader.getInt(); - reader.getInt(); //Building Type - this.buildingID = reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - - } - - - // Precache and configure this message before we serialize it - - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - writer.putInt(0); - writer.putInt(GameObjectType.Building.ordinal()); - writer.putInt(this.buildingID); - writer.putInt(this.maxHP); - writer.putInt(this.strongBox); - writer.putInt(0); //? - writer.putInt(this.repairCost); - writer.putInt(this.missingHealth); - - } - - - - public int getBuildingID() { - return buildingID; - } - - public void setBuildingID(int buildingID) { - this.buildingID = buildingID; - } - public int getType() { - return type; - } + private int type; + private int buildingID; + private int maxHP; + private int missingHealth; + private int strongBox; + private int repairCost; + + + public RepairBuildingMsg(int buildingID, int maxHP, int missingHealth, int repairCost, int strongBox) { + super(Protocol.REPAIRBUILDING); + this.buildingID = buildingID; + this.maxHP = maxHP; + this.missingHealth = missingHealth; + this.repairCost = repairCost; + this.strongBox = strongBox; + } + + public RepairBuildingMsg() { + super(Protocol.REPAIRBUILDING); + } + + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public RepairBuildingMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.REPAIRBUILDING, origin, reader); + } + //CALL THIS AFTER SANITY CHECKS AND BEFORE UPDATING HEALTH/GOLD. + + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.type = reader.getInt(); + reader.getInt(); //Building Type + this.buildingID = reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + + } + + + // Precache and configure this message before we serialize it + + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + writer.putInt(0); + writer.putInt(GameObjectType.Building.ordinal()); + writer.putInt(this.buildingID); + writer.putInt(this.maxHP); + writer.putInt(this.strongBox); + writer.putInt(0); //? + writer.putInt(this.repairCost); + writer.putInt(this.missingHealth); + + } + + + public int getBuildingID() { + return buildingID; + } + + public void setBuildingID(int buildingID) { + this.buildingID = buildingID; + } + + public int getType() { + return type; + } } diff --git a/src/engine/net/client/msg/RepairMsg.java b/src/engine/net/client/msg/RepairMsg.java index 4d91a28d..cd3712b5 100644 --- a/src/engine/net/client/msg/RepairMsg.java +++ b/src/engine/net/client/msg/RepairMsg.java @@ -23,7 +23,7 @@ import java.util.ArrayList; /** * Sell to NPC window msg * - * @author + * @author */ public class RepairMsg extends ClientNetMsg { @@ -35,184 +35,182 @@ public class RepairMsg extends ClientNetMsg { //10: charters //13: Jewelry - private int msgType; - //static 0 - private int unknown01; //0 or 10 - private int npcType; - private int npcID; - private NPC npc = null; - private int itemType; - private int itemID; - private int amountRepaired; - //static 0 - //static 0 //end repair req/ack here - //01 inc, 00 out - //item list - //skill list - //unk list - //static 0 //out - //static 0 //out - //static 10000 out? - //static 0 - - /** - * This is the general purpose constructor - */ - public RepairMsg() { - super(Protocol.REPAIROBJECT); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public RepairMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.REPAIROBJECT, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - - this.msgType = reader.getInt(); - reader.getInt(); - this.unknown01 = reader.getInt(); - this.npcType = reader.getInt(); - this.npcID = reader.getInt(); - this.itemType = reader.getInt(); - this.itemID = reader.getInt(); - this.amountRepaired = reader.getInt(); - reader.getInt(); - reader.getInt(); - - if (this.msgType == 1) { - reader.get(); //0x00 inc - int size = reader.getInt(); - for (int i=0;i list = c.getBuyItemType(); - writer.putInt(list.size()); - for (int l : list) - writer.putInt(l); - list = c.getBuySkillToken(); - writer.putInt(list.size()); - for (int l : list) - writer.putInt(l); - list = c.getBuyUnknownToken(); - writer.putInt(list.size()); - for (int l : list) - writer.putInt(l); - } else { - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - } - writer.putInt(0); - writer.putInt(0); - writer.putInt(10000); - writer.putInt(0); - } - } - - public int getMsgType() { - return this.msgType; - } - - public int getNPCType() { - return this.npcType; - } - - public int getNPCID() { - return this.npcID; - } - - public int getItemType() { - return this.itemType; - } - - public int getItemID() { - return this.itemID; - } - - public int getAmountRepaired() { - return this.amountRepaired; - } - - public NPC getNPC() { - return this.npc; - } - - public void setMsgType(int value) { - this.msgType = value; - } - - public void setNPCType(int value) { - this.npcType = value; - } - - public void setNPCID(int value) { - this.npcID = value; - } - - public void setItemType(int value) { - this.itemType = value; - } - - public void setItemID(int value) { - this.itemID = value; - } - - public void setAmountRrepaired(int value) { - this.amountRepaired = value; - } - - public void setNPC(NPC value) { - this.npc = value; - } - - public void setupRepairAck(int amountRepaired) { - this.unknown01 = 10; - this.amountRepaired = amountRepaired; - } - - public void setRepairWindowAck(NPC npc) { - this.unknown01 = 10; - this.npc = npc; - } + private int msgType; + //static 0 + private int unknown01; //0 or 10 + private int npcType; + private int npcID; + private NPC npc = null; + private int itemType; + private int itemID; + private int amountRepaired; + //static 0 + //static 0 //end repair req/ack here + //01 inc, 00 out + //item list + //skill list + //unk list + //static 0 //out + //static 0 //out + //static 10000 out? + //static 0 + + /** + * This is the general purpose constructor + */ + public RepairMsg() { + super(Protocol.REPAIROBJECT); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public RepairMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.REPAIROBJECT, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + + this.msgType = reader.getInt(); + reader.getInt(); + this.unknown01 = reader.getInt(); + this.npcType = reader.getInt(); + this.npcID = reader.getInt(); + this.itemType = reader.getInt(); + this.itemID = reader.getInt(); + this.amountRepaired = reader.getInt(); + reader.getInt(); + reader.getInt(); + + if (this.msgType == 1) { + reader.get(); //0x00 inc + int size = reader.getInt(); + for (int i = 0; i < size; i++) + reader.getInt(); + size = reader.getInt(); + for (int i = 0; i < size; i++) + reader.getInt(); + size = reader.getInt(); + for (int i = 0; i < size; i++) + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + } + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putInt(this.msgType); + writer.putInt(0); + writer.putInt(this.unknown01); + writer.putInt(this.npcType); + writer.putInt(this.npcID); + writer.putInt(this.itemType); + writer.putInt(this.itemID); + writer.putInt(this.amountRepaired); + writer.putInt(0); + writer.putInt(0); + if (this.msgType == 1) { + writer.put((byte) 0x00); + Contract c = (npc != null) ? npc.getContract() : null; + if (c != null) { + ArrayList list = c.getBuyItemType(); + writer.putInt(list.size()); + for (int l : list) + writer.putInt(l); + list = c.getBuySkillToken(); + writer.putInt(list.size()); + for (int l : list) + writer.putInt(l); + list = c.getBuyUnknownToken(); + writer.putInt(list.size()); + for (int l : list) + writer.putInt(l); + } else { + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + } + writer.putInt(0); + writer.putInt(0); + writer.putInt(10000); + writer.putInt(0); + } + } + + public int getMsgType() { + return this.msgType; + } + + public void setMsgType(int value) { + this.msgType = value; + } + + public int getNPCType() { + return this.npcType; + } + + public void setNPCType(int value) { + this.npcType = value; + } + + public int getNPCID() { + return this.npcID; + } + + public void setNPCID(int value) { + this.npcID = value; + } + + public int getItemType() { + return this.itemType; + } + + public void setItemType(int value) { + this.itemType = value; + } + + public int getItemID() { + return this.itemID; + } + + public void setItemID(int value) { + this.itemID = value; + } + + public int getAmountRepaired() { + return this.amountRepaired; + } + + public NPC getNPC() { + return this.npc; + } + + public void setNPC(NPC value) { + this.npc = value; + } + + public void setAmountRrepaired(int value) { + this.amountRepaired = value; + } + + public void setupRepairAck(int amountRepaired) { + this.unknown01 = 10; + this.amountRepaired = amountRepaired; + } + + public void setRepairWindowAck(NPC npc) { + this.unknown01 = 10; + this.npc = npc; + } } diff --git a/src/engine/net/client/msg/ReqBankInventoryMsg.java b/src/engine/net/client/msg/ReqBankInventoryMsg.java index 5fc06443..a2941cef 100644 --- a/src/engine/net/client/msg/ReqBankInventoryMsg.java +++ b/src/engine/net/client/msg/ReqBankInventoryMsg.java @@ -23,65 +23,65 @@ import engine.objects.AbstractGameObject; * @author Burfo */ public class ReqBankInventoryMsg extends ClientNetMsg { - - private int playerType; - private int playerID; - private long unknown01; // possibly NPC ID? - /** - * This is the general purpose constructor. - */ - public ReqBankInventoryMsg(AbstractGameObject ago, long unknown01) { - super(Protocol.OKCOSTTOOPENBANK); - this.playerType = ago.getObjectType().ordinal(); - this.playerID = ago.getObjectUUID(); - this.unknown01 = unknown01; - } + private int playerType; + private int playerID; + private long unknown01; // possibly NPC ID? - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ReqBankInventoryMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.OKCOSTTOOPENBANK, origin, reader); - } + /** + * This is the general purpose constructor. + */ + public ReqBankInventoryMsg(AbstractGameObject ago, long unknown01) { + super(Protocol.OKCOSTTOOPENBANK); + this.playerType = ago.getObjectType().ordinal(); + this.playerID = ago.getObjectUUID(); + this.unknown01 = unknown01; + } - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - playerType = reader.getInt(); - playerID = reader.getInt(); - unknown01 = reader.getLong(); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ReqBankInventoryMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.OKCOSTTOOPENBANK, origin, reader); + } - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - writer.putInt(playerType); - writer.putInt(playerID); - writer.putLong(unknown01); - } + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + playerType = reader.getInt(); + playerID = reader.getInt(); + unknown01 = reader.getLong(); + } - public int getPlayerType() { - return playerType; - } + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + writer.putInt(playerType); + writer.putInt(playerID); + writer.putLong(unknown01); + } - public void setPlayerType(int playerType) { - this.playerType = playerType; - } + public int getPlayerType() { + return playerType; + } - public int getPlayerID() { - return playerID; - } + public void setPlayerType(int playerType) { + this.playerType = playerType; + } + + public int getPlayerID() { + return playerID; + } + + public void setPlayerID(int playerID) { + this.playerID = playerID; + } - public void setPlayerID(int playerID) { - this.playerID = playerID; - } - } diff --git a/src/engine/net/client/msg/RequestBallListMessage.java b/src/engine/net/client/msg/RequestBallListMessage.java index 0483476e..bbdd4365 100644 --- a/src/engine/net/client/msg/RequestBallListMessage.java +++ b/src/engine/net/client/msg/RequestBallListMessage.java @@ -16,58 +16,56 @@ import engine.objects.PlayerCharacter; public class RequestBallListMessage extends ClientNetMsg { - public int playerID; - public String errorMessage; - public int msgType; - - public static int REQUEST = 0; + public static int REQUEST = 0; + public int playerID; + public String errorMessage; + public int msgType; - /** - * This is the general purpose constructor. - */ - public RequestBallListMessage(PlayerCharacter pc) { - super(Protocol.REQUESTBALLLIST); - } + /** + * This is the general purpose constructor. + */ + public RequestBallListMessage(PlayerCharacter pc) { + super(Protocol.REQUESTBALLLIST); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public RequestBallListMessage(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.REQUESTBALLLIST, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public RequestBallListMessage(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.REQUESTBALLLIST, origin, reader); + } - /** - * Copy constructor - */ - public RequestBallListMessage(RequestBallListMessage msg) { - super(Protocol.REQUESTBALLLIST); - } + /** + * Copy constructor + */ + public RequestBallListMessage(RequestBallListMessage msg) { + super(Protocol.REQUESTBALLLIST); + } - - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - reader.getInt(); - this.playerID = reader.getInt(); - this.msgType = reader.getInt(); - this.errorMessage = reader.getString(); - - } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(GameObjectType.PlayerCharacter.ordinal()); - writer.putInt(this.playerID); - writer.putInt(this.msgType); - writer.putString(this.errorMessage); - } + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.getInt(); + this.playerID = reader.getInt(); + this.msgType = reader.getInt(); + this.errorMessage = reader.getString(); + + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(GameObjectType.PlayerCharacter.ordinal()); + writer.putInt(this.playerID); + writer.putInt(this.msgType); + writer.putString(this.errorMessage); + } } diff --git a/src/engine/net/client/msg/RequestEnterWorldMsg.java b/src/engine/net/client/msg/RequestEnterWorldMsg.java index 47af6075..217eb375 100644 --- a/src/engine/net/client/msg/RequestEnterWorldMsg.java +++ b/src/engine/net/client/msg/RequestEnterWorldMsg.java @@ -17,55 +17,54 @@ import engine.net.client.Protocol; public class RequestEnterWorldMsg extends ClientNetMsg { - private byte pad; + private byte pad; - /** - * This is the general purpose constructor. - */ - public RequestEnterWorldMsg() { - super(Protocol.ENTERWORLD); - this.pad = 0x00; - } + /** + * This is the general purpose constructor. + */ + public RequestEnterWorldMsg() { + super(Protocol.ENTERWORLD); + this.pad = 0x00; + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public RequestEnterWorldMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ENTERWORLD, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public RequestEnterWorldMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ENTERWORLD, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.put(this.pad); - } + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.put(this.pad); + } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.pad = reader.get(); - } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.pad = reader.get(); + } - /** - * @return the pad - */ - public byte getPad() { - return pad; - } + /** + * @return the pad + */ + public byte getPad() { + return pad; + } - /** - * @param pad - * the pad to set - */ - public void setPad(byte pad) { - this.pad = pad; - } + /** + * @param pad the pad to set + */ + public void setPad(byte pad) { + this.pad = pad; + } } diff --git a/src/engine/net/client/msg/RespawnMsg.java b/src/engine/net/client/msg/RespawnMsg.java index 21419e47..ebf5eaa5 100644 --- a/src/engine/net/client/msg/RespawnMsg.java +++ b/src/engine/net/client/msg/RespawnMsg.java @@ -17,84 +17,84 @@ import engine.net.client.Protocol; public class RespawnMsg extends ClientNetMsg { - protected int objectType; - protected int objectID; - protected float playerHealth; - protected int playerExp; - - /** - * This is the general purpose constructor. - */ - public RespawnMsg() { - super(Protocol.RESETAFTERDEATH); - this.objectType = 0; - this.objectID = 0; - this.playerHealth = 0; - this.playerExp = 0; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public RespawnMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.RESETAFTERDEATH, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.objectType); - writer.putInt(this.objectID); - writer.putFloat(this.playerHealth); - writer.putInt(this.playerExp); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - - this.objectType = reader.getInt(); - this.objectID = reader.getInt(); - this.playerHealth = reader.getFloat(); - this.playerExp = reader.getInt(); - } - - public int getObjectType() { - return this.objectType; - } - - public int getObjectID() { - return this.objectID; - } - - public float getPlayerHealth() { - return this.playerHealth; - } - - public int getPlayerExp() { - return this.playerExp; - } - - public void setObjectType(int value) { - this.objectType = value; - } - - public void setObjectID(int value) { - this.objectID = value; - } - - public void setPlayerHealth(float value) { - this.playerHealth = value; - } - - public void setPlayerExp(int value) { - this.playerExp = value; - } + protected int objectType; + protected int objectID; + protected float playerHealth; + protected int playerExp; + + /** + * This is the general purpose constructor. + */ + public RespawnMsg() { + super(Protocol.RESETAFTERDEATH); + this.objectType = 0; + this.objectID = 0; + this.playerHealth = 0; + this.playerExp = 0; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public RespawnMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.RESETAFTERDEATH, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.objectType); + writer.putInt(this.objectID); + writer.putFloat(this.playerHealth); + writer.putInt(this.playerExp); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + + this.objectType = reader.getInt(); + this.objectID = reader.getInt(); + this.playerHealth = reader.getFloat(); + this.playerExp = reader.getInt(); + } + + public int getObjectType() { + return this.objectType; + } + + public void setObjectType(int value) { + this.objectType = value; + } + + public int getObjectID() { + return this.objectID; + } + + public void setObjectID(int value) { + this.objectID = value; + } + + public float getPlayerHealth() { + return this.playerHealth; + } + + public void setPlayerHealth(float value) { + this.playerHealth = value; + } + + public int getPlayerExp() { + return this.playerExp; + } + + public void setPlayerExp(int value) { + this.playerExp = value; + } } diff --git a/src/engine/net/client/msg/RespondLeaveWorldMsg.java b/src/engine/net/client/msg/RespondLeaveWorldMsg.java index 0268925f..a2c646dc 100644 --- a/src/engine/net/client/msg/RespondLeaveWorldMsg.java +++ b/src/engine/net/client/msg/RespondLeaveWorldMsg.java @@ -18,35 +18,35 @@ import engine.net.client.Protocol; public class RespondLeaveWorldMsg extends ClientNetMsg { - /** - * This is the general purpose constructor. - */ - public RespondLeaveWorldMsg() { - super(Protocol.LEAVEWORLD); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public RespondLeaveWorldMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.LEAVEWORLD, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - } + /** + * This is the general purpose constructor. + */ + public RespondLeaveWorldMsg() { + super(Protocol.LEAVEWORLD); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public RespondLeaveWorldMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.LEAVEWORLD, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + } } diff --git a/src/engine/net/client/msg/RotateObjectMsg.java b/src/engine/net/client/msg/RotateObjectMsg.java index 30a9677a..090a9b8c 100644 --- a/src/engine/net/client/msg/RotateObjectMsg.java +++ b/src/engine/net/client/msg/RotateObjectMsg.java @@ -19,43 +19,42 @@ import engine.objects.Mob; public class RotateObjectMsg extends ClientNetMsg { - - /** - * This is the general purpose constructor. - */ - public RotateObjectMsg(int type, Mob pet) { - super(Protocol.ROTATEMSG); - - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public RotateObjectMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ROTATEMSG, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - reader.getInt(); - reader.getInt(); - reader.getFloat(); - reader.getFloat(); - reader.getFloat(); - reader.getInt(); - } + /** + * This is the general purpose constructor. + */ + public RotateObjectMsg(int type, Mob pet) { + super(Protocol.ROTATEMSG); + + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public RotateObjectMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ROTATEMSG, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.getInt(); + reader.getInt(); + reader.getFloat(); + reader.getFloat(); + reader.getFloat(); + reader.getInt(); + } } diff --git a/src/engine/net/client/msg/SafeModeMsg.java b/src/engine/net/client/msg/SafeModeMsg.java index 3286e0a5..8dfb9de5 100644 --- a/src/engine/net/client/msg/SafeModeMsg.java +++ b/src/engine/net/client/msg/SafeModeMsg.java @@ -18,55 +18,55 @@ import engine.net.client.Protocol; public class SafeModeMsg extends ClientNetMsg { - private String message; + private String message; - /** - * Helper Constructor. - * - * This is the general purpose constructor. - */ - public SafeModeMsg() { - this("Safe Mode"); - } + /** + * Helper Constructor. + *

+ * This is the general purpose constructor. + */ + public SafeModeMsg() { + this("Safe Mode"); + } - /** - * This is the general purpose constructor. - */ - public SafeModeMsg(String message) { - super(Protocol.SAFEMODE); - this.message = message; - } + /** + * This is the general purpose constructor. + */ + public SafeModeMsg(String message) { + super(Protocol.SAFEMODE); + this.message = message; + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public SafeModeMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.SAFEMODE, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public SafeModeMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SAFEMODE, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putString(this.message); - } + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putString(this.message); + } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.message = reader.getString(); - } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.message = reader.getString(); + } - /** - * @return the message - */ - public String getMessage() { - return message; - } + /** + * @return the message + */ + public String getMessage() { + return message; + } } diff --git a/src/engine/net/client/msg/ScaleObjectMsg.java b/src/engine/net/client/msg/ScaleObjectMsg.java index f363672b..877fbcef 100644 --- a/src/engine/net/client/msg/ScaleObjectMsg.java +++ b/src/engine/net/client/msg/ScaleObjectMsg.java @@ -17,83 +17,83 @@ import engine.net.client.Protocol; public class ScaleObjectMsg extends ClientNetMsg { - private long compID; - private float scaleX; - private float scaleY; - private float scaleZ; - - /** - * This is the general purpose constructor. - */ - public ScaleObjectMsg(long compID, float scaleX, float scaleY, float scaleZ) { - super(Protocol.SCALEOBJECT); - this.compID = compID; - this.scaleX = scaleX; - this.scaleY = scaleY; - this.scaleZ = scaleZ; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ScaleObjectMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.SCALEOBJECT, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putLong(this.compID); - writer.putFloat(this.scaleX); - writer.putFloat(this.scaleY); - writer.putFloat(this.scaleZ); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.compID = reader.getLong(); - this.scaleX = reader.getFloat(); - this.scaleY = reader.getFloat(); - this.scaleZ = reader.getFloat(); - } - - public long getCompID() { - return this.compID; - } - - public float getScaleX() { - return this.scaleX; - } - - public float getScaleY() { - return this.scaleY; - } - - public float getScaleZ() { - return this.scaleZ; - } - - public void setCompID(long value) { - this.compID = value; - } - - public void setScaleX(float value) { - this.scaleX = value; - } - - public void setScaleY(float value) { - this.scaleY = value; - } - - public void setScaleZ(float value) { - this.scaleZ = value; - } + private long compID; + private float scaleX; + private float scaleY; + private float scaleZ; + + /** + * This is the general purpose constructor. + */ + public ScaleObjectMsg(long compID, float scaleX, float scaleY, float scaleZ) { + super(Protocol.SCALEOBJECT); + this.compID = compID; + this.scaleX = scaleX; + this.scaleY = scaleY; + this.scaleZ = scaleZ; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ScaleObjectMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SCALEOBJECT, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putLong(this.compID); + writer.putFloat(this.scaleX); + writer.putFloat(this.scaleY); + writer.putFloat(this.scaleZ); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.compID = reader.getLong(); + this.scaleX = reader.getFloat(); + this.scaleY = reader.getFloat(); + this.scaleZ = reader.getFloat(); + } + + public long getCompID() { + return this.compID; + } + + public void setCompID(long value) { + this.compID = value; + } + + public float getScaleX() { + return this.scaleX; + } + + public void setScaleX(float value) { + this.scaleX = value; + } + + public float getScaleY() { + return this.scaleY; + } + + public void setScaleY(float value) { + this.scaleY = value; + } + + public float getScaleZ() { + return this.scaleZ; + } + + public void setScaleZ(float value) { + this.scaleZ = value; + } } diff --git a/src/engine/net/client/msg/SelectCityMsg.java b/src/engine/net/client/msg/SelectCityMsg.java index 5e96a644..4e13af87 100644 --- a/src/engine/net/client/msg/SelectCityMsg.java +++ b/src/engine/net/client/msg/SelectCityMsg.java @@ -20,74 +20,75 @@ import engine.objects.PlayerCharacter; public class SelectCityMsg extends ClientNetMsg { - private PlayerCharacter pc; - private boolean isTeleport; - - /** - * This is the general purpose constructor. - */ - public SelectCityMsg(PlayerCharacter pc, boolean isTeleport) { - super(Protocol.SELECTCITY); - this.pc = pc; - this.isTeleport = isTeleport; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public SelectCityMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.SELECTCITY, origin, reader); - } - - /** - * Copy constructor - */ - public SelectCityMsg(SelectCityMsg msg) { - super(Protocol.SELECTCITY); - this.pc = msg.pc; - this.isTeleport = msg.isTeleport; - } - - /** - * @see AbstractNetMsg#getPowerOfTwoBufferSize() - */ - @Override - protected int getPowerOfTwoBufferSize() { - // Larger size for historically larger opcodes - return (12); - } - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - //Do we even want to try this? - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.put((byte)0); - } - - public PlayerCharacter pc() { - return this.pc; - } - - public boolean isTeleport() { - return this.isTeleport; - } - - public void setPC(PlayerCharacter pc) { - this.pc = pc; - } - - public void setIsTeleport(boolean value) { - this.isTeleport = value; - } + private PlayerCharacter pc; + private boolean isTeleport; + + /** + * This is the general purpose constructor. + */ + public SelectCityMsg(PlayerCharacter pc, boolean isTeleport) { + super(Protocol.SELECTCITY); + this.pc = pc; + this.isTeleport = isTeleport; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public SelectCityMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SELECTCITY, origin, reader); + } + + /** + * Copy constructor + */ + public SelectCityMsg(SelectCityMsg msg) { + super(Protocol.SELECTCITY); + this.pc = msg.pc; + this.isTeleport = msg.isTeleport; + } + + /** + * @see AbstractNetMsg#getPowerOfTwoBufferSize() + */ + @Override + protected int getPowerOfTwoBufferSize() { + // Larger size for historically larger opcodes + return (12); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + //Do we even want to try this? + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.put((byte) 0); + } + + public PlayerCharacter pc() { + return this.pc; + } + + public boolean isTeleport() { + return this.isTeleport; + } + + public void setPC(PlayerCharacter pc) { + this.pc = pc; + } + + public void setIsTeleport(boolean value) { + this.isTeleport = value; + } } diff --git a/src/engine/net/client/msg/SellToNPCMsg.java b/src/engine/net/client/msg/SellToNPCMsg.java index 0c28f003..dba25dba 100644 --- a/src/engine/net/client/msg/SellToNPCMsg.java +++ b/src/engine/net/client/msg/SellToNPCMsg.java @@ -23,93 +23,91 @@ import engine.net.client.Protocol; */ public class SellToNPCMsg extends ClientNetMsg { - int npcType; - int npcID; - int itemType; - int itemID; - int unknown01; - - /** - * This is the general purpose constructor - */ - public SellToNPCMsg() { - super(Protocol.SELLOBJECT); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public SellToNPCMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.SELLOBJECT, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - this.npcType = reader.getInt(); - this.npcID = reader.getInt(); - this.itemType = reader.getInt(); - this.itemID = reader.getInt(); - this.unknown01 = reader.getInt(); - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - writer.putInt(this.npcType); - writer.putInt(this.npcID); - writer.putInt(this.itemType); - writer.putInt(this.itemID); - writer.putInt(this.unknown01); - } - - public int getNPCType() { - return this.npcType; - } - - public int getNPCID() { - return this.npcID; - } - - public int getItemType() { - return this.itemType; - } - - public int getItemID() { - return this.itemID; - } - - public int getUnknown01() { - return this.unknown01; - } - - public void setNPCType(int value) { - this.npcType = value; - } - - public void setNPCID(int value) { - this.npcID = value; - } - - public void setItemType(int value) { - this.itemType = value; - } - - public void setItemID(int value) { - this.itemID = value; - } - - public void setUnknown01(int value) { - this.unknown01 = value; - } + int npcType; + int npcID; + int itemType; + int itemID; + int unknown01; + + /** + * This is the general purpose constructor + */ + public SellToNPCMsg() { + super(Protocol.SELLOBJECT); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public SellToNPCMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SELLOBJECT, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.npcType = reader.getInt(); + this.npcID = reader.getInt(); + this.itemType = reader.getInt(); + this.itemID = reader.getInt(); + this.unknown01 = reader.getInt(); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putInt(this.npcType); + writer.putInt(this.npcID); + writer.putInt(this.itemType); + writer.putInt(this.itemID); + writer.putInt(this.unknown01); + } + + public int getNPCType() { + return this.npcType; + } + + public void setNPCType(int value) { + this.npcType = value; + } + + public int getNPCID() { + return this.npcID; + } + + public void setNPCID(int value) { + this.npcID = value; + } + + public int getItemType() { + return this.itemType; + } + + public void setItemType(int value) { + this.itemType = value; + } + + public int getItemID() { + return this.itemID; + } + + public void setItemID(int value) { + this.itemID = value; + } + + public int getUnknown01() { + return this.unknown01; + } + + public void setUnknown01(int value) { + this.unknown01 = value; + } } diff --git a/src/engine/net/client/msg/SellToNPCWindowMsg.java b/src/engine/net/client/msg/SellToNPCWindowMsg.java index b9a30c74..17e37139 100644 --- a/src/engine/net/client/msg/SellToNPCWindowMsg.java +++ b/src/engine/net/client/msg/SellToNPCWindowMsg.java @@ -35,255 +35,253 @@ public class SellToNPCWindowMsg extends ClientNetMsg { //13: Jewelry - private int npcType; - private int npcID; - private byte unknownByte01; //so far always 0x00 - private byte unknownByte02; //0: show only specified, 1: show all - private ArrayList itemTypes; - private ArrayList skillTokens; - private ArrayList unknownArray02; - private int unknown01; //so far always 0 - private int unknown02; //so far always 0 on output - private int unknown03; //so far always 10000 - private int unknown04; //so far always 0 on output - private float unknown05; //suspect sell percentage, ex: 0.26 for 26% - private int unknown06; //suspect gold available on vendor - private int unknown07; //so far always 0 - - /** - * This is the general purpose constructor - */ - public SellToNPCWindowMsg(int npcType, int npcID, byte unknownByte02, - ArrayList itemTypes, ArrayList skillTokens, - ArrayList unknownArray02, float unknown05, int unknown06) { - super(Protocol.SHOPINFO); - this.npcType = npcType; - this.npcID = npcID; - this.unknownByte01 = (byte)0; - this.unknownByte02 = unknownByte02; - this.itemTypes = itemTypes; - this.skillTokens = skillTokens; - this.unknownArray02 = unknownArray02; - this.unknown01 = 0; - this.unknown02 = 0; - this.unknown03 = 10000; - this.unknown04 = 0; - this.unknown05 = unknown05; - this.unknown06 = unknown06; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public SellToNPCWindowMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.SHOPINFO, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - - this.itemTypes = new ArrayList<>(); - this.skillTokens = new ArrayList<>(); - this.unknownArray02 = new ArrayList<>(); - - this.npcType = reader.getInt(); - this.npcID = reader.getInt(); - this.unknownByte01 = reader.get(); - this.unknownByte02 = reader.get(); - int cnt = reader.getInt(); - for (int i=0; i getItemTypes() { - return this.itemTypes; - } - - public ArrayList getSkillTokens() { - return this.skillTokens; - } - - public ArrayList getUnknownArray02() { - return this.unknownArray02; - } - - public int getUnknown01() { - return unknown01; - } - - public int getUnknown02() { - return unknown02; - } - - public int getUnknown03() { - return unknown03; - } - - public int getUnknown04() { - return unknown04; - } - - public float getUnknown05() { - return unknown05; - } - - public int getUnknown06() { - return unknown06; - } - - public int getUnknown07() { - return unknown07; - } - - public void setNPCType(int value) { - this.npcType = value; - } - - public void setNPCID(int value) { - this.npcID = value; - } - - public void setUnknownByte01(byte value) { - this.unknownByte01 = value; - } - - public void setUnknownByte02(byte value) { - this.unknownByte02 = value; - } - - public void setItemTypes(ArrayList value) { - this.itemTypes = value; - } - - public void setskillTokens(ArrayList value) { - this.skillTokens = value; - } - - public void setUnknownArray02(ArrayList value) { - this.unknownArray02 = value; - } - - public void setUnknown01(int value) { - this.unknown01 = value; - } - - public void setUnknown02(int value) { - this.unknown02 = value; - } - - public void setUnknown03(int value) { - this.unknown03 = value; - } - - public void setUnknown04(int value) { - this.unknown04 = value; - } - - public void setUnknown05(float value) { - this.unknown05 = value; - } - - public void setUnknown06(int value) { - this.unknown06 = value; - } - - public void setUnknown07(int value) { - this.unknown07 = value; - } - - public void addItemType(int value) { - this.itemTypes.add(value); - } - - public void addSkillToken(int value) { - this.skillTokens.add(value); - } - - public void addUnknownArray02(int value) { - this.unknownArray02.add(value); - } - - public void setItemType(ArrayList value) { - this.itemTypes = value; - } - - public void setSkillTokens(ArrayList value) { - this.skillTokens = value; - } - - public void setUnknownArray(ArrayList value) { - this.unknownArray02 = value; - } - - public void setupOutput() { - this.unknownByte01 = (byte)0; - this.unknownByte02 = (byte)0; - this.unknown01 = 0; - this.unknown02 = 0; - this.unknown03 = 10000; - this.unknown04 = 0; - this.unknown07 = 0; - } + private int npcType; + private int npcID; + private byte unknownByte01; //so far always 0x00 + private byte unknownByte02; //0: show only specified, 1: show all + private ArrayList itemTypes; + private ArrayList skillTokens; + private ArrayList unknownArray02; + private int unknown01; //so far always 0 + private int unknown02; //so far always 0 on output + private int unknown03; //so far always 10000 + private int unknown04; //so far always 0 on output + private float unknown05; //suspect sell percentage, ex: 0.26 for 26% + private int unknown06; //suspect gold available on vendor + private int unknown07; //so far always 0 + + /** + * This is the general purpose constructor + */ + public SellToNPCWindowMsg(int npcType, int npcID, byte unknownByte02, + ArrayList itemTypes, ArrayList skillTokens, + ArrayList unknownArray02, float unknown05, int unknown06) { + super(Protocol.SHOPINFO); + this.npcType = npcType; + this.npcID = npcID; + this.unknownByte01 = (byte) 0; + this.unknownByte02 = unknownByte02; + this.itemTypes = itemTypes; + this.skillTokens = skillTokens; + this.unknownArray02 = unknownArray02; + this.unknown01 = 0; + this.unknown02 = 0; + this.unknown03 = 10000; + this.unknown04 = 0; + this.unknown05 = unknown05; + this.unknown06 = unknown06; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public SellToNPCWindowMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SHOPINFO, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + + this.itemTypes = new ArrayList<>(); + this.skillTokens = new ArrayList<>(); + this.unknownArray02 = new ArrayList<>(); + + this.npcType = reader.getInt(); + this.npcID = reader.getInt(); + this.unknownByte01 = reader.get(); + this.unknownByte02 = reader.get(); + int cnt = reader.getInt(); + for (int i = 0; i < cnt; i++) + this.itemTypes.add(reader.getInt()); + cnt = reader.getInt(); + for (int i = 0; i < cnt; i++) + this.skillTokens.add(reader.getInt()); + cnt = reader.getInt(); + for (int i = 0; i < cnt; i++) + this.unknownArray02.add(reader.getInt()); + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + this.unknown03 = reader.getInt(); + this.unknown04 = reader.getInt(); + this.unknown05 = reader.getFloat(); + this.unknown06 = reader.getInt(); + this.unknown07 = reader.getInt(); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putInt(this.npcType); + writer.putInt(this.npcID); + writer.put(this.unknownByte01); + writer.put(this.unknownByte02); + writer.putInt(this.itemTypes.size()); + for (Integer i : this.itemTypes) + writer.putInt(i); + writer.putInt(this.skillTokens.size()); + for (Integer i : this.skillTokens) + writer.putInt(i); + writer.putInt(this.unknownArray02.size()); + for (Integer i : this.unknownArray02) + writer.putInt(i); + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + writer.putInt(this.unknown03); + writer.putInt(this.unknown04); + writer.putFloat(this.unknown05); + writer.putInt(this.unknown06); + writer.putInt(this.unknown07); + } + + public int getNPCType() { + return this.npcType; + } + + public void setNPCType(int value) { + this.npcType = value; + } + + public int getNPCID() { + return this.npcID; + } + + public void setNPCID(int value) { + this.npcID = value; + } + + public byte getUnknownByte01() { + return this.unknownByte01; + } + + public void setUnknownByte01(byte value) { + this.unknownByte01 = value; + } + + public byte getUnknownByte02() { + return this.unknownByte02; + } + + public void setUnknownByte02(byte value) { + this.unknownByte02 = value; + } + + public ArrayList getItemTypes() { + return this.itemTypes; + } + + public void setItemTypes(ArrayList value) { + this.itemTypes = value; + } + + public ArrayList getSkillTokens() { + return this.skillTokens; + } + + public void setSkillTokens(ArrayList value) { + this.skillTokens = value; + } + + public ArrayList getUnknownArray02() { + return this.unknownArray02; + } + + public void setUnknownArray02(ArrayList value) { + this.unknownArray02 = value; + } + + public int getUnknown01() { + return unknown01; + } + + public void setUnknown01(int value) { + this.unknown01 = value; + } + + public int getUnknown02() { + return unknown02; + } + + public void setUnknown02(int value) { + this.unknown02 = value; + } + + public int getUnknown03() { + return unknown03; + } + + public void setUnknown03(int value) { + this.unknown03 = value; + } + + public int getUnknown04() { + return unknown04; + } + + public void setUnknown04(int value) { + this.unknown04 = value; + } + + public float getUnknown05() { + return unknown05; + } + + public void setUnknown05(float value) { + this.unknown05 = value; + } + + public int getUnknown06() { + return unknown06; + } + + public void setUnknown06(int value) { + this.unknown06 = value; + } + + public int getUnknown07() { + return unknown07; + } + + public void setUnknown07(int value) { + this.unknown07 = value; + } + + public void setskillTokens(ArrayList value) { + this.skillTokens = value; + } + + public void addItemType(int value) { + this.itemTypes.add(value); + } + + public void addSkillToken(int value) { + this.skillTokens.add(value); + } + + public void addUnknownArray02(int value) { + this.unknownArray02.add(value); + } + + public void setItemType(ArrayList value) { + this.itemTypes = value; + } + + public void setUnknownArray(ArrayList value) { + this.unknownArray02 = value; + } + + public void setupOutput() { + this.unknownByte01 = (byte) 0; + this.unknownByte02 = (byte) 0; + this.unknown01 = 0; + this.unknown02 = 0; + this.unknown03 = 10000; + this.unknown04 = 0; + this.unknown07 = 0; + } } diff --git a/src/engine/net/client/msg/SendBallEntryMessage.java b/src/engine/net/client/msg/SendBallEntryMessage.java index 8c32c9c3..9b431841 100644 --- a/src/engine/net/client/msg/SendBallEntryMessage.java +++ b/src/engine/net/client/msg/SendBallEntryMessage.java @@ -15,93 +15,92 @@ import engine.objects.PlayerCharacter; public class SendBallEntryMessage extends ClientNetMsg { - public int playerID; - public String description; - public int msgType; - public int ballColor; - public static final int ADDBALL = 4; - public static final int WHITEBALL = 2; - public static final int BLACKBALL = 1; - - /** - * This is the general purpose constructor. - */ - public SendBallEntryMessage(PlayerCharacter pc) { - super(Protocol.SENDBALLENTRY); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public SendBallEntryMessage(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.SENDBALLENTRY, origin, reader); - } - - /** - * Copy constructor - */ - public SendBallEntryMessage(SendBallEntryMessage msg) { - super(Protocol.SENDBALLENTRY); - } - - - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.msgType = reader.getInt(); - - switch (this.msgType){ - case ADDBALL: - this.readAddBall(reader); - break; - default: - break; - } - - } - - public void readAddBall(ByteBufferReader reader){ - reader.getInt(); - this.playerID = reader.getInt(); - - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - - reader.getInt(); // 1 ? - - reader.getInt(); - reader.getInt(); - - reader.getInt(); // source player type - reader.getInt(); // source player ID - - reader.getInt(); // targetType - reader.getInt(); // targetID (same as this.playerID) - this.description = reader.getString(); - reader.get(); - reader.get(); - reader.getInt(); // 100, max ball mark - reader.get(); - reader.get(); - reader.get(); - this.ballColor = reader.getInt(); - reader.get(); - - - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - } + public static final int ADDBALL = 4; + public static final int WHITEBALL = 2; + public static final int BLACKBALL = 1; + public int playerID; + public String description; + public int msgType; + public int ballColor; + + /** + * This is the general purpose constructor. + */ + public SendBallEntryMessage(PlayerCharacter pc) { + super(Protocol.SENDBALLENTRY); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public SendBallEntryMessage(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SENDBALLENTRY, origin, reader); + } + + /** + * Copy constructor + */ + public SendBallEntryMessage(SendBallEntryMessage msg) { + super(Protocol.SENDBALLENTRY); + } + + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.msgType = reader.getInt(); + + switch (this.msgType) { + case ADDBALL: + this.readAddBall(reader); + break; + default: + break; + } + + } + + public void readAddBall(ByteBufferReader reader) { + reader.getInt(); + this.playerID = reader.getInt(); + + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + + reader.getInt(); // 1 ? + + reader.getInt(); + reader.getInt(); + + reader.getInt(); // source player type + reader.getInt(); // source player ID + + reader.getInt(); // targetType + reader.getInt(); // targetID (same as this.playerID) + this.description = reader.getString(); + reader.get(); + reader.get(); + reader.getInt(); // 100, max ball mark + reader.get(); + reader.get(); + reader.get(); + this.ballColor = reader.getInt(); + reader.get(); + + + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + } } diff --git a/src/engine/net/client/msg/SendOwnPlayerMsg.java b/src/engine/net/client/msg/SendOwnPlayerMsg.java index 2a829990..f83f0dc1 100644 --- a/src/engine/net/client/msg/SendOwnPlayerMsg.java +++ b/src/engine/net/client/msg/SendOwnPlayerMsg.java @@ -24,100 +24,98 @@ import org.pmw.tinylog.Logger; public class SendOwnPlayerMsg extends ClientNetMsg { - private PlayerCharacter ch; - - /** - * This is the general purpose constructor. - * - * @param s - * Session from which the PlayerCharacter is obtained - */ - public SendOwnPlayerMsg(Session s) { - super(Protocol.PLAYERDATA); - - // Get all the character records for this account - ch = s.getPlayerCharacter(); - } - - /** - * This is the general purpose constructor. - * - * @param pc - * Playercharacter - */ - public SendOwnPlayerMsg(PlayerCharacter pc) { - super(Protocol.PLAYERDATA); - this.ch = pc; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public SendOwnPlayerMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.PLAYERDATA, origin, reader); - } - - /** - * @see AbstractNetMsg#getPowerOfTwoBufferSize() - */ - @Override - protected int getPowerOfTwoBufferSize() { - //Larger size for historically larger opcodes - return (17); // 2^17 == 131,072 - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - - Regions region = this.ch.region; - //region loading seralization. serialzes building level and floor. -1 = not in building. - if (region == null) { - writer.putInt(-1); - writer.putInt(-1); - } else { - Building regionBuilding = Regions.GetBuildingForRegion(region); - if (regionBuilding == null) { - writer.putInt(-1); - writer.putInt(-1); - } else { - writer.putInt(region.getLevel()); - writer.putInt(region.getRoom()); - } - } - writer.putVector3f(ch.getLoc()); - try { - PlayerCharacter.serializeForClientMsgFull(this.ch,writer); - } catch (SerializationException e) { - Logger.error(e); - } - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - - int unknown1 = reader.getInt(); - int unknown2 = reader.getInt(); - - int unknown3 = reader.getInt(); - int unknown4 = reader.getInt(); - - int unknown5 = reader.getInt(); - int unknown6 = reader.getInt(); - int unknown7 = reader.getInt(); - - // TODO finish deserialization implementation. - } - - public PlayerCharacter getChar() { - return this.ch; - } + private PlayerCharacter ch; + + /** + * This is the general purpose constructor. + * + * @param s Session from which the PlayerCharacter is obtained + */ + public SendOwnPlayerMsg(Session s) { + super(Protocol.PLAYERDATA); + + // Get all the character records for this account + ch = s.getPlayerCharacter(); + } + + /** + * This is the general purpose constructor. + * + * @param pc Playercharacter + */ + public SendOwnPlayerMsg(PlayerCharacter pc) { + super(Protocol.PLAYERDATA); + this.ch = pc; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public SendOwnPlayerMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.PLAYERDATA, origin, reader); + } + + /** + * @see AbstractNetMsg#getPowerOfTwoBufferSize() + */ + @Override + protected int getPowerOfTwoBufferSize() { + //Larger size for historically larger opcodes + return (17); // 2^17 == 131,072 + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + + Regions region = this.ch.region; + //region loading seralization. serialzes building level and floor. -1 = not in building. + if (region == null) { + writer.putInt(-1); + writer.putInt(-1); + } else { + Building regionBuilding = Regions.GetBuildingForRegion(region); + if (regionBuilding == null) { + writer.putInt(-1); + writer.putInt(-1); + } else { + writer.putInt(region.getLevel()); + writer.putInt(region.getRoom()); + } + } + writer.putVector3f(ch.getLoc()); + try { + PlayerCharacter.serializeForClientMsgFull(this.ch, writer); + } catch (SerializationException e) { + Logger.error(e); + } + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + + int unknown1 = reader.getInt(); + int unknown2 = reader.getInt(); + + int unknown3 = reader.getInt(); + int unknown4 = reader.getInt(); + + int unknown5 = reader.getInt(); + int unknown6 = reader.getInt(); + int unknown7 = reader.getInt(); + + // TODO finish deserialization implementation. + } + + public PlayerCharacter getChar() { + return this.ch; + } } diff --git a/src/engine/net/client/msg/SendSummonsRequestMsg.java b/src/engine/net/client/msg/SendSummonsRequestMsg.java index d5991d56..a634343e 100644 --- a/src/engine/net/client/msg/SendSummonsRequestMsg.java +++ b/src/engine/net/client/msg/SendSummonsRequestMsg.java @@ -17,90 +17,90 @@ import engine.net.client.Protocol; public class SendSummonsRequestMsg extends ClientNetMsg { - private int powerToken; - private int sourceType; - private int sourceID; - private String targetName; - private int trains; - - /** - * This is the general purpose constructor. - */ - public SendSummonsRequestMsg() { - super(Protocol.POWERTARGNAME); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public SendSummonsRequestMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.POWERTARGNAME, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.powerToken); - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.putString(this.targetName); - writer.putInt(this.trains); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.powerToken = reader.getInt(); - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.targetName = reader.getString(); - this.trains = reader.getInt(); - } - - public int getPowerToken() { - return this.powerToken; - } - - public int getSourceType() { - return this.sourceType; - } - - public int getSourceID() { - return this.sourceID; - } - - public String getTargetName() { - return this.targetName; - } - - public int getTrains() { - return this.trains; - } - - public void setPowerToken(int value) { - this.powerToken = value; - } - - public void setSourceType(int value) { - this.sourceType = value; - } - - public void setSourceID(int value) { - this.sourceID = value; - } - - public void setTargetName(String value) { - this.targetName = value; - } - - public void setTrains(int value) { - this.trains = value; - } + private int powerToken; + private int sourceType; + private int sourceID; + private String targetName; + private int trains; + + /** + * This is the general purpose constructor. + */ + public SendSummonsRequestMsg() { + super(Protocol.POWERTARGNAME); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public SendSummonsRequestMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.POWERTARGNAME, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.powerToken); + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.putString(this.targetName); + writer.putInt(this.trains); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.powerToken = reader.getInt(); + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.targetName = reader.getString(); + this.trains = reader.getInt(); + } + + public int getPowerToken() { + return this.powerToken; + } + + public void setPowerToken(int value) { + this.powerToken = value; + } + + public int getSourceType() { + return this.sourceType; + } + + public void setSourceType(int value) { + this.sourceType = value; + } + + public int getSourceID() { + return this.sourceID; + } + + public void setSourceID(int value) { + this.sourceID = value; + } + + public String getTargetName() { + return this.targetName; + } + + public void setTargetName(String value) { + this.targetName = value; + } + + public int getTrains() { + return this.trains; + } + + public void setTrains(int value) { + this.trains = value; + } } diff --git a/src/engine/net/client/msg/ServerInfoMsg.java b/src/engine/net/client/msg/ServerInfoMsg.java index d14a7138..33320c0f 100644 --- a/src/engine/net/client/msg/ServerInfoMsg.java +++ b/src/engine/net/client/msg/ServerInfoMsg.java @@ -23,63 +23,62 @@ import engine.server.world.WorldServer; public class ServerInfoMsg extends ClientNetMsg { - /** - * This is the general purpose constructor. - */ - public ServerInfoMsg() { - super(Protocol.SELECTSERVER); - } + /** + * This is the general purpose constructor. + */ + public ServerInfoMsg() { + super(Protocol.SELECTSERVER); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ServerInfoMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.SELECTSERVER, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ServerInfoMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SELECTSERVER, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - // writer.putInt(this.servers.size()); - // for (WorldServerInfoSnapshot wsis : this.servers) { - // wsis.serializeForClientMsg(writer); - // } - writer.putInt(1); + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + // writer.putInt(this.servers.size()); + // for (WorldServerInfoSnapshot wsis : this.servers) { + // wsis.serializeForClientMsg(writer); + // } + writer.putInt(1); writer.putInt(WorldServer.worldMapID); writer.putString(ConfigManager.MB_WORLD_NAME.getValue()); - if (LoginServer.population < MBServerStatics.LOW_POPULATION) - writer.putInt(0); //Land Rush - else if (LoginServer.population < MBServerStatics.NORMAL_POPULATION) - writer.putInt(1); //Low pop - else if (LoginServer.population < MBServerStatics.HIGH_POPULATION) - writer.putInt(2); //Normal pop - else if (LoginServer.population < MBServerStatics.VERY_OVERPOPULATED_POPULATION) - writer.putInt(3); //High Pop - else if (LoginServer.population < MBServerStatics.FULL_POPULATION) - writer.putInt(4); //Very overpopulated pop - else - writer.putInt(5); //Full pop - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - int size = reader.getInt(); - for (int i = 0; i < size; i++) { - int ID = reader.getInt(); - String name = reader.getString(); - int pop = reader.getInt(); - } - } + if (LoginServer.population < MBServerStatics.LOW_POPULATION) + writer.putInt(0); //Land Rush + else if (LoginServer.population < MBServerStatics.NORMAL_POPULATION) + writer.putInt(1); //Low pop + else if (LoginServer.population < MBServerStatics.HIGH_POPULATION) + writer.putInt(2); //Normal pop + else if (LoginServer.population < MBServerStatics.VERY_OVERPOPULATED_POPULATION) + writer.putInt(3); //High Pop + else if (LoginServer.population < MBServerStatics.FULL_POPULATION) + writer.putInt(4); //Very overpopulated pop + else + writer.putInt(5); //Full pop + } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + int size = reader.getInt(); + for (int i = 0; i < size; i++) { + int ID = reader.getInt(); + String name = reader.getString(); + int pop = reader.getInt(); + } + } } diff --git a/src/engine/net/client/msg/SetCombatModeMsg.java b/src/engine/net/client/msg/SetCombatModeMsg.java index e1ee8e18..7ae0f3f5 100644 --- a/src/engine/net/client/msg/SetCombatModeMsg.java +++ b/src/engine/net/client/msg/SetCombatModeMsg.java @@ -23,75 +23,71 @@ import engine.net.client.Protocol; */ public class SetCombatModeMsg extends ClientNetMsg { - private long playerCompID; - private boolean toggle; + private long playerCompID; + private boolean toggle; - /** - * This is the general purpose constructor. - */ - public SetCombatModeMsg(long playerCompID, boolean toggle) { - super(Protocol.ARCCOMBATMODEATTACKING); - this.playerCompID = playerCompID; - this.toggle = toggle; - } + /** + * This is the general purpose constructor. + */ + public SetCombatModeMsg(long playerCompID, boolean toggle) { + super(Protocol.ARCCOMBATMODEATTACKING); + this.playerCompID = playerCompID; + this.toggle = toggle; + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public SetCombatModeMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.ARCCOMBATMODEATTACKING, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public SetCombatModeMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ARCCOMBATMODEATTACKING, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putLong(playerCompID); - writer.put(toggle ? (byte) 0x01 : (byte) 0x00); - } + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putLong(playerCompID); + writer.put(toggle ? (byte) 0x01 : (byte) 0x00); + } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - this.playerCompID = reader.getLong(); - this.toggle = (reader.get() == 0x01) ? true : false; - } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.playerCompID = reader.getLong(); + this.toggle = (reader.get() == 0x01) ? true : false; + } - /** - * @return the playerCompID - */ - public long getPlayerCompID() { - return playerCompID; - } + /** + * @return the playerCompID + */ + public long getPlayerCompID() { + return playerCompID; + } - /** - * @return the toggle - */ - public boolean getToggle() { - return toggle; - } + /** + * @param playerCompID the playerCompID to set + */ + public void setPlayerCompID(long playerCompID) { + this.playerCompID = playerCompID; + } - /** - * @param playerCompID - * the playerCompID to set - */ - public void setPlayerCompID(long playerCompID) { - this.playerCompID = playerCompID; - } + /** + * @return the toggle + */ + public boolean getToggle() { + return toggle; + } - /** - * @param toggle - * the toggle to set - */ - public void setToggle(boolean toggle) { - this.toggle = toggle; - } + /** + * @param toggle the toggle to set + */ + public void setToggle(boolean toggle) { + this.toggle = toggle; + } } diff --git a/src/engine/net/client/msg/SetObjectValueMsg.java b/src/engine/net/client/msg/SetObjectValueMsg.java index 92bad166..a7ea9e68 100644 --- a/src/engine/net/client/msg/SetObjectValueMsg.java +++ b/src/engine/net/client/msg/SetObjectValueMsg.java @@ -18,81 +18,81 @@ import engine.net.client.Protocol; import engine.objects.AbstractGameObject; public class SetObjectValueMsg extends ClientNetMsg { - private int targetType; - private int targetID; - private int msgType; - private AbstractGameObject ago; - - - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public SetObjectValueMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.SETOBJVAL, origin, reader); - } - - public SetObjectValueMsg() { - super(Protocol.SETOBJVAL); - } - public SetObjectValueMsg(AbstractGameObject ago,int type) { - super(Protocol.SETOBJVAL); - if (ago == null) - return; - this.msgType = type; - this.targetType = ago.getObjectType().ordinal(); - this.targetID = ago.getObjectUUID(); - this.ago = ago; - - } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - writer.putInt(this.targetType); - writer.putInt(this.targetID); - writer.putInt(0); - writer.putInt(0); - writer.putInt(msgType); - writer.putInt(0); - } - - - - public AbstractGameObject getAgo() { - return ago; - } - - public void setAgo(AbstractGameObject ago) { - this.ago = ago; - } - - public int getTargetType() { - return targetType; - } - - public void setTargetType(int targetType) { - this.targetType = targetType; - } - - public int getTargetID() { - return targetID; - } - - public void setTargetID(int targetID) { - this.targetID = targetID; - } + private int targetType; + private int targetID; + private int msgType; + private AbstractGameObject ago; + + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public SetObjectValueMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SETOBJVAL, origin, reader); + } + + public SetObjectValueMsg() { + super(Protocol.SETOBJVAL); + } + + public SetObjectValueMsg(AbstractGameObject ago, int type) { + super(Protocol.SETOBJVAL); + if (ago == null) + return; + this.msgType = type; + this.targetType = ago.getObjectType().ordinal(); + this.targetID = ago.getObjectUUID(); + this.ago = ago; + + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + writer.putInt(this.targetType); + writer.putInt(this.targetID); + writer.putInt(0); + writer.putInt(0); + writer.putInt(msgType); + writer.putInt(0); + } + + + public AbstractGameObject getAgo() { + return ago; + } + + public void setAgo(AbstractGameObject ago) { + this.ago = ago; + } + + public int getTargetType() { + return targetType; + } + + public void setTargetType(int targetType) { + this.targetType = targetType; + } + + public int getTargetID() { + return targetID; + } + + public void setTargetID(int targetID) { + this.targetID = targetID; + } } diff --git a/src/engine/net/client/msg/ShowBankInventoryMsg.java b/src/engine/net/client/msg/ShowBankInventoryMsg.java index dbd25f43..cbf1ee58 100644 --- a/src/engine/net/client/msg/ShowBankInventoryMsg.java +++ b/src/engine/net/client/msg/ShowBankInventoryMsg.java @@ -29,34 +29,44 @@ import java.util.ArrayList; */ public class ShowBankInventoryMsg extends ClientNetMsg { - PlayerCharacter pc; - long unknown01; - - /** - * This is the general purpose constructor. - */ - public ShowBankInventoryMsg(PlayerCharacter pc, long unknown01) { - super(Protocol.BANKINVENTORY); - this.pc = pc; - this.unknown01 = unknown01; - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - - ArrayList bank = pc.getCharItemManager().getBank(); - - writer.put((byte) 1); // static value - Item.putList(writer, bank, false, pc.getObjectUUID()); - writer.putInt(AbstractCharacter.getBankCapacity()); - - // TODO: Gold is sent last and has a slightly different structure. - // Everything is static except the 3 labeled lines - //TODO: f/Eighty: I don't think gold is sent separately. - // will need to check once transfer to bank is working. + PlayerCharacter pc; + long unknown01; + + /** + * This is the general purpose constructor. + */ + public ShowBankInventoryMsg(PlayerCharacter pc, long unknown01) { + super(Protocol.BANKINVENTORY); + this.pc = pc; + this.unknown01 = unknown01; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ShowBankInventoryMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.BANKINVENTORY, origin, reader); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + + ArrayList bank = pc.getCharItemManager().getBank(); + + writer.put((byte) 1); // static value + Item.putList(writer, bank, false, pc.getObjectUUID()); + writer.putInt(AbstractCharacter.getBankCapacity()); + + // TODO: Gold is sent last and has a slightly different structure. + // Everything is static except the 3 labeled lines + //TODO: f/Eighty: I don't think gold is sent separately. + // will need to check once transfer to bank is working. /* 00:00:00:00: 07:00:00:00: @@ -85,31 +95,21 @@ public class ShowBankInventoryMsg extends ClientNetMsg { 58:02:00:00: unknown? */ - writer.putInt(pc.getObjectType().ordinal()); - writer.putInt(pc.getObjectUUID()); - writer.putLong(unknown01); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ShowBankInventoryMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.BANKINVENTORY, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - } - - @Override - protected int getPowerOfTwoBufferSize() { - // Larger size for historically larger opcodes - return 17; // 2^15 == 32,768 - } + writer.putInt(pc.getObjectType().ordinal()); + writer.putInt(pc.getObjectUUID()); + writer.putLong(unknown01); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + } + + @Override + protected int getPowerOfTwoBufferSize() { + // Larger size for historically larger opcodes + return 17; // 2^15 == 32,768 + } } diff --git a/src/engine/net/client/msg/ShowMsg.java b/src/engine/net/client/msg/ShowMsg.java index 24701d53..93686ce8 100644 --- a/src/engine/net/client/msg/ShowMsg.java +++ b/src/engine/net/client/msg/ShowMsg.java @@ -18,123 +18,123 @@ import engine.net.client.Protocol; public class ShowMsg extends ClientNetMsg { - private int targetType; - private int targetID; - private Vector3fImmutable unknown01; - private Vector3fImmutable unknown02; - private float range01; - private Vector3fImmutable unknown03; - private Vector3fImmutable unknown04; - private float range02; - - /** - * This is the general purpose constructor. - */ - public ShowMsg() { - super(Protocol.SHOWCOMBATINFO); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ShowMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.SHOWCOMBATINFO, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.targetType); - writer.putInt(this.targetID); - writer.putVector3f(this.unknown01); - writer.putVector3f(this.unknown02); - writer.putFloat(this.range01); - writer.putVector3f(this.unknown03); - writer.putVector3f(this.unknown04); - writer.putFloat(this.range02); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - this.unknown01 = reader.getVector3fImmutable(); - this.unknown02 = reader.getVector3fImmutable(); - this.range01 = reader.getFloat(); - this.unknown03 = reader.getVector3fImmutable(); - this.unknown04 = reader.getVector3fImmutable(); - this.range02 = reader.getFloat(); - } - - public int getTargetType() { - return this.targetType; - } - - public int getTargetID() { - return this.targetID; - } - - public Vector3fImmutable getUnknown01() { - return this.unknown01; - } - - public Vector3fImmutable getUnknown02() { - return this.unknown02; - } - - public Vector3fImmutable getUnknown03() { - return this.unknown03; - } - - public Vector3fImmutable getUnknown04() { - return this.unknown04; - } - - public float getRange01() { - return this.range01; - } - - public float getRange02() { - return this.range02; - } - - public void setTargetType(int value) { - this.targetType = value; - } - - public void setTargetID(int value) { - this.targetID = value; - } - - public void setUnknown01(Vector3fImmutable value) { - this.unknown01 = value; - } - - public void setUnknown02(Vector3fImmutable value) { - this.unknown02 = value; - } - - public void setUnknown03(Vector3fImmutable value) { - this.unknown03 = value; - } - - public void setUnknown04(Vector3fImmutable value) { - this.unknown04 = value; - } - - public void setRange01(float value) { - this.range01 = value; - } - - public void setRange02(float value) { - this.range02 = value; - } + private int targetType; + private int targetID; + private Vector3fImmutable unknown01; + private Vector3fImmutable unknown02; + private float range01; + private Vector3fImmutable unknown03; + private Vector3fImmutable unknown04; + private float range02; + + /** + * This is the general purpose constructor. + */ + public ShowMsg() { + super(Protocol.SHOWCOMBATINFO); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ShowMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SHOWCOMBATINFO, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.targetType); + writer.putInt(this.targetID); + writer.putVector3f(this.unknown01); + writer.putVector3f(this.unknown02); + writer.putFloat(this.range01); + writer.putVector3f(this.unknown03); + writer.putVector3f(this.unknown04); + writer.putFloat(this.range02); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + this.unknown01 = reader.getVector3fImmutable(); + this.unknown02 = reader.getVector3fImmutable(); + this.range01 = reader.getFloat(); + this.unknown03 = reader.getVector3fImmutable(); + this.unknown04 = reader.getVector3fImmutable(); + this.range02 = reader.getFloat(); + } + + public int getTargetType() { + return this.targetType; + } + + public void setTargetType(int value) { + this.targetType = value; + } + + public int getTargetID() { + return this.targetID; + } + + public void setTargetID(int value) { + this.targetID = value; + } + + public Vector3fImmutable getUnknown01() { + return this.unknown01; + } + + public void setUnknown01(Vector3fImmutable value) { + this.unknown01 = value; + } + + public Vector3fImmutable getUnknown02() { + return this.unknown02; + } + + public void setUnknown02(Vector3fImmutable value) { + this.unknown02 = value; + } + + public Vector3fImmutable getUnknown03() { + return this.unknown03; + } + + public void setUnknown03(Vector3fImmutable value) { + this.unknown03 = value; + } + + public Vector3fImmutable getUnknown04() { + return this.unknown04; + } + + public void setUnknown04(Vector3fImmutable value) { + this.unknown04 = value; + } + + public float getRange01() { + return this.range01; + } + + public void setRange01(float value) { + this.range01 = value; + } + + public float getRange02() { + return this.range02; + } + + public void setRange02(float value) { + this.range02 = value; + } } diff --git a/src/engine/net/client/msg/ShowVaultInventoryMsg.java b/src/engine/net/client/msg/ShowVaultInventoryMsg.java index fc0d1be6..5df29795 100644 --- a/src/engine/net/client/msg/ShowVaultInventoryMsg.java +++ b/src/engine/net/client/msg/ShowVaultInventoryMsg.java @@ -21,66 +21,67 @@ import java.util.ArrayList; /** * Vault inventory contents + * * @author Eighty */ public class ShowVaultInventoryMsg extends ClientNetMsg { - PlayerCharacter pc; - int accountType; - int accountID; - - int npcType; - int npcID; - - - /** - * This is the general purpose constructor. - */ - public ShowVaultInventoryMsg(PlayerCharacter pc, Account account, NPC npc) { - super(Protocol.SHOWVAULTINVENTORY); - this.pc = pc; - this.accountType = account.getObjectType().ordinal(); - this.accountID = account.getObjectUUID(); - this.npcType = npc.getObjectType().ordinal(); - this.npcID = npc.getObjectUUID(); - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - - writer.putInt(accountType); - writer.putInt(accountID); - writer.putInt(npcType); - writer.putInt(npcID); - writer.putString(pc.getFirstName()); - - ArrayList vault = pc.getAccount().getVault(); - - Item.putList(writer, vault, false, pc.getObjectUUID()); - writer.putInt(AbstractCharacter.getVaultCapacity()); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public ShowVaultInventoryMsg(AbstractConnection origin, - ByteBufferReader reader) { - super(Protocol.SHOWVAULTINVENTORY, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - } - - @Override - protected int getPowerOfTwoBufferSize() { - return 17; - } + PlayerCharacter pc; + int accountType; + int accountID; + + int npcType; + int npcID; + + + /** + * This is the general purpose constructor. + */ + public ShowVaultInventoryMsg(PlayerCharacter pc, Account account, NPC npc) { + super(Protocol.SHOWVAULTINVENTORY); + this.pc = pc; + this.accountType = account.getObjectType().ordinal(); + this.accountID = account.getObjectUUID(); + this.npcType = npc.getObjectType().ordinal(); + this.npcID = npc.getObjectUUID(); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public ShowVaultInventoryMsg(AbstractConnection origin, + ByteBufferReader reader) { + super(Protocol.SHOWVAULTINVENTORY, origin, reader); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + + writer.putInt(accountType); + writer.putInt(accountID); + writer.putInt(npcType); + writer.putInt(npcID); + writer.putString(pc.getFirstName()); + + ArrayList vault = pc.getAccount().getVault(); + + Item.putList(writer, vault, false, pc.getObjectUUID()); + writer.putInt(AbstractCharacter.getVaultCapacity()); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + } + + @Override + protected int getPowerOfTwoBufferSize() { + return 17; + } } diff --git a/src/engine/net/client/msg/SocialMsg.java b/src/engine/net/client/msg/SocialMsg.java index fbeba2d3..be748357 100644 --- a/src/engine/net/client/msg/SocialMsg.java +++ b/src/engine/net/client/msg/SocialMsg.java @@ -17,162 +17,155 @@ import engine.net.client.Protocol; public class SocialMsg extends ClientNetMsg { - private int sourceType; - private int sourceID; - private int unknown01; - private int unknown02; - private int targetType; - private int targetID; - private int social; - - /** - * This is the general purpose constructor. - */ - public SocialMsg() { - super(Protocol.SOCIALCHANNEL); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public SocialMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.SOCIALCHANNEL, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - writer.putInt(this.targetType); - writer.putInt(this.targetID); - writer.putInt(this.social); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - this.social = reader.getInt(); - } - - /** - * @return the sourceType - */ - public int getSourceType() { - return sourceType; - } - - /** - * @param sourceType - * the sourceType to set - */ - public void setSourceType(int sourceType) { - this.sourceType = sourceType; - } - - /** - * @return the sourceID - */ - public int getSourceID() { - return sourceID; - } - - /** - * @param sourceID - * the sourceID to set - */ - public void setSourceID(int sourceID) { - this.sourceID = sourceID; - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the unknown02 - */ - public int getUnknown02() { - return unknown02; - } - - /** - * @param unknown02 - * the unknown02 to set - */ - public void setUnknown02(int unknown02) { - this.unknown02 = unknown02; - } - - /** - * @return the targetType - */ - public int getTargetType() { - return targetType; - } - - /** - * @param targetType - * the targetType to set - */ - public void setTargetType(int targetType) { - this.targetType = targetType; - } - - /** - * @return the targetID - */ - public int getTargetID() { - return targetID; - } - - /** - * @param targetID - * the targetID to set - */ - public void setTargetID(int targetID) { - this.targetID = targetID; - } - - /** - * @return the social - */ - public int getSocial() { - return social; - } - - /** - * @param social - * the social to set - */ - public void setSocial(int social) { - this.social = social; - } + private int sourceType; + private int sourceID; + private int unknown01; + private int unknown02; + private int targetType; + private int targetID; + private int social; + + /** + * This is the general purpose constructor. + */ + public SocialMsg() { + super(Protocol.SOCIALCHANNEL); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public SocialMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SOCIALCHANNEL, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + writer.putInt(this.targetType); + writer.putInt(this.targetID); + writer.putInt(this.social); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + this.social = reader.getInt(); + } + + /** + * @return the sourceType + */ + public int getSourceType() { + return sourceType; + } + + /** + * @param sourceType the sourceType to set + */ + public void setSourceType(int sourceType) { + this.sourceType = sourceType; + } + + /** + * @return the sourceID + */ + public int getSourceID() { + return sourceID; + } + + /** + * @param sourceID the sourceID to set + */ + public void setSourceID(int sourceID) { + this.sourceID = sourceID; + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the unknown02 + */ + public int getUnknown02() { + return unknown02; + } + + /** + * @param unknown02 the unknown02 to set + */ + public void setUnknown02(int unknown02) { + this.unknown02 = unknown02; + } + + /** + * @return the targetType + */ + public int getTargetType() { + return targetType; + } + + /** + * @param targetType the targetType to set + */ + public void setTargetType(int targetType) { + this.targetType = targetType; + } + + /** + * @return the targetID + */ + public int getTargetID() { + return targetID; + } + + /** + * @param targetID the targetID to set + */ + public void setTargetID(int targetID) { + this.targetID = targetID; + } + + /** + * @return the social + */ + public int getSocial() { + return social; + } + + /** + * @param social the social to set + */ + public void setSocial(int social) { + this.social = social; + } } diff --git a/src/engine/net/client/msg/StuckCommandMsg.java b/src/engine/net/client/msg/StuckCommandMsg.java index e089221c..2058633e 100644 --- a/src/engine/net/client/msg/StuckCommandMsg.java +++ b/src/engine/net/client/msg/StuckCommandMsg.java @@ -18,35 +18,35 @@ import engine.net.client.Protocol; public class StuckCommandMsg extends ClientNetMsg { - /** - * This is the general purpose constructor. - */ - public StuckCommandMsg() { - super(Protocol.STUCK); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public StuckCommandMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.STUCK, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - } + /** + * This is the general purpose constructor. + */ + public StuckCommandMsg() { + super(Protocol.STUCK); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public StuckCommandMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.STUCK, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + } } diff --git a/src/engine/net/client/msg/SyncMessage.java b/src/engine/net/client/msg/SyncMessage.java index 2d50e353..dfe5a150 100644 --- a/src/engine/net/client/msg/SyncMessage.java +++ b/src/engine/net/client/msg/SyncMessage.java @@ -25,122 +25,127 @@ import org.pmw.tinylog.Logger; import java.util.ArrayList; public class SyncMessage extends ClientNetMsg { - - private int type; - private int size; - private int pad = 0; - private int objectType; - private int objectUUID; - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public SyncMessage(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CITYASSET, origin, reader); - } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - //none yet - } - - public SyncMessage() { - super(Protocol.CITYASSET); - } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - //lets do returns before writing so we don't send improper structures to the client - - Building tol = BuildingManager.getBuilding(this.objectUUID); - - if (tol == null){ - Logger.debug("TOL is null"); - return; - } - Zone zone = ZoneManager.findSmallestZone(tol.getLoc()); - if (zone == null){ - Logger.debug( "Zone is null"); - return; - } - ArrayList allCityAssets = DbManager.BuildingQueries.GET_ALL_BUILDINGS_FOR_ZONE(zone); - - // *** Refactor: collection created but never used? - - ArrayList canProtectAssets = new ArrayList<>(); - - for (Building b: allCityAssets){ - if (b.getBlueprintUUID() != 0) - canProtectAssets.add(b); - } - - // *** Refactor : Not sure what this synch message does - // Get the feeling it should be looping over upgradable - // assets. - writer.putInt(0); - writer.putInt(0); - writer.putInt(this.objectType); - writer.putInt(this.objectUUID); - writer.putInt(allCityAssets.size()); - for (Building b: allCityAssets){ - String name = b.getName(); - // if (name.equals("")) - // name = b.getBuildingSet().getName(); - writer.putInt(b.getObjectType().ordinal()); - writer.putInt(b.getObjectUUID()); - - writer.putString(b.getName()); // Blueprint name? - writer.putString(b.getGuild().getName()); - writer.putInt(20);// \/ Temp \/ - writer.putInt(b.getRank()); - writer.putInt(1); // symbol - writer.putInt(7); //TODO identify these Guild tags?? - writer.putInt(17); - writer.putInt(14); - writer.putInt(14); - writer.putInt(98);// /\ Temp /\ - - } - } - - public int getObjectType() { - return objectType; - } - - public void setObjectType(int value) { - this.objectType = value; - } - - public void setPad(int value) { - this.pad = value; - } - - public int getUUID() { - return objectUUID; - - } - - public int getPad() { - return pad; - } - public int getType() { - return type; - } - public void setType(int type) { - this.type = type; - } - - public int getSize() { - return size; - } - public void setSize(int size) { - this.size = size; - } + + private int type; + private int size; + private int pad = 0; + private int objectType; + private int objectUUID; + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public SyncMessage(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CITYASSET, origin, reader); + } + + public SyncMessage() { + super(Protocol.CITYASSET); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + //none yet + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + //lets do returns before writing so we don't send improper structures to the client + + Building tol = BuildingManager.getBuilding(this.objectUUID); + + if (tol == null) { + Logger.debug("TOL is null"); + return; + } + Zone zone = ZoneManager.findSmallestZone(tol.getLoc()); + if (zone == null) { + Logger.debug("Zone is null"); + return; + } + ArrayList allCityAssets = DbManager.BuildingQueries.GET_ALL_BUILDINGS_FOR_ZONE(zone); + + // *** Refactor: collection created but never used? + + ArrayList canProtectAssets = new ArrayList<>(); + + for (Building b : allCityAssets) { + if (b.getBlueprintUUID() != 0) + canProtectAssets.add(b); + } + + // *** Refactor : Not sure what this synch message does + // Get the feeling it should be looping over upgradable + // assets. + writer.putInt(0); + writer.putInt(0); + writer.putInt(this.objectType); + writer.putInt(this.objectUUID); + writer.putInt(allCityAssets.size()); + for (Building b : allCityAssets) { + String name = b.getName(); + // if (name.equals("")) + // name = b.getBuildingSet().getName(); + writer.putInt(b.getObjectType().ordinal()); + writer.putInt(b.getObjectUUID()); + + writer.putString(b.getName()); // Blueprint name? + writer.putString(b.getGuild().getName()); + writer.putInt(20);// \/ Temp \/ + writer.putInt(b.getRank()); + writer.putInt(1); // symbol + writer.putInt(7); //TODO identify these Guild tags?? + writer.putInt(17); + writer.putInt(14); + writer.putInt(14); + writer.putInt(98);// /\ Temp /\ + + } + } + + public int getObjectType() { + return objectType; + } + + public void setObjectType(int value) { + this.objectType = value; + } + + public int getUUID() { + return objectUUID; + + } + + public int getPad() { + return pad; + } + + public void setPad(int value) { + this.pad = value; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } } diff --git a/src/engine/net/client/msg/TargetObjectMsg.java b/src/engine/net/client/msg/TargetObjectMsg.java index 3c567887..8c823da7 100644 --- a/src/engine/net/client/msg/TargetObjectMsg.java +++ b/src/engine/net/client/msg/TargetObjectMsg.java @@ -17,65 +17,65 @@ import engine.net.client.Protocol; public class TargetObjectMsg extends ClientNetMsg { - private int targetType; - private int targetID; + private int targetType; + private int targetID; - /** - * This is the general purpose constructor. - */ - public TargetObjectMsg(int targetType, int targetID) { - super(Protocol.SETSELECTEDOBECT); - this.targetType = targetType; - this.targetID = targetID; - } + /** + * This is the general purpose constructor. + */ + public TargetObjectMsg(int targetType, int targetID) { + super(Protocol.SETSELECTEDOBECT); + this.targetType = targetType; + this.targetID = targetID; + } - /** - * This is the general purpose constructor. - */ - public TargetObjectMsg() { - super(Protocol.SETSELECTEDOBECT); - } + /** + * This is the general purpose constructor. + */ + public TargetObjectMsg() { + super(Protocol.SETSELECTEDOBECT); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public TargetObjectMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.SETSELECTEDOBECT, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TargetObjectMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SETSELECTEDOBECT, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.targetType); - writer.putInt(this.targetID); - } + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.targetType); + writer.putInt(this.targetID); + } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + } - /** - * @return the targetType - */ - public int getTargetType() { - return targetType; - } + /** + * @return the targetType + */ + public int getTargetType() { + return targetType; + } - /** - * @return the targetID - */ - public int getTargetID() { - return targetID; - } + /** + * @return the targetID + */ + public int getTargetID() { + return targetID; + } } diff --git a/src/engine/net/client/msg/TargetedActionMsg.java b/src/engine/net/client/msg/TargetedActionMsg.java index 5f01002a..7016e4e2 100644 --- a/src/engine/net/client/msg/TargetedActionMsg.java +++ b/src/engine/net/client/msg/TargetedActionMsg.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -32,315 +29,315 @@ import engine.objects.PlayerCharacter; public class TargetedActionMsg extends ClientNetMsg { - public static int un2cnt = 65; - - //attack animations - //64: overhead RH swing 1h RH axe? - //65: overhead LH swing - //66: underhand RH uppercut - //67: shoulder high RH swing - //68: underhand RH swing - //69: sweeping LH swing - //70: overhead circle RH swing - //71: RH across body and back swing - //72: RH 1h overhead to 2h swing - //73: RH overhead to cross body swing (bm?) - //74: 2h low stab to cross body slash - //75: unarmed punch unarmed RH - //76: unarmed RH punch LH punch - //77: unarmed LH jab - //78: unarmed LH jab, RH uppercut - //79: kick - //80: roundhouse kick - //81: dagger RH stab dagger RH - //82: dagger LH stab - //83: dagger slash - //84: dagger hard stab - //85: Polearm/staff overhead swing Polearm, Staff - //86: Polearm/staff side swing - //87: Polearm/staff step into overhead swing - //88: swinging RH stab - //89: swinging LF stab - //90: swinging RH stab (faster) - //91: 1H slash across body and back (sword?) - //92: spear stab spear - //93: spear low stab step into - //94: spear swing leg stab - //95: unarmed overhead swing RH, underhand swing LH - //96: inverted weapon across body followed by roundhouse LH swing - //97: step back followed by overhead roundhouse swing 2H - //98: underhand slash (1h sword) 1H RH Sword - //99: fast LH swing (dagger or sword?) - //100: 1h swing RH (sword) 1h axe? - //101: 1h overhead swing (club or sword) - //102: fast 1h underhand swing (club or sword) - //103: step into RH slash 1h - //104: 1h overhead to cross body slash RH - //105: 2h overhead swing (axe, hammer, sword) 2H Axe, Hammer, Sword - //106: step into 2h swing - //107: step int 2h overhead swing - //108: step into 2h swing - //109: bow draw and fire bow - //110: crossbow draw and fire crossbow - //115: throwing axe/hammer? - //116: overhand throwing dagger? - //117: throwing dagger - - private int sourceType; - private int sourceID; - private int targetType; - private int targetID; - private float locX; - private float locZ; - private int unknown01 = 14; - private int unknown02 = 100; //source animation - private float unknown03 = 1f; - private float sourceStamina = 1f; // attackers stamina after attack - private int unknown05 = 6; //signify passive defense - private int unknown06 = 10; //target animation - private float newHealth = 10f; // health after damage - private float damage = 0f; // damage, 0 for miss - - /** - * This is the general purpose constructor. - */ - public TargetedActionMsg(int sourceType, int sourceID, int targetType, int targetID, float locX, float locZ, float sourceStamina, - float newHealth, float damage) { - super(Protocol.TARGETEDACTION); - this.sourceType = sourceType; - this.sourceID = sourceID; - this.targetType = targetType; - this.targetID = targetID; - this.sourceStamina = sourceStamina; - this.locX = locX; - this.locZ = locZ; - this.newHealth = newHealth; - this.damage = damage; - //this.unknown02 = TargetedActionMsg.un2cnt; - } - - /** - * This is a helper constructor. Designed to send an UPDATE only. Damage for - * this constructor is hard coded to ZERO. - */ - public TargetedActionMsg(PlayerCharacter pc) { - super(Protocol.TARGETEDACTION); - this.sourceType = pc.getObjectType().ordinal(); - this.sourceID = pc.getObjectUUID(); - this.targetType = pc.getObjectType().ordinal(); - this.targetID = pc.getObjectUUID(); - this.sourceStamina = pc.getStamina(); - this.locX = pc.getLoc().x; - this.locZ = pc.getLoc().z; - this.newHealth = pc.getCurrentHitpoints(); - this.damage = 0.0f; - } - - public TargetedActionMsg(PlayerCharacter pc,int unknown06) { - super(Protocol.TARGETEDACTION); - this.sourceType = pc.getObjectType().ordinal(); - this.sourceID = pc.getObjectUUID(); - this.targetType = pc.getObjectType().ordinal(); - this.targetID = pc.getObjectUUID(); - this.sourceStamina = pc.getStamina(); - this.locX = pc.getLoc().x; - this.locZ = pc.getLoc().z; - this.newHealth = pc.getCurrentHitpoints(); - this.damage = 0.0f; - } - - public TargetedActionMsg(AbstractCharacter source, AbstractWorldObject target, Float damage, int swingAnimation) { - super(Protocol.TARGETEDACTION); - if (source != null) { - this.sourceType = source.getObjectType().ordinal(); - this.sourceID = source.getObjectUUID(); - this.sourceStamina = source.getStamina(); - } else { - this.sourceType = 0; - this.sourceID = 0; - this.sourceStamina = 0; - } - if (target != null) { - this.targetType = target.getObjectType().ordinal(); - this.targetID = target.getObjectUUID(); - this.locX = target.getLoc().x; - this.locZ = target.getLoc().z; - this.newHealth = target.getHealth(); - this.damage = damage; - - } else { - this.targetType = 0; - this.targetID = 0; - this.locX = 50000f; - this.locZ = -50000f; - this.newHealth = 1f; - this.damage = damage; - } - this.unknown02 = swingAnimation; - //this.unknown02 = TargetedActionMsg.un2cnt; - } - - public TargetedActionMsg(AbstractCharacter source, AbstractWorldObject target, Float damage, int swingAnimation, int dead) { - super(Protocol.TARGETEDACTION); - if (source != null) { - this.sourceType = source.getObjectType().ordinal(); - this.sourceID = source.getObjectUUID(); - this.sourceStamina = source.getStamina(); - } else { - this.sourceType = 0; - this.sourceID = 0; - this.sourceStamina = 0; - } - if (target != null) { - this.targetType = target.getObjectType().ordinal(); - this.targetID = target.getObjectUUID(); - this.locX = target.getLoc().x; - this.locZ = target.getLoc().z; - this.newHealth = target.getCurrentHitpoints(); - this.damage = damage; - this.unknown06 = dead; - - } else { - this.targetType = 0; - this.targetID = 0; - this.locX = 50000f; - this.locZ = -50000f; - this.newHealth = 1f; - this.damage = damage; - } - this.unknown02 = swingAnimation; - //this.unknown02 = TargetedActionMsg.un2cnt; - } - - /** - * Added in an attempt to have mobs fall over after death. - */ - - public TargetedActionMsg(AbstractWorldObject target, boolean kill) { - this(null, target, 0f, 75); - if (kill){ - this.newHealth = -1f; - this.sourceType = 0x101; - this.sourceID = 0x101; - } - } - - /** - * This constructor can be used to create CombatMessages that indicate a block or parry has occurred.
- *
- * Set passiveAnimation to 21 for block.
- * Set passiveAnimation to 22 for parry.
- */ - public TargetedActionMsg(AbstractCharacter source, int swingAnimation, AbstractWorldObject target, int passiveAnimation) { - this(source, target, 0.0f, swingAnimation); - this.unknown05 = passiveAnimation; - this.unknown06 = 0; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public TargetedActionMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.TARGETEDACTION, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.putInt(this.targetType); - writer.putInt(this.targetID); - writer.putFloat(this.locX); - writer.putFloat(this.locZ); - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - writer.putFloat(this.unknown03); - writer.putFloat(this.sourceStamina); - writer.putInt(this.unknown05); - // writer.putInt(this.unknown06); - - if (this.newHealth < 0) - writer.putInt(55); - else if(damage != 0 && this.unknown05 < 20) - writer.putInt(60); - else - writer.putInt(this.unknown06); - writer.putFloat(this.newHealth); - writer.putFloat(this.damage); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - this.locX = reader.getFloat(); - this.locZ = reader.getFloat(); - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - this.unknown03 = reader.getFloat(); - this.sourceStamina = reader.getFloat(); - this.unknown05 = reader.getInt(); - this.unknown06 = reader.getInt(); - this.newHealth = reader.getFloat(); - this.damage = reader.getFloat(); - } - - /** - * @return the sourceType - */ - public int getSourceType() { - return sourceType; - } - - /** - * @return the sourceID - */ - public int getSourceID() { - return sourceID; - } - - /** - * @return the targetType - */ - public int getTargetType() { - return targetType; - } - - /** - * @return the targetID - */ - public int getTargetID() { - return targetID; - } - - public void setSourceType(int value) { - this.sourceType = value; - } - - public void setSourceID(int value) { - this.sourceID = value; - } - - public void setTargetType(int value) { - this.targetType = value; - } - - public void setTargetID(int value) { - this.targetID = value; - } - - public float getDamage() { - return damage; - } + public static int un2cnt = 65; + + //attack animations + //64: overhead RH swing 1h RH axe? + //65: overhead LH swing + //66: underhand RH uppercut + //67: shoulder high RH swing + //68: underhand RH swing + //69: sweeping LH swing + //70: overhead circle RH swing + //71: RH across body and back swing + //72: RH 1h overhead to 2h swing + //73: RH overhead to cross body swing (bm?) + //74: 2h low stab to cross body slash + //75: unarmed punch unarmed RH + //76: unarmed RH punch LH punch + //77: unarmed LH jab + //78: unarmed LH jab, RH uppercut + //79: kick + //80: roundhouse kick + //81: dagger RH stab dagger RH + //82: dagger LH stab + //83: dagger slash + //84: dagger hard stab + //85: Polearm/staff overhead swing Polearm, Staff + //86: Polearm/staff side swing + //87: Polearm/staff step into overhead swing + //88: swinging RH stab + //89: swinging LF stab + //90: swinging RH stab (faster) + //91: 1H slash across body and back (sword?) + //92: spear stab spear + //93: spear low stab step into + //94: spear swing leg stab + //95: unarmed overhead swing RH, underhand swing LH + //96: inverted weapon across body followed by roundhouse LH swing + //97: step back followed by overhead roundhouse swing 2H + //98: underhand slash (1h sword) 1H RH Sword + //99: fast LH swing (dagger or sword?) + //100: 1h swing RH (sword) 1h axe? + //101: 1h overhead swing (club or sword) + //102: fast 1h underhand swing (club or sword) + //103: step into RH slash 1h + //104: 1h overhead to cross body slash RH + //105: 2h overhead swing (axe, hammer, sword) 2H Axe, Hammer, Sword + //106: step into 2h swing + //107: step int 2h overhead swing + //108: step into 2h swing + //109: bow draw and fire bow + //110: crossbow draw and fire crossbow + //115: throwing axe/hammer? + //116: overhand throwing dagger? + //117: throwing dagger + + private int sourceType; + private int sourceID; + private int targetType; + private int targetID; + private float locX; + private float locZ; + private int unknown01 = 14; + private int unknown02 = 100; //source animation + private float unknown03 = 1f; + private float sourceStamina = 1f; // attackers stamina after attack + private int unknown05 = 6; //signify passive defense + private int unknown06 = 10; //target animation + private float newHealth = 10f; // health after damage + private float damage = 0f; // damage, 0 for miss + + /** + * This is the general purpose constructor. + */ + public TargetedActionMsg(int sourceType, int sourceID, int targetType, int targetID, float locX, float locZ, float sourceStamina, + float newHealth, float damage) { + super(Protocol.TARGETEDACTION); + this.sourceType = sourceType; + this.sourceID = sourceID; + this.targetType = targetType; + this.targetID = targetID; + this.sourceStamina = sourceStamina; + this.locX = locX; + this.locZ = locZ; + this.newHealth = newHealth; + this.damage = damage; + //this.unknown02 = TargetedActionMsg.un2cnt; + } + + /** + * This is a helper constructor. Designed to send an UPDATE only. Damage for + * this constructor is hard coded to ZERO. + */ + public TargetedActionMsg(PlayerCharacter pc) { + super(Protocol.TARGETEDACTION); + this.sourceType = pc.getObjectType().ordinal(); + this.sourceID = pc.getObjectUUID(); + this.targetType = pc.getObjectType().ordinal(); + this.targetID = pc.getObjectUUID(); + this.sourceStamina = pc.getStamina(); + this.locX = pc.getLoc().x; + this.locZ = pc.getLoc().z; + this.newHealth = pc.getCurrentHitpoints(); + this.damage = 0.0f; + } + + public TargetedActionMsg(PlayerCharacter pc, int unknown06) { + super(Protocol.TARGETEDACTION); + this.sourceType = pc.getObjectType().ordinal(); + this.sourceID = pc.getObjectUUID(); + this.targetType = pc.getObjectType().ordinal(); + this.targetID = pc.getObjectUUID(); + this.sourceStamina = pc.getStamina(); + this.locX = pc.getLoc().x; + this.locZ = pc.getLoc().z; + this.newHealth = pc.getCurrentHitpoints(); + this.damage = 0.0f; + } + + public TargetedActionMsg(AbstractCharacter source, AbstractWorldObject target, Float damage, int swingAnimation) { + super(Protocol.TARGETEDACTION); + if (source != null) { + this.sourceType = source.getObjectType().ordinal(); + this.sourceID = source.getObjectUUID(); + this.sourceStamina = source.getStamina(); + } else { + this.sourceType = 0; + this.sourceID = 0; + this.sourceStamina = 0; + } + if (target != null) { + this.targetType = target.getObjectType().ordinal(); + this.targetID = target.getObjectUUID(); + this.locX = target.getLoc().x; + this.locZ = target.getLoc().z; + this.newHealth = target.getHealth(); + this.damage = damage; + + } else { + this.targetType = 0; + this.targetID = 0; + this.locX = 50000f; + this.locZ = -50000f; + this.newHealth = 1f; + this.damage = damage; + } + this.unknown02 = swingAnimation; + //this.unknown02 = TargetedActionMsg.un2cnt; + } + + public TargetedActionMsg(AbstractCharacter source, AbstractWorldObject target, Float damage, int swingAnimation, int dead) { + super(Protocol.TARGETEDACTION); + if (source != null) { + this.sourceType = source.getObjectType().ordinal(); + this.sourceID = source.getObjectUUID(); + this.sourceStamina = source.getStamina(); + } else { + this.sourceType = 0; + this.sourceID = 0; + this.sourceStamina = 0; + } + if (target != null) { + this.targetType = target.getObjectType().ordinal(); + this.targetID = target.getObjectUUID(); + this.locX = target.getLoc().x; + this.locZ = target.getLoc().z; + this.newHealth = target.getCurrentHitpoints(); + this.damage = damage; + this.unknown06 = dead; + + } else { + this.targetType = 0; + this.targetID = 0; + this.locX = 50000f; + this.locZ = -50000f; + this.newHealth = 1f; + this.damage = damage; + } + this.unknown02 = swingAnimation; + //this.unknown02 = TargetedActionMsg.un2cnt; + } + + /** + * Added in an attempt to have mobs fall over after death. + */ + + public TargetedActionMsg(AbstractWorldObject target, boolean kill) { + this(null, target, 0f, 75); + if (kill) { + this.newHealth = -1f; + this.sourceType = 0x101; + this.sourceID = 0x101; + } + } + + /** + * This constructor can be used to create CombatMessages that indicate a block or parry has occurred.
+ *
+ * Set passiveAnimation to 21 for block.
+ * Set passiveAnimation to 22 for parry.
+ */ + public TargetedActionMsg(AbstractCharacter source, int swingAnimation, AbstractWorldObject target, int passiveAnimation) { + this(source, target, 0.0f, swingAnimation); + this.unknown05 = passiveAnimation; + this.unknown06 = 0; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TargetedActionMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.TARGETEDACTION, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.putInt(this.targetType); + writer.putInt(this.targetID); + writer.putFloat(this.locX); + writer.putFloat(this.locZ); + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + writer.putFloat(this.unknown03); + writer.putFloat(this.sourceStamina); + writer.putInt(this.unknown05); + // writer.putInt(this.unknown06); + + if (this.newHealth < 0) + writer.putInt(55); + else if (damage != 0 && this.unknown05 < 20) + writer.putInt(60); + else + writer.putInt(this.unknown06); + writer.putFloat(this.newHealth); + writer.putFloat(this.damage); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + this.locX = reader.getFloat(); + this.locZ = reader.getFloat(); + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + this.unknown03 = reader.getFloat(); + this.sourceStamina = reader.getFloat(); + this.unknown05 = reader.getInt(); + this.unknown06 = reader.getInt(); + this.newHealth = reader.getFloat(); + this.damage = reader.getFloat(); + } + + /** + * @return the sourceType + */ + public int getSourceType() { + return sourceType; + } + + public void setSourceType(int value) { + this.sourceType = value; + } + + /** + * @return the sourceID + */ + public int getSourceID() { + return sourceID; + } + + public void setSourceID(int value) { + this.sourceID = value; + } + + /** + * @return the targetType + */ + public int getTargetType() { + return targetType; + } + + public void setTargetType(int value) { + this.targetType = value; + } + + /** + * @return the targetID + */ + public int getTargetID() { + return targetID; + } + + public void setTargetID(int value) { + this.targetID = value; + } + + public float getDamage() { + return damage; + } } diff --git a/src/engine/net/client/msg/TaxCityMsg.java b/src/engine/net/client/msg/TaxCityMsg.java index 3a7a9859..a00a4041 100644 --- a/src/engine/net/client/msg/TaxCityMsg.java +++ b/src/engine/net/client/msg/TaxCityMsg.java @@ -23,93 +23,92 @@ import engine.objects.GuildTag; public class TaxCityMsg extends ClientNetMsg { - private int buildingID; - private int msgType; + private int buildingID; + private int msgType; - public TaxCityMsg(Building building, int msgType) { - super(Protocol.TAXCITY); - this.buildingID = building.getObjectUUID(); - this.msgType = msgType; + public TaxCityMsg(Building building, int msgType) { + super(Protocol.TAXCITY); + this.buildingID = building.getObjectUUID(); + this.msgType = msgType; - } + } - public TaxCityMsg() { - super(Protocol.TAXCITY); - } + public TaxCityMsg() { + super(Protocol.TAXCITY); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public TaxCityMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.TAXCITY, origin, reader); - } - //CALL THIS AFTER SANITY CHECKS AND BEFORE UPDATING HEALTH/GOLD. + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TaxCityMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.TAXCITY, origin, reader); + } + //CALL THIS AFTER SANITY CHECKS AND BEFORE UPDATING HEALTH/GOLD. - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.msgType = reader.getInt(); - reader.getInt(); //object Type.. always building - this.buildingID = reader.getInt(); - reader.getInt(); - reader.getInt(); + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.msgType = reader.getInt(); + reader.getInt(); //object Type.. always building + this.buildingID = reader.getInt(); + reader.getInt(); + reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); - } + } - // Precache and configure this message before we serialize it + // Precache and configure this message before we serialize it - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { - writer.putInt(0); - writer.putInt(GameObjectType.Building.ordinal()); - writer.putInt(this.buildingID); - Building building = BuildingManager.getBuildingFromCache(this.buildingID); + writer.putInt(0); + writer.putInt(GameObjectType.Building.ordinal()); + writer.putInt(this.buildingID); + Building building = BuildingManager.getBuildingFromCache(this.buildingID); - writer.putInt(0); - writer.putFloat(.2f); - GuildTag._serializeForDisplay(building.getGuild().getGuildTag(),writer); - GuildTag._serializeForDisplay(building.getGuild().getGuildTag(),writer); + writer.putInt(0); + writer.putFloat(.2f); + GuildTag._serializeForDisplay(building.getGuild().getGuildTag(), writer); + GuildTag._serializeForDisplay(building.getGuild().getGuildTag(), writer); + } - } + public int getGuildID() { + return buildingID; + } - public int getGuildID() { - return buildingID; - } + public int getMsgType() { + return msgType; + } - public int getMsgType() { - return msgType; - } - - public void setMsgType(int msgType) { - this.msgType = msgType; - } + public void setMsgType(int msgType) { + this.msgType = msgType; + } } diff --git a/src/engine/net/client/msg/TaxResourcesMsg.java b/src/engine/net/client/msg/TaxResourcesMsg.java index a6a91650..dd8ea199 100644 --- a/src/engine/net/client/msg/TaxResourcesMsg.java +++ b/src/engine/net/client/msg/TaxResourcesMsg.java @@ -23,101 +23,101 @@ import java.util.HashMap; public class TaxResourcesMsg extends ClientNetMsg { - private int buildingID; - private int msgType; - private HashMap resources; - private float taxPercent; - - - public TaxResourcesMsg(Building building, int msgType) { - super(Protocol.TAXRESOURCES); - this.buildingID = building.getObjectUUID(); - this.msgType = msgType; - - } - - public TaxResourcesMsg() { - super(Protocol.TAXRESOURCES); - } - - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public TaxResourcesMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.TAXRESOURCES, origin, reader); - } - //CALL THIS AFTER SANITY CHECKS AND BEFORE UPDATING HEALTH/GOLD. - - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.msgType = reader.getInt(); - reader.getInt(); //object Type.. always building - this.buildingID = reader.getInt(); - HashMap resourcesTemp = new HashMap<>(); - int size = reader.getInt(); - for (int i=0;i getResources() { - return resources; - } - - public float getTaxPercent() { - return taxPercent; - } + private int buildingID; + private int msgType; + private HashMap resources; + private float taxPercent; + + + public TaxResourcesMsg(Building building, int msgType) { + super(Protocol.TAXRESOURCES); + this.buildingID = building.getObjectUUID(); + this.msgType = msgType; + + } + + public TaxResourcesMsg() { + super(Protocol.TAXRESOURCES); + } + + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TaxResourcesMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.TAXRESOURCES, origin, reader); + } + //CALL THIS AFTER SANITY CHECKS AND BEFORE UPDATING HEALTH/GOLD. + + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.msgType = reader.getInt(); + reader.getInt(); //object Type.. always building + this.buildingID = reader.getInt(); + HashMap resourcesTemp = new HashMap<>(); + int size = reader.getInt(); + for (int i = 0; i < size; i++) { + int resourceHash = reader.getInt(); + resourcesTemp.put(resourceHash, 0); + } + this.resources = resourcesTemp; + taxPercent = reader.getFloat(); + reader.getInt(); + + + } + + + // Precache and configure this message before we serialize it + + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + + writer.putInt(0); + writer.putInt(GameObjectType.Building.ordinal()); + writer.putInt(this.buildingID); + writer.putInt(this.resources.size()); + for (int resource : resources.keySet()) + writer.putInt(resource); + writer.putFloat(this.taxPercent); + writer.putInt(this.resources.size()); + for (int resource : resources.keySet()) { + writer.putInt(resource); + writer.putInt(0); + writer.putInt(resources.get(resource)); + } + + } + + public int getBuildingID() { + return buildingID; + } + + public int getMsgType() { + return msgType; + } + + public void setMsgType(int msgType) { + this.msgType = msgType; + } + + public HashMap getResources() { + return resources; + } + + public float getTaxPercent() { + return taxPercent; + } } diff --git a/src/engine/net/client/msg/TeleportRepledgeListMsg.java b/src/engine/net/client/msg/TeleportRepledgeListMsg.java index 2379bdd2..a76f2abf 100644 --- a/src/engine/net/client/msg/TeleportRepledgeListMsg.java +++ b/src/engine/net/client/msg/TeleportRepledgeListMsg.java @@ -23,53 +23,54 @@ import java.util.ArrayList; public class TeleportRepledgeListMsg extends ClientNetMsg { - private PlayerCharacter player; - private boolean isTeleport; ArrayList cities; + private PlayerCharacter player; + private boolean isTeleport; + + /** + * This is the general purpose constructor. + */ + public TeleportRepledgeListMsg(PlayerCharacter player, boolean isTeleport) { + super(Protocol.SENDCITYENTRY); + this.player = player; + this.isTeleport = isTeleport; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TeleportRepledgeListMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SENDCITYENTRY, origin, reader); + } - /** - * This is the general purpose constructor. - */ - public TeleportRepledgeListMsg(PlayerCharacter player, boolean isTeleport) { - super(Protocol.SENDCITYENTRY); - this.player = player; - this.isTeleport = isTeleport; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public TeleportRepledgeListMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.SENDCITYENTRY, origin, reader); - } - - /** - * Copy constructor - */ - public TeleportRepledgeListMsg(TeleportRepledgeListMsg msg) { - super(Protocol.SENDCITYENTRY); + /** + * Copy constructor + */ + public TeleportRepledgeListMsg(TeleportRepledgeListMsg msg) { + super(Protocol.SENDCITYENTRY); this.player = msg.player; this.isTeleport = msg.isTeleport; - } - - /** - * @see AbstractNetMsg#getPowerOfTwoBufferSize() - */ - @Override - protected int getPowerOfTwoBufferSize() { - // Larger size for historically larger opcodes - return (16); - } - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - //Do we even want to try this? - } + } + + /** + * @see AbstractNetMsg#getPowerOfTwoBufferSize() + */ + @Override + protected int getPowerOfTwoBufferSize() { + // Larger size for historically larger opcodes + return (16); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + //Do we even want to try this? + } // Pre-caches and configures message so data is avaiable // when we serialize. @@ -82,31 +83,31 @@ public class TeleportRepledgeListMsg extends ClientNetMsg { cities = City.getCitiesToRepledgeTo(player); } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - if (isTeleport) - writer.putInt(2); //teleport? - else - writer.putInt(1); //repledge? + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + if (isTeleport) + writer.putInt(2); //teleport? + else + writer.putInt(1); //repledge? - for (int i=0;i<3;i++) - writer.putInt(0); + for (int i = 0; i < 3; i++) + writer.putInt(0); - writer.putInt(cities.size()); + writer.putInt(cities.size()); - for (City city : cities) - City.serializeForClientMsg(city,writer); - } + for (City city : cities) + City.serializeForClientMsg(city, writer); + } - public PlayerCharacter getPlayer() { - return this.player; - } + public PlayerCharacter getPlayer() { + return this.player; + } - public boolean isTeleport() { - return this.isTeleport; - } + public boolean isTeleport() { + return this.isTeleport; + } } diff --git a/src/engine/net/client/msg/TeleportToPointMsg.java b/src/engine/net/client/msg/TeleportToPointMsg.java index 23807599..07b4a1fe 100644 --- a/src/engine/net/client/msg/TeleportToPointMsg.java +++ b/src/engine/net/client/msg/TeleportToPointMsg.java @@ -18,204 +18,198 @@ import engine.objects.AbstractWorldObject; public class TeleportToPointMsg extends ClientNetMsg { - private int sourceType; - private int sourceUUID; - private float endLat; - private float endLon; - private float endAlt; - private int targetType; - private int targetUUID; - private int unknown01; - private int unknown02; - - /** - * This is the general purpose constructor. - */ - public TeleportToPointMsg(AbstractWorldObject ago, float endLat, float endAlt, float endLon, long targetID, int unknown01, int unknown02) { - super(Protocol.TELEPORT); - - this.sourceType = ago.getObjectType().ordinal(); - this.sourceUUID = ago.getObjectUUID(); - this.endLat = endLat; - this.endAlt = endAlt; - this.endLon = endLon; - if (targetID != 0){ - this.targetType = GameObjectType.Building.ordinal(); - this.targetUUID = (int) targetID; - } else { - this.targetType = 0; - this.targetUUID = 0; - } - - - this.unknown01 = unknown01; - this.unknown02 = unknown02; - - if (ago.region != null) { - this.targetType = GameObjectType.Building.ordinal(); - this.targetUUID = ago.region.parentBuildingID; - this.unknown01 = ago.region.level; - this.unknown02 = ago.region.room; - } - } - - /** - * This is the general purpose constructor. - */ - public TeleportToPointMsg() { - super(Protocol.TELEPORT); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public TeleportToPointMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.TELEPORT, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.sourceType); - writer.putInt(this.sourceUUID); - writer.putFloat(this.endLat); - writer.putFloat(this.endAlt); - writer.putFloat(this.endLon); - writer.putInt(this.targetType); - writer.putInt(this.targetUUID); - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.sourceType = reader.getInt(); - this.sourceUUID = reader.getInt(); - this.endLat = reader.getInt(); - this.endAlt = reader.getInt(); - this.endLon = reader.getInt(); - this.targetType = reader.getInt(); - this.targetUUID = reader.getInt(); - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - } - - - /** - * @return the endLat - */ - public float getEndLat() { - return endLat; - } - - /** - * @param endLat - * the endLat to set - */ - public void setEndLat(float endLat) { - this.endLat = endLat; - } - - /** - * @return the endLon - */ - public float getEndLon() { - return endLon; - } - - /** - * @param endLon - * the endLon to set - */ - public void setEndLon(float endLon) { - this.endLon = endLon; - } - - /** - * @return the endAlt - */ - public float getEndAlt() { - return endAlt; - } - - /** - * @param endAlt - * the endAlt to set - */ - public void setEndAlt(float endAlt) { - this.endAlt = endAlt; - } - - - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the unknown02 - */ - public int getUnknown02() { - return unknown02; - } - - /** - * @param unknown02 - * the unknown02 to set - */ - public void setUnknown02(int unknown02) { - this.unknown02 = unknown02; - } - - public int getSourceType() { - return sourceType; - } - - public void setSourceType(int sourceType) { - this.sourceType = sourceType; - } - - public int getSourceUUID() { - return sourceUUID; - } - - public void setSourceUUID(int sourceUUID) { - this.sourceUUID = sourceUUID; - } - - public int getTargetType() { - return targetType; - } - - public void setTargetType(int targetType) { - this.targetType = targetType; - } - - public int getTargetUUID() { - return targetUUID; - } - - public void setTargetUUID(int targetUUID) { - this.targetUUID = targetUUID; - } + private int sourceType; + private int sourceUUID; + private float endLat; + private float endLon; + private float endAlt; + private int targetType; + private int targetUUID; + private int unknown01; + private int unknown02; + + /** + * This is the general purpose constructor. + */ + public TeleportToPointMsg(AbstractWorldObject ago, float endLat, float endAlt, float endLon, long targetID, int unknown01, int unknown02) { + super(Protocol.TELEPORT); + + this.sourceType = ago.getObjectType().ordinal(); + this.sourceUUID = ago.getObjectUUID(); + this.endLat = endLat; + this.endAlt = endAlt; + this.endLon = endLon; + if (targetID != 0) { + this.targetType = GameObjectType.Building.ordinal(); + this.targetUUID = (int) targetID; + } else { + this.targetType = 0; + this.targetUUID = 0; + } + + + this.unknown01 = unknown01; + this.unknown02 = unknown02; + + if (ago.region != null) { + this.targetType = GameObjectType.Building.ordinal(); + this.targetUUID = ago.region.parentBuildingID; + this.unknown01 = ago.region.level; + this.unknown02 = ago.region.room; + } + } + + /** + * This is the general purpose constructor. + */ + public TeleportToPointMsg() { + super(Protocol.TELEPORT); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TeleportToPointMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.TELEPORT, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.sourceType); + writer.putInt(this.sourceUUID); + writer.putFloat(this.endLat); + writer.putFloat(this.endAlt); + writer.putFloat(this.endLon); + writer.putInt(this.targetType); + writer.putInt(this.targetUUID); + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.sourceType = reader.getInt(); + this.sourceUUID = reader.getInt(); + this.endLat = reader.getInt(); + this.endAlt = reader.getInt(); + this.endLon = reader.getInt(); + this.targetType = reader.getInt(); + this.targetUUID = reader.getInt(); + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + } + + + /** + * @return the endLat + */ + public float getEndLat() { + return endLat; + } + + /** + * @param endLat the endLat to set + */ + public void setEndLat(float endLat) { + this.endLat = endLat; + } + + /** + * @return the endLon + */ + public float getEndLon() { + return endLon; + } + + /** + * @param endLon the endLon to set + */ + public void setEndLon(float endLon) { + this.endLon = endLon; + } + + /** + * @return the endAlt + */ + public float getEndAlt() { + return endAlt; + } + + /** + * @param endAlt the endAlt to set + */ + public void setEndAlt(float endAlt) { + this.endAlt = endAlt; + } + + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the unknown02 + */ + public int getUnknown02() { + return unknown02; + } + + /** + * @param unknown02 the unknown02 to set + */ + public void setUnknown02(int unknown02) { + this.unknown02 = unknown02; + } + + public int getSourceType() { + return sourceType; + } + + public void setSourceType(int sourceType) { + this.sourceType = sourceType; + } + + public int getSourceUUID() { + return sourceUUID; + } + + public void setSourceUUID(int sourceUUID) { + this.sourceUUID = sourceUUID; + } + + public int getTargetType() { + return targetType; + } + + public void setTargetType(int targetType) { + this.targetType = targetType; + } + + public int getTargetUUID() { + return targetUUID; + } + + public void setTargetUUID(int targetUUID) { + this.targetUUID = targetUUID; + } } diff --git a/src/engine/net/client/msg/TerritoryChangeMessage.java b/src/engine/net/client/msg/TerritoryChangeMessage.java index 57f74369..87e811b0 100644 --- a/src/engine/net/client/msg/TerritoryChangeMessage.java +++ b/src/engine/net/client/msg/TerritoryChangeMessage.java @@ -21,75 +21,72 @@ import engine.objects.Realm; public class TerritoryChangeMessage extends ClientNetMsg { - - private Realm realm; - private PlayerCharacter realmOwner; - - - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public TerritoryChangeMessage(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.TERRITORYCHANGE, origin, reader); - } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - - - } - - public TerritoryChangeMessage() { - super(Protocol.TERRITORYCHANGE); - } - - public TerritoryChangeMessage(PlayerCharacter guildLeader, Realm realm) { - super(Protocol.TERRITORYCHANGE); - - this.realm = realm; - this.realmOwner = guildLeader; - } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - - writer.putString(realm.getRealmName()); - if(this.realmOwner != null){ - writer.putString(this.realmOwner.getCombinedName()); - writer.putInt(PlayerCharacter.GetPlayerRealmTitle(this.realmOwner)); - writer.putInt(1); - writer.put((byte)1); - writer.put((byte)1); - writer.putInt(realm.getCharterType()); - if (this.realmOwner != null && this.realmOwner.getGuild() != null) - writer.putString(this.realmOwner.getGuild().getName()); - else - writer.putString("None"); - writer.put((byte)0); - }else{ - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.put((byte)1); - writer.put((byte)1); - writer.putInt(0); - writer.putInt(0); - writer.put((byte)0); - } - - - - } - - + private Realm realm; + private PlayerCharacter realmOwner; + + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TerritoryChangeMessage(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.TERRITORYCHANGE, origin, reader); + } + + public TerritoryChangeMessage() { + super(Protocol.TERRITORYCHANGE); + } + + public TerritoryChangeMessage(PlayerCharacter guildLeader, Realm realm) { + super(Protocol.TERRITORYCHANGE); + + this.realm = realm; + this.realmOwner = guildLeader; + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + + + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + + writer.putString(realm.getRealmName()); + if (this.realmOwner != null) { + writer.putString(this.realmOwner.getCombinedName()); + writer.putInt(PlayerCharacter.GetPlayerRealmTitle(this.realmOwner)); + writer.putInt(1); + writer.put((byte) 1); + writer.put((byte) 1); + writer.putInt(realm.getCharterType()); + if (this.realmOwner != null && this.realmOwner.getGuild() != null) + writer.putString(this.realmOwner.getGuild().getName()); + else + writer.putString("None"); + writer.put((byte) 0); + } else { + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 1); + writer.put((byte) 1); + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 0); + } + + + } } diff --git a/src/engine/net/client/msg/ToggleCombatMsg.java b/src/engine/net/client/msg/ToggleCombatMsg.java index 56e7de20..613ee1f0 100644 --- a/src/engine/net/client/msg/ToggleCombatMsg.java +++ b/src/engine/net/client/msg/ToggleCombatMsg.java @@ -18,68 +18,68 @@ import engine.net.client.Protocol; public class ToggleCombatMsg extends ClientNetMsg { - private int sourceType; - private int sourceID; - private boolean toggleCombat; - - /** - * This is the general purpose constructor. - */ - public ToggleCombatMsg() { - super(Protocol.COMBATMODE); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ToggleCombatMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.COMBATMODE, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.put(this.toggleCombat ? (byte) 0x01 : (byte) 0x00); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.toggleCombat = (reader.get() == (byte) 0x01) ? true : false; - } - - public int getSourceType() { - return this.sourceType; - } - - public int getSourceID() { - return this.sourceID; - } - - public boolean toggleCombat() { - return this.toggleCombat; - } - - public void setSourceType(int value) { - this.sourceType = value; - } - - public void setSourceID(int value) { - this.sourceID = value; - } - - public void setToggleCombat(boolean value) { - this.toggleCombat = value; - } + private int sourceType; + private int sourceID; + private boolean toggleCombat; + + /** + * This is the general purpose constructor. + */ + public ToggleCombatMsg() { + super(Protocol.COMBATMODE); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ToggleCombatMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.COMBATMODE, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.put(this.toggleCombat ? (byte) 0x01 : (byte) 0x00); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.toggleCombat = (reader.get() == (byte) 0x01) ? true : false; + } + + public int getSourceType() { + return this.sourceType; + } + + public void setSourceType(int value) { + this.sourceType = value; + } + + public int getSourceID() { + return this.sourceID; + } + + public void setSourceID(int value) { + this.sourceID = value; + } + + public boolean toggleCombat() { + return this.toggleCombat; + } + + public void setToggleCombat(boolean value) { + this.toggleCombat = value; + } } diff --git a/src/engine/net/client/msg/ToggleLfgRecruitingMsg.java b/src/engine/net/client/msg/ToggleLfgRecruitingMsg.java index 2dfd611c..8b443240 100644 --- a/src/engine/net/client/msg/ToggleLfgRecruitingMsg.java +++ b/src/engine/net/client/msg/ToggleLfgRecruitingMsg.java @@ -17,80 +17,80 @@ import engine.net.client.Protocol; public class ToggleLfgRecruitingMsg extends ClientNetMsg { - private int sourceType; - private int sourceID; - private byte toggleLfgRecruiting; - private byte unknown01; - - /** - * This is the general purpose constructor. - */ - public ToggleLfgRecruitingMsg() { - super(Protocol.MODIFYGUILDSTATE); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ToggleLfgRecruitingMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.MODIFYGUILDSTATE, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.put(this.toggleLfgRecruiting); - writer.put(this.unknown01); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.toggleLfgRecruiting = reader.get(); - this.unknown01 = reader.get(); - } - - public int getSourceType() { - return this.sourceType; - } - - public int getSourceID() { - return this.sourceID; - } - - public byte toggleLfgRecruiting() { - return this.toggleLfgRecruiting; - } - - public byte getUnknown01() { - return this.unknown01; - } - - public void setSourceType(int value) { - this.sourceType = value; - } - - public void setSourceID(int value) { - this.sourceID = value; - } - - public void setToggleLfgRecruiting(byte value) { - this.toggleLfgRecruiting = value; - } - - public void setUnknown01(byte value) { - this.unknown01 = value; - } + private int sourceType; + private int sourceID; + private byte toggleLfgRecruiting; + private byte unknown01; + + /** + * This is the general purpose constructor. + */ + public ToggleLfgRecruitingMsg() { + super(Protocol.MODIFYGUILDSTATE); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ToggleLfgRecruitingMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.MODIFYGUILDSTATE, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.put(this.toggleLfgRecruiting); + writer.put(this.unknown01); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.toggleLfgRecruiting = reader.get(); + this.unknown01 = reader.get(); + } + + public int getSourceType() { + return this.sourceType; + } + + public void setSourceType(int value) { + this.sourceType = value; + } + + public int getSourceID() { + return this.sourceID; + } + + public void setSourceID(int value) { + this.sourceID = value; + } + + public byte toggleLfgRecruiting() { + return this.toggleLfgRecruiting; + } + + public byte getUnknown01() { + return this.unknown01; + } + + public void setUnknown01(byte value) { + this.unknown01 = value; + } + + public void setToggleLfgRecruiting(byte value) { + this.toggleLfgRecruiting = value; + } } diff --git a/src/engine/net/client/msg/ToggleSitStandMsg.java b/src/engine/net/client/msg/ToggleSitStandMsg.java index 90446503..e7e94898 100644 --- a/src/engine/net/client/msg/ToggleSitStandMsg.java +++ b/src/engine/net/client/msg/ToggleSitStandMsg.java @@ -17,68 +17,68 @@ import engine.net.client.Protocol; public class ToggleSitStandMsg extends ClientNetMsg { - private int sourceType; - private int sourceID; - private boolean toggleSitStand; - - /** - * This is the general purpose constructor. - */ - public ToggleSitStandMsg() { - super(Protocol.TOGGLESITSTAND); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ToggleSitStandMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.TOGGLESITSTAND, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.put(this.toggleSitStand ? (byte) 0x01 : (byte) 0x00); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.toggleSitStand = (reader.get() == (byte) 0x01) ? true : false; - } - - public int getSourceType() { - return this.sourceType; - } - - public int getSourceID() { - return this.sourceID; - } - - public boolean toggleSitStand() { - return this.toggleSitStand; - } - - public void setSourceType(int value) { - this.sourceType = value; - } - - public void setSourceID(int value) { - this.sourceID = value; - } - - public void setToggleSitStand(boolean value) { - this.toggleSitStand = value; - } + private int sourceType; + private int sourceID; + private boolean toggleSitStand; + + /** + * This is the general purpose constructor. + */ + public ToggleSitStandMsg() { + super(Protocol.TOGGLESITSTAND); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ToggleSitStandMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.TOGGLESITSTAND, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.put(this.toggleSitStand ? (byte) 0x01 : (byte) 0x00); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.toggleSitStand = (reader.get() == (byte) 0x01) ? true : false; + } + + public int getSourceType() { + return this.sourceType; + } + + public void setSourceType(int value) { + this.sourceType = value; + } + + public int getSourceID() { + return this.sourceID; + } + + public void setSourceID(int value) { + this.sourceID = value; + } + + public boolean toggleSitStand() { + return this.toggleSitStand; + } + + public void setToggleSitStand(boolean value) { + this.toggleSitStand = value; + } } diff --git a/src/engine/net/client/msg/TrackArrowMsg.java b/src/engine/net/client/msg/TrackArrowMsg.java index 9655be18..b66056de 100644 --- a/src/engine/net/client/msg/TrackArrowMsg.java +++ b/src/engine/net/client/msg/TrackArrowMsg.java @@ -18,44 +18,44 @@ import engine.net.client.Protocol; public class TrackArrowMsg extends ClientNetMsg { - protected float direction; - - public TrackArrowMsg(float direction) { - super(Protocol.ARCTRACKOBJECT); - this.direction = direction; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public TrackArrowMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ARCTRACKOBJECT, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putFloat(this.direction); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.direction = reader.getFloat(); - } - - public float getDirection() { - return this.direction; - } - - public void setDirection(float value) { - this.direction = value; - } + protected float direction; + + public TrackArrowMsg(float direction) { + super(Protocol.ARCTRACKOBJECT); + this.direction = direction; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TrackArrowMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ARCTRACKOBJECT, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putFloat(this.direction); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.direction = reader.getFloat(); + } + + public float getDirection() { + return this.direction; + } + + public void setDirection(float value) { + this.direction = value; + } } diff --git a/src/engine/net/client/msg/TrackWindowMsg.java b/src/engine/net/client/msg/TrackWindowMsg.java index 1241320b..7b647ee9 100644 --- a/src/engine/net/client/msg/TrackWindowMsg.java +++ b/src/engine/net/client/msg/TrackWindowMsg.java @@ -22,127 +22,128 @@ import java.util.HashSet; public class TrackWindowMsg extends ClientNetMsg { - private int powerToken; - private PlayerCharacter source = null; - private HashSet characters = new HashSet<>(); - - /** - * This is the general purpose constructor. - */ - public TrackWindowMsg(int powerToken, HashSet characters) { - super(Protocol.ARCTRACKINGLIST); - this.powerToken = powerToken; - this.characters = characters; - } - - public TrackWindowMsg(TrackWindowMsg trackWindowMsg) { - super(Protocol.ARCTRACKINGLIST); - this.powerToken = trackWindowMsg.powerToken; - this.source = trackWindowMsg.source; - this.characters = trackWindowMsg.characters; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public TrackWindowMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ARCTRACKINGLIST, origin, reader); - } - - /** - * @see AbstractNetMsg#getPowerOfTwoBufferSize() - */ - @Override - protected int getPowerOfTwoBufferSize() { - // Larger size for historically larger opcodes - return (13); - } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.powerToken); - writer.putInt(characters.size()); - for (AbstractCharacter ac : characters) { - boolean isGroup = false; - if (this.source != null && ac.getObjectType().equals(GameObjectType.PlayerCharacter)) { - if (Group.sameGroup((PlayerCharacter)ac, this.source)) - isGroup = true; - } - AbstractCharacter.serializeForTrack(ac,writer, isGroup); - } - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.powerToken = reader.getInt(); - - int size = reader.getInt(); - for (int i=0;i getCharacters() { - return this.characters; - } - - public void setPowerToken(int value) { - this.powerToken = value; - } - - public void setCharacters(HashSet value) { - this.characters = value; - } - - public void addCharacter(PlayerCharacter value) { - if (value != null) - this.characters.add(value); - } - - public void clearChracters() { - this.characters.clear(); - } - - public void setSource(PlayerCharacter value) { - this.source = value; - } + private int powerToken; + private PlayerCharacter source = null; + private HashSet characters = new HashSet<>(); + + /** + * This is the general purpose constructor. + */ + public TrackWindowMsg(int powerToken, HashSet characters) { + super(Protocol.ARCTRACKINGLIST); + this.powerToken = powerToken; + this.characters = characters; + } + + public TrackWindowMsg(TrackWindowMsg trackWindowMsg) { + super(Protocol.ARCTRACKINGLIST); + this.powerToken = trackWindowMsg.powerToken; + this.source = trackWindowMsg.source; + this.characters = trackWindowMsg.characters; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TrackWindowMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ARCTRACKINGLIST, origin, reader); + } + + /** + * @see AbstractNetMsg#getPowerOfTwoBufferSize() + */ + @Override + protected int getPowerOfTwoBufferSize() { + // Larger size for historically larger opcodes + return (13); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.powerToken); + writer.putInt(characters.size()); + for (AbstractCharacter ac : characters) { + boolean isGroup = false; + if (this.source != null && ac.getObjectType().equals(GameObjectType.PlayerCharacter)) { + if (Group.sameGroup((PlayerCharacter) ac, this.source)) + isGroup = true; + } + AbstractCharacter.serializeForTrack(ac, writer, isGroup); + } + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.powerToken = reader.getInt(); + + int size = reader.getInt(); + for (int i = 0; i < size; i++) { + int objectType = reader.getInt(); + int objectID = reader.getInt(); + this.source = PlayerCharacter.getFromCache(objectID); + reader.getString(); //name + reader.get(); //always 00? + reader.getInt(); //guildObjectType + reader.getInt(); //guildID + reader.get(); //always 01? + for (int j = 0; j < 5; j++) + reader.getInt(); //guild tags + reader.getInt(); //nation ObjectType + reader.getInt(); //nation ID + reader.get(); //always 01? + for (int j = 0; j < 5; j++) + reader.getInt(); //nation tags + + //Get the Character from it's Object Type and ID + AbstractCharacter ac = null; + if (objectType == GameObjectType.PlayerCharacter.ordinal()) + ac = PlayerCharacter.getFromCache(objectID); + else if (objectType == GameObjectType.NPC.ordinal()) + ac = NPC.getFromCache(objectID); + else if (objectType == GameObjectType.Mob.ordinal()) + ac = Mob.getFromCache(objectID); + + //If found, add to message list + if (ac != null) + characters.add(ac); + } + } + + public int getPowerToken() { + return this.powerToken; + } + + public void setPowerToken(int value) { + this.powerToken = value; + } + + public HashSet getCharacters() { + return this.characters; + } + + public void setCharacters(HashSet value) { + this.characters = value; + } + + public void addCharacter(PlayerCharacter value) { + if (value != null) + this.characters.add(value); + } + + public void clearChracters() { + this.characters.clear(); + } + + public void setSource(PlayerCharacter value) { + this.source = value; + } } diff --git a/src/engine/net/client/msg/TradeRequestMsg.java b/src/engine/net/client/msg/TradeRequestMsg.java index 25e64ab4..bf9ace62 100644 --- a/src/engine/net/client/msg/TradeRequestMsg.java +++ b/src/engine/net/client/msg/TradeRequestMsg.java @@ -24,107 +24,105 @@ import engine.objects.AbstractGameObject; */ public class TradeRequestMsg extends ClientNetMsg { - private int unknown01; //pad? - private int playerType; - private int playerID; - private int sourceType; - private int sourceID; - - - /** - * This is the general purpose constructor - */ - public TradeRequestMsg(int unknown01, AbstractGameObject player, AbstractGameObject target) { - super(Protocol.REQUESTTOTRADE); - this.unknown01 = unknown01; - this.sourceType = player.getObjectType().ordinal(); - this.sourceID = player.getObjectUUID(); - this.playerType = target.getObjectType().ordinal(); - this.playerID = target.getObjectUUID(); - - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public TradeRequestMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.REQUESTTOTRADE, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - unknown01 = reader.getInt(); - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.playerType = reader.getInt(); - this.playerID = reader.getInt(); - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - writer.putInt(unknown01); - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.putInt(this.playerType); - writer.putInt(this.playerID); - - - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - - public int getPlayerType() { - return playerType; - } - - public void setPlayerType(int playerType) { - this.playerType = playerType; - } - - public int getPlayerID() { - return playerID; - } - - public void setPlayerID(int playerID) { - this.playerID = playerID; - } - - public int getSourceType() { - return sourceType; - } - - public void setSourceType(int sourceType) { - this.sourceType = sourceType; - } - - public int getSourceID() { - return sourceID; - } - - public void setSourceID(int sourceID) { - this.sourceID = sourceID; - } + private int unknown01; //pad? + private int playerType; + private int playerID; + private int sourceType; + private int sourceID; + + + /** + * This is the general purpose constructor + */ + public TradeRequestMsg(int unknown01, AbstractGameObject player, AbstractGameObject target) { + super(Protocol.REQUESTTOTRADE); + this.unknown01 = unknown01; + this.sourceType = player.getObjectType().ordinal(); + this.sourceID = player.getObjectUUID(); + this.playerType = target.getObjectType().ordinal(); + this.playerID = target.getObjectUUID(); + + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public TradeRequestMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.REQUESTTOTRADE, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + unknown01 = reader.getInt(); + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.playerType = reader.getInt(); + this.playerID = reader.getInt(); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putInt(unknown01); + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.putInt(this.playerType); + writer.putInt(this.playerID); + + + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + + public int getPlayerType() { + return playerType; + } + + public void setPlayerType(int playerType) { + this.playerType = playerType; + } + + public int getPlayerID() { + return playerID; + } + + public void setPlayerID(int playerID) { + this.playerID = playerID; + } + + public int getSourceType() { + return sourceType; + } + + public void setSourceType(int sourceType) { + this.sourceType = sourceType; + } + + public int getSourceID() { + return sourceID; + } + + public void setSourceID(int sourceID) { + this.sourceID = sourceID; + } } diff --git a/src/engine/net/client/msg/TrainMsg.java b/src/engine/net/client/msg/TrainMsg.java index 8f048aa8..cb778dcf 100644 --- a/src/engine/net/client/msg/TrainMsg.java +++ b/src/engine/net/client/msg/TrainMsg.java @@ -29,333 +29,327 @@ import java.util.concurrent.ConcurrentHashMap; public class TrainMsg extends ClientNetMsg { - private int npcType; - private int npcID; - private int unknown01 = 1; - private int trainCost01; //why two trainer costs? - private int trainCost02; //why two trainer costs? - private boolean isSkill; //true: skill; false: power - private int token; - private boolean unknown02 = true; - private String ok = ""; - private int unknown03 = 0; - - /** - * This is the general purpose constructor. - */ - public TrainMsg() { - super(Protocol.TRAINSKILL); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public TrainMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.TRAINSKILL, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.npcType); - writer.putInt(this.npcID); - writer.putInt(this.unknown01); - writer.putInt(trainCost01); - writer.putInt(trainCost02); - writer.put((this.isSkill == true) ? (byte)0x01 : (byte)0x00); - writer.putInt(this.token); - writer.put((this.unknown02 == true) ? (byte)0x01 : (byte)0x00); - writer.putString(this.ok); - writer.putInt(this.unknown03); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.npcType = reader.getInt(); - this.npcID = reader.getInt(); - this.unknown01 = reader.getInt(); - this.trainCost01 = reader.getInt(); - this.trainCost02 = reader.getInt(); - this.isSkill = (reader.get() == (byte)0x01) ? true : false; - this.token = reader.getInt(); - this.unknown02 = (reader.get() == (byte)0x01) ? true : false; - this.ok = reader.getString(); - this.unknown03 = reader.getInt(); - } - - public int getToken() { - return this.token; - } - - public boolean isSkill() { - return this.isSkill; - } - - public int getNpcType() { - return this.npcType; - } - - public int getNpcID() { - return this.npcID; - } - - public static void train(TrainMsg msg, ClientConnection origin) throws MsgSendException { - origin.getPlayerCharacter().recalculate(); - PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter(origin); - Dispatch dispatch; - - if (playerCharacter == null) - return; + private int npcType; + private int npcID; + private int unknown01 = 1; + private int trainCost01; //why two trainer costs? + private int trainCost02; //why two trainer costs? + private boolean isSkill; //true: skill; false: power + private int token; + private boolean unknown02 = true; + private String ok = ""; + private int unknown03 = 0; + + /** + * This is the general purpose constructor. + */ + public TrainMsg() { + super(Protocol.TRAINSKILL); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TrainMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.TRAINSKILL, origin, reader); + } + + public static void train(TrainMsg msg, ClientConnection origin) throws MsgSendException { + origin.getPlayerCharacter().recalculate(); + PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter(origin); + Dispatch dispatch; + + if (playerCharacter == null) + return; NPC npc = NPC.getFromCache(msg.npcID); - if (npc == null) - return; + if (npc == null) + return; - if (origin.trainLock.tryLock()){ - try{ - Item gold = playerCharacter.getCharItemManager().getGoldInventory(); + if (origin.trainLock.tryLock()) { + try { + Item gold = playerCharacter.getCharItemManager().getGoldInventory(); - if (gold == null) - return; + if (gold == null) + return; - if (!gold.validForInventory(origin, playerCharacter, playerCharacter.getCharItemManager())) - return; + if (!gold.validForInventory(origin, playerCharacter, playerCharacter.getCharItemManager())) + return; - boolean canTrain = false; + boolean canTrain = false; if (msg.isSkill) { - //Get skill + //Get skill SkillsBase sb = DbManager.SkillsBaseQueries.GET_BASE_BY_TOKEN(msg.token); - ConcurrentHashMap skills = playerCharacter.getSkills(); - - if (sb == null || skills == null) - return; - - CharacterSkill sk = skills.get(sb.getName()); - - if (sk == null) - return; - - if (sk.getSkillsBase().getToken() == 40661438){ - int maxValue = 15; - - - if (MaxSkills.MaxSkillsSet.get(252647) != null) - for (MaxSkills maxSkills: MaxSkills.MaxSkillsSet.get(252647)){ - if (maxSkills.getSkillToken() != sk.getToken()) - continue; - - if (maxSkills.getSkillLevel() > npc.getLevel()) - continue; - maxValue += maxSkills.getMaxSkillPercent(); - } - if (maxValue> sk.getModifiedAmountBeforeMods()){ - canTrain = true; - } - - } - if (canTrain == false) - if (npc.getContract() != null && npc.getContract().getExtraRune() != 0){ - int maxValue = 15; - - - if (MaxSkills.MaxSkillsSet.get(npc.getContract().getExtraRune()) != null) - for (MaxSkills maxSkills: MaxSkills.MaxSkillsSet.get(npc.getContract().getExtraRune())){ - if (maxSkills.getSkillToken() != sk.getToken()) - continue; - - if (maxSkills.getSkillLevel() > npc.getLevel()) - continue; - maxValue += maxSkills.getMaxSkillPercent(); - } - if (maxValue > sk.getModifiedAmountBeforeMods()){ - canTrain = true; - } - - - } - if (canTrain == false){ - int maxValue = 15; - if (MaxSkills.MaxSkillsSet.get(npc.getContractID()) != null) - for (MaxSkills maxSkills: MaxSkills.MaxSkillsSet.get(npc.getContractID())){ - if (maxSkills.getSkillToken() != sk.getToken()) - continue; - - if (maxSkills.getSkillLevel() > npc.getLevel()) - continue; - maxValue += maxSkills.getMaxSkillPercent(); - } - if (maxValue > sk.getModifiedAmountBeforeMods()){ - canTrain = true; - } - } - - if (canTrain == false){ - int maxValue = 15; - if (MaxSkills.MaxSkillsSet.get(npc.getContract().getClassID()) != null) - for (MaxSkills maxSkills: MaxSkills.MaxSkillsSet.get(npc.getContract().getClassID())){ - if (maxSkills.getSkillToken() != sk.getToken()) - continue; - - if (maxSkills.getSkillLevel() > npc.getLevel()) - continue; - maxValue += maxSkills.getMaxSkillPercent(); - } - if (maxValue > sk.getModifiedAmountBeforeMods()){ - canTrain = true; - } - } - - if (canTrain == false){ - int maxValue = 15; - if (MaxSkills.MaxSkillsSet.get(npc.extraRune2) != null) - for (MaxSkills maxSkills: MaxSkills.MaxSkillsSet.get(npc.getContract().getClassID())){ - if (maxSkills.getSkillToken() != sk.getToken()) - continue; - - if (maxSkills.getSkillLevel() > npc.getLevel()) - continue; - maxValue += maxSkills.getMaxSkillPercent(); - } - if (maxValue > sk.getModifiedAmountBeforeMods()){ - canTrain = true; - } - } - - if (canTrain == false){ - ChatManager.chatSystemError(playerCharacter, "NPC cannot train that skill any higher"); - return; - } - - float cost = sk.getTrainingCost(playerCharacter, npc); - float profitCost = cost * npc.getSellPercent(playerCharacter); - - profitCost += .5f; - if (profitCost > playerCharacter.getCharItemManager().getGoldInventory().getNumOfItems()) - return; - Building b = npc.getBuilding(); - if (b != null && b.getProtectionState().equals(ProtectionState.NPC)) - b = null; - - if (b != null && b.getStrongboxValue() + (profitCost - cost) > b.getMaxGold()){ - ErrorPopupMsg.sendErrorPopup(playerCharacter, 206); - return; - } - - if (playerCharacter.getCharItemManager().getGoldInventory().getNumOfItems() - profitCost < 0) - return; - - if (playerCharacter.getCharItemManager().getGoldInventory().getNumOfItems() - profitCost > MBServerStatics.PLAYER_GOLD_LIMIT) - return; - - - //attempt to train - if (sk.train(playerCharacter)) { - playerCharacter.getCharItemManager().buyFromNPC(b, (int)profitCost, (int)(profitCost - cost)); - - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - //update trainer window - - if (npc != null) { + ConcurrentHashMap skills = playerCharacter.getSkills(); + + if (sb == null || skills == null) + return; + + CharacterSkill sk = skills.get(sb.getName()); + + if (sk == null) + return; + + if (sk.getSkillsBase().getToken() == 40661438) { + int maxValue = 15; + + + if (MaxSkills.MaxSkillsSet.get(252647) != null) + for (MaxSkills maxSkills : MaxSkills.MaxSkillsSet.get(252647)) { + if (maxSkills.getSkillToken() != sk.getToken()) + continue; + + if (maxSkills.getSkillLevel() > npc.getLevel()) + continue; + maxValue += maxSkills.getMaxSkillPercent(); + } + if (maxValue > sk.getModifiedAmountBeforeMods()) { + canTrain = true; + } + + } + if (canTrain == false) + if (npc.getContract() != null && npc.getContract().getExtraRune() != 0) { + int maxValue = 15; + + + if (MaxSkills.MaxSkillsSet.get(npc.getContract().getExtraRune()) != null) + for (MaxSkills maxSkills : MaxSkills.MaxSkillsSet.get(npc.getContract().getExtraRune())) { + if (maxSkills.getSkillToken() != sk.getToken()) + continue; + + if (maxSkills.getSkillLevel() > npc.getLevel()) + continue; + maxValue += maxSkills.getMaxSkillPercent(); + } + if (maxValue > sk.getModifiedAmountBeforeMods()) { + canTrain = true; + } + + + } + if (canTrain == false) { + int maxValue = 15; + if (MaxSkills.MaxSkillsSet.get(npc.getContractID()) != null) + for (MaxSkills maxSkills : MaxSkills.MaxSkillsSet.get(npc.getContractID())) { + if (maxSkills.getSkillToken() != sk.getToken()) + continue; + + if (maxSkills.getSkillLevel() > npc.getLevel()) + continue; + maxValue += maxSkills.getMaxSkillPercent(); + } + if (maxValue > sk.getModifiedAmountBeforeMods()) { + canTrain = true; + } + } + + if (canTrain == false) { + int maxValue = 15; + if (MaxSkills.MaxSkillsSet.get(npc.getContract().getClassID()) != null) + for (MaxSkills maxSkills : MaxSkills.MaxSkillsSet.get(npc.getContract().getClassID())) { + if (maxSkills.getSkillToken() != sk.getToken()) + continue; + + if (maxSkills.getSkillLevel() > npc.getLevel()) + continue; + maxValue += maxSkills.getMaxSkillPercent(); + } + if (maxValue > sk.getModifiedAmountBeforeMods()) { + canTrain = true; + } + } + + if (canTrain == false) { + int maxValue = 15; + if (MaxSkills.MaxSkillsSet.get(npc.extraRune2) != null) + for (MaxSkills maxSkills : MaxSkills.MaxSkillsSet.get(npc.getContract().getClassID())) { + if (maxSkills.getSkillToken() != sk.getToken()) + continue; + + if (maxSkills.getSkillLevel() > npc.getLevel()) + continue; + maxValue += maxSkills.getMaxSkillPercent(); + } + if (maxValue > sk.getModifiedAmountBeforeMods()) { + canTrain = true; + } + } + + if (canTrain == false) { + ChatManager.chatSystemError(playerCharacter, "NPC cannot train that skill any higher"); + return; + } + + float cost = sk.getTrainingCost(playerCharacter, npc); + float profitCost = cost * npc.getSellPercent(playerCharacter); + + profitCost += .5f; + if (profitCost > playerCharacter.getCharItemManager().getGoldInventory().getNumOfItems()) + return; + Building b = npc.getBuilding(); + if (b != null && b.getProtectionState().equals(ProtectionState.NPC)) + b = null; + + if (b != null && b.getStrongboxValue() + (profitCost - cost) > b.getMaxGold()) { + ErrorPopupMsg.sendErrorPopup(playerCharacter, 206); + return; + } + + if (playerCharacter.getCharItemManager().getGoldInventory().getNumOfItems() - profitCost < 0) + return; + + if (playerCharacter.getCharItemManager().getGoldInventory().getNumOfItems() - profitCost > MBServerStatics.PLAYER_GOLD_LIMIT) + return; + + + //attempt to train + if (sk.train(playerCharacter)) { + playerCharacter.getCharItemManager().buyFromNPC(b, (int) profitCost, (int) (profitCost - cost)); + + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + //update trainer window + + if (npc != null) { TrainerInfoMsg tim = new TrainerInfoMsg(msg.npcType, msg.npcID, npc.getSellPercent(playerCharacter)); - tim.setTrainPercent(npc.getSellPercent(playerCharacter)); - dispatch = Dispatch.borrow(playerCharacter, tim); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } - } - - } else { - //Get Power + tim.setTrainPercent(npc.getSellPercent(playerCharacter)); + dispatch = Dispatch.borrow(playerCharacter, tim); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } + } + + } else { + //Get Power int token = msg.token; - if (MBServerStatics.POWERS_DEBUG) { + if (MBServerStatics.POWERS_DEBUG) { ChatManager.chatSayInfo(playerCharacter, "Training Power: " + - Integer.toHexString(msg.token) + " (" + msg.token + ')'); + Integer.toHexString(msg.token) + " (" + msg.token + ')'); System.out.println("Training Power: " + - Integer.toHexString(msg.token) + " (" + msg.token + ')'); - } - - PowersBase pb = PowersManager.getPowerByToken(token); - ConcurrentHashMap powers = playerCharacter.getPowers(); - if (pb == null || powers == null) - return; - - if (pb.isWeaponPower) - return; - CharacterPower cp = null; - if (powers.containsKey(token)) - cp = powers.get(token); - if (cp == null) - return; - - //attempt to train - float cost = (int) cp.getTrainingCost(playerCharacter, npc); - float profitCost = cost * npc.getSellPercent(playerCharacter); - profitCost += .5f; - if (profitCost > playerCharacter.getCharItemManager().getGoldInventory().getNumOfItems()){ - // ChatManager.chatSystemError(pc, "You do not have enough gold to train this skill."); - return; - } - - Building b = npc.getBuilding(); - - if (b != null && b.getProtectionState().equals(ProtectionState.NPC)) - b = null; - - if (b != null && b.getStrongboxValue() + (profitCost - cost) > b.getMaxGold()){ - ErrorPopupMsg.sendErrorPopup(playerCharacter, 206); - return; - } - if (cp.train(playerCharacter)) { - - if (!playerCharacter.getCharItemManager().buyFromNPC(b, (int)profitCost, (int)(profitCost - cost))) - ChatManager.chatSystemError(playerCharacter, "Failed to Withdrawl gold from inventory. Contact CCR"); - - //train succeeded - - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - //update trainer window - - if (npc != null) { - TrainerInfoMsg tim = new TrainerInfoMsg(msg.npcType, msg.npcID, npc.getSellPercent(playerCharacter)); - tim.setTrainPercent(npc.getSellPercent(playerCharacter)); - dispatch = Dispatch.borrow(playerCharacter, tim); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } - } - } - }catch(Exception e){ - Logger.error(e); - }finally{ - origin.trainLock.unlock(); - } + Integer.toHexString(msg.token) + " (" + msg.token + ')'); + } + PowersBase pb = PowersManager.getPowerByToken(token); + ConcurrentHashMap powers = playerCharacter.getPowers(); + if (pb == null || powers == null) + return; - } + if (pb.isWeaponPower) + return; + CharacterPower cp = null; + if (powers.containsKey(token)) + cp = powers.get(token); + if (cp == null) + return; + //attempt to train + float cost = (int) cp.getTrainingCost(playerCharacter, npc); + float profitCost = cost * npc.getSellPercent(playerCharacter); + profitCost += .5f; + if (profitCost > playerCharacter.getCharItemManager().getGoldInventory().getNumOfItems()) { + // ChatManager.chatSystemError(pc, "You do not have enough gold to train this skill."); + return; + } + Building b = npc.getBuilding(); + if (b != null && b.getProtectionState().equals(ProtectionState.NPC)) + b = null; + if (b != null && b.getStrongboxValue() + (profitCost - cost) > b.getMaxGold()) { + ErrorPopupMsg.sendErrorPopup(playerCharacter, 206); + return; + } + if (cp.train(playerCharacter)) { + if (!playerCharacter.getCharItemManager().buyFromNPC(b, (int) profitCost, (int) (profitCost - cost))) + ChatManager.chatSystemError(playerCharacter, "Failed to Withdrawl gold from inventory. Contact CCR"); + //train succeeded + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } + //update trainer window - public static float getTrainPercent(NPC npc) { - return 0f; - } + if (npc != null) { + TrainerInfoMsg tim = new TrainerInfoMsg(msg.npcType, msg.npcID, npc.getSellPercent(playerCharacter)); + tim.setTrainPercent(npc.getSellPercent(playerCharacter)); + dispatch = Dispatch.borrow(playerCharacter, tim); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } + } + } + } catch (Exception e) { + Logger.error(e); + } finally { + origin.trainLock.unlock(); + } + + + } + + + } + + public static float getTrainPercent(NPC npc) { + return 0f; + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.npcType); + writer.putInt(this.npcID); + writer.putInt(this.unknown01); + writer.putInt(trainCost01); + writer.putInt(trainCost02); + writer.put((this.isSkill == true) ? (byte) 0x01 : (byte) 0x00); + writer.putInt(this.token); + writer.put((this.unknown02 == true) ? (byte) 0x01 : (byte) 0x00); + writer.putString(this.ok); + writer.putInt(this.unknown03); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.npcType = reader.getInt(); + this.npcID = reader.getInt(); + this.unknown01 = reader.getInt(); + this.trainCost01 = reader.getInt(); + this.trainCost02 = reader.getInt(); + this.isSkill = (reader.get() == (byte) 0x01) ? true : false; + this.token = reader.getInt(); + this.unknown02 = (reader.get() == (byte) 0x01) ? true : false; + this.ok = reader.getString(); + this.unknown03 = reader.getInt(); + } + + public int getToken() { + return this.token; + } + + public boolean isSkill() { + return this.isSkill; + } + + public int getNpcType() { + return this.npcType; + } + + public int getNpcID() { + return this.npcID; + } } diff --git a/src/engine/net/client/msg/TrainerInfoMsg.java b/src/engine/net/client/msg/TrainerInfoMsg.java index f44712dd..ea8c5630 100644 --- a/src/engine/net/client/msg/TrainerInfoMsg.java +++ b/src/engine/net/client/msg/TrainerInfoMsg.java @@ -17,85 +17,85 @@ import engine.net.client.Protocol; public class TrainerInfoMsg extends ClientNetMsg { - private int objectType; - private int objectID; - private float trainPercent; - - /** - * This is the general purpose constructor. - */ - public TrainerInfoMsg(int objectType, int objectID, float trainPercent) { - super(Protocol.TRAINERLIST); - this.objectType = objectType; - this.objectID = objectID; - this.trainPercent = trainPercent; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public TrainerInfoMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.TRAINERLIST, origin, reader); - } - - /** - * Copy constructor - */ - public TrainerInfoMsg(TrainerInfoMsg msg) { - super(Protocol.TRAINERLIST); - this.objectType = msg.objectType; - this.objectID = msg.objectID; - this.trainPercent = msg.trainPercent; - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - reader.get(); - this.objectType = reader.getInt(); - this.objectID = reader.getInt(); - this.trainPercent = reader.getFloat(); - reader.getInt(); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.put((byte)0); - writer.putInt(this.objectType); - writer.putInt(this.objectID); - writer.putFloat(this.trainPercent); - writer.putInt(0); - } - - public int getObjectType() { - return this.objectType; - } - - public int getObjectID() { - return this.objectID; - } - - public float getTrainPercent() { - return this.trainPercent; - } - - public void setObjectType(int value) { - this.objectType = value; - } - - public void setObjectID(int value) { - this.objectID = value; - } - - public void setTrainPercent(float value) { - this.trainPercent = value; - } + private int objectType; + private int objectID; + private float trainPercent; + + /** + * This is the general purpose constructor. + */ + public TrainerInfoMsg(int objectType, int objectID, float trainPercent) { + super(Protocol.TRAINERLIST); + this.objectType = objectType; + this.objectID = objectID; + this.trainPercent = trainPercent; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TrainerInfoMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.TRAINERLIST, origin, reader); + } + + /** + * Copy constructor + */ + public TrainerInfoMsg(TrainerInfoMsg msg) { + super(Protocol.TRAINERLIST); + this.objectType = msg.objectType; + this.objectID = msg.objectID; + this.trainPercent = msg.trainPercent; + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.get(); + this.objectType = reader.getInt(); + this.objectID = reader.getInt(); + this.trainPercent = reader.getFloat(); + reader.getInt(); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.put((byte) 0); + writer.putInt(this.objectType); + writer.putInt(this.objectID); + writer.putFloat(this.trainPercent); + writer.putInt(0); + } + + public int getObjectType() { + return this.objectType; + } + + public void setObjectType(int value) { + this.objectType = value; + } + + public int getObjectID() { + return this.objectID; + } + + public void setObjectID(int value) { + this.objectID = value; + } + + public float getTrainPercent() { + return this.trainPercent; + } + + public void setTrainPercent(float value) { + this.trainPercent = value; + } } diff --git a/src/engine/net/client/msg/TransferAssetMsg.java b/src/engine/net/client/msg/TransferAssetMsg.java index 0f354801..1ea61d0a 100644 --- a/src/engine/net/client/msg/TransferAssetMsg.java +++ b/src/engine/net/client/msg/TransferAssetMsg.java @@ -17,83 +17,89 @@ import engine.net.ByteBufferWriter; import engine.net.client.Protocol; public class TransferAssetMsg extends ClientNetMsg { - - private int objectType; - private int objectID; - private int targetType; - private int targetID; - private int pad = 0; - -/** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ -public TransferAssetMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.TRANSFERASSET, origin, reader); -} -/** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ -@Override -protected void _deserialize(ByteBufferReader reader) { - this.pad = reader.getInt(); - this.objectType = reader.getInt(); - this.objectID = reader.getInt(); - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - reader.getShort(); -} - -/** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ -@Override -protected void _serialize(ByteBufferWriter writer) throws SerializationException { - writer.putInt(this.pad); - writer.putInt(this.objectType); - writer.putInt(this.objectID); - writer.putInt(this.targetType); - writer.putInt(this.targetID); - writer.putShort((short)0); - -} - -public int getObjectType() { - return objectType; -} - -public void setObjectType(int value) { -this.objectType = value; -} - -public void setPad(int value) { -this.pad = value; -} - -public int getPad() { -return pad; -} - -public int getTargetType() { - return targetType; -} -public void setTargetObject(int targetObject) { - this.targetType = targetObject; -} -public int getTargetID() { - return targetID; -} -public void setTargetID(int targetID) { - this.targetID = targetID; -} -public int getObjectID() { - return objectID; -} -public void setObjectID(int objectID) { - this.objectID = objectID; -} + + private int objectType; + private int objectID; + private int targetType; + private int targetID; + private int pad = 0; + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TransferAssetMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.TRANSFERASSET, origin, reader); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.pad = reader.getInt(); + this.objectType = reader.getInt(); + this.objectID = reader.getInt(); + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + reader.getShort(); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + writer.putInt(this.pad); + writer.putInt(this.objectType); + writer.putInt(this.objectID); + writer.putInt(this.targetType); + writer.putInt(this.targetID); + writer.putShort((short) 0); + + } + + public int getObjectType() { + return objectType; + } + + public void setObjectType(int value) { + this.objectType = value; + } + + public int getPad() { + return pad; + } + + public void setPad(int value) { + this.pad = value; + } + + public int getTargetType() { + return targetType; + } + + public void setTargetObject(int targetObject) { + this.targetType = targetObject; + } + + public int getTargetID() { + return targetID; + } + + public void setTargetID(int targetID) { + this.targetID = targetID; + } + + public int getObjectID() { + return objectID; + } + + public void setObjectID(int objectID) { + this.objectID = objectID; + } } \ No newline at end of file diff --git a/src/engine/net/client/msg/TransferBuildingMsg.java b/src/engine/net/client/msg/TransferBuildingMsg.java index 63a7f408..7a04c25c 100644 --- a/src/engine/net/client/msg/TransferBuildingMsg.java +++ b/src/engine/net/client/msg/TransferBuildingMsg.java @@ -17,81 +17,87 @@ import engine.net.ByteBufferWriter; import engine.net.client.Protocol; public class TransferBuildingMsg extends ClientNetMsg { - - private int objectType; - private int objectID; - private int targetType; - private int targetID; - private int pad = 0; - -/** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ -public TransferBuildingMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.TRANSFERASSET, origin, reader); -} -/** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ -@Override -protected void _deserialize(ByteBufferReader reader) { - this.pad = reader.getInt(); - this.objectType = reader.getInt(); - this.objectID = reader.getInt(); - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); -} - -/** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ -@Override -protected void _serialize(ByteBufferWriter writer) throws SerializationException { - writer.putInt(this.pad); - writer.putInt(this.objectType); - writer.putInt(this.objectID); - writer.putInt(this.targetType); - writer.putInt(this.targetID); - -} - -public int getObjectType() { - return objectType; -} - -public void setObjectType(int value) { -this.objectType = value; -} - -public void setPad(int value) { -this.pad = value; -} - -public int getPad() { -return pad; -} - -public int getTargetType() { - return targetType; -} -public void setTargetObject(int targetObject) { - this.targetType = targetObject; -} -public int getTargetID() { - return targetID; -} -public void setTargetID(int targetID) { - this.targetID = targetID; -} -public int getObjectID() { - return objectID; -} -public void setObjectID(int objectID) { - this.objectID = objectID; -} + + private int objectType; + private int objectID; + private int targetType; + private int targetID; + private int pad = 0; + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TransferBuildingMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.TRANSFERASSET, origin, reader); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.pad = reader.getInt(); + this.objectType = reader.getInt(); + this.objectID = reader.getInt(); + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + writer.putInt(this.pad); + writer.putInt(this.objectType); + writer.putInt(this.objectID); + writer.putInt(this.targetType); + writer.putInt(this.targetID); + + } + + public int getObjectType() { + return objectType; + } + + public void setObjectType(int value) { + this.objectType = value; + } + + public int getPad() { + return pad; + } + + public void setPad(int value) { + this.pad = value; + } + + public int getTargetType() { + return targetType; + } + + public void setTargetObject(int targetObject) { + this.targetType = targetObject; + } + + public int getTargetID() { + return targetID; + } + + public void setTargetID(int targetID) { + this.targetID = targetID; + } + + public int getObjectID() { + return objectID; + } + + public void setObjectID(int objectID) { + this.objectID = objectID; + } } \ No newline at end of file diff --git a/src/engine/net/client/msg/TransferGoldFromInventoryToVaultMsg.java b/src/engine/net/client/msg/TransferGoldFromInventoryToVaultMsg.java index de31e72e..459bc61a 100644 --- a/src/engine/net/client/msg/TransferGoldFromInventoryToVaultMsg.java +++ b/src/engine/net/client/msg/TransferGoldFromInventoryToVaultMsg.java @@ -24,82 +24,81 @@ import engine.net.client.Protocol; public class TransferGoldFromInventoryToVaultMsg extends ClientNetMsg { - private int playerID; - private int accountID; - private int npcID; - - private int amount; - - /** - * This is the general purpose constructor - */ - public TransferGoldFromInventoryToVaultMsg() { - super(Protocol.GOLDTOVAULT); - - } - public TransferGoldFromInventoryToVaultMsg(int playerID, int npcID, int accountID, int amount) { - super(Protocol.GOLDTOVAULT); - this.playerID = playerID; - this.npcID = npcID; - this.accountID = accountID; - this.amount = amount; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public TransferGoldFromInventoryToVaultMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.GOLDTOVAULT, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - reader.getInt(); - this.playerID = reader.getInt(); - reader.getInt(); - this.accountID = reader.getInt(); - reader.getInt(); - this.npcID = reader.getInt(); - this.amount = reader.getInt(); - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - writer.putInt(GameObjectType.PlayerCharacter.ordinal()); - writer.putInt(this.playerID); - writer.putInt(GameObjectType.Account.ordinal()); - writer.putInt(this.accountID); - writer.putInt(GameObjectType.NPC.ordinal()); - writer.putInt(this.npcID); - - writer.putInt(this.amount); - } + private int playerID; + private int accountID; + private int npcID; + private int amount; /** - * @return the amount - */ - public int getAmount() { - return amount; - } - - /** - * @param amount the amount to set - */ - public void setAmount(int amount) { - this.amount = amount; - } + * This is the general purpose constructor + */ + public TransferGoldFromInventoryToVaultMsg() { + super(Protocol.GOLDTOVAULT); + + } + + public TransferGoldFromInventoryToVaultMsg(int playerID, int npcID, int accountID, int amount) { + super(Protocol.GOLDTOVAULT); + this.playerID = playerID; + this.npcID = npcID; + this.accountID = accountID; + this.amount = amount; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TransferGoldFromInventoryToVaultMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.GOLDTOVAULT, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.getInt(); + this.playerID = reader.getInt(); + reader.getInt(); + this.accountID = reader.getInt(); + reader.getInt(); + this.npcID = reader.getInt(); + this.amount = reader.getInt(); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putInt(GameObjectType.PlayerCharacter.ordinal()); + writer.putInt(this.playerID); + writer.putInt(GameObjectType.Account.ordinal()); + writer.putInt(this.accountID); + writer.putInt(GameObjectType.NPC.ordinal()); + writer.putInt(this.npcID); + + writer.putInt(this.amount); + } + + + /** + * @return the amount + */ + public int getAmount() { + return amount; + } + + /** + * @param amount the amount to set + */ + public void setAmount(int amount) { + this.amount = amount; + } } diff --git a/src/engine/net/client/msg/TransferGoldFromVaultToInventoryMsg.java b/src/engine/net/client/msg/TransferGoldFromVaultToInventoryMsg.java index 580b8769..b76b68f6 100644 --- a/src/engine/net/client/msg/TransferGoldFromVaultToInventoryMsg.java +++ b/src/engine/net/client/msg/TransferGoldFromVaultToInventoryMsg.java @@ -23,110 +23,108 @@ import engine.net.client.Protocol; */ public class TransferGoldFromVaultToInventoryMsg extends ClientNetMsg { - private long unknown01; - private long playerCompID; - private long accountCompID; - private int amount; - - /** - * This is the general purpose constructor - */ - public TransferGoldFromVaultToInventoryMsg(long unknown01, long playerCompID, long accountCompID, int amount) { - super(Protocol.TRANSFERGOLDFROMVAULTTOINVENTORY); - this.unknown01 = unknown01; - this.playerCompID = playerCompID; - this.accountCompID = accountCompID; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public TransferGoldFromVaultToInventoryMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.TRANSFERGOLDFROMVAULTTOINVENTORY, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - unknown01 = reader.getLong(); - playerCompID = reader.getLong(); - accountCompID = reader.getLong(); - amount = reader.getInt(); - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - writer.putLong(unknown01); - writer.putLong(playerCompID); - writer.putLong(accountCompID); - writer.putInt(amount); - } - - /** - * @return the unknown01 - */ - public long getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 the unknown01 to set - */ - public void setUnknown01(long unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the playerCompID - */ - public long getPlayerCompID() { - return playerCompID; - } - - /** - * @param playerCompID the playerCompID to set - */ - public void setPlayerCompID(long playerCompID) { - this.playerCompID = playerCompID; - } - - /** - * @return the unknown02 - */ - public long getAccountCompID() { - return accountCompID; - } - - /** - * @param unknown02 the unknown02 to set - */ - public void setAccountCompID(long accountCompID) { - this.accountCompID = accountCompID; - } - - /** - * @return the amount - */ - public int getAmount() { - return amount; - } - - /** - * @param amount the amount to set - */ - public void setAmount(int amount) { - this.amount = amount; - } + private long unknown01; + private long playerCompID; + private long accountCompID; + private int amount; + + /** + * This is the general purpose constructor + */ + public TransferGoldFromVaultToInventoryMsg(long unknown01, long playerCompID, long accountCompID, int amount) { + super(Protocol.TRANSFERGOLDFROMVAULTTOINVENTORY); + this.unknown01 = unknown01; + this.playerCompID = playerCompID; + this.accountCompID = accountCompID; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TransferGoldFromVaultToInventoryMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.TRANSFERGOLDFROMVAULTTOINVENTORY, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + unknown01 = reader.getLong(); + playerCompID = reader.getLong(); + accountCompID = reader.getLong(); + amount = reader.getInt(); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putLong(unknown01); + writer.putLong(playerCompID); + writer.putLong(accountCompID); + writer.putInt(amount); + } + + /** + * @return the unknown01 + */ + public long getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(long unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the playerCompID + */ + public long getPlayerCompID() { + return playerCompID; + } + + /** + * @param playerCompID the playerCompID to set + */ + public void setPlayerCompID(long playerCompID) { + this.playerCompID = playerCompID; + } + + /** + * @return the unknown02 + */ + public long getAccountCompID() { + return accountCompID; + } + + /** + * @param unknown02 the unknown02 to set + */ + public void setAccountCompID(long accountCompID) { + this.accountCompID = accountCompID; + } + + /** + * @return the amount + */ + public int getAmount() { + return amount; + } + + /** + * @param amount the amount to set + */ + public void setAmount(int amount) { + this.amount = amount; + } } diff --git a/src/engine/net/client/msg/TransferGoldToFromBuildingMsg.java b/src/engine/net/client/msg/TransferGoldToFromBuildingMsg.java index 488c8627..60011884 100644 --- a/src/engine/net/client/msg/TransferGoldToFromBuildingMsg.java +++ b/src/engine/net/client/msg/TransferGoldToFromBuildingMsg.java @@ -25,125 +25,121 @@ import engine.net.client.Protocol; public class TransferGoldToFromBuildingMsg extends ClientNetMsg { - private int direction; //Maybe? 1 and 2 - private int failReason; - private int objectType; - private int objectID; - private int amount; - private int unknown01; - private int unknown02; - - /** - * This is the general purpose constructor - */ - public TransferGoldToFromBuildingMsg() { - super(Protocol.TRANSFERGOLDTOFROMBUILDING); - this.direction = 0; - this.failReason = 0; - this.objectType = 0; - this.objectID = 0; - this.amount = 0; - this.unknown01 = 0; - this.unknown02 = 0; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public TransferGoldToFromBuildingMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.TRANSFERGOLDTOFROMBUILDING, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - this.direction = reader.getInt(); - this.failReason = reader.getInt(); - this.objectType = reader.getInt(); - this.objectID = reader.getInt(); - this.amount = reader.getInt(); - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - writer.putInt(this.direction); - writer.putInt(this.failReason); - writer.putInt(this.objectType); - writer.putInt(this.objectID); - writer.putInt(this.amount); - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - - } - - public int getDirection() { - return this.direction; - } - - public int getAmount() { - return this.amount; - } - - public int getUnknown01() { - return this.unknown01; - } - - public int getUnknown02() { - return this.unknown02; - } - - public void setDirection(int value) { - this.direction = value; - } - - - public void setAmount(int value) { - this.amount = value; - } - - public void setUnknown01(int value) { - this.unknown01 = value; - } - - public void setUnknown02(int value) { - this.unknown02 = value; - } - - public void setFailReason(int failReason) { - this.failReason = failReason; - } - - public int getFailReason() { - return failReason; - } - - - public int getObjectType() { - return objectType; - } - - public void setObjectType(int objectType) { - this.objectType = objectType; - } - - public int getObjectID() { - return objectID; - } - - public void setObjectID(int objectID) { - this.objectID = objectID; - } + private int direction; //Maybe? 1 and 2 + private int failReason; + private int objectType; + private int objectID; + private int amount; + private int unknown01; + private int unknown02; + + /** + * This is the general purpose constructor + */ + public TransferGoldToFromBuildingMsg() { + super(Protocol.TRANSFERGOLDTOFROMBUILDING); + this.direction = 0; + this.failReason = 0; + this.objectType = 0; + this.objectID = 0; + this.amount = 0; + this.unknown01 = 0; + this.unknown02 = 0; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TransferGoldToFromBuildingMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.TRANSFERGOLDTOFROMBUILDING, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.direction = reader.getInt(); + this.failReason = reader.getInt(); + this.objectType = reader.getInt(); + this.objectID = reader.getInt(); + this.amount = reader.getInt(); + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putInt(this.direction); + writer.putInt(this.failReason); + writer.putInt(this.objectType); + writer.putInt(this.objectID); + writer.putInt(this.amount); + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + + } + + public int getDirection() { + return this.direction; + } + + public void setDirection(int value) { + this.direction = value; + } + + public int getAmount() { + return this.amount; + } + + public void setAmount(int value) { + this.amount = value; + } + + public int getUnknown01() { + return this.unknown01; + } + + public void setUnknown01(int value) { + this.unknown01 = value; + } + + public int getUnknown02() { + return this.unknown02; + } + + public void setUnknown02(int value) { + this.unknown02 = value; + } + + public int getFailReason() { + return failReason; + } + + public void setFailReason(int failReason) { + this.failReason = failReason; + } + + public int getObjectType() { + return objectType; + } + + public void setObjectType(int objectType) { + this.objectType = objectType; + } + + public int getObjectID() { + return objectID; + } + + public void setObjectID(int objectID) { + this.objectID = objectID; + } } diff --git a/src/engine/net/client/msg/TransferItemFromBankToInventoryMsg.java b/src/engine/net/client/msg/TransferItemFromBankToInventoryMsg.java index b68c7df4..cd29a156 100644 --- a/src/engine/net/client/msg/TransferItemFromBankToInventoryMsg.java +++ b/src/engine/net/client/msg/TransferItemFromBankToInventoryMsg.java @@ -24,197 +24,196 @@ import engine.net.client.Protocol; public class TransferItemFromBankToInventoryMsg extends ClientNetMsg { - private long playerCompID1; - private long playerCompID2; - private int type; - private int objectUUID; - private int unknown1; - private int unknown2; - private int numItems; - private byte unknown4; - - /** - * This is the general purpose constructor - */ - public TransferItemFromBankToInventoryMsg(long playerCompID1, - long playerCompID2, int type, int objectUUID, int unknown1, - int unknown2, int numItems, byte unknown4) { - super(Protocol.TRANSFERITEMFROMBANK); - this.playerCompID1 = playerCompID1; - this.playerCompID2 = playerCompID2; - this.type = type; - this.objectUUID = objectUUID; - this.unknown1 = unknown1; - this.unknown2 = unknown2; - this.numItems = numItems; - this.unknown4 = unknown4; - } - - public TransferItemFromBankToInventoryMsg(TransferItemFromInventoryToBankMsg msg) { - super(Protocol.TRANSFERITEMFROMBANK); - this.playerCompID1 = msg.getPlayerCompID1(); - this.playerCompID2 = msg.getPlayerCompID2(); - this.type = msg.getType(); - this.objectUUID = msg.getUUID(); - this.unknown1 = msg.getUnknown1(); - this.unknown2 = msg.getUnknown2(); - this.numItems = msg.getNumItems(); - this.unknown4 = msg.getUnknown4(); - } - - /** - * This is the general purpose constructor - */ - public TransferItemFromBankToInventoryMsg() { - super(Protocol.TRANSFERITEMFROMBANK); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public TransferItemFromBankToInventoryMsg(AbstractConnection origin, - ByteBufferReader reader) { - super(Protocol.TRANSFERITEMFROMBANK, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - playerCompID1 = reader.getLong(); - playerCompID2 = reader.getLong(); - type = reader.getInt(); - objectUUID = reader.getInt(); - unknown1 = reader.getInt(); - unknown2 = reader.getInt(); - numItems = reader.getInt(); - unknown4 = reader.get(); - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - writer.putLong(playerCompID1); - writer.putLong(playerCompID2); - writer.putInt(type); - writer.putInt(objectUUID); - writer.putInt(unknown1); - writer.putInt(unknown2); - writer.putInt(numItems); - writer.put(unknown4); - } - - /** - * @return the playerCompID1 - */ - public long getPlayerCompID1() { - return playerCompID1; - } - - /** - * @param playerCompID1 the playerCompID1 to set - */ - public void setPlayerCompID1(long playerCompID1) { - this.playerCompID1 = playerCompID1; - } - - /** - * @return the playerCompID2 - */ - public long getPlayerCompID2() { - return playerCompID2; - } - - /** - * @param playerCompID2 the playerCompID2 to set - */ - public void setPlayerCompID2(long playerCompID2) { - this.playerCompID2 = playerCompID2; - } - - /** - * @return the type - */ - public int getType() { - return type; - } - - /** - * @param type the type to set - */ - public void setType(int type) { - this.type = type; - } - - /** - * @return the objectUUID - */ - public int getUUID() { - return objectUUID; - } - - /** - * @return the unknown1 - */ - public int getUnknown1() { - return unknown1; - } - - /** - * @param unknown1 the unknown1 to set - */ - public void setUnknown1(int unknown1) { - this.unknown1 = unknown1; - } - - /** - * @return the unknown2 - */ - public int getUnknown2() { - return unknown2; - } - - /** - * @param unknown2 the unknown2 to set - */ - public void setUnknown2(int unknown2) { - this.unknown2 = unknown2; - } - - /** - * @return the numItems - */ - public int getNumItems() { - return numItems; - } - - /** - * @param numItems the numItems to set - */ - public void setNumItems(int numItems) { - this.numItems = numItems; - } - - /** - * @return the unknown4 - */ - public byte getUnknown4() { - return unknown4; - } - - /** - * @param unknown4 the unknown4 to set - */ - public void setUnknown4(byte unknown4) { - this.unknown4 = unknown4; - } + private long playerCompID1; + private long playerCompID2; + private int type; + private int objectUUID; + private int unknown1; + private int unknown2; + private int numItems; + private byte unknown4; + + /** + * This is the general purpose constructor + */ + public TransferItemFromBankToInventoryMsg(long playerCompID1, + long playerCompID2, int type, int objectUUID, int unknown1, + int unknown2, int numItems, byte unknown4) { + super(Protocol.TRANSFERITEMFROMBANK); + this.playerCompID1 = playerCompID1; + this.playerCompID2 = playerCompID2; + this.type = type; + this.objectUUID = objectUUID; + this.unknown1 = unknown1; + this.unknown2 = unknown2; + this.numItems = numItems; + this.unknown4 = unknown4; + } + + public TransferItemFromBankToInventoryMsg(TransferItemFromInventoryToBankMsg msg) { + super(Protocol.TRANSFERITEMFROMBANK); + this.playerCompID1 = msg.getPlayerCompID1(); + this.playerCompID2 = msg.getPlayerCompID2(); + this.type = msg.getType(); + this.objectUUID = msg.getUUID(); + this.unknown1 = msg.getUnknown1(); + this.unknown2 = msg.getUnknown2(); + this.numItems = msg.getNumItems(); + this.unknown4 = msg.getUnknown4(); + } + + /** + * This is the general purpose constructor + */ + public TransferItemFromBankToInventoryMsg() { + super(Protocol.TRANSFERITEMFROMBANK); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TransferItemFromBankToInventoryMsg(AbstractConnection origin, + ByteBufferReader reader) { + super(Protocol.TRANSFERITEMFROMBANK, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + playerCompID1 = reader.getLong(); + playerCompID2 = reader.getLong(); + type = reader.getInt(); + objectUUID = reader.getInt(); + unknown1 = reader.getInt(); + unknown2 = reader.getInt(); + numItems = reader.getInt(); + unknown4 = reader.get(); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putLong(playerCompID1); + writer.putLong(playerCompID2); + writer.putInt(type); + writer.putInt(objectUUID); + writer.putInt(unknown1); + writer.putInt(unknown2); + writer.putInt(numItems); + writer.put(unknown4); + } + + /** + * @return the playerCompID1 + */ + public long getPlayerCompID1() { + return playerCompID1; + } + + /** + * @param playerCompID1 the playerCompID1 to set + */ + public void setPlayerCompID1(long playerCompID1) { + this.playerCompID1 = playerCompID1; + } + + /** + * @return the playerCompID2 + */ + public long getPlayerCompID2() { + return playerCompID2; + } + + /** + * @param playerCompID2 the playerCompID2 to set + */ + public void setPlayerCompID2(long playerCompID2) { + this.playerCompID2 = playerCompID2; + } + + /** + * @return the type + */ + public int getType() { + return type; + } + + /** + * @param type the type to set + */ + public void setType(int type) { + this.type = type; + } + + /** + * @return the objectUUID + */ + public int getUUID() { + return objectUUID; + } + + /** + * @return the unknown1 + */ + public int getUnknown1() { + return unknown1; + } + + /** + * @param unknown1 the unknown1 to set + */ + public void setUnknown1(int unknown1) { + this.unknown1 = unknown1; + } + + /** + * @return the unknown2 + */ + public int getUnknown2() { + return unknown2; + } + + /** + * @param unknown2 the unknown2 to set + */ + public void setUnknown2(int unknown2) { + this.unknown2 = unknown2; + } + + /** + * @return the numItems + */ + public int getNumItems() { + return numItems; + } + + /** + * @param numItems the numItems to set + */ + public void setNumItems(int numItems) { + this.numItems = numItems; + } + + /** + * @return the unknown4 + */ + public byte getUnknown4() { + return unknown4; + } + + /** + * @param unknown4 the unknown4 to set + */ + public void setUnknown4(byte unknown4) { + this.unknown4 = unknown4; + } } diff --git a/src/engine/net/client/msg/TransferItemFromEquipToInventoryMsg.java b/src/engine/net/client/msg/TransferItemFromEquipToInventoryMsg.java index 7aef05b3..2dd59b54 100644 --- a/src/engine/net/client/msg/TransferItemFromEquipToInventoryMsg.java +++ b/src/engine/net/client/msg/TransferItemFromEquipToInventoryMsg.java @@ -19,73 +19,72 @@ import engine.objects.AbstractGameObject; public class TransferItemFromEquipToInventoryMsg extends ClientNetMsg { - private int playerType; - private int playerUUID; - private int slotNumber; + private int playerType; + private int playerUUID; + private int slotNumber; /** - * This is the general purpose constructor. - */ - public TransferItemFromEquipToInventoryMsg(AbstractGameObject ago, int slotNumber) { - super(Protocol.UNEQUIP); - this.playerType = ago.getObjectType().ordinal(); - this.playerUUID = ago.getObjectUUID(); - this.slotNumber = slotNumber; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public TransferItemFromEquipToInventoryMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.UNEQUIP, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.playerType = reader.getInt(); - this.playerUUID = reader.getInt(); - this.slotNumber = reader.getInt(); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - writer.putInt(this.playerType); - writer.putInt(this.playerUUID); - writer.putInt(this.slotNumber); - } - - - - /** - * @return the slotNumber - */ - public int getSlotNumber() { - return slotNumber; - } - - public int getPlayerType() { - return playerType; - } - - public void setPlayerType(int playerType) { - this.playerType = playerType; - } - - public int getPlayerUUID() { - return playerUUID; - } - - public void setPlayerUUID(int playerUUID) { - this.playerUUID = playerUUID; - } + * This is the general purpose constructor. + */ + public TransferItemFromEquipToInventoryMsg(AbstractGameObject ago, int slotNumber) { + super(Protocol.UNEQUIP); + this.playerType = ago.getObjectType().ordinal(); + this.playerUUID = ago.getObjectUUID(); + this.slotNumber = slotNumber; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TransferItemFromEquipToInventoryMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.UNEQUIP, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.playerType = reader.getInt(); + this.playerUUID = reader.getInt(); + this.slotNumber = reader.getInt(); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + writer.putInt(this.playerType); + writer.putInt(this.playerUUID); + writer.putInt(this.slotNumber); + } + + + /** + * @return the slotNumber + */ + public int getSlotNumber() { + return slotNumber; + } + + public int getPlayerType() { + return playerType; + } + + public void setPlayerType(int playerType) { + this.playerType = playerType; + } + + public int getPlayerUUID() { + return playerUUID; + } + + public void setPlayerUUID(int playerUUID) { + this.playerUUID = playerUUID; + } } diff --git a/src/engine/net/client/msg/TransferItemFromInventoryToBankMsg.java b/src/engine/net/client/msg/TransferItemFromInventoryToBankMsg.java index 124f684e..f4dbbd31 100644 --- a/src/engine/net/client/msg/TransferItemFromInventoryToBankMsg.java +++ b/src/engine/net/client/msg/TransferItemFromInventoryToBankMsg.java @@ -24,197 +24,196 @@ import engine.net.client.Protocol; public class TransferItemFromInventoryToBankMsg extends ClientNetMsg { - private long playerCompID1; - private long playerCompID2; - private int type; - private int objectUUID; - private int unknown1; - private int unknown2; - private int numItems; - private byte unknown4; - - /** - * This is the general purpose constructor - */ - public TransferItemFromInventoryToBankMsg(long playerCompID1, - long playerCompID2, int type, int objectUUID, int unknown1, - int unknown2, int numItems, byte unknown4) { - super(Protocol.TRANSFERITEMTOBANK); - this.playerCompID1 = playerCompID1; - this.playerCompID2 = playerCompID2; - this.type = type; - this.objectUUID = objectUUID; - this.unknown1 = unknown1; - this.unknown2 = unknown2; - this.numItems = numItems; - this.unknown4 = unknown4; - } - - public TransferItemFromInventoryToBankMsg(TransferItemFromBankToInventoryMsg msg) { - super(Protocol.TRANSFERITEMTOBANK); - this.playerCompID1 = msg.getPlayerCompID1(); - this.playerCompID2 = msg.getPlayerCompID2(); - this.type = msg.getType(); - this.objectUUID = msg.getUUID(); - this.unknown1 = msg.getUnknown1(); - this.unknown2 = msg.getUnknown2(); - this.numItems = msg.getNumItems(); - this.unknown4 = msg.getUnknown4(); - } - - /** - * This is the general purpose constructor - */ - public TransferItemFromInventoryToBankMsg() { - super(Protocol.TRANSFERITEMTOBANK); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public TransferItemFromInventoryToBankMsg(AbstractConnection origin, - ByteBufferReader reader) { - super(Protocol.TRANSFERITEMTOBANK, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - playerCompID1 = reader.getLong(); - playerCompID2 = reader.getLong(); - type = reader.getInt(); - objectUUID = reader.getInt(); - unknown1 = reader.getInt(); - unknown2 = reader.getInt(); - numItems = reader.getInt(); - unknown4 = reader.get(); - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - writer.putLong(playerCompID1); - writer.putLong(playerCompID2); - writer.putInt(type); - writer.putInt(objectUUID); - writer.putInt(unknown1); - writer.putInt(unknown2); - writer.putInt(numItems); - writer.put(unknown4); - } - - /** - * @return the playerCompID1 - */ - public long getPlayerCompID1() { - return playerCompID1; - } - - /** - * @param playerCompID1 the playerCompID1 to set - */ - public void setPlayerCompID1(long playerCompID1) { - this.playerCompID1 = playerCompID1; - } - - /** - * @return the playerCompID2 - */ - public long getPlayerCompID2() { - return playerCompID2; - } - - /** - * @param playerCompID2 the playerCompID2 to set - */ - public void setPlayerCompID2(long playerCompID2) { - this.playerCompID2 = playerCompID2; - } - - /** - * @return the type - */ - public int getType() { - return type; - } - - /** - * @param type the type to set - */ - public void setType(int type) { - this.type = type; - } - - /** - * @return the objectUUID - */ - public int getUUID() { - return objectUUID; - } - - /** - * @return the unknown1 - */ - public int getUnknown1() { - return unknown1; - } - - /** - * @param unknown1 the unknown1 to set - */ - public void setUnknown1(int unknown1) { - this.unknown1 = unknown1; - } - - /** - * @return the unknown2 - */ - public int getUnknown2() { - return unknown2; - } - - /** - * @param unknown2 the unknown2 to set - */ - public void setUnknown2(int unknown2) { - this.unknown2 = unknown2; - } - - /** - * @return the numItems - */ - public int getNumItems() { - return numItems; - } - - /** - * @param numItems the numItems to set - */ - public void setNumItems(int numItems) { - this.numItems = numItems; - } - - /** - * @return the unknown4 - */ - public byte getUnknown4() { - return unknown4; - } - - /** - * @param unknown4 the unknown4 to set - */ - public void setUnknown4(byte unknown4) { - this.unknown4 = unknown4; - } + private long playerCompID1; + private long playerCompID2; + private int type; + private int objectUUID; + private int unknown1; + private int unknown2; + private int numItems; + private byte unknown4; + + /** + * This is the general purpose constructor + */ + public TransferItemFromInventoryToBankMsg(long playerCompID1, + long playerCompID2, int type, int objectUUID, int unknown1, + int unknown2, int numItems, byte unknown4) { + super(Protocol.TRANSFERITEMTOBANK); + this.playerCompID1 = playerCompID1; + this.playerCompID2 = playerCompID2; + this.type = type; + this.objectUUID = objectUUID; + this.unknown1 = unknown1; + this.unknown2 = unknown2; + this.numItems = numItems; + this.unknown4 = unknown4; + } + + public TransferItemFromInventoryToBankMsg(TransferItemFromBankToInventoryMsg msg) { + super(Protocol.TRANSFERITEMTOBANK); + this.playerCompID1 = msg.getPlayerCompID1(); + this.playerCompID2 = msg.getPlayerCompID2(); + this.type = msg.getType(); + this.objectUUID = msg.getUUID(); + this.unknown1 = msg.getUnknown1(); + this.unknown2 = msg.getUnknown2(); + this.numItems = msg.getNumItems(); + this.unknown4 = msg.getUnknown4(); + } + + /** + * This is the general purpose constructor + */ + public TransferItemFromInventoryToBankMsg() { + super(Protocol.TRANSFERITEMTOBANK); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TransferItemFromInventoryToBankMsg(AbstractConnection origin, + ByteBufferReader reader) { + super(Protocol.TRANSFERITEMTOBANK, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + playerCompID1 = reader.getLong(); + playerCompID2 = reader.getLong(); + type = reader.getInt(); + objectUUID = reader.getInt(); + unknown1 = reader.getInt(); + unknown2 = reader.getInt(); + numItems = reader.getInt(); + unknown4 = reader.get(); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putLong(playerCompID1); + writer.putLong(playerCompID2); + writer.putInt(type); + writer.putInt(objectUUID); + writer.putInt(unknown1); + writer.putInt(unknown2); + writer.putInt(numItems); + writer.put(unknown4); + } + + /** + * @return the playerCompID1 + */ + public long getPlayerCompID1() { + return playerCompID1; + } + + /** + * @param playerCompID1 the playerCompID1 to set + */ + public void setPlayerCompID1(long playerCompID1) { + this.playerCompID1 = playerCompID1; + } + + /** + * @return the playerCompID2 + */ + public long getPlayerCompID2() { + return playerCompID2; + } + + /** + * @param playerCompID2 the playerCompID2 to set + */ + public void setPlayerCompID2(long playerCompID2) { + this.playerCompID2 = playerCompID2; + } + + /** + * @return the type + */ + public int getType() { + return type; + } + + /** + * @param type the type to set + */ + public void setType(int type) { + this.type = type; + } + + /** + * @return the objectUUID + */ + public int getUUID() { + return objectUUID; + } + + /** + * @return the unknown1 + */ + public int getUnknown1() { + return unknown1; + } + + /** + * @param unknown1 the unknown1 to set + */ + public void setUnknown1(int unknown1) { + this.unknown1 = unknown1; + } + + /** + * @return the unknown2 + */ + public int getUnknown2() { + return unknown2; + } + + /** + * @param unknown2 the unknown2 to set + */ + public void setUnknown2(int unknown2) { + this.unknown2 = unknown2; + } + + /** + * @return the numItems + */ + public int getNumItems() { + return numItems; + } + + /** + * @param numItems the numItems to set + */ + public void setNumItems(int numItems) { + this.numItems = numItems; + } + + /** + * @return the unknown4 + */ + public byte getUnknown4() { + return unknown4; + } + + /** + * @param unknown4 the unknown4 to set + */ + public void setUnknown4(byte unknown4) { + this.unknown4 = unknown4; + } } diff --git a/src/engine/net/client/msg/TransferItemFromInventoryToEquipMsg.java b/src/engine/net/client/msg/TransferItemFromInventoryToEquipMsg.java index 223d7a54..c74c035e 100644 --- a/src/engine/net/client/msg/TransferItemFromInventoryToEquipMsg.java +++ b/src/engine/net/client/msg/TransferItemFromInventoryToEquipMsg.java @@ -19,203 +19,195 @@ import engine.objects.AbstractCharacter; public class TransferItemFromInventoryToEquipMsg extends ClientNetMsg { - private int sourceType; - private int sourceID; - private int pad1; - private int itemBase; - private int type; - private int objectUUID; - private int slotNumber; - private int pad2; - private float unknown1, unknown2; - - /** - * This is the general purpose constructor. - */ - public TransferItemFromInventoryToEquipMsg() { - super(Protocol.EQUIP); - } - - public TransferItemFromInventoryToEquipMsg(AbstractCharacter source, int slot, int itemBaseID) { - super(Protocol.EQUIP); - this.sourceType = source.getObjectType().ordinal(); - this.sourceID = source.getObjectUUID(); - this.slotNumber = slot; - this.itemBase = itemBaseID; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public TransferItemFromInventoryToEquipMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.EQUIP, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - pad1 = reader.getInt(); - itemBase = reader.getInt(); - type = reader.getInt(); - objectUUID = reader.getInt(); - slotNumber = reader.getInt(); - pad2 = reader.getInt(); - unknown1 = reader.getFloat(); - unknown2 = reader.getFloat(); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.putInt(pad1); - writer.putInt(itemBase); - writer.putInt(type); - writer.putInt(objectUUID); - writer.putInt(slotNumber); - writer.putInt(pad2); - writer.putFloat(unknown1); - writer.putFloat(unknown1); - } - - - - /** - * @return the pad1 - */ - public int getPad1() { - return pad1; - } - - /** - * @param pad1 - * the pad1 to set - */ - public void setPad1(int pad1) { - this.pad1 = pad1; - } - - /** - * @return the itemBase - */ - public int getItemBase() { - return itemBase; - } - - /** - * @param itemBase - * the itemBase to set - */ - public void setItemBase(int itemBase) { - this.itemBase = itemBase; - } - - /** - * @return the type - */ - public int getType() { - return type; - } - - /** - * @param type - * the type to set - */ - public void setType(int type) { - this.type = type; - } - - /** - * @return the objectUUID - */ - public int getUUID() { - return objectUUID; - } - - /** - * @return the slotNumber - */ - public int getSlotNumber() { - return slotNumber; - } - - /** - * @param slotNumber - * the slotNumber to set - */ - public void setSlotNumber(int slotNumber) { - this.slotNumber = slotNumber; - } - - /** - * @return the pad2 - */ - public int getPad2() { - return pad2; - } - - /** - * @param pad2 - * the pad2 to set - */ - public void setPad2(int pad2) { - this.pad2 = pad2; - } - - /** - * @return the unknown1 - */ - public float getUnknown1() { - return unknown1; - } - - /** - * @param unknown1 - * the unknown1 to set - */ - public void setUnknown1(float unknown1) { - this.unknown1 = unknown1; - } - - /** - * @return the unknown2 - */ - public float getUnknown2() { - return unknown2; - } - - /** - * @param unknown2 - * the unknown2 to set - */ - public void setUnknown2(float unknown2) { - this.unknown2 = unknown2; - } - - public int getSourceType() { - return sourceType; - } - - public void setSourceType(int sourceType) { - this.sourceType = sourceType; - } - - public int getSourceID() { - return sourceID; - } - - public void setSourceID(int sourceID) { - this.sourceID = sourceID; - } + private int sourceType; + private int sourceID; + private int pad1; + private int itemBase; + private int type; + private int objectUUID; + private int slotNumber; + private int pad2; + private float unknown1, unknown2; + + /** + * This is the general purpose constructor. + */ + public TransferItemFromInventoryToEquipMsg() { + super(Protocol.EQUIP); + } + + public TransferItemFromInventoryToEquipMsg(AbstractCharacter source, int slot, int itemBaseID) { + super(Protocol.EQUIP); + this.sourceType = source.getObjectType().ordinal(); + this.sourceID = source.getObjectUUID(); + this.slotNumber = slot; + this.itemBase = itemBaseID; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TransferItemFromInventoryToEquipMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.EQUIP, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + pad1 = reader.getInt(); + itemBase = reader.getInt(); + type = reader.getInt(); + objectUUID = reader.getInt(); + slotNumber = reader.getInt(); + pad2 = reader.getInt(); + unknown1 = reader.getFloat(); + unknown2 = reader.getFloat(); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.putInt(pad1); + writer.putInt(itemBase); + writer.putInt(type); + writer.putInt(objectUUID); + writer.putInt(slotNumber); + writer.putInt(pad2); + writer.putFloat(unknown1); + writer.putFloat(unknown1); + } + + + /** + * @return the pad1 + */ + public int getPad1() { + return pad1; + } + + /** + * @param pad1 the pad1 to set + */ + public void setPad1(int pad1) { + this.pad1 = pad1; + } + + /** + * @return the itemBase + */ + public int getItemBase() { + return itemBase; + } + + /** + * @param itemBase the itemBase to set + */ + public void setItemBase(int itemBase) { + this.itemBase = itemBase; + } + + /** + * @return the type + */ + public int getType() { + return type; + } + + /** + * @param type the type to set + */ + public void setType(int type) { + this.type = type; + } + + /** + * @return the objectUUID + */ + public int getUUID() { + return objectUUID; + } + + /** + * @return the slotNumber + */ + public int getSlotNumber() { + return slotNumber; + } + + /** + * @param slotNumber the slotNumber to set + */ + public void setSlotNumber(int slotNumber) { + this.slotNumber = slotNumber; + } + + /** + * @return the pad2 + */ + public int getPad2() { + return pad2; + } + + /** + * @param pad2 the pad2 to set + */ + public void setPad2(int pad2) { + this.pad2 = pad2; + } + + /** + * @return the unknown1 + */ + public float getUnknown1() { + return unknown1; + } + + /** + * @param unknown1 the unknown1 to set + */ + public void setUnknown1(float unknown1) { + this.unknown1 = unknown1; + } + + /** + * @return the unknown2 + */ + public float getUnknown2() { + return unknown2; + } + + /** + * @param unknown2 the unknown2 to set + */ + public void setUnknown2(float unknown2) { + this.unknown2 = unknown2; + } + + public int getSourceType() { + return sourceType; + } + + public void setSourceType(int sourceType) { + this.sourceType = sourceType; + } + + public int getSourceID() { + return sourceID; + } + + public void setSourceID(int sourceID) { + this.sourceID = sourceID; + } } diff --git a/src/engine/net/client/msg/TransferItemFromInventoryToVaultMsg.java b/src/engine/net/client/msg/TransferItemFromInventoryToVaultMsg.java index e1c5bc47..9ec0cd7a 100644 --- a/src/engine/net/client/msg/TransferItemFromInventoryToVaultMsg.java +++ b/src/engine/net/client/msg/TransferItemFromInventoryToVaultMsg.java @@ -24,184 +24,177 @@ import engine.net.client.Protocol; public class TransferItemFromInventoryToVaultMsg extends ClientNetMsg { - private int unknown01; - private int unknown02; - private long playerCompID; - private int type; - private int objectUUID; - private int unknown03; - private int unknown04; - - /** - * This is the general purpose constructor - */ - public TransferItemFromInventoryToVaultMsg(long playerCompID, - int unknown01, int unknown02, int type, int objectUUID, int unknown03, - int unknown04) { - super(Protocol.ITEMTOVAULT); - this.playerCompID = playerCompID; - this.unknown01 = unknown01; - this.unknown02 = unknown02; - this.type = type; - this.objectUUID = objectUUID; - this.unknown03 = unknown03; - this.unknown04 = unknown04; - } - - public TransferItemFromInventoryToVaultMsg(TransferItemFromVaultToInventoryMsg msg) { - super(Protocol.ITEMTOVAULT); - this.playerCompID = msg.getPlayerCompID(); - this.unknown01 = msg.getUnknown01(); - this.unknown02 = msg.getUnknown02(); - this.type = msg.getType(); - this.objectUUID = msg.getUUID(); - this.unknown03 = msg.getUnknown03(); - this.unknown04 = msg.getUnknown04(); - } - - /** - * This is the general purpose constructor - */ - public TransferItemFromInventoryToVaultMsg() { - super(Protocol.ITEMTOVAULT); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public TransferItemFromInventoryToVaultMsg(AbstractConnection origin, - ByteBufferReader reader) { - super(Protocol.ITEMTOVAULT, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - playerCompID = reader.getLong(); - unknown01 = reader.getInt(); - unknown02 = reader.getInt(); - type = reader.getInt(); - objectUUID = reader.getInt(); - unknown03 = reader.getInt(); - unknown04 = reader.getInt(); - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - writer.putLong(playerCompID); - writer.putInt(unknown01); - writer.putInt(unknown02); - writer.putInt(type); - writer.putInt(objectUUID); - writer.putInt(unknown03); - writer.putInt(unknown04); - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the unknown02 - */ - public int getUnknown02() { - return unknown02; - } - - /** - * @param unknown02 - * the unknown02 to set - */ - public void setUnknown02(int unknown02) { - this.unknown02 = unknown02; - } - - /** - * @return the playerCompID - */ - public long getPlayerCompID() { - return playerCompID; - } - - /** - * @param playerCompID - * the playerCompID to set - */ - public void setPlayerCompID(long playerCompID) { - this.playerCompID = playerCompID; - } - - /** - * @return the type - */ - public int getType() { - return type; - } - - /** - * @param type - * the type to set - */ - public void setType(int type) { - this.type = type; - } - - /** - * @return the objectUUID - */ - public int getUUID() { - return objectUUID; - } - - /** - * @return the unknown03 - */ - public int getUnknown03() { - return unknown03; - } - - /** - * @param unknown03 - * the unknown03 to set - */ - public void setUnknown03(int unknown03) { - this.unknown03 = unknown03; - } - - /** - * @return the unknown04 - */ - public int getUnknown04() { - return unknown04; - } - - /** - * @param unknown04 - * the unknown04 to set - */ - public void setUnknown04(int unknown04) { - this.unknown04 = unknown04; - } + private int unknown01; + private int unknown02; + private long playerCompID; + private int type; + private int objectUUID; + private int unknown03; + private int unknown04; + + /** + * This is the general purpose constructor + */ + public TransferItemFromInventoryToVaultMsg(long playerCompID, + int unknown01, int unknown02, int type, int objectUUID, int unknown03, + int unknown04) { + super(Protocol.ITEMTOVAULT); + this.playerCompID = playerCompID; + this.unknown01 = unknown01; + this.unknown02 = unknown02; + this.type = type; + this.objectUUID = objectUUID; + this.unknown03 = unknown03; + this.unknown04 = unknown04; + } + + public TransferItemFromInventoryToVaultMsg(TransferItemFromVaultToInventoryMsg msg) { + super(Protocol.ITEMTOVAULT); + this.playerCompID = msg.getPlayerCompID(); + this.unknown01 = msg.getUnknown01(); + this.unknown02 = msg.getUnknown02(); + this.type = msg.getType(); + this.objectUUID = msg.getUUID(); + this.unknown03 = msg.getUnknown03(); + this.unknown04 = msg.getUnknown04(); + } + + /** + * This is the general purpose constructor + */ + public TransferItemFromInventoryToVaultMsg() { + super(Protocol.ITEMTOVAULT); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TransferItemFromInventoryToVaultMsg(AbstractConnection origin, + ByteBufferReader reader) { + super(Protocol.ITEMTOVAULT, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + playerCompID = reader.getLong(); + unknown01 = reader.getInt(); + unknown02 = reader.getInt(); + type = reader.getInt(); + objectUUID = reader.getInt(); + unknown03 = reader.getInt(); + unknown04 = reader.getInt(); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putLong(playerCompID); + writer.putInt(unknown01); + writer.putInt(unknown02); + writer.putInt(type); + writer.putInt(objectUUID); + writer.putInt(unknown03); + writer.putInt(unknown04); + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the unknown02 + */ + public int getUnknown02() { + return unknown02; + } + + /** + * @param unknown02 the unknown02 to set + */ + public void setUnknown02(int unknown02) { + this.unknown02 = unknown02; + } + + /** + * @return the playerCompID + */ + public long getPlayerCompID() { + return playerCompID; + } + + /** + * @param playerCompID the playerCompID to set + */ + public void setPlayerCompID(long playerCompID) { + this.playerCompID = playerCompID; + } + + /** + * @return the type + */ + public int getType() { + return type; + } + + /** + * @param type the type to set + */ + public void setType(int type) { + this.type = type; + } + + /** + * @return the objectUUID + */ + public int getUUID() { + return objectUUID; + } + + /** + * @return the unknown03 + */ + public int getUnknown03() { + return unknown03; + } + + /** + * @param unknown03 the unknown03 to set + */ + public void setUnknown03(int unknown03) { + this.unknown03 = unknown03; + } + + /** + * @return the unknown04 + */ + public int getUnknown04() { + return unknown04; + } + + /** + * @param unknown04 the unknown04 to set + */ + public void setUnknown04(int unknown04) { + this.unknown04 = unknown04; + } } diff --git a/src/engine/net/client/msg/TransferItemFromVaultToInventoryMsg.java b/src/engine/net/client/msg/TransferItemFromVaultToInventoryMsg.java index dcef2821..053a40d2 100644 --- a/src/engine/net/client/msg/TransferItemFromVaultToInventoryMsg.java +++ b/src/engine/net/client/msg/TransferItemFromVaultToInventoryMsg.java @@ -24,177 +24,176 @@ import engine.net.client.Protocol; public class TransferItemFromVaultToInventoryMsg extends ClientNetMsg { - private int unknown01; - private int unknown02; - private long playerCompID; - private int type; - private int objectUUID; - private int unknown03; - private int unknown04; - - /** - * This is the general purpose constructor - */ - public TransferItemFromVaultToInventoryMsg(int unknown01, int unknown02, - long playerCompID, int type, int objectUUID, int unknown03, int unknown04) { - super(Protocol.TRANSFERITEMFROMVAULTTOINVENTORY); - this.unknown01 = unknown01; - this.unknown02 = unknown02; - this.playerCompID = playerCompID; - this.type = type; - this.objectUUID = objectUUID; - this.unknown03 = unknown03; - this.unknown04 = unknown04; - } - - public TransferItemFromVaultToInventoryMsg(TransferItemFromInventoryToVaultMsg msg) { - super(Protocol.TRANSFERITEMFROMVAULTTOINVENTORY); - this.playerCompID = msg.getPlayerCompID(); - this.unknown01 = msg.getUnknown01(); - this.unknown02 = msg.getUnknown02(); - this.type = msg.getType(); - this.objectUUID = msg.getUUID(); - this.unknown03 = msg.getUnknown03(); - this.unknown04 = msg.getUnknown04(); - } - - /** - * This is the general purpose constructor - */ - public TransferItemFromVaultToInventoryMsg() { - super(Protocol.TRANSFERITEMFROMVAULTTOINVENTORY); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public TransferItemFromVaultToInventoryMsg(AbstractConnection origin, - ByteBufferReader reader) { - super(Protocol.TRANSFERITEMFROMVAULTTOINVENTORY, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - unknown01 = reader.getInt(); - unknown02 = reader.getInt(); - playerCompID = reader.getLong(); - type = reader.getInt(); - objectUUID = reader.getInt(); - unknown03 = reader.getInt(); - unknown04 = reader.getInt(); - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - writer.putInt(unknown01); - writer.putInt(unknown02); - writer.putLong(playerCompID); - writer.putInt(type); - writer.putInt(objectUUID); - writer.putInt(unknown03); - writer.putInt(unknown04); - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the unknown02 - */ - public int getUnknown02() { - return unknown02; - } - - /** - * @param unknown02 the unknown02 to set - */ - public void setUnknown02(int unknown02) { - this.unknown02 = unknown02; - } - - /** - * @return the playerCompID - */ - public long getPlayerCompID() { - return playerCompID; - } - - /** - * @param playerCompID the playerCompID to set - */ - public void setPlayerCompID(long playerCompID) { - this.playerCompID = playerCompID; - } - - /** - * @return the type - */ - public int getType() { - return type; - } - - /** - * @param type the type to set - */ - public void setType(int type) { - this.type = type; - } - - /** - * @return the objectUUID - */ - public int getUUID() { - return objectUUID; - } - - /** - * @return the unknown03 - */ - public int getUnknown03() { - return unknown03; - } - - /** - * @param unknown03 the unknown03 to set - */ - public void setUnknown03(int unknown03) { - this.unknown03 = unknown03; - } - - /** - * @return the unknown04 - */ - public int getUnknown04() { - return unknown04; - } - - /** - * @param unknown04 the unknown04 to set - */ - public void setUnknown04(int unknown04) { - this.unknown04 = unknown04; - } + private int unknown01; + private int unknown02; + private long playerCompID; + private int type; + private int objectUUID; + private int unknown03; + private int unknown04; + + /** + * This is the general purpose constructor + */ + public TransferItemFromVaultToInventoryMsg(int unknown01, int unknown02, + long playerCompID, int type, int objectUUID, int unknown03, int unknown04) { + super(Protocol.TRANSFERITEMFROMVAULTTOINVENTORY); + this.unknown01 = unknown01; + this.unknown02 = unknown02; + this.playerCompID = playerCompID; + this.type = type; + this.objectUUID = objectUUID; + this.unknown03 = unknown03; + this.unknown04 = unknown04; + } + + public TransferItemFromVaultToInventoryMsg(TransferItemFromInventoryToVaultMsg msg) { + super(Protocol.TRANSFERITEMFROMVAULTTOINVENTORY); + this.playerCompID = msg.getPlayerCompID(); + this.unknown01 = msg.getUnknown01(); + this.unknown02 = msg.getUnknown02(); + this.type = msg.getType(); + this.objectUUID = msg.getUUID(); + this.unknown03 = msg.getUnknown03(); + this.unknown04 = msg.getUnknown04(); + } + + /** + * This is the general purpose constructor + */ + public TransferItemFromVaultToInventoryMsg() { + super(Protocol.TRANSFERITEMFROMVAULTTOINVENTORY); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public TransferItemFromVaultToInventoryMsg(AbstractConnection origin, + ByteBufferReader reader) { + super(Protocol.TRANSFERITEMFROMVAULTTOINVENTORY, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + unknown01 = reader.getInt(); + unknown02 = reader.getInt(); + playerCompID = reader.getLong(); + type = reader.getInt(); + objectUUID = reader.getInt(); + unknown03 = reader.getInt(); + unknown04 = reader.getInt(); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putInt(unknown01); + writer.putInt(unknown02); + writer.putLong(playerCompID); + writer.putInt(type); + writer.putInt(objectUUID); + writer.putInt(unknown03); + writer.putInt(unknown04); + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the unknown02 + */ + public int getUnknown02() { + return unknown02; + } + + /** + * @param unknown02 the unknown02 to set + */ + public void setUnknown02(int unknown02) { + this.unknown02 = unknown02; + } + + /** + * @return the playerCompID + */ + public long getPlayerCompID() { + return playerCompID; + } + + /** + * @param playerCompID the playerCompID to set + */ + public void setPlayerCompID(long playerCompID) { + this.playerCompID = playerCompID; + } + + /** + * @return the type + */ + public int getType() { + return type; + } + + /** + * @param type the type to set + */ + public void setType(int type) { + this.type = type; + } + + /** + * @return the objectUUID + */ + public int getUUID() { + return objectUUID; + } + + /** + * @return the unknown03 + */ + public int getUnknown03() { + return unknown03; + } + + /** + * @param unknown03 the unknown03 to set + */ + public void setUnknown03(int unknown03) { + this.unknown03 = unknown03; + } + + /** + * @return the unknown04 + */ + public int getUnknown04() { + return unknown04; + } + + /** + * @param unknown04 the unknown04 to set + */ + public void setUnknown04(int unknown04) { + this.unknown04 = unknown04; + } } diff --git a/src/engine/net/client/msg/UncommitToTradeMsg.java b/src/engine/net/client/msg/UncommitToTradeMsg.java index d3429f29..7a175350 100644 --- a/src/engine/net/client/msg/UncommitToTradeMsg.java +++ b/src/engine/net/client/msg/UncommitToTradeMsg.java @@ -24,72 +24,70 @@ import engine.net.client.Protocol; */ public class UncommitToTradeMsg extends ClientNetMsg { - private int unknown01; - private long playerCompID; - - /** - * This is the general purpose constructor - */ - public UncommitToTradeMsg(int unknown01, long playerCompID) { - super(Protocol.TRADEUNCONFIRM); - this.unknown01 = unknown01; - this.playerCompID = playerCompID; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public UncommitToTradeMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.TRADEUNCONFIRM, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - unknown01 = reader.getInt(); - playerCompID = reader.getLong(); - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - writer.putInt(unknown01); - writer.putLong(playerCompID); - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the playerCompID - */ - public long getPlayerCompID() { - return playerCompID; - } - - /** - * @param playerCompID the playerCompID to set - */ - public void setPlayerCompID(long playerCompID) { - this.playerCompID = playerCompID; - } + private int unknown01; + private long playerCompID; + + /** + * This is the general purpose constructor + */ + public UncommitToTradeMsg(int unknown01, long playerCompID) { + super(Protocol.TRADEUNCONFIRM); + this.unknown01 = unknown01; + this.playerCompID = playerCompID; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public UncommitToTradeMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.TRADEUNCONFIRM, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + unknown01 = reader.getInt(); + playerCompID = reader.getLong(); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putInt(unknown01); + writer.putLong(playerCompID); + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the playerCompID + */ + public long getPlayerCompID() { + return playerCompID; + } + + /** + * @param playerCompID the playerCompID to set + */ + public void setPlayerCompID(long playerCompID) { + this.playerCompID = playerCompID; + } } diff --git a/src/engine/net/client/msg/Unknown1Msg.java b/src/engine/net/client/msg/Unknown1Msg.java index 29fa9ad5..4c92abf1 100644 --- a/src/engine/net/client/msg/Unknown1Msg.java +++ b/src/engine/net/client/msg/Unknown1Msg.java @@ -17,63 +17,63 @@ import engine.net.client.Protocol; public class Unknown1Msg extends ClientNetMsg { - private int targetType; - private int targetID; + private int targetType; + private int targetID; - /** - * This is the general purpose constructor. - */ - public Unknown1Msg(int targetType, int targetID) { - super(Protocol.UNKNOWN1); - this.targetType = targetType; - this.targetID = targetID; - } + /** + * This is the general purpose constructor. + */ + public Unknown1Msg(int targetType, int targetID) { + super(Protocol.UNKNOWN1); + this.targetType = targetType; + this.targetID = targetID; + } - /** - * This is the general purpose constructor. - */ - public Unknown1Msg() { - super(Protocol.UNKNOWN1); - } + /** + * This is the general purpose constructor. + */ + public Unknown1Msg() { + super(Protocol.UNKNOWN1); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public Unknown1Msg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.UNKNOWN1, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public Unknown1Msg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.UNKNOWN1, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - } + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + } - /** - * @return the targetType - */ - public int getTargetType() { - return targetType; - } + /** + * @return the targetType + */ + public int getTargetType() { + return targetType; + } - /** - * @return the targetID - */ - public int getTargetID() { - return targetID; - } + /** + * @return the targetID + */ + public int getTargetID() { + return targetID; + } } diff --git a/src/engine/net/client/msg/UnknownMsg.java b/src/engine/net/client/msg/UnknownMsg.java index f806125f..7d57ea49 100644 --- a/src/engine/net/client/msg/UnknownMsg.java +++ b/src/engine/net/client/msg/UnknownMsg.java @@ -17,139 +17,134 @@ import engine.net.client.Protocol; public class UnknownMsg extends ClientNetMsg { - private int unknown01; - private int unknown02; - private int unknown03; - private short unknown04; - private byte unknown05; - - /** - * This is the general purpose constructor. - */ - public UnknownMsg() { - super(Protocol.UNKNOWN); - this.unknown01 = 0x40A5BDB0; - this.unknown02 = 0x342AA9F0; - this.unknown03 = 0; - this.unknown04 = (short) 0; - this.unknown05 = (byte) 0; - - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public UnknownMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.UNKNOWN, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - writer.putInt(this.unknown03); - writer.putShort(this.unknown04); - writer.put(this.unknown05); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - reader.getFloat(); - reader.getString(); - reader.getString(); - reader.getInt(); - reader.get(); - reader.getInt(); - reader.getInt(); - int unknownSize =reader.getInt(); - for (int i = 0; i < unknownSize;i++) - reader.getInt(); - reader.getInt(); - reader.getString(); - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the unknown02 - */ - public int getUnknown02() { - return unknown02; - } - - /** - * @param unknown02 - * the unknown02 to set - */ - public void setUnknown02(int unknown02) { - this.unknown02 = unknown02; - } - - /** - * @return the unknown03 - */ - public int getUnknown03() { - return unknown03; - } - - /** - * @param unknown03 - * the unknown03 to set - */ - public void setUnknown03(int unknown03) { - this.unknown03 = unknown03; - } - - /** - * @return the unknown04 - */ - public short getUnknown04() { - return unknown04; - } - - /** - * @param unknown04 - * the unknown04 to set - */ - public void setUnknown04(short unknown04) { - this.unknown04 = unknown04; - } - - /** - * @return the unknown05 - */ - public byte getUnknown05() { - return unknown05; - } - - /** - * @param unknown05 - * the unknown05 to set - */ - public void setUnknown05(byte unknown05) { - this.unknown05 = unknown05; - } + private int unknown01; + private int unknown02; + private int unknown03; + private short unknown04; + private byte unknown05; + + /** + * This is the general purpose constructor. + */ + public UnknownMsg() { + super(Protocol.UNKNOWN); + this.unknown01 = 0x40A5BDB0; + this.unknown02 = 0x342AA9F0; + this.unknown03 = 0; + this.unknown04 = (short) 0; + this.unknown05 = (byte) 0; + + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public UnknownMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.UNKNOWN, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + writer.putInt(this.unknown03); + writer.putShort(this.unknown04); + writer.put(this.unknown05); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.getFloat(); + reader.getString(); + reader.getString(); + reader.getInt(); + reader.get(); + reader.getInt(); + reader.getInt(); + int unknownSize = reader.getInt(); + for (int i = 0; i < unknownSize; i++) + reader.getInt(); + reader.getInt(); + reader.getString(); + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the unknown02 + */ + public int getUnknown02() { + return unknown02; + } + + /** + * @param unknown02 the unknown02 to set + */ + public void setUnknown02(int unknown02) { + this.unknown02 = unknown02; + } + + /** + * @return the unknown03 + */ + public int getUnknown03() { + return unknown03; + } + + /** + * @param unknown03 the unknown03 to set + */ + public void setUnknown03(int unknown03) { + this.unknown03 = unknown03; + } + + /** + * @return the unknown04 + */ + public short getUnknown04() { + return unknown04; + } + + /** + * @param unknown04 the unknown04 to set + */ + public void setUnknown04(short unknown04) { + this.unknown04 = unknown04; + } + + /** + * @return the unknown05 + */ + public byte getUnknown05() { + return unknown05; + } + + /** + * @param unknown05 the unknown05 to set + */ + public void setUnknown05(byte unknown05) { + this.unknown05 = unknown05; + } } diff --git a/src/engine/net/client/msg/UnloadObjectsMsg.java b/src/engine/net/client/msg/UnloadObjectsMsg.java index 4e2c0770..e300e646 100644 --- a/src/engine/net/client/msg/UnloadObjectsMsg.java +++ b/src/engine/net/client/msg/UnloadObjectsMsg.java @@ -22,75 +22,75 @@ import java.util.HashMap; public class UnloadObjectsMsg extends ClientNetMsg { - private HashMap objectList = new HashMap<>(); - - /** - * This is the general purpose constructor. - */ - public UnloadObjectsMsg() { - super(Protocol.FORGETOBJECTS); - init(); - } - - private void init() { - objectList = new HashMap<>(); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public UnloadObjectsMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.FORGETOBJECTS, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - - if (this.objectList == null){ - writer.putInt(0); - return; - } - - writer.putInt(this.objectList.size()); - for (int objectUUID: this.objectList.keySet()){ - writer.putInt(this.objectList.get(objectUUID)); - writer.putInt(objectUUID); - } - - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - init(); - int size = reader.getInt(); + private HashMap objectList = new HashMap<>(); + + /** + * This is the general purpose constructor. + */ + public UnloadObjectsMsg() { + super(Protocol.FORGETOBJECTS); + init(); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public UnloadObjectsMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.FORGETOBJECTS, origin, reader); + } + + private void init() { + objectList = new HashMap<>(); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + + if (this.objectList == null) { + writer.putInt(0); + return; + } + + writer.putInt(this.objectList.size()); + for (int objectUUID : this.objectList.keySet()) { + writer.putInt(this.objectList.get(objectUUID)); + writer.putInt(objectUUID); + } + + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + init(); + int size = reader.getInt(); // for (int i = 0; i < size; i++) // this.objectList.add(reader.getLong()); - Logger.info( "Client telling server to unload objects.. ??"); - } + Logger.info("Client telling server to unload objects.. ??"); + } - public HashMap getObjectList() { - return this.objectList; - } + public HashMap getObjectList() { + return this.objectList; + } - public void addObject(AbstractGameObject value) { - this.objectList.put(value.getObjectUUID(), value.getObjectType().ordinal()); - } + public void addObject(AbstractGameObject value) { + this.objectList.put(value.getObjectUUID(), value.getObjectType().ordinal()); + } - public int size() { - return this.objectList.size(); - } + public int size() { + return this.objectList.size(); + } - @Override - protected int getPowerOfTwoBufferSize() { - return 13; - } + @Override + protected int getPowerOfTwoBufferSize() { + return 13; + } } diff --git a/src/engine/net/client/msg/UpdateCharOrMobMessage.java b/src/engine/net/client/msg/UpdateCharOrMobMessage.java index 7607ba5d..5eae48ed 100644 --- a/src/engine/net/client/msg/UpdateCharOrMobMessage.java +++ b/src/engine/net/client/msg/UpdateCharOrMobMessage.java @@ -19,160 +19,175 @@ import engine.objects.AbstractCharacter; public class UpdateCharOrMobMessage extends ClientNetMsg { - private int type; - private int npcType; - private int npcID; - - private int playerType; - private int playerID; - private int size; - private int subRace; - - private int pad = 0; - private int objectType; - private int objectUUID; - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public UpdateCharOrMobMessage(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.UPDATECHARORMOB, origin, reader); - } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - - } - - public UpdateCharOrMobMessage(AbstractCharacter tar, int type, int subRaceID) { - super(Protocol.UPDATECHARORMOB); - this.playerType = tar.getObjectType().ordinal(); - this.playerID = tar.getObjectUUID(); - this.type = type; - this.subRace = subRaceID; - } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - writer.putInt(this.type); - if (this.type == 2){ - writer.putInt(this.playerType); - writer.putInt(this.playerID); - writer.putInt(this.subRace); - writer.putInt(-600065291); - return; - } - writer.putInt(this.playerType); - writer.putInt(this.playerID); - writer.put((byte)1); - writer.putInt(0); - writer.putInt(this.subRace); - writer.putInt(this.playerType); - writer.putInt(this.playerID); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putFloat(1); - writer.putFloat(1); - writer.putFloat(1); - writer.putFloat(1); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putLong(-1); - writer.putInt(0); - writer.put((byte)1); - writer.putInt(0); - writer.put((byte)1); - writer.putInt(0); - writer.putInt(0); - writer.put((byte)1); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(4); - writer.putInt(0); - writer.putInt(0); - writer.putInt(1); - writer.putShort((short)0); - writer.put((byte)0); - - - } - - public int getObjectType() { - return objectType; - } - - public void setObjectType(int value) { - this.objectType = value; - } - - public void setPad(int value) { - this.pad = value; - } - - public int getUUID() { - return objectUUID; - - } - - public int getPad() { - return pad; - } - public int getType() { - return type; - } - public void setType(int type) { - this.type = type; - } - public int getSize() { - return size; - } - public void setSize(int size) { - this.size = size; - } - - public int getSubRace() { - return subRace; - } - public void setSubRace(int subRace) { - this.subRace = subRace; - } - public int getNpcType() { - return npcType; - } - public void setNpcType(int npcType) { - this.npcType = npcType; - } - public int getNpcID() { - return npcID; - } - public void setNpcID(int npcID) { - this.npcID = npcID; - } - public int getPlayerType() { - return playerType; - } - public void setPlayerType(int playerType) { - this.playerType = playerType; - } - public int getPlayerID() { - return playerID; - } - public void setPlayerID(int playerID) { - this.playerID = playerID; - } + private int type; + private int npcType; + private int npcID; + + private int playerType; + private int playerID; + private int size; + private int subRace; + + private int pad = 0; + private int objectType; + private int objectUUID; + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public UpdateCharOrMobMessage(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.UPDATECHARORMOB, origin, reader); + } + + public UpdateCharOrMobMessage(AbstractCharacter tar, int type, int subRaceID) { + super(Protocol.UPDATECHARORMOB); + this.playerType = tar.getObjectType().ordinal(); + this.playerID = tar.getObjectUUID(); + this.type = type; + this.subRace = subRaceID; + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + writer.putInt(this.type); + if (this.type == 2) { + writer.putInt(this.playerType); + writer.putInt(this.playerID); + writer.putInt(this.subRace); + writer.putInt(-600065291); + return; + } + writer.putInt(this.playerType); + writer.putInt(this.playerID); + writer.put((byte) 1); + writer.putInt(0); + writer.putInt(this.subRace); + writer.putInt(this.playerType); + writer.putInt(this.playerID); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putFloat(1); + writer.putFloat(1); + writer.putFloat(1); + writer.putFloat(1); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putLong(-1); + writer.putInt(0); + writer.put((byte) 1); + writer.putInt(0); + writer.put((byte) 1); + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 1); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(4); + writer.putInt(0); + writer.putInt(0); + writer.putInt(1); + writer.putShort((short) 0); + writer.put((byte) 0); + + + } + + public int getObjectType() { + return objectType; + } + + public void setObjectType(int value) { + this.objectType = value; + } + + public int getUUID() { + return objectUUID; + + } + + public int getPad() { + return pad; + } + + public void setPad(int value) { + this.pad = value; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + public int getSubRace() { + return subRace; + } + + public void setSubRace(int subRace) { + this.subRace = subRace; + } + + public int getNpcType() { + return npcType; + } + + public void setNpcType(int npcType) { + this.npcType = npcType; + } + + public int getNpcID() { + return npcID; + } + + public void setNpcID(int npcID) { + this.npcID = npcID; + } + + public int getPlayerType() { + return playerType; + } + + public void setPlayerType(int playerType) { + this.playerType = playerType; + } + + public int getPlayerID() { + return playerID; + } + + public void setPlayerID(int playerID) { + this.playerID = playerID; + } } diff --git a/src/engine/net/client/msg/UpdateClientAlliancesMsg.java b/src/engine/net/client/msg/UpdateClientAlliancesMsg.java index ed74bbaa..dfd0d19f 100644 --- a/src/engine/net/client/msg/UpdateClientAlliancesMsg.java +++ b/src/engine/net/client/msg/UpdateClientAlliancesMsg.java @@ -21,75 +21,75 @@ import engine.objects.Guild; public class UpdateClientAlliancesMsg extends ClientNetMsg { - private int guildID; + private int guildID; - public UpdateClientAlliancesMsg(Guild guild) { - super(Protocol.UPDATECLIENTALLIANCES); - this.guildID = guild.getObjectUUID(); + public UpdateClientAlliancesMsg(Guild guild) { + super(Protocol.UPDATECLIENTALLIANCES); + this.guildID = guild.getObjectUUID(); - } + } - public UpdateClientAlliancesMsg() { - super(Protocol.UPDATECLIENTALLIANCES); - } + public UpdateClientAlliancesMsg() { + super(Protocol.UPDATECLIENTALLIANCES); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public UpdateClientAlliancesMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.UPDATECLIENTALLIANCES, origin, reader); - } - //CALL THIS AFTER SANITY CHECKS AND BEFORE UPDATING HEALTH/GOLD. + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public UpdateClientAlliancesMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.UPDATECLIENTALLIANCES, origin, reader); + } + //CALL THIS AFTER SANITY CHECKS AND BEFORE UPDATING HEALTH/GOLD. - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.get(); - } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.get(); + } - // Precache and configure this message before we serialize it + // Precache and configure this message before we serialize it - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { - Guild guild = Guild.getGuild(this.guildID); + Guild guild = Guild.getGuild(this.guildID); - writer.putInt(guild.getAllyList().size()); + writer.putInt(guild.getAllyList().size()); - for (Guild allies: guild.getAllyList()){ - writer.putInt(GameObjectType.Guild.ordinal()); - writer.putInt(allies.getObjectUUID()); - } + for (Guild allies : guild.getAllyList()) { + writer.putInt(GameObjectType.Guild.ordinal()); + writer.putInt(allies.getObjectUUID()); + } - writer.putInt(guild.getEnemyList().size()); - for (Guild enemies: guild.getEnemyList()){ - writer.putInt(GameObjectType.Guild.ordinal()); - writer.putInt(enemies.getObjectUUID()); - } - writer.putInt(0); - writer.putInt(0); - writer.put((byte)1); - } + writer.putInt(guild.getEnemyList().size()); + for (Guild enemies : guild.getEnemyList()) { + writer.putInt(GameObjectType.Guild.ordinal()); + writer.putInt(enemies.getObjectUUID()); + } + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 1); + } - public int getGuildID() { - return guildID; - } + public int getGuildID() { + return guildID; + } } diff --git a/src/engine/net/client/msg/UpdateEffectsMsg.java b/src/engine/net/client/msg/UpdateEffectsMsg.java index b5248cac..aa7a1f8b 100644 --- a/src/engine/net/client/msg/UpdateEffectsMsg.java +++ b/src/engine/net/client/msg/UpdateEffectsMsg.java @@ -21,66 +21,66 @@ import java.util.ArrayList; public class UpdateEffectsMsg extends ClientNetMsg { - AbstractWorldObject awo; + AbstractWorldObject awo; - /** - * This is the general purpose constructor. - */ - public UpdateEffectsMsg() { - super(Protocol.UPDATEEFFECTS); - this.awo = null; - } + /** + * This is the general purpose constructor. + */ + public UpdateEffectsMsg() { + super(Protocol.UPDATEEFFECTS); + this.awo = null; + } - /** - * This is the general purpose constructor. - */ - public UpdateEffectsMsg(AbstractWorldObject awo) { - super(Protocol.UPDATEEFFECTS); - this.awo = awo; - } + /** + * This is the general purpose constructor. + */ + public UpdateEffectsMsg(AbstractWorldObject awo) { + super(Protocol.UPDATEEFFECTS); + this.awo = awo; + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public UpdateEffectsMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.UPDATEEFFECTS, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public UpdateEffectsMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.UPDATEEFFECTS, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - if (awo == null) { - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - } else { - writer.putInt(awo.getObjectType().ordinal()); - writer.putInt(awo.getObjectUUID()); + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + if (awo == null) { + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + } else { + writer.putInt(awo.getObjectType().ordinal()); + writer.putInt(awo.getObjectUUID()); - ArrayList effects = new ArrayList<>(awo.getEffects().values()); - writer.putInt(effects.size()); - for (Effect effect : effects) - effect.serializeForClientMsg(writer); - } - } + ArrayList effects = new ArrayList<>(awo.getEffects().values()); + writer.putInt(effects.size()); + for (Effect effect : effects) + effect.serializeForClientMsg(writer); + } + } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + } - public AbstractWorldObject getAwo() { - return this.awo; - } + public AbstractWorldObject getAwo() { + return this.awo; + } - public void setAwo(AbstractWorldObject awo) { - this.awo = awo; - } + public void setAwo(AbstractWorldObject awo) { + this.awo = awo; + } } diff --git a/src/engine/net/client/msg/UpdateFriendStatusMessage.java b/src/engine/net/client/msg/UpdateFriendStatusMessage.java index b0f6bfb7..2da0f7c4 100644 --- a/src/engine/net/client/msg/UpdateFriendStatusMessage.java +++ b/src/engine/net/client/msg/UpdateFriendStatusMessage.java @@ -16,63 +16,61 @@ import engine.objects.PlayerCharacter; public class UpdateFriendStatusMessage extends ClientNetMsg { - - public int statusType; - public PlayerCharacter player; - public boolean online = true; + public int statusType; + public PlayerCharacter player; + public boolean online = true; - /** - * This is the general purpose constructor. - */ - public UpdateFriendStatusMessage(PlayerCharacter player) { - super(Protocol.UPDATEFRIENDSTATUS); - this.player = player; - this.online = SessionManager.getPlayerCharacterByID(player.getObjectUUID()) != null ? true : false; - } + /** + * This is the general purpose constructor. + */ + public UpdateFriendStatusMessage(PlayerCharacter player) { + super(Protocol.UPDATEFRIENDSTATUS); + this.player = player; + this.online = SessionManager.getPlayerCharacterByID(player.getObjectUUID()) != null ? true : false; + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public UpdateFriendStatusMessage(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.UPDATEFRIENDSTATUS, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public UpdateFriendStatusMessage(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.UPDATEFRIENDSTATUS, origin, reader); + } - /** - * Copy constructor - */ - public UpdateFriendStatusMessage(UpdateFriendStatusMessage msg) { - super(Protocol.UPDATEFRIENDSTATUS); - } + /** + * Copy constructor + */ + public UpdateFriendStatusMessage(UpdateFriendStatusMessage msg) { + super(Protocol.UPDATEFRIENDSTATUS); + } - - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - //message is serialize only, no need for deserialize. - @Override - protected void _deserialize(ByteBufferReader reader) { - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - this.statusType = reader.getInt(); - } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(GameObjectType.PlayerCharacter.ordinal()); - writer.putInt(player.getObjectUUID()); - writer.putString(player.getCombinedName()); - writer.putInt(online ? 0 : 1); - writer.putInt(player.friendStatus.ordinal()); - } + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + //message is serialize only, no need for deserialize. + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + this.statusType = reader.getInt(); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(GameObjectType.PlayerCharacter.ordinal()); + writer.putInt(player.getObjectUUID()); + writer.putString(player.getCombinedName()); + writer.putInt(online ? 0 : 1); + writer.putInt(player.friendStatus.ordinal()); + } } diff --git a/src/engine/net/client/msg/UpdateGoldMsg.java b/src/engine/net/client/msg/UpdateGoldMsg.java index cb3fc5be..08feaf8a 100644 --- a/src/engine/net/client/msg/UpdateGoldMsg.java +++ b/src/engine/net/client/msg/UpdateGoldMsg.java @@ -28,11 +28,11 @@ import engine.objects.PlayerCharacter; public class UpdateGoldMsg extends ClientNetMsg { - private AbstractWorldObject looter; CharacterItemManager itemManager; - private Item goldInventory; - private Item goldBank; - private int tradeGold = 0; + private AbstractWorldObject looter; + private Item goldInventory; + private Item goldBank; + private int tradeGold = 0; /** @@ -44,74 +44,73 @@ public class UpdateGoldMsg extends ClientNetMsg { } - /** - * This is the general purpose constructor - */ - public UpdateGoldMsg() { - super(Protocol.UPDATEGOLDVALUE); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public UpdateGoldMsg(AbstractConnection origin, - ByteBufferReader reader) { - super(Protocol.UPDATEGOLDVALUE, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - - } + /** + * This is the general purpose constructor + */ + public UpdateGoldMsg() { + super(Protocol.UPDATEGOLDVALUE); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public UpdateGoldMsg(AbstractConnection origin, + ByteBufferReader reader) { + super(Protocol.UPDATEGOLDVALUE, origin, reader); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + + } // Pre-cache and set values so they are available when we // serialize the data. public void configure() { - if (this.looter != null && this.looter.getObjectType() == GameObjectType.PlayerCharacter){ - itemManager = ((PlayerCharacter)looter).getCharItemManager(); + if (this.looter != null && this.looter.getObjectType() == GameObjectType.PlayerCharacter) { + itemManager = ((PlayerCharacter) looter).getCharItemManager(); goldInventory = itemManager.getGoldInventory(); this.tradeGold = itemManager.getGoldTrading(); goldBank = itemManager.getGoldBank(); - }else{ - itemManager = null; - goldInventory = null; - goldBank = null; - } + } else { + itemManager = null; + goldInventory = null; + goldBank = null; + } } - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { - if (looter == null){ + if (looter == null) { writer.putInt(0); writer.putInt(0); - }else{ + } else { writer.putInt(looter.getObjectType().ordinal()); writer.putInt(looter.getObjectUUID()); - } + } if (goldInventory != null && goldInventory.getNumOfItems() - this.tradeGold > 0) { writer.put((byte) 1); - Item.serializeForClientMsgWithoutSlot(goldInventory,writer); + Item.serializeForClientMsgWithoutSlot(goldInventory, writer); } else writer.put((byte) 0); if (goldBank != null && goldBank.getNumOfItems() != 0) { writer.put((byte) 1); - Item.serializeForClientMsgWithoutSlot(goldBank,writer); + Item.serializeForClientMsgWithoutSlot(goldBank, writer); } else writer.put((byte) 0); } diff --git a/src/engine/net/client/msg/UpdateInventoryMsg.java b/src/engine/net/client/msg/UpdateInventoryMsg.java index c9480eb8..5479f14d 100644 --- a/src/engine/net/client/msg/UpdateInventoryMsg.java +++ b/src/engine/net/client/msg/UpdateInventoryMsg.java @@ -20,89 +20,87 @@ import java.util.ArrayList; public class UpdateInventoryMsg extends ClientNetMsg { - private ArrayList toAdd; - private ArrayList bank; - - /** - * This is the general purpose constructor. - */ - public UpdateInventoryMsg(ArrayList inventory,ArrayList bank, Item gold, boolean add) { - super(Protocol.UPDATECLIENTINVENTORIES); - toAdd = inventory; - if (gold != null) - toAdd.add(gold); - - this.bank = bank; - - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public UpdateInventoryMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.UPDATECLIENTINVENTORIES, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - putList(writer, this.toAdd); - if (bank != null) - putList(writer, this.bank); - else - writer.putInt(0); - } - - public static void putList(ByteBufferWriter writer, ArrayList list) { - int indexPosition = writer.position(); - writer.putInt(0); - - int serialized = 0; - - - for (Item item : list) { - if (item.getItemBase().getType().equals(ItemType.GOLD)) { - if (item.getNumOfItems() == 0) - continue; - } - Item.serializeForClientMsgWithoutSlot(item,writer); - ++serialized; - } - - writer.putIntAt(serialized, indexPosition); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - } - - public ArrayList getToAdd() { - return this.toAdd; - } - - - public void setToAdd(ArrayList value) { - this.toAdd = value; - } - - - public void addToInventory(Item value) { - this.toAdd.add(value); - } - - - @Override - protected int getPowerOfTwoBufferSize() { - return 20; - } + private ArrayList toAdd; + private ArrayList bank; + + /** + * This is the general purpose constructor. + */ + public UpdateInventoryMsg(ArrayList inventory, ArrayList bank, Item gold, boolean add) { + super(Protocol.UPDATECLIENTINVENTORIES); + toAdd = inventory; + if (gold != null) + toAdd.add(gold); + + this.bank = bank; + + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public UpdateInventoryMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.UPDATECLIENTINVENTORIES, origin, reader); + } + + public static void putList(ByteBufferWriter writer, ArrayList list) { + int indexPosition = writer.position(); + writer.putInt(0); + + int serialized = 0; + + + for (Item item : list) { + if (item.getItemBase().getType().equals(ItemType.GOLD)) { + if (item.getNumOfItems() == 0) + continue; + } + Item.serializeForClientMsgWithoutSlot(item, writer); + ++serialized; + } + + writer.putIntAt(serialized, indexPosition); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + putList(writer, this.toAdd); + if (bank != null) + putList(writer, this.bank); + else + writer.putInt(0); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + } + + public ArrayList getToAdd() { + return this.toAdd; + } + + + public void setToAdd(ArrayList value) { + this.toAdd = value; + } + + + public void addToInventory(Item value) { + this.toAdd.add(value); + } + + + @Override + protected int getPowerOfTwoBufferSize() { + return 20; + } } diff --git a/src/engine/net/client/msg/UpdateObjectMsg.java b/src/engine/net/client/msg/UpdateObjectMsg.java index 364ac4f4..aae3ea64 100644 --- a/src/engine/net/client/msg/UpdateObjectMsg.java +++ b/src/engine/net/client/msg/UpdateObjectMsg.java @@ -18,119 +18,119 @@ import engine.net.client.Protocol; import engine.objects.*; public class UpdateObjectMsg extends ClientNetMsg { - private int msgType; - private AbstractWorldObject ago; - - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public UpdateObjectMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.UPDATEOBJECT, origin, reader); - } - - public UpdateObjectMsg() { - super(Protocol.UPDATEOBJECT); - } - - public UpdateObjectMsg(AbstractWorldObject ago,int type) { - super(Protocol.UPDATEOBJECT); - if (ago == null) - return; - this.msgType = type; - this.ago = ago; - - - } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { - writer.putInt(this.msgType); - switch (this.msgType){ - case 2: - updateName(writer); - break; - case 3: - updateRank(writer); - break; - case 4: - derank(writer); - break; - case 5: - updateGuild(writer); - break; - - default: - break; - - } - } - - private void updateName(ByteBufferWriter writer){ - - writer.putInt(ago.getObjectType().ordinal()); - writer.putInt(ago.getObjectUUID()); - writer.putString(ago.getName()); - writer.putInt(0); - } - - private void updateRank(ByteBufferWriter writer){ - writer.putInt(ago.getObjectType().ordinal()); - writer.putInt(ago.getObjectUUID()); - writer.putFloat(ago.getHealthMax()); - writer.putFloat(ago.getCurrentHitpoints()); - writer.put((byte)1); - writer.putInt(0); - - } - - private void updateGuild(ByteBufferWriter writer){ - - writer.putInt(ago.getObjectType().ordinal()); - writer.putInt(ago.getObjectUUID()); - - switch (ago.getObjectType()){ - case Building: - Guild guild = ((Building)ago).getGuild(); - GuildTag._serializeForDisplay(guild.getGuildTag(),writer); - GuildTag._serializeForDisplay(guild.getNation().getGuildTag(),writer); - writer.putInt(0); - - break; - default: - break; - } - - - } - - private void derank(ByteBufferWriter writer){ - writer.putInt(0); - writer.putInt(0); - writer.put((byte)0); - writer.putInt(ago.getObjectType().ordinal()); - writer.putInt(ago.getObjectUUID()); - writer.putInt(0); - } - - - - public AbstractGameObject getAgo() { - return ago; - } + private int msgType; + private AbstractWorldObject ago; + + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public UpdateObjectMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.UPDATEOBJECT, origin, reader); + } + + public UpdateObjectMsg() { + super(Protocol.UPDATEOBJECT); + } + + public UpdateObjectMsg(AbstractWorldObject ago, int type) { + super(Protocol.UPDATEOBJECT); + if (ago == null) + return; + this.msgType = type; + this.ago = ago; + + + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { + writer.putInt(this.msgType); + switch (this.msgType) { + case 2: + updateName(writer); + break; + case 3: + updateRank(writer); + break; + case 4: + derank(writer); + break; + case 5: + updateGuild(writer); + break; + + default: + break; + + } + } + + private void updateName(ByteBufferWriter writer) { + + writer.putInt(ago.getObjectType().ordinal()); + writer.putInt(ago.getObjectUUID()); + writer.putString(ago.getName()); + writer.putInt(0); + } + + private void updateRank(ByteBufferWriter writer) { + writer.putInt(ago.getObjectType().ordinal()); + writer.putInt(ago.getObjectUUID()); + writer.putFloat(ago.getHealthMax()); + writer.putFloat(ago.getCurrentHitpoints()); + writer.put((byte) 1); + writer.putInt(0); + + } + + private void updateGuild(ByteBufferWriter writer) { + + writer.putInt(ago.getObjectType().ordinal()); + writer.putInt(ago.getObjectUUID()); + + switch (ago.getObjectType()) { + case Building: + Guild guild = ((Building) ago).getGuild(); + GuildTag._serializeForDisplay(guild.getGuildTag(), writer); + GuildTag._serializeForDisplay(guild.getNation().getGuildTag(), writer); + writer.putInt(0); + + break; + default: + break; + } + + + } + + private void derank(ByteBufferWriter writer) { + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 0); + writer.putInt(ago.getObjectType().ordinal()); + writer.putInt(ago.getObjectUUID()); + writer.putInt(0); + } + + + public AbstractGameObject getAgo() { + return ago; + } } diff --git a/src/engine/net/client/msg/UpdateStateMsg.java b/src/engine/net/client/msg/UpdateStateMsg.java index 184234d9..eaa7e9ed 100644 --- a/src/engine/net/client/msg/UpdateStateMsg.java +++ b/src/engine/net/client/msg/UpdateStateMsg.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -31,192 +28,187 @@ import engine.objects.PlayerCharacter; public class UpdateStateMsg extends ClientNetMsg { - private int charType; - private int charUUID; - private int activity; //1 dead,2 unconscious, 3 Sleeping, 4 resting,5 casting,6 IDLE,7 casting? , 8 nothing 9 unknown, - private int speed; // 1 low, 2 high (walk,run) - private int aware; // 1 low, 2 high (combat off,combat on) - - private int mode; // 0 unknown, 1 water, 2 ground, 3 flight. - private int fighting; // 1 disengaged, 2 engaged. - private int headlights; // LFGroup/LFGuild/Recruiting Icons - - /** - * This is the general purpose constructor. - */ - public UpdateStateMsg() { - super(Protocol.UPDATESTATE); - this.fighting = 1; - this.headlights = 0; - } - - public UpdateStateMsg(AbstractCharacter ac) { - super(Protocol.UPDATESTATE); - this.fighting = 1; - this.headlights = 0; - setPlayer(ac); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public UpdateStateMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.UPDATESTATE, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.charType); - writer.putInt(this.charUUID); - writer.putInt(this.activity); - writer.putInt(this.speed); - writer.putInt(this.aware); - writer.putInt(this.mode); - writer.putInt(this.fighting); - writer.putInt(this.headlights); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.charType = reader.getInt(); - this.charUUID = reader.getInt(); - this.activity = reader.getInt(); - this.speed = reader.getInt(); - this.aware = reader.getInt(); - - this.mode = reader.getInt(); - this.fighting = reader.getInt(); - this.headlights = reader.getInt(); - } - - /** - * Sets this Msg's charUUID, sitStand, walkRun and combatToggle parameters - * based on supplied AbstractCharacter - * - * @param ac - */ - public final void setPlayer(AbstractCharacter ac) { - - PlayerCharacter player; - - this.charType = ac.getObjectType().ordinal(); - this.charUUID = ac.getObjectUUID(); - this.activity = ac.getIsSittingAsInt(); - this.speed = ac.getIsWalkingAsInt(); - this.aware = ac.getIsCombatAsInt(); - - if (ac.getObjectType() == GameObjectType.PlayerCharacter) { - player = (PlayerCharacter)ac; - this.headlights = player.getHeadlightsAsInt(); - } else this.headlights = 0; - - this.mode = ac.getIsFlightAsInt(); - } - - /** - * @return the charUUID - */ - public int getPlayerUUID() { - return charUUID; - } - - /** - * @return the sitStand - */ - public int getActivity() { - return activity; - } - - /** - * @param activity - * the sitStand to set - */ - public void setActivity(int activity) { - this.activity = activity; - } - - /** - * @return the walkRun - */ - public int getSpeed() { - return speed; - } - - /** - * @param speed - * the walkRun to set - */ - public void setSpeed(int speed) { - this.speed = speed; - } - - /** - * @return the combatToggle - */ - public int getAware() { - return aware; - } - - /** - * @param aware - * the combatToggle to set - */ - public void setAware(int aware) { - this.aware = aware; - } - - /** - * @return the unknown01 - */ - public int getMode() { - return mode; - } - - /** - * @param mode - * the unknown01 to set - */ - public void setMode(int mode) { - this.mode = mode; - } - - /** - * @return the unknown02 - */ - public int getFighting() { - return fighting; - } - - /** - * @param fighting - * the unknown02 to set - */ - public void setFighting(int fighting) { - this.fighting = fighting; - } - - /** - * @return the unknown03 - */ - public int getHeadlights() { - return headlights; - } - - /** - * @param headlights - * the headlights to set - */ - public void setHeadlights(int headlights) { - this.headlights = headlights; - } + private int charType; + private int charUUID; + private int activity; //1 dead,2 unconscious, 3 Sleeping, 4 resting,5 casting,6 IDLE,7 casting? , 8 nothing 9 unknown, + private int speed; // 1 low, 2 high (walk,run) + private int aware; // 1 low, 2 high (combat off,combat on) + + private int mode; // 0 unknown, 1 water, 2 ground, 3 flight. + private int fighting; // 1 disengaged, 2 engaged. + private int headlights; // LFGroup/LFGuild/Recruiting Icons + + /** + * This is the general purpose constructor. + */ + public UpdateStateMsg() { + super(Protocol.UPDATESTATE); + this.fighting = 1; + this.headlights = 0; + } + + public UpdateStateMsg(AbstractCharacter ac) { + super(Protocol.UPDATESTATE); + this.fighting = 1; + this.headlights = 0; + setPlayer(ac); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public UpdateStateMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.UPDATESTATE, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.charType); + writer.putInt(this.charUUID); + writer.putInt(this.activity); + writer.putInt(this.speed); + writer.putInt(this.aware); + writer.putInt(this.mode); + writer.putInt(this.fighting); + writer.putInt(this.headlights); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.charType = reader.getInt(); + this.charUUID = reader.getInt(); + this.activity = reader.getInt(); + this.speed = reader.getInt(); + this.aware = reader.getInt(); + + this.mode = reader.getInt(); + this.fighting = reader.getInt(); + this.headlights = reader.getInt(); + } + + /** + * Sets this Msg's charUUID, sitStand, walkRun and combatToggle parameters + * based on supplied AbstractCharacter + * + * @param ac + */ + public final void setPlayer(AbstractCharacter ac) { + + PlayerCharacter player; + + this.charType = ac.getObjectType().ordinal(); + this.charUUID = ac.getObjectUUID(); + this.activity = ac.getIsSittingAsInt(); + this.speed = ac.getIsWalkingAsInt(); + this.aware = ac.getIsCombatAsInt(); + + if (ac.getObjectType() == GameObjectType.PlayerCharacter) { + player = (PlayerCharacter) ac; + this.headlights = player.getHeadlightsAsInt(); + } else + this.headlights = 0; + + this.mode = ac.getIsFlightAsInt(); + } + + /** + * @return the charUUID + */ + public int getPlayerUUID() { + return charUUID; + } + + /** + * @return the sitStand + */ + public int getActivity() { + return activity; + } + + /** + * @param activity the sitStand to set + */ + public void setActivity(int activity) { + this.activity = activity; + } + + /** + * @return the walkRun + */ + public int getSpeed() { + return speed; + } + + /** + * @param speed the walkRun to set + */ + public void setSpeed(int speed) { + this.speed = speed; + } + + /** + * @return the combatToggle + */ + public int getAware() { + return aware; + } + + /** + * @param aware the combatToggle to set + */ + public void setAware(int aware) { + this.aware = aware; + } + + /** + * @return the unknown01 + */ + public int getMode() { + return mode; + } + + /** + * @param mode the unknown01 to set + */ + public void setMode(int mode) { + this.mode = mode; + } + + /** + * @return the unknown02 + */ + public int getFighting() { + return fighting; + } + + /** + * @param fighting the unknown02 to set + */ + public void setFighting(int fighting) { + this.fighting = fighting; + } + + /** + * @return the unknown03 + */ + public int getHeadlights() { + return headlights; + } + + /** + * @param headlights the headlights to set + */ + public void setHeadlights(int headlights) { + this.headlights = headlights; + } } diff --git a/src/engine/net/client/msg/UpdateTradeWindowMsg.java b/src/engine/net/client/msg/UpdateTradeWindowMsg.java index 13c40adc..187993b4 100644 --- a/src/engine/net/client/msg/UpdateTradeWindowMsg.java +++ b/src/engine/net/client/msg/UpdateTradeWindowMsg.java @@ -22,74 +22,74 @@ import java.util.ArrayList; /** * Update trade window message. Send item info to other player. + * * @author Eighty */ public class UpdateTradeWindowMsg extends ClientNetMsg { - PlayerCharacter pc1; - PlayerCharacter pc2; - - /** - * This is the general purpose constructor. - */ - public UpdateTradeWindowMsg(PlayerCharacter pc1, PlayerCharacter pc2) { - super(Protocol.UPDATETRADEWINDOW); - this.pc1 = pc1; - this.pc2 = pc2; - } - - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - - writer.putInt(pc1.getObjectType().ordinal()); - writer.putInt(pc1.getObjectUUID()); - - writer.putInt(pc2.getObjectType().ordinal()); - writer.putInt(pc2.getObjectUUID()); - - - - ArrayList trading1 = new ArrayList<>(); - - for (int itemID : pc1.getCharItemManager().getTrading()){ - Item item = Item.getFromCache(itemID); - if (item == null) - continue; - trading1.add(item); - } - - ArrayList trading2 = new ArrayList<>(); - for (int itemID : pc2.getCharItemManager().getTrading()){ - Item item = Item.getFromCache(itemID); - if (item == null) - continue; - trading2.add(item); - } - Item.putTradingList(pc1,writer, trading1, false, pc1.getObjectUUID(),false,null); - Item.putTradingList(pc2,writer, trading2, false, pc2.getObjectUUID(),false,null); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public UpdateTradeWindowMsg(AbstractConnection origin, - ByteBufferReader reader) { - super(Protocol.UPDATETRADEWINDOW, origin, reader); - } - - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - } - - @Override - protected int getPowerOfTwoBufferSize() { - return 16; - } + PlayerCharacter pc1; + PlayerCharacter pc2; + + /** + * This is the general purpose constructor. + */ + public UpdateTradeWindowMsg(PlayerCharacter pc1, PlayerCharacter pc2) { + super(Protocol.UPDATETRADEWINDOW); + this.pc1 = pc1; + this.pc2 = pc2; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public UpdateTradeWindowMsg(AbstractConnection origin, + ByteBufferReader reader) { + super(Protocol.UPDATETRADEWINDOW, origin, reader); + } + + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + + writer.putInt(pc1.getObjectType().ordinal()); + writer.putInt(pc1.getObjectUUID()); + + writer.putInt(pc2.getObjectType().ordinal()); + writer.putInt(pc2.getObjectUUID()); + + + ArrayList trading1 = new ArrayList<>(); + + for (int itemID : pc1.getCharItemManager().getTrading()) { + Item item = Item.getFromCache(itemID); + if (item == null) + continue; + trading1.add(item); + } + + ArrayList trading2 = new ArrayList<>(); + for (int itemID : pc2.getCharItemManager().getTrading()) { + Item item = Item.getFromCache(itemID); + if (item == null) + continue; + trading2.add(item); + } + Item.putTradingList(pc1, writer, trading1, false, pc1.getObjectUUID(), false, null); + Item.putTradingList(pc2, writer, trading2, false, pc2.getObjectUUID(), false, null); + } + + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + } + + @Override + protected int getPowerOfTwoBufferSize() { + return 16; + } } diff --git a/src/engine/net/client/msg/UpdateVaultMsg.java b/src/engine/net/client/msg/UpdateVaultMsg.java index f06c6b25..0ef84124 100644 --- a/src/engine/net/client/msg/UpdateVaultMsg.java +++ b/src/engine/net/client/msg/UpdateVaultMsg.java @@ -10,7 +10,6 @@ package engine.net.client.msg; - import engine.exception.SerializationException; import engine.net.AbstractConnection; import engine.net.ByteBufferReader; @@ -20,50 +19,51 @@ import engine.objects.Account; /** * Vault inventory contents + * * @author Eighty */ public class UpdateVaultMsg extends ClientNetMsg { - - private int accountType; - private int accountID; - - /** - * This is the general purpose constructor. - */ - public UpdateVaultMsg(Account account) { - super(Protocol.CLIENTUPDATEVAULT); - this.accountType = account.getObjectType().ordinal(); - this.accountID = account.getObjectUUID(); - } + private int accountType; + private int accountID; + + + /** + * This is the general purpose constructor. + */ + public UpdateVaultMsg(Account account) { + super(Protocol.CLIENTUPDATEVAULT); + this.accountType = account.getObjectType().ordinal(); + this.accountID = account.getObjectUUID(); + } - /** - * Serializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - writer.putInt(accountType); - writer.putInt(accountID); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public UpdateVaultMsg(AbstractConnection origin, + ByteBufferReader reader) { + super(Protocol.CLIENTUPDATEVAULT, origin, reader); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public UpdateVaultMsg(AbstractConnection origin, - ByteBufferReader reader) { - super(Protocol.CLIENTUPDATEVAULT, origin, reader); - } + /** + * Serializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + writer.putInt(accountType); + writer.putInt(accountID); + } - /** - * Deserializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - } + /** + * Deserializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + } - @Override - protected int getPowerOfTwoBufferSize() { - return 17; - } + @Override + protected int getPowerOfTwoBufferSize() { + return 17; + } } diff --git a/src/engine/net/client/msg/UpgradeAssetMessage.java b/src/engine/net/client/msg/UpgradeAssetMessage.java index 1091944b..d0366928 100644 --- a/src/engine/net/client/msg/UpgradeAssetMessage.java +++ b/src/engine/net/client/msg/UpgradeAssetMessage.java @@ -19,74 +19,74 @@ import engine.net.client.Protocol; public class UpgradeAssetMessage extends ClientNetMsg { - private int unknown01; - private int unknown02; - private int buildingUUID; + private int unknown01; + private int unknown02; + private int buildingUUID; /** - * This is the general purpose constructor. - */ - public UpgradeAssetMessage() { - super(Protocol.UPGRADEASSET); - - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public UpgradeAssetMessage(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.UPGRADEASSET, origin, reader); - } - - /** - * @see AbstractNetMsg#getPowerOfTwoBufferSize() - */ - @Override - protected int getPowerOfTwoBufferSize() { - //Larger size for historically larger opcodes - return (16); // 2^16 == 64k - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - reader.getInt(); // Object Type Padding - this.buildingUUID = reader.getInt(); - } - - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - public int getUnknown01() { - return unknown01; - } - - public void setUnknown02(int unknown02) { - this.unknown02 = unknown02; - } - - public int getUnknown02() { - return unknown02; - } - - public int getBuildingUUID() { - return buildingUUID; - } + * This is the general purpose constructor. + */ + public UpgradeAssetMessage() { + super(Protocol.UPGRADEASSET); + + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public UpgradeAssetMessage(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.UPGRADEASSET, origin, reader); + } + + /** + * @see AbstractNetMsg#getPowerOfTwoBufferSize() + */ + @Override + protected int getPowerOfTwoBufferSize() { + //Larger size for historically larger opcodes + return (16); // 2^16 == 64k + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + reader.getInt(); // Object Type Padding + this.buildingUUID = reader.getInt(); + } + + public int getUnknown01() { + return unknown01; + } + + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + public int getUnknown02() { + return unknown02; + } + + public void setUnknown02(int unknown02) { + this.unknown02 = unknown02; + } + + public int getBuildingUUID() { + return buildingUUID; + } } diff --git a/src/engine/net/client/msg/UseCharterMsg.java b/src/engine/net/client/msg/UseCharterMsg.java index 4387fedd..e31d2522 100644 --- a/src/engine/net/client/msg/UseCharterMsg.java +++ b/src/engine/net/client/msg/UseCharterMsg.java @@ -20,44 +20,44 @@ import engine.objects.PlayerCharacter; public class UseCharterMsg extends ClientNetMsg { - private int unknown01; - private int unknown02; - private int unknown03; - private String type; - private int unknown04; - private int unknown05; - private int unknown06; - private boolean close = false; - private PlayerCharacter player; + private int unknown01; + private int unknown02; + private int unknown03; + private String type; + private int unknown04; + private int unknown05; + private int unknown06; + private boolean close = false; + private PlayerCharacter player; private int charterUUID; - /** - * This is the general purpose constructor. - */ - public UseCharterMsg() { - super(Protocol.ACTIVATECHARTER); - } - - public UseCharterMsg(PlayerCharacter player, boolean close) { - super(Protocol.ACTIVATECHARTER); - this.close = close; - this.player = player; - - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public UseCharterMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ACTIVATECHARTER, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ + /** + * This is the general purpose constructor. + */ + public UseCharterMsg() { + super(Protocol.ACTIVATECHARTER); + } + + public UseCharterMsg(PlayerCharacter player, boolean close) { + super(Protocol.ACTIVATECHARTER); + this.close = close; + this.player = player; + + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public UseCharterMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ACTIVATECHARTER, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ public void configure() { @@ -71,35 +71,35 @@ public class UseCharterMsg extends ClientNetMsg { } } - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - writer.putInt(this.unknown03); - writer.putString(this.type); - writer.putInt(this.unknown04); - writer.putInt(this.unknown05); - writer.putInt(this.unknown06); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - this.unknown03 = reader.getInt(); - this.type = reader.getString(); - this.unknown04 = reader.getInt(); - this.unknown05 = reader.getInt(); - this.unknown06 = reader.getInt(); - } - - /** - * @return the unknown01 - */ - public void setUnknown02(int unknown02) { - this.unknown02 = unknown02; - } + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + writer.putInt(this.unknown03); + writer.putString(this.type); + writer.putInt(this.unknown04); + writer.putInt(this.unknown05); + writer.putInt(this.unknown06); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + this.unknown03 = reader.getInt(); + this.type = reader.getString(); + this.unknown04 = reader.getInt(); + this.unknown05 = reader.getInt(); + this.unknown06 = reader.getInt(); + } + + /** + * @return the unknown01 + */ + public void setUnknown02(int unknown02) { + this.unknown02 = unknown02; + } } diff --git a/src/engine/net/client/msg/VendorDialogMsg.java b/src/engine/net/client/msg/VendorDialogMsg.java index 2c3b80cc..1ced6074 100644 --- a/src/engine/net/client/msg/VendorDialogMsg.java +++ b/src/engine/net/client/msg/VendorDialogMsg.java @@ -28,878 +28,868 @@ import java.util.concurrent.ThreadLocalRandom; public class VendorDialogMsg extends ClientNetMsg { - public static final int MSG_TYPE_VENDOR = 0; - public static final int MSG_TYPE_TRAINER = 1; - public static int cnt = 1; - private int messageType; - private String language; - private int vendorObjectType; - private int vendorObjectID; - private int unknown01; - private int unknown02; - private int unknown03; - private int unknown04; - private String dialogType = "TrainerDialog"; - private String intro = "FighterIntro"; - private String introCode = " [ FighterIntro ] "; - private String merchantCode = " [ Merchant options ] "; - private int menuType = 1; // 0: close, 1: normal, 2: train, 3: untrain - private VendorDialog vd; - - /** - * This is the general purpose constructor. - */ - public VendorDialogMsg(int messageType, int vendorObjectType, int vendorObjectID, String dialogType, String intro, int menuType) { - super(Protocol.VENDORDIALOG); - this.messageType = messageType; - this.vendorObjectType = vendorObjectType; - this.vendorObjectID = vendorObjectID; - this.dialogType = dialogType; - this.intro = intro; - this.introCode = " [ " + intro + " ] "; - this.menuType = menuType; - } - - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public VendorDialogMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.VENDORDIALOG, origin, reader); - } - - public static void replyDialog(VendorDialogMsg msg, ClientConnection origin) throws MsgSendException { - - PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter(origin); - - if (playerCharacter == null) - return; - - if (playerCharacter.getTimeStamp("lastvendorwindow") > System.currentTimeMillis()) { - return; - } - - // Get NPC that player is talking to - NPC npc = NPC.getFromCache(msg.vendorObjectID); - int npcClassID; - - if (npc == null) - return; - - // test within talking range - - if (playerCharacter.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) { - ErrorPopupMsg.sendErrorPopup(playerCharacter, 14); - return; - } - - // Restrict disc trainers to only characters who have - // tht disc applied. - - npcClassID = npc.getContract().getClassID(); - - if (npc.getContract() != null && - ApplyRuneMsg.isDiscipline(npcClassID)) { - - if (playerCharacter.getRune(npcClassID) == null) { - ErrorPopupMsg.sendErrorPopup(playerCharacter, 49); - return; - } - - } - playerCharacter.setLastNPCDialog(npc); - - VendorDialog vd = null; - Contract contract = npc.getContract(); - - if (contract == null) - vd = VendorDialog.getHostileVendorDialog(); - else if (npc.getBuilding() != null) { - if (BuildingManager.IsPlayerHostile(npc.getBuilding(), playerCharacter)) - vd = VendorDialog.getHostileVendorDialog(); - else vd = contract.getVendorDialog(); - } - else - vd = contract.getVendorDialog(); - if (vd == null) - vd = VendorDialog.getHostileVendorDialog(); - - if (msg.messageType == 1 || msg.unknown03 == vd.getObjectUUID()) { - msg.updateMessage(3, vd); - } - else { - if (VendorDialogMsg.handleSpecialCase(msg, npc, playerCharacter, vd, origin)) - return; - - vd = VendorDialog.getVendorDialog(msg.unknown03); - msg.updateMessage(3, vd); - } - - Dispatch dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - } - - // protected void serializeMerchantMenu(ByteBufferWriter writer) { - // writer.putInt(2); - // writer.putInt(14); - // writer.putInt(0); - // writer.putInt(0); - // writer.put((byte) 0); - // writer.put((byte) 1); - // writer.putString(" [ Merchant options ] "); - // for (int i = 0; i < 4; i++) - // writer.putInt(0); - // writer.putInt(10); - // writer.putInt(0); - // writer.putInt(0); - // writer.put((byte) 0); - // writer.put((byte) 1); - // writer.putString("Done"); - // for (int i = 0; i < 8; i++) - // writer.putInt(0); - // } - - // protected void serializeForTrain(ByteBufferWriter writer, boolean train) { - // writer.putInt(0); - // writer.putInt(0x364AF0D0); // 0x325695C0 - // writer.putInt(this.unknown03); - // writer.putInt(1); - // writer.put((byte) 0); - // writer.putInt(this.unknown03); - // writer.put((byte) 0); - // writer.putInt(0); - // writer.putInt(0); - // writer.putInt(2); // 2 - // if (train) - // writer.putInt(3); // 3=buy/sell/trade, 4=untrain, 5 closes - // else - // writer.putInt(4); //refine - // writer.putInt(10); // 10 - // writer.putInt(0); - // writer.putInt(0); - // writer.putInt(0); - // } - - // protected void serializeClose(ByteBufferWriter writer) { - // writer.putInt(0); - // writer.putInt(0x364AF0D0); // 0x325695C0 - // writer.putInt(this.unknown03); - // writer.putInt(1); - // writer.put((byte) 0); - // writer.putInt(this.unknown03); - // writer.put((byte) 0); - // writer.putInt(0); - // writer.putInt(0); - // writer.putInt(2); // 2 - // writer.putInt(5); // 3=buy/sell/trade, 4=untrain, 5 closes - // writer.putInt(10); // 10 - // writer.putInt(0); - // writer.putInt(0); - // writer.putInt(0); - // } - - // Handles special case menu selections, such as promote, train, ect. - private static boolean handleSpecialCase(VendorDialogMsg msg, NPC npc, PlayerCharacter playerCharacter, VendorDialog vd, ClientConnection origin) - throws MsgSendException { - - Dispatch dispatch; - int menuID = msg.unknown03; // aka menuoptions.optionID - Vector3fImmutable loc; - - switch (menuID) { - case 0: // Close Dialog - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 180: // Promote to class - VendorDialogMsg.promote(playerCharacter, npc); - msg.updateMessage(4, 0); // <-0 closes dialog - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 1000: // TrainSkill skills and powers - msg.updateMessage(4, 2); // <-2 sends trainer screen - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 1001: // Open Bank - getBank(playerCharacter, npc, origin); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 1002: // Open Vault - getVault(playerCharacter, npc, origin); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 1003: //Refine - msg.updateMessage(4, 3); // <-3 sends refine screen - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - - // Mainland Teleports - case 100011: // teleport me to Aeldreth - City city = City.getCity(25); - if (city != null) - handleTeleport(playerCharacter, city.getLoc(), 10, 75, false); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 100012: // teleport me to SDR - city = City.getCity(24); - if (city != null) - handleTeleport(playerCharacter, city.getLoc(), 10, 75, true); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 100013: // teleport me to Erkeng Hold - city = City.getCity(26); - if (city != null) - handleTeleport(playerCharacter, city.getLoc(), 10, 75, true); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 100014: // teleport me to Khan - city = City.getCity(36); - if (city != null) - handleTeleport(playerCharacter, city.getLoc(), 1, 75, true); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - - case 100015: // teleport me to Maelstrom - loc = new Vector3fImmutable(105100f, 40f, -25650f); - handleTeleport(playerCharacter, loc, 10, 75, false); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 100016: // teleport me to Oblivion - loc = new Vector3fImmutable(108921f, 167f, -51590f); - handleTeleport(playerCharacter, loc, 10, 75, false); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 100017: // teleport me to Vander's Doom - loc = new Vector3fImmutable(42033f, 46f, -54471f); - handleTeleport(playerCharacter, loc, 10, 75, false); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 100018: // teleport me to The Sinking Isle - loc = new Vector3fImmutable(67177f, 36f, -31940f); - handleTeleport(playerCharacter, loc, 10, 75, false); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - - // MainLand Repledges - case 100030: // repledge me to Aeldreth - city = City.getCity(25); - if (city != null) - handleRepledge(playerCharacter, city, 10, 55, false); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 100031: // repledge me to Sea Dog's Rest - city = City.getCity(24); - if (city != null) - handleRepledge(playerCharacter, city, 10, 75, true); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 100032: // repledge me to Erkeng Hold - city = City.getCity(26); - if (city != null) - handleRepledge(playerCharacter, city, 10, 55, false); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 100033: // repledge me to Khan\'Of Srekel - city = City.getCity(36); - if (city != null) - handleRepledge(playerCharacter, city, 1, 75, true); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 100035: // repledge me to Starkholm - city = City.getCity(27); - if (city != null) - handleRepledge(playerCharacter, city, 1, 20, false); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - - // Noob Isle Teleports - case 100040: // teleport me to Starkholm - city = City.getCity(27); - if (city != null) - handleTeleport(playerCharacter, city.getLoc(), 1, 20, true); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 100041: // teleport me to All-Father's Rest - city = City.getCity(28); - if (city != null) - handleTeleport(playerCharacter, city.getLoc(), 1, 20, true); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 100042: // teleport me to Hengest - city = City.getCity(33); - if (city != null) - handleTeleport(playerCharacter, city.getLoc(), 1, 20, true); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 100043: // teleport me to Hrimdal - city = City.getCity(30); - if (city != null) - handleTeleport(playerCharacter, city.getLoc(), 1, 20, true); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 100044: // teleport me to Hothor's Doom - city = City.getCity(29); - if (city != null) - handleTeleport(playerCharacter, city.getLoc(), 1, 20, true); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 100045: // teleport me to Scraefahl - city = City.getCity(32); - if (city != null) - handleTeleport(playerCharacter, city.getLoc(), 1, 20, false); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - case 100046: // teleport me to Valkirch - city = City.getCity(31); - if (city != null) - handleTeleport(playerCharacter, city.getLoc(), 1, 20, true); - msg.updateMessage(4, 0); - dispatch = Dispatch.borrow(playerCharacter, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - - - - default: - } - return false; - } - - private static boolean finishMessage(VendorDialogMsg msg, ClientConnection origin) throws MsgSendException { - msg.updateMessage(4, 0); - Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - } - - private static void handleTeleport(PlayerCharacter pc, Vector3fImmutable loc, int minLevel, int maxLevel, boolean useSquare) { - if (pc == null) - return; - - int level = pc.getLevel(); - if (level >= minLevel && level <= maxLevel) { - if (useSquare) - loc = getSquare(loc); - pc.teleport(loc); - pc.setSafeMode(); - // PowersManager.applyPower(pc, pc, new Vector3f(0f, - // 0f, 0f), -1661758934, 40, false); - } - else { - if (level < minLevel) - ErrorPopupMsg.sendErrorPopup(pc, 74); - else - ErrorPopupMsg.sendErrorPopup(pc, 139); - - } - } - - private static void handleRepledge(PlayerCharacter pc, City city, int minLevel, int maxLevel, boolean useSquare) { - if (pc == null || city == null) - return; - - Vector3fImmutable loc = city.getLoc(); - int level = pc.getLevel(); - if (level >= minLevel && level <= maxLevel) { - // set guild - Guild guild = city.getGuild(); - if (guild != null) { - // teleport player - if (useSquare) - loc = getSquare(loc); - pc.teleport(loc); - pc.setSafeMode(); - // PowersManager.applyPower(pc, pc, new - // Vector3f(0f, 0f, 0f), -1661758934, 40, false); - - // join guild - GuildManager.joinGuild(pc, guild, GuildHistoryType.JOIN); - - pc.resetGuildStatuses(); - - if (guild.isNPCGuild()) - pc.setFullMember(true); - - if (useSquare) - loc = loc.add(30, 0, 0); - pc.setBindLoc(loc); - } - else { - // guild not found, just teleport - if (useSquare) - loc = getSquare(loc); - pc.teleport(loc); - pc.setSafeMode(); - // PowersManager.applyPower(pc, pc, new - // Vector3f(0f, 0f, 0f), -1661758934, 50, false); - } - } - else { - - if (level < minLevel) - ErrorPopupMsg.sendErrorPopup(pc, 74); - else - ErrorPopupMsg.sendErrorPopup(pc, 139); - } - } - - // randomly place around a tol using a square (+- 30 units in x and z - // direction) - public static Vector3fImmutable getSquare(Vector3fImmutable cityLoc) { - Vector3fImmutable loc = cityLoc; - // get direction - int roll = ThreadLocalRandom.current().nextInt(4); - if (roll == 0) { // north - loc = loc.add((ThreadLocalRandom.current().nextInt(60) - 30), 0, -30); - } - else if (roll == 1) { // south - loc = loc.add((ThreadLocalRandom.current().nextInt(60) - 30), 0, 30); - } - else if (roll == 2) { // east - loc = loc.add(30, 0, (ThreadLocalRandom.current().nextInt(60) - 30)); - } - else { // west - loc = loc.add(-30, 0, (ThreadLocalRandom.current().nextInt(60) - 30)); - } - - // Make sure no one gets stuck in the tree. - - if (loc.distanceSquared2D(cityLoc) < 250) { - loc = cityLoc; - loc = loc.add(30, 0, 0); - } - - return loc; - } - - // Handle promotion - private static void promote(PlayerCharacter pc, NPC npc) { - - if (npc == null || pc == null) - return; - - // test level 10 - if (pc.getLevel() < 10) { - // TODO send client promotion error - while (pc.getLevel() > 65) - pc.setLevel((short) 65); - return; - } - - // verify player not already promoted - if (pc.getPromotionClass() != null) { - // TODO send client promotion error - return; - } - - // Get promotion class for npc - Contract contract = npc.getContract(); - if (contract == null) - return; - int promoID = contract.getPromotionClass(); - if (promoID == 0) - return; - PromotionClass promo = DbManager.PromotionQueries.GET_PROMOTION_CLASS(promoID); - if (promo == null) { - // TODO log error here - return; - } - - // verify race valid for profession - Race race = pc.getRace(); - if (race == null || !promo.isAllowedRune(race.getToken())) { - // TODO send client promotion error - return; - } - - // verify baseclass valid for profession - BaseClass bc = pc.getBaseClass(); - if (bc == null || !promo.isAllowedRune(bc.getToken())) { - // TODO send client promotion error - return; - } - - // verify gender - if (promoID == 2511 && pc.isMale()) // Fury - return; - if (promoID == 2512 && pc.isMale()) // Huntress - return; - if (promoID == 2517 && !pc.isMale()) // Warlock - return; - - // Everything valid. Let's promote - pc.setPromotionClass(promo.getObjectUUID()); - - //pc.setLevel((short) 65); - - - promo = pc.getPromotionClass(); - if (promo == null) { - // TODO log error here - return; - } - - // recalculate all bonuses/formulas/skills/powers - pc.recalculate(); - - // send the rune application to the clients - ApplyRuneMsg arm = new ApplyRuneMsg(pc.getObjectType().ordinal(), pc.getObjectUUID(), promo.getObjectUUID(), promo.getObjectType().ordinal(), promo - .getObjectUUID(), true); - DispatchMessage.dispatchMsgToInterestArea(pc, arm, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - - - } - - /** - * Load and send vault to player. This is public only so a DevCmd can hook - * into it. - * - * @param playerCharacter - Player Character requesting vault - * @param target - NPC vaultkeeper - * @param cc - Client Connection - */ - public static void getVault(PlayerCharacter playerCharacter, NPC target, ClientConnection cc) { - if (playerCharacter == null || cc == null || target == null) - return; - - Account ac = playerCharacter.getAccount(); - if (ac == null) - return; - - CharacterItemManager itemManager = playerCharacter.getCharItemManager(); - if (itemManager == null) - return; - - // TODO uncomment this block after we determine when we - // setBankOpen(false) - /* - * // cannot have bank and vault open at the same time if - * (itemManager.isBankOpen()) return; - */ - - if (itemManager.getTradingWith() != null) { - return; - // TODO close trade window here - simple once this is moved to WS - } - - itemManager.setVaultOpen(true); - - // TODO for public test - remove this afterwards - // DevCmd.fillVault(pc, itemManager); - - // TODO When do we setVaultOpen(false)? I don't think the client sends a - // "CloseVault" message. - - OpenVaultMsg openVaultMsg = new OpenVaultMsg(playerCharacter, target); - Dispatch dispatch = Dispatch.borrow(playerCharacter, openVaultMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - ShowVaultInventoryMsg showVaultInventoryMsg = new ShowVaultInventoryMsg(playerCharacter, ac, target); // 37?? - dispatch = Dispatch.borrow(playerCharacter, showVaultInventoryMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - // All recordings have "open - show - open." - // Seems to work fine with just "show - open" as well. - - } - - /** - * Load and send Bank to player. This is public only so a DevCmd can hook - * into it. - * - * @param playerCharacter - Player Character requesting vault - * @param target - NPC vaultkeeper - * @param cc - Client Connection - */ - public static void getBank(PlayerCharacter playerCharacter, NPC target, ClientConnection cc) { - - if (playerCharacter == null) - return; - - if (cc == null) - return; - - CharacterItemManager itemManager = playerCharacter.getCharItemManager(); - - if (itemManager == null) - return; - - // TODO uncomment this block after we determine when we - // setVaultOpen(false) - /* - * // cannot have bank and vault open at the same time if - * (itemManager.isVaultOpen()) return; - */ - - if (itemManager.getTradingWith() != null) { - return; - // TODO close trade window here - simple once this is moved to WS - } - - itemManager.setBankOpen(true); - // TODO When do we setBankOpen(false)? I don't think the client sends a - // "CloseBank" message. - - AckBankWindowOpenedMsg ackBankWindowOpenedMsg = new AckBankWindowOpenedMsg(playerCharacter, 0L, 0L); - - Dispatch dispatch = Dispatch.borrow(playerCharacter, ackBankWindowOpenedMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - ReqBankInventoryMsg reqBankInventoryMsg = new ReqBankInventoryMsg(playerCharacter, 0L); - dispatch = Dispatch.borrow(playerCharacter, reqBankInventoryMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - ShowBankInventoryMsg showBankInventoryMsg = new ShowBankInventoryMsg(playerCharacter, 0L); - dispatch = Dispatch.borrow(playerCharacter, showBankInventoryMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - - writer.putInt(this.messageType); - for (int i = 0; i < 3; i++) - writer.putInt(0); - if (messageType == 1) - writer.putString(this.language); - else - writer.putString(""); - writer.putInt(this.vendorObjectType); - writer.putInt(this.vendorObjectID); - - for (int i = 0; i < 3; i++) - writer.putInt(0); - writer.put((byte) 0); - writer.put((byte) 0); - if (this.messageType == 1) { - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - } - else if (this.messageType == 4) { - writer.putInt(0); - writer.putInt(0x364AF0D0); // 0x325695C0 - if (this.vd != null) - writer.putInt(vd.getObjectUUID()); - else - writer.putInt(this.unknown03); - writer.putInt(1); - writer.put((byte) 0); - writer.putInt(this.unknown03); - writer.put((byte) 0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(2); // 2 - if (menuType == 2) - writer.putInt(3); - else if (menuType == 3) - writer.putInt(4); - else - writer.putInt(5); - // writer.putInt(3); // 3=buy/sell/trade, 4=untrain, 5 closes - writer.putInt(10); // 10 - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - return; - - } - writer.putInt(15); - writer.putInt(5); - if (this.vd != null) - writer.putInt(vd.getObjectUUID()); - else - writer.putInt(this.unknown03); - - //filename datablock - writer.putInt(1); - writer.put((byte) 1); - writer.putInt(this.unknown03); - writer.put((byte) 1); - writer.putString(vd.getDialogType()); - writer.putInt(0); - writer.putInt(1); - writer.putInt(4); - writer.putInt(0); - writer.put((byte) 1); - - //vendor dialog datablock - writer.putString(vd.getDialogType()); - writer.putString(vd.getIntro()); - writer.put((byte) 0); - - //menu options datablock - writer.putInt(1); - writer.putString(" [ " + vd.getIntro() + " ] "); - ArrayList options = vd.getOptions(); - writer.putInt((options.size() + 1)); - for (MenuOption option : options) { - if (option.getMessage().equals(" [ Merchant options ] ")) { - writer.putInt(16); - } - else { - writer.putInt(14); - } - writer.put((byte) 0); - writer.putInt(0); - writer.put((byte) 0); - writer.putInt(1); - writer.putString(option.getMessage()); - writer.putInt(option.getOptionID()); - for (int i = 0; i < 3; i++) - writer.putInt(0); - } - writer.putInt(10); - writer.put((byte) 0); - writer.putInt(0); - writer.put((byte) 0); - writer.putInt(1); - writer.putString("Done"); - for (int i = 0; i < 4; i++) - writer.putInt(0); - // writer.putInt(1); - // writer.putInt(2); - for (int i = 0; i < 4; i++) - writer.putInt(0); - } - - /** - * Deserializes the subclass specific items from the supplied - * ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.messageType = reader.getInt(); - for (int i = 0; i < 3; i++) - reader.getInt(); - this.language = reader.getString(); - this.vendorObjectType = reader.getInt(); - this.vendorObjectID = reader.getInt(); - for (int i = 0; i < 3; i++) - reader.getInt(); - reader.get(); - reader.get(); - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - this.unknown03 = reader.getInt(); - reader.getInt(); - // if (this.messageType == 1) { - reader.get(); - reader.getInt(); - reader.get(); - reader.getInt(); - reader.getShort(); - // return; - // } - // reader.get(); - // this.unknown04 = reader.getInt(); - // reader.get(); - // TODO more message to go here - } - - public int getMessageType() { - return this.messageType; - } - - public void setMessageType(int value) { - this.messageType = value; - } - - public int getVendorObjectType() { - return this.vendorObjectType; - } - - public int getVendorObjectID() { - return this.vendorObjectID; - } - - public int getUnknown01() { - return this.unknown01; - } - - public int getUnknown02() { - return this.unknown02; - } - - public int getUnknown03() { - return this.unknown03; - } - - public void setUnknown03(int value) { - this.unknown03 = value; - } - - public void setLanguage(String value) { - this.language = value; - } - - public void updateMessage(int messageType, int menuType) { - this.messageType = messageType; - this.menuType = menuType; - } - - public void updateMessage(int messageType, String dialogType, String intro, int menuType) { - this.messageType = messageType; - this.dialogType = dialogType; - this.intro = intro; - this.introCode = " [ " + this.intro + " ] "; - this.menuType = menuType; - } - - public void updateMessage(int messageType, VendorDialog vd) { - this.messageType = messageType; - this.vd = vd; - } + public static final int MSG_TYPE_VENDOR = 0; + public static final int MSG_TYPE_TRAINER = 1; + public static int cnt = 1; + private int messageType; + private String language; + private int vendorObjectType; + private int vendorObjectID; + private int unknown01; + private int unknown02; + private int unknown03; + private int unknown04; + private String dialogType = "TrainerDialog"; + private String intro = "FighterIntro"; + private String introCode = " [ FighterIntro ] "; + private String merchantCode = " [ Merchant options ] "; + private int menuType = 1; // 0: close, 1: normal, 2: train, 3: untrain + private VendorDialog vd; + + /** + * This is the general purpose constructor. + */ + public VendorDialogMsg(int messageType, int vendorObjectType, int vendorObjectID, String dialogType, String intro, int menuType) { + super(Protocol.VENDORDIALOG); + this.messageType = messageType; + this.vendorObjectType = vendorObjectType; + this.vendorObjectID = vendorObjectID; + this.dialogType = dialogType; + this.intro = intro; + this.introCode = " [ " + intro + " ] "; + this.menuType = menuType; + } + + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public VendorDialogMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.VENDORDIALOG, origin, reader); + } + + public static void replyDialog(VendorDialogMsg msg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter(origin); + + if (playerCharacter == null) + return; + + if (playerCharacter.getTimeStamp("lastvendorwindow") > System.currentTimeMillis()) { + return; + } + + // Get NPC that player is talking to + NPC npc = NPC.getFromCache(msg.vendorObjectID); + int npcClassID; + + if (npc == null) + return; + + // test within talking range + + if (playerCharacter.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) { + ErrorPopupMsg.sendErrorPopup(playerCharacter, 14); + return; + } + + // Restrict disc trainers to only characters who have + // tht disc applied. + + npcClassID = npc.getContract().getClassID(); + + if (npc.getContract() != null && + ApplyRuneMsg.isDiscipline(npcClassID)) { + + if (playerCharacter.getRune(npcClassID) == null) { + ErrorPopupMsg.sendErrorPopup(playerCharacter, 49); + return; + } + + } + playerCharacter.setLastNPCDialog(npc); + + VendorDialog vd = null; + Contract contract = npc.getContract(); + + if (contract == null) + vd = VendorDialog.getHostileVendorDialog(); + else if (npc.getBuilding() != null) { + if (BuildingManager.IsPlayerHostile(npc.getBuilding(), playerCharacter)) + vd = VendorDialog.getHostileVendorDialog(); + else + vd = contract.getVendorDialog(); + } else + vd = contract.getVendorDialog(); + if (vd == null) + vd = VendorDialog.getHostileVendorDialog(); + + if (msg.messageType == 1 || msg.unknown03 == vd.getObjectUUID()) { + msg.updateMessage(3, vd); + } else { + if (VendorDialogMsg.handleSpecialCase(msg, npc, playerCharacter, vd, origin)) + return; + + vd = VendorDialog.getVendorDialog(msg.unknown03); + msg.updateMessage(3, vd); + } + + Dispatch dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + } + + // protected void serializeMerchantMenu(ByteBufferWriter writer) { + // writer.putInt(2); + // writer.putInt(14); + // writer.putInt(0); + // writer.putInt(0); + // writer.put((byte) 0); + // writer.put((byte) 1); + // writer.putString(" [ Merchant options ] "); + // for (int i = 0; i < 4; i++) + // writer.putInt(0); + // writer.putInt(10); + // writer.putInt(0); + // writer.putInt(0); + // writer.put((byte) 0); + // writer.put((byte) 1); + // writer.putString("Done"); + // for (int i = 0; i < 8; i++) + // writer.putInt(0); + // } + + // protected void serializeForTrain(ByteBufferWriter writer, boolean train) { + // writer.putInt(0); + // writer.putInt(0x364AF0D0); // 0x325695C0 + // writer.putInt(this.unknown03); + // writer.putInt(1); + // writer.put((byte) 0); + // writer.putInt(this.unknown03); + // writer.put((byte) 0); + // writer.putInt(0); + // writer.putInt(0); + // writer.putInt(2); // 2 + // if (train) + // writer.putInt(3); // 3=buy/sell/trade, 4=untrain, 5 closes + // else + // writer.putInt(4); //refine + // writer.putInt(10); // 10 + // writer.putInt(0); + // writer.putInt(0); + // writer.putInt(0); + // } + + // protected void serializeClose(ByteBufferWriter writer) { + // writer.putInt(0); + // writer.putInt(0x364AF0D0); // 0x325695C0 + // writer.putInt(this.unknown03); + // writer.putInt(1); + // writer.put((byte) 0); + // writer.putInt(this.unknown03); + // writer.put((byte) 0); + // writer.putInt(0); + // writer.putInt(0); + // writer.putInt(2); // 2 + // writer.putInt(5); // 3=buy/sell/trade, 4=untrain, 5 closes + // writer.putInt(10); // 10 + // writer.putInt(0); + // writer.putInt(0); + // writer.putInt(0); + // } + + // Handles special case menu selections, such as promote, train, ect. + private static boolean handleSpecialCase(VendorDialogMsg msg, NPC npc, PlayerCharacter playerCharacter, VendorDialog vd, ClientConnection origin) + throws MsgSendException { + + Dispatch dispatch; + int menuID = msg.unknown03; // aka menuoptions.optionID + Vector3fImmutable loc; + + switch (menuID) { + case 0: // Close Dialog + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 180: // Promote to class + VendorDialogMsg.promote(playerCharacter, npc); + msg.updateMessage(4, 0); // <-0 closes dialog + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 1000: // TrainSkill skills and powers + msg.updateMessage(4, 2); // <-2 sends trainer screen + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 1001: // Open Bank + getBank(playerCharacter, npc, origin); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 1002: // Open Vault + getVault(playerCharacter, npc, origin); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 1003: //Refine + msg.updateMessage(4, 3); // <-3 sends refine screen + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + + // Mainland Teleports + case 100011: // teleport me to Aeldreth + City city = City.getCity(25); + if (city != null) + handleTeleport(playerCharacter, city.getLoc(), 10, 75, false); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 100012: // teleport me to SDR + city = City.getCity(24); + if (city != null) + handleTeleport(playerCharacter, city.getLoc(), 10, 75, true); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 100013: // teleport me to Erkeng Hold + city = City.getCity(26); + if (city != null) + handleTeleport(playerCharacter, city.getLoc(), 10, 75, true); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 100014: // teleport me to Khan + city = City.getCity(36); + if (city != null) + handleTeleport(playerCharacter, city.getLoc(), 1, 75, true); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + + case 100015: // teleport me to Maelstrom + loc = new Vector3fImmutable(105100f, 40f, -25650f); + handleTeleport(playerCharacter, loc, 10, 75, false); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 100016: // teleport me to Oblivion + loc = new Vector3fImmutable(108921f, 167f, -51590f); + handleTeleport(playerCharacter, loc, 10, 75, false); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 100017: // teleport me to Vander's Doom + loc = new Vector3fImmutable(42033f, 46f, -54471f); + handleTeleport(playerCharacter, loc, 10, 75, false); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 100018: // teleport me to The Sinking Isle + loc = new Vector3fImmutable(67177f, 36f, -31940f); + handleTeleport(playerCharacter, loc, 10, 75, false); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + + // MainLand Repledges + case 100030: // repledge me to Aeldreth + city = City.getCity(25); + if (city != null) + handleRepledge(playerCharacter, city, 10, 55, false); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 100031: // repledge me to Sea Dog's Rest + city = City.getCity(24); + if (city != null) + handleRepledge(playerCharacter, city, 10, 75, true); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 100032: // repledge me to Erkeng Hold + city = City.getCity(26); + if (city != null) + handleRepledge(playerCharacter, city, 10, 55, false); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 100033: // repledge me to Khan\'Of Srekel + city = City.getCity(36); + if (city != null) + handleRepledge(playerCharacter, city, 1, 75, true); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 100035: // repledge me to Starkholm + city = City.getCity(27); + if (city != null) + handleRepledge(playerCharacter, city, 1, 20, false); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + + // Noob Isle Teleports + case 100040: // teleport me to Starkholm + city = City.getCity(27); + if (city != null) + handleTeleport(playerCharacter, city.getLoc(), 1, 20, true); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 100041: // teleport me to All-Father's Rest + city = City.getCity(28); + if (city != null) + handleTeleport(playerCharacter, city.getLoc(), 1, 20, true); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 100042: // teleport me to Hengest + city = City.getCity(33); + if (city != null) + handleTeleport(playerCharacter, city.getLoc(), 1, 20, true); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 100043: // teleport me to Hrimdal + city = City.getCity(30); + if (city != null) + handleTeleport(playerCharacter, city.getLoc(), 1, 20, true); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 100044: // teleport me to Hothor's Doom + city = City.getCity(29); + if (city != null) + handleTeleport(playerCharacter, city.getLoc(), 1, 20, true); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 100045: // teleport me to Scraefahl + city = City.getCity(32); + if (city != null) + handleTeleport(playerCharacter, city.getLoc(), 1, 20, false); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + case 100046: // teleport me to Valkirch + city = City.getCity(31); + if (city != null) + handleTeleport(playerCharacter, city.getLoc(), 1, 20, true); + msg.updateMessage(4, 0); + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + + + default: + } + return false; + } + + private static boolean finishMessage(VendorDialogMsg msg, ClientConnection origin) throws MsgSendException { + msg.updateMessage(4, 0); + Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + } + + private static void handleTeleport(PlayerCharacter pc, Vector3fImmutable loc, int minLevel, int maxLevel, boolean useSquare) { + if (pc == null) + return; + + int level = pc.getLevel(); + if (level >= minLevel && level <= maxLevel) { + if (useSquare) + loc = getSquare(loc); + pc.teleport(loc); + pc.setSafeMode(); + // PowersManager.applyPower(pc, pc, new Vector3f(0f, + // 0f, 0f), -1661758934, 40, false); + } else { + if (level < minLevel) + ErrorPopupMsg.sendErrorPopup(pc, 74); + else + ErrorPopupMsg.sendErrorPopup(pc, 139); + + } + } + + private static void handleRepledge(PlayerCharacter pc, City city, int minLevel, int maxLevel, boolean useSquare) { + if (pc == null || city == null) + return; + + Vector3fImmutable loc = city.getLoc(); + int level = pc.getLevel(); + if (level >= minLevel && level <= maxLevel) { + // set guild + Guild guild = city.getGuild(); + if (guild != null) { + // teleport player + if (useSquare) + loc = getSquare(loc); + pc.teleport(loc); + pc.setSafeMode(); + // PowersManager.applyPower(pc, pc, new + // Vector3f(0f, 0f, 0f), -1661758934, 40, false); + + // join guild + GuildManager.joinGuild(pc, guild, GuildHistoryType.JOIN); + + pc.resetGuildStatuses(); + + if (guild.isNPCGuild()) + pc.setFullMember(true); + + if (useSquare) + loc = loc.add(30, 0, 0); + pc.setBindLoc(loc); + } else { + // guild not found, just teleport + if (useSquare) + loc = getSquare(loc); + pc.teleport(loc); + pc.setSafeMode(); + // PowersManager.applyPower(pc, pc, new + // Vector3f(0f, 0f, 0f), -1661758934, 50, false); + } + } else { + + if (level < minLevel) + ErrorPopupMsg.sendErrorPopup(pc, 74); + else + ErrorPopupMsg.sendErrorPopup(pc, 139); + } + } + + // randomly place around a tol using a square (+- 30 units in x and z + // direction) + public static Vector3fImmutable getSquare(Vector3fImmutable cityLoc) { + Vector3fImmutable loc = cityLoc; + // get direction + int roll = ThreadLocalRandom.current().nextInt(4); + if (roll == 0) { // north + loc = loc.add((ThreadLocalRandom.current().nextInt(60) - 30), 0, -30); + } else if (roll == 1) { // south + loc = loc.add((ThreadLocalRandom.current().nextInt(60) - 30), 0, 30); + } else if (roll == 2) { // east + loc = loc.add(30, 0, (ThreadLocalRandom.current().nextInt(60) - 30)); + } else { // west + loc = loc.add(-30, 0, (ThreadLocalRandom.current().nextInt(60) - 30)); + } + + // Make sure no one gets stuck in the tree. + + if (loc.distanceSquared2D(cityLoc) < 250) { + loc = cityLoc; + loc = loc.add(30, 0, 0); + } + + return loc; + } + + // Handle promotion + private static void promote(PlayerCharacter pc, NPC npc) { + + if (npc == null || pc == null) + return; + + // test level 10 + if (pc.getLevel() < 10) { + // TODO send client promotion error + while (pc.getLevel() > 65) + pc.setLevel((short) 65); + return; + } + + // verify player not already promoted + if (pc.getPromotionClass() != null) { + // TODO send client promotion error + return; + } + + // Get promotion class for npc + Contract contract = npc.getContract(); + if (contract == null) + return; + int promoID = contract.getPromotionClass(); + if (promoID == 0) + return; + PromotionClass promo = DbManager.PromotionQueries.GET_PROMOTION_CLASS(promoID); + if (promo == null) { + // TODO log error here + return; + } + + // verify race valid for profession + Race race = pc.getRace(); + if (race == null || !promo.isAllowedRune(race.getToken())) { + // TODO send client promotion error + return; + } + + // verify baseclass valid for profession + BaseClass bc = pc.getBaseClass(); + if (bc == null || !promo.isAllowedRune(bc.getToken())) { + // TODO send client promotion error + return; + } + + // verify gender + if (promoID == 2511 && pc.isMale()) // Fury + return; + if (promoID == 2512 && pc.isMale()) // Huntress + return; + if (promoID == 2517 && !pc.isMale()) // Warlock + return; + + // Everything valid. Let's promote + pc.setPromotionClass(promo.getObjectUUID()); + + //pc.setLevel((short) 65); + + + promo = pc.getPromotionClass(); + if (promo == null) { + // TODO log error here + return; + } + + // recalculate all bonuses/formulas/skills/powers + pc.recalculate(); + + // send the rune application to the clients + ApplyRuneMsg arm = new ApplyRuneMsg(pc.getObjectType().ordinal(), pc.getObjectUUID(), promo.getObjectUUID(), promo.getObjectType().ordinal(), promo + .getObjectUUID(), true); + DispatchMessage.dispatchMsgToInterestArea(pc, arm, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + + + } + + /** + * Load and send vault to player. This is public only so a DevCmd can hook + * into it. + * + * @param playerCharacter - Player Character requesting vault + * @param target - NPC vaultkeeper + * @param cc - Client Connection + */ + public static void getVault(PlayerCharacter playerCharacter, NPC target, ClientConnection cc) { + if (playerCharacter == null || cc == null || target == null) + return; + + Account ac = playerCharacter.getAccount(); + if (ac == null) + return; + + CharacterItemManager itemManager = playerCharacter.getCharItemManager(); + if (itemManager == null) + return; + + // TODO uncomment this block after we determine when we + // setBankOpen(false) + /* + * // cannot have bank and vault open at the same time if + * (itemManager.isBankOpen()) return; + */ + + if (itemManager.getTradingWith() != null) { + return; + // TODO close trade window here - simple once this is moved to WS + } + + itemManager.setVaultOpen(true); + + // TODO for public test - remove this afterwards + // DevCmd.fillVault(pc, itemManager); + + // TODO When do we setVaultOpen(false)? I don't think the client sends a + // "CloseVault" message. + + OpenVaultMsg openVaultMsg = new OpenVaultMsg(playerCharacter, target); + Dispatch dispatch = Dispatch.borrow(playerCharacter, openVaultMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + ShowVaultInventoryMsg showVaultInventoryMsg = new ShowVaultInventoryMsg(playerCharacter, ac, target); // 37?? + dispatch = Dispatch.borrow(playerCharacter, showVaultInventoryMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + // All recordings have "open - show - open." + // Seems to work fine with just "show - open" as well. + + } + + /** + * Load and send Bank to player. This is public only so a DevCmd can hook + * into it. + * + * @param playerCharacter - Player Character requesting vault + * @param target - NPC vaultkeeper + * @param cc - Client Connection + */ + public static void getBank(PlayerCharacter playerCharacter, NPC target, ClientConnection cc) { + + if (playerCharacter == null) + return; + + if (cc == null) + return; + + CharacterItemManager itemManager = playerCharacter.getCharItemManager(); + + if (itemManager == null) + return; + + // TODO uncomment this block after we determine when we + // setVaultOpen(false) + /* + * // cannot have bank and vault open at the same time if + * (itemManager.isVaultOpen()) return; + */ + + if (itemManager.getTradingWith() != null) { + return; + // TODO close trade window here - simple once this is moved to WS + } + + itemManager.setBankOpen(true); + // TODO When do we setBankOpen(false)? I don't think the client sends a + // "CloseBank" message. + + AckBankWindowOpenedMsg ackBankWindowOpenedMsg = new AckBankWindowOpenedMsg(playerCharacter, 0L, 0L); + + Dispatch dispatch = Dispatch.borrow(playerCharacter, ackBankWindowOpenedMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + ReqBankInventoryMsg reqBankInventoryMsg = new ReqBankInventoryMsg(playerCharacter, 0L); + dispatch = Dispatch.borrow(playerCharacter, reqBankInventoryMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + ShowBankInventoryMsg showBankInventoryMsg = new ShowBankInventoryMsg(playerCharacter, 0L); + dispatch = Dispatch.borrow(playerCharacter, showBankInventoryMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + + writer.putInt(this.messageType); + for (int i = 0; i < 3; i++) + writer.putInt(0); + if (messageType == 1) + writer.putString(this.language); + else + writer.putString(""); + writer.putInt(this.vendorObjectType); + writer.putInt(this.vendorObjectID); + + for (int i = 0; i < 3; i++) + writer.putInt(0); + writer.put((byte) 0); + writer.put((byte) 0); + if (this.messageType == 1) { + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + } else if (this.messageType == 4) { + writer.putInt(0); + writer.putInt(0x364AF0D0); // 0x325695C0 + if (this.vd != null) + writer.putInt(vd.getObjectUUID()); + else + writer.putInt(this.unknown03); + writer.putInt(1); + writer.put((byte) 0); + writer.putInt(this.unknown03); + writer.put((byte) 0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(2); // 2 + if (menuType == 2) + writer.putInt(3); + else if (menuType == 3) + writer.putInt(4); + else + writer.putInt(5); + // writer.putInt(3); // 3=buy/sell/trade, 4=untrain, 5 closes + writer.putInt(10); // 10 + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + return; + + } + writer.putInt(15); + writer.putInt(5); + if (this.vd != null) + writer.putInt(vd.getObjectUUID()); + else + writer.putInt(this.unknown03); + + //filename datablock + writer.putInt(1); + writer.put((byte) 1); + writer.putInt(this.unknown03); + writer.put((byte) 1); + writer.putString(vd.getDialogType()); + writer.putInt(0); + writer.putInt(1); + writer.putInt(4); + writer.putInt(0); + writer.put((byte) 1); + + //vendor dialog datablock + writer.putString(vd.getDialogType()); + writer.putString(vd.getIntro()); + writer.put((byte) 0); + + //menu options datablock + writer.putInt(1); + writer.putString(" [ " + vd.getIntro() + " ] "); + ArrayList options = vd.getOptions(); + writer.putInt((options.size() + 1)); + for (MenuOption option : options) { + if (option.getMessage().equals(" [ Merchant options ] ")) { + writer.putInt(16); + } else { + writer.putInt(14); + } + writer.put((byte) 0); + writer.putInt(0); + writer.put((byte) 0); + writer.putInt(1); + writer.putString(option.getMessage()); + writer.putInt(option.getOptionID()); + for (int i = 0; i < 3; i++) + writer.putInt(0); + } + writer.putInt(10); + writer.put((byte) 0); + writer.putInt(0); + writer.put((byte) 0); + writer.putInt(1); + writer.putString("Done"); + for (int i = 0; i < 4; i++) + writer.putInt(0); + // writer.putInt(1); + // writer.putInt(2); + for (int i = 0; i < 4; i++) + writer.putInt(0); + } + + /** + * Deserializes the subclass specific items from the supplied + * ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.messageType = reader.getInt(); + for (int i = 0; i < 3; i++) + reader.getInt(); + this.language = reader.getString(); + this.vendorObjectType = reader.getInt(); + this.vendorObjectID = reader.getInt(); + for (int i = 0; i < 3; i++) + reader.getInt(); + reader.get(); + reader.get(); + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + this.unknown03 = reader.getInt(); + reader.getInt(); + // if (this.messageType == 1) { + reader.get(); + reader.getInt(); + reader.get(); + reader.getInt(); + reader.getShort(); + // return; + // } + // reader.get(); + // this.unknown04 = reader.getInt(); + // reader.get(); + // TODO more message to go here + } + + public int getMessageType() { + return this.messageType; + } + + public void setMessageType(int value) { + this.messageType = value; + } + + public int getVendorObjectType() { + return this.vendorObjectType; + } + + public int getVendorObjectID() { + return this.vendorObjectID; + } + + public int getUnknown01() { + return this.unknown01; + } + + public int getUnknown02() { + return this.unknown02; + } + + public int getUnknown03() { + return this.unknown03; + } + + public void setUnknown03(int value) { + this.unknown03 = value; + } + + public void setLanguage(String value) { + this.language = value; + } + + public void updateMessage(int messageType, int menuType) { + this.messageType = messageType; + this.menuType = menuType; + } + + public void updateMessage(int messageType, String dialogType, String intro, int menuType) { + this.messageType = messageType; + this.dialogType = dialogType; + this.intro = intro; + this.introCode = " [ " + this.intro + " ] "; + this.menuType = menuType; + } + + public void updateMessage(int messageType, VendorDialog vd) { + this.messageType = messageType; + this.vd = vd; + } } diff --git a/src/engine/net/client/msg/ViewResourcesMessage.java b/src/engine/net/client/msg/ViewResourcesMessage.java index 074d6077..9457e159 100644 --- a/src/engine/net/client/msg/ViewResourcesMessage.java +++ b/src/engine/net/client/msg/ViewResourcesMessage.java @@ -20,179 +20,176 @@ import engine.objects.*; public class ViewResourcesMessage extends ClientNetMsg { - //resource hashes - //0001240F - //002339C7 (locked) - //00263669 - //00270DC3 - //002D6DEF - //047636B3 (locked) - //047B0CC1 - //04AB3761 - //1AF5DB3A - //47033237 - //4F8EFB0F - //5B57C3E4 - //86A0AC24 - //9705591E - //98378CB4 - //98D78D15 - //A0703E8C (locked) - //A0DA3807 - //A1723A93 - //A26E59CF - //D665C60F - //E3D05AE3 - //ED13904D - - private Guild guild; - private Building warehouseBuilding; - private Warehouse warehouseObject; - private PlayerCharacter player; - private City city; - - /** - * This is the general purpose constructor. - */ - - public ViewResourcesMessage(PlayerCharacter player) { - super(Protocol.VIEWRESOURCES); - this.guild = null; - this.player = player; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public ViewResourcesMessage(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.VIEWRESOURCES, origin, reader); - } - - public boolean configure() { - - if (this.warehouseBuilding.getParentZone() == null) - return false; - - this.city = (City) DbManager.getObject(Enum.GameObjectType.City, this.warehouseBuilding.getParentZone().getPlayerCityUUID()); - - if (this.city == null) - return false; - - this.warehouseObject = this.city.getWarehouse(); + //resource hashes + //0001240F + //002339C7 (locked) + //00263669 + //00270DC3 + //002D6DEF + //047636B3 (locked) + //047B0CC1 + //04AB3761 + //1AF5DB3A + //47033237 + //4F8EFB0F + //5B57C3E4 + //86A0AC24 + //9705591E + //98378CB4 + //98D78D15 + //A0703E8C (locked) + //A0DA3807 + //A1723A93 + //A26E59CF + //D665C60F + //E3D05AE3 + //ED13904D + + private Guild guild; + private Building warehouseBuilding; + private Warehouse warehouseObject; + private PlayerCharacter player; + private City city; + + /** + * This is the general purpose constructor. + */ + + public ViewResourcesMessage(PlayerCharacter player) { + super(Protocol.VIEWRESOURCES); + this.guild = null; + this.player = player; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public ViewResourcesMessage(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.VIEWRESOURCES, origin, reader); + } + + public boolean configure() { + + if (this.warehouseBuilding.getParentZone() == null) + return false; + + this.city = (City) DbManager.getObject(Enum.GameObjectType.City, this.warehouseBuilding.getParentZone().getPlayerCityUUID()); + + if (this.city == null) + return false; + + this.warehouseObject = this.city.getWarehouse(); return this.warehouseObject != null; } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - - writer.putInt(warehouseObject.getResources().size()); - - for (ItemBase ib : (warehouseObject.getResources().keySet())){ - - writer.putInt(ib.getHashID()); - writer.putInt((warehouseObject.getResources().get(ib))); - - - if (warehouseObject.isResourceLocked(ib) == true) - writer.put((byte)1); - else - writer.put((byte)0); - } - - writer.putInt(warehouseObject.getResources().size()); - - for (ItemBase ib : warehouseObject.getResources().keySet()){ - writer.putInt(ib.getHashID()); - writer.putInt(0); //available? - writer.putInt(Warehouse.getMaxResources().get(ib.getUUID())); //max? - } - GuildTag._serializeForDisplay(guild.getGuildTag(),writer); - - // Serialize what tags? Errant? - - writer.putInt(16); - writer.putInt(16); - writer.putInt(16); - writer.putInt(0); - writer.putInt(0); - - if (GuildStatusController.isTaxCollector(player.getGuildStatus())){ - writer.putInt(1); - writer.putString("Deposit"); - writer.putInt(-1760114543); - writer.putInt(1); - writer.put((byte)0); - - }else - - if (this.player.getGuild().equals(warehouseBuilding.getGuild()) && (GuildStatusController.isInnerCouncil(this.player.getGuildStatus()))){ - writer.putInt(4); - writer.putString("Lock"); - writer.putInt(2393548); - writer.putInt(1); //locked? on/off - writer.put((byte)0); - writer.putString("Deposit"); - writer.putInt(-1760114543); - - writer.putInt(1); - writer.put((byte)0); - writer.putString("Manage Mines"); - writer.putInt(-820683698); - writer.putInt(1); - writer.put((byte)0); - writer.putString("Withdraw"); - writer.putInt(-530228289); - writer.putInt(1); - writer.put((byte)0); - }else{ - writer.putInt(2); - writer.putString("Lock"); - writer.putInt(2393548); - writer.putInt(0); //locked? on/off - writer.put((byte)0); - writer.putString("Deposit"); - writer.putInt(-1760114543); - writer.putInt(1); - writer.put((byte)0); - } - - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - // this.locX = reader.getFloat(); - // this.locY = reader.getFloat(); - // this.locZ = reader.getFloat(); - // this.name = reader.getString(); - // this.unknown01 = reader.getInt(); - } - - public void setGuild(Guild guild) { - this.guild = guild; - } - - public void setWarehouseBuilding(Building warehouseBuilding) { - this.warehouseBuilding = warehouseBuilding; - } + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + + writer.putInt(warehouseObject.getResources().size()); + + for (ItemBase ib : (warehouseObject.getResources().keySet())) { + + writer.putInt(ib.getHashID()); + writer.putInt((warehouseObject.getResources().get(ib))); + + + if (warehouseObject.isResourceLocked(ib) == true) + writer.put((byte) 1); + else + writer.put((byte) 0); + } + + writer.putInt(warehouseObject.getResources().size()); + + for (ItemBase ib : warehouseObject.getResources().keySet()) { + writer.putInt(ib.getHashID()); + writer.putInt(0); //available? + writer.putInt(Warehouse.getMaxResources().get(ib.getUUID())); //max? + } + GuildTag._serializeForDisplay(guild.getGuildTag(), writer); + + // Serialize what tags? Errant? + + writer.putInt(16); + writer.putInt(16); + writer.putInt(16); + writer.putInt(0); + writer.putInt(0); + + if (GuildStatusController.isTaxCollector(player.getGuildStatus())) { + writer.putInt(1); + writer.putString("Deposit"); + writer.putInt(-1760114543); + writer.putInt(1); + writer.put((byte) 0); + + } else if (this.player.getGuild().equals(warehouseBuilding.getGuild()) && (GuildStatusController.isInnerCouncil(this.player.getGuildStatus()))) { + writer.putInt(4); + writer.putString("Lock"); + writer.putInt(2393548); + writer.putInt(1); //locked? on/off + writer.put((byte) 0); + writer.putString("Deposit"); + writer.putInt(-1760114543); + + writer.putInt(1); + writer.put((byte) 0); + writer.putString("Manage Mines"); + writer.putInt(-820683698); + writer.putInt(1); + writer.put((byte) 0); + writer.putString("Withdraw"); + writer.putInt(-530228289); + writer.putInt(1); + writer.put((byte) 0); + } else { + writer.putInt(2); + writer.putString("Lock"); + writer.putInt(2393548); + writer.putInt(0); //locked? on/off + writer.put((byte) 0); + writer.putString("Deposit"); + writer.putInt(-1760114543); + writer.putInt(1); + writer.put((byte) 0); + } + + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + // this.locX = reader.getFloat(); + // this.locY = reader.getFloat(); + // this.locZ = reader.getFloat(); + // this.name = reader.getString(); + // this.unknown01 = reader.getInt(); + } + + public void setGuild(Guild guild) { + this.guild = guild; + } + + public void setWarehouseBuilding(Building warehouseBuilding) { + this.warehouseBuilding = warehouseBuilding; + } } diff --git a/src/engine/net/client/msg/VisualUpdateMessage.java b/src/engine/net/client/msg/VisualUpdateMessage.java index 348cc338..5a5e8035 100644 --- a/src/engine/net/client/msg/VisualUpdateMessage.java +++ b/src/engine/net/client/msg/VisualUpdateMessage.java @@ -20,55 +20,57 @@ import engine.objects.AbstractGameObject; import engine.objects.Building; public class VisualUpdateMessage extends ClientNetMsg { - private int effectType; - private AbstractGameObject ago; - private Building building; - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public VisualUpdateMessage(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.VISUALUPDATE, origin, reader); - } - - public VisualUpdateMessage() { - super(Protocol.VISUALUPDATE); - } - - public VisualUpdateMessage(AbstractGameObject ago, int visualID) { - super(Protocol.VISUALUPDATE); - - if (ago == null) - return; - - this.effectType = visualID; - this.ago = ago; - - } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - - } + private int effectType; + private AbstractGameObject ago; + private Building building; + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public VisualUpdateMessage(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.VISUALUPDATE, origin, reader); + } + + public VisualUpdateMessage() { + super(Protocol.VISUALUPDATE); + } + + public VisualUpdateMessage(AbstractGameObject ago, int visualID) { + super(Protocol.VISUALUPDATE); + + if (ago == null) + return; + + this.effectType = visualID; + this.ago = ago; + + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + + } public void configure() { if (this.ago.getObjectType() == GameObjectType.Building) - this.building = (Building)this.ago; + this.building = (Building) this.ago; else this.building = null; } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) throws SerializationException { + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) throws SerializationException { if (this.building == null) { writer.putInt(4); @@ -80,12 +82,12 @@ public class VisualUpdateMessage extends ClientNetMsg { return; } - writer.putShort((short)100); - writer.putShort((short)120); + writer.putShort((short) 100); + writer.putShort((short) 120); writer.putInt(1); writer.putInt(this.building.getObjectType().ordinal()); writer.putInt(this.building.getObjectUUID()); writer.putInt(this.effectType); - } + } } diff --git a/src/engine/net/client/msg/WhoRequestMsg.java b/src/engine/net/client/msg/WhoRequestMsg.java index c04dbd2b..93433461 100644 --- a/src/engine/net/client/msg/WhoRequestMsg.java +++ b/src/engine/net/client/msg/WhoRequestMsg.java @@ -17,90 +17,87 @@ import engine.net.client.Protocol; public class WhoRequestMsg extends ClientNetMsg { - private int set; - private int filterType; - private String filter; - - /** - * This is the general purpose constructor. - */ - public WhoRequestMsg() { - super(Protocol.WHOREQUEST); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public WhoRequestMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.WHOREQUEST, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.set); - writer.putInt(this.filterType); - writer.putString(this.filter); - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.set = reader.getInt(); - this.filterType = reader.getInt(); - this.filter = reader.getString(); - } - - /** - * @return the set - */ - public int getSet() { - return set; - } - - /** - * @return the filterType - */ - public int getFilterType() { - return filterType; - } - - /** - * @return the filter - */ - public String getFilter() { - return filter; - } - - /** - * @param set - * the set to set - */ - public void setSet(int set) { - this.set = set; - } - - /** - * @param filterType - * the filterType to set - */ - public void setFilterType(int filterType) { - this.filterType = filterType; - } - - /** - * @param filter - * the filter to set - */ - public void setFilter(String filter) { - this.filter = filter; - } + private int set; + private int filterType; + private String filter; + + /** + * This is the general purpose constructor. + */ + public WhoRequestMsg() { + super(Protocol.WHOREQUEST); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public WhoRequestMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.WHOREQUEST, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.set); + writer.putInt(this.filterType); + writer.putString(this.filter); + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.set = reader.getInt(); + this.filterType = reader.getInt(); + this.filter = reader.getString(); + } + + /** + * @return the set + */ + public int getSet() { + return set; + } + + /** + * @param set the set to set + */ + public void setSet(int set) { + this.set = set; + } + + /** + * @return the filterType + */ + public int getFilterType() { + return filterType; + } + + /** + * @param filterType the filterType to set + */ + public void setFilterType(int filterType) { + this.filterType = filterType; + } + + /** + * @return the filter + */ + public String getFilter() { + return filter; + } + + /** + * @param filter the filter to set + */ + public void setFilter(String filter) { + this.filter = filter; + } } diff --git a/src/engine/net/client/msg/WhoResponseMsg.java b/src/engine/net/client/msg/WhoResponseMsg.java index 85184b77..dc27c00b 100644 --- a/src/engine/net/client/msg/WhoResponseMsg.java +++ b/src/engine/net/client/msg/WhoResponseMsg.java @@ -25,39 +25,210 @@ import java.util.ArrayList; public class WhoResponseMsg extends ClientNetMsg { - private int unknown01; - private static int worldPop; - private ArrayList members = new ArrayList<>(); - - /** - * This is the general purpose constructor. - */ - public WhoResponseMsg() { - super(Protocol.WHORESPONSE); - this.unknown01 = 1; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public WhoResponseMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.WHORESPONSE, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ + private static int worldPop; + private int unknown01; + private ArrayList members = new ArrayList<>(); + + /** + * This is the general purpose constructor. + */ + public WhoResponseMsg() { + super(Protocol.WHORESPONSE); + this.unknown01 = 1; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public WhoResponseMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.WHORESPONSE, origin, reader); + } + + /** + * @return the worldPop + */ + public static int getWorldPop() { + return WhoResponseMsg.worldPop; + } + + /** + * @param worldPop the worldPop to set + */ + public static void setWorldPop(int worldPop) { + WhoResponseMsg.worldPop = worldPop; + } + + public static void HandleResponse(int set, int filterType, String filter, ClientConnection origin) { + + WhoResponseMsg msg = new WhoResponseMsg(); + WhoResponseMsg.setWorldPop(SessionManager.getAllActivePlayerCharacters().size()); + + PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter(origin); + + if (playerCharacter != null) { + //check threshold + long currentTime = System.currentTimeMillis(); + long timestamp = playerCharacter.getTimeStamp("whoWindow"); + long dif = currentTime - timestamp; + if (dif < MBServerStatics.WHO_WINDOW_THRESHOLD) + return; + playerCharacter.setTimeStamp("whoWindow", currentTime); + } + + if (playerCharacter == null) { + } else if (filterType == 0) { // No Filter, send everyone + for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) + if (player != null) + if (player.isActive()) + if (!isAdmin(player)) + if (!HandleSet(set, player, playerCharacter, msg)) + break; + } else if (filterType == 1) { // Race Filter + for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) + if (player != null) + if (!isAdmin(player)) + if (player.isActive()) { + String[] race = player.getRace().getName().split(","); + if (filter.compareTo(race[0]) == 0) + if (!HandleSet(set, player, playerCharacter, msg)) + break; + } + } else if (filterType == 2) { // Class Filter + for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) + if (player != null) + if (!isAdmin(player)) + if (player.isActive()) { + if (filter.compareTo(player.getBaseClass().getName()) == 0 || (player.getPromotionClass() != null && filter.compareTo(player.getPromotionClass().getName()) == 0)) + if (!HandleSet(set, player, playerCharacter, msg)) + break; + + + // TODO Promotion Class needs added to + // PlayerCharacter + // else if + // (filter.compareTo(pc.getPromotionClass().getName()) + // == 0) + // if (!HandleSet(set, pc, ori, msg)) + // break; + } + } else if (filterType == 3) { // Level Filter + String range[] = filter.split(" "); + int low; + int high; + + try { + low = Integer.parseInt(range[0]); + } catch (NumberFormatException e) { + low = 1; + Logger.error("WhoResponseMsg: Low value in filter is not a proper integer. Defaulting to 1. Error = " + + e.getMessage()); + } + + try { + high = Integer.parseInt(range[1]); + } catch (NumberFormatException e) { + high = 1; + Logger.error( + "WhoResponseMsg: High value in filter is not a proper integer. Defaulting to 75. Error = " + e.getMessage()); + } + + for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) + if (player != null) + if (!isAdmin(player)) + if (player.isActive()) + if (player.getLevel() >= low && player.getLevel() <= high) + if (!HandleSet(set, player, playerCharacter, msg)) + break; + } else if (filterType == 4) { // Name Filter + filter = filter.toLowerCase(); + for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) + if (player != null) + if (!isAdmin(player)) + if (player.isActive()) + if (player.getName().toLowerCase().indexOf(filter) > -1) + if (!HandleSet(set, player, playerCharacter, msg)) + break; + } else if (filterType == 6) { // Status Filter + int type = Integer.parseInt(filter); + for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) + if (player != null) + if (!isAdmin(player)) + if (player.isActive()) { + if (type == 1) { + if (player.isLFGroup()) + if (!HandleSet(set, player, playerCharacter, msg)) + break; + } else if (type == 2) { + if (player.isLFGuild()) + if (!HandleSet(set, player, playerCharacter, msg)) + break; + } else if (type == 3) { + if (player.isRecruiting()) + if (!HandleSet(set, player, playerCharacter, msg)) + break; + } else + break; + } + } + + Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + } + + private static boolean HandleSet(int set, PlayerCharacter a, PlayerCharacter b, WhoResponseMsg msg) { + // This function handles the sets. 0 = search all, 1 = search nation, + // 2 = search guild. Returns true until 100 (max) players found + + if (set == 0) { // All + return msg.addMember(a); + } else if (set == 1) { // Nation + if (compareNation(a, b)) + return msg.addMember(a); + } else if (set == 2) { // Guild + if (compareGuild(a, b)) + return msg.addMember(a); + } + return true; + } + + private static boolean isAdmin(PlayerCharacter pc) { + PromotionClass promo = pc.getPromotionClass(); + if (promo == null) + return false; + return promo.getObjectUUID() <= 2503 || promo.getObjectUUID() >= 2527; + } + + private static boolean compareGuild(PlayerCharacter a, PlayerCharacter b) { + if (a == null || b == null) + return false; + return Guild.sameGuild(a.getGuild(), b.getGuild()); + } + + private static boolean compareNation(PlayerCharacter a, PlayerCharacter b) { + if (a == null || b == null) + return false; + Guild aG = a.getGuild(); + Guild bG = b.getGuild(); + if (aG == null || bG == null) + return false; + return (aG.getNation() == bG.getNation()) && aG.getNation() != null; + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ @Override protected void _serialize(ByteBufferWriter writer) { writer.putInt(unknown01); writer.putInt(worldPop); - int size = this.members.size(); + int size = this.members.size(); writer.putInt(size); //PlayerCharacter pc : this.members - for (PlayerCharacter pc: this.members) { + for (PlayerCharacter pc : this.members) { writer.putInt(pc.getObjectType().ordinal()); writer.putInt(pc.getObjectUUID()); writer.putString(pc.getFirstName()); @@ -83,231 +254,47 @@ public class WhoResponseMsg extends ClientNetMsg { } } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.unknown01 = reader.getInt(); - WhoResponseMsg.worldPop = reader.getInt(); - // TODO implement Deserialization - } - - /** - * @return the number of PlayerCharacters - */ - public int getSize() { - return this.members.size(); - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the worldPop - */ - public static int getWorldPop() { - return WhoResponseMsg.worldPop; - } - - /** - * @param worldPop - * the worldPop to set - */ - public static void setWorldPop(int worldPop) { - WhoResponseMsg.worldPop = worldPop; - } - - public boolean addMember(PlayerCharacter pc) { - if (this.members.size() > 100) - return false; - this.members.add(pc); - return true; - } - - public static void HandleResponse(int set, int filterType, String filter, ClientConnection origin) { - - WhoResponseMsg msg = new WhoResponseMsg(); - WhoResponseMsg.setWorldPop(SessionManager.getAllActivePlayerCharacters().size()); - - PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter(origin); - - if (playerCharacter != null) { - //check threshold - long currentTime = System.currentTimeMillis(); - long timestamp = playerCharacter.getTimeStamp("whoWindow"); - long dif = currentTime - timestamp; - if (dif < MBServerStatics.WHO_WINDOW_THRESHOLD) - return; - playerCharacter.setTimeStamp("whoWindow", currentTime); - } - - if (playerCharacter == null) { - } else if (filterType == 0) { // No Filter, send everyone - for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) - if (player != null) - if (player.isActive()) - if (!isAdmin(player)) - if (!HandleSet(set, player, playerCharacter, msg)) - break; - } - - else if (filterType == 1) { // Race Filter - for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) - if (player != null) - if (!isAdmin(player)) - if (player.isActive()) { - String[] race = player.getRace().getName().split(","); - if (filter.compareTo(race[0]) == 0) - if (!HandleSet(set, player, playerCharacter, msg)) - break; - } - } - - else if (filterType == 2) { // Class Filter - for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) - if (player != null) - if (!isAdmin(player)) - if (player.isActive()) { - if (filter.compareTo(player.getBaseClass().getName()) ==0 || (player.getPromotionClass() != null && filter.compareTo(player.getPromotionClass().getName()) == 0)) - if (!HandleSet(set, player, playerCharacter, msg)) - break; - - - // TODO Promotion Class needs added to - // PlayerCharacter - // else if - // (filter.compareTo(pc.getPromotionClass().getName()) - // == 0) - // if (!HandleSet(set, pc, ori, msg)) - // break; - } - } - - else if (filterType == 3) { // Level Filter - String range[] = filter.split(" "); - int low; - int high; - - try { - low = Integer.parseInt(range[0]); - } catch (NumberFormatException e) { - low = 1; - Logger.error("WhoResponseMsg: Low value in filter is not a proper integer. Defaulting to 1. Error = " - + e.getMessage()); - } - - try { - high = Integer.parseInt(range[1]); - } catch (NumberFormatException e) { - high = 1; - Logger.error( - "WhoResponseMsg: High value in filter is not a proper integer. Defaulting to 75. Error = " + e.getMessage()); - } - - for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) - if (player != null) - if (!isAdmin(player)) - if (player.isActive()) - if (player.getLevel() >= low && player.getLevel() <= high) - if (!HandleSet(set, player, playerCharacter, msg)) - break; - } - - else if (filterType == 4) { // Name Filter - filter = filter.toLowerCase(); - for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) - if (player != null) - if (!isAdmin(player)) - if (player.isActive()) - if (player.getName().toLowerCase().indexOf(filter) > -1) - if (!HandleSet(set, player, playerCharacter, msg)) - break; - } - - else if (filterType == 6) { // Status Filter - int type = Integer.parseInt(filter); - for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) - if (player != null) - if (!isAdmin(player)) - if (player.isActive()) { - if (type == 1) { - if (player.isLFGroup()) - if (!HandleSet(set, player, playerCharacter, msg)) - break; - } else if (type == 2) { - if (player.isLFGuild()) - if (!HandleSet(set, player, playerCharacter, msg)) - break; - } else if (type == 3) { - if (player.isRecruiting()) - if (!HandleSet(set, player, playerCharacter, msg)) - break; - } else - break; - } - } - - Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.unknown01 = reader.getInt(); + WhoResponseMsg.worldPop = reader.getInt(); + // TODO implement Deserialization + } - private static boolean HandleSet(int set, PlayerCharacter a, PlayerCharacter b, WhoResponseMsg msg) { - // This function handles the sets. 0 = search all, 1 = search nation, - // 2 = search guild. Returns true until 100 (max) players found - - if (set == 0) { // All - return msg.addMember(a); - } else if (set == 1) { // Nation - if (compareNation(a, b)) - return msg.addMember(a); - } else if (set == 2) { // Guild - if (compareGuild(a, b)) - return msg.addMember(a); - } - return true; - } - - private static boolean isAdmin(PlayerCharacter pc) { - PromotionClass promo = pc.getPromotionClass(); - if (promo == null) - return false; - return promo.getObjectUUID() <= 2503 || promo.getObjectUUID() >= 2527; + /** + * @return the number of PlayerCharacters + */ + public int getSize() { + return this.members.size(); } - private static boolean compareGuild(PlayerCharacter a, PlayerCharacter b) { - if (a == null || b == null) - return false; - return Guild.sameGuild(a.getGuild(), b.getGuild()); + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; } - private static boolean compareNation(PlayerCharacter a, PlayerCharacter b) { - if (a == null || b == null) - return false; - Guild aG = a.getGuild(); - Guild bG = b.getGuild(); - if (aG == null || bG == null) - return false; - return (aG.getNation() == bG.getNation()) && aG.getNation() != null; + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; } + public boolean addMember(PlayerCharacter pc) { + if (this.members.size() > 100) + return false; + this.members.add(pc); + return true; + } - @Override - protected int getPowerOfTwoBufferSize() { - return 14; - } + @Override + protected int getPowerOfTwoBufferSize() { + return 14; + } } diff --git a/src/engine/net/client/msg/WorldDataMsg.java b/src/engine/net/client/msg/WorldDataMsg.java index 66095499..2db0ee11 100644 --- a/src/engine/net/client/msg/WorldDataMsg.java +++ b/src/engine/net/client/msg/WorldDataMsg.java @@ -24,111 +24,107 @@ import org.pmw.tinylog.Logger; public class WorldDataMsg extends ClientNetMsg { - public static final long wdComp = 0xFF00FF0000000001L; - private static byte ver; - - /** - * This is the general purpose constructor. - */ - public WorldDataMsg() { - super(Protocol.NEWWORLD); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public WorldDataMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.NEWWORLD, origin, reader); - } - - /** - * @see AbstractNetMsg#getPowerOfTwoBufferSize() - */ - @Override - protected int getPowerOfTwoBufferSize() { - // Larger size for historically larger opcodes - return (18); // 2^17 == 131,072 - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) - throws SerializationException { - - - // TODO replace this return with SerializationException - - Zone root = ZoneManager.getSeaFloor(); - if (root == null){ - Logger.error("Failed to find Sea Floor!"); - return; - } - - writer.putString(ConfigManager.MB_WORLD_NAME.getValue()); - writer.putInt(512); - writer.putInt(384); - - writer.putInt(WorldServer.worldMapID); - writer.putInt(0x00000000); - - writer.putInt(getTotalMapSize(root) + 1); - Zone.serializeForClientMsg(root,writer); - - Zone hotzone = ZoneManager.hotZone;; - - if (hotzone == null) - writer.putLong(0L); - else { - writer.putInt(hotzone.getObjectType().ordinal()); - writer.putInt(hotzone.getObjectUUID()); - } - - - - - writer.putFloat(0); - writer.putFloat(1); - writer.putFloat(0); - writer.putFloat(0.69999999f); - writer.putFloat(.5f); - writer.putFloat(1); - writer.putFloat(.5f); - writer.putFloat(0.69999999f); - writer.putFloat(1); - writer.putFloat(0); - writer.putFloat(0); - writer.putFloat(0.69999999f); - writer.putFloat(1); - writer.putFloat(.5f); - writer.putFloat(.5f); - writer.putFloat(0.69999999f); - writer.putFloat(1); - - - - } - - - @Override - protected void _deserialize(ByteBufferReader reader) { - - } - - private static int getTotalMapSize(Zone root) { - if (root.getNodes().isEmpty()) - return 0; - - int size = root.getNodes().size(); - for (Zone child : root.getNodes()) - size += getTotalMapSize(child); - return size; - } + public static final long wdComp = 0xFF00FF0000000001L; + private static byte ver; + + /** + * This is the general purpose constructor. + */ + public WorldDataMsg() { + super(Protocol.NEWWORLD); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public WorldDataMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.NEWWORLD, origin, reader); + } + + private static int getTotalMapSize(Zone root) { + if (root.getNodes().isEmpty()) + return 0; + + int size = root.getNodes().size(); + for (Zone child : root.getNodes()) + size += getTotalMapSize(child); + return size; + } + + /** + * @see AbstractNetMsg#getPowerOfTwoBufferSize() + */ + @Override + protected int getPowerOfTwoBufferSize() { + // Larger size for historically larger opcodes + return (18); // 2^17 == 131,072 + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) + throws SerializationException { + + + // TODO replace this return with SerializationException + + Zone root = ZoneManager.getSeaFloor(); + if (root == null) { + Logger.error("Failed to find Sea Floor!"); + return; + } + + writer.putString(ConfigManager.MB_WORLD_NAME.getValue()); + writer.putInt(512); + writer.putInt(384); + + writer.putInt(WorldServer.worldMapID); + writer.putInt(0x00000000); + + writer.putInt(getTotalMapSize(root) + 1); + Zone.serializeForClientMsg(root, writer); + + Zone hotzone = ZoneManager.hotZone; + ; + + if (hotzone == null) + writer.putLong(0L); + else { + writer.putInt(hotzone.getObjectType().ordinal()); + writer.putInt(hotzone.getObjectUUID()); + } + + + writer.putFloat(0); + writer.putFloat(1); + writer.putFloat(0); + writer.putFloat(0.69999999f); + writer.putFloat(.5f); + writer.putFloat(1); + writer.putFloat(.5f); + writer.putFloat(0.69999999f); + writer.putFloat(1); + writer.putFloat(0); + writer.putFloat(0); + writer.putFloat(0.69999999f); + writer.putFloat(1); + writer.putFloat(.5f); + writer.putFloat(.5f); + writer.putFloat(0.69999999f); + writer.putFloat(1); + + + } + + @Override + protected void _deserialize(ByteBufferReader reader) { + + } } diff --git a/src/engine/net/client/msg/WorldRealmMsg.java b/src/engine/net/client/msg/WorldRealmMsg.java index 9c2c435b..82ca2cf4 100644 --- a/src/engine/net/client/msg/WorldRealmMsg.java +++ b/src/engine/net/client/msg/WorldRealmMsg.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -31,59 +28,58 @@ import engine.server.world.WorldServer; public class WorldRealmMsg extends ClientNetMsg { - - /** - * This is the general purpose constructor. - */ - public WorldRealmMsg() { - super(Protocol.REALMDATA); - } + /** + * This is the general purpose constructor. + */ + public WorldRealmMsg() { + super(Protocol.REALMDATA); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public WorldRealmMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.REALMDATA, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public WorldRealmMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.REALMDATA, origin, reader); + } - @Override - protected int getPowerOfTwoBufferSize() { - return (14); // 2^14 == 16384 - } + @Override + protected int getPowerOfTwoBufferSize() { + return (14); // 2^14 == 16384 + } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ - @Override - protected void _serialize(ByteBufferWriter writer) { + @Override + protected void _serialize(ByteBufferWriter writer) { - int realmCount; - int realmID; - Realm serverRealm; + int realmCount; + int realmID; + Realm serverRealm; - realmCount = Realm._realms.size(); + realmCount = Realm._realms.size(); - writer.putInt(realmCount); + writer.putInt(realmCount); - for (Realm realm : Realm._realms.values()) - realm.serializeForClientMsg(writer); + for (Realm realm : Realm._realms.values()) + realm.serializeForClientMsg(writer); - writer.putInt(0x0); - writer.putInt(WorldServer.worldRealmMap); + writer.putInt(0x0); + writer.putInt(WorldServer.worldRealmMap); - } + } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - // TODO Implement Deserialization - } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + // TODO Implement Deserialization + } } diff --git a/src/engine/net/client/msg/chat/AbstractChatMsg.java b/src/engine/net/client/msg/chat/AbstractChatMsg.java index 714f71b1..5b69e03a 100644 --- a/src/engine/net/client/msg/chat/AbstractChatMsg.java +++ b/src/engine/net/client/msg/chat/AbstractChatMsg.java @@ -20,171 +20,163 @@ import engine.objects.AbstractWorldObject; public abstract class AbstractChatMsg extends ClientNetMsg { - protected int sourceType; - protected int sourceID; - protected String sourceName; - protected AbstractWorldObject source; - - protected int unknown01; - protected String message; - protected int unknown02; - - /** - * This is the general purpose constructor. - */ - protected AbstractChatMsg(Protocol protocolMsg, AbstractWorldObject source, String message) { - super(protocolMsg); - - this.unknown01 = 0; - this.message = message; - this.source = source; - this.unknown02 = 0; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - protected AbstractChatMsg(Protocol protocolMsg, AbstractConnection origin, ByteBufferReader reader) { - super(protocolMsg, origin, reader); - - //THIS may cause initialization error, but messing up guild chat - //this.unknown01 = 0; - //this.unknown02 = 0; - } - - /** - * Copy constructor - */ - protected AbstractChatMsg(AbstractChatMsg msg) { - super(msg.getProtocolMsg()); + protected int sourceType; + protected int sourceID; + protected String sourceName; + protected AbstractWorldObject source; + + protected int unknown01; + protected String message; + protected int unknown02; + + /** + * This is the general purpose constructor. + */ + protected AbstractChatMsg(Protocol protocolMsg, AbstractWorldObject source, String message) { + super(protocolMsg); + + this.unknown01 = 0; + this.message = message; + this.source = source; + this.unknown02 = 0; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + protected AbstractChatMsg(Protocol protocolMsg, AbstractConnection origin, ByteBufferReader reader) { + super(protocolMsg, origin, reader); + + //THIS may cause initialization error, but messing up guild chat + //this.unknown01 = 0; + //this.unknown02 = 0; + } + + /** + * Copy constructor + */ + protected AbstractChatMsg(AbstractChatMsg msg) { + super(msg.getProtocolMsg()); this.sourceType = msg.sourceType; this.sourceID = msg.sourceID; this.sourceName = msg.sourceName; this.source = msg.source; this.unknown01 = msg.unknown01; - this.message = msg.getMessage(); - this.unknown02 = msg.getUnknown02(); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected abstract void _deserialize(ByteBufferReader reader) ; - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected abstract void _serialize(ByteBufferWriter writer) throws SerializationException; - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @return the message - */ - public String getMessage() { - return message; - } - - /** - * @return the unknown02 - */ - public int getUnknown02() { - return unknown02; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @param message - * the message to set - */ - public void setMessage(String message) { - this.message = message; - } - - /** - * @param unknown02 - * the unknown02 to set - */ - public void setUnknown02(int unknown02) { - this.unknown02 = unknown02; - } - - /** - * @return the sourceObjName - */ - public AbstractWorldObject getSource() { - return source; - } - - /** - * @param sourceObjName - * the sourceObjName to set - */ - public void setSource(AbstractWorldObject source) { - this.source = source; - } - - /** - * @return the sourceType - */ - public int getSourceType() { - return sourceType; - } - - /** - * @return the sourceID - */ - public int getSourceID() { - return sourceID; - } - - - /** - * @return the sourceName - */ - public String getSourceName() { - return sourceName; - } - - /** - * @param sourceType - * the sourceType to set - */ - public void setSourceType(int sourceType) { - this.sourceType = sourceType; - } - - /** - * @param sourceID - * the sourceID to set - */ - public void setSourceID(int sourceID) { - this.sourceID = sourceID; - } - - /** - * @param sourceName - * the sourceName to set - */ - public void setSourceName(String sourceName) { - this.sourceName = sourceName; - } + this.message = msg.getMessage(); + this.unknown02 = msg.getUnknown02(); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected abstract void _deserialize(ByteBufferReader reader); + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected abstract void _serialize(ByteBufferWriter writer) throws SerializationException; + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the message + */ + public String getMessage() { + return message; + } + + /** + * @param message the message to set + */ + public void setMessage(String message) { + this.message = message; + } + + /** + * @return the unknown02 + */ + public int getUnknown02() { + return unknown02; + } + + /** + * @param unknown02 the unknown02 to set + */ + public void setUnknown02(int unknown02) { + this.unknown02 = unknown02; + } + + /** + * @return the sourceObjName + */ + public AbstractWorldObject getSource() { + return source; + } + + /** + * @param sourceObjName the sourceObjName to set + */ + public void setSource(AbstractWorldObject source) { + this.source = source; + } + + /** + * @return the sourceType + */ + public int getSourceType() { + return sourceType; + } + + /** + * @param sourceType the sourceType to set + */ + public void setSourceType(int sourceType) { + this.sourceType = sourceType; + } + + /** + * @return the sourceID + */ + public int getSourceID() { + return sourceID; + } + + /** + * @param sourceID the sourceID to set + */ + public void setSourceID(int sourceID) { + this.sourceID = sourceID; + } + + /** + * @return the sourceName + */ + public String getSourceName() { + return sourceName; + } + + /** + * @param sourceName the sourceName to set + */ + public void setSourceName(String sourceName) { + this.sourceName = sourceName; + } } diff --git a/src/engine/net/client/msg/chat/ChatCSRMsg.java b/src/engine/net/client/msg/chat/ChatCSRMsg.java index 8fe806b9..1aff5bbd 100644 --- a/src/engine/net/client/msg/chat/ChatCSRMsg.java +++ b/src/engine/net/client/msg/chat/ChatCSRMsg.java @@ -22,57 +22,57 @@ import engine.session.Session; public class ChatCSRMsg extends AbstractChatMsg { - /** - * This is the general purpose constructor. - */ - public ChatCSRMsg(AbstractWorldObject source, String message) { - super(Protocol.CHATCSR, source, message); - } + /** + * This is the general purpose constructor. + */ + public ChatCSRMsg(AbstractWorldObject source, String message) { + super(Protocol.CHATCSR, source, message); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ChatCSRMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CHATCSR, origin, reader); - Session s = SessionManager.getSession((ClientConnection) origin); - if (s == null) - return; - this.source = s.getPlayerCharacter(); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ChatCSRMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CHATCSR, origin, reader); + Session s = SessionManager.getSession((ClientConnection) origin); + if (s == null) + return; + this.source = s.getPlayerCharacter(); + } - /** - * Copy constructor - */ - public ChatCSRMsg(ChatCSRMsg msg) { - super(msg); - } + /** + * Copy constructor + */ + public ChatCSRMsg(ChatCSRMsg msg) { + super(msg); + } - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - reader.getInt(); - reader.getLong(); - this.message = reader.getString(); - reader.getInt(); // pad - this.unknown02 = reader.getInt(); - } + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.getInt(); + reader.getLong(); + this.message = reader.getString(); + reader.getInt(); // pad + this.unknown02 = reader.getInt(); + } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.source.getObjectType().ordinal()); - writer.putInt(this.source.getObjectUUID()); - writer.putInt(this.unknown01); - writer.putString(this.message); + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.source.getObjectType().ordinal()); + writer.putInt(this.source.getObjectUUID()); + writer.putInt(this.unknown01); + writer.putString(this.message); writer.putString(this.source.getName()); writer.putInt(WorldServer.worldMapID); - } + } } diff --git a/src/engine/net/client/msg/chat/ChatCityMsg.java b/src/engine/net/client/msg/chat/ChatCityMsg.java index f8e060d4..b39bef3c 100644 --- a/src/engine/net/client/msg/chat/ChatCityMsg.java +++ b/src/engine/net/client/msg/chat/ChatCityMsg.java @@ -22,67 +22,65 @@ import engine.server.world.WorldServer; public class ChatCityMsg extends AbstractChatMsg { - /** - * This is the general purpose constructor. - */ - public ChatCityMsg(AbstractWorldObject source, String message) { - super(Protocol.CHATCITY, source, message); - } + /** + * This is the general purpose constructor. + */ + public ChatCityMsg(AbstractWorldObject source, String message) { + super(Protocol.CHATCITY, source, message); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ChatCityMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CHATCITY, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ChatCityMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CHATCITY, origin, reader); + } - /** - * Copy constructor - */ - public ChatCityMsg(ChatCityMsg msg) { - super(msg); - } + /** + * Copy constructor + */ + public ChatCityMsg(ChatCityMsg msg) { + super(msg); + } - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - long sourceID = reader.getLong(); - int objectUUID = AbstractGameObject.extractUUID(GameObjectType.PlayerCharacter, sourceID); - this.source = SessionManager.getPlayerCharacterByID(objectUUID); - this.unknown01 = reader.getInt(); - this.message = reader.getString(); - this.sourceName = reader.getString(); - this.unknown02 = reader.getInt(); - } + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + long sourceID = reader.getLong(); + int objectUUID = AbstractGameObject.extractUUID(GameObjectType.PlayerCharacter, sourceID); + this.source = SessionManager.getPlayerCharacterByID(objectUUID); + this.unknown01 = reader.getInt(); + this.message = reader.getString(); + this.sourceName = reader.getString(); + this.unknown02 = reader.getInt(); + } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - // TODO Implement Serialize - if (this.source != null){ - writer.putInt(source.getObjectType().ordinal()); - writer.putInt(source.getObjectUUID()); - } - - else - writer.putLong(0L); - writer.putInt(0); - writer.putString(this.message); - if (this.source == null) { - // TODO log error here - writer.putString(""); - writer.putInt(0); - } else { + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + // TODO Implement Serialize + if (this.source != null) { + writer.putInt(source.getObjectType().ordinal()); + writer.putInt(source.getObjectUUID()); + } else + writer.putLong(0L); + writer.putInt(0); + writer.putString(this.message); + if (this.source == null) { + // TODO log error here + writer.putString(""); + writer.putInt(0); + } else { writer.putString(((AbstractCharacter) this.source).getFirstName()); writer.putInt(WorldServer.worldMapID); - } - } + } + } } diff --git a/src/engine/net/client/msg/chat/ChatGlobalMsg.java b/src/engine/net/client/msg/chat/ChatGlobalMsg.java index 650901ab..f7658ddd 100644 --- a/src/engine/net/client/msg/chat/ChatGlobalMsg.java +++ b/src/engine/net/client/msg/chat/ChatGlobalMsg.java @@ -20,70 +20,70 @@ import engine.server.world.WorldServer; public class ChatGlobalMsg extends AbstractChatMsg { - /** - * This is the general purpose constructor. - */ - - //chat global is using leader channel protocolMsg now. - public ChatGlobalMsg(AbstractWorldObject source, String message) { - super(Protocol.LEADERCHANNELMESSAGE, source, message); - } + /** + * This is the general purpose constructor. + */ - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ChatGlobalMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.LEADERCHANNELMESSAGE, origin, reader); - } + //chat global is using leader channel protocolMsg now. + public ChatGlobalMsg(AbstractWorldObject source, String message) { + super(Protocol.LEADERCHANNELMESSAGE, source, message); + } - /** - * Copy constructor - */ - public ChatGlobalMsg(ChatGlobalMsg msg) { - super(msg); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ChatGlobalMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.LEADERCHANNELMESSAGE, origin, reader); + } - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.unknown01 = reader.getInt(); + /** + * Copy constructor + */ + public ChatGlobalMsg(ChatGlobalMsg msg) { + super(msg); + } - this.message = reader.getString(); - this.sourceName = reader.getString(); + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - - } + this.message = reader.getString(); + this.sourceName = reader.getString(); - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.putInt(this.unknown01); - writer.putString(this.message); - if (this.source == null) { - // TODO log error here - writer.putString(""); - writer.putInt(0); - } else { + this.unknown02 = reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.putInt(this.unknown01); + writer.putString(this.message); + if (this.source == null) { + // TODO log error here + writer.putString(""); + writer.putInt(0); + } else { writer.putString(((AbstractCharacter) this.source).getFirstName()); writer.putInt(WorldServer.worldMapID); - } - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - } + } + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + } } diff --git a/src/engine/net/client/msg/chat/ChatGroupMsg.java b/src/engine/net/client/msg/chat/ChatGroupMsg.java index 72fd375f..15bbe6a1 100644 --- a/src/engine/net/client/msg/chat/ChatGroupMsg.java +++ b/src/engine/net/client/msg/chat/ChatGroupMsg.java @@ -18,58 +18,58 @@ import engine.objects.AbstractWorldObject; public class ChatGroupMsg extends AbstractChatMsg { - /** - * This is the general purpose constructor. - */ - public ChatGroupMsg(AbstractWorldObject source, String message) { - super(Protocol.CHATGROUP, source, message); - } + /** + * This is the general purpose constructor. + */ + public ChatGroupMsg(AbstractWorldObject source, String message) { + super(Protocol.CHATGROUP, source, message); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ChatGroupMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CHATGROUP, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ChatGroupMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CHATGROUP, origin, reader); + } - /** - * Copy constructor - */ - public ChatGroupMsg(ChatGroupMsg msg) { - super(msg); - } + /** + * Copy constructor + */ + public ChatGroupMsg(ChatGroupMsg msg) { + super(msg); + } - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.unknown01 = reader.getInt(); + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.unknown01 = reader.getInt(); - this.message = reader.getString(); - this.sourceName = reader.getString(); + this.message = reader.getString(); + this.sourceName = reader.getString(); - this.unknown02 = reader.getInt(); - } + this.unknown02 = reader.getInt(); + } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.putInt(this.unknown01); + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.putInt(this.unknown01); - writer.putString(this.message); - writer.putString(this.sourceName); + writer.putString(this.message); + writer.putString(this.sourceName); - writer.putInt(this.unknown02); - } + writer.putInt(this.unknown02); + } } diff --git a/src/engine/net/client/msg/chat/ChatGuildMsg.java b/src/engine/net/client/msg/chat/ChatGuildMsg.java index 94b77de6..8974654e 100644 --- a/src/engine/net/client/msg/chat/ChatGuildMsg.java +++ b/src/engine/net/client/msg/chat/ChatGuildMsg.java @@ -18,136 +18,132 @@ import engine.objects.AbstractWorldObject; public class ChatGuildMsg extends AbstractChatMsg { - protected int unknown03; - protected int unknown04; - protected int unknown05; - protected int unknown06; - - /** - * This is the general purpose constructor. - */ - public ChatGuildMsg(AbstractWorldObject source, String message) { - super(Protocol.CHATGUILD, source, message); - this.unknown03 = 0; - this.unknown04 = 0; - this.unknown05 = 0; - this.unknown06 = 0; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ChatGuildMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CHATGUILD, origin, reader); - } - - /** - * Copy constructor - */ - public ChatGuildMsg(ChatGuildMsg msg) { - super(msg); + protected int unknown03; + protected int unknown04; + protected int unknown05; + protected int unknown06; + + /** + * This is the general purpose constructor. + */ + public ChatGuildMsg(AbstractWorldObject source, String message) { + super(Protocol.CHATGUILD, source, message); + this.unknown03 = 0; + this.unknown04 = 0; + this.unknown05 = 0; + this.unknown06 = 0; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ChatGuildMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CHATGUILD, origin, reader); + } + + /** + * Copy constructor + */ + public ChatGuildMsg(ChatGuildMsg msg) { + super(msg); this.unknown03 = msg.unknown03; this.unknown04 = msg.unknown04; this.unknown05 = msg.unknown05; this.unknown06 = msg.unknown06; - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.unknown01 = reader.getInt(); - this.message = reader.getString(); - this.unknown02 = reader.getInt(); - this.sourceName = reader.getString(); - this.unknown03 = reader.getInt(); - this.unknown04 = reader.getInt(); - this.unknown05 = reader.getInt(); - this.unknown06 = reader.getInt(); - } - - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.putInt(this.unknown01); - writer.putString(this.message); - writer.putInt(this.unknown02); - writer.putString(this.sourceName); - writer.putInt(this.unknown03); - writer.putInt(this.unknown04); - writer.putInt(this.unknown05); - writer.putInt(this.unknown06); - } - - /** - * @return the unknown03 - */ - public int getUnknown03() { - return unknown03; - } - - /** - * @param unknown03 - * the unknown03 to set - */ - public void setUnknown03(int unknown03) { - this.unknown03 = unknown03; - } - - /** - * @return the unknown04 - */ - public int getUnknown04() { - return unknown04; - } - - /** - * @param unknown04 - * the unknown04 to set - */ - public void setUnknown04(int unknown04) { - this.unknown04 = unknown04; - } - - /** - * @return the unknown05 - */ - public int getUnknown05() { - return unknown05; - } - - /** - * @param unknown05 - * the unknown05 to set - */ - public void setUnknown05(int unknown05) { - this.unknown05 = unknown05; - } - - /** - * @return the unknown06 - */ - public int getUnknown06() { - return unknown06; - } - - /** - * @param unknown06 - * the unknown06 to set - */ - public void setUnknown06(int unknown06) { - this.unknown06 = unknown06; - } + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.unknown01 = reader.getInt(); + this.message = reader.getString(); + this.unknown02 = reader.getInt(); + this.sourceName = reader.getString(); + this.unknown03 = reader.getInt(); + this.unknown04 = reader.getInt(); + this.unknown05 = reader.getInt(); + this.unknown06 = reader.getInt(); + } + + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.putInt(this.unknown01); + writer.putString(this.message); + writer.putInt(this.unknown02); + writer.putString(this.sourceName); + writer.putInt(this.unknown03); + writer.putInt(this.unknown04); + writer.putInt(this.unknown05); + writer.putInt(this.unknown06); + } + + /** + * @return the unknown03 + */ + public int getUnknown03() { + return unknown03; + } + + /** + * @param unknown03 the unknown03 to set + */ + public void setUnknown03(int unknown03) { + this.unknown03 = unknown03; + } + + /** + * @return the unknown04 + */ + public int getUnknown04() { + return unknown04; + } + + /** + * @param unknown04 the unknown04 to set + */ + public void setUnknown04(int unknown04) { + this.unknown04 = unknown04; + } + + /** + * @return the unknown05 + */ + public int getUnknown05() { + return unknown05; + } + + /** + * @param unknown05 the unknown05 to set + */ + public void setUnknown05(int unknown05) { + this.unknown05 = unknown05; + } + + /** + * @return the unknown06 + */ + public int getUnknown06() { + return unknown06; + } + + /** + * @param unknown06 the unknown06 to set + */ + public void setUnknown06(int unknown06) { + this.unknown06 = unknown06; + } } diff --git a/src/engine/net/client/msg/chat/ChatICMsg.java b/src/engine/net/client/msg/chat/ChatICMsg.java index cc50d26a..b2d3dfe4 100644 --- a/src/engine/net/client/msg/chat/ChatICMsg.java +++ b/src/engine/net/client/msg/chat/ChatICMsg.java @@ -18,115 +18,112 @@ import engine.objects.AbstractWorldObject; public class ChatICMsg extends AbstractChatMsg { - protected int unknown03; - protected int unknown04; - protected int unknown05; - - /** - * This is the general purpose constructor. - */ - public ChatICMsg(AbstractWorldObject source, String message) { - super(Protocol.CHATIC, source, message); - this.unknown03 = 0; - this.unknown04 = 0; - this.unknown05 = 0; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ChatICMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CHATIC, origin, reader); - } - - /** - * Copy constructor - */ - public ChatICMsg(ChatICMsg msg) { - super(msg); + protected int unknown03; + protected int unknown04; + protected int unknown05; + + /** + * This is the general purpose constructor. + */ + public ChatICMsg(AbstractWorldObject source, String message) { + super(Protocol.CHATIC, source, message); + this.unknown03 = 0; + this.unknown04 = 0; + this.unknown05 = 0; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ChatICMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CHATIC, origin, reader); + } + + /** + * Copy constructor + */ + public ChatICMsg(ChatICMsg msg) { + super(msg); this.unknown03 = msg.unknown03; this.unknown04 = msg.unknown04; this.unknown05 = msg.unknown05; - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.unknown01 = reader.getInt(); - this.message = reader.getString(); - this.sourceName = reader.getString(); - this.unknown02 = reader.getInt(); - this.unknown03 = reader.getInt(); - this.unknown04 = reader.getInt(); - this.unknown05 = reader.getInt(); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.putInt(this.unknown01); - writer.putString(this.message); - writer.putString(this.sourceName); - writer.putInt(this.unknown02); - writer.putInt(this.unknown03); - writer.putInt(this.unknown04); - writer.putInt(this.unknown05); - } - - /** - * @return the unknown03 - */ - public int getUnknown03() { - return unknown03; - } - - /** - * @param unknown03 - * the unknown03 to set - */ - public void setUnknown03(int unknown03) { - this.unknown03 = unknown03; - } - - /** - * @return the unknown04 - */ - public int getUnknown04() { - return unknown04; - } - - /** - * @param unknown04 - * the unknown04 to set - */ - public void setUnknown04(int unknown04) { - this.unknown04 = unknown04; - } - - /** - * @return the unknown05 - */ - public int getUnknown05() { - return unknown05; - } - - /** - * @param unknown05 - * the unknown05 to set - */ - public void setUnknown05(int unknown05) { - this.unknown05 = unknown05; - } + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.unknown01 = reader.getInt(); + this.message = reader.getString(); + this.sourceName = reader.getString(); + this.unknown02 = reader.getInt(); + this.unknown03 = reader.getInt(); + this.unknown04 = reader.getInt(); + this.unknown05 = reader.getInt(); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.putInt(this.unknown01); + writer.putString(this.message); + writer.putString(this.sourceName); + writer.putInt(this.unknown02); + writer.putInt(this.unknown03); + writer.putInt(this.unknown04); + writer.putInt(this.unknown05); + } + + /** + * @return the unknown03 + */ + public int getUnknown03() { + return unknown03; + } + + /** + * @param unknown03 the unknown03 to set + */ + public void setUnknown03(int unknown03) { + this.unknown03 = unknown03; + } + + /** + * @return the unknown04 + */ + public int getUnknown04() { + return unknown04; + } + + /** + * @param unknown04 the unknown04 to set + */ + public void setUnknown04(int unknown04) { + this.unknown04 = unknown04; + } + + /** + * @return the unknown05 + */ + public int getUnknown05() { + return unknown05; + } + + /** + * @param unknown05 the unknown05 to set + */ + public void setUnknown05(int unknown05) { + this.unknown05 = unknown05; + } } \ No newline at end of file diff --git a/src/engine/net/client/msg/chat/ChatInfoMsg.java b/src/engine/net/client/msg/chat/ChatInfoMsg.java index d39b4c85..5645e8d0 100644 --- a/src/engine/net/client/msg/chat/ChatInfoMsg.java +++ b/src/engine/net/client/msg/chat/ChatInfoMsg.java @@ -18,43 +18,43 @@ import engine.objects.AbstractWorldObject; public class ChatInfoMsg extends AbstractChatMsg { - /** - * This is the general purpose constructor. - */ - public ChatInfoMsg(AbstractWorldObject source, String message) { - super(Protocol.CHATINFO, source, message); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ChatInfoMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CHATINFO, origin, reader); - } - - /** - * Copy constructor - */ - public ChatInfoMsg(ChatInfoMsg msg) { - super(msg); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - // TODO Implement Serialization - } + /** + * This is the general purpose constructor. + */ + public ChatInfoMsg(AbstractWorldObject source, String message) { + super(Protocol.CHATINFO, source, message); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ChatInfoMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CHATINFO, origin, reader); + } + + /** + * Copy constructor + */ + public ChatInfoMsg(ChatInfoMsg msg) { + super(msg); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + // TODO Implement Serialization + } } diff --git a/src/engine/net/client/msg/chat/ChatLeaderMsg.java b/src/engine/net/client/msg/chat/ChatLeaderMsg.java index 82f57281..7f83f1ed 100644 --- a/src/engine/net/client/msg/chat/ChatLeaderMsg.java +++ b/src/engine/net/client/msg/chat/ChatLeaderMsg.java @@ -18,134 +18,130 @@ import engine.objects.AbstractWorldObject; public class ChatLeaderMsg extends AbstractChatMsg { - protected int unknown03; - protected int unknown04; - protected int unknown05; - protected int unknown06; - - /** - * This is the general purpose constructor. - */ - public ChatLeaderMsg(AbstractWorldObject source, String message) { - super(Protocol.LEADERCHANNELMESSAGE, source, message); - this.unknown03 = 0; - this.unknown04 = 0; - this.unknown05 = 0; - this.unknown06 = 0; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ChatLeaderMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.LEADERCHANNELMESSAGE, origin, reader); - } - - /** - * Copy constructor - */ - public ChatLeaderMsg(ChatLeaderMsg msg) { - super(msg); + protected int unknown03; + protected int unknown04; + protected int unknown05; + protected int unknown06; + + /** + * This is the general purpose constructor. + */ + public ChatLeaderMsg(AbstractWorldObject source, String message) { + super(Protocol.LEADERCHANNELMESSAGE, source, message); + this.unknown03 = 0; + this.unknown04 = 0; + this.unknown05 = 0; + this.unknown06 = 0; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ChatLeaderMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.LEADERCHANNELMESSAGE, origin, reader); + } + + /** + * Copy constructor + */ + public ChatLeaderMsg(ChatLeaderMsg msg) { + super(msg); this.unknown03 = msg.unknown03; this.unknown04 = msg.unknown04; this.unknown05 = msg.unknown05; this.unknown06 = msg.unknown06; - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.unknown01 = reader.getInt(); - this.message = reader.getString(); - this.sourceName = reader.getString(); - this.unknown03 = reader.getInt(); - this.unknown04 = reader.getInt(); - this.unknown05 = reader.getInt(); - this.unknown06 = reader.getInt(); - } - - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.putInt(this.unknown01); - writer.putString(this.message); - writer.putString(this.sourceName); - writer.putInt(this.unknown03); - writer.putInt(this.unknown04); - writer.putInt(this.unknown05); - writer.putInt(this.unknown06); - } - - /** - * @return the unknown03 - */ - public int getUnknown03() { - return unknown03; - } - - /** - * @param unknown03 - * the unknown03 to set - */ - public void setUnknown03(int unknown03) { - this.unknown03 = unknown03; - } - - /** - * @return the unknown04 - */ - public int getUnknown04() { - return unknown04; - } - - /** - * @param unknown04 - * the unknown04 to set - */ - public void setUnknown04(int unknown04) { - this.unknown04 = unknown04; - } - - /** - * @return the unknown05 - */ - public int getUnknown05() { - return unknown05; - } - - /** - * @param unknown05 - * the unknown05 to set - */ - public void setUnknown05(int unknown05) { - this.unknown05 = unknown05; - } - - /** - * @return the unknown06 - */ - public int getUnknown06() { - return unknown06; - } - - /** - * @param unknown06 - * the unknown06 to set - */ - public void setUnknown06(int unknown06) { - this.unknown06 = unknown06; - } + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.unknown01 = reader.getInt(); + this.message = reader.getString(); + this.sourceName = reader.getString(); + this.unknown03 = reader.getInt(); + this.unknown04 = reader.getInt(); + this.unknown05 = reader.getInt(); + this.unknown06 = reader.getInt(); + } + + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.putInt(this.unknown01); + writer.putString(this.message); + writer.putString(this.sourceName); + writer.putInt(this.unknown03); + writer.putInt(this.unknown04); + writer.putInt(this.unknown05); + writer.putInt(this.unknown06); + } + + /** + * @return the unknown03 + */ + public int getUnknown03() { + return unknown03; + } + + /** + * @param unknown03 the unknown03 to set + */ + public void setUnknown03(int unknown03) { + this.unknown03 = unknown03; + } + + /** + * @return the unknown04 + */ + public int getUnknown04() { + return unknown04; + } + + /** + * @param unknown04 the unknown04 to set + */ + public void setUnknown04(int unknown04) { + this.unknown04 = unknown04; + } + + /** + * @return the unknown05 + */ + public int getUnknown05() { + return unknown05; + } + + /** + * @param unknown05 the unknown05 to set + */ + public void setUnknown05(int unknown05) { + this.unknown05 = unknown05; + } + + /** + * @return the unknown06 + */ + public int getUnknown06() { + return unknown06; + } + + /** + * @param unknown06 the unknown06 to set + */ + public void setUnknown06(int unknown06) { + this.unknown06 = unknown06; + } } diff --git a/src/engine/net/client/msg/chat/ChatPvPMsg.java b/src/engine/net/client/msg/chat/ChatPvPMsg.java index dd93f139..a84610af 100644 --- a/src/engine/net/client/msg/chat/ChatPvPMsg.java +++ b/src/engine/net/client/msg/chat/ChatPvPMsg.java @@ -18,70 +18,69 @@ import engine.objects.AbstractWorldObject; public class ChatPvPMsg extends AbstractChatMsg { - protected int unknown03; + protected int unknown03; - /** - * This is the general purpose constructor. - */ - public ChatPvPMsg(AbstractWorldObject source, String message) { - super(Protocol.CHATPVP, source, message); - this.unknown03 = 0; - } + /** + * This is the general purpose constructor. + */ + public ChatPvPMsg(AbstractWorldObject source, String message) { + super(Protocol.CHATPVP, source, message); + this.unknown03 = 0; + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ChatPvPMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CHATPVP, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ChatPvPMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CHATPVP, origin, reader); + } - /** - * Copy constructor - */ - public ChatPvPMsg(ChatPvPMsg msg) { - super(msg); + /** + * Copy constructor + */ + public ChatPvPMsg(ChatPvPMsg msg) { + super(msg); this.unknown03 = msg.unknown03; - } + } - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - this.unknown03 = reader.getInt(); - this.message = reader.getString(); - } + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + this.unknown03 = reader.getInt(); + this.message = reader.getString(); + } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(0); // Probably Type - writer.putInt(0); // Probably objectUUID - writer.putInt(0); + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(0); // Probably Type + writer.putInt(0); // Probably objectUUID + writer.putInt(0); - writer.putString(this.message); - } + writer.putString(this.message); + } - /** - * @return the unknown03 - */ - public int getUnknown03() { - return unknown03; - } + /** + * @return the unknown03 + */ + public int getUnknown03() { + return unknown03; + } - /** - * @param unknown03 - * the unknown03 to set - */ - public void setUnknown03(int unknown03) { - this.unknown03 = unknown03; - } + /** + * @param unknown03 the unknown03 to set + */ + public void setUnknown03(int unknown03) { + this.unknown03 = unknown03; + } } diff --git a/src/engine/net/client/msg/chat/ChatSayMsg.java b/src/engine/net/client/msg/chat/ChatSayMsg.java index a0a0b525..a50e93d0 100644 --- a/src/engine/net/client/msg/chat/ChatSayMsg.java +++ b/src/engine/net/client/msg/chat/ChatSayMsg.java @@ -22,70 +22,69 @@ import engine.server.world.WorldServer; public class ChatSayMsg extends AbstractChatMsg { - /** - * This is the general purpose constructor. - */ - public ChatSayMsg(AbstractWorldObject source, String message) { - super(Protocol.CHATSAY, source, message); - } + /** + * This is the general purpose constructor. + */ + public ChatSayMsg(AbstractWorldObject source, String message) { + super(Protocol.CHATSAY, source, message); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ChatSayMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CHATSAY, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ChatSayMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CHATSAY, origin, reader); + } - /** - * Copy constructor - */ - public ChatSayMsg(ChatSayMsg msg) { - super(msg); - } + /** + * Copy constructor + */ + public ChatSayMsg(ChatSayMsg msg) { + super(msg); + } - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { - long sourceID = reader.getLong(); - this.unknown01 = reader.getInt(); + long sourceID = reader.getLong(); + this.unknown01 = reader.getInt(); - int objectUUID = AbstractGameObject.extractUUID(GameObjectType.PlayerCharacter, sourceID); - this.source = SessionManager.getPlayerCharacterByID(objectUUID); + int objectUUID = AbstractGameObject.extractUUID(GameObjectType.PlayerCharacter, sourceID); + this.source = SessionManager.getPlayerCharacterByID(objectUUID); - // this.unknown01 = reader.getInt(); //not needed? - this.message = reader.getString(); + // this.unknown01 = reader.getInt(); //not needed? + this.message = reader.getString(); - this.sourceName = reader.getString(); - this.unknown02 = reader.getInt(); - } + this.sourceName = reader.getString(); + this.unknown02 = reader.getInt(); + } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { - if (this.source != null){ - writer.putInt(this.source.getObjectType().ordinal()); - writer.putInt(source.getObjectUUID()); - } - else - writer.putLong(0L); - writer.putInt(0); - writer.putString(this.message); - if (this.source == null) { - // TODO log error here - writer.putString(""); - writer.putInt(0); - } else { + if (this.source != null) { + writer.putInt(this.source.getObjectType().ordinal()); + writer.putInt(source.getObjectUUID()); + } else + writer.putLong(0L); + writer.putInt(0); + writer.putString(this.message); + if (this.source == null) { + // TODO log error here + writer.putString(""); + writer.putInt(0); + } else { writer.putString(((AbstractCharacter) this.source).getFirstName()); writer.putInt(WorldServer.worldMapID); - } - } + } + } } diff --git a/src/engine/net/client/msg/chat/ChatShoutMsg.java b/src/engine/net/client/msg/chat/ChatShoutMsg.java index e9571a37..761f13dd 100644 --- a/src/engine/net/client/msg/chat/ChatShoutMsg.java +++ b/src/engine/net/client/msg/chat/ChatShoutMsg.java @@ -20,61 +20,61 @@ import engine.server.world.WorldServer; public class ChatShoutMsg extends AbstractChatMsg { - /** - * This is the general purpose constructor. - */ - public ChatShoutMsg(AbstractWorldObject source, String message) { - super(Protocol.CHATSHOUT, source, message); - } + /** + * This is the general purpose constructor. + */ + public ChatShoutMsg(AbstractWorldObject source, String message) { + super(Protocol.CHATSHOUT, source, message); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ChatShoutMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CHATSHOUT, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ChatShoutMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CHATSHOUT, origin, reader); + } - /** - * Copy constructor - */ - public ChatShoutMsg(ChatShoutMsg msg) { - super(msg); - } + /** + * Copy constructor + */ + public ChatShoutMsg(ChatShoutMsg msg) { + super(msg); + } - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.unknown01 = reader.getInt(); + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.unknown01 = reader.getInt(); - this.message = reader.getString(); - this.sourceName = reader.getString(); + this.message = reader.getString(); + this.sourceName = reader.getString(); - this.unknown02 = reader.getInt(); - } + this.unknown02 = reader.getInt(); + } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.putInt(this.unknown01); - writer.putString(this.message); - if (this.source == null) { - // TODO log error here - writer.putString(""); - writer.putInt(0); - } else { + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.putInt(this.unknown01); + writer.putString(this.message); + if (this.source == null) { + // TODO log error here + writer.putString(""); + writer.putInt(0); + } else { writer.putString(((AbstractCharacter) this.source).getFirstName()); writer.putInt(WorldServer.worldMapID); - } - } + } + } } diff --git a/src/engine/net/client/msg/chat/ChatSystemChannelMsg.java b/src/engine/net/client/msg/chat/ChatSystemChannelMsg.java index 33c96e7d..30e1f1a9 100644 --- a/src/engine/net/client/msg/chat/ChatSystemChannelMsg.java +++ b/src/engine/net/client/msg/chat/ChatSystemChannelMsg.java @@ -18,145 +18,141 @@ import engine.objects.AbstractWorldObject; public class ChatSystemChannelMsg extends AbstractChatMsg { - // TODO enum this? - - // messageType - // 1 = Error - // 2 = Info - // 3 = Message of the Day - protected int messageType; - - protected int unknown03; - protected int unknown04; - - protected int channel; - - /** - * This is the general purpose constructor. - */ - public ChatSystemChannelMsg(AbstractWorldObject source, String message, int messageType) { - super(Protocol.SYSTEMCHANNEL, source, message); - this.channel = 0; - this.messageType = messageType; - this.unknown03 = 0; - this.unknown04 = 0; - } - - /** - * Copy constructor - */ - public ChatSystemChannelMsg(ChatSystemChannelMsg msg) { - super(msg); + // TODO enum this? + + // messageType + // 1 = Error + // 2 = Info + // 3 = Message of the Day + protected int messageType; + + protected int unknown03; + protected int unknown04; + + protected int channel; + + /** + * This is the general purpose constructor. + */ + public ChatSystemChannelMsg(AbstractWorldObject source, String message, int messageType) { + super(Protocol.SYSTEMCHANNEL, source, message); + this.channel = 0; + this.messageType = messageType; + this.unknown03 = 0; + this.unknown04 = 0; + } + + /** + * Copy constructor + */ + public ChatSystemChannelMsg(ChatSystemChannelMsg msg) { + super(msg); this.messageType = msg.messageType; this.unknown03 = msg.unknown03; this.unknown04 = msg.unknown04; this.channel = msg.channel; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ChatSystemChannelMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.SYSTEMCHANNEL, origin, reader); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.channel = reader.getInt(); - this.messageType = reader.getInt(); - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.message = reader.getString(); - this.unknown03 = reader.getInt(); - this.unknown04 = reader.getInt(); // seems to alternate beween 0x0 and - // 0x40C30000 - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.channel); - writer.putInt(this.messageType); - if (this.source != null) - ;// writer.putLong(this.source.getCompositeID()); - else - // writer.putLong(0L); - writer.putString(this.message); - writer.putInt(this.unknown03); - writer.putInt(this.unknown04); - - /* - * for (String key : this.vars.keySet()) { writer.putString(key); - * writer.putString(this.vars.get(key)); } - */ - } - - /** - * @return the channel - */ - public int getChannel() { - return channel; - } - - /** - * @param channel - * the channel to set - */ - public void setChannel(int channel) { - this.channel = channel; - } - - /** - * @return the messageType - */ - public int getMessageType() { - return messageType; - } - - /** - * @param messageType - * the messageType to set - */ - public void setMessageType(int messageType) { - this.messageType = messageType; - } - - /** - * @return the unknown03 - */ - public int getUnknown03() { - return unknown03; - } - - /** - * @param unknown03 - * the unknown03 to set - */ - public void setUnknown03(int unknown03) { - this.unknown03 = unknown03; - } - - /** - * @return the unknown04 - */ - public int getUnknown04() { - return unknown04; - } - - /** - * @param unknown04 - * the unknown04 to set - */ - public void setUnknown04(int unknown04) { - this.unknown04 = unknown04; - } + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ChatSystemChannelMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SYSTEMCHANNEL, origin, reader); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.channel = reader.getInt(); + this.messageType = reader.getInt(); + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.message = reader.getString(); + this.unknown03 = reader.getInt(); + this.unknown04 = reader.getInt(); // seems to alternate beween 0x0 and + // 0x40C30000 + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.channel); + writer.putInt(this.messageType); + if (this.source != null) + ;// writer.putLong(this.source.getCompositeID()); + else + // writer.putLong(0L); + writer.putString(this.message); + writer.putInt(this.unknown03); + writer.putInt(this.unknown04); + + /* + * for (String key : this.vars.keySet()) { writer.putString(key); + * writer.putString(this.vars.get(key)); } + */ + } + + /** + * @return the channel + */ + public int getChannel() { + return channel; + } + + /** + * @param channel the channel to set + */ + public void setChannel(int channel) { + this.channel = channel; + } + + /** + * @return the messageType + */ + public int getMessageType() { + return messageType; + } + + /** + * @param messageType the messageType to set + */ + public void setMessageType(int messageType) { + this.messageType = messageType; + } + + /** + * @return the unknown03 + */ + public int getUnknown03() { + return unknown03; + } + + /** + * @param unknown03 the unknown03 to set + */ + public void setUnknown03(int unknown03) { + this.unknown03 = unknown03; + } + + /** + * @return the unknown04 + */ + public int getUnknown04() { + return unknown04; + } + + /** + * @param unknown04 the unknown04 to set + */ + public void setUnknown04(int unknown04) { + this.unknown04 = unknown04; + } } diff --git a/src/engine/net/client/msg/chat/ChatSystemMsg.java b/src/engine/net/client/msg/chat/ChatSystemMsg.java index e6e61968..29b412fa 100644 --- a/src/engine/net/client/msg/chat/ChatSystemMsg.java +++ b/src/engine/net/client/msg/chat/ChatSystemMsg.java @@ -22,182 +22,178 @@ import java.util.concurrent.ConcurrentHashMap; public class ChatSystemMsg extends AbstractChatMsg { - // TODO enum this? - - // channel - // 1 = System - // 2 = General Announcement (Flashing at top of screen!) - // 3 = Commander - // 5 = Nation - // 6 = Leader - // 7 = Shout - // 8 = Siege - // 9 = Territory - // 10 = Info - // 12 = Guild - // 13 = Inner Council - // 14 = Group - // 15 = City - // 16 = say - // 17 = Emote - // 19 = tell - protected int channel; - - // messageType - // 1 = Error - // 2 = Info - // 3 = Message of the Day - protected int messageType; - - protected int unknown03; - protected int numVariables; - // TODO this doesn't need to be a global value, - // its inherit to the HashMap - protected ConcurrentHashMap vars; - - // TODO make a list of variables - /** - * This is the general purpose constructor. - */ - public ChatSystemMsg(AbstractWorldObject source, String message) { - super(Protocol.SYSTEMBROADCASTCHANNEL, source, message); - this.messageType = 2; - this.unknown03 = 0; - this.numVariables = 0; - vars = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ChatSystemMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.SYSTEMBROADCASTCHANNEL, origin, reader); - } - - /** - * Copy constructor - */ - public ChatSystemMsg(ChatSystemMsg msg) { - super(msg); + // TODO enum this? + + // channel + // 1 = System + // 2 = General Announcement (Flashing at top of screen!) + // 3 = Commander + // 5 = Nation + // 6 = Leader + // 7 = Shout + // 8 = Siege + // 9 = Territory + // 10 = Info + // 12 = Guild + // 13 = Inner Council + // 14 = Group + // 15 = City + // 16 = say + // 17 = Emote + // 19 = tell + protected int channel; + + // messageType + // 1 = Error + // 2 = Info + // 3 = Message of the Day + protected int messageType; + + protected int unknown03; + protected int numVariables; + // TODO this doesn't need to be a global value, + // its inherit to the HashMap + protected ConcurrentHashMap vars; + + // TODO make a list of variables + + /** + * This is the general purpose constructor. + */ + public ChatSystemMsg(AbstractWorldObject source, String message) { + super(Protocol.SYSTEMBROADCASTCHANNEL, source, message); + this.messageType = 2; + this.unknown03 = 0; + this.numVariables = 0; + vars = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ChatSystemMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SYSTEMBROADCASTCHANNEL, origin, reader); + } + + /** + * Copy constructor + */ + public ChatSystemMsg(ChatSystemMsg msg) { + super(msg); this.channel = msg.channel; this.messageType = msg.messageType; this.unknown03 = msg.unknown03; this.numVariables = msg.numVariables; this.vars = msg.vars; - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.vars = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - - this.channel = reader.getInt(); - this.messageType = reader.getInt(); - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - - this.message = reader.getString(); - this.unknown03 = reader.getInt(); - this.numVariables = reader.getInt(); - - for (int i = 0; i < this.numVariables; ++i) { - String key = reader.getString(); - String value = reader.getString(); - reader.get(); - this.vars.put(key, value); - } - - } - - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.channel); - writer.putInt(this.messageType); - if (this.source != null){ - writer.putInt(source.getObjectType().ordinal()); - writer.putInt(source.getObjectUUID()); - } - else - writer.putLong(0L); - writer.putString(this.message); - writer.putInt(this.unknown03); - writer.putInt(this.numVariables); - - for (String key : this.vars.keySet()) { - writer.putString(key); - writer.putString(this.vars.get(key)); - } - } - - /** - * @return the channel - */ - public int getChannel() { - return channel; - } - - /** - * @param channel - * the channel to set - */ - public void setChannel(int channel) { - this.channel = channel; - } - - /** - * @return the messageType - */ - public int getMessageType() { - return messageType; - } - - /** - * @param messageType - * the messageType to set - */ - public void setMessageType(int messageType) { - this.messageType = messageType; - } - - /** - * @return the unknown03 - */ - public int getUnknown03() { - return unknown03; - } - - /** - * @param unknown03 - * the unknown03 to set - */ - public void setUnknown03(int unknown03) { - this.unknown03 = unknown03; - } - - /** - * @return the numVariables - */ - public int getNumVariables() { - return numVariables; - } - - - - /** - * @return the vars - */ - public ConcurrentHashMap getVars() { - return vars; - } + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.vars = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + + this.channel = reader.getInt(); + this.messageType = reader.getInt(); + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + + this.message = reader.getString(); + this.unknown03 = reader.getInt(); + this.numVariables = reader.getInt(); + + for (int i = 0; i < this.numVariables; ++i) { + String key = reader.getString(); + String value = reader.getString(); + reader.get(); + this.vars.put(key, value); + } + + } + + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.channel); + writer.putInt(this.messageType); + if (this.source != null) { + writer.putInt(source.getObjectType().ordinal()); + writer.putInt(source.getObjectUUID()); + } else + writer.putLong(0L); + writer.putString(this.message); + writer.putInt(this.unknown03); + writer.putInt(this.numVariables); + + for (String key : this.vars.keySet()) { + writer.putString(key); + writer.putString(this.vars.get(key)); + } + } + + /** + * @return the channel + */ + public int getChannel() { + return channel; + } + + /** + * @param channel the channel to set + */ + public void setChannel(int channel) { + this.channel = channel; + } + + /** + * @return the messageType + */ + public int getMessageType() { + return messageType; + } + + /** + * @param messageType the messageType to set + */ + public void setMessageType(int messageType) { + this.messageType = messageType; + } + + /** + * @return the unknown03 + */ + public int getUnknown03() { + return unknown03; + } + + /** + * @param unknown03 the unknown03 to set + */ + public void setUnknown03(int unknown03) { + this.unknown03 = unknown03; + } + + /** + * @return the numVariables + */ + public int getNumVariables() { + return numVariables; + } + + + /** + * @return the vars + */ + public ConcurrentHashMap getVars() { + return vars; + } } diff --git a/src/engine/net/client/msg/chat/ChatTellMsg.java b/src/engine/net/client/msg/chat/ChatTellMsg.java index 61c62be7..fe60e679 100644 --- a/src/engine/net/client/msg/chat/ChatTellMsg.java +++ b/src/engine/net/client/msg/chat/ChatTellMsg.java @@ -20,92 +20,92 @@ import engine.server.world.WorldServer; public class ChatTellMsg extends AbstractChatMsg { - protected AbstractWorldObject target; - protected int targetType; - protected int targetID; - protected String targetName; - protected int unknown03; - - /** - * This is the general purpose constructor. - */ - public ChatTellMsg(AbstractWorldObject source, AbstractWorldObject target, String message) { - super(Protocol.CHATTELL, source, message); - this.target = target; - - // TODO could this be simplified? Check serializer; - if (this.target != null) { - this.targetType = target.getObjectType().ordinal(); - this.targetID = target.getObjectUUID(); - this.targetName = target.getName(); - } - this.unknown03 = 0; - } - - /** - * Copy constructor - */ - public ChatTellMsg(ChatTellMsg msg) { - super(msg); - this.target = msg.target; - this.targetType = msg.targetType; - this.targetID = msg.targetID; - this.targetName = msg.targetName; - this.unknown03 = msg.unknown03; - } - - public int getTargetType() { - return targetType; - } - - public int getTargetID() { - return targetID; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ChatTellMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CHATTELL, origin, reader); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.unknown01 = reader.getInt(); - this.message = reader.getString(); - this.sourceName = reader.getString(); // sourceName - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - this.targetName = reader.getString(); - this.unknown02 = reader.getInt(); - this.unknown03 = reader.getInt(); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.source.getObjectType().ordinal()); - writer.putInt(source.getObjectUUID()); - writer.putInt(this.unknown01); - writer.putString(this.message); - if (AbstractWorldObject.IsAbstractCharacter(source)) { - writer.putString(((AbstractCharacter) this.source).getFirstName()); - } else { - writer.putString(this.source.getName()); - } - if (this.target != null) { - writer.putInt(this.target.getObjectType().ordinal()); - writer.putInt(this.target.getObjectUUID()); + protected AbstractWorldObject target; + protected int targetType; + protected int targetID; + protected String targetName; + protected int unknown03; + + /** + * This is the general purpose constructor. + */ + public ChatTellMsg(AbstractWorldObject source, AbstractWorldObject target, String message) { + super(Protocol.CHATTELL, source, message); + this.target = target; + + // TODO could this be simplified? Check serializer; + if (this.target != null) { + this.targetType = target.getObjectType().ordinal(); + this.targetID = target.getObjectUUID(); + this.targetName = target.getName(); + } + this.unknown03 = 0; + } + + /** + * Copy constructor + */ + public ChatTellMsg(ChatTellMsg msg) { + super(msg); + this.target = msg.target; + this.targetType = msg.targetType; + this.targetID = msg.targetID; + this.targetName = msg.targetName; + this.unknown03 = msg.unknown03; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ChatTellMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CHATTELL, origin, reader); + } + + public int getTargetType() { + return targetType; + } + + public int getTargetID() { + return targetID; + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.unknown01 = reader.getInt(); + this.message = reader.getString(); + this.sourceName = reader.getString(); // sourceName + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + this.targetName = reader.getString(); + this.unknown02 = reader.getInt(); + this.unknown03 = reader.getInt(); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.source.getObjectType().ordinal()); + writer.putInt(source.getObjectUUID()); + writer.putInt(this.unknown01); + writer.putString(this.message); + if (AbstractWorldObject.IsAbstractCharacter(source)) { + writer.putString(((AbstractCharacter) this.source).getFirstName()); + } else { + writer.putString(this.source.getName()); + } + if (this.target != null) { + writer.putInt(this.target.getObjectType().ordinal()); + writer.putInt(this.target.getObjectUUID()); if (AbstractWorldObject.IsAbstractCharacter(target)) { writer.putString(((AbstractCharacter) this.target).getFirstName()); } else { @@ -120,52 +120,47 @@ public class ChatTellMsg extends AbstractChatMsg { writer.putInt(WorldServer.worldMapID); } - /** - * @return the target - */ - public AbstractWorldObject getTarget() { - return target; - } - - /** - * @param target - * the target to set - */ - public void setTarget(AbstractWorldObject target) { - this.target = target; - } - - - - - /** - * @return the targetName - */ - public String getTargetName() { - return targetName; - } - - /** - * @param targetName - * the targetName to set - */ - public void setTargetName(String targetName) { - this.targetName = targetName; - } - - /** - * @return the unknown03 - */ - public int getUnknown03() { - return unknown03; - } - - /** - * @param unknown03 - * the unknown03 to set - */ - public void setUnknown03(int unknown03) { - this.unknown03 = unknown03; - } + /** + * @return the target + */ + public AbstractWorldObject getTarget() { + return target; + } + + /** + * @param target the target to set + */ + public void setTarget(AbstractWorldObject target) { + this.target = target; + } + + + /** + * @return the targetName + */ + public String getTargetName() { + return targetName; + } + + /** + * @param targetName the targetName to set + */ + public void setTargetName(String targetName) { + this.targetName = targetName; + } + + /** + * @return the unknown03 + */ + public int getUnknown03() { + return unknown03; + } + + /** + * @param unknown03 the unknown03 to set + */ + public void setUnknown03(int unknown03) { + this.unknown03 = unknown03; + } } diff --git a/src/engine/net/client/msg/chat/GuildEnterWorldMsg.java b/src/engine/net/client/msg/chat/GuildEnterWorldMsg.java index ef3e3ed7..586cfad3 100644 --- a/src/engine/net/client/msg/chat/GuildEnterWorldMsg.java +++ b/src/engine/net/client/msg/chat/GuildEnterWorldMsg.java @@ -18,35 +18,35 @@ import engine.objects.PlayerCharacter; public class GuildEnterWorldMsg extends AbstractChatMsg { - protected String name; - protected int guildTitle; - protected int charterType; - protected int unknown04; - protected int guildUUID; - protected int unknown05; - protected int unknown06; - - /** - * This is the general purpose constructor. - */ - public GuildEnterWorldMsg(PlayerCharacter source) { - super(Protocol.GUILDMEMBERONLINE, source, "[!PLAYERRANK!] !PLAYERNAME! is online"); - - this.name = ""; - this.guildTitle = 0; - this.charterType = 9; - this.unknown02 = 12; - this.unknown04 = 2; - this.guildUUID = 0; - this.unknown05 = 0x2E46D00C; - this.unknown06 = 0; - } - - /** - * Copy constructor - */ - public GuildEnterWorldMsg(GuildEnterWorldMsg msg) { - super(msg); + protected String name; + protected int guildTitle; + protected int charterType; + protected int unknown04; + protected int guildUUID; + protected int unknown05; + protected int unknown06; + + /** + * This is the general purpose constructor. + */ + public GuildEnterWorldMsg(PlayerCharacter source) { + super(Protocol.GUILDMEMBERONLINE, source, "[!PLAYERRANK!] !PLAYERNAME! is online"); + + this.name = ""; + this.guildTitle = 0; + this.charterType = 9; + this.unknown02 = 12; + this.unknown04 = 2; + this.guildUUID = 0; + this.unknown05 = 0x2E46D00C; + this.unknown06 = 0; + } + + /** + * Copy constructor + */ + public GuildEnterWorldMsg(GuildEnterWorldMsg msg) { + super(msg); this.name = msg.name; this.guildTitle = msg.guildTitle; this.charterType = msg.charterType; @@ -54,193 +54,184 @@ public class GuildEnterWorldMsg extends AbstractChatMsg { this.guildUUID = msg.guildUUID; this.unknown05 = msg.unknown05; this.unknown06 = msg.unknown06; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public GuildEnterWorldMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.GUILDMEMBERONLINE, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putString(this.name); - - writer.putInt(guildTitle); - writer.put((byte) 1); // forgot this - writer.putInt(this.charterType); - writer.putInt(this.unknown02); - writer.putInt(this.unknown04); - writer.putInt(GameObjectType.Guild.ordinal()); - writer.putInt(this.guildUUID); - - writer.putString(this.message); - writer.putInt(this.unknown05); - writer.putInt(this.unknown06); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.name = reader.getString(); - this.guildTitle = reader.getInt(); - reader.get(); // forgot this - this.unknown02 = reader.getInt(); - this.charterType = reader.getInt(); - this.unknown04 = reader.getInt(); - reader.getInt(); // Object Type Padding - this.guildUUID = reader.getInt(); - this.message = reader.getString(); - this.unknown05 = reader.getInt(); - this.unknown06 = reader.getInt(); - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name - * the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the guildTitle - */ - public int getGuildTitle() { - return guildTitle; - } - - /** - * @param guildTitle - * the guildTitle to set - */ - public void setGuildTitle(int guildTitle) { - this.guildTitle = guildTitle; - } - - /** - * @return the unknown02 - */ - @Override - public int getUnknown02() { - return unknown02; - } - - /** - * @param unknown02 - * the unknown02 to set - */ - @Override - public void setUnknown02(int unknown02) { - this.unknown02 = unknown02; - } - - /** - * @return the unknown03 - */ - public int getCharter() { - return charterType; - } - - /** - * @param unknown03 - * the unknown03 to set - */ - public void setCharter(int charter) { - this.charterType = charter; - } - - /** - * @return the unknown04 - */ - public int getUnknown04() { - return unknown04; - } - - /** - * @param unknown04 - * the unknown04 to set - */ - public void setUnknown04(int unknown04) { - this.unknown04 = unknown04; - } - - /** - * @return the guildUUID - */ - public int getGuildUUID() { - return guildUUID; - } - - /** - * @param guildUUID - * the guildUUID to set - */ - public void setGuildUUID(int guildUUID) { - this.guildUUID = guildUUID; - } - - /** - * @return the message - */ - @Override - public String getMessage() { - return message; - } - - /** - * @param message - * the message to set - */ - @Override - public void setMessage(String message) { - this.message = message; - } - - /** - * @return the unknown05 - */ - public int getUnknown05() { - return unknown05; - } - - /** - * @param unknown05 - * the unknown05 to set - */ - public void setUnknown05(int unknown05) { - this.unknown05 = unknown05; - } - - /** - * @return the unknown06 - */ - public int getUnknown06() { - return unknown06; - } - - /** - * @param unknown06 - * the unknown06 to set - */ - public void setUnknown06(int unknown06) { - this.unknown06 = unknown06; - } + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public GuildEnterWorldMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.GUILDMEMBERONLINE, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putString(this.name); + + writer.putInt(guildTitle); + writer.put((byte) 1); // forgot this + writer.putInt(this.charterType); + writer.putInt(this.unknown02); + writer.putInt(this.unknown04); + writer.putInt(GameObjectType.Guild.ordinal()); + writer.putInt(this.guildUUID); + + writer.putString(this.message); + writer.putInt(this.unknown05); + writer.putInt(this.unknown06); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.name = reader.getString(); + this.guildTitle = reader.getInt(); + reader.get(); // forgot this + this.unknown02 = reader.getInt(); + this.charterType = reader.getInt(); + this.unknown04 = reader.getInt(); + reader.getInt(); // Object Type Padding + this.guildUUID = reader.getInt(); + this.message = reader.getString(); + this.unknown05 = reader.getInt(); + this.unknown06 = reader.getInt(); + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the guildTitle + */ + public int getGuildTitle() { + return guildTitle; + } + + /** + * @param guildTitle the guildTitle to set + */ + public void setGuildTitle(int guildTitle) { + this.guildTitle = guildTitle; + } + + /** + * @return the unknown02 + */ + @Override + public int getUnknown02() { + return unknown02; + } + + /** + * @param unknown02 the unknown02 to set + */ + @Override + public void setUnknown02(int unknown02) { + this.unknown02 = unknown02; + } + + /** + * @return the unknown03 + */ + public int getCharter() { + return charterType; + } + + /** + * @param unknown03 the unknown03 to set + */ + public void setCharter(int charter) { + this.charterType = charter; + } + + /** + * @return the unknown04 + */ + public int getUnknown04() { + return unknown04; + } + + /** + * @param unknown04 the unknown04 to set + */ + public void setUnknown04(int unknown04) { + this.unknown04 = unknown04; + } + + /** + * @return the guildUUID + */ + public int getGuildUUID() { + return guildUUID; + } + + /** + * @param guildUUID the guildUUID to set + */ + public void setGuildUUID(int guildUUID) { + this.guildUUID = guildUUID; + } + + /** + * @return the message + */ + @Override + public String getMessage() { + return message; + } + + /** + * @param message the message to set + */ + @Override + public void setMessage(String message) { + this.message = message; + } + + /** + * @return the unknown05 + */ + public int getUnknown05() { + return unknown05; + } + + /** + * @param unknown05 the unknown05 to set + */ + public void setUnknown05(int unknown05) { + this.unknown05 = unknown05; + } + + /** + * @return the unknown06 + */ + public int getUnknown06() { + return unknown06; + } + + /** + * @param unknown06 the unknown06 to set + */ + public void setUnknown06(int unknown06) { + this.unknown06 = unknown06; + } } diff --git a/src/engine/net/client/msg/commands/ClientAdminCommandMsg.java b/src/engine/net/client/msg/commands/ClientAdminCommandMsg.java index 5335f660..3eb3025c 100644 --- a/src/engine/net/client/msg/commands/ClientAdminCommandMsg.java +++ b/src/engine/net/client/msg/commands/ClientAdminCommandMsg.java @@ -21,81 +21,81 @@ import engine.objects.AbstractGameObject; public class ClientAdminCommandMsg extends ClientNetMsg { - private int msgType; - private String msgCommand; - private long senderCompID; - private int targetType; - private int targetUUID; - private Vector3f location; - private AbstractGameObject target; + private int msgType; + private String msgCommand; + private long senderCompID; + private int targetType; + private int targetUUID; + private Vector3f location; + private AbstractGameObject target; - /** - * This is the general purpose constructor. - */ - public ClientAdminCommandMsg() { - super(Protocol.CLIENTADMINCOMMAND); - } + /** + * This is the general purpose constructor. + */ + public ClientAdminCommandMsg() { + super(Protocol.CLIENTADMINCOMMAND); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ClientAdminCommandMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CLIENTADMINCOMMAND, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ClientAdminCommandMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CLIENTADMINCOMMAND, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - // TODO implement Serialize() - } + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + // TODO implement Serialize() + } - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.msgType = reader.getInt(); - this.msgCommand = reader.getString(); - this.targetType = reader.getInt(); - this.targetUUID = reader.getInt(); - this.senderCompID = reader.getLong(); // always null?? - this.location = new Vector3f(reader.getFloat(), reader.getFloat(), reader.getFloat()); + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.msgType = reader.getInt(); + this.msgCommand = reader.getString(); + this.targetType = reader.getInt(); + this.targetUUID = reader.getInt(); + this.senderCompID = reader.getLong(); // always null?? + this.location = new Vector3f(reader.getFloat(), reader.getFloat(), reader.getFloat()); - if (targetUUID != 0) - target = DbManager.getObject(GameObjectType.values()[this.targetType], this.targetUUID); - } + if (targetUUID != 0) + target = DbManager.getObject(GameObjectType.values()[this.targetType], this.targetUUID); + } - /** - * @return the msgCommand - */ - public String getMsgCommand() { - return msgCommand; - } + /** + * @return the msgCommand + */ + public String getMsgCommand() { + return msgCommand; + } - /** - * @return the targetUUID - */ - public int getTargetUUID() { - return targetUUID; - } + /** + * @return the targetUUID + */ + public int getTargetUUID() { + return targetUUID; + } - /** - * @return the location - */ - public Vector3f getLocation() { - return location; - } + /** + * @return the location + */ + public Vector3f getLocation() { + return location; + } - /** - * @return the target - */ - public AbstractGameObject getTarget() { - return target; - } + /** + * @return the target + */ + public AbstractGameObject getTarget() { + return target; + } } diff --git a/src/engine/net/client/msg/group/AppointGroupLeaderMsg.java b/src/engine/net/client/msg/group/AppointGroupLeaderMsg.java index 636c34d4..d3d4013b 100644 --- a/src/engine/net/client/msg/group/AppointGroupLeaderMsg.java +++ b/src/engine/net/client/msg/group/AppointGroupLeaderMsg.java @@ -18,112 +18,108 @@ import engine.net.client.msg.ClientNetMsg; public class AppointGroupLeaderMsg extends ClientNetMsg { - private int targetType; - private int targetID; - private int response; - private String message; - - /** - * This is the general purpose constructor. - */ - public AppointGroupLeaderMsg() { - super(Protocol.GROUPLEADERAPPOINT); - this.message = "You are already the group leader"; - - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public AppointGroupLeaderMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.GROUPLEADERAPPOINT, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.targetType); - writer.putInt(this.targetID); - writer.putInt(this.response); - if (this.response == 1) - writer.putString(this.message); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - this.response = reader.getInt(); - if (this.response == 1) - this.message = reader.getString(); - } - - /** - * @return the targetType - */ - public int getTargetType() { - return targetType; - } - - /** - * @param targetType - * the targetType to set - */ - public void setTargetType(int targetType) { - this.targetType = targetType; - } - - /** - * @return the targetID - */ - public int getTargetID() { - return targetID; - } - - /** - * @param targetID - * the targetID to set - */ - public void setTargetID(int targetID) { - this.targetID = targetID; - } - - /** - * @return the response - */ - public int getResponse() { - return response; - } - - /** - * @param response - * the response to set - */ - public void setResponse(int response) { - this.response = response; - } - - /** - * @return the message - */ - public String getMessage() { - return message; - } - - /** - * @param message - * the message to set - */ - public void setMessage(String message) { - this.message = message; - } + private int targetType; + private int targetID; + private int response; + private String message; + + /** + * This is the general purpose constructor. + */ + public AppointGroupLeaderMsg() { + super(Protocol.GROUPLEADERAPPOINT); + this.message = "You are already the group leader"; + + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public AppointGroupLeaderMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.GROUPLEADERAPPOINT, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.targetType); + writer.putInt(this.targetID); + writer.putInt(this.response); + if (this.response == 1) + writer.putString(this.message); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + this.response = reader.getInt(); + if (this.response == 1) + this.message = reader.getString(); + } + + /** + * @return the targetType + */ + public int getTargetType() { + return targetType; + } + + /** + * @param targetType the targetType to set + */ + public void setTargetType(int targetType) { + this.targetType = targetType; + } + + /** + * @return the targetID + */ + public int getTargetID() { + return targetID; + } + + /** + * @param targetID the targetID to set + */ + public void setTargetID(int targetID) { + this.targetID = targetID; + } + + /** + * @return the response + */ + public int getResponse() { + return response; + } + + /** + * @param response the response to set + */ + public void setResponse(int response) { + this.response = response; + } + + /** + * @return the message + */ + public String getMessage() { + return message; + } + + /** + * @param message the message to set + */ + public void setMessage(String message) { + this.message = message; + } } diff --git a/src/engine/net/client/msg/group/DisbandGroupMsg.java b/src/engine/net/client/msg/group/DisbandGroupMsg.java index d542420b..b23ae529 100644 --- a/src/engine/net/client/msg/group/DisbandGroupMsg.java +++ b/src/engine/net/client/msg/group/DisbandGroupMsg.java @@ -18,52 +18,50 @@ import engine.net.client.msg.ClientNetMsg; public class DisbandGroupMsg extends ClientNetMsg { - private int unknown01; + private int unknown01; - /** - * This is the general purpose constructor. - */ - public DisbandGroupMsg() { - super(Protocol.GROUPDISBAND); - } + /** + * This is the general purpose constructor. + */ + public DisbandGroupMsg() { + super(Protocol.GROUPDISBAND); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public DisbandGroupMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.GROUPDISBAND, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public DisbandGroupMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.GROUPDISBAND, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.unknown01); - } + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.unknown01); + } - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.unknown01 = reader.getInt(); - } + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.unknown01 = reader.getInt(); + } - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } } diff --git a/src/engine/net/client/msg/group/FormationFollowMsg.java b/src/engine/net/client/msg/group/FormationFollowMsg.java index c57401ca..afd2acc4 100644 --- a/src/engine/net/client/msg/group/FormationFollowMsg.java +++ b/src/engine/net/client/msg/group/FormationFollowMsg.java @@ -18,95 +18,91 @@ import engine.net.client.msg.ClientNetMsg; public class FormationFollowMsg extends ClientNetMsg { - private boolean follow; - private int formation; - private int unknown01; - - /** - * This is the general purpose constructor. - */ - public FormationFollowMsg() { - super(Protocol.GROUPFOLLOW); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public FormationFollowMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.GROUPFOLLOW, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - if (this.follow) { - writer.putInt(1); - writer.putInt(0); - } else { - writer.putInt(0); - writer.putInt(1); - } - writer.putInt(this.formation); - writer.putInt(this.unknown01); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { + private boolean follow; + private int formation; + private int unknown01; + + /** + * This is the general purpose constructor. + */ + public FormationFollowMsg() { + super(Protocol.GROUPFOLLOW); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public FormationFollowMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.GROUPFOLLOW, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + if (this.follow) { + writer.putInt(1); + writer.putInt(0); + } else { + writer.putInt(0); + writer.putInt(1); + } + writer.putInt(this.formation); + writer.putInt(this.unknown01); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { this.follow = reader.getInt() == 1; - reader.getInt(); - this.formation = reader.getInt(); - this.unknown01 = reader.getInt(); - } - - /** - * @return the follow - */ - public boolean isFollow() { - return follow; - } - - /** - * @param follow - * the follow to set - */ - public void setFollow(boolean follow) { - this.follow = follow; - } - - /** - * @return the formation - */ - public int getFormation() { - return formation; - } - - /** - * @param formation - * the formation to set - */ - public void setFormation(int formation) { - this.formation = formation; - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } + reader.getInt(); + this.formation = reader.getInt(); + this.unknown01 = reader.getInt(); + } + + /** + * @return the follow + */ + public boolean isFollow() { + return follow; + } + + /** + * @param follow the follow to set + */ + public void setFollow(boolean follow) { + this.follow = follow; + } + + /** + * @return the formation + */ + public int getFormation() { + return formation; + } + + /** + * @param formation the formation to set + */ + public void setFormation(int formation) { + this.formation = formation; + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } } diff --git a/src/engine/net/client/msg/group/GroupInviteMsg.java b/src/engine/net/client/msg/group/GroupInviteMsg.java index c7e98ed5..f6afdf00 100644 --- a/src/engine/net/client/msg/group/GroupInviteMsg.java +++ b/src/engine/net/client/msg/group/GroupInviteMsg.java @@ -18,203 +18,194 @@ import engine.net.client.msg.ClientNetMsg; public class GroupInviteMsg extends ClientNetMsg { - private int sourceType; - private int sourceID; - private int targetType; - private int targetID; - private int groupType; - private int groupID; - private int unknown01; - private int invited; - private String name; - - /** - * This is the general purpose constructor. - */ - public GroupInviteMsg() { - super(Protocol.INVITEGROUP); - this.name = ""; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public GroupInviteMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.INVITEGROUP, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.sourceType); - writer.putInt(this.sourceID); - writer.putInt(this.targetType); - writer.putInt(this.targetID); - writer.putInt(this.groupType); - writer.putInt(this.groupID); - writer.putInt(this.unknown01); - writer.putInt(this.invited); - if (this.invited == 1) - writer.putString(this.name); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - - this.sourceType = reader.getInt(); - this.sourceID = reader.getInt(); - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - this.groupType = reader.getInt(); - this.groupID = reader.getInt(); - this.unknown01 = reader.getInt(); - this.invited = reader.getInt(); - if (this.invited == 1) - this.name = reader.getString(); - - } - - /** - * @return the sourceType - */ - public int getSourceType() { - return sourceType; - } - - /** - * @param sourceType - * the sourceType to set - */ - public void setSourceType(int sourceType) { - this.sourceType = sourceType; - } - - /** - * @return the sourceID - */ - public int getSourceID() { - return sourceID; - } - - /** - * @param sourceID - * the sourceID to set - */ - public void setSourceID(int sourceID) { - this.sourceID = sourceID; - } - - /** - * @return the targetType - */ - public int getTargetType() { - return targetType; - } - - /** - * @param targetType - * the targetType to set - */ - public void setTargetType(int targetType) { - this.targetType = targetType; - } - - /** - * @return the targetID - */ - public int getTargetID() { - return targetID; - } - - /** - * @param targetID - * the targetID to set - */ - public void setTargetID(int targetID) { - this.targetID = targetID; - } - - /** - * @return the groupType - */ - public int getGroupType() { - return groupType; - } - - /** - * @param groupType - * the groupType to set - */ - public void setGroupType(int groupType) { - this.groupType = groupType; - } - - /** - * @return the groupID - */ - public int getGroupID() { - return groupID; - } - - /** - * @param groupID - * the groupID to set - */ - public void setGroupID(int groupID) { - this.groupID = groupID; - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the invited - */ - public int getInvited() { - return invited; - } - - /** - * @param invited - * the invited to set - */ - public void setInvited(int invited) { - this.invited = invited; - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name - * the name to set - */ - public void setName(String name) { - this.name = name; - } + private int sourceType; + private int sourceID; + private int targetType; + private int targetID; + private int groupType; + private int groupID; + private int unknown01; + private int invited; + private String name; + + /** + * This is the general purpose constructor. + */ + public GroupInviteMsg() { + super(Protocol.INVITEGROUP); + this.name = ""; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public GroupInviteMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.INVITEGROUP, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.sourceType); + writer.putInt(this.sourceID); + writer.putInt(this.targetType); + writer.putInt(this.targetID); + writer.putInt(this.groupType); + writer.putInt(this.groupID); + writer.putInt(this.unknown01); + writer.putInt(this.invited); + if (this.invited == 1) + writer.putString(this.name); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + + this.sourceType = reader.getInt(); + this.sourceID = reader.getInt(); + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + this.groupType = reader.getInt(); + this.groupID = reader.getInt(); + this.unknown01 = reader.getInt(); + this.invited = reader.getInt(); + if (this.invited == 1) + this.name = reader.getString(); + + } + + /** + * @return the sourceType + */ + public int getSourceType() { + return sourceType; + } + + /** + * @param sourceType the sourceType to set + */ + public void setSourceType(int sourceType) { + this.sourceType = sourceType; + } + + /** + * @return the sourceID + */ + public int getSourceID() { + return sourceID; + } + + /** + * @param sourceID the sourceID to set + */ + public void setSourceID(int sourceID) { + this.sourceID = sourceID; + } + + /** + * @return the targetType + */ + public int getTargetType() { + return targetType; + } + + /** + * @param targetType the targetType to set + */ + public void setTargetType(int targetType) { + this.targetType = targetType; + } + + /** + * @return the targetID + */ + public int getTargetID() { + return targetID; + } + + /** + * @param targetID the targetID to set + */ + public void setTargetID(int targetID) { + this.targetID = targetID; + } + + /** + * @return the groupType + */ + public int getGroupType() { + return groupType; + } + + /** + * @param groupType the groupType to set + */ + public void setGroupType(int groupType) { + this.groupType = groupType; + } + + /** + * @return the groupID + */ + public int getGroupID() { + return groupID; + } + + /** + * @param groupID the groupID to set + */ + public void setGroupID(int groupID) { + this.groupID = groupID; + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the invited + */ + public int getInvited() { + return invited; + } + + /** + * @param invited the invited to set + */ + public void setInvited(int invited) { + this.invited = invited; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } } diff --git a/src/engine/net/client/msg/group/GroupInviteResponseMsg.java b/src/engine/net/client/msg/group/GroupInviteResponseMsg.java index c988f43e..c9e26bf9 100644 --- a/src/engine/net/client/msg/group/GroupInviteResponseMsg.java +++ b/src/engine/net/client/msg/group/GroupInviteResponseMsg.java @@ -18,106 +18,101 @@ import engine.net.client.msg.ClientNetMsg; public class GroupInviteResponseMsg extends ClientNetMsg { - private int groupType; - private int groupID; - private int unknown01; - private int unknown02; - - /** - * This is the general purpose constructor. - */ - public GroupInviteResponseMsg() { - super(Protocol.JOINGROUP); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public GroupInviteResponseMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.JOINGROUP, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.groupType); - writer.putInt(this.groupID); - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.groupType = reader.getInt(); - this.groupID = reader.getInt(); - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - } - - /** - * @return the groupType - */ - public int getGroupType() { - return groupType; - } - - /** - * @param groupType - * the groupType to set - */ - public void setGroupType(int groupType) { - this.groupType = groupType; - } - - /** - * @return the groupID - */ - public int getGroupID() { - return groupID; - } - - /** - * @param groupID - * the groupID to set - */ - public void setGroupID(int groupID) { - this.groupID = groupID; - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the unknown02 - */ - public int getUnknown02() { - return unknown02; - } - - /** - * @param unknown02 - * the unknown02 to set - */ - public void setUnknown02(int unknown02) { - this.unknown02 = unknown02; - } + private int groupType; + private int groupID; + private int unknown01; + private int unknown02; + + /** + * This is the general purpose constructor. + */ + public GroupInviteResponseMsg() { + super(Protocol.JOINGROUP); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public GroupInviteResponseMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.JOINGROUP, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.groupType); + writer.putInt(this.groupID); + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.groupType = reader.getInt(); + this.groupID = reader.getInt(); + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + } + + /** + * @return the groupType + */ + public int getGroupType() { + return groupType; + } + + /** + * @param groupType the groupType to set + */ + public void setGroupType(int groupType) { + this.groupType = groupType; + } + + /** + * @return the groupID + */ + public int getGroupID() { + return groupID; + } + + /** + * @param groupID the groupID to set + */ + public void setGroupID(int groupID) { + this.groupID = groupID; + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the unknown02 + */ + public int getUnknown02() { + return unknown02; + } + + /** + * @param unknown02 the unknown02 to set + */ + public void setUnknown02(int unknown02) { + this.unknown02 = unknown02; + } } diff --git a/src/engine/net/client/msg/group/GroupUpdateMsg.java b/src/engine/net/client/msg/group/GroupUpdateMsg.java index e4b554bc..6b9393dc 100644 --- a/src/engine/net/client/msg/group/GroupUpdateMsg.java +++ b/src/engine/net/client/msg/group/GroupUpdateMsg.java @@ -58,10 +58,20 @@ public class GroupUpdateMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public GroupUpdateMsg(AbstractConnection origin, ByteBufferReader reader) { + public GroupUpdateMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.UPDATEGROUP, origin, reader); } + private static void _serializeFour(ByteBufferWriter writer) { + + // 4 sends a party dissolved window + for (int i = 0; i < 3; i++) { + writer.putInt(0); + } + } + + // *** Refactor: This method is an abortion. Needs to be re-written from scratch. + /** * Serializes the subclass specific items to the supplied ByteBufferWriter. */ @@ -71,12 +81,12 @@ public class GroupUpdateMsg extends ClientNetMsg { writer.putInt(this.group.getObjectUUID()); writer.putInt(this.messageType); - // 5 breaks everything including movement etc + // 5 breaks everything including movement etc // 4 sends a party dissolved message // 3 closes the group window and leaves the group // 2 seems to update the location but not the stats correctly upon coming back into range // 1 seems to add you to the group but if called by a job tops up your stats on the client and desyncs it - + switch (messageType) { case 4: GroupUpdateMsg._serializeFour(writer); @@ -106,10 +116,8 @@ public class GroupUpdateMsg extends ClientNetMsg { } } - // *** Refactor: This method is an abortion. Needs to be re-written from scratch. - private void serializePlayer(ByteBufferWriter writer, PlayerCharacter player, int messageType, int count) { - + if (messageType == 1) { writer.putString((player != null) ? player.getFirstName() : "nullError"); writer.putString((player != null) ? player.getLastName() : ""); @@ -141,7 +149,7 @@ public class GroupUpdateMsg extends ClientNetMsg { writer.putInt((player != null) ? Float.floatToIntBits(player.getLoc().getY()) : 0); writer.putInt((player != null) ? Float.floatToIntBits(player.getLoc().getZ()) : 0); } - + if (player == null) writer.putLong(0); else { @@ -173,7 +181,7 @@ public class GroupUpdateMsg extends ClientNetMsg { writer.putInt(1); writer.put((byte) 1); - // if sending message type 1 this seems to make the group window flicker the button + // if sending message type 1 this seems to make the group window flicker the button // i think getfollow and split gold might be the wrong way around if (group != null) { writer.put(this.group.getSplitGold() ? (byte) 1 : (byte) 0); @@ -189,14 +197,6 @@ public class GroupUpdateMsg extends ClientNetMsg { } } - private static void _serializeFour(ByteBufferWriter writer) { - - // 4 sends a party dissolved window - for (int i = 0; i < 3; i++) { - writer.putInt(0); - } - } - //sync player's stats and position private void _serializeFive(ByteBufferWriter writer) { writer.putInt(1); @@ -213,7 +213,7 @@ public class GroupUpdateMsg extends ClientNetMsg { writer.putFloat(player.getLoc().z); writer.putInt(GameObjectType.PlayerCharacter.ordinal()); writer.putInt(player.getObjectUUID()); - + } writer.putInt(0); writer.putInt(0); @@ -243,7 +243,8 @@ public class GroupUpdateMsg extends ClientNetMsg { } private void _serializeEight(ByteBufferWriter writer) { - PlayerCharacter player = this.players.iterator().next();; + PlayerCharacter player = this.players.iterator().next(); + ; writer.putInt(0); if (player != null) { writer.put(player.getFollow() ? (byte) 1 : (byte) 0); @@ -262,7 +263,7 @@ public class GroupUpdateMsg extends ClientNetMsg { * ByteBufferReader. */ @Override - protected void _deserialize(ByteBufferReader reader) { + protected void _deserialize(ByteBufferReader reader) { this.players = Collections.newSetFromMap(new ConcurrentHashMap<>()); reader.getInt(); diff --git a/src/engine/net/client/msg/group/LeaveGroupMsg.java b/src/engine/net/client/msg/group/LeaveGroupMsg.java index 8c3f1678..f477de3b 100644 --- a/src/engine/net/client/msg/group/LeaveGroupMsg.java +++ b/src/engine/net/client/msg/group/LeaveGroupMsg.java @@ -18,105 +18,100 @@ import engine.net.client.msg.ClientNetMsg; public class LeaveGroupMsg extends ClientNetMsg { - private int unknown01; - private int unknown02; - private int unknown03; - private int unknown04; - - /** - * This is the general purpose constructor. - */ - public LeaveGroupMsg() { - super(Protocol.LEAVEGROUP); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public LeaveGroupMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.LEAVEGROUP, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - writer.putInt(this.unknown03); - writer.putInt(this.unknown04); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - this.unknown03 = reader.getInt(); - this.unknown04 = reader.getInt(); - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the unknown02 - */ - public int getUnknown02() { - return unknown02; - } - - /** - * @param unknown02 - * the unknown02 to set - */ - public void setUnknown02(int unknown02) { - this.unknown02 = unknown02; - } - - /** - * @return the unknown03 - */ - public int getUnknown03() { - return unknown03; - } - - /** - * @param unknown03 - * the unknown03 to set - */ - public void setUnknown03(int unknown03) { - this.unknown03 = unknown03; - } - - /** - * @return the unknown04 - */ - public int getUnknown04() { - return unknown04; - } - - /** - * @param unknown04 - * the unknown04 to set - */ - public void setUnknown04(int unknown04) { - this.unknown04 = unknown04; - } + private int unknown01; + private int unknown02; + private int unknown03; + private int unknown04; + + /** + * This is the general purpose constructor. + */ + public LeaveGroupMsg() { + super(Protocol.LEAVEGROUP); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public LeaveGroupMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.LEAVEGROUP, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + writer.putInt(this.unknown03); + writer.putInt(this.unknown04); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + this.unknown03 = reader.getInt(); + this.unknown04 = reader.getInt(); + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the unknown02 + */ + public int getUnknown02() { + return unknown02; + } + + /** + * @param unknown02 the unknown02 to set + */ + public void setUnknown02(int unknown02) { + this.unknown02 = unknown02; + } + + /** + * @return the unknown03 + */ + public int getUnknown03() { + return unknown03; + } + + /** + * @param unknown03 the unknown03 to set + */ + public void setUnknown03(int unknown03) { + this.unknown03 = unknown03; + } + + /** + * @return the unknown04 + */ + public int getUnknown04() { + return unknown04; + } + + /** + * @param unknown04 the unknown04 to set + */ + public void setUnknown04(int unknown04) { + this.unknown04 = unknown04; + } } diff --git a/src/engine/net/client/msg/group/RemoveFromGroupMsg.java b/src/engine/net/client/msg/group/RemoveFromGroupMsg.java index 4ee5fb56..7ff6586a 100644 --- a/src/engine/net/client/msg/group/RemoveFromGroupMsg.java +++ b/src/engine/net/client/msg/group/RemoveFromGroupMsg.java @@ -18,112 +18,108 @@ import engine.net.client.msg.ClientNetMsg; public class RemoveFromGroupMsg extends ClientNetMsg { - private int targetType; - private int targetID; - private int response; - private String message; - - /** - * This is the general purpose constructor. - */ - public RemoveFromGroupMsg() { - super(Protocol.GROUPREMOVE); - - this.message = "Quit if you want to remove yourself"; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public RemoveFromGroupMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.GROUPREMOVE, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.targetType); - writer.putInt(this.targetID); - writer.putInt(this.response); - if (this.response == 1) - writer.putString(this.message); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - this.response = reader.getInt(); - if (this.response == 1) - this.message = reader.getString(); - } - - /** - * @return the targetType - */ - public int getTargetType() { - return targetType; - } - - /** - * @param targetType - * the targetType to set - */ - public void setTargetType(int targetType) { - this.targetType = targetType; - } - - /** - * @return the targetID - */ - public int getTargetID() { - return targetID; - } - - /** - * @param targetID - * the targetID to set - */ - public void setTargetID(int targetID) { - this.targetID = targetID; - } - - /** - * @return the response - */ - public int getResponse() { - return response; - } - - /** - * @param response - * the response to set - */ - public void setResponse(int response) { - this.response = response; - } - - /** - * @return the message - */ - public String getMessage() { - return message; - } - - /** - * @param message - * the message to set - */ - public void setMessage(String message) { - this.message = message; - } + private int targetType; + private int targetID; + private int response; + private String message; + + /** + * This is the general purpose constructor. + */ + public RemoveFromGroupMsg() { + super(Protocol.GROUPREMOVE); + + this.message = "Quit if you want to remove yourself"; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public RemoveFromGroupMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.GROUPREMOVE, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.targetType); + writer.putInt(this.targetID); + writer.putInt(this.response); + if (this.response == 1) + writer.putString(this.message); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + this.response = reader.getInt(); + if (this.response == 1) + this.message = reader.getString(); + } + + /** + * @return the targetType + */ + public int getTargetType() { + return targetType; + } + + /** + * @param targetType the targetType to set + */ + public void setTargetType(int targetType) { + this.targetType = targetType; + } + + /** + * @return the targetID + */ + public int getTargetID() { + return targetID; + } + + /** + * @param targetID the targetID to set + */ + public void setTargetID(int targetID) { + this.targetID = targetID; + } + + /** + * @return the response + */ + public int getResponse() { + return response; + } + + /** + * @param response the response to set + */ + public void setResponse(int response) { + this.response = response; + } + + /** + * @return the message + */ + public String getMessage() { + return message; + } + + /** + * @param message the message to set + */ + public void setMessage(String message) { + this.message = message; + } } diff --git a/src/engine/net/client/msg/group/ToggleGroupSplitMsg.java b/src/engine/net/client/msg/group/ToggleGroupSplitMsg.java index c58aaa77..1becdabb 100644 --- a/src/engine/net/client/msg/group/ToggleGroupSplitMsg.java +++ b/src/engine/net/client/msg/group/ToggleGroupSplitMsg.java @@ -18,55 +18,54 @@ import engine.net.client.msg.ClientNetMsg; public class ToggleGroupSplitMsg extends ClientNetMsg { - private int unknown01; + private int unknown01; - /** - * This is the general purpose constructor. - */ - public ToggleGroupSplitMsg() { - super(Protocol.GROUPTREASURE); - this.unknown01 = 1; - } + /** + * This is the general purpose constructor. + */ + public ToggleGroupSplitMsg() { + super(Protocol.GROUPTREASURE); + this.unknown01 = 1; + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ToggleGroupSplitMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.GROUPTREASURE, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ToggleGroupSplitMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.GROUPTREASURE, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.unknown01); - } + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.unknown01); + } - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.unknown01 = reader.getInt(); - } + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.unknown01 = reader.getInt(); + } - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } } diff --git a/src/engine/net/client/msg/guild/AcceptInviteToGuildMsg.java b/src/engine/net/client/msg/guild/AcceptInviteToGuildMsg.java index f9899e73..4e16f6ef 100644 --- a/src/engine/net/client/msg/guild/AcceptInviteToGuildMsg.java +++ b/src/engine/net/client/msg/guild/AcceptInviteToGuildMsg.java @@ -42,8 +42,7 @@ public class AcceptInviteToGuildMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public AcceptInviteToGuildMsg(AbstractConnection origin, ByteBufferReader reader) - { + public AcceptInviteToGuildMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.JOINGUILD, origin, reader); } @@ -63,7 +62,7 @@ public class AcceptInviteToGuildMsg extends ClientNetMsg { * ByteBufferReader. */ @Override - protected void _deserialize(ByteBufferReader reader) { + protected void _deserialize(ByteBufferReader reader) { reader.getInt(); // Object Type padding this.guildUUID = reader.getInt(); this.unknown01 = reader.getInt(); @@ -85,8 +84,7 @@ public class AcceptInviteToGuildMsg extends ClientNetMsg { } /** - * @param unknown01 - * the unknown01 to set + * @param unknown01 the unknown01 to set */ public void setUnknown01(int unknown01) { this.unknown01 = unknown01; @@ -100,8 +98,7 @@ public class AcceptInviteToGuildMsg extends ClientNetMsg { } /** - * @param unknown02 - * the unknown02 to set + * @param unknown02 the unknown02 to set */ public void setUnknown02(int unknown02) { this.unknown02 = unknown02; diff --git a/src/engine/net/client/msg/guild/AcceptSubInviteMsg.java b/src/engine/net/client/msg/guild/AcceptSubInviteMsg.java index 8e35ca6d..53b0ed87 100644 --- a/src/engine/net/client/msg/guild/AcceptSubInviteMsg.java +++ b/src/engine/net/client/msg/guild/AcceptSubInviteMsg.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -19,9 +16,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -31,9 +25,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -54,101 +45,98 @@ import engine.net.client.msg.ClientNetMsg; public class AcceptSubInviteMsg extends ClientNetMsg { - private int guildUUID; - private int unknown01; - private int unknown02; - private String response; - - /** - * This is the general purpose constructor. - */ - public AcceptSubInviteMsg() { - super(Protocol.JOINFORPROVINCE); - } - - public AcceptSubInviteMsg(int guildUUID, int unknown01, int unknown02, String response) { - super(Protocol.JOINFORPROVINCE); - this.guildUUID = guildUUID; - this.unknown01 = unknown01; - this.unknown02 = unknown02; - this.response = response; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public AcceptSubInviteMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.JOINFORPROVINCE, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(GameObjectType.Guild.ordinal()); - writer.putInt(this.guildUUID); - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - writer.putString(this.response); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - reader.getInt(); // Object Type Padding - this.guildUUID = reader.getInt(); - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - reader.getString(); - } - - /** - * @return the guildUUID - */ - public int guildUUID() { - return guildUUID; - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the unknown02 - */ - public int getUnknown02() { - return unknown02; - } - - /** - * @param unknown02 - * the unknown02 to set - */ - public void setUnknown02(int unknown02) { - this.unknown02 = unknown02; - } - - - public String getResponse() { - return this.response; - } - - public void setResponse(String value) { - this.response = value; - } + private int guildUUID; + private int unknown01; + private int unknown02; + private String response; + + /** + * This is the general purpose constructor. + */ + public AcceptSubInviteMsg() { + super(Protocol.JOINFORPROVINCE); + } + + public AcceptSubInviteMsg(int guildUUID, int unknown01, int unknown02, String response) { + super(Protocol.JOINFORPROVINCE); + this.guildUUID = guildUUID; + this.unknown01 = unknown01; + this.unknown02 = unknown02; + this.response = response; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public AcceptSubInviteMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.JOINFORPROVINCE, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(GameObjectType.Guild.ordinal()); + writer.putInt(this.guildUUID); + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + writer.putString(this.response); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.getInt(); // Object Type Padding + this.guildUUID = reader.getInt(); + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + reader.getString(); + } + + /** + * @return the guildUUID + */ + public int guildUUID() { + return guildUUID; + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the unknown02 + */ + public int getUnknown02() { + return unknown02; + } + + /** + * @param unknown02 the unknown02 to set + */ + public void setUnknown02(int unknown02) { + this.unknown02 = unknown02; + } + + + public String getResponse() { + return this.response; + } + + public void setResponse(String value) { + this.response = value; + } } diff --git a/src/engine/net/client/msg/guild/BanishUnbanishMsg.java b/src/engine/net/client/msg/guild/BanishUnbanishMsg.java index af8722d3..d06af36c 100644 --- a/src/engine/net/client/msg/guild/BanishUnbanishMsg.java +++ b/src/engine/net/client/msg/guild/BanishUnbanishMsg.java @@ -18,55 +18,54 @@ import engine.net.client.msg.ClientNetMsg; public class BanishUnbanishMsg extends ClientNetMsg { - private int target; - private int msgType; + private int target; + private int msgType; - /** - * This is the general purpose constructor. - */ - public BanishUnbanishMsg() { - super(Protocol.BANISHMEMBER); - } + /** + * This is the general purpose constructor. + */ + public BanishUnbanishMsg() { + super(Protocol.BANISHMEMBER); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public BanishUnbanishMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.BANISHMEMBER, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public BanishUnbanishMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.BANISHMEMBER, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { - } + } - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - reader.getInt(); - target = reader.getInt(); + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.getInt(); + target = reader.getInt(); - //Unknows? - reader.getInt(); + //Unknows? + reader.getInt(); this.msgType = reader.getInt(); reader.getInt(); - } + } - public int getTarget() { - return target; - } + public int getTarget() { + return target; + } - public int getMsgType() { - return msgType; - } + public int getMsgType() { + return msgType; + } - public void setMsgType(int msgType) { - this.msgType = msgType; - } + public void setMsgType(int msgType) { + this.msgType = msgType; + } } diff --git a/src/engine/net/client/msg/guild/BreakFealtyMsg.java b/src/engine/net/client/msg/guild/BreakFealtyMsg.java index ae4bac3e..7a003f63 100644 --- a/src/engine/net/client/msg/guild/BreakFealtyMsg.java +++ b/src/engine/net/client/msg/guild/BreakFealtyMsg.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.net.client.msg.guild; @@ -19,43 +18,42 @@ import engine.net.client.msg.ClientNetMsg; public class BreakFealtyMsg extends ClientNetMsg { - private int guildUUID; - - /** - * This is the general purpose constructor. - */ - public BreakFealtyMsg() { - super(Protocol.BREAKFEALTY); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public BreakFealtyMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.BREAKFEALTY, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - reader.getInt(); // Object Type Padding - this.guildUUID = reader.getInt(); - reader.getInt(); - } - - public int getGuildUUID() { - return guildUUID; - } + private int guildUUID; + + /** + * This is the general purpose constructor. + */ + public BreakFealtyMsg() { + super(Protocol.BREAKFEALTY); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public BreakFealtyMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.BREAKFEALTY, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.getInt(); // Object Type Padding + this.guildUUID = reader.getInt(); + reader.getInt(); + } + + public int getGuildUUID() { + return guildUUID; + } } diff --git a/src/engine/net/client/msg/guild/ChangeRankMsg.java b/src/engine/net/client/msg/guild/ChangeRankMsg.java index 05e14a4c..5a9885f2 100644 --- a/src/engine/net/client/msg/guild/ChangeRankMsg.java +++ b/src/engine/net/client/msg/guild/ChangeRankMsg.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -19,9 +16,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -31,9 +25,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -43,8 +34,6 @@ // www.magicbane.com - - package engine.net.client.msg.guild; import engine.Enum.GameObjectType; @@ -74,8 +63,7 @@ public class ChangeRankMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public ChangeRankMsg(AbstractConnection origin, ByteBufferReader reader) - { + public ChangeRankMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.GUILDRANKCHANGE, origin, reader); } @@ -147,7 +135,7 @@ public class ChangeRankMsg extends ClientNetMsg { * ByteBufferReader. */ @Override - protected void _deserialize(ByteBufferReader reader) { + protected void _deserialize(ByteBufferReader reader) { reader.getInt(); // Object Type Padding this.playerUUID = reader.getInt(); this.newRank = reader.getInt(); diff --git a/src/engine/net/client/msg/guild/DisbandGuildMsg.java b/src/engine/net/client/msg/guild/DisbandGuildMsg.java index 0ed97a3b..f9f7cfd3 100644 --- a/src/engine/net/client/msg/guild/DisbandGuildMsg.java +++ b/src/engine/net/client/msg/guild/DisbandGuildMsg.java @@ -18,41 +18,40 @@ import engine.net.client.msg.ClientNetMsg; public class DisbandGuildMsg extends ClientNetMsg { - private int response; - private String message; - - /** - * This is the general purpose constructor. - */ - public DisbandGuildMsg() { - super(Protocol.DISBANDGUILD); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public DisbandGuildMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.DISBANDGUILD, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.response); - writer.putString(this.message); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.response = reader.getInt(); - this.message = reader.getString(); - //this.sourceID = reader.getInt(); - } + private int response; + private String message; + + /** + * This is the general purpose constructor. + */ + public DisbandGuildMsg() { + super(Protocol.DISBANDGUILD); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public DisbandGuildMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.DISBANDGUILD, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.response); + writer.putString(this.message); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.response = reader.getInt(); + this.message = reader.getString(); + //this.sourceID = reader.getInt(); + } } diff --git a/src/engine/net/client/msg/guild/DismissGuildMsg.java b/src/engine/net/client/msg/guild/DismissGuildMsg.java index 1e0559ea..5d67a966 100644 --- a/src/engine/net/client/msg/guild/DismissGuildMsg.java +++ b/src/engine/net/client/msg/guild/DismissGuildMsg.java @@ -18,61 +18,59 @@ import engine.net.client.msg.ClientNetMsg; public class DismissGuildMsg extends ClientNetMsg { - private int unknown01; - private int guildType; - private int guildID; - - /** - * This is the general purpose constructor. - */ - public DismissGuildMsg() { - super(Protocol.DISMISSGUILD); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public DismissGuildMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.DISMISSGUILD, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.unknown01 = reader.getInt(); - this.guildType = reader.getInt(); - this.guildID = reader.getInt(); - reader.getInt(); - - } - - public int getUnknown01() { - return this.unknown01; - } - - - - public void setUnknown01(int value) { - this.unknown01 = value; - } - - public int getGuildID() { - return guildID; - } - - public void setGuildID(int guildID) { - this.guildID = guildID; - } + private int unknown01; + private int guildType; + private int guildID; + + /** + * This is the general purpose constructor. + */ + public DismissGuildMsg() { + super(Protocol.DISMISSGUILD); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public DismissGuildMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.DISMISSGUILD, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.unknown01 = reader.getInt(); + this.guildType = reader.getInt(); + this.guildID = reader.getInt(); + reader.getInt(); + + } + + public int getUnknown01() { + return this.unknown01; + } + + + public void setUnknown01(int value) { + this.unknown01 = value; + } + + public int getGuildID() { + return guildID; + } + + public void setGuildID(int guildID) { + this.guildID = guildID; + } } diff --git a/src/engine/net/client/msg/guild/GuildControlMsg.java b/src/engine/net/client/msg/guild/GuildControlMsg.java index 39e286da..8d938a1d 100644 --- a/src/engine/net/client/msg/guild/GuildControlMsg.java +++ b/src/engine/net/client/msg/guild/GuildControlMsg.java @@ -18,224 +18,215 @@ import engine.net.client.msg.ClientNetMsg; public class GuildControlMsg extends ClientNetMsg { - private int unknown01; - private int unknown02; - private int unknown03; - private int unknown04; - private String message; - private byte unknown05; - private int unknown06; - private int unknown07; - private byte unknown08; - - private byte isGM; - - /** - * This is the general purpose constructor. - */ - public GuildControlMsg() { - super(Protocol.REQUESTMEMBERLIST); - this.unknown01 = 2; - this.unknown02 = 0; - this.unknown03 = 0; - this.unknown04 = 0; - this.message = "No error message"; - this.unknown05 = 0; - this.unknown06 = 0; - this.unknown07 = 257; - this.unknown08 = (byte) 1; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public GuildControlMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.REQUESTMEMBERLIST, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - writer.putInt(this.unknown03); - writer.putInt(this.unknown04); - writer.putString(this.message); - - writer.put((byte) 1); //Always 1 - - writer.put(isGM); //Can be Tax Collector - writer.put(isGM); //Can be Recruiter - writer.put(isGM); //Can be IC - writer.put(isGM); - - writer.put(isGM); //Can be GM - writer.put((byte) 1); - writer.put((byte) 1); - writer.put((byte) 1); - writer.put((byte) 1); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - this.unknown03 = reader.getInt(); - this.unknown04 = reader.getInt(); - this.message = reader.getString(); - this.unknown05 = reader.get(); - if (this.unknown05 == (byte) 1) { - this.unknown06 = reader.getInt(); - this.unknown07 = reader.getInt(); - this.unknown08 = reader.get(); - } - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the unknown02 - */ - public int getUnknown02() { - return unknown02; - } - - /** - * @param unknown02 - * the unknown02 to set - */ - public void setUnknown02(int unknown02) { - this.unknown02 = unknown02; - } - - /** - * @return the unknown03 - */ - public int getUnknown03() { - return unknown03; - } - - /** - * @param unknown03 - * the unknown03 to set - */ - public void setUnknown03(int unknown03) { - this.unknown03 = unknown03; - } - - /** - * @return the unknown04 - */ - public int getUnknown04() { - return unknown04; - } - - /** - * @param unknown04 - * the unknown04 to set - */ - public void setUnknown04(int unknown04) { - this.unknown04 = unknown04; - } - - /** - * @return the message - */ - public String getMessage() { - return message; - } - - /** - * @param message - * the message to set - */ - public void setMessage(String message) { - this.message = message; - } - - /** - * @return the unknown05 - */ - public byte getUnknown05() { - return unknown05; - } - - /** - * @param unknown05 - * the unknown05 to set - */ - public void setUnknown05(byte unknown05) { - this.unknown05 = unknown05; - } - - /** - * @return the unknown06 - */ - public int getUnknown06() { - return unknown06; - } - - /** - * @param unknown06 - * the unknown06 to set - */ - public void setUnknown06(int unknown06) { - this.unknown06 = unknown06; - } - - /** - * @return the unknown07 - */ - public int getUnknown07() { - return unknown07; - } - - /** - * @param unknown07 - * the unknown07 to set - */ - public void setUnknown07(int unknown07) { - this.unknown07 = unknown07; - } - - /** - * @return the unknown08 - */ - public byte getUnknown08() { - return unknown08; - } - - public void setGM(byte b) { - this.isGM = b; - } - - /** - * @param unknown08 - * the unknown08 to set - */ - public void setUnknown08(byte unknown08) { - this.unknown08 = unknown08; - } + private int unknown01; + private int unknown02; + private int unknown03; + private int unknown04; + private String message; + private byte unknown05; + private int unknown06; + private int unknown07; + private byte unknown08; + + private byte isGM; + + /** + * This is the general purpose constructor. + */ + public GuildControlMsg() { + super(Protocol.REQUESTMEMBERLIST); + this.unknown01 = 2; + this.unknown02 = 0; + this.unknown03 = 0; + this.unknown04 = 0; + this.message = "No error message"; + this.unknown05 = 0; + this.unknown06 = 0; + this.unknown07 = 257; + this.unknown08 = (byte) 1; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public GuildControlMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.REQUESTMEMBERLIST, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + writer.putInt(this.unknown03); + writer.putInt(this.unknown04); + writer.putString(this.message); + + writer.put((byte) 1); //Always 1 + + writer.put(isGM); //Can be Tax Collector + writer.put(isGM); //Can be Recruiter + writer.put(isGM); //Can be IC + writer.put(isGM); + + writer.put(isGM); //Can be GM + writer.put((byte) 1); + writer.put((byte) 1); + writer.put((byte) 1); + writer.put((byte) 1); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + this.unknown03 = reader.getInt(); + this.unknown04 = reader.getInt(); + this.message = reader.getString(); + this.unknown05 = reader.get(); + if (this.unknown05 == (byte) 1) { + this.unknown06 = reader.getInt(); + this.unknown07 = reader.getInt(); + this.unknown08 = reader.get(); + } + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the unknown02 + */ + public int getUnknown02() { + return unknown02; + } + + /** + * @param unknown02 the unknown02 to set + */ + public void setUnknown02(int unknown02) { + this.unknown02 = unknown02; + } + + /** + * @return the unknown03 + */ + public int getUnknown03() { + return unknown03; + } + + /** + * @param unknown03 the unknown03 to set + */ + public void setUnknown03(int unknown03) { + this.unknown03 = unknown03; + } + + /** + * @return the unknown04 + */ + public int getUnknown04() { + return unknown04; + } + + /** + * @param unknown04 the unknown04 to set + */ + public void setUnknown04(int unknown04) { + this.unknown04 = unknown04; + } + + /** + * @return the message + */ + public String getMessage() { + return message; + } + + /** + * @param message the message to set + */ + public void setMessage(String message) { + this.message = message; + } + + /** + * @return the unknown05 + */ + public byte getUnknown05() { + return unknown05; + } + + /** + * @param unknown05 the unknown05 to set + */ + public void setUnknown05(byte unknown05) { + this.unknown05 = unknown05; + } + + /** + * @return the unknown06 + */ + public int getUnknown06() { + return unknown06; + } + + /** + * @param unknown06 the unknown06 to set + */ + public void setUnknown06(int unknown06) { + this.unknown06 = unknown06; + } + + /** + * @return the unknown07 + */ + public int getUnknown07() { + return unknown07; + } + + /** + * @param unknown07 the unknown07 to set + */ + public void setUnknown07(int unknown07) { + this.unknown07 = unknown07; + } + + /** + * @return the unknown08 + */ + public byte getUnknown08() { + return unknown08; + } + + /** + * @param unknown08 the unknown08 to set + */ + public void setUnknown08(byte unknown08) { + this.unknown08 = unknown08; + } + + public void setGM(byte b) { + this.isGM = b; + } } diff --git a/src/engine/net/client/msg/guild/GuildCreationCloseMsg.java b/src/engine/net/client/msg/guild/GuildCreationCloseMsg.java index 82b4e552..3a259238 100644 --- a/src/engine/net/client/msg/guild/GuildCreationCloseMsg.java +++ b/src/engine/net/client/msg/guild/GuildCreationCloseMsg.java @@ -20,46 +20,46 @@ import org.pmw.tinylog.Logger; public class GuildCreationCloseMsg extends ClientNetMsg { - /** - * This is the general purpose constructor. - */ - public GuildCreationCloseMsg() { - super(Protocol.CANCELGUILDCREATION); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public GuildCreationCloseMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CANCELGUILDCREATION, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - - - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - for(int j = 0; j < 4; j++) { - int i = reader.getInt(); - Logger.info( j+ "->" + i); - } - } + /** + * This is the general purpose constructor. + */ + public GuildCreationCloseMsg() { + super(Protocol.CANCELGUILDCREATION); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public GuildCreationCloseMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CANCELGUILDCREATION, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + + + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + for (int j = 0; j < 4; j++) { + int i = reader.getInt(); + Logger.info(j + "->" + i); + } + } } diff --git a/src/engine/net/client/msg/guild/GuildCreationFinalizeMsg.java b/src/engine/net/client/msg/guild/GuildCreationFinalizeMsg.java index a28c4c58..53f71710 100644 --- a/src/engine/net/client/msg/guild/GuildCreationFinalizeMsg.java +++ b/src/engine/net/client/msg/guild/GuildCreationFinalizeMsg.java @@ -59,7 +59,7 @@ public class GuildCreationFinalizeMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public GuildCreationFinalizeMsg(AbstractConnection origin, ByteBufferReader reader) { + public GuildCreationFinalizeMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.CREATEPETITION, origin, reader); } @@ -68,8 +68,8 @@ public class GuildCreationFinalizeMsg extends ClientNetMsg { */ @Override protected void _serialize(ByteBufferWriter writer) { - - GuildTag._serializeForDisplay(guildTag,writer); + + GuildTag._serializeForDisplay(guildTag, writer); writer.putString(this.guildName); writer.putString(this.guildMotto); @@ -95,7 +95,7 @@ public class GuildCreationFinalizeMsg extends ClientNetMsg { * Deserializes the subclass specific items from the supplied NetMsgReader. */ @Override - protected void _deserialize(ByteBufferReader reader) { + protected void _deserialize(ByteBufferReader reader) { guildTag = new GuildTag(reader, true); this.guildName = reader.getString(); @@ -133,7 +133,7 @@ public class GuildCreationFinalizeMsg extends ClientNetMsg { charterObject = Item.getFromCache(this.charterUUID); if (charterObject == null) - Logger.error( "Invalid charter object UUID: " + this.charterUUID); + Logger.error("Invalid charter object UUID: " + this.charterUUID); return charterObject; } @@ -143,18 +143,18 @@ public class GuildCreationFinalizeMsg extends ClientNetMsg { } public int getMemberVoteFlag() { - + if (this.membershipVote != 0) return 1; - + return 0; } public int getICVoteFlag() { - + if (this.icVote != 0) return 1; - + return 0; } } diff --git a/src/engine/net/client/msg/guild/GuildCreationOptionsMsg.java b/src/engine/net/client/msg/guild/GuildCreationOptionsMsg.java index 83574d94..c22979b0 100644 --- a/src/engine/net/client/msg/guild/GuildCreationOptionsMsg.java +++ b/src/engine/net/client/msg/guild/GuildCreationOptionsMsg.java @@ -19,133 +19,134 @@ import engine.objects.GuildTag; public class GuildCreationOptionsMsg extends ClientNetMsg { - private int screenType; - private ScreenType messageScreen; - private boolean close = false; - - /** - * This is the general purpose constructor. - */ - public GuildCreationOptionsMsg() { - super(Protocol.CHECKUNIQUEGUILD); - } - public GuildCreationOptionsMsg(boolean close) { - super(Protocol.CHECKUNIQUEGUILD); - this.close = close; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public GuildCreationOptionsMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CHECKUNIQUEGUILD, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.screenType); - if (this.close){ - writer.putInt(2); - writer.putInt(0); + private int screenType; + private ScreenType messageScreen; + private boolean close = false; + + /** + * This is the general purpose constructor. + */ + public GuildCreationOptionsMsg() { + super(Protocol.CHECKUNIQUEGUILD); + } + + public GuildCreationOptionsMsg(boolean close) { + super(Protocol.CHECKUNIQUEGUILD); + this.close = close; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public GuildCreationOptionsMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CHECKUNIQUEGUILD, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.screenType); + if (this.close) { + writer.putInt(2); + writer.putInt(0); // writer.putInt(0); - return; - } - if(this.messageScreen != null) { - this.messageScreen._serialize(writer); - } else { - writer.putInt(0); - writer.putInt(5); - } - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.screenType = reader.getInt(); - if(this.screenType == 1) { - this.messageScreen = new Screen1(); - } else if(this.screenType == 2){ - this.messageScreen = new Screen2(); - } else { - System.out.println("Attempting to Deserilaize: Message Type" + screenType); - int counter = 0; - do { - int i = reader.getInt(); - System.out.println(counter++ + "->" + i); - } while (true); - } - this.messageScreen._deserialize(reader); - } - - /** - * @return the rulership - */ - public int getScreenType() { - return this.screenType; - } - - /** - * @param rulership - * the rulership to set - */ - public void setScreenType(int type) { - this.screenType = type; - } + return; + } + if (this.messageScreen != null) { + this.messageScreen._serialize(writer); + } else { + writer.putInt(0); + writer.putInt(5); + } + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.screenType = reader.getInt(); + if (this.screenType == 1) { + this.messageScreen = new Screen1(); + } else if (this.screenType == 2) { + this.messageScreen = new Screen2(); + } else { + System.out.println("Attempting to Deserilaize: Message Type" + screenType); + int counter = 0; + do { + int i = reader.getInt(); + System.out.println(counter++ + "->" + i); + } while (true); + } + this.messageScreen._deserialize(reader); + } + + /** + * @return the rulership + */ + public int getScreenType() { + return this.screenType; + } + + /** + * @param rulership the rulership to set + */ + public void setScreenType(int type) { + this.screenType = type; + } } abstract class ScreenType { - public abstract void _serialize(ByteBufferWriter writer); - public abstract void _deserialize(ByteBufferReader reader) ; + public abstract void _serialize(ByteBufferWriter writer); + + public abstract void _deserialize(ByteBufferReader reader); } -class Screen1 extends ScreenType{ - private int unknown01; - private int unknown02; - private String name; - private String motto; - - @Override - public void _serialize(ByteBufferWriter writer) { - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - writer.putString(this.name); - } - @Override - public void _deserialize(ByteBufferReader reader) - { - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - this.name = reader.getString(); - this.motto = reader.getString(); - } +class Screen1 extends ScreenType { + private int unknown01; + private int unknown02; + private String name; + private String motto; + + @Override + public void _serialize(ByteBufferWriter writer) { + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + writer.putString(this.name); + } + + @Override + public void _deserialize(ByteBufferReader reader) { + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + this.name = reader.getString(); + this.motto = reader.getString(); + } } -class Screen2 extends ScreenType{ - private int unknown01; - private int unknown02; - private GuildTag gt; - - @Override - public void _serialize(ByteBufferWriter writer) { - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - GuildTag._serializeForGuildCreation(this.gt,writer); - } - @Override - public void _deserialize(ByteBufferReader reader) - { - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - this.gt = new GuildTag(reader, true); - } +class Screen2 extends ScreenType { + private int unknown01; + private int unknown02; + private GuildTag gt; + + @Override + public void _serialize(ByteBufferWriter writer) { + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + GuildTag._serializeForGuildCreation(this.gt, writer); + } + + @Override + public void _deserialize(ByteBufferReader reader) { + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + this.gt = new GuildTag(reader, true); + } } diff --git a/src/engine/net/client/msg/guild/GuildInfoMsg.java b/src/engine/net/client/msg/guild/GuildInfoMsg.java index f81f4f06..c99bd893 100644 --- a/src/engine/net/client/msg/guild/GuildInfoMsg.java +++ b/src/engine/net/client/msg/guild/GuildInfoMsg.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -34,420 +31,414 @@ import org.joda.time.DateTime; public class GuildInfoMsg extends ClientNetMsg { - private int msgType; - private int objectUUID; - private int objectType; - private Guild guild; - private AbstractGameObject ago; - - /** - * This is the general purpose constructor. - */ - public GuildInfoMsg() { - super(Protocol.UPDATEGUILD); - this.msgType = 4; + private int msgType; + private int objectUUID; + private int objectType; + private Guild guild; + private AbstractGameObject ago; + + /** + * This is the general purpose constructor. + */ + public GuildInfoMsg() { + super(Protocol.UPDATEGUILD); + this.msgType = 4; this.objectType = 0; this.objectUUID = 0; - } + } - public GuildInfoMsg(AbstractGameObject ago, Guild guild, int unknown01) { - super(Protocol.UPDATEGUILD); - this.msgType = unknown01; + public GuildInfoMsg(AbstractGameObject ago, Guild guild, int unknown01) { + super(Protocol.UPDATEGUILD); + this.msgType = unknown01; this.objectType = ago.getObjectType().ordinal(); this.objectUUID = ago.getObjectUUID(); - this.ago = ago; - - this.guild = guild; - } - - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public GuildInfoMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.UPDATEGUILD, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.msgType); - - if(this.msgType == 2) { - new GuildInfoMessageType2(this.ago, guild)._serialize(writer); - } else if(this.msgType == 5) { - new GuildInfoMessageType5(this.ago, guild)._serialize(writer); - }else if(this.msgType == 4){ - new GuildInfoMessageType4(this.ago, guild)._serialize(writer); - } else { - writer.putLong(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.put((byte) 0); - } - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.msgType = reader.getInt(); + this.ago = ago; + + this.guild = guild; + } + + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public GuildInfoMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.UPDATEGUILD, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.msgType); + + if (this.msgType == 2) { + new GuildInfoMessageType2(this.ago, guild)._serialize(writer); + } else if (this.msgType == 5) { + new GuildInfoMessageType5(this.ago, guild)._serialize(writer); + } else if (this.msgType == 4) { + new GuildInfoMessageType4(this.ago, guild)._serialize(writer); + } else { + writer.putLong(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.put((byte) 0); + } + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.msgType = reader.getInt(); this.objectType = reader.getInt(); this.objectUUID = reader.getInt(); - + if (this.msgType == 1) - reader.getInt(); - reader.getInt(); // PAdding - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.get(); - - //default guild tag deserializations. - if (this.msgType == 5){ - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - - reader.getInt(); - } - - - } - - /** - * @return the unknown01 - */ - public int getMsgType() { - return msgType; - } - - public void setMsgType(int msgType) { - this.msgType = msgType; - } - - /** - * @return the objectUUID - */ - public int getObjectID() { - return objectUUID; - } - - public int getObjectType() { - return objectType; - } - - public void setObjectType(int objectType) { - this.objectType = objectType; - } + reader.getInt(); + reader.getInt(); // PAdding + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.get(); + + //default guild tag deserializations. + if (this.msgType == 5) { + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + + reader.getInt(); + } + + + } + + /** + * @return the unknown01 + */ + public int getMsgType() { + return msgType; + } + + public void setMsgType(int msgType) { + this.msgType = msgType; + } + + /** + * @return the objectUUID + */ + public int getObjectID() { + return objectUUID; + } + + public int getObjectType() { + return objectType; + } + + public void setObjectType(int objectType) { + this.objectType = objectType; + } } abstract class GuildInfoMessageType { - protected int objectType; - protected int objectID; - protected Guild g; - protected AbstractGameObject ago; - - public GuildInfoMessageType(AbstractGameObject ago, Guild g) { - this.objectType = ago.getObjectType().ordinal(); - this.objectID = ago.getObjectUUID(); - this.ago = ago; - this.g = g; - } - - abstract void _serialize(ByteBufferWriter writer); + protected int objectType; + protected int objectID; + protected Guild g; + protected AbstractGameObject ago; + + public GuildInfoMessageType(AbstractGameObject ago, Guild g) { + this.objectType = ago.getObjectType().ordinal(); + this.objectID = ago.getObjectUUID(); + this.ago = ago; + this.g = g; + } + + abstract void _serialize(ByteBufferWriter writer); } class GuildInfoMessageType2 extends GuildInfoMessageType { - public GuildInfoMessageType2(AbstractGameObject ago, Guild g) { - super(ago, g); - } - - @Override - void _serialize(ByteBufferWriter writer) { - writer.putInt(this.objectType); - writer.putInt(this.objectID); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(1); - - Guild nation = null; - if (this.g != null) { - writer.putInt(GameObjectType.Guild.ordinal()); - writer.putInt(g.getObjectUUID()); - writer.putString(g.getName()); - - if(this.objectType == GameObjectType.PlayerCharacter.ordinal()) { - PlayerCharacter pc = PlayerCharacter.getFromCache(this.objectID); - - if(pc != null) { - writer.putInt(GuildStatusController.getRank(pc.getGuildStatus())); - } - } else { - writer.putInt(5); - } - GuildTag._serializeForDisplay(g.getGuildTag(),writer); - nation = this.g.getNation(); - } else { - writer.putLong(0L); - writer.putString(""); - GuildTag._serializeForDisplay(GuildTag.ERRANT,writer); - } - - writer.putInt(1); - if (nation != null) { - writer.putInt(GameObjectType.Guild.ordinal()); - writer.putInt(nation.getObjectUUID()); - - City city = g.getOwnedCity(); - if (city != null) { - writer.putString(city.getCityName()); - writer.putInt(city.getObjectType().ordinal()); - writer.putInt(city.getObjectUUID()); - } else { - writer.putString(""); //city name - writer.putLong(0L); //should be city ID - } - - GuildTag._serializeForDisplay(nation.getGuildTag(),writer); - - } else { - writer.putLong(0L); - writer.putString(""); - writer.putLong(0L); - GuildTag._serializeForDisplay(GuildTag.ERRANT,writer); - } - writer.putInt(0); - - writer.putInt(0); - writer.put((byte)0); - } + public GuildInfoMessageType2(AbstractGameObject ago, Guild g) { + super(ago, g); + } + + @Override + void _serialize(ByteBufferWriter writer) { + writer.putInt(this.objectType); + writer.putInt(this.objectID); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(1); + + Guild nation = null; + if (this.g != null) { + writer.putInt(GameObjectType.Guild.ordinal()); + writer.putInt(g.getObjectUUID()); + writer.putString(g.getName()); + + if (this.objectType == GameObjectType.PlayerCharacter.ordinal()) { + PlayerCharacter pc = PlayerCharacter.getFromCache(this.objectID); + + if (pc != null) { + writer.putInt(GuildStatusController.getRank(pc.getGuildStatus())); + } + } else { + writer.putInt(5); + } + GuildTag._serializeForDisplay(g.getGuildTag(), writer); + nation = this.g.getNation(); + } else { + writer.putLong(0L); + writer.putString(""); + GuildTag._serializeForDisplay(GuildTag.ERRANT, writer); + } + + writer.putInt(1); + if (nation != null) { + writer.putInt(GameObjectType.Guild.ordinal()); + writer.putInt(nation.getObjectUUID()); + + City city = g.getOwnedCity(); + if (city != null) { + writer.putString(city.getCityName()); + writer.putInt(city.getObjectType().ordinal()); + writer.putInt(city.getObjectUUID()); + } else { + writer.putString(""); //city name + writer.putLong(0L); //should be city ID + } + + GuildTag._serializeForDisplay(nation.getGuildTag(), writer); + + } else { + writer.putLong(0L); + writer.putString(""); + writer.putLong(0L); + GuildTag._serializeForDisplay(GuildTag.ERRANT, writer); + } + writer.putInt(0); + + writer.putInt(0); + writer.put((byte) 0); + } } class GuildInfoMessageType4 extends GuildInfoMessageType { - public GuildInfoMessageType4(AbstractGameObject ago, Guild g) { - super(ago, g); - } - - @Override - void _serialize(ByteBufferWriter writer) { - String cityName = ""; - writer.putInt(this.objectType); - writer.putInt(this.objectID); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - PlayerCharacter pc = PlayerCharacter.getFromCache(this.objectID); - if (this.g == null || pc == null){ - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.put((byte)0); - return; - } - - writer.putInt(1); - Guild nation = this.g.getNation(); - writer.putInt(0); - writer.putInt(0); - writer.putString(g.getName()); - writer.putInt(0); - GuildTag._serializeForDisplay(g.getGuildTag(),writer); - writer.putInt(1); - writer.putInt(0); - writer.putInt(0); - City city = g.getOwnedCity(); - if (city != null) - cityName = city.getCityName(); - writer.putString(nation.getName()); - writer.putInt(0); - writer.putInt(0); - - GuildTag._serializeForDisplay(nation.getGuildTag(),writer); - writer.putInt(1); - - writer.putString(g.getName()); - writer.putString(g.getMotto()); - writer.putString(nation.getName()); - writer.putInt(GuildStatusController.getRank(pc.getGuildStatus())); - writer.putInt(GuildStatusController.getTitle(pc.getGuildStatus())); - writer.putInt(g.getCharter()); - writer.putString(cityName); //Shows City Name FUCK - AbstractCharacter guildLeader; - String guildLeaderName = ""; - if (g.isNPCGuild()){ - guildLeader = NPC.getFromCache(g.getGuildLeaderUUID()); - if (guildLeader != null) - guildLeaderName = guildLeader.getName(); - } - - else{ - guildLeader = PlayerCharacter.getFromCache(g.getGuildLeaderUUID()); - if (guildLeader != null) - guildLeaderName = ((PlayerCharacter)guildLeader).getCombinedName(); - } - - writer.putString(guildLeaderName); - writer.putString(pc.getName()); - - writer.putDateTime(DateTime.now()); - writer.put((byte)1); - writer.put((byte)1); - writer.put((byte)1); - writer.put((byte)0); - writer.putInt(0); - - - - - - - // writer.put((byte)0); - - - // writer.putString(cityName); - // writer.putInt(10); - // writer.putInt(6); - // writer.putInt(10); - // writer.putString(cityName); - // writer.putString(pc.getFirstName()); - // writer.putString("Nation Leader"); - // writer.putDateTime(DateTime.now()); - // writer.put((byte)1); - // writer.put((byte)1); - // writer.putInt(1); - // writer.putInt(this.objectType); - // writer.putInt(this.objectID); - // writer.putInt(0); - // writer.putInt(0); - - - } + public GuildInfoMessageType4(AbstractGameObject ago, Guild g) { + super(ago, g); + } + + @Override + void _serialize(ByteBufferWriter writer) { + String cityName = ""; + writer.putInt(this.objectType); + writer.putInt(this.objectID); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + PlayerCharacter pc = PlayerCharacter.getFromCache(this.objectID); + if (this.g == null || pc == null) { + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 0); + return; + } + + writer.putInt(1); + Guild nation = this.g.getNation(); + writer.putInt(0); + writer.putInt(0); + writer.putString(g.getName()); + writer.putInt(0); + GuildTag._serializeForDisplay(g.getGuildTag(), writer); + writer.putInt(1); + writer.putInt(0); + writer.putInt(0); + City city = g.getOwnedCity(); + if (city != null) + cityName = city.getCityName(); + writer.putString(nation.getName()); + writer.putInt(0); + writer.putInt(0); + + GuildTag._serializeForDisplay(nation.getGuildTag(), writer); + writer.putInt(1); + + writer.putString(g.getName()); + writer.putString(g.getMotto()); + writer.putString(nation.getName()); + writer.putInt(GuildStatusController.getRank(pc.getGuildStatus())); + writer.putInt(GuildStatusController.getTitle(pc.getGuildStatus())); + writer.putInt(g.getCharter()); + writer.putString(cityName); //Shows City Name FUCK + AbstractCharacter guildLeader; + String guildLeaderName = ""; + if (g.isNPCGuild()) { + guildLeader = NPC.getFromCache(g.getGuildLeaderUUID()); + if (guildLeader != null) + guildLeaderName = guildLeader.getName(); + } else { + guildLeader = PlayerCharacter.getFromCache(g.getGuildLeaderUUID()); + if (guildLeader != null) + guildLeaderName = ((PlayerCharacter) guildLeader).getCombinedName(); + } + + writer.putString(guildLeaderName); + writer.putString(pc.getName()); + + writer.putDateTime(DateTime.now()); + writer.put((byte) 1); + writer.put((byte) 1); + writer.put((byte) 1); + writer.put((byte) 0); + writer.putInt(0); + + + // writer.put((byte)0); + + + // writer.putString(cityName); + // writer.putInt(10); + // writer.putInt(6); + // writer.putInt(10); + // writer.putString(cityName); + // writer.putString(pc.getFirstName()); + // writer.putString("Nation Leader"); + // writer.putDateTime(DateTime.now()); + // writer.put((byte)1); + // writer.put((byte)1); + // writer.putInt(1); + // writer.putInt(this.objectType); + // writer.putInt(this.objectID); + // writer.putInt(0); + // writer.putInt(0); + + + } } class GuildInfoMessageType5 extends GuildInfoMessageType { - public GuildInfoMessageType5(AbstractGameObject ago, Guild g) { - super(ago, g); - } + public GuildInfoMessageType5(AbstractGameObject ago, Guild g) { + super(ago, g); + } + + @Override + void _serialize(ByteBufferWriter writer) { - @Override - void _serialize(ByteBufferWriter writer) { + PlayerCharacter pc = null; - PlayerCharacter pc = null; + if (ago.getObjectType().equals(GameObjectType.PlayerCharacter)) { + pc = (PlayerCharacter) ago; + } - if(ago.getObjectType().equals(GameObjectType.PlayerCharacter)) { - pc = (PlayerCharacter) ago; - } + if (pc != null && g != null && g.getObjectUUID() != 0) { + Guild n = g.getNation(); + if (n == null) { + n = Guild.getErrantNation(); + } - if(pc != null && g != null && g.getObjectUUID() != 0) { - Guild n = g.getNation(); - if(n == null) { - n = Guild.getErrantNation(); - } - - writer.putInt(ago.getObjectType().ordinal()); - writer.putInt(ago.getObjectUUID()); + writer.putInt(ago.getObjectType().ordinal()); + writer.putInt(ago.getObjectUUID()); - 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(1); - writer.putInt(0); - writer.putInt(0); + writer.putInt(1); + writer.putInt(0); + writer.putInt(0); - writer.putString(g.getName()); //No Effect? - writer.putInt(0); //Pad + writer.putString(g.getName()); //No Effect? + writer.putInt(0); //Pad - GuildTag._serializeForDisplay(g.getGuildTag(),writer); //Also a waste of space... + GuildTag._serializeForDisplay(g.getGuildTag(), writer); //Also a waste of space... - writer.putInt(1); - writer.putInt(0); - writer.putInt(0); - writer.putString(n.getName()); //No Effect? - writer.putInt(0); - writer.putInt(0); + writer.putInt(1); + writer.putInt(0); + writer.putInt(0); + writer.putString(n.getName()); //No Effect? + writer.putInt(0); + writer.putInt(0); - GuildTag._serializeForDisplay(n.getGuildTag(),writer); + GuildTag._serializeForDisplay(n.getGuildTag(), writer); - writer.putInt(1); + writer.putInt(1); - writer.putString(g.getName()); //Guild Name - writer.putString(g.getMotto()); //TODO Motto - writer.putString(n.getName()); //Nation Name + writer.putString(g.getName()); //Guild Name + writer.putString(g.getMotto()); //TODO Motto + writer.putString(n.getName()); //Nation Name - writer.putInt(GuildStatusController.getRank(pc.getGuildStatus())); //Rank - writer.putInt(GuildStatusController.getTitle(pc.getGuildStatus())); //Title - writer.putInt(g.getCharter()); + writer.putInt(GuildStatusController.getRank(pc.getGuildStatus())); //Rank + writer.putInt(GuildStatusController.getTitle(pc.getGuildStatus())); //Title + writer.putInt(g.getCharter()); - if(g.getNation().equals(Guild.getErrantNation())) - writer.putString("Errant"); - else - writer.putString("City"); - writer.putString("Guild Leader"); - writer.putString(""); //Nation Leader - I believe + if (g.getNation().equals(Guild.getErrantNation())) + writer.putString("Errant"); + else + writer.putString("City"); + writer.putString("Guild Leader"); + writer.putString(""); //Nation Leader - I believe - DateTime now = DateTime.now(); - writer.putDateTime(now); + DateTime now = DateTime.now(); + writer.putDateTime(now); - writer.put((byte) 1); - writer.put((byte) 1); - writer.put((byte) 0); - writer.put((byte) 0); + writer.put((byte) 1); + writer.put((byte) 1); + writer.put((byte) 0); + writer.put((byte) 0); - GuildTag._serializeForDisplay(g.getGuildTag(),writer); - GuildTag._serializeForDisplay(g.getNation().getGuildTag(),writer); - writer.putInt(0); - } else { - writer.putLong(0); + GuildTag._serializeForDisplay(g.getGuildTag(), writer); + GuildTag._serializeForDisplay(g.getNation().getGuildTag(), writer); + writer.putInt(0); + } else { + writer.putLong(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.putInt(0); + writer.putInt(0); - writer.put((byte) 0); + writer.put((byte) 0); - GuildTag._serializeForDisplay(GuildTag.ERRANT,writer); - GuildTag._serializeForDisplay(GuildTag.ERRANT,writer); + GuildTag._serializeForDisplay(GuildTag.ERRANT, writer); + GuildTag._serializeForDisplay(GuildTag.ERRANT, writer); - writer.putInt(0); - } - } + writer.putInt(0); + } + } } diff --git a/src/engine/net/client/msg/guild/GuildListMsg.java b/src/engine/net/client/msg/guild/GuildListMsg.java index 17404166..f40783be 100644 --- a/src/engine/net/client/msg/guild/GuildListMsg.java +++ b/src/engine/net/client/msg/guild/GuildListMsg.java @@ -27,49 +27,49 @@ import java.util.ArrayList; public class GuildListMsg extends ClientNetMsg { - private GuildListMessageType glm; - - /** - * Type 1 Constructor - Guild Roster - */ - public GuildListMsg(Guild g) { - super(Protocol.SENDMEMBERENTRY); - this.glm = new GuildListMessageType1(g); - } - - /** - * Type 4 Constructor - Guild History - */ - public GuildListMsg(PlayerCharacter pc) { - super(Protocol.SENDMEMBERENTRY); - this.glm = new GuildListMessageType2(pc); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public GuildListMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.SENDMEMBERENTRY, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - - //TODO Find Default and null check this - this.glm._serialize(writer); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { + private GuildListMessageType glm; + + /** + * Type 1 Constructor - Guild Roster + */ + public GuildListMsg(Guild g) { + super(Protocol.SENDMEMBERENTRY); + this.glm = new GuildListMessageType1(g); + } + + /** + * Type 4 Constructor - Guild History + */ + public GuildListMsg(PlayerCharacter pc) { + super(Protocol.SENDMEMBERENTRY); + this.glm = new GuildListMessageType2(pc); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public GuildListMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SENDMEMBERENTRY, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + + //TODO Find Default and null check this + this.glm._serialize(writer); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { /* * * The Server should never receive this message directly. @@ -100,129 +100,129 @@ public class GuildListMsg extends ClientNetMsg { gt.setUnknown07(reader.getInt()); } */ - } + } - @Override - protected int getPowerOfTwoBufferSize() { - // Larger size for historically larger opcodes - return 15; - } + @Override + protected int getPowerOfTwoBufferSize() { + // Larger size for historically larger opcodes + return 15; + } } abstract class GuildListMessageType { - public ArrayList history = new ArrayList<>(); + public ArrayList history = new ArrayList<>(); - abstract void _serialize(ByteBufferWriter writer); + abstract void _serialize(ByteBufferWriter writer); } class GuildListMessageType1 extends GuildListMessageType { - private Guild g; - - public GuildListMessageType1(Guild g) { - this.g = g; - } - - @Override - void _serialize(ByteBufferWriter writer) { - Enum.GuildType gt = Enum.GuildType.getGuildTypeFromInt(g.getCharter()); - - writer.putInt(1); - writer.putInt(gt.ordinal()); //Charter Type - writer.putInt(1); //Always 1? - writer.put((byte) 1); - writer.put((byte) 0); - writer.putInt(gt.getNumberOfRanks()); //Number of Ranks - - - ArrayList guildRoster = Guild.GuildRoster(g); - writer.putInt(guildRoster.size() + g.getBanishList().size()); - - // Send guild list of each player - for (PlayerCharacter player : guildRoster) { - - byte isActive = SessionManager.getPlayerCharacterByID(player.getObjectUUID()) != null ? (byte)1 : (byte)0; - writer.putInt(Enum.GameObjectType.PlayerCharacter.ordinal()); - writer.putInt(player.getObjectUUID()); - writer.putString(player.getCombinedName()); - writer.put(isActive); //Active? - writer.putInt(GuildStatusController.getTitle(player.getGuildStatus())); - writer.putInt(GuildStatusController.getRank(player.getGuildStatus())); - writer.putInt(0); // 1/2 has no effect - writer.putInt(0); // 1 has no effect - writer.putInt(0); // 1 has no effect - writer.putInt(0); // 1 has no effect - writer.putInt(GuildStatusController.getRank(player.getGuildStatus())); - writer.putInt(0); // window failed to open when set to 1 - } - - for (PlayerCharacter banished : g.getBanishList()){ - byte isActive = SessionManager.getPlayerCharacterByID(banished.getObjectUUID()) != null ? (byte)1 : (byte)0; - writer.putInt(Enum.GameObjectType.PlayerCharacter.ordinal()); - writer.putInt(banished.getObjectUUID()); - writer.putString(banished.getCombinedName()); - writer.put(isActive); //Active? - writer.putInt(GuildStatusController.getTitle(banished.getGuildStatus())); - writer.putInt(3); - writer.putInt(0); // 1/2 has no effect - writer.putInt(0); // 1 has no effect - writer.putInt(0); // 1 has no effect - writer.putInt(0); // 1 has no effect - writer.putInt(3); - writer.putInt(0); // window failed to open when set to 1 - } - } + private Guild g; + + public GuildListMessageType1(Guild g) { + this.g = g; + } + + @Override + void _serialize(ByteBufferWriter writer) { + Enum.GuildType gt = Enum.GuildType.getGuildTypeFromInt(g.getCharter()); + + writer.putInt(1); + writer.putInt(gt.ordinal()); //Charter Type + writer.putInt(1); //Always 1? + writer.put((byte) 1); + writer.put((byte) 0); + writer.putInt(gt.getNumberOfRanks()); //Number of Ranks + + + ArrayList guildRoster = Guild.GuildRoster(g); + writer.putInt(guildRoster.size() + g.getBanishList().size()); + + // Send guild list of each player + for (PlayerCharacter player : guildRoster) { + + byte isActive = SessionManager.getPlayerCharacterByID(player.getObjectUUID()) != null ? (byte) 1 : (byte) 0; + writer.putInt(Enum.GameObjectType.PlayerCharacter.ordinal()); + writer.putInt(player.getObjectUUID()); + writer.putString(player.getCombinedName()); + writer.put(isActive); //Active? + writer.putInt(GuildStatusController.getTitle(player.getGuildStatus())); + writer.putInt(GuildStatusController.getRank(player.getGuildStatus())); + writer.putInt(0); // 1/2 has no effect + writer.putInt(0); // 1 has no effect + writer.putInt(0); // 1 has no effect + writer.putInt(0); // 1 has no effect + writer.putInt(GuildStatusController.getRank(player.getGuildStatus())); + writer.putInt(0); // window failed to open when set to 1 + } + + for (PlayerCharacter banished : g.getBanishList()) { + byte isActive = SessionManager.getPlayerCharacterByID(banished.getObjectUUID()) != null ? (byte) 1 : (byte) 0; + writer.putInt(Enum.GameObjectType.PlayerCharacter.ordinal()); + writer.putInt(banished.getObjectUUID()); + writer.putString(banished.getCombinedName()); + writer.put(isActive); //Active? + writer.putInt(GuildStatusController.getTitle(banished.getGuildStatus())); + writer.putInt(3); + writer.putInt(0); // 1/2 has no effect + writer.putInt(0); // 1 has no effect + writer.putInt(0); // 1 has no effect + writer.putInt(0); // 1 has no effect + writer.putInt(3); + writer.putInt(0); // window failed to open when set to 1 + } + } } class GuildListMessageType2 extends GuildListMessageType { - private PlayerCharacter pc; + private PlayerCharacter pc; - public GuildListMessageType2(PlayerCharacter pc) { - this.pc = pc; - } + public GuildListMessageType2(PlayerCharacter pc) { + this.pc = pc; + } - @Override - void _serialize(ByteBufferWriter writer) { + @Override + void _serialize(ByteBufferWriter writer) { - Guild g = pc.getGuild(); + Guild g = pc.getGuild(); - writer.putInt(4); + writer.putInt(4); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); - writer.put((byte) 0); - writer.put((byte) 0); - writer.putInt(1); - writer.putInt(pc.getObjectType().ordinal()); - writer.putInt(pc.getObjectUUID()); - writer.putString(pc.getCombinedName()); + writer.put((byte) 0); + writer.put((byte) 0); + writer.putInt(1); + writer.putInt(pc.getObjectType().ordinal()); + writer.putInt(pc.getObjectUUID()); + writer.putString(pc.getCombinedName()); - writer.put((byte) 1); - writer.putInt(GuildStatusController.getTitle(pc.getGuildStatus())); //Title Maybe? - writer.putInt(GuildStatusController.getRank(pc.getGuildStatus())); //Rank? + writer.put((byte) 1); + writer.putInt(GuildStatusController.getTitle(pc.getGuildStatus())); //Title Maybe? + writer.putInt(GuildStatusController.getRank(pc.getGuildStatus())); //Rank? - writer.putInt(pc.getRaceToken()); //race token - writer.putInt(pc.getBaseClassToken()); //class token + writer.putInt(pc.getRaceToken()); //race token + writer.putInt(pc.getBaseClassToken()); //class token - writer.putInt(2); //PAD - writer.putInt(pc.getLevel()); - writer.putInt(g.getCharter()); + writer.putInt(2); //PAD + writer.putInt(pc.getLevel()); + writer.putInt(g.getCharter()); - //TODO Get Guild History from the DB - //ArrayList history = DbManager.GuildQueries.GET_GUILD_HISTORY_OF_PLAYER((int)pc.getPlayerUUID()); - writer.putInt(pc.getGuildHistory().size()); //Number of Entries + //TODO Get Guild History from the DB + //ArrayList history = DbManager.GuildQueries.GET_GUILD_HISTORY_OF_PLAYER((int)pc.getPlayerUUID()); + writer.putInt(pc.getGuildHistory().size()); //Number of Entries - for(GuildHistory guildHistory : pc.getGuildHistory()) { - writer.putInt(guildHistory.getHistoryType().getType()); - writer.putInt(GameObjectType.Guild.ordinal()); - writer.putInt((int) guildHistory.getGuildID()); - writer.putString(guildHistory.getGuildName()); - writer.putInt(0); - writer.putDateTime(guildHistory.getTime()); - } - } + for (GuildHistory guildHistory : pc.getGuildHistory()) { + writer.putInt(guildHistory.getHistoryType().getType()); + writer.putInt(GameObjectType.Guild.ordinal()); + writer.putInt((int) guildHistory.getGuildID()); + writer.putString(guildHistory.getGuildName()); + writer.putInt(0); + writer.putDateTime(guildHistory.getTime()); + } + } } diff --git a/src/engine/net/client/msg/guild/GuildUnknownMsg.java b/src/engine/net/client/msg/guild/GuildUnknownMsg.java index 6eb32778..87ff4020 100644 --- a/src/engine/net/client/msg/guild/GuildUnknownMsg.java +++ b/src/engine/net/client/msg/guild/GuildUnknownMsg.java @@ -18,50 +18,49 @@ import engine.net.client.msg.ClientNetMsg; public class GuildUnknownMsg extends ClientNetMsg { - private int unknown01; - private int unknown02; - private int unknown03; - private byte unknownByte; + private int unknown01; + private int unknown02; + private int unknown03; + private byte unknownByte; - /** - * This is the general purpose constructor. - */ - public GuildUnknownMsg() { - super(Protocol.UPDATECLIENTALLIANCES); - } + /** + * This is the general purpose constructor. + */ + public GuildUnknownMsg() { + super(Protocol.UPDATECLIENTALLIANCES); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public GuildUnknownMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.UPDATECLIENTALLIANCES, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public GuildUnknownMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.UPDATECLIENTALLIANCES, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.put((byte)1); + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 1); // writer.putInt(this.unknown01); // writer.putInt(this.unknown02); // writer.putInt(this.unknown02); // writer.putInt(this.unknownByte); - } + } - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.unknown01 = reader.getInt(); - this.unknown02 = reader.getInt(); - this.unknown02 = reader.getInt(); - this.unknownByte = reader.get(); - } + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.unknown01 = reader.getInt(); + this.unknown02 = reader.getInt(); + this.unknown02 = reader.getInt(); + this.unknownByte = reader.get(); + } } diff --git a/src/engine/net/client/msg/guild/InviteToGuildMsg.java b/src/engine/net/client/msg/guild/InviteToGuildMsg.java index a5692ac4..48d9369f 100644 --- a/src/engine/net/client/msg/guild/InviteToGuildMsg.java +++ b/src/engine/net/client/msg/guild/InviteToGuildMsg.java @@ -19,173 +19,163 @@ import engine.objects.GuildTag; public class InviteToGuildMsg extends ClientNetMsg { - private int response; - private int sourceType; - private int sourceUUID; - private int targetType; - private int targetUUID; - private int unknown01; - private String message; - private GuildTag gt; - private String guildName; - private int guildType; - private int guildID; - private String targetName; - - /** - * This is the general purpose constructor. - */ - public InviteToGuildMsg() { - super(Protocol.INVITETOGUILD); - this.response = 0; - this.message = "No error message"; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public InviteToGuildMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.INVITETOGUILD, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.response); - writer.putLong(this.sourceUUID); - writer.putLong(this.targetUUID); - writer.putInt(this.unknown01); - writer.putString(this.message); - writer.putInt(this.gt.backgroundColor01); - writer.putInt(this.gt.backgroundColor02); - writer.putInt(this.gt.symbolColor); - writer.putInt(this.gt.symbol); - writer.putInt(this.gt.backgroundDesign); - writer.putString(this.guildName); - writer.putInt(this.guildType); - writer.putInt(this.guildID); - writer.putString(this.targetName); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.response = reader.getInt(); - this.sourceType = reader.getInt(); - this.sourceUUID = reader.getInt(); - this.targetType = reader.getInt(); - this.targetUUID = reader.getInt(); - this.unknown01 = reader.getInt(); - this.message = reader.getString(); - this.gt = new GuildTag(reader); - this.guildName = reader.getString(); - this.guildType = reader.getInt(); - this.guildID = reader.getInt(); - this.targetName = reader.getString(); - } - - public GuildTag getGuildTag() { - return this.gt; - } - - public void setGuildTag(GuildTag gt) { - this.gt = gt; - } - - /** - * @return the response - */ - public int getResponse() { - return response; - } - - /** - * @param response - * the response to set - */ - public void setResponse(int response) { - this.response = response; - } - - /** - * @return the sourceUUID - */ - public int getSourceUUID() { - return sourceUUID; - } - - /** - * @param sourceUUID - * the sourceUUID to set - */ - public void setSourceUUID(int sourceUUID) { - this.sourceUUID = sourceUUID; - } - - /** - * @return the targetUUID - */ - public int getTargetUUID() { - return targetUUID; - } - - /** - * @param targetUUID - * the targetUUID to set - */ - public void setTargetUUID(int targetUUID) { - this.targetUUID = targetUUID; - } - - /** - * @param guildName - * the guildName to set - */ - public void setGuildName(String guildName) { - this.guildName = guildName; - } - - /** - * @param guildID - * the guildID to set - */ - public void setGuildUUID(int guildID) { - this.guildID = guildID; - } - - /** - * @return the targetName - */ - public String getTargetName() { - return targetName; - } - - /** - * @param targetName - * the targetName to set - */ - public void setTargetName(String targetName) { - this.targetName = targetName; - } - - public void setSourceType(int sourceType) { - this.sourceType = sourceType; - } - - public void setTargetType(int targetType) { - this.targetType = targetType; - } - - public void setGuildType(int guildType) { - this.guildType = guildType; - } + private int response; + private int sourceType; + private int sourceUUID; + private int targetType; + private int targetUUID; + private int unknown01; + private String message; + private GuildTag gt; + private String guildName; + private int guildType; + private int guildID; + private String targetName; + + /** + * This is the general purpose constructor. + */ + public InviteToGuildMsg() { + super(Protocol.INVITETOGUILD); + this.response = 0; + this.message = "No error message"; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public InviteToGuildMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.INVITETOGUILD, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.response); + writer.putLong(this.sourceUUID); + writer.putLong(this.targetUUID); + writer.putInt(this.unknown01); + writer.putString(this.message); + writer.putInt(this.gt.backgroundColor01); + writer.putInt(this.gt.backgroundColor02); + writer.putInt(this.gt.symbolColor); + writer.putInt(this.gt.symbol); + writer.putInt(this.gt.backgroundDesign); + writer.putString(this.guildName); + writer.putInt(this.guildType); + writer.putInt(this.guildID); + writer.putString(this.targetName); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.response = reader.getInt(); + this.sourceType = reader.getInt(); + this.sourceUUID = reader.getInt(); + this.targetType = reader.getInt(); + this.targetUUID = reader.getInt(); + this.unknown01 = reader.getInt(); + this.message = reader.getString(); + this.gt = new GuildTag(reader); + this.guildName = reader.getString(); + this.guildType = reader.getInt(); + this.guildID = reader.getInt(); + this.targetName = reader.getString(); + } + + public GuildTag getGuildTag() { + return this.gt; + } + + public void setGuildTag(GuildTag gt) { + this.gt = gt; + } + + /** + * @return the response + */ + public int getResponse() { + return response; + } + + /** + * @param response the response to set + */ + public void setResponse(int response) { + this.response = response; + } + + /** + * @return the sourceUUID + */ + public int getSourceUUID() { + return sourceUUID; + } + + /** + * @param sourceUUID the sourceUUID to set + */ + public void setSourceUUID(int sourceUUID) { + this.sourceUUID = sourceUUID; + } + + /** + * @return the targetUUID + */ + public int getTargetUUID() { + return targetUUID; + } + + /** + * @param targetUUID the targetUUID to set + */ + public void setTargetUUID(int targetUUID) { + this.targetUUID = targetUUID; + } + + /** + * @param guildName the guildName to set + */ + public void setGuildName(String guildName) { + this.guildName = guildName; + } + + /** + * @param guildID the guildID to set + */ + public void setGuildUUID(int guildID) { + this.guildID = guildID; + } + + /** + * @return the targetName + */ + public String getTargetName() { + return targetName; + } + + /** + * @param targetName the targetName to set + */ + public void setTargetName(String targetName) { + this.targetName = targetName; + } + + public void setSourceType(int sourceType) { + this.sourceType = sourceType; + } + + public void setGuildType(int guildType) { + this.guildType = guildType; + } /** * @return the targetType @@ -193,4 +183,8 @@ public class InviteToGuildMsg extends ClientNetMsg { public int getTargetType() { return targetType; } + + public void setTargetType(int targetType) { + this.targetType = targetType; + } } diff --git a/src/engine/net/client/msg/guild/InviteToSubMsg.java b/src/engine/net/client/msg/guild/InviteToSubMsg.java index 3784d696..4fa7b078 100644 --- a/src/engine/net/client/msg/guild/InviteToSubMsg.java +++ b/src/engine/net/client/msg/guild/InviteToSubMsg.java @@ -19,183 +19,180 @@ import engine.objects.GuildTag; public class InviteToSubMsg extends ClientNetMsg { - //12d67402 0000f062 56253600 0010b062 d7821800 00000000 - //10000000 4e006f0020006500720072006f00720020006d00650073007300610067006500 - //0a000000 03000000 07000000 a0000000 04000000 - //17000000 4800650072006f006500730020006f0066002000530065006100200044006f006700730020005200650073007400 - //0000200a 33000000 00000000 01000000 - - //12d67402 0000d062 11fe1700 00009063 3ee91300 00000000 - //10000000 4e006f0020006500720072006f00720020006d00650073007300610067006500 - //08000000 08000000 07000000 96000000 0d000000 - //11000000 42006c006f006f00640020004d006f006f006e00200052006900730069006e006700 - //0000c006 64540000 01000000 00000000 - - //12d67402 0000e062 db2d0000 00005063 116e1100 00000000 - //10000000 4e006f0020006500720072006f00720020006d00650073007300610067006500 - //05000000 11000000 0e000000 95000000 05000000 - //09000000 530074006f0072006d0068006f006c006400 - //0000c006 56300000 01000000 00000000 - - private int sourceUUID; - private int targetUUID; - private int unknown01; - private String message; - private GuildTag gt; - private String guildName; - private int guildUUID; - private int unknown02; - private int unknown03; - - /** - * This is the general purpose constructor. - */ - public InviteToSubMsg() { - super(Protocol.INVITEGUILDFEALTY); - this.message = "No error message"; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public InviteToSubMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.INVITEGUILDFEALTY, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(GameObjectType.PlayerCharacter.ordinal()); - writer.putInt(this.sourceUUID); - writer.putInt(GameObjectType.PlayerCharacter.ordinal()); - writer.putInt(this.targetUUID); - writer.putInt(this.unknown01); - writer.putString(this.message); - writer.putInt(this.gt.backgroundColor01); - writer.putInt(this.gt.backgroundColor02); - writer.putInt(this.gt.symbolColor); - writer.putInt(this.gt.symbol); - writer.putInt(this.gt.backgroundDesign); - writer.putString(this.guildName); - writer.putInt(GameObjectType.Guild.ordinal()); - writer.putInt(this.guildUUID); - writer.putInt(this.unknown02); - writer.putInt(this.unknown03); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - reader.getInt(); - this.sourceUUID = reader.getInt(); - reader.getInt(); - this.targetUUID = reader.getInt(); - this.unknown01 = reader.getInt(); - this.message = reader.getString(); - this.gt = new GuildTag(reader); - this.guildName = reader.getString(); - reader.getInt(); // Padding for Object Type - this.guildUUID = reader.getInt(); - this.unknown02 = reader.getInt(); - this.unknown03 = reader.getInt(); - } - - public GuildTag getGuildTag() { - return this.gt; - } - - public void setGuildTag(GuildTag gt) { - this.gt = gt; - } - - /** - * @return the sourceUUID - */ - public int getSourceUUID() { - return sourceUUID; - } - - /** - * @return the targetUUID - */ - public int getTargetUUID() { - return targetUUID; - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the message - */ - public String getMessage() { - return message; - } - - /** - * @param message - * the message to set - */ - public void setMessage(String message) { - this.message = message; - } - - /** - * @return the guildName - */ - public String getGuildName() { - return guildName; - } - - /** - * @param guildName - * the guildName to set - */ - public void setGuildName(String guildName) { - this.guildName = guildName; - } - - - public int getUnknown02() { - return unknown02; - } - - public void setUnknown02(int unknown02) { - this.unknown02 = unknown02; - } - - public int getUnknown03() { - return unknown03; - } - - public void setUnknown03(int unknown03) { - this.unknown03 = unknown03; - } - - public int getGuildUUID() { - return guildUUID; - } - - public void setGuildUUID(int guildUUID) { - this.guildUUID = guildUUID; - } + //12d67402 0000f062 56253600 0010b062 d7821800 00000000 + //10000000 4e006f0020006500720072006f00720020006d00650073007300610067006500 + //0a000000 03000000 07000000 a0000000 04000000 + //17000000 4800650072006f006500730020006f0066002000530065006100200044006f006700730020005200650073007400 + //0000200a 33000000 00000000 01000000 + + //12d67402 0000d062 11fe1700 00009063 3ee91300 00000000 + //10000000 4e006f0020006500720072006f00720020006d00650073007300610067006500 + //08000000 08000000 07000000 96000000 0d000000 + //11000000 42006c006f006f00640020004d006f006f006e00200052006900730069006e006700 + //0000c006 64540000 01000000 00000000 + + //12d67402 0000e062 db2d0000 00005063 116e1100 00000000 + //10000000 4e006f0020006500720072006f00720020006d00650073007300610067006500 + //05000000 11000000 0e000000 95000000 05000000 + //09000000 530074006f0072006d0068006f006c006400 + //0000c006 56300000 01000000 00000000 + + private int sourceUUID; + private int targetUUID; + private int unknown01; + private String message; + private GuildTag gt; + private String guildName; + private int guildUUID; + private int unknown02; + private int unknown03; + + /** + * This is the general purpose constructor. + */ + public InviteToSubMsg() { + super(Protocol.INVITEGUILDFEALTY); + this.message = "No error message"; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public InviteToSubMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.INVITEGUILDFEALTY, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(GameObjectType.PlayerCharacter.ordinal()); + writer.putInt(this.sourceUUID); + writer.putInt(GameObjectType.PlayerCharacter.ordinal()); + writer.putInt(this.targetUUID); + writer.putInt(this.unknown01); + writer.putString(this.message); + writer.putInt(this.gt.backgroundColor01); + writer.putInt(this.gt.backgroundColor02); + writer.putInt(this.gt.symbolColor); + writer.putInt(this.gt.symbol); + writer.putInt(this.gt.backgroundDesign); + writer.putString(this.guildName); + writer.putInt(GameObjectType.Guild.ordinal()); + writer.putInt(this.guildUUID); + writer.putInt(this.unknown02); + writer.putInt(this.unknown03); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.getInt(); + this.sourceUUID = reader.getInt(); + reader.getInt(); + this.targetUUID = reader.getInt(); + this.unknown01 = reader.getInt(); + this.message = reader.getString(); + this.gt = new GuildTag(reader); + this.guildName = reader.getString(); + reader.getInt(); // Padding for Object Type + this.guildUUID = reader.getInt(); + this.unknown02 = reader.getInt(); + this.unknown03 = reader.getInt(); + } + + public GuildTag getGuildTag() { + return this.gt; + } + + public void setGuildTag(GuildTag gt) { + this.gt = gt; + } + + /** + * @return the sourceUUID + */ + public int getSourceUUID() { + return sourceUUID; + } + + /** + * @return the targetUUID + */ + public int getTargetUUID() { + return targetUUID; + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the message + */ + public String getMessage() { + return message; + } + + /** + * @param message the message to set + */ + public void setMessage(String message) { + this.message = message; + } + + /** + * @return the guildName + */ + public String getGuildName() { + return guildName; + } + + /** + * @param guildName the guildName to set + */ + public void setGuildName(String guildName) { + this.guildName = guildName; + } + + + public int getUnknown02() { + return unknown02; + } + + public void setUnknown02(int unknown02) { + this.unknown02 = unknown02; + } + + public int getUnknown03() { + return unknown03; + } + + public void setUnknown03(int unknown03) { + this.unknown03 = unknown03; + } + + public int getGuildUUID() { + return guildUUID; + } + + public void setGuildUUID(int guildUUID) { + this.guildUUID = guildUUID; + } } diff --git a/src/engine/net/client/msg/guild/LeaveGuildMsg.java b/src/engine/net/client/msg/guild/LeaveGuildMsg.java index 8ee24ce3..f8a56216 100644 --- a/src/engine/net/client/msg/guild/LeaveGuildMsg.java +++ b/src/engine/net/client/msg/guild/LeaveGuildMsg.java @@ -18,88 +18,84 @@ import engine.net.client.msg.ClientNetMsg; public class LeaveGuildMsg extends ClientNetMsg { - private int response; - private String message; - private long sourceID; - - /** - * This is the general purpose constructor. - */ - public LeaveGuildMsg() { - super(Protocol.LEAVEGUILD); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public LeaveGuildMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.LEAVEGUILD, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.response); - writer.putString(this.message); - writer.putLong(this.sourceID); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.response = reader.getInt(); - this.message = reader.getString(); - this.sourceID = reader.getLong(); - } - - /** - * @return the response - */ - public int getResponse() { - return response; - } - - /** - * @param response - * the response to set - */ - public void setResponse(int response) { - this.response = response; - } - - /** - * @return the message - */ - public String getMessage() { - return message; - } - - /** - * @param message - * the message to set - */ - public void setMessage(String message) { - this.message = message; - } - - /** - * @return the sourceID - */ - public long getSourceID() { - return sourceID; - } - - /** - * @param sourceID - * the sourceID to set - */ - public void setSourceID(long sourceID) { - this.sourceID = sourceID; - } + private int response; + private String message; + private long sourceID; + + /** + * This is the general purpose constructor. + */ + public LeaveGuildMsg() { + super(Protocol.LEAVEGUILD); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public LeaveGuildMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.LEAVEGUILD, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.response); + writer.putString(this.message); + writer.putLong(this.sourceID); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.response = reader.getInt(); + this.message = reader.getString(); + this.sourceID = reader.getLong(); + } + + /** + * @return the response + */ + public int getResponse() { + return response; + } + + /** + * @param response the response to set + */ + public void setResponse(int response) { + this.response = response; + } + + /** + * @return the message + */ + public String getMessage() { + return message; + } + + /** + * @param message the message to set + */ + public void setMessage(String message) { + this.message = message; + } + + /** + * @return the sourceID + */ + public long getSourceID() { + return sourceID; + } + + /** + * @param sourceID the sourceID to set + */ + public void setSourceID(long sourceID) { + this.sourceID = sourceID; + } } diff --git a/src/engine/net/client/msg/guild/MOTDCommitMsg.java b/src/engine/net/client/msg/guild/MOTDCommitMsg.java index 58b70016..6f821824 100644 --- a/src/engine/net/client/msg/guild/MOTDCommitMsg.java +++ b/src/engine/net/client/msg/guild/MOTDCommitMsg.java @@ -18,93 +18,90 @@ import engine.net.client.msg.ClientNetMsg; public class MOTDCommitMsg extends ClientNetMsg { - private String message; - private int unknown01; - private int type; - - /** - * This is the general purpose constructor. - */ - public MOTDCommitMsg() { - super(Protocol.SETMOTD); - this.message = ""; - this.unknown01 = 0; - this.type = 0; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public MOTDCommitMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.SETMOTD, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putString(this.message); - writer.putInt(this.unknown01); - writer.putInt(this.type); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.message = reader.getString(); - this.unknown01 = reader.getInt(); - this.type = reader.getInt(); - } - - /** - * @return the message - */ - public String getMessage() { - return message; - } - - /** - * @param message - * the message to set - */ - public void setMessage(String message) { - this.message = message; - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the type - */ - public int getType() { - return type; - } - - /** - * @param type - * the type to set - */ - public void setType(int type) { - this.type = type; - } + private String message; + private int unknown01; + private int type; + + /** + * This is the general purpose constructor. + */ + public MOTDCommitMsg() { + super(Protocol.SETMOTD); + this.message = ""; + this.unknown01 = 0; + this.type = 0; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public MOTDCommitMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SETMOTD, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putString(this.message); + writer.putInt(this.unknown01); + writer.putInt(this.type); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.message = reader.getString(); + this.unknown01 = reader.getInt(); + this.type = reader.getInt(); + } + + /** + * @return the message + */ + public String getMessage() { + return message; + } + + /** + * @param message the message to set + */ + public void setMessage(String message) { + this.message = message; + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the type + */ + public int getType() { + return type; + } + + /** + * @param type the type to set + */ + public void setType(int type) { + this.type = type; + } } diff --git a/src/engine/net/client/msg/guild/MOTDMsg.java b/src/engine/net/client/msg/guild/MOTDMsg.java index ec33b534..16060ae5 100644 --- a/src/engine/net/client/msg/guild/MOTDMsg.java +++ b/src/engine/net/client/msg/guild/MOTDMsg.java @@ -18,116 +18,112 @@ import engine.net.client.msg.ClientNetMsg; public class MOTDMsg extends ClientNetMsg { - private int type; - private byte response; - private int unknown01; - private String message; - - /** - * This is the general purpose constructor. - */ - public MOTDMsg() { - super(Protocol.MOTD); - this.type = 0; - this.response = (byte) 0; - this.unknown01 = 0; - this.message = ""; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public MOTDMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.MOTD, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.type); - writer.put(this.response); - if (this.response == (byte) 1) { - writer.putInt(this.unknown01); - writer.putString(this.message); - } - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.type = reader.getInt(); - this.response = reader.get(); - if (this.response == (byte) 1) { - this.unknown01 = reader.getInt(); - this.message = reader.getString(); - } - } - - /** - * @return the type - */ - public int getType() { - return type; - } - - /** - * @param type - * the type to set - */ - public void setType(int type) { - this.type = type; - } - - /** - * @return the response - */ - public byte getResponse() { - return response; - } - - /** - * @param response - * the response to set - */ - public void setResponse(byte response) { - this.response = response; - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the message - */ - public String getMessage() { - return message; - } - - /** - * @param message - * the message to set - */ - public void setMessage(String message) { - this.message = message; - } + private int type; + private byte response; + private int unknown01; + private String message; + + /** + * This is the general purpose constructor. + */ + public MOTDMsg() { + super(Protocol.MOTD); + this.type = 0; + this.response = (byte) 0; + this.unknown01 = 0; + this.message = ""; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public MOTDMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.MOTD, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.type); + writer.put(this.response); + if (this.response == (byte) 1) { + writer.putInt(this.unknown01); + writer.putString(this.message); + } + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.type = reader.getInt(); + this.response = reader.get(); + if (this.response == (byte) 1) { + this.unknown01 = reader.getInt(); + this.message = reader.getString(); + } + } + + /** + * @return the type + */ + public int getType() { + return type; + } + + /** + * @param type the type to set + */ + public void setType(int type) { + this.type = type; + } + + /** + * @return the response + */ + public byte getResponse() { + return response; + } + + /** + * @param response the response to set + */ + public void setResponse(byte response) { + this.response = response; + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the message + */ + public String getMessage() { + return message; + } + + /** + * @param message the message to set + */ + public void setMessage(String message) { + this.message = message; + } } diff --git a/src/engine/net/client/msg/guild/ReqGuildListMsg.java b/src/engine/net/client/msg/guild/ReqGuildListMsg.java index 69d8491f..8dbe382a 100644 --- a/src/engine/net/client/msg/guild/ReqGuildListMsg.java +++ b/src/engine/net/client/msg/guild/ReqGuildListMsg.java @@ -18,39 +18,38 @@ import engine.net.client.msg.ClientNetMsg; public class ReqGuildListMsg extends ClientNetMsg { - private long nationCompID; - private long guildToSubCompID; - - /** - * This is the general purpose constructor. - */ - public ReqGuildListMsg() { - super(Protocol.REQUESTGUILDLIST); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public ReqGuildListMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.REQUESTGUILDLIST, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - reader.getInt(); - reader.getString(); - } + private long nationCompID; + private long guildToSubCompID; + + /** + * This is the general purpose constructor. + */ + public ReqGuildListMsg() { + super(Protocol.REQUESTGUILDLIST); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public ReqGuildListMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.REQUESTGUILDLIST, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.getInt(); + reader.getString(); + } } diff --git a/src/engine/net/client/msg/guild/SendGuildEntryMsg.java b/src/engine/net/client/msg/guild/SendGuildEntryMsg.java index 73105b86..6398c14c 100644 --- a/src/engine/net/client/msg/guild/SendGuildEntryMsg.java +++ b/src/engine/net/client/msg/guild/SendGuildEntryMsg.java @@ -23,84 +23,83 @@ import java.util.ArrayList; public class SendGuildEntryMsg extends ClientNetMsg { - private PlayerCharacter pc; - - /** - * This is the general purpose constructor. - */ - public SendGuildEntryMsg(PlayerCharacter pc) { - super(Protocol.SENDGUILDENTRY); - this.pc = pc; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public SendGuildEntryMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.SENDGUILDENTRY, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - - ArrayListsubsAndSovs = new ArrayList<>(); - - Guild nation = pc.getGuild().getNation(); - if (pc.getGuild() != nation) - subsAndSovs.add(nation); - subsAndSovs.addAll(pc.getGuild().getSubGuildList()); - - - writer.putInt(1); - //GuildState - //Petitioner = 2, Sworn = 4 , Nation = 5, protectorate = 6, city-State = 7(nation), province = 8, - - writer.putInt(subsAndSovs.size()); - writer.putInt(1); - if (subsAndSovs.size() > 0){ - - for (Guild guild : subsAndSovs){ - int state = guild.getGuildState().getStateID(); - - writer.putInt(guild.getObjectType().ordinal()); - writer.putInt(guild.getObjectUUID()); - - writer.putString(guild.getName()); - - //TODO set Alliance date - writer.putShort((short)1); - writer.putInt(0); - writer.putShort((short)0); - writer.put((byte)0); - - writer.putInt(state); - GuildTag._serializeForDisplay(guild.getGuildTag(),writer); - if (guild == nation) - writer.putInt(2); // Break Fealty - else - writer.putInt(1); // Dismiss, Swear In. - } - } - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - - } - - public PlayerCharacter getPc() { - return pc; - } - - public void setPc(PlayerCharacter pc) { - this.pc = pc; - } + private PlayerCharacter pc; + + /** + * This is the general purpose constructor. + */ + public SendGuildEntryMsg(PlayerCharacter pc) { + super(Protocol.SENDGUILDENTRY); + this.pc = pc; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public SendGuildEntryMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SENDGUILDENTRY, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + + ArrayList subsAndSovs = new ArrayList<>(); + + Guild nation = pc.getGuild().getNation(); + if (pc.getGuild() != nation) + subsAndSovs.add(nation); + subsAndSovs.addAll(pc.getGuild().getSubGuildList()); + + + writer.putInt(1); + //GuildState + //Petitioner = 2, Sworn = 4 , Nation = 5, protectorate = 6, city-State = 7(nation), province = 8, + + writer.putInt(subsAndSovs.size()); + writer.putInt(1); + if (subsAndSovs.size() > 0) { + + for (Guild guild : subsAndSovs) { + int state = guild.getGuildState().getStateID(); + + writer.putInt(guild.getObjectType().ordinal()); + writer.putInt(guild.getObjectUUID()); + + writer.putString(guild.getName()); + + //TODO set Alliance date + writer.putShort((short) 1); + writer.putInt(0); + writer.putShort((short) 0); + writer.put((byte) 0); + + writer.putInt(state); + GuildTag._serializeForDisplay(guild.getGuildTag(), writer); + if (guild == nation) + writer.putInt(2); // Break Fealty + else + writer.putInt(1); // Dismiss, Swear In. + } + } + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + + } + + public PlayerCharacter getPc() { + return pc; + } + + public void setPc(PlayerCharacter pc) { + this.pc = pc; + } } diff --git a/src/engine/net/client/msg/guild/SwearInGuildMsg.java b/src/engine/net/client/msg/guild/SwearInGuildMsg.java index 480f97b6..a9051f59 100644 --- a/src/engine/net/client/msg/guild/SwearInGuildMsg.java +++ b/src/engine/net/client/msg/guild/SwearInGuildMsg.java @@ -18,61 +18,60 @@ import engine.net.client.msg.ClientNetMsg; public class SwearInGuildMsg extends ClientNetMsg { - private int guildType; - private int guildUUID; - - private String message; - - /** - * This is the general purpose constructor. - */ - public SwearInGuildMsg() { - super(Protocol.SWEARINGUILD); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public SwearInGuildMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.SWEARINGUILD, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - - this.guildType = reader.getInt(); - this.guildUUID = reader.getInt(); - reader.getInt(); - this.message = reader.getString(); - } - - /** - * @return the targetType - */ - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - - public int getGuildUUID() { - return guildUUID; - } + private int guildType; + private int guildUUID; + + private String message; + + /** + * This is the general purpose constructor. + */ + public SwearInGuildMsg() { + super(Protocol.SWEARINGUILD); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public SwearInGuildMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SWEARINGUILD, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + + this.guildType = reader.getInt(); + this.guildUUID = reader.getInt(); + reader.getInt(); + this.message = reader.getString(); + } + + /** + * @return the targetType + */ + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + + public int getGuildUUID() { + return guildUUID; + } } diff --git a/src/engine/net/client/msg/guild/SwearInMsg.java b/src/engine/net/client/msg/guild/SwearInMsg.java index 8a7f5b75..aa9c239e 100644 --- a/src/engine/net/client/msg/guild/SwearInMsg.java +++ b/src/engine/net/client/msg/guild/SwearInMsg.java @@ -18,106 +18,101 @@ import engine.net.client.msg.ClientNetMsg; public class SwearInMsg extends ClientNetMsg { - private int targetType; - private int targetID; - private int unknown01; - private String message; - - /** - * This is the general purpose constructor. - */ - public SwearInMsg() { - super(Protocol.ACTIVATEPLEDGE); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public SwearInMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.ACTIVATEPLEDGE, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.targetType); - writer.putInt(this.targetID); - writer.putInt(this.unknown01); - writer.putString(this.message); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.targetType = reader.getInt(); - this.targetID = reader.getInt(); - this.unknown01 = reader.getInt(); - this.message = reader.getString(); - } - - /** - * @return the targetType - */ - public int getTargetType() { - return targetType; - } - - /** - * @param targetType - * the targetType to set - */ - public void setTargetType(int targetType) { - this.targetType = targetType; - } - - /** - * @return the targetID - */ - public int getTargetID() { - return targetID; - } - - /** - * @param targetID - * the targetID to set - */ - public void setTargetID(int targetID) { - this.targetID = targetID; - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the message - */ - public String getMessage() { - return message; - } - - /** - * @param message - * the message to set - */ - public void setMessage(String message) { - this.message = message; - } + private int targetType; + private int targetID; + private int unknown01; + private String message; + + /** + * This is the general purpose constructor. + */ + public SwearInMsg() { + super(Protocol.ACTIVATEPLEDGE); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public SwearInMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ACTIVATEPLEDGE, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.targetType); + writer.putInt(this.targetID); + writer.putInt(this.unknown01); + writer.putString(this.message); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.targetType = reader.getInt(); + this.targetID = reader.getInt(); + this.unknown01 = reader.getInt(); + this.message = reader.getString(); + } + + /** + * @return the targetType + */ + public int getTargetType() { + return targetType; + } + + /** + * @param targetType the targetType to set + */ + public void setTargetType(int targetType) { + this.targetType = targetType; + } + + /** + * @return the targetID + */ + public int getTargetID() { + return targetID; + } + + /** + * @param targetID the targetID to set + */ + public void setTargetID(int targetID) { + this.targetID = targetID; + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the message + */ + public String getMessage() { + return message; + } + + /** + * @param message the message to set + */ + public void setMessage(String message) { + this.message = message; + } } diff --git a/src/engine/net/client/msg/login/CharSelectScreenMsg.java b/src/engine/net/client/msg/login/CharSelectScreenMsg.java index 47585c29..34fd3f32 100644 --- a/src/engine/net/client/msg/login/CharSelectScreenMsg.java +++ b/src/engine/net/client/msg/login/CharSelectScreenMsg.java @@ -27,268 +27,261 @@ import java.util.ArrayList; public class CharSelectScreenMsg extends ClientNetMsg { - private int numChars; - private int selectedIndex; - private int static01; - private byte static02; - private ArrayList chars; - private boolean fromCommit; - private Account account; - - /** - * Special Constructor - * - * @param s - */ - public CharSelectScreenMsg(Session s) { - this(s, false); - } - - /** - * Special Constructor - * - * @param s - * @param fromCommit - */ - public CharSelectScreenMsg(Session s, boolean fromCommit) { - super(Protocol.CHARSELECTSCREEN); - this.fromCommit = fromCommit; - this.chars = new ArrayList<>(); - // get this account - this.account = s.getAccount(); - - // Get all the character records for this account - chars = new ArrayList<>(this.account.characterMap.values()); - - if (chars == null) { - this.chars = new ArrayList<>(); - } - - // idiot check the quantity of the ArrayList/numChars - this.numChars = chars.size(); - if (this.numChars > 7) { - Logger.error("Account '" + this.account.getUname() + "' has more than 7 characters."); - - this.numChars = 7; - } - - // Get the last character used (As a composite ID). - int lastChar = s.getAccount().getLastCharIDUsed(); - - // Look it up for the index # - this.selectedIndex = 0; - - for (PlayerCharacter pc : chars) - if (pc.getObjectUUID() == lastChar) - break; - else - selectedIndex++; - - // idiot check the index # - if (this.selectedIndex < 0) { - this.selectedIndex = 0; - } - if (this.selectedIndex > 6) { - this.selectedIndex = 6; - } - - this.static01 = 7; - this.static02 = (byte) 1; - } - - /** - * This is the general purpose constructor. - */ - public CharSelectScreenMsg() { - super(Protocol.CHARSELECTSCREEN); - this.chars = new ArrayList<>(); - this.selectedIndex = 0; - this.static01 = 7; - this.static02 = (byte) 1; - this.fromCommit = false; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public CharSelectScreenMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CHARSELECTSCREEN, origin, reader); - - this.chars = new ArrayList<>(); - } - - /** - * @see AbstractNetMsg#getPowerOfTwoBufferSize() - */ - @Override - protected int getPowerOfTwoBufferSize() { - //Larger size for historically larger opcodes - return (17); // 2^17 == 131,072 - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - - if (this.account == null) - Logger.error( "failed to find account for message"); - - // Double check char belongs to this account - for (int i = 0; i < this.numChars; ++i) { - if (this.chars.get(i) == null) - Logger.error("failed to find character"); - if (this.chars.get(i).getAccount() == null) - Logger.error("failed to find account for character " - + this.chars.get(i).getObjectUUID()); - if (this.chars.get(i).getAccount().getObjectUUID() != this.account.getObjectUUID()) { - this.chars.remove(i); - this.numChars--; - - Logger.error( "This character doesn't belong to this account."); - - } - } - - writer.putInt(this.numChars); // 4bytes - writer.putInt(this.selectedIndex); // 4bytes - writer.putInt(this.static01); // 4bytes - writer.put(this.static02); // 1 byte - - for (int i = 0; i < this.numChars; ++i) { - try { - if (!fromCommit) - PlayerCharacter.serializeForClientMsgLogin(this.chars.get(i),writer); - else - PlayerCharacter.serializeForClientMsgCommit(this.chars.get(i),writer); - } catch (SerializationException e) { - Logger.error( "failed to serialize character " + this.chars.get(i).getObjectUUID()); - // Handled already. - } - } - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.numChars = reader.getInt(); - this.selectedIndex = reader.getInt(); - - this.static01 = reader.monitorInt(0, "CharSelectScreenMsg-01"); - this.static02 = reader.monitorByte((byte) 0, "CharSelectScreenMsg-02"); - - // TODO is this correct?!?!? - } - - /** - * @return the numChars - */ - public int getNumChars() { - return numChars; - } - - /** - * @param numChars - * the numChars to set - */ - public void setNumChars(int numChars) { - this.numChars = numChars; - } - - /** - * @return the selectedIndex - */ - public int getSelectedIndex() { - return selectedIndex; - } - - /** - * @param selectedIndex - * the selectedIndex to set - */ - public void setSelectedIndex(int selectedIndex) { - this.selectedIndex = selectedIndex; - } - - /** - * @return the static01 - */ - public int getStatic01() { - return static01; - } - - /** - * @param static01 - * the static01 to set - */ - public void setStatic01(int static01) { - this.static01 = static01; - } - - /** - * @return the static02 - */ - public byte getStatic02() { - return static02; - } - - /** - * @param static02 - * the static02 to set - */ - public void setStatic02(byte static02) { - this.static02 = static02; - } - - /** - * @return the chars - */ - public ArrayList getChars() { - return chars; - } - - /** - * @param chars - * the chars to set - */ - public void setChars(ArrayList chars) { - this.chars = chars; - } - - /** - * @return the fromCommit - */ - public boolean isFromCommit() { - return fromCommit; - } - - /** - * @param fromCommit - * the fromCommit to set - */ - public void setFromCommit(boolean fromCommit) { - this.fromCommit = fromCommit; - } - - /** - * @return the account - */ - public Account getAccount() { - return account; - } - - /** - * @param account - * the account to set - */ - public void setAccount(Account account) { - this.account = account; - } + private int numChars; + private int selectedIndex; + private int static01; + private byte static02; + private ArrayList chars; + private boolean fromCommit; + private Account account; + + /** + * Special Constructor + * + * @param s + */ + public CharSelectScreenMsg(Session s) { + this(s, false); + } + + /** + * Special Constructor + * + * @param s + * @param fromCommit + */ + public CharSelectScreenMsg(Session s, boolean fromCommit) { + super(Protocol.CHARSELECTSCREEN); + this.fromCommit = fromCommit; + this.chars = new ArrayList<>(); + // get this account + this.account = s.getAccount(); + + // Get all the character records for this account + chars = new ArrayList<>(this.account.characterMap.values()); + + if (chars == null) { + this.chars = new ArrayList<>(); + } + + // idiot check the quantity of the ArrayList/numChars + this.numChars = chars.size(); + if (this.numChars > 7) { + Logger.error("Account '" + this.account.getUname() + "' has more than 7 characters."); + + this.numChars = 7; + } + + // Get the last character used (As a composite ID). + int lastChar = s.getAccount().getLastCharIDUsed(); + + // Look it up for the index # + this.selectedIndex = 0; + + for (PlayerCharacter pc : chars) + if (pc.getObjectUUID() == lastChar) + break; + else + selectedIndex++; + + // idiot check the index # + if (this.selectedIndex < 0) { + this.selectedIndex = 0; + } + if (this.selectedIndex > 6) { + this.selectedIndex = 6; + } + + this.static01 = 7; + this.static02 = (byte) 1; + } + + /** + * This is the general purpose constructor. + */ + public CharSelectScreenMsg() { + super(Protocol.CHARSELECTSCREEN); + this.chars = new ArrayList<>(); + this.selectedIndex = 0; + this.static01 = 7; + this.static02 = (byte) 1; + this.fromCommit = false; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public CharSelectScreenMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CHARSELECTSCREEN, origin, reader); + + this.chars = new ArrayList<>(); + } + + /** + * @see AbstractNetMsg#getPowerOfTwoBufferSize() + */ + @Override + protected int getPowerOfTwoBufferSize() { + //Larger size for historically larger opcodes + return (17); // 2^17 == 131,072 + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + + if (this.account == null) + Logger.error("failed to find account for message"); + + // Double check char belongs to this account + for (int i = 0; i < this.numChars; ++i) { + if (this.chars.get(i) == null) + Logger.error("failed to find character"); + if (this.chars.get(i).getAccount() == null) + Logger.error("failed to find account for character " + + this.chars.get(i).getObjectUUID()); + if (this.chars.get(i).getAccount().getObjectUUID() != this.account.getObjectUUID()) { + this.chars.remove(i); + this.numChars--; + + Logger.error("This character doesn't belong to this account."); + + } + } + + writer.putInt(this.numChars); // 4bytes + writer.putInt(this.selectedIndex); // 4bytes + writer.putInt(this.static01); // 4bytes + writer.put(this.static02); // 1 byte + + for (int i = 0; i < this.numChars; ++i) { + try { + if (!fromCommit) + PlayerCharacter.serializeForClientMsgLogin(this.chars.get(i), writer); + else + PlayerCharacter.serializeForClientMsgCommit(this.chars.get(i), writer); + } catch (SerializationException e) { + Logger.error("failed to serialize character " + this.chars.get(i).getObjectUUID()); + // Handled already. + } + } + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.numChars = reader.getInt(); + this.selectedIndex = reader.getInt(); + + this.static01 = reader.monitorInt(0, "CharSelectScreenMsg-01"); + this.static02 = reader.monitorByte((byte) 0, "CharSelectScreenMsg-02"); + + // TODO is this correct?!?!? + } + + /** + * @return the numChars + */ + public int getNumChars() { + return numChars; + } + + /** + * @param numChars the numChars to set + */ + public void setNumChars(int numChars) { + this.numChars = numChars; + } + + /** + * @return the selectedIndex + */ + public int getSelectedIndex() { + return selectedIndex; + } + + /** + * @param selectedIndex the selectedIndex to set + */ + public void setSelectedIndex(int selectedIndex) { + this.selectedIndex = selectedIndex; + } + + /** + * @return the static01 + */ + public int getStatic01() { + return static01; + } + + /** + * @param static01 the static01 to set + */ + public void setStatic01(int static01) { + this.static01 = static01; + } + + /** + * @return the static02 + */ + public byte getStatic02() { + return static02; + } + + /** + * @param static02 the static02 to set + */ + public void setStatic02(byte static02) { + this.static02 = static02; + } + + /** + * @return the chars + */ + public ArrayList getChars() { + return chars; + } + + /** + * @param chars the chars to set + */ + public void setChars(ArrayList chars) { + this.chars = chars; + } + + /** + * @return the fromCommit + */ + public boolean isFromCommit() { + return fromCommit; + } + + /** + * @param fromCommit the fromCommit to set + */ + public void setFromCommit(boolean fromCommit) { + this.fromCommit = fromCommit; + } + + /** + * @return the account + */ + public Account getAccount() { + return account; + } + + /** + * @param account the account to set + */ + public void setAccount(Account account) { + this.account = account; + } } diff --git a/src/engine/net/client/msg/login/ClientLoginInfoMsg.java b/src/engine/net/client/msg/login/ClientLoginInfoMsg.java index 5d38b673..419360f5 100644 --- a/src/engine/net/client/msg/login/ClientLoginInfoMsg.java +++ b/src/engine/net/client/msg/login/ClientLoginInfoMsg.java @@ -18,250 +18,240 @@ import engine.net.client.msg.ClientNetMsg; public class ClientLoginInfoMsg extends ClientNetMsg { - private String uname; - private String pword; - - private int unknown01; - private int unknown02; - - private String os; - - private int unknown03; - private int unknown04; - private int unknown05; - private int unknown06; - private int unknown07; - private int unknown08; - private short unknown09; - - /** - * This is the general purpose constructor. - */ - public ClientLoginInfoMsg(String uName, String pWord, String os) { - super(Protocol.LOGIN); - this.uname = uName; - this.pword = pWord; - this.os = os; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ClientLoginInfoMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.LOGIN, origin, reader); - } - - /** - * This is the Copy constructor. - */ - public ClientLoginInfoMsg(ClientLoginInfoMsg msg) { - super(Protocol.LOGIN, msg); + private String uname; + private String pword; + + private int unknown01; + private int unknown02; + + private String os; + + private int unknown03; + private int unknown04; + private int unknown05; + private int unknown06; + private int unknown07; + private int unknown08; + private short unknown09; + + /** + * This is the general purpose constructor. + */ + public ClientLoginInfoMsg(String uName, String pWord, String os) { + super(Protocol.LOGIN); + this.uname = uName; + this.pword = pWord; + this.os = os; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ClientLoginInfoMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.LOGIN, origin, reader); + } + + /** + * This is the Copy constructor. + */ + public ClientLoginInfoMsg(ClientLoginInfoMsg msg) { + super(Protocol.LOGIN, msg); this.uname = msg.uname; this.pword = msg.pword; this.os = msg.os; - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putString(this.uname); - writer.putString(this.pword); - writer.putInt(this.unknown01); - writer.putInt(this.unknown02); - writer.putString(this.os); - writer.putInt(this.unknown03); - writer.putInt(this.unknown04); - writer.putInt(this.unknown05); - writer.putInt(this.unknown06); - writer.putInt(this.unknown07); - writer.putInt(this.unknown08); - writer.putShort(this.unknown09); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.uname = reader.getString(); - this.pword = reader.getString(); - - this.unknown01 = reader.monitorInt(0, "ClientLoginInfoMsg 01"); - this.unknown02 = reader.monitorInt(0, "ClientLoginInfoMsg 02"); - - this.os = reader.getString(); - - this.unknown03 = reader.monitorInt(0, "ClientLoginInfoMsg 03"); - this.unknown04 = reader.monitorInt(0, "ClientLoginInfoMsg 04"); - this.unknown05 = reader.monitorInt(0, "ClientLoginInfoMsg 05"); - this.unknown06 = reader.monitorInt(0, "ClientLoginInfoMsg 06"); - this.unknown07 = reader.monitorInt(0, "ClientLoginInfoMsg 07"); - this.unknown08 = reader.monitorInt(0, "ClientLoginInfoMsg 08"); - this.unknown09 = reader - .monitorShort((short) 0, "ClientLoginInfoMsg 09"); - - } - - /** - * @return the uname - */ - public String getUname() { - return uname; - } - - /** - * @return the pword - */ - public String getPword() { - return pword; - } - - /** - * @return the os - */ - public String getOs() { - return os; - } - - /** - * @return the unknown01 - */ - public int getUnknown01() { - return unknown01; - } - - /** - * @param unknown01 - * the unknown01 to set - */ - public void setUnknown01(int unknown01) { - this.unknown01 = unknown01; - } - - /** - * @return the unknown02 - */ - public int getUnknown02() { - return unknown02; - } - - /** - * @param unknown02 - * the unknown02 to set - */ - public void setUnknown02(int unknown02) { - this.unknown02 = unknown02; - } - - /** - * @return the unknown03 - */ - public int getUnknown03() { - return unknown03; - } - - /** - * @param unknown03 - * the unknown03 to set - */ - public void setUnknown03(int unknown03) { - this.unknown03 = unknown03; - } - - /** - * @return the unknown04 - */ - public int getUnknown04() { - return unknown04; - } - - /** - * @param unknown04 - * the unknown04 to set - */ - public void setUnknown04(int unknown04) { - this.unknown04 = unknown04; - } - - /** - * @return the unknown05 - */ - public int getUnknown05() { - return unknown05; - } - - /** - * @param unknown05 - * the unknown05 to set - */ - public void setUnknown05(int unknown05) { - this.unknown05 = unknown05; - } - - /** - * @return the unknown06 - */ - public int getUnknown06() { - return unknown06; - } - - /** - * @param unknown06 - * the unknown06 to set - */ - public void setUnknown06(int unknown06) { - this.unknown06 = unknown06; - } - - /** - * @return the unknown07 - */ - public int getUnknown07() { - return unknown07; - } - - /** - * @param unknown07 - * the unknown07 to set - */ - public void setUnknown07(int unknown07) { - this.unknown07 = unknown07; - } - - /** - * @return the unknown08 - */ - public int getUnknown08() { - return unknown08; - } - - /** - * @param unknown08 - * the unknown08 to set - */ - public void setUnknown08(int unknown08) { - this.unknown08 = unknown08; - } - - /** - * @return the unknown09 - */ - public short getUnknown09() { - return unknown09; - } - - /** - * @param unknown09 - * the unknown09 to set - */ - public void setUnknown09(short unknown09) { - this.unknown09 = unknown09; - } + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putString(this.uname); + writer.putString(this.pword); + writer.putInt(this.unknown01); + writer.putInt(this.unknown02); + writer.putString(this.os); + writer.putInt(this.unknown03); + writer.putInt(this.unknown04); + writer.putInt(this.unknown05); + writer.putInt(this.unknown06); + writer.putInt(this.unknown07); + writer.putInt(this.unknown08); + writer.putShort(this.unknown09); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.uname = reader.getString(); + this.pword = reader.getString(); + + this.unknown01 = reader.monitorInt(0, "ClientLoginInfoMsg 01"); + this.unknown02 = reader.monitorInt(0, "ClientLoginInfoMsg 02"); + + this.os = reader.getString(); + + this.unknown03 = reader.monitorInt(0, "ClientLoginInfoMsg 03"); + this.unknown04 = reader.monitorInt(0, "ClientLoginInfoMsg 04"); + this.unknown05 = reader.monitorInt(0, "ClientLoginInfoMsg 05"); + this.unknown06 = reader.monitorInt(0, "ClientLoginInfoMsg 06"); + this.unknown07 = reader.monitorInt(0, "ClientLoginInfoMsg 07"); + this.unknown08 = reader.monitorInt(0, "ClientLoginInfoMsg 08"); + this.unknown09 = reader + .monitorShort((short) 0, "ClientLoginInfoMsg 09"); + + } + + /** + * @return the uname + */ + public String getUname() { + return uname; + } + + /** + * @return the pword + */ + public String getPword() { + return pword; + } + + /** + * @return the os + */ + public String getOs() { + return os; + } + + /** + * @return the unknown01 + */ + public int getUnknown01() { + return unknown01; + } + + /** + * @param unknown01 the unknown01 to set + */ + public void setUnknown01(int unknown01) { + this.unknown01 = unknown01; + } + + /** + * @return the unknown02 + */ + public int getUnknown02() { + return unknown02; + } + + /** + * @param unknown02 the unknown02 to set + */ + public void setUnknown02(int unknown02) { + this.unknown02 = unknown02; + } + + /** + * @return the unknown03 + */ + public int getUnknown03() { + return unknown03; + } + + /** + * @param unknown03 the unknown03 to set + */ + public void setUnknown03(int unknown03) { + this.unknown03 = unknown03; + } + + /** + * @return the unknown04 + */ + public int getUnknown04() { + return unknown04; + } + + /** + * @param unknown04 the unknown04 to set + */ + public void setUnknown04(int unknown04) { + this.unknown04 = unknown04; + } + + /** + * @return the unknown05 + */ + public int getUnknown05() { + return unknown05; + } + + /** + * @param unknown05 the unknown05 to set + */ + public void setUnknown05(int unknown05) { + this.unknown05 = unknown05; + } + + /** + * @return the unknown06 + */ + public int getUnknown06() { + return unknown06; + } + + /** + * @param unknown06 the unknown06 to set + */ + public void setUnknown06(int unknown06) { + this.unknown06 = unknown06; + } + + /** + * @return the unknown07 + */ + public int getUnknown07() { + return unknown07; + } + + /** + * @param unknown07 the unknown07 to set + */ + public void setUnknown07(int unknown07) { + this.unknown07 = unknown07; + } + + /** + * @return the unknown08 + */ + public int getUnknown08() { + return unknown08; + } + + /** + * @param unknown08 the unknown08 to set + */ + public void setUnknown08(int unknown08) { + this.unknown08 = unknown08; + } + + /** + * @return the unknown09 + */ + public short getUnknown09() { + return unknown09; + } + + /** + * @param unknown09 the unknown09 to set + */ + public void setUnknown09(short unknown09) { + this.unknown09 = unknown09; + } } diff --git a/src/engine/net/client/msg/login/CommitNewCharacterMsg.java b/src/engine/net/client/msg/login/CommitNewCharacterMsg.java index 5078e7df..968829d7 100644 --- a/src/engine/net/client/msg/login/CommitNewCharacterMsg.java +++ b/src/engine/net/client/msg/login/CommitNewCharacterMsg.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -30,428 +27,411 @@ import engine.net.client.msg.ClientNetMsg; public class CommitNewCharacterMsg extends ClientNetMsg { - private String firstName; - private String lastName; - private int serverID; - private int hairStyle; - private int beardStyle; - private int skinColor; - private int hairColor; - private int beardColor; - private int kit; - private int numRunes; - private int[] runes; - private int numStats; - private int strengthMod; - private int dexterityMod; - private int constitutionMod; - private int intelligenceMod; - private int spiritMod; - - /** - * This is the general purpose constructor. - */ - public CommitNewCharacterMsg() { - super(Protocol.CREATECHAR); - runes = new int[23]; - strengthMod = 0; - dexterityMod = 0; - constitutionMod = 0; - intelligenceMod = 0; - spiritMod = 0; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public CommitNewCharacterMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.CREATECHAR, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - - writer.putString(this.firstName); - writer.putString(this.lastName); - - writer.putInt(this.serverID); - writer.putInt(0); - writer.putInt(this.hairStyle); - writer.putInt(0); - writer.putInt(this.beardStyle); - writer.putInt(this.skinColor); - writer.putInt(this.hairColor); - writer.putInt(this.beardColor); - writer.putInt(this.kit); - for (int i = 0; i < 23; i++) { - writer.putInt(0); - writer.putInt(this.runes[i]); - writer.putInt(0); - writer.putInt(0); - } - writer.putInt(this.numStats); - if (this.strengthMod != 0) { - writer.putInt(0x8AC3C0E6); - writer.putInt(this.strengthMod); - } - if (this.dexterityMod != 0) { - writer.putInt(0xE07B3336); - writer.putInt(this.dexterityMod); - } - if (this.constitutionMod != 0) { - writer.putInt(0xB15DC77E); - writer.putInt(this.constitutionMod); - } - if (this.intelligenceMod != 0) { - writer.putInt(0xFF665EC3); - writer.putInt(this.intelligenceMod); - } - if (this.spiritMod != 0) { - writer.putInt(0xACB82E33); - writer.putInt(this.spiritMod); - } - - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - runes = new int[23]; - runes = new int[23]; - strengthMod = 0; - dexterityMod = 0; - constitutionMod = 0; - intelligenceMod = 0; - spiritMod = 0; - - this.firstName = reader.getString(); - this.lastName = reader.getString(); - this.serverID = reader.getInt(); - - reader.monitorInt(0, "CommitNewCharacter 01"); - - this.hairStyle = reader.getInt(); - - reader.monitorInt(0, "CommitNewCharacter 02"); - - this.beardStyle = reader.getInt(); - this.skinColor = reader.getInt(); - this.hairColor = reader.getInt(); - this.beardColor = reader.getInt(); - this.kit = reader.getInt(); - this.clearRunes(); - int runeCount = 0; - for (int i = 0; i < 23; i++) { - - reader.monitorInt(0, "CommitNewCharacter 03-" + i); - - this.runes[i] = reader.getInt(); - - reader.monitorInt(0, "CommitNewCharacter 04-" + i); - reader.monitorInt(0, "CommitNewCharacter 05-" + i); - - if (this.runes[i] != 0) - runeCount++; - } - this.numRunes = runeCount; - this.numStats = reader.getInt(); - int stattype; - for (int i = 0; i < this.numStats; i++) { - stattype = reader.getInt(); - if (stattype == 0x8AC3C0E6) - this.strengthMod = reader.getInt(); - else if (stattype == 0xE07B3336) - this.dexterityMod = reader.getInt(); - else if (stattype == 0xB15DC77E) - this.constitutionMod = reader.getInt(); - else if (stattype == 0xFF665EC3) - this.intelligenceMod = reader.getInt(); - else if (stattype == 0xACB82E33) - this.spiritMod = reader.getInt(); - } - } - - - public void clearRunes() { - for (int i = 0; i < 23; i++) - this.runes[i] = 0; - } - - public int getRace() { - for (int i = 0; i < 23; i++) - if (this.runes[i] > 1999 && this.runes[i] < 2030) - return this.runes[i]; - return 0; - } - - public int getBaseClass() { - for (int i = 0; i < 23; i++) - if (this.runes[i] > 2499 && this.runes[i] < 2504) - return this.runes[i]; - return 0; - } - - /** - * @return the firstName - */ - public String getFirstName() { - return firstName; - } - - /** - * @param firstName - * the firstName to set - */ - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - /** - * @return the lastName - */ - public String getLastName() { - return lastName; - } - - /** - * @param lastName - * the lastName to set - */ - public void setLastName(String lastName) { - this.lastName = lastName; - } - - /** - * @return the serverID - */ - public int getServerID() { - return serverID; - } - - /** - * @param serverID - * the serverID to set - */ - public void setServerID(int serverID) { - this.serverID = serverID; - } - - /** - * @return the hairStyle - */ - public int getHairStyle() { - return hairStyle; - } - - /** - * @param hairStyle - * the hairStyle to set - */ - public void setHairStyle(int hairStyle) { - this.hairStyle = hairStyle; - } - - /** - * @return the beardStyle - */ - public int getBeardStyle() { - return beardStyle; - } - - /** - * @param beardStyle - * the beardStyle to set - */ - public void setBeardStyle(int beardStyle) { - this.beardStyle = beardStyle; - } - - /** - * @return the skinColor - */ - public int getSkinColor() { - return skinColor; - } - - /** - * @param skinColor - * the skinColor to set - */ - public void setSkinColor(int skinColor) { - this.skinColor = skinColor; - } - - /** - * @return the hairColor - */ - public int getHairColor() { - return hairColor; - } - - /** - * @param hairColor - * the hairColor to set - */ - public void setHairColor(int hairColor) { - this.hairColor = hairColor; - } - - /** - * @return the beardColor - */ - public int getBeardColor() { - return beardColor; - } - - /** - * @param beardColor - * the beardColor to set - */ - public void setBeardColor(int beardColor) { - this.beardColor = beardColor; - } - - /** - * @return the kit - */ - public int getKit() { - return kit; - } - - /** - * @param kit - * the kit to set - */ - public void setKit(int kit) { - this.kit = kit; - } - - /** - * @return the runeCount - */ - public int getNumRunes() { - return numRunes; - } - - /** - * @param numRunes - * the runeCount to set - */ - public void setNumRunes(int numRunes) { - this.numRunes = numRunes; - } - - /** - * @return the runes - */ - public int[] getRunes() { - return runes; - } - - /** - * @param runes - * the runes to set - */ - public void setRunes(int[] runes) { - this.runes = runes; - } - - /** - * @return the numStats - */ - public int getNumStats() { - return numStats; - } - - /** - * @param numStats - * the numStats to set - */ - public void setNumStats(int numStats) { - this.numStats = numStats; - } - - /** - * @return the strengthMod - */ - public int getStrengthMod() { - return strengthMod; - } - - /** - * @param strengthMod - * the strengthMod to set - */ - public void setStrengthMod(int strengthMod) { - this.strengthMod = strengthMod; - } - - /** - * @return the dexterityMod - */ - public int getDexterityMod() { - return dexterityMod; - } - - /** - * @param dexterityMod - * the dexterityMod to set - */ - public void setDexterityMod(int dexterityMod) { - this.dexterityMod = dexterityMod; - } - - /** - * @return the constitutionMod - */ - public int getConstitutionMod() { - return constitutionMod; - } - - /** - * @param constitutionMod - * the constitutionMod to set - */ - public void setConstitutionMod(int constitutionMod) { - this.constitutionMod = constitutionMod; - } - - /** - * @return the intelligenceMod - */ - public int getIntelligenceMod() { - return intelligenceMod; - } - - /** - * @param intelligenceMod - * the intelligenceMod to set - */ - public void setIntelligenceMod(int intelligenceMod) { - this.intelligenceMod = intelligenceMod; - } - - /** - * @return the spiritMod - */ - public int getSpiritMod() { - return spiritMod; - } - - /** - * @param spiritMod - * the spiritMod to set - */ - public void setSpiritMod(int spiritMod) { - this.spiritMod = spiritMod; - } + private String firstName; + private String lastName; + private int serverID; + private int hairStyle; + private int beardStyle; + private int skinColor; + private int hairColor; + private int beardColor; + private int kit; + private int numRunes; + private int[] runes; + private int numStats; + private int strengthMod; + private int dexterityMod; + private int constitutionMod; + private int intelligenceMod; + private int spiritMod; + + /** + * This is the general purpose constructor. + */ + public CommitNewCharacterMsg() { + super(Protocol.CREATECHAR); + runes = new int[23]; + strengthMod = 0; + dexterityMod = 0; + constitutionMod = 0; + intelligenceMod = 0; + spiritMod = 0; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public CommitNewCharacterMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CREATECHAR, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + + writer.putString(this.firstName); + writer.putString(this.lastName); + + writer.putInt(this.serverID); + writer.putInt(0); + writer.putInt(this.hairStyle); + writer.putInt(0); + writer.putInt(this.beardStyle); + writer.putInt(this.skinColor); + writer.putInt(this.hairColor); + writer.putInt(this.beardColor); + writer.putInt(this.kit); + for (int i = 0; i < 23; i++) { + writer.putInt(0); + writer.putInt(this.runes[i]); + writer.putInt(0); + writer.putInt(0); + } + writer.putInt(this.numStats); + if (this.strengthMod != 0) { + writer.putInt(0x8AC3C0E6); + writer.putInt(this.strengthMod); + } + if (this.dexterityMod != 0) { + writer.putInt(0xE07B3336); + writer.putInt(this.dexterityMod); + } + if (this.constitutionMod != 0) { + writer.putInt(0xB15DC77E); + writer.putInt(this.constitutionMod); + } + if (this.intelligenceMod != 0) { + writer.putInt(0xFF665EC3); + writer.putInt(this.intelligenceMod); + } + if (this.spiritMod != 0) { + writer.putInt(0xACB82E33); + writer.putInt(this.spiritMod); + } + + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + runes = new int[23]; + runes = new int[23]; + strengthMod = 0; + dexterityMod = 0; + constitutionMod = 0; + intelligenceMod = 0; + spiritMod = 0; + + this.firstName = reader.getString(); + this.lastName = reader.getString(); + this.serverID = reader.getInt(); + + reader.monitorInt(0, "CommitNewCharacter 01"); + + this.hairStyle = reader.getInt(); + + reader.monitorInt(0, "CommitNewCharacter 02"); + + this.beardStyle = reader.getInt(); + this.skinColor = reader.getInt(); + this.hairColor = reader.getInt(); + this.beardColor = reader.getInt(); + this.kit = reader.getInt(); + this.clearRunes(); + int runeCount = 0; + for (int i = 0; i < 23; i++) { + + reader.monitorInt(0, "CommitNewCharacter 03-" + i); + + this.runes[i] = reader.getInt(); + + reader.monitorInt(0, "CommitNewCharacter 04-" + i); + reader.monitorInt(0, "CommitNewCharacter 05-" + i); + + if (this.runes[i] != 0) + runeCount++; + } + this.numRunes = runeCount; + this.numStats = reader.getInt(); + int stattype; + for (int i = 0; i < this.numStats; i++) { + stattype = reader.getInt(); + if (stattype == 0x8AC3C0E6) + this.strengthMod = reader.getInt(); + else if (stattype == 0xE07B3336) + this.dexterityMod = reader.getInt(); + else if (stattype == 0xB15DC77E) + this.constitutionMod = reader.getInt(); + else if (stattype == 0xFF665EC3) + this.intelligenceMod = reader.getInt(); + else if (stattype == 0xACB82E33) + this.spiritMod = reader.getInt(); + } + } + + + public void clearRunes() { + for (int i = 0; i < 23; i++) + this.runes[i] = 0; + } + + public int getRace() { + for (int i = 0; i < 23; i++) + if (this.runes[i] > 1999 && this.runes[i] < 2030) + return this.runes[i]; + return 0; + } + + public int getBaseClass() { + for (int i = 0; i < 23; i++) + if (this.runes[i] > 2499 && this.runes[i] < 2504) + return this.runes[i]; + return 0; + } + + /** + * @return the firstName + */ + public String getFirstName() { + return firstName; + } + + /** + * @param firstName the firstName to set + */ + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + /** + * @return the lastName + */ + public String getLastName() { + return lastName; + } + + /** + * @param lastName the lastName to set + */ + public void setLastName(String lastName) { + this.lastName = lastName; + } + + /** + * @return the serverID + */ + public int getServerID() { + return serverID; + } + + /** + * @param serverID the serverID to set + */ + public void setServerID(int serverID) { + this.serverID = serverID; + } + + /** + * @return the hairStyle + */ + public int getHairStyle() { + return hairStyle; + } + + /** + * @param hairStyle the hairStyle to set + */ + public void setHairStyle(int hairStyle) { + this.hairStyle = hairStyle; + } + + /** + * @return the beardStyle + */ + public int getBeardStyle() { + return beardStyle; + } + + /** + * @param beardStyle the beardStyle to set + */ + public void setBeardStyle(int beardStyle) { + this.beardStyle = beardStyle; + } + + /** + * @return the skinColor + */ + public int getSkinColor() { + return skinColor; + } + + /** + * @param skinColor the skinColor to set + */ + public void setSkinColor(int skinColor) { + this.skinColor = skinColor; + } + + /** + * @return the hairColor + */ + public int getHairColor() { + return hairColor; + } + + /** + * @param hairColor the hairColor to set + */ + public void setHairColor(int hairColor) { + this.hairColor = hairColor; + } + + /** + * @return the beardColor + */ + public int getBeardColor() { + return beardColor; + } + + /** + * @param beardColor the beardColor to set + */ + public void setBeardColor(int beardColor) { + this.beardColor = beardColor; + } + + /** + * @return the kit + */ + public int getKit() { + return kit; + } + + /** + * @param kit the kit to set + */ + public void setKit(int kit) { + this.kit = kit; + } + + /** + * @return the runeCount + */ + public int getNumRunes() { + return numRunes; + } + + /** + * @param numRunes the runeCount to set + */ + public void setNumRunes(int numRunes) { + this.numRunes = numRunes; + } + + /** + * @return the runes + */ + public int[] getRunes() { + return runes; + } + + /** + * @param runes the runes to set + */ + public void setRunes(int[] runes) { + this.runes = runes; + } + + /** + * @return the numStats + */ + public int getNumStats() { + return numStats; + } + + /** + * @param numStats the numStats to set + */ + public void setNumStats(int numStats) { + this.numStats = numStats; + } + + /** + * @return the strengthMod + */ + public int getStrengthMod() { + return strengthMod; + } + + /** + * @param strengthMod the strengthMod to set + */ + public void setStrengthMod(int strengthMod) { + this.strengthMod = strengthMod; + } + + /** + * @return the dexterityMod + */ + public int getDexterityMod() { + return dexterityMod; + } + + /** + * @param dexterityMod the dexterityMod to set + */ + public void setDexterityMod(int dexterityMod) { + this.dexterityMod = dexterityMod; + } + + /** + * @return the constitutionMod + */ + public int getConstitutionMod() { + return constitutionMod; + } + + /** + * @param constitutionMod the constitutionMod to set + */ + public void setConstitutionMod(int constitutionMod) { + this.constitutionMod = constitutionMod; + } + + /** + * @return the intelligenceMod + */ + public int getIntelligenceMod() { + return intelligenceMod; + } + + /** + * @param intelligenceMod the intelligenceMod to set + */ + public void setIntelligenceMod(int intelligenceMod) { + this.intelligenceMod = intelligenceMod; + } + + /** + * @return the spiritMod + */ + public int getSpiritMod() { + return spiritMod; + } + + /** + * @param spiritMod the spiritMod to set + */ + public void setSpiritMod(int spiritMod) { + this.spiritMod = spiritMod; + } } diff --git a/src/engine/net/client/msg/login/DeleteCharacterMsg.java b/src/engine/net/client/msg/login/DeleteCharacterMsg.java index be4efab2..ddcf300b 100644 --- a/src/engine/net/client/msg/login/DeleteCharacterMsg.java +++ b/src/engine/net/client/msg/login/DeleteCharacterMsg.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.net.client.msg.login; import engine.Enum.GameObjectType; @@ -36,8 +35,7 @@ public class DeleteCharacterMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public DeleteCharacterMsg(AbstractConnection origin, ByteBufferReader reader) - { + public DeleteCharacterMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.REMOVECHAR, origin, reader); } @@ -56,9 +54,9 @@ public class DeleteCharacterMsg extends ClientNetMsg { * Deserializes the subclass specific items from the supplied * ByteBufferReader. */ - + @Override - protected void _deserialize(ByteBufferReader reader) { + protected void _deserialize(ByteBufferReader reader) { reader.getInt(); // Object Type Padding this.characterUUID = reader.getInt(); this.firstName = reader.getString(); diff --git a/src/engine/net/client/msg/login/GameServerIPRequestMsg.java b/src/engine/net/client/msg/login/GameServerIPRequestMsg.java index 5e548e36..cbacdb32 100644 --- a/src/engine/net/client/msg/login/GameServerIPRequestMsg.java +++ b/src/engine/net/client/msg/login/GameServerIPRequestMsg.java @@ -18,46 +18,45 @@ import engine.net.client.msg.ClientNetMsg; public class GameServerIPRequestMsg extends ClientNetMsg { - private int characterUUID; - - /** - * This is the general purpose constructor. - */ - public GameServerIPRequestMsg() { - super(Protocol.SELECTCHAR); - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public GameServerIPRequestMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.SELECTCHAR, origin, reader); - } - - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(GameObjectType.PlayerCharacter.ordinal()); - writer.putInt(this.characterUUID); - } - - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - reader.getInt(); // Object Type Padding - this.characterUUID = reader.getInt(); - } - - /** - * @return the characterUUID - */ - public int getCharacterUUID() { - return characterUUID; - } + private int characterUUID; + + /** + * This is the general purpose constructor. + */ + public GameServerIPRequestMsg() { + super(Protocol.SELECTCHAR); + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public GameServerIPRequestMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.SELECTCHAR, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(GameObjectType.PlayerCharacter.ordinal()); + writer.putInt(this.characterUUID); + } + + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + reader.getInt(); // Object Type Padding + this.characterUUID = reader.getInt(); + } + + /** + * @return the characterUUID + */ + public int getCharacterUUID() { + return characterUUID; + } } diff --git a/src/engine/net/client/msg/login/GameServerIPResponseMsg.java b/src/engine/net/client/msg/login/GameServerIPResponseMsg.java index c3cfbce4..b14acdf0 100644 --- a/src/engine/net/client/msg/login/GameServerIPResponseMsg.java +++ b/src/engine/net/client/msg/login/GameServerIPResponseMsg.java @@ -19,67 +19,67 @@ import engine.net.client.msg.ClientNetMsg; public class GameServerIPResponseMsg extends ClientNetMsg { - private String ip; - private int port; + private String ip; + private int port; - /** - * This is the general purpose constructor. - */ - public GameServerIPResponseMsg(String ip, int port) { - super(Protocol.GAMESERVERIPRESPONSE); - this.ip = ip; - this.port = port; - } + /** + * This is the general purpose constructor. + */ + public GameServerIPResponseMsg(String ip, int port) { + super(Protocol.GAMESERVERIPRESPONSE); + this.ip = ip; + this.port = port; + } - /** - * This is the general purpose constructor. - */ - public GameServerIPResponseMsg( ) { - super(Protocol.GAMESERVERIPRESPONSE); - this.ip = ConfigManager.MB_BIND_ADDR.getValue(); - this.port = Integer.parseInt(ConfigManager.MB_WORLD_PORT.getValue()); - } + /** + * This is the general purpose constructor. + */ + public GameServerIPResponseMsg() { + super(Protocol.GAMESERVERIPRESPONSE); + this.ip = ConfigManager.MB_BIND_ADDR.getValue(); + this.port = Integer.parseInt(ConfigManager.MB_WORLD_PORT.getValue()); + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public GameServerIPResponseMsg(AbstractConnection origin, - ByteBufferReader reader) { - super(Protocol.GAMESERVERIPRESPONSE, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public GameServerIPResponseMsg(AbstractConnection origin, + ByteBufferReader reader) { + super(Protocol.GAMESERVERIPRESPONSE, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putString(this.ip); - writer.putInt(this.port); - } + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putString(this.ip); + writer.putInt(this.port); + } - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.ip = reader.getString(); - this.port = reader.getInt(); - } + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.ip = reader.getString(); + this.port = reader.getInt(); + } - /** - * @return the ip - */ - public String getIp() { - return ip; - } + /** + * @return the ip + */ + public String getIp() { + return ip; + } - /** - * @return the port - */ - public int getPort() { - return port; - } + /** + * @return the port + */ + public int getPort() { + return port; + } } diff --git a/src/engine/net/client/msg/login/InvalidNameMsg.java b/src/engine/net/client/msg/login/InvalidNameMsg.java index 246176d4..0547abea 100644 --- a/src/engine/net/client/msg/login/InvalidNameMsg.java +++ b/src/engine/net/client/msg/login/InvalidNameMsg.java @@ -19,71 +19,71 @@ import engine.server.world.WorldServer; public class InvalidNameMsg extends ClientNetMsg { - private String FirstName; - private String LastName; - private int errorCode; - private int serverID; - /** - * This is the general purpose constructor. - */ - public InvalidNameMsg(String FirstName, String LastName, - int errorCode) { - super(Protocol.NAMEVERIFY); - this.FirstName = FirstName; - this.LastName = LastName; - this.errorCode = errorCode; - } + private String FirstName; + private String LastName; + private int errorCode; + private int serverID; - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public InvalidNameMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.NAMEVERIFY, origin, reader); - } + /** + * This is the general purpose constructor. + */ + public InvalidNameMsg(String FirstName, String LastName, + int errorCode) { + super(Protocol.NAMEVERIFY); + this.FirstName = FirstName; + this.LastName = LastName; + this.errorCode = errorCode; + } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putString(this.FirstName); + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public InvalidNameMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.NAMEVERIFY, origin, reader); + } + + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putString(this.FirstName); writer.putString(this.LastName); writer.putInt(WorldServer.worldMapID); writer.putInt(errorCode); - } + } - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.FirstName = reader.getString(); - this.LastName = reader.getString(); - this.serverID = reader.getInt(); - reader.monitorInt(0, "InvalidNameMsg 01"); - } + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.FirstName = reader.getString(); + this.LastName = reader.getString(); + this.serverID = reader.getInt(); + reader.monitorInt(0, "InvalidNameMsg 01"); + } - /** - * @return the firstName - */ - public String getFirstName() { - return FirstName; - } + /** + * @return the firstName + */ + public String getFirstName() { + return FirstName; + } - /** - * @return the lastName - */ - public String getLastName() { - return LastName; - } + /** + * @return the lastName + */ + public String getLastName() { + return LastName; + } - /** - * @return the errorCode - */ - public int getErrorCode() { - return errorCode; - } + /** + * @return the errorCode + */ + public int getErrorCode() { + return errorCode; + } } diff --git a/src/engine/net/client/msg/login/LoginErrorMsg.java b/src/engine/net/client/msg/login/LoginErrorMsg.java index 9decaaa5..d5247d96 100644 --- a/src/engine/net/client/msg/login/LoginErrorMsg.java +++ b/src/engine/net/client/msg/login/LoginErrorMsg.java @@ -18,55 +18,54 @@ import engine.net.client.msg.ClientNetMsg; public class LoginErrorMsg extends ClientNetMsg { - private int reason; - private String message; + private int reason; + private String message; - /** - * This is the general purpose constructor. - */ - public LoginErrorMsg(int Reason, String message) { - super(Protocol.LOGINFAILED); - this.reason = Reason; - this.message = message; - } + /** + * This is the general purpose constructor. + */ + public LoginErrorMsg(int Reason, String message) { + super(Protocol.LOGINFAILED); + this.reason = Reason; + this.message = message; + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public LoginErrorMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.LOGINFAILED, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public LoginErrorMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.LOGINFAILED, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.reason); - writer.putString(this.message); - } + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.reason); + writer.putString(this.message); + } - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.reason = reader.getInt(); - this.message = reader.getString(); - } + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.reason = reader.getInt(); + this.message = reader.getString(); + } - /** - * @return the reason - */ - public int getReason() { - return reason; - } + /** + * @return the reason + */ + public int getReason() { + return reason; + } - /** - * @return the message - */ - public String getMessage() { - return message; - } + /** + * @return the message + */ + public String getMessage() { + return message; + } } diff --git a/src/engine/net/client/msg/login/ServerStatusMsg.java b/src/engine/net/client/msg/login/ServerStatusMsg.java index 241bf8b2..32d96198 100644 --- a/src/engine/net/client/msg/login/ServerStatusMsg.java +++ b/src/engine/net/client/msg/login/ServerStatusMsg.java @@ -18,63 +18,63 @@ import engine.net.client.msg.ClientNetMsg; public class ServerStatusMsg extends ClientNetMsg { - private int serverID; - private byte isUp; + private int serverID; + private byte isUp; - /** - * This is the general purpose constructor. - */ - public ServerStatusMsg(int serverID, byte isUp) { - super(Protocol.ARCSERVERSTATUS); - this.serverID = serverID; - this.isUp = isUp; - } + /** + * This is the general purpose constructor. + */ + public ServerStatusMsg(int serverID, byte isUp) { + super(Protocol.ARCSERVERSTATUS); + this.serverID = serverID; + this.isUp = isUp; + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public ServerStatusMsg(AbstractConnection origin, ByteBufferReader reader) { - super(Protocol.ARCSERVERSTATUS, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public ServerStatusMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.ARCSERVERSTATUS, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putInt(this.serverID); - writer.put(this.isUp); - } + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putInt(this.serverID); + writer.put(this.isUp); + } - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.serverID = reader.getInt(); - this.isUp = reader.get(); - } + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.serverID = reader.getInt(); + this.isUp = reader.get(); + } - public int getServerID() { - return this.serverID; - } - - public byte getIsUp() { - return this.isUp; - } + public int getServerID() { + return this.serverID; + } - public boolean isUp() { - return (this.isUp == 0x01); - } + public void setServerID(int value) { + this.serverID = value; + } - public void setServerID(int value) { - this.serverID = value; - } - - public void setIsUp(byte value) { - this.isUp = value; - } + public byte getIsUp() { + return this.isUp; + } + + public void setIsUp(byte value) { + this.isUp = value; + } + + public boolean isUp() { + return (this.isUp == 0x01); + } } diff --git a/src/engine/net/client/msg/login/VersionInfoMsg.java b/src/engine/net/client/msg/login/VersionInfoMsg.java index bd6eb78a..81852009 100644 --- a/src/engine/net/client/msg/login/VersionInfoMsg.java +++ b/src/engine/net/client/msg/login/VersionInfoMsg.java @@ -18,55 +18,54 @@ import engine.net.client.msg.ClientNetMsg; public class VersionInfoMsg extends ClientNetMsg { - private String majorVersion; - private String minorVersion; + private String majorVersion; + private String minorVersion; - /** - * This is the general purpose constructor. - */ - public VersionInfoMsg(String majorVersion, String minorVersion) { - super(Protocol.VERSIONINFO); - this.majorVersion = majorVersion; - this.minorVersion = minorVersion; - } + /** + * This is the general purpose constructor. + */ + public VersionInfoMsg(String majorVersion, String minorVersion) { + super(Protocol.VERSIONINFO); + this.majorVersion = majorVersion; + this.minorVersion = minorVersion; + } - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. - */ - public VersionInfoMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.VERSIONINFO, origin, reader); - } + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. + */ + public VersionInfoMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.VERSIONINFO, origin, reader); + } - /** - * Serializes the subclass specific items to the supplied ByteBufferWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - writer.putString(this.majorVersion); - writer.putString(this.minorVersion); - } + /** + * Serializes the subclass specific items to the supplied ByteBufferWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + writer.putString(this.majorVersion); + writer.putString(this.minorVersion); + } - /** - * Deserializes the subclass specific items from the supplied ByteBufferReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) { - this.majorVersion = reader.getString(); - this.minorVersion = reader.getString(); - } + /** + * Deserializes the subclass specific items from the supplied ByteBufferReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + this.majorVersion = reader.getString(); + this.minorVersion = reader.getString(); + } - /** - * @return the majorVersion - */ - public String getMajorVersion() { - return majorVersion; - } + /** + * @return the majorVersion + */ + public String getMajorVersion() { + return majorVersion; + } - /** - * @return the minorVersion - */ - public String getMinorVersion() { - return minorVersion; - } + /** + * @return the minorVersion + */ + public String getMinorVersion() { + return minorVersion; + } } diff --git a/src/engine/objects/AbstractCharacter.java b/src/engine/objects/AbstractCharacter.java index 0fd5aa8c..161968b2 100644 --- a/src/engine/objects/AbstractCharacter.java +++ b/src/engine/objects/AbstractCharacter.java @@ -43,1915 +43,1884 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; public abstract class AbstractCharacter extends AbstractWorldObject { - protected String firstName; - protected String lastName; - protected short statStrCurrent; - protected short statDexCurrent; - protected short statConCurrent; - protected short statIntCurrent; - protected short statSpiCurrent; - protected short unusedStatPoints; - public short level; - protected int exp; - protected Vector3fImmutable bindLoc; - protected Vector3fImmutable faceDir; - protected Guild guild; - protected byte runningTrains; - protected ConcurrentHashMap powers; - protected ConcurrentHashMap skills; - protected final CharacterItemManager charItemManager; - - // Variables NOT to be stored in db - protected boolean sit = false; - protected boolean walkMode; - protected boolean combat = false; - - protected Vector3fImmutable startLoc = Vector3fImmutable.ZERO; - protected Vector3fImmutable endLoc = Vector3fImmutable.ZERO; + protected final CharacterItemManager charItemManager; + private final ReentrantReadWriteLock healthLock = new ReentrantReadWriteLock(); + private final ReentrantReadWriteLock teleportLock = new ReentrantReadWriteLock(); + public short level; + public AbstractWorldObject combatTarget; + public Contract contract; + protected String firstName; + protected String lastName; + protected short statStrCurrent; + protected short statDexCurrent; + protected short statConCurrent; + protected short statIntCurrent; + protected short statSpiCurrent; + protected short unusedStatPoints; + protected int exp; + protected Vector3fImmutable bindLoc; + protected Vector3fImmutable faceDir; + protected Guild guild; + protected byte runningTrains; + protected ConcurrentHashMap powers; + protected ConcurrentHashMap skills; + // Variables NOT to be stored in db + protected boolean sit = false; + protected boolean walkMode; + protected boolean combat = false; + protected Vector3fImmutable startLoc = Vector3fImmutable.ZERO; + protected Vector3fImmutable endLoc = Vector3fImmutable.ZERO; + protected boolean itemCasting = false; + // nextEndLoc is used to store the next end location when someone is clicking + // around the ground while other timers like changeAltitude are still + // 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(); + protected float staminaMax; + protected AtomicFloat mana = new AtomicFloat(); + protected float manaMax; // Health/Mana/Stamina + protected AtomicBoolean isAlive = new AtomicBoolean(true); + protected Resists resists = new Resists("Genric"); + protected ConcurrentHashMap timers; + protected ConcurrentHashMap timestamps; + protected int atrHandOne; + protected int atrHandTwo; + protected int minDamageHandOne; + protected int maxDamageHandOne; + protected int minDamageHandTwo; + protected int maxDamageHandTwo; + protected float rangeHandOne; + protected float rangeHandTwo; + protected float speedHandOne; + protected float speedHandTwo; + protected int defenseRating; + 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; + protected JobContainer lastChant; + protected boolean isCasting = false; + protected long lastSetLocUpdate = 0L; + protected int inBuilding = -1; // -1 not in building 0 on ground floor, 1 on first floor etc + protected int inBuildingID = 0; + protected int inFloorID = -1; + protected int liveCounter = 0; + protected int debug = 0; + protected Regions lastRegion = null; + protected boolean movingUp = false; private float desiredAltitude = 0; - private long takeOffTime = 0; - protected boolean itemCasting = false; - - // nextEndLoc is used to store the next end location when someone is clicking - // around the ground while other timers like changeAltitude are still - // 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(); - protected float staminaMax; - protected AtomicFloat mana = new AtomicFloat(); - protected float manaMax; // Health/Mana/Stamina - protected AtomicBoolean isAlive = new AtomicBoolean(true); - protected Resists resists = new Resists("Genric"); - public AbstractWorldObject combatTarget; - protected ConcurrentHashMap timers; - protected ConcurrentHashMap timestamps; - protected int atrHandOne; - protected int atrHandTwo; - protected int minDamageHandOne; - protected int maxDamageHandOne; - protected int minDamageHandTwo; - protected int maxDamageHandTwo; - protected float rangeHandOne; - protected float rangeHandTwo; - protected float speedHandOne; - protected float speedHandTwo; - protected int defenseRating; - 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; - protected JobContainer lastChant; - protected boolean isCasting = false; - private final ReentrantReadWriteLock healthLock = new ReentrantReadWriteLock(); - private final ReentrantReadWriteLock teleportLock = new ReentrantReadWriteLock(); - protected long lastSetLocUpdate = 0L; - protected int inBuilding = -1; // -1 not in building 0 on ground floor, 1 on first floor etc - protected int inBuildingID = 0; - protected int inFloorID = -1; - protected int liveCounter = 0; - - protected int debug = 0; - private float hateValue = 0; - private long lastHateUpdate = 0; - private boolean collided = false; - protected Regions lastRegion = null; - - protected boolean movingUp = false; - public Contract contract; - - - /** - * No Id Constructor - */ - public AbstractCharacter( - final String firstName, - final String lastName, - final short statStrCurrent, - final short statDexCurrent, - final short statConCurrent, - final short statIntCurrent, - final short statSpiCurrent, - final short level, - final int exp, - final Vector3fImmutable bindLoc, - final Vector3fImmutable currentLoc, - final Vector3fImmutable faceDir, - final Guild guild, - final byte runningTrains - ) { - super(); - this.firstName = firstName; - this.lastName = lastName; - - this.statStrCurrent = statStrCurrent; - this.statDexCurrent = statDexCurrent; - this.statConCurrent = statConCurrent; - this.statIntCurrent = statIntCurrent; - this.statSpiCurrent = statSpiCurrent; - this.level = level; - this.exp = exp; - this.walkMode = true; - this.bindLoc = bindLoc; - if (ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER)) - this.setLoc(currentLoc); - this.faceDir = faceDir; - this.guild = guild; - this.runningTrains = runningTrains; - this.powers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - this.skills = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - this.initializeCharacter(); - - // Dangerous to use THIS in a constructor!!! - this.charItemManager = new CharacterItemManager(this); - } - - /** - * Normal Constructor - */ - public AbstractCharacter( - final String firstName, - final String lastName, - final short statStrCurrent, - final short statDexCurrent, - final short statConCurrent, - final short statIntCurrent, - final short statSpiCurrent, - final short level, - final int exp, - final Vector3fImmutable bindLoc, - final Vector3fImmutable currentLoc, - final Vector3fImmutable faceDir, - final Guild guild, - final byte runningTrains, - final int newUUID - ) { - - super(newUUID); - this.firstName = firstName; - this.lastName = lastName; - - this.statStrCurrent = statStrCurrent; - this.statDexCurrent = statDexCurrent; - this.statConCurrent = statConCurrent; - this.statIntCurrent = statIntCurrent; - this.statSpiCurrent = statSpiCurrent; - this.level = level; - this.exp = exp; - this.walkMode = true; - - this.bindLoc = bindLoc; - if (ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER)) - this.setLoc(currentLoc); - this.faceDir = faceDir; - this.guild = guild; - - this.runningTrains = runningTrains; - this.powers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - this.skills = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - this.initializeCharacter(); - - // Dangerous to use THIS in a constructor!!! - this.charItemManager = new CharacterItemManager(this); - } - - /** - * ResultSet Constructor for players - */ - public AbstractCharacter( - final ResultSet rs, - final boolean isPlayer - ) throws SQLException { - super(rs); - - this.firstName = rs.getString("char_firstname"); - this.lastName = rs.getString("char_lastname"); - - this.level = 1; - this.exp = rs.getInt("char_experience"); - this.walkMode = false; - - this.bindLoc = new Vector3fImmutable(0f, 0f, 0f); - this.endLoc = Vector3fImmutable.ZERO; - - this.faceDir = Vector3fImmutable.ZERO; - - final int guildID = rs.getInt("GuildUID"); - final Guild errantGuild = Guild.getErrantGuild(); - - if (guildID == errantGuild.getObjectUUID()) { - this.guild = errantGuild; - } - else { - this.guild = Guild.getGuild(guildID); - if (this.guild == null) { - this.guild = Guild.getErrantGuild(); - } - } - - if (this.guild == null) - this.guild = errantGuild; - - this.skills = new ConcurrentHashMap<>(); - this.powers = new ConcurrentHashMap<>(); - this.initializeCharacter(); - - // Dangerous to use THIS in a constructor!!! - this.charItemManager = new CharacterItemManager(this); - } - - /** - * ResultSet Constructor for NPC/Mobs - */ - public AbstractCharacter(final ResultSet rs) throws SQLException { - super(rs); - - this.firstName = ""; - this.lastName = ""; - - this.statStrCurrent = (short) 0; - this.statDexCurrent = (short) 0; - this.statConCurrent = (short) 0; - this.statIntCurrent = (short) 0; - this.statSpiCurrent = (short) 0; - - this.unusedStatPoints = (short) 0; - - this.level = (short) 0; // TODO get this from MobsBase later - this.exp = 1; - this.walkMode = true; - - //this.bindLoc = new Vector3fImmutable(rs.getFloat("spawnX"), rs.getFloat("spawnY"), rs.getFloat("spawnZ")); - this.bindLoc = Vector3fImmutable.ZERO; - //setLoc(this.bindLoc); - - this.faceDir = Vector3fImmutable.ZERO; - - this.runningTrains = (byte) 0; - - this.skills = new ConcurrentHashMap<>(); - this.powers = new ConcurrentHashMap<>(); - initializeCharacter(); - - // Dangerous to use THIS in a constructor!!! - this.charItemManager = new CharacterItemManager(this); - } - - /** - * ResultSet Constructor for static Mobs - */ - public AbstractCharacter(final ResultSet rs, final int objectUUID) throws SQLException { - - super(objectUUID); - - this.firstName = ""; - this.lastName = ""; - - this.statStrCurrent = (short) 0; - this.statDexCurrent = (short) 0; - this.statConCurrent = (short) 0; - this.statIntCurrent = (short) 0; - this.statSpiCurrent = (short) 0; - - this.unusedStatPoints = (short) 0; - - this.level = (short) 0; // TODO get this from MobsBase later - this.exp = 1; - this.walkMode = true; - - this.bindLoc = new Vector3fImmutable(rs.getFloat("spawnX"), rs.getFloat("spawnY"), rs.getFloat("spawnZ")); - - if (ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER)) - this.setLoc(this.bindLoc); - this.endLoc = Vector3fImmutable.ZERO; - - - this.faceDir = Vector3fImmutable.ZERO; - - final int guildID = rs.getInt("GuildID"); - - if (guildID == Guild.getErrantGuild().getObjectUUID()) { - this.guild = Guild.getErrantGuild(); - } - else { - this.guild = Guild.getGuild(guildID); - } - - if (this.guild == null) - this.guild = Guild.getErrantGuild(); - - this.runningTrains = (byte) 0; - this.skills = new ConcurrentHashMap<>(); - this.powers = new ConcurrentHashMap<>(); - - this.initializeCharacter(); - - // Dangerous to use THIS in a constructor!!! - this.charItemManager = new CharacterItemManager(this); - } - - private void initializeCharacter() { - this.timers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - this.timestamps = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - final long l = System.currentTimeMillis(); - this.timestamps.put("Health Recovery", l); - this.timestamps.put("Stamina Recovery", l); - this.timestamps.put("Mana Recovery", l); - this.recycleTimers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - } - - protected abstract ConcurrentHashMap initializePowers(); - - private byte aoecntr = 0; - - public final void addPersistantAoe( - final String name, - final int duration, - final PersistentAoeJob asj, - final EffectsBase eb, - final int trains - ) { - if (!isAlive()) { - return; - } - final JobContainer jc = JobScheduler.getInstance().scheduleJob(asj, duration); - final Effect eff = new Effect(jc, eb, trains); - aoecntr++; - this.effects.put(name + aoecntr, eff); - eff.setPAOE(); - } - - public final void setLastChant( - final int duration, - final ChantJob cj - ) { - if (!isAlive()) { - return; - } - if (this.lastChant != null) { - this.lastChant.cancelJob(); - } - this.lastChant = JobScheduler.getInstance().scheduleJob(cj, duration); - } - - - public final void cancelLastChant() { - if (this.lastChant != null) { - this.lastChant.cancelJob(); - this.lastChant = null; - } - } - - public final void cancelLastChantIfSame(final Effect eff) { - if (eff == null || this.lastChant == null) { - return; - } - final AbstractJob aj = this.lastChant.getJob(); - if (aj == null || (!(aj instanceof ChantJob))) { - return; - } - final int token = ((ChantJob) aj).getPowerToken(); - if (eff.getPowerToken() == token && token != 0) { - this.cancelLastChant(); - } - } - - /* - * Getters - */ - public final short getUnusedStatPoints() { - return this.unusedStatPoints; - } - - public final void setUnusedStatPoints(final short value) { - this.unusedStatPoints = value; - } - - public final CharacterItemManager getCharItemManager() { - return this.charItemManager; - } - - public final void setDebug( - final int value, - final boolean toggle - ) { - if (toggle) { - this.debug |= value; //turn on debug - } - else { - this.debug &= ~value; //turn off debug - } - } - - public final boolean getDebug(final int value) { - return ((this.debug & value) != 0); - } - - @Override - public String getName() { - if (this.firstName.length() == 0 && this.lastName.length() == 0) { - return "Unnamed " + '(' + this.getObjectUUID() + ')'; - } - else if (this.lastName.length() == 0) { - return this.getFirstName(); - } - else { - return this.getFirstName() + ' ' + this.getLastName(); - } - } - - public String getFirstName() { - return this.firstName; - } - - public String getLastName() { - return this.lastName; - } - - public void setFirstName(final String name) { - this.firstName = name; - } - - public void setLastName(final String name) { - this.lastName = name; - } - - public final short getStatStrCurrent() { - return this.statStrCurrent; - } - - public final short getStatDexCurrent() { - return this.statDexCurrent; - } - - public final short getStatConCurrent() { - return this.statConCurrent; - } - - public final short getStatIntCurrent() { - return this.statIntCurrent; - } - - public final short getStatSpiCurrent() { - return this.statSpiCurrent; - } - - public short getLevel() { - return this.level; - } - - public void setLevel(final short value) { - this.level = value; - } - - public final boolean isActive() { - return this.isActive; - } - - public final void setActive(final boolean value) { - this.isActive = value; - } - - public final Resists getResists() { - if (this.resists == null) - return Resists.getResists(0); - return this.resists; - } - - public final void setResists(final Resists value) { - this.resists = value; - } - - public final int getExp() { - return this.exp; - } - - public final void setExp(final int value) { - this.exp = value; - } - - public final void setLastPower(final JobContainer jc) { - if (this.timers != null) { - this.timers.put("LastPower", jc); - } - } - - public final JobContainer getLastPower() { - if (this.timers == null) { - return null; - } - return this.timers.get("LastPower"); - } - - public final void clearLastPower() { - if (this.timers != null) { - this.timers.remove("LastPower"); - } - } - - public final void setLastItem(final JobContainer jc) { - if (this.timers != null) { - this.timers.put("LastItem", jc); - } - } - - public final JobContainer getLastItem() { - if (this.timers == null) { - return null; - } - return this.timers.get("LastItem"); - } - - public final void clearLastItem() { - if (this.timers != null) { - this.timers.remove("LastItem"); - } - } - - public final int getIsSittingAsInt() { - if (!this.isAlive()) { - return 1; - } - - if (this.sit) { - return 4; - } - else { - if (this.isMoving()) - return 7; - else - return 5; - } - } - - public final int getIsWalkingAsInt() { - if (this.walkMode) { - return 1; - } - return 2; - } - - public final int getIsCombatAsInt() { - if (this.combat) { - return 2; - } - return 1; - } - - public final int getIsFlightAsInt() { - if (this.altitude > 0) { - return 3; - } - - if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) - if (((PlayerCharacter)this).isLastSwimming()) - return 1; //swimming - - return 2; //ground - } - - - public final void clearTimer(final String name) { - if (this.timers != null) { - this.timers.remove(name); - } - } - - public abstract Vector3fImmutable getBindLoc(); - - - public final Vector3fImmutable getFaceDir() { - return this.faceDir; - } - - public final Vector3fImmutable getStartLoc() { - return this.startLoc; - } - - public final Vector3fImmutable getEndLoc() { - return this.endLoc; - } - - public final Vector3fImmutable getNextEndLoc() { - // this is only used when users are changing their end - // location while a timer like changeAltitude is ticking down - return this.nextEndLoc; - } - - public final void stopMovement(Vector3fImmutable stopLoc) { - - - locationLock.writeLock().lock(); - - try{ - this.setLoc(stopLoc); - this.endLoc = Vector3fImmutable.ZERO; - this.resetLastSetLocUpdate(); - }catch(Exception e){ - Logger.error(e); - }finally{ - locationLock.writeLock().unlock(); - } - } - - public final boolean isMoving() { - - // I might be on my way but my movement is paused - // due to a flight alt change - //TODO who the fuck wrote changeHeightJob. FIX THIS. - - - if (this.endLoc.equals(Vector3fImmutable.ZERO) || this.endLoc.equals(this.bindLoc)) - return false; - - if (this.takeOffTime != 0) - return false; - - if (this.isCasting && this.getObjectType().equals(GameObjectType.PlayerCharacter)) - return false; - - return true; - } - - - public final boolean useFlyMoveRegen() { - - - if (this.endLoc.x != 0 && this.endLoc.z != 0) - return true; - - return false; - } - - public boolean asciiLastName() { - return true; - } - - public final ConcurrentHashMap getSkills() { - return this.skills; - } - - public final ConcurrentHashMap getPowers() { - return this.powers; - } - - public final int getInBuilding() { - return this.inBuilding; - } - - public Guild getGuild() { - return this.guild; - } - - public int getGuildUUID() { - return this.guild.getObjectUUID(); - } - - - public final int getRank() { - return (this.level / 10); - } - - public final int getAtrHandOne() { - return this.atrHandOne; - } - - public final int getAtrHandTwo() { - return this.atrHandTwo; - } - - public final int getMinDamageHandOne() { - return this.minDamageHandOne; - } - - public final int getMaxDamageHandOne() { - return this.maxDamageHandOne; - } - - public final int getMinDamageHandTwo() { - return this.minDamageHandTwo; - } - - public final int getMaxDamageHandTwo() { - return this.maxDamageHandTwo; - } - - public final int getDefenseRating() { - return this.defenseRating; - } - - public final float getRangeHandOne() { - return this.rangeHandOne; - } - - public final float getRangeHandTwo() { - return this.rangeHandTwo; - } - - public final float getSpeedHandOne() { - return this.speedHandOne; - } - - public final float getSpeedHandTwo() { - return this.speedHandTwo; - } - - public final float getRange() { - - // Treb range does not appear to be set here - // what gives? - - - if (this.getObjectType() == GameObjectType.Mob) { - Mob mob = (Mob) this; - if (mob.isSiege()) { - return 300; - } - float range = 8; - if(((Mob) this).getEquip().get(1) != null){ - range = ((Mob) this).getEquip().get(1).getItemBase().getRange(); - } else if(((Mob) this).getEquip().get(2) != null){ - range = ((Mob) this).getEquip().get(2).getItemBase().getRange(); - } - if(range > 80){ - range = 80; - } - return range; - } - if (this.rangeHandOne > this.rangeHandTwo) { - return this.rangeHandOne; - } - return this.rangeHandTwo; - } - - public abstract float getPassiveChance( - final String type, - final int attackerLevel, - final boolean fromCombat); - - public abstract float getSpeed(); - - public static int getBankCapacity() { - return 500; - } - - public final int getBankCapacityRemaining() { - return (AbstractCharacter.getBankCapacity() - this.charItemManager.getBankWeight()); - } - - public static int getVaultCapacity() { - return 5000; - } - - public final int getVaultCapacityRemaining() { - return (AbstractCharacter.getVaultCapacity() - this.charItemManager.getVaultWeight()); - } - - public final ArrayList getInventory() { - return this.getInventory(false); - } - - public final ArrayList getInventory(final boolean getGold) { - if (this.charItemManager == null) { - return new ArrayList<>(); - } - return this.charItemManager.getInventory(getGold); - } - - @Override - public Vector3fImmutable getLoc() { - - return super.getLoc(); - } - - public Vector3fImmutable getMovementLoc() { - - if (this.endLoc.equals(Vector3fImmutable.ZERO)) - return super.getLoc(); - if (this.takeOffTime != 0) - return super.getLoc(); - - return super.getLoc().moveTowards(this.endLoc, this.getSpeed() * ((System.currentTimeMillis() - lastSetLocUpdate) * .001f)); - - } - - /* - * Setters - */ - public void setGuild(final Guild value) { - this.guild = value; - } - - public final void setBindLoc(final float x, final float y, final float z) { - this.bindLoc = new Vector3fImmutable(x, y, z); - } - - public final void setEndLoc(final Vector3fImmutable value) { - if(value.x > MBServerStatics.MAX_PLAYER_X_LOC) - return; - if (value.z < MBServerStatics.MAX_PLAYER_Y_LOC) - return; - - this.endLoc = value; - // reset the location timer so our next call to getLoc is correct - this.resetLastSetLocUpdate(); - } - - public final void resetLastSetLocUpdate() { - this.lastSetLocUpdate = System.currentTimeMillis(); - } - - public final void setBindLoc(final Vector3fImmutable value) { - this.bindLoc = value; - } - - @Override - public final void setLoc(final Vector3fImmutable value) { - super.setLoc(value); // set the location in the world - this.resetLastSetLocUpdate(); - //Logger.info("AbstractCharacter", "Setting char location to :" + value.getX() + " " + value.getZ()); - } - - public final void setFaceDir(final Vector3fImmutable value) { - this.faceDir = value; - } - - public void setIsCasting(final boolean isCasting) { - this.isCasting = isCasting; - } - - public final boolean isCasting() { - return this.isCasting; - } - - @Override - public final boolean isAlive() { - return this.isAlive.get(); - } - - public final boolean isSafeMode() { - - if (this.resists == null) - return false; - - for (Effect eff: this.getEffects().values()){ - if (eff.getEffectToken() == -1661750486) - return true; - } - return this.resists.immuneToAll(); - } - - public abstract void killCharacter(final AbstractCharacter killer); - - public abstract void killCharacter(final String reason); - - /** - * Determines if the character is in a lootable state. - * - * @return True if lootable. - */ - public abstract boolean canBeLooted(); - /* - * Utils - */ - - public float calcHitBox() { - if (this.getObjectType() == GameObjectType.PlayerCharacter) { - // hit box radius is str/100 (gets diameter of hitbox) /2 (as we want a radius) - // note this formula is guesswork - if (MBServerStatics.COMBAT_TARGET_HITBOX_DEBUG) { - Logger.info( "Hit box radius for " + this.getFirstName() + " is " + (this.statStrCurrent / 200f)); - } - return ((PlayerCharacter) this).getStrForClient() / 200f; - //TODO CALCULATE MOB HITBOX BECAUSE FAIL EMU IS FAIL!!!!!!! - } - else if (this.getObjectType() == GameObjectType.Mob) { - if (MBServerStatics.COMBAT_TARGET_HITBOX_DEBUG) { - Logger.info("Hit box radius for " + this.getFirstName() + " is " + ((Mob) this).getMobBase().getHitBoxRadius()); - } - return ((Mob) this).getMobBase().getHitBoxRadius(); - } - return 0f; - } - - public final boolean isSit() { - return this.sit; - } - - public final boolean isWalk() { - return this.walkMode; - } - - public final boolean isCombat() { - return this.combat; - } - - public final void setSit(final boolean value) { - - if (this.sit != value) { - // change sit/stand and sync location - this.sit = value; - if (value == true) // we have been told to sit - { - this.stopMovement(this.getLoc()); - } - } - - } - - public final void setWalkMode(final boolean value) { - // sync movement location as getLoc gets where we are at the exact moment in time (i.e. not the last updated loc) - this.setLoc(this.getLoc()); - if (this.walkMode == value) { - return; - } - else { - this.walkMode = value; - } - } - - public final void setCombat(final boolean value) { - this.combat = value; - } - - public final void setInBuilding(final int floor) { - this.inBuilding = floor; - } - - public final AbstractWorldObject getCombatTarget() { - return this.combatTarget; - } - - public final void setCombatTarget(final AbstractWorldObject value) { - this.combatTarget = value; - } - - public final ConcurrentHashMap getTimers() { - if (this.timers == null) { - this.timers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - } - return this.timers; - } - - public final int getLiveCounter() { - return this.liveCounter; - } - - public final void addTimer( - final String name, - final AbstractJob asj, - final int duration - ) { - final JobContainer jc = JobScheduler.getInstance().scheduleJob(asj, duration); - if (this.timers == null) { - this.timers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - } - this.timers.put(name, jc); - } - - public final void renewTimer( - final String name, - final AbstractJob asj, - final int duration - ) { - this.cancelTimer(name); - this.addTimer(name, asj, duration); - } - - public final ConcurrentHashMap getRecycleTimers() { - return this.recycleTimers; - } - - public final ConcurrentHashMap getTimestamps() { - return this.timestamps; - } - - public final long getTimeStamp(final String name) { - if (this.timestamps.containsKey(name)) { - return this.timestamps.get(name); - } - return 0L; - } - - public final void setTimeStamp(final String name, final long value) { - this.timestamps.put(name, value); - } - - public final void setTimeStampNow(final String name) { - this.timestamps.put(name, System.currentTimeMillis()); - } - - public final void cancelTimer(final String name) { - cancelTimer(name, true); - } - - public final void cancelTimer(final String name, final boolean jobRunning) { - if (this.timers == null) { - this.timers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - } - if (this.timers.containsKey(name)) { - if (jobRunning) { - this.timers.get(name).cancelJob(); - } - this.timers.remove(name); - } - } - - public final float modifyHealth( - final float value, - final AbstractCharacter attacker, - final boolean fromCost) { - - try{ - - try{ - boolean ready = this.healthLock.writeLock().tryLock(1, TimeUnit.SECONDS); - - while (!ready) - ready = this.healthLock.writeLock().tryLock(1, TimeUnit.SECONDS); - - if (!this.isAlive()) - return 0; - - Float oldHealth, newHealth; - - if (!this.isAlive()) - return 0f; - - oldHealth = this.health.get(); - newHealth = oldHealth + value; - - if (newHealth > this.healthMax) - newHealth = healthMax; - - this.health.set(newHealth); - - if (newHealth <= 0) { - if (this.isAlive.compareAndSet(true, false)) { - killCharacter(attacker); - return newHealth - oldHealth; - } - else - return 0f; //already dead, don't send damage again - } // past this lock! - - //TODO why is Handle REtaliate and cancelontakedamage in modifyHealth? shouldnt this be outside this method? - if (value < 0f && !fromCost) { - this.cancelOnTakeDamage(); - CombatManager.handleRetaliate(this, attacker); - } - - return newHealth - oldHealth; - }finally{ - this.healthLock.writeLock().unlock(); - } - - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return 0; - } - - public float getCurrentHitpoints() { - return this.health.get(); - } - - public final float modifyMana( - final float value, - final AbstractCharacter attacker - ) { - return this.modifyMana(value, attacker, false); - } - - public final float modifyMana( - final float value, - final AbstractCharacter attacker, - final boolean fromCost - ) { - - if (!this.isAlive()) { - return 0f; - } - boolean worked = false; - Float oldMana = 0f, newMana = 0f; - while (!worked) { - oldMana = this.mana.get(); - newMana = oldMana + value; - if (newMana > this.manaMax) { - newMana = manaMax; - } - else if (newMana < 0) { - newMana = 0f; - } - worked = this.mana.compareAndSet(oldMana, newMana); - } - if (value < 0f && !fromCost) { - this.cancelOnTakeDamage(); - CombatManager.handleRetaliate(this, attacker); - } - return newMana - oldMana; - } - - public final float modifyStamina( - final float value, - final AbstractCharacter attacker - ) { - return this.modifyStamina(value, attacker, false); - } - - public final float modifyStamina( - final float value, - final AbstractCharacter attacker, - final boolean fromCost - ) { - - if (!this.isAlive()) { - return 0f; - } - boolean worked = false; - Float oldStamina = 0f, newStamina = 0f; - while (!worked) { - oldStamina = this.stamina.get(); - newStamina = oldStamina + value; - if (newStamina > this.staminaMax) { - newStamina = staminaMax; - } - else if (newStamina < 0) { - newStamina = 0f; - } - worked = this.stamina.compareAndSet(oldStamina, newStamina); - } - if (value < 0f && !fromCost) { - this.cancelOnTakeDamage(); - CombatManager.handleRetaliate(this, attacker); - } - return newStamina - oldStamina; - } - - public final float setMana( - final float value, - final AbstractCharacter attacker - ) { - return setMana(value, attacker, false); - } - - public final float setMana( - final float value, - final AbstractCharacter attacker, - final boolean fromCost - ) { - - if (!this.isAlive()) { - return 0f; - } - boolean worked = false; - Float oldMana = 0f, newMana = 0f; - while (!worked) { - oldMana = this.mana.get(); - newMana = value; - if (newMana > this.manaMax) { - newMana = manaMax; - } - else if (newMana < 0) { - newMana = 0f; - } - worked = this.mana.compareAndSet(oldMana, newMana); - } - if (oldMana > newMana && !fromCost) { - this.cancelOnTakeDamage(); - CombatManager.handleRetaliate(this, attacker); - } - return newMana - oldMana; - } - - public final float setStamina( - final float value, - final AbstractCharacter attacker - ) { - return setStamina(value, attacker, false); - } - - public final float setStamina( - final float value, - final AbstractCharacter attacker, - final boolean fromCost - ) { - - if (!this.isAlive()) { - return 0f; - } - boolean worked = false; - Float oldStamina = 0f, newStamina = 0f; - while (!worked) { - oldStamina = this.stamina.get(); - newStamina = value; - if (newStamina > this.staminaMax) { - newStamina = staminaMax; - } - else if (newStamina < 0) { - newStamina = 0f; - } - worked = this.stamina.compareAndSet(oldStamina, newStamina); - } - if (oldStamina > newStamina && !fromCost) { - this.cancelOnTakeDamage(); - CombatManager.handleRetaliate(this, attacker); - } - return newStamina - oldStamina; - - } - - public final float getStamina() { - if (this.getObjectType() == GameObjectType.Mob) - return this.getStaminaMax(); - return this.stamina.get(); - } - - public final float getMana() { - if (this.getObjectType() == GameObjectType.Mob) - return this.getManaMax(); - return this.mana.get(); - } - - public final float getStaminaMax() { - if (this.getObjectType() == GameObjectType.Mob) - return 2000; - return this.staminaMax; - } - - public final float getManaMax() { - if (this.getObjectType() == GameObjectType.Mob) - return 2000; - return this.manaMax; - } - - public final PlayerBonuses getBonuses() { - return this.bonuses; - } - - public void teleport(final Vector3fImmutable targetLoc) { - locationLock.writeLock().lock(); - try{ - MovementManager.translocate(this, targetLoc, null); - MovementManager.sendRWSSMsg(this); - }catch(Exception e){ - Logger.error(e); - }finally{ - locationLock.writeLock().unlock(); - } - } - - /* - * Serializing - */ - - public static void _serializeForClientMsg(AbstractCharacter abstractCharacter,final ByteBufferWriter writer) throws SerializationException { - AbstractCharacter.__serializeForClientMsg(abstractCharacter,writer); - } - - public static void __serializeForClientMsg(AbstractCharacter abstractCharacter,final ByteBufferWriter writer) throws SerializationException { - } - - - public static void serializeForClientMsgOtherPlayer(AbstractCharacter abstractCharacter,final ByteBufferWriter writer) throws SerializationException { - } - - public static void serializeForClientMsgOtherPlayer(AbstractCharacter abstractCharacter,final ByteBufferWriter writer, final boolean asciiLastName) throws SerializationException { - - switch (abstractCharacter.getObjectType()){ - case PlayerCharacter: - PlayerCharacter.serializePlayerForClientMsgOtherPlayer((PlayerCharacter)abstractCharacter, writer, asciiLastName); - break; - case Mob: - Mob.serializeMobForClientMsgOtherPlayer((Mob)abstractCharacter, writer); - break; - case NPC: - NPC.serializeNpcForClientMsgOtherPlayer((NPC)abstractCharacter, writer, asciiLastName); - break; - } - - - //TODO INPUT SWITCH CASE ON GAME OBJECTS TO CALL SPECIFIC METHODS. - } - - public static final void serializeForTrack(AbstractCharacter abstractCharacter, final ByteBufferWriter writer, boolean isGroup) { - writer.putInt(abstractCharacter.getObjectType().ordinal()); - writer.putInt(abstractCharacter.getObjectUUID()); - - if (abstractCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)) { - writer.putString(abstractCharacter.getName()); - } - else { - writer.putString(abstractCharacter.getFirstName()); - } - writer.put(isGroup ? (byte) 1 : (byte) 0); - if (abstractCharacter.guild != null) { - Guild.serializeForTrack(abstractCharacter.guild,writer); - } - else { - Guild.serializeErrantForTrack(writer); - } - } - - /* - * Cancel effects upon actions - */ - public final void cancelOnAttack() { // added to one spot - - boolean changed = false; - - for (String s : this.effects.keySet()) { - - Effect eff = this.effects.get(s); - - if (eff == null) - continue; - if (eff.cancelOnAttack() && eff.cancel()) { - eff.cancelJob(); - this.effects.remove(s); - changed = true; - } - } - - if (changed) { - applyBonuses(); - } - - PowersManager.cancelOnAttack(this); - } - - public final void cancelOnAttackSwing() { // added - boolean changed = false; - for (String s : this.effects.keySet()) { - Effect eff = this.effects.get(s); - if (eff == null) - continue; - if (eff.cancelOnAttackSwing() && eff.cancel()) { - //System.out.println("canceling on AttackSwing"); - eff.cancelJob(); - this.effects.remove(s); - changed = true; - } - } - if (changed) { - applyBonuses(); - } - PowersManager.cancelOnAttackSwing(this); - } - - public final void cancelOnCast() { - boolean changed = false; - for (String s : this.effects.keySet()) { - Effect eff = this.effects.get(s); - - if (eff == null) - continue; - if (eff.cancelOnCast() && eff.cancel()) { - - // Don't cancel the track effect on the character being tracked - if (eff.getJob() != null && eff.getJob() instanceof TrackJob) { - if (((TrackJob) eff.getJob()).getSource().getObjectUUID() - == this.getObjectUUID()) { - continue; - } - } - - //System.out.println("canceling on Cast"); - eff.cancelJob(); - this.effects.remove(s); - changed = true; - } - } - if (changed) { - applyBonuses(); - } - PowersManager.cancelOnCast(this); - } - - public final void cancelOnSpell() { - boolean changed = false; - for (String s : this.effects.keySet()) { - Effect eff = this.effects.get(s); - if (eff == null) - continue; - if (eff.cancelOnCastSpell() && eff.cancel()) { - //System.out.println("canceling on CastSpell"); - eff.cancelJob(); - this.effects.remove(s); - changed = true; - } - } - if (changed) { - applyBonuses(); - } - PowersManager.cancelOnSpell(this); - } - - public final void cancelOnMove() { // added - boolean changed = false; - for (String s : this.effects.keySet()) { - Effect eff = this.effects.get(s); - if (eff == null) - continue; - if (eff.cancelOnMove() && eff.cancel()) { - //System.out.println("canceling on Move"); - eff.cancelJob(); - this.effects.remove(s); - changed = true; - } - } - if (changed) { - applyBonuses(); - } - PowersManager.cancelOnMove(this); - } - - public final void cancelOnSit() { // added - boolean changed = false; - for (String s : this.effects.keySet()) { - Effect eff = this.effects.get(s); - if (eff == null) - continue; - if (eff.cancelOnSit() && eff.cancel()) { - //System.out.println("canceling on Sit"); - eff.cancelJob(); - this.effects.remove(s); - changed = true; - } - } - if (changed) { - applyBonuses(); - } - PowersManager.cancelOnSit(this); - } - - public final void cancelOnTakeDamage() { - boolean changed = false; - for (String s : this.effects.keySet()) { - Effect eff = this.effects.get(s); - if (eff == null) - continue; - if (eff.cancelOnTakeDamage() && eff.cancel()) { - //System.out.println("canceling on Take Damage"); - eff.cancelJob(); - this.effects.remove(s); - changed = true; - } - } - if (changed) { - applyBonuses(); - } - PowersManager.cancelOnTakeDamage(this); - } - - public final void cancelOnTakeDamage(final DamageType type, final float amount) { - boolean changed = false; - for (String s : this.effects.keySet()) { - Effect eff = this.effects.get(s); - if (eff == null) - continue; - if (eff.cancelOnTakeDamage(type, amount) && eff.cancel()) { - eff.cancelJob(); - this.effects.remove(s); - changed = true; - } - } - if (changed) { - applyBonuses(); - } - } - - public final Effect getDamageAbsorber() { - for (String s : this.effects.keySet()) { - Effect eff = this.effects.get(s); - if (eff == null) - continue; - if (eff.isDamageAbsorber()) { - return eff; - } - } - return null; - } - - public final void cancelOnUnEquip() { - boolean changed = false; - for (String s : this.effects.keySet()) { - Effect eff = this.effects.get(s); - if (eff == null) - continue; - if (eff.cancelOnUnEquip() && eff.cancel()) { - //System.out.println("canceling on UnEquip"); - eff.cancelJob(); - this.effects.remove(s); - changed = true; - } - } - if (changed) { - applyBonuses(); - } - PowersManager.cancelOnUnEquip(this); - } - - public final void cancelOnStun() { - boolean changed = false; - for (String s : this.effects.keySet()) { - Effect eff = this.effects.get(s); - - if (eff == null){ - Logger.error("null effect for " + this.getObjectUUID() + " : effect " + s); - continue; - } - if (eff.cancelOnStun() && eff.cancel()) { - //System.out.println("canceling on Stun"); - eff.cancelJob(); - this.effects.remove(s); - changed = true; - } - } - if (changed) { - applyBonuses(); - } - PowersManager.cancelOnStun(this); - } - - //Call to apply any new effects to player - public synchronized void applyBonuses() { - PlayerCharacter player; - //tell the player to applyBonuses because something has changed - - //start running the bonus calculations - - try{ - runBonuses(); - - // Check if calculations affected flight. - - if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) { - player = (PlayerCharacter) this; - - // Ground players who cannot fly but are currently flying - - if (CanFly(player) == false && - player.getMovementState().equals(MovementState.FLYING)) - PlayerCharacter.GroundPlayer(player); - } - - }catch(Exception e){ - Logger.error("Error in run bonuses for object UUID " + this.getObjectUUID()); - Logger.error(e); - } - } - - //Don't call this function directly. linked from ac.applyBonuses() - //through BonusCalcJob. Designed to only run from one worker thread - public final void runBonuses() { - // synchronized with getBonuses() - synchronized (this.bonuses) { - try { - //run until no new bonuses are applied - - // clear bonuses and reapply rune bonuses - if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) { - this.bonuses.calculateRuneBaseEffects((PlayerCharacter) this); - } - else { - this.bonuses.clearRuneBaseEffects(); - } - - // apply effect bonuses - for (Effect eff : this.effects.values()) { - eff.applyBonus(this); - } - - //apply item bonuses for equipped items - ConcurrentHashMap equip = null; - - if (this.charItemManager != null) { - equip = this.charItemManager.getEquipped(); - } - if (equip != null) { - for (Item item : equip.values()) { - item.clearBonuses(); - if (item != null) { - ConcurrentHashMap effects = item.getEffects(); - if (effects != null) { - for (Effect eff : effects.values()) { - eff.applyBonus(item, this); - } - } - } - } - } - - //recalculate passive defenses - if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) { - ((PlayerCharacter) this).setPassives(); - } - - - - // recalculate everything - if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) { - PlayerCharacter pc = (PlayerCharacter) this; - - //calculate item bonuses - pc.calculateItemBonuses(); - - //recalculate formulas - pc.recalculatePlayerStats(true); - - - } - else if (this.getObjectType().equals(GameObjectType.Mob)) { - Mob mob = (Mob) this; - - //recalculate formulas - mob.recalculateStats(); - } - } catch (Exception e) { - Logger.error( e); - } - } - } - - public static void runBonusesOnLoad(PlayerCharacter pc) { - // synchronized with getBonuses() - synchronized (pc.bonuses) { - try { - //run until no new bonuses are applied - - // clear bonuses and reapply rune bonuses - if (pc.getObjectType() == GameObjectType.PlayerCharacter) { - pc.bonuses.calculateRuneBaseEffects(pc); - } - else { - pc.bonuses.clearRuneBaseEffects(); - } - - // apply effect bonuses - for (Effect eff : pc.effects.values()) { - eff.applyBonus(pc); - } - - //apply item bonuses for equipped items - ConcurrentHashMap equip = null; - - if (pc.charItemManager != null) - equip = pc.charItemManager.getEquipped(); - - if (equip != null) { - for (Item item : equip.values()) { - item.clearBonuses(); - if (item != null) { - ConcurrentHashMap effects = item.getEffects(); - if (effects != null) { - for (Effect eff : effects.values()) { - eff.applyBonus(item, pc); - } - } - } - } - } - - //recalculate passive defenses - pc.setPassives(); - - //flip the active bonus set for synchronization purposes - //do this after all bonus updates, but before recalculations. - // recalculate everything - //calculate item bonuses - pc.calculateItemBonuses(); - - //recalculate formulas - PlayerCharacter.recalculatePlayerStatsOnLoad(pc); - - } catch (Exception e) { - Logger.error( e); - } - - } - // TODO remove later, for debugging. - //this.bonuses.printBonuses(); - - } - - public int getInBuildingID() { - return inBuildingID; - } - - public void setInBuildingID(int inBuildingID) { - this.inBuildingID = inBuildingID; - } - - public float getHateValue() { - if (this.hateValue <= 0) { - this.hateValue = 0; - return hateValue; - } - - if (this.lastHateUpdate == 0) { - this.lastHateUpdate = System.currentTimeMillis(); - return this.hateValue; - } - long duration = System.currentTimeMillis() - this.lastHateUpdate; - //convert duration to seconds and multiply Hate Delimiter. - float modAmount = duration / 1000 * MBServerStatics.PLAYER_HATE_DELIMITER; - this.hateValue -= modAmount; - this.lastHateUpdate = System.currentTimeMillis(); - return this.hateValue; - } - - public void setHateValue(float hateValue) { - this.lastHateUpdate = System.currentTimeMillis(); - this.hateValue = hateValue; - } - - public int getInFloorID() { - return inFloorID; - } - - public void setInFloorID(int inFloorID) { - this.inFloorID = inFloorID; - } - - public boolean isCollided() { - return collided; - } - - public void setCollided(boolean collided) { - this.collided = collided; - } - - - public static void SetBuildingLevelRoom(AbstractCharacter character, int buildingID, int buildingLevel, int room, Regions region){ - character.inBuildingID = buildingID; - character.inBuilding = buildingLevel; - character.inFloorID = room; - character.lastRegion = region; - } - - public static Regions InsideBuildingRegion(AbstractCharacter player){ - - Regions currentRegion = null; - HashSet buildings = WorldGrid.getObjectsInRangePartial(player, 300, MBServerStatics.MASK_BUILDING); - - for (AbstractWorldObject awo: buildings){ - - Building building = (Building)awo; - - if (building.getBounds() == null) - continue; - - if (building.getBounds().getRegions() == null) - continue; - - for (Regions region : building.getBounds().getRegions()){ - //TODO ADD NEW REGION CODE - } - } - return currentRegion; - } - - public static Regions InsideBuildingRegionGoingDown(AbstractCharacter player){ - - HashSet buildings = WorldGrid.getObjectsInRangePartial(player, 1000, MBServerStatics.MASK_BUILDING); - - Regions tempRegion = null; - for (AbstractWorldObject awo: buildings){ - - Building building = (Building)awo; - if (building.getBounds() == null) - continue; - - if (!Bounds.collide(player.getLoc(), building.getBounds())) - continue; - - for (Regions region : building.getBounds().getRegions()){ - - if (!region.isPointInPolygon(player.getLoc())) - continue; - - if (!region.isOutside()) - continue; - if (tempRegion == null) - tempRegion = region; - - if (tempRegion.highLerp.y < region.highLerp.y) - tempRegion = region; - } - - if (tempRegion != null) - break; - } - return tempRegion; - } - - public float getDesiredAltitude() { - return desiredAltitude; - } - - public void setDesiredAltitude(float desiredAltitude) { - this.desiredAltitude = desiredAltitude; - } - - - public long getTakeOffTime() { - return takeOffTime; - } - - public void setTakeOffTime(long takeOffTime) { - this.takeOffTime = takeOffTime; - } - - public static boolean CanFly(AbstractCharacter flyer){ - boolean canFly = false; - PlayerBonuses bonus = flyer.getBonuses(); - - if (bonus != null && !bonus.getBool(ModType.NoMod, SourceType.Fly) && bonus.getBool(ModType.Fly,SourceType.None) && flyer.isAlive()) - canFly = true; - - return canFly; - - } - - public boolean isItemCasting() { - return itemCasting; - } - - public void setItemCasting(boolean itemCasting) { - this.itemCasting = itemCasting; - } - - //updates - public void update(){ - } - public void updateRegen(){ - } - public void updateMovementState(){ - } - public void updateLocation(){ - } - public void updateFlight(){ - } - - - public void dynamicUpdate(UpdateType updateType){ - if (this.updateLock.writeLock().tryLock()){ - try{ - switch(updateType){ - case ALL: - update(); - break; - case REGEN: - updateRegen(); - break; - case LOCATION: - update(); - break; - case MOVEMENTSTATE: - update(); - break; - case FLIGHT: - updateFlight(); - break; - } - - }catch(Exception e){ - Logger.error(e); - }finally{ - this.updateLock.writeLock().unlock(); - } - } - - } - - public Regions getLastRegion() { - return lastRegion; - } - - public boolean isMovingUp() { - return movingUp; - } - - public void setMovingUp(boolean movingUp) { - this.movingUp = movingUp; - } - public static void UpdateRegion(AbstractCharacter worldObject){ - worldObject.region = AbstractWorldObject.GetRegionByWorldObject(worldObject); - } - - public static void teleport(AbstractCharacter worldObject, final Vector3fImmutable targetLoc) { - worldObject.locationLock.writeLock().lock(); - try{ - MovementManager.translocate(worldObject, targetLoc,null); - if (worldObject.getObjectType().equals(GameObjectType.PlayerCharacter)) - InterestManager.INTERESTMANAGER.HandleLoadForTeleport((PlayerCharacter)worldObject); - }catch(Exception e){ - Logger.error(e); - }finally{ - worldObject.locationLock.writeLock().unlock(); - } - } + private long takeOffTime = 0; + private float hateValue = 0; + private long lastHateUpdate = 0; + private boolean collided = false; + private byte aoecntr = 0; + + /** + * No Id Constructor + */ + public AbstractCharacter( + final String firstName, + final String lastName, + final short statStrCurrent, + final short statDexCurrent, + final short statConCurrent, + final short statIntCurrent, + final short statSpiCurrent, + final short level, + final int exp, + final Vector3fImmutable bindLoc, + final Vector3fImmutable currentLoc, + final Vector3fImmutable faceDir, + final Guild guild, + final byte runningTrains + ) { + super(); + this.firstName = firstName; + this.lastName = lastName; + + this.statStrCurrent = statStrCurrent; + this.statDexCurrent = statDexCurrent; + this.statConCurrent = statConCurrent; + this.statIntCurrent = statIntCurrent; + this.statSpiCurrent = statSpiCurrent; + this.level = level; + this.exp = exp; + this.walkMode = true; + this.bindLoc = bindLoc; + if (ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER)) + this.setLoc(currentLoc); + this.faceDir = faceDir; + this.guild = guild; + this.runningTrains = runningTrains; + this.powers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + this.skills = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + this.initializeCharacter(); + + // Dangerous to use THIS in a constructor!!! + this.charItemManager = new CharacterItemManager(this); + } + + /** + * Normal Constructor + */ + public AbstractCharacter( + final String firstName, + final String lastName, + final short statStrCurrent, + final short statDexCurrent, + final short statConCurrent, + final short statIntCurrent, + final short statSpiCurrent, + final short level, + final int exp, + final Vector3fImmutable bindLoc, + final Vector3fImmutable currentLoc, + final Vector3fImmutable faceDir, + final Guild guild, + final byte runningTrains, + final int newUUID + ) { + + super(newUUID); + this.firstName = firstName; + this.lastName = lastName; + + this.statStrCurrent = statStrCurrent; + this.statDexCurrent = statDexCurrent; + this.statConCurrent = statConCurrent; + this.statIntCurrent = statIntCurrent; + this.statSpiCurrent = statSpiCurrent; + this.level = level; + this.exp = exp; + this.walkMode = true; + + this.bindLoc = bindLoc; + if (ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER)) + this.setLoc(currentLoc); + this.faceDir = faceDir; + this.guild = guild; + + this.runningTrains = runningTrains; + this.powers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + this.skills = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + this.initializeCharacter(); + + // Dangerous to use THIS in a constructor!!! + this.charItemManager = new CharacterItemManager(this); + } + + /** + * ResultSet Constructor for players + */ + public AbstractCharacter( + final ResultSet rs, + final boolean isPlayer + ) throws SQLException { + super(rs); + + this.firstName = rs.getString("char_firstname"); + this.lastName = rs.getString("char_lastname"); + + this.level = 1; + this.exp = rs.getInt("char_experience"); + this.walkMode = false; + + this.bindLoc = new Vector3fImmutable(0f, 0f, 0f); + this.endLoc = Vector3fImmutable.ZERO; + + this.faceDir = Vector3fImmutable.ZERO; + + final int guildID = rs.getInt("GuildUID"); + final Guild errantGuild = Guild.getErrantGuild(); + + if (guildID == errantGuild.getObjectUUID()) { + this.guild = errantGuild; + } else { + this.guild = Guild.getGuild(guildID); + if (this.guild == null) { + this.guild = Guild.getErrantGuild(); + } + } + + if (this.guild == null) + this.guild = errantGuild; + + this.skills = new ConcurrentHashMap<>(); + this.powers = new ConcurrentHashMap<>(); + this.initializeCharacter(); + + // Dangerous to use THIS in a constructor!!! + this.charItemManager = new CharacterItemManager(this); + } + + /** + * ResultSet Constructor for NPC/Mobs + */ + public AbstractCharacter(final ResultSet rs) throws SQLException { + super(rs); + + this.firstName = ""; + this.lastName = ""; + + this.statStrCurrent = (short) 0; + this.statDexCurrent = (short) 0; + this.statConCurrent = (short) 0; + this.statIntCurrent = (short) 0; + this.statSpiCurrent = (short) 0; + + this.unusedStatPoints = (short) 0; + + this.level = (short) 0; // TODO get this from MobsBase later + this.exp = 1; + this.walkMode = true; + + //this.bindLoc = new Vector3fImmutable(rs.getFloat("spawnX"), rs.getFloat("spawnY"), rs.getFloat("spawnZ")); + this.bindLoc = Vector3fImmutable.ZERO; + //setLoc(this.bindLoc); + + this.faceDir = Vector3fImmutable.ZERO; + + this.runningTrains = (byte) 0; + + this.skills = new ConcurrentHashMap<>(); + this.powers = new ConcurrentHashMap<>(); + initializeCharacter(); + + // Dangerous to use THIS in a constructor!!! + this.charItemManager = new CharacterItemManager(this); + } + + /** + * ResultSet Constructor for static Mobs + */ + public AbstractCharacter(final ResultSet rs, final int objectUUID) throws SQLException { + + super(objectUUID); + + this.firstName = ""; + this.lastName = ""; + + this.statStrCurrent = (short) 0; + this.statDexCurrent = (short) 0; + this.statConCurrent = (short) 0; + this.statIntCurrent = (short) 0; + this.statSpiCurrent = (short) 0; + + this.unusedStatPoints = (short) 0; + + this.level = (short) 0; // TODO get this from MobsBase later + this.exp = 1; + this.walkMode = true; + + this.bindLoc = new Vector3fImmutable(rs.getFloat("spawnX"), rs.getFloat("spawnY"), rs.getFloat("spawnZ")); + + if (ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER)) + this.setLoc(this.bindLoc); + this.endLoc = Vector3fImmutable.ZERO; + + + this.faceDir = Vector3fImmutable.ZERO; + + final int guildID = rs.getInt("GuildID"); + + if (guildID == Guild.getErrantGuild().getObjectUUID()) { + this.guild = Guild.getErrantGuild(); + } else { + this.guild = Guild.getGuild(guildID); + } + + if (this.guild == null) + this.guild = Guild.getErrantGuild(); + + this.runningTrains = (byte) 0; + this.skills = new ConcurrentHashMap<>(); + this.powers = new ConcurrentHashMap<>(); + + this.initializeCharacter(); + + // Dangerous to use THIS in a constructor!!! + this.charItemManager = new CharacterItemManager(this); + } + + public static int getBankCapacity() { + return 500; + } + + public static int getVaultCapacity() { + return 5000; + } + + public static void _serializeForClientMsg(AbstractCharacter abstractCharacter, final ByteBufferWriter writer) throws SerializationException { + AbstractCharacter.__serializeForClientMsg(abstractCharacter, writer); + } + + public static void __serializeForClientMsg(AbstractCharacter abstractCharacter, final ByteBufferWriter writer) throws SerializationException { + } + + public static void serializeForClientMsgOtherPlayer(AbstractCharacter abstractCharacter, final ByteBufferWriter writer) throws SerializationException { + } + + public static void serializeForClientMsgOtherPlayer(AbstractCharacter abstractCharacter, final ByteBufferWriter writer, final boolean asciiLastName) throws SerializationException { + + switch (abstractCharacter.getObjectType()) { + case PlayerCharacter: + PlayerCharacter.serializePlayerForClientMsgOtherPlayer((PlayerCharacter) abstractCharacter, writer, asciiLastName); + break; + case Mob: + Mob.serializeMobForClientMsgOtherPlayer((Mob) abstractCharacter, writer); + break; + case NPC: + NPC.serializeNpcForClientMsgOtherPlayer((NPC) abstractCharacter, writer, asciiLastName); + break; + } + + + //TODO INPUT SWITCH CASE ON GAME OBJECTS TO CALL SPECIFIC METHODS. + } + + public static final void serializeForTrack(AbstractCharacter abstractCharacter, final ByteBufferWriter writer, boolean isGroup) { + writer.putInt(abstractCharacter.getObjectType().ordinal()); + writer.putInt(abstractCharacter.getObjectUUID()); + + if (abstractCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)) { + writer.putString(abstractCharacter.getName()); + } else { + writer.putString(abstractCharacter.getFirstName()); + } + writer.put(isGroup ? (byte) 1 : (byte) 0); + if (abstractCharacter.guild != null) { + Guild.serializeForTrack(abstractCharacter.guild, writer); + } else { + Guild.serializeErrantForTrack(writer); + } + } + + public static void runBonusesOnLoad(PlayerCharacter pc) { + // synchronized with getBonuses() + synchronized (pc.bonuses) { + try { + //run until no new bonuses are applied + + // clear bonuses and reapply rune bonuses + if (pc.getObjectType() == GameObjectType.PlayerCharacter) { + pc.bonuses.calculateRuneBaseEffects(pc); + } else { + pc.bonuses.clearRuneBaseEffects(); + } + + // apply effect bonuses + for (Effect eff : pc.effects.values()) { + eff.applyBonus(pc); + } + + //apply item bonuses for equipped items + ConcurrentHashMap equip = null; + + if (pc.charItemManager != null) + equip = pc.charItemManager.getEquipped(); + + if (equip != null) { + for (Item item : equip.values()) { + item.clearBonuses(); + if (item != null) { + ConcurrentHashMap effects = item.getEffects(); + if (effects != null) { + for (Effect eff : effects.values()) { + eff.applyBonus(item, pc); + } + } + } + } + } + + //recalculate passive defenses + pc.setPassives(); + + //flip the active bonus set for synchronization purposes + //do this after all bonus updates, but before recalculations. + // recalculate everything + //calculate item bonuses + pc.calculateItemBonuses(); + + //recalculate formulas + PlayerCharacter.recalculatePlayerStatsOnLoad(pc); + + } catch (Exception e) { + Logger.error(e); + } + + } + // TODO remove later, for debugging. + //this.bonuses.printBonuses(); + + } + + public static void SetBuildingLevelRoom(AbstractCharacter character, int buildingID, int buildingLevel, int room, Regions region) { + character.inBuildingID = buildingID; + character.inBuilding = buildingLevel; + character.inFloorID = room; + character.lastRegion = region; + } + + public static Regions InsideBuildingRegion(AbstractCharacter player) { + + Regions currentRegion = null; + HashSet buildings = WorldGrid.getObjectsInRangePartial(player, 300, MBServerStatics.MASK_BUILDING); + + for (AbstractWorldObject awo : buildings) { + + Building building = (Building) awo; + + if (building.getBounds() == null) + continue; + + if (building.getBounds().getRegions() == null) + continue; + + for (Regions region : building.getBounds().getRegions()) { + //TODO ADD NEW REGION CODE + } + } + return currentRegion; + } + + public static Regions InsideBuildingRegionGoingDown(AbstractCharacter player) { + + HashSet buildings = WorldGrid.getObjectsInRangePartial(player, 1000, MBServerStatics.MASK_BUILDING); + + Regions tempRegion = null; + for (AbstractWorldObject awo : buildings) { + + Building building = (Building) awo; + if (building.getBounds() == null) + continue; + + if (!Bounds.collide(player.getLoc(), building.getBounds())) + continue; + + for (Regions region : building.getBounds().getRegions()) { + + if (!region.isPointInPolygon(player.getLoc())) + continue; + + if (!region.isOutside()) + continue; + if (tempRegion == null) + tempRegion = region; + + if (tempRegion.highLerp.y < region.highLerp.y) + tempRegion = region; + } + + if (tempRegion != null) + break; + } + return tempRegion; + } + + public static boolean CanFly(AbstractCharacter flyer) { + boolean canFly = false; + PlayerBonuses bonus = flyer.getBonuses(); + + if (bonus != null && !bonus.getBool(ModType.NoMod, SourceType.Fly) && bonus.getBool(ModType.Fly, SourceType.None) && flyer.isAlive()) + canFly = true; + + return canFly; + + } + + public static void UpdateRegion(AbstractCharacter worldObject) { + worldObject.region = AbstractWorldObject.GetRegionByWorldObject(worldObject); + } + + public static void teleport(AbstractCharacter worldObject, final Vector3fImmutable targetLoc) { + worldObject.locationLock.writeLock().lock(); + try { + MovementManager.translocate(worldObject, targetLoc, null); + if (worldObject.getObjectType().equals(GameObjectType.PlayerCharacter)) + InterestManager.INTERESTMANAGER.HandleLoadForTeleport((PlayerCharacter) worldObject); + } catch (Exception e) { + Logger.error(e); + } finally { + worldObject.locationLock.writeLock().unlock(); + } + } + + private void initializeCharacter() { + this.timers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + this.timestamps = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + final long l = System.currentTimeMillis(); + this.timestamps.put("Health Recovery", l); + this.timestamps.put("Stamina Recovery", l); + this.timestamps.put("Mana Recovery", l); + this.recycleTimers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + } + + protected abstract ConcurrentHashMap initializePowers(); + + public final void addPersistantAoe( + final String name, + final int duration, + final PersistentAoeJob asj, + final EffectsBase eb, + final int trains + ) { + if (!isAlive()) { + return; + } + final JobContainer jc = JobScheduler.getInstance().scheduleJob(asj, duration); + final Effect eff = new Effect(jc, eb, trains); + aoecntr++; + this.effects.put(name + aoecntr, eff); + eff.setPAOE(); + } + + public final void setLastChant( + final int duration, + final ChantJob cj + ) { + if (!isAlive()) { + return; + } + if (this.lastChant != null) { + this.lastChant.cancelJob(); + } + this.lastChant = JobScheduler.getInstance().scheduleJob(cj, duration); + } + + public final void cancelLastChant() { + if (this.lastChant != null) { + this.lastChant.cancelJob(); + this.lastChant = null; + } + } + + public final void cancelLastChantIfSame(final Effect eff) { + if (eff == null || this.lastChant == null) { + return; + } + final AbstractJob aj = this.lastChant.getJob(); + if (aj == null || (!(aj instanceof ChantJob))) { + return; + } + final int token = ((ChantJob) aj).getPowerToken(); + if (eff.getPowerToken() == token && token != 0) { + this.cancelLastChant(); + } + } + + /* + * Getters + */ + public final short getUnusedStatPoints() { + return this.unusedStatPoints; + } + + public final void setUnusedStatPoints(final short value) { + this.unusedStatPoints = value; + } + + public final CharacterItemManager getCharItemManager() { + return this.charItemManager; + } + + public final void setDebug( + final int value, + final boolean toggle + ) { + if (toggle) { + this.debug |= value; //turn on debug + } else { + this.debug &= ~value; //turn off debug + } + } + + public final boolean getDebug(final int value) { + return ((this.debug & value) != 0); + } + + @Override + public String getName() { + if (this.firstName.length() == 0 && this.lastName.length() == 0) { + return "Unnamed " + '(' + this.getObjectUUID() + ')'; + } else if (this.lastName.length() == 0) { + return this.getFirstName(); + } else { + return this.getFirstName() + ' ' + this.getLastName(); + } + } + + public String getFirstName() { + return this.firstName; + } + + public void setFirstName(final String name) { + this.firstName = name; + } + + public String getLastName() { + return this.lastName; + } + + public void setLastName(final String name) { + this.lastName = name; + } + + public final short getStatStrCurrent() { + return this.statStrCurrent; + } + + public final short getStatDexCurrent() { + return this.statDexCurrent; + } + + public final short getStatConCurrent() { + return this.statConCurrent; + } + + public final short getStatIntCurrent() { + return this.statIntCurrent; + } + + public final short getStatSpiCurrent() { + return this.statSpiCurrent; + } + + public short getLevel() { + return this.level; + } + + public void setLevel(final short value) { + this.level = value; + } + + public final boolean isActive() { + return this.isActive; + } + + public final void setActive(final boolean value) { + this.isActive = value; + } + + public final Resists getResists() { + if (this.resists == null) + return Resists.getResists(0); + return this.resists; + } + + public final void setResists(final Resists value) { + this.resists = value; + } + + public final int getExp() { + return this.exp; + } + + public final void setExp(final int value) { + this.exp = value; + } + + public final JobContainer getLastPower() { + if (this.timers == null) { + return null; + } + return this.timers.get("LastPower"); + } + + public final void setLastPower(final JobContainer jc) { + if (this.timers != null) { + this.timers.put("LastPower", jc); + } + } + + public final void clearLastPower() { + if (this.timers != null) { + this.timers.remove("LastPower"); + } + } + + public final JobContainer getLastItem() { + if (this.timers == null) { + return null; + } + return this.timers.get("LastItem"); + } + + public final void setLastItem(final JobContainer jc) { + if (this.timers != null) { + this.timers.put("LastItem", jc); + } + } + + public final void clearLastItem() { + if (this.timers != null) { + this.timers.remove("LastItem"); + } + } + + public final int getIsSittingAsInt() { + if (!this.isAlive()) { + return 1; + } + + if (this.sit) { + return 4; + } else { + if (this.isMoving()) + return 7; + else + return 5; + } + } + + public final int getIsWalkingAsInt() { + if (this.walkMode) { + return 1; + } + return 2; + } + + public final int getIsCombatAsInt() { + if (this.combat) { + return 2; + } + return 1; + } + + public final int getIsFlightAsInt() { + if (this.altitude > 0) { + return 3; + } + + if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) + if (((PlayerCharacter) this).isLastSwimming()) + return 1; //swimming + + return 2; //ground + } + + public final void clearTimer(final String name) { + if (this.timers != null) { + this.timers.remove(name); + } + } + + public abstract Vector3fImmutable getBindLoc(); + + public final void setBindLoc(final Vector3fImmutable value) { + this.bindLoc = value; + } + + public final Vector3fImmutable getFaceDir() { + return this.faceDir; + } + + public final void setFaceDir(final Vector3fImmutable value) { + this.faceDir = value; + } + + public final Vector3fImmutable getStartLoc() { + return this.startLoc; + } + + public final Vector3fImmutable getEndLoc() { + return this.endLoc; + } + + public final void setEndLoc(final Vector3fImmutable value) { + if (value.x > MBServerStatics.MAX_PLAYER_X_LOC) + return; + if (value.z < MBServerStatics.MAX_PLAYER_Y_LOC) + return; + + this.endLoc = value; + // reset the location timer so our next call to getLoc is correct + this.resetLastSetLocUpdate(); + } + + public final Vector3fImmutable getNextEndLoc() { + // this is only used when users are changing their end + // location while a timer like changeAltitude is ticking down + return this.nextEndLoc; + } + + public final void stopMovement(Vector3fImmutable stopLoc) { + + + locationLock.writeLock().lock(); + + try { + this.setLoc(stopLoc); + this.endLoc = Vector3fImmutable.ZERO; + this.resetLastSetLocUpdate(); + } catch (Exception e) { + Logger.error(e); + } finally { + locationLock.writeLock().unlock(); + } + } + + public final boolean isMoving() { + + // I might be on my way but my movement is paused + // due to a flight alt change + //TODO who the fuck wrote changeHeightJob. FIX THIS. + + + if (this.endLoc.equals(Vector3fImmutable.ZERO) || this.endLoc.equals(this.bindLoc)) + return false; + + if (this.takeOffTime != 0) + return false; + + if (this.isCasting && this.getObjectType().equals(GameObjectType.PlayerCharacter)) + return false; + + return true; + } + + public final boolean useFlyMoveRegen() { + + + if (this.endLoc.x != 0 && this.endLoc.z != 0) + return true; + + return false; + } + + public boolean asciiLastName() { + return true; + } + + public final ConcurrentHashMap getSkills() { + return this.skills; + } + + public final ConcurrentHashMap getPowers() { + return this.powers; + } + + public final int getInBuilding() { + return this.inBuilding; + } + + public final void setInBuilding(final int floor) { + this.inBuilding = floor; + } + + public Guild getGuild() { + return this.guild; + } + + /* + * Setters + */ + public void setGuild(final Guild value) { + this.guild = value; + } + + public int getGuildUUID() { + return this.guild.getObjectUUID(); + } + + public final int getRank() { + return (this.level / 10); + } + + public final int getAtrHandOne() { + return this.atrHandOne; + } + + public final int getAtrHandTwo() { + return this.atrHandTwo; + } + + public final int getMinDamageHandOne() { + return this.minDamageHandOne; + } + + public final int getMaxDamageHandOne() { + return this.maxDamageHandOne; + } + + public final int getMinDamageHandTwo() { + return this.minDamageHandTwo; + } + + public final int getMaxDamageHandTwo() { + return this.maxDamageHandTwo; + } + + public final int getDefenseRating() { + return this.defenseRating; + } + + public final float getRangeHandOne() { + return this.rangeHandOne; + } + + public final float getRangeHandTwo() { + return this.rangeHandTwo; + } + + public final float getSpeedHandOne() { + return this.speedHandOne; + } + + public final float getSpeedHandTwo() { + return this.speedHandTwo; + } + + public final float getRange() { + + // Treb range does not appear to be set here + // what gives? + + + if (this.getObjectType() == GameObjectType.Mob) { + Mob mob = (Mob) this; + if (mob.isSiege()) { + return 300; + } + float range = 8; + if (((Mob) this).getEquip().get(1) != null) { + range = ((Mob) this).getEquip().get(1).getItemBase().getRange(); + } else if (((Mob) this).getEquip().get(2) != null) { + range = ((Mob) this).getEquip().get(2).getItemBase().getRange(); + } + if (range > 80) { + range = 80; + } + return range; + } + if (this.rangeHandOne > this.rangeHandTwo) { + return this.rangeHandOne; + } + return this.rangeHandTwo; + } + + public abstract float getPassiveChance( + final String type, + final int attackerLevel, + final boolean fromCombat); + + public abstract float getSpeed(); + + public final int getBankCapacityRemaining() { + return (AbstractCharacter.getBankCapacity() - this.charItemManager.getBankWeight()); + } + + public final int getVaultCapacityRemaining() { + return (AbstractCharacter.getVaultCapacity() - this.charItemManager.getVaultWeight()); + } + + public final ArrayList getInventory() { + return this.getInventory(false); + } + /* + * Utils + */ + + public final ArrayList getInventory(final boolean getGold) { + if (this.charItemManager == null) { + return new ArrayList<>(); + } + return this.charItemManager.getInventory(getGold); + } + + @Override + public Vector3fImmutable getLoc() { + + return super.getLoc(); + } + + @Override + public final void setLoc(final Vector3fImmutable value) { + super.setLoc(value); // set the location in the world + this.resetLastSetLocUpdate(); + //Logger.info("AbstractCharacter", "Setting char location to :" + value.getX() + " " + value.getZ()); + } + + public Vector3fImmutable getMovementLoc() { + + if (this.endLoc.equals(Vector3fImmutable.ZERO)) + return super.getLoc(); + if (this.takeOffTime != 0) + return super.getLoc(); + + return super.getLoc().moveTowards(this.endLoc, this.getSpeed() * ((System.currentTimeMillis() - lastSetLocUpdate) * .001f)); + + } + + public final void setBindLoc(final float x, final float y, final float z) { + this.bindLoc = new Vector3fImmutable(x, y, z); + } + + public final void resetLastSetLocUpdate() { + this.lastSetLocUpdate = System.currentTimeMillis(); + } + + public void setIsCasting(final boolean isCasting) { + this.isCasting = isCasting; + } + + public final boolean isCasting() { + return this.isCasting; + } + + @Override + public final boolean isAlive() { + return this.isAlive.get(); + } + + public final boolean isSafeMode() { + + if (this.resists == null) + return false; + + for (Effect eff : this.getEffects().values()) { + if (eff.getEffectToken() == -1661750486) + return true; + } + return this.resists.immuneToAll(); + } + + public abstract void killCharacter(final AbstractCharacter killer); + + public abstract void killCharacter(final String reason); + + /** + * Determines if the character is in a lootable state. + * + * @return True if lootable. + */ + public abstract boolean canBeLooted(); + + public float calcHitBox() { + if (this.getObjectType() == GameObjectType.PlayerCharacter) { + // hit box radius is str/100 (gets diameter of hitbox) /2 (as we want a radius) + // note this formula is guesswork + if (MBServerStatics.COMBAT_TARGET_HITBOX_DEBUG) { + Logger.info("Hit box radius for " + this.getFirstName() + " is " + (this.statStrCurrent / 200f)); + } + return ((PlayerCharacter) this).getStrForClient() / 200f; + //TODO CALCULATE MOB HITBOX BECAUSE FAIL EMU IS FAIL!!!!!!! + } else if (this.getObjectType() == GameObjectType.Mob) { + if (MBServerStatics.COMBAT_TARGET_HITBOX_DEBUG) { + Logger.info("Hit box radius for " + this.getFirstName() + " is " + ((Mob) this).getMobBase().getHitBoxRadius()); + } + return ((Mob) this).getMobBase().getHitBoxRadius(); + } + return 0f; + } + + public final boolean isSit() { + return this.sit; + } + + public final void setSit(final boolean value) { + + if (this.sit != value) { + // change sit/stand and sync location + this.sit = value; + if (value == true) // we have been told to sit + { + this.stopMovement(this.getLoc()); + } + } + + } + + public final boolean isWalk() { + return this.walkMode; + } + + public final boolean isCombat() { + return this.combat; + } + + public final void setCombat(final boolean value) { + this.combat = value; + } + + public final void setWalkMode(final boolean value) { + // sync movement location as getLoc gets where we are at the exact moment in time (i.e. not the last updated loc) + this.setLoc(this.getLoc()); + if (this.walkMode == value) { + return; + } else { + this.walkMode = value; + } + } + + public final AbstractWorldObject getCombatTarget() { + return this.combatTarget; + } + + public final void setCombatTarget(final AbstractWorldObject value) { + this.combatTarget = value; + } + + public final ConcurrentHashMap getTimers() { + if (this.timers == null) { + this.timers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + } + return this.timers; + } + + public final int getLiveCounter() { + return this.liveCounter; + } + + public final void addTimer( + final String name, + final AbstractJob asj, + final int duration + ) { + final JobContainer jc = JobScheduler.getInstance().scheduleJob(asj, duration); + if (this.timers == null) { + this.timers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + } + this.timers.put(name, jc); + } + + public final void renewTimer( + final String name, + final AbstractJob asj, + final int duration + ) { + this.cancelTimer(name); + this.addTimer(name, asj, duration); + } + + public final ConcurrentHashMap getRecycleTimers() { + return this.recycleTimers; + } + + public final ConcurrentHashMap getTimestamps() { + return this.timestamps; + } + + public final long getTimeStamp(final String name) { + if (this.timestamps.containsKey(name)) { + return this.timestamps.get(name); + } + return 0L; + } + + public final void setTimeStamp(final String name, final long value) { + this.timestamps.put(name, value); + } + + public final void setTimeStampNow(final String name) { + this.timestamps.put(name, System.currentTimeMillis()); + } + + public final void cancelTimer(final String name) { + cancelTimer(name, true); + } + + public final void cancelTimer(final String name, final boolean jobRunning) { + if (this.timers == null) { + this.timers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + } + if (this.timers.containsKey(name)) { + if (jobRunning) { + this.timers.get(name).cancelJob(); + } + this.timers.remove(name); + } + } + + public final float modifyHealth( + final float value, + final AbstractCharacter attacker, + final boolean fromCost) { + + try { + + try { + boolean ready = this.healthLock.writeLock().tryLock(1, TimeUnit.SECONDS); + + while (!ready) + ready = this.healthLock.writeLock().tryLock(1, TimeUnit.SECONDS); + + if (!this.isAlive()) + return 0; + + Float oldHealth, newHealth; + + if (!this.isAlive()) + return 0f; + + oldHealth = this.health.get(); + newHealth = oldHealth + value; + + if (newHealth > this.healthMax) + newHealth = healthMax; + + this.health.set(newHealth); + + if (newHealth <= 0) { + if (this.isAlive.compareAndSet(true, false)) { + killCharacter(attacker); + return newHealth - oldHealth; + } else + return 0f; //already dead, don't send damage again + } // past this lock! + + //TODO why is Handle REtaliate and cancelontakedamage in modifyHealth? shouldnt this be outside this method? + if (value < 0f && !fromCost) { + this.cancelOnTakeDamage(); + CombatManager.handleRetaliate(this, attacker); + } + + return newHealth - oldHealth; + } finally { + this.healthLock.writeLock().unlock(); + } + + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return 0; + } + + public float getCurrentHitpoints() { + return this.health.get(); + } + + public final float modifyMana( + final float value, + final AbstractCharacter attacker + ) { + return this.modifyMana(value, attacker, false); + } + + public final float modifyMana( + final float value, + final AbstractCharacter attacker, + final boolean fromCost + ) { + + if (!this.isAlive()) { + return 0f; + } + boolean worked = false; + Float oldMana = 0f, newMana = 0f; + while (!worked) { + oldMana = this.mana.get(); + newMana = oldMana + value; + if (newMana > this.manaMax) { + newMana = manaMax; + } else if (newMana < 0) { + newMana = 0f; + } + worked = this.mana.compareAndSet(oldMana, newMana); + } + if (value < 0f && !fromCost) { + this.cancelOnTakeDamage(); + CombatManager.handleRetaliate(this, attacker); + } + return newMana - oldMana; + } + + /* + * Serializing + */ + + public final float modifyStamina( + final float value, + final AbstractCharacter attacker + ) { + return this.modifyStamina(value, attacker, false); + } + + public final float modifyStamina( + final float value, + final AbstractCharacter attacker, + final boolean fromCost + ) { + + if (!this.isAlive()) { + return 0f; + } + boolean worked = false; + Float oldStamina = 0f, newStamina = 0f; + while (!worked) { + oldStamina = this.stamina.get(); + newStamina = oldStamina + value; + if (newStamina > this.staminaMax) { + newStamina = staminaMax; + } else if (newStamina < 0) { + newStamina = 0f; + } + worked = this.stamina.compareAndSet(oldStamina, newStamina); + } + if (value < 0f && !fromCost) { + this.cancelOnTakeDamage(); + CombatManager.handleRetaliate(this, attacker); + } + return newStamina - oldStamina; + } + + public final float setMana( + final float value, + final AbstractCharacter attacker + ) { + return setMana(value, attacker, false); + } + + public final float setMana( + final float value, + final AbstractCharacter attacker, + final boolean fromCost + ) { + + if (!this.isAlive()) { + return 0f; + } + boolean worked = false; + Float oldMana = 0f, newMana = 0f; + while (!worked) { + oldMana = this.mana.get(); + newMana = value; + if (newMana > this.manaMax) { + newMana = manaMax; + } else if (newMana < 0) { + newMana = 0f; + } + worked = this.mana.compareAndSet(oldMana, newMana); + } + if (oldMana > newMana && !fromCost) { + this.cancelOnTakeDamage(); + CombatManager.handleRetaliate(this, attacker); + } + return newMana - oldMana; + } + + public final float setStamina( + final float value, + final AbstractCharacter attacker + ) { + return setStamina(value, attacker, false); + } + + public final float setStamina( + final float value, + final AbstractCharacter attacker, + final boolean fromCost + ) { + + if (!this.isAlive()) { + return 0f; + } + boolean worked = false; + Float oldStamina = 0f, newStamina = 0f; + while (!worked) { + oldStamina = this.stamina.get(); + newStamina = value; + if (newStamina > this.staminaMax) { + newStamina = staminaMax; + } else if (newStamina < 0) { + newStamina = 0f; + } + worked = this.stamina.compareAndSet(oldStamina, newStamina); + } + if (oldStamina > newStamina && !fromCost) { + this.cancelOnTakeDamage(); + CombatManager.handleRetaliate(this, attacker); + } + return newStamina - oldStamina; + + } + + public final float getStamina() { + if (this.getObjectType() == GameObjectType.Mob) + return this.getStaminaMax(); + return this.stamina.get(); + } + + public final float getMana() { + if (this.getObjectType() == GameObjectType.Mob) + return this.getManaMax(); + return this.mana.get(); + } + + public final float getStaminaMax() { + if (this.getObjectType() == GameObjectType.Mob) + return 2000; + return this.staminaMax; + } + + public final float getManaMax() { + if (this.getObjectType() == GameObjectType.Mob) + return 2000; + return this.manaMax; + } + + public final PlayerBonuses getBonuses() { + return this.bonuses; + } + + public void teleport(final Vector3fImmutable targetLoc) { + locationLock.writeLock().lock(); + try { + MovementManager.translocate(this, targetLoc, null); + MovementManager.sendRWSSMsg(this); + } catch (Exception e) { + Logger.error(e); + } finally { + locationLock.writeLock().unlock(); + } + } + + /* + * Cancel effects upon actions + */ + public final void cancelOnAttack() { // added to one spot + + boolean changed = false; + + for (String s : this.effects.keySet()) { + + Effect eff = this.effects.get(s); + + if (eff == null) + continue; + if (eff.cancelOnAttack() && eff.cancel()) { + eff.cancelJob(); + this.effects.remove(s); + changed = true; + } + } + + if (changed) { + applyBonuses(); + } + + PowersManager.cancelOnAttack(this); + } + + public final void cancelOnAttackSwing() { // added + boolean changed = false; + for (String s : this.effects.keySet()) { + Effect eff = this.effects.get(s); + if (eff == null) + continue; + if (eff.cancelOnAttackSwing() && eff.cancel()) { + //System.out.println("canceling on AttackSwing"); + eff.cancelJob(); + this.effects.remove(s); + changed = true; + } + } + if (changed) { + applyBonuses(); + } + PowersManager.cancelOnAttackSwing(this); + } + + public final void cancelOnCast() { + boolean changed = false; + for (String s : this.effects.keySet()) { + Effect eff = this.effects.get(s); + + if (eff == null) + continue; + if (eff.cancelOnCast() && eff.cancel()) { + + // Don't cancel the track effect on the character being tracked + if (eff.getJob() != null && eff.getJob() instanceof TrackJob) { + if (((TrackJob) eff.getJob()).getSource().getObjectUUID() + == this.getObjectUUID()) { + continue; + } + } + + //System.out.println("canceling on Cast"); + eff.cancelJob(); + this.effects.remove(s); + changed = true; + } + } + if (changed) { + applyBonuses(); + } + PowersManager.cancelOnCast(this); + } + + public final void cancelOnSpell() { + boolean changed = false; + for (String s : this.effects.keySet()) { + Effect eff = this.effects.get(s); + if (eff == null) + continue; + if (eff.cancelOnCastSpell() && eff.cancel()) { + //System.out.println("canceling on CastSpell"); + eff.cancelJob(); + this.effects.remove(s); + changed = true; + } + } + if (changed) { + applyBonuses(); + } + PowersManager.cancelOnSpell(this); + } + + public final void cancelOnMove() { // added + boolean changed = false; + for (String s : this.effects.keySet()) { + Effect eff = this.effects.get(s); + if (eff == null) + continue; + if (eff.cancelOnMove() && eff.cancel()) { + //System.out.println("canceling on Move"); + eff.cancelJob(); + this.effects.remove(s); + changed = true; + } + } + if (changed) { + applyBonuses(); + } + PowersManager.cancelOnMove(this); + } + + public final void cancelOnSit() { // added + boolean changed = false; + for (String s : this.effects.keySet()) { + Effect eff = this.effects.get(s); + if (eff == null) + continue; + if (eff.cancelOnSit() && eff.cancel()) { + //System.out.println("canceling on Sit"); + eff.cancelJob(); + this.effects.remove(s); + changed = true; + } + } + if (changed) { + applyBonuses(); + } + PowersManager.cancelOnSit(this); + } + + public final void cancelOnTakeDamage() { + boolean changed = false; + for (String s : this.effects.keySet()) { + Effect eff = this.effects.get(s); + if (eff == null) + continue; + if (eff.cancelOnTakeDamage() && eff.cancel()) { + //System.out.println("canceling on Take Damage"); + eff.cancelJob(); + this.effects.remove(s); + changed = true; + } + } + if (changed) { + applyBonuses(); + } + PowersManager.cancelOnTakeDamage(this); + } + + public final void cancelOnTakeDamage(final DamageType type, final float amount) { + boolean changed = false; + for (String s : this.effects.keySet()) { + Effect eff = this.effects.get(s); + if (eff == null) + continue; + if (eff.cancelOnTakeDamage(type, amount) && eff.cancel()) { + eff.cancelJob(); + this.effects.remove(s); + changed = true; + } + } + if (changed) { + applyBonuses(); + } + } + + public final Effect getDamageAbsorber() { + for (String s : this.effects.keySet()) { + Effect eff = this.effects.get(s); + if (eff == null) + continue; + if (eff.isDamageAbsorber()) { + return eff; + } + } + return null; + } + + public final void cancelOnUnEquip() { + boolean changed = false; + for (String s : this.effects.keySet()) { + Effect eff = this.effects.get(s); + if (eff == null) + continue; + if (eff.cancelOnUnEquip() && eff.cancel()) { + //System.out.println("canceling on UnEquip"); + eff.cancelJob(); + this.effects.remove(s); + changed = true; + } + } + if (changed) { + applyBonuses(); + } + PowersManager.cancelOnUnEquip(this); + } + + public final void cancelOnStun() { + boolean changed = false; + for (String s : this.effects.keySet()) { + Effect eff = this.effects.get(s); + + if (eff == null) { + Logger.error("null effect for " + this.getObjectUUID() + " : effect " + s); + continue; + } + if (eff.cancelOnStun() && eff.cancel()) { + //System.out.println("canceling on Stun"); + eff.cancelJob(); + this.effects.remove(s); + changed = true; + } + } + if (changed) { + applyBonuses(); + } + PowersManager.cancelOnStun(this); + } + + //Call to apply any new effects to player + public synchronized void applyBonuses() { + PlayerCharacter player; + //tell the player to applyBonuses because something has changed + + //start running the bonus calculations + + try { + runBonuses(); + + // Check if calculations affected flight. + + if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) { + player = (PlayerCharacter) this; + + // Ground players who cannot fly but are currently flying + + if (CanFly(player) == false && + player.getMovementState().equals(MovementState.FLYING)) + PlayerCharacter.GroundPlayer(player); + } + + } catch (Exception e) { + Logger.error("Error in run bonuses for object UUID " + this.getObjectUUID()); + Logger.error(e); + } + } + + //Don't call this function directly. linked from ac.applyBonuses() + //through BonusCalcJob. Designed to only run from one worker thread + public final void runBonuses() { + // synchronized with getBonuses() + synchronized (this.bonuses) { + try { + //run until no new bonuses are applied + + // clear bonuses and reapply rune bonuses + if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) { + this.bonuses.calculateRuneBaseEffects((PlayerCharacter) this); + } else { + this.bonuses.clearRuneBaseEffects(); + } + + // apply effect bonuses + for (Effect eff : this.effects.values()) { + eff.applyBonus(this); + } + + //apply item bonuses for equipped items + ConcurrentHashMap equip = null; + + if (this.charItemManager != null) { + equip = this.charItemManager.getEquipped(); + } + if (equip != null) { + for (Item item : equip.values()) { + item.clearBonuses(); + if (item != null) { + ConcurrentHashMap effects = item.getEffects(); + if (effects != null) { + for (Effect eff : effects.values()) { + eff.applyBonus(item, this); + } + } + } + } + } + + //recalculate passive defenses + if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) { + ((PlayerCharacter) this).setPassives(); + } + + + // recalculate everything + if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) { + PlayerCharacter pc = (PlayerCharacter) this; + + //calculate item bonuses + pc.calculateItemBonuses(); + + //recalculate formulas + pc.recalculatePlayerStats(true); + + + } else if (this.getObjectType().equals(GameObjectType.Mob)) { + Mob mob = (Mob) this; + + //recalculate formulas + mob.recalculateStats(); + } + } catch (Exception e) { + Logger.error(e); + } + } + } + + public int getInBuildingID() { + return inBuildingID; + } + + public void setInBuildingID(int inBuildingID) { + this.inBuildingID = inBuildingID; + } + + public float getHateValue() { + if (this.hateValue <= 0) { + this.hateValue = 0; + return hateValue; + } + + if (this.lastHateUpdate == 0) { + this.lastHateUpdate = System.currentTimeMillis(); + return this.hateValue; + } + long duration = System.currentTimeMillis() - this.lastHateUpdate; + //convert duration to seconds and multiply Hate Delimiter. + float modAmount = duration / 1000 * MBServerStatics.PLAYER_HATE_DELIMITER; + this.hateValue -= modAmount; + this.lastHateUpdate = System.currentTimeMillis(); + return this.hateValue; + } + + public void setHateValue(float hateValue) { + this.lastHateUpdate = System.currentTimeMillis(); + this.hateValue = hateValue; + } + + public int getInFloorID() { + return inFloorID; + } + + public void setInFloorID(int inFloorID) { + this.inFloorID = inFloorID; + } + + public boolean isCollided() { + return collided; + } + + public void setCollided(boolean collided) { + this.collided = collided; + } + + public float getDesiredAltitude() { + return desiredAltitude; + } + + public void setDesiredAltitude(float desiredAltitude) { + this.desiredAltitude = desiredAltitude; + } + + public long getTakeOffTime() { + return takeOffTime; + } + + public void setTakeOffTime(long takeOffTime) { + this.takeOffTime = takeOffTime; + } + + public boolean isItemCasting() { + return itemCasting; + } + + public void setItemCasting(boolean itemCasting) { + this.itemCasting = itemCasting; + } + + //updates + public void update() { + } + + public void updateRegen() { + } + + public void updateMovementState() { + } + + public void updateLocation() { + } + + public void updateFlight() { + } + + public void dynamicUpdate(UpdateType updateType) { + if (this.updateLock.writeLock().tryLock()) { + try { + switch (updateType) { + case ALL: + update(); + break; + case REGEN: + updateRegen(); + break; + case LOCATION: + update(); + break; + case MOVEMENTSTATE: + update(); + break; + case FLIGHT: + updateFlight(); + break; + } + + } catch (Exception e) { + Logger.error(e); + } finally { + this.updateLock.writeLock().unlock(); + } + } + + } + + public Regions getLastRegion() { + return lastRegion; + } + + public boolean isMovingUp() { + return movingUp; + } + + public void setMovingUp(boolean movingUp) { + this.movingUp = movingUp; + } } diff --git a/src/engine/objects/AbstractGameObject.java b/src/engine/objects/AbstractGameObject.java index aad22fbf..b105cf14 100644 --- a/src/engine/objects/AbstractGameObject.java +++ b/src/engine/objects/AbstractGameObject.java @@ -24,212 +24,210 @@ import java.util.concurrent.ConcurrentHashMap; public abstract class AbstractGameObject { - private GameObjectType objectType = GameObjectType.unknown; - private int objectUUID; - - private byte ver = 1; - - private ConcurrentHashMap databaseJobs = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - - /** - * No Table ID Constructor - */ - public AbstractGameObject() { - super(); - setObjectType(); - this.objectUUID = MBServerStatics.NO_DB_ROW_ASSIGNED_YET; - } - - /** - * Normal Constructor - */ - public AbstractGameObject(int objectUUID) { - this(); - this.objectUUID = objectUUID; - } - - /** - * ResultSet Constructor - * - * @param rs - * ResultSet containing record for this object + private GameObjectType objectType = GameObjectType.unknown; + private int objectUUID; + + private byte ver = 1; + + private ConcurrentHashMap databaseJobs = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + + /** + * No Table ID Constructor + */ + public AbstractGameObject() { + super(); + setObjectType(); + this.objectUUID = MBServerStatics.NO_DB_ROW_ASSIGNED_YET; + } + + /** + * Normal Constructor + */ + public AbstractGameObject(int objectUUID) { + this(); + this.objectUUID = objectUUID; + } + + /** + * ResultSet Constructor + * + * @param rs ResultSet containing record for this object + */ + public AbstractGameObject(ResultSet rs, int objectUUID) throws SQLException { + this(); + this.objectUUID = objectUUID; + } + + /** + * ResultSet Constructor; assumes first column in ResultSet is ID + * + * @param rs ResultSet containing record for this object */ - public AbstractGameObject(ResultSet rs, int objectUUID) throws SQLException { - this(); - this.objectUUID = objectUUID; - } - - /** - * ResultSet Constructor; assumes first column in ResultSet is ID - * - * @param rs - * ResultSet containing record for this object - */ - public AbstractGameObject(ResultSet rs) throws SQLException { - this(rs, rs.getInt(1)); - } - - /* - * Getters - */ - public GameObjectType getObjectType() { - return this.objectType; - } - - protected final void setObjectType() { - try { - this.objectType = GameObjectType.valueOf(this.getClass().getSimpleName()); - } catch (SecurityException | IllegalArgumentException e) { - Logger.error("Failed to find class " + this.getClass().getSimpleName() - + " in GameObjectTypes file. Defaulting ObjectType to 0."); - } - } - - public int getObjectUUID() { - return this.objectUUID; - } - - protected void setObjectUUID(int objectUUID) { - this.objectUUID = objectUUID; - } - - public byte getVer() { - return this.ver; - } - - public void incVer() { - this.ver++; - if (this.ver == (byte)-1) //-1 reserved - this.ver++; - } - - /* - * Util - */ - - public static int extractUUID(GameObjectType type, long compositeID) { - if (type == null || type == GameObjectType.unknown || compositeID == 0L) { - return -1; - } - int out = (int) compositeID; - if (out > Long.MAX_VALUE || out < 0) { - Logger.error("There was a problem reverse calculating a UUID from a compositeID. \tcomposID: " - + compositeID + " \ttype: " + type.toString() + "\tresult: " + out); - } - return out; - } - - public static GameObjectType extractTypeID(long compositeID) { - int ordinal = (int) (compositeID >>> 32); - return GameObjectType.values()[ordinal]; - } - - public boolean equals(AbstractGameObject obj) { - - if (obj == null) - return false; + public AbstractGameObject(ResultSet rs) throws SQLException { + this(rs, rs.getInt(1)); + } + + public static int extractUUID(GameObjectType type, long compositeID) { + if (type == null || type == GameObjectType.unknown || compositeID == 0L) { + return -1; + } + int out = (int) compositeID; + if (out > Long.MAX_VALUE || out < 0) { + Logger.error("There was a problem reverse calculating a UUID from a compositeID. \tcomposID: " + + compositeID + " \ttype: " + type.toString() + "\tresult: " + out); + } + return out; + } + + public static GameObjectType extractTypeID(long compositeID) { + int ordinal = (int) (compositeID >>> 32); + return GameObjectType.values()[ordinal]; + } + + /** + * Generates a {@link PreparedStatementShared} based on the specified query. + *

+ * If {@link AbstractGameObject} Database functions will properly release + * the PreparedStatementShared upon completion. If these functions are not + * used, then {@link PreparedStatementShared#release release()} must be + * called when finished with this object. + * + * @param sql The SQL string used to generate the PreparedStatementShared + * @return {@link PreparedStatementShared} + * @throws {@link SQLException} + **/ + protected static PreparedStatementShared prepareStatement(String sql) throws SQLException { + return new PreparedStatementShared(sql); + } + + public static AbstractGameObject getFromTypeAndID(long compositeID) { + int objectTypeID = extractTypeOrdinal(compositeID); + int tableID = extractTableID(objectTypeID, compositeID); + GameObjectType objectType = GameObjectType.values()[objectTypeID]; + + switch (objectType) { + case PlayerCharacter: + return PlayerCharacter.getPlayerCharacter(tableID); + + case NPC: + return NPC.getNPC(tableID); + + case Mob: + return Mob.getMob(tableID); + + case Building: + return BuildingManager.getBuilding(tableID); + + case Guild: + return Guild.getGuild(tableID); + + case Item: + return Item.getFromCache(tableID); + + case MobLoot: + return MobLoot.getFromCache(tableID); + + default: + Logger.error("Failed to convert compositeID to AbstractGameObject. " + "Unsupported type encountered. " + + "CompositeID: " + compositeID + " ObjectType: 0x" + Integer.toHexString(objectTypeID) + " TableID: " + tableID); + } + return null; + } + + public static int extractTypeOrdinal(long compositeID) { + return (int) (compositeID >>> 32); + } + + public static int extractTableID(int type, long compositeID) { + if (type == 0 || compositeID == 0L) { + return -1; + } + return (int) compositeID; + } + + /* + * Util + */ + + /* + * Getters + */ + public GameObjectType getObjectType() { + return this.objectType; + } + + protected final void setObjectType() { + try { + this.objectType = GameObjectType.valueOf(this.getClass().getSimpleName()); + } catch (SecurityException | IllegalArgumentException e) { + Logger.error("Failed to find class " + this.getClass().getSimpleName() + + " in GameObjectTypes file. Defaulting ObjectType to 0."); + } + } + + public int getObjectUUID() { + return this.objectUUID; + } + + protected void setObjectUUID(int objectUUID) { + this.objectUUID = objectUUID; + } + + public byte getVer() { + return this.ver; + } + + public void incVer() { + this.ver++; + if (this.ver == (byte) -1) //-1 reserved + this.ver++; + } + + public boolean equals(AbstractGameObject obj) { + + if (obj == null) + return false; if (obj.objectType != this.objectType) { - return false; - } + return false; + } return obj.getObjectUUID() == this.getObjectUUID(); } - public void removeFromCache() { - DbManager.removeFromCache(this); - } - - /** - * Generates a {@link PreparedStatementShared} based on the specified query. - *

- * If {@link AbstractGameObject} Database functions will properly release - * the PreparedStatementShared upon completion. If these functions are not - * used, then {@link PreparedStatementShared#release release()} must be - * called when finished with this object. - * - * @param sql - * The SQL string used to generate the PreparedStatementShared - * @return {@link PreparedStatementShared} - * @throws {@link SQLException} - **/ - protected static PreparedStatementShared prepareStatement(String sql) throws SQLException { - return new PreparedStatementShared(sql); - } - - public ConcurrentHashMap getDatabaseJobs() { - return this.databaseJobs; - } - - public void addDatabaseJob(String type, int duration) { - DatabaseUpdateJob updateJob; - - if (databaseJobs.containsKey(type)) - return; - - updateJob = new DatabaseUpdateJob(this, type); - JobContainer jc = JobScheduler.getInstance().scheduleJob(updateJob, duration); - databaseJobs.put(type, jc); - } - - public void removeDatabaseJob(String type, boolean canceled) { - if (databaseJobs.containsKey(type)) { - if (canceled) { - JobContainer jc = databaseJobs.get(type); - if (jc != null) - jc.cancelJob(); - } - databaseJobs.remove(type); - } - } - - public static AbstractGameObject getFromTypeAndID(long compositeID) { - int objectTypeID = extractTypeOrdinal(compositeID); - int tableID = extractTableID(objectTypeID, compositeID); - GameObjectType objectType = GameObjectType.values()[objectTypeID]; - - switch (objectType) { - case PlayerCharacter: - return PlayerCharacter.getPlayerCharacter(tableID); - - case NPC: - return NPC.getNPC(tableID); - - case Mob: - return Mob.getMob(tableID); - - case Building: - return BuildingManager.getBuilding(tableID); - - case Guild: - return Guild.getGuild(tableID); - - case Item: - return Item.getFromCache(tableID); - - case MobLoot: - return MobLoot.getFromCache(tableID); - - default: - Logger.error("Failed to convert compositeID to AbstractGameObject. " + "Unsupported type encountered. " - + "CompositeID: " + compositeID + " ObjectType: 0x" + Integer.toHexString(objectTypeID) + " TableID: " + tableID); - } - return null; - } - - public static int extractTypeOrdinal(long compositeID) { - return (int) (compositeID >>> 32); - } - public static int extractTableID(int type, long compositeID) { - if (type == 0 || compositeID == 0L) { - return -1; - } - return (int) compositeID; - } + public void removeFromCache() { + DbManager.removeFromCache(this); + } + + public ConcurrentHashMap getDatabaseJobs() { + return this.databaseJobs; + } + + public void addDatabaseJob(String type, int duration) { + DatabaseUpdateJob updateJob; + + if (databaseJobs.containsKey(type)) + return; + + updateJob = new DatabaseUpdateJob(this, type); + JobContainer jc = JobScheduler.getInstance().scheduleJob(updateJob, duration); + databaseJobs.put(type, jc); + } + + public void removeDatabaseJob(String type, boolean canceled) { + if (databaseJobs.containsKey(type)) { + if (canceled) { + JobContainer jc = databaseJobs.get(type); + if (jc != null) + jc.cancelJob(); + } + databaseJobs.remove(type); + } + } + + /* + * Abstract Methods + */ - /* - * Abstract Methods - */ - - public abstract void updateDatabase(); + public abstract void updateDatabase(); } diff --git a/src/engine/objects/AbstractIntelligenceAgent.java b/src/engine/objects/AbstractIntelligenceAgent.java index 75d4e408..e9b42ff5 100644 --- a/src/engine/objects/AbstractIntelligenceAgent.java +++ b/src/engine/objects/AbstractIntelligenceAgent.java @@ -28,217 +28,214 @@ import java.util.ArrayList; public abstract class AbstractIntelligenceAgent extends AbstractCharacter { - private boolean assist = false; - private AbstractCharacter callForHelpAggro = null; - private int type = 0; //Mob: 0, Pet: 1, Guard: 2 - protected Vector3fImmutable lastBindLoc; - private boolean clearAggro = false; - - - public AbstractIntelligenceAgent(ResultSet rs) throws SQLException { - super(rs); - } - - public AbstractIntelligenceAgent(ResultSet rs, boolean isPlayer) - throws SQLException { - super(rs, isPlayer); - } - - - public AbstractIntelligenceAgent(ResultSet rs, - int UUID) throws SQLException { - super(rs, UUID); - } - - public AbstractIntelligenceAgent( String firstName, - String lastName, short statStrCurrent, short statDexCurrent, - short statConCurrent, short statIntCurrent, short statSpiCurrent, - short level, int exp, boolean sit, boolean walk, boolean combat, - Vector3fImmutable bindLoc, Vector3fImmutable currentLoc, Vector3fImmutable faceDir, - short healthCurrent, short manaCurrent, short stamCurrent, - Guild guild, byte runningTrains) { - super(firstName, lastName, statStrCurrent, statDexCurrent, statConCurrent, - statIntCurrent, statSpiCurrent, level, exp, bindLoc, - currentLoc, faceDir, guild, - runningTrains); - } - - public AbstractIntelligenceAgent(String firstName, - String lastName, short statStrCurrent, short statDexCurrent, - short statConCurrent, short statIntCurrent, short statSpiCurrent, - short level, int exp, boolean sit, boolean walk, boolean combat, - Vector3fImmutable bindLoc, Vector3fImmutable currentLoc, Vector3fImmutable faceDir, - short healthCurrent, short manaCurrent, short stamCurrent, - Guild guild, byte runningTrains, int newUUID) { - super(firstName, lastName, statStrCurrent, statDexCurrent, statConCurrent, - statIntCurrent, statSpiCurrent, level, exp, bindLoc, - currentLoc, faceDir, guild, - runningTrains, newUUID); - } - - @Override - public void setObjectTypeMask(int mask) { - mask |= MBServerStatics.MASK_IAGENT; - super.setObjectTypeMask(mask); - } - - /* AI Job Management */ - - public MobBase getMobBase() { - - if (this.getObjectType().equals(GameObjectType.Mob)) - return this.getMobBase(); - return null; - } - - public void setCallForHelpAggro(AbstractCharacter ac) { - this.callForHelpAggro = ac; - } - - public AbstractCharacter getCallForHelpAggro() { - return callForHelpAggro; - } - - public void setMob() { - this.type = 0; - } - - public void setPet(PlayerCharacter owner, boolean summoned) { - if (summoned) - this.type = 1; //summoned - else - this.type = 2; //charmed - if (this.getObjectType().equals(GameObjectType.Mob)) { - ((Mob)this).setOwner(owner); - } - } - - public void setGuard() { - this.type = 3; - } - - public boolean isMob() { - return (this.type == 0); - } - - public boolean isPet() { - return (this.type == 1 || this.type == 2); - } - - public boolean isSummonedPet() { - return (this.type == 1); - } - - public boolean isCharmedPet() { - return (this.type == 2); - } - - public boolean isGuard() { - return (this.type == 3); - } - - public boolean assist() { - return this.assist; - } - - public void setAssist(boolean value) { - this.assist = value; - } - - public void toggleAssist() { - this.assist = (this.assist) ? false : true; - } - - public int getDBID() { - - if (this.getObjectType().equals(GameObjectType.Mob)) - return this.getDBID(); - return 0; - } - - public boolean clearAggro() { - return clearAggro; - } - - public void setClearAggro(boolean value) { - this.clearAggro = value; - } - - public Vector3fImmutable getLastBindLoc() { - if (this.lastBindLoc == null) - this.lastBindLoc = this.getBindLoc(); - return this.lastBindLoc; - } - - public PlayerCharacter getOwner() { - - if (this .getObjectType().equals(GameObjectType.Mob)) - return this.getOwner(); - return null; - } - - public boolean getSafeZone() { - ArrayListallIn = ZoneManager.getAllZonesIn(this.getLoc()); - for (Zone zone : allIn) { - if (zone.getSafeZone() == (byte)1) - return true; - } - return false; - //return this.safeZone; - } - - public abstract AbstractWorldObject getFearedObject(); - - public float getAggroRange() { - float ret = MobileFSMManager.AI_BASE_AGGRO_RANGE; - if (this.bonuses != null) - ret *= (1 +this.bonuses.getFloatPercentAll(ModType.ScanRange, SourceType.None)); - return ret; - } - - public void dismiss() { - - if (this.isPet()) { - - if (this.isSummonedPet()) { //delete summoned pet - - WorldGrid.RemoveWorldObject(this); - if (this.getObjectType() == GameObjectType.Mob){ + protected Vector3fImmutable lastBindLoc; + private boolean assist = false; + private AbstractCharacter callForHelpAggro = null; + private int type = 0; //Mob: 0, Pet: 1, Guard: 2 + private boolean clearAggro = false; + + + public AbstractIntelligenceAgent(ResultSet rs) throws SQLException { + super(rs); + } + + public AbstractIntelligenceAgent(ResultSet rs, boolean isPlayer) + throws SQLException { + super(rs, isPlayer); + } + + + public AbstractIntelligenceAgent(ResultSet rs, + int UUID) throws SQLException { + super(rs, UUID); + } + + public AbstractIntelligenceAgent(String firstName, + String lastName, short statStrCurrent, short statDexCurrent, + short statConCurrent, short statIntCurrent, short statSpiCurrent, + short level, int exp, boolean sit, boolean walk, boolean combat, + Vector3fImmutable bindLoc, Vector3fImmutable currentLoc, Vector3fImmutable faceDir, + short healthCurrent, short manaCurrent, short stamCurrent, + Guild guild, byte runningTrains) { + super(firstName, lastName, statStrCurrent, statDexCurrent, statConCurrent, + statIntCurrent, statSpiCurrent, level, exp, bindLoc, + currentLoc, faceDir, guild, + runningTrains); + } + + public AbstractIntelligenceAgent(String firstName, + String lastName, short statStrCurrent, short statDexCurrent, + short statConCurrent, short statIntCurrent, short statSpiCurrent, + short level, int exp, boolean sit, boolean walk, boolean combat, + Vector3fImmutable bindLoc, Vector3fImmutable currentLoc, Vector3fImmutable faceDir, + short healthCurrent, short manaCurrent, short stamCurrent, + Guild guild, byte runningTrains, int newUUID) { + super(firstName, lastName, statStrCurrent, statDexCurrent, statConCurrent, + statIntCurrent, statSpiCurrent, level, exp, bindLoc, + currentLoc, faceDir, guild, + runningTrains, newUUID); + } + + @Override + public void setObjectTypeMask(int mask) { + mask |= MBServerStatics.MASK_IAGENT; + super.setObjectTypeMask(mask); + } + + /* AI Job Management */ + + public MobBase getMobBase() { + + if (this.getObjectType().equals(GameObjectType.Mob)) + return this.getMobBase(); + return null; + } + + public AbstractCharacter getCallForHelpAggro() { + return callForHelpAggro; + } + + public void setCallForHelpAggro(AbstractCharacter ac) { + this.callForHelpAggro = ac; + } + + public void setMob() { + this.type = 0; + } + + public void setPet(PlayerCharacter owner, boolean summoned) { + if (summoned) + this.type = 1; //summoned + else + this.type = 2; //charmed + if (this.getObjectType().equals(GameObjectType.Mob)) { + ((Mob) this).setOwner(owner); + } + } + + public void setGuard() { + this.type = 3; + } + + public boolean isMob() { + return (this.type == 0); + } + + public boolean isPet() { + return (this.type == 1 || this.type == 2); + } + + public boolean isSummonedPet() { + return (this.type == 1); + } + + public boolean isCharmedPet() { + return (this.type == 2); + } + + public boolean isGuard() { + return (this.type == 3); + } + + public boolean assist() { + return this.assist; + } + + public void setAssist(boolean value) { + this.assist = value; + } + + public void toggleAssist() { + this.assist = (this.assist) ? false : true; + } + + public int getDBID() { + + if (this.getObjectType().equals(GameObjectType.Mob)) + return this.getDBID(); + return 0; + } + + public boolean clearAggro() { + return clearAggro; + } + + public void setClearAggro(boolean value) { + this.clearAggro = value; + } + + public Vector3fImmutable getLastBindLoc() { + if (this.lastBindLoc == null) + this.lastBindLoc = this.getBindLoc(); + return this.lastBindLoc; + } + + public PlayerCharacter getOwner() { + + if (this.getObjectType().equals(GameObjectType.Mob)) + return this.getOwner(); + return null; + } + + public boolean getSafeZone() { + ArrayList allIn = ZoneManager.getAllZonesIn(this.getLoc()); + for (Zone zone : allIn) { + if (zone.getSafeZone() == (byte) 1) + return true; + } + return false; + //return this.safeZone; + } + + public abstract AbstractWorldObject getFearedObject(); + + public float getAggroRange() { + float ret = MobileFSMManager.AI_BASE_AGGRO_RANGE; + if (this.bonuses != null) + ret *= (1 + this.bonuses.getFloatPercentAll(ModType.ScanRange, SourceType.None)); + return ret; + } + + public void dismiss() { + + if (this.isPet()) { + + if (this.isSummonedPet()) { //delete summoned pet + + WorldGrid.RemoveWorldObject(this); + if (this.getObjectType() == GameObjectType.Mob) { //((Mob)this).state = STATE.Disabled; - if (((Mob)this).getParentZone() != null) - ((Mob)this).getParentZone().zoneMobSet.remove(this); - } - - } else { //revert charmed pet - this.setMob(); - this.setCombatTarget(null); - // if (this.isAlive()) - // WorldServer.updateObject(this); - } - //clear owner - PlayerCharacter owner = this.getOwner(); - - //close pet window - if (owner != null) { - Mob pet = owner.getPet(); - PetMsg pm = new PetMsg(5, null); - Dispatch dispatch = Dispatch.borrow(owner, pm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - if (pet != null && pet.getObjectUUID() == this.getObjectUUID()) - owner.setPet(null); - - if (this.getObjectType().equals(GameObjectType.Mob)) - ((Mob)this).setOwner(null); - } - - - } - } - - - - - + if (((Mob) this).getParentZone() != null) + ((Mob) this).getParentZone().zoneMobSet.remove(this); + } + + } else { //revert charmed pet + this.setMob(); + this.setCombatTarget(null); + // if (this.isAlive()) + // WorldServer.updateObject(this); + } + //clear owner + PlayerCharacter owner = this.getOwner(); + + //close pet window + if (owner != null) { + Mob pet = owner.getPet(); + PetMsg pm = new PetMsg(5, null); + Dispatch dispatch = Dispatch.borrow(owner, pm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + if (pet != null && pet.getObjectUUID() == this.getObjectUUID()) + owner.setPet(null); + + if (this.getObjectType().equals(GameObjectType.Mob)) + ((Mob) this).setOwner(null); + } + + + } + } + + } diff --git a/src/engine/objects/AbstractWorldObject.java b/src/engine/objects/AbstractWorldObject.java index 99d3ec98..8856af1d 100644 --- a/src/engine/objects/AbstractWorldObject.java +++ b/src/engine/objects/AbstractWorldObject.java @@ -39,596 +39,587 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; public abstract class AbstractWorldObject extends AbstractGameObject { - private String name = ""; - - protected final ReadWriteLock locationLock = new ReentrantReadWriteLock(true); - protected final ReadWriteLock updateLock = new ReentrantReadWriteLock(true); - - protected Vector3fImmutable loc = new Vector3fImmutable(0.0f, 0.0f, 0.0f); - private byte tier = 0; - private Vector3f rot = new Vector3f(0.0f, 0.0f, 0.0f); - protected AtomicFloat health = new AtomicFloat(); - public float healthMax; - protected boolean load = true; - public ConcurrentHashMap effects = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private int objectTypeMask = 0; - private Bounds bounds; - - public int gridX = -1; - public int gridZ = -1; - - protected GridObjectType gridObjectType; - - protected float altitude = 0; - public Regions region; - protected boolean movingUp = false; - public Regions landingRegion = null; - public Vector3fImmutable lastLoc = Vector3fImmutable.ZERO; - - /** - * No Id Constructor - */ - public AbstractWorldObject() { - super(); - } - - /** - * Normal Constructor - */ - public AbstractWorldObject(int objectUUID) { - super(objectUUID); - } - - - /** - * ResultSet Constructor - */ - public AbstractWorldObject(ResultSet rs) throws SQLException { - super(rs); - } - - //this should be called to handle any after load functions. - public abstract void runAfterLoad(); - - /* - * Getters - */ - public float getHealth() { - - - return this.health.get(); - - } - public float getCurrentHitpoints(){ - return this.health.get(); - } - - public float getHealthMax() { - return this.healthMax; - } - - public ConcurrentHashMap getEffects() { - return this.effects; - } - - //Add new effect - public void addEffect(String name, int duration, AbstractScheduleJob asj, EffectsBase eb, int trains) { - - if (!isAlive() && eb.getToken() != 1672601862) { - return; - } - JobContainer jc = JobScheduler.getInstance().scheduleJob(asj, duration); - Effect eff = new Effect(jc, eb, trains); - this.effects.put(name, eff); - applyAllBonuses(); - } - - public Effect addEffectNoTimer(String name, EffectsBase eb, int trains, boolean isStatic) { - NoTimeJob ntj = new NoTimeJob(this, name, eb, trains); //infinite timer - - if (this.getObjectType() == GameObjectType.Item || this.getObjectType() == GameObjectType.City){ - ntj.setEffectSourceType(this.getObjectType().ordinal()); - ntj.setEffectSourceID(this.getObjectUUID()); - } - - JobContainer jc = new JobContainer(ntj); - Effect eff = new Effect(jc, eb, trains); - if (isStatic) - eff.setIsStatic(isStatic); - this.effects.put(name, eff); - applyAllBonuses(); - return eff; - } - - //called when an effect runs it's course - public void endEffect(String name) { - - Effect eff = this.effects.get(name); - if (eff == null) { - return; - } - if (!isAlive() && eff.getEffectsBase().getToken() != 1672601862) { - return; - } - - if (eff.cancel()) { - - eff.endEffect(); - this.effects.remove(name); - if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) - if (name.equals("Flight")){ - ((PlayerCharacter)this).update(); - PlayerCharacter.GroundPlayer((PlayerCharacter)this); - } - } - applyAllBonuses(); - } - - public void endEffectNoPower(String name) { - - Effect eff = this.effects.get(name); - if (eff == null) { - return; - } - if (!isAlive() && eff.getEffectsBase().getToken() != 1672601862) { - return; - } - - if (eff.cancel()) { - eff.cancelJob(); - eff.endEffectNoPower(); - this.effects.remove(name); - } - applyAllBonuses(); - } - - //Called to cancel an effect prematurely. - public void cancelEffect(String name, boolean overwrite) { - - Effect eff = this.effects.get(name); - if (eff == null) { - return; - } - if (!isAlive() && eff.getEffectsBase().getToken() != 1672601862) { - return; - } - - if (eff.cancel()) { - eff.cancelJob(); - this.effects.remove(name); - if (AbstractWorldObject.IsAbstractCharacter(this)) { - ((AbstractCharacter) this).cancelLastChantIfSame(eff); - } - } - if (!overwrite) { - applyAllBonuses(); - } - } - - //Called when an object dies/is destroyed - public void clearEffects() { - for (String name : this.effects.keySet()) { - Effect eff = this.effects.get(name); - if (eff == null) { - return; - } - - //Dont remove deathshroud here! - if (eff.getEffectToken() == 1672601862) - continue; - - if (eff.cancel()) { - if (eff.getPower() == null) { - if (!eff.isStatic()) - eff.endEffectNoPower(); - } - if (!eff.isStatic()) - eff.cancelJob(); - } - - this.effects.remove(name); - } - if (AbstractWorldObject.IsAbstractCharacter(this)) { - ((AbstractCharacter) this).cancelLastChant(); - } - applyAllBonuses(); - } - - public void removeEffectBySource(EffectSourceType source, int trains, boolean removeAll) { - if (!isAlive() && source.equals(EffectSourceType.DeathShroud) == false) { - return; - } - - //hacky way to dispell trebs. - if (this.getObjectType() == GameObjectType.Mob){ - Mob mob = (Mob)this; - if (mob.isSiege()){ - if (mob.isPet()){ - PlayerCharacter petOwner = mob.getOwner(); - if (petOwner != null && source.equals(EffectSourceType.Effect)){ - petOwner.dismissPet(); - return; - } - } - } - } - boolean changed = false; - String toRemove = ""; - int toRemoveToken = Integer.MAX_VALUE; - for (String name : this.effects.keySet()) { - Effect eff = this.effects.get(name); - if (eff == null) { - continue; - } - if (eff.containsSource(source) && trains >= eff.getTrains()) { - if (removeAll) { - //remove all effects of source type - if (eff.cancel()) { - eff.cancelJob(); - } - this.effects.remove(name); - changed = true; - - if (source.equals("Flight")){ - //ground player - if (this.getObjectType().equals(GameObjectType.PlayerCharacter)){ - ((PlayerCharacter)this).update(); - PlayerCharacter.GroundPlayer((PlayerCharacter)this); - } - } - } else { - //find lowest token of source type to remove - int tok = eff.getEffectToken(); - if (tok != 0 && tok < toRemoveToken) { - toRemove = name; - toRemoveToken = tok; - } - } - } - } - - //WTF IS THIS? - if (toRemoveToken < Integer.MAX_VALUE && this.effects.containsKey(toRemove)) { - //remove lowest found token of source type - Effect eff = this.effects.get(toRemove); - if (eff != null) { - changed = true; - if (eff.cancel()) { - eff.cancelJob(); - } - this.effects.remove(toRemove); - - if (source.equals("Flight")){ - //ground player - if (this.getObjectType().equals(GameObjectType.PlayerCharacter)){ - ((PlayerCharacter)this).update(); - PlayerCharacter.GroundPlayer((PlayerCharacter)this); - } - } - - } - } - if (changed) { - applyAllBonuses(); - } - } - - public void sendAllEffects(ClientConnection cc) { - UpdateEffectsMsg msg = new UpdateEffectsMsg(this); - Dispatch dispatch = Dispatch.borrow((PlayerCharacter)this, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - } - - public void applyAllBonuses() { - if (AbstractWorldObject.IsAbstractCharacter(this)) { - ((AbstractCharacter) this).applyBonuses(); - } - } - - public JobContainer getEffectJobContainer(String name) { - Effect ef = this.effects.get(name); - if (ef != null) { - return ef.getJobContainer(); - } - return null; - } - - public AbstractScheduleJob getEffectJob(String name) { - Effect ef = this.effects.get(name); - if (ef == null) { - return null; - } - JobContainer jc = ef.getJobContainer(); - if (jc != null) { - return (AbstractScheduleJob) jc.getJob(); - } - return null; - } - - public boolean containsEffect(int token) { - for (Effect eff : this.effects.values()) { - if (eff != null) { - if (eff.getEffectsBase() != null) { - if (eff.getEffectsBase().getToken() == token) { - return true; - } - } - } - } - return false; - } - - public int getObjectTypeMask() { - return objectTypeMask; - } - - - public Vector3fImmutable getLoc() { - return this.loc; - } - - public Vector3f getRot() { - return rot; - } - - public byte getTier() { - return tier; - } - - public boolean isAlive() { - if (AbstractWorldObject.IsAbstractCharacter(this)) { - return this.isAlive(); - } else if (this.getObjectType().equals(GameObjectType.Building)) { - return (!(((Building) this).getRank() < 0)); - } else { - return true; - } - } - - /* - * Setters - */ - public void setObjectTypeMask(int mask) { - this.objectTypeMask = mask; - } - - //TODO return false if something goes wrong? resync player? - public void setLoc(Vector3fImmutable loc) { - locationLock.writeLock().lock(); - try { - if (Float.isNaN(loc.x) || Float.isNaN(loc.z)) - return; - - if (loc.equals(Vector3fImmutable.ZERO)) - return; - - if (loc.x > MBServerStatics.MAX_WORLD_WIDTH || loc.z < MBServerStatics.MAX_WORLD_HEIGHT) - return; - this.lastLoc = new Vector3fImmutable(this.loc); - this.loc = loc; - this.loc = this.loc.setY(HeightMap.getWorldHeight(this) + this.getAltitude()); - - //lets not add mob to world grid if he is currently despawned. - if (this.getObjectType().equals(GameObjectType.Mob) && ((Mob)this).despawned) - return; - - //do not add objectUUID 0 to world grid. dunno da fuck this doing why its doing but its doing... da fuck. - if (this.getObjectUUID() == 0) - return; - WorldGrid.addObject(this,loc.x,loc.z); - - }catch(Exception e){ - Logger.error("Failed to set location for World Object. Type = " + this.getObjectType().name() + " : Name = " + this.getName()); - e.printStackTrace(); - } finally { - locationLock.writeLock().unlock(); - } - - } - - public void setY(float y){ - this.loc = this.loc.setY(y); - } - - - public void setRot(Vector3f rotation) { - synchronized (this.rot) { - this.rot = rotation; - } - } - - public void setTier(byte tier) { - synchronized (this.rot) { - this.tier = tier; - } - } - - public static int getType() { - return 0; - } - - public boolean load() { - return this.load; - } - - /* - * Utils - */ - public String getName() { - if (this.name.length() == 0) { - return "Unnamed " + '(' - + this.getObjectUUID() + ')'; - } else { - return this.name; - } - } - - public String getSimpleName() { - return this.name; - } - - - /** - * @return the bounds - */ - public Bounds getBounds() { - return bounds; - } - - public void setBounds(Bounds bounds) { - - this.bounds = bounds; - } - - /** - * @param health the health to set - */ - public void setHealth(float health) { - - this.health.set(health); - } - - public static boolean IsAbstractCharacter(AbstractWorldObject awo){ - - if (awo == null) - return false; - - if (awo.getObjectType() == GameObjectType.PlayerCharacter || awo.getObjectType() == GameObjectType.Mob || awo.getObjectType() == GameObjectType.NPC) - return true; - return false; - } - - public static void RemoveFromWorldGrid(AbstractWorldObject gridObjectToRemove){ - if (gridObjectToRemove.gridX < 0 || gridObjectToRemove.gridZ < 0) - return; - - ConcurrentHashMap gridMap; - switch(gridObjectToRemove.gridObjectType){ - case STATIC: - gridMap = WorldGrid.StaticGridMap[gridObjectToRemove.gridX][gridObjectToRemove.gridZ]; - break; - case DYNAMIC: - gridMap = WorldGrid.DynamicGridMap[gridObjectToRemove.gridX][gridObjectToRemove.gridZ]; - break; - default: - gridMap = WorldGrid.StaticGridMap[gridObjectToRemove.gridX][gridObjectToRemove.gridZ]; - break; - - } - - if (gridMap == null){ - Logger.info("Null gridmap for Object UUD: " + gridObjectToRemove); - return; - } - - - - - gridMap.remove(gridObjectToRemove.getObjectUUID()); - gridObjectToRemove.gridX = -1; - gridObjectToRemove.gridZ = -1; - - } - - public static boolean AddToWorldGrid(AbstractWorldObject gridObjectToAdd, int x, int z){ - try{ - - ConcurrentHashMap gridMap; + protected 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); + public int gridX = -1; + public int gridZ = -1; + public Regions region; + public Regions landingRegion = null; + public Vector3fImmutable lastLoc = Vector3fImmutable.ZERO; + protected Vector3fImmutable loc = new Vector3fImmutable(0.0f, 0.0f, 0.0f); + protected AtomicFloat health = new AtomicFloat(); + protected boolean load = true; + protected GridObjectType gridObjectType; + protected float altitude = 0; + protected boolean movingUp = false; + private String name = ""; + private byte tier = 0; + private Vector3f rot = new Vector3f(0.0f, 0.0f, 0.0f); + private int objectTypeMask = 0; + private Bounds bounds; + + /** + * No Id Constructor + */ + public AbstractWorldObject() { + super(); + } + + /** + * Normal Constructor + */ + public AbstractWorldObject(int objectUUID) { + super(objectUUID); + } + + + /** + * ResultSet Constructor + */ + public AbstractWorldObject(ResultSet rs) throws SQLException { + super(rs); + } + + public static int getType() { + return 0; + } + + public static boolean IsAbstractCharacter(AbstractWorldObject awo) { + + if (awo == null) + return false; + + if (awo.getObjectType() == GameObjectType.PlayerCharacter || awo.getObjectType() == GameObjectType.Mob || awo.getObjectType() == GameObjectType.NPC) + return true; + return false; + } + + public static void RemoveFromWorldGrid(AbstractWorldObject gridObjectToRemove) { + if (gridObjectToRemove.gridX < 0 || gridObjectToRemove.gridZ < 0) + return; + + ConcurrentHashMap gridMap; + switch (gridObjectToRemove.gridObjectType) { + case STATIC: + gridMap = WorldGrid.StaticGridMap[gridObjectToRemove.gridX][gridObjectToRemove.gridZ]; + break; + case DYNAMIC: + gridMap = WorldGrid.DynamicGridMap[gridObjectToRemove.gridX][gridObjectToRemove.gridZ]; + break; + default: + gridMap = WorldGrid.StaticGridMap[gridObjectToRemove.gridX][gridObjectToRemove.gridZ]; + break; + + } + + if (gridMap == null) { + Logger.info("Null gridmap for Object UUD: " + gridObjectToRemove); + return; + } + + + gridMap.remove(gridObjectToRemove.getObjectUUID()); + gridObjectToRemove.gridX = -1; + gridObjectToRemove.gridZ = -1; + + } + + public static boolean AddToWorldGrid(AbstractWorldObject gridObjectToAdd, int x, int z) { + try { + + ConcurrentHashMap gridMap; if (gridObjectToAdd.gridObjectType.equals(GridObjectType.STATIC)) - gridMap = WorldGrid.StaticGridMap[x][z]; - else - gridMap = WorldGrid.DynamicGridMap[x][z]; - - gridMap.put(gridObjectToAdd.getObjectUUID(),gridObjectToAdd); - gridObjectToAdd.gridX = x; - gridObjectToAdd.gridZ = z; - return true; - }catch(Exception e){ - Logger.error(e); - return false; - } - - } - - public static Regions GetRegionByWorldObject(AbstractWorldObject worldObject){ - Regions region = null; - - if (worldObject.getObjectType().equals(GameObjectType.PlayerCharacter)) - if (((PlayerCharacter)worldObject).isFlying()) - return null; - //Find building - for (AbstractWorldObject awo:WorldGrid.getObjectsInRangePartial(worldObject.getLoc(), MBServerStatics.STRUCTURE_LOAD_RANGE, MBServerStatics.MASK_BUILDING)){ - Building building = (Building)awo; - if (!Bounds.collide(worldObject.getLoc(), building.getBounds())) - continue; - - //find regions that intersect x and z, check if object can enter. - for (Regions toEnter: building.getBounds().getRegions()){ - if (toEnter.isPointInPolygon(worldObject.getLoc())){ - if (Regions.CanEnterRegion(worldObject, toEnter)) - if (region == null) - region = toEnter; - else // we're using a low level to high level tree structure, database not always in order low to high. - //check for highest level index. - if(region != null && toEnter.highLerp.y > region.highLerp.y) - region = toEnter; - - - } - } - } - - //set players new altitude to region lerp altitude. - if (region != null) - if (region.center.y == region.highLerp.y) - worldObject.loc = worldObject.loc.setY(region.center.y + worldObject.getAltitude()); - else - worldObject.loc = worldObject.loc.setY(region.lerpY(worldObject) + worldObject.getAltitude()); - - return region; - } - - public static Regions GetRegionFromBuilding(Vector3fImmutable worldLoc, Building building){ - Regions region = null; - - - return region; - } - - public float getAltitude() { - return altitude; - } - - - public ReadWriteLock getUpdateLock() { - return updateLock; - } - - public GridObjectType getGridObjectType() { - return gridObjectType; - } - - - public boolean isMovingUp() { - return movingUp; - } - - public void setMovingUp(boolean movingUp) { - this.movingUp = movingUp; - } - - public void setRegion(Regions region) { - this.region = region; - } - - //used for interestmanager loading and unloading objects to client. - // if not in grid, unload from player. - public boolean isInWorldGrid(){ - if (this.gridX == -1 && this.gridZ == -1) - return false; - - return true; - } - + gridMap = WorldGrid.StaticGridMap[x][z]; + else + gridMap = WorldGrid.DynamicGridMap[x][z]; + + gridMap.put(gridObjectToAdd.getObjectUUID(), gridObjectToAdd); + gridObjectToAdd.gridX = x; + gridObjectToAdd.gridZ = z; + return true; + } catch (Exception e) { + Logger.error(e); + return false; + } + + } + + public static Regions GetRegionByWorldObject(AbstractWorldObject worldObject) { + Regions region = null; + + if (worldObject.getObjectType().equals(GameObjectType.PlayerCharacter)) + if (((PlayerCharacter) worldObject).isFlying()) + return null; + //Find building + for (AbstractWorldObject awo : WorldGrid.getObjectsInRangePartial(worldObject.getLoc(), MBServerStatics.STRUCTURE_LOAD_RANGE, MBServerStatics.MASK_BUILDING)) { + Building building = (Building) awo; + if (!Bounds.collide(worldObject.getLoc(), building.getBounds())) + continue; + + //find regions that intersect x and z, check if object can enter. + for (Regions toEnter : building.getBounds().getRegions()) { + if (toEnter.isPointInPolygon(worldObject.getLoc())) { + if (Regions.CanEnterRegion(worldObject, toEnter)) + if (region == null) + region = toEnter; + else // we're using a low level to high level tree structure, database not always in order low to high. + //check for highest level index. + if (region != null && toEnter.highLerp.y > region.highLerp.y) + region = toEnter; + + + } + } + } + + //set players new altitude to region lerp altitude. + if (region != null) + if (region.center.y == region.highLerp.y) + worldObject.loc = worldObject.loc.setY(region.center.y + worldObject.getAltitude()); + else + worldObject.loc = worldObject.loc.setY(region.lerpY(worldObject) + worldObject.getAltitude()); + + return region; + } + + public static Regions GetRegionFromBuilding(Vector3fImmutable worldLoc, Building building) { + Regions region = null; + + + return region; + } + + //this should be called to handle any after load functions. + public abstract void runAfterLoad(); + + /* + * Getters + */ + public float getHealth() { + + + return this.health.get(); + + } + + /** + * @param health the health to set + */ + public void setHealth(float health) { + + this.health.set(health); + } + + public float getCurrentHitpoints() { + return this.health.get(); + } + + public float getHealthMax() { + return this.healthMax; + } + + public ConcurrentHashMap getEffects() { + return this.effects; + } + + //Add new effect + public void addEffect(String name, int duration, AbstractScheduleJob asj, EffectsBase eb, int trains) { + + if (!isAlive() && eb.getToken() != 1672601862) { + return; + } + JobContainer jc = JobScheduler.getInstance().scheduleJob(asj, duration); + Effect eff = new Effect(jc, eb, trains); + this.effects.put(name, eff); + applyAllBonuses(); + } + + public Effect addEffectNoTimer(String name, EffectsBase eb, int trains, boolean isStatic) { + NoTimeJob ntj = new NoTimeJob(this, name, eb, trains); //infinite timer + + if (this.getObjectType() == GameObjectType.Item || this.getObjectType() == GameObjectType.City) { + ntj.setEffectSourceType(this.getObjectType().ordinal()); + ntj.setEffectSourceID(this.getObjectUUID()); + } + + JobContainer jc = new JobContainer(ntj); + Effect eff = new Effect(jc, eb, trains); + if (isStatic) + eff.setIsStatic(isStatic); + this.effects.put(name, eff); + applyAllBonuses(); + return eff; + } + + //called when an effect runs it's course + public void endEffect(String name) { + + Effect eff = this.effects.get(name); + if (eff == null) { + return; + } + if (!isAlive() && eff.getEffectsBase().getToken() != 1672601862) { + return; + } + + if (eff.cancel()) { + + eff.endEffect(); + this.effects.remove(name); + if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) + if (name.equals("Flight")) { + ((PlayerCharacter) this).update(); + PlayerCharacter.GroundPlayer((PlayerCharacter) this); + } + } + applyAllBonuses(); + } + + public void endEffectNoPower(String name) { + + Effect eff = this.effects.get(name); + if (eff == null) { + return; + } + if (!isAlive() && eff.getEffectsBase().getToken() != 1672601862) { + return; + } + + if (eff.cancel()) { + eff.cancelJob(); + eff.endEffectNoPower(); + this.effects.remove(name); + } + applyAllBonuses(); + } + + //Called to cancel an effect prematurely. + public void cancelEffect(String name, boolean overwrite) { + + Effect eff = this.effects.get(name); + if (eff == null) { + return; + } + if (!isAlive() && eff.getEffectsBase().getToken() != 1672601862) { + return; + } + + if (eff.cancel()) { + eff.cancelJob(); + this.effects.remove(name); + if (AbstractWorldObject.IsAbstractCharacter(this)) { + ((AbstractCharacter) this).cancelLastChantIfSame(eff); + } + } + if (!overwrite) { + applyAllBonuses(); + } + } + + //Called when an object dies/is destroyed + public void clearEffects() { + for (String name : this.effects.keySet()) { + Effect eff = this.effects.get(name); + if (eff == null) { + return; + } + + //Dont remove deathshroud here! + if (eff.getEffectToken() == 1672601862) + continue; + + if (eff.cancel()) { + if (eff.getPower() == null) { + if (!eff.isStatic()) + eff.endEffectNoPower(); + } + if (!eff.isStatic()) + eff.cancelJob(); + } + + this.effects.remove(name); + } + if (AbstractWorldObject.IsAbstractCharacter(this)) { + ((AbstractCharacter) this).cancelLastChant(); + } + applyAllBonuses(); + } + + public void removeEffectBySource(EffectSourceType source, int trains, boolean removeAll) { + if (!isAlive() && source.equals(EffectSourceType.DeathShroud) == false) { + return; + } + + //hacky way to dispell trebs. + if (this.getObjectType() == GameObjectType.Mob) { + Mob mob = (Mob) this; + if (mob.isSiege()) { + if (mob.isPet()) { + PlayerCharacter petOwner = mob.getOwner(); + if (petOwner != null && source.equals(EffectSourceType.Effect)) { + petOwner.dismissPet(); + return; + } + } + } + } + boolean changed = false; + String toRemove = ""; + int toRemoveToken = Integer.MAX_VALUE; + for (String name : this.effects.keySet()) { + Effect eff = this.effects.get(name); + if (eff == null) { + continue; + } + if (eff.containsSource(source) && trains >= eff.getTrains()) { + if (removeAll) { + //remove all effects of source type + if (eff.cancel()) { + eff.cancelJob(); + } + this.effects.remove(name); + changed = true; + + if (source.equals("Flight")) { + //ground player + if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) { + ((PlayerCharacter) this).update(); + PlayerCharacter.GroundPlayer((PlayerCharacter) this); + } + } + } else { + //find lowest token of source type to remove + int tok = eff.getEffectToken(); + if (tok != 0 && tok < toRemoveToken) { + toRemove = name; + toRemoveToken = tok; + } + } + } + } + + //WTF IS THIS? + if (toRemoveToken < Integer.MAX_VALUE && this.effects.containsKey(toRemove)) { + //remove lowest found token of source type + Effect eff = this.effects.get(toRemove); + if (eff != null) { + changed = true; + if (eff.cancel()) { + eff.cancelJob(); + } + this.effects.remove(toRemove); + + if (source.equals("Flight")) { + //ground player + if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) { + ((PlayerCharacter) this).update(); + PlayerCharacter.GroundPlayer((PlayerCharacter) this); + } + } + + } + } + if (changed) { + applyAllBonuses(); + } + } + + public void sendAllEffects(ClientConnection cc) { + UpdateEffectsMsg msg = new UpdateEffectsMsg(this); + Dispatch dispatch = Dispatch.borrow((PlayerCharacter) this, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + } + + public void applyAllBonuses() { + if (AbstractWorldObject.IsAbstractCharacter(this)) { + ((AbstractCharacter) this).applyBonuses(); + } + } + + public JobContainer getEffectJobContainer(String name) { + Effect ef = this.effects.get(name); + if (ef != null) { + return ef.getJobContainer(); + } + return null; + } + + public AbstractScheduleJob getEffectJob(String name) { + Effect ef = this.effects.get(name); + if (ef == null) { + return null; + } + JobContainer jc = ef.getJobContainer(); + if (jc != null) { + return (AbstractScheduleJob) jc.getJob(); + } + return null; + } + + public boolean containsEffect(int token) { + for (Effect eff : this.effects.values()) { + if (eff != null) { + if (eff.getEffectsBase() != null) { + if (eff.getEffectsBase().getToken() == token) { + return true; + } + } + } + } + return false; + } + + public int getObjectTypeMask() { + return objectTypeMask; + } + + /* + * Setters + */ + public void setObjectTypeMask(int mask) { + this.objectTypeMask = mask; + } + + public Vector3fImmutable getLoc() { + return this.loc; + } + + //TODO return false if something goes wrong? resync player? + public void setLoc(Vector3fImmutable loc) { + locationLock.writeLock().lock(); + try { + if (Float.isNaN(loc.x) || Float.isNaN(loc.z)) + return; + + if (loc.equals(Vector3fImmutable.ZERO)) + return; + + if (loc.x > MBServerStatics.MAX_WORLD_WIDTH || loc.z < MBServerStatics.MAX_WORLD_HEIGHT) + return; + this.lastLoc = new Vector3fImmutable(this.loc); + this.loc = loc; + this.loc = this.loc.setY(HeightMap.getWorldHeight(this) + this.getAltitude()); + + //lets not add mob to world grid if he is currently despawned. + if (this.getObjectType().equals(GameObjectType.Mob) && ((Mob) this).despawned) + return; + + //do not add objectUUID 0 to world grid. dunno da fuck this doing why its doing but its doing... da fuck. + if (this.getObjectUUID() == 0) + return; + WorldGrid.addObject(this, loc.x, loc.z); + + } catch (Exception e) { + Logger.error("Failed to set location for World Object. Type = " + this.getObjectType().name() + " : Name = " + this.getName()); + e.printStackTrace(); + } finally { + locationLock.writeLock().unlock(); + } + + } + + public Vector3f getRot() { + return rot; + } + + public void setRot(Vector3f rotation) { + synchronized (this.rot) { + this.rot = rotation; + } + } + + public byte getTier() { + return tier; + } + + public void setTier(byte tier) { + synchronized (this.rot) { + this.tier = tier; + } + } + + public boolean isAlive() { + if (AbstractWorldObject.IsAbstractCharacter(this)) { + return this.isAlive(); + } else if (this.getObjectType().equals(GameObjectType.Building)) { + return (!(((Building) this).getRank() < 0)); + } else { + return true; + } + } + + public void setY(float y) { + this.loc = this.loc.setY(y); + } + + public boolean load() { + return this.load; + } + + /* + * Utils + */ + public String getName() { + if (this.name.length() == 0) { + return "Unnamed " + '(' + + this.getObjectUUID() + ')'; + } else { + return this.name; + } + } + + public String getSimpleName() { + return this.name; + } + + /** + * @return the bounds + */ + public Bounds getBounds() { + return bounds; + } + + public void setBounds(Bounds bounds) { + + this.bounds = bounds; + } + + public float getAltitude() { + return altitude; + } + + + public ReadWriteLock getUpdateLock() { + return updateLock; + } + + public GridObjectType getGridObjectType() { + return gridObjectType; + } + + + public boolean isMovingUp() { + return movingUp; + } + + public void setMovingUp(boolean movingUp) { + this.movingUp = movingUp; + } + + public void setRegion(Regions region) { + this.region = region; + } + + //used for interestmanager loading and unloading objects to client. + // if not in grid, unload from player. + public boolean isInWorldGrid() { + if (this.gridX == -1 && this.gridZ == -1) + return false; + + return true; + } + } diff --git a/src/engine/objects/Account.java b/src/engine/objects/Account.java index f910faf2..7beb72b5 100644 --- a/src/engine/objects/Account.java +++ b/src/engine/objects/Account.java @@ -34,357 +34,357 @@ import java.util.concurrent.ConcurrentHashMap; public class Account extends AbstractGameObject { - private final String uname; - private String passwd; - private int lastCharIDUsed; - private String salt; - public String discordAccount; - private byte loginAttempts = 0; - private long lastLoginFailure = System.currentTimeMillis(); - public HashMap characterMap = new HashMap<>(); - public static ConcurrentHashMap AccountsMap = new ConcurrentHashMap<>(); - private ArrayList vault = new ArrayList<>(); - public Item vaultGold = null; - public long lastPasswordCheck = 0; - public Enum.AccountStatus status; - - public ArrayList getVault() { - return vault; - } - - public Account(ResultSet resultSet) throws SQLException { - super(resultSet); - - this.uname = resultSet.getString("acct_uname"); - this.passwd = resultSet.getString("acct_passwd"); - this.lastCharIDUsed = resultSet.getInt("acct_lastCharUID"); - this.salt = resultSet.getString("acct_salt"); - this.discordAccount = resultSet.getString("discordAccount"); - this.status = Enum.AccountStatus.valueOf(resultSet.getString("status")); - } - - public String getUname() { - return uname; - } - - public String getPasswd() { - return passwd; - } - - public String getSalt() { - return salt; - } - - public int getLastCharIDUsed() { - return lastCharIDUsed; - } - - public byte getLoginAttempts() { - return loginAttempts; - } - - public long getLastLoginFailure() { - return this.lastLoginFailure; - } - - public void setLastCharIDUsed(int lastCharIDUsed) { - this.lastCharIDUsed = lastCharIDUsed; - } - - public void setLastLoginFailure() { - this.lastLoginFailure = System.currentTimeMillis(); - } - - public void setLastCharacter(int uuid) { - this.lastCharIDUsed = uuid; - // this.updateDatabase(); - } - - public void incrementLoginAttempts() { - ++this.loginAttempts; - this.setLastLoginFailure(); - } - - public void resetLoginAttempts() { - this.loginAttempts = 0; - } - - /* - * on successfully matching the password, this method additionally calls to - * associateIpToAccount for IPAddress tracking. dokks - */ - public boolean passIsValid(String pw, String ip, String machineID) throws IllegalArgumentException { - boolean result = false; - // see if it was entered in plain text first, if the plain text matches, - // hash it and save to the database. - try { - pw = ByteUtils.byteArrayToSafeStringHex(MessageDigest - .getInstance("md5").digest(pw.getBytes("UTF-8"))) - + salt; - pw = ByteUtils.byteArrayToSafeStringHex(MessageDigest - .getInstance("md5").digest(pw.getBytes())); - result = this.passwd.equals(pw); - } catch ( NoSuchAlgorithmException | UnsupportedEncodingException e) { - Logger.error( e.toString()); - } - - if (result) { - // TODO: should use an executor here so that we can - // fire and forget this update. - // this is a valid user, so let's also update the - // database with login time and IP. - if((ip==null)||(ip.length()==0)) { - throw new IllegalArgumentException(); - } - } - return result; - } - - public ClientConnection getClientConnection() { - return SessionManager.getClientConnection(this); - } - - public PlayerCharacter getPlayerCharacter() { - return SessionManager.getPlayerCharacter(this); - } - - @Override - public void updateDatabase() { - DbManager.AccountQueries.updateDatabase(this); - } - - //this should be called to handle any after load functions. - - public void runAfterLoad() { - - try { - - if (ConfigManager.serverType.equals(Enum.ServerType.LOGINSERVER)){ - ArrayList playerList = DbManager.PlayerCharacterQueries.GET_CHARACTERS_FOR_ACCOUNT(this.getObjectUUID()); - - for(PlayerCharacter player:playerList) { - PlayerCharacter.initializePlayer(player); - this.characterMap.putIfAbsent(player.getObjectUUID(), player); - } - - playerList.clear(); - } - - if (ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER)) { - this.vault = DbManager.ItemQueries.GET_ITEMS_FOR_ACCOUNT(this.getObjectUUID()); - - for (Item item : this.vault) { - if (item.getItemBase().getUUID() == 7) { - this.vaultGold = item; - } - } - - if (this.vaultGold == null) { - this.vaultGold = Item.newGoldItem(this.getObjectUUID(), ItemBase.getItemBase(7), ItemContainerType.VAULT); - - if (this.vaultGold != null) - this.vault.add(this.vaultGold); - } - } - - } catch (Exception e) { - Logger.error( e); - } - } - - public synchronized void transferItemFromInventoryToVault(TransferItemFromInventoryToVaultMsg msg, ClientConnection origin) { - - PlayerCharacter player = origin.getPlayerCharacter(); - Dispatch dispatch; - - if (player == null) - return; - - if (!ClientMessagePump.NPCVaultBankRangeCheck(player, origin, "vault")) { - ClientMessagePump.forceTransferFromVaultToInventory(msg, origin, "You are out of range of the vault."); - return; - } - - int uuid = msg.getUUID(); - Item item = Item.getFromCache(uuid); - - if (item == null) { - ClientMessagePump.forceTransferFromVaultToInventory(msg, origin, "Can't find the item."); - return; - } - - //dupe check - if (!item.validForInventory(origin, player, player.getCharItemManager())) - return; + public static ConcurrentHashMap AccountsMap = new ConcurrentHashMap<>(); + private final String uname; + public String discordAccount; + public HashMap characterMap = new HashMap<>(); + public Item vaultGold = null; + public long lastPasswordCheck = 0; + public Enum.AccountStatus status; + private String passwd; + private int lastCharIDUsed; + private String salt; + private byte loginAttempts = 0; + private long lastLoginFailure = System.currentTimeMillis(); + private ArrayList vault = new ArrayList<>(); + + public Account(ResultSet resultSet) throws SQLException { + super(resultSet); + + this.uname = resultSet.getString("acct_uname"); + this.passwd = resultSet.getString("acct_passwd"); + this.lastCharIDUsed = resultSet.getInt("acct_lastCharUID"); + this.salt = resultSet.getString("acct_salt"); + this.discordAccount = resultSet.getString("discordAccount"); + this.status = Enum.AccountStatus.valueOf(resultSet.getString("status")); + } + + public ArrayList getVault() { + return vault; + } + + public String getUname() { + return uname; + } + + public String getPasswd() { + return passwd; + } + + public String getSalt() { + return salt; + } + + public int getLastCharIDUsed() { + return lastCharIDUsed; + } + + public void setLastCharIDUsed(int lastCharIDUsed) { + this.lastCharIDUsed = lastCharIDUsed; + } + + public byte getLoginAttempts() { + return loginAttempts; + } + + public long getLastLoginFailure() { + return this.lastLoginFailure; + } + + public void setLastLoginFailure() { + this.lastLoginFailure = System.currentTimeMillis(); + } + + public void setLastCharacter(int uuid) { + this.lastCharIDUsed = uuid; + // this.updateDatabase(); + } + + public void incrementLoginAttempts() { + ++this.loginAttempts; + this.setLastLoginFailure(); + } + + public void resetLoginAttempts() { + this.loginAttempts = 0; + } + + /* + * on successfully matching the password, this method additionally calls to + * associateIpToAccount for IPAddress tracking. dokks + */ + public boolean passIsValid(String pw, String ip, String machineID) throws IllegalArgumentException { + boolean result = false; + // see if it was entered in plain text first, if the plain text matches, + // hash it and save to the database. + try { + pw = ByteUtils.byteArrayToSafeStringHex(MessageDigest + .getInstance("md5").digest(pw.getBytes("UTF-8"))) + + salt; + pw = ByteUtils.byteArrayToSafeStringHex(MessageDigest + .getInstance("md5").digest(pw.getBytes())); + result = this.passwd.equals(pw); + } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { + Logger.error(e.toString()); + } + + if (result) { + // TODO: should use an executor here so that we can + // fire and forget this update. + // this is a valid user, so let's also update the + // database with login time and IP. + if ((ip == null) || (ip.length() == 0)) { + throw new IllegalArgumentException(); + } + } + return result; + } + + public ClientConnection getClientConnection() { + return SessionManager.getClientConnection(this); + } + + public PlayerCharacter getPlayerCharacter() { + return SessionManager.getPlayerCharacter(this); + } + + @Override + public void updateDatabase() { + DbManager.AccountQueries.updateDatabase(this); + } + + //this should be called to handle any after load functions. + + public void runAfterLoad() { + + try { + + if (ConfigManager.serverType.equals(Enum.ServerType.LOGINSERVER)) { + ArrayList playerList = DbManager.PlayerCharacterQueries.GET_CHARACTERS_FOR_ACCOUNT(this.getObjectUUID()); + + for (PlayerCharacter player : playerList) { + PlayerCharacter.initializePlayer(player); + this.characterMap.putIfAbsent(player.getObjectUUID(), player); + } + + playerList.clear(); + } + + if (ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER)) { + this.vault = DbManager.ItemQueries.GET_ITEMS_FOR_ACCOUNT(this.getObjectUUID()); + + for (Item item : this.vault) { + if (item.getItemBase().getUUID() == 7) { + this.vaultGold = item; + } + } + + if (this.vaultGold == null) { + this.vaultGold = Item.newGoldItem(this.getObjectUUID(), ItemBase.getItemBase(7), ItemContainerType.VAULT); + + if (this.vaultGold != null) + this.vault.add(this.vaultGold); + } + } + + } catch (Exception e) { + Logger.error(e); + } + } + + public synchronized void transferItemFromInventoryToVault(TransferItemFromInventoryToVaultMsg msg, ClientConnection origin) { + + PlayerCharacter player = origin.getPlayerCharacter(); + Dispatch dispatch; + + if (player == null) + return; + + if (!ClientMessagePump.NPCVaultBankRangeCheck(player, origin, "vault")) { + ClientMessagePump.forceTransferFromVaultToInventory(msg, origin, "You are out of range of the vault."); + return; + } + + int uuid = msg.getUUID(); + Item item = Item.getFromCache(uuid); + + if (item == null) { + ClientMessagePump.forceTransferFromVaultToInventory(msg, origin, "Can't find the item."); + return; + } + + //dupe check + if (!item.validForInventory(origin, player, player.getCharItemManager())) + return; - if (item.containerType == Enum.ItemContainerType.INVENTORY && player.getCharItemManager().isVaultOpen()) { - if (!player.getCharItemManager().hasRoomVault(item.getItemBase().getWeight())) { - ClientMessagePump.forceTransferFromVaultToInventory(msg, origin, "There is no room in your vault."); - return; - } + if (item.containerType == Enum.ItemContainerType.INVENTORY && player.getCharItemManager().isVaultOpen()) { + if (!player.getCharItemManager().hasRoomVault(item.getItemBase().getWeight())) { + ClientMessagePump.forceTransferFromVaultToInventory(msg, origin, "There is no room in your vault."); + return; + } - if (player.getCharItemManager().moveItemToVault(item)) { - this.vault.add(item); - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } else - ClientMessagePump.forceTransferFromVaultToInventory(msg, origin, "Failed to transfer item."); - } - } + if (player.getCharItemManager().moveItemToVault(item)) { + this.vault.add(item); + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + } else + ClientMessagePump.forceTransferFromVaultToInventory(msg, origin, "Failed to transfer item."); + } + } - public synchronized void transferItemFromVaultToInventory(TransferItemFromVaultToInventoryMsg msg, ClientConnection origin) { + public synchronized void transferItemFromVaultToInventory(TransferItemFromVaultToInventoryMsg msg, ClientConnection origin) { - PlayerCharacter player = origin.getPlayerCharacter(); - Dispatch dispatch; + PlayerCharacter player = origin.getPlayerCharacter(); + Dispatch dispatch; - if (player == null) - return; + if (player == null) + return; - if (!ClientMessagePump.NPCVaultBankRangeCheck(player, origin, "vault")) { - ClientMessagePump.forceTransferFromInventoryToVault(msg, origin, "You are out of range of the vault."); - return; - } + if (!ClientMessagePump.NPCVaultBankRangeCheck(player, origin, "vault")) { + ClientMessagePump.forceTransferFromInventoryToVault(msg, origin, "You are out of range of the vault."); + return; + } - CharacterItemManager itemManager = player.getCharItemManager(); + CharacterItemManager itemManager = player.getCharItemManager(); - if (itemManager == null) { - ClientMessagePump.forceTransferFromInventoryToVault(msg, origin, "Can't find your item manager."); - return; - } + if (itemManager == null) { + ClientMessagePump.forceTransferFromInventoryToVault(msg, origin, "Can't find your item manager."); + return; + } - Item item = Item.getFromCache(msg.getUUID()); + Item item = Item.getFromCache(msg.getUUID()); - if (item == null) { - ClientMessagePump.forceTransferFromInventoryToVault(msg, origin, "Can't find the item."); - return; - } + if (item == null) { + ClientMessagePump.forceTransferFromInventoryToVault(msg, origin, "Can't find the item."); + return; + } - //dupe check - if (!item.validForVault(origin, player, itemManager)) - return; + //dupe check + if (!item.validForVault(origin, player, itemManager)) + return; - if (item.containerType == Enum.ItemContainerType.VAULT && itemManager.isVaultOpen()) { - if (!itemManager.hasRoomInventory(item.getItemBase().getWeight())) { - ClientMessagePump.forceTransferFromInventoryToVault(msg, origin, "There is no room in your inventory."); - return; - } - if (itemManager.moveItemToInventory(item)) { - this.vault.remove(item); + if (item.containerType == Enum.ItemContainerType.VAULT && itemManager.isVaultOpen()) { + if (!itemManager.hasRoomInventory(item.getItemBase().getWeight())) { + ClientMessagePump.forceTransferFromInventoryToVault(msg, origin, "There is no room in your inventory."); + return; + } + if (itemManager.moveItemToInventory(item)) { + this.vault.remove(item); - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } else - ClientMessagePump.forceTransferFromInventoryToVault(msg, origin, "Failed to transfer item."); - } - } + } else + ClientMessagePump.forceTransferFromInventoryToVault(msg, origin, "Failed to transfer item."); + } + } - public synchronized void transferGoldFromVaultToInventory(TransferGoldFromVaultToInventoryMsg msg, ClientConnection origin) { + public synchronized void transferGoldFromVaultToInventory(TransferGoldFromVaultToInventoryMsg msg, ClientConnection origin) { - PlayerCharacter player = origin.getPlayerCharacter(); - Dispatch dispatch; + PlayerCharacter player = origin.getPlayerCharacter(); + Dispatch dispatch; - if (player == null) - return; + if (player == null) + return; - Account account = player.getAccount(); + Account account = player.getAccount(); - if (account == null) - return; + if (account == null) + return; - if (!ClientMessagePump.NPCVaultBankRangeCheck(player, origin, "vault")) - return; + if (!ClientMessagePump.NPCVaultBankRangeCheck(player, origin, "vault")) + return; - NPC npc = player.getLastNPCDialog(); + NPC npc = player.getLastNPCDialog(); - if (npc == null) - return; + if (npc == null) + return; - CharacterItemManager itemManager = player.getCharItemManager(); + CharacterItemManager itemManager = player.getCharItemManager(); - if (itemManager == null) - return; + if (itemManager == null) + return; - if (itemManager.isVaultOpen() == false) - return; + if (itemManager.isVaultOpen() == false) + return; - if (itemManager.moveGoldToInventory(itemManager.getGoldVault(), msg.getAmount()) == false) - return; + if (itemManager.moveGoldToInventory(itemManager.getGoldVault(), msg.getAmount()) == false) + return; - OpenVaultMsg open = new OpenVaultMsg(player, npc); - ShowVaultInventoryMsg show = new ShowVaultInventoryMsg(player, account, npc); // 37?? + OpenVaultMsg open = new OpenVaultMsg(player, npc); + ShowVaultInventoryMsg show = new ShowVaultInventoryMsg(player, account, npc); // 37?? - UpdateGoldMsg ugm = new UpdateGoldMsg(player); - ugm.configure(); - dispatch = Dispatch.borrow(player, ugm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + UpdateGoldMsg ugm = new UpdateGoldMsg(player); + ugm.configure(); + dispatch = Dispatch.borrow(player, ugm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - UpdateVaultMsg uvm = new UpdateVaultMsg(account); - dispatch = Dispatch.borrow(player, uvm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + UpdateVaultMsg uvm = new UpdateVaultMsg(account); + dispatch = Dispatch.borrow(player, uvm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - dispatch = Dispatch.borrow(player, open); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + dispatch = Dispatch.borrow(player, open); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - dispatch = Dispatch.borrow(player, show); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + dispatch = Dispatch.borrow(player, show); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } + } - public synchronized void transferGoldFromInventoryToVault(TransferGoldFromInventoryToVaultMsg msg, ClientConnection origin) { + public synchronized void transferGoldFromInventoryToVault(TransferGoldFromInventoryToVaultMsg msg, ClientConnection origin) { - PlayerCharacter player = origin.getPlayerCharacter(); - Dispatch dispatch; + PlayerCharacter player = origin.getPlayerCharacter(); + Dispatch dispatch; - if (player == null) - return; + if (player == null) + return; - Account account = player.getAccount(); + Account account = player.getAccount(); - if (account == null) - return; + if (account == null) + return; - if (!ClientMessagePump.NPCVaultBankRangeCheck(player, origin, "vault")) - return; + if (!ClientMessagePump.NPCVaultBankRangeCheck(player, origin, "vault")) + return; - CharacterItemManager itemManager = player.getCharItemManager(); + CharacterItemManager itemManager = player.getCharItemManager(); - if (itemManager == null) - return; + if (itemManager == null) + return; - NPC npc = player.getLastNPCDialog(); + NPC npc = player.getLastNPCDialog(); - if (npc == null) - return; + if (npc == null) + return; - // Cannot have bank and vault open concurrently - // Dupe prevention + // Cannot have bank and vault open concurrently + // Dupe prevention - if (itemManager.isVaultOpen() == false) - return; + if (itemManager.isVaultOpen() == false) + return; - // Something went horribly wrong. Should be log this? + // Something went horribly wrong. Should be log this? - if (itemManager.moveGoldToVault(itemManager.getGoldInventory(), msg.getAmount()) == false) - return; + if (itemManager.moveGoldToVault(itemManager.getGoldInventory(), msg.getAmount()) == false) + return; - UpdateGoldMsg ugm = new UpdateGoldMsg(player); - ugm.configure(); - dispatch = Dispatch.borrow(player, ugm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + UpdateGoldMsg ugm = new UpdateGoldMsg(player); + ugm.configure(); + dispatch = Dispatch.borrow(player, ugm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - UpdateVaultMsg uvm = new UpdateVaultMsg(account); - dispatch = Dispatch.borrow(player, uvm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + UpdateVaultMsg uvm = new UpdateVaultMsg(account); + dispatch = Dispatch.borrow(player, uvm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - OpenVaultMsg open = new OpenVaultMsg(player, npc); - dispatch = Dispatch.borrow(player, open); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - // - // - ShowVaultInventoryMsg show = new ShowVaultInventoryMsg(player, account, npc); // 37?? - dispatch = Dispatch.borrow(player, show); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + OpenVaultMsg open = new OpenVaultMsg(player, npc); + dispatch = Dispatch.borrow(player, open); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + // + // + ShowVaultInventoryMsg show = new ShowVaultInventoryMsg(player, account, npc); // 37?? + dispatch = Dispatch.borrow(player, show); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } + } } diff --git a/src/engine/objects/Bane.java b/src/engine/objects/Bane.java index b05a6807..5b98aaa4 100644 --- a/src/engine/objects/Bane.java +++ b/src/engine/objects/Bane.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.objects; import engine.Enum; @@ -42,17 +41,16 @@ import java.util.concurrent.ConcurrentHashMap; public final class Bane { + public static ConcurrentHashMap banes = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); private final int cityUUID; - private int ownerUUID; private final int stoneUUID; + private int ownerUUID; private DateTime placementDate = null; private DateTime liveDate = null; private BaneDefaultTimeJob defaultTimeJob; - private ActivateBaneJob activateBaneJob; // Internal cache for banes - - public static ConcurrentHashMap banes = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private ActivateBaneJob activateBaneJob; /** * ResultSet Constructor @@ -121,17 +119,17 @@ public final class Bane { baningGuild = player.getGuild(); if (baningGuild.getNation().isEmptyGuild()) { - PlaceAssetMsg.sendPlaceAssetError( origin, 55, ""); // You must be in a Nation + PlaceAssetMsg.sendPlaceAssetError(origin, 55, ""); // You must be in a Nation return false; } if (baningGuild.getNation().isNPCGuild()) { - PlaceAssetMsg.sendPlaceAssetError( origin, 72, ""); // Cannot be in an NPC nation + PlaceAssetMsg.sendPlaceAssetError(origin, 72, ""); // Cannot be in an NPC nation return false; } if (GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false) { - PlaceAssetMsg.sendPlaceAssetError( origin, 10, ""); // You must be a guild leader + PlaceAssetMsg.sendPlaceAssetError(origin, 10, ""); // You must be a guild leader return false; } @@ -147,17 +145,17 @@ public final class Bane { targetCity = ZoneManager.getCityAtLocation(player.getLoc()); if (targetCity == null) { - PlaceAssetMsg.sendPlaceAssetError( origin, 59, ""); // No city to siege at this location! + PlaceAssetMsg.sendPlaceAssetError(origin, 59, ""); // No city to siege at this location! return false; } if (targetCity.isSafeHold()) { - PlaceAssetMsg.sendPlaceAssetError( origin, 15, ""); // Cannot place assets in peace zone + PlaceAssetMsg.sendPlaceAssetError(origin, 15, ""); // Cannot place assets in peace zone return false; } if (targetCity.getRank() > rank) { - PlaceAssetMsg.sendPlaceAssetError( origin, 60, ""); // Bane rank is too low + PlaceAssetMsg.sendPlaceAssetError(origin, 60, ""); // Bane rank is too low return false; } @@ -172,22 +170,22 @@ public final class Bane { } if (baningGuild.getNation() == targetCity.getGuild().getNation()) { - PlaceAssetMsg.sendPlaceAssetError( origin, 20, ""); //Cannot bane yourself! + PlaceAssetMsg.sendPlaceAssetError(origin, 20, ""); //Cannot bane yourself! return false; } if (targetCity.getTOL() == null) { - PlaceAssetMsg.sendPlaceAssetError( origin, 65, ""); // Cannot find tree to target + PlaceAssetMsg.sendPlaceAssetError(origin, 65, ""); // Cannot find tree to target return false; } if (targetCity.getBane() != null) { - PlaceAssetMsg.sendPlaceAssetError( origin, 23, ""); // Tree is already baned. + PlaceAssetMsg.sendPlaceAssetError(origin, 23, ""); // Tree is already baned. return false; } if (getBaneByAttackerGuild(baningGuild) != null) { - PlaceAssetMsg.sendPlaceAssetError( origin, 1, "Your guild has already placed a bane!"); + PlaceAssetMsg.sendPlaceAssetError(origin, 1, "Your guild has already placed a bane!"); return false; } @@ -196,12 +194,12 @@ public final class Bane { // A nation can only have 3 concurrent banes if (nationBanes.size() == 3) { - PlaceAssetMsg.sendPlaceAssetError( origin, 64, ""); // Your nation is already at war and your limit has been reached + PlaceAssetMsg.sendPlaceAssetError(origin, 64, ""); // Your nation is already at war and your limit has been reached return false; } if (targetCity.isLocationOnCityGrid(player.getLoc()) == true) { - PlaceAssetMsg.sendPlaceAssetError( origin, 1, "Cannot place banestone on city grid."); + PlaceAssetMsg.sendPlaceAssetError(origin, 1, "Cannot place banestone on city grid."); return false; } @@ -249,7 +247,7 @@ public final class Bane { targetCity.getTOL().addEffectBit((1 << 16)); targetCity.getTOL().updateEffects(); - + Vector3fImmutable movePlayerOutsideStone = player.getLoc(); movePlayerOutsideStone = movePlayerOutsideStone.setX(movePlayerOutsideStone.x + 10); movePlayerOutsideStone = movePlayerOutsideStone.setZ(movePlayerOutsideStone.z + 10); @@ -271,6 +269,84 @@ public final class Bane { return true; } + public static Bane getBane(int cityUUID) { + + Bane outBane; + + // Check cache first + + outBane = banes.get(cityUUID); + + // Last resort attempt to load from database + + if (outBane == null) + outBane = DbManager.BaneQueries.LOAD_BANE(cityUUID); + else + return outBane; + + // As we loaded from the db, store it in the internal cache + + if (outBane != null) + banes.put(cityUUID, outBane); + + return outBane; + } + + public static Bane getBaneByAttackerGuild(Guild guild) { + + + if (guild == null || guild.isEmptyGuild()) + return null; + ArrayList baneList; + + baneList = new ArrayList<>(banes.values()); + + for (Bane bane : baneList) { + if (bane.getOwner().getGuild().equals(guild)) + return bane; + } + + return null; + } + + public static ArrayList getBanesByNation(Guild guild) { + + ArrayList baneList; + ArrayList returnList; + + baneList = new ArrayList<>(banes.values()); + returnList = new ArrayList<>(); + + for (Bane bane : baneList) { + if (bane.getOwner().getGuild().getNation().equals(guild)) + returnList.add(bane); + } + + return returnList; + } + + public static void addBane(Bane bane) { + + Bane.banes.put(bane.cityUUID, bane); + + } + + public static Bane makeBane(PlayerCharacter owner, City city, Building stone) { + + Bane newBane; + + if (DbManager.BaneQueries.CREATE_BANE(city, owner, stone) == false) { + Logger.error("Error writing to database"); + return null; + } + + newBane = DbManager.BaneQueries.LOAD_BANE(city.getObjectUUID()); + + return newBane; + } + + //Call this to prematurely end a bane + public SiegePhase getSiegePhase() { SiegePhase phase; @@ -281,16 +357,18 @@ public final class Bane { } if (DateTime.now().isAfter(this.liveDate)) { - phase = SiegePhase.WAR; //war + phase = SiegePhase.WAR; //war return phase; } // If code reaches this point we are in standoff mode. - phase = SiegePhase.STANDOFF; //standoff + phase = SiegePhase.STANDOFF; //standoff return phase; } + // Cache access + private void setDefaultTime() { DateTime timeToSetDefault = new DateTime(this.placementDate); @@ -316,60 +394,7 @@ public final class Bane { } } - public void setLiveDate(DateTime baneTime) { - - if (DbManager.BaneQueries.SET_BANE_TIME(baneTime, this.getCity().getObjectUUID())) { - this.liveDate = new DateTime(baneTime); - - // Push event to warehouse - - BaneRecord.updateLiveDate(this, baneTime); - - ChatManager.chatGuildInfo(this.getOwner().getGuild(), "The bane on " + this.getCity().getGuild().getName() + " has been set! Standoff phase has begun!"); - Guild attackerNation = this.getOwner().getGuild().getNation(); - - if (attackerNation != null) - - for (Guild subGuild : attackerNation.getSubGuildList()) { - - //Don't send the message twice. - if (subGuild.equals(attackerNation)) - continue; - - ChatManager.chatGuildInfo(subGuild, "The bane on " + this.getCity().getGuild().getName() + " has been set! Standoff phase has begun!"); - } - - ChatManager.chatGuildInfo(this.getCity().getGuild(), "The bane on " + this.getCity().getGuild().getName() + " has been set! Standoff phase has begun!"); - - Guild defenderNation = this.getCity().getGuild().getNation(); - - if (defenderNation != null) { - - if (defenderNation != this.getCity().getGuild()) - ChatManager.chatGuildInfo(defenderNation, "The bane on " + this.getCity().getGuild().getName() + " has been set! Standoff phase has begun!"); - - for (Guild subGuild : defenderNation.getSubGuildList()) { - //Don't send the message twice. - if (subGuild == this.getCity().getGuild()) - continue; - ChatManager.chatGuildInfo(subGuild, "The bane on " + this.getCity().getGuild().getName() + " has been set! Standoff phase has begun!"); - } - } - - if (activateBaneJob != null) - this.activateBaneJob.cancelJob(); - - ActivateBaneJob abtj = new ActivateBaneJob(cityUUID); - - JobScheduler.getInstance().scheduleJob(abtj, this.liveDate.getMillis()); - this.activateBaneJob = abtj; - } else { - Logger.debug( "error with city " + this.getCity().getName()); - ChatManager.chatGuildInfo(this.getOwner().getGuild(), "A Serious error has occurred. Please post details for to ensure transaction integrity"); - ChatManager.chatGuildInfo(this.getCity().getGuild(), "A Serious error has occurred. Please post details for to ensure transaction integrity"); - } - - } + //Returns a guild's bane /* * Getters @@ -382,8 +407,6 @@ public final class Bane { return (PlayerCharacter) DbManager.getObject(Enum.GameObjectType.PlayerCharacter, ownerUUID); } - //Call this to prematurely end a bane - public boolean remove() { Building baneStone; @@ -396,19 +419,19 @@ public final class Bane { } // Reassert protection contracts - + this.getCity().protectionEnforced = true; // Remove visual effects on Bane and TOL. - + this.getStone().removeAllVisualEffects(); this.getStone().updateEffects(); this.getCity().getTOL().removeAllVisualEffects(); this.getCity().getTOL().updateEffects(); - + // Remove bane from the database - + if (DbManager.BaneQueries.REMOVE_BANE(this) == false) { Logger.error("Database call failed for city UUID: " + this.getCity().getObjectUUID()); return false; @@ -417,113 +440,88 @@ public final class Bane { // Remove bane from ingame cache Bane.banes.remove(cityUUID); - + // Delete stone from database - + if (DbManager.BuildingQueries.DELETE_FROM_DATABASE(baneStone) == false) { - Logger.error( "Database error when deleting stone object"); + Logger.error("Database error when deleting stone object"); return false; } // Remove object from simulation - + baneStone.removeFromCache(); WorldGrid.RemoveWorldObject(baneStone); WorldGrid.removeObject(baneStone); return true; } - // Cache access - - public static Bane getBane(int cityUUID) { - - Bane outBane; - - // Check cache first + public final DateTime getPlacementDate() { + return placementDate; + } - outBane = banes.get(cityUUID); + public final boolean isAccepted() { - // Last resort attempt to load from database + return (this.getSiegePhase() != SiegePhase.CHALLENGE); + } - if (outBane == null) - outBane = DbManager.BaneQueries.LOAD_BANE(cityUUID); - else - return outBane; + public final DateTime getLiveDate() { + return liveDate; + } - // As we loaded from the db, store it in the internal cache + public void setLiveDate(DateTime baneTime) { - if (outBane != null) - banes.put(cityUUID, outBane); + if (DbManager.BaneQueries.SET_BANE_TIME(baneTime, this.getCity().getObjectUUID())) { + this.liveDate = new DateTime(baneTime); - return outBane; - } + // Push event to warehouse - //Returns a guild's bane - - public static Bane getBaneByAttackerGuild(Guild guild) { - - - if (guild == null || guild.isEmptyGuild()) - return null; - ArrayList baneList; - - baneList = new ArrayList<>(banes.values()); - - for (Bane bane : baneList) { - if (bane.getOwner().getGuild().equals(guild)) - return bane; - } - - return null; - } + BaneRecord.updateLiveDate(this, baneTime); - public static ArrayList getBanesByNation(Guild guild) { + ChatManager.chatGuildInfo(this.getOwner().getGuild(), "The bane on " + this.getCity().getGuild().getName() + " has been set! Standoff phase has begun!"); + Guild attackerNation = this.getOwner().getGuild().getNation(); - ArrayList baneList; - ArrayList returnList; - - baneList = new ArrayList<>(banes.values()); - returnList = new ArrayList<>(); - - for (Bane bane : baneList) { - if (bane.getOwner().getGuild().getNation().equals(guild)) - returnList.add(bane); - } - - return returnList; - } + if (attackerNation != null) - public static void addBane(Bane bane) { + for (Guild subGuild : attackerNation.getSubGuildList()) { - Bane.banes.put(bane.cityUUID, bane); + //Don't send the message twice. + if (subGuild.equals(attackerNation)) + continue; - } + ChatManager.chatGuildInfo(subGuild, "The bane on " + this.getCity().getGuild().getName() + " has been set! Standoff phase has begun!"); + } - public static Bane makeBane(PlayerCharacter owner, City city, Building stone) { + ChatManager.chatGuildInfo(this.getCity().getGuild(), "The bane on " + this.getCity().getGuild().getName() + " has been set! Standoff phase has begun!"); - Bane newBane; + Guild defenderNation = this.getCity().getGuild().getNation(); - if (DbManager.BaneQueries.CREATE_BANE(city, owner, stone) == false) { - Logger.error("Error writing to database"); - return null; - } + if (defenderNation != null) { - newBane = DbManager.BaneQueries.LOAD_BANE(city.getObjectUUID()); + if (defenderNation != this.getCity().getGuild()) + ChatManager.chatGuildInfo(defenderNation, "The bane on " + this.getCity().getGuild().getName() + " has been set! Standoff phase has begun!"); - return newBane; - } + for (Guild subGuild : defenderNation.getSubGuildList()) { + //Don't send the message twice. + if (subGuild == this.getCity().getGuild()) + continue; + ChatManager.chatGuildInfo(subGuild, "The bane on " + this.getCity().getGuild().getName() + " has been set! Standoff phase has begun!"); + } + } - public final DateTime getPlacementDate() { - return placementDate; - } + if (activateBaneJob != null) + this.activateBaneJob.cancelJob(); - public final boolean isAccepted() { + ActivateBaneJob abtj = new ActivateBaneJob(cityUUID); - return (this.getSiegePhase() != SiegePhase.CHALLENGE); - } + JobScheduler.getInstance().scheduleJob(abtj, this.liveDate.getMillis()); + this.activateBaneJob = abtj; + } else { + Logger.debug("error with city " + this.getCity().getName()); + ChatManager.chatGuildInfo(this.getOwner().getGuild(), "A Serious error has occurred. Please post details for to ensure transaction integrity"); + ChatManager.chatGuildInfo(this.getCity().getGuild(), "A Serious error has occurred. Please post details for to ensure transaction integrity"); + } - public final DateTime getLiveDate() { - return liveDate; } public final void endBane(SiegeResult siegeResult) { @@ -533,9 +531,9 @@ public final class Bane { // No matter what the outcome of a bane, we re-asset // protection contracts at this time. They don't quite // matter if the city falls, as they are invalidated. - + this.getCity().protectionEnforced = true; - + switch (siegeResult) { case DEFEND: @@ -548,19 +546,19 @@ public final class Bane { if (baneRemoved) { // Update seieges withstood - + this.getCity().setSiegesWithstood(this.getCity().getSiegesWithstood() + 1); - + // Notify players - - ChatSystemMsg msg = new ChatSystemMsg(null, "[Bane Channel]" + this.getCity().getGuild().getName() + " has rallied against " + this.getOwner().getGuild().getName() + ". The siege on " + this.getCity().getCityName() + " has been broken!"); - msg.setMessageType(4); - msg.setChannel(engine.Enum.ChatChannelType.SYSTEM.getChannelID()); - - DispatchMessage.dispatchMsgToAll(msg); - + + ChatSystemMsg msg = new ChatSystemMsg(null, "[Bane Channel]" + this.getCity().getGuild().getName() + " has rallied against " + this.getOwner().getGuild().getName() + ". The siege on " + this.getCity().getCityName() + " has been broken!"); + msg.setMessageType(4); + msg.setChannel(engine.Enum.ChatChannelType.SYSTEM.getChannelID()); + + DispatchMessage.dispatchMsgToAll(msg); + } - + break; case CAPTURE: @@ -572,11 +570,11 @@ public final class Bane { if (baneRemoved) { - ChatSystemMsg msg = new ChatSystemMsg(null, "[Bane Channel]" + this.getOwner().getGuild().getName() + " have defeated " + this.getCity().getGuild().getName() + " and captured " + this.getCity().getCityName() + '!'); - msg.setMessageType(4); - msg.setChannel(engine.Enum.ChatChannelType.SYSTEM.getChannelID()); - - DispatchMessage.dispatchMsgToAll(msg); + ChatSystemMsg msg = new ChatSystemMsg(null, "[Bane Channel]" + this.getOwner().getGuild().getName() + " have defeated " + this.getCity().getGuild().getName() + " and captured " + this.getCity().getCityName() + '!'); + msg.setMessageType(4); + msg.setChannel(engine.Enum.ChatChannelType.SYSTEM.getChannelID()); + + DispatchMessage.dispatchMsgToAll(msg); } break; case DESTROY: @@ -589,11 +587,11 @@ public final class Bane { if (baneRemoved) { - ChatSystemMsg msg = new ChatSystemMsg(null, "[Bane Channel]" + this.getOwner().getGuild().getName() + " have defeated " + this.getCity().getGuild().getName() + " and razed " + this.getCity().getCityName() + '!'); - msg.setMessageType(4); - msg.setChannel(engine.Enum.ChatChannelType.SYSTEM.getChannelID()); - - DispatchMessage.dispatchMsgToAll(msg); + ChatSystemMsg msg = new ChatSystemMsg(null, "[Bane Channel]" + this.getOwner().getGuild().getName() + " have defeated " + this.getCity().getGuild().getName() + " and razed " + this.getCity().getCityName() + '!'); + msg.setMessageType(4); + msg.setChannel(engine.Enum.ChatChannelType.SYSTEM.getChannelID()); + + DispatchMessage.dispatchMsgToAll(msg); } break; } @@ -601,12 +599,12 @@ public final class Bane { Zone cityZone = this.getCity().getParent(); if (cityZone == null) - return; + return; //UNPROTECT ALL SIEGE EQUIPMENT AFTER A BANE - for (Building toUnprotect: cityZone.zoneBuildingSet){ - if (toUnprotect.getBlueprint() != null && toUnprotect.getBlueprint().isSiegeEquip() && toUnprotect.assetIsProtected() == true) - toUnprotect.setProtectionState(ProtectionState.NONE); + for (Building toUnprotect : cityZone.zoneBuildingSet) { + if (toUnprotect.getBlueprint() != null && toUnprotect.getBlueprint().isSiegeEquip() && toUnprotect.assetIsProtected() == true) + toUnprotect.setProtectionState(ProtectionState.NONE); } } @@ -618,7 +616,7 @@ public final class Bane { if (this.getOwner() == null) return isErrant; - + if (this.getOwner().getGuild().isEmptyGuild() == true) return isErrant; diff --git a/src/engine/objects/BaseClass.java b/src/engine/objects/BaseClass.java index a00c208e..4e4eae31 100644 --- a/src/engine/objects/BaseClass.java +++ b/src/engine/objects/BaseClass.java @@ -19,202 +19,200 @@ import java.util.ArrayList; public class BaseClass extends AbstractGameObject { - private final String name; - private final String description; - - private final byte strMod; - private final byte dexMod; - private final byte conMod; - private final byte intMod; - private final byte spiMod; - - private final float healthMod; - private final float manaMod; - private final float staminaMod; - - private int token = 0; - - private final ArrayList skillsGranted; - private final ArrayList powersGranted; - private ArrayList effectsList = new ArrayList<>(); - - - /** - * No Table ID Constructor - */ - public BaseClass(String name, String description, byte strMod, byte dexMod, byte conMod, byte intMod, byte spiMod, - ArrayList allowedRunes, ArrayList skillsGranted, ArrayList powersGranted) { - super(); - this.name = name; - this.description = description; - this.strMod = strMod; - this.dexMod = dexMod; - this.conMod = conMod; - this.intMod = intMod; - this.spiMod = spiMod; - this.healthMod = 1; - this.manaMod = 1; - this.staminaMod = 1; - - this.skillsGranted = skillsGranted; - this.powersGranted = powersGranted; - - } - - /** - * Normal Constructor - */ - public BaseClass(String name, String description, byte strMod, byte dexMod, byte conMod, byte intMod, byte spiMod, - ArrayList allowedRunes, ArrayList skillsGranted, ArrayList powersGranted, int newUUID) { - super(newUUID); - this.name = name; - this.description = description; - this.strMod = strMod; - this.dexMod = dexMod; - this.conMod = conMod; - this.intMod = intMod; - this.spiMod = spiMod; - this.healthMod = 1; - this.manaMod = 1; - this.staminaMod = 1; - this.skillsGranted = skillsGranted; - this.powersGranted = powersGranted; - - } - - - /** - * ResultSet Constructor - */ - public BaseClass(ResultSet rs) throws SQLException { - super(rs); - - this.name = rs.getString("name"); - this.description = rs.getString("description"); - this.strMod = rs.getByte("strMod"); - this.dexMod = rs.getByte("dexMod"); - this.conMod = rs.getByte("conMod"); - this.intMod = rs.getByte("intMod"); - this.spiMod = rs.getByte("spiMod"); - this.token = rs.getInt("token"); - this.healthMod = rs.getInt("healthMod"); - this.manaMod = rs.getInt("manaMod"); - this.staminaMod = rs.getInt("staminaMod"); - this.skillsGranted = DbManager.SkillReqQueries.GET_REQS_FOR_RUNE(this.getObjectUUID()); - this.powersGranted = PowerReq.getPowerReqsForRune(this.getObjectUUID()); - this.effectsList = (DbManager.MobBaseQueries.GET_RUNEBASE_EFFECTS(this.getObjectUUID())); - - } - - /* - * Getters - */ - public String getName() { - return name; - } - - public String getDescription() { - return description; - } - - public byte getStrMod() { - return strMod; - } - - public byte getDexMod() { - return dexMod; - } - - public byte getConMod() { - return conMod; - } - - public byte getIntMod() { - return intMod; - } - - public byte getSpiMod() { - return spiMod; - } - - public int getToken() { - return this.token; - } - - public float getHealthMod() { - return this.healthMod; - } - - public float getManaMod() { - return this.manaMod; - } - - public float getStaminaMod() { - return this.staminaMod; - } - - public ArrayList getRuneList() { - return RuneBase.AllowedBaseClassRunesMap.get(this.getObjectUUID()); - } - - public ArrayList getSkillsGranted() { - return this.skillsGranted; - } - - public ArrayList getPowersGranted() { - return this.powersGranted; - } - - public ArrayList getEffectsGranted() { - return RuneBaseEffect.RuneIDBaseEffectMap.get(this.getObjectUUID()); - } - - /* - * Utils - */ - public boolean isAllowedRune(RuneBase rb) { - - if (this.getRuneList().contains(rb.getObjectUUID())) - return true; - - if (RuneBase.AllowedBaseClassRunesMap.containsKey(111111)){ - if (RuneBase.AllowedBaseClassRunesMap.get(111111).contains(rb.getObjectUUID())) - return true; - } - return false; - } - - public static void LoadAllBaseClasses(){ - DbManager.BaseClassQueries.GET_ALL_BASE_CLASSES(); - } - - /* - * Serializing - */ - - public static void serializeForClientMsg(BaseClass baseClass, ByteBufferWriter writer) { - serializeForClientMsg(baseClass,writer, 3); - } - - public static void serializeForClientMsg(BaseClass baseClass,ByteBufferWriter writer, int type) { - writer.putInt(type); // For BaseClass - writer.putInt(0); // Pad - writer.putInt(baseClass.getObjectUUID()); - writer.putInt(baseClass.getObjectType().ordinal()); // Is this correct? - writer.putInt(baseClass.getObjectUUID()); - } - - public static BaseClass getBaseClass(final int UUID) { - return DbManager.BaseClassQueries.GET_BASE_CLASS(UUID); - } - - @Override - public void updateDatabase() { - ; //Never update.. - } - - public ArrayList getEffectsList() { - return effectsList; - } + private final String name; + private final String description; + + private final byte strMod; + private final byte dexMod; + private final byte conMod; + private final byte intMod; + private final byte spiMod; + + private final float healthMod; + private final float manaMod; + private final float staminaMod; + private final ArrayList skillsGranted; + private final ArrayList powersGranted; + private int token = 0; + private ArrayList effectsList = new ArrayList<>(); + + + /** + * No Table ID Constructor + */ + public BaseClass(String name, String description, byte strMod, byte dexMod, byte conMod, byte intMod, byte spiMod, + ArrayList allowedRunes, ArrayList skillsGranted, ArrayList powersGranted) { + super(); + this.name = name; + this.description = description; + this.strMod = strMod; + this.dexMod = dexMod; + this.conMod = conMod; + this.intMod = intMod; + this.spiMod = spiMod; + this.healthMod = 1; + this.manaMod = 1; + this.staminaMod = 1; + + this.skillsGranted = skillsGranted; + this.powersGranted = powersGranted; + + } + + /** + * Normal Constructor + */ + public BaseClass(String name, String description, byte strMod, byte dexMod, byte conMod, byte intMod, byte spiMod, + ArrayList allowedRunes, ArrayList skillsGranted, ArrayList powersGranted, int newUUID) { + super(newUUID); + this.name = name; + this.description = description; + this.strMod = strMod; + this.dexMod = dexMod; + this.conMod = conMod; + this.intMod = intMod; + this.spiMod = spiMod; + this.healthMod = 1; + this.manaMod = 1; + this.staminaMod = 1; + this.skillsGranted = skillsGranted; + this.powersGranted = powersGranted; + + } + + + /** + * ResultSet Constructor + */ + public BaseClass(ResultSet rs) throws SQLException { + super(rs); + + this.name = rs.getString("name"); + this.description = rs.getString("description"); + this.strMod = rs.getByte("strMod"); + this.dexMod = rs.getByte("dexMod"); + this.conMod = rs.getByte("conMod"); + this.intMod = rs.getByte("intMod"); + this.spiMod = rs.getByte("spiMod"); + this.token = rs.getInt("token"); + this.healthMod = rs.getInt("healthMod"); + this.manaMod = rs.getInt("manaMod"); + this.staminaMod = rs.getInt("staminaMod"); + this.skillsGranted = DbManager.SkillReqQueries.GET_REQS_FOR_RUNE(this.getObjectUUID()); + this.powersGranted = PowerReq.getPowerReqsForRune(this.getObjectUUID()); + this.effectsList = (DbManager.MobBaseQueries.GET_RUNEBASE_EFFECTS(this.getObjectUUID())); + + } + + public static void LoadAllBaseClasses() { + DbManager.BaseClassQueries.GET_ALL_BASE_CLASSES(); + } + + public static void serializeForClientMsg(BaseClass baseClass, ByteBufferWriter writer) { + serializeForClientMsg(baseClass, writer, 3); + } + + public static void serializeForClientMsg(BaseClass baseClass, ByteBufferWriter writer, int type) { + writer.putInt(type); // For BaseClass + writer.putInt(0); // Pad + writer.putInt(baseClass.getObjectUUID()); + writer.putInt(baseClass.getObjectType().ordinal()); // Is this correct? + writer.putInt(baseClass.getObjectUUID()); + } + + public static BaseClass getBaseClass(final int UUID) { + return DbManager.BaseClassQueries.GET_BASE_CLASS(UUID); + } + + /* + * Getters + */ + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public byte getStrMod() { + return strMod; + } + + public byte getDexMod() { + return dexMod; + } + + public byte getConMod() { + return conMod; + } + + public byte getIntMod() { + return intMod; + } + + public byte getSpiMod() { + return spiMod; + } + + public int getToken() { + return this.token; + } + + public float getHealthMod() { + return this.healthMod; + } + + public float getManaMod() { + return this.manaMod; + } + + public float getStaminaMod() { + return this.staminaMod; + } + + public ArrayList getRuneList() { + return RuneBase.AllowedBaseClassRunesMap.get(this.getObjectUUID()); + } + + public ArrayList getSkillsGranted() { + return this.skillsGranted; + } + + /* + * Serializing + */ + + public ArrayList getPowersGranted() { + return this.powersGranted; + } + + public ArrayList getEffectsGranted() { + return RuneBaseEffect.RuneIDBaseEffectMap.get(this.getObjectUUID()); + } + + /* + * Utils + */ + public boolean isAllowedRune(RuneBase rb) { + + if (this.getRuneList().contains(rb.getObjectUUID())) + return true; + + if (RuneBase.AllowedBaseClassRunesMap.containsKey(111111)) { + if (RuneBase.AllowedBaseClassRunesMap.get(111111).contains(rb.getObjectUUID())) + return true; + } + return false; + } + + @Override + public void updateDatabase() { + ; //Never update.. + } + + public ArrayList getEffectsList() { + return effectsList; + } } diff --git a/src/engine/objects/Blueprint.java b/src/engine/objects/Blueprint.java index 8b982445..15777c27 100644 --- a/src/engine/objects/Blueprint.java +++ b/src/engine/objects/Blueprint.java @@ -9,7 +9,6 @@ package engine.objects; // www.magicbane.com - import engine.Enum.BuildingGroup; import engine.gameManager.DbManager; import engine.math.Vector2f; @@ -26,606 +25,604 @@ import java.util.HashMap; */ public class Blueprint { - public final static Vector2f IrikieForgeExtents = new Vector2f(32, 32); - public final static Vector2f IrikieBarracksExtents = new Vector2f(32, 32); + public final static Vector2f IrikieForgeExtents = new Vector2f(32, 32); + public final static Vector2f IrikieBarracksExtents = new Vector2f(32, 32); + public static HashMap _meshLookup = new HashMap<>(); + private static HashMap _blueprints = new HashMap<>(); + private static HashMap _doorNumbers = new HashMap<>(); + private final int blueprintUUID; + private final String name; + private final BuildingGroup buildingGroup; + private final int icon; + private final int maxRank; + private final int maxSlots; + private final int rank1UUID; + private final int rank3UUID; + private final int rank7UUID; + private final int destroyedUUID; + + private Blueprint() { + this.blueprintUUID = 0; + this.name = ""; + this.icon = 0; + this.buildingGroup = BuildingGroup.BANESTONE; + this.maxRank = 0; + this.maxSlots = 0; + this.rank1UUID = 0; + this.rank3UUID = 0; + this.rank7UUID = 0; + this.destroyedUUID = 0; + } - private static HashMap _blueprints = new HashMap<>(); - private static HashMap _doorNumbers = new HashMap<>(); - public static HashMap _meshLookup = new HashMap<>(); + public Blueprint(ResultSet rs) throws SQLException { - private final int blueprintUUID; - private final String name; - private final BuildingGroup buildingGroup; - private final int icon; - private final int maxRank; - private final int maxSlots; - private final int rank1UUID; - private final int rank3UUID; - private final int rank7UUID; - private final int destroyedUUID; + this.blueprintUUID = rs.getInt("Rank0UUID"); + this.name = rs.getString("MeshName"); + this.icon = rs.getInt("Icon"); + this.buildingGroup = BuildingGroup.valueOf(rs.getString("BuildingGroup")); + this.maxRank = rs.getInt("MaxRank"); + this.maxSlots = rs.getInt("MaxSlots"); + this.rank1UUID = rs.getInt("Rank1UUID"); + this.rank3UUID = rs.getInt("Rank3UUID"); + this.rank7UUID = rs.getInt("Rank7UUID"); + this.destroyedUUID = rs.getInt("DestroyedUUID"); - private Blueprint() { - this.blueprintUUID = 0; - this.name = ""; - this.icon = 0; - this.buildingGroup = BuildingGroup.BANESTONE; - this.maxRank = 0; - this.maxSlots = 0; - this.rank1UUID = 0; - this.rank3UUID = 0; - this.rank7UUID = 0; - this.destroyedUUID = 0; - } + } - public Blueprint(ResultSet rs) throws SQLException { + // Accessors - this.blueprintUUID = rs.getInt("Rank0UUID"); - this.name = rs.getString("MeshName"); - this.icon = rs.getInt("Icon"); - this.buildingGroup = BuildingGroup.valueOf(rs.getString("BuildingGroup")); - this.maxRank = rs.getInt("MaxRank"); - this.maxSlots = rs.getInt("MaxSlots"); - this.rank1UUID = rs.getInt("Rank1UUID"); - this.rank3UUID = rs.getInt("Rank3UUID"); - this.rank7UUID = rs.getInt("Rank7UUID"); - this.destroyedUUID = rs.getInt("DestroyedUUID"); + public static Blueprint getBlueprint(int blueprintUUID) { - } + return _blueprints.get(blueprintUUID); - // Accessors + } - public static Blueprint getBlueprint(int blueprintUUID) { + public static BuildingGroup getBuildingGroup(int blueprintUUID) { - return _blueprints.get(blueprintUUID); + Blueprint blueprint; - } + blueprint = _blueprints.get(blueprintUUID); - public static BuildingGroup getBuildingGroup(int blueprintUUID) { + return blueprint.buildingGroup; + } - Blueprint blueprint; + public static int getMaxShrines(int treeRank) { + + // Returns the number of allowed spires/shrines + // for a given rank. + + int maxShrines; + + switch (treeRank) { + case 0: + case 1: + case 2: + maxShrines = 0; + break; + case 3: + case 4: + maxShrines = 1; + break; + case 5: + case 6: + maxShrines = 2; + break; + case 7: + case 8: + maxShrines = 3; + break; + default: + maxShrines = 0; - blueprint = _blueprints.get(blueprintUUID); + } - return blueprint.buildingGroup; + return maxShrines; } - public static int getMaxShrines(int treeRank) { + public static void loadAllBlueprints() { - // Returns the number of allowed spires/shrines - // for a given rank. + _blueprints = DbManager.BlueprintQueries.LOAD_ALL_BLUEPRINTS(); - int maxShrines; + } - switch (treeRank) { - case 0: - case 1: - case 2: - maxShrines = 0; - break; - case 3: - case 4: - maxShrines = 1; - break; - case 5: - case 6: - maxShrines = 2; - break; - case 7: - case 8: - maxShrines = 3; - break; - default: - maxShrines = 0; + // Method returns a blueprint based on a blueprintUUID - } + public static void loadAllDoorNumbers() { - return maxShrines; - } + _doorNumbers = DbManager.BlueprintQueries.LOAD_ALL_DOOR_NUMBERS(); - public static void loadAllBlueprints() { + } - _blueprints = DbManager.BlueprintQueries.LOAD_ALL_BLUEPRINTS(); + public static int getDoorNumberbyMesh(int doorMeshUUID) { - } + if (_doorNumbers.containsKey(doorMeshUUID)) + return _doorNumbers.get(doorMeshUUID); - // Method returns a blueprint based on a blueprintUUID + return 0; + } - public static void loadAllDoorNumbers() { + public static boolean isMeshWallPiece(int meshUUID) { - _doorNumbers = DbManager.BlueprintQueries.LOAD_ALL_DOOR_NUMBERS(); + Blueprint buildingBlueprint = Blueprint.getBlueprint(meshUUID); - } + if (buildingBlueprint == null) + return false; - public static int getDoorNumberbyMesh(int doorMeshUUID) { + switch (buildingBlueprint.buildingGroup) { + case WALLSTRAIGHT: + case ARTYTOWER: + case WALLCORNER: + case SMALLGATE: + case WALLSTAIRS: + case WALLSTRAIGHTTOWER: + return true; + default: + break; + } + return false; - if (_doorNumbers.containsKey(doorMeshUUID)) - return _doorNumbers.get(doorMeshUUID); + } - return 0; - } + // Method calculates available vendor slots + // based upon the building's current rank - public static boolean isMeshWallPiece(int meshUUID) { + public static int getNpcMaintCost(int rank) { + int maintCost = Integer.MAX_VALUE; - Blueprint buildingBlueprint = Blueprint.getBlueprint(meshUUID); + maintCost = (9730 * rank) + 1890; - if (buildingBlueprint == null) - return false; + return maintCost; + } - switch (buildingBlueprint.buildingGroup) { - case WALLSTRAIGHT: - case ARTYTOWER: - case WALLCORNER: - case SMALLGATE: - case WALLSTAIRS: - case WALLSTRAIGHTTOWER: - return true; - default: - break; - } - return false; + public int getMaxRank() { + return maxRank; + } - } + public int getMaxSlots() { + if (this.buildingGroup != null && this.buildingGroup.equals(BuildingGroup.BARRACK)) + return 1; + return maxSlots; + } - // Method calculates available vendor slots - // based upon the building's current rank + // Method returns a mesh UUID for this blueprint + // based upon a given rank. - public static int getNpcMaintCost(int rank) { - int maintCost = Integer.MAX_VALUE; + public BuildingGroup getBuildingGroup() { + return this.buildingGroup; + } - maintCost = (9730 * rank) + 1890; + // Method returns a cost to upgrade a building to a given rank + // based upon this blueprint's maintenance group - return maintCost; - } + public int getMaxHealth(int currentRank) { - public int getMaxRank() { - return maxRank; - } + int maxHealth; - public int getMaxSlots() { - if (this.buildingGroup != null && this.buildingGroup.equals(BuildingGroup.BARRACK)) - return 1; - return maxSlots; - } + // Return 0 health for a destroyed building + // or 1 for a destroyed mine (cleint looting restriction) - // Method returns a mesh UUID for this blueprint - // based upon a given rank. + if (currentRank == -1) { - public BuildingGroup getBuildingGroup() { - return this.buildingGroup; - } + return this.buildingGroup == BuildingGroup.MINE ? 1 : 0; + } - // Method returns a cost to upgrade a building to a given rank - // based upon this blueprint's maintenance group + // Return 15k for a constructing mesh - public int getMaxHealth(int currentRank) { + if (currentRank == 0) + return 15000; - int maxHealth; + switch (this.buildingGroup) { + + case TOL: + maxHealth = (70000 * currentRank) + 10000; + break; + case BARRACK: + maxHealth = (35000 * currentRank) + 5000; + break; + case BANESTONE: + maxHealth = (170000 * currentRank) - 120000; + break; + case CHURCH: + maxHealth = (28000 * currentRank) + 4000; + break; + case MAGICSHOP: + case FORGE: + case INN: + case TAILOR: + maxHealth = (17500 * currentRank) + 2500; + break; + case VILLA: + case ESTATE: + case FORTRESS: + maxHealth = 300000; + break; + case CITADEL: + maxHealth = 500000; + break; + case SPIRE: + maxHealth = (37000 * currentRank) - 9000; + break; + case GENERICNOUPGRADE: + case SHACK: + case SIEGETENT: + maxHealth = 40000; + break; + case BULWARK: + if (currentRank == 1) + maxHealth = 110000; + else + maxHealth = 40000; + break; + case WALLSTRAIGHT: + case WALLSTRAIGHTTOWER: + case WALLSTAIRS: + maxHealth = 1000000; + break; + case WALLCORNER: + case ARTYTOWER: + maxHealth = 900000; + break; + case SMALLGATE: + maxHealth = 1100000; + break; + case AMAZONHALL: + case CATHEDRAL: + case GREATHALL: + case KEEP: + case THIEFHALL: + case TEMPLEHALL: + case WIZARDHALL: + case ELVENHALL: + case ELVENSANCTUM: + case IREKEIHALL: + case FORESTHALL: + maxHealth = (28000 * currentRank) + 4000; + break; + case MINE: + maxHealth = 125000; + break; + case RUNEGATE: + maxHealth = 100000; + break; + case SHRINE: + maxHealth = 100000; + break; + case WAREHOUSE: + maxHealth = 40000; + break; + + default: + maxHealth = 40000; + break; + + } + return maxHealth; + } - // Return 0 health for a destroyed building - // or 1 for a destroyed mine (cleint looting restriction) + // Returns number of vendor slots available + // for the building's current rank. - if (currentRank == -1) { + public int getSlotsForRank(int currentRank) { - return this.buildingGroup == BuildingGroup.MINE ? 1 : 0; - } - - // Return 15k for a constructing mesh - - if (currentRank == 0) - return 15000; - - switch (this.buildingGroup) { - - case TOL: - maxHealth = (70000 * currentRank) + 10000; - break; - case BARRACK: - maxHealth = (35000 * currentRank) + 5000; - break; - case BANESTONE: - maxHealth = (170000 * currentRank) - 120000; - break; - case CHURCH: - maxHealth = (28000 * currentRank) + 4000; - break; - case MAGICSHOP: - case FORGE: - case INN: - case TAILOR: - maxHealth = (17500 * currentRank) + 2500; - break; - case VILLA: - case ESTATE: - case FORTRESS: - maxHealth = 300000; - break; - case CITADEL: - maxHealth = 500000; - break; - case SPIRE: - maxHealth = (37000 * currentRank) - 9000; - break; - case GENERICNOUPGRADE: - case SHACK: - case SIEGETENT: - maxHealth = 40000; - break; - case BULWARK: - if (currentRank == 1) - maxHealth = 110000; - else - maxHealth = 40000; - break; - case WALLSTRAIGHT: - case WALLSTRAIGHTTOWER: - case WALLSTAIRS: - maxHealth = 1000000; - break; - case WALLCORNER: - case ARTYTOWER: - maxHealth = 900000; - break; - case SMALLGATE: - maxHealth = 1100000; - break; - case AMAZONHALL: - case CATHEDRAL: - case GREATHALL: - case KEEP: - case THIEFHALL: - case TEMPLEHALL: - case WIZARDHALL: - case ELVENHALL: - case ELVENSANCTUM: - case IREKEIHALL: - case FORESTHALL: - maxHealth = (28000 * currentRank) + 4000; - break; - case MINE: - maxHealth = 125000; - break; - case RUNEGATE: - maxHealth = 100000; - break; - case SHRINE: - maxHealth = 100000; - break; - case WAREHOUSE: - maxHealth = 40000; - break; - - default: - maxHealth = 40000; - break; - - } - return maxHealth; - } - - // Returns number of vendor slots available - // for the building's current rank. - - public int getSlotsForRank(int currentRank) { - - int availableSlots; - - // Early exit for buildings not yet constructed - - if (currentRank == 0) - return 0; - - // Early exit for buildings with single or no slots - - if (this.maxSlots <= 1) - return maxSlots; - - if (this.maxRank == 1 && currentRank == 1) - return getMaxSlots(); - - switch (currentRank) { - - case 1: - case 2: - availableSlots = 1; - break; - case 3: - case 4: - case 5: - case 6: - availableSlots = 2; - break; - case 7: - availableSlots = 3; - break; - case 8: - availableSlots = 1; - break; - default: - availableSlots = 0; - break; - } - - return availableSlots; - } - - // Returns the half extents of this blueprint's - // bounding box, based upon it's buildinggroup - - public int getIcon() { - return this.icon; - } - - public String getName() { - return this.name; - } - - public int getMeshForRank(int targetRank) { - - int targetMesh = this.blueprintUUID; - - // The Blueprint UUID is the 'constructing' mesh so - // we return that value if the rank passed is 0. + int availableSlots; + + // Early exit for buildings not yet constructed + + if (currentRank == 0) + return 0; + + // Early exit for buildings with single or no slots + + if (this.maxSlots <= 1) + return maxSlots; + + if (this.maxRank == 1 && currentRank == 1) + return getMaxSlots(); + + switch (currentRank) { + + case 1: + case 2: + availableSlots = 1; + break; + case 3: + case 4: + case 5: + case 6: + availableSlots = 2; + break; + case 7: + availableSlots = 3; + break; + case 8: + availableSlots = 1; + break; + default: + availableSlots = 0; + break; + } + + return availableSlots; + } + + // Returns the half extents of this blueprint's + // bounding box, based upon it's buildinggroup + + public int getIcon() { + return this.icon; + } + + public String getName() { + return this.name; + } + + public int getMeshForRank(int targetRank) { + + int targetMesh = this.blueprintUUID; + + // The Blueprint UUID is the 'constructing' mesh so + // we return that value if the rank passed is 0. if ((maxRank == 1) && (this.rank1UUID == 0)) { return blueprintUUID; } - // Set the return value to the proper mesh UID for rank - - switch (targetRank) { - - case -1: - targetMesh = this.destroyedUUID; // -1 Rank is a destroyed mesh - break; - case 0: - targetMesh = this.blueprintUUID; // Rank 0 is the 'constructing' mesh - break; - case 1: - case 2: - targetMesh = this.rank1UUID; - break; - case 3: - case 4: - case 5: - case 6: - targetMesh = this.rank3UUID; - break; - case 7: - case 8: - targetMesh = this.rank7UUID; - break; - default: - break; - } - - return targetMesh; - } - - public int getRankCost(int targetRank) { - - // Set a MAXINT rankcost in case something goes wrong - - int rankCost = Integer.MAX_VALUE; - - // Sanity chack for retrieving a rankcost outside proper range + // Set the return value to the proper mesh UID for rank + + switch (targetRank) { + + case -1: + targetMesh = this.destroyedUUID; // -1 Rank is a destroyed mesh + break; + case 0: + targetMesh = this.blueprintUUID; // Rank 0 is the 'constructing' mesh + break; + case 1: + case 2: + targetMesh = this.rank1UUID; + break; + case 3: + case 4: + case 5: + case 6: + targetMesh = this.rank3UUID; + break; + case 7: + case 8: + targetMesh = this.rank7UUID; + break; + default: + break; + } + + return targetMesh; + } + + public int getRankCost(int targetRank) { + + // Set a MAXINT rankcost in case something goes wrong + + int rankCost = Integer.MAX_VALUE; + + // Sanity chack for retrieving a rankcost outside proper range if ((targetRank > maxRank) || (targetRank < 0)) { - Logger.error( "Attempt to retrieve rankcost for rank of" + targetRank); - return rankCost; - } - - // Select linear equation for rank cost based upon the - // buildings current Maintenance BuildingGroup. - - switch (this.buildingGroup) { - - case GENERICNOUPGRADE: - case WALLSTRAIGHT: - case WALLSTAIRS: - case WALLCORNER: - case SMALLGATE: - case ARTYTOWER: - case SIEGETENT: - case BULWARK: - case BANESTONE: - case SHACK: - break; // This set cannot be upgraded. Returns max integer. - - case TOL: - rankCost = (880000 * targetRank) - 440000; - break; - case BARRACK: - case VILLA: - case ESTATE: - case FORTRESS: - case CITADEL: - rankCost = (451000 * targetRank) - 308000; - break; - case CHURCH: - rankCost = (682000 * targetRank) - 110000; - break; - case FORGE: - case INN: - case TAILOR: - case MAGICSHOP: - rankCost = (440000 * targetRank) - 550000; - break; - case SPIRE: - rankCost = (176000 * targetRank) - 88000; - break; - case AMAZONHALL: - case CATHEDRAL: - case GREATHALL: - case KEEP: - case THIEFHALL: - case TEMPLEHALL: - case WIZARDHALL: - case ELVENHALL: - case ELVENSANCTUM: - case IREKEIHALL: - case FORESTHALL: - rankCost = (682000 * targetRank) - 110000; - break; - default: - Logger.error("Attempt to retrieve rankcost without MaintGroup for " + this.buildingGroup.name()); - break; - } - - return rankCost; - } - - public int getRankTime(int targetRank) { - - // Set a very long rankTime in case something goes wrong - - int rankTime = (Integer.MAX_VALUE / 2); - - // Set all initial construction to a default of 4 hours. - - if (targetRank == 1) - return 4; - - // Sanity chack for retrieving a ranktime outside proper range + Logger.error("Attempt to retrieve rankcost for rank of" + targetRank); + return rankCost; + } + + // Select linear equation for rank cost based upon the + // buildings current Maintenance BuildingGroup. + + switch (this.buildingGroup) { + + case GENERICNOUPGRADE: + case WALLSTRAIGHT: + case WALLSTAIRS: + case WALLCORNER: + case SMALLGATE: + case ARTYTOWER: + case SIEGETENT: + case BULWARK: + case BANESTONE: + case SHACK: + break; // This set cannot be upgraded. Returns max integer. + + case TOL: + rankCost = (880000 * targetRank) - 440000; + break; + case BARRACK: + case VILLA: + case ESTATE: + case FORTRESS: + case CITADEL: + rankCost = (451000 * targetRank) - 308000; + break; + case CHURCH: + rankCost = (682000 * targetRank) - 110000; + break; + case FORGE: + case INN: + case TAILOR: + case MAGICSHOP: + rankCost = (440000 * targetRank) - 550000; + break; + case SPIRE: + rankCost = (176000 * targetRank) - 88000; + break; + case AMAZONHALL: + case CATHEDRAL: + case GREATHALL: + case KEEP: + case THIEFHALL: + case TEMPLEHALL: + case WIZARDHALL: + case ELVENHALL: + case ELVENSANCTUM: + case IREKEIHALL: + case FORESTHALL: + rankCost = (682000 * targetRank) - 110000; + break; + default: + Logger.error("Attempt to retrieve rankcost without MaintGroup for " + this.buildingGroup.name()); + break; + } + + return rankCost; + } + + public int getRankTime(int targetRank) { + + // Set a very long rankTime in case something goes wrong + + int rankTime = (Integer.MAX_VALUE / 2); + + // Set all initial construction to a default of 4 hours. + + if (targetRank == 1) + return 4; + + // Sanity chack for retrieving a ranktime outside proper range if ((targetRank > maxRank) || (targetRank < 1)) { - Logger.error( "Attempt to retrieve ranktime for rank of" + targetRank); - return rankTime; - } - - // Select equation for rank time based upon the - // buildings current Maintenance BuildingGroup. These values - // are expressed in hours - - switch (this.buildingGroup) { - - case GENERICNOUPGRADE: - break; // Cannot be upgraded - case VILLA: - case ESTATE: - case FORTRESS: - case CITADEL: - rankTime = (7 * targetRank) - 7; - break; - case TOL: - rankTime = (7 * targetRank) - 7; - break; - case BARRACK: - rankTime = (7 * targetRank) - 7; - break; - case CHURCH: - rankTime = (7 * targetRank) - 7; - break; - case FORGE: - case INN: - case TAILOR: - case MAGICSHOP: - rankTime = (7 * targetRank) - 7; - break; - case SPIRE: - rankTime = (4 * targetRank) + 4; - break; - case AMAZONHALL: - case CATHEDRAL: - case GREATHALL: - case KEEP: - case THIEFHALL: - case TEMPLEHALL: - case WIZARDHALL: - case ELVENHALL: - case ELVENSANCTUM: - case IREKEIHALL: - case FORESTHALL: - rankTime = (7 * targetRank) - 7; - break; - default: - Logger.error("Attempt to retrieve ranktime without MaintGroup"); - break; - } - - return rankTime; - } - - public Vector2f getExtents() { + Logger.error("Attempt to retrieve ranktime for rank of" + targetRank); + return rankTime; + } + + // Select equation for rank time based upon the + // buildings current Maintenance BuildingGroup. These values + // are expressed in hours + + switch (this.buildingGroup) { + + case GENERICNOUPGRADE: + break; // Cannot be upgraded + case VILLA: + case ESTATE: + case FORTRESS: + case CITADEL: + rankTime = (7 * targetRank) - 7; + break; + case TOL: + rankTime = (7 * targetRank) - 7; + break; + case BARRACK: + rankTime = (7 * targetRank) - 7; + break; + case CHURCH: + rankTime = (7 * targetRank) - 7; + break; + case FORGE: + case INN: + case TAILOR: + case MAGICSHOP: + rankTime = (7 * targetRank) - 7; + break; + case SPIRE: + rankTime = (4 * targetRank) + 4; + break; + case AMAZONHALL: + case CATHEDRAL: + case GREATHALL: + case KEEP: + case THIEFHALL: + case TEMPLEHALL: + case WIZARDHALL: + case ELVENHALL: + case ELVENSANCTUM: + case IREKEIHALL: + case FORESTHALL: + rankTime = (7 * targetRank) - 7; + break; + default: + Logger.error("Attempt to retrieve ranktime without MaintGroup"); + break; + } + + return rankTime; + } + + public Vector2f getExtents() { if (blueprintUUID == 1302600) - return Blueprint.IrikieForgeExtents; - else if (blueprintUUID == 1300600) - return Blueprint.IrikieBarracksExtents; + return Blueprint.IrikieForgeExtents; + else if (blueprintUUID == 1300600) + return Blueprint.IrikieBarracksExtents; - return this.buildingGroup.getExtents(); + return this.buildingGroup.getExtents(); - } + } - public boolean isWallPiece() { + public boolean isWallPiece() { switch (this.buildingGroup) { - case WALLSTRAIGHT: - case WALLSTAIRS: - case ARTYTOWER: - case WALLCORNER: - case SMALLGATE: - return true; - default: - break; - } - return false; - } - - public boolean isSiegeEquip() { + case WALLSTRAIGHT: + case WALLSTAIRS: + case ARTYTOWER: + case WALLCORNER: + case SMALLGATE: + return true; + default: + break; + } + return false; + } + + public boolean isSiegeEquip() { switch (this.buildingGroup) { - case BULWARK: - case SIEGETENT: - return true; - default: - break; - } - return false; + case BULWARK: + case SIEGETENT: + return true; + default: + break; + } + return false; - } + } - public int getBlueprintUUID() { - return blueprintUUID; - } + public int getBlueprintUUID() { + return blueprintUUID; + } - @Override - public boolean equals(Object object) { + @Override + public boolean equals(Object object) { - if ((object instanceof Blueprint) == false) - return false; + if ((object instanceof Blueprint) == false) + return false; - Blueprint blueprint = (Blueprint) object; + Blueprint blueprint = (Blueprint) object; return this.blueprintUUID == blueprint.blueprintUUID; - } + } - @Override - public int hashCode() { + @Override + public int hashCode() { - return this.blueprintUUID ; - } + return this.blueprintUUID; + } - public int getMaintCost(int rank) { + public int getMaintCost(int rank) { - int maintCost = Integer.MAX_VALUE; + int maintCost = Integer.MAX_VALUE; switch (this.buildingGroup) { - case TOL: - case BARRACK: - maintCost = (61500 * rank) + 19500; - break; - case SPIRE: - maintCost = (4800 * rank) + 1200; - break; - default: - if (maxRank == 1) - maintCost = 22500; - else - maintCost = (15900 * rank) + 3300; - break; - } - - return maintCost; - } + case TOL: + case BARRACK: + maintCost = (61500 * rank) + 19500; + break; + case SPIRE: + maintCost = (4800 * rank) + 1200; + break; + default: + if (maxRank == 1) + maintCost = 22500; + else + maintCost = (15900 * rank) + 3300; + break; + } + + return maintCost; + } } diff --git a/src/engine/objects/Boon.java b/src/engine/objects/Boon.java index 29908b05..2cdcfd94 100644 --- a/src/engine/objects/Boon.java +++ b/src/engine/objects/Boon.java @@ -18,47 +18,42 @@ import java.util.ArrayList; import java.util.HashMap; +public class Boon { -public class Boon { + public static HashMap> GetBoonsForItemBase = new HashMap<>(); + private ShrineType shrineType; + private int amount; + private int itemBaseID; - private ShrineType shrineType; - private int amount; - private int itemBaseID; - public static HashMap> GetBoonsForItemBase = new HashMap<>(); + /** + * ResultSet Constructor + */ + public Boon(ResultSet rs) throws SQLException { - /** - * ResultSet Constructor - */ - public Boon(ResultSet rs) throws SQLException { + this.shrineType = ShrineType.valueOf(rs.getString("shrineType")); + this.itemBaseID = rs.getInt("itemBaseID"); + this.amount = rs.getInt("amount"); + } - this.shrineType = ShrineType.valueOf(rs.getString("shrineType")); - this.itemBaseID = rs.getInt("itemBaseID"); - this.amount = rs.getInt("amount"); - } + public static void HandleBoonListsForItemBase(int itemBaseID) { + ArrayList boons = null; + boons = DbManager.BoonQueries.GET_BOON_AMOUNTS_FOR_ITEMBASE(itemBaseID); + if (boons != null) + GetBoonsForItemBase.put(itemBaseID, boons); + } - public int getAmount() { - return this.amount; - } + public int getAmount() { + return this.amount; + } - + public int getItemBaseID() { + return itemBaseID; + } - public int getItemBaseID() { - return itemBaseID; - } + public ShrineType getShrineType() { + return shrineType; + } - public ShrineType getShrineType() { - return shrineType; - } - - - public static void HandleBoonListsForItemBase(int itemBaseID){ - ArrayList boons = null; - boons = DbManager.BoonQueries.GET_BOON_AMOUNTS_FOR_ITEMBASE(itemBaseID); - if (boons != null) - GetBoonsForItemBase.put(itemBaseID, boons); - } - - } diff --git a/src/engine/objects/BootySetEntry.java b/src/engine/objects/BootySetEntry.java index a159b2ac..ff22bbaf 100644 --- a/src/engine/objects/BootySetEntry.java +++ b/src/engine/objects/BootySetEntry.java @@ -14,24 +14,24 @@ import java.sql.SQLException; public class BootySetEntry { - public String bootyType; - public int lowGold; - public int highGold; - public int itemBase; - public int lootTable; - public float dropChance; - - /** - * ResultSet Constructor - */ - - public BootySetEntry(ResultSet rs) throws SQLException { - this.bootyType = (rs.getString("bootyType")); - this.lowGold = (rs.getInt("lowGold")); - this.highGold = (rs.getInt("highGold")); - this.itemBase = (rs.getInt("itemBase")); - this.lootTable = (rs.getInt("lootTable")); - this.dropChance = (rs.getFloat("dropChance")); - } + public String bootyType; + public int lowGold; + public int highGold; + public int itemBase; + public int lootTable; + public float dropChance; + + /** + * ResultSet Constructor + */ + + public BootySetEntry(ResultSet rs) throws SQLException { + this.bootyType = (rs.getString("bootyType")); + this.lowGold = (rs.getInt("lowGold")); + this.highGold = (rs.getInt("highGold")); + this.itemBase = (rs.getInt("itemBase")); + this.lootTable = (rs.getInt("lootTable")); + this.dropChance = (rs.getFloat("dropChance")); + } } diff --git a/src/engine/objects/Building.java b/src/engine/objects/Building.java index a2e6fc81..0b058624 100644 --- a/src/engine/objects/Building.java +++ b/src/engine/objects/Building.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.objects; import engine.Enum; @@ -49,1667 +48,1664 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; public class Building extends AbstractWorldObject { - // Used for thread safety - - private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); - - /* The Blueprint class has methods able to derive - * all defining characteristics of this building, - */ - private int blueprintUUID = 0; - public int meshUUID; - private float w = 1.0f; - private Vector3f meshScale = new Vector3f(1.0f, 1.0f, 1.0f); - private int doorState = 0; - private int ownerUUID = 0; //NPC or Character--check ownerIsNPC flag - private int _strongboxValue = 0; - private int maxGold; - private int effectFlags = 0; - private String name = ""; - private int rank; - private boolean ownerIsNPC = true; - private boolean spireIsActive = false; - public Zone parentZone; - public boolean reverseKOS; - public int reserve = 0; - - // Variables NOT to be stored in db - - protected Resists resists; - public float statLat; - public float statLon; - public float statAlt; - private ConcurrentHashMap timers = null; - private ConcurrentHashMap timestamps = null; - private final ConcurrentHashMap hirelings = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private final HashMap doorJobs = new HashMap<>(); - private ConcurrentHashMap friends = new ConcurrentHashMap<>(); - private ConcurrentHashMap condemned = new ConcurrentHashMap<>(); - public LocalDateTime upgradeDateTime = null; - public LocalDateTime taxDateTime = null; - private ProtectionState protectionState = ProtectionState.NONE; - - public ArrayList patrolPoints = new ArrayList<>(); - public ArrayList sentryPoints = new ArrayList<>(); - public TaxType taxType = TaxType.NONE; - public int taxAmount; - public boolean enforceKOS = false; - - public int parentBuildingID; - public boolean isFurniture = false; - - public int floor; - public int level; - public AtomicBoolean isDeranking = new AtomicBoolean(false); - private ArrayList children = null; - public LocalDateTime maintDateTime; - - /** - * ResultSet Constructor - */ - - public Building(ResultSet rs) throws SQLException { - super(rs); - - float scale; - Blueprint blueprint = null; - - try { - this.meshUUID = rs.getInt("meshUUID"); - this.setObjectTypeMask(MBServerStatics.MASK_BUILDING); - this.blueprintUUID = rs.getInt("blueprintUUID"); - this.gridObjectType = GridObjectType.STATIC; - this.parentZone = DbManager.ZoneQueries.GET_BY_UID(rs.getLong("parent")); - this.name = rs.getString("name"); - this.ownerUUID = rs.getInt("ownerUUID"); - - // Orphaned Object Sanity Check - //This was causing ABANDONED Tols. - // if (objectType == DbObjectType.INVALID) - // this.ownerUUID = 0; - - this.doorState = rs.getInt("doorState"); - this.setHealth(rs.getInt("currentHP")); - this.w = rs.getFloat("w"); - this.setRot(new Vector3f(0f, rs.getFloat("rotY"), 0f)); - this.reverseKOS = rs.getByte("reverseKOS") == 1 ? true : false; - - scale = rs.getFloat("scale"); - this.meshScale = new Vector3f(scale, scale, scale); - - this.rank = rs.getInt("rank"); - this.parentBuildingID = rs.getInt("parentBuildingID"); - - //create a new list if the building is a parent and not a child. - - if (this.parentBuildingID == 0) - this.children = new ArrayList<>(); - - this.floor = rs.getInt("floor"); - this.level = rs.getInt("level"); - this.isFurniture = (rs.getBoolean("isFurniture")); - - // Lookup building blueprint - - if (this.blueprintUUID == 0) - blueprint = Blueprint._meshLookup.get(meshUUID); - else - blueprint = this.getBlueprint(); - - // Log error if something went horrible wrong - - if ((this.blueprintUUID != 0) && (blueprint == null)) - Logger.error( "Invalid blueprint for object: " + this.getObjectUUID()); - - // Note: We handle R8 tree edge case for mesh and health - // after city is loaded to avoid recursive result set call - // in City resulting in a stack ovreflow. - - if (blueprint != null) { - - // Only switch mesh for player dropped structures - - if (this.blueprintUUID != 0) - this.meshUUID = blueprint.getMeshForRank(rank); - - this.healthMax = blueprint.getMaxHealth(this.rank); - - // If this object has no blueprint but is a blueprint + // Used for thread safety + + private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); + private final ConcurrentHashMap hirelings = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private final HashMap doorJobs = new HashMap<>(); + public int meshUUID; + public Zone parentZone; + public boolean reverseKOS; + public int reserve = 0; + public float statLat; + public float statLon; + public float statAlt; + public LocalDateTime upgradeDateTime = null; + public LocalDateTime taxDateTime = null; + public ArrayList patrolPoints = new ArrayList<>(); + public ArrayList sentryPoints = new ArrayList<>(); + public TaxType taxType = TaxType.NONE; + public int taxAmount; + public boolean enforceKOS = false; + + // Variables NOT to be stored in db + public int parentBuildingID; + public boolean isFurniture = false; + public int floor; + public int level; + public AtomicBoolean isDeranking = new AtomicBoolean(false); + public LocalDateTime maintDateTime; + protected Resists resists; + /* The Blueprint class has methods able to derive + * all defining characteristics of this building, + */ + private int blueprintUUID = 0; + private float w = 1.0f; + private Vector3f meshScale = new Vector3f(1.0f, 1.0f, 1.0f); + private int doorState = 0; + private int ownerUUID = 0; //NPC or Character--check ownerIsNPC flag + private int _strongboxValue = 0; + private int maxGold; + private int effectFlags = 0; + private String name = ""; + private int rank; + private boolean ownerIsNPC = true; + private boolean spireIsActive = false; + private ConcurrentHashMap timers = null; + private ConcurrentHashMap timestamps = null; + private ConcurrentHashMap friends = new ConcurrentHashMap<>(); + private ConcurrentHashMap condemned = new ConcurrentHashMap<>(); + private ProtectionState protectionState = ProtectionState.NONE; + private ArrayList children = null; + + /** + * ResultSet Constructor + */ + + public Building(ResultSet rs) throws SQLException { + super(rs); + + float scale; + Blueprint blueprint = null; + + try { + this.meshUUID = rs.getInt("meshUUID"); + this.setObjectTypeMask(MBServerStatics.MASK_BUILDING); + this.blueprintUUID = rs.getInt("blueprintUUID"); + this.gridObjectType = GridObjectType.STATIC; + this.parentZone = DbManager.ZoneQueries.GET_BY_UID(rs.getLong("parent")); + this.name = rs.getString("name"); + this.ownerUUID = rs.getInt("ownerUUID"); + + // Orphaned Object Sanity Check + //This was causing ABANDONED Tols. + // if (objectType == DbObjectType.INVALID) + // this.ownerUUID = 0; + + this.doorState = rs.getInt("doorState"); + this.setHealth(rs.getInt("currentHP")); + this.w = rs.getFloat("w"); + this.setRot(new Vector3f(0f, rs.getFloat("rotY"), 0f)); + this.reverseKOS = rs.getByte("reverseKOS") == 1 ? true : false; + + scale = rs.getFloat("scale"); + this.meshScale = new Vector3f(scale, scale, scale); + + this.rank = rs.getInt("rank"); + this.parentBuildingID = rs.getInt("parentBuildingID"); + + //create a new list if the building is a parent and not a child. + + if (this.parentBuildingID == 0) + this.children = new ArrayList<>(); + + this.floor = rs.getInt("floor"); + this.level = rs.getInt("level"); + this.isFurniture = (rs.getBoolean("isFurniture")); + + // Lookup building blueprint + + if (this.blueprintUUID == 0) + blueprint = Blueprint._meshLookup.get(meshUUID); + else + blueprint = this.getBlueprint(); + + // Log error if something went horrible wrong + + if ((this.blueprintUUID != 0) && (blueprint == null)) + Logger.error("Invalid blueprint for object: " + this.getObjectUUID()); + + // Note: We handle R8 tree edge case for mesh and health + // after city is loaded to avoid recursive result set call + // in City resulting in a stack ovreflow. + + if (blueprint != null) { + + // Only switch mesh for player dropped structures + + if (this.blueprintUUID != 0) + this.meshUUID = blueprint.getMeshForRank(rank); + + this.healthMax = blueprint.getMaxHealth(this.rank); + + // If this object has no blueprint but is a blueprint // mesh then set it's current health to max health - if (this.blueprintUUID == 0) + if (this.blueprintUUID == 0) this.setHealth(healthMax); - if (blueprint.getBuildingGroup().equals(BuildingGroup.BARRACK)) - this.patrolPoints = DbManager.BuildingQueries.LOAD_PATROL_POINTS(this); + if (blueprint.getBuildingGroup().equals(BuildingGroup.BARRACK)) + this.patrolPoints = DbManager.BuildingQueries.LOAD_PATROL_POINTS(this); - } else{ - this.healthMax = 100000; // Structures with no blueprint mesh + } else { + this.healthMax = 100000; // Structures with no blueprint mesh this.setHealth(healthMax); } - // Null out blueprint if not needed (npc building) + // Null out blueprint if not needed (npc building) + + if (blueprintUUID == 0) + blueprint = null; + + resists = new Resists("Building"); + this.statLat = rs.getFloat("locationX"); + this.statAlt = rs.getFloat("locationY"); + this.statLon = rs.getFloat("locationZ"); + + if (this.parentZone != null) { + if (this.parentBuildingID != 0) { + Building parentBuilding = BuildingManager.getBuilding(this.parentBuildingID); + if (parentBuilding != null) { + this.setLoc(new Vector3fImmutable(this.statLat + this.parentZone.absX + parentBuilding.statLat, this.statAlt + this.parentZone.absY + parentBuilding.statAlt, this.statLon + this.parentZone.absZ + parentBuilding.statLon)); + } else { + this.setLoc(new Vector3fImmutable(this.statLat + this.parentZone.absX, this.statAlt + this.parentZone.absY, this.statLon + this.parentZone.absZ)); + + } + } else { + + // Altitude of this building is derived from the heightmap engine. + + Vector3fImmutable tempLoc = new Vector3fImmutable(this.statLat + this.parentZone.absX, 0, this.statLon + this.parentZone.absZ); + tempLoc = new Vector3fImmutable(tempLoc.x, HeightMap.getWorldHeight(tempLoc), tempLoc.z); + this.setLoc(tempLoc); + } + } + + this._strongboxValue = rs.getInt("currentGold"); + this.maxGold = 15000000; // *** Refactor to blueprint method + this.reserve = rs.getInt("reserve"); + + // Does building have a protection contract? + this.taxType = TaxType.valueOf(rs.getString("taxType")); + this.taxAmount = rs.getInt("taxAmount"); + this.protectionState = ProtectionState.valueOf(rs.getString("protectionState")); + + java.sql.Timestamp maintTimeStamp = rs.getTimestamp("maintDate"); + + if (maintTimeStamp != null) + this.maintDateTime = LocalDateTime.ofInstant(maintTimeStamp.toInstant(), ZoneId.systemDefault()); + + java.sql.Timestamp taxTimeStamp = rs.getTimestamp("taxDate"); + + if (taxTimeStamp != null) + this.taxDateTime = LocalDateTime.ofInstant(taxTimeStamp.toInstant(), ZoneId.systemDefault()); + + java.sql.Timestamp upgradeTimeStamp = rs.getTimestamp("upgradeDate"); - if (blueprintUUID == 0) - blueprint = null; + if (upgradeTimeStamp != null) + this.upgradeDateTime = LocalDateTime.ofInstant(upgradeTimeStamp.toInstant(), ZoneId.systemDefault()); - resists = new Resists("Building"); - this.statLat = rs.getFloat("locationX"); - this.statAlt = rs.getFloat("locationY"); - this.statLon = rs.getFloat("locationZ"); + } catch (Exception e) { - if (this.parentZone != null){ - if (this.parentBuildingID != 0){ - Building parentBuilding = BuildingManager.getBuilding(this.parentBuildingID); - if (parentBuilding != null){ - this.setLoc(new Vector3fImmutable(this.statLat + this.parentZone.absX + parentBuilding.statLat, this.statAlt + this.parentZone.absY + parentBuilding.statAlt, this.statLon + this.parentZone.absZ + parentBuilding.statLon)); - }else{ - this.setLoc(new Vector3fImmutable(this.statLat + this.parentZone.absX, this.statAlt + this.parentZone.absY, this.statLon + this.parentZone.absZ)); + Logger.error("Failed for object " + this.blueprintUUID + ' ' + this.getObjectUUID() + e.toString()); + } + } - } - } else { + /* + * Getters + */ - // Altitude of this building is derived from the heightmap engine. + public static void _serializeForClientMsg(Building building, ByteBufferWriter writer) { + writer.putInt(building.getObjectType().ordinal()); + writer.putInt(building.getObjectUUID()); + writer.putInt(0); // pad - Vector3fImmutable tempLoc = new Vector3fImmutable(this.statLat + this.parentZone.absX, 0, this.statLon + this.parentZone.absZ); - tempLoc = new Vector3fImmutable(tempLoc.x, HeightMap.getWorldHeight(tempLoc), tempLoc.z); - this.setLoc(tempLoc); - } - } + writer.putInt(building.meshUUID); - this._strongboxValue = rs.getInt("currentGold"); - this.maxGold = 15000000; // *** Refactor to blueprint method - this.reserve = rs.getInt("reserve"); + writer.putInt(0); // pad - // Does building have a protection contract? - this.taxType = TaxType.valueOf(rs.getString("taxType")); - this.taxAmount = rs.getInt("taxAmount"); - this.protectionState = ProtectionState.valueOf(rs.getString("protectionState")); + if (building.parentBuildingID != 0) { - java.sql.Timestamp maintTimeStamp = rs.getTimestamp("maintDate"); + writer.putFloat(building.statLat); + writer.putFloat(building.statAlt); + writer.putFloat(building.statLon); - if (maintTimeStamp != null) - this.maintDateTime = LocalDateTime.ofInstant(maintTimeStamp.toInstant(), ZoneId.systemDefault()); + } else { + writer.putFloat(building.getLoc().getX()); + writer.putFloat(building.getLoc().getY()); // Y location + writer.putFloat(building.getLoc().getZ()); + } - java.sql.Timestamp taxTimeStamp = rs.getTimestamp("taxDate"); + writer.putFloat(building.w); + writer.putFloat(0f); + writer.putFloat(building.getRot().y); - if (taxTimeStamp != null) - this.taxDateTime = LocalDateTime.ofInstant(taxTimeStamp.toInstant(), ZoneId.systemDefault()); + writer.putFloat(0f); + writer.putFloat(building.meshScale.getX()); + writer.putFloat(building.meshScale.getY()); + writer.putFloat(building.meshScale.getZ()); - java.sql.Timestamp upgradeTimeStamp = rs.getTimestamp("upgradeDate"); + if (building.parentBuildingID != 0) { + writer.putInt(GameObjectType.Building.ordinal()); + writer.putInt(building.parentBuildingID); + writer.putInt(building.floor); + writer.putInt(building.level); - if (upgradeTimeStamp != null) - this.upgradeDateTime = LocalDateTime.ofInstant(upgradeTimeStamp.toInstant(), ZoneId.systemDefault()); + } else { + writer.putInt(0); // Pad //Parent + writer.putInt(0); // Pad + writer.putInt(-1); // Static + writer.putInt(-1); // Static + } - } catch (Exception e) { + writer.put((byte) 0); // 0 + writer.putFloat(3); // 3 + writer.putInt(GameObjectType.Building.ordinal()); + writer.putInt(building.getObjectUUID()); - Logger.error( "Failed for object " + this.blueprintUUID + ' ' + this.getObjectUUID() + e.toString()); - } - } + if (building.ownerIsNPC) + writer.putInt(GameObjectType.NPC.ordinal()); + else + writer.putInt(GameObjectType.PlayerCharacter.ordinal()); - /* - * Getters - */ + writer.putInt(building.ownerUUID); - public final boolean isRanking() { + writer.put((byte) 1); // End Datablock + writer.putFloat(building.health.get()); + writer.putFloat(building.healthMax); - return this.upgradeDateTime != null; - } + if (building.blueprintUUID == 0) + writer.putInt(0); + else + writer.putInt(building.getBlueprint().getIcon()); - public final int getRank() { - return rank; - } + writer.putInt(building.effectFlags); - public final int getOwnerUUID() { - return ownerUUID; - } + writer.put((byte) 1); // End Datablock + Guild g = building.getGuild(); + Guild nation = null; - public final boolean isOwnerIsNPC() { - return ownerIsNPC; - } + if (g == null) { - public final City getCity() { + for (int i = 0; i < 3; i++) { + writer.putInt(16); + } + for (int i = 0; i < 2; i++) { + writer.putInt(0); + } + } else { + GuildTag._serializeForDisplay(g.getGuildTag(), writer); + nation = g.getNation(); + } + writer.put((byte) 1); // End Datablock? + if (nation == null) { + for (int i = 0; i < 3; i++) { + writer.putInt(16); + } + for (int i = 0; i < 2; i++) { + writer.putInt(0); + } + } else + GuildTag._serializeForDisplay(nation.getGuildTag(), writer); + writer.putString(building.name); + writer.put((byte) 0); // End datablock + } - if (this.parentZone == null) - return null; + public final boolean isRanking() { - if (this.getBlueprint() != null && this.getBlueprint().isSiegeEquip() && this.protectionState.equals(ProtectionState.PROTECTED)){ - if (this.getGuild() != null){ - if (this.getGuild().getOwnedCity() != null){ - if (this.getLoc().isInsideCircle(this.getGuild().getOwnedCity().getLoc(), CityBoundsType.ZONE.extents)) - return this.getGuild().getOwnedCity(); - }else{ - Bane bane = Bane.getBaneByAttackerGuild(this.getGuild()); - - if (bane != null){ - if (bane.getCity() != null){ - if (this.getLoc().isInsideCircle(bane.getCity().getLoc(), CityBoundsType.ZONE.extents)) - return bane.getCity(); - } - } - } - } - } - if (this.parentZone.isPlayerCity() == false) - return null; + return this.upgradeDateTime != null; + } - return City.getCity(this.parentZone.getPlayerCityUUID()); + public final int getRank() { + return rank; + } - } + public final void setRank(int newRank) { - public final String getCityName() { + int newMeshUUID; + boolean success; - City city = getCity(); - if (city != null) - return city.getName(); + // If this building has no blueprint then set rank and exit immediatly. - return ""; - } + if (this.blueprintUUID == 0 || this.getBlueprint() != null && this.getBlueprint().getBuildingGroup().equals(BuildingGroup.MINE)) { + this.rank = newRank; + DbManager.BuildingQueries.CHANGE_RANK(this.getObjectUUID(), newRank); + return; + } - public final Blueprint getBlueprint() { + // Delete any upgrade jobs before doing anything else. It won't quite work + // if in a few lines we happen to delete this building. - if (this.blueprintUUID == 0) - return null; + JobContainer jc = this.getTimers().get("UPGRADE"); - return Blueprint.getBlueprint(this.blueprintUUID); + if (jc != null) { + if (!JobScheduler.getInstance().cancelScheduledJob(jc)) + Logger.error("failed to cancel existing upgrade job."); + } - } + // Attempt write to database, or delete the building + // if we are destroying it. - public final int getBlueprintUUID() { + if (newRank == -1) + success = DbManager.BuildingQueries.DELETE_FROM_DATABASE(this); + else + success = DbManager.BuildingQueries.updateBuildingRank(this, newRank); - return this.blueprintUUID; - } + if (success == false) { + Logger.error("Error writing to database UUID: " + this.getObjectUUID()); + return; + } - public final void setCurrentHitPoints(Float CurrentHitPoints) { - this.addDatabaseJob("health", MBServerStatics.ONE_MINUTE); - this.setHealth(CurrentHitPoints); - } + this.isDeranking.compareAndSet(false, true); - public final LocalDateTime getUpgradeDateTime() { - lock.readLock().lock(); - try { - return upgradeDateTime; - } finally { - lock.readLock().unlock(); - } - } + // Change the building's rank - public final float modifyHealth(final float value, final AbstractCharacter attacker) { + this.rank = newRank; - if (this.rank == -1) - return 0f; + // New rank means new mesh - boolean worked = false; - Float oldHealth=0f, newHealth=0f; - while (!worked) { - if (this.rank == -1) - return 0f; - oldHealth = this.health.get(); - newHealth = oldHealth + value; - if (newHealth > this.healthMax) - newHealth = healthMax; - worked = this.health.compareAndSet(oldHealth, newHealth); - } + newMeshUUID = this.getBlueprint().getMeshForRank(this.rank); + this.meshUUID = newMeshUUID; - if (newHealth < 0) { - if (this.isDeranking.compareAndSet(false, true)) { - this.destroyOrDerank(attacker); - } + // New rank mean new max hitpoints. - return newHealth - oldHealth; - } else - this.addDatabaseJob("health", MBServerStatics.ONE_MINUTE); + this.healthMax = this.getBlueprint().getMaxHealth(this.rank); + this.setCurrentHitPoints(this.healthMax); - if (value < 0) - Mine.SendMineAttackMessage(this); + if (this.getUpgradeDateTime() != null) + BuildingManager.setUpgradeDateTime(this, null, 0); - return newHealth - oldHealth; + // If we destroyed this building make sure to turn off + // protection + if (this.rank == -1) + this.protectionState = ProtectionState.NONE; - } + if ((this.getBlueprint().getBuildingGroup() == BuildingGroup.TOL) + && (this.rank == 8)) + this.meshUUID = Realm.getRealmMesh(this.getCity()); + ; - //This method is to handle when a building is damaged below 0 health. - //Either destroy or derank it. + // update object to clients - public final void destroyOrDerank(AbstractCharacter attacker) { + this.refresh(true); + if (this.getBounds() != null) + this.getBounds().setBounds(this); - Blueprint blueprint; - City city; + // Cleanup hirelings resulting from rank change - // Sanity check: Early exit if a non - // blueprinted object is attempting to - // derank. + BuildingManager.cleanupHirelings(this); - if (this.blueprintUUID == 0) - return; + this.isDeranking.compareAndSet(true, false); + } - blueprint = this.getBlueprint(); - city = this.getCity(); + public final int getOwnerUUID() { + return ownerUUID; + } - // Special handling of destroyed Banes + public final boolean isOwnerIsNPC() { + return ownerIsNPC; + } - if (blueprint.getBuildingGroup() == BuildingGroup.BANESTONE) { - city.getBane().endBane(SiegeResult.DEFEND); - return; - } + public final City getCity() { - // Special handling of warehouses + if (this.parentZone == null) + return null; - if (blueprint.getBuildingGroup() == BuildingGroup.WAREHOUSE) - if (city != null) - city.setWarehouseBuildingID(0); + if (this.getBlueprint() != null && this.getBlueprint().isSiegeEquip() && this.protectionState.equals(ProtectionState.PROTECTED)) { + if (this.getGuild() != null) { + if (this.getGuild().getOwnedCity() != null) { + if (this.getLoc().isInsideCircle(this.getGuild().getOwnedCity().getLoc(), CityBoundsType.ZONE.extents)) + return this.getGuild().getOwnedCity(); + } else { + Bane bane = Bane.getBaneByAttackerGuild(this.getGuild()); - // Special handling of destroyed Spires + if (bane != null) { + if (bane.getCity() != null) { + if (this.getLoc().isInsideCircle(bane.getCity().getLoc(), CityBoundsType.ZONE.extents)) + return bane.getCity(); + } + } + } + } + } + if (this.parentZone.isPlayerCity() == false) + return null; - if ((blueprint.getBuildingGroup() == BuildingGroup.SPIRE) && this.rank == 1) - this.disableSpire(true); + return City.getCity(this.parentZone.getPlayerCityUUID()); - // Special handling of destroyed Mines + } - if (blueprint.getBuildingGroup() == BuildingGroup.MINE - && this.rank == 1) { + public final String getCityName() { - Mine mine = Mine.getMineFromTower(this.getObjectUUID()); + City city = getCity(); - if (mine != null) { + if (city != null) + return city.getName(); - // Warehouse mine destruction event + return ""; + } - MineRecord mineRecord = MineRecord.borrow(mine, attacker, RecordEventType.DESTROY); - DataWarehouse.pushToWarehouse(mineRecord); + public final Blueprint getBlueprint() { - this.setRank(-1); - this.setCurrentHitPoints((float) 1); - this.healthMax = (float) 1; - this.meshUUID = this.getBlueprint().getMeshForRank(this.rank); - mine.handleDestroyMine(); - this.getBounds().setBounds(this); - this.refresh(true); - return; - } - } + if (this.blueprintUUID == 0) + return null; - // Special handling of deranking Trees + return Blueprint.getBlueprint(this.blueprintUUID); - if (blueprint.getBuildingGroup() == BuildingGroup.TOL) { - derankTreeOfLife(); - return; - } + } - // If codepath reaches here then it's a regular - // structure not requiring special handling. - // Time to either derank or destroy the building. + public final int getBlueprintUUID() { - if ((this.rank - 1) < 1) - this.setRank(-1); - else - this.setRank(this.rank - 1); + return this.blueprintUUID; + } - } + public final void setCurrentHitPoints(Float CurrentHitPoints) { + this.addDatabaseJob("health", MBServerStatics.ONE_MINUTE); + this.setHealth(CurrentHitPoints); + } - private void derankTreeOfLife() { + //This method is to handle when a building is damaged below 0 health. + //Either destroy or derank it. - City city; - Bane bane; - Realm cityRealm;ArrayList spireBuildings = new ArrayList<>(); - ArrayList shrineBuildings = new ArrayList<>(); - ArrayList barracksBuildings = new ArrayList<>(); - Building spireBuilding; - Building shrineBuilding; - SiegeResult siegeResult; - AbstractCharacter newOwner; + public final LocalDateTime getUpgradeDateTime() { + lock.readLock().lock(); + try { + return upgradeDateTime; + } finally { + lock.readLock().unlock(); + } + } - city = this.getCity(); + public final float modifyHealth(final float value, final AbstractCharacter attacker) { - if (city == null) { - Logger.error("No city for tree of uuid" + this.getObjectUUID()); - return; - } + if (this.rank == -1) + return 0f; - bane = city.getBane(); + boolean worked = false; + Float oldHealth = 0f, newHealth = 0f; + while (!worked) { + if (this.rank == -1) + return 0f; + oldHealth = this.health.get(); + newHealth = oldHealth + value; + if (newHealth > this.healthMax) + newHealth = healthMax; + worked = this.health.compareAndSet(oldHealth, newHealth); + } - // We need to collect the spires and shrines on the citygrid in case - // they will be deleted as excess as the tree deranks. + if (newHealth < 0) { + if (this.isDeranking.compareAndSet(false, true)) { + this.destroyOrDerank(attacker); + } - for (Building building : city.getParent().zoneBuildingSet) { + return newHealth - oldHealth; + } else + this.addDatabaseJob("health", MBServerStatics.ONE_MINUTE); - //don't add -1 rank buildings. + if (value < 0) + Mine.SendMineAttackMessage(this); - if (building.rank <= 0) - continue; - if (building.getBlueprint() != null && building.getBlueprint().getBuildingGroup() == BuildingGroup.SPIRE) - spireBuildings.add(building); + return newHealth - oldHealth; - if (building.getBlueprint() != null && building.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE) - shrineBuildings.add(building); - if (building.getBlueprint() != null && building.getBlueprint().getBuildingGroup() == BuildingGroup.BARRACK) - barracksBuildings.add(building); - } + } - // A tree can only hold so many spires. As it deranks we need to delete - // the excess + public final void destroyOrDerank(AbstractCharacter attacker) { - if (spireBuildings.size() > Blueprint.getMaxShrines(this.rank - 1)) { + Blueprint blueprint; + City city; - spireBuilding = spireBuildings.get(0); + // Sanity check: Early exit if a non + // blueprinted object is attempting to + // derank. - // Disable and delete a random spire + if (this.blueprintUUID == 0) + return; - if (spireBuilding != null) { - spireBuilding.disableSpire(true); - spireBuilding.setRank(-1); - } - } + blueprint = this.getBlueprint(); + city = this.getCity(); - if (shrineBuildings.size() > Blueprint.getMaxShrines(this.rank - 1)) { + // Special handling of destroyed Banes - shrineBuilding = shrineBuildings.get(0); + if (blueprint.getBuildingGroup() == BuildingGroup.BANESTONE) { + city.getBane().endBane(SiegeResult.DEFEND); + return; + } - // Delete a random shrine + // Special handling of warehouses - if (shrineBuilding != null) - shrineBuilding.setRank(-1); - } + if (blueprint.getBuildingGroup() == BuildingGroup.WAREHOUSE) + if (city != null) + city.setWarehouseBuildingID(0); - if (barracksBuildings.size() > this.rank - 1) { + // Special handling of destroyed Spires - Building barracksBuilding = barracksBuildings.get(0); + if ((blueprint.getBuildingGroup() == BuildingGroup.SPIRE) && this.rank == 1) + this.disableSpire(true); - // Delete a random barrack + // Special handling of destroyed Mines - if (barracksBuilding != null) - barracksBuilding.setRank(-1); - } + if (blueprint.getBuildingGroup() == BuildingGroup.MINE + && this.rank == 1) { - // If the tree is R8 and deranking, we need to update it's - // mesh along with buildings losing their health bonus + Mine mine = Mine.getMineFromTower(this.getObjectUUID()); - if (this.rank == 8) { + if (mine != null) { - cityRealm = city.getRealm(); + // Warehouse mine destruction event - if (cityRealm != null) - cityRealm.abandonRealm(); + MineRecord mineRecord = MineRecord.borrow(mine, attacker, RecordEventType.DESTROY); + DataWarehouse.pushToWarehouse(mineRecord); - for (Building cityBuilding : this.parentZone.zoneBuildingSet) { + this.setRank(-1); + this.setCurrentHitPoints((float) 1); + this.healthMax = (float) 1; + this.meshUUID = this.getBlueprint().getMeshForRank(this.rank); + mine.handleDestroyMine(); + this.getBounds().setBounds(this); + this.refresh(true); + return; + } + } - if ((cityBuilding.getBlueprint() != null && cityBuilding.getBlueprint().getBuildingGroup() != BuildingGroup.TOL) - && (cityBuilding.getBlueprint().getBuildingGroup() != BuildingGroup.BANESTONE)) { - cityBuilding.healthMax = cityBuilding.getBlueprint().getMaxHealth(cityBuilding.rank); - } + // Special handling of deranking Trees - if (cityBuilding.health.get() > cityBuilding.healthMax) - cityBuilding.setHealth(cityBuilding.healthMax); - } - } + if (blueprint.getBuildingGroup() == BuildingGroup.TOL) { + derankTreeOfLife(); + return; + } - // Tree is simply deranking. - // Let's do so and early exit + // If codepath reaches here then it's a regular + // structure not requiring special handling. + // Time to either derank or destroy the building. - if (this.rank > 1) { - this.setRank(rank - 1); - City.lastCityUpdate = System.currentTimeMillis(); - return; - } + if ((this.rank - 1) < 1) + this.setRank(-1); + else + this.setRank(this.rank - 1); - // Must remove a bane before considering destruction of a TOL + } - if (bane != null) { + // Return the maint cost in gold associated with this structure - // Cache the new owner + private void derankTreeOfLife() { - newOwner = Guild.GetGL(bane.getOwner().getGuild()); + City city; + Bane bane; + Realm cityRealm; + ArrayList spireBuildings = new ArrayList<>(); + ArrayList shrineBuildings = new ArrayList<>(); + ArrayList barracksBuildings = new ArrayList<>(); + Building spireBuilding; + Building shrineBuilding; + SiegeResult siegeResult; + AbstractCharacter newOwner; - this.isDeranking.compareAndSet(false, true); + city = this.getCity(); - if ((bane.getOwner().getGuild().getGuildState() == GuildState.Sovereign) || - (bane.getOwner().getGuild().getGuildState() == GuildState.Protectorate) || - (bane.getOwner().getGuild().getGuildState() == GuildState.Province) || - (bane.getOwner().getGuild().getGuildState() == GuildState.Nation)) - siegeResult = SiegeResult.DESTROY; - else - siegeResult = SiegeResult.CAPTURE; + if (city == null) { + Logger.error("No city for tree of uuid" + this.getObjectUUID()); + return; + } - // Remove realm if city had one + bane = city.getBane(); - Realm realm = RealmMap.getRealmAtLocation(city.getLoc()); + // We need to collect the spires and shrines on the citygrid in case + // they will be deleted as excess as the tree deranks. - if (realm != null) - if (realm.isRealmFullAfterBane()) - siegeResult = SiegeResult.DESTROY; + for (Building building : city.getParent().zoneBuildingSet) { - city.getBane().endBane(siegeResult); + //don't add -1 rank buildings. - // If it's a capture bane transfer the tree and exit + if (building.rank <= 0) + continue; + if (building.getBlueprint() != null && building.getBlueprint().getBuildingGroup() == BuildingGroup.SPIRE) + spireBuildings.add(building); - if (siegeResult.equals(SiegeResult.CAPTURE)) { - city.transfer(newOwner); - CityRecord cityRecord = CityRecord.borrow(city, RecordEventType.CAPTURE); - DataWarehouse.pushToWarehouse(cityRecord); - return; - } - } // end removal of bane + if (building.getBlueprint() != null && building.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE) + shrineBuildings.add(building); - // if codepath reaches here then we can now destroy the tree and the city + if (building.getBlueprint() != null && building.getBlueprint().getBuildingGroup() == BuildingGroup.BARRACK) + barracksBuildings.add(building); + } - CityRecord cityRecord = CityRecord.borrow(city, RecordEventType.DESTROY); - DataWarehouse.pushToWarehouse(cityRecord); + // A tree can only hold so many spires. As it deranks we need to delete + // the excess - city.destroy(); + if (spireBuildings.size() > Blueprint.getMaxShrines(this.rank - 1)) { - } + spireBuilding = spireBuildings.get(0); - public float getCurrentHitpoints(){ - return this.health.get(); - } + // Disable and delete a random spire - // Return the maint cost in gold associated with this structure + if (spireBuilding != null) { + spireBuilding.disableSpire(true); + spireBuilding.setRank(-1); + } + } - public int getMaintCost() { + if (shrineBuildings.size() > Blueprint.getMaxShrines(this.rank - 1)) { - int maintCost =0; + shrineBuilding = shrineBuildings.get(0); - // Add cost for building structure + // Delete a random shrine - maintCost += this.getBlueprint().getMaintCost(rank); + if (shrineBuilding != null) + shrineBuilding.setRank(-1); + } - // Add costs associated with hirelings + if (barracksBuildings.size() > this.rank - 1) { - for (AbstractCharacter npc : this.hirelings.keySet()) { + Building barracksBuilding = barracksBuildings.get(0); - if (npc.getObjectType() != GameObjectType.NPC) - continue; + // Delete a random barrack + if (barracksBuilding != null) + barracksBuilding.setRank(-1); + } + // If the tree is R8 and deranking, we need to update it's + // mesh along with buildings losing their health bonus - maintCost += Blueprint.getNpcMaintCost(npc.getRank()); - } + if (this.rank == 8) { - return maintCost; - } + cityRealm = city.getRealm(); + if (cityRealm != null) + cityRealm.abandonRealm(); - public final void submitOpenDoorJob(int doorID) { + for (Building cityBuilding : this.parentZone.zoneBuildingSet) { - //cancel any outstanding door close jobs for this door + if ((cityBuilding.getBlueprint() != null && cityBuilding.getBlueprint().getBuildingGroup() != BuildingGroup.TOL) + && (cityBuilding.getBlueprint().getBuildingGroup() != BuildingGroup.BANESTONE)) { + cityBuilding.healthMax = cityBuilding.getBlueprint().getMaxHealth(cityBuilding.rank); + } - if (this.doorJobs.containsKey(doorID)) { - this.doorJobs.get(doorID).cancelJob(); - this.doorJobs.remove(doorID); - } + if (cityBuilding.health.get() > cityBuilding.healthMax) + cityBuilding.setHealth(cityBuilding.healthMax); + } + } + + // Tree is simply deranking. + // Let's do so and early exit - //add new door close job + if (this.rank > 1) { + this.setRank(rank - 1); + City.lastCityUpdate = System.currentTimeMillis(); + return; + } - DoorCloseJob dcj = new DoorCloseJob(this, doorID); - this.doorJobs.put(doorID, dcj); - JobScheduler.getInstance().scheduleJob(dcj, MBServerStatics.DOOR_CLOSE_TIMER); - } + // Must remove a bane before considering destruction of a TOL - public final float getMaxHitPoints() { - return this.healthMax; - } + if (bane != null) { - public final void setMaxHitPoints(float maxHealth) { - this.healthMax = maxHealth; - } + // Cache the new owner - public final void setName(String value) { + newOwner = Guild.GetGL(bane.getOwner().getGuild()); - if (DbManager.BuildingQueries.CHANGE_NAME(this, value) == false) - return; + this.isDeranking.compareAndSet(false, true); - this.name = value; - this.updateName(); - } + if ((bane.getOwner().getGuild().getGuildState() == GuildState.Sovereign) || + (bane.getOwner().getGuild().getGuildState() == GuildState.Protectorate) || + (bane.getOwner().getGuild().getGuildState() == GuildState.Province) || + (bane.getOwner().getGuild().getGuildState() == GuildState.Nation)) + siegeResult = SiegeResult.DESTROY; + else + siegeResult = SiegeResult.CAPTURE; - public final void setw(float value) { - this.w = value; - } + // Remove realm if city had one - public final float getw() { - return this.w; - } + Realm realm = RealmMap.getRealmAtLocation(city.getLoc()); - public final Vector3f getMeshScale() { - return this.meshScale; - } + if (realm != null) + if (realm.isRealmFullAfterBane()) + siegeResult = SiegeResult.DESTROY; - public final int getMeshUUID() { - return this.meshUUID; - } + city.getBane().endBane(siegeResult); - public final Resists getResists() { - return this.resists; - } + // If it's a capture bane transfer the tree and exit - public final Zone getParentZone() { - return this.parentZone; - } + if (siegeResult.equals(SiegeResult.CAPTURE)) { + city.transfer(newOwner); + CityRecord cityRecord = CityRecord.borrow(city, RecordEventType.CAPTURE); + DataWarehouse.pushToWarehouse(cityRecord); + return; + } + } // end removal of bane - public final int getParentZoneID() { + // if codepath reaches here then we can now destroy the tree and the city - if (this.parentZone == null) - return 0; + CityRecord cityRecord = CityRecord.borrow(city, RecordEventType.DESTROY); + DataWarehouse.pushToWarehouse(cityRecord); - return this.parentZone.getObjectUUID(); - } + city.destroy(); - public final void setParentZone(Zone zone) { + } - //update ZoneManager's zone building list - if (zone != null) - if (this.parentZone != null) { + public float getCurrentHitpoints() { + return this.health.get(); + } - this.parentZone.zoneBuildingSet.remove(this); - if(this.getBlueprint() != null && this.getBlueprint().getBuildingGroup().equals(BuildingGroup.BARRACK)){ - this.RemoveFromBarracksList(); - } - zone.zoneBuildingSet.add(this); + public int getMaintCost() { - } else - zone.zoneBuildingSet.add(this); - else if (this.parentZone != null) { - this.parentZone.zoneBuildingSet.remove(this); - if(this.getBlueprint() != null && this.getBlueprint().getBuildingGroup().equals(BuildingGroup.BARRACK)){ - this.RemoveFromBarracksList(); - } - } - if (this.parentZone == null) { - this.parentZone = zone; - this.setLoc(new Vector3fImmutable(this.statLat + zone.absX, this.statAlt + zone.absY, this.statLon + zone.absZ)); - } else - this.parentZone = zone; - if(this.getBlueprint() != null && this.getBlueprint().getBuildingGroup().equals(BuildingGroup.BARRACK)){ - AddToBarracksList(); - } - } + int maintCost = 0; - //Sets the relative position to a parent zone + // Add cost for building structure - public float getStatLat() { - return statLat; - } + maintCost += this.getBlueprint().getMaintCost(rank); - public float getStatLon() { - return statLon; - } + // Add costs associated with hirelings - public float getStatAlt() { - return statAlt; - } + for (AbstractCharacter npc : this.hirelings.keySet()) { - public Guild getGuild() { + if (npc.getObjectType() != GameObjectType.NPC) + continue; - AbstractCharacter buildingOwner; - - buildingOwner = this.getOwner(); - if (buildingOwner != null) - return buildingOwner.getGuild(); - else - return Guild.getErrantGuild(); - } - - public int getEffectFlags() { - return this.effectFlags; - } - - public void addEffectBit(int bit) { - this.effectFlags |= bit; - } - - public void removeAllVisualEffects() { - this.effectFlags = 0; - ApplyBuildingEffectMsg applyBuildingEffectMsg = new ApplyBuildingEffectMsg(3276859, 1, this.getObjectType().ordinal(), this.getObjectUUID(), 0); - DispatchMessage.sendToAllInRange(this, applyBuildingEffectMsg); - } - - public void removeEffectBit(int bit) { - this.effectFlags &= (~bit); - - } - - @Override - public String getName() { - return this.name; - } - - /* - * Utils - */ - - public final AbstractCharacter getOwner() { - - if (this.ownerUUID == 0) - return null; - if (this.ownerIsNPC) - return NPC.getFromCache(this.ownerUUID); - - return PlayerCharacter.getFromCache(this.ownerUUID); - - } - - public final String getOwnerName() { - AbstractCharacter owner = this.getOwner(); - if (owner != null) - return owner.getName(); - return ""; - } - - public final String getGuildName() { - Guild g = getGuild(); - if (g != null) - return g.getName(); - return "None"; - } - - - /* - * Serializing - */ - - public static void _serializeForClientMsg(Building building, ByteBufferWriter writer) { - writer.putInt(building.getObjectType().ordinal()); - writer.putInt(building.getObjectUUID()); - writer.putInt(0); // pad - - writer.putInt(building.meshUUID); - - writer.putInt(0); // pad - - if (building.parentBuildingID != 0){ - - writer.putFloat(building.statLat); - writer.putFloat(building.statAlt); - writer.putFloat(building.statLon); - - }else{ - writer.putFloat(building.getLoc().getX()); - writer.putFloat(building.getLoc().getY()); // Y location - writer.putFloat(building.getLoc().getZ()); - } - - writer.putFloat(building.w); - writer.putFloat(0f); - writer.putFloat(building.getRot().y); - - writer.putFloat(0f); - writer.putFloat(building.meshScale.getX()); - writer.putFloat(building.meshScale.getY()); - writer.putFloat(building.meshScale.getZ()); - - if (building.parentBuildingID != 0){ - writer.putInt(GameObjectType.Building.ordinal()); - writer.putInt(building.parentBuildingID); - writer.putInt(building.floor); - writer.putInt(building.level); - - }else{ - writer.putInt(0); // Pad //Parent - writer.putInt(0); // Pad - writer.putInt(-1); // Static - writer.putInt(-1); // Static - } - - writer.put((byte)0); // 0 - writer.putFloat(3); // 3 - writer.putInt(GameObjectType.Building.ordinal()); - writer.putInt(building.getObjectUUID()); - - if (building.ownerIsNPC) - writer.putInt(GameObjectType.NPC.ordinal()); - else - writer.putInt(GameObjectType.PlayerCharacter.ordinal()); - - writer.putInt(building.ownerUUID); - - writer.put((byte) 1); // End Datablock - writer.putFloat(building.health.get()); - writer.putFloat(building.healthMax); - - if (building.blueprintUUID == 0) - writer.putInt(0); - else - writer.putInt(building.getBlueprint().getIcon()); - - writer.putInt(building.effectFlags); - - writer.put((byte) 1); // End Datablock - Guild g = building.getGuild(); - Guild nation = null; - - if (g == null) { - - for (int i = 0; i < 3; i++) { - writer.putInt(16); - } - for (int i = 0; i < 2; i++) { - writer.putInt(0); - } - } else { - GuildTag._serializeForDisplay(g.getGuildTag(),writer); - nation = g.getNation(); - } - writer.put((byte) 1); // End Datablock? - if (nation == null) { - for (int i = 0; i < 3; i++) { - writer.putInt(16); - } - for (int i = 0; i < 2; i++) { - writer.putInt(0); - } - } else - GuildTag._serializeForDisplay(nation.getGuildTag(),writer); - writer.putString(building.name); - writer.put((byte) 0); // End datablock - } + maintCost += Blueprint.getNpcMaintCost(npc.getRank()); + } - /* - * Database - */ + return maintCost; + } - @Override - public void updateDatabase() { + public final void submitOpenDoorJob(int doorID) { - // *** Refactor : Log error here to see if it's ever called - } + //cancel any outstanding door close jobs for this door - public final LocalDateTime getDateToUpgrade() { - return upgradeDateTime; - } + if (this.doorJobs.containsKey(doorID)) { + this.doorJobs.get(doorID).cancelJob(); + this.doorJobs.remove(doorID); + } - public final boolean setStrongboxValue(int newValue) { + //add new door close job - boolean success = true; + DoorCloseJob dcj = new DoorCloseJob(this, doorID); + this.doorJobs.put(doorID, dcj); + JobScheduler.getInstance().scheduleJob(dcj, MBServerStatics.DOOR_CLOSE_TIMER); + } - try { - DbManager.BuildingQueries.SET_PROPERTY(this, "currentGold", newValue); - this._strongboxValue = newValue; - } catch (Exception e) { - success = false; - Logger.error( "Error writing to database"); - } + public final float getMaxHitPoints() { + return this.healthMax; + } - return success; - } + public final void setMaxHitPoints(float maxHealth) { + this.healthMax = maxHealth; + } - public final int getStrongboxValue() { - return _strongboxValue; - } + public final void setw(float value) { + this.w = value; + } - public final void setMeshUUID(int value) { - this.meshUUID = value; - } + public final float getw() { + return this.w; + } - public final void setRank(int newRank) { + public final Vector3f getMeshScale() { + return this.meshScale; + } - int newMeshUUID; - boolean success; + public final int getMeshUUID() { + return this.meshUUID; + } + public final void setMeshUUID(int value) { + this.meshUUID = value; + } - // If this building has no blueprint then set rank and exit immediatly. + public final Resists getResists() { + return this.resists; + } - if (this.blueprintUUID == 0 || this.getBlueprint() != null && this.getBlueprint().getBuildingGroup().equals(BuildingGroup.MINE)) { - this.rank = newRank; - DbManager.BuildingQueries.CHANGE_RANK(this.getObjectUUID(), newRank); - return; - } + public final Zone getParentZone() { + return this.parentZone; + } - // Delete any upgrade jobs before doing anything else. It won't quite work - // if in a few lines we happen to delete this building. + //Sets the relative position to a parent zone - JobContainer jc = this.getTimers().get("UPGRADE"); + public final void setParentZone(Zone zone) { - if (jc != null) { - if (!JobScheduler.getInstance().cancelScheduledJob(jc)) - Logger.error( "failed to cancel existing upgrade job."); - } + //update ZoneManager's zone building list + if (zone != null) + if (this.parentZone != null) { - // Attempt write to database, or delete the building - // if we are destroying it. + this.parentZone.zoneBuildingSet.remove(this); + if (this.getBlueprint() != null && this.getBlueprint().getBuildingGroup().equals(BuildingGroup.BARRACK)) { + this.RemoveFromBarracksList(); + } + zone.zoneBuildingSet.add(this); - if (newRank == -1) - success = DbManager.BuildingQueries.DELETE_FROM_DATABASE(this); - else - success = DbManager.BuildingQueries.updateBuildingRank(this, newRank); + } else + zone.zoneBuildingSet.add(this); + else if (this.parentZone != null) { + this.parentZone.zoneBuildingSet.remove(this); + if (this.getBlueprint() != null && this.getBlueprint().getBuildingGroup().equals(BuildingGroup.BARRACK)) { + this.RemoveFromBarracksList(); + } + } + if (this.parentZone == null) { + this.parentZone = zone; + this.setLoc(new Vector3fImmutable(this.statLat + zone.absX, this.statAlt + zone.absY, this.statLon + zone.absZ)); + } else + this.parentZone = zone; + if (this.getBlueprint() != null && this.getBlueprint().getBuildingGroup().equals(BuildingGroup.BARRACK)) { + AddToBarracksList(); + } + } - if (success == false) { - Logger.error("Error writing to database UUID: " + this.getObjectUUID()); - return; - } + public final int getParentZoneID() { - this.isDeranking.compareAndSet(false, true); + if (this.parentZone == null) + return 0; - // Change the building's rank + return this.parentZone.getObjectUUID(); + } - this.rank = newRank; + public float getStatLat() { + return statLat; + } - // New rank means new mesh + public float getStatLon() { + return statLon; + } - newMeshUUID = this.getBlueprint().getMeshForRank(this.rank); - this.meshUUID = newMeshUUID; + public float getStatAlt() { + return statAlt; + } - // New rank mean new max hitpoints. + public Guild getGuild() { - this.healthMax = this.getBlueprint().getMaxHealth(this.rank); - this.setCurrentHitPoints(this.healthMax); + AbstractCharacter buildingOwner; - if (this.getUpgradeDateTime() != null) - BuildingManager.setUpgradeDateTime(this, null, 0); + buildingOwner = this.getOwner(); - // If we destroyed this building make sure to turn off - // protection + if (buildingOwner != null) + return buildingOwner.getGuild(); + else + return Guild.getErrantGuild(); + } - if (this.rank == -1) - this.protectionState = ProtectionState.NONE; + public int getEffectFlags() { + return this.effectFlags; + } - if ((this.getBlueprint().getBuildingGroup() == BuildingGroup.TOL) - && (this.rank == 8)) - this.meshUUID = Realm.getRealmMesh(this.getCity());; + public void addEffectBit(int bit) { + this.effectFlags |= bit; + } - // update object to clients + public void removeAllVisualEffects() { + this.effectFlags = 0; + ApplyBuildingEffectMsg applyBuildingEffectMsg = new ApplyBuildingEffectMsg(3276859, 1, this.getObjectType().ordinal(), this.getObjectUUID(), 0); + DispatchMessage.sendToAllInRange(this, applyBuildingEffectMsg); + } - this.refresh(true); - if (this.getBounds() != null) - this.getBounds().setBounds(this); + /* + * Utils + */ - // Cleanup hirelings resulting from rank change + public void removeEffectBit(int bit) { + this.effectFlags &= (~bit); - BuildingManager.cleanupHirelings(this); + } - this.isDeranking.compareAndSet(true, false); - } + @Override + public String getName() { + return this.name; + } - public final void refresh(boolean newMesh) { + public final void setName(String value) { - if (newMesh) - WorldGrid.updateObject(this); - else { - UpdateObjectMsg uom = new UpdateObjectMsg(this, 3); - DispatchMessage.sendToAllInRange(this, uom); - } - } + if (DbManager.BuildingQueries.CHANGE_NAME(this, value) == false) + return; - public final void updateName() { + this.name = value; + this.updateName(); + } - UpdateObjectMsg uom = new UpdateObjectMsg(this, 2); - DispatchMessage.sendToAllInRange(this, uom); - } + /* + * Serializing + */ - // *** Refactor: Can't we just use setRank() for this? + public final AbstractCharacter getOwner() { - public final void rebuildMine(){ - this.setRank(1); - this.meshUUID = this.getBlueprint().getMeshForRank(this.rank); + if (this.ownerUUID == 0) + return null; + if (this.ownerIsNPC) + return NPC.getFromCache(this.ownerUUID); - // New rank mean new max hitpoints. + return PlayerCharacter.getFromCache(this.ownerUUID); - this.healthMax = this.getBlueprint().getMaxHealth(this.rank); - this.setCurrentHitPoints(this.healthMax); - this.getBounds().setBounds(this); - } + } - public final void refreshGuild() { + /* + * Database + */ - UpdateObjectMsg uom = new UpdateObjectMsg(this, 5); - DispatchMessage.sendToAllInRange(this, uom); + public final String getOwnerName() { + AbstractCharacter owner = this.getOwner(); + if (owner != null) + return owner.getName(); + return ""; + } - } + public final String getGuildName() { + Guild g = getGuild(); + if (g != null) + return g.getName(); + return "None"; + } - public int getMaxGold() { - return maxGold; - } + @Override + public void updateDatabase() { - //This returns if a player is allowed access to control the building + // *** Refactor : Log error here to see if it's ever called + } - @Override - public void runAfterLoad() { + public final LocalDateTime getDateToUpgrade() { + return upgradeDateTime; + } - try { + public final boolean setStrongboxValue(int newValue) { - this.parentZone.zoneBuildingSet.add(this); + boolean success = true; - // Submit upgrade job if building is currently set to rank. + try { + DbManager.BuildingQueries.SET_PROPERTY(this, "currentGold", newValue); + this._strongboxValue = newValue; + } catch (Exception e) { + success = false; + Logger.error("Error writing to database"); + } - try { - DbObjectType objectType = DbManager.BuildingQueries.GET_UID_ENUM(this.ownerUUID); - this.ownerIsNPC = (objectType == DbObjectType.NPC); - } catch (Exception e) { - this.ownerIsNPC = false; - Logger.error("Failed to find Object Type for owner " + this.ownerUUID+ " Location " + this.getLoc().toString()); - } + return success; + } - try{ - DbManager.BuildingQueries.LOAD_ALL_FRIENDS_FOR_BUILDING(this); - DbManager.BuildingQueries.LOAD_ALL_CONDEMNED_FOR_BUILDING(this); - }catch(Exception e){ - Logger.error( this.getObjectUUID() + " failed to load friends/condemned." + e.getMessage()); - } + public final int getStrongboxValue() { + return _strongboxValue; + } - //LOad Owners in Cache so we do not have to continuely look in the db for owner. + public final void refresh(boolean newMesh) { - if (this.ownerIsNPC){ - if (NPC.getNPC(this.ownerUUID) == null) - Logger.info( "Building UID " + this.getObjectUUID() + " Failed to Load NPC Owner with ID " + this.ownerUUID+ " Location " + this.getLoc().toString()); + if (newMesh) + WorldGrid.updateObject(this); + else { + UpdateObjectMsg uom = new UpdateObjectMsg(this, 3); + DispatchMessage.sendToAllInRange(this, uom); + } + } - }else if (this.ownerUUID != 0){ - if (PlayerCharacter.getPlayerCharacter(this.ownerUUID) == null){ - Logger.info( "Building UID " + this.getObjectUUID() + " Failed to Load Player Owner with ID " + this.ownerUUID + " Location " + this.getLoc().toString()); - } - } + public final void updateName() { - // Apply health bonus and special mesh for realm if applicable - if ((this.getCity() != null) && this.getCity().getTOL() != null && (this.getCity().getTOL().rank == 8)) { + UpdateObjectMsg uom = new UpdateObjectMsg(this, 2); + DispatchMessage.sendToAllInRange(this, uom); - // Update mesh accordingly - if (this.getBlueprint() != null && this.getBlueprint().getBuildingGroup() == BuildingGroup.TOL) - this.meshUUID = Realm.getRealmMesh(this.getCity()); + } - // Apply realm capital health bonus. - // Do not apply bonus to banestones or TOL's. *** Refactor: - // Possibly only protected buildings? Needs some thought. + // *** Refactor: Can't we just use setRank() for this? - float missingHealth = 0; + public final void rebuildMine() { + this.setRank(1); + this.meshUUID = this.getBlueprint().getMeshForRank(this.rank); - if (this.health.get() != 0) - missingHealth = this.healthMax-this.health.get(); + // New rank mean new max hitpoints. - if ((this.getBlueprint() != null && this.getBlueprint().getBuildingGroup() != BuildingGroup.TOL) - && (this.getBlueprint().getBuildingGroup() != BuildingGroup.BANESTONE)){ - this.healthMax += (this.healthMax * Realm.getRealmHealthMod(this.getCity())); + this.healthMax = this.getBlueprint().getMaxHealth(this.rank); + this.setCurrentHitPoints(this.healthMax); + this.getBounds().setBounds(this); + } - if (this.health.get() != 0) - this.health.set(this.healthMax - missingHealth); + public final void refreshGuild() { - if (this.health.get() > this.healthMax) - this.health.set(this.healthMax); - } - } + UpdateObjectMsg uom = new UpdateObjectMsg(this, 5); + DispatchMessage.sendToAllInRange(this, uom); - // Set bounds for this building + } - Bounds buildingBounds = Bounds.borrow(); - buildingBounds.setBounds(this); - this.setBounds(buildingBounds); - - //create a new list for children if the building is not a child. children list default is null. - //TODO Remove Furniture/Child buildings from building class and move them into a seperate class. + public int getMaxGold() { + return maxGold; + } - if (this.parentBuildingID == 0) - this.children = new ArrayList<>(); + //This returns if a player is allowed access to control the building - if (this.parentBuildingID != 0){ - Building parent = BuildingManager.getBuildingFromCache(this.parentBuildingID); - - if (parent != null){ - parent.children.add(this); + @Override + public void runAfterLoad() { - //add furniture to region cache. floor and level are reversed in database, //TODO Fix + try { - Regions region = BuildingManager.GetRegion(parent, this.level,this.floor, this.getLoc().x, this.getLoc().z); - if (region != null) - Regions.FurnitureRegionMap.put(this.getObjectUUID(), region); - } - - } - - if (this.upgradeDateTime != null) - BuildingManager.submitUpgradeJob(this); + this.parentZone.zoneBuildingSet.add(this); - }catch (Exception e){ - e.printStackTrace(); - } - } + // Submit upgrade job if building is currently set to rank. - public synchronized boolean setOwner(AbstractCharacter newOwner) { + try { + DbObjectType objectType = DbManager.BuildingQueries.GET_UID_ENUM(this.ownerUUID); + this.ownerIsNPC = (objectType == DbObjectType.NPC); + } catch (Exception e) { + this.ownerIsNPC = false; + Logger.error("Failed to find Object Type for owner " + this.ownerUUID + " Location " + this.getLoc().toString()); + } + + try { + DbManager.BuildingQueries.LOAD_ALL_FRIENDS_FOR_BUILDING(this); + DbManager.BuildingQueries.LOAD_ALL_CONDEMNED_FOR_BUILDING(this); + } catch (Exception e) { + Logger.error(this.getObjectUUID() + " failed to load friends/condemned." + e.getMessage()); + } - int newOwnerID; - if (newOwner == null) - newOwnerID = 0; - else - newOwnerID = newOwner.getObjectUUID(); + //LOad Owners in Cache so we do not have to continuely look in the db for owner. - try { + if (this.ownerIsNPC) { + if (NPC.getNPC(this.ownerUUID) == null) + Logger.info("Building UID " + this.getObjectUUID() + " Failed to Load NPC Owner with ID " + this.ownerUUID + " Location " + this.getLoc().toString()); - // Save new owner to database + } else if (this.ownerUUID != 0) { + if (PlayerCharacter.getPlayerCharacter(this.ownerUUID) == null) { + Logger.info("Building UID " + this.getObjectUUID() + " Failed to Load Player Owner with ID " + this.ownerUUID + " Location " + this.getLoc().toString()); + } + } + + // Apply health bonus and special mesh for realm if applicable + if ((this.getCity() != null) && this.getCity().getTOL() != null && (this.getCity().getTOL().rank == 8)) { + + // Update mesh accordingly + if (this.getBlueprint() != null && this.getBlueprint().getBuildingGroup() == BuildingGroup.TOL) + this.meshUUID = Realm.getRealmMesh(this.getCity()); + + // Apply realm capital health bonus. + // Do not apply bonus to banestones or TOL's. *** Refactor: + // Possibly only protected buildings? Needs some thought. + + float missingHealth = 0; + + if (this.health.get() != 0) + missingHealth = this.healthMax - this.health.get(); + + if ((this.getBlueprint() != null && this.getBlueprint().getBuildingGroup() != BuildingGroup.TOL) + && (this.getBlueprint().getBuildingGroup() != BuildingGroup.BANESTONE)) { + this.healthMax += (this.healthMax * Realm.getRealmHealthMod(this.getCity())); + + if (this.health.get() != 0) + this.health.set(this.healthMax - missingHealth); + + if (this.health.get() > this.healthMax) + this.health.set(this.healthMax); + } + } + + // Set bounds for this building + + Bounds buildingBounds = Bounds.borrow(); + buildingBounds.setBounds(this); + this.setBounds(buildingBounds); + + //create a new list for children if the building is not a child. children list default is null. + //TODO Remove Furniture/Child buildings from building class and move them into a seperate class. + + if (this.parentBuildingID == 0) + this.children = new ArrayList<>(); + + if (this.parentBuildingID != 0) { + Building parent = BuildingManager.getBuildingFromCache(this.parentBuildingID); + + if (parent != null) { + parent.children.add(this); + + //add furniture to region cache. floor and level are reversed in database, //TODO Fix + + Regions region = BuildingManager.GetRegion(parent, this.level, this.floor, this.getLoc().x, this.getLoc().z); + if (region != null) + Regions.FurnitureRegionMap.put(this.getObjectUUID(), region); + } + + } + + if (this.upgradeDateTime != null) + BuildingManager.submitUpgradeJob(this); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + public synchronized boolean setOwner(AbstractCharacter newOwner) { + + int newOwnerID; + if (newOwner == null) + newOwnerID = 0; + else + newOwnerID = newOwner.getObjectUUID(); + + try { + + // Save new owner to database + + if (!DbManager.BuildingQueries.updateBuildingOwner(this, newOwnerID)) + return false; + + if (newOwner == null) { + this.ownerIsNPC = false; + this.ownerUUID = 0; + } else { + this.ownerUUID = newOwner.getObjectUUID(); + this.ownerIsNPC = (newOwner.getObjectType() == GameObjectType.NPC); + } - if (!DbManager.BuildingQueries.updateBuildingOwner(this, newOwnerID)) - return false; - if (newOwner == null) { - this.ownerIsNPC = false; - this.ownerUUID = 0; } - else { - this.ownerUUID = newOwner.getObjectUUID(); - this.ownerIsNPC = (newOwner.getObjectType() == GameObjectType.NPC); - } + // Set new guild for hirelings and refresh all clients + this.refreshGuild(); + BuildingManager.refreshHirelings(this); - // Set new guild for hirelings and refresh all clients + } catch (Exception e) { + Logger.error("Error updating owner! UUID: " + this.getObjectUUID()); + return false; + } - this.refreshGuild(); - BuildingManager.refreshHirelings(this); + return true; - } catch (Exception e) { - Logger.error( "Error updating owner! UUID: " + this.getObjectUUID()); - return false; - } + } - return true; + //This turns on and off low damage effect for building - } + public void toggleDamageLow(boolean on) { + if (on) + addEffectBit(2); + else + removeEffectBit(2); + } - //This turns on and off low damage effect for building + //This turns on and off medium damage effect for building - public void toggleDamageLow(boolean on) { - if (on) - addEffectBit(2); - else - removeEffectBit(2); - } + public void toggleDamageMedium(boolean on) { + if (on) + addEffectBit(4); + else + removeEffectBit(4); + } - //This turns on and off medium damage effect for building + //This turns on and off high damage effect for building - public void toggleDamageMedium(boolean on) { - if (on) - addEffectBit(4); - else - removeEffectBit(4); - } + public void toggleDamageHigh(boolean on) { + if (on) + addEffectBit(8); + else + removeEffectBit(8); + } - //This turns on and off high damage effect for building + //This clears all damage effects on a building + public void clearDamageEffect() { + toggleDamageLow(false); + toggleDamageMedium(false); + toggleDamageHigh(false); + } - public void toggleDamageHigh(boolean on) { - if (on) - addEffectBit(8); - else - removeEffectBit(8); - } + public Vector3fImmutable getStuckLocation() { + Vector3fImmutable stuckLocation; + ArrayList stuckLocations; - //This clears all damage effects on a building - public void clearDamageEffect() { - toggleDamageLow(false); - toggleDamageMedium(false); - toggleDamageHigh(false); - } + stuckLocations = BuildingManager._stuckLocations.get(this.meshUUID); - public Vector3fImmutable getStuckLocation() { - Vector3fImmutable stuckLocation; - ArrayList stuckLocations; + // Sanity check - stuckLocations = BuildingManager._stuckLocations.get(this.meshUUID); + if (stuckLocations == null || + stuckLocations.isEmpty()) + return this.getLoc(); - // Sanity check + stuckLocation = stuckLocations.get(ThreadLocalRandom.current().nextInt(stuckLocations.size())).getLocation(); + stuckLocation = this.getLoc().add(stuckLocation); - if (stuckLocations == null || - stuckLocations.isEmpty()) - return this.getLoc(); + return stuckLocation; + } - stuckLocation = stuckLocations.get(ThreadLocalRandom.current().nextInt(stuckLocations.size())).getLocation(); - stuckLocation = this.getLoc().add(stuckLocation); + public boolean isDoorOpen(int doorNumber) { - return stuckLocation; - } + if (this.doorState == 0) + return false; - public boolean isDoorOpen(int doorNumber) { + return (this.doorState & (1 << doorNumber + 16)) != 0; - if (this.doorState == 0) - return false; + } - return (this.doorState & (1 << doorNumber + 16)) != 0; + public boolean isDoorLocked(int doorNumber) { - } + if (this.doorState == 0) + return false; - public boolean isDoorLocked(int doorNumber) { + return (this.doorState & (1 << doorNumber)) != 0; - if (this.doorState == 0) - return false; + } - return (this.doorState & (1 << doorNumber)) != 0; + public boolean setDoorState(int doorNumber, DoorState doorState) { - } + boolean updateRecord; - public boolean setDoorState(int doorNumber, DoorState doorState) { + updateRecord = false; - boolean updateRecord; + // Can't have an invalid door number + // Log error? - updateRecord = false; + if (doorNumber < 1 || doorNumber > 16) + return false; - // Can't have an invalid door number - // Log error? + switch (doorState) { - if (doorNumber < 1 || doorNumber > 16) - return false; + case OPEN: + this.doorState |= (1 << (doorNumber + 16)); + break; + case CLOSED: + this.doorState &= ~(1 << (doorNumber + 16)); + break; + case UNLOCKED: + this.doorState &= ~(1 << doorNumber); + updateRecord = true; + break; + case LOCKED: + this.doorState |= (1 << doorNumber); + updateRecord = true; + break; + } - switch (doorState) { + // Save to database ? + if (updateRecord == true) + return DbManager.BuildingQueries.UPDATE_DOOR_LOCK(this.getObjectUUID(), this.doorState); + else + return true; + } - case OPEN: - this.doorState |= (1 << (doorNumber + 16)); - break; - case CLOSED: - this.doorState &= ~(1 << (doorNumber + 16)); - break; - case UNLOCKED: - this.doorState &= ~(1 << doorNumber); - updateRecord = true; - break; - case LOCKED: - this.doorState |= (1 << doorNumber); - updateRecord = true; - break; - } + public void updateEffects() { - // Save to database ? - if (updateRecord == true) - return DbManager.BuildingQueries.UPDATE_DOOR_LOCK(this.getObjectUUID(), this.doorState); - else - return true; - } + ApplyBuildingEffectMsg applyBuildingEffectMsg = new ApplyBuildingEffectMsg(0x00720063, 1, this.getObjectType().ordinal(), this.getObjectUUID(), this.effectFlags); + DispatchMessage.sendToAllInRange(this, applyBuildingEffectMsg); - public void updateEffects() { + } - ApplyBuildingEffectMsg applyBuildingEffectMsg = new ApplyBuildingEffectMsg(0x00720063, 1, this.getObjectType().ordinal(), this.getObjectUUID(), this.effectFlags); - DispatchMessage.sendToAllInRange(this, applyBuildingEffectMsg); + public final void enableSpire() { - } + SpireType spireType; - public final void enableSpire() { + if (this.getCity() == null) + return; - SpireType spireType; + // Blueprint sanity check - if (this.getCity() == null) - return; + if (this.blueprintUUID == 0) + return; - // Blueprint sanity check + spireType = SpireType.getByBlueprintUUID(this.blueprintUUID); - if (this.blueprintUUID == 0) - return; + SiegeSpireWithdrawlJob spireJob = new SiegeSpireWithdrawlJob(this); + JobContainer jc = JobScheduler.getInstance().scheduleJob(spireJob, 300000); + this.getTimers().put("SpireWithdrawl", jc); - spireType = SpireType.getByBlueprintUUID(this.blueprintUUID); + this.getCity().addCityEffect(spireType.getEffectBase(), rank); + addEffectBit(spireType.getEffectFlag()); + this.spireIsActive = true; + this.updateEffects(); - SiegeSpireWithdrawlJob spireJob = new SiegeSpireWithdrawlJob(this); - JobContainer jc = JobScheduler.getInstance().scheduleJob(spireJob, 300000); - this.getTimers().put("SpireWithdrawl", jc); - this.getCity().addCityEffect(spireType.getEffectBase(), rank); - addEffectBit(spireType.getEffectFlag()); - this.spireIsActive = true; - this.updateEffects(); + } + public final void disableSpire(boolean refreshEffect) { - } + SpireType spireType; - public final void disableSpire(boolean refreshEffect) { + if (this.getCity() == null) + return; - SpireType spireType; + // Blueprint sanity check - if (this.getCity() == null) - return; + if (this.blueprintUUID == 0) + return; - // Blueprint sanity check + spireType = SpireType.getByBlueprintUUID(this.blueprintUUID); - if (this.blueprintUUID == 0) - return; + this.getCity().removeCityEffect(spireType.getEffectBase(), rank, refreshEffect); - spireType = SpireType.getByBlueprintUUID(this.blueprintUUID); + JobContainer toRemove = this.getTimers().get("SpireWithdrawl"); - this.getCity().removeCityEffect(spireType.getEffectBase(), rank, refreshEffect); + if (toRemove != null) { + toRemove.cancelJob(); + this.getTimers().remove("SpireWithdrawl"); + } - JobContainer toRemove = this.getTimers().get("SpireWithdrawl"); + this.spireIsActive = false; + this.removeEffectBit(spireType.getEffectFlag()); + this.updateEffects(); + } - if (toRemove != null) { - toRemove.cancelJob(); - this.getTimers().remove("SpireWithdrawl"); - } + public ConcurrentHashMap getHirelings() { + return hirelings; + } - this.spireIsActive = false; - this.removeEffectBit(spireType.getEffectFlag()); - this.updateEffects(); - } + public final boolean isSpireIsActive() { + return spireIsActive; + } - public ConcurrentHashMap getHirelings() { - return hirelings; - } + public final void setSpireIsActive(boolean spireIsActive) { + this.spireIsActive = spireIsActive; + } - public final boolean isSpireIsActive() { - return spireIsActive; - } + public final boolean isVulnerable() { - public final boolean isVulnerable() { + // NPC owned buildings are never vulnerable - // NPC owned buildings are never vulnerable + if (ownerIsNPC) + return false; - if (ownerIsNPC) - return false; + // Buildings on an npc citygrid are never vulnerable - // Buildings on an npc citygrid are never vulnerable + if (this.getCity() != null) { + if (this.getCity().getParent().isNPCCity() == true) + return false; + } - if (this.getCity() != null) { - if (this.getCity().getParent().isNPCCity() == true) - return false; - } + // Destroyed buildings are never vulnerable - // Destroyed buildings are never vulnerable + if (rank < 0) + return false; - if (rank < 0) - return false; + // Any structure without a blueprint was not placed by a + // player and we can assume to be invulnerable regardless + // of a protection contract or not. - // Any structure without a blueprint was not placed by a - // player and we can assume to be invulnerable regardless - // of a protection contract or not. + if (this.getBlueprint() == null) + return false; - if (this.getBlueprint() == null) - return false; + // Runegates are never vulerable. - // Runegates are never vulerable. + if (this.getBlueprint().getBuildingGroup() == BuildingGroup.RUNEGATE) + return false; - if (this.getBlueprint().getBuildingGroup() == BuildingGroup.RUNEGATE) - return false; + // Shrines are never vulerable. They blow up as a + // tree deranks. - // Shrines are never vulerable. They blow up as a - // tree deranks. + if (this.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE) + return false; - if (this.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE) - return false; + // Mines are vulnerable only if they are active - // Mines are vulnerable only if they are active + if (this.getBlueprint().getBuildingGroup() == BuildingGroup.MINE) { - if (this.getBlueprint().getBuildingGroup() == BuildingGroup.MINE) { + // Cannot access mine - // Cannot access mine + if (Mine.getMineFromTower(this.getObjectUUID()) == null) + return false; - if (Mine.getMineFromTower(this.getObjectUUID()) == null) - return false; + return Mine.getMineFromTower(this.getObjectUUID()).getIsActive() == true; + } - return Mine.getMineFromTower(this.getObjectUUID()).getIsActive() == true; - } + // Errant banestones are vulnerable by default - // Errant banestones are vulnerable by default + if ((this.getBlueprint().getBuildingGroup() == BuildingGroup.BANESTONE) && + this.getCity().getBane().isErrant() == true) + return true; - if ((this.getBlueprint().getBuildingGroup() == BuildingGroup.BANESTONE) && - this.getCity().getBane().isErrant() == true) - return true; + // There is an active protection contract. Is there also + // an active bane? If so, it's meaningless. - // There is an active protection contract. Is there also - // an active bane? If so, it's meaningless. + if (this.assetIsProtected() == true) { - if (this.assetIsProtected() == true) { + // Building protection is meaningless without a city - // Building protection is meaningless without a city + if (this.getCity() == null) + return true; - if (this.getCity() == null) - return true; + // All buildings are vulnerable during an active bane - // All buildings are vulnerable during an active bane + return (this.getCity().protectionEnforced == false); - return (this.getCity().protectionEnforced == false); + } - } + // No protection contract? Oh well, you're vunerable! - // No protection contract? Oh well, you're vunerable! + return true; + } - return true; - } + public final ConcurrentHashMap getTimers() { + if (this.timers == null) + this.timers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + return this.timers; + } - public final void setSpireIsActive(boolean spireIsActive) { - this.spireIsActive = spireIsActive; - } + public final ConcurrentHashMap getTimestamps() { + if (this.timestamps == null) + this.timestamps = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + return this.timestamps; + } - public final ConcurrentHashMap getTimers() { - if (this.timers == null) - this.timers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - return this.timers; - } + public final long getTimeStamp(final String name) { + if (this.getTimestamps().containsKey(name)) + return this.timestamps.get(name); + return 0L; + } - public final ConcurrentHashMap getTimestamps() { - if (this.timestamps == null) - this.timestamps = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - return this.timestamps; - } + public final void setTimeStamp(final String name, final long value) { + this.getTimestamps().put(name, value); + } - public final long getTimeStamp(final String name) { - if (this.getTimestamps().containsKey(name)) - return this.timestamps.get(name); - return 0L; - } + public ConcurrentHashMap getFriends() { + return this.friends; + } - public final void setTimeStamp(final String name, final long value) { - this.getTimestamps().put(name, value); - } + public final void claim(AbstractCharacter sourcePlayer) { - public ConcurrentHashMap getFriends() { - return this.friends; - } + // Clear any existing friend or condemn entries - public final void claim(AbstractCharacter sourcePlayer) { + this.friends.clear(); + DbManager.BuildingQueries.CLEAR_FRIENDS_LIST(this.getObjectUUID()); - // Clear any existing friend or condemn entries + condemned.clear(); + DbManager.BuildingQueries.CLEAR_CONDEMNED_LIST(this.getObjectUUID()); - this.friends.clear(); - DbManager.BuildingQueries.CLEAR_FRIENDS_LIST(this.getObjectUUID()); + // Transfer the building asset ownership - condemned.clear(); - DbManager.BuildingQueries.CLEAR_CONDEMNED_LIST(this.getObjectUUID()); + this.setOwner(sourcePlayer); - // Transfer the building asset ownership + } - this.setOwner(sourcePlayer); + /** + * @return the protectionState + */ + public ProtectionState getProtectionState() { + return protectionState; + } - } + /** + * @param protectionState the protectionState to set + */ + public void setProtectionState(ProtectionState protectionState) { - /** - * @return the protectionState - */ - public ProtectionState getProtectionState() { - return protectionState; - } + // Early exit if protection state is already set to input value - /** - * @param protectionState the protectionState to set - */ - public void setProtectionState(ProtectionState protectionState) { + if (this.protectionState.equals(protectionState)) + return; - // Early exit if protection state is already set to input value + // if building is destroyed, just set the protection state. There isn't a DB + // record to write anything to. - if (this.protectionState.equals(protectionState)) - return; + if (rank == -1) { + this.protectionState = protectionState; + return; + } - // if building is destroyed, just set the protection state. There isn't a DB - // record to write anything to. + if (DbManager.BuildingQueries.UPDATE_PROTECTIONSTATE(this.getObjectUUID(), protectionState) == true) { + this.protectionState = protectionState; + return; + } - if (rank == -1) { - this.protectionState = protectionState; - return; - } + Logger.error("Protection update failed for UUID: " + this.getObjectUUID() + "\n" + + this.getBlueprint().getName() + " From " + this.protectionState.name() + " To: " + protectionState.name()); - if (DbManager.BuildingQueries.UPDATE_PROTECTIONSTATE(this.getObjectUUID(), protectionState) == true) { - this.protectionState = protectionState; - return; - } + } - Logger.error("Protection update failed for UUID: " + this.getObjectUUID() + "\n" + - this.getBlueprint().getName() + " From " + this.protectionState.name() + " To: " + protectionState.name()); + public ConcurrentHashMap getCondemned() { + return condemned; + } - } + public boolean setReverseKOS(boolean reverseKOS) { + if (!DbManager.BuildingQueries.updateReverseKOS(this, reverseKOS)) + return false; + this.reverseKOS = reverseKOS; + return true; + } - public ConcurrentHashMap getCondemned() { - return condemned; - } + public boolean assetIsProtected() { - public boolean setReverseKOS(boolean reverseKOS) { - if (!DbManager.BuildingQueries.updateReverseKOS(this, reverseKOS)) - return false; - this.reverseKOS = reverseKOS; - return true; - } + boolean outValue = false; - public boolean assetIsProtected() { + if (protectionState.equals(ProtectionState.PROTECTED)) + outValue = true; - boolean outValue = false; + if (protectionState.equals(ProtectionState.CONTRACT)) + outValue = true; - if (protectionState.equals(ProtectionState.PROTECTED)) - outValue = true; + return outValue; + } - if (protectionState.equals(ProtectionState.CONTRACT)) - outValue = true; + public synchronized boolean transferGold(int amount, boolean tax) { - return outValue; - } + if (amount < 0) + if (!this.hasFunds(-amount)) + return false; - public synchronized boolean transferGold(int amount,boolean tax){ + if (_strongboxValue + amount < 0) + return false; - if (amount < 0) - if (!this.hasFunds(-amount)) - return false; + if (_strongboxValue + amount > maxGold) + return false; - if (_strongboxValue + amount < 0) - return false; + //Deduct Profit taxes. + if (tax) + if (taxType == TaxType.PROFIT && protectionState == ProtectionState.CONTRACT && amount > 0) + amount = this.payProfitTaxes(amount); - if (_strongboxValue + amount > maxGold) - return false; - //Deduct Profit taxes. - if (tax) - if (taxType == TaxType.PROFIT && protectionState == ProtectionState.CONTRACT && amount > 0) - amount = this.payProfitTaxes(amount); + if (amount != 0) + return this.setStrongboxValue(_strongboxValue + amount); + return true; + } + public synchronized int payProfitTaxes(int amount) { - if (amount != 0) - return this.setStrongboxValue(_strongboxValue + amount); - return true; - } + if (this.getCity() == null) + return amount; + if (this.getCity().getWarehouse() == null) + return amount; - public synchronized int payProfitTaxes(int amount){ + if (this.getCity().getWarehouse().getResources().get(ItemBase.getGoldItemBase()) >= Warehouse.getMaxResources().get(ItemBase.getGoldItemBase().getUUID())) + return amount; - if (this.getCity() == null) - return amount; - if (this.getCity().getWarehouse() == null) - return amount; + int profitAmount = (int) (amount * (taxAmount * .01f)); - if (this.getCity().getWarehouse().getResources().get(ItemBase.getGoldItemBase()) >= Warehouse.getMaxResources().get(ItemBase.getGoldItemBase().getUUID())) - return amount; + if (this.getCity().getWarehouse().getResources().get(ItemBase.getGoldItemBase()) + profitAmount <= Warehouse.getMaxResources().get(ItemBase.getGoldItemBase().getUUID())) { + this.getCity().getWarehouse().depositProfitTax(ItemBase.getGoldItemBase(), profitAmount, this); + return amount - profitAmount; + } + //overDrafting + int warehouseDeposit = Warehouse.getMaxResources().get(ItemBase.getGoldItemBase().getUUID()) - this.getCity().getWarehouse().getResources().get(ItemBase.getGoldItemBase()); + this.getCity().getWarehouse().depositProfitTax(ItemBase.getGoldItemBase(), warehouseDeposit, this); + return amount - warehouseDeposit; + } - int profitAmount = (int) (amount * (taxAmount *.01f)); + public synchronized boolean setReserve(int amount, PlayerCharacter player) { - if (this.getCity().getWarehouse().getResources().get(ItemBase.getGoldItemBase()) + profitAmount <= Warehouse.getMaxResources().get(ItemBase.getGoldItemBase().getUUID())){ - this.getCity().getWarehouse().depositProfitTax(ItemBase.getGoldItemBase(), profitAmount,this); - return amount - profitAmount; - } - //overDrafting - int warehouseDeposit = Warehouse.getMaxResources().get(ItemBase.getGoldItemBase().getUUID()) - this.getCity().getWarehouse().getResources().get(ItemBase.getGoldItemBase()); - this.getCity().getWarehouse().depositProfitTax(ItemBase.getGoldItemBase(), warehouseDeposit,this); - return amount - warehouseDeposit; - } + if (!BuildingManager.playerCanManageNotFriends(player, this)) + return false; - public synchronized boolean setReserve(int amount, PlayerCharacter player){ + if (amount < 0) + return false; - if (!BuildingManager.playerCanManageNotFriends(player, this)) - return false; + if (!DbManager.BuildingQueries.SET_RESERVE(this, amount)) + return false; - if (amount < 0) - return false; + this.reserve = amount; - if (!DbManager.BuildingQueries.SET_RESERVE(this, amount)) - return false; + return true; + } - this.reserve = amount; + public synchronized boolean hasFunds(int amount) { + return amount <= (this._strongboxValue - reserve); + } - return true; - } + public ArrayList getPatrolPoints() { + return patrolPoints; + } - public synchronized boolean hasFunds(int amount){ - return amount <= (this._strongboxValue - reserve); - } + public void setPatrolPoints(ArrayList patrolPoints) { + this.patrolPoints = patrolPoints; + } - public ArrayList getPatrolPoints() { - return patrolPoints; - } + public ArrayList getSentryPoints() { + return sentryPoints; + } - public void setPatrolPoints(ArrayList patrolPoints) { - this.patrolPoints = patrolPoints; - } + public void setSentryPoints(ArrayList sentryPoints) { + this.sentryPoints = sentryPoints; + } - public ArrayList getSentryPoints() { - return sentryPoints; - } + public synchronized boolean addProtectionTax(Building building, PlayerCharacter pc, final TaxType taxType, int amount, boolean enforceKOS) { + if (building == null) + return false; - public void setSentryPoints(ArrayList sentryPoints) { - this.sentryPoints = sentryPoints; - } + if (this.getBlueprint() == null) + return false; - public synchronized boolean addProtectionTax(Building building, PlayerCharacter pc, final TaxType taxType, int amount, boolean enforceKOS){ - if (building == null) - return false; + if (this.getBlueprint().getBuildingGroup() != BuildingGroup.TOL) + return false; - if (this.getBlueprint() == null) - return false; + if (building.assetIsProtected()) + return false; - if (this.getBlueprint().getBuildingGroup() != BuildingGroup.TOL) - return false; + if (!DbManager.BuildingQueries.addTaxes(building, taxType, amount, enforceKOS)) + return false; - if (building.assetIsProtected()) - return false; + building.taxType = taxType; + building.taxAmount = amount; + building.enforceKOS = enforceKOS; - if (!DbManager.BuildingQueries.addTaxes(building, taxType, amount, enforceKOS)) - return false; + return true; - building.taxType = taxType; - building.taxAmount = amount; - building.enforceKOS = enforceKOS; + } - return true; + public synchronized boolean declineTaxOffer() { + return true; + } - } + public synchronized boolean acceptTaxOffer() { + return true; + } - public synchronized boolean declineTaxOffer(){ - return true; - } + public synchronized boolean acceptTaxes() { - public synchronized boolean acceptTaxOffer(){ - return true; - } + if (!DbManager.BuildingQueries.acceptTaxes(this)) + return false; - public synchronized boolean acceptTaxes(){ + this.setProtectionState(Enum.ProtectionState.CONTRACT); + this.taxDateTime = LocalDateTime.now().plusDays(7); - if (!DbManager.BuildingQueries.acceptTaxes(this)) - return false; + return true; + } - this.setProtectionState(Enum.ProtectionState.CONTRACT); - this.taxDateTime = LocalDateTime.now().plusDays(7); + public synchronized boolean removeTaxes() { - return true; - } + if (!DbManager.BuildingQueries.removeTaxes(this)) + return false; - public synchronized boolean removeTaxes(){ + this.taxType = TaxType.NONE; + this.taxAmount = 0; + this.taxDateTime = null; + this.enforceKOS = false; - if (!DbManager.BuildingQueries.removeTaxes(this)) - return false; + return true; + } - this.taxType = TaxType.NONE; - this.taxAmount = 0; - this.taxDateTime = null; - this.enforceKOS = false; + public boolean isTaxed() { + if (this.taxType == TaxType.NONE) + return false; + if (this.taxAmount == 0) + return false; + return this.taxDateTime != null; + } - return true; - } + public void AddToBarracksList() { + City playerCity = ZoneManager.getCityAtLocation(this.loc); + if (playerCity != null) { + playerCity.cityBarracks.add(this); + } + } - public boolean isTaxed(){ - if (this.taxType == TaxType.NONE) - return false; - if (this.taxAmount == 0) - return false; - return this.taxDateTime != null; - } - public void AddToBarracksList(){ - City playerCity = ZoneManager.getCityAtLocation(this.loc); - if(playerCity != null){ - playerCity.cityBarracks.add(this); - } - } - public void RemoveFromBarracksList(){ + public void RemoveFromBarracksList() { - } + } } diff --git a/src/engine/objects/BuildingFriends.java b/src/engine/objects/BuildingFriends.java index f6518759..b5308978 100644 --- a/src/engine/objects/BuildingFriends.java +++ b/src/engine/objects/BuildingFriends.java @@ -12,40 +12,42 @@ package engine.objects; import java.sql.ResultSet; import java.sql.SQLException; -public class BuildingFriends { - - private int playerUID; - private int buildingUID; - private int guildUID; - private int friendType; - - /** - * ResultSet Constructor - */ - - public BuildingFriends(ResultSet rs) throws SQLException { - this.playerUID = rs.getInt("playerUID"); - this.buildingUID = rs.getInt("buildingUID"); - this.guildUID = rs.getInt("guildUID"); - this.friendType = rs.getInt("friendType"); - } - - public BuildingFriends(int playerUID, int buildingUID, int guildUID, int friendType) { - super(); - this.playerUID = playerUID; - this.buildingUID = buildingUID; - this.guildUID = guildUID; - this.friendType = friendType; - } - - public int getPlayerUID() { - return playerUID; - } - public int getGuildUID() { - return guildUID; - } - public int getFriendType() { - return friendType; - } +public class BuildingFriends { + + private int playerUID; + private int buildingUID; + private int guildUID; + private int friendType; + + /** + * ResultSet Constructor + */ + + public BuildingFriends(ResultSet rs) throws SQLException { + this.playerUID = rs.getInt("playerUID"); + this.buildingUID = rs.getInt("buildingUID"); + this.guildUID = rs.getInt("guildUID"); + this.friendType = rs.getInt("friendType"); + } + + public BuildingFriends(int playerUID, int buildingUID, int guildUID, int friendType) { + super(); + this.playerUID = playerUID; + this.buildingUID = buildingUID; + this.guildUID = guildUID; + this.friendType = friendType; + } + + public int getPlayerUID() { + return playerUID; + } + + public int getGuildUID() { + return guildUID; + } + + public int getFriendType() { + return friendType; + } } diff --git a/src/engine/objects/BuildingLocation.java b/src/engine/objects/BuildingLocation.java index 4c9c0d6a..214d89db 100644 --- a/src/engine/objects/BuildingLocation.java +++ b/src/engine/objects/BuildingLocation.java @@ -22,106 +22,105 @@ import java.util.HashMap; public class BuildingLocation extends AbstractGameObject { - private final int buildingUUID; - private final int type; - private final int slot; - private final int unknown; - private final Vector3fImmutable location; - private final Quaternion rotation; - - - public BuildingLocation() { - - this.buildingUUID = 0; - this.type = 0; - this.slot = 0; - this.unknown = 0; - this.location = Vector3fImmutable.ZERO; - this.rotation = new Quaternion(); - } - - /** - * ResultSet Constructor - */ - public BuildingLocation(ResultSet rs) throws SQLException { - super(rs); - this.buildingUUID = rs.getInt("BuildingID"); - this.type = rs.getInt("type"); - this.slot = rs.getInt("slot"); - this.unknown = rs.getInt("unknown"); - this.location = new Vector3fImmutable(rs.getFloat("locX"), rs.getFloat("locY"), rs.getFloat("locZ")); - this.rotation = new Quaternion(rs.getFloat("rotX"), rs.getFloat("rotY"), rs.getFloat("rotZ"), rs.getFloat("w")); - } - - /* - * Getters - */ - - public int getBuildingUUID() { - return this.buildingUUID; - } - - public int getType() { - return this.type; - } - - public int getSlot() { - return this.slot; - } - - public int getUnknown() { - return this.unknown; - } - - public float getLocX() { - return this.location.x; - } - - public float getLocY() { - return this.location.y; - } - - - public Vector3fImmutable getLocation() { - return this.location; - } - - public Quaternion getRotation() { - return this.rotation; - } - - @Override - public void updateDatabase() { - } - - public static void loadBuildingLocations() { - - ArrayList buildingLocations = DbManager.BuildingLocationQueries.LOAD_BUILDING_LOCATIONS(); - HashMap> locationCollection = new HashMap<>(); - - // Only slot locations and stuck locations are currently loaded. - - for (BuildingLocation buildingLocation : buildingLocations) { - - switch (buildingLocation.type) { - case 6: - locationCollection = BuildingManager._slotLocations; - break; - case 8: - locationCollection = BuildingManager._stuckLocations; - break; - } - - // Add location to collection in BuildingManager - - if (locationCollection.containsKey(buildingLocation.buildingUUID)) - locationCollection.get(buildingLocation.buildingUUID).add(buildingLocation); - else { - locationCollection.put(buildingLocation.buildingUUID, new ArrayList<>()); - locationCollection.get(buildingLocation.buildingUUID).add(buildingLocation); - } - - } - } + private final int buildingUUID; + private final int type; + private final int slot; + private final int unknown; + private final Vector3fImmutable location; + private final Quaternion rotation; + + + public BuildingLocation() { + + this.buildingUUID = 0; + this.type = 0; + this.slot = 0; + this.unknown = 0; + this.location = Vector3fImmutable.ZERO; + this.rotation = new Quaternion(); + } + + /** + * ResultSet Constructor + */ + public BuildingLocation(ResultSet rs) throws SQLException { + super(rs); + this.buildingUUID = rs.getInt("BuildingID"); + this.type = rs.getInt("type"); + this.slot = rs.getInt("slot"); + this.unknown = rs.getInt("unknown"); + this.location = new Vector3fImmutable(rs.getFloat("locX"), rs.getFloat("locY"), rs.getFloat("locZ")); + this.rotation = new Quaternion(rs.getFloat("rotX"), rs.getFloat("rotY"), rs.getFloat("rotZ"), rs.getFloat("w")); + } + + /* + * Getters + */ + + public static void loadBuildingLocations() { + + ArrayList buildingLocations = DbManager.BuildingLocationQueries.LOAD_BUILDING_LOCATIONS(); + HashMap> locationCollection = new HashMap<>(); + + // Only slot locations and stuck locations are currently loaded. + + for (BuildingLocation buildingLocation : buildingLocations) { + + switch (buildingLocation.type) { + case 6: + locationCollection = BuildingManager._slotLocations; + break; + case 8: + locationCollection = BuildingManager._stuckLocations; + break; + } + + // Add location to collection in BuildingManager + + if (locationCollection.containsKey(buildingLocation.buildingUUID)) + locationCollection.get(buildingLocation.buildingUUID).add(buildingLocation); + else { + locationCollection.put(buildingLocation.buildingUUID, new ArrayList<>()); + locationCollection.get(buildingLocation.buildingUUID).add(buildingLocation); + } + + } + } + + public int getBuildingUUID() { + return this.buildingUUID; + } + + public int getType() { + return this.type; + } + + public int getSlot() { + return this.slot; + } + + public int getUnknown() { + return this.unknown; + } + + public float getLocX() { + return this.location.x; + } + + public float getLocY() { + return this.location.y; + } + + public Vector3fImmutable getLocation() { + return this.location; + } + + public Quaternion getRotation() { + return this.rotation; + } + + @Override + public void updateDatabase() { + } } diff --git a/src/engine/objects/BuildingRegions.java b/src/engine/objects/BuildingRegions.java index 0cd8fddd..e19b0185 100644 --- a/src/engine/objects/BuildingRegions.java +++ b/src/engine/objects/BuildingRegions.java @@ -17,372 +17,294 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; -public class BuildingRegions { - - - private int buildingID; - private int level; - private int numVertex ; - private float vertex1X ; - private float vertex1Y ; - private float vertex1Z ; - private float vertex2X ; - private float vertex2Y ; - private float vertex2Z ; - private float vertex3X ; - private float vertex3Y ; - private float vertex3Z ; - private float vertex4X ; - private float vertex4Y ; - private float vertex4Z ; - private byte ground1; - private byte ground2; - private byte ground3; - private byte ground4; - - private short contentBehavior; - private boolean outside; - private float centerX; - private float centerZ; - private int room = 0; - public static HashMap> _staticRegions = new HashMap<>(); - private final boolean exitRegion; - private final boolean stairs; - - private ArrayList regionPoints = new ArrayList<>(); - public Vector3f center; - - /** - * ResultSet Constructor - */ - - public BuildingRegions(ResultSet rs) throws SQLException { - - buildingID = rs.getInt("buildingID"); - level = rs.getInt("level"); - room = rs.getInt("room"); - numVertex = rs.getInt("numVertex"); - vertex1X = rs.getFloat("vertex1X"); - vertex1Y = rs.getFloat("vertex1Y"); - vertex1Z = rs.getFloat("vertex1Z"); - vertex2X = rs.getFloat("vertex2X"); - vertex2Y = rs.getFloat("vertex2Y"); - vertex2Z = rs.getFloat("vertex2Z"); - vertex3X = rs.getFloat("vertex3X"); - vertex3Y = rs.getFloat("vertex3Y"); - vertex3Z = rs.getFloat("vertex3Z"); - vertex4X = rs.getFloat("vertex4X"); - vertex4Y = rs.getFloat("vertex4Y"); - vertex4Z = rs.getFloat("vertex4Z"); - - regionPoints.add(new Vector3f(vertex1X,vertex1Y,vertex1Z)); - regionPoints.add(new Vector3f(vertex2X,vertex2Y,vertex2Z)); - regionPoints.add(new Vector3f(vertex3X,vertex3Y,vertex3Z)); - - - if(numVertex ==4) - regionPoints.add(new Vector3f(vertex4X,vertex4Y,vertex4Z)); - - - this.contentBehavior = (rs.getShort("unknown_Order1")); - short state = rs.getShort("unknown_Order2"); - - if (state == 2) - this.outside = (true); - else - this.outside = (false); - - this.exitRegion = rs.getBoolean("colOrder1"); - this.stairs = rs.getBoolean("colOrder2"); +public class BuildingRegions { + + + public static HashMap> _staticRegions = new HashMap<>(); + private final boolean exitRegion; + private final boolean stairs; + public Vector3f center; + private int buildingID; + private int level; + private int numVertex; + private float vertex1X; + private float vertex1Y; + private float vertex1Z; + private float vertex2X; + private float vertex2Y; + private float vertex2Z; + private float vertex3X; + private float vertex3Y; + private float vertex3Z; + private float vertex4X; + private float vertex4Y; + private float vertex4Z; + private byte ground1; + private byte ground2; + private byte ground3; + private byte ground4; + private short contentBehavior; + private boolean outside; + private float centerX; + private float centerZ; + private int room = 0; + private ArrayList regionPoints = new ArrayList<>(); + + /** + * ResultSet Constructor + */ + + public BuildingRegions(ResultSet rs) throws SQLException { + + buildingID = rs.getInt("buildingID"); + level = rs.getInt("level"); + room = rs.getInt("room"); + numVertex = rs.getInt("numVertex"); + vertex1X = rs.getFloat("vertex1X"); + vertex1Y = rs.getFloat("vertex1Y"); + vertex1Z = rs.getFloat("vertex1Z"); + vertex2X = rs.getFloat("vertex2X"); + vertex2Y = rs.getFloat("vertex2Y"); + vertex2Z = rs.getFloat("vertex2Z"); + vertex3X = rs.getFloat("vertex3X"); + vertex3Y = rs.getFloat("vertex3Y"); + vertex3Z = rs.getFloat("vertex3Z"); + vertex4X = rs.getFloat("vertex4X"); + vertex4Y = rs.getFloat("vertex4Y"); + vertex4Z = rs.getFloat("vertex4Z"); + + regionPoints.add(new Vector3f(vertex1X, vertex1Y, vertex1Z)); + regionPoints.add(new Vector3f(vertex2X, vertex2Y, vertex2Z)); + regionPoints.add(new Vector3f(vertex3X, vertex3Y, vertex3Z)); + + + if (numVertex == 4) + regionPoints.add(new Vector3f(vertex4X, vertex4Y, vertex4Z)); + + + this.contentBehavior = (rs.getShort("unknown_Order1")); + short state = rs.getShort("unknown_Order2"); + + if (state == 2) + this.outside = (true); + else + this.outside = (false); + + this.exitRegion = rs.getBoolean("colOrder1"); + this.stairs = rs.getBoolean("colOrder2"); + + + ground1 = rs.getByte("colOrder1"); + ground2 = rs.getByte("colOrder2"); + ground3 = rs.getByte("colOrder3"); + ground4 = rs.getByte("colOrder4"); + + float centerY = rs.getFloat("unknown_VectorY"); + centerX = rs.getFloat("unknown_VectorX"); + centerZ = rs.getFloat("unknown_VectorZ"); + + this.center = new Vector3f(centerX, centerY, centerZ); - - - ground1 = rs.getByte("colOrder1"); - ground2 = rs.getByte("colOrder2"); - ground3 = rs.getByte("colOrder3"); - ground4 = rs.getByte("colOrder4"); - - float centerY = rs.getFloat("unknown_VectorY"); - centerX = rs.getFloat("unknown_VectorX"); - centerZ = rs.getFloat("unknown_VectorZ"); - - this.center = new Vector3f(centerX,centerY,centerZ); - - } - - - - public int getBuildingID() { - return buildingID; - } - - - - public void setBuildingID(int buildingID) { - this.buildingID = buildingID; - } - - - - public int getLevel() { - return level; - } - - - - public void setLevel(int level) { - this.level = level; - } - - - - public int getNumVertex() { - return numVertex; - } - - - - public void setNumVertex(int numVertex) { - this.numVertex = numVertex; - } - - - - public float getVertex1X() { - return vertex1X; - } - - - - public void setVertex1X(float vertex1x) { - vertex1X = vertex1x; - } - - - - public float getVertex1Y() { - return vertex1Y; - } - - - - public void setVertex1Y(float vertex1y) { - vertex1Y = vertex1y; - } - - - - public float getVertex1Z() { - return vertex1Z; - } - - - - public void setVertex1Z(float vertex1z) { - vertex1Z = vertex1z; - } - - - - public float getVertex2X() { - return vertex2X; - } - - - - public void setVertex2X(float vertex2x) { - vertex2X = vertex2x; - } - - - - public float getVertex2Y() { - return vertex2Y; - } - - - - public void setVertex2Y(float vertex2y) { - vertex2Y = vertex2y; - } - - - - public float getVertex2Z() { - return vertex2Z; - } - - - - public void setVertex2Z(float vertex2z) { - vertex2Z = vertex2z; - } - - - - public float getVertex3X() { - return vertex3X; - } - - - - public void setVertex3X(float vertex3x) { - vertex3X = vertex3x; - } - - - - public float getVertex3Y() { - return vertex3Y; - } - - - - public void setVertex3Y(float vertex3y) { - vertex3Y = vertex3y; - } + } + public static HashMap> get_staticRegions() { + return _staticRegions; + } + public static void set_staticRegions(HashMap> _staticRegions) { + BuildingRegions._staticRegions = _staticRegions; + } - public float getVertex3Z() { - return vertex3Z; - } + public static void loadAllStaticColliders() { + _staticRegions = DbManager.BuildingQueries.LOAD_BUILDING_REGIONS(); + } + public static ArrayList GetStaticCollidersForMeshID(int meshID) { + return _staticRegions.get(meshID); + } + public int getBuildingID() { + return buildingID; + } - public void setVertex3Z(float vertex3z) { - vertex3Z = vertex3z; - } + public void setBuildingID(int buildingID) { + this.buildingID = buildingID; + } + public int getLevel() { + return level; + } + public void setLevel(int level) { + this.level = level; + } - public float getVertex4X() { - return vertex4X; - } + public int getNumVertex() { + return numVertex; + } + public void setNumVertex(int numVertex) { + this.numVertex = numVertex; + } + public float getVertex1X() { + return vertex1X; + } - public void setVertex4X(float vertex4x) { - vertex4X = vertex4x; - } + public void setVertex1X(float vertex1x) { + vertex1X = vertex1x; + } + public float getVertex1Y() { + return vertex1Y; + } + public void setVertex1Y(float vertex1y) { + vertex1Y = vertex1y; + } - public float getVertex4Y() { - return vertex4Y; - } + public float getVertex1Z() { + return vertex1Z; + } + public void setVertex1Z(float vertex1z) { + vertex1Z = vertex1z; + } + public float getVertex2X() { + return vertex2X; + } - public void setVertex4Y(float vertex4y) { - vertex4Y = vertex4y; - } + public void setVertex2X(float vertex2x) { + vertex2X = vertex2x; + } + public float getVertex2Y() { + return vertex2Y; + } + public void setVertex2Y(float vertex2y) { + vertex2Y = vertex2y; + } - public float getVertex4Z() { - return vertex4Z; - } + public float getVertex2Z() { + return vertex2Z; + } + public void setVertex2Z(float vertex2z) { + vertex2Z = vertex2z; + } + public float getVertex3X() { + return vertex3X; + } - public void setVertex4Z(float vertex4z) { - vertex4Z = vertex4z; - } + public void setVertex3X(float vertex3x) { + vertex3X = vertex3x; + } + public float getVertex3Y() { + return vertex3Y; + } + public void setVertex3Y(float vertex3y) { + vertex3Y = vertex3y; + } - public static HashMap> get_staticRegions() { - return _staticRegions; - } + public float getVertex3Z() { + return vertex3Z; + } + public void setVertex3Z(float vertex3z) { + vertex3Z = vertex3z; + } + public float getVertex4X() { + return vertex4X; + } - public static void set_staticRegions(HashMap> _staticRegions) { - BuildingRegions._staticRegions = _staticRegions; - } + public void setVertex4X(float vertex4x) { + vertex4X = vertex4x; + } + public float getVertex4Y() { + return vertex4Y; + } + public void setVertex4Y(float vertex4y) { + vertex4Y = vertex4y; + } - public static void loadAllStaticColliders(){ - _staticRegions = DbManager.BuildingQueries.LOAD_BUILDING_REGIONS(); - } + public float getVertex4Z() { + return vertex4Z; + } - public static ArrayList GetStaticCollidersForMeshID(int meshID) { - return _staticRegions.get(meshID); - } + public void setVertex4Z(float vertex4z) { + vertex4Z = vertex4z; + } - public boolean isGroundLevel(){ - if (this.level > 0) - return false; + public boolean isGroundLevel() { + if (this.level > 0) + return false; - if (this.ground1 == 0) - return true; - if (this.ground2 == 0) - return true; - if (this.ground3 == 0) - return true; + if (this.ground1 == 0) + return true; + if (this.ground2 == 0) + return true; + if (this.ground3 == 0) + return true; return this.ground4 == 0; } + public float getCenterX() { + return centerX; + } - public float getCenterX() { - return centerX; - } - - - - public void setCenterX(float centerX) { - this.centerX = centerX; - } - - - - public float getCenterY() { - return centerZ; - } - - - - public void setCenterY(float centerY) { - this.centerZ = centerY; - } + public void setCenterX(float centerX) { + this.centerX = centerX; + } - public boolean isOutside() { - return outside; - } + public float getCenterY() { + return centerZ; + } - public short getContentBehavior() { - return contentBehavior; - } + public void setCenterY(float centerY) { + this.centerZ = centerY; + } - public int getRoom() { - return room; - } + public boolean isOutside() { + return outside; + } + public short getContentBehavior() { + return contentBehavior; + } - public ArrayList getRegionPoints() { - return regionPoints; - } + public int getRoom() { + return room; + } + public ArrayList getRegionPoints() { + return regionPoints; + } - public boolean isExitRegion() { - return exitRegion; - } + public boolean isExitRegion() { + return exitRegion; + } - public boolean isStairs() { - return stairs; - } + public boolean isStairs() { + return stairs; + } } diff --git a/src/engine/objects/CharacterItemManager.java b/src/engine/objects/CharacterItemManager.java index bc51e3f8..b4b6fcfa 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -36,595 +36,615 @@ import static engine.math.FastMath.sqr; import static engine.net.client.msg.ErrorPopupMsg.sendErrorPopup; - public class CharacterItemManager { - private final AbstractCharacter absCharacter; - private Account account; - - // Mapping of all the items associated with this Manager - private final ConcurrentHashMap itemIDtoType = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - - // Mapping of all items equipped in this Manager - // Key = Item Slot - private final ConcurrentHashMap equipped = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - - private final HashSet inventory = new HashSet<>(); - private final HashSet bank = new HashSet<>(); - private final HashSet vault = new HashSet<>(); - - private Item goldInventory; - private Item goldBank; - public Item goldVault; - - private boolean bankOpened; - private boolean vaultOpened; - - private short bankWeight; - private short inventoryWeight; - private short equipWeight; - private short vaultWeight; - - private ClientConnection tradingWith; - private byte tradeCommitted; - private boolean tradeSuccess; - private HashSet trading; - private int goldTradingAmount; - private int tradeID = 0; - private final HashSet equipOrder = new HashSet<>(); - - /* - * Item Manager Version data - */ - private byte equipVer = (byte) 0; - private static final byte inventoryVer = (byte) 0; - private static final byte bankVer = (byte) 0; - private static final byte vaultVer = (byte) 0; - - public CharacterItemManager(AbstractCharacter ac) { - super(); - this.absCharacter = ac; - } - - public void load() { - loadForGeneric(); - - if (this.absCharacter .getObjectType().equals(GameObjectType.PlayerCharacter)) - loadForPlayerCharacter(); - else if (this.absCharacter.getObjectType().equals(GameObjectType.NPC)) - loadForNPC(); - - } - - public void loadGoldItems() { - - if (ConfigManager.serverType.equals(Enum.ServerType.LOGINSERVER)) { - //other server, just make generic - this.goldInventory = new MobLoot(this.absCharacter, 0); - this.goldBank = new MobLoot(this.absCharacter, 0); - this.goldVault = new MobLoot(this.absCharacter, 0); - return; - } - - //create inventory gold if needed - if (this.goldInventory == null) - if (this.absCharacter != null && (this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter) || this.absCharacter.getObjectType().equals(GameObjectType.NPC))) - this.goldInventory = Item.newGoldItem(this.absCharacter, ItemBase.getItemBase(7), Enum.ItemContainerType.INVENTORY); - else - this.goldInventory = new MobLoot(this.absCharacter, 0); - - //create bank gold if needed - if (this.goldBank == null) - if (this.absCharacter != null && this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)) - this.goldBank = Item.newGoldItem(this.absCharacter, ItemBase.getItemBase(7), Enum.ItemContainerType.BANK); - else - this.goldBank = new MobLoot(this.absCharacter, 0); - - //create vault gold if needed - if (this.goldVault == null) - if (this.absCharacter != null && this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)){ - this.goldVault = this.account.vaultGold; - } - - else - this.goldVault = new MobLoot(this.absCharacter, 0); - - this.itemIDtoType.put(this.goldInventory.getObjectUUID(), this.goldInventory.getObjectType().ordinal()); - this.itemIDtoType.put(this.goldBank.getObjectUUID(), this.goldBank.getObjectType().ordinal()); - this.itemIDtoType.put(this.goldVault.getObjectUUID(), this.goldVault.getObjectType().ordinal()); - - } - - private void loadForPlayerCharacter() { - ArrayList al = null; - - // TODO Verify this is an actual account. - this.account = ((PlayerCharacter) this.absCharacter).getAccount(); - - // Get Items for player and vault - if (ConfigManager.serverType.equals(Enum.ServerType.LOGINSERVER)) //login, only need equipped items - al = DbManager.ItemQueries.GET_EQUIPPED_ITEMS(this.absCharacter.getObjectUUID()); - else - al = DbManager.ItemQueries.GET_ITEMS_FOR_PC(this.absCharacter.getObjectUUID()); - - for (Item i : al) { - - i.validateItemContainer(); - this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal()); - - switch (i.containerType) { - case EQUIPPED: - if (this.equipped.containsValue(i) == false) { - this.equipped.put((int) i.getEquipSlot(), i); - addEquipOrder((int) i.getEquipSlot()); - } - break; - case BANK: - if (i.getItemBase().getType().equals(ItemType.GOLD)) - this.goldBank = i; - else if (this.bank.contains(i) == false) - this.bank.add(i); - break; - case INVENTORY: - if (i.getItemBase().getType().equals(ItemType.GOLD)) - this.goldInventory = i; - else if (this.inventory.contains(i) == false) - this.inventory.add(i); - break; - case VAULT: - if (i.getItemBase().getType().equals(ItemType.GOLD)) - this.goldVault = i; - else if (this.vault.contains(i) == false) - this.vault.add(i); - break; - default: - i.junk(); - break; - } - - } - - this.goldVault = this.account.vaultGold; - - //check all gold is created - //loadGoldItems(); - calculateWeights(); - } - - private void loadForNPC() { - ArrayList al = null; - - // Get all items related to this NPC: - al = DbManager.ItemQueries.GET_ITEMS_FOR_NPC(this.absCharacter.getObjectUUID()); - - for (Item i : al) { - i.validateItemContainer(); - this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal()); - - switch (i.containerType) { - case EQUIPPED: - if (this.equipped.containsValue(i) == false) - this.equipped.put((int) i.getEquipSlot(), i); - break; - case BANK: - if (i.getItemBase().getType().equals(ItemType.GOLD)) - this.goldBank = i; - else if (this.bank.contains(i) == false) - this.bank.add(i); - break; - case INVENTORY: - if (i.getItemBase().getType().equals(ItemType.GOLD)) - this.goldInventory = i; - else if (this.inventory.contains(i) == false) - this.inventory.add(i); - break; - default: - i.junk(); - break; - } - } - - //check all gold is created - //loadGoldItems(); - } - - private void loadForGeneric() { - this.bankWeight = 0; - this.inventoryWeight = 0; - this.equipWeight = 0; - this.vaultWeight = 0; - - //check all gold is created - //loadGoldItems(); - // Always initialize with bank and vault closed - bankOpened = false; - vaultOpened = false; - } - - //Positve Amount = TO BUILDING; Negative Amount = FROM BUILDING. flip signs for Player inventory. - public synchronized boolean transferGoldToFromBuilding(int amount, AbstractWorldObject object){ + private static final byte inventoryVer = (byte) 0; + private static final byte bankVer = (byte) 0; + private static final byte vaultVer = (byte) 0; + private final AbstractCharacter absCharacter; + // Mapping of all the items associated with this Manager + private final ConcurrentHashMap itemIDtoType = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + // Mapping of all items equipped in this Manager + // Key = Item Slot + private final ConcurrentHashMap equipped = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private final HashSet inventory = new HashSet<>(); + private final HashSet bank = new HashSet<>(); + private final HashSet vault = new HashSet<>(); + private final HashSet equipOrder = new HashSet<>(); + public Item goldVault; + private Account account; + private Item goldInventory; + private Item goldBank; + private boolean bankOpened; + private boolean vaultOpened; + private short bankWeight; + private short inventoryWeight; + private short equipWeight; + private short vaultWeight; + private ClientConnection tradingWith; + private byte tradeCommitted; + private boolean tradeSuccess; + private HashSet trading; + private int goldTradingAmount; + private int tradeID = 0; + /* + * Item Manager Version data + */ + private byte equipVer = (byte) 0; + + public CharacterItemManager(AbstractCharacter ac) { + super(); + this.absCharacter = ac; + } + + public static byte getInventoryVer() { + return inventoryVer; + } + + public static byte getBankVer() { + return bankVer; + } + + public static byte getVaultVer() { + return vaultVer; + } + + public static void takeFromNPC(NPC npc, PlayerCharacter pc, Item take, ClientMessagePump clientMessagePump) { + ItemBase ib = take.getItemBase(); + if (ib == null) + return; + CharacterItemManager itemMan = pc.getCharItemManager(); + if (itemMan == null) + return; + CharacterItemManager npcCim = npc.getCharItemManager(); + if (npcCim == null) + return; + if (!npcCim.inventoryContains(take)) { + return; + } + + if (!itemMan.hasRoomInventory(ib.getWeight())) + return; + if (take != null) { + itemMan.buyFromNPC(take, npc); + itemMan.updateInventory(); + } + } + + public void load() { + loadForGeneric(); + + if (this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)) + loadForPlayerCharacter(); + else if (this.absCharacter.getObjectType().equals(GameObjectType.NPC)) + loadForNPC(); + + } + + public void loadGoldItems() { + + if (ConfigManager.serverType.equals(Enum.ServerType.LOGINSERVER)) { + //other server, just make generic + this.goldInventory = new MobLoot(this.absCharacter, 0); + this.goldBank = new MobLoot(this.absCharacter, 0); + this.goldVault = new MobLoot(this.absCharacter, 0); + return; + } + + //create inventory gold if needed + if (this.goldInventory == null) + if (this.absCharacter != null && (this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter) || this.absCharacter.getObjectType().equals(GameObjectType.NPC))) + this.goldInventory = Item.newGoldItem(this.absCharacter, ItemBase.getItemBase(7), Enum.ItemContainerType.INVENTORY); + else + this.goldInventory = new MobLoot(this.absCharacter, 0); + + //create bank gold if needed + if (this.goldBank == null) + if (this.absCharacter != null && this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)) + this.goldBank = Item.newGoldItem(this.absCharacter, ItemBase.getItemBase(7), Enum.ItemContainerType.BANK); + else + this.goldBank = new MobLoot(this.absCharacter, 0); + + //create vault gold if needed + if (this.goldVault == null) + if (this.absCharacter != null && this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)) { + this.goldVault = this.account.vaultGold; + } else + this.goldVault = new MobLoot(this.absCharacter, 0); + + this.itemIDtoType.put(this.goldInventory.getObjectUUID(), this.goldInventory.getObjectType().ordinal()); + this.itemIDtoType.put(this.goldBank.getObjectUUID(), this.goldBank.getObjectType().ordinal()); + this.itemIDtoType.put(this.goldVault.getObjectUUID(), this.goldVault.getObjectType().ordinal()); + + } + + private void loadForPlayerCharacter() { + ArrayList al = null; + + // TODO Verify this is an actual account. + this.account = ((PlayerCharacter) this.absCharacter).getAccount(); + + // Get Items for player and vault + if (ConfigManager.serverType.equals(Enum.ServerType.LOGINSERVER)) //login, only need equipped items + al = DbManager.ItemQueries.GET_EQUIPPED_ITEMS(this.absCharacter.getObjectUUID()); + else + al = DbManager.ItemQueries.GET_ITEMS_FOR_PC(this.absCharacter.getObjectUUID()); + + for (Item i : al) { + + i.validateItemContainer(); + this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal()); + + switch (i.containerType) { + case EQUIPPED: + if (this.equipped.containsValue(i) == false) { + this.equipped.put((int) i.getEquipSlot(), i); + addEquipOrder((int) i.getEquipSlot()); + } + break; + case BANK: + if (i.getItemBase().getType().equals(ItemType.GOLD)) + this.goldBank = i; + else if (this.bank.contains(i) == false) + this.bank.add(i); + break; + case INVENTORY: + if (i.getItemBase().getType().equals(ItemType.GOLD)) + this.goldInventory = i; + else if (this.inventory.contains(i) == false) + this.inventory.add(i); + break; + case VAULT: + if (i.getItemBase().getType().equals(ItemType.GOLD)) + this.goldVault = i; + else if (this.vault.contains(i) == false) + this.vault.add(i); + break; + default: + i.junk(); + break; + } + + } + + this.goldVault = this.account.vaultGold; + + //check all gold is created + //loadGoldItems(); + calculateWeights(); + } + + private void loadForNPC() { + ArrayList al = null; + + // Get all items related to this NPC: + al = DbManager.ItemQueries.GET_ITEMS_FOR_NPC(this.absCharacter.getObjectUUID()); + + for (Item i : al) { + i.validateItemContainer(); + this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal()); + + switch (i.containerType) { + case EQUIPPED: + if (this.equipped.containsValue(i) == false) + this.equipped.put((int) i.getEquipSlot(), i); + break; + case BANK: + if (i.getItemBase().getType().equals(ItemType.GOLD)) + this.goldBank = i; + else if (this.bank.contains(i) == false) + this.bank.add(i); + break; + case INVENTORY: + if (i.getItemBase().getType().equals(ItemType.GOLD)) + this.goldInventory = i; + else if (this.inventory.contains(i) == false) + this.inventory.add(i); + break; + default: + i.junk(); + break; + } + } + + //check all gold is created + //loadGoldItems(); + } + + private void loadForGeneric() { + this.bankWeight = 0; + this.inventoryWeight = 0; + this.equipWeight = 0; + this.vaultWeight = 0; + + //check all gold is created + //loadGoldItems(); + // Always initialize with bank and vault closed + bankOpened = false; + vaultOpened = false; + } + + //Positve Amount = TO BUILDING; Negative Amount = FROM BUILDING. flip signs for Player inventory. + public synchronized boolean transferGoldToFromBuilding(int amount, AbstractWorldObject object) { if (this.absCharacter.getObjectType() != GameObjectType.PlayerCharacter) - return false; + return false; PlayerCharacter player = (PlayerCharacter) this.absCharacter; - switch (object.getObjectType()){ - case Building: - Building building = (Building)object; + switch (object.getObjectType()) { + case Building: + Building building = (Building) object; + + if (!this.getGoldInventory().validForInventory(player.getClientConnection(), player, this)) + return false; + + if (amount < 0 && amount > building.getStrongboxValue()) + return false; + + // Not enough gold in inventory to transfer to tree + + if ((amount > 0) && + (this.getGoldInventory().getNumOfItems() - amount < 0)) { + sendErrorPopup(player, 28); + return false; + } + + if (this.getGoldInventory().getNumOfItems() - amount > MBServerStatics.PLAYER_GOLD_LIMIT) { + ErrorPopupMsg.sendErrorPopup(player, 202); + return false; + } + + + // Not enough gold to transfer to inventory from tree + + if ((amount < 0) && + (building.getStrongboxValue() + amount < 0)) { + sendErrorPopup(player, 127); + return false; + } + + if (amount < 0) + if (!building.hasFunds(-amount)) + return false; + + //Verify player can access building to transfer goldItem + + if (!BuildingManager.playerCanManage(player, building)) + return false; - if (!this.getGoldInventory().validForInventory(player.getClientConnection(), player, this)) - return false; + if (building.getStrongboxValue() + amount > building.getMaxGold()) { + ErrorPopupMsg.sendErrorPopup(player, 201); + return false; + } - if (amount <0 && amount > building.getStrongboxValue()) - return false; + if (this.getOwner().getCharItemManager().getGoldTrading() > 0) { + if (this.getOwner().getObjectType().equals(GameObjectType.PlayerCharacter)) + ErrorPopupMsg.sendErrorPopup((PlayerCharacter) this.getOwner(), 195); + return false; + } - // Not enough gold in inventory to transfer to tree + if (!this.modifyInventoryGold(-amount)) { - if ((amount > 0) && - (this.getGoldInventory().getNumOfItems() - amount < 0)) { - sendErrorPopup(player, 28); - return false; - } + Logger.error(player.getName() + " transfer amount = " + amount + " ; Gold Inventory = " + this.getGoldInventory().getNumOfItems()); - if (this.getGoldInventory().getNumOfItems() - amount > MBServerStatics.PLAYER_GOLD_LIMIT){ - ErrorPopupMsg.sendErrorPopup(player, 202); - return false; - } - - + // ChatManager.chatSystemError(player, "You do not have this Gold."); + return false; + } - // Not enough gold to transfer to inventory from tree + if (!building.transferGold(amount, false)) { - if ((amount < 0) && - (building.getStrongboxValue() + amount < 0)) { - sendErrorPopup(player, 127); - return false; - } + Logger.error(player.getName() + " transfer amount = " + amount + " ; Gold Inventory = " + this.getGoldInventory().getNumOfItems() + "; Building Strongbox = " + building.getStrongboxValue()); - if (amount < 0) - if (!building.hasFunds(-amount)) - return false; + //ChatManager.chatSystemError(player, "Something went terribly wrong. Contact CCR."); + return false; + } - //Verify player can access building to transfer goldItem + break; + case Warehouse: - if (!BuildingManager.playerCanManage(player, building)) - return false; + Warehouse warehouse = (Warehouse) object; - if (building.getStrongboxValue() + amount > building.getMaxGold()){ - ErrorPopupMsg.sendErrorPopup(player, 201); - return false; - } - - if (this.getOwner().getCharItemManager().getGoldTrading() > 0){ - if (this.getOwner().getObjectType().equals(GameObjectType.PlayerCharacter)) - ErrorPopupMsg.sendErrorPopup((PlayerCharacter)this.getOwner(), 195); - return false; - } + if (amount < 0) { + if (!warehouse.deposit((PlayerCharacter) this.absCharacter, this.getGoldInventory(), amount * -1, true, true)) { - if (!this.modifyInventoryGold(-amount)){ + ErrorPopupMsg.sendErrorPopup((PlayerCharacter) this.absCharacter, 203); + return false; + } + } else { + if (!warehouse.withdraw((PlayerCharacter) this.absCharacter, this.getGoldInventory().getItemBase(), amount * -1, true, true)) { - Logger.error(player.getName() + " transfer amount = " + amount +" ; Gold Inventory = " + this.getGoldInventory().getNumOfItems()); + ErrorPopupMsg.sendErrorPopup((PlayerCharacter) this.absCharacter, 203); + return false; + } - // ChatManager.chatSystemError(player, "You do not have this Gold."); - return false; - } + } - if (!building.transferGold(amount,false)){ + break; - Logger.error(player.getName() + " transfer amount = " + amount +" ; Gold Inventory = " + this.getGoldInventory().getNumOfItems() + "; Building Strongbox = " + building.getStrongboxValue()); + } + return true; + } + + /* + * Item Controls + */ + public synchronized boolean modifyInventoryGold(int modifyValue) { + + Item goldItem; + PlayerCharacter player; + boolean success = false; + + goldItem = getGoldInventory(); + + if (goldItem == null) { + Logger.error("ModifyInventoryGold", "Could not create gold item"); + return success; + } + + if (this.getGoldInventory().getNumOfItems() + modifyValue > MBServerStatics.PLAYER_GOLD_LIMIT) { + return false; + } + + if (this.getGoldInventory().getNumOfItems() + modifyValue < 0) + return false; - //ChatManager.chatSystemError(player, "Something went terribly wrong. Contact CCR."); - return false; - } + // No database update for npc's gold values so we use the player object + // for flow control later on. - break; - case Warehouse: + if (this.absCharacter.getObjectType() == GameObjectType.PlayerCharacter) + player = (PlayerCharacter) this.absCharacter; + else + player = null; - Warehouse warehouse = (Warehouse)object; + // If this is an update for a player character update the database - if (amount < 0){ - if (!warehouse.deposit((PlayerCharacter) this.absCharacter, this.getGoldInventory(), amount*-1, true,true)){ + if (player != null) + try { + if (!DbManager.ItemQueries.UPDATE_GOLD(this.getGoldInventory(), this.goldInventory.getNumOfItems() + modifyValue)) { + return false; + } - ErrorPopupMsg.sendErrorPopup((PlayerCharacter) this.absCharacter, 203); - return false; - } - }else{ - if (!warehouse.withdraw((PlayerCharacter) this.absCharacter, this.getGoldInventory().getItemBase(), amount*-1, true,true)){ - ErrorPopupMsg.sendErrorPopup((PlayerCharacter) this.absCharacter, 203); - return false; - } + success = true; + } catch (Exception e) { + Logger.error("ModifyInventoryGold", "Error writing to database"); + } - } + // Update in-game gold values for character + goldItem.setNumOfItems(goldItem.getNumOfItems() + modifyValue); + UpdateGoldMsg ugm = new UpdateGoldMsg(this.absCharacter); + ugm.configure(); - break; + Dispatch dispatch = Dispatch.borrow(player, ugm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } - return true; - } + return success; + } - /* - * Item Controls - */ - public synchronized boolean modifyInventoryGold(int modifyValue) { + public synchronized boolean tradeRequest(TradeRequestMsg msg) { - Item goldItem; - PlayerCharacter player; - boolean success = false; + PlayerCharacter source = (PlayerCharacter) this.getOwner(); + PlayerCharacter target = PlayerCharacter.getFromCache(msg.getPlayerID()); + Dispatch dispatch; - goldItem = getGoldInventory(); + if (!canTrade(source, target)) { + ChatManager.chatSystemError(source, "Can't currently trade with target player"); + return false; + } - if (goldItem == null) { - Logger.error("ModifyInventoryGold", "Could not create gold item"); - return success; - } + // TODO uncomment this block after we determine when we + // setBankOpen(false) and setVaultOpen(false) + CharacterItemManager cim1 = source.getCharItemManager(); + CharacterItemManager cim2 = target.getCharItemManager(); - if (this.getGoldInventory().getNumOfItems() + modifyValue > MBServerStatics.PLAYER_GOLD_LIMIT){ - return false; - } + if (cim1 == null) + return false; - if (this.getGoldInventory().getNumOfItems() + modifyValue < 0) - return false; + if (cim2 == null) + return false; - // No database update for npc's gold values so we use the player object - // for flow control later on. + dispatch = Dispatch.borrow(target, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + return true; - if (this.absCharacter.getObjectType() == GameObjectType.PlayerCharacter) - player = (PlayerCharacter) this.absCharacter; - else - player = null; + } - // If this is an update for a player character update the database + public synchronized boolean invalidTradeRequest(InvalidTradeRequestMsg msg) { + PlayerCharacter requester = PlayerCharacter.getFromCache(msg.getRequesterID()); + Dispatch dispatch; - if (player != null) - try { - if (!DbManager.ItemQueries.UPDATE_GOLD(this.getGoldInventory(), this.goldInventory.getNumOfItems() + modifyValue)){ - return false; - } + dispatch = Dispatch.borrow(requester, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + return true; + } - success = true; - } catch (Exception e) { - Logger.error("ModifyInventoryGold", "Error writing to database"); - } + public synchronized boolean canTrade(PlayerCharacter playerA, PlayerCharacter playerB) { - // Update in-game gold values for character - goldItem.setNumOfItems(goldItem.getNumOfItems() + modifyValue); - UpdateGoldMsg ugm = new UpdateGoldMsg(this.absCharacter); - ugm.configure(); + if (playerA == null || playerB == null) + return false; - Dispatch dispatch = Dispatch.borrow(player, ugm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + //make sure both are alive + if (!playerA.isAlive() || !playerB.isAlive()) + return false; - return success; - } - - public synchronized boolean tradeRequest(TradeRequestMsg msg) { + //distance check + Vector3fImmutable aLoc = playerA.getLoc(); + Vector3fImmutable bLoc = playerB.getLoc(); - PlayerCharacter source = (PlayerCharacter) this.getOwner(); - PlayerCharacter target = PlayerCharacter.getFromCache(msg.getPlayerID()); - Dispatch dispatch; + if (aLoc.distanceSquared2D(bLoc) > sqr(MBServerStatics.TRADE_RANGE)) + return false; - if (!canTrade(source, target)) { - ChatManager.chatSystemError(source, "Can't currently trade with target player"); - return false; - } + //visibility check + if (!playerA.canSee(playerB) || !playerB.canSee(playerA)) + return false; - // TODO uncomment this block after we determine when we - // setBankOpen(false) and setVaultOpen(false) - CharacterItemManager cim1 = source.getCharItemManager(); - CharacterItemManager cim2 = target.getCharItemManager(); + if (playerA.lastBuildingAccessed != 0) { + ManageCityAssetsMsg mca = new ManageCityAssetsMsg(); + mca.actionType = 4; + mca.setTargetType(Enum.GameObjectType.Building.ordinal()); + mca.setTargetID(playerA.lastBuildingAccessed); + Dispatch dispatch = Dispatch.borrow(playerA, mca); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + playerA.lastBuildingAccessed = 0; + } - if (cim1 == null) - return false; + return true; + } - if (cim2 == null) - return false; + public synchronized boolean acceptTradeRequest(AcceptTradeRequestMsg msg) { - dispatch = Dispatch.borrow(target, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - return true; + PlayerCharacter source = (PlayerCharacter) this.getOwner(); + PlayerCharacter target = PlayerCharacter.getFromCache(msg.getTargetID()); - } - - public synchronized boolean invalidTradeRequest(InvalidTradeRequestMsg msg) { - PlayerCharacter requester = PlayerCharacter.getFromCache(msg.getRequesterID()); - Dispatch dispatch; + Dispatch dispatch; - dispatch = Dispatch.borrow(requester, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - return true; + if (source == null || !source.isAlive()) + return false; - } - - public synchronized boolean canTrade(PlayerCharacter playerA, PlayerCharacter playerB) { + if (target == null || !target.isAlive()) + return false; - if (playerA == null || playerB == null) - return false; - - //make sure both are alive - if (!playerA.isAlive() || !playerB.isAlive()) - return false; - - //distance check - Vector3fImmutable aLoc = playerA.getLoc(); - Vector3fImmutable bLoc = playerB.getLoc(); - - if (aLoc.distanceSquared2D(bLoc) > sqr(MBServerStatics.TRADE_RANGE)) - return false; - - //visibility check - if (!playerA.canSee(playerB) || !playerB.canSee(playerA)) - return false; - - if (playerA.lastBuildingAccessed != 0) { - ManageCityAssetsMsg mca = new ManageCityAssetsMsg(); - mca.actionType = 4; - mca.setTargetType(Enum.GameObjectType.Building.ordinal()); - mca.setTargetID(playerA.lastBuildingAccessed); - Dispatch dispatch = Dispatch.borrow(playerA, mca); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - playerA.lastBuildingAccessed = 0; - } - - return true; - } - - public synchronized boolean acceptTradeRequest(AcceptTradeRequestMsg msg) { + if (this.tradingWith != null) + return false; - PlayerCharacter source = (PlayerCharacter)this.getOwner(); - PlayerCharacter target = PlayerCharacter.getFromCache(msg.getTargetID()); + if (!canTrade(source, target)) + return false; - Dispatch dispatch; + // verify characterTarget is in range + if (source.getLoc().distanceSquared2D(target.getLoc()) > sqr(MBServerStatics.TRADE_RANGE)) + return false; - if (source == null || !source.isAlive()) - return false; + // TODO uncomment this block after we determine when we + // setBankOpen(false) and setVaultOpen(false) + /* + * CharacterItemManager cim1 = source.getCharItemManager(); + * CharacterItemManager cim2 = characterTarget.getCharItemManager(); if (cim1 == + * null) return false; if (cim2 == null) return false; if (cim1.isBankOpen()) + * return false; if (cim2.isVaultOpen()) return false; + */ + ClientConnection sourceConn = source.getClientConnection(); + ClientConnection targetConn = target.getClientConnection(); + + if (sourceConn == null) + return false; - if (target == null || !target.isAlive()) - return false; + if (targetConn == null) + return false; - if (this.tradingWith != null) - return false; - - if (!canTrade(source, target)) - return false; - // verify characterTarget is in range - if (source.getLoc().distanceSquared2D(target.getLoc()) > sqr(MBServerStatics.TRADE_RANGE)) - return false; + CharacterItemManager toTradeWith = target.getCharItemManager(); - // TODO uncomment this block after we determine when we - // setBankOpen(false) and setVaultOpen(false) - /* - * CharacterItemManager cim1 = source.getCharItemManager(); - * CharacterItemManager cim2 = characterTarget.getCharItemManager(); if (cim1 == - * null) return false; if (cim2 == null) return false; if (cim1.isBankOpen()) - * return false; if (cim2.isVaultOpen()) return false; - */ - ClientConnection sourceConn = source.getClientConnection(); - ClientConnection targetConn = target.getClientConnection(); + if (toTradeWith == null) + return false; - if (sourceConn == null) - return false; + Account sourceAccount = source.getAccount(); + Account targetAccount = target.getAccount(); - if (targetConn == null) - return false; + UpdateVaultMsg uvmSource = new UpdateVaultMsg(sourceAccount); + UpdateVaultMsg uvmTarget = new UpdateVaultMsg(targetAccount); - - CharacterItemManager toTradeWith = target.getCharItemManager(); + dispatch = Dispatch.borrow(source, uvmSource); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); - if (toTradeWith == null) - return false; + dispatch = Dispatch.borrow(target, uvmTarget); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); - Account sourceAccount = source.getAccount(); - Account targetAccount = target.getAccount(); + this.setVaultOpen(false); + toTradeWith.setVaultOpen(false); + this.setBankOpen(false); + toTradeWith.setBankOpen(false); - UpdateVaultMsg uvmSource = new UpdateVaultMsg(sourceAccount); - UpdateVaultMsg uvmTarget = new UpdateVaultMsg(targetAccount); + OpenTradeWindowMsg otwm = new OpenTradeWindowMsg(msg.getUnknown01(), source, target); - dispatch = Dispatch.borrow(source, uvmSource); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); + // Only start trade if both players aren't already trading with + // someone - dispatch = Dispatch.borrow(target, uvmTarget); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); + if (this.getTradingWith() != null || toTradeWith.getTradingWith() != null) + return false; - this.setVaultOpen(false); - toTradeWith.setVaultOpen(false); - this.setBankOpen(false); - toTradeWith.setBankOpen(false); + this.initializeTrade(); + toTradeWith.initializeTrade(); + this.setTradingWith(targetConn); + toTradeWith.setTradingWith(sourceConn); + this.tradeID = msg.getUnknown01(); + toTradeWith.tradeID = msg.getUnknown01(); - OpenTradeWindowMsg otwm = new OpenTradeWindowMsg(msg.getUnknown01(), source, target); + dispatch = Dispatch.borrow(source, otwm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); - // Only start trade if both players aren't already trading with - // someone - - if (this.getTradingWith() != null || toTradeWith.getTradingWith() != null) - return false; - - this.initializeTrade(); - toTradeWith.initializeTrade(); - this.setTradingWith(targetConn); - toTradeWith.setTradingWith(sourceConn); - this.tradeID = msg.getUnknown01(); - toTradeWith.tradeID = msg.getUnknown01(); + dispatch = Dispatch.borrow(target, otwm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); - dispatch = Dispatch.borrow(source, otwm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); + return true; + } - dispatch = Dispatch.borrow(target, otwm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); + public synchronized boolean addItemToTradeWindow(AddItemToTradeWindowMsg msg) { + PlayerCharacter source = (PlayerCharacter) this.getOwner(); + Dispatch dispatch; - return true; - } - - public synchronized boolean addItemToTradeWindow(AddItemToTradeWindowMsg msg) { - PlayerCharacter source =(PlayerCharacter)this.getOwner(); - Dispatch dispatch; + if (source == null || !source.isAlive()) + return false; - if (source == null || !source.isAlive()) - return false; - + ClientConnection ccOther = this.getTradingWith(); + if (ccOther == null) + return false; - ClientConnection ccOther = this.getTradingWith(); + PlayerCharacter other = ccOther.getPlayerCharacter(); - if (ccOther == null) - return false; + if (other == null || !other.isAlive()) + return false; - PlayerCharacter other = ccOther.getPlayerCharacter(); + CharacterItemManager tradingWith = other.getCharItemManager(); - if (other == null || !other.isAlive()) - return false; + if (tradingWith == null) + return false; - CharacterItemManager tradingWith = other.getCharItemManager(); + if (!canTrade(source, other)) + return false; - if (tradingWith == null) - return false; + Item i = Item.getFromCache(msg.getItemID()); - if (!canTrade(source, other)) - return false; + if (i == null) + return false; - Item i = Item.getFromCache(msg.getItemID()); + if (!this.doesCharOwnThisItem(i.getObjectUUID())) + return false; - if (i == null) - return false; + //can't add item to trade window twice + if (this.tradingContains(i)) + return false; - if (!this.doesCharOwnThisItem(i.getObjectUUID())) - return false; + //dupe check + if (!i.validForInventory(source.getClientConnection(), source, this)) + return false; - //can't add item to trade window twice - if (this.tradingContains(i)) - return false; + if (!tradingWith.hasRoomTrade(i.getItemBase().getWeight())) { + dispatch = Dispatch.borrow(source, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); + return false; + } - //dupe check - if (!i.validForInventory(source.getClientConnection(), source, this)) - return false; + UpdateTradeWindowMsg utwm = new UpdateTradeWindowMsg(source, other); - if (!tradingWith.hasRoomTrade(i.getItemBase().getWeight())) { - dispatch = Dispatch.borrow(source, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); - return false; - } + this.setTradeCommitted((byte) 0); + tradingWith.setTradeCommitted((byte) 0); - UpdateTradeWindowMsg utwm = new UpdateTradeWindowMsg(source, other); + this.addItemToTrade(i); - this.setTradeCommitted((byte) 0); - tradingWith.setTradeCommitted((byte) 0); + dispatch = Dispatch.borrow(other, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); - this.addItemToTrade(i); - - dispatch = Dispatch.borrow(other, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); + modifyCommitToTrade(); - modifyCommitToTrade(); + dispatch = Dispatch.borrow(other, utwm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); + return true; + } - dispatch = Dispatch.borrow(other, utwm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); - return true; - } - - public synchronized boolean addGoldToTradeWindow(AddGoldToTradeWindowMsg msg) { + public synchronized boolean addGoldToTradeWindow(AddGoldToTradeWindowMsg msg) { PlayerCharacter source = (PlayerCharacter) this.getOwner(); Dispatch dispatch; @@ -632,8 +652,6 @@ public class CharacterItemManager { if (source == null || !source.isAlive()) return false; - - ClientConnection ccOther = this.getTradingWith(); @@ -661,16 +679,16 @@ public class CharacterItemManager { int amt = msg.getAmount(); - if (amt <= 0){ - Logger.info( source.getFirstName() + " added negative gold to trade window. Dupe attempt FAILED!"); + if (amt <= 0) { + Logger.info(source.getFirstName() + " added negative gold to trade window. Dupe attempt FAILED!"); return false; } - + if (amt > MBServerStatics.PLAYER_GOLD_LIMIT) - return false; - + return false; + if (this.getGoldInventory().getNumOfItems() - amt < 0) - return false; + return false; this.addGoldToTrade(amt); @@ -690,12 +708,11 @@ public class CharacterItemManager { dispatch = Dispatch.borrow(other, utwmOther); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - return true; + return true; } - - - public synchronized boolean uncommitToTrade(UncommitToTradeMsg msg) { + + public synchronized boolean uncommitToTrade(UncommitToTradeMsg msg) { PlayerCharacter source = (PlayerCharacter) this.getOwner(); @@ -724,17 +741,15 @@ public class CharacterItemManager { return modifyCommitToTrade(); } - - public synchronized boolean commitToTrade(CommitToTradeMsg msg) { - PlayerCharacter source = (PlayerCharacter)this.getOwner(); + public synchronized boolean commitToTrade(CommitToTradeMsg msg) { + + PlayerCharacter source = (PlayerCharacter) this.getOwner(); if (source == null || !source.isAlive()) return false; - - this.setTradeCommitted((byte) 1); ClientConnection ccOther = this.getTradingWith(); @@ -758,1873 +773,1824 @@ public class CharacterItemManager { modifyCommitToTrade(); if (this.getTradeCommitted() == (byte) 1 && tradingWith.getTradeCommitted() == (byte) 1) { - int tradeID = this.tradeID; + int tradeID = this.tradeID; CloseTradeWindowMsg ctwm1 = new CloseTradeWindowMsg(source, tradeID); CloseTradeWindowMsg ctwm2 = new CloseTradeWindowMsg(other, tradeID); this.commitTrade(); this.closeTradeWindow(ctwm1, false); other.getCharItemManager().closeTradeWindow(ctwm2, false); } - return true; - } - - private synchronized boolean modifyCommitToTrade() { - CharacterItemManager man1 = this; - - if (this.getTradingWith() == null) - return false; - - if (this.getTradingWith().getPlayerCharacter() == null) - return false; - CharacterItemManager man2 = this.getTradingWith().getPlayerCharacter().getCharItemManager(); - Dispatch dispatch; - - if (man1 == null || man2 == null) - return false; - - ModifyCommitToTradeMsg modify = new ModifyCommitToTradeMsg(this.getOwner(), man2.getOwner(), man1.getTradeCommitted(), - man2.getTradeCommitted()); - - dispatch = Dispatch.borrow((PlayerCharacter) this.getOwner(), modify); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - dispatch = Dispatch.borrow((PlayerCharacter) man2.getOwner(), modify); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - return true; - - } - - public synchronized boolean closeTradeWindow(CloseTradeWindowMsg msg, boolean sourceTrade) { - - - Dispatch dispatch; - - PlayerCharacter source = (PlayerCharacter) this.getOwner(); - if (source == null) - return false; - - CharacterItemManager sourceItemMan = source.getCharItemManager(); - - if (sourceItemMan == null) - return false; - - int tradeID = this.tradeID; - CloseTradeWindowMsg closeMsg = new CloseTradeWindowMsg(source,tradeID); - - dispatch = Dispatch.borrow(source, closeMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - if (!sourceTrade){ - sourceItemMan.endTrade(); - return true; - } - - ClientConnection cc2 = sourceItemMan.getTradingWith(); - - if (cc2 == null || cc2.getPlayerCharacter() == null){ - sourceItemMan.endTrade(); - return true; - } - - sourceItemMan.endTrade(); - - - - cc2.getPlayerCharacter().getCharItemManager().closeTradeWindow(msg, false); - - - - - return true; - } - - public Item getGoldInventory() { - if (this.goldInventory == null) - loadGoldItems(); - return this.goldInventory; - } - - public Item getGoldBank() { - if (this.goldBank == null) - loadGoldItems(); - return this.goldBank; - } - - public Item getGoldVault() { - if (this.goldVault == null) - loadGoldItems(); - return this.goldVault; - } - - public void addEquipOrder(int slot) { - synchronized (this.equipOrder) { - Integer iSlot = slot; - if (this.equipOrder.contains(iSlot)) - this.equipOrder.remove(iSlot); - this.equipOrder.add(slot); - } - } - - public synchronized boolean doesCharOwnThisItem(int itemID) { - return this.itemIDtoType.containsKey(itemID); - } - - public synchronized boolean junk(Item i) { - return junk(i, true); - } - - public synchronized boolean recycle(Item i) { - if (i.getObjectType() == GameObjectType.Item) - return junk(i, false); - else{ - if(this.removeItemFromInventory(i) == false) - return false; - ((MobLoot)i).recycle((NPC)this.absCharacter); - calculateInventoryWeight(); - return true; - } - } - - // The DeleteItemMsg takes care of updating inventory, so we don't want to do it separately - public synchronized boolean delete(Item i) { - return junk(i, false); - } - - //cleanup an item from CharacterItemManager if it doesn't belong here - public synchronized boolean cleanupDupe(Item i) { - if (i == null) - return false; - - if(i.getItemBase().getType().equals(ItemType.GOLD)){ - if (this.getGoldInventory() != null){ - if (i.getObjectUUID() == this.getGoldInventory().getObjectUUID()) - this.goldInventory = null; - }else if (this.getGoldBank() != null){ - if (i.getObjectUUID() == this.getGoldBank().getObjectUUID()) - this.goldBank = null; - } - return true; - } - - byte slot = i.getEquipSlot(); - - if (this.doesCharOwnThisItem(i.getObjectUUID()) == false) - return false; - - // remove it from other lists: - this.remItemFromLists(i, slot); - this.itemIDtoType.remove(i.getObjectUUID()); - - calculateWeights(); - return true; - } - - public synchronized boolean consume(Item i) { - i.decrementChargesRemaining(); - if (i.getChargesRemaining() > 0) - return true; - return junk(i, true); - } - - private synchronized boolean junk(Item i, boolean updateInventory) { - if (i.getItemBase().getType().equals(ItemType.GOLD)) { - if (this.getGoldInventory().getObjectUUID() == i.getObjectUUID()) - if (DbManager.ItemQueries.UPDATE_GOLD(i, 0)) { - this.getGoldInventory().setNumOfItems(0); - if (updateInventory) - updateInventory(); - return true; - }else{ - return false; - } - if (!(this.absCharacter.getObjectType().equals(GameObjectType.Mob))) - return false; - } - - byte slot = i.getEquipSlot(); + return true; + } - if (this.doesCharOwnThisItem(i.getObjectUUID()) == false && this.absCharacter.getObjectType() != GameObjectType.Mob && (i.containerType != Enum.ItemContainerType.FORGE)) - return false; + private synchronized boolean modifyCommitToTrade() { + CharacterItemManager man1 = this; - // remove it from other lists: - this.remItemFromLists(i, slot); - this.itemIDtoType.remove(i.getObjectUUID()); + if (this.getTradingWith() == null) + return false; + + if (this.getTradingWith().getPlayerCharacter() == null) + return false; + CharacterItemManager man2 = this.getTradingWith().getPlayerCharacter().getCharItemManager(); + Dispatch dispatch; - i.junk(); + if (man1 == null || man2 == null) + return false; - //Why are we adding junked items?! + ModifyCommitToTradeMsg modify = new ModifyCommitToTradeMsg(this.getOwner(), man2.getOwner(), man1.getTradeCommitted(), + man2.getTradeCommitted()); - // if (i.getObjectType() != GameObjectType.MobLoot) - // CharacterItemManager.junkedItems.add(i); + dispatch = Dispatch.borrow((PlayerCharacter) this.getOwner(), modify); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + dispatch = Dispatch.borrow((PlayerCharacter) man2.getOwner(), modify); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - calculateWeights(); - - if (updateInventory) - // Send the new inventory - //updateInventory(i, false); this line was causing entire inventory to disappear - updateInventory(this.getInventory(), true); - - return true; - } - - public synchronized boolean moveItemToInventory(Item i) { - - boolean fromEquip = false; - synchronized (this) { - byte slot = i.getEquipSlot(); - - //Skip if NOT in vault. - if (i.containerType != Enum.ItemContainerType.VAULT) - if (this.doesCharOwnThisItem(i.getObjectUUID()) == false) - return false; - - // Only valid from bank, equip and vault - if (!bankContains(i) && !equippedContains(i) && !vaultContains(i)) - return false; - - if (equippedContains(i)) { - fromEquip = true; - ItemBase ib = i.getItemBase(); - if (ib != null && ib.getType().equals(ItemType.GOLD)) - this.absCharacter.cancelOnUnEquip(); - } - - // check to see what type of AbstractCharacter subclass we have stored - if (this.absCharacter.getClass() == PlayerCharacter.class) { - if (!i.moveItemToInventory((PlayerCharacter) this.absCharacter)) - return false; - } else if (!i.moveItemToInventory((NPC) this.absCharacter)) - return false; - - // remove it from other lists: - this.remItemFromLists(i, slot); - - // add to Inventory - this.inventory.add(i); - i.addToCache(); - this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal()); - - calculateWeights(); - } - - //Apply bonuses if from equip - if (fromEquip && this.absCharacter != null) { - this.absCharacter.applyBonuses(); - if (this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)) - this.absCharacter.incVer(); - } - - return true; - } - - public synchronized boolean moveItemToBank(Item i) { - byte slot = i.getEquipSlot(); - - if (this.doesCharOwnThisItem(i.getObjectUUID()) == false) - return false; - - // Item must be in inventory to move to bank - if (!this.inventory.contains(i)) - return false; - - // check to see what type of AbstractCharacter subclass we have stored - if (this.absCharacter.getClass() == PlayerCharacter.class) { - if (!i.moveItemToBank((PlayerCharacter) this.absCharacter)) - return false; - } else if (!i.moveItemToBank((NPC) this.absCharacter)) - return false; - - // remove it from other lists: - this.remItemFromLists(i, slot); - - // add to Bank - this.bank.add(i); - i.addToCache(); - - calculateWeights(); - - return true; - } - - public synchronized boolean moveGoldToBank(Item from, int amt) { - if (from == null) - return false; - if (from.getNumOfItems() - amt < 0) - return false; - if (this.goldBank.getNumOfItems() + amt > MBServerStatics.BANK_GOLD_LIMIT){ - if (this.absCharacter.getObjectType() == GameObjectType.PlayerCharacter){ - PlayerCharacter pc = (PlayerCharacter)this.absCharacter; - if (pc.getClientConnection() != null) - ErrorPopupMsg.sendErrorPopup(pc, 202); - return false; - } - } - - if (!DbManager.ItemQueries.MOVE_GOLD(from, this.getGoldBank(), amt)) - return false; - from.setNumOfItems(from.getNumOfItems() - amt); - this.goldBank.setNumOfItems(this.goldBank.getNumOfItems() + amt); - return true; - } - - public synchronized boolean moveGoldToVault(Item from, int amt) { - if (from == null) - return false; - if (from.getNumOfItems() - amt < 0) - return false; - if (!DbManager.ItemQueries.MOVE_GOLD(from, this.account.vaultGold, amt)) - return false; - from.setNumOfItems(from.getNumOfItems() - amt); - this.account.vaultGold.setNumOfItems(this.goldVault.getNumOfItems() + amt); - return true; - } - - public synchronized boolean moveGoldToInventory(Item from, int amt) { - if (from == null) - return false; - if (from.getNumOfItems() - amt < 0 || amt < 1) - return false; - - if (this.goldInventory.getNumOfItems() + amt > MBServerStatics.PLAYER_GOLD_LIMIT){ - if (this.absCharacter.getObjectType() == GameObjectType.PlayerCharacter){ - PlayerCharacter pc = (PlayerCharacter)this.absCharacter; - if (pc.getClientConnection() != null) - ErrorPopupMsg.sendErrorPopup(pc, 202); - return false; - } - } - - if (from instanceof MobLoot) { - if (!DbManager.ItemQueries.UPDATE_GOLD(this.getGoldInventory(), - this.goldInventory.getNumOfItems() + amt)) - return false; - } else if (!DbManager.ItemQueries.MOVE_GOLD(from, this.goldInventory, amt)) - return false; - from.setNumOfItems(from.getNumOfItems() - amt); - this.goldInventory.setNumOfItems(this.goldInventory.getNumOfItems() + amt); - return true; - } - - //This is called by the addGold devCmd. - public synchronized boolean addGoldToInventory(int amt, boolean fromDevCmd) { - - if (this.absCharacter == null || (!(this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)))) - return false; - - if (this.getGoldInventory().getNumOfItems() + amt > MBServerStatics.PLAYER_GOLD_LIMIT){ - return false; - } - - if (this.getGoldInventory().getNumOfItems() + amt < 0) - return false; - - - boolean worked = DbManager.ItemQueries.UPDATE_GOLD(this.getGoldInventory(), this.goldInventory.getNumOfItems() + amt); - if (worked) { - //log this since it's technically a dupe. Only use on test server! - if (fromDevCmd) { - String logString = this.absCharacter.getName() + " added " + amt + " gold to their inventory"; - Logger.info(logString); - } - this.goldInventory.setNumOfItems(this.goldInventory.getNumOfItems() + amt); - } - return worked; - } - - //Used to trainsfer gold from one inventory to another, for steal, etc. - public boolean transferGoldToMyInventory(AbstractCharacter tar, int amount) { - if (tar == null) - return false; - - CharacterItemManager tarCim = tar.getCharItemManager(); - if (tarCim == null) - return false; - - if (this.getGoldInventory().getNumOfItems() + amount < 0) - return false; - - if (this.getGoldInventory().getNumOfItems() + amount > MBServerStatics.PLAYER_GOLD_LIMIT) - return false; - - if (tarCim.getGoldInventory().getNumOfItems() -amount < 0) - return false; - - if (tarCim.getGoldInventory().getNumOfItems() - amount > MBServerStatics.PLAYER_GOLD_LIMIT) - return false; - - synchronized (this) { - synchronized (tarCim) { - if (!tarCim.addGoldToInventory(0 - amount, false)) //remove gold from target - return false; - if (!addGoldToInventory(amount, false)) //add to this inventory - return false; - } - } - return true; - } - - public synchronized boolean moveItemToVault(Item i) { - byte slot = i.getEquipSlot(); - - // if (this.doesCharOwnThisItem(i.getObjectUUID()) == false) - // return false; - - // Item must be in inventory to move to vault - if (!this.inventory.contains(i)) - return false; - - // check to see what type of AbstractCharacter subclass we have stored - if (this.absCharacter.getClass() == PlayerCharacter.class) { - if (!i.moveItemToVault(this.account)) - return false; - } else - return false; // NPC's dont have vaults! - - // remove it from other lists: - this.remItemFromLists(i, slot); - - // add to Vault - i.addToCache(); - - calculateWeights(); - - return true; - } - - // This removes ingame item from inventory for loot. - private synchronized boolean removeItemFromInventory(Item i) { - if (i.getItemBase().getType().equals(ItemType.GOLD)) { - if (i.getObjectUUID() != this.getGoldInventory().getObjectUUID()) - return false; - if (!DbManager.ItemQueries.UPDATE_GOLD(this.goldInventory, 0)){ - return false; - } - - } else { - if (this.doesCharOwnThisItem(i.getObjectUUID()) == false) - return false; - if (this.inventory.contains(i)) { - this.inventory.remove(i); - this.itemIDtoType.remove(i.getObjectUUID()); - return true; - } - } - // tell client we're removing item - updateInventory(i, false); - return false; - } - - // This adds item to inventory for loot. Validity checks already handled - public synchronized boolean addItemToInventory(Item i) { - if (i.getItemBase().getType().equals(ItemType.GOLD)) - if (this.absCharacter.getObjectType() == GameObjectType.Mob) { - if (this.goldInventory == null) - loadGoldItems(); - this.goldInventory.setNumOfItems(this.goldInventory.getNumOfItems() + i.getNumOfItems()); - } else { - int amt = i.getNumOfItems(); - if (DbManager.ItemQueries.UPDATE_GOLD(this.goldInventory, this.goldInventory.getNumOfItems() + amt)) { - updateInventory(); - return true; - } - - return false; - } - - this.inventory.add(i); - this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal()); - - ItemBase ib = i.getItemBase(); - if (ib != null) - this.inventoryWeight += ib.getWeight(); - return true; - } - - - - //called for adding gold of a specified amount - public synchronized boolean addItemToInventory(Item i, int amount) { - if (i.getItemBase().getType().equals(ItemType.GOLD)) - return DbManager.ItemQueries.UPDATE_GOLD(this.getGoldInventory(), this.goldInventory.getNumOfItems() + amount); - return false; - } + return true; - public boolean equipItem(Item i, byte slot) { + } - synchronized (this) { - byte curSlot = i.getEquipSlot(); // Should be 0 + public synchronized boolean closeTradeWindow(CloseTradeWindowMsg msg, boolean sourceTrade) { - if (this.doesCharOwnThisItem(i.getObjectUUID()) == false && this.absCharacter.getObjectType() != GameObjectType.Mob) { - Logger.error("Doesnt own item"); - return false; - } - // Item must be in inventory to equip - if (!this.inventory.contains(i) && this.absCharacter.getObjectType() != GameObjectType.Mob) - return false; + Dispatch dispatch; - // make sure player can equip item - if (i.getItemBase() == null) - return false; - if (!i.getItemBase().canEquip(slot, this, absCharacter, i) && this.absCharacter.getObjectType() != GameObjectType.Mob) - return false; + PlayerCharacter source = (PlayerCharacter) this.getOwner(); + if (source == null) + return false; - // check to see if item is already there. - Item old = this.equipped.get((int) slot); - if (old != null) { - Logger.error( "already equipped"); - return false; - } + CharacterItemManager sourceItemMan = source.getCharItemManager(); - // check to see what type of AbstractCharacter subclass we have stored - if (this.absCharacter.getClass() == PlayerCharacter.class) { - if (!i.equipItem((PlayerCharacter) this.absCharacter, slot)) - return false; - } else if (this.absCharacter.getObjectType() == GameObjectType.Mob) { - if (!i.equipItem((Mob) this.absCharacter, slot)) { - Logger.error("Failed to set Equip"); - return false; - } + if (sourceItemMan == null) + return false; - } else if (!i.equipItem((NPC) this.absCharacter, slot)) - return false; + int tradeID = this.tradeID; + CloseTradeWindowMsg closeMsg = new CloseTradeWindowMsg(source, tradeID); - // remove it from other lists: - this.remItemFromLists(i, slot); + dispatch = Dispatch.borrow(source, closeMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - // add to Equipped - this.equipped.put((int) slot, i); - i.addToCache(); + if (!sourceTrade) { + sourceItemMan.endTrade(); + return true; + } - addEquipOrder(i.getEquipSlot()); + ClientConnection cc2 = sourceItemMan.getTradingWith(); - //calculateWeights(); - } + if (cc2 == null || cc2.getPlayerCharacter() == null) { + sourceItemMan.endTrade(); + return true; + } - //Apply Bonuses and update player - if (this.absCharacter != null) { - this.absCharacter.applyBonuses(); - if (this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)) - this.absCharacter.incVer(); - } + sourceItemMan.endTrade(); - return true; - } - //Used for buying MobEquipment from NPC - //Handles the gold transfer aspect + cc2.getPlayerCharacter().getCharItemManager().closeTradeWindow(msg, false); - public synchronized boolean buyFromNPC(Building vendorBuilding, int cost,int buildingDeposit) { - Item gold = this.getGoldInventory(); + return true; + } - if (cost <= 0 || (gold.getNumOfItems() - cost) < 0) - return false; - - - if (this.getOwner() != null && this.getOwner().getObjectType().equals(GameObjectType.PlayerCharacter)){ - if (this.goldTradingAmount > 0){ - ErrorPopupMsg.sendErrorPopup((PlayerCharacter)this.getOwner(), 195); - return false; - } - } + public Item getGoldInventory() { + if (this.goldInventory == null) + loadGoldItems(); + return this.goldInventory; + } - // Create gold from screatch instead of building strongbox - // if the NPC is not slotted. + public Item getGoldBank() { + if (this.goldBank == null) + loadGoldItems(); + return this.goldBank; + } - if (vendorBuilding == null) { + public Item getGoldVault() { + if (this.goldVault == null) + loadGoldItems(); + return this.goldVault; + } - return this.modifyInventoryGold(-cost); + public void addEquipOrder(int slot) { + synchronized (this.equipOrder) { + Integer iSlot = slot; + if (this.equipOrder.contains(iSlot)) + this.equipOrder.remove(iSlot); + this.equipOrder.add(slot); } + } + + public synchronized boolean doesCharOwnThisItem(int itemID) { + return this.itemIDtoType.containsKey(itemID); + } + public synchronized boolean junk(Item i) { + return junk(i, true); + } - if (vendorBuilding.getStrongboxValue() + cost > vendorBuilding.getMaxGold()){ - - if (this.absCharacter.getObjectType() == GameObjectType.PlayerCharacter){ - PlayerCharacter pc = (PlayerCharacter)this.absCharacter; - if (pc.getClientConnection() != null) - ErrorPopupMsg.sendErrorPopup(pc, 206); - } - - return false; - } - - - // Update strongbox and inventory gold - if (!this.modifyInventoryGold(-cost)) - return false; - - City buildingCity = vendorBuilding.getCity(); - - if (buildingCity != null){ - buildingCity.transactionLock.writeLock().lock(); - try{ - if (!vendorBuilding.transferGold(buildingDeposit, true)) - return false; - }catch(Exception e){ - Logger.error(e); - return false; - }finally{ - buildingCity.transactionLock.writeLock().unlock(); - } - }else - if (!vendorBuilding.transferGold(buildingDeposit, true)) - return false; - - return true; + public synchronized boolean recycle(Item i) { + if (i.getObjectType() == GameObjectType.Item) + return junk(i, false); + else { + if (this.removeItemFromInventory(i) == false) + return false; + ((MobLoot) i).recycle((NPC) this.absCharacter); + calculateInventoryWeight(); + return true; + } } - //Used for selling items to NPC - public synchronized boolean sellToNPC(Building building, int cost, Item item) { + // The DeleteItemMsg takes care of updating inventory, so we don't want to do it separately + public synchronized boolean delete(Item i) { + return junk(i, false); + } + + //cleanup an item from CharacterItemManager if it doesn't belong here + public synchronized boolean cleanupDupe(Item i) { + if (i == null) + return false; - // Create gold from screatch instead of building strongbox - // if the NPC is not slotted. + if (i.getItemBase().getType().equals(ItemType.GOLD)) { + if (this.getGoldInventory() != null) { + if (i.getObjectUUID() == this.getGoldInventory().getObjectUUID()) + this.goldInventory = null; + } else if (this.getGoldBank() != null) { + if (i.getObjectUUID() == this.getGoldBank().getObjectUUID()) + this.goldBank = null; + } + return true; + } - if (this.getGoldInventory().getNumOfItems() + cost < 0) - return false; + byte slot = i.getEquipSlot(); - if (this.getGoldInventory().getNumOfItems() + cost > MBServerStatics.PLAYER_GOLD_LIMIT) - return false; - + if (this.doesCharOwnThisItem(i.getObjectUUID()) == false) + return false; - if (this.getOwner().getCharItemManager().getGoldTrading() > 0){ - if (this.getOwner().getObjectType().equals(GameObjectType.PlayerCharacter)) - ErrorPopupMsg.sendErrorPopup((PlayerCharacter)this.getOwner(), 195); - return false; - } + // remove it from other lists: + this.remItemFromLists(i, slot); + this.itemIDtoType.remove(i.getObjectUUID()); + calculateWeights(); + return true; + } - if (building == null) { - return this.modifyInventoryGold(cost); + public synchronized boolean consume(Item i) { + i.decrementChargesRemaining(); + if (i.getChargesRemaining() > 0) + return true; + return junk(i, true); + } + + private synchronized boolean junk(Item i, boolean updateInventory) { + if (i.getItemBase().getType().equals(ItemType.GOLD)) { + if (this.getGoldInventory().getObjectUUID() == i.getObjectUUID()) + if (DbManager.ItemQueries.UPDATE_GOLD(i, 0)) { + this.getGoldInventory().setNumOfItems(0); + if (updateInventory) + updateInventory(); + return true; + } else { + return false; + } + if (!(this.absCharacter.getObjectType().equals(GameObjectType.Mob))) + return false; } - //make sure strongbox can afford gold. + byte slot = i.getEquipSlot(); - if (!building.hasFunds(cost)) - return false; + if (this.doesCharOwnThisItem(i.getObjectUUID()) == false && this.absCharacter.getObjectType() != GameObjectType.Mob && (i.containerType != Enum.ItemContainerType.FORGE)) + return false; - if ((building.getStrongboxValue() - cost) < 0) - return false; + // remove it from other lists: + this.remItemFromLists(i, slot); + this.itemIDtoType.remove(i.getObjectUUID()); - // Update strongbox and inventory gold + i.junk(); - if (!building.transferGold(-cost,false)) - return false; + //Why are we adding junked items?! - return this.modifyInventoryGold(cost); + // if (i.getObjectType() != GameObjectType.MobLoot) + // CharacterItemManager.junkedItems.add(i); + + + calculateWeights(); + + if (updateInventory) + // Send the new inventory + //updateInventory(i, false); this line was causing entire inventory to disappear + updateInventory(this.getInventory(), true); + + return true; } - /** - * This sells an item to an npc - * - * @return True on success - */ - public synchronized boolean sellToNPC(Item itemToSell, NPC npc) { + public synchronized boolean moveItemToInventory(Item i) { - CharacterItemManager itemMan; + boolean fromEquip = false; + synchronized (this) { + byte slot = i.getEquipSlot(); - if (itemToSell == null || npc == null) - return false; + //Skip if NOT in vault. + if (i.containerType != Enum.ItemContainerType.VAULT) + if (this.doesCharOwnThisItem(i.getObjectUUID()) == false) + return false; - itemMan = npc.getCharItemManager(); + // Only valid from bank, equip and vault + if (!bankContains(i) && !equippedContains(i) && !vaultContains(i)) + return false; - if (itemMan == null) - return false; + if (equippedContains(i)) { + fromEquip = true; + ItemBase ib = i.getItemBase(); + if (ib != null && ib.getType().equals(ItemType.GOLD)) + this.absCharacter.cancelOnUnEquip(); + } - //test npc inventory is not full + // check to see what type of AbstractCharacter subclass we have stored + if (this.absCharacter.getClass() == PlayerCharacter.class) { + if (!i.moveItemToInventory((PlayerCharacter) this.absCharacter)) + return false; + } else if (!i.moveItemToInventory((NPC) this.absCharacter)) + return false; - synchronized (this) { - synchronized (itemMan) { - if (!this.doesCharOwnThisItem(itemToSell.getObjectUUID())) - return false; - // attempt to transfer item in db + // remove it from other lists: + this.remItemFromLists(i, slot); - boolean sdrMerchant = false; + // add to Inventory + this.inventory.add(i); + i.addToCache(); + this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal()); - if (npc.getContractID() >= 1900 && npc.getContractID() <= 1906) - sdrMerchant = true; + calculateWeights(); + } + + //Apply bonuses if from equip + if (fromEquip && this.absCharacter != null) { + this.absCharacter.applyBonuses(); + if (this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)) + this.absCharacter.incVer(); + } + + return true; + } + + public synchronized boolean moveItemToBank(Item i) { + byte slot = i.getEquipSlot(); + + if (this.doesCharOwnThisItem(i.getObjectUUID()) == false) + return false; - if (sdrMerchant){ - this.delete(itemToSell); - this.updateInventory(); + // Item must be in inventory to move to bank + if (!this.inventory.contains(i)) + return false; + + // check to see what type of AbstractCharacter subclass we have stored + if (this.absCharacter.getClass() == PlayerCharacter.class) { + if (!i.moveItemToBank((PlayerCharacter) this.absCharacter)) + return false; + } else if (!i.moveItemToBank((NPC) this.absCharacter)) + return false; + + // remove it from other lists: + this.remItemFromLists(i, slot); + + // add to Bank + this.bank.add(i); + i.addToCache(); + + calculateWeights(); + + return true; + } - }else - if (!itemToSell.moveItemToInventory(npc)) - return false; + public synchronized boolean moveGoldToBank(Item from, int amt) { + if (from == null) + return false; + if (from.getNumOfItems() - amt < 0) + return false; + if (this.goldBank.getNumOfItems() + amt > MBServerStatics.BANK_GOLD_LIMIT) { + if (this.absCharacter.getObjectType() == GameObjectType.PlayerCharacter) { + PlayerCharacter pc = (PlayerCharacter) this.absCharacter; + if (pc.getClientConnection() != null) + ErrorPopupMsg.sendErrorPopup(pc, 202); + return false; + } + } - // db transfer successfull, remove from this character - // skip this check if this is a mobLoot item (which is not in any inventory) - if (!sdrMerchant) - if (!removeItemFromInventory(itemToSell)) - return false; + if (!DbManager.ItemQueries.MOVE_GOLD(from, this.getGoldBank(), amt)) + return false; + from.setNumOfItems(from.getNumOfItems() - amt); + this.goldBank.setNumOfItems(this.goldBank.getNumOfItems() + amt); + return true; + } - // add item to looter. - if(!sdrMerchant) - if (!itemMan.addItemToInventory(itemToSell)) - return false; - } - } + public synchronized boolean moveGoldToVault(Item from, int amt) { + if (from == null) + return false; + if (from.getNumOfItems() - amt < 0) + return false; + if (!DbManager.ItemQueries.MOVE_GOLD(from, this.account.vaultGold, amt)) + return false; + from.setNumOfItems(from.getNumOfItems() - amt); + this.account.vaultGold.setNumOfItems(this.goldVault.getNumOfItems() + amt); + return true; + } - // calculate new weights - calculateInventoryWeight(); - itemMan.calculateInventoryWeight(); - return true; - } + public synchronized boolean moveGoldToInventory(Item from, int amt) { + if (from == null) + return false; + if (from.getNumOfItems() - amt < 0 || amt < 1) + return false; - /** - * This buys an item from an npc - * Handles transfer of item. - * - * @return True on success - */ - public synchronized boolean buyFromNPC(Item purchasedItem, NPC npc) { + if (this.goldInventory.getNumOfItems() + amt > MBServerStatics.PLAYER_GOLD_LIMIT) { + if (this.absCharacter.getObjectType() == GameObjectType.PlayerCharacter) { + PlayerCharacter pc = (PlayerCharacter) this.absCharacter; + if (pc.getClientConnection() != null) + ErrorPopupMsg.sendErrorPopup(pc, 202); + return false; + } + } - CharacterItemManager itemMan; - ItemBase itemBase; + if (from instanceof MobLoot) { + if (!DbManager.ItemQueries.UPDATE_GOLD(this.getGoldInventory(), + this.goldInventory.getNumOfItems() + amt)) + return false; + } else if (!DbManager.ItemQueries.MOVE_GOLD(from, this.goldInventory, amt)) + return false; + from.setNumOfItems(from.getNumOfItems() - amt); + this.goldInventory.setNumOfItems(this.goldInventory.getNumOfItems() + amt); + return true; + } - if (purchasedItem == null || npc == null) - return false; + //This is called by the addGold devCmd. + public synchronized boolean addGoldToInventory(int amt, boolean fromDevCmd) { - itemMan = npc.getCharItemManager(); + if (this.absCharacter == null || (!(this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)))) + return false; - if (itemMan == null) - return false; + if (this.getGoldInventory().getNumOfItems() + amt > MBServerStatics.PLAYER_GOLD_LIMIT) { + return false; + } + if (this.getGoldInventory().getNumOfItems() + amt < 0) + return false; - synchronized (this) { - synchronized (itemMan) { - itemBase = purchasedItem.getItemBase(); + boolean worked = DbManager.ItemQueries.UPDATE_GOLD(this.getGoldInventory(), this.goldInventory.getNumOfItems() + amt); + if (worked) { + //log this since it's technically a dupe. Only use on test server! + if (fromDevCmd) { + String logString = this.absCharacter.getName() + " added " + amt + " gold to their inventory"; + Logger.info(logString); + } + this.goldInventory.setNumOfItems(this.goldInventory.getNumOfItems() + amt); + } + return worked; + } - if (itemBase == null) - return false; + //Used to trainsfer gold from one inventory to another, for steal, etc. + public boolean transferGoldToMyInventory(AbstractCharacter tar, int amount) { + if (tar == null) + return false; - //test inventory is not full + CharacterItemManager tarCim = tar.getCharItemManager(); + if (tarCim == null) + return false; - if (!hasRoomInventory(itemBase.getWeight())) - return false; + if (this.getGoldInventory().getNumOfItems() + amount < 0) + return false; - if (!itemMan.inventory.contains(purchasedItem)) - return false; - // attempt to transfer item in db + if (this.getGoldInventory().getNumOfItems() + amount > MBServerStatics.PLAYER_GOLD_LIMIT) + return false; - if (purchasedItem.getObjectType() == GameObjectType.MobLoot){ + if (tarCim.getGoldInventory().getNumOfItems() - amount < 0) + return false; - Item newItem = ((MobLoot) purchasedItem).promoteToItem((PlayerCharacter)this.absCharacter); - if (newItem == null) - return false; - - if (!itemMan.removeItemFromInventory(purchasedItem)) - return false; - - if (!addItemToInventory(newItem)) - return false; - //Item was created and still a mobloot item, remove from npc production list in db. - - DbManager.NPCQueries.REMOVE_FROM_PRODUCTION_LIST(purchasedItem.getObjectUUID(),npc.getObjectUUID()); - - - }else{ - if (!purchasedItem.moveItemToInventory((PlayerCharacter) this.absCharacter)) - return false; - - if (purchasedItem.getValue() != purchasedItem.getMagicValue()){ - DbManager.ItemQueries.UPDATE_VALUE(purchasedItem,0); - purchasedItem.setValue(0); - } - - // db transfer successfull, remove from this character - // skip this check if this is a mobLoot item (which is not in any inventory) - if (!itemMan.removeItemFromInventory(purchasedItem)) - return false; - - // add item to looter. - - if (!addItemToInventory(purchasedItem)) - return false; - } - - } - } - - // calculate new weights - calculateInventoryWeight(); - itemMan.calculateInventoryWeight(); - return true; - } - - /** - * Loot an item from an AbstractCharacter. Call this function on - * the CharacterItemManager of the current item owner, not the looter. - * This method will verify that the looter can receive the item - * (e.g. inventory isn't full). - * - * @param i Item being looted - * @param looter Player looting the item - * @param origin ClientConnection - * @return True on success - */ - public synchronized Item lootItemFromMe(Item i, PlayerCharacter looter, ClientConnection origin) { - return lootItemFromMe(i, looter, origin, false, -1); - } - - //This function is used for both looting and stealing - public synchronized Item lootItemFromMe(Item lootItem, PlayerCharacter lootingPlayer, ClientConnection origin, boolean fromSteal, int amount) { - - //TODO this function should have more logging - // make sure lootingPlayer exists - if (lootingPlayer == null) - return null; - - // get looters item manager - CharacterItemManager looterItems = lootingPlayer.getCharItemManager(); - - if (looterItems == null) - return null; - - if (fromSteal) { - if (!this.absCharacter.isAlive()) - return null; - } else if (!this.absCharacter.canBeLooted()) - return null; - - MobLoot mobLoot = null; - if (lootItem instanceof MobLoot) { - mobLoot = (MobLoot) lootItem; - if (mobLoot.isDeleted()) - return null; - } - - //Lock both ItemManagers; lower ID first - CharacterItemManager lockFirst; - CharacterItemManager lockSecond; - if (this.absCharacter.getObjectUUID() - < looterItems.absCharacter.getObjectUUID()) { - lockFirst = this; - lockSecond = looterItems; - } else { - lockFirst = looterItems; - lockSecond = this; - } - - synchronized (lockFirst) { - synchronized (lockSecond) { - // make sure current player has item in inventory - if (lootItem.getItemBase().getType().equals(ItemType.GOLD) && lootItem.getObjectUUID() != this.getGoldInventory().getObjectUUID() && !(this.absCharacter.getObjectType().equals(GameObjectType.Mob))) - return null; - else if (!this.inventory.contains(lootItem) && !this.getEquippedList().contains(lootItem) && !lootItem.getItemBase().getType().equals(ItemType.GOLD)) - return null; - - // get weight of item - ItemBase ib = lootItem.getItemBase(); - if (ib == null) - return null; - short weight = ib.getWeight(); - - // make sure lootingPlayer has room for item - if (!lootItem.getItemBase().getType().equals(ItemType.GOLD) && !looterItems.hasRoomInventory(weight)) - return null; - - if (lootItem.getItemBase().getType().equals(ItemType.GOLD)) - if (amount != -1) { //from steal - int total = lootItem.getNumOfItems(); - amount = (amount > total) ? total : amount; - if (!looterItems.moveGoldToInventory(lootItem, amount)) - return null; - if (mobLoot != null && amount == total) - this.delete(mobLoot); - } else { //from loot - if (!looterItems.moveGoldToInventory(lootItem, lootItem.getNumOfItems())) - return null; - if (mobLoot != null) // delete mobloot after it has been looted - this.delete(mobLoot); - } - else { //not Gold item - boolean created = false; - if (mobLoot != null) { - lootItem = mobLoot.promoteToItem(lootingPlayer); + if (tarCim.getGoldInventory().getNumOfItems() - amount > MBServerStatics.PLAYER_GOLD_LIMIT) + return false; - // delete mobloot after it has been looted - this.delete(mobLoot); - if (lootItem == null) - return null; - - created = true; - } - - // attempt to transfer item in db - - if (!lootItem.moveItemToInventory(lootingPlayer)) - return null; - - // db transfer successfull, remove from this character - // skip this check if this is a mobLoot item (which is not in any inventory) - if (mobLoot == null) - if (!removeItemFromInventory(lootItem)) - return null; - - // add item to lootingPlayer. - if (!looterItems.addItemToInventory(lootItem)) - return null; - } - } - } - - // calculate new weights - calculateInventoryWeight(); - looterItems.calculateInventoryWeight(); - - return lootItem; - } - - private synchronized void remItemFromLists(Item i, byte slot) { - - this.equipped.remove((int) slot); - this.vault.remove(i); - this.bank.remove(i); - this.inventory.remove(i); - } - - /* - * Delegates - */ - public synchronized boolean bankContains(Item i) { - if (i.getItemBase().getType().equals(ItemType.GOLD)) - return (this.getGoldBank() != null && this.goldBank.getObjectUUID() == i.getObjectUUID()); - return bank.contains(i); - } - - - public synchronized boolean inventoryContains(Item i) { - if (i.getItemBase().getType().equals(ItemType.GOLD)) - return (this.getGoldInventory() != null && this.goldInventory.getObjectUUID() == i.getObjectUUID()); - return inventory.contains(i); - } - - public synchronized boolean forgeContains(Item i,NPC vendor) { - if (i.getItemBase().getType().equals(ItemType.GOLD)) - return (this.getGoldInventory() != null && this.goldInventory.getObjectUUID() == i.getObjectUUID()); - return vendor.getRolling().contains(i); - } - - - - public synchronized boolean vaultContains(Item i) { - if (i.getItemBase().getType().equals(ItemType.GOLD)) - return (this.getGoldVault() != null && this.goldVault.getObjectUUID() == i.getObjectUUID()); - return this.account.getVault().contains(i); - } - - public synchronized boolean vaultContainsType(ItemBase ib) { - if (ib.getUUID() == 7) - return (this.getGoldVault() != null); - for (Item i : vault) { - if (i.getItemBase().getUUID() == ib.getUUID()) - return true; - } - return false; - } - - //for calling from devCmd fill vault. Already synchronized - public boolean vaultContainsTypeA(ItemBase ib) { - if (ib.getUUID() == 7) - return (this.getGoldVault() != null); - for (Item i : vault) { - if (i.getItemBase().getUUID() == ib.getUUID()) - return true; - } - return false; - } - - - public synchronized boolean equippedContains(Item i) { - return equipped.containsValue(i); - } - - public synchronized Item getItemFromEquipped(int slot) { - return equipped.get(slot); - } - - public synchronized Item getItemByUUID(int objectUUID) { - if (this.itemIDtoType.containsKey(objectUUID)){ - - Integer integer = this.itemIDtoType.get(objectUUID); - if (integer == GameObjectType.Item.ordinal()) { - return Item.getFromCache(objectUUID); - } else if (integer == GameObjectType.MobLoot.ordinal()) { - return MobLoot.getFromCache(objectUUID); - } - - } - - if (this.getGoldInventory() != null && this.goldInventory.getObjectUUID() == objectUUID) - return this.goldInventory; - if (this.getGoldBank() != null && this.goldBank.getObjectUUID() == objectUUID) - return this.goldBank; - if (this.getGoldVault() != null && this.goldVault.getObjectUUID() == objectUUID) - return this.goldVault; - return null; - } - - public boolean tradingContains(Item i) { - if (this.trading == null || i == null) - return false; - return this.trading.contains(i.getObjectUUID()); - } - - public boolean isBankOpen() { - return this.bankOpened; - } - - public synchronized void setBankOpen(boolean bankOpened) { - this.bankOpened = bankOpened; - } - - public boolean isVaultOpen() { - return this.vaultOpened; - } - - public synchronized void setVaultOpen(boolean vaultOpened) { - this.vaultOpened = vaultOpened; - } - - public ClientConnection getTradingWith() { - return tradingWith; - } - - public synchronized void setTradingWith(ClientConnection tradingWith) { - this.tradingWith = tradingWith; - } - - public synchronized void clearTradingWith() { - this.tradingWith = null; - } - - public int getGoldTrading() { - return goldTradingAmount; - } - - public synchronized void setTradeCommitted(byte tradeCommitted) { - this.tradeCommitted = tradeCommitted; - } - - public byte getTradeCommitted() { - return tradeCommitted; - } - - public HashSet getTrading() { - return trading; - } - - - public synchronized void addItemToTrade(Item i) { - this.trading.add(i.getObjectUUID()); - } - - - public synchronized void setTradeSuccess(boolean tradeSuccess) { - this.tradeSuccess = tradeSuccess; - } - - public boolean getTradeSuccess() { - return tradeSuccess; - } - - - public synchronized boolean RemoveEquipmentFromLackOfSkill(PlayerCharacter pc, boolean initialized) { - - - if (pc == null) - return false; - - if (this.equipped == null) - return false; - - - for (int slot : this.equipped.keySet()) { - - if (slot == MBServerStatics.SLOT_HAIRSTYLE || slot == MBServerStatics.SLOT_BEARDSTYLE) - continue; - - Item item = this.equipped.get(slot); - - if (item == null){ - this.equipped.remove(slot); - pc.applyBonuses(); - continue; - } - - if (!item.getItemBase().validForSkills(pc.getSkills())){ - this.forceToInventory(slot, item, pc, initialized); - pc.applyBonuses(); - } - } - - return true; - } - - /* - * List Copiers - */ - /** - * Note that this method returns a copy of the internally stored - * list. - * - * @return the equipped - */ - public ConcurrentHashMap getEquipped() { - synchronized (this.equipped) { - return new ConcurrentHashMap<>(this.equipped); - } - } - - public ArrayList getEquippedList() { - ArrayList ret = new ArrayList<>(); - synchronized (this.equipOrder) { - synchronized (this.equipped) { - for (int slot : this.equipOrder) { - if (this.equipped.containsKey(slot)) - ret.add(this.equipped.get(slot)); - } - if (ret.size() != this.equipped.size()) - //missed adding some items, figure out what. - for (int slot : this.equipped.keySet()) { - if (!(this.equipOrder.contains(slot))) { - this.equipOrder.add(slot); - ret.add(this.equipped.get(slot)); - } - } - } - } - return ret; - } - - public Item getEquipped(int slot) { - synchronized (this.equipped) { - return this.equipped.get(slot); - } - } - - /** - * Note that this method returns a copy of the internally stored - * list. - * - * @return the inventory - */ - public ArrayList getInventory() { - return getInventory(false); - } - - public ArrayList getInventory(boolean sendGold) { - synchronized (this.inventory) { - ArrayList ret = new ArrayList<>(this.inventory); - if (sendGold && this.getGoldInventory() != null && this.goldInventory.getNumOfItems() > 0) - ret.add(this.goldInventory); - return ret; - } - } - - public int getInventoryCount() { - synchronized (this.inventory) { - return this.inventory.size(); - } - } - - /** - * Clears ownership of items. Called when player dies, but before - * respawning. - * - * @return the inventory - */ - public synchronized void orphanInventory() { - PlayerCharacter pc = null; - if (this.absCharacter != null && this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)) - pc = (PlayerCharacter) this.absCharacter; - synchronized (this.inventory) { - //dupe check, validate player properly owns all items - if (pc != null) { - Iterator iter = this.inventory.iterator(); - while (iter.hasNext()) { - Item item = iter.next(); - //this call may remove the item from this.inventory - if (!item.validForInventory(pc.getClientConnection(), pc, this)) { - } - } - } - - if (this.inventory.size() > 0) - DbManager.ItemQueries.ORPHAN_INVENTORY(this.inventory); - //make a copy of gold inventory for looting - //so we don't remove the goldInventory - if (this.getGoldInventory().getNumOfItems() > 0) { - int amt = this.goldInventory.getNumOfItems(); - if (DbManager.ItemQueries.UPDATE_GOLD(this.goldInventory, 0)) { - this.goldInventory.setNumOfItems(0); - MobLoot gold = new MobLoot(this.absCharacter, amt); - this.inventory.add(gold); - } - } - } - } - - /** - * This transfers the entire inventory to another list For populating - * corpse' inventory when player dies - * - * @return the inventory - */ - public synchronized void transferEntireInventory( - ArrayList newInventory, Corpse corpse, boolean enterWorld) { - - PlayerCharacter pc = null; - if (this.absCharacter != null && this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)) - pc = (PlayerCharacter) this.absCharacter; - - if (this.getGoldInventory().getNumOfItems() > 0) { - int amt = this.goldInventory.getNumOfItems(); - if (DbManager.ItemQueries.UPDATE_GOLD(this.goldInventory, 0)) { - this.goldInventory.setNumOfItems(0); - MobLoot gold = new MobLoot(this.absCharacter, amt); - newInventory.add(gold); - } - } - - for (Item item : this.inventory) { - if (item != null) - if (item instanceof MobLoot) { - - //MobLoot - item.zeroItem(); - item.containerType = Enum.ItemContainerType.INVENTORY; - - if (item.getItemBase().getType().equals(ItemType.GOLD)) - //only add gold item once - if (!corpse.hasGold()) - corpse.setHasGold(true); - newInventory.add(item); - } else //item - if (item.getItemBase().getType().equals(ItemType.GOLD)) { - int amt = item.getNumOfItems(); - item.setNumOfItems(0); - MobLoot ml = new MobLoot(this.absCharacter, amt); - ml.zeroItem(); - ml.containerType = Enum.ItemContainerType.INVENTORY; - if (!corpse.hasGold()) { - corpse.setHasGold(true); - newInventory.add(ml); - } - } else { - boolean transferred = item.moveItemToInventory(corpse); - if (!transferred) - Logger.error( - "CharItemManager.transferEntireInvetory", - "DB Error, Failed to transfer item " - + item.getObjectUUID() + " to new owner " - + corpse.getObjectUUID()); - newInventory.add(item); - - } - } - - // tell client we're clearing inventory - - - // clear the inventory. - this.inventory.clear(); - - //re-calculate inventory weight - calculateInventoryWeight(); - if (!enterWorld) - updateInventory(this.getInventory(), false); - } - - public synchronized void purgeInventory() { - - if (!this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)) - return; - - if (this.goldInventory != null) - if (this.getGoldInventory().getNumOfItems() > 0) { - if (DbManager.ItemQueries.UPDATE_GOLD(this.goldInventory, 0)) { - this.goldInventory.setNumOfItems(0); - } - } - - if (this.inventory.size() > 0) - DbManager.ItemQueries.ORPHAN_INVENTORY(this.inventory); - - // clear the inventory. - this.inventory.clear(); - //re-calculate inventory weight - calculateInventoryWeight(); - } - - /** - * Note that this method returns a copy of the internally stored - * list. - * - * @return the bank - */ - public ArrayList getBank() { - synchronized (this.bank) { - ArrayList ret = new ArrayList<>(this.bank); - if (this.getGoldBank() != null && this.goldBank.getNumOfItems() > 0) - ret.add(this.goldBank); - return ret; - } - } - - /** - * Note that this method returns a copy of the internally stored - * list. - * - * @return the vault - */ - public ArrayList getVault() { - synchronized (this.vault) { - ArrayList ret = new ArrayList<>(this.vault); - if (this.getGoldVault() != null && this.goldVault.getNumOfItems() > 0) - ret.add(this.goldVault); - return ret; - } - } - - public boolean hasRoomInventory(short weight) { - if (this.absCharacter == null) - return false; - if (this.absCharacter.getObjectType() == GameObjectType.PlayerCharacter) { - PlayerCharacter pc = (PlayerCharacter) this.absCharacter; - int newWeight = this.getCarriedWeight() + weight; - return newWeight <= (int) pc.statStrBase * 3; - } else if (this.absCharacter.getObjectType() == GameObjectType.NPC){ - int newWeight = this.getCarriedWeight() + weight; - return newWeight <= 1900 + (this.absCharacter.getLevel() * 3); - }else - return true; // npc's need checked - } + synchronized (this) { + synchronized (tarCim) { + if (!tarCim.addGoldToInventory(0 - amount, false)) //remove gold from target + return false; + if (!addGoldToInventory(amount, false)) //add to this inventory + return false; + } + } + return true; + } - public boolean hasRoomTrade(short itemWeight) { + public synchronized boolean moveItemToVault(Item i) { + byte slot = i.getEquipSlot(); - PlayerCharacter playerCharacter; - PlayerCharacter tradeCharacter; + // if (this.doesCharOwnThisItem(i.getObjectUUID()) == false) + // return false; - int tradeWeight; + // Item must be in inventory to move to vault + if (!this.inventory.contains(i)) + return false; - if (this.absCharacter == null) - return false; + // check to see what type of AbstractCharacter subclass we have stored + if (this.absCharacter.getClass() == PlayerCharacter.class) { + if (!i.moveItemToVault(this.account)) + return false; + } else + return false; // NPC's dont have vaults! - if (this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter) == false) - return false; + // remove it from other lists: + this.remItemFromLists(i, slot); - playerCharacter = (PlayerCharacter) this.absCharacter; + // add to Vault + i.addToCache(); - if ((this.tradingWith == null) || - (this.tradingWith.isConnected() == false)) - return false; + calculateWeights(); - tradeCharacter = this.tradingWith.getPlayerCharacter(); + return true; + } - tradeWeight = this.getCarriedWeight() + itemWeight; - tradeWeight = tradeWeight + tradeCharacter.getCharItemManager().getTradingWeight(); - tradeWeight = tradeWeight - this.getTradingWeight(); + //Used for buying MobEquipment from NPC + //Handles the gold transfer aspect + + // This removes ingame item from inventory for loot. + private synchronized boolean removeItemFromInventory(Item i) { + if (i.getItemBase().getType().equals(ItemType.GOLD)) { + if (i.getObjectUUID() != this.getGoldInventory().getObjectUUID()) + return false; + if (!DbManager.ItemQueries.UPDATE_GOLD(this.goldInventory, 0)) { + return false; + } + + } else { + if (this.doesCharOwnThisItem(i.getObjectUUID()) == false) + return false; + if (this.inventory.contains(i)) { + this.inventory.remove(i); + this.itemIDtoType.remove(i.getObjectUUID()); + return true; + } + } + // tell client we're removing item + updateInventory(i, false); + return false; + } - return tradeWeight <= (int) playerCharacter.statStrBase * 3; - } + // This adds item to inventory for loot. Validity checks already handled + public synchronized boolean addItemToInventory(Item i) { + if (i.getItemBase().getType().equals(ItemType.GOLD)) + if (this.absCharacter.getObjectType() == GameObjectType.Mob) { + if (this.goldInventory == null) + loadGoldItems(); + this.goldInventory.setNumOfItems(this.goldInventory.getNumOfItems() + i.getNumOfItems()); + } else { + int amt = i.getNumOfItems(); + if (DbManager.ItemQueries.UPDATE_GOLD(this.goldInventory, this.goldInventory.getNumOfItems() + amt)) { + updateInventory(); + return true; + } + + return false; + } + + this.inventory.add(i); + this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal()); + + ItemBase ib = i.getItemBase(); + if (ib != null) + this.inventoryWeight += ib.getWeight(); + return true; + } - public boolean hasRoomBank(short weight) { - if (this.absCharacter == null) - return false; - return weight <= this.absCharacter.getBankCapacityRemaining(); + //called for adding gold of a specified amount + public synchronized boolean addItemToInventory(Item i, int amount) { + if (i.getItemBase().getType().equals(ItemType.GOLD)) + return DbManager.ItemQueries.UPDATE_GOLD(this.getGoldInventory(), this.goldInventory.getNumOfItems() + amount); + return false; } - public boolean hasRoomVault(short weight) { - if (this.absCharacter == null) - return false; - return weight <= this.absCharacter.getVaultCapacityRemaining(); + public boolean equipItem(Item i, byte slot) { + + synchronized (this) { + byte curSlot = i.getEquipSlot(); // Should be 0 + + if (this.doesCharOwnThisItem(i.getObjectUUID()) == false && this.absCharacter.getObjectType() != GameObjectType.Mob) { + Logger.error("Doesnt own item"); + return false; + } + + // Item must be in inventory to equip + if (!this.inventory.contains(i) && this.absCharacter.getObjectType() != GameObjectType.Mob) + return false; + + // make sure player can equip item + if (i.getItemBase() == null) + return false; + if (!i.getItemBase().canEquip(slot, this, absCharacter, i) && this.absCharacter.getObjectType() != GameObjectType.Mob) + return false; + + // check to see if item is already there. + Item old = this.equipped.get((int) slot); + if (old != null) { + Logger.error("already equipped"); + return false; + } + + // check to see what type of AbstractCharacter subclass we have stored + if (this.absCharacter.getClass() == PlayerCharacter.class) { + if (!i.equipItem((PlayerCharacter) this.absCharacter, slot)) + return false; + } else if (this.absCharacter.getObjectType() == GameObjectType.Mob) { + if (!i.equipItem((Mob) this.absCharacter, slot)) { + Logger.error("Failed to set Equip"); + return false; + } + + } else if (!i.equipItem((NPC) this.absCharacter, slot)) + return false; + + // remove it from other lists: + this.remItemFromLists(i, slot); + + // add to Equipped + this.equipped.put((int) slot, i); + i.addToCache(); + + addEquipOrder(i.getEquipSlot()); + + //calculateWeights(); + } + + //Apply Bonuses and update player + if (this.absCharacter != null) { + this.absCharacter.applyBonuses(); + if (this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)) + this.absCharacter.incVer(); + } + + return true; } - public int getCarriedWeight() { - return getInventoryWeight() + getEquipWeight(); - } - - public int getInventoryWeight() { - return this.inventoryWeight; - } - - public int getBankWeight() { - return this.bankWeight; - } - - public int getEquipWeight() { - return this.equipWeight; - } - - public int getVaultWeight() { - return this.vaultWeight; - } - - public int getTradingForWeight() { - return calculateTradingForWeight(); - } - - public int getTradingWeight() { - - int weight = 0; - Item item; - - for (int i : this.trading) { - item = Item.getFromCache(i); - - if (item == null) - continue; - - ItemBase ib = item.getItemBase(); - weight += ib.getWeight(); - } - return weight; - } - - public AbstractCharacter getOwner() { - return this.absCharacter; - } - - public void calculateWeights() { - calculateBankWeight(); - calculateInventoryWeight(); - calculateEquipWeight(); - calculateVaultWeight(); - } - - public void calculateBankWeight() { - this.bankWeight = 0; - for (Item i : this.bank) { - ItemBase ib = i.getItemBase(); - if (ib != null) - this.bankWeight += ib.getWeight(); - } - } - - public void calculateEquipWeight() { - this.equipWeight = 0; - Collection c = this.equipped.values(); - Iterator it = c.iterator(); - while (it.hasNext()) { - Item i = it.next(); - ItemBase ib = i.getItemBase(); - if (ib != null) - this.equipWeight += ib.getWeight(); - } - } - - public void calculateInventoryWeight() { - this.inventoryWeight = 0; - for (Item i : this.inventory) { - ItemBase ib = i.getItemBase(); - if (ib != null) - this.inventoryWeight += ib.getWeight(); - } - } - - public void calculateVaultWeight() { - this.vaultWeight = 0; - for (Item i : this.vault) { - ItemBase ib = i.getItemBase(); - if (ib != null) - this.vaultWeight += ib.getWeight(); - } - } - - private int calculateTradingForWeight() { - int tradingForWeight = 0; - - return tradingForWeight; - } - - - public void updateInventory(Item item, boolean add) { - ArrayList list = new ArrayList<>(); - list.add(item); - updateInventory(list, add); - } - - private void updateInventory(ArrayList inventory, boolean add) { - - if (this.absCharacter == null) - return; - - if (this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter) == false) - return; - - PlayerCharacter pc = (PlayerCharacter) this.absCharacter; - - UpdateInventoryMsg updateInventoryMsg = new UpdateInventoryMsg(inventory, this.getBank(), this.getGoldInventory(), add); - Dispatch dispatch = Dispatch.borrow(pc, updateInventoryMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - } - - public void forceToInventory(int slot, Item item, PlayerCharacter pc, boolean initialized) { - if (item == null || pc == null) - return; - - if (!item.moveItemToInventory(pc)) { - //TODO well why did this fail? clean it up - } - - // remove it from other lists: - this.remItemFromLists(item, (byte) slot); - - // add to Inventory - this.inventory.add(item); - item.addToCache(); - - calculateWeights(); - - //Update players with unequipped item - if (initialized) { - TransferItemFromEquipToInventoryMsg back = new TransferItemFromEquipToInventoryMsg(pc, slot); - DispatchMessage.dispatchMsgToInterestArea(pc, back, engine.Enum.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - } - - } - - /** - * Update the player's inventory window by resending the entire contents. - */ - public void updateInventory() { - this.updateInventory(this.getInventory(), true); - } - - public synchronized void initializeTrade() { - this.trading = new HashSet<>(); - } - - public synchronized boolean commitTrade() { - int goldFrom1 = 0; - int goldFrom2 = 0; - - if (this.getTradingWith() == null || this.getTradingWith().isConnected() == false - || this.getTradingWith().getPlayerCharacter() == null){ - this.endTrade(); - return false; - } - - - CharacterItemManager tradingWith = this.getTradingWith().getPlayerCharacter().getCharItemManager(); - - if (tradingWith == null) - return false; - - if (this.goldTradingAmount != 0) { - - if (tradingWith.goldInventory == null){ - Logger.error("Null Gold for player " + this.getOwner().getObjectUUID()); - return false; - } - goldFrom1 = this.goldTradingAmount; - } - if (tradingWith.goldTradingAmount != 0) { - - if (this.getGoldInventory() == null){ - Logger.error("Null Gold for player " + this.getOwner().getObjectUUID()); - return false; - } - goldFrom2 = tradingWith.goldTradingAmount; - } - - - if (this.getGoldInventory().getNumOfItems() + goldFrom2 > 10000000){ - PlayerCharacter pc = (PlayerCharacter)this.absCharacter; - if (pc.getClientConnection() != null) - ErrorPopupMsg.sendErrorPopup(pc, 202); - return false; - } - - - if (tradingWith.getGoldInventory().getNumOfItems() + goldFrom1 > 10000000){ - PlayerCharacter pc = (PlayerCharacter)tradingWith.absCharacter; - if (pc.getClientConnection() != null) - ErrorPopupMsg.sendErrorPopup(pc, 202); - return false; - } - - if (this.trading.size() > 0 || tradingWith.trading.size() > 0 || goldFrom1 > 0 || goldFrom2 > 0) { - if (!DbManager.ItemQueries.DO_TRADE(this.trading, tradingWith.trading, this, tradingWith, - this.goldInventory, tradingWith.goldInventory, goldFrom1, goldFrom2)) - return false; - } else - return true; - - for (int i : this.trading) { - Item item = Item.getFromCache(i); - if (item == null) - continue; - this.trade(item); - tradingWith.tradeForItem(item); - } - for (int i : tradingWith.trading) { - Item item = Item.getFromCache(i); - if (item == null) - continue; - tradingWith.trade(item); - this.tradeForItem(item); - } - - //subtract gold your trading from your inventory. - if (this.goldTradingAmount > 0) - this.getGoldInventory().setNumOfItems(this.getGoldInventory().getNumOfItems() - this.goldTradingAmount); - //subtract gold your trading from your inventory. - if (tradingWith.goldTradingAmount > 0) - tradingWith.getGoldInventory().setNumOfItems(tradingWith.getGoldInventory().getNumOfItems() - tradingWith.goldTradingAmount); - - if (tradingWith.goldTradingAmount > 0) - this.getGoldInventory().setNumOfItems(this.goldInventory.getNumOfItems() - + tradingWith.goldTradingAmount); - if (this.goldTradingAmount > 0) - tradingWith.getGoldInventory().setNumOfItems(tradingWith.goldInventory.getNumOfItems() - + this.goldTradingAmount); - - this.tradeSuccess = true; - tradingWith.tradeSuccess = true; - - return true; - - } - - public synchronized void endTrade() { - updateInventory(this.getInventory(), true); - this.tradeCommitted = (byte) 0; - this.tradeSuccess = false; - this.tradingWith = null; - this.trading = null; - this.goldTradingAmount = 0; - this.tradeID = 0; - } - - public synchronized void endTrade(boolean fromDeath) { - this.tradeCommitted = (byte) 0; - this.tradeSuccess = false; - this.tradingWith = null; - this.trading = null; - this.goldTradingAmount = 0; - } - - // Remove item from your possession - private synchronized boolean trade(Item i) { - if (this.doesCharOwnThisItem(i.getObjectUUID()) == false) - return false; - - // Only valid from inventory - if (!inventoryContains(i)) - return false; - - // remove from Inventory - this.inventory.remove(i); - this.itemIDtoType.remove(i.getObjectUUID()); - i.setOwnerID(0); - - calculateWeights(); - - return true; - } - - //Damage an equipped item a specified amount - public void damageItem(Item item, int amount) { - if (item == null || amount < 1 || amount > 5) - return; - - //verify the item is equipped by this player - int slot = item.getEquipSlot(); - if (!this.equipped.containsKey(slot)) - return; - Item verify = this.equipped.get(slot); - if (verify == null || item.getObjectUUID() != verify.getObjectUUID()) - return; - - //don't damage noob gear, hair or beards. - if (item.getDurabilityMax() == 0) - return; - - if (!item.isCanDestroy()) - return; - - int dur = (int) item.getDurabilityCurrent(); - if (dur - amount <= 0) { - //destroy the item - junk(item); - - //TODO remove item from the client - //This may not be correct - dur = 0; - } else { - dur -= amount; - if (!DbManager.ItemQueries.SET_DURABILITY(item, dur)) - return; - item.setDurabilityCurrent((short) dur); - - } - - if (this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter) == false) - return; - - //send damage item msg to client - PlayerCharacter pc = (PlayerCharacter) this.absCharacter; - - ItemHealthUpdateMsg itemHealthUpdateMsg = new ItemHealthUpdateMsg(slot, (float) dur); - Dispatch dispatch = Dispatch.borrow(pc, itemHealthUpdateMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - } - - //Damage a random piece of armor a specified amount - public void damageRandomArmor(int amount) { - ArrayList armor = new ArrayList<>(); - if (this.equipped.containsKey(MBServerStatics.SLOT_OFFHAND)) { - Item item = this.equipped.get(MBServerStatics.SLOT_OFFHAND); - ItemBase ib = item.getItemBase(); - if (ib.isShield()) - armor.add(item); - } - if (this.equipped.containsKey(MBServerStatics.SLOT_HELMET)) - armor.add(this.equipped.get(MBServerStatics.SLOT_HELMET)); - if (this.equipped.containsKey(MBServerStatics.SLOT_CHEST)) - armor.add(this.equipped.get(MBServerStatics.SLOT_CHEST)); - if (this.equipped.containsKey(MBServerStatics.SLOT_ARMS)) - armor.add(this.equipped.get(MBServerStatics.SLOT_ARMS)); - if (this.equipped.containsKey(MBServerStatics.SLOT_GLOVES)) - armor.add(this.equipped.get(MBServerStatics.SLOT_GLOVES)); - if (this.equipped.containsKey(MBServerStatics.SLOT_GLOVES)) - armor.add(this.equipped.get(MBServerStatics.SLOT_GLOVES)); - if (this.equipped.containsKey(MBServerStatics.SLOT_LEGGINGS)) - armor.add(this.equipped.get(MBServerStatics.SLOT_LEGGINGS)); - if (this.equipped.containsKey(MBServerStatics.SLOT_FEET)) - armor.add(this.equipped.get(MBServerStatics.SLOT_FEET)); - - if (armor.isEmpty()) - return; //nothing to damage - - int roll = ThreadLocalRandom.current().nextInt(armor.size()); - damageItem(armor.get(roll), amount); - } - - //Damage all equipped gear a random amount between 1 and 5 - public void damageAllGear() { - for (Item gear : this.equipped.values()) { - damageItem(gear, (ThreadLocalRandom.current().nextInt(5) + 1)); - } - } - - // Add item to your possession - public synchronized boolean tradeForItem(Item i) { - // add to Inventory - this.inventory.add(i); - this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal()); - i.setOwnerID(this.absCharacter.getObjectUUID()); + public synchronized boolean buyFromNPC(Building vendorBuilding, int cost, int buildingDeposit) { + + Item gold = this.getGoldInventory(); + + if (cost <= 0 || (gold.getNumOfItems() - cost) < 0) + return false; + + + if (this.getOwner() != null && this.getOwner().getObjectType().equals(GameObjectType.PlayerCharacter)) { + if (this.goldTradingAmount > 0) { + ErrorPopupMsg.sendErrorPopup((PlayerCharacter) this.getOwner(), 195); + return false; + } + } + + // Create gold from screatch instead of building strongbox + // if the NPC is not slotted. + + if (vendorBuilding == null) { + + return this.modifyInventoryGold(-cost); + } + - calculateWeights(); - - return true; - } - - public synchronized boolean addGoldToTrade(int amount) { - - if (this.goldTradingAmount + amount > MBServerStatics.PLAYER_GOLD_LIMIT) - return false; - - this.goldTradingAmount += amount; - - return true; - } - - /** - * Completely empties inventory, deleting any items. Use with caution! - */ - public synchronized void clearInventory() { - this.getGoldInventory().setNumOfItems(0); - Iterator ii = this.inventory.iterator(); - while (ii.hasNext()) { - Item itm = ii.next(); - ii.remove(); - this.delete(itm); - } - } - - public synchronized void clearEquip() { - - ArrayList equipCopy = new ArrayList<>(this.getEquippedList()); - Iterator ii = equipCopy.iterator(); - while (ii.hasNext()) { - Item itm = ii.next(); - this.getEquippedList().remove(itm); - this.delete(itm); - } - } - - public byte getEquipVer() { - return this.equipVer; - } - - public static byte getInventoryVer() { - return inventoryVer; - } - - public static byte getBankVer() { - return bankVer; - } - - public static byte getVaultVer() { - return vaultVer; - } - - public void incEquipVer() { - this.equipVer++; - } - - public void incInventoryVer() { - this.equipVer++; - } - - public void incBankVer() { - this.equipVer++; - } - - public void incVaultVer() { - this.equipVer++; - } - - public static void takeFromNPC(NPC npc, PlayerCharacter pc, Item take, ClientMessagePump clientMessagePump) { - ItemBase ib = take.getItemBase(); - if (ib == null) - return; - CharacterItemManager itemMan = pc.getCharItemManager(); - if (itemMan == null) - return; - CharacterItemManager npcCim = npc.getCharItemManager(); - if (npcCim == null) - return; - if (!npcCim.inventoryContains(take)) { - return; - } - - if (!itemMan.hasRoomInventory(ib.getWeight())) - return; - if (take != null) { - itemMan.buyFromNPC(take, npc); - itemMan.updateInventory(); - } - } - - public int getTradeID() { - return tradeID; - } - - public synchronized boolean closeTradeWindow(){ - if (this.getTradingWith() != null || this.getTradeID() != 0) - this.closeTradeWindow(new CloseTradeWindowMsg(this.getOwner(), this.getTradeID()), true); - return true; - - } + if (vendorBuilding.getStrongboxValue() + cost > vendorBuilding.getMaxGold()) { + + if (this.absCharacter.getObjectType() == GameObjectType.PlayerCharacter) { + PlayerCharacter pc = (PlayerCharacter) this.absCharacter; + if (pc.getClientConnection() != null) + ErrorPopupMsg.sendErrorPopup(pc, 206); + } + + return false; + } + + + // Update strongbox and inventory gold + if (!this.modifyInventoryGold(-cost)) + return false; + + City buildingCity = vendorBuilding.getCity(); + + if (buildingCity != null) { + buildingCity.transactionLock.writeLock().lock(); + try { + if (!vendorBuilding.transferGold(buildingDeposit, true)) + return false; + } catch (Exception e) { + Logger.error(e); + return false; + } finally { + buildingCity.transactionLock.writeLock().unlock(); + } + } else if (!vendorBuilding.transferGold(buildingDeposit, true)) + return false; + + return true; + } + + //Used for selling items to NPC + public synchronized boolean sellToNPC(Building building, int cost, Item item) { + + // Create gold from screatch instead of building strongbox + // if the NPC is not slotted. + + if (this.getGoldInventory().getNumOfItems() + cost < 0) + return false; + + if (this.getGoldInventory().getNumOfItems() + cost > MBServerStatics.PLAYER_GOLD_LIMIT) + return false; + + + if (this.getOwner().getCharItemManager().getGoldTrading() > 0) { + if (this.getOwner().getObjectType().equals(GameObjectType.PlayerCharacter)) + ErrorPopupMsg.sendErrorPopup((PlayerCharacter) this.getOwner(), 195); + return false; + } + + + if (building == null) { + return this.modifyInventoryGold(cost); + } + + //make sure strongbox can afford gold. + + if (!building.hasFunds(cost)) + return false; + + if ((building.getStrongboxValue() - cost) < 0) + return false; + + // Update strongbox and inventory gold + + if (!building.transferGold(-cost, false)) + return false; + + return this.modifyInventoryGold(cost); + } + + /** + * This sells an item to an npc + * + * @return True on success + */ + public synchronized boolean sellToNPC(Item itemToSell, NPC npc) { + + CharacterItemManager itemMan; + + if (itemToSell == null || npc == null) + return false; + + itemMan = npc.getCharItemManager(); + + if (itemMan == null) + return false; + + //test npc inventory is not full + + synchronized (this) { + synchronized (itemMan) { + if (!this.doesCharOwnThisItem(itemToSell.getObjectUUID())) + return false; + // attempt to transfer item in db + + boolean sdrMerchant = false; + + if (npc.getContractID() >= 1900 && npc.getContractID() <= 1906) + sdrMerchant = true; + + if (sdrMerchant) { + this.delete(itemToSell); + this.updateInventory(); + + } else if (!itemToSell.moveItemToInventory(npc)) + return false; + + // db transfer successfull, remove from this character + // skip this check if this is a mobLoot item (which is not in any inventory) + if (!sdrMerchant) + if (!removeItemFromInventory(itemToSell)) + return false; + + // add item to looter. + if (!sdrMerchant) + if (!itemMan.addItemToInventory(itemToSell)) + return false; + } + } + + // calculate new weights + calculateInventoryWeight(); + itemMan.calculateInventoryWeight(); + return true; + } + + /** + * This buys an item from an npc + * Handles transfer of item. + * + * @return True on success + */ + public synchronized boolean buyFromNPC(Item purchasedItem, NPC npc) { + + CharacterItemManager itemMan; + ItemBase itemBase; + + if (purchasedItem == null || npc == null) + return false; + + itemMan = npc.getCharItemManager(); + + if (itemMan == null) + return false; + + + synchronized (this) { + synchronized (itemMan) { + itemBase = purchasedItem.getItemBase(); + + if (itemBase == null) + return false; + + //test inventory is not full + + if (!hasRoomInventory(itemBase.getWeight())) + return false; + + if (!itemMan.inventory.contains(purchasedItem)) + return false; + // attempt to transfer item in db + + if (purchasedItem.getObjectType() == GameObjectType.MobLoot) { + + Item newItem = ((MobLoot) purchasedItem).promoteToItem((PlayerCharacter) this.absCharacter); + if (newItem == null) + return false; + + if (!itemMan.removeItemFromInventory(purchasedItem)) + return false; + + if (!addItemToInventory(newItem)) + return false; + //Item was created and still a mobloot item, remove from npc production list in db. + + DbManager.NPCQueries.REMOVE_FROM_PRODUCTION_LIST(purchasedItem.getObjectUUID(), npc.getObjectUUID()); + + + } else { + if (!purchasedItem.moveItemToInventory((PlayerCharacter) this.absCharacter)) + return false; + + if (purchasedItem.getValue() != purchasedItem.getMagicValue()) { + DbManager.ItemQueries.UPDATE_VALUE(purchasedItem, 0); + purchasedItem.setValue(0); + } + + // db transfer successfull, remove from this character + // skip this check if this is a mobLoot item (which is not in any inventory) + if (!itemMan.removeItemFromInventory(purchasedItem)) + return false; + + // add item to looter. + + if (!addItemToInventory(purchasedItem)) + return false; + } + + } + } + + // calculate new weights + calculateInventoryWeight(); + itemMan.calculateInventoryWeight(); + return true; + } + + /** + * Loot an item from an AbstractCharacter. Call this function on + * the CharacterItemManager of the current item owner, not the looter. + * This method will verify that the looter can receive the item + * (e.g. inventory isn't full). + * + * @param i Item being looted + * @param looter Player looting the item + * @param origin ClientConnection + * @return True on success + */ + public synchronized Item lootItemFromMe(Item i, PlayerCharacter looter, ClientConnection origin) { + return lootItemFromMe(i, looter, origin, false, -1); + } + + //This function is used for both looting and stealing + public synchronized Item lootItemFromMe(Item lootItem, PlayerCharacter lootingPlayer, ClientConnection origin, boolean fromSteal, int amount) { + + //TODO this function should have more logging + // make sure lootingPlayer exists + if (lootingPlayer == null) + return null; + + // get looters item manager + CharacterItemManager looterItems = lootingPlayer.getCharItemManager(); + + if (looterItems == null) + return null; + + if (fromSteal) { + if (!this.absCharacter.isAlive()) + return null; + } else if (!this.absCharacter.canBeLooted()) + return null; + + MobLoot mobLoot = null; + if (lootItem instanceof MobLoot) { + mobLoot = (MobLoot) lootItem; + if (mobLoot.isDeleted()) + return null; + } + + //Lock both ItemManagers; lower ID first + CharacterItemManager lockFirst; + CharacterItemManager lockSecond; + if (this.absCharacter.getObjectUUID() + < looterItems.absCharacter.getObjectUUID()) { + lockFirst = this; + lockSecond = looterItems; + } else { + lockFirst = looterItems; + lockSecond = this; + } + + synchronized (lockFirst) { + synchronized (lockSecond) { + // make sure current player has item in inventory + if (lootItem.getItemBase().getType().equals(ItemType.GOLD) && lootItem.getObjectUUID() != this.getGoldInventory().getObjectUUID() && !(this.absCharacter.getObjectType().equals(GameObjectType.Mob))) + return null; + else if (!this.inventory.contains(lootItem) && !this.getEquippedList().contains(lootItem) && !lootItem.getItemBase().getType().equals(ItemType.GOLD)) + return null; + + // get weight of item + ItemBase ib = lootItem.getItemBase(); + if (ib == null) + return null; + short weight = ib.getWeight(); + + // make sure lootingPlayer has room for item + if (!lootItem.getItemBase().getType().equals(ItemType.GOLD) && !looterItems.hasRoomInventory(weight)) + return null; + + if (lootItem.getItemBase().getType().equals(ItemType.GOLD)) + if (amount != -1) { //from steal + int total = lootItem.getNumOfItems(); + amount = (amount > total) ? total : amount; + if (!looterItems.moveGoldToInventory(lootItem, amount)) + return null; + if (mobLoot != null && amount == total) + this.delete(mobLoot); + } else { //from loot + if (!looterItems.moveGoldToInventory(lootItem, lootItem.getNumOfItems())) + return null; + if (mobLoot != null) // delete mobloot after it has been looted + this.delete(mobLoot); + } + else { //not Gold item + boolean created = false; + if (mobLoot != null) { + lootItem = mobLoot.promoteToItem(lootingPlayer); + + // delete mobloot after it has been looted + this.delete(mobLoot); + if (lootItem == null) + return null; + + created = true; + } + + // attempt to transfer item in db + + if (!lootItem.moveItemToInventory(lootingPlayer)) + return null; + + // db transfer successfull, remove from this character + // skip this check if this is a mobLoot item (which is not in any inventory) + if (mobLoot == null) + if (!removeItemFromInventory(lootItem)) + return null; + + // add item to lootingPlayer. + if (!looterItems.addItemToInventory(lootItem)) + return null; + } + } + } + + // calculate new weights + calculateInventoryWeight(); + looterItems.calculateInventoryWeight(); + + return lootItem; + } + + private synchronized void remItemFromLists(Item i, byte slot) { + + this.equipped.remove((int) slot); + this.vault.remove(i); + this.bank.remove(i); + this.inventory.remove(i); + } + + /* + * Delegates + */ + public synchronized boolean bankContains(Item i) { + if (i.getItemBase().getType().equals(ItemType.GOLD)) + return (this.getGoldBank() != null && this.goldBank.getObjectUUID() == i.getObjectUUID()); + return bank.contains(i); + } + + public synchronized boolean inventoryContains(Item i) { + if (i.getItemBase().getType().equals(ItemType.GOLD)) + return (this.getGoldInventory() != null && this.goldInventory.getObjectUUID() == i.getObjectUUID()); + return inventory.contains(i); + } + + public synchronized boolean forgeContains(Item i, NPC vendor) { + if (i.getItemBase().getType().equals(ItemType.GOLD)) + return (this.getGoldInventory() != null && this.goldInventory.getObjectUUID() == i.getObjectUUID()); + return vendor.getRolling().contains(i); + } + + public synchronized boolean vaultContains(Item i) { + if (i.getItemBase().getType().equals(ItemType.GOLD)) + return (this.getGoldVault() != null && this.goldVault.getObjectUUID() == i.getObjectUUID()); + return this.account.getVault().contains(i); + } + + public synchronized boolean vaultContainsType(ItemBase ib) { + if (ib.getUUID() == 7) + return (this.getGoldVault() != null); + for (Item i : vault) { + if (i.getItemBase().getUUID() == ib.getUUID()) + return true; + } + return false; + } + + //for calling from devCmd fill vault. Already synchronized + public boolean vaultContainsTypeA(ItemBase ib) { + if (ib.getUUID() == 7) + return (this.getGoldVault() != null); + for (Item i : vault) { + if (i.getItemBase().getUUID() == ib.getUUID()) + return true; + } + return false; + } + + public synchronized boolean equippedContains(Item i) { + return equipped.containsValue(i); + } + + public synchronized Item getItemFromEquipped(int slot) { + return equipped.get(slot); + } + + public synchronized Item getItemByUUID(int objectUUID) { + if (this.itemIDtoType.containsKey(objectUUID)) { + + Integer integer = this.itemIDtoType.get(objectUUID); + if (integer == GameObjectType.Item.ordinal()) { + return Item.getFromCache(objectUUID); + } else if (integer == GameObjectType.MobLoot.ordinal()) { + return MobLoot.getFromCache(objectUUID); + } + + } + + if (this.getGoldInventory() != null && this.goldInventory.getObjectUUID() == objectUUID) + return this.goldInventory; + if (this.getGoldBank() != null && this.goldBank.getObjectUUID() == objectUUID) + return this.goldBank; + if (this.getGoldVault() != null && this.goldVault.getObjectUUID() == objectUUID) + return this.goldVault; + return null; + } + + public boolean tradingContains(Item i) { + if (this.trading == null || i == null) + return false; + return this.trading.contains(i.getObjectUUID()); + } + + public boolean isBankOpen() { + return this.bankOpened; + } + + public synchronized void setBankOpen(boolean bankOpened) { + this.bankOpened = bankOpened; + } + + public boolean isVaultOpen() { + return this.vaultOpened; + } + + public synchronized void setVaultOpen(boolean vaultOpened) { + this.vaultOpened = vaultOpened; + } + + public ClientConnection getTradingWith() { + return tradingWith; + } + + public synchronized void setTradingWith(ClientConnection tradingWith) { + this.tradingWith = tradingWith; + } + + public synchronized void clearTradingWith() { + this.tradingWith = null; + } + + public int getGoldTrading() { + return goldTradingAmount; + } + + public byte getTradeCommitted() { + return tradeCommitted; + } + + public synchronized void setTradeCommitted(byte tradeCommitted) { + this.tradeCommitted = tradeCommitted; + } + + public HashSet getTrading() { + return trading; + } + + /* + * List Copiers + */ + + public synchronized void addItemToTrade(Item i) { + this.trading.add(i.getObjectUUID()); + } + + public boolean getTradeSuccess() { + return tradeSuccess; + } + + public synchronized void setTradeSuccess(boolean tradeSuccess) { + this.tradeSuccess = tradeSuccess; + } + + public synchronized boolean RemoveEquipmentFromLackOfSkill(PlayerCharacter pc, boolean initialized) { + + + if (pc == null) + return false; + + if (this.equipped == null) + return false; + + + for (int slot : this.equipped.keySet()) { + + if (slot == MBServerStatics.SLOT_HAIRSTYLE || slot == MBServerStatics.SLOT_BEARDSTYLE) + continue; + + Item item = this.equipped.get(slot); + + if (item == null) { + this.equipped.remove(slot); + pc.applyBonuses(); + continue; + } + + if (!item.getItemBase().validForSkills(pc.getSkills())) { + this.forceToInventory(slot, item, pc, initialized); + pc.applyBonuses(); + } + } + + return true; + } + + /** + * Note that this method returns a copy of the internally stored + * list. + * + * @return the equipped + */ + public ConcurrentHashMap getEquipped() { + synchronized (this.equipped) { + return new ConcurrentHashMap<>(this.equipped); + } + } + + public ArrayList getEquippedList() { + ArrayList ret = new ArrayList<>(); + synchronized (this.equipOrder) { + synchronized (this.equipped) { + for (int slot : this.equipOrder) { + if (this.equipped.containsKey(slot)) + ret.add(this.equipped.get(slot)); + } + if (ret.size() != this.equipped.size()) + //missed adding some items, figure out what. + for (int slot : this.equipped.keySet()) { + if (!(this.equipOrder.contains(slot))) { + this.equipOrder.add(slot); + ret.add(this.equipped.get(slot)); + } + } + } + } + return ret; + } + + public Item getEquipped(int slot) { + synchronized (this.equipped) { + return this.equipped.get(slot); + } + } + + /** + * Note that this method returns a copy of the internally stored + * list. + * + * @return the inventory + */ + public ArrayList getInventory() { + return getInventory(false); + } + + public ArrayList getInventory(boolean sendGold) { + synchronized (this.inventory) { + ArrayList ret = new ArrayList<>(this.inventory); + if (sendGold && this.getGoldInventory() != null && this.goldInventory.getNumOfItems() > 0) + ret.add(this.goldInventory); + return ret; + } + } + + public int getInventoryCount() { + synchronized (this.inventory) { + return this.inventory.size(); + } + } + + /** + * Clears ownership of items. Called when player dies, but before + * respawning. + * + * @return the inventory + */ + public synchronized void orphanInventory() { + PlayerCharacter pc = null; + if (this.absCharacter != null && this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)) + pc = (PlayerCharacter) this.absCharacter; + synchronized (this.inventory) { + //dupe check, validate player properly owns all items + if (pc != null) { + Iterator iter = this.inventory.iterator(); + while (iter.hasNext()) { + Item item = iter.next(); + //this call may remove the item from this.inventory + if (!item.validForInventory(pc.getClientConnection(), pc, this)) { + } + } + } + + if (this.inventory.size() > 0) + DbManager.ItemQueries.ORPHAN_INVENTORY(this.inventory); + //make a copy of gold inventory for looting + //so we don't remove the goldInventory + if (this.getGoldInventory().getNumOfItems() > 0) { + int amt = this.goldInventory.getNumOfItems(); + if (DbManager.ItemQueries.UPDATE_GOLD(this.goldInventory, 0)) { + this.goldInventory.setNumOfItems(0); + MobLoot gold = new MobLoot(this.absCharacter, amt); + this.inventory.add(gold); + } + } + } + } + + /** + * This transfers the entire inventory to another list For populating + * corpse' inventory when player dies + * + * @return the inventory + */ + public synchronized void transferEntireInventory( + ArrayList newInventory, Corpse corpse, boolean enterWorld) { + + PlayerCharacter pc = null; + if (this.absCharacter != null && this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)) + pc = (PlayerCharacter) this.absCharacter; + + if (this.getGoldInventory().getNumOfItems() > 0) { + int amt = this.goldInventory.getNumOfItems(); + if (DbManager.ItemQueries.UPDATE_GOLD(this.goldInventory, 0)) { + this.goldInventory.setNumOfItems(0); + MobLoot gold = new MobLoot(this.absCharacter, amt); + newInventory.add(gold); + } + } + + for (Item item : this.inventory) { + if (item != null) + if (item instanceof MobLoot) { + + //MobLoot + item.zeroItem(); + item.containerType = Enum.ItemContainerType.INVENTORY; + + if (item.getItemBase().getType().equals(ItemType.GOLD)) + //only add gold item once + if (!corpse.hasGold()) + corpse.setHasGold(true); + newInventory.add(item); + } else //item + if (item.getItemBase().getType().equals(ItemType.GOLD)) { + int amt = item.getNumOfItems(); + item.setNumOfItems(0); + MobLoot ml = new MobLoot(this.absCharacter, amt); + ml.zeroItem(); + ml.containerType = Enum.ItemContainerType.INVENTORY; + if (!corpse.hasGold()) { + corpse.setHasGold(true); + newInventory.add(ml); + } + } else { + boolean transferred = item.moveItemToInventory(corpse); + if (!transferred) + Logger.error( + "CharItemManager.transferEntireInvetory", + "DB Error, Failed to transfer item " + + item.getObjectUUID() + " to new owner " + + corpse.getObjectUUID()); + newInventory.add(item); + + } + } + + // tell client we're clearing inventory + + + // clear the inventory. + this.inventory.clear(); + + //re-calculate inventory weight + calculateInventoryWeight(); + if (!enterWorld) + updateInventory(this.getInventory(), false); + } + + public synchronized void purgeInventory() { + + if (!this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)) + return; + + if (this.goldInventory != null) + if (this.getGoldInventory().getNumOfItems() > 0) { + if (DbManager.ItemQueries.UPDATE_GOLD(this.goldInventory, 0)) { + this.goldInventory.setNumOfItems(0); + } + } + + if (this.inventory.size() > 0) + DbManager.ItemQueries.ORPHAN_INVENTORY(this.inventory); + + // clear the inventory. + this.inventory.clear(); + //re-calculate inventory weight + calculateInventoryWeight(); + } + + /** + * Note that this method returns a copy of the internally stored + * list. + * + * @return the bank + */ + public ArrayList getBank() { + synchronized (this.bank) { + ArrayList ret = new ArrayList<>(this.bank); + if (this.getGoldBank() != null && this.goldBank.getNumOfItems() > 0) + ret.add(this.goldBank); + return ret; + } + } + + /** + * Note that this method returns a copy of the internally stored + * list. + * + * @return the vault + */ + public ArrayList getVault() { + synchronized (this.vault) { + ArrayList ret = new ArrayList<>(this.vault); + if (this.getGoldVault() != null && this.goldVault.getNumOfItems() > 0) + ret.add(this.goldVault); + return ret; + } + } + + public boolean hasRoomInventory(short weight) { + if (this.absCharacter == null) + return false; + if (this.absCharacter.getObjectType() == GameObjectType.PlayerCharacter) { + PlayerCharacter pc = (PlayerCharacter) this.absCharacter; + int newWeight = this.getCarriedWeight() + weight; + return newWeight <= (int) pc.statStrBase * 3; + } else if (this.absCharacter.getObjectType() == GameObjectType.NPC) { + int newWeight = this.getCarriedWeight() + weight; + return newWeight <= 1900 + (this.absCharacter.getLevel() * 3); + } else + return true; // npc's need checked + } + + public boolean hasRoomTrade(short itemWeight) { + + PlayerCharacter playerCharacter; + PlayerCharacter tradeCharacter; + + int tradeWeight; + + if (this.absCharacter == null) + return false; + + if (this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter) == false) + return false; + + playerCharacter = (PlayerCharacter) this.absCharacter; + + if ((this.tradingWith == null) || + (this.tradingWith.isConnected() == false)) + return false; + + tradeCharacter = this.tradingWith.getPlayerCharacter(); + + tradeWeight = this.getCarriedWeight() + itemWeight; + tradeWeight = tradeWeight + tradeCharacter.getCharItemManager().getTradingWeight(); + tradeWeight = tradeWeight - this.getTradingWeight(); + + return tradeWeight <= (int) playerCharacter.statStrBase * 3; + } + + public boolean hasRoomBank(short weight) { + if (this.absCharacter == null) + return false; + return weight <= this.absCharacter.getBankCapacityRemaining(); + } + + public boolean hasRoomVault(short weight) { + if (this.absCharacter == null) + return false; + return weight <= this.absCharacter.getVaultCapacityRemaining(); + } + + public int getCarriedWeight() { + return getInventoryWeight() + getEquipWeight(); + } + + public int getInventoryWeight() { + return this.inventoryWeight; + } + + public int getBankWeight() { + return this.bankWeight; + } + + public int getEquipWeight() { + return this.equipWeight; + } + + public int getVaultWeight() { + return this.vaultWeight; + } + + public int getTradingForWeight() { + return calculateTradingForWeight(); + } + + public int getTradingWeight() { + + int weight = 0; + Item item; + + for (int i : this.trading) { + item = Item.getFromCache(i); + + if (item == null) + continue; + + ItemBase ib = item.getItemBase(); + weight += ib.getWeight(); + } + return weight; + } + + public AbstractCharacter getOwner() { + return this.absCharacter; + } + + public void calculateWeights() { + calculateBankWeight(); + calculateInventoryWeight(); + calculateEquipWeight(); + calculateVaultWeight(); + } + + public void calculateBankWeight() { + this.bankWeight = 0; + for (Item i : this.bank) { + ItemBase ib = i.getItemBase(); + if (ib != null) + this.bankWeight += ib.getWeight(); + } + } + + public void calculateEquipWeight() { + this.equipWeight = 0; + Collection c = this.equipped.values(); + Iterator it = c.iterator(); + while (it.hasNext()) { + Item i = it.next(); + ItemBase ib = i.getItemBase(); + if (ib != null) + this.equipWeight += ib.getWeight(); + } + } + + public void calculateInventoryWeight() { + this.inventoryWeight = 0; + for (Item i : this.inventory) { + ItemBase ib = i.getItemBase(); + if (ib != null) + this.inventoryWeight += ib.getWeight(); + } + } + + public void calculateVaultWeight() { + this.vaultWeight = 0; + for (Item i : this.vault) { + ItemBase ib = i.getItemBase(); + if (ib != null) + this.vaultWeight += ib.getWeight(); + } + } + + private int calculateTradingForWeight() { + int tradingForWeight = 0; + + return tradingForWeight; + } + + public void updateInventory(Item item, boolean add) { + ArrayList list = new ArrayList<>(); + list.add(item); + updateInventory(list, add); + } + + private void updateInventory(ArrayList inventory, boolean add) { + + if (this.absCharacter == null) + return; + + if (this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter) == false) + return; + + PlayerCharacter pc = (PlayerCharacter) this.absCharacter; + + UpdateInventoryMsg updateInventoryMsg = new UpdateInventoryMsg(inventory, this.getBank(), this.getGoldInventory(), add); + Dispatch dispatch = Dispatch.borrow(pc, updateInventoryMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + } + + public void forceToInventory(int slot, Item item, PlayerCharacter pc, boolean initialized) { + if (item == null || pc == null) + return; + + if (!item.moveItemToInventory(pc)) { + //TODO well why did this fail? clean it up + } + + // remove it from other lists: + this.remItemFromLists(item, (byte) slot); + + // add to Inventory + this.inventory.add(item); + item.addToCache(); + + calculateWeights(); + + //Update players with unequipped item + if (initialized) { + TransferItemFromEquipToInventoryMsg back = new TransferItemFromEquipToInventoryMsg(pc, slot); + DispatchMessage.dispatchMsgToInterestArea(pc, back, engine.Enum.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + } + + } + + /** + * Update the player's inventory window by resending the entire contents. + */ + public void updateInventory() { + this.updateInventory(this.getInventory(), true); + } + + public synchronized void initializeTrade() { + this.trading = new HashSet<>(); + } + + public synchronized boolean commitTrade() { + int goldFrom1 = 0; + int goldFrom2 = 0; + + if (this.getTradingWith() == null || this.getTradingWith().isConnected() == false + || this.getTradingWith().getPlayerCharacter() == null) { + this.endTrade(); + return false; + } + + + CharacterItemManager tradingWith = this.getTradingWith().getPlayerCharacter().getCharItemManager(); + + if (tradingWith == null) + return false; + + if (this.goldTradingAmount != 0) { + + if (tradingWith.goldInventory == null) { + Logger.error("Null Gold for player " + this.getOwner().getObjectUUID()); + return false; + } + goldFrom1 = this.goldTradingAmount; + } + if (tradingWith.goldTradingAmount != 0) { + + if (this.getGoldInventory() == null) { + Logger.error("Null Gold for player " + this.getOwner().getObjectUUID()); + return false; + } + goldFrom2 = tradingWith.goldTradingAmount; + } + + + if (this.getGoldInventory().getNumOfItems() + goldFrom2 > 10000000) { + PlayerCharacter pc = (PlayerCharacter) this.absCharacter; + if (pc.getClientConnection() != null) + ErrorPopupMsg.sendErrorPopup(pc, 202); + return false; + } + + + if (tradingWith.getGoldInventory().getNumOfItems() + goldFrom1 > 10000000) { + PlayerCharacter pc = (PlayerCharacter) tradingWith.absCharacter; + if (pc.getClientConnection() != null) + ErrorPopupMsg.sendErrorPopup(pc, 202); + return false; + } + + if (this.trading.size() > 0 || tradingWith.trading.size() > 0 || goldFrom1 > 0 || goldFrom2 > 0) { + if (!DbManager.ItemQueries.DO_TRADE(this.trading, tradingWith.trading, this, tradingWith, + this.goldInventory, tradingWith.goldInventory, goldFrom1, goldFrom2)) + return false; + } else + return true; + + for (int i : this.trading) { + Item item = Item.getFromCache(i); + if (item == null) + continue; + this.trade(item); + tradingWith.tradeForItem(item); + } + for (int i : tradingWith.trading) { + Item item = Item.getFromCache(i); + if (item == null) + continue; + tradingWith.trade(item); + this.tradeForItem(item); + } + + //subtract gold your trading from your inventory. + if (this.goldTradingAmount > 0) + this.getGoldInventory().setNumOfItems(this.getGoldInventory().getNumOfItems() - this.goldTradingAmount); + //subtract gold your trading from your inventory. + if (tradingWith.goldTradingAmount > 0) + tradingWith.getGoldInventory().setNumOfItems(tradingWith.getGoldInventory().getNumOfItems() - tradingWith.goldTradingAmount); + + if (tradingWith.goldTradingAmount > 0) + this.getGoldInventory().setNumOfItems(this.goldInventory.getNumOfItems() + + tradingWith.goldTradingAmount); + if (this.goldTradingAmount > 0) + tradingWith.getGoldInventory().setNumOfItems(tradingWith.goldInventory.getNumOfItems() + + this.goldTradingAmount); + + this.tradeSuccess = true; + tradingWith.tradeSuccess = true; + + return true; + + } + + public synchronized void endTrade() { + updateInventory(this.getInventory(), true); + this.tradeCommitted = (byte) 0; + this.tradeSuccess = false; + this.tradingWith = null; + this.trading = null; + this.goldTradingAmount = 0; + this.tradeID = 0; + } + + public synchronized void endTrade(boolean fromDeath) { + this.tradeCommitted = (byte) 0; + this.tradeSuccess = false; + this.tradingWith = null; + this.trading = null; + this.goldTradingAmount = 0; + } + + // Remove item from your possession + private synchronized boolean trade(Item i) { + if (this.doesCharOwnThisItem(i.getObjectUUID()) == false) + return false; + + // Only valid from inventory + if (!inventoryContains(i)) + return false; + + // remove from Inventory + this.inventory.remove(i); + this.itemIDtoType.remove(i.getObjectUUID()); + i.setOwnerID(0); + + calculateWeights(); + + return true; + } + + //Damage an equipped item a specified amount + public void damageItem(Item item, int amount) { + if (item == null || amount < 1 || amount > 5) + return; + + //verify the item is equipped by this player + int slot = item.getEquipSlot(); + if (!this.equipped.containsKey(slot)) + return; + Item verify = this.equipped.get(slot); + if (verify == null || item.getObjectUUID() != verify.getObjectUUID()) + return; + + //don't damage noob gear, hair or beards. + if (item.getDurabilityMax() == 0) + return; + + if (!item.isCanDestroy()) + return; + + int dur = (int) item.getDurabilityCurrent(); + if (dur - amount <= 0) { + //destroy the item + junk(item); + + //TODO remove item from the client + //This may not be correct + dur = 0; + } else { + dur -= amount; + if (!DbManager.ItemQueries.SET_DURABILITY(item, dur)) + return; + item.setDurabilityCurrent((short) dur); + + } + + if (this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter) == false) + return; + + //send damage item msg to client + PlayerCharacter pc = (PlayerCharacter) this.absCharacter; + + ItemHealthUpdateMsg itemHealthUpdateMsg = new ItemHealthUpdateMsg(slot, (float) dur); + Dispatch dispatch = Dispatch.borrow(pc, itemHealthUpdateMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + } + + //Damage a random piece of armor a specified amount + public void damageRandomArmor(int amount) { + ArrayList armor = new ArrayList<>(); + if (this.equipped.containsKey(MBServerStatics.SLOT_OFFHAND)) { + Item item = this.equipped.get(MBServerStatics.SLOT_OFFHAND); + ItemBase ib = item.getItemBase(); + if (ib.isShield()) + armor.add(item); + } + if (this.equipped.containsKey(MBServerStatics.SLOT_HELMET)) + armor.add(this.equipped.get(MBServerStatics.SLOT_HELMET)); + if (this.equipped.containsKey(MBServerStatics.SLOT_CHEST)) + armor.add(this.equipped.get(MBServerStatics.SLOT_CHEST)); + if (this.equipped.containsKey(MBServerStatics.SLOT_ARMS)) + armor.add(this.equipped.get(MBServerStatics.SLOT_ARMS)); + if (this.equipped.containsKey(MBServerStatics.SLOT_GLOVES)) + armor.add(this.equipped.get(MBServerStatics.SLOT_GLOVES)); + if (this.equipped.containsKey(MBServerStatics.SLOT_GLOVES)) + armor.add(this.equipped.get(MBServerStatics.SLOT_GLOVES)); + if (this.equipped.containsKey(MBServerStatics.SLOT_LEGGINGS)) + armor.add(this.equipped.get(MBServerStatics.SLOT_LEGGINGS)); + if (this.equipped.containsKey(MBServerStatics.SLOT_FEET)) + armor.add(this.equipped.get(MBServerStatics.SLOT_FEET)); + + if (armor.isEmpty()) + return; //nothing to damage + + int roll = ThreadLocalRandom.current().nextInt(armor.size()); + damageItem(armor.get(roll), amount); + } + + //Damage all equipped gear a random amount between 1 and 5 + public void damageAllGear() { + for (Item gear : this.equipped.values()) { + damageItem(gear, (ThreadLocalRandom.current().nextInt(5) + 1)); + } + } + + // Add item to your possession + public synchronized boolean tradeForItem(Item i) { + // add to Inventory + this.inventory.add(i); + this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal()); + i.setOwnerID(this.absCharacter.getObjectUUID()); + + calculateWeights(); + + return true; + } + + public synchronized boolean addGoldToTrade(int amount) { + + if (this.goldTradingAmount + amount > MBServerStatics.PLAYER_GOLD_LIMIT) + return false; + + this.goldTradingAmount += amount; + + return true; + } + + /** + * Completely empties inventory, deleting any items. Use with caution! + */ + public synchronized void clearInventory() { + this.getGoldInventory().setNumOfItems(0); + Iterator ii = this.inventory.iterator(); + while (ii.hasNext()) { + Item itm = ii.next(); + ii.remove(); + this.delete(itm); + } + } + + public synchronized void clearEquip() { + + ArrayList equipCopy = new ArrayList<>(this.getEquippedList()); + Iterator ii = equipCopy.iterator(); + while (ii.hasNext()) { + Item itm = ii.next(); + this.getEquippedList().remove(itm); + this.delete(itm); + } + } + + public byte getEquipVer() { + return this.equipVer; + } + + public void incEquipVer() { + this.equipVer++; + } + + public void incInventoryVer() { + this.equipVer++; + } + + public void incBankVer() { + this.equipVer++; + } + + public void incVaultVer() { + this.equipVer++; + } + + public int getTradeID() { + return tradeID; + } + + public synchronized boolean closeTradeWindow() { + if (this.getTradingWith() != null || this.getTradeID() != 0) + this.closeTradeWindow(new CloseTradeWindowMsg(this.getOwner(), this.getTradeID()), true); + return true; + + } } diff --git a/src/engine/objects/CharacterPower.java b/src/engine/objects/CharacterPower.java index ecc2c808..c220438f 100644 --- a/src/engine/objects/CharacterPower.java +++ b/src/engine/objects/CharacterPower.java @@ -27,603 +27,597 @@ import java.util.concurrent.atomic.AtomicInteger; public class CharacterPower extends AbstractGameObject { - private final PowersBase power; - private AtomicInteger trains = new AtomicInteger(); - private short grantedTrains; - private int ownerUID; - private boolean trained = false; - private int requiredLevel = 0; - - - - - /** - * No Table ID Constructor - */ - public CharacterPower(PowersBase power, PlayerCharacter pc) { - super(); - this.power = power; - this.trains.set(0); + private final PowersBase power; + private AtomicInteger trains = new AtomicInteger(); + private short grantedTrains; + private int ownerUID; + private boolean trained = false; + private int requiredLevel = 0; + + + /** + * No Table ID Constructor + */ + public CharacterPower(PowersBase power, PlayerCharacter pc) { + super(); + this.power = power; + this.trains.set(0); this.grantedTrains = this.grantedTrains; - this.ownerUID = pc.getObjectUUID(); + this.ownerUID = pc.getObjectUUID(); - } + } - /** - * Normal Constructor - */ - public CharacterPower(PowersBase power, PlayerCharacter pc, int newUUID) { - super(newUUID); - this.power = power; - this.trains.set(0); + /** + * Normal Constructor + */ + public CharacterPower(PowersBase power, PlayerCharacter pc, int newUUID) { + super(newUUID); + this.power = power; + this.trains.set(0); this.grantedTrains = this.grantedTrains; - this.ownerUID = pc.getObjectUUID(); + this.ownerUID = pc.getObjectUUID(); + + } - } + /** + * ResultSet Constructor + */ + public CharacterPower(ResultSet rs, PlayerCharacter pc) throws SQLException { + super(rs); + int powersBaseToken = rs.getInt("PowersBaseToken"); + this.power = PowersManager.getPowerByToken(powersBaseToken); - /** - * ResultSet Constructor - */ - public CharacterPower(ResultSet rs, PlayerCharacter pc) throws SQLException { - super(rs); - int powersBaseToken = rs.getInt("PowersBaseToken"); - this.power = PowersManager.getPowerByToken(powersBaseToken); - - if (this.power != null && this.power.isWeaponPower()) - this.trains.set(0); - else - this.trains.set(rs.getInt("trains")); + if (this.power != null && this.power.isWeaponPower()) + this.trains.set(0); + else + this.trains.set(rs.getInt("trains")); this.grantedTrains = this.grantedTrains; - this.ownerUID = pc.getObjectUUID(); + this.ownerUID = pc.getObjectUUID(); - } + } - public CharacterPower(ResultSet rs) throws SQLException { - super(rs); - int powersBaseToken = rs.getInt("PowersBaseToken"); - this.power = PowersManager.getPowerByToken(powersBaseToken); - this.trains.set(rs.getInt("trains")); + public CharacterPower(ResultSet rs) throws SQLException { + super(rs); + int powersBaseToken = rs.getInt("PowersBaseToken"); + this.power = PowersManager.getPowerByToken(powersBaseToken); + this.trains.set(rs.getInt("trains")); this.grantedTrains = this.grantedTrains; - this.ownerUID = rs.getInt("CharacterID"); - - // this.owner = DbManager.PlayerCharacterQueries.GET_PLAYER_CHARACTER(rs.getInt("CharacterID")); - } - - private short getGrantedTrains(PlayerCharacter pc) { - if (this.power != null && pc != null) { - // if (this.power.isWeaponPower()) { - // SkillsBase sb = null; - // try { - // sb = SkillsBase.getSkillsBaseByName(this.power.getSkillName()); - // } catch (SQLException e) {} - // if (sb != null) { - // return pc.getBonuses().getByte("gt." + sb.getToken()); - // } else - // return pc.getBonuses().getByte("gt." + this.power.getToken()); - // } else - // return pc.getBonuses().getByte("gt." + this.power.getToken()); - return PowerGrant.getGrantedTrains(this.power.getToken(), pc); - } - else - return 0; - } - - /* - * Getters - */ - public PowersBase getPower() { - return power; - } - - public int getPowerID() { - return power.getUUID(); - } - - public boolean isTrained() { - return trained; - } - - public static PlayerCharacter getOwner(CharacterPower cp) { - return PlayerCharacter.getFromCache(cp.ownerUID); - } - - public void setTrained(boolean b) { - trained = b; - } - - public int getTrains() { - return this.trains.get(); - } - - public short getGrantedTrains() { - return this.grantedTrains; - } - - public int getTotalTrains() { - return (this.trains.get() + this.grantedTrains); - } - - public float getTrainingCost(PlayerCharacter pc, NPC trainer){ - int charLevel = pc.getLevel(); - int skillRank = this.trains.get() -1 + this.requiredLevel; - - - float baseCost = 50 * this.requiredLevel ; //TODO GET BASE COSTS OF SKILLS. - - - - float sellPercent = -4f; //NOT SELL PERCENT! - float cost; - float const5; - int const2 = 1; - float const3 = 50; - float const4 = const3 + const2; - if (charLevel > 50) - const5 = 50 / const4; - else - const5 = charLevel/const4; - - const5 = 1-const5; - const5 = (float) (Math.log(const5) / Math.log(2) * .75f); - float rounded5 = Math.round(const5); - const5 = rounded5 - const5; - - const5 *= -1; - - const5 = (float) (Math.pow(2, const5) - 1); - - const5 +=1; - const5 = Math.scalb(const5, (int) rounded5); - const5 *= (charLevel - skillRank); - const5 *= sellPercent; - - const5 = (float) (Math.log(const5) / Math.log(2) * 3); - rounded5 = Math.round(const5); - const5 = rounded5 - const5; - const5 *= -1; - const5 = (float) (Math.pow(2, const5) - 1); - const5 +=1; - - - const5 = Math.scalb(const5, (int) rounded5); - const5 += 1; - cost = const5 * baseCost; - - - if (Float.isNaN(cost)) - cost = baseCost; - return cost; - } - - public synchronized boolean train(PlayerCharacter pc) { - if (pc == null || this.power == null) - return false; - - //see if any prereqs to train this power is met - if (!canTrain(pc)) - return false; - - boolean succeeded=true; - int oldTrains = this.trains.get(); - int tr = oldTrains + this.grantedTrains; - if (pc.getTrainsAvailable() <= 0) - return false; - if (tr == this.power.getMaxTrains()) //at max, stop here - return false; - else if (tr > this.power.getMaxTrains()) //catch incase we somehow go over - this.trains.set((this.power.getMaxTrains() - this.grantedTrains)); - else //add the train - succeeded = this.trains.compareAndSet(oldTrains, oldTrains+1); - - if (this.trains.get() > this.power.getMaxTrains()) { //double check not over max trains - this.trains.set(this.power.getMaxTrains()); - succeeded = false; - } - - if (succeeded) { - this.trained = true; - - //update database - pc.addDatabaseJob("Skills", MBServerStatics.THIRTY_SECONDS); - - //subtract from trains available - pc.modifyTrainsAvailable(-1); - - pc.calculateSkills(); - return true; - } else - return false; - } - - public boolean reset(PlayerCharacter pc) { - if (pc == null || this.power == null) - return false; - - //see if any prereqs to refine this power is met - - boolean succeeded=true; - int oldTrains = this.trains.get(); - int tr = oldTrains + this.grantedTrains; - if (oldTrains < 1) - return false; - else //subtract the train - succeeded = this.trains.compareAndSet(oldTrains, 0); - if (succeeded) { - this.trained = true; - - //update database - pc.addDatabaseJob("Skills", MBServerStatics.THIRTY_SECONDS); - - //subtract from trains available - pc.modifyTrainsAvailable(oldTrains); - - pc.calculateSkills(); - return true; - } else - return false; - } - - public boolean refine(PlayerCharacter pc) { - if (pc == null || this.power == null) - return false; - - //see if any prereqs to refine this power is met - if (!canRefine(pc)) - return false; - - boolean succeeded=true; - int oldTrains = this.trains.get(); - int tr = oldTrains + this.grantedTrains; - if (oldTrains < 1) - return false; - else //subtract the train - succeeded = this.trains.compareAndSet(oldTrains, oldTrains-1); - if (succeeded) { - this.trained = true; - - //update database - pc.addDatabaseJob("Skills", MBServerStatics.THIRTY_SECONDS); - - //subtract from trains available - pc.modifyTrainsAvailable(1); - - pc.calculateSkills(); - return true; - } else - return false; - } - - - /* - * Utils - */ - - /* - * This iterates through players runes and adds and removes powers as needed - * Don't Call this directly. Instead call pc.calculateSkills(). - */ - public static void calculatePowers(PlayerCharacter pc) { - if (pc == null) - return; - - // First add powers that don't exist - ConcurrentHashMap powers = pc.getPowers(); - // ArrayList genericPowers = PowerReq.getPowerReqsForAll(); - // CharacterPower.grantPowers(genericPowers, powers, pc); - Race race = pc.getRace(); - if (race != null) { - CharacterPower.grantPowers(race.getPowersGranted(), powers, pc); - } else - Logger.error( "Failed to find Race for player " + pc.getObjectUUID()); - BaseClass bc = pc.getBaseClass(); - if (bc != null) { - CharacterPower.grantPowers(bc.getPowersGranted(), powers, pc); - } else - Logger.error( "Failed to find BaseClass for player " + pc.getObjectUUID()); - PromotionClass promo = pc.getPromotionClass(); - if (promo != null) - CharacterPower.grantPowers(promo.getPowersGranted(), powers, pc); - ArrayList runes = pc.getRunes(); - if (runes != null) { - for (CharacterRune rune : runes) { - CharacterPower.grantPowers(rune.getPowersGranted(), powers, pc); - } - } else - Logger.error("Failed to find Runes list for player " + pc.getObjectUUID()); - - // next remove any skills that no longer belong - Iterator it = powers.keySet().iterator(); - while (it.hasNext()) { - Integer token = it.next(); - boolean valid = false; - // if (CharacterPower.powerAllowed(token, genericPowers, pc)) - // continue; - if (CharacterPower.powerAllowed(token, race.getPowersGranted(), pc)) - continue; - if (CharacterPower.powerAllowed(token, bc.getPowersGranted(), pc)) - continue; - if (promo != null) - if (CharacterPower.powerAllowed(token, promo.getPowersGranted(), pc)) - continue; - for (CharacterRune rune : runes) { - if (CharacterPower.powerAllowed(token, rune.getPowersGranted(), pc)) { - valid = true; - continue; - } - } - - // if power doesn't belong to any runes or skill, then remove it - if (!valid) { - CharacterPower cp = powers.get(token); - DbManager.CharacterPowerQueries.DELETE_CHARACTER_POWER(cp.getObjectUUID()); - it.remove(); - } - } - } - - /* - * This grants powers for specific runes - */ - private static void grantPowers(ArrayList powersGranted, ConcurrentHashMap powers, PlayerCharacter pc) { - ConcurrentHashMap skills = pc.getSkills(); - - for (PowerReq powerreq : powersGranted) { - PowersBase powersBase = powerreq.getPowersBase(); - - if (powersBase == null) - continue; - // skip if player already has power - if (powers.containsKey(powerreq.getToken())){ - CharacterPower cp = powers.get(powersBase.getToken()); + this.ownerUID = rs.getInt("CharacterID"); + + // this.owner = DbManager.PlayerCharacterQueries.GET_PLAYER_CHARACTER(rs.getInt("CharacterID")); + } + + public static PlayerCharacter getOwner(CharacterPower cp) { + return PlayerCharacter.getFromCache(cp.ownerUID); + } + + /* + * This iterates through players runes and adds and removes powers as needed + * Don't Call this directly. Instead call pc.calculateSkills(). + */ + public static void calculatePowers(PlayerCharacter pc) { + if (pc == null) + return; + + // First add powers that don't exist + ConcurrentHashMap powers = pc.getPowers(); + // ArrayList genericPowers = PowerReq.getPowerReqsForAll(); + // CharacterPower.grantPowers(genericPowers, powers, pc); + Race race = pc.getRace(); + if (race != null) { + CharacterPower.grantPowers(race.getPowersGranted(), powers, pc); + } else + Logger.error("Failed to find Race for player " + pc.getObjectUUID()); + BaseClass bc = pc.getBaseClass(); + if (bc != null) { + CharacterPower.grantPowers(bc.getPowersGranted(), powers, pc); + } else + Logger.error("Failed to find BaseClass for player " + pc.getObjectUUID()); + PromotionClass promo = pc.getPromotionClass(); + if (promo != null) + CharacterPower.grantPowers(promo.getPowersGranted(), powers, pc); + ArrayList runes = pc.getRunes(); + if (runes != null) { + for (CharacterRune rune : runes) { + CharacterPower.grantPowers(rune.getPowersGranted(), powers, pc); + } + } else + Logger.error("Failed to find Runes list for player " + pc.getObjectUUID()); + + // next remove any skills that no longer belong + Iterator it = powers.keySet().iterator(); + while (it.hasNext()) { + Integer token = it.next(); + boolean valid = false; + // if (CharacterPower.powerAllowed(token, genericPowers, pc)) + // continue; + if (CharacterPower.powerAllowed(token, race.getPowersGranted(), pc)) + continue; + if (CharacterPower.powerAllowed(token, bc.getPowersGranted(), pc)) + continue; + if (promo != null) + if (CharacterPower.powerAllowed(token, promo.getPowersGranted(), pc)) + continue; + for (CharacterRune rune : runes) { + if (CharacterPower.powerAllowed(token, rune.getPowersGranted(), pc)) { + valid = true; + continue; + } + } + + // if power doesn't belong to any runes or skill, then remove it + if (!valid) { + CharacterPower cp = powers.get(token); + DbManager.CharacterPowerQueries.DELETE_CHARACTER_POWER(cp.getObjectUUID()); + it.remove(); + } + } + } + + /* + * This grants powers for specific runes + */ + private static void grantPowers(ArrayList powersGranted, ConcurrentHashMap powers, PlayerCharacter pc) { + ConcurrentHashMap skills = pc.getSkills(); + + for (PowerReq powerreq : powersGranted) { + PowersBase powersBase = powerreq.getPowersBase(); + + if (powersBase == null) + continue; + // skip if player already has power + if (powers.containsKey(powerreq.getToken())) { + CharacterPower cp = powers.get(powersBase.getToken()); if (cp != null) - if (cp.requiredLevel == 0) { - cp.requiredLevel = (int) powerreq.getLevel(); - } - - continue; - } - - // If player not high enough level for power, then skip - if (pc.getLevel() < powerreq.getLevel()) - continue; - - // See if any prereq powers needed - boolean valid = true; - ConcurrentHashMap preqs = powerreq.getPowerReqs(); - for (Integer tok : preqs.keySet()) { - if (!powers.containsKey(tok)) - valid = false; - else { - CharacterPower cpp = powers.get(tok); + if (cp.requiredLevel == 0) { + cp.requiredLevel = (int) powerreq.getLevel(); + } + + continue; + } + + // If player not high enough level for power, then skip + if (pc.getLevel() < powerreq.getLevel()) + continue; + + // See if any prereq powers needed + boolean valid = true; + ConcurrentHashMap preqs = powerreq.getPowerReqs(); + for (Integer tok : preqs.keySet()) { + if (!powers.containsKey(tok)) + valid = false; + else { + CharacterPower cpp = powers.get(tok); if ((cpp.getTrains() + cpp.grantedTrains) < preqs.get(tok)) - valid = false; - } - } - if (!valid) - continue; - - // See if any prereq skills needed - preqs = powerreq.getSkillReqs(); - for (Integer tok : preqs.keySet()) { - if (tok == 0) - continue; - CharacterSkill found = null; - for (CharacterSkill sk : skills.values()) { - if (sk.getToken() == tok) { - found = sk; - continue; - } - } - if (found != null) { - if (found.getModifiedAmountBeforeMods() < preqs.get(tok)) - valid = false; - } else - valid = false; - } - if (!valid) - continue; - - - if (!powers.containsKey(powersBase.getToken())) { - CharacterPower newPower = new CharacterPower(powersBase, pc); - CharacterPower cp = null; - try { - cp = DbManager.CharacterPowerQueries.ADD_CHARACTER_POWER(newPower); - } catch (Exception e) { - cp = null; - } - if (cp != null){ - cp.requiredLevel = (int) powerreq.getLevel(); - powers.put(powersBase.getToken(), cp); - } - - else - Logger.error("Failed to add CharacterPower to player " + pc.getObjectUUID()); - }else{ - CharacterPower cp = powers.get(powersBase.getToken()); + valid = false; + } + } + if (!valid) + continue; + + // See if any prereq skills needed + preqs = powerreq.getSkillReqs(); + for (Integer tok : preqs.keySet()) { + if (tok == 0) + continue; + CharacterSkill found = null; + for (CharacterSkill sk : skills.values()) { + if (sk.getToken() == tok) { + found = sk; + continue; + } + } + if (found != null) { + if (found.getModifiedAmountBeforeMods() < preqs.get(tok)) + valid = false; + } else + valid = false; + } + if (!valid) + continue; + + + if (!powers.containsKey(powersBase.getToken())) { + CharacterPower newPower = new CharacterPower(powersBase, pc); + CharacterPower cp = null; + try { + cp = DbManager.CharacterPowerQueries.ADD_CHARACTER_POWER(newPower); + } catch (Exception e) { + cp = null; + } + if (cp != null) { + cp.requiredLevel = (int) powerreq.getLevel(); + powers.put(powersBase.getToken(), cp); + } else + Logger.error("Failed to add CharacterPower to player " + pc.getObjectUUID()); + } else { + CharacterPower cp = powers.get(powersBase.getToken()); if (cp != null) - if (cp.requiredLevel == 0) { - cp.requiredLevel = (int) powerreq.getLevel(); - } - } - } - } - - public static void grantTrains(PlayerCharacter pc) { - if (pc == null) - return; - ConcurrentHashMap powers = pc.getPowers(); - for (CharacterPower cp : powers.values()) { - cp.grantedTrains = cp.getGrantedTrains(pc); - } - } - - /* - * This verifies if a power is valid for a players rune - */ - private static boolean powerAllowed(Integer token, ArrayList powersGranted, PlayerCharacter pc) { - ConcurrentHashMap skills = pc.getSkills(); - ConcurrentHashMap powers = pc.getPowers(); - if (skills == null || powers == null) - return false; - for (PowerReq powerreq : powersGranted) { - PowersBase pb = powerreq.getPowersBase(); - if (pb != null) { - if (pb.getToken() == token) { - - //test level requirements - if (powerreq.getLevel() > pc.getLevel()) { - return false; - } - - //test skill requirements are met - ConcurrentHashMap skillReqs = powerreq.getSkillReqs(); - for (int tok : skillReqs.keySet()) { - boolean valid = false; - if (tok == 0) - continue; - for (CharacterSkill skill : skills.values()) { - if (skill.getToken() == tok) { - if (skill.getModifiedAmountBeforeMods() < skillReqs.get(tok)) - return false; - valid = true; - break; - } - } - if (!valid) - return false; - } - - //test power prerequisites are met - ConcurrentHashMap powerReqs = powerreq.getPowerReqs(); - for (int tok : powerReqs.keySet()) { - if (!powers.containsKey(tok)) - return false; - CharacterPower cp = powers.get(tok); - if (cp.getTotalTrains() < powerReqs.get(tok)) - return false; - } - - //everything passed. power is valid - return true; - } - } - } - return false; - } - - //This verifies the power is not blocked from refining by prereqs on other powers. - private boolean canRefine(PlayerCharacter pc) { - if (this.power == null || pc == null) - return false; - - ConcurrentHashMap powers = pc.getPowers(); - Race race = pc.getRace(); - if (race != null) { - if (!canRefine(race.getPowersGranted(), powers, pc)) - return false; - } else - return false; - BaseClass bc = pc.getBaseClass(); - if (bc != null) { - if (!canRefine(bc.getPowersGranted(), powers, pc)) - return false; - } else - return false; - PromotionClass promo = pc.getPromotionClass(); - if (promo != null) - if (!canRefine(promo.getPowersGranted(), powers, pc)) - return false; - ArrayList runes = pc.getRunes(); - if (runes != null) { - for (CharacterRune rune : runes) { - if (!canRefine(rune.getPowersGranted(), powers, pc)) - return false; - } - } - - //all tests passed. Can refine - return true; - } - - private boolean canRefine(ArrayList powersGranted, ConcurrentHashMap powers, PlayerCharacter pc) { - for (PowerReq pr : powersGranted) { - ConcurrentHashMap powerReqs = pr.getPowerReqs(); - for (int token : powerReqs.keySet()) { - if (token == this.power.getToken()) { - //this is a prereq, find the power and make sure it has enough trains - int trainsReq = (int)powerReqs.get(token); - for (CharacterPower cp : powers.values()) { + if (cp.requiredLevel == 0) { + cp.requiredLevel = (int) powerreq.getLevel(); + } + } + } + } + + public static void grantTrains(PlayerCharacter pc) { + if (pc == null) + return; + ConcurrentHashMap powers = pc.getPowers(); + for (CharacterPower cp : powers.values()) { + cp.grantedTrains = cp.getGrantedTrains(pc); + } + } + + /* + * This verifies if a power is valid for a players rune + */ + private static boolean powerAllowed(Integer token, ArrayList powersGranted, PlayerCharacter pc) { + ConcurrentHashMap skills = pc.getSkills(); + ConcurrentHashMap powers = pc.getPowers(); + if (skills == null || powers == null) + return false; + for (PowerReq powerreq : powersGranted) { + PowersBase pb = powerreq.getPowersBase(); + if (pb != null) { + if (pb.getToken() == token) { + + //test level requirements + if (powerreq.getLevel() > pc.getLevel()) { + return false; + } + + //test skill requirements are met + ConcurrentHashMap skillReqs = powerreq.getSkillReqs(); + for (int tok : skillReqs.keySet()) { + boolean valid = false; + if (tok == 0) + continue; + for (CharacterSkill skill : skills.values()) { + if (skill.getToken() == tok) { + if (skill.getModifiedAmountBeforeMods() < skillReqs.get(tok)) + return false; + valid = true; + break; + } + } + if (!valid) + return false; + } + + //test power prerequisites are met + ConcurrentHashMap powerReqs = powerreq.getPowerReqs(); + for (int tok : powerReqs.keySet()) { + if (!powers.containsKey(tok)) + return false; + CharacterPower cp = powers.get(tok); + if (cp.getTotalTrains() < powerReqs.get(tok)) + return false; + } + + //everything passed. power is valid + return true; + } + } + } + return false; + } + + public static void serializeForClientMsg(CharacterPower characterPower, ByteBufferWriter writer) { + if (characterPower.power != null) + writer.putInt(characterPower.power.getToken()); + else + writer.putInt(0); + writer.putInt(characterPower.getTrains()); + } + + public static CharacterPower getPower(int tableId) { + return DbManager.CharacterPowerQueries.GET_CHARACTER_POWER(tableId); + } + + private short getGrantedTrains(PlayerCharacter pc) { + if (this.power != null && pc != null) { + // if (this.power.isWeaponPower()) { + // SkillsBase sb = null; + // try { + // sb = SkillsBase.getSkillsBaseByName(this.power.getSkillName()); + // } catch (SQLException e) {} + // if (sb != null) { + // return pc.getBonuses().getByte("gt." + sb.getToken()); + // } else + // return pc.getBonuses().getByte("gt." + this.power.getToken()); + // } else + // return pc.getBonuses().getByte("gt." + this.power.getToken()); + return PowerGrant.getGrantedTrains(this.power.getToken(), pc); + } else + return 0; + } + + /* + * Getters + */ + public PowersBase getPower() { + return power; + } + + public int getPowerID() { + return power.getUUID(); + } + + public boolean isTrained() { + return trained; + } + + public void setTrained(boolean b) { + trained = b; + } + + public int getTrains() { + return this.trains.get(); + } + + + /* + * Utils + */ + + public short getGrantedTrains() { + return this.grantedTrains; + } + + public int getTotalTrains() { + return (this.trains.get() + this.grantedTrains); + } + + public float getTrainingCost(PlayerCharacter pc, NPC trainer) { + int charLevel = pc.getLevel(); + int skillRank = this.trains.get() - 1 + this.requiredLevel; + + + float baseCost = 50 * this.requiredLevel; //TODO GET BASE COSTS OF SKILLS. + + + float sellPercent = -4f; //NOT SELL PERCENT! + float cost; + float const5; + int const2 = 1; + float const3 = 50; + float const4 = const3 + const2; + if (charLevel > 50) + const5 = 50 / const4; + else + const5 = charLevel / const4; + + const5 = 1 - const5; + const5 = (float) (Math.log(const5) / Math.log(2) * .75f); + float rounded5 = Math.round(const5); + const5 = rounded5 - const5; + + const5 *= -1; + + const5 = (float) (Math.pow(2, const5) - 1); + + const5 += 1; + const5 = Math.scalb(const5, (int) rounded5); + const5 *= (charLevel - skillRank); + const5 *= sellPercent; + + const5 = (float) (Math.log(const5) / Math.log(2) * 3); + rounded5 = Math.round(const5); + const5 = rounded5 - const5; + const5 *= -1; + const5 = (float) (Math.pow(2, const5) - 1); + const5 += 1; + + + const5 = Math.scalb(const5, (int) rounded5); + const5 += 1; + cost = const5 * baseCost; + + + if (Float.isNaN(cost)) + cost = baseCost; + return cost; + } + + public synchronized boolean train(PlayerCharacter pc) { + if (pc == null || this.power == null) + return false; + + //see if any prereqs to train this power is met + if (!canTrain(pc)) + return false; + + boolean succeeded = true; + int oldTrains = this.trains.get(); + int tr = oldTrains + this.grantedTrains; + if (pc.getTrainsAvailable() <= 0) + return false; + if (tr == this.power.getMaxTrains()) //at max, stop here + return false; + else if (tr > this.power.getMaxTrains()) //catch incase we somehow go over + this.trains.set((this.power.getMaxTrains() - this.grantedTrains)); + else //add the train + succeeded = this.trains.compareAndSet(oldTrains, oldTrains + 1); + + if (this.trains.get() > this.power.getMaxTrains()) { //double check not over max trains + this.trains.set(this.power.getMaxTrains()); + succeeded = false; + } + + if (succeeded) { + this.trained = true; + + //update database + pc.addDatabaseJob("Skills", MBServerStatics.THIRTY_SECONDS); + + //subtract from trains available + pc.modifyTrainsAvailable(-1); + + pc.calculateSkills(); + return true; + } else + return false; + } + + public boolean reset(PlayerCharacter pc) { + if (pc == null || this.power == null) + return false; + + //see if any prereqs to refine this power is met + + boolean succeeded = true; + int oldTrains = this.trains.get(); + int tr = oldTrains + this.grantedTrains; + if (oldTrains < 1) + return false; + else //subtract the train + succeeded = this.trains.compareAndSet(oldTrains, 0); + if (succeeded) { + this.trained = true; + + //update database + pc.addDatabaseJob("Skills", MBServerStatics.THIRTY_SECONDS); + + //subtract from trains available + pc.modifyTrainsAvailable(oldTrains); + + pc.calculateSkills(); + return true; + } else + return false; + } + + public boolean refine(PlayerCharacter pc) { + if (pc == null || this.power == null) + return false; + + //see if any prereqs to refine this power is met + if (!canRefine(pc)) + return false; + + boolean succeeded = true; + int oldTrains = this.trains.get(); + int tr = oldTrains + this.grantedTrains; + if (oldTrains < 1) + return false; + else //subtract the train + succeeded = this.trains.compareAndSet(oldTrains, oldTrains - 1); + if (succeeded) { + this.trained = true; + + //update database + pc.addDatabaseJob("Skills", MBServerStatics.THIRTY_SECONDS); + + //subtract from trains available + pc.modifyTrainsAvailable(1); + + pc.calculateSkills(); + return true; + } else + return false; + } + + //This verifies the power is not blocked from refining by prereqs on other powers. + private boolean canRefine(PlayerCharacter pc) { + if (this.power == null || pc == null) + return false; + + ConcurrentHashMap powers = pc.getPowers(); + Race race = pc.getRace(); + if (race != null) { + if (!canRefine(race.getPowersGranted(), powers, pc)) + return false; + } else + return false; + BaseClass bc = pc.getBaseClass(); + if (bc != null) { + if (!canRefine(bc.getPowersGranted(), powers, pc)) + return false; + } else + return false; + PromotionClass promo = pc.getPromotionClass(); + if (promo != null) + if (!canRefine(promo.getPowersGranted(), powers, pc)) + return false; + ArrayList runes = pc.getRunes(); + if (runes != null) { + for (CharacterRune rune : runes) { + if (!canRefine(rune.getPowersGranted(), powers, pc)) + return false; + } + } + + //all tests passed. Can refine + return true; + } + + /* + * Serializing + */ + + private boolean canRefine(ArrayList powersGranted, ConcurrentHashMap powers, PlayerCharacter pc) { + for (PowerReq pr : powersGranted) { + ConcurrentHashMap powerReqs = pr.getPowerReqs(); + for (int token : powerReqs.keySet()) { + if (token == this.power.getToken()) { + //this is a prereq, find the power and make sure it has enough trains + int trainsReq = (int) powerReqs.get(token); + for (CharacterPower cp : powers.values()) { if (cp.power.getToken() == pr.getToken()) { - if (this.getTotalTrains() <= trainsReq && cp.getTrains() > 0) { + if (this.getTotalTrains() <= trainsReq && cp.getTrains() > 0) { ErrorPopupMsg.sendErrorMsg(pc, "You must refine " + cp.power.getName() + " to 0 before refining any more from this power."); - return false; - } - } - } - } - } - } - - return true; - } - - private boolean canTrain(PlayerCharacter pc) { - if (this.power == null || pc == null) - return false; - int token = this.power.getToken(); - boolean valid = false; - Race race = pc.getRace(); - if (race != null) { - if (CharacterPower.powerAllowed(token, race.getPowersGranted(), pc)) - return true; - } else - return false; - BaseClass bc = pc.getBaseClass(); - if (bc != null) { - if (CharacterPower.powerAllowed(token, bc.getPowersGranted(), pc)) - return true; - } else - return false; - PromotionClass promo = pc.getPromotionClass(); - if (promo != null) - if (CharacterPower.powerAllowed(token, promo.getPowersGranted(), pc)) - return true; - ArrayList runes = pc.getRunes(); - for (CharacterRune rune : runes) - if (CharacterPower.powerAllowed(token, rune.getPowersGranted(), pc)) - return true; - return false; - } - - /* - * Serializing - */ - - public static void serializeForClientMsg(CharacterPower characterPower, ByteBufferWriter writer) { - if (characterPower.power != null) - writer.putInt(characterPower.power.getToken()); - else - writer.putInt(0); - writer.putInt(characterPower.getTrains()); - } - - public static CharacterPower getPower(int tableId) { - return DbManager.CharacterPowerQueries.GET_CHARACTER_POWER(tableId); - } - - @Override - public void updateDatabase() { - DbManager.CharacterPowerQueries.updateDatabase(this); - } - - public int getRequiredLevel() { - return requiredLevel; - } - - public void setRequiredLevel(int requiredLevel) { - this.requiredLevel = requiredLevel; - } + return false; + } + } + } + } + } + } + + return true; + } + + private boolean canTrain(PlayerCharacter pc) { + if (this.power == null || pc == null) + return false; + int token = this.power.getToken(); + boolean valid = false; + Race race = pc.getRace(); + if (race != null) { + if (CharacterPower.powerAllowed(token, race.getPowersGranted(), pc)) + return true; + } else + return false; + BaseClass bc = pc.getBaseClass(); + if (bc != null) { + if (CharacterPower.powerAllowed(token, bc.getPowersGranted(), pc)) + return true; + } else + return false; + PromotionClass promo = pc.getPromotionClass(); + if (promo != null) + if (CharacterPower.powerAllowed(token, promo.getPowersGranted(), pc)) + return true; + ArrayList runes = pc.getRunes(); + for (CharacterRune rune : runes) + if (CharacterPower.powerAllowed(token, rune.getPowersGranted(), pc)) + return true; + return false; + } + + @Override + public void updateDatabase() { + DbManager.CharacterPowerQueries.updateDatabase(this); + } + + public int getRequiredLevel() { + return requiredLevel; + } + + public void setRequiredLevel(int requiredLevel) { + this.requiredLevel = requiredLevel; + } } diff --git a/src/engine/objects/CharacterRune.java b/src/engine/objects/CharacterRune.java index 0eb40073..c9e10e66 100644 --- a/src/engine/objects/CharacterRune.java +++ b/src/engine/objects/CharacterRune.java @@ -23,189 +23,189 @@ import java.util.ArrayList; public class CharacterRune extends AbstractGameObject { - private final RuneBase runeBase; - private final int player; - private final ArrayList skillsGranted; - private final ArrayList powersGranted; - private final ArrayList effectsGranted; - - /** - * No Table ID Constructor - */ - public CharacterRune(RuneBase runeBase, int characterID) { - super(); - this.runeBase = runeBase; - this.player = characterID; - if (this.runeBase != null) { - this.skillsGranted = DbManager.SkillReqQueries.GET_REQS_FOR_RUNE(this.runeBase.getObjectUUID()); - this.powersGranted = PowerReq.getPowerReqsForRune(this.runeBase.getObjectUUID()); - } else { - this.skillsGranted = new ArrayList<>(); - this.powersGranted = new ArrayList<>(); - } - if (this.runeBase != null) - this.effectsGranted = DbManager.RuneBaseEffectQueries.GET_EFFECTS_FOR_RUNEBASE(this.runeBase.getObjectUUID()); - else - this.effectsGranted = new ArrayList<>(); - } - - /** - * Normal Constructor - */ - public CharacterRune(RuneBase runeBase, int characterID, int newUUID) { - super(newUUID); - this.runeBase = runeBase; - this.player = characterID; - if (this.runeBase != null) { - this.skillsGranted = DbManager.SkillReqQueries.GET_REQS_FOR_RUNE(this.runeBase.getObjectUUID()); - this.powersGranted = PowerReq.getPowerReqsForRune(this.runeBase.getObjectUUID()); - } else { - this.skillsGranted = new ArrayList<>(); - this.powersGranted = new ArrayList<>(); - } - if (this.runeBase != null) - this.effectsGranted = DbManager.RuneBaseEffectQueries.GET_EFFECTS_FOR_RUNEBASE(this.runeBase.getObjectUUID()); - else - this.effectsGranted = new ArrayList<>(); - } - - /** - * ResultSet Constructor - */ - public CharacterRune(ResultSet rs) throws SQLException { - super(rs); - - this.runeBase = RuneBase.getRuneBase(rs.getInt("RuneBaseID")); - this.player = rs.getInt("CharacterID"); - if (this.runeBase != null) { - this.skillsGranted = DbManager.SkillReqQueries.GET_REQS_FOR_RUNE(this.runeBase.getObjectUUID()); - this.powersGranted = PowerReq.getPowerReqsForRune(this.runeBase.getObjectUUID()); - this.effectsGranted = DbManager.RuneBaseEffectQueries.GET_EFFECTS_FOR_RUNEBASE(this.runeBase.getObjectUUID()); - } else { - Logger.error("Failed to find RuneBase for CharacterRune " + this.getObjectUUID()); - this.skillsGranted = new ArrayList<>(); - this.powersGranted = new ArrayList<>(); - this.effectsGranted = new ArrayList<>(); - } - } - - /* - * Getters - */ - public RuneBase getRuneBase() { - return this.runeBase; - } - - public int getRuneBaseID() { - if (this.runeBase != null) - return this.runeBase.getObjectUUID(); - return 0; - } - - public int getPlayerID() { - return this.player; - } - - public ArrayList getSkillsGranted() { - return this.skillsGranted; - } - - public ArrayList getPowersGranted() { - return this.powersGranted; - } - - public ArrayList getEffectsGranted() { - return this.effectsGranted; - } - - /* - * Serializing - */ - - public static void serializeForClientMsg(CharacterRune characterRune, ByteBufferWriter writer) { - if (characterRune.runeBase != null) { - int idd = characterRune.runeBase.getObjectUUID(); - if (idd > 3000 && idd < 3050) - writer.putInt(4); - else - writer.putInt(5); - // writer.putInt(this.runeBase.getMessageType()); - writer.putInt(0); - writer.putInt(characterRune.runeBase.getObjectUUID()); - writer.putInt(characterRune.getObjectType().ordinal()); - writer.putInt(characterRune.getObjectUUID()); - } else { - for (int i = 0; i < 5; i++) - writer.putInt(0); - } - } - - public static boolean grantRune(PlayerCharacter pc, int runeID) { - //Verify not too many runes - ArrayList runes = pc.getRunes(); - boolean worked = false; - synchronized (runes) { - if (runes == null || runes.size() > 12) - return false; - - //Verify player doesn't already have rune - for (CharacterRune rune : runes) { + private final RuneBase runeBase; + private final int player; + private final ArrayList skillsGranted; + private final ArrayList powersGranted; + private final ArrayList effectsGranted; + + /** + * No Table ID Constructor + */ + public CharacterRune(RuneBase runeBase, int characterID) { + super(); + this.runeBase = runeBase; + this.player = characterID; + if (this.runeBase != null) { + this.skillsGranted = DbManager.SkillReqQueries.GET_REQS_FOR_RUNE(this.runeBase.getObjectUUID()); + this.powersGranted = PowerReq.getPowerReqsForRune(this.runeBase.getObjectUUID()); + } else { + this.skillsGranted = new ArrayList<>(); + this.powersGranted = new ArrayList<>(); + } + if (this.runeBase != null) + this.effectsGranted = DbManager.RuneBaseEffectQueries.GET_EFFECTS_FOR_RUNEBASE(this.runeBase.getObjectUUID()); + else + this.effectsGranted = new ArrayList<>(); + } + + /** + * Normal Constructor + */ + public CharacterRune(RuneBase runeBase, int characterID, int newUUID) { + super(newUUID); + this.runeBase = runeBase; + this.player = characterID; + if (this.runeBase != null) { + this.skillsGranted = DbManager.SkillReqQueries.GET_REQS_FOR_RUNE(this.runeBase.getObjectUUID()); + this.powersGranted = PowerReq.getPowerReqsForRune(this.runeBase.getObjectUUID()); + } else { + this.skillsGranted = new ArrayList<>(); + this.powersGranted = new ArrayList<>(); + } + if (this.runeBase != null) + this.effectsGranted = DbManager.RuneBaseEffectQueries.GET_EFFECTS_FOR_RUNEBASE(this.runeBase.getObjectUUID()); + else + this.effectsGranted = new ArrayList<>(); + } + + /** + * ResultSet Constructor + */ + public CharacterRune(ResultSet rs) throws SQLException { + super(rs); + + this.runeBase = RuneBase.getRuneBase(rs.getInt("RuneBaseID")); + this.player = rs.getInt("CharacterID"); + if (this.runeBase != null) { + this.skillsGranted = DbManager.SkillReqQueries.GET_REQS_FOR_RUNE(this.runeBase.getObjectUUID()); + this.powersGranted = PowerReq.getPowerReqsForRune(this.runeBase.getObjectUUID()); + this.effectsGranted = DbManager.RuneBaseEffectQueries.GET_EFFECTS_FOR_RUNEBASE(this.runeBase.getObjectUUID()); + } else { + Logger.error("Failed to find RuneBase for CharacterRune " + this.getObjectUUID()); + this.skillsGranted = new ArrayList<>(); + this.powersGranted = new ArrayList<>(); + this.effectsGranted = new ArrayList<>(); + } + } + + public static void serializeForClientMsg(CharacterRune characterRune, ByteBufferWriter writer) { + if (characterRune.runeBase != null) { + int idd = characterRune.runeBase.getObjectUUID(); + if (idd > 3000 && idd < 3050) + writer.putInt(4); + else + writer.putInt(5); + // writer.putInt(this.runeBase.getMessageType()); + writer.putInt(0); + writer.putInt(characterRune.runeBase.getObjectUUID()); + writer.putInt(characterRune.getObjectType().ordinal()); + writer.putInt(characterRune.getObjectUUID()); + } else { + for (int i = 0; i < 5; i++) + writer.putInt(0); + } + } + + public static boolean grantRune(PlayerCharacter pc, int runeID) { + //Verify not too many runes + ArrayList runes = pc.getRunes(); + boolean worked = false; + synchronized (runes) { + if (runes == null || runes.size() > 12) + return false; + + //Verify player doesn't already have rune + for (CharacterRune rune : runes) { RuneBase rb = rune.runeBase; - if (rb == null || rb.getObjectUUID() == runeID) - return false; - } - - RuneBase rb = RuneBase.getRuneBase(runeID); - if (rb == null) - return false; - - //Attempt to add rune to database - CharacterRune toAdd = new CharacterRune(rb, pc.getObjectUUID()); - CharacterRune rune = null; - try { - rune = DbManager.CharacterRuneQueries.ADD_CHARACTER_RUNE(toAdd); - } catch (Exception e) { - return false; - } - if (rune == null) - return false; - - //attempt add rune to player - worked = pc.addRune(rune); - - //worked, send ApplyRuneMsg - if (worked) { - ApplyRuneMsg arm = new ApplyRuneMsg(pc.getObjectType().ordinal(), pc.getObjectUUID(), runeID, rune.getObjectType().ordinal(), rune.getObjectUUID(), true); - DispatchMessage.dispatchMsgToInterestArea(pc, arm, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - CharacterSkill.calculateSkills(pc); - pc.applyBonuses(); - return true; - } else - return false; - } - - } - - public static boolean removeRune(PlayerCharacter pc, int runeID) { - ArrayList runes = pc.getRunes(); - synchronized (runes) { - for (CharacterRune rune : runes) { + if (rb == null || rb.getObjectUUID() == runeID) + return false; + } + + RuneBase rb = RuneBase.getRuneBase(runeID); + if (rb == null) + return false; + + //Attempt to add rune to database + CharacterRune toAdd = new CharacterRune(rb, pc.getObjectUUID()); + CharacterRune rune = null; + try { + rune = DbManager.CharacterRuneQueries.ADD_CHARACTER_RUNE(toAdd); + } catch (Exception e) { + return false; + } + if (rune == null) + return false; + + //attempt add rune to player + worked = pc.addRune(rune); + + //worked, send ApplyRuneMsg + if (worked) { + ApplyRuneMsg arm = new ApplyRuneMsg(pc.getObjectType().ordinal(), pc.getObjectUUID(), runeID, rune.getObjectType().ordinal(), rune.getObjectUUID(), true); + DispatchMessage.dispatchMsgToInterestArea(pc, arm, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + CharacterSkill.calculateSkills(pc); + pc.applyBonuses(); + return true; + } else + return false; + } + + } + + public static boolean removeRune(PlayerCharacter pc, int runeID) { + ArrayList runes = pc.getRunes(); + synchronized (runes) { + for (CharacterRune rune : runes) { RuneBase rb = rune.runeBase; - if (rb == null) - continue; - if (rb.getObjectUUID() == runeID && DbManager.CharacterRuneQueries.DELETE_CHARACTER_RUNE(rune)) { - runes.remove(runes.indexOf(rune)); - CharacterSkill.calculateSkills(pc); - pc.applyBonuses(); - return true; - } - } - return false; - } - } - - @Override - public void updateDatabase() { - DbManager.CharacterRuneQueries.updateDatabase(this); - } + if (rb == null) + continue; + if (rb.getObjectUUID() == runeID && DbManager.CharacterRuneQueries.DELETE_CHARACTER_RUNE(rune)) { + runes.remove(runes.indexOf(rune)); + CharacterSkill.calculateSkills(pc); + pc.applyBonuses(); + return true; + } + } + return false; + } + } + + /* + * Getters + */ + public RuneBase getRuneBase() { + return this.runeBase; + } + + public int getRuneBaseID() { + if (this.runeBase != null) + return this.runeBase.getObjectUUID(); + return 0; + } + + public int getPlayerID() { + return this.player; + } + + /* + * Serializing + */ + + public ArrayList getSkillsGranted() { + return this.skillsGranted; + } + + public ArrayList getPowersGranted() { + return this.powersGranted; + } + + public ArrayList getEffectsGranted() { + return this.effectsGranted; + } + + @Override + public void updateDatabase() { + DbManager.CharacterRuneQueries.updateDatabase(this); + } } diff --git a/src/engine/objects/CharacterSkill.java b/src/engine/objects/CharacterSkill.java index e2179392..a4cb9588 100644 --- a/src/engine/objects/CharacterSkill.java +++ b/src/engine/objects/CharacterSkill.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.objects; import engine.Enum; @@ -28,1221 +27,1211 @@ import java.util.concurrent.atomic.AtomicInteger; public class CharacterSkill extends AbstractGameObject { - private static final int[] maxTrains = { - 29, 29, 29, 29, 29, //0 to 4 - 29, 32, 34, 36, 38, //5 to 9 - 40, 42, 43, 45, 47, //10 to 14 - 48, 49, 51, 52, 53, //15 to 19 - 55, 56, 57, 58, 59, //20 to 24 - 60, 62, 63, 64, 65, //25 to 29 - 66, 67, 68, 68, 69, //30 to 34 - 70, 71, 72, 73, 74, //35 to 39 - 75, 76, 76, 77, 78, //40 to 44 - 79, 80, 80, 81, 82, //45 to 49 - 83, 83, 84, 85, 85, //50 to 54 - 86, 87, 88, 88, 89, //55 to 59 - 90, 90, 91, 92, 92, //60 to 64 - 93, 94, 94, 95, 95, //65 to 69 - 96, 97, 97, 98, 99, //70 to 74 - 99, 100, 100, 101, 101, //75 to 79 - 102, 103, 103, 104, 104, //80 to 84 - 105, 105, 106, 106, 107, //85 to 89 - 108, 109, 109, 110, 110, //90 to 94 - 111, 112, 112, 113, 113, //95 to 99 - 114, 115, 115, 116, 116, //100 to 104 - 117, 118, 118, 119, 119, //105 to 109 - 120, 121, 121, 122, 122, //110 to 114 - 123, 124, 124, 125, 125, //115 to 119 - 126, 127, 127, 128, 128, //120 to 124 - 129, 130, 130, 131, 131, //125 to 129 - 132, 133, 133, 134, 134, //130 to 134 - 135, 136, 136, 137, 137, //135 to 139 - 138, 139, 139, 140, 140, //140 to 144 - 141, 142, 142, 143, 143, //145 to 149 - 144, 145, 145, 146, 146, //150 to 154 - 147, 148, 148, 149, 149, //155 to 159 - 150, 151, 151, 152, 152, //160 to 164 - 153, 154, 154, 155, 155, //165 to 169 - 156, 157, 157, 158, 158, //170 to 174 - 159, 160, 160, 161, 161, //175 to 179 - 162, 163, 163, 164, 164, //180 to 184 - 165, 166, 166, 167, 167, //185 to 189 - 168}; //190 - - private static final float[] baseSkillValues = { - 0.0f, 0.0f, 0.2f, 0.4f, 0.6f, //0 to 4 - 0.8f, 1.0f, 1.1666666f, 1.3333334f, 1.5f, //5 to 9 - 1.6666667f, 1.8333334f, 2.0f, 2.2f, 2.4f, //10 to 14 - 2.6f, 2.8f, 3.0f, 3.2f, 3.4f, //15 to 19 - 3.6f, 3.8f, 4.0f, 4.2f, 4.4f, //20 to 24 - 4.6f, 4.8f, 5.0f, 5.25f, 5.5f, //25 to 29 - 5.75f, 6.0f, 6.2f, 6.4f, 6.6f, //30 to 34 - 6.8f, 7.0f, 7.25f, 7.5f, 7.75f, //35 to 39 - 8.0f, 8.2f, 8.4f, 8.6f, 8.8f, //40 to 44 - 9.0f, 9.25f, 9.5f, 9.75f, 10.0f, //45 to 49 - 10.25f, 10.5f, 10.75f, 11.0f, 11.2f, //50 to 54 - 11.4f, 11.6f, 11.8f, 12.0f, 12.25f, //55 to 59 - 12.5f, 12.75f, 13.0f, 13.25f, 13.5f, //60 to 64 - 13.75f, 14.0f, 14.25f, 14.5f, 14.75f, //65 to 69 - 15.0f, 15.333333f, 15.666667f, 16.0f, 16.25f, //70 to 74 - 16.5f, 16.75f, 17.0f, 17.25f, 17.5f, //75 to 79 - 17.75f, 18.0f, 18.25f, 18.5f, 18.75f, //80 to 84 - 19.0f, 19.333334f, 19.666666f, 20.0f, 20.25f, //85 to 89 - 20.5f, 20.75f, 21.0f, 21.25f, 21.5f, //90 to 94 - 21.75f, 22.0f, 22.333334f, 22.666666f, 23.0f, //95 to 99 - 23.25f, 23.5f, 23.75f, 24.0f, 24.333334f, //100 to 104 - 24.666666f, 25.0f, 25.25f, 25.5f, 25.75f, //105 to 109 - 26.0f, 26.333334f, 26.666666f, 27.0f, 27.333334f, //110 to 114 - 27.666666f, 28.0f, 28.25f, 28.5f, 28.75f, //115 to 119 - 29.0f, 29.333334f, 29.666666f, 30.0f, 30.333334f, //120 to 124 - 30.666666f, 31.0f, 31.25f, 31.5f, 31.75f, //125 to 129 - 32.0f, 32.333332f, 32.666668f, 33.0f, 33.333332f, //130 to 134 - 33.666668f, 34.0f, 34.333332f, 34.666668f, 35.0f, //135 to 139 - 35.333332f, 35.666668f, 36.0f, 36.333332f, 36.666668f, //140 to 144 - 37.0f, 37.25f, 37.5f, 37.75f, 38.0f, //145 to 149 - 38.333332f, 38.666668f, 39.0f, 39.333332f, 39.666668f, //150 to 154 - 40.0f, 40.333332f, 40.666668f, 41.0f, 41.333332f, //155 to 159 - 41.666668f, 42.0f, 42.333332f, 42.666668f, 43.0f, //160 to 164 - 43.333332f, 43.666668f, 44.0f, 44.333332f, 44.666668f, //165 to 169 - 45.0f, 45.5f, 46.0f, 46.333332f, 46.666668f, //170 to 174 - 47.0f, 47.333332f, 47.666668f, 48.0f, 48.333332f, //175 to 179 - 48.666668f, 49.0f, 49.333332f, 49.666668f, 50.0f, //180 to 184 - 50.333332f, 50.666668f, 51.0f, 51.333332f, 51.666668f, //185 to 189 - 52.0f, 52.5f, 53.0f, 53.333332f, 53.666668f, //190 to 194 - 54.0f, 54.333332f, 54.666668f, 55.0f, 55.333332f, //195 to 199 - 55.666668f, 56.0f, 56.333332f, 56.666668f, 57.0f, //200 to 204 - 57.5f, 58.0f, 58.333332f, 58.666668f, 59.0f, //205 to 209 - 59.333332f, 59.666668f, 60.0f, 60.5f, 61.0f, //210 to 214 - 61.333332f, 61.666668f, 62.0f, 62.333332f, 62.666668f, //215 to 219 - 63.0f, 63.5f, 64.0f, 64.333336f, 64.666664f, //220 to 224 - 65.0f, 65.333336f, 65.666664f, 66.0f, 66.5f, //225 to 229 - 67.0f, 67.333336f, 67.666664f, 68.0f, 68.5f, //230 to 234 - 69.0f, 69.333336f, 69.666664f, 70.0f, 70.333336f, //235 to 239 - 70.666664f, 71.0f, 71.5f, 72.0f, 72.5f, //240 to 244 - 73.0f, 73.333336f, 73.666664f, 74.0f, 74.333336f, //245 to 249 - 74.666664f, 75.0f, 75.5f, 76.0f, 76.333336f, //250 to 254 - 76.666664f, 77.0f, 77.5f, 78.0f, 78.333336f, //255 to 259 - 78.666664f, 79.0f, 79.5f, 80.0f, 80.333336f, //260 to 264 - 80.666664f, 81.0f, 81.5f, 82.0f, 82.333336f, //265 to 269 - 82.666664f, 83.0f, 83.5f, 84.0f, 84.333336f, //270 to 274 - 84.666664f, 85.0f, 85.5f, 86.0f, 86.5f, //275 to 279 - 87.0f, 87.333336f, 87.666664f, 88.0f, 88.5f, //280 to 284 - 89.0f, 89.333336f, 89.666664f, 90.0f, 90.5f, //285 to 289 - 91.0f, 91.5f, 92.0f, 92.333336f, 92.666664f, //290 to 294 - 93.0f, 93.5f, 94.0f, 94.5f, 95.0f, //295 to 299 - 95.333336f, 95.666664f, 96.0f, 96.5f, 97.0f, //300 to 304 - 97.5f, 98.0f, 98.333336f, 98.666664f, 99.0f, //305 to 309 - 99.5f, 100.0f, 100.5f, 101.0f, 101.5f, //310 to 314 - 102.0f, 102.5f, 103.0f, 103.333336f, 103.666664f, //315 to 319 - 104.0f, 104.333336f, 104.666664f, 105.0f, 105.5f, //320 to 324 - 106.0f, 106.5f, 107.0f, 108.0f, 108.333336f, //325 to 329 - 108.666664f, 109.0f, 109.333336f, 109.666664f, 110.0f, //330 to 334 - 110.5f, 111.0f, 111.5f, 112.0f, 112.5f, //335 to 339 - 113.0f, 113.333336f, 113.666664f, 114.0f, 114.5f, //340 to 344 - 115.0f, 115.5f, 116.0f, 116.5f, 117.0f, //345 to 349 - 117.5f, 118.0f, 118.333336f, 118.666664f, 119.0f, //350 to 354 - 119.5f, 120.0f, 120.5f, 121.0f, 121.5f, //355 to 359 - 122.0f, 122.5f, 123.0f, 123.333336f, 123.666664f, //360 to 364 - 124.0f, 124.5f, 125.0f, 125.5f, 126.0f, //365 to 369 - 126.5f, 127.0f, 127.5f, 128.0f, 128.5f, //370 to 374 - 129.0f, 129.5f, 130.0f, 130.33333f, 130.66667f, //375 to 379 - 131.0f, 131.5f, 132.0f, 132.5f, 133.0f, //380 to 384 - 133.5f, 134.0f, 134.5f, 135.0f, 135.5f, //385 to 389 - 136.0f, 136.5f, 137.0f, 137.5f, 138.0f, //390 to 394 - 138.5f, 139.0f, 139.5f, 140.0f, 140.33333f, //395 to 399 - 140.66667f, 141.0f, 141.5f, 142.0f, 142.5f, //400 to 404 - 143.0f, 143.5f, 144.0f, 144.5f, 145.0f, //405 to 409 - 145.5f, 146.0f, 146.5f, 147.0f, 147.5f, //410 to 414 - 148.0f, 148.5f, 149.0f, 149.5f, 150.0f, //415 to 419 - 150.5f, 151.0f, 151.5f, 152.0f, 152.5f, //420 to 424 - 153.0f, 153.5f, 154.0f, 154.5f, 155.0f, //425 to 429 - 155.5f, 156.0f, 156.5f, 157.0f, 157.5f, //430 to 434 - 158.0f, 158.5f, 159.0f, 159.5f, 160.0f, //435 to 439 - 160.5f, 161.0f, 161.5f, 162.0f, 162.5f, //440 to 444 - 163.0f, 163.5f, 164.0f, 164.5f, 165.0f, //445 to 449 - 165.5f, 166.0f, 166.5f, 167.0f, 167.5f, //450 to 454 - 168.0f, 168.5f, 169.0f, 169.5f, 170.0f, //455 to 459 - 170.5f, 171.0f, 171.5f, 172.0f, 172.5f, //460 to 464 - 173.0f, 173.5f, 174.0f, 174.5f, 175.0f, //465 to 469 - 176.0f, 176.5f, 177.0f, 177.5f, 178.0f, //470 to 474 - 178.5f, 179.0f, 179.5f, 180.0f, 180.5f, //475 to 479 - 181.0f, 181.5f, 182.0f, 182.5f, 183.0f, //480 to 484 - 183.5f, 184.0f, 184.5f, 185.0f, 185.5f, //485 to 489 - 186.0f, 187.0f, 187.5f, 188.0f, 188.5f, //490 to 494 - 189.0f, 189.5f, 190.0f, 190.5f, 191.0f, //495 to 499 - 191.5f, 192.0f, 192.5f, 193.0f, 193.5f, //500 to 504 - 194.0f, 194.5f, 195.0f, 196.0f, 196.5f, //505 to 509 - 197.0f, 197.5f, 198.0f, 198.5f, 199.0f, //510 to 514 - 199.5f, 200.0f, 200.5f, 201.0f, 201.5f, //515 to 519 - 202.0f, 203.0f, 203.5f, 204.0f, 204.5f, //520 to 524 - 205.0f, 205.5f, 206.0f, 206.5f, 207.0f, //525 to 529 - 207.5f, 208.0f, 209.0f, 209.5f, 210.0f, //530 to 534 - 210.5f, 211.0f, 211.5f, 212.0f, 212.5f, //535 to 539 - 213.0f, 214.0f, 214.5f, 215.0f, 215.5f, //540 to 544 - 216.0f, 216.5f, 217.0f, 217.5f, 218.0f, //545 to 549 - 218.5f, 219.0f, 220.0f, 220.5f, 221.0f, //550 to 554 - 221.5f, 222.0f, 222.5f, 223.0f, 224.0f, //555 to 559 - 224.5f, 225.0f, 225.5f, 226.0f, 226.5f, //560 to 564 - 227.0f, 227.5f, 228.0f, 229.0f, 229.5f, //565 to 569 - 230.0f, 230.5f, 231.0f, 231.5f, 232.0f, //570 to 574 - 233.0f, 233.5f, 234.0f, 234.5f, 235.0f, //575 to 579 - 235.5f, 236.0f, 237.0f, 237.5f, 238.0f, //580 to 584 - 238.5f, 239.0f, 239.5f, 240.0f, 241.0f, //585 to 589 - 241.5f, 242.0f, 242.5f, 243.0f, 243.5f, //590 to 594 - 244.0f, 245.0f, 245.5f, 246.0f, 246.5f, //595 to 599 - 247.0f}; //600 - - - private SkillsBase skillsBase; - private AtomicInteger numTrains = new AtomicInteger(); - - private CharacterSkills skillType; - - //Skill% before trains and before any effects or item bonuses - private float baseAmountBeforeMods; - - //Skill% after trains but before any effects or item bonuses - private float modifiedAmountBeforeMods; - private boolean isMobOwner = false; - - //Skill% before trains but after any effects or item bonuses - private float baseAmount; - - //Skill% after trains and after any effects or item bonuses - private float modifiedAmount; - - private int ownerUID; - private boolean trained = false; - private int requiredLevel = 0; - - /** - * No Table ID Constructor - */ - public CharacterSkill(SkillsBase skillsBase, PlayerCharacter pc) { - super(); - this.skillsBase = skillsBase; - this.numTrains.set(0); - this.ownerUID = pc.getObjectUUID(); - calculateBaseAmount(); - calculateModifiedAmount(); - this.skillType = CharacterSkills.GetCharacterSkillByToken(this.skillsBase.getToken()); - } - - /** - * Normal Constructor - */ - public CharacterSkill(SkillsBase skillsBase, PlayerCharacter pc, int newUUID) { - - super(newUUID); - this.skillsBase = skillsBase; - this.numTrains.set(0); - this.ownerUID = pc.getObjectUUID(); - this.trained = true; - calculateBaseAmount(); - calculateModifiedAmount(); - this.skillType = CharacterSkills.GetCharacterSkillByToken(this.skillsBase.getToken()); - - } - - /** - * ResultSet Constructor - */ - public CharacterSkill(ResultSet rs, PlayerCharacter pc) throws SQLException { - super(rs); - - int skillsBaseID = rs.getInt("SkillsBaseID"); - this.skillsBase = DbManager.SkillsBaseQueries.GET_BASE(skillsBaseID); - this.numTrains.set(rs.getShort("trains")); - this.ownerUID = pc.getObjectUUID(); - calculateBaseAmount(); - calculateModifiedAmount(); - this.skillType = CharacterSkills.GetCharacterSkillByToken(this.skillsBase.getToken()); - } - - public CharacterSkill(SkillsBase sb, Mob mob, int trains) { - super(); - this.skillsBase = sb; - this.numTrains.set(trains); - this.ownerUID = mob.getObjectUUID(); - this.isMobOwner = true; - calculateMobBaseAmount(); - calculateModifiedAmount(); - this.skillType = CharacterSkills.GetCharacterSkillByToken(this.skillsBase.getToken()); - } - - public CharacterSkill(ResultSet rs) throws SQLException { - super(rs); - int skillsBaseID = rs.getInt("SkillsBaseID"); - this.skillsBase = DbManager.SkillsBaseQueries.GET_BASE(skillsBaseID); - this.numTrains.set(rs.getShort("trains")); - this.ownerUID = rs.getInt("CharacterID"); - // this.owner = DbManager.PlayerCharacterQueries.GET_PLAYER_CHARACTER(rs.getInt("CharacterID")); - calculateBaseAmount(); - calculateModifiedAmount(); - this.skillType = CharacterSkills.GetCharacterSkillByToken(this.skillsBase.getToken()); - } - - public static AbstractCharacter GetOwner(CharacterSkill cs){ - if (cs.ownerUID == 0) - return null; - if (cs.isMobOwner) - return Mob.getFromCache(cs.ownerUID); - else - return PlayerCharacter.getFromCache(cs.ownerUID); - } - - /* - * Getters - */ - - public static float getATR(AbstractCharacter ac, String name) { - if (ac == null) - return 0f; - float atr; - ConcurrentHashMap skills = ac.getSkills(); - CharacterSkill skill = skills.get(name); - if (skill != null) - atr = skill.getATR(ac); - else { - float mast = CharacterSkill.getQuickMastery(ac, name); - atr = (((int)mast * 7) + (ac.getStatDexCurrent() / 2)); - } - //apply effect mods - PlayerBonuses bonus = ac.getBonuses(); - if (bonus == null) - return atr; - atr += bonus.getFloat(ModType.OCV, SourceType.None); - float pos_Bonus = bonus.getFloatPercentPositive(ModType.OCV, SourceType.None); - atr *= (1 + pos_Bonus); - //rUNES will already be applied - // atr *= (1 + ((float)bonus.getShort("rune.Attack") / 100)); //precise - float neg_Bonus = bonus.getFloatPercentNegative(ModType.OCV, SourceType.None); - atr *= (1 +neg_Bonus); - return atr; - } - - private float getATR(AbstractCharacter ac) { - return (((int)this.modifiedAmount * 7) + (ac.getStatDexCurrent() / 2)); - } - - public synchronized boolean train(PlayerCharacter pc) { - if (pc == null || this.skillsBase == null) - return false; - - boolean running = false; - - //trying out a table lookup - int intt = (int) pc.statIntBase; - int maxTrains = 0; - if (intt > 0 && intt < 191) - maxTrains = CharacterSkill.maxTrains[intt]; - else - maxTrains = (int)(33 + 1.25 * (int) pc.statIntBase - 0.005 * Math.pow((int) pc.statIntBase, 2)); - - - int oldTrains = this.numTrains.get(); - boolean succeeded = true; - if (pc.getTrainsAvailable() <= 0) - return false; - if (oldTrains == maxTrains) //at gold, stop here - return false; - else if (oldTrains > maxTrains) //catch incase we somehow go over - this.numTrains.set(maxTrains); - else //add the train - succeeded = this.numTrains.compareAndSet(oldTrains, oldTrains+1); - - if (this.numTrains.get() > maxTrains) { //double check not over max trains - this.numTrains.set(maxTrains); - succeeded = false; - } - - if (succeeded) { - this.trained = true; - - //subtract from trains available - pc.modifyTrainsAvailable(-1); - - //update database - pc.addDatabaseJob("Skills", MBServerStatics.THIRTY_SECONDS); - - //recalculate this skill - calculateBaseAmount(); - calculateModifiedAmount(); - - //see if any new skills or powers granted - pc.calculateSkills(); - - //reapply all bonuses - pc.applyBonuses(); - - //update cache if running trains change - if (running) - pc.incVer(); - - return true; - } else - return false; - } - - public float getTrainingCost(PlayerCharacter pc, NPC trainer){ - int charLevel = pc.getLevel(); - int skillRank = this.getNumTrains() - 1 + this.requiredLevel; - float baseCost = 15 * this.requiredLevel; //TODO GET BASE COSTS OF SKILLS. - - - - float sellPercent = -.20f; - float cost; - float const5; - int const2 = 1; - float const3 = 50; - float const4 = const3 + const2; - - if (charLevel > 50) - const5 = 50 / const4; - else - const5 = charLevel/const4; - - const5 = 1-const5; - const5 = (float) (Math.log(const5) / Math.log(2) * .75f); - float rounded5 = Math.round(const5); - const5 = rounded5 - const5; - - const5 *= -1; - - const5 = (float) (Math.pow(2, const5) - 1); - - const5 +=1; - const5 = Math.scalb(const5, (int) rounded5); - const5 *= (charLevel - skillRank); - const5 *= sellPercent; - const5 = (float) (Math.log(const5) / Math.log(2) * 3); - rounded5 = Math.round(const5); - const5 = rounded5 - const5; - const5 *= -1; - const5 = (float) (Math.pow(2, const5) - 1); - const5 +=1; - - - const5 = Math.scalb(const5, (int) rounded5); - const5 += 1; - cost = const5 * (baseCost); - - - if (Float.isNaN(cost)) - cost = baseCost; - return cost; - } - - //Call this to refine skills and recalculate everything for pc. - public boolean refine(PlayerCharacter pc) { - return refine(pc, true); - } - - public boolean refine(PlayerCharacter pc, boolean recalculate) { - if (pc == null || this.skillsBase == null) - return false; - - int oldTrains = this.numTrains.get(); - boolean succeeded = true; - if (this.getNumTrains() < 1) - return false; - succeeded = this.numTrains.compareAndSet(oldTrains, oldTrains-1); - if (succeeded) { - this.trained = true; - - //add to trains available - pc.modifyTrainsAvailable(1); - - //update database - pc.addDatabaseJob("Skills", MBServerStatics.THIRTY_SECONDS); - - if (recalculate) { - //recalculate this skill - calculateBaseAmount(); - calculateModifiedAmount(); - - //see if any skills or powers removed - pc.calculateSkills(); - - //reapply all bonuses - pc.applyBonuses(); - } - - return true; - } else - return false; - } - - - public boolean reset(PlayerCharacter pc, boolean recalculate) { - if (pc == null || this.skillsBase == null) - return false; - - int oldTrains = this.numTrains.get(); - boolean succeeded = true; - if (this.getNumTrains() < 1) - return false; - succeeded = this.numTrains.compareAndSet(oldTrains, 0); - if (succeeded) { - this.trained = true; - - //add to trains available - pc.modifyTrainsAvailable(oldTrains); - - //update database - pc.addDatabaseJob("Skills", MBServerStatics.THIRTY_SECONDS); - - if (recalculate) { - //recalculate this skill - calculateBaseAmount(); - calculateModifiedAmount(); - - //see if any skills or powers removed - pc.calculateSkills(); - - //reapply all bonuses - pc.applyBonuses(); - } - - return true; - } else - return false; - } - - - /* - * Returns Skill Base for skill - */ - public SkillsBase getSkillsBase() { - return this.skillsBase; - } - - /* - * Returns number of trains in skill - */ - public int getNumTrains() { - return this.numTrains.get(); - } - - - - /* - * Returns Skill% before trains added - */ - public float getBaseAmount() { - return this.baseAmount; - } - - /* - * Returns Skill% after trains added - */ - public float getModifiedAmount() { - return this.modifiedAmount; - } - - /* - * Returns Skill% before trains added, minus bonus from equip and effects - */ - public float getBaseAmountBeforeMods() { - return this.baseAmountBeforeMods; - } - - /* - * Returns Skill% after trains added, minus bonus from equip and effects - */ - public float getModifiedAmountBeforeMods() { - return this.modifiedAmountBeforeMods; - } - - public String getName() { - if (this.skillsBase != null) - return this.skillsBase.getName(); - return ""; - } - - public int getToken() { - if (this.skillsBase != null) - return this.skillsBase.getToken(); - return 0; - } - - public boolean isTrained() { - return trained; - } - - public void syncTrains() { - this.trained = false; - } - - /* - * Serializing - */ - - public static void serializeForClientMsg(CharacterSkill characterSkill, ByteBufferWriter writer) { - if (characterSkill.skillsBase == null) { - Logger.error( "SkillsBase not found for skill " + characterSkill.getObjectUUID()); - writer.putInt(0); - writer.putInt(0); - } else { - writer.putInt(characterSkill.skillsBase.getToken()); - writer.putInt(characterSkill.numTrains.get()); - } - } - - /** - * @ This updates all Base Skill Amouts for a player - * Convienence method - */ - public static void updateAllBaseAmounts(PlayerCharacter pc) { - if (pc == null) - return; - ConcurrentHashMap skills = pc.getSkills(); - Iterator it = skills.keySet().iterator(); - while(it.hasNext()) { - String name = it.next(); - CharacterSkill cs = skills.get(name); - if (cs != null) - cs.calculateBaseAmount(); - // Logger.info("CharacterSkill", pc.getName() + ", skill: " + - // cs.getSkillsBase().getName() + ", trains: " + cs.numTrains + - // ", base: " + cs.baseAmount + ", mod: " + cs.modifiedAmount); - } - - //Recalculate ATR, damage and defense - //pc.calculateAtrDefenseDamage(); - - //recalculate movement bonus - //pc.calculateSpeedMod(); - } - - /** - * @ This updates all Modified skill Amounts for a player - * Convienence method - */ - public static void updateAllModifiedAmounts(PlayerCharacter pc) { - if (pc == null) - return; - ConcurrentHashMap skills = pc.getSkills(); - Iterator it = skills.keySet().iterator(); - while(it.hasNext()) { - String name = it.next(); - CharacterSkill cs = skills.get(name); - if (cs != null) - cs.calculateModifiedAmount(); - - } - - //Recalculate ATR, damage and defense - //pc.calculateAtrDefenseDamage(); - } - - /** - * @ Calculates Base Skill Percentage - * Call this when stats change for a player - */ - public void calculateBaseAmount() { - if (CharacterSkill.GetOwner(this) == null) { - Logger.error("owner not found for owner uuid : " + this.ownerUID); - this.baseAmount = 1; - this.modifiedAmount = 1; - return; - } - - if (this.skillsBase == null) { - Logger.error("SkillsBase not found for skill " + this.getObjectUUID()); - this.baseAmount = 1; - this.modifiedAmount = 1; - return; - } - - //Get any rune bonus - float bonus = 0f; - //runes will already be calculated - if (CharacterSkill.GetOwner(this).getBonuses() != null) { - //Get bonuses from runes - bonus = CharacterSkill.GetOwner(this).getBonuses().getSkillBonus(this.skillsBase.sourceType); - } - - //Get Base skill for unmodified stats - float base = 7f; - float statMod = 0.5f; - if (this.skillsBase.getStrMod() > 0) - statMod += (float)this.skillsBase.getStrMod() * (float) (int) ((PlayerCharacter) CharacterSkill.GetOwner(this)).statStrBase / 100f; - if (this.skillsBase.getDexMod() > 0) - statMod += (float)this.skillsBase.getDexMod() * (float) (int) ((PlayerCharacter) CharacterSkill.GetOwner(this)).statDexBase / 100f; - if (this.skillsBase.getConMod() > 0) - statMod += (float)this.skillsBase.getConMod() * (float) (int) ((PlayerCharacter) CharacterSkill.GetOwner(this)).statConBase / 100f; - if (this.skillsBase.getIntMod() > 0) - statMod += (float)this.skillsBase.getIntMod() * (float) (int) ((PlayerCharacter) CharacterSkill.GetOwner(this)).statIntBase / 100f; - if (this.skillsBase.getSpiMod() > 0) - statMod += (float)this.skillsBase.getSpiMod() * (float) (int) ((PlayerCharacter) CharacterSkill.GetOwner(this)).statSpiBase / 100f; - if (statMod < 1) - statMod = 1f; - else if (statMod > 600) - statMod = 600f; - base += CharacterSkill.baseSkillValues[(int)statMod]; - - if (base + bonus < 1f) - this.baseAmountBeforeMods = 1f; - else - this.baseAmountBeforeMods = base + bonus; - this.modifiedAmountBeforeMods = Math.round(this.baseAmountBeforeMods + calculateAmountAfterTrains()); - } - - public void calculateMobBaseAmount() { - if (CharacterSkill.GetOwner(this) == null) { - Logger.error("owner not found for owner uuid : " + this.ownerUID); - this.baseAmount = 1; - this.modifiedAmount = 1; - return; - } - - if (this.skillsBase == null) { - Logger.error("SkillsBase not found for skill " + this.getObjectUUID()); - this.baseAmount = 1; - this.modifiedAmount = 1; - return; - } - - //Get any rune bonus - float bonus = 0f; - //TODO SKILLS RUNES - - if (CharacterSkill.GetOwner(this).getBonuses() != null) { - //Get bonuses from runes - bonus = CharacterSkill.GetOwner(this).getBonuses().getSkillBonus(this.skillsBase.sourceType); - } - - //Get Base skill for unmodified stats - float base = 7f; - float statMod = 0.5f; - if (this.skillsBase.getStrMod() > 0) - statMod += (float)this.skillsBase.getStrMod() * (float)((Mob)CharacterSkill.GetOwner(this)).getMobBase().getMobBaseStats().getBaseStr() / 100f; - if (this.skillsBase.getDexMod() > 0) - statMod += (float)this.skillsBase.getDexMod() * (float)((Mob)CharacterSkill.GetOwner(this)).getMobBase().getMobBaseStats().getBaseDex() / 100f; - if (this.skillsBase.getConMod() > 0) - statMod += (float)this.skillsBase.getConMod() * (float)((Mob)CharacterSkill.GetOwner(this)).getMobBase().getMobBaseStats().getBaseCon() / 100f; - if (this.skillsBase.getIntMod() > 0) - statMod += (float)this.skillsBase.getIntMod() * (float)((Mob)CharacterSkill.GetOwner(this)).getMobBase().getMobBaseStats().getBaseInt() / 100f; - if (this.skillsBase.getSpiMod() > 0) - statMod += (float)this.skillsBase.getSpiMod() * (float)((Mob)CharacterSkill.GetOwner(this)).getMobBase().getMobBaseStats().getBaseSpi() / 100f; - if (statMod < 1) - statMod = 1f; - else if (statMod > 600) - statMod = 600f; - base += CharacterSkill.baseSkillValues[(int)statMod]; - - if (base + bonus < 1f) - this.baseAmountBeforeMods = 1f; - else - this.baseAmountBeforeMods = base + bonus; - this.modifiedAmountBeforeMods = (int)(this.baseAmountBeforeMods + calculateAmountAfterTrains()); - } - - public void calculateModifiedAmount() { - if (CharacterSkill.GetOwner(this) == null || this.skillsBase == null) { - Logger.error( "owner or SkillsBase not found for skill " + this.getObjectUUID()); - this.baseAmount = 1; - this.modifiedAmount = 1; - return; - } - - //Get any rune bonus - float bonus = 0f; - if (CharacterSkill.GetOwner(this).getBonuses() != null) { - //Get bonuses from runes - bonus = CharacterSkill.GetOwner(this).getBonuses().getSkillBonus(this.skillsBase.sourceType); - } - - //Get Base skill for modified stats - //TODO this fomula needs verified - float base = 7f; - float statMod = 0.5f; - if (this.skillsBase.getStrMod() > 0) - statMod += (float)this.skillsBase.getStrMod() * (float)CharacterSkill.GetOwner(this).getStatStrCurrent() / 100f; - if (this.skillsBase.getDexMod() > 0) - statMod += (float)this.skillsBase.getDexMod() * (float)CharacterSkill.GetOwner(this).getStatDexCurrent() / 100f; - if (this.skillsBase.getConMod() > 0) - statMod += (float)this.skillsBase.getConMod() * (float)CharacterSkill.GetOwner(this).getStatConCurrent() / 100f; - if (this.skillsBase.getIntMod() > 0) - statMod += (float)this.skillsBase.getIntMod() * (float)CharacterSkill.GetOwner(this).getStatIntCurrent() / 100f; - if (this.skillsBase.getSpiMod() > 0) - statMod += (float)this.skillsBase.getSpiMod() * (float)CharacterSkill.GetOwner(this).getStatSpiCurrent() / 100f; - if (statMod < 1) - statMod = 1f; - else if (statMod > 600) - statMod = 600f; - base += CharacterSkill.baseSkillValues[(int)statMod]; - SourceType sourceType = SourceType.GetSourceType(this.skillsBase.getNameNoSpace()); - - //Get any rune, effect and item bonus - - if (CharacterSkill.GetOwner(this).getBonuses() != null) { - //add bonuses from effects/items and runes - base += bonus + CharacterSkill.GetOwner(this).getBonuses().getFloat(ModType.Skill, sourceType); - } - - if (base < 1f) - this.baseAmount = 1f; - else - this.baseAmount = base; - - float modAmount = this.baseAmount + calculateAmountAfterTrains(); - - if (CharacterSkill.GetOwner(this).getBonuses() != null) { - //Multiply any percent bonuses - modAmount *= (1 + CharacterSkill.GetOwner(this).getBonuses().getFloatPercentAll(ModType.Skill, sourceType)); - } - - this.modifiedAmount = (int)(modAmount); - } - - /** - * @ Calculates Modified Skill Percentage - * Call this when number of trains change for skill - */ - public float calculateAmountAfterTrains() { - if (this.skillsBase == null) { - Logger.error( "SkillsBase not found for skill " + this.getObjectUUID()); - this.modifiedAmount = this.baseAmount; - } - int amount; - - int trains = this.numTrains.get(); - if (trains < 10) - amount = (trains * 2); - else if (trains < 90) - amount = 10 + trains; - else if (trains < 134) - amount = 100 + ((trains-90) / 2); - else - amount = 122 + ((trains-134) / 3); - - return amount; - } - - public static int getTrainsAvailable(PlayerCharacter pc) { - - if (pc == null) - return 0; - if (pc.getRace() == null || pc.getBaseClass() == null) { - Logger.error("Race or BaseClass not found for player " + pc.getObjectUUID()); - return 0; - } - int raceBonus = 0; - int baseMod = 0; - int promoMod = 6; - int available = 0; - - //get racial bonus; - if (pc.getRace().getRaceType().equals(Enum.RaceType.HUMANMALE) || - pc.getRace().getRaceType().equals(Enum.RaceType.HUMANFEMALE) ) - raceBonus = 1; //Human racial bonus; - - //get base class trains - if (pc.getBaseClass().getObjectUUID() == 2500 || pc.getBaseClass().getObjectUUID() == 2502) { - baseMod = 4; //Fighter or Rogue - } else { - baseMod = 5; //Healer or Mage - } - - int level = pc.getLevel(); - if (level > 74) - available = 62 + (49 * (promoMod + baseMod + raceBonus)) + (9 * (baseMod + raceBonus)); - else if (level > 69) - available = ((level - 69) * 3) + 45 + (49 * (promoMod + baseMod + raceBonus)) + (9 * (baseMod + raceBonus)); - else if (level > 64) - available = ((level - 64) * 4) + 25 + (49 * (promoMod + baseMod + raceBonus)) + (9 * (baseMod + raceBonus)); - else if (level > 59) //Between 60 and 65 - available = ((level - 59) * 5) + (49 * (promoMod + baseMod + raceBonus)) + (9 * (baseMod + raceBonus)); - else if (level > 10) //Between 11 and 59 - available = ((level - 10) * (promoMod + baseMod + raceBonus)) + (9 * (baseMod + raceBonus)); - // available = (level - 59) + (49 * (promoMod + baseMod + raceBonus)) + (9 * (baseMod + raceBonus)); - else if (level == 10 && (pc.getPromotionClass() != null)) //10 but promoted - available = (promoMod + baseMod + raceBonus) + (9 * (baseMod + raceBonus)); - else //not promoted - available = (level-1) * (baseMod + raceBonus); - - //next subtract trains in any skills - ConcurrentHashMap skills = pc.getSkills(); - Iterator it = skills.keySet().iterator(); - while(it.hasNext()) { - String name = it.next(); - CharacterSkill cs = skills.get(name); - if (cs != null) - available -= cs.numTrains.get(); - } - - //TODO subtract any trains from powers - ConcurrentHashMap powers = pc.getPowers(); - for (CharacterPower power : powers.values()) { - if (power != null) - available -= power.getTrains(); - } - - if(MBServerStatics.BONUS_TRAINS_ENABLED) { - available += 1000; - } - - // if (available < 0) { - //TODO readd this error log after test - // Logger.error("CharacterSkill.getTrainsAvailable", "Number of trains available less then 0 for Player " + pc.getUUID()); - // available = 0; - // } - - //return what's left - return available; - } - - /** - * @ Returns mastery base when mastery not granted - * to player. For calculating damage correctly - */ - public static float getQuickMastery(AbstractCharacter pc, String mastery) { - SkillsBase sb = SkillsBase.getFromCache(mastery); - if (sb == null) { - sb = DbManager.SkillsBaseQueries.GET_BASE_BY_NAME(mastery); - if (sb == null) { - //Logger.error("CharacterSkill.getQuickMastery", "Unable to find skillsbase of name " + mastery); - return 0f; - } - } - - float bonus = 0f; - SourceType sourceType = SourceType.GetSourceType(sb.getNameNoSpace()); - if (pc.getBonuses() != null) { - //Get bonuses from runes - bonus = pc.getBonuses().getSkillBonus(sb.sourceType); - } - float base = 4.75f; - base += (0.0025f * sb.getStrMod() * pc.getStatStrCurrent()); - base += (0.0025f * sb.getDexMod() * pc.getStatDexCurrent()); - base += (0.0025f * sb.getConMod() * pc.getStatConCurrent()); - base += (0.0025f * sb.getIntMod() * pc.getStatIntCurrent()); - base += (0.0025f * sb.getSpiMod() * pc.getStatSpiCurrent()); - return base + bonus; - } - - /* - * This iterates through players runes and adds and removes skills as needed - * Don't Call this directly. Instead call pc.calculateSkills(). - */ - public static void calculateSkills(PlayerCharacter pc) { - if (pc == null) - return; - - ConcurrentHashMap skills = pc.getSkills(); - - //First add skills that don't exist - Race race = pc.getRace(); - if (race != null) { - CharacterSkill.grantSkills(race.getSkillsGranted(), pc); - } else - Logger.error( "Failed to find Race for player " + pc.getObjectUUID()); - BaseClass bc = pc.getBaseClass(); - if (bc != null) { - CharacterSkill.grantSkills(bc.getSkillsGranted(), pc); - } else - Logger.error( "Failed to find BaseClass for player " + pc.getObjectUUID()); - PromotionClass promo = pc.getPromotionClass(); - if (promo != null) - CharacterSkill.grantSkills(promo.getSkillsGranted(), pc); - ArrayList runes = pc.getRunes(); - if (runes != null) { - for (CharacterRune rune : runes) { - CharacterSkill.grantSkills(rune.getSkillsGranted(), pc); - } - } else - Logger.error("Failed to find Runes list for player " + pc.getObjectUUID()); - - //next remove any skills that no longer belong - Iterator it = skills.values().iterator(); - while(it.hasNext()) { - CharacterSkill cs = it.next(); - if (cs == null) - continue; - SkillsBase sb = cs.skillsBase; - if (sb == null) { - DbManager.CharacterSkillQueries.DELETE_SKILL(cs.getObjectUUID()); - it.remove(); - continue; - } - boolean valid = false; - if (CharacterSkill.skillAllowed(sb.getObjectUUID(), race.getSkillsGranted(), pc)) - continue; - if (CharacterSkill.skillAllowed(sb.getObjectUUID(), bc.getSkillsGranted(), pc)) - continue; - if (promo != null) - if (CharacterSkill.skillAllowed(sb.getObjectUUID(), promo.getSkillsGranted(), pc)) - continue; - for (CharacterRune rune : runes) { - if (CharacterSkill.skillAllowed(sb.getObjectUUID(), rune.getSkillsGranted(), pc)) { - valid = true; - continue; - } - } - //if skill doesn't belong to any runes, then remove it - if (!valid) { - DbManager.CharacterSkillQueries.DELETE_SKILL(cs.getObjectUUID()); - it.remove(); - } - } - CharacterSkill.updateAllBaseAmounts(pc); - CharacterSkill.updateAllModifiedAmounts(pc); - CharacterPower.calculatePowers(pc); - } - - /* - *This grants skills for specific runes - */ - private static void grantSkills(ArrayList skillsGranted, PlayerCharacter pc) { - ConcurrentHashMap skills = pc.getSkills(); - if (skills == null) - return; - - for (SkillReq skillreq : skillsGranted) { - SkillsBase skillsBase = skillreq.getSkillsBase(); - - //If player not high enough level for skill, then skip - if (pc.getLevel() < skillreq.getLevel()) - continue; - //If player doesn't have prereq skills high enough then skip - boolean valid = true; - for (byte prereqSkill : skillreq.getSkillReqs()) { - SkillsBase sb = null; - sb = DbManager.SkillsBaseQueries.GET_BASE(prereqSkill); - if (sb != null) { - if (skills.containsKey(sb.getName())) { - if (validForWarrior(pc, skills.get(sb.getName()), skillreq)) { - valid = true; - break; //add if any prereq skills met - } else if (skills.get(sb.getName()).modifiedAmountBeforeMods >= 80) { - valid = true; - break; //add if any prereq skills met - // allow blade masters to use blade master without training sword above 80.. - } else if (skillsBase.getObjectUUID() == 9){ - valid = true; - break; - } - - } - } else { - Logger.error("Failed to find SkillsBase of ID " + prereqSkill); - } - valid = false; - } - // Throwing does not need axe,dagger, or hammer at 80% - if (skillreq.getSkillID() == 43) - valid = true; - if (!valid) - continue; - - //Skill valid for player. Add if don't already have - if (skillsBase != null) { - if (!skills.containsKey(skillsBase.getName())) { - CharacterSkill newSkill = new CharacterSkill(skillsBase, pc); - CharacterSkill cs = null; - try { - cs = DbManager.CharacterSkillQueries.ADD_SKILL(newSkill); - } catch (Exception e) { - cs = null; - } - if (cs != null){ - cs.requiredLevel = (int) skillreq.getLevel(); - skills.put(skillsBase.getName(), cs); - } - - else - Logger.error("Failed to add CharacterSkill to player " + pc.getObjectUUID()); - } - else{ - CharacterSkill cs = skills.get(skillsBase.getName()); - if (cs != null && cs.requiredLevel == 0) { - cs.requiredLevel = (int) skillreq.getLevel(); - } - } - - } else - Logger.error( "Failed to find SkillsBase for SkillReq " + skillreq.getObjectUUID()); - } - } - - private static boolean validForWarrior(PlayerCharacter pc, CharacterSkill skill, SkillReq skillreq) { - if (pc.getPromotionClass() == null || pc.getPromotionClass().getObjectUUID() != 2518 || skill == null || skillreq == null) - return false; //not a warrior - int sID = (skill.skillsBase != null) ? skill.skillsBase.getObjectUUID() : 0; - switch (skillreq.getSkillID()) { - case 3: //Axe mastery - case 19: //Great axe mastery - return (sID == 4) ? (skill.modifiedAmountBeforeMods >= 50) : false; - case 15: //Dagger mastery - return (sID == 16) ? (skill.modifiedAmountBeforeMods >= 50) : false; - case 20: //Great hammer mastery - case 22: //Hammer mastery - return (sID == 23) ? (skill.modifiedAmountBeforeMods >= 50) : false; - case 28: //Polearm mastery - return (sID == 29) ? (skill.modifiedAmountBeforeMods >= 50) : false; - case 21: //Great sword mastery - case 39: //Sword mastery - return (sID == 40) ? (skill.modifiedAmountBeforeMods >= 50) : false; - case 34: //Spear mastery - return (sID == 35) ? (skill.modifiedAmountBeforeMods >= 50) : false; - case 36: //Staff mastery - return (sID == 37) ? (skill.modifiedAmountBeforeMods >= 50) : false; - case 45: //Unarmed combat mastery - return (sID == 46) ? (skill.modifiedAmountBeforeMods >= 50) : false; - case 40: - return true; - case 9: - return true; - default: - } - return false; - } - - /* - * This verifies if a skill is valid for a players rune - */ - private static boolean skillAllowed(int UUID, ArrayList skillsGranted, PlayerCharacter pc) { - ConcurrentHashMap skills = pc.getSkills(); - for (SkillReq skillreq : skillsGranted) { - SkillsBase sb = skillreq.getSkillsBase(); - if (sb != null) { - if (sb.getObjectUUID() == UUID) { - if (skillreq.getLevel() <= pc.getLevel()) { - SkillsBase sbp = null; - if (skillreq.getSkillReqs().size() == 0) - return true; - for (byte prereqSkill : skillreq.getSkillReqs()) { - sbp = DbManager.SkillsBaseQueries.GET_BASE(prereqSkill); - if (sbp != null && skills.containsKey(sbp.getName())) { - if (validForWarrior(pc, skills.get(sbp.getName()), skillreq)) { - return true; - } else if (skills.get(sbp.getName()).modifiedAmountBeforeMods >= 80) - return true; - } - } - - if (skillreq.getSkillID() == 43) - return true; - if (skillreq.getSkillID() == 9) - return true; - } - } - } else - Logger.error( "Failed to find SkillsBase for SkillReq " + skillreq.getObjectUUID()); - } - return false; - } - - //Print skills for player for debugging - public static void printSkills(PlayerCharacter pc) { - if (pc == null) - return; - ConcurrentHashMap skills = pc.getSkills(); - String out = "Player: " + pc.getObjectUUID() + ", SkillCount: " + skills.size(); - Iterator it = skills.keySet().iterator(); - while(it.hasNext()) { - String name = it.next(); - out += ", " + name; - } - Logger.info( out); - } - - public static int getMaxTrains(int intt) { - if (intt > 0 && intt < 191) - return CharacterSkill.maxTrains[intt]; - else - return (int)(33 + 1.25 * intt - 0.005 * Math.pow(intt, 2)); - } - - public int getSkillPercentFromAttributes(){ - AbstractCharacter ac = CharacterSkill.GetOwner(this); - - if (ac == null) - return 0; - - float statMod = 0; - - if (this.skillsBase.getStrMod() > 0){ - float strengthModPercent = (float)this.skillsBase.getStrMod() * .01f; - strengthModPercent *= ac.getStatStrCurrent() * .01f + .6f; - statMod += strengthModPercent; - } - - if (this.skillsBase.getDexMod() > 0){ - float dexModPercent = (float)this.skillsBase.getDexMod() * .01f; - dexModPercent *= ac.getStatDexCurrent() * .01f + .6f; - statMod += dexModPercent; - } - if (this.skillsBase.getConMod() > 0){ - float conModPercent = (float)this.skillsBase.getConMod() * .01f; - conModPercent *= ac.getStatConCurrent() * .01f + .6f; - statMod += conModPercent; - } - if (this.skillsBase.getIntMod() > 0){ - float intModPercent = (float)this.skillsBase.getIntMod() * .01f; - intModPercent *= ac.getStatIntCurrent() * .01f + .6f; - statMod += intModPercent; - } - if (this.skillsBase.getSpiMod() > 0){ - float spiModPercent = (float)this.skillsBase.getSpiMod() * .01f; - spiModPercent *= ac.getStatSpiCurrent() * .01f + .6f; - statMod += spiModPercent; - } - - statMod = (float) (Math.pow(statMod, 1.5f) * 15f); - if (statMod < 1) - statMod = 1f; - else if (statMod > 600) - statMod = 600f; - - - - - return (int) statMod; - } - - public int getSkillPercentFromTrains(){ - - int trains = this.numTrains.get(); - if ( trains <= 10 ) - return 2 * trains; - if ( trains <= 90 ) - return trains + 10; - if ( trains > 130 ) - return (int) (120 - ((trains - 130) * -0.33000001)); - return (int) (100 - ((trains - 90) * -0.5)); - - } - - public int getTotalSkillPercet(){ - - AbstractCharacter ac = CharacterSkill.GetOwner(this); - - if (ac == null) - return 0; - - float bonus = 0f; - SourceType sourceType = SourceType.GetSourceType(this.skillsBase.getNameNoSpace()); - if (CharacterSkill.GetOwner(this).getBonuses() != null) { - //Get bonuses from runes - bonus = CharacterSkill.GetOwner(this).getBonuses().getSkillBonus(this.skillsBase.sourceType); - } - return this.getSkillPercentFromTrains() + this.getSkillPercentFromAttributes(); - } - - @Override - public void updateDatabase() { - DbManager.CharacterSkillQueries.updateDatabase(this); - } - - public int getRequiredLevel() { - return requiredLevel; - } - - public void setRequiredLevel(int requiredLevel) { - this.requiredLevel = requiredLevel; - } + private static final int[] maxTrains = { + 29, 29, 29, 29, 29, //0 to 4 + 29, 32, 34, 36, 38, //5 to 9 + 40, 42, 43, 45, 47, //10 to 14 + 48, 49, 51, 52, 53, //15 to 19 + 55, 56, 57, 58, 59, //20 to 24 + 60, 62, 63, 64, 65, //25 to 29 + 66, 67, 68, 68, 69, //30 to 34 + 70, 71, 72, 73, 74, //35 to 39 + 75, 76, 76, 77, 78, //40 to 44 + 79, 80, 80, 81, 82, //45 to 49 + 83, 83, 84, 85, 85, //50 to 54 + 86, 87, 88, 88, 89, //55 to 59 + 90, 90, 91, 92, 92, //60 to 64 + 93, 94, 94, 95, 95, //65 to 69 + 96, 97, 97, 98, 99, //70 to 74 + 99, 100, 100, 101, 101, //75 to 79 + 102, 103, 103, 104, 104, //80 to 84 + 105, 105, 106, 106, 107, //85 to 89 + 108, 109, 109, 110, 110, //90 to 94 + 111, 112, 112, 113, 113, //95 to 99 + 114, 115, 115, 116, 116, //100 to 104 + 117, 118, 118, 119, 119, //105 to 109 + 120, 121, 121, 122, 122, //110 to 114 + 123, 124, 124, 125, 125, //115 to 119 + 126, 127, 127, 128, 128, //120 to 124 + 129, 130, 130, 131, 131, //125 to 129 + 132, 133, 133, 134, 134, //130 to 134 + 135, 136, 136, 137, 137, //135 to 139 + 138, 139, 139, 140, 140, //140 to 144 + 141, 142, 142, 143, 143, //145 to 149 + 144, 145, 145, 146, 146, //150 to 154 + 147, 148, 148, 149, 149, //155 to 159 + 150, 151, 151, 152, 152, //160 to 164 + 153, 154, 154, 155, 155, //165 to 169 + 156, 157, 157, 158, 158, //170 to 174 + 159, 160, 160, 161, 161, //175 to 179 + 162, 163, 163, 164, 164, //180 to 184 + 165, 166, 166, 167, 167, //185 to 189 + 168}; //190 + + private static final float[] baseSkillValues = { + 0.0f, 0.0f, 0.2f, 0.4f, 0.6f, //0 to 4 + 0.8f, 1.0f, 1.1666666f, 1.3333334f, 1.5f, //5 to 9 + 1.6666667f, 1.8333334f, 2.0f, 2.2f, 2.4f, //10 to 14 + 2.6f, 2.8f, 3.0f, 3.2f, 3.4f, //15 to 19 + 3.6f, 3.8f, 4.0f, 4.2f, 4.4f, //20 to 24 + 4.6f, 4.8f, 5.0f, 5.25f, 5.5f, //25 to 29 + 5.75f, 6.0f, 6.2f, 6.4f, 6.6f, //30 to 34 + 6.8f, 7.0f, 7.25f, 7.5f, 7.75f, //35 to 39 + 8.0f, 8.2f, 8.4f, 8.6f, 8.8f, //40 to 44 + 9.0f, 9.25f, 9.5f, 9.75f, 10.0f, //45 to 49 + 10.25f, 10.5f, 10.75f, 11.0f, 11.2f, //50 to 54 + 11.4f, 11.6f, 11.8f, 12.0f, 12.25f, //55 to 59 + 12.5f, 12.75f, 13.0f, 13.25f, 13.5f, //60 to 64 + 13.75f, 14.0f, 14.25f, 14.5f, 14.75f, //65 to 69 + 15.0f, 15.333333f, 15.666667f, 16.0f, 16.25f, //70 to 74 + 16.5f, 16.75f, 17.0f, 17.25f, 17.5f, //75 to 79 + 17.75f, 18.0f, 18.25f, 18.5f, 18.75f, //80 to 84 + 19.0f, 19.333334f, 19.666666f, 20.0f, 20.25f, //85 to 89 + 20.5f, 20.75f, 21.0f, 21.25f, 21.5f, //90 to 94 + 21.75f, 22.0f, 22.333334f, 22.666666f, 23.0f, //95 to 99 + 23.25f, 23.5f, 23.75f, 24.0f, 24.333334f, //100 to 104 + 24.666666f, 25.0f, 25.25f, 25.5f, 25.75f, //105 to 109 + 26.0f, 26.333334f, 26.666666f, 27.0f, 27.333334f, //110 to 114 + 27.666666f, 28.0f, 28.25f, 28.5f, 28.75f, //115 to 119 + 29.0f, 29.333334f, 29.666666f, 30.0f, 30.333334f, //120 to 124 + 30.666666f, 31.0f, 31.25f, 31.5f, 31.75f, //125 to 129 + 32.0f, 32.333332f, 32.666668f, 33.0f, 33.333332f, //130 to 134 + 33.666668f, 34.0f, 34.333332f, 34.666668f, 35.0f, //135 to 139 + 35.333332f, 35.666668f, 36.0f, 36.333332f, 36.666668f, //140 to 144 + 37.0f, 37.25f, 37.5f, 37.75f, 38.0f, //145 to 149 + 38.333332f, 38.666668f, 39.0f, 39.333332f, 39.666668f, //150 to 154 + 40.0f, 40.333332f, 40.666668f, 41.0f, 41.333332f, //155 to 159 + 41.666668f, 42.0f, 42.333332f, 42.666668f, 43.0f, //160 to 164 + 43.333332f, 43.666668f, 44.0f, 44.333332f, 44.666668f, //165 to 169 + 45.0f, 45.5f, 46.0f, 46.333332f, 46.666668f, //170 to 174 + 47.0f, 47.333332f, 47.666668f, 48.0f, 48.333332f, //175 to 179 + 48.666668f, 49.0f, 49.333332f, 49.666668f, 50.0f, //180 to 184 + 50.333332f, 50.666668f, 51.0f, 51.333332f, 51.666668f, //185 to 189 + 52.0f, 52.5f, 53.0f, 53.333332f, 53.666668f, //190 to 194 + 54.0f, 54.333332f, 54.666668f, 55.0f, 55.333332f, //195 to 199 + 55.666668f, 56.0f, 56.333332f, 56.666668f, 57.0f, //200 to 204 + 57.5f, 58.0f, 58.333332f, 58.666668f, 59.0f, //205 to 209 + 59.333332f, 59.666668f, 60.0f, 60.5f, 61.0f, //210 to 214 + 61.333332f, 61.666668f, 62.0f, 62.333332f, 62.666668f, //215 to 219 + 63.0f, 63.5f, 64.0f, 64.333336f, 64.666664f, //220 to 224 + 65.0f, 65.333336f, 65.666664f, 66.0f, 66.5f, //225 to 229 + 67.0f, 67.333336f, 67.666664f, 68.0f, 68.5f, //230 to 234 + 69.0f, 69.333336f, 69.666664f, 70.0f, 70.333336f, //235 to 239 + 70.666664f, 71.0f, 71.5f, 72.0f, 72.5f, //240 to 244 + 73.0f, 73.333336f, 73.666664f, 74.0f, 74.333336f, //245 to 249 + 74.666664f, 75.0f, 75.5f, 76.0f, 76.333336f, //250 to 254 + 76.666664f, 77.0f, 77.5f, 78.0f, 78.333336f, //255 to 259 + 78.666664f, 79.0f, 79.5f, 80.0f, 80.333336f, //260 to 264 + 80.666664f, 81.0f, 81.5f, 82.0f, 82.333336f, //265 to 269 + 82.666664f, 83.0f, 83.5f, 84.0f, 84.333336f, //270 to 274 + 84.666664f, 85.0f, 85.5f, 86.0f, 86.5f, //275 to 279 + 87.0f, 87.333336f, 87.666664f, 88.0f, 88.5f, //280 to 284 + 89.0f, 89.333336f, 89.666664f, 90.0f, 90.5f, //285 to 289 + 91.0f, 91.5f, 92.0f, 92.333336f, 92.666664f, //290 to 294 + 93.0f, 93.5f, 94.0f, 94.5f, 95.0f, //295 to 299 + 95.333336f, 95.666664f, 96.0f, 96.5f, 97.0f, //300 to 304 + 97.5f, 98.0f, 98.333336f, 98.666664f, 99.0f, //305 to 309 + 99.5f, 100.0f, 100.5f, 101.0f, 101.5f, //310 to 314 + 102.0f, 102.5f, 103.0f, 103.333336f, 103.666664f, //315 to 319 + 104.0f, 104.333336f, 104.666664f, 105.0f, 105.5f, //320 to 324 + 106.0f, 106.5f, 107.0f, 108.0f, 108.333336f, //325 to 329 + 108.666664f, 109.0f, 109.333336f, 109.666664f, 110.0f, //330 to 334 + 110.5f, 111.0f, 111.5f, 112.0f, 112.5f, //335 to 339 + 113.0f, 113.333336f, 113.666664f, 114.0f, 114.5f, //340 to 344 + 115.0f, 115.5f, 116.0f, 116.5f, 117.0f, //345 to 349 + 117.5f, 118.0f, 118.333336f, 118.666664f, 119.0f, //350 to 354 + 119.5f, 120.0f, 120.5f, 121.0f, 121.5f, //355 to 359 + 122.0f, 122.5f, 123.0f, 123.333336f, 123.666664f, //360 to 364 + 124.0f, 124.5f, 125.0f, 125.5f, 126.0f, //365 to 369 + 126.5f, 127.0f, 127.5f, 128.0f, 128.5f, //370 to 374 + 129.0f, 129.5f, 130.0f, 130.33333f, 130.66667f, //375 to 379 + 131.0f, 131.5f, 132.0f, 132.5f, 133.0f, //380 to 384 + 133.5f, 134.0f, 134.5f, 135.0f, 135.5f, //385 to 389 + 136.0f, 136.5f, 137.0f, 137.5f, 138.0f, //390 to 394 + 138.5f, 139.0f, 139.5f, 140.0f, 140.33333f, //395 to 399 + 140.66667f, 141.0f, 141.5f, 142.0f, 142.5f, //400 to 404 + 143.0f, 143.5f, 144.0f, 144.5f, 145.0f, //405 to 409 + 145.5f, 146.0f, 146.5f, 147.0f, 147.5f, //410 to 414 + 148.0f, 148.5f, 149.0f, 149.5f, 150.0f, //415 to 419 + 150.5f, 151.0f, 151.5f, 152.0f, 152.5f, //420 to 424 + 153.0f, 153.5f, 154.0f, 154.5f, 155.0f, //425 to 429 + 155.5f, 156.0f, 156.5f, 157.0f, 157.5f, //430 to 434 + 158.0f, 158.5f, 159.0f, 159.5f, 160.0f, //435 to 439 + 160.5f, 161.0f, 161.5f, 162.0f, 162.5f, //440 to 444 + 163.0f, 163.5f, 164.0f, 164.5f, 165.0f, //445 to 449 + 165.5f, 166.0f, 166.5f, 167.0f, 167.5f, //450 to 454 + 168.0f, 168.5f, 169.0f, 169.5f, 170.0f, //455 to 459 + 170.5f, 171.0f, 171.5f, 172.0f, 172.5f, //460 to 464 + 173.0f, 173.5f, 174.0f, 174.5f, 175.0f, //465 to 469 + 176.0f, 176.5f, 177.0f, 177.5f, 178.0f, //470 to 474 + 178.5f, 179.0f, 179.5f, 180.0f, 180.5f, //475 to 479 + 181.0f, 181.5f, 182.0f, 182.5f, 183.0f, //480 to 484 + 183.5f, 184.0f, 184.5f, 185.0f, 185.5f, //485 to 489 + 186.0f, 187.0f, 187.5f, 188.0f, 188.5f, //490 to 494 + 189.0f, 189.5f, 190.0f, 190.5f, 191.0f, //495 to 499 + 191.5f, 192.0f, 192.5f, 193.0f, 193.5f, //500 to 504 + 194.0f, 194.5f, 195.0f, 196.0f, 196.5f, //505 to 509 + 197.0f, 197.5f, 198.0f, 198.5f, 199.0f, //510 to 514 + 199.5f, 200.0f, 200.5f, 201.0f, 201.5f, //515 to 519 + 202.0f, 203.0f, 203.5f, 204.0f, 204.5f, //520 to 524 + 205.0f, 205.5f, 206.0f, 206.5f, 207.0f, //525 to 529 + 207.5f, 208.0f, 209.0f, 209.5f, 210.0f, //530 to 534 + 210.5f, 211.0f, 211.5f, 212.0f, 212.5f, //535 to 539 + 213.0f, 214.0f, 214.5f, 215.0f, 215.5f, //540 to 544 + 216.0f, 216.5f, 217.0f, 217.5f, 218.0f, //545 to 549 + 218.5f, 219.0f, 220.0f, 220.5f, 221.0f, //550 to 554 + 221.5f, 222.0f, 222.5f, 223.0f, 224.0f, //555 to 559 + 224.5f, 225.0f, 225.5f, 226.0f, 226.5f, //560 to 564 + 227.0f, 227.5f, 228.0f, 229.0f, 229.5f, //565 to 569 + 230.0f, 230.5f, 231.0f, 231.5f, 232.0f, //570 to 574 + 233.0f, 233.5f, 234.0f, 234.5f, 235.0f, //575 to 579 + 235.5f, 236.0f, 237.0f, 237.5f, 238.0f, //580 to 584 + 238.5f, 239.0f, 239.5f, 240.0f, 241.0f, //585 to 589 + 241.5f, 242.0f, 242.5f, 243.0f, 243.5f, //590 to 594 + 244.0f, 245.0f, 245.5f, 246.0f, 246.5f, //595 to 599 + 247.0f}; //600 + + + private SkillsBase skillsBase; + private AtomicInteger numTrains = new AtomicInteger(); + + private CharacterSkills skillType; + + //Skill% before trains and before any effects or item bonuses + private float baseAmountBeforeMods; + + //Skill% after trains but before any effects or item bonuses + private float modifiedAmountBeforeMods; + private boolean isMobOwner = false; + + //Skill% before trains but after any effects or item bonuses + private float baseAmount; + + //Skill% after trains and after any effects or item bonuses + private float modifiedAmount; + + private int ownerUID; + private boolean trained = false; + private int requiredLevel = 0; + + /** + * No Table ID Constructor + */ + public CharacterSkill(SkillsBase skillsBase, PlayerCharacter pc) { + super(); + this.skillsBase = skillsBase; + this.numTrains.set(0); + this.ownerUID = pc.getObjectUUID(); + calculateBaseAmount(); + calculateModifiedAmount(); + this.skillType = CharacterSkills.GetCharacterSkillByToken(this.skillsBase.getToken()); + } + + /** + * Normal Constructor + */ + public CharacterSkill(SkillsBase skillsBase, PlayerCharacter pc, int newUUID) { + + super(newUUID); + this.skillsBase = skillsBase; + this.numTrains.set(0); + this.ownerUID = pc.getObjectUUID(); + this.trained = true; + calculateBaseAmount(); + calculateModifiedAmount(); + this.skillType = CharacterSkills.GetCharacterSkillByToken(this.skillsBase.getToken()); + + } + + /** + * ResultSet Constructor + */ + public CharacterSkill(ResultSet rs, PlayerCharacter pc) throws SQLException { + super(rs); + + int skillsBaseID = rs.getInt("SkillsBaseID"); + this.skillsBase = DbManager.SkillsBaseQueries.GET_BASE(skillsBaseID); + this.numTrains.set(rs.getShort("trains")); + this.ownerUID = pc.getObjectUUID(); + calculateBaseAmount(); + calculateModifiedAmount(); + this.skillType = CharacterSkills.GetCharacterSkillByToken(this.skillsBase.getToken()); + } + + public CharacterSkill(SkillsBase sb, Mob mob, int trains) { + super(); + this.skillsBase = sb; + this.numTrains.set(trains); + this.ownerUID = mob.getObjectUUID(); + this.isMobOwner = true; + calculateMobBaseAmount(); + calculateModifiedAmount(); + this.skillType = CharacterSkills.GetCharacterSkillByToken(this.skillsBase.getToken()); + } + + public CharacterSkill(ResultSet rs) throws SQLException { + super(rs); + int skillsBaseID = rs.getInt("SkillsBaseID"); + this.skillsBase = DbManager.SkillsBaseQueries.GET_BASE(skillsBaseID); + this.numTrains.set(rs.getShort("trains")); + this.ownerUID = rs.getInt("CharacterID"); + // this.owner = DbManager.PlayerCharacterQueries.GET_PLAYER_CHARACTER(rs.getInt("CharacterID")); + calculateBaseAmount(); + calculateModifiedAmount(); + this.skillType = CharacterSkills.GetCharacterSkillByToken(this.skillsBase.getToken()); + } + + public static AbstractCharacter GetOwner(CharacterSkill cs) { + if (cs.ownerUID == 0) + return null; + if (cs.isMobOwner) + return Mob.getFromCache(cs.ownerUID); + else + return PlayerCharacter.getFromCache(cs.ownerUID); + } + + /* + * Getters + */ + + public static float getATR(AbstractCharacter ac, String name) { + if (ac == null) + return 0f; + float atr; + ConcurrentHashMap skills = ac.getSkills(); + CharacterSkill skill = skills.get(name); + if (skill != null) + atr = skill.getATR(ac); + else { + float mast = CharacterSkill.getQuickMastery(ac, name); + atr = (((int) mast * 7) + (ac.getStatDexCurrent() / 2)); + } + //apply effect mods + PlayerBonuses bonus = ac.getBonuses(); + if (bonus == null) + return atr; + atr += bonus.getFloat(ModType.OCV, SourceType.None); + float pos_Bonus = bonus.getFloatPercentPositive(ModType.OCV, SourceType.None); + atr *= (1 + pos_Bonus); + //rUNES will already be applied + // atr *= (1 + ((float)bonus.getShort("rune.Attack") / 100)); //precise + float neg_Bonus = bonus.getFloatPercentNegative(ModType.OCV, SourceType.None); + atr *= (1 + neg_Bonus); + return atr; + } + + public static void serializeForClientMsg(CharacterSkill characterSkill, ByteBufferWriter writer) { + if (characterSkill.skillsBase == null) { + Logger.error("SkillsBase not found for skill " + characterSkill.getObjectUUID()); + writer.putInt(0); + writer.putInt(0); + } else { + writer.putInt(characterSkill.skillsBase.getToken()); + writer.putInt(characterSkill.numTrains.get()); + } + } + + /** + * @ This updates all Base Skill Amouts for a player + * Convienence method + */ + public static void updateAllBaseAmounts(PlayerCharacter pc) { + if (pc == null) + return; + ConcurrentHashMap skills = pc.getSkills(); + Iterator it = skills.keySet().iterator(); + while (it.hasNext()) { + String name = it.next(); + CharacterSkill cs = skills.get(name); + if (cs != null) + cs.calculateBaseAmount(); + // Logger.info("CharacterSkill", pc.getName() + ", skill: " + + // cs.getSkillsBase().getName() + ", trains: " + cs.numTrains + + // ", base: " + cs.baseAmount + ", mod: " + cs.modifiedAmount); + } + + //Recalculate ATR, damage and defense + //pc.calculateAtrDefenseDamage(); + + //recalculate movement bonus + //pc.calculateSpeedMod(); + } + + /** + * @ This updates all Modified skill Amounts for a player + * Convienence method + */ + public static void updateAllModifiedAmounts(PlayerCharacter pc) { + if (pc == null) + return; + ConcurrentHashMap skills = pc.getSkills(); + Iterator it = skills.keySet().iterator(); + while (it.hasNext()) { + String name = it.next(); + CharacterSkill cs = skills.get(name); + if (cs != null) + cs.calculateModifiedAmount(); + + } + + //Recalculate ATR, damage and defense + //pc.calculateAtrDefenseDamage(); + } + + public static int getTrainsAvailable(PlayerCharacter pc) { + + if (pc == null) + return 0; + if (pc.getRace() == null || pc.getBaseClass() == null) { + Logger.error("Race or BaseClass not found for player " + pc.getObjectUUID()); + return 0; + } + int raceBonus = 0; + int baseMod = 0; + int promoMod = 6; + int available = 0; + + //get racial bonus; + if (pc.getRace().getRaceType().equals(Enum.RaceType.HUMANMALE) || + pc.getRace().getRaceType().equals(Enum.RaceType.HUMANFEMALE)) + raceBonus = 1; //Human racial bonus; + + //get base class trains + if (pc.getBaseClass().getObjectUUID() == 2500 || pc.getBaseClass().getObjectUUID() == 2502) { + baseMod = 4; //Fighter or Rogue + } else { + baseMod = 5; //Healer or Mage + } + + int level = pc.getLevel(); + if (level > 74) + available = 62 + (49 * (promoMod + baseMod + raceBonus)) + (9 * (baseMod + raceBonus)); + else if (level > 69) + available = ((level - 69) * 3) + 45 + (49 * (promoMod + baseMod + raceBonus)) + (9 * (baseMod + raceBonus)); + else if (level > 64) + available = ((level - 64) * 4) + 25 + (49 * (promoMod + baseMod + raceBonus)) + (9 * (baseMod + raceBonus)); + else if (level > 59) //Between 60 and 65 + available = ((level - 59) * 5) + (49 * (promoMod + baseMod + raceBonus)) + (9 * (baseMod + raceBonus)); + else if (level > 10) //Between 11 and 59 + available = ((level - 10) * (promoMod + baseMod + raceBonus)) + (9 * (baseMod + raceBonus)); + // available = (level - 59) + (49 * (promoMod + baseMod + raceBonus)) + (9 * (baseMod + raceBonus)); + else if (level == 10 && (pc.getPromotionClass() != null)) //10 but promoted + available = (promoMod + baseMod + raceBonus) + (9 * (baseMod + raceBonus)); + else //not promoted + available = (level - 1) * (baseMod + raceBonus); + + //next subtract trains in any skills + ConcurrentHashMap skills = pc.getSkills(); + Iterator it = skills.keySet().iterator(); + while (it.hasNext()) { + String name = it.next(); + CharacterSkill cs = skills.get(name); + if (cs != null) + available -= cs.numTrains.get(); + } + + //TODO subtract any trains from powers + ConcurrentHashMap powers = pc.getPowers(); + for (CharacterPower power : powers.values()) { + if (power != null) + available -= power.getTrains(); + } + + if (MBServerStatics.BONUS_TRAINS_ENABLED) { + available += 1000; + } + + // if (available < 0) { + //TODO readd this error log after test + // Logger.error("CharacterSkill.getTrainsAvailable", "Number of trains available less then 0 for Player " + pc.getUUID()); + // available = 0; + // } + + //return what's left + return available; + } + + /** + * @ Returns mastery base when mastery not granted + * to player. For calculating damage correctly + */ + public static float getQuickMastery(AbstractCharacter pc, String mastery) { + SkillsBase sb = SkillsBase.getFromCache(mastery); + if (sb == null) { + sb = DbManager.SkillsBaseQueries.GET_BASE_BY_NAME(mastery); + if (sb == null) { + //Logger.error("CharacterSkill.getQuickMastery", "Unable to find skillsbase of name " + mastery); + return 0f; + } + } + + float bonus = 0f; + SourceType sourceType = SourceType.GetSourceType(sb.getNameNoSpace()); + if (pc.getBonuses() != null) { + //Get bonuses from runes + bonus = pc.getBonuses().getSkillBonus(sb.sourceType); + } + float base = 4.75f; + base += (0.0025f * sb.getStrMod() * pc.getStatStrCurrent()); + base += (0.0025f * sb.getDexMod() * pc.getStatDexCurrent()); + base += (0.0025f * sb.getConMod() * pc.getStatConCurrent()); + base += (0.0025f * sb.getIntMod() * pc.getStatIntCurrent()); + base += (0.0025f * sb.getSpiMod() * pc.getStatSpiCurrent()); + return base + bonus; + } + + /* + * This iterates through players runes and adds and removes skills as needed + * Don't Call this directly. Instead call pc.calculateSkills(). + */ + public static void calculateSkills(PlayerCharacter pc) { + if (pc == null) + return; + + ConcurrentHashMap skills = pc.getSkills(); + + //First add skills that don't exist + Race race = pc.getRace(); + if (race != null) { + CharacterSkill.grantSkills(race.getSkillsGranted(), pc); + } else + Logger.error("Failed to find Race for player " + pc.getObjectUUID()); + BaseClass bc = pc.getBaseClass(); + if (bc != null) { + CharacterSkill.grantSkills(bc.getSkillsGranted(), pc); + } else + Logger.error("Failed to find BaseClass for player " + pc.getObjectUUID()); + PromotionClass promo = pc.getPromotionClass(); + if (promo != null) + CharacterSkill.grantSkills(promo.getSkillsGranted(), pc); + ArrayList runes = pc.getRunes(); + if (runes != null) { + for (CharacterRune rune : runes) { + CharacterSkill.grantSkills(rune.getSkillsGranted(), pc); + } + } else + Logger.error("Failed to find Runes list for player " + pc.getObjectUUID()); + + //next remove any skills that no longer belong + Iterator it = skills.values().iterator(); + while (it.hasNext()) { + CharacterSkill cs = it.next(); + if (cs == null) + continue; + SkillsBase sb = cs.skillsBase; + if (sb == null) { + DbManager.CharacterSkillQueries.DELETE_SKILL(cs.getObjectUUID()); + it.remove(); + continue; + } + boolean valid = false; + if (CharacterSkill.skillAllowed(sb.getObjectUUID(), race.getSkillsGranted(), pc)) + continue; + if (CharacterSkill.skillAllowed(sb.getObjectUUID(), bc.getSkillsGranted(), pc)) + continue; + if (promo != null) + if (CharacterSkill.skillAllowed(sb.getObjectUUID(), promo.getSkillsGranted(), pc)) + continue; + for (CharacterRune rune : runes) { + if (CharacterSkill.skillAllowed(sb.getObjectUUID(), rune.getSkillsGranted(), pc)) { + valid = true; + continue; + } + } + //if skill doesn't belong to any runes, then remove it + if (!valid) { + DbManager.CharacterSkillQueries.DELETE_SKILL(cs.getObjectUUID()); + it.remove(); + } + } + CharacterSkill.updateAllBaseAmounts(pc); + CharacterSkill.updateAllModifiedAmounts(pc); + CharacterPower.calculatePowers(pc); + } + + /* + *This grants skills for specific runes + */ + private static void grantSkills(ArrayList skillsGranted, PlayerCharacter pc) { + ConcurrentHashMap skills = pc.getSkills(); + if (skills == null) + return; + + for (SkillReq skillreq : skillsGranted) { + SkillsBase skillsBase = skillreq.getSkillsBase(); + + //If player not high enough level for skill, then skip + if (pc.getLevel() < skillreq.getLevel()) + continue; + //If player doesn't have prereq skills high enough then skip + boolean valid = true; + for (byte prereqSkill : skillreq.getSkillReqs()) { + SkillsBase sb = null; + sb = DbManager.SkillsBaseQueries.GET_BASE(prereqSkill); + if (sb != null) { + if (skills.containsKey(sb.getName())) { + if (validForWarrior(pc, skills.get(sb.getName()), skillreq)) { + valid = true; + break; //add if any prereq skills met + } else if (skills.get(sb.getName()).modifiedAmountBeforeMods >= 80) { + valid = true; + break; //add if any prereq skills met + // allow blade masters to use blade master without training sword above 80.. + } else if (skillsBase.getObjectUUID() == 9) { + valid = true; + break; + } + + } + } else { + Logger.error("Failed to find SkillsBase of ID " + prereqSkill); + } + valid = false; + } + // Throwing does not need axe,dagger, or hammer at 80% + if (skillreq.getSkillID() == 43) + valid = true; + if (!valid) + continue; + + //Skill valid for player. Add if don't already have + if (skillsBase != null) { + if (!skills.containsKey(skillsBase.getName())) { + CharacterSkill newSkill = new CharacterSkill(skillsBase, pc); + CharacterSkill cs = null; + try { + cs = DbManager.CharacterSkillQueries.ADD_SKILL(newSkill); + } catch (Exception e) { + cs = null; + } + if (cs != null) { + cs.requiredLevel = (int) skillreq.getLevel(); + skills.put(skillsBase.getName(), cs); + } else + Logger.error("Failed to add CharacterSkill to player " + pc.getObjectUUID()); + } else { + CharacterSkill cs = skills.get(skillsBase.getName()); + if (cs != null && cs.requiredLevel == 0) { + cs.requiredLevel = (int) skillreq.getLevel(); + } + } + + } else + Logger.error("Failed to find SkillsBase for SkillReq " + skillreq.getObjectUUID()); + } + } + + private static boolean validForWarrior(PlayerCharacter pc, CharacterSkill skill, SkillReq skillreq) { + if (pc.getPromotionClass() == null || pc.getPromotionClass().getObjectUUID() != 2518 || skill == null || skillreq == null) + return false; //not a warrior + int sID = (skill.skillsBase != null) ? skill.skillsBase.getObjectUUID() : 0; + switch (skillreq.getSkillID()) { + case 3: //Axe mastery + case 19: //Great axe mastery + return (sID == 4) ? (skill.modifiedAmountBeforeMods >= 50) : false; + case 15: //Dagger mastery + return (sID == 16) ? (skill.modifiedAmountBeforeMods >= 50) : false; + case 20: //Great hammer mastery + case 22: //Hammer mastery + return (sID == 23) ? (skill.modifiedAmountBeforeMods >= 50) : false; + case 28: //Polearm mastery + return (sID == 29) ? (skill.modifiedAmountBeforeMods >= 50) : false; + case 21: //Great sword mastery + case 39: //Sword mastery + return (sID == 40) ? (skill.modifiedAmountBeforeMods >= 50) : false; + case 34: //Spear mastery + return (sID == 35) ? (skill.modifiedAmountBeforeMods >= 50) : false; + case 36: //Staff mastery + return (sID == 37) ? (skill.modifiedAmountBeforeMods >= 50) : false; + case 45: //Unarmed combat mastery + return (sID == 46) ? (skill.modifiedAmountBeforeMods >= 50) : false; + case 40: + return true; + case 9: + return true; + default: + } + return false; + } + + /* + * This verifies if a skill is valid for a players rune + */ + private static boolean skillAllowed(int UUID, ArrayList skillsGranted, PlayerCharacter pc) { + ConcurrentHashMap skills = pc.getSkills(); + for (SkillReq skillreq : skillsGranted) { + SkillsBase sb = skillreq.getSkillsBase(); + if (sb != null) { + if (sb.getObjectUUID() == UUID) { + if (skillreq.getLevel() <= pc.getLevel()) { + SkillsBase sbp = null; + if (skillreq.getSkillReqs().size() == 0) + return true; + for (byte prereqSkill : skillreq.getSkillReqs()) { + sbp = DbManager.SkillsBaseQueries.GET_BASE(prereqSkill); + if (sbp != null && skills.containsKey(sbp.getName())) { + if (validForWarrior(pc, skills.get(sbp.getName()), skillreq)) { + return true; + } else if (skills.get(sbp.getName()).modifiedAmountBeforeMods >= 80) + return true; + } + } + + if (skillreq.getSkillID() == 43) + return true; + if (skillreq.getSkillID() == 9) + return true; + } + } + } else + Logger.error("Failed to find SkillsBase for SkillReq " + skillreq.getObjectUUID()); + } + return false; + } + + //Print skills for player for debugging + public static void printSkills(PlayerCharacter pc) { + if (pc == null) + return; + ConcurrentHashMap skills = pc.getSkills(); + String out = "Player: " + pc.getObjectUUID() + ", SkillCount: " + skills.size(); + Iterator it = skills.keySet().iterator(); + while (it.hasNext()) { + String name = it.next(); + out += ", " + name; + } + Logger.info(out); + } + + public static int getMaxTrains(int intt) { + if (intt > 0 && intt < 191) + return CharacterSkill.maxTrains[intt]; + else + return (int) (33 + 1.25 * intt - 0.005 * Math.pow(intt, 2)); + } + + private float getATR(AbstractCharacter ac) { + return (((int) this.modifiedAmount * 7) + (ac.getStatDexCurrent() / 2)); + } + + public synchronized boolean train(PlayerCharacter pc) { + if (pc == null || this.skillsBase == null) + return false; + + boolean running = false; + + //trying out a table lookup + int intt = (int) pc.statIntBase; + int maxTrains = 0; + if (intt > 0 && intt < 191) + maxTrains = CharacterSkill.maxTrains[intt]; + else + maxTrains = (int) (33 + 1.25 * (int) pc.statIntBase - 0.005 * Math.pow((int) pc.statIntBase, 2)); + + + int oldTrains = this.numTrains.get(); + boolean succeeded = true; + if (pc.getTrainsAvailable() <= 0) + return false; + if (oldTrains == maxTrains) //at gold, stop here + return false; + else if (oldTrains > maxTrains) //catch incase we somehow go over + this.numTrains.set(maxTrains); + else //add the train + succeeded = this.numTrains.compareAndSet(oldTrains, oldTrains + 1); + + if (this.numTrains.get() > maxTrains) { //double check not over max trains + this.numTrains.set(maxTrains); + succeeded = false; + } + + if (succeeded) { + this.trained = true; + + //subtract from trains available + pc.modifyTrainsAvailable(-1); + + //update database + pc.addDatabaseJob("Skills", MBServerStatics.THIRTY_SECONDS); + + //recalculate this skill + calculateBaseAmount(); + calculateModifiedAmount(); + + //see if any new skills or powers granted + pc.calculateSkills(); + + //reapply all bonuses + pc.applyBonuses(); + + //update cache if running trains change + if (running) + pc.incVer(); + + return true; + } else + return false; + } + + public float getTrainingCost(PlayerCharacter pc, NPC trainer) { + int charLevel = pc.getLevel(); + int skillRank = this.getNumTrains() - 1 + this.requiredLevel; + float baseCost = 15 * this.requiredLevel; //TODO GET BASE COSTS OF SKILLS. + + + float sellPercent = -.20f; + float cost; + float const5; + int const2 = 1; + float const3 = 50; + float const4 = const3 + const2; + + if (charLevel > 50) + const5 = 50 / const4; + else + const5 = charLevel / const4; + + const5 = 1 - const5; + const5 = (float) (Math.log(const5) / Math.log(2) * .75f); + float rounded5 = Math.round(const5); + const5 = rounded5 - const5; + + const5 *= -1; + + const5 = (float) (Math.pow(2, const5) - 1); + + const5 += 1; + const5 = Math.scalb(const5, (int) rounded5); + const5 *= (charLevel - skillRank); + const5 *= sellPercent; + const5 = (float) (Math.log(const5) / Math.log(2) * 3); + rounded5 = Math.round(const5); + const5 = rounded5 - const5; + const5 *= -1; + const5 = (float) (Math.pow(2, const5) - 1); + const5 += 1; + + + const5 = Math.scalb(const5, (int) rounded5); + const5 += 1; + cost = const5 * (baseCost); + + + if (Float.isNaN(cost)) + cost = baseCost; + return cost; + } + + //Call this to refine skills and recalculate everything for pc. + public boolean refine(PlayerCharacter pc) { + return refine(pc, true); + } + + public boolean refine(PlayerCharacter pc, boolean recalculate) { + if (pc == null || this.skillsBase == null) + return false; + + int oldTrains = this.numTrains.get(); + boolean succeeded = true; + if (this.getNumTrains() < 1) + return false; + succeeded = this.numTrains.compareAndSet(oldTrains, oldTrains - 1); + if (succeeded) { + this.trained = true; + + //add to trains available + pc.modifyTrainsAvailable(1); + + //update database + pc.addDatabaseJob("Skills", MBServerStatics.THIRTY_SECONDS); + + if (recalculate) { + //recalculate this skill + calculateBaseAmount(); + calculateModifiedAmount(); + + //see if any skills or powers removed + pc.calculateSkills(); + + //reapply all bonuses + pc.applyBonuses(); + } + + return true; + } else + return false; + } + + /* + * Serializing + */ + + public boolean reset(PlayerCharacter pc, boolean recalculate) { + if (pc == null || this.skillsBase == null) + return false; + + int oldTrains = this.numTrains.get(); + boolean succeeded = true; + if (this.getNumTrains() < 1) + return false; + succeeded = this.numTrains.compareAndSet(oldTrains, 0); + if (succeeded) { + this.trained = true; + + //add to trains available + pc.modifyTrainsAvailable(oldTrains); + + //update database + pc.addDatabaseJob("Skills", MBServerStatics.THIRTY_SECONDS); + + if (recalculate) { + //recalculate this skill + calculateBaseAmount(); + calculateModifiedAmount(); + + //see if any skills or powers removed + pc.calculateSkills(); + + //reapply all bonuses + pc.applyBonuses(); + } + + return true; + } else + return false; + } + + /* + * Returns Skill Base for skill + */ + public SkillsBase getSkillsBase() { + return this.skillsBase; + } + + /* + * Returns number of trains in skill + */ + public int getNumTrains() { + return this.numTrains.get(); + } + + /* + * Returns Skill% before trains added + */ + public float getBaseAmount() { + return this.baseAmount; + } + + /* + * Returns Skill% after trains added + */ + public float getModifiedAmount() { + return this.modifiedAmount; + } + + /* + * Returns Skill% before trains added, minus bonus from equip and effects + */ + public float getBaseAmountBeforeMods() { + return this.baseAmountBeforeMods; + } + + /* + * Returns Skill% after trains added, minus bonus from equip and effects + */ + public float getModifiedAmountBeforeMods() { + return this.modifiedAmountBeforeMods; + } + + public String getName() { + if (this.skillsBase != null) + return this.skillsBase.getName(); + return ""; + } + + public int getToken() { + if (this.skillsBase != null) + return this.skillsBase.getToken(); + return 0; + } + + public boolean isTrained() { + return trained; + } + + public void syncTrains() { + this.trained = false; + } + + /** + * @ Calculates Base Skill Percentage + * Call this when stats change for a player + */ + public void calculateBaseAmount() { + if (CharacterSkill.GetOwner(this) == null) { + Logger.error("owner not found for owner uuid : " + this.ownerUID); + this.baseAmount = 1; + this.modifiedAmount = 1; + return; + } + + if (this.skillsBase == null) { + Logger.error("SkillsBase not found for skill " + this.getObjectUUID()); + this.baseAmount = 1; + this.modifiedAmount = 1; + return; + } + + //Get any rune bonus + float bonus = 0f; + //runes will already be calculated + if (CharacterSkill.GetOwner(this).getBonuses() != null) { + //Get bonuses from runes + bonus = CharacterSkill.GetOwner(this).getBonuses().getSkillBonus(this.skillsBase.sourceType); + } + + //Get Base skill for unmodified stats + float base = 7f; + float statMod = 0.5f; + if (this.skillsBase.getStrMod() > 0) + statMod += (float) this.skillsBase.getStrMod() * (float) (int) ((PlayerCharacter) CharacterSkill.GetOwner(this)).statStrBase / 100f; + if (this.skillsBase.getDexMod() > 0) + statMod += (float) this.skillsBase.getDexMod() * (float) (int) ((PlayerCharacter) CharacterSkill.GetOwner(this)).statDexBase / 100f; + if (this.skillsBase.getConMod() > 0) + statMod += (float) this.skillsBase.getConMod() * (float) (int) ((PlayerCharacter) CharacterSkill.GetOwner(this)).statConBase / 100f; + if (this.skillsBase.getIntMod() > 0) + statMod += (float) this.skillsBase.getIntMod() * (float) (int) ((PlayerCharacter) CharacterSkill.GetOwner(this)).statIntBase / 100f; + if (this.skillsBase.getSpiMod() > 0) + statMod += (float) this.skillsBase.getSpiMod() * (float) (int) ((PlayerCharacter) CharacterSkill.GetOwner(this)).statSpiBase / 100f; + if (statMod < 1) + statMod = 1f; + else if (statMod > 600) + statMod = 600f; + base += CharacterSkill.baseSkillValues[(int) statMod]; + + if (base + bonus < 1f) + this.baseAmountBeforeMods = 1f; + else + this.baseAmountBeforeMods = base + bonus; + this.modifiedAmountBeforeMods = Math.round(this.baseAmountBeforeMods + calculateAmountAfterTrains()); + } + + public void calculateMobBaseAmount() { + if (CharacterSkill.GetOwner(this) == null) { + Logger.error("owner not found for owner uuid : " + this.ownerUID); + this.baseAmount = 1; + this.modifiedAmount = 1; + return; + } + + if (this.skillsBase == null) { + Logger.error("SkillsBase not found for skill " + this.getObjectUUID()); + this.baseAmount = 1; + this.modifiedAmount = 1; + return; + } + + //Get any rune bonus + float bonus = 0f; + //TODO SKILLS RUNES + + if (CharacterSkill.GetOwner(this).getBonuses() != null) { + //Get bonuses from runes + bonus = CharacterSkill.GetOwner(this).getBonuses().getSkillBonus(this.skillsBase.sourceType); + } + + //Get Base skill for unmodified stats + float base = 7f; + float statMod = 0.5f; + if (this.skillsBase.getStrMod() > 0) + statMod += (float) this.skillsBase.getStrMod() * (float) ((Mob) CharacterSkill.GetOwner(this)).getMobBase().getMobBaseStats().getBaseStr() / 100f; + if (this.skillsBase.getDexMod() > 0) + statMod += (float) this.skillsBase.getDexMod() * (float) ((Mob) CharacterSkill.GetOwner(this)).getMobBase().getMobBaseStats().getBaseDex() / 100f; + if (this.skillsBase.getConMod() > 0) + statMod += (float) this.skillsBase.getConMod() * (float) ((Mob) CharacterSkill.GetOwner(this)).getMobBase().getMobBaseStats().getBaseCon() / 100f; + if (this.skillsBase.getIntMod() > 0) + statMod += (float) this.skillsBase.getIntMod() * (float) ((Mob) CharacterSkill.GetOwner(this)).getMobBase().getMobBaseStats().getBaseInt() / 100f; + if (this.skillsBase.getSpiMod() > 0) + statMod += (float) this.skillsBase.getSpiMod() * (float) ((Mob) CharacterSkill.GetOwner(this)).getMobBase().getMobBaseStats().getBaseSpi() / 100f; + if (statMod < 1) + statMod = 1f; + else if (statMod > 600) + statMod = 600f; + base += CharacterSkill.baseSkillValues[(int) statMod]; + + if (base + bonus < 1f) + this.baseAmountBeforeMods = 1f; + else + this.baseAmountBeforeMods = base + bonus; + this.modifiedAmountBeforeMods = (int) (this.baseAmountBeforeMods + calculateAmountAfterTrains()); + } + + public void calculateModifiedAmount() { + if (CharacterSkill.GetOwner(this) == null || this.skillsBase == null) { + Logger.error("owner or SkillsBase not found for skill " + this.getObjectUUID()); + this.baseAmount = 1; + this.modifiedAmount = 1; + return; + } + + //Get any rune bonus + float bonus = 0f; + if (CharacterSkill.GetOwner(this).getBonuses() != null) { + //Get bonuses from runes + bonus = CharacterSkill.GetOwner(this).getBonuses().getSkillBonus(this.skillsBase.sourceType); + } + + //Get Base skill for modified stats + //TODO this fomula needs verified + float base = 7f; + float statMod = 0.5f; + if (this.skillsBase.getStrMod() > 0) + statMod += (float) this.skillsBase.getStrMod() * (float) CharacterSkill.GetOwner(this).getStatStrCurrent() / 100f; + if (this.skillsBase.getDexMod() > 0) + statMod += (float) this.skillsBase.getDexMod() * (float) CharacterSkill.GetOwner(this).getStatDexCurrent() / 100f; + if (this.skillsBase.getConMod() > 0) + statMod += (float) this.skillsBase.getConMod() * (float) CharacterSkill.GetOwner(this).getStatConCurrent() / 100f; + if (this.skillsBase.getIntMod() > 0) + statMod += (float) this.skillsBase.getIntMod() * (float) CharacterSkill.GetOwner(this).getStatIntCurrent() / 100f; + if (this.skillsBase.getSpiMod() > 0) + statMod += (float) this.skillsBase.getSpiMod() * (float) CharacterSkill.GetOwner(this).getStatSpiCurrent() / 100f; + if (statMod < 1) + statMod = 1f; + else if (statMod > 600) + statMod = 600f; + base += CharacterSkill.baseSkillValues[(int) statMod]; + SourceType sourceType = SourceType.GetSourceType(this.skillsBase.getNameNoSpace()); + + //Get any rune, effect and item bonus + + if (CharacterSkill.GetOwner(this).getBonuses() != null) { + //add bonuses from effects/items and runes + base += bonus + CharacterSkill.GetOwner(this).getBonuses().getFloat(ModType.Skill, sourceType); + } + + if (base < 1f) + this.baseAmount = 1f; + else + this.baseAmount = base; + + float modAmount = this.baseAmount + calculateAmountAfterTrains(); + + if (CharacterSkill.GetOwner(this).getBonuses() != null) { + //Multiply any percent bonuses + modAmount *= (1 + CharacterSkill.GetOwner(this).getBonuses().getFloatPercentAll(ModType.Skill, sourceType)); + } + + this.modifiedAmount = (int) (modAmount); + } + + /** + * @ Calculates Modified Skill Percentage + * Call this when number of trains change for skill + */ + public float calculateAmountAfterTrains() { + if (this.skillsBase == null) { + Logger.error("SkillsBase not found for skill " + this.getObjectUUID()); + this.modifiedAmount = this.baseAmount; + } + int amount; + + int trains = this.numTrains.get(); + if (trains < 10) + amount = (trains * 2); + else if (trains < 90) + amount = 10 + trains; + else if (trains < 134) + amount = 100 + ((trains - 90) / 2); + else + amount = 122 + ((trains - 134) / 3); + + return amount; + } + + public int getSkillPercentFromAttributes() { + AbstractCharacter ac = CharacterSkill.GetOwner(this); + + if (ac == null) + return 0; + + float statMod = 0; + + if (this.skillsBase.getStrMod() > 0) { + float strengthModPercent = (float) this.skillsBase.getStrMod() * .01f; + strengthModPercent *= ac.getStatStrCurrent() * .01f + .6f; + statMod += strengthModPercent; + } + + if (this.skillsBase.getDexMod() > 0) { + float dexModPercent = (float) this.skillsBase.getDexMod() * .01f; + dexModPercent *= ac.getStatDexCurrent() * .01f + .6f; + statMod += dexModPercent; + } + if (this.skillsBase.getConMod() > 0) { + float conModPercent = (float) this.skillsBase.getConMod() * .01f; + conModPercent *= ac.getStatConCurrent() * .01f + .6f; + statMod += conModPercent; + } + if (this.skillsBase.getIntMod() > 0) { + float intModPercent = (float) this.skillsBase.getIntMod() * .01f; + intModPercent *= ac.getStatIntCurrent() * .01f + .6f; + statMod += intModPercent; + } + if (this.skillsBase.getSpiMod() > 0) { + float spiModPercent = (float) this.skillsBase.getSpiMod() * .01f; + spiModPercent *= ac.getStatSpiCurrent() * .01f + .6f; + statMod += spiModPercent; + } + + statMod = (float) (Math.pow(statMod, 1.5f) * 15f); + if (statMod < 1) + statMod = 1f; + else if (statMod > 600) + statMod = 600f; + + + return (int) statMod; + } + + public int getSkillPercentFromTrains() { + + int trains = this.numTrains.get(); + if (trains <= 10) + return 2 * trains; + if (trains <= 90) + return trains + 10; + if (trains > 130) + return (int) (120 - ((trains - 130) * -0.33000001)); + return (int) (100 - ((trains - 90) * -0.5)); + + } + + public int getTotalSkillPercet() { + + AbstractCharacter ac = CharacterSkill.GetOwner(this); + + if (ac == null) + return 0; + + float bonus = 0f; + SourceType sourceType = SourceType.GetSourceType(this.skillsBase.getNameNoSpace()); + if (CharacterSkill.GetOwner(this).getBonuses() != null) { + //Get bonuses from runes + bonus = CharacterSkill.GetOwner(this).getBonuses().getSkillBonus(this.skillsBase.sourceType); + } + return this.getSkillPercentFromTrains() + this.getSkillPercentFromAttributes(); + } + + @Override + public void updateDatabase() { + DbManager.CharacterSkillQueries.updateDatabase(this); + } + + public int getRequiredLevel() { + return requiredLevel; + } + + public void setRequiredLevel(int requiredLevel) { + this.requiredLevel = requiredLevel; + } } diff --git a/src/engine/objects/CharacterTitle.java b/src/engine/objects/CharacterTitle.java index 1ca8a4e6..796a7ef1 100644 --- a/src/engine/objects/CharacterTitle.java +++ b/src/engine/objects/CharacterTitle.java @@ -15,107 +15,107 @@ import java.nio.ByteBuffer; public enum CharacterTitle { - NONE(0,0,0,""), - CSR_1(255,0,0,"CCR"), - CSR_2(255,0,0,"CCR"), - CSR_3(255,0,0,"CCR"), - CSR_4(251,181,13,"CCR"), - DEVELOPER(166,153,114,"Programmer"), - QA(88,250,244,"GIRLFRIEND"); - - CharacterTitle(int _r, int _g, int _b, String _prefix) { - char[] str_header = ("^\\c" + - (((_r < 100)?((_r < 10)?"00":"0"):"") + ((byte) _r & 0xFF)) + - (((_g < 100)?((_g < 10)?"00":"0"):"") + ((byte) _g & 0xFF)) + - (((_b < 100)?((_b < 10)?"00":"0"):"") + ((byte) _b & 0xFF)) + + NONE(0, 0, 0, ""), + CSR_1(255, 0, 0, "CCR"), + CSR_2(255, 0, 0, "CCR"), + CSR_3(255, 0, 0, "CCR"), + CSR_4(251, 181, 13, "CCR"), + DEVELOPER(166, 153, 114, "Programmer"), + QA(88, 250, 244, "GIRLFRIEND"); + + int headerLength, footerLength; + private ByteBuffer header; + private ByteBuffer footer; + + CharacterTitle(int _r, int _g, int _b, String _prefix) { + char[] str_header = ("^\\c" + + (((_r < 100) ? ((_r < 10) ? "00" : "0") : "") + ((byte) _r & 0xFF)) + + (((_g < 100) ? ((_g < 10) ? "00" : "0") : "") + ((byte) _g & 0xFF)) + + (((_b < 100) ? ((_b < 10) ? "00" : "0") : "") + ((byte) _b & 0xFF)) + '<' + _prefix + "> ").toCharArray(); - char[] str_footer = ("^\\c255255255").toCharArray(); - - this.headerLength = str_header.length; - this.footerLength = str_footer.length; - - this.header = ByteBuffer.allocateDirect(headerLength << 1); - this.footer = ByteBuffer.allocateDirect(footerLength << 1); - - ByteBufferWriter headWriter= new ByteBufferWriter(header); - - for(char c : str_header) { - headWriter.putChar(c); - } - - ByteBufferWriter footWriter = new ByteBufferWriter(footer); - - for(char c : str_footer) { - footWriter.putChar(c); - } - } - - int headerLength, footerLength; - private ByteBuffer header; - private ByteBuffer footer; - - public void _serializeFirstName(ByteBufferWriter writer, String firstName) { - _serializeFirstName(writer, firstName, false); - } - - public void _serializeFirstName(ByteBufferWriter writer, String firstName, boolean smallString) { - if(this.ordinal() == 0) { - if (smallString) - writer.putSmallString(firstName); - else - writer.putString(firstName); - return; - } - - char[] chars = firstName.toCharArray(); - - if (smallString) - writer.put((byte)(chars.length + this.headerLength)); - else - writer.putInt(chars.length + this.headerLength); - writer.putBB(header); - - for(char c : chars) { - writer.putChar(c); - } - } - - public void _serializeLastName(ByteBufferWriter writer, String lastName, boolean haln, boolean asciiLastName) { - _serializeLastName(writer, lastName, haln, asciiLastName, false); - } - - public void _serializeLastName(ByteBufferWriter writer, String lastName, boolean haln, boolean asciiLastName, boolean smallString) { - if (!haln || asciiLastName) { - if(this.ordinal() == 0) { - if (smallString) - writer.putSmallString(lastName); - else - writer.putString(lastName); - return; - } - } - - if (!haln || asciiLastName) { - char[] chars = lastName.toCharArray(); - - if (smallString) - writer.put((byte)(chars.length + this.footerLength)); - else - writer.putInt(chars.length + this.footerLength); - - for(char c : chars) { - writer.putChar(c); - } - - writer.putBB(footer); - } else { - if (smallString) - writer.put((byte)this.footerLength); - else - writer.putInt(this.footerLength); - writer.putBB(footer); - } - - } + char[] str_footer = ("^\\c255255255").toCharArray(); + + this.headerLength = str_header.length; + this.footerLength = str_footer.length; + + this.header = ByteBuffer.allocateDirect(headerLength << 1); + this.footer = ByteBuffer.allocateDirect(footerLength << 1); + + ByteBufferWriter headWriter = new ByteBufferWriter(header); + + for (char c : str_header) { + headWriter.putChar(c); + } + + ByteBufferWriter footWriter = new ByteBufferWriter(footer); + + for (char c : str_footer) { + footWriter.putChar(c); + } + } + + public void _serializeFirstName(ByteBufferWriter writer, String firstName) { + _serializeFirstName(writer, firstName, false); + } + + public void _serializeFirstName(ByteBufferWriter writer, String firstName, boolean smallString) { + if (this.ordinal() == 0) { + if (smallString) + writer.putSmallString(firstName); + else + writer.putString(firstName); + return; + } + + char[] chars = firstName.toCharArray(); + + if (smallString) + writer.put((byte) (chars.length + this.headerLength)); + else + writer.putInt(chars.length + this.headerLength); + writer.putBB(header); + + for (char c : chars) { + writer.putChar(c); + } + } + + public void _serializeLastName(ByteBufferWriter writer, String lastName, boolean haln, boolean asciiLastName) { + _serializeLastName(writer, lastName, haln, asciiLastName, false); + } + + public void _serializeLastName(ByteBufferWriter writer, String lastName, boolean haln, boolean asciiLastName, boolean smallString) { + if (!haln || asciiLastName) { + if (this.ordinal() == 0) { + if (smallString) + writer.putSmallString(lastName); + else + writer.putString(lastName); + return; + } + } + + if (!haln || asciiLastName) { + char[] chars = lastName.toCharArray(); + + if (smallString) + writer.put((byte) (chars.length + this.footerLength)); + else + writer.putInt(chars.length + this.footerLength); + + for (char c : chars) { + writer.putChar(c); + } + + writer.putBB(footer); + } else { + if (smallString) + writer.put((byte) this.footerLength); + else + writer.putInt(this.footerLength); + writer.putBB(footer); + } + + } } diff --git a/src/engine/objects/City.java b/src/engine/objects/City.java index ef5f349a..d3d36eac 100644 --- a/src/engine/objects/City.java +++ b/src/engine/objects/City.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.objects; import engine.Enum; @@ -48,594 +47,319 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; public class City extends AbstractWorldObject { - private String cityName; - private String motto; - private String description; - public java.time.LocalDateTime established; - private int isNoobIsle; //1: noob, 0: not noob: -1: not noob, no teleport - private int population = 0; - private int siegesWithstood = 0; - private int realmID; - private int radiusType; - private float bindRadius; - private float statLat; - private float statAlt; - private float statLon; - private float bindX; - private float bindZ; - private byte isNpc; //aka Safehold - private byte isCapital = 0; - private byte isSafeHold; - private boolean forceRename = false; - public boolean hasBeenTransfered = false; - - private boolean noTeleport = false; //used by npc cities - private boolean noRepledge = false; //used by npc cities - private boolean isOpen = false; - - private int treeOfLifeID; - private Vector3fImmutable location = Vector3fImmutable.ZERO; - private Vector3fImmutable bindLoc; - protected Zone parentZone; - private int warehouseBuildingID = 0; - private boolean open = false; - private boolean reverseKOS = false; - public static long lastCityUpdate = 0; - public LocalDateTime realmTaxDate; - - public ReentrantReadWriteLock transactionLock = new ReentrantReadWriteLock(); - - // Players who have entered the city (used for adding and removing affects) - - public final HashSet _playerMemory = new HashSet<>(); - - public volatile boolean protectionEnforced = true; - private String hash; - public ArrayListcityBarracks; - public ArrayList cityOutlaws = new ArrayList<>(); - - /** - * ResultSet Constructor - */ - - public City(ResultSet rs) throws SQLException { - super(rs); - try { - this.cityName = rs.getString("name"); - this.motto = rs.getString("motto"); - this.isNpc = rs.getByte("isNpc"); - this.isSafeHold = (byte) ((this.isNpc == 1) ? 1 : 0); - this.description = ""; // TODO Implement this! - this.isNoobIsle = rs.getByte("isNoobIsle"); // Noob - this.gridObjectType = GridObjectType.STATIC; - // Island - // City(00000001), - // Otherwise(FFFFFFFF) - this.population = rs.getInt("population"); - this.siegesWithstood = rs.getInt("siegesWithstood"); - - java.sql.Timestamp establishedTimeStamp = rs.getTimestamp("established"); - - if (establishedTimeStamp != null) - this.established = java.time.LocalDateTime.ofInstant(establishedTimeStamp.toInstant(), ZoneId.systemDefault()); - - this.location = new Vector3fImmutable(rs.getFloat("xCoord"), rs.getFloat("yCoord"), rs.getFloat("zCoord")); - this.statLat = rs.getFloat("xCoord"); - this.statAlt = rs.getFloat("yCoord"); - this.statLon = rs.getFloat("zCoord"); - - java.sql.Timestamp realmTaxTimeStamp = rs.getTimestamp("realmTaxDate"); - - if (realmTaxTimeStamp != null) - this.realmTaxDate = realmTaxTimeStamp.toLocalDateTime(); - - if (this.realmTaxDate == null) - this.realmTaxDate = LocalDateTime.now(); - - this.treeOfLifeID = rs.getInt("treeOfLifeUUID"); - this.bindX = rs.getFloat("bindX"); - this.bindZ = rs.getFloat("bindZ"); - this.bindLoc = new Vector3fImmutable(this.location.getX() + this.bindX, - this.location.getY(), - this.location.getZ() + this.bindZ); - this.radiusType = rs.getInt("radiusType"); - float bindradiustemp = rs.getFloat("bindRadius"); - if (bindradiustemp > 2) - bindradiustemp -=2; - - this.bindRadius = bindradiustemp; - - this.forceRename = rs.getInt("forceRename") == 1; - this.open = rs.getInt("open") == 1; - - if (this.cityName.equals("Perdition") || this.cityName.equals("Bastion")) { - this.noTeleport = true; - this.noRepledge = true; - } else { - this.noTeleport = false; - this.noRepledge = false; - } - - this.hash = rs.getString("hash"); - - if (this.motto.isEmpty()){ - Guild guild = this.getGuild(); - - if (guild != null && guild.isEmptyGuild() == false) - this.motto = guild.getMotto(); - } - - - //Disabled till i finish. - // this.reverseKOS = rs.getInt("kos") == 1; - - - Zone zone = ZoneManager.getZoneByUUID(rs.getInt("parent")); - - if (zone != null) - setParent(zone); - - //npc cities without heightmaps except swampstone are specials. - - - - this.realmID = rs.getInt("realmID"); - - }catch(Exception e){ - Logger.error(e); - } - - // *** Refactor: Is this working? Intended to supress - // login server errors from attempting to - // load cities/realms along with players - - - - } - - /* - * Utils - */ - - public boolean renameCity(String cityName){ - if (!DbManager.CityQueries.renameCity(this, cityName)) - return false; - if (!DbManager.CityQueries.updateforceRename(this, false)) - return false; - - this.cityName = cityName; - this.forceRename = false; - return true; - } - - public boolean updateTOL(Building tol){ - if (tol == null) - return false; - if (!DbManager.CityQueries.updateTOL(this, tol.getObjectUUID())) - return false; - this.treeOfLifeID = tol.getObjectUUID(); - return true; - } - - public boolean renameCityForNewPlant(String cityName){ - if (!DbManager.CityQueries.renameCity(this, cityName)) - return false; - if (!DbManager.CityQueries.updateforceRename(this, true)) - return false; - - this.cityName = cityName; - this.forceRename = true; - return true; - } - - public void setForceRename(boolean forceRename) { - if (!DbManager.CityQueries.updateforceRename(this, forceRename)) - return; - this.forceRename = forceRename; - } - public String getCityName() { - - return cityName; - } - - public String getMotto() { - return motto; - } - - public String getDescription() { - return description; - } - - public Building getTOL() { - if (this.treeOfLifeID == 0) - return null; - - return BuildingManager.getBuildingFromCache(this.treeOfLifeID); - - } - - public int getIsNoobIsle() { - return isNoobIsle; - } - - public int getPopulation() { - return population; - } - - public int getSiegesWithstood() { - return siegesWithstood; - } + public static long lastCityUpdate = 0; + public final HashSet _playerMemory = new HashSet<>(); + public java.time.LocalDateTime established; + public boolean hasBeenTransfered = false; + public LocalDateTime realmTaxDate; + public ReentrantReadWriteLock transactionLock = new ReentrantReadWriteLock(); + public volatile boolean protectionEnforced = true; + public ArrayList cityBarracks; + public ArrayList cityOutlaws = new ArrayList<>(); + protected Zone parentZone; + private String cityName; + private String motto; + private String description; + private int isNoobIsle; //1: noob, 0: not noob: -1: not noob, no teleport + private int population = 0; + private int siegesWithstood = 0; + private int realmID; + private int radiusType; + private float bindRadius; + private float statLat; + private float statAlt; + private float statLon; + private float bindX; + private float bindZ; + private byte isNpc; //aka Safehold + private byte isCapital = 0; + private byte isSafeHold; + private boolean forceRename = false; + private boolean noTeleport = false; //used by npc cities + private boolean noRepledge = false; //used by npc cities + private boolean isOpen = false; + private int treeOfLifeID; + private Vector3fImmutable location = Vector3fImmutable.ZERO; + + // Players who have entered the city (used for adding and removing affects) + private Vector3fImmutable bindLoc; + private int warehouseBuildingID = 0; + private boolean open = false; + private boolean reverseKOS = false; + private String hash; + + /** + * ResultSet Constructor + */ + + public City(ResultSet rs) throws SQLException { + super(rs); + try { + this.cityName = rs.getString("name"); + this.motto = rs.getString("motto"); + this.isNpc = rs.getByte("isNpc"); + this.isSafeHold = (byte) ((this.isNpc == 1) ? 1 : 0); + this.description = ""; // TODO Implement this! + this.isNoobIsle = rs.getByte("isNoobIsle"); // Noob + this.gridObjectType = GridObjectType.STATIC; + // Island + // City(00000001), + // Otherwise(FFFFFFFF) + this.population = rs.getInt("population"); + this.siegesWithstood = rs.getInt("siegesWithstood"); + + java.sql.Timestamp establishedTimeStamp = rs.getTimestamp("established"); + + if (establishedTimeStamp != null) + this.established = java.time.LocalDateTime.ofInstant(establishedTimeStamp.toInstant(), ZoneId.systemDefault()); + + this.location = new Vector3fImmutable(rs.getFloat("xCoord"), rs.getFloat("yCoord"), rs.getFloat("zCoord")); + this.statLat = rs.getFloat("xCoord"); + this.statAlt = rs.getFloat("yCoord"); + this.statLon = rs.getFloat("zCoord"); + + java.sql.Timestamp realmTaxTimeStamp = rs.getTimestamp("realmTaxDate"); + + if (realmTaxTimeStamp != null) + this.realmTaxDate = realmTaxTimeStamp.toLocalDateTime(); + + if (this.realmTaxDate == null) + this.realmTaxDate = LocalDateTime.now(); + + this.treeOfLifeID = rs.getInt("treeOfLifeUUID"); + this.bindX = rs.getFloat("bindX"); + this.bindZ = rs.getFloat("bindZ"); + this.bindLoc = new Vector3fImmutable(this.location.getX() + this.bindX, + this.location.getY(), + this.location.getZ() + this.bindZ); + this.radiusType = rs.getInt("radiusType"); + float bindradiustemp = rs.getFloat("bindRadius"); + if (bindradiustemp > 2) + bindradiustemp -= 2; + + this.bindRadius = bindradiustemp; + + this.forceRename = rs.getInt("forceRename") == 1; + this.open = rs.getInt("open") == 1; + + if (this.cityName.equals("Perdition") || this.cityName.equals("Bastion")) { + this.noTeleport = true; + this.noRepledge = true; + } else { + this.noTeleport = false; + this.noRepledge = false; + } + + this.hash = rs.getString("hash"); + + if (this.motto.isEmpty()) { + Guild guild = this.getGuild(); + + if (guild != null && guild.isEmptyGuild() == false) + this.motto = guild.getMotto(); + } + + + //Disabled till i finish. + // this.reverseKOS = rs.getInt("kos") == 1; - public float getLatitude() { - return this.location.x; - } - public float getLongitude() { - return this.location.z; - } - - public float getAltitude() { - return this.location.y; - } + Zone zone = ZoneManager.getZoneByUUID(rs.getInt("parent")); - @Override - public Vector3fImmutable getLoc() { - return this.location; - } + if (zone != null) + setParent(zone); - public byte getIsNpcOwned() { - return isNpc; - } + //npc cities without heightmaps except swampstone are specials. - public byte getIsSafeHold() { - return this.isSafeHold; - } - public boolean isSafeHold() { - return (this.isSafeHold == (byte) 1); - } - - public byte getIsCapital() { - return isCapital; - } - - public void setIsCapital(boolean state) { - this.isCapital = (state) ? (byte) 1 : (byte) 0; - } - - public int getRadiusType() { - return this.radiusType; - } - - public float getBindRadius() { - return this.bindRadius; - } - - public int getRank() { - return (this.getTOL() == null) ? 0 : this.getTOL().getRank(); - } - - public Bane getBane() { - return Bane.getBane(this.getObjectUUID()); - } - - public void setParent(Zone zone) { - - try { - - - this.parentZone = zone; - this.location = new Vector3fImmutable(zone.absX + statLat, zone.absY + statAlt, zone.absZ + statLon); - this.bindLoc = new Vector3fImmutable(this.location.x + this.bindX, - this.location.y, - this.location.z + this.bindZ); + this.realmID = rs.getInt("realmID"); - // set city bounds + } catch (Exception e) { + Logger.error(e); + } - Bounds cityBounds = Bounds.borrow(); - cityBounds.setBounds(new Vector2f(this.location.x + 64, this.location.z + 64), // location x and z are offset by 64 from the center of the city. - new Vector2f(Enum.CityBoundsType.GRID.extents, Enum.CityBoundsType.GRID.extents), - 0.0f); - this.setBounds(cityBounds); - - if (zone.getHeightMap() == null && this.isNpc == 1 && this.getObjectUUID() != 1213 ){ - HeightMap.GenerateCustomHeightMap(zone); - Logger.info(zone.getName() + " created custom heightmap"); - } - }catch(Exception e){ - Logger.error(e); - } - } + // *** Refactor: Is this working? Intended to supress + // login server errors from attempting to + // load cities/realms along with players - public Zone getParent() { - return this.parentZone; - } - public boolean isCityZone(Zone zone) { + } - if (zone == null || this.parentZone == null) - return false; + /* + * Utils + */ - return zone.getObjectUUID() == this.parentZone.getObjectUUID(); + public static void _serializeForClientMsg(City city, ByteBufferWriter writer) { + City.serializeForClientMsg(city, writer); + } - } + public static void serializeForClientMsg(City city, ByteBufferWriter writer) { + AbstractCharacter guildRuler; + Guild rulingGuild; + Guild rulingNation; + java.time.LocalDateTime dateTime1900; - public AbstractCharacter getOwner() { + // Cities aren't a city without a TOL. Time to early exit. + // No need to spam the log here as non-existant TOL's are indicated + // during bootstrap routines. - if (this.getTOL() == null) - return null; + if (city.getTOL() == null) { - int ownerID = this.getTOL().getOwnerUUID(); + Logger.error("NULL TOL FOR " + city.cityName); + } - if (ownerID == 0) - return null; - if (this.isNpc == 1) - return NPC.getNPC(ownerID); - else - return PlayerCharacter.getPlayerCharacter(ownerID); - } + // Assign city owner - public Guild getGuild() { + if (city.getTOL() != null) + guildRuler = city.getTOL().getOwner(); + else + guildRuler = null; - if (this.getTOL() == null) - return null; + // If is an errant tree, use errant guild for serialization. + // otherwise we serialize the soverign guild + if (guildRuler == null) + rulingGuild = Guild.getErrantGuild(); + else + rulingGuild = guildRuler.getGuild(); + rulingNation = rulingGuild.getNation(); - if (this.isNpc == 1) { + // Begin Serialzing soverign guild data + writer.putInt(city.getObjectType().ordinal()); + writer.putInt(city.getObjectUUID()); + writer.putString(city.cityName); + writer.putInt(rulingGuild.getObjectType().ordinal()); + writer.putInt(rulingGuild.getObjectUUID()); - if (this.getTOL().getOwner() == null) - return null; - return this.getTOL().getOwner().getGuild(); - } else { - if (this.getTOL().getOwner() == null) - return null; - return this.getTOL().getOwner().getGuild(); - } - } + writer.putString(rulingGuild.getName()); + writer.putString(city.motto); + writer.putString(rulingGuild.getLeadershipType()); - public boolean openCity(boolean open){ - if (!DbManager.CityQueries.updateOpenCity(this, open)) - return false; - this.open = open; - return true; - } + // Serialize guild ruler's name + // If tree is abandoned blank out the name + // to allow them a rename. - - public static void _serializeForClientMsg(City city, ByteBufferWriter writer) { - City.serializeForClientMsg(city,writer); - } + if (guildRuler == null) + writer.putString(""); + else + writer.putString(guildRuler.getFirstName() + ' ' + guildRuler.getLastName()); - /* - * Serializing - */ + writer.putInt(rulingGuild.getCharter()); + writer.putInt(0); // always 00000000 - - public static void serializeForClientMsg(City city, ByteBufferWriter writer) { - AbstractCharacter guildRuler; - Guild rulingGuild; - Guild rulingNation; - java.time.LocalDateTime dateTime1900; + writer.put(city.isSafeHold); - // Cities aren't a city without a TOL. Time to early exit. - // No need to spam the log here as non-existant TOL's are indicated - // during bootstrap routines. + writer.put((byte) 1); + writer.put((byte) 1); // *** Refactor: What are these flags? + writer.put((byte) 1); + writer.put((byte) 1); + writer.put((byte) 1); - if (city.getTOL() == null){ + GuildTag._serializeForDisplay(rulingGuild.getGuildTag(), writer); + GuildTag._serializeForDisplay(rulingNation.getGuildTag(), writer); - Logger.error( "NULL TOL FOR " + city.cityName); - } + writer.putInt(0);// TODO Implement description text + writer.put((byte) 1); - // Assign city owner + if (city.isCapital > 0) + writer.put((byte) 1); + else + writer.put((byte) 0); - if (city.getTOL() != null) - guildRuler = city.getTOL().getOwner(); - else guildRuler = null; + writer.put((byte) 1); - // If is an errant tree, use errant guild for serialization. - // otherwise we serialize the soverign guild + // Begin serializing nation guild info - if (guildRuler == null) - rulingGuild = Guild.getErrantGuild(); - else - rulingGuild = guildRuler.getGuild(); + if (rulingNation.isEmptyGuild()) { + writer.putInt(rulingGuild.getObjectType().ordinal()); + writer.putInt(rulingGuild.getObjectUUID()); + } else { + writer.putInt(rulingNation.getObjectType().ordinal()); + writer.putInt(rulingNation.getObjectUUID()); + } - rulingNation = rulingGuild.getNation(); - // Begin Serialzing soverign guild data - writer.putInt(city.getObjectType().ordinal()); - writer.putInt(city.getObjectUUID()); - writer.putString(city.cityName); - writer.putInt(rulingGuild.getObjectType().ordinal()); - writer.putInt(rulingGuild.getObjectUUID()); + // Serialize nation name - writer.putString(rulingGuild.getName()); - writer.putString(city.motto); - writer.putString(rulingGuild.getLeadershipType()); + if (rulingNation.isEmptyGuild()) + writer.putString("None"); + else + writer.putString(rulingNation.getName()); - // Serialize guild ruler's name - // If tree is abandoned blank out the name - // to allow them a rename. + writer.putInt(city.getTOL().getRank()); - if (guildRuler == null) - writer.putString(""); - else - writer.putString(guildRuler.getFirstName() + ' ' + guildRuler.getLastName()); + if (city.isNoobIsle > 0) + writer.putInt(1); + else + writer.putInt(0xFFFFFFFF); - writer.putInt(rulingGuild.getCharter()); - writer.putInt(0); // always 00000000 + writer.putInt(city.population); - writer.put(city.isSafeHold); + if (rulingNation.isEmptyGuild()) + writer.putString(" "); + else + writer.putString(Guild.GetGL(rulingNation).getFirstName() + ' ' + Guild.GetGL(rulingNation).getLastName()); - writer.put((byte) 1); - writer.put((byte) 1); // *** Refactor: What are these flags? - writer.put((byte) 1); - writer.put((byte) 1); - writer.put((byte) 1); - GuildTag._serializeForDisplay(rulingGuild.getGuildTag(),writer); - GuildTag._serializeForDisplay(rulingNation.getGuildTag(),writer); + writer.putLocalDateTime(city.established); - writer.putInt(0);// TODO Implement description text +// writer.put((byte) city.established.getDayOfMonth()); +// writer.put((byte) city.established.minusMonths(1).getMonth().getValue()); +// writer.putInt((int) years); +// writer.put((byte) hours); +// writer.put((byte) minutes); +// writer.put((byte) seconds); - writer.put((byte) 1); + writer.putFloat(city.location.x); + writer.putFloat(city.location.y); + writer.putFloat(city.location.z); - if (city.isCapital > 0) - writer.put((byte) 1); - else - writer.put((byte) 0); + writer.putInt(city.siegesWithstood); - writer.put((byte) 1); + writer.put((byte) 1); + writer.put((byte) 0); + writer.putInt(0x64); + writer.put((byte) 0); + writer.put((byte) 0); + writer.put((byte) 0); + } - // Begin serializing nation guild info + public static Vector3fImmutable getBindLoc(int cityID) { - if (rulingNation.isEmptyGuild()){ - writer.putInt(rulingGuild.getObjectType().ordinal()); - writer.putInt(rulingGuild.getObjectUUID()); - } + City city; - else{ - writer.putInt(rulingNation.getObjectType().ordinal()); - writer.putInt(rulingNation.getObjectUUID()); - } + city = City.getCity(cityID); + if (city == null) + return Enum.Ruins.getRandomRuin().getLocation(); - // Serialize nation name + return city.getBindLoc(); + } - if (rulingNation.isEmptyGuild()) - writer.putString("None"); - else - writer.putString(rulingNation.getName()); + public static ArrayList getCitiesToTeleportTo(PlayerCharacter pc) { - writer.putInt(city.getTOL().getRank()); + ArrayList cities = new ArrayList<>(); - if (city.isNoobIsle > 0) - writer.putInt(1); - else - writer.putInt(0xFFFFFFFF); + if (pc == null) + return cities; - writer.putInt(city.population); + Guild pcG = pc.getGuild(); - if (rulingNation.isEmptyGuild()) - writer.putString(" "); - else - writer.putString(Guild.GetGL(rulingNation).getFirstName() + ' ' + Guild.GetGL(rulingNation).getLastName()); + ConcurrentHashMap worldCities = DbManager.getMap(Enum.GameObjectType.City); + //add npc cities + for (AbstractGameObject ago : worldCities.values()) { - writer.putLocalDateTime(city.established); + if (ago.getObjectType().equals(GameObjectType.City)) { + City city = (City) ago; -// writer.put((byte) city.established.getDayOfMonth()); -// writer.put((byte) city.established.minusMonths(1).getMonth().getValue()); -// writer.putInt((int) years); -// writer.put((byte) hours); -// writer.put((byte) minutes); -// writer.put((byte) seconds); + if (city.noTeleport) + continue; - writer.putFloat(city.location.x); - writer.putFloat(city.location.y); - writer.putFloat(city.location.z); - - writer.putInt(city.siegesWithstood); - - writer.put((byte) 1); - writer.put((byte) 0); - writer.putInt(0x64); - writer.put((byte) 0); - writer.put((byte) 0); - writer.put((byte) 0); - } - - public static Vector3fImmutable getBindLoc(int cityID) { - - City city; - - city = City.getCity(cityID); - - if (city == null) - return Enum.Ruins.getRandomRuin().getLocation(); - - return city.getBindLoc(); - } - - public Vector3fImmutable getBindLoc() { - Vector3fImmutable treeLoc = null; - - if (this.getTOL() != null && this.getTOL().getRank() == 8) - treeLoc = this.getTOL().getStuckLocation(); - - if (treeLoc != null) - return treeLoc; - - if (this.radiusType == 1 && this.bindRadius > 0f) { - //square radius - float x = this.bindLoc.getX(); - float z = this.bindLoc.getZ(); - float offset = ((ThreadLocalRandom.current().nextFloat() * 2) - 1) * this.bindRadius; - int direction = ThreadLocalRandom.current().nextInt(4); - - switch (direction) { - case 0: - x += this.bindRadius; - z += offset; - break; - case 1: - x += offset; - z -= this.bindRadius; - break; - case 2: - x -= this.bindRadius; - z += offset; - break; - case 3: - x += offset; - z += this.bindRadius; - break; - } - return new Vector3fImmutable(x, this.bindLoc.getY(), z); - } else if (this.radiusType == 2 && this.bindRadius > 0f) { - //circle radius - Vector3fImmutable dir = FastMath.randomVector2D(); - return this.bindLoc.scaleAdd(this.bindRadius, dir); - } else if (this.radiusType == 3 && this.bindRadius > 0f) { - //random inside square - float x = this.bindLoc.getX(); - x += ((ThreadLocalRandom.current().nextFloat() * 2) - 1) * this.bindRadius; - float z = this.bindLoc.getZ(); - z += ((ThreadLocalRandom.current().nextFloat() * 2) - 1) * this.bindRadius; - return new Vector3fImmutable(x, this.bindLoc.getY(), z); - } else if (this.radiusType == 4 && this.bindRadius > 0f) { - //random inside circle - Vector3fImmutable dir = FastMath.randomVector2D(); - return this.bindLoc.scaleAdd(ThreadLocalRandom.current().nextFloat() * this.bindRadius, dir); - } else - //spawn at bindLoc - //System.out.println("x: " + this.bindLoc.x + ", z: " + this.bindLoc.z); - return this.bindLoc; - } - - public static ArrayList getCitiesToTeleportTo(PlayerCharacter pc) { - - ArrayList cities = new ArrayList<>(); - - if (pc == null) - return cities; - - Guild pcG = pc.getGuild(); - - ConcurrentHashMap worldCities = DbManager.getMap(Enum.GameObjectType.City); - - //add npc cities - for (AbstractGameObject ago : worldCities.values()) { - - if (ago.getObjectType().equals(GameObjectType.City)) { - City city = (City) ago; - - if (city.noTeleport) - continue; - - if (city.parentZone != null && city.parentZone.isPlayerCity()) { + if (city.parentZone != null && city.parentZone.isPlayerCity()) { if (pc.getAccount().status.equals(AccountStatus.ADMIN)) { cities.add(city); @@ -647,68 +371,51 @@ public class City extends AbstractWorldObject { if (!BuildingManager.IsPlayerHostile(city.getTOL(), pc)) cities.add(city); //verify nation or guild is same - } - - else if (Guild.sameNationExcludeErrant(city.getGuild(), pcG)) - cities.add(city); - + } else if (Guild.sameNationExcludeErrant(city.getGuild(), pcG)) + cities.add(city); - } else if (city.isNpc == 1) { - //list NPC cities - Guild g = city.getGuild(); - if (g == null) { - if (city.isNpc == 1) - if (city.isNoobIsle == 1) { - if (pc.getLevel() < 21) - cities.add(city); - } else if (pc.getLevel() > 9) - cities.add(city); - } else if (pc.getLevel() >= g.getTeleportMin() && pc.getLevel() <= g.getTeleportMax()){ + } else if (city.isNpc == 1) { + //list NPC cities + Guild g = city.getGuild(); + if (g == null) { + if (city.isNpc == 1) + if (city.isNoobIsle == 1) { + if (pc.getLevel() < 21) + cities.add(city); + } else if (pc.getLevel() > 9) + cities.add(city); + } else if (pc.getLevel() >= g.getTeleportMin() && pc.getLevel() <= g.getTeleportMax()) { - cities.add(city); - } - } + cities.add(city); + } + } - } - } - - return cities; - } - - public NPC getRuneMaster() { - NPC outNPC = null; - - if (this.getTOL() == null) - return outNPC; - for (AbstractCharacter npc : getTOL().getHirelings().keySet()) { - if (npc.getObjectType() == GameObjectType.NPC) - if (((NPC)npc).getContract().isRuneMaster() == true) - outNPC = (NPC)npc; - } + } + } - return outNPC; - } + return cities; + } - public static ArrayList getCitiesToRepledgeTo(PlayerCharacter pc) { - ArrayList cities = new ArrayList<>(); - if (pc == null) - return cities; - Guild pcG = pc.getGuild(); + public static ArrayList getCitiesToRepledgeTo(PlayerCharacter pc) { + ArrayList cities = new ArrayList<>(); + if (pc == null) + return cities; + Guild pcG = pc.getGuild(); - ConcurrentHashMap worldCities = DbManager.getMap(Enum.GameObjectType.City); + ConcurrentHashMap worldCities = DbManager.getMap(Enum.GameObjectType.City); - //add npc cities - for (AbstractGameObject ago : worldCities.values()) { - if (ago.getObjectType().equals(GameObjectType.City)) { - City city = (City) ago; - if (city.noRepledge) - continue; + //add npc cities + for (AbstractGameObject ago : worldCities.values()) { + if (ago.getObjectType().equals(GameObjectType.City)) { + City city = (City) ago; + if (city.noRepledge) + continue; - if (city.parentZone != null && city.parentZone.isPlayerCity()) { + if (city.parentZone != null && city.parentZone.isPlayerCity()) { //list Player cities //open city, just list @@ -721,742 +428,1017 @@ public class City extends AbstractWorldObject { } else if (Guild.sameNationExcludeErrant(city.getGuild(), pcG)) cities.add(city); - } else if (city.isNpc == 1) { - //list NPC cities + } else if (city.isNpc == 1) { + //list NPC cities - Guild g = city.getGuild(); - if (g == null) { - if (city.isNpc == 1) - if (city.isNoobIsle == 1) { - if (pc.getLevel() < 21) - cities.add(city); - } else if (pc.getLevel() > 9) - cities.add(city); - } else if (pc.getLevel() >= g.getRepledgeMin() && pc.getLevel() <= g.getRepledgeMax()){ + Guild g = city.getGuild(); + if (g == null) { + if (city.isNpc == 1) + if (city.isNoobIsle == 1) { + if (pc.getLevel() < 21) + cities.add(city); + } else if (pc.getLevel() > 9) + cities.add(city); + } else if (pc.getLevel() >= g.getRepledgeMin() && pc.getLevel() <= g.getRepledgeMax()) { - cities.add(city); - } - } - } - } - return cities; - } + cities.add(city); + } + } + } + } + return cities; + } - public boolean isOpen() { - return open; - } + public static City getCity(int cityId) { + if (cityId == 0) + return null; - @Override - public void updateDatabase() { - // TODO Create update logic. - } + City city = (City) DbManager.getFromCache(Enum.GameObjectType.City, cityId); + if (city != null) + return city; - public static City getCity(int cityId) { + return DbManager.CityQueries.GET_CITY(cityId); - if (cityId == 0) - return null; + } - City city = (City) DbManager.getFromCache(Enum.GameObjectType.City, cityId); - if (city != null) - return city; + public static City GetCityFromCache(int cityId) { - return DbManager.CityQueries.GET_CITY(cityId); + if (cityId == 0) + return null; - } - public static City GetCityFromCache(int cityId) { + return (City) DbManager.getFromCache(Enum.GameObjectType.City, cityId); + } - if (cityId == 0) - return null; + public boolean renameCity(String cityName) { + if (!DbManager.CityQueries.renameCity(this, cityName)) + return false; + if (!DbManager.CityQueries.updateforceRename(this, false)) + return false; - return (City) DbManager.getFromCache(Enum.GameObjectType.City, cityId); - } + this.cityName = cityName; + this.forceRename = false; + return true; + } - @Override - public void runAfterLoad() { + public boolean updateTOL(Building tol) { + if (tol == null) + return false; + if (!DbManager.CityQueries.updateTOL(this, tol.getObjectUUID())) + return false; + this.treeOfLifeID = tol.getObjectUUID(); + return true; + } - // Set city bounds - // *** Note: Moved to SetParent() - // for some undocumented reason + public boolean renameCityForNewPlant(String cityName) { + if (!DbManager.CityQueries.renameCity(this, cityName)) + return false; + if (!DbManager.CityQueries.updateforceRename(this, true)) + return false; - // Set city motto to current guild motto + this.cityName = cityName; + this.forceRename = true; + return true; + } - if (BuildingManager.getBuilding(this.treeOfLifeID) == null) - Logger.info( "City UID " + this.getObjectUUID() + " Failed to Load Tree of Life with ID " + this.treeOfLifeID); + public String getCityName() { - if ((ConfigManager.serverType.equals(ServerType.WORLDSERVER)) - && (this.isNpc == (byte) 0)) { + return cityName; + } - Realm wsr = Realm.getRealm(this.realmID); + public String getMotto() { + return motto; + } - if (wsr != null) - wsr.addCity(this.getObjectUUID()); - else - Logger.error("Unable to find realm of ID " + realmID + " for city " + this.getObjectUUID()); - } + public String getDescription() { + return description; + } - if (this.getGuild() != null) { - this.motto = this.getGuild().getMotto(); + public Building getTOL() { + if (this.treeOfLifeID == 0) + return null; - // Determine if this city is a nation capitol + return BuildingManager.getBuildingFromCache(this.treeOfLifeID); - if (this.getGuild().getGuildState() == GuildState.Nation) - for (Guild sub : this.getGuild().getSubGuildList()) { + } - if ( (sub.getGuildState() == GuildState.Protectorate) || - (sub.getGuildState() == GuildState.Province)) - this.isCapital = 1; - } + public int getIsNoobIsle() { + return isNoobIsle; + } - ArrayList guildList = Guild.GuildRoster(this.getGuild()); + public int getPopulation() { + return population; + } - this.population = guildList.size(); - } + /** + * @param population the population to set + */ + public void setPopulation(int population) { + this.population = population; + } - // Banes are loaded for this city from the database at this point + public int getSiegesWithstood() { + return siegesWithstood; + } - if (this.getBane() == null) - return; + /** + * @param siegesWithstood the siegesWithstood to set + */ + public void setSiegesWithstood(int siegesWithstood) { - // if this city is baned, add the siege effect + // early exit if setting to current value - try { - this.getTOL().addEffectBit((1 << 16)); - this.getBane().getStone().addEffectBit((1 << 19));; - }catch(Exception e){ - Logger.info("Failed ao add bane effects on city." + e.getMessage()); - } - } + if (this.siegesWithstood == siegesWithstood) + return; - public void addCityEffect(EffectsBase effectBase, int rank) { + if (DbManager.CityQueries.updateSiegesWithstood(this, siegesWithstood) == true) + this.siegesWithstood = siegesWithstood; + else + Logger.error("Error when writing to database for cityUUID: " + this.getObjectUUID()); + } - HashSet currentPlayers; - PlayerCharacter player; + public float getLatitude() { + return this.location.x; + } - // Add this new effect to the current city effect collection. - // so any new player to the grid will have all effects applied + public float getLongitude() { + return this.location.z; + } - this.addEffectNoTimer(Integer.toString(effectBase.getUUID()), effectBase, rank, false); + public float getAltitude() { + return this.location.y; + } - // Any players currently in the zone will not be processed by the heartbeat - // if it's not the first effect toggled so we do it here manually + @Override + public Vector3fImmutable getLoc() { + return this.location; + } - currentPlayers = WorldGrid.getObjectsInRangePartial(this.location, this.parentZone.getBounds().getHalfExtents().x * 1.2f, MBServerStatics.MASK_PLAYER); + public byte getIsNpcOwned() { + return isNpc; + } - for (AbstractWorldObject playerObject : currentPlayers) { + public byte getIsSafeHold() { + return this.isSafeHold; + } - if (playerObject == null) - continue; - if (!this.isLocationWithinSiegeBounds(playerObject.getLoc())) - continue; + public boolean isSafeHold() { + return (this.isSafeHold == (byte) 1); + } - player = (PlayerCharacter) playerObject; - player.addCityEffect(Integer.toString(effectBase.getUUID()), effectBase, rank, MBServerStatics.FOURTYFIVE_SECONDS, true,this); - } + public byte getIsCapital() { + return isCapital; + } - } + public void setIsCapital(boolean state) { + this.isCapital = (state) ? (byte) 1 : (byte) 0; + } - public void removeCityEffect(EffectsBase effectBase, int rank, boolean refreshEffect) { + public int getRadiusType() { + return this.radiusType; + } + public float getBindRadius() { + return this.bindRadius; + } - PlayerCharacter player; + public int getRank() { + return (this.getTOL() == null) ? 0 : this.getTOL().getRank(); + } - // Remove the city effect from the ago's internal collection + /* + * Serializing + */ - if (this.getEffects().containsKey(Integer.toString(effectBase.getUUID()))) - this.getEffects().remove(Integer.toString(effectBase.getUUID())); + public Bane getBane() { + return Bane.getBane(this.getObjectUUID()); + } - // Any players currently in the zone will not be processed by the heartbeat - // so we do it here manually + public Zone getParent() { + return this.parentZone; + } + public void setParent(Zone zone) { - for (Integer playerID : this._playerMemory) { + try { - player = PlayerCharacter.getFromCache(playerID); - if (player == null) - continue; - player.endEffectNoPower(Integer.toString(effectBase.getUUID())); + this.parentZone = zone; + this.location = new Vector3fImmutable(zone.absX + statLat, zone.absY + statAlt, zone.absZ + statLon); + this.bindLoc = new Vector3fImmutable(this.location.x + this.bindX, + this.location.y, + this.location.z + this.bindZ); + + // set city bounds + + Bounds cityBounds = Bounds.borrow(); + cityBounds.setBounds(new Vector2f(this.location.x + 64, this.location.z + 64), // location x and z are offset by 64 from the center of the city. + new Vector2f(Enum.CityBoundsType.GRID.extents, Enum.CityBoundsType.GRID.extents), + 0.0f); + this.setBounds(cityBounds); + + if (zone.getHeightMap() == null && this.isNpc == 1 && this.getObjectUUID() != 1213) { + HeightMap.GenerateCustomHeightMap(zone); + Logger.info(zone.getName() + " created custom heightmap"); + } + } catch (Exception e) { + Logger.error(e); + } + } + + public boolean isCityZone(Zone zone) { + + if (zone == null || this.parentZone == null) + return false; + + return zone.getObjectUUID() == this.parentZone.getObjectUUID(); + + } + + public AbstractCharacter getOwner() { + + if (this.getTOL() == null) + return null; + + int ownerID = this.getTOL().getOwnerUUID(); + + if (ownerID == 0) + return null; + + if (this.isNpc == 1) + return NPC.getNPC(ownerID); + else + return PlayerCharacter.getPlayerCharacter(ownerID); + } + + public Guild getGuild() { + + if (this.getTOL() == null) + return null; + + + if (this.isNpc == 1) { + + if (this.getTOL().getOwner() == null) + return null; + return this.getTOL().getOwner().getGuild(); + } else { + if (this.getTOL().getOwner() == null) + return null; + return this.getTOL().getOwner().getGuild(); + } + } + + public boolean openCity(boolean open) { + if (!DbManager.CityQueries.updateOpenCity(this, open)) + return false; + this.open = open; + return true; + } + + public Vector3fImmutable getBindLoc() { + Vector3fImmutable treeLoc = null; + + if (this.getTOL() != null && this.getTOL().getRank() == 8) + treeLoc = this.getTOL().getStuckLocation(); + + if (treeLoc != null) + return treeLoc; + + if (this.radiusType == 1 && this.bindRadius > 0f) { + //square radius + float x = this.bindLoc.getX(); + float z = this.bindLoc.getZ(); + float offset = ((ThreadLocalRandom.current().nextFloat() * 2) - 1) * this.bindRadius; + int direction = ThreadLocalRandom.current().nextInt(4); + + switch (direction) { + case 0: + x += this.bindRadius; + z += offset; + break; + case 1: + x += offset; + z -= this.bindRadius; + break; + case 2: + x -= this.bindRadius; + z += offset; + break; + case 3: + x += offset; + z += this.bindRadius; + break; + } + return new Vector3fImmutable(x, this.bindLoc.getY(), z); + } else if (this.radiusType == 2 && this.bindRadius > 0f) { + //circle radius + Vector3fImmutable dir = FastMath.randomVector2D(); + return this.bindLoc.scaleAdd(this.bindRadius, dir); + } else if (this.radiusType == 3 && this.bindRadius > 0f) { + //random inside square + float x = this.bindLoc.getX(); + x += ((ThreadLocalRandom.current().nextFloat() * 2) - 1) * this.bindRadius; + float z = this.bindLoc.getZ(); + z += ((ThreadLocalRandom.current().nextFloat() * 2) - 1) * this.bindRadius; + return new Vector3fImmutable(x, this.bindLoc.getY(), z); + } else if (this.radiusType == 4 && this.bindRadius > 0f) { + //random inside circle + Vector3fImmutable dir = FastMath.randomVector2D(); + return this.bindLoc.scaleAdd(ThreadLocalRandom.current().nextFloat() * this.bindRadius, dir); + } else + //spawn at bindLoc + //System.out.println("x: " + this.bindLoc.x + ", z: " + this.bindLoc.z); + return this.bindLoc; + } + + public NPC getRuneMaster() { + NPC outNPC = null; + + if (this.getTOL() == null) + return outNPC; + + for (AbstractCharacter npc : getTOL().getHirelings().keySet()) { + if (npc.getObjectType() == GameObjectType.NPC) + if (((NPC) npc).getContract().isRuneMaster() == true) + outNPC = (NPC) npc; + } + + return outNPC; + } + + public boolean isOpen() { + return open; + } + + @Override + public void updateDatabase() { + // TODO Create update logic. + } - // Reapply effect with timeout? + @Override + public void runAfterLoad() { + + // Set city bounds + // *** Note: Moved to SetParent() + // for some undocumented reason - if (refreshEffect == true) - player.addCityEffect(Integer.toString(effectBase.getUUID()), effectBase, rank, MBServerStatics.FOURTYFIVE_SECONDS, false,this); + // Set city motto to current guild motto - } + if (BuildingManager.getBuilding(this.treeOfLifeID) == null) + Logger.info("City UID " + this.getObjectUUID() + " Failed to Load Tree of Life with ID " + this.treeOfLifeID); - } + if ((ConfigManager.serverType.equals(ServerType.WORLDSERVER)) + && (this.isNpc == (byte) 0)) { - public Warehouse getWarehouse() { - if (this.warehouseBuildingID == 0) - return null; - return Warehouse.warehouseByBuildingUUID.get(this.warehouseBuildingID); - } + Realm wsr = Realm.getRealm(this.realmID); - public Realm getRealm() { + if (wsr != null) + wsr.addCity(this.getObjectUUID()); + else + Logger.error("Unable to find realm of ID " + realmID + " for city " + this.getObjectUUID()); + } - return Realm.getRealm(this.realmID); + if (this.getGuild() != null) { + this.motto = this.getGuild().getMotto(); - } + // Determine if this city is a nation capitol - public boolean isLocationOnCityGrid(Vector3fImmutable insideLoc) { + if (this.getGuild().getGuildState() == GuildState.Nation) + for (Guild sub : this.getGuild().getSubGuildList()) { - Bounds newBounds = Bounds.borrow(); - newBounds.setBounds(insideLoc); - boolean collided = Bounds.collide(this.getBounds(), newBounds,0); - newBounds.release(); - return collided; - } - - public boolean isLocationOnCityGrid(Bounds newBounds) { + if ((sub.getGuildState() == GuildState.Protectorate) || + (sub.getGuildState() == GuildState.Province)) + this.isCapital = 1; + } - boolean collided = Bounds.collide(this.getBounds(), newBounds,0); - return collided; - } + ArrayList guildList = Guild.GuildRoster(this.getGuild()); - public boolean isLocationWithinSiegeBounds(Vector3fImmutable insideLoc) { + this.population = guildList.size(); + } - return insideLoc.isInsideCircle(this.getLoc(), CityBoundsType.ZONE.extents); + // Banes are loaded for this city from the database at this point - } + if (this.getBane() == null) + return; - public boolean isLocationOnCityZone(Vector3fImmutable insideLoc) { - return Bounds.collide(insideLoc, this.parentZone.getBounds()); - } + // if this city is baned, add the siege effect - private void applyAllCityEffects(PlayerCharacter player) { + try { + this.getTOL().addEffectBit((1 << 16)); + this.getBane().getStone().addEffectBit((1 << 19)); + ; + } catch (Exception e) { + Logger.info("Failed ao add bane effects on city." + e.getMessage()); + } + } - Effect effect; - EffectsBase effectBase; + public void addCityEffect(EffectsBase effectBase, int rank) { - try { - for (String cityEffect : this.getEffects().keySet()) { + HashSet currentPlayers; + PlayerCharacter player; - effect = this.getEffects().get(cityEffect); - effectBase = effect.getEffectsBase(); + // Add this new effect to the current city effect collection. + // so any new player to the grid will have all effects applied - if (effectBase == null) - continue; + this.addEffectNoTimer(Integer.toString(effectBase.getUUID()), effectBase, rank, false); - player.addCityEffect(Integer.toString(effectBase.getUUID()), effectBase, effect.getTrains(), MBServerStatics.FOURTYFIVE_SECONDS, true,this); - } - } catch (Exception e) { - Logger.error( e.getMessage()); - } + // Any players currently in the zone will not be processed by the heartbeat + // if it's not the first effect toggled so we do it here manually - } + currentPlayers = WorldGrid.getObjectsInRangePartial(this.location, this.parentZone.getBounds().getHalfExtents().x * 1.2f, MBServerStatics.MASK_PLAYER); - private void removeAllCityEffects(PlayerCharacter player,boolean force) { + for (AbstractWorldObject playerObject : currentPlayers) { - Effect effect; - EffectsBase effectBase; + if (playerObject == null) + continue; + if (!this.isLocationWithinSiegeBounds(playerObject.getLoc())) + continue; - try { - for (String cityEffect : this.getEffects().keySet()) { + player = (PlayerCharacter) playerObject; + player.addCityEffect(Integer.toString(effectBase.getUUID()), effectBase, rank, MBServerStatics.FOURTYFIVE_SECONDS, true, this); + } - effect = this.getEffects().get(cityEffect); - effectBase = effect.getEffectsBase(); + } - if (player.getEffects().get(cityEffect) == null) - return; + public void removeCityEffect(EffectsBase effectBase, int rank, boolean refreshEffect) { - // player.endEffectNoPower(cityEffect); - player.addCityEffect(Integer.toString(effectBase.getUUID()), effectBase, effect.getTrains(), MBServerStatics.FOURTYFIVE_SECONDS, false,this); - } - } catch (Exception e) { - Logger.error(e.getMessage()); - } - } - public void onEnter() { + PlayerCharacter player; - HashSet currentPlayers; - HashSet currentMemory; - PlayerCharacter player; + // Remove the city effect from the ago's internal collection - // Gather current list of players within the zone bounds + if (this.getEffects().containsKey(Integer.toString(effectBase.getUUID()))) + this.getEffects().remove(Integer.toString(effectBase.getUUID())); - currentPlayers = WorldGrid.getObjectsInRangePartial(this.location, CityBoundsType.ZONE.extents, MBServerStatics.MASK_PLAYER); - currentMemory = new HashSet<>(); + // Any players currently in the zone will not be processed by the heartbeat + // so we do it here manually - for (AbstractWorldObject playerObject : currentPlayers) { - if (playerObject == null) - continue; + for (Integer playerID : this._playerMemory) { - player = (PlayerCharacter) playerObject; - currentMemory.add(player.getObjectUUID()); + player = PlayerCharacter.getFromCache(playerID); + if (player == null) + continue; - // Player is already in our memory + player.endEffectNoPower(Integer.toString(effectBase.getUUID())); - if (_playerMemory.contains(player.getObjectUUID())) - continue; + // Reapply effect with timeout? - if (!this.isLocationWithinSiegeBounds(player.getLoc())) - continue; - // Apply safehold affect to player if needed + if (refreshEffect == true) + player.addCityEffect(Integer.toString(effectBase.getUUID()), effectBase, rank, MBServerStatics.FOURTYFIVE_SECONDS, false, this); - if ((this.isSafeHold == 1)) - player.setSafeZone(true); + } - //add spire effects. - if (this.getEffects().size() > 0) - this.applyAllCityEffects(player); + } - // Add player to our city's memory + public Warehouse getWarehouse() { + if (this.warehouseBuildingID == 0) + return null; + return Warehouse.warehouseByBuildingUUID.get(this.warehouseBuildingID); + } - _playerMemory.add(player.getObjectUUID()); + public Realm getRealm() { - // ***For debugging - // Logger.info("PlayerMemory for ", this.getCityName() + ": " + _playerMemory.size()); - } - try { - onExit(currentMemory); - } catch (Exception e) { - Logger.error( e.getMessage()); - } + return Realm.getRealm(this.realmID); - } + } - /* All characters in city player memory but - * not the current memory have obviously - * left the city. Remove their affects. - */ + public boolean isLocationOnCityGrid(Vector3fImmutable insideLoc) { - private void onExit(HashSet currentMemory) { + Bounds newBounds = Bounds.borrow(); + newBounds.setBounds(insideLoc); + boolean collided = Bounds.collide(this.getBounds(), newBounds, 0); + newBounds.release(); + return collided; + } - PlayerCharacter player; - int playerUUID = 0; - HashSet toRemove = new HashSet<>(); - Iterator iter = _playerMemory.iterator(); + public boolean isLocationOnCityGrid(Bounds newBounds) { - while (iter.hasNext()) { + boolean collided = Bounds.collide(this.getBounds(), newBounds, 0); + return collided; + } - playerUUID = iter.next(); + public boolean isLocationWithinSiegeBounds(Vector3fImmutable insideLoc) { + return insideLoc.isInsideCircle(this.getLoc(), CityBoundsType.ZONE.extents); + } - player = PlayerCharacter.getFromCache(playerUUID); + public boolean isLocationOnCityZone(Vector3fImmutable insideLoc) { + return Bounds.collide(insideLoc, this.parentZone.getBounds()); + } - if (this.isLocationWithinSiegeBounds(player.getLoc())) - continue; + private void applyAllCityEffects(PlayerCharacter player) { - // Remove players safezone status if warranted - // they can assumed to be not on the citygrid at - // this point. + Effect effect; + EffectsBase effectBase; + try { + for (String cityEffect : this.getEffects().keySet()) { - player.setSafeZone(false); + effect = this.getEffects().get(cityEffect); + effectBase = effect.getEffectsBase(); - this.removeAllCityEffects(player,false); + if (effectBase == null) + continue; - // We will remove this player after iteration is complete - // so store it in a temporary collection + player.addCityEffect(Integer.toString(effectBase.getUUID()), effectBase, effect.getTrains(), MBServerStatics.FOURTYFIVE_SECONDS, true, this); + } + } catch (Exception e) { + Logger.error(e.getMessage()); + } - toRemove.add(playerUUID); - // ***For debugging - // Logger.info("PlayerMemory for ", this.getCityName() + ": " + _playerMemory.size()); - } + } - // Remove players from city memory + private void removeAllCityEffects(PlayerCharacter player, boolean force) { - _playerMemory.removeAll(toRemove); - for(Integer removalUUID : toRemove){ - if(this.cityOutlaws.contains(removalUUID)) - this.cityOutlaws.remove(removalUUID); - } - } + Effect effect; + EffectsBase effectBase; - public int getWarehouseBuildingID() { - return warehouseBuildingID; - } + try { + for (String cityEffect : this.getEffects().keySet()) { - public void setWarehouseBuildingID(int warehouseBuildingID) { - this.warehouseBuildingID = warehouseBuildingID; - } + effect = this.getEffects().get(cityEffect); + effectBase = effect.getEffectsBase(); - public final void destroy() { + if (player.getEffects().get(cityEffect) == null) + return; - Thread destroyCityThread = new Thread(new DestroyCityThread(this)); + // player.endEffectNoPower(cityEffect); + player.addCityEffect(Integer.toString(effectBase.getUUID()), effectBase, effect.getTrains(), MBServerStatics.FOURTYFIVE_SECONDS, false, this); + } + } catch (Exception e) { + Logger.error(e.getMessage()); + } + } - destroyCityThread.setName("deestroyCity:" + this.getName()); - destroyCityThread.start(); - } + /* All characters in city player memory but + * not the current memory have obviously + * left the city. Remove their affects. + */ - public final void transfer(AbstractCharacter newOwner) { + public void onEnter() { - Thread transferCityThread = new Thread(new TransferCityThread(this, newOwner)); + HashSet currentPlayers; + HashSet currentMemory; + PlayerCharacter player; - transferCityThread.setName("TransferCity:" + this.getName()); - transferCityThread.start(); - } + // Gather current list of players within the zone bounds - public final void claim(AbstractCharacter sourcePlayer) { + currentPlayers = WorldGrid.getObjectsInRangePartial(this.location, CityBoundsType.ZONE.extents, MBServerStatics.MASK_PLAYER); + currentMemory = new HashSet<>(); - Guild sourceNation; - Guild sourceGuild; - Zone cityZone; + for (AbstractWorldObject playerObject : currentPlayers) { - sourceGuild = sourcePlayer.getGuild(); + if (playerObject == null) + continue; - if (sourceGuild == null) - return; + player = (PlayerCharacter) playerObject; + currentMemory.add(player.getObjectUUID()); - sourceNation = sourcePlayer.getGuild().getNation(); + // Player is already in our memory - if (sourceGuild.isEmptyGuild()) - return; + if (_playerMemory.contains(player.getObjectUUID())) + continue; - //cant claim tree with owned tree. + if (!this.isLocationWithinSiegeBounds(player.getLoc())) + continue; + // Apply safehold affect to player if needed - if (sourceGuild.getOwnedCity() != null) - return; + if ((this.isSafeHold == 1)) + player.setSafeZone(true); - cityZone = this.parentZone; + //add spire effects. + if (this.getEffects().size() > 0) + this.applyAllCityEffects(player); - // Can't claim a tree not in a player city zone + // Add player to our city's memory - // Reset sieges withstood + _playerMemory.add(player.getObjectUUID()); - this.setSiegesWithstood(0); + // ***For debugging + // Logger.info("PlayerMemory for ", this.getCityName() + ": " + _playerMemory.size()); + } + try { + onExit(currentMemory); + } catch (Exception e) { + Logger.error(e.getMessage()); + } - this.hasBeenTransfered = true; + } - // If currently a sub of another guild, desub when - // claiming your new tree and set as Landed + private void onExit(HashSet currentMemory) { - if (!sourceNation.isEmptyGuild() && sourceNation != sourceGuild) { - if (!DbManager.GuildQueries.UPDATE_PARENT(sourceGuild.getObjectUUID(), WorldServer.worldUUID)) { - ChatManager.chatGuildError((PlayerCharacter) sourcePlayer, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - return; - } + PlayerCharacter player; + int playerUUID = 0; + HashSet toRemove = new HashSet<>(); + Iterator iter = _playerMemory.iterator(); - sourceNation.getSubGuildList().remove(sourceGuild); + while (iter.hasNext()) { - if (sourceNation.getSubGuildList().isEmpty()) - sourceNation.downgradeGuildState(); - } + playerUUID = iter.next(); - // Link the mew guild with the tree - if (!DbManager.GuildQueries.SET_GUILD_OWNED_CITY(sourceGuild.getObjectUUID(), this.getObjectUUID())) { - ChatManager.chatGuildError((PlayerCharacter) sourcePlayer, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - return; - } + player = PlayerCharacter.getFromCache(playerUUID); - sourceGuild.setCityUUID(this.getObjectUUID()); + if (this.isLocationWithinSiegeBounds(player.getLoc())) + continue; - sourceGuild.setNation(sourceGuild); - sourceGuild.setGuildState(GuildState.Sovereign); - GuildManager.updateAllGuildTags(sourceGuild); - GuildManager.updateAllGuildBinds(sourceGuild, this); + // Remove players safezone status if warranted + // they can assumed to be not on the citygrid at + // this point. - // Build list of buildings within this parent zone - for (Building cityBuilding : cityZone.zoneBuildingSet) { + player.setSafeZone(false); - // Buildings without blueprints are unclaimable + this.removeAllCityEffects(player, false); - if (cityBuilding.getBlueprintUUID() == 0) - continue; + // We will remove this player after iteration is complete + // so store it in a temporary collection - // All protection contracts are void upon transfer of a city + toRemove.add(playerUUID); + // ***For debugging + // Logger.info("PlayerMemory for ", this.getCityName() + ": " + _playerMemory.size()); + } - // All protection contracts are void upon transfer of a city - //Dont forget to not Flip protection on Banestones and siege Equipment... Noob. - if (cityBuilding.getBlueprint() != null && !cityBuilding.getBlueprint().isSiegeEquip() - && cityBuilding.getBlueprint().getBuildingGroup() != BuildingGroup.BANESTONE) - cityBuilding.setProtectionState(ProtectionState.NONE); + // Remove players from city memory - // Transfer ownership of valid city assets - // these assets are autoprotected. + _playerMemory.removeAll(toRemove); + for (Integer removalUUID : toRemove) { + if (this.cityOutlaws.contains(removalUUID)) + this.cityOutlaws.remove(removalUUID); + } + } - if ((cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.TOL) - || (cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.SPIRE) - || (cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.BARRACK) - || (cityBuilding.getBlueprint().isWallPiece()) - || (cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE)) { + public int getWarehouseBuildingID() { + return warehouseBuildingID; + } - cityBuilding.claim(sourcePlayer); - cityBuilding.setProtectionState(ProtectionState.PROTECTED); - } - } + public void setWarehouseBuildingID(int warehouseBuildingID) { + this.warehouseBuildingID = warehouseBuildingID; + } - this.setForceRename(true); + public final void destroy() { - // Reset city timer for map update + Thread destroyCityThread = new Thread(new DestroyCityThread(this)); - City.lastCityUpdate = System.currentTimeMillis(); - } + destroyCityThread.setName("deestroyCity:" + this.getName()); + destroyCityThread.start(); + } - public final boolean transferGuildLeader(PlayerCharacter sourcePlayer) { + public final void transfer(AbstractCharacter newOwner) { - Guild sourceGuild; - Zone cityZone; - sourceGuild = sourcePlayer.getGuild(); + Thread transferCityThread = new Thread(new TransferCityThread(this, newOwner)); + transferCityThread.setName("TransferCity:" + this.getName()); + transferCityThread.start(); + } - if (sourceGuild == null) - return false; + public final void claim(AbstractCharacter sourcePlayer) { - if (sourceGuild.isEmptyGuild()) - return false; + Guild sourceNation; + Guild sourceGuild; + Zone cityZone; - cityZone = this.parentZone; + sourceGuild = sourcePlayer.getGuild(); - for (Building cityBuilding : cityZone.zoneBuildingSet) { + if (sourceGuild == null) + return; - // Buildings without blueprints are unclaimable + sourceNation = sourcePlayer.getGuild().getNation(); - if (cityBuilding.getBlueprintUUID() == 0) - continue; + if (sourceGuild.isEmptyGuild()) + return; - // All protection contracts are void upon transfer of a city - //Dont forget to not Flip protection on Banestones and siege Equipment... Noob. + //cant claim tree with owned tree. - // Transfer ownership of valid city assets - // these assets are autoprotected. + if (sourceGuild.getOwnedCity() != null) + return; - if ((cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.TOL) - || (cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.SPIRE) - || (cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.BARRACK) - || (cityBuilding.getBlueprint().isWallPiece()) - || (cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE) - ) { + cityZone = this.parentZone; - cityBuilding.claim(sourcePlayer); - cityBuilding.setProtectionState(ProtectionState.PROTECTED); - } else if(cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.WAREHOUSE) - cityBuilding.claim(sourcePlayer); + // Can't claim a tree not in a player city zone + // Reset sieges withstood - } - this.setForceRename(true); - CityRecord cityRecord = CityRecord.borrow(this, Enum.RecordEventType.TRANSFER); - DataWarehouse.pushToWarehouse(cityRecord); - return true; + this.setSiegesWithstood(0); - } + this.hasBeenTransfered = true; - /** - * @return the forceRename - */ - public boolean isForceRename() { - return forceRename; - } + // If currently a sub of another guild, desub when + // claiming your new tree and set as Landed - /** - * @param siegesWithstood the siegesWithstood to set - */ - public void setSiegesWithstood(int siegesWithstood) { + if (!sourceNation.isEmptyGuild() && sourceNation != sourceGuild) { + if (!DbManager.GuildQueries.UPDATE_PARENT(sourceGuild.getObjectUUID(), WorldServer.worldUUID)) { + ChatManager.chatGuildError((PlayerCharacter) sourcePlayer, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + return; + } - // early exit if setting to current value + sourceNation.getSubGuildList().remove(sourceGuild); - if (this.siegesWithstood == siegesWithstood) - return; + if (sourceNation.getSubGuildList().isEmpty()) + sourceNation.downgradeGuildState(); + } - if (DbManager.CityQueries.updateSiegesWithstood(this, siegesWithstood) == true) - this.siegesWithstood = siegesWithstood; - else - Logger.error("Error when writing to database for cityUUID: " + this.getObjectUUID()); - } + // Link the mew guild with the tree - /** - * @param population the population to set - */ - public void setPopulation(int population) { - this.population = population; - } + if (!DbManager.GuildQueries.SET_GUILD_OWNED_CITY(sourceGuild.getObjectUUID(), this.getObjectUUID())) { + ChatManager.chatGuildError((PlayerCharacter) sourcePlayer, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + return; + } - public boolean isReverseKOS() { - return reverseKOS; - } + sourceGuild.setCityUUID(this.getObjectUUID()); - public void setReverseKOS(boolean reverseKOS) { - this.reverseKOS = reverseKOS; - } + sourceGuild.setNation(sourceGuild); + sourceGuild.setGuildState(GuildState.Sovereign); + GuildManager.updateAllGuildTags(sourceGuild); + GuildManager.updateAllGuildBinds(sourceGuild, this); - public String getHash() { - return hash; - } + // Build list of buildings within this parent zone - public void setHash(String hash) { - this.hash = hash; - } + for (Building cityBuilding : cityZone.zoneBuildingSet) { - public void setHash() { + // Buildings without blueprints are unclaimable - this.hash = DataWarehouse.hasher.encrypt(this.getObjectUUID()); + if (cityBuilding.getBlueprintUUID() == 0) + continue; - // Write hash to player character table + // All protection contracts are void upon transfer of a city - DataWarehouse.writeHash(Enum.DataRecordType.CITY, this.getObjectUUID()); - } + // All protection contracts are void upon transfer of a city + //Dont forget to not Flip protection on Banestones and siege Equipment... Noob. + if (cityBuilding.getBlueprint() != null && !cityBuilding.getBlueprint().isSiegeEquip() + && cityBuilding.getBlueprint().getBuildingGroup() != BuildingGroup.BANESTONE) + cityBuilding.setProtectionState(ProtectionState.NONE); - public boolean setRealmTaxDate(LocalDateTime realmTaxDate) { + // Transfer ownership of valid city assets + // these assets are autoprotected. - if (!DbManager.CityQueries.updateRealmTaxDate(this, realmTaxDate)) - return false; + if ((cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.TOL) + || (cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.SPIRE) + || (cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.BARRACK) + || (cityBuilding.getBlueprint().isWallPiece()) + || (cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE)) { - this.realmTaxDate = realmTaxDate; - return true; + cityBuilding.claim(sourcePlayer); + cityBuilding.setProtectionState(ProtectionState.PROTECTED); + } + } - } + this.setForceRename(true); - //TODO use this for taxing later. -// public boolean isAfterTaxPeriod(LocalDateTime dateTime,PlayerCharacter player){ -// if (dateTime.isBefore(realmTaxDate)){ -// String wait = ""; -// float hours = 1000*60*60; -// float seconds = 1000; -// float hoursUntil = realmTaxDate.minus(dateTime.get).getMillis() /hours; -// int secondsUntil = (int) (realmTaxDate.minus(dateTime.getMillis()).getMillis() /seconds); -// if (hoursUntil < 1) -// wait = "You must wait " + secondsUntil + " seconds before taxing this city again!"; -// else -// wait = "You must wait " + hoursUntil + " hours before taxing this city again!"; -// ErrorPopupMsg.sendErrorMsg(player, wait); -// return false; -// } -// -// return true; -// } + // Reset city timer for map update + + City.lastCityUpdate = System.currentTimeMillis(); + } - + public final boolean transferGuildLeader(PlayerCharacter sourcePlayer) { - public synchronized boolean TaxWarehouse(TaxResourcesMsg msg,PlayerCharacter player) { + Guild sourceGuild; + Zone cityZone; + sourceGuild = sourcePlayer.getGuild(); - // Member variable declaration - Building building = BuildingManager.getBuildingFromCache(msg.getBuildingID()); - Guild playerGuild = player.getGuild(); - if (building == null){ - ErrorPopupMsg.sendErrorMsg(player, "Not a valid Building!"); - return true; - } + if (sourceGuild == null) + return false; - City city = building.getCity(); - if (city == null){ - ErrorPopupMsg.sendErrorMsg(player, "This building does not belong to a city."); - return true; - } + if (sourceGuild.isEmptyGuild()) + return false; + cityZone = this.parentZone; - if (playerGuild == null || playerGuild.isEmptyGuild()){ - ErrorPopupMsg.sendErrorMsg(player, "You must belong to a guild to do that!"); - return true; - } + for (Building cityBuilding : cityZone.zoneBuildingSet) { - if (playerGuild.getOwnedCity() == null){ - ErrorPopupMsg.sendErrorMsg(player, "Your Guild needs to own a city!"); - return true; - } + // Buildings without blueprints are unclaimable - if (playerGuild.getOwnedCity().getTOL() == null){ - ErrorPopupMsg.sendErrorMsg(player, "Cannot find Tree of Life for your city!"); - return true; - } + if (cityBuilding.getBlueprintUUID() == 0) + continue; - if (playerGuild.getOwnedCity().getTOL().getRank() != 8){ - ErrorPopupMsg.sendErrorMsg(player, "Your City needs to Own a realm!"); - return true; - } + // All protection contracts are void upon transfer of a city + //Dont forget to not Flip protection on Banestones and siege Equipment... Noob. - if (playerGuild.getOwnedCity().getRealm() == null){ - ErrorPopupMsg.sendErrorMsg(player, "Cannot find realm for your city!"); - return true; - } - Realm targetRealm = RealmMap.getRealmForCity(city); + // Transfer ownership of valid city assets + // these assets are autoprotected. - if (targetRealm == null){ - ErrorPopupMsg.sendErrorMsg(player, "Cannot find realm for city you are attempting to tax!"); - return true; - } + if ((cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.TOL) + || (cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.SPIRE) + || (cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.BARRACK) + || (cityBuilding.getBlueprint().isWallPiece()) + || (cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE) + ) { - if (targetRealm.getRulingCity() == null){ - ErrorPopupMsg.sendErrorMsg(player, "Realm Does not have a ruling city!"); - return true; - } + cityBuilding.claim(sourcePlayer); + cityBuilding.setProtectionState(ProtectionState.PROTECTED); + } else if (cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.WAREHOUSE) + cityBuilding.claim(sourcePlayer); - if (targetRealm.getRulingCity().getObjectUUID() != playerGuild.getOwnedCity().getObjectUUID()){ - ErrorPopupMsg.sendErrorMsg(player, "Your guild does not rule this realm!"); - return true; - } - if (playerGuild.getOwnedCity().getObjectUUID() == city.getObjectUUID()){ - ErrorPopupMsg.sendErrorMsg(player, "You cannot tax your own city!"); - return true; - } + } + this.setForceRename(true); + CityRecord cityRecord = CityRecord.borrow(this, Enum.RecordEventType.TRANSFER); + DataWarehouse.pushToWarehouse(cityRecord); + return true; + } + /** + * @return the forceRename + */ + public boolean isForceRename() { + return forceRename; + } + public void setForceRename(boolean forceRename) { + if (!DbManager.CityQueries.updateforceRename(this, forceRename)) + return; + this.forceRename = forceRename; + } - if (!GuildStatusController.isTaxCollector(player.getGuildStatus())){ - ErrorPopupMsg.sendErrorMsg(player, "You Must be a tax Collector!"); - return true; - } + public boolean isReverseKOS() { + return reverseKOS; + } + public void setReverseKOS(boolean reverseKOS) { + this.reverseKOS = reverseKOS; + } - - if (this.realmTaxDate.isAfter(LocalDateTime.now())) - return true; - if (msg.getResources().size() == 0) - return true; + public String getHash() { + return hash; + } - if (city.getWarehouse() == null) - return true; - Warehouse ruledWarehouse = playerGuild.getOwnedCity().getWarehouse(); - if (ruledWarehouse == null) - return true; + public void setHash(String hash) { + this.hash = hash; + } + public void setHash() { + this.hash = DataWarehouse.hasher.encrypt(this.getObjectUUID()); - ItemBase.getItemHashIDMap(); + // Write hash to player character table + + DataWarehouse.writeHash(Enum.DataRecordType.CITY, this.getObjectUUID()); + } + + public boolean setRealmTaxDate(LocalDateTime realmTaxDate) { + + if (!DbManager.CityQueries.updateRealmTaxDate(this, realmTaxDate)) + return false; + + this.realmTaxDate = realmTaxDate; + return true; + + } + + //TODO use this for taxing later. +// public boolean isAfterTaxPeriod(LocalDateTime dateTime,PlayerCharacter player){ +// if (dateTime.isBefore(realmTaxDate)){ +// String wait = ""; +// float hours = 1000*60*60; +// float seconds = 1000; +// float hoursUntil = realmTaxDate.minus(dateTime.get).getMillis() /hours; +// int secondsUntil = (int) (realmTaxDate.minus(dateTime.getMillis()).getMillis() /seconds); +// if (hoursUntil < 1) +// wait = "You must wait " + secondsUntil + " seconds before taxing this city again!"; +// else +// wait = "You must wait " + hoursUntil + " hours before taxing this city again!"; +// ErrorPopupMsg.sendErrorMsg(player, wait); +// return false; +// } +// +// return true; +// } - ArrayListresources = new ArrayList<>(); - float taxPercent = msg.getTaxPercent(); - if (taxPercent > 20) - taxPercent = .20f; + public synchronized boolean TaxWarehouse(TaxResourcesMsg msg, PlayerCharacter player) { - for (int resourceHash:msg.getResources().keySet()){ - if (ItemBase.getItemHashIDMap().get(resourceHash) != null) - resources.add(ItemBase.getItemHashIDMap().get(resourceHash)); + // Member variable declaration + Building building = BuildingManager.getBuildingFromCache(msg.getBuildingID()); + Guild playerGuild = player.getGuild(); - } + if (building == null) { + ErrorPopupMsg.sendErrorMsg(player, "Not a valid Building!"); + return true; + } - for (Integer itemBaseID:resources){ - ItemBase ib = ItemBase.getItemBase(itemBaseID); - if (ib == null) - continue; - if (ruledWarehouse.isAboveCap(ib, (int) (city.getWarehouse().getResources().get(ib) * taxPercent))){ - ErrorPopupMsg.sendErrorMsg(player, "You're warehouse has enough " + ib.getName() + " already!"); - return true; - } + City city = building.getCity(); + if (city == null) { + ErrorPopupMsg.sendErrorMsg(player, "This building does not belong to a city."); + return true; + } - } - - if(!city.setRealmTaxDate(LocalDateTime.now().plusDays(7))){ - ErrorPopupMsg.sendErrorMsg(player, "Failed to Update next Tax Date due to internal Error. City was not charged taxes this time."); - return false; - } - try{ - city.getWarehouse().transferResources(player,msg,resources, taxPercent,ruledWarehouse); - }catch(Exception e){ - Logger.info( e.getMessage()); - } - // Member variable assignment - - ViewResourcesMessage vrm = new ViewResourcesMessage(player); - vrm.setGuild(building.getGuild()); - vrm.setWarehouseBuilding(BuildingManager.getBuildingFromCache(building.getCity().getWarehouse().getBuildingUID())); - vrm.configure(); - Dispatch dispatch = Dispatch.borrow(player, vrm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - return true; + if (playerGuild == null || playerGuild.isEmptyGuild()) { + ErrorPopupMsg.sendErrorMsg(player, "You must belong to a guild to do that!"); + return true; + } - } + if (playerGuild.getOwnedCity() == null) { + ErrorPopupMsg.sendErrorMsg(player, "Your Guild needs to own a city!"); + return true; + } + + if (playerGuild.getOwnedCity().getTOL() == null) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot find Tree of Life for your city!"); + return true; + } + + if (playerGuild.getOwnedCity().getTOL().getRank() != 8) { + ErrorPopupMsg.sendErrorMsg(player, "Your City needs to Own a realm!"); + return true; + } + + if (playerGuild.getOwnedCity().getRealm() == null) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot find realm for your city!"); + return true; + } + Realm targetRealm = RealmMap.getRealmForCity(city); + + if (targetRealm == null) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot find realm for city you are attempting to tax!"); + return true; + } + + if (targetRealm.getRulingCity() == null) { + ErrorPopupMsg.sendErrorMsg(player, "Realm Does not have a ruling city!"); + return true; + } + + if (targetRealm.getRulingCity().getObjectUUID() != playerGuild.getOwnedCity().getObjectUUID()) { + ErrorPopupMsg.sendErrorMsg(player, "Your guild does not rule this realm!"); + return true; + } + + if (playerGuild.getOwnedCity().getObjectUUID() == city.getObjectUUID()) { + ErrorPopupMsg.sendErrorMsg(player, "You cannot tax your own city!"); + return true; + } + + + if (!GuildStatusController.isTaxCollector(player.getGuildStatus())) { + ErrorPopupMsg.sendErrorMsg(player, "You Must be a tax Collector!"); + return true; + } + + + if (this.realmTaxDate.isAfter(LocalDateTime.now())) + return true; + if (msg.getResources().size() == 0) + return true; + + if (city.getWarehouse() == null) + return true; + Warehouse ruledWarehouse = playerGuild.getOwnedCity().getWarehouse(); + if (ruledWarehouse == null) + return true; + + + ItemBase.getItemHashIDMap(); + + ArrayList resources = new ArrayList<>(); + + float taxPercent = msg.getTaxPercent(); + if (taxPercent > 20) + taxPercent = .20f; + + for (int resourceHash : msg.getResources().keySet()) { + if (ItemBase.getItemHashIDMap().get(resourceHash) != null) + resources.add(ItemBase.getItemHashIDMap().get(resourceHash)); + + } + + for (Integer itemBaseID : resources) { + ItemBase ib = ItemBase.getItemBase(itemBaseID); + if (ib == null) + continue; + if (ruledWarehouse.isAboveCap(ib, (int) (city.getWarehouse().getResources().get(ib) * taxPercent))) { + ErrorPopupMsg.sendErrorMsg(player, "You're warehouse has enough " + ib.getName() + " already!"); + return true; + } + + } + + if (!city.setRealmTaxDate(LocalDateTime.now().plusDays(7))) { + ErrorPopupMsg.sendErrorMsg(player, "Failed to Update next Tax Date due to internal Error. City was not charged taxes this time."); + return false; + } + try { + city.getWarehouse().transferResources(player, msg, resources, taxPercent, ruledWarehouse); + } catch (Exception e) { + Logger.info(e.getMessage()); + } + + // Member variable assignment + + ViewResourcesMessage vrm = new ViewResourcesMessage(player); + vrm.setGuild(building.getGuild()); + vrm.setWarehouseBuilding(BuildingManager.getBuildingFromCache(building.getCity().getWarehouse().getBuildingUID())); + vrm.configure(); + Dispatch dispatch = Dispatch.borrow(player, vrm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + return true; + + } } diff --git a/src/engine/objects/Colliders.java b/src/engine/objects/Colliders.java index cbd68bcf..e1d46f7e 100644 --- a/src/engine/objects/Colliders.java +++ b/src/engine/objects/Colliders.java @@ -12,54 +12,52 @@ package engine.objects; import java.awt.geom.Line2D; -public class Colliders { +public class Colliders { - private Line2D collider; - private int doorID; - private boolean link = false; - public float startX; - public float startY; - public float endX; - public float endY; + public float startX; + public float startY; + public float endX; + public float endY; + private Line2D collider; + private int doorID; + private boolean link = false; - public Colliders(Line2D collider, int doorID, boolean link) { - super(); - this.collider = collider; - this.doorID = doorID; - this.link = link; - } - - public Colliders(float startX, float startY, float endX ,float endY, int doorID, boolean link) { - super(); - this.startX = startX; - this.startY = startY; - this.endX = endX; - this.endY = endY; - this.doorID = doorID; - this.link = link; - } + public Colliders(Line2D collider, int doorID, boolean link) { + super(); + this.collider = collider; + this.doorID = doorID; + this.link = link; + } + public Colliders(float startX, float startY, float endX, float endY, int doorID, boolean link) { + super(); + this.startX = startX; + this.startY = startY; + this.endX = endX; + this.endY = endY; + this.doorID = doorID; + this.link = link; + } - public int getDoorID() { - return doorID; - } - public Line2D getCollider() { - return collider; - } + public int getDoorID() { + return doorID; + } + public Line2D getCollider() { + return collider; + } - public boolean isLink() { - return link; - } - - public void setLink(boolean link) { - this.link = link; - } + public boolean isLink() { + return link; + } + public void setLink(boolean link) { + this.link = link; + } } diff --git a/src/engine/objects/Condemned.java b/src/engine/objects/Condemned.java index b4ef9744..bdcb59a6 100644 --- a/src/engine/objects/Condemned.java +++ b/src/engine/objects/Condemned.java @@ -15,84 +15,71 @@ import java.sql.ResultSet; import java.sql.SQLException; +public class Condemned { + public static final int INDIVIDUAL = 2; + public static final int GUILD = 4; + public static final int NATION = 5; + private int ID; + private int playerUID; + private int parent; + private int guildUID; + private int friendType; + private boolean active; -public class Condemned { - private int ID; - private int playerUID; - private int parent; - private int guildUID; - private int friendType; - private boolean active; - public static final int INDIVIDUAL = 2; - public static final int GUILD = 4; - public static final int NATION = 5; + /** + * ResultSet Constructor + */ + public Condemned(ResultSet rs) throws SQLException { + this.playerUID = rs.getInt("playerUID"); + this.parent = rs.getInt("buildingUID"); + this.guildUID = rs.getInt("guildUID"); + this.friendType = rs.getInt("friendType"); + this.active = rs.getBoolean("active"); + } - + public Condemned(int playerUID, int parent, int guildUID, int friendType) { + super(); + this.playerUID = playerUID; + this.parent = parent; + this.guildUID = guildUID; + this.friendType = friendType; + this.active = false; + } - /** - * ResultSet Constructor - */ - public Condemned(ResultSet rs) throws SQLException { - this.playerUID = rs.getInt("playerUID"); - this.parent = rs.getInt("buildingUID"); - this.guildUID = rs.getInt("guildUID"); - this.friendType = rs.getInt("friendType"); - this.active = rs.getBoolean("active"); - } - - + public int getPlayerUID() { + return playerUID; + } - public Condemned(int playerUID, int parent, int guildUID, int friendType) { - super(); - this.playerUID = playerUID; - this.parent = parent; - this.guildUID = guildUID; - this.friendType = friendType; - this.active = false; - } + public int getParent() { + return parent; + } + public int getGuildUID() { + return guildUID; + } - public int getPlayerUID() { - return playerUID; - } + public int getFriendType() { + return friendType; + } + public boolean isActive() { + return active; + } - public int getParent() { - return parent; - } + public boolean setActive(boolean active) { + if (!DbManager.BuildingQueries.updateActiveCondemn(this, active)) + return false; + this.active = active; + return true; + } - public int getGuildUID() { - return guildUID; - } - - public int getFriendType() { - return friendType; - } - - public boolean isActive() { - return active; - } - - - - - public boolean setActive(boolean active) { - if (!DbManager.BuildingQueries.updateActiveCondemn(this, active)) - return false; - this.active = active; - return true; - } - - - - } diff --git a/src/engine/objects/Contract.java b/src/engine/objects/Contract.java index 2fb2626d..39f3a8ac 100644 --- a/src/engine/objects/Contract.java +++ b/src/engine/objects/Contract.java @@ -20,281 +20,277 @@ import java.util.ArrayList; public class Contract extends AbstractGameObject { - private final int contractID; - private final String name; - private final int mobbaseID; - private final int classID; - private final int extraRune; - private final int iconID; - private int vendorID; - private boolean isTrainer; - private VendorDialog vendorDialog; - private ArrayList npcMenuOptions = new ArrayList<>(); - private ArrayList npcModTypeTable = new ArrayList<>(); - private ArrayList npcModSuffixTable = new ArrayList<>(); - private ArrayList itemModTable = new ArrayList<>(); - private ArrayList sellInventory = new ArrayList<>(); - private EnumBitSet allowedBuildings; - - private ArrayList buyItemType = new ArrayList<>(); - private ArrayList buySkillToken = new ArrayList<>(); - private ArrayList buyUnknownToken = new ArrayList<>(); - - public int equipmentSet = 0; - public int inventorySet = 0; - - /** - * No Table ID Constructor - */ - public Contract(int contractID, String name, int mobbaseID, int classID, int dialogID, int iconID, int extraRune) { - super(); - this.contractID = contractID; - this.name = name; - this.mobbaseID = mobbaseID; - this.classID = classID; - this.iconID = iconID; - this.extraRune = extraRune; - this.vendorDialog = VendorDialog.getVendorDialog(dialogID); - setBools(); - } - - /** - * Normal Constructor - */ - public Contract(int contractID, String name, int mobbaseID, int classID, int dialogID, int iconID, int extraRune, int newUUID) { - super(newUUID); - this.contractID = contractID; - this.name = name; - this.mobbaseID = mobbaseID; - this.classID = classID; - this.iconID = iconID; - this.extraRune = extraRune; - this.vendorDialog = VendorDialog.getVendorDialog(dialogID); - setBools(); - } - - - - /** - * ResultSet Constructor - */ - public Contract(ResultSet rs) throws SQLException { - super(rs); - this.contractID = rs.getInt("contractID"); - this.name = rs.getString("name"); - this.mobbaseID = rs.getInt("mobbaseID"); - this.classID = rs.getInt("classID"); - this.extraRune = rs.getInt("extraRune"); - this.vendorDialog = VendorDialog.getVendorDialog(rs.getInt("dialogID")); - this.iconID = rs.getInt("iconID"); - this.vendorID = rs.getInt("vendorID"); - this.allowedBuildings = EnumBitSet.asEnumBitSet(rs.getLong("allowedBuildingTypeID"), Enum.BuildingGroup.class); - this.equipmentSet = rs.getInt("equipSetID"); - this.inventorySet = rs.getInt("inventorySet"); - - try { - String menuoptions = rs.getString("menuoptions"); - - if (!menuoptions.isEmpty()){ - String[] data = menuoptions.split(" "); - for (String data1 : data) { - this.npcMenuOptions.add(Integer.parseInt(data1)); - } - } - - String modtypetable = rs.getString("pTable"); - if (!modtypetable.isEmpty()){ - String[] data = modtypetable.split(" "); - for (String data1 : data) { - this.npcModTypeTable.add(Integer.parseInt(data1)); - } - } - - String suffix = rs.getString("sTable"); - - if (!suffix.isEmpty()){ - String[] data1 = suffix.split(" "); - - for (String data11 : data1) { - this.npcModSuffixTable.add(Integer.parseInt(data11)); - } - } - - String itemMod = rs.getString("itemModTable"); - - if (!itemMod.isEmpty()){ - String[] data2 = itemMod.split(" "); - for (byte i = 0; i < data2.length; i++) { - this.itemModTable.add(Byte.parseByte(data2[i])); - } - - } - - } catch (SQLException | NumberFormatException e) { - Logger.error( "Error when parsing mod tables"); - } - setBools(); - } - - //Specify if trainer, merchant, banker, etc via classID - private void setBools() { - DbManager.ContractQueries.LOAD_CONTRACT_INVENTORY(this); - DbManager.ContractQueries.LOAD_SELL_LIST_FOR_CONTRACT(this); - - this.isTrainer = this.classID > 2499 && this.classID < 3050 || this.classID == 2028; - - } - - /* - * Getters - */ - public int getContractID() { - return this.contractID; - } - - public String getName() { - return this.name; - } - - public int getMobbaseID() { - return this.mobbaseID; - } - - public int getClassID() { - return this.classID; - } - - public int getExtraRune() { - return this.extraRune; - } - - public boolean isTrainer() { - return this.isTrainer; - } - - public int getIconID() { - return this.iconID; - } - - public int getVendorID() { - return this.vendorID; - } - - public VendorDialog getVendorDialog() { - return this.vendorDialog; - } - - public ArrayList getNPCMenuOptions() { - return this.npcMenuOptions; - } - - public ArrayList getNPCModTypeTable() { - return this.npcModTypeTable; - } - - public ArrayList getNpcModSuffixTable() { - return npcModSuffixTable; - } - - public ArrayList getItemModTable() { - return itemModTable; - } - - public ArrayList getSellInventory() { - return this.sellInventory; - } - - public int getPromotionClass() { - if (this.classID < 2504 || this.classID > 2526) - return 0; - return this.classID; - } - - public boolean isRuneMaster() { - return (this.classID == 850); - } - - public boolean isArtilleryCaptain() { - return this.contractID == 839 || this.contractID == 842 ; - } - - - @Override - public void updateDatabase() { - DbManager.ContractQueries.updateDatabase(this); - } - - public EnumBitSet getAllowedBuildings() { - return allowedBuildings; - } - - public ArrayList getBuyItemType() { - return this.buyItemType; - } - - public ArrayList getBuySkillToken() { - return this.buySkillToken; - } - - public ArrayList getBuyUnknownToken() { - return this.buyUnknownToken; - } - - public boolean canSlotinBuilding(Building building) { - - // Need a building to slot in a building! - if (building == null) - return false; - - // Can't slot in anything but a blueprinted building - if (building.getBlueprintUUID() == 0) - return false; - - // No buildings no slotting - if (this.allowedBuildings.size() == 0) - return false; - - // Binary match - return (building.getBlueprint().getBuildingGroup().elementOf(this.allowedBuildings)); - } - - public int getEquipmentSet() { - return equipmentSet; - } - - public static boolean NoSlots(Contract contract){ - switch(contract.contractID){ - case 830: - case 838: - case 847: - case 860: - case 866: - case 865: - case 1502003: - case 889: - case 890: - case 896: - case 974: - case 1064: - case 1172: - case 1267: - case 1368: - case 1468: - case 1520: - case 1528: - case 1553: - case 1578: - case 1617: - case 1667: - case 1712: - case 893: - case 820: - return true; - - } - - if (contract.isTrainer) - return true; - return false; - } + private final int contractID; + private final String name; + private final int mobbaseID; + private final int classID; + private final int extraRune; + private final int iconID; + public int equipmentSet = 0; + public int inventorySet = 0; + private int vendorID; + private boolean isTrainer; + private VendorDialog vendorDialog; + private ArrayList npcMenuOptions = new ArrayList<>(); + private ArrayList npcModTypeTable = new ArrayList<>(); + private ArrayList npcModSuffixTable = new ArrayList<>(); + private ArrayList itemModTable = new ArrayList<>(); + private ArrayList sellInventory = new ArrayList<>(); + private EnumBitSet allowedBuildings; + private ArrayList buyItemType = new ArrayList<>(); + private ArrayList buySkillToken = new ArrayList<>(); + private ArrayList buyUnknownToken = new ArrayList<>(); + + /** + * No Table ID Constructor + */ + public Contract(int contractID, String name, int mobbaseID, int classID, int dialogID, int iconID, int extraRune) { + super(); + this.contractID = contractID; + this.name = name; + this.mobbaseID = mobbaseID; + this.classID = classID; + this.iconID = iconID; + this.extraRune = extraRune; + this.vendorDialog = VendorDialog.getVendorDialog(dialogID); + setBools(); + } + + /** + * Normal Constructor + */ + public Contract(int contractID, String name, int mobbaseID, int classID, int dialogID, int iconID, int extraRune, int newUUID) { + super(newUUID); + this.contractID = contractID; + this.name = name; + this.mobbaseID = mobbaseID; + this.classID = classID; + this.iconID = iconID; + this.extraRune = extraRune; + this.vendorDialog = VendorDialog.getVendorDialog(dialogID); + setBools(); + } + + + /** + * ResultSet Constructor + */ + public Contract(ResultSet rs) throws SQLException { + super(rs); + this.contractID = rs.getInt("contractID"); + this.name = rs.getString("name"); + this.mobbaseID = rs.getInt("mobbaseID"); + this.classID = rs.getInt("classID"); + this.extraRune = rs.getInt("extraRune"); + this.vendorDialog = VendorDialog.getVendorDialog(rs.getInt("dialogID")); + this.iconID = rs.getInt("iconID"); + this.vendorID = rs.getInt("vendorID"); + this.allowedBuildings = EnumBitSet.asEnumBitSet(rs.getLong("allowedBuildingTypeID"), Enum.BuildingGroup.class); + this.equipmentSet = rs.getInt("equipSetID"); + this.inventorySet = rs.getInt("inventorySet"); + + try { + String menuoptions = rs.getString("menuoptions"); + + if (!menuoptions.isEmpty()) { + String[] data = menuoptions.split(" "); + for (String data1 : data) { + this.npcMenuOptions.add(Integer.parseInt(data1)); + } + } + + String modtypetable = rs.getString("pTable"); + if (!modtypetable.isEmpty()) { + String[] data = modtypetable.split(" "); + for (String data1 : data) { + this.npcModTypeTable.add(Integer.parseInt(data1)); + } + } + + String suffix = rs.getString("sTable"); + + if (!suffix.isEmpty()) { + String[] data1 = suffix.split(" "); + + for (String data11 : data1) { + this.npcModSuffixTable.add(Integer.parseInt(data11)); + } + } + + String itemMod = rs.getString("itemModTable"); + + if (!itemMod.isEmpty()) { + String[] data2 = itemMod.split(" "); + for (byte i = 0; i < data2.length; i++) { + this.itemModTable.add(Byte.parseByte(data2[i])); + } + + } + + } catch (SQLException | NumberFormatException e) { + Logger.error("Error when parsing mod tables"); + } + setBools(); + } + + public static boolean NoSlots(Contract contract) { + switch (contract.contractID) { + case 830: + case 838: + case 847: + case 860: + case 866: + case 865: + case 1502003: + case 889: + case 890: + case 896: + case 974: + case 1064: + case 1172: + case 1267: + case 1368: + case 1468: + case 1520: + case 1528: + case 1553: + case 1578: + case 1617: + case 1667: + case 1712: + case 893: + case 820: + return true; + + } + + if (contract.isTrainer) + return true; + return false; + } + + //Specify if trainer, merchant, banker, etc via classID + private void setBools() { + DbManager.ContractQueries.LOAD_CONTRACT_INVENTORY(this); + DbManager.ContractQueries.LOAD_SELL_LIST_FOR_CONTRACT(this); + + this.isTrainer = this.classID > 2499 && this.classID < 3050 || this.classID == 2028; + + } + + /* + * Getters + */ + public int getContractID() { + return this.contractID; + } + + public String getName() { + return this.name; + } + + public int getMobbaseID() { + return this.mobbaseID; + } + + public int getClassID() { + return this.classID; + } + + public int getExtraRune() { + return this.extraRune; + } + + public boolean isTrainer() { + return this.isTrainer; + } + + public int getIconID() { + return this.iconID; + } + + public int getVendorID() { + return this.vendorID; + } + + public VendorDialog getVendorDialog() { + return this.vendorDialog; + } + + public ArrayList getNPCMenuOptions() { + return this.npcMenuOptions; + } + + public ArrayList getNPCModTypeTable() { + return this.npcModTypeTable; + } + + public ArrayList getNpcModSuffixTable() { + return npcModSuffixTable; + } + + public ArrayList getItemModTable() { + return itemModTable; + } + + public ArrayList getSellInventory() { + return this.sellInventory; + } + + public int getPromotionClass() { + if (this.classID < 2504 || this.classID > 2526) + return 0; + return this.classID; + } + + public boolean isRuneMaster() { + return (this.classID == 850); + } + + public boolean isArtilleryCaptain() { + return this.contractID == 839 || this.contractID == 842; + } + + @Override + public void updateDatabase() { + DbManager.ContractQueries.updateDatabase(this); + } + + public EnumBitSet getAllowedBuildings() { + return allowedBuildings; + } + + public ArrayList getBuyItemType() { + return this.buyItemType; + } + + public ArrayList getBuySkillToken() { + return this.buySkillToken; + } + + public ArrayList getBuyUnknownToken() { + return this.buyUnknownToken; + } + + public boolean canSlotinBuilding(Building building) { + + // Need a building to slot in a building! + if (building == null) + return false; + + // Can't slot in anything but a blueprinted building + if (building.getBlueprintUUID() == 0) + return false; + + // No buildings no slotting + if (this.allowedBuildings.size() == 0) + return false; + + // Binary match + return (building.getBlueprint().getBuildingGroup().elementOf(this.allowedBuildings)); + } + + public int getEquipmentSet() { + return equipmentSet; + } } diff --git a/src/engine/objects/Corpse.java b/src/engine/objects/Corpse.java index e9c4c195..9958a72b 100644 --- a/src/engine/objects/Corpse.java +++ b/src/engine/objects/Corpse.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -42,378 +39,374 @@ import java.util.concurrent.atomic.AtomicInteger; public class Corpse extends AbstractWorldObject { - private static AtomicInteger corpseCounter = new AtomicInteger(0); - - private String firstName; - private String lastName; - private int level; - private int belongsToType; - private int belongsToID; - private ArrayList inventory; - public JobContainer cleanup; - private boolean asciiLastName = true; - private boolean hasGold = false; - private int inBuildingID = 0; - private int inFloorID = -1; - private int inBuilding = -1; - - /** - * No Id Constructor - */ - public Corpse( int newUUID, AbstractCharacter belongsTo, boolean safeZone,boolean enterWorld) { - super(newUUID); - this.setObjectType(); - this.inventory = new ArrayList<>(); - this.gridObjectType = GridObjectType.STATIC; - this.setObjectTypeMask(MBServerStatics.MASK_CORPSE); - if (belongsTo != null) { - this.firstName = belongsTo.getFirstName(); - this.lastName = belongsTo.getLastName(); - this.asciiLastName = belongsTo.asciiLastName(); - this.level = belongsTo.getLevel(); - this.belongsToType = belongsTo.getObjectType().ordinal(); - this.belongsToID = belongsTo.getObjectUUID(); + private static AtomicInteger corpseCounter = new AtomicInteger(0); + public JobContainer cleanup; + private String firstName; + private String lastName; + private int level; + private int belongsToType; + private int belongsToID; + private ArrayList inventory; + private boolean asciiLastName = true; + private boolean hasGold = false; + private int inBuildingID = 0; + private int inFloorID = -1; + private int inBuilding = -1; + + /** + * No Id Constructor + */ + public Corpse(int newUUID, AbstractCharacter belongsTo, boolean safeZone, boolean enterWorld) { + super(newUUID); + this.setObjectType(); + this.inventory = new ArrayList<>(); + this.gridObjectType = GridObjectType.STATIC; + this.setObjectTypeMask(MBServerStatics.MASK_CORPSE); + if (belongsTo != null) { + this.firstName = belongsTo.getFirstName(); + this.lastName = belongsTo.getLastName(); + this.asciiLastName = belongsTo.asciiLastName(); + this.level = belongsTo.getLevel(); + this.belongsToType = belongsTo.getObjectType().ordinal(); + this.belongsToID = belongsTo.getObjectUUID(); this.inBuilding = belongsTo.getInBuilding(); this.inFloorID = belongsTo.getInFloorID(); this.inBuildingID = belongsTo.getInBuildingID(); - this.setLoc(belongsTo.getLoc()); - } else { - Logger.error("No player passed in for corpse"); - this.firstName = ""; - this.lastName = ""; - this.level = 1; - this.belongsToType = 0; - this.belongsToID = 0; - } - this.setObjectTypeMask(MBServerStatics.MASK_CORPSE); - - if (!safeZone) - transferInventory(belongsTo,enterWorld); - - - } - - public boolean removeItemFromInventory(Item item) { - synchronized (this.inventory) { - if (this.inventory.contains(item)) { - this.inventory.remove(item); - return true; - } - return false; - } - } - - public void transferInventory(AbstractCharacter belongsTo,boolean enterWorld) { - if (belongsTo == null) { - Logger.error( "Can't find player that corpse " + this.getObjectUUID() + " belongs to"); - return; - } - - //TODO transfer items from players inventory and trade window to corpse - CharacterItemManager cim = belongsTo.getCharItemManager(); - if (cim != null) - cim.transferEntireInventory(this.inventory, this,enterWorld); - else - Logger.error( "Can't find inventory for player " + belongsTo.getObjectUUID()); - } - - public static int getNextCorpseCount() { - return Corpse.corpseCounter.addAndGet(2); //newUUID and runeID - } - - //Create a new corpse - public static Corpse makeCorpse(AbstractCharacter belongsTo,boolean enterWorld) { - boolean safeZone = false; - if (belongsTo != null && belongsTo.getObjectType() == GameObjectType.PlayerCharacter) - safeZone = ((PlayerCharacter)belongsTo).isInSafeZone(); - - - - Corpse corpse = new Corpse(Corpse.getNextCorpseCount(), belongsTo, safeZone,enterWorld); - - //create cleanup job - if (corpse != null) { - RemoveCorpseJob rcj = new RemoveCorpseJob(corpse); + this.setLoc(belongsTo.getLoc()); + } else { + Logger.error("No player passed in for corpse"); + this.firstName = ""; + this.lastName = ""; + this.level = 1; + this.belongsToType = 0; + this.belongsToID = 0; + } + this.setObjectTypeMask(MBServerStatics.MASK_CORPSE); + + if (!safeZone) + transferInventory(belongsTo, enterWorld); + + + } + + public static int getNextCorpseCount() { + return Corpse.corpseCounter.addAndGet(2); //newUUID and runeID + } + + //Create a new corpse + public static Corpse makeCorpse(AbstractCharacter belongsTo, boolean enterWorld) { + boolean safeZone = false; + if (belongsTo != null && belongsTo.getObjectType() == GameObjectType.PlayerCharacter) + safeZone = ((PlayerCharacter) belongsTo).isInSafeZone(); + + + Corpse corpse = new Corpse(Corpse.getNextCorpseCount(), belongsTo, safeZone, enterWorld); + + //create cleanup job + if (corpse != null) { + RemoveCorpseJob rcj = new RemoveCorpseJob(corpse); corpse.cleanup = JobScheduler.getInstance().scheduleJob(rcj, MBServerStatics.CORPSE_CLEANUP_TIMER_MS); - DbManager.addToCache(corpse); - } - - return corpse; - } - - //Get existing corpse - public static Corpse getCorpse(int newUUID) { - return (Corpse) DbManager.getFromCache(GameObjectType.Corpse, newUUID); - } - - public Item lootItem(Item i, PlayerCharacter looter) { - //make sure looter exists - if (looter == null) - return null; - - //get looters item manager - CharacterItemManager looterItems = looter.getCharItemManager(); - if (looterItems == null) - return null; - - synchronized (this.inventory) { - - //make sure player has item in inventory - if (!this.inventory.contains(i)) - return null; - - //get weight of item - ItemBase ib = i.getItemBase(); - if (ib == null) - return null; - short weight = ib.getWeight(); - - //make sure looter has room for item - if (ib.getType().equals(ItemType.GOLD) == false && !looterItems.hasRoomInventory(weight)) - return null; - - //attempt to transfer item in db - if (ib.getType().equals(ItemType.GOLD)) { - if (!looterItems.moveGoldToInventory(i, i.getNumOfItems())) - return null; - } else if (!i.moveItemToInventory(looter)) - return null; - - //db transfer successful, remove from this character - this.inventory.remove(this.inventory.indexOf(i)); - } - - //add item to looter. - if (!looterItems.addItemToInventory(i)) - return null; - - //calculate new weights - looterItems.calculateInventoryWeight(); - - return i; - } - - - //remove corpse from world - public static void removeCorpse(int newUUID, boolean fromTimer) { - Corpse c = (Corpse) DbManager.getFromCache(GameObjectType.Corpse, newUUID); - if (c == null) - Logger.error( "No corpse found of ID " + newUUID); - else - Corpse.removeCorpse(c, fromTimer); - } - - public static void removeCorpse(Corpse corpse, boolean fromTimer) { - if (corpse == null) - return; - - corpse.purgeInventory(); - - //cleanup timer - if (!fromTimer) { - JobScheduler.getInstance().cancelScheduledJob(corpse.cleanup); - } - corpse.cleanup = null; - - //Remove from world - UnloadObjectsMsg uom = new UnloadObjectsMsg(); - uom.addObject(corpse); - DispatchMessage.sendToAllInRange(corpse, uom); - WorldGrid.RemoveWorldObject(corpse); - - //clear from cache - DbManager.removeFromCache(corpse); - } - - - public static void _serializeForClientMsg(Corpse corpse, ByteBufferWriter writer) - throws SerializationException {} - - public static void _serializeForClientMsg(Corpse corpse, ByteBufferWriter writer, boolean aln) - throws SerializationException { - - Building building = null; - if (corpse.inBuildingID != 0) - building = BuildingManager.getBuildingFromCache(corpse.inBuildingID); - - //Send Rune Count - writer.putInt(0); - writer.putInt(0); - writer.putInt(1); - - //Send Corpse Rune - writer.putInt(1); - writer.putInt(0); - writer.putInt(MBServerStatics.TOMBSTONE); - writer.putInt(corpse.getObjectType().ordinal()); - writer.putInt((corpse.getObjectUUID() + 1)); - - //Send Stats - writer.putInt(5); - writer.putInt(MBServerStatics.STAT_STR_ID); // Strength ID - writer.putInt(5000); - writer.putInt(MBServerStatics.STAT_SPI_ID); // Spirit ID - writer.putInt(0); - writer.putInt(MBServerStatics.STAT_CON_ID); // Constitution ID - writer.putInt(0); - writer.putInt(MBServerStatics.STAT_DEX_ID); // Dexterity ID - writer.putInt(0); - writer.putInt(MBServerStatics.STAT_INT_ID); // Intelligence ID - writer.putInt(0); - - //Send Name - writer.putString(corpse.firstName); - if (aln && !corpse.asciiLastName) - writer.putString(""); - else - writer.putString(corpse.lastName); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.put((byte)1); - - //Send Corpse Info - writer.putInt(0); - writer.putInt(corpse.getObjectType().ordinal()); - writer.putInt((corpse.getObjectUUID())); - writer.putFloat(10f); //FaceDir or scale - writer.putFloat(10); //FaceDir or scale - writer.putFloat(10); //FaceDir or scale - - writer.putFloat(corpse.getLoc().x); - writer.putFloat(corpse.getLoc().y); - writer.putFloat(corpse.getLoc().z); - - writer.putFloat(6.235f); //1.548146f); //w - writer.putInt(0); - writer.putInt(0); - - //Send BelongsToInfo - writer.putInt(((corpse.level / 10))); //Rank - writer.putInt(corpse.level); //Level - writer.putInt(1); - writer.putInt(1); - writer.putInt(1); //Missing this? - writer.putInt(2); - writer.putInt(1); - // writer.putInt(0); //not needed? - writer.putInt(0); - - writer.putInt(corpse.belongsToType); - writer.putInt(corpse.belongsToID); - - writer.putInt(0); - writer.putInt(0); - - - - for (int i=0;i<9;i++) - writer.putInt(0); - writer.putShort((short)0); - writer.put((byte)0); - - //Send Errant Guild Info - for (int i=0;i<13;i++) - writer.putInt(0); - writer.putInt(16); - writer.putInt(16); - writer.putInt(16); - writer.putInt(0); - writer.putInt(0); //Missing this? - writer.putInt(16); - writer.putInt(16); - writer.putInt(16); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - - //Send unknown counter - writer.putInt(1); - writer.putInt(0x047A0E67); //What is this? - writer.put((byte)0); - - //Send unknown - writer.putInt(0); - writer.putInt(0); - writer.putFloat(1293.4449f); //Unknown - writer.putFloat(-100f); //Unknown - writer.putInt(0); - writer.put((byte)0); - - writer.put((byte)0); //End datablock - - } - - - public boolean hasGold() { - return this.hasGold; - } - - public void setHasGold(boolean value) { - this.hasGold = value; - } - - public ArrayList getInventory() { - synchronized(this.inventory) { - return this.inventory; - } - } - - /** - * Delete and remove all items in the inventory - */ - private void purgeInventory() { - //make a copy so we're not inside synchronized{} while waiting for all items to be junked - ArrayList inventoryCopy; - synchronized(this.inventory) { - inventoryCopy = new ArrayList<>(this.inventory); - this.inventory.clear(); - } - - for (Item item : inventoryCopy) { - item.junk(); - } - } - - @Override - public void updateDatabase() { - } - - @Override - public void runAfterLoad() {} - - public int getBelongsToType() { - return this.belongsToType; - } - - public int getBelongsToID() { - return this.belongsToID; - } - - @Override - public String getName() { - if (this.firstName.length() == 0) { - return "Unknown corpse"; - } - if (this.lastName.length() == 0) { - return this.firstName; - } - return this.firstName + ' ' + this.lastName; - } - - public int getInBuilding() { - return inBuilding; - } - - public void setInBuilding(int inBuilding) { - this.inBuilding = inBuilding; - } - - public int getInFloorID() { - return inFloorID; - } - - public void setInFloorID(int inFloorID) { - this.inFloorID = inFloorID; - } + DbManager.addToCache(corpse); + } + + return corpse; + } + + //Get existing corpse + public static Corpse getCorpse(int newUUID) { + return (Corpse) DbManager.getFromCache(GameObjectType.Corpse, newUUID); + } + + //remove corpse from world + public static void removeCorpse(int newUUID, boolean fromTimer) { + Corpse c = (Corpse) DbManager.getFromCache(GameObjectType.Corpse, newUUID); + if (c == null) + Logger.error("No corpse found of ID " + newUUID); + else + Corpse.removeCorpse(c, fromTimer); + } + + public static void removeCorpse(Corpse corpse, boolean fromTimer) { + if (corpse == null) + return; + + corpse.purgeInventory(); + + //cleanup timer + if (!fromTimer) { + JobScheduler.getInstance().cancelScheduledJob(corpse.cleanup); + } + corpse.cleanup = null; + + //Remove from world + UnloadObjectsMsg uom = new UnloadObjectsMsg(); + uom.addObject(corpse); + DispatchMessage.sendToAllInRange(corpse, uom); + WorldGrid.RemoveWorldObject(corpse); + + //clear from cache + DbManager.removeFromCache(corpse); + } + + public static void _serializeForClientMsg(Corpse corpse, ByteBufferWriter writer) + throws SerializationException { + } + + public static void _serializeForClientMsg(Corpse corpse, ByteBufferWriter writer, boolean aln) + throws SerializationException { + + Building building = null; + if (corpse.inBuildingID != 0) + building = BuildingManager.getBuildingFromCache(corpse.inBuildingID); + + //Send Rune Count + writer.putInt(0); + writer.putInt(0); + writer.putInt(1); + + //Send Corpse Rune + writer.putInt(1); + writer.putInt(0); + writer.putInt(MBServerStatics.TOMBSTONE); + writer.putInt(corpse.getObjectType().ordinal()); + writer.putInt((corpse.getObjectUUID() + 1)); + + //Send Stats + writer.putInt(5); + writer.putInt(MBServerStatics.STAT_STR_ID); // Strength ID + writer.putInt(5000); + writer.putInt(MBServerStatics.STAT_SPI_ID); // Spirit ID + writer.putInt(0); + writer.putInt(MBServerStatics.STAT_CON_ID); // Constitution ID + writer.putInt(0); + writer.putInt(MBServerStatics.STAT_DEX_ID); // Dexterity ID + writer.putInt(0); + writer.putInt(MBServerStatics.STAT_INT_ID); // Intelligence ID + writer.putInt(0); + + //Send Name + writer.putString(corpse.firstName); + if (aln && !corpse.asciiLastName) + writer.putString(""); + else + writer.putString(corpse.lastName); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 1); + + //Send Corpse Info + writer.putInt(0); + writer.putInt(corpse.getObjectType().ordinal()); + writer.putInt((corpse.getObjectUUID())); + writer.putFloat(10f); //FaceDir or scale + writer.putFloat(10); //FaceDir or scale + writer.putFloat(10); //FaceDir or scale + + writer.putFloat(corpse.getLoc().x); + writer.putFloat(corpse.getLoc().y); + writer.putFloat(corpse.getLoc().z); + + writer.putFloat(6.235f); //1.548146f); //w + writer.putInt(0); + writer.putInt(0); + + //Send BelongsToInfo + writer.putInt(((corpse.level / 10))); //Rank + writer.putInt(corpse.level); //Level + writer.putInt(1); + writer.putInt(1); + writer.putInt(1); //Missing this? + writer.putInt(2); + writer.putInt(1); + // writer.putInt(0); //not needed? + writer.putInt(0); + + writer.putInt(corpse.belongsToType); + writer.putInt(corpse.belongsToID); + + writer.putInt(0); + writer.putInt(0); + + + for (int i = 0; i < 9; i++) + writer.putInt(0); + writer.putShort((short) 0); + writer.put((byte) 0); + + //Send Errant Guild Info + for (int i = 0; i < 13; i++) + writer.putInt(0); + writer.putInt(16); + writer.putInt(16); + writer.putInt(16); + writer.putInt(0); + writer.putInt(0); //Missing this? + writer.putInt(16); + writer.putInt(16); + writer.putInt(16); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + + //Send unknown counter + writer.putInt(1); + writer.putInt(0x047A0E67); //What is this? + writer.put((byte) 0); + + //Send unknown + writer.putInt(0); + writer.putInt(0); + writer.putFloat(1293.4449f); //Unknown + writer.putFloat(-100f); //Unknown + writer.putInt(0); + writer.put((byte) 0); + + writer.put((byte) 0); //End datablock + + } + + public boolean removeItemFromInventory(Item item) { + synchronized (this.inventory) { + if (this.inventory.contains(item)) { + this.inventory.remove(item); + return true; + } + return false; + } + } + + public void transferInventory(AbstractCharacter belongsTo, boolean enterWorld) { + if (belongsTo == null) { + Logger.error("Can't find player that corpse " + this.getObjectUUID() + " belongs to"); + return; + } + + //TODO transfer items from players inventory and trade window to corpse + CharacterItemManager cim = belongsTo.getCharItemManager(); + if (cim != null) + cim.transferEntireInventory(this.inventory, this, enterWorld); + else + Logger.error("Can't find inventory for player " + belongsTo.getObjectUUID()); + } + + public Item lootItem(Item i, PlayerCharacter looter) { + //make sure looter exists + if (looter == null) + return null; + + //get looters item manager + CharacterItemManager looterItems = looter.getCharItemManager(); + if (looterItems == null) + return null; + + synchronized (this.inventory) { + + //make sure player has item in inventory + if (!this.inventory.contains(i)) + return null; + + //get weight of item + ItemBase ib = i.getItemBase(); + if (ib == null) + return null; + short weight = ib.getWeight(); + + //make sure looter has room for item + if (ib.getType().equals(ItemType.GOLD) == false && !looterItems.hasRoomInventory(weight)) + return null; + + //attempt to transfer item in db + if (ib.getType().equals(ItemType.GOLD)) { + if (!looterItems.moveGoldToInventory(i, i.getNumOfItems())) + return null; + } else if (!i.moveItemToInventory(looter)) + return null; + + //db transfer successful, remove from this character + this.inventory.remove(this.inventory.indexOf(i)); + } + + //add item to looter. + if (!looterItems.addItemToInventory(i)) + return null; + + //calculate new weights + looterItems.calculateInventoryWeight(); + + return i; + } + + public boolean hasGold() { + return this.hasGold; + } + + public void setHasGold(boolean value) { + this.hasGold = value; + } + + public ArrayList getInventory() { + synchronized (this.inventory) { + return this.inventory; + } + } + + /** + * Delete and remove all items in the inventory + */ + private void purgeInventory() { + //make a copy so we're not inside synchronized{} while waiting for all items to be junked + ArrayList inventoryCopy; + synchronized (this.inventory) { + inventoryCopy = new ArrayList<>(this.inventory); + this.inventory.clear(); + } + + for (Item item : inventoryCopy) { + item.junk(); + } + } + + @Override + public void updateDatabase() { + } + + @Override + public void runAfterLoad() { + } + + public int getBelongsToType() { + return this.belongsToType; + } + + public int getBelongsToID() { + return this.belongsToID; + } + + @Override + public String getName() { + if (this.firstName.length() == 0) { + return "Unknown corpse"; + } + if (this.lastName.length() == 0) { + return this.firstName; + } + return this.firstName + ' ' + this.lastName; + } + + public int getInBuilding() { + return inBuilding; + } + + public void setInBuilding(int inBuilding) { + this.inBuilding = inBuilding; + } + + public int getInFloorID() { + return inFloorID; + } + + public void setInFloorID(int inFloorID) { + this.inFloorID = inFloorID; + } } diff --git a/src/engine/objects/Effect.java b/src/engine/objects/Effect.java index 85f73226..60e991c8 100644 --- a/src/engine/objects/Effect.java +++ b/src/engine/objects/Effect.java @@ -7,7 +7,7 @@ // www.magicbane.com - package engine.objects; +package engine.objects; import engine.Enum.DamageType; import engine.Enum.EffectSourceType; @@ -32,634 +32,632 @@ import java.util.concurrent.atomic.AtomicBoolean; public class Effect { - private JobContainer jc; - - //Fail Conditions - private boolean cancelOnAttack; - private boolean cancelOnAttackSwing; - private boolean cancelOnCast; - private boolean cancelOnCastSpell; - private boolean cancelOnEquipChange; - private boolean cancelOnLogout; - private boolean cancelOnMove; - private boolean cancelOnNewCharm; - private boolean cancelOnSit; - private boolean cancelOnTakeDamage; - private boolean cancelOnTerritoryClaim; - private boolean cancelOnUnEquip; - private boolean cancelOnStun; - private boolean bakedInStat = false; - private boolean isStatic = false; - private int effectSourceType = 0; - private int effectSourceID = 0; - - - private EffectsBase eb; - private int trains; - private float damageAmount = 0f; - - private AtomicBoolean cancel = new AtomicBoolean(false); - - //private AbstractWorldObject owner; - - /** - * Generic Constructor - */ - public Effect(JobContainer jc, EffectsBase eb, int trains) { - this.jc = jc; - this.cancelOnAttack = false; - this.cancelOnAttackSwing = false; - this.cancelOnCast = false; - this.cancelOnCastSpell = false; - this.cancelOnEquipChange = false; - this.cancelOnLogout = false; - this.cancelOnMove = false; - this.cancelOnNewCharm = false; - this.cancelOnSit = false; - this.cancelOnTakeDamage = false; - this.cancelOnTerritoryClaim = false; - this.cancelOnUnEquip = false; - this.cancelOnStun = false; - this.eb = eb; - this.trains = trains; - } - - public Effect(JobContainer jc, EffectsBase eb, int trains,boolean isStatic) { - this.jc = jc; - this.cancelOnAttack = false; - this.cancelOnAttackSwing = false; - this.cancelOnCast = false; - this.cancelOnCastSpell = false; - this.cancelOnEquipChange = false; - this.cancelOnLogout = false; - this.cancelOnMove = false; - this.cancelOnNewCharm = false; - this.cancelOnSit = false; - this.cancelOnTakeDamage = false; - this.cancelOnTerritoryClaim = false; - this.cancelOnUnEquip = false; - this.cancelOnStun = false; - this.eb = eb; - this.trains = trains; - this.isStatic = isStatic; - } - - //called when effect ends. Send message to client to remove effect - public void endEffect() { - if (this.jc != null) { - AbstractJob aj = jc.getJob(); - if (aj == null) - return; - if (aj instanceof AbstractEffectJob) { - ((AbstractEffectJob)aj).setSkipCancelEffect(false); - ((AbstractEffectJob)aj).endEffect(); - } - } - } - - public void endEffectNoPower() { - if (this.jc != null) { - AbstractJob aj = jc.getJob(); - if (aj == null) - return; - if (aj instanceof AbstractEffectJob) { - ((AbstractEffectJob)aj).setSkipCancelEffect(false); - ((AbstractEffectJob)aj).endEffectNoPower(); - } - } - } - - //Called when effect ends before timer done - public void cancelJob() { - if (this.jc != null) { - AbstractJob aj = jc.getJob(); - if (aj == null) - return; - if (aj instanceof AbstractEffectJob) - ((AbstractEffectJob)aj).setSkipCancelEffect(false); - if (aj instanceof AbstractScheduleJob) { - ((AbstractScheduleJob)aj).cancelJob(); - } - } - } - - public void cancelJob(boolean skipEffect) { - if (this.jc != null) { - AbstractJob aj = jc.getJob(); - if (aj == null) - return; - if (skipEffect && aj instanceof AbstractEffectJob) { - ((AbstractEffectJob)aj).setSkipCancelEffect(skipEffect); - } - if (aj instanceof AbstractScheduleJob) { - ((AbstractScheduleJob)aj).cancelJob(); - } - } - } - - public boolean applyBonus(Item item) { - if (this.jc == null) - return false; - AbstractJob aj = jc.getJob(); - if (aj == null) - return false; - if (aj instanceof AbstractEffectJob) { - AbstractEffectJob aej = (AbstractEffectJob)aj; - EffectsBase eb = aej.getEffect(); - if (eb == null) - return false; - HashSet aems = eb.getModifiers(); - for(AbstractEffectModifier aem : aems) - aem.applyBonus(item, aej.getTrains()); - return true; - } - return false; - } - - public boolean applyBonus(Building building) { - if (this.jc == null) - return false; - AbstractJob aj = jc.getJob(); - if (aj == null) - return false; - if (aj instanceof AbstractEffectJob) { - AbstractEffectJob aej = (AbstractEffectJob)aj; - EffectsBase eb = aej.getEffect(); - if (eb == null) - return false; - HashSet aems = eb.getModifiers(); - for(AbstractEffectModifier aem : aems) - aem.applyBonus(building, aej.getTrains()); - return true; - } - return false; - } - - public boolean applyBonus(AbstractCharacter ac) { - if (this.jc == null) - return false; - AbstractJob aj = jc.getJob(); - if (aj == null) - return false; - if (aj instanceof AbstractEffectJob) { - AbstractEffectJob aej = (AbstractEffectJob)aj; - EffectsBase eb = aej.getEffect(); - if (eb == null) - return false; - HashSet aems = eb.getModifiers(); - for(AbstractEffectModifier aem : aems) - aem.applyBonus(ac, aej.getTrains()); - return true; - } - return false; - } - - public boolean applyBonus(Item item, AbstractCharacter ac) { - if (this.jc == null) - return false; - AbstractJob aj = jc.getJob(); - if (aj == null) - return false; - if (aj instanceof AbstractEffectJob) { - AbstractEffectJob aej = (AbstractEffectJob)aj; - EffectsBase eb = aej.getEffect(); - if (eb == null) - return false; - HashSet aems = eb.getModifiers(); - for(AbstractEffectModifier aem : aems) { - aem.applyBonus(item, aej.getTrains()); - aem.applyBonus(ac, aej.getTrains()); - } - return true; - } - return false; - } - - public HashSet getEffectModifiers() { - if (this.jc == null) - return null; - AbstractJob aj = jc.getJob(); - if (aj == null) - return null; - if (aj instanceof AbstractEffectJob) { - AbstractEffectJob aej = (AbstractEffectJob)aj; - EffectsBase eb = aej.getEffect(); - if (eb == null) - return null; - return eb.getModifiers(); - } - return null; - } - - - //Send this effect to a client when loading a player - public void sendEffect(ClientConnection cc) { - if (this.jc == null || this.eb == null || cc == null) - return; - AbstractJob aj = this.jc.getJob(); - if (aj == null || (!(aj instanceof AbstractEffectJob))) - return; - this.eb.sendEffect((AbstractEffectJob)aj, (this.jc.timeToExecutionLeft() / 1000), cc); - } - - public void sendEffectNoPower(ClientConnection cc) { - if (this.jc == null || this.eb == null || cc == null) - return; - AbstractJob aj = this.jc.getJob(); - if (aj == null || (!(aj instanceof AbstractEffectJob))) - return; - this.eb.sendEffectNoPower((AbstractEffectJob)aj, (this.jc.timeToExecutionLeft() / 1000), cc); - } - - public void sendSpireEffect(ClientConnection cc, boolean onEnter) { - if (this.jc == null || this.eb == null || cc == null) - return; - AbstractJob aj = this.jc.getJob(); - if (aj == null || (!(aj instanceof AbstractEffectJob))) - return; - int duration = 45; - if (onEnter) - duration = -1; - this.eb.sendEffectNoPower((AbstractEffectJob)aj, duration, cc); - } - - public void serializeForItem(ByteBufferWriter writer, Item item) { - if (this.jc == null) { - blankFill(writer); - return; - } - AbstractJob aj = this.jc.getJob(); - if (aj == null || (!(aj instanceof AbstractEffectJob))) { - blankFill(writer); - return; - } - AbstractEffectJob aej = (AbstractEffectJob)aj; - PowersBase pb = aej.getPower(); - ActionsBase ab = aej.getAction(); - if (this.eb == null) { - blankFill(writer); - return; - } else if (pb == null && !(this.jc.noTimer())) { - blankFill(writer); - return; - } - if (this.jc.noTimer()) { - if (pb == null) - writer.putInt(this.eb.getToken()); - else - writer.putInt(pb.getToken()); - writer.putInt(aej.getTrains()); - writer.putInt(1); - writer.put((byte)1); - writer.putInt(item.getObjectType().ordinal()); - writer.putInt(item.getObjectUUID()); - - writer.putString(item.getName()); - writer.putFloat(-1000f); - } else { - float duration = this.jc.timeToExecutionLeft() / 1000; - writer.putInt(this.eb.getToken()); - writer.putInt(aej.getTrains()); - writer.putInt(0); - writer.put((byte)0); - writer.putInt(pb.getToken()); - writer.putString(pb.getName()); - writer.putFloat(duration); - } - } - - public void serializeForClientMsg(ByteBufferWriter writer) { - AbstractJob aj = this.jc.getJob(); - if (aj == null || (!(aj instanceof AbstractEffectJob))) { - //TODO put error message here - blankFill(writer); - return; - } - AbstractEffectJob aej = (AbstractEffectJob)aj; - PowersBase pb = aej.getPower(); - ActionsBase ab = aej.getAction(); - if (ab == null || pb == null || this.eb == null) { - //TODO put error message here - blankFill(writer); - return; - } - - if ( aej instanceof PersistentAoeJob){ - blankFill(writer); - return; - } - - float duration = this.jc.timeToExecutionLeft() / 1000; - if (aej instanceof DamageOverTimeJob) - duration = ab.getDurationInSeconds(aej.getTrains()) - (((DamageOverTimeJob)aej).getIteration()*5); - - - - writer.putInt(pb.getToken()); - writer.putInt(aej.getTrains()); - writer.putInt(0); - writer.put((byte)0); - writer.putInt(this.eb.getToken()); - writer.putString(pb.getName()); - writer.putFloat(duration); - } - - public boolean serializeForLoad(ByteBufferWriter writer) { - AbstractJob aj = this.jc.getJob(); - if (aj == null || (!(aj instanceof AbstractEffectJob))) { - return false; - } - - - AbstractEffectJob aej = (AbstractEffectJob)aj; - PowersBase pb = aej.getPower(); - ActionsBase ab = aej.getAction(); - if (this.eb == null) { - return false; - } - if ( aej instanceof PersistentAoeJob){ - return false; - } - - - float duration = this.jc.timeToExecutionLeft() / 1000; - if (aej instanceof DamageOverTimeJob) - if (ab != null) - duration = ab.getDurationInSeconds(aej.getTrains()) - (((DamageOverTimeJob)aej).getIteration()*5); - if (aej instanceof NoTimeJob) - duration = -1; - - int sendToken = this.getEffectToken(); - - if (aej.getAction() != null) - if ( aej.getAction().getPowerAction() != null - && PowersManager.ActionTokenByIDString.containsKey(aej.getAction().getPowerAction().getIDString())) - try{ - sendToken = PowersManager.ActionTokenByIDString.get(aej.getAction().getPowerAction().getIDString()); - }catch(Exception e){ - sendToken = this.getEffectToken(); - } - - - writer.putInt(sendToken); + private JobContainer jc; + + //Fail Conditions + private boolean cancelOnAttack; + private boolean cancelOnAttackSwing; + private boolean cancelOnCast; + private boolean cancelOnCastSpell; + private boolean cancelOnEquipChange; + private boolean cancelOnLogout; + private boolean cancelOnMove; + private boolean cancelOnNewCharm; + private boolean cancelOnSit; + private boolean cancelOnTakeDamage; + private boolean cancelOnTerritoryClaim; + private boolean cancelOnUnEquip; + private boolean cancelOnStun; + private boolean bakedInStat = false; + private boolean isStatic = false; + private int effectSourceType = 0; + private int effectSourceID = 0; + + + private EffectsBase eb; + private int trains; + private float damageAmount = 0f; + + private AtomicBoolean cancel = new AtomicBoolean(false); + + //private AbstractWorldObject owner; + + /** + * Generic Constructor + */ + public Effect(JobContainer jc, EffectsBase eb, int trains) { + this.jc = jc; + this.cancelOnAttack = false; + this.cancelOnAttackSwing = false; + this.cancelOnCast = false; + this.cancelOnCastSpell = false; + this.cancelOnEquipChange = false; + this.cancelOnLogout = false; + this.cancelOnMove = false; + this.cancelOnNewCharm = false; + this.cancelOnSit = false; + this.cancelOnTakeDamage = false; + this.cancelOnTerritoryClaim = false; + this.cancelOnUnEquip = false; + this.cancelOnStun = false; + this.eb = eb; + this.trains = trains; + } + + public Effect(JobContainer jc, EffectsBase eb, int trains, boolean isStatic) { + this.jc = jc; + this.cancelOnAttack = false; + this.cancelOnAttackSwing = false; + this.cancelOnCast = false; + this.cancelOnCastSpell = false; + this.cancelOnEquipChange = false; + this.cancelOnLogout = false; + this.cancelOnMove = false; + this.cancelOnNewCharm = false; + this.cancelOnSit = false; + this.cancelOnTakeDamage = false; + this.cancelOnTerritoryClaim = false; + this.cancelOnUnEquip = false; + this.cancelOnStun = false; + this.eb = eb; + this.trains = trains; + this.isStatic = isStatic; + } + + private static void blankFill(ByteBufferWriter writer) { + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + } + + //called when effect ends. Send message to client to remove effect + public void endEffect() { + if (this.jc != null) { + AbstractJob aj = jc.getJob(); + if (aj == null) + return; + if (aj instanceof AbstractEffectJob) { + ((AbstractEffectJob) aj).setSkipCancelEffect(false); + ((AbstractEffectJob) aj).endEffect(); + } + } + } + + public void endEffectNoPower() { + if (this.jc != null) { + AbstractJob aj = jc.getJob(); + if (aj == null) + return; + if (aj instanceof AbstractEffectJob) { + ((AbstractEffectJob) aj).setSkipCancelEffect(false); + ((AbstractEffectJob) aj).endEffectNoPower(); + } + } + } + + //Called when effect ends before timer done + public void cancelJob() { + if (this.jc != null) { + AbstractJob aj = jc.getJob(); + if (aj == null) + return; + if (aj instanceof AbstractEffectJob) + ((AbstractEffectJob) aj).setSkipCancelEffect(false); + if (aj instanceof AbstractScheduleJob) { + ((AbstractScheduleJob) aj).cancelJob(); + } + } + } + + public void cancelJob(boolean skipEffect) { + if (this.jc != null) { + AbstractJob aj = jc.getJob(); + if (aj == null) + return; + if (skipEffect && aj instanceof AbstractEffectJob) { + ((AbstractEffectJob) aj).setSkipCancelEffect(skipEffect); + } + if (aj instanceof AbstractScheduleJob) { + ((AbstractScheduleJob) aj).cancelJob(); + } + } + } + + public boolean applyBonus(Item item) { + if (this.jc == null) + return false; + AbstractJob aj = jc.getJob(); + if (aj == null) + return false; + if (aj instanceof AbstractEffectJob) { + AbstractEffectJob aej = (AbstractEffectJob) aj; + EffectsBase eb = aej.getEffect(); + if (eb == null) + return false; + HashSet aems = eb.getModifiers(); + for (AbstractEffectModifier aem : aems) + aem.applyBonus(item, aej.getTrains()); + return true; + } + return false; + } + + public boolean applyBonus(Building building) { + if (this.jc == null) + return false; + AbstractJob aj = jc.getJob(); + if (aj == null) + return false; + if (aj instanceof AbstractEffectJob) { + AbstractEffectJob aej = (AbstractEffectJob) aj; + EffectsBase eb = aej.getEffect(); + if (eb == null) + return false; + HashSet aems = eb.getModifiers(); + for (AbstractEffectModifier aem : aems) + aem.applyBonus(building, aej.getTrains()); + return true; + } + return false; + } + + public boolean applyBonus(AbstractCharacter ac) { + if (this.jc == null) + return false; + AbstractJob aj = jc.getJob(); + if (aj == null) + return false; + if (aj instanceof AbstractEffectJob) { + AbstractEffectJob aej = (AbstractEffectJob) aj; + EffectsBase eb = aej.getEffect(); + if (eb == null) + return false; + HashSet aems = eb.getModifiers(); + for (AbstractEffectModifier aem : aems) + aem.applyBonus(ac, aej.getTrains()); + return true; + } + return false; + } + + public boolean applyBonus(Item item, AbstractCharacter ac) { + if (this.jc == null) + return false; + AbstractJob aj = jc.getJob(); + if (aj == null) + return false; + if (aj instanceof AbstractEffectJob) { + AbstractEffectJob aej = (AbstractEffectJob) aj; + EffectsBase eb = aej.getEffect(); + if (eb == null) + return false; + HashSet aems = eb.getModifiers(); + for (AbstractEffectModifier aem : aems) { + aem.applyBonus(item, aej.getTrains()); + aem.applyBonus(ac, aej.getTrains()); + } + return true; + } + return false; + } + + public HashSet getEffectModifiers() { + if (this.jc == null) + return null; + AbstractJob aj = jc.getJob(); + if (aj == null) + return null; + if (aj instanceof AbstractEffectJob) { + AbstractEffectJob aej = (AbstractEffectJob) aj; + EffectsBase eb = aej.getEffect(); + if (eb == null) + return null; + return eb.getModifiers(); + } + return null; + } + + //Send this effect to a client when loading a player + public void sendEffect(ClientConnection cc) { + if (this.jc == null || this.eb == null || cc == null) + return; + AbstractJob aj = this.jc.getJob(); + if (aj == null || (!(aj instanceof AbstractEffectJob))) + return; + this.eb.sendEffect((AbstractEffectJob) aj, (this.jc.timeToExecutionLeft() / 1000), cc); + } + + public void sendEffectNoPower(ClientConnection cc) { + if (this.jc == null || this.eb == null || cc == null) + return; + AbstractJob aj = this.jc.getJob(); + if (aj == null || (!(aj instanceof AbstractEffectJob))) + return; + this.eb.sendEffectNoPower((AbstractEffectJob) aj, (this.jc.timeToExecutionLeft() / 1000), cc); + } + + public void sendSpireEffect(ClientConnection cc, boolean onEnter) { + if (this.jc == null || this.eb == null || cc == null) + return; + AbstractJob aj = this.jc.getJob(); + if (aj == null || (!(aj instanceof AbstractEffectJob))) + return; + int duration = 45; + if (onEnter) + duration = -1; + this.eb.sendEffectNoPower((AbstractEffectJob) aj, duration, cc); + } + + public void serializeForItem(ByteBufferWriter writer, Item item) { + if (this.jc == null) { + blankFill(writer); + return; + } + AbstractJob aj = this.jc.getJob(); + if (aj == null || (!(aj instanceof AbstractEffectJob))) { + blankFill(writer); + return; + } + AbstractEffectJob aej = (AbstractEffectJob) aj; + PowersBase pb = aej.getPower(); + ActionsBase ab = aej.getAction(); + if (this.eb == null) { + blankFill(writer); + return; + } else if (pb == null && !(this.jc.noTimer())) { + blankFill(writer); + return; + } + if (this.jc.noTimer()) { + if (pb == null) + writer.putInt(this.eb.getToken()); + else + writer.putInt(pb.getToken()); + writer.putInt(aej.getTrains()); + writer.putInt(1); + writer.put((byte) 1); + writer.putInt(item.getObjectType().ordinal()); + writer.putInt(item.getObjectUUID()); + + writer.putString(item.getName()); + writer.putFloat(-1000f); + } else { + float duration = this.jc.timeToExecutionLeft() / 1000; + writer.putInt(this.eb.getToken()); + writer.putInt(aej.getTrains()); + writer.putInt(0); + writer.put((byte) 0); + writer.putInt(pb.getToken()); + writer.putString(pb.getName()); + writer.putFloat(duration); + } + } + + public void serializeForClientMsg(ByteBufferWriter writer) { + AbstractJob aj = this.jc.getJob(); + if (aj == null || (!(aj instanceof AbstractEffectJob))) { + //TODO put error message here + blankFill(writer); + return; + } + AbstractEffectJob aej = (AbstractEffectJob) aj; + PowersBase pb = aej.getPower(); + ActionsBase ab = aej.getAction(); + if (ab == null || pb == null || this.eb == null) { + //TODO put error message here + blankFill(writer); + return; + } + + if (aej instanceof PersistentAoeJob) { + blankFill(writer); + return; + } + + float duration = this.jc.timeToExecutionLeft() / 1000; + if (aej instanceof DamageOverTimeJob) + duration = ab.getDurationInSeconds(aej.getTrains()) - (((DamageOverTimeJob) aej).getIteration() * 5); + + + writer.putInt(pb.getToken()); + writer.putInt(aej.getTrains()); + writer.putInt(0); + writer.put((byte) 0); + writer.putInt(this.eb.getToken()); + writer.putString(pb.getName()); + writer.putFloat(duration); + } + + public boolean serializeForLoad(ByteBufferWriter writer) { + AbstractJob aj = this.jc.getJob(); + if (aj == null || (!(aj instanceof AbstractEffectJob))) { + return false; + } + + + AbstractEffectJob aej = (AbstractEffectJob) aj; + PowersBase pb = aej.getPower(); + ActionsBase ab = aej.getAction(); + if (this.eb == null) { + return false; + } + if (aej instanceof PersistentAoeJob) { + return false; + } + + + float duration = this.jc.timeToExecutionLeft() / 1000; + if (aej instanceof DamageOverTimeJob) + if (ab != null) + duration = ab.getDurationInSeconds(aej.getTrains()) - (((DamageOverTimeJob) aej).getIteration() * 5); + if (aej instanceof NoTimeJob) + duration = -1; + + int sendToken = this.getEffectToken(); + + if (aej.getAction() != null) + if (aej.getAction().getPowerAction() != null + && PowersManager.ActionTokenByIDString.containsKey(aej.getAction().getPowerAction().getIDString())) + try { + sendToken = PowersManager.ActionTokenByIDString.get(aej.getAction().getPowerAction().getIDString()); + } catch (Exception e) { + sendToken = this.getEffectToken(); + } + + + writer.putInt(sendToken); writer.putInt(this.trains); - writer.putInt(0); //? - if (aej.getEffectSourceID() != 0){ - writer.put((byte) 1); - writer.putInt(aej.getEffectSourceType()); - writer.putInt(aej.getEffectSourceID()); - }else{ - writer.put((byte)0); - writer.putInt(pb != null ? pb.getToken() : 0); - } - writer.putString(pb != null ? pb.getName() : eb.getName()); - - writer.putFloat(duration); + writer.putInt(0); //? + if (aej.getEffectSourceID() != 0) { + writer.put((byte) 1); + writer.putInt(aej.getEffectSourceType()); + writer.putInt(aej.getEffectSourceID()); + } else { + writer.put((byte) 0); + writer.putInt(pb != null ? pb.getToken() : 0); + } + writer.putString(pb != null ? pb.getName() : eb.getName()); + + writer.putFloat(duration); return true; - } - - private static void blankFill(ByteBufferWriter writer) { - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.put((byte)0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - } - - public float getDuration() { - float duration = 0f; - if (this.jc != null) - duration = this.jc.timeToExecutionLeft() / 1000; - return duration; - } - - public boolean containsSource(EffectSourceType source) { - if (this.eb != null) - return this.eb.containsSource(source); - return false; - } - - public JobContainer getJobContainer() { - return this.jc; - } - - public int getTrains() { - return this.trains; - } - - public void setTrains(int value) { - this.trains = value; - } - - public float getDamageAmount() { - return this.damageAmount; - } - - public AbstractJob getJob() { - if (this.jc == null) - return null; - return jc.getJob(); - } - - public boolean bakedInStat() { - return this.bakedInStat; - } - - public void setBakedInStat(boolean value) { - this.bakedInStat = value; - } - - public PowersBase getPower() { - if (this.jc == null) - return null; - AbstractJob aj = jc.getJob(); - if (aj == null || (!(aj instanceof AbstractEffectJob))) - return null; - return ((AbstractEffectJob)aj).getPower(); - } - - public int getPowerToken() { - if (this.jc == null) - return 0; - AbstractJob aj = jc.getJob(); - if (aj == null || (!(aj instanceof AbstractEffectJob))) - return 0; - PowersBase pb = ((AbstractEffectJob)aj).getPower(); - if (pb == null) - return 0; - return pb.getToken(); - } - - public int getEffectToken() { - if (this.eb != null) - return this.eb.getToken(); - return 0; - } - - public EffectsBase getEffectsBase() { - return this.eb; - } - - public String getName() { - if (this.jc == null) - return ""; - AbstractJob aj = this.jc.getJob(); - if (aj == null || !(aj instanceof AbstractEffectJob)) - return ""; - AbstractEffectJob aej = (AbstractEffectJob)aj; - PowersBase pb = aej.getPower(); - if (pb == null) - return ""; - return pb.getName(); - } - - public boolean cancel() { - return this.cancel.compareAndSet(false, true); - } - - public boolean canceled() { - return this.cancel.get(); - } - - public boolean cancelOnAttack() { - if (this.eb == null) - return true; - return this.eb.cancelOnAttack(); - } - - public boolean cancelOnAttackSwing() { - if (this.eb == null) - return true; - return this.eb.cancelOnAttackSwing(); - } - - public boolean cancelOnCast() { - if (this.eb == null) - return true; - return this.eb.cancelOnCast(); - } - - public boolean cancelOnCastSpell() { - if (this.eb == null) - return true; - return this.eb.cancelOnCastSpell(); - } - - public boolean cancelOnEquipChange() { - if (this.eb == null) - return true; - return this.eb.cancelOnEquipChange(); - } - - public boolean cancelOnLogout() { - if (this.eb == null) - return true; - return this.eb.cancelOnLogout(); - } - - public boolean cancelOnMove() { - if (this.eb == null || this.cancelOnMove) - return true; - return this.eb.cancelOnMove(); - } - - public boolean cancelOnNewCharm() { - if (this.eb == null) - return true; - return this.eb.cancelOnNewCharm(); - } - - public boolean cancelOnSit() { - if (this.eb == null) - return true; - return this.eb.cancelOnSit(); - } - - public boolean cancelOnStun() { - if (this.eb == null) - return true; - return this.cancelOnStun; - } - - public boolean cancelOnTakeDamage() { - if (this.eb == null) - return true; - if (this.eb.damageTypeSpecific()) { - return false; //handled in call from resists - } else { - return this.eb.cancelOnTakeDamage(); - } - } - - //Used for verifying when damage absorbers fails - public boolean cancelOnTakeDamage(DamageType type, float amount) { - if (!this.eb.cancelOnTakeDamage()) - return false; - if (this.eb == null || amount < 0f) - return false; - if (this.eb.damageTypeSpecific()) { - if (type == null) - return false; - if (this.eb.containsDamageType(type)) { - this.damageAmount += amount; + } + + public float getDuration() { + float duration = 0f; + if (this.jc != null) + duration = this.jc.timeToExecutionLeft() / 1000; + return duration; + } + + public boolean containsSource(EffectSourceType source) { + if (this.eb != null) + return this.eb.containsSource(source); + return false; + } + + public JobContainer getJobContainer() { + return this.jc; + } + + public int getTrains() { + return this.trains; + } + + public void setTrains(int value) { + this.trains = value; + } + + public float getDamageAmount() { + return this.damageAmount; + } + + public AbstractJob getJob() { + if (this.jc == null) + return null; + return jc.getJob(); + } + + public boolean bakedInStat() { + return this.bakedInStat; + } + + public void setBakedInStat(boolean value) { + this.bakedInStat = value; + } + + public PowersBase getPower() { + if (this.jc == null) + return null; + AbstractJob aj = jc.getJob(); + if (aj == null || (!(aj instanceof AbstractEffectJob))) + return null; + return ((AbstractEffectJob) aj).getPower(); + } + + public int getPowerToken() { + if (this.jc == null) + return 0; + AbstractJob aj = jc.getJob(); + if (aj == null || (!(aj instanceof AbstractEffectJob))) + return 0; + PowersBase pb = ((AbstractEffectJob) aj).getPower(); + if (pb == null) + return 0; + return pb.getToken(); + } + + public int getEffectToken() { + if (this.eb != null) + return this.eb.getToken(); + return 0; + } + + public EffectsBase getEffectsBase() { + return this.eb; + } + + public String getName() { + if (this.jc == null) + return ""; + AbstractJob aj = this.jc.getJob(); + if (aj == null || !(aj instanceof AbstractEffectJob)) + return ""; + AbstractEffectJob aej = (AbstractEffectJob) aj; + PowersBase pb = aej.getPower(); + if (pb == null) + return ""; + return pb.getName(); + } + + public boolean cancel() { + return this.cancel.compareAndSet(false, true); + } + + public boolean canceled() { + return this.cancel.get(); + } + + public boolean cancelOnAttack() { + if (this.eb == null) + return true; + return this.eb.cancelOnAttack(); + } + + public boolean cancelOnAttackSwing() { + if (this.eb == null) + return true; + return this.eb.cancelOnAttackSwing(); + } + + public boolean cancelOnCast() { + if (this.eb == null) + return true; + return this.eb.cancelOnCast(); + } + + public boolean cancelOnCastSpell() { + if (this.eb == null) + return true; + return this.eb.cancelOnCastSpell(); + } + + public boolean cancelOnEquipChange() { + if (this.eb == null) + return true; + return this.eb.cancelOnEquipChange(); + } + + public boolean cancelOnLogout() { + if (this.eb == null) + return true; + return this.eb.cancelOnLogout(); + } + + public boolean cancelOnMove() { + if (this.eb == null || this.cancelOnMove) + return true; + return this.eb.cancelOnMove(); + } + + public boolean cancelOnNewCharm() { + if (this.eb == null) + return true; + return this.eb.cancelOnNewCharm(); + } + + public boolean cancelOnSit() { + if (this.eb == null) + return true; + return this.eb.cancelOnSit(); + } + + public boolean cancelOnStun() { + if (this.eb == null) + return true; + return this.cancelOnStun; + } + + public boolean cancelOnTakeDamage() { + if (this.eb == null) + return true; + if (this.eb.damageTypeSpecific()) { + return false; //handled in call from resists + } else { + return this.eb.cancelOnTakeDamage(); + } + } + + //Used for verifying when damage absorbers fails + public boolean cancelOnTakeDamage(DamageType type, float amount) { + if (!this.eb.cancelOnTakeDamage()) + return false; + if (this.eb == null || amount < 0f) + return false; + if (this.eb.damageTypeSpecific()) { + if (type == null) + return false; + if (this.eb.containsDamageType(type)) { + this.damageAmount += amount; return this.damageAmount > this.eb.getDamageAmount(this.trains); - } else - return false; - } else - return false; //handled by call from AbstractCharacter - } - - public boolean isDamageAbsorber() { - if (this.eb == null) - return false; - if (!this.eb.cancelOnTakeDamage()) - return false; + } else + return false; + } else + return false; //handled by call from AbstractCharacter + } + + public boolean isDamageAbsorber() { + if (this.eb == null) + return false; + if (!this.eb.cancelOnTakeDamage()) + return false; return this.eb.damageTypeSpecific(); } - public boolean cancelOnTerritoryClaim() { - if (this.eb == null) - return true; - return this.eb.cancelOnTerritoryClaim(); - } - - public boolean cancelOnUnEquip() { - if (this.eb == null) - return true; - return this.eb.cancelOnUnEquip(); - } - - public void setPAOE() { - this.cancelOnStun = true; - this.cancelOnMove = true; - } - - public boolean isStatic() { - return isStatic; - } - - public void setIsStatic(boolean isStatic) { - this.isStatic = isStatic; - - } - - public int getEffectSourceID() { - return effectSourceID; - } - - public void setEffectSourceID(int effectSourceID) { - this.effectSourceID = effectSourceID; - } - - public int getEffectSourceType() { - return effectSourceType; - } - - public void setEffectSourceType(int effectSourceType) { - this.effectSourceType = effectSourceType; - } + public boolean cancelOnTerritoryClaim() { + if (this.eb == null) + return true; + return this.eb.cancelOnTerritoryClaim(); + } + + public boolean cancelOnUnEquip() { + if (this.eb == null) + return true; + return this.eb.cancelOnUnEquip(); + } + + public void setPAOE() { + this.cancelOnStun = true; + this.cancelOnMove = true; + } + + public boolean isStatic() { + return isStatic; + } + + public void setIsStatic(boolean isStatic) { + this.isStatic = isStatic; + + } + + public int getEffectSourceID() { + return effectSourceID; + } + + public void setEffectSourceID(int effectSourceID) { + this.effectSourceID = effectSourceID; + } + + public int getEffectSourceType() { + return effectSourceType; + } + + public void setEffectSourceType(int effectSourceType) { + this.effectSourceType = effectSourceType; + } } \ No newline at end of file diff --git a/src/engine/objects/EffectsResourceCosts.java b/src/engine/objects/EffectsResourceCosts.java index c5cf7e51..17547d1d 100644 --- a/src/engine/objects/EffectsResourceCosts.java +++ b/src/engine/objects/EffectsResourceCosts.java @@ -15,62 +15,59 @@ import java.sql.SQLException; public class EffectsResourceCosts extends AbstractGameObject { - private String IDString; - private int resourceID; - private int amount; - private int UID; + private String IDString; + private int resourceID; + private int amount; + private int UID; - /** - * No Table ID Constructor - */ - public EffectsResourceCosts() { + /** + * No Table ID Constructor + */ + public EffectsResourceCosts() { - } + } - /** - * ResultSet Constructor - */ - public EffectsResourceCosts(ResultSet rs) throws SQLException { + /** + * ResultSet Constructor + */ + public EffectsResourceCosts(ResultSet rs) throws SQLException { - this.UID = rs.getInt("UID"); - this.IDString = rs.getString("IDString"); - this.resourceID = rs.getInt("resource"); - this.amount = rs.getInt("amount"); - } + this.UID = rs.getInt("UID"); + this.IDString = rs.getString("IDString"); + this.resourceID = rs.getInt("resource"); + this.amount = rs.getInt("amount"); + } - - public String getIDString() { - return this.IDString; - } + public String getIDString() { + return this.IDString; + } - - public int getAmount() { - return this.amount; - } + public int getAmount() { + return this.amount; + } - - public int getResourceID() { - return resourceID; - } + public int getResourceID() { + return resourceID; + } - @Override - public void removeFromCache() { - // TODO Auto-generated method stub - - } + @Override + public void removeFromCache() { + // TODO Auto-generated method stub - @Override - public void updateDatabase() { - // TODO Auto-generated method stub - - } + } + + @Override + public void updateDatabase() { + // TODO Auto-generated method stub + + } + + public int getUID() { + return UID; + } - public int getUID() { - return UID; - } - } diff --git a/src/engine/objects/EnchantmentBase.java b/src/engine/objects/EnchantmentBase.java index 9ae2e406..73f5d801 100644 --- a/src/engine/objects/EnchantmentBase.java +++ b/src/engine/objects/EnchantmentBase.java @@ -7,7 +7,7 @@ // www.magicbane.com - package engine.objects; +package engine.objects; import java.sql.ResultSet; import java.sql.SQLException; @@ -15,78 +15,78 @@ import java.sql.SQLException; public class EnchantmentBase extends AbstractGameObject { - private final String name; - private final String prefix; - private final String suffix; - - private final byte attributeID; - private final int modValue; - - /** - * No Table ID Constructor - */ - public EnchantmentBase(String name, String prefix, String suffix, - byte attributeID, int modValue) { - super(); - this.name = name; - this.prefix = prefix; - this.suffix = suffix; - this.attributeID = attributeID; - this.modValue = modValue; - } - - /** - * Normal Constructor - */ - public EnchantmentBase(String name, String prefix, String suffix, - byte attributeID, int modValue, int newUUID) { - super(newUUID); - this.name = name; - this.prefix = prefix; - this.suffix = suffix; - this.attributeID = attributeID; - this.modValue = modValue; - } - - /** - * ResultSet Constructor - */ - public EnchantmentBase(ResultSet rs) throws SQLException { - super(rs); - - this.name = rs.getString("name"); - this.prefix = rs.getString("prefix"); - this.suffix = rs.getString("suffix"); - this.attributeID = rs.getByte("attributeID"); - this.modValue = rs.getInt("modValue"); - - } - - /* - * Getters - */ - public String getName() { - return name; - } - - public String getPrefix() { - return prefix; - } - - public String getSuffix() { - return suffix; - } - - public byte getAttributeID() { - return attributeID; - } - - public int getModValue() { - return modValue; - } - - @Override - public void updateDatabase() { - // TODO Create update logic. - } + private final String name; + private final String prefix; + private final String suffix; + + private final byte attributeID; + private final int modValue; + + /** + * No Table ID Constructor + */ + public EnchantmentBase(String name, String prefix, String suffix, + byte attributeID, int modValue) { + super(); + this.name = name; + this.prefix = prefix; + this.suffix = suffix; + this.attributeID = attributeID; + this.modValue = modValue; + } + + /** + * Normal Constructor + */ + public EnchantmentBase(String name, String prefix, String suffix, + byte attributeID, int modValue, int newUUID) { + super(newUUID); + this.name = name; + this.prefix = prefix; + this.suffix = suffix; + this.attributeID = attributeID; + this.modValue = modValue; + } + + /** + * ResultSet Constructor + */ + public EnchantmentBase(ResultSet rs) throws SQLException { + super(rs); + + this.name = rs.getString("name"); + this.prefix = rs.getString("prefix"); + this.suffix = rs.getString("suffix"); + this.attributeID = rs.getByte("attributeID"); + this.modValue = rs.getInt("modValue"); + + } + + /* + * Getters + */ + public String getName() { + return name; + } + + public String getPrefix() { + return prefix; + } + + public String getSuffix() { + return suffix; + } + + public byte getAttributeID() { + return attributeID; + } + + public int getModValue() { + return modValue; + } + + @Override + public void updateDatabase() { + // TODO Create update logic. + } } diff --git a/src/engine/objects/Experience.java b/src/engine/objects/Experience.java index b153679b..ad365a3d 100644 --- a/src/engine/objects/Experience.java +++ b/src/engine/objects/Experience.java @@ -18,420 +18,418 @@ import engine.server.MBServerStatics; import java.util.ArrayList; import java.util.TreeMap; -public class Experience { - - private static final TreeMap ExpToLevel; - private static final int[] LevelToExp = { Integer.MIN_VALUE, // Pad - // everything - // over 1 - - // R0 - 0, // Level 1 - 150, // Level 2 - 1200, // Level 3 - 4050, // Level 4 - 9600, // Level 5 - 18750, // Level 6 - 32400, // Level 7 - 51450, // Level 8 - 76800, // Level 9 - - // R1 - 109350, // Level 10 - 150000, // Level 11 - 199650, // Level 12 - 259200, // Level 13 - 329550, // Level 14 - 411600, // Level 15 - 506250, // Level 16 - 614400, // Level 17 - 736950, // Level 18 - 874800, // Level 19 - - // R2 - 1028850, // Level 20 - 1200000, // Level 21 - 1389150, // Level 22 - 1597200, // Level 23 - 1825050, // Level 24 - 2073600, // Level 25 - 2343750, // Level 26 - 2636400, // Level 27 - 2952450, // Level 28 - 3292800, // Level 29 - - // R3 - 3658350, // Level 30 - 4050000, // Level 31 - 4468650, // Level 32 - 4915200, // Level 33 - 5390550, // Level 34 - 5895600, // Level 35 - 6431250, // Level 36 - 6998400, // Level 37 - 7597950, // Level 38 - 8230800, // Level 39 - - // R4 - 8897850, // Level 40 - 10091520, // Level 41 - 11396777, // Level 42 - 12820187, // Level 43 - 14368505, // Level 44 - 16048666, // Level 45 - 17867790, // Level 46 - 19833183, // Level 47 - 21952335, // Level 48 - 24232919, // Level 49 - - // R5 - 26682793, // Level 50 - 29310000, // Level 51 - 32122766, // Level 52 - 35129502, // Level 53 - 38338805, // Level 54 - 41759452, // Level 55 - 45400409, // Level 56 - 49270824, // Level 57 - 53380030, // Level 58 - 57737542, // Level 59 - - // R6 - 62353064, // Level 60 - 67236479, // Level 61 - 72397859, // Level 62 - 77847457, // Level 63 - 83595712, // Level 64 - 89653247, // Level 65 - 96030869, // Level 66 - 102739569, // Level 67 - 109790524, // Level 68 - 117195093, // Level 69 - - // R7 - 124964822, // Level 70 - 133111438, // Level 71 - 141646855, // Level 72 - 150583171, // Level 73 - 159932666, // Level 74 - 169707808, // Level 75 - 179921247, // Level 76 - - }; - - private static final float[] MaxExpPerLevel = { Float.MIN_VALUE, // Pad - // everything - // over - // 1 - - // R0 - 15, // Level 1 - 105, // Level 2 - 285, // Level 3 - 555, // Level 4 - 610, // Level 5 - 682.5f, // Level 6 - 730, // Level 7 - 975, // Level 8 - 1251.92f, // Level 9 - - // R1 - 1563.46f, // Level 10 - 1909.62f, // Level 11 - 2290.38f, // Level 12 - 2705.77f, // Level 13 - 3155.77f, // Level 14 - 3640.38f, // Level 15 - 4159.62f, // Level 16 - 4713.46f, // Level 17 - 5301.92f, // Level 18 - 5925, // Level 19 - - // R2 - 6582.69f, // Level 20 - 7275, // Level 21 - 8001.92f, // Level 22 - 8763.46f, // Level 23 - 9559.62f, // Level 24 - 10390.38f, // Level 25 - 11255.77f, // Level 26 - 12155.77f, // Level 27 - 13090.38f, // Level 28 - 14059.62f, // Level 29 - - // R3 - 15063.46f, // Level 30 - 16101.92f, // Level 31 - 17175, // Level 32 - 18282.69f, // Level 33 - 19425, // Level 34 - 20601.92f, // Level 35 - 21813.46f, // Level 36 - 23059.62f, // Level 37 - 24340.38f, // Level 38 - 25655.77f, // Level 39 - - // R4 - 45910.38f, // Level 40 - 34348.87f, // Level 41 - 37458.16f, // Level 42 - 40745.21f, // Level 43 - 44214.76f, // Level 44 - 47871.68f, // Level 45 - 51720.87f, // Level 46 - 55767.16f, // Level 47 - 60015.37f, // Level 48 - 64470.37f, // Level 49 - - // R5 - 69137.03f, // Level 50 - 74020.16f, // Level 51 - 79124.63f, // Level 52 - 84455.34f, // Level 53 - 90017.03f, // Level 54 - 95814.66f, // Level 55 - 101853.03f, // Level 56 - 108137, // Level 57 - 114671.37f, // Level 58 - 121461.11f, // Level 59 - - // R6 - 128510.92f, // Level 60 - 135825.79f, // Level 61 - 143410.47f, // Level 62 - 151269.87f, // Level 63 - 159408.82f, // Level 64 - 167832.16f, // Level 65 - 176544.74f, // Level 66 - 185551.45f, // Level 67 - 194857.08f, // Level 68 - 204466.55f, // Level 69 - - // R7 - 214384.63f, // Level 70 - 224616.24f, // Level 71 - 235166.21f, // Level 72 - 246039.34f, // Level 73 - 257240.58f, // Level 74 - 1 // 268774.71 //Level 75 - - }; - - static { - ExpToLevel = new TreeMap<>(); - - // flip keys and values for other Map - for (int i = 1; i < LevelToExp.length; i++) { - ExpToLevel.put(LevelToExp[i], i); - } - } // end Static block - - // Used to calcuate the amount of experience a monster grants in the - // following formula - // expGranted = a(moblevel)^2 + b(moblevel) + c - private static final float EXPQUADA = 10.0f; - private static final float EXPQUADB = 6.0f; - private static final float EXPQUADC = -10.0f; - - // Adds addtional exp per addtional member of a group using the following - // (expGranted / group.size()) * (groupBonus * (group.size()-1) +1) - private static final float GROUP_BONUS = 0.5f; // 0.2 grants (20%) addtional - // exp per group member - - // called to determine current level based on xp - public static int getLevel(int experience) { - int expKey = ExpToLevel.floorKey(experience); - int level = ExpToLevel.get(expKey); - if (level > MBServerStatics.LEVELCAP) { - level = MBServerStatics.LEVELCAP; - } - return level; - } - - // Get the base xp for a level - public static int getBaseExperience(int level) { - if (level < LevelToExp.length) { - return LevelToExp[level]; - } - - int fLevel = level - 1; - int baseXP = fLevel * fLevel * fLevel; - return (int) ((fLevel < 40) ? (baseXP * 150) - : (baseXP * (150 + (7.6799998 * (level - 40))))); - } - - // Get XP needed for the next level - public static int getExpForNextLevel(int experience, int currentLevel) { - return (getBaseExperience(currentLevel + 1) - experience); - } - - // Max XP granted for killing a blue, yellow or orange mob - public static float maxXPPerKill(int level) { - if (level < 1) - level = 1; - if (level > 75) - level = 75; - return MaxExpPerLevel[level]; - // return (LevelToExp[level + 1] - LevelToExp[level])/(11 + level/2); - // return ((((level * level)-level)*50)+16); - } - - // Returns a penalty modifier depending on mob color - public static double getConMod(AbstractCharacter pc, AbstractCharacter mob) { - switch (TargetColor.getCon(pc, mob)) { - case Red: - return 1.25; - case Orange: - return 1.15; - case Yellow: - return 1.05; - case Blue: - return 1; - case Cyan: - return 0.8; - case Green: - return 0.5; - default: - return 0; - } - } - - public static double getGroupMemberPenalty(double leadership, - PlayerCharacter currPlayer, ArrayList players, - int highestLevel) { - - double penalty = 0.0; - int adjustedGroupSize = 0; - int totalLevels = 0; - int level = currPlayer.getLevel(); - - // Group Size Penalty - if (players.size() > 2) - penalty = (players.size() - 2) * 1.5; - - // Calculate Penalty For Highest level -> Current Player difference, != - // check to prevent divide by zero error - if (highestLevel != level) - penalty += ((highestLevel - level) * .5); - - // double avgLevels = totalLevels / adjustedGroupSize; - // if (adjustedGroupSize >= 1) - // if (level < avgLevels) - // penalty += ((avgLevels - level) * .5); - - // Extra noob penalty - if ((highestLevel - level) > 25) - penalty += (highestLevel - level - 25); - - return penalty; - } - - public static void doExperience(PlayerCharacter killer, AbstractCharacter mob, Group g) { - // Check for some failure conditions - if (killer == null || mob == null) - return; - - double grantedExperience = 0.0; - - if (g != null) { // Do group EXP stuff - - int leadership = 0; - int highestLevel = 0; - double penalty = 0.0; - - ArrayList giveEXPTo = new ArrayList<>(); - - // Check if leader is within range of kill and then get leadership - // skill - Vector3fImmutable killLoc = mob.getLoc(); - if (killLoc.distanceSquared2D(g.getGroupLead().getLoc()) < (MBServerStatics.EXP_RANGE * MBServerStatics.EXP_RANGE)) { - CharacterSkill leaderskill = g.getGroupLead().skills - .get("Leadership"); - if (leaderskill != null) - leadership = leaderskill.getNumTrains(); - if (leadership > 90) - leadership = 90; // leadership caps at 90% - } - - // Check every group member for distance to see if they get xp - for (PlayerCharacter pc : g.getMembers()) { - if (pc.isAlive()) { // Skip if the player is dead. - - // Check within range - if (killLoc.distanceSquared2D(pc.getLoc()) < (MBServerStatics.EXP_RANGE * MBServerStatics.EXP_RANGE)) { - giveEXPTo.add(pc); - // Track highest level character - if (pc.getLevel() > highestLevel) - highestLevel = pc.getLevel(); - } - } - } - - // Process every player in the group getting XP - for (PlayerCharacter playerCharacter : giveEXPTo) { - if (playerCharacter.getLevel() >= MBServerStatics.LEVELCAP) - continue; - - // Sets Max XP with server exp mod taken into account. - grantedExperience = (double) Float.parseFloat(ConfigManager.MB_NORMAL_EXP_RATE.getValue()) * maxXPPerKill(playerCharacter.getLevel()); - - // Adjust XP for Mob Level - grantedExperience *= getConMod(playerCharacter, mob); - - // Process XP for this member - penalty = getGroupMemberPenalty(leadership, playerCharacter, giveEXPTo, - highestLevel); - - // Leadership Penalty Reduction - if (leadership > 0) - penalty -= ((leadership) * 0.01) * penalty; - - // Modify for hotzone - if (grantedExperience != 0) - if (ZoneManager.inHotZone(mob.getLoc())) - grantedExperience *= Float.parseFloat(ConfigManager.MB_HOTZONE_EXP_RATE.getValue()); - - // Check for 0 XP due to white mob, otherwise subtract penalty - // xp - if (grantedExperience == 0) { - grantedExperience = 1; - } else { - grantedExperience -= (penalty * 0.01) * grantedExperience; - - // Errant Penalty Calculation - if (playerCharacter.getGuild().isEmptyGuild()) - grantedExperience *= 0.6; - } - - if (grantedExperience == 0) - grantedExperience = 1; - - // Grant the player the EXP - playerCharacter.grantXP((int) Math.floor(grantedExperience)); - } - - } else { // Give EXP to a single character - if (!killer.isAlive()) // Skip if the player is dead. - return; - - if (killer.getLevel() >= MBServerStatics.LEVELCAP) - return; - - // Get XP and adjust for Mob Level with world xp modifier taken into account - grantedExperience = (double) Float.parseFloat(ConfigManager.MB_NORMAL_EXP_RATE.getValue()) * maxXPPerKill(killer.getLevel()); - grantedExperience *= getConMod(killer, mob); - - // Modify for hotzone - if (ZoneManager.inHotZone(mob.getLoc())) - grantedExperience *= Float.parseFloat(ConfigManager.MB_HOTZONE_EXP_RATE.getValue()); - - // Errant penalty - if (grantedExperience != 1) - if (killer.getGuild().isEmptyGuild()) - grantedExperience *= .6; - - // Grant XP - killer.grantXP((int) Math.floor(grantedExperience)); - } - } +public class Experience { + + private static final TreeMap ExpToLevel; + private static final int[] LevelToExp = {Integer.MIN_VALUE, // Pad + // everything + // over 1 + + // R0 + 0, // Level 1 + 150, // Level 2 + 1200, // Level 3 + 4050, // Level 4 + 9600, // Level 5 + 18750, // Level 6 + 32400, // Level 7 + 51450, // Level 8 + 76800, // Level 9 + + // R1 + 109350, // Level 10 + 150000, // Level 11 + 199650, // Level 12 + 259200, // Level 13 + 329550, // Level 14 + 411600, // Level 15 + 506250, // Level 16 + 614400, // Level 17 + 736950, // Level 18 + 874800, // Level 19 + + // R2 + 1028850, // Level 20 + 1200000, // Level 21 + 1389150, // Level 22 + 1597200, // Level 23 + 1825050, // Level 24 + 2073600, // Level 25 + 2343750, // Level 26 + 2636400, // Level 27 + 2952450, // Level 28 + 3292800, // Level 29 + + // R3 + 3658350, // Level 30 + 4050000, // Level 31 + 4468650, // Level 32 + 4915200, // Level 33 + 5390550, // Level 34 + 5895600, // Level 35 + 6431250, // Level 36 + 6998400, // Level 37 + 7597950, // Level 38 + 8230800, // Level 39 + + // R4 + 8897850, // Level 40 + 10091520, // Level 41 + 11396777, // Level 42 + 12820187, // Level 43 + 14368505, // Level 44 + 16048666, // Level 45 + 17867790, // Level 46 + 19833183, // Level 47 + 21952335, // Level 48 + 24232919, // Level 49 + + // R5 + 26682793, // Level 50 + 29310000, // Level 51 + 32122766, // Level 52 + 35129502, // Level 53 + 38338805, // Level 54 + 41759452, // Level 55 + 45400409, // Level 56 + 49270824, // Level 57 + 53380030, // Level 58 + 57737542, // Level 59 + + // R6 + 62353064, // Level 60 + 67236479, // Level 61 + 72397859, // Level 62 + 77847457, // Level 63 + 83595712, // Level 64 + 89653247, // Level 65 + 96030869, // Level 66 + 102739569, // Level 67 + 109790524, // Level 68 + 117195093, // Level 69 + + // R7 + 124964822, // Level 70 + 133111438, // Level 71 + 141646855, // Level 72 + 150583171, // Level 73 + 159932666, // Level 74 + 169707808, // Level 75 + 179921247, // Level 76 + + }; + + private static final float[] MaxExpPerLevel = {Float.MIN_VALUE, // Pad + // everything + // over + // 1 + + // R0 + 15, // Level 1 + 105, // Level 2 + 285, // Level 3 + 555, // Level 4 + 610, // Level 5 + 682.5f, // Level 6 + 730, // Level 7 + 975, // Level 8 + 1251.92f, // Level 9 + + // R1 + 1563.46f, // Level 10 + 1909.62f, // Level 11 + 2290.38f, // Level 12 + 2705.77f, // Level 13 + 3155.77f, // Level 14 + 3640.38f, // Level 15 + 4159.62f, // Level 16 + 4713.46f, // Level 17 + 5301.92f, // Level 18 + 5925, // Level 19 + + // R2 + 6582.69f, // Level 20 + 7275, // Level 21 + 8001.92f, // Level 22 + 8763.46f, // Level 23 + 9559.62f, // Level 24 + 10390.38f, // Level 25 + 11255.77f, // Level 26 + 12155.77f, // Level 27 + 13090.38f, // Level 28 + 14059.62f, // Level 29 + + // R3 + 15063.46f, // Level 30 + 16101.92f, // Level 31 + 17175, // Level 32 + 18282.69f, // Level 33 + 19425, // Level 34 + 20601.92f, // Level 35 + 21813.46f, // Level 36 + 23059.62f, // Level 37 + 24340.38f, // Level 38 + 25655.77f, // Level 39 + + // R4 + 45910.38f, // Level 40 + 34348.87f, // Level 41 + 37458.16f, // Level 42 + 40745.21f, // Level 43 + 44214.76f, // Level 44 + 47871.68f, // Level 45 + 51720.87f, // Level 46 + 55767.16f, // Level 47 + 60015.37f, // Level 48 + 64470.37f, // Level 49 + + // R5 + 69137.03f, // Level 50 + 74020.16f, // Level 51 + 79124.63f, // Level 52 + 84455.34f, // Level 53 + 90017.03f, // Level 54 + 95814.66f, // Level 55 + 101853.03f, // Level 56 + 108137, // Level 57 + 114671.37f, // Level 58 + 121461.11f, // Level 59 + + // R6 + 128510.92f, // Level 60 + 135825.79f, // Level 61 + 143410.47f, // Level 62 + 151269.87f, // Level 63 + 159408.82f, // Level 64 + 167832.16f, // Level 65 + 176544.74f, // Level 66 + 185551.45f, // Level 67 + 194857.08f, // Level 68 + 204466.55f, // Level 69 + + // R7 + 214384.63f, // Level 70 + 224616.24f, // Level 71 + 235166.21f, // Level 72 + 246039.34f, // Level 73 + 257240.58f, // Level 74 + 1 // 268774.71 //Level 75 + + }; + // Used to calcuate the amount of experience a monster grants in the + // following formula + // expGranted = a(moblevel)^2 + b(moblevel) + c + private static final float EXPQUADA = 10.0f; + private static final float EXPQUADB = 6.0f; + private static final float EXPQUADC = -10.0f; + // Adds addtional exp per addtional member of a group using the following + // (expGranted / group.size()) * (groupBonus * (group.size()-1) +1) + private static final float GROUP_BONUS = 0.5f; // 0.2 grants (20%) addtional + + static { + ExpToLevel = new TreeMap<>(); + + // flip keys and values for other Map + for (int i = 1; i < LevelToExp.length; i++) { + ExpToLevel.put(LevelToExp[i], i); + } + } // end Static block + // exp per group member + + // called to determine current level based on xp + public static int getLevel(int experience) { + int expKey = ExpToLevel.floorKey(experience); + int level = ExpToLevel.get(expKey); + if (level > MBServerStatics.LEVELCAP) { + level = MBServerStatics.LEVELCAP; + } + return level; + } + + // Get the base xp for a level + public static int getBaseExperience(int level) { + if (level < LevelToExp.length) { + return LevelToExp[level]; + } + + int fLevel = level - 1; + int baseXP = fLevel * fLevel * fLevel; + return (int) ((fLevel < 40) ? (baseXP * 150) + : (baseXP * (150 + (7.6799998 * (level - 40))))); + } + + // Get XP needed for the next level + public static int getExpForNextLevel(int experience, int currentLevel) { + return (getBaseExperience(currentLevel + 1) - experience); + } + + // Max XP granted for killing a blue, yellow or orange mob + public static float maxXPPerKill(int level) { + if (level < 1) + level = 1; + if (level > 75) + level = 75; + return MaxExpPerLevel[level]; + // return (LevelToExp[level + 1] - LevelToExp[level])/(11 + level/2); + // return ((((level * level)-level)*50)+16); + } + + // Returns a penalty modifier depending on mob color + public static double getConMod(AbstractCharacter pc, AbstractCharacter mob) { + switch (TargetColor.getCon(pc, mob)) { + case Red: + return 1.25; + case Orange: + return 1.15; + case Yellow: + return 1.05; + case Blue: + return 1; + case Cyan: + return 0.8; + case Green: + return 0.5; + default: + return 0; + } + } + + public static double getGroupMemberPenalty(double leadership, + PlayerCharacter currPlayer, ArrayList players, + int highestLevel) { + + double penalty = 0.0; + int adjustedGroupSize = 0; + int totalLevels = 0; + int level = currPlayer.getLevel(); + + // Group Size Penalty + if (players.size() > 2) + penalty = (players.size() - 2) * 1.5; + + // Calculate Penalty For Highest level -> Current Player difference, != + // check to prevent divide by zero error + if (highestLevel != level) + penalty += ((highestLevel - level) * .5); + + // double avgLevels = totalLevels / adjustedGroupSize; + // if (adjustedGroupSize >= 1) + // if (level < avgLevels) + // penalty += ((avgLevels - level) * .5); + + // Extra noob penalty + if ((highestLevel - level) > 25) + penalty += (highestLevel - level - 25); + + return penalty; + } + + public static void doExperience(PlayerCharacter killer, AbstractCharacter mob, Group g) { + // Check for some failure conditions + if (killer == null || mob == null) + return; + + double grantedExperience = 0.0; + + if (g != null) { // Do group EXP stuff + + int leadership = 0; + int highestLevel = 0; + double penalty = 0.0; + + ArrayList giveEXPTo = new ArrayList<>(); + + // Check if leader is within range of kill and then get leadership + // skill + Vector3fImmutable killLoc = mob.getLoc(); + if (killLoc.distanceSquared2D(g.getGroupLead().getLoc()) < (MBServerStatics.EXP_RANGE * MBServerStatics.EXP_RANGE)) { + CharacterSkill leaderskill = g.getGroupLead().skills + .get("Leadership"); + if (leaderskill != null) + leadership = leaderskill.getNumTrains(); + if (leadership > 90) + leadership = 90; // leadership caps at 90% + } + + // Check every group member for distance to see if they get xp + for (PlayerCharacter pc : g.getMembers()) { + if (pc.isAlive()) { // Skip if the player is dead. + + // Check within range + if (killLoc.distanceSquared2D(pc.getLoc()) < (MBServerStatics.EXP_RANGE * MBServerStatics.EXP_RANGE)) { + giveEXPTo.add(pc); + // Track highest level character + if (pc.getLevel() > highestLevel) + highestLevel = pc.getLevel(); + } + } + } + + // Process every player in the group getting XP + for (PlayerCharacter playerCharacter : giveEXPTo) { + if (playerCharacter.getLevel() >= MBServerStatics.LEVELCAP) + continue; + + // Sets Max XP with server exp mod taken into account. + grantedExperience = (double) Float.parseFloat(ConfigManager.MB_NORMAL_EXP_RATE.getValue()) * maxXPPerKill(playerCharacter.getLevel()); + + // Adjust XP for Mob Level + grantedExperience *= getConMod(playerCharacter, mob); + + // Process XP for this member + penalty = getGroupMemberPenalty(leadership, playerCharacter, giveEXPTo, + highestLevel); + + // Leadership Penalty Reduction + if (leadership > 0) + penalty -= ((leadership) * 0.01) * penalty; + + // Modify for hotzone + if (grantedExperience != 0) + if (ZoneManager.inHotZone(mob.getLoc())) + grantedExperience *= Float.parseFloat(ConfigManager.MB_HOTZONE_EXP_RATE.getValue()); + + // Check for 0 XP due to white mob, otherwise subtract penalty + // xp + if (grantedExperience == 0) { + grantedExperience = 1; + } else { + grantedExperience -= (penalty * 0.01) * grantedExperience; + + // Errant Penalty Calculation + if (playerCharacter.getGuild().isEmptyGuild()) + grantedExperience *= 0.6; + } + + if (grantedExperience == 0) + grantedExperience = 1; + + // Grant the player the EXP + playerCharacter.grantXP((int) Math.floor(grantedExperience)); + } + + } else { // Give EXP to a single character + if (!killer.isAlive()) // Skip if the player is dead. + return; + + if (killer.getLevel() >= MBServerStatics.LEVELCAP) + return; + + // Get XP and adjust for Mob Level with world xp modifier taken into account + grantedExperience = (double) Float.parseFloat(ConfigManager.MB_NORMAL_EXP_RATE.getValue()) * maxXPPerKill(killer.getLevel()); + grantedExperience *= getConMod(killer, mob); + + // Modify for hotzone + if (ZoneManager.inHotZone(mob.getLoc())) + grantedExperience *= Float.parseFloat(ConfigManager.MB_HOTZONE_EXP_RATE.getValue()); + + // Errant penalty + if (grantedExperience != 1) + if (killer.getGuild().isEmptyGuild()) + grantedExperience *= .6; + + // Grant XP + killer.grantXP((int) Math.floor(grantedExperience)); + } + } } diff --git a/src/engine/objects/Formation.java b/src/engine/objects/Formation.java index 28d147a1..e8875764 100644 --- a/src/engine/objects/Formation.java +++ b/src/engine/objects/Formation.java @@ -13,106 +13,106 @@ import engine.math.Vector3f; public class Formation { - // Offsets are as follows. - // X determines left/right offset - // Y not used - // Z determines front/back offset - - private static final Vector3f[] COLUMN = { new Vector3f(0, 0, 0), // Group - // Lead - new Vector3f(6, 0, 0), // Player 1 offset - new Vector3f(0, 0, -6), // Player 2 offset - new Vector3f(6, 0, -6), // Player 3 offset - new Vector3f(0, 0, -12), // Player 4 offset - new Vector3f(6, 0, -12), // Player 5 offset - new Vector3f(0, 0, -18), // Player 6 offset - new Vector3f(6, 0, -18), // Player 7 offset - new Vector3f(0, 0, -24), // Player 8 offset - new Vector3f(6, 0, -24) }; // Player 9 offset - - private static final Vector3f[] LINE = { new Vector3f(0, 0, 0), - new Vector3f(0, 0, -6), new Vector3f(0, 0, -12), - new Vector3f(0, 0, -18), new Vector3f(0, 0, -24), - new Vector3f(0, 0, -30), new Vector3f(0, 0, -36), - new Vector3f(0, 0, -42), new Vector3f(0, 0, -48), - new Vector3f(0, 0, -54) }; - - private static final Vector3f[] BOX = { new Vector3f(0, 0, 0), - new Vector3f(-6, 0, 0), new Vector3f(6, 0, 0), - new Vector3f(-6, 0, -6), new Vector3f(0, 0, -6), - new Vector3f(6, 0, -6), new Vector3f(-6, 0, -12), - new Vector3f(0, 0, -12), new Vector3f(5, 0, -12), - new Vector3f(0, 0, -18) }; - - private static final Vector3f[] TRIANGLE = { new Vector3f(0, 0, 0), - new Vector3f(-6, 0, -6), new Vector3f(6, 0, -6), - new Vector3f(-12, 0, -12), new Vector3f(0, 0, -12), - new Vector3f(12, 0, -12), new Vector3f(-18, 0, -18), - new Vector3f(-6, 0, -18), new Vector3f(6, 0, -18), - new Vector3f(18, 0, -18) }; - - private static final Vector3f[] CIRCLE = { new Vector3f(0, 0, 0), - new Vector3f(-12, 0, -3), new Vector3f(12, 0, -3), - new Vector3f(-18, 0, -12), new Vector3f(18, 0, -12), - new Vector3f(-18, 0, -21), new Vector3f(18, 0, -21), - new Vector3f(-12, 0, -30), new Vector3f(12, 0, -30), - new Vector3f(0, 0, -33) }; - - private static final Vector3f[] RANKS = { new Vector3f(0, 0, 0), - new Vector3f(0, 0, -6), new Vector3f(-6, 0, 0), - new Vector3f(-6, 0, -6), new Vector3f(6, 0, 0), - new Vector3f(6, 0, -6), new Vector3f(-12, 0, 0), - new Vector3f(-12, 0, -6), new Vector3f(12, 0, 0), - new Vector3f(12, 0, -6) }; - - private static final Vector3f[] WEDGE = { new Vector3f(0, 0, 0), - new Vector3f(6, 0, 0), new Vector3f(-6, 0, -6), - new Vector3f(12, 0, -6), new Vector3f(-12, 0, -12), - new Vector3f(18, 0, -12), new Vector3f(-18, 0, -18), - new Vector3f(24, 0, -18), new Vector3f(-24, 0, -24), - new Vector3f(30, 0, -24) }; - - private static final Vector3f[] INVERSEWEDGE = { new Vector3f(0, 0, 0), - new Vector3f(6, 0, 0), new Vector3f(-6, 0, 6), - new Vector3f(12, 0, 6), new Vector3f(-12, 0, 12), - new Vector3f(18, 0, 12), new Vector3f(-18, 0, 18), - new Vector3f(24, 0, 18), new Vector3f(-24, 0, 24), - new Vector3f(30, 0, 24) }; - - private static final Vector3f[] T = { new Vector3f(0, 0, 0), - new Vector3f(-6, 0, 0), new Vector3f(6, 0, 0), - new Vector3f(0, 0, -6), new Vector3f(-12, 0, 0), - new Vector3f(12, 0, 0), new Vector3f(0, 0, -12), - new Vector3f(-18, 0, 0), new Vector3f(18, 0, 0), - new Vector3f(0, 0, -18) }; - - public static Vector3f getOffset(int formation, int position) { - if (position > 9 || position < 0) { - // TODO log error here - position = 0; - } - - switch (formation) { - case 0: - return Formation.COLUMN[position]; - case 1: - return Formation.LINE[position]; - case 2: - return Formation.BOX[position]; - case 3: - return Formation.TRIANGLE[position]; - case 4: - return Formation.CIRCLE[position]; - case 5: - return Formation.RANKS[position]; - case 6: - return Formation.WEDGE[position]; - case 7: - return Formation.INVERSEWEDGE[position]; - case 9: - return Formation.T[position]; - default: // default to box - return Formation.BOX[position]; - } - } + // Offsets are as follows. + // X determines left/right offset + // Y not used + // Z determines front/back offset + + private static final Vector3f[] COLUMN = {new Vector3f(0, 0, 0), // Group + // Lead + new Vector3f(6, 0, 0), // Player 1 offset + new Vector3f(0, 0, -6), // Player 2 offset + new Vector3f(6, 0, -6), // Player 3 offset + new Vector3f(0, 0, -12), // Player 4 offset + new Vector3f(6, 0, -12), // Player 5 offset + new Vector3f(0, 0, -18), // Player 6 offset + new Vector3f(6, 0, -18), // Player 7 offset + new Vector3f(0, 0, -24), // Player 8 offset + new Vector3f(6, 0, -24)}; // Player 9 offset + + private static final Vector3f[] LINE = {new Vector3f(0, 0, 0), + new Vector3f(0, 0, -6), new Vector3f(0, 0, -12), + new Vector3f(0, 0, -18), new Vector3f(0, 0, -24), + new Vector3f(0, 0, -30), new Vector3f(0, 0, -36), + new Vector3f(0, 0, -42), new Vector3f(0, 0, -48), + new Vector3f(0, 0, -54)}; + + private static final Vector3f[] BOX = {new Vector3f(0, 0, 0), + new Vector3f(-6, 0, 0), new Vector3f(6, 0, 0), + new Vector3f(-6, 0, -6), new Vector3f(0, 0, -6), + new Vector3f(6, 0, -6), new Vector3f(-6, 0, -12), + new Vector3f(0, 0, -12), new Vector3f(5, 0, -12), + new Vector3f(0, 0, -18)}; + + private static final Vector3f[] TRIANGLE = {new Vector3f(0, 0, 0), + new Vector3f(-6, 0, -6), new Vector3f(6, 0, -6), + new Vector3f(-12, 0, -12), new Vector3f(0, 0, -12), + new Vector3f(12, 0, -12), new Vector3f(-18, 0, -18), + new Vector3f(-6, 0, -18), new Vector3f(6, 0, -18), + new Vector3f(18, 0, -18)}; + + private static final Vector3f[] CIRCLE = {new Vector3f(0, 0, 0), + new Vector3f(-12, 0, -3), new Vector3f(12, 0, -3), + new Vector3f(-18, 0, -12), new Vector3f(18, 0, -12), + new Vector3f(-18, 0, -21), new Vector3f(18, 0, -21), + new Vector3f(-12, 0, -30), new Vector3f(12, 0, -30), + new Vector3f(0, 0, -33)}; + + private static final Vector3f[] RANKS = {new Vector3f(0, 0, 0), + new Vector3f(0, 0, -6), new Vector3f(-6, 0, 0), + new Vector3f(-6, 0, -6), new Vector3f(6, 0, 0), + new Vector3f(6, 0, -6), new Vector3f(-12, 0, 0), + new Vector3f(-12, 0, -6), new Vector3f(12, 0, 0), + new Vector3f(12, 0, -6)}; + + private static final Vector3f[] WEDGE = {new Vector3f(0, 0, 0), + new Vector3f(6, 0, 0), new Vector3f(-6, 0, -6), + new Vector3f(12, 0, -6), new Vector3f(-12, 0, -12), + new Vector3f(18, 0, -12), new Vector3f(-18, 0, -18), + new Vector3f(24, 0, -18), new Vector3f(-24, 0, -24), + new Vector3f(30, 0, -24)}; + + private static final Vector3f[] INVERSEWEDGE = {new Vector3f(0, 0, 0), + new Vector3f(6, 0, 0), new Vector3f(-6, 0, 6), + new Vector3f(12, 0, 6), new Vector3f(-12, 0, 12), + new Vector3f(18, 0, 12), new Vector3f(-18, 0, 18), + new Vector3f(24, 0, 18), new Vector3f(-24, 0, 24), + new Vector3f(30, 0, 24)}; + + private static final Vector3f[] T = {new Vector3f(0, 0, 0), + new Vector3f(-6, 0, 0), new Vector3f(6, 0, 0), + new Vector3f(0, 0, -6), new Vector3f(-12, 0, 0), + new Vector3f(12, 0, 0), new Vector3f(0, 0, -12), + new Vector3f(-18, 0, 0), new Vector3f(18, 0, 0), + new Vector3f(0, 0, -18)}; + + public static Vector3f getOffset(int formation, int position) { + if (position > 9 || position < 0) { + // TODO log error here + position = 0; + } + + switch (formation) { + case 0: + return Formation.COLUMN[position]; + case 1: + return Formation.LINE[position]; + case 2: + return Formation.BOX[position]; + case 3: + return Formation.TRIANGLE[position]; + case 4: + return Formation.CIRCLE[position]; + case 5: + return Formation.RANKS[position]; + case 6: + return Formation.WEDGE[position]; + case 7: + return Formation.INVERSEWEDGE[position]; + case 9: + return Formation.T[position]; + default: // default to box + return Formation.BOX[position]; + } + } } diff --git a/src/engine/objects/Group.java b/src/engine/objects/Group.java index 934deb78..2dbf310a 100644 --- a/src/engine/objects/Group.java +++ b/src/engine/objects/Group.java @@ -24,159 +24,159 @@ import java.util.concurrent.ConcurrentHashMap; public class Group extends AbstractWorldObject { - private PlayerCharacter groupLead; public final Set members; + private PlayerCharacter groupLead; + private boolean splitGold = true; + private int formation = 2; + + private UpdateGroupJob updateGroupJob = null; + + /** + * No Id Constructor + */ + public Group(PlayerCharacter pc) { + super(); + this.groupLead = pc; + this.members = Collections.newSetFromMap(new ConcurrentHashMap<>()); + } - private boolean splitGold = true; - private int formation = 2; - - private UpdateGroupJob updateGroupJob = null; - - /** - * No Id Constructor - */ - public Group( PlayerCharacter pc) { - super(); - this.groupLead = pc; - this.members = Collections.newSetFromMap(new ConcurrentHashMap<>()); - } - - /** - * Normal Constructor - */ - public Group( PlayerCharacter pc, int newUUID) { - super(newUUID); - this.groupLead = pc; + /** + * Normal Constructor + */ + public Group(PlayerCharacter pc, int newUUID) { + super(newUUID); + this.groupLead = pc; this.members = Collections.newSetFromMap(new ConcurrentHashMap<>()); - } - - /* - * Getters - */ - public PlayerCharacter getGroupLead() { - return this.groupLead; - } - - public Set getMembers() { - return this.members; - } - - public boolean getSplitGold() { - return this.splitGold; - } - - public int getFormation() { - return this.formation; - } - - public String getFormationName() { - return MBServerStatics.FORMATION_NAMES[this.formation]; - } - - /* - * Setters - */ - public void setFormation(int value) { - if (value < 0 || value > 8) - value = 2; // Default Box - this.formation = value; - } - - public boolean setGroupLead(int ID) { - for (PlayerCharacter pc : this.members) { - if (pc.getObjectUUID() == ID) { - this.groupLead = pc; - return true; - } - } - return false; - } - - public void setSplitGold(boolean value) { - this.splitGold = value; - } - - /* - * Utils - */ - public boolean isGroupLead(int ID) { - return (this.groupLead.getObjectUUID() == ID); - } - - public boolean isGroupLead(PlayerCharacter pc) { - if (pc == null || this.groupLead == null) - return false; - return (this.groupLead.getObjectUUID() == pc.getObjectUUID()); - } - - public boolean toggleSplitGold() { - this.splitGold = this.splitGold == false; - return this.splitGold; - } + } - public void sendUpdate(GroupUpdateMsg msg) { + public static boolean sameGroup(PlayerCharacter a, PlayerCharacter b) { - for (PlayerCharacter pc : this.members) { - Dispatch dispatch = Dispatch.borrow(pc, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - } - } + if (a == null || b == null) + return false; + + Group aG = GroupManager.getGroup(a); + Group bG = GroupManager.getGroup(b); - public boolean addGroupMember(PlayerCharacter pc) { + if (aG == null || bG == null) + return false; - if (this.members.size() > 9) // group full - return false; + return aG.getObjectUUID() == bG.getObjectUUID(); + + } - if (this.members.contains(pc)) // Can't add player twice - return false; + /* + * Getters + */ + public PlayerCharacter getGroupLead() { + return this.groupLead; + } - this.members.add(pc); - return true; - } + public Set getMembers() { + return this.members; + } - public int removeGroupMember(PlayerCharacter pc) { + public boolean getSplitGold() { + return this.splitGold; + } - this.members.remove(pc); // remove player - return this.members.size(); - } + public void setSplitGold(boolean value) { + this.splitGold = value; + } - public void clearMembers() { - this.members.clear(); - } + public int getFormation() { + return this.formation; + } - public static boolean sameGroup(PlayerCharacter a, PlayerCharacter b) { + /* + * Setters + */ + public void setFormation(int value) { + if (value < 0 || value > 8) + value = 2; // Default Box + this.formation = value; + } - if (a == null || b == null) - return false; + public String getFormationName() { + return MBServerStatics.FORMATION_NAMES[this.formation]; + } - Group aG = GroupManager.getGroup(a); - Group bG = GroupManager.getGroup(b); + public boolean setGroupLead(int ID) { + for (PlayerCharacter pc : this.members) { + if (pc.getObjectUUID() == ID) { + this.groupLead = pc; + return true; + } + } + return false; + } - if (aG == null || bG == null) - return false; + /* + * Utils + */ + public boolean isGroupLead(int ID) { + return (this.groupLead.getObjectUUID() == ID); + } - return aG.getObjectUUID() == bG.getObjectUUID(); + public boolean isGroupLead(PlayerCharacter pc) { + if (pc == null || this.groupLead == null) + return false; + return (this.groupLead.getObjectUUID() == pc.getObjectUUID()); + } + + public boolean toggleSplitGold() { + this.splitGold = this.splitGold == false; + return this.splitGold; + } + + public void sendUpdate(GroupUpdateMsg msg) { + + for (PlayerCharacter pc : this.members) { + Dispatch dispatch = Dispatch.borrow(pc, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + } + } + + public boolean addGroupMember(PlayerCharacter pc) { + if (this.members.size() > 9) // group full + return false; + + if (this.members.contains(pc)) // Can't add player twice + return false; + + this.members.add(pc); + return true; } - public void addUpdateGroupJob() { - this.updateGroupJob = new UpdateGroupJob(this); - JobScheduler.getInstance().scheduleJob(this.updateGroupJob, MBServerStatics.UPDATE_GROUP_RATE); - } + public int removeGroupMember(PlayerCharacter pc) { + + this.members.remove(pc); // remove player + return this.members.size(); + } - public void removeUpdateGroupJob() { - this.updateGroupJob.cancelJob(); - this.updateGroupJob = null; - } + public void clearMembers() { + this.members.clear(); + } - /* - * Database - */ - @Override - public void updateDatabase() { - // TODO Create update logic. - } + public void addUpdateGroupJob() { + this.updateGroupJob = new UpdateGroupJob(this); + JobScheduler.getInstance().scheduleJob(this.updateGroupJob, MBServerStatics.UPDATE_GROUP_RATE); + } - @Override - public void runAfterLoad() {} + public void removeUpdateGroupJob() { + this.updateGroupJob.cancelJob(); + this.updateGroupJob = null; + } + + /* + * Database + */ + @Override + public void updateDatabase() { + // TODO Create update logic. + } + + @Override + public void runAfterLoad() { + } } diff --git a/src/engine/objects/Guild.java b/src/engine/objects/Guild.java index c5ed1599..300c7850 100644 --- a/src/engine/objects/Guild.java +++ b/src/engine/objects/Guild.java @@ -43,9 +43,21 @@ import java.util.concurrent.ConcurrentHashMap; public class Guild extends AbstractWorldObject { + private static Guild errantGuild; + private static Guild errantNation; private final String name; - private Guild nation; private final GuildTag guildTag; + private final int charter; + private final String leadershipType; // Have to see how this is sent to the client + private final int repledgeMin; + private final int repledgeMax; + private final int repledgeKick; + private final int teleportMin; + private final int teleportMax; + private final ConcurrentHashMap guildCondemned = new ConcurrentHashMap<>(); + public boolean wooWasModified; + public HashMap guildAlliances = new HashMap<>(); + private Guild nation; // TODO add these to database private String motto = ""; private String motd = ""; @@ -53,14 +65,7 @@ public class Guild extends AbstractWorldObject { private String nmotd = ""; private int guildLeaderUUID; private int realmsOwned; - private final int charter; private int cityUUID = 0; - private final String leadershipType; // Have to see how this is sent to the client - private final int repledgeMin; - private final int repledgeMax; - private final int repledgeKick; - private final int teleportMin; - private final int teleportMax; private int mineTime; private ArrayList banishList; private ArrayList characterKOSList; @@ -71,16 +76,9 @@ public class Guild extends AbstractWorldObject { private ArrayList subGuildList; private int nationUUID = 0; private GuildState guildState = GuildState.Errant; - private final ConcurrentHashMap guildCondemned = new ConcurrentHashMap<>(); private String hash; private boolean ownerIsNPC; - private static Guild errantGuild; - private static Guild errantNation; - - public boolean wooWasModified; - public HashMap guildAlliances = new HashMap<>(); - /** * No Id Constructor */ @@ -181,11 +179,251 @@ public class Guild extends AbstractWorldObject { this.hash = rs.getString("hash"); } - public void setNation(Guild nation) { - if (nation == null) - this.nation = Guild.getErrantGuild(); + public static AbstractCharacter GetGL(Guild guild) { + if (guild == null) + return null; + + if (guild.guildLeaderUUID == 0) + return null; + + if (guild.ownerIsNPC) + return NPC.getFromCache(guild.guildLeaderUUID); + + return PlayerCharacter.getFromCache(guild.guildLeaderUUID); + } + + public static boolean sameGuild(Guild a, Guild b) { + if (a == null || b == null) + return false; + return a.getObjectUUID() == b.getObjectUUID(); + } + + public static boolean sameGuildExcludeErrant(Guild a, Guild b) { + if (a == null || b == null) + return false; + if (a.isEmptyGuild() || b.isEmptyGuild()) + return false; + return a.getObjectUUID() == b.getObjectUUID(); + } + + public static boolean sameGuildIncludeErrant(Guild a, Guild b) { + if (a == null || b == null) + return false; + if (a.isEmptyGuild() || b.isEmptyGuild()) + return true; + return a.getObjectUUID() == b.getObjectUUID(); + } + + public static boolean sameNation(Guild a, Guild b) { + if (a == null || b == null) + return false; + if (a.getObjectUUID() == b.getObjectUUID()) + return true; + if (a.nation == null || b.nation == null) + return false; + return a.nation.getObjectUUID() == b.nation.getObjectUUID(); + } + + public static boolean sameNationExcludeErrant(Guild a, Guild b) { + if (a == null || b == null) + return false; + if (a.getObjectUUID() == b.getObjectUUID()) + return true; + if (a.nation == null || b.nation == null) + return false; + return a.nation.getObjectUUID() == b.nation.getObjectUUID() && !a.nation.isEmptyGuild(); + } + + public static boolean isTaxCollector(int uuid) { + //TODO add the handling for this later + return false; + } + + public static boolean canSwearIn(Guild toSub) { + + boolean canSwear = false; + + switch (toSub.guildState) { + + case Protectorate: + case Petitioner: + canSwear = true; + break; + default: + canSwear = false; + } + + return canSwear; + } + + public static void _serializeForClientMsg(Guild guild, ByteBufferWriter writer) { + Guild.serializeForClientMsg(guild, writer, null, false); + } + + public static void serializeForClientMsg(Guild guild, ByteBufferWriter writer, PlayerCharacter pc, boolean reshowGuild) { + writer.putInt(guild.getObjectType().ordinal()); + writer.putInt(guild.getObjectUUID()); + writer.putInt(guild.nation.getObjectType().ordinal()); + writer.putInt(guild.nation.getObjectUUID()); + + if (pc == null) { + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); // Defaults + writer.putInt(0); // Defaults + } else { + writer.putString(guild.name); + writer.putString(guild.nation.name); + writer.putInt(GuildStatusController.getTitle(pc.getGuildStatus())); // TODO Double check this is + // title and rank + if (GuildStatusController.isGuildLeader(pc.getGuildStatus())) + writer.putInt(PlayerCharacter.GetPlayerRealmTitle(pc)); + else + writer.putInt(GuildStatusController.getRank(pc.getGuildStatus())); + //writer.putInt(GuildStatusController.getRank(pc.getGuildStatus())); + } + + City ownedCity = guild.getOwnedCity(); + + if (ownedCity != null) { + Realm realm = guild.getOwnedCity().getRealm(); + if (realm != null && realm.getRulingCity() != null) { + if (realm.getRulingCity().equals(ownedCity)) { + writer.putInt(realm.getCharterType()); + } else + writer.putInt(0); + } else { + writer.putInt(0); + } + } else + writer.putInt(0); + + writer.putFloat(200); + writer.putFloat(200); // Pad + + GuildTag._serializeForDisplay(guild.guildTag, writer); + GuildTag._serializeForDisplay(guild.nation.guildTag, writer); + if (reshowGuild) { + writer.putInt(1); + writer.putInt(guild.getObjectType().ordinal()); + writer.putInt(guild.getObjectUUID()); + + } else + writer.putInt(0); // Pad + } + + public static void serializeForTrack(Guild guild, ByteBufferWriter writer) { + Guild.serializeGuildForTrack(guild, writer); + if (guild.nation != null) + Guild.serializeGuildForTrack(guild.nation, writer); else - this.nation = nation; + Guild.addErrantForTrack(writer); + } + + public static void serializeGuildForTrack(Guild guild, ByteBufferWriter writer) { + writer.putInt(guild.getObjectType().ordinal()); + writer.putInt(guild.getObjectUUID()); + writer.put((byte) 1); + GuildTag._serializeForDisplay(guild.guildTag, writer); + } + + public static void serializeErrantForTrack(ByteBufferWriter writer) { + addErrantForTrack(writer); //Guild + addErrantForTrack(writer); //Nation + } + + private static void addErrantForTrack(ByteBufferWriter writer) { + writer.putInt(0); //type + writer.putInt(0); //ID + writer.put((byte) 1); + writer.putInt(16); //Tags + writer.putInt(16); + writer.putInt(16); + writer.putInt(0); + writer.putInt(0); + } + + public static Guild getErrantGuild() { + + if (Guild.errantGuild == null) + Guild.errantGuild = new Guild("None", Guild.getErrantNation(), 0, + "Anarchy", GuildTag.ERRANT, 0); + + return Guild.errantGuild; + } + + public static Guild getErrantNation() { + if (Guild.errantNation == null) + Guild.errantNation = new Guild("None", null, 10, "Despot Rule", GuildTag.ERRANT, 0); + return Guild.errantNation; + } + + public static Guild getGuild(final int objectUUID) { + + if (objectUUID == 0) + return Guild.getErrantGuild(); + Guild guild = (Guild) DbManager.getFromCache(Enum.GameObjectType.Guild, objectUUID); + if (guild != null) + return guild; + + Guild dbGuild = DbManager.GuildQueries.GET_GUILD(objectUUID); + + if (dbGuild == null) + return Guild.getErrantGuild(); + else + return dbGuild; + } + + public static void UpdateClientAlliances(Guild toUpdate) { + UpdateClientAlliancesMsg ucam = new UpdateClientAlliancesMsg(toUpdate); + + + for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) { + + if (Guild.sameGuild(player.getGuild(), toUpdate)) { + Dispatch dispatch = Dispatch.borrow(player, ucam); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } + + + } + } + + public static void UpdateClientAlliancesForPlayer(PlayerCharacter toUpdate) { + UpdateClientAlliancesMsg ucam = new UpdateClientAlliancesMsg(toUpdate.getGuild()); + Dispatch dispatch = Dispatch.borrow(toUpdate, ucam); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + + } + + public static Guild getFromCache(int id) { + return (Guild) DbManager.getFromCache(GameObjectType.Guild, id); + } + + public static ArrayList GuildRoster(Guild guild) { + ArrayList roster = new ArrayList<>(); + if (guild == null) + return roster; + + if (guild.isEmptyGuild()) + return roster; + + if (DbManager.getList(GameObjectType.PlayerCharacter) == null) + return roster; + for (AbstractGameObject ago : DbManager.getList(GameObjectType.PlayerCharacter)) { + PlayerCharacter toAdd = (PlayerCharacter) ago; + + if (!toAdd.getGuild().equals(guild)) + continue; + + if (toAdd.isDeleted()) + continue; + + roster.add(toAdd); + + } + return roster; } /* @@ -211,6 +449,13 @@ public class Guild extends AbstractWorldObject { return this.nation != null && this.cityUUID != 0 && this.nation == this; } + public void setNation(Guild nation) { + if (nation == null) + this.nation = Guild.getErrantGuild(); + else + this.nation = nation; + } + public City getOwnedCity() { return City.getCity(this.cityUUID); @@ -255,31 +500,37 @@ public class Guild extends AbstractWorldObject { return charter; } + /* + * Utils + */ + public int getGuildLeaderUUID() { return this.guildLeaderUUID; } - public static AbstractCharacter GetGL(Guild guild) { - if (guild == null) - return null; - - if (guild.guildLeaderUUID == 0) - return null; - - if (guild.ownerIsNPC) - return NPC.getFromCache(guild.guildLeaderUUID); - - return PlayerCharacter.getFromCache(guild.guildLeaderUUID); + /* + * Setters + */ + public void setGuildLeaderUUID(int value) { + this.guildLeaderUUID = value; } public String getMOTD() { return this.motd; } + public void setMOTD(String value) { + this.motd = value; + } + public String getICMOTD() { return this.icmotd; } + public void setICMOTD(String value) { + this.icmotd = value; + } + public boolean isNPCGuild() { return this.ownerIsNPC; @@ -310,10 +561,11 @@ public class Guild extends AbstractWorldObject { } /* - * Setters + * Serialization */ - public void setGuildLeaderUUID(int value) { - this.guildLeaderUUID = value; + + public void setMineTime(int mineTime) { + this.mineTime = mineTime; } public boolean setGuildLeader(AbstractCharacter ac) { @@ -356,14 +608,6 @@ public class Guild extends AbstractWorldObject { return true; } - public void setMOTD(String value) { - this.motd = value; - } - - public void setICMOTD(String value) { - this.icmotd = value; - } - public int getBgc1() { if (this.guildTag != null) return this.guildTag.backgroundColor01; @@ -395,67 +639,16 @@ public class Guild extends AbstractWorldObject { return 0; } - /* - * Utils - */ - public boolean isEmptyGuild() { return this.getObjectUUID() == Guild.errantGuild.getObjectUUID(); } - public static boolean sameGuild(Guild a, Guild b) { - if (a == null || b == null) - return false; - return a.getObjectUUID() == b.getObjectUUID(); - } - - public static boolean sameGuildExcludeErrant(Guild a, Guild b) { - if (a == null || b == null) - return false; - if (a.isEmptyGuild() || b.isEmptyGuild()) - return false; - return a.getObjectUUID() == b.getObjectUUID(); - } - - public static boolean sameGuildIncludeErrant(Guild a, Guild b) { - if (a == null || b == null) - return false; - if (a.isEmptyGuild() || b.isEmptyGuild()) - return true; - return a.getObjectUUID() == b.getObjectUUID(); - } - - public static boolean sameNation(Guild a, Guild b) { - if (a == null || b == null) - return false; - if (a.getObjectUUID() == b.getObjectUUID()) - return true; - if (a.nation == null || b.nation == null) - return false; - return a.nation.getObjectUUID() == b.nation.getObjectUUID(); - } - - public static boolean sameNationExcludeErrant(Guild a, Guild b) { - if (a == null || b == null) - return false; - if (a.getObjectUUID() == b.getObjectUUID()) - return true; - if (a.nation == null || b.nation == null) - return false; - return a.nation.getObjectUUID() == b.nation.getObjectUUID() && !a.nation.isEmptyGuild(); - } - public boolean isGuildLeader(int uuid) { return (this.guildLeaderUUID == uuid); } - public static boolean isTaxCollector(int uuid) { - //TODO add the handling for this later - return false; - } - /** * Removes a PlayerCharacter from this (non-Errant) Guild. * @@ -574,103 +767,6 @@ public class Guild extends AbstractWorldObject { return canSub; } - public static boolean canSwearIn(Guild toSub) { - - boolean canSwear = false; - - switch (toSub.guildState) { - - case Protectorate: - case Petitioner: - canSwear = true; - break; - default: - canSwear = false; - } - - return canSwear; - } - - /* - * Serialization - */ - - public static void _serializeForClientMsg(Guild guild, ByteBufferWriter writer) { - Guild.serializeForClientMsg(guild, writer, null, false); - } - - public static void serializeForClientMsg(Guild guild, ByteBufferWriter writer, PlayerCharacter pc, boolean reshowGuild) { - writer.putInt(guild.getObjectType().ordinal()); - writer.putInt(guild.getObjectUUID()); - writer.putInt(guild.nation.getObjectType().ordinal()); - writer.putInt(guild.nation.getObjectUUID()); - - if (pc == null) { - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); // Defaults - writer.putInt(0); // Defaults - } else { - writer.putString(guild.name); - writer.putString(guild.nation.name); - writer.putInt(GuildStatusController.getTitle(pc.getGuildStatus())); // TODO Double check this is - // title and rank - if (GuildStatusController.isGuildLeader(pc.getGuildStatus())) - writer.putInt(PlayerCharacter.GetPlayerRealmTitle(pc)); - else - writer.putInt(GuildStatusController.getRank(pc.getGuildStatus())); - //writer.putInt(GuildStatusController.getRank(pc.getGuildStatus())); - } - - City ownedCity = guild.getOwnedCity(); - - if (ownedCity != null) { - Realm realm = guild.getOwnedCity().getRealm(); - if (realm != null && realm.getRulingCity() != null) { - if (realm.getRulingCity().equals(ownedCity)) { - writer.putInt(realm.getCharterType()); - } else - writer.putInt(0); - } else { - writer.putInt(0); - } - } else - writer.putInt(0); - - writer.putFloat(200); - writer.putFloat(200); // Pad - - GuildTag._serializeForDisplay(guild.guildTag, writer); - GuildTag._serializeForDisplay(guild.nation.guildTag, writer); - if (reshowGuild) { - writer.putInt(1); - writer.putInt(guild.getObjectType().ordinal()); - writer.putInt(guild.getObjectUUID()); - - } else - writer.putInt(0); // Pad - } - - public static void serializeForTrack(Guild guild, ByteBufferWriter writer) { - Guild.serializeGuildForTrack(guild, writer); - if (guild.nation != null) - Guild.serializeGuildForTrack(guild.nation, writer); - else - Guild.addErrantForTrack(writer); - } - - public static void serializeGuildForTrack(Guild guild, ByteBufferWriter writer) { - writer.putInt(guild.getObjectType().ordinal()); - writer.putInt(guild.getObjectUUID()); - writer.put((byte) 1); - GuildTag._serializeForDisplay(guild.guildTag, writer); - } - - public static void serializeErrantForTrack(ByteBufferWriter writer) { - addErrantForTrack(writer); //Guild - addErrantForTrack(writer); //Nation - } - public int getRealmsOwnedFlag() { int flag = 0; switch (realmsOwned) { @@ -694,17 +790,6 @@ public class Guild extends AbstractWorldObject { return flag; } - private static void addErrantForTrack(ByteBufferWriter writer) { - writer.putInt(0); //type - writer.putInt(0); //ID - writer.put((byte) 1); - writer.putInt(16); //Tags - writer.putInt(16); - writer.putInt(16); - writer.putInt(0); - writer.putInt(0); - } - public void serializeForPlayer(ByteBufferWriter writer) { writer.putInt(this.getObjectType().ordinal()); writer.putInt(this.getObjectUUID()); @@ -713,38 +798,6 @@ public class Guild extends AbstractWorldObject { } - public static Guild getErrantGuild() { - - if (Guild.errantGuild == null) - Guild.errantGuild = new Guild("None", Guild.getErrantNation(), 0, - "Anarchy", GuildTag.ERRANT, 0); - - return Guild.errantGuild; - } - - public static Guild getErrantNation() { - if (Guild.errantNation == null) - Guild.errantNation = new Guild("None", null, 10, "Despot Rule", GuildTag.ERRANT, 0); - return Guild.errantNation; - } - - public static Guild getGuild(final int objectUUID) { - - if (objectUUID == 0) - return Guild.getErrantGuild(); - Guild guild = (Guild) DbManager.getFromCache(Enum.GameObjectType.Guild, objectUUID); - if (guild != null) - return guild; - - Guild dbGuild = DbManager.GuildQueries.GET_GUILD(objectUUID); - - if (dbGuild == null) - return Guild.getErrantGuild(); - else - return dbGuild; - } - - @Override public void updateDatabase() { DbManager.GuildQueries.updateDatabase(this); @@ -943,15 +996,10 @@ public class Guild extends AbstractWorldObject { } - public void setMineTime(int mineTime) { - this.mineTime = mineTime; - } - public ConcurrentHashMap getGuildCondemned() { return guildCondemned; } - public String getHash() { return hash; } @@ -1182,17 +1230,17 @@ public class Guild extends AbstractWorldObject { } public synchronized boolean removeGuildFromAlliance(Guild toRemove) { - this.allyList.remove(toRemove); + this.allyList.remove(toRemove); return true; } public synchronized boolean removeGuildFromEnemy(Guild toRemove) { - this.enemyList.remove(toRemove); + this.enemyList.remove(toRemove); return true; } public synchronized boolean removeGuildFromRecommended(Guild toRemove) { - this.recommendList.remove(toRemove); + this.recommendList.remove(toRemove); return true; } @@ -1219,57 +1267,5 @@ public class Guild extends AbstractWorldObject { } - public static void UpdateClientAlliances(Guild toUpdate) { - UpdateClientAlliancesMsg ucam = new UpdateClientAlliancesMsg(toUpdate); - - - for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) { - - if (Guild.sameGuild(player.getGuild(), toUpdate)) { - Dispatch dispatch = Dispatch.borrow(player, ucam); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } - - - } - } - - public static void UpdateClientAlliancesForPlayer(PlayerCharacter toUpdate) { - UpdateClientAlliancesMsg ucam = new UpdateClientAlliancesMsg(toUpdate.getGuild()); - Dispatch dispatch = Dispatch.borrow(toUpdate, ucam); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - - } - - public static Guild getFromCache(int id) { - return (Guild) DbManager.getFromCache(GameObjectType.Guild, id); - } - - public static ArrayList GuildRoster(Guild guild) { - ArrayList roster = new ArrayList<>(); - if (guild == null) - return roster; - - if (guild.isEmptyGuild()) - return roster; - - if (DbManager.getList(GameObjectType.PlayerCharacter) == null) - return roster; - for (AbstractGameObject ago : DbManager.getList(GameObjectType.PlayerCharacter)) { - PlayerCharacter toAdd = (PlayerCharacter) ago; - - if (!toAdd.getGuild().equals(guild)) - continue; - - if (toAdd.isDeleted()) - continue; - - roster.add(toAdd); - - } - return roster; - } - } diff --git a/src/engine/objects/GuildAlliances.java b/src/engine/objects/GuildAlliances.java index 7c078729..7f43f1bb 100644 --- a/src/engine/objects/GuildAlliances.java +++ b/src/engine/objects/GuildAlliances.java @@ -15,88 +15,88 @@ import engine.gameManager.DbManager; import java.sql.ResultSet; import java.sql.SQLException; -public class GuildAlliances { - - private int sourceGuild; - private int allianceGuild; - private boolean isRecommended; - private boolean isAlly; - private String recommender; - - /** - * ResultSet Constructor - */ - - public GuildAlliances(ResultSet rs) throws SQLException { - this.sourceGuild = rs.getInt("GuildID"); - this.allianceGuild = rs.getInt("OtherGuildID"); - this.isRecommended = rs.getBoolean("isRecommended"); - this.isAlly = rs.getBoolean("isAlliance"); - this.recommender =rs.getString("recommender"); - } - - public GuildAlliances(int sourceGuild, int allianceGuild, boolean isRecommended, boolean isAlly, - String recommender) { - super(); - this.sourceGuild = sourceGuild; - this.allianceGuild = allianceGuild; - this.isRecommended = isRecommended; - this.isAlly = isAlly; - this.recommender = recommender; - } - - public int getSourceGuild() { - return sourceGuild; - } - - public int getAllianceGuild() { - return allianceGuild; - } - - public boolean isRecommended() { - return isRecommended; - } - - public boolean isAlly() { - return isAlly; - } - - public String getRecommender() { - return recommender; - } - - public synchronized boolean UpdateAlliance(final AllianceType allianceType, boolean updateRecommended){ - switch (allianceType){ - case Ally: - if (updateRecommended){ - if (!DbManager.GuildQueries.UPDATE_ALLIANCE_AND_RECOMMENDED(this.sourceGuild, this.allianceGuild, true)) - return false; - this.isAlly = true; - this.isRecommended = false; - }else{ - if (!DbManager.GuildQueries.UPDATE_ALLIANCE(this.sourceGuild, this.allianceGuild, true)) - return false; - this.isAlly = true; - this.isRecommended = false; - } - break; - case Enemy: - - if (updateRecommended){ - if (!DbManager.GuildQueries.UPDATE_ALLIANCE_AND_RECOMMENDED(this.sourceGuild, this.allianceGuild, false)) - return false; - this.isAlly = false; - this.isRecommended = false; - }else{ - if (!DbManager.GuildQueries.UPDATE_ALLIANCE(this.sourceGuild, this.allianceGuild, false)) - return false; - this.isAlly = false; - this.isRecommended = false; - } - break; - - } - return true; - } +public class GuildAlliances { + + private int sourceGuild; + private int allianceGuild; + private boolean isRecommended; + private boolean isAlly; + private String recommender; + + /** + * ResultSet Constructor + */ + + public GuildAlliances(ResultSet rs) throws SQLException { + this.sourceGuild = rs.getInt("GuildID"); + this.allianceGuild = rs.getInt("OtherGuildID"); + this.isRecommended = rs.getBoolean("isRecommended"); + this.isAlly = rs.getBoolean("isAlliance"); + this.recommender = rs.getString("recommender"); + } + + public GuildAlliances(int sourceGuild, int allianceGuild, boolean isRecommended, boolean isAlly, + String recommender) { + super(); + this.sourceGuild = sourceGuild; + this.allianceGuild = allianceGuild; + this.isRecommended = isRecommended; + this.isAlly = isAlly; + this.recommender = recommender; + } + + public int getSourceGuild() { + return sourceGuild; + } + + public int getAllianceGuild() { + return allianceGuild; + } + + public boolean isRecommended() { + return isRecommended; + } + + public boolean isAlly() { + return isAlly; + } + + public String getRecommender() { + return recommender; + } + + public synchronized boolean UpdateAlliance(final AllianceType allianceType, boolean updateRecommended) { + switch (allianceType) { + case Ally: + if (updateRecommended) { + if (!DbManager.GuildQueries.UPDATE_ALLIANCE_AND_RECOMMENDED(this.sourceGuild, this.allianceGuild, true)) + return false; + this.isAlly = true; + this.isRecommended = false; + } else { + if (!DbManager.GuildQueries.UPDATE_ALLIANCE(this.sourceGuild, this.allianceGuild, true)) + return false; + this.isAlly = true; + this.isRecommended = false; + } + break; + case Enemy: + + if (updateRecommended) { + if (!DbManager.GuildQueries.UPDATE_ALLIANCE_AND_RECOMMENDED(this.sourceGuild, this.allianceGuild, false)) + return false; + this.isAlly = false; + this.isRecommended = false; + } else { + if (!DbManager.GuildQueries.UPDATE_ALLIANCE(this.sourceGuild, this.allianceGuild, false)) + return false; + this.isAlly = false; + this.isRecommended = false; + } + break; + + } + return true; + } } diff --git a/src/engine/objects/GuildCondemn.java b/src/engine/objects/GuildCondemn.java index 87a883d5..8aceafc2 100644 --- a/src/engine/objects/GuildCondemn.java +++ b/src/engine/objects/GuildCondemn.java @@ -15,63 +15,54 @@ import java.util.ArrayList; import java.util.HashMap; +public class GuildCondemn { + public static HashMap> GetCondemnedFromGuildID = new HashMap<>(); + private int ID; + private int playerUID; + private int parentGuildUID; + private int guildUID; + private int friendType; -public class GuildCondemn { - private int ID; - private int playerUID; - private int parentGuildUID; - private int guildUID; - private int friendType; - public static HashMap> GetCondemnedFromGuildID = new HashMap<>(); + /** + * ResultSet Constructor + */ + public GuildCondemn(ResultSet rs) throws SQLException { + this.playerUID = rs.getInt("playerUID"); + this.parentGuildUID = rs.getInt("buildingUID"); + this.guildUID = rs.getInt("guildUID"); + this.friendType = rs.getInt("friendType"); + } - /** - * ResultSet Constructor - */ - public GuildCondemn(ResultSet rs) throws SQLException { - this.playerUID = rs.getInt("playerUID"); - this.parentGuildUID = rs.getInt("buildingUID"); - this.guildUID = rs.getInt("guildUID"); - this.friendType = rs.getInt("friendType"); - } - - + public GuildCondemn(int playerUID, int parentGuildUID, int guildUID, int friendType) { + super(); + this.playerUID = playerUID; + this.parentGuildUID = parentGuildUID; + this.guildUID = guildUID; + this.friendType = friendType; + } - public GuildCondemn(int playerUID, int parentGuildUID, int guildUID, int friendType) { - super(); - this.playerUID = playerUID; - this.parentGuildUID = parentGuildUID; - this.guildUID = guildUID; - this.friendType = friendType; - } + public int getPlayerUID() { + return playerUID; + } + public int getParentGuildUID() { + return parentGuildUID; + } - public int getPlayerUID() { - return playerUID; - } + public int getGuildUID() { + return guildUID; + } - public int getParentGuildUID() { - return parentGuildUID; - } + public int getFriendType() { + return friendType; + } - public int getGuildUID() { - return guildUID; - } - - - public int getFriendType() { - return friendType; - } - - - - - } diff --git a/src/engine/objects/GuildHistory.java b/src/engine/objects/GuildHistory.java index ad48e476..6c29820a 100644 --- a/src/engine/objects/GuildHistory.java +++ b/src/engine/objects/GuildHistory.java @@ -22,73 +22,68 @@ import java.sql.SQLException; public class GuildHistory { - private int guildID; - private String guildName; - private DateTime time; - private GuildHistoryType historyType; - - - - - public GuildHistory( int guildID, String guildName, - DateTime dateTime, GuildHistoryType historyType ) { - super(); - this.guildID = guildID; - this.guildName = guildName; - this.time = dateTime; - this.historyType = historyType; - - } - - public GuildHistoryType getHistoryType() { - return historyType; - } - - public GuildHistory(ResultSet rs) throws SQLException { - java.util.Date sqlDateTime; - this.guildID = rs.getInt("guildID"); - Guild guild = Guild.getGuild(this.guildID); - if (guild != null) - this.guildName = guild.getName(); - else - this.guildName = "Guild Not Found"; - - sqlDateTime = rs.getTimestamp("historyDate"); - if (sqlDateTime != null) - this.time = new DateTime(sqlDateTime); - else - this.time = DateTime.now().minusYears(1); - this.historyType = GuildHistoryType.valueOf(rs.getString("historyType")); - } - - - public long getGuildID() { - return guildID; - } - - public String getGuildName() { - return guildName; - } - - - - public void _serialize(ByteBufferWriter writer) { - writer.putInt(this.historyType.getType()); - writer.putInt(GameObjectType.Guild.ordinal()); - writer.putInt(this.guildID); - writer.putString(guildName); - writer.putInt(0); //Pad - writer.putDateTime(this.time); - } - - public DateTime getTime() { - return time; - } - - public void setTime(DateTime time) { - this.time = time; - } - + private int guildID; + private String guildName; + private DateTime time; + private GuildHistoryType historyType; + + + public GuildHistory(int guildID, String guildName, + DateTime dateTime, GuildHistoryType historyType) { + super(); + this.guildID = guildID; + this.guildName = guildName; + this.time = dateTime; + this.historyType = historyType; + + } + + public GuildHistory(ResultSet rs) throws SQLException { + java.util.Date sqlDateTime; + this.guildID = rs.getInt("guildID"); + Guild guild = Guild.getGuild(this.guildID); + if (guild != null) + this.guildName = guild.getName(); + else + this.guildName = "Guild Not Found"; + + sqlDateTime = rs.getTimestamp("historyDate"); + if (sqlDateTime != null) + this.time = new DateTime(sqlDateTime); + else + this.time = DateTime.now().minusYears(1); + this.historyType = GuildHistoryType.valueOf(rs.getString("historyType")); + } + + public GuildHistoryType getHistoryType() { + return historyType; + } + + public long getGuildID() { + return guildID; + } + + public String getGuildName() { + return guildName; + } + + + public void _serialize(ByteBufferWriter writer) { + writer.putInt(this.historyType.getType()); + writer.putInt(GameObjectType.Guild.ordinal()); + writer.putInt(this.guildID); + writer.putString(guildName); + writer.putInt(0); //Pad + writer.putDateTime(this.time); + } + + public DateTime getTime() { + return time; + } + + public void setTime(DateTime time) { + this.time = time; + } } diff --git a/src/engine/objects/GuildStatusController.java b/src/engine/objects/GuildStatusController.java index ac76790b..6c7f8631 100644 --- a/src/engine/objects/GuildStatusController.java +++ b/src/engine/objects/GuildStatusController.java @@ -13,119 +13,118 @@ import java.util.concurrent.atomic.AtomicInteger; public class GuildStatusController { - /* - * Status is stored in a single integer contained within the Character Table - * - * This class is responsible for maintaining and interpreting that value. - * - * Byte 1 - All : Title [0x000000FF] - * Byte 2 - Low : isFullMember [0x00000F00] - * Byte 2 - High : isTaxCollector [0x0000F000] - * Byte 3 - Low : isRecruiter [0x000F0000] - * Byte 3 - High : isInnerCouncil [0x00F00000] - * Byte 4 - Low : isGuildLeader [0x0F000000] - * Byte 4 - High : Empty [0xF0000000] - */ - - //Getters - public static boolean isGuildLeader(AtomicInteger status) { - return ((status.get() & GUILDLEADER) > 0); - } - - public static boolean isInnerCouncil(AtomicInteger status) { - return ((status.get() & INNERCOUNCIL) > 0); - } - - public static boolean isRecruiter(AtomicInteger status) { - return ((status.get() & RECRUITER) > 0); - } - - public static boolean isTaxCollector(AtomicInteger status) { - return ((status.get() & TAXCOLLECTOR) > 0); - } - - public static boolean isFullMember(AtomicInteger status) { - return ((status.get() & FULLMEMBER) > 0); - } - - public static int getTitle(AtomicInteger status) { - return status.get() & TITLE; - } - - public static int getRank(AtomicInteger status) { - int value = status.get(); - - //Guild Leader - if(value > 0x00FFFFFF) { - return 10; - } - - //Inner Council - if(value > 0x000FFFFF) { - return 9; - } - - //Recruiter - if(value > 0x0000FFFF) { - return 8; - } - - //Tax Collector - if(value > 0x00000FFF) { - return 7; - } - - //Full Member - if(value > 0x000000FF) { - return 6; - } - - //Petitioner - return 5; - } - - //Setters - public static void setTitle(AtomicInteger current, int i) { - int value; - i &= TITLE; - do { - value = current.get(); - }while(!current.compareAndSet(value, (value & ~TITLE) | i)); - } - - - public static void setFullMember(AtomicInteger status, boolean newValue) { - setNibble(status, newValue, FULLMEMBER); - } - - public static void setTaxCollector(AtomicInteger status, boolean newValue) { - setNibble(status, newValue, TAXCOLLECTOR); - } - - public static void setRecruiter(AtomicInteger status, boolean newValue) { - setNibble(status, newValue, RECRUITER); - } - - public static void setInnerCouncil(AtomicInteger status, boolean newValue) { - setNibble(status, newValue, INNERCOUNCIL); - } - - public static void setGuildLeader (AtomicInteger status, boolean newValue) { - setNibble(status, newValue, GUILDLEADER); - } - - private static void setNibble(AtomicInteger current, boolean newValue, int mask) { - int value, i = ((newValue)?mask & -1:0); - do { - value = current.get(); - }while(!current.compareAndSet(value, (value & ~mask) | i)); - } - - //Constants - private static final int TITLE = 0x000000FF; // 00, F0 and 0F had no effect - private static final int FULLMEMBER = 0x00000F00; - private static final int TAXCOLLECTOR = 0x0000F000; - private static final int RECRUITER = 0x000F0000; - private static final int INNERCOUNCIL = 0x00F00000; - private static final int GUILDLEADER = 0x0F000000; + /* + * Status is stored in a single integer contained within the Character Table + * + * This class is responsible for maintaining and interpreting that value. + * + * Byte 1 - All : Title [0x000000FF] + * Byte 2 - Low : isFullMember [0x00000F00] + * Byte 2 - High : isTaxCollector [0x0000F000] + * Byte 3 - Low : isRecruiter [0x000F0000] + * Byte 3 - High : isInnerCouncil [0x00F00000] + * Byte 4 - Low : isGuildLeader [0x0F000000] + * Byte 4 - High : Empty [0xF0000000] + */ + + //Constants + private static final int TITLE = 0x000000FF; // 00, F0 and 0F had no effect + private static final int FULLMEMBER = 0x00000F00; + private static final int TAXCOLLECTOR = 0x0000F000; + private static final int RECRUITER = 0x000F0000; + private static final int INNERCOUNCIL = 0x00F00000; + private static final int GUILDLEADER = 0x0F000000; + + //Getters + public static boolean isGuildLeader(AtomicInteger status) { + return ((status.get() & GUILDLEADER) > 0); + } + + public static boolean isInnerCouncil(AtomicInteger status) { + return ((status.get() & INNERCOUNCIL) > 0); + } + + public static boolean isRecruiter(AtomicInteger status) { + return ((status.get() & RECRUITER) > 0); + } + + public static boolean isTaxCollector(AtomicInteger status) { + return ((status.get() & TAXCOLLECTOR) > 0); + } + + public static boolean isFullMember(AtomicInteger status) { + return ((status.get() & FULLMEMBER) > 0); + } + + public static int getTitle(AtomicInteger status) { + return status.get() & TITLE; + } + + public static int getRank(AtomicInteger status) { + int value = status.get(); + + //Guild Leader + if (value > 0x00FFFFFF) { + return 10; + } + + //Inner Council + if (value > 0x000FFFFF) { + return 9; + } + + //Recruiter + if (value > 0x0000FFFF) { + return 8; + } + + //Tax Collector + if (value > 0x00000FFF) { + return 7; + } + + //Full Member + if (value > 0x000000FF) { + return 6; + } + + //Petitioner + return 5; + } + + //Setters + public static void setTitle(AtomicInteger current, int i) { + int value; + i &= TITLE; + do { + value = current.get(); + } while (!current.compareAndSet(value, (value & ~TITLE) | i)); + } + + public static void setFullMember(AtomicInteger status, boolean newValue) { + setNibble(status, newValue, FULLMEMBER); + } + + public static void setTaxCollector(AtomicInteger status, boolean newValue) { + setNibble(status, newValue, TAXCOLLECTOR); + } + + public static void setRecruiter(AtomicInteger status, boolean newValue) { + setNibble(status, newValue, RECRUITER); + } + + public static void setInnerCouncil(AtomicInteger status, boolean newValue) { + setNibble(status, newValue, INNERCOUNCIL); + } + + public static void setGuildLeader(AtomicInteger status, boolean newValue) { + setNibble(status, newValue, GUILDLEADER); + } + + private static void setNibble(AtomicInteger current, boolean newValue, int mask) { + int value, i = ((newValue) ? mask & -1 : 0); + do { + value = current.get(); + } while (!current.compareAndSet(value, (value & ~mask) | i)); + } } diff --git a/src/engine/objects/GuildTag.java b/src/engine/objects/GuildTag.java index 014c0341..60a6d4b9 100644 --- a/src/engine/objects/GuildTag.java +++ b/src/engine/objects/GuildTag.java @@ -13,81 +13,79 @@ import engine.net.ByteBufferReader; import engine.net.ByteBufferWriter; public class GuildTag { - public final int backgroundColor01; - public final int backgroundColor02; - public final int symbolColor; - public final int symbol; - public final int backgroundDesign; - public static final GuildTag ERRANT = new GuildTag(16,16,16,0,0); + public static final GuildTag ERRANT = new GuildTag(16, 16, 16, 0, 0); + public final int backgroundColor01; + public final int backgroundColor02; + public final int symbolColor; + public final int symbol; + public final int backgroundDesign; - public GuildTag(int backgroundColor01, int backgroundColor02, - int symbolColor, int symbol, int backgroundDesign) { - super(); - this.backgroundColor01 = backgroundColor01; - this.backgroundColor02 = backgroundColor02; - this.symbolColor = symbolColor; - this.symbol = symbol; - this.backgroundDesign = backgroundDesign; - } + public GuildTag(int backgroundColor01, int backgroundColor02, + int symbolColor, int symbol, int backgroundDesign) { + super(); + this.backgroundColor01 = backgroundColor01; + this.backgroundColor02 = backgroundColor02; + this.symbolColor = symbolColor; + this.symbol = symbol; + this.backgroundDesign = backgroundDesign; + } - public GuildTag(ByteBufferReader reader, boolean forCreation) { - this.backgroundColor01 = reader.getInt(); - this.backgroundColor02 = reader.getInt(); - this.symbolColor = reader.getInt(); - if(forCreation) { - this.symbol = reader.getInt(); - this.backgroundDesign = reader.getInt(); - } else { - this.backgroundDesign = reader.getInt(); - this.symbol = reader.getInt(); - } - } + public GuildTag(ByteBufferReader reader, boolean forCreation) { + this.backgroundColor01 = reader.getInt(); + this.backgroundColor02 = reader.getInt(); + this.symbolColor = reader.getInt(); + if (forCreation) { + this.symbol = reader.getInt(); + this.backgroundDesign = reader.getInt(); + } else { + this.backgroundDesign = reader.getInt(); + this.symbol = reader.getInt(); + } + } - public GuildTag(ByteBufferReader reader) { - this(reader, false); - } + public GuildTag(ByteBufferReader reader) { + this(reader, false); + } - public boolean isValid() { - if(this.backgroundColor01 < 0 || this.backgroundColor01 > 18) - return false; - if(this.backgroundColor02 < 0 || this.backgroundColor02 > 18) - return false; - if(this.symbolColor < 0 || this.symbolColor > 18) - return false; - if(this.symbol < 0 || this.symbol > 183) - return false; - return this.backgroundDesign >= 0 && this.backgroundDesign <= 14; + public static void _serializeForGuildCreation(GuildTag guildTag, ByteBufferWriter writer) { + writer.putInt(guildTag.backgroundColor01); + writer.putInt(guildTag.backgroundColor02); + writer.putInt(guildTag.symbolColor); + writer.putInt(guildTag.symbol); + writer.putInt(guildTag.backgroundDesign); + } + + public static void _serializeForDisplay(GuildTag guildTag, ByteBufferWriter writer) { + writer.putInt(guildTag.backgroundColor01); + writer.putInt(guildTag.backgroundColor02); + writer.putInt(guildTag.symbolColor); + writer.putInt(guildTag.backgroundDesign); + writer.putInt(guildTag.symbol); } - - public static void _serializeForGuildCreation(GuildTag guildTag, ByteBufferWriter writer) { - writer.putInt(guildTag.backgroundColor01); - writer.putInt(guildTag.backgroundColor02); - writer.putInt(guildTag.symbolColor); - writer.putInt(guildTag.symbol); - writer.putInt(guildTag.backgroundDesign); - } + public boolean isValid() { + if (this.backgroundColor01 < 0 || this.backgroundColor01 > 18) + return false; + if (this.backgroundColor02 < 0 || this.backgroundColor02 > 18) + return false; + if (this.symbolColor < 0 || this.symbolColor > 18) + return false; + if (this.symbol < 0 || this.symbol > 183) + return false; + return this.backgroundDesign >= 0 && this.backgroundDesign <= 14; + } - public static void _serializeForDisplay(GuildTag guildTag, ByteBufferWriter writer) { - writer.putInt(guildTag.backgroundColor01); - writer.putInt(guildTag.backgroundColor02); - writer.putInt(guildTag.symbolColor); - writer.putInt(guildTag.backgroundDesign); - writer.putInt(guildTag.symbol); - } + public void serializeObject(ByteBufferWriter writer) { + writer.put((byte) this.backgroundColor01); + writer.put((byte) this.backgroundColor02); + writer.put((byte) this.symbolColor); + writer.put((byte) this.backgroundDesign); + writer.put((byte) this.symbol); + } - public void serializeObject(ByteBufferWriter writer) { - writer.put((byte)this.backgroundColor01); - writer.put((byte)this.backgroundColor02); - writer.put((byte)this.symbolColor); - writer.put((byte)this.backgroundDesign); - writer.put((byte)this.symbol); - } - - - public String summarySentence() { - return "Bkgrnd: " + this.backgroundDesign + '(' + this.backgroundColor01 + '-' + this.backgroundColor02 + ')' + - "; Symbol: " + this.symbol + '(' + this.symbolColor + ')'; - } + public String summarySentence() { + return "Bkgrnd: " + this.backgroundDesign + '(' + this.backgroundColor01 + '-' + this.backgroundColor02 + ')' + + "; Symbol: " + this.symbol + '(' + this.symbolColor + ')'; + } } diff --git a/src/engine/objects/Heraldry.java b/src/engine/objects/Heraldry.java index f7757a95..b60fda8d 100644 --- a/src/engine/objects/Heraldry.java +++ b/src/engine/objects/Heraldry.java @@ -18,154 +18,153 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; -public class Heraldry { - - public int playerUID; - public int characterUUID; - public int characterType; - - public static HashMap > HeraldyMap = new HashMap<>(); - - /** - * ResultSet Constructor - */ - - public Heraldry(ResultSet rs) throws SQLException { - this.playerUID = rs.getInt("playerUID"); - this.characterUUID = rs.getInt("characterUID"); - this.characterType = rs.getInt("characterType"); - - //cache player friends. - //hashset already created, just add to set. - if (HeraldyMap.containsKey(playerUID)){ - HashMap playerHeraldySet = HeraldyMap.get(playerUID); - playerHeraldySet.put(characterUUID,characterType); - //hashset not yet created, create new set, and add to map. - }else{ - HashMap playerHeraldySet = new HashMap<>(); - playerHeraldySet.put(characterUUID,characterType); - HeraldyMap.put(this.playerUID, playerHeraldySet); - } - - } - - public Heraldry(int playerUID, int friendUID) { - super(); - this.playerUID = playerUID; - this.characterUUID = friendUID; - } - - public int getPlayerUID() { - return playerUID; - } - - public static boolean AddToHeraldy(int playerID, AbstractWorldObject character){ - HashMap characters = HeraldyMap.get(playerID); - - if (characters != null){ - //already in friends list, don't do anything. - if (characters.containsKey(character.getObjectUUID())) - return false; - - DbManager.PlayerCharacterQueries.ADD_HERALDY(playerID, character); - characters.put(character.getObjectUUID(),character.getObjectType().ordinal()); - }else{ - characters = new HashMap<>(); - DbManager.PlayerCharacterQueries.ADD_HERALDY(playerID, character); - characters.put(character.getObjectUUID(),character.getObjectType().ordinal()); - HeraldyMap.put(playerID, characters); - } - return true; - } - - public static boolean RemoveFromHeraldy(int playerID, int characterID){ - - if (!CanRemove(playerID, characterID)) - return false; - - HashMap characters = HeraldyMap.get(playerID); - - if (characters != null){ - DbManager.PlayerCharacterQueries.REMOVE_HERALDY(playerID, characterID); - characters.remove(characterID); - } - return true; - } - - public static boolean CanRemove(int playerID, int toRemove){ - if (HeraldyMap.get(playerID) == null) - return false; - - if (HeraldyMap.get(playerID).isEmpty()) - return false; - - if (!HeraldyMap.get(playerID).containsKey(toRemove)) - return false; - - return true; - } - - public static void AuditHeraldry() { - - HashMap characterMap; - ArrayList purgeList = new ArrayList<>(); - - for (int playerID : Heraldry.HeraldyMap.keySet()) { - - characterMap = Heraldry.HeraldyMap.get(playerID); - - if (characterMap == null || characterMap.isEmpty()) - continue; - - // Loop through map adding deleted characters to our purge map - - purgeList.clear(); - - for (int characterID : characterMap.keySet()) { - - int characterType = characterMap.get(characterID); - - if (characterType != GameObjectType.PlayerCharacter.ordinal()) - continue; - - // Player is deleted, add to purge list - - if (PlayerCharacter.getFromCache(characterID) == null) - purgeList.add(characterID); - - } - - // Run purge - - for (int uuid : purgeList) { - - if (!Heraldry.RemoveFromHeraldy(playerID, uuid)) - continue; - - Logger.info("Removed Deleted Character ID " + uuid + " from PlayerID " + playerID + " heraldry."); - - } - } - } - - public static void ValidateHeraldry(int playerUUID) { - - HashMap heraldryMap = Heraldry.HeraldyMap.get(playerUUID); - - if (heraldryMap == null || heraldryMap.isEmpty()) - return; - - for (int characterID : heraldryMap.keySet()){ - int characterType = heraldryMap.get(characterID); - - GameObjectType objectType = GameObjectType.values()[characterType]; - - AbstractGameObject ago = DbManager.getFromCache(objectType, characterID); - - if (ago == null) - heraldryMap.remove(characterID); - - } - } - +public class Heraldry { + + public static HashMap> HeraldyMap = new HashMap<>(); + public int playerUID; + public int characterUUID; + public int characterType; + + /** + * ResultSet Constructor + */ + + public Heraldry(ResultSet rs) throws SQLException { + this.playerUID = rs.getInt("playerUID"); + this.characterUUID = rs.getInt("characterUID"); + this.characterType = rs.getInt("characterType"); + + //cache player friends. + //hashset already created, just add to set. + if (HeraldyMap.containsKey(playerUID)) { + HashMap playerHeraldySet = HeraldyMap.get(playerUID); + playerHeraldySet.put(characterUUID, characterType); + //hashset not yet created, create new set, and add to map. + } else { + HashMap playerHeraldySet = new HashMap<>(); + playerHeraldySet.put(characterUUID, characterType); + HeraldyMap.put(this.playerUID, playerHeraldySet); + } + + } + + public Heraldry(int playerUID, int friendUID) { + super(); + this.playerUID = playerUID; + this.characterUUID = friendUID; + } + + public static boolean AddToHeraldy(int playerID, AbstractWorldObject character) { + HashMap characters = HeraldyMap.get(playerID); + + if (characters != null) { + //already in friends list, don't do anything. + if (characters.containsKey(character.getObjectUUID())) + return false; + + DbManager.PlayerCharacterQueries.ADD_HERALDY(playerID, character); + characters.put(character.getObjectUUID(), character.getObjectType().ordinal()); + } else { + characters = new HashMap<>(); + DbManager.PlayerCharacterQueries.ADD_HERALDY(playerID, character); + characters.put(character.getObjectUUID(), character.getObjectType().ordinal()); + HeraldyMap.put(playerID, characters); + } + return true; + } + + public static boolean RemoveFromHeraldy(int playerID, int characterID) { + + if (!CanRemove(playerID, characterID)) + return false; + + HashMap characters = HeraldyMap.get(playerID); + + if (characters != null) { + DbManager.PlayerCharacterQueries.REMOVE_HERALDY(playerID, characterID); + characters.remove(characterID); + } + return true; + } + + public static boolean CanRemove(int playerID, int toRemove) { + if (HeraldyMap.get(playerID) == null) + return false; + + if (HeraldyMap.get(playerID).isEmpty()) + return false; + + if (!HeraldyMap.get(playerID).containsKey(toRemove)) + return false; + + return true; + } + + public static void AuditHeraldry() { + + HashMap characterMap; + ArrayList purgeList = new ArrayList<>(); + + for (int playerID : Heraldry.HeraldyMap.keySet()) { + + characterMap = Heraldry.HeraldyMap.get(playerID); + + if (characterMap == null || characterMap.isEmpty()) + continue; + + // Loop through map adding deleted characters to our purge map + + purgeList.clear(); + + for (int characterID : characterMap.keySet()) { + + int characterType = characterMap.get(characterID); + + if (characterType != GameObjectType.PlayerCharacter.ordinal()) + continue; + + // Player is deleted, add to purge list + + if (PlayerCharacter.getFromCache(characterID) == null) + purgeList.add(characterID); + + } + + // Run purge + + for (int uuid : purgeList) { + + if (!Heraldry.RemoveFromHeraldy(playerID, uuid)) + continue; + + Logger.info("Removed Deleted Character ID " + uuid + " from PlayerID " + playerID + " heraldry."); + + } + } + } + + public static void ValidateHeraldry(int playerUUID) { + + HashMap heraldryMap = Heraldry.HeraldyMap.get(playerUUID); + + if (heraldryMap == null || heraldryMap.isEmpty()) + return; + + for (int characterID : heraldryMap.keySet()) { + int characterType = heraldryMap.get(characterID); + + GameObjectType objectType = GameObjectType.values()[characterType]; + + AbstractGameObject ago = DbManager.getFromCache(objectType, characterID); + + if (ago == null) + heraldryMap.remove(characterID); + + } + } + + public int getPlayerUID() { + return playerUID; + } + } diff --git a/src/engine/objects/Item.java b/src/engine/objects/Item.java index 11bd94e5..cc74c165 100644 --- a/src/engine/objects/Item.java +++ b/src/engine/objects/Item.java @@ -38,1431 +38,1418 @@ import java.util.concurrent.locks.ReentrantLock; public class Item extends AbstractWorldObject { - private int ownerID; //may be character, account, npc, mob - private int flags; //1 = isIDed - private int numberOfItems; - private short durabilityCurrent; - private final short durabilityMax; - private final byte chargesMax; - private byte chargesRemaining; - private byte equipSlot; - private boolean canDestroy; - private boolean rentable; - private boolean isRandom = false; - - private int value; - - public Enum.ItemContainerType containerType; - - private OwnerType ownerType; - private int itemBaseID; - private AbstractWorldObject lastOwner; - private ArrayList enchants = new ArrayList<>(); - private final ConcurrentHashMap bonuses = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private final ArrayList effectNames = new ArrayList<>(); - private static ConcurrentHashMap enchantValues = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private long dateToUpgrade; - public ReentrantLock lootLock = new ReentrantLock(); - private String customName = ""; - private int magicValue; - - /** - * No Id Constructor - */ - public Item( ItemBase itemBase, int ownerID, - OwnerType ownerType, byte chargesMax, byte chargesRemaining, - short durabilityCurrent, short durabilityMax, boolean canDestroy, - boolean rentable, Enum.ItemContainerType containerType, byte equipSlot, - ArrayList enchants, String name) { - super(); - this.itemBaseID = itemBase.getUUID(); - this.ownerID = ownerID; - this.ownerType = ownerType; - - if (itemBase.getType().getValue() == 20){ - this.chargesMax = chargesMax; - this.chargesRemaining = chargesRemaining; - } - else{ - this.chargesMax = (byte) itemBase.getNumCharges(); - this.chargesRemaining = (byte) itemBase.getNumCharges(); - } - - this.durabilityMax = (short) itemBase.getDurability(); - this.durabilityCurrent = (short) itemBase.getDurability(); - this.containerType = containerType; - this.canDestroy = canDestroy; - this.rentable = rentable; - this.equipSlot = equipSlot; - this.enchants = enchants; - this.flags = 1; + private static ConcurrentHashMap enchantValues = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private final short durabilityMax; + private final byte chargesMax; + private final ConcurrentHashMap bonuses = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private final ArrayList effectNames = new ArrayList<>(); + public Enum.ItemContainerType containerType; + public ReentrantLock lootLock = new ReentrantLock(); + private int ownerID; //may be character, account, npc, mob + private int flags; //1 = isIDed + private int numberOfItems; + private short durabilityCurrent; + private byte chargesRemaining; + private byte equipSlot; + private boolean canDestroy; + private boolean rentable; + private boolean isRandom = false; + private int value; + private OwnerType ownerType; + private int itemBaseID; + private AbstractWorldObject lastOwner; + private ArrayList enchants = new ArrayList<>(); + private long dateToUpgrade; + private String customName = ""; + private int magicValue; + + /** + * No Id Constructor + */ + public Item(ItemBase itemBase, int ownerID, + OwnerType ownerType, byte chargesMax, byte chargesRemaining, + short durabilityCurrent, short durabilityMax, boolean canDestroy, + boolean rentable, Enum.ItemContainerType containerType, byte equipSlot, + ArrayList enchants, String name) { + super(); + this.itemBaseID = itemBase.getUUID(); + this.ownerID = ownerID; + this.ownerType = ownerType; + + if (itemBase.getType().getValue() == 20) { + this.chargesMax = chargesMax; + this.chargesRemaining = chargesRemaining; + } else { + this.chargesMax = (byte) itemBase.getNumCharges(); + this.chargesRemaining = (byte) itemBase.getNumCharges(); + } + + this.durabilityMax = (short) itemBase.getDurability(); + this.durabilityCurrent = (short) itemBase.getDurability(); + this.containerType = containerType; + this.canDestroy = canDestroy; + this.rentable = rentable; + this.equipSlot = equipSlot; + this.enchants = enchants; + this.flags = 1; this.value = this.magicValue; - this.customName = name; + this.customName = name; - loadEnchantments(); - bakeInStats(); - } + loadEnchantments(); + bakeInStats(); + } - public Item( ItemBase itemBase, int ownerID, - OwnerType ownerType, byte chargesMax, byte chargesRemaining, - short durabilityCurrent, short durabilityMax, boolean canDestroy, - boolean rentable, boolean inBank, boolean inVault, - boolean inInventory, boolean isEquipped, boolean isForge, byte equipSlot, - ArrayList enchants) { + public Item(ItemBase itemBase, int ownerID, + OwnerType ownerType, byte chargesMax, byte chargesRemaining, + short durabilityCurrent, short durabilityMax, boolean canDestroy, + boolean rentable, boolean inBank, boolean inVault, + boolean inInventory, boolean isEquipped, boolean isForge, byte equipSlot, + ArrayList enchants) { - super(); - this.itemBaseID = itemBase.getUUID(); - this.ownerID = ownerID; - this.ownerType = ownerType; + super(); + this.itemBaseID = itemBase.getUUID(); + this.ownerID = ownerID; + this.ownerType = ownerType; - this.chargesMax = (byte) itemBase.getNumCharges(); - this.chargesRemaining = (byte) itemBase.getNumCharges(); + this.chargesMax = (byte) itemBase.getNumCharges(); + this.chargesRemaining = (byte) itemBase.getNumCharges(); - this.durabilityMax = (short) itemBase.getDurability(); - this.durabilityCurrent = (short) itemBase.getDurability(); + this.durabilityMax = (short) itemBase.getDurability(); + this.durabilityCurrent = (short) itemBase.getDurability(); - this.canDestroy = canDestroy; - this.rentable = rentable; + this.canDestroy = canDestroy; + this.rentable = rentable; - this.equipSlot = equipSlot; - this.enchants = enchants; - this.flags = 1; + this.equipSlot = equipSlot; + this.enchants = enchants; + this.flags = 1; this.value = this.magicValue; - loadEnchantments(); - bakeInStats(); - } - - /** - * Normal Constructor - */ - public Item(ItemBase itemBase, int ownerID, - OwnerType ownerType, byte chargesMax, byte chargesRemaining, - short durabilityCurrent, short durabilityMax, boolean canDestroy, - boolean rentable, boolean inBank, boolean inVault, - boolean inInventory, boolean isEquipped, byte equipSlot, - ArrayList enchants, int newUUID) { - - super(newUUID); - this.itemBaseID = itemBase.getUUID(); - this.ownerID = ownerID; - this.ownerType = ownerType; - this.customName = ""; - - this.chargesMax = (byte) itemBase.getNumCharges(); - this.chargesRemaining = (byte) itemBase.getNumCharges(); - - this.durabilityMax = (short) itemBase.getDurability(); - this.durabilityCurrent = (short) itemBase.getDurability(); - this.canDestroy = canDestroy; - this.rentable = rentable; - this.equipSlot = equipSlot; - this.enchants = enchants; - this.flags = 1; + loadEnchantments(); + bakeInStats(); + } + + /** + * Normal Constructor + */ + public Item(ItemBase itemBase, int ownerID, + OwnerType ownerType, byte chargesMax, byte chargesRemaining, + short durabilityCurrent, short durabilityMax, boolean canDestroy, + boolean rentable, boolean inBank, boolean inVault, + boolean inInventory, boolean isEquipped, byte equipSlot, + ArrayList enchants, int newUUID) { + + super(newUUID); + this.itemBaseID = itemBase.getUUID(); + this.ownerID = ownerID; + this.ownerType = ownerType; + this.customName = ""; + + this.chargesMax = (byte) itemBase.getNumCharges(); + this.chargesRemaining = (byte) itemBase.getNumCharges(); + + this.durabilityMax = (short) itemBase.getDurability(); + this.durabilityCurrent = (short) itemBase.getDurability(); + this.canDestroy = canDestroy; + this.rentable = rentable; + this.equipSlot = equipSlot; + this.enchants = enchants; + this.flags = 1; this.value = this.magicValue; - loadEnchantments(); - bakeInStats(); - } - /** - * ResultSet Constructor - */ - public Item(ResultSet rs) throws SQLException { - super(rs); - - this.itemBaseID = rs.getInt("item_itemBaseID"); - - // Set container enumeration - - String container = rs.getString("item_container"); - - switch (container) { - case "inventory": - this.containerType = Enum.ItemContainerType.INVENTORY; - break; - case "bank": - this.containerType = Enum.ItemContainerType.BANK; - break; - case "vault": - this.containerType = Enum.ItemContainerType.VAULT; - break; - case "equip": - this.containerType = Enum.ItemContainerType.EQUIPPED; - break; - case "forge": - this.containerType = Enum.ItemContainerType.FORGE; - break; - case "warehouse": - this.containerType = Enum.ItemContainerType.FORGE; - break; - } - - this.ownerID = rs.getInt("parent"); - - if (this.getItemBase() != null) - this.chargesMax = (byte) this.getItemBase().getNumCharges(); - else - this.chargesMax = 0; - - this.chargesRemaining = rs.getByte("item_chargesRemaining"); - - this.durabilityCurrent = rs.getShort("item_durabilityCurrent"); - this.durabilityMax = rs.getShort("item_durabilityMax"); - - DbObjectType ownerType; - ownerType = DbManager.BuildingQueries.GET_UID_ENUM(this.ownerID); - - switch (ownerType) { - case CHARACTER: - this.ownerType = OwnerType.PlayerCharacter; - break; - case NPC: - this.ownerType = OwnerType.Npc; - break; - case ACCOUNT: - this.ownerType = OwnerType.Account; - break; - } - - this.canDestroy = true; - - this.equipSlot = rs.getByte("item_equipSlot"); - - this.numberOfItems = rs.getInt("item_numberOfItems"); - - this.flags = rs.getInt("item_flags"); - this.dateToUpgrade = rs.getLong("item_dateToUpgrade"); - this.value = rs.getInt("item_value"); - this.customName = rs.getString("item_name"); - - - } - - public String getCustomName() { - return customName; - } - - public void setName(String name) { - this.customName = name; - } - - public ItemBase getItemBase() { - return ItemBase.getItemBase(itemBaseID); - } - - public int getItemBaseID() { - return this.itemBaseID; - } - - public int getOwnerID() { - return ownerID; - } - - public OwnerType getOwnerType() { - return ownerType; - } - - public AbstractGameObject getOwner() { - if (this.ownerType == OwnerType.Npc) - return NPC.getFromCache(this.ownerID); - else if (this.ownerType == OwnerType.PlayerCharacter) - return PlayerCharacter.getFromCache(this.ownerID); - else if (this.ownerType == OwnerType.Mob) - return Mob.getFromCache(this.ownerID); - else if (this.ownerType == OwnerType.Account) - return DbManager.AccountQueries.GET_ACCOUNT(this.ownerID); - else - return null; - } - - //Only to be used for trading - public void setOwnerID(int ownerID) { - this.ownerID = ownerID; - } - - public boolean setOwner(AbstractGameObject owner) { - if (owner == null) - return false; - if (owner.getObjectType().equals(GameObjectType.NPC)) - this.ownerType = OwnerType.Npc; - else if (owner.getObjectType().equals(GameObjectType.PlayerCharacter)) - this.ownerType = OwnerType.PlayerCharacter; - else if (owner.getObjectType().equals(GameObjectType.Mob)) - this.ownerType = OwnerType.Mob; - else if (owner.getObjectType().equals(GameObjectType.Account)) - this.ownerType = OwnerType.Account; - else - return false; - this.ownerID = owner.getObjectUUID(); - return true; - } - - public boolean isOwnerNPC() { - return (ownerType == OwnerType.Npc); - } - - public boolean isOwnerCharacter() { - return (ownerType == OwnerType.PlayerCharacter); - } - - public boolean isOwnerAccount() { - return (ownerType == OwnerType.Account); - } - - public byte getChargesMax() { - return chargesMax; - } - - public byte getChargesRemaining() { - return chargesRemaining; - } - - public short getDurabilityCurrent() { - return durabilityCurrent; - } - - public short getDurabilityMax() {return durabilityMax;} - public void setDurabilityCurrent(short value) { - this.durabilityCurrent = value; - } - - public boolean isCanDestroy() { - return canDestroy; - } - - public boolean isRentable() { - return rentable; - } - - public byte getEquipSlot() { - return equipSlot; - } - - public ArrayList getEnchants() { - return enchants; - } - - public int getNumOfItems() { - return this.numberOfItems; - } - - public synchronized void setNumOfItems(int numberOfItems) { - this.numberOfItems = numberOfItems; - } - - public ConcurrentHashMap getBonuses() { - return this.bonuses; - } - - public void clearBonuses() { - this.bonuses.clear(); - } - - - public float getBonus(ModType modType, SourceType sourceType) { - - int amount = 0; - for (AbstractEffectModifier modifier: this.getBonuses().keySet()){ - if (modifier.getPercentMod() != 0) - continue; - if (modifier.modType.equals(modType) == false || modifier.sourceType.equals(sourceType)== false) - continue; - amount += this.bonuses.get(modifier); - } - return amount; - } - -public float getBonusPercent(ModType modType, SourceType sourceType) { - - int amount = 0; - for (AbstractEffectModifier modifier: this.getBonuses().keySet()){ - - if (modifier.getPercentMod() == 0) - continue; - if (modifier.modType.equals(modType) == false || modifier.sourceType.equals(sourceType)== false) - continue; - amount += this.bonuses.get(modifier); - } - return amount; - } - - public boolean isID() { - return ((this.flags & 1) > 0); - } - - public void setIsID(boolean value) { - if (value) - this.flags |= 1; - else - this.flags &= ~1; - } - - public void setIsComplete(boolean value) { - if (value) - this.flags |= 2; - else - this.flags &= ~2; - } - - public boolean isComplete() { - return this.dateToUpgrade < System.currentTimeMillis() + 1000; + loadEnchantments(); + bakeInStats(); } - public String getContainerInfo() { - String ret = "OwnerID: " + this.ownerID + ", container: "; - ret += this.containerType.toString(); - ret += "Equip Slot: " + this.equipSlot; - return ret; - } - - public int getFlags() { - return this.flags; - } - - public void setFlags(int value) { - this.flags = value; - } - - public void addBonus(AbstractEffectModifier key, float amount) { - if (this.bonuses.containsKey(key)) - this.bonuses.put(key, (this.bonuses.get(key) + amount)); - else - this.bonuses.put(key, amount); - } - - public void multBonus(AbstractEffectModifier key, float amount) { - if (this.bonuses.containsKey(key)) - this.bonuses.put(key, (this.bonuses.get(key) * amount)); - else - this.bonuses.put(key, amount); - } - - public synchronized void decrementChargesRemaining() { - this.chargesRemaining -= 1; - if (this.chargesRemaining < 0) - this.chargesRemaining = 0; - DbManager.ItemQueries.UPDATE_REMAINING_CHARGES(this); - } - - protected void validateItemContainer() { + /** + * ResultSet Constructor + */ + public Item(ResultSet rs) throws SQLException { + super(rs); + + this.itemBaseID = rs.getInt("item_itemBaseID"); + + // Set container enumeration + + String container = rs.getString("item_container"); + + switch (container) { + case "inventory": + this.containerType = Enum.ItemContainerType.INVENTORY; + break; + case "bank": + this.containerType = Enum.ItemContainerType.BANK; + break; + case "vault": + this.containerType = Enum.ItemContainerType.VAULT; + break; + case "equip": + this.containerType = Enum.ItemContainerType.EQUIPPED; + break; + case "forge": + this.containerType = Enum.ItemContainerType.FORGE; + break; + case "warehouse": + this.containerType = Enum.ItemContainerType.FORGE; + break; + } + + this.ownerID = rs.getInt("parent"); + + if (this.getItemBase() != null) + this.chargesMax = (byte) this.getItemBase().getNumCharges(); + else + this.chargesMax = 0; + + this.chargesRemaining = rs.getByte("item_chargesRemaining"); + + this.durabilityCurrent = rs.getShort("item_durabilityCurrent"); + this.durabilityMax = rs.getShort("item_durabilityMax"); + + DbObjectType ownerType; + ownerType = DbManager.BuildingQueries.GET_UID_ENUM(this.ownerID); + + switch (ownerType) { + case CHARACTER: + this.ownerType = OwnerType.PlayerCharacter; + break; + case NPC: + this.ownerType = OwnerType.Npc; + break; + case ACCOUNT: + this.ownerType = OwnerType.Account; + break; + } + + this.canDestroy = true; + + this.equipSlot = rs.getByte("item_equipSlot"); + + this.numberOfItems = rs.getInt("item_numberOfItems"); + + this.flags = rs.getInt("item_flags"); + this.dateToUpgrade = rs.getLong("item_dateToUpgrade"); + this.value = rs.getInt("item_value"); + this.customName = rs.getString("item_name"); - if (this.containerType == Enum.ItemContainerType.NONE) - if (this.ownerID != 0) - // Item has an owner, just somehow the flags got messed up. - // Default to bank. - // TODO NEED LOG EVENT HERE. - this.containerType = Enum.ItemContainerType.BANK; - else - // This item is on the ground. Nothing to worry about. - this.zeroItem(); - } - - // Removes all ownership of item and 'orphans' it. - protected synchronized void junk() { - - DbManager.ItemQueries.UPDATE_OWNER(this, 0, false, false, false, ItemContainerType.NONE, 0); - this.zeroItem(); - - //TODO do we want to delete the item here? - this.lastOwner = null; - //cleanup item from server. - this.removeFromCache(); - } - - public synchronized void zeroItem() { - this.ownerID = 0; - - this.ownerType = null; - this.containerType = Enum.ItemContainerType.NONE; - this.equipSlot = MBServerStatics.SLOT_UNEQUIPPED; - } - - protected synchronized boolean moveItemToInventory(PlayerCharacter pc) { - if (!DbManager.ItemQueries.UPDATE_OWNER(this, - pc.getObjectUUID(), //tableID - false, //isNPC - true, //isPlayer - false, //isAccount - ItemContainerType.INVENTORY, - 0)) //Slot - - return false; - - this.zeroItem(); - this.ownerID = pc.getObjectUUID(); - this.ownerType = OwnerType.PlayerCharacter; - this.containerType = ItemContainerType.INVENTORY; - return true; - } - - protected synchronized boolean moveItemToInventory(NPC npc) { - if (npc.isStatic()) { - if (!DbManager.ItemQueries.UPDATE_OWNER(this, 0, false, false, false,ItemContainerType.INVENTORY, 0)) - return false; - } else - if (!DbManager.ItemQueries.UPDATE_OWNER(this, - npc.getObjectUUID(), //UUID - true, //isNPC - false, //isPlayer - false, //isAccount - ItemContainerType.INVENTORY, - 0)) //Slot - - return false; - this.zeroItem(); - this.ownerID = npc.getObjectUUID(); - this.ownerType = OwnerType.Npc; - this.containerType = Enum.ItemContainerType.INVENTORY; - return true; - } - - protected synchronized boolean moveItemToInventory(Corpse corpse) { - if (!DbManager.ItemQueries.UPDATE_OWNER(this, - 0, //no ID for corpse - false, //isNPC - true, //isPlayer - false, //isAccount - ItemContainerType.INVENTORY, - 0)) //Slot - - return false; - this.zeroItem(); - this.ownerID = 0; - this.ownerType = null; - this.containerType = Enum.ItemContainerType.INVENTORY; - return true; - } - - protected synchronized boolean moveItemToBank(PlayerCharacter pc) { - if (!DbManager.ItemQueries.UPDATE_OWNER(this, - pc.getObjectUUID(), //UUID - false, //isNPC - true, //isPlayer - false, //isAccount - ItemContainerType.BANK, - 0)) //Slot - - return false; - this.zeroItem(); - this.ownerID = pc.getObjectUUID(); - this.ownerType = OwnerType.PlayerCharacter; - this.containerType = Enum.ItemContainerType.BANK; - return true; - } - - protected synchronized boolean moveItemToBank(NPC npc) { - if (!DbManager.ItemQueries.UPDATE_OWNER(this, - npc.getObjectUUID(), //UUID - true, //isNPC - false, //isPlayer - false, //isAccount - ItemContainerType.BANK, - 0)) //Slot - - return false; - this.zeroItem(); - this.ownerID = npc.getObjectUUID(); - this.ownerType = OwnerType.Npc; - this.containerType = Enum.ItemContainerType.BANK; - return true; - } - - protected synchronized boolean moveItemToVault(Account a) { - if (!DbManager.ItemQueries.UPDATE_OWNER(this, - a.getObjectUUID(), //UUID - false, //isNPC - false, //isPlayer - true, //isAccount - ItemContainerType.VAULT, - 0)) //Slot - - return false; - this.zeroItem(); - this.ownerID = a.getObjectUUID(); - this.ownerType = OwnerType.Account; - this.containerType = Enum.ItemContainerType.VAULT; - return true; - } - - protected synchronized boolean equipItem(PlayerCharacter pc, byte slot) { - - if (!DbManager.ItemQueries.UPDATE_OWNER(this, - pc.getObjectUUID(), //tableID - false, //isNPC - true, //isPlayer - false, //isAccount - ItemContainerType.EQUIPPED, - slot)) //Slot - - return false; - this.zeroItem(); - this.ownerID = pc.getObjectUUID(); - this.ownerType = OwnerType.PlayerCharacter; - this.containerType = Enum.ItemContainerType.EQUIPPED; - this.equipSlot = slot; - return true; - } - - protected synchronized boolean equipItem(NPC npc, byte slot) { - if (!DbManager.ItemQueries.UPDATE_OWNER(this, - npc.getObjectUUID(), //UUID - true, //isNPC - false, //isPlayer - false, //isAccount - ItemContainerType.EQUIPPED, - slot)) //Slot - - return false; - this.zeroItem(); - this.ownerID = npc.getObjectUUID(); - this.ownerType = OwnerType.Npc; - this.containerType = Enum.ItemContainerType.EQUIPPED; - this.equipSlot = slot; - return true; - } - - protected synchronized boolean equipItem(Mob npc, byte slot) { - - this.zeroItem(); - this.ownerID = npc.getObjectUUID(); - this.ownerType = OwnerType.Mob; - this.containerType = Enum.ItemContainerType.EQUIPPED; - this.equipSlot = slot; - return true; - } - - - public static void _serializeForClientMsg(Item item, ByteBufferWriter writer) - throws SerializationException { - Item._serializeForClientMsg(item, writer, true); - } - - public static void serializeForClientMsgWithoutSlot(Item item, ByteBufferWriter writer) { - Item._serializeForClientMsg(item, writer, false); - } - - public static void serializeForClientMsgForVendor(Item item, ByteBufferWriter writer, float percent) { - Item._serializeForClientMsg(item, writer, true); + } + + public static void _serializeForClientMsg(Item item, ByteBufferWriter writer) + throws SerializationException { + Item._serializeForClientMsg(item, writer, true); + } + + public static void serializeForClientMsgWithoutSlot(Item item, ByteBufferWriter writer) { + Item._serializeForClientMsg(item, writer, false); + } + + public static void serializeForClientMsgForVendor(Item item, ByteBufferWriter writer, float percent) { + Item._serializeForClientMsg(item, writer, true); int baseValue = item.magicValue; - writer.putInt(baseValue); - writer.putInt((int) (baseValue * percent)); - } - - public static void serializeForClientMsgForVendorWithoutSlot(Item item,ByteBufferWriter writer, float percent) { - Item._serializeForClientMsg(item, writer, false); - writer.putInt(item.getValue()); - writer.putInt(item.getValue()); - } - - public static void _serializeForClientMsg(Item item,ByteBufferWriter writer, - boolean includeSlot) { - if (includeSlot) - writer.putInt(item.equipSlot); - writer.putInt(0); // Pad - writer.putInt(item.getItemBase().getUUID()); - - writer.putInt(item.getObjectType().ordinal()); - writer.putInt(item.getObjectUUID()); - - // Unknown statics - for (int i = 0; i < 3; i++) { - writer.putInt(0); // Pad - } - for (int i = 0; i < 4; i++) { - writer.putInt(0x3F800000); // Static - } - for (int i = 0; i < 5; i++) { - writer.putInt(0); // Pad - } - for (int i = 0; i < 2; i++) { - writer.putInt(0xFFFFFFFF); // Static - } - - // Handle Hair / Beard / horns Color. - boolean isHair = (item.equipSlot == (byte) MBServerStatics.SLOT_HAIRSTYLE); - boolean isBeard = (item.equipSlot == (byte) MBServerStatics.SLOT_BEARDSTYLE); - int itemColor = 0; - if (isHair || isBeard) { + writer.putInt(baseValue); + writer.putInt((int) (baseValue * percent)); + } + + public static void serializeForClientMsgForVendorWithoutSlot(Item item, ByteBufferWriter writer, float percent) { + Item._serializeForClientMsg(item, writer, false); + writer.putInt(item.getValue()); + writer.putInt(item.getValue()); + } + + public static void _serializeForClientMsg(Item item, ByteBufferWriter writer, + boolean includeSlot) { + if (includeSlot) + writer.putInt(item.equipSlot); + writer.putInt(0); // Pad + writer.putInt(item.getItemBase().getUUID()); + + writer.putInt(item.getObjectType().ordinal()); + writer.putInt(item.getObjectUUID()); + + // Unknown statics + for (int i = 0; i < 3; i++) { + writer.putInt(0); // Pad + } + for (int i = 0; i < 4; i++) { + writer.putInt(0x3F800000); // Static + } + for (int i = 0; i < 5; i++) { + writer.putInt(0); // Pad + } + for (int i = 0; i < 2; i++) { + writer.putInt(0xFFFFFFFF); // Static + } + + // Handle Hair / Beard / horns Color. + boolean isHair = (item.equipSlot == (byte) MBServerStatics.SLOT_HAIRSTYLE); + boolean isBeard = (item.equipSlot == (byte) MBServerStatics.SLOT_BEARDSTYLE); + int itemColor = 0; + if (isHair || isBeard) { PlayerCharacter pc = PlayerCharacter.getFromCache(item.ownerID); - if (pc != null) - if (isHair) - itemColor = pc.getHairColor(); - else if (isBeard) - itemColor = pc.getBeardColor(); - } - writer.putInt(itemColor); - - writer.put((byte) 1); // End Datablock byte - if (item.customName.isEmpty() || item.customName.isEmpty()){ - writer.putInt(0); - } - - else - writer.putString(item.customName); // Unknown. pad? - writer.put((byte) 1); // End Datablock byte - - writer.putFloat((float)item.durabilityMax); - writer.putFloat((float)item.durabilityCurrent); - - writer.put((byte) 1); // End Datablock byte - - writer.putInt(0); // Pad - writer.putInt(0); // Pad - - if (item.getItemBase().equals(ItemBase.GOLD_ITEM_BASE)){ - - if (item.getOwner() != null && item.getOwner().getObjectType() == GameObjectType.PlayerCharacter){ - PlayerCharacter player = (PlayerCharacter)item.getOwner(); - int tradingAmount = player.getCharItemManager().getGoldTrading(); - writer.putInt(item.numberOfItems - tradingAmount); - }else - writer.putInt(item.numberOfItems); // Amount of gold - } - - else - writer.putInt(item.getItemBase().getBaseValue()); - - writer.putInt(item.getValue()); - - int effectsSize = item.effects.size(); - ArrayList effs = null; - Effect nextE = null; - if (effectsSize > 0 && item.isID()) { - effs = new ArrayList<>(item.effects.values()); - - //Don't send effects that have a token of 1 - Iterator efi = effs.iterator(); - while (efi.hasNext()) { - nextE = efi.next(); - if (nextE.getEffectToken() == 1 || nextE.bakedInStat()) - efi.remove(); - } - } else - effs = new ArrayList<>(); - - int effectsToSendSize = effs.size(); - writer.putInt(effectsToSendSize); - for (int i = 0; i < effectsToSendSize; i++) { - effs.get(i).serializeForItem(writer, item); - } - writer.putInt(0x00000000); - - - if (effectsSize > 0) - if (item.isID()) - writer.putInt(36); //Magical, blue name - else - writer.putInt(40); //Magical, unidentified - else if (item.getItemBase().getBakedInStats().size() > 0) - writer.putInt(36); //Magical, blue name - else - writer.putInt(4); //Non-Magical, grey name - writer.putInt(item.chargesRemaining); - writer.putInt(0); // Pad - writer.putInt(item.numberOfItems); - writer.put((byte)0); - - - if (item.getItemBase().getType().getValue() != 20){ - writer.putShort((short)0); - return; - } - writer.put((byte)1); // - writer.putInt(0); - writer.putInt(0); - if (item.chargesRemaining == 0) - writer.putInt(1); - else - writer.putInt(item.chargesRemaining); - writer.put((byte) 0); - } - - public static void SerializeTradingGold(PlayerCharacter player,ByteBufferWriter writer) { - - writer.putInt(0); // Pad - writer.putInt(7); - - writer.putInt(GameObjectType.Item.ordinal()); - writer.putInt(player.getObjectUUID()); - - // Unknown statics - for (int i = 0; i < 3; i++) { - writer.putInt(0); // Pad - } - for (int i = 0; i < 4; i++) { - writer.putInt(0x3F800000); // Static - } - for (int i = 0; i < 5; i++) { - writer.putInt(0); // Pad - } - for (int i = 0; i < 2; i++) { - writer.putInt(0xFFFFFFFF); // Static - } - - // Handle Hair / Beard / horns Color. - - int itemColor = 0; - writer.putInt(itemColor); - - writer.put((byte) 1); // End Datablock byte - writer.putInt(0); - writer.put((byte) 1); // End Datablock byte - - writer.putFloat((float)1); - writer.putFloat((float)1); - - writer.put((byte) 1); // End Datablock byte - - writer.putInt(0); // Pad - writer.putInt(0); // Pad - - - writer.putInt(player.getCharItemManager().getGoldTrading()); // Amount of gold - - - writer.putInt(0); - - - writer.putInt(0); - - writer.putInt(0x00000000); - - writer.putInt(4); //Non-Magical, grey name - writer.putInt(1); - writer.putInt(0); // Pad - writer.putInt(player.getCharItemManager().getGoldTrading()); - writer.put((byte)0); - - writer.putShort((short)0); - - } - - public static boolean MakeItemForPlayer(ItemBase toCreate, PlayerCharacter reciever, int amount) { - - boolean itemWorked = false; - - Item item = new Item( toCreate, reciever.getObjectUUID(), OwnerType.PlayerCharacter, (byte) 0, (byte) 0, - (short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, - new ArrayList<>(),""); - - synchronized (item) { - item.numberOfItems = amount; - } - item.containerType = Enum.ItemContainerType.INVENTORY; - - try { - item = DbManager.ItemQueries.ADD_ITEM(item); - itemWorked = true; - } catch (Exception e) { - Logger.error(e); - } - - if (!itemWorked) - return false; - - reciever.getCharItemManager().addItemToInventory(item); - reciever.getCharItemManager().updateInventory(); - - return true; - } - - public static Item deserializeFromClientMsg(ByteBufferReader reader, - boolean includeSlot) { - if (includeSlot) - reader.getInt(); - reader.getInt(); - int itemBase = reader.getInt(); //itemBase - int objectType = reader.getInt(); //object type; - int UUID = reader.getInt(); - for (int i = 0; i < 14; i++) { - reader.getInt(); // Pads and statics - } - int unknown = reader.getInt(); - - byte readString = reader.get(); - if (readString == 1) - reader.getString(); - byte readDurability = reader.get(); - if (readDurability == 1){ - reader.getInt(); - reader.getInt(); - } - - byte readEnchants = reader.get(); - if (readEnchants == 1){ - reader.getInt(); - reader.getInt(); - reader.getInt(); - reader.getInt(); - int enchantSize = reader.getInt(); - for (int i = 0; i < enchantSize; i++) { - reader.getInt(); //effect token - reader.getInt(); //trains - int type = reader.getInt(); - reader.get(); - if (type == 1) - reader.getLong(); //item comp - else - reader.getInt(); //power token - reader.getString(); //name - reader.getFloat(); //duration - } - for (int i = 0; i < 5; i++) { - reader.getInt(); - } - } - - reader.get(); - byte isContract = reader.get(); - if (isContract == 1){ - reader.getInt(); - reader.getInt(); - reader.getInt(); - } - reader.get(); - - if (UUID == 0 || objectType == 0) - return null; - if (objectType == GameObjectType.MobLoot.ordinal()) - return MobLoot.getFromCache(UUID); - return Item.getFromCache(UUID); - } - - public final int getMagicValue() { - return this.magicValue; - } - - public int getBaseValue() { - if (this.getItemBase() != null) - return this.getItemBase().getBaseValue(); - return 0; - } - - public static void putListForVendor(ByteBufferWriter writer, ArrayList list, NPC vendor) { - putList(writer, list, false, vendor.getObjectUUID(), true, vendor); - } - - public static void putList(ByteBufferWriter writer, ArrayList list, boolean includeSlot, int ownerID) { - putList(writer, list, includeSlot, ownerID, false, null); - } - - private static void putList(ByteBufferWriter writer, ArrayList list, boolean includeSlot, int ownerID, boolean forVendor, NPC vendor) { - int indexPosition = writer.position(); - //reserve 4 bytes for index. - writer.putInt(0); - - int serialized = 0; - for (Item item : list) { + if (pc != null) + if (isHair) + itemColor = pc.getHairColor(); + else if (isBeard) + itemColor = pc.getBeardColor(); + } + writer.putInt(itemColor); + + writer.put((byte) 1); // End Datablock byte + if (item.customName.isEmpty() || item.customName.isEmpty()) { + writer.putInt(0); + } else + writer.putString(item.customName); // Unknown. pad? + writer.put((byte) 1); // End Datablock byte + + writer.putFloat((float) item.durabilityMax); + writer.putFloat((float) item.durabilityCurrent); + + writer.put((byte) 1); // End Datablock byte + + writer.putInt(0); // Pad + writer.putInt(0); // Pad + + if (item.getItemBase().equals(ItemBase.GOLD_ITEM_BASE)) { + + if (item.getOwner() != null && item.getOwner().getObjectType() == GameObjectType.PlayerCharacter) { + PlayerCharacter player = (PlayerCharacter) item.getOwner(); + int tradingAmount = player.getCharItemManager().getGoldTrading(); + writer.putInt(item.numberOfItems - tradingAmount); + } else + writer.putInt(item.numberOfItems); // Amount of gold + } else + writer.putInt(item.getItemBase().getBaseValue()); + + writer.putInt(item.getValue()); + + int effectsSize = item.effects.size(); + ArrayList effs = null; + Effect nextE = null; + if (effectsSize > 0 && item.isID()) { + effs = new ArrayList<>(item.effects.values()); + + //Don't send effects that have a token of 1 + Iterator efi = effs.iterator(); + while (efi.hasNext()) { + nextE = efi.next(); + if (nextE.getEffectToken() == 1 || nextE.bakedInStat()) + efi.remove(); + } + } else + effs = new ArrayList<>(); + + int effectsToSendSize = effs.size(); + writer.putInt(effectsToSendSize); + for (int i = 0; i < effectsToSendSize; i++) { + effs.get(i).serializeForItem(writer, item); + } + writer.putInt(0x00000000); + + + if (effectsSize > 0) + if (item.isID()) + writer.putInt(36); //Magical, blue name + else + writer.putInt(40); //Magical, unidentified + else if (item.getItemBase().getBakedInStats().size() > 0) + writer.putInt(36); //Magical, blue name + else + writer.putInt(4); //Non-Magical, grey name + writer.putInt(item.chargesRemaining); + writer.putInt(0); // Pad + writer.putInt(item.numberOfItems); + writer.put((byte) 0); + + + if (item.getItemBase().getType().getValue() != 20) { + writer.putShort((short) 0); + return; + } + writer.put((byte) 1); // + writer.putInt(0); + writer.putInt(0); + if (item.chargesRemaining == 0) + writer.putInt(1); + else + writer.putInt(item.chargesRemaining); + writer.put((byte) 0); + } + + public static void SerializeTradingGold(PlayerCharacter player, ByteBufferWriter writer) { + + writer.putInt(0); // Pad + writer.putInt(7); + + writer.putInt(GameObjectType.Item.ordinal()); + writer.putInt(player.getObjectUUID()); + + // Unknown statics + for (int i = 0; i < 3; i++) { + writer.putInt(0); // Pad + } + for (int i = 0; i < 4; i++) { + writer.putInt(0x3F800000); // Static + } + for (int i = 0; i < 5; i++) { + writer.putInt(0); // Pad + } + for (int i = 0; i < 2; i++) { + writer.putInt(0xFFFFFFFF); // Static + } + + // Handle Hair / Beard / horns Color. + + int itemColor = 0; + writer.putInt(itemColor); + + writer.put((byte) 1); // End Datablock byte + writer.putInt(0); + writer.put((byte) 1); // End Datablock byte + + writer.putFloat((float) 1); + writer.putFloat((float) 1); + + writer.put((byte) 1); // End Datablock byte + + writer.putInt(0); // Pad + writer.putInt(0); // Pad + + + writer.putInt(player.getCharItemManager().getGoldTrading()); // Amount of gold + + + writer.putInt(0); + + + writer.putInt(0); + + writer.putInt(0x00000000); + + writer.putInt(4); //Non-Magical, grey name + writer.putInt(1); + writer.putInt(0); // Pad + writer.putInt(player.getCharItemManager().getGoldTrading()); + writer.put((byte) 0); + + writer.putShort((short) 0); + + } + + public static boolean MakeItemForPlayer(ItemBase toCreate, PlayerCharacter reciever, int amount) { + + boolean itemWorked = false; + + Item item = new Item(toCreate, reciever.getObjectUUID(), OwnerType.PlayerCharacter, (byte) 0, (byte) 0, + (short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, + new ArrayList<>(), ""); + + synchronized (item) { + item.numberOfItems = amount; + } + item.containerType = Enum.ItemContainerType.INVENTORY; + + try { + item = DbManager.ItemQueries.ADD_ITEM(item); + itemWorked = true; + } catch (Exception e) { + Logger.error(e); + } + + if (!itemWorked) + return false; + + reciever.getCharItemManager().addItemToInventory(item); + reciever.getCharItemManager().updateInventory(); + + return true; + } + + public static Item deserializeFromClientMsg(ByteBufferReader reader, + boolean includeSlot) { + if (includeSlot) + reader.getInt(); + reader.getInt(); + int itemBase = reader.getInt(); //itemBase + int objectType = reader.getInt(); //object type; + int UUID = reader.getInt(); + for (int i = 0; i < 14; i++) { + reader.getInt(); // Pads and statics + } + int unknown = reader.getInt(); + + byte readString = reader.get(); + if (readString == 1) + reader.getString(); + byte readDurability = reader.get(); + if (readDurability == 1) { + reader.getInt(); + reader.getInt(); + } + + byte readEnchants = reader.get(); + if (readEnchants == 1) { + reader.getInt(); + reader.getInt(); + reader.getInt(); + reader.getInt(); + int enchantSize = reader.getInt(); + for (int i = 0; i < enchantSize; i++) { + reader.getInt(); //effect token + reader.getInt(); //trains + int type = reader.getInt(); + reader.get(); + if (type == 1) + reader.getLong(); //item comp + else + reader.getInt(); //power token + reader.getString(); //name + reader.getFloat(); //duration + } + for (int i = 0; i < 5; i++) { + reader.getInt(); + } + } + + reader.get(); + byte isContract = reader.get(); + if (isContract == 1) { + reader.getInt(); + reader.getInt(); + reader.getInt(); + } + reader.get(); + + if (UUID == 0 || objectType == 0) + return null; + if (objectType == GameObjectType.MobLoot.ordinal()) + return MobLoot.getFromCache(UUID); + return Item.getFromCache(UUID); + } + + public static void putListForVendor(ByteBufferWriter writer, ArrayList list, NPC vendor) { + putList(writer, list, false, vendor.getObjectUUID(), true, vendor); + } + + public static void putList(ByteBufferWriter writer, ArrayList list, boolean includeSlot, int ownerID) { + putList(writer, list, includeSlot, ownerID, false, null); + } + + private static void putList(ByteBufferWriter writer, ArrayList list, boolean includeSlot, int ownerID, boolean forVendor, NPC vendor) { + int indexPosition = writer.position(); + //reserve 4 bytes for index. + writer.putInt(0); + + int serialized = 0; + for (Item item : list) { if (item.getItemBase().getType().equals(ItemType.GOLD)) - if (item.numberOfItems == 0) - continue; - try { - if (includeSlot && !forVendor) - Item._serializeForClientMsg(item,writer); - else if (!includeSlot && !forVendor) - Item.serializeForClientMsgWithoutSlot(item,writer); + if (item.numberOfItems == 0) + continue; + try { + if (includeSlot && !forVendor) + Item._serializeForClientMsg(item, writer); + else if (!includeSlot && !forVendor) + Item.serializeForClientMsgWithoutSlot(item, writer); - if (!includeSlot && forVendor) //TODO separate for sell/buy percent + if (!includeSlot && forVendor) //TODO separate for sell/buy percent - Item.serializeForClientMsgForVendorWithoutSlot(item,writer, vendor.getSellPercent()); + Item.serializeForClientMsgForVendorWithoutSlot(item, writer, vendor.getSellPercent()); - if (includeSlot && forVendor) //TODO separate for sell/buy percent + if (includeSlot && forVendor) //TODO separate for sell/buy percent - Item.serializeForClientMsgForVendor(item,writer, vendor.getSellPercent()); + Item.serializeForClientMsgForVendor(item, writer, vendor.getSellPercent()); - } catch (SerializationException se) { - continue; - } - ++serialized; - } + } catch (SerializationException se) { + continue; + } + ++serialized; + } + + writer.putIntAt(serialized, indexPosition); + } - writer.putIntAt(serialized, indexPosition); - } - - public static void putTradingList(PlayerCharacter player, ByteBufferWriter writer, ArrayList list, boolean includeSlot, int ownerID, boolean forVendor, NPC vendor) { - int indexPosition = writer.position(); - //reserve 4 bytes for index. - writer.putInt(0); + public static void putTradingList(PlayerCharacter player, ByteBufferWriter writer, ArrayList list, boolean includeSlot, int ownerID, boolean forVendor, NPC vendor) { + int indexPosition = writer.position(); + //reserve 4 bytes for index. + writer.putInt(0); - int serialized = 0; - for (Item item : list) { + int serialized = 0; + for (Item item : list) { if (item.getItemBase().getType().equals(ItemType.GOLD)) - if (item.numberOfItems == 0) - continue; - try { - if (includeSlot && !forVendor) - Item._serializeForClientMsg(item,writer); - else if (!includeSlot && !forVendor) - Item.serializeForClientMsgWithoutSlot(item,writer); - - if (!includeSlot && forVendor) //TODO separate for sell/buy percent + if (item.numberOfItems == 0) + continue; + try { + if (includeSlot && !forVendor) + Item._serializeForClientMsg(item, writer); + else if (!includeSlot && !forVendor) + Item.serializeForClientMsgWithoutSlot(item, writer); + + if (!includeSlot && forVendor) //TODO separate for sell/buy percent + + Item.serializeForClientMsgForVendorWithoutSlot(item, writer, vendor.getSellPercent()); + + if (includeSlot && forVendor) //TODO separate for sell/buy percent + + Item.serializeForClientMsgForVendor(item, writer, vendor.getSellPercent()); + + } catch (SerializationException se) { + continue; + } + ++serialized; + } + if (player.getCharItemManager().getGoldTrading() > 0) { + Item.SerializeTradingGold(player, writer); + ++serialized; + } + + + writer.putIntAt(serialized, indexPosition); + } + + public static Item createItemForPlayer(PlayerCharacter pc, ItemBase ib) { + Item item = null; + byte charges = 0; + + charges = (byte) ib.getNumCharges(); + + short durability = (short) ib.getDurability(); + + Item temp = new Item(ib, pc.getObjectUUID(), + OwnerType.PlayerCharacter, charges, charges, durability, durability, + true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, + new ArrayList<>(), ""); + try { + item = DbManager.ItemQueries.ADD_ITEM(temp); + } catch (Exception e) { + Logger.error(e); + } + return item; + } + + public static Item createItemForPlayerBank(PlayerCharacter pc, ItemBase ib) { + Item item = null; + byte charges = 0; - Item.serializeForClientMsgForVendorWithoutSlot(item,writer, vendor.getSellPercent()); - - if (includeSlot && forVendor) //TODO separate for sell/buy percent - - Item.serializeForClientMsgForVendor(item,writer, vendor.getSellPercent()); - - } catch (SerializationException se) { - continue; - } - ++serialized; - } - if (player.getCharItemManager().getGoldTrading() > 0){ - Item.SerializeTradingGold(player, writer); - ++serialized; - } - - - writer.putIntAt(serialized, indexPosition); - } - - public AbstractWorldObject getLastOwner() { - return this.lastOwner; - } - - public void setLastOwner(AbstractWorldObject value) { - this.lastOwner = value; - } - - - @Override - public String getName() { - if (this.customName.isEmpty()) - if (this.getItemBase() != null) - return this.getItemBase().getName(); - return this.customName; - } - - - - private void bakeInStats() { - - EffectsBase effect; - - if (ConfigManager.serverType.equals(Enum.ServerType.LOGINSERVER)) - return; - - if (this.getItemBase() != null) - - for (Integer token : this.getItemBase().getBakedInStats().keySet()) { - - effect = PowersManager.getEffectByToken(token); - - if (effect == null) { - Logger.error("missing effect of token " + token); - continue; - } - AbstractPowerAction apa = PowersManager.getPowerActionByIDString(effect.getIDString()); - apa.applyBakedInStatsForItem(this, this.getItemBase().getBakedInStats().get(token)); - } - } - - public final void loadEnchantments() { - //dont load mobloot enchantments, they arent in db. - if (this.getObjectType().equals(GameObjectType.MobLoot)){ - this.magicValue = this.getItemBase().getBaseValue() + calcMagicValue(); - return; - } - - ConcurrentHashMap enchantList = DbManager.EnchantmentQueries.GET_ENCHANTMENTS_FOR_ITEM(this.getObjectUUID()); - - for (String enchant : enchantList.keySet()) { - AbstractPowerAction apa = PowersManager.getPowerActionByIDString(enchant); - if (apa != null) { - apa.applyEffectForItem(this, enchantList.get(enchant)); - this.effectNames.add(enchant); - } - } - - this.magicValue = this.getItemBase().getBaseValue() + calcMagicValue(); - } - - public HashMap getBakedInStats() { - if (this.getItemBase() != null) - return this.getItemBase().getBakedInStats(); - return null; - } - - public void clearEnchantments() { - - //Clear permanent enchantment out of database - DbManager.EnchantmentQueries.CLEAR_ENCHANTMENTS((long) this.getObjectUUID()); - - for (String name : this.getEffects().keySet()) { - Effect eff = this.getEffects().get(name); - if (!eff.bakedInStat()) - this.endEffect(name); - } - this.effectNames.clear(); - } - - public void addPermanentEnchantment(String enchantID, int rank) { - AbstractPowerAction apa = PowersManager.getPowerActionByIDString(enchantID); - if (apa == null) - return; - - DbManager.EnchantmentQueries.CREATE_ENCHANTMENT_FOR_ITEM((long) this.getObjectUUID(), enchantID, rank); - apa.applyEffectForItem(this, rank); - this.effectNames.add(enchantID); - } - - public void addPermanentEnchantmentForDev(String enchantID, int rank) { - AbstractPowerAction apa = PowersManager.getPowerActionByIDString(enchantID); - if (apa == null) - return; - - DbManager.EnchantmentQueries.CREATE_ENCHANTMENT_FOR_ITEM((long) this.getObjectUUID(), enchantID, rank); - apa.applyEffectForItem(this, rank); - this.effectNames.add(enchantID); - } - - protected int calcMagicValue() { - int ret = 0; - for (String enchant : this.effectNames) { - ret += Item.getEnchantValue(enchant+ 'A'); - } - return ret; - } - - public static Item createItemForPlayer(PlayerCharacter pc, ItemBase ib) { - Item item = null; - byte charges = 0; - - charges = (byte) ib.getNumCharges(); - - short durability = (short) ib.getDurability(); - - Item temp = new Item( ib, pc.getObjectUUID(), - OwnerType.PlayerCharacter, charges, charges, durability, durability, - true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, - new ArrayList<>(),""); - try { - item = DbManager.ItemQueries.ADD_ITEM(temp); - } catch (Exception e) { - Logger.error(e); - } - return item; - } - - public static Item createItemForPlayerBank(PlayerCharacter pc, ItemBase ib) { - Item item = null; - byte charges = 0; - - charges = (byte) ib.getNumCharges(); - - short durability = (short) ib.getDurability(); - - Item temp = new Item( ib, pc.getObjectUUID(), - OwnerType.PlayerCharacter, charges, charges, durability, durability, - true, false, Enum.ItemContainerType.BANK, (byte) 0, - new ArrayList<>(),""); - try { - item = DbManager.ItemQueries.ADD_ITEM(temp); - } catch (Exception e) { - } - return item; - } - - public static Item createItemForMob(Mob mob, ItemBase ib) { - Item item = null; - byte charges = 0; - - charges = (byte) ib.getNumCharges(); - short durability = (short) ib.getDurability(); - - Item temp = new Item( ib, mob.getObjectUUID(), - OwnerType.Mob, charges, charges, durability, durability, - true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, - new ArrayList<>(),""); - try { - item = DbManager.ItemQueries.ADD_ITEM(temp); - } catch (Exception e) { - Logger.error(e); - } - return item; - } - - public static Item getFromCache(int id) { - return (Item) DbManager.getFromCache(GameObjectType.Item, id); - } - - - - public void addToCache() { - DbManager.addToCache(this); - } - - public static Item newGoldItem(AbstractWorldObject awo, ItemBase ib, Enum.ItemContainerType containerType) { - return newGoldItem(awo, ib, containerType, true); - } - - //used for vault! - public static Item newGoldItem(int accountID,ItemBase ib, Enum.ItemContainerType containerType) { - return newGoldItem(accountID, ib, containerType, true); - } - - private static Item newGoldItem(int accountID, ItemBase ib, Enum.ItemContainerType containerType, boolean persist) { - - int ownerID; - OwnerType ownerType; - - ownerID = accountID; - ownerType = OwnerType.Account; - - - Item newGold = new Item( ib, ownerID, ownerType, - (byte) 0, (byte) 0, (short) 0, (short) 0, true, false, containerType, (byte) 0, - new ArrayList<>(),""); - - synchronized (newGold) { - newGold.numberOfItems = 0; - } - - if (persist) { - try { - newGold = DbManager.ItemQueries.ADD_ITEM(newGold); - if (newGold != null) { - synchronized (newGold) { - newGold.numberOfItems = 0; - } - } - } catch (Exception e) { - Logger.error(e); - } - DbManager.ItemQueries.ZERO_ITEM_STACK(newGold); - } - - return newGold; - } - - private static Item newGoldItem(AbstractWorldObject awo, ItemBase ib, Enum.ItemContainerType containerType,boolean persist) { - - int ownerID; - OwnerType ownerType; - - if (awo.getObjectType().equals(GameObjectType.Mob)) - return null; - - if (containerType == Enum.ItemContainerType.VAULT) { - if (!(awo.getObjectType().equals(GameObjectType.PlayerCharacter))) { - Logger.error("AWO is not a PlayerCharacter"); - return null; - } - ownerID = ((PlayerCharacter) awo).getAccount().getObjectUUID(); - ownerType = OwnerType.Account; - } else { - - ownerID = awo.getObjectUUID(); - - switch (awo.getObjectType()) { - - case NPC: - ownerType = OwnerType.Npc; - break; - case PlayerCharacter: - ownerType = OwnerType.PlayerCharacter; - break; - case Mob: - ownerType = OwnerType.Mob; - break; - default: - Logger.error("Unsupported AWO object type."); - return null; - } - } - - Item newGold = new Item( ib, ownerID, ownerType, - (byte) 0, (byte) 0, (short) 0, (short) 0, true, false, containerType, (byte) 0, - new ArrayList<>(),""); - - synchronized (newGold) { - newGold.numberOfItems = 0; - } - - if (persist) { - try { - newGold = DbManager.ItemQueries.ADD_ITEM(newGold); - if (newGold != null) { - synchronized (newGold) { - newGold.numberOfItems = 0; - } - } - } catch (Exception e) { - Logger.error(e); - } - DbManager.ItemQueries.ZERO_ITEM_STACK(newGold); - } - newGold.containerType = containerType; - - return newGold; - } - - // This is to be used for trades - the new item is not stored in the database - public static Item newGoldItemTemp(AbstractWorldObject awo, ItemBase ib) { - return Item.newGoldItem(awo, ib, Enum.ItemContainerType.NONE,false); - } - - public static Item getItem(int UUID) { - if (UUID == 0) - return null; - - Item item = (Item) DbManager.getFromCache(GameObjectType.Item, UUID); - if (item != null) - return item; - return DbManager.ItemQueries.GET_ITEM(UUID); - } - - @Override - public void updateDatabase() { - //DbManager.ItemQueries.updateDatabase(this); - } - - public static void addEnchantValue(String enchant, int value) { - Item.enchantValues.put(enchant, value); - } - - public static int getEnchantValue(String enchant) { - if (Item.enchantValues.containsKey(enchant)) - return Item.enchantValues.get(enchant); - return 0; - } - - @Override - public void runAfterLoad() { - loadEnchantments(); - bakeInStats(); - } - - - public ArrayList getEffectNames() { - return effectNames; - } - - public boolean validForItem(long flags) { - if (this.getItemBase() == null) - return false; - return this.getItemBase().validSlotFlag(flags); - } - - public boolean validForInventory(ClientConnection origin, PlayerCharacter pc, CharacterItemManager charItemMan) { - - if (origin == null || pc == null || charItemMan == null) - return false; + charges = (byte) ib.getNumCharges(); + + short durability = (short) ib.getDurability(); + + Item temp = new Item(ib, pc.getObjectUUID(), + OwnerType.PlayerCharacter, charges, charges, durability, durability, + true, false, Enum.ItemContainerType.BANK, (byte) 0, + new ArrayList<>(), ""); + try { + item = DbManager.ItemQueries.ADD_ITEM(temp); + } catch (Exception e) { + } + return item; + } + + public static Item createItemForMob(Mob mob, ItemBase ib) { + Item item = null; + byte charges = 0; + + charges = (byte) ib.getNumCharges(); + short durability = (short) ib.getDurability(); + + Item temp = new Item(ib, mob.getObjectUUID(), + OwnerType.Mob, charges, charges, durability, durability, + true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, + new ArrayList<>(), ""); + try { + item = DbManager.ItemQueries.ADD_ITEM(temp); + } catch (Exception e) { + Logger.error(e); + } + return item; + } + + public static Item getFromCache(int id) { + return (Item) DbManager.getFromCache(GameObjectType.Item, id); + } + + public static Item newGoldItem(AbstractWorldObject awo, ItemBase ib, Enum.ItemContainerType containerType) { + return newGoldItem(awo, ib, containerType, true); + } + + //used for vault! + public static Item newGoldItem(int accountID, ItemBase ib, Enum.ItemContainerType containerType) { + return newGoldItem(accountID, ib, containerType, true); + } + + private static Item newGoldItem(int accountID, ItemBase ib, Enum.ItemContainerType containerType, boolean persist) { + + int ownerID; + OwnerType ownerType; + + ownerID = accountID; + ownerType = OwnerType.Account; + + + Item newGold = new Item(ib, ownerID, ownerType, + (byte) 0, (byte) 0, (short) 0, (short) 0, true, false, containerType, (byte) 0, + new ArrayList<>(), ""); + + synchronized (newGold) { + newGold.numberOfItems = 0; + } + + if (persist) { + try { + newGold = DbManager.ItemQueries.ADD_ITEM(newGold); + if (newGold != null) { + synchronized (newGold) { + newGold.numberOfItems = 0; + } + } + } catch (Exception e) { + Logger.error(e); + } + DbManager.ItemQueries.ZERO_ITEM_STACK(newGold); + } + + return newGold; + } + + private static Item newGoldItem(AbstractWorldObject awo, ItemBase ib, Enum.ItemContainerType containerType, boolean persist) { + + int ownerID; + OwnerType ownerType; + + if (awo.getObjectType().equals(GameObjectType.Mob)) + return null; + + if (containerType == Enum.ItemContainerType.VAULT) { + if (!(awo.getObjectType().equals(GameObjectType.PlayerCharacter))) { + Logger.error("AWO is not a PlayerCharacter"); + return null; + } + ownerID = ((PlayerCharacter) awo).getAccount().getObjectUUID(); + ownerType = OwnerType.Account; + } else { + + ownerID = awo.getObjectUUID(); + + switch (awo.getObjectType()) { + + case NPC: + ownerType = OwnerType.Npc; + break; + case PlayerCharacter: + ownerType = OwnerType.PlayerCharacter; + break; + case Mob: + ownerType = OwnerType.Mob; + break; + default: + Logger.error("Unsupported AWO object type."); + return null; + } + } + + Item newGold = new Item(ib, ownerID, ownerType, + (byte) 0, (byte) 0, (short) 0, (short) 0, true, false, containerType, (byte) 0, + new ArrayList<>(), ""); + + synchronized (newGold) { + newGold.numberOfItems = 0; + } + + if (persist) { + try { + newGold = DbManager.ItemQueries.ADD_ITEM(newGold); + if (newGold != null) { + synchronized (newGold) { + newGold.numberOfItems = 0; + } + } + } catch (Exception e) { + Logger.error(e); + } + DbManager.ItemQueries.ZERO_ITEM_STACK(newGold); + } + newGold.containerType = containerType; + + return newGold; + } + + // This is to be used for trades - the new item is not stored in the database + public static Item newGoldItemTemp(AbstractWorldObject awo, ItemBase ib) { + return Item.newGoldItem(awo, ib, Enum.ItemContainerType.NONE, false); + } + + public static Item getItem(int UUID) { + if (UUID == 0) + return null; + + Item item = (Item) DbManager.getFromCache(GameObjectType.Item, UUID); + if (item != null) + return item; + return DbManager.ItemQueries.GET_ITEM(UUID); + } + + public static void addEnchantValue(String enchant, int value) { + Item.enchantValues.put(enchant, value); + } + + public static int getEnchantValue(String enchant) { + if (Item.enchantValues.containsKey(enchant)) + return Item.enchantValues.get(enchant); + return 0; + } + + public String getCustomName() { + return customName; + } + + public ItemBase getItemBase() { + return ItemBase.getItemBase(itemBaseID); + } + + public int getItemBaseID() { + return this.itemBaseID; + } + + public int getOwnerID() { + return ownerID; + } + + //Only to be used for trading + public void setOwnerID(int ownerID) { + this.ownerID = ownerID; + } + + public OwnerType getOwnerType() { + return ownerType; + } + + public AbstractGameObject getOwner() { + if (this.ownerType == OwnerType.Npc) + return NPC.getFromCache(this.ownerID); + else if (this.ownerType == OwnerType.PlayerCharacter) + return PlayerCharacter.getFromCache(this.ownerID); + else if (this.ownerType == OwnerType.Mob) + return Mob.getFromCache(this.ownerID); + else if (this.ownerType == OwnerType.Account) + return DbManager.AccountQueries.GET_ACCOUNT(this.ownerID); + else + return null; + } + + public boolean setOwner(AbstractGameObject owner) { + if (owner == null) + return false; + if (owner.getObjectType().equals(GameObjectType.NPC)) + this.ownerType = OwnerType.Npc; + else if (owner.getObjectType().equals(GameObjectType.PlayerCharacter)) + this.ownerType = OwnerType.PlayerCharacter; + else if (owner.getObjectType().equals(GameObjectType.Mob)) + this.ownerType = OwnerType.Mob; + else if (owner.getObjectType().equals(GameObjectType.Account)) + this.ownerType = OwnerType.Account; + else + return false; + this.ownerID = owner.getObjectUUID(); + return true; + } + + public boolean isOwnerNPC() { + return (ownerType == OwnerType.Npc); + } + + public boolean isOwnerCharacter() { + return (ownerType == OwnerType.PlayerCharacter); + } + + public boolean isOwnerAccount() { + return (ownerType == OwnerType.Account); + } + + public byte getChargesMax() { + return chargesMax; + } + + public byte getChargesRemaining() { + return chargesRemaining; + } + + public short getDurabilityCurrent() { + return durabilityCurrent; + } + + public void setDurabilityCurrent(short value) { + this.durabilityCurrent = value; + } + + public short getDurabilityMax() { + return durabilityMax; + } + + public boolean isCanDestroy() { + return canDestroy; + } + + public boolean isRentable() { + return rentable; + } + + public byte getEquipSlot() { + return equipSlot; + } + + public ArrayList getEnchants() { + return enchants; + } + + public int getNumOfItems() { + return this.numberOfItems; + } + + public synchronized void setNumOfItems(int numberOfItems) { + this.numberOfItems = numberOfItems; + } + + public ConcurrentHashMap getBonuses() { + return this.bonuses; + } + + public void clearBonuses() { + this.bonuses.clear(); + } + + public float getBonus(ModType modType, SourceType sourceType) { + + int amount = 0; + for (AbstractEffectModifier modifier : this.getBonuses().keySet()) { + if (modifier.getPercentMod() != 0) + continue; + if (modifier.modType.equals(modType) == false || modifier.sourceType.equals(sourceType) == false) + continue; + amount += this.bonuses.get(modifier); + } + return amount; + } + + public float getBonusPercent(ModType modType, SourceType sourceType) { + + int amount = 0; + for (AbstractEffectModifier modifier : this.getBonuses().keySet()) { + + if (modifier.getPercentMod() == 0) + continue; + if (modifier.modType.equals(modType) == false || modifier.sourceType.equals(sourceType) == false) + continue; + amount += this.bonuses.get(modifier); + } + return amount; + } + + public boolean isID() { + return ((this.flags & 1) > 0); + } + + public void setIsID(boolean value) { + if (value) + this.flags |= 1; + else + this.flags &= ~1; + } + + public void setIsComplete(boolean value) { + if (value) + this.flags |= 2; + else + this.flags &= ~2; + } + + public boolean isComplete() { + return this.dateToUpgrade < System.currentTimeMillis() + 1000; + } + + public String getContainerInfo() { + String ret = "OwnerID: " + this.ownerID + ", container: "; + ret += this.containerType.toString(); + ret += "Equip Slot: " + this.equipSlot; + return ret; + } + + public int getFlags() { + return this.flags; + } + + public void setFlags(int value) { + this.flags = value; + } + + public void addBonus(AbstractEffectModifier key, float amount) { + if (this.bonuses.containsKey(key)) + this.bonuses.put(key, (this.bonuses.get(key) + amount)); + else + this.bonuses.put(key, amount); + } + + public void multBonus(AbstractEffectModifier key, float amount) { + if (this.bonuses.containsKey(key)) + this.bonuses.put(key, (this.bonuses.get(key) * amount)); + else + this.bonuses.put(key, amount); + } + + public synchronized void decrementChargesRemaining() { + this.chargesRemaining -= 1; + if (this.chargesRemaining < 0) + this.chargesRemaining = 0; + DbManager.ItemQueries.UPDATE_REMAINING_CHARGES(this); + } + + protected void validateItemContainer() { + + if (this.containerType == Enum.ItemContainerType.NONE) + + if (this.ownerID != 0) + // Item has an owner, just somehow the flags got messed up. + // Default to bank. + // TODO NEED LOG EVENT HERE. + this.containerType = Enum.ItemContainerType.BANK; + else + // This item is on the ground. Nothing to worry about. + this.zeroItem(); + } + + // Removes all ownership of item and 'orphans' it. + protected synchronized void junk() { + + DbManager.ItemQueries.UPDATE_OWNER(this, 0, false, false, false, ItemContainerType.NONE, 0); + this.zeroItem(); + + //TODO do we want to delete the item here? + this.lastOwner = null; + //cleanup item from server. + this.removeFromCache(); + } + + public synchronized void zeroItem() { + this.ownerID = 0; + + this.ownerType = null; + this.containerType = Enum.ItemContainerType.NONE; + this.equipSlot = MBServerStatics.SLOT_UNEQUIPPED; + } + + protected synchronized boolean moveItemToInventory(PlayerCharacter pc) { + if (!DbManager.ItemQueries.UPDATE_OWNER(this, + pc.getObjectUUID(), //tableID + false, //isNPC + true, //isPlayer + false, //isAccount + ItemContainerType.INVENTORY, + 0)) //Slot + + return false; + + this.zeroItem(); + this.ownerID = pc.getObjectUUID(); + this.ownerType = OwnerType.PlayerCharacter; + this.containerType = ItemContainerType.INVENTORY; + return true; + } + + protected synchronized boolean moveItemToInventory(NPC npc) { + if (npc.isStatic()) { + if (!DbManager.ItemQueries.UPDATE_OWNER(this, 0, false, false, false, ItemContainerType.INVENTORY, 0)) + return false; + } else if (!DbManager.ItemQueries.UPDATE_OWNER(this, + npc.getObjectUUID(), //UUID + true, //isNPC + false, //isPlayer + false, //isAccount + ItemContainerType.INVENTORY, + 0)) //Slot + + return false; + this.zeroItem(); + this.ownerID = npc.getObjectUUID(); + this.ownerType = OwnerType.Npc; + this.containerType = Enum.ItemContainerType.INVENTORY; + return true; + } + + protected synchronized boolean moveItemToInventory(Corpse corpse) { + if (!DbManager.ItemQueries.UPDATE_OWNER(this, + 0, //no ID for corpse + false, //isNPC + true, //isPlayer + false, //isAccount + ItemContainerType.INVENTORY, + 0)) //Slot + + return false; + this.zeroItem(); + this.ownerID = 0; + this.ownerType = null; + this.containerType = Enum.ItemContainerType.INVENTORY; + return true; + } + + protected synchronized boolean moveItemToBank(PlayerCharacter pc) { + if (!DbManager.ItemQueries.UPDATE_OWNER(this, + pc.getObjectUUID(), //UUID + false, //isNPC + true, //isPlayer + false, //isAccount + ItemContainerType.BANK, + 0)) //Slot + + return false; + this.zeroItem(); + this.ownerID = pc.getObjectUUID(); + this.ownerType = OwnerType.PlayerCharacter; + this.containerType = Enum.ItemContainerType.BANK; + return true; + } + + protected synchronized boolean moveItemToBank(NPC npc) { + if (!DbManager.ItemQueries.UPDATE_OWNER(this, + npc.getObjectUUID(), //UUID + true, //isNPC + false, //isPlayer + false, //isAccount + ItemContainerType.BANK, + 0)) //Slot + + return false; + this.zeroItem(); + this.ownerID = npc.getObjectUUID(); + this.ownerType = OwnerType.Npc; + this.containerType = Enum.ItemContainerType.BANK; + return true; + } + + protected synchronized boolean moveItemToVault(Account a) { + if (!DbManager.ItemQueries.UPDATE_OWNER(this, + a.getObjectUUID(), //UUID + false, //isNPC + false, //isPlayer + true, //isAccount + ItemContainerType.VAULT, + 0)) //Slot + + return false; + this.zeroItem(); + this.ownerID = a.getObjectUUID(); + this.ownerType = OwnerType.Account; + this.containerType = Enum.ItemContainerType.VAULT; + return true; + } + + protected synchronized boolean equipItem(PlayerCharacter pc, byte slot) { + + if (!DbManager.ItemQueries.UPDATE_OWNER(this, + pc.getObjectUUID(), //tableID + false, //isNPC + true, //isPlayer + false, //isAccount + ItemContainerType.EQUIPPED, + slot)) //Slot + + return false; + this.zeroItem(); + this.ownerID = pc.getObjectUUID(); + this.ownerType = OwnerType.PlayerCharacter; + this.containerType = Enum.ItemContainerType.EQUIPPED; + this.equipSlot = slot; + return true; + } + + protected synchronized boolean equipItem(NPC npc, byte slot) { + if (!DbManager.ItemQueries.UPDATE_OWNER(this, + npc.getObjectUUID(), //UUID + true, //isNPC + false, //isPlayer + false, //isAccount + ItemContainerType.EQUIPPED, + slot)) //Slot + + return false; + this.zeroItem(); + this.ownerID = npc.getObjectUUID(); + this.ownerType = OwnerType.Npc; + this.containerType = Enum.ItemContainerType.EQUIPPED; + this.equipSlot = slot; + return true; + } + + protected synchronized boolean equipItem(Mob npc, byte slot) { + + this.zeroItem(); + this.ownerID = npc.getObjectUUID(); + this.ownerType = OwnerType.Mob; + this.containerType = Enum.ItemContainerType.EQUIPPED; + this.equipSlot = slot; + return true; + } + + public final int getMagicValue() { + return this.magicValue; + } + + public int getBaseValue() { + if (this.getItemBase() != null) + return this.getItemBase().getBaseValue(); + return 0; + } + + public AbstractWorldObject getLastOwner() { + return this.lastOwner; + } + + public void setLastOwner(AbstractWorldObject value) { + this.lastOwner = value; + } + + @Override + public String getName() { + if (this.customName.isEmpty()) + if (this.getItemBase() != null) + return this.getItemBase().getName(); + return this.customName; + } + + public void setName(String name) { + this.customName = name; + } + + private void bakeInStats() { + + EffectsBase effect; + + if (ConfigManager.serverType.equals(Enum.ServerType.LOGINSERVER)) + return; + + if (this.getItemBase() != null) + + for (Integer token : this.getItemBase().getBakedInStats().keySet()) { + + effect = PowersManager.getEffectByToken(token); + + if (effect == null) { + Logger.error("missing effect of token " + token); + continue; + } + AbstractPowerAction apa = PowersManager.getPowerActionByIDString(effect.getIDString()); + apa.applyBakedInStatsForItem(this, this.getItemBase().getBakedInStats().get(token)); + } + } + + public final void loadEnchantments() { + //dont load mobloot enchantments, they arent in db. + if (this.getObjectType().equals(GameObjectType.MobLoot)) { + this.magicValue = this.getItemBase().getBaseValue() + calcMagicValue(); + return; + } + + ConcurrentHashMap enchantList = DbManager.EnchantmentQueries.GET_ENCHANTMENTS_FOR_ITEM(this.getObjectUUID()); + + for (String enchant : enchantList.keySet()) { + AbstractPowerAction apa = PowersManager.getPowerActionByIDString(enchant); + if (apa != null) { + apa.applyEffectForItem(this, enchantList.get(enchant)); + this.effectNames.add(enchant); + } + } + + this.magicValue = this.getItemBase().getBaseValue() + calcMagicValue(); + } + + public HashMap getBakedInStats() { + if (this.getItemBase() != null) + return this.getItemBase().getBakedInStats(); + return null; + } + + public void clearEnchantments() { + + //Clear permanent enchantment out of database + DbManager.EnchantmentQueries.CLEAR_ENCHANTMENTS((long) this.getObjectUUID()); + + for (String name : this.getEffects().keySet()) { + Effect eff = this.getEffects().get(name); + if (!eff.bakedInStat()) + this.endEffect(name); + } + this.effectNames.clear(); + } + + public void addPermanentEnchantment(String enchantID, int rank) { + AbstractPowerAction apa = PowersManager.getPowerActionByIDString(enchantID); + if (apa == null) + return; + + DbManager.EnchantmentQueries.CREATE_ENCHANTMENT_FOR_ITEM((long) this.getObjectUUID(), enchantID, rank); + apa.applyEffectForItem(this, rank); + this.effectNames.add(enchantID); + } + + public void addPermanentEnchantmentForDev(String enchantID, int rank) { + AbstractPowerAction apa = PowersManager.getPowerActionByIDString(enchantID); + if (apa == null) + return; + + DbManager.EnchantmentQueries.CREATE_ENCHANTMENT_FOR_ITEM((long) this.getObjectUUID(), enchantID, rank); + apa.applyEffectForItem(this, rank); + this.effectNames.add(enchantID); + } + + protected int calcMagicValue() { + int ret = 0; + for (String enchant : this.effectNames) { + ret += Item.getEnchantValue(enchant + 'A'); + } + return ret; + } + + public void addToCache() { + DbManager.addToCache(this); + } + + @Override + public void updateDatabase() { + //DbManager.ItemQueries.updateDatabase(this); + } + + @Override + public void runAfterLoad() { + loadEnchantments(); + bakeInStats(); + } + + + public ArrayList getEffectNames() { + return effectNames; + } + + public boolean validForItem(long flags) { + if (this.getItemBase() == null) + return false; + return this.getItemBase().validSlotFlag(flags); + } + + public boolean validForInventory(ClientConnection origin, PlayerCharacter pc, CharacterItemManager charItemMan) { + + if (origin == null || pc == null || charItemMan == null) + return false; if (ownerID != pc.getObjectUUID()) { - Logger.warn("Inventory Item " + this.getObjectUUID() + " not owned by Character " + charItemMan.getOwner().getObjectUUID()); - charItemMan.updateInventory(); - return false; - } - - if (!charItemMan.inventoryContains(this)){ - charItemMan.updateInventory(); - return false; - } - return true; - } - - public boolean validForBank(ClientConnection origin, PlayerCharacter pc, CharacterItemManager charItemMan) { - if (origin == null || pc == null || charItemMan == null) - return false; + Logger.warn("Inventory Item " + this.getObjectUUID() + " not owned by Character " + charItemMan.getOwner().getObjectUUID()); + charItemMan.updateInventory(); + return false; + } + + if (!charItemMan.inventoryContains(this)) { + charItemMan.updateInventory(); + return false; + } + return true; + } + + public boolean validForBank(ClientConnection origin, PlayerCharacter pc, CharacterItemManager charItemMan) { + if (origin == null || pc == null || charItemMan == null) + return false; if (!charItemMan.bankContains(this)) - return false; - else if (ownerID != pc.getObjectUUID()) { - Logger.warn("Bank Item " + this.getObjectUUID() + " not owned by Character " + charItemMan.getOwner().getObjectUUID()); - return false; - } - return true; - } - - public boolean validForEquip(ClientConnection origin, PlayerCharacter pc, CharacterItemManager charItemMan) { - if (origin == null || pc == null || charItemMan == null) - return false; + return false; + else if (ownerID != pc.getObjectUUID()) { + Logger.warn("Bank Item " + this.getObjectUUID() + " not owned by Character " + charItemMan.getOwner().getObjectUUID()); + return false; + } + return true; + } + + public boolean validForEquip(ClientConnection origin, PlayerCharacter pc, CharacterItemManager charItemMan) { + if (origin == null || pc == null || charItemMan == null) + return false; if (!charItemMan.equippedContains(this)) - return false; - else if (ownerID != pc.getObjectUUID()) { - //duped item, cleanup - Logger.warn("Duped item id " - + this.getObjectUUID() + " removed from PC " + pc.getObjectUUID() + '.'); - DeleteItemMsg deleteItemMsg = new DeleteItemMsg(this.getObjectType().ordinal(), this.getObjectUUID()); - charItemMan.cleanupDupe(this); - Dispatch dispatch = Dispatch.borrow(pc, deleteItemMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - return false; - } - return true; - } - - public boolean validForVault(ClientConnection origin, PlayerCharacter pc, CharacterItemManager charItemMan) { - if (origin == null || pc == null || charItemMan == null) - return false; - - if (pc.getAccount() == null) - return false; + return false; + else if (ownerID != pc.getObjectUUID()) { + //duped item, cleanup + Logger.warn("Duped item id " + + this.getObjectUUID() + " removed from PC " + pc.getObjectUUID() + '.'); + DeleteItemMsg deleteItemMsg = new DeleteItemMsg(this.getObjectType().ordinal(), this.getObjectUUID()); + charItemMan.cleanupDupe(this); + Dispatch dispatch = Dispatch.borrow(pc, deleteItemMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + return false; + } + return true; + } + + public boolean validForVault(ClientConnection origin, PlayerCharacter pc, CharacterItemManager charItemMan) { + if (origin == null || pc == null || charItemMan == null) + return false; + + if (pc.getAccount() == null) + return false; if (!pc.getAccount().getVault().contains(this)) - return false; - else if (ownerID != pc.getAccount().getObjectUUID()) { - //duped item, cleanup - Logger.warn("Duped item id " - + this.getObjectUUID() + " removed from PC " + pc.getObjectUUID() + '.'); - DeleteItemMsg deleteItemMsg = new DeleteItemMsg(this.getObjectType().ordinal(), this.getObjectUUID()); - charItemMan.cleanupDupe(this); - Dispatch dispatch = Dispatch.borrow(pc, deleteItemMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - return false; - } - return true; - } - - public long getDateToUpgrade() { - return dateToUpgrade; - } - - public void setDateToUpgrade(long dateToUpgrade) { - this.dateToUpgrade = dateToUpgrade; - } - - /** - * @return the value - */ - public int getValue() { - - if (this.value == 0) - if (this.isID()) { + return false; + else if (ownerID != pc.getAccount().getObjectUUID()) { + //duped item, cleanup + Logger.warn("Duped item id " + + this.getObjectUUID() + " removed from PC " + pc.getObjectUUID() + '.'); + DeleteItemMsg deleteItemMsg = new DeleteItemMsg(this.getObjectType().ordinal(), this.getObjectUUID()); + charItemMan.cleanupDupe(this); + Dispatch dispatch = Dispatch.borrow(pc, deleteItemMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + return false; + } + return true; + } + + public long getDateToUpgrade() { + return dateToUpgrade; + } + + public void setDateToUpgrade(long dateToUpgrade) { + this.dateToUpgrade = dateToUpgrade; + } + + /** + * @return the value + */ + public int getValue() { + + if (this.value == 0) + if (this.isID()) { return this.getMagicValue(); - } - else - return this.getBaseValue(); - - return this.value; - } - - /** - * @param value the value to set - */ - public void setValue(int value) { - this.value = value; - } - - public boolean isRandom() { - return isRandom; - } - - public void setRandom(boolean isRandom) { - this.isRandom = isRandom; - } - - public boolean isCustomValue(){ - if (this.value == 0) - return false; - return true; - } + } else + return this.getBaseValue(); + + return this.value; + } + + /** + * @param value the value to set + */ + public void setValue(int value) { + this.value = value; + } + + public boolean isRandom() { + return isRandom; + } + + public void setRandom(boolean isRandom) { + this.isRandom = isRandom; + } + + public boolean isCustomValue() { + if (this.value == 0) + return false; + return true; + } } diff --git a/src/engine/objects/ItemBase.java b/src/engine/objects/ItemBase.java index 49286e31..0b767663 100644 --- a/src/engine/objects/ItemBase.java +++ b/src/engine/objects/ItemBase.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -37,890 +34,893 @@ import java.util.concurrent.ConcurrentHashMap; public class ItemBase { - public static final byte GOLD_BASE_TYPE = 4; - public static ItemBase GOLD_ITEM_BASE = null; - public static int GOLD_BASE_ID = 7; - public static ArrayList AnniverseryGifts = new ArrayList<>(); - // Internal cache - private static HashMap itemHashIDMap = new HashMap<>(); - private static HashMap _IDsByNames = new HashMap<>(); - public static HashMap _itemBaseByUUID = new HashMap<>(); - private static ArrayList _resourceList = new ArrayList<>(); - private final int uuid; - private final String name; - private float durability; - private int value; - private short weight; - private short color; - private ItemType type; - private int vendorType; - private int modTable; - private int useID; - private int hashID; - private byte useAmount; - // Armor and weapon related values - private int equipFlag; - private int restrictFlag; - private String skillRequired; - private short percentRequired; - private float slashResist; - private float crushResist; - private float pierceResist; - private float blockMod; - private short defense; - private float dexPenalty; - private float speed; - private float range; - private short minDamage; - private short maxDamage; - private String mastery; - private engine.Enum.DamageType damageType; - private boolean twoHanded; - private boolean isConsumable; - private boolean isStackable; - private int numCharges; - // Item stat modifiers - private HashMap bakedInStats = new HashMap<>(); - private HashMap usedStats = new HashMap<>(); - private float parryBonus; - private boolean isStrBased; - private ArrayList animations = new ArrayList<>(); - private ArrayList offHandAnimations = new ArrayList<>(); - private boolean autoID = false; - public static HashMap> ItemBaseTypeMap = new HashMap<>(); - /** - * ResultSet Constructor - */ - public ItemBase(ResultSet rs) throws SQLException { - - this.uuid = rs.getInt("ID"); - this.name = rs.getString("name"); - this.durability = rs.getInt("durability"); - this.value = rs.getInt("value"); - this.weight = rs.getShort("weight"); - this.color = rs.getShort("color"); - this.type = ItemType.valueOf(rs.getString("Type")); - this.useID = rs.getInt("useID"); - this.vendorType = rs.getInt("vendorType"); - this.useAmount = rs.getByte("useAmount"); - this.modTable = rs.getInt("modTable"); - this.hashID = rs.getInt("itemHashID"); - - this.isConsumable = false; - this.isStackable = false; - this.numCharges = rs.getShort("numCharges"); - - this.equipFlag = rs.getInt("equipFlag"); - this.restrictFlag = rs.getInt("restrictFlag"); - this.skillRequired = rs.getString("skillRequired"); - this.percentRequired = rs.getShort("percentRequired"); - this.slashResist = rs.getFloat("slashResist"); - this.crushResist = rs.getFloat("crushResist"); - this.pierceResist = rs.getFloat("pierceResist"); - this.blockMod = rs.getFloat("blockMod"); - this.defense = rs.getShort("defense"); - this.dexPenalty = rs.getFloat("dexPenalty"); - this.parryBonus = rs.getFloat("parryBonus"); - this.isStrBased = (rs.getInt("isStrBased") == 1); - this.speed = rs.getFloat("speed"); - this.range = rs.getFloat("range"); - this.minDamage = rs.getShort("minDamage"); - this.maxDamage = rs.getShort("maxDamage"); - - this.mastery = rs.getString("mastery"); - damageType = DamageType.valueOf(rs.getString("damageType")); - - this.twoHanded = (rs.getInt("twoHanded") == 1); - - switch (this.type) { - case RUNE: - case SCROLL: - case COMMANDROD: - case POTION: - case TEARS: - case GUILDCHARTER: - case DEED: - case CONTRACT: - case WATERBUCKET: - case REALMCHARTER: - case GIFT: - this.isConsumable = true; - break; - case OFFERING: - this.isConsumable = true; - Boon.HandleBoonListsForItemBase(uuid); - break; - case RESOURCE: - this.isStackable = true; - break; - - } - - this.autoIDItemsCheck(); - - try{ - DbManager.ItemBaseQueries.LOAD_ANIMATIONS(this); - }catch(Exception e){ - Logger.error( e.getMessage()); - } - initBakedInStats(); - initializeHashes(); - - } - - public static void addToCache(ItemBase itemBase) { - - _itemBaseByUUID.put(itemBase.uuid, itemBase); - - if (itemBase.type.equals(ItemType.RESOURCE)) - _resourceList.add(itemBase); - - _IDsByNames.put(itemBase.name.toLowerCase().replace(" ", "_"), itemBase.uuid); - } - - public static HashMap getItemHashIDMap() { - return itemHashIDMap; - } - - /* - * Database - */ - public static ItemBase getItemBase(int uuid) { - - return _itemBaseByUUID.get(uuid); - } - - /** - * Get the ItemBase instance for Gold. - * - * @return ItemBase for Gold - */ - public static ItemBase getGoldItemBase() { - if (ItemBase.GOLD_ITEM_BASE == null) - ItemBase.GOLD_ITEM_BASE = getItemBase(7); - return ItemBase.GOLD_ITEM_BASE; - } - - public static int getIDByName(String name) { - if (ItemBase._IDsByNames.containsKey(name)) - return ItemBase._IDsByNames.get(name); - return 0; - } - - /** - * @return the _itemBaseByUUID - */ - public static HashMap getUUIDCache() { - return _itemBaseByUUID; - } - - /** - * @return the _resourceList - */ - public static ArrayList getResourceList() { - return _resourceList; - } - - public static void loadAllItemBases() { - DbManager.ItemBaseQueries.LOAD_ALL_ITEMBASES(); - AnniverseryGifts.add(971000); - AnniverseryGifts.add(971001); - AnniverseryGifts.add(971002); - AnniverseryGifts.add(971003); - AnniverseryGifts.add(971004); - AnniverseryGifts.add(971005); - AnniverseryGifts.add(971006); - AnniverseryGifts.add(971007); - AnniverseryGifts.add(971008); - AnniverseryGifts.add(971009); - AnniverseryGifts.add(971010); - AnniverseryGifts.add(5101000); - AnniverseryGifts.add(5101020); - AnniverseryGifts.add(5101100); - AnniverseryGifts.add(5101120); - AnniverseryGifts.add(5101040); - AnniverseryGifts.add(5101140); - AnniverseryGifts.add(5101060); - AnniverseryGifts.add(5101080); - - - } - - /* - * Getters - */ - public String getName() { - return this.name; - } - - public float getDurability() { - return this.durability; - } - - private void initBakedInStats() { - DbManager.ItemBaseQueries.LOAD_BAKEDINSTATS(this); - } - - //TODO fix this later. Shouldn't be gotten from item base - public int getMagicValue() { - return this.value; - } - - public int getBaseValue() { - return this.value; - } - - public short getWeight() { - return this.weight; - } - - public int getColor() { - return this.color; - } - - public boolean isConsumable() { - return this.isConsumable; - } - - public boolean isStackable() { - return this.isStackable; - } - - public int getNumCharges() { - - return this.numCharges; - - } - - public int getEquipFlag() { - - if ((this.type == ItemType.ARMOR) - || (this.type == ItemType.WEAPON) - || (this.type == ItemType.JEWELRY)) - return this.equipFlag; - else - return 0; - } - - public boolean isRune() { - int ID = uuid; - if (ID > 2499 && ID < 3050) //class, discipline runes - return true; - else return ID > 249999 && ID < 252137; - } - - public boolean isStatRune() { - int ID = uuid; - return ID > 249999 && ID < 250045; - } - public boolean isDiscRune(){ - int ID = uuid; - if (ID > 2499 && ID < 3050) { //class, discipline runes - return true; - } - else{ - return false; - } - } - public boolean isGlass() { - int ID = uuid; - return ID > 7000099 && ID < 7000281; - } - - - public boolean isMasteryRune() { - int ID = uuid; - if (ID > 250114 && ID < 252128) - switch (ID) { - case 250115: - case 250118: - case 250119: - case 250120: - case 250121: - case 250122: - case 252123: - case 252124: - case 252125: - case 252126: - case 252127: - return true; - default: - return false; - } - return false; - } - - //returns powers tokens baked in to item - public HashMap getBakedInStats() { - return this.bakedInStats; - } - - //returns power tokens granted when using item, such as scrolls and potions - public HashMap getUsedStats() { - return this.usedStats; - } - - public final void initializeHashes() { - itemHashIDMap.put(this.hashID, uuid); - - } - - public ItemType getType() { - return this.type; - } - - public int getUseID() { - return this.useID; - } - - public byte getUseAmount() { - return this.useAmount; - } - - public int getModTable() { - return modTable; - } - - public int getVendorType() { - return vendorType; - } - - public void setVendorType(int vendorType) { - this.vendorType = vendorType; - } - - public int getHashID() { - return hashID; - } - - public void setHashID(int hashID) { - this.hashID = hashID; - } - - private void autoIDItemsCheck(){ - //AUto ID Vorg and Glass - switch (uuid){ - - case 27550: - case 27560: - case 27580: - case 27590: - case 188500: - case 188510: - case 188520: - case 188530: - case 188540: - case 188550: - case 189100: - case 189110: - case 189120: - case 189130: - case 189140: - case 189150: - case 189510: - case 27600: - case 181840: - case 188700: - case 188720: - case 189550: - case 189560: - case 7000100: - case 7000110: - case 7000120: - case 7000130: - case 7000140: - case 7000150: - case 7000160: - case 7000170: - case 7000180: - case 7000190: - case 7000200: - case 7000210: - case 7000220: - case 7000230: - case 7000240: - case 7000250: - case 7000270: - case 7000280: - this.autoID = true; - break; - default: - this.autoID = false; - } - } - - public boolean validForSkills(ConcurrentHashMap skills) { - - CharacterSkill characterSkill; - - if (this.skillRequired.isEmpty()) - return true; - - characterSkill = skills.get(this.skillRequired); - - if (characterSkill == null) - return false; - - return !(this.percentRequired > characterSkill.getModifiedAmountBeforeMods()); - } - - public boolean canEquip(int slot, CharacterItemManager itemManager, AbstractCharacter abstractCharacter, Item item) { - - if (itemManager == null || abstractCharacter == null) - return false; - - if (abstractCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)) { - - if (!validForSlot(slot, itemManager.getEquipped(), item)) - return false; - - if (!validForSkills(abstractCharacter.getSkills())) - return false; - - return item.getItemBase().value != 0 || Kit.IsNoobGear(item.getItemBase().uuid); - //players can't wear 0 value items. - - } - - return true; //Mobiles and NPC's don't need to check equip - } - - public int getValidSlot() { - int slotValue = 0; - - switch (this.type) { - case WEAPON: - if ((this.equipFlag & 1) != 0) - slotValue = MBServerStatics.SLOT_MAINHAND; - else if ((this.equipFlag & 2) != 0) - slotValue = MBServerStatics.SLOT_OFFHAND; - break; - case ARMOR: - if ((this.equipFlag & 2) != 0) - slotValue = MBServerStatics.SLOT_OFFHAND; - else if ((this.equipFlag & 4) != 0) - slotValue = MBServerStatics.SLOT_HELMET; - else if ((this.equipFlag & 8) != 0) - slotValue = MBServerStatics.SLOT_CHEST; - else if ((this.equipFlag & 16) != 0) - slotValue = MBServerStatics.SLOT_ARMS; - else if ((this.equipFlag & 32) != 0) - slotValue = MBServerStatics.SLOT_GLOVES; - else if ((this.equipFlag & 64) != 0) - slotValue = MBServerStatics.SLOT_RING2; - else if ((this.equipFlag & 128) != 0) - slotValue = MBServerStatics.SLOT_RING1; - else if ((this.equipFlag & 256) != 0) - slotValue = MBServerStatics.SLOT_NECKLACE; - else if ((this.equipFlag & 512) != 0) - slotValue = MBServerStatics.SLOT_LEGGINGS; - else if ((this.equipFlag & 1024) != 0) - slotValue = MBServerStatics.SLOT_FEET; - break; - - case HAIR: - if (this.equipFlag == 131072) - slotValue = MBServerStatics.SLOT_HAIRSTYLE; - else if(this.equipFlag == 65536) - slotValue = MBServerStatics.SLOT_BEARDSTYLE; - break; - - } - return slotValue; - - } - - public boolean validSlotFlag(long flags) { - - boolean validSlot = false; - - switch (this.type) { - case WEAPON: - if (this.isMelee()) - validSlot = ((flags & 1) != 0); - else if (this.isThrowing()) - validSlot = ((flags & 2) != 0); - else if (this.isArchery()) - validSlot = ((flags & 4) != 0); - else if (this.isScepter()) - validSlot = ((flags & 8) != 0); - else if (this.isStaff()) - validSlot = ((flags & 16) != 0); - break; - case JEWELRY: - if (this.isNecklace()) - validSlot = ((flags & 2147483648L) != 0L); - else - validSlot = ((flags & 4294967296L) != 0L); - break; - case ARMOR: - - if (this.isShield()) { - validSlot = ((flags & 32) != 0); - break; - } - - if (this.isClothArmor()) { - - if (this.getEquipFlag() == 4) //hood - validSlot = ((flags & 64) != 0); - else if (this.getEquipFlag() == 8) { - if ((restrictFlag & 512) != 0) //Robe - validSlot = ((flags & 128) != 0); - else - validSlot = ((flags & 1024) != 0); //Tunic/Shirt - - break; - } else if (this.getEquipFlag() == 16) //Sleeves - validSlot = ((flags & 2048) != 0); - else if (this.getEquipFlag() == 32) //Gloves - validSlot = ((flags & 512) != 0); - else if (this.getEquipFlag() == 512) //Pants - validSlot = ((flags & 4096) != 0); - else if (this.getEquipFlag() == 1024) //Boots - validSlot = ((flags & 256) != 0); - - break; - } - - if (this.isLightArmor()) { - if (this.getEquipFlag() == 4) //helm - validSlot = ((flags & 8192) != 0); - else if (this.getEquipFlag() == 8) //Chest - validSlot = ((flags & 16384) != 0); - else if (this.getEquipFlag() == 16) //Sleeves - validSlot = ((flags & 32768) != 0); - else if (this.getEquipFlag() == 32) //Gloves - validSlot = ((flags & 65536) != 0); - else if (this.getEquipFlag() == 512) //Pants - validSlot = ((flags & 131072) != 0); - else if (this.getEquipFlag() == 1024) //Boots - validSlot = ((flags & 262144) != 0); - - break; - } - - if (this.isMediumArmor()) { - if (this.getEquipFlag() == 4) //helm - validSlot = ((flags & 524288) != 0); - else if (this.getEquipFlag() == 8) //Chest - validSlot = ((flags & 1048576) != 0); - else if (this.getEquipFlag() == 16) //Sleeves - validSlot = ((flags & 2097152) != 0); - else if (this.getEquipFlag() == 32) //Gloves - validSlot = ((flags & 4194304) != 0); - else if (this.getEquipFlag() == 512) //Pants - validSlot = ((flags & 8388608) != 0); - else if (this.getEquipFlag() == 1024) //Boots - validSlot = ((flags & 16777216) != 0); - - break; - } - - if (this.isHeavyArmor()) - if (this.getEquipFlag() == 4) //helm - validSlot = ((flags & 33554432) != 0); - else if (this.getEquipFlag() == 8) //Chest - validSlot = ((flags & 67108864) != 0); - else if (this.getEquipFlag() == 16) //Sleeves - validSlot = ((flags & 134217728) != 0); - else if (this.getEquipFlag() == 32) //Gloves - validSlot = ((flags & 268435456) != 0); - else if (this.getEquipFlag() == 512) //Pants - validSlot = ((flags & 536870912) != 0); - else if (this.getEquipFlag() == 1024) //Boots - validSlot = ((flags & 1073741824) != 0); - break; - } - return validSlot; - } - - public boolean validForSlot(int slot, ConcurrentHashMap equipped, Item item) { - - boolean validSlot = false; - - if (equipped == null) - return validSlot; - - // Cannot equip an item in a slot already taken - if (equipped.get(slot) != null && equipped.get(slot).equals(item) == false) - return validSlot; - - switch (item.getItemBase().type) { - case WEAPON: - - // Only two slots available for weapons - if ((slot != MBServerStatics.SLOT_MAINHAND) && (slot != MBServerStatics.SLOT_OFFHAND)) - break; - - //make sure weapon is valid for slot - if ((slot & this.equipFlag) == 0) - break; - - // Two handed weapons take up two slots - if ((this.twoHanded == true) && - ((slot == MBServerStatics.SLOT_OFFHAND && equipped.get(MBServerStatics.SLOT_MAINHAND) != null) || - (slot == MBServerStatics.SLOT_MAINHAND && equipped.get(MBServerStatics.SLOT_OFFHAND) != null))) - break; - - // Validation passed, must be a valid weapon - - validSlot = true; - break; - case JEWELRY: - // Not a valid slot for ring - - if (this.isRing() && - ((slot != MBServerStatics.SLOT_RING1) && (slot != MBServerStatics.SLOT_RING2))) - break; - - // Not a valid slot for necklace - - if (this.isNecklace() && slot != MBServerStatics.SLOT_NECKLACE) - break; - - // Passed validation, must be valid bling bling - - validSlot = true; - break; - case ARMOR: - - // Invalid slot for armor? - if (slot == MBServerStatics.SLOT_OFFHAND && ((2 & this.equipFlag) == 0)) - break; - if (slot == MBServerStatics.SLOT_HELMET && ((4 & this.equipFlag) == 0)) - break; - if (slot == MBServerStatics.SLOT_CHEST && ((8 & this.equipFlag) == 0)) - break; - if (slot == MBServerStatics.SLOT_ARMS && ((16 & this.equipFlag) == 0)) - break; - if (slot == MBServerStatics.SLOT_GLOVES && ((32 & this.equipFlag) == 0)) - break; - if (slot == MBServerStatics.SLOT_LEGGINGS && ((512 & this.equipFlag) == 0)) - break; - if (slot == MBServerStatics.SLOT_FEET && ((1024 & this.equipFlag) == 0)) - break; - - // Is slot for this piece already taken? - if (((this.restrictFlag & 2) != 0) && (equipped.get(MBServerStatics.SLOT_OFFHAND) != null) && slot != MBServerStatics.SLOT_OFFHAND) - break; - if (((this.restrictFlag & 4) != 0) && (equipped.get(MBServerStatics.SLOT_HELMET) != null) && slot != MBServerStatics.SLOT_HELMET) - break; - if (((this.restrictFlag & 8) != 0) && (equipped.get(MBServerStatics.SLOT_CHEST) != null) && slot != MBServerStatics.SLOT_CHEST) - break; - if (((this.restrictFlag & 16) != 0) && (equipped.get(MBServerStatics.SLOT_ARMS) != null) && slot != MBServerStatics.SLOT_ARMS) - break; - if (((this.restrictFlag & 32) != 0) && (equipped.get(MBServerStatics.SLOT_GLOVES) != null) && slot != MBServerStatics.SLOT_GLOVES) - break; - if (((this.restrictFlag & 512) != 0) && (equipped.get(MBServerStatics.SLOT_LEGGINGS) != null) && slot != MBServerStatics.SLOT_LEGGINGS) - break; - if (((this.restrictFlag & 1024) != 0) && (equipped.get(MBServerStatics.SLOT_FEET) != null) && slot != MBServerStatics.SLOT_FEET) - break; - - // Passed validation. Is a valid armor piece - - validSlot = true; - break; - } - return validSlot; - } - - /** - * @return the uuid - */ - public final int getUUID() { - return uuid; - } - - public boolean isRing() { - return ((this.equipFlag & (64 | 128 | 192)) != 0); - } - - public boolean isNecklace() { - return (this.equipFlag == 256); - } - - public boolean isShield() { - return this.type.equals(ItemType.ARMOR) && this.equipFlag == 2; - } - - public boolean isLightArmor() { - return this.skillRequired.equals("Wear Armor, Light"); - } - - public boolean isMediumArmor() { - return this.skillRequired.equals("Wear Armor, Medium"); - } - - public boolean isHeavyArmor() { - return this.skillRequired.equals("Wear Armor, Heavy"); - } - - public boolean isClothArmor() { - return this.skillRequired.isEmpty(); - } - - public boolean isThrowing() { - return this.mastery.equals("Throwing") ? true : false; - } - - public boolean isStaff() { - return this.mastery.equals("Staff") ? true : false; - } - - public boolean isScepter() { - return this.mastery.equals("Benediction") ? true : false; - } - - public boolean isArchery() { - return this.mastery.equals("Archery") ? true : false; - } - - public boolean isMelee() { - return (this.isThrowing() == false && this.isStaff() == false && this.isScepter() == false && this.isArchery() == false); - } - - public boolean isTwoHanded() { - return this.twoHanded; - } - - /** - * @return the restrictFlag - */ - public int getRestrictFlag() { - return restrictFlag; - } - - /** - * @return the slashResist - */ - public float getSlashResist() { - return slashResist; - } - - /** - * @return the crushResist - */ - public float getCrushResist() { - return crushResist; - } - - /** - * @return the pierceResist - */ - public float getPierceResist() { - return pierceResist; - } - - /** - * @return the skillRequired - */ - public String getSkillRequired() { - return skillRequired; - } - - /** - * @return the mastery - */ - public String getMastery() { - return mastery; - } - - /** - * @return the blockMod - */ - public float getBlockMod() { - return blockMod; - } - - /** - * @return the defense - */ - public short getDefense() { - return defense; - } - - /** - * @return the dexPenalty - */ - public float getDexPenalty() { - return dexPenalty; - } - - /** - * @return the speed - */ - public float getSpeed() { - return speed; - } - - /** - * @return the range - */ - public float getRange() { - return range; - } - - /** - * @return the isStrBased - */ - public boolean isStrBased() { - return isStrBased; - } - - /** - * @return the parryBonus - */ - public float getParryBonus() { - return parryBonus; - } - - /** - * @return the maxDamage - */ - public short getMaxDamage() { - return maxDamage; - } - - /** - * @return the minDamage - */ - public short getMinDamage() { - return minDamage; - } - - /** - * @return the damageType - */ - public engine.Enum.DamageType getDamageType() { - return damageType; - } - - public short getPercentRequired() { - return percentRequired; - } - - public ArrayList getAnimations() { - return animations; - } - - public void setAnimations(ArrayList animations) { - this.animations = animations; - } - - public ArrayList getOffHandAnimations() { - return offHandAnimations; - } - - public void setOffHandAnimations(ArrayList offHandAnimations) { - this.offHandAnimations = offHandAnimations; - } - - public boolean isAutoID() { - return autoID; - } - - public void setAutoID(boolean autoID) { - this.autoID = autoID; - } + public static final byte GOLD_BASE_TYPE = 4; + public static ItemBase GOLD_ITEM_BASE = null; + public static int GOLD_BASE_ID = 7; + public static ArrayList AnniverseryGifts = new ArrayList<>(); + public static HashMap _itemBaseByUUID = new HashMap<>(); + public static HashMap> ItemBaseTypeMap = new HashMap<>(); + // Internal cache + private static HashMap itemHashIDMap = new HashMap<>(); + private static HashMap _IDsByNames = new HashMap<>(); + private static ArrayList _resourceList = new ArrayList<>(); + private final int uuid; + private final String name; + private float durability; + private int value; + private short weight; + private short color; + private ItemType type; + private int vendorType; + private int modTable; + private int useID; + private int hashID; + private byte useAmount; + // Armor and weapon related values + private int equipFlag; + private int restrictFlag; + private String skillRequired; + private short percentRequired; + private float slashResist; + private float crushResist; + private float pierceResist; + private float blockMod; + private short defense; + private float dexPenalty; + private float speed; + private float range; + private short minDamage; + private short maxDamage; + private String mastery; + private engine.Enum.DamageType damageType; + private boolean twoHanded; + private boolean isConsumable; + private boolean isStackable; + private int numCharges; + // Item stat modifiers + private HashMap bakedInStats = new HashMap<>(); + private HashMap usedStats = new HashMap<>(); + private float parryBonus; + private boolean isStrBased; + private ArrayList animations = new ArrayList<>(); + private ArrayList offHandAnimations = new ArrayList<>(); + private boolean autoID = false; + + /** + * ResultSet Constructor + */ + public ItemBase(ResultSet rs) throws SQLException { + + this.uuid = rs.getInt("ID"); + this.name = rs.getString("name"); + this.durability = rs.getInt("durability"); + this.value = rs.getInt("value"); + this.weight = rs.getShort("weight"); + this.color = rs.getShort("color"); + this.type = ItemType.valueOf(rs.getString("Type")); + this.useID = rs.getInt("useID"); + this.vendorType = rs.getInt("vendorType"); + this.useAmount = rs.getByte("useAmount"); + this.modTable = rs.getInt("modTable"); + this.hashID = rs.getInt("itemHashID"); + + this.isConsumable = false; + this.isStackable = false; + this.numCharges = rs.getShort("numCharges"); + + this.equipFlag = rs.getInt("equipFlag"); + this.restrictFlag = rs.getInt("restrictFlag"); + this.skillRequired = rs.getString("skillRequired"); + this.percentRequired = rs.getShort("percentRequired"); + this.slashResist = rs.getFloat("slashResist"); + this.crushResist = rs.getFloat("crushResist"); + this.pierceResist = rs.getFloat("pierceResist"); + this.blockMod = rs.getFloat("blockMod"); + this.defense = rs.getShort("defense"); + this.dexPenalty = rs.getFloat("dexPenalty"); + this.parryBonus = rs.getFloat("parryBonus"); + this.isStrBased = (rs.getInt("isStrBased") == 1); + this.speed = rs.getFloat("speed"); + this.range = rs.getFloat("range"); + this.minDamage = rs.getShort("minDamage"); + this.maxDamage = rs.getShort("maxDamage"); + + this.mastery = rs.getString("mastery"); + damageType = DamageType.valueOf(rs.getString("damageType")); + + this.twoHanded = (rs.getInt("twoHanded") == 1); + + switch (this.type) { + case RUNE: + case SCROLL: + case COMMANDROD: + case POTION: + case TEARS: + case GUILDCHARTER: + case DEED: + case CONTRACT: + case WATERBUCKET: + case REALMCHARTER: + case GIFT: + this.isConsumable = true; + break; + case OFFERING: + this.isConsumable = true; + Boon.HandleBoonListsForItemBase(uuid); + break; + case RESOURCE: + this.isStackable = true; + break; + + } + + this.autoIDItemsCheck(); + + try { + DbManager.ItemBaseQueries.LOAD_ANIMATIONS(this); + } catch (Exception e) { + Logger.error(e.getMessage()); + } + initBakedInStats(); + initializeHashes(); + + } + + public static void addToCache(ItemBase itemBase) { + + _itemBaseByUUID.put(itemBase.uuid, itemBase); + + if (itemBase.type.equals(ItemType.RESOURCE)) + _resourceList.add(itemBase); + + _IDsByNames.put(itemBase.name.toLowerCase().replace(" ", "_"), itemBase.uuid); + } + + public static HashMap getItemHashIDMap() { + return itemHashIDMap; + } + + /* + * Database + */ + public static ItemBase getItemBase(int uuid) { + + return _itemBaseByUUID.get(uuid); + } + + /** + * Get the ItemBase instance for Gold. + * + * @return ItemBase for Gold + */ + public static ItemBase getGoldItemBase() { + if (ItemBase.GOLD_ITEM_BASE == null) + ItemBase.GOLD_ITEM_BASE = getItemBase(7); + return ItemBase.GOLD_ITEM_BASE; + } + + public static int getIDByName(String name) { + if (ItemBase._IDsByNames.containsKey(name)) + return ItemBase._IDsByNames.get(name); + return 0; + } + + /** + * @return the _itemBaseByUUID + */ + public static HashMap getUUIDCache() { + return _itemBaseByUUID; + } + + /** + * @return the _resourceList + */ + public static ArrayList getResourceList() { + return _resourceList; + } + + public static void loadAllItemBases() { + DbManager.ItemBaseQueries.LOAD_ALL_ITEMBASES(); + AnniverseryGifts.add(971000); + AnniverseryGifts.add(971001); + AnniverseryGifts.add(971002); + AnniverseryGifts.add(971003); + AnniverseryGifts.add(971004); + AnniverseryGifts.add(971005); + AnniverseryGifts.add(971006); + AnniverseryGifts.add(971007); + AnniverseryGifts.add(971008); + AnniverseryGifts.add(971009); + AnniverseryGifts.add(971010); + AnniverseryGifts.add(5101000); + AnniverseryGifts.add(5101020); + AnniverseryGifts.add(5101100); + AnniverseryGifts.add(5101120); + AnniverseryGifts.add(5101040); + AnniverseryGifts.add(5101140); + AnniverseryGifts.add(5101060); + AnniverseryGifts.add(5101080); + + + } + + /* + * Getters + */ + public String getName() { + return this.name; + } + + public float getDurability() { + return this.durability; + } + + private void initBakedInStats() { + DbManager.ItemBaseQueries.LOAD_BAKEDINSTATS(this); + } + + //TODO fix this later. Shouldn't be gotten from item base + public int getMagicValue() { + return this.value; + } + + public int getBaseValue() { + return this.value; + } + + public short getWeight() { + return this.weight; + } + + public int getColor() { + return this.color; + } + + public boolean isConsumable() { + return this.isConsumable; + } + + public boolean isStackable() { + return this.isStackable; + } + + public int getNumCharges() { + + return this.numCharges; + + } + + public int getEquipFlag() { + + if ((this.type == ItemType.ARMOR) + || (this.type == ItemType.WEAPON) + || (this.type == ItemType.JEWELRY)) + return this.equipFlag; + else + return 0; + } + + public boolean isRune() { + int ID = uuid; + if (ID > 2499 && ID < 3050) //class, discipline runes + return true; + else + return ID > 249999 && ID < 252137; + } + + public boolean isStatRune() { + int ID = uuid; + return ID > 249999 && ID < 250045; + } + + public boolean isDiscRune() { + int ID = uuid; + if (ID > 2499 && ID < 3050) { //class, discipline runes + return true; + } else { + return false; + } + } + + public boolean isGlass() { + int ID = uuid; + return ID > 7000099 && ID < 7000281; + } + + + public boolean isMasteryRune() { + int ID = uuid; + if (ID > 250114 && ID < 252128) + switch (ID) { + case 250115: + case 250118: + case 250119: + case 250120: + case 250121: + case 250122: + case 252123: + case 252124: + case 252125: + case 252126: + case 252127: + return true; + default: + return false; + } + return false; + } + + //returns powers tokens baked in to item + public HashMap getBakedInStats() { + return this.bakedInStats; + } + + //returns power tokens granted when using item, such as scrolls and potions + public HashMap getUsedStats() { + return this.usedStats; + } + + public final void initializeHashes() { + itemHashIDMap.put(this.hashID, uuid); + + } + + public ItemType getType() { + return this.type; + } + + public int getUseID() { + return this.useID; + } + + public byte getUseAmount() { + return this.useAmount; + } + + public int getModTable() { + return modTable; + } + + public int getVendorType() { + return vendorType; + } + + public void setVendorType(int vendorType) { + this.vendorType = vendorType; + } + + public int getHashID() { + return hashID; + } + + public void setHashID(int hashID) { + this.hashID = hashID; + } + + private void autoIDItemsCheck() { + //AUto ID Vorg and Glass + switch (uuid) { + + case 27550: + case 27560: + case 27580: + case 27590: + case 188500: + case 188510: + case 188520: + case 188530: + case 188540: + case 188550: + case 189100: + case 189110: + case 189120: + case 189130: + case 189140: + case 189150: + case 189510: + case 27600: + case 181840: + case 188700: + case 188720: + case 189550: + case 189560: + case 7000100: + case 7000110: + case 7000120: + case 7000130: + case 7000140: + case 7000150: + case 7000160: + case 7000170: + case 7000180: + case 7000190: + case 7000200: + case 7000210: + case 7000220: + case 7000230: + case 7000240: + case 7000250: + case 7000270: + case 7000280: + this.autoID = true; + break; + default: + this.autoID = false; + } + } + + public boolean validForSkills(ConcurrentHashMap skills) { + + CharacterSkill characterSkill; + + if (this.skillRequired.isEmpty()) + return true; + + characterSkill = skills.get(this.skillRequired); + + if (characterSkill == null) + return false; + + return !(this.percentRequired > characterSkill.getModifiedAmountBeforeMods()); + } + + public boolean canEquip(int slot, CharacterItemManager itemManager, AbstractCharacter abstractCharacter, Item item) { + + if (itemManager == null || abstractCharacter == null) + return false; + + if (abstractCharacter.getObjectType().equals(GameObjectType.PlayerCharacter)) { + + if (!validForSlot(slot, itemManager.getEquipped(), item)) + return false; + + if (!validForSkills(abstractCharacter.getSkills())) + return false; + + return item.getItemBase().value != 0 || Kit.IsNoobGear(item.getItemBase().uuid); + //players can't wear 0 value items. + + } + + return true; //Mobiles and NPC's don't need to check equip + } + + public int getValidSlot() { + int slotValue = 0; + + switch (this.type) { + case WEAPON: + if ((this.equipFlag & 1) != 0) + slotValue = MBServerStatics.SLOT_MAINHAND; + else if ((this.equipFlag & 2) != 0) + slotValue = MBServerStatics.SLOT_OFFHAND; + break; + case ARMOR: + if ((this.equipFlag & 2) != 0) + slotValue = MBServerStatics.SLOT_OFFHAND; + else if ((this.equipFlag & 4) != 0) + slotValue = MBServerStatics.SLOT_HELMET; + else if ((this.equipFlag & 8) != 0) + slotValue = MBServerStatics.SLOT_CHEST; + else if ((this.equipFlag & 16) != 0) + slotValue = MBServerStatics.SLOT_ARMS; + else if ((this.equipFlag & 32) != 0) + slotValue = MBServerStatics.SLOT_GLOVES; + else if ((this.equipFlag & 64) != 0) + slotValue = MBServerStatics.SLOT_RING2; + else if ((this.equipFlag & 128) != 0) + slotValue = MBServerStatics.SLOT_RING1; + else if ((this.equipFlag & 256) != 0) + slotValue = MBServerStatics.SLOT_NECKLACE; + else if ((this.equipFlag & 512) != 0) + slotValue = MBServerStatics.SLOT_LEGGINGS; + else if ((this.equipFlag & 1024) != 0) + slotValue = MBServerStatics.SLOT_FEET; + break; + + case HAIR: + if (this.equipFlag == 131072) + slotValue = MBServerStatics.SLOT_HAIRSTYLE; + else if (this.equipFlag == 65536) + slotValue = MBServerStatics.SLOT_BEARDSTYLE; + break; + + } + return slotValue; + + } + + public boolean validSlotFlag(long flags) { + + boolean validSlot = false; + + switch (this.type) { + case WEAPON: + if (this.isMelee()) + validSlot = ((flags & 1) != 0); + else if (this.isThrowing()) + validSlot = ((flags & 2) != 0); + else if (this.isArchery()) + validSlot = ((flags & 4) != 0); + else if (this.isScepter()) + validSlot = ((flags & 8) != 0); + else if (this.isStaff()) + validSlot = ((flags & 16) != 0); + break; + case JEWELRY: + if (this.isNecklace()) + validSlot = ((flags & 2147483648L) != 0L); + else + validSlot = ((flags & 4294967296L) != 0L); + break; + case ARMOR: + + if (this.isShield()) { + validSlot = ((flags & 32) != 0); + break; + } + + if (this.isClothArmor()) { + + if (this.getEquipFlag() == 4) //hood + validSlot = ((flags & 64) != 0); + else if (this.getEquipFlag() == 8) { + if ((restrictFlag & 512) != 0) //Robe + validSlot = ((flags & 128) != 0); + else + validSlot = ((flags & 1024) != 0); //Tunic/Shirt + + break; + } else if (this.getEquipFlag() == 16) //Sleeves + validSlot = ((flags & 2048) != 0); + else if (this.getEquipFlag() == 32) //Gloves + validSlot = ((flags & 512) != 0); + else if (this.getEquipFlag() == 512) //Pants + validSlot = ((flags & 4096) != 0); + else if (this.getEquipFlag() == 1024) //Boots + validSlot = ((flags & 256) != 0); + + break; + } + + if (this.isLightArmor()) { + if (this.getEquipFlag() == 4) //helm + validSlot = ((flags & 8192) != 0); + else if (this.getEquipFlag() == 8) //Chest + validSlot = ((flags & 16384) != 0); + else if (this.getEquipFlag() == 16) //Sleeves + validSlot = ((flags & 32768) != 0); + else if (this.getEquipFlag() == 32) //Gloves + validSlot = ((flags & 65536) != 0); + else if (this.getEquipFlag() == 512) //Pants + validSlot = ((flags & 131072) != 0); + else if (this.getEquipFlag() == 1024) //Boots + validSlot = ((flags & 262144) != 0); + + break; + } + + if (this.isMediumArmor()) { + if (this.getEquipFlag() == 4) //helm + validSlot = ((flags & 524288) != 0); + else if (this.getEquipFlag() == 8) //Chest + validSlot = ((flags & 1048576) != 0); + else if (this.getEquipFlag() == 16) //Sleeves + validSlot = ((flags & 2097152) != 0); + else if (this.getEquipFlag() == 32) //Gloves + validSlot = ((flags & 4194304) != 0); + else if (this.getEquipFlag() == 512) //Pants + validSlot = ((flags & 8388608) != 0); + else if (this.getEquipFlag() == 1024) //Boots + validSlot = ((flags & 16777216) != 0); + + break; + } + + if (this.isHeavyArmor()) + if (this.getEquipFlag() == 4) //helm + validSlot = ((flags & 33554432) != 0); + else if (this.getEquipFlag() == 8) //Chest + validSlot = ((flags & 67108864) != 0); + else if (this.getEquipFlag() == 16) //Sleeves + validSlot = ((flags & 134217728) != 0); + else if (this.getEquipFlag() == 32) //Gloves + validSlot = ((flags & 268435456) != 0); + else if (this.getEquipFlag() == 512) //Pants + validSlot = ((flags & 536870912) != 0); + else if (this.getEquipFlag() == 1024) //Boots + validSlot = ((flags & 1073741824) != 0); + break; + } + return validSlot; + } + + public boolean validForSlot(int slot, ConcurrentHashMap equipped, Item item) { + + boolean validSlot = false; + + if (equipped == null) + return validSlot; + + // Cannot equip an item in a slot already taken + if (equipped.get(slot) != null && equipped.get(slot).equals(item) == false) + return validSlot; + + switch (item.getItemBase().type) { + case WEAPON: + + // Only two slots available for weapons + if ((slot != MBServerStatics.SLOT_MAINHAND) && (slot != MBServerStatics.SLOT_OFFHAND)) + break; + + //make sure weapon is valid for slot + if ((slot & this.equipFlag) == 0) + break; + + // Two handed weapons take up two slots + if ((this.twoHanded == true) && + ((slot == MBServerStatics.SLOT_OFFHAND && equipped.get(MBServerStatics.SLOT_MAINHAND) != null) || + (slot == MBServerStatics.SLOT_MAINHAND && equipped.get(MBServerStatics.SLOT_OFFHAND) != null))) + break; + + // Validation passed, must be a valid weapon + + validSlot = true; + break; + case JEWELRY: + // Not a valid slot for ring + + if (this.isRing() && + ((slot != MBServerStatics.SLOT_RING1) && (slot != MBServerStatics.SLOT_RING2))) + break; + + // Not a valid slot for necklace + + if (this.isNecklace() && slot != MBServerStatics.SLOT_NECKLACE) + break; + + // Passed validation, must be valid bling bling + + validSlot = true; + break; + case ARMOR: + + // Invalid slot for armor? + if (slot == MBServerStatics.SLOT_OFFHAND && ((2 & this.equipFlag) == 0)) + break; + if (slot == MBServerStatics.SLOT_HELMET && ((4 & this.equipFlag) == 0)) + break; + if (slot == MBServerStatics.SLOT_CHEST && ((8 & this.equipFlag) == 0)) + break; + if (slot == MBServerStatics.SLOT_ARMS && ((16 & this.equipFlag) == 0)) + break; + if (slot == MBServerStatics.SLOT_GLOVES && ((32 & this.equipFlag) == 0)) + break; + if (slot == MBServerStatics.SLOT_LEGGINGS && ((512 & this.equipFlag) == 0)) + break; + if (slot == MBServerStatics.SLOT_FEET && ((1024 & this.equipFlag) == 0)) + break; + + // Is slot for this piece already taken? + if (((this.restrictFlag & 2) != 0) && (equipped.get(MBServerStatics.SLOT_OFFHAND) != null) && slot != MBServerStatics.SLOT_OFFHAND) + break; + if (((this.restrictFlag & 4) != 0) && (equipped.get(MBServerStatics.SLOT_HELMET) != null) && slot != MBServerStatics.SLOT_HELMET) + break; + if (((this.restrictFlag & 8) != 0) && (equipped.get(MBServerStatics.SLOT_CHEST) != null) && slot != MBServerStatics.SLOT_CHEST) + break; + if (((this.restrictFlag & 16) != 0) && (equipped.get(MBServerStatics.SLOT_ARMS) != null) && slot != MBServerStatics.SLOT_ARMS) + break; + if (((this.restrictFlag & 32) != 0) && (equipped.get(MBServerStatics.SLOT_GLOVES) != null) && slot != MBServerStatics.SLOT_GLOVES) + break; + if (((this.restrictFlag & 512) != 0) && (equipped.get(MBServerStatics.SLOT_LEGGINGS) != null) && slot != MBServerStatics.SLOT_LEGGINGS) + break; + if (((this.restrictFlag & 1024) != 0) && (equipped.get(MBServerStatics.SLOT_FEET) != null) && slot != MBServerStatics.SLOT_FEET) + break; + + // Passed validation. Is a valid armor piece + + validSlot = true; + break; + } + return validSlot; + } + + /** + * @return the uuid + */ + public final int getUUID() { + return uuid; + } + + public boolean isRing() { + return ((this.equipFlag & (64 | 128 | 192)) != 0); + } + + public boolean isNecklace() { + return (this.equipFlag == 256); + } + + public boolean isShield() { + return this.type.equals(ItemType.ARMOR) && this.equipFlag == 2; + } + + public boolean isLightArmor() { + return this.skillRequired.equals("Wear Armor, Light"); + } + + public boolean isMediumArmor() { + return this.skillRequired.equals("Wear Armor, Medium"); + } + + public boolean isHeavyArmor() { + return this.skillRequired.equals("Wear Armor, Heavy"); + } + + public boolean isClothArmor() { + return this.skillRequired.isEmpty(); + } + + public boolean isThrowing() { + return this.mastery.equals("Throwing") ? true : false; + } + + public boolean isStaff() { + return this.mastery.equals("Staff") ? true : false; + } + + public boolean isScepter() { + return this.mastery.equals("Benediction") ? true : false; + } + + public boolean isArchery() { + return this.mastery.equals("Archery") ? true : false; + } + + public boolean isMelee() { + return (this.isThrowing() == false && this.isStaff() == false && this.isScepter() == false && this.isArchery() == false); + } + + public boolean isTwoHanded() { + return this.twoHanded; + } + + /** + * @return the restrictFlag + */ + public int getRestrictFlag() { + return restrictFlag; + } + + /** + * @return the slashResist + */ + public float getSlashResist() { + return slashResist; + } + + /** + * @return the crushResist + */ + public float getCrushResist() { + return crushResist; + } + + /** + * @return the pierceResist + */ + public float getPierceResist() { + return pierceResist; + } + + /** + * @return the skillRequired + */ + public String getSkillRequired() { + return skillRequired; + } + + /** + * @return the mastery + */ + public String getMastery() { + return mastery; + } + + /** + * @return the blockMod + */ + public float getBlockMod() { + return blockMod; + } + + /** + * @return the defense + */ + public short getDefense() { + return defense; + } + + /** + * @return the dexPenalty + */ + public float getDexPenalty() { + return dexPenalty; + } + + /** + * @return the speed + */ + public float getSpeed() { + return speed; + } + + /** + * @return the range + */ + public float getRange() { + return range; + } + + /** + * @return the isStrBased + */ + public boolean isStrBased() { + return isStrBased; + } + + /** + * @return the parryBonus + */ + public float getParryBonus() { + return parryBonus; + } + + /** + * @return the maxDamage + */ + public short getMaxDamage() { + return maxDamage; + } + + /** + * @return the minDamage + */ + public short getMinDamage() { + return minDamage; + } + + /** + * @return the damageType + */ + public engine.Enum.DamageType getDamageType() { + return damageType; + } + + public short getPercentRequired() { + return percentRequired; + } + + public ArrayList getAnimations() { + return animations; + } + + public void setAnimations(ArrayList animations) { + this.animations = animations; + } + + public ArrayList getOffHandAnimations() { + return offHandAnimations; + } + + public void setOffHandAnimations(ArrayList offHandAnimations) { + this.offHandAnimations = offHandAnimations; + } + + public boolean isAutoID() { + return autoID; + } + + public void setAutoID(boolean autoID) { + this.autoID = autoID; + } } diff --git a/src/engine/objects/ItemContainer.java b/src/engine/objects/ItemContainer.java index 558fb3f5..db984558 100644 --- a/src/engine/objects/ItemContainer.java +++ b/src/engine/objects/ItemContainer.java @@ -7,7 +7,7 @@ // www.magicbane.com - package engine.objects; +package engine.objects; import engine.Enum.ContainerType; import engine.server.MBServerStatics; @@ -20,83 +20,83 @@ import java.util.concurrent.ConcurrentHashMap; public class ItemContainer extends AbstractGameObject { - private AbstractWorldObject owner; - private ConcurrentHashMapitemMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - - private ContainerType containerType; - - /** - * No Table ID Constructor - */ - public ItemContainer(AbstractWorldObject owner, ContainerType containerType) { - super(); - this.owner = owner; - this.containerType = containerType; - } - - /** - * Normal Constructor - */ - public ItemContainer(AbstractWorldObject owner, ContainerType containerType, int newUUID) { - super(newUUID); - this.owner = owner; - this.containerType = containerType; - } - - /** - * ResultSet Constructor - */ - public ItemContainer(ResultSet rs) throws SQLException { - super(rs); - - //get owner - long ownerID = rs.getLong("parent"); - this.owner = (AbstractWorldObject)AbstractGameObject.getFromTypeAndID(ownerID); - - //get ContainerType - String ct = rs.getString("container_type"); - try { - this.containerType = ContainerType.valueOf(ct.toUpperCase()); - } catch (Exception e) { - this.containerType = ContainerType.INVENTORY; - Logger.error( "invalid containerType"); - } - } - - /* - * Getters - */ - public AbstractWorldObject getOwner() { - return this.owner; - } - - public ConcurrentHashMap getItemMap() { - return this.itemMap; - } - - public ContainerType getContainerType() { - return this.containerType; - } - - public boolean isBank() { - return (this.containerType == ContainerType.BANK); - } - - public boolean isInventory() { - return (this.containerType == ContainerType.INVENTORY); - } - - public boolean isVault() { - return (this.containerType == ContainerType.VAULT); - } - - public boolean containsItem(long itemID) { - return this.itemMap.containsKey(itemID); - } - - @Override - public void updateDatabase() { - // TODO Create update logic. - } + private AbstractWorldObject owner; + private ConcurrentHashMap itemMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + + private ContainerType containerType; + + /** + * No Table ID Constructor + */ + public ItemContainer(AbstractWorldObject owner, ContainerType containerType) { + super(); + this.owner = owner; + this.containerType = containerType; + } + + /** + * Normal Constructor + */ + public ItemContainer(AbstractWorldObject owner, ContainerType containerType, int newUUID) { + super(newUUID); + this.owner = owner; + this.containerType = containerType; + } + + /** + * ResultSet Constructor + */ + public ItemContainer(ResultSet rs) throws SQLException { + super(rs); + + //get owner + long ownerID = rs.getLong("parent"); + this.owner = (AbstractWorldObject) AbstractGameObject.getFromTypeAndID(ownerID); + + //get ContainerType + String ct = rs.getString("container_type"); + try { + this.containerType = ContainerType.valueOf(ct.toUpperCase()); + } catch (Exception e) { + this.containerType = ContainerType.INVENTORY; + Logger.error("invalid containerType"); + } + } + + /* + * Getters + */ + public AbstractWorldObject getOwner() { + return this.owner; + } + + public ConcurrentHashMap getItemMap() { + return this.itemMap; + } + + public ContainerType getContainerType() { + return this.containerType; + } + + public boolean isBank() { + return (this.containerType == ContainerType.BANK); + } + + public boolean isInventory() { + return (this.containerType == ContainerType.INVENTORY); + } + + public boolean isVault() { + return (this.containerType == ContainerType.VAULT); + } + + public boolean containsItem(long itemID) { + return this.itemMap.containsKey(itemID); + } + + @Override + public void updateDatabase() { + // TODO Create update logic. + } } diff --git a/src/engine/objects/ItemFactory.java b/src/engine/objects/ItemFactory.java index 33d93d8c..4e0cc8dd 100644 --- a/src/engine/objects/ItemFactory.java +++ b/src/engine/objects/ItemFactory.java @@ -29,1171 +29,1163 @@ import java.util.concurrent.ThreadLocalRandom; public class ItemFactory { - public static void fillInventory(PlayerCharacter pc, int objectID, int count) { + public static void fillInventory(PlayerCharacter pc, int objectID, int count) { - if(pc == null) - return; + if (pc == null) + return; - int max = 20; - CharacterItemManager itemManager = pc.getCharItemManager(); - ItemBase ib = ItemBase.getItemBase(objectID); - if (count > max) - count = max; + int max = 20; + CharacterItemManager itemManager = pc.getCharItemManager(); + ItemBase ib = ItemBase.getItemBase(objectID); + if (count > max) + count = max; - ClientConnection cc = pc.getClientConnection(); + ClientConnection cc = pc.getClientConnection(); - if(itemManager == null || ib == null || cc == null) - return; + if (itemManager == null || ib == null || cc == null) + return; - boolean worked; - for (int i = 0; i < count; i++) { - worked = false; + boolean worked; + for (int i = 0; i < count; i++) { + worked = false; - if(!itemManager.hasRoomInventory(ib.getWeight())) { - if (pc != null) - ChatManager.chatSystemInfo(pc, "You can not carry any more of that item."); - break; - } + if (!itemManager.hasRoomInventory(ib.getWeight())) { + if (pc != null) + ChatManager.chatSystemInfo(pc, "You can not carry any more of that item."); + break; + } - Item item = new Item(ib, pc.getObjectUUID(), OwnerType.PlayerCharacter, (byte) 0, (byte) 0, - (short) 1, (short) 1, true, false, ItemContainerType.INVENTORY, (byte) 0, - new ArrayList<>(),""); - try { - item = DbManager.ItemQueries.ADD_ITEM(item); - worked = true; - } catch (Exception e) { - Logger.error(e); - } - if (worked) { - itemManager.addItemToInventory(item); - } - } - itemManager.updateInventory(); - } - public static Item fillForge(NPC npc, PlayerCharacter pc,int itemsToRoll, int itemID, int pToken, int sToken, String customName) { - - String prefixString = ""; - String suffixString = ""; - if(npc == null) - return null; + Item item = new Item(ib, pc.getObjectUUID(), OwnerType.PlayerCharacter, (byte) 0, (byte) 0, + (short) 1, (short) 1, true, false, ItemContainerType.INVENTORY, (byte) 0, + new ArrayList<>(), ""); + try { + item = DbManager.ItemQueries.ADD_ITEM(item); + worked = true; + } catch (Exception e) { + Logger.error(e); + } + if (worked) { + itemManager.addItemToInventory(item); + } + } + itemManager.updateInventory(); + } + + public static Item fillForge(NPC npc, PlayerCharacter pc, int itemsToRoll, int itemID, int pToken, int sToken, String customName) { + + String prefixString = ""; + String suffixString = ""; + if (npc == null) + return null; - boolean useWarehouse = false; + boolean useWarehouse = false; - ItemBase ib = ItemBase.getItemBase(itemID); + ItemBase ib = ItemBase.getItemBase(itemID); - if (ib == null) - return null; + if (ib == null) + return null; - Building forge = npc.getBuilding(); + Building forge = npc.getBuilding(); - if (forge == null) - return null; + if (forge == null) + return null; + if (!npc.getCharItemManager().hasRoomInventory(ib.getWeight())) { + if (pc != null) + ErrorPopupMsg.sendErrorPopup(pc, 21); + return null; + } - if (!npc.getCharItemManager().hasRoomInventory(ib.getWeight())){ - if (pc!= null) - ErrorPopupMsg.sendErrorPopup(pc, 21); - return null; - } + Zone zone = npc.getBuilding().getParentZone(); - Zone zone = npc.getBuilding().getParentZone(); + if (zone == null) + return null; - if (zone == null) - return null; + City city = City.getCity(zone.getPlayerCityUUID()); - City city = City.getCity(zone.getPlayerCityUUID()); + if (city == null) + return null; + MobLoot ml = null; + city.transactionLock.writeLock().lock(); - if (city == null) - return null; - MobLoot ml = null; - city.transactionLock.writeLock().lock(); + try { + Warehouse cityWarehouse = city.getWarehouse(); - try{ - Warehouse cityWarehouse = city.getWarehouse(); + if (cityWarehouse != null && forge.assetIsProtected()) + useWarehouse = true; + // ROLL BANE SCROLL. - if (cityWarehouse != null && forge.assetIsProtected()) - useWarehouse = true; - // ROLL BANE SCROLL. + if (ib.getUUID() > 910010 && ib.getUUID() < 910019) { + ConcurrentHashMap resources = cityWarehouse.getResources(); - if (ib.getUUID() > 910010 && ib.getUUID() < 910019){ - ConcurrentHashMap resources = cityWarehouse.getResources(); + int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, ib.getBaseValue()); + int overdraft = BuildingManager.GetOverdraft(forge, ib.getBaseValue()); + if (overdraft > 0 && !useWarehouse) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + " " + ib.getName()); + return null; + } - int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, ib.getBaseValue()); - int overdraft = BuildingManager.GetOverdraft(forge, ib.getBaseValue()); + if (overdraft > 0 && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + " " + ib.getName()); + return null; + } + + if (overdraft > resources.get(ItemBase.GOLD_ITEM_BASE)) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + " " + ib.getName()); + return null; + } + + //All checks passed, lets withdraw from building first. + + // if (pc != null){ + // ChatManager.chatGuildInfo(pc.getGuild(), "Building withdraw = " + buildingWithdraw); + // ChatManager.chatGuildInfo(pc.getGuild(), "Warehouse overdraft withdraw = " + overdraft); + // + // ChatManager.chatGuildInfo(pc.getGuild(), "total withdraw = " + (overdraft + buildingWithdraw)); + // } + + if (!forge.transferGold(-buildingWithdraw, false)) { + overdraft += buildingWithdraw; + + if (!useWarehouse) { + ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + ib.getName()); + return null; + } else { + if (overdraft > resources.get(ItemBase.GOLD_ITEM_BASE)) { + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + ib.getName()); + return null; + } + } + } + + if (overdraft > 0) + if (!cityWarehouse.withdraw(npc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) { + //ChatManager.chatGuildError(pc, "Failed to create Item"); + Logger.error("Warehouse With UID of " + cityWarehouse.getUID() + " Failed to Create Item." + ib.getName()); + return null; + } - if (overdraft > 0 && !useWarehouse){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + " " + ib.getName()); - return null; - } - if (overdraft > 0 && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + " " + ib.getName()); - return null; - } + ml = new MobLoot(npc, ib, false); + + + ml.containerType = Enum.ItemContainerType.FORGE; + ml.setValue(0); + ml.loadEnchantments(); + + float time; + float rank = npc.getBuilding().getRank() - 1; + float rate = (float) (2.5 * rank); + time = (20 - rate); + time *= MBServerStatics.ONE_MINUTE; + + if (ml.getItemBase().getUUID() > 910010 && ml.getItemBase().getUUID() < 910019) { + rank = ml.getItemBaseID() - 910010; + time = rank * 60 * 60 * 3 * 1000; + + } + + // No job is submitted, as object's upgradetime field + // is used to determin whether or not an object has + // compelted rolling. The game object exists previously + // to this, not when 'compelte' is pressed. + long upgradeTime = System.currentTimeMillis() + (long) (time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue())); + + DateTime dateTime = new DateTime(); + dateTime = dateTime.withMillis(upgradeTime); + ml.setDateToUpgrade(upgradeTime); + + npc.addItemToForge(ml); + + int playerID = 0; + + if (pc != null) + playerID = pc.getObjectUUID(); + DbManager.NPCQueries.ADD_TO_PRODUCTION_LIST(ml.getObjectUUID(), npc.getObjectUUID(), ml.getItemBaseID(), dateTime, "", "", "", false, playerID); + ProducedItem pi = new ProducedItem(ml.getObjectUUID(), npc.getObjectUUID(), ml.getItemBaseID(), dateTime, false, "", "", "", playerID); + pi.setProducedItemID(ml.getObjectUUID()); + pi.setAmount(itemsToRoll); + pi.setRandom(false); + + ItemQueue produced = ItemQueue.borrow(pi, (long) (time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue()))); + ItemProductionManager.send(produced); + + return ml; + } + + + int galvorAmount = 0; + int wormwoodAmount = 0; + int prefixCost = 0; + int suffixCost = 0; + + + if (ib.getType() == ItemType.WEAPON && ib.getPercentRequired() == 110) { + switch (ib.getSkillRequired()) { + case "Bow": + case "Crossbow": + case "Spear": + case "Pole Arm": + case "Staff": + wormwoodAmount = 20; + break; + case "Axe": + case "Dagger": + case "Sword": + case "Hammer": + case "Unarmed Combat": + + if (ib.isTwoHanded()) + galvorAmount = 20; + else + galvorAmount = 10; + break; + } + } + + ItemBase galvor = ItemBase.getItemBase(1580017); + ItemBase wormwood = ItemBase.getItemBase(1580018); + + if (galvorAmount > 0 || wormwoodAmount > 0) + if (!useWarehouse) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "This item requires resources to roll! Please make sure the forge is protected to access the warehouse." + ib.getName()); + return null; + + } + + if (galvorAmount > 0) { + if (cityWarehouse.isResourceLocked(galvor)) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + ib.getName()); + return null; + } + + if (cityWarehouse.getResources().get(galvor) < galvorAmount) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item." + ib.getName()); + return null; + } + } + + if (wormwoodAmount > 0) { + if (cityWarehouse.isResourceLocked(wormwood)) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Wormwood is locked." + ib.getName()); + return null; + } + + if (cityWarehouse.getResources().get(wormwood) < wormwoodAmount) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Wormwood in warehouse to roll this item." + ib.getName()); + return null; + } + } + ConcurrentHashMap suffixResourceCosts = null; + ConcurrentHashMap prefixResourceCosts = null; + EffectsBase prefix = null; + if (pToken != 0) { + + if (!useWarehouse) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Forge cannot access warehouse! Check to make sure forge is protected." + ib.getName()); + return null; + } + prefix = PowersManager.getEffectByToken(pToken); + if (prefix == null) + return null; + EffectsBase prefixValue = PowersManager.getEffectByIDString(prefix.getIDString() + 'A'); + if (prefixValue == null) + return null; + + int baseCost = ib.getBaseValue(); + int effectCost = (int) prefixValue.getValue(); + int total = baseCost * 10 + effectCost; + + prefixCost = effectCost; + int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, total); + int overdraft = BuildingManager.GetOverdraft(forge, total); + + if (overdraft > 0 && !useWarehouse) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + ib.getName()); + return null; + } + + if (overdraft > 0 && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName()); + return null; + } + + if (overdraft > cityWarehouse.getResources().get(ItemBase.GOLD_ITEM_BASE)) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + ib.getName()); + return null; + } + prefixResourceCosts = prefix.getResourcesForEffect(); + for (ItemBase ibResources : prefixResourceCosts.keySet()) { + int warehouseAmount = cityWarehouse.getResources().get(ibResources); + int creationAmount = prefixResourceCosts.get(ibResources); + //ChatManager.chatInfoError(pc, "Prefix : " + ibResources.getName() + " / " + creationAmount); + if (warehouseAmount < creationAmount) { + //ChatManager.chatInfoError(pc, "You need at least " + creationAmount + " " + ibResources.getName() + " to Create this item."); + return null; + } + + } + } + + EffectsBase suffix = null; + if (sToken != 0) { + + if (!useWarehouse) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Forge cannot access warehouse! Check to make sure forge is protected." + ib.getName()); + return null; + } + suffix = PowersManager.getEffectByToken(sToken); + if (suffix == null) + return null; + EffectsBase suffixValue = PowersManager.getEffectByIDString(suffix.getIDString() + 'A'); + if (suffixValue == null) + return null; + suffixResourceCosts = suffix.getResourcesForEffect(); + int baseCost = ib.getBaseValue(); + int effectCost = (int) suffixValue.getValue(); + suffixCost = effectCost; + int total = baseCost * 10 + effectCost; + + + // int buildingWithdraw = Building.GetWithdrawAmountForRolling(forge, total); + int overdraft = BuildingManager.GetOverdraft(forge, total); + + if (overdraft > 0 && !useWarehouse) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + ib.getName()); + return null; + } + + if (overdraft > 0 && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName()); + return null; + } + + if (overdraft > cityWarehouse.getResources().get(ItemBase.GOLD_ITEM_BASE)) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + ib.getName()); + return null; + } + + + for (ItemBase ibResources : suffixResourceCosts.keySet()) { + int warehouseAmount = cityWarehouse.getResources().get(ibResources); + int creationAmount = suffixResourceCosts.get(ibResources); + if (warehouseAmount < creationAmount) { + // if (pc != null) + // ChatManager.chatInfoError(pc, "You need at least " + creationAmount + " " + ibResources.getName() + " to Create this item."); + return null; + } + + + } + + } + + + //Check if Total suffix and prefix costs + itemCost can be withdrawn. + int costToCreate = suffixCost + prefixCost + (ib.getBaseValue()); + int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, costToCreate); + + int overdraft = BuildingManager.GetOverdraft(forge, costToCreate); + + if (overdraft > 0 && !useWarehouse) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + ib.getName()); + return null; + } + + if (overdraft > 0 && useWarehouse && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName()); + return null; + } + + if (useWarehouse && overdraft > cityWarehouse.getResources().get(ItemBase.GOLD_ITEM_BASE)) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + ib.getName()); + return null; + } + + // if (pc != null){ + // ChatManager.chatGuildInfo(pc.getGuild(), "Building withdraw = " + buildingWithdraw); + // ChatManager.chatGuildInfo(pc.getGuild(), "Warehouse overdraft withdraw = " + overdraft); + // + // ChatManager.chatGuildInfo(pc.getGuild(), "total withdraw = " + (overdraft + buildingWithdraw)); + // } + + if (!forge.transferGold(-buildingWithdraw, false)) { + overdraft += buildingWithdraw; + + if (!useWarehouse) { + ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + ib.getName()); + return null; + } else { + if (overdraft > cityWarehouse.getResources().get(ItemBase.GOLD_ITEM_BASE)) { + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + ib.getName()); + return null; + } + } + } + + if (overdraft > 0 && useWarehouse) + if (!cityWarehouse.withdraw(npc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) { + //ChatManager.chatGuildError(pc, "Failed to create Item"); + Logger.error("Warehouse With UID of " + cityWarehouse.getUID() + " Failed to Create Item." + ib.getName()); + return null; + } + + + if (prefix != null) { + + if (!useWarehouse) { + ErrorPopupMsg.sendErrorMsg(pc, "Cannot Resource Roll without access to the warehouse! Make sure the forge is currently protected." + ib.getName()); + return null; + } + + + for (ItemBase ibResources : prefixResourceCosts.keySet()) { + + int creationAmount = prefixResourceCosts.get(ibResources); + + if (cityWarehouse.isResourceLocked(ibResources) == true) + return null; + + int oldAmount = cityWarehouse.getResources().get(ibResources); + int amount = creationAmount; + + if (oldAmount < amount) + amount = oldAmount; + + if (!cityWarehouse.withdraw(npc, ibResources, amount, false, true)) { + //ChatManager.chatGuildError(pc, "Failed to create Item"); + Logger.error("Warehouse With UID of " + cityWarehouse.getUID() + " Failed to Create Item." + ib.getName()); + return null; + } + } + } + + if (suffix != null) { + + for (ItemBase ibResources : suffixResourceCosts.keySet()) { + int creationAmount = suffixResourceCosts.get(ibResources); + + if (cityWarehouse.isResourceLocked(ibResources) == true) { + ChatManager.chatSystemError(pc, ibResources.getName() + " is locked!" + ib.getName()); + return null; + } + + int oldAmount = cityWarehouse.getResources().get(ibResources); + int amount = creationAmount; + if (oldAmount < amount) + amount = oldAmount; + if (!cityWarehouse.withdraw(npc, ibResources, amount, false, true)) { + //ChatManager.chatGuildError(pc, "Failed to create Item"); + Logger.error("Warehouse With UID of " + cityWarehouse.getUID() + " Failed to Create Item." + ib.getName()); + return null; + } + } + } + + if (prefix == null && suffix == null) { + + int baseCost = ib.getBaseValue(); + int total = (int) (baseCost + baseCost * (float) .10); + + buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, total); + + overdraft = BuildingManager.GetOverdraft(forge, total); + + if (overdraft > 0 && !useWarehouse) { + + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + ib.getName()); + return null; + } + + if (overdraft > 0 && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)) { + + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName()); + return null; + } + + if (useWarehouse && overdraft > cityWarehouse.getResources().get(ItemBase.GOLD_ITEM_BASE)) { + + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + ib.getName()); + return null; + } + } + + if (!forge.transferGold(-buildingWithdraw, false)) { + overdraft += buildingWithdraw; + + if (!useWarehouse) { + ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + ib.getName()); + return null; + } else { + if (overdraft > cityWarehouse.getResources().get(ItemBase.GOLD_ITEM_BASE)) { + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + ib.getName()); + return null; + } + } + } + + if (overdraft > 0) + if (!cityWarehouse.withdraw(npc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) { + //ChatManager.chatGuildError(pc, "Failed to create Item"); + Logger.error("Warehouse With UID of " + cityWarehouse.getUID() + " Failed to Create Item." + ib.getName()); + return null; + } + + // ChatManager.chatGuildInfo(pc, "Gold Cost = " + total); + + if (galvorAmount > 0) { + if (!cityWarehouse.withdraw(npc, galvor, galvorAmount, false, true)) { + ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Galvor from warehouse!" + ib.getName()); + Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); + return null; + } + } + + if (wormwoodAmount > 0) { + if (!cityWarehouse.withdraw(npc, wormwood, wormwoodAmount, false, true)) { + ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Wormwood from warehouse!" + ib.getName()); + Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); + return null; + } + } + + ml = new MobLoot(npc, ib, false); + + ml.containerType = Enum.ItemContainerType.FORGE; + ml.setName(customName); + + if (prefix != null) { + ml.addPermanentEnchantment(prefix.getIDString(), 0, 0, true); + ml.setPrefix(prefix.getIDString()); + prefixString = prefix.getIDString(); + } + + if (suffix != null) { + ml.addPermanentEnchantment(suffix.getIDString(), 0, 0, false); + ml.setSuffix(suffix.getIDString()); + suffixString = suffix.getIDString(); + } + + ml.loadEnchantments(); + //set value to 0 so magicvalue can be recalculated in getValue. + ml.setValue(0); + + + float time; + float rank = npc.getBuilding().getRank() - 1; + float rate = (float) (2.5 * rank); + time = (20 - rate); + time *= MBServerStatics.ONE_MINUTE; + + if (ml.getItemBase().getUUID() > 910010 && ml.getItemBase().getUUID() < 910019) { + rank = ml.getItemBaseID() - 910010; + time = rank * 60 * 60 * 3 * 1000; + } - if (overdraft > resources.get(ItemBase.GOLD_ITEM_BASE)){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + " " + ib.getName()); - return null; - } - //All checks passed, lets withdraw from building first. + // No job is submitted, as object's upgradetime field + // is used to determin whether or not an object has + // compelted rolling. The game object exists previously + // to this, not when 'compelte' is pressed. + long upgradeTime = System.currentTimeMillis() + (long) (time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue())); - // if (pc != null){ - // ChatManager.chatGuildInfo(pc.getGuild(), "Building withdraw = " + buildingWithdraw); - // ChatManager.chatGuildInfo(pc.getGuild(), "Warehouse overdraft withdraw = " + overdraft); - // - // ChatManager.chatGuildInfo(pc.getGuild(), "total withdraw = " + (overdraft + buildingWithdraw)); - // } + DateTime dateTime = new DateTime(); + dateTime = dateTime.withMillis(upgradeTime); + ml.setDateToUpgrade(upgradeTime); - if (!forge.transferGold(-buildingWithdraw,false)){ - overdraft += buildingWithdraw; - - if (!useWarehouse){ - ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item."+ ib.getName()); - return null; - }else{ - if (overdraft > resources.get(ItemBase.GOLD_ITEM_BASE)){ - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item."+ ib.getName()); - return null; - } - } - } + npc.addItemToForge(ml); + int playerID = 0; - if (overdraft > 0) - if(!cityWarehouse.withdraw(npc, ItemBase.GOLD_ITEM_BASE, overdraft, false,true)){ - //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error( "Warehouse With UID of " + cityWarehouse.getUID() + " Failed to Create Item."+ ib.getName()); - return null; - } + if (pc != null) + playerID = pc.getObjectUUID(); + DbManager.NPCQueries.ADD_TO_PRODUCTION_LIST(ml.getObjectUUID(), npc.getObjectUUID(), ml.getItemBaseID(), dateTime, prefixString, suffixString, ml.getCustomName(), false, playerID); + ProducedItem pi = new ProducedItem(npc.getRolling().size(), npc.getObjectUUID(), ml.getItemBaseID(), dateTime, false, prefixString, suffixString, ml.getCustomName(), playerID); + pi.setProducedItemID(ml.getObjectUUID()); + pi.setAmount(itemsToRoll); + ItemQueue produced = ItemQueue.borrow(pi, (long) (time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue()))); + ItemProductionManager.send(produced); + } catch (Exception e) { + Logger.error(e); + } finally { + city.transactionLock.writeLock().unlock(); + } + // npc.addItemToForge(item); + return ml; - ml = new MobLoot(npc, ib, false); - + } - ml.containerType = Enum.ItemContainerType.FORGE; - ml.setValue(0); - ml.loadEnchantments(); - float time; - float rank = npc.getBuilding().getRank() - 1; - float rate = (float) (2.5 * rank); - time = (20 - rate); - time *= MBServerStatics.ONE_MINUTE; + public static Item randomRoll(NPC vendor, PlayerCharacter pc, int itemsToRoll, int itemID) { + byte itemModTable; + int prefixMod = 0; + int suffixMod = 0; + LootTable prefixLootTable; + LootTable suffixLootTable; + String suffix = ""; + String prefix = ""; + MobLoot toRoll; - if (ml.getItemBase().getUUID() > 910010 && ml.getItemBase().getUUID() < 910019){ - rank = ml.getItemBaseID() - 910010; - time = rank * 60 * 60 * 3 * 1000; - - } - - // No job is submitted, as object's upgradetime field - // is used to determin whether or not an object has - // compelted rolling. The game object exists previously - // to this, not when 'compelte' is pressed. - long upgradeTime = System.currentTimeMillis() + (long)(time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue())); - - DateTime dateTime = new DateTime(); - dateTime = dateTime.withMillis(upgradeTime); - ml.setDateToUpgrade(upgradeTime); - - npc.addItemToForge(ml); - - int playerID = 0; - - if (pc != null) - playerID = pc.getObjectUUID(); - DbManager.NPCQueries.ADD_TO_PRODUCTION_LIST(ml.getObjectUUID(),npc.getObjectUUID(), ml.getItemBaseID(), dateTime, "", "", "", false,playerID); - ProducedItem pi = new ProducedItem(ml.getObjectUUID(),npc.getObjectUUID(),ml.getItemBaseID(),dateTime,false,"", "", "",playerID); - pi.setProducedItemID(ml.getObjectUUID()); - pi.setAmount(itemsToRoll); - pi.setRandom(false); - - ItemQueue produced = ItemQueue.borrow(pi, (long) (time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue()))); - ItemProductionManager.send(produced); - - return ml; - } - - - - int galvorAmount = 0; - int wormwoodAmount = 0; - int prefixCost = 0; - int suffixCost = 0; - - - if (ib.getType() == ItemType.WEAPON && ib.getPercentRequired() == 110){ - switch (ib.getSkillRequired()){ - case "Bow": - case "Crossbow": - case "Spear": - case "Pole Arm": - case "Staff": - wormwoodAmount = 20; - break; - case "Axe": - case "Dagger": - case "Sword": - case "Hammer": - case "Unarmed Combat": - - if (ib.isTwoHanded()) - galvorAmount = 20; - else - galvorAmount = 10; - break; - } - } - - ItemBase galvor = ItemBase.getItemBase(1580017); - ItemBase wormwood = ItemBase.getItemBase(1580018); - - if (galvorAmount > 0 || wormwoodAmount > 0) - if (!useWarehouse){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "This item requires resources to roll! Please make sure the forge is protected to access the warehouse."+ ib.getName()); - return null; - - } - - if (galvorAmount > 0){ - if (cityWarehouse.isResourceLocked(galvor)){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked."+ ib.getName()); - return null; - } - - if (cityWarehouse.getResources().get(galvor) < galvorAmount){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item."+ ib.getName()); - return null; - } - } - - if (wormwoodAmount > 0){ - if (cityWarehouse.isResourceLocked(wormwood)){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Wormwood is locked."+ ib.getName()); - return null; - } - - if (cityWarehouse.getResources().get(wormwood) < wormwoodAmount){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Wormwood in warehouse to roll this item."+ ib.getName()); - return null; - } - } - ConcurrentHashMap suffixResourceCosts = null; - ConcurrentHashMap prefixResourceCosts = null; - EffectsBase prefix = null; - if (pToken != 0){ - - if (!useWarehouse){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Forge cannot access warehouse! Check to make sure forge is protected."+ ib.getName()); - return null; - } - prefix = PowersManager.getEffectByToken(pToken); - if (prefix == null) - return null; - EffectsBase prefixValue = PowersManager.getEffectByIDString(prefix.getIDString() + 'A'); - if (prefixValue == null) - return null; - - int baseCost = ib.getBaseValue(); - int effectCost = (int) prefixValue.getValue(); - int total = baseCost * 10 + effectCost; - - prefixCost = effectCost; - int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, total); - int overdraft = BuildingManager.GetOverdraft(forge, total); - - if (overdraft > 0 && !useWarehouse){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox."+ ib.getName()); - return null; - } - - if (overdraft > 0 && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse."+ ib.getName()); - return null; - } - - if (overdraft > cityWarehouse.getResources().get(ItemBase.GOLD_ITEM_BASE)){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft."+ ib.getName()); - return null; - } - prefixResourceCosts = prefix.getResourcesForEffect(); - for (ItemBase ibResources: prefixResourceCosts.keySet()){ - int warehouseAmount = cityWarehouse.getResources().get(ibResources); - int creationAmount = prefixResourceCosts.get(ibResources); - //ChatManager.chatInfoError(pc, "Prefix : " + ibResources.getName() + " / " + creationAmount); - if (warehouseAmount < creationAmount){ - //ChatManager.chatInfoError(pc, "You need at least " + creationAmount + " " + ibResources.getName() + " to Create this item."); - return null; - } - - } - } - - EffectsBase suffix = null; - if (sToken != 0){ - - if (!useWarehouse){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Forge cannot access warehouse! Check to make sure forge is protected."+ ib.getName()); - return null; - } - suffix = PowersManager.getEffectByToken(sToken); - if (suffix == null) - return null; - EffectsBase suffixValue = PowersManager.getEffectByIDString(suffix.getIDString() + 'A'); - if (suffixValue == null) - return null; - suffixResourceCosts = suffix.getResourcesForEffect(); - int baseCost = ib.getBaseValue(); - int effectCost = (int) suffixValue.getValue(); - suffixCost = effectCost; - int total = baseCost * 10 + effectCost; - - - - // int buildingWithdraw = Building.GetWithdrawAmountForRolling(forge, total); - int overdraft = BuildingManager.GetOverdraft(forge, total); - - if (overdraft > 0 && !useWarehouse){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox."+ ib.getName()); - return null; - } - - if (overdraft > 0 && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse."+ ib.getName()); - return null; - } - - if (overdraft > cityWarehouse.getResources().get(ItemBase.GOLD_ITEM_BASE)){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft."+ ib.getName()); - return null; - } - - - for (ItemBase ibResources: suffixResourceCosts.keySet()){ - int warehouseAmount = cityWarehouse.getResources().get(ibResources); - int creationAmount = suffixResourceCosts.get(ibResources); - if (warehouseAmount < creationAmount){ - // if (pc != null) - // ChatManager.chatInfoError(pc, "You need at least " + creationAmount + " " + ibResources.getName() + " to Create this item."); - return null; - } - - - } - - } - - - //Check if Total suffix and prefix costs + itemCost can be withdrawn. - int costToCreate = suffixCost + prefixCost + (ib.getBaseValue()); - int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, costToCreate); - - int overdraft = BuildingManager.GetOverdraft(forge, costToCreate); - - if (overdraft > 0 && !useWarehouse){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox."+ ib.getName()); - return null; - } - - if (overdraft > 0 && useWarehouse && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse."+ ib.getName()); - return null; - } - - if (useWarehouse && overdraft > cityWarehouse.getResources().get(ItemBase.GOLD_ITEM_BASE)){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft."+ ib.getName()); - return null; - } - - // if (pc != null){ - // ChatManager.chatGuildInfo(pc.getGuild(), "Building withdraw = " + buildingWithdraw); - // ChatManager.chatGuildInfo(pc.getGuild(), "Warehouse overdraft withdraw = " + overdraft); - // - // ChatManager.chatGuildInfo(pc.getGuild(), "total withdraw = " + (overdraft + buildingWithdraw)); - // } - - if (!forge.transferGold(-buildingWithdraw,false)){ - overdraft += buildingWithdraw; - - if (!useWarehouse){ - ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item."+ ib.getName()); - return null; - }else{ - if (overdraft > cityWarehouse.getResources().get(ItemBase.GOLD_ITEM_BASE)){ - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item."+ ib.getName()); - return null; - } - } - } - - if (overdraft > 0 && useWarehouse) - if(!cityWarehouse.withdraw(npc, ItemBase.GOLD_ITEM_BASE, overdraft, false,true)){ - //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error("Warehouse With UID of " + cityWarehouse.getUID() + " Failed to Create Item."+ ib.getName()); - return null; - } - - - if (prefix != null){ - - if (!useWarehouse){ - ErrorPopupMsg.sendErrorMsg(pc, "Cannot Resource Roll without access to the warehouse! Make sure the forge is currently protected."+ ib.getName()); - return null; - } - - - for (ItemBase ibResources: prefixResourceCosts.keySet()){ - - int creationAmount = prefixResourceCosts.get(ibResources); - - if (cityWarehouse.isResourceLocked(ibResources) == true) - return null; - - int oldAmount = cityWarehouse.getResources().get(ibResources); - int amount = creationAmount; - - if (oldAmount < amount) - amount = oldAmount; - - if(!cityWarehouse.withdraw(npc, ibResources, amount, false,true)){ - //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error("Warehouse With UID of " + cityWarehouse.getUID() + " Failed to Create Item."+ ib.getName()); - return null; - } - } - } - - if (suffix != null) { - - for (ItemBase ibResources: suffixResourceCosts.keySet()){ - int creationAmount = suffixResourceCosts.get(ibResources); - - if (cityWarehouse.isResourceLocked(ibResources) == true) { - ChatManager.chatSystemError(pc, ibResources.getName() + " is locked!"+ ib.getName()); - return null; - } - - int oldAmount = cityWarehouse.getResources().get(ibResources); - int amount = creationAmount; - if (oldAmount < amount) - amount = oldAmount; - if(!cityWarehouse.withdraw(npc, ibResources, amount, false,true)){ - //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error( "Warehouse With UID of " + cityWarehouse.getUID() + " Failed to Create Item."+ ib.getName()); - return null; - } - } - } - - if (prefix == null && suffix == null){ - - int baseCost = ib.getBaseValue(); - int total = (int) (baseCost + baseCost *(float).10); - - buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, total); - - overdraft = BuildingManager.GetOverdraft(forge, total); - - if (overdraft > 0 && !useWarehouse){ - - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox."+ ib.getName()); - return null; - } - - if (overdraft > 0 && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)){ - - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse."+ ib.getName()); - return null; - } - - if (useWarehouse && overdraft > cityWarehouse.getResources().get(ItemBase.GOLD_ITEM_BASE)){ - - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft."+ ib.getName()); - return null; - } } - - if (!forge.transferGold(-buildingWithdraw,false)){ - overdraft += buildingWithdraw; - - if (!useWarehouse){ - ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item."+ ib.getName()); - return null; - }else{ - if (overdraft > cityWarehouse.getResources().get(ItemBase.GOLD_ITEM_BASE)){ - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item."+ ib.getName()); - return null; - } - } - } - - if (overdraft > 0) - if(!cityWarehouse.withdraw(npc, ItemBase.GOLD_ITEM_BASE, overdraft, false,true)){ - //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error( "Warehouse With UID of " + cityWarehouse.getUID() + " Failed to Create Item."+ ib.getName()); - return null; - } - - // ChatManager.chatGuildInfo(pc, "Gold Cost = " + total); - - if (galvorAmount > 0){ - if (!cityWarehouse.withdraw(npc, galvor, galvorAmount, false,true)){ - ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Galvor from warehouse!"+ ib.getName()); - Logger.error( "Warehouse with UID of" + cityWarehouse.getObjectUUID()+ "Failed to Withdrawl "); - return null; - } - } - - if (wormwoodAmount > 0){ - if (!cityWarehouse.withdraw(npc, wormwood, wormwoodAmount, false,true)){ - ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Wormwood from warehouse!"+ ib.getName()); - Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID()+ "Failed to Withdrawl "); - return null; - } - } - - ml = new MobLoot(npc, ib, false); - - ml.containerType = Enum.ItemContainerType.FORGE; - ml.setName(customName); - - if (prefix != null){ - ml.addPermanentEnchantment(prefix.getIDString(), 0, 0, true); - ml.setPrefix(prefix.getIDString()); - prefixString = prefix.getIDString(); - } - - if (suffix != null){ - ml.addPermanentEnchantment(suffix.getIDString(), 0, 0, false); - ml.setSuffix(suffix.getIDString()); - suffixString = suffix.getIDString(); - } - - ml.loadEnchantments(); - //set value to 0 so magicvalue can be recalculated in getValue. - ml.setValue(0); - - - float time; - float rank = npc.getBuilding().getRank() - 1; - float rate = (float) (2.5 * rank); - time = (20 - rate); - time *= MBServerStatics.ONE_MINUTE; + ItemBase ib = ItemBase.getItemBase(itemID); - if (ml.getItemBase().getUUID() > 910010 && ml.getItemBase().getUUID() < 910019){ - rank = ml.getItemBaseID() - 910010; - time = rank * 60 * 60 * 3 * 1000; - } + if (ib == null) + return null; + if (!vendor.getCharItemManager().hasRoomInventory(ib.getWeight())) { + if (pc != null) + ChatManager.chatSystemInfo(pc, vendor.getName() + " " + vendor.getContract().getName() + " Inventory is full."); + return null; + } - // No job is submitted, as object's upgradetime field - // is used to determin whether or not an object has - // compelted rolling. The game object exists previously - // to this, not when 'compelte' is pressed. - long upgradeTime = System.currentTimeMillis() + (long)(time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue())) ; + float calculatedMobLevel; + calculatedMobLevel = vendor.getLevel(); - DateTime dateTime = new DateTime(); - dateTime = dateTime.withMillis(upgradeTime); - ml.setDateToUpgrade(upgradeTime); + if (calculatedMobLevel < 16) + calculatedMobLevel = 16; - npc.addItemToForge(ml); - int playerID = 0; - - if (pc != null) - playerID = pc.getObjectUUID(); + if (calculatedMobLevel > 49) + calculatedMobLevel = 49; - DbManager.NPCQueries.ADD_TO_PRODUCTION_LIST(ml.getObjectUUID(),npc.getObjectUUID(), ml.getItemBaseID(), dateTime, prefixString, suffixString, ml.getCustomName(), false,playerID); - ProducedItem pi = new ProducedItem(npc.getRolling().size(),npc.getObjectUUID(),ml.getItemBaseID(),dateTime,false,prefixString, suffixString, ml.getCustomName(),playerID); - pi.setProducedItemID(ml.getObjectUUID()); - pi.setAmount(itemsToRoll); - - ItemQueue produced = ItemQueue.borrow(pi, (long) (time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue()))); - ItemProductionManager.send(produced); - }catch(Exception e){ - Logger.error(e); - }finally{ - city.transactionLock.writeLock().unlock(); - } + itemModTable = (byte) ib.getModTable(); - + if (!vendor.getItemModTable().contains(itemModTable)) { + if (pc != null) + ErrorPopupMsg.sendErrorPopup(pc, 59); + return null; + } - // npc.addItemToForge(item); - return ml; + for (byte temp : vendor.getItemModTable()) { + if (itemModTable != temp) + continue; + prefixMod = vendor.getModTypeTable().get(vendor.getItemModTable().indexOf(temp)); + suffixMod = vendor.getModSuffixTable().get(vendor.getItemModTable().indexOf(temp)); + } - } + if (prefixMod == 0 && suffixMod == 0) { + Logger.info("Failed to find modTables for item " + ib.getName()); + return null; + } + prefixLootTable = LootTable.getModGroup(prefixMod); + suffixLootTable = LootTable.getModGroup(suffixMod); + if (prefixLootTable == null || suffixLootTable == null) + return null; - public static Item randomRoll( NPC vendor, PlayerCharacter pc, int itemsToRoll, int itemID){ - byte itemModTable; - int prefixMod = 0; - int suffixMod = 0; - LootTable prefixLootTable; - LootTable suffixLootTable; - String suffix = ""; - String prefix = ""; - MobLoot toRoll; + int rollPrefix = ThreadLocalRandom.current().nextInt(100); - ItemBase ib = ItemBase.getItemBase(itemID); + if (rollPrefix < 80) { + int randomPrefix = ThreadLocalRandom.current().nextInt(100) + 1; + LootRow prefixLootRow = prefixLootTable.getLootRow(randomPrefix); - if (ib == null) - return null; + if (prefixLootRow != null) { + LootTable prefixTypeTable = LootTable.getModTable(prefixLootRow.getValueOne()); - if (!vendor.getCharItemManager().hasRoomInventory(ib.getWeight())){ - if (pc != null) - ChatManager.chatSystemInfo(pc, vendor.getName() + " " +vendor.getContract().getName() + " Inventory is full." ); - return null; - } + int minRoll = (int) ((calculatedMobLevel - 5) * 5); + int maxRoll = (int) ((calculatedMobLevel + 15) * 5); - float calculatedMobLevel; - calculatedMobLevel = vendor.getLevel(); + if (minRoll < (int) prefixTypeTable.minRoll) + minRoll = (int) prefixTypeTable.minRoll; - if (calculatedMobLevel < 16) - calculatedMobLevel = 16; + if (maxRoll < minRoll) + maxRoll = minRoll; - if (calculatedMobLevel > 49) - calculatedMobLevel = 49; + if (maxRoll > prefixTypeTable.maxRoll) + maxRoll = (int) prefixTypeTable.maxRoll; - itemModTable = (byte) ib.getModTable(); + if (maxRoll > 320) + maxRoll = 320; - if (!vendor.getItemModTable().contains(itemModTable)){ - if (pc != null) - ErrorPopupMsg.sendErrorPopup(pc, 59); - return null; - } + int randomPrefix1 = (int) ThreadLocalRandom.current().nextDouble(minRoll, maxRoll + 1); //Does not return Max, but does return min? - for (byte temp: vendor.getItemModTable()){ - if (itemModTable != temp) - continue; - prefixMod = vendor.getModTypeTable().get(vendor.getItemModTable().indexOf(temp)); - suffixMod = vendor.getModSuffixTable().get(vendor.getItemModTable().indexOf(temp)); - } + if (randomPrefix1 < prefixTypeTable.minRoll) + randomPrefix1 = (int) prefixTypeTable.minRoll; - if (prefixMod == 0 && suffixMod == 0){ - Logger.info( "Failed to find modTables for item " + ib.getName()); - return null; - } + if (randomPrefix1 > prefixTypeTable.maxRoll) + randomPrefix1 = (int) prefixTypeTable.maxRoll; - prefixLootTable = LootTable.getModGroup(prefixMod); - suffixLootTable = LootTable.getModGroup(suffixMod); + LootRow prefixTypelootRow = prefixTypeTable.getLootRow(randomPrefix1); - if (prefixLootTable == null || suffixLootTable == null) - return null; + if (prefixTypelootRow == null) + prefixTypelootRow = prefixTypeTable.getLootRow((int) ((prefixTypeTable.maxRoll + prefixTypeTable.minRoll) * .05f)); - int rollPrefix = ThreadLocalRandom.current().nextInt(100); + if (prefixTypelootRow != null) { + prefix = prefixTypelootRow.getAction(); + } + } + } - if (rollPrefix < 80){ - int randomPrefix = ThreadLocalRandom.current().nextInt(100) + 1; - LootRow prefixLootRow = prefixLootTable.getLootRow(randomPrefix); + int rollSuffix = ThreadLocalRandom.current().nextInt(100); - if (prefixLootRow != null){ - LootTable prefixTypeTable = LootTable.getModTable(prefixLootRow.getValueOne()); + if (rollSuffix < 80) { - int minRoll = (int) ((calculatedMobLevel - 5) * 5); - int maxRoll = (int) ((calculatedMobLevel + 15) * 5); + int randomSuffix = ThreadLocalRandom.current().nextInt(100) + 1; + LootRow suffixLootRow = suffixLootTable.getLootRow(randomSuffix); - if (minRoll < (int)prefixTypeTable.minRoll) - minRoll = (int)prefixTypeTable.minRoll; + if (suffixLootRow != null) { - if (maxRoll < minRoll) - maxRoll = minRoll; + LootTable suffixTypeTable = LootTable.getModTable(suffixLootRow.getValueOne()); - if (maxRoll > prefixTypeTable.maxRoll) - maxRoll = (int) prefixTypeTable.maxRoll; + if (suffixTypeTable != null) { + int minRoll = (int) ((calculatedMobLevel - 5) * 5); + int maxRoll = (int) ((calculatedMobLevel + 15) * 5); - if (maxRoll > 320) - maxRoll = 320; + if (minRoll < (int) suffixTypeTable.minRoll) + minRoll = (int) suffixTypeTable.minRoll; - int randomPrefix1 = (int) ThreadLocalRandom.current().nextDouble(minRoll, maxRoll + 1); //Does not return Max, but does return min? + if (maxRoll < minRoll) + maxRoll = minRoll; - if (randomPrefix1 < prefixTypeTable.minRoll) - randomPrefix1 = (int) prefixTypeTable.minRoll; + if (maxRoll > suffixTypeTable.maxRoll) + maxRoll = (int) suffixTypeTable.maxRoll; - if (randomPrefix1 > prefixTypeTable.maxRoll) - randomPrefix1 = (int) prefixTypeTable.maxRoll; + if (maxRoll > 320) + maxRoll = 320; - LootRow prefixTypelootRow = prefixTypeTable.getLootRow(randomPrefix1); + int randomSuffix1 = (int) ThreadLocalRandom.current().nextDouble(minRoll, maxRoll + 1); //Does not return Max, but does return min? - if (prefixTypelootRow == null) - prefixTypelootRow = prefixTypeTable.getLootRow((int) ((prefixTypeTable.maxRoll + prefixTypeTable.minRoll) * .05f)); + if (randomSuffix1 < suffixTypeTable.minRoll) + randomSuffix1 = (int) suffixTypeTable.minRoll; - if (prefixTypelootRow != null){ - prefix = prefixTypelootRow.getAction(); - } - } - } + if (randomSuffix1 > suffixTypeTable.maxRoll) + randomSuffix1 = (int) suffixTypeTable.maxRoll; - int rollSuffix = ThreadLocalRandom.current().nextInt(100); + LootRow suffixTypelootRow = suffixTypeTable.getLootRow(randomSuffix1); - if (rollSuffix < 80){ + if (suffixTypelootRow != null) { + suffix = suffixTypelootRow.getAction(); + } + } + } + } - int randomSuffix = ThreadLocalRandom.current().nextInt(100) + 1; - LootRow suffixLootRow = suffixLootTable.getLootRow(randomSuffix); - - if (suffixLootRow != null){ + if (prefix.isEmpty() && suffix.isEmpty()) { - LootTable suffixTypeTable = LootTable.getModTable(suffixLootRow.getValueOne()); + rollPrefix = ThreadLocalRandom.current().nextInt(100); - if (suffixTypeTable != null){ - int minRoll = (int) ((calculatedMobLevel - 5) * 5); - int maxRoll = (int) ((calculatedMobLevel + 15) * 5); + if (rollPrefix < 50) { - if (minRoll < (int)suffixTypeTable.minRoll) - minRoll = (int)suffixTypeTable.minRoll; + int randomPrefix = ThreadLocalRandom.current().nextInt(100) + 1; + LootRow prefixLootRow = prefixLootTable.getLootRow(randomPrefix); - if (maxRoll < minRoll) - maxRoll = minRoll; + if (prefixLootRow != null) { - if (maxRoll > suffixTypeTable.maxRoll) - maxRoll = (int) suffixTypeTable.maxRoll; + LootTable prefixTypeTable = LootTable.getModTable(prefixLootRow.getValueOne()); - if (maxRoll > 320) - maxRoll = 320; + int minRoll = (int) ((calculatedMobLevel) * 5); + int maxRoll = (int) ((calculatedMobLevel + 15) * 5); - int randomSuffix1 = (int) ThreadLocalRandom.current().nextDouble(minRoll, maxRoll + 1); //Does not return Max, but does return min? + if (minRoll < (int) prefixTypeTable.minRoll) + minRoll = (int) prefixTypeTable.minRoll; - if (randomSuffix1 < suffixTypeTable.minRoll) - randomSuffix1 = (int) suffixTypeTable.minRoll; + if (maxRoll < minRoll) + maxRoll = minRoll; - if (randomSuffix1 > suffixTypeTable.maxRoll) - randomSuffix1 = (int) suffixTypeTable.maxRoll; + if (maxRoll > prefixTypeTable.maxRoll) + maxRoll = (int) prefixTypeTable.maxRoll; - LootRow suffixTypelootRow = suffixTypeTable.getLootRow(randomSuffix1); + if (maxRoll > 320) + maxRoll = 320; - if (suffixTypelootRow != null){ - suffix = suffixTypelootRow.getAction(); - } - } - } - } + int randomPrefix1 = (int) ThreadLocalRandom.current().nextDouble(minRoll, maxRoll + 1); //Does not return Max, but does return min? - if (prefix.isEmpty() && suffix.isEmpty()){ + if (randomPrefix1 < prefixTypeTable.minRoll) + randomPrefix1 = (int) prefixTypeTable.minRoll; - rollPrefix = ThreadLocalRandom.current().nextInt(100); + if (randomPrefix1 > prefixTypeTable.maxRoll) + randomPrefix1 = (int) prefixTypeTable.maxRoll; - if (rollPrefix < 50){ + LootRow prefixTypelootRow = prefixTypeTable.getLootRow(randomPrefix1); - int randomPrefix = ThreadLocalRandom.current().nextInt(100) + 1; - LootRow prefixLootRow = prefixLootTable.getLootRow(randomPrefix); + if (prefixTypelootRow == null) + prefixTypelootRow = prefixTypeTable.getLootRow((int) ((prefixTypeTable.maxRoll + prefixTypeTable.minRoll) * .05f)); - if (prefixLootRow != null){ + if (prefixTypelootRow != null) { + prefix = prefixTypelootRow.getAction(); + } + } + } else { + int randomSuffix = ThreadLocalRandom.current().nextInt(100) + 1; + LootRow suffixLootRow = suffixLootTable.getLootRow(randomSuffix); - LootTable prefixTypeTable = LootTable.getModTable(prefixLootRow.getValueOne()); + if (suffixLootRow != null) { - int minRoll = (int) ((calculatedMobLevel) * 5); - int maxRoll = (int) ((calculatedMobLevel + 15) * 5); + LootTable suffixTypeTable = LootTable.getModTable(suffixLootRow.getValueOne()); - if (minRoll < (int)prefixTypeTable.minRoll) - minRoll = (int)prefixTypeTable.minRoll; + if (suffixTypeTable != null) { - if (maxRoll < minRoll) - maxRoll = minRoll; + int minRoll = (int) ((calculatedMobLevel) * 5); + int maxRoll = (int) ((calculatedMobLevel + 15) * 5); - if (maxRoll > prefixTypeTable.maxRoll) - maxRoll = (int) prefixTypeTable.maxRoll; + if (minRoll < (int) suffixTypeTable.minRoll) + minRoll = (int) suffixTypeTable.minRoll; - if (maxRoll > 320) - maxRoll = 320; + if (maxRoll < minRoll) + maxRoll = minRoll; - int randomPrefix1 = (int) ThreadLocalRandom.current().nextDouble(minRoll, maxRoll + 1); //Does not return Max, but does return min? + if (maxRoll > suffixTypeTable.maxRoll) + maxRoll = (int) suffixTypeTable.maxRoll; - if (randomPrefix1 < prefixTypeTable.minRoll) - randomPrefix1 = (int) prefixTypeTable.minRoll; + if (maxRoll > 320) + maxRoll = 320; - if (randomPrefix1 > prefixTypeTable.maxRoll) - randomPrefix1 = (int) prefixTypeTable.maxRoll; + int randomSuffix1 = (int) ThreadLocalRandom.current().nextDouble(minRoll, maxRoll + 1); //Does not return Max, but does return min? - LootRow prefixTypelootRow = prefixTypeTable.getLootRow(randomPrefix1); + if (randomSuffix1 < suffixTypeTable.minRoll) + randomSuffix1 = (int) suffixTypeTable.minRoll; - if (prefixTypelootRow == null) - prefixTypelootRow = prefixTypeTable.getLootRow((int) ((prefixTypeTable.maxRoll + prefixTypeTable.minRoll) * .05f)); + if (randomSuffix1 > suffixTypeTable.maxRoll) + randomSuffix1 = (int) suffixTypeTable.maxRoll; - if (prefixTypelootRow != null){ - prefix = prefixTypelootRow.getAction(); - } - } - }else{ - int randomSuffix = ThreadLocalRandom.current().nextInt(100) + 1; - LootRow suffixLootRow = suffixLootTable.getLootRow(randomSuffix); + LootRow suffixTypelootRow = suffixTypeTable.getLootRow(randomSuffix1); - if (suffixLootRow != null){ + if (suffixTypelootRow != null) + suffix = suffixTypelootRow.getAction(); + } + } + } + } - LootTable suffixTypeTable = LootTable.getModTable(suffixLootRow.getValueOne()); + toRoll = ItemFactory.produceRandomRoll(vendor, pc, prefix, suffix, itemID); - if (suffixTypeTable != null){ + if (toRoll == null) + return null; - int minRoll = (int) ((calculatedMobLevel) * 5); - int maxRoll = (int) ((calculatedMobLevel + 15) * 5); + toRoll.setValue(0); - if (minRoll < (int)suffixTypeTable.minRoll) - minRoll = (int)suffixTypeTable.minRoll; + float time; + float rank = vendor.getBuilding().getRank() - 1; + float rate = (float) (2.5 * rank); + time = (20 - rate); + time *= MBServerStatics.ONE_MINUTE; - if (maxRoll < minRoll) - maxRoll = minRoll; + if (toRoll.getItemBase().getUUID() > 910010 && toRoll.getItemBase().getUUID() < 910019) { + rank = toRoll.getItemBaseID() - 910010; + time = rank * 60 * 60 * 3 * 1000; + } - if (maxRoll > suffixTypeTable.maxRoll) - maxRoll = (int) suffixTypeTable.maxRoll; + // No job is submitted, as object's upgradetime field + // is used to determin whether or not an object has + // compelted rolling. The game object exists previously + // to this, not when 'compelte' is pressed. + long upgradeTime = System.currentTimeMillis() + (long) (time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue())); - if (maxRoll > 320) - maxRoll = 320; + DateTime dateTime = new DateTime(); + dateTime = dateTime.withMillis(upgradeTime); + toRoll.setDateToUpgrade(upgradeTime); - int randomSuffix1 = (int) ThreadLocalRandom.current().nextDouble(minRoll, maxRoll + 1); //Does not return Max, but does return min? + int playerID = 0; - if (randomSuffix1 < suffixTypeTable.minRoll) - randomSuffix1 = (int) suffixTypeTable.minRoll; + if (pc != null) + playerID = pc.getObjectUUID(); + DbManager.NPCQueries.ADD_TO_PRODUCTION_LIST(toRoll.getObjectUUID(), vendor.getObjectUUID(), toRoll.getItemBaseID(), dateTime, prefix, suffix, toRoll.getCustomName(), true, playerID); + ProducedItem pi = new ProducedItem(toRoll.getObjectUUID(), vendor.getObjectUUID(), toRoll.getItemBaseID(), dateTime, true, prefix, suffix, toRoll.getCustomName(), playerID); + pi.setProducedItemID(toRoll.getObjectUUID()); + pi.setAmount(itemsToRoll); + ItemQueue produced = ItemQueue.borrow(pi, (long) (time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue()))); + ItemProductionManager.send(produced); + return toRoll; + } - if (randomSuffix1 > suffixTypeTable.maxRoll) - randomSuffix1 = (int) suffixTypeTable.maxRoll; + public static MobLoot produceRandomRoll(NPC npc, PlayerCharacter pc, String prefixString, String suffixString, int itemID) { - LootRow suffixTypelootRow = suffixTypeTable.getLootRow(randomSuffix1); + boolean useWarehouse = false; - if (suffixTypelootRow != null) - suffix = suffixTypelootRow.getAction(); - } - } - } - } + if (npc == null) + return null; - toRoll =ItemFactory.produceRandomRoll(vendor, pc,prefix,suffix, itemID); + ItemBase ib = ItemBase.getItemBase(itemID); - if (toRoll == null) - return null; + if (ib == null) + return null; - toRoll.setValue(0); + Building forge = npc.getBuilding(); - float time; - float rank = vendor.getBuilding().getRank() - 1; - float rate = (float) (2.5 * rank); - time = (20 - rate); - time *= MBServerStatics.ONE_MINUTE; + if (forge == null) + return null; + + Zone zone = npc.getBuilding().getParentZone(); + + if (zone == null) + return null; + + City city = City.getCity(zone.getPlayerCityUUID()); + + if (city == null) + return null; + + MobLoot ml = null; + city.transactionLock.writeLock().lock(); + + try { + + + Warehouse cityWarehouse = city.getWarehouse(); + + if (cityWarehouse != null && forge.assetIsProtected()) + useWarehouse = true; + + ConcurrentHashMap resources = null; + + if (useWarehouse) + resources = cityWarehouse.getResources(); + + int galvorAmount = 0; + int wormwoodAmount = 0; - if (toRoll.getItemBase().getUUID() > 910010 && toRoll.getItemBase().getUUID() < 910019){ - rank = toRoll.getItemBaseID() - 910010; - time = rank * 60 * 60 * 3 * 1000; - } - - // No job is submitted, as object's upgradetime field - // is used to determin whether or not an object has - // compelted rolling. The game object exists previously - // to this, not when 'compelte' is pressed. - long upgradeTime = System.currentTimeMillis() + (long)(time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue())) ; - - DateTime dateTime = new DateTime(); - dateTime = dateTime.withMillis(upgradeTime); - toRoll.setDateToUpgrade(upgradeTime); - - int playerID = 0; - - if (pc != null) - playerID = pc.getObjectUUID(); - DbManager.NPCQueries.ADD_TO_PRODUCTION_LIST(toRoll.getObjectUUID(),vendor.getObjectUUID(), toRoll.getItemBaseID(), dateTime, prefix, suffix, toRoll.getCustomName(), true,playerID); - ProducedItem pi = new ProducedItem(toRoll.getObjectUUID(),vendor.getObjectUUID(),toRoll.getItemBaseID(),dateTime,true,prefix, suffix, toRoll.getCustomName(),playerID); - pi.setProducedItemID(toRoll.getObjectUUID()); - pi.setAmount(itemsToRoll); - ItemQueue produced = ItemQueue.borrow(pi, (long) (time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue()))); - ItemProductionManager.send(produced); - return toRoll; - } - - public static MobLoot produceRandomRoll(NPC npc,PlayerCharacter pc,String prefixString, String suffixString, int itemID) { - - boolean useWarehouse = false; - - if(npc == null) - return null; - - ItemBase ib = ItemBase.getItemBase(itemID); - - if (ib == null) - return null; - - Building forge = npc.getBuilding(); - - if (forge == null) - return null; - - Zone zone = npc.getBuilding().getParentZone(); - - if (zone == null) - return null; - - City city = City.getCity(zone.getPlayerCityUUID()); - - if (city == null) - return null; - - MobLoot ml = null; - city.transactionLock.writeLock().lock(); - - try{ - - - - Warehouse cityWarehouse = city.getWarehouse(); - - if (cityWarehouse != null && forge.assetIsProtected()) - useWarehouse = true; - - ConcurrentHashMap resources = null; - - if (useWarehouse) - resources = cityWarehouse.getResources(); - - int galvorAmount = 0; - int wormwoodAmount = 0; - - if (ib.getType() == ItemType.WEAPON && ib.getPercentRequired() == 110){ - switch (ib.getSkillRequired()){ - case "Bow": - case "Crossbow": - case "Spear": - case "Pole Arm": - case "Staff": - wormwoodAmount = 22; - break; - case "Axe": - case "Dagger": - case "Sword": - case "Hammer": - case "Unarmed Combat": - - if (ib.isTwoHanded()) - galvorAmount = 22; - else - galvorAmount = 11; - break; - } - } - - ItemBase galvor = ItemBase.getItemBase(1580017); - ItemBase wormwood = ItemBase.getItemBase(1580018); - - //Cant roll 110% weapons that require resources if not allowed to use warehouse. - if (galvorAmount > 0 || wormwoodAmount > 0) - if (!useWarehouse) - return null; - - if (galvorAmount > 0){ - if (cityWarehouse.isResourceLocked(galvor)){ - ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked."+ ib.getName()); - return null; - } - - if (cityWarehouse.getResources().get(galvor) < galvorAmount){ - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item."+ ib.getName()); - return null; - } - } - - if (wormwoodAmount > 0){ - if (cityWarehouse.isResourceLocked(wormwood)){ - ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked."+ ib.getName()); - return null; - } - - if (cityWarehouse.getResources().get(wormwood) < wormwoodAmount){ - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item."+ ib.getName()); - return null; - } - } - - EffectsBase prefix = null; - - if (!prefixString.isEmpty()){ - prefix = PowersManager.getEffectByIDString(prefixString); - if (prefix == null) - return null; - } - - ItemBase goldIB = ItemBase.getGoldItemBase(); - - int baseCost = ib.getBaseValue(); - int total = (int) (baseCost + baseCost * .10); - - EffectsBase suffix = null; - - if (!suffixString.isEmpty()){ - suffix = PowersManager.getEffectByIDString(suffixString); - - if (suffix == null) - return null; - } - - //calculate gold costs and remove from the warehouse - if (prefix != null || suffix != null){ - int costToCreate = (int) (ib.getBaseValue() + ib.getBaseValue() *.10f); - int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, costToCreate); - int overdraft = BuildingManager.GetOverdraft(forge, costToCreate); - - if (overdraft > 0 && !useWarehouse){ - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox."+ ib.getName()); - return null; - } - - if (useWarehouse && overdraft > 0 && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse."+ ib.getName()); - return null; - } - - if (useWarehouse && overdraft > resources.get(goldIB)){ - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft."+ ib.getName()); - return null; - } - - if (!forge.transferGold(-buildingWithdraw,false)){ - overdraft += buildingWithdraw; - - if (!useWarehouse){ - ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item."+ ib.getName()); - return null; - }else{ - if (overdraft > resources.get(goldIB)){ - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item."+ ib.getName()); - return null; - } - } - } - - // there was an overdraft, withdraw the rest from warehouse. - if (overdraft > 0){ - if (pc != null){ - if (!cityWarehouse.withdraw(pc, ItemBase.GOLD_ITEM_BASE, overdraft, false,true)){ - Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID()+ "Failed to Withdrawl "); - return null; - } - }else{ - if (!cityWarehouse.withdraw(npc,ItemBase.GOLD_ITEM_BASE, overdraft, false,true)){ - Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID()+ "Failed to Withdrawl "); - return null; - } - } - } - } - - if (prefix == null && suffix == null){ - - int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, total); - int overdraft = BuildingManager.GetOverdraft(forge, total); - - if (overdraft > 0 && !useWarehouse){ - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox."+ ib.getName()); - return null; - } - - if (useWarehouse && overdraft > 0 && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)){ - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse."+ ib.getName()); - return null; - } - - if (useWarehouse && overdraft > resources.get(goldIB)){ - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft."+ ib.getName()); - return null; - } - - if (!forge.transferGold(-buildingWithdraw,false)){ - overdraft += buildingWithdraw; - - if (!useWarehouse){ - ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item."+ ib.getName()); - return null; - }else{ - if (overdraft > resources.get(goldIB)){ - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item."+ ib.getName()); - return null; - } - } - } - - if (overdraft > 0 && useWarehouse){ - - if (pc != null){ - if (!cityWarehouse.withdraw(pc, ItemBase.GOLD_ITEM_BASE, overdraft, false,true)){ - Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID()+ "Failed to Withdrawl "); - return null; - } - }else{ - if (!cityWarehouse.withdraw(npc, ItemBase.GOLD_ITEM_BASE, overdraft, false,true)){ - Logger.error( "Warehouse with UID of" + cityWarehouse.getObjectUUID()+ "Failed to Withdrawl "); - return null; - } - } - } - } - - if (galvorAmount > 0 && useWarehouse){ - //ChatManager.chatGuildInfo(pc, "Withdrawing " + galvorAmount + " galvor from warehouse"); - if (!cityWarehouse.withdraw(npc, galvor, galvorAmount, false,true)){ - ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Galvor from warehouse!"+ ib.getName()); - Logger.error( "Warehouse with UID of" + cityWarehouse.getObjectUUID()+ "Failed to Withdrawl "); - return null; - } - } - - if (wormwoodAmount > 0 && useWarehouse){ - //ChatManager.chatGuildInfo(pc, "Withdrawing " + wormwoodAmount + " wormwood from warehouse"); - if (!cityWarehouse.withdraw(npc, wormwood, wormwoodAmount, false,true)){ - ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Wormwood from warehouse for " + ib.getName()); - Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID()+ "Failed to Withdrawl "); - - return null; - } - } - - ml = new MobLoot(npc, ib, false); - - ml.containerType = Enum.ItemContainerType.FORGE; - - if (prefix != null){ - ml.addPermanentEnchantment(prefix.getIDString(), 0, 0, true); - ml.setPrefix(prefix.getIDString()); - } - - if (suffix != null){ - ml.addPermanentEnchantment(suffix.getIDString(), 0, 0, false); - ml.setSuffix(suffix.getIDString()); - } - - ml.loadEnchantments(); - - - ml.setValue(0); - ml.setRandom(true); - npc.addItemToForge(ml); - }catch(Exception e){ - Logger.error(e); - }finally{ - city.transactionLock.writeLock().unlock(); - } - return ml; - - } + if (ib.getType() == ItemType.WEAPON && ib.getPercentRequired() == 110) { + switch (ib.getSkillRequired()) { + case "Bow": + case "Crossbow": + case "Spear": + case "Pole Arm": + case "Staff": + wormwoodAmount = 22; + break; + case "Axe": + case "Dagger": + case "Sword": + case "Hammer": + case "Unarmed Combat": + + if (ib.isTwoHanded()) + galvorAmount = 22; + else + galvorAmount = 11; + break; + } + } + + ItemBase galvor = ItemBase.getItemBase(1580017); + ItemBase wormwood = ItemBase.getItemBase(1580018); + + //Cant roll 110% weapons that require resources if not allowed to use warehouse. + if (galvorAmount > 0 || wormwoodAmount > 0) + if (!useWarehouse) + return null; + + if (galvorAmount > 0) { + if (cityWarehouse.isResourceLocked(galvor)) { + ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + ib.getName()); + return null; + } + + if (cityWarehouse.getResources().get(galvor) < galvorAmount) { + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item." + ib.getName()); + return null; + } + } + + if (wormwoodAmount > 0) { + if (cityWarehouse.isResourceLocked(wormwood)) { + ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + ib.getName()); + return null; + } + + if (cityWarehouse.getResources().get(wormwood) < wormwoodAmount) { + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item." + ib.getName()); + return null; + } + } + + EffectsBase prefix = null; + + if (!prefixString.isEmpty()) { + prefix = PowersManager.getEffectByIDString(prefixString); + if (prefix == null) + return null; + } + + ItemBase goldIB = ItemBase.getGoldItemBase(); + + int baseCost = ib.getBaseValue(); + int total = (int) (baseCost + baseCost * .10); + + EffectsBase suffix = null; + + if (!suffixString.isEmpty()) { + suffix = PowersManager.getEffectByIDString(suffixString); + + if (suffix == null) + return null; + } + + //calculate gold costs and remove from the warehouse + if (prefix != null || suffix != null) { + int costToCreate = (int) (ib.getBaseValue() + ib.getBaseValue() * .10f); + int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, costToCreate); + int overdraft = BuildingManager.GetOverdraft(forge, costToCreate); + + if (overdraft > 0 && !useWarehouse) { + ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + ib.getName()); + return null; + } + + if (useWarehouse && overdraft > 0 && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName()); + return null; + } + + if (useWarehouse && overdraft > resources.get(goldIB)) { + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + ib.getName()); + return null; + } + + if (!forge.transferGold(-buildingWithdraw, false)) { + overdraft += buildingWithdraw; + + if (!useWarehouse) { + ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + ib.getName()); + return null; + } else { + if (overdraft > resources.get(goldIB)) { + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + ib.getName()); + return null; + } + } + } + + // there was an overdraft, withdraw the rest from warehouse. + if (overdraft > 0) { + if (pc != null) { + if (!cityWarehouse.withdraw(pc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) { + Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); + return null; + } + } else { + if (!cityWarehouse.withdraw(npc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) { + Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); + return null; + } + } + } + } + + if (prefix == null && suffix == null) { + + int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, total); + int overdraft = BuildingManager.GetOverdraft(forge, total); + + if (overdraft > 0 && !useWarehouse) { + ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + ib.getName()); + return null; + } + + if (useWarehouse && overdraft > 0 && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)) { + if (pc != null) + ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName()); + return null; + } + + if (useWarehouse && overdraft > resources.get(goldIB)) { + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + ib.getName()); + return null; + } + + if (!forge.transferGold(-buildingWithdraw, false)) { + overdraft += buildingWithdraw; + + if (!useWarehouse) { + ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + ib.getName()); + return null; + } else { + if (overdraft > resources.get(goldIB)) { + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + ib.getName()); + return null; + } + } + } + + if (overdraft > 0 && useWarehouse) { + + if (pc != null) { + if (!cityWarehouse.withdraw(pc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) { + Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); + return null; + } + } else { + if (!cityWarehouse.withdraw(npc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) { + Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); + return null; + } + } + } + } + + if (galvorAmount > 0 && useWarehouse) { + //ChatManager.chatGuildInfo(pc, "Withdrawing " + galvorAmount + " galvor from warehouse"); + if (!cityWarehouse.withdraw(npc, galvor, galvorAmount, false, true)) { + ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Galvor from warehouse!" + ib.getName()); + Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); + return null; + } + } + + if (wormwoodAmount > 0 && useWarehouse) { + //ChatManager.chatGuildInfo(pc, "Withdrawing " + wormwoodAmount + " wormwood from warehouse"); + if (!cityWarehouse.withdraw(npc, wormwood, wormwoodAmount, false, true)) { + ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Wormwood from warehouse for " + ib.getName()); + Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); + + return null; + } + } + + ml = new MobLoot(npc, ib, false); + + ml.containerType = Enum.ItemContainerType.FORGE; + + if (prefix != null) { + ml.addPermanentEnchantment(prefix.getIDString(), 0, 0, true); + ml.setPrefix(prefix.getIDString()); + } + + if (suffix != null) { + ml.addPermanentEnchantment(suffix.getIDString(), 0, 0, false); + ml.setSuffix(suffix.getIDString()); + } + + ml.loadEnchantments(); + + + ml.setValue(0); + ml.setRandom(true); + npc.addItemToForge(ml); + } catch (Exception e) { + Logger.error(e); + } finally { + city.transactionLock.writeLock().unlock(); + } + return ml; + + } } diff --git a/src/engine/objects/Kit.java b/src/engine/objects/Kit.java index d2642b80..b44c4d86 100644 --- a/src/engine/objects/Kit.java +++ b/src/engine/objects/Kit.java @@ -24,406 +24,404 @@ import java.util.HashMap; public class Kit extends AbstractGameObject { - private final int raceBaseClassID; - private final byte kitNumber; - private final int legs; - private final int chest; - private final int feet; - private final int offhand; - private final int weapon; - public static HashMap NoobGearIDS = new HashMap<>(); - public static HashMap> RaceClassIDMap = new HashMap<>(); - - - /** - * No Table ID Constructor - */ - public Kit(int raceBaseClassID, byte kitNumber, int legs, int chest, - int feet, int offhand, int weapon) { - super(); - this.raceBaseClassID = raceBaseClassID; - this.kitNumber = kitNumber; - this.legs = legs; - this.chest = chest; - this.feet = feet; - this.offhand = offhand; - this.weapon = weapon; - } - - /** - * Normal Constructor - */ - public Kit(int raceBaseClassID, byte kitNumber, int legs, int chest, - int feet, int offhand, int weapon, int newUUID) { - super(newUUID); - this.raceBaseClassID = raceBaseClassID; - this.kitNumber = kitNumber; - this.legs = legs; - this.chest = chest; - this.feet = feet; - this.offhand = offhand; - this.weapon = weapon; - } - - /** - * RecordSet Constructor - */ - public Kit(ResultSet rs) throws SQLException, UnknownHostException { - super(rs); - - this.raceBaseClassID = rs.getInt("RaceBaseClassesID"); - this.kitNumber = rs.getByte("kitNumber"); - - this.legs = rs.getInt("legs"); - this.chest = rs.getInt("chest"); - this.feet = rs.getInt("feet"); - this.offhand = rs.getInt("offhand"); - this.weapon = rs.getInt("weapon"); - if (Kit.RaceClassIDMap.containsKey(this.raceBaseClassID)){ - Kit.RaceClassIDMap.get(this.raceBaseClassID).add(this); - }else{ - ArrayList tempList = new ArrayList<>(); - tempList.add(this); - Kit.RaceClassIDMap.put(this.raceBaseClassID, tempList); - - } - - if (this.legs != 0) - Kit.NoobGearIDS.put(this.legs, true); - if (this.chest != 0) - Kit.NoobGearIDS.put(this.chest, true); - if (this.feet != 0) - Kit.NoobGearIDS.put(this.feet, true); - if (this.offhand != 0) - Kit.NoobGearIDS.put(this.offhand, true); - if (this.weapon != 0) - Kit.NoobGearIDS.put(this.weapon, true); - - } - - public static boolean IsNoobGear(int itemID){ + public static HashMap NoobGearIDS = new HashMap<>(); + public static HashMap> RaceClassIDMap = new HashMap<>(); + private final int raceBaseClassID; + private final byte kitNumber; + private final int legs; + private final int chest; + private final int feet; + private final int offhand; + private final int weapon; + + + /** + * No Table ID Constructor + */ + public Kit(int raceBaseClassID, byte kitNumber, int legs, int chest, + int feet, int offhand, int weapon) { + super(); + this.raceBaseClassID = raceBaseClassID; + this.kitNumber = kitNumber; + this.legs = legs; + this.chest = chest; + this.feet = feet; + this.offhand = offhand; + this.weapon = weapon; + } + + /** + * Normal Constructor + */ + public Kit(int raceBaseClassID, byte kitNumber, int legs, int chest, + int feet, int offhand, int weapon, int newUUID) { + super(newUUID); + this.raceBaseClassID = raceBaseClassID; + this.kitNumber = kitNumber; + this.legs = legs; + this.chest = chest; + this.feet = feet; + this.offhand = offhand; + this.weapon = weapon; + } + + /** + * RecordSet Constructor + */ + public Kit(ResultSet rs) throws SQLException, UnknownHostException { + super(rs); + + this.raceBaseClassID = rs.getInt("RaceBaseClassesID"); + this.kitNumber = rs.getByte("kitNumber"); + + this.legs = rs.getInt("legs"); + this.chest = rs.getInt("chest"); + this.feet = rs.getInt("feet"); + this.offhand = rs.getInt("offhand"); + this.weapon = rs.getInt("weapon"); + if (Kit.RaceClassIDMap.containsKey(this.raceBaseClassID)) { + Kit.RaceClassIDMap.get(this.raceBaseClassID).add(this); + } else { + ArrayList tempList = new ArrayList<>(); + tempList.add(this); + Kit.RaceClassIDMap.put(this.raceBaseClassID, tempList); + + } + + if (this.legs != 0) + Kit.NoobGearIDS.put(this.legs, true); + if (this.chest != 0) + Kit.NoobGearIDS.put(this.chest, true); + if (this.feet != 0) + Kit.NoobGearIDS.put(this.feet, true); + if (this.offhand != 0) + Kit.NoobGearIDS.put(this.offhand, true); + if (this.weapon != 0) + Kit.NoobGearIDS.put(this.weapon, true); + + } + + public static boolean IsNoobGear(int itemID) { return Kit.NoobGearIDS.containsKey(itemID); } - /* - * Getters - */ - - public int getRaceBaseClassID() { - return raceBaseClassID; - } - - public byte getKitNumber() { - return kitNumber; - } - - public int getLegs() { - return legs; - } - - public int getChest() { - return chest; - } - - public int getFeet() { - return feet; - } - - public int getOffhand() { - return offhand; - } - - public int getWeapon() { - return weapon; - } - - public void equipPCwithKit(PlayerCharacter pc) { - if (weapon != 0) - kitItemCreator(pc, weapon, MBServerStatics.SLOT_MAINHAND); - if (offhand != 0) - kitItemCreator(pc, offhand, MBServerStatics.SLOT_OFFHAND); - if (chest != 0) - kitItemCreator(pc, chest, MBServerStatics.SLOT_CHEST); - if (legs != 0) - kitItemCreator(pc, legs, MBServerStatics.SLOT_LEGGINGS); - if (feet != 0) - kitItemCreator(pc, feet, MBServerStatics.SLOT_FEET); - } - - private static boolean kitItemCreator(PlayerCharacter pc, int itemBase, int slot) - { - ItemBase i = ItemBase.getItemBase(itemBase); - - Item temp = new Item( i, pc.getObjectUUID(), - OwnerType.PlayerCharacter, (byte) 0, (byte) 0, (short) 0, (short) 0, - false, false,ItemContainerType.EQUIPPED, (byte) slot, - new ArrayList<>(),""); - - try { - temp = DbManager.ItemQueries.ADD_ITEM(temp); - } catch (Exception e) { - Logger.error(e); - } - - if (temp == null) { - Logger.info("Ungoof this goof, something is wrong with our kit."); - } - return true; - } - - public static int GetKitIDByRaceClass(final int raceID, final int classID){ - switch (raceID){ - case 2000: - switch(classID){ - case 2500: - return 2; - case 2501: - return 3; - case 2502: - return 4; - case 2503: - return 5; - } - case 2001: - - switch(classID){ - case 2500: - return 6; - case 2501: - return 7; - case 2502: - return 8; - case 2503: - return 9; - } - case 2002: - switch(classID){ - case 2500: - return 10; - case 2501: - return 11; - case 2502: - return 12; - - } - case 2003: - switch(classID){ - case 2500: - return 13; - case 2501: - return 14; - case 2502: - return 15; - } - case 2004: - - switch(classID){ - case 2500: - return 16; - case 2501: - return 17; - } - case 2005: - switch(classID){ - case 2500: - return 18; - case 2501: - return 19; - } - case 2006: - - switch(classID){ - case 2500: - return 20; - case 2501: - return 21; - - } - case 2008: - - switch(classID){ - case 2500: - return 22; - case 2501: - return 23; - case 2502: - return 24; - case 2503: - return 25; - } - - case 2009: - - switch(classID){ - case 2500: - return 26; - case 2501: - return 27; - case 2502: - return 28; - case 2503: - return 29; - } - case 2010: - - switch(classID){ - case 2500: - return 30; - } - - case 2011: - - switch(classID){ - case 2500: - return 31; - case 2501: - return 32; - case 2502: - return 33; - case 2503: - return 34; - } - - case 2012: - - switch(classID){ - case 2500: - return 35; - case 2501: - return 36; - case 2502: - return 37; - case 2503: - return 38; - } - - case 2013: - - switch(classID){ - case 2500: - return 39; - case 2501: - return 40; - case 2502: - return 41; - case 2503: - return 42; - } - - case 2014: - - switch(classID){ - case 2500: - return 43; - case 2501: - return 44; - case 2502: - return 45; - case 2503: - return 46; - } - - case 2015: - - switch(classID){ - case 2500: - return 47; - case 2502: - return 48; - case 2503: - return 49; - - } - - case 2016: - - switch(classID){ - case 2500: - return 50; - case 2502: - return 51; - case 2503: - return 52; - - } - - case 2017: - - switch(classID){ - case 2500: - return 53; - case 2501: - return 54; - - } - - case 2025: - - switch(classID){ - case 2500: - return 55; - case 2501: - return 56; - case 2502: - return 57; - case 2503: - return 58; - } - - case 2026: - - switch(classID){ - case 2500: - return 59; - case 2501: - return 60; - case 2502: - return 61; - case 2503: - return 62; - } - - case 2027: - - switch(classID){ - case 2500: - return 63; - } - - case 2028: - - switch(classID){ - case 2500: - return 64; - - case 2502: - return 65; - case 2503: - return 66; - } - - case 2029: - - switch(classID){ - case 2500: - return 67; - - case 2502: - return 68; - case 2503: - return 69; - } - - - - } - return -1; - } - - @Override - public void updateDatabase() { - // TODO Create update logic. - } + /* + * Getters + */ + + private static boolean kitItemCreator(PlayerCharacter pc, int itemBase, int slot) { + ItemBase i = ItemBase.getItemBase(itemBase); + + Item temp = new Item(i, pc.getObjectUUID(), + OwnerType.PlayerCharacter, (byte) 0, (byte) 0, (short) 0, (short) 0, + false, false, ItemContainerType.EQUIPPED, (byte) slot, + new ArrayList<>(), ""); + + try { + temp = DbManager.ItemQueries.ADD_ITEM(temp); + } catch (Exception e) { + Logger.error(e); + } + + if (temp == null) { + Logger.info("Ungoof this goof, something is wrong with our kit."); + } + return true; + } + + public static int GetKitIDByRaceClass(final int raceID, final int classID) { + switch (raceID) { + case 2000: + switch (classID) { + case 2500: + return 2; + case 2501: + return 3; + case 2502: + return 4; + case 2503: + return 5; + } + case 2001: + + switch (classID) { + case 2500: + return 6; + case 2501: + return 7; + case 2502: + return 8; + case 2503: + return 9; + } + case 2002: + switch (classID) { + case 2500: + return 10; + case 2501: + return 11; + case 2502: + return 12; + + } + case 2003: + switch (classID) { + case 2500: + return 13; + case 2501: + return 14; + case 2502: + return 15; + } + case 2004: + + switch (classID) { + case 2500: + return 16; + case 2501: + return 17; + } + case 2005: + switch (classID) { + case 2500: + return 18; + case 2501: + return 19; + } + case 2006: + + switch (classID) { + case 2500: + return 20; + case 2501: + return 21; + + } + case 2008: + + switch (classID) { + case 2500: + return 22; + case 2501: + return 23; + case 2502: + return 24; + case 2503: + return 25; + } + + case 2009: + + switch (classID) { + case 2500: + return 26; + case 2501: + return 27; + case 2502: + return 28; + case 2503: + return 29; + } + case 2010: + + switch (classID) { + case 2500: + return 30; + } + + case 2011: + + switch (classID) { + case 2500: + return 31; + case 2501: + return 32; + case 2502: + return 33; + case 2503: + return 34; + } + + case 2012: + + switch (classID) { + case 2500: + return 35; + case 2501: + return 36; + case 2502: + return 37; + case 2503: + return 38; + } + + case 2013: + + switch (classID) { + case 2500: + return 39; + case 2501: + return 40; + case 2502: + return 41; + case 2503: + return 42; + } + + case 2014: + + switch (classID) { + case 2500: + return 43; + case 2501: + return 44; + case 2502: + return 45; + case 2503: + return 46; + } + + case 2015: + + switch (classID) { + case 2500: + return 47; + case 2502: + return 48; + case 2503: + return 49; + + } + + case 2016: + + switch (classID) { + case 2500: + return 50; + case 2502: + return 51; + case 2503: + return 52; + + } + + case 2017: + + switch (classID) { + case 2500: + return 53; + case 2501: + return 54; + + } + + case 2025: + + switch (classID) { + case 2500: + return 55; + case 2501: + return 56; + case 2502: + return 57; + case 2503: + return 58; + } + + case 2026: + + switch (classID) { + case 2500: + return 59; + case 2501: + return 60; + case 2502: + return 61; + case 2503: + return 62; + } + + case 2027: + + switch (classID) { + case 2500: + return 63; + } + + case 2028: + + switch (classID) { + case 2500: + return 64; + + case 2502: + return 65; + case 2503: + return 66; + } + + case 2029: + + switch (classID) { + case 2500: + return 67; + + case 2502: + return 68; + case 2503: + return 69; + } + + + } + return -1; + } + + public int getRaceBaseClassID() { + return raceBaseClassID; + } + + public byte getKitNumber() { + return kitNumber; + } + + public int getLegs() { + return legs; + } + + public int getChest() { + return chest; + } + + public int getFeet() { + return feet; + } + + public int getOffhand() { + return offhand; + } + + public int getWeapon() { + return weapon; + } + + public void equipPCwithKit(PlayerCharacter pc) { + if (weapon != 0) + kitItemCreator(pc, weapon, MBServerStatics.SLOT_MAINHAND); + if (offhand != 0) + kitItemCreator(pc, offhand, MBServerStatics.SLOT_OFFHAND); + if (chest != 0) + kitItemCreator(pc, chest, MBServerStatics.SLOT_CHEST); + if (legs != 0) + kitItemCreator(pc, legs, MBServerStatics.SLOT_LEGGINGS); + if (feet != 0) + kitItemCreator(pc, feet, MBServerStatics.SLOT_FEET); + } + + @Override + public void updateDatabase() { + // TODO Create update logic. + } } diff --git a/src/engine/objects/LevelDefault.java b/src/engine/objects/LevelDefault.java index c66d6db3..60492d7e 100644 --- a/src/engine/objects/LevelDefault.java +++ b/src/engine/objects/LevelDefault.java @@ -7,7 +7,7 @@ // www.magicbane.com - package engine.objects; +package engine.objects; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; @@ -18,55 +18,54 @@ import java.util.concurrent.ConcurrentHashMap; public class LevelDefault { - public final int level; - public final float health; - public final float mana; - public final float stamina; - public final float atr; - public final float def; - public final float minDamage; - public final float maxDamage; - public final int goldMin; - public final int goldMax; + public static ConcurrentHashMap defaults = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + public final int level; + public final float health; + public final float mana; + public final float stamina; + public final float atr; + public final float def; + public final float minDamage; + public final float maxDamage; + public final int goldMin; + public final int goldMax; - public static ConcurrentHashMap defaults = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + /** + * ResultSet Constructor + */ + public LevelDefault(ResultSet rs) throws SQLException { + super(); + this.level = rs.getInt("level"); + this.health = rs.getFloat("health"); + this.mana = (float) rs.getInt("mana"); + this.stamina = (float) rs.getInt("stamina"); + this.atr = (float) rs.getInt("atr"); + this.def = (float) rs.getInt("def"); + this.minDamage = (float) rs.getInt("minDamage"); + this.maxDamage = (float) rs.getInt("maxDamage"); + this.goldMin = rs.getInt("goldMin"); + this.goldMax = rs.getInt("goldMax"); + } - /** - * ResultSet Constructor - */ - public LevelDefault(ResultSet rs) throws SQLException { - super(); - this.level = rs.getInt("level"); - this.health = rs.getFloat("health"); - this.mana = (float)rs.getInt("mana"); - this.stamina = (float)rs.getInt("stamina"); - this.atr = (float)rs.getInt("atr"); - this.def = (float)rs.getInt("def"); - this.minDamage = (float)rs.getInt("minDamage"); - this.maxDamage = (float)rs.getInt("maxDamage"); - this.goldMin = rs.getInt("goldMin"); - this.goldMax = rs.getInt("goldMax"); - } + public static LevelDefault getLevelDefault(byte level) { + LevelDefault ret = null; + if (LevelDefault.defaults.containsKey(level)) + return LevelDefault.defaults.get(level); - public static LevelDefault getLevelDefault(byte level) { - LevelDefault ret = null; - if (LevelDefault.defaults.containsKey(level)) - return LevelDefault.defaults.get(level); - - PreparedStatementShared ps = null; - try { - ps = new PreparedStatementShared("SELECT * FROM `static_npc_level_defaults` WHERE level = ?;"); - ps.setInt(1, (int)level); - ResultSet rs = ps.executeQuery(); - if (rs.next()) { - ret = new LevelDefault(rs); - LevelDefault.defaults.put(level, ret); - } - } catch (SQLException e) { - Logger.error("SQL Error number: " + e.getErrorCode() + ' ' + e.getMessage()); - } finally { - ps.release(); - } - return ret; - } + PreparedStatementShared ps = null; + try { + ps = new PreparedStatementShared("SELECT * FROM `static_npc_level_defaults` WHERE level = ?;"); + ps.setInt(1, (int) level); + ResultSet rs = ps.executeQuery(); + if (rs.next()) { + ret = new LevelDefault(rs); + LevelDefault.defaults.put(level, ret); + } + } catch (SQLException e) { + Logger.error("SQL Error number: " + e.getErrorCode() + ' ' + e.getMessage()); + } finally { + ps.release(); + } + return ret; + } } \ No newline at end of file diff --git a/src/engine/objects/LootRow.java b/src/engine/objects/LootRow.java index 3a74c269..4e99ae3d 100644 --- a/src/engine/objects/LootRow.java +++ b/src/engine/objects/LootRow.java @@ -11,53 +11,53 @@ package engine.objects; public class LootRow { - private int valueOne; - private int valueTwo; - private int valueThree; - private String action; - - - /** - * Generic Constructor - */ - public LootRow(int valueOne, int valueTwo, int valueThree, String action) { - this.valueOne = valueOne; - this.valueTwo = valueTwo; - this.valueThree = valueThree; - this.action = action; - - } - - public int getValueOne() { - return this.valueOne; - } - - public int getValueTwo() { - return this.valueTwo; - } - - public int getValueThree() { - return this.valueThree; - } - - public String getAction() { - return this.action; - } - - public void setValueOne(int value) { - this.valueOne = value; - } - - public void setValueTwo(int value) { - this.valueTwo = value; - } - - public void setValueThree(int value) { - this.valueThree = value; - } - - public void setAction(String value) { - this.action = value; - } + private int valueOne; + private int valueTwo; + private int valueThree; + private String action; + + + /** + * Generic Constructor + */ + public LootRow(int valueOne, int valueTwo, int valueThree, String action) { + this.valueOne = valueOne; + this.valueTwo = valueTwo; + this.valueThree = valueThree; + this.action = action; + + } + + public int getValueOne() { + return this.valueOne; + } + + public void setValueOne(int value) { + this.valueOne = value; + } + + public int getValueTwo() { + return this.valueTwo; + } + + public void setValueTwo(int value) { + this.valueTwo = value; + } + + public int getValueThree() { + return this.valueThree; + } + + public void setValueThree(int value) { + this.valueThree = value; + } + + public String getAction() { + return this.action; + } + + public void setAction(String value) { + this.action = value; + } } diff --git a/src/engine/objects/LootTable.java b/src/engine/objects/LootTable.java index 7c12f698..74e86e8f 100644 --- a/src/engine/objects/LootTable.java +++ b/src/engine/objects/LootTable.java @@ -27,1244 +27,1224 @@ import java.util.concurrent.ThreadLocalRandom; public class LootTable { - private static final ConcurrentHashMap lootGroups = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private static final ConcurrentHashMap lootTables = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private static final ConcurrentHashMap modTables = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private static final ConcurrentHashMap modGroups = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private static final ConcurrentHashMap statRuneChances = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private final ConcurrentHashMap lootTable = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private static final ConcurrentHashMap lootGroups = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private static final ConcurrentHashMap lootTables = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private static final ConcurrentHashMap modTables = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private static final ConcurrentHashMap modGroups = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private static final ConcurrentHashMap statRuneChances = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private static final int oneDrop = 95; + private static final int twoDrop = 100; + private static final int noDropHotZone = 79; + private static final int oneDropHotZone = 98; + public static boolean initialized = false; + public static HashMap itemsDroppedMap = new HashMap<>(); + public static HashMap resourceDroppedMap = new HashMap<>(); + public static HashMap runeDroppedMap = new HashMap<>(); + public static HashMap contractDroppedMap = new HashMap<>(); + public static HashMap glassDroppedMap = new HashMap<>(); + public static int rollCount = 0; + public static int dropCount = 0; + public static int runeCount = 0; + public static int contractCount = 0; + public static int resourceCount = 0; + public static int glassCount = 0; + private final ConcurrentHashMap lootTable = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + public float minRoll = 320; + public float maxRoll = 1; + public int lootTableID = 0; + + + /** + * Generic Constructor + */ + public LootTable(int lootTableID) { + this.lootTableID = lootTableID; + } + + public static LootTable getLootGroup(int UUID) { + + if (lootGroups.containsKey(UUID)) + return lootGroups.get(UUID); + + LootTable lootGroup = new LootTable(UUID); + lootGroups.put(UUID, lootGroup); + return lootGroup; + } + + public static LootTable getLootTable(int UUID) { + + if (lootTables.containsKey(UUID)) + return lootTables.get(UUID); + + LootTable lootTable = new LootTable(UUID); + lootTables.put(UUID, lootTable); + return lootTable; + } + + /** + * @return the lootGroups + */ + public static ConcurrentHashMap getLootGroups() { + return lootGroups; + } + + /** + * @return the lootTables + */ + public static ConcurrentHashMap getLootTables() { + return lootTables; + } + + /** + * @return the modTables + */ + public static ConcurrentHashMap getModTables() { + return modTables; + } + + /** + * @return the modGroups + */ + public static ConcurrentHashMap getModGroups() { + return modGroups; + } + + public static LootTable getModGroup(int UUID) { + if (modGroups.containsKey(UUID)) + return modGroups.get(UUID); + LootTable modTable = new LootTable(UUID); + modGroups.put(UUID, modTable); + return modTable; + } + + public static LootTable getModTable(int UUID) { + if (modTables.containsKey(UUID)) + return modTables.get(UUID); + LootTable modTypeTable = new LootTable(UUID); + modTables.put(UUID, modTypeTable); + return modTypeTable; + } + + //call this on server startup to populate the tables + public static void populateLootTables() { + DbManager.LootQueries.populateLootGroups(); + DbManager.LootQueries.populateLootTables(); + DbManager.LootQueries.populateModTables(); + DbManager.LootQueries.populateModGroups(); + + //preset chances for rune drops + populateStatRuneChances(); + } + + //Returns a list of random loot for a mob based on level, lootTable and hotzone + public static ArrayList getMobLoot(Mob mobile, int mobLevel, int lootTable, boolean hotzone) { + + ArrayList mobLoot; + int calculatedLootTable; + int randomRoll; + + mobLoot = new ArrayList<>(); + + // Setup default loot table if none exists + + calculatedLootTable = lootTable; + + LootTable.rollCount++; + if (MobLootBase.MobLootSet.get(mobile.getMobBase().getLoadID()).isEmpty()) { + randomRoll = ThreadLocalRandom.current().nextInt(100); - private static final int oneDrop = 95; - private static final int twoDrop = 100; - private static final int noDropHotZone = 79; - private static final int oneDropHotZone = 98; + if (randomRoll > 90) + if (randomRoll > LootTable.oneDropHotZone) + addMobLoot(mobile, mobLoot, mobLevel, calculatedLootTable, 1, true); + else + addMobLoot(mobile, mobLoot, mobLevel, calculatedLootTable, 1, true); + } else { + for (MobLootBase mlb : MobLootBase.MobLootSet.get(mobile.getMobBase().getLoadID())) { - public float minRoll = 320; - public float maxRoll = 1; - public static boolean initialized = false; + float chance = mlb.getChance() * .01f; - public int lootTableID = 0; + chance *= Float.parseFloat(ConfigManager.MB_NORMAL_DROP_RATE.getValue()); - public static HashMap itemsDroppedMap = new HashMap<>(); - public static HashMap resourceDroppedMap = new HashMap<>(); - public static HashMap runeDroppedMap = new HashMap<>(); - public static HashMap contractDroppedMap = new HashMap<>(); - public static HashMap glassDroppedMap = new HashMap<>(); - - public static int rollCount = 0; - public static int dropCount = 0; - public static int runeCount = 0; - public static int contractCount = 0; - public static int resourceCount = 0; - public static int glassCount = 0; - - - /** - * Generic Constructor - */ - public LootTable(int lootTableID) { - this.lootTableID = lootTableID; - } - - public void addRow(float min, float max, int valueOne, int valueTwo, int valueThree, String action) { - - //hackey way to set the minimum roll for SHIAT! - if (min < this.minRoll) - this.minRoll = min; - - if (max > this.maxRoll) - this.maxRoll = max; - - int minInt = (int) min; - int maxInt = (int) max; - - //Round up min - if (minInt != min){ - min = minInt + 1; - } - - //Round down max; - if (maxInt != max) - max = maxInt; - - - - LootRow lootRow = new LootRow(valueOne, valueTwo, valueThree, action); - for (int i = (int) min; i <= max; i++) { - lootTable.put(i, lootRow); - } - } + calculatedLootTable = mlb.getLootTableID(); - public static LootTable getLootGroup(int UUID) { + if (ThreadLocalRandom.current().nextFloat() > chance) + continue; - if (lootGroups.containsKey(UUID)) - return lootGroups.get(UUID); + addMobLoot(mobile, mobLoot, mobLevel, calculatedLootTable, 1, false); - LootTable lootGroup = new LootTable(UUID); - lootGroups.put(UUID, lootGroup); - return lootGroup; - } + } + } - public static LootTable getLootTable(int UUID) { + //calculatedLootTable = lootTable; - if (lootTables.containsKey(UUID)) - return lootTables.get(UUID); + if (calculatedLootTable <= 1) + calculatedLootTable = 1300; // GENERIC WORLD - LootTable lootTable = new LootTable(UUID); - lootTables.put(UUID, lootTable); - return lootTable; - } + //handle hotzone random loot - /** - * @return the lootGroups - */ - public static ConcurrentHashMap getLootGroups() { - return lootGroups; - } + if (hotzone) { - /** - * @return the lootTables - */ - public static ConcurrentHashMap getLootTables() { - return lootTables; - } + LootTable.rollCount++; - /** - * @return the modTables - */ - public static ConcurrentHashMap getModTables() { - return modTables; - } + if (!MobLootBase.MobLootSet.get(mobile.getMobBase().getLoadID()).isEmpty()) + for (MobLootBase mlb : MobLootBase.MobLootSet.get(mobile.getMobBase().getLoadID())) { + if (!LootTable.lootGroups.containsKey(mlb.getLootTableID() + 1)) + continue; + calculatedLootTable = mlb.getLootTableID(); + break; + } - /** - * @return the modGroups - */ - public static ConcurrentHashMap getModGroups() { - return modGroups; - } + randomRoll = ThreadLocalRandom.current().nextInt(100); + if (randomRoll > 90) + if (randomRoll > LootTable.oneDropHotZone) + addMobLoot(mobile, mobLoot, mobLevel, calculatedLootTable + 1, 1, true); + else + addMobLoot(mobile, mobLoot, mobLevel, calculatedLootTable + 1, 1, true); + } - public static LootTable getModGroup(int UUID) { - if (modGroups.containsKey(UUID)) - return modGroups.get(UUID); - LootTable modTable = new LootTable(UUID); - modGroups.put(UUID, modTable); - return modTable; - } + //handle mob specific special loot - public static LootTable getModTable(int UUID) { - if (modTables.containsKey(UUID)) - return modTables.get(UUID); - LootTable modTypeTable = new LootTable(UUID); - modTables.put(UUID, modTypeTable); - return modTypeTable; - } + ArrayList bootyLoot = getBootyLoot(mobile); + mobLoot.addAll(bootyLoot); + return mobLoot; + } - public LootRow getLootRow(int probability) { - if (lootTable.containsKey(probability)) - return lootTable.get(probability); - return null; - } + public static ArrayList getMobLootDeath(Mob mobile, int mobLevel, int lootTable) { + ArrayList mobLoot = new ArrayList<>(); - //call this on server startup to populate the tables - public static void populateLootTables() { - DbManager.LootQueries.populateLootGroups(); - DbManager.LootQueries.populateLootTables(); - DbManager.LootQueries.populateModTables(); - DbManager.LootQueries.populateModGroups(); + if (mobile == null) + return mobLoot; - //preset chances for rune drops - populateStatRuneChances(); - } + //handle hotzone random loot + boolean hotzone = ZoneManager.inHotZone(mobile.getLoc()); + if (hotzone) { - //Returns a list of random loot for a mob based on level, lootTable and hotzone - public static ArrayList getMobLoot(Mob mobile, int mobLevel, int lootTable, boolean hotzone) { + if (MobLootBase.MobLootSet.get(mobile.getMobBase().getLoadID()).isEmpty()) { + lootTable += 1; - ArrayList mobLoot; - int calculatedLootTable; - int randomRoll; + if (lootTable <= 1) + lootTable = 1301; // GENERIC WORLD + int roll = ThreadLocalRandom.current().nextInt(100); + if (roll > 90) + if (roll > LootTable.oneDropHotZone) + addMobLoot(mobile, mobLoot, mobLevel, lootTable, 1, true); + else + addMobLoot(mobile, mobLoot, mobLevel, lootTable, 1, true); + } else { + for (MobLootBase mlb : MobLootBase.MobLootSet.get(mobile.getMobBase().getLoadID())) { + lootTable = mlb.getLootTableID() + 1; + if (!LootTable.lootGroups.containsKey(lootTable)) + continue; - mobLoot = new ArrayList<>(); + int roll = ThreadLocalRandom.current().nextInt(100); + if (roll > 90) + if (roll > LootTable.oneDropHotZone) + addMobLoot(mobile, mobLoot, mobLevel, (lootTable), 1, true); + else + addMobLoot(mobile, mobLoot, mobLevel, (lootTable), 1, true); - // Setup default loot table if none exists + break; + } + } - calculatedLootTable = lootTable; - LootTable.rollCount++; + if (mobLoot.isEmpty()) { - if (MobLootBase.MobLootSet.get(mobile.getMobBase().getLoadID()).isEmpty()){ + LootTable.rollCount++; //add another rollCount here. + int resourceRoll = ThreadLocalRandom.current().nextInt(100); + if (resourceRoll <= 5) + addMobLootResources(mobile, mobLoot, mobLevel, (lootTable), 1, true); + } - randomRoll = ThreadLocalRandom.current().nextInt(100); + } - if (randomRoll > 90) - if (randomRoll > LootTable.oneDropHotZone) - addMobLoot(mobile, mobLoot, mobLevel, calculatedLootTable, 1, true); - else - addMobLoot(mobile, mobLoot, mobLevel, calculatedLootTable, 1, true); - }else{ - for (MobLootBase mlb:MobLootBase.MobLootSet.get(mobile.getMobBase().getLoadID())){ - float chance = mlb.getChance() *.01f; + //handle mob specific booty on death - chance *= Float.parseFloat(ConfigManager.MB_NORMAL_DROP_RATE.getValue()); + ArrayList bootyLoot = getBootyLoot(mobile); + mobLoot.addAll(bootyLoot); - calculatedLootTable = mlb.getLootTableID(); + return mobLoot; + } - if (ThreadLocalRandom.current().nextFloat() > chance) - continue; + private static ArrayList getBootyLoot(Mob mob) { - addMobLoot(mobile, mobLoot, mobLevel, calculatedLootTable, 1, false); + ArrayList bootySetList; + ArrayList mobLootList = new ArrayList<>(); - } - } + if (mob.bootySet == 0) + return mobLootList; - //calculatedLootTable = lootTable; + bootySetList = NPCManager._bootySetMap.get(mob.bootySet); - if (calculatedLootTable <= 1) - calculatedLootTable = 1300; // GENERIC WORLD + for (BootySetEntry bootyEntry : bootySetList) + if (ThreadLocalRandom.current().nextInt(100) < bootyEntry.dropChance) { + ItemBase itemBase = ItemBase.getItemBase(bootyEntry.itemBase); - //handle hotzone random loot + if (itemBase != null) { + MobLoot mobLoot = new MobLoot(mob, itemBase, true); + mobLootList.add(mobLoot); + } + } + return mobLootList; + } - if (hotzone) { + //called by getMobLoot to add the actual loot + private static void addMobLoot(Mob mob, ArrayList loot, int mobLevel, int lootTableID, int cnt, boolean hotzone) { - LootTable.rollCount++; + // Member variable declaration + float calculatedMobLevel; + int minSpawn; + int maxSpawn; + int spawnQuanity = 0; + int prefixValue = 0; + int suffixValue = 0; + int subTableID; + String modifierPrefix = ""; + String modifierSuffix = ""; - if (!MobLootBase.MobLootSet.get(mobile.getMobBase().getLoadID()).isEmpty()) - for (MobLootBase mlb : MobLootBase.MobLootSet.get(mobile.getMobBase().getLoadID())) { - if (!LootTable.lootGroups.containsKey(mlb.getLootTableID() + 1)) - continue; - calculatedLootTable = mlb.getLootTableID(); - break; - } + // Lookup Table Variables + LootTable lootTable; + LootRow lootRow; + LootTable lootGroup; + LootRow groupRow = null; + LootTable modTable; + LootTable modGroup; + LootRow modRow = null; - randomRoll = ThreadLocalRandom.current().nextInt(100); + // Used for actual generation of items - if (randomRoll > 90) - if (randomRoll > LootTable.oneDropHotZone) - addMobLoot(mobile, mobLoot, mobLevel, calculatedLootTable + 1, 1, true); - else - addMobLoot(mobile, mobLoot, mobLevel, calculatedLootTable + 1, 1, true); - } + int itemBaseUUID; + ItemBase itemBase = null; + MobLoot mobLoot; - //handle mob specific special loot + if (!LootTable.lootGroups.containsKey(lootTableID)) + return; - ArrayList bootyLoot = getBootyLoot(mobile); - mobLoot.addAll(bootyLoot); + lootGroup = LootTable.lootGroups.get(lootTableID); - return mobLoot; - } + calculatedMobLevel = mobLevel; - public static ArrayList getMobLootDeath(Mob mobile, int mobLevel, int lootTable) { - ArrayList mobLoot = new ArrayList<>(); + if (calculatedMobLevel > 49) + calculatedMobLevel = 49; - if (mobile == null) - return mobLoot; - //handle hotzone random loot - boolean hotzone = ZoneManager.inHotZone(mobile.getLoc()); - if (hotzone) { + int randomRoll = 0; + for (int i = 0; i < cnt; i++) { - if (MobLootBase.MobLootSet.get(mobile.getMobBase().getLoadID()).isEmpty()){ - lootTable += 1; + Random random = new Random(); - if (lootTable <= 1) - lootTable = 1301; // GENERIC WORLD - int roll = ThreadLocalRandom.current().nextInt(100); - if (roll > 90) - if (roll > LootTable.oneDropHotZone) - addMobLoot(mobile, mobLoot, mobLevel, lootTable, 1, true); - else - addMobLoot(mobile, mobLoot, mobLevel, lootTable, 1, true); - }else{ - for (MobLootBase mlb:MobLootBase.MobLootSet.get(mobile.getMobBase().getLoadID())){ - lootTable = mlb.getLootTableID() + 1; - if (!LootTable.lootGroups.containsKey(lootTable)) - continue; + randomRoll = random.nextInt(100) + 1; //random roll between 1 and 100 + groupRow = lootGroup.getLootRow(randomRoll); - int roll = ThreadLocalRandom.current().nextInt(100); - if (roll > 90) - if (roll > LootTable.oneDropHotZone) - addMobLoot(mobile, mobLoot, mobLevel, (lootTable), 1, true); - else - addMobLoot(mobile, mobLoot, mobLevel, (lootTable), 1, true); + if (groupRow == null) + return; - break; - } - } + //get loot table for this group + if (!LootTable.lootTables.containsKey(groupRow.getValueOne())) + return; + lootTable = LootTable.lootTables.get(groupRow.getValueOne()); - if (mobLoot.isEmpty()){ + int minRoll = (int) ((calculatedMobLevel - 5) * 5); + int maxRoll = (int) ((calculatedMobLevel + 15) * 5); - LootTable.rollCount++; //add another rollCount here. - int resourceRoll = ThreadLocalRandom.current().nextInt(100); - if (resourceRoll <=5) - addMobLootResources(mobile, mobLoot, mobLevel, (lootTable), 1, true); - } + if (minRoll < (int) lootTable.minRoll) + minRoll = (int) lootTable.minRoll; - } + if (maxRoll < minRoll) + maxRoll = minRoll; + if (maxRoll > lootTable.maxRoll) + maxRoll = (int) lootTable.maxRoll; - //handle mob specific booty on death + if (maxRoll > 320) + maxRoll = 320; - ArrayList bootyLoot = getBootyLoot(mobile); - mobLoot.addAll(bootyLoot); + randomRoll = (int) ThreadLocalRandom.current().nextDouble(minRoll, maxRoll + 1); //Does not return Max, but does return min? - return mobLoot; - } + lootRow = lootTable.getLootRow(randomRoll); //get the item row from the bell's curve of level +-15 - private static ArrayList getBootyLoot(Mob mob) { + if (lootRow == null) + continue; //no item found for roll - ArrayList bootySetList; - ArrayList mobLootList = new ArrayList<>(); + itemBaseUUID = lootRow.getValueOne(); - if (mob.bootySet == 0) - return mobLootList; + if (lootRow.getValueOne() == 0) + continue; - bootySetList = NPCManager._bootySetMap.get(mob.bootySet); + //handle quantities > 1 for resource drops - for (BootySetEntry bootyEntry : bootySetList) - if (ThreadLocalRandom.current().nextInt(100) < bootyEntry.dropChance) { - ItemBase itemBase = ItemBase.getItemBase(bootyEntry.itemBase); + minSpawn = lootRow.getValueTwo(); + maxSpawn = lootRow.getValueThree(); - if (itemBase != null) { - MobLoot mobLoot = new MobLoot(mob, itemBase, true); - mobLootList.add(mobLoot); - } - } - return mobLootList; - } + // spawnQuantity between min spawn (inclusive) and max spawn (inclusive) + if (maxSpawn > 1) + spawnQuanity = ThreadLocalRandom.current().nextInt((maxSpawn + 1 - minSpawn)) + minSpawn; + //get modifierPrefix + calculatedMobLevel = mobLevel; - //called by getMobLoot to add the actual loot - private static void addMobLoot(Mob mob, ArrayList loot, int mobLevel, int lootTableID, int cnt, boolean hotzone) { + if (calculatedMobLevel < 16) + calculatedMobLevel = 16; - // Member variable declaration - float calculatedMobLevel; - int minSpawn; - int maxSpawn; - int spawnQuanity = 0; - int prefixValue = 0; - int suffixValue = 0; - int subTableID; - String modifierPrefix = ""; - String modifierSuffix = ""; + if (calculatedMobLevel > 49) + calculatedMobLevel = 49; - // Lookup Table Variables - LootTable lootTable; - LootRow lootRow; - LootTable lootGroup; - LootRow groupRow = null; - LootTable modTable; - LootTable modGroup; - LootRow modRow = null; + int chanceMod = ThreadLocalRandom.current().nextInt(100) + 1; - // Used for actual generation of items + if (chanceMod < 25) { + modGroup = LootTable.modGroups.get(groupRow.getValueTwo()); - int itemBaseUUID; - ItemBase itemBase = null; - MobLoot mobLoot; + if (modGroup != null) { - if (!LootTable.lootGroups.containsKey(lootTableID)) - return; + for (int a = 0; a < 10; a++) { + randomRoll = ThreadLocalRandom.current().nextInt(100) + 1; + modRow = modGroup.getLootRow(randomRoll); + if (modRow != null) + break; + } - lootGroup = LootTable.lootGroups.get(lootTableID); + if (modRow != null) { + subTableID = modRow.getValueOne(); - calculatedMobLevel = mobLevel; + if (LootTable.modTables.containsKey(subTableID)) { - if (calculatedMobLevel > 49) - calculatedMobLevel = 49; + modTable = LootTable.modTables.get(subTableID); + randomRoll = gaussianLevel((int) calculatedMobLevel); - int randomRoll = 0; - for (int i = 0; i < cnt; i++) { + if (randomRoll < modTable.minRoll) + randomRoll = (int) modTable.minRoll; - Random random = new Random(); + if (randomRoll > modTable.maxRoll) + randomRoll = (int) modTable.maxRoll; - randomRoll = random.nextInt(100) + 1; //random roll between 1 and 100 - groupRow = lootGroup.getLootRow(randomRoll); + modRow = modTable.getLootRow(randomRoll); - if (groupRow == null) - return; + if (modRow != null) { + prefixValue = modRow.getValueOne(); + modifierPrefix = modRow.getAction(); + } + } + } + } + } else if (chanceMod < 50) { + modGroup = LootTable.modGroups.get(groupRow.getValueThree()); - //get loot table for this group - if (!LootTable.lootTables.containsKey(groupRow.getValueOne())) - return; + if (modGroup != null) { - lootTable = LootTable.lootTables.get(groupRow.getValueOne()); + for (int a = 0; a < 10; a++) { + randomRoll = ThreadLocalRandom.current().nextInt(100) + 1; + modRow = modGroup.getLootRow(randomRoll); + if (modRow != null) + break; + } - int minRoll = (int) ((calculatedMobLevel - 5) * 5); - int maxRoll = (int) ((calculatedMobLevel + 15) * 5); + if (modRow != null) { - if (minRoll < (int)lootTable.minRoll) - minRoll = (int)lootTable.minRoll; + subTableID = modRow.getValueOne(); - if (maxRoll < minRoll) - maxRoll = minRoll; + if (LootTable.modTables.containsKey(subTableID)) { - if (maxRoll > lootTable.maxRoll) - maxRoll = (int) lootTable.maxRoll; + modTable = LootTable.modTables.get(subTableID); + randomRoll = gaussianLevel((int) calculatedMobLevel); - if (maxRoll > 320) - maxRoll = 320; + if (randomRoll < modTable.minRoll) + randomRoll = (int) modTable.minRoll; - randomRoll = (int) ThreadLocalRandom.current().nextDouble(minRoll, maxRoll + 1); //Does not return Max, but does return min? + if (randomRoll > modTable.maxRoll) + randomRoll = (int) modTable.maxRoll; - lootRow = lootTable.getLootRow(randomRoll); //get the item row from the bell's curve of level +-15 + modRow = modTable.getLootRow(randomRoll); - if (lootRow == null) - continue; //no item found for roll + if (modRow == null) + modRow = modTable.getLootRow((int) ((modTable.minRoll + modTable.maxRoll) * .05f)); - itemBaseUUID = lootRow.getValueOne(); - if (lootRow.getValueOne() == 0) - continue; + if (modRow != null) { + suffixValue = modRow.getValueOne(); + modifierSuffix = modRow.getAction(); + } + } + } + } + } else { + modGroup = LootTable.modGroups.get(groupRow.getValueTwo()); - //handle quantities > 1 for resource drops + if (modGroup != null) { - minSpawn = lootRow.getValueTwo(); - maxSpawn = lootRow.getValueThree(); - // spawnQuantity between min spawn (inclusive) and max spawn (inclusive) - if (maxSpawn > 1) - spawnQuanity = ThreadLocalRandom.current().nextInt((maxSpawn + 1 - minSpawn)) + minSpawn; + for (int a = 0; a < 10; a++) { + randomRoll = ThreadLocalRandom.current().nextInt(100) + 1; + modRow = modGroup.getLootRow(randomRoll); + if (modRow != null) + break; + } - //get modifierPrefix - calculatedMobLevel = mobLevel; + if (modRow != null) { + subTableID = modRow.getValueOne(); - if (calculatedMobLevel < 16) - calculatedMobLevel = 16; + if (LootTable.modTables.containsKey(subTableID)) { - if (calculatedMobLevel > 49) - calculatedMobLevel = 49; + modTable = LootTable.modTables.get(subTableID); - int chanceMod = ThreadLocalRandom.current().nextInt(100) + 1; + randomRoll = gaussianLevel((int) calculatedMobLevel); - if (chanceMod < 25) { - modGroup = LootTable.modGroups.get(groupRow.getValueTwo()); + if (randomRoll < modTable.minRoll) + randomRoll = (int) modTable.minRoll; - if (modGroup != null) { + if (randomRoll > modTable.maxRoll) + randomRoll = (int) modTable.maxRoll; - for (int a = 0;a<10;a++){ - randomRoll = ThreadLocalRandom.current().nextInt(100) + 1; - modRow = modGroup.getLootRow(randomRoll); - if (modRow != null) - break; - } + modRow = modTable.getLootRow(randomRoll); - if (modRow != null) { - subTableID = modRow.getValueOne(); + if (modRow == null) + modRow = modTable.getLootRow((int) ((modTable.minRoll + modTable.maxRoll) * .05f)); - if (LootTable.modTables.containsKey(subTableID)) { + if (modRow != null) { + prefixValue = modRow.getValueOne(); + modifierPrefix = modRow.getAction(); + } + } + } + } - modTable = LootTable.modTables.get(subTableID); + //get modifierSuffix + modGroup = LootTable.modGroups.get(groupRow.getValueThree()); - randomRoll = gaussianLevel((int)calculatedMobLevel); + if (modGroup != null) { - if (randomRoll < modTable.minRoll) - randomRoll = (int) modTable.minRoll; + for (int a = 0; a < 10; a++) { + randomRoll = ThreadLocalRandom.current().nextInt(100) + 1; + modRow = modGroup.getLootRow(randomRoll); + if (modRow != null) + break; + } - if (randomRoll > modTable.maxRoll) - randomRoll = (int) modTable.maxRoll; + if (modRow != null) { - modRow = modTable.getLootRow(randomRoll); + subTableID = modRow.getValueOne(); - if (modRow != null) { - prefixValue = modRow.getValueOne(); - modifierPrefix = modRow.getAction(); - } - } - } - } - }else if(chanceMod < 50) { - modGroup = LootTable.modGroups.get(groupRow.getValueThree()); + if (LootTable.modTables.containsKey(subTableID)) { - if (modGroup != null) { + modTable = LootTable.modTables.get(subTableID); + randomRoll = gaussianLevel((int) calculatedMobLevel); - for (int a = 0;a<10;a++){ - randomRoll = ThreadLocalRandom.current().nextInt(100) + 1; - modRow = modGroup.getLootRow(randomRoll); - if (modRow != null) - break; - } + if (randomRoll < modTable.minRoll) + randomRoll = (int) modTable.minRoll; - if (modRow != null) { + if (randomRoll > modTable.maxRoll) + randomRoll = (int) modTable.maxRoll; - subTableID = modRow.getValueOne(); + modRow = modTable.getLootRow(randomRoll); - if (LootTable.modTables.containsKey(subTableID)) { + if (modRow == null) + modRow = modTable.getLootRow((int) ((modTable.minRoll + modTable.maxRoll) * .05f)); - modTable = LootTable.modTables.get(subTableID); - randomRoll = gaussianLevel((int)calculatedMobLevel); + if (modRow != null) { + suffixValue = modRow.getValueOne(); + modifierSuffix = modRow.getAction(); + } + } + } + } + } - if (randomRoll < modTable.minRoll) - randomRoll = (int) modTable.minRoll; + itemBase = ItemBase.getItemBase(itemBaseUUID); - if (randomRoll > modTable.maxRoll) - randomRoll = (int) modTable.maxRoll; + if (itemBase == null) + return; - modRow = modTable.getLootRow(randomRoll); + //Handle logging of drops + LootTable.HandleDropLogs(itemBase); - if (modRow == null) - modRow = modTable.getLootRow((int) ((modTable.minRoll + modTable.maxRoll) *.05f)); + if (itemBase.getType() == ItemType.OFFERING) + spawnQuanity = 1; + if (spawnQuanity > 0) + mobLoot = new MobLoot(mob, itemBase, spawnQuanity, false); + else + mobLoot = new MobLoot(mob, itemBase, false); - if (modRow != null) { - suffixValue = modRow.getValueOne(); - modifierSuffix = modRow.getAction(); - } - } - } - } - }else{ - modGroup = LootTable.modGroups.get(groupRow.getValueTwo()); + if (!modifierPrefix.isEmpty()) + mobLoot.addPermanentEnchantment(modifierPrefix, 0, prefixValue, true); - if (modGroup != null) { + if (!modifierSuffix.isEmpty()) + mobLoot.addPermanentEnchantment(modifierSuffix, 0, suffixValue, false); + mobLoot.loadEnchantments(); - for (int a = 0;a<10;a++) { - randomRoll = ThreadLocalRandom.current().nextInt(100) + 1; - modRow = modGroup.getLootRow(randomRoll); - if (modRow != null) - break; - } + loot.add(mobLoot); + } + } - if (modRow != null) { - subTableID = modRow.getValueOne(); + private static void addMobLootResources(Mob mob, ArrayList loot, int mobLevel, int lootTableID, int cnt, boolean hotzone) { - if (LootTable.modTables.containsKey(subTableID)) { + // Member variable declaration + float calculatedMobLevel; + int minSpawn; + int maxSpawn; + int spawnQuanity = 0; - modTable = LootTable.modTables.get(subTableID); + // Lookup Table Variables + LootTable lootTable; + LootRow lootRow; + LootTable lootGroup; + LootRow groupRow = null; - randomRoll = gaussianLevel((int)calculatedMobLevel); + // Used for actual generation of items + int itemBaseUUID; + ItemBase itemBase; + MobLoot mobLoot; - if (randomRoll < modTable.minRoll) - randomRoll = (int) modTable.minRoll; + if (!LootTable.lootGroups.containsKey(lootTableID)) + return; - if (randomRoll > modTable.maxRoll) - randomRoll = (int) modTable.maxRoll; + lootGroup = LootTable.lootGroups.get(lootTableID); - modRow = modTable.getLootRow(randomRoll); + calculatedMobLevel = mobLevel; - if (modRow == null) - modRow = modTable.getLootRow((int) ((modTable.minRoll + modTable.maxRoll) *.05f)); + if (calculatedMobLevel > 49) + calculatedMobLevel = 49; - if (modRow != null) { - prefixValue = modRow.getValueOne(); - modifierPrefix = modRow.getAction(); - } - } - } - } + int roll = 0; + for (int i = 0; i < cnt; i++) { - //get modifierSuffix - modGroup = LootTable.modGroups.get(groupRow.getValueThree()); + if (lootTableID == 1901) + groupRow = lootGroup.getLootRow(66); + else if (lootTableID == 1501) + groupRow = lootGroup.getLootRow(98); + else + groupRow = lootGroup.getLootRow(80); - if (modGroup != null) { + if (groupRow == null) + return; - for (int a = 0;a<10;a++){ - randomRoll = ThreadLocalRandom.current().nextInt(100) + 1; - modRow = modGroup.getLootRow(randomRoll); - if (modRow != null) - break; - } + //get loot table for this group - if (modRow != null) { + if (!LootTable.lootTables.containsKey(groupRow.getValueOne())) + return; - subTableID = modRow.getValueOne(); + lootTable = LootTable.lootTables.get(groupRow.getValueOne()); - if (LootTable.modTables.containsKey(subTableID)) { + int minRoll = (int) ((calculatedMobLevel - 5) * 5); + int maxRoll = (int) ((calculatedMobLevel + 15) * 5); - modTable = LootTable.modTables.get(subTableID); - randomRoll = gaussianLevel((int)calculatedMobLevel); + if (minRoll < (int) lootTable.minRoll) + minRoll = (int) lootTable.minRoll; - if (randomRoll < modTable.minRoll) - randomRoll = (int) modTable.minRoll; + if (maxRoll < minRoll) + maxRoll = minRoll; - if (randomRoll > modTable.maxRoll) - randomRoll = (int) modTable.maxRoll; + if (maxRoll > 320) + maxRoll = 320; - modRow = modTable.getLootRow(randomRoll); + roll = ThreadLocalRandom.current().nextInt(minRoll, maxRoll + 1); //Does not return Max, but does return min? + lootRow = lootTable.getLootRow(roll); //get the item row from the bell's curve of level +-15 - if (modRow == null) - modRow = modTable.getLootRow((int) ((modTable.minRoll + modTable.maxRoll) *.05f)); + if (lootRow == null) + continue; //no item found for roll - if (modRow != null) { - suffixValue = modRow.getValueOne(); - modifierSuffix = modRow.getAction(); - } - } - } - } - } + itemBaseUUID = lootRow.getValueOne(); - itemBase = ItemBase.getItemBase(itemBaseUUID); + if (lootRow.getValueOne() == 0) + continue; - if (itemBase == null) - return; + //handle quantities > 1 for resource drops - //Handle logging of drops - LootTable.HandleDropLogs(itemBase); + minSpawn = lootRow.getValueTwo(); + maxSpawn = lootRow.getValueThree(); - if (itemBase.getType() == ItemType.OFFERING) - spawnQuanity = 1; + // spawnQuanity between minspawn (inclusive) and maxspawn (inclusive) - if (spawnQuanity > 0) - mobLoot = new MobLoot(mob, itemBase, spawnQuanity, false); - else - mobLoot = new MobLoot(mob, itemBase, false); + if (maxSpawn > 1) + spawnQuanity = ThreadLocalRandom.current().nextInt((maxSpawn + 1 - minSpawn)) + minSpawn; - if (!modifierPrefix.isEmpty()) - mobLoot.addPermanentEnchantment(modifierPrefix, 0, prefixValue, true); + itemBase = ItemBase.getItemBase(itemBaseUUID); - if (!modifierSuffix.isEmpty()) - mobLoot.addPermanentEnchantment(modifierSuffix, 0, suffixValue, false); + if (itemBase == null) + return; - mobLoot.loadEnchantments(); + LootTable.HandleDropLogs(itemBase); - loot.add(mobLoot); + switch (itemBase.getUUID()) { + case 19290: + continue; + case 19291: + continue; + case 19292: + continue; + case 27530: + continue; + case 973000: + continue; + case 973200: + continue; + + case 26360: + continue; + } - } - } + // Handle drop rates of resources/runes/contracts. + // We intentionally drop them in half - private static void addMobLootResources(Mob mob, ArrayList loot, int mobLevel, int lootTableID, int cnt, boolean hotzone) { + if (itemBase.getType() == ItemType.OFFERING) + spawnQuanity = 1; - // Member variable declaration - float calculatedMobLevel; - int minSpawn; - int maxSpawn; - int spawnQuanity = 0; + if (spawnQuanity > 0) + mobLoot = new MobLoot(mob, itemBase, spawnQuanity, false); + else + mobLoot = new MobLoot(mob, itemBase, false); - // Lookup Table Variables - LootTable lootTable; - LootRow lootRow; - LootTable lootGroup; - LootRow groupRow = null; + loot.add(mobLoot); - // Used for actual generation of items - int itemBaseUUID; - ItemBase itemBase; - MobLoot mobLoot; + } + } + + public static int gaussianLevel(int level) { + int ret = -76; + + while (ret < -75 || ret > 75) { + ret = (int) (ThreadLocalRandom.current().nextGaussian() * 75); + } + + return (level * 5) + ret; + + } + + //This set's the drop chances for stat runes. + public static void populateStatRuneChances() { + //+3, Increased + statRuneChances.put(250018, 60); + statRuneChances.put(250009, 60); + statRuneChances.put(250027, 60); + statRuneChances.put(250036, 60); + statRuneChances.put(250000, 60); + + //+5, Enhanced + statRuneChances.put(250019, 60); + statRuneChances.put(250010, 60); + statRuneChances.put(250028, 60); + statRuneChances.put(250037, 60); + statRuneChances.put(250001, 60); + + //+10 Exceptional + statRuneChances.put(250020, 60); + statRuneChances.put(250011, 60); + statRuneChances.put(250029, 60); + statRuneChances.put(250038, 60); + statRuneChances.put(250002, 60); + + //+15, Amazing + statRuneChances.put(250021, 60); + statRuneChances.put(250012, 60); + statRuneChances.put(250030, 60); + statRuneChances.put(250039, 60); + statRuneChances.put(250003, 60); + + //+20, Incredible + statRuneChances.put(250022, 60); + statRuneChances.put(250013, 60); + statRuneChances.put(250031, 60); + statRuneChances.put(250040, 60); + statRuneChances.put(250004, 60); + + //+25, Great + statRuneChances.put(250023, 60); + statRuneChances.put(250014, 60); + statRuneChances.put(250032, 60); + statRuneChances.put(250041, 60); + statRuneChances.put(250005, 60); + + //+30, Heroic + statRuneChances.put(250024, 60); + statRuneChances.put(250015, 60); + statRuneChances.put(250033, 60); + statRuneChances.put(250042, 60); + statRuneChances.put(250006, 60); + + //+35, Legendary + statRuneChances.put(250025, 60); + statRuneChances.put(250016, 60); + statRuneChances.put(250034, 60); + statRuneChances.put(250043, 60); + statRuneChances.put(250007, 60); + + //+40, of the Gods + statRuneChances.put(250026, 60); + statRuneChances.put(250017, 60); + statRuneChances.put(250035, 60); + statRuneChances.put(250044, 60); + statRuneChances.put(250008, 60); + } + + private static void HandleDropLogs(ItemBase itemBase) { + + if (itemBase == null) + return; + + LootTable.dropCount++; //item dropped, add to all item count. + + + if (LootTable.itemsDroppedMap.get(itemBase) == null) { + LootTable.itemsDroppedMap.put(itemBase, 1); //First time dropping, make count 1. + } else { + int dropCount = LootTable.itemsDroppedMap.get(itemBase); + dropCount++; + LootTable.itemsDroppedMap.put(itemBase, dropCount); + } + + switch (itemBase.getType()) { + case RESOURCE: + LootTable.resourceCount++; + + if (LootTable.resourceDroppedMap.get(itemBase) == null) { + LootTable.resourceDroppedMap.put(itemBase, 1); //First time dropping, make count 1. + } else { + int dropCount = LootTable.resourceDroppedMap.get(itemBase); + dropCount++; + LootTable.resourceDroppedMap.put(itemBase, dropCount); + } + break; + case RUNE: + LootTable.runeCount++; + if (LootTable.runeDroppedMap.get(itemBase) == null) { + LootTable.runeDroppedMap.put(itemBase, 1); //First time dropping, make count 1. + } else { + int dropCount = LootTable.runeDroppedMap.get(itemBase); + dropCount++; + LootTable.runeDroppedMap.put(itemBase, dropCount); + } + break; + case CONTRACT: + LootTable.contractCount++; + + if (LootTable.contractDroppedMap.get(itemBase) == null) { + LootTable.contractDroppedMap.put(itemBase, 1); //First time dropping, make count 1. + } else { + int dropCount = LootTable.contractDroppedMap.get(itemBase); + dropCount++; + LootTable.contractDroppedMap.put(itemBase, dropCount); + } + + break; + case WEAPON: //Glass Drop + + if (itemBase.isGlass()) { + LootTable.glassCount++; + if (LootTable.glassDroppedMap.get(itemBase) == null) { + LootTable.glassDroppedMap.put(itemBase, 1); //First time dropping, make count 1. + } else { + int dropCount = LootTable.glassDroppedMap.get(itemBase); + dropCount++; + LootTable.glassDroppedMap.put(itemBase, dropCount); + } + } + + break; + } + + } + + public static Item CreateGamblerItem(Item item, PlayerCharacter gambler) { + + if (item == null) + return null; + + int groupID = 0; + + switch (item.getItemBase().getUUID()) { + case 971050: //Wrapped Axe + groupID = 3000; + break; + case 971051://Wrapped Great Axe + groupID = 3005; + break; + case 971052://Wrapped Throwing Axe + groupID = 3010; + break; + case 971053:// Wrapped Bow + groupID = 3015; + break; + case 971054://Wrapped Crossbow + groupID = 3020; + break; + case 971055: //Wrapped Dagger + groupID = 3025; + break; + case 971056: // Wrapped Throwing Dagger + groupID = 3030; + break; + case 971057: // Wrapped Hammer + groupID = 3035; + break; + case 971058:// Wrapped Great Hammer + groupID = 3040; + break; + case 971059:// Wrapped Throwing Hammer + groupID = 3045; + break; + case 971060:// Wrapped Polearm + groupID = 3050; + break; + case 971061:// Wrapped Spear + groupID = 3055; + break; + case 971062:// Wrapped Staff + groupID = 3060; + break; + case 971063:// Wrapped Sword + groupID = 3065; + break; + case 971064:// Wrapped Great Sword + groupID = 3070; + break; + case 971065:// Wrapped Unarmed Weapon + groupID = 3075; + break; + case 971066:// Wrapped Cloth Armor + groupID = 3100; + break; + case 971067:// Wrapped Light Armor + groupID = 3105; + break; + case 971068:// Wrapped Medium Armor + groupID = 3110; + break; + case 971069:// Wrapped Heavy Armor + groupID = 3115; + break; + case 971070:// Wrapped Rune + groupID = 3200; + break; + case 971071:// Wrapped City Improvement + groupID = 3210; + break; + } + //couldnt find group + if (groupID == 0) + return null; + + + LootTable lootGroup = LootTable.lootGroups.get(groupID); + + if (lootGroup == null) + return null; + float calculatedMobLevel; + int minSpawn; + int maxSpawn; + int spawnQuanity = 0; + int prefixValue = 0; + int suffixValue = 0; + int subTableID; + String modifierPrefix = ""; + String modifierSuffix = ""; + + // Lookup Table Variables + LootTable lootTable; + LootRow lootRow; + LootRow groupRow = null; + LootTable modTable; + LootTable modGroup; + LootRow modRow = null; + + // Used for actual generation of items + int itemBaseUUID; + ItemBase itemBase = null; + MobLoot mobLoot; + + + int roll = ThreadLocalRandom.current().nextInt(100) + 1; //Does not return Max, but does return min? + + groupRow = lootGroup.getLootRow(roll); + + lootTable = LootTable.lootTables.get(groupRow.getValueOne()); + roll = ThreadLocalRandom.current().nextInt(100) + 1; + lootRow = lootTable.getLootRow(roll + 220); //get the item row from the bell's curve of level +-15 + + if (lootRow == null) + return null; //no item found for roll + + itemBaseUUID = lootRow.getValueOne(); + + + if (lootRow.getValueOne() == 0) + return null; + + //handle quantities > 1 for resource drops + minSpawn = lootRow.getValueTwo(); + maxSpawn = lootRow.getValueThree(); + + // spawnQuanity between minspawn (inclusive) and maxspawn (inclusive) + if (maxSpawn > 1) + spawnQuanity = ThreadLocalRandom.current().nextInt((maxSpawn + 1 - minSpawn)) + minSpawn; - if (!LootTable.lootGroups.containsKey(lootTableID)) - return; - lootGroup = LootTable.lootGroups.get(lootTableID); + //get modifierPrefix - calculatedMobLevel = mobLevel; + calculatedMobLevel = 49; - if (calculatedMobLevel > 49) - calculatedMobLevel = 49; - int roll = 0; - for (int i = 0; i < cnt; i++) { + int chanceMod = ThreadLocalRandom.current().nextInt(100) + 1; - if (lootTableID == 1901) - groupRow = lootGroup.getLootRow(66); - else if (lootTableID == 1501) - groupRow = lootGroup.getLootRow(98); - else - groupRow = lootGroup.getLootRow(80); + if (chanceMod < 25) { + modGroup = LootTable.modGroups.get(groupRow.getValueTwo()); - if (groupRow == null) - return; + if (modGroup != null) { - //get loot table for this group - if (!LootTable.lootTables.containsKey(groupRow.getValueOne())) - return; + for (int a = 0; a < 10; a++) { + roll = ThreadLocalRandom.current().nextInt(100) + 1; + modRow = modGroup.getLootRow(roll); + if (modRow != null) + break; + } - lootTable = LootTable.lootTables.get(groupRow.getValueOne()); - int minRoll = (int) ((calculatedMobLevel-5) * 5); - int maxRoll = (int) ((calculatedMobLevel + 15) *5); + if (modRow != null) { + subTableID = modRow.getValueOne(); - if (minRoll < (int)lootTable.minRoll) - minRoll = (int)lootTable.minRoll; + if (LootTable.modTables.containsKey(subTableID)) { - if (maxRoll < minRoll) - maxRoll = minRoll; + modTable = LootTable.modTables.get(subTableID); - if (maxRoll > 320) - maxRoll = 320; + roll = gaussianLevel((int) calculatedMobLevel); - roll = ThreadLocalRandom.current().nextInt(minRoll, maxRoll + 1); //Does not return Max, but does return min? - lootRow = lootTable.getLootRow(roll); //get the item row from the bell's curve of level +-15 + if (roll < modTable.minRoll) + roll = (int) modTable.minRoll; - if (lootRow == null) - continue; //no item found for roll + if (roll > modTable.maxRoll) + roll = (int) modTable.maxRoll; - itemBaseUUID = lootRow.getValueOne(); - if (lootRow.getValueOne() == 0) - continue; + modRow = modTable.getLootRow(roll); - //handle quantities > 1 for resource drops + if (modRow != null) { + prefixValue = modRow.getValueOne(); + modifierPrefix = modRow.getAction(); + } + } + } + } + } else if (chanceMod < 50) { + modGroup = LootTable.modGroups.get(groupRow.getValueThree()); - minSpawn = lootRow.getValueTwo(); - maxSpawn = lootRow.getValueThree(); + if (modGroup != null) { - // spawnQuanity between minspawn (inclusive) and maxspawn (inclusive) + for (int a = 0; a < 10; a++) { + roll = ThreadLocalRandom.current().nextInt(100) + 1; + modRow = modGroup.getLootRow(roll); + if (modRow != null) + break; + } - if (maxSpawn > 1) - spawnQuanity = ThreadLocalRandom.current().nextInt((maxSpawn + 1 - minSpawn)) + minSpawn; + if (modRow != null) { - itemBase = ItemBase.getItemBase(itemBaseUUID); + subTableID = modRow.getValueOne(); - if (itemBase == null) - return; + if (LootTable.modTables.containsKey(subTableID)) { - LootTable.HandleDropLogs(itemBase); + modTable = LootTable.modTables.get(subTableID); + roll = gaussianLevel((int) calculatedMobLevel); - switch (itemBase.getUUID()){ - case 19290: - continue; - case 19291: - continue; - case 19292: - continue; - case 27530: - continue; - case 973000: - continue; - case 973200: - continue; - - case 26360: - continue; - } + if (roll < modTable.minRoll) + roll = (int) modTable.minRoll; - // Handle drop rates of resources/runes/contracts. - // We intentionally drop them in half + if (roll > modTable.maxRoll) + roll = (int) modTable.maxRoll; - if (itemBase.getType() == ItemType.OFFERING) - spawnQuanity = 1; + modRow = modTable.getLootRow(roll); - if (spawnQuanity > 0) - mobLoot = new MobLoot(mob, itemBase, spawnQuanity, false); - else - mobLoot = new MobLoot(mob, itemBase, false); + if (modRow == null) { + modRow = modTable.getLootRow((int) ((modTable.minRoll + modTable.maxRoll) * .05f)); + } - loot.add(mobLoot); + if (modRow != null) { + suffixValue = modRow.getValueOne(); + modifierSuffix = modRow.getAction(); + } + } + } + } + } else { + modGroup = LootTable.modGroups.get(groupRow.getValueTwo()); - } - } + if (modGroup != null) { - public static int gaussianLevel(int level) { - int ret = -76; - while (ret < -75 || ret > 75) { - ret = (int) (ThreadLocalRandom.current().nextGaussian() * 75); - } - - return (level * 5) + ret; - - } - - //This set's the drop chances for stat runes. - public static void populateStatRuneChances() { - //+3, Increased - statRuneChances.put(250018, 60); - statRuneChances.put(250009, 60); - statRuneChances.put(250027, 60); - statRuneChances.put(250036, 60); - statRuneChances.put(250000, 60); - - //+5, Enhanced - statRuneChances.put(250019, 60); - statRuneChances.put(250010, 60); - statRuneChances.put(250028, 60); - statRuneChances.put(250037, 60); - statRuneChances.put(250001, 60); - - //+10 Exceptional - statRuneChances.put(250020, 60); - statRuneChances.put(250011, 60); - statRuneChances.put(250029, 60); - statRuneChances.put(250038, 60); - statRuneChances.put(250002, 60); - - //+15, Amazing - statRuneChances.put(250021, 60); - statRuneChances.put(250012, 60); - statRuneChances.put(250030, 60); - statRuneChances.put(250039, 60); - statRuneChances.put(250003, 60); - - //+20, Incredible - statRuneChances.put(250022, 60); - statRuneChances.put(250013, 60); - statRuneChances.put(250031, 60); - statRuneChances.put(250040, 60); - statRuneChances.put(250004, 60); - - //+25, Great - statRuneChances.put(250023, 60); - statRuneChances.put(250014, 60); - statRuneChances.put(250032, 60); - statRuneChances.put(250041, 60); - statRuneChances.put(250005, 60); - - //+30, Heroic - statRuneChances.put(250024, 60); - statRuneChances.put(250015, 60); - statRuneChances.put(250033, 60); - statRuneChances.put(250042, 60); - statRuneChances.put(250006, 60); - - //+35, Legendary - statRuneChances.put(250025, 60); - statRuneChances.put(250016, 60); - statRuneChances.put(250034, 60); - statRuneChances.put(250043, 60); - statRuneChances.put(250007, 60); - - //+40, of the Gods - statRuneChances.put(250026, 60); - statRuneChances.put(250017, 60); - statRuneChances.put(250035, 60); - statRuneChances.put(250044, 60); - statRuneChances.put(250008, 60); - } - - public ConcurrentHashMap getLootTable() { - return lootTable; - } - - private static void HandleDropLogs(ItemBase itemBase){ - - if (itemBase == null) - return; - - LootTable.dropCount++; //item dropped, add to all item count. - - - if (LootTable.itemsDroppedMap.get(itemBase) == null){ - LootTable.itemsDroppedMap.put(itemBase, 1); //First time dropping, make count 1. - }else{ - int dropCount = LootTable.itemsDroppedMap.get(itemBase); - dropCount++; - LootTable.itemsDroppedMap.put(itemBase, dropCount); - } - - switch (itemBase.getType()){ - case RESOURCE: - LootTable.resourceCount++; - - if (LootTable.resourceDroppedMap.get(itemBase) == null){ - LootTable.resourceDroppedMap.put(itemBase, 1); //First time dropping, make count 1. - }else{ - int dropCount = LootTable.resourceDroppedMap.get(itemBase); - dropCount++; - LootTable.resourceDroppedMap.put(itemBase, dropCount); - } - break; - case RUNE: - LootTable.runeCount++; - if (LootTable.runeDroppedMap.get(itemBase) == null){ - LootTable.runeDroppedMap.put(itemBase, 1); //First time dropping, make count 1. - }else{ - int dropCount = LootTable.runeDroppedMap.get(itemBase); - dropCount++; - LootTable.runeDroppedMap.put(itemBase, dropCount); - } - break; - case CONTRACT: - LootTable.contractCount++; - - if (LootTable.contractDroppedMap.get(itemBase) == null){ - LootTable.contractDroppedMap.put(itemBase, 1); //First time dropping, make count 1. - }else{ - int dropCount = LootTable.contractDroppedMap.get(itemBase); - dropCount++; - LootTable.contractDroppedMap.put(itemBase, dropCount); - } - - break; - case WEAPON: //Glass Drop - - if (itemBase.isGlass()){ - LootTable.glassCount++; - if (LootTable.glassDroppedMap.get(itemBase) == null){ - LootTable.glassDroppedMap.put(itemBase, 1); //First time dropping, make count 1. - }else{ - int dropCount = LootTable.glassDroppedMap.get(itemBase); - dropCount++; - LootTable.glassDroppedMap.put(itemBase, dropCount); - } - } - - break; - } - - } - - public static Item CreateGamblerItem(Item item, PlayerCharacter gambler){ - - if (item == null) - return null; - - int groupID = 0; - - switch (item.getItemBase().getUUID()){ - case 971050: //Wrapped Axe - groupID = 3000; - break; - case 971051://Wrapped Great Axe - groupID = 3005; - break; - case 971052://Wrapped Throwing Axe - groupID = 3010; - break; - case 971053:// Wrapped Bow - groupID = 3015; - break; - case 971054://Wrapped Crossbow - groupID = 3020; - break; - case 971055: //Wrapped Dagger - groupID = 3025; - break; - case 971056: // Wrapped Throwing Dagger - groupID = 3030; - break; - case 971057: // Wrapped Hammer - groupID = 3035; - break; - case 971058:// Wrapped Great Hammer - groupID = 3040; - break; - case 971059:// Wrapped Throwing Hammer - groupID = 3045; - break; - case 971060:// Wrapped Polearm - groupID = 3050; - break; - case 971061:// Wrapped Spear - groupID = 3055; - break; - case 971062:// Wrapped Staff - groupID = 3060; - break; - case 971063:// Wrapped Sword - groupID = 3065; - break; - case 971064:// Wrapped Great Sword - groupID = 3070; - break; - case 971065:// Wrapped Unarmed Weapon - groupID = 3075; - break; - case 971066:// Wrapped Cloth Armor - groupID = 3100; - break; - case 971067:// Wrapped Light Armor - groupID = 3105; - break; - case 971068:// Wrapped Medium Armor - groupID = 3110; - break; - case 971069:// Wrapped Heavy Armor - groupID = 3115; - break; - case 971070:// Wrapped Rune - groupID = 3200; - break; - case 971071:// Wrapped City Improvement - groupID = 3210; - break; - } - //couldnt find group - if (groupID == 0) - return null; - - - LootTable lootGroup = LootTable.lootGroups.get(groupID); - - if (lootGroup == null) - return null; - float calculatedMobLevel; - int minSpawn; - int maxSpawn; - int spawnQuanity = 0; - int prefixValue = 0; - int suffixValue = 0; - int subTableID; - String modifierPrefix = ""; - String modifierSuffix = ""; - - // Lookup Table Variables - LootTable lootTable; - LootRow lootRow; - LootRow groupRow = null; - LootTable modTable; - LootTable modGroup; - LootRow modRow = null; - - // Used for actual generation of items - int itemBaseUUID; - ItemBase itemBase = null; - MobLoot mobLoot; - - - - int roll = ThreadLocalRandom.current().nextInt(100) + 1; //Does not return Max, but does return min? - - groupRow = lootGroup.getLootRow(roll); - - lootTable = LootTable.lootTables.get(groupRow.getValueOne()); - roll = ThreadLocalRandom.current().nextInt(100) + 1; - lootRow = lootTable.getLootRow(roll + 220); //get the item row from the bell's curve of level +-15 - - if (lootRow == null) - return null; //no item found for roll + for (int a = 0; a < 10; a++) { + roll = ThreadLocalRandom.current().nextInt(100) + 1; + modRow = modGroup.getLootRow(roll); + if (modRow != null) + break; + } - itemBaseUUID = lootRow.getValueOne(); + if (modRow != null) { + subTableID = modRow.getValueOne(); + if (LootTable.modTables.containsKey(subTableID)) { - if (lootRow.getValueOne() == 0) - return null; + modTable = LootTable.modTables.get(subTableID); - //handle quantities > 1 for resource drops - minSpawn = lootRow.getValueTwo(); - maxSpawn = lootRow.getValueThree(); + roll = gaussianLevel((int) calculatedMobLevel); - // spawnQuanity between minspawn (inclusive) and maxspawn (inclusive) - if (maxSpawn > 1) - spawnQuanity = ThreadLocalRandom.current().nextInt((maxSpawn + 1 - minSpawn)) + minSpawn; + if (roll < modTable.minRoll) + roll = (int) modTable.minRoll; + if (roll > modTable.maxRoll) + roll = (int) modTable.maxRoll; - //get modifierPrefix + modRow = modTable.getLootRow(roll); - calculatedMobLevel = 49; + if (modRow == null) { + modRow = modTable.getLootRow((int) ((modTable.minRoll + modTable.maxRoll) * .05f)); + } + if (modRow != null) { + prefixValue = modRow.getValueOne(); + modifierPrefix = modRow.getAction(); + } + } + } + } + //get modifierSuffix + modGroup = LootTable.modGroups.get(groupRow.getValueThree()); - int chanceMod = ThreadLocalRandom.current().nextInt(100) + 1; + if (modGroup != null) { - if (chanceMod < 25){ - modGroup = LootTable.modGroups.get(groupRow.getValueTwo()); + for (int a = 0; a < 10; a++) { + roll = ThreadLocalRandom.current().nextInt(100) + 1; + modRow = modGroup.getLootRow(roll); + if (modRow != null) + break; + } - if (modGroup != null) { + if (modRow != null) { + subTableID = modRow.getValueOne(); - for (int a = 0;a<10;a++){ - roll = ThreadLocalRandom.current().nextInt(100) + 1; - modRow = modGroup.getLootRow(roll); - if (modRow != null) - break; - } + if (LootTable.modTables.containsKey(subTableID)) { + modTable = LootTable.modTables.get(subTableID); + roll = gaussianLevel((int) calculatedMobLevel); - if (modRow != null) { - subTableID = modRow.getValueOne(); + if (roll < modTable.minRoll) + roll = (int) modTable.minRoll; - if (LootTable.modTables.containsKey(subTableID)) { + if (roll > modTable.maxRoll) + roll = (int) modTable.maxRoll; - modTable = LootTable.modTables.get(subTableID); + modRow = modTable.getLootRow(roll); - roll = gaussianLevel((int)calculatedMobLevel); + if (modRow == null) { + modRow = modTable.getLootRow((int) ((modTable.minRoll + modTable.maxRoll) * .05f)); + } - if (roll < modTable.minRoll) - roll = (int) modTable.minRoll; + if (modRow != null) { + suffixValue = modRow.getValueOne(); + modifierSuffix = modRow.getAction(); + } + } + } + } + } - if (roll > modTable.maxRoll) - roll = (int) modTable.maxRoll; + itemBase = ItemBase.getItemBase(itemBaseUUID); + byte charges = (byte) itemBase.getNumCharges(); + short dur = (short) itemBase.getDurability(); - modRow = modTable.getLootRow(roll); + short weight = itemBase.getWeight(); + if (!gambler.getCharItemManager().hasRoomInventory(weight)) { + return null; + } - if (modRow != null) { - prefixValue = modRow.getValueOne(); - modifierPrefix = modRow.getAction(); - } - } - } - } - }else if(chanceMod < 50){ - modGroup = LootTable.modGroups.get(groupRow.getValueThree()); - if (modGroup != null) { + Item gambledItem = new Item(itemBase, gambler.getObjectUUID(), + OwnerType.PlayerCharacter, charges, charges, dur, dur, + true, false, ItemContainerType.INVENTORY, (byte) 0, + new ArrayList<>(), ""); - for (int a = 0;a<10;a++){ - roll = ThreadLocalRandom.current().nextInt(100) + 1; - modRow = modGroup.getLootRow(roll); - if (modRow != null) - break; - } + if (spawnQuanity == 0 && itemBase.getType().equals(ItemType.RESOURCE)) + spawnQuanity = 1; - if (modRow != null) { + if (spawnQuanity > 0) + item.setNumOfItems(spawnQuanity); - subTableID = modRow.getValueOne(); + try { + gambledItem = DbManager.ItemQueries.ADD_ITEM(gambledItem); - if (LootTable.modTables.containsKey(subTableID)) { + } catch (Exception e) { + Logger.error(e); + } - modTable = LootTable.modTables.get(subTableID); - roll = gaussianLevel((int)calculatedMobLevel); + if (gambledItem == null) { - if (roll < modTable.minRoll) - roll = (int) modTable.minRoll; + return null; + } + if (!modifierPrefix.isEmpty()) + gambledItem.addPermanentEnchantment(modifierPrefix, 0); - if (roll > modTable.maxRoll) - roll = (int) modTable.maxRoll; + if (!modifierSuffix.isEmpty()) + gambledItem.addPermanentEnchantment(modifierSuffix, 0); - modRow = modTable.getLootRow(roll); - if (modRow == null){ - modRow = modTable.getLootRow((int) ((modTable.minRoll + modTable.maxRoll) *.05f)); - } + //add item to inventory + gambler.getCharItemManager().addItemToInventory(gambledItem); - if (modRow != null) { - suffixValue = modRow.getValueOne(); - modifierSuffix = modRow.getAction(); - } - } - } - } - }else{ - modGroup = LootTable.modGroups.get(groupRow.getValueTwo()); + gambler.getCharItemManager().updateInventory(); - if (modGroup != null) { + return gambledItem; + } + public void addRow(float min, float max, int valueOne, int valueTwo, int valueThree, String action) { - for (int a = 0;a<10;a++){ - roll = ThreadLocalRandom.current().nextInt(100) + 1; - modRow = modGroup.getLootRow(roll); - if (modRow != null) - break; - } + //hackey way to set the minimum roll for SHIAT! + if (min < this.minRoll) + this.minRoll = min; + if (max > this.maxRoll) + this.maxRoll = max; - if (modRow != null) { - subTableID = modRow.getValueOne(); + int minInt = (int) min; + int maxInt = (int) max; - if (LootTable.modTables.containsKey(subTableID)) { + //Round up min + if (minInt != min) { + min = minInt + 1; + } - modTable = LootTable.modTables.get(subTableID); + //Round down max; + if (maxInt != max) + max = maxInt; - roll = gaussianLevel((int)calculatedMobLevel); - if (roll < modTable.minRoll) - roll = (int) modTable.minRoll; + LootRow lootRow = new LootRow(valueOne, valueTwo, valueThree, action); + for (int i = (int) min; i <= max; i++) { + lootTable.put(i, lootRow); + } + } - if (roll > modTable.maxRoll) - roll = (int) modTable.maxRoll; + public LootRow getLootRow(int probability) { + if (lootTable.containsKey(probability)) + return lootTable.get(probability); + return null; + } - - - modRow = modTable.getLootRow(roll); - - if (modRow == null){ - modRow = modTable.getLootRow((int) ((modTable.minRoll + modTable.maxRoll) *.05f)); - } - - if (modRow != null) { - prefixValue = modRow.getValueOne(); - modifierPrefix = modRow.getAction(); - } - } - } - } - - //get modifierSuffix - modGroup = LootTable.modGroups.get(groupRow.getValueThree()); - - if (modGroup != null) { - - for (int a = 0;a<10;a++){ - roll = ThreadLocalRandom.current().nextInt(100) + 1; - modRow = modGroup.getLootRow(roll); - if (modRow != null) - break; - } - - if (modRow != null) { - - subTableID = modRow.getValueOne(); - - if (LootTable.modTables.containsKey(subTableID)) { - - modTable = LootTable.modTables.get(subTableID); - roll = gaussianLevel((int)calculatedMobLevel); - - if (roll < modTable.minRoll) - roll = (int) modTable.minRoll; - - if (roll > modTable.maxRoll) - roll = (int) modTable.maxRoll; - - modRow = modTable.getLootRow(roll); - - if (modRow == null){ - modRow = modTable.getLootRow((int) ((modTable.minRoll + modTable.maxRoll) *.05f)); - } - - if (modRow != null) { - suffixValue = modRow.getValueOne(); - modifierSuffix = modRow.getAction(); - } - } - } - } - } - - - itemBase = ItemBase.getItemBase(itemBaseUUID); - byte charges = (byte) itemBase.getNumCharges(); - short dur = (short) itemBase.getDurability(); - - - - short weight = itemBase.getWeight(); - if (!gambler.getCharItemManager().hasRoomInventory(weight)) { - return null; - } - - - Item gambledItem = new Item(itemBase, gambler.getObjectUUID(), - OwnerType.PlayerCharacter, charges, charges, dur, dur, - true, false,ItemContainerType.INVENTORY,(byte) 0, - new ArrayList<>(),""); - - if (spawnQuanity == 0 && itemBase.getType().equals(ItemType.RESOURCE)) - spawnQuanity = 1; - - if (spawnQuanity > 0) - item.setNumOfItems(spawnQuanity); - - try { - gambledItem = DbManager.ItemQueries.ADD_ITEM(gambledItem); - - } catch (Exception e) { - Logger.error(e); - } - - if (gambledItem == null) { - - return null; - } - if (!modifierPrefix.isEmpty()) - gambledItem.addPermanentEnchantment(modifierPrefix, 0); - - if (!modifierSuffix.isEmpty()) - gambledItem.addPermanentEnchantment(modifierSuffix, 0); - - - - //add item to inventory - gambler.getCharItemManager().addItemToInventory(gambledItem); - - gambler.getCharItemManager().updateInventory(); - - return gambledItem; - } + public ConcurrentHashMap getLootTable() { + return lootTable; + } } diff --git a/src/engine/objects/MaxSkills.java b/src/engine/objects/MaxSkills.java index 00a12414..4850190e 100644 --- a/src/engine/objects/MaxSkills.java +++ b/src/engine/objects/MaxSkills.java @@ -14,66 +14,63 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; -public class MaxSkills { +public class MaxSkills { - private int runeID; - private int skillToken; - private int skillLevel; - private int maxSkillPercent; + public static HashMap> MaxSkillsSet = new HashMap<>(); + private int runeID; + private int skillToken; + private int skillLevel; + private int maxSkillPercent; + /** + * ResultSet Constructor + */ - public static HashMap> MaxSkillsSet = new HashMap<>(); - - - /** - * ResultSet Constructor - */ - - public MaxSkills(ResultSet rs) throws SQLException { - this.runeID = rs.getInt("runeID"); - this.skillToken =rs.getInt("skillToken"); - this.skillLevel = rs.getInt("skillLevel"); + public MaxSkills(ResultSet rs) throws SQLException { + this.runeID = rs.getInt("runeID"); + this.skillToken = rs.getInt("skillToken"); + this.skillLevel = rs.getInt("skillLevel"); this.maxSkillPercent = rs.getInt("maxSkillPercent"); } - public MaxSkills(int runeID, int skillToken, int skillLevel, int maxSkillPercent) { - super(); - this.runeID = runeID; - this.skillToken = skillToken; - this.skillLevel = skillLevel; + public MaxSkills(int runeID, int skillToken, int skillLevel, int maxSkillPercent) { + super(); + this.runeID = runeID; + this.skillToken = skillToken; + this.skillLevel = skillLevel; this.maxSkillPercent = maxSkillPercent; } - public int getRuneID() { - return runeID; - } + public int getRuneID() { + return runeID; + } - public void setRuneID(int runeID) { - this.runeID = runeID; - } + public void setRuneID(int runeID) { + this.runeID = runeID; + } - public int getSkillLevel() { - return skillLevel; - } + public int getSkillLevel() { + return skillLevel; + } - public void setSkillLevel(int skillLevel) { - this.skillLevel = skillLevel; - } + public void setSkillLevel(int skillLevel) { + this.skillLevel = skillLevel; + } - public int getSkillToken() { - return skillToken; - } + public int getSkillToken() { + return skillToken; + } - public void setSkillToken(int skillToken) { - this.skillToken = skillToken; - } + public void setSkillToken(int skillToken) { + this.skillToken = skillToken; + } - public int getMaxSkillPercent() { - return maxSkillPercent; - } + public int getMaxSkillPercent() { + return maxSkillPercent; + } - public void setMaxSkillPercent(int maxSkillPercent) { - this.maxSkillPercent = maxSkillPercent; - } + public void setMaxSkillPercent(int maxSkillPercent) { + this.maxSkillPercent = maxSkillPercent; + } } diff --git a/src/engine/objects/MenuOption.java b/src/engine/objects/MenuOption.java index 8363cac4..36ea561a 100644 --- a/src/engine/objects/MenuOption.java +++ b/src/engine/objects/MenuOption.java @@ -15,44 +15,45 @@ import java.sql.SQLException; public class MenuOption extends AbstractGameObject { - private final int menuID; - private final String message; - private final int optionID; - private final int prereq; - - /** - * ResultSet Constructor - */ - public MenuOption(ResultSet rs) throws SQLException { - super(rs); - this.menuID = rs.getInt("menuID"); - this.message = rs.getString("message"); - this.optionID = rs.getInt("optionID"); - this.prereq = rs.getInt("prereq"); - } - - /* - * Getters - */ - public int getMenuID() { - return this.menuID; - } - - public String getMessage() { - return this.message; - } - - public int getOptionID() { - return this.optionID; - } - - public int getPrereq() { - return this.prereq; - } - - /* - * Database - */ - @Override - public void updateDatabase() {} + private final int menuID; + private final String message; + private final int optionID; + private final int prereq; + + /** + * ResultSet Constructor + */ + public MenuOption(ResultSet rs) throws SQLException { + super(rs); + this.menuID = rs.getInt("menuID"); + this.message = rs.getString("message"); + this.optionID = rs.getInt("optionID"); + this.prereq = rs.getInt("prereq"); + } + + /* + * Getters + */ + public int getMenuID() { + return this.menuID; + } + + public String getMessage() { + return this.message; + } + + public int getOptionID() { + return this.optionID; + } + + public int getPrereq() { + return this.prereq; + } + + /* + * Database + */ + @Override + public void updateDatabase() { + } } diff --git a/src/engine/objects/MeshBounds.java b/src/engine/objects/MeshBounds.java index 5266746b..10688e32 100644 --- a/src/engine/objects/MeshBounds.java +++ b/src/engine/objects/MeshBounds.java @@ -17,33 +17,33 @@ import java.sql.SQLException; public class MeshBounds { - public int meshID; - public final float minX; - public final float minY; - public final float minZ; - public final float maxX; - public final float maxY; - public final float maxZ; - public final float radius; - - public MeshBounds(ResultSet rs) throws SQLException { - - meshID = rs.getInt("meshID"); - minX = rs.getFloat("minX"); - minY = rs.getFloat("minY"); - minZ = rs.getFloat("minZ"); - maxX = rs.getFloat("maxX"); - maxY = rs.getFloat("maxY"); - maxZ = rs.getFloat("maxZ"); - float radiusX = (int) maxX; - float radiusZ = (int) maxZ; - - radius = Math.max(radiusX,radiusZ); - } - - public static void InitializeBuildingBounds(){ - Bounds.meshBoundsCache = DbManager.BuildingQueries.LOAD_MESH_BOUNDS(); - } - + public final float minX; + public final float minY; + public final float minZ; + public final float maxX; + public final float maxY; + public final float maxZ; + public final float radius; + public int meshID; + + public MeshBounds(ResultSet rs) throws SQLException { + + meshID = rs.getInt("meshID"); + minX = rs.getFloat("minX"); + minY = rs.getFloat("minY"); + minZ = rs.getFloat("minZ"); + maxX = rs.getFloat("maxX"); + maxY = rs.getFloat("maxY"); + maxZ = rs.getFloat("maxZ"); + float radiusX = (int) maxX; + float radiusZ = (int) maxZ; + + radius = Math.max(radiusX, radiusZ); + } + + public static void InitializeBuildingBounds() { + Bounds.meshBoundsCache = DbManager.BuildingQueries.LOAD_MESH_BOUNDS(); + } + } diff --git a/src/engine/objects/Mine.java b/src/engine/objects/Mine.java index 85d61b80..b0dc6653 100644 --- a/src/engine/objects/Mine.java +++ b/src/engine/objects/Mine.java @@ -44,6 +44,8 @@ public class Mine extends AbstractGameObject { public static ConcurrentHashMap mineMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); public static ConcurrentHashMap towerMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private final String zoneName; + private final Zone parentZone; public boolean isActive = false; public PlayerCharacter lastClaimer; public boolean wasClaimed = false; @@ -52,12 +54,10 @@ public class Mine extends AbstractGameObject { public GuildTag guildTag; public String nationName; public GuildTag nationTag; - private final String zoneName; private Resource production; private Guild owningGuild; private int flags; private int buildingID; - private final Zone parentZone; private MineProduction mineType; /** diff --git a/src/engine/objects/MineProduction.java b/src/engine/objects/MineProduction.java index 76c15f0a..0aac80a0 100644 --- a/src/engine/objects/MineProduction.java +++ b/src/engine/objects/MineProduction.java @@ -13,78 +13,78 @@ import java.util.HashMap; public enum MineProduction { - LUMBER("Lumber Camp", new HashMap<>(), Resource.WORMWOOD, 1618637196, 1663491950), - ORE("Ore Mine", new HashMap<>(), Resource.OBSIDIAN, 518103023, -788976428), - GOLD("Gold Mine", new HashMap<>(), Resource.GALVOR, -662193002, -1227205358), - MAGIC("Magic Mine", new HashMap<>(), Resource.BLOODSTONE, 504746863, -1753567069); + LUMBER("Lumber Camp", new HashMap<>(), Resource.WORMWOOD, 1618637196, 1663491950), + ORE("Ore Mine", new HashMap<>(), Resource.OBSIDIAN, 518103023, -788976428), + GOLD("Gold Mine", new HashMap<>(), Resource.GALVOR, -662193002, -1227205358), + MAGIC("Magic Mine", new HashMap<>(), Resource.BLOODSTONE, 504746863, -1753567069); - public final String name; - public final HashMap resources; - public final Resource xpac; - public final int hash; - public final int xpacHash; + public final String name; + public final HashMap resources; + public final Resource xpac; + public final int hash; + public final int xpacHash; - MineProduction(String name, HashMapresources, Resource xpac, int hash, int xpacHash) { - this.name = name; - this.resources = resources; - this.xpac = xpac; - this.hash = hash; - this.xpacHash = xpacHash; - } + MineProduction(String name, HashMap resources, Resource xpac, int hash, int xpacHash) { + this.name = name; + this.resources = resources; + this.xpac = xpac; + this.hash = hash; + this.xpacHash = xpacHash; + } - public static void addResources() { - if (MineProduction.LUMBER.resources.size() == 0) { - MineProduction.LUMBER.resources.put(7, Resource.GOLD); - MineProduction.LUMBER.resources.put(1580004, Resource.LUMBER); - MineProduction.LUMBER.resources.put(1580005, Resource.OAK); - MineProduction.LUMBER.resources.put(1580006, Resource.BRONZEWOOD); - MineProduction.LUMBER.resources.put(1580007, Resource.MANDRAKE); - } - if (MineProduction.ORE.resources.size() == 0) { - MineProduction.ORE.resources.put(7, Resource.GOLD); - MineProduction.ORE.resources.put(1580000, Resource.STONE); - MineProduction.ORE.resources.put(1580001, Resource.TRUESTEEL); - MineProduction.ORE.resources.put(1580002, Resource.IRON); - MineProduction.ORE.resources.put(1580003, Resource.ADAMANT); - } - if (MineProduction.GOLD.resources.size() == 0) { - MineProduction.GOLD.resources.put(7, Resource.GOLD); - MineProduction.GOLD.resources.put(1580000, Resource.STONE); - MineProduction.GOLD.resources.put(1580008, Resource.COAL); - MineProduction.GOLD.resources.put(1580009, Resource.AGATE); - MineProduction.GOLD.resources.put(1580010, Resource.DIAMOND); - MineProduction.GOLD.resources.put(1580011, Resource.ONYX); - } - if (MineProduction.MAGIC.resources.size() == 0) { - MineProduction.MAGIC.resources.put(7, Resource.GOLD); - MineProduction.MAGIC.resources.put(1580012, Resource.AZOTH); - MineProduction.MAGIC.resources.put(1580013, Resource.ORICHALK); - MineProduction.MAGIC.resources.put(1580014, Resource.ANTIMONY); - MineProduction.MAGIC.resources.put(1580015, Resource.SULFUR); - MineProduction.MAGIC.resources.put(1580016, Resource.QUICKSILVER); - } - } + public static void addResources() { + if (MineProduction.LUMBER.resources.size() == 0) { + MineProduction.LUMBER.resources.put(7, Resource.GOLD); + MineProduction.LUMBER.resources.put(1580004, Resource.LUMBER); + MineProduction.LUMBER.resources.put(1580005, Resource.OAK); + MineProduction.LUMBER.resources.put(1580006, Resource.BRONZEWOOD); + MineProduction.LUMBER.resources.put(1580007, Resource.MANDRAKE); + } + if (MineProduction.ORE.resources.size() == 0) { + MineProduction.ORE.resources.put(7, Resource.GOLD); + MineProduction.ORE.resources.put(1580000, Resource.STONE); + MineProduction.ORE.resources.put(1580001, Resource.TRUESTEEL); + MineProduction.ORE.resources.put(1580002, Resource.IRON); + MineProduction.ORE.resources.put(1580003, Resource.ADAMANT); + } + if (MineProduction.GOLD.resources.size() == 0) { + MineProduction.GOLD.resources.put(7, Resource.GOLD); + MineProduction.GOLD.resources.put(1580000, Resource.STONE); + MineProduction.GOLD.resources.put(1580008, Resource.COAL); + MineProduction.GOLD.resources.put(1580009, Resource.AGATE); + MineProduction.GOLD.resources.put(1580010, Resource.DIAMOND); + MineProduction.GOLD.resources.put(1580011, Resource.ONYX); + } + if (MineProduction.MAGIC.resources.size() == 0) { + MineProduction.MAGIC.resources.put(7, Resource.GOLD); + MineProduction.MAGIC.resources.put(1580012, Resource.AZOTH); + MineProduction.MAGIC.resources.put(1580013, Resource.ORICHALK); + MineProduction.MAGIC.resources.put(1580014, Resource.ANTIMONY); + MineProduction.MAGIC.resources.put(1580015, Resource.SULFUR); + MineProduction.MAGIC.resources.put(1580016, Resource.QUICKSILVER); + } + } - public static MineProduction getByName(String name) { - if (name.toLowerCase().equals("lumber")) - return MineProduction.LUMBER; - else if (name.toLowerCase().equals("ore")) - return MineProduction.ORE; - else if (name.toLowerCase().equals("gold")) - return MineProduction.GOLD; - else - return MineProduction.MAGIC; - } + public static MineProduction getByName(String name) { + if (name.toLowerCase().equals("lumber")) + return MineProduction.LUMBER; + else if (name.toLowerCase().equals("ore")) + return MineProduction.ORE; + else if (name.toLowerCase().equals("gold")) + return MineProduction.GOLD; + else + return MineProduction.MAGIC; + } - public boolean validForMine(Resource r, boolean isXpac) { - if (r == null) - return false; - if (this.resources.containsKey(r.UUID)) - return true; - else return isXpac && r.UUID == this.xpac.UUID; + public boolean validForMine(Resource r, boolean isXpac) { + if (r == null) + return false; + if (this.resources.containsKey(r.UUID)) + return true; + else + return isXpac && r.UUID == this.xpac.UUID; } - - + //Name Xpac Resources //Lumber Camp Wormwood Gold, Lumber, Oak, Bronzewood, Mandrake diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index 794ae48e..f3091d86 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -79,6 +79,7 @@ public class Mob extends AbstractIntelligenceAgent { public ArrayList patrolPoints; public int lastPatrolPointIndex = 0; public long stopPatrolTime = 0; + public City guardedCity; protected int dbID; //the database ID protected int loadID; protected boolean isMob; @@ -100,7 +101,6 @@ public class Mob extends AbstractIntelligenceAgent { private DeferredPowerJob weaponPower; private DateTime upgradeDateTime = null; private boolean lootSync = false; - public City guardedCity; /** * No Id Constructor @@ -374,7 +374,7 @@ public class Mob extends AbstractIntelligenceAgent { writer.putFloat(1.0f); } - writer.putVector3f(mob.getLoc()); + writer.putVector3f(mob.getLoc()); //Rotation float radians = (float) Math.acos(mob.getRot().y) * 2; @@ -807,12 +807,12 @@ public class Mob extends AbstractIntelligenceAgent { guardCaptain.siegeMinionMap.put(mob, slot); mob.deathTime = System.currentTimeMillis(); mob.npcOwner = guardCaptain; - mob.spawnTime = (int)(-2.500 * guardCaptain.building.getRank() + 22.5) * 60; + mob.spawnTime = (int) (-2.500 * guardCaptain.building.getRank() + 22.5) * 60; mob.BehaviourType = Enum.MobBehaviourType.GuardMinion; mob.guardedCity = guardCaptain.guardedCity; mob.parentZone = parent; parent.zoneMobSet.add(mob); - MovementManager.translocate(mob,guardCaptain.bindLoc,guardCaptain.region); + MovementManager.translocate(mob, guardCaptain.bindLoc, guardCaptain.region); mob.bindLoc = guardCaptain.bindLoc; return mob; } @@ -1309,7 +1309,7 @@ public class Mob extends AbstractIntelligenceAgent { this.playerAgroMap.clear(); this.timeToSpawnSiege = System.currentTimeMillis() + 60 * 15 * 1000; - if(this.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardMinion.ordinal()) { + if (this.BehaviourType.ordinal() == Enum.MobBehaviourType.GuardMinion.ordinal()) { this.spawnTime = (int) (-2.500 * ((Mob) this.npcOwner).building.getRank() + 22.5) * 60; } if (this.isPet()) { @@ -1397,12 +1397,12 @@ public class Mob extends AbstractIntelligenceAgent { NPCManager.applyRuneSetEffects(this); this.recalculateStats(); this.setHealth(this.healthMax); - if(this.building == null && this.npcOwner != null && ((Mob)this.npcOwner).BehaviourType.ordinal() == MobBehaviourType.GuardCaptain.ordinal()){ - this.building = ((Mob)this.npcOwner).building; - } else if(this.building != null){ + if (this.building == null && this.npcOwner != null && ((Mob) this.npcOwner).BehaviourType.ordinal() == MobBehaviourType.GuardCaptain.ordinal()) { + this.building = ((Mob) this.npcOwner).building; + } else if (this.building != null) { this.region = BuildingManager.GetRegion(this.building, bindLoc.x, bindLoc.y, bindLoc.z); } - MovementManager.translocate(this,this.bindLoc, this.region); + MovementManager.translocate(this, this.bindLoc, this.region); if (!this.isSiege && !this.isPlayerGuard && contract == null) loadInventory(); @@ -1967,7 +1967,7 @@ public class Mob extends AbstractIntelligenceAgent { Bounds mobBounds = Bounds.borrow(); mobBounds.setBounds(this.getLoc()); this.setBounds(mobBounds); - if(this.contract != null && this.contract.getContractID() == 910){ + if (this.contract != null && this.contract.getContractID() == 910) { this.isPlayerGuard = true; this.BehaviourType = MobBehaviourType.GuardCaptain; this.spawnTime = 900; @@ -1988,8 +1988,8 @@ public class Mob extends AbstractIntelligenceAgent { Vector3fImmutable newPatrolPoint = Vector3fImmutable.getRandomPointInCircle(this.getBindLoc(), patrolRadius); this.patrolPoints.add(newPatrolPoint); - if(i == 1) - MovementManager.translocate(this,newPatrolPoint,null); + if (i == 1) + MovementManager.translocate(this, newPatrolPoint, null); } } if (this.BehaviourType == null) @@ -1999,8 +1999,7 @@ public class Mob extends AbstractIntelligenceAgent { if (NPC.ISWallArcher(this.getContract())) { this.BehaviourType = MobBehaviourType.GuardWallArcher; this.spawnTime = 450; - } - else { + } else { this.BehaviourType = MobBehaviourType.GuardCaptain; this.spawnTime = 900; this.guardedCity = ZoneManager.getCityAtLocation(this.bindLoc); diff --git a/src/engine/objects/MobBase.java b/src/engine/objects/MobBase.java index 67df8821..1c8fa548 100644 --- a/src/engine/objects/MobBase.java +++ b/src/engine/objects/MobBase.java @@ -22,285 +22,282 @@ import java.util.HashMap; public class MobBase extends AbstractGameObject { - private final int loadID; - private final String firstName; - private final byte level; - private float healthMax; - private int attackRating; - private int defenseRating; - private float damageMin; - private float damageMax; - private float hitBoxRadius; - private final float scale; - private EnumBitSet flags; - private int mask; - private int goldMod; - private int seeInvis; - private int spawnTime = 0; - private int defense = 0; - private int atr = 0; - private float minDmg = 0; - private float maxDmg = 0; - private float attackRange; - private boolean isNecroPet = false; - private MobBaseStats mobBaseStats; + private final int loadID; + private final String firstName; + private final byte level; + private final float scale; + public int bootySet; + public Enum.MobBehaviourType fsm; + public EnumBitSet notEnemy; + public EnumBitSet enemy; + private float healthMax; + private int attackRating; + private int defenseRating; + private float damageMin; + private float damageMax; + private float hitBoxRadius; + private EnumBitSet flags; + private int mask; + private int goldMod; + private int seeInvis; + private int spawnTime = 0; + private int defense = 0; + private int atr = 0; + private float minDmg = 0; + private float maxDmg = 0; + private float attackRange; + private boolean isNecroPet = false; + private MobBaseStats mobBaseStats; + private float walk = 0; + private float run = 0; + private float walkCombat = 0; + private float runCombat = 0; + + /** + * ResultSet Constructor + */ + public MobBase(ResultSet rs) throws SQLException { + super(rs, rs.getInt("ID")); + + this.loadID = rs.getInt("loadID"); + + this.firstName = rs.getString("name"); + this.level = rs.getByte("level"); + + this.goldMod = rs.getInt("goldMod"); + this.spawnTime = rs.getInt("spawnTime"); + + this.healthMax = rs.getInt("health"); + this.damageMin = rs.getFloat("minDmg"); + this.damageMax = rs.getFloat("maxDmg"); + + this.attackRating = rs.getInt("atr"); + this.defenseRating = rs.getInt("defense"); + this.attackRange = rs.getFloat("attackRange"); + this.bootySet = rs.getInt("bootySet"); + + this.fsm = Enum.MobBehaviourType.valueOf(rs.getString("fsm")); + + this.flags = EnumBitSet.asEnumBitSet(rs.getLong("flags"), Enum.MobFlagType.class); + this.notEnemy = EnumBitSet.asEnumBitSet(rs.getLong("notEnemy"), Enum.MonsterType.class); + this.enemy = EnumBitSet.asEnumBitSet(rs.getLong("enemy"), Enum.MonsterType.class); + + this.seeInvis = rs.getInt("seeInvis"); + this.scale = rs.getFloat("scale"); + this.hitBoxRadius = 5f; + this.mask = 0; + + if (this.getObjectUUID() == 12021 || this.getObjectUUID() == 12022) + this.isNecroPet = true; + + if (Enum.MobFlagType.HUMANOID.elementOf(this.flags)) + this.mask += MBServerStatics.MASK_HUMANOID; + + if (Enum.MobFlagType.UNDEAD.elementOf(this.flags)) + this.mask += MBServerStatics.MASK_UNDEAD; + + if (Enum.MobFlagType.BEAST.elementOf(this.flags)) + this.mask += MBServerStatics.MASK_BEAST; + + if (Enum.MobFlagType.DRAGON.elementOf(this.flags)) + this.mask += MBServerStatics.MASK_DRAGON; + + if (Enum.MobFlagType.RAT.elementOf(this.flags)) + this.mask += MBServerStatics.MASK_RAT; + + this.mobBaseStats = DbManager.MobBaseQueries.LOAD_STATS(this.loadID); + DbManager.MobBaseQueries.LOAD_ALL_MOBBASE_SPEEDS(this); + + } + + public static HashMap loadEquipmentSet(int equipmentSetID) { + + ArrayList equipList; + HashMap equip = new HashMap<>(); + + if (equipmentSetID == 0) + return equip; + + equipList = NPCManager._bootySetMap.get(equipmentSetID); + + if (equipList == null) + return equip; + + for (BootySetEntry equipmentSetEntry : equipList) { + + MobEquipment mobEquipment = new MobEquipment(equipmentSetEntry.itemBase, equipmentSetEntry.dropChance); + ItemBase itemBase = mobEquipment.getItemBase(); + + if (itemBase != null) { + if (itemBase.getType().equals(Enum.ItemType.WEAPON)) + if (mobEquipment.getSlot() == 1 && itemBase.getEquipFlag() == 2) + mobEquipment.setSlot(2); + + equip.put(mobEquipment.getSlot(), mobEquipment); + } + } + + return equip; + } + + public static MobBase getMobBase(int id) { + return DbManager.MobBaseQueries.GET_MOBBASE(id); + } + + public static int GetClassType(int mobbaseID) { + + switch (mobbaseID) { + case 17235: + case 17233: + case 17256: + case 17259: + case 17260: + case 17261: + return 2518; + case 17258: + case 17257: + case 17237: + case 17234: + return 2521; + default: + return 2518; + } + } - private float walk = 0; - private float run = 0; - private float walkCombat = 0; - private float runCombat = 0; - public int bootySet; - public Enum.MobBehaviourType fsm; + public void updateSpeeds(float walk, float walkCombat, float run, float runCombat) { + this.walk = walk; + this.walkCombat = walkCombat; + this.run = run; + this.runCombat = runCombat; - public EnumBitSet notEnemy; - public EnumBitSet enemy; - - /** - * ResultSet Constructor - */ - public MobBase(ResultSet rs) throws SQLException { - super(rs, rs.getInt("ID")); + } - this.loadID = rs.getInt("loadID"); - - this.firstName = rs.getString("name"); - this.level = rs.getByte("level"); - - this.goldMod = rs.getInt("goldMod"); - this.spawnTime = rs.getInt("spawnTime"); + /* + * Getters + */ + public String getFirstName() { + return this.firstName; + } + + public int getLoadID() { + return this.loadID; + } + + public int getLevel() { + return this.level; + } - this.healthMax = rs.getInt("health"); - this.damageMin = rs.getFloat("minDmg"); - this.damageMax = rs.getFloat("maxDmg"); - - this.attackRating = rs.getInt("atr"); - this.defenseRating = rs.getInt("defense"); - this.attackRange = rs.getFloat("attackRange"); - this.bootySet = rs.getInt("bootySet"); - - this.fsm = Enum.MobBehaviourType.valueOf(rs.getString("fsm")); - - this.flags = EnumBitSet.asEnumBitSet(rs.getLong("flags"), Enum.MobFlagType.class); - this.notEnemy = EnumBitSet.asEnumBitSet(rs.getLong("notEnemy"), Enum.MonsterType.class); - this.enemy = EnumBitSet.asEnumBitSet(rs.getLong("enemy"), Enum.MonsterType.class); - - this.seeInvis = rs.getInt("seeInvis"); - this.scale = rs.getFloat("scale"); - this.hitBoxRadius = 5f; - this.mask = 0; - - if (this.getObjectUUID() == 12021 || this.getObjectUUID() == 12022) - this.isNecroPet = true; - - if (Enum.MobFlagType.HUMANOID.elementOf(this.flags)) - this.mask += MBServerStatics.MASK_HUMANOID; - - if (Enum.MobFlagType.UNDEAD.elementOf(this.flags)) - this.mask += MBServerStatics.MASK_UNDEAD; - - if (Enum.MobFlagType.BEAST.elementOf(this.flags)) - this.mask += MBServerStatics.MASK_BEAST; - - if (Enum.MobFlagType.DRAGON.elementOf(this.flags)) - this.mask += MBServerStatics.MASK_DRAGON; - - if (Enum.MobFlagType.RAT.elementOf(this.flags)) - this.mask += MBServerStatics.MASK_RAT; - - this.mobBaseStats = DbManager.MobBaseQueries.LOAD_STATS(this.loadID); - DbManager.MobBaseQueries.LOAD_ALL_MOBBASE_SPEEDS(this); - - } - - public static HashMap loadEquipmentSet(int equipmentSetID){ - - ArrayList equipList; - HashMap equip = new HashMap<>(); - - if (equipmentSetID == 0) - return equip; - - equipList = NPCManager._bootySetMap.get(equipmentSetID); - - if (equipList == null) - return equip; - - for (BootySetEntry equipmentSetEntry : equipList) { - - MobEquipment mobEquipment = new MobEquipment(equipmentSetEntry.itemBase, equipmentSetEntry.dropChance); - ItemBase itemBase = mobEquipment.getItemBase(); - - if (itemBase != null) { - if (itemBase.getType().equals(Enum.ItemType.WEAPON)) - if (mobEquipment.getSlot() == 1 && itemBase.getEquipFlag() == 2) - mobEquipment.setSlot(2); - - equip.put(mobEquipment.getSlot(), mobEquipment); - } - } - - return equip; - } - - public void updateSpeeds(float walk, float walkCombat,float run, float runCombat){ - this.walk = walk; - this.walkCombat = walkCombat; - this.run = run; - this.runCombat = runCombat; - - } - - /* - * Getters - */ - public String getFirstName() { - return this.firstName; - } - - public int getLoadID() { - return this.loadID; - } - - public int getLevel() { - return this.level; - } - - public float getHealthMax() { - return this.healthMax; - } - - public float getDamageMin() { - return this.damageMin; - } - - public float getDamageMax() { - return this.damageMax; - } - - public int getAttackRating() { - return this.attackRating; - } - - public int getDefenseRating() { - return this.defenseRating; - } - - - public EnumBitSet getFlags() { - return this.flags; - } - - public float getScale() { - return this.scale; - } - - public int getTypeMasks() { - return this.mask; - } - - public int getSeeInvis() { - return this.seeInvis; - } - - public int getSpawnTime() { - return this.spawnTime; - } - - public static MobBase getMobBase(int id) { - return DbManager.MobBaseQueries.GET_MOBBASE(id); - } - - @Override - public void updateDatabase() { - // TODO Create update logic. - } - - public float getHitBoxRadius() { - if (this.hitBoxRadius < 0f) { - return 0f; - } else { - return this.hitBoxRadius; - } - } - - public MobBaseStats getMobBaseStats() { - return mobBaseStats; - } - - public float getMaxDmg() { - return maxDmg; - } - - public float getMinDmg() { - return minDmg; - } - - public int getAtr() { - return atr; - } - - public void setAtr(int atr) { - this.atr = atr; - } - - public int getDefense() { - return defense; - } - - public void setDefense(int defense) { - this.defense = defense; - } - - public float getAttackRange() { - return attackRange; - } - - public boolean isNecroPet() { - return isNecroPet; - } - - public static int GetClassType(int mobbaseID){ - - switch (mobbaseID){ - case 17235: - case 17233: - case 17256: - case 17259: - case 17260: - case 17261: - return 2518; - case 17258: - case 17257: - case 17237: - case 17234: - return 2521; - default: - return 2518; - } - } - - public float getWalk() { - return walk; - } - - public void setWalk(float walk) { - this.walk = walk; - } - - public float getRun() { - return run; - } - - public void setRun(float run) { - this.run = run; - } - - public float getWalkCombat() { - return walkCombat; - } - - public float getRunCombat() { - return runCombat; - } + public float getHealthMax() { + return this.healthMax; + } + + public float getDamageMin() { + return this.damageMin; + } + + public float getDamageMax() { + return this.damageMax; + } + + public int getAttackRating() { + return this.attackRating; + } + + public int getDefenseRating() { + return this.defenseRating; + } + + public EnumBitSet getFlags() { + return this.flags; + } + + public float getScale() { + return this.scale; + } + + public int getTypeMasks() { + return this.mask; + } + + public int getSeeInvis() { + return this.seeInvis; + } + + public int getSpawnTime() { + return this.spawnTime; + } + + @Override + public void updateDatabase() { + // TODO Create update logic. + } + + public float getHitBoxRadius() { + if (this.hitBoxRadius < 0f) { + return 0f; + } else { + return this.hitBoxRadius; + } + } + + public MobBaseStats getMobBaseStats() { + return mobBaseStats; + } + + public float getMaxDmg() { + return maxDmg; + } + + public float getMinDmg() { + return minDmg; + } + + public int getAtr() { + return atr; + } + + public void setAtr(int atr) { + this.atr = atr; + } + + public int getDefense() { + return defense; + } + + public void setDefense(int defense) { + this.defense = defense; + } + + public float getAttackRange() { + return attackRange; + } + + public boolean isNecroPet() { + return isNecroPet; + } + + public float getWalk() { + return walk; + } + + public void setWalk(float walk) { + this.walk = walk; + } + + public float getRun() { + return run; + } + + public void setRun(float run) { + this.run = run; + } + + public float getWalkCombat() { + return walkCombat; + } + + public float getRunCombat() { + return runCombat; + } } diff --git a/src/engine/objects/MobBaseEffects.java b/src/engine/objects/MobBaseEffects.java index d8c08172..4f938ef2 100644 --- a/src/engine/objects/MobBaseEffects.java +++ b/src/engine/objects/MobBaseEffects.java @@ -13,54 +13,50 @@ import java.sql.ResultSet; import java.sql.SQLException; -public class MobBaseEffects { +public class MobBaseEffects { - private int mobBaseID; - private int token; - private int rank; - private int reqLvl; - + private int mobBaseID; + private int token; + private int rank; + private int reqLvl; - /** - * ResultSet Constructor - */ - public MobBaseEffects(ResultSet rs) throws SQLException { - this.token = rs.getInt("token"); - this.rank = rs.getInt("rank"); - this.reqLvl = rs.getInt("reqLvl"); - } + /** + * ResultSet Constructor + */ + public MobBaseEffects(ResultSet rs) throws SQLException { + this.token = rs.getInt("token"); + this.rank = rs.getInt("rank"); + this.reqLvl = rs.getInt("reqLvl"); + } - /** - * @return the mobBaseID - */ - public int getMobBaseID() { - return mobBaseID; - } + /** + * @return the mobBaseID + */ + public int getMobBaseID() { + return mobBaseID; + } + public void setMobBaseID(int mobBaseID) { + this.mobBaseID = mobBaseID; + } - public void setMobBaseID(int mobBaseID) { - this.mobBaseID = mobBaseID; - } + public int getToken() { + return token; + } - public int getToken() { - return token; - } + public int getRank() { + return rank; + } - public int getRank() { - return rank; - } - - - - public int getReqLvl() { - return reqLvl; - } + public int getReqLvl() { + return reqLvl; + } } diff --git a/src/engine/objects/MobBaseStats.java b/src/engine/objects/MobBaseStats.java index 95ba2f7c..38a09379 100644 --- a/src/engine/objects/MobBaseStats.java +++ b/src/engine/objects/MobBaseStats.java @@ -12,68 +12,65 @@ package engine.objects; import java.sql.ResultSet; import java.sql.SQLException; -public class MobBaseStats { - - private final int baseStr; - private final int baseInt; - private final int baseCon; - private final int baseSpi; - private final int baseDex; - public static MobBaseStats mbs = null; - - - /** - * ResultSet Constructor - */ - public MobBaseStats(ResultSet rs) throws SQLException { - this.baseStr = rs.getInt("Strength"); - this.baseInt = rs.getInt("Intelligence"); - this.baseCon = rs.getInt("Constitution"); - this.baseSpi = rs.getInt("Spirit"); - this.baseDex = rs.getInt("Dexterity"); - } - - /** - * Generic Constructor - */ - - public MobBaseStats() { - this.baseStr = 0; - this.baseInt = 0; - this.baseCon = 0; - this.baseSpi = 0; - this.baseDex = 0; - } - public int getBaseStr() { - return baseStr; - } - - - public int getBaseInt() { - return baseInt; - } - - - public int getBaseCon() { - return baseCon; - } - - - public int getBaseSpi() { - return baseSpi; - } - - - public int getBaseDex() { - return baseDex; - } - - public static MobBaseStats GetGenericStats(){ - if (mbs != null) - return mbs; +public class MobBaseStats { + + public static MobBaseStats mbs = null; + private final int baseStr; + private final int baseInt; + private final int baseCon; + private final int baseSpi; + private final int baseDex; + + + /** + * ResultSet Constructor + */ + public MobBaseStats(ResultSet rs) throws SQLException { + this.baseStr = rs.getInt("Strength"); + this.baseInt = rs.getInt("Intelligence"); + this.baseCon = rs.getInt("Constitution"); + this.baseSpi = rs.getInt("Spirit"); + this.baseDex = rs.getInt("Dexterity"); + } + + /** + * Generic Constructor + */ + + public MobBaseStats() { + this.baseStr = 0; + this.baseInt = 0; + this.baseCon = 0; + this.baseSpi = 0; + this.baseDex = 0; + } + + public static MobBaseStats GetGenericStats() { + if (mbs != null) + return mbs; mbs = new MobBaseStats(); - return mbs; - } + return mbs; + } + + public int getBaseStr() { + return baseStr; + } + + public int getBaseInt() { + return baseInt; + } + + public int getBaseCon() { + return baseCon; + } + + public int getBaseSpi() { + return baseSpi; + } + + public int getBaseDex() { + return baseDex; + } } diff --git a/src/engine/objects/MobEquipment.java b/src/engine/objects/MobEquipment.java index 3eecd5b8..d15b6274 100644 --- a/src/engine/objects/MobEquipment.java +++ b/src/engine/objects/MobEquipment.java @@ -22,346 +22,340 @@ import java.util.concurrent.atomic.AtomicInteger; public class MobEquipment extends AbstractGameObject { - private static AtomicInteger equipCounter = new AtomicInteger(0); - private final ItemBase itemBase; - private int slot; - private int parentID; - - //effects - private boolean enchanted; - private boolean isID = false; - private AbstractPowerAction prefix; - private AbstractPowerAction suffix; - private int pValue; - private int sValue; - private int magicValue; - - private float dropChance = 0; - - /** - * No Id Constructor - */ - public MobEquipment(ItemBase itemBase, int slot, int parentID) { - super(MobEquipment.getNewID()); - this.itemBase = itemBase; - this.slot = slot; - this.parentID = parentID; - this.enchanted = false; - this.prefix = null; - this.suffix = null; - this.pValue = 0; - this.sValue = 0; - setMagicValue(); - } - - public MobEquipment(ItemBase itemBase, int slot, int parentID, String pIDString, String sIDString, int pValue, int sValue) { - super(MobEquipment.getNewID()); - this.itemBase = itemBase; - this.slot = slot; - this.parentID = parentID; - - //add effects - this.prefix = PowersManager.getPowerActionByIDString(pIDString); - this.suffix = PowersManager.getPowerActionByIDString(sIDString); - - this.pValue = pValue; - this.sValue = sValue; - this.enchanted = this.prefix == null || this.suffix == null; - setMagicValue(); - } - - /** - * ResultSet Constructor - */ - public MobEquipment(ResultSet rs) throws SQLException { - super(MobEquipment.getNewID()); - int itemBaseID = rs.getInt("ItemID"); - this.itemBase = ItemBase.getItemBase(itemBaseID); - this.slot = rs.getInt("slot"); - this.parentID = rs.getInt("mobID"); - setMagicValue(); - } - - - public MobEquipment(int itemBaseID,float dropChance) { - super(MobEquipment.getNewID()); - this.itemBase = ItemBase.getItemBase(itemBaseID); - - if (this.itemBase != null) - this.slot = this.itemBase.getValidSlot(); - else{ - Logger.error("Failed to find Itembase for ID : " + itemBaseID); - this.slot = 0; - } - - this.dropChance = dropChance; - - this.parentID = 0; - setMagicValue(); - } - - public ItemBase getItemBase() { - return itemBase; - } - - public int getSlot() { - return this.slot; - } - - public void setSlot(int value) { - this.slot = value; - } - - public static int getNewID() { - return MobEquipment.equipCounter.incrementAndGet(); - } - - public static void serializeForVendor(MobEquipment mobEquipment,ByteBufferWriter writer, float percent) throws SerializationException { - _serializeForClientMsg(mobEquipment,writer, false); - int baseValue = mobEquipment.itemBase.getBaseValue() + mobEquipment.itemBase.getMagicValue(); - writer.putInt(mobEquipment.magicValue); - writer.putInt(mobEquipment.magicValue); - } - - - public static void serializeForClientMsg(MobEquipment mobEquipment,ByteBufferWriter writer) throws SerializationException { - _serializeForClientMsg(mobEquipment,writer, true); - } - - public static void _serializeForClientMsg(MobEquipment mobEquipment,ByteBufferWriter writer, boolean useSlot) throws SerializationException { - - if (useSlot) - writer.putInt(mobEquipment.slot); - writer.putInt(0); // Pad - writer.putInt(mobEquipment.itemBase.getUUID()); - writer.putInt(mobEquipment.getObjectType().ordinal()); - writer.putInt(mobEquipment.getObjectUUID()); - - // Unknown statics - for (int i = 0; i < 3; i++) { - writer.putInt(0); // Pad - } - for (int i = 0; i < 4; i++) { - writer.putInt(0x3F800000); // Static - } - for (int i = 0; i < 5; i++) { - writer.putInt(0); // Pad - } - for (int i = 0; i < 2; i++) { - writer.putInt(0xFFFFFFFF); // Static - } - - writer.putInt(0); - - writer.put((byte) 1); // End Datablock byte - writer.putInt(0); // Unknown. pad? - writer.put((byte) 1); // End Datablock byte - - writer.putFloat(mobEquipment.itemBase.getDurability()); - writer.putFloat(mobEquipment.itemBase.getDurability()); - - writer.put((byte) 1); // End Datablock byte - - writer.putInt(0); // Pad - writer.putInt(0); // Pad - - writer.putInt(mobEquipment.itemBase.getBaseValue()); - writer.putInt(mobEquipment.magicValue); - - serializeEffects(mobEquipment,writer); - - writer.putInt(0x00000000); - - //name color, think mobEquipment is where mobEquipment goes - if (mobEquipment.enchanted) - if (mobEquipment.isID) - writer.putInt(36); - else - writer.putInt(40); - else - writer.putInt(4); - - writer.putInt(0); - writer.putInt(0); // Pad - writer.putInt(1); - writer.putShort((short) 0); - writer.put((byte) 0); - } - - public final void setMagicValue() { - float value = 1; - if (itemBase != null) - value = itemBase.getBaseValue(); - if (this.prefix != null) { - if (this.prefix.getEffectsBase() != null) - value += this.prefix.getEffectsBase().getValue(); - if (this.prefix.getEffectsBase2() != null) - value += this.prefix.getEffectsBase2().getValue(); - } - if (this.suffix != null) { - if (this.suffix.getEffectsBase() != null) - value += this.suffix.getEffectsBase().getValue(); - if (this.suffix.getEffectsBase2() != null) - value += this.suffix.getEffectsBase2().getValue(); - } - - if (itemBase != null) - - for (Integer token : itemBase.getBakedInStats().keySet()) { - - EffectsBase effect = PowersManager.getEffectByToken(token); - - AbstractPowerAction apa = PowersManager.getPowerActionByIDString(effect.getIDString()); - if (apa.getEffectsBase() != null) - if (apa.getEffectsBase().getValue() > 0){ - //System.out.println(apa.getEffectsBase().getValue()); - value += apa.getEffectsBase().getValue(); - } - - - if (apa.getEffectsBase2() != null) - value += apa.getEffectsBase2().getValue(); - } - - this.magicValue = (int) value; - } - - public int getMagicValue() { - - if (!this.isID) { + private static AtomicInteger equipCounter = new AtomicInteger(0); + private final ItemBase itemBase; + private int slot; + private int parentID; + + //effects + private boolean enchanted; + private boolean isID = false; + private AbstractPowerAction prefix; + private AbstractPowerAction suffix; + private int pValue; + private int sValue; + private int magicValue; + + private float dropChance = 0; + + /** + * No Id Constructor + */ + public MobEquipment(ItemBase itemBase, int slot, int parentID) { + super(MobEquipment.getNewID()); + this.itemBase = itemBase; + this.slot = slot; + this.parentID = parentID; + this.enchanted = false; + this.prefix = null; + this.suffix = null; + this.pValue = 0; + this.sValue = 0; + setMagicValue(); + } + + public MobEquipment(ItemBase itemBase, int slot, int parentID, String pIDString, String sIDString, int pValue, int sValue) { + super(MobEquipment.getNewID()); + this.itemBase = itemBase; + this.slot = slot; + this.parentID = parentID; + + //add effects + this.prefix = PowersManager.getPowerActionByIDString(pIDString); + this.suffix = PowersManager.getPowerActionByIDString(sIDString); + + this.pValue = pValue; + this.sValue = sValue; + this.enchanted = this.prefix == null || this.suffix == null; + setMagicValue(); + } + + /** + * ResultSet Constructor + */ + public MobEquipment(ResultSet rs) throws SQLException { + super(MobEquipment.getNewID()); + int itemBaseID = rs.getInt("ItemID"); + this.itemBase = ItemBase.getItemBase(itemBaseID); + this.slot = rs.getInt("slot"); + this.parentID = rs.getInt("mobID"); + setMagicValue(); + } + + + public MobEquipment(int itemBaseID, float dropChance) { + super(MobEquipment.getNewID()); + this.itemBase = ItemBase.getItemBase(itemBaseID); + + if (this.itemBase != null) + this.slot = this.itemBase.getValidSlot(); + else { + Logger.error("Failed to find Itembase for ID : " + itemBaseID); + this.slot = 0; + } + + this.dropChance = dropChance; + + this.parentID = 0; + setMagicValue(); + } + + public static int getNewID() { + return MobEquipment.equipCounter.incrementAndGet(); + } + + public static void serializeForVendor(MobEquipment mobEquipment, ByteBufferWriter writer, float percent) throws SerializationException { + _serializeForClientMsg(mobEquipment, writer, false); + int baseValue = mobEquipment.itemBase.getBaseValue() + mobEquipment.itemBase.getMagicValue(); + writer.putInt(mobEquipment.magicValue); + writer.putInt(mobEquipment.magicValue); + } + + public static void serializeForClientMsg(MobEquipment mobEquipment, ByteBufferWriter writer) throws SerializationException { + _serializeForClientMsg(mobEquipment, writer, true); + } + + public static void _serializeForClientMsg(MobEquipment mobEquipment, ByteBufferWriter writer, boolean useSlot) throws SerializationException { + + if (useSlot) + writer.putInt(mobEquipment.slot); + writer.putInt(0); // Pad + writer.putInt(mobEquipment.itemBase.getUUID()); + writer.putInt(mobEquipment.getObjectType().ordinal()); + writer.putInt(mobEquipment.getObjectUUID()); + + // Unknown statics + for (int i = 0; i < 3; i++) { + writer.putInt(0); // Pad + } + for (int i = 0; i < 4; i++) { + writer.putInt(0x3F800000); // Static + } + for (int i = 0; i < 5; i++) { + writer.putInt(0); // Pad + } + for (int i = 0; i < 2; i++) { + writer.putInt(0xFFFFFFFF); // Static + } + + writer.putInt(0); + + writer.put((byte) 1); // End Datablock byte + writer.putInt(0); // Unknown. pad? + writer.put((byte) 1); // End Datablock byte + + writer.putFloat(mobEquipment.itemBase.getDurability()); + writer.putFloat(mobEquipment.itemBase.getDurability()); + + writer.put((byte) 1); // End Datablock byte + + writer.putInt(0); // Pad + writer.putInt(0); // Pad + + writer.putInt(mobEquipment.itemBase.getBaseValue()); + writer.putInt(mobEquipment.magicValue); + + serializeEffects(mobEquipment, writer); + + writer.putInt(0x00000000); + + //name color, think mobEquipment is where mobEquipment goes + if (mobEquipment.enchanted) + if (mobEquipment.isID) + writer.putInt(36); + else + writer.putInt(40); + else + writer.putInt(4); + + writer.putInt(0); + writer.putInt(0); // Pad + writer.putInt(1); + writer.putShort((short) 0); + writer.put((byte) 0); + } + + public static void serializeEffects(MobEquipment mobEquipment, ByteBufferWriter writer) { + + //skip sending effects if not IDed + if (!mobEquipment.isID) { + writer.putInt(0); + return; + } + + //handle effect count + int cnt = 0; + EffectsBase pre = null; + EffectsBase suf = null; + if (mobEquipment.prefix != null) { + pre = PowersManager.getEffectByIDString(mobEquipment.prefix.getIDString()); + if (pre != null) + cnt++; + } + if (mobEquipment.suffix != null) { + suf = PowersManager.getEffectByIDString(mobEquipment.suffix.getIDString()); + if (suf != null) + cnt++; + } + + writer.putInt(cnt); + + //serialize prefix + if (pre != null) + serializeEffect(mobEquipment, writer, pre, mobEquipment.pValue); + + //serialize suffix + if (suf != null) + serializeEffect(mobEquipment, writer, suf, mobEquipment.sValue); + } + + public static void serializeEffect(MobEquipment mobEquipment, ByteBufferWriter writer, EffectsBase eb, int rank) { + String name; + if (eb.isPrefix()) { + if (mobEquipment.itemBase == null) + name = eb.getName(); + else + name = eb.getName() + ' ' + mobEquipment.itemBase.getName(); + } else if (eb.isSuffix()) { + if (mobEquipment.itemBase == null) + name = eb.getName(); + else + name = mobEquipment.itemBase.getName() + ' ' + eb.getName(); + } else { + if (mobEquipment.itemBase == null) + name = ""; + else + name = mobEquipment.itemBase.getName(); + } + + writer.putInt(eb.getToken()); + writer.putInt(rank); + writer.putInt(1); + writer.put((byte) 1); + writer.putInt(mobEquipment.getObjectType().ordinal()); + writer.putInt(mobEquipment.getObjectUUID()); + writer.putString(name); + writer.putFloat(-1000f); + } + + public ItemBase getItemBase() { + return itemBase; + } + + public int getSlot() { + return this.slot; + } + + public void setSlot(int value) { + this.slot = value; + } + + public final void setMagicValue() { + float value = 1; + if (itemBase != null) + value = itemBase.getBaseValue(); + if (this.prefix != null) { + if (this.prefix.getEffectsBase() != null) + value += this.prefix.getEffectsBase().getValue(); + if (this.prefix.getEffectsBase2() != null) + value += this.prefix.getEffectsBase2().getValue(); + } + if (this.suffix != null) { + if (this.suffix.getEffectsBase() != null) + value += this.suffix.getEffectsBase().getValue(); + if (this.suffix.getEffectsBase2() != null) + value += this.suffix.getEffectsBase2().getValue(); + } + + if (itemBase != null) + + for (Integer token : itemBase.getBakedInStats().keySet()) { + + EffectsBase effect = PowersManager.getEffectByToken(token); + + AbstractPowerAction apa = PowersManager.getPowerActionByIDString(effect.getIDString()); + if (apa.getEffectsBase() != null) + if (apa.getEffectsBase().getValue() > 0) { + //System.out.println(apa.getEffectsBase().getValue()); + value += apa.getEffectsBase().getValue(); + } + + + if (apa.getEffectsBase2() != null) + value += apa.getEffectsBase2().getValue(); + } + + this.magicValue = (int) value; + } + + public int getMagicValue() { + + if (!this.isID) { return itemBase.getBaseValue(); } - return this.magicValue; - } - - - public static void serializeEffects(MobEquipment mobEquipment,ByteBufferWriter writer) { - - //skip sending effects if not IDed - if (!mobEquipment.isID) { - writer.putInt(0); - return; - } - - //handle effect count - int cnt = 0; - EffectsBase pre = null; - EffectsBase suf = null; - if (mobEquipment.prefix != null) { - pre = PowersManager.getEffectByIDString(mobEquipment.prefix.getIDString()); - if (pre != null) - cnt++; - } - if (mobEquipment.suffix != null) { - suf = PowersManager.getEffectByIDString(mobEquipment.suffix.getIDString()); - if (suf != null) - cnt++; - } - - writer.putInt(cnt); - - //serialize prefix - if (pre != null) - serializeEffect(mobEquipment,writer, pre, mobEquipment.pValue); - - //serialize suffix - if (suf != null) - serializeEffect(mobEquipment,writer, suf, mobEquipment.sValue); - } - - public static void serializeEffect(MobEquipment mobEquipment,ByteBufferWriter writer, EffectsBase eb, int rank) { - String name; - if (eb.isPrefix()) { - if (mobEquipment.itemBase == null) - name = eb.getName(); - else - name = eb.getName() + ' ' + mobEquipment.itemBase.getName(); - } - else if (eb.isSuffix()) { - if (mobEquipment.itemBase == null) - name = eb.getName(); - else - name = mobEquipment.itemBase.getName() + ' ' + eb.getName(); - } - else { - if (mobEquipment.itemBase == null) - name = ""; - else - name = mobEquipment.itemBase.getName(); - } - - writer.putInt(eb.getToken()); - writer.putInt(rank); - writer.putInt(1); - writer.put((byte) 1); - writer.putInt(mobEquipment.getObjectType().ordinal()); - writer.putInt(mobEquipment.getObjectUUID()); - writer.putString(name); - writer.putFloat(-1000f); - } - - public void setPrefix(String pIDString, int pValue) { - AbstractPowerAction apa = PowersManager.getPowerActionByIDString(pIDString); - if (apa != null) { - this.prefix = apa; - this.pValue = pValue; - } else - this.prefix = null; - - this.enchanted = this.prefix != null || this.suffix != null; - - setMagicValue(); - } - - public void setSuffix(String sIDString, int sValue) { - AbstractPowerAction apa = PowersManager.getPowerActionByIDString(sIDString); - if (apa != null) { - this.suffix = apa; - this.sValue = sValue; - } else - this.suffix = null; - - this.enchanted = this.prefix != null || this.suffix != null; - - setMagicValue(); - } - - public void setIsID(boolean value) { - this.isID = value; - } - - public boolean isID() { - return this.isID; - } - - public void transferEnchants(Item item) { - if (this.prefix != null) { - String IDString = this.prefix.getIDString(); - item.addPermanentEnchantment(IDString, this.pValue); - } - if (this.suffix != null) { - String IDString = this.suffix.getIDString(); - item.addPermanentEnchantment(IDString, this.sValue); - } - if (this.isID) - item.setIsID(true); - } - - /* - * Database - */ - @Override - public void updateDatabase() { - } - - - - - public float getDropChance() { - return dropChance; - } - - public void setDropChance(float dropChance) { - this.dropChance = dropChance; - } + return this.magicValue; + } + + public void setPrefix(String pIDString, int pValue) { + AbstractPowerAction apa = PowersManager.getPowerActionByIDString(pIDString); + if (apa != null) { + this.prefix = apa; + this.pValue = pValue; + } else + this.prefix = null; + + this.enchanted = this.prefix != null || this.suffix != null; + + setMagicValue(); + } + + public void setSuffix(String sIDString, int sValue) { + AbstractPowerAction apa = PowersManager.getPowerActionByIDString(sIDString); + if (apa != null) { + this.suffix = apa; + this.sValue = sValue; + } else + this.suffix = null; + + this.enchanted = this.prefix != null || this.suffix != null; + + setMagicValue(); + } + + public void setIsID(boolean value) { + this.isID = value; + } + + public boolean isID() { + return this.isID; + } + + public void transferEnchants(Item item) { + if (this.prefix != null) { + String IDString = this.prefix.getIDString(); + item.addPermanentEnchantment(IDString, this.pValue); + } + if (this.suffix != null) { + String IDString = this.suffix.getIDString(); + item.addPermanentEnchantment(IDString, this.sValue); + } + if (this.isID) + item.setIsID(true); + } + + /* + * Database + */ + @Override + public void updateDatabase() { + } + + + public float getDropChance() { + return dropChance; + } + + public void setDropChance(float dropChance) { + this.dropChance = dropChance; + } } diff --git a/src/engine/objects/MobLoot.java b/src/engine/objects/MobLoot.java index bfd3fa43..235eccd1 100644 --- a/src/engine/objects/MobLoot.java +++ b/src/engine/objects/MobLoot.java @@ -27,369 +27,370 @@ import java.util.concurrent.atomic.AtomicInteger; */ public final class MobLoot extends Item { - private static final AtomicInteger LastUsedId = new AtomicInteger(0); - - private boolean isDeleted = false; - private boolean noSteal; - private String prefix = ""; - private String suffix = ""; - - /** - * Create a new MobLoot. - * Do not use this to create Gold. - * - * @param mob Mob that owns this item - * @param ib ItemBase - */ - public MobLoot(AbstractCharacter mob, ItemBase ib, boolean noSteal) { - this(mob, ib, 0, noSteal); - } - - /** - * Create a new MobLoot item to hold Gold for the Mob. - * - * @param mob Mob that owns this item - * @param qtyOfGold Quantity of gold - */ - public MobLoot(AbstractCharacter mob, int qtyOfGold) { - this(mob, ItemBase.getGoldItemBase(), qtyOfGold, false); - } - - /** - * Create a new MobLoot. - * Primarily used for stackable items that have a quantity. - * - * @param mob Mob that owns this item - * @param ib ItemBase - * @param quantity Quantity of the item - */ - public MobLoot(AbstractCharacter mob, ItemBase ib, int quantity, boolean noSteal) { - super( ib, mob.getObjectUUID(), - OwnerType.Mob, (byte) 0, (byte) 0, (short) 0, - (short) 0, true, false, false, false, true, - false, (byte) 0, new ArrayList<>(), generateId()); - - if (quantity == 0 && ib.getType() == ItemType.RESOURCE) - quantity = 1; - - - if (quantity > 0) - this.setNumOfItems(quantity); - - this.noSteal = noSteal; - this.setIsID(this.getItemBase().isAutoID()); - - // Class is 'final'; passing 'this' should be okay at the end of the constructor - - DbManager.addToCache(this); - } - - /** - * Converts this MotLoot to a persistable Item. Used when a MotLoot is - * looted - * from a Mob to a Player. Do not call for a Gold item. - * - * @return An orphaned Item, ready to be moved to the Player's inventory. - */ - public synchronized Item promoteToItem(PlayerCharacter looter) { - - if (looter == null) - return null; - - if (isDeleted) - return null; - - if (this.getItemBase().getType().equals(ItemType.GOLD)) - return null; - - - Item item = (Item)this; - - item.setOwner(looter); - //item.setIsID(false); - - item.containerType = Enum.ItemContainerType.INVENTORY; - item.setValue(0); - item.setName(this.getCustomName()); - item.setIsID(this.isID()); - - if (this.getNumOfItems() > 1) - item.setNumOfItems(this.getNumOfItems()); - - try { - item = DbManager.ItemQueries.ADD_ITEM(item); - } catch (Exception e) { - Logger.error("e"); - return null; - } - - // for (String effectName : this.effectNames) - // item.addPermanentEnchantment(effectName, 0); - //transfer enchantments to item - if (this.prefix.length() != 0) - item.addPermanentEnchantment(this.prefix, 0); - if (this.suffix.length() != 0) - item.addPermanentEnchantment(this.suffix, 0); - - this.junk(); - return item; - } - - public synchronized Item promoteToItemForNPC(NPC looter) { - - if (looter == null) - return null; - - if (isDeleted) - return null; - - if (this.getItemBase().getType().equals(ItemType.GOLD)) - return null; - - Item item = this; - item.setOwner(looter); - item.containerType = Enum.ItemContainerType.INVENTORY; - item.setIsID(true); - - if (this.getNumOfItems() > 1) - item.setNumOfItems(this.getNumOfItems()); - - try { - item = DbManager.ItemQueries.ADD_ITEM(item); - } catch (Exception e) { - Logger.error(e); - return null; - } - item.containerType = Enum.ItemContainerType.INVENTORY; - - // for (String effectName : this.effectNames) - // item.addPermanentEnchantment(effectName, 0); - //transfer enchantments to item - try{ - for (String enchant:this.getEffectNames()){ - item.addPermanentEnchantment(enchant, 0); - } - }catch(Exception e){ - Logger.error(e.getMessage()); - } - - DbManager.NPCQueries.REMOVE_FROM_PRODUCTION_LIST(this.getObjectUUID(),looter.getObjectUUID()); - looter.removeItemFromForge(this); - this.junk(); - return item; - } - - public synchronized void recycle(NPC vendor){ - - //remove from production list for npc in db - - DbManager.NPCQueries.REMOVE_FROM_PRODUCTION_LIST(this.getObjectUUID(),vendor.getObjectUUID()); - this.removeFromCache(); - isDeleted = true; - } - - /** - * Junks the item and marks it as deleted - */ - @Override - protected synchronized void junk() { - this.removeFromCache(); - isDeleted = true; - } - - /** - * Get the MobLoot object from its Id number - * - * @param id Id Number - * @return MobLoot object - */ - public static MobLoot getFromCache(int id) { - return (MobLoot) DbManager.getFromCache(Enum.GameObjectType.MobLoot, id); - } - - /** - * Determines if this object has been marked as deleted. - * - * @return True if deleted. - */ - public boolean isDeleted() { - return this.isDeleted; - } - - public boolean noSteal() { - return this.noSteal; - } - - public void addPermanentEnchantment(String enchantID, int rank, int value, boolean prefix) { - AbstractPowerAction apa = PowersManager.getPowerActionByIDString(enchantID); - if (apa == null) - return; - apa.applyEffectForItem(this, rank); - - //limit to 2 effects - // if (this.effectNames.size() < 2) - // this.effectNames.add(enchantID); - if (prefix) - this.prefix = enchantID; - else - this.suffix = enchantID; - - this.getEffectNames().add(enchantID); - } - - /** - * Get the next available Id number. - * - * @return Id number - */ - private static int generateId() { - int id = LastUsedId.decrementAndGet(); - - //TODO Add a way to reclaim disposed IDs if this becomes a problem - if (id == (-10000)) - Logger.warn("Only 10,000 Id numbers remain useable. Server restart suggested."); - else if (id < Integer.MIN_VALUE + 1000) - Logger.warn("Only " + (Integer.MIN_VALUE + id) - + " Id numbers remain useable! Server restart suggested."); - else if (id == Integer.MIN_VALUE) - throw new UnsupportedOperationException("MobLoot has no remaining Id numbers! Restart server immediately!"); - else if ((id % 10000) == 0) - Logger.info( id + " of " + Integer.MIN_VALUE + " Id numbers consumed."); - - return id; - } - - /* ***** - * All of the following methods are overridden from - * the superclass and intentionally not implemented. - * ***** - */ - /** - * Not implemented - */ - @Override - @Deprecated - public void setOwnerID(int id) { - } - - /** - * Not implemented - */ - @Override - @Deprecated - public synchronized void decrementChargesRemaining() { - } - - /** - * Not implemented - */ - @Override - @Deprecated - protected boolean equipItem(NPC npc, byte slot) { - return false; - } - - /** - * Not implemented - */ - @Override - @Deprecated - protected boolean equipItem(PlayerCharacter pc, byte slot) { - return false; - } - - /** - * Not implemented - */ - @Override - @Deprecated - protected boolean moveItemToBank(NPC npc) { - return false; - } - - /** - * Not implemented - */ - @Override - @Deprecated - protected boolean moveItemToBank(PlayerCharacter pc) { - return false; - } - - /** - * Not implemented - */ - @Override - @Deprecated - protected boolean moveItemToInventory(Corpse corpse) { - return false; - } - - /** - * Not implemented - */ - @Override - @Deprecated - protected boolean moveItemToInventory(NPC npc) { - return false; - } - - /** - * Not implemented - */ - @Override - @Deprecated - protected boolean moveItemToInventory(PlayerCharacter pc) { - return false; - } - - /** - * Not implemented - */ - @Override - @Deprecated - protected boolean moveItemToVault(Account a) { - return false; - } - - /** - * Not implemented - */ - @Override - @Deprecated - public void setLastOwner(AbstractWorldObject value) { - } - - /** - * Not implemented - */ - @Override - @Deprecated - public void updateDatabase() { - } - - /** - * Not implemented - */ - @Override - @Deprecated - protected void validateItemContainer() { - } - - public String getPrefix() { - return prefix; - } - - public void setPrefix(String prefix) { - this.prefix = prefix; - } - - public String getSuffix() { - return suffix; - } - - public void setSuffix(String suffix) { - this.suffix = suffix; - } + private static final AtomicInteger LastUsedId = new AtomicInteger(0); + + private boolean isDeleted = false; + private boolean noSteal; + private String prefix = ""; + private String suffix = ""; + + /** + * Create a new MobLoot. + * Do not use this to create Gold. + * + * @param mob Mob that owns this item + * @param ib ItemBase + */ + public MobLoot(AbstractCharacter mob, ItemBase ib, boolean noSteal) { + this(mob, ib, 0, noSteal); + } + + /** + * Create a new MobLoot item to hold Gold for the Mob. + * + * @param mob Mob that owns this item + * @param qtyOfGold Quantity of gold + */ + public MobLoot(AbstractCharacter mob, int qtyOfGold) { + this(mob, ItemBase.getGoldItemBase(), qtyOfGold, false); + } + + /** + * Create a new MobLoot. + * Primarily used for stackable items that have a quantity. + * + * @param mob Mob that owns this item + * @param ib ItemBase + * @param quantity Quantity of the item + */ + public MobLoot(AbstractCharacter mob, ItemBase ib, int quantity, boolean noSteal) { + super(ib, mob.getObjectUUID(), + OwnerType.Mob, (byte) 0, (byte) 0, (short) 0, + (short) 0, true, false, false, false, true, + false, (byte) 0, new ArrayList<>(), generateId()); + + if (quantity == 0 && ib.getType() == ItemType.RESOURCE) + quantity = 1; + + + if (quantity > 0) + this.setNumOfItems(quantity); + + this.noSteal = noSteal; + this.setIsID(this.getItemBase().isAutoID()); + + // Class is 'final'; passing 'this' should be okay at the end of the constructor + + DbManager.addToCache(this); + } + + /** + * Get the MobLoot object from its Id number + * + * @param id Id Number + * @return MobLoot object + */ + public static MobLoot getFromCache(int id) { + return (MobLoot) DbManager.getFromCache(Enum.GameObjectType.MobLoot, id); + } + + /** + * Get the next available Id number. + * + * @return Id number + */ + private static int generateId() { + int id = LastUsedId.decrementAndGet(); + + //TODO Add a way to reclaim disposed IDs if this becomes a problem + if (id == (-10000)) + Logger.warn("Only 10,000 Id numbers remain useable. Server restart suggested."); + else if (id < Integer.MIN_VALUE + 1000) + Logger.warn("Only " + (Integer.MIN_VALUE + id) + + " Id numbers remain useable! Server restart suggested."); + else if (id == Integer.MIN_VALUE) + throw new UnsupportedOperationException("MobLoot has no remaining Id numbers! Restart server immediately!"); + else if ((id % 10000) == 0) + Logger.info(id + " of " + Integer.MIN_VALUE + " Id numbers consumed."); + + return id; + } + + /** + * Converts this MotLoot to a persistable Item. Used when a MotLoot is + * looted + * from a Mob to a Player. Do not call for a Gold item. + * + * @return An orphaned Item, ready to be moved to the Player's inventory. + */ + public synchronized Item promoteToItem(PlayerCharacter looter) { + + if (looter == null) + return null; + + if (isDeleted) + return null; + + if (this.getItemBase().getType().equals(ItemType.GOLD)) + return null; + + + Item item = (Item) this; + + item.setOwner(looter); + //item.setIsID(false); + + item.containerType = Enum.ItemContainerType.INVENTORY; + item.setValue(0); + item.setName(this.getCustomName()); + item.setIsID(this.isID()); + + if (this.getNumOfItems() > 1) + item.setNumOfItems(this.getNumOfItems()); + + try { + item = DbManager.ItemQueries.ADD_ITEM(item); + } catch (Exception e) { + Logger.error("e"); + return null; + } + + // for (String effectName : this.effectNames) + // item.addPermanentEnchantment(effectName, 0); + //transfer enchantments to item + if (this.prefix.length() != 0) + item.addPermanentEnchantment(this.prefix, 0); + if (this.suffix.length() != 0) + item.addPermanentEnchantment(this.suffix, 0); + + this.junk(); + return item; + } + + public synchronized Item promoteToItemForNPC(NPC looter) { + + if (looter == null) + return null; + + if (isDeleted) + return null; + + if (this.getItemBase().getType().equals(ItemType.GOLD)) + return null; + + Item item = this; + item.setOwner(looter); + item.containerType = Enum.ItemContainerType.INVENTORY; + item.setIsID(true); + + if (this.getNumOfItems() > 1) + item.setNumOfItems(this.getNumOfItems()); + + try { + item = DbManager.ItemQueries.ADD_ITEM(item); + } catch (Exception e) { + Logger.error(e); + return null; + } + item.containerType = Enum.ItemContainerType.INVENTORY; + + // for (String effectName : this.effectNames) + // item.addPermanentEnchantment(effectName, 0); + //transfer enchantments to item + try { + for (String enchant : this.getEffectNames()) { + item.addPermanentEnchantment(enchant, 0); + } + } catch (Exception e) { + Logger.error(e.getMessage()); + } + + DbManager.NPCQueries.REMOVE_FROM_PRODUCTION_LIST(this.getObjectUUID(), looter.getObjectUUID()); + looter.removeItemFromForge(this); + this.junk(); + return item; + } + + public synchronized void recycle(NPC vendor) { + + //remove from production list for npc in db + + DbManager.NPCQueries.REMOVE_FROM_PRODUCTION_LIST(this.getObjectUUID(), vendor.getObjectUUID()); + this.removeFromCache(); + isDeleted = true; + } + + /** + * Junks the item and marks it as deleted + */ + @Override + protected synchronized void junk() { + this.removeFromCache(); + isDeleted = true; + } + + /** + * Determines if this object has been marked as deleted. + * + * @return True if deleted. + */ + public boolean isDeleted() { + return this.isDeleted; + } + + public boolean noSteal() { + return this.noSteal; + } + + public void addPermanentEnchantment(String enchantID, int rank, int value, boolean prefix) { + AbstractPowerAction apa = PowersManager.getPowerActionByIDString(enchantID); + if (apa == null) + return; + apa.applyEffectForItem(this, rank); + + //limit to 2 effects + // if (this.effectNames.size() < 2) + // this.effectNames.add(enchantID); + if (prefix) + this.prefix = enchantID; + else + this.suffix = enchantID; + + this.getEffectNames().add(enchantID); + } + + /* ***** + * All of the following methods are overridden from + * the superclass and intentionally not implemented. + * ***** + */ + + /** + * Not implemented + */ + @Override + @Deprecated + public void setOwnerID(int id) { + } + + /** + * Not implemented + */ + @Override + @Deprecated + public synchronized void decrementChargesRemaining() { + } + + /** + * Not implemented + */ + @Override + @Deprecated + protected boolean equipItem(NPC npc, byte slot) { + return false; + } + + /** + * Not implemented + */ + @Override + @Deprecated + protected boolean equipItem(PlayerCharacter pc, byte slot) { + return false; + } + + /** + * Not implemented + */ + @Override + @Deprecated + protected boolean moveItemToBank(NPC npc) { + return false; + } + + /** + * Not implemented + */ + @Override + @Deprecated + protected boolean moveItemToBank(PlayerCharacter pc) { + return false; + } + + /** + * Not implemented + */ + @Override + @Deprecated + protected boolean moveItemToInventory(Corpse corpse) { + return false; + } + + /** + * Not implemented + */ + @Override + @Deprecated + protected boolean moveItemToInventory(NPC npc) { + return false; + } + + /** + * Not implemented + */ + @Override + @Deprecated + protected boolean moveItemToInventory(PlayerCharacter pc) { + return false; + } + + /** + * Not implemented + */ + @Override + @Deprecated + protected boolean moveItemToVault(Account a) { + return false; + } + + /** + * Not implemented + */ + @Override + @Deprecated + public void setLastOwner(AbstractWorldObject value) { + } + + /** + * Not implemented + */ + @Override + @Deprecated + public void updateDatabase() { + } + + /** + * Not implemented + */ + @Override + @Deprecated + protected void validateItemContainer() { + } + + public String getPrefix() { + return prefix; + } + + public void setPrefix(String prefix) { + this.prefix = prefix; + } + + public String getSuffix() { + return suffix; + } + + public void setSuffix(String suffix) { + this.suffix = suffix; + } } diff --git a/src/engine/objects/MobLootBase.java b/src/engine/objects/MobLootBase.java index f3ce7925..e7a64b28 100644 --- a/src/engine/objects/MobLootBase.java +++ b/src/engine/objects/MobLootBase.java @@ -14,46 +14,46 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; -public class MobLootBase { +public class MobLootBase { - private int mobBaseID; - private int lootTableID; - private float chance; + public static HashMap> MobLootSet = new HashMap<>(); + private int mobBaseID; + private int lootTableID; + private float chance; - public static HashMap> MobLootSet = new HashMap<>(); + /** + * ResultSet Constructor + */ - /** - * ResultSet Constructor - */ - - public MobLootBase(ResultSet rs) throws SQLException { - this.mobBaseID = rs.getInt("mobBaseID"); + public MobLootBase(ResultSet rs) throws SQLException { + this.mobBaseID = rs.getInt("mobBaseID"); this.lootTableID = rs.getInt("lootTable"); this.chance = rs.getFloat("chance"); - } + } - public MobLootBase(int mobBaseID, int lootTableID, int chance) { - super(); - this.mobBaseID = mobBaseID; + public MobLootBase(int mobBaseID, int lootTableID, int chance) { + super(); + this.mobBaseID = mobBaseID; this.lootTableID = lootTableID; this.chance = chance; - } + } + + public int getMobBaseID() { + return mobBaseID; + } - public int getMobBaseID() { - return mobBaseID; - } - public float getChance() { - return chance; - } + public float getChance() { + return chance; + } - public int getLootTableID() { - return lootTableID; - } + public int getLootTableID() { + return lootTableID; + } - public void setLootTableID(int lootTableID) { - this.lootTableID = lootTableID; - } + public void setLootTableID(int lootTableID) { + this.lootTableID = lootTableID; + } } diff --git a/src/engine/objects/NPC.java b/src/engine/objects/NPC.java index 57bffc18..2af4d984 100644 --- a/src/engine/objects/NPC.java +++ b/src/engine/objects/NPC.java @@ -45,1548 +45,1548 @@ import static engine.util.StringUtils.wordCount; public class NPC extends AbstractCharacter { - public static int SVR_CLOSE_WINDOW = 4; - public static ArrayList Oprhans = new ArrayList<>(); - public static HashMap> _pirateNames = new HashMap<>(); - // Used for thread safety - public final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); - private final ArrayList rolling = new ArrayList<>(); - private final ArrayList siegeMinions = new ArrayList<>(); - public Building building; - public ReentrantReadWriteLock minionLock = new ReentrantReadWriteLock(); - public ArrayList forgedItems = new ArrayList<>(); - public HashMap equip = null; - public int runeSetID = 0; - public int extraRune2 = 0; - protected int loadID; - protected boolean isMob; - protected MobBase mobBase; - protected String name; - protected int dbID; - protected int currentID; - //used by static npcs - protected Zone parentZone; - protected float statLat; - protected float statLon; - protected float statAlt; - protected float sellPercent; //also train percent - protected float buyPercent; - protected int vendorID; - protected ArrayList modTypeTable; - protected ArrayList modSuffixTable; - protected ArrayList itemModTable; - protected int symbol; - // Variables NOT to be stored in db - protected boolean isStatic = false; - private DateTime upgradeDateTime = null; - private ConcurrentHashMap siegeMinionMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private HashSet canRoll = null; - private int parentZoneID; - private int equipmentSetID = 0; - private int repairCost = 5; - - - /** - * No Id Constructor - */ - public NPC(String name, short statStrCurrent, short statDexCurrent, short statConCurrent, - short statIntCurrent, short statSpiCurrent, short level, int exp, boolean sit, boolean walk, boolean combat, Vector3fImmutable bindLoc, - Vector3fImmutable currentLoc, Vector3fImmutable faceDir, short healthCurrent, short manaCurrent, short stamCurrent, Guild guild, - byte runningTrains, int npcType, boolean isMob, Building building, int contractID, Zone parent) { - super(name, "", statStrCurrent, statDexCurrent, statConCurrent, statIntCurrent, statSpiCurrent, level, exp, - bindLoc, currentLoc, faceDir, guild, runningTrains); - this.loadID = npcType; - this.isMob = isMob; - this.contract = DbManager.ContractQueries.GET_CONTRACT(contractID); - - if (this.contract != null) - this.mobBase = MobBase.getMobBase(this.contract.getMobbaseID()); - else - this.mobBase = MobBase.getMobBase(loadID); - - this.name = name; - this.buyPercent = 0.33f; - this.sellPercent = 1f; - this.building = building; - - this.parentZone = parent; - - clearStatic(); - - this.dbID = MBServerStatics.NO_DB_ROW_ASSIGNED_YET; - this.currentID = MBServerStatics.NO_DB_ROW_ASSIGNED_YET; - } - - /** - * Normal Constructor - */ - public NPC(String name, short statStrCurrent, short statDexCurrent, short statConCurrent, - short statIntCurrent, short statSpiCurrent, short level, int exp, boolean sit, boolean walk, boolean combat, Vector3fImmutable bindLoc, - Vector3fImmutable currentLoc, Vector3fImmutable faceDir, short healthCurrent, short manaCurrent, short stamCurrent, Guild guild, - byte runningTrains, int npcType, boolean isMob, Building building, int contractID, Zone parent, int newUUID) { - super(name, "", statStrCurrent, statDexCurrent, statConCurrent, statIntCurrent, statSpiCurrent, level, exp, - bindLoc, currentLoc, faceDir, guild, runningTrains, newUUID); - this.loadID = npcType; - this.isMob = isMob; - - if (this.contract != null) - this.mobBase = MobBase.getMobBase(this.contract.getMobbaseID()); - else - this.mobBase = MobBase.getMobBase(loadID); - - this.building = building; - this.name = name; - this.buyPercent = 0.33f; - this.sellPercent = 1f; - - this.parentZone = parent; - this.dbID = newUUID; - this.currentID = newUUID; - - initializeNPC(); - clearStatic(); - } - - /** - * ResultSet Constructor - */ - public NPC(ResultSet rs) throws SQLException { - - super(rs); - - java.util.Date sqlDateTime; - - try { - this.dbID = rs.getInt(1); - this.currentID = this.dbID; - this.setObjectTypeMask(MBServerStatics.MASK_NPC); - int contractID = rs.getInt("npc_contractID"); - this.contract = DbManager.ContractQueries.GET_CONTRACT(contractID); - this.parentZoneID = rs.getInt("parent"); - - this.gridObjectType = GridObjectType.STATIC; - this.equipmentSetID = rs.getInt("equipmentSet"); - this.runeSetID = rs.getInt("runeSet"); - - if (this.equipmentSetID == 0 && this.contract != null) - this.equipmentSetID = this.contract.equipmentSet; + public static int SVR_CLOSE_WINDOW = 4; + public static ArrayList Oprhans = new ArrayList<>(); + public static HashMap> _pirateNames = new HashMap<>(); + // Used for thread safety + public final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); + private final ArrayList rolling = new ArrayList<>(); + private final ArrayList siegeMinions = new ArrayList<>(); + public Building building; + public ReentrantReadWriteLock minionLock = new ReentrantReadWriteLock(); + public ArrayList forgedItems = new ArrayList<>(); + public HashMap equip = null; + public int runeSetID = 0; + public int extraRune2 = 0; + protected int loadID; + protected boolean isMob; + protected MobBase mobBase; + protected String name; + protected int dbID; + protected int currentID; + //used by static npcs + protected Zone parentZone; + protected float statLat; + protected float statLon; + protected float statAlt; + protected float sellPercent; //also train percent + protected float buyPercent; + protected int vendorID; + protected ArrayList modTypeTable; + protected ArrayList modSuffixTable; + protected ArrayList itemModTable; + protected int symbol; + // Variables NOT to be stored in db + protected boolean isStatic = false; + private DateTime upgradeDateTime = null; + private ConcurrentHashMap siegeMinionMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private HashSet canRoll = null; + private int parentZoneID; + private int equipmentSetID = 0; + private int repairCost = 5; + + + /** + * No Id Constructor + */ + public NPC(String name, short statStrCurrent, short statDexCurrent, short statConCurrent, + short statIntCurrent, short statSpiCurrent, short level, int exp, boolean sit, boolean walk, boolean combat, Vector3fImmutable bindLoc, + Vector3fImmutable currentLoc, Vector3fImmutable faceDir, short healthCurrent, short manaCurrent, short stamCurrent, Guild guild, + byte runningTrains, int npcType, boolean isMob, Building building, int contractID, Zone parent) { + super(name, "", statStrCurrent, statDexCurrent, statConCurrent, statIntCurrent, statSpiCurrent, level, exp, + bindLoc, currentLoc, faceDir, guild, runningTrains); + this.loadID = npcType; + this.isMob = isMob; + this.contract = DbManager.ContractQueries.GET_CONTRACT(contractID); + + if (this.contract != null) + this.mobBase = MobBase.getMobBase(this.contract.getMobbaseID()); + else + this.mobBase = MobBase.getMobBase(loadID); + + this.name = name; + this.buyPercent = 0.33f; + this.sellPercent = 1f; + this.building = building; + + this.parentZone = parent; + + clearStatic(); + + this.dbID = MBServerStatics.NO_DB_ROW_ASSIGNED_YET; + this.currentID = MBServerStatics.NO_DB_ROW_ASSIGNED_YET; + } + + /** + * Normal Constructor + */ + public NPC(String name, short statStrCurrent, short statDexCurrent, short statConCurrent, + short statIntCurrent, short statSpiCurrent, short level, int exp, boolean sit, boolean walk, boolean combat, Vector3fImmutable bindLoc, + Vector3fImmutable currentLoc, Vector3fImmutable faceDir, short healthCurrent, short manaCurrent, short stamCurrent, Guild guild, + byte runningTrains, int npcType, boolean isMob, Building building, int contractID, Zone parent, int newUUID) { + super(name, "", statStrCurrent, statDexCurrent, statConCurrent, statIntCurrent, statSpiCurrent, level, exp, + bindLoc, currentLoc, faceDir, guild, runningTrains, newUUID); + this.loadID = npcType; + this.isMob = isMob; + + if (this.contract != null) + this.mobBase = MobBase.getMobBase(this.contract.getMobbaseID()); + else + this.mobBase = MobBase.getMobBase(loadID); + + this.building = building; + this.name = name; + this.buyPercent = 0.33f; + this.sellPercent = 1f; + + this.parentZone = parent; + this.dbID = newUUID; + this.currentID = newUUID; + + initializeNPC(); + clearStatic(); + } + + /** + * ResultSet Constructor + */ + public NPC(ResultSet rs) throws SQLException { + + super(rs); + + java.util.Date sqlDateTime; + + try { + this.dbID = rs.getInt(1); + this.currentID = this.dbID; + this.setObjectTypeMask(MBServerStatics.MASK_NPC); + int contractID = rs.getInt("npc_contractID"); + this.contract = DbManager.ContractQueries.GET_CONTRACT(contractID); + this.parentZoneID = rs.getInt("parent"); + + this.gridObjectType = GridObjectType.STATIC; + this.equipmentSetID = rs.getInt("equipmentSet"); + this.runeSetID = rs.getInt("runeSet"); + + if (this.equipmentSetID == 0 && this.contract != null) + this.equipmentSetID = this.contract.equipmentSet; - this.loadID = rs.getInt("npc_raceID"); + this.loadID = rs.getInt("npc_raceID"); - // Default to contract load ID + // Default to contract load ID - if (loadID == 0) { + if (loadID == 0) { - if (this.contract != null) - loadID = this.contract.getMobbaseID(); - else { - Logger.error("Invalid contract for NPC: " + this.getObjectUUID()); - loadID = 2100; // Default human male - } - } + if (this.contract != null) + loadID = this.contract.getMobbaseID(); + else { + Logger.error("Invalid contract for NPC: " + this.getObjectUUID()); + loadID = 2100; // Default human male + } + } - this.mobBase = MobBase.getMobBase(this.loadID); - this.level = rs.getByte("npc_level"); - this.isMob = false; + this.mobBase = MobBase.getMobBase(this.loadID); + this.level = rs.getByte("npc_level"); + this.isMob = false; - int buildingID = rs.getInt("npc_buildingID"); - this.building = BuildingManager.getBuilding(buildingID); + int buildingID = rs.getInt("npc_buildingID"); + this.building = BuildingManager.getBuilding(buildingID); - // Most objects from the cache have a default buy - // percentage of 100% which was a dupe source due - // to the way MB calculated item values. + // Most objects from the cache have a default buy + // percentage of 100% which was a dupe source due + // to the way MB calculated item values. - // this.buyPercent = rs.getFloat("npc_buyPercent"); + // this.buyPercent = rs.getFloat("npc_buyPercent"); - this.buyPercent = .33f; - this.sellPercent = 1; + this.buyPercent = .33f; + this.sellPercent = 1; - this.setRot(new Vector3f(0, rs.getFloat("npc_rotation"), 0)); + this.setRot(new Vector3f(0, rs.getFloat("npc_rotation"), 0)); - this.statLat = rs.getFloat("npc_spawnX"); - this.statAlt = rs.getFloat("npc_spawnY"); - this.statLon = rs.getFloat("npc_spawnZ"); + this.statLat = rs.getFloat("npc_spawnX"); + this.statAlt = rs.getFloat("npc_spawnY"); + this.statLon = rs.getFloat("npc_spawnZ"); - int guildID = rs.getInt("npc_guildID"); + int guildID = rs.getInt("npc_guildID"); - if (this.building != null) - this.guild = this.building.getGuild(); - else - this.guild = Guild.getGuild(guildID); + if (this.building != null) + this.guild = this.building.getGuild(); + else + this.guild = Guild.getGuild(guildID); - if (guildID != 0 && (this.guild == null || this.guild.isEmptyGuild())) - NPC.Oprhans.add(currentID); - else if (this.building == null && buildingID > 0) - NPC.Oprhans.add(currentID); + if (guildID != 0 && (this.guild == null || this.guild.isEmptyGuild())) + NPC.Oprhans.add(currentID); + else if (this.building == null && buildingID > 0) + NPC.Oprhans.add(currentID); - if (this.guild == null) - this.guild = Guild.getErrantGuild(); + if (this.guild == null) + this.guild = Guild.getErrantGuild(); - // Set upgrade date JodaTime DateTime object - // if one exists in the database. + // Set upgrade date JodaTime DateTime object + // if one exists in the database. - sqlDateTime = rs.getTimestamp("upgradeDate"); + sqlDateTime = rs.getTimestamp("upgradeDate"); - if (sqlDateTime != null) - upgradeDateTime = new DateTime(sqlDateTime); - else - upgradeDateTime = null; + if (sqlDateTime != null) + upgradeDateTime = new DateTime(sqlDateTime); + else + upgradeDateTime = null; - // Submit upgrade job if NPC is currently set to rank. + // Submit upgrade job if NPC is currently set to rank. - if (this.upgradeDateTime != null) - submitUpgradeJob(); + if (this.upgradeDateTime != null) + submitUpgradeJob(); - this.name = rs.getString("npc_name"); + this.name = rs.getString("npc_name"); - // Name override for npc + // Name override for npc - if (wordCount(this.name) < 2 && this.contract != null) - this.name += " the " + this.contract.getName(); + if (wordCount(this.name) < 2 && this.contract != null) + this.name += " the " + this.contract.getName(); - } catch (Exception e) { - Logger.error("NPC: " + this.dbID + " :" + e); - e.printStackTrace(); - } + } catch (Exception e) { + Logger.error("NPC: " + this.dbID + " :" + e); + e.printStackTrace(); + } - try { - initializeNPC(); - } catch (Exception e) { - Logger.error("NPC: " + this.dbID + " :" + e); - } + try { + initializeNPC(); + } catch (Exception e) { + Logger.error("NPC: " + this.dbID + " :" + e); + } - } + } - public static boolean ISWallArcher(Contract contract) { + public static boolean ISWallArcher(Contract contract) { - if (contract == null) - return false; + if (contract == null) + return false; - //838, 950, 1051, 1181, 1251, 1351, 1451, 1501, 1526, 1551, 980101, + //838, 950, 1051, 1181, 1251, 1351, 1451, 1501, 1526, 1551, 980101, - return contract.getAllowedBuildings().contains(BuildingGroup.WALLCORNER) || - contract.getAllowedBuildings().contains(BuildingGroup.WALLSTRAIGHTTOWER); - } + return contract.getAllowedBuildings().contains(BuildingGroup.WALLCORNER) || + contract.getAllowedBuildings().contains(BuildingGroup.WALLSTRAIGHTTOWER); + } - //This method restarts an upgrade timer when a building is loaded from the database. - // Submit upgrade job for this building based upon it's current upgradeDateTime + //This method restarts an upgrade timer when a building is loaded from the database. + // Submit upgrade job for this building based upon it's current upgradeDateTime - public static NPC getFromCache(int id) { - return (NPC) DbManager.getFromCache(GameObjectType.NPC, id); - } + public static NPC getFromCache(int id) { + return (NPC) DbManager.getFromCache(GameObjectType.NPC, id); + } - public static boolean UpdateName(NPC npc, String value) { + public static boolean UpdateName(NPC npc, String value) { - if (!DbManager.NPCQueries.UPDATE_NAME(npc, value)) - return false; + if (!DbManager.NPCQueries.UPDATE_NAME(npc, value)) + return false; - npc.name = value; - return true; + npc.name = value; + return true; - } + } - public static void serializeNpcForClientMsgOtherPlayer(NPC npc, ByteBufferWriter writer, boolean hideAsciiLastName) - throws SerializationException { - serializeForClientMsgOtherPlayer(npc, writer); - } + public static void serializeNpcForClientMsgOtherPlayer(NPC npc, ByteBufferWriter writer, boolean hideAsciiLastName) + throws SerializationException { + serializeForClientMsgOtherPlayer(npc, writer); + } - public static void serializeForClientMsgOtherPlayer(NPC npc, ByteBufferWriter writer) - throws SerializationException { + public static void serializeForClientMsgOtherPlayer(NPC npc, ByteBufferWriter writer) + throws SerializationException { - writer.putInt(0); - writer.putInt(0); + writer.putInt(0); + writer.putInt(0); - //num Runes - int cnt = 3; - boolean isVamp = false, isHealer = false, isArcher = false, isTrainer = false; - int contractID = 0, classID = 0; - int extraRune = 0; + //num Runes + int cnt = 3; + boolean isVamp = false, isHealer = false, isArcher = false, isTrainer = false; + int contractID = 0, classID = 0; + int extraRune = 0; - if (npc.contract != null) { - contractID = npc.contract.getContractID(); - classID = npc.contract.getClassID(); - extraRune = npc.contract.getExtraRune(); + if (npc.contract != null) { + contractID = npc.contract.getContractID(); + classID = npc.contract.getClassID(); + extraRune = npc.contract.getExtraRune(); - if (extraRune == contractID) - extraRune = 0; - - } + if (extraRune == contractID) + extraRune = 0; + + } - if ((contractID > 252642 && contractID < 252647) || contractID == 252652) { - isVamp = true; - cnt++; - } + if ((contractID > 252642 && contractID < 252647) || contractID == 252652) { + isVamp = true; + cnt++; + } - if (contractID == 252582 || contractID == 252579 || contractID == 252581 - || contractID == 252584 || contractID == 252597 || contractID == 252598 - || contractID == 252628 || extraRune == 252582 || extraRune == 252579 - || extraRune == 252581 || extraRune == 252584 || extraRune == 252597 - || extraRune == 252598 || extraRune == 252628) { - isHealer = true; - cnt++; - } - - if (contractID == 252570) { - isArcher = true; - cnt++; - } - - if (classID != 0) - cnt++; - - if (extraRune != 0 && extraRune != contractID) - cnt++; - - writer.putInt(cnt); - - //Race - writer.putInt(1); - writer.putInt(0); - - if (npc.mobBase != null) - writer.putInt(npc.mobBase.getLoadID()); - else - writer.putInt(2011); - - writer.putInt(GameObjectType.NPCRaceRune.ordinal()); - writer.putInt(npc.currentID); - - //Class/Trainer/Whatever - writer.putInt(5); - writer.putInt(0); + if (contractID == 252582 || contractID == 252579 || contractID == 252581 + || contractID == 252584 || contractID == 252597 || contractID == 252598 + || contractID == 252628 || extraRune == 252582 || extraRune == 252579 + || extraRune == 252581 || extraRune == 252584 || extraRune == 252597 + || extraRune == 252598 || extraRune == 252628) { + isHealer = true; + cnt++; + } + + if (contractID == 252570) { + isArcher = true; + cnt++; + } + + if (classID != 0) + cnt++; + + if (extraRune != 0 && extraRune != contractID) + cnt++; + + writer.putInt(cnt); + + //Race + writer.putInt(1); + writer.putInt(0); + + if (npc.mobBase != null) + writer.putInt(npc.mobBase.getLoadID()); + else + writer.putInt(2011); + + writer.putInt(GameObjectType.NPCRaceRune.ordinal()); + writer.putInt(npc.currentID); + + //Class/Trainer/Whatever + writer.putInt(5); + writer.putInt(0); - if (npc.contract != null) - writer.putInt(contractID); - else - writer.putInt(2500); - - writer.putInt(GameObjectType.NPCClassRune.ordinal()); - writer.putInt(npc.currentID); - - //vampire trainer - cnt = 0; - - if (extraRune != 0) - cnt = serializeExtraRune(npc, extraRune, cnt, writer); - if (isVamp) - cnt = serializeExtraRune(npc, 252647, cnt, writer); - - //Healer trainer - if (isHealer) { - // int healerRune = 2501; - // if (npc.getLevel() >= 60) - //healerRune = 252592; - cnt = serializeExtraRune(npc, 252592, cnt, writer); - } - - if (classID != 0) { - writer.putInt(4); - writer.putInt(0); - writer.putInt(classID); - writer.putInt(GameObjectType.NPCExtraRune.ordinal()); - writer.putInt(npc.currentID); - } - - //Scout trainer - if (isArcher) { - cnt = serializeExtraRune(npc, 252654, cnt, writer); - } - - //Shopkeeper - writer.putInt(5); - writer.putInt(0); - writer.putInt(0x3DACC); - writer.putInt(GameObjectType.NPCShopkeeperRune.ordinal()); - writer.putInt(npc.currentID); - - //Send Stats - writer.putInt(5); - writer.putInt(0x8AC3C0E6); //Str - writer.putInt(0); - writer.putInt(0xACB82E33); //Dex - writer.putInt(0); - writer.putInt(0xB15DC77E); //Con - writer.putInt(0); - writer.putInt(0xE07B3336); //Int - writer.putInt(0); - writer.putInt(0xFF665EC3); //Spi - writer.putInt(0); - - writer.putString(npc.name); - writer.putString(""); - - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - - writer.put((byte) 0); - writer.putInt(npc.getObjectType().ordinal()); - writer.putInt(npc.currentID); - - writer.putFloat(1.0f); - writer.putFloat(1.0f); - writer.putFloat(1.0f); - - if (npc.region != null) - writer.putVector3f(ZoneManager.convertWorldToLocal(npc.building, npc.getLoc())); - else - writer.putVector3f(npc.getLoc()); - - //Rotation - float radians = (float) Math.acos(npc.getRot().y) * 2; - - if (npc.building != null) - if (npc.building.getBounds() != null && npc.building.getBounds().getQuaternion() != null) - radians += (npc.building.getBounds().getQuaternion()).angleY; - - writer.putFloat(radians); - - //Running Speed - writer.putInt(0); - - // get a copy of the equipped items. - - if (npc.equip != null) { - writer.putInt(npc.equip.size()); - - for (MobEquipment me : npc.equip.values()) - MobEquipment.serializeForClientMsg(me, writer); - } else - writer.putInt(0); - - writer.putInt((npc.level / 10)); - writer.putInt(npc.level); - writer.putInt(npc.getIsSittingAsInt()); //Standing - writer.putInt(npc.getIsWalkingAsInt()); //Walking - writer.putInt(npc.getIsCombatAsInt()); //Combat - writer.putInt(2); //Unknown - writer.putInt(1); //Unknown - Headlights? - writer.putInt(0); - - if (npc.building != null && npc.region != null) { - writer.putInt(npc.building.getObjectType().ordinal()); - writer.putInt(npc.building.getObjectUUID()); - } else { - writer.putInt(0); //<-Building Object Type - writer.putInt(0); //<-Building Object ID - } - writer.put((byte) 0); - writer.put((byte) 0); - writer.put((byte) 0); - - //npc dialog menus from contracts - - if (npc.contract != null) { - ArrayList npcMenuOptions = npc.contract.getNPCMenuOptions(); - writer.putInt(npcMenuOptions.size()); - for (Integer val : npcMenuOptions) { - writer.putInt(val); - } - - } else - writer.putInt(0); - - writer.put((byte) 1); - - if (npc.building != null) { - writer.putInt(GameObjectType.StrongBox.ordinal()); - writer.putInt(npc.currentID); - writer.putInt(GameObjectType.StrongBox.ordinal()); - writer.putInt(npc.building.getObjectUUID()); - } else { - writer.putLong(0); - writer.putLong(0); - } - - if (npc.contract != null) - writer.putInt(npc.contract.getIconID()); - else - writer.putInt(0); //npc icon ID - - writer.putInt(0); - writer.putShort((short) 0); - - if (npc.contract != null && npc.contract.isTrainer()) { - writer.putInt(classID); - } else { - writer.putInt(0); - } - - if (npc.contract != null && npc.contract.isTrainer()) - writer.putInt(classID); - else - writer.putInt(0); - - writer.putInt(0); - writer.putInt(0); - - writer.putFloat(4); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.put((byte) 0); - - //Pull guild info from building if linked to one - - Guild.serializeForClientMsg(npc.guild, writer, null, true); - - writer.putInt(1); - writer.putInt(0x8A2E); - writer.putInt(0); - writer.putInt(0); - - //TODO Guard - writer.put((byte) 0); //Is guard.. - - writer.putFloat(1500f); //npc.healthMax - writer.putFloat(1500f); //npc.health - - //TODO Peace Zone - writer.put((byte) 1); //0=show tags, 1=don't - writer.putInt(0); - writer.put((byte) 0); - } - - private static int serializeExtraRune(NPC npc, int runeID, int cnt, ByteBufferWriter writer) { - writer.putInt(5); - writer.putInt(0); - writer.putInt(runeID); - if (cnt == 0) - writer.putInt(GameObjectType.NPCClassRuneTwo.ordinal()); - else - writer.putInt(GameObjectType.NPCClassRuneThree.ordinal()); - - writer.putInt(npc.currentID); - return cnt + 1; - } + if (npc.contract != null) + writer.putInt(contractID); + else + writer.putInt(2500); + + writer.putInt(GameObjectType.NPCClassRune.ordinal()); + writer.putInt(npc.currentID); + + //vampire trainer + cnt = 0; + + if (extraRune != 0) + cnt = serializeExtraRune(npc, extraRune, cnt, writer); + if (isVamp) + cnt = serializeExtraRune(npc, 252647, cnt, writer); + + //Healer trainer + if (isHealer) { + // int healerRune = 2501; + // if (npc.getLevel() >= 60) + //healerRune = 252592; + cnt = serializeExtraRune(npc, 252592, cnt, writer); + } + + if (classID != 0) { + writer.putInt(4); + writer.putInt(0); + writer.putInt(classID); + writer.putInt(GameObjectType.NPCExtraRune.ordinal()); + writer.putInt(npc.currentID); + } + + //Scout trainer + if (isArcher) { + cnt = serializeExtraRune(npc, 252654, cnt, writer); + } + + //Shopkeeper + writer.putInt(5); + writer.putInt(0); + writer.putInt(0x3DACC); + writer.putInt(GameObjectType.NPCShopkeeperRune.ordinal()); + writer.putInt(npc.currentID); + + //Send Stats + writer.putInt(5); + writer.putInt(0x8AC3C0E6); //Str + writer.putInt(0); + writer.putInt(0xACB82E33); //Dex + writer.putInt(0); + writer.putInt(0xB15DC77E); //Con + writer.putInt(0); + writer.putInt(0xE07B3336); //Int + writer.putInt(0); + writer.putInt(0xFF665EC3); //Spi + writer.putInt(0); + + writer.putString(npc.name); + writer.putString(""); + + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + + writer.put((byte) 0); + writer.putInt(npc.getObjectType().ordinal()); + writer.putInt(npc.currentID); + + writer.putFloat(1.0f); + writer.putFloat(1.0f); + writer.putFloat(1.0f); + + if (npc.region != null) + writer.putVector3f(ZoneManager.convertWorldToLocal(npc.building, npc.getLoc())); + else + writer.putVector3f(npc.getLoc()); + + //Rotation + float radians = (float) Math.acos(npc.getRot().y) * 2; + + if (npc.building != null) + if (npc.building.getBounds() != null && npc.building.getBounds().getQuaternion() != null) + radians += (npc.building.getBounds().getQuaternion()).angleY; + + writer.putFloat(radians); + + //Running Speed + writer.putInt(0); + + // get a copy of the equipped items. + + if (npc.equip != null) { + writer.putInt(npc.equip.size()); + + for (MobEquipment me : npc.equip.values()) + MobEquipment.serializeForClientMsg(me, writer); + } else + writer.putInt(0); + + writer.putInt((npc.level / 10)); + writer.putInt(npc.level); + writer.putInt(npc.getIsSittingAsInt()); //Standing + writer.putInt(npc.getIsWalkingAsInt()); //Walking + writer.putInt(npc.getIsCombatAsInt()); //Combat + writer.putInt(2); //Unknown + writer.putInt(1); //Unknown - Headlights? + writer.putInt(0); + + if (npc.building != null && npc.region != null) { + writer.putInt(npc.building.getObjectType().ordinal()); + writer.putInt(npc.building.getObjectUUID()); + } else { + writer.putInt(0); //<-Building Object Type + writer.putInt(0); //<-Building Object ID + } + writer.put((byte) 0); + writer.put((byte) 0); + writer.put((byte) 0); + + //npc dialog menus from contracts + + if (npc.contract != null) { + ArrayList npcMenuOptions = npc.contract.getNPCMenuOptions(); + writer.putInt(npcMenuOptions.size()); + for (Integer val : npcMenuOptions) { + writer.putInt(val); + } + + } else + writer.putInt(0); + + writer.put((byte) 1); + + if (npc.building != null) { + writer.putInt(GameObjectType.StrongBox.ordinal()); + writer.putInt(npc.currentID); + writer.putInt(GameObjectType.StrongBox.ordinal()); + writer.putInt(npc.building.getObjectUUID()); + } else { + writer.putLong(0); + writer.putLong(0); + } + + if (npc.contract != null) + writer.putInt(npc.contract.getIconID()); + else + writer.putInt(0); //npc icon ID + + writer.putInt(0); + writer.putShort((short) 0); + + if (npc.contract != null && npc.contract.isTrainer()) { + writer.putInt(classID); + } else { + writer.putInt(0); + } + + if (npc.contract != null && npc.contract.isTrainer()) + writer.putInt(classID); + else + writer.putInt(0); + + writer.putInt(0); + writer.putInt(0); + + writer.putFloat(4); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.put((byte) 0); + + //Pull guild info from building if linked to one + + Guild.serializeForClientMsg(npc.guild, writer, null, true); + + writer.putInt(1); + writer.putInt(0x8A2E); + writer.putInt(0); + writer.putInt(0); + + //TODO Guard + writer.put((byte) 0); //Is guard.. + + writer.putFloat(1500f); //npc.healthMax + writer.putFloat(1500f); //npc.health + + //TODO Peace Zone + writer.put((byte) 1); //0=show tags, 1=don't + writer.putInt(0); + writer.put((byte) 0); + } + + private static int serializeExtraRune(NPC npc, int runeID, int cnt, ByteBufferWriter writer) { + writer.putInt(5); + writer.putInt(0); + writer.putInt(runeID); + if (cnt == 0) + writer.putInt(GameObjectType.NPCClassRuneTwo.ordinal()); + else + writer.putInt(GameObjectType.NPCClassRuneThree.ordinal()); + + writer.putInt(npc.currentID); + return cnt + 1; + } - public static NPC createNPC(String name, int contractID, Vector3fImmutable spawn, Guild guild, boolean isMob, Zone parent, short level, Building building) { + public static NPC createNPC(String name, int contractID, Vector3fImmutable spawn, Guild guild, boolean isMob, Zone parent, short level, Building building) { - NPC npcWithoutID = new NPC(name, (short) 0, (short) 0, (short) 0, (short) 0, - (short) 0, (short) 1, 0, false, false, false, spawn, spawn, Vector3fImmutable.ZERO, - (short) 1, (short) 1, (short) 1, guild, (byte) 0, 0, isMob, building, contractID, parent); + NPC npcWithoutID = new NPC(name, (short) 0, (short) 0, (short) 0, (short) 0, + (short) 0, (short) 1, 0, false, false, false, spawn, spawn, Vector3fImmutable.ZERO, + (short) 1, (short) 1, (short) 1, guild, (byte) 0, 0, isMob, building, contractID, parent); - npcWithoutID.setLevel(level); + npcWithoutID.setLevel(level); - if (npcWithoutID.mobBase == null) { - return null; - } - if (parent != null) { - npcWithoutID.setRelPos(parent, spawn.x - parent.absX, spawn.y - parent.absY, spawn.z - parent.absZ); - } - NPC npc; - try { - npc = DbManager.NPCQueries.ADD_NPC(npcWithoutID, isMob); - npc.setObjectTypeMask(MBServerStatics.MASK_NPC); - } catch (Exception e) { - Logger.error(e); - npc = null; - } + if (npcWithoutID.mobBase == null) { + return null; + } + if (parent != null) { + npcWithoutID.setRelPos(parent, spawn.x - parent.absX, spawn.y - parent.absY, spawn.z - parent.absZ); + } + NPC npc; + try { + npc = DbManager.NPCQueries.ADD_NPC(npcWithoutID, isMob); + npc.setObjectTypeMask(MBServerStatics.MASK_NPC); + } catch (Exception e) { + Logger.error(e); + npc = null; + } - return npc; - } + return npc; + } - public static NPC getNPC(int id) { + public static NPC getNPC(int id) { - if (id == 0) - return null; - NPC npc = (NPC) DbManager.getFromCache(GameObjectType.NPC, id); - if (npc != null) - return npc; + if (id == 0) + return null; + NPC npc = (NPC) DbManager.getFromCache(GameObjectType.NPC, id); + if (npc != null) + return npc; - return DbManager.NPCQueries.GET_NPC(id); - } + return DbManager.NPCQueries.GET_NPC(id); + } - /* - * Getters - */ + /* + * Getters + */ - public static boolean ISGuardCaptain(int contractID) { - return MinionType.ContractToMinionMap.containsKey(contractID); - } + public static boolean ISGuardCaptain(int contractID) { + return MinionType.ContractToMinionMap.containsKey(contractID); + } - public static boolean UpdateEquipSetID(NPC npc, int equipSetID) { + public static boolean UpdateEquipSetID(NPC npc, int equipSetID) { - if (!NPCManager._bootySetMap.containsKey(equipSetID)) - return false; + if (!NPCManager._bootySetMap.containsKey(equipSetID)) + return false; - if (!DbManager.NPCQueries.UPDATE_EQUIPSET(npc, equipSetID)) - return false; + if (!DbManager.NPCQueries.UPDATE_EQUIPSET(npc, equipSetID)) + return false; - npc.equipmentSetID = equipSetID; + npc.equipmentSetID = equipSetID; - return true; - } + return true; + } - public static boolean UpdateRaceID(NPC npc, int raceID) { + public static boolean UpdateRaceID(NPC npc, int raceID) { - if (!DbManager.NPCQueries.UPDATE_MOBBASE(npc, raceID)) - return false; + if (!DbManager.NPCQueries.UPDATE_MOBBASE(npc, raceID)) + return false; - npc.loadID = raceID; - npc.mobBase = MobBase.getMobBase(npc.loadID); - return true; - } + npc.loadID = raceID; + npc.mobBase = MobBase.getMobBase(npc.loadID); + return true; + } - public static NPCProfits GetNPCProfits(NPC npc) { - return NPCProfits.ProfitCache.get(npc.currentID); - } + public static NPCProfits GetNPCProfits(NPC npc) { + return NPCProfits.ProfitCache.get(npc.currentID); + } - public static void processRedeedNPC(NPC npc, Building building, ClientConnection origin) { + public static void processRedeedNPC(NPC npc, Building building, ClientConnection origin) { - // Member variable declaration - PlayerCharacter player; - Contract contract; - CharacterItemManager itemMan; - ItemBase itemBase; - Item item; + // Member variable declaration + PlayerCharacter player; + Contract contract; + CharacterItemManager itemMan; + ItemBase itemBase; + Item item; - npc.lock.writeLock().lock(); + npc.lock.writeLock().lock(); - try { + try { - if (building == null) - return; - player = SessionManager.getPlayerCharacter(origin); - itemMan = player.getCharItemManager(); + if (building == null) + return; + player = SessionManager.getPlayerCharacter(origin); + itemMan = player.getCharItemManager(); - contract = npc.getContract(); + contract = npc.getContract(); - if (!player.getCharItemManager().hasRoomInventory((short) 1)) { - ErrorPopupMsg.sendErrorPopup(player, 21); - return; - } + if (!player.getCharItemManager().hasRoomInventory((short) 1)) { + ErrorPopupMsg.sendErrorPopup(player, 21); + return; + } - if (!building.getHirelings().containsKey(npc)) - return; + if (!building.getHirelings().containsKey(npc)) + return; - if (!npc.remove()) { - PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - return; - } + if (!npc.remove()) { + PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + return; + } - building.getHirelings().remove(npc); + building.getHirelings().remove(npc); - itemBase = ItemBase.getItemBase(contract.getContractID()); + itemBase = ItemBase.getItemBase(contract.getContractID()); - if (itemBase == null) { - Logger.error("Could not find Contract for npc: " + npc.getObjectUUID()); - return; - } + if (itemBase == null) { + Logger.error("Could not find Contract for npc: " + npc.getObjectUUID()); + return; + } - boolean itemWorked = false; + boolean itemWorked = false; - item = new Item(itemBase, player.getObjectUUID(), OwnerType.PlayerCharacter, (byte) ((byte) npc.getRank() - 1), (byte) ((byte) npc.getRank() - 1), - (short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, - new ArrayList<>(), ""); - item.setNumOfItems(1); - item.containerType = Enum.ItemContainerType.INVENTORY; + item = new Item(itemBase, player.getObjectUUID(), OwnerType.PlayerCharacter, (byte) ((byte) npc.getRank() - 1), (byte) ((byte) npc.getRank() - 1), + (short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, + new ArrayList<>(), ""); + item.setNumOfItems(1); + item.containerType = Enum.ItemContainerType.INVENTORY; - try { - item = DbManager.ItemQueries.ADD_ITEM(item); - itemWorked = true; - } catch (Exception e) { - Logger.error(e); - } - if (itemWorked) { - itemMan.addItemToInventory(item); - itemMan.updateInventory(); - } + try { + item = DbManager.ItemQueries.ADD_ITEM(item); + itemWorked = true; + } catch (Exception e) { + Logger.error(e); + } + if (itemWorked) { + itemMan.addItemToInventory(item); + itemMan.updateInventory(); + } - ManageCityAssetsMsg mca = new ManageCityAssetsMsg(); - mca.actionType = SVR_CLOSE_WINDOW; - mca.setTargetType(building.getObjectType().ordinal()); - mca.setTargetID(building.getObjectUUID()); - origin.sendMsg(mca); + ManageCityAssetsMsg mca = new ManageCityAssetsMsg(); + mca.actionType = SVR_CLOSE_WINDOW; + mca.setTargetType(building.getObjectType().ordinal()); + mca.setTargetID(building.getObjectUUID()); + origin.sendMsg(mca); - } catch (Exception e) { - Logger.error(e); - } finally { - npc.lock.writeLock().unlock(); - } + } catch (Exception e) { + Logger.error(e); + } finally { + npc.lock.writeLock().unlock(); + } - } + } - public final void submitUpgradeJob() { + public final void submitUpgradeJob() { - JobContainer jc; + JobContainer jc; - if (this.getUpgradeDateTime() == null) { - Logger.error("Attempt to submit upgrade job for non-ranking NPC"); - return; - } + if (this.getUpgradeDateTime() == null) { + Logger.error("Attempt to submit upgrade job for non-ranking NPC"); + return; + } - // Submit upgrade job for future date or current instant + // Submit upgrade job for future date or current instant - if (this.getUpgradeDateTime().isAfter(DateTime.now())) - jc = JobScheduler.getInstance().scheduleJob(new UpgradeNPCJob(this), - this.getUpgradeDateTime().getMillis()); - else - JobScheduler.getInstance().scheduleJob(new UpgradeNPCJob(this), 0); + if (this.getUpgradeDateTime().isAfter(DateTime.now())) + jc = JobScheduler.getInstance().scheduleJob(new UpgradeNPCJob(this), + this.getUpgradeDateTime().getMillis()); + else + JobScheduler.getInstance().scheduleJob(new UpgradeNPCJob(this), 0); - } + } - public void setRank(int newRank) { + public void setRank(int newRank) { - DbManager.NPCQueries.SET_PROPERTY(this, "npc_level", newRank); - this.level = (short) newRank; - } + DbManager.NPCQueries.SET_PROPERTY(this, "npc_level", newRank); + this.level = (short) newRank; + } - public int getDBID() { - return this.dbID; - } + public int getDBID() { + return this.dbID; + } - @Override - public int getObjectUUID() { - return currentID; - } + @Override + public int getObjectUUID() { + return currentID; + } - private void clearStatic() { - this.parentZone = null; - this.statLat = 0f; - this.statLon = 0f; - this.statAlt = 0f; - } + private void clearStatic() { + this.parentZone = null; + this.statLat = 0f; + this.statLon = 0f; + this.statAlt = 0f; + } - private void initializeNPC() { + private void initializeNPC() { - int slot; - Vector3fImmutable slotLocation; - Quaternion slotRotation; + int slot; + Vector3fImmutable slotLocation; + Quaternion slotRotation; - if (ConfigManager.serverType.equals(ServerType.LOGINSERVER)) - return; + if (ConfigManager.serverType.equals(ServerType.LOGINSERVER)) + return; - // NPC Guild owners have no contract + // NPC Guild owners have no contract - if (this.contract == null) - return; + if (this.contract == null) + return; - // Configure parent zone adding this NPC to the - // zone collection + // Configure parent zone adding this NPC to the + // zone collection - this.parentZone = ZoneManager.getZoneByUUID(this.parentZoneID); - this.parentZone.zoneNPCSet.remove(this); - this.parentZone.zoneNPCSet.add(this); + this.parentZone = ZoneManager.getZoneByUUID(this.parentZoneID); + this.parentZone.zoneNPCSet.remove(this); + this.parentZone.zoneNPCSet.add(this); - // Setup location for this NPC + // Setup location for this NPC - this.bindLoc = new Vector3fImmutable(this.statLat, this.statAlt, this.statLon); - this.bindLoc = this.parentZone.getLoc().add(this.bindLoc); - this.loc = new Vector3fImmutable(bindLoc); + this.bindLoc = new Vector3fImmutable(this.statLat, this.statAlt, this.statLon); + this.bindLoc = this.parentZone.getLoc().add(this.bindLoc); + this.loc = new Vector3fImmutable(bindLoc); - // Handle NPCs within buildings + // Handle NPCs within buildings - if (this.building != null) { + if (this.building != null) { - // Get next available slot for this NPC and use it - // to add the NPC to the building's hireling list + // Get next available slot for this NPC and use it + // to add the NPC to the building's hireling list - slot = BuildingManager.getAvailableSlot(building); + slot = BuildingManager.getAvailableSlot(building); - if (slot == -1) - Logger.error("No available slot for NPC: " + this.getObjectUUID()); + if (slot == -1) + Logger.error("No available slot for NPC: " + this.getObjectUUID()); - building.getHirelings().put(this, slot); + building.getHirelings().put(this, slot); - // Override bind and location for this npc derived - // from BuildingManager slot location data. + // Override bind and location for this npc derived + // from BuildingManager slot location data. - slotLocation = BuildingManager.getSlotLocation(building, slot).getLocation(); + slotLocation = BuildingManager.getSlotLocation(building, slot).getLocation(); - this.bindLoc = building.getLoc().add(slotLocation); + this.bindLoc = building.getLoc().add(slotLocation); - // Rotate slot position by the building rotation + // Rotate slot position by the building rotation - this.bindLoc = Vector3fImmutable.rotateAroundPoint(building.getLoc(), this.bindLoc, building.getBounds().getQuaternion().angleY); + this.bindLoc = Vector3fImmutable.rotateAroundPoint(building.getLoc(), this.bindLoc, building.getBounds().getQuaternion().angleY); - this.loc = new Vector3fImmutable(bindLoc); + this.loc = new Vector3fImmutable(bindLoc); - // Rotate NPC by slot rotation + // Rotate NPC by slot rotation - slotRotation = BuildingManager.getSlotLocation(building, slot).getRotation(); - this.setRot(new Vector3f(0, slotRotation.y, 0)); + slotRotation = BuildingManager.getSlotLocation(building, slot).getRotation(); + this.setRot(new Vector3f(0, slotRotation.y, 0)); - // Rotate NPC rotation by the building's rotation + // Rotate NPC rotation by the building's rotation - slotRotation = new Quaternion().fromAngles(0, acos(this.getRot().y) * 2, 0); - slotRotation = slotRotation.mult(building.getBounds().getQuaternion()); - this.setRot(new Vector3f(0, slotRotation.y, 0)); + slotRotation = new Quaternion().fromAngles(0, acos(this.getRot().y) * 2, 0); + slotRotation = slotRotation.mult(building.getBounds().getQuaternion()); + this.setRot(new Vector3f(0, slotRotation.y, 0)); - // Configure region and floor/level for this NPC + // Configure region and floor/level for this NPC - this.region = BuildingManager.GetRegion(this.building, bindLoc.x, bindLoc.y, bindLoc.z); - } + this.region = BuildingManager.GetRegion(this.building, bindLoc.x, bindLoc.y, bindLoc.z); + } - if (this.contract != null) { - this.symbol = this.contract.getIconID(); - this.modTypeTable = this.contract.getNPCModTypeTable(); - this.modSuffixTable = this.contract.getNpcModSuffixTable(); - this.itemModTable = this.contract.getItemModTable(); - int VID = this.contract.getVendorID(); + if (this.contract != null) { + this.symbol = this.contract.getIconID(); + this.modTypeTable = this.contract.getNPCModTypeTable(); + this.modSuffixTable = this.contract.getNpcModSuffixTable(); + this.itemModTable = this.contract.getItemModTable(); + int VID = this.contract.getVendorID(); - if (VID != 0) - this.vendorID = VID; - else - this.vendorID = 1; //no vendor items - } + if (VID != 0) + this.vendorID = VID; + else + this.vendorID = 1; //no vendor items + } - if (this.mobBase != null) { - this.healthMax = this.mobBase.getHealthMax(); - this.manaMax = 0; - this.staminaMax = 0; - this.setHealth(this.healthMax); - this.mana.set(this.manaMax); - this.stamina.set(this.staminaMax); - } + if (this.mobBase != null) { + this.healthMax = this.mobBase.getHealthMax(); + this.manaMax = 0; + this.staminaMax = 0; + this.setHealth(this.healthMax); + this.mana.set(this.manaMax); + this.stamina.set(this.staminaMax); + } - if (this.parentZone.isPlayerCity()) - if (NPC.GetNPCProfits(this) == null) - NPCProfits.CreateProfits(this); + if (this.parentZone.isPlayerCity()) + if (NPC.GetNPCProfits(this) == null) + NPCProfits.CreateProfits(this); - //TODO set these correctly later - this.rangeHandOne = 8; - this.rangeHandTwo = -1; - this.minDamageHandOne = 1; - this.maxDamageHandOne = 4; - this.minDamageHandTwo = 1; - this.maxDamageHandTwo = 4; - this.atrHandOne = 300; - this.defenseRating = 200; - this.isActive = true; + //TODO set these correctly later + this.rangeHandOne = 8; + this.rangeHandTwo = -1; + this.minDamageHandOne = 1; + this.maxDamageHandOne = 4; + this.minDamageHandTwo = 1; + this.maxDamageHandTwo = 4; + this.atrHandOne = 300; + this.defenseRating = 200; + this.isActive = true; - this.charItemManager.load(); - } + this.charItemManager.load(); + } - public boolean isMob() { - return this.isMob; - } + public boolean isMob() { + return this.isMob; + } - public MobBase getMobBase() { - return this.mobBase; - } + public MobBase getMobBase() { + return this.mobBase; + } - public Contract getContract() { - return this.contract; - } + public Contract getContract() { + return this.contract; + } - /* - * Serialization - */ + /* + * Serialization + */ - public int getContractID() { + public int getContractID() { - if (this.contract != null) - return this.contract.getObjectUUID(); + if (this.contract != null) + return this.contract.getObjectUUID(); - return 0; - } + return 0; + } - public boolean isStatic() { - return this.isStatic; - } + public boolean isStatic() { + return this.isStatic; + } - public Building getBuilding() { - return this.building; - } + public Building getBuilding() { + return this.building; + } - public void setBuilding(Building value) { - this.building = value; - } + public void setBuilding(Building value) { + this.building = value; + } - @Override - public String getFirstName() { - return this.name; - } + @Override + public String getFirstName() { + return this.name; + } - @Override - public String getName() { - return this.name; - } + @Override + public String getName() { + return this.name; + } - public void setName(String value) { - this.name = value; - } - - @Override - public String getLastName() { - return ""; - } - - @Override - public Vector3fImmutable getBindLoc() { - return this.bindLoc; - } - - @Override - public int getGuildUUID() { - - if (this.guild == null) - return 0; - - return this.guild.getObjectUUID(); - } - - public void removeMinions() { + public void setName(String value) { + this.name = value; + } + + @Override + public String getLastName() { + return ""; + } + + @Override + public Vector3fImmutable getBindLoc() { + return this.bindLoc; + } + + @Override + public int getGuildUUID() { + + if (this.guild == null) + return 0; + + return this.guild.getObjectUUID(); + } + + public void removeMinions() { - for (Mob toRemove : this.siegeMinionMap.keySet()) { + for (Mob toRemove : this.siegeMinionMap.keySet()) { - try { - toRemove.clearEffects(); - } catch (Exception e) { - Logger.error(e.getMessage()); - } + try { + toRemove.clearEffects(); + } catch (Exception e) { + Logger.error(e.getMessage()); + } - if (toRemove.getParentZone() != null) - toRemove.getParentZone().zoneMobSet.remove(toRemove); + if (toRemove.getParentZone() != null) + toRemove.getParentZone().zoneMobSet.remove(toRemove); - WorldGrid.RemoveWorldObject(toRemove); - DbManager.removeFromCache(toRemove); + WorldGrid.RemoveWorldObject(toRemove); + DbManager.removeFromCache(toRemove); - PlayerCharacter petOwner = toRemove.getOwner(); + PlayerCharacter petOwner = toRemove.getOwner(); - if (petOwner != null) { + if (petOwner != null) { - petOwner.setPet(null); - toRemove.setOwner(null); + petOwner.setPet(null); + toRemove.setOwner(null); - PetMsg petMsg = new PetMsg(5, null); - Dispatch dispatch = Dispatch.borrow(petOwner, petMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); + PetMsg petMsg = new PetMsg(5, null); + Dispatch dispatch = Dispatch.borrow(petOwner, petMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); - } - } - } + } + } + } - @Override - public float getSpeed() { + @Override + public float getSpeed() { - if (this.isWalk()) - return MBServerStatics.WALKSPEED; - else - return MBServerStatics.RUNSPEED; - } + if (this.isWalk()) + return MBServerStatics.WALKSPEED; + else + return MBServerStatics.RUNSPEED; + } - @Override - public float getPassiveChance(String type, int AttackerLevel, boolean fromCombat) { - //TODO add this later for dodge - return 0f; - } + @Override + public float getPassiveChance(String type, int AttackerLevel, boolean fromCombat) { + //TODO add this later for dodge + return 0f; + } - /** - * @ Kill this Character - */ - @Override - public void killCharacter(AbstractCharacter attacker) { - //TODO Handle Death - killCleanup(); - - //TODO Send death message if needed - } - - @Override - public void killCharacter(String reason) { - //TODO Handle Death - killCleanup(); - - //Orphan inventory so it can be looted - //if (!this.inSafeZone) - if (this.charItemManager != null) - this.charItemManager.orphanInventory(); - - //TODO Send death message if needed - //Question? How would a mob die to water? - } - - private void killCleanup() { - //TODO handle cleanup from death here - - //set so character won't load - this.load = false; - - //Create Corpse and add to world - //Corpse.makeCorpse(this); - //TODO damage equipped items - //TODO cleanup any timers - } - - public Zone getParentZone() { - return this.parentZone; - } - - public int getParentZoneID() { - - if (this.parentZone != null) - return this.parentZone.getObjectUUID(); - - return 0; - } - - @Override - public Vector3fImmutable getLoc() { - - return super.getLoc(); - } - - public float getSpawnX() { - return this.statLat; - } - - public float getSpawnY() { - return this.statAlt; - } - - public float getSpawnZ() { - return this.statLon; - } - - //Sets the relative position to a parent zone - public void setRelPos(Zone zone, float locX, float locY, float locZ) { - - //update ZoneManager's zone building list - if (zone != null) { - if (this.parentZone != null) { - if (zone.getObjectUUID() != this.parentZone.getObjectUUID()) { - this.parentZone.zoneNPCSet.remove(this); - //zone.zoneNPCSet.add(this); - } - } else { - //zone.zoneNPCSet.add(this); - } - } else if (this.parentZone != null) { - this.parentZone.zoneNPCSet.remove(this); - } - - this.statLat = locX; - this.statAlt = locY; - this.statLon = locZ; - this.parentZone = zone; - } - - public float getSellPercent() { - return this.sellPercent; - } - - public float getBuyPercent() { - return this.buyPercent; - } + /** + * @ Kill this Character + */ + @Override + public void killCharacter(AbstractCharacter attacker) { + //TODO Handle Death + killCleanup(); + + //TODO Send death message if needed + } + + @Override + public void killCharacter(String reason) { + //TODO Handle Death + killCleanup(); + + //Orphan inventory so it can be looted + //if (!this.inSafeZone) + if (this.charItemManager != null) + this.charItemManager.orphanInventory(); + + //TODO Send death message if needed + //Question? How would a mob die to water? + } + + private void killCleanup() { + //TODO handle cleanup from death here + + //set so character won't load + this.load = false; + + //Create Corpse and add to world + //Corpse.makeCorpse(this); + //TODO damage equipped items + //TODO cleanup any timers + } + + public Zone getParentZone() { + return this.parentZone; + } + + public int getParentZoneID() { + + if (this.parentZone != null) + return this.parentZone.getObjectUUID(); + + return 0; + } + + @Override + public Vector3fImmutable getLoc() { + + return super.getLoc(); + } + + public float getSpawnX() { + return this.statLat; + } + + public float getSpawnY() { + return this.statAlt; + } + + public float getSpawnZ() { + return this.statLon; + } + + //Sets the relative position to a parent zone + public void setRelPos(Zone zone, float locX, float locY, float locZ) { + + //update ZoneManager's zone building list + if (zone != null) { + if (this.parentZone != null) { + if (zone.getObjectUUID() != this.parentZone.getObjectUUID()) { + this.parentZone.zoneNPCSet.remove(this); + //zone.zoneNPCSet.add(this); + } + } else { + //zone.zoneNPCSet.add(this); + } + } else if (this.parentZone != null) { + this.parentZone.zoneNPCSet.remove(this); + } + + this.statLat = locX; + this.statAlt = locY; + this.statLon = locZ; + this.parentZone = zone; + } + + public float getSellPercent() { + return this.sellPercent; + } + + public float getBuyPercent() { + return this.buyPercent; + } - public void setBuyPercent(float buyPercent) { - this.buyPercent = buyPercent; - } + public void setBuyPercent(float buyPercent) { + this.buyPercent = buyPercent; + } - public float getBuyPercent(PlayerCharacter player) { - if (NPC.GetNPCProfits(this) == null || this.guild == null) - return this.buyPercent; - NPCProfits profits = NPC.GetNPCProfits(this); - if (player.getGuild().equals(this.guild)) - return profits.buyGuild; - if (player.getGuild().getNation().equals(this.guild.getNation())) - return profits.buyNation; + public float getBuyPercent(PlayerCharacter player) { + if (NPC.GetNPCProfits(this) == null || this.guild == null) + return this.buyPercent; + NPCProfits profits = NPC.GetNPCProfits(this); + if (player.getGuild().equals(this.guild)) + return profits.buyGuild; + if (player.getGuild().getNation().equals(this.guild.getNation())) + return profits.buyNation; - return profits.buyNormal; - } + return profits.buyNormal; + } - public float getSellPercent(PlayerCharacter player) { - if (NPC.GetNPCProfits(this) == null || this.guild == null) - return 1 + this.sellPercent; - NPCProfits profits = NPC.GetNPCProfits(this); - if (player.getGuild().equals(this.guild)) - return 1 + profits.sellGuild; - if (player.getGuild().getNation().equals(this.guild.getNation())) - return 1 + profits.sellNation; + public float getSellPercent(PlayerCharacter player) { + if (NPC.GetNPCProfits(this) == null || this.guild == null) + return 1 + this.sellPercent; + NPCProfits profits = NPC.GetNPCProfits(this); + if (player.getGuild().equals(this.guild)) + return 1 + profits.sellGuild; + if (player.getGuild().getNation().equals(this.guild.getNation())) + return 1 + profits.sellNation; - return 1 + profits.sellNormal; - } + return 1 + profits.sellNormal; + } - @Override - public boolean canBeLooted() { - return !this.isAlive(); - } + @Override + public boolean canBeLooted() { + return !this.isAlive(); + } - public ArrayList getModTypeTable() { - return this.modTypeTable; - } + public ArrayList getModTypeTable() { + return this.modTypeTable; + } - @Override - public void updateDatabase() { - DbManager.NPCQueries.updateDatabase(this); - } + @Override + public void updateDatabase() { + DbManager.NPCQueries.updateDatabase(this); + } - public int getSymbol() { - return symbol; - } + public int getSymbol() { + return symbol; + } - public ArrayList getModSuffixTable() { - return modSuffixTable; - } - - public ArrayList getItemModTable() { - return itemModTable; - } - - public boolean isRanking() { - - return this.upgradeDateTime != null; - } - - @Override - public void runAfterLoad() { - - if (ConfigManager.serverType.equals(ServerType.LOGINSERVER)) - return; - - try { - - this.equip = loadEquipmentSet(this.equipmentSetID); - - } catch (Exception e) { - Logger.error(e.getMessage()); - } - - if (this.equip == null) - this.equip = new HashMap<>(); - - try { - - DbManager.NPCQueries.LOAD_ALL_ITEMS_TO_PRODUCE(this); - - for (ProducedItem producedItem : this.forgedItems) { - MobLoot ml = new MobLoot(this, ItemBase.getItemBase(producedItem.getItemBaseID()), false); - - DbManager.NPCQueries.UPDATE_ITEM_ID(producedItem.getID(), currentID, ml.getObjectUUID()); - - if (producedItem.isInForge()) { - - if (producedItem.getPrefix() != null && !producedItem.getPrefix().isEmpty()) { - ml.addPermanentEnchantment(producedItem.getPrefix(), 0, 0, true); - ml.setPrefix(producedItem.getPrefix()); - } + public ArrayList getModSuffixTable() { + return modSuffixTable; + } + + public ArrayList getItemModTable() { + return itemModTable; + } + + public boolean isRanking() { + + return this.upgradeDateTime != null; + } + + @Override + public void runAfterLoad() { + + if (ConfigManager.serverType.equals(ServerType.LOGINSERVER)) + return; + + try { + + this.equip = loadEquipmentSet(this.equipmentSetID); + + } catch (Exception e) { + Logger.error(e.getMessage()); + } + + if (this.equip == null) + this.equip = new HashMap<>(); + + try { + + DbManager.NPCQueries.LOAD_ALL_ITEMS_TO_PRODUCE(this); + + for (ProducedItem producedItem : this.forgedItems) { + MobLoot ml = new MobLoot(this, ItemBase.getItemBase(producedItem.getItemBaseID()), false); + + DbManager.NPCQueries.UPDATE_ITEM_ID(producedItem.getID(), currentID, ml.getObjectUUID()); + + if (producedItem.isInForge()) { + + if (producedItem.getPrefix() != null && !producedItem.getPrefix().isEmpty()) { + ml.addPermanentEnchantment(producedItem.getPrefix(), 0, 0, true); + ml.setPrefix(producedItem.getPrefix()); + } - if (producedItem.getSuffix() != null && !producedItem.getSuffix().isEmpty()) { - ml.addPermanentEnchantment(producedItem.getSuffix(), 0, 0, false); - ml.setSuffix(producedItem.getSuffix()); - } + if (producedItem.getSuffix() != null && !producedItem.getSuffix().isEmpty()) { + ml.addPermanentEnchantment(producedItem.getSuffix(), 0, 0, false); + ml.setSuffix(producedItem.getSuffix()); + } - if (!producedItem.isRandom()) - ml.setIsID(true); + if (!producedItem.isRandom()) + ml.setIsID(true); - ml.loadEnchantments(); + ml.loadEnchantments(); - ml.setValue(producedItem.getValue()); - ml.setDateToUpgrade(producedItem.getDateToUpgrade().getMillis()); - ml.containerType = Enum.ItemContainerType.FORGE; - this.addItemToForge(ml); + ml.setValue(producedItem.getValue()); + ml.setDateToUpgrade(producedItem.getDateToUpgrade().getMillis()); + ml.containerType = Enum.ItemContainerType.FORGE; + this.addItemToForge(ml); - } else { + } else { - if (producedItem.getPrefix() != null && !producedItem.getPrefix().isEmpty()) { - ml.addPermanentEnchantment(producedItem.getPrefix(), 0, 0, true); - ml.setPrefix(producedItem.getPrefix()); - } + if (producedItem.getPrefix() != null && !producedItem.getPrefix().isEmpty()) { + ml.addPermanentEnchantment(producedItem.getPrefix(), 0, 0, true); + ml.setPrefix(producedItem.getPrefix()); + } - if (producedItem.getSuffix() != null && !producedItem.getSuffix().isEmpty()) { - ml.addPermanentEnchantment(producedItem.getSuffix(), 0, 0, false); - ml.setSuffix(producedItem.getSuffix()); - } + if (producedItem.getSuffix() != null && !producedItem.getSuffix().isEmpty()) { + ml.addPermanentEnchantment(producedItem.getSuffix(), 0, 0, false); + ml.setSuffix(producedItem.getSuffix()); + } - ml.setDateToUpgrade(producedItem.getDateToUpgrade().getMillis()); - ml.containerType = Enum.ItemContainerType.INVENTORY; - ml.setIsID(true); + ml.setDateToUpgrade(producedItem.getDateToUpgrade().getMillis()); + ml.containerType = Enum.ItemContainerType.INVENTORY; + ml.setIsID(true); - this.charItemManager.addItemToInventory(ml); - } - ml.setValue(producedItem.getValue()); - } + this.charItemManager.addItemToInventory(ml); + } + ml.setValue(producedItem.getValue()); + } - // Create NPC bounds object - Bounds npcBounds = Bounds.borrow(); - npcBounds.setBounds(this.getLoc()); + // Create NPC bounds object + Bounds npcBounds = Bounds.borrow(); + npcBounds.setBounds(this.getLoc()); - } catch (Exception e) { - Logger.error(e.getMessage()); - } - } + } catch (Exception e) { + Logger.error(e.getMessage()); + } + } - public void removeFromZone() { - this.parentZone.zoneNPCSet.remove(this); - } + public void removeFromZone() { + this.parentZone.zoneNPCSet.remove(this); + } - @Override - protected ConcurrentHashMap initializePowers() { - return new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - } + @Override + protected ConcurrentHashMap initializePowers() { + return new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + } - public DateTime getUpgradeDateTime() { - lock.readLock().lock(); - try { - return upgradeDateTime; - } finally { - lock.readLock().unlock(); - } - } + public DateTime getUpgradeDateTime() { + lock.readLock().lock(); + try { + return upgradeDateTime; + } finally { + lock.readLock().unlock(); + } + } - public void setUpgradeDateTime(DateTime upgradeDateTime) { + public void setUpgradeDateTime(DateTime upgradeDateTime) { - if (!DbManager.NPCQueries.updateUpgradeTime(this, upgradeDateTime)) { - Logger.error("Failed to set upgradeTime for building " + currentID); - return; - } + if (!DbManager.NPCQueries.updateUpgradeTime(this, upgradeDateTime)) { + Logger.error("Failed to set upgradeTime for building " + currentID); + return; + } - this.upgradeDateTime = upgradeDateTime; - } + this.upgradeDateTime = upgradeDateTime; + } - public ArrayList getRolling() { - synchronized (rolling) { - return rolling; - } - } + public ArrayList getRolling() { + synchronized (rolling) { + return rolling; + } + } - public int getRollingCount() { - synchronized (this.rolling) { - return rolling.size(); - } - } + public int getRollingCount() { + synchronized (this.rolling) { + return rolling.size(); + } + } - public void addItemToForge(MobLoot item) { - synchronized (this.rolling) { - this.rolling.add(item); - } - } + public void addItemToForge(MobLoot item) { + synchronized (this.rolling) { + this.rolling.add(item); + } + } - public void removeItemFromForge(Item item) { - synchronized (this.rolling) { - this.rolling.remove(item); - } - } + public void removeItemFromForge(Item item) { + synchronized (this.rolling) { + this.rolling.remove(item); + } + } - public ArrayList getProtectedBuildings() { + public ArrayList getProtectedBuildings() { - ArrayList protectedBuildings = new ArrayList<>(); + ArrayList protectedBuildings = new ArrayList<>(); - if (this.building == null) - return protectedBuildings; + if (this.building == null) + return protectedBuildings; - if (this.building.getCity() == null) - return protectedBuildings; + if (this.building.getCity() == null) + return protectedBuildings; - for (Building b : this.building.getCity().getParent().zoneBuildingSet) { + for (Building b : this.building.getCity().getParent().zoneBuildingSet) { - if (b.getBlueprint() == null) - continue; + if (b.getBlueprint() == null) + continue; - if (b.getProtectionState().equals(ProtectionState.CONTRACT)) - protectedBuildings.add(b); + if (b.getProtectionState().equals(ProtectionState.CONTRACT)) + protectedBuildings.add(b); - if (b.getProtectionState().equals(ProtectionState.PENDING)) - protectedBuildings.add(b); - } + if (b.getProtectionState().equals(ProtectionState.PENDING)) + protectedBuildings.add(b); + } - return protectedBuildings; - } + return protectedBuildings; + } - @Override - public Guild getGuild() { - if (this.building != null) - return building.getGuild(); - return this.guild; - } + @Override + public Guild getGuild() { + if (this.building != null) + return building.getGuild(); + return this.guild; + } - // Method removes the npc from the game simulation - // and deletes it from the database. + // Method removes the npc from the game simulation + // and deletes it from the database. - public ArrayList getSiegeMinions() { - return siegeMinions; - } + public ArrayList getSiegeMinions() { + return siegeMinions; + } - public HashSet getCanRoll() { + public HashSet getCanRoll() { - if (this.canRoll == null) { - this.canRoll = DbManager.ItemQueries.GET_ITEMS_FOR_VENDOR(this.vendorID); + if (this.canRoll == null) { + this.canRoll = DbManager.ItemQueries.GET_ITEMS_FOR_VENDOR(this.vendorID); - if (this.contract.getVendorID() == 102) { + if (this.contract.getVendorID() == 102) { - for (int i = 0; i < this.getRank(); i++) { - int subID = i + 1; - this.canRoll.add(910010 + subID); - } + for (int i = 0; i < this.getRank(); i++) { + int subID = i + 1; + this.canRoll.add(910010 + subID); + } - if (this.getRank() == 7) - this.canRoll.add(910018); - } - } + if (this.getRank() == 7) + this.canRoll.add(910018); + } + } - return this.canRoll; - } + return this.canRoll; + } - public int getRollingTimeInSeconds(int itemID) { + public int getRollingTimeInSeconds(int itemID) { - ItemBase ib = ItemBase.getItemBase(itemID); + ItemBase ib = ItemBase.getItemBase(itemID); - if (ib == null) - return 0; + if (ib == null) + return 0; - if (ib.getType() == ItemType.SCROLL) - return this.getRank() * 60 * 60 * 3; + if (ib.getType() == ItemType.SCROLL) + return this.getRank() * 60 * 60 * 3; - float time; + float time; - if (this.building == null) - return 600; + if (this.building == null) + return 600; - float rank = this.building.getRank() - 1; - float rate = (float) (2.5 * rank); - time = (20 - rate); - time *= 60; - return (int) time; - } + float rank = this.building.getRank() - 1; + float rate = (float) (2.5 * rank); + time = (20 - rate); + time *= 60; + return (int) time; + } - public ConcurrentHashMap getSiegeMinionMap() { - return siegeMinionMap; - } + public ConcurrentHashMap getSiegeMinionMap() { + return siegeMinionMap; + } - public boolean remove() { + public boolean remove() { - Building building; + Building building; - // Remove npc from it's building + // Remove npc from it's building - building = this.building; + building = this.building; - if (building != null) { - building.getHirelings().remove(this); - this.removeMinions(); - } + if (building != null) { + building.getHirelings().remove(this); + this.removeMinions(); + } - // Delete npc from database + // Delete npc from database - if (DbManager.NPCQueries.DELETE_NPC(this) == 0) { - return false; - } + if (DbManager.NPCQueries.DELETE_NPC(this) == 0) { + return false; + } - // Remove npc from the simulation + // Remove npc from the simulation - this.removeFromCache(); - WorldGrid.RemoveWorldObject(this); - WorldGrid.removeObject(this); - return true; - } + this.removeFromCache(); + WorldGrid.RemoveWorldObject(this); + WorldGrid.removeObject(this); + return true; + } - public int getUpgradeCost() { + public int getUpgradeCost() { - int upgradeCost; + int upgradeCost; - upgradeCost = Integer.MAX_VALUE; + upgradeCost = Integer.MAX_VALUE; - if (this.getRank() < 7) - return (this.getRank() * 100650) + 21450; + if (this.getRank() < 7) + return (this.getRank() * 100650) + 21450; - return upgradeCost; - } + return upgradeCost; + } - public int getUpgradeTime() { + public int getUpgradeTime() { - int upgradeTime; // expressed in hours + int upgradeTime; // expressed in hours - upgradeTime = Integer.MAX_VALUE; + upgradeTime = Integer.MAX_VALUE; - if (this.getRank() < 7) - return (this.getRank() * 8); + if (this.getRank() < 7) + return (this.getRank() * 8); - return 0; - } + return 0; + } - public synchronized Item produceItem(int playerID, int amount, boolean isRandom, int pToken, int sToken, String customName, int itemID) { + public synchronized Item produceItem(int playerID, int amount, boolean isRandom, int pToken, int sToken, String customName, int itemID) { - Zone serverZone; - City city; - Item item = null; + Zone serverZone; + City city; + Item item = null; - PlayerCharacter player = null; + PlayerCharacter player = null; - if (playerID != 0) - player = SessionManager.getPlayerCharacterByID(playerID); + if (playerID != 0) + player = SessionManager.getPlayerCharacterByID(playerID); - try { + try { - if (this.getRollingCount() >= this.getRank()) { + if (this.getRollingCount() >= this.getRank()) { - if (player != null) - ChatManager.chatSystemInfo(player, this.getName() + " " + this.getContract().getName() + " slots are full"); + if (player != null) + ChatManager.chatSystemInfo(player, this.getName() + " " + this.getContract().getName() + " slots are full"); - return null; - } + return null; + } - // Cannot roll items without a warehouse. - // Due to the fact fillForge references the - // warehouse and early exits. *** Refactor??? + // Cannot roll items without a warehouse. + // Due to the fact fillForge references the + // warehouse and early exits. *** Refactor??? - serverZone = this.building.getParentZone(); + serverZone = this.building.getParentZone(); - if (serverZone == null) - return null; + if (serverZone == null) + return null; - city = City.GetCityFromCache(serverZone.getPlayerCityUUID()); + city = City.GetCityFromCache(serverZone.getPlayerCityUUID()); - if (city == null) { + if (city == null) { - if (player != null) - ErrorPopupMsg.sendErrorMsg(player, "Could not find city."); // Production denied: This building must be protected to gain access to warehouse resources. + if (player != null) + ErrorPopupMsg.sendErrorMsg(player, "Could not find city."); // Production denied: This building must be protected to gain access to warehouse resources. - return null; - } + return null; + } - if (this.building == null) { + if (this.building == null) { - if (player != null) - ErrorPopupMsg.sendErrorMsg(player, "Could not find building."); // Production denied: This building must be protected to gain ac + if (player != null) + ErrorPopupMsg.sendErrorMsg(player, "Could not find building."); // Production denied: This building must be protected to gain ac - return null; - } + return null; + } - //TODO create Normal Items. + //TODO create Normal Items. - if (amount == 0) - amount = 1; + if (amount == 0) + amount = 1; - if (isRandom) - item = ItemFactory.randomRoll(this, player, amount, itemID); - else - item = ItemFactory.fillForge(this, player, amount, itemID, pToken, sToken, customName); + if (isRandom) + item = ItemFactory.randomRoll(this, player, amount, itemID); + else + item = ItemFactory.fillForge(this, player, amount, itemID, pToken, sToken, customName); - if (item == null) - return null; + if (item == null) + return null; - ItemProductionMsg outMsg = new ItemProductionMsg(this.building, this, item, 8, true); - DispatchMessage.dispatchMsgToInterestArea(this, outMsg, DispatchChannel.SECONDARY, 700, false, false); + ItemProductionMsg outMsg = new ItemProductionMsg(this.building, this, item, 8, true); + DispatchMessage.dispatchMsgToInterestArea(this, outMsg, DispatchChannel.SECONDARY, 700, false, false); - } catch (Exception e) { - Logger.error(e); - } - return item; - } + } catch (Exception e) { + Logger.error(e); + } + return item; + } - public synchronized boolean completeItem(int itemUUID) { + public synchronized boolean completeItem(int itemUUID) { - MobLoot targetItem; + MobLoot targetItem; - try { - targetItem = MobLoot.getFromCache(itemUUID); + try { + targetItem = MobLoot.getFromCache(itemUUID); - if (targetItem == null) - return false; + if (targetItem == null) + return false; - if (!this.getCharItemManager().forgeContains(targetItem, this)) - return false; + if (!this.getCharItemManager().forgeContains(targetItem, this)) + return false; - if (!DbManager.NPCQueries.UPDATE_ITEM_TO_INVENTORY(targetItem.getObjectUUID(), currentID)) - return false; + if (!DbManager.NPCQueries.UPDATE_ITEM_TO_INVENTORY(targetItem.getObjectUUID(), currentID)) + return false; - targetItem.setIsID(true); + targetItem.setIsID(true); - this.rolling.remove(targetItem); - this.getCharItemManager().addItemToInventory(targetItem); + this.rolling.remove(targetItem); + this.getCharItemManager().addItemToInventory(targetItem); - //remove from client forge window + //remove from client forge window - ItemProductionMsg outMsg1 = new ItemProductionMsg(this.building, this, targetItem, 9, true); - DispatchMessage.dispatchMsgToInterestArea(this, outMsg1, DispatchChannel.SECONDARY, MBServerStatics.STRUCTURE_LOAD_RANGE, false, false); - ItemProductionMsg outMsg = new ItemProductionMsg(this.building, this, targetItem, 10, true); - DispatchMessage.dispatchMsgToInterestArea(this, outMsg, DispatchChannel.SECONDARY, MBServerStatics.STRUCTURE_LOAD_RANGE, false, false); + ItemProductionMsg outMsg1 = new ItemProductionMsg(this.building, this, targetItem, 9, true); + DispatchMessage.dispatchMsgToInterestArea(this, outMsg1, DispatchChannel.SECONDARY, MBServerStatics.STRUCTURE_LOAD_RANGE, false, false); + ItemProductionMsg outMsg = new ItemProductionMsg(this.building, this, targetItem, 10, true); + DispatchMessage.dispatchMsgToInterestArea(this, outMsg, DispatchChannel.SECONDARY, MBServerStatics.STRUCTURE_LOAD_RANGE, false, false); - } catch (Exception e) { - Logger.error(e.getMessage()); - } - return true; - } + } catch (Exception e) { + Logger.error(e.getMessage()); + } + return true; + } - public HashMap getEquip() { - return equip; - } + public HashMap getEquip() { + return equip; + } - public int getEquipmentSetID() { - return equipmentSetID; - } + public int getEquipmentSetID() { + return equipmentSetID; + } - public String getNameOverride() { - return name; - } + public String getNameOverride() { + return name; + } - public int getRepairCost() { - return repairCost; - } + public int getRepairCost() { + return repairCost; + } - public void setRepairCost(int repairCost) { - this.repairCost = repairCost; - } + public void setRepairCost(int repairCost) { + this.repairCost = repairCost; + } - public void processUpgradeNPC(PlayerCharacter player) { + public void processUpgradeNPC(PlayerCharacter player) { - int rankCost; - Building building; - DateTime dateToUpgrade; + int rankCost; + Building building; + DateTime dateToUpgrade; - this.lock.writeLock().lock(); - try { + this.lock.writeLock().lock(); + try { - building = this.getBuilding(); + building = this.getBuilding(); - // Cannot upgrade an npc not within a building + // Cannot upgrade an npc not within a building - if (building == null) - return; + if (building == null) + return; - // Cannot upgrade an npc at max rank + // Cannot upgrade an npc at max rank - if (this.getRank() == 7) - return; + if (this.getRank() == 7) + return; - // Cannot upgrade an npc who is currently ranking + // Cannot upgrade an npc who is currently ranking - if (this.isRanking()) - return; + if (this.isRanking()) + return; - rankCost = this.getUpgradeCost(); + rankCost = this.getUpgradeCost(); - // SEND NOT ENOUGH GOLD ERROR + // SEND NOT ENOUGH GOLD ERROR - if (!building.hasFunds(rankCost)) { - sendErrorPopup(player, 127); - return; - } + if (!building.hasFunds(rankCost)) { + sendErrorPopup(player, 127); + return; + } - if (rankCost > building.getStrongboxValue()) { - sendErrorPopup(player, 127); - return; - } + if (rankCost > building.getStrongboxValue()) { + sendErrorPopup(player, 127); + return; + } - try { + try { - if (!building.transferGold(-rankCost, false)) - return; + if (!building.transferGold(-rankCost, false)) + return; - dateToUpgrade = DateTime.now().plusHours(this.getUpgradeTime()); + dateToUpgrade = DateTime.now().plusHours(this.getUpgradeTime()); - this.setUpgradeDateTime(dateToUpgrade); + this.setUpgradeDateTime(dateToUpgrade); - // Schedule upgrade job + // Schedule upgrade job - this.submitUpgradeJob(); + this.submitUpgradeJob(); - } catch (Exception e) { - PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - } - } catch (Exception e) { - Logger.error(e); - } finally { - this.lock.writeLock().unlock(); - } - } + } catch (Exception e) { + PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); + } + } catch (Exception e) { + Logger.error(e); + } finally { + this.lock.writeLock().unlock(); + } + } } diff --git a/src/engine/objects/NPCProfits.java b/src/engine/objects/NPCProfits.java index c96ac55b..280be130 100644 --- a/src/engine/objects/NPCProfits.java +++ b/src/engine/objects/NPCProfits.java @@ -16,91 +16,86 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.HashMap; -public class NPCProfits { - - - public int npcUID; - public float buyNormal; - public float buyGuild; - public float buyNation; - public float sellNormal; - public float sellGuild; - public float sellNation; - - public static NPCProfits defaultProfits = new NPCProfits(0,.33f,.33f,.33f,1,1,1); - - - - - public static HashMap ProfitCache = new HashMap<>(); - - /** - * ResultSet Constructor - */ - - public NPCProfits(ResultSet rs) throws SQLException { - - npcUID = rs.getInt("npcUID"); - buyNormal = rs.getFloat("buy_normal"); - buyGuild = rs.getFloat("buy_guild"); - buyNation = rs.getFloat("buy_nation"); - sellNormal = rs.getFloat("sell_normal"); - sellGuild = rs.getFloat("sell_guild"); - sellNation = rs.getFloat("sell_nation"); - - } - - public NPCProfits(int npcUID, float buyNormal, float buyGuild, float buyNation, float sellNormal, - float sellGuild, float sellNation) { - super(); - this.npcUID = npcUID; - this.buyNormal = buyNormal; - this.buyGuild = buyGuild; - this.buyNation = buyNation; - this.sellNormal = sellNormal; - this.sellGuild = sellGuild; - this.sellNation = sellNation; - } - - public static boolean UpdateProfits(NPC npc, NPCProfits profit, ProfitType profitType, float value){ - - try { - if (!DbManager.NPCQueries.UPDATE_PROFITS(npc, profitType, value)) - return false; - }catch(Exception e){ - e.printStackTrace(); - } - - switch (profitType){ - case BuyNormal: - profit.buyNormal = value; - break; - case BuyGuild: - profit.buyGuild = value; - break; - case BuyNation: - profit.buyNation = value; - break; - case SellNormal: - profit.sellNormal = value; - break; - case SellGuild: - profit.sellGuild = value; - break; - case SellNation: - profit.sellNation = value; - break; - - } - return true; - } - - - public static boolean CreateProfits(NPC npc){ - DbManager.NPCQueries.CREATE_PROFITS(npc); - NPCProfits profits = new NPCProfits(npc.getObjectUUID(),.33f,.33f,.33f,1,1,1); - NPCProfits.ProfitCache.put(npc.getObjectUUID(), profits); - return true; - } - +public class NPCProfits { + + + public static NPCProfits defaultProfits = new NPCProfits(0, .33f, .33f, .33f, 1, 1, 1); + public static HashMap ProfitCache = new HashMap<>(); + public int npcUID; + public float buyNormal; + public float buyGuild; + public float buyNation; + public float sellNormal; + public float sellGuild; + public float sellNation; + + /** + * ResultSet Constructor + */ + + public NPCProfits(ResultSet rs) throws SQLException { + + npcUID = rs.getInt("npcUID"); + buyNormal = rs.getFloat("buy_normal"); + buyGuild = rs.getFloat("buy_guild"); + buyNation = rs.getFloat("buy_nation"); + sellNormal = rs.getFloat("sell_normal"); + sellGuild = rs.getFloat("sell_guild"); + sellNation = rs.getFloat("sell_nation"); + + } + + public NPCProfits(int npcUID, float buyNormal, float buyGuild, float buyNation, float sellNormal, + float sellGuild, float sellNation) { + super(); + this.npcUID = npcUID; + this.buyNormal = buyNormal; + this.buyGuild = buyGuild; + this.buyNation = buyNation; + this.sellNormal = sellNormal; + this.sellGuild = sellGuild; + this.sellNation = sellNation; + } + + public static boolean UpdateProfits(NPC npc, NPCProfits profit, ProfitType profitType, float value) { + + try { + if (!DbManager.NPCQueries.UPDATE_PROFITS(npc, profitType, value)) + return false; + } catch (Exception e) { + e.printStackTrace(); + } + + switch (profitType) { + case BuyNormal: + profit.buyNormal = value; + break; + case BuyGuild: + profit.buyGuild = value; + break; + case BuyNation: + profit.buyNation = value; + break; + case SellNormal: + profit.sellNormal = value; + break; + case SellGuild: + profit.sellGuild = value; + break; + case SellNation: + profit.sellNation = value; + break; + + } + return true; + } + + + public static boolean CreateProfits(NPC npc) { + DbManager.NPCQueries.CREATE_PROFITS(npc); + NPCProfits profits = new NPCProfits(npc.getObjectUUID(), .33f, .33f, .33f, 1, 1, 1); + NPCProfits.ProfitCache.put(npc.getObjectUUID(), profits); + return true; + } + } diff --git a/src/engine/objects/NPCRune.java b/src/engine/objects/NPCRune.java index 9f4ad3fb..ed17749d 100644 --- a/src/engine/objects/NPCRune.java +++ b/src/engine/objects/NPCRune.java @@ -20,100 +20,101 @@ import java.util.ArrayList; public class NPCRune extends AbstractGameObject { - private final RuneBase runeBase; - private final int player; - private final ArrayList skillsGranted; - private final ArrayList effectsGranted; - - /** - * No Table ID Constructor - */ - public NPCRune(RuneBase runeBase, int characterID) { - super(); - this.runeBase = runeBase; - this.player = characterID; - if (this.runeBase != null) - this.skillsGranted = DbManager.SkillReqQueries.GET_REQS_FOR_RUNE(this.runeBase.getObjectUUID()); - else - this.skillsGranted = new ArrayList<>(); - this.effectsGranted = new ArrayList<>(); - } - - /** - * Normal Constructor - */ - public NPCRune(RuneBase runeBase, int characterID, int newUUID) { - super(newUUID); - this.runeBase = runeBase; - this.player = characterID; - if (this.runeBase == null) - this.skillsGranted = DbManager.SkillReqQueries.GET_REQS_FOR_RUNE(this.runeBase.getObjectUUID()); - else - this.skillsGranted = new ArrayList<>(); - this.effectsGranted = new ArrayList<>(); - } - /** - * ResultSet Constructor - */ - public NPCRune(ResultSet rs) throws SQLException { - super(rs); - - this.runeBase = RuneBase.getRuneBase(rs.getInt("RuneBaseID")); - this.player = rs.getInt("NpcID"); - if (this.runeBase != null) { - this.skillsGranted = DbManager.SkillReqQueries.GET_REQS_FOR_RUNE(this.runeBase.getObjectUUID()); - this.effectsGranted = DbManager.RuneBaseEffectQueries.GET_EFFECTS_FOR_RUNEBASE(this.runeBase.getObjectUUID()); - } else { - Logger.error("Failed to find RuneBase for NPCRune " + this.getObjectUUID()); - this.skillsGranted = new ArrayList<>(); - this.effectsGranted = new ArrayList<>(); - } - } - - /* - * Getters - */ - public RuneBase getRuneBase() { - return this.runeBase; - } - - public int getRuneBaseID() { - if (this.runeBase != null) - return this.runeBase.getObjectUUID(); - return 0; - } - - public int getPlayerID() { - return this.player; - } - - public ArrayList getSkillsGranted() { - return this.skillsGranted; - } - - public ArrayList getEffectsGranted() { - return this.effectsGranted; - } - - /* - * Serializing - */ - - public static void serializeForClientMsg(NPCRune npcRune,ByteBufferWriter writer) { - if (npcRune.runeBase != null) { - writer.putInt(npcRune.runeBase.getType()); - writer.putInt(0); - writer.putInt(npcRune.runeBase.getObjectUUID()); - writer.putInt(npcRune.getObjectType().ordinal()); - writer.putInt(npcRune.getObjectUUID()); - } else { - for (int i = 0; i < 5; i++) - writer.putInt(0); - } - } - - @Override - public void updateDatabase() { - - } + private final RuneBase runeBase; + private final int player; + private final ArrayList skillsGranted; + private final ArrayList effectsGranted; + + /** + * No Table ID Constructor + */ + public NPCRune(RuneBase runeBase, int characterID) { + super(); + this.runeBase = runeBase; + this.player = characterID; + if (this.runeBase != null) + this.skillsGranted = DbManager.SkillReqQueries.GET_REQS_FOR_RUNE(this.runeBase.getObjectUUID()); + else + this.skillsGranted = new ArrayList<>(); + this.effectsGranted = new ArrayList<>(); + } + + /** + * Normal Constructor + */ + public NPCRune(RuneBase runeBase, int characterID, int newUUID) { + super(newUUID); + this.runeBase = runeBase; + this.player = characterID; + if (this.runeBase == null) + this.skillsGranted = DbManager.SkillReqQueries.GET_REQS_FOR_RUNE(this.runeBase.getObjectUUID()); + else + this.skillsGranted = new ArrayList<>(); + this.effectsGranted = new ArrayList<>(); + } + + /** + * ResultSet Constructor + */ + public NPCRune(ResultSet rs) throws SQLException { + super(rs); + + this.runeBase = RuneBase.getRuneBase(rs.getInt("RuneBaseID")); + this.player = rs.getInt("NpcID"); + if (this.runeBase != null) { + this.skillsGranted = DbManager.SkillReqQueries.GET_REQS_FOR_RUNE(this.runeBase.getObjectUUID()); + this.effectsGranted = DbManager.RuneBaseEffectQueries.GET_EFFECTS_FOR_RUNEBASE(this.runeBase.getObjectUUID()); + } else { + Logger.error("Failed to find RuneBase for NPCRune " + this.getObjectUUID()); + this.skillsGranted = new ArrayList<>(); + this.effectsGranted = new ArrayList<>(); + } + } + + public static void serializeForClientMsg(NPCRune npcRune, ByteBufferWriter writer) { + if (npcRune.runeBase != null) { + writer.putInt(npcRune.runeBase.getType()); + writer.putInt(0); + writer.putInt(npcRune.runeBase.getObjectUUID()); + writer.putInt(npcRune.getObjectType().ordinal()); + writer.putInt(npcRune.getObjectUUID()); + } else { + for (int i = 0; i < 5; i++) + writer.putInt(0); + } + } + + /* + * Getters + */ + public RuneBase getRuneBase() { + return this.runeBase; + } + + public int getRuneBaseID() { + if (this.runeBase != null) + return this.runeBase.getObjectUUID(); + return 0; + } + + public int getPlayerID() { + return this.player; + } + + public ArrayList getSkillsGranted() { + return this.skillsGranted; + } + + /* + * Serializing + */ + + public ArrayList getEffectsGranted() { + return this.effectsGranted; + } + + @Override + public void updateDatabase() { + + } } diff --git a/src/engine/objects/Nation.java b/src/engine/objects/Nation.java index 59b69294..94719e6d 100644 --- a/src/engine/objects/Nation.java +++ b/src/engine/objects/Nation.java @@ -7,7 +7,7 @@ // www.magicbane.com - package engine.objects; +package engine.objects; import engine.net.ByteBufferWriter; @@ -17,105 +17,104 @@ import java.sql.SQLException; public class Nation extends AbstractWorldObject { - private final String name; - private GuildTag gt; - private String motd = ""; - private int primaryGuildID = 0; - - /** - * No Id Constructor - */ - public Nation( String name, GuildTag gt) { - super(); - this.name = name; - this.gt = gt; - } - - /** - * Normal Constructor - */ - public Nation(String name, GuildTag gt, int newUUID) { - super(newUUID); - this.name = name; - this.gt = gt; - } - - /** - * ResultSet Constructor - */ - public Nation(ResultSet rs) throws SQLException { - super(rs); - - this.name = rs.getString("name"); - - this.gt = new GuildTag( rs.getInt("backgroundColor01"), - rs.getInt("backgroundColor02"), - rs.getInt("symbolColor"), - rs.getInt("symbol"), - rs.getInt("backgroundDesign")); - this.motd = rs.getString("motd"); - this.primaryGuildID = rs.getInt("primaryGuild"); - } - - /* - * Getters - */ - @Override - public String getName() { - return this.name; - } - - public GuildTag getGuildTag() { - return this.gt; - } - - public String getMOTD() { - return this.motd; - } - - public void setMOTD(String value) { - this.motd = value; - } - - public int getPrimaryGuildID() { - return this.primaryGuildID; - } - - public void setPrimaryGuildID(int value) { - this.primaryGuildID = value; - } - - /* - * Utils - */ - private static Nation n; - - public static Nation getErrantNation() { - if (n == null) { - n = new Nation("None", GuildTag.ERRANT, 0); - } - return n; - } - - - - /* - * Serialization - */ - - public static void serializeForTrack(Nation nation,ByteBufferWriter writer) { - writer.putInt(nation.getObjectType().ordinal()); - writer.putInt(nation.getObjectUUID()); - writer.put((byte)1); - GuildTag._serializeForDisplay(nation.gt,writer); - } - - - @Override - public void updateDatabase() { - - } - - @Override - public void runAfterLoad() {} + /* + * Utils + */ + private static Nation n; + private final String name; + private GuildTag gt; + private String motd = ""; + private int primaryGuildID = 0; + + /** + * No Id Constructor + */ + public Nation(String name, GuildTag gt) { + super(); + this.name = name; + this.gt = gt; + } + + /** + * Normal Constructor + */ + public Nation(String name, GuildTag gt, int newUUID) { + super(newUUID); + this.name = name; + this.gt = gt; + } + + /** + * ResultSet Constructor + */ + public Nation(ResultSet rs) throws SQLException { + super(rs); + + this.name = rs.getString("name"); + + this.gt = new GuildTag(rs.getInt("backgroundColor01"), + rs.getInt("backgroundColor02"), + rs.getInt("symbolColor"), + rs.getInt("symbol"), + rs.getInt("backgroundDesign")); + this.motd = rs.getString("motd"); + this.primaryGuildID = rs.getInt("primaryGuild"); + } + + public static Nation getErrantNation() { + if (n == null) { + n = new Nation("None", GuildTag.ERRANT, 0); + } + return n; + } + + public static void serializeForTrack(Nation nation, ByteBufferWriter writer) { + writer.putInt(nation.getObjectType().ordinal()); + writer.putInt(nation.getObjectUUID()); + writer.put((byte) 1); + GuildTag._serializeForDisplay(nation.gt, writer); + } + + /* + * Getters + */ + @Override + public String getName() { + return this.name; + } + + public GuildTag getGuildTag() { + return this.gt; + } + + public String getMOTD() { + return this.motd; + } + + public void setMOTD(String value) { + this.motd = value; + } + + public int getPrimaryGuildID() { + return this.primaryGuildID; + } + + + + /* + * Serialization + */ + + public void setPrimaryGuildID(int value) { + this.primaryGuildID = value; + } + + @Override + public void updateDatabase() { + + } + + @Override + public void runAfterLoad() { + } } diff --git a/src/engine/objects/PlayerBonuses.java b/src/engine/objects/PlayerBonuses.java index 60492929..5a8ad2ed 100644 --- a/src/engine/objects/PlayerBonuses.java +++ b/src/engine/objects/PlayerBonuses.java @@ -26,475 +26,466 @@ import java.util.concurrent.ConcurrentHashMap; public class PlayerBonuses { - //First bonus set - private ConcurrentHashMap bonusFloats = new ConcurrentHashMap<>(); - private ConcurrentHashMap bonusDamageShields = new ConcurrentHashMap<>(); - private ConcurrentHashMap bonusStrings = new ConcurrentHashMap<>(); - private ConcurrentHashMap> bonusLists = new ConcurrentHashMap<>(); - private ConcurrentHashMap> bonusBools = new ConcurrentHashMap<>(); - private ConcurrentHashMap skillBonuses = new ConcurrentHashMap<>(); - private ConcurrentHashMap regens = new ConcurrentHashMap<>(); - - //If active == 0 then all gets come from the A list and all puts go to the B list - //If active == 1 then all gets come from the B list and all puts go to the A list - //They alternate each time bonuses are calculated so the one being updated isn't read from. - - - /** - * Generic Constructor - */ - public PlayerBonuses(PlayerCharacter pc) { - } - - public static void InitializeBonuses(PlayerCharacter player){ - if (player.bonuses == null) - return; - if (ConfigManager.serverType.equals(Enum.ServerType.LOGINSERVER)) - return; - - player.bonuses.calculateRuneBaseEffects(player); - } - - public PlayerBonuses(Mob mob) { - clearRuneBaseEffects(); - } - - public static PlayerBonuses grantBonuses(AbstractCharacter ac) { - - if (ac.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) - return new PlayerBonuses((PlayerCharacter)ac); - else if (ac.getObjectType().equals(Enum.GameObjectType.Mob)) - return new PlayerBonuses((Mob)ac); - else - return null; - } - - public void clearRuneBaseEffects() { - - this.bonusBools.clear(); - this.bonusFloats.clear(); - this.bonusStrings.clear(); - this.bonusDamageShields.clear(); - this.bonusLists.clear(); - this.skillBonuses.clear(); - this.regens.put(ModType.HealthRecoverRate, (float) 1); - this.regens.put(ModType.ManaRecoverRate, (float) 1); - this.regens.put(ModType.StaminaRecoverRate, (float) 1); - } - - - - public void calculateRuneBaseEffects(PlayerCharacter pc) { - //Clear everything - clearRuneBaseEffects(); - - //recalculate race - - - if (pc.getRace() != null){ - - - if (pc.getRace().getEffectsList() != null) - for (MobBaseEffects raceEffect: pc.getRace().getEffectsList()){ - EffectsBase eb = PowersManager.getEffectByToken(raceEffect.getToken()); - - if (eb == null) - continue; - if (pc.getLevel() < raceEffect.getReqLvl()) - continue; - for (AbstractEffectModifier modifier: eb.getModifiers()){ - modifier.applyBonus(pc, raceEffect.getRank()); - } - - } - - if (SkillsBase.runeSkillsCache.containsKey(pc.getRaceID())){ - for (int skillToken : SkillsBase.runeSkillsCache.get(pc.getRaceID()).keySet()){ - float amount = SkillsBase.runeSkillsCache.get(pc.getRaceID()).get(skillToken); - - SkillsBase sb = SkillsBase.tokenCache.get(skillToken); - - if (sb == null) - continue; - if (this.skillBonuses.containsKey(sb.sourceType) == false) - this.skillBonuses.put(sb.sourceType, amount); - else - this.skillBonuses.put(sb.sourceType, this.skillBonuses.get(sb.sourceType) + amount); - - } - } - } - - //calculate baseclass effects - if (pc.getBaseClass() != null){ - - if (pc.getBaseClass().getEffectsList() != null) - for (MobBaseEffects classEffect: pc.getBaseClass().getEffectsList()){ - EffectsBase eb = PowersManager.getEffectByToken(classEffect.getToken()); - - if (eb == null) - continue; - if (pc.getLevel() < classEffect.getReqLvl()) - continue; - for (AbstractEffectModifier modifier: eb.getModifiers()){ - modifier.applyBonus(pc, classEffect.getRank()); - } - - } - - if (SkillsBase.runeSkillsCache.containsKey(pc.getBaseClassID())){ - for (int skillToken : SkillsBase.runeSkillsCache.get(pc.getBaseClassID()).keySet()){ - float amount = SkillsBase.runeSkillsCache.get(pc.getBaseClassID()).get(skillToken); - - SkillsBase sb = SkillsBase.tokenCache.get(skillToken); - - if (sb == null) - continue; - if (this.skillBonuses.containsKey(sb.sourceType) == false) - this.skillBonuses.put(sb.sourceType, amount); - else - this.skillBonuses.put(sb.sourceType, this.skillBonuses.get(sb.sourceType) + amount); - } - } - - } - - //calculate promotionClass Effects - if (pc.getPromotionClass() != null){ - if (pc.getPromotionClass().getEffectsList() != null) - for (MobBaseEffects promoEffect: pc.getPromotionClass().getEffectsList()){ - EffectsBase eb = PowersManager.getEffectByToken(promoEffect.getToken()); - - if (eb == null) - continue; - if (pc.getLevel() < promoEffect.getReqLvl()) - continue; - for (AbstractEffectModifier modifier: eb.getModifiers()){ - modifier.applyBonus(pc, promoEffect.getRank()); - } - - } - - if (SkillsBase.runeSkillsCache.containsKey(pc.getPromotionClassID())){ - for (int skillToken : SkillsBase.runeSkillsCache.get(pc.getPromotionClassID()).keySet()){ - float amount = SkillsBase.runeSkillsCache.get(pc.getPromotionClassID()).get(skillToken); - - SkillsBase sb = SkillsBase.tokenCache.get(skillToken); - - if (sb == null) - continue; - if (this.skillBonuses.containsKey(sb.sourceType) == false) - this.skillBonuses.put(sb.sourceType, amount); - else - this.skillBonuses.put(sb.sourceType, this.skillBonuses.get(sb.sourceType) + amount); - - } - } - - } - - for(CharacterRune runes : pc.getRunes()){ - RuneBase characterRune = RuneBase.getRuneBase(runes.getRuneBaseID()); - - if (characterRune.getEffectsList() != null) - for (MobBaseEffects runeEffect: characterRune.getEffectsList()){ - EffectsBase eb = PowersManager.getEffectByToken(runeEffect.getToken()); - - if (eb == null) - continue; - if (pc.getLevel() < runeEffect.getReqLvl()) - continue; - for (AbstractEffectModifier modifier: eb.getModifiers()){ - modifier.applyBonus(pc, runeEffect.getRank()); - } - - } - - if (SkillsBase.runeSkillsCache.containsKey(runes.getRuneBaseID())){ - for (int skillToken : SkillsBase.runeSkillsCache.get(runes.getRuneBaseID()).keySet()){ - float amount = SkillsBase.runeSkillsCache.get(runes.getRuneBaseID()).get(skillToken); - - SkillsBase sb = SkillsBase.tokenCache.get(skillToken); - - if (sb == null) - continue; - if (this.skillBonuses.containsKey(sb.sourceType) == false) - this.skillBonuses.put(sb.sourceType, amount); - else - this.skillBonuses.put(sb.sourceType, this.skillBonuses.get(sb.sourceType) + amount); - - } - } - - } - - //Update seeInvis if needed - - float seeInvis = this.getFloat(ModType.SeeInvisible, SourceType.None); - if (pc.getSeeInvis() < seeInvis) - pc.setSeeInvis((short)seeInvis); - - } - - - public void grantEffect(RuneBaseEffect rbe) { - } - - - public void setFloat(AbstractEffectModifier mod, float val) { - if (val != 0) - this.bonusFloats.put(mod, val); - else - this.bonusFloats.remove(mod); - } - - public void setString(AbstractEffectModifier mod, String val) { - if (!val.isEmpty()) - this.bonusStrings.put(mod, val); - else - this.bonusStrings.remove(mod); - } - - public void setList(ModType mod, HashSet val) { - if (!val.equals(null)) - this.bonusLists.put(mod, val); - else - this.bonusLists.remove(mod); - } - - - - - public void addFloat(AbstractEffectModifier mod, Float val) { - if (this.bonusFloats.containsKey(mod) == false) - this.bonusFloats.put(mod, val); - else - this.bonusFloats.put(mod, this.bonusFloats.get(mod) + val); - } - - public void multFloat(AbstractEffectModifier mod, Float val) { - if (this.bonusFloats.containsKey(mod) == false) - this.bonusFloats.put(mod, val); - else - this.bonusFloats.put(mod,this.bonusFloats.get(mod) + (val * ( this.bonusFloats.get(mod) + val))); - } - - public void multRegen(ModType mod, Float val) { - this.regens.put(mod,this.regens.get(mod) + (this.regens.get(mod) * val)); - } - - - public boolean getBool(ModType modType, SourceType sourceType) { - - if (this.bonusBools.containsKey(modType) == false) - return false; - - if (this.bonusBools.get(modType).containsKey(sourceType) == false) - return false; - - return this.bonusBools.get(modType).get(sourceType); - - } - - public float getSkillBonus(SourceType sourceType) { - - if (this.skillBonuses.containsKey(sourceType) == false) - return 0; - return this.skillBonuses.get(sourceType); - } - - - public float getFloat(ModType modType, SourceType sourceType) { - float amount = 0; - for (AbstractEffectModifier mod : this.bonusFloats.keySet()){ - if (mod.getPercentMod() != 0) - continue; - if (mod.modType.equals(modType) == false || mod.sourceType.equals(sourceType) == false) - continue; - - if (this.bonusFloats.get(mod) == null) - continue; - - amount += this.bonusFloats.get(mod); - } - return amount; - } - - public float getFloatPercentPositive(ModType modType, SourceType sourceType) { - float amount = 0; - for (AbstractEffectModifier mod : this.bonusFloats.keySet()){ - - if (mod.getPercentMod() == 0 && !modType.equals(ModType.AdjustAboveDmgCap)) - continue; - - - if (mod.modType.equals(modType) == false || mod.sourceType.equals(sourceType) == false) - continue; - - - if (this.bonusFloats.get(mod) == null) - continue; - - if (this.bonusFloats.get(mod) < 0) - continue; - amount += this.bonusFloats.get(mod); - } - - return amount; - } - - public float getFloatPercentAll(ModType modType, SourceType sourceType) { - float amount = 0; - for (AbstractEffectModifier mod : this.bonusFloats.keySet()){ - - if (mod.getPercentMod() == 0 && !modType.equals(ModType.AdjustAboveDmgCap)) - continue; - - - if (mod.modType.equals(modType) == false || mod.sourceType.equals(sourceType) == false) - continue; - - if (this.bonusFloats.get(mod) == null) - continue; - - amount += this.bonusFloats.get(mod); - } - - return amount; - } - - public float getRegen(ModType modType) { - return this.regens.get(modType); - } - - - - public float getFloatPercentNullZero(ModType modType, SourceType sourceType) { - float amount = 0; - for (AbstractEffectModifier mod : this.bonusFloats.keySet()){ - - if (mod.getPercentMod() == 0) - continue; - if (mod.modType.equals(modType) == false || mod.sourceType.equals(sourceType) == false) - continue; - - if (this.bonusFloats.get(mod) == null) - continue; - - amount += this.bonusFloats.get(mod); - } - return amount; - } - - public float getFloatPercentNegative(ModType modType, SourceType sourceType) { - float amount = 0; - for (AbstractEffectModifier mod : this.bonusFloats.keySet()){ - - if (mod.getPercentMod() == 0) - continue; - if (mod.modType.equals(modType) == false || mod.sourceType.equals(sourceType) == false) - continue; - - if (this.bonusFloats.get(mod) == null) - continue; - - if (this.bonusFloats.get(mod) > 0) - continue; - - - amount += this.bonusFloats.get(mod); - } - return amount; - } - - - - - - public HashSet getList(ModType modType) { - if (this.bonusLists.containsKey(modType)) - return this.bonusLists.get(modType); - else - return null; - } - - public ConcurrentHashMap getDamageShields() { - return this.bonusDamageShields; - } - - public void addDamageShield(AbstractEffectModifier mod , DamageShield ds) { - this.bonusDamageShields.put(mod, ds); - } - - - - public void updateIfHigher(AbstractEffectModifier mod, Float val) { - - if (this.bonusFloats.containsKey(mod) == false){ - this.bonusFloats.put(mod, val); - return; - } - float oldVal = this.getFloat(mod.modType, mod.sourceType); - - if (oldVal > val) - return; - - this.bonusFloats.put(mod,val); - - } - - - //Read maps - - public void printBonusesToClient(PlayerCharacter pc) { - - - - for (ModType modType: this.bonusBools.keySet()){ - for (SourceType sourceType: this.bonusBools.get(modType).keySet()){ - ChatManager.chatSystemInfo(pc, modType.name() + "-" + sourceType.name() + " = " + this.bonusBools.get(modType).get(sourceType)); - } - } - - for (ModType modType : ModType.values()){ - - if (modType.equals(ModType.StaminaRecoverRate) || modType.equals(ModType.HealthRecoverRate) || modType.equals(ModType.ManaRecoverRate)) - ChatManager.chatSystemInfo(pc, modType.name() + " = " + this.getRegen(modType)); - else - for (SourceType sourceType : SourceType.values()){ - float amount = this.getFloat(modType, sourceType); - float percentAmount = this.getFloatPercentPositive(modType, sourceType); - float percentAmountNegative = this.getFloatPercentNegative(modType, sourceType); - - if (amount != 0) - ChatManager.chatSystemInfo(pc, modType.name() + "-" + (sourceType.equals(SourceType.None) == false ? sourceType.name() : "") + " = " + amount); - - if (percentAmount != 0) - ChatManager.chatSystemInfo(pc, "Percent : " + modType.name() + "-" + (sourceType.equals(SourceType.None) == false ? sourceType.name() : "") + " = " + percentAmount); - - if (percentAmountNegative != 0) - ChatManager.chatSystemInfo(pc, "Negative Percent : " + modType.name() + "-" + (sourceType.equals(SourceType.None) == false ? sourceType.name() : "") + " = " + percentAmountNegative); - - } - } - - } - - - public void setBool(ModType modType, SourceType sourceType , boolean val) { - if (val == true){ - - if (this.bonusBools.get(modType) == null){ - HashMap sourceMap = new HashMap<>(); - this.bonusBools.put(modType, sourceMap); - } - - this.bonusBools.get(modType).put(sourceType, val); - return; - } - - if (this.bonusBools.containsKey(modType)) - this.bonusBools.get(modType).remove(sourceType); - } - + //First bonus set + private ConcurrentHashMap bonusFloats = new ConcurrentHashMap<>(); + private ConcurrentHashMap bonusDamageShields = new ConcurrentHashMap<>(); + private ConcurrentHashMap bonusStrings = new ConcurrentHashMap<>(); + private ConcurrentHashMap> bonusLists = new ConcurrentHashMap<>(); + private ConcurrentHashMap> bonusBools = new ConcurrentHashMap<>(); + private ConcurrentHashMap skillBonuses = new ConcurrentHashMap<>(); + private ConcurrentHashMap regens = new ConcurrentHashMap<>(); + + //If active == 0 then all gets come from the A list and all puts go to the B list + //If active == 1 then all gets come from the B list and all puts go to the A list + //They alternate each time bonuses are calculated so the one being updated isn't read from. + + + /** + * Generic Constructor + */ + public PlayerBonuses(PlayerCharacter pc) { + } + + public PlayerBonuses(Mob mob) { + clearRuneBaseEffects(); + } + + public static void InitializeBonuses(PlayerCharacter player) { + if (player.bonuses == null) + return; + if (ConfigManager.serverType.equals(Enum.ServerType.LOGINSERVER)) + return; + + player.bonuses.calculateRuneBaseEffects(player); + } + + public static PlayerBonuses grantBonuses(AbstractCharacter ac) { + + if (ac.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) + return new PlayerBonuses((PlayerCharacter) ac); + else if (ac.getObjectType().equals(Enum.GameObjectType.Mob)) + return new PlayerBonuses((Mob) ac); + else + return null; + } + + public void clearRuneBaseEffects() { + + this.bonusBools.clear(); + this.bonusFloats.clear(); + this.bonusStrings.clear(); + this.bonusDamageShields.clear(); + this.bonusLists.clear(); + this.skillBonuses.clear(); + this.regens.put(ModType.HealthRecoverRate, (float) 1); + this.regens.put(ModType.ManaRecoverRate, (float) 1); + this.regens.put(ModType.StaminaRecoverRate, (float) 1); + } + + + public void calculateRuneBaseEffects(PlayerCharacter pc) { + //Clear everything + clearRuneBaseEffects(); + + //recalculate race + + + if (pc.getRace() != null) { + + + if (pc.getRace().getEffectsList() != null) + for (MobBaseEffects raceEffect : pc.getRace().getEffectsList()) { + EffectsBase eb = PowersManager.getEffectByToken(raceEffect.getToken()); + + if (eb == null) + continue; + if (pc.getLevel() < raceEffect.getReqLvl()) + continue; + for (AbstractEffectModifier modifier : eb.getModifiers()) { + modifier.applyBonus(pc, raceEffect.getRank()); + } + + } + + if (SkillsBase.runeSkillsCache.containsKey(pc.getRaceID())) { + for (int skillToken : SkillsBase.runeSkillsCache.get(pc.getRaceID()).keySet()) { + float amount = SkillsBase.runeSkillsCache.get(pc.getRaceID()).get(skillToken); + + SkillsBase sb = SkillsBase.tokenCache.get(skillToken); + + if (sb == null) + continue; + if (this.skillBonuses.containsKey(sb.sourceType) == false) + this.skillBonuses.put(sb.sourceType, amount); + else + this.skillBonuses.put(sb.sourceType, this.skillBonuses.get(sb.sourceType) + amount); + + } + } + } + + //calculate baseclass effects + if (pc.getBaseClass() != null) { + + if (pc.getBaseClass().getEffectsList() != null) + for (MobBaseEffects classEffect : pc.getBaseClass().getEffectsList()) { + EffectsBase eb = PowersManager.getEffectByToken(classEffect.getToken()); + + if (eb == null) + continue; + if (pc.getLevel() < classEffect.getReqLvl()) + continue; + for (AbstractEffectModifier modifier : eb.getModifiers()) { + modifier.applyBonus(pc, classEffect.getRank()); + } + + } + + if (SkillsBase.runeSkillsCache.containsKey(pc.getBaseClassID())) { + for (int skillToken : SkillsBase.runeSkillsCache.get(pc.getBaseClassID()).keySet()) { + float amount = SkillsBase.runeSkillsCache.get(pc.getBaseClassID()).get(skillToken); + + SkillsBase sb = SkillsBase.tokenCache.get(skillToken); + + if (sb == null) + continue; + if (this.skillBonuses.containsKey(sb.sourceType) == false) + this.skillBonuses.put(sb.sourceType, amount); + else + this.skillBonuses.put(sb.sourceType, this.skillBonuses.get(sb.sourceType) + amount); + } + } + + } + + //calculate promotionClass Effects + if (pc.getPromotionClass() != null) { + if (pc.getPromotionClass().getEffectsList() != null) + for (MobBaseEffects promoEffect : pc.getPromotionClass().getEffectsList()) { + EffectsBase eb = PowersManager.getEffectByToken(promoEffect.getToken()); + + if (eb == null) + continue; + if (pc.getLevel() < promoEffect.getReqLvl()) + continue; + for (AbstractEffectModifier modifier : eb.getModifiers()) { + modifier.applyBonus(pc, promoEffect.getRank()); + } + + } + + if (SkillsBase.runeSkillsCache.containsKey(pc.getPromotionClassID())) { + for (int skillToken : SkillsBase.runeSkillsCache.get(pc.getPromotionClassID()).keySet()) { + float amount = SkillsBase.runeSkillsCache.get(pc.getPromotionClassID()).get(skillToken); + + SkillsBase sb = SkillsBase.tokenCache.get(skillToken); + + if (sb == null) + continue; + if (this.skillBonuses.containsKey(sb.sourceType) == false) + this.skillBonuses.put(sb.sourceType, amount); + else + this.skillBonuses.put(sb.sourceType, this.skillBonuses.get(sb.sourceType) + amount); + + } + } + + } + + for (CharacterRune runes : pc.getRunes()) { + RuneBase characterRune = RuneBase.getRuneBase(runes.getRuneBaseID()); + + if (characterRune.getEffectsList() != null) + for (MobBaseEffects runeEffect : characterRune.getEffectsList()) { + EffectsBase eb = PowersManager.getEffectByToken(runeEffect.getToken()); + + if (eb == null) + continue; + if (pc.getLevel() < runeEffect.getReqLvl()) + continue; + for (AbstractEffectModifier modifier : eb.getModifiers()) { + modifier.applyBonus(pc, runeEffect.getRank()); + } + + } + + if (SkillsBase.runeSkillsCache.containsKey(runes.getRuneBaseID())) { + for (int skillToken : SkillsBase.runeSkillsCache.get(runes.getRuneBaseID()).keySet()) { + float amount = SkillsBase.runeSkillsCache.get(runes.getRuneBaseID()).get(skillToken); + + SkillsBase sb = SkillsBase.tokenCache.get(skillToken); + + if (sb == null) + continue; + if (this.skillBonuses.containsKey(sb.sourceType) == false) + this.skillBonuses.put(sb.sourceType, amount); + else + this.skillBonuses.put(sb.sourceType, this.skillBonuses.get(sb.sourceType) + amount); + + } + } + + } + + //Update seeInvis if needed + + float seeInvis = this.getFloat(ModType.SeeInvisible, SourceType.None); + if (pc.getSeeInvis() < seeInvis) + pc.setSeeInvis((short) seeInvis); + + } + + + public void grantEffect(RuneBaseEffect rbe) { + } + + + public void setFloat(AbstractEffectModifier mod, float val) { + if (val != 0) + this.bonusFloats.put(mod, val); + else + this.bonusFloats.remove(mod); + } + + public void setString(AbstractEffectModifier mod, String val) { + if (!val.isEmpty()) + this.bonusStrings.put(mod, val); + else + this.bonusStrings.remove(mod); + } + + public void setList(ModType mod, HashSet val) { + if (!val.equals(null)) + this.bonusLists.put(mod, val); + else + this.bonusLists.remove(mod); + } + + + public void addFloat(AbstractEffectModifier mod, Float val) { + if (this.bonusFloats.containsKey(mod) == false) + this.bonusFloats.put(mod, val); + else + this.bonusFloats.put(mod, this.bonusFloats.get(mod) + val); + } + + public void multFloat(AbstractEffectModifier mod, Float val) { + if (this.bonusFloats.containsKey(mod) == false) + this.bonusFloats.put(mod, val); + else + this.bonusFloats.put(mod, this.bonusFloats.get(mod) + (val * (this.bonusFloats.get(mod) + val))); + } + + public void multRegen(ModType mod, Float val) { + this.regens.put(mod, this.regens.get(mod) + (this.regens.get(mod) * val)); + } + + + public boolean getBool(ModType modType, SourceType sourceType) { + + if (this.bonusBools.containsKey(modType) == false) + return false; + + if (this.bonusBools.get(modType).containsKey(sourceType) == false) + return false; + + return this.bonusBools.get(modType).get(sourceType); + + } + + public float getSkillBonus(SourceType sourceType) { + + if (this.skillBonuses.containsKey(sourceType) == false) + return 0; + return this.skillBonuses.get(sourceType); + } + + + public float getFloat(ModType modType, SourceType sourceType) { + float amount = 0; + for (AbstractEffectModifier mod : this.bonusFloats.keySet()) { + if (mod.getPercentMod() != 0) + continue; + if (mod.modType.equals(modType) == false || mod.sourceType.equals(sourceType) == false) + continue; + + if (this.bonusFloats.get(mod) == null) + continue; + + amount += this.bonusFloats.get(mod); + } + return amount; + } + + public float getFloatPercentPositive(ModType modType, SourceType sourceType) { + float amount = 0; + for (AbstractEffectModifier mod : this.bonusFloats.keySet()) { + + if (mod.getPercentMod() == 0 && !modType.equals(ModType.AdjustAboveDmgCap)) + continue; + + + if (mod.modType.equals(modType) == false || mod.sourceType.equals(sourceType) == false) + continue; + + + if (this.bonusFloats.get(mod) == null) + continue; + + if (this.bonusFloats.get(mod) < 0) + continue; + amount += this.bonusFloats.get(mod); + } + + return amount; + } + + public float getFloatPercentAll(ModType modType, SourceType sourceType) { + float amount = 0; + for (AbstractEffectModifier mod : this.bonusFloats.keySet()) { + + if (mod.getPercentMod() == 0 && !modType.equals(ModType.AdjustAboveDmgCap)) + continue; + + + if (mod.modType.equals(modType) == false || mod.sourceType.equals(sourceType) == false) + continue; + + if (this.bonusFloats.get(mod) == null) + continue; + + amount += this.bonusFloats.get(mod); + } + + return amount; + } + + public float getRegen(ModType modType) { + return this.regens.get(modType); + } + + + public float getFloatPercentNullZero(ModType modType, SourceType sourceType) { + float amount = 0; + for (AbstractEffectModifier mod : this.bonusFloats.keySet()) { + + if (mod.getPercentMod() == 0) + continue; + if (mod.modType.equals(modType) == false || mod.sourceType.equals(sourceType) == false) + continue; + + if (this.bonusFloats.get(mod) == null) + continue; + + amount += this.bonusFloats.get(mod); + } + return amount; + } + + public float getFloatPercentNegative(ModType modType, SourceType sourceType) { + float amount = 0; + for (AbstractEffectModifier mod : this.bonusFloats.keySet()) { + + if (mod.getPercentMod() == 0) + continue; + if (mod.modType.equals(modType) == false || mod.sourceType.equals(sourceType) == false) + continue; + + if (this.bonusFloats.get(mod) == null) + continue; + + if (this.bonusFloats.get(mod) > 0) + continue; + + + amount += this.bonusFloats.get(mod); + } + return amount; + } + + + public HashSet getList(ModType modType) { + if (this.bonusLists.containsKey(modType)) + return this.bonusLists.get(modType); + else + return null; + } + + public ConcurrentHashMap getDamageShields() { + return this.bonusDamageShields; + } + + public void addDamageShield(AbstractEffectModifier mod, DamageShield ds) { + this.bonusDamageShields.put(mod, ds); + } + + + public void updateIfHigher(AbstractEffectModifier mod, Float val) { + + if (this.bonusFloats.containsKey(mod) == false) { + this.bonusFloats.put(mod, val); + return; + } + float oldVal = this.getFloat(mod.modType, mod.sourceType); + + if (oldVal > val) + return; + + this.bonusFloats.put(mod, val); + + } + + + //Read maps + + public void printBonusesToClient(PlayerCharacter pc) { + + + for (ModType modType : this.bonusBools.keySet()) { + for (SourceType sourceType : this.bonusBools.get(modType).keySet()) { + ChatManager.chatSystemInfo(pc, modType.name() + "-" + sourceType.name() + " = " + this.bonusBools.get(modType).get(sourceType)); + } + } + + for (ModType modType : ModType.values()) { + + if (modType.equals(ModType.StaminaRecoverRate) || modType.equals(ModType.HealthRecoverRate) || modType.equals(ModType.ManaRecoverRate)) + ChatManager.chatSystemInfo(pc, modType.name() + " = " + this.getRegen(modType)); + else + for (SourceType sourceType : SourceType.values()) { + float amount = this.getFloat(modType, sourceType); + float percentAmount = this.getFloatPercentPositive(modType, sourceType); + float percentAmountNegative = this.getFloatPercentNegative(modType, sourceType); + + if (amount != 0) + ChatManager.chatSystemInfo(pc, modType.name() + "-" + (sourceType.equals(SourceType.None) == false ? sourceType.name() : "") + " = " + amount); + + if (percentAmount != 0) + ChatManager.chatSystemInfo(pc, "Percent : " + modType.name() + "-" + (sourceType.equals(SourceType.None) == false ? sourceType.name() : "") + " = " + percentAmount); + + if (percentAmountNegative != 0) + ChatManager.chatSystemInfo(pc, "Negative Percent : " + modType.name() + "-" + (sourceType.equals(SourceType.None) == false ? sourceType.name() : "") + " = " + percentAmountNegative); + + } + } + + } + + + public void setBool(ModType modType, SourceType sourceType, boolean val) { + if (val == true) { + + if (this.bonusBools.get(modType) == null) { + HashMap sourceMap = new HashMap<>(); + this.bonusBools.put(modType, sourceMap); + } + + this.bonusBools.get(modType).put(sourceType, val); + return; + } + + if (this.bonusBools.containsKey(modType)) + this.bonusBools.get(modType).remove(sourceType); + } + } diff --git a/src/engine/objects/PlayerCharacter.java b/src/engine/objects/PlayerCharacter.java index 80c8ab3b..41d141fc 100644 --- a/src/engine/objects/PlayerCharacter.java +++ b/src/engine/objects/PlayerCharacter.java @@ -56,2255 +56,682 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; public class PlayerCharacter extends AbstractCharacter { - //This object is to be used as the lock in a synchronized statement - //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(); - - private final Account account; - private final Race race; - private BaseClass baseClass; - private PromotionClass promotionClass; - protected ArrayList runes; - - private final byte skinColor; - private final byte hairColor; - private final byte beardColor; - - private final byte hairStyle; - private final byte beardStyle; - private long channelMute = 0; // none muted. - - //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(); - private final ReadWriteLock teleportLock = new ReentrantReadWriteLock(true); - public final ReadWriteLock respawnLock = new ReentrantReadWriteLock(true); - - private ConcurrentHashMap ignoredPlayerIDs = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - - public boolean notDeleted; // <-Use this for deleting character - - // =========================================== - // Variables NOT to put into the database!!!! (session only) - // =========================================== - public short statStrMax; // Max Base Stats - public short statDexMax; - public short statConMax; - public short statIntMax; - public short statSpiMax; - public short statStrMin; // Min Base Stats - public short statDexMin; - public short statConMin; - public short statIntMin; - public short statSpiMin; - - // Current Stats before Equip and Effect - // Modifiers - public short statStrBase; - public short statDexBase; - public short statConBase; - public short statIntBase; - public short statSpiBase; - public short trainedStatPoints = 0; - - private boolean lfGroup = false; - private boolean lfGuild = false; - private boolean recruiting = false; - private MovementState movementState = MovementState.IDLE; - private MovementState lastMovementState = MovementState.IDLE; - - private int overFlowEXP = 0; - - private int lastGuildToInvite; - private int lastGroupToInvite; - private boolean follow = false; - private final HashMap summoners = new HashMap<>(); - private final HashSet loadedObjects = new HashSet<>(); - private HashSet loadedStaticObjects = new HashSet<>(); - private Vector3fImmutable lastStaticLoc = new Vector3fImmutable(0.0f, 0.0f, 0.0f); - 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 GameObjectType lastTargetType; - 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; - private float raceRunMod; - private boolean teleportMode = false; // Teleport on MoveToPoint - private final AtomicInteger trainsAvailable = new AtomicInteger(0); // num skill trains not used - private float dexPenalty; - private long lastPlayerAttackTime = 0; - private long lastMobAttackTime = 0; - private long lastUsedPowerTime = 0; - private long lastTargetOfUsedPowerTime = 0; - private long lastUpdateTime = System.currentTimeMillis(); - private long lastStamUpdateTime = System.currentTimeMillis(); - private boolean safeZone = false; - public boolean isCSR = false; - private int bindBuildingID; - private int lastContract; - private boolean noTeleScreen = false; - - private int lastRealmID = -2; - private int subRaceID = 0; - - private boolean hasAnniversery = false; - - //TODO Public fields break OO!!! - public boolean newChar; - - private DeferredPowerJob weaponPower; - private NPC lastNPCDialog; - - private Mob pet; - public final ArrayList necroPets = new ArrayList<>(); - //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; - - private boolean canBreathe = true; - /* + //This object is to be used as the lock in a synchronized statement + //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 final ReadWriteLock respawnLock = new ReentrantReadWriteLock(true); + public final ArrayList necroPets = new ArrayList<>(); + private final Account account; + private final Race race; + private final byte skinColor; + private final byte hairColor; + private final byte beardColor; + private final byte hairStyle; + 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(); + 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 boolean notDeleted; // <-Use this for deleting character + // =========================================== + // Variables NOT to put into the database!!!! (session only) + // =========================================== + public short statStrMax; // Max Base Stats + public short statDexMax; + public short statConMax; + public short statIntMax; + public short statSpiMax; + public short statStrMin; // Min Base Stats + public short statDexMin; + public short statConMin; + public short statIntMin; + public short statSpiMin; + // Current Stats before Equip and Effect + // Modifiers + public short statStrBase; + public short statDexBase; + public short statConBase; + public short statIntBase; + public short statSpiBase; + public short trainedStatPoints = 0; + public boolean isCSR = false; + //TODO Public fields break OO!!! + public boolean newChar; + public LinkedList pvpKills; + public LinkedList pvpDeaths; + public int lastBuildingAccessed = 0; + public double timeLoggedIn = 0; + public boolean RUN_MAGICTREK = true; + public int spellsCasted = 0; + public int pingCount = 0; + public long startPing = 0; + public double ping = 0; + public float centerHeight = 0; + public float landingAltitude = 0; + public int bindBuilding = 0; + public FriendStatus friendStatus = FriendStatus.Available; + protected ArrayList runes; + private BaseClass baseClass; + private PromotionClass promotionClass; + private long channelMute = 0; // none muted. + 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 recruiting = false; + private MovementState movementState = MovementState.IDLE; + private MovementState lastMovementState = MovementState.IDLE; + private int overFlowEXP = 0; + private int lastGuildToInvite; + private int lastGroupToInvite; + private boolean follow = false; + private HashSet loadedStaticObjects = new HashSet<>(); + private Vector3fImmutable lastStaticLoc = new Vector3fImmutable(0.0f, 0.0f, 0.0f); + private GameObjectType lastTargetType; + 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; + private float raceRunMod; + private boolean teleportMode = false; // Teleport on MoveToPoint + private float dexPenalty; + private long lastPlayerAttackTime = 0; + private long lastMobAttackTime = 0; + private long lastUsedPowerTime = 0; + private long lastTargetOfUsedPowerTime = 0; + private long lastUpdateTime = System.currentTimeMillis(); + private long lastStamUpdateTime = System.currentTimeMillis(); + private boolean safeZone = false; + private int bindBuildingID; + private int lastContract; + /* DataWarehouse based kill/death tracking. These sets contain the last 10 UUID's - */ - - public LinkedList pvpKills; - public LinkedList pvpDeaths; - private String hash; - public int lastBuildingAccessed = 0; - - private ArrayList guildHistory = new ArrayList<>(); - - public double timeLoggedIn = 0; - - public boolean RUN_MAGICTREK = true; - - public int spellsCasted = 0; - public int pingCount = 0; - public long startPing = 0; - public double ping = 0; - private boolean wasTripped75 = false; - private boolean wasTripped50 = false; - private boolean wasTripped25 = false; - - private float characterHeight = 0; - public float centerHeight = 0; - private boolean lastSwimming = false; - - private boolean isTeleporting = false; - public float landingAltitude = 0; - - public int bindBuilding = 0; - public FriendStatus friendStatus = FriendStatus.Available; - - /** - * No Id Constructor - */ - public PlayerCharacter( String firstName, String lastName, short strMod, short dexMod, short conMod, short intMod, - short spiMod, Guild guild, byte runningTrains, Account account, Race race, BaseClass baseClass, byte skinColor, byte hairColor, - byte beardColor, byte hairStyle, byte beardStyle) { - super(firstName, lastName, (short) 1, (short) 1, (short) 1, (short) 1, (short) 1, (short) 1, 0, - Vector3fImmutable.ZERO, Vector3fImmutable.ZERO, Vector3fImmutable.ZERO, - guild, runningTrains); - - this.runes = new ArrayList<>(); - this.account = account; - this.notDeleted = true; - this.race = race; - this.baseClass = baseClass; - this.skinColor = skinColor; - this.hairColor = hairColor; - this.beardColor = beardColor; - this.hairStyle = hairStyle; - this.beardStyle = beardStyle; - this.lfGroup = false; - this.lfGuild = false; - - this.strMod.set(strMod); - this.dexMod.set(dexMod); - this.conMod.set(conMod); - this.intMod.set(intMod); - this.spiMod.set(spiMod); - - this.guildStatus = new AtomicInteger(0); - this.bindBuildingID = -1; - } - - /** - * ResultSet Constructor - */ - public PlayerCharacter(ResultSet rs) throws SQLException { - super(rs, true); - - this.runes = DbManager.CharacterRuneQueries.GET_RUNES_FOR_CHARACTER(this.getObjectUUID()); - int accountID = rs.getInt("parent"); - this.account = DbManager.AccountQueries.GET_ACCOUNT(accountID); - this.gridObjectType = GridObjectType.DYNAMIC; - - this.notDeleted = rs.getBoolean("char_isActive"); - - int raceID = rs.getInt("char_raceID"); - this.race = Race.getRace(raceID); - - int baseClassID = rs.getInt("char_baseClassID"); - this.baseClass = DbManager.BaseClassQueries.GET_BASE_CLASS(baseClassID); - - int promotionClassID = rs.getInt("char_promotionClassID"); - this.promotionClass = DbManager.PromotionQueries.GET_PROMOTION_CLASS(promotionClassID); - - this.skinColor = rs.getByte("char_skinColor"); - this.hairColor = rs.getByte("char_hairColor"); - this.beardColor = rs.getByte("char_beardColor"); - this.hairStyle = rs.getByte("char_hairStyle"); - this.beardStyle = rs.getByte("char_beardStyle"); - - this.lfGroup = false; - this.lfGuild = false; - - //TODO Unify game object with database after DB overhaul - 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 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); - } - - public void setRecruiter(boolean value) { - if (GuildStatusController.isRecruiter(this.guildStatus) == value) - return; - DbManager.PlayerCharacterQueries.SET_RECRUITER(this, value); - GuildStatusController.setRecruiter(guildStatus, value); - } - - public void setTaxCollector(boolean value) { - if (GuildStatusController.isTaxCollector(this.guildStatus) == value) - return; - DbManager.PlayerCharacterQueries.SET_TAX_COLLECTOR(this, value); - GuildStatusController.setTaxCollector(guildStatus, value); - } - - public void setInnerCouncil(boolean value) { - - // dont update if its the same. - if (GuildStatusController.isInnerCouncil(this.guildStatus) == value) - return; - - DbManager.PlayerCharacterQueries.SET_INNERCOUNCIL(this, value); - GuildStatusController.setInnerCouncil(guildStatus, value); - } - - public void setGuildLeader(boolean value) { - if (GuildStatusController.isGuildLeader(this.guildStatus) == value) - return; - - 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); - } - - /* - * Getters - */ - public byte getHairStyle() { - return hairStyle; - } - - public byte getBeardStyle() { - return beardStyle; - } - - public void setWeaponPower(DeferredPowerJob value) { - this.weaponPower = value; - } - - public DeferredPowerJob getWeaponPower() { - return this.weaponPower; - } - - public void setSafeZone(boolean value) { - this.safeZone = value; - } - - public boolean inSafeZone() { - return this.safeZone; - } - - public boolean isInSafeZone() { - - Zone zone = ZoneManager.findSmallestZone(this.getLoc()); - - if (zone != null){ - return zone.getSafeZone() == (byte) 1; - } - - return false; - //return this.safeZone; - } - - /** - * @return the account - */ - public Account getAccount() { - return account; - } - - public void deactivateCharacter() { - this.notDeleted = false; - DbManager.PlayerCharacterQueries.SET_DELETED(this); - DbManager.removeFromCache(this); - } - - public void activateCharacter() { - this.notDeleted = true; - DbManager.PlayerCharacterQueries.SET_DELETED(this); - } - - public boolean isDeleted() { - return !this.notDeleted; - } - - public ArrayList getRunes() { - return this.runes; - } - - public CharacterRune getRune(int runeID) { - if (this.runes == null) - return null; - for (CharacterRune cr : this.runes) { - if (cr.getRuneBase() != null && cr.getRuneBase().getObjectUUID() == runeID) - return cr; - } - return null; - } - - public boolean addRune(CharacterRune value) { - if (this.runes.size() > 12) // Max Runes - return false; - if (this.runes.indexOf(value) != -1) // Already contains rune - return false; - this.runes.add(value); - return true; - } - - public boolean removeRune(CharacterRune value) { - int index = this.runes.indexOf(value); - if (index == -1) - return false; - this.runes.remove(index); - return true; - } - - public CharacterRune removeRune(int runeID) { - Iterator it = this.runes.iterator(); - while (it.hasNext()) { - CharacterRune cr = it.next(); - if (cr != null) { - RuneBase rb = cr.getRuneBase(); - if (rb != null) - if (runeID == rb.getObjectUUID()) { - it.remove(); - DbManager.CharacterRuneQueries.DELETE_CHARACTER_RUNE(cr); - return cr; - } - } - } - return null; - } - - /** - * @ Kill this Character - */ - @Override - public void killCharacter(AbstractCharacter attacker) { - - killCleanup(); - - // *** Mobs have a separate combat path? Crazy shit! - // *** Mobs don't get Experience for killing players. everything else is done in killCleanup(); - - if (attacker.getObjectType().equals(GameObjectType.PlayerCharacter) == false){ - - Zone zone = ZoneManager.findSmallestZone(this.getLoc()); - - //DeathShroud - - if (zone.getSafeZone() == 0) - PowersManager.applyPower(this, this, Vector3fImmutable.ZERO, 1672601862, 40, false); - - //enable this to give players deathshroud if mobs kill player. - - // Zone zone = ZoneManager.findSmallestZone(this.getLoc()); - // if (zone.getSafeZone() == 0) - // PowersManager.applyPower(this, this, Vector3fImmutable.ZERO, 1672601862, 40, false); - return; - } - - - // Death to other player. - // TODO Send PvP and guild/nation message - PlayerCharacter att = (PlayerCharacter) attacker; - String message = this.getFirstName(); - if (this.guild != null && (!(this.guild.getName().equals("Errant")))) - message += " of " + this.guild.getName(); - message += " was killed by " + att.getFirstName(); - if (att.guild != null && (!(att.guild.getName().equals("Errant")))) - message += " of " + att.guild.getName(); - message += "!"; - - - //see if we shold grant xp to attacker - boolean doPVPEXP = false; - long lastKill = att.getLastKillOfTarget(this.getObjectUUID()); - if ((System.currentTimeMillis() - lastKill) > MBServerStatics.PLAYER_KILL_XP_TIMER) - if (attacker.getLevel() > 39 && this.getLevel() > 39) { - Guild aN = null; - Guild tN = null; - if (attacker.getGuild() != null) - aN = attacker.getGuild().getNation(); - if (this.getGuild() != null) - tN = this.getGuild().getNation(); - if (aN == null || tN == null || aN.isEmptyGuild() || Guild.sameGuild(aN, tN) || this.isDeathShroud()) { - //skip giving xp if same guild or attacker is errant, or target is in death shroud. - } else { - doPVPEXP = true; - } - } - //apply death shroud to non safeholds. - Zone zone = ZoneManager.findSmallestZone(this.getLoc()); - - //DeathShroud - - if (zone.getSafeZone() == 0) - PowersManager.applyPower(this, this, Vector3fImmutable.ZERO, 1672601862, 40, false); - - if (doPVPEXP){ - Group g = GroupManager.getGroup((PlayerCharacter) attacker); - Experience.doExperience((PlayerCharacter) attacker, this, g); - } - - ChatManager.chatPVP(message); - - /* - Update kill / death tracking lists - Each character on list is unique. Only once! - */ - - PlayerCharacter aggressorCharacter = (PlayerCharacter)attacker; - - boolean containsVictim = true; - boolean containsAttacker = true; - - containsVictim = aggressorCharacter.pvpKills.contains(this.getObjectUUID()); - containsAttacker = aggressorCharacter.pvpKills.contains(this.getObjectUUID()); - - // Rorate attacker's kill list - - if ((aggressorCharacter.pvpKills.size() == 10) && containsVictim == false) - aggressorCharacter.pvpKills.removeLast(); - - if (containsVictim == false) - aggressorCharacter.pvpKills.addFirst(this.getObjectUUID()); + */ + 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; + private boolean canBreathe = true; + private String hash; + private ArrayList guildHistory = new ArrayList<>(); + private boolean wasTripped75 = false; + private boolean wasTripped50 = false; + private boolean wasTripped25 = false; + private float characterHeight = 0; + private boolean lastSwimming = false; + private boolean isTeleporting = false; + + /** + * No Id Constructor + */ + public PlayerCharacter(String firstName, String lastName, short strMod, short dexMod, short conMod, short intMod, + short spiMod, Guild guild, byte runningTrains, Account account, Race race, BaseClass baseClass, byte skinColor, byte hairColor, + byte beardColor, byte hairStyle, byte beardStyle) { + super(firstName, lastName, (short) 1, (short) 1, (short) 1, (short) 1, (short) 1, (short) 1, 0, + Vector3fImmutable.ZERO, Vector3fImmutable.ZERO, Vector3fImmutable.ZERO, + guild, runningTrains); + + this.runes = new ArrayList<>(); + this.account = account; + this.notDeleted = true; + this.race = race; + this.baseClass = baseClass; + this.skinColor = skinColor; + this.hairColor = hairColor; + this.beardColor = beardColor; + this.hairStyle = hairStyle; + this.beardStyle = beardStyle; + this.lfGroup = false; + this.lfGuild = false; + + this.strMod.set(strMod); + this.dexMod.set(dexMod); + this.conMod.set(conMod); + this.intMod.set(intMod); + this.spiMod.set(spiMod); + + this.guildStatus = new AtomicInteger(0); + this.bindBuildingID = -1; + } - // Rotate the poor victim's deathlist + /** + * ResultSet Constructor + */ + public PlayerCharacter(ResultSet rs) throws SQLException { + super(rs, true); - if ((this.pvpDeaths.size() == 10) && containsAttacker == false) - this.pvpDeaths.removeLast(); + this.runes = DbManager.CharacterRuneQueries.GET_RUNES_FOR_CHARACTER(this.getObjectUUID()); + int accountID = rs.getInt("parent"); + this.account = DbManager.AccountQueries.GET_ACCOUNT(accountID); + this.gridObjectType = GridObjectType.DYNAMIC; - if (containsAttacker == false) - this.pvpDeaths.addFirst(this.getObjectUUID()); + this.notDeleted = rs.getBoolean("char_isActive"); - // DataWarehouse: store pvp event + int raceID = rs.getInt("char_raceID"); + this.race = Race.getRace(raceID); - PvpRecord pvpRecord = PvpRecord.borrow((PlayerCharacter) attacker, this, this.getLoc(), doPVPEXP); - DataWarehouse.pushToWarehouse(pvpRecord); + int baseClassID = rs.getInt("char_baseClassID"); + this.baseClass = DbManager.BaseClassQueries.GET_BASE_CLASS(baseClassID); - // Mark kill time in killmap + int promotionClassID = rs.getInt("char_promotionClassID"); + this.promotionClass = DbManager.PromotionQueries.GET_PROMOTION_CLASS(promotionClassID); - att.updateKillMap(this.getObjectUUID()); - } + this.skinColor = rs.getByte("char_skinColor"); + this.hairColor = rs.getByte("char_hairColor"); + this.beardColor = rs.getByte("char_beardColor"); + this.hairStyle = rs.getByte("char_hairStyle"); + this.beardStyle = rs.getByte("char_beardStyle"); - @Override - public void killCharacter(String reason) { + this.lfGroup = false; + this.lfGuild = false; - killCleanup(); - Zone zone = ZoneManager.findSmallestZone(this.getLoc()); + //TODO Unify game object with database after DB overhaul + this.guildStatus = new AtomicInteger(0); - if (zone.getSafeZone() == 0) - PowersManager.applyPower(this, this, Vector3fImmutable.ZERO, 1672601862, 40, false); + Guild guild = Guild.getGuild(this.getGuildUUID()); + if (guild != null && guild.isGuildLeader(this.getObjectUUID())) + this.setGuildLeader(true); + else + this.setGuildLeader(false); - // Send death message if needed - if (reason.equals("Water")) { + this.hasAnniversery = rs.getBoolean("anniversery"); - TargetedActionMsg targetedActionMsg = new TargetedActionMsg(this, true); - Dispatch dispatch = Dispatch.borrow(this, targetedActionMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + 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")); - String message = this.getFirstName(); + if (this.account != null) + this.ignoredPlayerIDs = DbManager.PlayerCharacterQueries.GET_IGNORE_LIST(this.account.getObjectUUID(), false); - if (this.guild != null && (!(this.guild.getName().equals("Errant")))) - message += " of " + this.guild.getName(); - else - message += this.getLastName(); - message += " was killed by water!"; + 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")); - ChatManager.chatPVP(message); + this.bindBuildingID = rs.getInt("char_bindBuilding"); - } - } + this.hash = rs.getString("hash"); - private void killCleanup() { - this.stopMovement(this.getLoc()); - this.health.set(-1); - //remove pet - if (this.pet != null) - this.dismissPet(); + // For debugging skills + // CharacterSkill.printSkills(this); + } - NPCManager.dismissNecroPets(this); - // remove flight job. + public static Building getUpdatedBindBuilding(PlayerCharacter player) { + Building returnBuilding = null; - this.setTakeOffTime(0); - this.setDesiredAltitude(0); - this.altitude = (float) 0; + //update bindBuilding based on Guild or nation TOL; - // Release Mine Claims + if (player.getBindBuildingID() == 0) { - Mine.releaseMineClaims(this); + returnBuilding = PlayerCharacter.getBindBuildingForGuild(player); - this.getCharItemManager().closeTradeWindow(); + if (returnBuilding != null) + player.setBindBuildingID(returnBuilding.getObjectUUID()); + return returnBuilding; + } + returnBuilding = BuildingManager.getBuildingFromCache(player.getBindBuildingID()); - //increment live counter. This is to prevent double kills from casts - this.liveCounter++; + if (returnBuilding == null) { + returnBuilding = PlayerCharacter.getBindBuildingForGuild(player); - //remove any effects - try { - this.clearEffects(); - }catch(Exception e){ - Logger.error("PlayerCharacter.KillCleanup", e.getMessage()); - } + if (returnBuilding != null) + player.setBindBuildingID(returnBuilding.getObjectUUID()); + } + return returnBuilding; + } - //remove the SIT flag - this.setSit(false); + public static Building getBindBuildingForGuild(PlayerCharacter player) { + Building returnBuilding; + if (player.getGuild() == null || player.getGuild().isEmptyGuild()) + return null; - // sends a kill message to ensure the Player falls over. + if (player.getGuild().getOwnedCity() == null) { - this.respawnLock.writeLock().lock(); + if (player.getGuild().getNation().getOwnedCity() == null) + return null; - try{ - if (SessionManager.getPlayerCharacterByID(this.getObjectUUID()) == null && !this.enteredWorld){ - WorldGrid.RemoveWorldObject(this); - this.respawn(false, false,true); - }else{ - TargetedActionMsg killmsg = new TargetedActionMsg(this, true); - DispatchMessage.dispatchMsgToInterestArea(this, killmsg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); - } - }catch(Exception e){ - Logger.error(e); - }finally{ - this.respawnLock.writeLock().unlock(); - } + if (player.getGuild().getNation().getOwnedCity().getTOL() == null) + return null; - // TODO damage equipped items - if (this.charItemManager != null) - this.charItemManager.damageAllGear(); + returnBuilding = player.getGuild().getNation().getOwnedCity().getTOL(); + player.setBindBuildingID(returnBuilding.getObjectUUID()); + return returnBuilding; + } - // TODO cleanup any timers - //recalculate inventory weights - if (this.charItemManager != null) { - this.charItemManager.endTrade(true); - this.charItemManager.calculateWeights(); - this.charItemManager.updateInventory(); - } + 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); + } - public void updateKillMap(int target) { - this.killMap.put(target, System.currentTimeMillis()); - } + // 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); + } - public long getLastKillOfTarget(int target) { - if (this.killMap.containsKey(target)) - return this.killMap.get(target); - return 0L; - } + /* + * STATS + */ + // Number of Stats to follow + writer.putInt(5); - public boolean isDeathShroud() { - return this.effects != null && this.effects.containsKey("DeathShroud"); - } + writer.putInt(MBServerStatics.STAT_STR_ID); // Strength ID + writer.putInt(freshChar ? 0 : playerCharacter.getStrMod()); - public void setSafeMode() { - PowersManager.applyPower(this, this, Vector3fImmutable.ZERO, -1661758934, 40, false); - } + writer.putInt(MBServerStatics.STAT_SPI_ID); // Spirit ID + writer.putInt(freshChar ? 0 : playerCharacter.getSpiMod()); - public boolean safemodeInvis() { + writer.putInt(MBServerStatics.STAT_CON_ID); // Constitution ID + writer.putInt(freshChar ? 0 : playerCharacter.getConMod()); - if (!this.effects.containsKey("Invisible")) - return false; + writer.putInt(MBServerStatics.STAT_DEX_ID); // Dexterity ID + writer.putInt(freshChar ? 0 : playerCharacter.getDexMod()); - Effect eff = this.effects.get("Invisible"); + writer.putInt(MBServerStatics.STAT_INT_ID); // Intelligence ID + writer.putInt(freshChar ? 0 : playerCharacter.getIntMod()); - if (eff == null) - return false; + // Handle Info + playerCharacter.title._serializeFirstName(writer, playerCharacter.firstName); + playerCharacter.title._serializeLastName(writer, playerCharacter.lastName, hideAsciiLastName, playerCharacter.asciiLastName); - return eff.getEffectToken() == -1661751254; + // Unknown + writer.putInt(0); - } + writer.putString(ConfigManager.MB_WORLD_NAME.getValue()); + writer.putInt(WorldServer.worldMapID); - public void respawn(boolean setAlive, boolean enterWorld, boolean makeCorpse) { + writer.put((byte) 1); // End Datablock byte + writer.putInt(0); // Unsure, Pad? + writer.putInt(playerCharacter.getObjectType().ordinal()); + writer.putInt(playerCharacter.getObjectUUID()); - // Recalculate everything + // 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 - this.recalculatePlayerStats(true); - this.setCombat(false); + // facing - // Set Health to 1/4 max + // 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); - Corpse corpse = null; + ArrayList equipped = playerCharacter.charItemManager.getEquippedList(); - 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. - } + 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); + } - 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()); + 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); - this.lastUpdateTime = System.currentTimeMillis(); - this.lastStamUpdateTime = System.currentTimeMillis(); +// 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); + } - this.update(); - PowersManager.applyPower(this, this, Vector3fImmutable.ZERO, -1661758934, 40, false); + //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 (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 - */ - public Race getRace() { - return race; - } - - public int getRaceID() { - if (race != null) - return race.getRaceRuneID(); - return 0; - } - - /** - * @return the baseClass - */ - public BaseClass getBaseClass() { - return baseClass; - } - - public int getBaseClassID() { - if (baseClass != null) - return baseClass.getObjectUUID(); - return 0; - } - - public int getBaseClassToken() { - if (this.baseClass == null) - return 0; - else - return this.baseClass.getToken(); - } - - public boolean setBaseClass(int value) { - BaseClass bs = BaseClass.getBaseClass(value); - if (bs != null) { - this.baseClass = bs; - return true; - } - return false; - } - - @Override - public Vector3fImmutable getBindLoc() { - - Vector3fImmutable bindLocation; - - // Return garbage and early exit if this is the login server. - // getBindLoc() does a TOL lookup, which also then loads the - // city and other garbage not needed on the login server. - - if (ConfigManager.serverType.equals(ServerType.LOGINSERVER)) - return Vector3fImmutable.ZERO; - - Building bindBuilding = PlayerCharacter.getUpdatedBindBuilding(this); - - //handle rented room binds. - - if (bindBuilding == null){ - bindLocation = Enum.Ruins.getRandomRuin().getLocation(); - return bindLocation; - } - - bindLocation = BuildingManager.GetBindLocationForBuilding(bindBuilding); - - if (bindLocation == null) - bindLocation = Enum.Ruins.getRandomRuin().getLocation(); - - return bindLocation; - - } - - public int getInventoryCapacity() { - return statStrBase * 3; - } - - public int getInventoryCapacityRemaining() { - return (this.getInventoryCapacity() - this.charItemManager.getInventoryWeight()); - } - - /** - * @return the PromotionClass - */ - public PromotionClass getPromotionClass() { - return promotionClass; - } - - public int getPromotionClassID() { - if (promotionClass != null) - return promotionClass.getObjectUUID(); - return 0; - } - - public boolean setPromotionClass(int value) { - - PromotionClass promotionClass = PromotionClass.GetPromtionClassFromCache(value); - - if (promotionClass == null) - return false; - - - if (!DbManager.PlayerCharacterQueries.SET_PROMOTION_CLASS(this, value)) - return false; - - this.promotionClass = promotionClass; - - // Warehouse this event - CharacterRecord.updatePromotionClass(this); - return true; - } - - /** - * @return the skinColor - */ - public byte getSkinColor() { - return skinColor; - } - - /** - * @return the hairColor - */ - public byte getHairColor() { - return hairColor; - } - - /** - * @return the beardColor - */ - public byte getBeardColor() { - return beardColor; - } - - /** - * @return the lfGroup - */ - public boolean isLfGroup() { - return lfGroup; - } - - public int getIsLfGroupAsInt() { - if (lfGroup) - return 2; - return 1; - } - - - public final void toggleLFGroup() { - this.lfGroup = !this.lfGroup; - } - - public final void toggleLFGuild() { - this.lfGuild = !this.lfGuild; - } - - public final void toggleRecruiting() { - this.recruiting = !this.recruiting; - } - - public final void setLFGroup(final boolean value) { - this.lfGroup = value; - } - - public final void setLFGuild(final boolean value) { - this.lfGuild = value; - } - - public final void setRecruiting(final boolean value) { - this.recruiting = value; - } - - public final boolean isLFGroup() { - return this.lfGroup; - } - - public final boolean isLFGuild() { - return this.lfGuild; - } - - public final boolean isRecruiting() { - return this.recruiting; - } - - /** - * @return the lfGuild - */ - public boolean isLfGuild() { - return lfGuild; - } - - public final int getHeadlightsAsInt() { - if (this.lfGroup) - if (this.lfGuild) - if (this.recruiting) - return 14; // LFGroup + LFGuild + Recruiting - else - return 6; // LFGroup + LFGuild - else if (this.recruiting) - return 10; // LFGroup + Recruiting - else - return 2; // LFGroup only - else if (this.lfGuild) - if (this.recruiting) - return 12; // LFGuild + Recruiting - else - return 4; // LFGuild only - else if (this.recruiting) - return 8; // Recruiting only - else - return 0; // No Headlights - } - - public int getIsLfGuildAsInt() { - if (lfGuild) - return 2; - return 1; - } - - public int getStrMax() { - return this.statStrMax; - } - public int getDexMax() { - return this.statDexMax; - } - public int getConMax() { - return this.statConMax; - } - 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 void setLastTarget(GameObjectType type, int id) { - this.lastTargetType = type; - this.lastTargetID = id; - } - - public GameObjectType getLastTargetType() { - return this.lastTargetType; - } - - public int getLastTargetID() { - return this.lastTargetID; - } - - public synchronized int getBindBuildingID() { - return this.bindBuildingID; - } - - public synchronized void setBindBuildingID(int value) { - DbManager.PlayerCharacterQueries.SET_BIND_BUILDING(this, value); - this.bindBuildingID = value; - } - - 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 AbstractGameObject getLastTarget() { - if (this.lastTargetType == GameObjectType.unknown) - return null; - - switch (this.lastTargetType) { - // Make sure these only return an object that is - // already in the GOM, and doesn't reload from the DB - case PlayerCharacter: - return DbManager.getFromCache(GameObjectType.PlayerCharacter, this.lastTargetID); - - case Building: - return DbManager.getFromCache(GameObjectType.Building, this.lastTargetID); - - case NPC: - return NPC.getFromCache(this.lastTargetID); - - case Mob: - return Mob.getFromCache(this.lastTargetID); - - case Item: - return DbManager.getFromCache(GameObjectType.Item, this.lastTargetID); - - case Corpse: - return DbManager.getFromCache(GameObjectType.Corpse, this.lastTargetID); - - default: - - // Ignore exception for MobLoot? ***Check - if (this.lastTargetType != GameObjectType.MobLoot) - Logger.error( "getLastTarget() unhandled object type: " - + this.lastTargetType.toString()); - } - return null; - } - - public Vector3fImmutable getLastStaticLoc() { - return this.lastStaticLoc; - } - - public void setLastStaticLoc(Vector3fImmutable value) { - this.lastStaticLoc = value; - } - - public int getHidden() { - return this.hidden; - } - - public void setHidden(int value) { - this.hidden = value; - } - - public int getSeeInvis() { - if (this.getDebug(8)) //<-added for see invis debug devcmd - return 10000; - return this.seeInvis; - } - - public void setSeeInvis(int value) { - this.seeInvis = value; - } - - public long getLastPlayerAttackTime() { - return this.lastPlayerAttackTime; - } - - public void setLastPlayerAttackTime() { - this.lastPlayerAttackTime = System.currentTimeMillis(); - } - - public void setLastMobAttackTime() { - this.lastMobAttackTime = System.currentTimeMillis(); - } - - public void setLastUsedPowerTime() { - this.lastUsedPowerTime = System.currentTimeMillis(); - } - - public void setLastTargetOfUsedPowerTime() { - this.lastTargetOfUsedPowerTime = System.currentTimeMillis(); - } - - public void setLastNPCDialog(NPC value) { - this.lastNPCDialog = value; - } - - public NPC getLastNPCDialog() { - return this.lastNPCDialog; - } - - public void setLastContract(int value) { - this.lastContract = value; - } - - public void setPet(Mob mob) { - - if (mob == null) - return; - - this.pet = mob; - } - - public Mob getPet() { - return this.pet; - } - - public void dismissPet() { - - if (this.pet != null) { - this.pet.dismiss(); - this.pet = null; - } - } + if (otherPlayer) { + writer.put((byte) 0); // End Datablock Byte + return; - //called to verify player has correct item equipped for casting. - public boolean validEquip(int slot, String type) { - - if (this.charItemManager == null) - return false; - - Item item = this.charItemManager.getEquipped(slot); - - if (item == null) - return false; - - ItemBase ib = item.getItemBase(); - if (ib != null) { - - if ((ib.getType().equals(ItemType.WEAPON)) - && (ib.getSkillRequired().equals(type) || ib.getMastery().equals(type))) - return true; - - return (ib.getType().equals(ItemType.ARMOR)) - && (ib.getSkillRequired().equals(type)); - } - - return false; - } - - public short getPCLevel() { - short level = (short) Experience.getLevel(this.exp); - if (this.promotionClass == null && level >= 10) - return (short) 10; - - if (this.overFlowEXP > 0) - return this.level; - - return level; - } - - @Override - public float getSpeed() { - - float speed; - - if (this.getAltitude() > 0) - if (this.walkMode) { - speed = race.getRaceType().getRunSpeed().getFlyWalk(); - } - else { - speed = race.getRaceType().getRunSpeed().getFlyRun(); - } - else if (this.lastSwimming == true) - speed = MBServerStatics.SWIMSPEED; - else - if (this.walkMode) { - if (this.isCombat()) - speed = race.getRaceType().getRunSpeed().getWalkCombat(); - else - speed = race.getRaceType().getRunSpeed().getWalkStandard(); - } - else { - if (this.isCombat()) - speed = race.getRaceType().getRunSpeed().getRunCombat(); - else - speed = race.getRaceType().getRunSpeed().getRunStandard(); - } + } - float endSpeed = speed * this.speedMod; - - if (endSpeed > 41 && !this.isCSR) - endSpeed = 41; - - return endSpeed; - } - - public synchronized void grantXP(int xp) { - // 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(); - 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(); - this.speedMod = bonus; - } - - public ClientConnection getClientConnection() { - return SessionManager.getClientConnection(this); - } - - /* - * Serializing - */ - - 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 { + //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); + } + } - /* - * 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); - } + /* + * 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); + } + } - /* - * 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()); + /* + * 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()); + } - /* - * 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); - } - } + /* + * Bank + */ + if (loginData) { + writer.putInt(0); // Skip Bank + writer.putInt(AbstractCharacter.getBankCapacity()); // Bank Capacity - /* - * 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); - } - } + } else { + ArrayList bank = playerCharacter.charItemManager.getBank(); - /* - * Inventory - */ - if (loginData) { - writer.putInt(0); // Skip Inventory - writer.putInt(playerCharacter.getInventoryCapacity()); // Inventory Capacity + 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()); + } + + } + } + } - } 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.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 @@ -2313,3284 +740,4796 @@ public class PlayerCharacter extends AbstractCharacter { if (playerCharacter.account == null) serverUp = 0; - if ((playerCharacter.account.status.equals(AccountStatus.ADMIN) == false) && - (playerCharacter.account.status.equals(WorldServer.worldAccessLevel) == false)) - 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(); - - 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 (!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 (!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 = Kit.GetKitIDByRaceClass(raceID, 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; - } - - // 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 String getCombinedName() { - return this.getName(); - } - - public long getLastGuildToInvite() { - return this.lastGuildToInvite; - } - - public void setLastGuildToInvite(int value) { - this.lastGuildToInvite = value; - } - - public boolean getFollow() { - return this.follow; - } - - public boolean toggleFollow() { - this.follow = !this.follow; - return this.follow; - } - - public void setFollow(boolean value) { - this.follow = value; - } - - public int getLastGroupToInvite() { - return this.lastGroupToInvite; - } - - public void setLastGroupToInvite(int value) { - this.lastGroupToInvite = value; - } - - @Override - public float getAltitude() { - if (this.altitude < 0) - this.altitude = 0; - - //player has reached desired altitude, return normal altitude. - if (this.getTakeOffTime() == 0) - return this.altitude; - - //sanity check if desired altitude is the same as current altitude. return desired altitude. - if (this.altitude == this.getDesiredAltitude()){ - return this.getDesiredAltitude(); - } - - //calculate how much the player has moved up - float amountMoved = (System.currentTimeMillis() - this.getTakeOffTime()) * MBServerStatics.FLY_RATE; //FUCK DIVIDING - - //Player is moving up - if (this.getDesiredAltitude() > this.altitude){ - - //if amount moved passed desiredAltitude, return the desired altitude. - if (this.altitude + amountMoved >= this.getDesiredAltitude()) - return this.getDesiredAltitude(); - - return this.altitude + amountMoved; - //Player is moving down - }else{ - //if amount moved passed desiredAltitude, return the desired altitude. - if (this.altitude - amountMoved <= this.getDesiredAltitude()) - return this.getDesiredAltitude(); - return this.altitude - amountMoved; - } - - - - } - - public void setAltitude(float value) { - this.altitude = value; - } - - public HashSet getLoadedObjects() { - return this.loadedObjects; - } - - public HashSet getLoadedStaticObjects() { - return this.loadedStaticObjects; - } - - public void setLoadedStaticObjects(HashSet value) { - this.loadedStaticObjects = value; - } - - public void setTeleportMode(boolean teleportMode) { - this.teleportMode = teleportMode; - } - - public boolean isTeleportMode() { - return 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 - LinkedList times = null; - long oldestTime; - synchronized (chatChanFloodList) { - if (!chatChanFloodList.containsKey(chatOpcode)) { - times = new LinkedList<>(); - for (int i = 0; i < qtyToSave; i++) { - times.add(0L); - } - chatChanFloodList.put(chatOpcode, times); - } else - times = chatChanFloodList.get(chatOpcode); - oldestTime = times.getLast(); - times.removeLast(); - times.addFirst(chatTimeMilli); - } - return oldestTime; - } - - public void addIgnoredPlayer(Account ac, String name) { - if (ac == null) - return; - int acID = ac.getObjectUUID(); - if (acID < 1) - return; - if (ignoredPlayerIDs == null) - return; - if (acID == getObjectUUID()) - return; // yourself - - ignoredPlayerIDs.put(acID, name); - } - - public static boolean isIgnoreListFull() { - return false; //Why were we setting a limit on ignores? - - //return (ignoredPlayerIDs.size() >= MBServerStatics.IGNORE_LIST_MAX); - } - - public void removeIgnoredPlayer(Account ac) { - if (ac == null) - return; - int acID = ac.getObjectUUID(); - if (acID < 1) - return; - if (ignoredPlayerIDs == null) - return; - if (acID == getObjectUUID()) - return; // yourself - - ignoredPlayerIDs.remove(acID); - } - - public boolean isIgnoringPlayer(PlayerCharacter pc) { + } + + 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(); + + 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 (!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 (!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 = Kit.GetKitIDByRaceClass(raceID, 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; + } + + // 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.bindLoc); + 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; - if (pc.account == null) + Building bindBuilding = BuildingManager.getBuildingFromCache(buildingID); + + if (bindBuilding == null) return false; - return isIgnoringPlayer(pc.account); + 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 boolean isIgnoringPlayer(Account ac) { - if (ac == null) - return false; - int acID = ac.getObjectUUID(); - if (acID < 1) - return false; - return ignoredPlayerIDs.containsKey(acID); - } - - public static boolean isIgnorable() { - return true; - // // if (account == null) return false; - // if (account.getAccessLevel() > 0) { - // return false; - // } - // return true; - } - - public String[] getIgnoredPlayerNames() { - int size = ignoredPlayerIDs.size(); - String[] ary = new String[size]; - for (int i = 0; i < size; i++) { - // ary[i] = PlayerCharacter.getFirstName(ignoredPlayerIDs.get(i)); - ary[i] = ignoredPlayerIDs.get(i); - } - return ary; - } - - public int getStrMod() { - return this.strMod.get(); - } - - public int getDexMod() { - return this.dexMod.get(); - } - - public int getConMod() { - return this.conMod.get(); - } - - public int getIntMod() { - return this.intMod.get(); - } - - public int getSpiMod() { - return this.spiMod.get(); - } - - public boolean isMale() { - if (this.race == null) - return true; - return (this.race.getRaceType().getCharacterSex().equals(CharacterSex.MALE)); - } - - - public boolean canSee(PlayerCharacter tar) { + public void setFullMember(boolean value) { + if (GuildStatusController.isFullMember(this.guildStatus) == value) + return; + DbManager.PlayerCharacterQueries.SET_FULL_MEMBER(this, value); + GuildStatusController.setFullMember(guildStatus, value); + } - if (tar == null) - return false; + public void setRecruiter(boolean value) { + if (GuildStatusController.isRecruiter(this.guildStatus) == value) + return; + DbManager.PlayerCharacterQueries.SET_RECRUITER(this, value); + GuildStatusController.setRecruiter(guildStatus, value); + } - if (this.equals(tar)) - return true; + public void setTaxCollector(boolean value) { + if (GuildStatusController.isTaxCollector(this.guildStatus) == value) + return; + DbManager.PlayerCharacterQueries.SET_TAX_COLLECTOR(this, value); + GuildStatusController.setTaxCollector(guildStatus, value); + } - return this.getSeeInvis() >= tar.hidden && !tar.safemodeInvis(); - } + public void setInnerCouncil(boolean value) { - /** - * @ Initialize player upon creation - */ - public static void initializePlayer(PlayerCharacter player) { + // dont update if its the same. + if (GuildStatusController.isInnerCouncil(this.guildStatus) == value) + return; - 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.bindLoc); - player.endLoc = Vector3fImmutable.ZERO; + DbManager.PlayerCharacterQueries.SET_INNERCOUNCIL(this, value); + GuildStatusController.setInnerCouncil(guildStatus, value); + } - //get level based on experience - player.level = (short) Experience.getLevel(player.exp); + public void setGuildLeader(boolean value) { + if (GuildStatusController.isGuildLeader(this.guildStatus) == value) + return; - 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(); + GuildStatusController.setGuildLeader(guildStatus, value); + if (value == true) { + this.setInnerCouncil(true); + this.setFullMember(true); + } + } - if (ConfigManager.serverType.equals(ServerType.WORLDSERVER)) { + //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); + } - //CharacterSkill.updateAllBaseAmounts(this); - CharacterPower.grantTrains(player); + /* + * Getters + */ + public byte getHairStyle() { + return hairStyle; + } - // calculate skills. Make sure none are missing. - AbstractCharacter.runBonusesOnLoad(player); - - PlayerCharacter.InitializeSkillsOnLoad(player); + public byte getBeardStyle() { + return beardStyle; + } - //apply all bonuses - player.recalculatePlayerStats(true); - player.trainsAvailable.set(CharacterSkill.getTrainsAvailable(player)); + public DeferredPowerJob getWeaponPower() { + return this.weaponPower; + } - if (player.trainsAvailable.get() < 0) - player.recalculateTrains(); + public void setWeaponPower(DeferredPowerJob value) { + this.weaponPower = value; + } - //this.resists.calculateResists(this); - player.newChar = true; + public void setSafeZone(boolean value) { + this.safeZone = value; + } - //check current guild valid for player - player.checkGuildStatus(); + public boolean inSafeZone() { + return this.safeZone; + } - player.setHealth(player.getHealthMax()); - player.mana.set(player.manaMax); - player.stamina.set(player.staminaMax); - } else - player.setBindLoc(Vector3fImmutable.ZERO); + public boolean isInSafeZone() { - player.initialized = true; + Zone zone = ZoneManager.findSmallestZone(this.getLoc()); - String lastAscii = player.lastName.replaceAll("[^\\p{ASCII}]", ""); - player.asciiLastName = lastAscii.equals(player.lastName); - } + if (zone != null) { + return zone.getSafeZone() == (byte) 1; + } - public void recalculatePlayerStats(boolean initialized) { + return false; + //return this.safeZone; + } - //calculate base stats - calculateBaseStats(); + /** + * @return the account + */ + public Account getAccount() { + return account; + } - //calculate base skills - CharacterSkill.updateAllBaseAmounts(this); - calculateModifiedStats(); + public void deactivateCharacter() { + this.notDeleted = false; + DbManager.PlayerCharacterQueries.SET_DELETED(this); + DbManager.removeFromCache(this); + } - //calculate modified skills - CharacterSkill.updateAllModifiedAmounts(this); - this.updateScaleHeight(); + public void activateCharacter() { + this.notDeleted = true; + DbManager.PlayerCharacterQueries.SET_DELETED(this); + } - //calculate modified stats + public boolean isDeleted() { + return !this.notDeleted; + } + public ArrayList getRunes() { + return this.runes; + } - //calculate ATR, damage and defense - calculateAtrDefenseDamage(); - - //calculate movement bonus - calculateSpeedMod(); - - // recalculate Max Health/Mana/Stamina - calculateMaxHealthManaStamina(); - - // recalculate Resists - Resists.calculateResists(this); - - } - - 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); - - } - - /** - * @ Recalculate player after promoting or gaining a level - */ - public void recalculate() { - this.applyBonuses(); - this.trainsAvailable.set(CharacterSkill.getTrainsAvailable(this)); - if (this.trainsAvailable.get() < 0) - recalculateTrains(); - //this.resists.calculateResists(this); - - // calculate skills and powers. Make sure none are missing. - this.calculateSkills(); - - // calculate powers again. See if any new powers unlocked - this.calculateSkills(); - } - - //This is run to auto-fix any overage on skill training. - private void recalculateTrains() { - int trainsAvailable = CharacterSkill.getTrainsAvailable(this); - if (trainsAvailable < 0) { - - //refine powers first, run twice to catch any prereqs - ConcurrentHashMap powers = this.getPowers(); - for (int i = 0; i < 2; i++) { - for (CharacterPower p : powers.values()) { - if (trainsAvailable >= 0) - return; - while (p.getTrains() > 0 && p.refine(this)) { - trainsAvailable++; - if (trainsAvailable >= 0) - return; - } - } - } - - //refine skills - ConcurrentHashMap skills = this.getSkills(); - for (CharacterSkill s : skills.values()) { - if (trainsAvailable >= 0) - return; - while (s.getNumTrains() > 0 && s.refine(this)) { - if (CharacterSkill.getTrainsAvailable(this) >= 0) - return; - } - } - } - } - - /** - * @ Calculates Base Stats Call this when modifying stats or adding/removing - * runes - */ - public void calculateBaseStats() { - if (this.race == null || this.baseClass == null) - // Logger.getInstance().log( LogEventType.ERROR, - // "PlayerCharacter.updateBaseStats: Missing race or baseclass for Player " - // + this.getUUID()); - return; - - // get base stats and total available - int strMin = this.race.getStrStart() + this.baseClass.getStrMod() - 5; - int dexMin = this.race.getDexStart() + this.baseClass.getDexMod() - 5; - int conMin = this.race.getConStart() + this.baseClass.getConMod() - 5; - int intMin = this.race.getIntStart() + this.baseClass.getIntMod() - 5; - int spiMin = this.race.getSpiStart() + this.baseClass.getSpiMod() - 5; - int str = this.race.getStrStart() + this.baseClass.getStrMod() + this.strMod.get(); - int dex = this.race.getDexStart() + this.baseClass.getDexMod() + this.dexMod.get(); - int con = this.race.getConStart() + this.baseClass.getConMod() + this.conMod.get(); - int intt = this.race.getIntStart() + this.baseClass.getIntMod() + this.intMod.get(); - int spi = this.race.getSpiStart() + this.baseClass.getSpiMod() + this.spiMod.get(); - int strMax = this.race.getStrMax(); - int dexMax = this.race.getDexMax(); - int conMax = this.race.getConMax(); - int intMax = this.race.getIntMax(); - int spiMax = this.race.getSpiMax(); - int available = this.race.getStartingPoints() - this.strMod.get() - this.dexMod.get() - this.conMod.get() - this.intMod.get() - this.spiMod.get(); - if (level < 20) - available += (level - 1) * 5; - else if (level < 30) - available += 90 + (level - 19) * 4; - else if (level < 40) - available += 130 + (level - 29) * 3; - else if (level < 50) - available += 160 + (level - 39) * 2; - else - available += 180 + (level - 49); - - // modify for any runes applied. - for (CharacterRune rune : this.runes) { - if (rune.getRuneBase() == null) - // Logger.getInstance().log( LogEventType.ERROR, - // "PlayerCharacter.updateBaseStats: Missing runebase for rune " - // + rune.getUUID()); - continue; - ArrayList attrs = rune.getRuneBase().getAttrs(); - if (attrs == null) - // Logger.getInstance().log( LogEventType.ERROR, - // "PlayerCharacter.updateBaseStats: Missing attributes for runebase " - // + rune.getRuneBase().getUUID()); - continue; - for (RuneBaseAttribute abr : attrs) { - int attrID = abr.getAttributeID(); - int value = abr.getModValue(); - switch (attrID) { - case MBServerStatics.RUNE_COST_ATTRIBUTE_ID: - available -= value; - break; - case MBServerStatics.RUNE_STR_ATTRIBUTE_ID: - str += value; - strMin += value; - break; - case MBServerStatics.RUNE_DEX_ATTRIBUTE_ID: - dex += value; - dexMin += value; - break; - case MBServerStatics.RUNE_CON_ATTRIBUTE_ID: - con += value; - conMin += value; - break; - case MBServerStatics.RUNE_INT_ATTRIBUTE_ID: - intt += value; - intMin += value; - break; - case MBServerStatics.RUNE_SPI_ATTRIBUTE_ID: - spi += value; - spiMin += value; - break; - case MBServerStatics.RUNE_STR_MAX_ATTRIBUTE_ID: - strMax += value; - break; - case MBServerStatics.RUNE_DEX_MAX_ATTRIBUTE_ID: - dexMax += value; - break; - case MBServerStatics.RUNE_CON_MAX_ATTRIBUTE_ID: - conMax += value; - break; - case MBServerStatics.RUNE_INT_MAX_ATTRIBUTE_ID: - intMax += value; - break; - case MBServerStatics.RUNE_SPI_MAX_ATTRIBUTE_ID: - spiMax += value; - break; - default: - } - } - - //Set titles based on rune.. - switch (rune.getRuneBaseID()) { - default: - break; - - case 2901: //CSR 1 - this.title = CharacterTitle.CSR_1; - break; - case 2902: //CSR 1 - this.title = CharacterTitle.CSR_2; - break; - case 2903: //CSR 1 - this.title = CharacterTitle.CSR_3; - break; - case 2904: //CSR 1 - this.title = CharacterTitle.CSR_4; - break; - - case 2910: //Wolfpack Developer - this.title = CharacterTitle.DEVELOPER; - break; - case 2911: //QA Test Rune - this.title = CharacterTitle.QA; - break; - } - } - - //hack check. Make sure available does not go below 0. - //subtract from each stat until available is 0 or greater. - if (available < 0) { - while (this.spiMod.get() > 0 && available < 0) { - this.spiMod.decrementAndGet(); - spi--; - available++; - } - while (this.conMod.get() > 0 && available < 0) { - this.conMod.decrementAndGet(); - con--; - available++; - } - while (this.strMod.get() > 0 && available < 0) { - this.strMod.decrementAndGet(); - str--; - available++; - } - while (this.dexMod.get() > 0 && available < 0) { - this.dexMod.decrementAndGet(); - dex--; - available++; - } - while (this.intMod.get() > 0 && available < 0) { - this.intMod.decrementAndGet(); - intt--; - available++; - } - - //update database - this.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); - } - - this.statStrBase = (short) str; - this.statDexBase = (short) dex; - this.statConBase = (short) con; - this.statIntBase = (short) intt; - this.statSpiBase = (short) spi; - this.statStrMax = (short) (strMax); - this.statDexMax = (short) (dexMax); - this.statConMax = (short) (conMax); - this.statIntMax = (short) (intMax); - this.statSpiMax = (short) (spiMax); - this.statStrMin = (short) strMin; - this.statDexMin = (short) dexMin; - this.statConMin = (short) conMin; - this.statIntMin = (short) intMin; - this.statSpiMin = (short) spiMin; - this.unusedStatPoints = (short) available; - this.trainedStatPoints = 0; - - // Testing, allow characters to have more stats then normal for formula checking - if (this.statStrBase > this.statStrMax) - this.statStrMax = this.statStrBase; - if (this.statDexBase > this.statDexMax) - this.statDexMax = this.statDexBase; - if (this.statConBase > this.statConMax) - this.statConMax = this.statConBase; - if (this.statIntBase > this.statIntMax) - this.statIntMax = this.statIntBase; - if (this.statSpiBase > this.statSpiMax) - this.statSpiMax = this.statSpiBase; - - // Modified stats must be recalculated when base stats are - //calculateModifiedStats(); - //update hide and seeInvis levels - if (this.bonuses != null) { - this.hidden = (int)bonuses.getFloat(ModType.Invisible, SourceType.None); - this.seeInvis = (int) bonuses.getFloat(ModType.SeeInvisible, SourceType.None); - } else { - this.hidden = (byte) 0; - this.seeInvis = (byte) 0; - } - - //check is player is a CSR - this.isCSR = this.containsCSRRune(); - } - - private boolean containsCSRRune() { - - if (this.race != null && this.race.getRaceType().equals(RaceType.CSRMALE)) - return true; - - if (this.baseClass != null && this.baseClass.getObjectUUID() > 2900 && this.baseClass.getObjectUUID() < 2905) - return true; - - if (this.promotionClass != null && this.promotionClass.getObjectUUID() > 2900 && this.promotionClass.getObjectUUID() < 2905) - return true; - - if (this.runes == null) - return false; - - for (CharacterRune rune : this.runes) { - - if (rune == null || rune.getRuneBase() == null) - continue; - - RuneBase rb = rune.getRuneBase(); - - if (rb.getObjectUUID() > 2900 && rb.getObjectUUID() < 2905) - return true; - if (rb.getObjectUUID() == 2910) - return true; - - } - return false; - } - - public boolean isCSR() { - return this.isCSR; - } - - public void setAsciiLastName(boolean value) { - this.asciiLastName = value; - } - - public boolean _asciiLastName() { - return this.asciiLastName; - } - - public static boolean hideNonAscii() { - - return false; - } - - /** - * @ Calculates Modified Stats Call this when changing equipment or - * add/removing effect. skips base stat modification. - */ - public void calculateModifiedStats() { - float strVal = this.statStrBase; - float dexVal = this.statDexBase; - float conVal = this.statConBase; - float intVal = this.statIntBase; - float spiVal = this.statSpiBase; - - this.dexPenalty = getDexPenalty(); - - // TODO modify for equipment - if (this.bonuses != null) { - // modify for effects - strVal += Math.round(this.bonuses.getFloat(ModType.Attr, SourceType.Strength)); - dexVal += Math.round(this.bonuses.getFloat(ModType.Attr, SourceType.Dexterity)); - conVal += Math.round(this.bonuses.getFloat(ModType.Attr, SourceType.Constitution)); - intVal += Math.round(this.bonuses.getFloat(ModType.Attr, SourceType.Intelligence)); - spiVal += Math.round(this.bonuses.getFloat(ModType.Attr, SourceType.Spirit)); - - // apply dex penalty for armor - dexVal *= this.dexPenalty; - - // modify percent amounts. DO THIS LAST! - strVal *= (1 + this.bonuses.getFloatPercentAll(ModType.Attr, SourceType.Strength)); - dexVal *= (1 + this.bonuses.getFloatPercentAll(ModType.Attr, SourceType.Dexterity)); - conVal *= (1 + this.bonuses.getFloatPercentAll(ModType.Attr, SourceType.Constitution)); - intVal *= (1 + this.bonuses.getFloatPercentAll(ModType.Attr, SourceType.Intelligence)); - spiVal *= (1 + this.bonuses.getFloatPercentAll(ModType.Attr, SourceType.Spirit)); - - } else - // apply dex penalty for armor - dexVal *= this.dexPenalty; - - // Set current stats - this.statStrCurrent = (strVal < 1) ? (short) 1 : (short) strVal; - this.statDexCurrent = (dexVal < 1) ? (short) 1 : (short) dexVal; - this.statConCurrent = (conVal < 1) ? (short) 1 : (short) conVal; - this.statIntCurrent = (intVal < 1) ? (short) 1 : (short) intVal; - this.statSpiCurrent = (spiVal < 1) ? (short) 1 : (short) spiVal; - - // recalculate skills - //CharacterSkill.updateAllBaseAmounts(this); - // recalculate Max Health/Mana/Stamina - //calculateMaxHealthManaStamina(); - // recalculate Resists - //this.resists.calculateResists(this); - } - - public float getDexPenalty() { - - if (this.charItemManager == null || this.charItemManager.getEquipped() == null) { - Logger.error( "Player " + this.getObjectUUID() + " missing equipment"); - return 1f; - } - - 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)); - return (1 - (dexPenalty / 100)); - } - - public static float getDexPenalty(Item armor) { - if (armor == null) - return 0f; - ItemBase ab = armor.getItemBase(); - if (ab == null) - return 0f; - return ab.getDexPenalty(); - } - - public int getStrForClient() { - return this.statStrCurrent - this.race.getStrStart() - this.baseClass.getStrMod(); - } - - public int getDexForClient() { - return this.statDexCurrent - this.race.getDexStart() - this.baseClass.getDexMod(); - } - - public int getConForClient() { - return this.statConCurrent - this.race.getConStart() - this.baseClass.getConMod(); - } - - public int getIntForClient() { - return this.statIntCurrent - this.race.getIntStart() - this.baseClass.getIntMod(); - } - - public int getSpiForClient() { - return this.statSpiCurrent - this.race.getSpiStart() - this.baseClass.getSpiMod(); - } - - public int getTrainsAvailable() { - return this.trainsAvailable.get(); - } - - public void modifyTrainsAvailable(int amount) { - boolean worked = false; - while (!worked) { - int old = this.trainsAvailable.get(); - int newVal = old + amount; - // if (newVal < 0) - // newVal = 0; - worked = this.trainsAvailable.compareAndSet(old, newVal); - } - } - - // Reset any data that should not persist from a previous session - public void resetDataAtLogin() { - loadedObjects.clear(); - loadedStaticObjects.clear(); - lastStaticLoc = Vector3fImmutable.ZERO; - setLastTarget(GameObjectType.unknown, 0); - this.follow = false; - } - - /** - * @ Calculates Atr (both hands) Defense, and Damage for pc - */ - public void calculateAtrDefenseDamage() { - if (this.charItemManager == null || this.charItemManager.getEquipped() == null || this.skills == null) { - Logger.error("Player " + this.getObjectUUID() + " missing skills or equipment"); - defaultAtrAndDamage(true); - defaultAtrAndDamage(false); - this.defenseRating = 0; - return; - } - ConcurrentHashMap equipped = this.charItemManager.getEquipped(); - - // // Reset passives - // if (this.bonuses != null) { - // this.bonuses.setBool("Block", false); - // this.bonuses.setBool("Parry", false); - // if (this.baseClass != null && this.baseClass.getUUID() == 2502) - // this.bonuses.setBool("Dodge", true); - // else - // this.bonuses.setBool("Dodge", false); - // } - // calculate atr and damage for each hand - calculateAtrDamageForWeapon(equipped.get(MBServerStatics.SLOT_MAINHAND), true, equipped.get(MBServerStatics.SLOT_OFFHAND)); - calculateAtrDamageForWeapon(equipped.get(MBServerStatics.SLOT_OFFHAND), false, equipped.get(MBServerStatics.SLOT_MAINHAND)); - - // No Defense while in DeathShroud - if (this.effects != null && this.effects.containsKey("DeathShroud")) - this.defenseRating = (short) 0; - else { - // calculate defense for equipment - float defense = this.statDexCurrent * 2; - defense += getShieldDefense(equipped.get(MBServerStatics.SLOT_OFFHAND)); - defense += getArmorDefense(equipped.get(MBServerStatics.SLOT_HELMET)); - defense += getArmorDefense(equipped.get(MBServerStatics.SLOT_CHEST)); - defense += getArmorDefense(equipped.get(MBServerStatics.SLOT_ARMS)); - defense += getArmorDefense(equipped.get(MBServerStatics.SLOT_GLOVES)); - defense += getArmorDefense(equipped.get(MBServerStatics.SLOT_LEGGINGS)); - defense += getArmorDefense(equipped.get(MBServerStatics.SLOT_FEET)); - defense += getWeaponDefense(equipped); - - if (this.bonuses != null) { - // add any bonuses - defense += (short) this.bonuses.getFloat(ModType.DCV, SourceType.None); - - // Finally multiply any percent modifiers. DO THIS LAST! - float pos_Bonus = this.bonuses.getFloatPercentPositive(ModType.DCV, SourceType.None); - defense = (short) (defense * (1 + pos_Bonus)); - - //Lucky rune applies next - //applied runes will be calculated and added to the normal bonuses. no need for this garbage anymore - //defense = (short) (defense * (1 + ((float) this.bonuses.getShort("rune.Defense") / 100))); - - //and negative percent modifiers - //already done... - float neg_Bonus = this.bonuses.getFloatPercentNegative(ModType.DCV, SourceType.None); - defense = (short) (defense *(1 + neg_Bonus)); - - } else - // TODO add error log here - Logger.error( "Error: missing bonuses"); - - defense = (defense < 1) ? 1 : defense; - this.defenseRating = (short) (defense + 0.5f); - } - } - - /** - * @ Calculates Atr, and Damage for each weapon - */ - private void calculateAtrDamageForWeapon(Item weapon, boolean mainHand, Item otherHand) { - - // make sure weapon exists - boolean noWeapon = false; - ItemBase wb = null; - if (weapon == null) - noWeapon = true; - else { - ItemBase ib = weapon.getItemBase(); - if (ib == null) - noWeapon = true; - else - if (!ib.getType().equals(ItemType.WEAPON)) { - defaultAtrAndDamage(mainHand); - return; - } else - wb = ib; - } - float skillPercentage, masteryPercentage; - float mastDam; - float min, max; - float speed = 20f; - boolean strBased = false; - - ItemBase wbMain = (weapon != null) ? weapon.getItemBase() : null; - ItemBase wbOff = (otherHand != null) ? otherHand.getItemBase() : null; - - // get skill percentages and min and max damage for weapons - if (noWeapon) { - if (mainHand) { - Item off = this.charItemManager.getEquipped().get(MBServerStatics.SLOT_OFFHAND); - if (off != null && off.getItemBase() != null && off.getItemBase().getType().equals(ItemType.WEAPON)) - this.rangeHandOne = 10 * (1 + (this.statStrBase / 600)); // Set - // to - // no - // weapon - // range - else - this.rangeHandOne = -1; // set to do not attack - } else - this.rangeHandTwo = -1; // set to do not attack - - skillPercentage = getModifiedAmount(this.skills.get("Unarmed Combat")); - masteryPercentage = getModifiedAmount(this.skills.get("Unarmed Combat Mastery")); - if (masteryPercentage == 0f) - mastDam = CharacterSkill.getQuickMastery(this, "Unarmed Combat Mastery"); - else - mastDam = masteryPercentage; - // TODO Correct these - min = 1; - max = 3; - } else { - if (mainHand) - this.rangeHandOne = weapon.getItemBase().getRange() * (1 + (this.statStrBase / 600)); - else - this.rangeHandTwo = weapon.getItemBase().getRange() * (1 + (this.statStrBase / 600)); - - if (this.bonuses != null){ - float range_bonus = 1 + this.bonuses.getFloatPercentAll(ModType.WeaponRange, SourceType.None); - - if (mainHand) - this.rangeHandOne *= range_bonus; - else - this.rangeHandTwo *= range_bonus; - - } - skillPercentage = getModifiedAmount(this.skills.get(wb.getSkillRequired())); - masteryPercentage = getModifiedAmount(this.skills.get(wb.getMastery())); - if (masteryPercentage == 0f) - mastDam = 0f; - // mastDam = CharacterSkill.getQuickMastery(this, wb.getMastery()); - else - mastDam = masteryPercentage; - min = (float) wb.getMinDamage(); - max = (float) wb.getMaxDamage(); - strBased = wb.isStrBased(); - - // - // Add parry bonus for weapon and allow parry if needed - - // // Only Fighters and Thieves can Parry - // if ((this.baseClass != null && this.baseClass.getUUID() == 2500) - // || (this.promotionClass != null && this.promotionClass.getUUID() == 2520)) { - // if (wbMain == null || wbMain.getRange() < MBServerStatics.RANGED_WEAPON_RANGE) - // if (wbOff == null || wbOff.getRange() < MBServerStatics.RANGED_WEAPON_RANGE) - // this.bonuses.setBool("Parry", true); - // } - // } - } - - if (this.effects != null && this.effects.containsKey("DeathShroud")) - // No Atr in deathshroud. - if (mainHand) - this.atrHandOne = (short) 0; - else - this.atrHandTwo = (short) 0; - else { - // calculate atr - float atr = 0; - atr += (int) skillPercentage * 4f; //<-round down skill% - - atr += (int) masteryPercentage * 3f; - if (this.statStrCurrent > this.statDexCurrent) - atr += statStrCurrent / 2; - else - atr += statDexCurrent / 2; - - // add in any bonuses to atr - if (this.bonuses != null) { - // Add any base bonuses - atr += this.bonuses.getFloat(ModType.OCV, SourceType.None); - - // Finally use any multipliers. DO THIS LAST! - float pos_Bonus = (1 + this.bonuses.getFloatPercentPositive(ModType.OCV, SourceType.None)); - atr *= pos_Bonus; - - // next precise - //runes will have their own bonuses. - // atr *= (1 + ((float) this.bonuses.getShort("rune.Attack") / 100)); - - //and negative percent modifiers - float neg_Bonus = this.bonuses.getFloatPercentNegative(ModType.OCV, SourceType.None); - - atr *= (1 + neg_Bonus); - } - - atr = (atr < 1) ? 1 : atr; - - // set atr - if (mainHand) - this.atrHandOne = (short) (atr + 0.5f); - else - this.atrHandTwo = (short) (atr + 0.5f); - } - - //calculate speed - if (wb != null) - speed = wb.getSpeed(); - else - speed = 20f; //unarmed attack speed - if (weapon != null) - speed *= (1 + this.bonuses.getFloatPercentAll(ModType.WeaponSpeed, SourceType.None)); - speed *= (1 + this.bonuses.getFloatPercentAll(ModType.AttackDelay, SourceType.None)); - if (speed < 10) - speed = 10; - - //add min/max damage bonuses for weapon - if (weapon != null) { - // Add any base bonuses - - min += weapon.getBonus(ModType.MinDamage, SourceType.None); - max += weapon.getBonus(ModType.MaxDamage, SourceType.None); - - min += weapon.getBonus(ModType.MeleeDamageModifier, SourceType.None); - max += weapon.getBonus(ModType.MeleeDamageModifier, SourceType.None); - // Finally use any multipliers. DO THIS LAST! - - float percentMinDamage = 1; - float percentMaxDamage = 1; - - percentMinDamage += weapon.getBonusPercent(ModType.MinDamage, SourceType.None); - percentMinDamage += weapon.getBonusPercent(ModType.MeleeDamageModifier, SourceType.None); - - percentMaxDamage += weapon.getBonusPercent(ModType.MaxDamage, SourceType.None); - percentMaxDamage += weapon.getBonusPercent(ModType.MeleeDamageModifier, SourceType.None); - - - - min *= percentMinDamage; - max *= percentMaxDamage; - } - - //if duel wielding, cut damage by 30% - if (otherHand != null) { - ItemBase ibo = otherHand.getItemBase(); - if (ibo != null && ibo.getType().equals(ItemType.WEAPON)) { - min *= 0.7f; - max *= 0.7f; - } - } - - // calculate damage - float minDamage; - float maxDamage; - float pri = (strBased) ? (float) this.statStrCurrent : (float) this.statDexCurrent; - float sec = (strBased) ? (float) this.statDexCurrent : (float) this.statStrCurrent; - minDamage = (float) (min * ((0.0315f * Math.pow(pri, 0.75f)) + (0.042f * Math.pow(sec, 0.75f)) + (0.01f * ((int) skillPercentage + (int) mastDam)))); - maxDamage = (float) (max * ((0.0785f * Math.pow(pri, 0.75f)) + (0.016f * Math.pow(sec, 0.75f)) + (0.0075f * ((int) skillPercentage + (int) mastDam)))); - minDamage = (float) ((int) (minDamage + 0.5f)); //round to nearest decimal - maxDamage = (float) ((int) (maxDamage + 0.5f)); //round to nearest decimal - - // Half damage if in death shroud - if (this.effects != null && this.effects.containsKey("DeathShroud")) { - minDamage *= 0.5f; - maxDamage *= 0.5f; - } - - // add in any bonuses to damage - if (this.bonuses != null) { - // Add any base bonuses - minDamage += this.bonuses.getFloat(ModType.MinDamage, SourceType.None); - maxDamage += this.bonuses.getFloat(ModType.MaxDamage, SourceType.None); - - minDamage += this.bonuses.getFloat(ModType.MeleeDamageModifier, SourceType.None); - maxDamage += this.bonuses.getFloat(ModType.MeleeDamageModifier, SourceType.None); - // Finally use any multipliers. DO THIS LAST! - - float percentMinDamage = 1; - float percentMaxDamage = 1; - - percentMinDamage += this.bonuses.getFloatPercentAll(ModType.MinDamage, SourceType.None); - percentMinDamage += this.bonuses.getFloatPercentAll(ModType.MeleeDamageModifier, SourceType.None); - - percentMaxDamage += this.bonuses.getFloatPercentAll(ModType.MaxDamage, SourceType.None); - percentMaxDamage += this.bonuses.getFloatPercentAll(ModType.MeleeDamageModifier, SourceType.None); - - minDamage *= percentMinDamage; - maxDamage *= percentMaxDamage; - - } - - // set damages - if (mainHand) { - this.minDamageHandOne = (int) minDamage; - this.maxDamageHandOne = (int) maxDamage; - this.speedHandOne = speed; - } else { - this.minDamageHandTwo = (int) minDamage; - this.maxDamageHandTwo = (int) maxDamage; - this.speedHandTwo = speed; - } - } - - /** - * @ Calculates Defense for shield - */ - private float getShieldDefense(Item shield) { - if (shield == null) - return 0; - ItemBase ab = shield.getItemBase(); - if (ab == null || !ab.isShield()) - return 0; - CharacterSkill blockSkill = this.skills.get("Block"); - float skillMod; - if (blockSkill == null) { - skillMod = 0; - } else - skillMod = blockSkill.getModifiedAmount(); - - float def = ab.getDefense(); - //apply item defense bonuses - if (shield != null){ - def += shield.getBonus(ModType.DR, SourceType.None); - def *= (1 + shield.getBonusPercent(ModType.DR, SourceType.None)); - - } - - // float val = ((float)ab.getDefense()) * (1 + (skillMod / 100)); - return (def * (1 + ((int) skillMod / 100f))); - } - - public void setPassives() { - if (this.bonuses != null) { - ConcurrentHashMap equipped = this.charItemManager.getEquipped(); - Item off = equipped.get(MBServerStatics.SLOT_OFFHAND); - Item main = equipped.get(MBServerStatics.SLOT_MAINHAND); - ItemBase wbMain = null; - ItemBase wbOff = null; - if (main != null) - wbMain = main.getItemBase(); - if (off != null) - wbOff = off.getItemBase(); - - //set block if block found - this.bonuses.setBool(ModType.Block,SourceType.None, false); - if (this.baseClass != null && (this.baseClass.getObjectUUID() == 2500 || this.baseClass.getObjectUUID() == 2501)) - if (off != null && off.getItemBase() != null && off.getItemBase().isShield()) - this.bonuses.setBool(ModType.Block,SourceType.None, true); - - //set dodge if rogue - if (this.baseClass != null && this.baseClass.getObjectUUID() == 2502) - this.bonuses.setBool(ModType.Dodge,SourceType.None, true); - else - this.bonuses.setBool(ModType.Dodge,SourceType.None, false); - - //set parry if fighter or thief and no invalid weapon found - this.bonuses.setBool(ModType.Parry,SourceType.None, false); - if ((this.baseClass != null && this.baseClass.getObjectUUID() == 2500) - || (this.promotionClass != null && this.promotionClass.getObjectUUID() == 2520)) - if (wbMain == null || wbMain.getRange() < MBServerStatics.RANGED_WEAPON_RANGE) - if (wbOff == null || wbOff.getRange() < MBServerStatics.RANGED_WEAPON_RANGE) - this.bonuses.setBool(ModType.Parry,SourceType.None, true); - - } - - } - - /** - * @ Calculates Defense for armor - */ - private float getArmorDefense(Item armor) { - - if (armor == null) - return 0; - - ItemBase ib = armor.getItemBase(); - - if (ib == null) - return 0; - - if (!ib.getType().equals(ItemType.ARMOR)) - return 0; - if (ib.getSkillRequired().isEmpty()) - return ib.getDefense(); - CharacterSkill armorSkill = this.skills.get(ib.getSkillRequired()); - if (armorSkill == null) { - Logger.error( "Player " + this.getObjectUUID() - + " has armor equipped without the nescessary skill to equip it"); - return ib.getDefense(); - } - - float def = ib.getDefense(); - //apply item defense bonuses - if (armor != null){ - def += armor.getBonus(ModType.DR, SourceType.None); - def *= (1 + armor.getBonusPercent(ModType.DR, SourceType.None)); - } - - - return (def * (1 + ((int) armorSkill.getModifiedAmount() / 50f))); - } - - /** - * @ Calculates Defense for weapon - */ - private float getWeaponDefense(ConcurrentHashMap equipped) { - Item weapon = equipped.get(MBServerStatics.SLOT_MAINHAND); - ItemBase wb = null; - CharacterSkill skill, mastery; - float val = 0; - boolean unarmed = false; - if (weapon == null) { - weapon = equipped.get(MBServerStatics.SLOT_OFFHAND); - if (weapon == null || weapon.getItemBase().isShield()) - unarmed = true; - else - wb = weapon.getItemBase(); - } else - wb = weapon.getItemBase(); - if (wb == null) - unarmed = true; - if (unarmed) { - skill = this.skills.get("Unarmed Combat"); - mastery = this.skills.get("Unarmed Combat Mastery"); - } else { - skill = this.skills.get(wb.getSkillRequired()); - mastery = this.skills.get(wb.getMastery()); - } - if (skill != null) - val += (int) skill.getModifiedAmount() / 2f; - if (mastery != null) - val += (int) mastery.getModifiedAmount() / 2f; - return val; - } - - private static float getModifiedAmount(CharacterSkill skill) { - if (skill == null) - return 0f; - return skill.getModifiedAmount(); - } - - //Call this function to recalculate granted skills and powers for player - public synchronized void calculateSkills() { - //tell the player to applyBonuses because something has changed - - runSkillCalc(); - - //start running the skill/power calculations - } - - //Don't call this function directly. linked from pc.calculateSkills() - //through SkillCalcJob. Designed to only run from one worker thread - public void runSkillCalc() { - try { - - //see if any new skills or powers granted - CharacterSkill.calculateSkills(this); - // calculate granted Trains in powers. - CharacterPower.grantTrains(this); - //see if any new powers unlocked from previous check - CharacterPower.calculatePowers(this); - - } catch (Exception e) { - } - - } - - 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()); - } - - } - - //calculate item bonuses here - public void calculateItemBonuses() { - if (this.charItemManager == null || this.bonuses == null) - return; - ConcurrentHashMap equipped = this.charItemManager.getEquipped(); - for (Item item : equipped.values()) { - ItemBase ib = item.getItemBase(); - if (ib == null) - continue; - //TODO add effect bonuses in here for equipped items - } - } - - /** - * @ Defaults ATR, Defense and Damage for player - */ - private void defaultAtrAndDamage(boolean mainHand) { - if (mainHand) { - this.atrHandOne = 0; - this.minDamageHandOne = 0; - this.maxDamageHandOne = 0; - this.rangeHandOne = -1; - this.speedHandOne = 20; - } else { - this.atrHandTwo = 0; - this.minDamageHandTwo = 0; - this.maxDamageHandTwo = 0; - this.rangeHandTwo = -1; - this.speedHandTwo = 20; - } - } - - public void calculateMaxHealthManaStamina() { - float h = 1f; - float m = 0f; - float s = 0f; - float baseHealth = 15f; - float baseMana = 5f; - float baseStamina = 1f; - float promoHealth = 0f; - float promoMana = 0f; - float promoStamina = 0f; - float raceHealth = 0f; - float raceMana = 0f; - float raceStamina = 0f; - float toughness = 0f; - float athletics = 0f; - - //get baseclass modifiers - if (this.baseClass != null) { - baseHealth = this.baseClass.getHealthMod(); - baseMana = this.baseClass.getManaMod(); - baseStamina = this.baseClass.getStaminaMod(); - } else { - //TODO log error here - } - - //get promotion modifiers - if (this.promotionClass != null) { - promoHealth = this.promotionClass.getHealthMod(); - promoMana = this.promotionClass.getManaMod(); - promoStamina = this.promotionClass.getStaminaMod(); - } - - // next get racial modifer - if (this.race != null) { - raceHealth += this.race.getHealthBonus(); - raceMana += this.race.getManaBonus(); - raceStamina += this.race.getStaminaBonus(); - } else { - //TODO log error here - } - - //Get level modifers - float f = 0; - float g = 0; - if (this.level < 10 || this.promotionClass == null) - f = this.level; - else if (this.level < 20) { - f = this.level; - g = this.level - 9; - } else if (level < 30) { - f = (float) (19 + (this.level - 19) * 0.8); - g = (float) (10 + (this.level - 19) * 0.8); - } else if (level < 40) { - f = (float) (27 + (this.level - 29) * 0.6); - g = (float) (18 + (this.level - 29) * 0.6); - } else if (level < 50) { - f = (float) (33 + (this.level - 39) * 0.4); - g = (float) (24 + (this.level - 39) * 0.4); - } else if (level < 60) { - f = (float) (37 + (this.level - 49) * 0.2); - g = (float) (28 + (this.level - 49) * 0.2); - } else { - f = (float) (39 + (this.level - 59) * 0.1); - g = (float) (30 + (this.level - 59) * 0.1); - } - - //get toughness and athletics amount - if (this.skills != null) { - if (this.skills.containsKey("Toughness")) - toughness = this.skills.get("Toughness").getModifiedAmount(); - if (this.skills.containsKey("Athletics")) - athletics = this.skills.get("Athletics").getModifiedAmount(); - } - - h = (((f * baseHealth) + (g * promoHealth)) * (0.3f + (0.005f * this.statConCurrent)) + (this.statConCurrent + raceHealth)) * (1 + (int) toughness / 400f); - m = ((f * baseMana) + (g * promoMana)) * (0.3f + (0.005f * this.statSpiCurrent)) + (this.statSpiCurrent + raceMana); - s = (((f * baseStamina) + (g * promoStamina)) * (0.3f + (0.005f * this.statConCurrent)) + (this.statConCurrent + raceStamina)) * (1 + (int) athletics / 300f); - - // s = f * (baseStamina + 1.75f) * .5f + this.statConCurrent + raceStamina; - // Apply any bonuses from runes and effects - if (this.bonuses != null) { - - - //apply effects - h += this.bonuses.getFloat(ModType.HealthFull, SourceType.None); - m += this.bonuses.getFloat(ModType.ManaFull, SourceType.None); - s += this.bonuses.getFloat(ModType.StaminaFull, SourceType.None); - - h *= (1 +this.bonuses.getFloatPercentAll(ModType.HealthFull, SourceType.None)) ; - m *= (1+this.bonuses.getFloatPercentAll(ModType.ManaFull, SourceType.None)); - s *= (1+this.bonuses.getFloatPercentAll(ModType.StaminaFull, SourceType.None)); - - } - - // Set max health, mana and stamina - if (h > 0) - this.healthMax = h; - else - this.healthMax = 1; - if (m > -1) - this.manaMax = m; - else - this.manaMax = 0; - if (s > -1) - this.staminaMax = s; - else - this.staminaMax = 0; - - // Update health, mana and stamina if needed - if (this.getCurrentHitpoints() > this.healthMax) - this.setHealth(this.healthMax); - if (this.mana.get() > this.manaMax) - this.mana.set(this.manaMax); - if (this.stamina.get() > this.staminaMax) - this.stamina.set(staminaMax); - } - - @Override - public float getPassiveChance(String type, int attackerLevel, boolean fromCombat) { - if (this.skills == null || this.bonuses == null) - return 0f; - - ModType modType = ModType.GetModType(type); - - // must be allowed to use this passive - if (!this.bonuses.getBool(modType, SourceType.None)) - return 0f; - - // must not be stunned - if (this.bonuses.getBool(ModType.Stunned, SourceType.None)) - return 0f; - - // Get base skill amount - CharacterSkill sk = this.skills.get(type); - float amount; - if (sk == null) - amount = CharacterSkill.getQuickMastery(this, type); - else - amount = sk.getModifiedAmount(); - - // Add bonuses - amount += this.bonuses.getFloat(modType, SourceType.None); - - // Add item bonuses and return - if (type.equals(ModType.Dodge) && !fromCombat) - return ((amount / 4) - attackerLevel + this.getLevel()) / 4; - else - return (amount - attackerLevel + this.getLevel()) / 4; - } - - public float getPassiveChance1(ModType modType, SourceType sourceType, int attackerLevel, boolean fromCombat) { - if (this.skills == null || this.bonuses == null) - return 0f; - - // must be allowed to use this passive - if (!this.bonuses.getBool(modType, sourceType)) - return 0f; - - // must not be stunned - if (this.bonuses.getBool(ModType.Stunned, SourceType.None)) - return 0f; - - // Get base skill amount - CharacterSkill sk = this.skills.get(sourceType.name()); - float amount; - if (sk == null) - amount = CharacterSkill.getQuickMastery(this, modType.name()); - else - amount = sk.getModifiedAmount(); - - // Add bonuses - amount += this.bonuses.getFloat(modType, sourceType); - - // Add item bonuses and return - if (sourceType.equals(SourceType.Dodge) && !fromCombat) - return ((amount / 4) - attackerLevel + this.getLevel()) / 4; - else - return (amount - attackerLevel + this.getLevel()) / 4; - } - - public float getRegenModifier(ModType type) { - float regen = 1f; - - if (this.bonuses != null) - // get regen bonus from effects - regen = this.bonuses.getRegen(type); - return regen; - } - - @Override - public boolean canBeLooted() { - return !this.isAlive(); - } - - @Override - public void setLevel(short targetLevel) { - - short tmpLevel; - - tmpLevel = targetLevel; - - tmpLevel = (short) Math.min(tmpLevel, 75); - - while (this.level < tmpLevel) { - grantXP(Experience.getBaseExperience(tmpLevel) - this.exp); - } - - } - - 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."); - - for (Item e : this.charItemManager.getEquipped().values()) { - e.removeFromCache(); - } - - for (Item i : this.charItemManager.getInventory(true)) { - i.removeFromCache(); - } - - for (Item b : this.charItemManager.getBank()) { - b.removeFromCache(); - } - - if (this.account.getLastCharIDUsed() == this.getObjectUUID()) - for (Item v : this.charItemManager.getVault()) { - v.removeFromCache(); - } - - for (CharacterSkill cs : this.getSkills().values()) { - cs.removeFromCache(); - } - - for (CharacterPower ps : this.getPowers().values()) { - ps.removeFromCache(); - } - - for (CharacterRune cr : this.runes) { - cr.removeFromCache(); - } - - super.removeFromCache(); - } - - 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 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() { - } - - @Override - public void runAfterLoad() { - - // Create player bounds object - - // if ((MBServer.getApp() instanceof engine.server.world.WorldServer)) - // DbManager.GuildQueries.LOAD_GUILD_HISTORY_FOR_PLAYER(this); - - Bounds playerBounds = Bounds.borrow(); - playerBounds.setBounds(this.getLoc()); - this.setBounds(playerBounds); - } - - @Override - protected ConcurrentHashMap initializePowers() { - return DbManager.CharacterPowerQueries.GET_POWERS_FOR_CHARACTER(this); - } - - @Override - public final void setFirstName(final String name) { - super.setFirstName(name); - } - - @Override - public void setLastName(final String name) { - super.setLastName(name); - } - - @Override - public short getLevel() { - return this.getPCLevel(); - } - - @Override - public boolean asciiLastName() { - return this._asciiLastName(); - } - - @Override - public void setGuild(Guild value) { - - if (value == null) - value = Guild.getErrantGuild(); - - int guildID = 0; - - if (!value.isEmptyGuild()) - guildID = value.getObjectUUID(); - DbManager.PlayerCharacterQueries.UPDATE_GUILD(this, guildID); - super.setGuild(value); - - // Player changed guild so let's invalidate the login server - // cache to reflect this event. - - //Update player bind location; - - Building cityTol = null; - - if (value.getOwnedCity() != null) - cityTol = value.getOwnedCity().getTOL(); - - this.setBindBuildingID(cityTol != null ? cityTol.getObjectUUID() : 0); - //update binds, checks for nation tol if guild tol == null; - PlayerCharacter.getUpdatedBindBuilding(this); - - - DbManager.AccountQueries.INVALIDATE_LOGIN_CACHE(this.getObjectUUID(), "character"); - } - - public long getSummoner(int summoner) { - synchronized (this.summoners) { - if (!this.summoners.containsKey(summoner)) - return 0; - return this.summoners.get(summoner); - } - } - - public void addSummoner(int summoner, long time) { - synchronized (this.summoners) { - this.summoners.put(summoner, time); - } - } - - public void removeSummoner(int summoner) { - synchronized (this.summoners) { - if (this.summoners.containsKey(summoner)) - this.summoners.remove(summoner); - } - } - - 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.setMob(); - 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; - } - - public boolean isNoTeleScreen() { - return noTeleScreen; - } - - public void setNoTeleScreen(boolean noTeleScreen) { - this.noTeleScreen = noTeleScreen; - } - - private double getDeltaTime() { - - return (System.currentTimeMillis() - lastUpdateTime) * .001f; - } - - private double getStamDeltaTime() { - - 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; - } - - // Method is called by Server Heartbeat simulation tick. - // Stat regen and transform updates should go in here. - - @Override - public void update() { - - if (this.updateLock.writeLock().tryLock()){ - try{ - - if (!this.isAlive()) - return; - - updateLocation(); - updateMovementState(); - updateRegen(); - - if (this.getStamina() < 10){ - if (this.getAltitude() > 0 || this.getDesiredAltitude() > 0){ - PlayerCharacter.GroundPlayer(this); - updateRegen(); - } - } - - RealmMap.updateRealm(this); - updateBlessingMessage(); - - this.safeZone = this.isInSafeZone(); - - }catch(Exception e){ - Logger.error(e); - }finally{ - this.updateLock.writeLock().unlock(); - } - } - } - @Override - public void updateFlight() { - - if (this.getAltitude() == 0 && this.getTakeOffTime() == 0) - return; - - if (this.getTakeOffTime() == 0) - return; - - if (this.getAltitude() == this.getDesiredAltitude()){ - if (this.getDesiredAltitude() == 0) - this.syncClient(); - //landing in a building, mark altitude to 0 as player is no longer flying. - if (this.landingRegion != null){ - this.altitude = 0; - this.region = this.landingRegion; - this.loc = this.loc.setY(this.landingRegion.lerpY(this)); - } - else - this.altitude = this.getDesiredAltitude(); - - this.loc = this.loc.setY(HeightMap.getWorldHeight(this) + this.getAltitude()); - - this.setTakeOffTime(0); - MovementManager.finishChangeAltitude(this, this.getDesiredAltitude()); - - return; - } - - 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(){ - - - if (!this.isMoving()) - return; - - if (!this.isActive) - return; - - Vector3fImmutable newLoc = this.getMovementLoc(); - - if (this.isAlive() == false || this.getBonuses().getBool(ModType.Stunned, SourceType.None) || this.getBonuses().getBool(ModType.CannotMove, SourceType.None)) { - //Target is stunned or rooted. Don't move - this.stopMovement(newLoc); - this.region = AbstractWorldObject.GetRegionByWorldObject(this); - return; - } - if (newLoc.equals(this.getEndLoc())){ - this.stopMovement(newLoc); - this.region = AbstractWorldObject.GetRegionByWorldObject(this); - if (this.getDebug(1)) - ChatManager.chatSystemInfo( this, - "Arrived at End location. " + this.getEndLoc()); - return; - //Next upda - } - - setLoc(newLoc); - this.region = AbstractWorldObject.GetRegionByWorldObject(this); - - if (this.getDebug(1)) - ChatManager.chatSystemInfo(this, - "Distance to target " + this.getEndLoc().distance2D(this.getLoc()) + " speed " + this.getSpeed()); - - if (this.getStamina() < 10) - MovementManager.sendOOS(this); - - // if (MBServerStatics.MOVEMENT_SYNC_DEBUG || this.getDebug(1)) - // Logger.info("MovementManager", "Updating movement current loc:" + this.getLoc().getX() + " " + this.getLoc().getZ() - // + " end loc: " + this.getEndLoc().getX() + " " + this.getEndLoc().getZ() + " distance " + this.getEndLoc().distance2D(this.getLoc())); - - } - @Override - public void updateMovementState() { - - - if (this.enteredWorld) { - if (!this.lastSwimming) { - boolean enterWater = PlayerCharacter.enterWater(this); - - if (enterWater){ - this.lastSwimming = enterWater; - MovementManager.sendRWSSMsg(this); - - } - } else { - if (PlayerCharacter.LeaveWater(this)){ - this.lastSwimming = false; - if (!this.isMoving()) - MovementManager.sendRWSSMsg(this); - } - - } - - boolean breathe = PlayerCharacter.CanBreathe(this); - - if (breathe != this.canBreathe){ - this.canBreathe = breathe; - // ChatManager.chatSystemInfo(this, "Breathe : " + this.canBreathe); - this.syncClient(); - } - } - - //char is flying - if (this.isFlying() == true) { - this.movementState = MovementState.FLYING; - return; - } - // Char is not moving. Set sitting or idle - if (!this.isMoving()) { - - if (this.sit == true) - this.movementState = MovementState.SITTING; - else - this.movementState = MovementState.IDLE; - - return; - } else { - this.movementState = MovementState.RUNNING; - } - - // Char is swimming // we now are saving lastSwimstate boolean, use this instead of calling getSwimming again. - if (this.lastSwimming == true) { - this.movementState = MovementState.SWIMMING; - return; - } - - // Char is moving, yet not swimming or flying he must be running - this.movementState = MovementState.RUNNING; - - } - @Override - public void updateRegen() { - - float healthRegen = 0f; - float manaRegen = 0f; - float stamRegen = 0f; - - boolean updateClient = false; - - // Early exit if char is dead or disconnected - if ((this.isAlive() == false) - || (this.isActive() == false) || this.getLoc().x == 0 && this.getLoc().z == 0) - return; - - // Calculate Regen amount from last simulation tick - switch (this.movementState) { - - case IDLE: - - healthRegen = ((this.healthMax * MBServerStatics.HEALTH_REGEN_IDLE) + MBServerStatics.HEALTH_REGEN_IDLE_STATIC) * (getRegenModifier(ModType.HealthRecoverRate)); - - if (this.isCasting() || this.isItemCasting()) - healthRegen *= .75f; - // Characters regen mana when in only walk mode and idle - if (this.walkMode) - manaRegen = ((this.manaMax * MBServerStatics.MANA_REGEN_IDLE) * getRegenModifier(ModType.ManaRecoverRate)); - else if (!this.isCasting() && !this.isItemCasting()) - manaRegen = ((this.manaMax * MBServerStatics.MANA_REGEN_IDLE) * getRegenModifier(ModType.ManaRecoverRate)); - else - manaRegen = 0; - - if (!PlayerCharacter.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); - else - stamRegen =0 ; - break; - case SITTING: - healthRegen = ((this.healthMax * MBServerStatics.HEALTH_REGEN_SIT) + MBServerStatics.HEALTH_REGEN_SIT_STATIC) * getRegenModifier(ModType.HealthRecoverRate); - manaRegen = (this.manaMax * MBServerStatics.MANA_REGEN_SIT) * ( getRegenModifier(ModType.ManaRecoverRate)); - stamRegen = MBServerStatics.STAMINA_REGEN_SIT * getRegenModifier(ModType.StaminaRecoverRate); - break; - case RUNNING: - if (this.walkMode == true) { - healthRegen = ((this.healthMax * MBServerStatics.HEALTH_REGEN_WALK) + MBServerStatics.HEALTH_REGEN_IDLE_STATIC) * getRegenModifier(ModType.HealthRecoverRate); - manaRegen = this.manaMax * MBServerStatics.MANA_REGEN_WALK * getRegenModifier(ModType.ManaRecoverRate); - stamRegen = MBServerStatics.STAMINA_REGEN_WALK; - } else { - healthRegen =0; - manaRegen = 0; - - if (this.combat == true) - stamRegen = MBServerStatics.STAMINA_REGEN_RUN_COMBAT; - else - stamRegen = MBServerStatics.STAMINA_REGEN_RUN_NONCOMBAT; - } - break; - case FLYING: - - float seventyFive = this.staminaMax * .75f; - float fifty = this.staminaMax *.5f; - float twentyFive = this.staminaMax *.25f; - - if (this.getDesiredAltitude() == 0 && this.getAltitude() <= 10){ - if (this.isCombat()) - stamRegen = 0; - else - stamRegen = MBServerStatics.STAMINA_REGEN_IDLE * getRegenModifier(ModType.StaminaRecoverRate); - } - else if (!this.useFlyMoveRegen()){ - - healthRegen = ((this.healthMax * MBServerStatics.HEALTH_REGEN_IDLE) + MBServerStatics.HEALTH_REGEN_IDLE_STATIC) * ( getRegenModifier(ModType.HealthRecoverRate)); - - if (this.isCasting() || this.isItemCasting()) - healthRegen *= .75f; - // Characters regen mana when in only walk mode and idle - if (this.walkMode) - manaRegen = (this.manaMax * MBServerStatics.MANA_REGEN_IDLE + (this.getSpiMod() * .015f))* ( getRegenModifier(ModType.ManaRecoverRate)); - else if (!this.isCasting() && !this.isItemCasting()) - manaRegen = (this.manaMax * MBServerStatics.MANA_REGEN_IDLE + (this.getSpiMod() * .015f)) * ( getRegenModifier(ModType.ManaRecoverRate)); - else - manaRegen = 0; - - if (!this.isItemCasting() && !this.isCasting() || this.getTakeOffTime() != 0) - stamRegen = MBServerStatics.STAMINA_REGEN_FLY_IDLE; - else - stamRegen = -1f; - } - else - if (this.walkMode == true) { - healthRegen = ((this.healthMax * MBServerStatics.HEALTH_REGEN_WALK) + MBServerStatics.HEALTH_REGEN_IDLE_STATIC) * getRegenModifier(ModType.HealthRecoverRate); - manaRegen = ((this.manaMax * MBServerStatics.MANA_REGEN_WALK)+ (this.getSpiMod() * .015f)) * (getRegenModifier(ModType.ManaRecoverRate)); - stamRegen = MBServerStatics.STAMINA_REGEN_FLY_WALK; - } else { - healthRegen = 0; - manaRegen = 0; - if (this.isCombat()) - stamRegen = MBServerStatics.STAMINA_REGEN_FLY_RUN_COMBAT; - else - stamRegen = MBServerStatics.STAMINA_REGEN_FLY_RUN; - } - - float oldStamina = this.stamina.get(); - - if (FastMath.between(oldStamina, 0, twentyFive) && !this.wasTripped25){ - updateClient = true; - this.wasTripped25 = true; - this.wasTripped50 = false; - this.wasTripped75 = false; - }else if (FastMath.between(oldStamina, twentyFive, fifty) && !this.wasTripped50){ - updateClient = true; - this.wasTripped25 = false; - this.wasTripped50 = true; - this.wasTripped75 = false; - }else if (FastMath.between(oldStamina, fifty, seventyFive) && !this.wasTripped75){ - updateClient = true; - this.wasTripped25 = false; - this.wasTripped50 = false; - this.wasTripped75 = true; - } - break; - case SWIMMING: - if (this.walkMode == true) { - healthRegen = ((this.healthMax * MBServerStatics.HEALTH_REGEN_WALK) + MBServerStatics.HEALTH_REGEN_IDLE_STATIC) * getRegenModifier(ModType.HealthRecoverRate); - manaRegen = ((this.manaMax * MBServerStatics.MANA_REGEN_WALK)+ (this.getSpiMod() * .015f)) * ( getRegenModifier(ModType.ManaRecoverRate)); - stamRegen = MBServerStatics.STAMINA_REGEN_SWIM; - } else { - healthRegen = 0; - manaRegen = 0; - stamRegen = MBServerStatics.STAMINA_REGEN_SWIM; - - if (this.combat == true) - stamRegen += MBServerStatics.STAMINA_REGEN_RUN_COMBAT; - else - stamRegen += MBServerStatics.STAMINA_REGEN_RUN_NONCOMBAT; - } - break; - } - - // Are we drowning? - if ((this.getStamina() <= 0) - && (PlayerCharacter.CanBreathe(this) == false)) - healthRegen = (this.healthMax * -.03f); - - // Multiple regen values by current deltaTime - // Logger.info("", healthRegen + ""); - healthRegen *= getDeltaTime(); - manaRegen *= getDeltaTime(); - stamRegen *= getStamDeltaTime(); - - boolean workedHealth = false; - boolean workedMana = false; - boolean workedStamina = false; - - float old, mod; - while(!workedHealth || !workedMana || !workedStamina) { - if (!this.isAlive() || !this.isActive()) - return; - if (!workedHealth) { - old = this.health.get(); - mod = old + healthRegen; - if (mod > this.healthMax) - mod = healthMax; - else if (mod <= 0) { - if (this.isAlive.compareAndSet(true, false)) - killCharacter("Water"); - return; - } - workedHealth = this.health.compareAndSet(old, mod); - } - if (!workedStamina) { - old = this.stamina.get(); - mod = old + stamRegen; - if (mod > this.staminaMax) - mod = staminaMax; - else if (mod < 0) - mod = 0; - workedStamina = this.stamina.compareAndSet(old, mod); - } - if (!workedMana) { - old = this.mana.get(); - mod = old + manaRegen; - if (mod > this.manaMax) - mod = manaMax; - else if (mod < 0) - mod = 0; - workedMana = this.mana.compareAndSet(old, mod); - } - } - - if (updateClient) - this.syncClient(); - - // Reset this char's frame time. - this.lastUpdateTime = System.currentTimeMillis(); - this.lastStamUpdateTime = System.currentTimeMillis(); - - } - - public synchronized void updateStamRegen(long time) { - - boolean disable = true; - - if (disable) - return; - - float stamRegen = 0f; - - // Early exit if char is dead or disconnected - if ((this.isAlive() == false) - || (this.isActive() == false) || this.getLoc().x == 0 && this.getLoc().z == 0) - return; - - // Calculate Regen amount from last simulation tick - switch (this.movementState) { - - case IDLE: - if (!PlayerCharacter.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); - else - stamRegen =0 ; - break; - case SITTING: - stamRegen = MBServerStatics.STAMINA_REGEN_SIT * getRegenModifier(ModType.StaminaRecoverRate); - break; - case RUNNING: - if (this.walkMode == true) { - stamRegen = MBServerStatics.STAMINA_REGEN_WALK; - } else { - if (this.combat == true) - stamRegen = MBServerStatics.STAMINA_REGEN_RUN_COMBAT; - else - stamRegen = MBServerStatics.STAMINA_REGEN_RUN_NONCOMBAT; - } - break; - case FLYING: - - if (this.getDesiredAltitude() == 0 && this.getAltitude() <= 10){ - if (this.isCombat()) - stamRegen = 0; - else - stamRegen = MBServerStatics.STAMINA_REGEN_IDLE * getRegenModifier(ModType.StaminaRecoverRate); - } - else if (!this.isMoving()){ - - - if (!this.isItemCasting() && !this.isCasting() || this.getTakeOffTime() != 0) - stamRegen = MBServerStatics.STAMINA_REGEN_FLY_IDLE; - else - stamRegen = -1f; - - } - else - - if (this.walkMode == true) { - - stamRegen = MBServerStatics.STAMINA_REGEN_FLY_WALK; - } else { - if (this.isCombat()) - stamRegen = MBServerStatics.STAMINA_REGEN_FLY_RUN_COMBAT; - else - stamRegen = MBServerStatics.STAMINA_REGEN_FLY_RUN; - } - break; - case SWIMMING: - if (this.walkMode == true) { - stamRegen = MBServerStatics.STAMINA_REGEN_SWIM; - } else { - stamRegen = MBServerStatics.STAMINA_REGEN_SWIM; - } - break; - } - - - - - // Multiple regen values by current deltaTime - // Logger.info("", healthRegen + ""); - - stamRegen *= (time * .001f); - - - - boolean workedStamina = false; - - - float old, mod; - while( !workedStamina) { - if (!this.isAlive() || !this.isActive()) - return; - - if (!workedStamina) { - old = this.stamina.get(); - mod = old + stamRegen; - if (mod > this.staminaMax) - mod = staminaMax; - else if (mod < 0) - mod = 0; - workedStamina = this.stamina.compareAndSet(old, mod); - } - - } - - } - - public void syncClient() { - - ModifyHealthMsg modifyHealthMsg = new ModifyHealthMsg(null, this, 0, 1, 1, -1984683793, "", 0, 652920987); - //mhm.setOmitFromChat(0); - Dispatch dispatch = Dispatch.borrow(this, modifyHealthMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - - } - - public MovementState getMovementState() { - 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; - } - - public void setHash() { - - this.hash = DataWarehouse.hasher.encrypt(this.getObjectUUID()); - - // Write hash to player character table - - DataWarehouse.writeHash(DataRecordType.CHARACTER, this.getObjectUUID()); - } - - public AtomicInteger getGuildStatus() { - return guildStatus; - } - - 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 void setLastRealmID(int lastRealmID) { - this.lastRealmID = lastRealmID; - } - - public int getLastRealmID() { - return lastRealmID; - } - - public int getSubRaceID() { - return subRaceID; - } - - public void setSubRaceID(int subRaceID) { - this.subRaceID = subRaceID; - } - - public ArrayList getGuildHistory() { - return guildHistory; - } - - public void setGuildHistory(ArrayList guildHistory) { - 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; - float unknownScale1 = 0; - float unknownScale2 = 0; - float unknownScale3 = 0; - - float scaleHeight = 0; - - if ((int) this.statStrBase > 40) - strengthScale = ((int) this.statStrBase - 40)* 0.0024999999f; //Y scale ? - - unknownScale1 = (float) (((int) this.statStrBase * 0.0024999999f + strengthScale + 0.89999998) * race.getRaceType().getScaleHeight()); - strengthScale = (int) this.statStrBase * 0.0037499999f + strengthScale + 0.85000002f; //strengthScale is different for x and z - - unknownScale2 = strengthScale * race.getRaceType().getScaleHeight(); //x scale? - unknownScale3 = strengthScale * race.getRaceType().getScaleHeight(); //z Scale? - - - - scaleHeight = (1.5f + unknownScale1); - - - - this.characterHeight = scaleHeight; - - this.centerHeight = scaleHeight; - - } - - public int getOverFlowEXP() { - return overFlowEXP; - } - - public void setOverFlowEXP(int overFlowEXP) { - this.overFlowEXP = overFlowEXP; - } - - 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 MovementState getLastMovementState() { - return lastMovementState; - } - - public void setLastMovementState(MovementState lastMovementState) { - this.lastMovementState = lastMovementState; - } - @Override - public final void setIsCasting(final boolean isCasting) { - if (this.isCasting != isCasting) - this.update(); - this.isCasting = isCasting; - } - @Override - public void setItemCasting(boolean itemCasting) { - if (this.itemCasting != itemCasting) - this.dynamicUpdate(UpdateType.REGEN); - this.itemCasting = itemCasting; - } - - public void resetRegenUpdateTime(){ - this.lastUpdateTime = System.currentTimeMillis(); - this.lastStamUpdateTime = System.currentTimeMillis(); - } - - public float getCharacterHeight() { - return characterHeight; - } - - public void setCharacterHeight(float characterHeight) { - this.characterHeight = characterHeight; - } - - public void setCenterHeight(float centerHeight) { - this.centerHeight = centerHeight; - } - - 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 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) { - locationLock.writeLock().lock(); - try{ - MovementManager.translocate(this, targetLoc,null); - }catch(Exception e){ - Logger.error(e); - }finally{ - locationLock.writeLock().unlock(); - } - } - - public ReadWriteLock getTeleportLock() { - return teleportLock; - } - - 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 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 CharacterRune getRune(int runeID) { + if (this.runes == null) + return null; + for (CharacterRune cr : this.runes) { + if (cr.getRuneBase() != null && cr.getRuneBase().getObjectUUID() == runeID) + return cr; + } + return null; + } + + public boolean addRune(CharacterRune value) { + if (this.runes.size() > 12) // Max Runes + return false; + if (this.runes.indexOf(value) != -1) // Already contains rune + return false; + this.runes.add(value); + return true; + } + + public boolean removeRune(CharacterRune value) { + int index = this.runes.indexOf(value); + if (index == -1) + return false; + this.runes.remove(index); + return true; + } + + public CharacterRune removeRune(int runeID) { + Iterator it = this.runes.iterator(); + while (it.hasNext()) { + CharacterRune cr = it.next(); + if (cr != null) { + RuneBase rb = cr.getRuneBase(); + if (rb != null) + if (runeID == rb.getObjectUUID()) { + it.remove(); + DbManager.CharacterRuneQueries.DELETE_CHARACTER_RUNE(cr); + return cr; + } + } + } + return null; + } + + /** + * @ Kill this Character + */ + @Override + public void killCharacter(AbstractCharacter attacker) { + + killCleanup(); + + // *** Mobs have a separate combat path? Crazy shit! + // *** Mobs don't get Experience for killing players. everything else is done in killCleanup(); + + if (attacker.getObjectType().equals(GameObjectType.PlayerCharacter) == false) { + + Zone zone = ZoneManager.findSmallestZone(this.getLoc()); + + //DeathShroud + + if (zone.getSafeZone() == 0) + PowersManager.applyPower(this, this, Vector3fImmutable.ZERO, 1672601862, 40, false); + + //enable this to give players deathshroud if mobs kill player. + + // Zone zone = ZoneManager.findSmallestZone(this.getLoc()); + // if (zone.getSafeZone() == 0) + // PowersManager.applyPower(this, this, Vector3fImmutable.ZERO, 1672601862, 40, false); + return; + } + + + // Death to other player. + // TODO Send PvP and guild/nation message + PlayerCharacter att = (PlayerCharacter) attacker; + String message = this.getFirstName(); + if (this.guild != null && (!(this.guild.getName().equals("Errant")))) + message += " of " + this.guild.getName(); + message += " was killed by " + att.getFirstName(); + if (att.guild != null && (!(att.guild.getName().equals("Errant")))) + message += " of " + att.guild.getName(); + message += "!"; + + + //see if we shold grant xp to attacker + boolean doPVPEXP = false; + long lastKill = att.getLastKillOfTarget(this.getObjectUUID()); + if ((System.currentTimeMillis() - lastKill) > MBServerStatics.PLAYER_KILL_XP_TIMER) + if (attacker.getLevel() > 39 && this.getLevel() > 39) { + Guild aN = null; + Guild tN = null; + if (attacker.getGuild() != null) + aN = attacker.getGuild().getNation(); + if (this.getGuild() != null) + tN = this.getGuild().getNation(); + if (aN == null || tN == null || aN.isEmptyGuild() || Guild.sameGuild(aN, tN) || this.isDeathShroud()) { + //skip giving xp if same guild or attacker is errant, or target is in death shroud. + } else { + doPVPEXP = true; + } + } + //apply death shroud to non safeholds. + Zone zone = ZoneManager.findSmallestZone(this.getLoc()); + + //DeathShroud + + if (zone.getSafeZone() == 0) + PowersManager.applyPower(this, this, Vector3fImmutable.ZERO, 1672601862, 40, false); + + if (doPVPEXP) { + Group g = GroupManager.getGroup((PlayerCharacter) attacker); + Experience.doExperience((PlayerCharacter) attacker, this, g); + } + + ChatManager.chatPVP(message); + + /* + Update kill / death tracking lists + Each character on list is unique. Only once! + */ + + PlayerCharacter aggressorCharacter = (PlayerCharacter) attacker; + + boolean containsVictim = true; + boolean containsAttacker = true; + + containsVictim = aggressorCharacter.pvpKills.contains(this.getObjectUUID()); + containsAttacker = aggressorCharacter.pvpKills.contains(this.getObjectUUID()); + + // Rorate attacker's kill list + + if ((aggressorCharacter.pvpKills.size() == 10) && containsVictim == false) + aggressorCharacter.pvpKills.removeLast(); + + if (containsVictim == false) + aggressorCharacter.pvpKills.addFirst(this.getObjectUUID()); + + // Rotate the poor victim's deathlist + + if ((this.pvpDeaths.size() == 10) && containsAttacker == false) + this.pvpDeaths.removeLast(); + + if (containsAttacker == false) + this.pvpDeaths.addFirst(this.getObjectUUID()); + + // DataWarehouse: store pvp event + + PvpRecord pvpRecord = PvpRecord.borrow((PlayerCharacter) attacker, this, this.getLoc(), doPVPEXP); + DataWarehouse.pushToWarehouse(pvpRecord); + + // Mark kill time in killmap + + att.updateKillMap(this.getObjectUUID()); + } + + @Override + public void killCharacter(String reason) { + + killCleanup(); + Zone zone = ZoneManager.findSmallestZone(this.getLoc()); + + if (zone.getSafeZone() == 0) + PowersManager.applyPower(this, this, Vector3fImmutable.ZERO, 1672601862, 40, false); + + // Send death message if needed + if (reason.equals("Water")) { + + TargetedActionMsg targetedActionMsg = new TargetedActionMsg(this, true); + Dispatch dispatch = Dispatch.borrow(this, targetedActionMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + + String message = this.getFirstName(); + + if (this.guild != null && (!(this.guild.getName().equals("Errant")))) + message += " of " + this.guild.getName(); + else + message += this.getLastName(); + message += " was killed by water!"; + + ChatManager.chatPVP(message); + + } + } + + private void killCleanup() { + this.stopMovement(this.getLoc()); + + this.health.set(-1); + //remove pet + if (this.pet != null) + this.dismissPet(); + + NPCManager.dismissNecroPets(this); + // remove flight job. + + this.setTakeOffTime(0); + this.setDesiredAltitude(0); + this.altitude = (float) 0; + + // Release Mine Claims + + Mine.releaseMineClaims(this); + + this.getCharItemManager().closeTradeWindow(); + + //increment live counter. This is to prevent double kills from casts + this.liveCounter++; + + //remove any effects + try { + this.clearEffects(); + } catch (Exception e) { + Logger.error("PlayerCharacter.KillCleanup", e.getMessage()); + } + + //remove the SIT flag + this.setSit(false); + + + // sends a kill message to ensure the Player falls over. + + this.respawnLock.writeLock().lock(); + + try { + if (SessionManager.getPlayerCharacterByID(this.getObjectUUID()) == null && !this.enteredWorld) { + WorldGrid.RemoveWorldObject(this); + this.respawn(false, false, true); + } else { + TargetedActionMsg killmsg = new TargetedActionMsg(this, true); + DispatchMessage.dispatchMsgToInterestArea(this, killmsg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); + } + } catch (Exception e) { + Logger.error(e); + } finally { + this.respawnLock.writeLock().unlock(); + } + + // TODO damage equipped items + if (this.charItemManager != null) + this.charItemManager.damageAllGear(); + + // TODO cleanup any timers + //recalculate inventory weights + if (this.charItemManager != null) { + this.charItemManager.endTrade(true); + this.charItemManager.calculateWeights(); + this.charItemManager.updateInventory(); + } + + + } + + public void updateKillMap(int target) { + this.killMap.put(target, System.currentTimeMillis()); + } + + public long getLastKillOfTarget(int target) { + if (this.killMap.containsKey(target)) + return this.killMap.get(target); + return 0L; + } + + public boolean isDeathShroud() { + return this.effects != null && this.effects.containsKey("DeathShroud"); + } + + public void setSafeMode() { + PowersManager.applyPower(this, this, Vector3fImmutable.ZERO, -1661758934, 40, false); + } + + public boolean safemodeInvis() { + + if (!this.effects.containsKey("Invisible")) + return false; + + Effect eff = this.effects.get("Invisible"); + + if (eff == null) + return false; + + return eff.getEffectToken() == -1661751254; + + } + + public void respawn(boolean setAlive, boolean enterWorld, boolean makeCorpse) { + + // Recalculate everything + + + 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(); + + 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 + */ + public Race getRace() { + return race; + } + + public int getRaceID() { + if (race != null) + return race.getRaceRuneID(); + return 0; + } + + /** + * @return the baseClass + */ + public BaseClass getBaseClass() { + return baseClass; + } + + public int getBaseClassID() { + if (baseClass != null) + return baseClass.getObjectUUID(); + return 0; + } + + public int getBaseClassToken() { + if (this.baseClass == null) + return 0; + else + return this.baseClass.getToken(); + } + + public boolean setBaseClass(int value) { + BaseClass bs = BaseClass.getBaseClass(value); + if (bs != null) { + this.baseClass = bs; + return true; + } + return false; + } + + @Override + public Vector3fImmutable getBindLoc() { + + Vector3fImmutable bindLocation; + + // Return garbage and early exit if this is the login server. + // getBindLoc() does a TOL lookup, which also then loads the + // city and other garbage not needed on the login server. + + if (ConfigManager.serverType.equals(ServerType.LOGINSERVER)) + return Vector3fImmutable.ZERO; + + Building bindBuilding = PlayerCharacter.getUpdatedBindBuilding(this); + + //handle rented room binds. + + if (bindBuilding == null) { + bindLocation = Enum.Ruins.getRandomRuin().getLocation(); + return bindLocation; + } + + bindLocation = BuildingManager.GetBindLocationForBuilding(bindBuilding); + + if (bindLocation == null) + bindLocation = Enum.Ruins.getRandomRuin().getLocation(); + + return bindLocation; + + } + + public int getInventoryCapacity() { + return statStrBase * 3; + } + + public int getInventoryCapacityRemaining() { + return (this.getInventoryCapacity() - this.charItemManager.getInventoryWeight()); + } + + /** + * @return the PromotionClass + */ + public PromotionClass getPromotionClass() { + return promotionClass; + } + + public int getPromotionClassID() { + if (promotionClass != null) + return promotionClass.getObjectUUID(); + return 0; + } + + public boolean setPromotionClass(int value) { + + PromotionClass promotionClass = PromotionClass.GetPromtionClassFromCache(value); + + if (promotionClass == null) + return false; + + + if (!DbManager.PlayerCharacterQueries.SET_PROMOTION_CLASS(this, value)) + return false; + + this.promotionClass = promotionClass; + + // Warehouse this event + CharacterRecord.updatePromotionClass(this); + return true; + } + + /** + * @return the skinColor + */ + public byte getSkinColor() { + return skinColor; + } + + /** + * @return the hairColor + */ + public byte getHairColor() { + return hairColor; + } + + /** + * @return the beardColor + */ + public byte getBeardColor() { + return beardColor; + } + + /** + * @return the lfGroup + */ + public boolean isLfGroup() { + return lfGroup; + } + + public int getIsLfGroupAsInt() { + if (lfGroup) + return 2; + return 1; + } + + public final void toggleLFGroup() { + this.lfGroup = !this.lfGroup; + } + + public final void toggleLFGuild() { + this.lfGuild = !this.lfGuild; + } + + public final void toggleRecruiting() { + this.recruiting = !this.recruiting; + } + + public final boolean isLFGroup() { + 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) + if (this.recruiting) + return 14; // LFGroup + LFGuild + Recruiting + else + return 6; // LFGroup + LFGuild + else if (this.recruiting) + return 10; // LFGroup + Recruiting + else + return 2; // LFGroup only + else if (this.lfGuild) + if (this.recruiting) + return 12; // LFGuild + Recruiting + else + return 4; // LFGuild only + else if (this.recruiting) + return 8; // Recruiting only + else + return 0; // No Headlights + } + + public int getIsLfGuildAsInt() { + if (lfGuild) + return 2; + return 1; + } + + public int getStrMax() { + return this.statStrMax; + } + + public int getDexMax() { + return this.statDexMax; + } + + public int getConMax() { + return this.statConMax; + } + + 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 void setLastTarget(GameObjectType type, int id) { + this.lastTargetType = type; + this.lastTargetID = id; + } + + public GameObjectType getLastTargetType() { + return this.lastTargetType; + } + + public int getLastTargetID() { + return this.lastTargetID; + } + + /* + * Serializing + */ + + public synchronized int getBindBuildingID() { + return this.bindBuildingID; + } + + public synchronized void setBindBuildingID(int value) { + DbManager.PlayerCharacterQueries.SET_BIND_BUILDING(this, value); + this.bindBuildingID = value; + } + + public AbstractGameObject getLastTarget() { + if (this.lastTargetType == GameObjectType.unknown) + return null; + + switch (this.lastTargetType) { + // Make sure these only return an object that is + // already in the GOM, and doesn't reload from the DB + case PlayerCharacter: + return DbManager.getFromCache(GameObjectType.PlayerCharacter, this.lastTargetID); + + case Building: + return DbManager.getFromCache(GameObjectType.Building, this.lastTargetID); + + case NPC: + return NPC.getFromCache(this.lastTargetID); + + case Mob: + return Mob.getFromCache(this.lastTargetID); + + case Item: + return DbManager.getFromCache(GameObjectType.Item, this.lastTargetID); + + case Corpse: + return DbManager.getFromCache(GameObjectType.Corpse, this.lastTargetID); + + default: + + // Ignore exception for MobLoot? ***Check + if (this.lastTargetType != GameObjectType.MobLoot) + Logger.error("getLastTarget() unhandled object type: " + + this.lastTargetType.toString()); + } + return null; + } + + public Vector3fImmutable getLastStaticLoc() { + return this.lastStaticLoc; + } + + public void setLastStaticLoc(Vector3fImmutable value) { + this.lastStaticLoc = value; + } + + public int getHidden() { + return this.hidden; + } + + public void setHidden(int value) { + this.hidden = value; + } + + public int getSeeInvis() { + if (this.getDebug(8)) //<-added for see invis debug devcmd + return 10000; + return this.seeInvis; + } + + public void setSeeInvis(int value) { + this.seeInvis = value; + } + + public long getLastPlayerAttackTime() { + return this.lastPlayerAttackTime; + } + + public void setLastPlayerAttackTime() { + this.lastPlayerAttackTime = System.currentTimeMillis(); + } + + public void setLastMobAttackTime() { + this.lastMobAttackTime = System.currentTimeMillis(); + } + + public void setLastUsedPowerTime() { + this.lastUsedPowerTime = System.currentTimeMillis(); + } + + public void setLastTargetOfUsedPowerTime() { + this.lastTargetOfUsedPowerTime = System.currentTimeMillis(); + } + + public NPC getLastNPCDialog() { + return this.lastNPCDialog; + } + + public void setLastNPCDialog(NPC value) { + this.lastNPCDialog = value; + } + + public void setLastContract(int value) { + this.lastContract = value; + } + + public Mob getPet() { + return this.pet; + } + + public void setPet(Mob mob) { + + if (mob == null) + return; + + this.pet = mob; + } + + public void dismissPet() { + + if (this.pet != null) { + this.pet.dismiss(); + this.pet = null; + } + } + + //called to verify player has correct item equipped for casting. + public boolean validEquip(int slot, String type) { + + if (this.charItemManager == null) + return false; + + Item item = this.charItemManager.getEquipped(slot); + + if (item == null) + return false; + + ItemBase ib = item.getItemBase(); + if (ib != null) { + + if ((ib.getType().equals(ItemType.WEAPON)) + && (ib.getSkillRequired().equals(type) || ib.getMastery().equals(type))) + return true; + + return (ib.getType().equals(ItemType.ARMOR)) + && (ib.getSkillRequired().equals(type)); + } + + return false; + } + + public short getPCLevel() { + short level = (short) Experience.getLevel(this.exp); + if (this.promotionClass == null && level >= 10) + return (short) 10; + + if (this.overFlowEXP > 0) + return this.level; + + return level; + } + + @Override + public float getSpeed() { + + float speed; + + if (this.getAltitude() > 0) + if (this.walkMode) { + speed = race.getRaceType().getRunSpeed().getFlyWalk(); + } else { + speed = race.getRaceType().getRunSpeed().getFlyRun(); + } + else if (this.lastSwimming == true) + speed = MBServerStatics.SWIMSPEED; + else if (this.walkMode) { + if (this.isCombat()) + speed = race.getRaceType().getRunSpeed().getWalkCombat(); + else + speed = race.getRaceType().getRunSpeed().getWalkStandard(); + } else { + if (this.isCombat()) + speed = race.getRaceType().getRunSpeed().getRunCombat(); + else + speed = race.getRaceType().getRunSpeed().getRunStandard(); + } + + float endSpeed = speed * this.speedMod; + + if (endSpeed > 41 && !this.isCSR) + endSpeed = 41; + + return endSpeed; + } + + public synchronized void grantXP(int xp) { + // 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(); + 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(); + this.speedMod = bonus; + } + + public ClientConnection getClientConnection() { + return SessionManager.getClientConnection(this); + } + + public String getCombinedName() { + return this.getName(); + } + + public long getLastGuildToInvite() { + return this.lastGuildToInvite; + } + + public void setLastGuildToInvite(int value) { + this.lastGuildToInvite = value; + } + + public boolean getFollow() { + return this.follow; + } + + public void setFollow(boolean value) { + this.follow = value; + } + + public boolean toggleFollow() { + this.follow = !this.follow; + return this.follow; + } + + public int getLastGroupToInvite() { + return this.lastGroupToInvite; + } + + public void setLastGroupToInvite(int value) { + this.lastGroupToInvite = value; + } + + @Override + public float getAltitude() { + if (this.altitude < 0) + this.altitude = 0; + + //player has reached desired altitude, return normal altitude. + if (this.getTakeOffTime() == 0) + return this.altitude; + + //sanity check if desired altitude is the same as current altitude. return desired altitude. + if (this.altitude == this.getDesiredAltitude()) { + return this.getDesiredAltitude(); + } + + //calculate how much the player has moved up + float amountMoved = (System.currentTimeMillis() - this.getTakeOffTime()) * MBServerStatics.FLY_RATE; //FUCK DIVIDING + + //Player is moving up + if (this.getDesiredAltitude() > this.altitude) { + + //if amount moved passed desiredAltitude, return the desired altitude. + if (this.altitude + amountMoved >= this.getDesiredAltitude()) + return this.getDesiredAltitude(); + + return this.altitude + amountMoved; + //Player is moving down + } else { + //if amount moved passed desiredAltitude, return the desired altitude. + if (this.altitude - amountMoved <= this.getDesiredAltitude()) + return this.getDesiredAltitude(); + return this.altitude - amountMoved; + } + + + } + + public void setAltitude(float value) { + this.altitude = value; + } + + public HashSet getLoadedObjects() { + return this.loadedObjects; + } + + public HashSet getLoadedStaticObjects() { + return this.loadedStaticObjects; + } + + public void setLoadedStaticObjects(HashSet value) { + this.loadedStaticObjects = value; + } + + public boolean isTeleportMode() { + return teleportMode; + } + + public void setTeleportMode(boolean teleportMode) { + 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 + LinkedList times = null; + long oldestTime; + synchronized (chatChanFloodList) { + if (!chatChanFloodList.containsKey(chatOpcode)) { + times = new LinkedList<>(); + for (int i = 0; i < qtyToSave; i++) { + times.add(0L); + } + chatChanFloodList.put(chatOpcode, times); + } else + times = chatChanFloodList.get(chatOpcode); + oldestTime = times.getLast(); + times.removeLast(); + times.addFirst(chatTimeMilli); + } + return oldestTime; + } + + public void addIgnoredPlayer(Account ac, String name) { + if (ac == null) + return; + int acID = ac.getObjectUUID(); + if (acID < 1) + return; + if (ignoredPlayerIDs == null) + return; + if (acID == getObjectUUID()) + return; // yourself + + ignoredPlayerIDs.put(acID, name); + } + + public void removeIgnoredPlayer(Account ac) { + if (ac == null) + return; + int acID = ac.getObjectUUID(); + if (acID < 1) + return; + if (ignoredPlayerIDs == null) + return; + if (acID == getObjectUUID()) + return; // yourself + + ignoredPlayerIDs.remove(acID); + } + + public boolean isIgnoringPlayer(PlayerCharacter pc) { + + if (pc == null) + return false; + + if (pc.account == null) + return false; + + return isIgnoringPlayer(pc.account); + } + + public boolean isIgnoringPlayer(Account ac) { + if (ac == null) + return false; + int acID = ac.getObjectUUID(); + if (acID < 1) + return false; + return ignoredPlayerIDs.containsKey(acID); + } + + public String[] getIgnoredPlayerNames() { + int size = ignoredPlayerIDs.size(); + String[] ary = new String[size]; + for (int i = 0; i < size; i++) { + // ary[i] = PlayerCharacter.getFirstName(ignoredPlayerIDs.get(i)); + ary[i] = ignoredPlayerIDs.get(i); + } + return ary; + } + + public int getStrMod() { + return this.strMod.get(); + } + + public int getDexMod() { + return this.dexMod.get(); + } + + public int getConMod() { + return this.conMod.get(); + } + + public int getIntMod() { + return this.intMod.get(); + } + + public int getSpiMod() { + return this.spiMod.get(); + } + + public boolean isMale() { + if (this.race == null) + return true; + return (this.race.getRaceType().getCharacterSex().equals(CharacterSex.MALE)); + } + + public boolean canSee(PlayerCharacter tar) { + + if (tar == null) + return false; + + if (this.equals(tar)) + return true; + + return this.getSeeInvis() >= tar.hidden && !tar.safemodeInvis(); + } + + public void recalculatePlayerStats(boolean initialized) { + + //calculate base stats + calculateBaseStats(); + + //calculate base skills + CharacterSkill.updateAllBaseAmounts(this); + calculateModifiedStats(); + + //calculate modified skills + CharacterSkill.updateAllModifiedAmounts(this); + this.updateScaleHeight(); + + //calculate modified stats + + + //calculate ATR, damage and defense + calculateAtrDefenseDamage(); + + //calculate movement bonus + calculateSpeedMod(); + + // recalculate Max Health/Mana/Stamina + calculateMaxHealthManaStamina(); + + // recalculate Resists + Resists.calculateResists(this); + + } + + /** + * @ Recalculate player after promoting or gaining a level + */ + public void recalculate() { + this.applyBonuses(); + this.trainsAvailable.set(CharacterSkill.getTrainsAvailable(this)); + if (this.trainsAvailable.get() < 0) + recalculateTrains(); + //this.resists.calculateResists(this); + + // calculate skills and powers. Make sure none are missing. + this.calculateSkills(); + + // calculate powers again. See if any new powers unlocked + this.calculateSkills(); + } + + //This is run to auto-fix any overage on skill training. + private void recalculateTrains() { + int trainsAvailable = CharacterSkill.getTrainsAvailable(this); + if (trainsAvailable < 0) { + + //refine powers first, run twice to catch any prereqs + ConcurrentHashMap powers = this.getPowers(); + for (int i = 0; i < 2; i++) { + for (CharacterPower p : powers.values()) { + if (trainsAvailable >= 0) + return; + while (p.getTrains() > 0 && p.refine(this)) { + trainsAvailable++; + if (trainsAvailable >= 0) + return; + } + } + } + + //refine skills + ConcurrentHashMap skills = this.getSkills(); + for (CharacterSkill s : skills.values()) { + if (trainsAvailable >= 0) + return; + while (s.getNumTrains() > 0 && s.refine(this)) { + if (CharacterSkill.getTrainsAvailable(this) >= 0) + return; + } + } + } + } + + /** + * @ Calculates Base Stats Call this when modifying stats or adding/removing + * runes + */ + public void calculateBaseStats() { + if (this.race == null || this.baseClass == null) + // Logger.getInstance().log( LogEventType.ERROR, + // "PlayerCharacter.updateBaseStats: Missing race or baseclass for Player " + // + this.getUUID()); + return; + + // get base stats and total available + int strMin = this.race.getStrStart() + this.baseClass.getStrMod() - 5; + int dexMin = this.race.getDexStart() + this.baseClass.getDexMod() - 5; + int conMin = this.race.getConStart() + this.baseClass.getConMod() - 5; + int intMin = this.race.getIntStart() + this.baseClass.getIntMod() - 5; + int spiMin = this.race.getSpiStart() + this.baseClass.getSpiMod() - 5; + int str = this.race.getStrStart() + this.baseClass.getStrMod() + this.strMod.get(); + int dex = this.race.getDexStart() + this.baseClass.getDexMod() + this.dexMod.get(); + int con = this.race.getConStart() + this.baseClass.getConMod() + this.conMod.get(); + int intt = this.race.getIntStart() + this.baseClass.getIntMod() + this.intMod.get(); + int spi = this.race.getSpiStart() + this.baseClass.getSpiMod() + this.spiMod.get(); + int strMax = this.race.getStrMax(); + int dexMax = this.race.getDexMax(); + int conMax = this.race.getConMax(); + int intMax = this.race.getIntMax(); + int spiMax = this.race.getSpiMax(); + int available = this.race.getStartingPoints() - this.strMod.get() - this.dexMod.get() - this.conMod.get() - this.intMod.get() - this.spiMod.get(); + if (level < 20) + available += (level - 1) * 5; + else if (level < 30) + available += 90 + (level - 19) * 4; + else if (level < 40) + available += 130 + (level - 29) * 3; + else if (level < 50) + available += 160 + (level - 39) * 2; + else + available += 180 + (level - 49); + + // modify for any runes applied. + for (CharacterRune rune : this.runes) { + if (rune.getRuneBase() == null) + // Logger.getInstance().log( LogEventType.ERROR, + // "PlayerCharacter.updateBaseStats: Missing runebase for rune " + // + rune.getUUID()); + continue; + ArrayList attrs = rune.getRuneBase().getAttrs(); + if (attrs == null) + // Logger.getInstance().log( LogEventType.ERROR, + // "PlayerCharacter.updateBaseStats: Missing attributes for runebase " + // + rune.getRuneBase().getUUID()); + continue; + for (RuneBaseAttribute abr : attrs) { + int attrID = abr.getAttributeID(); + int value = abr.getModValue(); + switch (attrID) { + case MBServerStatics.RUNE_COST_ATTRIBUTE_ID: + available -= value; + break; + case MBServerStatics.RUNE_STR_ATTRIBUTE_ID: + str += value; + strMin += value; + break; + case MBServerStatics.RUNE_DEX_ATTRIBUTE_ID: + dex += value; + dexMin += value; + break; + case MBServerStatics.RUNE_CON_ATTRIBUTE_ID: + con += value; + conMin += value; + break; + case MBServerStatics.RUNE_INT_ATTRIBUTE_ID: + intt += value; + intMin += value; + break; + case MBServerStatics.RUNE_SPI_ATTRIBUTE_ID: + spi += value; + spiMin += value; + break; + case MBServerStatics.RUNE_STR_MAX_ATTRIBUTE_ID: + strMax += value; + break; + case MBServerStatics.RUNE_DEX_MAX_ATTRIBUTE_ID: + dexMax += value; + break; + case MBServerStatics.RUNE_CON_MAX_ATTRIBUTE_ID: + conMax += value; + break; + case MBServerStatics.RUNE_INT_MAX_ATTRIBUTE_ID: + intMax += value; + break; + case MBServerStatics.RUNE_SPI_MAX_ATTRIBUTE_ID: + spiMax += value; + break; + default: + } + } + + //Set titles based on rune.. + switch (rune.getRuneBaseID()) { + default: + break; + + case 2901: //CSR 1 + this.title = CharacterTitle.CSR_1; + break; + case 2902: //CSR 1 + this.title = CharacterTitle.CSR_2; + break; + case 2903: //CSR 1 + this.title = CharacterTitle.CSR_3; + break; + case 2904: //CSR 1 + this.title = CharacterTitle.CSR_4; + break; + + case 2910: //Wolfpack Developer + this.title = CharacterTitle.DEVELOPER; + break; + case 2911: //QA Test Rune + this.title = CharacterTitle.QA; + break; + } + } + + //hack check. Make sure available does not go below 0. + //subtract from each stat until available is 0 or greater. + if (available < 0) { + while (this.spiMod.get() > 0 && available < 0) { + this.spiMod.decrementAndGet(); + spi--; + available++; + } + while (this.conMod.get() > 0 && available < 0) { + this.conMod.decrementAndGet(); + con--; + available++; + } + while (this.strMod.get() > 0 && available < 0) { + this.strMod.decrementAndGet(); + str--; + available++; + } + while (this.dexMod.get() > 0 && available < 0) { + this.dexMod.decrementAndGet(); + dex--; + available++; + } + while (this.intMod.get() > 0 && available < 0) { + this.intMod.decrementAndGet(); + intt--; + available++; + } + + //update database + this.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); + } + + this.statStrBase = (short) str; + this.statDexBase = (short) dex; + this.statConBase = (short) con; + this.statIntBase = (short) intt; + this.statSpiBase = (short) spi; + this.statStrMax = (short) (strMax); + this.statDexMax = (short) (dexMax); + this.statConMax = (short) (conMax); + this.statIntMax = (short) (intMax); + this.statSpiMax = (short) (spiMax); + this.statStrMin = (short) strMin; + this.statDexMin = (short) dexMin; + this.statConMin = (short) conMin; + this.statIntMin = (short) intMin; + this.statSpiMin = (short) spiMin; + this.unusedStatPoints = (short) available; + this.trainedStatPoints = 0; + + // Testing, allow characters to have more stats then normal for formula checking + if (this.statStrBase > this.statStrMax) + this.statStrMax = this.statStrBase; + if (this.statDexBase > this.statDexMax) + this.statDexMax = this.statDexBase; + if (this.statConBase > this.statConMax) + this.statConMax = this.statConBase; + if (this.statIntBase > this.statIntMax) + this.statIntMax = this.statIntBase; + if (this.statSpiBase > this.statSpiMax) + this.statSpiMax = this.statSpiBase; + + // Modified stats must be recalculated when base stats are + //calculateModifiedStats(); + //update hide and seeInvis levels + if (this.bonuses != null) { + this.hidden = (int) bonuses.getFloat(ModType.Invisible, SourceType.None); + this.seeInvis = (int) bonuses.getFloat(ModType.SeeInvisible, SourceType.None); + } else { + this.hidden = (byte) 0; + this.seeInvis = (byte) 0; + } + + //check is player is a CSR + this.isCSR = this.containsCSRRune(); + } + + private boolean containsCSRRune() { + + if (this.race != null && this.race.getRaceType().equals(RaceType.CSRMALE)) + return true; + + if (this.baseClass != null && this.baseClass.getObjectUUID() > 2900 && this.baseClass.getObjectUUID() < 2905) + return true; + + if (this.promotionClass != null && this.promotionClass.getObjectUUID() > 2900 && this.promotionClass.getObjectUUID() < 2905) + return true; + + if (this.runes == null) + return false; + + for (CharacterRune rune : this.runes) { + + if (rune == null || rune.getRuneBase() == null) + continue; + + RuneBase rb = rune.getRuneBase(); + + if (rb.getObjectUUID() > 2900 && rb.getObjectUUID() < 2905) + return true; + if (rb.getObjectUUID() == 2910) + return true; + + } + return false; + } + + public boolean isCSR() { + return this.isCSR; + } + + public void setAsciiLastName(boolean value) { + this.asciiLastName = value; + } + + public boolean _asciiLastName() { + return this.asciiLastName; + } + + /** + * @ Calculates Modified Stats Call this when changing equipment or + * add/removing effect. skips base stat modification. + */ + public void calculateModifiedStats() { + float strVal = this.statStrBase; + float dexVal = this.statDexBase; + float conVal = this.statConBase; + float intVal = this.statIntBase; + float spiVal = this.statSpiBase; + + this.dexPenalty = getDexPenalty(); + + // TODO modify for equipment + if (this.bonuses != null) { + // modify for effects + strVal += Math.round(this.bonuses.getFloat(ModType.Attr, SourceType.Strength)); + dexVal += Math.round(this.bonuses.getFloat(ModType.Attr, SourceType.Dexterity)); + conVal += Math.round(this.bonuses.getFloat(ModType.Attr, SourceType.Constitution)); + intVal += Math.round(this.bonuses.getFloat(ModType.Attr, SourceType.Intelligence)); + spiVal += Math.round(this.bonuses.getFloat(ModType.Attr, SourceType.Spirit)); + + // apply dex penalty for armor + dexVal *= this.dexPenalty; + + // modify percent amounts. DO THIS LAST! + strVal *= (1 + this.bonuses.getFloatPercentAll(ModType.Attr, SourceType.Strength)); + dexVal *= (1 + this.bonuses.getFloatPercentAll(ModType.Attr, SourceType.Dexterity)); + conVal *= (1 + this.bonuses.getFloatPercentAll(ModType.Attr, SourceType.Constitution)); + intVal *= (1 + this.bonuses.getFloatPercentAll(ModType.Attr, SourceType.Intelligence)); + spiVal *= (1 + this.bonuses.getFloatPercentAll(ModType.Attr, SourceType.Spirit)); + + } else + // apply dex penalty for armor + dexVal *= this.dexPenalty; + + // Set current stats + this.statStrCurrent = (strVal < 1) ? (short) 1 : (short) strVal; + this.statDexCurrent = (dexVal < 1) ? (short) 1 : (short) dexVal; + this.statConCurrent = (conVal < 1) ? (short) 1 : (short) conVal; + this.statIntCurrent = (intVal < 1) ? (short) 1 : (short) intVal; + this.statSpiCurrent = (spiVal < 1) ? (short) 1 : (short) spiVal; + + // recalculate skills + //CharacterSkill.updateAllBaseAmounts(this); + // recalculate Max Health/Mana/Stamina + //calculateMaxHealthManaStamina(); + // recalculate Resists + //this.resists.calculateResists(this); + } + + public float getDexPenalty() { + + if (this.charItemManager == null || this.charItemManager.getEquipped() == null) { + Logger.error("Player " + this.getObjectUUID() + " missing equipment"); + return 1f; + } + + 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)); + return (1 - (dexPenalty / 100)); + } + + public int getStrForClient() { + return this.statStrCurrent - this.race.getStrStart() - this.baseClass.getStrMod(); + } + + public int getDexForClient() { + return this.statDexCurrent - this.race.getDexStart() - this.baseClass.getDexMod(); + } + + public int getConForClient() { + return this.statConCurrent - this.race.getConStart() - this.baseClass.getConMod(); + } + + public int getIntForClient() { + return this.statIntCurrent - this.race.getIntStart() - this.baseClass.getIntMod(); + } + + public int getSpiForClient() { + return this.statSpiCurrent - this.race.getSpiStart() - this.baseClass.getSpiMod(); + } + + public int getTrainsAvailable() { + return this.trainsAvailable.get(); + } + + public void modifyTrainsAvailable(int amount) { + boolean worked = false; + while (!worked) { + int old = this.trainsAvailable.get(); + int newVal = old + amount; + // if (newVal < 0) + // newVal = 0; + worked = this.trainsAvailable.compareAndSet(old, newVal); + } + } + + // Reset any data that should not persist from a previous session + public void resetDataAtLogin() { + loadedObjects.clear(); + loadedStaticObjects.clear(); + lastStaticLoc = Vector3fImmutable.ZERO; + setLastTarget(GameObjectType.unknown, 0); + this.follow = false; + } + + /** + * @ Calculates Atr (both hands) Defense, and Damage for pc + */ + public void calculateAtrDefenseDamage() { + if (this.charItemManager == null || this.charItemManager.getEquipped() == null || this.skills == null) { + Logger.error("Player " + this.getObjectUUID() + " missing skills or equipment"); + defaultAtrAndDamage(true); + defaultAtrAndDamage(false); + this.defenseRating = 0; + return; + } + ConcurrentHashMap equipped = this.charItemManager.getEquipped(); + + // // Reset passives + // if (this.bonuses != null) { + // this.bonuses.setBool("Block", false); + // this.bonuses.setBool("Parry", false); + // if (this.baseClass != null && this.baseClass.getUUID() == 2502) + // this.bonuses.setBool("Dodge", true); + // else + // this.bonuses.setBool("Dodge", false); + // } + // calculate atr and damage for each hand + calculateAtrDamageForWeapon(equipped.get(MBServerStatics.SLOT_MAINHAND), true, equipped.get(MBServerStatics.SLOT_OFFHAND)); + calculateAtrDamageForWeapon(equipped.get(MBServerStatics.SLOT_OFFHAND), false, equipped.get(MBServerStatics.SLOT_MAINHAND)); + + // No Defense while in DeathShroud + if (this.effects != null && this.effects.containsKey("DeathShroud")) + this.defenseRating = (short) 0; + else { + // calculate defense for equipment + float defense = this.statDexCurrent * 2; + defense += getShieldDefense(equipped.get(MBServerStatics.SLOT_OFFHAND)); + defense += getArmorDefense(equipped.get(MBServerStatics.SLOT_HELMET)); + defense += getArmorDefense(equipped.get(MBServerStatics.SLOT_CHEST)); + defense += getArmorDefense(equipped.get(MBServerStatics.SLOT_ARMS)); + defense += getArmorDefense(equipped.get(MBServerStatics.SLOT_GLOVES)); + defense += getArmorDefense(equipped.get(MBServerStatics.SLOT_LEGGINGS)); + defense += getArmorDefense(equipped.get(MBServerStatics.SLOT_FEET)); + defense += getWeaponDefense(equipped); + + if (this.bonuses != null) { + // add any bonuses + defense += (short) this.bonuses.getFloat(ModType.DCV, SourceType.None); + + // Finally multiply any percent modifiers. DO THIS LAST! + float pos_Bonus = this.bonuses.getFloatPercentPositive(ModType.DCV, SourceType.None); + defense = (short) (defense * (1 + pos_Bonus)); + + //Lucky rune applies next + //applied runes will be calculated and added to the normal bonuses. no need for this garbage anymore + //defense = (short) (defense * (1 + ((float) this.bonuses.getShort("rune.Defense") / 100))); + + //and negative percent modifiers + //already done... + float neg_Bonus = this.bonuses.getFloatPercentNegative(ModType.DCV, SourceType.None); + defense = (short) (defense * (1 + neg_Bonus)); + + } else + // TODO add error log here + Logger.error("Error: missing bonuses"); + + defense = (defense < 1) ? 1 : defense; + this.defenseRating = (short) (defense + 0.5f); + } + } + + /** + * @ Calculates Atr, and Damage for each weapon + */ + private void calculateAtrDamageForWeapon(Item weapon, boolean mainHand, Item otherHand) { + + // make sure weapon exists + boolean noWeapon = false; + ItemBase wb = null; + if (weapon == null) + noWeapon = true; + else { + ItemBase ib = weapon.getItemBase(); + if (ib == null) + noWeapon = true; + else if (!ib.getType().equals(ItemType.WEAPON)) { + defaultAtrAndDamage(mainHand); + return; + } else + wb = ib; + } + float skillPercentage, masteryPercentage; + float mastDam; + float min, max; + float speed = 20f; + boolean strBased = false; + + ItemBase wbMain = (weapon != null) ? weapon.getItemBase() : null; + ItemBase wbOff = (otherHand != null) ? otherHand.getItemBase() : null; + + // get skill percentages and min and max damage for weapons + if (noWeapon) { + if (mainHand) { + Item off = this.charItemManager.getEquipped().get(MBServerStatics.SLOT_OFFHAND); + if (off != null && off.getItemBase() != null && off.getItemBase().getType().equals(ItemType.WEAPON)) + this.rangeHandOne = 10 * (1 + (this.statStrBase / 600)); // Set + // to + // no + // weapon + // range + else + this.rangeHandOne = -1; // set to do not attack + } else + this.rangeHandTwo = -1; // set to do not attack + + skillPercentage = getModifiedAmount(this.skills.get("Unarmed Combat")); + masteryPercentage = getModifiedAmount(this.skills.get("Unarmed Combat Mastery")); + if (masteryPercentage == 0f) + mastDam = CharacterSkill.getQuickMastery(this, "Unarmed Combat Mastery"); + else + mastDam = masteryPercentage; + // TODO Correct these + min = 1; + max = 3; + } else { + if (mainHand) + this.rangeHandOne = weapon.getItemBase().getRange() * (1 + (this.statStrBase / 600)); + else + this.rangeHandTwo = weapon.getItemBase().getRange() * (1 + (this.statStrBase / 600)); + + if (this.bonuses != null) { + float range_bonus = 1 + this.bonuses.getFloatPercentAll(ModType.WeaponRange, SourceType.None); + + if (mainHand) + this.rangeHandOne *= range_bonus; + else + this.rangeHandTwo *= range_bonus; + + } + skillPercentage = getModifiedAmount(this.skills.get(wb.getSkillRequired())); + masteryPercentage = getModifiedAmount(this.skills.get(wb.getMastery())); + if (masteryPercentage == 0f) + mastDam = 0f; + // mastDam = CharacterSkill.getQuickMastery(this, wb.getMastery()); + else + mastDam = masteryPercentage; + min = (float) wb.getMinDamage(); + max = (float) wb.getMaxDamage(); + strBased = wb.isStrBased(); + + // + // Add parry bonus for weapon and allow parry if needed + + // // Only Fighters and Thieves can Parry + // if ((this.baseClass != null && this.baseClass.getUUID() == 2500) + // || (this.promotionClass != null && this.promotionClass.getUUID() == 2520)) { + // if (wbMain == null || wbMain.getRange() < MBServerStatics.RANGED_WEAPON_RANGE) + // if (wbOff == null || wbOff.getRange() < MBServerStatics.RANGED_WEAPON_RANGE) + // this.bonuses.setBool("Parry", true); + // } + // } + } + + if (this.effects != null && this.effects.containsKey("DeathShroud")) + // No Atr in deathshroud. + if (mainHand) + this.atrHandOne = (short) 0; + else + this.atrHandTwo = (short) 0; + else { + // calculate atr + float atr = 0; + atr += (int) skillPercentage * 4f; //<-round down skill% - + atr += (int) masteryPercentage * 3f; + if (this.statStrCurrent > this.statDexCurrent) + atr += statStrCurrent / 2; + else + atr += statDexCurrent / 2; + + // add in any bonuses to atr + if (this.bonuses != null) { + // Add any base bonuses + atr += this.bonuses.getFloat(ModType.OCV, SourceType.None); + + // Finally use any multipliers. DO THIS LAST! + float pos_Bonus = (1 + this.bonuses.getFloatPercentPositive(ModType.OCV, SourceType.None)); + atr *= pos_Bonus; + + // next precise + //runes will have their own bonuses. + // atr *= (1 + ((float) this.bonuses.getShort("rune.Attack") / 100)); + + //and negative percent modifiers + float neg_Bonus = this.bonuses.getFloatPercentNegative(ModType.OCV, SourceType.None); + + atr *= (1 + neg_Bonus); + } + + atr = (atr < 1) ? 1 : atr; + + // set atr + if (mainHand) + this.atrHandOne = (short) (atr + 0.5f); + else + this.atrHandTwo = (short) (atr + 0.5f); + } + + //calculate speed + if (wb != null) + speed = wb.getSpeed(); + else + speed = 20f; //unarmed attack speed + if (weapon != null) + speed *= (1 + this.bonuses.getFloatPercentAll(ModType.WeaponSpeed, SourceType.None)); + speed *= (1 + this.bonuses.getFloatPercentAll(ModType.AttackDelay, SourceType.None)); + if (speed < 10) + speed = 10; + + //add min/max damage bonuses for weapon + if (weapon != null) { + // Add any base bonuses + + min += weapon.getBonus(ModType.MinDamage, SourceType.None); + max += weapon.getBonus(ModType.MaxDamage, SourceType.None); + + min += weapon.getBonus(ModType.MeleeDamageModifier, SourceType.None); + max += weapon.getBonus(ModType.MeleeDamageModifier, SourceType.None); + // Finally use any multipliers. DO THIS LAST! + + float percentMinDamage = 1; + float percentMaxDamage = 1; + + percentMinDamage += weapon.getBonusPercent(ModType.MinDamage, SourceType.None); + percentMinDamage += weapon.getBonusPercent(ModType.MeleeDamageModifier, SourceType.None); + + percentMaxDamage += weapon.getBonusPercent(ModType.MaxDamage, SourceType.None); + percentMaxDamage += weapon.getBonusPercent(ModType.MeleeDamageModifier, SourceType.None); + + + min *= percentMinDamage; + max *= percentMaxDamage; + } + + //if duel wielding, cut damage by 30% + if (otherHand != null) { + ItemBase ibo = otherHand.getItemBase(); + if (ibo != null && ibo.getType().equals(ItemType.WEAPON)) { + min *= 0.7f; + max *= 0.7f; + } + } + + // calculate damage + float minDamage; + float maxDamage; + float pri = (strBased) ? (float) this.statStrCurrent : (float) this.statDexCurrent; + float sec = (strBased) ? (float) this.statDexCurrent : (float) this.statStrCurrent; + minDamage = (float) (min * ((0.0315f * Math.pow(pri, 0.75f)) + (0.042f * Math.pow(sec, 0.75f)) + (0.01f * ((int) skillPercentage + (int) mastDam)))); + maxDamage = (float) (max * ((0.0785f * Math.pow(pri, 0.75f)) + (0.016f * Math.pow(sec, 0.75f)) + (0.0075f * ((int) skillPercentage + (int) mastDam)))); + minDamage = (float) ((int) (minDamage + 0.5f)); //round to nearest decimal + maxDamage = (float) ((int) (maxDamage + 0.5f)); //round to nearest decimal + + // Half damage if in death shroud + if (this.effects != null && this.effects.containsKey("DeathShroud")) { + minDamage *= 0.5f; + maxDamage *= 0.5f; + } + + // add in any bonuses to damage + if (this.bonuses != null) { + // Add any base bonuses + minDamage += this.bonuses.getFloat(ModType.MinDamage, SourceType.None); + maxDamage += this.bonuses.getFloat(ModType.MaxDamage, SourceType.None); + + minDamage += this.bonuses.getFloat(ModType.MeleeDamageModifier, SourceType.None); + maxDamage += this.bonuses.getFloat(ModType.MeleeDamageModifier, SourceType.None); + // Finally use any multipliers. DO THIS LAST! + + float percentMinDamage = 1; + float percentMaxDamage = 1; + + percentMinDamage += this.bonuses.getFloatPercentAll(ModType.MinDamage, SourceType.None); + percentMinDamage += this.bonuses.getFloatPercentAll(ModType.MeleeDamageModifier, SourceType.None); + + percentMaxDamage += this.bonuses.getFloatPercentAll(ModType.MaxDamage, SourceType.None); + percentMaxDamage += this.bonuses.getFloatPercentAll(ModType.MeleeDamageModifier, SourceType.None); + + minDamage *= percentMinDamage; + maxDamage *= percentMaxDamage; + + } + + // set damages + if (mainHand) { + this.minDamageHandOne = (int) minDamage; + this.maxDamageHandOne = (int) maxDamage; + this.speedHandOne = speed; + } else { + this.minDamageHandTwo = (int) minDamage; + this.maxDamageHandTwo = (int) maxDamage; + this.speedHandTwo = speed; + } + } + + /** + * @ Calculates Defense for shield + */ + private float getShieldDefense(Item shield) { + if (shield == null) + return 0; + ItemBase ab = shield.getItemBase(); + if (ab == null || !ab.isShield()) + return 0; + CharacterSkill blockSkill = this.skills.get("Block"); + float skillMod; + if (blockSkill == null) { + skillMod = 0; + } else + skillMod = blockSkill.getModifiedAmount(); + + float def = ab.getDefense(); + //apply item defense bonuses + if (shield != null) { + def += shield.getBonus(ModType.DR, SourceType.None); + def *= (1 + shield.getBonusPercent(ModType.DR, SourceType.None)); + + } + + // float val = ((float)ab.getDefense()) * (1 + (skillMod / 100)); + return (def * (1 + ((int) skillMod / 100f))); + } + + public void setPassives() { + if (this.bonuses != null) { + ConcurrentHashMap equipped = this.charItemManager.getEquipped(); + Item off = equipped.get(MBServerStatics.SLOT_OFFHAND); + Item main = equipped.get(MBServerStatics.SLOT_MAINHAND); + ItemBase wbMain = null; + ItemBase wbOff = null; + if (main != null) + wbMain = main.getItemBase(); + if (off != null) + wbOff = off.getItemBase(); + + //set block if block found + this.bonuses.setBool(ModType.Block, SourceType.None, false); + if (this.baseClass != null && (this.baseClass.getObjectUUID() == 2500 || this.baseClass.getObjectUUID() == 2501)) + if (off != null && off.getItemBase() != null && off.getItemBase().isShield()) + this.bonuses.setBool(ModType.Block, SourceType.None, true); + + //set dodge if rogue + if (this.baseClass != null && this.baseClass.getObjectUUID() == 2502) + this.bonuses.setBool(ModType.Dodge, SourceType.None, true); + else + this.bonuses.setBool(ModType.Dodge, SourceType.None, false); + + //set parry if fighter or thief and no invalid weapon found + this.bonuses.setBool(ModType.Parry, SourceType.None, false); + if ((this.baseClass != null && this.baseClass.getObjectUUID() == 2500) + || (this.promotionClass != null && this.promotionClass.getObjectUUID() == 2520)) + if (wbMain == null || wbMain.getRange() < MBServerStatics.RANGED_WEAPON_RANGE) + if (wbOff == null || wbOff.getRange() < MBServerStatics.RANGED_WEAPON_RANGE) + this.bonuses.setBool(ModType.Parry, SourceType.None, true); + + } + + } + + /** + * @ Calculates Defense for armor + */ + private float getArmorDefense(Item armor) { + + if (armor == null) + return 0; + + ItemBase ib = armor.getItemBase(); + + if (ib == null) + return 0; + + if (!ib.getType().equals(ItemType.ARMOR)) + return 0; + if (ib.getSkillRequired().isEmpty()) + return ib.getDefense(); + CharacterSkill armorSkill = this.skills.get(ib.getSkillRequired()); + if (armorSkill == null) { + Logger.error("Player " + this.getObjectUUID() + + " has armor equipped without the nescessary skill to equip it"); + return ib.getDefense(); + } + + float def = ib.getDefense(); + //apply item defense bonuses + if (armor != null) { + def += armor.getBonus(ModType.DR, SourceType.None); + def *= (1 + armor.getBonusPercent(ModType.DR, SourceType.None)); + } + + + return (def * (1 + ((int) armorSkill.getModifiedAmount() / 50f))); + } + + /** + * @ Calculates Defense for weapon + */ + private float getWeaponDefense(ConcurrentHashMap equipped) { + Item weapon = equipped.get(MBServerStatics.SLOT_MAINHAND); + ItemBase wb = null; + CharacterSkill skill, mastery; + float val = 0; + boolean unarmed = false; + if (weapon == null) { + weapon = equipped.get(MBServerStatics.SLOT_OFFHAND); + if (weapon == null || weapon.getItemBase().isShield()) + unarmed = true; + else + wb = weapon.getItemBase(); + } else + wb = weapon.getItemBase(); + if (wb == null) + unarmed = true; + if (unarmed) { + skill = this.skills.get("Unarmed Combat"); + mastery = this.skills.get("Unarmed Combat Mastery"); + } else { + skill = this.skills.get(wb.getSkillRequired()); + mastery = this.skills.get(wb.getMastery()); + } + if (skill != null) + val += (int) skill.getModifiedAmount() / 2f; + if (mastery != null) + val += (int) mastery.getModifiedAmount() / 2f; + return val; + } + + //Call this function to recalculate granted skills and powers for player + public synchronized void calculateSkills() { + //tell the player to applyBonuses because something has changed + + runSkillCalc(); + + //start running the skill/power calculations + } + + //Don't call this function directly. linked from pc.calculateSkills() + //through SkillCalcJob. Designed to only run from one worker thread + public void runSkillCalc() { + try { + + //see if any new skills or powers granted + CharacterSkill.calculateSkills(this); + // calculate granted Trains in powers. + CharacterPower.grantTrains(this); + //see if any new powers unlocked from previous check + CharacterPower.calculatePowers(this); + + } catch (Exception e) { + } + + } + + //calculate item bonuses here + public void calculateItemBonuses() { + if (this.charItemManager == null || this.bonuses == null) + return; + ConcurrentHashMap equipped = this.charItemManager.getEquipped(); + for (Item item : equipped.values()) { + ItemBase ib = item.getItemBase(); + if (ib == null) + continue; + //TODO add effect bonuses in here for equipped items + } + } + + /** + * @ Defaults ATR, Defense and Damage for player + */ + private void defaultAtrAndDamage(boolean mainHand) { + if (mainHand) { + this.atrHandOne = 0; + this.minDamageHandOne = 0; + this.maxDamageHandOne = 0; + this.rangeHandOne = -1; + this.speedHandOne = 20; + } else { + this.atrHandTwo = 0; + this.minDamageHandTwo = 0; + this.maxDamageHandTwo = 0; + this.rangeHandTwo = -1; + this.speedHandTwo = 20; + } + } + + public void calculateMaxHealthManaStamina() { + float h = 1f; + float m = 0f; + float s = 0f; + float baseHealth = 15f; + float baseMana = 5f; + float baseStamina = 1f; + float promoHealth = 0f; + float promoMana = 0f; + float promoStamina = 0f; + float raceHealth = 0f; + float raceMana = 0f; + float raceStamina = 0f; + float toughness = 0f; + float athletics = 0f; + + //get baseclass modifiers + if (this.baseClass != null) { + baseHealth = this.baseClass.getHealthMod(); + baseMana = this.baseClass.getManaMod(); + baseStamina = this.baseClass.getStaminaMod(); + } else { + //TODO log error here + } + + //get promotion modifiers + if (this.promotionClass != null) { + promoHealth = this.promotionClass.getHealthMod(); + promoMana = this.promotionClass.getManaMod(); + promoStamina = this.promotionClass.getStaminaMod(); + } + + // next get racial modifer + if (this.race != null) { + raceHealth += this.race.getHealthBonus(); + raceMana += this.race.getManaBonus(); + raceStamina += this.race.getStaminaBonus(); + } else { + //TODO log error here + } + + //Get level modifers + float f = 0; + float g = 0; + if (this.level < 10 || this.promotionClass == null) + f = this.level; + else if (this.level < 20) { + f = this.level; + g = this.level - 9; + } else if (level < 30) { + f = (float) (19 + (this.level - 19) * 0.8); + g = (float) (10 + (this.level - 19) * 0.8); + } else if (level < 40) { + f = (float) (27 + (this.level - 29) * 0.6); + g = (float) (18 + (this.level - 29) * 0.6); + } else if (level < 50) { + f = (float) (33 + (this.level - 39) * 0.4); + g = (float) (24 + (this.level - 39) * 0.4); + } else if (level < 60) { + f = (float) (37 + (this.level - 49) * 0.2); + g = (float) (28 + (this.level - 49) * 0.2); + } else { + f = (float) (39 + (this.level - 59) * 0.1); + g = (float) (30 + (this.level - 59) * 0.1); + } + + //get toughness and athletics amount + if (this.skills != null) { + if (this.skills.containsKey("Toughness")) + toughness = this.skills.get("Toughness").getModifiedAmount(); + if (this.skills.containsKey("Athletics")) + athletics = this.skills.get("Athletics").getModifiedAmount(); + } + + h = (((f * baseHealth) + (g * promoHealth)) * (0.3f + (0.005f * this.statConCurrent)) + (this.statConCurrent + raceHealth)) * (1 + (int) toughness / 400f); + m = ((f * baseMana) + (g * promoMana)) * (0.3f + (0.005f * this.statSpiCurrent)) + (this.statSpiCurrent + raceMana); + s = (((f * baseStamina) + (g * promoStamina)) * (0.3f + (0.005f * this.statConCurrent)) + (this.statConCurrent + raceStamina)) * (1 + (int) athletics / 300f); + + // s = f * (baseStamina + 1.75f) * .5f + this.statConCurrent + raceStamina; + // Apply any bonuses from runes and effects + if (this.bonuses != null) { + + + //apply effects + h += this.bonuses.getFloat(ModType.HealthFull, SourceType.None); + m += this.bonuses.getFloat(ModType.ManaFull, SourceType.None); + s += this.bonuses.getFloat(ModType.StaminaFull, SourceType.None); + + h *= (1 + this.bonuses.getFloatPercentAll(ModType.HealthFull, SourceType.None)); + m *= (1 + this.bonuses.getFloatPercentAll(ModType.ManaFull, SourceType.None)); + s *= (1 + this.bonuses.getFloatPercentAll(ModType.StaminaFull, SourceType.None)); + + } + + // Set max health, mana and stamina + if (h > 0) + this.healthMax = h; + else + this.healthMax = 1; + if (m > -1) + this.manaMax = m; + else + this.manaMax = 0; + if (s > -1) + this.staminaMax = s; + else + this.staminaMax = 0; + + // Update health, mana and stamina if needed + if (this.getCurrentHitpoints() > this.healthMax) + this.setHealth(this.healthMax); + if (this.mana.get() > this.manaMax) + this.mana.set(this.manaMax); + if (this.stamina.get() > this.staminaMax) + this.stamina.set(staminaMax); + } + + @Override + public float getPassiveChance(String type, int attackerLevel, boolean fromCombat) { + if (this.skills == null || this.bonuses == null) + return 0f; + + ModType modType = ModType.GetModType(type); + + // must be allowed to use this passive + if (!this.bonuses.getBool(modType, SourceType.None)) + return 0f; + + // must not be stunned + if (this.bonuses.getBool(ModType.Stunned, SourceType.None)) + return 0f; + + // Get base skill amount + CharacterSkill sk = this.skills.get(type); + float amount; + if (sk == null) + amount = CharacterSkill.getQuickMastery(this, type); + else + amount = sk.getModifiedAmount(); + + // Add bonuses + amount += this.bonuses.getFloat(modType, SourceType.None); + + // Add item bonuses and return + if (type.equals(ModType.Dodge) && !fromCombat) + return ((amount / 4) - attackerLevel + this.getLevel()) / 4; + else + return (amount - attackerLevel + this.getLevel()) / 4; + } + + public float getPassiveChance1(ModType modType, SourceType sourceType, int attackerLevel, boolean fromCombat) { + if (this.skills == null || this.bonuses == null) + return 0f; + + // must be allowed to use this passive + if (!this.bonuses.getBool(modType, sourceType)) + return 0f; + + // must not be stunned + if (this.bonuses.getBool(ModType.Stunned, SourceType.None)) + return 0f; + + // Get base skill amount + CharacterSkill sk = this.skills.get(sourceType.name()); + float amount; + if (sk == null) + amount = CharacterSkill.getQuickMastery(this, modType.name()); + else + amount = sk.getModifiedAmount(); + + // Add bonuses + amount += this.bonuses.getFloat(modType, sourceType); + + // Add item bonuses and return + if (sourceType.equals(SourceType.Dodge) && !fromCombat) + return ((amount / 4) - attackerLevel + this.getLevel()) / 4; + else + return (amount - attackerLevel + this.getLevel()) / 4; + } + + public float getRegenModifier(ModType type) { + float regen = 1f; + + if (this.bonuses != null) + // get regen bonus from effects + regen = this.bonuses.getRegen(type); + return regen; + } + + @Override + public boolean canBeLooted() { + 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."); + + for (Item e : this.charItemManager.getEquipped().values()) { + e.removeFromCache(); + } + + for (Item i : this.charItemManager.getInventory(true)) { + i.removeFromCache(); + } + + for (Item b : this.charItemManager.getBank()) { + b.removeFromCache(); + } + + if (this.account.getLastCharIDUsed() == this.getObjectUUID()) + for (Item v : this.charItemManager.getVault()) { + v.removeFromCache(); + } + + for (CharacterSkill cs : this.getSkills().values()) { + cs.removeFromCache(); + } + + for (CharacterPower ps : this.getPowers().values()) { + ps.removeFromCache(); + } + + for (CharacterRune cr : this.runes) { + cr.removeFromCache(); + } + + 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() { + } + + @Override + public void runAfterLoad() { + + // Create player bounds object + + // if ((MBServer.getApp() instanceof engine.server.world.WorldServer)) + // DbManager.GuildQueries.LOAD_GUILD_HISTORY_FOR_PLAYER(this); + + Bounds playerBounds = Bounds.borrow(); + playerBounds.setBounds(this.getLoc()); + this.setBounds(playerBounds); + } + + @Override + protected ConcurrentHashMap initializePowers() { + return DbManager.CharacterPowerQueries.GET_POWERS_FOR_CHARACTER(this); + } + + @Override + public final void setFirstName(final String name) { + super.setFirstName(name); + } + + @Override + public void setLastName(final String name) { + super.setLastName(name); + } + + @Override + public short getLevel() { + return this.getPCLevel(); + } + + @Override + public void setLevel(short targetLevel) { + + short tmpLevel; + + tmpLevel = targetLevel; + + tmpLevel = (short) Math.min(tmpLevel, 75); + + while (this.level < tmpLevel) { + grantXP(Experience.getBaseExperience(tmpLevel) - this.exp); + } + + } + + @Override + public boolean asciiLastName() { + return this._asciiLastName(); + } + + @Override + public void setGuild(Guild value) { + + if (value == null) + value = Guild.getErrantGuild(); + + int guildID = 0; + + if (!value.isEmptyGuild()) + guildID = value.getObjectUUID(); + DbManager.PlayerCharacterQueries.UPDATE_GUILD(this, guildID); + super.setGuild(value); + + // Player changed guild so let's invalidate the login server + // cache to reflect this event. + + //Update player bind location; + + Building cityTol = null; + + if (value.getOwnedCity() != null) + cityTol = value.getOwnedCity().getTOL(); + + this.setBindBuildingID(cityTol != null ? cityTol.getObjectUUID() : 0); + //update binds, checks for nation tol if guild tol == null; + PlayerCharacter.getUpdatedBindBuilding(this); + + + DbManager.AccountQueries.INVALIDATE_LOGIN_CACHE(this.getObjectUUID(), "character"); + } + + public long getSummoner(int summoner) { + synchronized (this.summoners) { + if (!this.summoners.containsKey(summoner)) + return 0; + return this.summoners.get(summoner); + } + } + + public void addSummoner(int summoner, long time) { + synchronized (this.summoners) { + this.summoners.put(summoner, time); + } + } + + public void removeSummoner(int summoner) { + synchronized (this.summoners) { + if (this.summoners.containsKey(summoner)) + this.summoners.remove(summoner); + } + } + + 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.setMob(); + 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; + } + + private double getStamDeltaTime() { + + 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; + } + + @Override + public void update() { + + if (this.updateLock.writeLock().tryLock()) { + try { + + if (!this.isAlive()) + return; + + updateLocation(); + updateMovementState(); + updateRegen(); + + if (this.getStamina() < 10) { + if (this.getAltitude() > 0 || this.getDesiredAltitude() > 0) { + PlayerCharacter.GroundPlayer(this); + updateRegen(); + } + } + + RealmMap.updateRealm(this); + updateBlessingMessage(); + + this.safeZone = this.isInSafeZone(); + + } catch (Exception e) { + Logger.error(e); + } finally { + this.updateLock.writeLock().unlock(); + } + } + } + + @Override + public void updateFlight() { + + if (this.getAltitude() == 0 && this.getTakeOffTime() == 0) + return; + + if (this.getTakeOffTime() == 0) + return; + + if (this.getAltitude() == this.getDesiredAltitude()) { + if (this.getDesiredAltitude() == 0) + this.syncClient(); + //landing in a building, mark altitude to 0 as player is no longer flying. + if (this.landingRegion != null) { + this.altitude = 0; + this.region = this.landingRegion; + this.loc = this.loc.setY(this.landingRegion.lerpY(this)); + } else + this.altitude = this.getDesiredAltitude(); + + this.loc = this.loc.setY(HeightMap.getWorldHeight(this) + this.getAltitude()); + + this.setTakeOffTime(0); + MovementManager.finishChangeAltitude(this, this.getDesiredAltitude()); + + return; + } + + 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() { + + + if (!this.isMoving()) + return; + + if (!this.isActive) + return; + + Vector3fImmutable newLoc = this.getMovementLoc(); + + if (this.isAlive() == false || this.getBonuses().getBool(ModType.Stunned, SourceType.None) || this.getBonuses().getBool(ModType.CannotMove, SourceType.None)) { + //Target is stunned or rooted. Don't move + this.stopMovement(newLoc); + this.region = AbstractWorldObject.GetRegionByWorldObject(this); + return; + } + if (newLoc.equals(this.getEndLoc())) { + this.stopMovement(newLoc); + this.region = AbstractWorldObject.GetRegionByWorldObject(this); + if (this.getDebug(1)) + ChatManager.chatSystemInfo(this, + "Arrived at End location. " + this.getEndLoc()); + return; + //Next upda + } + + setLoc(newLoc); + this.region = AbstractWorldObject.GetRegionByWorldObject(this); + + if (this.getDebug(1)) + ChatManager.chatSystemInfo(this, + "Distance to target " + this.getEndLoc().distance2D(this.getLoc()) + " speed " + this.getSpeed()); + + if (this.getStamina() < 10) + MovementManager.sendOOS(this); + + // if (MBServerStatics.MOVEMENT_SYNC_DEBUG || this.getDebug(1)) + // Logger.info("MovementManager", "Updating movement current loc:" + this.getLoc().getX() + " " + this.getLoc().getZ() + // + " end loc: " + this.getEndLoc().getX() + " " + this.getEndLoc().getZ() + " distance " + this.getEndLoc().distance2D(this.getLoc())); + + } + + @Override + public void updateMovementState() { + + + if (this.enteredWorld) { + if (!this.lastSwimming) { + boolean enterWater = PlayerCharacter.enterWater(this); + + if (enterWater) { + this.lastSwimming = enterWater; + MovementManager.sendRWSSMsg(this); + + } + } else { + if (PlayerCharacter.LeaveWater(this)) { + this.lastSwimming = false; + if (!this.isMoving()) + MovementManager.sendRWSSMsg(this); + } + + } + + boolean breathe = PlayerCharacter.CanBreathe(this); + + if (breathe != this.canBreathe) { + this.canBreathe = breathe; + // ChatManager.chatSystemInfo(this, "Breathe : " + this.canBreathe); + this.syncClient(); + } + } + + //char is flying + if (this.isFlying() == true) { + this.movementState = MovementState.FLYING; + return; + } + // Char is not moving. Set sitting or idle + if (!this.isMoving()) { + + if (this.sit == true) + this.movementState = MovementState.SITTING; + else + this.movementState = MovementState.IDLE; + + return; + } else { + this.movementState = MovementState.RUNNING; + } + + // Char is swimming // we now are saving lastSwimstate boolean, use this instead of calling getSwimming again. + if (this.lastSwimming == true) { + this.movementState = MovementState.SWIMMING; + return; + } + + // Char is moving, yet not swimming or flying he must be running + this.movementState = MovementState.RUNNING; + + } + + @Override + public void updateRegen() { + + float healthRegen = 0f; + float manaRegen = 0f; + float stamRegen = 0f; + + boolean updateClient = false; + + // Early exit if char is dead or disconnected + if ((this.isAlive() == false) + || (this.isActive() == false) || this.getLoc().x == 0 && this.getLoc().z == 0) + return; + + // Calculate Regen amount from last simulation tick + switch (this.movementState) { + + case IDLE: + + healthRegen = ((this.healthMax * MBServerStatics.HEALTH_REGEN_IDLE) + MBServerStatics.HEALTH_REGEN_IDLE_STATIC) * (getRegenModifier(ModType.HealthRecoverRate)); + + if (this.isCasting() || this.isItemCasting()) + healthRegen *= .75f; + // Characters regen mana when in only walk mode and idle + if (this.walkMode) + manaRegen = ((this.manaMax * MBServerStatics.MANA_REGEN_IDLE) * getRegenModifier(ModType.ManaRecoverRate)); + else if (!this.isCasting() && !this.isItemCasting()) + manaRegen = ((this.manaMax * MBServerStatics.MANA_REGEN_IDLE) * getRegenModifier(ModType.ManaRecoverRate)); + else + manaRegen = 0; + + if (!PlayerCharacter.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); + else + stamRegen = 0; + break; + case SITTING: + healthRegen = ((this.healthMax * MBServerStatics.HEALTH_REGEN_SIT) + MBServerStatics.HEALTH_REGEN_SIT_STATIC) * getRegenModifier(ModType.HealthRecoverRate); + manaRegen = (this.manaMax * MBServerStatics.MANA_REGEN_SIT) * (getRegenModifier(ModType.ManaRecoverRate)); + stamRegen = MBServerStatics.STAMINA_REGEN_SIT * getRegenModifier(ModType.StaminaRecoverRate); + break; + case RUNNING: + if (this.walkMode == true) { + healthRegen = ((this.healthMax * MBServerStatics.HEALTH_REGEN_WALK) + MBServerStatics.HEALTH_REGEN_IDLE_STATIC) * getRegenModifier(ModType.HealthRecoverRate); + manaRegen = this.manaMax * MBServerStatics.MANA_REGEN_WALK * getRegenModifier(ModType.ManaRecoverRate); + stamRegen = MBServerStatics.STAMINA_REGEN_WALK; + } else { + healthRegen = 0; + manaRegen = 0; + + if (this.combat == true) + stamRegen = MBServerStatics.STAMINA_REGEN_RUN_COMBAT; + else + stamRegen = MBServerStatics.STAMINA_REGEN_RUN_NONCOMBAT; + } + break; + case FLYING: + + float seventyFive = this.staminaMax * .75f; + float fifty = this.staminaMax * .5f; + float twentyFive = this.staminaMax * .25f; + + if (this.getDesiredAltitude() == 0 && this.getAltitude() <= 10) { + if (this.isCombat()) + stamRegen = 0; + else + stamRegen = MBServerStatics.STAMINA_REGEN_IDLE * getRegenModifier(ModType.StaminaRecoverRate); + } else if (!this.useFlyMoveRegen()) { + + healthRegen = ((this.healthMax * MBServerStatics.HEALTH_REGEN_IDLE) + MBServerStatics.HEALTH_REGEN_IDLE_STATIC) * (getRegenModifier(ModType.HealthRecoverRate)); + + if (this.isCasting() || this.isItemCasting()) + healthRegen *= .75f; + // Characters regen mana when in only walk mode and idle + if (this.walkMode) + manaRegen = (this.manaMax * MBServerStatics.MANA_REGEN_IDLE + (this.getSpiMod() * .015f)) * (getRegenModifier(ModType.ManaRecoverRate)); + else if (!this.isCasting() && !this.isItemCasting()) + manaRegen = (this.manaMax * MBServerStatics.MANA_REGEN_IDLE + (this.getSpiMod() * .015f)) * (getRegenModifier(ModType.ManaRecoverRate)); + else + manaRegen = 0; + + if (!this.isItemCasting() && !this.isCasting() || this.getTakeOffTime() != 0) + stamRegen = MBServerStatics.STAMINA_REGEN_FLY_IDLE; + else + stamRegen = -1f; + } else if (this.walkMode == true) { + healthRegen = ((this.healthMax * MBServerStatics.HEALTH_REGEN_WALK) + MBServerStatics.HEALTH_REGEN_IDLE_STATIC) * getRegenModifier(ModType.HealthRecoverRate); + manaRegen = ((this.manaMax * MBServerStatics.MANA_REGEN_WALK) + (this.getSpiMod() * .015f)) * (getRegenModifier(ModType.ManaRecoverRate)); + stamRegen = MBServerStatics.STAMINA_REGEN_FLY_WALK; + } else { + healthRegen = 0; + manaRegen = 0; + if (this.isCombat()) + stamRegen = MBServerStatics.STAMINA_REGEN_FLY_RUN_COMBAT; + else + stamRegen = MBServerStatics.STAMINA_REGEN_FLY_RUN; + } + + float oldStamina = this.stamina.get(); + + if (FastMath.between(oldStamina, 0, twentyFive) && !this.wasTripped25) { + updateClient = true; + this.wasTripped25 = true; + this.wasTripped50 = false; + this.wasTripped75 = false; + } else if (FastMath.between(oldStamina, twentyFive, fifty) && !this.wasTripped50) { + updateClient = true; + this.wasTripped25 = false; + this.wasTripped50 = true; + this.wasTripped75 = false; + } else if (FastMath.between(oldStamina, fifty, seventyFive) && !this.wasTripped75) { + updateClient = true; + this.wasTripped25 = false; + this.wasTripped50 = false; + this.wasTripped75 = true; + } + break; + case SWIMMING: + if (this.walkMode == true) { + healthRegen = ((this.healthMax * MBServerStatics.HEALTH_REGEN_WALK) + MBServerStatics.HEALTH_REGEN_IDLE_STATIC) * getRegenModifier(ModType.HealthRecoverRate); + manaRegen = ((this.manaMax * MBServerStatics.MANA_REGEN_WALK) + (this.getSpiMod() * .015f)) * (getRegenModifier(ModType.ManaRecoverRate)); + stamRegen = MBServerStatics.STAMINA_REGEN_SWIM; + } else { + healthRegen = 0; + manaRegen = 0; + stamRegen = MBServerStatics.STAMINA_REGEN_SWIM; + + if (this.combat == true) + stamRegen += MBServerStatics.STAMINA_REGEN_RUN_COMBAT; + else + stamRegen += MBServerStatics.STAMINA_REGEN_RUN_NONCOMBAT; + } + break; + } + + // Are we drowning? + if ((this.getStamina() <= 0) + && (PlayerCharacter.CanBreathe(this) == false)) + healthRegen = (this.healthMax * -.03f); + + // Multiple regen values by current deltaTime + // Logger.info("", healthRegen + ""); + healthRegen *= getDeltaTime(); + manaRegen *= getDeltaTime(); + stamRegen *= getStamDeltaTime(); + + boolean workedHealth = false; + boolean workedMana = false; + boolean workedStamina = false; + + float old, mod; + while (!workedHealth || !workedMana || !workedStamina) { + if (!this.isAlive() || !this.isActive()) + return; + if (!workedHealth) { + old = this.health.get(); + mod = old + healthRegen; + if (mod > this.healthMax) + mod = healthMax; + else if (mod <= 0) { + if (this.isAlive.compareAndSet(true, false)) + killCharacter("Water"); + return; + } + workedHealth = this.health.compareAndSet(old, mod); + } + if (!workedStamina) { + old = this.stamina.get(); + mod = old + stamRegen; + if (mod > this.staminaMax) + mod = staminaMax; + else if (mod < 0) + mod = 0; + workedStamina = this.stamina.compareAndSet(old, mod); + } + if (!workedMana) { + old = this.mana.get(); + mod = old + manaRegen; + if (mod > this.manaMax) + mod = manaMax; + else if (mod < 0) + mod = 0; + workedMana = this.mana.compareAndSet(old, mod); + } + } + + if (updateClient) + this.syncClient(); + + // Reset this char's frame time. + this.lastUpdateTime = System.currentTimeMillis(); + this.lastStamUpdateTime = System.currentTimeMillis(); + + } + + public synchronized void updateStamRegen(long time) { + + boolean disable = true; + + if (disable) + return; + + float stamRegen = 0f; + + // Early exit if char is dead or disconnected + if ((this.isAlive() == false) + || (this.isActive() == false) || this.getLoc().x == 0 && this.getLoc().z == 0) + return; + + // Calculate Regen amount from last simulation tick + switch (this.movementState) { + + case IDLE: + if (!PlayerCharacter.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); + else + stamRegen = 0; + break; + case SITTING: + stamRegen = MBServerStatics.STAMINA_REGEN_SIT * getRegenModifier(ModType.StaminaRecoverRate); + break; + case RUNNING: + if (this.walkMode == true) { + stamRegen = MBServerStatics.STAMINA_REGEN_WALK; + } else { + if (this.combat == true) + stamRegen = MBServerStatics.STAMINA_REGEN_RUN_COMBAT; + else + stamRegen = MBServerStatics.STAMINA_REGEN_RUN_NONCOMBAT; + } + break; + case FLYING: + + if (this.getDesiredAltitude() == 0 && this.getAltitude() <= 10) { + if (this.isCombat()) + stamRegen = 0; + else + stamRegen = MBServerStatics.STAMINA_REGEN_IDLE * getRegenModifier(ModType.StaminaRecoverRate); + } else if (!this.isMoving()) { + + + if (!this.isItemCasting() && !this.isCasting() || this.getTakeOffTime() != 0) + stamRegen = MBServerStatics.STAMINA_REGEN_FLY_IDLE; + else + stamRegen = -1f; + + } else if (this.walkMode == true) { + + stamRegen = MBServerStatics.STAMINA_REGEN_FLY_WALK; + } else { + if (this.isCombat()) + stamRegen = MBServerStatics.STAMINA_REGEN_FLY_RUN_COMBAT; + else + stamRegen = MBServerStatics.STAMINA_REGEN_FLY_RUN; + } + break; + case SWIMMING: + if (this.walkMode == true) { + stamRegen = MBServerStatics.STAMINA_REGEN_SWIM; + } else { + stamRegen = MBServerStatics.STAMINA_REGEN_SWIM; + } + break; + } + + + // Multiple regen values by current deltaTime + // Logger.info("", healthRegen + ""); + + stamRegen *= (time * .001f); + + + boolean workedStamina = false; + + + float old, mod; + while (!workedStamina) { + if (!this.isAlive() || !this.isActive()) + return; + + if (!workedStamina) { + old = this.stamina.get(); + mod = old + stamRegen; + if (mod > this.staminaMax) + mod = staminaMax; + else if (mod < 0) + mod = 0; + workedStamina = this.stamina.compareAndSet(old, mod); + } + + } + + } + + public void syncClient() { + + ModifyHealthMsg modifyHealthMsg = new ModifyHealthMsg(null, this, 0, 1, 1, -1984683793, "", 0, 652920987); + //mhm.setOmitFromChat(0); + Dispatch dispatch = Dispatch.borrow(this, modifyHealthMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + + } + + public MovementState getMovementState() { + 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; + } + + public void setHash() { + + this.hash = DataWarehouse.hasher.encrypt(this.getObjectUUID()); + + // Write hash to player character table + + DataWarehouse.writeHash(DataRecordType.CHARACTER, this.getObjectUUID()); + } + + public AtomicInteger getGuildStatus() { + return guildStatus; + } + + public int getLastRealmID() { + return lastRealmID; + } + + public void setLastRealmID(int lastRealmID) { + this.lastRealmID = lastRealmID; + } + + public int getSubRaceID() { + return subRaceID; + } + + public void setSubRaceID(int subRaceID) { + this.subRaceID = subRaceID; + } + + public ArrayList getGuildHistory() { + return guildHistory; + } + + public void setGuildHistory(ArrayList guildHistory) { + 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; + float unknownScale1 = 0; + float unknownScale2 = 0; + float unknownScale3 = 0; + + float scaleHeight = 0; + + if ((int) this.statStrBase > 40) + strengthScale = ((int) this.statStrBase - 40) * 0.0024999999f; //Y scale ? + + unknownScale1 = (float) (((int) this.statStrBase * 0.0024999999f + strengthScale + 0.89999998) * race.getRaceType().getScaleHeight()); + strengthScale = (int) this.statStrBase * 0.0037499999f + strengthScale + 0.85000002f; //strengthScale is different for x and z + + unknownScale2 = strengthScale * race.getRaceType().getScaleHeight(); //x scale? + unknownScale3 = strengthScale * race.getRaceType().getScaleHeight(); //z Scale? + + + scaleHeight = (1.5f + unknownScale1); + + + this.characterHeight = scaleHeight; + + this.centerHeight = scaleHeight; + + } + + public int getOverFlowEXP() { + return overFlowEXP; + } + + public void setOverFlowEXP(int overFlowEXP) { + this.overFlowEXP = overFlowEXP; + } + + public MovementState getLastMovementState() { + return lastMovementState; + } + + public void setLastMovementState(MovementState lastMovementState) { + this.lastMovementState = lastMovementState; + } + + @Override + public final void setIsCasting(final boolean isCasting) { + if (this.isCasting != isCasting) + this.update(); + this.isCasting = isCasting; + } + + @Override + public void setItemCasting(boolean itemCasting) { + if (this.itemCasting != itemCasting) + this.dynamicUpdate(UpdateType.REGEN); + this.itemCasting = itemCasting; + } + + public void resetRegenUpdateTime() { + this.lastUpdateTime = System.currentTimeMillis(); + this.lastStamUpdateTime = System.currentTimeMillis(); + } + + public float getCharacterHeight() { + 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) { + locationLock.writeLock().lock(); + try { + MovementManager.translocate(this, targetLoc, null); + } 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; + } } diff --git a/src/engine/objects/PlayerFriends.java b/src/engine/objects/PlayerFriends.java index 2d2cdf08..97405333 100644 --- a/src/engine/objects/PlayerFriends.java +++ b/src/engine/objects/PlayerFriends.java @@ -21,102 +21,101 @@ import java.sql.SQLException; import java.util.HashMap; import java.util.HashSet; -public class PlayerFriends { - - public int playerUID; - public int friendUID; - - public static HashMap > PlayerFriendsMap = new HashMap<>(); - - /** - * ResultSet Constructor - */ - - public PlayerFriends(ResultSet rs) throws SQLException { - this.playerUID = rs.getInt("playerUID"); - this.friendUID = rs.getInt("friendUID"); - - //cache player friends. - //hashset already created, just add to set. - if (PlayerFriendsMap.containsKey(playerUID)){ - HashSet playerFriendSet = PlayerFriendsMap.get(playerUID); - playerFriendSet.add(friendUID); - //hashset not yet created, create new set, and add to map. - }else{ - HashSet playerFriendSet = new HashSet<>(); - playerFriendSet.add(friendUID); - PlayerFriendsMap.put(this.playerUID, playerFriendSet); - } - - } - - public PlayerFriends(int playerUID, int friendUID) { - super(); - this.playerUID = playerUID; - this.friendUID = friendUID; - } - - public int getPlayerUID() { - return playerUID; - } - - public static void AddToFriends(int playerID, int friendID){ - HashSet friends = PlayerFriendsMap.get(playerID); - - if (friends != null){ - //already in friends list, don't do anything. - if (friends.contains(friendID)) - return; - - DbManager.PlayerCharacterQueries.ADD_FRIEND(playerID, friendID); - friends.add(friendID); - }else{ - friends = new HashSet<>(); - DbManager.PlayerCharacterQueries.ADD_FRIEND(playerID, friendID); - friends.add(friendID); - PlayerFriendsMap.put(playerID, friends); - } - } - - public static void RemoveFromFriends(int playerID, int friendID){ - - if (!CanRemove(playerID, friendID)) - return; - -HashSet friends = PlayerFriendsMap.get(playerID); - - if (friends != null){ - DbManager.PlayerCharacterQueries.REMOVE_FRIEND(playerID, friendID); - friends.remove(friendID); - } - } - - public static boolean CanRemove(int playerID, int toRemove){ - if (PlayerFriendsMap.get(playerID) == null) - return false; - - if (PlayerFriendsMap.get(playerID).isEmpty()) - return false; - - if (!PlayerFriendsMap.get(playerID).contains(toRemove)) - return false; - - return true; - } - - public static void SendFriendsStatus(PlayerCharacter player, boolean online ){ - HashSet friendsSet = PlayerFriends.PlayerFriendsMap.get(player.getObjectUUID()); - if (friendsSet != null){ - for(int friendID: friendsSet){ - PlayerCharacter friend = SessionManager.getPlayerCharacterByID(friendID); - if (friend == null) - continue; - UpdateFriendStatusMessage outMsg = new UpdateFriendStatusMessage(player); - outMsg.online = online; - Dispatch dispatch = Dispatch.borrow(friend, outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } - } - - } +public class PlayerFriends { + + public static HashMap> PlayerFriendsMap = new HashMap<>(); + public int playerUID; + public int friendUID; + + /** + * ResultSet Constructor + */ + + public PlayerFriends(ResultSet rs) throws SQLException { + this.playerUID = rs.getInt("playerUID"); + this.friendUID = rs.getInt("friendUID"); + + //cache player friends. + //hashset already created, just add to set. + if (PlayerFriendsMap.containsKey(playerUID)) { + HashSet playerFriendSet = PlayerFriendsMap.get(playerUID); + playerFriendSet.add(friendUID); + //hashset not yet created, create new set, and add to map. + } else { + HashSet playerFriendSet = new HashSet<>(); + playerFriendSet.add(friendUID); + PlayerFriendsMap.put(this.playerUID, playerFriendSet); + } + + } + + public PlayerFriends(int playerUID, int friendUID) { + super(); + this.playerUID = playerUID; + this.friendUID = friendUID; + } + + public static void AddToFriends(int playerID, int friendID) { + HashSet friends = PlayerFriendsMap.get(playerID); + + if (friends != null) { + //already in friends list, don't do anything. + if (friends.contains(friendID)) + return; + + DbManager.PlayerCharacterQueries.ADD_FRIEND(playerID, friendID); + friends.add(friendID); + } else { + friends = new HashSet<>(); + DbManager.PlayerCharacterQueries.ADD_FRIEND(playerID, friendID); + friends.add(friendID); + PlayerFriendsMap.put(playerID, friends); + } + } + + public static void RemoveFromFriends(int playerID, int friendID) { + + if (!CanRemove(playerID, friendID)) + return; + + HashSet friends = PlayerFriendsMap.get(playerID); + + if (friends != null) { + DbManager.PlayerCharacterQueries.REMOVE_FRIEND(playerID, friendID); + friends.remove(friendID); + } + } + + public static boolean CanRemove(int playerID, int toRemove) { + if (PlayerFriendsMap.get(playerID) == null) + return false; + + if (PlayerFriendsMap.get(playerID).isEmpty()) + return false; + + if (!PlayerFriendsMap.get(playerID).contains(toRemove)) + return false; + + return true; + } + + public static void SendFriendsStatus(PlayerCharacter player, boolean online) { + HashSet friendsSet = PlayerFriends.PlayerFriendsMap.get(player.getObjectUUID()); + if (friendsSet != null) { + for (int friendID : friendsSet) { + PlayerCharacter friend = SessionManager.getPlayerCharacterByID(friendID); + if (friend == null) + continue; + UpdateFriendStatusMessage outMsg = new UpdateFriendStatusMessage(player); + outMsg.online = online; + Dispatch dispatch = Dispatch.borrow(friend, outMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + } + } + + } + + public int getPlayerUID() { + return playerUID; + } } diff --git a/src/engine/objects/Portal.java b/src/engine/objects/Portal.java index 78e382c3..f285f45a 100644 --- a/src/engine/objects/Portal.java +++ b/src/engine/objects/Portal.java @@ -18,101 +18,101 @@ import java.util.HashSet; public class Portal { - private boolean active; - public Enum.PortalType portalType; - public Building sourceGate; - public Building targetGate; - public final Vector3fImmutable portalLocation; - private long lastActive = 0; + public final Vector3fImmutable portalLocation; + public Enum.PortalType portalType; + public Building sourceGate; + public Building targetGate; + private boolean active; + private long lastActive = 0; - public Portal(Building sourceGate, PortalType portalType, Building targetGate) { - Vector3fImmutable tmpLocation; + public Portal(Building sourceGate, PortalType portalType, Building targetGate) { + Vector3fImmutable tmpLocation; - this.active = false; - this.sourceGate = sourceGate; - this.targetGate = targetGate; - this.portalType = portalType; + this.active = false; + this.sourceGate = sourceGate; + this.targetGate = targetGate; + this.portalType = portalType; - tmpLocation = sourceGate.getLoc().add(new Vector3fImmutable(portalType.offset.x, 6, portalType.offset.y)); + tmpLocation = sourceGate.getLoc().add(new Vector3fImmutable(portalType.offset.x, 6, portalType.offset.y)); - // Rotate portal by gate rotation + // Rotate portal by gate rotation - tmpLocation = Vector3fImmutable.rotateAroundPoint(sourceGate.getLoc(), tmpLocation, sourceGate.getBounds().getQuaternion().angleY); + tmpLocation = Vector3fImmutable.rotateAroundPoint(sourceGate.getLoc(), tmpLocation, sourceGate.getBounds().getQuaternion().angleY); - this.portalLocation = tmpLocation; - } + this.portalLocation = tmpLocation; + } - public boolean isActive() { + public boolean isActive() { - return this.active; + return this.active; - } + } - public void deactivate() { + public void deactivate() { - // Remove effect bit from the runegate building, which turns off this - // portal type's particle effect + // Remove effect bit from the runegate building, which turns off this + // portal type's particle effect - sourceGate.removeEffectBit(portalType.effectFlag); - this.active = false; - sourceGate.updateEffects(); - } + sourceGate.removeEffectBit(portalType.effectFlag); + this.active = false; + sourceGate.updateEffects(); + } - public void activate(boolean autoClose) { + public void activate(boolean autoClose) { - Building sourceBuilding; + Building sourceBuilding; - // Apply effect bit to the runegate building, which turns on this - // portal type's particle effect + // Apply effect bit to the runegate building, which turns on this + // portal type's particle effect - sourceGate.addEffectBit(portalType.effectFlag); - this.lastActive = System.currentTimeMillis(); - this.active = true; + sourceGate.addEffectBit(portalType.effectFlag); + this.lastActive = System.currentTimeMillis(); + this.active = true; - // Do not update effects at bootstrap as it - // tries to send a dispatch. + // Do not update effects at bootstrap as it + // tries to send a dispatch. - if (ConfigManager.worldServer.isRunning == true) - sourceGate.updateEffects(); + if (ConfigManager.worldServer.isRunning == true) + sourceGate.updateEffects(); - if (autoClose == true) { + if (autoClose == true) { CloseGateJob cgj = new CloseGateJob(sourceGate, portalType); - JobScheduler.getInstance().scheduleJob(cgj, MBServerStatics.RUNEGATE_CLOSE_TIME); - } - } + JobScheduler.getInstance().scheduleJob(cgj, MBServerStatics.RUNEGATE_CLOSE_TIME); + } + } - public void collide() { + public void collide() { - HashSet playerList; + HashSet playerList; - playerList = WorldGrid.getObjectsInRangePartial(this.portalLocation, 2, MBServerStatics.MASK_PLAYER); + playerList = WorldGrid.getObjectsInRangePartial(this.portalLocation, 2, MBServerStatics.MASK_PLAYER); - if (playerList.isEmpty()) - return; + if (playerList.isEmpty()) + return; - for (AbstractWorldObject player : playerList) { + for (AbstractWorldObject player : playerList) { - onEnter((PlayerCharacter) player); + onEnter((PlayerCharacter) player); - } - } + } + } - public void onEnter(PlayerCharacter player) { + public void onEnter(PlayerCharacter player) { - if (player.getTimeStamp("lastMoveGate") < this.lastActive) - return; + if (player.getTimeStamp("lastMoveGate") < this.lastActive) + return; - player.teleport(targetGate.getLoc()); - player.setSafeMode(); - - } + player.teleport(targetGate.getLoc()); + player.setSafeMode(); - /** - * @return the portalLocation - */ - public Vector3fImmutable getPortalLocation() { - return portalLocation; - } + } + + /** + * @return the portalLocation + */ + public Vector3fImmutable getPortalLocation() { + return portalLocation; + } } diff --git a/src/engine/objects/PowerGrant.java b/src/engine/objects/PowerGrant.java index fb5a8c31..cffa21b9 100644 --- a/src/engine/objects/PowerGrant.java +++ b/src/engine/objects/PowerGrant.java @@ -18,121 +18,120 @@ import java.util.ArrayList; import java.util.concurrent.ConcurrentHashMap; - - public class PowerGrant extends AbstractGameObject { - private int token; - private ConcurrentHashMap runeGrants = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private static ConcurrentHashMap grantedPowers = null; - - /** - * ResultSet Constructor - */ - public PowerGrant(ResultSet rs) throws SQLException { - super(); - this.token = rs.getInt("powerToken"); - runeGrants.put(rs.getInt("runeID"), rs.getShort("grantAmount")); - } - - /* - * Getters - */ - - public ConcurrentHashMap getRuneGrants() { - return this.runeGrants; - } - - public int getToken() { - return this.token; - } - - private void addRuneGrant(int runeID, short amount) { - this.runeGrants.put(runeID, amount); - } + private static ConcurrentHashMap grantedPowers = null; + private int token; + private ConcurrentHashMap runeGrants = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + /** + * ResultSet Constructor + */ + public PowerGrant(ResultSet rs) throws SQLException { + super(); + this.token = rs.getInt("powerToken"); + runeGrants.put(rs.getInt("runeID"), rs.getShort("grantAmount")); + } - /* - * Database - */ + /* + * Getters + */ - public static Short getGrantedTrains(int token, PlayerCharacter pc) { - if (pc == null) - return (short) 0; + public static Short getGrantedTrains(int token, PlayerCharacter pc) { + if (pc == null) + return (short) 0; - if (PowerGrant.grantedPowers == null) - fillGrantedPowers(); + if (PowerGrant.grantedPowers == null) + fillGrantedPowers(); - if (PowerGrant.grantedPowers.containsKey(token)) { - PowerGrant pg = PowerGrant.grantedPowers.get(token); + if (PowerGrant.grantedPowers.containsKey(token)) { + PowerGrant pg = PowerGrant.grantedPowers.get(token); ConcurrentHashMap runeGrants = pg.runeGrants; - ArrayList toks = new ArrayList<>(); - - //get race ID - Race race = pc.getRace(); - if (race != null) - toks.add(race.getRaceRuneID()); - - //get baseClass ID - BaseClass bc = pc.getBaseClass(); - if (bc != null) - toks.add(bc.getObjectUUID()); - - //get promoClass ID - PromotionClass pcc = pc.getPromotionClass(); - if (pcc != null) - toks.add(pcc.getObjectUUID()); - - //get promotion and base class combined ID - if (bc != null && pcc != null) - toks.add( ((pcc.getObjectUUID() * 10) + bc.getObjectUUID()) ); - - //get any other rune IDs - ArrayList runes = pc.getRunes(); - for (CharacterRune rune : runes) - toks.add(rune.getRuneBaseID()); - - //Add any power bonuses granted from runes up - short amount = (short) 0; - for (Integer tok : toks) { - if (runeGrants.containsKey(tok)) - amount += runeGrants.get(tok); - } - - return amount; - } else - return (short) 0; - } - - public static void fillGrantedPowers() { - PowerGrant.grantedPowers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - PreparedStatementShared ps = null; - try { - ps = prepareStatement("SELECT * FROM static_power_powergrant"); - ResultSet rs = ps.executeQuery(); - if (PowerGrant.grantedPowers.size() > 0) { - rs.close(); - return; - } - while (rs.next()) { - int token = rs.getInt("powerToken"); - PowerGrant pg = null; - if (PowerGrant.grantedPowers.containsKey(token)) { - pg = PowerGrant.grantedPowers.get(token); - pg.addRuneGrant(rs.getInt("runeID"), rs.getShort("grantAmount")); - } else { - pg = new PowerGrant(rs); - PowerGrant.grantedPowers.put(token, pg); - } - } - rs.close(); - } catch (SQLException e) { - Logger.error( "SQL Error number: " + e.getErrorCode(), e); - } finally { - ps.release(); - } - } - - @Override - public void updateDatabase() {} + ArrayList toks = new ArrayList<>(); + + //get race ID + Race race = pc.getRace(); + if (race != null) + toks.add(race.getRaceRuneID()); + + //get baseClass ID + BaseClass bc = pc.getBaseClass(); + if (bc != null) + toks.add(bc.getObjectUUID()); + + //get promoClass ID + PromotionClass pcc = pc.getPromotionClass(); + if (pcc != null) + toks.add(pcc.getObjectUUID()); + + //get promotion and base class combined ID + if (bc != null && pcc != null) + toks.add(((pcc.getObjectUUID() * 10) + bc.getObjectUUID())); + + //get any other rune IDs + ArrayList runes = pc.getRunes(); + for (CharacterRune rune : runes) + toks.add(rune.getRuneBaseID()); + + //Add any power bonuses granted from runes up + short amount = (short) 0; + for (Integer tok : toks) { + if (runeGrants.containsKey(tok)) + amount += runeGrants.get(tok); + } + + return amount; + } else + return (short) 0; + } + + public static void fillGrantedPowers() { + PowerGrant.grantedPowers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + PreparedStatementShared ps = null; + try { + ps = prepareStatement("SELECT * FROM static_power_powergrant"); + ResultSet rs = ps.executeQuery(); + if (PowerGrant.grantedPowers.size() > 0) { + rs.close(); + return; + } + while (rs.next()) { + int token = rs.getInt("powerToken"); + PowerGrant pg = null; + if (PowerGrant.grantedPowers.containsKey(token)) { + pg = PowerGrant.grantedPowers.get(token); + pg.addRuneGrant(rs.getInt("runeID"), rs.getShort("grantAmount")); + } else { + pg = new PowerGrant(rs); + PowerGrant.grantedPowers.put(token, pg); + } + } + rs.close(); + } catch (SQLException e) { + Logger.error("SQL Error number: " + e.getErrorCode(), e); + } finally { + ps.release(); + } + } + + public ConcurrentHashMap getRuneGrants() { + return this.runeGrants; + } + + + /* + * Database + */ + + public int getToken() { + return this.token; + } + + private void addRuneGrant(int runeID, short amount) { + this.runeGrants.put(runeID, amount); + } + + @Override + public void updateDatabase() { + } } diff --git a/src/engine/objects/PowerReq.java b/src/engine/objects/PowerReq.java index 7c5548d3..bc1e7c2b 100644 --- a/src/engine/objects/PowerReq.java +++ b/src/engine/objects/PowerReq.java @@ -23,172 +23,172 @@ import java.util.concurrent.ConcurrentHashMap; public class PowerReq extends AbstractGameObject implements Comparable { - private PowersBase powersBase; - private int token; - private short level; - private ConcurrentHashMap powerReqs; - private ConcurrentHashMap skillReqs; - - private static ConcurrentHashMap> runePowers = fillRunePowers(); - private static ArrayList powersForAll = new ArrayList<>(); - - /** - * No Table ID Constructor - */ - public PowerReq(PowersBase powersBase, short level, ConcurrentHashMap powerReqs, ConcurrentHashMap skillReqs) { - super(); - this.powersBase = powersBase; - this.level = level; - this.powerReqs = powerReqs; - this.skillReqs = skillReqs; - if (this.powersBase != null) - this.token = this.powersBase.getToken(); - else - this.token = 0; - } - - /** - * Normal Constructor - */ - public PowerReq(PowersBase powersBase, short level, ConcurrentHashMap powerReqs, ConcurrentHashMap skillReqs, int newUUID) { - super(newUUID); - this.powersBase = powersBase; - this.level = level; - this.powerReqs = powerReqs; - this.skillReqs = skillReqs; - if (this.powersBase != null) - this.token = this.powersBase.getToken(); - else - this.token = 0; - } - - /** - * ResultSet Constructor - */ - public PowerReq(ResultSet rs) throws SQLException { - super(rs); - this.token = rs.getInt("powerToken"); - this.powersBase = PowersManager.getPowerByToken(this.token); - this.level = rs.getShort("level"); - int type = rs.getInt("type"); - this.powerReqs = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - this.skillReqs = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - if (type == 1) - this.skillReqs.put(rs.getInt("requiredToken"), rs.getByte("requiredAmount")); - else if (type == 2) - this.powerReqs.put(rs.getInt("requiredToken"), rs.getByte("requiredAmount")); - } - - /* - * Getters - */ - public PowersBase getPowersBase() { - if (this.powersBase == null) { - this.powersBase = PowersManager.getPowerByToken(this.token); - } - return this.powersBase; - } - - public short getLevel() { - return this.level; - } - - public ConcurrentHashMap getPowerReqs() { - return this.powerReqs; - } - - public ConcurrentHashMap getSkillReqs() { - return this.skillReqs; - } - - public int getToken() { - return this.token; - } - - private void addPower(int token, byte amount) { - this.powerReqs.put(token, amount); - } - - private void addSkill(int token, byte amount) { - this.skillReqs.put(token, amount); - } - - - @Override - public int compareTo(PowerReq n) throws ClassCastException { - if (n.level == this.level) - return 0; - else if (this.level > n.level) - return 1; - else - return -1; - } - - - /* - * Database - */ - - public static ArrayList getPowerReqsForRune(int id) { + private static ArrayList powersForAll = new ArrayList<>(); + private PowersBase powersBase; + private int token; + private short level; + private ConcurrentHashMap powerReqs; + private ConcurrentHashMap skillReqs; + private static ConcurrentHashMap> runePowers = fillRunePowers(); + + /** + * No Table ID Constructor + */ + public PowerReq(PowersBase powersBase, short level, ConcurrentHashMap powerReqs, ConcurrentHashMap skillReqs) { + super(); + this.powersBase = powersBase; + this.level = level; + this.powerReqs = powerReqs; + this.skillReqs = skillReqs; + if (this.powersBase != null) + this.token = this.powersBase.getToken(); + else + this.token = 0; + } + + /** + * Normal Constructor + */ + public PowerReq(PowersBase powersBase, short level, ConcurrentHashMap powerReqs, ConcurrentHashMap skillReqs, int newUUID) { + super(newUUID); + this.powersBase = powersBase; + this.level = level; + this.powerReqs = powerReqs; + this.skillReqs = skillReqs; + if (this.powersBase != null) + this.token = this.powersBase.getToken(); + else + this.token = 0; + } + + /** + * ResultSet Constructor + */ + public PowerReq(ResultSet rs) throws SQLException { + super(rs); + this.token = rs.getInt("powerToken"); + this.powersBase = PowersManager.getPowerByToken(this.token); + this.level = rs.getShort("level"); + int type = rs.getInt("type"); + this.powerReqs = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + this.skillReqs = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + if (type == 1) + this.skillReqs.put(rs.getInt("requiredToken"), rs.getByte("requiredAmount")); + else if (type == 2) + this.powerReqs.put(rs.getInt("requiredToken"), rs.getByte("requiredAmount")); + } + + public static ArrayList getPowerReqsForRune(int id) { // if (PowerReq.runePowers == null) // fillRunePowers(); - if (PowerReq.runePowers.containsKey(id)) - return PowerReq.runePowers.get(id); - return new ArrayList<>(); - } - - public static ConcurrentHashMap> fillRunePowers() { - PowerReq.runePowers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - PreparedStatementShared ps = null; - try { - ps = prepareStatement("SELECT * FROM static_power_powerrequirement"); - ResultSet rs = ps.executeQuery(); - if (PowerReq.runePowers.size() > 0) { - rs.close(); - return PowerReq.runePowers; - } - while (rs.next()) { - ArrayList runePR = null; - int runeID = rs.getInt("runeID"); - int token = rs.getInt("powerToken"); - if (PowerReq.runePowers.containsKey(runeID)) - runePR = PowerReq.runePowers.get(runeID); - else { - runePR = new ArrayList<>(); - PowerReq.runePowers.put(runeID, runePR); - } - boolean found = false; - for (PowerReq pr : runePR) { + if (PowerReq.runePowers.containsKey(id)) + return PowerReq.runePowers.get(id); + return new ArrayList<>(); + } + + public static ConcurrentHashMap> fillRunePowers() { + PowerReq.runePowers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + PreparedStatementShared ps = null; + try { + ps = prepareStatement("SELECT * FROM static_power_powerrequirement"); + ResultSet rs = ps.executeQuery(); + if (PowerReq.runePowers.size() > 0) { + rs.close(); + return PowerReq.runePowers; + } + while (rs.next()) { + ArrayList runePR = null; + int runeID = rs.getInt("runeID"); + int token = rs.getInt("powerToken"); + if (PowerReq.runePowers.containsKey(runeID)) + runePR = PowerReq.runePowers.get(runeID); + else { + runePR = new ArrayList<>(); + PowerReq.runePowers.put(runeID, runePR); + } + boolean found = false; + for (PowerReq pr : runePR) { if (pr.token == token) { - int type = rs.getInt("type"); - if (type == 1) - pr.addSkill(rs.getInt("requiredToken"), rs.getByte("requiredAmount")); - else - pr.addPower(rs.getInt("requiredToken"), rs.getByte("requiredAmount")); - found = true; - } - } - if (!found) { - PowerReq pr = new PowerReq(rs); - runePR.add(pr); - } - } - rs.close(); - - //order the lists by level so prerequisites are met - for (ArrayList runePR : PowerReq.runePowers.values()) { - Collections.sort(runePR); - } - } catch (SQLException e) { - Logger.error( "SQL Error number: " + e.getErrorCode(), e); - } finally { - ps.release(); - } - return PowerReq.runePowers; - } - - @Override - public void updateDatabase() { - - } + int type = rs.getInt("type"); + if (type == 1) + pr.addSkill(rs.getInt("requiredToken"), rs.getByte("requiredAmount")); + else + pr.addPower(rs.getInt("requiredToken"), rs.getByte("requiredAmount")); + found = true; + } + } + if (!found) { + PowerReq pr = new PowerReq(rs); + runePR.add(pr); + } + } + rs.close(); + + //order the lists by level so prerequisites are met + for (ArrayList runePR : PowerReq.runePowers.values()) { + Collections.sort(runePR); + } + } catch (SQLException e) { + Logger.error("SQL Error number: " + e.getErrorCode(), e); + } finally { + ps.release(); + } + return PowerReq.runePowers; + } + + /* + * Getters + */ + public PowersBase getPowersBase() { + if (this.powersBase == null) { + this.powersBase = PowersManager.getPowerByToken(this.token); + } + return this.powersBase; + } + + public short getLevel() { + return this.level; + } + + public ConcurrentHashMap getPowerReqs() { + return this.powerReqs; + } + + public ConcurrentHashMap getSkillReqs() { + return this.skillReqs; + } + + public int getToken() { + return this.token; + } + + private void addPower(int token, byte amount) { + this.powerReqs.put(token, amount); + } + + private void addSkill(int token, byte amount) { + this.skillReqs.put(token, amount); + } + + + /* + * Database + */ + + @Override + public int compareTo(PowerReq n) throws ClassCastException { + if (n.level == this.level) + return 0; + else if (this.level > n.level) + return 1; + else + return -1; + } + + @Override + public void updateDatabase() { + + } + + } \ No newline at end of file diff --git a/src/engine/objects/PowersBaseAttribute.java b/src/engine/objects/PowersBaseAttribute.java index 5a479a0b..fa6b5653 100644 --- a/src/engine/objects/PowersBaseAttribute.java +++ b/src/engine/objects/PowersBaseAttribute.java @@ -7,7 +7,7 @@ // www.magicbane.com - package engine.objects; +package engine.objects; import java.sql.ResultSet; import java.sql.SQLException; @@ -15,51 +15,51 @@ import java.sql.SQLException; public class PowersBaseAttribute extends AbstractGameObject { - private final short attributeID; - private final short modValue; - private final short castTime; - private final short duration; - private final short recycleTime; + private final short attributeID; + private final short modValue; + private final short castTime; + private final short duration; + private final short recycleTime; - /** - * ResultSet Constructor - */ - public PowersBaseAttribute(ResultSet rs) throws SQLException { - super(rs); + /** + * ResultSet Constructor + */ + public PowersBaseAttribute(ResultSet rs) throws SQLException { + super(rs); - this.attributeID = rs.getShort("attributeID"); - this.modValue = rs.getShort("modValue"); - this.castTime = rs.getShort("castTime"); - this.duration = rs.getShort("duration"); - this.recycleTime = rs.getShort("recycleTime"); - } + this.attributeID = rs.getShort("attributeID"); + this.modValue = rs.getShort("modValue"); + this.castTime = rs.getShort("castTime"); + this.duration = rs.getShort("duration"); + this.recycleTime = rs.getShort("recycleTime"); + } - /* - * Getters - */ - public short getAttributeID() { - return attributeID; - } + /* + * Getters + */ + public short getAttributeID() { + return attributeID; + } - public short getModValue() { - return modValue; - } + public short getModValue() { + return modValue; + } - public short getCastTime() { - return castTime; - } + public short getCastTime() { + return castTime; + } - public short getDuration() { - return duration; - } + public short getDuration() { + return duration; + } - public short getRecycleTime() { - return recycleTime; - } + public short getRecycleTime() { + return recycleTime; + } - @Override - public void updateDatabase() { - // TODO Create update logic. - } + @Override + public void updateDatabase() { + // TODO Create update logic. + } } diff --git a/src/engine/objects/PreparedStatementShared.java b/src/engine/objects/PreparedStatementShared.java index 436956fe..de3aae0c 100644 --- a/src/engine/objects/PreparedStatementShared.java +++ b/src/engine/objects/PreparedStatementShared.java @@ -32,1233 +32,1230 @@ import java.util.concurrent.ConcurrentHashMap; * All of the methods from the PreparedStatement interface simply check to see * that the PreparedStatement is active, and call the corresponding method on * that PreparedStatement. - * + * * @author Burfo * @see PreparedStatement - * **/ -public class PreparedStatementShared implements PreparedStatement { - private static final ConcurrentHashMap> statementList = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private static final ArrayList statementListDelegated = new ArrayList<>(); - private static final String ExceptionMessage = "PreparedStatementShared object " + "was accessed after being released."; - private static boolean debuggingIsOn; - - private PreparedStatement ps = null; - private int sqlHash; - private String sql; - private long delegatedTime; - - //debugging variables - private StackTraceElement[] stackTrace; - private DebugParam[] variables; - private String filteredSql; - - private class DebugParam { - private Object debugObject; - private boolean valueAssigned; - - public DebugParam(Object debugObject){ - this.debugObject = debugObject; - valueAssigned = true; - } - - public Object getDebugObject(){ - return debugObject; - } - - public boolean isValueAssigned(){ - return valueAssigned; - } - } - - @Override - public boolean isCloseOnCompletion() { - return true; - } - @Override - public void closeOnCompletion() { - Logger.warn( "Prepared Statement Closed"); - } - - /** - * Generates a new PreparedStatementShared based on the specified sql. - * - * @param sql - * Query string to generate the PreparedStatement - * @throws SQLException - **/ - public PreparedStatementShared(String sql) throws SQLException { - this.sqlHash = sql.hashCode(); - this.sql = sql; - this.delegatedTime = System.currentTimeMillis(); - this.ps = getFromPool(sql, sqlHash); - if (this.ps == null) { - this.ps = createNew(sql, sqlHash); - } - - - - if (debuggingIsOn) { - //see if there are any '?' in the statement that are not bind variables - //and filter them out. - boolean isString = false; - char[] sqlString = this.sql.toCharArray(); - for (int i = 0; i < sqlString.length; i++){ - if (sqlString[i] == '\'') - isString = !isString; - //substitute the ? with an unprintable character if is in a string - if (sqlString[i] == '?' && isString) - sqlString[i] = '\u0007'; - } - this.filteredSql = new String(sqlString); - - //find out how many variables are present in statement. - int count = 0; - int index = -1; - while ((index = filteredSql.indexOf('?',index+1)) != -1){ - count++; - } - - //create variables array with size equal to count of variables - this.variables = new DebugParam[count]; - - this.stackTrace = Thread.currentThread().getStackTrace(); - - } else { - this.stackTrace = null; - this.variables = null; - this.filteredSql = null; - } - - synchronized (statementListDelegated) { - statementListDelegated.add(this); - } +public class PreparedStatementShared implements PreparedStatement { + private static final ConcurrentHashMap> statementList = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private static final ArrayList statementListDelegated = new ArrayList<>(); + private static final String ExceptionMessage = "PreparedStatementShared object " + "was accessed after being released."; + private static boolean debuggingIsOn; + + private PreparedStatement ps = null; + private int sqlHash; + private String sql; + private long delegatedTime; + + //debugging variables + private StackTraceElement[] stackTrace; + private DebugParam[] variables; + private String filteredSql; - } - - private static PreparedStatement getFromPool(String sql, int sqlHash) throws SQLException { - PreparedStatement ps = null; - - if (statementList.containsKey(sqlHash)) { - LinkedList list = statementList.get(sqlHash); - if (list == null) { // Shouldn't happen b/c no keys are ever removed - throw new AssertionError("list cannot be null."); - } - boolean success = false; - synchronized (list) { - do { - ps = list.pollFirst(); - if (ps == null) { - break; - } - if (ps.isClosed()) { // should rarely happen - Logger.warn("A closed PreparedStatement was removed " - + "from AbstractGameObject statementList. " + "SQL: " + sql); - } else { - success = true; - } - } while (!success); - } - - if (ps != null) { - if (MBServerStatics.DB_DEBUGGING_ON_BY_DEFAULT) { - Logger.info("Found cached PreparedStatement for SQL hash: " + sqlHash - + " SQL String: " + sql); - } - } - } - return ps; - } - - private static PreparedStatement createNew(String sql, int sqlHash) throws SQLException { - statementList.putIfAbsent(sqlHash, new LinkedList<>()); - return DbManager.prepareStatement(sql); - } - - /** - * Releases the use of a PreparedStatementShared that was generated by - * {@link AbstractGameObject#prepareStatement}, making it available for use - * by another query. - *

- * Do not utilize or modify the object after calling this method. - *

- * Example: - * - *

-	 * @code
-	 * PreparedStatementShared ps = prepareStatement(...);
-	 * ps.executeUpdate();
-	 * ps.release();
-	 * ps = null;}
-	 * 
- **/ - public void release() { - if (this.ps == null) { - return; - } // nothing to release - if (statementListDelegated.contains(this)) { - synchronized (statementListDelegated) { - statementListDelegated.remove(this); - } - try { - if (this.ps.isClosed()) { - return; - } - this.ps.clearParameters(); - this.variables = null; - } catch (SQLException ignore) { - } - - // add back to pool - LinkedList list = statementList.get(this.sqlHash); - if (list == null) { - return; - } - synchronized (list) { - list.add(this.ps); - } - } - // clear values from this object so caller cannot use it after it has - // been released - this.ps = null; - this.sqlHash = 0; - this.sql = ""; - this.delegatedTime = 0; - this.stackTrace = null; - } - - /** - * Determines if the object is in a usable state. - * - * @return True if the object is in a useable state. - **/ - public boolean isUsable() { - if (ps == null) { - return false; - } - try { - if (ps.isClosed()) { - return false; - } - } catch (SQLException e) { - return false; - } - return true; - } + /** + * Generates a new PreparedStatementShared based on the specified sql. + * + * @param sql Query string to generate the PreparedStatement + * @throws SQLException + **/ + public PreparedStatementShared(String sql) throws SQLException { + this.sqlHash = sql.hashCode(); + this.sql = sql; + this.delegatedTime = System.currentTimeMillis(); + this.ps = getFromPool(sql, sqlHash); + if (this.ps == null) { + this.ps = createNew(sql, sqlHash); + } - private String getTraceInfo() { - if (stackTrace == null) { - return ""; - } - if (stackTrace.length > 3) { - return stackTrace[3].getClassName() + '.' + stackTrace[3].getMethodName(); - } else if (stackTrace.length == 0) { - return ""; - } else { - return stackTrace[stackTrace.length - 1].getClassName() + '.' + stackTrace[stackTrace.length - 1].getMethodName(); - } - } - - public static void submitPreparedStatementsCleaningJob() { - JobScheduler.getInstance().scheduleJob(new BasicScheduledJob("cleanUnreleasedStatements", PreparedStatementShared.class), 1000 * 60 * 2); // 2 - // minutes - } - - public static void cleanUnreleasedStatements() { - long now = System.currentTimeMillis(); - long timeLimit = 120000; // 2 minutes - - synchronized (statementListDelegated) { - Iterator iterator = statementListDelegated.iterator(); - while (iterator.hasNext()) { - PreparedStatementShared pss = iterator.next(); - if ((pss.delegatedTime + timeLimit) >= now) { - continue; - } - iterator.remove(); - - Logger.warn("Forcefully released after being held for > 2 minutes." + " SQL STRING: \"" - + pss.sql + "\" METHOD: " + pss.getTraceInfo()); - } - } + if (debuggingIsOn) { + //see if there are any '?' in the statement that are not bind variables + //and filter them out. + boolean isString = false; + char[] sqlString = this.sql.toCharArray(); + for (int i = 0; i < sqlString.length; i++) { + if (sqlString[i] == '\'') + isString = !isString; + //substitute the ? with an unprintable character if is in a string + if (sqlString[i] == '?' && isString) + sqlString[i] = '\u0007'; + } + this.filteredSql = new String(sqlString); + + //find out how many variables are present in statement. + int count = 0; + int index = -1; + while ((index = filteredSql.indexOf('?', index + 1)) != -1) { + count++; + } + + //create variables array with size equal to count of variables + this.variables = new DebugParam[count]; + + this.stackTrace = Thread.currentThread().getStackTrace(); + + } else { + this.stackTrace = null; + this.variables = null; + this.filteredSql = null; + } - submitPreparedStatementsCleaningJob(); // resubmit - } + synchronized (statementListDelegated) { + statementListDelegated.add(this); + } - @Override - public boolean equals(Object obj) { - if (ps == null || obj == null) { - return false; - } + } - if (obj instanceof PreparedStatementShared) { - return this.ps.equals(((PreparedStatementShared) obj).ps); - } + private static PreparedStatement getFromPool(String sql, int sqlHash) throws SQLException { + PreparedStatement ps = null; + + if (statementList.containsKey(sqlHash)) { + LinkedList list = statementList.get(sqlHash); + if (list == null) { // Shouldn't happen b/c no keys are ever removed + throw new AssertionError("list cannot be null."); + } + boolean success = false; + synchronized (list) { + do { + ps = list.pollFirst(); + if (ps == null) { + break; + } + if (ps.isClosed()) { // should rarely happen + Logger.warn("A closed PreparedStatement was removed " + + "from AbstractGameObject statementList. " + "SQL: " + sql); + } else { + success = true; + } + } while (!success); + } + + if (ps != null) { + if (MBServerStatics.DB_DEBUGGING_ON_BY_DEFAULT) { + Logger.info("Found cached PreparedStatement for SQL hash: " + sqlHash + + " SQL String: " + sql); + } + } + } + return ps; + } - if (obj instanceof PreparedStatement) { - return this.ps.equals(obj); - } + private static PreparedStatement createNew(String sql, int sqlHash) throws SQLException { + statementList.putIfAbsent(sqlHash, new LinkedList<>()); + return DbManager.prepareStatement(sql); + } - return false; - } - - @Override - public String toString(){ - if (!debuggingIsOn || variables == null) { - return "SQL: " + this.sql + " (enable DB debugging for more data)"; - } - - String out; - - out = "SQL: [" + this.sql + "] "; - out += "VARIABLES[count=" + variables.length + "]: "; - - for (int i=0; i iterator = statementListDelegated.iterator(); + while (iterator.hasNext()) { + PreparedStatementShared pss = iterator.next(); + if ((pss.delegatedTime + timeLimit) >= now) { + continue; + } + iterator.remove(); + + Logger.warn("Forcefully released after being held for > 2 minutes." + " SQL STRING: \"" + + pss.sql + "\" METHOD: " + pss.getTraceInfo()); + } + } - } + submitPreparedStatementsCleaningJob(); // resubmit + } - private void saveObject(int parameterIndex, Object obj) throws SQLException { - if (!debuggingIsOn || this.variables == null) { - return; - } - - if (parameterIndex > variables.length){ - throw new SQLException("Parameter index of " + parameterIndex + - " exceeds actual parameter count of " + this.variables.length); - } - - this.variables[parameterIndex-1] = new DebugParam(obj); - } - - private void logExceptionAndRethrow(SQLException e) throws SQLException { - Logger.error("SQL operation failed: (" + - e.getMessage() + ") " + this.toString(), e); - throw e; - } - - @Override - public void clearParameters() throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } + public static void enableDebugging() { + debuggingIsOn = true; + Logger.info("Database debugging has been enabled."); + } - this.ps.clearParameters(); - for (int i=0; i + * Do not utilize or modify the object after calling this method. + *

+ * Example: + * + *

+     * @code
+     * PreparedStatementShared ps = prepareStatement(...);
+     * ps.executeUpdate();
+     * ps.release();
+     * ps = null;}
+     * 
+ **/ + public void release() { + if (this.ps == null) { + return; + } // nothing to release + if (statementListDelegated.contains(this)) { + synchronized (statementListDelegated) { + statementListDelegated.remove(this); + } + try { + if (this.ps.isClosed()) { + return; + } + this.ps.clearParameters(); + this.variables = null; + } catch (SQLException ignore) { + } + + // add back to pool + LinkedList list = statementList.get(this.sqlHash); + if (list == null) { + return; + } + synchronized (list) { + list.add(this.ps); + } + } + // clear values from this object so caller cannot use it after it has + // been released + this.ps = null; + this.sqlHash = 0; + this.sql = ""; + this.delegatedTime = 0; + this.stackTrace = null; + } - @Override - public ResultSetMetaData getMetaData() throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - return this.ps.getMetaData(); - } + /** + * Determines if the object is in a usable state. + * + * @return True if the object is in a useable state. + **/ + public boolean isUsable() { + if (ps == null) { + return false; + } + try { + if (ps.isClosed()) { + return false; + } + } catch (SQLException e) { + return false; + } + return true; + } - @Override - public ParameterMetaData getParameterMetaData() throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - return this.ps.getParameterMetaData(); - } + private String getTraceInfo() { + if (stackTrace == null) { + return ""; + } - @Override - public void setArray(int parameterIndex, Array x) throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - this.saveObject(parameterIndex, x); - this.ps.setArray(parameterIndex, x); - } + if (stackTrace.length > 3) { + return stackTrace[3].getClassName() + '.' + stackTrace[3].getMethodName(); + } else if (stackTrace.length == 0) { + return ""; + } else { + return stackTrace[stackTrace.length - 1].getClassName() + '.' + stackTrace[stackTrace.length - 1].getMethodName(); + } + } - @Override - public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - saveObject(parameterIndex, (x==null?"NULL":"")); - this.ps.setAsciiStream(parameterIndex, x); - } + @Override + public boolean equals(Object obj) { + if (ps == null || obj == null) { + return false; + } - @Override - public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - saveObject(parameterIndex, (x==null?"NULL":"")); - this.ps.setBinaryStream(parameterIndex, x); - } + @Override + public String toString() { + if (!debuggingIsOn || variables == null) { + return "SQL: " + this.sql + " (enable DB debugging for more data)"; + } - @Override - public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - saveObject(parameterIndex, (x==null?"NULL":"")); - this.ps.setBlob(parameterIndex, x); - } + @Override + public void addBatch() throws SQLException { + if (this.ps == null) { + throw new SQLException(); + } + this.ps.addBatch(); - @Override - public void setBlob(int parameterIndex, InputStream x, long length) throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - saveObject(parameterIndex, (x==null?"NULL":"")); - this.ps.setCharacterStream(parameterIndex, reader); - } + private void logExceptionAndRethrow(SQLException e) throws SQLException { + Logger.error("SQL operation failed: (" + + e.getMessage() + ") " + this.toString(), e); + throw e; + } - @Override - public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - saveObject(parameterIndex, (reader==null?"NULL":"")); - this.ps.setClob(parameterIndex, reader); - } + @Override + public boolean execute() throws SQLException { + if (this.ps == null) { + throw new SQLException(ExceptionMessage); + } - @Override - public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - saveObject(parameterIndex, (reader==null?"NULL":"int value. - * The driver converts this - * to an SQL INTEGER value when it sends it to the database. - * - * @param parameterIndex the first parameter is 1, the second is 2, ... - * @param x the parameter value - * @param setZeroAsNull Converts an int value of 0 to an SQL NULL. - * Should be set TRUE on INSERTS and UPDATES for record pointers - * (e.g. GuildID) and FALSE for data elements (e.g. player's level). - * @exception SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed PreparedStatement - */ - public void setInt(int parameterIndex, int x, boolean setZeroAsNull) throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - if (setZeroAsNull && x == 0) { - this.ps.setNull(parameterIndex, java.sql.Types.INTEGER); - saveObject(parameterIndex,"NULL"); - return; - } - saveObject(parameterIndex,new Integer(x)); - this.ps.setInt(parameterIndex, x); - - } - - @Override - public void setInt(int parameterIndex, int x) throws SQLException { - setInt(parameterIndex, x, false); - } - - - @Override - public void setLong(int parameterIndex, long x) throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - saveObject(parameterIndex,new Long(x)); - this.ps.setLong(parameterIndex, x); - } + @Override + public int executeUpdate() throws SQLException { + if (this.ps == null) { + throw new SQLException(ExceptionMessage); + } - @Override - public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - saveObject(parameterIndex, (value==null?"NULL":"")); - this.ps.setNCharacterStream(parameterIndex, value); - } + if (debuggingIsOn || MBServerStatics.ENABLE_UPDATE_TIME_WARNING) { + long startTime = System.currentTimeMillis(); + int rs = 0; + try { + rs = this.ps.executeUpdate(); + } catch (SQLException e) { + logExceptionAndRethrow(e); + } + if ((startTime + MBServerStatics.DB_UPDATE_WARNING_TIME_MS) < System.currentTimeMillis()) + Logger.warn("The following update took " + (System.currentTimeMillis() - startTime) + + " millis to execute: " + this.sql); + return rs; + } - @Override - public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - saveObject(parameterIndex, (value==null?"NULL":"")); - this.ps.setNClob(parameterIndex, value); - } + @Override + public ResultSetMetaData getMetaData() throws SQLException { + if (this.ps == null) { + throw new SQLException(ExceptionMessage); + } + return this.ps.getMetaData(); + } - @Override - public void setNClob(int parameterIndex, Reader reader) throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - saveObject(parameterIndex, (reader==null?"NULL":"")); - this.ps.setNClob(parameterIndex, reader); - } + @Override + public ParameterMetaData getParameterMetaData() throws SQLException { + if (this.ps == null) { + throw new SQLException(ExceptionMessage); + } + return this.ps.getParameterMetaData(); + } - @Override - public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - saveObject(parameterIndex, (reader==null?"NULL":"")); + this.ps.setAsciiStream(parameterIndex, x); + } - @Override - public void setNull(int parameterIndex, int sqlType) throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - saveObject(parameterIndex, "NULL"); - this.ps.setNull(parameterIndex, sqlType); - } + @Override + public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { + if (this.ps == null) { + throw new SQLException(ExceptionMessage); + } + saveObject(parameterIndex, (x == null ? "NULL" : "")); + this.ps.setBinaryStream(parameterIndex, x); + } - @Override - public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - saveObject(parameterIndex, (x==null?"NULL":x.getClass().getName())); - this.ps.setObject(parameterIndex, x, targetSqlType, scaleOrLength); - } + @Override + public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { + if (this.ps == null) { + throw new SQLException(ExceptionMessage); + } + saveObject(parameterIndex, (x == null ? "NULL" : "")); + this.ps.setBlob(parameterIndex, x); + } - @Override - public void setShort(int parameterIndex, short x) throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - saveObject(parameterIndex, new Short(x)); - this.ps.setShort(parameterIndex, x); - } + @Override + public void setBlob(int parameterIndex, InputStream x, long length) throws SQLException { + if (this.ps == null) { + throw new SQLException(ExceptionMessage); + } + saveObject(parameterIndex, (x == null ? "NULL" : "")); + this.ps.setCharacterStream(parameterIndex, reader); + } - @Override - public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - saveObject(parameterIndex, x); - this.ps.setTimestamp(parameterIndex, x, cal); - } + @Override + public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { + if (this.ps == null) { + throw new SQLException(ExceptionMessage); + } + saveObject(parameterIndex, (reader == null ? "NULL" : "")); + this.ps.setClob(parameterIndex, reader); + } + + @Override + public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { + if (this.ps == null) { + throw new SQLException(ExceptionMessage); + } + saveObject(parameterIndex, (reader == null ? "NULL" : "")); + this.ps.setNCharacterStream(parameterIndex, value); + } + + @Override + public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { + if (this.ps == null) { + throw new SQLException(ExceptionMessage); + } + saveObject(parameterIndex, (value == null ? "NULL" : "")); + this.ps.setNClob(parameterIndex, value); + } + + @Override + public void setNClob(int parameterIndex, Reader reader) throws SQLException { + if (this.ps == null) { + throw new SQLException(ExceptionMessage); + } + saveObject(parameterIndex, (reader == null ? "NULL" : "")); + this.ps.setNClob(parameterIndex, reader); + } + + @Override + public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { + if (this.ps == null) { + throw new SQLException(ExceptionMessage); + } + saveObject(parameterIndex, (reader == null ? "NULL" : " iface) throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - return this.ps.isWrapperFor(iface); - } + @Override + public void setCursorName(String name) throws SQLException { + if (this.ps == null) { + throw new SQLException(ExceptionMessage); + } + this.ps.setCursorName(name); + } - @Override - public T unwrap(Class iface) throws SQLException { - if (this.ps == null) { - throw new SQLException(ExceptionMessage); - } - return this.ps.unwrap(iface); - } + @Override + public void setEscapeProcessing(boolean enable) throws SQLException { + if (this.ps == null) { + throw new SQLException(ExceptionMessage); + } + this.ps.setEscapeProcessing(enable); + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + if (this.ps == null) { + throw new SQLException(ExceptionMessage); + } + return this.ps.isWrapperFor(iface); + } + + @Override + public T unwrap(Class iface) throws SQLException { + if (this.ps == null) { + throw new SQLException(ExceptionMessage); + } + return this.ps.unwrap(iface); + } + + private class DebugParam { + private Object debugObject; + private boolean valueAssigned; + + public DebugParam(Object debugObject) { + this.debugObject = debugObject; + valueAssigned = true; + } + + public Object getDebugObject() { + return debugObject; + } + + public boolean isValueAssigned() { + return valueAssigned; + } + } } diff --git a/src/engine/objects/ProducedItem.java b/src/engine/objects/ProducedItem.java index 1284384d..3e3caafb 100644 --- a/src/engine/objects/ProducedItem.java +++ b/src/engine/objects/ProducedItem.java @@ -21,216 +21,213 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.Date; -public class ProducedItem { +public class ProducedItem { - private int ID; - private int npcUID; - private int itemBaseID; - private DateTime dateToUpgrade; - private boolean isRandom; + private int ID; + private int npcUID; + private int itemBaseID; + private DateTime dateToUpgrade; + private boolean isRandom; - private String prefix; - private String suffix; - private String name; - private int amount; - private int producedItemID = 0; - private boolean inForge; - private int value; - - private int playerID; + private String prefix; + private String suffix; + private String name; + private int amount; + private int producedItemID = 0; + private boolean inForge; + private int value; + private int playerID; - /** - * ResultSet Constructor - */ + /** + * ResultSet Constructor + */ - public ProducedItem(ResultSet rs) throws SQLException { - this.ID = rs.getInt("ID"); - this.npcUID = rs.getInt("npcUID"); + public ProducedItem(ResultSet rs) throws SQLException { + this.ID = rs.getInt("ID"); + this.npcUID = rs.getInt("npcUID"); this.itemBaseID = rs.getInt("itemBaseID"); Date sqlDateTime = rs.getTimestamp("dateToUpgrade"); - if (sqlDateTime != null) - this.dateToUpgrade = new DateTime(sqlDateTime); - else - dateToUpgrade = null; + if (sqlDateTime != null) + this.dateToUpgrade = new DateTime(sqlDateTime); + else + dateToUpgrade = null; this.isRandom = rs.getBoolean("isRandom"); this.prefix = rs.getString("prefix"); this.suffix = rs.getString("suffix"); this.name = rs.getString("name"); - this.inForge = rs.getBoolean("inForge"); - this.value = rs.getInt("value"); - this.playerID = rs.getInt("playerID"); - } - - public ProducedItem(int ID,int npcUID, int itemBaseID, DateTime dateToUpgrade, boolean isRandom, String prefix, String suffix, String name, int playerID) { - super(); - this.ID = ID; - this.npcUID = npcUID; + this.inForge = rs.getBoolean("inForge"); + this.value = rs.getInt("value"); + this.playerID = rs.getInt("playerID"); + } + + public ProducedItem(int ID, int npcUID, int itemBaseID, DateTime dateToUpgrade, boolean isRandom, String prefix, String suffix, String name, int playerID) { + super(); + this.ID = ID; + this.npcUID = npcUID; this.itemBaseID = itemBaseID; this.dateToUpgrade = dateToUpgrade; - this.isRandom = isRandom; - this.prefix = prefix; - this.suffix = suffix; - this.name = name; - this.value = 0; - this.playerID = playerID; + this.isRandom = isRandom; + this.prefix = prefix; + this.suffix = suffix; + this.name = name; + this.value = 0; + this.playerID = playerID; + } - } + public int getNpcUID() { + return npcUID; + } - public int getNpcUID() { - return npcUID; - } - public DateTime getDateToUpgrade() { - return dateToUpgrade; - } + public DateTime getDateToUpgrade() { + return dateToUpgrade; + } - public int getItemBaseID() { - return itemBaseID; - } + public int getItemBaseID() { + return itemBaseID; + } - public void setItemBaseID(int itemBaseID) { - this.itemBaseID = itemBaseID; - } + public void setItemBaseID(int itemBaseID) { + this.itemBaseID = itemBaseID; + } + + public boolean isRandom() { + return isRandom; + } + + public void setRandom(boolean isRandom) { + this.isRandom = isRandom; + } + + public String getPrefix() { + return prefix; + } + + public void setPrefix(String prefix) { + this.prefix = prefix; + } + + public String getSuffix() { + return suffix; + } + + public void setSuffix(String suffix) { + this.suffix = suffix; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getID() { + return ID; + } + + public void setID(int iD) { + ID = iD; + } + + public int getAmount() { + return amount; + } + + public void setAmount(int amount) { + this.amount = amount; + } + + + public int getProducedItemID() { + return producedItemID; + } + + public void setProducedItemID(int producedItemID) { + this.producedItemID = producedItemID; + } + + public boolean isInForge() { + return inForge; + } + + public void setInForge(boolean inForge) { + this.inForge = inForge; + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } + + public boolean finishProduction() { + NPC npc = NPC.getFromCache(this.getNpcUID()); + + if (npc == null) + return false; + + + //update the client to ID the item in the window when item finishes rolling. + //If there is more than 1 item left to roll, complete the item and throw it in inventory + //and reproduce next item. + + try { + + if (this.getAmount() > 1) { + this.setAmount(this.getAmount() - 1); + npc.completeItem(this.getProducedItemID()); + + int pToken = 0; + int sToken = 0; + + if (!this.isRandom()) { + EffectsBase eb = PowersManager.getEffectByIDString(this.getPrefix()); + if (eb != null) + pToken = eb.getToken(); + eb = PowersManager.getEffectByIDString(this.getSuffix()); + if (eb != null) + sToken = eb.getToken(); + + } + + Item item = npc.produceItem(0, this.getAmount(), this.isRandom(), pToken, sToken, this.getName(), this.getItemBaseID()); + + if (item == null) + return false; + + } else { + + //update item to complete + MobLoot targetItem = MobLoot.getFromCache(this.getProducedItemID()); + + if (targetItem == null) + return false; + + ItemProductionMsg outMsg = new ItemProductionMsg(npc.getBuilding(), npc, targetItem, 8, true); - public boolean isRandom() { - return isRandom; - } - public void setRandom(boolean isRandom) { - this.isRandom = isRandom; - } + DispatchMessage.dispatchMsgToInterestArea(npc, outMsg, DispatchChannel.SECONDARY, 700, false, false); + } - public String getPrefix() { - return prefix; - } + } catch (Exception e) { + Logger.error(e); + return false; + } + return true; + } - public void setPrefix(String prefix) { - this.prefix = prefix; - } - - public String getSuffix() { - return suffix; - } - - public void setSuffix(String suffix) { - this.suffix = suffix; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getID() { - return ID; - } - - public void setID(int iD) { - ID = iD; - } - - public int getAmount() { - return amount; - } - - public void setAmount(int amount) { - this.amount = amount; - } - - - public int getProducedItemID() { - return producedItemID; - } - - public void setProducedItemID(int producedItemID) { - this.producedItemID = producedItemID; - } - - public boolean isInForge() { - return inForge; - } - - public void setInForge(boolean inForge) { - this.inForge = inForge; - } - - public int getValue() { - return value; - } - - public void setValue(int value) { - this.value = value; - } - - public boolean finishProduction(){ - NPC npc = NPC.getFromCache(this.getNpcUID()); - - if (npc == null) - return false; - - - //update the client to ID the item in the window when item finishes rolling. - //If there is more than 1 item left to roll, complete the item and throw it in inventory - //and reproduce next item. - - try{ - - if(this.getAmount() > 1){ - this.setAmount(this.getAmount() - 1); - npc.completeItem(this.getProducedItemID()); - - int pToken = 0; - int sToken = 0; - - if (!this.isRandom()){ - EffectsBase eb = PowersManager.getEffectByIDString(this.getPrefix()); - if (eb != null) - pToken = eb.getToken(); - eb = PowersManager.getEffectByIDString(this.getSuffix()); - if (eb != null) - sToken = eb.getToken(); - - } - - Item item = npc.produceItem(0,this.getAmount(),this.isRandom(),pToken,sToken,this.getName(),this.getItemBaseID()); - - if (item == null) - return false; - - }else{ - - //update item to complete - MobLoot targetItem = MobLoot.getFromCache(this.getProducedItemID()); - - if (targetItem == null) - return false; - - ItemProductionMsg outMsg = new ItemProductionMsg(npc.getBuilding(), npc, targetItem, 8, true); - - - - DispatchMessage.dispatchMsgToInterestArea(npc, outMsg, DispatchChannel.SECONDARY, 700, false, false); - } - - }catch(Exception e){ - Logger.error(e); - return false; - } - return true; - } - - public int getPlayerID() { - return playerID; - } - + public int getPlayerID() { + return playerID; + } } diff --git a/src/engine/objects/PromotionClass.java b/src/engine/objects/PromotionClass.java index dcccda72..08e476f3 100644 --- a/src/engine/objects/PromotionClass.java +++ b/src/engine/objects/PromotionClass.java @@ -20,184 +20,182 @@ import java.util.ArrayList; public class PromotionClass extends AbstractGameObject { - private final String name; - private final String description; - private int token = 0; - - private final float healthMod; - private final float manaMod; - private final float staminaMod; - - private final ArrayList allowedRunes; - private final ArrayList skillsGranted; - private final ArrayList powersGranted; - private final ArrayList effectsGranted; - private final ArrayList effectsGrantedFighter; - private final ArrayList effectsGrantedHealer; - private final ArrayList effectsGrantedRogue; - private final ArrayList effectsGrantedMage; - private ArrayList effectsList = new ArrayList<>(); - - /** - * No Table ID Constructor - */ - public PromotionClass(String name, String description, - ArrayList allowedRunes, ArrayList skillsGranted, ArrayList powersGranted) { - super(); - this.name = name; - this.description = description; - this.allowedRunes = allowedRunes; - this.skillsGranted = skillsGranted; - this.powersGranted = powersGranted; - this.healthMod = 0f; - this.manaMod = 0f; - this.staminaMod = 0f; - this.effectsGranted = new ArrayList<>(); - this.effectsGrantedFighter = new ArrayList<>(); - this.effectsGrantedHealer = new ArrayList<>(); - this.effectsGrantedRogue = new ArrayList<>(); - this.effectsGrantedMage = new ArrayList<>(); - } - - /** - * Normal Constructor - */ - public PromotionClass(String name, String description, - ArrayList allowedRunes, ArrayList skillsGranted, ArrayList powersGranted, int newUUID) { - super(newUUID); - this.name = name; - this.description = description; - this.allowedRunes = allowedRunes; - this.skillsGranted = skillsGranted; - this.powersGranted = powersGranted; - this.healthMod = 0f; - this.manaMod = 0f; - this.staminaMod = 0f; - this.effectsGranted = new ArrayList<>(); - this.effectsGrantedFighter = new ArrayList<>(); - this.effectsGrantedHealer = new ArrayList<>(); - this.effectsGrantedRogue = new ArrayList<>(); - this.effectsGrantedMage = new ArrayList<>(); - } - - /** - * ResultSet Constructor - */ - public PromotionClass(ResultSet rs) throws SQLException { - super(rs); - - this.name = rs.getString("name"); - this.description = rs.getString("description"); - this.token = rs.getInt("token"); - this.healthMod = rs.getFloat("healthMod"); - this.manaMod = rs.getFloat("manaMod"); - this.staminaMod = rs.getFloat("staminaMod"); - this.allowedRunes = DbManager.PromotionQueries.GET_ALLOWED_RUNES(this); - this.skillsGranted = DbManager.SkillReqQueries.GET_REQS_FOR_RUNE(this.getObjectUUID()); - this.powersGranted = PowerReq.getPowerReqsForRune(this.getObjectUUID()); - this.effectsGranted = DbManager.RuneBaseEffectQueries.GET_EFFECTS_FOR_RUNEBASE(this.getObjectUUID()); - this.effectsGrantedFighter = DbManager.RuneBaseEffectQueries.GET_EFFECTS_FOR_RUNEBASE((this.getObjectUUID() * 10) + 2500); - this.effectsGrantedHealer = DbManager.RuneBaseEffectQueries.GET_EFFECTS_FOR_RUNEBASE((this.getObjectUUID() * 10) + 2501); - this.effectsGrantedRogue = DbManager.RuneBaseEffectQueries.GET_EFFECTS_FOR_RUNEBASE((this.getObjectUUID() * 10) + 2502); - this.effectsGrantedMage = DbManager.RuneBaseEffectQueries.GET_EFFECTS_FOR_RUNEBASE((this.getObjectUUID() * 10) + 2503); - this.effectsList = DbManager.MobBaseQueries.GET_RUNEBASE_EFFECTS(this.getObjectUUID()); - - - } - - /* - * Getters - */ - public String getName() { - return name; - } - - public String getDescription() { - return description; - } - - public int getToken() { - return this.token; - } - - public float getHealthMod() { - return this.healthMod; - } - - public float getManaMod() { - return this.manaMod; - } - - public float getStaminaMod() { - return this.staminaMod; - } - - public boolean isAllowedRune(int token) { - for (int b : this.allowedRunes) { - if (token == b) { - return true; - } - } - return false; - } - - public ArrayList getRuneList() { - return this.allowedRunes; - } - - public ArrayList getSkillsGranted() { - return this.skillsGranted; - } - - public ArrayList getPowersGranted() { - return this.powersGranted; - } - - public ArrayList getEffectsGranted() { - return this.effectsGranted; - } - - public ArrayList getEffectsGranted(int baseClassID) { - if (baseClassID == 2500) - return this.effectsGrantedFighter; - else if (baseClassID == 2501) - return this.effectsGrantedHealer; - else if (baseClassID == 2502) - return this.effectsGrantedRogue; - else if (baseClassID == 2503) - return this.effectsGrantedMage; - else - return new ArrayList<>(); - } - - /* - * Serializing - */ - - public static void serializeForClientMsg(PromotionClass promotionClass, ByteBufferWriter writer) { - writer.putInt(3); // For BaseClass - writer.putInt(0); // Pad - writer.putInt(promotionClass.getObjectUUID()); - writer.putInt(promotionClass.getObjectType().ordinal()); - writer.putInt(promotionClass.getObjectUUID()); - } - - @Override - public void updateDatabase() { - // TODO Create update logic. - } - - public static PromotionClass GetPromtionClassFromCache(int runeID){ - if (runeID == 0) - return null; - return (PromotionClass) DbManager.getFromCache(GameObjectType.PromotionClass, runeID); - } - - public ArrayList getEffectsList() { - return effectsList; - } - - public void setEffectsList(ArrayList effectsList) { - this.effectsList = effectsList; - } + private final String name; + private final String description; + private final float healthMod; + private final float manaMod; + private final float staminaMod; + private final ArrayList allowedRunes; + private final ArrayList skillsGranted; + private final ArrayList powersGranted; + private final ArrayList effectsGranted; + private final ArrayList effectsGrantedFighter; + private final ArrayList effectsGrantedHealer; + private final ArrayList effectsGrantedRogue; + private final ArrayList effectsGrantedMage; + private int token = 0; + private ArrayList effectsList = new ArrayList<>(); + + /** + * No Table ID Constructor + */ + public PromotionClass(String name, String description, + ArrayList allowedRunes, ArrayList skillsGranted, ArrayList powersGranted) { + super(); + this.name = name; + this.description = description; + this.allowedRunes = allowedRunes; + this.skillsGranted = skillsGranted; + this.powersGranted = powersGranted; + this.healthMod = 0f; + this.manaMod = 0f; + this.staminaMod = 0f; + this.effectsGranted = new ArrayList<>(); + this.effectsGrantedFighter = new ArrayList<>(); + this.effectsGrantedHealer = new ArrayList<>(); + this.effectsGrantedRogue = new ArrayList<>(); + this.effectsGrantedMage = new ArrayList<>(); + } + + /** + * Normal Constructor + */ + public PromotionClass(String name, String description, + ArrayList allowedRunes, ArrayList skillsGranted, ArrayList powersGranted, int newUUID) { + super(newUUID); + this.name = name; + this.description = description; + this.allowedRunes = allowedRunes; + this.skillsGranted = skillsGranted; + this.powersGranted = powersGranted; + this.healthMod = 0f; + this.manaMod = 0f; + this.staminaMod = 0f; + this.effectsGranted = new ArrayList<>(); + this.effectsGrantedFighter = new ArrayList<>(); + this.effectsGrantedHealer = new ArrayList<>(); + this.effectsGrantedRogue = new ArrayList<>(); + this.effectsGrantedMage = new ArrayList<>(); + } + + /** + * ResultSet Constructor + */ + public PromotionClass(ResultSet rs) throws SQLException { + super(rs); + + this.name = rs.getString("name"); + this.description = rs.getString("description"); + this.token = rs.getInt("token"); + this.healthMod = rs.getFloat("healthMod"); + this.manaMod = rs.getFloat("manaMod"); + this.staminaMod = rs.getFloat("staminaMod"); + this.allowedRunes = DbManager.PromotionQueries.GET_ALLOWED_RUNES(this); + this.skillsGranted = DbManager.SkillReqQueries.GET_REQS_FOR_RUNE(this.getObjectUUID()); + this.powersGranted = PowerReq.getPowerReqsForRune(this.getObjectUUID()); + this.effectsGranted = DbManager.RuneBaseEffectQueries.GET_EFFECTS_FOR_RUNEBASE(this.getObjectUUID()); + this.effectsGrantedFighter = DbManager.RuneBaseEffectQueries.GET_EFFECTS_FOR_RUNEBASE((this.getObjectUUID() * 10) + 2500); + this.effectsGrantedHealer = DbManager.RuneBaseEffectQueries.GET_EFFECTS_FOR_RUNEBASE((this.getObjectUUID() * 10) + 2501); + this.effectsGrantedRogue = DbManager.RuneBaseEffectQueries.GET_EFFECTS_FOR_RUNEBASE((this.getObjectUUID() * 10) + 2502); + this.effectsGrantedMage = DbManager.RuneBaseEffectQueries.GET_EFFECTS_FOR_RUNEBASE((this.getObjectUUID() * 10) + 2503); + this.effectsList = DbManager.MobBaseQueries.GET_RUNEBASE_EFFECTS(this.getObjectUUID()); + + + } + + public static void serializeForClientMsg(PromotionClass promotionClass, ByteBufferWriter writer) { + writer.putInt(3); // For BaseClass + writer.putInt(0); // Pad + writer.putInt(promotionClass.getObjectUUID()); + writer.putInt(promotionClass.getObjectType().ordinal()); + writer.putInt(promotionClass.getObjectUUID()); + } + + public static PromotionClass GetPromtionClassFromCache(int runeID) { + if (runeID == 0) + return null; + return (PromotionClass) DbManager.getFromCache(GameObjectType.PromotionClass, runeID); + } + + /* + * Getters + */ + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public int getToken() { + return this.token; + } + + public float getHealthMod() { + return this.healthMod; + } + + public float getManaMod() { + return this.manaMod; + } + + public float getStaminaMod() { + return this.staminaMod; + } + + public boolean isAllowedRune(int token) { + for (int b : this.allowedRunes) { + if (token == b) { + return true; + } + } + return false; + } + + public ArrayList getRuneList() { + return this.allowedRunes; + } + + public ArrayList getSkillsGranted() { + return this.skillsGranted; + } + + public ArrayList getPowersGranted() { + return this.powersGranted; + } + + /* + * Serializing + */ + + public ArrayList getEffectsGranted() { + return this.effectsGranted; + } + + public ArrayList getEffectsGranted(int baseClassID) { + if (baseClassID == 2500) + return this.effectsGrantedFighter; + else if (baseClassID == 2501) + return this.effectsGrantedHealer; + else if (baseClassID == 2502) + return this.effectsGrantedRogue; + else if (baseClassID == 2503) + return this.effectsGrantedMage; + else + return new ArrayList<>(); + } + + @Override + public void updateDatabase() { + // TODO Create update logic. + } + + public ArrayList getEffectsList() { + return effectsList; + } + + public void setEffectsList(ArrayList effectsList) { + this.effectsList = effectsList; + } } diff --git a/src/engine/objects/Race.java b/src/engine/objects/Race.java index 28a3467f..93ef9426 100644 --- a/src/engine/objects/Race.java +++ b/src/engine/objects/Race.java @@ -23,346 +23,332 @@ import java.util.concurrent.ConcurrentHashMap; public class Race { - // Local class cache - - private static ConcurrentHashMap _raceByID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - - private final String name; - private final String description; - private final int raceRuneID; - private Enum.RaceType raceType; - private final short strStart; - private final short strMin; - private final short strMax; - - private final short dexStart; - private final short dexMin; - private final short dexMax; - - private final short conStart; - private final short conMin; - private final short conMax; - - private final short intStart; - private final short intMin; - private final short intMax; - - private final short spiStart; - private final short spiMin; - private final short spiMax; - - private final short healthBonus; - private final short manaBonus; - private final short staminaBonus; - - private final byte startingPoints; - - private final float minHeight; - private final float strHeightMod; - - private int token = 0; - - private HashSet hairStyles; - private HashSet beardStyles; - - private final HashSet skinColors; - private final HashSet beardColors; - private final HashSet hairColors; - - private final ArrayList baseClasses; - private ArrayList effectsList = new ArrayList<>(); - - - private final ArrayList skillsGranted; - private final ArrayList powersGranted; - - public static void loadAllRaces() { - Race._raceByID = DbManager.RaceQueries.LOAD_ALL_RACES(); - } - - - @Override - public boolean equals(Object object) { - - if ((object instanceof Race) == false) - return false; - - Race race = (Race) object; - - return this.raceRuneID == race.raceRuneID; - } - - @Override - public int hashCode() { - return this.raceRuneID; - } - - /** - * ResultSet Constructor - */ - public Race(ResultSet rs) throws SQLException { - - this.raceRuneID = rs.getInt("ID"); - this.raceType = Enum.RaceType.getRaceTypebyRuneID(raceRuneID); - this.name = rs.getString("name"); - this.description = rs.getString("description"); - this.strStart = rs.getShort("strStart"); - this.strMin = rs.getShort("strMin"); - this.strMax = rs.getShort("strMax"); - this.dexStart = rs.getShort("dexStart"); - this.dexMin = rs.getShort("dexMin"); - this.dexMax = rs.getShort("dexMax"); - this.conStart = rs.getShort("conStart"); - this.conMin = rs.getShort("conMin"); - this.conMax = rs.getShort("conMax"); - this.intStart = rs.getShort("intStart"); - this.intMin = rs.getShort("intMin"); - this.intMax = rs.getShort("intMax"); - this.spiStart = rs.getShort("spiStart"); - this.spiMin = rs.getShort("spiMin"); - this.spiMax = rs.getShort("spiMax"); - this.token = rs.getInt("token"); - this.healthBonus = rs.getShort("healthBonus"); - this.manaBonus = rs.getShort("manaBonus"); - this.staminaBonus = rs.getShort("staminaBonus"); - this.startingPoints = rs.getByte("startingPoints"); - this.raceType = RaceType.getRaceTypebyRuneID(this.raceRuneID); - this.minHeight = rs.getFloat("minHeight"); - this.strHeightMod = rs.getFloat("strHeightMod"); - this.hairStyles = DbManager.RaceQueries.HAIR_STYLES_FOR_RACE(raceRuneID); - this.beardStyles = DbManager.RaceQueries.BEARD_STYLES_FOR_RACE(raceRuneID); - this.skinColors = DbManager.RaceQueries.SKIN_COLOR_FOR_RACE(raceRuneID); - this.beardColors = DbManager.RaceQueries.BEARD_COLORS_FOR_RACE(raceRuneID); - this.hairColors = DbManager.RaceQueries.HAIR_COLORS_FOR_RACE(raceRuneID); - this.baseClasses = DbManager.BaseClassQueries.GET_BASECLASS_FOR_RACE(raceRuneID); - this.skillsGranted = DbManager.SkillReqQueries.GET_REQS_FOR_RUNE(raceRuneID); - this.powersGranted = PowerReq.getPowerReqsForRune(raceRuneID); - this.effectsList = DbManager.MobBaseQueries.GET_RUNEBASE_EFFECTS(this.raceRuneID); - - } - - /* - * Getters - */ - public String getName() { - return name; - } - - public String getDescription() { - return description; - } - - public short getStrStart() { - return strStart; - } - - public short getStrMin() { - return strMin; - } - - public short getStrMax() { - return strMax; - } - - public short getDexStart() { - return dexStart; - } - - public short getDexMin() { - return dexMin; - } - - public short getDexMax() { - return dexMax; - } - - public short getConStart() { - return conStart; - } - - public short getConMin() { - return conMin; - } - - public short getConMax() { - return conMax; - } - - public short getIntStart() { - return intStart; - } - - public short getIntMin() { - return intMin; - } - - public short getIntMax() { - return intMax; - } - - public short getSpiStart() { - return spiStart; - } - - public short getSpiMin() { - return spiMin; - } - - public short getSpiMax() { - return spiMax; - } - - public byte getStartingPoints() { - return startingPoints; - } - - public int getToken() { - return token; - } - - public final HashSet getHairStyles() { - return hairStyles; - } - - public final HashSet getBeardStyles() { - return beardStyles; - } - - public final HashSet getBeardColors() { - return beardColors; - } - - public HashSet getHairColors() { - return hairColors; - } + // Local class cache + + private static ConcurrentHashMap _raceByID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + + private final String name; + private final String description; + private final int raceRuneID; + private final short strStart; + private final short strMin; + private final short strMax; + private final short dexStart; + private final short dexMin; + private final short dexMax; + private final short conStart; + private final short conMin; + private final short conMax; + private final short intStart; + private final short intMin; + private final short intMax; + private final short spiStart; + private final short spiMin; + private final short spiMax; + private final short healthBonus; + private final short manaBonus; + private final short staminaBonus; + private final byte startingPoints; + private final float minHeight; + private final float strHeightMod; + private final HashSet skinColors; + private final HashSet beardColors; + private final HashSet hairColors; + private final ArrayList baseClasses; + private final ArrayList skillsGranted; + private final ArrayList powersGranted; + private Enum.RaceType raceType; + private int token = 0; + private HashSet hairStyles; + private HashSet beardStyles; + private ArrayList effectsList = new ArrayList<>(); + + /** + * ResultSet Constructor + */ + public Race(ResultSet rs) throws SQLException { + + this.raceRuneID = rs.getInt("ID"); + this.raceType = Enum.RaceType.getRaceTypebyRuneID(raceRuneID); + this.name = rs.getString("name"); + this.description = rs.getString("description"); + this.strStart = rs.getShort("strStart"); + this.strMin = rs.getShort("strMin"); + this.strMax = rs.getShort("strMax"); + this.dexStart = rs.getShort("dexStart"); + this.dexMin = rs.getShort("dexMin"); + this.dexMax = rs.getShort("dexMax"); + this.conStart = rs.getShort("conStart"); + this.conMin = rs.getShort("conMin"); + this.conMax = rs.getShort("conMax"); + this.intStart = rs.getShort("intStart"); + this.intMin = rs.getShort("intMin"); + this.intMax = rs.getShort("intMax"); + this.spiStart = rs.getShort("spiStart"); + this.spiMin = rs.getShort("spiMin"); + this.spiMax = rs.getShort("spiMax"); + this.token = rs.getInt("token"); + this.healthBonus = rs.getShort("healthBonus"); + this.manaBonus = rs.getShort("manaBonus"); + this.staminaBonus = rs.getShort("staminaBonus"); + this.startingPoints = rs.getByte("startingPoints"); + this.raceType = RaceType.getRaceTypebyRuneID(this.raceRuneID); + this.minHeight = rs.getFloat("minHeight"); + this.strHeightMod = rs.getFloat("strHeightMod"); + this.hairStyles = DbManager.RaceQueries.HAIR_STYLES_FOR_RACE(raceRuneID); + this.beardStyles = DbManager.RaceQueries.BEARD_STYLES_FOR_RACE(raceRuneID); + this.skinColors = DbManager.RaceQueries.SKIN_COLOR_FOR_RACE(raceRuneID); + this.beardColors = DbManager.RaceQueries.BEARD_COLORS_FOR_RACE(raceRuneID); + this.hairColors = DbManager.RaceQueries.HAIR_COLORS_FOR_RACE(raceRuneID); + this.baseClasses = DbManager.BaseClassQueries.GET_BASECLASS_FOR_RACE(raceRuneID); + this.skillsGranted = DbManager.SkillReqQueries.GET_REQS_FOR_RUNE(raceRuneID); + this.powersGranted = PowerReq.getPowerReqsForRune(raceRuneID); + this.effectsList = DbManager.MobBaseQueries.GET_RUNEBASE_EFFECTS(this.raceRuneID); + + } + + public static void loadAllRaces() { + Race._raceByID = DbManager.RaceQueries.LOAD_ALL_RACES(); + } + + public static Race getRace(int id) { + return _raceByID.get(id); + } + + @Override + public boolean equals(Object object) { + + if ((object instanceof Race) == false) + return false; + + Race race = (Race) object; + + return this.raceRuneID == race.raceRuneID; + } + + @Override + public int hashCode() { + return this.raceRuneID; + } + + /* + * Getters + */ + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public short getStrStart() { + return strStart; + } + + public short getStrMin() { + return strMin; + } + + public short getStrMax() { + return strMax; + } + + public short getDexStart() { + return dexStart; + } + + public short getDexMin() { + return dexMin; + } + + public short getDexMax() { + return dexMax; + } + + public short getConStart() { + return conStart; + } + + public short getConMin() { + return conMin; + } + + public short getConMax() { + return conMax; + } + + public short getIntStart() { + return intStart; + } + + public short getIntMin() { + return intMin; + } + + public short getIntMax() { + return intMax; + } + + public short getSpiStart() { + return spiStart; + } + + public short getSpiMin() { + return spiMin; + } - public HashSet getSkinColors() { - return skinColors; - } + public short getSpiMax() { + return spiMax; + } - public int getNumSkinColors() { - return this.skinColors.size(); - } + public byte getStartingPoints() { + return startingPoints; + } - public int getNumHairColors() { - return this.hairColors.size(); - } + public int getToken() { + return token; + } - public int getNumBeardColors() { - return this.beardColors.size(); - } + public final HashSet getHairStyles() { + return hairStyles; + } - public final ArrayList getValidBaseClasses() { - return baseClasses; - } + public final HashSet getBeardStyles() { + return beardStyles; + } - public ArrayList getAllowedRunes() { + public final HashSet getBeardColors() { + return beardColors; + } + + public HashSet getHairColors() { + return hairColors; + } + + public HashSet getSkinColors() { + return skinColors; + } + + public int getNumSkinColors() { + return this.skinColors.size(); + } + + public int getNumHairColors() { + return this.hairColors.size(); + } + + public int getNumBeardColors() { + return this.beardColors.size(); + } + + public final ArrayList getValidBaseClasses() { + return baseClasses; + } + + public ArrayList getAllowedRunes() { return RuneBase.AllowedRaceRunesMap.get(raceRuneID); - } - - public ArrayList getSkillsGranted() { - return this.skillsGranted; - } + } + + public ArrayList getSkillsGranted() { + return this.skillsGranted; + } + + public ArrayList getPowersGranted() { + return this.powersGranted; + } - public ArrayList getPowersGranted() { - return this.powersGranted; - } + public ArrayList getEffectsGranted() { + return RuneBaseEffect.RuneIDBaseEffectMap.get(this.raceRuneID); + } - public ArrayList getEffectsGranted() { - return RuneBaseEffect.RuneIDBaseEffectMap.get(this.raceRuneID); - } + /* + * Validators + */ + public boolean isValidBeardStyle(int id) { + return this.beardStyles.contains(id); + } - /* - * Validators - */ - public boolean isValidBeardStyle(int id) { - return this.beardStyles.contains(id); - } + public boolean isValidBeardColor(int id) { + return this.beardColors.contains(id); + } - public boolean isValidBeardColor(int id) { - return this.beardColors.contains(id); - } + public boolean isValidHairStyle(int id) { + return this.hairStyles.contains(id); + } - public boolean isValidHairStyle(int id) { - return this.hairStyles.contains(id); - } + public boolean isValidHairColor(int id) { + return this.hairColors.contains(id); + } - public boolean isValidHairColor(int id) { - return this.hairColors.contains(id); - } + public boolean isValidSkinColor(int id) { + return this.skinColors.contains(id); + } - public boolean isValidSkinColor(int id) { - return this.skinColors.contains(id); - } + public boolean isAllowedRune(RuneBase rb) { - public boolean isAllowedRune(RuneBase rb) { + if (this.getAllowedRunes() != null) + if (this.getAllowedRunes().contains(rb.getObjectUUID())) + return true; + if (RuneBase.AllowedBaseClassRunesMap.containsKey(111111)) { + if (RuneBase.AllowedRaceRunesMap.get(111111).contains(rb.getObjectUUID())) + return true; + } + return false; + } - if (this.getAllowedRunes() != null) - if (this.getAllowedRunes().contains(rb.getObjectUUID())) - return true; - if (RuneBase.AllowedBaseClassRunesMap.containsKey(111111)){ - if (RuneBase.AllowedRaceRunesMap.get(111111).contains(rb.getObjectUUID())) - return true; - } - return false; - } + public float getHealthBonus() { + return this.healthBonus; + } - public float getHealthBonus() { - return this.healthBonus; - } + public float getManaBonus() { + return this.manaBonus; + } - public float getManaBonus() { - return this.manaBonus; - } + public float getStaminaBonus() { + return this.staminaBonus; + } - public float getStaminaBonus() { - return this.staminaBonus; - } + public float getMinHeight() { + return this.minHeight; + } - public float getMinHeight() { - return this.minHeight; - } + public float getStrHeightMod() { + return this.strHeightMod; + } - public float getStrHeightMod() { - return this.strHeightMod; - } + public float getHeight(short str) { + return this.minHeight + (this.strHeightMod * str); + } - public float getHeight(short str) { - return this.minHeight + (this.strHeightMod * str); - } - public float getCenterHeight(short str) { - return getHeight(str) / 2f; - } + /* + * Serializing + */ + public float getCenterHeight(short str) { + return getHeight(str) / 2f; + } - /* - * Serializing - */ + public void serializeForClientMsg(ByteBufferWriter writer) { + writer.putInt(1); // For Race + writer.putInt(0); // Pad + writer.putInt(this.raceRuneID); - public void serializeForClientMsg(ByteBufferWriter writer) { - writer.putInt(1); // For Race - writer.putInt(0); // Pad - writer.putInt(this.raceRuneID); + writer.putInt(Enum.GameObjectType.Race.ordinal()); + writer.putInt(raceRuneID); + } - writer.putInt(Enum.GameObjectType.Race.ordinal()); - writer.putInt(raceRuneID); - } + public int getRaceRuneID() { + return raceRuneID; + } - public static Race getRace(int id) { - return _raceByID.get(id); - } + public Enum.RaceType getRaceType() { + return raceType; + } - public int getRaceRuneID() { - return raceRuneID; - } - public Enum.RaceType getRaceType() { - return raceType; - } - - - public ArrayList getEffectsList() { - return effectsList; - } + public ArrayList getEffectsList() { + return effectsList; + } } diff --git a/src/engine/objects/Realm.java b/src/engine/objects/Realm.java index 7f00fcd9..e97a4533 100644 --- a/src/engine/objects/Realm.java +++ b/src/engine/objects/Realm.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.objects; import engine.Enum; @@ -34,399 +33,398 @@ import static engine.Enum.CharterType; public class Realm { - // Internal class cache - - public static ConcurrentHashMap _realms = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - - public Color mapColor; - private final float mapR; //Red color - private final float mapG; //Green color - private final float mapB; //Blue color - private final float mapA; //Alpha color - private final boolean canBeClaimed; - private final boolean canPlaceCities; - private final int numCities; - private final String realmName; - private int rulingCityUUID; - private int rulingCharacterUUID; - private int rulingCharacterOrdinal; - private String rulingCharacterName; - private int rulingNationUUID; - private GuildTag rulingNationTags; - private String rulingNationName; - private int charterType; - public LocalDateTime ruledSince; - private final float mapY1; - private final float mapX1; - private final float mapY2; - private final float mapX2; - private final int stretchX; - private final int stretchY; - private final int locX; - private final int locY; - public final int realmID; - private final HashSet cities = new HashSet<>(); - private String hash; - - /** - * ResultSet Constructor - */ - public Realm(ResultSet rs) throws SQLException { - - this.mapColor = new Color(Integer.parseInt(rs.getString("realmColor"), 16)); - this.mapR = (float) (mapColor.getRed() * 0.00392156863); - this.mapG = (float) (mapColor.getGreen() * 0.00392156863); - this.mapB = (float) (mapColor.getBlue() * 0.00392156863); - this.mapA = 1; - this.canBeClaimed = rs.getBoolean("canBeClaimed"); - this.canPlaceCities = rs.getBoolean("canPlaceCities"); - this.numCities = rs.getInt("numCities"); - this.realmName = rs.getString("realmName"); - this.rulingCityUUID = rs.getInt("rulingCityUID"); - this.charterType = rs.getInt("charterType"); - - java.sql.Timestamp ruledTimeStamp = rs.getTimestamp("ruledSince"); - - if (ruledTimeStamp != null) - this.ruledSince = LocalDateTime.ofInstant(ruledTimeStamp.toInstant(), ZoneId.systemDefault()); - - this.mapY1 = rs.getFloat("mapY1"); - this.mapX1 = rs.getFloat("mapX1"); - this.mapY2 = rs.getFloat("mapY2"); - this.mapX2 = rs.getFloat("mapX2"); - this.stretchX = rs.getInt("stretchX"); - this.stretchY = rs.getInt("stretchY"); - this.locX = rs.getInt("locX"); - this.locY = rs.getInt("locY"); - this.realmID = rs.getInt("realmID"); - this.hash = rs.getString("hash"); - } - - /* - * Getters - */ - public boolean isRuled() { - return (this.rulingCityUUID != 0); - } + // Internal class cache + + public static ConcurrentHashMap _realms = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + public final int realmID; + private final float mapR; //Red color + private final float mapG; //Green color + private final float mapB; //Blue color + private final float mapA; //Alpha color + private final boolean canBeClaimed; + private final boolean canPlaceCities; + private final int numCities; + private final String realmName; + private final float mapY1; + private final float mapX1; + private final float mapY2; + private final float mapX2; + private final int stretchX; + private final int stretchY; + private final int locX; + private final int locY; + private final HashSet cities = new HashSet<>(); + public Color mapColor; + public LocalDateTime ruledSince; + private int rulingCityUUID; + private int rulingCharacterUUID; + private int rulingCharacterOrdinal; + private String rulingCharacterName; + private int rulingNationUUID; + private GuildTag rulingNationTags; + private String rulingNationName; + private int charterType; + private String hash; + + /** + * ResultSet Constructor + */ + public Realm(ResultSet rs) throws SQLException { + + this.mapColor = new Color(Integer.parseInt(rs.getString("realmColor"), 16)); + this.mapR = (float) (mapColor.getRed() * 0.00392156863); + this.mapG = (float) (mapColor.getGreen() * 0.00392156863); + this.mapB = (float) (mapColor.getBlue() * 0.00392156863); + this.mapA = 1; + this.canBeClaimed = rs.getBoolean("canBeClaimed"); + this.canPlaceCities = rs.getBoolean("canPlaceCities"); + this.numCities = rs.getInt("numCities"); + this.realmName = rs.getString("realmName"); + this.rulingCityUUID = rs.getInt("rulingCityUID"); + this.charterType = rs.getInt("charterType"); + + java.sql.Timestamp ruledTimeStamp = rs.getTimestamp("ruledSince"); + + if (ruledTimeStamp != null) + this.ruledSince = LocalDateTime.ofInstant(ruledTimeStamp.toInstant(), ZoneId.systemDefault()); + + this.mapY1 = rs.getFloat("mapY1"); + this.mapX1 = rs.getFloat("mapX1"); + this.mapY2 = rs.getFloat("mapY2"); + this.mapX2 = rs.getFloat("mapX2"); + this.stretchX = rs.getInt("stretchX"); + this.stretchY = rs.getInt("stretchY"); + this.locX = rs.getInt("locX"); + this.locY = rs.getInt("locY"); + this.realmID = rs.getInt("realmID"); + this.hash = rs.getString("hash"); + } - public float getMapR() { - return this.mapR; - } + public static void configureAllRealms() { - public float getMapG() { - return this.mapG; - } + for (Realm realm : Realm._realms.values()) { + realm.configure(); + } + } - public float getMapB() { - return this.mapB; - } + public static Realm getRealm(int realmID) { + return _realms.get(realmID); + } - public float getMapA() { - return this.mapA; - } + public static boolean HasAllBlessings(PlayerCharacter claimer) { - public boolean getCanBeClaimed() { - return this.canBeClaimed; - } + if (claimer == null) + return false; - public boolean getCanPlaceCities() { - return this.canPlaceCities; - } + PowersBase powerBlessing = PowersManager.getPowerByIDString("BLS-POWER"); + if (!claimer.effects.containsKey(Integer.toString(powerBlessing.getActions().get(0).getUUID()))) + return false; + PowersBase wisdomBlessing = PowersManager.getPowerByIDString("BLS-POWER"); + if (!claimer.effects.containsKey(Integer.toString(wisdomBlessing.getActions().get(0).getUUID()))) + return false; + PowersBase fortuneBlessing = PowersManager.getPowerByIDString("BLS-FORTUNE"); + return claimer.effects.containsKey(Integer.toString(fortuneBlessing.getActions().get(0).getUUID())); + } - public int getNumCities() { - return this.numCities; - } + public static float getRealmHealthMod(City city) { + Realm serverRealm; + int charterType; + float returnBonus = 0.0f; + + serverRealm = RealmMap.getRealmForCity(city); + charterType = serverRealm.charterType; + + switch (charterType) { + + case 762228431: + returnBonus = 0.0f; + break; + case -15978914: + returnBonus = -.15f; + break; + case -600065291: + returnBonus = .15f; + break; + default: + break; + } - public String getRealmName() { - return this.realmName; - } + return returnBonus; + } - public City getRulingCity() { - return City.getCity(this.rulingCityUUID); - } + public static int getRealmMesh(City city) { + Realm serverRealm; + CharterType charterType; - public float getMapY1() { - return this.mapY1; - } - - public float getMapX1() { - return this.mapX1; - } - - public float getMapY2() { - return this.mapY2; - } - - public float getMapX2() { - return this.mapX2; - } + serverRealm = city.getRealm(); + charterType = CharterType.getCharterTypeByID(serverRealm.charterType); - public int getStretchX() { - return this.stretchX; - } + return charterType.getMeshID(); + } - public int getStretchY() { - return this.stretchY; - } - - public int getlocX() { - return this.locX; - } - - public int getlocY() { - return this.locY; - } - - public int getRealmID() { - return this.realmID; - } - - public void addCity(int cityUUID) { - if (!this.cities.add(cityUUID)) - this.cities.add(cityUUID); - } - - public void removeCity(int cityUUID) { - this.cities.remove(cityUUID); - } - - public boolean isRealmFull() { - - return this.cities.size() >= this.numCities; - } - - public boolean isRealmFullAfterBane() { - - return this.cities.size() > this.numCities; - } - - public static void configureAllRealms() { - - for (Realm realm : Realm._realms.values()) { - realm.configure(); - } - } - - // Call this after changing ownership before you serialize a realm - - public void configure() { - - PlayerCharacter rulingCharacter; - - // Configure what exactly? We won't send any of it. - - if (this.rulingCityUUID == 0) - return; - if (this.getRulingCity() == null) - return; - if (this.getRulingCity().getTOL() == null) - return; - - rulingCharacter = PlayerCharacter.getPlayerCharacter(this.getRulingCity().getTOL().getOwnerUUID()); - if (rulingCharacter == null){ - Logger.info( this.realmName + " failed to load " + this.getRulingCity().getCityName() + " ID : " + this.rulingCityUUID); - return; - } - - this.rulingCharacterUUID = rulingCharacter.getObjectUUID(); - this.rulingCharacterOrdinal = rulingCharacter.getObjectType().ordinal(); - this.rulingCharacterName = rulingCharacter.getFirstName() + ' ' + rulingCharacter.getLastName(); - this.rulingNationUUID = rulingCharacter.getGuild().getNation().getObjectUUID(); - this.rulingNationName = rulingCharacter.getGuild().getNation().getName(); - this.rulingNationTags = rulingCharacter.getGuild().getNation().getGuildTag(); - } - - public void serializeForClientMsg(ByteBufferWriter writer) { - - writer.putFloat(this.mapR); - writer.putFloat(this.mapG); - writer.putFloat(this.mapB); - writer.putFloat(this.mapA); - writer.put((byte) (this.canBeClaimed ? 0x1 : 0x0)); - writer.put((byte) (this.canPlaceCities ? 0x1 : 0x0)); - writer.putInt(this.numCities); - writer.putFloat(this.mapR); - writer.putFloat(this.mapG); - writer.putFloat(this.mapB); - writer.putFloat(this.mapA); - writer.putString(this.realmName); - - if (isRuled() == true) { - writer.putInt(Enum.GameObjectType.Guild.ordinal()); - writer.putInt(rulingNationUUID); - - writer.putInt(rulingCharacterOrdinal); - writer.putInt(rulingCharacterUUID); - - writer.putInt(Enum.GameObjectType.City.ordinal()); - writer.putInt(rulingCityUUID); - - writer.putLocalDateTime(this.ruledSince); - - writer.putString(rulingNationName); - GuildTag._serializeForDisplay(rulingNationTags,writer); - writer.putString(rulingCharacterName); - writer.putInt(0xB); // Display Title: enum index starts at 10. - } else { - if (this.rulingCityUUID != 0) - Logger.error( "Failed to Load realm info for city" + this.rulingCityUUID); - writer.putLong(0); - writer.putLong(0); - writer.putLong(0); - writer.put((byte) 1); - writer.put((byte) 0); - writer.putInt(0x64); - writer.put((byte) 0); - writer.put((byte) 0); - writer.put((byte) 0); - writer.putInt(0); - writer.putInt(0x10); - writer.putInt(0x10); - writer.putInt(0x10); - writer.putInt(0x0); - writer.putInt(0x0); - writer.putInt(0); - writer.putInt(0); - } - writer.putInt(0); // Male/Female - writer.putInt(this.charterType); // Charter Type - writer.putFloat(this.mapY1); - writer.putFloat(this.mapX1); - writer.putFloat(this.mapY2); - writer.putFloat(this.mapX2); - writer.putInt(this.stretchX); - writer.putInt(this.stretchY); - writer.putInt(this.locX); - writer.putInt(this.locY); - } - - public void updateDatabase() { - DbManager.RealmQueries.REALM_UPDATE(this); - } - - public static Realm getRealm(int realmID) { - return _realms.get(realmID); - } - - /** - * @return the charterType - */ - public int getCharterType() { - return charterType; - } + public static void loadAllRealms() { - /** - * @param charterType the charterType to set - */ - public void setCharterType(int charterType) { - this.charterType = charterType; - } + _realms = DbManager.RealmQueries.LOAD_ALL_REALMS(); - public void abandonRealm() { + } - // Push event to warehouse + /* + * Getters + */ + public boolean isRuled() { + return (this.rulingCityUUID != 0); + } - RealmRecord realmRecord = RealmRecord.borrow(this, Enum.RecordEventType.LOST); - DataWarehouse.pushToWarehouse(realmRecord); + public float getMapR() { + return this.mapR; + } - // No longer own a realm - this.getRulingCity().getGuild().setRealmsOwned(this.getRulingCity().getGuild().getRealmsOwned() - 1); - if (!this.getRulingCity().getGuild().getNation().equals(this.getRulingCity().getGuild())) - this.getRulingCity().getGuild().getNation().setRealmsOwned(this.getRulingCity().getGuild().getNation().getRealmsOwned() - 1); + public float getMapG() { + return this.mapG; + } - // Configure realm - this.charterType = 0; - this.rulingCityUUID = 0; - this.ruledSince = null; + public float getMapB() { + return this.mapB; + } - this.updateDatabase(); - } + public float getMapA() { + return this.mapA; + } - public void claimRealmForCity(City city, int charterType) { + public boolean getCanBeClaimed() { + return this.canBeClaimed; + } - // Configure realm - this.charterType = charterType; - this.rulingCityUUID = city.getObjectUUID(); - this.ruledSince = LocalDateTime.now(); - this.configure(); - this.updateDatabase(); + public boolean getCanPlaceCities() { + return this.canPlaceCities; + } - // Push event to warehouse + public int getNumCities() { + return this.numCities; + } - RealmRecord realmRecord = RealmRecord.borrow(this, Enum.RecordEventType.CAPTURE); - DataWarehouse.pushToWarehouse(realmRecord); + public String getRealmName() { + return this.realmName; + } - } + public City getRulingCity() { + return City.getCity(this.rulingCityUUID); + } - public static boolean HasAllBlessings(PlayerCharacter claimer) { + public float getMapY1() { + return this.mapY1; + } - if (claimer == null) - return false; + public float getMapX1() { + return this.mapX1; + } - PowersBase powerBlessing = PowersManager.getPowerByIDString("BLS-POWER"); - if (!claimer.effects.containsKey(Integer.toString(powerBlessing.getActions().get(0).getUUID()))) - return false; - PowersBase wisdomBlessing = PowersManager.getPowerByIDString("BLS-POWER"); - if (!claimer.effects.containsKey(Integer.toString(wisdomBlessing.getActions().get(0).getUUID()))) - return false; - PowersBase fortuneBlessing = PowersManager.getPowerByIDString("BLS-FORTUNE"); - return claimer.effects.containsKey(Integer.toString(fortuneBlessing.getActions().get(0).getUUID())); - } + public float getMapY2() { + return this.mapY2; + } - public static float getRealmHealthMod(City city) { - Realm serverRealm; - int charterType; - float returnBonus = 0.0f; + public float getMapX2() { + return this.mapX2; + } - serverRealm = RealmMap.getRealmForCity(city); - charterType = serverRealm.charterType; + public int getStretchX() { + return this.stretchX; + } - switch (charterType) { + public int getStretchY() { + return this.stretchY; + } - case 762228431: - returnBonus = 0.0f; - break; - case -15978914: - returnBonus = -.15f; - break; - case -600065291: - returnBonus = .15f; - break; - default: - break; - } + public int getlocX() { + return this.locX; + } - return returnBonus; - } + public int getlocY() { + return this.locY; + } - public static int getRealmMesh(City city) { - Realm serverRealm; - CharterType charterType; + // Call this after changing ownership before you serialize a realm - serverRealm = city.getRealm(); - charterType = CharterType.getCharterTypeByID(serverRealm.charterType); + public int getRealmID() { + return this.realmID; + } - return charterType.getMeshID(); - } + public void addCity(int cityUUID) { + if (!this.cities.add(cityUUID)) + this.cities.add(cityUUID); + } - public static void loadAllRealms() { + public void removeCity(int cityUUID) { + this.cities.remove(cityUUID); + } - _realms = DbManager.RealmQueries.LOAD_ALL_REALMS(); + public boolean isRealmFull() { - } + return this.cities.size() >= this.numCities; + } - public String getHash() { - return hash; - } + public boolean isRealmFullAfterBane() { - public void setHash() { + return this.cities.size() > this.numCities; + } + + public void configure() { + + PlayerCharacter rulingCharacter; + + // Configure what exactly? We won't send any of it. + + if (this.rulingCityUUID == 0) + return; + if (this.getRulingCity() == null) + return; + if (this.getRulingCity().getTOL() == null) + return; + + rulingCharacter = PlayerCharacter.getPlayerCharacter(this.getRulingCity().getTOL().getOwnerUUID()); + if (rulingCharacter == null) { + Logger.info(this.realmName + " failed to load " + this.getRulingCity().getCityName() + " ID : " + this.rulingCityUUID); + return; + } + + this.rulingCharacterUUID = rulingCharacter.getObjectUUID(); + this.rulingCharacterOrdinal = rulingCharacter.getObjectType().ordinal(); + this.rulingCharacterName = rulingCharacter.getFirstName() + ' ' + rulingCharacter.getLastName(); + this.rulingNationUUID = rulingCharacter.getGuild().getNation().getObjectUUID(); + this.rulingNationName = rulingCharacter.getGuild().getNation().getName(); + this.rulingNationTags = rulingCharacter.getGuild().getNation().getGuildTag(); + } + + public void serializeForClientMsg(ByteBufferWriter writer) { + + writer.putFloat(this.mapR); + writer.putFloat(this.mapG); + writer.putFloat(this.mapB); + writer.putFloat(this.mapA); + writer.put((byte) (this.canBeClaimed ? 0x1 : 0x0)); + writer.put((byte) (this.canPlaceCities ? 0x1 : 0x0)); + writer.putInt(this.numCities); + writer.putFloat(this.mapR); + writer.putFloat(this.mapG); + writer.putFloat(this.mapB); + writer.putFloat(this.mapA); + writer.putString(this.realmName); + + if (isRuled() == true) { + writer.putInt(Enum.GameObjectType.Guild.ordinal()); + writer.putInt(rulingNationUUID); + + writer.putInt(rulingCharacterOrdinal); + writer.putInt(rulingCharacterUUID); + + writer.putInt(Enum.GameObjectType.City.ordinal()); + writer.putInt(rulingCityUUID); + + writer.putLocalDateTime(this.ruledSince); + + writer.putString(rulingNationName); + GuildTag._serializeForDisplay(rulingNationTags, writer); + writer.putString(rulingCharacterName); + writer.putInt(0xB); // Display Title: enum index starts at 10. + } else { + if (this.rulingCityUUID != 0) + Logger.error("Failed to Load realm info for city" + this.rulingCityUUID); + writer.putLong(0); + writer.putLong(0); + writer.putLong(0); + writer.put((byte) 1); + writer.put((byte) 0); + writer.putInt(0x64); + writer.put((byte) 0); + writer.put((byte) 0); + writer.put((byte) 0); + writer.putInt(0); + writer.putInt(0x10); + writer.putInt(0x10); + writer.putInt(0x10); + writer.putInt(0x0); + writer.putInt(0x0); + writer.putInt(0); + writer.putInt(0); + } + writer.putInt(0); // Male/Female + writer.putInt(this.charterType); // Charter Type + writer.putFloat(this.mapY1); + writer.putFloat(this.mapX1); + writer.putFloat(this.mapY2); + writer.putFloat(this.mapX2); + writer.putInt(this.stretchX); + writer.putInt(this.stretchY); + writer.putInt(this.locX); + writer.putInt(this.locY); + } + + public void updateDatabase() { + DbManager.RealmQueries.REALM_UPDATE(this); + } + + /** + * @return the charterType + */ + public int getCharterType() { + return charterType; + } + + /** + * @param charterType the charterType to set + */ + public void setCharterType(int charterType) { + this.charterType = charterType; + } - this.hash = DataWarehouse.hasher.encrypt(this.realmID); + public void abandonRealm() { - // Write hash to player character table + // Push event to warehouse - DataWarehouse.writeHash(Enum.DataRecordType.REALM, this.realmID); - } + RealmRecord realmRecord = RealmRecord.borrow(this, Enum.RecordEventType.LOST); + DataWarehouse.pushToWarehouse(realmRecord); + + // No longer own a realm + this.getRulingCity().getGuild().setRealmsOwned(this.getRulingCity().getGuild().getRealmsOwned() - 1); + if (!this.getRulingCity().getGuild().getNation().equals(this.getRulingCity().getGuild())) + this.getRulingCity().getGuild().getNation().setRealmsOwned(this.getRulingCity().getGuild().getNation().getRealmsOwned() - 1); + + // Configure realm + this.charterType = 0; + this.rulingCityUUID = 0; + this.ruledSince = null; + + this.updateDatabase(); + } + + public void claimRealmForCity(City city, int charterType) { + + // Configure realm + this.charterType = charterType; + this.rulingCityUUID = city.getObjectUUID(); + this.ruledSince = LocalDateTime.now(); + this.configure(); + this.updateDatabase(); + + // Push event to warehouse + + RealmRecord realmRecord = RealmRecord.borrow(this, Enum.RecordEventType.CAPTURE); + DataWarehouse.pushToWarehouse(realmRecord); + + } + + public String getHash() { + return hash; + } + + public void setHash() { + + this.hash = DataWarehouse.hasher.encrypt(this.realmID); + + // Write hash to player character table + + DataWarehouse.writeHash(Enum.DataRecordType.REALM, this.realmID); + } /* *** Keeping around in case needed for server wipe or some other emergency diff --git a/src/engine/objects/Regions.java b/src/engine/objects/Regions.java index ea03ce64..aa0c363d 100644 --- a/src/engine/objects/Regions.java +++ b/src/engine/objects/Regions.java @@ -21,364 +21,354 @@ import java.util.ArrayList; import java.util.HashMap; +public class Regions { + + public static HashMap FurnitureRegionMap = new HashMap<>(); + public final boolean stairs; + public final boolean exit; + public int room; + public boolean outside; + public int level; + public Vector3fImmutable lowLerp; + public Vector3fImmutable highLerp; + public Vector3f center; + public float regionDistanceSquared; + + public ArrayList regionPoints; + + public int parentBuildingID; + + + public Regions(ArrayList regionPoints, int level, int room, boolean outside, boolean exit, boolean stairs, Vector3f center, int parentBuildingID) { + super(); -public class Regions { - - public int room; - public boolean outside; - public int level; - public final boolean stairs; - public final boolean exit; - public static HashMap FurnitureRegionMap = new HashMap<>(); - public Vector3fImmutable lowLerp; - public Vector3fImmutable highLerp; - public Vector3f center; - public float regionDistanceSquared; - - public ArrayList regionPoints; - - public int parentBuildingID; - - - public Regions(ArrayList regionPoints, int level, int room, boolean outside, boolean exit,boolean stairs, Vector3f center, int parentBuildingID) { - super(); - this.level = level; this.room = room; - - this.outside = (outside); - this.regionPoints = regionPoints; - this.exit = exit; - this.stairs = stairs; - this.center = center; - this.parentBuildingID = parentBuildingID; - //order regionpoints clockwise starting from top left, and ending bottom left. - - ArrayList top = new ArrayList<>(); - ArrayList bottom = new ArrayList<>(); - - for (Vector3f point : this.regionPoints){ - if (point.y > center.y) - top.add(point); - else if (point.y < center.y) - bottom.add(point); - } - - - if (top.size() == 2 && bottom.size() == 2){ - Vector3f topLeft = Vector3f.min(top.get(0), top.get(1)); - Vector3f topRight = Vector3f.max(top.get(0), top.get(1)); - - Vector3f topCenter = topLeft.lerp(topRight, .5f); - - Vector3f bottomLeft = Vector3f.min(bottom.get(0), bottom.get(1)); - Vector3f bottomRight = Vector3f.max(bottom.get(0), bottom.get(1)); - - Vector3f bottomCenter = bottomLeft.lerp(bottomRight, .5f); - - this.lowLerp = new Vector3fImmutable(bottomCenter); - this.highLerp = new Vector3fImmutable(topCenter); - - } else if (top.size() == 2 && bottom.size() == 1){ - Vector3f topLeft = Vector3f.min(top.get(0), top.get(1)); - Vector3f topRight = Vector3f.max(top.get(0), top.get(1)); - - Vector3f topCenter = topLeft.lerp(topRight, .5f); - - Vector3f topCopy = topRight.subtract2D(topLeft); - topCopy.normalize(); - - float topMagnitude = topRight.subtract2D(topLeft).length(); - - topCopy.multLocal(topMagnitude); - - Vector3f bottomLeft = null; - Vector3f bottomRight = null; - if (bottom.get(0).distance2D(topLeft) <= bottom.get(0).distance2D(topRight)) - bottomLeft = bottom.get(0); - else if (bottom.get(0).distance2D(topRight) <= bottom.get(0).distance2D(topLeft)) - bottomRight = bottom.get(0); - //find bottom right point - - if (bottomLeft != null){ - bottomRight = bottomLeft.add(topCopy); - }else if (bottomRight != null){ - bottomLeft = bottomRight.subtract(topCopy); - } - - - - Vector3f bottomCenter = bottomLeft.lerp(bottomRight, .5f); - - this.lowLerp = new Vector3fImmutable(bottomCenter); - this.highLerp = new Vector3fImmutable(topCenter); - - }else if (bottom.size() == 2 && top.size() == 1){ - Vector3f topLeft = Vector3f.min(bottom.get(0), bottom.get(1)); - Vector3f topRight = Vector3f.max(bottom.get(0), bottom.get(1)); - - Vector3f topCenter = topLeft.lerp(topRight, .5f); - - Vector3f topCopy = topRight.subtract2D(topLeft); - topCopy.normalize(); - - float topMagnitude = topRight.subtract2D(topLeft).length(); - - topCopy.multLocal(topMagnitude); - - Vector3f bottomLeft = null; - Vector3f bottomRight = null; - if (top.get(0).distance2D(topLeft) < top.get(0).distance2D(topRight)) - bottomLeft = bottom.get(0); - else if (top.get(0).distance2D(topRight) < top.get(0).distance2D(topLeft)) - bottomRight = bottom.get(0); - //find bottom right point - - if (bottomLeft != null){ - bottomRight = bottomLeft.add(topCopy); - }else if (bottomRight != null){ - bottomLeft = bottomRight.subtract(topCopy); - } - - - - Vector3f bottomCenter = bottomLeft.lerp(bottomRight, .5f); - - this.lowLerp = new Vector3fImmutable(bottomCenter); - this.highLerp = new Vector3fImmutable(topCenter); - } - - if (this.lowLerp == null) - this.lowLerp = new Vector3fImmutable(this.regionPoints.get(0)); - - if (this.highLerp == null){ - this.highLerp = new Vector3fImmutable(this.regionPoints.get(2)); - } - - this.regionDistanceSquared = this.lowLerp.distanceSquared2D(this.highLerp); - } - - public int getRoom() { - return room; - } - - - - - public boolean isOutside() { - return outside; - } - - - public int getLevel() { - return level; - } - - public boolean collides(Vector3fImmutable collisionPoint){ - - //test if inside triangle // Regions either have 3 or 4 points - if (this.regionPoints.size() == 3){ - float regionArea = FastMath.area(regionPoints.get(0).x, regionPoints.get(0).z, regionPoints.get(1).x, regionPoints.get(1).z, regionPoints.get(2).x, regionPoints.get(2).z); - float collisionArea1 = FastMath.area(collisionPoint.x, collisionPoint.z, regionPoints.get(0).x, regionPoints.get(0).z,regionPoints.get(1).x, regionPoints.get(1).z); - float collisionArea2 = FastMath.area(collisionPoint.x, collisionPoint.z, regionPoints.get(1).x, regionPoints.get(1).z,regionPoints.get(2).x, regionPoints.get(2).z); - float collisionArea3 = FastMath.area(collisionPoint.x, collisionPoint.z, regionPoints.get(0).x, regionPoints.get(0).z,regionPoints.get(2).x, regionPoints.get(2).z); - - if ((collisionArea1 + collisionArea2 + collisionArea3) == regionArea) - return true; - - }else{ - - int i; - int j; - for (i = 0, j = this.regionPoints.size() - 1; i < this.regionPoints.size(); j = i++) { - if ((regionPoints.get(i).z > collisionPoint.z) != (regionPoints.get(j).z > collisionPoint.z) && - (collisionPoint.x < (regionPoints.get(j).x - regionPoints.get(i).x) * (collisionPoint.z - regionPoints.get(i).z) / (regionPoints.get(j).z-regionPoints.get(i).z) + regionPoints.get(i).x)) { - return true; - } - } - - } - - return false; - } - - public boolean isPointInPolygon( Vector3fImmutable point) - { - boolean inside = false; - for (int i = 0, j = regionPoints.size()-1; i < regionPoints.size(); j = i++) - { - if (((regionPoints.get(i).z > point.z) != (regionPoints.get(j).z > point.z)) && - (point.x < (regionPoints.get(j).x - regionPoints.get(i).x) * (point.z - regionPoints.get(i).z) / (regionPoints.get(j).z - regionPoints.get(i).z) + regionPoints.get(i).x)) - inside = !inside; - } - return inside; - } - - public static boolean CanEnterRegion(AbstractWorldObject worldObject, Regions toEnter){ - - if (worldObject.region == null) - if (toEnter.level == 0 || toEnter.room == -1 || toEnter.exit) - return true; - else - return false; - - if (worldObject.region.equals(toEnter)) - return true; - - if (worldObject.region.level == toEnter.level) - return true; - - //next region is stairs, if they are on the same level as stairs or 1 up, world object can enter. - if (toEnter.stairs) - if (worldObject.region.level == toEnter.level || toEnter.level - 1 == worldObject.region.level) - return true; - if (worldObject.region.stairs) { - - boolean movingUp = false; - - boolean movingDown = false; - float yLerp = worldObject.region.lerpY(worldObject); - - if (yLerp == (worldObject.region.highLerp.y)) - movingUp = true; - else if (yLerp == (worldObject.region.lowLerp.y)) - movingDown = true; - //Stairs are always considered on the bottom floor. - - - if (movingUp) { - if (toEnter.level == worldObject.region.level + 1) - return true; - } else if (movingDown) - if (toEnter.level == worldObject.region.level) - return true; - - } - - return false; - } - - public float lerpY (AbstractWorldObject lerper){ - - Vector3fImmutable lengthVector = this.highLerp.subtract2D(this.lowLerp); - Vector3fImmutable characterVector = lerper.getLoc().subtract2D(this.lowLerp); - float lengthVectorMagnitude = lengthVector.magnitude(); - float characterVectorMagnitude = characterVector.magnitude(); - float percentDistance = characterVectorMagnitude/lengthVectorMagnitude; - float interpolatedY = this.lowLerp.interpolate(this.highLerp, percentDistance).y; - - if (interpolatedY > this.highLerp.y) - interpolatedY = this.highLerp.y; - else if (interpolatedY < this.lowLerp.y) - interpolatedY = this.lowLerp.y; - return interpolatedY; - } - - - public boolean isStairs() { - return stairs; - } - - - public boolean isExit() { - return exit; - } - -public static float GetMagnitudeOfRegionSlope(Regions region){ - Vector3fImmutable lengthVector = region.highLerp.subtract2D(region.lowLerp); - return lengthVector.magnitude(); - } - -public static float GetMagnitudeOfPlayerOnRegionSlope(Regions region, PlayerCharacter player){ - Vector3fImmutable characterVector = player.getLoc().subtract2D(region.lowLerp); - return characterVector.magnitude(); - } - -public static float SlopeLerpPercent(PlayerCharacter player, Regions region){ - - float lengthVectorMagnitude = Regions.GetMagnitudeOfRegionSlope(region); - float characterVectorMagnitude = Regions.GetMagnitudeOfPlayerOnRegionSlope(region, player); - float percentDistance = characterVectorMagnitude/lengthVectorMagnitude * 2; - return percentDistance; -} -public static boolean CanEnterFromOutsideBuilding(Building building,Regions region){ - if (!region.outside) - return false; - if (region.lowLerp.y - building.getLoc().y > 1 ) - return false; - - return true; -} + this.outside = (outside); + this.regionPoints = regionPoints; + this.exit = exit; + this.stairs = stairs; + this.center = center; + this.parentBuildingID = parentBuildingID; + //order regionpoints clockwise starting from top left, and ending bottom left. -public static boolean CanEnterNextLevel(Regions fromRegion,Regions toRegion, AbstractWorldObject worldObject){ - - if (fromRegion == null) - return false; - - if (toRegion == null) - return false; - - // regions are the same, no need to go any further. - if (fromRegion.equals(toRegion)) - return true; - - //cant move up a level without stairs. - if (!fromRegion.stairs) - return false; - - boolean movingUp = false; - - Vector3fImmutable closestPoint = Vector3fImmutable.ClosestPointOnLine(fromRegion.lowLerp, fromRegion.highLerp, worldObject.getLoc()); - - //Closest point of a region higher than current region will always return highlerp. - if (closestPoint.equals(fromRegion.highLerp)) - movingUp = true; - //Stairs are always considered on the bottom floor. - - if (movingUp){ - if(toRegion.level != fromRegion.level + 1) - return false; - }else if (toRegion.level != fromRegion.level) - return false; - return true; -} + ArrayList top = new ArrayList<>(); + ArrayList bottom = new ArrayList<>(); -public static boolean IsGroundLevel(Regions region, Building building){ - - if (region.lowLerp.y - building.getLoc().y > 1) - return false; - return true; -} + for (Vector3f point : this.regionPoints) { + if (point.y > center.y) + top.add(point); + else if (point.y < center.y) + bottom.add(point); + } -public static Building GetBuildingForRegion(Regions region){ - return BuildingManager.getBuildingFromCache(region.parentBuildingID); -} -public static Regions GetRegionForTeleport(Vector3fImmutable location){ - Regions region = null; - - - //Find building - for (AbstractWorldObject awo:WorldGrid.getObjectsInRangePartial(location, MBServerStatics.STRUCTURE_LOAD_RANGE, MBServerStatics.MASK_BUILDING)){ - Building building = (Building)awo; - if (!Bounds.collide(location, building.getBounds())) - continue; - - //find regions that intersect x and z, check if object can enter. - for (Regions toEnter: building.getBounds().getRegions()){ - if (toEnter.isPointInPolygon(location)){ - - if (region == null) - region = toEnter; - else // we're using a low level to high level tree structure, database not always in order low to high. - //check for highest level index. - if(region != null && toEnter.highLerp.y > region.highLerp.y) - region = toEnter; - - - } - } - } - return region; -} + + if (top.size() == 2 && bottom.size() == 2) { + Vector3f topLeft = Vector3f.min(top.get(0), top.get(1)); + Vector3f topRight = Vector3f.max(top.get(0), top.get(1)); + + Vector3f topCenter = topLeft.lerp(topRight, .5f); + + Vector3f bottomLeft = Vector3f.min(bottom.get(0), bottom.get(1)); + Vector3f bottomRight = Vector3f.max(bottom.get(0), bottom.get(1)); + + Vector3f bottomCenter = bottomLeft.lerp(bottomRight, .5f); + + this.lowLerp = new Vector3fImmutable(bottomCenter); + this.highLerp = new Vector3fImmutable(topCenter); + + } else if (top.size() == 2 && bottom.size() == 1) { + Vector3f topLeft = Vector3f.min(top.get(0), top.get(1)); + Vector3f topRight = Vector3f.max(top.get(0), top.get(1)); + + Vector3f topCenter = topLeft.lerp(topRight, .5f); + + Vector3f topCopy = topRight.subtract2D(topLeft); + topCopy.normalize(); + + float topMagnitude = topRight.subtract2D(topLeft).length(); + + topCopy.multLocal(topMagnitude); + + Vector3f bottomLeft = null; + Vector3f bottomRight = null; + if (bottom.get(0).distance2D(topLeft) <= bottom.get(0).distance2D(topRight)) + bottomLeft = bottom.get(0); + else if (bottom.get(0).distance2D(topRight) <= bottom.get(0).distance2D(topLeft)) + bottomRight = bottom.get(0); + //find bottom right point + + if (bottomLeft != null) { + bottomRight = bottomLeft.add(topCopy); + } else if (bottomRight != null) { + bottomLeft = bottomRight.subtract(topCopy); + } + + + Vector3f bottomCenter = bottomLeft.lerp(bottomRight, .5f); + + this.lowLerp = new Vector3fImmutable(bottomCenter); + this.highLerp = new Vector3fImmutable(topCenter); + + } else if (bottom.size() == 2 && top.size() == 1) { + Vector3f topLeft = Vector3f.min(bottom.get(0), bottom.get(1)); + Vector3f topRight = Vector3f.max(bottom.get(0), bottom.get(1)); + + Vector3f topCenter = topLeft.lerp(topRight, .5f); + + Vector3f topCopy = topRight.subtract2D(topLeft); + topCopy.normalize(); + + float topMagnitude = topRight.subtract2D(topLeft).length(); + + topCopy.multLocal(topMagnitude); + + Vector3f bottomLeft = null; + Vector3f bottomRight = null; + if (top.get(0).distance2D(topLeft) < top.get(0).distance2D(topRight)) + bottomLeft = bottom.get(0); + else if (top.get(0).distance2D(topRight) < top.get(0).distance2D(topLeft)) + bottomRight = bottom.get(0); + //find bottom right point + + if (bottomLeft != null) { + bottomRight = bottomLeft.add(topCopy); + } else if (bottomRight != null) { + bottomLeft = bottomRight.subtract(topCopy); + } + + + Vector3f bottomCenter = bottomLeft.lerp(bottomRight, .5f); + + this.lowLerp = new Vector3fImmutable(bottomCenter); + this.highLerp = new Vector3fImmutable(topCenter); + } + + if (this.lowLerp == null) + this.lowLerp = new Vector3fImmutable(this.regionPoints.get(0)); + + if (this.highLerp == null) { + this.highLerp = new Vector3fImmutable(this.regionPoints.get(2)); + } + + this.regionDistanceSquared = this.lowLerp.distanceSquared2D(this.highLerp); + } + + public static boolean CanEnterRegion(AbstractWorldObject worldObject, Regions toEnter) { + + if (worldObject.region == null) + if (toEnter.level == 0 || toEnter.room == -1 || toEnter.exit) + return true; + else + return false; + + if (worldObject.region.equals(toEnter)) + return true; + + if (worldObject.region.level == toEnter.level) + return true; + + //next region is stairs, if they are on the same level as stairs or 1 up, world object can enter. + if (toEnter.stairs) + if (worldObject.region.level == toEnter.level || toEnter.level - 1 == worldObject.region.level) + return true; + if (worldObject.region.stairs) { + + boolean movingUp = false; + + boolean movingDown = false; + float yLerp = worldObject.region.lerpY(worldObject); + + if (yLerp == (worldObject.region.highLerp.y)) + movingUp = true; + else if (yLerp == (worldObject.region.lowLerp.y)) + movingDown = true; + //Stairs are always considered on the bottom floor. + + + if (movingUp) { + if (toEnter.level == worldObject.region.level + 1) + return true; + } else if (movingDown) + if (toEnter.level == worldObject.region.level) + return true; + + } + + return false; + } + + public static float GetMagnitudeOfRegionSlope(Regions region) { + Vector3fImmutable lengthVector = region.highLerp.subtract2D(region.lowLerp); + return lengthVector.magnitude(); + } + + public static float GetMagnitudeOfPlayerOnRegionSlope(Regions region, PlayerCharacter player) { + Vector3fImmutable characterVector = player.getLoc().subtract2D(region.lowLerp); + return characterVector.magnitude(); + } + + public static float SlopeLerpPercent(PlayerCharacter player, Regions region) { + + float lengthVectorMagnitude = Regions.GetMagnitudeOfRegionSlope(region); + float characterVectorMagnitude = Regions.GetMagnitudeOfPlayerOnRegionSlope(region, player); + float percentDistance = characterVectorMagnitude / lengthVectorMagnitude * 2; + return percentDistance; + } + + public static boolean CanEnterFromOutsideBuilding(Building building, Regions region) { + if (!region.outside) + return false; + if (region.lowLerp.y - building.getLoc().y > 1) + return false; + + return true; + } + + public static boolean CanEnterNextLevel(Regions fromRegion, Regions toRegion, AbstractWorldObject worldObject) { + + if (fromRegion == null) + return false; + + if (toRegion == null) + return false; + + // regions are the same, no need to go any further. + if (fromRegion.equals(toRegion)) + return true; + + //cant move up a level without stairs. + if (!fromRegion.stairs) + return false; + + boolean movingUp = false; + + Vector3fImmutable closestPoint = Vector3fImmutable.ClosestPointOnLine(fromRegion.lowLerp, fromRegion.highLerp, worldObject.getLoc()); + + //Closest point of a region higher than current region will always return highlerp. + if (closestPoint.equals(fromRegion.highLerp)) + movingUp = true; + //Stairs are always considered on the bottom floor. + + if (movingUp) { + if (toRegion.level != fromRegion.level + 1) + return false; + } else if (toRegion.level != fromRegion.level) + return false; + return true; + } + + public static boolean IsGroundLevel(Regions region, Building building) { + + if (region.lowLerp.y - building.getLoc().y > 1) + return false; + return true; + } + + public static Building GetBuildingForRegion(Regions region) { + return BuildingManager.getBuildingFromCache(region.parentBuildingID); + } + + public static Regions GetRegionForTeleport(Vector3fImmutable location) { + Regions region = null; + + + //Find building + for (AbstractWorldObject awo : WorldGrid.getObjectsInRangePartial(location, MBServerStatics.STRUCTURE_LOAD_RANGE, MBServerStatics.MASK_BUILDING)) { + Building building = (Building) awo; + if (!Bounds.collide(location, building.getBounds())) + continue; + + //find regions that intersect x and z, check if object can enter. + for (Regions toEnter : building.getBounds().getRegions()) { + if (toEnter.isPointInPolygon(location)) { + + if (region == null) + region = toEnter; + else // we're using a low level to high level tree structure, database not always in order low to high. + //check for highest level index. + if (region != null && toEnter.highLerp.y > region.highLerp.y) + region = toEnter; + + + } + } + } + return region; + } + + public int getRoom() { + return room; + } + + public boolean isOutside() { + return outside; + } + + public int getLevel() { + return level; + } + + public boolean collides(Vector3fImmutable collisionPoint) { + + //test if inside triangle // Regions either have 3 or 4 points + if (this.regionPoints.size() == 3) { + float regionArea = FastMath.area(regionPoints.get(0).x, regionPoints.get(0).z, regionPoints.get(1).x, regionPoints.get(1).z, regionPoints.get(2).x, regionPoints.get(2).z); + float collisionArea1 = FastMath.area(collisionPoint.x, collisionPoint.z, regionPoints.get(0).x, regionPoints.get(0).z, regionPoints.get(1).x, regionPoints.get(1).z); + float collisionArea2 = FastMath.area(collisionPoint.x, collisionPoint.z, regionPoints.get(1).x, regionPoints.get(1).z, regionPoints.get(2).x, regionPoints.get(2).z); + float collisionArea3 = FastMath.area(collisionPoint.x, collisionPoint.z, regionPoints.get(0).x, regionPoints.get(0).z, regionPoints.get(2).x, regionPoints.get(2).z); + + if ((collisionArea1 + collisionArea2 + collisionArea3) == regionArea) + return true; + + } else { + + int i; + int j; + for (i = 0, j = this.regionPoints.size() - 1; i < this.regionPoints.size(); j = i++) { + if ((regionPoints.get(i).z > collisionPoint.z) != (regionPoints.get(j).z > collisionPoint.z) && + (collisionPoint.x < (regionPoints.get(j).x - regionPoints.get(i).x) * (collisionPoint.z - regionPoints.get(i).z) / (regionPoints.get(j).z - regionPoints.get(i).z) + regionPoints.get(i).x)) { + return true; + } + } + + } + + return false; + } + + public boolean isPointInPolygon(Vector3fImmutable point) { + boolean inside = false; + for (int i = 0, j = regionPoints.size() - 1; i < regionPoints.size(); j = i++) { + if (((regionPoints.get(i).z > point.z) != (regionPoints.get(j).z > point.z)) && + (point.x < (regionPoints.get(j).x - regionPoints.get(i).x) * (point.z - regionPoints.get(i).z) / (regionPoints.get(j).z - regionPoints.get(i).z) + regionPoints.get(i).x)) + inside = !inside; + } + return inside; + } + + public float lerpY(AbstractWorldObject lerper) { + + Vector3fImmutable lengthVector = this.highLerp.subtract2D(this.lowLerp); + Vector3fImmutable characterVector = lerper.getLoc().subtract2D(this.lowLerp); + float lengthVectorMagnitude = lengthVector.magnitude(); + float characterVectorMagnitude = characterVector.magnitude(); + float percentDistance = characterVectorMagnitude / lengthVectorMagnitude; + float interpolatedY = this.lowLerp.interpolate(this.highLerp, percentDistance).y; + + if (interpolatedY > this.highLerp.y) + interpolatedY = this.highLerp.y; + else if (interpolatedY < this.lowLerp.y) + interpolatedY = this.lowLerp.y; + return interpolatedY; + } + + public boolean isStairs() { + return stairs; + } + + public boolean isExit() { + return exit; + } } diff --git a/src/engine/objects/Resists.java b/src/engine/objects/Resists.java index 5e5fae0b..e72b1827 100644 --- a/src/engine/objects/Resists.java +++ b/src/engine/objects/Resists.java @@ -27,415 +27,445 @@ import java.util.concurrent.ConcurrentHashMap; public class Resists { - private ConcurrentHashMap resists = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private ConcurrentHashMap immuneTo = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private DamageType protection; - private int protectionTrains=0; - private boolean immuneToAll; - private static ConcurrentHashMap mobResists = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - - /** - * Generic Constructor - */ - - public Resists(String type) { - switch (type) { - case "Building": - setBuildingResists(); - break; - case "Mine": - setMineResists(); - break; - default: - setGenericResists(); - break; - } - } - - public Resists(Resists r) { - for (DamageType dt : r.resists.keySet()) - this.resists.put(dt, r.resists.get(dt)); - for (DamageType dt : r.immuneTo.keySet()) - this.immuneTo.put(dt, r.immuneTo.get(dt)); - this.protection = r.protection; - this.protectionTrains = r.protectionTrains; - this.immuneToAll = r.immuneToAll; - } - - /** - * Generic Constructor for player - */ - public Resists(PlayerCharacter pc) { - setGenericResists(); - } - - public Resists(Mob mob) { - setGenericResists(); - } - - /** - * Called for mobBase when getting from the db fails - */ - public Resists(MobBase mobBase) { - setGenericResists(); - } - /** - * Database Constructor - */ - public Resists(ResultSet rs) throws SQLException { - this.immuneToAll = false; - this.resists.put(DamageType.Slash, rs.getFloat("slash")); - this.resists.put(DamageType.Crush, rs.getFloat("crush")); - this.resists.put(DamageType.Pierce, rs.getFloat("pierce")); - this.resists.put(DamageType.Magic, rs.getFloat("magic")); - this.resists.put(DamageType.Bleed, rs.getFloat("bleed")); - this.resists.put(DamageType.Poison, rs.getFloat("poison")); - this.resists.put(DamageType.Mental, rs.getFloat("mental")); - this.resists.put(DamageType.Holy, rs.getFloat("holy")); - this.resists.put(DamageType.Unholy, rs.getFloat("unholy")); - this.resists.put(DamageType.Lightning, rs.getFloat("lightning")); - this.resists.put(DamageType.Fire, rs.getFloat("fire")); - this.resists.put(DamageType.Cold, rs.getFloat("cold")); - this.resists.put(DamageType.Healing, 0f); - } - - /** - * Create generic resists for buildings - */ - public final void setBuildingResists() { - this.immuneToAll = false; - this.resists.put(DamageType.Slash, 85f); - this.resists.put(DamageType.Crush, 85f); - this.resists.put(DamageType.Siege, 0f); - this.immuneTo.put(DamageType.Pierce, true); - this.immuneTo.put(DamageType.Magic, true); - this.immuneTo.put(DamageType.Bleed, true); - this.immuneTo.put(DamageType.Poison, true); - this.immuneTo.put(DamageType.Mental, true); - this.immuneTo.put(DamageType.Holy, true); - this.immuneTo.put(DamageType.Unholy, true); - this.immuneTo.put(DamageType.Lightning, true); - this.immuneTo.put(DamageType.Fire, true); - this.immuneTo.put(DamageType.Cold, true); - - } - - /** - * Create generic resists for mines - */ - public final void setMineResists() { - this.immuneToAll = false; - this.immuneTo.put(DamageType.Slash, true); - this.immuneTo.put(DamageType.Crush, true); - this.immuneTo.put(DamageType.Pierce, true); - this.immuneTo.put(DamageType.Magic, true); - this.immuneTo.put(DamageType.Bleed, true); - this.immuneTo.put(DamageType.Poison, true); - this.immuneTo.put(DamageType.Mental, true); - this.immuneTo.put(DamageType.Holy, true); - this.immuneTo.put(DamageType.Unholy, true); - this.immuneTo.put(DamageType.Lightning, true); - this.immuneTo.put(DamageType.Fire, true); - this.immuneTo.put(DamageType.Cold, true); - this.resists.put(DamageType.Siege, 0f); - } - - /** - * Create generic resists - */ - public final void setGenericResists() { - this.immuneToAll = false; - this.resists.put(DamageType.Slash, 0f); - this.resists.put(DamageType.Crush, 0f); - this.resists.put(DamageType.Pierce, 0f); - this.resists.put(DamageType.Magic, 0f); - this.resists.put(DamageType.Bleed, 0f); - this.resists.put(DamageType.Poison, 0f); - this.resists.put(DamageType.Mental, 0f); - this.resists.put(DamageType.Holy, 0f); - this.resists.put(DamageType.Unholy, 0f); - this.resists.put(DamageType.Lightning, 0f); - this.resists.put(DamageType.Fire, 0f); - this.resists.put(DamageType.Cold, 0f); - this.resists.put(DamageType.Healing, 0f); - this.immuneTo.put(DamageType.Siege, true); - - } - - /** - * Get a resist - */ - public float getResist(DamageType type, int trains) { - //get resisted amount - Float amount = 0f; - if (this.resists.containsKey(type)) - amount = this.resists.get(type); - - //add protection - if (trains > 0 && protection != null && type.equals(this.protection)) { - float prot = 50 + this.protectionTrains - trains; - amount += (prot >= 0) ? prot : 0; - } - - if (amount == null) - return 0f; - if (amount > 75f) - return 75f; - return amount; - } - - /** - * get immuneTo - */ - public boolean immuneTo(DamageType type) { - if (this.immuneTo.containsKey(type)) - return this.immuneTo.get(type); - else - return false; - } - - /** - * get immuneToAll - */ - public boolean immuneToAll() { - return this.immuneToAll; - } - - public boolean immuneToPowers() { - return immuneTo(DamageType.Powers); - } - - public boolean immuneToAttacks() { - return immuneTo(DamageType.Attack); - } - - public boolean immuneToSpires() { - return immuneTo(DamageType.Spires); - } - - /** - * gets immuneTo(type) and immuneToAll - */ - public boolean isImmune(DamageType type) { - if (this.immuneToAll) - return true; - return this.immuneTo(type); - } - - /** - * Set a resist - */ - public void setResist(DamageType type, float value) { - this.resists.put(type, value); - } - - /** - * add to a resist - */ - public void incResist(DamageType type, float value) { - Float amount = this.resists.get(type); - if (amount == null) - this.resists.put(type, value); - else - this.resists.put(type, amount + value); - } - - /** - * subtract from a resist - */ - public void decResist(DamageType type, float value) { - Float amount = this.resists.get(type); - if (amount == null) - this.resists.put(type, (0 - value)); - else - this.resists.put(type, amount - value); - } - - /** - * set immunities from mobbase - */ - public void setImmuneTo(int immune) { - setImmuneTo(DamageType.Stun, ((immune & 1) != 0)); - setImmuneTo(DamageType.PowerBlock, ((immune & 2) != 0)); - setImmuneTo(DamageType.Drain, ((immune & 4) != 0)); - setImmuneTo(DamageType.Snare, ((immune & 8) != 0)); - setImmuneTo(DamageType.Siege, ((immune & 16) != 0)); - setImmuneTo(DamageType.Slash, ((immune & 32) != 0)); - setImmuneTo(DamageType.Crush, ((immune & 64) != 0)); - setImmuneTo(DamageType.Pierce, ((immune & 128) != 0)); - setImmuneTo(DamageType.Magic, ((immune & 256) != 0)); - setImmuneTo(DamageType.Bleed, ((immune & 512) != 0)); - setImmuneTo(DamageType.Poison, ((immune & 1024) != 0)); - setImmuneTo(DamageType.Mental, ((immune & 2048) != 0)); - setImmuneTo(DamageType.Holy, ((immune & 4096) != 0)); - setImmuneTo(DamageType.Unholy, ((immune & 8192) != 0)); - setImmuneTo(DamageType.Lightning, ((immune & 16384) != 0)); - setImmuneTo(DamageType.Fire, ((immune & 32768) != 0)); - setImmuneTo(DamageType.Cold, ((immune & 65536) != 0)); - setImmuneTo(DamageType.Steel, ((immune & 131072) != 0)); - } - - /** - * set/unset immuneTo - */ - public void setImmuneTo(DamageType type, boolean value) { - this.immuneTo.put(type, value); - } - - /** - * set immuneToAll - */ - public void setImmuneToAll(boolean value) { - this.immuneToAll = value; - } - - - /** - * set resists from mobbase - */ - public void setMobResists(int resistID) { - //TODO add this in later - //calls `static_npc_mob_resists` table WHERE `ID`='resistID' - } - - /** - * get Damage after resist - * Expects heals as negative damage and damage as positive damage for fortitudes. - */ - public float getResistedDamage(AbstractCharacter source, AbstractCharacter target, DamageType type, float damage, int trains) { - //handle fortitudes - damage = handleFortitude(target, type, damage); - //calculate armor piercing - float ap = source.getBonuses().getFloatPercentAll(ModType.ArmorPiercing,SourceType.None); - float damageAfterResists = damage * (1 - (this.getResist(type, trains) * 0.01f) + ap); - //check to see if any damage absorbers should cancel - if (target != null) { - //debug damage shields if any found - if (source.getDebug(2) && source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { - Effect da = target.getDamageAbsorber(); - if (da != null && da.getEffectsBase() != null) { - EffectsBase eb = da.getEffectsBase(); - String text = "Damage: " + damage + '\n'; - text += "Damage after resists: " + damageAfterResists + '\n'; - text += "Attack damage type: " + type.name() + '\n'; - text += "Fortitude damage types; " + eb.getDamageTypes() + '\n'; - text += "Fortitude damage before attack: " + da.getDamageAmount() + '\n'; - text += "Fortitude total health: " + eb.getDamageAmount(da.getTrains()) + '\n'; - text += "Fortitude trains: " + da.getTrains(); - ChatManager.chatSystemInfo((PlayerCharacter) source, text); - } - } - target.cancelOnTakeDamage(type, (damageAfterResists)); - } - return damageAfterResists; - } - - //Handle Fortitudes - private static float handleFortitude(AbstractCharacter target, DamageType type, float damage) { - if (target == null || !(target.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))) - return damage; - PlayerBonuses bonus = target.getBonuses(); - - //see if there is a fortitude - float damageCap = bonus.getFloatPercentAll(ModType.DamageCap, SourceType.None); - if (damageCap == 0f || type == DamageType.Healing) - return damage; - - //is fortitude, Are we under the cap? - float maxHealth = target.getHealthMax(); - float capFire = maxHealth * (damageCap); - if (damage < capFire) - return damage; - - //let's see if valid damagetype to apply it - boolean exclusive; - HashSet forts = bonus.getList(ModType.IgnoreDamageCap); - if (forts == null) { - exclusive = true; - forts = bonus.getList(ModType.ExclusiveDamageCap); - } else - exclusive = false; - if (forts == null || !isValidDamageCapType(forts, type, exclusive)) - return damage; - - float adjustedDamage = bonus.getFloatPercentAll(ModType.AdjustAboveDmgCap, SourceType.None); - //Adjust damage down and return new amount - float aadc = 1 +adjustedDamage; - return capFire * aadc; - } - - //Test if Damagetype is valid for foritude - private static boolean isValidDamageCapType(HashSet forts, DamageType damageType, boolean exclusive) { - for (SourceType fort: forts) { - DamageType dt = DamageType.valueOf(fort.name()); - - if (dt == DamageType.None) - continue; - - if (dt == damageType) { + private static ConcurrentHashMap mobResists = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private ConcurrentHashMap resists = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private ConcurrentHashMap immuneTo = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private DamageType protection; + private int protectionTrains = 0; + private boolean immuneToAll; + + /** + * Generic Constructor + */ + + public Resists(String type) { + switch (type) { + case "Building": + setBuildingResists(); + break; + case "Mine": + setMineResists(); + break; + default: + setGenericResists(); + break; + } + } + + public Resists(Resists r) { + for (DamageType dt : r.resists.keySet()) + this.resists.put(dt, r.resists.get(dt)); + for (DamageType dt : r.immuneTo.keySet()) + this.immuneTo.put(dt, r.immuneTo.get(dt)); + this.protection = r.protection; + this.protectionTrains = r.protectionTrains; + this.immuneToAll = r.immuneToAll; + } + + /** + * Generic Constructor for player + */ + public Resists(PlayerCharacter pc) { + setGenericResists(); + } + + public Resists(Mob mob) { + setGenericResists(); + } + + /** + * Called for mobBase when getting from the db fails + */ + public Resists(MobBase mobBase) { + setGenericResists(); + } + + /** + * Database Constructor + */ + public Resists(ResultSet rs) throws SQLException { + this.immuneToAll = false; + this.resists.put(DamageType.Slash, rs.getFloat("slash")); + this.resists.put(DamageType.Crush, rs.getFloat("crush")); + this.resists.put(DamageType.Pierce, rs.getFloat("pierce")); + this.resists.put(DamageType.Magic, rs.getFloat("magic")); + this.resists.put(DamageType.Bleed, rs.getFloat("bleed")); + this.resists.put(DamageType.Poison, rs.getFloat("poison")); + this.resists.put(DamageType.Mental, rs.getFloat("mental")); + this.resists.put(DamageType.Holy, rs.getFloat("holy")); + this.resists.put(DamageType.Unholy, rs.getFloat("unholy")); + this.resists.put(DamageType.Lightning, rs.getFloat("lightning")); + this.resists.put(DamageType.Fire, rs.getFloat("fire")); + this.resists.put(DamageType.Cold, rs.getFloat("cold")); + this.resists.put(DamageType.Healing, 0f); + } + + //Handle Fortitudes + private static float handleFortitude(AbstractCharacter target, DamageType type, float damage) { + if (target == null || !(target.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))) + return damage; + PlayerBonuses bonus = target.getBonuses(); + + //see if there is a fortitude + float damageCap = bonus.getFloatPercentAll(ModType.DamageCap, SourceType.None); + if (damageCap == 0f || type == DamageType.Healing) + return damage; + + //is fortitude, Are we under the cap? + float maxHealth = target.getHealthMax(); + float capFire = maxHealth * (damageCap); + if (damage < capFire) + return damage; + + //let's see if valid damagetype to apply it + boolean exclusive; + HashSet forts = bonus.getList(ModType.IgnoreDamageCap); + if (forts == null) { + exclusive = true; + forts = bonus.getList(ModType.ExclusiveDamageCap); + } else + exclusive = false; + if (forts == null || !isValidDamageCapType(forts, type, exclusive)) + return damage; + + float adjustedDamage = bonus.getFloatPercentAll(ModType.AdjustAboveDmgCap, SourceType.None); + //Adjust damage down and return new amount + float aadc = 1 + adjustedDamage; + return capFire * aadc; + } + + //Test if Damagetype is valid for foritude + private static boolean isValidDamageCapType(HashSet forts, DamageType damageType, boolean exclusive) { + for (SourceType fort : forts) { + DamageType dt = DamageType.valueOf(fort.name()); + + if (dt == DamageType.None) + continue; + + if (dt == damageType) { return exclusive; - } - } - return !exclusive; - } - - - /** - * Calculate Current Resists for Player - */ - public static void calculateResists(AbstractCharacter ac) { - if (ac.getResists() != null) - ac.getResists().calculateResists(ac, true); - else - Logger.error("Unable to find resists for character " + ac.getObjectUUID()); - } - - public void calculateResists(AbstractCharacter ac, boolean val) { - this.immuneTo.clear(); - - // get resists for runes - PlayerBonuses rb = ac.getBonuses(); - float slash = 0f, crush = 0f, pierce = 0f, magic = 0f, bleed = 0f, mental = 0f, holy = 0f, unholy = 0f, poison = 0f, lightning = 0f, fire = 0f, cold = 0f, healing = 0f; - - if (rb != null) { - // Handle immunities - if (rb.getBool(ModType.ImmuneTo, SourceType.Stun)) - this.immuneTo.put(DamageType.Stun, true); - if (rb.getBool(ModType.ImmuneTo, SourceType.Blind)) - this.immuneTo.put(DamageType.Blind, true); - if (rb.getBool(ModType.ImmuneToAttack, SourceType.None)) - this.immuneTo.put(DamageType.Attack, true); - if (rb.getBool(ModType.ImmuneToPowers, SourceType.None)) - this.immuneTo.put(DamageType.Powers, true); - if (rb.getBool(ModType.ImmuneTo, SourceType.Powerblock)) - this.immuneTo.put(DamageType.Powerblock, true); - if (rb.getBool(ModType.ImmuneTo, SourceType.DeBuff)) - this.immuneTo.put(DamageType.DeBuff, true); - if (rb.getBool(ModType.ImmuneTo, SourceType.Fear)) - this.immuneTo.put(DamageType.Fear, true); - if (rb.getBool(ModType.ImmuneTo, SourceType.Charm)) - this.immuneTo.put(DamageType.Charm, true); - if (rb.getBool(ModType.ImmuneTo, SourceType.Root)) - this.immuneTo.put(DamageType.Root, true); - if (rb.getBool(ModType.ImmuneTo, SourceType.Snare)) - this.immuneTo.put(DamageType.Snare, true); - - // Handle resists - slash += rb.getFloat(ModType.Resistance, SourceType.Slash); - crush += rb.getFloat(ModType.Resistance, SourceType.Crush); - pierce += rb.getFloat(ModType.Resistance, SourceType.Pierce); - magic += rb.getFloat(ModType.Resistance, SourceType.Magic); - bleed += rb.getFloat(ModType.Resistance, SourceType.Bleed); - poison += rb.getFloat(ModType.Resistance, SourceType.Poison); - mental += rb.getFloat(ModType.Resistance, SourceType.Mental); - holy += rb.getFloat(ModType.Resistance, SourceType.Holy); - unholy += rb.getFloat(ModType.Resistance, SourceType.Unholy); - lightning += rb.getFloat(ModType.Resistance, SourceType.Lightning); - fire += rb.getFloat(ModType.Resistance, SourceType.Fire); - cold += rb.getFloat(ModType.Resistance, SourceType.Cold); - healing += rb.getFloat(ModType.Resistance, SourceType.Healing); // DamageType.Healing.name()); - - //HHO + } + } + return !exclusive; + } + + /** + * Calculate Current Resists for Player + */ + public static void calculateResists(AbstractCharacter ac) { + if (ac.getResists() != null) + ac.getResists().calculateResists(ac, true); + else + Logger.error("Unable to find resists for character " + ac.getObjectUUID()); + } + + private static float[] getArmorResists(Item armor, float[] phys) { + if (armor == null) + return phys; + ItemBase ab = armor.getItemBase(); + if (ab == null) + return phys; + phys[0] += ab.getSlashResist(); + phys[1] += ab.getCrushResist(); + phys[2] += ab.getPierceResist(); + return phys; + } + + /** + * Get mob resists from db if there, otherwise set defaults + */ + public static Resists getResists(int resistID) { + //check cache first + if (mobResists.containsKey(resistID)) + return new Resists(mobResists.get(resistID)); + + //get from database + Resists resists = DbManager.ResistQueries.GET_RESISTS_FOR_MOB(resistID); + if (resists != null) { + mobResists.put(resistID, resists); + return new Resists(resists); + } + + //failed, may want to debug this + return null; + } + + /** + * Create generic resists for buildings + */ + public final void setBuildingResists() { + this.immuneToAll = false; + this.resists.put(DamageType.Slash, 85f); + this.resists.put(DamageType.Crush, 85f); + this.resists.put(DamageType.Siege, 0f); + this.immuneTo.put(DamageType.Pierce, true); + this.immuneTo.put(DamageType.Magic, true); + this.immuneTo.put(DamageType.Bleed, true); + this.immuneTo.put(DamageType.Poison, true); + this.immuneTo.put(DamageType.Mental, true); + this.immuneTo.put(DamageType.Holy, true); + this.immuneTo.put(DamageType.Unholy, true); + this.immuneTo.put(DamageType.Lightning, true); + this.immuneTo.put(DamageType.Fire, true); + this.immuneTo.put(DamageType.Cold, true); + + } + + /** + * Create generic resists for mines + */ + public final void setMineResists() { + this.immuneToAll = false; + this.immuneTo.put(DamageType.Slash, true); + this.immuneTo.put(DamageType.Crush, true); + this.immuneTo.put(DamageType.Pierce, true); + this.immuneTo.put(DamageType.Magic, true); + this.immuneTo.put(DamageType.Bleed, true); + this.immuneTo.put(DamageType.Poison, true); + this.immuneTo.put(DamageType.Mental, true); + this.immuneTo.put(DamageType.Holy, true); + this.immuneTo.put(DamageType.Unholy, true); + this.immuneTo.put(DamageType.Lightning, true); + this.immuneTo.put(DamageType.Fire, true); + this.immuneTo.put(DamageType.Cold, true); + this.resists.put(DamageType.Siege, 0f); + } + + /** + * Create generic resists + */ + public final void setGenericResists() { + this.immuneToAll = false; + this.resists.put(DamageType.Slash, 0f); + this.resists.put(DamageType.Crush, 0f); + this.resists.put(DamageType.Pierce, 0f); + this.resists.put(DamageType.Magic, 0f); + this.resists.put(DamageType.Bleed, 0f); + this.resists.put(DamageType.Poison, 0f); + this.resists.put(DamageType.Mental, 0f); + this.resists.put(DamageType.Holy, 0f); + this.resists.put(DamageType.Unholy, 0f); + this.resists.put(DamageType.Lightning, 0f); + this.resists.put(DamageType.Fire, 0f); + this.resists.put(DamageType.Cold, 0f); + this.resists.put(DamageType.Healing, 0f); + this.immuneTo.put(DamageType.Siege, true); + + } + + /** + * Get a resist + */ + public float getResist(DamageType type, int trains) { + //get resisted amount + Float amount = 0f; + if (this.resists.containsKey(type)) + amount = this.resists.get(type); + + //add protection + if (trains > 0 && protection != null && type.equals(this.protection)) { + float prot = 50 + this.protectionTrains - trains; + amount += (prot >= 0) ? prot : 0; + } + + if (amount == null) + return 0f; + if (amount > 75f) + return 75f; + return amount; + } + + /** + * get immuneTo + */ + public boolean immuneTo(DamageType type) { + if (this.immuneTo.containsKey(type)) + return this.immuneTo.get(type); + else + return false; + } + + /** + * get immuneToAll + */ + public boolean immuneToAll() { + return this.immuneToAll; + } + + public boolean immuneToPowers() { + return immuneTo(DamageType.Powers); + } + + public boolean immuneToAttacks() { + return immuneTo(DamageType.Attack); + } + + public boolean immuneToSpires() { + return immuneTo(DamageType.Spires); + } + + /** + * gets immuneTo(type) and immuneToAll + */ + public boolean isImmune(DamageType type) { + if (this.immuneToAll) + return true; + return this.immuneTo(type); + } + + /** + * Set a resist + */ + public void setResist(DamageType type, float value) { + this.resists.put(type, value); + } + + /** + * add to a resist + */ + public void incResist(DamageType type, float value) { + Float amount = this.resists.get(type); + if (amount == null) + this.resists.put(type, value); + else + this.resists.put(type, amount + value); + } + + /** + * subtract from a resist + */ + public void decResist(DamageType type, float value) { + Float amount = this.resists.get(type); + if (amount == null) + this.resists.put(type, (0 - value)); + else + this.resists.put(type, amount - value); + } + + /** + * set immunities from mobbase + */ + public void setImmuneTo(int immune) { + setImmuneTo(DamageType.Stun, ((immune & 1) != 0)); + setImmuneTo(DamageType.PowerBlock, ((immune & 2) != 0)); + setImmuneTo(DamageType.Drain, ((immune & 4) != 0)); + setImmuneTo(DamageType.Snare, ((immune & 8) != 0)); + setImmuneTo(DamageType.Siege, ((immune & 16) != 0)); + setImmuneTo(DamageType.Slash, ((immune & 32) != 0)); + setImmuneTo(DamageType.Crush, ((immune & 64) != 0)); + setImmuneTo(DamageType.Pierce, ((immune & 128) != 0)); + setImmuneTo(DamageType.Magic, ((immune & 256) != 0)); + setImmuneTo(DamageType.Bleed, ((immune & 512) != 0)); + setImmuneTo(DamageType.Poison, ((immune & 1024) != 0)); + setImmuneTo(DamageType.Mental, ((immune & 2048) != 0)); + setImmuneTo(DamageType.Holy, ((immune & 4096) != 0)); + setImmuneTo(DamageType.Unholy, ((immune & 8192) != 0)); + setImmuneTo(DamageType.Lightning, ((immune & 16384) != 0)); + setImmuneTo(DamageType.Fire, ((immune & 32768) != 0)); + setImmuneTo(DamageType.Cold, ((immune & 65536) != 0)); + setImmuneTo(DamageType.Steel, ((immune & 131072) != 0)); + } + + /** + * set/unset immuneTo + */ + public void setImmuneTo(DamageType type, boolean value) { + this.immuneTo.put(type, value); + } + + /** + * set immuneToAll + */ + public void setImmuneToAll(boolean value) { + this.immuneToAll = value; + } + + /** + * set resists from mobbase + */ + public void setMobResists(int resistID) { + //TODO add this in later + //calls `static_npc_mob_resists` table WHERE `ID`='resistID' + } + + /** + * get Damage after resist + * Expects heals as negative damage and damage as positive damage for fortitudes. + */ + public float getResistedDamage(AbstractCharacter source, AbstractCharacter target, DamageType type, float damage, int trains) { + //handle fortitudes + damage = handleFortitude(target, type, damage); + //calculate armor piercing + float ap = source.getBonuses().getFloatPercentAll(ModType.ArmorPiercing, SourceType.None); + float damageAfterResists = damage * (1 - (this.getResist(type, trains) * 0.01f) + ap); + //check to see if any damage absorbers should cancel + if (target != null) { + //debug damage shields if any found + if (source.getDebug(2) && source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { + Effect da = target.getDamageAbsorber(); + if (da != null && da.getEffectsBase() != null) { + EffectsBase eb = da.getEffectsBase(); + String text = "Damage: " + damage + '\n'; + text += "Damage after resists: " + damageAfterResists + '\n'; + text += "Attack damage type: " + type.name() + '\n'; + text += "Fortitude damage types; " + eb.getDamageTypes() + '\n'; + text += "Fortitude damage before attack: " + da.getDamageAmount() + '\n'; + text += "Fortitude total health: " + eb.getDamageAmount(da.getTrains()) + '\n'; + text += "Fortitude trains: " + da.getTrains(); + ChatManager.chatSystemInfo((PlayerCharacter) source, text); + } + } + target.cancelOnTakeDamage(type, (damageAfterResists)); + } + return damageAfterResists; + } + + public void calculateResists(AbstractCharacter ac, boolean val) { + this.immuneTo.clear(); + + // get resists for runes + PlayerBonuses rb = ac.getBonuses(); + float slash = 0f, crush = 0f, pierce = 0f, magic = 0f, bleed = 0f, mental = 0f, holy = 0f, unholy = 0f, poison = 0f, lightning = 0f, fire = 0f, cold = 0f, healing = 0f; + + if (rb != null) { + // Handle immunities + if (rb.getBool(ModType.ImmuneTo, SourceType.Stun)) + this.immuneTo.put(DamageType.Stun, true); + if (rb.getBool(ModType.ImmuneTo, SourceType.Blind)) + this.immuneTo.put(DamageType.Blind, true); + if (rb.getBool(ModType.ImmuneToAttack, SourceType.None)) + this.immuneTo.put(DamageType.Attack, true); + if (rb.getBool(ModType.ImmuneToPowers, SourceType.None)) + this.immuneTo.put(DamageType.Powers, true); + if (rb.getBool(ModType.ImmuneTo, SourceType.Powerblock)) + this.immuneTo.put(DamageType.Powerblock, true); + if (rb.getBool(ModType.ImmuneTo, SourceType.DeBuff)) + this.immuneTo.put(DamageType.DeBuff, true); + if (rb.getBool(ModType.ImmuneTo, SourceType.Fear)) + this.immuneTo.put(DamageType.Fear, true); + if (rb.getBool(ModType.ImmuneTo, SourceType.Charm)) + this.immuneTo.put(DamageType.Charm, true); + if (rb.getBool(ModType.ImmuneTo, SourceType.Root)) + this.immuneTo.put(DamageType.Root, true); + if (rb.getBool(ModType.ImmuneTo, SourceType.Snare)) + this.immuneTo.put(DamageType.Snare, true); + + // Handle resists + slash += rb.getFloat(ModType.Resistance, SourceType.Slash); + crush += rb.getFloat(ModType.Resistance, SourceType.Crush); + pierce += rb.getFloat(ModType.Resistance, SourceType.Pierce); + magic += rb.getFloat(ModType.Resistance, SourceType.Magic); + bleed += rb.getFloat(ModType.Resistance, SourceType.Bleed); + poison += rb.getFloat(ModType.Resistance, SourceType.Poison); + mental += rb.getFloat(ModType.Resistance, SourceType.Mental); + holy += rb.getFloat(ModType.Resistance, SourceType.Holy); + unholy += rb.getFloat(ModType.Resistance, SourceType.Unholy); + lightning += rb.getFloat(ModType.Resistance, SourceType.Lightning); + fire += rb.getFloat(ModType.Resistance, SourceType.Fire); + cold += rb.getFloat(ModType.Resistance, SourceType.Cold); + healing += rb.getFloat(ModType.Resistance, SourceType.Healing); // DamageType.Healing.name()); + + //HHO // String protectionString = rb.getString("protection"); // @@ -448,116 +478,85 @@ public class Resists { // this.protection = null; // } // this.protectionTrains = rb.getFloat("protection"); - } - - // get resists from equipment - if (ac.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { - if (ac.getCharItemManager() != null && ac.getCharItemManager().getEquipped() != null) { - float[] phys = { 0f, 0f, 0f }; - ConcurrentHashMap equip = ac.getCharItemManager().getEquipped(); - - // get base physical resists - phys = Resists.getArmorResists(equip.get(MBServerStatics.SLOT_HELMET), phys); - phys = Resists.getArmorResists(equip.get(MBServerStatics.SLOT_CHEST), phys); - phys = Resists.getArmorResists(equip.get(MBServerStatics.SLOT_ARMS), phys); - phys = Resists.getArmorResists(equip.get(MBServerStatics.SLOT_GLOVES), phys); - phys = Resists.getArmorResists(equip.get(MBServerStatics.SLOT_LEGGINGS), phys); - phys = Resists.getArmorResists(equip.get(MBServerStatics.SLOT_FEET), phys); - slash += phys[0]; - crush += phys[1]; - pierce += phys[2]; - - } - } - - this.resists.put(DamageType.Slash, slash); - this.resists.put(DamageType.Crush, crush); - this.resists.put(DamageType.Pierce, pierce); - this.resists.put(DamageType.Magic, magic); - this.resists.put(DamageType.Bleed, bleed); - this.resists.put(DamageType.Poison, poison); - this.resists.put(DamageType.Mental, mental); - this.resists.put(DamageType.Holy, holy); - this.resists.put(DamageType.Unholy, unholy); - this.resists.put(DamageType.Lightning, lightning); - this.resists.put(DamageType.Fire, fire); - this.resists.put(DamageType.Cold, cold); - this.resists.put(DamageType.Healing, healing); - - this.immuneTo.put(DamageType.Siege, true); - - // debug printing of resists - // printResists(pc); - } - - private static float[] getArmorResists(Item armor, float[] phys) { - if (armor == null) - return phys; - ItemBase ab = armor.getItemBase(); - if (ab == null) - return phys; - phys[0] += ab.getSlashResist(); - phys[1] += ab.getCrushResist(); - phys[2] += ab.getPierceResist(); - return phys; - } - - public void printResistsToClient(PlayerCharacter pc) { - for (DamageType dt : resists.keySet()) - ChatManager.chatSystemInfo(pc, " resist." + dt.name() + ": " + resists.get(dt)); - for (DamageType dt : immuneTo.keySet()) - ChatManager.chatSystemInfo(pc, " immuneTo." + dt.name() + ": " + immuneTo.get(dt)); - ChatManager.chatSystemInfo(pc, " immuneToAll: " + this.immuneToAll); - if (protection != null) - ChatManager.chatSystemInfo(pc, " Protection: " + protection.name() + ", Trains: " + protectionTrains); - else - ChatManager.chatSystemInfo(pc, " Protection: None"); - } - - public String getResists(PlayerCharacter pc) { - String out = pc.getName(); - - out += "Resists: "; - Iterator it = this.resists.keySet().iterator(); - while (it.hasNext()) { - DamageType damType = it.next(); - String dtName = damType.name(); - out += dtName + '=' + this.resists.get(dtName) + ", "; - } - - out += "ImmuneTo: "; - it = this.immuneTo.keySet().iterator(); - while (it.hasNext()) { - DamageType damType = it.next(); - - String dtName = damType.name(); - out += dtName + '=' + this.resists.get(dtName) + ", "; - } - - if (protection != null) - out += "Protection: " + protection.name() + ", Trains: " + protectionTrains; - else - out += "Protection: none"; - - return out; - } - - /** - * Get mob resists from db if there, otherwise set defaults - */ - public static Resists getResists(int resistID) { - //check cache first - if (mobResists.containsKey(resistID)) - return new Resists(mobResists.get(resistID)); - - //get from database - Resists resists = DbManager.ResistQueries.GET_RESISTS_FOR_MOB(resistID); - if (resists != null) { - mobResists.put(resistID, resists); - return new Resists(resists); - } - - //failed, may want to debug this - return null; - } + } + + // get resists from equipment + if (ac.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { + if (ac.getCharItemManager() != null && ac.getCharItemManager().getEquipped() != null) { + float[] phys = {0f, 0f, 0f}; + ConcurrentHashMap equip = ac.getCharItemManager().getEquipped(); + + // get base physical resists + phys = Resists.getArmorResists(equip.get(MBServerStatics.SLOT_HELMET), phys); + phys = Resists.getArmorResists(equip.get(MBServerStatics.SLOT_CHEST), phys); + phys = Resists.getArmorResists(equip.get(MBServerStatics.SLOT_ARMS), phys); + phys = Resists.getArmorResists(equip.get(MBServerStatics.SLOT_GLOVES), phys); + phys = Resists.getArmorResists(equip.get(MBServerStatics.SLOT_LEGGINGS), phys); + phys = Resists.getArmorResists(equip.get(MBServerStatics.SLOT_FEET), phys); + slash += phys[0]; + crush += phys[1]; + pierce += phys[2]; + + } + } + + this.resists.put(DamageType.Slash, slash); + this.resists.put(DamageType.Crush, crush); + this.resists.put(DamageType.Pierce, pierce); + this.resists.put(DamageType.Magic, magic); + this.resists.put(DamageType.Bleed, bleed); + this.resists.put(DamageType.Poison, poison); + this.resists.put(DamageType.Mental, mental); + this.resists.put(DamageType.Holy, holy); + this.resists.put(DamageType.Unholy, unholy); + this.resists.put(DamageType.Lightning, lightning); + this.resists.put(DamageType.Fire, fire); + this.resists.put(DamageType.Cold, cold); + this.resists.put(DamageType.Healing, healing); + + this.immuneTo.put(DamageType.Siege, true); + + // debug printing of resists + // printResists(pc); + } + + public void printResistsToClient(PlayerCharacter pc) { + for (DamageType dt : resists.keySet()) + ChatManager.chatSystemInfo(pc, " resist." + dt.name() + ": " + resists.get(dt)); + for (DamageType dt : immuneTo.keySet()) + ChatManager.chatSystemInfo(pc, " immuneTo." + dt.name() + ": " + immuneTo.get(dt)); + ChatManager.chatSystemInfo(pc, " immuneToAll: " + this.immuneToAll); + if (protection != null) + ChatManager.chatSystemInfo(pc, " Protection: " + protection.name() + ", Trains: " + protectionTrains); + else + ChatManager.chatSystemInfo(pc, " Protection: None"); + } + + public String getResists(PlayerCharacter pc) { + String out = pc.getName(); + + out += "Resists: "; + Iterator it = this.resists.keySet().iterator(); + while (it.hasNext()) { + DamageType damType = it.next(); + String dtName = damType.name(); + out += dtName + '=' + this.resists.get(dtName) + ", "; + } + + out += "ImmuneTo: "; + it = this.immuneTo.keySet().iterator(); + while (it.hasNext()) { + DamageType damType = it.next(); + + String dtName = damType.name(); + out += dtName + '=' + this.resists.get(dtName) + ", "; + } + + if (protection != null) + out += "Protection: " + protection.name() + ", Trains: " + protectionTrains; + else + out += "Protection: none"; + + return out; + } } diff --git a/src/engine/objects/Resource.java b/src/engine/objects/Resource.java index e8b72cd4..995cecf5 100644 --- a/src/engine/objects/Resource.java +++ b/src/engine/objects/Resource.java @@ -15,55 +15,56 @@ import java.util.concurrent.ConcurrentHashMap; public enum Resource { - ADAMANT("DefaultAdamant", 1557001525, 10, 1580003), - AGATE("DefaultAgate", -1096157543, 20, 1580009), - ANTIMONY("DefaultAntimony", 1256147265, 10, 1580014), - AZOTH("DefaultAzoth", -1205326951, 20, 1580012), - BLOODSTONE("DefaultBloodstone", -1912381716, 5, 1580020), - BRONZEWOOD("DefaultBronzewood", -519681813, 30, 1580006), - COAL("DefaultCoal", -1672872311, 30, 1580008), - DIAMOND("DefaultDiamond", 1540225085, 20, 1580010), - GALVOR("DefaultGalvor", -1683992404, 5, 1580017), - IRON("DefaultIron", -1673518119, 20, 1580002), - LUMBER("DefaultLumber", -1628412684, 100, 1580004), - MANDRAKE("DefaultMandrake", -1519910613, 10, 1580007), - MITHRIL("DefaultMithril", 626743397, 5, 1580021), - OAK("DefaultOak", -1653034775, 30, 1580005), - OBSIDIAN("DefaultObsidian", 778019055, 5, 1580019), - ONYX("DefaultOnyx", -1675952151, 10, 1580011), - ORICHALK("DefaultOrichalk", -1468730955, 30, 1580013), - QUICKSILVER("DefaultQuicksilver", -2081208434, 10, 1580016), - STONE("DefaultStone", -1094703863, 100, 1580000), - SULFUR("DefaultSulfur", -1763687412, 10, 1580015), - TRUESTEEL("DefaultTruesteel", -169012482, 20, 1580001), - WORMWOOD("DefaultWormwood", 1204785075, 5, 1580018), - GOLD("DefaultGold", -1670881623, 50000, 7); + ADAMANT("DefaultAdamant", 1557001525, 10, 1580003), + AGATE("DefaultAgate", -1096157543, 20, 1580009), + ANTIMONY("DefaultAntimony", 1256147265, 10, 1580014), + AZOTH("DefaultAzoth", -1205326951, 20, 1580012), + BLOODSTONE("DefaultBloodstone", -1912381716, 5, 1580020), + BRONZEWOOD("DefaultBronzewood", -519681813, 30, 1580006), + COAL("DefaultCoal", -1672872311, 30, 1580008), + DIAMOND("DefaultDiamond", 1540225085, 20, 1580010), + GALVOR("DefaultGalvor", -1683992404, 5, 1580017), + IRON("DefaultIron", -1673518119, 20, 1580002), + LUMBER("DefaultLumber", -1628412684, 100, 1580004), + MANDRAKE("DefaultMandrake", -1519910613, 10, 1580007), + MITHRIL("DefaultMithril", 626743397, 5, 1580021), + OAK("DefaultOak", -1653034775, 30, 1580005), + OBSIDIAN("DefaultObsidian", 778019055, 5, 1580019), + ONYX("DefaultOnyx", -1675952151, 10, 1580011), + ORICHALK("DefaultOrichalk", -1468730955, 30, 1580013), + QUICKSILVER("DefaultQuicksilver", -2081208434, 10, 1580016), + STONE("DefaultStone", -1094703863, 100, 1580000), + SULFUR("DefaultSulfur", -1763687412, 10, 1580015), + TRUESTEEL("DefaultTruesteel", -169012482, 20, 1580001), + WORMWOOD("DefaultWormwood", 1204785075, 5, 1580018), + GOLD("DefaultGold", -1670881623, 50000, 7); - public final String name; - public final int hash; - public final int baseProduction; - public final int UUID; - public static ConcurrentHashMap resourceByHash; + public static ConcurrentHashMap resourceByHash; - Resource(String name, int hash, int baseProduction, int uuid) { - this.name = name; - this.hash = hash; - this.baseProduction = baseProduction; - this.UUID = uuid; - } - - public static Resource GetResourceByHash(int hash){ - for (Resource resource: Resource.values()){ - if (hash == resource.hash) - return resource; - } - return Resource.MITHRIL; - } - - //load lookups via hashes - static { + //load lookups via hashes + static { resourceByHash = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); for (Resource r : Resource.values()) resourceByHash.put(r.hash, r); } + + public final String name; + public final int hash; + public final int baseProduction; + public final int UUID; + + Resource(String name, int hash, int baseProduction, int uuid) { + this.name = name; + this.hash = hash; + this.baseProduction = baseProduction; + this.UUID = uuid; + } + + public static Resource GetResourceByHash(int hash) { + for (Resource resource : Resource.values()) { + if (hash == resource.hash) + return resource; + } + return Resource.MITHRIL; + } } diff --git a/src/engine/objects/RuneBase.java b/src/engine/objects/RuneBase.java index 9738b4bc..39950a6b 100644 --- a/src/engine/objects/RuneBase.java +++ b/src/engine/objects/RuneBase.java @@ -23,195 +23,193 @@ import java.util.concurrent.ConcurrentHashMap; public class RuneBase extends AbstractGameObject { - private final String name; - private final String description; - private final int type; - private final byte subtype; - - private final ConcurrentHashMap race = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private final ConcurrentHashMap baseClass = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private final ConcurrentHashMap promotionClass = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private final ConcurrentHashMap discipline = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private final ArrayList overwrite = new ArrayList<>(); - private int levelRequired = 1; - - private ArrayList effectsList = new ArrayList<>(); - - public static HashMap> AllowedBaseClassRunesMap = new HashMap<>(); - public static HashMap> AllowedRaceRunesMap = new HashMap<>(); - /** - * No Table ID Constructor - */ - public RuneBase(String name, String description, int type, byte subtype, ArrayList attrs) { - super(); - - this.name = name; - this.description = description; - this.type = type; - this.subtype = subtype; - - } - - /** - * Normal Constructor - */ - public RuneBase(String name, String description, int type, byte subtype, ArrayList attrs, int newUUID) { - super(newUUID); - - this.name = name; - this.description = description; - this.type = type; - this.subtype = subtype; - - } - - /** - * ResultSet Constructor - */ - public RuneBase(ResultSet rs) throws SQLException { - super(rs); - - this.name = rs.getString("name"); - this.description = rs.getString("description"); - this.type = rs.getInt("type"); - this.subtype = rs.getByte("subtype"); - - DbManager.RuneBaseQueries.GET_RUNE_REQS(this); - this.effectsList = DbManager.MobBaseQueries.GET_RUNEBASE_EFFECTS(this.getObjectUUID()); - } - - @Override - public boolean equals(Object obj) { - - if (!super.equals(obj)) { - return false; - } - - if(obj instanceof RuneBase) { - RuneBase rbObj = (RuneBase) obj; - if (!this.name.equals(rbObj.name)) { - return false; - } - - if (!this.description.equals(rbObj.description)) { - return false; - } - - if (this.type != rbObj.type) { - return false; - } - - if (this.subtype != rbObj.subtype) { - return false; - } - - - return true; - } - - return false; - } - - /* - * Getters - */ - public String getName() { - return name; - } - - public String getDescription() { - return description; - } - - public int getType() { - return type; - } - - /** - * @return the subtype - */ - public byte getSubtype() { - return subtype; - } - - /** - * @return the attrs - */ - public ArrayList getAttrs() { - return RuneBaseAttribute.runeBaseAttributeMap.get(this.getObjectUUID()); - } - - public ConcurrentHashMap getRace() { - return this.race; - } - - public ConcurrentHashMap getBaseClass() { - return this.baseClass; - } - - public ConcurrentHashMap getPromotionClass() { - return this.promotionClass; - } - - public ConcurrentHashMap getDiscipline() { - return this.discipline; - } - - public ArrayList getOverwrite() { - return this.overwrite; - } - - public int getLevelRequired() { - return this.levelRequired; - } - - public void setLevelRequired(int levelRequired) { - this.levelRequired = levelRequired; - } - - public static RuneBase getRuneBase(int tableId) { - - if (tableId == 0) - return null; - - RuneBase rb = (RuneBase) DbManager.getFromCache(Enum.GameObjectType.RuneBase, tableId); - - if (rb != null) - return rb; - - return DbManager.RuneBaseQueries.GET_RUNEBASE(tableId); - } - - /* - * Serializing - */ - - public static void serializeForClientMsg(RuneBase runeBase,ByteBufferWriter writer) { - writer.putInt(runeBase.type); - writer.putInt(0); // Pad - writer.putInt(runeBase.getObjectUUID()); - writer.putInt(runeBase.getObjectType().ordinal()); - writer.putInt(runeBase.getObjectUUID()); - - } - - @Override - public void updateDatabase() { - // TODO Auto-generated method stub - } - - /** - * @return the effectsList - */ - public ArrayList getEffectsList() { - return effectsList; - } - - public static void LoadAllRuneBases(){ - - DbManager.RuneBaseQueries.LOAD_ALL_RUNEBASES(); - RuneBase.AllowedBaseClassRunesMap = DbManager.RuneBaseQueries.LOAD_ALLOWED_STARTING_RUNES_FOR_BASECLASS(); - RuneBase.AllowedRaceRunesMap = DbManager.RuneBaseQueries.LOAD_ALLOWED_STARTING_RUNES_FOR_RACE(); - } + public static HashMap> AllowedBaseClassRunesMap = new HashMap<>(); + public static HashMap> AllowedRaceRunesMap = new HashMap<>(); + private final String name; + private final String description; + private final int type; + private final byte subtype; + private final ConcurrentHashMap race = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private final ConcurrentHashMap baseClass = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private final ConcurrentHashMap promotionClass = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private final ConcurrentHashMap discipline = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private final ArrayList overwrite = new ArrayList<>(); + private int levelRequired = 1; + private ArrayList effectsList = new ArrayList<>(); + + /** + * No Table ID Constructor + */ + public RuneBase(String name, String description, int type, byte subtype, ArrayList attrs) { + super(); + + this.name = name; + this.description = description; + this.type = type; + this.subtype = subtype; + + } + + /** + * Normal Constructor + */ + public RuneBase(String name, String description, int type, byte subtype, ArrayList attrs, int newUUID) { + super(newUUID); + + this.name = name; + this.description = description; + this.type = type; + this.subtype = subtype; + + } + + /** + * ResultSet Constructor + */ + public RuneBase(ResultSet rs) throws SQLException { + super(rs); + + this.name = rs.getString("name"); + this.description = rs.getString("description"); + this.type = rs.getInt("type"); + this.subtype = rs.getByte("subtype"); + + DbManager.RuneBaseQueries.GET_RUNE_REQS(this); + this.effectsList = DbManager.MobBaseQueries.GET_RUNEBASE_EFFECTS(this.getObjectUUID()); + } + + public static RuneBase getRuneBase(int tableId) { + + if (tableId == 0) + return null; + + RuneBase rb = (RuneBase) DbManager.getFromCache(Enum.GameObjectType.RuneBase, tableId); + + if (rb != null) + return rb; + + return DbManager.RuneBaseQueries.GET_RUNEBASE(tableId); + } + + public static void serializeForClientMsg(RuneBase runeBase, ByteBufferWriter writer) { + writer.putInt(runeBase.type); + writer.putInt(0); // Pad + writer.putInt(runeBase.getObjectUUID()); + writer.putInt(runeBase.getObjectType().ordinal()); + writer.putInt(runeBase.getObjectUUID()); + + } + + public static void LoadAllRuneBases() { + + DbManager.RuneBaseQueries.LOAD_ALL_RUNEBASES(); + RuneBase.AllowedBaseClassRunesMap = DbManager.RuneBaseQueries.LOAD_ALLOWED_STARTING_RUNES_FOR_BASECLASS(); + RuneBase.AllowedRaceRunesMap = DbManager.RuneBaseQueries.LOAD_ALLOWED_STARTING_RUNES_FOR_RACE(); + } + + @Override + public boolean equals(Object obj) { + + if (!super.equals(obj)) { + return false; + } + + if (obj instanceof RuneBase) { + RuneBase rbObj = (RuneBase) obj; + if (!this.name.equals(rbObj.name)) { + return false; + } + + if (!this.description.equals(rbObj.description)) { + return false; + } + + if (this.type != rbObj.type) { + return false; + } + + if (this.subtype != rbObj.subtype) { + return false; + } + + + return true; + } + + return false; + } + + /* + * Getters + */ + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public int getType() { + return type; + } + + /** + * @return the subtype + */ + public byte getSubtype() { + return subtype; + } + + /** + * @return the attrs + */ + public ArrayList getAttrs() { + return RuneBaseAttribute.runeBaseAttributeMap.get(this.getObjectUUID()); + } + + public ConcurrentHashMap getRace() { + return this.race; + } + + public ConcurrentHashMap getBaseClass() { + return this.baseClass; + } + + public ConcurrentHashMap getPromotionClass() { + return this.promotionClass; + } + + public ConcurrentHashMap getDiscipline() { + return this.discipline; + } + + public ArrayList getOverwrite() { + return this.overwrite; + } + + /* + * Serializing + */ + + public int getLevelRequired() { + return this.levelRequired; + } + + public void setLevelRequired(int levelRequired) { + this.levelRequired = levelRequired; + } + + @Override + public void updateDatabase() { + // TODO Auto-generated method stub + } + + /** + * @return the effectsList + */ + public ArrayList getEffectsList() { + return effectsList; + } } diff --git a/src/engine/objects/RuneBaseAttribute.java b/src/engine/objects/RuneBaseAttribute.java index 5ea74162..82e93b22 100644 --- a/src/engine/objects/RuneBaseAttribute.java +++ b/src/engine/objects/RuneBaseAttribute.java @@ -20,88 +20,84 @@ import java.util.HashMap; public class RuneBaseAttribute extends AbstractGameObject { - private short attributeID; - private short modValue; - - private int runeBaseID; - - public static HashMap> runeBaseAttributeMap = new HashMap<>(); - - - /** - * No Table ID Constructor - */ - public RuneBaseAttribute(short attributeID, short modValue) { - super(); - - this.attributeID = attributeID; - this.modValue = modValue; - } - - /** - * Normal - */ - public RuneBaseAttribute(short attributeID, short modValue, int newUUID) { - super(newUUID); - - this.attributeID = attributeID; - this.modValue = modValue; - } - /** - * ResultSet Constructor - */ - public RuneBaseAttribute(ResultSet rs) throws SQLException { - super(rs); - - this.attributeID = rs.getShort("attributeID"); - this.modValue = rs.getShort("modValue"); - this.runeBaseID = rs.getInt("RuneBaseID"); - } - - /* - * Getters - */ - public short getAttributeID() { - return attributeID; - } - - public short getModValue() { - return modValue; - } - - public static void LoadAllAttributes(){ - DbManager.RuneBaseAttributeQueries.GET_ATTRIBUTES_FOR_RUNEBASE(); - - - //cache attributeLists for rune. - for (AbstractGameObject ago : DbManager.getList(GameObjectType.RuneBaseAttribute)){ - - RuneBaseAttribute runeBaseAttribute = (RuneBaseAttribute)ago; - - int runeBaseID = ((RuneBaseAttribute)runeBaseAttribute).runeBaseID; - if (runeBaseAttributeMap.get(runeBaseID) == null){ - ArrayList attributeList = new ArrayList<>(); - attributeList.add(runeBaseAttribute); - runeBaseAttributeMap.put(runeBaseID, attributeList); - } - else{ - ArrayListattributeList = runeBaseAttributeMap.get(runeBaseID); - attributeList.add(runeBaseAttribute); - runeBaseAttributeMap.put(runeBaseID, attributeList); - } - - } - - } - - /* - * Utils - */ - - - - @Override - public void updateDatabase() { - // TODO Auto-generated method stub - } + public static HashMap> runeBaseAttributeMap = new HashMap<>(); + private short attributeID; + private short modValue; + private int runeBaseID; + + + /** + * No Table ID Constructor + */ + public RuneBaseAttribute(short attributeID, short modValue) { + super(); + + this.attributeID = attributeID; + this.modValue = modValue; + } + + /** + * Normal + */ + public RuneBaseAttribute(short attributeID, short modValue, int newUUID) { + super(newUUID); + + this.attributeID = attributeID; + this.modValue = modValue; + } + + /** + * ResultSet Constructor + */ + public RuneBaseAttribute(ResultSet rs) throws SQLException { + super(rs); + + this.attributeID = rs.getShort("attributeID"); + this.modValue = rs.getShort("modValue"); + this.runeBaseID = rs.getInt("RuneBaseID"); + } + + public static void LoadAllAttributes() { + DbManager.RuneBaseAttributeQueries.GET_ATTRIBUTES_FOR_RUNEBASE(); + + + //cache attributeLists for rune. + for (AbstractGameObject ago : DbManager.getList(GameObjectType.RuneBaseAttribute)) { + + RuneBaseAttribute runeBaseAttribute = (RuneBaseAttribute) ago; + + int runeBaseID = ((RuneBaseAttribute) runeBaseAttribute).runeBaseID; + if (runeBaseAttributeMap.get(runeBaseID) == null) { + ArrayList attributeList = new ArrayList<>(); + attributeList.add(runeBaseAttribute); + runeBaseAttributeMap.put(runeBaseID, attributeList); + } else { + ArrayList attributeList = runeBaseAttributeMap.get(runeBaseID); + attributeList.add(runeBaseAttribute); + runeBaseAttributeMap.put(runeBaseID, attributeList); + } + + } + + } + + /* + * Getters + */ + public short getAttributeID() { + return attributeID; + } + + public short getModValue() { + return modValue; + } + + /* + * Utils + */ + + @Override + public void updateDatabase() { + // TODO Auto-generated method stub + } } diff --git a/src/engine/objects/RuneBaseEffect.java b/src/engine/objects/RuneBaseEffect.java index f9d79828..3a285e44 100644 --- a/src/engine/objects/RuneBaseEffect.java +++ b/src/engine/objects/RuneBaseEffect.java @@ -19,54 +19,53 @@ import java.util.HashMap; public class RuneBaseEffect extends AbstractGameObject { - private byte type; - private String name; - private short amount; - private int runeBaseID; - - public static HashMap> RuneIDBaseEffectMap = new HashMap<>(); - /** - * ResultSet Constructor - */ - public RuneBaseEffect(ResultSet rs) throws SQLException { - super(rs); - this.type = rs.getByte("type"); - this.name = rs.getString("name"); - this.amount = rs.getShort("amount"); - this.runeBaseID = rs.getInt("runeID"); - } - - /* - * Getters - */ - - public int getType() { - return this.type; - } - - public String getName() { - return this.name; - } - - public short getAmount() { - return this.amount; - } - - - @Override - public void updateDatabase() { - - } - - public int getRuneBaseID() { - return runeBaseID; - } - - public static void LoadRuneBaseEffects(){ - //cache runebase effects. - DbManager.RuneBaseEffectQueries.GET_ALL_RUNEBASE_EFFECTS(); - //store runebase effects in new hashmap. - RuneBaseEffect.RuneIDBaseEffectMap = DbManager.RuneBaseEffectQueries.LOAD_BASEEFFECTS_FOR_RUNEBASE(); - } + public static HashMap> RuneIDBaseEffectMap = new HashMap<>(); + private byte type; + private String name; + private short amount; + private int runeBaseID; + + /** + * ResultSet Constructor + */ + public RuneBaseEffect(ResultSet rs) throws SQLException { + super(rs); + this.type = rs.getByte("type"); + this.name = rs.getString("name"); + this.amount = rs.getShort("amount"); + this.runeBaseID = rs.getInt("runeID"); + } + + /* + * Getters + */ + + public static void LoadRuneBaseEffects() { + //cache runebase effects. + DbManager.RuneBaseEffectQueries.GET_ALL_RUNEBASE_EFFECTS(); + //store runebase effects in new hashmap. + RuneBaseEffect.RuneIDBaseEffectMap = DbManager.RuneBaseEffectQueries.LOAD_BASEEFFECTS_FOR_RUNEBASE(); + } + + public int getType() { + return this.type; + } + + public String getName() { + return this.name; + } + + public short getAmount() { + return this.amount; + } + + @Override + public void updateDatabase() { + + } + + public int getRuneBaseID() { + return runeBaseID; + } } \ No newline at end of file diff --git a/src/engine/objects/Runegate.java b/src/engine/objects/Runegate.java index d3434b70..762265a5 100644 --- a/src/engine/objects/Runegate.java +++ b/src/engine/objects/Runegate.java @@ -15,105 +15,103 @@ import java.util.HashMap; public class Runegate { - // Runegate class Instance variables - public static HashMap _runegates = new HashMap<>(); + // Runegate class Instance variables + public static HashMap _runegates = new HashMap<>(); - public Portal[] _portals; - public Building gateBuilding; + public Portal[] _portals; + public Building gateBuilding; - private Runegate(Building gateBuilding) { + private Runegate(Building gateBuilding) { - this._portals = new Portal[8]; - this.gateBuilding = gateBuilding; + this._portals = new Portal[8]; + this.gateBuilding = gateBuilding; - // Load portals for this runegate portals from the database + // Load portals for this runegate portals from the database - configurePortals(); + configurePortals(); - // Chaos, Khar and Oblivion are on by default + // Chaos, Khar and Oblivion are on by default - _portals[Enum.PortalType.CHAOS.ordinal()].activate(false); - _portals[Enum.PortalType.OBLIV.ordinal()].activate(false); - _portals[Enum.PortalType.MERCHANT.ordinal()].activate(false); + _portals[Enum.PortalType.CHAOS.ordinal()].activate(false); + _portals[Enum.PortalType.OBLIV.ordinal()].activate(false); + _portals[Enum.PortalType.MERCHANT.ordinal()].activate(false); - } + } - public void activatePortal(Enum.PortalType portalType) { + public static void loadAllRunegates() { - this._portals[portalType.ordinal()].activate(true); + ArrayList gateList; - } + gateList = DbManager.RunegateQueries.GET_RUNEGATE_LIST(); - public void deactivatePortal(Enum.PortalType portalType) { + for (int gateID : gateList) { - this._portals[portalType.ordinal()].deactivate(); + Building gateBuilding = (Building) DbManager.getObject(Enum.GameObjectType.Building, gateID); - } + Runegate runegate = new Runegate(gateBuilding); + _runegates.put(gateID, runegate); + } + } - public Portal[] getPortals() { + public static ArrayList GetAllOpenGateIDStrings() { + ArrayList openGateIDStrings = new ArrayList<>(); - return this._portals; + openGateIDStrings.add("TRA-003"); + openGateIDStrings.add("TRA-004"); + openGateIDStrings.add("TRA-005"); + openGateIDStrings.add("TRA-006"); + openGateIDStrings.add("TRA-007"); + openGateIDStrings.add("TRA-008"); + openGateIDStrings.add("TRA-009"); + openGateIDStrings.add("TRA-010"); + return openGateIDStrings; + } - } + public void activatePortal(Enum.PortalType portalType) { - public void collidePortals() { + this._portals[portalType.ordinal()].activate(true); - for (Portal portal : this.getPortals()) { + } - if (portal.isActive()) - portal.collide(); - } - } + public void deactivatePortal(Enum.PortalType portalType) { - public static void loadAllRunegates() { + this._portals[portalType.ordinal()].deactivate(); - ArrayList gateList; + } - gateList = DbManager.RunegateQueries.GET_RUNEGATE_LIST(); + public Portal[] getPortals() { - for (int gateID : gateList) { + return this._portals; - Building gateBuilding = (Building) DbManager.getObject(Enum.GameObjectType.Building, gateID); + } - Runegate runegate = new Runegate(gateBuilding); - _runegates.put(gateID, runegate); - } + public void collidePortals() { - } + for (Portal portal : this.getPortals()) { - public void configurePortals() { + if (portal.isActive()) + portal.collide(); + } + } - ArrayList portalList = DbManager.RunegateQueries.GET_PORTAL_LIST(this.gateBuilding.getObjectUUID()); + public void configurePortals() { - for (Portal portal : portalList) { - this._portals[portal.portalType.ordinal()] = portal; - } - } + ArrayList portalList = DbManager.RunegateQueries.GET_PORTAL_LIST(this.gateBuilding.getObjectUUID()); - public void _serializeForEnterWorld(ByteBufferWriter writer) { + for (Portal portal : portalList) { + this._portals[portal.portalType.ordinal()] = portal; + } + } - writer.putInt(gateBuilding.getObjectType().ordinal()); - writer.putInt(gateBuilding.getObjectUUID()); - writer.putString(gateBuilding.getParentZone().getName()); - writer.putFloat(gateBuilding.getLoc().getLat()); - writer.putFloat(gateBuilding.getLoc().getAlt()); - writer.putFloat(gateBuilding.getLoc().getLong()); - } + public void _serializeForEnterWorld(ByteBufferWriter writer) { - - public static ArrayList GetAllOpenGateIDStrings(){ - ArrayList openGateIDStrings = new ArrayList<>(); - - openGateIDStrings.add("TRA-003"); - openGateIDStrings.add("TRA-004"); - openGateIDStrings.add("TRA-005"); - openGateIDStrings.add("TRA-006"); - openGateIDStrings.add("TRA-007"); - openGateIDStrings.add("TRA-008"); - openGateIDStrings.add("TRA-009"); - openGateIDStrings.add("TRA-010"); - return openGateIDStrings; - } + writer.putInt(gateBuilding.getObjectType().ordinal()); + writer.putInt(gateBuilding.getObjectUUID()); + writer.putString(gateBuilding.getParentZone().getName()); + writer.putFloat(gateBuilding.getLoc().getLat()); + writer.putFloat(gateBuilding.getLoc().getAlt()); + writer.putFloat(gateBuilding.getLoc().getLong()); + } } diff --git a/src/engine/objects/Shrine.java b/src/engine/objects/Shrine.java index 86cd9a99..928be579 100644 --- a/src/engine/objects/Shrine.java +++ b/src/engine/objects/Shrine.java @@ -23,333 +23,331 @@ import java.util.concurrent.ConcurrentHashMap; public class Shrine extends AbstractWorldObject implements Comparable { - private final ShrineType shrineType; - private Integer favors; - private final int buildingID; + public static ConcurrentHashMap shrinesByBuildingUUID = new ConcurrentHashMap<>(); + private final ShrineType shrineType; + private final int buildingID; + private Integer favors; + + /** + * ResultSet Constructor + */ + public Shrine(ResultSet rs) throws SQLException { + super(rs); + this.shrineType = ShrineType.valueOf(rs.getString("shrine_type")); + this.favors = rs.getInt("shrine_favors"); + this.buildingID = rs.getInt("parent"); + shrinesByBuildingUUID.put(this.buildingID, this); + } + + // Decays this shrine's favor by 10% + + public static boolean canTakeFavor(PlayerCharacter grantee, Shrine shrine) { - public static ConcurrentHashMap shrinesByBuildingUUID = new ConcurrentHashMap<>(); - - /** - * ResultSet Constructor - */ - public Shrine(ResultSet rs) throws SQLException { - super(rs); - this.shrineType = ShrineType.valueOf(rs.getString("shrine_type")); - this.favors = rs.getInt("shrine_favors"); - this.buildingID = rs.getInt("parent"); - shrinesByBuildingUUID.put(this.buildingID, this); - } + if (shrine.shrineType.isRace()) + switch (grantee.getRaceID()) { + case 2000: + case 2001: + if (shrine.shrineType == ShrineType.Aelfborn) + return true; + break; + case 2002: + case 2003: + if (shrine.shrineType == ShrineType.Aracoix) + return true; + break; + case 2004: + case 2005: + if (shrine.shrineType == ShrineType.Centaur) + return true; + break; + case 2006: + if (shrine.shrineType == ShrineType.Dwarf) + return true; + break; + case 2008: + case 2009: + if (shrine.shrineType == ShrineType.Elf) + return true; + break; + case 2010: + case 2027: + if (shrine.shrineType == ShrineType.HalfGiant) + return true; + break; + case 2011: + case 2012: + if (shrine.shrineType == ShrineType.Human) + return true; + break; + case 2013: + case 2014: + if (shrine.shrineType == ShrineType.Irekei) + return true; + break; + case 2015: + case 2016: + if (shrine.shrineType == ShrineType.Shade) + return true; + break; + case 2017: + if (shrine.shrineType == ShrineType.Minotaur) + return true; + break; + + case 2025: + case 2026: + if (shrine.shrineType == ShrineType.Nephilim) + return true; + break; + case 2028: + case 2029: + if (shrine.shrineType == ShrineType.Vampire) + return true; + break; + + } + else + switch (grantee.getPromotionClassID()) { + case 2504: + if (shrine.shrineType == ShrineType.Assassin) + return true; + break; + case 2505: + if (shrine.shrineType == ShrineType.Barbarian) + return true; + break; + case 2506: + if (shrine.shrineType == ShrineType.Bard) + return true; + break; + case 2507: + if (shrine.shrineType == ShrineType.Channeler) + return true; + break; + case 2508: + if (shrine.shrineType == ShrineType.Confessor) + return true; + break; + case 2509: + if (shrine.shrineType == ShrineType.Crusader) + return true; + break; + case 2510: + if (shrine.shrineType == ShrineType.Druid) + return true; + break; + case 2511: + if (shrine.shrineType == ShrineType.Fury) + return true; + break; + case 2512: + if (shrine.shrineType == ShrineType.Huntress) + return true; + break; + case 2513: + if (shrine.shrineType == ShrineType.Prelate) + return true; + break; + case 2514: + if (shrine.shrineType == ShrineType.Ranger) + return true; + break; + case 2515: + if (shrine.shrineType == ShrineType.Scout) + return true; + break; + case 2516: + if (shrine.shrineType == ShrineType.Templar) + return true; + break; + case 2517: + if (shrine.shrineType == ShrineType.Warlock) + return true; + break; + case 2518: + if (shrine.shrineType == ShrineType.Warrior) + return true; + break; + case 2519: + if (shrine.shrineType == ShrineType.Priest) + return true; + break; + case 2520: + if (shrine.shrineType == ShrineType.Thief) + return true; + break; + case 2521: + if (shrine.shrineType == ShrineType.Wizard) + return true; + break; + case 2523: + if (shrine.shrineType == ShrineType.Doomsayer) + return true; + break; + case 2524: + if (shrine.shrineType == ShrineType.Sentinel) + return true; + break; + case 2525: + if (shrine.shrineType == ShrineType.Necromancer) + return true; + break; + case 2526: + if (shrine.shrineType == ShrineType.Nightstalker) + return true; + break; + } + + return false; + } + + public static ShrineType getShrineTypeByBlueprintUUID(int blueprintUUID) { + + for (ShrineType shrineType : ShrineType.values()) { + + if (shrineType.getBlueprintUUID() == blueprintUUID) + return shrineType; + } + return null; + } + + public static void RemoveShrineFromCacheByBuilding(Building building) { + + if (building.getBlueprint() != null && building.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE) { + Shrine shrine = Shrine.shrinesByBuildingUUID.get(building.getObjectUUID()); + + if (shrine != null) { + shrine.shrineType.RemoveShrineFromServerList(shrine); + Shrine.shrinesByBuildingUUID.remove(building.getObjectUUID()); + DbManager.removeFromCache(Enum.GameObjectType.Shrine, + shrine.getObjectUUID()); + } + } - // Decays this shrine's favor by 10% + } - public void decay() { + public void decay() { - if (this.getFavors() == 0) - return; + if (this.getFavors() == 0) + return; - int decayAmount = (int) (this.getFavors() - (this.getFavors() *.10f)); + int decayAmount = (int) (this.getFavors() - (this.getFavors() * .10f)); - if (decayAmount < 0) - decayAmount = 0; + if (decayAmount < 0) + decayAmount = 0; - if (!DbManager.ShrineQueries.updateFavors(this, decayAmount, this.getFavors())) { - Logger.error("Shrine Decay", "Error writing to DB. UUID: " + this.getObjectUUID()); - return; - } - this.favors = decayAmount; + if (!DbManager.ShrineQueries.updateFavors(this, decayAmount, this.getFavors())) { + Logger.error("Shrine Decay", "Error writing to DB. UUID: " + this.getObjectUUID()); + return; + } + this.favors = decayAmount; - Logger.info( shrineType.name() + " uuid:" + this.getObjectUUID() + " Amount: " + this.getFavors() *.10f ); + Logger.info(shrineType.name() + " uuid:" + this.getObjectUUID() + " Amount: " + this.getFavors() * .10f); - } + } - public synchronized boolean addFavor(PlayerCharacter boonOwner, Item boonItem) { + public synchronized boolean addFavor(PlayerCharacter boonOwner, Item boonItem) { - if (boonOwner == null) - return false; + if (boonOwner == null) + return false; - if (boonItem == null) - return false; + if (boonItem == null) + return false; - ItemBase ib = boonItem.getItemBase(); + ItemBase ib = boonItem.getItemBase(); - if (ib == null) - return false; + if (ib == null) + return false; - if (!boonOwner.getCharItemManager().doesCharOwnThisItem(boonItem.getObjectUUID())) - return false; + if (!boonOwner.getCharItemManager().doesCharOwnThisItem(boonItem.getObjectUUID())) + return false; - ArrayList boonList = Boon.GetBoonsForItemBase.get(ib.getUUID()); + ArrayList boonList = Boon.GetBoonsForItemBase.get(ib.getUUID()); - if (boonList == null) - return false; + if (boonList == null) + return false; - for (Boon boon : boonList) { + for (Boon boon : boonList) { - ShrineType boonShrineType = boon.getShrineType(); + ShrineType boonShrineType = boon.getShrineType(); if (boonShrineType != shrineType) - continue; - - //Same Shrine Type, add favors and stop loop. - int amount = boon.getAmount() * boonItem.getNumOfItems(); - int oldAmount = this.favors; - - if (!DbManager.ShrineQueries.updateFavors(this, this.favors + amount, oldAmount)) { - ChatManager.chatSystemError(boonOwner, "Failed to add boon to shrine."); - return false; - } - - this.favors += amount; - boonOwner.getCharItemManager().delete(boonItem); - boonOwner.getCharItemManager().updateInventory(); - return true; - } - return false; - } - - public synchronized boolean takeFavor(PlayerCharacter boonOwner) { - - if (boonOwner == null) - return false; - - int oldAmount = this.favors; - int newAmount = this.favors - 1; - - if (!DbManager.ShrineQueries.updateFavors(this, newAmount, oldAmount)) { - ChatManager.chatSystemError(boonOwner, "Failed to add boon to shrine."); - return false; - } - this.favors = newAmount; - return true; - } - - public static boolean canTakeFavor(PlayerCharacter grantee, Shrine shrine) { - - if (shrine.shrineType.isRace()) - switch (grantee.getRaceID()) { - case 2000: - case 2001: - if (shrine.shrineType == ShrineType.Aelfborn) - return true; - break; - case 2002: - case 2003: - if (shrine.shrineType == ShrineType.Aracoix) - return true; - break; - case 2004: - case 2005: - if (shrine.shrineType == ShrineType.Centaur) - return true; - break; - case 2006: - if (shrine.shrineType == ShrineType.Dwarf) - return true; - break; - case 2008: - case 2009: - if (shrine.shrineType == ShrineType.Elf) - return true; - break; - case 2010: - case 2027: - if (shrine.shrineType == ShrineType.HalfGiant) - return true; - break; - case 2011: - case 2012: - if (shrine.shrineType == ShrineType.Human) - return true; - break; - case 2013: - case 2014: - if (shrine.shrineType == ShrineType.Irekei) - return true; - break; - case 2015: - case 2016: - if (shrine.shrineType == ShrineType.Shade) - return true; - break; - case 2017: - if (shrine.shrineType == ShrineType.Minotaur) - return true; - break; - - case 2025: - case 2026: - if (shrine.shrineType == ShrineType.Nephilim) - return true; - break; - case 2028: - case 2029: - if (shrine.shrineType == ShrineType.Vampire) - return true; - break; - - } - else - switch (grantee.getPromotionClassID()) { - case 2504: - if (shrine.shrineType == ShrineType.Assassin) - return true; - break; - case 2505: - if (shrine.shrineType == ShrineType.Barbarian) - return true; - break; - case 2506: - if (shrine.shrineType == ShrineType.Bard) - return true; - break; - case 2507: - if (shrine.shrineType == ShrineType.Channeler) - return true; - break; - case 2508: - if (shrine.shrineType == ShrineType.Confessor) - return true; - break; - case 2509: - if (shrine.shrineType == ShrineType.Crusader) - return true; - break; - case 2510: - if (shrine.shrineType == ShrineType.Druid) - return true; - break; - case 2511: - if (shrine.shrineType == ShrineType.Fury) - return true; - break; - case 2512: - if (shrine.shrineType == ShrineType.Huntress) - return true; - break; - case 2513: - if (shrine.shrineType == ShrineType.Prelate) - return true; - break; - case 2514: - if (shrine.shrineType == ShrineType.Ranger) - return true; - break; - case 2515: - if (shrine.shrineType == ShrineType.Scout) - return true; - break; - case 2516: - if (shrine.shrineType == ShrineType.Templar) - return true; - break; - case 2517: - if (shrine.shrineType == ShrineType.Warlock) - return true; - break; - case 2518: - if (shrine.shrineType == ShrineType.Warrior) - return true; - break; - case 2519: - if (shrine.shrineType == ShrineType.Priest) - return true; - break; - case 2520: - if (shrine.shrineType == ShrineType.Thief) - return true; - break; - case 2521: - if (shrine.shrineType == ShrineType.Wizard) - return true; - break; - case 2523: - if (shrine.shrineType == ShrineType.Doomsayer) - return true; - break; - case 2524: - if (shrine.shrineType == ShrineType.Sentinel) - return true; - break; - case 2525: - if (shrine.shrineType == ShrineType.Necromancer) - return true; - break; - case 2526: - if (shrine.shrineType == ShrineType.Nightstalker) - return true; - break; - } - - return false; - } - - public static ShrineType getShrineTypeByBlueprintUUID(int blueprintUUID) { - - for (ShrineType shrineType : ShrineType.values()) { - - if (shrineType.getBlueprintUUID() == blueprintUUID) - return shrineType; - } - return null; - } - - @Override - public int compareTo(Shrine other) { - return other.favors.compareTo(this.favors); - } - - public int getRank() { + continue; + + //Same Shrine Type, add favors and stop loop. + int amount = boon.getAmount() * boonItem.getNumOfItems(); + int oldAmount = this.favors; + + if (!DbManager.ShrineQueries.updateFavors(this, this.favors + amount, oldAmount)) { + ChatManager.chatSystemError(boonOwner, "Failed to add boon to shrine."); + return false; + } + + this.favors += amount; + boonOwner.getCharItemManager().delete(boonItem); + boonOwner.getCharItemManager().updateInventory(); + return true; + } + return false; + } + + public synchronized boolean takeFavor(PlayerCharacter boonOwner) { + + if (boonOwner == null) + return false; + + int oldAmount = this.favors; + int newAmount = this.favors - 1; + + if (!DbManager.ShrineQueries.updateFavors(this, newAmount, oldAmount)) { + ChatManager.chatSystemError(boonOwner, "Failed to add boon to shrine."); + return false; + } + this.favors = newAmount; + return true; + } + + @Override + public int compareTo(Shrine other) { + return other.favors.compareTo(this.favors); + } + + public int getRank() { return shrineType.getShrinesCopy().indexOf(this); - } - - public ShrineType getShrineType() { - return shrineType; - } - - public static void RemoveShrineFromCacheByBuilding(Building building) { - - if (building.getBlueprint() != null && building.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE) { - Shrine shrine = Shrine.shrinesByBuildingUUID.get(building.getObjectUUID()); - - if (shrine != null) { - shrine.shrineType.RemoveShrineFromServerList(shrine); - Shrine.shrinesByBuildingUUID.remove(building.getObjectUUID()); - DbManager.removeFromCache(Enum.GameObjectType.Shrine, - shrine.getObjectUUID()); - } - } - - } + } - @Override - public void updateDatabase() { - // TODO Auto-generated method stub + public ShrineType getShrineType() { + return shrineType; + } - } + @Override + public void updateDatabase() { + // TODO Auto-generated method stub - public int getFavors() { - return favors; - } + } - public int getBuildingID() { - return buildingID; - } + public int getFavors() { + return favors; + } - @Override - public void runAfterLoad() { - // TODO Auto-generated method stub + public void setFavors(Integer favors) { + this.favors = favors; + } - } + public int getBuildingID() { + return buildingID; + } + @Override + public void runAfterLoad() { + // TODO Auto-generated method stub - @Override - public void removeFromCache() { - // TODO Auto-generated method stub + } - } + @Override + public void removeFromCache() { + // TODO Auto-generated method stub - public void setFavors(Integer favors) { - this.favors = favors; - } + } } diff --git a/src/engine/objects/SkillReq.java b/src/engine/objects/SkillReq.java index 99f4dea9..703279bf 100644 --- a/src/engine/objects/SkillReq.java +++ b/src/engine/objects/SkillReq.java @@ -19,9 +19,9 @@ import java.util.ArrayList; public class SkillReq extends AbstractGameObject { - private int skillID; - private short level; - private ArrayList skillReqs; + private int skillID; + private short level; + private ArrayList skillReqs; /* This shouldn't be used public SkillReq(SkillsBase skillsBase, short level, ArrayListskillReqs) { @@ -52,46 +52,49 @@ public class SkillReq extends AbstractGameObject { } */ - /** - * ResultSet Constructor - */ - public SkillReq(ResultSet rs) throws SQLException { - super(rs, 0); - this.skillID = rs.getInt("skillID"); - this.level = rs.getShort("level"); - skillReqs = new ArrayList<>(0); - - int skillReq; - skillReq = rs.getInt("skillreq1"); - if (skillReq > 0) skillReqs.add((byte)skillReq); - skillReq = rs.getInt("skillreq2"); - if (skillReq > 0) skillReqs.add((byte)skillReq); - skillReq = rs.getInt("skillreq3"); - if (skillReq > 0) skillReqs.add((byte)skillReq); - } - - /* - * Getters - */ - public SkillsBase getSkillsBase() { - return DbManager.SkillsBaseQueries.GET_BASE(this.skillID); - } - - public int getSkillID() { - return this.skillID; - } - - public short getLevel() { - return this.level; - } - - public ArrayList getSkillReqs() { - return this.skillReqs; - } - - - @Override - public void updateDatabase() { - - } + /** + * ResultSet Constructor + */ + public SkillReq(ResultSet rs) throws SQLException { + super(rs, 0); + this.skillID = rs.getInt("skillID"); + this.level = rs.getShort("level"); + skillReqs = new ArrayList<>(0); + + int skillReq; + skillReq = rs.getInt("skillreq1"); + if (skillReq > 0) + skillReqs.add((byte) skillReq); + skillReq = rs.getInt("skillreq2"); + if (skillReq > 0) + skillReqs.add((byte) skillReq); + skillReq = rs.getInt("skillreq3"); + if (skillReq > 0) + skillReqs.add((byte) skillReq); + } + + /* + * Getters + */ + public SkillsBase getSkillsBase() { + return DbManager.SkillsBaseQueries.GET_BASE(this.skillID); + } + + public int getSkillID() { + return this.skillID; + } + + public short getLevel() { + return this.level; + } + + public ArrayList getSkillReqs() { + return this.skillReqs; + } + + + @Override + public void updateDatabase() { + + } } \ No newline at end of file diff --git a/src/engine/objects/SkillsBase.java b/src/engine/objects/SkillsBase.java index 2c37fab7..d615b717 100644 --- a/src/engine/objects/SkillsBase.java +++ b/src/engine/objects/SkillsBase.java @@ -7,7 +7,7 @@ // www.magicbane.com - package engine.objects; +package engine.objects; import engine.Enum.SourceType; import engine.gameManager.DbManager; @@ -21,140 +21,138 @@ import java.util.concurrent.ConcurrentHashMap; public class SkillsBase extends AbstractGameObject { - private final String name; - private final String nameNoSpace; - private final String description; - private final int token; - private final short strMod; - private final short dexMod; - private final short conMod; - private final short intMod; - private final short spiMod; - public static ConcurrentHashMap skillsCache = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - public static ConcurrentHashMap tokenCache = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - public static HashMap> runeSkillsCache = new HashMap<>(); - public SourceType sourceType; - /** - * No Table ID Constructor - */ - public SkillsBase(String name, String description, int token, short strMod, - short dexMod, short conMod, short intMod, short spiMod) { - super(); - this.name = name; - this.nameNoSpace = name.replace(" ", ""); - this.sourceType = SourceType.GetSourceType(this.nameNoSpace.replace(",", "")); - this.description = description; - this.token = token; - this.strMod = strMod; - this.dexMod = dexMod; - this.conMod = conMod; - this.intMod = intMod; - this.spiMod = spiMod; - } - - /** - * Normal Constructor - */ - public SkillsBase(String name, String description, int token, short strMod, - short dexMod, short conMod, short intMod, short spiMod, int newUUID) { - super(newUUID); - this.name = name; - this.nameNoSpace = name.replace(" ", ""); - this.description = description; - this.token = token; - this.strMod = strMod; - this.dexMod = dexMod; - this.conMod = conMod; - this.intMod = intMod; - this.spiMod = spiMod; - } - - /** - * ResultSet Constructor - */ - public SkillsBase(ResultSet rs) throws SQLException { - super(rs); - - this.name = rs.getString("name"); - this.nameNoSpace = name.replace(" ", ""); - this.description = rs.getString("description"); - this.sourceType = SourceType.GetSourceType(this.nameNoSpace.replace("-", "").replace("\"", "").replace(",", "")); - this.token = rs.getInt("token"); - this.strMod = rs.getShort("strMod"); - this.dexMod = rs.getShort("dexMod"); - this.conMod = rs.getShort("conMod"); - this.intMod = rs.getShort("intMod"); - this.spiMod = rs.getShort("spiMod"); - } - - /* - * Getters - */ - public String getName() { - return name; - } - - public String getNameNoSpace() { - return nameNoSpace; - } - - - public String getDescription() { - return description; - } - - public int getToken() { - return this.token; - } - - public short getStrMod() { - return this.strMod; - } - - public short getDexMod() { - return this.dexMod; - } - - public short getConMod() { - return this.conMod; - } - - public short getIntMod() { - return this.intMod; - } - - public short getSpiMod() { - return this.spiMod; - } - - public static SkillsBase getFromCache(String name) { - if (skillsCache.containsKey(name)) - return skillsCache.get(name); - else - return null; - } - - public static SkillsBase getFromCache(int token) { - if (tokenCache.containsKey(token)) - return tokenCache.get(token); - else - return null; - } - - public static void putInCache(SkillsBase sb) { - - if(sb == null) - return; - - DbManager.addToCache(sb); + public static ConcurrentHashMap skillsCache = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + public static ConcurrentHashMap tokenCache = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + public static HashMap> runeSkillsCache = new HashMap<>(); + private final String name; + private final String nameNoSpace; + private final String description; + private final int token; + private final short strMod; + private final short dexMod; + private final short conMod; + private final short intMod; + private final short spiMod; + public SourceType sourceType; + + /** + * No Table ID Constructor + */ + public SkillsBase(String name, String description, int token, short strMod, + short dexMod, short conMod, short intMod, short spiMod) { + super(); + this.name = name; + this.nameNoSpace = name.replace(" ", ""); + this.sourceType = SourceType.GetSourceType(this.nameNoSpace.replace(",", "")); + this.description = description; + this.token = token; + this.strMod = strMod; + this.dexMod = dexMod; + this.conMod = conMod; + this.intMod = intMod; + this.spiMod = spiMod; + } + + /** + * Normal Constructor + */ + public SkillsBase(String name, String description, int token, short strMod, + short dexMod, short conMod, short intMod, short spiMod, int newUUID) { + super(newUUID); + this.name = name; + this.nameNoSpace = name.replace(" ", ""); + this.description = description; + this.token = token; + this.strMod = strMod; + this.dexMod = dexMod; + this.conMod = conMod; + this.intMod = intMod; + this.spiMod = spiMod; + } + + /** + * ResultSet Constructor + */ + public SkillsBase(ResultSet rs) throws SQLException { + super(rs); + + this.name = rs.getString("name"); + this.nameNoSpace = name.replace(" ", ""); + this.description = rs.getString("description"); + this.sourceType = SourceType.GetSourceType(this.nameNoSpace.replace("-", "").replace("\"", "").replace(",", "")); + this.token = rs.getInt("token"); + this.strMod = rs.getShort("strMod"); + this.dexMod = rs.getShort("dexMod"); + this.conMod = rs.getShort("conMod"); + this.intMod = rs.getShort("intMod"); + this.spiMod = rs.getShort("spiMod"); + } + + public static SkillsBase getFromCache(String name) { + if (skillsCache.containsKey(name)) + return skillsCache.get(name); + else + return null; + } + + public static SkillsBase getFromCache(int token) { + if (tokenCache.containsKey(token)) + return tokenCache.get(token); + else + return null; + } + + public static void putInCache(SkillsBase sb) { + + if (sb == null) + return; + + DbManager.addToCache(sb); skillsCache.putIfAbsent(sb.name, sb); tokenCache.putIfAbsent(sb.token, sb); - } - - - - @Override - public void updateDatabase() { - // TODO Auto-generated method stub - } + } + + /* + * Getters + */ + public String getName() { + return name; + } + + public String getNameNoSpace() { + return nameNoSpace; + } + + public String getDescription() { + return description; + } + + public int getToken() { + return this.token; + } + + public short getStrMod() { + return this.strMod; + } + + public short getDexMod() { + return this.dexMod; + } + + public short getConMod() { + return this.conMod; + } + + public short getIntMod() { + return this.intMod; + } + + public short getSpiMod() { + return this.spiMod; + } + + @Override + public void updateDatabase() { + // TODO Auto-generated method stub + } } diff --git a/src/engine/objects/SkillsBaseAttribute.java b/src/engine/objects/SkillsBaseAttribute.java index c8ce47a2..4269486e 100644 --- a/src/engine/objects/SkillsBaseAttribute.java +++ b/src/engine/objects/SkillsBaseAttribute.java @@ -7,7 +7,7 @@ // www.magicbane.com - package engine.objects; +package engine.objects; import java.sql.ResultSet; import java.sql.SQLException; @@ -15,56 +15,56 @@ import java.sql.SQLException; public class SkillsBaseAttribute extends AbstractGameObject { - private short attributeID; - private short modValue; - - /** - * No Table ID Constructor - */ - public SkillsBaseAttribute(short attributeID, short modValue) { - super(); - - this.attributeID = attributeID; - this.modValue = modValue; - } - - /** - * Normal Constructor - */ - public SkillsBaseAttribute(short attributeID, short modValue, int newUUID) { - super(newUUID); - - this.attributeID = attributeID; - this.modValue = modValue; - } - - /** - * ResultSet Constructor - */ - public SkillsBaseAttribute(ResultSet rs) throws SQLException { - super(rs); - - this.attributeID = rs.getShort("attributeID"); - this.modValue = rs.getShort("modValue"); - } - - /* - * Getters - */ - public short getAttributeID() { - return attributeID; - } - - public short getModValue() { - return modValue; - } - - - /* - * Database - */ - @Override - public void updateDatabase() { - // TODO Auto-generated method stub - } + private short attributeID; + private short modValue; + + /** + * No Table ID Constructor + */ + public SkillsBaseAttribute(short attributeID, short modValue) { + super(); + + this.attributeID = attributeID; + this.modValue = modValue; + } + + /** + * Normal Constructor + */ + public SkillsBaseAttribute(short attributeID, short modValue, int newUUID) { + super(newUUID); + + this.attributeID = attributeID; + this.modValue = modValue; + } + + /** + * ResultSet Constructor + */ + public SkillsBaseAttribute(ResultSet rs) throws SQLException { + super(rs); + + this.attributeID = rs.getShort("attributeID"); + this.modValue = rs.getShort("modValue"); + } + + /* + * Getters + */ + public short getAttributeID() { + return attributeID; + } + + public short getModValue() { + return modValue; + } + + + /* + * Database + */ + @Override + public void updateDatabase() { + // TODO Auto-generated method stub + } } diff --git a/src/engine/objects/StaticColliders.java b/src/engine/objects/StaticColliders.java index 4794d676..8c2306e5 100644 --- a/src/engine/objects/StaticColliders.java +++ b/src/engine/objects/StaticColliders.java @@ -16,86 +16,82 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; -public class StaticColliders { - - private int meshID; - private float startX; - private float startY; - private float endX; - private float endY; - private int doorID; - public static HashMap> _staticColliders = new HashMap<>(); - private boolean link = false; - - - - - /** - * ResultSet Constructor - */ - - public StaticColliders(ResultSet rs) throws SQLException { - this.meshID = rs.getInt("meshID"); - this.startX = rs.getInt("startX"); - this.startY = rs.getInt("startY"); - this.endX = rs.getInt("endX"); - this.endY = rs.getInt("endY"); - this.doorID = rs.getInt("doorID"); - this.link = rs.getBoolean("link"); - } - - public StaticColliders(int meshID, float startX, float startY, float endX, - float endY, int doorID,boolean link) { - super(); - this.meshID = meshID; - this.startX = startX; - this.startY = startY; - this.endX = endX; - this.endY = endY; - this.doorID = doorID; - this.link = link; - } - - public static void loadAllStaticColliders(){ - _staticColliders = DbManager.BuildingQueries.LOAD_ALL_STATIC_COLLIDERS(); - } - - public static ArrayList GetStaticCollidersForMeshID(int meshID) { - return _staticColliders.get(meshID); - } - - - - - public int getMeshID() { - return meshID; - } - - public float getStartX() { - return startX; - } - - public float getStartY() { - return startY; - } - - public float getEndX() { - return endX; - } - - public float getEndY() { - return endY; - } - - public int getDoorID() { - return doorID; - } - - public boolean isLink() { - return link; - } - - public void setLink(boolean link) { - this.link = link; - } +public class StaticColliders { + + public static HashMap> _staticColliders = new HashMap<>(); + private int meshID; + private float startX; + private float startY; + private float endX; + private float endY; + private int doorID; + private boolean link = false; + + + /** + * ResultSet Constructor + */ + + public StaticColliders(ResultSet rs) throws SQLException { + this.meshID = rs.getInt("meshID"); + this.startX = rs.getInt("startX"); + this.startY = rs.getInt("startY"); + this.endX = rs.getInt("endX"); + this.endY = rs.getInt("endY"); + this.doorID = rs.getInt("doorID"); + this.link = rs.getBoolean("link"); + } + + public StaticColliders(int meshID, float startX, float startY, float endX, + float endY, int doorID, boolean link) { + super(); + this.meshID = meshID; + this.startX = startX; + this.startY = startY; + this.endX = endX; + this.endY = endY; + this.doorID = doorID; + this.link = link; + } + + public static void loadAllStaticColliders() { + _staticColliders = DbManager.BuildingQueries.LOAD_ALL_STATIC_COLLIDERS(); + } + + public static ArrayList GetStaticCollidersForMeshID(int meshID) { + return _staticColliders.get(meshID); + } + + + public int getMeshID() { + return meshID; + } + + public float getStartX() { + return startX; + } + + public float getStartY() { + return startY; + } + + public float getEndX() { + return endX; + } + + public float getEndY() { + return endY; + } + + public int getDoorID() { + return doorID; + } + + public boolean isLink() { + return link; + } + + public void setLink(boolean link) { + this.link = link; + } } diff --git a/src/engine/objects/Transaction.java b/src/engine/objects/Transaction.java index c03b1cdf..1e282195 100644 --- a/src/engine/objects/Transaction.java +++ b/src/engine/objects/Transaction.java @@ -7,7 +7,6 @@ // www.magicbane.com - package engine.objects; import engine.Enum.GameObjectType; @@ -19,93 +18,91 @@ import java.sql.SQLException; import java.util.Date; +public class Transaction implements Comparable { + + private final int warehouseUUID; + private final int targetUUID; + private final Resource resource; + private final DateTime date; + private final int amount; + private final TransactionType transactionType; + private GameObjectType targetType; + + + public Transaction(ResultSet rs) throws SQLException { + this.warehouseUUID = rs.getInt("warehouseUID"); + this.targetUUID = rs.getInt("targetUID"); + this.targetType = GameObjectType.valueOf(rs.getString("targetType")); + this.transactionType = TransactionType.valueOf(rs.getString("type").toUpperCase()); + this.resource = Resource.valueOf(rs.getString("resource").toUpperCase()); + this.amount = rs.getInt("amount"); + + Date sqlDateTime = rs.getTimestamp("date"); + + if (sqlDateTime != null) + this.date = new DateTime(sqlDateTime); + else + this.date = DateTime.now(); -public class Transaction implements Comparable { + } - private final int warehouseUUID; - private final int targetUUID; - private final Resource resource; - private final DateTime date; - private final int amount; - private GameObjectType targetType; - private final TransactionType transactionType; - - - - public Transaction(ResultSet rs) throws SQLException { - this.warehouseUUID = rs.getInt("warehouseUID"); - this.targetUUID = rs.getInt("targetUID"); - this.targetType = GameObjectType.valueOf(rs.getString("targetType")); - this.transactionType = TransactionType.valueOf(rs.getString("type").toUpperCase()); - this.resource = Resource.valueOf(rs.getString("resource").toUpperCase()); - this.amount = rs.getInt("amount"); - - Date sqlDateTime = rs.getTimestamp("date"); - - if (sqlDateTime != null) - this.date = new DateTime(sqlDateTime); - else - this.date = DateTime.now(); - } + public Transaction(int warehouseUUID, GameObjectType targetType, int targetUUID, TransactionType transactionType, Resource resource, int amount, + DateTime date) { + this.warehouseUUID = warehouseUUID; + this.targetUUID = targetUUID; + this.resource = resource; + this.date = date; + this.amount = amount; + this.targetType = targetType; + this.transactionType = transactionType; + } - - public Transaction(int warehouseUUID,GameObjectType targetType, int targetUUID, TransactionType transactionType, Resource resource, int amount, - DateTime date) { - this.warehouseUUID = warehouseUUID; - this.targetUUID = targetUUID; - this.resource = resource; - this.date = date; - this.amount = amount; - this.targetType = targetType; - this.transactionType = transactionType; - } + public int getWarehouseUUID() { + return warehouseUUID; + } - public int getWarehouseUUID() { - return warehouseUUID; - } + public int getTargetUUID() { + return targetUUID; + } - public int getTargetUUID() { - return targetUUID; - } + public Resource getResource() { + return resource; + } - public Resource getResource() { - return resource; - } + public DateTime getDate() { + return date; + } - public DateTime getDate() { - return date; - } + public int getAmount() { + return amount; + } - public int getAmount() { - return amount; - } + public TransactionType getTransactionType() { + return transactionType; + } - public TransactionType getTransactionType() { - return transactionType; - } + @Override + public int compareTo(Transaction arg0) { + // TODO Auto-generated method stub + return 0; + } - @Override - public int compareTo(Transaction arg0) { - // TODO Auto-generated method stub - return 0; - } + public GameObjectType getTargetType() { + return targetType; + } - public GameObjectType getTargetType() { - return targetType; - } + public void setTargetType(GameObjectType targetType) { + this.targetType = targetType; + } - public void setTargetType(GameObjectType targetType) { - this.targetType = targetType; - } - } diff --git a/src/engine/objects/VendorDialog.java b/src/engine/objects/VendorDialog.java index 3bf2cdd1..674f34ea 100644 --- a/src/engine/objects/VendorDialog.java +++ b/src/engine/objects/VendorDialog.java @@ -18,57 +18,57 @@ import java.util.ArrayList; public class VendorDialog extends AbstractGameObject { - private final String dialogType; - private final String intro; - private ArrayList options = new ArrayList<>(); - - public VendorDialog(String dialogType, String intro, int UUID) { - super(UUID); - this.dialogType = dialogType; - this.intro = intro; - } - - /** - * ResultSet Constructor - */ - public VendorDialog(ResultSet rs) throws SQLException { - super(rs); - this.dialogType = rs.getString("dialogType"); - this.intro = rs.getString("intro"); - this.options = DbManager.MenuQueries.GET_MENU_OPTIONS(this.getObjectUUID()); - } - - /* - * Getters - */ - public String getDialogType() { - return this.dialogType; - } - - public String getIntro() { - return this.intro; - } - - public ArrayList getOptions() { - return this.options; - } - - private static VendorDialog vd; - public static VendorDialog getHostileVendorDialog() { - if (VendorDialog.vd == null) - VendorDialog.vd = new VendorDialog("TrainerDialog", "HostileIntro", 0); - return VendorDialog.vd; - } - - - /* - * Database - */ - @Override - public void updateDatabase() {} - - public static VendorDialog getVendorDialog(int id) { - - return DbManager.VendorDialogQueries.GET_VENDORDIALOG(id); - } + private static VendorDialog vd; + private final String dialogType; + private final String intro; + private ArrayList options = new ArrayList<>(); + + public VendorDialog(String dialogType, String intro, int UUID) { + super(UUID); + this.dialogType = dialogType; + this.intro = intro; + } + + /** + * ResultSet Constructor + */ + public VendorDialog(ResultSet rs) throws SQLException { + super(rs); + this.dialogType = rs.getString("dialogType"); + this.intro = rs.getString("intro"); + this.options = DbManager.MenuQueries.GET_MENU_OPTIONS(this.getObjectUUID()); + } + + public static VendorDialog getHostileVendorDialog() { + if (VendorDialog.vd == null) + VendorDialog.vd = new VendorDialog("TrainerDialog", "HostileIntro", 0); + return VendorDialog.vd; + } + + public static VendorDialog getVendorDialog(int id) { + + return DbManager.VendorDialogQueries.GET_VENDORDIALOG(id); + } + + /* + * Getters + */ + public String getDialogType() { + return this.dialogType; + } + + public String getIntro() { + return this.intro; + } + + public ArrayList getOptions() { + return this.options; + } + + /* + * Database + */ + @Override + public void updateDatabase() { + } } diff --git a/src/engine/objects/Warehouse.java b/src/engine/objects/Warehouse.java index a044810e..f96a5fcb 100644 --- a/src/engine/objects/Warehouse.java +++ b/src/engine/objects/Warehouse.java @@ -31,1300 +31,1297 @@ import java.util.concurrent.ConcurrentHashMap; public class Warehouse extends AbstractWorldObject { - private int UID; - - public EnumBitSet lockedResourceTypes; - - private int buildingUID; - private ArrayList transactions = new ArrayList<>(); - - private ConcurrentHashMap resources = new ConcurrentHashMap<>(); - - public static ItemBase goldIB = ItemBase.getItemBase(7); - public static ItemBase stoneIB = ItemBase.getItemBase(1580000); - public static ItemBase truesteelIB = ItemBase.getItemBase(1580001); - public static ItemBase ironIB = ItemBase.getItemBase(1580002); - public static ItemBase adamantIB = ItemBase.getItemBase(1580003); - public static ItemBase lumberIB = ItemBase.getItemBase(1580004); - public static ItemBase oakIB = ItemBase.getItemBase(1580005); - public static ItemBase bronzewoodIB = ItemBase.getItemBase(1580006); - public static ItemBase mandrakeIB = ItemBase.getItemBase(1580007); - public static ItemBase coalIB = ItemBase.getItemBase(1580008); - public static ItemBase agateIB = ItemBase.getItemBase(1580009); - public static ItemBase diamondIB = ItemBase.getItemBase(1580010); - public static ItemBase onyxIB = ItemBase.getItemBase(1580011); - public static ItemBase azothIB = ItemBase.getItemBase(1580012); - public static ItemBase orichalkIB = ItemBase.getItemBase(1580013); - public static ItemBase antimonyIB = ItemBase.getItemBase(1580014); - public static ItemBase sulferIB = ItemBase.getItemBase(1580015); - public static ItemBase quicksilverIB = ItemBase.getItemBase(1580016); - public static ItemBase galvorIB = ItemBase.getItemBase(1580017); - public static ItemBase wormwoodIB = ItemBase.getItemBase(1580018); - public static ItemBase obsidianIB = ItemBase.getItemBase(1580019); - public static ItemBase bloodstoneIB = ItemBase.getItemBase(1580020); - public static ItemBase mithrilIB = ItemBase.getItemBase(1580021); - public static ConcurrentHashMap maxResources = new ConcurrentHashMap<>(); - public static ConcurrentHashMap warehouseByBuildingUUID = new ConcurrentHashMap<>(); - - - - public static ConcurrentHashMap getMaxResources() { - if(maxResources.size() != 23){ - maxResources.put(7, 100000000); - maxResources.put(1580000, 10000); - maxResources.put(1580001, 2000); - maxResources.put(1580002, 2000); - maxResources.put(1580003, 1000); - maxResources.put(1580004, 10000); - maxResources.put(1580005, 3000); - maxResources.put(1580006, 3000); - maxResources.put(1580007, 1000); - maxResources.put(1580008, 3000); - maxResources.put(1580009, 2000); - maxResources.put(1580010, 2000); - maxResources.put(1580011, 1000); - maxResources.put(1580012, 2000); - maxResources.put(1580013, 3000); - maxResources.put(1580014, 1000); - maxResources.put(1580015, 1000); - maxResources.put(1580016, 1000); - maxResources.put(1580017, 500); - maxResources.put(1580018, 500); - maxResources.put(1580019, 500); - maxResources.put(1580020, 500); - maxResources.put(1580021, 500); - } - - return maxResources; - } - - /** - * ResultSet Constructor - */ - public Warehouse(ResultSet rs) throws SQLException { - super(rs); - this.UID = rs.getInt("UID"); - this.resources.put(stoneIB, rs.getInt("warehouse_stone")); - this.resources.put(truesteelIB,rs.getInt("warehouse_truesteel")); - this.resources.put(ironIB,rs.getInt("warehouse_iron")); - this.resources.put(adamantIB,rs.getInt("warehouse_adamant")); - this.resources.put(lumberIB,rs.getInt("warehouse_lumber")); - this.resources.put(oakIB,rs.getInt("warehouse_oak")); - this.resources.put(bronzewoodIB,rs.getInt("warehouse_bronzewood")); - this.resources.put(mandrakeIB,rs.getInt("warehouse_mandrake")); - this.resources.put(coalIB,rs.getInt("warehouse_coal")); - this.resources.put(agateIB,rs.getInt("warehouse_agate")); - this.resources.put(diamondIB,rs.getInt("warehouse_diamond")); - this.resources.put(onyxIB,rs.getInt("warehouse_onyx")); - this.resources.put(azothIB,rs.getInt("warehouse_azoth")); - this.resources.put(orichalkIB,rs.getInt("warehouse_orichalk")); - this.resources.put(antimonyIB,rs.getInt("warehouse_antimony")); - this.resources.put(sulferIB,rs.getInt("warehouse_sulfur")); - this.resources.put(quicksilverIB,rs.getInt("warehouse_quicksilver")); - this.resources.put(galvorIB,rs.getInt("warehouse_galvor")); - this.resources.put(wormwoodIB,rs.getInt("warehouse_wormwood")); - this.resources.put(obsidianIB,rs.getInt("warehouse_obsidian")); - this.resources.put(bloodstoneIB,rs.getInt("warehouse_bloodstone")); - this.resources.put(mithrilIB,rs.getInt("warehouse_mithril")); - this.resources.put(goldIB, rs.getInt("warehouse_gold")); - this.lockedResourceTypes = EnumBitSet.asEnumBitSet(rs.getLong("warehouse_locks"), Enum.ResourceType.class); - this.buildingUID = rs.getInt("parent"); - Warehouse.warehouseByBuildingUUID.put(this.buildingUID, this); - } + public static ItemBase goldIB = ItemBase.getItemBase(7); + public static ItemBase stoneIB = ItemBase.getItemBase(1580000); + public static ItemBase truesteelIB = ItemBase.getItemBase(1580001); + public static ItemBase ironIB = ItemBase.getItemBase(1580002); + public static ItemBase adamantIB = ItemBase.getItemBase(1580003); + public static ItemBase lumberIB = ItemBase.getItemBase(1580004); + public static ItemBase oakIB = ItemBase.getItemBase(1580005); + public static ItemBase bronzewoodIB = ItemBase.getItemBase(1580006); + public static ItemBase mandrakeIB = ItemBase.getItemBase(1580007); + public static ItemBase coalIB = ItemBase.getItemBase(1580008); + public static ItemBase agateIB = ItemBase.getItemBase(1580009); + public static ItemBase diamondIB = ItemBase.getItemBase(1580010); + public static ItemBase onyxIB = ItemBase.getItemBase(1580011); + public static ItemBase azothIB = ItemBase.getItemBase(1580012); + public static ItemBase orichalkIB = ItemBase.getItemBase(1580013); + public static ItemBase antimonyIB = ItemBase.getItemBase(1580014); + public static ItemBase sulferIB = ItemBase.getItemBase(1580015); + public static ItemBase quicksilverIB = ItemBase.getItemBase(1580016); + public static ItemBase galvorIB = ItemBase.getItemBase(1580017); + public static ItemBase wormwoodIB = ItemBase.getItemBase(1580018); + public static ItemBase obsidianIB = ItemBase.getItemBase(1580019); + public static ItemBase bloodstoneIB = ItemBase.getItemBase(1580020); + public static ItemBase mithrilIB = ItemBase.getItemBase(1580021); + public static ConcurrentHashMap maxResources = new ConcurrentHashMap<>(); + public static ConcurrentHashMap warehouseByBuildingUUID = new ConcurrentHashMap<>(); + public EnumBitSet lockedResourceTypes; + private int UID; + private int buildingUID; + private ArrayList transactions = new ArrayList<>(); + private ConcurrentHashMap resources = new ConcurrentHashMap<>(); + + + /** + * ResultSet Constructor + */ + public Warehouse(ResultSet rs) throws SQLException { + super(rs); + this.UID = rs.getInt("UID"); + this.resources.put(stoneIB, rs.getInt("warehouse_stone")); + this.resources.put(truesteelIB, rs.getInt("warehouse_truesteel")); + this.resources.put(ironIB, rs.getInt("warehouse_iron")); + this.resources.put(adamantIB, rs.getInt("warehouse_adamant")); + this.resources.put(lumberIB, rs.getInt("warehouse_lumber")); + this.resources.put(oakIB, rs.getInt("warehouse_oak")); + this.resources.put(bronzewoodIB, rs.getInt("warehouse_bronzewood")); + this.resources.put(mandrakeIB, rs.getInt("warehouse_mandrake")); + this.resources.put(coalIB, rs.getInt("warehouse_coal")); + this.resources.put(agateIB, rs.getInt("warehouse_agate")); + this.resources.put(diamondIB, rs.getInt("warehouse_diamond")); + this.resources.put(onyxIB, rs.getInt("warehouse_onyx")); + this.resources.put(azothIB, rs.getInt("warehouse_azoth")); + this.resources.put(orichalkIB, rs.getInt("warehouse_orichalk")); + this.resources.put(antimonyIB, rs.getInt("warehouse_antimony")); + this.resources.put(sulferIB, rs.getInt("warehouse_sulfur")); + this.resources.put(quicksilverIB, rs.getInt("warehouse_quicksilver")); + this.resources.put(galvorIB, rs.getInt("warehouse_galvor")); + this.resources.put(wormwoodIB, rs.getInt("warehouse_wormwood")); + this.resources.put(obsidianIB, rs.getInt("warehouse_obsidian")); + this.resources.put(bloodstoneIB, rs.getInt("warehouse_bloodstone")); + this.resources.put(mithrilIB, rs.getInt("warehouse_mithril")); + this.resources.put(goldIB, rs.getInt("warehouse_gold")); + this.lockedResourceTypes = EnumBitSet.asEnumBitSet(rs.getLong("warehouse_locks"), Enum.ResourceType.class); + this.buildingUID = rs.getInt("parent"); + Warehouse.warehouseByBuildingUUID.put(this.buildingUID, this); + } + + public static ConcurrentHashMap getMaxResources() { + if (maxResources.size() != 23) { + maxResources.put(7, 100000000); + maxResources.put(1580000, 10000); + maxResources.put(1580001, 2000); + maxResources.put(1580002, 2000); + maxResources.put(1580003, 1000); + maxResources.put(1580004, 10000); + maxResources.put(1580005, 3000); + maxResources.put(1580006, 3000); + maxResources.put(1580007, 1000); + maxResources.put(1580008, 3000); + maxResources.put(1580009, 2000); + maxResources.put(1580010, 2000); + maxResources.put(1580011, 1000); + maxResources.put(1580012, 2000); + maxResources.put(1580013, 3000); + maxResources.put(1580014, 1000); + maxResources.put(1580015, 1000); + maxResources.put(1580016, 1000); + maxResources.put(1580017, 500); + maxResources.put(1580018, 500); + maxResources.put(1580019, 500); + maxResources.put(1580020, 500); + maxResources.put(1580021, 500); + } + + return maxResources; + } public static void warehouseDeposit(MerchantMsg msg, PlayerCharacter player, NPC npc, ClientConnection origin) { - Building warehouseBuilding; - Warehouse warehouse; - int depositAmount; - Dispatch dispatch; + Building warehouseBuilding; + Warehouse warehouse; + int depositAmount; + Dispatch dispatch; - Item resource = Item.getFromCache(msg.getItemID()); + Item resource = Item.getFromCache(msg.getItemID()); - if (resource == null) - return; + if (resource == null) + return; - depositAmount = msg.getAmount(); - CharacterItemManager itemMan = player.getCharItemManager(); + depositAmount = msg.getAmount(); + CharacterItemManager itemMan = player.getCharItemManager(); - if (itemMan.doesCharOwnThisItem(resource.getObjectUUID()) == false) - return; + if (itemMan.doesCharOwnThisItem(resource.getObjectUUID()) == false) + return; - warehouseBuilding = npc.getBuilding(); + warehouseBuilding = npc.getBuilding(); - if (warehouseBuilding == null) - return; + if (warehouseBuilding == null) + return; - warehouse = warehouseByBuildingUUID.get(warehouseBuilding.getObjectUUID()); + warehouse = warehouseByBuildingUUID.get(warehouseBuilding.getObjectUUID()); - if (warehouse == null) - return; + if (warehouse == null) + return; - ItemBase ib = resource.getItemBase(); + ItemBase ib = resource.getItemBase(); - if (!warehouse.deposit(player, resource, depositAmount, true,true)) { - // ChatManager.chatGuildError(player, "Failed to deposit " + ib.getName() +"."); - // Logger.debug("OpenWindow", player.getName() + " Failed to deposit Item with ID " + resource.getObjectUUID() + " from Warehouse With ID = " + warehouseBuilding.getObjectUUID()); - return; - } + if (!warehouse.deposit(player, resource, depositAmount, true, true)) { + // ChatManager.chatGuildError(player, "Failed to deposit " + ib.getName() +"."); + // Logger.debug("OpenWindow", player.getName() + " Failed to deposit Item with ID " + resource.getObjectUUID() + " from Warehouse With ID = " + warehouseBuilding.getObjectUUID()); + return; + } - ViewResourcesMessage vrm = new ViewResourcesMessage(player); - vrm.setGuild(player.getGuild()); - vrm.setWarehouseBuilding(warehouseBuilding); - vrm.configure(); - dispatch = Dispatch.borrow(player, vrm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } + ViewResourcesMessage vrm = new ViewResourcesMessage(player); + vrm.setGuild(player.getGuild()); + vrm.setWarehouseBuilding(warehouseBuilding); + vrm.configure(); + dispatch = Dispatch.borrow(player, vrm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } public static void warehouseWithdraw(MerchantMsg msg, PlayerCharacter player, NPC npc, ClientConnection origin) { - int withdrawAmount; - Building warehouseBuilding; - Warehouse warehouse; - Dispatch dispatch; + int withdrawAmount; + Building warehouseBuilding; + Warehouse warehouse; + Dispatch dispatch; + + withdrawAmount = msg.getAmount(); + warehouseBuilding = npc.getBuilding(); + + if (warehouseBuilding == null) + return; + + if (player.getGuild() != warehouseBuilding.getGuild() || GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false) + return; + + warehouse = warehouseByBuildingUUID.get(warehouseBuilding.getObjectUUID()); + + if (warehouse == null) + return; + + int hashID = msg.getHashID(); + int itemBaseID = ItemBase.getItemHashIDMap().get(hashID); + ItemBase ib = ItemBase.getItemBase(itemBaseID); + + if (ib == null) { + Logger.debug("Failed to find Resource ItemBaseID with Hash ID = " + hashID); + return; + } + + if (warehouse.isResourceLocked(ib) == true) { + ChatManager.chatSystemInfo(player, "You cannot withdrawl a locked resource."); + return; + } + if (!warehouse.withdraw(player, ib, withdrawAmount, true, true)) { + ChatManager.chatGuildError(player, "Failed to withdrawl " + ib.getName() + '.'); + Logger.debug(player.getName() + " Failed to withdrawl =" + ib.getName() + " from Warehouse With ID = " + warehouseBuilding.getObjectUUID()); + return; + } + + ViewResourcesMessage vrm = new ViewResourcesMessage(player); + vrm.setGuild(player.getGuild()); + vrm.setWarehouseBuilding(warehouseBuilding); + vrm.configure(); + dispatch = Dispatch.borrow(player, vrm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } - withdrawAmount = msg.getAmount(); - warehouseBuilding = npc.getBuilding(); + public static void warehouseLock(MerchantMsg msg, PlayerCharacter player, NPC npc, ClientConnection origin) { + Building warehouse; + int hashID; + Dispatch dispatch; - if (warehouseBuilding == null) - return; + hashID = msg.getHashID(); + warehouse = npc.getBuilding(); - if (player.getGuild() != warehouseBuilding.getGuild() || GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false) - return; + if (warehouse == null) + return; - warehouse = warehouseByBuildingUUID.get(warehouseBuilding.getObjectUUID()); + if (player.getGuild() != warehouse.getGuild() || GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false) + return; - if (warehouse == null) - return; + Warehouse wh = warehouseByBuildingUUID.get(warehouse.getObjectUUID()); - int hashID = msg.getHashID(); - int itemBaseID = ItemBase.getItemHashIDMap().get(hashID); - ItemBase ib = ItemBase.getItemBase(itemBaseID); + if (wh == null) + return; - if (ib == null) { - Logger.debug("Failed to find Resource ItemBaseID with Hash ID = " + hashID); - return; - } + int itemBaseID = ItemBase.getItemHashIDMap().get(hashID); + ItemBase ib = ItemBase.getItemBase(itemBaseID); - if (warehouse.isResourceLocked(ib) == true) { - ChatManager.chatSystemInfo(player, "You cannot withdrawl a locked resource."); - return; - } - if (!warehouse.withdraw(player, ib, withdrawAmount, true,true)) { - ChatManager.chatGuildError(player, "Failed to withdrawl " + ib.getName() + '.'); - Logger.debug(player.getName() + " Failed to withdrawl =" + ib.getName() + " from Warehouse With ID = " + warehouseBuilding.getObjectUUID()); - return; - } + if (ib == null) + return; - ViewResourcesMessage vrm = new ViewResourcesMessage(player); - vrm.setGuild(player.getGuild()); - vrm.setWarehouseBuilding(warehouseBuilding); - vrm.configure(); - dispatch = Dispatch.borrow(player, vrm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } + if (wh.isResourceLocked(ib) == true) { + boolean worked = false; + EnumBitSet bitSet = EnumBitSet.asEnumBitSet(wh.lockedResourceTypes.toLong(), ResourceType.class); - public static void warehouseLock(MerchantMsg msg, PlayerCharacter player, NPC npc, ClientConnection origin) { - Building warehouse; - int hashID; - Dispatch dispatch; - - hashID = msg.getHashID(); - warehouse = npc.getBuilding(); - - if (warehouse == null) - return; - - if (player.getGuild() != warehouse.getGuild() || GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false) - return; - - Warehouse wh = warehouseByBuildingUUID.get(warehouse.getObjectUUID()); - - if (wh == null) - return; - - int itemBaseID = ItemBase.getItemHashIDMap().get(hashID); - ItemBase ib = ItemBase.getItemBase(itemBaseID); - - if (ib == null) - return; - - if (wh.isResourceLocked(ib) == true) { - boolean worked = false; - EnumBitSet bitSet = EnumBitSet.asEnumBitSet(wh.lockedResourceTypes.toLong(), ResourceType.class); - - bitSet.remove(ResourceType.resourceLookup.get(itemBaseID)); - - worked = DbManager.WarehouseQueries.updateLocks(wh, bitSet.toLong()); - - if (worked) { - wh.lockedResourceTypes.remove(Enum.ResourceType.resourceLookup.get(itemBaseID)); - ViewResourcesMessage vrm = new ViewResourcesMessage(player); - vrm.setGuild(player.getGuild()); - vrm.setWarehouseBuilding(warehouse); - vrm.configure(); - dispatch = Dispatch.borrow(player, vrm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } - return; - } + bitSet.remove(ResourceType.resourceLookup.get(itemBaseID)); + + worked = DbManager.WarehouseQueries.updateLocks(wh, bitSet.toLong()); + + if (worked) { + wh.lockedResourceTypes.remove(Enum.ResourceType.resourceLookup.get(itemBaseID)); + ViewResourcesMessage vrm = new ViewResourcesMessage(player); + vrm.setGuild(player.getGuild()); + vrm.setWarehouseBuilding(warehouse); + vrm.configure(); + dispatch = Dispatch.borrow(player, vrm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } + return; + } + + EnumBitSet bitSet = EnumBitSet.asEnumBitSet(wh.lockedResourceTypes.toLong(), ResourceType.class); + + bitSet.add(ResourceType.resourceLookup.get(itemBaseID)); + + if (DbManager.WarehouseQueries.updateLocks(wh, bitSet.toLong()) == false) + return; + + wh.lockedResourceTypes.add(Enum.ResourceType.resourceLookup.get(itemBaseID)); + ViewResourcesMessage vrm = new ViewResourcesMessage(player); + vrm.setGuild(player.getGuild()); + vrm.setWarehouseBuilding(warehouse); + vrm.configure(); + dispatch = Dispatch.borrow(player, vrm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + } + + public ConcurrentHashMap getResources() { + return resources; + } + + public int getUID() { + return UID; + } - EnumBitSet bitSet = EnumBitSet.asEnumBitSet(wh.lockedResourceTypes.toLong(), ResourceType.class); - - bitSet.add(ResourceType.resourceLookup.get(itemBaseID)); - - if (DbManager.WarehouseQueries.updateLocks(wh,bitSet.toLong()) == false) - return; - - wh.lockedResourceTypes.add(Enum.ResourceType.resourceLookup.get(itemBaseID)); - ViewResourcesMessage vrm = new ViewResourcesMessage(player); - vrm.setGuild(player.getGuild()); - vrm.setWarehouseBuilding(warehouse); - vrm.configure(); - dispatch = Dispatch.borrow(player, vrm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - } - - public ConcurrentHashMap getResources() { - return resources; - } - - public int getUID() { - return UID; - } - - public void setUID(int uID) { - UID = uID; - } - - public synchronized boolean deposit(PlayerCharacter pc,Item resource, int amount,boolean removeFromInventory, boolean transaction){ - - ClientConnection origin = pc.getClientConnection(); - if (origin == null) - return false; - - if (amount < 0){ - Logger.info(pc.getFirstName() + " Attempting to Dupe!!!!!!"); - return false; - } - - ItemBase ib = resource.getItemBase(); - - if (ib == null) - return false; - - if (this.resources.get(ib) == null) - return false; - - CharacterItemManager itemMan = pc.getCharItemManager(); - - if (itemMan == null) - return false; - - - if (itemMan.getGoldTrading() > 0){ - ErrorPopupMsg.sendErrorPopup(pc, 195); - return false; - } - - - if (!itemMan.doesCharOwnThisItem(resource.getObjectUUID())) - return false; - - if (!resource.validForInventory(origin, pc, itemMan)) - return false; - - if (resource.getNumOfItems() < amount) - return false; - - int oldAmount = resources.get(ib); - - int newAmount = oldAmount + amount; - - if (newAmount > Warehouse.getMaxResources().get(ib.getUUID())){ - //ChatManager.chatSystemInfo(pc, "The Warehouse is at it's maximum for this type of resource."); - return false; - } - - - if (removeFromInventory){ - if (ib.getUUID() == 7){ - - if (itemMan.getGoldInventory().getNumOfItems() -amount < 0) - return false; - - if (itemMan.getGoldInventory().getNumOfItems() - amount > MBServerStatics.PLAYER_GOLD_LIMIT) - return false; - - if (!itemMan.modifyInventoryGold(-amount)){ - //ChatManager.chatSystemError(pc, "You do not have this Gold."); - return false; - } - - UpdateGoldMsg ugm = new UpdateGoldMsg(pc); - ugm.configure(); - Dispatch dispatch = Dispatch.borrow(pc, ugm); - DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - - itemMan.updateInventory(); - - }else{ - itemMan.delete(resource); - itemMan.updateInventory(); - } - } - itemMan.updateInventory(); - int itemID = ib.getUUID(); - boolean worked = false; - switch(itemID){ - case 7: - worked = DbManager.WarehouseQueries.updateGold(this, newAmount); - break; - case 1580000: - worked = DbManager.WarehouseQueries.updateStone(this, newAmount); - break; - case 1580001: - worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); - break; - case 1580002: - worked = DbManager.WarehouseQueries.updateIron(this, newAmount); - break; - case 1580003: - worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); - break; - case 1580004: - worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); - break; - case 1580005: - worked = DbManager.WarehouseQueries.updateOak(this, newAmount); - break; - case 1580006: - worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); - break; - case 1580007: - worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); - break; - case 1580008: - worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); - break; - case 1580009: - worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); - break; - case 1580010: - worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); - break; - case 1580011: - worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); - break; - case 1580012: - worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); - break; - case 1580013: - worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); - break; - case 1580014: - worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); - break; - case 1580015: - worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); - break; - case 1580016: - worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); - break; - case 1580017: - worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); - break; - case 1580018: - worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); - break; - case 1580019: - worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); - break; - case 1580020: - worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); - break; - case 1580021: - worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); - break; - } - - if (!worked) - return false; - - resources.put(ib,newAmount); - - Resource resourceType; - - if (resource.getItemBase().getType().equals(engine.Enum.ItemType.GOLD)) - resourceType = Resource.GOLD; - else - resourceType = Resource.valueOf(resource.getItemBase().getName().toUpperCase()); - - if (transaction) - this.AddTransactionToWarehouse(pc.getObjectType(), pc.getObjectUUID(), TransactionType.DEPOSIT,resourceType, amount); - - return true; - } - - //for mine deposit - public synchronized boolean depositFromMine(Mine mine,ItemBase resource, int amount){ + public void setUID(int uID) { + UID = uID; + } + + public synchronized boolean deposit(PlayerCharacter pc, Item resource, int amount, boolean removeFromInventory, boolean transaction) { + + ClientConnection origin = pc.getClientConnection(); + if (origin == null) + return false; + + if (amount < 0) { + Logger.info(pc.getFirstName() + " Attempting to Dupe!!!!!!"); + return false; + } + + ItemBase ib = resource.getItemBase(); + + if (ib == null) + return false; + + if (this.resources.get(ib) == null) + return false; + + CharacterItemManager itemMan = pc.getCharItemManager(); + + if (itemMan == null) + return false; + + + if (itemMan.getGoldTrading() > 0) { + ErrorPopupMsg.sendErrorPopup(pc, 195); + return false; + } + + + if (!itemMan.doesCharOwnThisItem(resource.getObjectUUID())) + return false; + + if (!resource.validForInventory(origin, pc, itemMan)) + return false; + + if (resource.getNumOfItems() < amount) + return false; + + int oldAmount = resources.get(ib); + + int newAmount = oldAmount + amount; + + if (newAmount > Warehouse.getMaxResources().get(ib.getUUID())) { + //ChatManager.chatSystemInfo(pc, "The Warehouse is at it's maximum for this type of resource."); + return false; + } + + + if (removeFromInventory) { + if (ib.getUUID() == 7) { + + if (itemMan.getGoldInventory().getNumOfItems() - amount < 0) + return false; + + if (itemMan.getGoldInventory().getNumOfItems() - amount > MBServerStatics.PLAYER_GOLD_LIMIT) + return false; + + if (!itemMan.modifyInventoryGold(-amount)) { + //ChatManager.chatSystemError(pc, "You do not have this Gold."); + return false; + } + + UpdateGoldMsg ugm = new UpdateGoldMsg(pc); + ugm.configure(); + Dispatch dispatch = Dispatch.borrow(pc, ugm); + DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + + itemMan.updateInventory(); + + } else { + itemMan.delete(resource); + itemMan.updateInventory(); + } + } + itemMan.updateInventory(); + int itemID = ib.getUUID(); + boolean worked = false; + switch (itemID) { + case 7: + worked = DbManager.WarehouseQueries.updateGold(this, newAmount); + break; + case 1580000: + worked = DbManager.WarehouseQueries.updateStone(this, newAmount); + break; + case 1580001: + worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); + break; + case 1580002: + worked = DbManager.WarehouseQueries.updateIron(this, newAmount); + break; + case 1580003: + worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); + break; + case 1580004: + worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); + break; + case 1580005: + worked = DbManager.WarehouseQueries.updateOak(this, newAmount); + break; + case 1580006: + worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); + break; + case 1580007: + worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); + break; + case 1580008: + worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); + break; + case 1580009: + worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); + break; + case 1580010: + worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); + break; + case 1580011: + worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); + break; + case 1580012: + worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); + break; + case 1580013: + worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); + break; + case 1580014: + worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); + break; + case 1580015: + worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); + break; + case 1580016: + worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); + break; + case 1580017: + worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); + break; + case 1580018: + worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); + break; + case 1580019: + worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); + break; + case 1580020: + worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); + break; + case 1580021: + worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); + break; + } + + if (!worked) + return false; + + resources.put(ib, newAmount); + + Resource resourceType; + + if (resource.getItemBase().getType().equals(engine.Enum.ItemType.GOLD)) + resourceType = Resource.GOLD; + else + resourceType = Resource.valueOf(resource.getItemBase().getName().toUpperCase()); + + if (transaction) + this.AddTransactionToWarehouse(pc.getObjectType(), pc.getObjectUUID(), TransactionType.DEPOSIT, resourceType, amount); + + return true; + } + + //for mine deposit + public synchronized boolean depositFromMine(Mine mine, ItemBase resource, int amount) { if (resource == null) - return false; - - if (this.resources.get(resource) == null) - return false; - - int oldAmount = resources.get(resource); - int newAmount = oldAmount + amount; - - if (newAmount > Warehouse.getMaxResources().get(resource.getUUID())) - return false; - - int itemID = resource.getUUID(); - boolean worked = false; - - switch(itemID){ - case 7: - worked = DbManager.WarehouseQueries.updateGold(this, newAmount); - break; - case 1580000: - worked = DbManager.WarehouseQueries.updateStone(this, newAmount); - break; - case 1580001: - worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); - break; - case 1580002: - worked = DbManager.WarehouseQueries.updateIron(this, newAmount); - break; - case 1580003: - worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); - break; - case 1580004: - worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); - break; - case 1580005: - worked = DbManager.WarehouseQueries.updateOak(this, newAmount); - break; - case 1580006: - worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); - break; - case 1580007: - worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); - break; - case 1580008: - worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); - break; - case 1580009: - worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); - break; - case 1580010: - worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); - break; - case 1580011: - worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); - break; - case 1580012: - worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); - break; - case 1580013: - worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); - break; - case 1580014: - worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); - break; - case 1580015: - worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); - break; - case 1580016: - worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); - break; - case 1580017: - worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); - break; - case 1580018: - worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); - break; - case 1580019: - worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); - break; - case 1580020: - worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); - break; - case 1580021: - worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); - break; - } - if (!worked) - return false; - - this.resources.put(resource, newAmount); - Resource resourceType; - - if (resource.getUUID() == 7) - resourceType = Resource.GOLD; - else - resourceType = Resource.valueOf(resource.getName().toUpperCase()); - - if (mine != null) - this.AddTransactionToWarehouse(GameObjectType.Building, mine.getBuildingID(), TransactionType.MINE, resourceType, amount); - - return true; - } - - public synchronized boolean depositRealmTaxes(PlayerCharacter taxer, ItemBase ib,int amount){ - - if (ib == null) - return false; - - if (this.resources.get(ib) == null) - return false; - - int oldAmount = resources.get(ib); - int newAmount = oldAmount + amount; - - if (newAmount > Warehouse.getMaxResources().get(ib.getUUID())) - return false; - - int itemID = ib.getUUID(); - boolean worked = false; - - switch(itemID){ - case 7: - worked = DbManager.WarehouseQueries.updateGold(this, newAmount); - break; - case 1580000: - worked = DbManager.WarehouseQueries.updateStone(this, newAmount); - break; - case 1580001: - worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); - break; - case 1580002: - worked = DbManager.WarehouseQueries.updateIron(this, newAmount); - break; - case 1580003: - worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); - break; - case 1580004: - worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); - break; - case 1580005: - worked = DbManager.WarehouseQueries.updateOak(this, newAmount); - break; - case 1580006: - worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); - break; - case 1580007: - worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); - break; - case 1580008: - worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); - break; - case 1580009: - worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); - break; - case 1580010: - worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); - break; - case 1580011: - worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); - break; - case 1580012: - worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); - break; - case 1580013: - worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); - break; - case 1580014: - worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); - break; - case 1580015: - worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); - break; - case 1580016: - worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); - break; - case 1580017: - worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); - break; - case 1580018: - worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); - break; - case 1580019: - worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); - break; - case 1580020: - worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); - break; - case 1580021: - worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); - break; - } - - if (!worked) - return false; - - this.resources.put(ib, newAmount); - Resource resourceType; - - if (ib.getUUID() == 7) - resourceType = Resource.GOLD; - else - resourceType = Resource.valueOf(ib.getName().toUpperCase()); - - this.AddTransactionToWarehouse(taxer.getObjectType(), taxer.getObjectUUID(), TransactionType.TAXRESOURCEDEPOSIT, resourceType, amount); - - return true; - } - - public synchronized boolean depositProfitTax(ItemBase ib,int amount,Building building){ - - if (ib == null) - return false; - - if (this.resources.get(ib) == null) - return false; - - int oldAmount = resources.get(ib); - int newAmount = oldAmount + amount; - - if (newAmount > Warehouse.getMaxResources().get(ib.getUUID())) - return false; - - int itemID = ib.getUUID(); - boolean worked = false; - - switch(itemID){ - case 7: - worked = DbManager.WarehouseQueries.updateGold(this, newAmount); - break; - case 1580000: - worked = DbManager.WarehouseQueries.updateStone(this, newAmount); - break; - case 1580001: - worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); - break; - case 1580002: - worked = DbManager.WarehouseQueries.updateIron(this, newAmount); - break; - case 1580003: - worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); - break; - case 1580004: - worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); - break; - case 1580005: - worked = DbManager.WarehouseQueries.updateOak(this, newAmount); - break; - case 1580006: - worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); - break; - case 1580007: - worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); - break; - case 1580008: - worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); - break; - case 1580009: - worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); - break; - case 1580010: - worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); - break; - case 1580011: - worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); - break; - case 1580012: - worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); - break; - case 1580013: - worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); - break; - case 1580014: - worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); - break; - case 1580015: - worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); - break; - case 1580016: - worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); - break; - case 1580017: - worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); - break; - case 1580018: - worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); - break; - case 1580019: - worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); - break; - case 1580020: - worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); - break; - case 1580021: - worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); - break; - } - - if (!worked) - return false; - - this.resources.put(ib, newAmount); - Resource resourceType; - - if (ib.getUUID() == 7) - resourceType = Resource.GOLD; - else - resourceType = Resource.valueOf(ib.getName().toUpperCase()); - - if (building != null) - this.AddTransactionToWarehouse(GameObjectType.Building, building.getObjectUUID(), TransactionType.DEPOSIT, resourceType, amount); - - return true; - } - public synchronized boolean withdraw(PlayerCharacter pc, ItemBase ib, int amount, boolean addToInventory, boolean transaction){ - - if (pc == null) - return false; - - if (ib == null) - return false; - - if (this.resources.get(ib) == null) - return false; - - if (amount <= 0) - return false; - - CharacterItemManager itemMan = pc.getCharItemManager(); - - if(itemMan == null) - return false; - - if (addToInventory) - if(!itemMan.hasRoomInventory(ib.getWeight())) { - ChatManager.chatSystemInfo(pc, "You can not carry any more of that item."); - return false; - } - - if (addToInventory && ib.getUUID() == ItemBase.GOLD_BASE_ID){ - if (pc.getCharItemManager().getGoldInventory().getNumOfItems() + amount > MBServerStatics.PLAYER_GOLD_LIMIT){ - return false; - } - - if (pc.getCharItemManager().getGoldInventory().getNumOfItems() + amount < 0) - return false; - } - int oldAmount = this.resources.get(ib); - - if (oldAmount < amount) - return false; - - int hashID = ib.getHashID(); - int newAmount = oldAmount - amount; - - boolean worked = false; - - switch(hashID){ - case 2308551: - worked = DbManager.WarehouseQueries.updateGold(this,newAmount); - break; - case 74856115: - worked = DbManager.WarehouseQueries.updateStone(this, newAmount); - break; - case -317484979: - worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); - break; - case 2504297: - worked = DbManager.WarehouseQueries.updateIron(this, newAmount); - break; - case -1741189964: - worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); - break; - case -1603256692: - worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); - break; - case 74767: - worked = DbManager.WarehouseQueries.updateOak(this, newAmount); - break; - case 1334770447: - worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); - break; - case 1191391799: - worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); - break; - case 2559427: - worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); - break; - case 75173057: - worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); - break; - case -1730704107: - worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); - break; - case 2977263: - worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); - break; - case 78329697: - worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); - break; - case -2036290524: - worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); - break; - case 452320058: - worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); - break; - case -1586349421: - worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); - break; - case -472884509: - worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); - break; - case -1596311545: - worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); - break; - case 1532478436: - worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); - break; - case -697973233: - worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); - break; - case -1569826353: - worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); - break; - case -1761257186: - worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); - break; - } - if (!worked) - return false; - - this.resources.put(ib, newAmount); - - if (addToInventory){ - if (ib.getUUID() == 7){ - - itemMan.addGoldToInventory(amount, false); - UpdateGoldMsg ugm = new UpdateGoldMsg(pc); - ugm.configure(); - Dispatch dispatch = Dispatch.borrow(pc, ugm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - itemMan.updateInventory(); - }else{ - boolean itemWorked = false; - Item item = new Item( ib, pc.getObjectUUID(), OwnerType.PlayerCharacter, (byte) 0, (byte) 0, - (short) 1, (short) 1, true, false,ItemContainerType.INVENTORY, (byte) 0, - new ArrayList<>(),""); - item.setNumOfItems(amount); - item.containerType = Enum.ItemContainerType.INVENTORY; - - try { - item = DbManager.ItemQueries.ADD_ITEM(item); - itemWorked = true; - } catch (Exception e) { - Logger.error(e); - } - if (itemWorked) { - itemMan.addItemToInventory(item); - itemMan.updateInventory(); - } - } - } - Resource resourceType; - - if (ib.getUUID() == 7) - resourceType = Resource.GOLD; - else - resourceType = Resource.valueOf(ib.getName().toUpperCase()); - - if (transaction) - this.AddTransactionToWarehouse(pc.getObjectType(), pc.getObjectUUID(), TransactionType.WITHDRAWL, resourceType, amount); - - return true; - } - - public synchronized boolean withdraw(NPC npc, ItemBase ib, int amount, boolean addToInventory, boolean transaction){ - - if (npc == null) - return false; - - if (ib == null) - return false; - - if (this.resources.get(ib) == null) - return false; - - if (amount <= 0) - return false; - - int oldAmount = this.resources.get(ib); - - if (oldAmount < amount) - return false; - - int hashID = ib.getHashID(); - int newAmount = oldAmount - amount; - boolean worked = false; - - switch(hashID){ - case 2308551: - worked = DbManager.WarehouseQueries.updateGold(this,newAmount); - break; - case 74856115: - worked = DbManager.WarehouseQueries.updateStone(this, newAmount); - break; - case -317484979: - worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); - break; - case 2504297: - worked = DbManager.WarehouseQueries.updateIron(this, newAmount); - break; - case -1741189964: - worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); - break; - case -1603256692: - worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); - break; - case 74767: - worked = DbManager.WarehouseQueries.updateOak(this, newAmount); - break; - case 1334770447: - worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); - break; - case 1191391799: - worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); - break; - case 2559427: - worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); - break; - case 75173057: - worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); - break; - case -1730704107: - worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); - break; - case 2977263: - worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); - break; - case 78329697: - worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); - break; - case -2036290524: - worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); - break; - case 452320058: - worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); - break; - case -1586349421: - worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); - break; - case -472884509: - worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); - break; - case -1596311545: - worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); - break; - case 1532478436: - worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); - break; - case -697973233: - worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); - break; - case -1569826353: - worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); - break; - case -1761257186: - worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); - break; - } - - if (!worked) - return false; - - this.resources.put(ib, newAmount); - Resource resourceType; - - if (ib.getUUID() == 7) - resourceType = Resource.GOLD; - else - resourceType = Resource.valueOf(ib.getName().toUpperCase()); - - if (transaction) - this.AddTransactionToWarehouse(npc.getObjectType(), npc.getObjectUUID(), TransactionType.WITHDRAWL, resourceType, amount); - - return true; - } - - public synchronized boolean transferResources(PlayerCharacter taxer, TaxResourcesMsg msg, ArrayList realmResources, float taxPercent, Warehouse toWarehouse){ - - for (int ibID: realmResources){ - - ItemBase ib = ItemBase.getItemBase(ibID); - - if (ib == null) - return false; - - if (this.resources.get(ib) == null) - return false; - - int amount = (int) (this.resources.get(ib) * taxPercent); - - if (amount <= 0){ - msg.getResources().put(ib.getHashID(), 0); - continue; - } - - int oldAmount = this.resources.get(ib); - - if (oldAmount < amount) - amount = oldAmount; - - int hashID = ib.getHashID(); - int newAmount = oldAmount - amount; - - if (newAmount < amount) - continue; - - boolean worked = false; - - switch(hashID){ - case 2308551: - worked = DbManager.WarehouseQueries.updateGold(this,newAmount); - break; - case 74856115: - worked = DbManager.WarehouseQueries.updateStone(this, newAmount); - break; - case -317484979: - worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); - break; - case 2504297: - worked = DbManager.WarehouseQueries.updateIron(this, newAmount); - break; - case -1741189964: - worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); - break; - case -1603256692: - worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); - break; - case 74767: - worked = DbManager.WarehouseQueries.updateOak(this, newAmount); - break; - case 1334770447: - worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); - break; - case 1191391799: - worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); - break; - case 2559427: - worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); - break; - case 75173057: - worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); - break; - case -1730704107: - worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); - break; - case 2977263: - worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); - break; - case 78329697: - worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); - break; - case -2036290524: - worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); - break; - case 452320058: - worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); - break; - case -1586349421: - worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); - break; - case -472884509: - worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); - break; - case -1596311545: - worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); - break; - case 1532478436: - worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); - break; - case -697973233: - worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); - break; - case -1569826353: - worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); - break; - case -1761257186: - worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); - break; - } - - if (!worked){ - msg.getResources().put(ib.getHashID(), 0); - continue; - } - - msg.getResources().put(ib.getHashID(), amount); - - this.resources.put(ib, newAmount); - toWarehouse.depositRealmTaxes(taxer,ib, amount); - Resource resourceType; - - if (ib.getUUID() == 7) - resourceType = Resource.GOLD; - else - resourceType = Resource.valueOf(ib.getName().toUpperCase()); - - this.AddTransactionToWarehouse(taxer.getObjectType(), taxer.getObjectUUID(), TransactionType.TAXRESOURCE, resourceType, amount); - - } - return true; - } - - public synchronized boolean loot(PlayerCharacter pc, ItemBase ib, int amount, boolean addToInventory){ - - if (pc == null) - return false; - - if (ib == null) - return false; - - if (this.resources.get(ib) == null) - return false; - - if (amount <= 0) - return false; - - CharacterItemManager itemMan = pc.getCharItemManager(); - - if(itemMan == null) - return false; - - if(!itemMan.hasRoomInventory(ib.getWeight())) { - ChatManager.chatSystemInfo(pc, "You can not carry any more of that item."); - return false; - } - - int oldAmount = this.resources.get(ib); - - if (oldAmount < amount) - return false; - - int newAmount = oldAmount - amount; - - this.resources.put(ib, newAmount); - - if (addToInventory){ - if (ib.getUUID() == 7){ - - itemMan.addGoldToInventory(amount, false); - UpdateGoldMsg ugm = new UpdateGoldMsg(pc); - ugm.configure(); - Dispatch dispatch = Dispatch.borrow(pc, ugm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - itemMan.updateInventory(); - }else{ - boolean itemWorked = false; - Item item = new Item(ib, pc.getObjectUUID(), OwnerType.PlayerCharacter, (byte) 0, (byte) 0, - (short) 1, (short) 1, true, false,ItemContainerType.INVENTORY, (byte) 0, - new ArrayList<>(),""); - item.setNumOfItems(amount); - item.containerType = Enum.ItemContainerType.INVENTORY; - - try { - item = DbManager.ItemQueries.ADD_ITEM(item); - itemWorked = true; - } catch (Exception e) { - Logger.error(e); - } - if (itemWorked) { - itemMan.addItemToInventory(item); - itemMan.updateInventory(); - } - } - } - - return true; - } - - @Override - public void updateDatabase() { - // TODO Auto-generated method stub - - } - @Override - public void runAfterLoad() { - - try{ - Building warehouseBuilding = BuildingManager.getBuilding(this.buildingUID); - Logger.info("configuring warehouse " + UID + " for city " + warehouseBuilding.getCity().getCityName() + " structure UUID " + this.buildingUID); - - //Building is gone, but Warehouse still in DB?? Should never happen, sanity check anyway. - if (warehouseBuilding == null){ - Logger.error( "Failed to load Building for Warehouse"); - return; - } - - Zone cityZone = warehouseBuilding.getParentZone(); - - if (cityZone == null){ - Logger.error( "Failed to load Zone for Warehouse with UUID " + this.getObjectUUID()); - return; - } - - City city = City.getCity(cityZone.getPlayerCityUUID()); + return false; + + if (this.resources.get(resource) == null) + return false; + + int oldAmount = resources.get(resource); + int newAmount = oldAmount + amount; + + if (newAmount > Warehouse.getMaxResources().get(resource.getUUID())) + return false; + + int itemID = resource.getUUID(); + boolean worked = false; + + switch (itemID) { + case 7: + worked = DbManager.WarehouseQueries.updateGold(this, newAmount); + break; + case 1580000: + worked = DbManager.WarehouseQueries.updateStone(this, newAmount); + break; + case 1580001: + worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); + break; + case 1580002: + worked = DbManager.WarehouseQueries.updateIron(this, newAmount); + break; + case 1580003: + worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); + break; + case 1580004: + worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); + break; + case 1580005: + worked = DbManager.WarehouseQueries.updateOak(this, newAmount); + break; + case 1580006: + worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); + break; + case 1580007: + worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); + break; + case 1580008: + worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); + break; + case 1580009: + worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); + break; + case 1580010: + worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); + break; + case 1580011: + worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); + break; + case 1580012: + worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); + break; + case 1580013: + worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); + break; + case 1580014: + worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); + break; + case 1580015: + worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); + break; + case 1580016: + worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); + break; + case 1580017: + worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); + break; + case 1580018: + worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); + break; + case 1580019: + worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); + break; + case 1580020: + worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); + break; + case 1580021: + worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); + break; + } + if (!worked) + return false; + + this.resources.put(resource, newAmount); + Resource resourceType; + + if (resource.getUUID() == 7) + resourceType = Resource.GOLD; + else + resourceType = Resource.valueOf(resource.getName().toUpperCase()); + + if (mine != null) + this.AddTransactionToWarehouse(GameObjectType.Building, mine.getBuildingID(), TransactionType.MINE, resourceType, amount); + + return true; + } + + public synchronized boolean depositRealmTaxes(PlayerCharacter taxer, ItemBase ib, int amount) { + + if (ib == null) + return false; + + if (this.resources.get(ib) == null) + return false; + + int oldAmount = resources.get(ib); + int newAmount = oldAmount + amount; + + if (newAmount > Warehouse.getMaxResources().get(ib.getUUID())) + return false; + + int itemID = ib.getUUID(); + boolean worked = false; + + switch (itemID) { + case 7: + worked = DbManager.WarehouseQueries.updateGold(this, newAmount); + break; + case 1580000: + worked = DbManager.WarehouseQueries.updateStone(this, newAmount); + break; + case 1580001: + worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); + break; + case 1580002: + worked = DbManager.WarehouseQueries.updateIron(this, newAmount); + break; + case 1580003: + worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); + break; + case 1580004: + worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); + break; + case 1580005: + worked = DbManager.WarehouseQueries.updateOak(this, newAmount); + break; + case 1580006: + worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); + break; + case 1580007: + worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); + break; + case 1580008: + worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); + break; + case 1580009: + worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); + break; + case 1580010: + worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); + break; + case 1580011: + worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); + break; + case 1580012: + worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); + break; + case 1580013: + worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); + break; + case 1580014: + worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); + break; + case 1580015: + worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); + break; + case 1580016: + worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); + break; + case 1580017: + worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); + break; + case 1580018: + worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); + break; + case 1580019: + worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); + break; + case 1580020: + worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); + break; + case 1580021: + worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); + break; + } + + if (!worked) + return false; + + this.resources.put(ib, newAmount); + Resource resourceType; + + if (ib.getUUID() == 7) + resourceType = Resource.GOLD; + else + resourceType = Resource.valueOf(ib.getName().toUpperCase()); + + this.AddTransactionToWarehouse(taxer.getObjectType(), taxer.getObjectUUID(), TransactionType.TAXRESOURCEDEPOSIT, resourceType, amount); + + return true; + } + + public synchronized boolean depositProfitTax(ItemBase ib, int amount, Building building) { + + if (ib == null) + return false; + + if (this.resources.get(ib) == null) + return false; + + int oldAmount = resources.get(ib); + int newAmount = oldAmount + amount; + + if (newAmount > Warehouse.getMaxResources().get(ib.getUUID())) + return false; + + int itemID = ib.getUUID(); + boolean worked = false; + + switch (itemID) { + case 7: + worked = DbManager.WarehouseQueries.updateGold(this, newAmount); + break; + case 1580000: + worked = DbManager.WarehouseQueries.updateStone(this, newAmount); + break; + case 1580001: + worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); + break; + case 1580002: + worked = DbManager.WarehouseQueries.updateIron(this, newAmount); + break; + case 1580003: + worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); + break; + case 1580004: + worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); + break; + case 1580005: + worked = DbManager.WarehouseQueries.updateOak(this, newAmount); + break; + case 1580006: + worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); + break; + case 1580007: + worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); + break; + case 1580008: + worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); + break; + case 1580009: + worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); + break; + case 1580010: + worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); + break; + case 1580011: + worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); + break; + case 1580012: + worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); + break; + case 1580013: + worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); + break; + case 1580014: + worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); + break; + case 1580015: + worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); + break; + case 1580016: + worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); + break; + case 1580017: + worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); + break; + case 1580018: + worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); + break; + case 1580019: + worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); + break; + case 1580020: + worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); + break; + case 1580021: + worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); + break; + } + + if (!worked) + return false; + + this.resources.put(ib, newAmount); + Resource resourceType; + + if (ib.getUUID() == 7) + resourceType = Resource.GOLD; + else + resourceType = Resource.valueOf(ib.getName().toUpperCase()); + + if (building != null) + this.AddTransactionToWarehouse(GameObjectType.Building, building.getObjectUUID(), TransactionType.DEPOSIT, resourceType, amount); + + return true; + } + + public synchronized boolean withdraw(PlayerCharacter pc, ItemBase ib, int amount, boolean addToInventory, boolean transaction) { + + if (pc == null) + return false; + + if (ib == null) + return false; + + if (this.resources.get(ib) == null) + return false; + + if (amount <= 0) + return false; + + CharacterItemManager itemMan = pc.getCharItemManager(); + + if (itemMan == null) + return false; + + if (addToInventory) + if (!itemMan.hasRoomInventory(ib.getWeight())) { + ChatManager.chatSystemInfo(pc, "You can not carry any more of that item."); + return false; + } + + if (addToInventory && ib.getUUID() == ItemBase.GOLD_BASE_ID) { + if (pc.getCharItemManager().getGoldInventory().getNumOfItems() + amount > MBServerStatics.PLAYER_GOLD_LIMIT) { + return false; + } + + if (pc.getCharItemManager().getGoldInventory().getNumOfItems() + amount < 0) + return false; + } + int oldAmount = this.resources.get(ib); + + if (oldAmount < amount) + return false; + + int hashID = ib.getHashID(); + int newAmount = oldAmount - amount; + + boolean worked = false; + + switch (hashID) { + case 2308551: + worked = DbManager.WarehouseQueries.updateGold(this, newAmount); + break; + case 74856115: + worked = DbManager.WarehouseQueries.updateStone(this, newAmount); + break; + case -317484979: + worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); + break; + case 2504297: + worked = DbManager.WarehouseQueries.updateIron(this, newAmount); + break; + case -1741189964: + worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); + break; + case -1603256692: + worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); + break; + case 74767: + worked = DbManager.WarehouseQueries.updateOak(this, newAmount); + break; + case 1334770447: + worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); + break; + case 1191391799: + worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); + break; + case 2559427: + worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); + break; + case 75173057: + worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); + break; + case -1730704107: + worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); + break; + case 2977263: + worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); + break; + case 78329697: + worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); + break; + case -2036290524: + worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); + break; + case 452320058: + worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); + break; + case -1586349421: + worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); + break; + case -472884509: + worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); + break; + case -1596311545: + worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); + break; + case 1532478436: + worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); + break; + case -697973233: + worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); + break; + case -1569826353: + worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); + break; + case -1761257186: + worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); + break; + } + if (!worked) + return false; + + this.resources.put(ib, newAmount); + + if (addToInventory) { + if (ib.getUUID() == 7) { + + itemMan.addGoldToInventory(amount, false); + UpdateGoldMsg ugm = new UpdateGoldMsg(pc); + ugm.configure(); + Dispatch dispatch = Dispatch.borrow(pc, ugm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + itemMan.updateInventory(); + } else { + boolean itemWorked = false; + Item item = new Item(ib, pc.getObjectUUID(), OwnerType.PlayerCharacter, (byte) 0, (byte) 0, + (short) 1, (short) 1, true, false, ItemContainerType.INVENTORY, (byte) 0, + new ArrayList<>(), ""); + item.setNumOfItems(amount); + item.containerType = Enum.ItemContainerType.INVENTORY; + + try { + item = DbManager.ItemQueries.ADD_ITEM(item); + itemWorked = true; + } catch (Exception e) { + Logger.error(e); + } + if (itemWorked) { + itemMan.addItemToInventory(item); + itemMan.updateInventory(); + } + } + } + Resource resourceType; + + if (ib.getUUID() == 7) + resourceType = Resource.GOLD; + else + resourceType = Resource.valueOf(ib.getName().toUpperCase()); + + if (transaction) + this.AddTransactionToWarehouse(pc.getObjectType(), pc.getObjectUUID(), TransactionType.WITHDRAWL, resourceType, amount); + + return true; + } + + public synchronized boolean withdraw(NPC npc, ItemBase ib, int amount, boolean addToInventory, boolean transaction) { + + if (npc == null) + return false; + + if (ib == null) + return false; + + if (this.resources.get(ib) == null) + return false; + + if (amount <= 0) + return false; + + int oldAmount = this.resources.get(ib); + + if (oldAmount < amount) + return false; + + int hashID = ib.getHashID(); + int newAmount = oldAmount - amount; + boolean worked = false; + + switch (hashID) { + case 2308551: + worked = DbManager.WarehouseQueries.updateGold(this, newAmount); + break; + case 74856115: + worked = DbManager.WarehouseQueries.updateStone(this, newAmount); + break; + case -317484979: + worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); + break; + case 2504297: + worked = DbManager.WarehouseQueries.updateIron(this, newAmount); + break; + case -1741189964: + worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); + break; + case -1603256692: + worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); + break; + case 74767: + worked = DbManager.WarehouseQueries.updateOak(this, newAmount); + break; + case 1334770447: + worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); + break; + case 1191391799: + worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); + break; + case 2559427: + worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); + break; + case 75173057: + worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); + break; + case -1730704107: + worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); + break; + case 2977263: + worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); + break; + case 78329697: + worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); + break; + case -2036290524: + worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); + break; + case 452320058: + worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); + break; + case -1586349421: + worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); + break; + case -472884509: + worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); + break; + case -1596311545: + worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); + break; + case 1532478436: + worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); + break; + case -697973233: + worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); + break; + case -1569826353: + worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); + break; + case -1761257186: + worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); + break; + } + + if (!worked) + return false; + + this.resources.put(ib, newAmount); + Resource resourceType; + + if (ib.getUUID() == 7) + resourceType = Resource.GOLD; + else + resourceType = Resource.valueOf(ib.getName().toUpperCase()); + + if (transaction) + this.AddTransactionToWarehouse(npc.getObjectType(), npc.getObjectUUID(), TransactionType.WITHDRAWL, resourceType, amount); + + return true; + } + + public synchronized boolean transferResources(PlayerCharacter taxer, TaxResourcesMsg msg, ArrayList realmResources, float taxPercent, Warehouse toWarehouse) { + + for (int ibID : realmResources) { + + ItemBase ib = ItemBase.getItemBase(ibID); + + if (ib == null) + return false; + + if (this.resources.get(ib) == null) + return false; + + int amount = (int) (this.resources.get(ib) * taxPercent); + + if (amount <= 0) { + msg.getResources().put(ib.getHashID(), 0); + continue; + } + + int oldAmount = this.resources.get(ib); + + if (oldAmount < amount) + amount = oldAmount; + + int hashID = ib.getHashID(); + int newAmount = oldAmount - amount; + + if (newAmount < amount) + continue; + + boolean worked = false; + + switch (hashID) { + case 2308551: + worked = DbManager.WarehouseQueries.updateGold(this, newAmount); + break; + case 74856115: + worked = DbManager.WarehouseQueries.updateStone(this, newAmount); + break; + case -317484979: + worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); + break; + case 2504297: + worked = DbManager.WarehouseQueries.updateIron(this, newAmount); + break; + case -1741189964: + worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); + break; + case -1603256692: + worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); + break; + case 74767: + worked = DbManager.WarehouseQueries.updateOak(this, newAmount); + break; + case 1334770447: + worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); + break; + case 1191391799: + worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); + break; + case 2559427: + worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); + break; + case 75173057: + worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); + break; + case -1730704107: + worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); + break; + case 2977263: + worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); + break; + case 78329697: + worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); + break; + case -2036290524: + worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); + break; + case 452320058: + worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); + break; + case -1586349421: + worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); + break; + case -472884509: + worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); + break; + case -1596311545: + worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); + break; + case 1532478436: + worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); + break; + case -697973233: + worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); + break; + case -1569826353: + worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); + break; + case -1761257186: + worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); + break; + } + + if (!worked) { + msg.getResources().put(ib.getHashID(), 0); + continue; + } + + msg.getResources().put(ib.getHashID(), amount); + + this.resources.put(ib, newAmount); + toWarehouse.depositRealmTaxes(taxer, ib, amount); + Resource resourceType; + + if (ib.getUUID() == 7) + resourceType = Resource.GOLD; + else + resourceType = Resource.valueOf(ib.getName().toUpperCase()); + + this.AddTransactionToWarehouse(taxer.getObjectType(), taxer.getObjectUUID(), TransactionType.TAXRESOURCE, resourceType, amount); + + } + return true; + } + + public synchronized boolean loot(PlayerCharacter pc, ItemBase ib, int amount, boolean addToInventory) { + + if (pc == null) + return false; + + if (ib == null) + return false; + + if (this.resources.get(ib) == null) + return false; - if (city == null){ - Logger.error( "Failed to load City for Warehouse with UUID " + this.getObjectUUID()); - return; - } + if (amount <= 0) + return false; - warehouseByBuildingUUID.put(this.buildingUID, this); - city.setWarehouseBuildingID(this.buildingUID); - }catch(Exception E){ - Logger.info(this.getObjectUUID() + " failed"); - - } - } - - public boolean isEmpty(){ - int amount = 0; - for(ItemBase ib: ItemBase.getResourceList()){ - if (amount > 0) - return false; + CharacterItemManager itemMan = pc.getCharItemManager(); + + if (itemMan == null) + return false; + + if (!itemMan.hasRoomInventory(ib.getWeight())) { + ChatManager.chatSystemInfo(pc, "You can not carry any more of that item."); + return false; + } + + int oldAmount = this.resources.get(ib); + + if (oldAmount < amount) + return false; + + int newAmount = oldAmount - amount; + + this.resources.put(ib, newAmount); + + if (addToInventory) { + if (ib.getUUID() == 7) { + + itemMan.addGoldToInventory(amount, false); + UpdateGoldMsg ugm = new UpdateGoldMsg(pc); + ugm.configure(); + Dispatch dispatch = Dispatch.borrow(pc, ugm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + itemMan.updateInventory(); + } else { + boolean itemWorked = false; + Item item = new Item(ib, pc.getObjectUUID(), OwnerType.PlayerCharacter, (byte) 0, (byte) 0, + (short) 1, (short) 1, true, false, ItemContainerType.INVENTORY, (byte) 0, + new ArrayList<>(), ""); + item.setNumOfItems(amount); + item.containerType = Enum.ItemContainerType.INVENTORY; + + try { + item = DbManager.ItemQueries.ADD_ITEM(item); + itemWorked = true; + } catch (Exception e) { + Logger.error(e); + } + if (itemWorked) { + itemMan.addItemToInventory(item); + itemMan.updateInventory(); + } + } + } + + return true; + } + + @Override + public void updateDatabase() { + // TODO Auto-generated method stub + + } + + @Override + public void runAfterLoad() { + + try { + Building warehouseBuilding = BuildingManager.getBuilding(this.buildingUID); + Logger.info("configuring warehouse " + UID + " for city " + warehouseBuilding.getCity().getCityName() + " structure UUID " + this.buildingUID); + + //Building is gone, but Warehouse still in DB?? Should never happen, sanity check anyway. + if (warehouseBuilding == null) { + Logger.error("Failed to load Building for Warehouse"); + return; + } + + Zone cityZone = warehouseBuilding.getParentZone(); + + if (cityZone == null) { + Logger.error("Failed to load Zone for Warehouse with UUID " + this.getObjectUUID()); + return; + } + + City city = City.getCity(cityZone.getPlayerCityUUID()); + + if (city == null) { + Logger.error("Failed to load City for Warehouse with UUID " + this.getObjectUUID()); + return; + } + + warehouseByBuildingUUID.put(this.buildingUID, this); + city.setWarehouseBuildingID(this.buildingUID); + } catch (Exception E) { + Logger.info(this.getObjectUUID() + " failed"); + + } + } + + public boolean isEmpty() { + int amount = 0; + for (ItemBase ib : ItemBase.getResourceList()) { + if (amount > 0) + return false; amount += resources.get(ib); - } - return true; - } - - public int getBuildingUID() { - return buildingUID; - } - - public void loadAllTransactions(){ - this.transactions = DbManager.WarehouseQueries.GET_TRANSACTIONS_FOR_WAREHOUSE(this.buildingUID); - } - - public boolean AddTransactionToWarehouse(GameObjectType targetType, int targetUUID, TransactionType transactionType,Resource resource, int amount){ - - - if (!DbManager.WarehouseQueries.CREATE_TRANSACTION(this.buildingUID, targetType, targetUUID, transactionType, resource, amount, DateTime.now())) - return false; - - Transaction transaction = new Transaction(this.buildingUID,targetType,targetUUID,transactionType,resource,amount, DateTime.now()); - this.transactions.add(transaction); - return true; - } - - public ArrayList getTransactions() { - return transactions; - } - - public boolean isAboveCap(ItemBase ib, int deposit){ - int newAmount = this.resources.get(ib) + deposit; + } + return true; + } + + public int getBuildingUID() { + return buildingUID; + } + + public void loadAllTransactions() { + this.transactions = DbManager.WarehouseQueries.GET_TRANSACTIONS_FOR_WAREHOUSE(this.buildingUID); + } + + public boolean AddTransactionToWarehouse(GameObjectType targetType, int targetUUID, TransactionType transactionType, Resource resource, int amount) { + + + if (!DbManager.WarehouseQueries.CREATE_TRANSACTION(this.buildingUID, targetType, targetUUID, transactionType, resource, amount, DateTime.now())) + return false; + + Transaction transaction = new Transaction(this.buildingUID, targetType, targetUUID, transactionType, resource, amount, DateTime.now()); + this.transactions.add(transaction); + return true; + } + + public ArrayList getTransactions() { + return transactions; + } + + public boolean isAboveCap(ItemBase ib, int deposit) { + int newAmount = this.resources.get(ib) + deposit; return newAmount > Warehouse.getMaxResources().get(ib.getUUID()); } diff --git a/src/engine/objects/Zone.java b/src/engine/objects/Zone.java index 8fddf5d5..f3a8a8fc 100644 --- a/src/engine/objects/Zone.java +++ b/src/engine/objects/Zone.java @@ -30,396 +30,396 @@ import java.util.concurrent.ConcurrentHashMap; public class Zone extends AbstractGameObject { - public final Set zoneBuildingSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); - public final Set zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); - public final Set zoneMobSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); - private final int playerCityID; - private final String zoneName; - private final float xCoord; - private final float zCoord; - private final float yCoord; - private final int loadNum; - private final byte safeZone; - private final String Icon1; - private final String Icon2; - private final String Icon3; - public float absX = 0.0f; - public float absY = 0.0f; - public float absZ = 0.0f; - public int minLvl; - public int maxLvl; - public boolean hasBeenHotzone = false; - private ArrayList nodes = null; - private int parentZoneID; - private Zone parent = null; - private Bounds bounds; - private boolean isNPCCity = false; - private boolean isPlayerCity = false; - private String hash; - private float worldAltitude = 0; - private float seaLevel = 0; - - /** - * ResultSet Constructor - */ - public Zone(ResultSet rs) throws SQLException { - super(rs); - this.parentZoneID = rs.getInt("parent"); - this.playerCityID = rs.getInt("isPlayerCity"); - this.isPlayerCity = this.playerCityID != 0; - this.zoneName = rs.getString("Name"); - this.xCoord = rs.getFloat("XCoord"); - this.zCoord = rs.getFloat("ZCoord"); - this.yCoord = rs.getFloat("YOffset"); - this.loadNum = rs.getInt("LoadNum"); - this.safeZone = rs.getByte("SafeZone"); - this.Icon1 = rs.getString("Icon1"); - this.Icon2 = rs.getString("Icon2"); - this.Icon3 = rs.getString("Icon3"); - this.hash = rs.getString("hash"); - - this.minLvl = rs.getInt("minLvl"); - this.maxLvl = rs.getInt("maxLvl"); - - //this needs to be here specifically for new zones created after server boot (e.g. player city zones) - Zone parentZone = ZoneManager.getZoneByUUID(parentZoneID); - - this.setParent(parentZone); - - if (this.minLvl == 0 && parentZone != null) { - this.minLvl = parentZone.minLvl; - this.maxLvl = parentZone.maxLvl; - } - - if (parentZone != null) - parentZone.addNode(this); - - // If zone doesn't yet hava a hash then write it back to the zone table - - if (hash == null) - setHash(); - - - } - - public static void serializeForClientMsg(Zone zone, ByteBufferWriter writer) { - - if (zone.loadNum == 0 && zone.playerCityID == 0) - Logger.warn("Warning! WorldServerMap with ID " + zone.getObjectUUID() + " has a loadnum of 0 (player city) and no city linked. This will probably crash the client!"); - - // Player City Terraform values serialized here. - - if (zone.playerCityID > 0) { - writer.put((byte) 1); // Player City - True - writer.putFloat(Enum.CityBoundsType.ZONE.extents); - writer.putFloat(Enum.CityBoundsType.ZONE.extents); - } else - writer.put((byte) 0); // Player City - False - - writer.putFloat(zone.xCoord); - writer.putFloat(zone.zCoord); - writer.putFloat(zone.yCoord); - - writer.putInt(0); - writer.putInt(0); - writer.putInt(zone.loadNum); - - if (zone.playerCityID > 0) { - City k = City.getCity(zone.playerCityID); - - if (k != null) { - writer.putInt(k.getObjectType().ordinal()); - writer.putInt(k.getObjectUUID()); - } else - writer.putLong(0x0); - } else { - writer.putInt(zone.getObjectType().ordinal()); - writer.putInt(zone.getObjectUUID()); - } - writer.putInt(zone.nodes.size()); - - City city = City.getCity(zone.playerCityID); - - if (city != null) - writer.putString(city.getCityName()); - else - writer.putString(zone.zoneName); - writer.put(zone.safeZone); - writer.putString(zone.Icon1); - writer.putString(zone.Icon2); - writer.putString(zone.Icon3); - writer.put((byte) 0); // Pad + public final Set zoneBuildingSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); + public final Set zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); + public final Set zoneMobSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); + private final int playerCityID; + private final String zoneName; + private final float xCoord; + private final float zCoord; + private final float yCoord; + private final int loadNum; + private final byte safeZone; + private final String Icon1; + private final String Icon2; + private final String Icon3; + public float absX = 0.0f; + public float absY = 0.0f; + public float absZ = 0.0f; + public int minLvl; + public int maxLvl; + public boolean hasBeenHotzone = false; + private ArrayList nodes = null; + private int parentZoneID; + private Zone parent = null; + private Bounds bounds; + private boolean isNPCCity = false; + private boolean isPlayerCity = false; + private String hash; + private float worldAltitude = 0; + private float seaLevel = 0; + + /** + * ResultSet Constructor + */ + public Zone(ResultSet rs) throws SQLException { + super(rs); + this.parentZoneID = rs.getInt("parent"); + this.playerCityID = rs.getInt("isPlayerCity"); + this.isPlayerCity = this.playerCityID != 0; + this.zoneName = rs.getString("Name"); + this.xCoord = rs.getFloat("XCoord"); + this.zCoord = rs.getFloat("ZCoord"); + this.yCoord = rs.getFloat("YOffset"); + this.loadNum = rs.getInt("LoadNum"); + this.safeZone = rs.getByte("SafeZone"); + this.Icon1 = rs.getString("Icon1"); + this.Icon2 = rs.getString("Icon2"); + this.Icon3 = rs.getString("Icon3"); + this.hash = rs.getString("hash"); + + this.minLvl = rs.getInt("minLvl"); + this.maxLvl = rs.getInt("maxLvl"); + + //this needs to be here specifically for new zones created after server boot (e.g. player city zones) + Zone parentZone = ZoneManager.getZoneByUUID(parentZoneID); + + this.setParent(parentZone); + + if (this.minLvl == 0 && parentZone != null) { + this.minLvl = parentZone.minLvl; + this.maxLvl = parentZone.maxLvl; + } + + if (parentZone != null) + parentZone.addNode(this); + + // If zone doesn't yet hava a hash then write it back to the zone table + + if (hash == null) + setHash(); + + + } + + public static void serializeForClientMsg(Zone zone, ByteBufferWriter writer) { + + if (zone.loadNum == 0 && zone.playerCityID == 0) + Logger.warn("Warning! WorldServerMap with ID " + zone.getObjectUUID() + " has a loadnum of 0 (player city) and no city linked. This will probably crash the client!"); + + // Player City Terraform values serialized here. + + if (zone.playerCityID > 0) { + writer.put((byte) 1); // Player City - True + writer.putFloat(Enum.CityBoundsType.ZONE.extents); + writer.putFloat(Enum.CityBoundsType.ZONE.extents); + } else + writer.put((byte) 0); // Player City - False + + writer.putFloat(zone.xCoord); + writer.putFloat(zone.zCoord); + writer.putFloat(zone.yCoord); + + writer.putInt(0); + writer.putInt(0); + writer.putInt(zone.loadNum); + + if (zone.playerCityID > 0) { + City k = City.getCity(zone.playerCityID); + + if (k != null) { + writer.putInt(k.getObjectType().ordinal()); + writer.putInt(k.getObjectUUID()); + } else + writer.putLong(0x0); + } else { + writer.putInt(zone.getObjectType().ordinal()); + writer.putInt(zone.getObjectUUID()); + } + writer.putInt(zone.nodes.size()); + + City city = City.getCity(zone.playerCityID); + + if (city != null) + writer.putString(city.getCityName()); + else + writer.putString(zone.zoneName); + writer.put(zone.safeZone); + writer.putString(zone.Icon1); + writer.putString(zone.Icon2); + writer.putString(zone.Icon3); + writer.put((byte) 0); // Pad - for (Zone child : zone.nodes) { - Zone.serializeForClientMsg(child, writer); - } - } + for (Zone child : zone.nodes) { + Zone.serializeForClientMsg(child, writer); + } + } - /* Method sets a default value for player cities - * otherwise using values derived from the loadnum - * field in the obj_zone database table. - */ - public void setBounds() { + /* Method sets a default value for player cities + * otherwise using values derived from the loadnum + * field in the obj_zone database table. + */ + public void setBounds() { - float halfExtentX; - float halfExtentY; + float halfExtentX; + float halfExtentY; - // Set initial bounds object + // Set initial bounds object - this.bounds = Bounds.borrow(); + this.bounds = Bounds.borrow(); - // Player cities are assigned default value + // Player cities are assigned default value - if (this.loadNum == 0) { - bounds.setBounds(new Vector2f(this.absX, this.absZ), new Vector2f(Enum.CityBoundsType.ZONE.extents, Enum.CityBoundsType.ZONE.extents), 0.0f); - return; - } + if (this.loadNum == 0) { + bounds.setBounds(new Vector2f(this.absX, this.absZ), new Vector2f(Enum.CityBoundsType.ZONE.extents, Enum.CityBoundsType.ZONE.extents), 0.0f); + return; + } - Vector2f zoneSize = ZoneManager._zone_size_data.get(this.loadNum); + Vector2f zoneSize = ZoneManager._zone_size_data.get(this.loadNum); - // Default to player zone size on error? Maybe log this + // Default to player zone size on error? Maybe log this - if (zoneSize != null) - this.bounds.setBounds(new Vector2f(this.absX, this.absZ), zoneSize, 0.0f); - else - bounds.setBounds(new Vector2f(this.absX, this.absZ), new Vector2f(Enum.CityBoundsType.ZONE.extents, Enum.CityBoundsType.ZONE.extents), 0.0f); + if (zoneSize != null) + this.bounds.setBounds(new Vector2f(this.absX, this.absZ), zoneSize, 0.0f); + else + bounds.setBounds(new Vector2f(this.absX, this.absZ), new Vector2f(Enum.CityBoundsType.ZONE.extents, Enum.CityBoundsType.ZONE.extents), 0.0f); - } + } - public int getPlayerCityUUID() { - return this.playerCityID; - } + public int getPlayerCityUUID() { + return this.playerCityID; + } - public String getName() { - return zoneName; - } + public String getName() { + return zoneName; + } - public float getXCoord() { - return xCoord; - } + public float getXCoord() { + return xCoord; + } - public float getYCoord() { - return yCoord; - } + public float getYCoord() { + return yCoord; + } - public float getZCoord() { - return zCoord; - } + public float getZCoord() { + return zCoord; + } - public int getLoadNum() { - return loadNum; - } + public int getLoadNum() { + return loadNum; + } - public byte getSafeZone() { - return safeZone; - } + public byte getSafeZone() { + return safeZone; + } - public String getIcon1() { - return Icon1; - } + public String getIcon1() { + return Icon1; + } - public void generateWorldAltitude() { + public void generateWorldAltitude() { - if (ZoneManager.getSeaFloor().getObjectUUID() == this.getObjectUUID()) { - this.worldAltitude = MBServerStatics.SEA_FLOOR_ALTITUDE; - return; - } + if (ZoneManager.getSeaFloor().getObjectUUID() == this.getObjectUUID()) { + this.worldAltitude = MBServerStatics.SEA_FLOOR_ALTITUDE; + return; + } - Zone parentZone = this.parent; + Zone parentZone = this.parent; - Zone currentZone = this; - float altitude = this.absY; + Zone currentZone = this; + float altitude = this.absY; - //seafloor only zone with null parent; + //seafloor only zone with null parent; - while (parentZone != ZoneManager.getSeaFloor()) { + while (parentZone != ZoneManager.getSeaFloor()) { - if (parentZone.getHeightMap() != null) { + if (parentZone.getHeightMap() != null) { - Vector2f zoneLoc = ZoneManager.worldToZoneSpace(currentZone.getLoc(), parentZone); - altitude += parentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc); + Vector2f zoneLoc = ZoneManager.worldToZoneSpace(currentZone.getLoc(), parentZone); + altitude += parentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc); - } - currentZone = parentZone; - parentZone = parentZone.parent; + } + currentZone = parentZone; + parentZone = parentZone.parent; - } + } - this.worldAltitude = altitude; + this.worldAltitude = altitude; - if (ZoneManager.getSeaFloor().equals(this)) - this.seaLevel = 0; - else if - (this.getHeightMap() != null && this.getHeightMap().getSeaLevel() == 0) { - this.seaLevel = this.parent.seaLevel; + if (ZoneManager.getSeaFloor().equals(this)) + this.seaLevel = 0; + else if + (this.getHeightMap() != null && this.getHeightMap().getSeaLevel() == 0) { + this.seaLevel = this.parent.seaLevel; - } else if (this.getHeightMap() != null) { - this.seaLevel = this.worldAltitude + this.getHeightMap().getSeaLevel(); - } else { - this.seaLevel = this.parent.seaLevel; - } + } else if (this.getHeightMap() != null) { + this.seaLevel = this.worldAltitude + this.getHeightMap().getSeaLevel(); + } else { + this.seaLevel = this.parent.seaLevel; + } - } + } - public Zone getParent() { - return this.parent; - } + public Zone getParent() { + return this.parent; + } - public void setParent(final Zone value) { + public void setParent(final Zone value) { - this.parent = value; - this.parentZoneID = (this.parent != null) ? this.parent.getObjectUUID() : 0; + this.parent = value; + this.parentZoneID = (this.parent != null) ? this.parent.getObjectUUID() : 0; - if (this.parent != null) { - this.absX = this.xCoord + parent.absX; - this.absY = this.yCoord + parent.absY; - this.absZ = this.zCoord + parent.absZ; + if (this.parent != null) { + this.absX = this.xCoord + parent.absX; + this.absY = this.yCoord + parent.absY; + this.absZ = this.zCoord + parent.absZ; - if (this.minLvl == 0 || this.maxLvl == 0) { - this.minLvl = this.parent.minLvl; - this.maxLvl = this.parent.maxLvl; - } - } else { //only the Sea Floor zone does not have a parent - this.absX = this.xCoord; - this.absY = MBServerStatics.SEA_FLOOR_ALTITUDE; - this.absZ = this.zCoord; - } + if (this.minLvl == 0 || this.maxLvl == 0) { + this.minLvl = this.parent.minLvl; + this.maxLvl = this.parent.maxLvl; + } + } else { //only the Sea Floor zone does not have a parent + this.absX = this.xCoord; + this.absY = MBServerStatics.SEA_FLOOR_ALTITUDE; + this.absZ = this.zCoord; + } - // Zone AABB is set here as it's coordinate space is world requiring a parent. - this.setBounds(); + // Zone AABB is set here as it's coordinate space is world requiring a parent. + this.setBounds(); - if (this.getHeightMap() != null && this.getHeightMap().getSeaLevel() != 0) - this.seaLevel = this.getHeightMap().getSeaLevel(); + if (this.getHeightMap() != null && this.getHeightMap().getSeaLevel() != 0) + this.seaLevel = this.getHeightMap().getSeaLevel(); - } + } - public float getAbsX() { - return this.absX; - } + public float getAbsX() { + return this.absX; + } - public float getAbsY() { - return this.absY; - } + public float getAbsY() { + return this.absY; + } - public float getAbsZ() { - return this.absZ; - } + public float getAbsZ() { + return this.absZ; + } - public boolean isMacroZone() { + public boolean isMacroZone() { - // Macro zones have icons. + // Macro zones have icons. - if (this.isPlayerCity == true) - return false; + if (this.isPlayerCity == true) + return false; - if (this.parent == null) - return false; + if (this.parent == null) + return false; - return !this.getIcon1().equals(""); - } + return !this.getIcon1().equals(""); + } - public boolean isNPCCity() { - return this.isNPCCity; - } + public boolean isNPCCity() { + return this.isNPCCity; + } - public void setNPCCity(boolean value) { - this.isNPCCity = value; - } + public void setNPCCity(boolean value) { + this.isNPCCity = value; + } - public boolean isPlayerCity() { - return this.isPlayerCity; - } + public boolean isPlayerCity() { + return this.isPlayerCity; + } - public void setPlayerCity(boolean value) { - this.isPlayerCity = value; - } + public void setPlayerCity(boolean value) { + this.isPlayerCity = value; + } - public Vector3fImmutable getLoc() { - return new Vector3fImmutable(this.absX, this.absY, this.absZ); - } + public Vector3fImmutable getLoc() { + return new Vector3fImmutable(this.absX, this.absY, this.absZ); + } - public int getParentZoneID() { - return this.parentZoneID; - } + public int getParentZoneID() { + return this.parentZoneID; + } - public ArrayList getNodes() { - if (this.nodes == null) { - this.nodes = DbManager.ZoneQueries.GET_MAP_NODES(super.getObjectUUID()); + public ArrayList getNodes() { + if (this.nodes == null) { + this.nodes = DbManager.ZoneQueries.GET_MAP_NODES(super.getObjectUUID()); - //Add reverse lookup for child->parent - if (this.nodes != null) - for (Zone zone : this.nodes) { - zone.setParent(this); - } - } + //Add reverse lookup for child->parent + if (this.nodes != null) + for (Zone zone : this.nodes) { + zone.setParent(this); + } + } - return nodes; - } + return nodes; + } - /* - * Serializing - */ + /* + * Serializing + */ - public void addNode(Zone child) { - this.nodes.add(child); - } + public void addNode(Zone child) { + this.nodes.add(child); + } - @Override - public void updateDatabase() { - // TODO Auto-generated method stub - } + @Override + public void updateDatabase() { + // TODO Auto-generated method stub + } - public boolean isContinent() { + public boolean isContinent() { - if (this.equals(ZoneManager.getSeaFloor())) - return false; + if (this.equals(ZoneManager.getSeaFloor())) + return false; - if (this.getNodes().isEmpty()) - return false; + if (this.getNodes().isEmpty()) + return false; - if (this.getNodes().get(0).isMacroZone()) - return true; + if (this.getNodes().get(0).isMacroZone()) + return true; - return this.getParent().equals(ZoneManager.getSeaFloor()); + return this.getParent().equals(ZoneManager.getSeaFloor()); - } + } - /** - * @return the bounds - */ - public Bounds getBounds() { - return bounds; - } + /** + * @return the bounds + */ + public Bounds getBounds() { + return bounds; + } - public String getHash() { - return hash; - } + public String getHash() { + return hash; + } - public void setHash() { + public void setHash() { - this.hash = DataWarehouse.hasher.encrypt(this.getObjectUUID()); + this.hash = DataWarehouse.hasher.encrypt(this.getObjectUUID()); - // Write hash to player character table + // Write hash to player character table - DataWarehouse.writeHash(Enum.DataRecordType.ZONE, this.getObjectUUID()); - } + DataWarehouse.writeHash(Enum.DataRecordType.ZONE, this.getObjectUUID()); + } - // Return heightmap for this Zone. + // Return heightmap for this Zone. - public HeightMap getHeightMap() { + public HeightMap getHeightMap() { - if (this.isPlayerCity) - return HeightMap.PlayerCityHeightMap; + if (this.isPlayerCity) + return HeightMap.PlayerCityHeightMap; - return HeightMap.heightmapByLoadNum.get(this.loadNum); - } + return HeightMap.heightmapByLoadNum.get(this.loadNum); + } - public float getSeaLevel() { - return seaLevel; - } + public float getSeaLevel() { + return seaLevel; + } - public float getWorldAltitude() { - return worldAltitude; - } + public float getWorldAltitude() { + return worldAltitude; + } } diff --git a/src/engine/pooling/ByteBufferPool.java b/src/engine/pooling/ByteBufferPool.java index ef6459cf..a13fbaf6 100644 --- a/src/engine/pooling/ByteBufferPool.java +++ b/src/engine/pooling/ByteBufferPool.java @@ -15,55 +15,55 @@ import java.nio.ByteBuffer; public class ByteBufferPool extends LinkedObjectPool { - private final int defaultBufferSize; + private final int defaultBufferSize; - public ByteBufferPool(int defaultBufferSize) { - super(ObjectPool.DEFAULT_SIZE); - this.defaultBufferSize = defaultBufferSize; - } + public ByteBufferPool(int defaultBufferSize) { + super(ObjectPool.DEFAULT_SIZE); + this.defaultBufferSize = defaultBufferSize; + } - public ByteBufferPool(int size, int defaultBufferSize) { - super(size); - this.defaultBufferSize = defaultBufferSize; - } + public ByteBufferPool(int size, int defaultBufferSize) { + super(size); + this.defaultBufferSize = defaultBufferSize; + } - @Override - protected ByteBuffer makeNewObject() { - return ByteBuffer.allocate(defaultBufferSize); - } + @Override + protected ByteBuffer makeNewObject() { + return ByteBuffer.allocate(defaultBufferSize); + } - @Override - protected void resetObject(ByteBuffer obj) { - obj.clear(); - } + @Override + protected void resetObject(ByteBuffer obj) { + obj.clear(); + } - @Override - public ByteBuffer get() { + @Override + public ByteBuffer get() { // Logger.debug("ByteBufferPool.get() BB.capacity(): " + bb.capacity() - // + ", bb.pos(): " + bb.position() + ". Pool.size() is now: " - // + this.getPoolSize()); - return super.get(); - } + // + ", bb.pos(): " + bb.position() + ". Pool.size() is now: " + // + this.getPoolSize()); + return super.get(); + } - @Override - public void put(ByteBuffer bb) { - if(bb.isDirect()) - super.put(bb); - // Logger.debug("ByteBufferPool.put() BB.capacity(): " + bb.capacity() - // + ", bb.pos(): " + bb.position() + ". Pool.size() is now: " - // + this.getPoolSize()); - } + @Override + public void put(ByteBuffer bb) { + if (bb.isDirect()) + super.put(bb); + // Logger.debug("ByteBufferPool.put() BB.capacity(): " + bb.capacity() + // + ", bb.pos(): " + bb.position() + ". Pool.size() is now: " + // + this.getPoolSize()); + } - @Override - protected void handlePoolExhaustion() { - Logger.debug("ByteBufferPool(" + defaultBufferSize - + ") exhausted, making more objects."); + @Override + protected void handlePoolExhaustion() { + Logger.debug("ByteBufferPool(" + defaultBufferSize + + ") exhausted, making more objects."); - // If none exist, make (and pool) a few - // Dont sync the loop, let the makeNewObject() - // call return before locking the pool object - for (int i = 0; i < 5; ++i) - this.makeAndAdd(); - } + // If none exist, make (and pool) a few + // Dont sync the loop, let the makeNewObject() + // call return before locking the pool object + for (int i = 0; i < 5; ++i) + this.makeAndAdd(); + } } diff --git a/src/engine/pooling/ConnectionPool.java b/src/engine/pooling/ConnectionPool.java index cb8e240e..0ff76ec2 100644 --- a/src/engine/pooling/ConnectionPool.java +++ b/src/engine/pooling/ConnectionPool.java @@ -1,6 +1,6 @@ /* * Copyright 2013 MagicBane Emulator Project - * All Rights Reserved + * All Rights Reserved */ package engine.pooling; @@ -12,44 +12,44 @@ import java.sql.SQLException; public class ConnectionPool extends LinkedObjectPool { - static { - //Register the Driver - try { - Class.forName("com.mysql.cj.jdbc.Driver").newInstance(); - } catch (InstantiationException | ClassNotFoundException | IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + static { + //Register the Driver + try { + Class.forName("com.mysql.cj.jdbc.Driver").newInstance(); + } catch (InstantiationException | ClassNotFoundException | IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } - public ConnectionPool() { - super(10); - } - - @Override - protected Connection makeNewObject() { - // Protocol - String sqlURI = "jdbc:mysql://"; - sqlURI += ConfigManager.MB_DATABASE_ADDRESS.getValue() + ':' + ConfigManager.MB_DATABASE_PORT.getValue(); - sqlURI += '/' + ConfigManager.MB_DATABASE_NAME.getValue() + '?'; - sqlURI += "useServerPrepStmts=true"; - sqlURI += "&cachePrepStmts=false"; - sqlURI += "&cacheCallableStmts=true"; - sqlURI += "&characterEncoding=utf8"; - - Connection out = null; - try { - out = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(), - ConfigManager.MB_DATABASE_PASS.getValue()); - } catch (SQLException e) { - e.printStackTrace(); - } - - return out; - } - - @Override - protected void resetObject(Connection obj) { - - } + public ConnectionPool() { + super(10); + } + + @Override + protected Connection makeNewObject() { + // Protocol + String sqlURI = "jdbc:mysql://"; + sqlURI += ConfigManager.MB_DATABASE_ADDRESS.getValue() + ':' + ConfigManager.MB_DATABASE_PORT.getValue(); + sqlURI += '/' + ConfigManager.MB_DATABASE_NAME.getValue() + '?'; + sqlURI += "useServerPrepStmts=true"; + sqlURI += "&cachePrepStmts=false"; + sqlURI += "&cacheCallableStmts=true"; + sqlURI += "&characterEncoding=utf8"; + + Connection out = null; + try { + out = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(), + ConfigManager.MB_DATABASE_PASS.getValue()); + } catch (SQLException e) { + e.printStackTrace(); + } + + return out; + } + + @Override + protected void resetObject(Connection obj) { + + } } diff --git a/src/engine/pooling/LinkedObjectPool.java b/src/engine/pooling/LinkedObjectPool.java index 34828c5c..a58b8eda 100644 --- a/src/engine/pooling/LinkedObjectPool.java +++ b/src/engine/pooling/LinkedObjectPool.java @@ -16,127 +16,125 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.atomic.AtomicInteger; public abstract class LinkedObjectPool { - private final LinkedBlockingQueue pool; - private final AtomicInteger poolSize; - - /** - * Constructor that allows the caller to specify initial array size and - * percent of prefill. - * - * @param size - * - initial size for the containing array (pool) - */ - public LinkedObjectPool(int size) { - this.pool = new LinkedBlockingQueue<>(); - this.poolSize = new AtomicInteger(); - } - - /** - * Default Constructor that uses default initial Array size and percent - * prefill values - */ - public LinkedObjectPool() { - this(0); - } - - /** - * Forces pool to add numberOfObjects to the pool. This may cause - * internal ArrayList to resize. - * - * @param numberOfObjects - */ - public void fill(int numberOfObjects) { - for (int i = 0; i < numberOfObjects; ++i) - this.makeAndAdd(); - } - - /** - * Forces subclasses to implement factory routine for object creation. - */ - protected abstract T makeNewObject(); - - /** - * Forces subclasses to implement a way to reset object to a reusable state. - */ - protected abstract void resetObject(T obj); - - /** - * Generic Get routine. If the pool is empty, then one (or more) of T type - * objects will be created. If more than one T is created, then they will be - * put into the pool. One T will always be created and returned. - */ - public T get() { - T obj = pool.poll(); - - if(obj == null) { - //Oops pool is empty.. make a new obj - obj = this.makeNewObject(); - } else { - poolSize.decrementAndGet(); - } - - return obj; - } - - /** - * Generic put routine. If the current pool size is below threshold, this - * object will be pooled, otherwise it will be NULL'ed and scheduled for - * Garbage Collection - * - * @param obj - */ - public void put(T obj) { - //Logger.debug("Objectpool.put(). Pool size: " + pool.size()); - this.resetObject(obj); - this.poolSize.incrementAndGet(); - this.pool.add(obj); - } - - /** - * Helper method. Attempts to create and add a new T object. If this - * fails, an error is logged. - */ - protected final void makeAndAdd() { - T obj = this.makeNewObject(); - if (obj == null) { - Logger.error("Pooling failure: Object creation failed."); - } else { - this.put(obj); - } - } - - /** - * - * @return the current size of the pool, not the maximum capacity of the - * Array holding the pool. - */ - public final int getPoolSize() { - return this.poolSize.get(); - } - - /** - * Culls the pool and removes half of the stored objects. Removed objects - * are NULL'ed and scheduled form Garbage Collection. - * - * @return the number of Objects removed from the pool. - */ - public int cullHalf() { - int full, half; - full = this.getPoolSize(); - if (full < 1) { - return full; - } - - half = (full / 2); - - for (int i = 0; i < (full / 2); ++i) { - T obj = this.pool.poll(); - obj = null; // Null out for GC - } - return half; - } - - protected void handlePoolExhaustion() { - //Not needed in this implementation - } + private final LinkedBlockingQueue pool; + private final AtomicInteger poolSize; + + /** + * Constructor that allows the caller to specify initial array size and + * percent of prefill. + * + * @param size - initial size for the containing array (pool) + */ + public LinkedObjectPool(int size) { + this.pool = new LinkedBlockingQueue<>(); + this.poolSize = new AtomicInteger(); + } + + /** + * Default Constructor that uses default initial Array size and percent + * prefill values + */ + public LinkedObjectPool() { + this(0); + } + + /** + * Forces pool to add numberOfObjects to the pool. This may cause + * internal ArrayList to resize. + * + * @param numberOfObjects + */ + public void fill(int numberOfObjects) { + for (int i = 0; i < numberOfObjects; ++i) + this.makeAndAdd(); + } + + /** + * Forces subclasses to implement factory routine for object creation. + */ + protected abstract T makeNewObject(); + + /** + * Forces subclasses to implement a way to reset object to a reusable state. + */ + protected abstract void resetObject(T obj); + + /** + * Generic Get routine. If the pool is empty, then one (or more) of T type + * objects will be created. If more than one T is created, then they will be + * put into the pool. One T will always be created and returned. + */ + public T get() { + T obj = pool.poll(); + + if (obj == null) { + //Oops pool is empty.. make a new obj + obj = this.makeNewObject(); + } else { + poolSize.decrementAndGet(); + } + + return obj; + } + + /** + * Generic put routine. If the current pool size is below threshold, this + * object will be pooled, otherwise it will be NULL'ed and scheduled for + * Garbage Collection + * + * @param obj + */ + public void put(T obj) { + //Logger.debug("Objectpool.put(). Pool size: " + pool.size()); + this.resetObject(obj); + this.poolSize.incrementAndGet(); + this.pool.add(obj); + } + + /** + * Helper method. Attempts to create and add a new T object. If this + * fails, an error is logged. + */ + protected final void makeAndAdd() { + T obj = this.makeNewObject(); + if (obj == null) { + Logger.error("Pooling failure: Object creation failed."); + } else { + this.put(obj); + } + } + + /** + * @return the current size of the pool, not the maximum capacity of the + * Array holding the pool. + */ + public final int getPoolSize() { + return this.poolSize.get(); + } + + /** + * Culls the pool and removes half of the stored objects. Removed objects + * are NULL'ed and scheduled form Garbage Collection. + * + * @return the number of Objects removed from the pool. + */ + public int cullHalf() { + int full, half; + full = this.getPoolSize(); + if (full < 1) { + return full; + } + + half = (full / 2); + + for (int i = 0; i < (full / 2); ++i) { + T obj = this.pool.poll(); + obj = null; // Null out for GC + } + return half; + } + + protected void handlePoolExhaustion() { + //Not needed in this implementation + } } diff --git a/src/engine/pooling/MultisizeByteBufferPool.java b/src/engine/pooling/MultisizeByteBufferPool.java index 3196c517..18b90336 100644 --- a/src/engine/pooling/MultisizeByteBufferPool.java +++ b/src/engine/pooling/MultisizeByteBufferPool.java @@ -16,175 +16,169 @@ import java.util.HashMap; public class MultisizeByteBufferPool { - /** - * Maps a power of two (0-30) to a BB Pool - */ - private final HashMap powerToPoolMap = new HashMap<>(); - - public MultisizeByteBufferPool() { - super(); - } - - /** - * Gets a ByteBuffer that is of the size 2^powerOfTwo from the - * appropriate pool. - * - * @param powerOfTwo - * int range of 0-30 - * @return - */ - public ByteBuffer getBuffer(int powerOfTwo) { - // Validate input - if (powerOfTwo > 30 || powerOfTwo < 0) { - Logger.error("powerOfTwo out of range (0-30) in getBuffer(). Got: " + powerOfTwo); - return null; - } - - // Check to see if there is a pool for this size - ByteBufferPool bbp = this.getByteBufferPool(powerOfTwo); - return bbp.get(); - } - - /** - * Internal getter to provide synchronization. Adds ByteBufferPool if not mapped. - * - * @param powerOfTwo - * @return - */ - private ByteBufferPool getByteBufferPool(Integer powerOfTwo) { - synchronized (this.powerToPoolMap) { - // Check to see if there is a pool for this size - ByteBufferPool bbp = powerToPoolMap.get(powerOfTwo); - - if (bbp == null) { - bbp = MultisizeByteBufferPool.makeByteBufferPool(powersOfTwo[powerOfTwo]); - this.putByteBufferPool(powerOfTwo, bbp); - } - return bbp; - } - } - - /** - * Internal setter to provide synchronization - * - * @param powerOfTwo - * @param bbp - * @return - */ - private ByteBufferPool putByteBufferPool(Integer powerOfTwo, + /** + * List of the powers of two from 2^0 to 2^30. The index of the array + * corresponds to the power of two. Example: If you'd like to quickly lookup + * 2^19, then reference powersOfTwo[19] + */ + public static final int[] powersOfTwo = { + 1, // 2^0 + 2, // 2^1 + 4, // 2^2 + 8, // 2^3 + 16, // 2^4 + 32, // 2^5 + 64, // 2^6 + 128, // 2^7 + 256, // 2^8 + 512, // 2^9 + 1024, // 2^10 + 2048, // 2^11 + 4096, // 2^12 + 8192, // 2^13 + 16384, // 2^14 + 32768, // 2^15 + 65536, // 2^16 + 131072, // 2^17 + 262144, // 2^18 + 524288, // 2^19 + 1048576, // 2^20 + 2097152, // 2^21 + 4194304, // 2^22 + 8388608, // 2^23 + 16777216, // 2^24 + 33554432, // 2^25 + 67108864, // 2^26 + 134217728, // 2^27 + 268435456, // 2^28 + 536870912, // 2^29 + 1073741824, // 2^30 + }; + /** + * Maps a power of two (0-30) to a BB Pool + */ + private final HashMap powerToPoolMap = new HashMap<>(); + + public MultisizeByteBufferPool() { + super(); + } + + /** + * Returns the next power of two that is larger than or equal too the input + * value + * + * @param value + * @return the power of two that is larger than or equal too the input + * value. A return of -1 indicates out of range. + */ + public static int getPowerThatWillFit(final int value) { + return (value == 0 ? 0 : 32 - Integer.numberOfLeadingZeros(value - 1)); + } + + private static ByteBufferPool makeByteBufferPool(int bbInitialSize) { + return new ByteBufferPool(bbInitialSize); + } + + /** + * Gets a ByteBuffer that is of the size 2^powerOfTwo from the + * appropriate pool. + * + * @param powerOfTwo int range of 0-30 + * @return + */ + public ByteBuffer getBuffer(int powerOfTwo) { + // Validate input + if (powerOfTwo > 30 || powerOfTwo < 0) { + Logger.error("powerOfTwo out of range (0-30) in getBuffer(). Got: " + powerOfTwo); + return null; + } + + // Check to see if there is a pool for this size + ByteBufferPool bbp = this.getByteBufferPool(powerOfTwo); + return bbp.get(); + } + + /** + * Internal getter to provide synchronization. Adds ByteBufferPool if not mapped. + * + * @param powerOfTwo + * @return + */ + private ByteBufferPool getByteBufferPool(Integer powerOfTwo) { + synchronized (this.powerToPoolMap) { + // Check to see if there is a pool for this size + ByteBufferPool bbp = powerToPoolMap.get(powerOfTwo); + + if (bbp == null) { + bbp = MultisizeByteBufferPool.makeByteBufferPool(powersOfTwo[powerOfTwo]); + this.putByteBufferPool(powerOfTwo, bbp); + } + return bbp; + } + } + + /** + * Internal setter to provide synchronization + * + * @param powerOfTwo + * @param bbp + * @return + */ + private ByteBufferPool putByteBufferPool(Integer powerOfTwo, ByteBufferPool bbp) { - synchronized (this.powerToPoolMap) { - return powerToPoolMap.put(powerOfTwo, bbp); - } - } - - public ByteBuffer getBufferToFit(int numOfBytes) { - int pow = MultisizeByteBufferPool.getPowerThatWillFit(numOfBytes); - return this.getBuffer(pow); - } - - /** - * Puts a ByteBuffer that is of the size 2^powerOfTwo back into the - * appropriate pool. - * - * @param bb - * - Bytebuffer to put into a pool - * - */ - public void putBuffer(ByteBuffer bb) { - - if (bb == null) - return; - - // determine size: - int pow = MultisizeByteBufferPool.getPowerThatWillFit(bb.capacity()); - - // if we get here and pow == -1 then we have a bytebuffer > 2^30 !!!! - // so just file it under power of 30; - if (pow == -1) { - pow = 30; - } - - // get pool - ByteBufferPool bbp = this.getByteBufferPool(pow); - - // put buffer (back) into pool - bbp.put(bb); - } - - /** - * Returns the next power of two that is larger than or equal too the input - * value - * - * @param value - * @return the power of two that is larger than or equal too the input - * value. A return of -1 indicates out of range. - */ - public static int getPowerThatWillFit(final int value) { - return (value == 0 ? 0 : 32 - Integer.numberOfLeadingZeros(value - 1)); - } - - private static ByteBufferPool makeByteBufferPool(int bbInitialSize) { - return new ByteBufferPool(bbInitialSize); - } - - /** - * Returns the size of the ByteBufferPool mapped to the given powerOfTwo. - * - * @param powerOfTwo - * int range of 0-30 - * @return size of pool mapped to provided powerOfTwo. Returns -1 on - * error and lastError will be set. - */ - public int getSizeOfPool(int powerOfTwo) { - if (powerOfTwo > 30 || powerOfTwo < 0) { - Logger.error("powerOfTwo out of range (0-30) in getSizeOfPool(). Got: " - + powerOfTwo); - return -1; - } - ByteBufferPool bbp = this.getByteBufferPool(powerOfTwo); - - return bbp.getPoolSize(); - } - - - /** - * List of the powers of two from 2^0 to 2^30. The index of the array - * corresponds to the power of two. Example: If you'd like to quickly lookup - * 2^19, then reference powersOfTwo[19] - */ - public static final int[] powersOfTwo = { - 1, // 2^0 - 2, // 2^1 - 4, // 2^2 - 8, // 2^3 - 16, // 2^4 - 32, // 2^5 - 64, // 2^6 - 128, // 2^7 - 256, // 2^8 - 512, // 2^9 - 1024, // 2^10 - 2048, // 2^11 - 4096, // 2^12 - 8192, // 2^13 - 16384, // 2^14 - 32768, // 2^15 - 65536, // 2^16 - 131072, // 2^17 - 262144, // 2^18 - 524288, // 2^19 - 1048576, // 2^20 - 2097152, // 2^21 - 4194304, // 2^22 - 8388608, // 2^23 - 16777216, // 2^24 - 33554432, // 2^25 - 67108864, // 2^26 - 134217728, // 2^27 - 268435456, // 2^28 - 536870912, // 2^29 - 1073741824, // 2^30 - }; + synchronized (this.powerToPoolMap) { + return powerToPoolMap.put(powerOfTwo, bbp); + } + } + + public ByteBuffer getBufferToFit(int numOfBytes) { + int pow = MultisizeByteBufferPool.getPowerThatWillFit(numOfBytes); + return this.getBuffer(pow); + } + + /** + * Puts a ByteBuffer that is of the size 2^powerOfTwo back into the + * appropriate pool. + * + * @param bb - Bytebuffer to put into a pool + */ + public void putBuffer(ByteBuffer bb) { + + if (bb == null) + return; + + // determine size: + int pow = MultisizeByteBufferPool.getPowerThatWillFit(bb.capacity()); + + // if we get here and pow == -1 then we have a bytebuffer > 2^30 !!!! + // so just file it under power of 30; + if (pow == -1) { + pow = 30; + } + + // get pool + ByteBufferPool bbp = this.getByteBufferPool(pow); + + // put buffer (back) into pool + bbp.put(bb); + } + + /** + * Returns the size of the ByteBufferPool mapped to the given powerOfTwo. + * + * @param powerOfTwo int range of 0-30 + * @return size of pool mapped to provided powerOfTwo. Returns -1 on + * error and lastError will be set. + */ + public int getSizeOfPool(int powerOfTwo) { + if (powerOfTwo > 30 || powerOfTwo < 0) { + Logger.error("powerOfTwo out of range (0-30) in getSizeOfPool(). Got: " + + powerOfTwo); + return -1; + } + ByteBufferPool bbp = this.getByteBufferPool(powerOfTwo); + + return bbp.getPoolSize(); + } } diff --git a/src/engine/pooling/ObjectPool.java b/src/engine/pooling/ObjectPool.java index 5ded922f..3ebfeb9e 100644 --- a/src/engine/pooling/ObjectPool.java +++ b/src/engine/pooling/ObjectPool.java @@ -14,182 +14,179 @@ import org.pmw.tinylog.Logger; import java.util.ArrayList; public abstract class ObjectPool { - protected final static int DEFAULT_SIZE = 1000; - - // Simple + quick list - private final ArrayList pool; - - /** - * Once the ArrayList fills to threshold, subsequent .put() calls - * result in the object being thrown away. Default is 75% of supplied - * size. - */ - private int threshold; - - /** - * Constructor that allows the caller to specify initial array size and - * percent of prefill. - * - * @param size - * - initial size for the containing array (pool) - */ - public ObjectPool(int size) { - if (size == 0) { - size = DEFAULT_SIZE; - } - - threshold = (int) (0.75 * size); - - this.pool = new ArrayList<>(size); - - } - - /** - * Default Constructor that uses default initial Array size and percent - * prefill values - */ - public ObjectPool() { - this(DEFAULT_SIZE); - } - - /** - * Forces pool to add numberOfObjects to the pool. This may cause - * internal ArrayList to resize. - * - * @param numberOfObjects - */ - public void fill(int numberOfObjects) { - for (int i = 0; i < numberOfObjects; ++i) - this.makeAndAdd(); - } - - /** - * Forces subclasses to implement factory routine for object creation. - */ - protected abstract T makeNewObject(); - - /** - * Forces subclasses to implement a way to reset object to a reusable state. - */ - protected abstract void resetObject(T obj); - - /** - * Generic Get routine. If the pool is empty, then one (or more) of T type - * objects will be created. If more than one T is created, then they will be - * put into the pool. One T will always be created and returned. - */ - public T get() { - synchronized (pool) { - //Logger.debug("Objectpool.get(). Pool size before get: " + pool.size()); - if (pool.size() > 0) { - return pool.remove(0); - } - } - - this.handlePoolExhaustion(); - - T obj = this.makeNewObject(); - - if (obj == null) { - Logger.error("Pooling failure: Object creation failed."); - } - return obj; - } - - protected void handlePoolExhaustion(){ - Logger.debug("Pool exhausted, making more objects."); - - // If none exist, make (and pool) a few - // Dont sync the loop, let the makeNewObject() - // call return before locking the pool object - for (int i = 0; i < 5; ++i) - this.makeAndAdd(); - - } - - /** - * Generic put routine. If the current pool size is below threshold, this - * object will be pooled, otherwise it will be NULL'ed and scheduled for - * Garbage Collection - * - * @param obj - */ - public void put(T obj) { - synchronized (pool) { - if (pool.size() >= this.threshold) { - //Logger.debug("Objectpool.put() rejected. Pool size: " + pool.size()); - return; - } - //Logger.debug("Objectpool.put(). Pool size: " + pool.size()); - this.resetObject(obj); - this.pool.add(obj); - } - } - - /** - * Helper method. Attempts to create and add a new T object. If this - * fails, an error is logged. - */ - protected final void makeAndAdd() { - T obj = this.makeNewObject(); - if (obj == null) { - Logger.error("Pooling failure: Object creation failed."); - } else { - this.put(obj); - } - } - - /** - * - * @return the current size of the pool, not the maximum capacity of the - * Array holding the pool. - */ - public final int getPoolSize() { - synchronized (this.pool) { - return this.pool.size(); - } - } - - /** - * Culls the pool and removes half of the stored objects. Removed objects - * are NULL'ed and scheduled form Garbage Collection. - * - * @return the number of Objects removed from the pool. - */ - public int cullHalf() { - int full, half; - synchronized (this.pool) { - full = this.pool.size(); - if (full < 1) { - return full; - } - - half = (full / 2); - - for (int i = 0; i < (full / 2); ++i) { - T obj = this.get(); - obj = null; // Null out for GC - } - } - return half; - } - - /** - * @return the threshold - */ - public final int getThreshold() { - return threshold; - } - - /** - * @param threshold - * the threshold to set - */ - public void setThreshold(int threshold) { - if (threshold < 0) - return; - - this.threshold = threshold; - } + protected final static int DEFAULT_SIZE = 1000; + + // Simple + quick list + private final ArrayList pool; + + /** + * Once the ArrayList fills to threshold, subsequent .put() calls + * result in the object being thrown away. Default is 75% of supplied + * size. + */ + private int threshold; + + /** + * Constructor that allows the caller to specify initial array size and + * percent of prefill. + * + * @param size - initial size for the containing array (pool) + */ + public ObjectPool(int size) { + if (size == 0) { + size = DEFAULT_SIZE; + } + + threshold = (int) (0.75 * size); + + this.pool = new ArrayList<>(size); + + } + + /** + * Default Constructor that uses default initial Array size and percent + * prefill values + */ + public ObjectPool() { + this(DEFAULT_SIZE); + } + + /** + * Forces pool to add numberOfObjects to the pool. This may cause + * internal ArrayList to resize. + * + * @param numberOfObjects + */ + public void fill(int numberOfObjects) { + for (int i = 0; i < numberOfObjects; ++i) + this.makeAndAdd(); + } + + /** + * Forces subclasses to implement factory routine for object creation. + */ + protected abstract T makeNewObject(); + + /** + * Forces subclasses to implement a way to reset object to a reusable state. + */ + protected abstract void resetObject(T obj); + + /** + * Generic Get routine. If the pool is empty, then one (or more) of T type + * objects will be created. If more than one T is created, then they will be + * put into the pool. One T will always be created and returned. + */ + public T get() { + synchronized (pool) { + //Logger.debug("Objectpool.get(). Pool size before get: " + pool.size()); + if (pool.size() > 0) { + return pool.remove(0); + } + } + + this.handlePoolExhaustion(); + + T obj = this.makeNewObject(); + + if (obj == null) { + Logger.error("Pooling failure: Object creation failed."); + } + return obj; + } + + protected void handlePoolExhaustion() { + Logger.debug("Pool exhausted, making more objects."); + + // If none exist, make (and pool) a few + // Dont sync the loop, let the makeNewObject() + // call return before locking the pool object + for (int i = 0; i < 5; ++i) + this.makeAndAdd(); + + } + + /** + * Generic put routine. If the current pool size is below threshold, this + * object will be pooled, otherwise it will be NULL'ed and scheduled for + * Garbage Collection + * + * @param obj + */ + public void put(T obj) { + synchronized (pool) { + if (pool.size() >= this.threshold) { + //Logger.debug("Objectpool.put() rejected. Pool size: " + pool.size()); + return; + } + //Logger.debug("Objectpool.put(). Pool size: " + pool.size()); + this.resetObject(obj); + this.pool.add(obj); + } + } + + /** + * Helper method. Attempts to create and add a new T object. If this + * fails, an error is logged. + */ + protected final void makeAndAdd() { + T obj = this.makeNewObject(); + if (obj == null) { + Logger.error("Pooling failure: Object creation failed."); + } else { + this.put(obj); + } + } + + /** + * @return the current size of the pool, not the maximum capacity of the + * Array holding the pool. + */ + public final int getPoolSize() { + synchronized (this.pool) { + return this.pool.size(); + } + } + + /** + * Culls the pool and removes half of the stored objects. Removed objects + * are NULL'ed and scheduled form Garbage Collection. + * + * @return the number of Objects removed from the pool. + */ + public int cullHalf() { + int full, half; + synchronized (this.pool) { + full = this.pool.size(); + if (full < 1) { + return full; + } + + half = (full / 2); + + for (int i = 0; i < (full / 2); ++i) { + T obj = this.get(); + obj = null; // Null out for GC + } + } + return half; + } + + /** + * @return the threshold + */ + public final int getThreshold() { + return threshold; + } + + /** + * @param threshold the threshold to set + */ + public void setThreshold(int threshold) { + if (threshold < 0) + return; + + this.threshold = threshold; + } } diff --git a/src/engine/pooling/Poolable.java b/src/engine/pooling/Poolable.java index 4155cbc5..d1be89cb 100644 --- a/src/engine/pooling/Poolable.java +++ b/src/engine/pooling/Poolable.java @@ -10,5 +10,5 @@ package engine.pooling; public interface Poolable { - public void clear(); + public void clear(); } diff --git a/src/engine/powers/ActionsBase.java b/src/engine/powers/ActionsBase.java index 0f157354..5264d18b 100644 --- a/src/engine/powers/ActionsBase.java +++ b/src/engine/powers/ActionsBase.java @@ -24,243 +24,246 @@ import java.util.HashMap; public class ActionsBase { - public int UUID; - public String IDString; - public String effectID; - public int minTrains; - public int maxTrains; - public float duration; - public float ramp; - public boolean addFormula; - public String stackType; - public StackType stackTypeType; - public int stackOrder; - - public boolean greaterThanEqual = false; - public boolean always = false; - public boolean greaterThan = false; - public String stackPriority; - - private AbstractPowerAction powerAction; - - /** - * No Table ID Constructor - */ - public ActionsBase() { - - } - - /** - * ResultSet Constructor - */ - public ActionsBase(ResultSet rs, HashMap apa) throws SQLException { - - this.UUID = rs.getInt("ID"); - this.IDString = rs.getString("powerID"); - this.effectID = rs.getString("effectID"); - this.minTrains = rs.getInt("minTrains"); - this.maxTrains = rs.getInt("maxTrains"); - this.duration = rs.getFloat("duration"); - this.ramp = rs.getFloat("ramp"); - this.addFormula = (rs.getInt("useAddFormula") == 1) ? true : false; - this.stackType = rs.getString("stackType"); - this.stackTypeType = StackType.GetStackType(this.stackType); - this.stackOrder = rs.getInt("stackOrder"); - this.stackPriority = rs.getString("stackPriority"); - - switch (stackPriority) { - case "GreaterThanOrEqualTo": - this.greaterThanEqual = true; - break; - case "Always": - this.always = true; - break; - case "GreaterThan": - this.greaterThan = true; - break; - } - this.powerAction = apa.get(this.effectID); - } - - protected ActionsBase(int uUID, String effectID, int minTrains, int maxTrains, float duration, float ramp, - boolean addFormula, String stackType, int stackOrder, boolean greaterThanEqual, boolean always, - boolean greaterThan, AbstractPowerAction powerAction) { - super(); - UUID = uUID; - this.effectID = effectID; - this.minTrains = minTrains; - this.maxTrains = maxTrains; - this.duration = duration; - this.ramp = ramp; - this.addFormula = addFormula; - this.stackType = stackType; - this.stackTypeType = StackType.GetStackType(this.stackType); - if (this.stackTypeType == null) - Logger.info("Invalid Stack Type " + this.stackTypeType + " for " + this.effectID); - this.stackOrder = stackOrder; - this.greaterThanEqual = greaterThanEqual; - this.always = always; - this.greaterThan = greaterThan; - this.powerAction = powerAction; - - if (this.greaterThanEqual) - this.stackPriority = "GreaterThanOrEqualTo"; - else if(this.always) - this.stackPriority = "Always"; - else if (this.greaterThan) - this.stackPriority = "GreaterThan"; - - } - - // public static ArrayList getActionsBase(String ID) { - // PreparedStatementShared ps = null; - // ArrayList out = new ArrayList(); - // try { - // ps = new PreparedStatementShared("SELECT * FROM actions where powerID = ?"); - // ps.setString(1, ID); - // ResultSet rs = ps.executeQuery(); - // while (rs.next()) { - // ActionsBase toAdd = new ActionsBase(rs); - // out.add(toAdd); - // } - // rs.close(); - // } catch (Exception e) { - // Logger.error("ActionsBase", e); - // } finally { - // ps.release(); - // } - // return out; - // } - - public static void getActionsBase(HashMap powers, HashMap apa) { - PreparedStatementShared ps = null; - try { - ps = new PreparedStatementShared("SELECT * FROM static_power_action"); - ResultSet rs = ps.executeQuery(); - String IDString; ActionsBase toAdd; PowersBase pb; - while (rs.next()) { - IDString = rs.getString("powerID"); - pb = powers.get(IDString); - if (pb != null) { - toAdd = new ActionsBase(rs, apa); - pb.getActions().add(toAdd); - } - } - rs.close(); - } catch (Exception e) { - Logger.error( e.toString()); - } finally { - ps.release(); - } - - int gateID = 5000; - for (String IDString : Runegate.GetAllOpenGateIDStrings()){ - gateID++; - ActionsBase openGateActionBase = new ActionsBase(gateID, "OPENGATE", 5, 9999, 0, 0, true, "IgnoreStack", 0, true, false, false, PowersManager.getPowerActionByIDString("OPENGATE")); - - PowersBase openGatePower = powers.get(IDString); - - if (openGatePower == null){ - Logger.error( "no powerbase for action " + IDString); - break; - } - openGatePower.getActions().add(openGateActionBase); - } - } - - - public int getUUID() { - return this.UUID; - } - - public String getEffectID() { - return this.effectID; - } - - public int getMinTrains() { - return this.minTrains; - } - - public int getMaxTrains() { - return this.maxTrains; - } - - public float getDuration() { - return this.duration; - } - - public AbstractPowerAction getPowerAction() { - return this.powerAction; - } - - public int getDuration(int trains) { - if (this.addFormula) - return (int)((this.duration + (this.ramp * trains)) * 1000); - else - return (int)((this.duration * (1 + (this.ramp * trains))) * 1000); - } - - public float getDurationAsFloat(int trains) { - if (this.addFormula) - return ((this.duration + (this.ramp * trains)) * 1000); - else - return ((this.duration * (1 + (this.ramp * trains))) * 1000); - } - - public int getDurationInSeconds(int trains) { - if (this.addFormula) - return (int)(this.duration + (this.ramp * trains)); - else - return (int)(this.duration * (1 + (this.ramp * trains))); - } - - public String getStackType() { - return this.stackType; - } - - public int getStackOrder() { - return this.stackOrder; - } - - public boolean greaterThanEqual() { - return this.greaterThanEqual; - } - - public boolean greaterThan() { - return this.greaterThan; - } - - public boolean always() { - return this.always; - } - - //Add blocked types here - public boolean blocked(AbstractWorldObject awo, PowersBase pb, int trains) { - if (AbstractWorldObject.IsAbstractCharacter(awo)) { - AbstractCharacter ac = (AbstractCharacter) awo; - PlayerBonuses bonus = ac.getBonuses(); - if (bonus == null) - return false; - - //TODO make this more efficient then testing strings - if (this.stackType.equals("Stun") && bonus.getBool(ModType.ImmuneTo, SourceType.Stun)) - return true; //Currently stun immune. Skip stun - else if(this.stackType.equals("Snare") && bonus.getBool(ModType.ImmuneTo, SourceType.Snare)) - return true; //Currently snare immune. Skip snare - else if(this.stackType.equals("Blindness") && bonus.getBool(ModType.ImmuneTo, SourceType.Blind)) - return true; //Currently blind immune. Skip blind - else if(this.stackType.equals("PowerInhibitor") && bonus.getBool(ModType.ImmuneTo, SourceType.Powerblock)) - return true; //Currently power block immune. Skip power block - else if (this.stackType.equals("Root") && bonus.getBool(ModType.ImmuneTo, SourceType.Root)) - return true; - // else if (pb.isHeal() && (bonus.getByte("immuneTo.Heal")) >= trains) - // return true; //Currently shadowmantled. Skip heals - else if (this.stackType.equals("Flight") && bonus.getBool(ModType.NoMod, SourceType.Fly)) - return true; - else if (this.stackType.equals("Track") && bonus.getBool(ModType.CannotTrack, SourceType.None)) - return true; - else return pb.vampDrain() && bonus.getBool(ModType.BlockedPowerType, SourceType.VAMPDRAIN); - } - return false; - } + public int UUID; + public String IDString; + public String effectID; + public int minTrains; + public int maxTrains; + public float duration; + public float ramp; + public boolean addFormula; + public String stackType; + public StackType stackTypeType; + public int stackOrder; + + public boolean greaterThanEqual = false; + public boolean always = false; + public boolean greaterThan = false; + public String stackPriority; + + private AbstractPowerAction powerAction; + + /** + * No Table ID Constructor + */ + public ActionsBase() { + + } + + /** + * ResultSet Constructor + */ + public ActionsBase(ResultSet rs, HashMap apa) throws SQLException { + + this.UUID = rs.getInt("ID"); + this.IDString = rs.getString("powerID"); + this.effectID = rs.getString("effectID"); + this.minTrains = rs.getInt("minTrains"); + this.maxTrains = rs.getInt("maxTrains"); + this.duration = rs.getFloat("duration"); + this.ramp = rs.getFloat("ramp"); + this.addFormula = (rs.getInt("useAddFormula") == 1) ? true : false; + this.stackType = rs.getString("stackType"); + this.stackTypeType = StackType.GetStackType(this.stackType); + this.stackOrder = rs.getInt("stackOrder"); + this.stackPriority = rs.getString("stackPriority"); + + switch (stackPriority) { + case "GreaterThanOrEqualTo": + this.greaterThanEqual = true; + break; + case "Always": + this.always = true; + break; + case "GreaterThan": + this.greaterThan = true; + break; + } + this.powerAction = apa.get(this.effectID); + } + + protected ActionsBase(int uUID, String effectID, int minTrains, int maxTrains, float duration, float ramp, + boolean addFormula, String stackType, int stackOrder, boolean greaterThanEqual, boolean always, + boolean greaterThan, AbstractPowerAction powerAction) { + super(); + UUID = uUID; + this.effectID = effectID; + this.minTrains = minTrains; + this.maxTrains = maxTrains; + this.duration = duration; + this.ramp = ramp; + this.addFormula = addFormula; + this.stackType = stackType; + this.stackTypeType = StackType.GetStackType(this.stackType); + if (this.stackTypeType == null) + Logger.info("Invalid Stack Type " + this.stackTypeType + " for " + this.effectID); + this.stackOrder = stackOrder; + this.greaterThanEqual = greaterThanEqual; + this.always = always; + this.greaterThan = greaterThan; + this.powerAction = powerAction; + + if (this.greaterThanEqual) + this.stackPriority = "GreaterThanOrEqualTo"; + else if (this.always) + this.stackPriority = "Always"; + else if (this.greaterThan) + this.stackPriority = "GreaterThan"; + + } + + // public static ArrayList getActionsBase(String ID) { + // PreparedStatementShared ps = null; + // ArrayList out = new ArrayList(); + // try { + // ps = new PreparedStatementShared("SELECT * FROM actions where powerID = ?"); + // ps.setString(1, ID); + // ResultSet rs = ps.executeQuery(); + // while (rs.next()) { + // ActionsBase toAdd = new ActionsBase(rs); + // out.add(toAdd); + // } + // rs.close(); + // } catch (Exception e) { + // Logger.error("ActionsBase", e); + // } finally { + // ps.release(); + // } + // return out; + // } + + public static void getActionsBase(HashMap powers, HashMap apa) { + PreparedStatementShared ps = null; + try { + ps = new PreparedStatementShared("SELECT * FROM static_power_action"); + ResultSet rs = ps.executeQuery(); + String IDString; + ActionsBase toAdd; + PowersBase pb; + while (rs.next()) { + IDString = rs.getString("powerID"); + pb = powers.get(IDString); + if (pb != null) { + toAdd = new ActionsBase(rs, apa); + pb.getActions().add(toAdd); + } + } + rs.close(); + } catch (Exception e) { + Logger.error(e.toString()); + } finally { + ps.release(); + } + + int gateID = 5000; + for (String IDString : Runegate.GetAllOpenGateIDStrings()) { + gateID++; + ActionsBase openGateActionBase = new ActionsBase(gateID, "OPENGATE", 5, 9999, 0, 0, true, "IgnoreStack", 0, true, false, false, PowersManager.getPowerActionByIDString("OPENGATE")); + + PowersBase openGatePower = powers.get(IDString); + + if (openGatePower == null) { + Logger.error("no powerbase for action " + IDString); + break; + } + openGatePower.getActions().add(openGateActionBase); + } + } + + + public int getUUID() { + return this.UUID; + } + + public String getEffectID() { + return this.effectID; + } + + public int getMinTrains() { + return this.minTrains; + } + + public int getMaxTrains() { + return this.maxTrains; + } + + public float getDuration() { + return this.duration; + } + + public AbstractPowerAction getPowerAction() { + return this.powerAction; + } + + public int getDuration(int trains) { + if (this.addFormula) + return (int) ((this.duration + (this.ramp * trains)) * 1000); + else + return (int) ((this.duration * (1 + (this.ramp * trains))) * 1000); + } + + public float getDurationAsFloat(int trains) { + if (this.addFormula) + return ((this.duration + (this.ramp * trains)) * 1000); + else + return ((this.duration * (1 + (this.ramp * trains))) * 1000); + } + + public int getDurationInSeconds(int trains) { + if (this.addFormula) + return (int) (this.duration + (this.ramp * trains)); + else + return (int) (this.duration * (1 + (this.ramp * trains))); + } + + public String getStackType() { + return this.stackType; + } + + public int getStackOrder() { + return this.stackOrder; + } + + public boolean greaterThanEqual() { + return this.greaterThanEqual; + } + + public boolean greaterThan() { + return this.greaterThan; + } + + public boolean always() { + return this.always; + } + + //Add blocked types here + public boolean blocked(AbstractWorldObject awo, PowersBase pb, int trains) { + if (AbstractWorldObject.IsAbstractCharacter(awo)) { + AbstractCharacter ac = (AbstractCharacter) awo; + PlayerBonuses bonus = ac.getBonuses(); + if (bonus == null) + return false; + + //TODO make this more efficient then testing strings + if (this.stackType.equals("Stun") && bonus.getBool(ModType.ImmuneTo, SourceType.Stun)) + return true; //Currently stun immune. Skip stun + else if (this.stackType.equals("Snare") && bonus.getBool(ModType.ImmuneTo, SourceType.Snare)) + return true; //Currently snare immune. Skip snare + else if (this.stackType.equals("Blindness") && bonus.getBool(ModType.ImmuneTo, SourceType.Blind)) + return true; //Currently blind immune. Skip blind + else if (this.stackType.equals("PowerInhibitor") && bonus.getBool(ModType.ImmuneTo, SourceType.Powerblock)) + return true; //Currently power block immune. Skip power block + else if (this.stackType.equals("Root") && bonus.getBool(ModType.ImmuneTo, SourceType.Root)) + return true; + // else if (pb.isHeal() && (bonus.getByte("immuneTo.Heal")) >= trains) + // return true; //Currently shadowmantled. Skip heals + else if (this.stackType.equals("Flight") && bonus.getBool(ModType.NoMod, SourceType.Fly)) + return true; + else if (this.stackType.equals("Track") && bonus.getBool(ModType.CannotTrack, SourceType.None)) + return true; + else + return pb.vampDrain() && bonus.getBool(ModType.BlockedPowerType, SourceType.VAMPDRAIN); + } + return false; + } } diff --git a/src/engine/powers/DamageShield.java b/src/engine/powers/DamageShield.java index 58b4af0b..3b5663c5 100644 --- a/src/engine/powers/DamageShield.java +++ b/src/engine/powers/DamageShield.java @@ -7,37 +7,37 @@ // www.magicbane.com - package engine.powers; +package engine.powers; import engine.Enum.DamageType; public class DamageShield { - private final DamageType damageType; - private final float amount; - private final boolean usePercent; - - public DamageShield(DamageType damageType, float amount, boolean usePercent) { - super(); - this.damageType = damageType; - this.amount = amount; - this.usePercent = usePercent; - } - - public DamageType getDamageType() { - return this.damageType; - } - - public float getAmount() { - return this.amount; - } - - public boolean usePercent() { - return this.usePercent; - } - - @Override - public String toString() { - return "ds.DamageType: " + this.damageType.name() + ", Amount: " + this.amount + ", UsePercent: " + this.usePercent; - } + private final DamageType damageType; + private final float amount; + private final boolean usePercent; + + public DamageShield(DamageType damageType, float amount, boolean usePercent) { + super(); + this.damageType = damageType; + this.amount = amount; + this.usePercent = usePercent; + } + + public DamageType getDamageType() { + return this.damageType; + } + + public float getAmount() { + return this.amount; + } + + public boolean usePercent() { + return this.usePercent; + } + + @Override + public String toString() { + return "ds.DamageType: " + this.damageType.name() + ", Amount: " + this.amount + ", UsePercent: " + this.usePercent; + } } diff --git a/src/engine/powers/EffectsBase.java b/src/engine/powers/EffectsBase.java index 19bd9ebc..511adf7c 100644 --- a/src/engine/powers/EffectsBase.java +++ b/src/engine/powers/EffectsBase.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -51,750 +48,741 @@ import java.util.concurrent.ConcurrentHashMap; public class EffectsBase { - private int UUID; - private String IDString; - // private String name; - private int token; - private float amount; - private float amountRamp; - - // flags - private boolean isItemEffect; - private boolean isSpireEffect; - private boolean ignoreMod; - private boolean dontSave; - - private boolean cancelOnAttack = false; - private boolean cancelOnAttackSwing = false; - private boolean cancelOnCast = false; - private boolean cancelOnCastSpell = false; - private boolean cancelOnEquipChange = false; - private boolean cancelOnLogout = false; - private boolean cancelOnMove = false; - private boolean cancelOnNewCharm = false; - private boolean cancelOnSit = false; - private boolean cancelOnTakeDamage = false; - private boolean cancelOnTerritoryClaim = false; - private boolean cancelOnUnEquip = false; - private boolean useRampAdd; - private boolean isPrefix = false; //used by items - private boolean isSuffix = false; //used by items - private String name = ""; - private float value = 0; - private ConcurrentHashMap resourceCosts = new ConcurrentHashMap<>(); - private ConcurrentHashMap sourceTypes = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - public static HashMap> effectSourceTypeMap = new HashMap<>(); - public static HashMap> modifiersMap = new HashMap<>(); - private static ConcurrentHashMap itemEffectsByName = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private static int NewID = 3000; - public static HashMap>> OldEffectsMap = new HashMap<>(); - public static HashMap>> NewEffectsMap = new HashMap<>(); - public static HashMap>> ChangedEffectsMap = new HashMap<>(); - public static HashMap> EffectFailConditions = new HashMap<>(); - public static HashMap> EffectDamageTypes = new HashMap<>(); - - public static HashSet DefaultModifiers = new HashSet<>(); - /** - * No Table ID Constructor - */ - public EffectsBase() { - - } - - public EffectsBase(EffectsBase copyEffect, int newToken, String IDString) { - - UUID = NewID++; - this.IDString = IDString; - this.token = newToken; - - //filll - if (copyEffect == null){ - int flags = 0; - this.isItemEffect = ((flags & 1) != 0) ? true : false; - this.isSpireEffect = ((flags & 2) != 0) ? true : false; - this.ignoreMod = ((flags & 4) != 0) ? true : false; - this.dontSave = ((flags & 8) != 0) ? true : false; - - if (this.IDString.startsWith("PRE-")) - this.isPrefix = true; - else if (this.IDString.startsWith("SUF-")) - this.isSuffix = true; - - } - - - this.amount = copyEffect.amount; - this.amountRamp = copyEffect.amountRamp; - this.isItemEffect = copyEffect.isItemEffect; - this.isSpireEffect = copyEffect.isSpireEffect; - this.ignoreMod = copyEffect.ignoreMod; - this.dontSave = copyEffect.dontSave; - this.cancelOnAttack = copyEffect.cancelOnAttack; - this.cancelOnAttackSwing = copyEffect.cancelOnAttackSwing; - this.cancelOnCast = copyEffect.cancelOnCast; - this.cancelOnCastSpell = copyEffect.cancelOnCastSpell; - this.cancelOnEquipChange = copyEffect.cancelOnEquipChange; - this.cancelOnLogout = copyEffect.cancelOnLogout; - this.cancelOnMove = copyEffect.cancelOnMove; - this.cancelOnNewCharm = copyEffect.cancelOnNewCharm; - this.cancelOnSit = copyEffect.cancelOnSit; - this.cancelOnTakeDamage = copyEffect.cancelOnTakeDamage; - this.cancelOnTerritoryClaim = copyEffect.cancelOnTerritoryClaim; - this.cancelOnUnEquip = copyEffect.cancelOnUnEquip; - this.useRampAdd = copyEffect.useRampAdd; - this.isPrefix = copyEffect.isPrefix; - this.isSuffix = copyEffect.isSuffix; - this.name = copyEffect.name; - this.value = copyEffect.value; - this.resourceCosts = copyEffect.resourceCosts; - - } - - /** - * ResultSet Constructor - */ - public EffectsBase(ResultSet rs) throws SQLException { - - this.UUID = rs.getInt("ID"); - this.IDString = rs.getString("IDString"); - this.name = rs.getString("name"); - this.token = rs.getInt("Token"); - - //override tokens for some effects like Safemode that use the Action Token instead of the effect Token, - switch (this.IDString){ - case "INVIS-D": - this.token = -1661751254; - break; - case "SafeMode": - this.token = -1661750486; - break; - - } - int flags = rs.getInt("flags"); - this.isItemEffect = ((flags & 1) != 0) ? true : false; - this.isSpireEffect = ((flags & 2) != 0) ? true : false; - this.ignoreMod = ((flags & 4) != 0) ? true : false; - this.dontSave = ((flags & 8) != 0) ? true : false; - - if (this.IDString.startsWith("PRE-")) - this.isPrefix = true; - else if (this.IDString.startsWith("SUF-")) - this.isSuffix = true; - // getFailConditions(); - } - - public static void getFailConditions(HashMap effects) { - PreparedStatementShared ps = null; - try { - ps = new PreparedStatementShared("SELECT * FROM static_power_failcondition WHERE powerOrEffect = 'Effect';"); - - ResultSet rs = ps.executeQuery(); - PowerFailCondition failCondition = null; - - Object value; - while (rs.next()) { - String fail = rs.getString("type"); - - - - String IDString = rs.getString("IDString"); - int token = DbManager.hasher.SBStringHash(IDString); - failCondition = PowerFailCondition.valueOf(fail); - if (failCondition == null){ - Logger.error( "Couldn't Find FailCondition " + fail + " for " + IDString); - continue; - } - - if (EffectsBase.EffectFailConditions.get(IDString) == null){ - EffectsBase.EffectFailConditions.put(IDString, new HashSet<>()); - } - - EffectsBase.EffectFailConditions.get(IDString).add(failCondition); - EffectsBase eb = effects.get(IDString); - - switch (failCondition) { - - case TakeDamage: - - - - // dont go any further. - if (eb == null){ - break; - } - - eb.cancelOnTakeDamage = true; - - - - - eb.amount = rs.getFloat("amount"); - eb.amountRamp = rs.getFloat("ramp"); - eb.useRampAdd = rs.getBoolean("UseAddFormula"); - - String damageType1 = rs.getString("damageType1"); - String damageType2 = rs.getString("damageType2"); - String damageType3 = rs.getString("damageType3"); - - - if (damageType1.isEmpty() && damageType2.isEmpty() && damageType3.isEmpty()) - break; - - if (!EffectsBase.EffectDamageTypes.containsKey(eb.getToken())){ - EffectsBase.EffectDamageTypes.put(eb.getToken(), new HashSet<>()); - } - if (damageType1.equalsIgnoreCase("Crushing")) - damageType1 = "Crush"; - if (damageType1.equalsIgnoreCase("Piercing")) - damageType1 = "Pierce"; - if (damageType1.equalsIgnoreCase("Slashing")) - damageType1 = "Slash"; - - if (damageType2.equalsIgnoreCase("Crushing")) - damageType2 = "Crush"; - if (damageType2.equalsIgnoreCase("Piercing")) - damageType2 = "Pierce"; - if (damageType2.equalsIgnoreCase("Slashing")) - damageType2 = "Slash"; - - if (damageType3.equalsIgnoreCase("Crushing")) - damageType3 = "Crush"; - if (damageType3.equalsIgnoreCase("Piercing")) - damageType3 = "Pierce"; - if (damageType3.equalsIgnoreCase("Slashing")) - damageType3 = "Slash"; - DamageType dt = getDamageType(damageType1); - if (dt != null) - EffectsBase.EffectDamageTypes.get(eb.token).add(dt); - - dt = getDamageType(damageType2); - if (dt != null) - EffectsBase.EffectDamageTypes.get(eb.token).add(dt); - dt = getDamageType(damageType3); - if (dt != null) - EffectsBase.EffectDamageTypes.get(eb.token).add(dt); - break; - case Attack: - eb.cancelOnAttack = true; - break; - case AttackSwing: - eb.cancelOnAttackSwing = true; - break; - case Cast: - eb.cancelOnCast = true; - break; - case CastSpell: - eb.cancelOnCastSpell = true; - break; - case EquipChange: - eb.cancelOnEquipChange = true; - break; - case Logout: - eb.cancelOnLogout = true; - break; - case Move: - eb.cancelOnMove = true; - break; - case NewCharm: - eb.cancelOnNewCharm = true; - break; - case Sit: - eb.cancelOnSit = true; - break; - case TerritoryClaim: - eb.cancelOnTerritoryClaim = true; - break; - case UnEquip: - eb.cancelOnUnEquip = true; - break; - } - } - - rs.close(); - } catch (Exception e) { - Logger.error( e); - } finally { - ps.release(); - } - - } - - public float getDamageAmount(int trains) { - if (useRampAdd) - return (amount + (amountRamp * trains)); - else - return (amount * (1 + (amountRamp * trains))); - } - - public boolean damageTypeSpecific() { - - return EffectsBase.EffectDamageTypes.containsKey(this.token); - - } - - public boolean containsDamageType(DamageType dt) { - if (!EffectsBase.EffectDamageTypes.containsKey(this.token)) - return false; - return EffectsBase.EffectDamageTypes.get(this.token).contains(dt); - } - - private static DamageType getDamageType(String name) { - try { - switch (name) { - case "Crushing": - name = "Crush"; - break; - case "Slashing": - name = "Slash"; - break; - case "Piercing": - name = "Pierce"; - break; - } - if (name.isEmpty()) - return null; - else - return DamageType.valueOf(name); - } catch (Exception e) { - Logger.error(name); - return null; - } - } - - // public String getName() { - // return this.name; - // } - - public int getUUID() { - return this.UUID; - } - - public String getIDString() { - return this.IDString; - } - - public int getToken() { - return this.token; - } - - public ConcurrentHashMap getSourceTypes() { - return this.sourceTypes; - } - - public HashSet getModifiers() { - - if (EffectsBase.modifiersMap.containsKey(this.IDString) == false) - return EffectsBase.DefaultModifiers; - - return EffectsBase.modifiersMap.get(this.IDString); - } - - public boolean isItemEffect() { - return this.isItemEffect; - } - - public boolean isSpireEffect() { - return this.isSpireEffect; - } - - public boolean ignoreMod() { - return this.ignoreMod; - } - - public boolean dontSave() { - return this.dontSave; - } - - public boolean isPrefix() { - return this.isPrefix; - } - - public boolean isSuffix() { - return this.isSuffix; - } - - public void startEffect(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - - - // Add SourceTypes for dispel - - if (this.token != 0) { - if (effect == null) { - Logger.error("AbstractEffectModifier.applyEffectModifier: missing FinishEffectTimeJob"); - return; - } - // AbstractWorldObject source = effect.getSource(); - if (source == null) { - Logger.error( "AbstractEffectModifier.applyEffectModifier: missing source"); - return; - } - PowersBase pb = effect.getPower(); - if (pb == null) { - Logger.error( "AbstractEffectModifier.applyEffectModifier: missing power"); - return; - } - ActionsBase ab = effect.getAction(); - if (ab == null) { - Logger.error( "AbstractEffectModifier.applyEffectModifier: missing action"); - return; - } - - //don't send effect if dead, except for death shroud - if (!awo.isAlive()) { - if (pb.getToken() != 1672601862) - return; - } - - - if (!effect.skipSendEffect()) { - // float duration = (pb.isChant()) ? pb.getChantDuration() * 1000 : ab.getDuration(trains); - float duration = ab.getDurationInSeconds(trains); - if (pb.getToken() == 1672601862){ - - Effect eff = awo.getEffects().get("DeathShroud"); - - - - - if (eff != null) { - JobContainer jc = eff.getJobContainer(); - - - if (jc != null){ - duration = jc.timeOfExection() - System.currentTimeMillis(); - duration *= .001f; - } - } - } - - - - if (duration > 0f) { - int removeToken = this.token; - ApplyEffectMsg pum = new ApplyEffectMsg(); - if (effect.getAction() != null) - if ( effect.getAction().getPowerAction() != null - && PowersManager.ActionTokenByIDString.containsKey(effect.getAction().getPowerAction().getIDString())) - try{ - removeToken = PowersManager.ActionTokenByIDString.get(effect.getAction().getPowerAction().getIDString()); - }catch(Exception e){ - removeToken = this.token; - } - - pum.setEffectID(removeToken); - pum.setSourceType(source.getObjectType().ordinal()); - pum.setSourceID(source.getObjectUUID()); - pum.setTargetType(awo.getObjectType().ordinal()); - pum.setTargetID(awo.getObjectUUID()); - pum.setNumTrains(trains); - pum.setDuration((int) duration); - // pum.setDuration((pb.isChant()) ? (int)pb.getChantDuration() : ab.getDurationInSeconds(trains)); - pum.setPowerUsedID(pb.getToken()); - pum.setPowerUsedName(pb.getName()); - DispatchMessage.sendToAllInRange(awo, pum); - } - - if (awo.getObjectType().equals(GameObjectType.Item)) { - if (source.getCharItemManager() != null) { - source.getCharItemManager().updateInventory(); - } - } - } - - // call modifiers to do their job - if (!effect.skipApplyEffect()) { - for (AbstractEffectModifier em : this.getModifiers()) - em.applyEffectModifier(source, awo, trains, effect); - } - } - } - - // Send end effect message to client - public void endEffect(AbstractWorldObject source, AbstractWorldObject awo, int trains, PowersBase pb, AbstractEffectJob effect) { - if (awo == null) { - Logger.error("endEffect(): Null AWO object passed in."); - return; - } - if (pb == null) { - Logger.error("endEffect(): Null PowerBase object passed in."); - return; - } - if (!effect.skipCancelEffect() && !effect.isNoOverwrite()) { - - int sendToken = this.token; - - if (effect.getAction() != null) - if ( effect.getAction().getPowerAction() != null - && PowersManager.ActionTokenByIDString.containsKey(effect.getAction().getPowerAction().getIDString())) - try{ - sendToken = PowersManager.ActionTokenByIDString.get(effect.getAction().getPowerAction().getIDString()); - }catch(Exception e){ - sendToken = this.token; - } - ApplyEffectMsg pum = new ApplyEffectMsg(); - pum.setEffectID(sendToken); - if (source != null) { - pum.setSourceType(source.getObjectType().ordinal()); - pum.setSourceID(source.getObjectUUID()); - } else { - pum.setSourceType(0); - pum.setSourceID(0); - } - pum.setTargetType(awo.getObjectType().ordinal()); - pum.setTargetID(awo.getObjectUUID()); - pum.setUnknown02(2); - pum.setNumTrains(0); - pum.setDuration(-1); - pum.setPowerUsedID(pb.getToken()); - pum.setPowerUsedName(pb.getName()); - DispatchMessage.sendToAllInRange(awo, pum); - - } - } - - public void endEffectNoPower(int trains, AbstractEffectJob effect) { - - AbstractWorldObject source = effect.getSource(); - - if (source == null) - return; - - if (!effect.skipCancelEffect() && !effect.isNoOverwrite()) { - ApplyEffectMsg pum = new ApplyEffectMsg(); - pum.setEffectID(this.token); - - pum.setSourceType(source.getObjectType().ordinal()); - pum.setSourceID(source.getObjectUUID()); - pum.setTargetType(source.getObjectType().ordinal()); - pum.setTargetID(source.getObjectUUID()); - pum.setUnknown02(2); - pum.setNumTrains(0); - pum.setDuration(-1); - pum.setUnknown06((byte)1); - pum.setEffectSourceType(effect.getEffectSourceType()); - pum.setEffectSourceID(effect.getEffectSourceID()); - pum.setPowerUsedID(0); - pum.setPowerUsedName(this.name); - - if (source.getObjectType() == GameObjectType.PlayerCharacter){ - Dispatch dispatch = Dispatch.borrow((PlayerCharacter)source, pum); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); - } - } - } - - public void sendEffect(AbstractEffectJob effect, int duration, ClientConnection conn) { - if (effect == null && conn != null) - return; - - if (conn == null) - return; - AbstractWorldObject source = effect.getSource(); - AbstractWorldObject awo = effect.getTarget(); - int trains = effect.getTrains(); - if (source == null || awo == null) - return; - - if (this.token != 0) { - PowersBase pb = effect.getPower(); - if (pb == null) { - Logger.error( "AbstractEffectModifier.applyEffectModifier: missing power"); - return; - } - ActionsBase ab = effect.getAction(); - if (ab == null) { - Logger.error("AbstractEffectModifier.applyEffectModifier: missing action"); - return; - } - - //don't send effect if dead, except for death shroud - if (!awo.isAlive()) { - if (pb.getToken() != 1672601862) - return; - } - - //duration for damage over times is (total time - (number of ticks x 5 seconds per tick)) - if (effect instanceof DamageOverTimeJob) - duration = ((DamageOverTimeJob)effect).getTickLength(); - - // float dur = (pb.isChant()) ? pb.getChantDuration() * 1000 : ab.getDuration(trains); - float dur = ab.getDuration(trains); - if (dur > 0f) { - ApplyEffectMsg pum = new ApplyEffectMsg(); - pum.setEffectID(this.token); - pum.setSourceType(source.getObjectType().ordinal()); - pum.setSourceID(source.getObjectUUID()); - pum.setTargetType(awo.getObjectType().ordinal()); - pum.setTargetID(awo.getObjectUUID()); - pum.setNumTrains(trains); - pum.setDuration(duration); - pum.setPowerUsedID(pb.getToken()); - pum.setPowerUsedName(pb.getName()); - - Dispatch dispatch = Dispatch.borrow(conn.getPlayerCharacter(), pum); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); - - } - } - } - - public void sendEffectNoPower(AbstractEffectJob effect, int duration, ClientConnection conn) { - - if (effect == null && conn != null) - return; - - if (conn == null) - return; - - AbstractWorldObject source = effect.getSource(); - AbstractWorldObject awo = effect.getTarget(); - int trains = effect.getTrains(); - - if (source == null || awo == null) - return; - - if (this.token != 0) { - //don't send effect if dead, except for death shroud - if (!awo.isAlive()) { - return; - } - - //duration for damage over times is (total time - (number of ticks x 5 seconds per tick)) - if (effect instanceof DamageOverTimeJob) - duration = ((DamageOverTimeJob)effect).getTickLength(); - else if (effect instanceof FinishSpireEffectJob) - duration = 45; - else if (effect instanceof NoTimeJob) - duration = -1; - - // float dur = (pb.isChant()) ? pb.getChantDuration() * 1000 : ab.getDuration(trains); - - ApplyEffectMsg pum = new ApplyEffectMsg(); - pum.setEffectID(this.token); - pum.setSourceType(source.getObjectType().ordinal()); - pum.setSourceID(source.getObjectUUID()); - pum.setTargetType(source.getObjectType().ordinal()); - pum.setTargetID(source.getObjectUUID()); - pum.setUnknown06((byte)1); - pum.setEffectSourceType(effect.getEffectSourceType()); - pum.setEffectSourceID(effect.getEffectSourceID()); - pum.setNumTrains(trains); - pum.setDuration(duration); - pum.setPowerUsedID(0); - pum.setPowerUsedName(this.name); - - Dispatch dispatch = Dispatch.borrow(conn.getPlayerCharacter(), pum); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); - - } - } - - public boolean containsSource(EffectSourceType sourceType) { - if (EffectsBase.effectSourceTypeMap.containsKey(this.token) == false) - return false; - return EffectsBase.effectSourceTypeMap.get(this.token).contains(sourceType); - - } - - public boolean cancelOnAttack() { - return this.cancelOnAttack; - } - - public boolean cancelOnAttackSwing() { - return this.cancelOnAttackSwing; - } - - public boolean cancelOnCast() { - return this.cancelOnCast; - } - - public boolean cancelOnCastSpell() { - return this.cancelOnCastSpell; - } - - public boolean cancelOnEquipChange() { - return this.cancelOnEquipChange; - } - - public boolean cancelOnLogout() { - return this.cancelOnLogout; - } - - public boolean cancelOnMove() { - return this.cancelOnMove; - } - - public boolean cancelOnNewCharm() { - return this.cancelOnNewCharm; - } - - public boolean cancelOnSit() { - return this.cancelOnSit; - } - - public boolean cancelOnTakeDamage() { - return this.cancelOnTakeDamage; - } - - public boolean cancelOnTerritoryClaim() { - return this.cancelOnTerritoryClaim; - } - - public boolean cancelOnUnEquip() { - return this.cancelOnUnEquip; - } - - //For Debugging purposes. - public void setToken(int token) { - this.token = token; - } - - public static String getItemEffectsByName(String string) { - if (EffectsBase.itemEffectsByName.containsKey(string)) - return EffectsBase.itemEffectsByName.get(string); - return ""; - } - - public static void addItemEffectsByName(String name, String ID) { - EffectsBase.itemEffectsByName.put(name, ID); - } - - public String getDamageTypes() { - String text = ""; - if (!EffectsBase.EffectDamageTypes.containsKey(this.token)) - return text; - for (DamageType type: EffectsBase.EffectDamageTypes.get(this.token)) { - text += type.name() + ' '; - } - return text; - } - - public String getName() { - - return name; - } - - public void setName(String name){ - this.name = name; - } - - public float getValue() { - return value; - } - - public void setValue(float Value){ - this.value = Value; - } - public ConcurrentHashMap getResourcesForEffect() { - if (this.resourceCosts.isEmpty()){ - ArrayList effectsCostList = DbManager.EffectsResourceCostsQueries.GET_ALL_EFFECT_RESOURCES(this.IDString); - for (EffectsResourceCosts erc : effectsCostList){ - this.resourceCosts.put(ItemBase.getItemBase(erc.getResourceID()), erc.getAmount()); - } - } - return this.resourceCosts; - } + public static HashMap> effectSourceTypeMap = new HashMap<>(); + public static HashMap> modifiersMap = new HashMap<>(); + public static HashMap>> OldEffectsMap = new HashMap<>(); + public static HashMap>> NewEffectsMap = new HashMap<>(); + public static HashMap>> ChangedEffectsMap = new HashMap<>(); + public static HashMap> EffectFailConditions = new HashMap<>(); + public static HashMap> EffectDamageTypes = new HashMap<>(); + public static HashSet DefaultModifiers = new HashSet<>(); + private static ConcurrentHashMap itemEffectsByName = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private static int NewID = 3000; + private int UUID; + private String IDString; + // private String name; + private int token; + private float amount; + private float amountRamp; + // flags + private boolean isItemEffect; + private boolean isSpireEffect; + private boolean ignoreMod; + private boolean dontSave; + private boolean cancelOnAttack = false; + private boolean cancelOnAttackSwing = false; + private boolean cancelOnCast = false; + private boolean cancelOnCastSpell = false; + private boolean cancelOnEquipChange = false; + private boolean cancelOnLogout = false; + private boolean cancelOnMove = false; + private boolean cancelOnNewCharm = false; + private boolean cancelOnSit = false; + private boolean cancelOnTakeDamage = false; + private boolean cancelOnTerritoryClaim = false; + private boolean cancelOnUnEquip = false; + private boolean useRampAdd; + private boolean isPrefix = false; //used by items + private boolean isSuffix = false; //used by items + private String name = ""; + private float value = 0; + private ConcurrentHashMap resourceCosts = new ConcurrentHashMap<>(); + private ConcurrentHashMap sourceTypes = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + + /** + * No Table ID Constructor + */ + public EffectsBase() { + + } + + public EffectsBase(EffectsBase copyEffect, int newToken, String IDString) { + + UUID = NewID++; + this.IDString = IDString; + this.token = newToken; + + //filll + if (copyEffect == null) { + int flags = 0; + this.isItemEffect = ((flags & 1) != 0) ? true : false; + this.isSpireEffect = ((flags & 2) != 0) ? true : false; + this.ignoreMod = ((flags & 4) != 0) ? true : false; + this.dontSave = ((flags & 8) != 0) ? true : false; + + if (this.IDString.startsWith("PRE-")) + this.isPrefix = true; + else if (this.IDString.startsWith("SUF-")) + this.isSuffix = true; + + } + + + this.amount = copyEffect.amount; + this.amountRamp = copyEffect.amountRamp; + this.isItemEffect = copyEffect.isItemEffect; + this.isSpireEffect = copyEffect.isSpireEffect; + this.ignoreMod = copyEffect.ignoreMod; + this.dontSave = copyEffect.dontSave; + this.cancelOnAttack = copyEffect.cancelOnAttack; + this.cancelOnAttackSwing = copyEffect.cancelOnAttackSwing; + this.cancelOnCast = copyEffect.cancelOnCast; + this.cancelOnCastSpell = copyEffect.cancelOnCastSpell; + this.cancelOnEquipChange = copyEffect.cancelOnEquipChange; + this.cancelOnLogout = copyEffect.cancelOnLogout; + this.cancelOnMove = copyEffect.cancelOnMove; + this.cancelOnNewCharm = copyEffect.cancelOnNewCharm; + this.cancelOnSit = copyEffect.cancelOnSit; + this.cancelOnTakeDamage = copyEffect.cancelOnTakeDamage; + this.cancelOnTerritoryClaim = copyEffect.cancelOnTerritoryClaim; + this.cancelOnUnEquip = copyEffect.cancelOnUnEquip; + this.useRampAdd = copyEffect.useRampAdd; + this.isPrefix = copyEffect.isPrefix; + this.isSuffix = copyEffect.isSuffix; + this.name = copyEffect.name; + this.value = copyEffect.value; + this.resourceCosts = copyEffect.resourceCosts; + + } + + /** + * ResultSet Constructor + */ + public EffectsBase(ResultSet rs) throws SQLException { + + this.UUID = rs.getInt("ID"); + this.IDString = rs.getString("IDString"); + this.name = rs.getString("name"); + this.token = rs.getInt("Token"); + + //override tokens for some effects like Safemode that use the Action Token instead of the effect Token, + switch (this.IDString) { + case "INVIS-D": + this.token = -1661751254; + break; + case "SafeMode": + this.token = -1661750486; + break; + + } + int flags = rs.getInt("flags"); + this.isItemEffect = ((flags & 1) != 0) ? true : false; + this.isSpireEffect = ((flags & 2) != 0) ? true : false; + this.ignoreMod = ((flags & 4) != 0) ? true : false; + this.dontSave = ((flags & 8) != 0) ? true : false; + + if (this.IDString.startsWith("PRE-")) + this.isPrefix = true; + else if (this.IDString.startsWith("SUF-")) + this.isSuffix = true; + // getFailConditions(); + } + + public static void getFailConditions(HashMap effects) { + PreparedStatementShared ps = null; + try { + ps = new PreparedStatementShared("SELECT * FROM static_power_failcondition WHERE powerOrEffect = 'Effect';"); + + ResultSet rs = ps.executeQuery(); + PowerFailCondition failCondition = null; + + Object value; + while (rs.next()) { + String fail = rs.getString("type"); + + + String IDString = rs.getString("IDString"); + int token = DbManager.hasher.SBStringHash(IDString); + failCondition = PowerFailCondition.valueOf(fail); + if (failCondition == null) { + Logger.error("Couldn't Find FailCondition " + fail + " for " + IDString); + continue; + } + + if (EffectsBase.EffectFailConditions.get(IDString) == null) { + EffectsBase.EffectFailConditions.put(IDString, new HashSet<>()); + } + + EffectsBase.EffectFailConditions.get(IDString).add(failCondition); + EffectsBase eb = effects.get(IDString); + + switch (failCondition) { + + case TakeDamage: + + + // dont go any further. + if (eb == null) { + break; + } + + eb.cancelOnTakeDamage = true; + + + eb.amount = rs.getFloat("amount"); + eb.amountRamp = rs.getFloat("ramp"); + eb.useRampAdd = rs.getBoolean("UseAddFormula"); + + String damageType1 = rs.getString("damageType1"); + String damageType2 = rs.getString("damageType2"); + String damageType3 = rs.getString("damageType3"); + + + if (damageType1.isEmpty() && damageType2.isEmpty() && damageType3.isEmpty()) + break; + + if (!EffectsBase.EffectDamageTypes.containsKey(eb.getToken())) { + EffectsBase.EffectDamageTypes.put(eb.getToken(), new HashSet<>()); + } + if (damageType1.equalsIgnoreCase("Crushing")) + damageType1 = "Crush"; + if (damageType1.equalsIgnoreCase("Piercing")) + damageType1 = "Pierce"; + if (damageType1.equalsIgnoreCase("Slashing")) + damageType1 = "Slash"; + + if (damageType2.equalsIgnoreCase("Crushing")) + damageType2 = "Crush"; + if (damageType2.equalsIgnoreCase("Piercing")) + damageType2 = "Pierce"; + if (damageType2.equalsIgnoreCase("Slashing")) + damageType2 = "Slash"; + + if (damageType3.equalsIgnoreCase("Crushing")) + damageType3 = "Crush"; + if (damageType3.equalsIgnoreCase("Piercing")) + damageType3 = "Pierce"; + if (damageType3.equalsIgnoreCase("Slashing")) + damageType3 = "Slash"; + DamageType dt = getDamageType(damageType1); + if (dt != null) + EffectsBase.EffectDamageTypes.get(eb.token).add(dt); + + dt = getDamageType(damageType2); + if (dt != null) + EffectsBase.EffectDamageTypes.get(eb.token).add(dt); + dt = getDamageType(damageType3); + if (dt != null) + EffectsBase.EffectDamageTypes.get(eb.token).add(dt); + break; + case Attack: + eb.cancelOnAttack = true; + break; + case AttackSwing: + eb.cancelOnAttackSwing = true; + break; + case Cast: + eb.cancelOnCast = true; + break; + case CastSpell: + eb.cancelOnCastSpell = true; + break; + case EquipChange: + eb.cancelOnEquipChange = true; + break; + case Logout: + eb.cancelOnLogout = true; + break; + case Move: + eb.cancelOnMove = true; + break; + case NewCharm: + eb.cancelOnNewCharm = true; + break; + case Sit: + eb.cancelOnSit = true; + break; + case TerritoryClaim: + eb.cancelOnTerritoryClaim = true; + break; + case UnEquip: + eb.cancelOnUnEquip = true; + break; + } + } + + rs.close(); + } catch (Exception e) { + Logger.error(e); + } finally { + ps.release(); + } + + } + + private static DamageType getDamageType(String name) { + try { + switch (name) { + case "Crushing": + name = "Crush"; + break; + case "Slashing": + name = "Slash"; + break; + case "Piercing": + name = "Pierce"; + break; + } + if (name.isEmpty()) + return null; + else + return DamageType.valueOf(name); + } catch (Exception e) { + Logger.error(name); + return null; + } + } + + public static String getItemEffectsByName(String string) { + if (EffectsBase.itemEffectsByName.containsKey(string)) + return EffectsBase.itemEffectsByName.get(string); + return ""; + } + + public static void addItemEffectsByName(String name, String ID) { + EffectsBase.itemEffectsByName.put(name, ID); + } + + public float getDamageAmount(int trains) { + if (useRampAdd) + return (amount + (amountRamp * trains)); + else + return (amount * (1 + (amountRamp * trains))); + } + + // public String getName() { + // return this.name; + // } + + public boolean damageTypeSpecific() { + + return EffectsBase.EffectDamageTypes.containsKey(this.token); + + } + + public boolean containsDamageType(DamageType dt) { + if (!EffectsBase.EffectDamageTypes.containsKey(this.token)) + return false; + return EffectsBase.EffectDamageTypes.get(this.token).contains(dt); + } + + public int getUUID() { + return this.UUID; + } + + public String getIDString() { + return this.IDString; + } + + public int getToken() { + return this.token; + } + + //For Debugging purposes. + public void setToken(int token) { + this.token = token; + } + + public ConcurrentHashMap getSourceTypes() { + return this.sourceTypes; + } + + public HashSet getModifiers() { + + if (EffectsBase.modifiersMap.containsKey(this.IDString) == false) + return EffectsBase.DefaultModifiers; + + return EffectsBase.modifiersMap.get(this.IDString); + } + + public boolean isItemEffect() { + return this.isItemEffect; + } + + public boolean isSpireEffect() { + return this.isSpireEffect; + } + + public boolean ignoreMod() { + return this.ignoreMod; + } + + public boolean dontSave() { + return this.dontSave; + } + + public boolean isPrefix() { + return this.isPrefix; + } + + public boolean isSuffix() { + return this.isSuffix; + } + + public void startEffect(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + + // Add SourceTypes for dispel + + if (this.token != 0) { + if (effect == null) { + Logger.error("AbstractEffectModifier.applyEffectModifier: missing FinishEffectTimeJob"); + return; + } + // AbstractWorldObject source = effect.getSource(); + if (source == null) { + Logger.error("AbstractEffectModifier.applyEffectModifier: missing source"); + return; + } + PowersBase pb = effect.getPower(); + if (pb == null) { + Logger.error("AbstractEffectModifier.applyEffectModifier: missing power"); + return; + } + ActionsBase ab = effect.getAction(); + if (ab == null) { + Logger.error("AbstractEffectModifier.applyEffectModifier: missing action"); + return; + } + + //don't send effect if dead, except for death shroud + if (!awo.isAlive()) { + if (pb.getToken() != 1672601862) + return; + } + + + if (!effect.skipSendEffect()) { + // float duration = (pb.isChant()) ? pb.getChantDuration() * 1000 : ab.getDuration(trains); + float duration = ab.getDurationInSeconds(trains); + if (pb.getToken() == 1672601862) { + + Effect eff = awo.getEffects().get("DeathShroud"); + + + if (eff != null) { + JobContainer jc = eff.getJobContainer(); + + + if (jc != null) { + duration = jc.timeOfExection() - System.currentTimeMillis(); + duration *= .001f; + } + } + } + + + if (duration > 0f) { + int removeToken = this.token; + ApplyEffectMsg pum = new ApplyEffectMsg(); + if (effect.getAction() != null) + if (effect.getAction().getPowerAction() != null + && PowersManager.ActionTokenByIDString.containsKey(effect.getAction().getPowerAction().getIDString())) + try { + removeToken = PowersManager.ActionTokenByIDString.get(effect.getAction().getPowerAction().getIDString()); + } catch (Exception e) { + removeToken = this.token; + } + + pum.setEffectID(removeToken); + pum.setSourceType(source.getObjectType().ordinal()); + pum.setSourceID(source.getObjectUUID()); + pum.setTargetType(awo.getObjectType().ordinal()); + pum.setTargetID(awo.getObjectUUID()); + pum.setNumTrains(trains); + pum.setDuration((int) duration); + // pum.setDuration((pb.isChant()) ? (int)pb.getChantDuration() : ab.getDurationInSeconds(trains)); + pum.setPowerUsedID(pb.getToken()); + pum.setPowerUsedName(pb.getName()); + DispatchMessage.sendToAllInRange(awo, pum); + } + + if (awo.getObjectType().equals(GameObjectType.Item)) { + if (source.getCharItemManager() != null) { + source.getCharItemManager().updateInventory(); + } + } + } + + // call modifiers to do their job + if (!effect.skipApplyEffect()) { + for (AbstractEffectModifier em : this.getModifiers()) + em.applyEffectModifier(source, awo, trains, effect); + } + } + } + + // Send end effect message to client + public void endEffect(AbstractWorldObject source, AbstractWorldObject awo, int trains, PowersBase pb, AbstractEffectJob effect) { + if (awo == null) { + Logger.error("endEffect(): Null AWO object passed in."); + return; + } + if (pb == null) { + Logger.error("endEffect(): Null PowerBase object passed in."); + return; + } + if (!effect.skipCancelEffect() && !effect.isNoOverwrite()) { + + int sendToken = this.token; + + if (effect.getAction() != null) + if (effect.getAction().getPowerAction() != null + && PowersManager.ActionTokenByIDString.containsKey(effect.getAction().getPowerAction().getIDString())) + try { + sendToken = PowersManager.ActionTokenByIDString.get(effect.getAction().getPowerAction().getIDString()); + } catch (Exception e) { + sendToken = this.token; + } + ApplyEffectMsg pum = new ApplyEffectMsg(); + pum.setEffectID(sendToken); + if (source != null) { + pum.setSourceType(source.getObjectType().ordinal()); + pum.setSourceID(source.getObjectUUID()); + } else { + pum.setSourceType(0); + pum.setSourceID(0); + } + pum.setTargetType(awo.getObjectType().ordinal()); + pum.setTargetID(awo.getObjectUUID()); + pum.setUnknown02(2); + pum.setNumTrains(0); + pum.setDuration(-1); + pum.setPowerUsedID(pb.getToken()); + pum.setPowerUsedName(pb.getName()); + DispatchMessage.sendToAllInRange(awo, pum); + + } + } + + public void endEffectNoPower(int trains, AbstractEffectJob effect) { + + AbstractWorldObject source = effect.getSource(); + + if (source == null) + return; + + if (!effect.skipCancelEffect() && !effect.isNoOverwrite()) { + ApplyEffectMsg pum = new ApplyEffectMsg(); + pum.setEffectID(this.token); + + pum.setSourceType(source.getObjectType().ordinal()); + pum.setSourceID(source.getObjectUUID()); + pum.setTargetType(source.getObjectType().ordinal()); + pum.setTargetID(source.getObjectUUID()); + pum.setUnknown02(2); + pum.setNumTrains(0); + pum.setDuration(-1); + pum.setUnknown06((byte) 1); + pum.setEffectSourceType(effect.getEffectSourceType()); + pum.setEffectSourceID(effect.getEffectSourceID()); + pum.setPowerUsedID(0); + pum.setPowerUsedName(this.name); + + if (source.getObjectType() == GameObjectType.PlayerCharacter) { + Dispatch dispatch = Dispatch.borrow((PlayerCharacter) source, pum); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); + } + } + } + + public void sendEffect(AbstractEffectJob effect, int duration, ClientConnection conn) { + if (effect == null && conn != null) + return; + + if (conn == null) + return; + AbstractWorldObject source = effect.getSource(); + AbstractWorldObject awo = effect.getTarget(); + int trains = effect.getTrains(); + if (source == null || awo == null) + return; + + if (this.token != 0) { + PowersBase pb = effect.getPower(); + if (pb == null) { + Logger.error("AbstractEffectModifier.applyEffectModifier: missing power"); + return; + } + ActionsBase ab = effect.getAction(); + if (ab == null) { + Logger.error("AbstractEffectModifier.applyEffectModifier: missing action"); + return; + } + + //don't send effect if dead, except for death shroud + if (!awo.isAlive()) { + if (pb.getToken() != 1672601862) + return; + } + + //duration for damage over times is (total time - (number of ticks x 5 seconds per tick)) + if (effect instanceof DamageOverTimeJob) + duration = ((DamageOverTimeJob) effect).getTickLength(); + + // float dur = (pb.isChant()) ? pb.getChantDuration() * 1000 : ab.getDuration(trains); + float dur = ab.getDuration(trains); + if (dur > 0f) { + ApplyEffectMsg pum = new ApplyEffectMsg(); + pum.setEffectID(this.token); + pum.setSourceType(source.getObjectType().ordinal()); + pum.setSourceID(source.getObjectUUID()); + pum.setTargetType(awo.getObjectType().ordinal()); + pum.setTargetID(awo.getObjectUUID()); + pum.setNumTrains(trains); + pum.setDuration(duration); + pum.setPowerUsedID(pb.getToken()); + pum.setPowerUsedName(pb.getName()); + + Dispatch dispatch = Dispatch.borrow(conn.getPlayerCharacter(), pum); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); + + } + } + } + + public void sendEffectNoPower(AbstractEffectJob effect, int duration, ClientConnection conn) { + + if (effect == null && conn != null) + return; + + if (conn == null) + return; + + AbstractWorldObject source = effect.getSource(); + AbstractWorldObject awo = effect.getTarget(); + int trains = effect.getTrains(); + + if (source == null || awo == null) + return; + + if (this.token != 0) { + //don't send effect if dead, except for death shroud + if (!awo.isAlive()) { + return; + } + + //duration for damage over times is (total time - (number of ticks x 5 seconds per tick)) + if (effect instanceof DamageOverTimeJob) + duration = ((DamageOverTimeJob) effect).getTickLength(); + else if (effect instanceof FinishSpireEffectJob) + duration = 45; + else if (effect instanceof NoTimeJob) + duration = -1; + + // float dur = (pb.isChant()) ? pb.getChantDuration() * 1000 : ab.getDuration(trains); + + ApplyEffectMsg pum = new ApplyEffectMsg(); + pum.setEffectID(this.token); + pum.setSourceType(source.getObjectType().ordinal()); + pum.setSourceID(source.getObjectUUID()); + pum.setTargetType(source.getObjectType().ordinal()); + pum.setTargetID(source.getObjectUUID()); + pum.setUnknown06((byte) 1); + pum.setEffectSourceType(effect.getEffectSourceType()); + pum.setEffectSourceID(effect.getEffectSourceID()); + pum.setNumTrains(trains); + pum.setDuration(duration); + pum.setPowerUsedID(0); + pum.setPowerUsedName(this.name); + + Dispatch dispatch = Dispatch.borrow(conn.getPlayerCharacter(), pum); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); + + } + } + + public boolean containsSource(EffectSourceType sourceType) { + if (EffectsBase.effectSourceTypeMap.containsKey(this.token) == false) + return false; + return EffectsBase.effectSourceTypeMap.get(this.token).contains(sourceType); + + } + + public boolean cancelOnAttack() { + return this.cancelOnAttack; + } + + public boolean cancelOnAttackSwing() { + return this.cancelOnAttackSwing; + } + + public boolean cancelOnCast() { + return this.cancelOnCast; + } + + public boolean cancelOnCastSpell() { + return this.cancelOnCastSpell; + } + + public boolean cancelOnEquipChange() { + return this.cancelOnEquipChange; + } + + public boolean cancelOnLogout() { + return this.cancelOnLogout; + } + + public boolean cancelOnMove() { + return this.cancelOnMove; + } + + public boolean cancelOnNewCharm() { + return this.cancelOnNewCharm; + } + + public boolean cancelOnSit() { + return this.cancelOnSit; + } + + public boolean cancelOnTakeDamage() { + return this.cancelOnTakeDamage; + } + + public boolean cancelOnTerritoryClaim() { + return this.cancelOnTerritoryClaim; + } + + public boolean cancelOnUnEquip() { + return this.cancelOnUnEquip; + } + + public String getDamageTypes() { + String text = ""; + if (!EffectsBase.EffectDamageTypes.containsKey(this.token)) + return text; + for (DamageType type : EffectsBase.EffectDamageTypes.get(this.token)) { + text += type.name() + ' '; + } + return text; + } + + public String getName() { + + return name; + } + + public void setName(String name) { + this.name = name; + } + + public float getValue() { + return value; + } + + public void setValue(float Value) { + this.value = Value; + } + + public ConcurrentHashMap getResourcesForEffect() { + if (this.resourceCosts.isEmpty()) { + ArrayList effectsCostList = DbManager.EffectsResourceCostsQueries.GET_ALL_EFFECT_RESOURCES(this.IDString); + for (EffectsResourceCosts erc : effectsCostList) { + this.resourceCosts.put(ItemBase.getItemBase(erc.getResourceID()), erc.getAmount()); + } + } + return this.resourceCosts; + } } diff --git a/src/engine/powers/FailCondition.java b/src/engine/powers/FailCondition.java index 5ee49f51..faeece1e 100644 --- a/src/engine/powers/FailCondition.java +++ b/src/engine/powers/FailCondition.java @@ -19,100 +19,100 @@ import java.util.ArrayList; public class FailCondition { - private String IDString; - private Boolean forPower; - private String type; - private float amount; - private float ramp; - private boolean rampAdd; - - // private String damageType1; - // private String damageType2; - // private String damageType3; - - /** - * No Table ID Constructor - */ - public FailCondition() { - - } - - /** - * ResultSet Constructor - */ - public FailCondition(ResultSet rs) throws SQLException { - - this.IDString = rs.getString("IDString"); - this.forPower = (rs.getString("powerOrEffect").equals("Power")) ? true : false; - this.type = rs.getString("type"); - this.amount = rs.getFloat("amount"); - this.ramp = rs.getFloat("ramp"); - this.rampAdd = (rs.getInt("useAddFormula") == 1) ? true : false; - // this.damageType1 = rs.getString("damageType1"); - // this.damageType2 = rs.getString("damageType2"); - // this.damageType3 = rs.getString("damageType3"); - } - - public static ArrayList getAllFailConditions() { - PreparedStatementShared ps = null; - ArrayList out = new ArrayList<>(); - try { - ps = new PreparedStatementShared("SELECT * FROM failconditions"); - ResultSet rs = ps.executeQuery(); - while (rs.next()) { - FailCondition toAdd = new FailCondition(rs); - out.add(toAdd); - } - rs.close(); - } catch (Exception e) { - Logger.error( e); - - } finally { - ps.release(); - } - return out; - } - - public String getIDString() { - return this.IDString; - } - - public String getType() { - return this.type; - } - - public boolean forPower() { - return this.forPower; - } - - public float getAmount() { - return this.amount; - } - - public float getRamp() { - return this.ramp; - } - - public float getAmountForTrains(float trains) { - if (this.rampAdd) - return this.amount + (this.ramp * trains); - else - return this.amount * (1 + (this.ramp * trains)); - } - - public boolean useRampAdd() { - return this.rampAdd; - } - - // public String getDamageType1() { - // return this.damageType1; - // } - - // public String getDamageType2() { - // return this.damageType2; - // } - - // public String getDamageType3() { - // return this.damageType3; - // } + private String IDString; + private Boolean forPower; + private String type; + private float amount; + private float ramp; + private boolean rampAdd; + + // private String damageType1; + // private String damageType2; + // private String damageType3; + + /** + * No Table ID Constructor + */ + public FailCondition() { + + } + + /** + * ResultSet Constructor + */ + public FailCondition(ResultSet rs) throws SQLException { + + this.IDString = rs.getString("IDString"); + this.forPower = (rs.getString("powerOrEffect").equals("Power")) ? true : false; + this.type = rs.getString("type"); + this.amount = rs.getFloat("amount"); + this.ramp = rs.getFloat("ramp"); + this.rampAdd = (rs.getInt("useAddFormula") == 1) ? true : false; + // this.damageType1 = rs.getString("damageType1"); + // this.damageType2 = rs.getString("damageType2"); + // this.damageType3 = rs.getString("damageType3"); + } + + public static ArrayList getAllFailConditions() { + PreparedStatementShared ps = null; + ArrayList out = new ArrayList<>(); + try { + ps = new PreparedStatementShared("SELECT * FROM failconditions"); + ResultSet rs = ps.executeQuery(); + while (rs.next()) { + FailCondition toAdd = new FailCondition(rs); + out.add(toAdd); + } + rs.close(); + } catch (Exception e) { + Logger.error(e); + + } finally { + ps.release(); + } + return out; + } + + public String getIDString() { + return this.IDString; + } + + public String getType() { + return this.type; + } + + public boolean forPower() { + return this.forPower; + } + + public float getAmount() { + return this.amount; + } + + public float getRamp() { + return this.ramp; + } + + public float getAmountForTrains(float trains) { + if (this.rampAdd) + return this.amount + (this.ramp * trains); + else + return this.amount * (1 + (this.ramp * trains)); + } + + public boolean useRampAdd() { + return this.rampAdd; + } + + // public String getDamageType1() { + // return this.damageType1; + // } + + // public String getDamageType2() { + // return this.damageType2; + // } + + // public String getDamageType3() { + // return this.damageType3; + // } } diff --git a/src/engine/powers/PowerPrereq.java b/src/engine/powers/PowerPrereq.java index b280e878..086185a5 100644 --- a/src/engine/powers/PowerPrereq.java +++ b/src/engine/powers/PowerPrereq.java @@ -19,87 +19,90 @@ import java.util.HashMap; public class PowerPrereq { - private String effect; - private String message; - private boolean mainHand; - private boolean required; - - /** - * No Table ID Constructor - */ - public PowerPrereq() { - - } - - /** - * ResultSet Constructor - */ - public PowerPrereq(ResultSet rs, int type) throws SQLException { - - // this.IDString = rs.getString("IDString"); - if (type == 1) { - this.effect = rs.getString("messageone"); - this.message = rs.getString("messagetwo"); - this.mainHand = false; - this.required = false; - } else if (type == 2) { - String sl = rs.getString("messageone"); - if (sl.equals("RHELD")) - this.mainHand = true; - else if (sl.equals("LHELD")) - this.mainHand = false; - this.effect = ""; - this.message = rs.getString("messagetwo"); - this.required = (rs.getInt("required") == 1) ? true : false; - } else { //targetEffectPrereq - this.effect = rs.getString("messageone"); - this.message = ""; - this.mainHand = false; - this.required = (rs.getInt("required") == 1) ? true : false; - } - } - - public static void getAllPowerPrereqs(HashMap powers) { - PreparedStatementShared ps = null; - try { - ps = new PreparedStatementShared("SELECT * FROM static_power_powercastprereq"); - ResultSet rs = ps.executeQuery(); - int type; String IDString; PowerPrereq toAdd; PowersBase pb; - while (rs.next()) { - IDString = rs.getString("IDString"); - pb = powers.get(IDString); - if (pb != null) { - type = rs.getInt("Type"); - toAdd = new PowerPrereq(rs, type); - if (type == 1) - pb.getEffectPrereqs().add(toAdd); - else if (type == 2) - pb.getEquipPrereqs().add(toAdd); - else - pb.getTargetEffectPrereqs().add(toAdd); - } - } - rs.close(); - } catch (Exception e) { - Logger.error( e.toString()); - } finally { - ps.release(); - } - } - - public String getEffect() { - return this.effect; - } - - public String getMessage() { - return this.message; - } - - public boolean mainHand() { - return this.mainHand; - } - - public boolean isRequired() { - return this.required; - } + private String effect; + private String message; + private boolean mainHand; + private boolean required; + + /** + * No Table ID Constructor + */ + public PowerPrereq() { + + } + + /** + * ResultSet Constructor + */ + public PowerPrereq(ResultSet rs, int type) throws SQLException { + + // this.IDString = rs.getString("IDString"); + if (type == 1) { + this.effect = rs.getString("messageone"); + this.message = rs.getString("messagetwo"); + this.mainHand = false; + this.required = false; + } else if (type == 2) { + String sl = rs.getString("messageone"); + if (sl.equals("RHELD")) + this.mainHand = true; + else if (sl.equals("LHELD")) + this.mainHand = false; + this.effect = ""; + this.message = rs.getString("messagetwo"); + this.required = (rs.getInt("required") == 1) ? true : false; + } else { //targetEffectPrereq + this.effect = rs.getString("messageone"); + this.message = ""; + this.mainHand = false; + this.required = (rs.getInt("required") == 1) ? true : false; + } + } + + public static void getAllPowerPrereqs(HashMap powers) { + PreparedStatementShared ps = null; + try { + ps = new PreparedStatementShared("SELECT * FROM static_power_powercastprereq"); + ResultSet rs = ps.executeQuery(); + int type; + String IDString; + PowerPrereq toAdd; + PowersBase pb; + while (rs.next()) { + IDString = rs.getString("IDString"); + pb = powers.get(IDString); + if (pb != null) { + type = rs.getInt("Type"); + toAdd = new PowerPrereq(rs, type); + if (type == 1) + pb.getEffectPrereqs().add(toAdd); + else if (type == 2) + pb.getEquipPrereqs().add(toAdd); + else + pb.getTargetEffectPrereqs().add(toAdd); + } + } + rs.close(); + } catch (Exception e) { + Logger.error(e.toString()); + } finally { + ps.release(); + } + } + + public String getEffect() { + return this.effect; + } + + public String getMessage() { + return this.message; + } + + public boolean mainHand() { + return this.mainHand; + } + + public boolean isRequired() { + return this.required; + } } diff --git a/src/engine/powers/PowersBase.java b/src/engine/powers/PowersBase.java index ca24eb06..9cfc8c01 100644 --- a/src/engine/powers/PowersBase.java +++ b/src/engine/powers/PowersBase.java @@ -19,629 +19,618 @@ import java.util.ArrayList; public class PowersBase { - public int UUID; - public String name; - public int token; - public String IDString; - public String category; - public int skillID; - public float range; - public float cost; - public float costRamp; - public float castTime; - public float castTimeRamp; - public float cooldown; - public float recycleTime; - public float recycleRamp; - public int maxTrains; - public float hateValue; - public float hateRamp; - public String monsterTypePrereq; // target limited to these types - public String skillName; - public float weaponRange = 15f; - - // aoe related - public boolean isAOE = true; - public boolean useCone = false; - public boolean usePointBlank = false; - public boolean useSphere = false; - public float radius; - public byte groupReq; // who the spell won't hit - public int maxNumMobTargets; - public int maxNumPlayerTargets; - - // chant related - public float chantDuration; - public int chantIterations; - - // valid target types from targetType field - public boolean targetPlayer = false; - public boolean targetMob = false; - public boolean targetPet = false; - public boolean targetNecroPet = false; - public boolean targetSelf = false; - public boolean targetWeapon = false; - public boolean targetCorpse = false; - public boolean targetBuilding = false; - public boolean targetGroup = false; - public boolean targetGuildLeader = false; - public boolean targetJewelry = false; - public boolean targetArmor = false; - public boolean targetItem = false; - - - // flags - public boolean isCasterFriendly = false; // from groupReq - public boolean isGroupFriendly = false; // from groupReq - public boolean isGroupOnly = false; // from groupReq - public boolean mustHitPets = false; // from groupReq - public boolean isNationFriendly = false; // from groupReq - public boolean targetFromLastTarget = false; // from unknown06 - public boolean targetFromSelf = false; // from unknown06 - public boolean targetFromName = false; // from unknown06 - public boolean targetFromNearbyMobs = false; // from unknown06 - public boolean useHealth = false; // from costType - public boolean useMana = false; // from costType - public boolean useStamina = false; // from costType - public boolean isSpell = true; // from skillOrSpell field - public boolean allowedInCombat = false; // from combat field - public boolean allowedOutOfCombat = false; // from combat field - public boolean regularPlayerCanCast = false; // from grantOverrideVar - public boolean hateRampAdd = true; // 1 bit flag - public boolean costRampAdd = true; // 2 bit flag - public boolean recycleRampAdd = true; // 4 bit flag - public boolean initRampAdd = true; // 8 bit flag - public boolean canCastWhileMoving = false; // 16 bit flag - public boolean canCastWhileFlying = false; // 32 bit flag - public boolean isChant = false; // 64 bit flag - public boolean losCheck = false; // 128 bit flag - public boolean sticky = false; // 256 bit flag - public boolean isAdminPower = false; // 512 bit flag - public boolean requiresHitRoll = false; // 1024 bit flag - public boolean isWeaponPower = false; // from category - public boolean isHeal = false; //from category - public boolean isTrack = false; //from category - public boolean isHarmful = true; - public boolean vampDrain = false; - - public boolean cancelOnCastSpell = false; - public boolean cancelOnTakeDamage = false; - - public final ArrayList monsterTypeRestrictions = new ArrayList<>(); - public final ArrayList actions = new ArrayList<>(); - public final ArrayList effectPrereqs = new ArrayList<>(); - public final ArrayList targetEffectPrereqs = new ArrayList<>(); - public final ArrayList equipPrereqs = new ArrayList<>(); - - public PowerTargetType targetType; - public PowerCategoryType powerCategory; - public String description; - - /** - * No Table ID Constructor - */ - public PowersBase() { - - } - - /** - * ResultSet Constructor - */ - public PowersBase(ResultSet rs) throws SQLException { - - this.UUID = rs.getInt("ID"); - this.name = rs.getString("name").trim(); - this.token = rs.getInt("token"); - this.skillName = rs.getString("skillName").trim(); - this.IDString = rs.getString("IDString").trim(); - this.isSpell = (rs.getString("skillOrSpell").equals("SPELL")) ? true : false; - this.skillID = rs.getInt("skillID"); - this.range = rs.getFloat("range"); - this.description = (rs.getString("description")).trim().replace("\r\n ", ""); - String ct = rs.getString("costType").trim(); - if (ct.equals("HEALTH")) - this.useHealth = true; - else if (ct.equals("MANA")) - this.useMana = true; - else if (ct.equals("STAMINA")) - this.useStamina = true; - ct = rs.getString("targetType").trim(); - if (ct.equals("BUILDING")) - this.targetBuilding = true; - else if (ct.equals("CORPSE")) - this.targetCorpse = true; - else if (ct.equals("GROUP")) - this.targetGroup = true; - else if (ct.equals("GUILDLEADER")) - this.targetGuildLeader = true; - else if (ct.equals("MOBILE")) { - this.targetMob = true; - this.targetPet = true; // sure on this one? - } else if (ct.equals("PC")) - this.targetPlayer = true; - else if (ct.equals("SELF")) - this.targetSelf = true; - else if (ct.equals("PET")) - this.targetPet = true; - else if (ct.equals("NECROPET")) - this.targetNecroPet = true; - else if (ct.equals("ARMOR")) - this.targetArmor = true; - else if (ct.equals("WEAPON")) - this.targetWeapon = true; - else if (ct.equals("JEWELRY")) - this.targetJewelry = true; - else if (ct.equals("ITEM")) { - this.targetItem = true; - this.targetJewelry = true; - this.targetArmor = true; - this.targetWeapon = true; - } else if (ct.equals("ARMORWEAPONJEWELRY")) { - this.targetArmor = true; - this.targetWeapon = true; - this.targetJewelry = true; - } else if (ct.equals("PCMOBILE")) { - this.targetPlayer = true; - this.targetMob = true; - this.targetPet = true; // sure on this one? - } else if (ct.equals("WEAPONARMOR")) { - this.targetWeapon = true; - this.targetArmor = true; - } else { - Logger.info("Missed " + ct + " targetType"); - } - String cat = rs.getString("category").trim(); - this.category = cat; - - - if (cat.isEmpty()) - this.powerCategory = PowerCategoryType.NONE; - else - this.powerCategory = PowerCategoryType.valueOf(cat.replace("-", "")); - - - - - if (cat.equals("WEAPON")) { - this.isWeaponPower = true; - this.isHarmful = false; - if (this.skillName.equals("Bow") || this.skillName.equals("Crossbow") || this.skillName.equals("Archery")) - this.weaponRange = 1000f; - else if (this.skillName.equals("Throwing")) - this.weaponRange = 60f; - else - this.weaponRange = 15f; - } else if (cat.equals("HEAL") || cat.equals("GROUPHEAL")) { - this.isHeal = true; - this.isHarmful = false; - } else if (cat.equals("TRACK")) { - this.isTrack = true; - this.isHarmful = false; - } else if (cat.equals("AE") || cat.equals("AEDAMAGE") || - cat.equals("BREAKFLY") || - cat.equals("DAMAGE") || cat.equals("DEBUFF") || - cat.equals("MOVE") || cat.equals("SPECIAL") || - cat.equals("SPIREDISABLE")) - this.isHarmful = true; - else if (cat.equals("CHANT")) { - this.isHarmful = ct.equals("MOBILE") || ct.equals("PC") || ct.equals("PCMOBILE"); - } else if (cat.equals("DISPEL")) { - //TODO this needs broken down better later - this.isHarmful = false; - } else if (cat.isEmpty()) { - if (ct.equals("MOBILE") || ct.equals("PCMOBILE")) - this.isHarmful = true; - else if (ct.equals("PC")) { - this.isHarmful = this.token != 429607195 && this.token != 429425915; - } else - this.isHarmful = false; - } else - this.isHarmful = false; - - if (cat.equals("VAMPDRAIN")) { - this.vampDrain = true; - this.isHarmful = true; - } - - this.cost = rs.getFloat("cost"); - this.costRamp = rs.getFloat("costRamp"); - this.castTime = rs.getFloat("castTime"); - this.castTimeRamp = rs.getFloat("initRamp"); - this.cooldown = rs.getFloat("cooldown"); - this.recycleTime = rs.getFloat("recycleTime"); - this.recycleRamp = rs.getFloat("recycleRamp"); - this.maxTrains = rs.getInt("maxTrains"); - this.hateValue = rs.getFloat("hateValue"); - this.hateRamp = rs.getFloat("hateRamp"); - ct = rs.getString("unknown06").trim(); - if (this.targetSelf) { - } else if (ct.equals("CLICK")) - if (!this.targetGroup) - this.targetFromLastTarget = true; - else if (ct.equals("NAME")) - this.targetFromName = true; - else if (ct.equals("NEARBYMOBS")) - this.targetFromNearbyMobs = true; - this.monsterTypePrereq = rs.getString("monsterTypePrereqs").trim(); - ct = rs.getString("radiusType").trim(); - if (ct.equals("CONE")) - this.useCone = true; - else if (ct.equals("POINTBLANK")) - this.usePointBlank = true; - else if (ct.equals("SPHERE")) - this.useSphere = true; - else - this.isAOE = false; - this.radius = rs.getFloat("radius"); - ct = rs.getString("groupReq").trim(); - if (ct.equals("CASTER")) - this.isCasterFriendly = true; - else if (ct.equals("GROUP")) { - this.isGroupFriendly = true; - this.isCasterFriendly = true; - } - else if (ct.equals("ALLBUTGROUP")) - this.isGroupOnly = true; - else if (ct.equals("ALLBUTPETS")) - this.mustHitPets = true; - else if (ct.equals("NATION")) { - this.isNationFriendly = true; - this.isCasterFriendly = true; - } - this.maxNumMobTargets = rs.getInt("maxNumMobTargets"); - this.maxNumPlayerTargets = rs.getInt("maxNumPlayerTargets"); - this.chantDuration = rs.getFloat("chantDuration"); - this.chantIterations = rs.getInt("chantIterations"); - ct = rs.getString("combat").trim(); - if (ct.equals("COMBAT")) - this.allowedInCombat = true; - else if (ct.equals("NONCOMBAT")) - this.allowedOutOfCombat = true; - else if (ct.equals("BOTH")) { - this.allowedInCombat = true; - this.allowedOutOfCombat = true; - } - ct = rs.getString("grantOverideVar").trim(); - if (ct.equals("PGOV_PLAYER")) - this.regularPlayerCanCast = true; - int flags = rs.getInt("flags"); - if ((flags & 1) == 0) - this.hateRampAdd = false; - if ((flags & 2) == 0) - this.costRampAdd = false; - if ((flags & 4) == 0) - this.recycleRampAdd = false; - if ((flags & 8) == 0) - this.initRampAdd = false; - if ((flags & 16) != 0) - this.canCastWhileMoving = true; - if ((flags & 32) != 0) - this.canCastWhileFlying = true; - if ((flags & 64) != 0) - this.isChant = true; - if ((flags & 128) != 0) - this.losCheck = true; - if ((flags & 256) != 0) - this.sticky = true; - if ((flags & 512) != 0) - this.isAdminPower = true; - if ((flags & 1024) != 0) - this.requiresHitRoll = true; - ct = rs.getString("monsterTypeRestrict1").trim(); - if (!ct.isEmpty()) - this.monsterTypeRestrictions.add(ct); - ct = rs.getString("monsterTypeRestrict2").trim(); - if (!ct.isEmpty()) - this.monsterTypeRestrictions.add(ct); - ct = rs.getString("monsterTypeRestrict3").trim(); - if (!ct.isEmpty()) - this.monsterTypeRestrictions.add(ct); - } - - - public String getName() { - return this.name; - } - - public int getMaxTrains() { - return this.maxTrains; - } - - public int getUUID() { - return this.UUID; - } - - public String getIDString() { - return this.IDString; - } - - public int getToken() { - if (this.IDString.equals("BLEED-DOT-10.5-RANGE")) - return -369682965; - return this.token; - } - - public int getCastTime(int trains) { // returns cast time in ms - if (this.initRampAdd) - return (int) ((this.castTime + (this.castTimeRamp * trains)) * 1000); - else - return (int) ((this.castTime * (1 + (this.castTimeRamp * trains))) * 1000); - } - - public int getRecycleTime(int trains) { // returns cast time in ms - if (this.recycleRampAdd) - return (int) (((this.recycleTime + (this.recycleRamp * trains)) * 1000) + getCastTime(trains)); - else - return (int) (((this.recycleTime * (1 + (this.recycleRamp * trains))) * 1000) + getCastTime(trains)); - } - - // public ArrayList getConditions() { - // return this.conditions; - // } - - public ArrayList getEffectPrereqs() { - return this.effectPrereqs; - } - - public ArrayList getTargetEffectPrereqs() { - return this.targetEffectPrereqs; - } - - public ArrayList getEquipPrereqs() { - return this.equipPrereqs; - } - - public ArrayList getActions() { - return this.actions; - } - - public boolean usePointBlank() { - return this.usePointBlank; - } - - public float getRadius() { - return this.radius; - } - - public int getMaxNumMobTargets() { - return this.maxNumMobTargets; - } - - public int getMaxNumPlayerTargets() { - return this.maxNumPlayerTargets; - } - - public boolean cancelOnCastSpell() { - return this.cancelOnCastSpell; - } - - public boolean cancelOnTakeDamage() { - return this.cancelOnTakeDamage; - } - - public boolean allowedInCombat() { - return this.allowedInCombat; - } - - public boolean allowedOutOfCombat() { - return this.allowedOutOfCombat; - } - - public boolean isCasterFriendly() { - return this.isCasterFriendly; - } - - public boolean isGroupFriendly() { - return this.isGroupFriendly; - } - - public boolean isNationFriendly() { - return this.isNationFriendly; - } - - public boolean isGroupOnly() { - return this.isGroupOnly; - } - - public boolean mustHitPets() { - return this.mustHitPets; - } - - public boolean targetFromLastTarget() { - return this.targetFromLastTarget; - } - - public boolean targetFromSelf() { - return this.targetFromSelf; - } - - public boolean targetFromName() { - return this.targetFromName; - } - - public boolean targetFromNearbyMobs() { - return this.targetFromNearbyMobs; - } - - public float getRange() { - return this.range; - } - - public boolean requiresHitRoll() { - return this.requiresHitRoll; - } - - public boolean regularPlayerCanCast() { - return this.regularPlayerCanCast; - } + public final ArrayList monsterTypeRestrictions = new ArrayList<>(); + public final ArrayList actions = new ArrayList<>(); + public final ArrayList effectPrereqs = new ArrayList<>(); + public final ArrayList targetEffectPrereqs = new ArrayList<>(); + public final ArrayList equipPrereqs = new ArrayList<>(); + public int UUID; + public String name; + public int token; + public String IDString; + public String category; + public int skillID; + public float range; + public float cost; + public float costRamp; + public float castTime; + public float castTimeRamp; + public float cooldown; + public float recycleTime; + public float recycleRamp; + public int maxTrains; + public float hateValue; + public float hateRamp; + public String monsterTypePrereq; // target limited to these types + public String skillName; + public float weaponRange = 15f; + // aoe related + public boolean isAOE = true; + public boolean useCone = false; + public boolean usePointBlank = false; + public boolean useSphere = false; + public float radius; + public byte groupReq; // who the spell won't hit + public int maxNumMobTargets; + public int maxNumPlayerTargets; + // chant related + public float chantDuration; + public int chantIterations; + // valid target types from targetType field + public boolean targetPlayer = false; + public boolean targetMob = false; + public boolean targetPet = false; + public boolean targetNecroPet = false; + public boolean targetSelf = false; + public boolean targetWeapon = false; + public boolean targetCorpse = false; + public boolean targetBuilding = false; + public boolean targetGroup = false; + public boolean targetGuildLeader = false; + public boolean targetJewelry = false; + public boolean targetArmor = false; + public boolean targetItem = false; + // flags + public boolean isCasterFriendly = false; // from groupReq + public boolean isGroupFriendly = false; // from groupReq + public boolean isGroupOnly = false; // from groupReq + public boolean mustHitPets = false; // from groupReq + public boolean isNationFriendly = false; // from groupReq + public boolean targetFromLastTarget = false; // from unknown06 + public boolean targetFromSelf = false; // from unknown06 + public boolean targetFromName = false; // from unknown06 + public boolean targetFromNearbyMobs = false; // from unknown06 + public boolean useHealth = false; // from costType + public boolean useMana = false; // from costType + public boolean useStamina = false; // from costType + public boolean isSpell = true; // from skillOrSpell field + public boolean allowedInCombat = false; // from combat field + public boolean allowedOutOfCombat = false; // from combat field + public boolean regularPlayerCanCast = false; // from grantOverrideVar + public boolean hateRampAdd = true; // 1 bit flag + public boolean costRampAdd = true; // 2 bit flag + public boolean recycleRampAdd = true; // 4 bit flag + public boolean initRampAdd = true; // 8 bit flag + public boolean canCastWhileMoving = false; // 16 bit flag + public boolean canCastWhileFlying = false; // 32 bit flag + public boolean isChant = false; // 64 bit flag + public boolean losCheck = false; // 128 bit flag + public boolean sticky = false; // 256 bit flag + public boolean isAdminPower = false; // 512 bit flag + public boolean requiresHitRoll = false; // 1024 bit flag + public boolean isWeaponPower = false; // from category + public boolean isHeal = false; //from category + public boolean isTrack = false; //from category + public boolean isHarmful = true; + public boolean vampDrain = false; + public boolean cancelOnCastSpell = false; + public boolean cancelOnTakeDamage = false; + public PowerTargetType targetType; + public PowerCategoryType powerCategory; + public String description; + + /** + * No Table ID Constructor + */ + public PowersBase() { + + } + + /** + * ResultSet Constructor + */ + public PowersBase(ResultSet rs) throws SQLException { + + this.UUID = rs.getInt("ID"); + this.name = rs.getString("name").trim(); + this.token = rs.getInt("token"); + this.skillName = rs.getString("skillName").trim(); + this.IDString = rs.getString("IDString").trim(); + this.isSpell = (rs.getString("skillOrSpell").equals("SPELL")) ? true : false; + this.skillID = rs.getInt("skillID"); + this.range = rs.getFloat("range"); + this.description = (rs.getString("description")).trim().replace("\r\n ", ""); + String ct = rs.getString("costType").trim(); + if (ct.equals("HEALTH")) + this.useHealth = true; + else if (ct.equals("MANA")) + this.useMana = true; + else if (ct.equals("STAMINA")) + this.useStamina = true; + ct = rs.getString("targetType").trim(); + if (ct.equals("BUILDING")) + this.targetBuilding = true; + else if (ct.equals("CORPSE")) + this.targetCorpse = true; + else if (ct.equals("GROUP")) + this.targetGroup = true; + else if (ct.equals("GUILDLEADER")) + this.targetGuildLeader = true; + else if (ct.equals("MOBILE")) { + this.targetMob = true; + this.targetPet = true; // sure on this one? + } else if (ct.equals("PC")) + this.targetPlayer = true; + else if (ct.equals("SELF")) + this.targetSelf = true; + else if (ct.equals("PET")) + this.targetPet = true; + else if (ct.equals("NECROPET")) + this.targetNecroPet = true; + else if (ct.equals("ARMOR")) + this.targetArmor = true; + else if (ct.equals("WEAPON")) + this.targetWeapon = true; + else if (ct.equals("JEWELRY")) + this.targetJewelry = true; + else if (ct.equals("ITEM")) { + this.targetItem = true; + this.targetJewelry = true; + this.targetArmor = true; + this.targetWeapon = true; + } else if (ct.equals("ARMORWEAPONJEWELRY")) { + this.targetArmor = true; + this.targetWeapon = true; + this.targetJewelry = true; + } else if (ct.equals("PCMOBILE")) { + this.targetPlayer = true; + this.targetMob = true; + this.targetPet = true; // sure on this one? + } else if (ct.equals("WEAPONARMOR")) { + this.targetWeapon = true; + this.targetArmor = true; + } else { + Logger.info("Missed " + ct + " targetType"); + } + String cat = rs.getString("category").trim(); + this.category = cat; + + + if (cat.isEmpty()) + this.powerCategory = PowerCategoryType.NONE; + else + this.powerCategory = PowerCategoryType.valueOf(cat.replace("-", "")); + + + if (cat.equals("WEAPON")) { + this.isWeaponPower = true; + this.isHarmful = false; + if (this.skillName.equals("Bow") || this.skillName.equals("Crossbow") || this.skillName.equals("Archery")) + this.weaponRange = 1000f; + else if (this.skillName.equals("Throwing")) + this.weaponRange = 60f; + else + this.weaponRange = 15f; + } else if (cat.equals("HEAL") || cat.equals("GROUPHEAL")) { + this.isHeal = true; + this.isHarmful = false; + } else if (cat.equals("TRACK")) { + this.isTrack = true; + this.isHarmful = false; + } else if (cat.equals("AE") || cat.equals("AEDAMAGE") || + cat.equals("BREAKFLY") || + cat.equals("DAMAGE") || cat.equals("DEBUFF") || + cat.equals("MOVE") || cat.equals("SPECIAL") || + cat.equals("SPIREDISABLE")) + this.isHarmful = true; + else if (cat.equals("CHANT")) { + this.isHarmful = ct.equals("MOBILE") || ct.equals("PC") || ct.equals("PCMOBILE"); + } else if (cat.equals("DISPEL")) { + //TODO this needs broken down better later + this.isHarmful = false; + } else if (cat.isEmpty()) { + if (ct.equals("MOBILE") || ct.equals("PCMOBILE")) + this.isHarmful = true; + else if (ct.equals("PC")) { + this.isHarmful = this.token != 429607195 && this.token != 429425915; + } else + this.isHarmful = false; + } else + this.isHarmful = false; + + if (cat.equals("VAMPDRAIN")) { + this.vampDrain = true; + this.isHarmful = true; + } + + this.cost = rs.getFloat("cost"); + this.costRamp = rs.getFloat("costRamp"); + this.castTime = rs.getFloat("castTime"); + this.castTimeRamp = rs.getFloat("initRamp"); + this.cooldown = rs.getFloat("cooldown"); + this.recycleTime = rs.getFloat("recycleTime"); + this.recycleRamp = rs.getFloat("recycleRamp"); + this.maxTrains = rs.getInt("maxTrains"); + this.hateValue = rs.getFloat("hateValue"); + this.hateRamp = rs.getFloat("hateRamp"); + ct = rs.getString("unknown06").trim(); + if (this.targetSelf) { + } else if (ct.equals("CLICK")) + if (!this.targetGroup) + this.targetFromLastTarget = true; + else if (ct.equals("NAME")) + this.targetFromName = true; + else if (ct.equals("NEARBYMOBS")) + this.targetFromNearbyMobs = true; + this.monsterTypePrereq = rs.getString("monsterTypePrereqs").trim(); + ct = rs.getString("radiusType").trim(); + if (ct.equals("CONE")) + this.useCone = true; + else if (ct.equals("POINTBLANK")) + this.usePointBlank = true; + else if (ct.equals("SPHERE")) + this.useSphere = true; + else + this.isAOE = false; + this.radius = rs.getFloat("radius"); + ct = rs.getString("groupReq").trim(); + if (ct.equals("CASTER")) + this.isCasterFriendly = true; + else if (ct.equals("GROUP")) { + this.isGroupFriendly = true; + this.isCasterFriendly = true; + } else if (ct.equals("ALLBUTGROUP")) + this.isGroupOnly = true; + else if (ct.equals("ALLBUTPETS")) + this.mustHitPets = true; + else if (ct.equals("NATION")) { + this.isNationFriendly = true; + this.isCasterFriendly = true; + } + this.maxNumMobTargets = rs.getInt("maxNumMobTargets"); + this.maxNumPlayerTargets = rs.getInt("maxNumPlayerTargets"); + this.chantDuration = rs.getFloat("chantDuration"); + this.chantIterations = rs.getInt("chantIterations"); + ct = rs.getString("combat").trim(); + if (ct.equals("COMBAT")) + this.allowedInCombat = true; + else if (ct.equals("NONCOMBAT")) + this.allowedOutOfCombat = true; + else if (ct.equals("BOTH")) { + this.allowedInCombat = true; + this.allowedOutOfCombat = true; + } + ct = rs.getString("grantOverideVar").trim(); + if (ct.equals("PGOV_PLAYER")) + this.regularPlayerCanCast = true; + int flags = rs.getInt("flags"); + if ((flags & 1) == 0) + this.hateRampAdd = false; + if ((flags & 2) == 0) + this.costRampAdd = false; + if ((flags & 4) == 0) + this.recycleRampAdd = false; + if ((flags & 8) == 0) + this.initRampAdd = false; + if ((flags & 16) != 0) + this.canCastWhileMoving = true; + if ((flags & 32) != 0) + this.canCastWhileFlying = true; + if ((flags & 64) != 0) + this.isChant = true; + if ((flags & 128) != 0) + this.losCheck = true; + if ((flags & 256) != 0) + this.sticky = true; + if ((flags & 512) != 0) + this.isAdminPower = true; + if ((flags & 1024) != 0) + this.requiresHitRoll = true; + ct = rs.getString("monsterTypeRestrict1").trim(); + if (!ct.isEmpty()) + this.monsterTypeRestrictions.add(ct); + ct = rs.getString("monsterTypeRestrict2").trim(); + if (!ct.isEmpty()) + this.monsterTypeRestrictions.add(ct); + ct = rs.getString("monsterTypeRestrict3").trim(); + if (!ct.isEmpty()) + this.monsterTypeRestrictions.add(ct); + } + + + public String getName() { + return this.name; + } + + public int getMaxTrains() { + return this.maxTrains; + } + + public int getUUID() { + return this.UUID; + } + + public String getIDString() { + return this.IDString; + } + + public int getToken() { + if (this.IDString.equals("BLEED-DOT-10.5-RANGE")) + return -369682965; + return this.token; + } + + public int getCastTime(int trains) { // returns cast time in ms + if (this.initRampAdd) + return (int) ((this.castTime + (this.castTimeRamp * trains)) * 1000); + else + return (int) ((this.castTime * (1 + (this.castTimeRamp * trains))) * 1000); + } + + public int getRecycleTime(int trains) { // returns cast time in ms + if (this.recycleRampAdd) + return (int) (((this.recycleTime + (this.recycleRamp * trains)) * 1000) + getCastTime(trains)); + else + return (int) (((this.recycleTime * (1 + (this.recycleRamp * trains))) * 1000) + getCastTime(trains)); + } + + // public ArrayList getConditions() { + // return this.conditions; + // } + + public ArrayList getEffectPrereqs() { + return this.effectPrereqs; + } + + public ArrayList getTargetEffectPrereqs() { + return this.targetEffectPrereqs; + } + + public ArrayList getEquipPrereqs() { + return this.equipPrereqs; + } + + public ArrayList getActions() { + return this.actions; + } + + public boolean usePointBlank() { + return this.usePointBlank; + } + + public float getRadius() { + return this.radius; + } + + public int getMaxNumMobTargets() { + return this.maxNumMobTargets; + } + + public int getMaxNumPlayerTargets() { + return this.maxNumPlayerTargets; + } + + public boolean cancelOnCastSpell() { + return this.cancelOnCastSpell; + } + + public boolean cancelOnTakeDamage() { + return this.cancelOnTakeDamage; + } + + public boolean allowedInCombat() { + return this.allowedInCombat; + } + + public boolean allowedOutOfCombat() { + return this.allowedOutOfCombat; + } + + public boolean isCasterFriendly() { + return this.isCasterFriendly; + } + + public boolean isGroupFriendly() { + return this.isGroupFriendly; + } + + public boolean isNationFriendly() { + return this.isNationFriendly; + } + + public boolean isGroupOnly() { + return this.isGroupOnly; + } + + public boolean mustHitPets() { + return this.mustHitPets; + } + + public boolean targetFromLastTarget() { + return this.targetFromLastTarget; + } + + public boolean targetFromSelf() { + return this.targetFromSelf; + } + + public boolean targetFromName() { + return this.targetFromName; + } + + public boolean targetFromNearbyMobs() { + return this.targetFromNearbyMobs; + } + + public float getRange() { + return this.range; + } + + public boolean requiresHitRoll() { + return this.requiresHitRoll; + } + + public boolean regularPlayerCanCast() { + return this.regularPlayerCanCast; + } - public boolean isSpell() { - return this.isSpell; - } + public boolean isSpell() { + return this.isSpell; + } - public boolean isHarmful() { - return this.isHarmful; - } + public boolean isHarmful() { + return this.isHarmful; + } - public boolean targetPlayer() { - return this.targetPlayer; - } + public boolean targetPlayer() { + return this.targetPlayer; + } - public boolean targetMob() { - return this.targetMob; - } + public boolean targetMob() { + return this.targetMob; + } - public boolean targetPet() { - return this.targetPet; - } + public boolean targetPet() { + return this.targetPet; + } - public boolean targetNecroPet() { - return this.targetNecroPet; - } + public boolean targetNecroPet() { + return this.targetNecroPet; + } - public boolean targetSelf() { - return this.targetSelf; - } + public boolean targetSelf() { + return this.targetSelf; + } - public boolean targetCorpse() { - return this.targetCorpse; - } + public boolean targetCorpse() { + return this.targetCorpse; + } - public boolean targetBuilding() { - return this.targetBuilding; - } + public boolean targetBuilding() { + return this.targetBuilding; + } - public boolean targetGroup() { - return this.targetGroup; - } + public boolean targetGroup() { + return this.targetGroup; + } - public boolean targetGuildLeader() { - return this.targetGuildLeader; - } + public boolean targetGuildLeader() { + return this.targetGuildLeader; + } - public boolean targetJewelry() { - return this.targetJewelry; - } + public boolean targetJewelry() { + return this.targetJewelry; + } - public boolean targetArmor() { - return this.targetArmor; - } + public boolean targetArmor() { + return this.targetArmor; + } - public boolean targetWeapon() { - return this.targetWeapon; - } + public boolean targetWeapon() { + return this.targetWeapon; + } - public boolean targetItem() { - return this.targetItem; - } + public boolean targetItem() { + return this.targetItem; + } - public long getCooldown() { - return (long) (this.cooldown * 1000); // return - // in ms - } - - public boolean useHealth() { - return this.useHealth; - } - - public boolean useMana() { - return this.useMana; - } - - public boolean useStamina() { - return this.useStamina; - } - - public float getCost(int trains) { - if (this.costRampAdd) - return this.cost + (this.costRamp * trains); - else - return this.cost * (1 + (this.costRamp * trains)); - - } - - public float getHateValue() { - return this.hateValue; - } - - public float getHateRamp() { - return this.hateRamp; - } - - public float getHateValue(int trains) { - return this.hateValue + (this.hateRamp * trains); - } - - public boolean canCastWhileMoving() { - return this.canCastWhileMoving; - } - - public boolean canCastWhileFlying() { - return this.canCastWhileFlying; - } - - public boolean isAOE() { - return isAOE; - } - - public boolean isChant() { - return isChant; - } - - public int getChantIterations() { - return chantIterations; - } - - public float getChantDuration() { - return chantDuration; - } - - public boolean isWeaponPower() { - return isWeaponPower; - } - - public boolean isHeal() { - return isHeal; - } - - public boolean isTrack() { - return isTrack; - } - - public boolean vampDrain() { - return vampDrain; - } - - public void setCancelOnCastSpell(boolean value) { - this.cancelOnCastSpell = value; - } - - public void setCancelOnTakeDamage(boolean value) { - this.cancelOnTakeDamage = value; - } - - public String getSkillName() { - return this.skillName; - } - - public String getMonsterTypePrereq() { - return this.monsterTypePrereq; - } - - public String getCategory() { - return this.category; - } - - public float getWeaponRange() { - return this.weaponRange; - } - - public PowerCategoryType getPowerCategoryType(){ - return this.powerCategory; - } - - public String getDescription() { - return description; - } + public long getCooldown() { + return (long) (this.cooldown * 1000); // return + // in ms + } + + public boolean useHealth() { + return this.useHealth; + } + + public boolean useMana() { + return this.useMana; + } + + public boolean useStamina() { + return this.useStamina; + } + + public float getCost(int trains) { + if (this.costRampAdd) + return this.cost + (this.costRamp * trains); + else + return this.cost * (1 + (this.costRamp * trains)); + + } + + public float getHateValue() { + return this.hateValue; + } + + public float getHateRamp() { + return this.hateRamp; + } + + public float getHateValue(int trains) { + return this.hateValue + (this.hateRamp * trains); + } + + public boolean canCastWhileMoving() { + return this.canCastWhileMoving; + } + + public boolean canCastWhileFlying() { + return this.canCastWhileFlying; + } + + public boolean isAOE() { + return isAOE; + } + + public boolean isChant() { + return isChant; + } + + public int getChantIterations() { + return chantIterations; + } + + public float getChantDuration() { + return chantDuration; + } + + public boolean isWeaponPower() { + return isWeaponPower; + } + + public boolean isHeal() { + return isHeal; + } + + public boolean isTrack() { + return isTrack; + } + + public boolean vampDrain() { + return vampDrain; + } + + public void setCancelOnCastSpell(boolean value) { + this.cancelOnCastSpell = value; + } + + public void setCancelOnTakeDamage(boolean value) { + this.cancelOnTakeDamage = value; + } + + public String getSkillName() { + return this.skillName; + } + + public String getMonsterTypePrereq() { + return this.monsterTypePrereq; + } + + public String getCategory() { + return this.category; + } + + public float getWeaponRange() { + return this.weaponRange; + } + + public PowerCategoryType getPowerCategoryType() { + return this.powerCategory; + } + + public String getDescription() { + return description; + } } diff --git a/src/engine/powers/RangeBasedAwo.java b/src/engine/powers/RangeBasedAwo.java index b80c654e..66a499c8 100644 --- a/src/engine/powers/RangeBasedAwo.java +++ b/src/engine/powers/RangeBasedAwo.java @@ -23,82 +23,82 @@ import java.util.HashSet; //sorted by range from a specified point. public class RangeBasedAwo implements Comparable { - private float range; - private AbstractWorldObject awo; - - public RangeBasedAwo(Float range, AbstractWorldObject awo) { - super(); - this.range = range; - this.awo = awo; - } - - public static HashSet createList(HashSet awolist, Vector3fImmutable searchLoc) { - HashSet rbal = new HashSet<>(); - for (AbstractWorldObject awo: awolist) { - RangeBasedAwo rba = new RangeBasedAwo(searchLoc.distance(awo.getLoc()), awo); - rbal.add(rba); - } - return rbal; - } - - @Override - public int compareTo(RangeBasedAwo obj) throws ClassCastException { - return (int)(this.range - obj.range); - } - - public static HashSet getSortedList(HashSet awolist, Vector3fImmutable searchLoc, int maxPlayers, int maxMobs) { - int playerCnt = 0; - int mobCnt = 0; - int maxCnt = (maxPlayers > maxMobs) ? maxPlayers : maxMobs; - HashSet rbal = RangeBasedAwo.createList(awolist, searchLoc); - awolist = new HashSet<>(); - for (RangeBasedAwo rba : rbal) { - if (awolist.size() >= maxCnt) - return awolist; - AbstractWorldObject awo = rba.awo; - - if (awo.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { - if (playerCnt < maxPlayers) { - awolist.add(awo); - playerCnt++; - } - } else if (awo.getObjectType().equals(Enum.GameObjectType.Mob)) { - if (mobCnt < maxMobs) { - awolist.add(awo); - mobCnt++; - } - } - } - return awolist; - } - - public static HashSet getTrackList(HashSet awolist, PlayerCharacter pc, int max) { - Vector3fImmutable searchLoc = pc.getLoc(); - int cnt = 0; - HashSet rbal = RangeBasedAwo.createList(awolist, searchLoc); - HashSet aclist = new HashSet<>(); - for (RangeBasedAwo rba : rbal) { - if (aclist.size() >= max) - return aclist; - AbstractWorldObject awo = rba.awo; - - if (awo.getObjectType().equals(GameObjectType.PlayerCharacter)) - if (((PlayerCharacter)awo).isCSR()) - continue; - - if (AbstractWorldObject.IsAbstractCharacter(awo) && !(pc.equals(awo))) { - aclist.add((AbstractCharacter)awo); - cnt++; - } - } - return aclist; - } - - public float getRange() { - return this.range; - } - - public AbstractWorldObject getAwo() { - return this.awo; - } + private float range; + private AbstractWorldObject awo; + + public RangeBasedAwo(Float range, AbstractWorldObject awo) { + super(); + this.range = range; + this.awo = awo; + } + + public static HashSet createList(HashSet awolist, Vector3fImmutable searchLoc) { + HashSet rbal = new HashSet<>(); + for (AbstractWorldObject awo : awolist) { + RangeBasedAwo rba = new RangeBasedAwo(searchLoc.distance(awo.getLoc()), awo); + rbal.add(rba); + } + return rbal; + } + + public static HashSet getSortedList(HashSet awolist, Vector3fImmutable searchLoc, int maxPlayers, int maxMobs) { + int playerCnt = 0; + int mobCnt = 0; + int maxCnt = (maxPlayers > maxMobs) ? maxPlayers : maxMobs; + HashSet rbal = RangeBasedAwo.createList(awolist, searchLoc); + awolist = new HashSet<>(); + for (RangeBasedAwo rba : rbal) { + if (awolist.size() >= maxCnt) + return awolist; + AbstractWorldObject awo = rba.awo; + + if (awo.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { + if (playerCnt < maxPlayers) { + awolist.add(awo); + playerCnt++; + } + } else if (awo.getObjectType().equals(Enum.GameObjectType.Mob)) { + if (mobCnt < maxMobs) { + awolist.add(awo); + mobCnt++; + } + } + } + return awolist; + } + + public static HashSet getTrackList(HashSet awolist, PlayerCharacter pc, int max) { + Vector3fImmutable searchLoc = pc.getLoc(); + int cnt = 0; + HashSet rbal = RangeBasedAwo.createList(awolist, searchLoc); + HashSet aclist = new HashSet<>(); + for (RangeBasedAwo rba : rbal) { + if (aclist.size() >= max) + return aclist; + AbstractWorldObject awo = rba.awo; + + if (awo.getObjectType().equals(GameObjectType.PlayerCharacter)) + if (((PlayerCharacter) awo).isCSR()) + continue; + + if (AbstractWorldObject.IsAbstractCharacter(awo) && !(pc.equals(awo))) { + aclist.add((AbstractCharacter) awo); + cnt++; + } + } + return aclist; + } + + @Override + public int compareTo(RangeBasedAwo obj) throws ClassCastException { + return (int) (this.range - obj.range); + } + + public float getRange() { + return this.range; + } + + public AbstractWorldObject getAwo() { + return this.awo; + } } diff --git a/src/engine/powers/effectmodifiers/AbstractEffectModifier.java b/src/engine/powers/effectmodifiers/AbstractEffectModifier.java index 464141d9..b35eda3f 100644 --- a/src/engine/powers/effectmodifiers/AbstractEffectModifier.java +++ b/src/engine/powers/effectmodifiers/AbstractEffectModifier.java @@ -24,97 +24,98 @@ import java.sql.SQLException; public abstract class AbstractEffectModifier { - protected EffectsBase parent; - protected int UUID; - protected String IDString; - protected String effectType; - public float minMod; - protected float maxMod; - protected float percentMod; - protected float ramp; - protected boolean useRampAdd; - protected String type; - public SourceType sourceType; - - protected String string1; - protected String string2; - public ModType modType; - - public AbstractEffectModifier(ResultSet rs) throws SQLException { - - this.UUID = rs.getInt("ID"); - this.IDString = rs.getString("IDString"); - this.effectType = rs.getString("modType"); - this.modType = ModType.GetModType(this.effectType); - this.type = rs.getString("type").replace("\"", ""); - this.sourceType = SourceType.GetSourceType(this.type.replace(" ", "").replace("-", "")); - this.minMod = rs.getFloat("minMod"); - this.maxMod = rs.getFloat("maxMod"); - this.percentMod = rs.getFloat("percentMod"); - this.ramp = rs.getFloat("ramp"); - this.useRampAdd = (rs.getInt("useRampAdd") == 1) ? true : false; - - this.string1 = rs.getString("string1"); - this.string2 = rs.getString("string2"); - } - - - public int getUUID() { - return this.UUID; - } - - // public String getIDString() { - // return this.IDString; - // } - - public String getmodType() { - return this.effectType; - } - - public float getMinMod() { - return this.minMod; - } - - public float getMaxMod() { - return this.maxMod; - } - - public float getPercentMod() { - return this.percentMod; - } - - public float getRamp() { - return this.ramp; - } - - public String getType() { - return this.type; - } - - public String getString1() { - return this.string1; - } - - public String getString2() { - return this.string2; - } - - public EffectsBase getParent() { - return this.parent; - } - - public void setParent(EffectsBase value) { - this.parent = value; - } - - public void applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - _applyEffectModifier(source, awo, trains, effect); - } - - protected abstract void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect); - - public abstract void applyBonus(AbstractCharacter ac, int trains); - public abstract void applyBonus(Item item, int trains); - public abstract void applyBonus(Building building, int trains); + public float minMod; + public SourceType sourceType; + public ModType modType; + protected EffectsBase parent; + protected int UUID; + protected String IDString; + protected String effectType; + protected float maxMod; + protected float percentMod; + protected float ramp; + protected boolean useRampAdd; + protected String type; + protected String string1; + protected String string2; + + public AbstractEffectModifier(ResultSet rs) throws SQLException { + + this.UUID = rs.getInt("ID"); + this.IDString = rs.getString("IDString"); + this.effectType = rs.getString("modType"); + this.modType = ModType.GetModType(this.effectType); + this.type = rs.getString("type").replace("\"", ""); + this.sourceType = SourceType.GetSourceType(this.type.replace(" ", "").replace("-", "")); + this.minMod = rs.getFloat("minMod"); + this.maxMod = rs.getFloat("maxMod"); + this.percentMod = rs.getFloat("percentMod"); + this.ramp = rs.getFloat("ramp"); + this.useRampAdd = (rs.getInt("useRampAdd") == 1) ? true : false; + + this.string1 = rs.getString("string1"); + this.string2 = rs.getString("string2"); + } + + + public int getUUID() { + return this.UUID; + } + + // public String getIDString() { + // return this.IDString; + // } + + public String getmodType() { + return this.effectType; + } + + public float getMinMod() { + return this.minMod; + } + + public float getMaxMod() { + return this.maxMod; + } + + public float getPercentMod() { + return this.percentMod; + } + + public float getRamp() { + return this.ramp; + } + + public String getType() { + return this.type; + } + + public String getString1() { + return this.string1; + } + + public String getString2() { + return this.string2; + } + + public EffectsBase getParent() { + return this.parent; + } + + public void setParent(EffectsBase value) { + this.parent = value; + } + + public void applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + _applyEffectModifier(source, awo, trains, effect); + } + + protected abstract void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect); + + public abstract void applyBonus(AbstractCharacter ac, int trains); + + public abstract void applyBonus(Item item, int trains); + + public abstract void applyBonus(Building building, int trains); } diff --git a/src/engine/powers/effectmodifiers/AdjustAboveDmgCapEffectModifier.java b/src/engine/powers/effectmodifiers/AdjustAboveDmgCapEffectModifier.java index bf64a6c0..20672b83 100644 --- a/src/engine/powers/effectmodifiers/AdjustAboveDmgCapEffectModifier.java +++ b/src/engine/powers/effectmodifiers/AdjustAboveDmgCapEffectModifier.java @@ -18,32 +18,35 @@ import java.sql.SQLException; public class AdjustAboveDmgCapEffectModifier extends AbstractEffectModifier { - public AdjustAboveDmgCapEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount / 100; - PlayerBonuses bonus = ac.getBonuses(); - bonus.setFloat(this, amount); - - - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public AdjustAboveDmgCapEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + PlayerBonuses bonus = ac.getBonuses(); + bonus.setFloat(this, amount); + + + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/AmbidexterityEffectModifier.java b/src/engine/powers/effectmodifiers/AmbidexterityEffectModifier.java index 44f72554..fab03894 100644 --- a/src/engine/powers/effectmodifiers/AmbidexterityEffectModifier.java +++ b/src/engine/powers/effectmodifiers/AmbidexterityEffectModifier.java @@ -20,23 +20,26 @@ import java.sql.SQLException; public class AmbidexterityEffectModifier extends AbstractEffectModifier { - public AmbidexterityEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public AmbidexterityEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - PlayerBonuses bonus = ac.getBonuses(); - bonus.setBool(ModType.Ambidexterity, SourceType.None, true); - } + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + PlayerBonuses bonus = ac.getBonuses(); + bonus.setBool(ModType.Ambidexterity, SourceType.None, true); + } - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/ArmorPiercingEffectModifier.java b/src/engine/powers/effectmodifiers/ArmorPiercingEffectModifier.java index 39ec058e..aab12746 100644 --- a/src/engine/powers/effectmodifiers/ArmorPiercingEffectModifier.java +++ b/src/engine/powers/effectmodifiers/ArmorPiercingEffectModifier.java @@ -18,25 +18,28 @@ import java.sql.SQLException; public class ArmorPiercingEffectModifier extends AbstractEffectModifier { - public ArmorPiercingEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - amount = this.percentMod; - bonus.addFloat(this, amount * 0.01f); - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public ArmorPiercingEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + amount = this.percentMod; + bonus.addFloat(this, amount * 0.01f); + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/AttackDelayEffectModifier.java b/src/engine/powers/effectmodifiers/AttackDelayEffectModifier.java index 2ce2f6a3..59af7200 100644 --- a/src/engine/powers/effectmodifiers/AttackDelayEffectModifier.java +++ b/src/engine/powers/effectmodifiers/AttackDelayEffectModifier.java @@ -18,29 +18,32 @@ import java.sql.SQLException; public class AttackDelayEffectModifier extends AbstractEffectModifier { - public AttackDelayEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - PlayerBonuses bonus = ac.getBonuses(); - bonus.addFloat(this, amount); - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public AttackDelayEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + PlayerBonuses bonus = ac.getBonuses(); + bonus.addFloat(this, amount); + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/AttributeEffectModifier.java b/src/engine/powers/effectmodifiers/AttributeEffectModifier.java index 4aceb60c..831d8a62 100644 --- a/src/engine/powers/effectmodifiers/AttributeEffectModifier.java +++ b/src/engine/powers/effectmodifiers/AttributeEffectModifier.java @@ -18,39 +18,42 @@ import java.sql.SQLException; public class AttributeEffectModifier extends AbstractEffectModifier { - public AttributeEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - - ac.update(); - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.percentMod != 0f) { //Stat Percent Modifiers - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - bonus.addFloat(this, amount); - } else { //Stat Modifiers - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - bonus.addFloat(this, amount); - } - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public AttributeEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + + ac.update(); + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.percentMod != 0f) { //Stat Percent Modifiers + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + bonus.addFloat(this, amount); + } else { //Stat Modifiers + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + bonus.addFloat(this, amount); + } + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/BlackMantleEffectModifier.java b/src/engine/powers/effectmodifiers/BlackMantleEffectModifier.java index 1a6d7402..5619e98f 100644 --- a/src/engine/powers/effectmodifiers/BlackMantleEffectModifier.java +++ b/src/engine/powers/effectmodifiers/BlackMantleEffectModifier.java @@ -21,33 +21,36 @@ import java.sql.SQLException; public class BlackMantleEffectModifier extends AbstractEffectModifier { - public BlackMantleEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - PlayerBonuses bonus = ac.getBonuses(); - SourceType sourceType = SourceType.valueOf(this.type); - - if (sourceType == null){ - Logger.error("Bad Source Type for " + this.type); - return; - } - - if (this.type.equals("Heal")) - bonus.setFloat(this, trains); - else - bonus.setBool(ModType.ImmuneTo, this.sourceType, true); - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public BlackMantleEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + PlayerBonuses bonus = ac.getBonuses(); + SourceType sourceType = SourceType.valueOf(this.type); + + if (sourceType == null) { + Logger.error("Bad Source Type for " + this.type); + return; + } + + if (this.type.equals("Heal")) + bonus.setFloat(this, trains); + else + bonus.setBool(ModType.ImmuneTo, this.sourceType, true); + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/BladeTrailsEffectModifier.java b/src/engine/powers/effectmodifiers/BladeTrailsEffectModifier.java index 891e3781..5fd08bbc 100644 --- a/src/engine/powers/effectmodifiers/BladeTrailsEffectModifier.java +++ b/src/engine/powers/effectmodifiers/BladeTrailsEffectModifier.java @@ -20,22 +20,25 @@ import java.sql.SQLException; public class BladeTrailsEffectModifier extends AbstractEffectModifier { - public BladeTrailsEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public BladeTrailsEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { + @Override + public void applyBonus(AbstractCharacter ac, int trains) { - } + } - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/BlockEffectModifier.java b/src/engine/powers/effectmodifiers/BlockEffectModifier.java index b388dac1..feb9386c 100644 --- a/src/engine/powers/effectmodifiers/BlockEffectModifier.java +++ b/src/engine/powers/effectmodifiers/BlockEffectModifier.java @@ -18,29 +18,32 @@ import java.sql.SQLException; public class BlockEffectModifier extends AbstractEffectModifier { - public BlockEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - PlayerBonuses bonus = ac.getBonuses(); - bonus.setFloat(this, amount); - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public BlockEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + PlayerBonuses bonus = ac.getBonuses(); + bonus.setFloat(this, amount); + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/BlockedPowerTypeEffectModifier.java b/src/engine/powers/effectmodifiers/BlockedPowerTypeEffectModifier.java index 3e447d31..f55e903d 100644 --- a/src/engine/powers/effectmodifiers/BlockedPowerTypeEffectModifier.java +++ b/src/engine/powers/effectmodifiers/BlockedPowerTypeEffectModifier.java @@ -20,43 +20,46 @@ import java.util.HashSet; public class BlockedPowerTypeEffectModifier extends AbstractEffectModifier { - public BlockedPowerTypeEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - PlayerBonuses bonus = ac.getBonuses(); - bonus.setBool(this.modType,this.sourceType, true); - - - for (String effect : ac.getEffects().keySet()){ - Effect eff = ac.getEffects().get(effect); - ModType toBlock = ModType.None; - - switch (this.sourceType){ - case Invisible: - toBlock = ModType.Invisible; - break; - } - - HashSet aemList = eff.getEffectModifiers(); - for (AbstractEffectModifier aem : aemList ){ - if (aem.modType.equals(toBlock)){ - ac.endEffect(effect); - } - } - - } - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public BlockedPowerTypeEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + PlayerBonuses bonus = ac.getBonuses(); + bonus.setBool(this.modType, this.sourceType, true); + + + for (String effect : ac.getEffects().keySet()) { + Effect eff = ac.getEffects().get(effect); + ModType toBlock = ModType.None; + + switch (this.sourceType) { + case Invisible: + toBlock = ModType.Invisible; + break; + } + + HashSet aemList = eff.getEffectModifiers(); + for (AbstractEffectModifier aem : aemList) { + if (aem.modType.equals(toBlock)) { + ac.endEffect(effect); + } + } + + } + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/CannotAttackEffectModifier.java b/src/engine/powers/effectmodifiers/CannotAttackEffectModifier.java index 86435c20..67f72aaf 100644 --- a/src/engine/powers/effectmodifiers/CannotAttackEffectModifier.java +++ b/src/engine/powers/effectmodifiers/CannotAttackEffectModifier.java @@ -18,24 +18,27 @@ import java.sql.SQLException; public class CannotAttackEffectModifier extends AbstractEffectModifier { - public CannotAttackEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - PlayerBonuses bonus = ac.getBonuses(); - - bonus.setBool(this.modType,this.sourceType, true); - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public CannotAttackEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + PlayerBonuses bonus = ac.getBonuses(); + + bonus.setBool(this.modType, this.sourceType, true); + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/CannotCastEffectModifier.java b/src/engine/powers/effectmodifiers/CannotCastEffectModifier.java index 3dca97b7..1048b9e1 100644 --- a/src/engine/powers/effectmodifiers/CannotCastEffectModifier.java +++ b/src/engine/powers/effectmodifiers/CannotCastEffectModifier.java @@ -19,28 +19,31 @@ import java.sql.SQLException; public class CannotCastEffectModifier extends AbstractEffectModifier { - public CannotCastEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public CannotCastEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { + @Override + public void applyBonus(AbstractCharacter ac, int trains) { - if (ac.getObjectType().equals(Enum.GameObjectType.Mob)) { - Mob mob = (Mob) ac; - } + if (ac.getObjectType().equals(Enum.GameObjectType.Mob)) { + Mob mob = (Mob) ac; + } - PlayerBonuses bonus = ac.getBonuses(); - bonus.setBool(this.modType,this.sourceType, true); - } + PlayerBonuses bonus = ac.getBonuses(); + bonus.setBool(this.modType, this.sourceType, true); + } - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/CannotMoveEffectModifier.java b/src/engine/powers/effectmodifiers/CannotMoveEffectModifier.java index 51fe46cb..5cf0b8e7 100644 --- a/src/engine/powers/effectmodifiers/CannotMoveEffectModifier.java +++ b/src/engine/powers/effectmodifiers/CannotMoveEffectModifier.java @@ -18,24 +18,27 @@ import java.sql.SQLException; public class CannotMoveEffectModifier extends AbstractEffectModifier { - public CannotMoveEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - PlayerBonuses bonus = ac.getBonuses(); - bonus.setBool(this.modType,this.sourceType,true); - ac.stopMovement(ac.getMovementLoc()); - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public CannotMoveEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + PlayerBonuses bonus = ac.getBonuses(); + bonus.setBool(this.modType, this.sourceType, true); + ac.stopMovement(ac.getMovementLoc()); + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/CannotTrackEffectModifier.java b/src/engine/powers/effectmodifiers/CannotTrackEffectModifier.java index a4e6a4c0..e5c235a9 100644 --- a/src/engine/powers/effectmodifiers/CannotTrackEffectModifier.java +++ b/src/engine/powers/effectmodifiers/CannotTrackEffectModifier.java @@ -18,23 +18,26 @@ import java.sql.SQLException; public class CannotTrackEffectModifier extends AbstractEffectModifier { - public CannotTrackEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public CannotTrackEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - PlayerBonuses bonus = ac.getBonuses(); - bonus.setBool(this.modType,this.sourceType,true); - } + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + PlayerBonuses bonus = ac.getBonuses(); + bonus.setBool(this.modType, this.sourceType, true); + } - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/CharmedEffectModifier.java b/src/engine/powers/effectmodifiers/CharmedEffectModifier.java index 324dde83..0d464e94 100644 --- a/src/engine/powers/effectmodifiers/CharmedEffectModifier.java +++ b/src/engine/powers/effectmodifiers/CharmedEffectModifier.java @@ -20,22 +20,25 @@ import java.sql.SQLException; public class CharmedEffectModifier extends AbstractEffectModifier { - public CharmedEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public CharmedEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { + @Override + public void applyBonus(AbstractCharacter ac, int trains) { - } + } - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/ConstrainedAmbidexterityEffectModifier.java b/src/engine/powers/effectmodifiers/ConstrainedAmbidexterityEffectModifier.java index 22c7e497..47e8047b 100644 --- a/src/engine/powers/effectmodifiers/ConstrainedAmbidexterityEffectModifier.java +++ b/src/engine/powers/effectmodifiers/ConstrainedAmbidexterityEffectModifier.java @@ -18,23 +18,26 @@ import java.sql.SQLException; public class ConstrainedAmbidexterityEffectModifier extends AbstractEffectModifier { - public ConstrainedAmbidexterityEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public ConstrainedAmbidexterityEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - PlayerBonuses bonus = ac.getBonuses(); - bonus.setString(this,this.type); - } + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + PlayerBonuses bonus = ac.getBonuses(); + bonus.setString(this, this.type); + } - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/DCVEffectModifier.java b/src/engine/powers/effectmodifiers/DCVEffectModifier.java index 29dcd20e..16f0283c 100644 --- a/src/engine/powers/effectmodifiers/DCVEffectModifier.java +++ b/src/engine/powers/effectmodifiers/DCVEffectModifier.java @@ -18,37 +18,40 @@ import java.sql.SQLException; public class DCVEffectModifier extends AbstractEffectModifier { - public DCVEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.percentMod != 0f) { //Stat Percent Modifiers - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = (amount) / 100; - bonus.addFloat(this, amount); - } else { //Stat Modifiers - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - bonus.addFloat(this,amount); - } - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public DCVEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.percentMod != 0f) { //Stat Percent Modifiers + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = (amount) / 100; + bonus.addFloat(this, amount); + } else { //Stat Modifiers + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + bonus.addFloat(this, amount); + } + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/DREffectModifier.java b/src/engine/powers/effectmodifiers/DREffectModifier.java index 54b606a5..5ff9096f 100644 --- a/src/engine/powers/effectmodifiers/DREffectModifier.java +++ b/src/engine/powers/effectmodifiers/DREffectModifier.java @@ -20,42 +20,44 @@ import java.sql.SQLException; public class DREffectModifier extends AbstractEffectModifier { - public DREffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - //Defense Rating (defense bonus for armor) - } - - @Override - public void applyBonus(Item item, int trains) { - if (item == null) - return; - String key; float amount = 0f; - if (this.percentMod != 0f) { - if (this.useRampAdd) - amount = (this.percentMod + (this.ramp * trains)) / 100f; - else - amount = (this.percentMod * (1 + (this.ramp * trains))) / 100f; - amount = amount/100; - key = "DR.percent"; - } else { - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - key = "DR"; - } - item.addBonus(this, amount); - } - - @Override - public void applyBonus(Building building, int trains) {} + public DREffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + //Defense Rating (defense bonus for armor) + } + + @Override + public void applyBonus(Item item, int trains) { + if (item == null) + return; + String key; + float amount = 0f; + if (this.percentMod != 0f) { + if (this.useRampAdd) + amount = (this.percentMod + (this.ramp * trains)) / 100f; + else + amount = (this.percentMod * (1 + (this.ramp * trains))) / 100f; + amount = amount / 100; + key = "DR.percent"; + } else { + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + key = "DR"; + } + item.addBonus(this, amount); + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/DamageCapEffectModifier.java b/src/engine/powers/effectmodifiers/DamageCapEffectModifier.java index 905805f2..403dc7dc 100644 --- a/src/engine/powers/effectmodifiers/DamageCapEffectModifier.java +++ b/src/engine/powers/effectmodifiers/DamageCapEffectModifier.java @@ -18,29 +18,32 @@ import java.sql.SQLException; public class DamageCapEffectModifier extends AbstractEffectModifier { - public DamageCapEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - PlayerBonuses bonus = ac.getBonuses(); - bonus.setFloat(this, amount); - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public DamageCapEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + PlayerBonuses bonus = ac.getBonuses(); + bonus.setFloat(this, amount); + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/DamageShieldEffectModifier.java b/src/engine/powers/effectmodifiers/DamageShieldEffectModifier.java index 1a4bf094..d6b0e66b 100644 --- a/src/engine/powers/effectmodifiers/DamageShieldEffectModifier.java +++ b/src/engine/powers/effectmodifiers/DamageShieldEffectModifier.java @@ -20,45 +20,49 @@ import java.sql.SQLException; public class DamageShieldEffectModifier extends AbstractEffectModifier { - public DamageShieldEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public DamageShieldEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - float amount; boolean usePercent; - if (this.percentMod != 0) { - amount = this.percentMod; - usePercent = true; - } else { - amount = this.minMod; - usePercent = false; - } + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + float amount; + boolean usePercent; + if (this.percentMod != 0) { + amount = this.percentMod; + usePercent = true; + } else { + amount = this.minMod; + usePercent = false; + } - if (this.ramp > 0f) { - float mod = this.ramp * trains; - if (this.useRampAdd) - amount += mod; - else - amount *= (1 + mod); - } + if (this.ramp > 0f) { + float mod = this.ramp * trains; + if (this.useRampAdd) + amount += mod; + else + amount *= (1 + mod); + } - DamageType dt = DamageType.valueOf(this.type); - if (dt != null) { - DamageShield ds = new DamageShield(dt, amount, usePercent); - PlayerBonuses bonus = ac.getBonuses(); - if (bonus != null) - bonus.addDamageShield(this, ds); - } - } + DamageType dt = DamageType.valueOf(this.type); + if (dt != null) { + DamageShield ds = new DamageShield(dt, amount, usePercent); + PlayerBonuses bonus = ac.getBonuses(); + if (bonus != null) + bonus.addDamageShield(this, ds); + } + } - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/DodgeEffectModifier.java b/src/engine/powers/effectmodifiers/DodgeEffectModifier.java index 5580f7f0..027a3335 100644 --- a/src/engine/powers/effectmodifiers/DodgeEffectModifier.java +++ b/src/engine/powers/effectmodifiers/DodgeEffectModifier.java @@ -18,37 +18,40 @@ import java.sql.SQLException; public class DodgeEffectModifier extends AbstractEffectModifier { - public DodgeEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.percentMod != 0f) { //Stat Percent Modifiers - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - bonus.addFloat(this, amount); - } else { //Stat Modifiers - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - bonus.addFloat(this, amount); - } - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public DodgeEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.percentMod != 0f) { //Stat Percent Modifiers + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + bonus.addFloat(this, amount); + } else { //Stat Modifiers + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + bonus.addFloat(this, amount); + } + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/DurabilityEffectModifier.java b/src/engine/powers/effectmodifiers/DurabilityEffectModifier.java index 3baf4e6f..d69f9f6a 100644 --- a/src/engine/powers/effectmodifiers/DurabilityEffectModifier.java +++ b/src/engine/powers/effectmodifiers/DurabilityEffectModifier.java @@ -20,32 +20,33 @@ import java.sql.SQLException; public class DurabilityEffectModifier extends AbstractEffectModifier { - public DurabilityEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public DurabilityEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { + @Override + public void applyBonus(AbstractCharacter ac, int trains) { - } + } - @Override - public void applyBonus(Item item, int trains) - { - if(item == null){ - return; - } - float amount = 0; - amount = this.percentMod; - item.addBonus(this,amount); + @Override + public void applyBonus(Item item, int trains) { + if (item == null) { + return; + } + float amount = 0; + amount = this.percentMod; + item.addBonus(this, amount); - } - @Override - public void applyBonus(Building building, int trains) {} + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/ExclusiveDamageCapEffectModifier.java b/src/engine/powers/effectmodifiers/ExclusiveDamageCapEffectModifier.java index 0a652cef..1e53ae89 100644 --- a/src/engine/powers/effectmodifiers/ExclusiveDamageCapEffectModifier.java +++ b/src/engine/powers/effectmodifiers/ExclusiveDamageCapEffectModifier.java @@ -18,28 +18,31 @@ import java.util.HashSet; public class ExclusiveDamageCapEffectModifier extends AbstractEffectModifier { - public ExclusiveDamageCapEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - PlayerBonuses bonus = ac.getBonuses(); - if (bonus == null) - return; - if (bonus.getList(this.modType) == null) - bonus.setList(this.modType, new HashSet<>()); - bonus.getList(this.modType).add(this.sourceType); - - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public ExclusiveDamageCapEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + PlayerBonuses bonus = ac.getBonuses(); + if (bonus == null) + return; + if (bonus.getList(this.modType) == null) + bonus.setList(this.modType, new HashSet<>()); + bonus.getList(this.modType).add(this.sourceType); + + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/FadeEffectModifier.java b/src/engine/powers/effectmodifiers/FadeEffectModifier.java index 2e12d645..ede4cad9 100644 --- a/src/engine/powers/effectmodifiers/FadeEffectModifier.java +++ b/src/engine/powers/effectmodifiers/FadeEffectModifier.java @@ -20,22 +20,25 @@ import java.sql.SQLException; public class FadeEffectModifier extends AbstractEffectModifier { - public FadeEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public FadeEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { + @Override + public void applyBonus(AbstractCharacter ac, int trains) { - } + } - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/FlyEffectModifier.java b/src/engine/powers/effectmodifiers/FlyEffectModifier.java index 3e16ca7c..a3dc0a49 100644 --- a/src/engine/powers/effectmodifiers/FlyEffectModifier.java +++ b/src/engine/powers/effectmodifiers/FlyEffectModifier.java @@ -17,23 +17,26 @@ import java.sql.SQLException; public class FlyEffectModifier extends AbstractEffectModifier { - public FlyEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public FlyEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - PlayerBonuses bonus = ac.getBonuses(); - bonus.setBool(this.modType,this.sourceType,true); - } + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + PlayerBonuses bonus = ac.getBonuses(); + bonus.setBool(this.modType, this.sourceType, true); + } - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/HealthEffectModifier.java b/src/engine/powers/effectmodifiers/HealthEffectModifier.java index 97ef9462..3ddaf96b 100644 --- a/src/engine/powers/effectmodifiers/HealthEffectModifier.java +++ b/src/engine/powers/effectmodifiers/HealthEffectModifier.java @@ -29,162 +29,172 @@ import java.util.concurrent.ThreadLocalRandom; public class HealthEffectModifier extends AbstractEffectModifier { - private DamageType damageType; - - public HealthEffectModifier(ResultSet rs) throws SQLException { - super(rs); - String damageTypeDB = rs.getString("type"); - try { - this.damageType = DamageType.valueOf(damageTypeDB); - } catch (IllegalArgumentException e) { - Logger.error("DamageType could not be loaded from database. " + "UUID = " + this.UUID - + " value received = '" + damageTypeDB + '\'', e); - } - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - if (awo == null) { - Logger.error("_applyEffectModifier(): NULL AWO passed in."); - return; - } - - if (effect == null) { - Logger.error( "_applyEffectModifier(): NULL AbstractEffectJob passed in."); - return; - } - - float modAmount = 0f; - - // Modify health by percent - if (this.percentMod != 0f) { - - //high level mobs/players should not be %damaged/healed. - if (awo.getHealthMax() > 25000f && (this.percentMod < 0f || this.percentMod > 5f)) - return; - - float mod = 1f; - if (this.useRampAdd) - mod = (this.percentMod + (this.ramp * trains)) / 100; - else - mod = (this.percentMod * (1 + (this.ramp * trains))) / 100; - modAmount = mod * awo.getHealthMax(); - if (AbstractWorldObject.IsAbstractCharacter(awo)) { - if (((AbstractCharacter)awo).isSit()) - modAmount *= 2.5f; - } - - //debug for spell damage and atr - if (source.getDebug(16) && source.getObjectType().equals(GameObjectType.PlayerCharacter)) { - PlayerCharacter pc = (PlayerCharacter) source; - String smsg = "Percent Damage: " + mod * 100 + '%'; - ChatManager.chatSystemInfo(pc, smsg); - } - } - - // Modify health by min/max amount - else if (this.minMod != 0f || this.maxMod != 0f) { - float min = this.minMod; - float max = this.maxMod; - if (this.ramp > 0f) { - float mod = this.ramp * trains; - if (this.useRampAdd) { - min += mod; - max += mod; - } else { - min *= (1 + mod); - max *= (1 + mod); - } - } - if (source.getObjectType().equals(GameObjectType.PlayerCharacter)) { - PlayerCharacter pc = (PlayerCharacter) source; - - float focus; - CharacterSkill skill = pc.getSkills().get(effect.getPower().getSkillName()); - if (skill == null) - focus = CharacterSkill.getQuickMastery(pc, effect.getPower().getSkillName()); - else - focus = skill.getModifiedAmount(); - //TODO clean up old formulas once new one is verified - // min *= (0.5 + 0.0075 * pc.getStatIntCurrent() + 0.011 * pc.getStatSpiCurrent() + 0.0196 * focus); - // max *= (0.62 + 0.0192 * pc.getStatIntCurrent() + 0.00415 * pc.getStatSpiCurrent() + 0.015 * focus); - float intt = (pc.getStatIntCurrent() >= 1) ? (float)pc.getStatIntCurrent() : 1f; - float spi = (pc.getStatSpiCurrent() >= 1) ? (float)pc.getStatSpiCurrent() : 1f; - // min *= (intt * 0.0045 + 0.055 * (float)Math.sqrt(intt - 0.5) + spi * 0.006 + 0.07 * (float)Math.sqrt(spi - 0.5) + 0.02 * (int)focus); - // max *= (intt * 0.0117 + 0.13 * (float)Math.sqrt(intt - 0.5) + spi * 0.0024 + (float)Math.sqrt(spi - 0.5) * 0.021 + 0.015 * (int)focus); - min = HealthEffectModifier.getMinDamage(min, intt, spi, focus); - max = HealthEffectModifier.getMaxDamage(max, intt, spi, focus); - - //debug for spell damage and atr - if (pc.getDebug(16)) { - String smsg = "Damage: " + (int)Math.abs(min) + " - " + (int)Math.abs(max); - ChatManager.chatSystemInfo(pc, smsg); - } - }else if (source.getObjectType() == GameObjectType.Mob){ - Mob pc = (Mob) source; - - float focus; - CharacterSkill skill = pc.getSkills().get(effect.getPower().getSkillName()); - if (skill == null) - focus = CharacterSkill.getQuickMastery(pc, effect.getPower().getSkillName()); - else - focus = skill.getModifiedAmount(); - //TODO clean up old formulas once new one is verified - // min *= (0.5 + 0.0075 * pc.getStatIntCurrent() + 0.011 * pc.getStatSpiCurrent() + 0.0196 * focus); - // max *= (0.62 + 0.0192 * pc.getStatIntCurrent() + 0.00415 * pc.getStatSpiCurrent() + 0.015 * focus); - float intt = (pc.getStatIntCurrent() >= 1) ? (float)pc.getStatIntCurrent() : 1f; - - if (pc.isPlayerGuard()) - intt = 200; - float spi = (pc.getStatSpiCurrent() >= 1) ? (float)pc.getStatSpiCurrent() : 1f; - - if (pc.isPlayerGuard()) - spi = 200; - // min *= (intt * 0.0045 + 0.055 * (float)Math.sqrt(intt - 0.5) + spi * 0.006 + 0.07 * (float)Math.sqrt(spi - 0.5) + 0.02 * (int)focus); - // max *= (intt * 0.0117 + 0.13 * (float)Math.sqrt(intt - 0.5) + spi * 0.0024 + (float)Math.sqrt(spi - 0.5) * 0.021 + 0.015 * (int)focus); - min = HealthEffectModifier.getMinDamage(min, intt, spi, focus); - max = HealthEffectModifier.getMaxDamage(max, intt, spi, focus); - - //debug for spell damage and atr - // if (pc.getDebug(16)) { - // String smsg = "Damage: " + (int)Math.abs(min) + " - " + (int)Math.abs(max); - // ChatManager.chatSystemInfo(pc, smsg); - // } - } - modAmount = calculateDamage(source, min, max, awo, trains); - PlayerBonuses bonus = source.getBonuses(); - - // Apply any power effect modifiers (such as stances) - if (bonus != null) - modAmount *= (1 + (bonus.getFloatPercentAll(ModType.PowerDamageModifier, SourceType.None))); - } - if (modAmount == 0f) - return; - if (AbstractWorldObject.IsAbstractCharacter(awo)) { - AbstractCharacter ac = (AbstractCharacter) awo; - - if (!ac.isAlive()) - return; - - int powerID = 0, effectID = 0; - String powerName = ""; - if (effect.getPower() != null) { - powerID = effect.getPower().getToken(); - powerName = effect.getPower().getName(); - } else { - Logger.error("Power has returned null! Damage will fail to register! (" + (ac.getCurrentHitpoints()>0?"Alive)":"Dead)")); - } - - if (effect.getEffect() != null) { - effectID = effect.getEffect().getToken(); - } else { - Logger.error("Effect has returned null! Damage will fail to register! (" + (ac.getCurrentHitpoints()>0?"Alive)":"Dead)")); - } - - //see if target is immune to heals - if (modAmount > 0f) { - boolean skipImmune = false; - // first tick of HoT going thru SM was removed in a later patch + private DamageType damageType; + + public HealthEffectModifier(ResultSet rs) throws SQLException { + super(rs); + String damageTypeDB = rs.getString("type"); + try { + this.damageType = DamageType.valueOf(damageTypeDB); + } catch (IllegalArgumentException e) { + Logger.error("DamageType could not be loaded from database. " + "UUID = " + this.UUID + + " value received = '" + damageTypeDB + '\'', e); + } + } + + public static float getMinDamage(float baseMin, float intelligence, float spirit, float focus) { + float min = baseMin * (((float) Math.pow(intelligence, 0.75f) * 0.0311f) + (0.02f * (int) focus) + ((float) Math.pow(spirit, 0.75f) * 0.0416f)); + return (float) ((int) (min + 0.5f)); //round to nearest whole number + } + + public static float getMaxDamage(float baseMax, float intelligence, float spirit, float focus) { + float max = baseMax * (((float) Math.pow(intelligence, 0.75f) * 0.0785f) + (0.015f * (int) focus) + ((float) Math.pow(spirit, 0.75f) * 0.0157f)); + return (float) ((int) (max + 0.5f)); //round to nearest whole number + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + if (awo == null) { + Logger.error("_applyEffectModifier(): NULL AWO passed in."); + return; + } + + if (effect == null) { + Logger.error("_applyEffectModifier(): NULL AbstractEffectJob passed in."); + return; + } + + float modAmount = 0f; + + // Modify health by percent + if (this.percentMod != 0f) { + + //high level mobs/players should not be %damaged/healed. + if (awo.getHealthMax() > 25000f && (this.percentMod < 0f || this.percentMod > 5f)) + return; + + float mod = 1f; + if (this.useRampAdd) + mod = (this.percentMod + (this.ramp * trains)) / 100; + else + mod = (this.percentMod * (1 + (this.ramp * trains))) / 100; + modAmount = mod * awo.getHealthMax(); + if (AbstractWorldObject.IsAbstractCharacter(awo)) { + if (((AbstractCharacter) awo).isSit()) + modAmount *= 2.5f; + } + + //debug for spell damage and atr + if (source.getDebug(16) && source.getObjectType().equals(GameObjectType.PlayerCharacter)) { + PlayerCharacter pc = (PlayerCharacter) source; + String smsg = "Percent Damage: " + mod * 100 + '%'; + ChatManager.chatSystemInfo(pc, smsg); + } + } + + // Modify health by min/max amount + else if (this.minMod != 0f || this.maxMod != 0f) { + float min = this.minMod; + float max = this.maxMod; + if (this.ramp > 0f) { + float mod = this.ramp * trains; + if (this.useRampAdd) { + min += mod; + max += mod; + } else { + min *= (1 + mod); + max *= (1 + mod); + } + } + if (source.getObjectType().equals(GameObjectType.PlayerCharacter)) { + PlayerCharacter pc = (PlayerCharacter) source; + + float focus; + CharacterSkill skill = pc.getSkills().get(effect.getPower().getSkillName()); + if (skill == null) + focus = CharacterSkill.getQuickMastery(pc, effect.getPower().getSkillName()); + else + focus = skill.getModifiedAmount(); + //TODO clean up old formulas once new one is verified + // min *= (0.5 + 0.0075 * pc.getStatIntCurrent() + 0.011 * pc.getStatSpiCurrent() + 0.0196 * focus); + // max *= (0.62 + 0.0192 * pc.getStatIntCurrent() + 0.00415 * pc.getStatSpiCurrent() + 0.015 * focus); + float intt = (pc.getStatIntCurrent() >= 1) ? (float) pc.getStatIntCurrent() : 1f; + float spi = (pc.getStatSpiCurrent() >= 1) ? (float) pc.getStatSpiCurrent() : 1f; + // min *= (intt * 0.0045 + 0.055 * (float)Math.sqrt(intt - 0.5) + spi * 0.006 + 0.07 * (float)Math.sqrt(spi - 0.5) + 0.02 * (int)focus); + // max *= (intt * 0.0117 + 0.13 * (float)Math.sqrt(intt - 0.5) + spi * 0.0024 + (float)Math.sqrt(spi - 0.5) * 0.021 + 0.015 * (int)focus); + min = HealthEffectModifier.getMinDamage(min, intt, spi, focus); + max = HealthEffectModifier.getMaxDamage(max, intt, spi, focus); + + //debug for spell damage and atr + if (pc.getDebug(16)) { + String smsg = "Damage: " + (int) Math.abs(min) + " - " + (int) Math.abs(max); + ChatManager.chatSystemInfo(pc, smsg); + } + } else if (source.getObjectType() == GameObjectType.Mob) { + Mob pc = (Mob) source; + + float focus; + CharacterSkill skill = pc.getSkills().get(effect.getPower().getSkillName()); + if (skill == null) + focus = CharacterSkill.getQuickMastery(pc, effect.getPower().getSkillName()); + else + focus = skill.getModifiedAmount(); + //TODO clean up old formulas once new one is verified + // min *= (0.5 + 0.0075 * pc.getStatIntCurrent() + 0.011 * pc.getStatSpiCurrent() + 0.0196 * focus); + // max *= (0.62 + 0.0192 * pc.getStatIntCurrent() + 0.00415 * pc.getStatSpiCurrent() + 0.015 * focus); + float intt = (pc.getStatIntCurrent() >= 1) ? (float) pc.getStatIntCurrent() : 1f; + + if (pc.isPlayerGuard()) + intt = 200; + float spi = (pc.getStatSpiCurrent() >= 1) ? (float) pc.getStatSpiCurrent() : 1f; + + if (pc.isPlayerGuard()) + spi = 200; + // min *= (intt * 0.0045 + 0.055 * (float)Math.sqrt(intt - 0.5) + spi * 0.006 + 0.07 * (float)Math.sqrt(spi - 0.5) + 0.02 * (int)focus); + // max *= (intt * 0.0117 + 0.13 * (float)Math.sqrt(intt - 0.5) + spi * 0.0024 + (float)Math.sqrt(spi - 0.5) * 0.021 + 0.015 * (int)focus); + min = HealthEffectModifier.getMinDamage(min, intt, spi, focus); + max = HealthEffectModifier.getMaxDamage(max, intt, spi, focus); + + //debug for spell damage and atr + // if (pc.getDebug(16)) { + // String smsg = "Damage: " + (int)Math.abs(min) + " - " + (int)Math.abs(max); + // ChatManager.chatSystemInfo(pc, smsg); + // } + } + modAmount = calculateDamage(source, min, max, awo, trains); + PlayerBonuses bonus = source.getBonuses(); + + // Apply any power effect modifiers (such as stances) + if (bonus != null) + modAmount *= (1 + (bonus.getFloatPercentAll(ModType.PowerDamageModifier, SourceType.None))); + } + if (modAmount == 0f) + return; + if (AbstractWorldObject.IsAbstractCharacter(awo)) { + AbstractCharacter ac = (AbstractCharacter) awo; + + if (!ac.isAlive()) + return; + + int powerID = 0, effectID = 0; + String powerName = ""; + if (effect.getPower() != null) { + powerID = effect.getPower().getToken(); + powerName = effect.getPower().getName(); + } else { + Logger.error("Power has returned null! Damage will fail to register! (" + (ac.getCurrentHitpoints() > 0 ? "Alive)" : "Dead)")); + } + + if (effect.getEffect() != null) { + effectID = effect.getEffect().getToken(); + } else { + Logger.error("Effect has returned null! Damage will fail to register! (" + (ac.getCurrentHitpoints() > 0 ? "Alive)" : "Dead)")); + } + + //see if target is immune to heals + if (modAmount > 0f) { + boolean skipImmune = false; + // first tick of HoT going thru SM was removed in a later patch /*if (effect.getAction().getPowerAction() instanceof DirectDamagePowerAction) { ArrayList actions = effect.getPower().getActions(); for (ActionsBase ab : actions) { @@ -194,138 +204,131 @@ public class HealthEffectModifier extends AbstractEffectModifier { } }*/ - PlayerBonuses bonus = ac.getBonuses(); - if (!skipImmune && bonus.getFloat(ModType.BlackMantle, SourceType.Heal) >= trains) { - ModifyHealthMsg mhm = new ModifyHealthMsg(source, ac, 0f, 0f, 0f, powerID, powerName, trains, effectID); - mhm.setUnknown03(5); //set target is immune - DispatchMessage.sendToAllInRange(ac, mhm); - return; - } - } - float mod = 0; - - //Modify health - - mod = ac.modifyHealth(modAmount, source, false); - - float cur = awo.getCurrentHitpoints(); - float maxAmount = awo.getHealthMax() - cur; - - AbstractNetMsg mhm = null; - if (modAmount < 0 && cur < 0 && mod != 0) - mhm = new ModifyHealthKillMsg(source, ac, modAmount, 0f, 0f, powerID, powerName, trains, effectID); - else - mhm = new ModifyHealthMsg(source, ac, modAmount, 0f, 0f, powerID, powerName, trains, effectID); - - if (effect instanceof DamageOverTimeJob) { - if (mhm instanceof ModifyHealthMsg) - ((ModifyHealthMsg)mhm).setOmitFromChat(1); - else if (mhm instanceof ModifyHealthKillMsg) - ((ModifyHealthKillMsg)mhm).setUnknown02(1); - } - - //send the damage - - DispatchMessage.sendToAllInRange(ac, mhm); - - // //send corpse if this kills a mob - // //TODO fix the someone misses blurb. - // if(awo instanceof Mob && awo.getHealth() <= 0) { - // CombatMessageMsg cmm = new CombatMessageMsg(null, 0, awo, 15); - // try { - // DispatchMessage.sendToAllInRange(ac, cmm); - // } catch (MsgSendException e) { - // Logger.error("MobCorpseSendError", e); - // } - // } - } else if (awo.getObjectType().equals(GameObjectType.Building)) { - - Building b = (Building) awo; - - if (modAmount < 0 && (!b.isVulnerable())) - return; //can't damage invul building - - int powerID = 0, effectID = 0; - String powerName = ""; - if (effect.getPower() != null) { - powerID = effect.getPower().getToken(); - powerName = effect.getPower().getName(); - } else - Logger.error("Power has returned null! Damage will fail to register! (" + (b.getRank() == -1 ? "Standing)" : "Destroyed)")); - - if (effect.getEffect() != null) { - effectID = effect.getEffect().getToken(); - } else - Logger.error("Effect has returned null! Damage will fail to register! (" + (b.getRank() == -1 ? "Standing)" : "Destroyed)")); - - float mod = b.modifyHealth(modAmount, source); - ModifyHealthMsg mhm = new ModifyHealthMsg(source, b, modAmount, 0f, 0f, powerID, powerName, trains, effectID); - - if (effect instanceof DamageOverTimeJob) - mhm.setOmitFromChat(1); - - //send the damage - - DispatchMessage.sendToAllInRange(b, mhm); - - } - } - - private float calculateDamage(AbstractCharacter source, float minDamage, float maxDamage, AbstractWorldObject awo, int trains) { - - // get range between min and max - float range = maxDamage - minDamage; - - // Damage is calculated twice to average a more central point - float damage = ThreadLocalRandom.current().nextFloat() * range; - damage = (damage + (ThreadLocalRandom.current().nextFloat() * range)) / 2; - - // put it back between min and max - damage += minDamage; - - Resists resists = null; - // get resists - if (AbstractWorldObject.IsAbstractCharacter(awo)) { - AbstractCharacter ac = (AbstractCharacter) awo; - resists = ac.getResists(); - } else if (awo.getObjectType().equals(GameObjectType.Building)) - resists = ((Building) awo).getResists(); - - // calculate resists in if any - if (resists != null) { - if (AbstractWorldObject.IsAbstractCharacter(awo)) - damage = resists.getResistedDamage(source, (AbstractCharacter) awo, damageType, damage * -1, trains) * -1; - else - damage = resists.getResistedDamage(source, null, damageType, damage * -1, trains) * -1; - } - - if (AbstractWorldObject.IsAbstractCharacter(awo)) { - AbstractCharacter ac = (AbstractCharacter) awo; - if (ac.isSit()) - damage *= 2.5f; // increase damage if sitting - } - - return damage; - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} - - public static float getMinDamage(float baseMin, float intelligence, float spirit, float focus) { - float min = baseMin * (((float)Math.pow(intelligence, 0.75f) * 0.0311f) + (0.02f * (int)focus) + ((float)Math.pow(spirit, 0.75f) * 0.0416f)); - return (float)((int)(min + 0.5f)); //round to nearest whole number - } - - public static float getMaxDamage(float baseMax, float intelligence, float spirit, float focus) { - float max = baseMax * (((float)Math.pow(intelligence, 0.75f) * 0.0785f) + (0.015f * (int)focus) + ((float)Math.pow(spirit, 0.75f) * 0.0157f)); - return (float)((int)(max + 0.5f)); //round to nearest whole number - } + PlayerBonuses bonus = ac.getBonuses(); + if (!skipImmune && bonus.getFloat(ModType.BlackMantle, SourceType.Heal) >= trains) { + ModifyHealthMsg mhm = new ModifyHealthMsg(source, ac, 0f, 0f, 0f, powerID, powerName, trains, effectID); + mhm.setUnknown03(5); //set target is immune + DispatchMessage.sendToAllInRange(ac, mhm); + return; + } + } + float mod = 0; + + //Modify health + + mod = ac.modifyHealth(modAmount, source, false); + + float cur = awo.getCurrentHitpoints(); + float maxAmount = awo.getHealthMax() - cur; + + AbstractNetMsg mhm = null; + if (modAmount < 0 && cur < 0 && mod != 0) + mhm = new ModifyHealthKillMsg(source, ac, modAmount, 0f, 0f, powerID, powerName, trains, effectID); + else + mhm = new ModifyHealthMsg(source, ac, modAmount, 0f, 0f, powerID, powerName, trains, effectID); + + if (effect instanceof DamageOverTimeJob) { + if (mhm instanceof ModifyHealthMsg) + ((ModifyHealthMsg) mhm).setOmitFromChat(1); + else if (mhm instanceof ModifyHealthKillMsg) + ((ModifyHealthKillMsg) mhm).setUnknown02(1); + } + + //send the damage + + DispatchMessage.sendToAllInRange(ac, mhm); + + // //send corpse if this kills a mob + // //TODO fix the someone misses blurb. + // if(awo instanceof Mob && awo.getHealth() <= 0) { + // CombatMessageMsg cmm = new CombatMessageMsg(null, 0, awo, 15); + // try { + // DispatchMessage.sendToAllInRange(ac, cmm); + // } catch (MsgSendException e) { + // Logger.error("MobCorpseSendError", e); + // } + // } + } else if (awo.getObjectType().equals(GameObjectType.Building)) { + + Building b = (Building) awo; + + if (modAmount < 0 && (!b.isVulnerable())) + return; //can't damage invul building + + int powerID = 0, effectID = 0; + String powerName = ""; + if (effect.getPower() != null) { + powerID = effect.getPower().getToken(); + powerName = effect.getPower().getName(); + } else + Logger.error("Power has returned null! Damage will fail to register! (" + (b.getRank() == -1 ? "Standing)" : "Destroyed)")); + + if (effect.getEffect() != null) { + effectID = effect.getEffect().getToken(); + } else + Logger.error("Effect has returned null! Damage will fail to register! (" + (b.getRank() == -1 ? "Standing)" : "Destroyed)")); + + float mod = b.modifyHealth(modAmount, source); + ModifyHealthMsg mhm = new ModifyHealthMsg(source, b, modAmount, 0f, 0f, powerID, powerName, trains, effectID); + + if (effect instanceof DamageOverTimeJob) + mhm.setOmitFromChat(1); + + //send the damage + + DispatchMessage.sendToAllInRange(b, mhm); + + } + } + + private float calculateDamage(AbstractCharacter source, float minDamage, float maxDamage, AbstractWorldObject awo, int trains) { + + // get range between min and max + float range = maxDamage - minDamage; + + // Damage is calculated twice to average a more central point + float damage = ThreadLocalRandom.current().nextFloat() * range; + damage = (damage + (ThreadLocalRandom.current().nextFloat() * range)) / 2; + + // put it back between min and max + damage += minDamage; + + Resists resists = null; + // get resists + if (AbstractWorldObject.IsAbstractCharacter(awo)) { + AbstractCharacter ac = (AbstractCharacter) awo; + resists = ac.getResists(); + } else if (awo.getObjectType().equals(GameObjectType.Building)) + resists = ((Building) awo).getResists(); + + // calculate resists in if any + if (resists != null) { + if (AbstractWorldObject.IsAbstractCharacter(awo)) + damage = resists.getResistedDamage(source, (AbstractCharacter) awo, damageType, damage * -1, trains) * -1; + else + damage = resists.getResistedDamage(source, null, damageType, damage * -1, trains) * -1; + } + + if (AbstractWorldObject.IsAbstractCharacter(awo)) { + AbstractCharacter ac = (AbstractCharacter) awo; + if (ac.isSit()) + damage *= 2.5f; // increase damage if sitting + } + + return damage; + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/HealthFullEffectModifier.java b/src/engine/powers/effectmodifiers/HealthFullEffectModifier.java index 6025f670..4dc68b0a 100644 --- a/src/engine/powers/effectmodifiers/HealthFullEffectModifier.java +++ b/src/engine/powers/effectmodifiers/HealthFullEffectModifier.java @@ -17,37 +17,40 @@ import java.sql.SQLException; public class HealthFullEffectModifier extends AbstractEffectModifier { - public HealthFullEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.percentMod != 0f) { //Stat Percent Modifiers - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - bonus.addFloat(this, amount); - } else { //Stat Modifiers - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - bonus.addFloat(this, amount); - } - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public HealthFullEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.percentMod != 0f) { //Stat Percent Modifiers + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + bonus.addFloat(this, amount); + } else { //Stat Modifiers + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + bonus.addFloat(this, amount); + } + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/HealthRecoverRateEffectModifier.java b/src/engine/powers/effectmodifiers/HealthRecoverRateEffectModifier.java index 2eb38cdf..f657a765 100644 --- a/src/engine/powers/effectmodifiers/HealthRecoverRateEffectModifier.java +++ b/src/engine/powers/effectmodifiers/HealthRecoverRateEffectModifier.java @@ -17,31 +17,34 @@ import java.sql.SQLException; public class HealthRecoverRateEffectModifier extends AbstractEffectModifier { - public HealthRecoverRateEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - - ac.update(); - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - bonus.multRegen(this.modType, amount); //positive regen modifiers - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public HealthRecoverRateEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + + ac.update(); + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + bonus.multRegen(this.modType, amount); //positive regen modifiers + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/IgnoreDamageCapEffectModifier.java b/src/engine/powers/effectmodifiers/IgnoreDamageCapEffectModifier.java index 6b2ffbaf..6eb71af7 100644 --- a/src/engine/powers/effectmodifiers/IgnoreDamageCapEffectModifier.java +++ b/src/engine/powers/effectmodifiers/IgnoreDamageCapEffectModifier.java @@ -18,29 +18,32 @@ import java.util.HashSet; public class IgnoreDamageCapEffectModifier extends AbstractEffectModifier { - public IgnoreDamageCapEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - PlayerBonuses bonus = ac.getBonuses(); - if (bonus == null) - return; - - if (bonus.getList(this.modType) == null) - bonus.setList(this.modType, new HashSet<>()); - bonus.getList(this.modType).add(this.sourceType); - - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public IgnoreDamageCapEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + PlayerBonuses bonus = ac.getBonuses(); + if (bonus == null) + return; + + if (bonus.getList(this.modType) == null) + bonus.setList(this.modType, new HashSet<>()); + bonus.getList(this.modType).add(this.sourceType); + + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/IgnorePassiveDefenseEffectModifier.java b/src/engine/powers/effectmodifiers/IgnorePassiveDefenseEffectModifier.java index 3b02a302..c4092bbd 100644 --- a/src/engine/powers/effectmodifiers/IgnorePassiveDefenseEffectModifier.java +++ b/src/engine/powers/effectmodifiers/IgnorePassiveDefenseEffectModifier.java @@ -17,23 +17,26 @@ import java.sql.SQLException; public class IgnorePassiveDefenseEffectModifier extends AbstractEffectModifier { - public IgnorePassiveDefenseEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public IgnorePassiveDefenseEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - PlayerBonuses bonus = ac.getBonuses(); - bonus.setBool(this.modType,this.sourceType,true); - } + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + PlayerBonuses bonus = ac.getBonuses(); + bonus.setBool(this.modType, this.sourceType, true); + } - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/ImmuneToAttackEffectModifier.java b/src/engine/powers/effectmodifiers/ImmuneToAttackEffectModifier.java index 35876f37..003855f9 100644 --- a/src/engine/powers/effectmodifiers/ImmuneToAttackEffectModifier.java +++ b/src/engine/powers/effectmodifiers/ImmuneToAttackEffectModifier.java @@ -17,24 +17,27 @@ import java.sql.SQLException; public class ImmuneToAttackEffectModifier extends AbstractEffectModifier { - public ImmuneToAttackEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public ImmuneToAttackEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { + @Override + public void applyBonus(AbstractCharacter ac, int trains) { - PlayerBonuses bonus = ac.getBonuses(); - bonus.setBool(this.modType,this.sourceType,true); - } + PlayerBonuses bonus = ac.getBonuses(); + bonus.setBool(this.modType, this.sourceType, true); + } - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/ImmuneToEffectModifier.java b/src/engine/powers/effectmodifiers/ImmuneToEffectModifier.java index da21abec..f237a800 100644 --- a/src/engine/powers/effectmodifiers/ImmuneToEffectModifier.java +++ b/src/engine/powers/effectmodifiers/ImmuneToEffectModifier.java @@ -17,23 +17,26 @@ import java.sql.SQLException; public class ImmuneToEffectModifier extends AbstractEffectModifier { - public ImmuneToEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public ImmuneToEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - PlayerBonuses bonus = ac.getBonuses(); - bonus.setBool(this.modType,this.sourceType,true); - } + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + PlayerBonuses bonus = ac.getBonuses(); + bonus.setBool(this.modType, this.sourceType, true); + } - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/ImmuneToPowersEffectModifier.java b/src/engine/powers/effectmodifiers/ImmuneToPowersEffectModifier.java index 67b4225d..9ee5df4f 100644 --- a/src/engine/powers/effectmodifiers/ImmuneToPowersEffectModifier.java +++ b/src/engine/powers/effectmodifiers/ImmuneToPowersEffectModifier.java @@ -17,24 +17,27 @@ import java.sql.SQLException; public class ImmuneToPowersEffectModifier extends AbstractEffectModifier { - public ImmuneToPowersEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - - PlayerBonuses bonus = ac.getBonuses(); - bonus.setBool(this.modType,this.sourceType,true); - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public ImmuneToPowersEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + + PlayerBonuses bonus = ac.getBonuses(); + bonus.setBool(this.modType, this.sourceType, true); + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/InvisibleEffectModifier.java b/src/engine/powers/effectmodifiers/InvisibleEffectModifier.java index c9aba42a..5c358185 100644 --- a/src/engine/powers/effectmodifiers/InvisibleEffectModifier.java +++ b/src/engine/powers/effectmodifiers/InvisibleEffectModifier.java @@ -23,60 +23,62 @@ import java.sql.SQLException; public class InvisibleEffectModifier extends AbstractEffectModifier { - public InvisibleEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public InvisibleEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - if (awo.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { - PlayerCharacter pc = (PlayerCharacter) awo; + if (awo.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { + PlayerCharacter pc = (PlayerCharacter) awo; - if (effect == null) - return; + if (effect == null) + return; - PowersBase pb = effect.getPower(); - if (pb == null) - return; + PowersBase pb = effect.getPower(); + if (pb == null) + return; - ActionsBase ab = effect.getAction(); + ActionsBase ab = effect.getAction(); - if (ab == null) - return; + if (ab == null) + return; - //send invis message to everyone around. - ClientConnection origin = SessionManager.getClientConnection(pc); - if (origin == null) - return; + //send invis message to everyone around. + ClientConnection origin = SessionManager.getClientConnection(pc); + if (origin == null) + return; - ab.getDurationInSeconds(trains); + ab.getDurationInSeconds(trains); - pc.setHidden(trains); + pc.setHidden(trains); - pc.setTimeStampNow("Invis"); + pc.setTimeStampNow("Invis"); - } - else { - Logger.error( "Cannot go invis on a non player."); - } - } + } else { + Logger.error("Cannot go invis on a non player."); + } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - if (ac == null) - return; - PlayerBonuses bonus = ac.getBonuses(); - if (bonus != null) - bonus.updateIfHigher(this, (float)trains); + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + if (ac == null) + return; + PlayerBonuses bonus = ac.getBonuses(); + if (bonus != null) + bonus.updateIfHigher(this, (float) trains); - //remove pets - if (ac.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) - ((PlayerCharacter)ac).dismissPet(); - } + //remove pets + if (ac.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) + ((PlayerCharacter) ac).dismissPet(); + } - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/ItemNameEffectModifier.java b/src/engine/powers/effectmodifiers/ItemNameEffectModifier.java index e7d6c9c1..bf51fd3d 100644 --- a/src/engine/powers/effectmodifiers/ItemNameEffectModifier.java +++ b/src/engine/powers/effectmodifiers/ItemNameEffectModifier.java @@ -21,83 +21,126 @@ import java.sql.SQLException; public class ItemNameEffectModifier extends AbstractEffectModifier { - public String name = ""; - - public ItemNameEffectModifier(ResultSet rs) throws SQLException { - super(rs); - - //We're going to add effect names to a lookup map for ./makeitem - int ID = rs.getInt("ID"); - switch (ID) { //don't add these ID's to the name list. They're duplicates - case 4259: return; - case 4210: return; - case 4: return; - case 97: return; - case 610: return; - case 4442: return; - case 5106: return; - case 4637: return; - case 2271: return; - case 587: return; - case 600: return; - case 3191: return; - case 3589: return; - case 3950: return; - case 3499: return; - case 4925: return; - case 15: return; - case 5101: return; - case 2418: return; - case 183: return; - case 373: return; - case 1893: return; - case 3127: return; - case 1232: return; - case 4522: return; - case 4817: return; - case 2833: return; - case 4469: return; - case 2122: return; - case 3057: return; - case 3070: return; - case 191: return; - case 3117: return; - case 3702: return; - case 1619: return; - case 2584: return; - case 414: return; - case 2078: return; - case 4844: return; - case 2275: return; - } - - String namePre = rs.getString("string1"); - String nameSuf = rs.getString("string2"); - String n = (namePre.isEmpty()) ? nameSuf : namePre; - this.name = n; - n = n.toLowerCase(); - n = n.replace(" ", "_"); - String IDString = rs.getString("IDString"); - IDString = IDString.substring(0, IDString.length() - 1); - EffectsBase.addItemEffectsByName(n, IDString); - } - - public String getName() { - return this.name; - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public String name = ""; + + public ItemNameEffectModifier(ResultSet rs) throws SQLException { + super(rs); + + //We're going to add effect names to a lookup map for ./makeitem + int ID = rs.getInt("ID"); + switch (ID) { //don't add these ID's to the name list. They're duplicates + case 4259: + return; + case 4210: + return; + case 4: + return; + case 97: + return; + case 610: + return; + case 4442: + return; + case 5106: + return; + case 4637: + return; + case 2271: + return; + case 587: + return; + case 600: + return; + case 3191: + return; + case 3589: + return; + case 3950: + return; + case 3499: + return; + case 4925: + return; + case 15: + return; + case 5101: + return; + case 2418: + return; + case 183: + return; + case 373: + return; + case 1893: + return; + case 3127: + return; + case 1232: + return; + case 4522: + return; + case 4817: + return; + case 2833: + return; + case 4469: + return; + case 2122: + return; + case 3057: + return; + case 3070: + return; + case 191: + return; + case 3117: + return; + case 3702: + return; + case 1619: + return; + case 2584: + return; + case 414: + return; + case 2078: + return; + case 4844: + return; + case 2275: + return; + } + + String namePre = rs.getString("string1"); + String nameSuf = rs.getString("string2"); + String n = (namePre.isEmpty()) ? nameSuf : namePre; + this.name = n; + n = n.toLowerCase(); + n = n.replace(" ", "_"); + String IDString = rs.getString("IDString"); + IDString = IDString.substring(0, IDString.length() - 1); + EffectsBase.addItemEffectsByName(n, IDString); + } + + public String getName() { + return this.name; + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/ManaEffectModifier.java b/src/engine/powers/effectmodifiers/ManaEffectModifier.java index 94e20793..c0db91c0 100644 --- a/src/engine/powers/effectmodifiers/ManaEffectModifier.java +++ b/src/engine/powers/effectmodifiers/ManaEffectModifier.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -44,189 +41,192 @@ import java.util.concurrent.ThreadLocalRandom; public class ManaEffectModifier extends AbstractEffectModifier { - private DamageType damageType; - - public ManaEffectModifier(ResultSet rs) throws SQLException { - super(rs); - String damageTypeDB = rs.getString("type"); - try { - this.damageType = DamageType.valueOf(damageTypeDB); - } catch (IllegalArgumentException e) { - Logger.error("DamageType could not be loaded from database. " + "UUID = " + this.UUID - + " value received = '" + damageTypeDB + '\'', e); - } - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - if (awo == null) { - Logger.error( "_applyEffectModifier(): NULL AWO passed in."); - return; - } - - if (effect == null) { - Logger.error( "_applyEffectModifier(): NULL AbstractEffectJob passed in."); - return; - } - - if (!AbstractWorldObject.IsAbstractCharacter(awo)) - return; - AbstractCharacter awoac = (AbstractCharacter) awo; - - float modAmount = 0f; - - // Modify Mana by percent - if (this.percentMod != 0f) { - - float mod = 1f; - if (this.useRampAdd) - mod = (this.percentMod + (this.ramp * trains)) / 100; - else - mod = (this.percentMod * (1 + (this.ramp * trains))) / 100; - modAmount = mod * awoac.getManaMax(); - - if (awoac.isSit()) - modAmount *= 2.5f; - - //debug for spell damage and atr - if (source.getDebug(16) && source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { - - PlayerCharacter pc = (PlayerCharacter) source; - String smsg = "Percent Damage: " + mod * 100 + '%'; - - ChatManager.chatSystemInfo(pc, smsg); - } - } - - // Modify health by min/max amount - else if (this.minMod != 0f || this.maxMod != 0f) { - float min = this.minMod; - float max = this.maxMod; - if (this.ramp > 0f) { - float mod = this.ramp * trains; - if (this.useRampAdd) { - min += mod; - max += mod; - } else { - min *= (1 + mod); - max *= (1 + mod); - } - } - if (source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { - PlayerCharacter pc = (PlayerCharacter) source; - - float focus; - CharacterSkill skill = pc.getSkills().get(effect.getPower().getSkillName()); - if (skill == null) - focus = CharacterSkill.getQuickMastery(pc, effect.getPower().getSkillName()); - else - focus = skill.getModifiedAmount(); - //TODO clean up old formulas once new one is verified - // min *= (0.5 + 0.0075 * pc.getStatIntCurrent() + 0.011 * pc.getStatSpiCurrent() + 0.0196 * focus); - // max *= (0.62 + 0.0192 * pc.getStatIntCurrent() + 0.00415 * pc.getStatSpiCurrent() + 0.015 * focus); - float intt = (pc.getStatIntCurrent() >= 1) ? (float)pc.getStatIntCurrent() : 1f; - float spi = (pc.getStatSpiCurrent() >= 1) ? (float)pc.getStatSpiCurrent() : 1f; - // min *= (intt * 0.0045 + 0.055 * (float)Math.sqrt(intt - 0.5) + spi * 0.006 + 0.07 * (float)Math.sqrt(spi - 0.5) + 0.02 * (int)focus); - // max *= (intt * 0.0117 + 0.13 * (float)Math.sqrt(intt - 0.5) + spi * 0.0024 + (float)Math.sqrt(spi - 0.5) * 0.021 + 0.015 * (int)focus); - min = HealthEffectModifier.getMinDamage(min, intt, spi, focus); - max = HealthEffectModifier.getMaxDamage(max, intt, spi, focus); - - //debug for spell damage and atr - if (pc.getDebug(16)) { - String smsg = "Damage: " + (int)Math.abs(min) + " - " + (int)Math.abs(max); - ChatManager.chatSystemInfo(pc, smsg); - } - } - modAmount = calculateDamage(source, awoac, min, max, awo, trains); - PlayerBonuses bonus = source.getBonuses(); - - // Apply any power effect modifiers (such as stances) - if (bonus != null) - modAmount *= (1 + bonus.getFloatPercentAll(ModType.PowerDamageModifier, SourceType.None)); - } - if (modAmount == 0f) - return; - if (AbstractWorldObject.IsAbstractCharacter(awo)) { - AbstractCharacter ac = (AbstractCharacter) awo; - int powerID = 0, effectID = 0; - String powerName = ""; - if (effect.getPower() != null) { - powerID = effect.getPower().getToken(); - powerName = effect.getPower().getName(); - } - if (effect.getEffect() != null) { - effectID = effect.getEffect().getToken(); - } - - //see if target is immune to heals - if (modAmount > 0f) { - boolean skipImmune = false; - if (effect.getAction().getPowerAction() instanceof DirectDamagePowerAction) { - ArrayList actions = effect.getPower().getActions(); - for (ActionsBase ab : actions) { - AbstractPowerAction apa = ab.getPowerAction(); - if (apa instanceof DamageOverTimePowerAction) - skipImmune = true; - } - } - PlayerBonuses bonus = ac.getBonuses(); - if (!skipImmune && bonus.getFloat(ModType.BlackMantle, SourceType.Heal) >= trains) { - ModifyHealthMsg mhm = new ModifyHealthMsg(source, ac, 0f, 0f, 0f, powerID, powerName, trains, effectID); - mhm.setUnknown03(5); //set target is immune - DispatchMessage.sendToAllInRange(ac, mhm); - return; - } - } - - ac.modifyMana(modAmount, source); - - ModifyHealthMsg mhm = new ModifyHealthMsg(source, ac, 0f, modAmount, 0f, powerID, powerName, trains, - effectID); - if (effect instanceof DamageOverTimeJob) - mhm.setOmitFromChat(1); - DispatchMessage.sendToAllInRange(ac, mhm); - } - } - - private float calculateDamage(AbstractCharacter source, AbstractCharacter target, float minDamage, float maxDamage, AbstractWorldObject awo, int trains) { - // get range between min and max - float range = maxDamage - minDamage; - - // Damage is calculated twice to average a more central point - float damage = ThreadLocalRandom.current().nextFloat() * range; - damage = (damage + (ThreadLocalRandom.current().nextFloat() * range)) / 2; - - // put it back between min and max - damage += minDamage; - - Resists resists = null; - // get resists - if (AbstractWorldObject.IsAbstractCharacter(awo)) { - AbstractCharacter ac = (AbstractCharacter) awo; - resists = ac.getResists(); - } else if (awo.getObjectType().equals(Enum.GameObjectType.Building)) - resists = ((Building) awo).getResists(); - - // calculate resists in if any - if (resists != null) - damage = resists.getResistedDamage(source, target, damageType, damage * -1, trains) * -1; - - if (AbstractWorldObject.IsAbstractCharacter(awo)) { - AbstractCharacter ac = (AbstractCharacter) awo; - if (ac.isSit()) - damage *= 2.5f; // increase damage if sitting - } - - return damage; - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + private DamageType damageType; + + public ManaEffectModifier(ResultSet rs) throws SQLException { + super(rs); + String damageTypeDB = rs.getString("type"); + try { + this.damageType = DamageType.valueOf(damageTypeDB); + } catch (IllegalArgumentException e) { + Logger.error("DamageType could not be loaded from database. " + "UUID = " + this.UUID + + " value received = '" + damageTypeDB + '\'', e); + } + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + if (awo == null) { + Logger.error("_applyEffectModifier(): NULL AWO passed in."); + return; + } + + if (effect == null) { + Logger.error("_applyEffectModifier(): NULL AbstractEffectJob passed in."); + return; + } + + if (!AbstractWorldObject.IsAbstractCharacter(awo)) + return; + AbstractCharacter awoac = (AbstractCharacter) awo; + + float modAmount = 0f; + + // Modify Mana by percent + if (this.percentMod != 0f) { + + float mod = 1f; + if (this.useRampAdd) + mod = (this.percentMod + (this.ramp * trains)) / 100; + else + mod = (this.percentMod * (1 + (this.ramp * trains))) / 100; + modAmount = mod * awoac.getManaMax(); + + if (awoac.isSit()) + modAmount *= 2.5f; + + //debug for spell damage and atr + if (source.getDebug(16) && source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { + + PlayerCharacter pc = (PlayerCharacter) source; + String smsg = "Percent Damage: " + mod * 100 + '%'; + + ChatManager.chatSystemInfo(pc, smsg); + } + } + + // Modify health by min/max amount + else if (this.minMod != 0f || this.maxMod != 0f) { + float min = this.minMod; + float max = this.maxMod; + if (this.ramp > 0f) { + float mod = this.ramp * trains; + if (this.useRampAdd) { + min += mod; + max += mod; + } else { + min *= (1 + mod); + max *= (1 + mod); + } + } + if (source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { + PlayerCharacter pc = (PlayerCharacter) source; + + float focus; + CharacterSkill skill = pc.getSkills().get(effect.getPower().getSkillName()); + if (skill == null) + focus = CharacterSkill.getQuickMastery(pc, effect.getPower().getSkillName()); + else + focus = skill.getModifiedAmount(); + //TODO clean up old formulas once new one is verified + // min *= (0.5 + 0.0075 * pc.getStatIntCurrent() + 0.011 * pc.getStatSpiCurrent() + 0.0196 * focus); + // max *= (0.62 + 0.0192 * pc.getStatIntCurrent() + 0.00415 * pc.getStatSpiCurrent() + 0.015 * focus); + float intt = (pc.getStatIntCurrent() >= 1) ? (float) pc.getStatIntCurrent() : 1f; + float spi = (pc.getStatSpiCurrent() >= 1) ? (float) pc.getStatSpiCurrent() : 1f; + // min *= (intt * 0.0045 + 0.055 * (float)Math.sqrt(intt - 0.5) + spi * 0.006 + 0.07 * (float)Math.sqrt(spi - 0.5) + 0.02 * (int)focus); + // max *= (intt * 0.0117 + 0.13 * (float)Math.sqrt(intt - 0.5) + spi * 0.0024 + (float)Math.sqrt(spi - 0.5) * 0.021 + 0.015 * (int)focus); + min = HealthEffectModifier.getMinDamage(min, intt, spi, focus); + max = HealthEffectModifier.getMaxDamage(max, intt, spi, focus); + + //debug for spell damage and atr + if (pc.getDebug(16)) { + String smsg = "Damage: " + (int) Math.abs(min) + " - " + (int) Math.abs(max); + ChatManager.chatSystemInfo(pc, smsg); + } + } + modAmount = calculateDamage(source, awoac, min, max, awo, trains); + PlayerBonuses bonus = source.getBonuses(); + + // Apply any power effect modifiers (such as stances) + if (bonus != null) + modAmount *= (1 + bonus.getFloatPercentAll(ModType.PowerDamageModifier, SourceType.None)); + } + if (modAmount == 0f) + return; + if (AbstractWorldObject.IsAbstractCharacter(awo)) { + AbstractCharacter ac = (AbstractCharacter) awo; + int powerID = 0, effectID = 0; + String powerName = ""; + if (effect.getPower() != null) { + powerID = effect.getPower().getToken(); + powerName = effect.getPower().getName(); + } + if (effect.getEffect() != null) { + effectID = effect.getEffect().getToken(); + } + + //see if target is immune to heals + if (modAmount > 0f) { + boolean skipImmune = false; + if (effect.getAction().getPowerAction() instanceof DirectDamagePowerAction) { + ArrayList actions = effect.getPower().getActions(); + for (ActionsBase ab : actions) { + AbstractPowerAction apa = ab.getPowerAction(); + if (apa instanceof DamageOverTimePowerAction) + skipImmune = true; + } + } + PlayerBonuses bonus = ac.getBonuses(); + if (!skipImmune && bonus.getFloat(ModType.BlackMantle, SourceType.Heal) >= trains) { + ModifyHealthMsg mhm = new ModifyHealthMsg(source, ac, 0f, 0f, 0f, powerID, powerName, trains, effectID); + mhm.setUnknown03(5); //set target is immune + DispatchMessage.sendToAllInRange(ac, mhm); + return; + } + } + + ac.modifyMana(modAmount, source); + + ModifyHealthMsg mhm = new ModifyHealthMsg(source, ac, 0f, modAmount, 0f, powerID, powerName, trains, + effectID); + if (effect instanceof DamageOverTimeJob) + mhm.setOmitFromChat(1); + DispatchMessage.sendToAllInRange(ac, mhm); + } + } + + private float calculateDamage(AbstractCharacter source, AbstractCharacter target, float minDamage, float maxDamage, AbstractWorldObject awo, int trains) { + // get range between min and max + float range = maxDamage - minDamage; + + // Damage is calculated twice to average a more central point + float damage = ThreadLocalRandom.current().nextFloat() * range; + damage = (damage + (ThreadLocalRandom.current().nextFloat() * range)) / 2; + + // put it back between min and max + damage += minDamage; + + Resists resists = null; + // get resists + if (AbstractWorldObject.IsAbstractCharacter(awo)) { + AbstractCharacter ac = (AbstractCharacter) awo; + resists = ac.getResists(); + } else if (awo.getObjectType().equals(Enum.GameObjectType.Building)) + resists = ((Building) awo).getResists(); + + // calculate resists in if any + if (resists != null) + damage = resists.getResistedDamage(source, target, damageType, damage * -1, trains) * -1; + + if (AbstractWorldObject.IsAbstractCharacter(awo)) { + AbstractCharacter ac = (AbstractCharacter) awo; + if (ac.isSit()) + damage *= 2.5f; // increase damage if sitting + } + + return damage; + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/ManaFullEffectModifier.java b/src/engine/powers/effectmodifiers/ManaFullEffectModifier.java index ba637c39..ad1fa6b4 100644 --- a/src/engine/powers/effectmodifiers/ManaFullEffectModifier.java +++ b/src/engine/powers/effectmodifiers/ManaFullEffectModifier.java @@ -17,37 +17,40 @@ import java.sql.SQLException; public class ManaFullEffectModifier extends AbstractEffectModifier { - public ManaFullEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.percentMod != 0f) { //Stat Percent Modifiers - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - bonus.addFloat(this, amount); - } else { //Stat Modifiers - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - bonus.addFloat(this, amount); - } - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public ManaFullEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.percentMod != 0f) { //Stat Percent Modifiers + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + bonus.addFloat(this, amount); + } else { //Stat Modifiers + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + bonus.addFloat(this, amount); + } + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/ManaRecoverRateEffectModifier.java b/src/engine/powers/effectmodifiers/ManaRecoverRateEffectModifier.java index 64886767..7c657e61 100644 --- a/src/engine/powers/effectmodifiers/ManaRecoverRateEffectModifier.java +++ b/src/engine/powers/effectmodifiers/ManaRecoverRateEffectModifier.java @@ -17,29 +17,32 @@ import java.sql.SQLException; public class ManaRecoverRateEffectModifier extends AbstractEffectModifier { - public ManaRecoverRateEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - bonus.multRegen(this.modType, amount); //positive regen modifiers - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public ManaRecoverRateEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + bonus.multRegen(this.modType, amount); //positive regen modifiers + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/MaxDamageEffectModifier.java b/src/engine/powers/effectmodifiers/MaxDamageEffectModifier.java index e52045f2..dafe263a 100644 --- a/src/engine/powers/effectmodifiers/MaxDamageEffectModifier.java +++ b/src/engine/powers/effectmodifiers/MaxDamageEffectModifier.java @@ -20,42 +20,44 @@ import java.sql.SQLException; public class MaxDamageEffectModifier extends AbstractEffectModifier { - public MaxDamageEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - - } - - @Override - public void applyBonus(Item item, int trains) { - if (item == null) - return; - String key; float amount = 0f; - if (this.percentMod != 0f) { - if (this.useRampAdd) - amount = (this.percentMod + (this.ramp * trains)) / 100f; - else - amount = (this.percentMod * (1 + (this.ramp * trains))) / 100f; - amount = amount/100; - key = "max.percent"; - } else { - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - key = "max"; - } - item.addBonus(this, amount); - } - - @Override - public void applyBonus(Building building, int trains) {} + public MaxDamageEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + + } + + @Override + public void applyBonus(Item item, int trains) { + if (item == null) + return; + String key; + float amount = 0f; + if (this.percentMod != 0f) { + if (this.useRampAdd) + amount = (this.percentMod + (this.ramp * trains)) / 100f; + else + amount = (this.percentMod * (1 + (this.ramp * trains))) / 100f; + amount = amount / 100; + key = "max.percent"; + } else { + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + key = "max"; + } + item.addBonus(this, amount); + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/MeleeDamageEffectModifier.java b/src/engine/powers/effectmodifiers/MeleeDamageEffectModifier.java index f822aba4..156cc502 100644 --- a/src/engine/powers/effectmodifiers/MeleeDamageEffectModifier.java +++ b/src/engine/powers/effectmodifiers/MeleeDamageEffectModifier.java @@ -17,37 +17,40 @@ import java.sql.SQLException; public class MeleeDamageEffectModifier extends AbstractEffectModifier { - public MeleeDamageEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.percentMod != 0f) { //Stat Percent Modifiers - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - bonus.addFloat(this, amount); - } else { //Stat Modifiers - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - bonus.addFloat(this, amount); - } - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public MeleeDamageEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.percentMod != 0f) { //Stat Percent Modifiers + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + bonus.addFloat(this, amount); + } else { //Stat Modifiers + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + bonus.addFloat(this, amount); + } + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/MinDamageEffectModifier.java b/src/engine/powers/effectmodifiers/MinDamageEffectModifier.java index 90e73fe0..7eeae151 100644 --- a/src/engine/powers/effectmodifiers/MinDamageEffectModifier.java +++ b/src/engine/powers/effectmodifiers/MinDamageEffectModifier.java @@ -20,42 +20,44 @@ import java.sql.SQLException; public class MinDamageEffectModifier extends AbstractEffectModifier { - public MinDamageEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - - } - - @Override - public void applyBonus(Item item, int trains) { - if (item == null) - return; - String key; float amount = 0f; - if (this.percentMod != 0f) { - if (this.useRampAdd) - amount = (this.percentMod + (this.ramp * trains)) / 100f; - else - amount = (this.percentMod * (1 + (this.ramp * trains))) / 100f; - amount = amount/100; - key = "min.percent"; - } else { - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - key = "min"; - } - item.addBonus(this, amount); - } - - @Override - public void applyBonus(Building building, int trains) {} + public MinDamageEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + + } + + @Override + public void applyBonus(Item item, int trains) { + if (item == null) + return; + String key; + float amount = 0f; + if (this.percentMod != 0f) { + if (this.useRampAdd) + amount = (this.percentMod + (this.ramp * trains)) / 100f; + else + amount = (this.percentMod * (1 + (this.ramp * trains))) / 100f; + amount = amount / 100; + key = "min.percent"; + } else { + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + key = "min"; + } + item.addBonus(this, amount); + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/NoModEffectModifier.java b/src/engine/powers/effectmodifiers/NoModEffectModifier.java index f5716e03..a09c5600 100644 --- a/src/engine/powers/effectmodifiers/NoModEffectModifier.java +++ b/src/engine/powers/effectmodifiers/NoModEffectModifier.java @@ -18,36 +18,39 @@ import java.sql.SQLException; public class NoModEffectModifier extends AbstractEffectModifier { - public NoModEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - //TODO check if anything needs removed. - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - PlayerBonuses bonus = ac.getBonuses(); - bonus.setBool(this.modType,this.sourceType,true); - - switch (this.sourceType){ - case Fly: - if (!ac.getObjectType().equals(GameObjectType.PlayerCharacter)) - return; - PlayerCharacter flyer = (PlayerCharacter)ac; - - if (flyer.getAltitude() > 0) - flyer.update(); - PlayerCharacter.GroundPlayer(flyer); - break; - - } - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public NoModEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + //TODO check if anything needs removed. + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + PlayerBonuses bonus = ac.getBonuses(); + bonus.setBool(this.modType, this.sourceType, true); + + switch (this.sourceType) { + case Fly: + if (!ac.getObjectType().equals(GameObjectType.PlayerCharacter)) + return; + PlayerCharacter flyer = (PlayerCharacter) ac; + + if (flyer.getAltitude() > 0) + flyer.update(); + PlayerCharacter.GroundPlayer(flyer); + break; + + } + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/OCVEffectModifier.java b/src/engine/powers/effectmodifiers/OCVEffectModifier.java index 5c91affe..5d6cdc7b 100644 --- a/src/engine/powers/effectmodifiers/OCVEffectModifier.java +++ b/src/engine/powers/effectmodifiers/OCVEffectModifier.java @@ -17,37 +17,40 @@ import java.sql.SQLException; public class OCVEffectModifier extends AbstractEffectModifier { - public OCVEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.percentMod != 0f) { //Stat Percent Modifiers - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - bonus.addFloat(this, amount); - } else { //Stat Modifiers - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - bonus.addFloat(this, amount); - } - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public OCVEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.percentMod != 0f) { //Stat Percent Modifiers + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + bonus.addFloat(this, amount); + } else { //Stat Modifiers + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + bonus.addFloat(this, amount); + } + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/ParryEffectModifier.java b/src/engine/powers/effectmodifiers/ParryEffectModifier.java index 6a0f0f27..386e9f5c 100644 --- a/src/engine/powers/effectmodifiers/ParryEffectModifier.java +++ b/src/engine/powers/effectmodifiers/ParryEffectModifier.java @@ -17,37 +17,40 @@ import java.sql.SQLException; public class ParryEffectModifier extends AbstractEffectModifier { - public ParryEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.percentMod != 0f) { //Stat Percent Modifiers - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - bonus.addFloat(this, amount); - } else { //Stat Modifiers - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - bonus.addFloat(this, amount); - } - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public ParryEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.percentMod != 0f) { //Stat Percent Modifiers + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + bonus.addFloat(this, amount); + } else { //Stat Modifiers + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + bonus.addFloat(this, amount); + } + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/PassiveDefenseEffectModifier.java b/src/engine/powers/effectmodifiers/PassiveDefenseEffectModifier.java index 9789c4c4..b9ad4bb6 100644 --- a/src/engine/powers/effectmodifiers/PassiveDefenseEffectModifier.java +++ b/src/engine/powers/effectmodifiers/PassiveDefenseEffectModifier.java @@ -17,37 +17,40 @@ import java.sql.SQLException; public class PassiveDefenseEffectModifier extends AbstractEffectModifier { - public PassiveDefenseEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.percentMod != 0f) { //Stat Percent Modifiers - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - bonus.addFloat(this, amount); - } else { //Stat Modifiers - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - bonus.addFloat(this, amount); - } - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public PassiveDefenseEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.percentMod != 0f) { //Stat Percent Modifiers + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + bonus.addFloat(this, amount); + } else { //Stat Modifiers + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + bonus.addFloat(this, amount); + } + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/PowerCostEffectModifier.java b/src/engine/powers/effectmodifiers/PowerCostEffectModifier.java index 3a4c54d9..57c8216e 100644 --- a/src/engine/powers/effectmodifiers/PowerCostEffectModifier.java +++ b/src/engine/powers/effectmodifiers/PowerCostEffectModifier.java @@ -17,37 +17,40 @@ import java.sql.SQLException; public class PowerCostEffectModifier extends AbstractEffectModifier { - public PowerCostEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.percentMod != 0f) { //Stat Percent Modifiers - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - bonus.addFloat(this, amount); - } else { //Stat Modifiers - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - bonus.addFloat(this, amount); - } - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public PowerCostEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.percentMod != 0f) { //Stat Percent Modifiers + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + bonus.addFloat(this, amount); + } else { //Stat Modifiers + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + bonus.addFloat(this, amount); + } + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/PowerCostHealthEffectModifier.java b/src/engine/powers/effectmodifiers/PowerCostHealthEffectModifier.java index e6006a3a..ad80fdf7 100644 --- a/src/engine/powers/effectmodifiers/PowerCostHealthEffectModifier.java +++ b/src/engine/powers/effectmodifiers/PowerCostHealthEffectModifier.java @@ -20,22 +20,25 @@ import java.sql.SQLException; public class PowerCostHealthEffectModifier extends AbstractEffectModifier { - public PowerCostHealthEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public PowerCostHealthEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { + @Override + public void applyBonus(AbstractCharacter ac, int trains) { - } + } - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/PowerDamageEffectModifier.java b/src/engine/powers/effectmodifiers/PowerDamageEffectModifier.java index 238e3fbd..336bda4e 100644 --- a/src/engine/powers/effectmodifiers/PowerDamageEffectModifier.java +++ b/src/engine/powers/effectmodifiers/PowerDamageEffectModifier.java @@ -17,37 +17,40 @@ import java.sql.SQLException; public class PowerDamageEffectModifier extends AbstractEffectModifier { - public PowerDamageEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.percentMod != 0f) { //Stat Percent Modifiers - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - bonus.addFloat(this, amount); - } else { //Stat Modifiers - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - bonus.addFloat(this, amount); - } - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public PowerDamageEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.percentMod != 0f) { //Stat Percent Modifiers + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + bonus.addFloat(this, amount); + } else { //Stat Modifiers + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + bonus.addFloat(this, amount); + } + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/ProtectionFromEffectModifier.java b/src/engine/powers/effectmodifiers/ProtectionFromEffectModifier.java index f329bbf4..2b32aa95 100644 --- a/src/engine/powers/effectmodifiers/ProtectionFromEffectModifier.java +++ b/src/engine/powers/effectmodifiers/ProtectionFromEffectModifier.java @@ -17,26 +17,29 @@ import java.sql.SQLException; public class ProtectionFromEffectModifier extends AbstractEffectModifier { - public ProtectionFromEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - PlayerBonuses bonus = ac.getBonuses(); - if (bonus == null) - return; - bonus.setFloat(this, trains); - // bonus.setBool(this, true); - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public ProtectionFromEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + PlayerBonuses bonus = ac.getBonuses(); + if (bonus == null) + return; + bonus.setFloat(this, trains); + // bonus.setBool(this, true); + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/ResistanceEffectModifier.java b/src/engine/powers/effectmodifiers/ResistanceEffectModifier.java index e4286e24..341268e1 100644 --- a/src/engine/powers/effectmodifiers/ResistanceEffectModifier.java +++ b/src/engine/powers/effectmodifiers/ResistanceEffectModifier.java @@ -17,37 +17,40 @@ import java.sql.SQLException; public class ResistanceEffectModifier extends AbstractEffectModifier { - public ResistanceEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.percentMod != 0f) { //Stat Percent Modifiers - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - bonus.addFloat(this, amount); - } else { //Stat Modifiers - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - bonus.addFloat(this, amount); - } - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public ResistanceEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.percentMod != 0f) { //Stat Percent Modifiers + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + bonus.addFloat(this, amount); + } else { //Stat Modifiers + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + bonus.addFloat(this, amount); + } + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/ScaleHeightEffectModifier.java b/src/engine/powers/effectmodifiers/ScaleHeightEffectModifier.java index 6cd022a4..e9872926 100644 --- a/src/engine/powers/effectmodifiers/ScaleHeightEffectModifier.java +++ b/src/engine/powers/effectmodifiers/ScaleHeightEffectModifier.java @@ -20,22 +20,25 @@ import java.sql.SQLException; public class ScaleHeightEffectModifier extends AbstractEffectModifier { - public ScaleHeightEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public ScaleHeightEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { + @Override + public void applyBonus(AbstractCharacter ac, int trains) { - } + } - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/ScaleWidthEffectModifier.java b/src/engine/powers/effectmodifiers/ScaleWidthEffectModifier.java index 00e77e68..40339310 100644 --- a/src/engine/powers/effectmodifiers/ScaleWidthEffectModifier.java +++ b/src/engine/powers/effectmodifiers/ScaleWidthEffectModifier.java @@ -20,22 +20,25 @@ import java.sql.SQLException; public class ScaleWidthEffectModifier extends AbstractEffectModifier { - public ScaleWidthEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public ScaleWidthEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { + @Override + public void applyBonus(AbstractCharacter ac, int trains) { - } + } - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/ScanRangeEffectModifier.java b/src/engine/powers/effectmodifiers/ScanRangeEffectModifier.java index 968f2e3e..0b5f34a4 100644 --- a/src/engine/powers/effectmodifiers/ScanRangeEffectModifier.java +++ b/src/engine/powers/effectmodifiers/ScanRangeEffectModifier.java @@ -17,37 +17,40 @@ import java.sql.SQLException; public class ScanRangeEffectModifier extends AbstractEffectModifier { - public ScanRangeEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.percentMod != 0f) { //Stat Percent Modifiers - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - bonus.addFloat(this, amount); - } else { //Stat Modifiers - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - bonus.addFloat(this, amount); - } - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public ScanRangeEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.percentMod != 0f) { //Stat Percent Modifiers + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + bonus.addFloat(this, amount); + } else { //Stat Modifiers + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + bonus.addFloat(this, amount); + } + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/SeeInvisibleEffectModifier.java b/src/engine/powers/effectmodifiers/SeeInvisibleEffectModifier.java index 94ab63d9..ae779788 100644 --- a/src/engine/powers/effectmodifiers/SeeInvisibleEffectModifier.java +++ b/src/engine/powers/effectmodifiers/SeeInvisibleEffectModifier.java @@ -17,26 +17,29 @@ import java.sql.SQLException; public class SeeInvisibleEffectModifier extends AbstractEffectModifier { - public SeeInvisibleEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - if (ac == null) - return; - PlayerBonuses bonus = ac.getBonuses(); - if (bonus != null) - bonus.updateIfHigher(this, (float)trains); - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public SeeInvisibleEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + if (ac == null) + return; + PlayerBonuses bonus = ac.getBonuses(); + if (bonus != null) + bonus.updateIfHigher(this, (float) trains); + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/SilencedEffectModifier.java b/src/engine/powers/effectmodifiers/SilencedEffectModifier.java index 75764cc1..0bb0577b 100644 --- a/src/engine/powers/effectmodifiers/SilencedEffectModifier.java +++ b/src/engine/powers/effectmodifiers/SilencedEffectModifier.java @@ -17,24 +17,27 @@ import java.sql.SQLException; public class SilencedEffectModifier extends AbstractEffectModifier { - public SilencedEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - PlayerBonuses bonus = ac.getBonuses(); - bonus.setBool(this.modType,this.sourceType, true); - - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public SilencedEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + PlayerBonuses bonus = ac.getBonuses(); + bonus.setBool(this.modType, this.sourceType, true); + + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/SkillEffectModifier.java b/src/engine/powers/effectmodifiers/SkillEffectModifier.java index d49dd6f3..1f3928c3 100644 --- a/src/engine/powers/effectmodifiers/SkillEffectModifier.java +++ b/src/engine/powers/effectmodifiers/SkillEffectModifier.java @@ -17,37 +17,40 @@ import java.sql.SQLException; public class SkillEffectModifier extends AbstractEffectModifier { - public SkillEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.percentMod != 0f) { //Stat Percent Modifiers - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - bonus.addFloat(this, amount); - } else { //Stat Modifiers - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - bonus.addFloat(this, amount); - } - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public SkillEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.percentMod != 0f) { //Stat Percent Modifiers + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + bonus.addFloat(this, amount); + } else { //Stat Modifiers + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + bonus.addFloat(this, amount); + } + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/SlayEffectModifier.java b/src/engine/powers/effectmodifiers/SlayEffectModifier.java index c4608eee..9c149bdc 100644 --- a/src/engine/powers/effectmodifiers/SlayEffectModifier.java +++ b/src/engine/powers/effectmodifiers/SlayEffectModifier.java @@ -17,37 +17,40 @@ import java.sql.SQLException; public class SlayEffectModifier extends AbstractEffectModifier { - public SlayEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.percentMod != 0f) { //Stat Percent Modifiers - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - bonus.addFloat(this, amount); - } else { //Stat Modifiers - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - bonus.addFloat(this, amount); - } - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public SlayEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.percentMod != 0f) { //Stat Percent Modifiers + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + bonus.addFloat(this, amount); + } else { //Stat Modifiers + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + bonus.addFloat(this, amount); + } + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/SpeedEffectModifier.java b/src/engine/powers/effectmodifiers/SpeedEffectModifier.java index 9df8a13b..153dad7a 100644 --- a/src/engine/powers/effectmodifiers/SpeedEffectModifier.java +++ b/src/engine/powers/effectmodifiers/SpeedEffectModifier.java @@ -17,37 +17,40 @@ import java.sql.SQLException; public class SpeedEffectModifier extends AbstractEffectModifier { - public SpeedEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - //Logger.error(this.getSimpleClassName(), "Speed applied with " + trains + " trains"); - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.percentMod != 0f) { //Stat Percent Modifiers - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - bonus.addFloat(this, amount); - } else { //Stat Modifiers - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - bonus.addFloat(this, amount); - } - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public SpeedEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + //Logger.error(this.getSimpleClassName(), "Speed applied with " + trains + " trains"); + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.percentMod != 0f) { //Stat Percent Modifiers + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + bonus.addFloat(this, amount); + } else { //Stat Modifiers + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + bonus.addFloat(this, amount); + } + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/SpireBlockEffectModifier.java b/src/engine/powers/effectmodifiers/SpireBlockEffectModifier.java index 26dfb368..7cd3620f 100644 --- a/src/engine/powers/effectmodifiers/SpireBlockEffectModifier.java +++ b/src/engine/powers/effectmodifiers/SpireBlockEffectModifier.java @@ -17,23 +17,26 @@ import java.sql.SQLException; public class SpireBlockEffectModifier extends AbstractEffectModifier { - public SpireBlockEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public SpireBlockEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - PlayerBonuses bonus = ac.getBonuses(); - bonus.setBool(this.modType,this.sourceType, true); - } + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + PlayerBonuses bonus = ac.getBonuses(); + bonus.setBool(this.modType, this.sourceType, true); + } - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/StaminaEffectModifier.java b/src/engine/powers/effectmodifiers/StaminaEffectModifier.java index a15d2653..81de332f 100644 --- a/src/engine/powers/effectmodifiers/StaminaEffectModifier.java +++ b/src/engine/powers/effectmodifiers/StaminaEffectModifier.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -44,187 +41,190 @@ import java.util.concurrent.ThreadLocalRandom; public class StaminaEffectModifier extends AbstractEffectModifier { - private DamageType damageType; - - public StaminaEffectModifier(ResultSet rs) throws SQLException { - super(rs); - String damageTypeDB = rs.getString("type"); - try { - this.damageType = DamageType.valueOf(damageTypeDB); - } catch (IllegalArgumentException e) { - Logger.error("DamageType could not be loaded from database. " + "UUID = " + this.UUID - + " value received = '" + damageTypeDB + '\'', e); - } - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - if (awo == null) { - Logger.error( "_applyEffectModifier(): NULL AWO passed in."); - return; - } - - if (effect == null) { - Logger.error( "_applyEffectModifier(): NULL AbstractEffectJob passed in."); - return; - } - - if (!AbstractWorldObject.IsAbstractCharacter(awo)) - return; - AbstractCharacter awoac = (AbstractCharacter) awo; - - float modAmount = 0f; - - // Modify Stamina by percent - if (this.percentMod != 0f) { - float mod = 1f; - if (this.useRampAdd) - mod = (this.percentMod + (this.ramp * trains)) / 100; - else - mod = (this.percentMod * (1 + (this.ramp * trains))) / 100; - modAmount = mod * awoac.getStaminaMax(); - if (awoac.isSit()) - modAmount *= 2.5f; - - //debug for spell damage and atr - if (source.getDebug(16) && source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { - PlayerCharacter pc = (PlayerCharacter) source; - String smsg = "Percent Damage: " + mod * 100 + '%'; - ChatManager.chatSystemInfo(pc, smsg); - } - } - - // Modify Stamina by min/max amount - else if (this.minMod != 0f || this.maxMod != 0f) { - float min = this.minMod; - float max = this.maxMod; - if (this.ramp > 0f) { - float mod = this.ramp * trains; - if (this.useRampAdd) { - min += mod; - max += mod; - } else { - min *= (1 + mod); - max *= (1 + mod); - } - } - if (source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { - PlayerCharacter pc = (PlayerCharacter) source; - - float focus; - CharacterSkill skill = pc.getSkills().get(effect.getPower().getSkillName()); - if (skill == null) - focus = CharacterSkill.getQuickMastery(pc, effect.getPower().getSkillName()); - else - focus = skill.getModifiedAmount(); - //TODO clean up old formulas once new one is verified - // min *= (0.5 + 0.0075 * pc.getStatIntCurrent() + 0.011 * pc.getStatSpiCurrent() + 0.0196 * focus); - // max *= (0.62 + 0.0192 * pc.getStatIntCurrent() + 0.00415 * pc.getStatSpiCurrent() + 0.015 * focus); - float intt = (pc.getStatIntCurrent() >= 1) ? (float)pc.getStatIntCurrent() : 1f; - float spi = (pc.getStatSpiCurrent() >= 1) ? (float)pc.getStatSpiCurrent() : 1f; - // min *= (intt * 0.0045 + 0.055 * (float)Math.sqrt(intt - 0.5) + spi * 0.006 + 0.07 * (float)Math.sqrt(spi - 0.5) + 0.02 * (int)focus); - // max *= (intt * 0.0117 + 0.13 * (float)Math.sqrt(intt - 0.5) + spi * 0.0024 + (float)Math.sqrt(spi - 0.5) * 0.021 + 0.015 * (int)focus); - min = HealthEffectModifier.getMinDamage(min, intt, spi, focus); - max = HealthEffectModifier.getMaxDamage(max, intt, spi, focus); - - //debug for spell damage and atr - if (pc.getDebug(16)) { - String smsg = "Damage: " + (int)Math.abs(min) + " - " + (int)Math.abs(max); - ChatManager.chatSystemInfo(pc, smsg); - } - } - modAmount = calculateDamage(source, awoac, min, max, awo, trains); - PlayerBonuses bonus = source.getBonuses(); - - // Apply any power effect modifiers (such as stances) - if (bonus != null) - modAmount *= (1 + (bonus.getFloatPercentAll(ModType.PowerDamageModifier, SourceType.None))); - } - if (modAmount == 0f) - return; - if (AbstractWorldObject.IsAbstractCharacter(awo)) { - AbstractCharacter ac = (AbstractCharacter) awo; - int powerID = 0, effectID = 0; - String powerName = ""; - if (effect.getPower() != null) { - powerID = effect.getPower().getToken(); - powerName = effect.getPower().getName(); - } - if (effect.getEffect() != null) { - effectID = effect.getEffect().getToken(); - } - - //see if target is immune to heals - if (modAmount > 0f) { - boolean skipImmune = false; - if (effect.getAction().getPowerAction() instanceof DirectDamagePowerAction) { - ArrayList actions = effect.getPower().getActions(); - for (ActionsBase ab : actions) { - AbstractPowerAction apa = ab.getPowerAction(); - if (apa instanceof DamageOverTimePowerAction) - skipImmune = true; - } - } - PlayerBonuses bonus = ac.getBonuses(); - if (!skipImmune && bonus.getFloat(ModType.BlackMantle, SourceType.Heal) >= trains) { - ModifyHealthMsg mhm = new ModifyHealthMsg(source, ac, 0f, 0f, 0f, powerID, powerName, trains, effectID); - mhm.setUnknown03(5); //set target is immune - DispatchMessage.sendToAllInRange(ac, mhm); - - return; - } - } - - ac.modifyStamina(modAmount, source); - - ModifyHealthMsg mhm = new ModifyHealthMsg(source, ac, 0f, 0f, modAmount, powerID, powerName, trains, - effectID); - if (effect instanceof DamageOverTimeJob) - mhm.setOmitFromChat(1); - DispatchMessage.sendToAllInRange(ac, mhm); - } - } - - private float calculateDamage(AbstractCharacter source, AbstractCharacter target, float minDamage, float maxDamage, AbstractWorldObject awo, int trains) { - - // get range between min and max - float range = maxDamage - minDamage; - - // Damage is calculated twice to average a more central point - float damage = ThreadLocalRandom.current().nextFloat() * range; - damage = (damage + (ThreadLocalRandom.current().nextFloat() * range)) / 2; - - // put it back between min and max - damage += minDamage; - - Resists resists = null; - // get resists - if (AbstractWorldObject.IsAbstractCharacter(awo)) { - AbstractCharacter ac = (AbstractCharacter) awo; - resists = ac.getResists(); - } else if (awo.getObjectType().equals(Enum.GameObjectType.Building)) - resists = ((Building) awo).getResists(); - - // calculate resists in if any - if (resists != null) - damage = resists.getResistedDamage(source, target, damageType, damage * -1, trains) * -1; - - if (AbstractWorldObject.IsAbstractCharacter(awo)) { - AbstractCharacter ac = (AbstractCharacter) awo; - if (ac.isSit()) - damage *= 2.5f; // increase damage if sitting - } - - return damage; - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + private DamageType damageType; + + public StaminaEffectModifier(ResultSet rs) throws SQLException { + super(rs); + String damageTypeDB = rs.getString("type"); + try { + this.damageType = DamageType.valueOf(damageTypeDB); + } catch (IllegalArgumentException e) { + Logger.error("DamageType could not be loaded from database. " + "UUID = " + this.UUID + + " value received = '" + damageTypeDB + '\'', e); + } + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + if (awo == null) { + Logger.error("_applyEffectModifier(): NULL AWO passed in."); + return; + } + + if (effect == null) { + Logger.error("_applyEffectModifier(): NULL AbstractEffectJob passed in."); + return; + } + + if (!AbstractWorldObject.IsAbstractCharacter(awo)) + return; + AbstractCharacter awoac = (AbstractCharacter) awo; + + float modAmount = 0f; + + // Modify Stamina by percent + if (this.percentMod != 0f) { + float mod = 1f; + if (this.useRampAdd) + mod = (this.percentMod + (this.ramp * trains)) / 100; + else + mod = (this.percentMod * (1 + (this.ramp * trains))) / 100; + modAmount = mod * awoac.getStaminaMax(); + if (awoac.isSit()) + modAmount *= 2.5f; + + //debug for spell damage and atr + if (source.getDebug(16) && source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { + PlayerCharacter pc = (PlayerCharacter) source; + String smsg = "Percent Damage: " + mod * 100 + '%'; + ChatManager.chatSystemInfo(pc, smsg); + } + } + + // Modify Stamina by min/max amount + else if (this.minMod != 0f || this.maxMod != 0f) { + float min = this.minMod; + float max = this.maxMod; + if (this.ramp > 0f) { + float mod = this.ramp * trains; + if (this.useRampAdd) { + min += mod; + max += mod; + } else { + min *= (1 + mod); + max *= (1 + mod); + } + } + if (source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { + PlayerCharacter pc = (PlayerCharacter) source; + + float focus; + CharacterSkill skill = pc.getSkills().get(effect.getPower().getSkillName()); + if (skill == null) + focus = CharacterSkill.getQuickMastery(pc, effect.getPower().getSkillName()); + else + focus = skill.getModifiedAmount(); + //TODO clean up old formulas once new one is verified + // min *= (0.5 + 0.0075 * pc.getStatIntCurrent() + 0.011 * pc.getStatSpiCurrent() + 0.0196 * focus); + // max *= (0.62 + 0.0192 * pc.getStatIntCurrent() + 0.00415 * pc.getStatSpiCurrent() + 0.015 * focus); + float intt = (pc.getStatIntCurrent() >= 1) ? (float) pc.getStatIntCurrent() : 1f; + float spi = (pc.getStatSpiCurrent() >= 1) ? (float) pc.getStatSpiCurrent() : 1f; + // min *= (intt * 0.0045 + 0.055 * (float)Math.sqrt(intt - 0.5) + spi * 0.006 + 0.07 * (float)Math.sqrt(spi - 0.5) + 0.02 * (int)focus); + // max *= (intt * 0.0117 + 0.13 * (float)Math.sqrt(intt - 0.5) + spi * 0.0024 + (float)Math.sqrt(spi - 0.5) * 0.021 + 0.015 * (int)focus); + min = HealthEffectModifier.getMinDamage(min, intt, spi, focus); + max = HealthEffectModifier.getMaxDamage(max, intt, spi, focus); + + //debug for spell damage and atr + if (pc.getDebug(16)) { + String smsg = "Damage: " + (int) Math.abs(min) + " - " + (int) Math.abs(max); + ChatManager.chatSystemInfo(pc, smsg); + } + } + modAmount = calculateDamage(source, awoac, min, max, awo, trains); + PlayerBonuses bonus = source.getBonuses(); + + // Apply any power effect modifiers (such as stances) + if (bonus != null) + modAmount *= (1 + (bonus.getFloatPercentAll(ModType.PowerDamageModifier, SourceType.None))); + } + if (modAmount == 0f) + return; + if (AbstractWorldObject.IsAbstractCharacter(awo)) { + AbstractCharacter ac = (AbstractCharacter) awo; + int powerID = 0, effectID = 0; + String powerName = ""; + if (effect.getPower() != null) { + powerID = effect.getPower().getToken(); + powerName = effect.getPower().getName(); + } + if (effect.getEffect() != null) { + effectID = effect.getEffect().getToken(); + } + + //see if target is immune to heals + if (modAmount > 0f) { + boolean skipImmune = false; + if (effect.getAction().getPowerAction() instanceof DirectDamagePowerAction) { + ArrayList actions = effect.getPower().getActions(); + for (ActionsBase ab : actions) { + AbstractPowerAction apa = ab.getPowerAction(); + if (apa instanceof DamageOverTimePowerAction) + skipImmune = true; + } + } + PlayerBonuses bonus = ac.getBonuses(); + if (!skipImmune && bonus.getFloat(ModType.BlackMantle, SourceType.Heal) >= trains) { + ModifyHealthMsg mhm = new ModifyHealthMsg(source, ac, 0f, 0f, 0f, powerID, powerName, trains, effectID); + mhm.setUnknown03(5); //set target is immune + DispatchMessage.sendToAllInRange(ac, mhm); + + return; + } + } + + ac.modifyStamina(modAmount, source); + + ModifyHealthMsg mhm = new ModifyHealthMsg(source, ac, 0f, 0f, modAmount, powerID, powerName, trains, + effectID); + if (effect instanceof DamageOverTimeJob) + mhm.setOmitFromChat(1); + DispatchMessage.sendToAllInRange(ac, mhm); + } + } + + private float calculateDamage(AbstractCharacter source, AbstractCharacter target, float minDamage, float maxDamage, AbstractWorldObject awo, int trains) { + + // get range between min and max + float range = maxDamage - minDamage; + + // Damage is calculated twice to average a more central point + float damage = ThreadLocalRandom.current().nextFloat() * range; + damage = (damage + (ThreadLocalRandom.current().nextFloat() * range)) / 2; + + // put it back between min and max + damage += minDamage; + + Resists resists = null; + // get resists + if (AbstractWorldObject.IsAbstractCharacter(awo)) { + AbstractCharacter ac = (AbstractCharacter) awo; + resists = ac.getResists(); + } else if (awo.getObjectType().equals(Enum.GameObjectType.Building)) + resists = ((Building) awo).getResists(); + + // calculate resists in if any + if (resists != null) + damage = resists.getResistedDamage(source, target, damageType, damage * -1, trains) * -1; + + if (AbstractWorldObject.IsAbstractCharacter(awo)) { + AbstractCharacter ac = (AbstractCharacter) awo; + if (ac.isSit()) + damage *= 2.5f; // increase damage if sitting + } + + return damage; + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/StaminaFullEffectModifier.java b/src/engine/powers/effectmodifiers/StaminaFullEffectModifier.java index 1f2ac056..475ce82a 100644 --- a/src/engine/powers/effectmodifiers/StaminaFullEffectModifier.java +++ b/src/engine/powers/effectmodifiers/StaminaFullEffectModifier.java @@ -17,37 +17,40 @@ import java.sql.SQLException; public class StaminaFullEffectModifier extends AbstractEffectModifier { - public StaminaFullEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.percentMod != 0f) { //Stat Percent Modifiers - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - bonus.addFloat(this, amount); - } else { //Stat Modifiers - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - bonus.addFloat(this, amount); - } - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public StaminaFullEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.percentMod != 0f) { //Stat Percent Modifiers + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + bonus.addFloat(this, amount); + } else { //Stat Modifiers + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + bonus.addFloat(this, amount); + } + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/StaminaRecoverRateEffectModifier.java b/src/engine/powers/effectmodifiers/StaminaRecoverRateEffectModifier.java index 11a79d0f..b2847a8c 100644 --- a/src/engine/powers/effectmodifiers/StaminaRecoverRateEffectModifier.java +++ b/src/engine/powers/effectmodifiers/StaminaRecoverRateEffectModifier.java @@ -17,31 +17,34 @@ import java.sql.SQLException; public class StaminaRecoverRateEffectModifier extends AbstractEffectModifier { - public StaminaRecoverRateEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - - //Erection is this right? - amount = amount/100; - bonus.multRegen(this.modType, amount); //positive regen modifiers - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public StaminaRecoverRateEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + + //Erection is this right? + amount = amount / 100; + bonus.multRegen(this.modType, amount); //positive regen modifiers + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/StunnedEffectModifier.java b/src/engine/powers/effectmodifiers/StunnedEffectModifier.java index e1e0918a..0789f3c7 100644 --- a/src/engine/powers/effectmodifiers/StunnedEffectModifier.java +++ b/src/engine/powers/effectmodifiers/StunnedEffectModifier.java @@ -18,30 +18,33 @@ import java.sql.SQLException; public class StunnedEffectModifier extends AbstractEffectModifier { - public StunnedEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - if (ac.getObjectType() == GameObjectType.Mob) { - Mob mob = (Mob) ac; - } - - PlayerBonuses bonus = ac.getBonuses(); - bonus.setBool(this.modType,this.sourceType, true); - ac.cancelOnStun(); - ac.setIsCasting(false); - ac.stopMovement(ac.getLoc()); - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public StunnedEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + if (ac.getObjectType() == GameObjectType.Mob) { + Mob mob = (Mob) ac; + } + + PlayerBonuses bonus = ac.getBonuses(); + bonus.setBool(this.modType, this.sourceType, true); + ac.cancelOnStun(); + ac.setIsCasting(false); + ac.stopMovement(ac.getLoc()); + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/ValueEffectModifier.java b/src/engine/powers/effectmodifiers/ValueEffectModifier.java index 359d1a93..6b68cc83 100644 --- a/src/engine/powers/effectmodifiers/ValueEffectModifier.java +++ b/src/engine/powers/effectmodifiers/ValueEffectModifier.java @@ -20,22 +20,25 @@ import java.sql.SQLException; public class ValueEffectModifier extends AbstractEffectModifier { - public ValueEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public ValueEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { + @Override + public void applyBonus(AbstractCharacter ac, int trains) { - } + } - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/WeaponProcEffectModifier.java b/src/engine/powers/effectmodifiers/WeaponProcEffectModifier.java index 90258c58..5ef4251b 100644 --- a/src/engine/powers/effectmodifiers/WeaponProcEffectModifier.java +++ b/src/engine/powers/effectmodifiers/WeaponProcEffectModifier.java @@ -22,26 +22,29 @@ import java.sql.SQLException; public class WeaponProcEffectModifier extends AbstractEffectModifier { - public WeaponProcEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public WeaponProcEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { + @Override + public void applyBonus(AbstractCharacter ac, int trains) { - } + } - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + @Override + public void applyBonus(Item item, int trains) { + } - public void applyProc(AbstractCharacter ac, AbstractWorldObject target) { - PowersManager.applyPower(ac, target, Vector3fImmutable.ZERO, this.string1, (int)this.percentMod, false); - } + @Override + public void applyBonus(Building building, int trains) { + } + + public void applyProc(AbstractCharacter ac, AbstractWorldObject target) { + PowersManager.applyPower(ac, target, Vector3fImmutable.ZERO, this.string1, (int) this.percentMod, false); + } } diff --git a/src/engine/powers/effectmodifiers/WeaponRangeEffectModifier.java b/src/engine/powers/effectmodifiers/WeaponRangeEffectModifier.java index cc08ed6b..52d21e2a 100644 --- a/src/engine/powers/effectmodifiers/WeaponRangeEffectModifier.java +++ b/src/engine/powers/effectmodifiers/WeaponRangeEffectModifier.java @@ -17,38 +17,41 @@ import java.sql.SQLException; public class WeaponRangeEffectModifier extends AbstractEffectModifier { - public WeaponRangeEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - - } - - @Override - public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; - PlayerBonuses bonus = ac.getBonuses(); - if (this.percentMod != 0f) { //Stat Percent Modifiers - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - bonus.addFloat(this, amount); - } else { //Stat Modifiers - if (this.useRampAdd) - amount = this.minMod + (this.ramp * trains); - else - amount = this.minMod * (1 + (this.ramp * trains)); - bonus.addFloat(this, amount); - } - - } - - @Override - public void applyBonus(Item item, int trains) {} - @Override - public void applyBonus(Building building, int trains) {} + public WeaponRangeEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + + } + + @Override + public void applyBonus(AbstractCharacter ac, int trains) { + Float amount = 0f; + PlayerBonuses bonus = ac.getBonuses(); + if (this.percentMod != 0f) { //Stat Percent Modifiers + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + bonus.addFloat(this, amount); + } else { //Stat Modifiers + if (this.useRampAdd) + amount = this.minMod + (this.ramp * trains); + else + amount = this.minMod * (1 + (this.ramp * trains)); + bonus.addFloat(this, amount); + } + + } + + @Override + public void applyBonus(Item item, int trains) { + } + + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/effectmodifiers/WeaponSpeedEffectModifier.java b/src/engine/powers/effectmodifiers/WeaponSpeedEffectModifier.java index b108e691..b39958e0 100644 --- a/src/engine/powers/effectmodifiers/WeaponSpeedEffectModifier.java +++ b/src/engine/powers/effectmodifiers/WeaponSpeedEffectModifier.java @@ -20,41 +20,42 @@ import java.sql.SQLException; public class WeaponSpeedEffectModifier extends AbstractEffectModifier { - public WeaponSpeedEffectModifier(ResultSet rs) throws SQLException { - super(rs); - } + public WeaponSpeedEffectModifier(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { + @Override + protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) { - } + } - @Override - public void applyBonus(AbstractCharacter ac, int trains) { + @Override + public void applyBonus(AbstractCharacter ac, int trains) { - Float amount = 0f; + Float amount = 0f; - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; + amount = amount / 100; - ac.getBonuses().addFloat(this, amount); - } + ac.getBonuses().addFloat(this, amount); + } - @Override - public void applyBonus(Item item, int trains) { - Float amount = 0f; - if (this.useRampAdd) - amount = this.percentMod + (this.ramp * trains); - else - amount = this.percentMod * (1 + (this.ramp * trains)); - amount = amount/100; - item.addBonus(this, amount); - } + @Override + public void applyBonus(Item item, int trains) { + Float amount = 0f; + if (this.useRampAdd) + amount = this.percentMod + (this.ramp * trains); + else + amount = this.percentMod * (1 + (this.ramp * trains)); + amount = amount / 100; + item.addBonus(this, amount); + } - @Override - public void applyBonus(Building building, int trains) {} + @Override + public void applyBonus(Building building, int trains) { + } } diff --git a/src/engine/powers/poweractions/AbstractPowerAction.java b/src/engine/powers/poweractions/AbstractPowerAction.java index 20911147..5f8f2131 100644 --- a/src/engine/powers/poweractions/AbstractPowerAction.java +++ b/src/engine/powers/poweractions/AbstractPowerAction.java @@ -28,280 +28,279 @@ import java.util.HashMap; public abstract class AbstractPowerAction { - protected PowersBase parent; - protected int UUID; - protected String IDString; - protected String type; - protected boolean isAggressive; - protected long validItemFlags; - - /** - * No Table ID Constructor - */ - public AbstractPowerAction() { - - } - - /** - * ResultSet Constructor - */ - public AbstractPowerAction(ResultSet rs) throws SQLException { - - this.UUID = rs.getInt("ID"); - this.IDString = rs.getString("IDString"); - this.type = rs.getString("type"); - int flags = rs.getInt("flags"); - this.isAggressive = ((flags & 128) != 0) ? true : false; - } - - public AbstractPowerAction( int uUID, String iDString, String type, boolean isAggressive, - long validItemFlags) { - super(); - UUID = uUID; - IDString = iDString; - this.type = type; - this.isAggressive = false; - } - - public static void getAllPowerActions(HashMap powerActions, HashMap powerActionsByID, HashMap effects) { - PreparedStatementShared ps = null; - try { - ps = new PreparedStatementShared("SELECT * FROM static_power_poweraction"); - ResultSet rs = ps.executeQuery(); - String IDString, type; - while (rs.next()) { - AbstractPowerAction apa; - type = rs.getString("type"); - IDString = rs.getString("IDString"); - int token = DbManager.hasher.SBStringHash(IDString); - //cache token, used for applying effects. - PowersManager.ActionTokenByIDString.put(IDString, token); - apa = null; - switch (type) - { - default: - Logger.error("valid type not found for poweraction of ID" + rs.getInt("ID")); - break; - case "ApplyEffect": - apa = new ApplyEffectPowerAction(rs, effects); - break; - case "ApplyEffects": - apa = new ApplyEffectsPowerAction(rs, effects); - break; - case "DeferredPower": - apa = new DeferredPowerPowerAction(rs, effects); - break; - case "DamageOverTime": - apa = new DamageOverTimePowerAction(rs, effects); - break; - case "Peek": - apa = new PeekPowerAction(rs); - break; - case "Charm": - apa = new CharmPowerAction(rs); - break; - case "Fear": - apa = new FearPowerAction(rs); - break; - case "Confusion": - apa = new ConfusionPowerAction(rs); - break; - case "RemoveEffect": - apa = new RemoveEffectPowerAction(rs); - break; - case "Track": - apa = new TrackPowerAction(rs, effects); - break; - case "DirectDamage": - apa = new DirectDamagePowerAction(rs, effects); - break; - case "Transform": - apa = new TransformPowerAction(rs, effects); - break; - case "CreateMob": - apa = new CreateMobPowerAction(rs); - break; - case "Invis": - apa = new InvisPowerAction(rs, effects); - break; - case "ClearNearbyAggro": - apa = new ClearNearbyAggroPowerAction(rs); - break; - case "MobRecall": - apa = new MobRecallPowerAction(rs); - break; - case "SetItemFlag": - apa = new SetItemFlagPowerAction(rs); - break; - case "SimpleDamage": - apa = new SimpleDamagePowerAction(rs); - break; - case "TransferStatOT": - apa = new TransferStatOTPowerAction(rs, effects); - break; - case "TransferStat": - apa = new TransferStatPowerAction(rs, effects); - break; - case "Teleport": - apa = new TeleportPowerAction(rs); - break; - case "TreeChoke": - apa = new TreeChokePowerAction(rs); - break; - case "Block": - apa = new BlockPowerAction(rs); - break; - case "Resurrect": - apa = new ResurrectPowerAction(rs); - break; - case "ClearAggro": - apa = new ClearAggroPowerAction(rs); - break; - case "ClaimMine": - apa = new ClaimMinePowerAction(rs); - break; - case "Recall": - apa = new RecallPowerAction(rs); - break; - case "SpireDisable": - apa = new SpireDisablePowerAction(rs); - break; - case "Steal": - apa = new StealPowerAction(rs); - break; - case "Summon": - apa = new SummonPowerAction(rs); - break; - case "RunegateTeleport": - apa = new RunegateTeleportPowerAction(rs); - break; - case "OpenGate": - apa = new OpenGatePowerAction(rs); - break; - } - powerActions.put(IDString, apa); - powerActionsByID.put(apa.UUID, apa); - apa.validItemFlags = 0; - } - rs.close(); - } catch (Exception e) { - Logger.error( e.toString()); - } finally { - ps.release(); - } - - - - //Add OpenGatePowerAction - AbstractPowerAction openGateAction = new OpenGatePowerAction(5000, "OPENGATE", "OpenGate", false, 0); - powerActions.put("OPENGATE", openGateAction); - powerActionsByID.put(openGateAction.UUID, openGateAction); - } - - public void startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int numTrains, ActionsBase ab, PowersBase pb) { - this._startAction(source, awo, targetLoc, numTrains, ab, pb); - } - - public void startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int numTrains, ActionsBase ab, PowersBase pb, int duration) { - this._startAction(source, awo, targetLoc, numTrains, ab, pb,duration); - } - - protected abstract void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int numTrains, ActionsBase ab, PowersBase pb); - - protected abstract void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int numTrains, ActionsBase ab, PowersBase pb, int duration); - - public void handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int numTrains, ActionsBase ab, PowersBase pb) { - this._handleChant(source, target, targetLoc, numTrains, ab, pb); - } - - protected abstract void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int numTrains, ActionsBase ab, PowersBase pb); - - public int getUUID() { - return this.UUID; - } - - public String getIDString() { - return this.IDString; - } - - // public String getMessageType() { - // return this.type; - // } - - public boolean isAggressive() { - return this.isAggressive; - } - - public PowersBase getParent() { - return this.parent; - } - - public void setParent(PowersBase value) { - this.parent = value; - } - - public void applyEffectForItem(Item item, int trains) { - if (this instanceof ApplyEffectPowerAction) - ((ApplyEffectPowerAction)this)._applyEffectForItem(item, trains); - if (this instanceof ApplyEffectsPowerAction) - ((ApplyEffectsPowerAction)this)._applyEffectForItem(item, trains); - } - public void applyBakedInStatsForItem(Item item, int trains) { - if (this instanceof ApplyEffectPowerAction) - ((ApplyEffectPowerAction)this)._applyBakedInStatsForItem(item, trains); - if (this instanceof ApplyEffectsPowerAction) - ((ApplyEffectsPowerAction)this)._applyBakedInStatsForItem(item, trains); - } - - public EffectsBase getEffectsBase() { - if (this instanceof ApplyEffectPowerAction) - return ((ApplyEffectPowerAction)this).getEffect(); - else if (this instanceof ApplyEffectsPowerAction) - return ((ApplyEffectsPowerAction)this).getEffect(); - return null; - } - - public EffectsBase getEffectsBase2() { - if (this instanceof ApplyEffectsPowerAction) - return ((ApplyEffectsPowerAction)this).getEffect2(); - return null; - } - - public static void loadValidItemFlags(HashMap powerActions) { - PreparedStatementShared ps = null; - try { - ps = new PreparedStatementShared("SELECT * FROM `static_power_effect_allowed_item`"); - ResultSet rs = ps.executeQuery(); - String IDS; - long flags; - while (rs.next()) { - AbstractPowerAction apa; - flags = rs.getLong("flags"); - IDS = rs.getString("IDString"); - if (powerActions.containsKey(IDS)) { - apa = powerActions.get(IDS); - apa.validItemFlags = flags; - } else { - Logger.error("Unable to find PowerAction " + IDS); - continue; - } - } - rs.close(); - } catch (Exception e) { - Logger.error(e.toString()); - } finally { - ps.release(); - } - - } - - //These functions verify a powerAction is valid for an item type - public long getValidItemFlags() { - return this.validItemFlags; - } - - public String getType() { - return type; - } + protected PowersBase parent; + protected int UUID; + protected String IDString; + protected String type; + protected boolean isAggressive; + protected long validItemFlags; + + /** + * No Table ID Constructor + */ + public AbstractPowerAction() { + + } + + /** + * ResultSet Constructor + */ + public AbstractPowerAction(ResultSet rs) throws SQLException { + + this.UUID = rs.getInt("ID"); + this.IDString = rs.getString("IDString"); + this.type = rs.getString("type"); + int flags = rs.getInt("flags"); + this.isAggressive = ((flags & 128) != 0) ? true : false; + } + + public AbstractPowerAction(int uUID, String iDString, String type, boolean isAggressive, + long validItemFlags) { + super(); + UUID = uUID; + IDString = iDString; + this.type = type; + this.isAggressive = false; + } + + public static void getAllPowerActions(HashMap powerActions, HashMap powerActionsByID, HashMap effects) { + PreparedStatementShared ps = null; + try { + ps = new PreparedStatementShared("SELECT * FROM static_power_poweraction"); + ResultSet rs = ps.executeQuery(); + String IDString, type; + while (rs.next()) { + AbstractPowerAction apa; + type = rs.getString("type"); + IDString = rs.getString("IDString"); + int token = DbManager.hasher.SBStringHash(IDString); + //cache token, used for applying effects. + PowersManager.ActionTokenByIDString.put(IDString, token); + apa = null; + switch (type) { + default: + Logger.error("valid type not found for poweraction of ID" + rs.getInt("ID")); + break; + case "ApplyEffect": + apa = new ApplyEffectPowerAction(rs, effects); + break; + case "ApplyEffects": + apa = new ApplyEffectsPowerAction(rs, effects); + break; + case "DeferredPower": + apa = new DeferredPowerPowerAction(rs, effects); + break; + case "DamageOverTime": + apa = new DamageOverTimePowerAction(rs, effects); + break; + case "Peek": + apa = new PeekPowerAction(rs); + break; + case "Charm": + apa = new CharmPowerAction(rs); + break; + case "Fear": + apa = new FearPowerAction(rs); + break; + case "Confusion": + apa = new ConfusionPowerAction(rs); + break; + case "RemoveEffect": + apa = new RemoveEffectPowerAction(rs); + break; + case "Track": + apa = new TrackPowerAction(rs, effects); + break; + case "DirectDamage": + apa = new DirectDamagePowerAction(rs, effects); + break; + case "Transform": + apa = new TransformPowerAction(rs, effects); + break; + case "CreateMob": + apa = new CreateMobPowerAction(rs); + break; + case "Invis": + apa = new InvisPowerAction(rs, effects); + break; + case "ClearNearbyAggro": + apa = new ClearNearbyAggroPowerAction(rs); + break; + case "MobRecall": + apa = new MobRecallPowerAction(rs); + break; + case "SetItemFlag": + apa = new SetItemFlagPowerAction(rs); + break; + case "SimpleDamage": + apa = new SimpleDamagePowerAction(rs); + break; + case "TransferStatOT": + apa = new TransferStatOTPowerAction(rs, effects); + break; + case "TransferStat": + apa = new TransferStatPowerAction(rs, effects); + break; + case "Teleport": + apa = new TeleportPowerAction(rs); + break; + case "TreeChoke": + apa = new TreeChokePowerAction(rs); + break; + case "Block": + apa = new BlockPowerAction(rs); + break; + case "Resurrect": + apa = new ResurrectPowerAction(rs); + break; + case "ClearAggro": + apa = new ClearAggroPowerAction(rs); + break; + case "ClaimMine": + apa = new ClaimMinePowerAction(rs); + break; + case "Recall": + apa = new RecallPowerAction(rs); + break; + case "SpireDisable": + apa = new SpireDisablePowerAction(rs); + break; + case "Steal": + apa = new StealPowerAction(rs); + break; + case "Summon": + apa = new SummonPowerAction(rs); + break; + case "RunegateTeleport": + apa = new RunegateTeleportPowerAction(rs); + break; + case "OpenGate": + apa = new OpenGatePowerAction(rs); + break; + } + powerActions.put(IDString, apa); + powerActionsByID.put(apa.UUID, apa); + apa.validItemFlags = 0; + } + rs.close(); + } catch (Exception e) { + Logger.error(e.toString()); + } finally { + ps.release(); + } + + + //Add OpenGatePowerAction + AbstractPowerAction openGateAction = new OpenGatePowerAction(5000, "OPENGATE", "OpenGate", false, 0); + powerActions.put("OPENGATE", openGateAction); + powerActionsByID.put(openGateAction.UUID, openGateAction); + } + + public static void loadValidItemFlags(HashMap powerActions) { + PreparedStatementShared ps = null; + try { + ps = new PreparedStatementShared("SELECT * FROM `static_power_effect_allowed_item`"); + ResultSet rs = ps.executeQuery(); + String IDS; + long flags; + while (rs.next()) { + AbstractPowerAction apa; + flags = rs.getLong("flags"); + IDS = rs.getString("IDString"); + if (powerActions.containsKey(IDS)) { + apa = powerActions.get(IDS); + apa.validItemFlags = flags; + } else { + Logger.error("Unable to find PowerAction " + IDS); + continue; + } + } + rs.close(); + } catch (Exception e) { + Logger.error(e.toString()); + } finally { + ps.release(); + } + + } + + public void startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int numTrains, ActionsBase ab, PowersBase pb) { + this._startAction(source, awo, targetLoc, numTrains, ab, pb); + } + + public void startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int numTrains, ActionsBase ab, PowersBase pb, int duration) { + this._startAction(source, awo, targetLoc, numTrains, ab, pb, duration); + } + + protected abstract void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int numTrains, ActionsBase ab, PowersBase pb); + + protected abstract void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int numTrains, ActionsBase ab, PowersBase pb, int duration); + + public void handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int numTrains, ActionsBase ab, PowersBase pb) { + this._handleChant(source, target, targetLoc, numTrains, ab, pb); + } + + protected abstract void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int numTrains, ActionsBase ab, PowersBase pb); + + public int getUUID() { + return this.UUID; + } + + // public String getMessageType() { + // return this.type; + // } + + public String getIDString() { + return this.IDString; + } + + public boolean isAggressive() { + return this.isAggressive; + } + + public PowersBase getParent() { + return this.parent; + } + + public void setParent(PowersBase value) { + this.parent = value; + } + + public void applyEffectForItem(Item item, int trains) { + if (this instanceof ApplyEffectPowerAction) + ((ApplyEffectPowerAction) this)._applyEffectForItem(item, trains); + if (this instanceof ApplyEffectsPowerAction) + ((ApplyEffectsPowerAction) this)._applyEffectForItem(item, trains); + } + + public void applyBakedInStatsForItem(Item item, int trains) { + if (this instanceof ApplyEffectPowerAction) + ((ApplyEffectPowerAction) this)._applyBakedInStatsForItem(item, trains); + if (this instanceof ApplyEffectsPowerAction) + ((ApplyEffectsPowerAction) this)._applyBakedInStatsForItem(item, trains); + } + + public EffectsBase getEffectsBase() { + if (this instanceof ApplyEffectPowerAction) + return ((ApplyEffectPowerAction) this).getEffect(); + else if (this instanceof ApplyEffectsPowerAction) + return ((ApplyEffectsPowerAction) this).getEffect(); + return null; + } + + public EffectsBase getEffectsBase2() { + if (this instanceof ApplyEffectsPowerAction) + return ((ApplyEffectsPowerAction) this).getEffect2(); + return null; + } + + //These functions verify a powerAction is valid for an item type + public long getValidItemFlags() { + return this.validItemFlags; + } + + public String getType() { + return type; + } } diff --git a/src/engine/powers/poweractions/ApplyEffectPowerAction.java b/src/engine/powers/poweractions/ApplyEffectPowerAction.java index 1c0b58b0..b7454a5f 100644 --- a/src/engine/powers/poweractions/ApplyEffectPowerAction.java +++ b/src/engine/powers/poweractions/ApplyEffectPowerAction.java @@ -7,9 +7,6 @@ // www.magicbane.com - - - // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -24,7 +21,6 @@ package engine.powers.poweractions; import engine.Enum.GameObjectType; import engine.Enum.ModType; import engine.Enum.SourceType; -import engine.ai.MobileFSM; import engine.gameManager.ChatManager; import engine.jobs.ChantJob; import engine.jobs.DeferredPowerJob; @@ -44,222 +40,223 @@ import java.util.HashMap; public class ApplyEffectPowerAction extends AbstractPowerAction { - private String effectID; - private EffectsBase effect; - private String effectParentID; - private EffectsBase effectParent; - - public ApplyEffectPowerAction(ResultSet rs, HashMap effects) throws SQLException { - super(rs); - this.effectParentID = rs.getString("IDString"); - this.effectParent = effects.get(this.effectParentID); - this.effectID = rs.getString("effectID"); - this.effect = effects.get(this.effectID); - } - - public ApplyEffectPowerAction(ResultSet rs, EffectsBase effect) throws SQLException { - super(rs); - - this.effectID = rs.getString("effectID"); - this.effect = effect; - } - - public String getEffectID() { - return this.effectID; - } - - public EffectsBase getEffect() { - return this.effect; - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (this.effect == null || pb == null || ab == null) { - //TODO log error here - return; - } - - //add schedule job to end it if needed and add effect to pc - int duration = 0; - // if (pb.isChant()) - // duration = (int)pb.getChantDuration() * 1000; - // else - duration = ab.getDuration(trains); - String stackType = ab.getStackType(); - if (stackType.equals("WeaponMove")) { - DeferredPowerJob eff = new DeferredPowerJob(source, awo, stackType, trains, ab, pb, this.effect, this); - if (stackType.equals("IgnoreStack")) - awo.addEffect(Integer.toString(ab.getUUID()), 10000, eff, this.effect, trains); - else - awo.addEffect(stackType, 10000, eff, this.effect, trains); - if (awo.getObjectType().equals(GameObjectType.PlayerCharacter)) - ((PlayerCharacter)awo).setWeaponPower(eff); - this.effect.startEffect(source, awo, trains, eff); - } else { - FinishEffectTimeJob eff = new FinishEffectTimeJob(source, awo, stackType, trains, ab, pb, effect); - - if (blockInvul(pb, source, awo)) { - this.effect.endEffect(source, awo, trains, pb, eff); - return; - } - + private String effectID; + private EffectsBase effect; + private String effectParentID; + private EffectsBase effectParent; + + public ApplyEffectPowerAction(ResultSet rs, HashMap effects) throws SQLException { + super(rs); + this.effectParentID = rs.getString("IDString"); + this.effectParent = effects.get(this.effectParentID); + this.effectID = rs.getString("effectID"); + this.effect = effects.get(this.effectID); + } + + public ApplyEffectPowerAction(ResultSet rs, EffectsBase effect) throws SQLException { + super(rs); + + this.effectID = rs.getString("effectID"); + this.effect = effect; + } + + private static boolean blockInvul(PowersBase pb, AbstractCharacter source, AbstractWorldObject awo) { + if (awo == null || pb == null || source == null) + return false; + + if (source.getObjectUUID() == awo.getObjectUUID()) + return false; + + if (!AbstractWorldObject.IsAbstractCharacter(awo)) + return false; + + AbstractCharacter ac = (AbstractCharacter) awo; + + + return false; + } + + public String getEffectID() { + return this.effectID; + } + + public EffectsBase getEffect() { + return this.effect; + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + if (this.effect == null || pb == null || ab == null) { + //TODO log error here + return; + } + + //add schedule job to end it if needed and add effect to pc + int duration = 0; + // if (pb.isChant()) + // duration = (int)pb.getChantDuration() * 1000; + // else + duration = ab.getDuration(trains); + String stackType = ab.getStackType(); + if (stackType.equals("WeaponMove")) { + DeferredPowerJob eff = new DeferredPowerJob(source, awo, stackType, trains, ab, pb, this.effect, this); + if (stackType.equals("IgnoreStack")) + awo.addEffect(Integer.toString(ab.getUUID()), 10000, eff, this.effect, trains); + else + awo.addEffect(stackType, 10000, eff, this.effect, trains); + if (awo.getObjectType().equals(GameObjectType.PlayerCharacter)) + ((PlayerCharacter) awo).setWeaponPower(eff); + this.effect.startEffect(source, awo, trains, eff); + } else { + FinishEffectTimeJob eff = new FinishEffectTimeJob(source, awo, stackType, trains, ab, pb, effect); + + if (blockInvul(pb, source, awo)) { + this.effect.endEffect(source, awo, trains, pb, eff); + return; + } + // Effect lastEff = awo.getEffects().get(eff.getStackType()); -// +// // if (lastEff != null && lastEff.getPowerToken() == eff.getPowerToken()) // lastEff.cancelJob(true); - if (duration > 0) { - if (stackType.equals("IgnoreStack")) - awo.addEffect(Integer.toString(ab.getUUID()), duration, eff, effect, trains); - else - awo.addEffect(stackType, duration, eff, effect, trains); - } else - awo.applyAllBonuses(); - // //TODO if chant, start cycle - // if (pb.isChant() && source.equals(awo)) { - // ChantJob cj = new ChantJob(source, awo, stackType, trains, ab, pb, effect, eff); - // source.setLastChant((int)(pb.getChantDuration()-2) * 1000, cj); - // eff.setChant(true); - // } - - if (this.effectID.equals("TAUNT")){ - - if (awo != null && awo.getObjectType() == GameObjectType.Mob){ - ((Mob) awo).setCombatTarget(source); - ChatSystemMsg msg = ChatManager.CombatInfo(source, awo); - DispatchMessage.sendToAllInRange(source, msg); - } - } - this.effect.startEffect(source, awo, trains, eff); - } - } - - protected void _applyEffectForItem(Item item, int trains) { - if (item == null || this.effect == null) - return; - item.addEffectNoTimer(Integer.toString(this.effect.getUUID()), this.effect, trains,false); - item.addEffectNoTimer(Integer.toString(this.effectParent.getUUID()), this.effectParent, trains,false); - } - protected void _applyBakedInStatsForItem(Item item, int trains) { - if (item == null) - return; - if (this.effect == null){ - Logger.error( "Unknown Token: EffectBase ID " + this.effectID + '.'); - return; - } - - if (this.effectParent == null){ - Logger.error("Unknown Token: EffectBase ID " + this.effectParentID + '.'); - return; - } - Effect eff = item.addEffectNoTimer(Integer.toString(this.effect.getUUID()), this.effect, trains,false); - Effect eff3 = item.addEffectNoTimer(Integer.toString(this.effectParent.getUUID()), this.effectParent, trains,false); - if (eff != null && eff3 != null){ - eff3.setBakedInStat(true); - item.getEffectNames().add(this.effect.getIDString()); - item.getEffectNames().add(this.effectParent.getIDString()); - } - } - - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (source != null) { - PlayerBonuses bonuses = source.getBonuses(); - - if (bonuses == null) - return; - - boolean noSilence = bonuses.getBool(ModType.Silenced, SourceType.None); - - if (noSilence) - return; - - } - String stackType = ab.stackType; - stackType = stackType.equals("IgnoreStack") ? Integer.toString(ab.getUUID()) : stackType; - - FinishEffectTimeJob eff = new FinishEffectTimeJob(source, target, stackType, trains, ab, pb, effect); - ChantJob cj = new ChantJob(source, target, stackType, trains, ab, pb, effect, eff); - //handle invul - if(pb.getUUID() != 334) - source.setLastChant((int)(pb.getChantDuration()) * 1000, cj); - else - source.setLastChant((int)(pb.getChantDuration()) * 1000, cj); - eff.setChant(true); - } - - private static boolean blockInvul(PowersBase pb, AbstractCharacter source, AbstractWorldObject awo) { - if (awo == null || pb == null || source == null) - return false; - - if (source.getObjectUUID() == awo.getObjectUUID()) - return false; - - if (!AbstractWorldObject.IsAbstractCharacter(awo)) - return false; - - AbstractCharacter ac = (AbstractCharacter) awo; - - - return false; - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int trains, ActionsBase ab, PowersBase pb, int duration) { - if (this.effect == null || pb == null || ab == null) { - //TODO log error here - return; - } - - //add schedule job to end it if needed and add effect to pc - // if (pb.isChant()) - // duration = (int)pb.getChantDuration() * 1000; - // else - - String stackType = ab.getStackType(); - if (stackType.equals("WeaponMove")) { - DeferredPowerJob eff = new DeferredPowerJob(source, awo, stackType, trains, ab, pb, this.effect, this); - if (stackType.equals("IgnoreStack")) - awo.addEffect(Integer.toString(ab.getUUID()), 10000, eff, this.effect, trains); - else - awo.addEffect(stackType, 10000, eff, this.effect, trains); - if (awo.getObjectType().equals(GameObjectType.PlayerCharacter)) - ((PlayerCharacter)awo).setWeaponPower(eff); - this.effect.startEffect(source, awo, trains, eff); - } else { - FinishEffectTimeJob eff = new FinishEffectTimeJob(source, awo, stackType, trains, ab, pb, effect); - - if (blockInvul(pb, source, awo)) { - this.effect.endEffect(source, awo, trains, pb, eff); - return; - } - - if (duration > 0) { - if (stackType.equals("IgnoreStack")) - awo.addEffect(Integer.toString(ab.getUUID()), duration, eff, effect, trains); - else - awo.addEffect(stackType, duration, eff, effect, trains); - } else - awo.applyAllBonuses(); - // //TODO if chant, start cycle - // if (pb.isChant() && source.equals(awo)) { - // ChantJob cj = new ChantJob(source, awo, stackType, trains, ab, pb, effect, eff); - // source.setLastChant((int)(pb.getChantDuration()-2) * 1000, cj); - // eff.setChant(true); - // } - - if (this.effectID.equals("TAUNT")){ - - if (awo != null && awo.getObjectType() == GameObjectType.Mob){ - ((Mob) awo).setCombatTarget(source); - ChatSystemMsg msg = ChatManager.CombatInfo(source, awo); - DispatchMessage.sendToAllInRange(source, msg); - } - } - this.effect.startEffect(source, awo, trains, eff); - } - - } + if (duration > 0) { + if (stackType.equals("IgnoreStack")) + awo.addEffect(Integer.toString(ab.getUUID()), duration, eff, effect, trains); + else + awo.addEffect(stackType, duration, eff, effect, trains); + } else + awo.applyAllBonuses(); + // //TODO if chant, start cycle + // if (pb.isChant() && source.equals(awo)) { + // ChantJob cj = new ChantJob(source, awo, stackType, trains, ab, pb, effect, eff); + // source.setLastChant((int)(pb.getChantDuration()-2) * 1000, cj); + // eff.setChant(true); + // } + + if (this.effectID.equals("TAUNT")) { + + if (awo != null && awo.getObjectType() == GameObjectType.Mob) { + ((Mob) awo).setCombatTarget(source); + ChatSystemMsg msg = ChatManager.CombatInfo(source, awo); + DispatchMessage.sendToAllInRange(source, msg); + } + } + this.effect.startEffect(source, awo, trains, eff); + } + } + + protected void _applyEffectForItem(Item item, int trains) { + if (item == null || this.effect == null) + return; + item.addEffectNoTimer(Integer.toString(this.effect.getUUID()), this.effect, trains, false); + item.addEffectNoTimer(Integer.toString(this.effectParent.getUUID()), this.effectParent, trains, false); + } + + protected void _applyBakedInStatsForItem(Item item, int trains) { + if (item == null) + return; + if (this.effect == null) { + Logger.error("Unknown Token: EffectBase ID " + this.effectID + '.'); + return; + } + + if (this.effectParent == null) { + Logger.error("Unknown Token: EffectBase ID " + this.effectParentID + '.'); + return; + } + Effect eff = item.addEffectNoTimer(Integer.toString(this.effect.getUUID()), this.effect, trains, false); + Effect eff3 = item.addEffectNoTimer(Integer.toString(this.effectParent.getUUID()), this.effectParent, trains, false); + if (eff != null && eff3 != null) { + eff3.setBakedInStat(true); + item.getEffectNames().add(this.effect.getIDString()); + item.getEffectNames().add(this.effectParent.getIDString()); + } + } + + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + if (source != null) { + PlayerBonuses bonuses = source.getBonuses(); + + if (bonuses == null) + return; + + boolean noSilence = bonuses.getBool(ModType.Silenced, SourceType.None); + + if (noSilence) + return; + + } + String stackType = ab.stackType; + stackType = stackType.equals("IgnoreStack") ? Integer.toString(ab.getUUID()) : stackType; + + FinishEffectTimeJob eff = new FinishEffectTimeJob(source, target, stackType, trains, ab, pb, effect); + ChantJob cj = new ChantJob(source, target, stackType, trains, ab, pb, effect, eff); + //handle invul + if (pb.getUUID() != 334) + source.setLastChant((int) (pb.getChantDuration()) * 1000, cj); + else + source.setLastChant((int) (pb.getChantDuration()) * 1000, cj); + eff.setChant(true); + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int trains, ActionsBase ab, PowersBase pb, int duration) { + if (this.effect == null || pb == null || ab == null) { + //TODO log error here + return; + } + + //add schedule job to end it if needed and add effect to pc + // if (pb.isChant()) + // duration = (int)pb.getChantDuration() * 1000; + // else + + String stackType = ab.getStackType(); + if (stackType.equals("WeaponMove")) { + DeferredPowerJob eff = new DeferredPowerJob(source, awo, stackType, trains, ab, pb, this.effect, this); + if (stackType.equals("IgnoreStack")) + awo.addEffect(Integer.toString(ab.getUUID()), 10000, eff, this.effect, trains); + else + awo.addEffect(stackType, 10000, eff, this.effect, trains); + if (awo.getObjectType().equals(GameObjectType.PlayerCharacter)) + ((PlayerCharacter) awo).setWeaponPower(eff); + this.effect.startEffect(source, awo, trains, eff); + } else { + FinishEffectTimeJob eff = new FinishEffectTimeJob(source, awo, stackType, trains, ab, pb, effect); + + if (blockInvul(pb, source, awo)) { + this.effect.endEffect(source, awo, trains, pb, eff); + return; + } + + if (duration > 0) { + if (stackType.equals("IgnoreStack")) + awo.addEffect(Integer.toString(ab.getUUID()), duration, eff, effect, trains); + else + awo.addEffect(stackType, duration, eff, effect, trains); + } else + awo.applyAllBonuses(); + // //TODO if chant, start cycle + // if (pb.isChant() && source.equals(awo)) { + // ChantJob cj = new ChantJob(source, awo, stackType, trains, ab, pb, effect, eff); + // source.setLastChant((int)(pb.getChantDuration()-2) * 1000, cj); + // eff.setChant(true); + // } + + if (this.effectID.equals("TAUNT")) { + + if (awo != null && awo.getObjectType() == GameObjectType.Mob) { + ((Mob) awo).setCombatTarget(source); + ChatSystemMsg msg = ChatManager.CombatInfo(source, awo); + DispatchMessage.sendToAllInRange(source, msg); + } + } + this.effect.startEffect(source, awo, trains, eff); + } + + } } diff --git a/src/engine/powers/poweractions/ApplyEffectsPowerAction.java b/src/engine/powers/poweractions/ApplyEffectsPowerAction.java index 901b34c6..2ef45305 100644 --- a/src/engine/powers/poweractions/ApplyEffectsPowerAction.java +++ b/src/engine/powers/poweractions/ApplyEffectsPowerAction.java @@ -25,100 +25,102 @@ import java.util.HashMap; public class ApplyEffectsPowerAction extends AbstractPowerAction { - private String IDString; - private String effectID; - private String effectID2; - private EffectsBase effect; - private EffectsBase effect2; - private EffectsBase effectParent; - - public ApplyEffectsPowerAction(ResultSet rs, HashMap effects) throws SQLException { - super(rs); - this.IDString = rs.getString("IDString"); - this.effectID = rs.getString("effectID"); - this.effectID2 = rs.getString("effectID2"); - this.effect = effects.get(this.effectID); - this.effect2 = effects.get(this.effectID2); - this.effectParent = effects.get(this.IDString); - - } - - public String getEffectID() { - return this.effectID; - } - - public String getEffectID2() { - return this.effectID2; - } - - public EffectsBase getEffect() { - return this.effect; - } - - public EffectsBase getEffect2() { - return this.effect2; - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - - } - - protected void _applyEffectForItem(Item item, int trains) { - if (item == null || this.effect == null) - return; - item.addEffectNoTimer(Integer.toString(this.effect.getUUID()), this.effect, trains,false); - if (this.effect2 != null) - item.addEffectNoTimer(Integer.toString(this.effect2.getUUID()), this.effect2, trains,false); - item.addEffectNoTimer(Integer.toString(this.effectParent.getUUID()), this.effectParent, trains,false); - } - protected void _applyBakedInStatsForItem(Item item, int trains) { - - if (item == null) - return; - - if (this.effect == null){ - Logger.error( "Unknown Token: EffectBase ID " + this.effectID + '.'); - return; - } - - if (this.effect2 == null){ - Logger.error( "Unknown Token: EffectBase ID " + this.effectID2 + '.'); - return; - } - - if (this.effectParent == null){ - Logger.error( "Unknown Token: EffectBase ID " + this.IDString + '.'); - return; - } - - Effect eff = item.addEffectNoTimer(Integer.toString(this.effect.getUUID()), this.effect, trains,false); - Effect eff2 = item.addEffectNoTimer(Integer.toString(this.effect2.getUUID()), this.effect2, trains,false); - Effect eff3 = item.addEffectNoTimer(Integer.toString(this.effectParent.getUUID()), this.effectParent, trains,false); - - if (eff != null && eff2 != null && eff3 != null){ - eff3.setBakedInStat(true); - item.getEffectNames().add(this.effect.getIDString()); - item.getEffectNames().add(this.effect2.getIDString()); - item.getEffectNames().add(this.effectParent.getIDString()); - } - } - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } - - public String getIDString() { - return IDString; - } - - public void setIDString(String iDString) { - IDString = iDString; - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub - - } + private String IDString; + private String effectID; + private String effectID2; + private EffectsBase effect; + private EffectsBase effect2; + private EffectsBase effectParent; + + public ApplyEffectsPowerAction(ResultSet rs, HashMap effects) throws SQLException { + super(rs); + this.IDString = rs.getString("IDString"); + this.effectID = rs.getString("effectID"); + this.effectID2 = rs.getString("effectID2"); + this.effect = effects.get(this.effectID); + this.effect2 = effects.get(this.effectID2); + this.effectParent = effects.get(this.IDString); + + } + + public String getEffectID() { + return this.effectID; + } + + public String getEffectID2() { + return this.effectID2; + } + + public EffectsBase getEffect() { + return this.effect; + } + + public EffectsBase getEffect2() { + return this.effect2; + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + + } + + protected void _applyEffectForItem(Item item, int trains) { + if (item == null || this.effect == null) + return; + item.addEffectNoTimer(Integer.toString(this.effect.getUUID()), this.effect, trains, false); + if (this.effect2 != null) + item.addEffectNoTimer(Integer.toString(this.effect2.getUUID()), this.effect2, trains, false); + item.addEffectNoTimer(Integer.toString(this.effectParent.getUUID()), this.effectParent, trains, false); + } + + protected void _applyBakedInStatsForItem(Item item, int trains) { + + if (item == null) + return; + + if (this.effect == null) { + Logger.error("Unknown Token: EffectBase ID " + this.effectID + '.'); + return; + } + + if (this.effect2 == null) { + Logger.error("Unknown Token: EffectBase ID " + this.effectID2 + '.'); + return; + } + + if (this.effectParent == null) { + Logger.error("Unknown Token: EffectBase ID " + this.IDString + '.'); + return; + } + + Effect eff = item.addEffectNoTimer(Integer.toString(this.effect.getUUID()), this.effect, trains, false); + Effect eff2 = item.addEffectNoTimer(Integer.toString(this.effect2.getUUID()), this.effect2, trains, false); + Effect eff3 = item.addEffectNoTimer(Integer.toString(this.effectParent.getUUID()), this.effectParent, trains, false); + + if (eff != null && eff2 != null && eff3 != null) { + eff3.setBakedInStat(true); + item.getEffectNames().add(this.effect.getIDString()); + item.getEffectNames().add(this.effect2.getIDString()); + item.getEffectNames().add(this.effectParent.getIDString()); + } + } + + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } + + public String getIDString() { + return IDString; + } + + public void setIDString(String iDString) { + IDString = iDString; + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub + + } } diff --git a/src/engine/powers/poweractions/BlockPowerAction.java b/src/engine/powers/poweractions/BlockPowerAction.java index db395299..0ae43341 100644 --- a/src/engine/powers/poweractions/BlockPowerAction.java +++ b/src/engine/powers/poweractions/BlockPowerAction.java @@ -21,23 +21,23 @@ import java.sql.SQLException; public class BlockPowerAction extends AbstractPowerAction { - public BlockPowerAction(ResultSet rs) throws SQLException { - super(rs); - } + public BlockPowerAction(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + } - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub - } + } } diff --git a/src/engine/powers/poweractions/CharmPowerAction.java b/src/engine/powers/poweractions/CharmPowerAction.java index 4d3b1cde..39afcce7 100644 --- a/src/engine/powers/poweractions/CharmPowerAction.java +++ b/src/engine/powers/poweractions/CharmPowerAction.java @@ -25,49 +25,49 @@ import java.sql.SQLException; public class CharmPowerAction extends AbstractPowerAction { - private int levelCap; - private int levelCapRamp; + private int levelCap; + private int levelCapRamp; - public CharmPowerAction(ResultSet rs) throws SQLException { - super(rs); - this.levelCap = rs.getInt("levelCap"); - this.levelCapRamp = rs.getInt("levelCapRamp"); - } + public CharmPowerAction(ResultSet rs) throws SQLException { + super(rs); + this.levelCap = rs.getInt("levelCap"); + this.levelCapRamp = rs.getInt("levelCapRamp"); + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (source == null || awo == null || !(awo.getObjectType().equals(Enum.GameObjectType.Mob)) || !(source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))) - return; + if (source == null || awo == null || !(awo.getObjectType().equals(Enum.GameObjectType.Mob)) || !(source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))) + return; - PlayerCharacter owner = (PlayerCharacter) source; - ClientConnection origin = owner.getClientConnection(); + PlayerCharacter owner = (PlayerCharacter) source; + ClientConnection origin = owner.getClientConnection(); - if (origin == null) - return; + if (origin == null) + return; - //verify is mob, not pet or guard - Mob mob = (Mob) awo; - if (!mob.isMob()) - return; + //verify is mob, not pet or guard + Mob mob = (Mob) awo; + if (!mob.isMob()) + return; - //make sure mob isn't too high level - int cap = this.levelCap + (this.levelCapRamp * trains); - if (mob.getLevel() > cap && pb.getToken() != 1577464266) - return; + //make sure mob isn't too high level + int cap = this.levelCap + (this.levelCapRamp * trains); + if (mob.getLevel() > cap && pb.getToken() != 1577464266) + return; - //turn mob into pet. - owner.commandSiegeMinion(mob); - } + //turn mob into pet. + owner.commandSiegeMinion(mob); + } - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub - } + } } diff --git a/src/engine/powers/poweractions/ClaimMinePowerAction.java b/src/engine/powers/poweractions/ClaimMinePowerAction.java index c43b5d00..ecb83284 100644 --- a/src/engine/powers/poweractions/ClaimMinePowerAction.java +++ b/src/engine/powers/poweractions/ClaimMinePowerAction.java @@ -22,46 +22,46 @@ import java.sql.SQLException; public class ClaimMinePowerAction extends AbstractPowerAction { - public ClaimMinePowerAction(ResultSet rs) throws SQLException { - super(rs); - } + public ClaimMinePowerAction(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject worldObject, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject worldObject, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (source == null || worldObject == null) - return; + if (source == null || worldObject == null) + return; - if (!(source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))) - return; + if (!(source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))) + return; - PlayerCharacter playerCharacter = (PlayerCharacter) source; + PlayerCharacter playerCharacter = (PlayerCharacter) source; - if (!(worldObject.getObjectType().equals(Enum.GameObjectType.Building))) - return; + if (!(worldObject.getObjectType().equals(Enum.GameObjectType.Building))) + return; - Building mineBuilding = (Building)worldObject; + Building mineBuilding = (Building) worldObject; - if (mineBuilding.getRank() > 0) - return; + if (mineBuilding.getRank() > 0) + return; - Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID()); + Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID()); - if (mine == null) - return; + if (mine == null) + return; - if (mine.claimMine(playerCharacter) == true) - ChatManager.sendSystemMessage( (PlayerCharacter) source, "You successfully claimed this mine.."); - } + if (mine.claimMine(playerCharacter) == true) + ChatManager.sendSystemMessage((PlayerCharacter) source, "You successfully claimed this mine.."); + } - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub - } + } } diff --git a/src/engine/powers/poweractions/ClearAggroPowerAction.java b/src/engine/powers/poweractions/ClearAggroPowerAction.java index 1b02429f..ea9c0f18 100644 --- a/src/engine/powers/poweractions/ClearAggroPowerAction.java +++ b/src/engine/powers/poweractions/ClearAggroPowerAction.java @@ -23,28 +23,27 @@ import java.sql.SQLException; public class ClearAggroPowerAction extends AbstractPowerAction { - public ClearAggroPowerAction(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (awo != null && awo.getObjectType() == GameObjectType.Mob){ - ((Mob)awo).setCombatTarget(null); + public ClearAggroPowerAction(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + if (awo != null && awo.getObjectType() == GameObjectType.Mob) { + ((Mob) awo).setCombatTarget(null); } + } - } + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub - - } + } } diff --git a/src/engine/powers/poweractions/ClearNearbyAggroPowerAction.java b/src/engine/powers/poweractions/ClearNearbyAggroPowerAction.java index af0a0ac7..829fc0be 100644 --- a/src/engine/powers/poweractions/ClearNearbyAggroPowerAction.java +++ b/src/engine/powers/poweractions/ClearNearbyAggroPowerAction.java @@ -22,25 +22,25 @@ import java.sql.SQLException; public class ClearNearbyAggroPowerAction extends AbstractPowerAction { - public ClearNearbyAggroPowerAction(ResultSet rs) throws SQLException { - super(rs); - } + public ClearNearbyAggroPowerAction(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (source.getObjectType() == GameObjectType.Mob){ + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + if (source.getObjectType() == GameObjectType.Mob) { } - } + } - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub - } + } } diff --git a/src/engine/powers/poweractions/ConfusionPowerAction.java b/src/engine/powers/poweractions/ConfusionPowerAction.java index 1c2e1843..ca22c8eb 100644 --- a/src/engine/powers/poweractions/ConfusionPowerAction.java +++ b/src/engine/powers/poweractions/ConfusionPowerAction.java @@ -21,23 +21,23 @@ import java.sql.SQLException; public class ConfusionPowerAction extends AbstractPowerAction { - public ConfusionPowerAction(ResultSet rs) throws SQLException { - super(rs); - } + public ConfusionPowerAction(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + } - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub - } + } } diff --git a/src/engine/powers/poweractions/CreateMobPowerAction.java b/src/engine/powers/poweractions/CreateMobPowerAction.java index 35f894c0..e9823ffd 100644 --- a/src/engine/powers/poweractions/CreateMobPowerAction.java +++ b/src/engine/powers/poweractions/CreateMobPowerAction.java @@ -30,114 +30,112 @@ import java.sql.SQLException; public class CreateMobPowerAction extends AbstractPowerAction { - private int mobID; - private int mobLevel; + private int mobID; + private int mobLevel; - public CreateMobPowerAction(ResultSet rs) throws SQLException { - super(rs); + public CreateMobPowerAction(ResultSet rs) throws SQLException { + super(rs); - this.mobID = rs.getInt("mobID"); - this.mobLevel = rs.getInt("mobLevel"); - } + this.mobID = rs.getInt("mobID"); + this.mobLevel = rs.getInt("mobLevel"); + } - public int getMobID() { - return this.mobID; - } + public int getMobID() { + return this.mobID; + } - public int getMobLevel() { - return this.mobLevel; - } + public int getMobLevel() { + return this.mobLevel; + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (source == null || !(source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))) - return; + if (source == null || !(source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))) + return; - PlayerCharacter owner = (PlayerCharacter) source; - Mob currentPet = owner.getPet(); - Zone seaFloor = ZoneManager.getSeaFloor(); - Guild guild = Guild.getErrantGuild(); - ClientConnection origin = owner.getClientConnection(); + PlayerCharacter owner = (PlayerCharacter) source; + Mob currentPet = owner.getPet(); + Zone seaFloor = ZoneManager.getSeaFloor(); + Guild guild = Guild.getErrantGuild(); + ClientConnection origin = owner.getClientConnection(); - if (seaFloor == null || guild == null || origin == null) - return; + if (seaFloor == null || guild == null || origin == null) + return; - MobBase mobbase = MobBase.getMobBase(mobID); + MobBase mobbase = MobBase.getMobBase(mobID); - if (mobbase == null) { - Logger.error("Attempt to summon pet with null mobbase: " + mobID); - return; - } + if (mobbase == null) { + Logger.error("Attempt to summon pet with null mobbase: " + mobID); + return; + } - if (mobbase.isNecroPet() && owner.inSafeZone()) - return; + if (mobbase.isNecroPet() && owner.inSafeZone()) + return; - //create Pet - Mob pet = Mob.createPet(mobID, guild, seaFloor, owner, (short)mobLevel); + //create Pet + Mob pet = Mob.createPet(mobID, guild, seaFloor, owner, (short) mobLevel); - if(pet.getMobBaseID() == 12021 || pet.getMobBaseID() == 12022) { //is a necro pet - if(currentPet!= null && !currentPet.isNecroPet() && !currentPet.isSiege()) { - DbManager.removeFromCache(currentPet); - WorldGrid.RemoveWorldObject(currentPet); + if (pet.getMobBaseID() == 12021 || pet.getMobBaseID() == 12022) { //is a necro pet + if (currentPet != null && !currentPet.isNecroPet() && !currentPet.isSiege()) { + DbManager.removeFromCache(currentPet); + WorldGrid.RemoveWorldObject(currentPet); currentPet.setCombatTarget(null); - if (currentPet.getParentZone() != null) - currentPet.getParentZone().zoneMobSet.remove(currentPet); + if (currentPet.getParentZone() != null) + currentPet.getParentZone().zoneMobSet.remove(currentPet); - currentPet.playerAgroMap.clear(); + currentPet.playerAgroMap.clear(); - try { - currentPet.clearEffects(); - }catch(Exception e){ - Logger.error(e.getMessage()); - } + try { + currentPet.clearEffects(); + } catch (Exception e) { + Logger.error(e.getMessage()); + } - //currentPet.disableIntelligence(); - }else if (currentPet != null && currentPet.isSiege()){ - currentPet.setMob(); - currentPet.setOwner(null); - currentPet.setCombatTarget(null); + //currentPet.disableIntelligence(); + } else if (currentPet != null && currentPet.isSiege()) { + currentPet.setMob(); + currentPet.setOwner(null); + currentPet.setCombatTarget(null); - if (currentPet.isAlive()) - WorldGrid.updateObject(currentPet); - } - //remove 10th pet - - - NPCManager.spawnNecroPet(owner, pet); + if (currentPet.isAlive()) + WorldGrid.updateObject(currentPet); + } + //remove 10th pet - } - else { //is not a necro pet - if(currentPet != null) { - if(!currentPet.isNecroPet() && !currentPet.isSiege()) { - DbManager.removeFromCache(currentPet); - currentPet.setCombatTarget(null); + + NPCManager.spawnNecroPet(owner, pet); + + } else { //is not a necro pet + if (currentPet != null) { + if (!currentPet.isNecroPet() && !currentPet.isSiege()) { + DbManager.removeFromCache(currentPet); + currentPet.setCombatTarget(null); currentPet.setOwner(null); - WorldGrid.RemoveWorldObject(currentPet); - - currentPet.getParentZone().zoneMobSet.remove(currentPet); - currentPet.playerAgroMap.clear(); - currentPet.clearEffects(); - //currentPet.disableIntelligence(); - } - else { - if (currentPet.isSiege()){ - currentPet.setMob(); - currentPet.setOwner(null); - currentPet.setCombatTarget(null); - - if (currentPet.isAlive()) - WorldGrid.updateObject(currentPet); - } - - } - NPCManager.auditNecroPets(owner); - NPCManager.resetNecroPets(owner); - } - } + WorldGrid.RemoveWorldObject(currentPet); + + currentPet.getParentZone().zoneMobSet.remove(currentPet); + currentPet.playerAgroMap.clear(); + currentPet.clearEffects(); + //currentPet.disableIntelligence(); + } else { + if (currentPet.isSiege()) { + currentPet.setMob(); + currentPet.setOwner(null); + currentPet.setCombatTarget(null); + + if (currentPet.isAlive()) + WorldGrid.updateObject(currentPet); + } + + } + NPCManager.auditNecroPets(owner); + NPCManager.resetNecroPets(owner); + } + } /* if(owner.getPet() != null) { if(owner.getPet().getMobBaseID() != 12021 && owner.getPet().getMobBaseID() != 12022) { //if not a necro pet, remove pet @@ -152,22 +150,22 @@ public class CreateMobPowerAction extends AbstractPowerAction { } }*/ - // if (mobID == 12021 || mobID == 12022) //Necro Pets - // pet.setPet(owner, true); - owner.setPet(pet); - PetMsg pm = new PetMsg(5, pet); - Dispatch dispatch = Dispatch.borrow(owner, pm); - DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - } + // if (mobID == 12021 || mobID == 12022) //Necro Pets + // pet.setPet(owner, true); + owner.setPet(pet); + PetMsg pm = new PetMsg(5, pet); + Dispatch dispatch = Dispatch.borrow(owner, pm); + DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + } - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub - } + } } diff --git a/src/engine/powers/poweractions/DamageOverTimePowerAction.java b/src/engine/powers/poweractions/DamageOverTimePowerAction.java index 033f9b2d..53d060d7 100644 --- a/src/engine/powers/poweractions/DamageOverTimePowerAction.java +++ b/src/engine/powers/poweractions/DamageOverTimePowerAction.java @@ -24,62 +24,62 @@ import java.util.HashMap; public class DamageOverTimePowerAction extends AbstractPowerAction { - private String effectID; - private int numIterations; - private EffectsBase effect; - - public DamageOverTimePowerAction(ResultSet rs, HashMap effects) throws SQLException { - super(rs); - - this.effectID = rs.getString("effectID"); - this.numIterations = rs.getInt("numIterations"); - this.effect = effects.get(this.effectID); - } - - public String getEffectID() { - return this.effectID; - } - - public int getNumIterations() { - return this.numIterations; - } - - public EffectsBase getEffect() { - return this.effect; - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (this.effect == null || pb == null || ab == null) { - //TODO log error here - return; - } - //add schedule job to end it if needed and add effect to pc - int duration = ab.getDuration(trains); - String stackType = ab.getStackType(); - DamageOverTimeJob eff = new DamageOverTimeJob(source, awo, stackType, trains, ab, pb, this.effect, this); - int tick = eff.getTickLength(); - if (duration > 0) { - if (stackType.equals("IgnoreStack")) - awo.addEffect(Integer.toString(ab.getUUID()), eff.getTickLength(), eff, this.effect, trains); - else - awo.addEffect(stackType, tick, eff, this.effect, trains); - } - - //start effect icon for client. Skip applying dot until first iteration. - eff.setSkipApplyEffect(true); - this.effect.startEffect(source, awo, trains, eff); - eff.setSkipApplyEffect(false); - } - - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub - - } + private String effectID; + private int numIterations; + private EffectsBase effect; + + public DamageOverTimePowerAction(ResultSet rs, HashMap effects) throws SQLException { + super(rs); + + this.effectID = rs.getString("effectID"); + this.numIterations = rs.getInt("numIterations"); + this.effect = effects.get(this.effectID); + } + + public String getEffectID() { + return this.effectID; + } + + public int getNumIterations() { + return this.numIterations; + } + + public EffectsBase getEffect() { + return this.effect; + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + if (this.effect == null || pb == null || ab == null) { + //TODO log error here + return; + } + //add schedule job to end it if needed and add effect to pc + int duration = ab.getDuration(trains); + String stackType = ab.getStackType(); + DamageOverTimeJob eff = new DamageOverTimeJob(source, awo, stackType, trains, ab, pb, this.effect, this); + int tick = eff.getTickLength(); + if (duration > 0) { + if (stackType.equals("IgnoreStack")) + awo.addEffect(Integer.toString(ab.getUUID()), eff.getTickLength(), eff, this.effect, trains); + else + awo.addEffect(stackType, tick, eff, this.effect, trains); + } + + //start effect icon for client. Skip applying dot until first iteration. + eff.setSkipApplyEffect(true); + this.effect.startEffect(source, awo, trains, eff); + eff.setSkipApplyEffect(false); + } + + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub + + } } diff --git a/src/engine/powers/poweractions/DeferredPowerPowerAction.java b/src/engine/powers/poweractions/DeferredPowerPowerAction.java index d6cdabb9..5d575f70 100644 --- a/src/engine/powers/poweractions/DeferredPowerPowerAction.java +++ b/src/engine/powers/poweractions/DeferredPowerPowerAction.java @@ -26,70 +26,70 @@ import java.util.HashMap; public class DeferredPowerPowerAction extends AbstractPowerAction { - private String effectID; - private String deferedPowerID; - private EffectsBase effect; - // private EffectsBase deferedPower; - - public DeferredPowerPowerAction(ResultSet rs, HashMap effects) throws SQLException { - super(rs); - - this.effectID = rs.getString("effectID"); - this.deferedPowerID = rs.getString("deferredPowerID"); - this.effect = effects.get(this.effectID); - } - - public String getEffectID() { - return this.effectID; - } - - public String getDeferredPowerID() { - return this.deferedPowerID; - } - - public EffectsBase getEffect() { - return this.effect; - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (this.effect == null || pb == null || ab == null) { - //TODO log error here - return; - } - - //add schedule job to end it if needed and add effect to pc - - String stackType = ab.getStackType(); - DeferredPowerJob eff = new DeferredPowerJob(source, awo, stackType, trains, ab, pb, this.effect, this); - if (stackType.equals("IgnoreStack")) - awo.addEffect(Integer.toString(ab.getUUID()), 10000, eff, this.effect, trains); - else - awo.addEffect(stackType, 10000, eff, this.effect, trains); - - switch (awo.getObjectType()){ - case PlayerCharacter: - ((PlayerCharacter)awo).setWeaponPower(eff); - break; - case Mob: - ((Mob)awo).setWeaponPower(eff); - break; - default: - break; - } - - - this.effect.startEffect(source, awo, trains, eff); - } - - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub - - } + private String effectID; + private String deferedPowerID; + private EffectsBase effect; + // private EffectsBase deferedPower; + + public DeferredPowerPowerAction(ResultSet rs, HashMap effects) throws SQLException { + super(rs); + + this.effectID = rs.getString("effectID"); + this.deferedPowerID = rs.getString("deferredPowerID"); + this.effect = effects.get(this.effectID); + } + + public String getEffectID() { + return this.effectID; + } + + public String getDeferredPowerID() { + return this.deferedPowerID; + } + + public EffectsBase getEffect() { + return this.effect; + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + if (this.effect == null || pb == null || ab == null) { + //TODO log error here + return; + } + + //add schedule job to end it if needed and add effect to pc + + String stackType = ab.getStackType(); + DeferredPowerJob eff = new DeferredPowerJob(source, awo, stackType, trains, ab, pb, this.effect, this); + if (stackType.equals("IgnoreStack")) + awo.addEffect(Integer.toString(ab.getUUID()), 10000, eff, this.effect, trains); + else + awo.addEffect(stackType, 10000, eff, this.effect, trains); + + switch (awo.getObjectType()) { + case PlayerCharacter: + ((PlayerCharacter) awo).setWeaponPower(eff); + break; + case Mob: + ((Mob) awo).setWeaponPower(eff); + break; + default: + break; + } + + + this.effect.startEffect(source, awo, trains, eff); + } + + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub + + } } diff --git a/src/engine/powers/poweractions/DirectDamagePowerAction.java b/src/engine/powers/poweractions/DirectDamagePowerAction.java index 955ea6a9..4c670312 100644 --- a/src/engine/powers/poweractions/DirectDamagePowerAction.java +++ b/src/engine/powers/poweractions/DirectDamagePowerAction.java @@ -25,69 +25,69 @@ import java.util.HashMap; public class DirectDamagePowerAction extends AbstractPowerAction { - private String effectID; - private EffectsBase effect; - - public DirectDamagePowerAction(ResultSet rs, HashMap effects) throws SQLException { - super(rs); - - this.effectID = rs.getString("effectID"); - this.effect = effects.get(this.effectID); - } - - public String getEffectID() { - return this.effectID; - } - - public EffectsBase getEffect() { - return this.effect; - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (this.effect == null || pb == null || ab == null) { - //TODO log error here - return; - } - - //add schedule job to end it if needed and add effect to pc - int duration = ab.getDuration(trains); - String stackType = ab.getStackType(); - FinishEffectTimeJob eff = new FinishEffectTimeJob(source, awo, stackType, trains, ab, pb, this.effect); - eff.setSkipSendEffect(true); - if (duration > 0) { - if (stackType.equals("IgnoreStack")) - awo.addEffect(Integer.toString(ab.getUUID()), duration, eff, this.effect, trains); - else - awo.addEffect(stackType, duration, eff, this.effect, trains); - } - - // //if chant, start cycle - // if (pb.isChant() && targetLoc.x != 0f && targetLoc.z != 0f) { - // PersistentAoeJob paoe = new PersistentAoeJob(source, stackType, trains, ab, pb, effect, eff, targetLoc); - // source.addPersistantAoe(stackType, (int)(pb.getChantDuration() * 1000), paoe, effect, trains); - // eff.setChant(true); - // } - - this.effect.startEffect(source, awo, trains, eff); - } - - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - String stackType = ab.getStackType(); - stackType = stackType.equals("IgnoreStack") ? Integer.toString(ab.getUUID()) : stackType; - FinishEffectTimeJob eff = new FinishEffectTimeJob(source, target, stackType, trains, ab, pb, this.effect); - if (targetLoc.x != 0f && targetLoc.z != 0f) { - PersistentAoeJob paoe = new PersistentAoeJob(source,target, stackType, trains, ab, pb, effect, eff, targetLoc); - source.addPersistantAoe(stackType, (int)(pb.getChantDuration() * 1000), paoe, effect, trains); - eff.setChant(true); - } - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub - - } + private String effectID; + private EffectsBase effect; + + public DirectDamagePowerAction(ResultSet rs, HashMap effects) throws SQLException { + super(rs); + + this.effectID = rs.getString("effectID"); + this.effect = effects.get(this.effectID); + } + + public String getEffectID() { + return this.effectID; + } + + public EffectsBase getEffect() { + return this.effect; + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + if (this.effect == null || pb == null || ab == null) { + //TODO log error here + return; + } + + //add schedule job to end it if needed and add effect to pc + int duration = ab.getDuration(trains); + String stackType = ab.getStackType(); + FinishEffectTimeJob eff = new FinishEffectTimeJob(source, awo, stackType, trains, ab, pb, this.effect); + eff.setSkipSendEffect(true); + if (duration > 0) { + if (stackType.equals("IgnoreStack")) + awo.addEffect(Integer.toString(ab.getUUID()), duration, eff, this.effect, trains); + else + awo.addEffect(stackType, duration, eff, this.effect, trains); + } + + // //if chant, start cycle + // if (pb.isChant() && targetLoc.x != 0f && targetLoc.z != 0f) { + // PersistentAoeJob paoe = new PersistentAoeJob(source, stackType, trains, ab, pb, effect, eff, targetLoc); + // source.addPersistantAoe(stackType, (int)(pb.getChantDuration() * 1000), paoe, effect, trains); + // eff.setChant(true); + // } + + this.effect.startEffect(source, awo, trains, eff); + } + + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + String stackType = ab.getStackType(); + stackType = stackType.equals("IgnoreStack") ? Integer.toString(ab.getUUID()) : stackType; + FinishEffectTimeJob eff = new FinishEffectTimeJob(source, target, stackType, trains, ab, pb, this.effect); + if (targetLoc.x != 0f && targetLoc.z != 0f) { + PersistentAoeJob paoe = new PersistentAoeJob(source, target, stackType, trains, ab, pb, effect, eff, targetLoc); + source.addPersistantAoe(stackType, (int) (pb.getChantDuration() * 1000), paoe, effect, trains); + eff.setChant(true); + } + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub + + } } diff --git a/src/engine/powers/poweractions/FearPowerAction.java b/src/engine/powers/poweractions/FearPowerAction.java index 23c41123..2ddcb504 100644 --- a/src/engine/powers/poweractions/FearPowerAction.java +++ b/src/engine/powers/poweractions/FearPowerAction.java @@ -26,51 +26,51 @@ import java.sql.SQLException; public class FearPowerAction extends AbstractPowerAction { - private int levelCap; - private int levelCapRamp; + private int levelCap; + private int levelCapRamp; - public FearPowerAction(ResultSet rs) throws SQLException { - super(rs); - this.levelCap = rs.getInt("levelCap"); - this.levelCapRamp = rs.getInt("levelCapRamp"); - } + public FearPowerAction(ResultSet rs) throws SQLException { + super(rs); + this.levelCap = rs.getInt("levelCap"); + this.levelCapRamp = rs.getInt("levelCapRamp"); + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (source == null || awo == null || !(awo.getObjectType().equals(Enum.GameObjectType.Mob)) || !(source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))) - return; + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + if (source == null || awo == null || !(awo.getObjectType().equals(Enum.GameObjectType.Mob)) || !(source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))) + return; - PlayerCharacter owner = (PlayerCharacter) source; - ClientConnection origin = owner.getClientConnection(); - if (origin == null) - return; + PlayerCharacter owner = (PlayerCharacter) source; + ClientConnection origin = owner.getClientConnection(); + if (origin == null) + return; - //verify is mob, not pet or guard - Mob mob = (Mob) awo; - if (!mob.isMob()) - return; + //verify is mob, not pet or guard + Mob mob = (Mob) awo; + if (!mob.isMob()) + return; - //make sure mob isn't too high level - int cap = this.levelCap + (this.levelCapRamp * trains); - if (mob.getLevel() > cap || mob.getLevel() > 79) - return; + //make sure mob isn't too high level + int cap = this.levelCap + (this.levelCapRamp * trains); + if (mob.getLevel() > cap || mob.getLevel() > 79) + return; - //Apply fear to mob - int duration = 10 + ((int)(trains * 0.5)); - String stackType = ab.getStackType(); - EndFearJob efj = new EndFearJob(source, awo, stackType, trains, ab, pb, null); - ((Mob)awo).setFearedObject(source); - JobScheduler.getInstance().scheduleJob(efj, duration * 1000); - } + //Apply fear to mob + int duration = 10 + ((int) (trains * 0.5)); + String stackType = ab.getStackType(); + EndFearJob efj = new EndFearJob(source, awo, stackType, trains, ab, pb, null); + ((Mob) awo).setFearedObject(source); + JobScheduler.getInstance().scheduleJob(efj, duration * 1000); + } - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub - } + } } diff --git a/src/engine/powers/poweractions/InvisPowerAction.java b/src/engine/powers/poweractions/InvisPowerAction.java index cade11fc..f213da91 100644 --- a/src/engine/powers/poweractions/InvisPowerAction.java +++ b/src/engine/powers/poweractions/InvisPowerAction.java @@ -24,55 +24,55 @@ import java.util.HashMap; public class InvisPowerAction extends AbstractPowerAction { - private String effectID; - private EffectsBase effect; - - public InvisPowerAction(ResultSet rs, HashMap effects) throws SQLException { - super(rs); - - this.effectID = rs.getString("effectID"); - this.effect = effects.get(this.effectID); - } - - public String getEffectID() { - return this.effectID; - } - - public EffectsBase getEffect() { - return this.effect; - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (this.effect == null || pb == null || ab == null) { - //TODO log error here - return; - } - - // if (this.effect.ignoreMod()) - // trains = 50; //set above see invis for safe mode and csr-invis - - //add schedule job to end it if needed and add effect to pc - int duration = ab.getDuration(trains); - String stackType = ab.getStackType(); - FinishEffectTimeJob eff = new FinishEffectTimeJob(source, awo, stackType, trains, ab, pb, this.effect); - if (duration > 0) { - if (stackType.equals("IgnoreStack")) - awo.addEffect(Integer.toString(ab.getUUID()), duration, eff, this.effect, trains); - else - awo.addEffect(stackType, duration, eff, this.effect, trains); - } - this.effect.startEffect(source, awo, trains, eff); - } - - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub - - } + private String effectID; + private EffectsBase effect; + + public InvisPowerAction(ResultSet rs, HashMap effects) throws SQLException { + super(rs); + + this.effectID = rs.getString("effectID"); + this.effect = effects.get(this.effectID); + } + + public String getEffectID() { + return this.effectID; + } + + public EffectsBase getEffect() { + return this.effect; + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + if (this.effect == null || pb == null || ab == null) { + //TODO log error here + return; + } + + // if (this.effect.ignoreMod()) + // trains = 50; //set above see invis for safe mode and csr-invis + + //add schedule job to end it if needed and add effect to pc + int duration = ab.getDuration(trains); + String stackType = ab.getStackType(); + FinishEffectTimeJob eff = new FinishEffectTimeJob(source, awo, stackType, trains, ab, pb, this.effect); + if (duration > 0) { + if (stackType.equals("IgnoreStack")) + awo.addEffect(Integer.toString(ab.getUUID()), duration, eff, this.effect, trains); + else + awo.addEffect(stackType, duration, eff, this.effect, trains); + } + this.effect.startEffect(source, awo, trains, eff); + } + + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub + + } } diff --git a/src/engine/powers/poweractions/MobRecallPowerAction.java b/src/engine/powers/poweractions/MobRecallPowerAction.java index f71ad1b3..8b25c029 100644 --- a/src/engine/powers/poweractions/MobRecallPowerAction.java +++ b/src/engine/powers/poweractions/MobRecallPowerAction.java @@ -10,7 +10,6 @@ package engine.powers.poweractions; import engine.Enum.GameObjectType; -import engine.ai.MobileFSM; import engine.gameManager.MovementManager; import engine.math.Vector3fImmutable; import engine.objects.AbstractCharacter; @@ -25,37 +24,37 @@ import java.sql.SQLException; public class MobRecallPowerAction extends AbstractPowerAction { - public MobRecallPowerAction(ResultSet rs) throws SQLException { - super(rs); - } + public MobRecallPowerAction(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (!AbstractWorldObject.IsAbstractCharacter(awo) || source == null) - return; - AbstractCharacter awoac = (AbstractCharacter)awo; + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + if (!AbstractWorldObject.IsAbstractCharacter(awo) || source == null) + return; + AbstractCharacter awoac = (AbstractCharacter) awo; - if (awo.getObjectType() != GameObjectType.Mob) - return; + if (awo.getObjectType() != GameObjectType.Mob) + return; - - MovementManager.translocate(awoac,awoac.getBindLoc(), null); - if (awoac.getObjectType() == GameObjectType.Mob){ - //MobileFSM.setAwake((Mob)awoac,true); - ((Mob)awoac).setCombatTarget(null); - } + MovementManager.translocate(awoac, awoac.getBindLoc(), null); + if (awoac.getObjectType() == GameObjectType.Mob) { + //MobileFSM.setAwake((Mob)awoac,true); + ((Mob) awoac).setCombatTarget(null); + } - } - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } - } + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub + + } } diff --git a/src/engine/powers/poweractions/OpenGatePowerAction.java b/src/engine/powers/poweractions/OpenGatePowerAction.java index 809bed5a..76ed8bfa 100644 --- a/src/engine/powers/poweractions/OpenGatePowerAction.java +++ b/src/engine/powers/poweractions/OpenGatePowerAction.java @@ -26,99 +26,99 @@ import java.sql.SQLException; public class OpenGatePowerAction extends AbstractPowerAction { - /** - * ResultSet Constructor - */ - public OpenGatePowerAction(ResultSet rs) throws SQLException { - super(rs); - } + /** + * ResultSet Constructor + */ + public OpenGatePowerAction(ResultSet rs) throws SQLException { + super(rs); + } - public OpenGatePowerAction(int uUID, String iDString, String type, boolean isAggressive, long validItemFlags) { - super(uUID, iDString, type, isAggressive, validItemFlags); - // TODO Auto-generated constructor stub - } + public OpenGatePowerAction(int uUID, String iDString, String type, boolean isAggressive, long validItemFlags) { + super(uUID, iDString, type, isAggressive, validItemFlags); + // TODO Auto-generated constructor stub + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - - if (awo.getObjectType().equals(GameObjectType.Building) == false) - return; - Building targetBuilding = (Building) awo; - int token; + if (awo.getObjectType().equals(GameObjectType.Building) == false) + return; - // Sanity check. + Building targetBuilding = (Building) awo; + int token; - if (source == null || awo == null || !(awo.getObjectType().equals(Enum.GameObjectType.Building)) || pb == null) - return; + // Sanity check. - // Make sure building has a blueprint + if (source == null || awo == null || !(awo.getObjectType().equals(Enum.GameObjectType.Building)) || pb == null) + return; - if (targetBuilding.getBlueprintUUID() == 0) - return; + // Make sure building has a blueprint - // Make sure building is actually a runegate. + if (targetBuilding.getBlueprintUUID() == 0) + return; - if (targetBuilding.getBlueprint().getBuildingGroup() != BuildingGroup.RUNEGATE) - return; + // Make sure building is actually a runegate. - // Which portal was opened? + if (targetBuilding.getBlueprint().getBuildingGroup() != BuildingGroup.RUNEGATE) + return; - token = pb.getToken(); - PortalType portalType = PortalType.AIR; + // Which portal was opened? - switch (token) { - case 428937084: //Death Gate - portalType = PortalType.OBLIV; - break; + token = pb.getToken(); + PortalType portalType = PortalType.AIR; - case 429756284: //Chaos Gate - portalType = PortalType.CHAOS; - break; + switch (token) { + case 428937084: //Death Gate + portalType = PortalType.OBLIV; + break; - case 429723516: //Khar Gate - portalType = PortalType.MERCHANT; - break; + case 429756284: //Chaos Gate + portalType = PortalType.CHAOS; + break; - case 429559676: //Spirit Gate - portalType = PortalType.SPIRIT; - break; + case 429723516: //Khar Gate + portalType = PortalType.MERCHANT; + break; - case 429592444: //Water Gate - portalType = PortalType.WATER; - break; + case 429559676: //Spirit Gate + portalType = PortalType.SPIRIT; + break; - case 429428604: //Fire Gate - portalType = PortalType.FIRE; - break; + case 429592444: //Water Gate + portalType = PortalType.WATER; + break; - case 429526908: //Air Gate - portalType = PortalType.AIR; - break; + case 429428604: //Fire Gate + portalType = PortalType.FIRE; + break; - case 429625212: //Earth Gate - portalType = PortalType.EARTH; - break; + case 429526908: //Air Gate + portalType = PortalType.AIR; + break; - default: - } + case 429625212: //Earth Gate + portalType = PortalType.EARTH; + break; - // Which runegate was clicked on? + default: + } - Runegate runeGate = Runegate._runegates.get(targetBuilding.getObjectUUID()); - runeGate.activatePortal(portalType); + // Which runegate was clicked on? - } + Runegate runeGate = Runegate._runegates.get(targetBuilding.getObjectUUID()); + runeGate.activatePortal(portalType); - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } - } + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub + + } } diff --git a/src/engine/powers/poweractions/PeekPowerAction.java b/src/engine/powers/poweractions/PeekPowerAction.java index 289bc523..824e58dd 100644 --- a/src/engine/powers/poweractions/PeekPowerAction.java +++ b/src/engine/powers/poweractions/PeekPowerAction.java @@ -26,112 +26,111 @@ import java.util.concurrent.ThreadLocalRandom; public class PeekPowerAction extends AbstractPowerAction { - public PeekPowerAction(ResultSet rs) throws SQLException { - super(rs); - } + public PeekPowerAction(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + protected static boolean peekSuccess(AbstractCharacter pc, AbstractWorldObject awo) { + if (pc == null || awo == null || !AbstractWorldObject.IsAbstractCharacter(awo) || pc.getPowers() == null) + return false; - if (source == null || awo == null || !(source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))) - return; + int levelDif = pc.getLevel() - ((AbstractCharacter) awo).getLevel(); - PlayerCharacter pc = null; - if (source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) - pc = (PlayerCharacter) source; + if (!pc.getPowers().containsKey(429494332)) + return false; - AbstractCharacter target = null; - if (AbstractWorldObject.IsAbstractCharacter(awo)) - target = (AbstractCharacter) awo; + CharacterPower cp = pc.getPowers().get(429494332); + int trains = cp.getTotalTrains(); - //test probability of successful peek - boolean peekSuccess = peekSuccess(source, awo); - if (peekSuccess) { - ChatManager.chatPeekSteal(pc, target, null, true, peekDetect(source, awo), -1); - } else { - ChatManager.chatPeekSteal(pc, target, null, false, false, -1); - return; - } + float chance = 30 + (trains * 1.5f) + levelDif; + chance = (chance < 5f) ? 5f : chance; + chance = (chance > 95f) ? 95f : chance; - LootWindowResponseMsg lwrm = null; + float roll = ThreadLocalRandom.current().nextFloat() * 100f; - if (awo.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { + return roll < chance; - PlayerCharacter tar = (PlayerCharacter)awo; + } - if (!tar.isAlive()) - return; + protected static boolean peekDetect(AbstractCharacter pc, AbstractWorldObject awo) { + if (pc == null || awo == null || !AbstractWorldObject.IsAbstractCharacter(awo) || pc.getPowers() == null) + return false; - lwrm = new LootWindowResponseMsg(tar.getObjectType().ordinal(), tar.getObjectUUID(), tar.getInventory(true)); - } else if (awo.getObjectType().equals(Enum.GameObjectType.Mob)) { + int levelDif = pc.getLevel() - ((AbstractCharacter) awo).getLevel(); - Mob tar = (Mob) awo; + if (!pc.getPowers().containsKey(429494332)) + return false; - if (!tar.isAlive()) - return; + CharacterPower cp = pc.getPowers().get(429494332); + int trains = cp.getTotalTrains(); - lwrm = new LootWindowResponseMsg(tar.getObjectType().ordinal(), tar.getObjectUUID(), tar.getInventory(true)); - } - if (lwrm == null) - return; + // check if peek is detected + float chance = 30 + (40 - trains) * 1.5f - levelDif; + chance = (chance < 5f) ? 5f : chance; + chance = (chance > 95f) ? 95f : chance; - Dispatch dispatch = Dispatch.borrow(pc, lwrm); - DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - } + float roll = ThreadLocalRandom.current().nextFloat() * 100f; + return roll < chance; - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + } - protected static boolean peekSuccess(AbstractCharacter pc, AbstractWorldObject awo) { - if (pc == null || awo == null || !AbstractWorldObject.IsAbstractCharacter(awo) || pc.getPowers() == null) - return false; + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - int levelDif = pc.getLevel() - ((AbstractCharacter)awo).getLevel(); + if (source == null || awo == null || !(source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))) + return; - if (!pc.getPowers().containsKey(429494332)) - return false; + PlayerCharacter pc = null; + if (source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) + pc = (PlayerCharacter) source; - CharacterPower cp = pc.getPowers().get(429494332); - int trains = cp.getTotalTrains(); + AbstractCharacter target = null; + if (AbstractWorldObject.IsAbstractCharacter(awo)) + target = (AbstractCharacter) awo; - float chance = 30 + (trains * 1.5f) + levelDif; - chance = (chance < 5f) ? 5f : chance; - chance = (chance > 95f) ? 95f : chance; + //test probability of successful peek + boolean peekSuccess = peekSuccess(source, awo); + if (peekSuccess) { + ChatManager.chatPeekSteal(pc, target, null, true, peekDetect(source, awo), -1); + } else { + ChatManager.chatPeekSteal(pc, target, null, false, false, -1); + return; + } - float roll = ThreadLocalRandom.current().nextFloat() * 100f; + LootWindowResponseMsg lwrm = null; - return roll < chance; + if (awo.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { - } + PlayerCharacter tar = (PlayerCharacter) awo; + if (!tar.isAlive()) + return; - protected static boolean peekDetect(AbstractCharacter pc, AbstractWorldObject awo) { - if (pc == null || awo == null || !AbstractWorldObject.IsAbstractCharacter(awo) || pc.getPowers() == null) - return false; + lwrm = new LootWindowResponseMsg(tar.getObjectType().ordinal(), tar.getObjectUUID(), tar.getInventory(true)); + } else if (awo.getObjectType().equals(Enum.GameObjectType.Mob)) { - int levelDif = pc.getLevel() - ((AbstractCharacter)awo).getLevel(); + Mob tar = (Mob) awo; - if (!pc.getPowers().containsKey(429494332)) - return false; + if (!tar.isAlive()) + return; - CharacterPower cp = pc.getPowers().get(429494332); - int trains = cp.getTotalTrains(); + lwrm = new LootWindowResponseMsg(tar.getObjectType().ordinal(), tar.getObjectUUID(), tar.getInventory(true)); + } + if (lwrm == null) + return; - // check if peek is detected - float chance = 30 + (40-trains)*1.5f - levelDif; - chance = (chance < 5f) ? 5f : chance; - chance = (chance > 95f) ? 95f : chance; + Dispatch dispatch = Dispatch.borrow(pc, lwrm); + DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + } - float roll = ThreadLocalRandom.current().nextFloat() * 100f; - return roll < chance; + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } - } + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub - - } + } } diff --git a/src/engine/powers/poweractions/RecallPowerAction.java b/src/engine/powers/poweractions/RecallPowerAction.java index 16a8bf39..c0ffb409 100644 --- a/src/engine/powers/poweractions/RecallPowerAction.java +++ b/src/engine/powers/poweractions/RecallPowerAction.java @@ -11,7 +11,6 @@ package engine.powers.poweractions; import engine.Enum.GameObjectType; import engine.InterestManagement.WorldGrid; -import engine.ai.MobileFSM; import engine.gameManager.MovementManager; import engine.math.Vector3fImmutable; import engine.net.Dispatch; @@ -32,57 +31,57 @@ import java.sql.SQLException; public class RecallPowerAction extends AbstractPowerAction { - public RecallPowerAction(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (!AbstractWorldObject.IsAbstractCharacter(awo) || source == null) - return; - AbstractCharacter awoac = (AbstractCharacter)awo; - - if (awo.getObjectType().equals(GameObjectType.PlayerCharacter)) { - - PlayerCharacter pc = (PlayerCharacter) awo; - - if (pc.hasBoon()) - return; - - ClientConnection cc = pc.getClientConnection(); - - if(source.getObjectUUID() != pc.getObjectUUID()) { - pc.setTimeStampNow("PromptRecall"); - pc.setTimeStamp("LastRecallType",1); //recall to bind - PromptRecallMsg promptRecallMsgmsg = new PromptRecallMsg(); - Dispatch dispatch = Dispatch.borrow(pc, promptRecallMsgmsg); - DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - - } else { - MovementManager.translocate(awoac, awoac.getBindLoc(), null); - } - } else { - Vector3fImmutable bindloc = awoac.getBindLoc(); - if (bindloc.x == 0.0f || bindloc.y == 0.0f) - awoac.setBindLoc(MBServerStatics.startX, MBServerStatics.startY, MBServerStatics.startZ); - awoac.teleport(awoac.getBindLoc()); - if (awoac.getObjectType() == GameObjectType.Mob){ - ((Mob)awoac).setCombatTarget(null); - if (awoac.isAlive()) - WorldGrid.updateObject(awoac); - } - - } - } - - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub - - } + public RecallPowerAction(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + if (!AbstractWorldObject.IsAbstractCharacter(awo) || source == null) + return; + AbstractCharacter awoac = (AbstractCharacter) awo; + + if (awo.getObjectType().equals(GameObjectType.PlayerCharacter)) { + + PlayerCharacter pc = (PlayerCharacter) awo; + + if (pc.hasBoon()) + return; + + ClientConnection cc = pc.getClientConnection(); + + if (source.getObjectUUID() != pc.getObjectUUID()) { + pc.setTimeStampNow("PromptRecall"); + pc.setTimeStamp("LastRecallType", 1); //recall to bind + PromptRecallMsg promptRecallMsgmsg = new PromptRecallMsg(); + Dispatch dispatch = Dispatch.borrow(pc, promptRecallMsgmsg); + DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + + } else { + MovementManager.translocate(awoac, awoac.getBindLoc(), null); + } + } else { + Vector3fImmutable bindloc = awoac.getBindLoc(); + if (bindloc.x == 0.0f || bindloc.y == 0.0f) + awoac.setBindLoc(MBServerStatics.startX, MBServerStatics.startY, MBServerStatics.startZ); + awoac.teleport(awoac.getBindLoc()); + if (awoac.getObjectType() == GameObjectType.Mob) { + ((Mob) awoac).setCombatTarget(null); + if (awoac.isAlive()) + WorldGrid.updateObject(awoac); + } + + } + } + + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub + + } } diff --git a/src/engine/powers/poweractions/RemoveEffectPowerAction.java b/src/engine/powers/poweractions/RemoveEffectPowerAction.java index d992ce81..0cb838de 100644 --- a/src/engine/powers/poweractions/RemoveEffectPowerAction.java +++ b/src/engine/powers/poweractions/RemoveEffectPowerAction.java @@ -22,41 +22,40 @@ import java.sql.SQLException; public class RemoveEffectPowerAction extends AbstractPowerAction { - - public EffectSourceType sourceType; - private boolean removeAll; - - public RemoveEffectPowerAction(ResultSet rs) throws SQLException { - super(rs); - String effectTypeToRemove = rs.getString("effectSourceToRemove").replace("-", "").trim(); - sourceType = EffectSourceType.GetEffectSourceType(effectTypeToRemove); - int flags = rs.getInt("flags"); - this.removeAll = ((flags & 2) != 0) ? true : false; - } - - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (awo != null) { - - - if (this.removeAll) - awo.removeEffectBySource(this.sourceType, trains, true); - else - if (this.getIDString().equals("SNC-003A")) - trains = 40; - awo.removeEffectBySource(this.sourceType, trains, false); - } - } - - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub - - } + + public EffectSourceType sourceType; + private boolean removeAll; + + public RemoveEffectPowerAction(ResultSet rs) throws SQLException { + super(rs); + String effectTypeToRemove = rs.getString("effectSourceToRemove").replace("-", "").trim(); + sourceType = EffectSourceType.GetEffectSourceType(effectTypeToRemove); + int flags = rs.getInt("flags"); + this.removeAll = ((flags & 2) != 0) ? true : false; + } + + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + if (awo != null) { + + + if (this.removeAll) + awo.removeEffectBySource(this.sourceType, trains, true); + else if (this.getIDString().equals("SNC-003A")) + trains = 40; + awo.removeEffectBySource(this.sourceType, trains, false); + } + } + + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub + + } } diff --git a/src/engine/powers/poweractions/ResurrectPowerAction.java b/src/engine/powers/poweractions/ResurrectPowerAction.java index 85c04eab..b21e8de8 100644 --- a/src/engine/powers/poweractions/ResurrectPowerAction.java +++ b/src/engine/powers/poweractions/ResurrectPowerAction.java @@ -21,23 +21,23 @@ import java.sql.SQLException; public class ResurrectPowerAction extends AbstractPowerAction { - public ResurrectPowerAction(ResultSet rs) throws SQLException { - super(rs); - } + public ResurrectPowerAction(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + } - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub - } + } } diff --git a/src/engine/powers/poweractions/RunegateTeleportPowerAction.java b/src/engine/powers/poweractions/RunegateTeleportPowerAction.java index ef728452..09416a86 100644 --- a/src/engine/powers/poweractions/RunegateTeleportPowerAction.java +++ b/src/engine/powers/poweractions/RunegateTeleportPowerAction.java @@ -26,62 +26,62 @@ import static engine.math.FastMath.sqrt; public class RunegateTeleportPowerAction extends AbstractPowerAction { - /** - * ResultSet Constructor - */ - public RunegateTeleportPowerAction(ResultSet rs) throws SQLException { - super(rs); - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - - if (source == null || awo == null || !(awo .getObjectType().equals(Enum.GameObjectType.PlayerCharacter))) - return; - - PlayerCharacter pc = (PlayerCharacter) awo; - float dist = 9999999999f; - Building rg = null; - Vector3fImmutable rgLoc; - - for (Runegate runegate: Runegate._runegates.values()) { - - rgLoc = runegate.gateBuilding.getLoc(); - - float distanceToRunegateSquared = source.getLoc().distanceSquared2D(rgLoc); - - if (distanceToRunegateSquared < sqr(dist)) { - dist = sqrt(distanceToRunegateSquared); - rg = runegate.gateBuilding; - } - } - - if(source.getObjectUUID() != pc.getObjectUUID()) { - pc.setTimeStampNow("PromptRecall"); - pc.setTimeStamp("LastRecallType",0); //recall to rg - - if (rg != null) { - PromptRecallMsg promptRecallMsgmsg = new PromptRecallMsg(); - Dispatch dispatch = Dispatch.borrow(pc, promptRecallMsgmsg); - DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - } - - } else { - if (rg != null) { - pc.teleport(rg.getLoc()); - pc.setSafeMode(); - } - } - } - - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub - - } + /** + * ResultSet Constructor + */ + public RunegateTeleportPowerAction(ResultSet rs) throws SQLException { + super(rs); + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + + if (source == null || awo == null || !(awo.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))) + return; + + PlayerCharacter pc = (PlayerCharacter) awo; + float dist = 9999999999f; + Building rg = null; + Vector3fImmutable rgLoc; + + for (Runegate runegate : Runegate._runegates.values()) { + + rgLoc = runegate.gateBuilding.getLoc(); + + float distanceToRunegateSquared = source.getLoc().distanceSquared2D(rgLoc); + + if (distanceToRunegateSquared < sqr(dist)) { + dist = sqrt(distanceToRunegateSquared); + rg = runegate.gateBuilding; + } + } + + if (source.getObjectUUID() != pc.getObjectUUID()) { + pc.setTimeStampNow("PromptRecall"); + pc.setTimeStamp("LastRecallType", 0); //recall to rg + + if (rg != null) { + PromptRecallMsg promptRecallMsgmsg = new PromptRecallMsg(); + Dispatch dispatch = Dispatch.borrow(pc, promptRecallMsgmsg); + DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + } + + } else { + if (rg != null) { + pc.teleport(rg.getLoc()); + pc.setSafeMode(); + } + } + } + + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub + + } } diff --git a/src/engine/powers/poweractions/SetItemFlagPowerAction.java b/src/engine/powers/poweractions/SetItemFlagPowerAction.java index e3571750..3bd976a0 100644 --- a/src/engine/powers/poweractions/SetItemFlagPowerAction.java +++ b/src/engine/powers/poweractions/SetItemFlagPowerAction.java @@ -25,41 +25,41 @@ import java.sql.SQLException; public class SetItemFlagPowerAction extends AbstractPowerAction { - public SetItemFlagPowerAction(ResultSet rs) throws SQLException { - super(rs); - } + public SetItemFlagPowerAction(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (source == null || awo == null || !(awo .getObjectType().equals(Enum.GameObjectType.Item))) - return; + if (source == null || awo == null || !(awo.getObjectType().equals(Enum.GameObjectType.Item))) + return; - Item item = (Item) awo; + Item item = (Item) awo; - if (item.containerType != Enum.ItemContainerType.INVENTORY) - return; //Send an error here? + if (item.containerType != Enum.ItemContainerType.INVENTORY) + return; //Send an error here? - //until this is shown to do something else, just use it as item identify spell. - item.setIsID(true); + //until this is shown to do something else, just use it as item identify spell. + item.setIsID(true); - if (!DbManager.ItemQueries.UPDATE_FLAGS(item)) - item.setIsID(false); //update failed, reset + if (!DbManager.ItemQueries.UPDATE_FLAGS(item)) + item.setIsID(false); //update failed, reset - //update inventory - CharacterItemManager cim = source.getCharItemManager(); - if (cim != null) - cim.updateInventory(); - } + //update inventory + CharacterItemManager cim = source.getCharItemManager(); + if (cim != null) + cim.updateInventory(); + } - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub - } + } } diff --git a/src/engine/powers/poweractions/SimpleDamagePowerAction.java b/src/engine/powers/poweractions/SimpleDamagePowerAction.java index eb6a5b4d..1c16c146 100644 --- a/src/engine/powers/poweractions/SimpleDamagePowerAction.java +++ b/src/engine/powers/poweractions/SimpleDamagePowerAction.java @@ -21,31 +21,31 @@ import java.sql.SQLException; public class SimpleDamagePowerAction extends AbstractPowerAction { - private int simpleDamage; + private int simpleDamage; - public SimpleDamagePowerAction(ResultSet rs) throws SQLException { - super(rs); + public SimpleDamagePowerAction(ResultSet rs) throws SQLException { + super(rs); - this.simpleDamage = rs.getInt("simpleDamage"); - } + this.simpleDamage = rs.getInt("simpleDamage"); + } - public int getSimpleDamage() { - return this.simpleDamage; - } + public int getSimpleDamage() { + return this.simpleDamage; + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + } - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub - } + } } diff --git a/src/engine/powers/poweractions/SpireDisablePowerAction.java b/src/engine/powers/poweractions/SpireDisablePowerAction.java index 7ad0bd30..b61c0166 100644 --- a/src/engine/powers/poweractions/SpireDisablePowerAction.java +++ b/src/engine/powers/poweractions/SpireDisablePowerAction.java @@ -25,65 +25,64 @@ import java.sql.SQLException; public class SpireDisablePowerAction extends AbstractPowerAction { - /** - * ResultSet Constructor - */ - public SpireDisablePowerAction(ResultSet rs) throws SQLException { - super(rs); - } + /** + * ResultSet Constructor + */ + public SpireDisablePowerAction(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (awo == null) - return; + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + if (awo == null) + return; - if (source == null) - return; + if (source == null) + return; - PlayerCharacter pc = null; + PlayerCharacter pc = null; - if (source.getObjectType() == GameObjectType.PlayerCharacter) - pc = (PlayerCharacter)source; - else - return; + if (source.getObjectType() == GameObjectType.PlayerCharacter) + pc = (PlayerCharacter) source; + else + return; - if (awo.getObjectType() != GameObjectType.Building) - return; + if (awo.getObjectType() != GameObjectType.Building) + return; - //Check if Building is Spire. + //Check if Building is Spire. - Building spire = (Building)awo; + Building spire = (Building) awo; - if ((spire.getBlueprintUUID() == 0) || - (spire.getBlueprint() != null && spire.getBlueprint().getBuildingGroup() != BuildingGroup.SPIRE)) { - ChatManager.chatSystemError((PlayerCharacter)source, "This Building is not a spire."); - return; - } + if ((spire.getBlueprintUUID() == 0) || + (spire.getBlueprint() != null && spire.getBlueprint().getBuildingGroup() != BuildingGroup.SPIRE)) { + ChatManager.chatSystemError((PlayerCharacter) source, "This Building is not a spire."); + return; + } - if (!spire.isSpireIsActive()) - return; + if (!spire.isSpireIsActive()) + return; - spire.disableSpire(false); + spire.disableSpire(false); - if (trains > 20) - trains = 20; + if (trains > 20) + trains = 20; - long duration = trains * 4500 + 30000; - spire.setTimeStamp("DISABLED", System.currentTimeMillis() + duration); + long duration = trains * 4500 + 30000; + spire.setTimeStamp("DISABLED", System.currentTimeMillis() + duration); + } - } + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub - - } + } } diff --git a/src/engine/powers/poweractions/StealPowerAction.java b/src/engine/powers/poweractions/StealPowerAction.java index 2cdc56db..79a594dc 100644 --- a/src/engine/powers/poweractions/StealPowerAction.java +++ b/src/engine/powers/poweractions/StealPowerAction.java @@ -32,170 +32,170 @@ import static engine.math.FastMath.sqr; public class StealPowerAction extends AbstractPowerAction { - /** - * ResultSet Constructor - */ - public StealPowerAction(ResultSet rs) throws SQLException { - super(rs); - } + /** + * ResultSet Constructor + */ + public StealPowerAction(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + protected static boolean stealSuccess(PlayerCharacter pc, AbstractWorldObject awo) { + if (pc == null || awo == null || !AbstractWorldObject.IsAbstractCharacter(awo) || pc.getPowers() == null) + return false; - if (source == null || awo == null || !(source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) || !(awo.getObjectType().equals(Enum.GameObjectType.Item))) - return; + int levelDif = pc.getLevel() - ((AbstractCharacter) awo).getLevel(); - PlayerCharacter sourcePlayer = (PlayerCharacter) source; + if (!pc.getPowers().containsKey(429396028)) + return false; - if (sourcePlayer.isSafeMode()) - return; + CharacterPower cp = pc.getPowers().get(429396028); + int trains = cp.getTotalTrains(); - if (!sourcePlayer.isAlive()) - return; + float chance = 20 + (trains * 1.5f) + levelDif; + chance = (chance < 5f) ? 5f : chance; + chance = (chance > 85f) ? 85f : chance; - //prevent stealing no steal mob loot - if (awo instanceof MobLoot && ((MobLoot)awo).noSteal()) - return; + float roll = ThreadLocalRandom.current().nextFloat() * 100f; - Item tar = (Item) awo; - AbstractWorldObject owner = (AbstractWorldObject) tar.getOwner(); + return roll < chance; - if (owner == null) - return; + } + //called to get amount of gold to steal between 0 and max gold + protected static int getAmountToSteal(Item i) { + if (i.getItemBase() != null && i.getItemBase().getUUID() == 7) { + int amount = i.getNumOfItems(); + if (amount < 1) + return -1; + int a = ThreadLocalRandom.current().nextInt(amount + 1); + int b = ThreadLocalRandom.current().nextInt(amount + 1); + int c = ThreadLocalRandom.current().nextInt(amount + 1); + return (a + b + c) / 3; + } else + return 0; + } - AbstractCharacter ownerAC = null; - if (AbstractWorldObject.IsAbstractCharacter(owner)) - ownerAC = (AbstractCharacter) owner; + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (ownerAC != null) - if (ownerAC.getLoc().distanceSquared(sourcePlayer.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) - return; + if (source == null || awo == null || !(source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) || !(awo.getObjectType().equals(Enum.GameObjectType.Item))) + return; - //only steal from players or mobs + PlayerCharacter sourcePlayer = (PlayerCharacter) source; - if (owner.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { + if (sourcePlayer.isSafeMode()) + return; - PlayerCharacter ownerPC = (PlayerCharacter)owner; + if (!sourcePlayer.isAlive()) + return; - if (ownerPC.isSafeMode() || sourcePlayer.inSafeZone() || ownerPC.inSafeZone()) - return; + //prevent stealing no steal mob loot + if (awo instanceof MobLoot && ((MobLoot) awo).noSteal()) + return; - if (ownerPC.getLoc().distanceSquared(sourcePlayer.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) - return; + Item tar = (Item) awo; + AbstractWorldObject owner = (AbstractWorldObject) tar.getOwner(); - //dupe check, validate player has item - if (!tar.validForInventory(ownerPC.getClientConnection(), ownerPC, ownerPC.getCharItemManager()))//pc.getCharItemManager())) - return; + if (owner == null) + return; - //mark thief and target as player aggressive - sourcePlayer.setLastPlayerAttackTime(); - ownerPC.setLastPlayerAttackTime(); - //Handle target attacking back if in combat and has no other target - CombatManager.handleRetaliate(ownerAC, sourcePlayer); + AbstractCharacter ownerAC = null; + if (AbstractWorldObject.IsAbstractCharacter(owner)) + ownerAC = (AbstractCharacter) owner; - } else if (owner.getObjectType().equals(Enum.GameObjectType.Mob)) { - sourcePlayer.setLastMobAttackTime(); //mark thief as mob aggressive - } else - return; + if (ownerAC != null) + if (ownerAC.getLoc().distanceSquared(sourcePlayer.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) + return; - ClientConnection origin = sourcePlayer.getClientConnection(); + //only steal from players or mobs - if (origin == null) - return; + if (owner.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { - int amount = getAmountToSteal(tar); + PlayerCharacter ownerPC = (PlayerCharacter) owner; - //test probability of steal success - if (!stealSuccess(sourcePlayer, owner)) { - ChatManager.chatPeekSteal(sourcePlayer, ownerAC, tar, false, false, -1); - return; - } else { - ChatManager.chatPeekSteal(sourcePlayer, ownerAC, tar, true, false, amount); - //TODO send steal failure success - } + if (ownerPC.isSafeMode() || sourcePlayer.inSafeZone() || ownerPC.inSafeZone()) + return; - //attempt transfer item - CharacterItemManager myCIM = sourcePlayer.getCharItemManager(); - CharacterItemManager ownerCIM = ((AbstractCharacter)owner).getCharItemManager(); - if (myCIM == null || ownerCIM == null) - return; + if (ownerPC.getLoc().distanceSquared(sourcePlayer.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) + return; - if (tar.getItemBase().getType().equals(ItemType.GOLD)) { - //stealing gold - if (!myCIM.transferGoldToMyInventory((AbstractCharacter)owner, amount)) - return; - } else { - //stealing items - if (ownerCIM.lootItemFromMe(tar, sourcePlayer, origin, true, amount) == null) - return; - } + //dupe check, validate player has item + if (!tar.validForInventory(ownerPC.getClientConnection(), ownerPC, ownerPC.getCharItemManager()))//pc.getCharItemManager())) + return; - //send loot message to person stealing. - LootMsg lm = new LootMsg(source.getObjectType().ordinal(), source.getObjectUUID(), owner.getObjectType().ordinal(), owner.getObjectUUID(), tar); - Dispatch dispatch = Dispatch.borrow(sourcePlayer, lm); - DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + //mark thief and target as player aggressive + sourcePlayer.setLastPlayerAttackTime(); + ownerPC.setLastPlayerAttackTime(); - //update thief's inventory - if (sourcePlayer.getCharItemManager() != null) - sourcePlayer.getCharItemManager().updateInventory(); + //Handle target attacking back if in combat and has no other target + CombatManager.handleRetaliate(ownerAC, sourcePlayer); - //update victims inventory - if (owner.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { - PlayerCharacter ownerPC = (PlayerCharacter) owner; + } else if (owner.getObjectType().equals(Enum.GameObjectType.Mob)) { + sourcePlayer.setLastMobAttackTime(); //mark thief as mob aggressive + } else + return; - if (ownerPC.getCharItemManager() != null) - ownerPC.getCharItemManager().updateInventory(); - } + ClientConnection origin = sourcePlayer.getClientConnection(); - //TODO if victim is trading, cancel trade window for both people involved in trade - } + if (origin == null) + return; - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + int amount = getAmountToSteal(tar); - protected static boolean stealSuccess(PlayerCharacter pc, AbstractWorldObject awo) { - if (pc == null || awo == null || !AbstractWorldObject.IsAbstractCharacter(awo) || pc.getPowers() == null) - return false; + //test probability of steal success + if (!stealSuccess(sourcePlayer, owner)) { + ChatManager.chatPeekSteal(sourcePlayer, ownerAC, tar, false, false, -1); + return; + } else { + ChatManager.chatPeekSteal(sourcePlayer, ownerAC, tar, true, false, amount); + //TODO send steal failure success + } - int levelDif = pc.getLevel() - ((AbstractCharacter)awo).getLevel(); + //attempt transfer item + CharacterItemManager myCIM = sourcePlayer.getCharItemManager(); + CharacterItemManager ownerCIM = ((AbstractCharacter) owner).getCharItemManager(); + if (myCIM == null || ownerCIM == null) + return; - if (!pc.getPowers().containsKey(429396028)) - return false; + if (tar.getItemBase().getType().equals(ItemType.GOLD)) { + //stealing gold + if (!myCIM.transferGoldToMyInventory((AbstractCharacter) owner, amount)) + return; + } else { + //stealing items + if (ownerCIM.lootItemFromMe(tar, sourcePlayer, origin, true, amount) == null) + return; + } - CharacterPower cp = pc.getPowers().get(429396028); - int trains = cp.getTotalTrains(); + //send loot message to person stealing. + LootMsg lm = new LootMsg(source.getObjectType().ordinal(), source.getObjectUUID(), owner.getObjectType().ordinal(), owner.getObjectUUID(), tar); + Dispatch dispatch = Dispatch.borrow(sourcePlayer, lm); + DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - float chance = 20 + (trains * 1.5f) + levelDif; - chance = (chance < 5f) ? 5f : chance; - chance = (chance > 85f) ? 85f : chance; + //update thief's inventory + if (sourcePlayer.getCharItemManager() != null) + sourcePlayer.getCharItemManager().updateInventory(); - float roll = ThreadLocalRandom.current().nextFloat() * 100f; + //update victims inventory + if (owner.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { + PlayerCharacter ownerPC = (PlayerCharacter) owner; - return roll < chance; + if (ownerPC.getCharItemManager() != null) + ownerPC.getCharItemManager().updateInventory(); + } - } - - //called to get amount of gold to steal between 0 and max gold - protected static int getAmountToSteal(Item i) { - if (i.getItemBase() != null && i.getItemBase().getUUID() == 7) { - int amount = i.getNumOfItems(); - if (amount < 1) - return -1; - int a = ThreadLocalRandom.current().nextInt(amount + 1); - int b = ThreadLocalRandom.current().nextInt(amount + 1); - int c = ThreadLocalRandom.current().nextInt(amount + 1); - return (a + b + c) / 3; - } else - return 0; - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub - - } + //TODO if victim is trading, cancel trade window for both people involved in trade + } + + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub + + } } diff --git a/src/engine/powers/poweractions/SummonPowerAction.java b/src/engine/powers/poweractions/SummonPowerAction.java index 32ef0e64..92d3c92e 100644 --- a/src/engine/powers/poweractions/SummonPowerAction.java +++ b/src/engine/powers/poweractions/SummonPowerAction.java @@ -29,50 +29,50 @@ import java.sql.SQLException; public class SummonPowerAction extends AbstractPowerAction { - /** - * ResultSet Constructor - */ - public SummonPowerAction(ResultSet rs) throws SQLException { - super(rs); - } + /** + * ResultSet Constructor + */ + public SummonPowerAction(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, - PowersBase pb) { + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, + PowersBase pb) { - if (source == null || awo == null || !(awo.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) || !(source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))) - return; + if (source == null || awo == null || !(awo.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) || !(source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))) + return; - PlayerCharacter target = (PlayerCharacter) awo; + PlayerCharacter target = (PlayerCharacter) awo; - ClientConnection conn = SessionManager.getClientConnection(target); + ClientConnection conn = SessionManager.getClientConnection(target); - if (conn == null) - return; + if (conn == null) + return; - // TODO get location of summoning player - Zone zone = ZoneManager.findSmallestZone(source.getLoc()); - String location = "Somewhere"; + // TODO get location of summoning player + Zone zone = ZoneManager.findSmallestZone(source.getLoc()); + String location = "Somewhere"; - if (zone != null) - location = zone.getName(); + if (zone != null) + location = zone.getName(); - RecvSummonsRequestMsg rsrm = new RecvSummonsRequestMsg(source.getObjectType().ordinal(), source.getObjectUUID(), source.getFirstName(), - location, false); + RecvSummonsRequestMsg rsrm = new RecvSummonsRequestMsg(source.getObjectType().ordinal(), source.getObjectUUID(), source.getFirstName(), + location, false); - Dispatch dispatch = Dispatch.borrow(target, rsrm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + Dispatch dispatch = Dispatch.borrow(target, rsrm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } + } - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub - } + } } diff --git a/src/engine/powers/poweractions/TeleportPowerAction.java b/src/engine/powers/poweractions/TeleportPowerAction.java index e04e642d..36eed471 100644 --- a/src/engine/powers/poweractions/TeleportPowerAction.java +++ b/src/engine/powers/poweractions/TeleportPowerAction.java @@ -28,89 +28,89 @@ import java.sql.SQLException; public class TeleportPowerAction extends AbstractPowerAction { - private boolean ignoreNoTeleSpire; + private boolean ignoreNoTeleSpire; - public TeleportPowerAction(ResultSet rs) throws SQLException { - super(rs); + public TeleportPowerAction(ResultSet rs) throws SQLException { + super(rs); - int flags = rs.getInt("flags"); - this.ignoreNoTeleSpire = ((flags & 32768) != 0) ? true : false; - } + int flags = rs.getInt("flags"); + this.ignoreNoTeleSpire = ((flags & 32768) != 0) ? true : false; + } - public boolean ignoreNoTeleSpire() { - return this.ignoreNoTeleSpire; - } + private static void failTeleport(PowersBase pb, AbstractCharacter awo) { - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + if (pb == null || awo == null || (!(awo.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)))) + return; - if (!AbstractWorldObject.IsAbstractCharacter(awo)) - return; + //teleport failed. Reset teleport power + PowersManager.finishRecycleTime(pb.getToken(), (PlayerCharacter) awo, true); + } - AbstractCharacter awoac = (AbstractCharacter) awo; + public boolean ignoreNoTeleSpire() { + return this.ignoreNoTeleSpire; + } - //verify targetLoc within range + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (awo.getLoc().distanceSquared2D(targetLoc) > MBServerStatics.MAX_TELEPORT_RANGE * MBServerStatics.MAX_TELEPORT_RANGE) { - if (awo.equals(source)) - failTeleport(pb, awoac); - return; - } - - if (source.getBonuses().getBool(ModType.BlockedPowerType, SourceType.TELEPORT)) - return; + if (!AbstractWorldObject.IsAbstractCharacter(awo)) + return; - City city = ZoneManager.getCityAtLocation(targetLoc); + AbstractCharacter awoac = (AbstractCharacter) awo; - // Intentionally fail if target location is not on - // the actual city zone. - if (city != null) - if (city.isLocationOnCityZone(targetLoc) == false) - city = null; + //verify targetLoc within range - if (city != null){ + if (awo.getLoc().distanceSquared2D(targetLoc) > MBServerStatics.MAX_TELEPORT_RANGE * MBServerStatics.MAX_TELEPORT_RANGE) { + if (awo.equals(source)) + failTeleport(pb, awoac); + return; + } - for (String eff : city.getEffects().keySet()){ + if (source.getBonuses().getBool(ModType.BlockedPowerType, SourceType.TELEPORT)) + return; - Effect spireEffect = city.getEffects().get(eff); + City city = ZoneManager.getCityAtLocation(targetLoc); - for (AbstractEffectModifier aem : spireEffect.getEffectModifiers()){ + // Intentionally fail if target location is not on + // the actual city zone. + if (city != null) + if (city.isLocationOnCityZone(targetLoc) == false) + city = null; - if (aem.getType().equals("TELEPORT") && !this.ignoreNoTeleSpire){ - if (awo.equals(source)) - failTeleport(pb, awoac); - return; - } - } - } - } + if (city != null) { - //TODO verify target loc is valid loc - - Regions region = Regions.GetRegionForTeleport(targetLoc); + for (String eff : city.getEffects().keySet()) { - if (region != null && !region.isOutside()) - return; + Effect spireEffect = city.getEffects().get(eff); - MovementManager.translocate(awoac,targetLoc, region); - } + for (AbstractEffectModifier aem : spireEffect.getEffectModifiers()) { - private static void failTeleport(PowersBase pb, AbstractCharacter awo) { + if (aem.getType().equals("TELEPORT") && !this.ignoreNoTeleSpire) { + if (awo.equals(source)) + failTeleport(pb, awoac); + return; + } + } + } + } - if (pb == null || awo == null || (!(awo.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)))) - return; + //TODO verify target loc is valid loc - //teleport failed. Reset teleport power - PowersManager.finishRecycleTime(pb.getToken(), (PlayerCharacter) awo, true); - } + Regions region = Regions.GetRegionForTeleport(targetLoc); - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + if (region != null && !region.isOutside()) + return; - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub - } + MovementManager.translocate(awoac, targetLoc, region); + } + + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub + } } \ No newline at end of file diff --git a/src/engine/powers/poweractions/TrackPowerAction.java b/src/engine/powers/poweractions/TrackPowerAction.java index f12943c9..c9d4fdee 100644 --- a/src/engine/powers/poweractions/TrackPowerAction.java +++ b/src/engine/powers/poweractions/TrackPowerAction.java @@ -25,103 +25,103 @@ import java.util.HashMap; public class TrackPowerAction extends AbstractPowerAction { - private String effectID; - private boolean trackPlayer; - private boolean trackCorpse; - private boolean trackAll; - private boolean trackDragon; - private boolean trackGiant; - private boolean trackNPC; - private boolean trackUndead; - private boolean trackVampire; - private int maxTrack; - private EffectsBase effect; - - public TrackPowerAction(ResultSet rs, HashMap effects) throws SQLException { - super(rs); - - this.effectID = rs.getString("effectID"); - int flags = rs.getInt("flags"); - this.trackPlayer = ((flags & 1024) == 1) ? true : false; - this.trackCorpse = ((flags & 2048) == 1) ? true : false; - String trackFilter = rs.getString("trackFilter"); - this.trackAll = trackFilter.equals("All") ? true : false; - this.trackDragon = trackFilter.equals("Dragon") ? true : false; - this.trackGiant = trackFilter.equals("Giant") ? true : false; - this.trackNPC = trackFilter.equals("NPC") ? true : false; - this.trackUndead = trackFilter.equals("Undead") ? true : false; - this.trackVampire = trackFilter.equals("Vampire") ? true : false; - - this.maxTrack = rs.getInt("maxTrack"); - this.effect = effects.get(this.effectID); - } - - public String getEffectID() { - return this.effectID; - } - - public boolean trackPlayer() { - return this.trackPlayer; - } - - public boolean trackCorpse() { - return this.trackCorpse; - } - - public boolean trackAll() { - return this.trackAll; - } - - public boolean trackDragon() { - return this.trackDragon; - } - - public boolean trackGiant() { - return this.trackGiant; - } - - public boolean trackNPC() { - return this.trackNPC; - } - - public boolean trackUndead() { - return this.trackUndead; - } - - public boolean trackVampire() { - return this.trackVampire; - } - - public int getMaxTrack() { - return this.maxTrack; - } - - public EffectsBase getEffect() { - return this.effect; - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (source == null || awo == null || this.effect == null || pb == null || ab == null) { - //TODO log error here - return; - } - - //add schedule job to end it if needed and add effect to pc - int duration = MBServerStatics.TRACK_ARROW_SENSITIVITY; - String stackType = ab.getStackType(); - TrackJob eff = new TrackJob(source, awo, stackType, trains, ab, pb, this.effect, this); - source.addEffect(stackType, duration, eff, this.effect, trains); - } - - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub - - } + private String effectID; + private boolean trackPlayer; + private boolean trackCorpse; + private boolean trackAll; + private boolean trackDragon; + private boolean trackGiant; + private boolean trackNPC; + private boolean trackUndead; + private boolean trackVampire; + private int maxTrack; + private EffectsBase effect; + + public TrackPowerAction(ResultSet rs, HashMap effects) throws SQLException { + super(rs); + + this.effectID = rs.getString("effectID"); + int flags = rs.getInt("flags"); + this.trackPlayer = ((flags & 1024) == 1) ? true : false; + this.trackCorpse = ((flags & 2048) == 1) ? true : false; + String trackFilter = rs.getString("trackFilter"); + this.trackAll = trackFilter.equals("All") ? true : false; + this.trackDragon = trackFilter.equals("Dragon") ? true : false; + this.trackGiant = trackFilter.equals("Giant") ? true : false; + this.trackNPC = trackFilter.equals("NPC") ? true : false; + this.trackUndead = trackFilter.equals("Undead") ? true : false; + this.trackVampire = trackFilter.equals("Vampire") ? true : false; + + this.maxTrack = rs.getInt("maxTrack"); + this.effect = effects.get(this.effectID); + } + + public String getEffectID() { + return this.effectID; + } + + public boolean trackPlayer() { + return this.trackPlayer; + } + + public boolean trackCorpse() { + return this.trackCorpse; + } + + public boolean trackAll() { + return this.trackAll; + } + + public boolean trackDragon() { + return this.trackDragon; + } + + public boolean trackGiant() { + return this.trackGiant; + } + + public boolean trackNPC() { + return this.trackNPC; + } + + public boolean trackUndead() { + return this.trackUndead; + } + + public boolean trackVampire() { + return this.trackVampire; + } + + public int getMaxTrack() { + return this.maxTrack; + } + + public EffectsBase getEffect() { + return this.effect; + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + if (source == null || awo == null || this.effect == null || pb == null || ab == null) { + //TODO log error here + return; + } + + //add schedule job to end it if needed and add effect to pc + int duration = MBServerStatics.TRACK_ARROW_SENSITIVITY; + String stackType = ab.getStackType(); + TrackJob eff = new TrackJob(source, awo, stackType, trains, ab, pb, this.effect, this); + source.addEffect(stackType, duration, eff, this.effect, trains); + } + + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub + + } } diff --git a/src/engine/powers/poweractions/TransferStatOTPowerAction.java b/src/engine/powers/poweractions/TransferStatOTPowerAction.java index f3940233..a88a7237 100644 --- a/src/engine/powers/poweractions/TransferStatOTPowerAction.java +++ b/src/engine/powers/poweractions/TransferStatOTPowerAction.java @@ -25,44 +25,44 @@ import java.util.HashMap; public class TransferStatOTPowerAction extends TransferStatPowerAction { - private int numIterations; - - public TransferStatOTPowerAction(ResultSet rs, HashMap effects) throws SQLException { - super(rs, effects); - - this.numIterations = rs.getInt("numIterations"); - } - - public int getNumIterations() { - return this.numIterations; - } - - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3f targetLoc, int trains, ActionsBase ab, PowersBase pb) { - this.__startAction(source, awo, trains, ab, pb); - } - - @Override - protected void __startAction(AbstractCharacter source, AbstractWorldObject awo, int trains, ActionsBase ab, PowersBase pb) { - if (this.effect == null || source == null || awo == null || ab == null || pb == null) - return; - - //add schedule job to end it if needed and add effect to pc - int duration = ab.getDuration(trains); - String stackType = ab.getStackType(); - stackType = (stackType.equals("IgnoreStack")) ? Integer.toString(ab.getUUID()) : stackType; - TransferStatOTJob eff = new TransferStatOTJob(source, awo, stackType, trains, ab, pb, this.effect, this); - int tick = eff.getTickLength(); - - if (duration > 0) - awo.addEffect(stackType, tick, eff, this.effect, trains); - - //start effect icon for client. Skip applying dot until first iteration. - eff.setSkipApplyEffect(true); - this.effect.startEffect(source, awo, trains, eff); - eff.setSkipApplyEffect(false); - } - - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + private int numIterations; + + public TransferStatOTPowerAction(ResultSet rs, HashMap effects) throws SQLException { + super(rs, effects); + + this.numIterations = rs.getInt("numIterations"); + } + + public int getNumIterations() { + return this.numIterations; + } + + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3f targetLoc, int trains, ActionsBase ab, PowersBase pb) { + this.__startAction(source, awo, trains, ab, pb); + } + + @Override + protected void __startAction(AbstractCharacter source, AbstractWorldObject awo, int trains, ActionsBase ab, PowersBase pb) { + if (this.effect == null || source == null || awo == null || ab == null || pb == null) + return; + + //add schedule job to end it if needed and add effect to pc + int duration = ab.getDuration(trains); + String stackType = ab.getStackType(); + stackType = (stackType.equals("IgnoreStack")) ? Integer.toString(ab.getUUID()) : stackType; + TransferStatOTJob eff = new TransferStatOTJob(source, awo, stackType, trains, ab, pb, this.effect, this); + int tick = eff.getTickLength(); + + if (duration > 0) + awo.addEffect(stackType, tick, eff, this.effect, trains); + + //start effect icon for client. Skip applying dot until first iteration. + eff.setSkipApplyEffect(true); + this.effect.startEffect(source, awo, trains, eff); + eff.setSkipApplyEffect(false); + } + + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } } diff --git a/src/engine/powers/poweractions/TransferStatPowerAction.java b/src/engine/powers/poweractions/TransferStatPowerAction.java index cb2f7960..4deea480 100644 --- a/src/engine/powers/poweractions/TransferStatPowerAction.java +++ b/src/engine/powers/poweractions/TransferStatPowerAction.java @@ -32,268 +32,267 @@ import java.util.concurrent.ThreadLocalRandom; public class TransferStatPowerAction extends AbstractPowerAction { - protected String effectID; - protected boolean transferFromHealth = false; - protected boolean transferFromMana = false; - protected boolean transferFromStamina = false; - protected boolean transferToHealth = false; - protected boolean transferToMana = false; - protected boolean transferToStamina = false; - protected float transferAmount; - protected float transferRamp; - protected boolean transferRampAdd; - protected float transferEfficiency; - protected float transferEfficiencyRamp; - protected boolean transferEfficiencyRampAdd; - protected boolean targetToCaster; - protected DamageType damageType; - protected EffectsBase effect; - - public TransferStatPowerAction(ResultSet rs, HashMap effects) throws SQLException { - super(rs); - this.effectID = rs.getString("effectID"); - String st = rs.getString("transferFromType"); - if (st.equals("HEALTH")) - this.transferFromHealth = true; - else if (st.equals("MANA")) - this.transferFromMana = true; - else - this.transferFromStamina = true; - st = rs.getString("transferToType"); - if (st.equals("HEALTH")) - this.transferToHealth = true; - else if (st.equals("MANA")) - this.transferToMana = true; - else - this.transferToStamina = true; - this.transferAmount = rs.getFloat("transferAmount"); - this.transferRamp = rs.getFloat("transferRamp"); - this.transferEfficiency = rs.getFloat("transferEfficiency"); - this.transferEfficiencyRamp = rs.getFloat("transferEfficiencyRamp"); - int flags = rs.getInt("flags"); - this.transferRampAdd = ((flags & 4096) != 0) ? true : false; - this.transferEfficiencyRampAdd = ((flags & 8192) != 0) ? true : false; - this.targetToCaster = ((flags & 16384) != 0) ? true : false; - this.effect = effects.get(this.effectID); - try { - String damageString = rs.getString("damageType"); - // Damage type can sometimes be null in the DB. - - if (damageString.isEmpty() == false) - this.damageType = DamageType.valueOf(damageString); - } catch (Exception e) { - this.damageType = null; - } - } - - public String getEffectID() { - return this.effectID; - } - - public boolean transferFromHealth() { - return this.transferFromHealth; - } - - public boolean transferFromMana() { - return this.transferFromMana; - } - - public boolean transferFromStamina() { - return this.transferFromStamina; - } - - public boolean transferToHealth() { - return this.transferToHealth; - } - - public boolean transferToMana() { - return this.transferToMana; - } - - public boolean transferToStamina() { - return this.transferToStamina; - } - - public EffectsBase getEffect() { - return this.effect; - } - - public float getTransferAmount(float trains) { - // if (this.transferRampAdd) - return this.transferAmount + (this.transferRamp * trains); - // else - // return this.transferAmount * (1 + (this.transferRamp * trains)); - } - - public float getTransferEfficiency(float trains) { - return this.transferEfficiency + (this.transferEfficiencyRamp * trains); - } - - public boolean targetToCaster() { - return this.targetToCaster; - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - this.__startAction(source, awo, trains, ab, pb); - } - - //Added for dependancy check on TransferStatOTPowerAction - protected void __startAction(AbstractCharacter source, AbstractWorldObject awo, int trains, ActionsBase ab, PowersBase pb) { - this.runAction(source, awo, trains, ab, pb); - } - - public void runAction(AbstractCharacter source, AbstractWorldObject awo, int trains, ActionsBase ab, PowersBase pb) { - if (source == null || awo == null || ab == null || pb == null) - return; - - if (!source.isAlive() || !awo.isAlive()) - return; - - AbstractWorldObject fromAwo; - AbstractWorldObject toAwo; - if (this.targetToCaster) { - fromAwo = awo; - toAwo = source; - } else { - fromAwo = source; - toAwo = awo; - } - - - - if (AbstractWorldObject.IsAbstractCharacter(fromAwo) && AbstractWorldObject.IsAbstractCharacter(toAwo)) { - AbstractCharacter from = (AbstractCharacter) fromAwo; - AbstractCharacter to = (AbstractCharacter) toAwo; - - //get amount to drain - float fromAmount = getTransferAmount(trains); - - //modify for resists if needed - if (this.damageType != null) { - Resists resists = from.getResists(); - if (resists != null) - fromAmount = resists.getResistedDamage(to, from, this.damageType, fromAmount * -1, trains) * -1; - } - - float min = fromAmount;// * (getTransferEfficiency(trains) / 100); - float max = min; - float damage = 0f; - - if (source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { - PlayerCharacter pc = (PlayerCharacter) source; - float focus; - CharacterSkill skill = pc.getSkills().get(pb.getSkillName()); - if (skill == null) - focus = CharacterSkill.getQuickMastery(pc, pb.getSkillName()); - else - focus = skill.getModifiedAmount(); - - //TODO fix this formula later - float intt = (pc.getStatIntCurrent() >= 1) ? (float)pc.getStatIntCurrent() : 1f; - float spi = (pc.getStatSpiCurrent() >= 1) ? (float)pc.getStatSpiCurrent() : 1f; - // min *= (intt * 0.0045 + 0.055 * (float)Math.sqrt(intt - 0.5) + spi * 0.006 + 0.07 * (float)Math.sqrt(spi - 0.5) + 0.02 * (int)focus); - // max *= (intt * 0.0117 + 0.13 * (float)Math.sqrt(intt - 0.5) + spi * 0.0024 + (float)Math.sqrt(spi - 0.5) * 0.021 + 0.015 * (int)focus); - // min *= (0.62 + 0.0192 * pc.getStatSpiCurrent() + 0.00415 * pc.getStatIntCurrent() + 0.015 * focus) / 2; - // max *= (0.62 + 0.0192 * pc.getStatIntCurrent() + 0.00415 * pc.getStatSpiCurrent() + 0.015 * focus) / 2; - min = HealthEffectModifier.getMinDamage(min, intt, spi, focus); - max = HealthEffectModifier.getMaxDamage(max, intt, spi, focus); - - // get range between min and max - float range = max - min; - - //debug for spell damage and atr - if (pc.getDebug(16)) { - String smsg = "Damage: " + (int)Math.abs(min) + " - " + (int)Math.abs(max); - ChatManager.chatSystemInfo(pc, smsg); - } - - // Damage is calculated twice to average a more central point - damage = ThreadLocalRandom.current().nextFloat() * range; - damage = (damage + (ThreadLocalRandom.current().nextFloat() * range)) / 2; - - // put it back between min and max - damage += min; - } - - // Apply any power effect modifiers (such as stances) - PlayerBonuses bonus = source.getBonuses(); - if (bonus != null) - damage *= (1 + bonus.getFloatPercentAll(ModType.PowerDamageModifier, SourceType.None)); - - //get amount to transfer - fromAmount = damage; - float toAmount = fromAmount * (getTransferEfficiency(trains) / 100); - - //get max amount to transfer, don't give more then the target has - float maxDrain; - if (this.transferFromHealth) - maxDrain = from.getCurrentHitpoints(); - else if (this.transferFromMana) - maxDrain = from.getMana(); - else - maxDrain = from.getStamina(); - if (toAmount > maxDrain) - toAmount = maxDrain; - - //prep messages for transfer - int powerID = pb.getToken(); - int effectID = 496519310; - String powerName = pb.getName(); - ModifyHealthMsg mhmTo; - // ModifyHealthMsg mhmFrom; - AbstractNetMsg mhmFrom = null; - - //stop if target is immune to drains - if ( from.getBonuses().getBool(ModType.ImmuneTo, SourceType.Drain)) { - ModifyHealthMsg mhm = new ModifyHealthMsg(source, to, 0f, 0f, 0f, powerID, powerName, trains, effectID); - mhm.setUnknown03(5); //set target is immune - DispatchMessage.sendToAllInRange(from, mhm); - return; - } - - //apply transfer bonus - if (this.transferToHealth) { - to.modifyHealth(toAmount, source, false); - mhmTo = new ModifyHealthMsg(source, to, toAmount, 0f, 0f, powerID, powerName, trains, effectID); - } else if (this.transferToMana) { - to.modifyMana(toAmount, source); - mhmTo = new ModifyHealthMsg(source, to, 0f, toAmount, 0f, powerID, powerName, trains, effectID); - } else { - to.modifyStamina(toAmount, source); - mhmTo = new ModifyHealthMsg(source, to, 0f, 0f, toAmount, powerID, powerName, trains, effectID); - } - - //subtract transfer amount - if (this.transferFromHealth) { - float modFrom = from.modifyHealth(-fromAmount, source, false); - float cur = from.getHealth(); - if (cur < 0 && modFrom != 0) - mhmFrom = new ModifyHealthKillMsg(source, from, -fromAmount, 0f, 0f, powerID, powerName, trains, effectID); - else - mhmFrom = new ModifyHealthMsg(source, from, -fromAmount, 0f, 0f, powerID, powerName, trains, effectID); - } else if (this.transferFromMana) { - from.modifyMana(-fromAmount, source); - mhmFrom = new ModifyHealthMsg(source, from, 0f, -fromAmount, 0f, powerID, powerName, trains, effectID); - } else { - from.modifyStamina(-fromAmount, source); - mhmFrom = new ModifyHealthMsg(source, from, 0f, 0f, -fromAmount, powerID, powerName, trains, effectID); - } - - DispatchMessage.sendToAllInRange(to, mhmTo); - DispatchMessage.sendToAllInRange(from, mhmFrom); - - } - } - - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub - - } + protected String effectID; + protected boolean transferFromHealth = false; + protected boolean transferFromMana = false; + protected boolean transferFromStamina = false; + protected boolean transferToHealth = false; + protected boolean transferToMana = false; + protected boolean transferToStamina = false; + protected float transferAmount; + protected float transferRamp; + protected boolean transferRampAdd; + protected float transferEfficiency; + protected float transferEfficiencyRamp; + protected boolean transferEfficiencyRampAdd; + protected boolean targetToCaster; + protected DamageType damageType; + protected EffectsBase effect; + + public TransferStatPowerAction(ResultSet rs, HashMap effects) throws SQLException { + super(rs); + this.effectID = rs.getString("effectID"); + String st = rs.getString("transferFromType"); + if (st.equals("HEALTH")) + this.transferFromHealth = true; + else if (st.equals("MANA")) + this.transferFromMana = true; + else + this.transferFromStamina = true; + st = rs.getString("transferToType"); + if (st.equals("HEALTH")) + this.transferToHealth = true; + else if (st.equals("MANA")) + this.transferToMana = true; + else + this.transferToStamina = true; + this.transferAmount = rs.getFloat("transferAmount"); + this.transferRamp = rs.getFloat("transferRamp"); + this.transferEfficiency = rs.getFloat("transferEfficiency"); + this.transferEfficiencyRamp = rs.getFloat("transferEfficiencyRamp"); + int flags = rs.getInt("flags"); + this.transferRampAdd = ((flags & 4096) != 0) ? true : false; + this.transferEfficiencyRampAdd = ((flags & 8192) != 0) ? true : false; + this.targetToCaster = ((flags & 16384) != 0) ? true : false; + this.effect = effects.get(this.effectID); + try { + String damageString = rs.getString("damageType"); + // Damage type can sometimes be null in the DB. + + if (damageString.isEmpty() == false) + this.damageType = DamageType.valueOf(damageString); + } catch (Exception e) { + this.damageType = null; + } + } + + public String getEffectID() { + return this.effectID; + } + + public boolean transferFromHealth() { + return this.transferFromHealth; + } + + public boolean transferFromMana() { + return this.transferFromMana; + } + + public boolean transferFromStamina() { + return this.transferFromStamina; + } + + public boolean transferToHealth() { + return this.transferToHealth; + } + + public boolean transferToMana() { + return this.transferToMana; + } + + public boolean transferToStamina() { + return this.transferToStamina; + } + + public EffectsBase getEffect() { + return this.effect; + } + + public float getTransferAmount(float trains) { + // if (this.transferRampAdd) + return this.transferAmount + (this.transferRamp * trains); + // else + // return this.transferAmount * (1 + (this.transferRamp * trains)); + } + + public float getTransferEfficiency(float trains) { + return this.transferEfficiency + (this.transferEfficiencyRamp * trains); + } + + public boolean targetToCaster() { + return this.targetToCaster; + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + this.__startAction(source, awo, trains, ab, pb); + } + + //Added for dependancy check on TransferStatOTPowerAction + protected void __startAction(AbstractCharacter source, AbstractWorldObject awo, int trains, ActionsBase ab, PowersBase pb) { + this.runAction(source, awo, trains, ab, pb); + } + + public void runAction(AbstractCharacter source, AbstractWorldObject awo, int trains, ActionsBase ab, PowersBase pb) { + if (source == null || awo == null || ab == null || pb == null) + return; + + if (!source.isAlive() || !awo.isAlive()) + return; + + AbstractWorldObject fromAwo; + AbstractWorldObject toAwo; + if (this.targetToCaster) { + fromAwo = awo; + toAwo = source; + } else { + fromAwo = source; + toAwo = awo; + } + + + if (AbstractWorldObject.IsAbstractCharacter(fromAwo) && AbstractWorldObject.IsAbstractCharacter(toAwo)) { + AbstractCharacter from = (AbstractCharacter) fromAwo; + AbstractCharacter to = (AbstractCharacter) toAwo; + + //get amount to drain + float fromAmount = getTransferAmount(trains); + + //modify for resists if needed + if (this.damageType != null) { + Resists resists = from.getResists(); + if (resists != null) + fromAmount = resists.getResistedDamage(to, from, this.damageType, fromAmount * -1, trains) * -1; + } + + float min = fromAmount;// * (getTransferEfficiency(trains) / 100); + float max = min; + float damage = 0f; + + if (source.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { + PlayerCharacter pc = (PlayerCharacter) source; + float focus; + CharacterSkill skill = pc.getSkills().get(pb.getSkillName()); + if (skill == null) + focus = CharacterSkill.getQuickMastery(pc, pb.getSkillName()); + else + focus = skill.getModifiedAmount(); + + //TODO fix this formula later + float intt = (pc.getStatIntCurrent() >= 1) ? (float) pc.getStatIntCurrent() : 1f; + float spi = (pc.getStatSpiCurrent() >= 1) ? (float) pc.getStatSpiCurrent() : 1f; + // min *= (intt * 0.0045 + 0.055 * (float)Math.sqrt(intt - 0.5) + spi * 0.006 + 0.07 * (float)Math.sqrt(spi - 0.5) + 0.02 * (int)focus); + // max *= (intt * 0.0117 + 0.13 * (float)Math.sqrt(intt - 0.5) + spi * 0.0024 + (float)Math.sqrt(spi - 0.5) * 0.021 + 0.015 * (int)focus); + // min *= (0.62 + 0.0192 * pc.getStatSpiCurrent() + 0.00415 * pc.getStatIntCurrent() + 0.015 * focus) / 2; + // max *= (0.62 + 0.0192 * pc.getStatIntCurrent() + 0.00415 * pc.getStatSpiCurrent() + 0.015 * focus) / 2; + min = HealthEffectModifier.getMinDamage(min, intt, spi, focus); + max = HealthEffectModifier.getMaxDamage(max, intt, spi, focus); + + // get range between min and max + float range = max - min; + + //debug for spell damage and atr + if (pc.getDebug(16)) { + String smsg = "Damage: " + (int) Math.abs(min) + " - " + (int) Math.abs(max); + ChatManager.chatSystemInfo(pc, smsg); + } + + // Damage is calculated twice to average a more central point + damage = ThreadLocalRandom.current().nextFloat() * range; + damage = (damage + (ThreadLocalRandom.current().nextFloat() * range)) / 2; + + // put it back between min and max + damage += min; + } + + // Apply any power effect modifiers (such as stances) + PlayerBonuses bonus = source.getBonuses(); + if (bonus != null) + damage *= (1 + bonus.getFloatPercentAll(ModType.PowerDamageModifier, SourceType.None)); + + //get amount to transfer + fromAmount = damage; + float toAmount = fromAmount * (getTransferEfficiency(trains) / 100); + + //get max amount to transfer, don't give more then the target has + float maxDrain; + if (this.transferFromHealth) + maxDrain = from.getCurrentHitpoints(); + else if (this.transferFromMana) + maxDrain = from.getMana(); + else + maxDrain = from.getStamina(); + if (toAmount > maxDrain) + toAmount = maxDrain; + + //prep messages for transfer + int powerID = pb.getToken(); + int effectID = 496519310; + String powerName = pb.getName(); + ModifyHealthMsg mhmTo; + // ModifyHealthMsg mhmFrom; + AbstractNetMsg mhmFrom = null; + + //stop if target is immune to drains + if (from.getBonuses().getBool(ModType.ImmuneTo, SourceType.Drain)) { + ModifyHealthMsg mhm = new ModifyHealthMsg(source, to, 0f, 0f, 0f, powerID, powerName, trains, effectID); + mhm.setUnknown03(5); //set target is immune + DispatchMessage.sendToAllInRange(from, mhm); + return; + } + + //apply transfer bonus + if (this.transferToHealth) { + to.modifyHealth(toAmount, source, false); + mhmTo = new ModifyHealthMsg(source, to, toAmount, 0f, 0f, powerID, powerName, trains, effectID); + } else if (this.transferToMana) { + to.modifyMana(toAmount, source); + mhmTo = new ModifyHealthMsg(source, to, 0f, toAmount, 0f, powerID, powerName, trains, effectID); + } else { + to.modifyStamina(toAmount, source); + mhmTo = new ModifyHealthMsg(source, to, 0f, 0f, toAmount, powerID, powerName, trains, effectID); + } + + //subtract transfer amount + if (this.transferFromHealth) { + float modFrom = from.modifyHealth(-fromAmount, source, false); + float cur = from.getHealth(); + if (cur < 0 && modFrom != 0) + mhmFrom = new ModifyHealthKillMsg(source, from, -fromAmount, 0f, 0f, powerID, powerName, trains, effectID); + else + mhmFrom = new ModifyHealthMsg(source, from, -fromAmount, 0f, 0f, powerID, powerName, trains, effectID); + } else if (this.transferFromMana) { + from.modifyMana(-fromAmount, source); + mhmFrom = new ModifyHealthMsg(source, from, 0f, -fromAmount, 0f, powerID, powerName, trains, effectID); + } else { + from.modifyStamina(-fromAmount, source); + mhmFrom = new ModifyHealthMsg(source, from, 0f, 0f, -fromAmount, powerID, powerName, trains, effectID); + } + + DispatchMessage.sendToAllInRange(to, mhmTo); + DispatchMessage.sendToAllInRange(from, mhmFrom); + + } + } + + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub + + } } diff --git a/src/engine/powers/poweractions/TransformPowerAction.java b/src/engine/powers/poweractions/TransformPowerAction.java index 6f8d0be2..cd4a95b3 100644 --- a/src/engine/powers/poweractions/TransformPowerAction.java +++ b/src/engine/powers/poweractions/TransformPowerAction.java @@ -24,48 +24,48 @@ import java.util.HashMap; public class TransformPowerAction extends AbstractPowerAction { - private String effectID; - private EffectsBase effect; - - public TransformPowerAction(ResultSet rs, HashMap effects) throws SQLException { - super(rs); - - this.effectID = rs.getString("effectID"); - this.effect = effects.get(this.effectID); - } - - public String getEffectID() { - return this.effectID; - } - - public EffectsBase getEffect() { - return this.effect; - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - if (this.effect == null || pb == null || ab == null) { - //TODO log error here - return; - } - - int duration = ab.getDuration(trains); - String stackType = ab.getStackType(); - stackType = (stackType.equals("IgnoreStack")) ? Integer.toString(ab.getUUID()) : stackType; - FinishEffectTimeJob eff = new FinishEffectTimeJob(source, awo, stackType, trains, ab, pb, effect); - if (duration > 0) - awo.addEffect(stackType, duration, eff, effect, trains); - this.effect.startEffect(source, awo, trains, eff); - } - - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } - - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub - - } + private String effectID; + private EffectsBase effect; + + public TransformPowerAction(ResultSet rs, HashMap effects) throws SQLException { + super(rs); + + this.effectID = rs.getString("effectID"); + this.effect = effects.get(this.effectID); + } + + public String getEffectID() { + return this.effectID; + } + + public EffectsBase getEffect() { + return this.effect; + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + if (this.effect == null || pb == null || ab == null) { + //TODO log error here + return; + } + + int duration = ab.getDuration(trains); + String stackType = ab.getStackType(); + stackType = (stackType.equals("IgnoreStack")) ? Integer.toString(ab.getUUID()) : stackType; + FinishEffectTimeJob eff = new FinishEffectTimeJob(source, awo, stackType, trains, ab, pb, effect); + if (duration > 0) + awo.addEffect(stackType, duration, eff, effect, trains); + this.effect.startEffect(source, awo, trains, eff); + } + + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } + + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub + + } } diff --git a/src/engine/powers/poweractions/TreeChokePowerAction.java b/src/engine/powers/poweractions/TreeChokePowerAction.java index 00a93f14..d99be3c2 100644 --- a/src/engine/powers/poweractions/TreeChokePowerAction.java +++ b/src/engine/powers/poweractions/TreeChokePowerAction.java @@ -21,23 +21,23 @@ import java.sql.SQLException; public class TreeChokePowerAction extends AbstractPowerAction { - public TreeChokePowerAction(ResultSet rs) throws SQLException { - super(rs); - } + public TreeChokePowerAction(ResultSet rs) throws SQLException { + super(rs); + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + } - @Override - protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { - } + @Override + protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { + } - @Override - protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, - int numTrains, ActionsBase ab, PowersBase pb, int duration) { - // TODO Auto-generated method stub + @Override + protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, + int numTrains, ActionsBase ab, PowersBase pb, int duration) { + // TODO Auto-generated method stub - } + } } diff --git a/src/engine/server/MBServerStatics.java b/src/engine/server/MBServerStatics.java index cc20d2d6..80338e63 100644 --- a/src/engine/server/MBServerStatics.java +++ b/src/engine/server/MBServerStatics.java @@ -14,459 +14,401 @@ import engine.math.Vector3fImmutable; public class MBServerStatics { - public static final int revisionNumber = 1; - - public static String getEmulatorVersion() { - return Integer.toString(revisionNumber); - } - - public static final String CMDLINE_ARGS_EXE_NAME_DELIMITER = "-name"; - public static final String CMDLINE_ARGS_CONFIG_FILE_PATH_DELIMITER = "-config"; - public static final String CMDLINE_ARGS_CALLER_DELIMITER = "-caller"; - public static final String CMDLINE_ARGS_REASON_DELIMITER = "-reason"; - public static final String EXISTING_CONNECTION_CLOSED = "An existing connection was forcibly closed by the remote host"; - public static final String RESET_BY_PEER = "Connection reset by peer"; - /* - * ####Debugging Flags#### - */ - public static final boolean POWERS_DEBUG = false; - public static final boolean MOVEMENT_SYNC_DEBUG = false; - public static final boolean BONUS_TRAINS_ENABLED = false; - public static final boolean REGENS_DEBUG = false; - public static final boolean SHOW_SAFE_MODE_CHANGE = false; - public static final boolean COMBAT_TARGET_HITBOX_DEBUG = false; // output - // hit box - // calcs - public static final boolean PRINT_INCOMING_OPCODES = false; // print - // incoming - // opcodes to - // console - - public static final int BANK_GOLD_LIMIT = 25000000; - public static final int PLAYER_GOLD_LIMIT = 10000000; - - // buildings, npcs - /* - * Login cache flags - */ - public static final boolean SKIP_CACHE_LOGIN = false; // skip caching // login server - public static final boolean SKIP_CACHE_LOGIN_PLAYER = false; // skip caching // on login - public static final boolean SKIP_CACHE_LOGIN_ITEM = false; // skip caching - - /* - * ChatManager related - */ - public static final int SHOUT_PERCEPTION_RADIUS_MOD = 2; - /* - * DevCmd related - */ - public static final String DEV_CMD_PREFIX = "./"; - - /* - * JobManager related - */ - - // The number of elements in INITIAL_WORKERS defines the initial number of - // job pools - public static final int[] INITIAL_JOBPOOL_WORKERS = { 4, 2, 1 }; - public static final int JOBMANAGER_INTERNAL_MONITORING_INTERVAL_MS = 1000; - public static final int JOB_STALL_THRESHOLD_MS = 120 * 1000; - public static final int SCHEDULER_INITIAL_CAPACITY = 1000; - public static final int SCHEDULER_EXECUTION_TIME_COMPENSATION = 16; - - /* - * Concurrent Hash Map - Defaults - */ - - public static final int CHM_INIT_CAP = 10; - public static final float CHM_LOAD = 0.75f; - public static final int CHM_THREAD_HIGH = 4; - public static final int CHM_THREAD_MED = 2; - public static final int CHM_THREAD_LOW = 1; - - /* - * LoginErrorMsg related - */ - public static final int LOGINERROR_INVALID_USERNAME_PASSWORD = 1; - - /* - * Message is Version: - */ - public static final int LOGINERROR_INCORRECT_CLIENT_VERSION = 3; - public static final int LOGINERROR_NOT_ALLOWED_TO_LOGIN_YET = 4; - - /* - * Message is 'Error =' - */ - public static final int LOGINERROR_LOGINSERVER_IS_UNAVAILABLE = 5; - public static final int LOGINERROR_INVALID_ADMIN_USERNAME_PASSWORD = 6; - public static final int LOGINERROR_NO_MORE_PLAYTIME_ON_ACCOUNT = 7; - public static final int LOGINERROR_ACCOUNT_DOESNT_HAVE_SUBSCRIPTION = 8; - public static final int LOGINERROR_ACCOUNT_INSECURE_CHANGE_PASSWORD = 9; - public static final int LOGINERROR_TOO_MANY_LOGIN_TRIES = 10; - - /* - * Message is 'Error =' - */ - public static final int LOGINERROR_NOMOREPLAYTIME = 7; - public static final int LOGINERROR_INACTIVE = 8; - public static final int LOGINERROR_UNABLE_TO_LOGIN = 11; - public static final int LOGINERROR_LOGINSERVER_BUSY = 12; - public static final int LOGINERROR_BLANK = 13; - - /* - * Name Validation Related - */ - public static final int INVALIDNAME_FIRSTNAME_MUST_BE_LONGER = 1; - public static final int INVALIDNAME_FIRSTANDLAST_MUST_BE_SHORTER = 2; - public static final int INVALIDNAME_FIRSTNAME_MUST_NOT_HAVE_SPACES = 3; - public static final int INVALIDNAME_FIRSTNAME_INVALID_CHARACTERS = 4; - public static final int INVALIDNAME_PLEASE_CHOOSE_ANOTHER_FIRSTNAME = 5; - public static final int INVALIDNAME_PLEASE_CHOOSE_ANOTHER_LASTNAME = 7; - public static final int INVALIDNAME_LASTNAME_UNAVAILABLE = 8; - public static final int INVALIDNAME_FIRSTNAME_UNAVAILABLE = 9; - public static final int INVALIDNAME_WRONG_WORLD_ID = 10; - public static final int INVALIDNAME_GENERIC = 11; - - /* - * 1: A first name of at least 3 character(s) must be entered 2: Your first - * and last name cannot be more than 15 characters each. 3: Your first name - * may not contain spaces 4: There are invalid characters in the first name. - * 5: Please choose another first name 7: Please choose another last name 8: - * That last name is unavailable 9: That first name is unavailable 10: Your - * client sent an invalid world id 11: Invalid name. Choose another - */ - public static final int MIN_NAME_LENGTH = 3; - public static final int MAX_NAME_LENGTH = 15; - - /* - * ClientConnection related - */ - public static final boolean TCP_NO_DELAY_DEFAULT = true; - public static final byte MAX_CRYPTO_INIT_TRIES = 10; - - public static boolean DEBUG_PROTOCOL = false; - /* - * Account Related - */ - - public static final byte MAX_LOGIN_ATTEMPTS = 5; + public static final int revisionNumber = 1; + public static final String CMDLINE_ARGS_EXE_NAME_DELIMITER = "-name"; + public static final String CMDLINE_ARGS_CONFIG_FILE_PATH_DELIMITER = "-config"; + public static final String CMDLINE_ARGS_CALLER_DELIMITER = "-caller"; + public static final String CMDLINE_ARGS_REASON_DELIMITER = "-reason"; + public static final String EXISTING_CONNECTION_CLOSED = "An existing connection was forcibly closed by the remote host"; + public static final String RESET_BY_PEER = "Connection reset by peer"; + /* + * ####Debugging Flags#### + */ + public static final boolean POWERS_DEBUG = false; + public static final boolean MOVEMENT_SYNC_DEBUG = false; + public static final boolean BONUS_TRAINS_ENABLED = false; + public static final boolean REGENS_DEBUG = false; + public static final boolean SHOW_SAFE_MODE_CHANGE = false; + public static final boolean COMBAT_TARGET_HITBOX_DEBUG = false; // output + // hit box + // calcs + public static final boolean PRINT_INCOMING_OPCODES = false; // print + public static final int BANK_GOLD_LIMIT = 25000000; + // incoming + // opcodes to + // console + public static final int PLAYER_GOLD_LIMIT = 10000000; + // buildings, npcs + /* + * Login cache flags + */ + public static final boolean SKIP_CACHE_LOGIN = false; // skip caching // login server + public static final boolean SKIP_CACHE_LOGIN_PLAYER = false; // skip caching // on login + public static final boolean SKIP_CACHE_LOGIN_ITEM = false; // skip caching + /* + * ChatManager related + */ + public static final int SHOUT_PERCEPTION_RADIUS_MOD = 2; + /* + * DevCmd related + */ + public static final String DEV_CMD_PREFIX = "./"; + // The number of elements in INITIAL_WORKERS defines the initial number of + // job pools + public static final int[] INITIAL_JOBPOOL_WORKERS = {4, 2, 1}; + + /* + * JobManager related + */ + public static final int JOBMANAGER_INTERNAL_MONITORING_INTERVAL_MS = 1000; + public static final int JOB_STALL_THRESHOLD_MS = 120 * 1000; + public static final int SCHEDULER_INITIAL_CAPACITY = 1000; + public static final int SCHEDULER_EXECUTION_TIME_COMPENSATION = 16; + public static final int CHM_INIT_CAP = 10; + + /* + * Concurrent Hash Map - Defaults + */ + public static final float CHM_LOAD = 0.75f; + public static final int CHM_THREAD_HIGH = 4; + public static final int CHM_THREAD_MED = 2; + public static final int CHM_THREAD_LOW = 1; + /* + * LoginErrorMsg related + */ + public static final int LOGINERROR_INVALID_USERNAME_PASSWORD = 1; + /* + * Message is Version: + */ + public static final int LOGINERROR_INCORRECT_CLIENT_VERSION = 3; + public static final int LOGINERROR_NOT_ALLOWED_TO_LOGIN_YET = 4; + /* + * Message is 'Error =' + */ + public static final int LOGINERROR_LOGINSERVER_IS_UNAVAILABLE = 5; + public static final int LOGINERROR_INVALID_ADMIN_USERNAME_PASSWORD = 6; + public static final int LOGINERROR_NO_MORE_PLAYTIME_ON_ACCOUNT = 7; + public static final int LOGINERROR_ACCOUNT_DOESNT_HAVE_SUBSCRIPTION = 8; + public static final int LOGINERROR_ACCOUNT_INSECURE_CHANGE_PASSWORD = 9; + public static final int LOGINERROR_TOO_MANY_LOGIN_TRIES = 10; + /* + * Message is 'Error =' + */ + public static final int LOGINERROR_NOMOREPLAYTIME = 7; + public static final int LOGINERROR_INACTIVE = 8; + public static final int LOGINERROR_UNABLE_TO_LOGIN = 11; + public static final int LOGINERROR_LOGINSERVER_BUSY = 12; + public static final int LOGINERROR_BLANK = 13; + /* + * Name Validation Related + */ + public static final int INVALIDNAME_FIRSTNAME_MUST_BE_LONGER = 1; + public static final int INVALIDNAME_FIRSTANDLAST_MUST_BE_SHORTER = 2; + public static final int INVALIDNAME_FIRSTNAME_MUST_NOT_HAVE_SPACES = 3; + public static final int INVALIDNAME_FIRSTNAME_INVALID_CHARACTERS = 4; + public static final int INVALIDNAME_PLEASE_CHOOSE_ANOTHER_FIRSTNAME = 5; + public static final int INVALIDNAME_PLEASE_CHOOSE_ANOTHER_LASTNAME = 7; + public static final int INVALIDNAME_LASTNAME_UNAVAILABLE = 8; + public static final int INVALIDNAME_FIRSTNAME_UNAVAILABLE = 9; + public static final int INVALIDNAME_WRONG_WORLD_ID = 10; + public static final int INVALIDNAME_GENERIC = 11; + /* + * 1: A first name of at least 3 character(s) must be entered 2: Your first + * and last name cannot be more than 15 characters each. 3: Your first name + * may not contain spaces 4: There are invalid characters in the first name. + * 5: Please choose another first name 7: Please choose another last name 8: + * That last name is unavailable 9: That first name is unavailable 10: Your + * client sent an invalid world id 11: Invalid name. Choose another + */ + public static final int MIN_NAME_LENGTH = 3; + public static final int MAX_NAME_LENGTH = 15; + /* + * ClientConnection related + */ + public static final boolean TCP_NO_DELAY_DEFAULT = true; + public static final byte MAX_CRYPTO_INIT_TRIES = 10; + public static final byte MAX_LOGIN_ATTEMPTS = 5; public static final int RESET_LOGIN_ATTEMPTS_AFTER = (15 * 60 * 1000); // in + /* + * Account Related + */ public static final int MAX_ACTIVE_GAME_ACCOUNTS_PER_DISCORD_ACCOUNT = 4; // 0 - public static final byte MAX_NUM_OF_CHARACTERS = 7; - - public static final int STAT_STR_ID = 0x8AC3C0E6; - public static final int STAT_SPI_ID = 0xACB82E33; - public static final int STAT_CON_ID = 0xB15DC77E; - public static final int STAT_DEX_ID = 0xE07B3336; - public static final int STAT_INT_ID = 0xFF665EC3; - - public static final int SLOT_UNEQUIPPED = 0; - public static final int SLOT_MAINHAND = 1; - public static final int SLOT_OFFHAND = 2; - public static final int SLOT_HELMET = 3; - public static final int SLOT_CHEST = 4; - public static final int SLOT_ARMS = 5; - public static final int SLOT_GLOVES = 6; - public static final int SLOT_RING1 = 7; - public static final int SLOT_RING2 = 8; - public static final int SLOT_NECKLACE = 9; - public static final int SLOT_LEGGINGS = 10; - public static final int SLOT_FEET = 11; - public static final int SLOT_HAIRSTYLE = 18; // 17 & 18? Weird. - public static final int SLOT_BEARDSTYLE = 17; // 17 & 18? Weird. - - // Equip[0] = Slot1 = Weapon MainHand - // Equip[1] = Slot2 = OffHand - // Equip[2] = Slot3 = Helmet - // Equip[3] = Slot4 = Chest - // Equip[4] = Slot5 = Arms - // Equip[5] = Slot6 = Gloves - // Equip[6] = Slot7 = Ring1 - // Equip[7] = Slot8 = Ring2 - // Equip[8] = Slot9 = Necklace - // Equip[9] = Slot10 = Leggings - // Equip[10] = Slot11 = Feet - // Equip[11] = Slot17 = HairStyle - // Equip[12] = Slot18 = BeardStyle - - /* - * Group Formation Names - */ - public static final String[] FORMATION_NAMES = { "Column", "Line", "Box", - "Triangle", "Circle", "Ranks", "Wedge", "Inverse Wedge", "T" }; - - public static final int RUNE_COST_ATTRIBUTE_ID = 0; - - public static final int RUNE_STR_ATTRIBUTE_ID = 1; - public static final int RUNE_DEX_ATTRIBUTE_ID = 2; - public static final int RUNE_CON_ATTRIBUTE_ID = 3; - public static final int RUNE_INT_ATTRIBUTE_ID = 4; - public static final int RUNE_SPI_ATTRIBUTE_ID = 5; - - public static final int RUNE_STR_MAX_ATTRIBUTE_ID = 6; - public static final int RUNE_DEX_MAX_ATTRIBUTE_ID = 7; - public static final int RUNE_CON_MAX_ATTRIBUTE_ID = 8; - public static final int RUNE_INT_MAX_ATTRIBUTE_ID = 9; - public static final int RUNE_SPI_MAX_ATTRIBUTE_ID = 10; - - public static final int RUNE_STR_MIN_NEEDED_ATTRIBUTE_ID = 11; - public static final int RUNE_DEX_MIN_NEEDED_ATTRIBUTE_ID = 12; - public static final int RUNE_CON_MIN_NEEDED_ATTRIBUTE_ID = 13; - public static final int RUNE_INT_MIN_NEEDED_ATTRIBUTE_ID = 14; - public static final int RUNE_SPI_MIN_NEEDED_ATTRIBUTE_ID = 15; - - /* - * DBMan - */ - public static final int NO_DB_ROW_ASSIGNED_YET = Integer.MAX_VALUE; - - public static final boolean DB_DEBUGGING_ON_BY_DEFAULT = false; // warning: - - public static final boolean ENABLE_QUERY_TIME_WARNING = true; - public static final boolean ENABLE_UPDATE_TIME_WARNING = true; - public static final boolean ENABLE_EXECUTION_TIME_WARNING = true; - - public static final int AFK_TIMEOUT_MS = (30 * 60 * 1000) * 100; // Added - public static final int TIMEOUT_CHECKS_TIMER_MS = (60 * 1000); - - /* - * Masks for Quad Tree. Masks should be multiple of 2. - */ - - public static final int MASK_PLAYER = 1; - public static final int MASK_MOB = 2; - public static final int MASK_PET = 4; - public static final int MASK_CORPSE = 8; - public static final int MASK_BUILDING = 16; - public static final int MASK_UNDEAD = 64; - public static final int MASK_BEAST = 128; - public static final int MASK_HUMANOID = 256; - public static final int MASK_NPC = 512; - public static final int MASK_IAGENT = 2048; - - public static final int MASK_DRAGON = 4096; - public static final int MASK_RAT = 8192; - public static final int MASK_SIEGE = 16384; - public static final int MASK_CITY = 32768; - public static final int MASK_ZONE = 65536; - - /* - * Combined QT Masks. For convenience - */ - - public static final int MASK_AGGRO = 5; // Player, Pet - public static final int MASK_MOBILE = 7; // Player, Mob, Pet - public static final int MASK_STATIC = 568; // Corpse, Building, Trigger, NPC - - /* - * World Coordinate Data - */ - public static final double MAX_WORLD_HEIGHT = -98304.0; - public static final double MAX_WORLD_WIDTH = 131072.0; - public static final float SEA_FLOOR_ALTITUDE = -1000f; - public static int SPATIAL_HASH_BUCKETSX = 16384; - public static int SPATIAL_HASH_BUCKETSY = 12288; - public static float MAX_PLAYER_X_LOC = 129999; - public static float MAX_PLAYER_Y_LOC = -97000; - - /* - * Ranges - */ - public static final int CHARACTER_LOAD_RANGE = 400; // load range of mobile objects - // (default: 300) - public static final int STRUCTURE_LOAD_RANGE = 700; // load range of - // (default: 600) - - public static float LOOT_RANGE = 100; - public static final int EXP_RANGE = 400; - public static final int GOLD_SPLIT_RANGE = 600; - // non-moving objects - public static final int SAY_RANGE = 200; - public static final int SHOUT_RANGE = 300; - public static final int STATIC_THRESHOLD = 75; // Range must travel before - // reloading statics - public static final int FORMATION_RANGE = 75; // Max Distance a player can - // be from group lead on - // formation move - public static final int OPENCLOSEDOORDISTANCE = 128; // Max distance a - public static final int DOOR_CLOSE_TIMER = 30000; // 30 seconds - // player can be from a door in order to toggle its state - public static final int TRADE_RANGE = 10; // Max distance a player can be - // from another player to trade - public static final int NPC_TALK_RANGE = 20; // Range player can be to talk - // to npc - public static final int MAX_TELEPORT_RANGE = 1020; // Max range teleports - // will work at - public static final int RANGED_WEAPON_RANGE = 35; // any weapon attack - // range beyond this - // is ranged. - public static final int CALL_FOR_HELP_RADIUS = 100; // Range mobs will - // respond to calls - // for help - - public static final int TREE_TELEPORT_RADIUS = 30; - - public static float MOB_SPEED_WALK = 6.5f; - - public static float MOB_SPEED_WALKCOMBAT = 4.4f; - - public static float MOB_SPEED_RUN = 14.67f; - - public static float MOB_SPEED_RUNCOMBAT = 14.67f; - - - /* - * Noob Island Start Location for new players - */ - - public static final int[] DEFAULTGRID = {-1,1}; - public static final float startX = 19128;// 70149f; //19318.0f; - public static final float startY = 94f; // 94f; - public static final float startZ = -73553; // -73661.0f; - public static final Vector3fImmutable DEFAULT_START = new Vector3fImmutable( - MBServerStatics.startX, MBServerStatics.startY, - MBServerStatics.startZ); - - /* - * Base movement speeds. Do NOT modify these. They must match the client - */ - public static final float FLYWALKSPEED = 6.33f; - public static final float FLYRUNSPEED = 18.38f; - public static final float SWIMSPEED = 6.5f; - public static final float WALKSPEED = 6.5f; - public static final float RUNSPEED = 14.67f; - public static final float COMBATWALKSPEED = 4.44f; - public static final float COMBATRUNSPEED = 14.67f; - public static final float RUNSPEED_MOB = 15.4f; - - public static final float MOVEMENT_DESYNC_TOLERANCE = 2f; // Distance out of - - public static final float NO_WEAPON_RANGE = 8f; // Range for attack with no - // weapon - - - public static final float REGEN_IDLE = .06f; - /* - * Base regen rates. Do NOT modify these. They must match the client %per - * second for health/mana. x per second for stamina. - */ - public static final float HEALTH_REGEN_SIT = 0.0033333f; // 100% in 3 - // minutes - public static final float HEALTH_REGEN_IDLE = 0.000666667f; // 100% in 25 - // minutes - public static final float HEALTH_REGEN_WALK = 0.0005f; // 100% in 33.33 - // minutes - public static final float HEALTH_REGEN_RUN = 0f; - public static final float HEALTH_REGEN_SWIM_NOSTAMINA = -.03f; // 100% in - public static final float HEALTH_REGEN_SIT_STATIC = 0.33333f; // 100% in 3 - // minutes - public static final float HEALTH_REGEN_IDLE_STATIC = 0.0666667f; // 100% in - // 25 - // minutes - public static final float HEALTH_REGEN_WALK_STATIC = 0.05f; // 100% in 33.33 - // minutes - public static final float HEALTH_REGEN_RUN_STATIC = 0f; - public static final float HEALTH_REGEN_SWIM_NOSTAMINA_STATIC = 0f; // 100% - - public static final float MANA_REGEN_STATIC = 0.16666666666666666666666666666667f; - public static final float MANA_REGEN_SIT = 0.008333333f; // 100% in 2 - - public static final float MANA_REGEN_IDLE = 0.00166667f; // 100% in 10 - - public static final float MANA_REGEN_WALK = 0.00125f; // 100% in 13.333 - - public static final float MANA_REGEN_RUN = 0f; - public static final float STAMINA_REGEN_SIT = 2f; // 2 per second - public static final float STAMINA_REGEN_IDLE = 0.2f; // 1 per 5 seconds - public static final float STAMINA_REGEN_WALK = 0f; - public static final float STAMINA_REGEN_RUN_COMBAT = -0.6499999762f; - public static final float STAMINA_REGEN_RUN_NONCOMBAT = -0.400000006f; - public static final float STAMINA_REGEN_SWIM = -1f; // -1 per second - public static float STAMINA_REGEN_FLY_IDLE = -2f; // needs verifying - public static float STAMINA_REGEN_FLY_WALK = -1f; // needs verifying - public static float STAMINA_REGEN_FLY_RUN = -1.400000006f; // needs verifying - public static float STAMINA_REGEN_FLY_RUN_COMBAT = -1.6499999762f; // needs verifying - - public static final int REGEN_SENSITIVITY_PLAYER = 250; // calc regen ever X - public static final int REGEN_SENSITIVITY_MOB = 1000; // calc regen ever X - - public static final int TOMBSTONE = 2024; - - public static final int LOGOUT_TIMER_MS = 1000; // logout delay applied - public static final int CORPSE_CLEANUP_TIMER_MS = 15 * 60 * 1000; // Cleanup - public static final int DEFAULT_SPAWN_TIME_MS = 3 * 60 * 1000; // 3 minute - public static final int SESSION_CLEANUP_TIMER_MS = 30 * 1000; // cleanup - - public static final int MOVEMENT_FREQUENCY_MS = 1000; // Update movement - // once every X ms - public static final int FLY_FREQUENCY_MS = 1000; // Update flight once every - - public static final float FLY_RATE = .0078f; - // x ms - public static final int HEIGHT_CHANGE_TIMER_MS = 125; // Time in ms to fly - // up or down 1 unit - public static final long OPCODE_HANDLE_TIME_WARNING_MS = 250L; - public static final long DB_QUERY_WARNING_TIME_MS = 250L; - public static final long DB_UPDATE_WARNING_TIME_MS = 250L; - public static final long DB_EXECUTION_WARNING_TIME_MS = 250L; - public static boolean DB_ENABLE_QUERY_OUTPUT = false; - // summons - public static final int THIRTY_SECONDS = 30000; - public static final int FOURTYFIVE_SECONDS = 45000; - public static final int ONE_MINUTE = 60000; - public static final int FIVE_MINUTES = 300000; - public static final int FIFTEEN_MINUTES = 900000; - public static final int THIRTY_MINUTES = 1800000; - public static final long TWENTY_FOUR_HOURS = 86400000; - public static final int LOAD_OBJECT_DELAY = 500; // long to wait to update - - public static final int TELEPORT_TIME_IN_SECONDS = 10; - public static final int REPLEDGE_TIME_IN_SECONDS = 0; - public static final int RUNEGATE_CLOSE_TIME = 30000; // runegate close timer - public static final long PLAYER_KILL_XP_TIMER = 60 * 60 * 1000; // 60 - public static final int UPDATE_GROUP_RATE = 10000; // Update group info - public static float PLAYER_HATE_DELIMITER = 50; // reduces 50 hate a second - public static float PLAYER_COMBAT_HATE_MODIFIER = 2; - public static final int COMBAT_SEND_DODGE = 20; - public static final int COMBAT_SEND_BLOCK = 21; - public static final int COMBAT_SEND_PARRY = 22; - public static final short LEVELCAP = 75; - public static final int LEVEL_CON_WHITE = 7; - public static final int RESPAWN_TIMER = 90 * 1000; - public static final int DESPAWN_TIMER = 12 * 1000; - public static final int DESPAWN_TIMER_WITH_LOOT = 60 * 1000; - public static final int DESPAWN_TIMER_ONCE_LOOTED = 5 * 1000; - public static final int MAX_COMBAT_HITBOX_RADIUS = 80; - public static final int PROC_CHANCE = 5; // %chance to proc - + public static final byte MAX_NUM_OF_CHARACTERS = 7; + public static final int STAT_STR_ID = 0x8AC3C0E6; + public static final int STAT_SPI_ID = 0xACB82E33; + public static final int STAT_CON_ID = 0xB15DC77E; + public static final int STAT_DEX_ID = 0xE07B3336; + public static final int STAT_INT_ID = 0xFF665EC3; + public static final int SLOT_UNEQUIPPED = 0; + public static final int SLOT_MAINHAND = 1; + public static final int SLOT_OFFHAND = 2; + public static final int SLOT_HELMET = 3; + public static final int SLOT_CHEST = 4; + public static final int SLOT_ARMS = 5; + public static final int SLOT_GLOVES = 6; + public static final int SLOT_RING1 = 7; + public static final int SLOT_RING2 = 8; + public static final int SLOT_NECKLACE = 9; + public static final int SLOT_LEGGINGS = 10; + public static final int SLOT_FEET = 11; + public static final int SLOT_HAIRSTYLE = 18; // 17 & 18? Weird. + public static final int SLOT_BEARDSTYLE = 17; // 17 & 18? Weird. + /* + * Group Formation Names + */ + public static final String[] FORMATION_NAMES = {"Column", "Line", "Box", + "Triangle", "Circle", "Ranks", "Wedge", "Inverse Wedge", "T"}; + public static final int RUNE_COST_ATTRIBUTE_ID = 0; + + // Equip[0] = Slot1 = Weapon MainHand + // Equip[1] = Slot2 = OffHand + // Equip[2] = Slot3 = Helmet + // Equip[3] = Slot4 = Chest + // Equip[4] = Slot5 = Arms + // Equip[5] = Slot6 = Gloves + // Equip[6] = Slot7 = Ring1 + // Equip[7] = Slot8 = Ring2 + // Equip[8] = Slot9 = Necklace + // Equip[9] = Slot10 = Leggings + // Equip[10] = Slot11 = Feet + // Equip[11] = Slot17 = HairStyle + // Equip[12] = Slot18 = BeardStyle + public static final int RUNE_STR_ATTRIBUTE_ID = 1; + public static final int RUNE_DEX_ATTRIBUTE_ID = 2; + public static final int RUNE_CON_ATTRIBUTE_ID = 3; + public static final int RUNE_INT_ATTRIBUTE_ID = 4; + public static final int RUNE_SPI_ATTRIBUTE_ID = 5; + public static final int RUNE_STR_MAX_ATTRIBUTE_ID = 6; + public static final int RUNE_DEX_MAX_ATTRIBUTE_ID = 7; + public static final int RUNE_CON_MAX_ATTRIBUTE_ID = 8; + public static final int RUNE_INT_MAX_ATTRIBUTE_ID = 9; + public static final int RUNE_SPI_MAX_ATTRIBUTE_ID = 10; + public static final int RUNE_STR_MIN_NEEDED_ATTRIBUTE_ID = 11; + public static final int RUNE_DEX_MIN_NEEDED_ATTRIBUTE_ID = 12; + public static final int RUNE_CON_MIN_NEEDED_ATTRIBUTE_ID = 13; + public static final int RUNE_INT_MIN_NEEDED_ATTRIBUTE_ID = 14; + public static final int RUNE_SPI_MIN_NEEDED_ATTRIBUTE_ID = 15; + /* + * DBMan + */ + public static final int NO_DB_ROW_ASSIGNED_YET = Integer.MAX_VALUE; + public static final boolean DB_DEBUGGING_ON_BY_DEFAULT = false; // warning: + public static final boolean ENABLE_QUERY_TIME_WARNING = true; + public static final boolean ENABLE_UPDATE_TIME_WARNING = true; + public static final boolean ENABLE_EXECUTION_TIME_WARNING = true; + public static final int AFK_TIMEOUT_MS = (30 * 60 * 1000) * 100; // Added + public static final int TIMEOUT_CHECKS_TIMER_MS = (60 * 1000); + public static final int MASK_PLAYER = 1; + public static final int MASK_MOB = 2; + + /* + * Masks for Quad Tree. Masks should be multiple of 2. + */ + public static final int MASK_PET = 4; + public static final int MASK_CORPSE = 8; + public static final int MASK_BUILDING = 16; + public static final int MASK_UNDEAD = 64; + public static final int MASK_BEAST = 128; + public static final int MASK_HUMANOID = 256; + public static final int MASK_NPC = 512; + public static final int MASK_IAGENT = 2048; + public static final int MASK_DRAGON = 4096; + public static final int MASK_RAT = 8192; + public static final int MASK_SIEGE = 16384; + public static final int MASK_CITY = 32768; + public static final int MASK_ZONE = 65536; + public static final int MASK_AGGRO = 5; // Player, Pet + public static final int MASK_MOBILE = 7; // Player, Mob, Pet + + /* + * Combined QT Masks. For convenience + */ + public static final int MASK_STATIC = 568; // Corpse, Building, Trigger, NPC + /* + * World Coordinate Data + */ + public static final double MAX_WORLD_HEIGHT = -98304.0; + public static final double MAX_WORLD_WIDTH = 131072.0; + public static final float SEA_FLOOR_ALTITUDE = -1000f; + /* + * Ranges + */ + public static final int CHARACTER_LOAD_RANGE = 400; // load range of mobile objects + // (default: 300) + public static final int STRUCTURE_LOAD_RANGE = 700; // load range of + public static final int EXP_RANGE = 400; + public static final int GOLD_SPLIT_RANGE = 600; + // non-moving objects + public static final int SAY_RANGE = 200; + public static final int SHOUT_RANGE = 300; + public static final int STATIC_THRESHOLD = 75; // Range must travel before + // reloading statics + public static final int FORMATION_RANGE = 75; // Max Distance a player can + // (default: 600) + // be from group lead on + // formation move + public static final int OPENCLOSEDOORDISTANCE = 128; // Max distance a + public static final int DOOR_CLOSE_TIMER = 30000; // 30 seconds + // player can be from a door in order to toggle its state + public static final int TRADE_RANGE = 10; // Max distance a player can be + // from another player to trade + public static final int NPC_TALK_RANGE = 20; // Range player can be to talk + // to npc + public static final int MAX_TELEPORT_RANGE = 1020; // Max range teleports + // will work at + public static final int RANGED_WEAPON_RANGE = 35; // any weapon attack + // range beyond this + // is ranged. + public static final int CALL_FOR_HELP_RADIUS = 100; // Range mobs will + public static final int TREE_TELEPORT_RADIUS = 30; + public static final int[] DEFAULTGRID = {-1, 1}; + public static final float startX = 19128;// 70149f; //19318.0f; + public static final float startY = 94f; // 94f; + public static final float startZ = -73553; // -73661.0f; + public static final Vector3fImmutable DEFAULT_START = new Vector3fImmutable( + MBServerStatics.startX, MBServerStatics.startY, + MBServerStatics.startZ); + /* + * Base movement speeds. Do NOT modify these. They must match the client + */ + public static final float FLYWALKSPEED = 6.33f; + // respond to calls + // for help + public static final float FLYRUNSPEED = 18.38f; + public static final float SWIMSPEED = 6.5f; + public static final float WALKSPEED = 6.5f; + public static final float RUNSPEED = 14.67f; + public static final float COMBATWALKSPEED = 4.44f; + + + /* + * Noob Island Start Location for new players + */ + public static final float COMBATRUNSPEED = 14.67f; + public static final float RUNSPEED_MOB = 15.4f; + public static final float MOVEMENT_DESYNC_TOLERANCE = 2f; // Distance out of + public static final float NO_WEAPON_RANGE = 8f; // Range for attack with no + public static final float REGEN_IDLE = .06f; + /* + * Base regen rates. Do NOT modify these. They must match the client %per + * second for health/mana. x per second for stamina. + */ + public static final float HEALTH_REGEN_SIT = 0.0033333f; // 100% in 3 + // minutes + public static final float HEALTH_REGEN_IDLE = 0.000666667f; // 100% in 25 + // minutes + public static final float HEALTH_REGEN_WALK = 0.0005f; // 100% in 33.33 + // minutes + public static final float HEALTH_REGEN_RUN = 0f; + public static final float HEALTH_REGEN_SWIM_NOSTAMINA = -.03f; // 100% in + public static final float HEALTH_REGEN_SIT_STATIC = 0.33333f; // 100% in 3 + // minutes + public static final float HEALTH_REGEN_IDLE_STATIC = 0.0666667f; // 100% in + // 25 + // minutes + public static final float HEALTH_REGEN_WALK_STATIC = 0.05f; // 100% in 33.33 + // minutes + public static final float HEALTH_REGEN_RUN_STATIC = 0f; + public static final float HEALTH_REGEN_SWIM_NOSTAMINA_STATIC = 0f; // 100% + // weapon + public static final float MANA_REGEN_STATIC = 0.16666666666666666666666666666667f; + public static final float MANA_REGEN_SIT = 0.008333333f; // 100% in 2 + public static final float MANA_REGEN_IDLE = 0.00166667f; // 100% in 10 + public static final float MANA_REGEN_WALK = 0.00125f; // 100% in 13.333 + public static final float MANA_REGEN_RUN = 0f; + public static final float STAMINA_REGEN_SIT = 2f; // 2 per second + public static final float STAMINA_REGEN_IDLE = 0.2f; // 1 per 5 seconds + public static final float STAMINA_REGEN_WALK = 0f; + public static final float STAMINA_REGEN_RUN_COMBAT = -0.6499999762f; + public static final float STAMINA_REGEN_RUN_NONCOMBAT = -0.400000006f; + public static final float STAMINA_REGEN_SWIM = -1f; // -1 per second + public static final int REGEN_SENSITIVITY_PLAYER = 250; // calc regen ever X + public static final int REGEN_SENSITIVITY_MOB = 1000; // calc regen ever X + public static final int TOMBSTONE = 2024; + public static final int LOGOUT_TIMER_MS = 1000; // logout delay applied + public static final int CORPSE_CLEANUP_TIMER_MS = 15 * 60 * 1000; // Cleanup + public static final int DEFAULT_SPAWN_TIME_MS = 3 * 60 * 1000; // 3 minute + public static final int SESSION_CLEANUP_TIMER_MS = 30 * 1000; // cleanup + public static final int MOVEMENT_FREQUENCY_MS = 1000; // Update movement + // once every X ms + public static final int FLY_FREQUENCY_MS = 1000; // Update flight once every + public static final float FLY_RATE = .0078f; + // x ms + public static final int HEIGHT_CHANGE_TIMER_MS = 125; // Time in ms to fly + // up or down 1 unit + public static final long OPCODE_HANDLE_TIME_WARNING_MS = 250L; + public static final long DB_QUERY_WARNING_TIME_MS = 250L; + public static final long DB_UPDATE_WARNING_TIME_MS = 250L; + public static final long DB_EXECUTION_WARNING_TIME_MS = 250L; + // summons + public static final int THIRTY_SECONDS = 30000; + public static final int FOURTYFIVE_SECONDS = 45000; + public static final int ONE_MINUTE = 60000; + public static final int FIVE_MINUTES = 300000; + public static final int FIFTEEN_MINUTES = 900000; + public static final int THIRTY_MINUTES = 1800000; + public static final long TWENTY_FOUR_HOURS = 86400000; + public static final int LOAD_OBJECT_DELAY = 500; // long to wait to update + public static final int TELEPORT_TIME_IN_SECONDS = 10; + public static final int REPLEDGE_TIME_IN_SECONDS = 0; + public static final int RUNEGATE_CLOSE_TIME = 30000; // runegate close timer + public static final long PLAYER_KILL_XP_TIMER = 60 * 60 * 1000; // 60 + public static final int UPDATE_GROUP_RATE = 10000; // Update group info + public static final int COMBAT_SEND_DODGE = 20; + public static final int COMBAT_SEND_BLOCK = 21; + public static final int COMBAT_SEND_PARRY = 22; + public static final short LEVELCAP = 75; + public static final int LEVEL_CON_WHITE = 7; + public static final int RESPAWN_TIMER = 90 * 1000; + public static final int DESPAWN_TIMER = 12 * 1000; + public static final int DESPAWN_TIMER_WITH_LOOT = 60 * 1000; + public static final int DESPAWN_TIMER_ONCE_LOOTED = 5 * 1000; + public static final int MAX_COMBAT_HITBOX_RADIUS = 80; + public static final int PROC_CHANCE = 5; // %chance to proc + public static final float TRACK_ARROW_FAST_RANGE = 50f; // Range to go from + public static final int TRACK_ARROW_SENSITIVITY = 1000; // Refresh track + // arrows every X ms + public static final int TRACK_ARROW_SENSITIVITY_FAST = 250; // Refresh track + public static final int LOW_POPULATION = 100; + public static final int NORMAL_POPULATION = 500; + public static final int HIGH_POPULATION = 1000; + public static final int VERY_OVERPOPULATED_POPULATION = 3000; + public static final int FULL_POPULATION = 5000; + public static final int TRACK_WINDOW_THRESHOLD = 1000; // max refresh once + public static final int WHO_WINDOW_THRESHOLD = 3000; // max refresh once + // Mine related + public static final int MINE_EARLY_WINDOW = 16; // 4pm + public static final int MINE_LATE_WINDOW = 0; // Midnight + public static boolean DEBUG_PROTOCOL = false; + public static int SPATIAL_HASH_BUCKETSX = 16384; + public static int SPATIAL_HASH_BUCKETSY = 12288; + public static float MAX_PLAYER_X_LOC = 129999; + public static float MAX_PLAYER_Y_LOC = -97000; + public static float LOOT_RANGE = 100; + public static float MOB_SPEED_WALK = 6.5f; + public static float MOB_SPEED_WALKCOMBAT = 4.4f; + public static float MOB_SPEED_RUN = 14.67f; + public static float MOB_SPEED_RUNCOMBAT = 14.67f; + public static float STAMINA_REGEN_FLY_IDLE = -2f; // needs verifying + public static float STAMINA_REGEN_FLY_WALK = -1f; // needs verifying + public static float STAMINA_REGEN_FLY_RUN = -1.400000006f; // needs verifying + public static float STAMINA_REGEN_FLY_RUN_COMBAT = -1.6499999762f; // needs verifying + public static boolean DB_ENABLE_QUERY_OUTPUT = false; + public static float PLAYER_HATE_DELIMITER = 50; // reduces 50 hate a second + public static float PLAYER_COMBAT_HATE_MODIFIER = 2; // DO NOT FINAL THESE FIELD! public static Enum.AccountStatus accessLevel; // Min account level to login to server public static boolean blockLogin = false; - public static boolean ENABLE_VAULT_FILL = false; - public static boolean ENABLE_MOB_LOOT = true; - public static boolean ENABLE_AUDIT_JOB_WORKERS = true; - public static boolean ENABLE_COMBAT_TARGET_HITBOX = true; - - public static final float TRACK_ARROW_FAST_RANGE = 50f; // Range to go from - - public static final int TRACK_ARROW_SENSITIVITY = 1000; // Refresh track - // arrows every X ms - public static final int TRACK_ARROW_SENSITIVITY_FAST = 250; // Refresh track - public static final int LOW_POPULATION = 100; - public static final int NORMAL_POPULATION = 500; - public static final int HIGH_POPULATION = 1000; - public static final int VERY_OVERPOPULATED_POPULATION = 3000; - public static final int FULL_POPULATION = 5000; - public static final int TRACK_WINDOW_THRESHOLD = 1000; // max refresh once - public static final int WHO_WINDOW_THRESHOLD = 3000; // max refresh once - - - // Mine related - public static final int MINE_EARLY_WINDOW = 16; // 4pm - public static final int MINE_LATE_WINDOW = 0; // Midnight + public static boolean ENABLE_VAULT_FILL = false; + public static boolean ENABLE_MOB_LOOT = true; + public static boolean ENABLE_AUDIT_JOB_WORKERS = true; + public static boolean ENABLE_COMBAT_TARGET_HITBOX = true; public static String JUNIOR = "Junior"; public static String VETERAN = "Veteran"; public static String ELITE = "Elite"; + public static String getEmulatorVersion() { + return Integer.toString(revisionNumber); + } + } diff --git a/src/engine/server/login/LoginServer.java b/src/engine/server/login/LoginServer.java index c3c1c687..06e8f71c 100644 --- a/src/engine/server/login/LoginServer.java +++ b/src/engine/server/login/LoginServer.java @@ -50,16 +50,21 @@ public class LoginServer { // Instance variables - private VersionInfoMsg versionInfoMessage; public static int population = 0; public static boolean worldServerRunning = false; public static boolean loginServerRunning = false; - public static ServerStatusMsg serverStatusMsg = new ServerStatusMsg(0, (byte) 1); + private VersionInfoMsg versionInfoMessage; // This is the entrypoint for the MagicBane Login Server when // it is executed by the command line scripts. The fun begins here! + public LoginServer() { + + } + + // Mainline execution loop for the login server. + public static void main(String[] args) { LoginServer loginServer; @@ -83,8 +88,8 @@ public class LoginServer { ConfigManager.serverType = Enum.ServerType.LOGINSERVER; if (ConfigManager.init() == false) { - Logger.error("ABORT! Missing config entry!"); - return; + Logger.error("ABORT! Missing config entry!"); + return; } // Start the Login Server @@ -101,7 +106,68 @@ public class LoginServer { } } - // Mainline execution loop for the login server. + // Constructor + + public static boolean getActiveBaneQuery(PlayerCharacter playerCharacter) { + + boolean outStatus = false; + + // char has never logged on so cannot have dropped a bane + + if (playerCharacter.getHash() == null) + return outStatus; + + // query data warehouse for unresolved bane with this character + + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = buildQueryActiveBaneStatement(connection, playerCharacter); + ResultSet rs = statement.executeQuery()) { + + while (rs.next()) { + + outStatus = true; + } + + } catch (SQLException e) { + Logger.error(e.toString()); + } + + return outStatus; + } + + private static PreparedStatement buildQueryActiveBaneStatement(Connection connection, PlayerCharacter playerCharacter) throws SQLException { + PreparedStatement outStatement; + String queryString = "SELECT `city_id` FROM `warehouse_banehistory` WHERE `char_id` = ? AND `RESOLUTION` = 'PENDING'"; + outStatement = connection.prepareStatement(queryString); + outStatement.setString(1, playerCharacter.getHash()); + return outStatement; + + } + + public static boolean isPortInUse(int port) { + + ProcessBuilder builder = new ProcessBuilder("/bin/bash", "-c", "lsof -i tcp:" + port + " | tail -n +2 | awk '{print $2}'"); + builder.redirectErrorStream(true); + Process process = null; + String line = null; + boolean portInUse = false; + + try { + process = builder.start(); + + InputStream is = process.getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + + while ((line = reader.readLine()) != null) { + portInUse = true; + } + + } catch (IOException e) { + e.printStackTrace(); + } + + return portInUse; + } private void exec() { @@ -117,49 +183,43 @@ public class LoginServer { // Invalidate cache for players driven by forum // and stored procedure forum_link_pass() - // Run cache routine right away if requested. + // Run cache routine right away if requested. - File cacheFile = new File("cacheInvalid"); + File cacheFile = new File("cacheInvalid"); - if (cacheFile.exists() == true) { + if (cacheFile.exists() == true) { - nextCacheTime = LocalDateTime.now(); + nextCacheTime = LocalDateTime.now(); - try { - Files.deleteIfExists(Paths.get("cacheInvalid")); - } catch (IOException e) { - throw new RuntimeException(e); - } + try { + Files.deleteIfExists(Paths.get("cacheInvalid")); + } catch (IOException e) { + throw new RuntimeException(e); } + } - if (LocalDateTime.now().isAfter(nextCacheTime)) { - invalidateCacheList(); - nextCacheTime = LocalDateTime.now().plusSeconds(30); - } + if (LocalDateTime.now().isAfter(nextCacheTime)) { + invalidateCacheList(); + nextCacheTime = LocalDateTime.now().plusSeconds(30); + } - if (LocalDateTime.now().isAfter(nextServerTime)) { - checkServerHealth(); - nextServerTime = LocalDateTime.now().plusSeconds(1); - } + if (LocalDateTime.now().isAfter(nextServerTime)) { + checkServerHealth(); + nextServerTime = LocalDateTime.now().plusSeconds(1); + } - if (LocalDateTime.now().isAfter(nextDatabaseTime)) { - String pop = SimulationManager.getPopulationString(); - Logger.info("Keepalive: " + pop); - nextDatabaseTime = LocalDateTime.now().plusMinutes(30); - } + if (LocalDateTime.now().isAfter(nextDatabaseTime)) { + String pop = SimulationManager.getPopulationString(); + Logger.info("Keepalive: " + pop); + nextDatabaseTime = LocalDateTime.now().plusMinutes(30); + } - ThreadUtils.sleep(100); + ThreadUtils.sleep(100); } } - // Constructor - - public LoginServer() { - - } - private boolean init() { // Initialize Application Protocol @@ -219,6 +279,13 @@ public class LoginServer { Logger.info("***Boot Successful***"); return true; } + /* + * message handlers (relay) + */ + + // ============================== + // Support Functions + // ============================== private boolean initDatabaseLayer() { @@ -288,13 +355,6 @@ public class LoginServer { Logger.error(e.toString()); } } - /* - * message handlers (relay) - */ - - // ============================== - // Support Functions - // ============================== public VersionInfoMsg getDefaultVersionInfo() { return versionInfoMessage; @@ -406,67 +466,6 @@ public class LoginServer { } - public static boolean getActiveBaneQuery(PlayerCharacter playerCharacter) { - - boolean outStatus = false; - - // char has never logged on so cannot have dropped a bane - - if (playerCharacter.getHash() == null) - return outStatus; - - // query data warehouse for unresolved bane with this character - - try (Connection connection = DbManager.getConnection(); - PreparedStatement statement = buildQueryActiveBaneStatement(connection, playerCharacter); - ResultSet rs = statement.executeQuery()) { - - while (rs.next()) { - - outStatus = true; - } - - } catch (SQLException e) { - Logger.error(e.toString()); - } - - return outStatus; - } - - private static PreparedStatement buildQueryActiveBaneStatement(Connection connection, PlayerCharacter playerCharacter) throws SQLException { - PreparedStatement outStatement; - String queryString = "SELECT `city_id` FROM `warehouse_banehistory` WHERE `char_id` = ? AND `RESOLUTION` = 'PENDING'"; - outStatement = connection.prepareStatement(queryString); - outStatement.setString(1, playerCharacter.getHash()); - return outStatement; - - } - - public static boolean isPortInUse(int port) { - - ProcessBuilder builder = new ProcessBuilder("/bin/bash", "-c", "lsof -i tcp:" + port + " | tail -n +2 | awk '{print $2}'"); - builder.redirectErrorStream(true); - Process process = null; - String line = null; - boolean portInUse = false; - - try { - process = builder.start(); - - InputStream is = process.getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(is)); - - while ((line = reader.readLine()) != null) { - portInUse = true; - } - - } catch (IOException e) { - e.printStackTrace(); - } - - return portInUse; - } - private int readPopulationFile() { ProcessBuilder builder = new ProcessBuilder("/bin/bash", "-c", "cat " + ConfigManager.DEFAULT_DATA_DIR + ConfigManager.MB_WORLD_NAME.getValue().replaceAll("'", "") + ".pop"); diff --git a/src/engine/server/login/LoginServerMsgHandler.java b/src/engine/server/login/LoginServerMsgHandler.java index 54434e8b..0e920b7d 100644 --- a/src/engine/server/login/LoginServerMsgHandler.java +++ b/src/engine/server/login/LoginServerMsgHandler.java @@ -44,6 +44,18 @@ public class LoginServerMsgHandler implements NetMsgHandler { this.server = server; } + public static void sendInvalidNameMsg(String firstName, String lastName, int errorCode, ClientConnection clientConnection) { + + InvalidNameMsg invalidNameMessage; + + if (firstName.length() > 256 || lastName.length() > 256) + invalidNameMessage = new InvalidNameMsg(firstName, lastName, errorCode); + else + invalidNameMessage = new InvalidNameMsg(firstName, lastName, errorCode); + + clientConnection.sendMsg(invalidNameMessage); + } + /* * ========================================================================= * Client Messages @@ -124,7 +136,7 @@ public class LoginServerMsgHandler implements NetMsgHandler { cMajorVer = vim.getMajorVersion(); cMinorVer = vim.getMinorVersion(); - if (!cMajorVer.equals(this.server.getDefaultVersionInfo().getMajorVersion())) { + if (!cMajorVer.equals(this.server.getDefaultVersionInfo().getMajorVersion())) { this.KickToLogin(MBServerStatics.LOGINERROR_INCORRECT_CLIENT_VERSION, "Major Version Failure: " + cMajorVer, cc); return; } @@ -139,7 +151,7 @@ public class LoginServerMsgHandler implements NetMsgHandler { return; } - if (cMinorVer.length() < 8 || cMinorVer.length() > 16) { + if (cMinorVer.length() < 8 || cMinorVer.length() > 16) { this.KickToLogin(MBServerStatics.LOGINERROR_INCORRECT_CLIENT_VERSION, "Minor Version Failure: ", cc); return; } @@ -149,7 +161,7 @@ public class LoginServerMsgHandler implements NetMsgHandler { cc.machineID = cMinorVer; // send fake right back to the client - outVim = new VersionInfoMsg(vim.getMajorVersion(), this.server.getDefaultVersionInfo().getMinorVersion() ); + outVim = new VersionInfoMsg(vim.getMajorVersion(), this.server.getDefaultVersionInfo().getMinorVersion()); cc.sendMsg(outVim); } @@ -186,9 +198,9 @@ public class LoginServerMsgHandler implements NetMsgHandler { return; } - Logger.info("AutoRegister: " + uname + "/" + pass); - DbManager.AccountQueries.CREATE_SINGLE(uname, pass); - account = DbManager.AccountQueries.GET_ACCOUNT(uname); + Logger.info("AutoRegister: " + uname + "/" + pass); + DbManager.AccountQueries.CREATE_SINGLE(uname, pass); + account = DbManager.AccountQueries.GET_ACCOUNT(uname); if (account == null) { this.KickToLogin(MBServerStatics.LOGINERROR_INVALID_USERNAME_PASSWORD, "Could not find account (" + uname + ')', clientConnection); @@ -353,18 +365,6 @@ public class LoginServerMsgHandler implements NetMsgHandler { } } - public static void sendInvalidNameMsg(String firstName, String lastName, int errorCode, ClientConnection clientConnection) { - - InvalidNameMsg invalidNameMessage; - - if (firstName.length() > 256 || lastName.length() > 256) - invalidNameMessage = new InvalidNameMsg(firstName, lastName, errorCode); - else - invalidNameMessage = new InvalidNameMsg(firstName, lastName, errorCode); - - clientConnection.sendMsg(invalidNameMessage); - } - private void DeleteCharacter(DeleteCharacterMsg msg, ClientConnection origin) { try { diff --git a/src/engine/session/CSSession.java b/src/engine/session/CSSession.java index c6704d96..675f394c 100644 --- a/src/engine/session/CSSession.java +++ b/src/engine/session/CSSession.java @@ -19,105 +19,106 @@ import java.net.InetAddress; public class CSSession extends AbstractGameObject { - private String sessionID; - private PlayerCharacter playerCharacter; - private Account account; - - - private String machineID; - - public CSSession(String sessionID, Account acc, PlayerCharacter pc, String machineID) { - super(); - this.sessionID = sessionID; - this.playerCharacter = pc; - this.account = acc; - this.machineID = machineID; - - if (this.playerCharacter != null) - PlayerCharacter.initializePlayer(this.playerCharacter); - } - - public PlayerCharacter getPlayerCharacter() { - return this.playerCharacter; - } - - public void setPlayerCharacter(PlayerCharacter pc) { - this.playerCharacter = pc; - } - - public Account getAccount() { - return this.account; - } - - public void setAccount(Account acc) { - this.account = acc; - } - - @Override - public void removeFromCache() {} - - /* - * Database - */ - public static boolean addCrossServerSession(String secKey, Account acc, InetAddress inet, String machineID) { - return DbManager.CSSessionQueries.ADD_CSSESSION(secKey, acc, inet, machineID); - // PreparedStatementShared ps = null; - // try { - // ps = prepareStatement("INSERT INTO sessions (secretKey, accountID, vbID, sessionIP) VALUES (?,?,?,INET_ATON(?))"); - // ps.setString(1, secKey); - // ps.setInt(2, acc.getUUID(), true); - // ps.setInt(3, acc.getVBID()); - // ps.setString(4, StringUtils.InetAddressToClientString(inet)); - // if (ps.executeUpdate() > 0) - // return true; - // } catch (SQLException e) { - // Logger.error("CSSession", "Failed to create cross server session"); - // } finally { - // ps.release(); - // } - // return false; - } - - public static boolean deleteCrossServerSession(String secKey) { - return DbManager.CSSessionQueries.DELETE_CSSESSION(secKey); - // PreparedStatementShared ps = null; - // try { - // ps = prepareStatement("DELETE FROM sessions WHERE secretKey = ?"); - // ps.setString(1, secKey); - // if (ps.executeUpdate() > 0) - // return true; - // } catch (SQLException e) { - // Logger.error("CSSession", "Failed to delete cross server session"); - // } finally { - // ps.release(); - // } - // return false; - } - - public static boolean updateCrossServerSession(String secKey, int charID) { - return DbManager.CSSessionQueries.UPDATE_CSSESSION(secKey, charID); - } - - public static CSSession getCrossServerSession(String secKey) { - - CSSession sessionInfo; - - try { - sessionInfo = DbManager.CSSessionQueries.GET_CSSESSION(secKey); - } catch (Exception e) { - sessionInfo = null; - } - - return sessionInfo; - } - - public String getMachineID() { - return machineID; - } - - @Override - public void updateDatabase() { - // TODO Auto-generated method stub - - } + private String sessionID; + private PlayerCharacter playerCharacter; + private Account account; + + + private String machineID; + + public CSSession(String sessionID, Account acc, PlayerCharacter pc, String machineID) { + super(); + this.sessionID = sessionID; + this.playerCharacter = pc; + this.account = acc; + this.machineID = machineID; + + if (this.playerCharacter != null) + PlayerCharacter.initializePlayer(this.playerCharacter); + } + + /* + * Database + */ + public static boolean addCrossServerSession(String secKey, Account acc, InetAddress inet, String machineID) { + return DbManager.CSSessionQueries.ADD_CSSESSION(secKey, acc, inet, machineID); + // PreparedStatementShared ps = null; + // try { + // ps = prepareStatement("INSERT INTO sessions (secretKey, accountID, vbID, sessionIP) VALUES (?,?,?,INET_ATON(?))"); + // ps.setString(1, secKey); + // ps.setInt(2, acc.getUUID(), true); + // ps.setInt(3, acc.getVBID()); + // ps.setString(4, StringUtils.InetAddressToClientString(inet)); + // if (ps.executeUpdate() > 0) + // return true; + // } catch (SQLException e) { + // Logger.error("CSSession", "Failed to create cross server session"); + // } finally { + // ps.release(); + // } + // return false; + } + + public static boolean deleteCrossServerSession(String secKey) { + return DbManager.CSSessionQueries.DELETE_CSSESSION(secKey); + // PreparedStatementShared ps = null; + // try { + // ps = prepareStatement("DELETE FROM sessions WHERE secretKey = ?"); + // ps.setString(1, secKey); + // if (ps.executeUpdate() > 0) + // return true; + // } catch (SQLException e) { + // Logger.error("CSSession", "Failed to delete cross server session"); + // } finally { + // ps.release(); + // } + // return false; + } + + public static boolean updateCrossServerSession(String secKey, int charID) { + return DbManager.CSSessionQueries.UPDATE_CSSESSION(secKey, charID); + } + + public static CSSession getCrossServerSession(String secKey) { + + CSSession sessionInfo; + + try { + sessionInfo = DbManager.CSSessionQueries.GET_CSSESSION(secKey); + } catch (Exception e) { + sessionInfo = null; + } + + return sessionInfo; + } + + public PlayerCharacter getPlayerCharacter() { + return this.playerCharacter; + } + + public void setPlayerCharacter(PlayerCharacter pc) { + this.playerCharacter = pc; + } + + public Account getAccount() { + return this.account; + } + + public void setAccount(Account acc) { + this.account = acc; + } + + @Override + public void removeFromCache() { + } + + public String getMachineID() { + return machineID; + } + + @Override + public void updateDatabase() { + // TODO Auto-generated method stub + + } } diff --git a/src/engine/session/Session.java b/src/engine/session/Session.java index d02ffd94..8a8de33c 100644 --- a/src/engine/session/Session.java +++ b/src/engine/session/Session.java @@ -7,7 +7,7 @@ // www.magicbane.com - package engine.session; +package engine.session; import engine.Enum; import engine.gameManager.DbManager; @@ -18,54 +18,54 @@ import engine.objects.PlayerCharacter; public class Session { - private SessionID sessionID; - private PlayerCharacter playerCharacter; - private Account account; - private ClientConnection conn; - - public Session(SessionID sessionID, Account acc, ClientConnection conn) { - super(); - this.sessionID = sessionID; - this.playerCharacter = null; - this.account = acc; - this.conn = conn; - } - - public PlayerCharacter getPlayerCharacter() { - if (this.playerCharacter != null) { - - if (DbManager.inCache(Enum.GameObjectType.PlayerCharacter, this.playerCharacter.getObjectUUID())) - this.playerCharacter = (PlayerCharacter) DbManager.getFromCache(Enum.GameObjectType.PlayerCharacter, this.playerCharacter.getObjectUUID()); - } - return this.playerCharacter; - } - - public void setPlayerCharacter(PlayerCharacter pc) { - this.playerCharacter = pc; - } - - public SessionID getSessionID() { - return this.sessionID; - } - - public void setSessionID(SessionID sessionID) { - this.sessionID = sessionID; - } - - public Account getAccount() { - return this.account; - } - - public void setAccount(Account acc) { - this.account = acc; - } - - public ClientConnection getConn() { - return this.conn; - } - - public void setConn(ClientConnection conn) { - this.conn = conn; - } + private SessionID sessionID; + private PlayerCharacter playerCharacter; + private Account account; + private ClientConnection conn; + + public Session(SessionID sessionID, Account acc, ClientConnection conn) { + super(); + this.sessionID = sessionID; + this.playerCharacter = null; + this.account = acc; + this.conn = conn; + } + + public PlayerCharacter getPlayerCharacter() { + if (this.playerCharacter != null) { + + if (DbManager.inCache(Enum.GameObjectType.PlayerCharacter, this.playerCharacter.getObjectUUID())) + this.playerCharacter = (PlayerCharacter) DbManager.getFromCache(Enum.GameObjectType.PlayerCharacter, this.playerCharacter.getObjectUUID()); + } + return this.playerCharacter; + } + + public void setPlayerCharacter(PlayerCharacter pc) { + this.playerCharacter = pc; + } + + public SessionID getSessionID() { + return this.sessionID; + } + + public void setSessionID(SessionID sessionID) { + this.sessionID = sessionID; + } + + public Account getAccount() { + return this.account; + } + + public void setAccount(Account acc) { + this.account = acc; + } + + public ClientConnection getConn() { + return this.conn; + } + + public void setConn(ClientConnection conn) { + this.conn = conn; + } } diff --git a/src/engine/session/SessionID.java b/src/engine/session/SessionID.java index 921b976b..802d831c 100644 --- a/src/engine/session/SessionID.java +++ b/src/engine/session/SessionID.java @@ -13,38 +13,38 @@ import engine.util.ByteUtils; public class SessionID { - private final byte[] data; - private final String dataAsString; - - public SessionID(byte[] data) { - super(); - this.data = data; - this.dataAsString = ByteUtils.byteArrayToStringHex(data); - } - - @Override - public boolean equals(Object obj) { - boolean out = false; - if(obj instanceof SessionID) { - out = true; - SessionID id = (SessionID) obj; - for (int i = 0; out && i < id.data.length; ++i) { - if (id.data[i] != this.data[i]) { - out = false; - } - } - } - - return out; - } - - @Override - public String toString() { - return this.dataAsString; - } - - public final byte[] getData() { - return data; - } + private final byte[] data; + private final String dataAsString; + + public SessionID(byte[] data) { + super(); + this.data = data; + this.dataAsString = ByteUtils.byteArrayToStringHex(data); + } + + @Override + public boolean equals(Object obj) { + boolean out = false; + if (obj instanceof SessionID) { + out = true; + SessionID id = (SessionID) obj; + for (int i = 0; out && i < id.data.length; ++i) { + if (id.data[i] != this.data[i]) { + out = false; + } + } + } + + return out; + } + + @Override + public String toString() { + return this.dataAsString; + } + + public final byte[] getData() { + return data; + } } diff --git a/src/engine/util/ByteAnalyzer.java b/src/engine/util/ByteAnalyzer.java index a70de21c..3f84444d 100644 --- a/src/engine/util/ByteAnalyzer.java +++ b/src/engine/util/ByteAnalyzer.java @@ -7,7 +7,7 @@ // www.magicbane.com - package engine.util; +package engine.util; import java.io.ByteArrayInputStream; import java.io.DataInputStream; @@ -15,210 +15,210 @@ import java.io.IOException; public class ByteAnalyzer { - public static void analyze4Bytes(byte[] data, String Label, - boolean switchEndian) throws IOException { - - ByteArrayInputStream bias = new ByteArrayInputStream(data); - DataInputStream dis = new DataInputStream(bias); - dis.mark(4); - - System.out.println("Analysis 4 bytes: (" + Label + ')'); - System.out.println("\t Hex: " + ByteUtils.byteArrayToStringHex(data)); - System.out.println(ByteAnalyzer.buildAll4(dis, switchEndian)); - System.out.println(ByteAnalyzer.buildUTF8(dis)); - System.out.println(ByteAnalyzer.buildUTF16(dis)); - System.out.println(ByteAnalyzer.buildRawNumericalBytes(dis)); - System.out.println(); - } - - public static void analyze8Bytes(byte[] data, String Label, - boolean switchEndian) throws IOException { - - ByteArrayInputStream bias = new ByteArrayInputStream(data); - DataInputStream dis = new DataInputStream(bias); - dis.mark(8); - - System.out.println("Analysis for 8 bytes: (" + Label + ')'); - System.out.println("\tHex: " + ByteUtils.byteArrayToStringHex(data)); - System.out.println(ByteAnalyzer.buildAll8(dis, switchEndian)); - dis.reset(); - System.out.println(ByteAnalyzer.buildUTF8(dis)); - System.out.println(ByteAnalyzer.buildUTF16(dis)); - System.out.println(ByteAnalyzer.buildRawNumericalBytes(dis)); - System.out.println("\n"); - } - - public static String buildAll8(DataInputStream indis, boolean se) - throws IOException { - byte[] ba = new byte[8]; - indis.read(ba); - DataInputStream dis = new DataInputStream(new ByteArrayInputStream(ba)); - dis.mark(8); - - String out = ""; - - out += buildFromTemplate("8", dis, se); - out += buildFromTemplate("4.4", dis, se); - - out += buildFromTemplate("4.2.2", dis, se); - out += buildFromTemplate("4.2.1.1", dis, se); - out += buildFromTemplate("4.1.2.1", dis, se); - out += buildFromTemplate("4.1.1.2", dis, se); - out += buildFromTemplate("4.1.1.1.1", dis, se); - - out += buildFromTemplate("2.2.4", dis, se); - out += buildFromTemplate("2.1.1.4", dis, se); - out += buildFromTemplate("1.2.1.4", dis, se); - out += buildFromTemplate("1.1.2.4", dis, se); - out += buildFromTemplate("1.1.1.1.4", dis, se); - - out += buildFromTemplate("2.4.2", dis, se); - out += buildFromTemplate("2.4.1.1", dis, se); - out += buildFromTemplate("1.1.4.2", dis, se); - out += buildFromTemplate("1.1.4.1.1", dis, se); - - out += buildFromTemplate("2.1.2.2.1", dis, se); - out += buildFromTemplate("2.1.2.1.2", dis, se); - out += buildFromTemplate("1.2.2.2.1", dis, se); - out += buildFromTemplate("1.2.2.1.2", dis, se); - - out += buildFromTemplate("1.1.1.2.2.1", dis, se); - out += buildFromTemplate("2.1.2.1.1.1", dis, se); - out += buildFromTemplate("1.1.1.2.1.1.1", dis, se); - out += buildFromTemplate("1.1.1.1.1.1.1.1", dis, se); - - out += buildFromTemplate("2.1.1.1.1.1.1", dis, se); - out += buildFromTemplate("1.2.1.1.1.1.1", dis, se); - out += buildFromTemplate("1.1.2.1.1.1.1", dis, se); - - out += buildFromTemplate("1.1.1.1.2.1.1", dis, se); - out += buildFromTemplate("1.1.1.1.1.2.1", dis, se); - out += buildFromTemplate("1.1.1.1.1.1.2", dis, se); - - return out; - } - - public static String buildAll4(DataInputStream indis, boolean se) - throws IOException { - byte[] ba = new byte[4]; - indis.read(ba); - DataInputStream dis = new DataInputStream(new ByteArrayInputStream(ba)); - dis.mark(4); - - String out = ""; - out += buildFromTemplate("4", dis, se); - out += buildFromTemplate("2.2", dis, se); - out += buildFromTemplate("2.1.1", dis, se); - out += buildFromTemplate("1.2.1", dis, se); - out += buildFromTemplate("1.1.2", dis, se); - out += buildFromTemplate("1.1.1.1", dis, se); - - return out; - } - - public static String buildFromTemplate(String template, - DataInputStream dis, boolean se) throws IOException { - String out = '\t' + template + ": "; - - for (int i = template.length(); i < 16; ++i) { - out += " "; - } - - template = template.replace(".", ""); - String[] items = template.split(""); - dis.mark(dis.available()); - - for (String s : items) { - if (s.equals("1")) { - out += " (B:" + dis.readByte(); - dis.reset(); - out += "/uB:" + dis.readUnsignedByte() + ')'; - } else if (s.equals("2")) { - byte[] read = new byte[2]; - dis.read(read); - byte[] use = new byte[2]; - if (se) { - use = ByteUtils.switchByteArrayEndianness(read); - } else { - use = read; - } - out += " (S:" - + new DataInputStream(new ByteArrayInputStream(use)) - .readShort(); - out += "/uS:" - + new DataInputStream(new ByteArrayInputStream(use)) - .readUnsignedShort() + ')'; - - } else if (s.equals("4")) { - byte[] read = new byte[4]; - dis.read(read); - byte[] use = new byte[4]; - if (se) { - use = ByteUtils.switchByteArrayEndianness(read); - } else { - use = read; - } - out += " (I:"; - out += new DataInputStream(new ByteArrayInputStream(use)) - .readInt(); - - out += " / F:"; - out += new DataInputStream(new ByteArrayInputStream(use)) - .readFloat() - + ")"; - } else if (s.equals("8")) { - byte[] read = new byte[8]; - dis.read(read); - - byte[] use = new byte[8]; - if (se) { - use = ByteUtils.switchByteArrayEndianness(read); - } else { - use = read; - } - out += " (L:"; - out += new DataInputStream(new ByteArrayInputStream(use)) - .readLong(); - - out += " / D:"; - out += new DataInputStream(new ByteArrayInputStream(use)) - .readDouble() - + ")"; - } - } - dis.reset(); - return out + '\n'; - } - - public static String buildUTF8(DataInputStream dis) throws IOException { - dis.mark(dis.available()); - String out = "\tUTF-8: "; - while (dis.available() > 1) { - out += " '" + (char) dis.read() + '\''; - } - dis.reset(); - return out; - } - - public static String buildUTF16(DataInputStream dis) throws IOException { - dis.mark(dis.available()); - String out = "\tUTF-16:"; - while (dis.available() > 1) { - out += " '" + dis.readChar() + '\''; - } - dis.reset(); - return out; - } - - public static String buildRawNumericalBytes(DataInputStream dis) - throws IOException { - dis.mark(dis.available()); - String out = "\tRaw Bytes (int vals): "; - while (dis.available() > 1) { - out += " '" + dis.read() + '\''; - } - dis.reset(); - return out; - } + public static void analyze4Bytes(byte[] data, String Label, + boolean switchEndian) throws IOException { + + ByteArrayInputStream bias = new ByteArrayInputStream(data); + DataInputStream dis = new DataInputStream(bias); + dis.mark(4); + + System.out.println("Analysis 4 bytes: (" + Label + ')'); + System.out.println("\t Hex: " + ByteUtils.byteArrayToStringHex(data)); + System.out.println(ByteAnalyzer.buildAll4(dis, switchEndian)); + System.out.println(ByteAnalyzer.buildUTF8(dis)); + System.out.println(ByteAnalyzer.buildUTF16(dis)); + System.out.println(ByteAnalyzer.buildRawNumericalBytes(dis)); + System.out.println(); + } + + public static void analyze8Bytes(byte[] data, String Label, + boolean switchEndian) throws IOException { + + ByteArrayInputStream bias = new ByteArrayInputStream(data); + DataInputStream dis = new DataInputStream(bias); + dis.mark(8); + + System.out.println("Analysis for 8 bytes: (" + Label + ')'); + System.out.println("\tHex: " + ByteUtils.byteArrayToStringHex(data)); + System.out.println(ByteAnalyzer.buildAll8(dis, switchEndian)); + dis.reset(); + System.out.println(ByteAnalyzer.buildUTF8(dis)); + System.out.println(ByteAnalyzer.buildUTF16(dis)); + System.out.println(ByteAnalyzer.buildRawNumericalBytes(dis)); + System.out.println("\n"); + } + + public static String buildAll8(DataInputStream indis, boolean se) + throws IOException { + byte[] ba = new byte[8]; + indis.read(ba); + DataInputStream dis = new DataInputStream(new ByteArrayInputStream(ba)); + dis.mark(8); + + String out = ""; + + out += buildFromTemplate("8", dis, se); + out += buildFromTemplate("4.4", dis, se); + + out += buildFromTemplate("4.2.2", dis, se); + out += buildFromTemplate("4.2.1.1", dis, se); + out += buildFromTemplate("4.1.2.1", dis, se); + out += buildFromTemplate("4.1.1.2", dis, se); + out += buildFromTemplate("4.1.1.1.1", dis, se); + + out += buildFromTemplate("2.2.4", dis, se); + out += buildFromTemplate("2.1.1.4", dis, se); + out += buildFromTemplate("1.2.1.4", dis, se); + out += buildFromTemplate("1.1.2.4", dis, se); + out += buildFromTemplate("1.1.1.1.4", dis, se); + + out += buildFromTemplate("2.4.2", dis, se); + out += buildFromTemplate("2.4.1.1", dis, se); + out += buildFromTemplate("1.1.4.2", dis, se); + out += buildFromTemplate("1.1.4.1.1", dis, se); + + out += buildFromTemplate("2.1.2.2.1", dis, se); + out += buildFromTemplate("2.1.2.1.2", dis, se); + out += buildFromTemplate("1.2.2.2.1", dis, se); + out += buildFromTemplate("1.2.2.1.2", dis, se); + + out += buildFromTemplate("1.1.1.2.2.1", dis, se); + out += buildFromTemplate("2.1.2.1.1.1", dis, se); + out += buildFromTemplate("1.1.1.2.1.1.1", dis, se); + out += buildFromTemplate("1.1.1.1.1.1.1.1", dis, se); + + out += buildFromTemplate("2.1.1.1.1.1.1", dis, se); + out += buildFromTemplate("1.2.1.1.1.1.1", dis, se); + out += buildFromTemplate("1.1.2.1.1.1.1", dis, se); + + out += buildFromTemplate("1.1.1.1.2.1.1", dis, se); + out += buildFromTemplate("1.1.1.1.1.2.1", dis, se); + out += buildFromTemplate("1.1.1.1.1.1.2", dis, se); + + return out; + } + + public static String buildAll4(DataInputStream indis, boolean se) + throws IOException { + byte[] ba = new byte[4]; + indis.read(ba); + DataInputStream dis = new DataInputStream(new ByteArrayInputStream(ba)); + dis.mark(4); + + String out = ""; + out += buildFromTemplate("4", dis, se); + out += buildFromTemplate("2.2", dis, se); + out += buildFromTemplate("2.1.1", dis, se); + out += buildFromTemplate("1.2.1", dis, se); + out += buildFromTemplate("1.1.2", dis, se); + out += buildFromTemplate("1.1.1.1", dis, se); + + return out; + } + + public static String buildFromTemplate(String template, + DataInputStream dis, boolean se) throws IOException { + String out = '\t' + template + ": "; + + for (int i = template.length(); i < 16; ++i) { + out += " "; + } + + template = template.replace(".", ""); + String[] items = template.split(""); + dis.mark(dis.available()); + + for (String s : items) { + if (s.equals("1")) { + out += " (B:" + dis.readByte(); + dis.reset(); + out += "/uB:" + dis.readUnsignedByte() + ')'; + } else if (s.equals("2")) { + byte[] read = new byte[2]; + dis.read(read); + byte[] use = new byte[2]; + if (se) { + use = ByteUtils.switchByteArrayEndianness(read); + } else { + use = read; + } + out += " (S:" + + new DataInputStream(new ByteArrayInputStream(use)) + .readShort(); + out += "/uS:" + + new DataInputStream(new ByteArrayInputStream(use)) + .readUnsignedShort() + ')'; + + } else if (s.equals("4")) { + byte[] read = new byte[4]; + dis.read(read); + byte[] use = new byte[4]; + if (se) { + use = ByteUtils.switchByteArrayEndianness(read); + } else { + use = read; + } + out += " (I:"; + out += new DataInputStream(new ByteArrayInputStream(use)) + .readInt(); + + out += " / F:"; + out += new DataInputStream(new ByteArrayInputStream(use)) + .readFloat() + + ")"; + } else if (s.equals("8")) { + byte[] read = new byte[8]; + dis.read(read); + + byte[] use = new byte[8]; + if (se) { + use = ByteUtils.switchByteArrayEndianness(read); + } else { + use = read; + } + out += " (L:"; + out += new DataInputStream(new ByteArrayInputStream(use)) + .readLong(); + + out += " / D:"; + out += new DataInputStream(new ByteArrayInputStream(use)) + .readDouble() + + ")"; + } + } + dis.reset(); + return out + '\n'; + } + + public static String buildUTF8(DataInputStream dis) throws IOException { + dis.mark(dis.available()); + String out = "\tUTF-8: "; + while (dis.available() > 1) { + out += " '" + (char) dis.read() + '\''; + } + dis.reset(); + return out; + } + + public static String buildUTF16(DataInputStream dis) throws IOException { + dis.mark(dis.available()); + String out = "\tUTF-16:"; + while (dis.available() > 1) { + out += " '" + dis.readChar() + '\''; + } + dis.reset(); + return out; + } + + public static String buildRawNumericalBytes(DataInputStream dis) + throws IOException { + dis.mark(dis.available()); + String out = "\tRaw Bytes (int vals): "; + while (dis.available() > 1) { + out += " '" + dis.read() + '\''; + } + dis.reset(); + return out; + } } diff --git a/src/engine/util/ByteBufferUtils.java b/src/engine/util/ByteBufferUtils.java index f3aa91c8..e937d327 100644 --- a/src/engine/util/ByteBufferUtils.java +++ b/src/engine/util/ByteBufferUtils.java @@ -15,190 +15,191 @@ import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; public class ByteBufferUtils { - public static String getString(ByteBuffer bb) - throws BufferUnderflowException { - return getString(bb, false, false); - } - - public static String getString(ByteBuffer bb, boolean switchEndian, boolean small) - throws BufferUnderflowException { - String out = ""; - synchronized (bb) { - - //This version works with non-latin characters - int stringLen; - if (small) - stringLen = (int)bb.get(); - else - stringLen = bb.getInt(); - if (switchEndian) - stringLen = ((Integer.reverseBytes(stringLen)) * 2); - else - stringLen *= 2; - byte[] b = new byte[stringLen]; - for (int i=0;i 255) - length = 255; //limit for smallString - - synchronized (bb) { - // Write length - if (small) - bb.put((byte)length); - else { - if (switchEndian) { - bb.putInt(Integer.reverseBytes(length)); - } else { - bb.putInt(length); - } - } - // Write chars - for (int i=0;i 255) + length = 255; //limit for smallString + + synchronized (bb) { + // Write length + if (small) + bb.put((byte) length); + else { + if (switchEndian) { + bb.putInt(Integer.reverseBytes(length)); + } else { + bb.putInt(length); + } + } + // Write chars + for (int i = 0; i < length; i++) { + char c = chars[i]; + if (switchEndian) { + bb.putChar(Character.reverseBytes(c)); + } else { + bb.putChar(c); + } + } + } + } + + public static String getHexString(ByteBuffer bb) + throws BufferUnderflowException { + return getHexString(bb, false); + } + + public static String getHexString(ByteBuffer bb, boolean switchEndian) + throws BufferUnderflowException { + String out = ""; + synchronized (bb) { + // Read len + int stringLen = bb.getInt(); + + if (switchEndian) { + stringLen = Integer.reverseBytes(stringLen); + } + + // Read len worth of chars + for (int i = 0; i < stringLen; ++i) { + out += Integer.toString((bb.get() & 0xff) + 0x100, 16) + .substring(1); + } + } + return out; + } + + public static void putHexString(ByteBuffer bb, String data) + throws BufferOverflowException { + putHexString(bb, data, false); + } + + public static void putHexString(ByteBuffer bb, String data, + boolean switchEndian) throws BufferOverflowException { + + if (data == null) { + data = ""; + } + + byte[] bts = new byte[data.length() / 2]; + + for (int i = 0; i < bts.length; i++) { + bts[i] = (byte) Integer.parseInt(data.substring(2 * i, 2 * i + 1), + 16); + } + + synchronized (bb) { + if (switchEndian) { + bb.putInt(Integer.reverseBytes(data.length() / 2)); + } else { + bb.putInt(data.length() / 2); + } + bb.put(bts); + } + } + + public static String getUnicodeString(ByteBuffer bb) + throws BufferUnderflowException { + return getUnicodeString(bb, false); + } + + public static String getUnicodeString(ByteBuffer bb, boolean switchEndian) + throws BufferUnderflowException { + byte[] out; + short thisChar; + synchronized (bb) { + // Read len + int stringLen = bb.getInt(); + if (switchEndian) { + stringLen = Integer.reverseBytes(stringLen); + } + out = new byte[stringLen]; + // Read len worth of chars + for (int i = 0; i < stringLen; ++i) { + thisChar = bb.getShort(); + if (switchEndian) + Short.reverseBytes(thisChar); + out[i] = (byte) (thisChar & 0xff); // ignore first byte + } + } + return new String(out); + } + + public static void putUnicodeString(ByteBuffer bb, String data) + throws BufferOverflowException { + putUnicodeString(bb, data, false); + } + + public static void putUnicodeString(ByteBuffer bb, String data, + boolean switchEndian) throws BufferOverflowException { + byte[] out; + short thisChar; + if (data == null) + return; + out = new byte[data.length()]; + out = data.getBytes(); + + for (byte b : out) { + thisChar = b; + if (switchEndian) + thisChar = Short.reverseBytes(thisChar); + bb.putShort(thisChar); + } + } + + public static boolean checkByteBufferNearFull(ByteBuffer bb) { return bb.position() >= (bb.capacity() * 0.9); } - //FIXME: Replace these!!! + //FIXME: Replace these!!! // public static ByteBuffer resizeByteBuffer(ByteBuffer bb, int multiplyer) { // // ByteBuffer out = ByteBuffer.allocate(bb.capacity() * multiplyer); diff --git a/src/engine/util/ByteUtils.java b/src/engine/util/ByteUtils.java index 51fb65c9..bcd766c8 100644 --- a/src/engine/util/ByteUtils.java +++ b/src/engine/util/ByteUtils.java @@ -7,7 +7,7 @@ // www.magicbane.com - package engine.util; +package engine.util; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -17,155 +17,155 @@ import java.util.zip.GZIPOutputStream; public abstract class ByteUtils { - private ByteUtils() { - } - - public static byte[] switchByteArrayEndianness(byte[] in) { - int size = in.length; - - byte[] out = new byte[size]; - - for (int i = 0; i < size; ++i) { - out[size - i - 1] = in[i]; - } - return out; - } - - /* - * Converts a single byte to a hex StringBuffer - */ - public static void byteToStringHex(byte b, StringBuffer buf) { - char[] hexChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'A', 'B', 'C', 'D', 'E', 'F' }; - int high = ((b & 0xf0) >> 4); - int low = (b & 0x0f); - buf.append(hexChars[high]); - buf.append(hexChars[low]); - } - - /* - * Converts a single byte to a hex String - */ - public static String byteToStringHex(byte b) { - StringBuffer sb = new StringBuffer(); - byteToStringHex(b, sb); - return sb.toString(); - } - - /* - * Converts a byte array to hex String - */ - public static String byteArrayToStringHex(byte[] block) { - StringBuffer buf = new StringBuffer(); - int len = block.length; - - for (int i = 0; i < len; i++) { - ByteUtils.byteToStringHex(block[i], buf); - if (i < len - 1) { - buf.append(':'); - } - } - return buf.toString(); - } - - /* - * Converts a single byte to a hex StringBuffer - */ - public static void byteToSafeStringHex(byte b, StringBuffer buf) { - char[] hexChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'a', 'b', 'c', 'd', 'e', 'f' }; - int high = ((b & 0xf0) >> 4); - int low = (b & 0x0f); - buf.append(hexChars[high]); - buf.append(hexChars[low]); - } - - /* - * Converts a single byte to a hex String - */ - public static String byteToSafeStringHex(byte b) { - StringBuffer sb = new StringBuffer(); - byteToSafeStringHex(b, sb); - return sb.toString(); - } - - /* - * Converts a byte array to hex String - */ - public static String byteArrayToSafeStringHex(byte[] block) { - StringBuffer buf = new StringBuffer(); - - int len = block.length; - - for (int i = 0; i < len; i++) { - ByteUtils.byteToSafeStringHex(block[i], buf); - } - return buf.toString(); - } - - /* - * Converts a hex string to Byte Array - */ - public static byte[] stringHexToByteArray(String hex) { - int length = hex.length(); - char[] hexchar = hex.toCharArray(); - byte[] ret = new byte[length / 2]; - int i1 = 0; - - for (int i = 0; i < length - 1; i += 2) { - ret[i1] = (byte) (Character.digit(hexchar[i], 16) * 16 + Character - .digit(hexchar[i + 1], 16)); - i1++; - } - - return ret; - } - - /* - * Converts a hex string formatted by our byteToStringHex to a byte array - * returns null if passed a null string - */ - public static byte[] formattedStringHexToByteArray(String hex) { - if(hex == null){ - return null; - } - - String tmpString = hex.replaceAll(":",""); - int length = tmpString.length(); - char[] hexchar = tmpString.toCharArray(); - byte[] ret = new byte[length / 2]; - int i1 = 0; - - for (int i = 0; i < length - 1; i += 2) { - ret[i1] = (byte) (Character.digit(hexchar[i], 16) * 16 + Character - .digit(hexchar[i + 1], 16)); - i1++; - } - - return ret; - } - - public static byte[] compress(final byte[] in) throws IOException{ + private ByteUtils() { + } + + public static byte[] switchByteArrayEndianness(byte[] in) { + int size = in.length; + + byte[] out = new byte[size]; + + for (int i = 0; i < size; ++i) { + out[size - i - 1] = in[i]; + } + return out; + } + + /* + * Converts a single byte to a hex StringBuffer + */ + public static void byteToStringHex(byte b, StringBuffer buf) { + char[] hexChars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'A', 'B', 'C', 'D', 'E', 'F'}; + int high = ((b & 0xf0) >> 4); + int low = (b & 0x0f); + buf.append(hexChars[high]); + buf.append(hexChars[low]); + } + + /* + * Converts a single byte to a hex String + */ + public static String byteToStringHex(byte b) { + StringBuffer sb = new StringBuffer(); + byteToStringHex(b, sb); + return sb.toString(); + } + + /* + * Converts a byte array to hex String + */ + public static String byteArrayToStringHex(byte[] block) { + StringBuffer buf = new StringBuffer(); + int len = block.length; + + for (int i = 0; i < len; i++) { + ByteUtils.byteToStringHex(block[i], buf); + if (i < len - 1) { + buf.append(':'); + } + } + return buf.toString(); + } + + /* + * Converts a single byte to a hex StringBuffer + */ + public static void byteToSafeStringHex(byte b, StringBuffer buf) { + char[] hexChars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'a', 'b', 'c', 'd', 'e', 'f'}; + int high = ((b & 0xf0) >> 4); + int low = (b & 0x0f); + buf.append(hexChars[high]); + buf.append(hexChars[low]); + } + + /* + * Converts a single byte to a hex String + */ + public static String byteToSafeStringHex(byte b) { + StringBuffer sb = new StringBuffer(); + byteToSafeStringHex(b, sb); + return sb.toString(); + } + + /* + * Converts a byte array to hex String + */ + public static String byteArrayToSafeStringHex(byte[] block) { + StringBuffer buf = new StringBuffer(); + + int len = block.length; + + for (int i = 0; i < len; i++) { + ByteUtils.byteToSafeStringHex(block[i], buf); + } + return buf.toString(); + } + + /* + * Converts a hex string to Byte Array + */ + public static byte[] stringHexToByteArray(String hex) { + int length = hex.length(); + char[] hexchar = hex.toCharArray(); + byte[] ret = new byte[length / 2]; + int i1 = 0; + + for (int i = 0; i < length - 1; i += 2) { + ret[i1] = (byte) (Character.digit(hexchar[i], 16) * 16 + Character + .digit(hexchar[i + 1], 16)); + i1++; + } + + return ret; + } + + /* + * Converts a hex string formatted by our byteToStringHex to a byte array + * returns null if passed a null string + */ + public static byte[] formattedStringHexToByteArray(String hex) { + if (hex == null) { + return null; + } + + String tmpString = hex.replaceAll(":", ""); + int length = tmpString.length(); + char[] hexchar = tmpString.toCharArray(); + byte[] ret = new byte[length / 2]; + int i1 = 0; + + for (int i = 0; i < length - 1; i += 2) { + ret[i1] = (byte) (Character.digit(hexchar[i], 16) * 16 + Character + .digit(hexchar[i + 1], 16)); + i1++; + } + + return ret; + } + + public static byte[] compress(final byte[] in) throws IOException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final GZIPOutputStream gzOs = new GZIPOutputStream(out); gzOs.write(in); gzOs.close(); return out.toByteArray(); - } - - public static byte[] decompress(final byte[] in) throws IOException{ + } + + public static byte[] decompress(final byte[] in) throws IOException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final GZIPInputStream gzIs = new GZIPInputStream(new ByteArrayInputStream(in)); final byte[] buffer = new byte[512]; int lastRead = 0; - + lastRead = gzIs.read(buffer); while (lastRead > 0) { - out.write(buffer,0,lastRead); + out.write(buffer, 0, lastRead); lastRead = gzIs.read(buffer); } gzIs.close(); return out.toByteArray(); } - + } diff --git a/src/engine/util/Hasher.java b/src/engine/util/Hasher.java index 2914c03a..ccb60c7c 100644 --- a/src/engine/util/Hasher.java +++ b/src/engine/util/Hasher.java @@ -71,73 +71,6 @@ public class Hasher { alphabet_ = consistentShuffle(alphabet_.replaceAll(" ", ""), salt_); } - public String encrypt(long... numbers) { - return encode(numbers, alphabet_, salt_, minHashLength_); - } - - public long[] decrypt(String hash) { - return decode(hash); - } - - private String encode(long[] numbers, String alphabet, String salt, int minHashLength) { - String ret = ""; - String seps = consistentShuffle(join(seps_, ""), join(numbers, "")); - char lotteryChar = 0; - - for (int i = 0; i < numbers.length; i++) { - if (i == 0) { - String lotterySalt = join(numbers, "-"); - for (long number : numbers) { - lotterySalt += "-" + (number + 1) * 2; - } - String lottery = consistentShuffle(alphabet, lotterySalt); - lotteryChar = lottery.charAt(0); - ret += lotteryChar; - - alphabet = lotteryChar + alphabet.replaceAll(String.valueOf(lotteryChar), ""); - } - - alphabet = consistentShuffle(alphabet, ((int) lotteryChar & 12345) + salt); - ret += hash(numbers[i], alphabet); - - if (i + 1 < numbers.length) { - ret += seps.charAt((int) ((numbers[i] + i) % seps.length())); - } - } - - if (ret.length() < minHashLength) { - int firstIndex = 0; - for (int i = 0; i < numbers.length; i++) { - firstIndex += (i + 1) * numbers[i]; - } - - int guardIndex = firstIndex % guards_.size(); - char guard = guards_.get(guardIndex); - ret = guard + ret; - - if (ret.length() < minHashLength) { - guardIndex = (guardIndex + ret.length()) % guards_.size(); - guard = guards_.get(guardIndex); - ret += guard; - } - } - - while (ret.length() < minHashLength) { - long[] padArray = new long[]{alphabet.charAt(1), alphabet.charAt(0)}; - String padLeft = encode(padArray, alphabet, salt, 0); - String padRight = encode(padArray, alphabet, join(padArray, ""), 0); - - ret = padLeft + ret + padRight; - int excess = ret.length() - minHashLength; - if (excess > 0) { - ret = ret.substring(excess / 2, excess / 2 + minHashLength); - } - alphabet = consistentShuffle(alphabet, salt + ret); - } - - return ret; - } - private static String hash(long number, String alphabet) { String hash = ""; @@ -160,54 +93,6 @@ public class Hasher { return number; } - private long[] decode(String hash) { - List ret = new ArrayList<>(); - String originalHash = hash; - - if (hash != null && !hash.isEmpty()) { - String alphabet = ""; - char lotteryChar = 0; - - for (char guard : guards_) { - hash = hash.replaceAll(String.valueOf(guard), " "); - } - - String[] hashSplit = hash.split(" "); - - hash = hashSplit[hashSplit.length == 3 || hashSplit.length == 2 ? 1 : 0]; - - for (char sep : seps_) { - hash = hash.replaceAll(String.valueOf(sep), " "); - } - - String[] hashArray = hash.split(" "); - for (int i = 0; i < hashArray.length; i++) { - String subHash = hashArray[i]; - - if (subHash != null && !subHash.isEmpty()) { - if (i == 0) { - lotteryChar = hash.charAt(0); - subHash = subHash.substring(1); - alphabet = lotteryChar + alphabet_.replaceAll(String.valueOf(lotteryChar), ""); - } - } - - if (alphabet.length() > 0) { - alphabet = consistentShuffle(alphabet, ((int) lotteryChar & 12345) + salt_); - ret.add(unhash(subHash, alphabet)); - } - } - } - - long[] numbers = longListToPrimitiveArray(ret); - - if (!encrypt(numbers).equals(originalHash)) { - return new long[0]; - } - - return numbers; - } - private static String consistentShuffle(String alphabet, String salt) { String ret = ""; @@ -254,18 +139,6 @@ public class Hasher { return ret; } - public String getSalt() { - return salt_; - } - - public String getAlphabet() { - return alphabet_; - } - - public int getMinHashLength() { - return minHashLength_; - } - public static String getVersion() { return "0.1.4"; } @@ -379,4 +252,131 @@ public class Hasher { return eax; } } + + public String encrypt(long... numbers) { + return encode(numbers, alphabet_, salt_, minHashLength_); + } + + public long[] decrypt(String hash) { + return decode(hash); + } + + private String encode(long[] numbers, String alphabet, String salt, int minHashLength) { + String ret = ""; + String seps = consistentShuffle(join(seps_, ""), join(numbers, "")); + char lotteryChar = 0; + + for (int i = 0; i < numbers.length; i++) { + if (i == 0) { + String lotterySalt = join(numbers, "-"); + for (long number : numbers) { + lotterySalt += "-" + (number + 1) * 2; + } + String lottery = consistentShuffle(alphabet, lotterySalt); + lotteryChar = lottery.charAt(0); + ret += lotteryChar; + + alphabet = lotteryChar + alphabet.replaceAll(String.valueOf(lotteryChar), ""); + } + + alphabet = consistentShuffle(alphabet, ((int) lotteryChar & 12345) + salt); + ret += hash(numbers[i], alphabet); + + if (i + 1 < numbers.length) { + ret += seps.charAt((int) ((numbers[i] + i) % seps.length())); + } + } + + if (ret.length() < minHashLength) { + int firstIndex = 0; + for (int i = 0; i < numbers.length; i++) { + firstIndex += (i + 1) * numbers[i]; + } + + int guardIndex = firstIndex % guards_.size(); + char guard = guards_.get(guardIndex); + ret = guard + ret; + + if (ret.length() < minHashLength) { + guardIndex = (guardIndex + ret.length()) % guards_.size(); + guard = guards_.get(guardIndex); + ret += guard; + } + } + + while (ret.length() < minHashLength) { + long[] padArray = new long[]{alphabet.charAt(1), alphabet.charAt(0)}; + String padLeft = encode(padArray, alphabet, salt, 0); + String padRight = encode(padArray, alphabet, join(padArray, ""), 0); + + ret = padLeft + ret + padRight; + int excess = ret.length() - minHashLength; + if (excess > 0) { + ret = ret.substring(excess / 2, excess / 2 + minHashLength); + } + alphabet = consistentShuffle(alphabet, salt + ret); + } + + return ret; + } + + private long[] decode(String hash) { + List ret = new ArrayList<>(); + String originalHash = hash; + + if (hash != null && !hash.isEmpty()) { + String alphabet = ""; + char lotteryChar = 0; + + for (char guard : guards_) { + hash = hash.replaceAll(String.valueOf(guard), " "); + } + + String[] hashSplit = hash.split(" "); + + hash = hashSplit[hashSplit.length == 3 || hashSplit.length == 2 ? 1 : 0]; + + for (char sep : seps_) { + hash = hash.replaceAll(String.valueOf(sep), " "); + } + + String[] hashArray = hash.split(" "); + for (int i = 0; i < hashArray.length; i++) { + String subHash = hashArray[i]; + + if (subHash != null && !subHash.isEmpty()) { + if (i == 0) { + lotteryChar = hash.charAt(0); + subHash = subHash.substring(1); + alphabet = lotteryChar + alphabet_.replaceAll(String.valueOf(lotteryChar), ""); + } + } + + if (alphabet.length() > 0) { + alphabet = consistentShuffle(alphabet, ((int) lotteryChar & 12345) + salt_); + ret.add(unhash(subHash, alphabet)); + } + } + } + + long[] numbers = longListToPrimitiveArray(ret); + + if (!encrypt(numbers).equals(originalHash)) { + return new long[0]; + } + + return numbers; + } + + public String getSalt() { + return salt_; + } + + public String getAlphabet() { + return alphabet_; + } + + public int getMinHashLength() { + return minHashLength_; + } } \ No newline at end of file diff --git a/src/engine/util/KeyCloneAudit.java b/src/engine/util/KeyCloneAudit.java index f01e7cdd..cdae6317 100644 --- a/src/engine/util/KeyCloneAudit.java +++ b/src/engine/util/KeyCloneAudit.java @@ -20,11 +20,11 @@ public enum KeyCloneAudit { if (machineID.equals(member.getClientConnection().machineID)) machineCount = machineCount + 1; - if (machineCount > Integer.parseInt(ConfigManager.MB_WORLD_KEYCLONE_MAX.getValue())) { - Logger.error("Keyclone detected from: " + player.getAccount().getUname() + - " with machine count of: " + machineCount); - DbManager.AccountQueries.SET_TRASH(machineID); - } + if (machineCount > Integer.parseInt(ConfigManager.MB_WORLD_KEYCLONE_MAX.getValue())) { + Logger.error("Keyclone detected from: " + player.getAccount().getUname() + + " with machine count of: " + machineCount); + DbManager.AccountQueries.SET_TRASH(machineID); + } } } diff --git a/src/engine/util/MapLoader.java b/src/engine/util/MapLoader.java index bb4263ec..d43cfda8 100644 --- a/src/engine/util/MapLoader.java +++ b/src/engine/util/MapLoader.java @@ -27,9 +27,9 @@ public enum MapLoader { long bytesRead = 0; long realmsWritten = 0; int realmUUID; - + // Load image from disk - + try { image = ImageIO.read(new File(ConfigManager.DEFAULT_DATA_DIR + "realmmap.png")); @@ -38,12 +38,12 @@ public enum MapLoader { MBServerStatics.SPATIAL_HASH_BUCKETSY = image.getHeight(); realmMap = new int[MBServerStatics.SPATIAL_HASH_BUCKETSX][MBServerStatics.SPATIAL_HASH_BUCKETSY]; } catch (IOException e) { - Logger.error( "Error loading realm map: " + e.toString()); + Logger.error("Error loading realm map: " + e.toString()); return null; } // Flip image on the y axis - + image = flipImage(image); // Load spatial imageMap with color data from file @@ -52,9 +52,9 @@ public enum MapLoader { for (int j = 0; j < MBServerStatics.SPATIAL_HASH_BUCKETSX; j++) { Color pixelColor = new Color(image.getRGB(j, i)); - realmUUID = RealmMap.getRealmIDByColor(pixelColor); + realmUUID = RealmMap.getRealmIDByColor(pixelColor); - realmMap[j][i] = realmUUID; + realmMap[j][i] = realmUUID; bytesRead++; if (realmUUID != 0) @@ -71,13 +71,13 @@ public enum MapLoader { } public static BufferedImage flipImage(BufferedImage img) { - + int w = img.getWidth(); int h = img.getHeight(); - + BufferedImage dimg = new BufferedImage(w, h, img.getColorModel() .getTransparency()); - + Graphics2D g = dimg.createGraphics(); g.drawImage(img, 0, 0, w, h, 0, h, w, 0, null); g.dispose(); diff --git a/src/engine/util/MiscUtils.java b/src/engine/util/MiscUtils.java index 03f79ed6..9f077c69 100644 --- a/src/engine/util/MiscUtils.java +++ b/src/engine/util/MiscUtils.java @@ -15,24 +15,24 @@ import engine.server.MBServerStatics; public class MiscUtils { - public static boolean checkIfFirstNameInvalid(String firstName) { - if ((firstName == null) || (firstName.length() == 0) - || (firstName.length() > MBServerStatics.MAX_NAME_LENGTH) - || (firstName.length() < MBServerStatics.MIN_NAME_LENGTH)) { - return true; - } - return (!ConfigManager.regex.get(ConfigManager.MB_LOGIN_FNAME_REGEX).matcher(firstName).matches()); - } + public static boolean checkIfFirstNameInvalid(String firstName) { + if ((firstName == null) || (firstName.length() == 0) + || (firstName.length() > MBServerStatics.MAX_NAME_LENGTH) + || (firstName.length() < MBServerStatics.MIN_NAME_LENGTH)) { + return true; + } + return (!ConfigManager.regex.get(ConfigManager.MB_LOGIN_FNAME_REGEX).matcher(firstName).matches()); + } - public static boolean checkIfLastNameInvalid(String lastName) { - if ((lastName != null) && (lastName.length() != 0)) { - // make sure it's less than max length + public static boolean checkIfLastNameInvalid(String lastName) { + if ((lastName != null) && (lastName.length() != 0)) { + // make sure it's less than max length return lastName.length() > MBServerStatics.MAX_NAME_LENGTH; - // first character: A-Z, a-z - // remaining chars (optional): hyphen, apostrophe, A-Z, a-z, space + // first character: A-Z, a-z + // remaining chars (optional): hyphen, apostrophe, A-Z, a-z, space // return (!lastNameRegex.matcher(lastName).matches()); - } - // empty last names are fine, return false - return false; - } + } + // empty last names are fine, return false + return false; + } } diff --git a/src/engine/util/StringUtils.java b/src/engine/util/StringUtils.java index e7a6f548..d0fcc7a3 100644 --- a/src/engine/util/StringUtils.java +++ b/src/engine/util/StringUtils.java @@ -7,82 +7,82 @@ // www.magicbane.com - package engine.util; +package engine.util; import java.net.InetAddress; import java.util.StringTokenizer; public class StringUtils { - public static String addWS(String s, int totalLen) { - if (s.length() >= totalLen) { - return s; - } - - int diff = totalLen - s.length(); - - String out = s; - - for (int i = 0; i < diff; ++i) { - out += " "; - } - return out; - } - - public static String bannerize(String s, int totalLen) { - if (s.length() >= totalLen) { - return s; - } - - int diff = totalLen - s.length(); - int halfDiff = diff / 2; - - String side = ""; - for (int i = 0; i < halfDiff; ++i) { - side += "*"; - } - - return side + ' ' + s + ' ' + side; - } - - public static String InetAddressToClientString(InetAddress address) { - return address.toString().replaceAll("/", ""); - } - - public static String toHexString(int i) { - return Integer.toHexString(i).toUpperCase(); - } - - public static String toHexString(long l) { - return Long.toHexString(l).toUpperCase(); - } - - // Well done IDA Pro. - - public static int hashString(String toHash) { - byte[] hashArray = toHash.getBytes(); - int hash = 0; - int shift = 0; - if (hashArray.length == 8 ||hashArray.length == 7){ - int ecx = 0; - if (hashArray.length == 8){ - ecx = hashArray[7]; - } - int eax = hashArray[4]; - int esi = ecx * 0x8; + public static String addWS(String s, int totalLen) { + if (s.length() >= totalLen) { + return s; + } + + int diff = totalLen - s.length(); + + String out = s; + + for (int i = 0; i < diff; ++i) { + out += " "; + } + return out; + } + + public static String bannerize(String s, int totalLen) { + if (s.length() >= totalLen) { + return s; + } + + int diff = totalLen - s.length(); + int halfDiff = diff / 2; + + String side = ""; + for (int i = 0; i < halfDiff; ++i) { + side += "*"; + } + + return side + ' ' + s + ' ' + side; + } + + public static String InetAddressToClientString(InetAddress address) { + return address.toString().replaceAll("/", ""); + } + + public static String toHexString(int i) { + return Integer.toHexString(i).toUpperCase(); + } + + public static String toHexString(long l) { + return Long.toHexString(l).toUpperCase(); + } + + // Well done IDA Pro. + + public static int hashString(String toHash) { + byte[] hashArray = toHash.getBytes(); + int hash = 0; + int shift = 0; + if (hashArray.length == 8 || hashArray.length == 7) { + int ecx = 0; + if (hashArray.length == 8) { + ecx = hashArray[7]; + } + int eax = hashArray[4]; + int esi = ecx * 0x8; eax ^= esi; ecx ^= 0x5A0; - esi = hashArray[5]; + esi = hashArray[5]; eax <<= 4; eax ^= esi; - esi = hashArray[6]; + esi = hashArray[6]; eax <<= 4; eax ^= esi; - esi = hashArray[2]; + esi = hashArray[2]; eax <<= 5; eax ^= esi; - esi = hashArray[1]; - int edx = hashArray[0]; + esi = hashArray[1]; + int edx = hashArray[0]; eax <<= 5; eax ^= esi; ecx /= 2; @@ -90,73 +90,68 @@ public class StringUtils { eax <<= 5; ecx ^= edx; eax ^= ecx; - return eax; - }else{ + return eax; + } else { - for (int i = 0; i 24){ - int newShift = 0x20 - shift; - int newShifted = toShift >> newShift; + if (shift > 24) { + int newShift = 0x20 - shift; + int newShifted = toShift >> newShift; hash ^= newShifted; - if (shift > 27){ + if (shift > 27) { shift -= 0x20; - } - } - } - return hash; - } - } - - public static String wordWrap(String text,int LineWidth) - { - StringTokenizer st=new StringTokenizer(text); - int SpaceLeft=LineWidth; - int SpaceWidth=80; - String outString = ""; - - while(st.hasMoreTokens()) - { - String word=st.nextToken(); - if((word.length()+SpaceWidth)>SpaceLeft) - { - outString+= '\n' +word+ ' '; - SpaceLeft=LineWidth-word.length(); - } - else - { - outString+=word+ ' '; - SpaceLeft-=(word.length()+SpaceWidth); - } - - } - - return outString; - - } - - public static String truncate(String input, int length) { - if (input != null && input.length() > length) - input = input.substring(0, length); - return input; - } - - public static int wordCount(String input) { - - String workString = input.trim(); - - if (workString.isEmpty()) - return 0; - - return workString.split("\\s+").length; - - } + } + } + } + return hash; + } + } + + public static String wordWrap(String text, int LineWidth) { + StringTokenizer st = new StringTokenizer(text); + int SpaceLeft = LineWidth; + int SpaceWidth = 80; + String outString = ""; + + while (st.hasMoreTokens()) { + String word = st.nextToken(); + if ((word.length() + SpaceWidth) > SpaceLeft) { + outString += '\n' + word + ' '; + SpaceLeft = LineWidth - word.length(); + } else { + outString += word + ' '; + SpaceLeft -= (word.length() + SpaceWidth); + } + + } + + return outString; + + } + + public static String truncate(String input, int length) { + if (input != null && input.length() > length) + input = input.substring(0, length); + return input; + } + + public static int wordCount(String input) { + + String workString = input.trim(); + + if (workString.isEmpty()) + return 0; + + return workString.split("\\s+").length; + + } } diff --git a/src/engine/util/ThreadUtils.java b/src/engine/util/ThreadUtils.java index 8b802141..e25095f4 100644 --- a/src/engine/util/ThreadUtils.java +++ b/src/engine/util/ThreadUtils.java @@ -14,30 +14,26 @@ import org.pmw.tinylog.Logger; public abstract class ThreadUtils { - private ThreadUtils() { - } - - /** - * Force the current thread to sleep for sec seconds and ms - * milliseconds. - * - * - */ - public static void sleep(int sec, long ms) { - try { - Thread.sleep((1000L * sec) + ms); - } catch (InterruptedException e) { - Logger.error( e.toString()); - } - } - - /** - * Force the current thread to sleep for ms milliseconds. - * - * - */ - public static void sleep(long ms) { - ThreadUtils.sleep(0, ms); - } + private ThreadUtils() { + } + + /** + * Force the current thread to sleep for sec seconds and ms + * milliseconds. + */ + public static void sleep(int sec, long ms) { + try { + Thread.sleep((1000L * sec) + ms); + } catch (InterruptedException e) { + Logger.error(e.toString()); + } + } + + /** + * Force the current thread to sleep for ms milliseconds. + */ + public static void sleep(long ms) { + ThreadUtils.sleep(0, ms); + } } diff --git a/src/engine/workthreads/DestroyCityThread.java b/src/engine/workthreads/DestroyCityThread.java index 47e3d97f..aeb46a6c 100644 --- a/src/engine/workthreads/DestroyCityThread.java +++ b/src/engine/workthreads/DestroyCityThread.java @@ -33,123 +33,123 @@ import java.util.ArrayList; public class DestroyCityThread implements Runnable { - City city; + City city; - public DestroyCityThread(City city) { + public DestroyCityThread(City city) { - this.city = city; - } + this.city = city; + } - public void run(){ + public void run() { - // Member variable declaration + // Member variable declaration - Zone cityZone; - Zone newParent; - Guild formerGuild; - Vector3fImmutable localCoords; - ArrayList subGuildList; + Zone cityZone; + Zone newParent; + Guild formerGuild; + Vector3fImmutable localCoords; + ArrayList subGuildList; - // Member variable assignment + // Member variable assignment - cityZone = city.getParent(); - newParent = cityZone.getParent(); - formerGuild = city.getTOL().getGuild(); + cityZone = city.getParent(); + newParent = cityZone.getParent(); + formerGuild = city.getTOL().getGuild(); - // Former guild loses it's tree! + // Former guild loses it's tree! - if (DbManager.GuildQueries.SET_GUILD_OWNED_CITY(formerGuild.getObjectUUID(), 0)) { + if (DbManager.GuildQueries.SET_GUILD_OWNED_CITY(formerGuild.getObjectUUID(), 0)) { - //Successful Update of guild + //Successful Update of guild - formerGuild.setGuildState(engine.Enum.GuildState.Errant); - formerGuild.setNation(null); - formerGuild.setCityUUID(0); - GuildManager.updateAllGuildTags(formerGuild); - GuildManager.updateAllGuildBinds(formerGuild, null); - } + formerGuild.setGuildState(engine.Enum.GuildState.Errant); + formerGuild.setNation(null); + formerGuild.setCityUUID(0); + GuildManager.updateAllGuildTags(formerGuild); + GuildManager.updateAllGuildBinds(formerGuild, null); + } - // By losing the tree, the former owners lose all of their subguilds. + // By losing the tree, the former owners lose all of their subguilds. - if (formerGuild.getSubGuildList().isEmpty() == false) { + if (formerGuild.getSubGuildList().isEmpty() == false) { - subGuildList = new ArrayList<>(); + subGuildList = new ArrayList<>(); - for (Guild subGuild : formerGuild.getSubGuildList()) { - subGuildList.add(subGuild); - } + for (Guild subGuild : formerGuild.getSubGuildList()) { + subGuildList.add(subGuild); + } - for (Guild subGuild : subGuildList) { - formerGuild.removeSubGuild(subGuild); - } - } + for (Guild subGuild : subGuildList) { + formerGuild.removeSubGuild(subGuild); + } + } - // Build list of buildings within this parent zone + // Build list of buildings within this parent zone - for (Building cityBuilding : cityZone.zoneBuildingSet) { + for (Building cityBuilding : cityZone.zoneBuildingSet) { - // Sanity Check in case player deletes the building - // before this thread can get to it + // Sanity Check in case player deletes the building + // before this thread can get to it - if (cityBuilding == null) - continue; + if (cityBuilding == null) + continue; - // Do nothing with the banestone. It will be removed elsewhere + // Do nothing with the banestone. It will be removed elsewhere - if (cityBuilding.getBlueprint().getBuildingGroup().equals(Enum.BuildingGroup.BANESTONE)) - continue; - - // All buildings are moved to a location relative - // to their new parent zone + if (cityBuilding.getBlueprint().getBuildingGroup().equals(Enum.BuildingGroup.BANESTONE)) + continue; - localCoords = ZoneManager.worldToLocal(cityBuilding.getLoc(), newParent); + // All buildings are moved to a location relative + // to their new parent zone - DbManager.BuildingQueries.MOVE_BUILDING(cityBuilding.getObjectUUID(), newParent.getObjectUUID(), localCoords.x, localCoords.y, localCoords.z); + localCoords = ZoneManager.worldToLocal(cityBuilding.getLoc(), newParent); - // All buildings are re-parented to a zone one node - // higher in the tree (continent) as we will be - // deleting the city zone very shortly. + DbManager.BuildingQueries.MOVE_BUILDING(cityBuilding.getObjectUUID(), newParent.getObjectUUID(), localCoords.x, localCoords.y, localCoords.z); - if (cityBuilding.getParentZoneID() != newParent.getParentZoneID()) - cityBuilding.setParentZone(newParent); + // All buildings are re-parented to a zone one node + // higher in the tree (continent) as we will be + // deleting the city zone very shortly. - // No longer a tree, no longer any protection contract! + if (cityBuilding.getParentZoneID() != newParent.getParentZoneID()) + cityBuilding.setParentZone(newParent); - cityBuilding.setProtectionState(Enum.ProtectionState.NONE); + // No longer a tree, no longer any protection contract! - // Destroy all remaining city assets + cityBuilding.setProtectionState(Enum.ProtectionState.NONE); - if ((cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.BARRACK) - || (cityBuilding.getBlueprint().isWallPiece()) - || (cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.SHRINE) - || (cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.TOL) - || (cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.SPIRE) - || (cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.WAREHOUSE)) { + // Destroy all remaining city assets - if (cityBuilding.getRank() != -1) - cityBuilding.setRank(-1); - } - } + if ((cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.BARRACK) + || (cityBuilding.getBlueprint().isWallPiece()) + || (cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.SHRINE) + || (cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.TOL) + || (cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.SPIRE) + || (cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.WAREHOUSE)) { - if (city.getRealm() != null) - city.getRealm().removeCity(city.getObjectUUID()); + if (cityBuilding.getRank() != -1) + cityBuilding.setRank(-1); + } + } - // It's now safe to delete the city zone from the database - // which will cause a cascade delete of everything else + if (city.getRealm() != null) + city.getRealm().removeCity(city.getObjectUUID()); + // It's now safe to delete the city zone from the database + // which will cause a cascade delete of everything else - if (DbManager.ZoneQueries.DELETE_ZONE(cityZone) == false) { - Logger.error("DestroyCityThread", "Database error when deleting city zone: " + cityZone.getObjectUUID()); - return; - } - // Refresh the city for map requests + if (DbManager.ZoneQueries.DELETE_ZONE(cityZone) == false) { + Logger.error("DestroyCityThread", "Database error when deleting city zone: " + cityZone.getObjectUUID()); + return; + } - City.lastCityUpdate = System.currentTimeMillis(); + // Refresh the city for map requests - // Zone and city should vanish upon next reboot - // if the codebase reaches here. + City.lastCityUpdate = System.currentTimeMillis(); - Logger.info(city.getParent().getName() + " uuid:" + city.getObjectUUID() + "has been destroyed!"); - } + // Zone and city should vanish upon next reboot + // if the codebase reaches here. + + Logger.info(city.getParent().getName() + " uuid:" + city.getObjectUUID() + "has been destroyed!"); + } } diff --git a/src/engine/workthreads/DisconnectTrashTask.java b/src/engine/workthreads/DisconnectTrashTask.java index 97a5f012..b0cf6748 100644 --- a/src/engine/workthreads/DisconnectTrashTask.java +++ b/src/engine/workthreads/DisconnectTrashTask.java @@ -25,28 +25,29 @@ public class DisconnectTrashTask extends TimerTask { // Pass it a list of characters and it will disconnect them // 5 seconds in the future. - public DisconnectTrashTask(ArrayList trashList) - { + public DisconnectTrashTask(ArrayList trashList) { this.trashList = new ArrayList<>(trashList); } public void run() { - Logger.info("Disconnecting actives from pool of: " + trashList.size()); + Logger.info("Disconnecting actives from pool of: " + trashList.size()); Session trashSession; int accountUID; - for (PlayerCharacter trashPlayer:trashList) { - trashSession = SessionManager.getSession(trashPlayer); - accountUID = trashPlayer.getAccount().getObjectUUID(); + for (PlayerCharacter trashPlayer : trashList) { + trashSession = SessionManager.getSession(trashPlayer); + accountUID = trashPlayer.getAccount().getObjectUUID(); - if (trashSession != null) - trashSession.getConn().disconnect(); + if (trashSession != null) + trashSession.getConn().disconnect(); - // Remove account from cache + // Remove account from cache - DbManager.removeFromCache(Enum.GameObjectType.Account, accountUID); - } - }; + DbManager.removeFromCache(Enum.GameObjectType.Account, accountUID); + } + } + + ; } diff --git a/src/engine/workthreads/PurgeOprhans.java b/src/engine/workthreads/PurgeOprhans.java index dc33c17c..6287d67f 100644 --- a/src/engine/workthreads/PurgeOprhans.java +++ b/src/engine/workthreads/PurgeOprhans.java @@ -56,7 +56,7 @@ public class PurgeOprhans implements Runnable { } } catch (Exception e) { - Logger.error( e.toString()); + Logger.error(e.toString()); } Logger.info("Thread is exiting with " + recordsDeleted.toString() + " items deleted"); diff --git a/src/engine/workthreads/TransferCityThread.java b/src/engine/workthreads/TransferCityThread.java index ab2d049a..812f82fe 100644 --- a/src/engine/workthreads/TransferCityThread.java +++ b/src/engine/workthreads/TransferCityThread.java @@ -39,7 +39,7 @@ public class TransferCityThread implements Runnable { this.newOwner = newOwner; } - public void run(){ + public void run() { Guild formerGuild; ArrayList subGuildList; @@ -81,7 +81,7 @@ public class TransferCityThread implements Runnable { city.claim(newOwner); //Set name of City to attacker's guild name - BuildingManager.setUpgradeDateTime(city.getTOL(),null, 0); + BuildingManager.setUpgradeDateTime(city.getTOL(), null, 0); city.getTOL().setName(newOwner.getGuild().getName()); // Send updated cityZone to players @@ -94,6 +94,6 @@ public class TransferCityThread implements Runnable { City.lastCityUpdate = System.currentTimeMillis(); Logger.info("uuid:" + city.getObjectUUID() + "transferred from " + formerGuild.getName() + - " to " + newOwner.getGuild().getName()); + " to " + newOwner.getGuild().getName()); } } diff --git a/src/engine/workthreads/WarehousePushThread.java b/src/engine/workthreads/WarehousePushThread.java index da920ecb..77c368f5 100644 --- a/src/engine/workthreads/WarehousePushThread.java +++ b/src/engine/workthreads/WarehousePushThread.java @@ -25,427 +25,424 @@ import java.sql.*; public class WarehousePushThread implements Runnable { - // Used to track last push. These are read - // at thread startup and written back out - // when we're done + // Used to track last push. These are read + // at thread startup and written back out + // when we're done + + public static int charIndex, charDelta; + public static int cityIndex, cityDelta; + public static int guildIndex, guildDelta; + public static int realmIndex, realmDelta; + public static int baneIndex, baneDelta; + public static int pvpIndex, pvpDelta; + public static int mineIndex, mineDelta; + + public WarehousePushThread() { + + } + + public static boolean pushMineRecords() { + + try (Connection localConnection = DbManager.getConnection(); + PreparedStatement statement = MineRecord.buildMineQueryStatement(localConnection); + ResultSet rs = statement.executeQuery()) { + + while (rs.next()) { + pushMineRecord(rs); + mineDelta = rs.getInt("event_number"); + } + + return true; + } catch (SQLException e) { + Logger.error("Error with local DB connection: " + e.toString()); + e.printStackTrace(); + return false; + } + } - public static int charIndex, charDelta; - public static int cityIndex, cityDelta; - public static int guildIndex, guildDelta; - public static int realmIndex, realmDelta; - public static int baneIndex, baneDelta; - public static int pvpIndex, pvpDelta; - public static int mineIndex, mineDelta; + public static boolean pushCharacterRecords() { - public WarehousePushThread() { + try (Connection localConnection = DbManager.getConnection(); + PreparedStatement statement = CharacterRecord.buildCharacterQueryStatement(localConnection); + ResultSet rs = statement.executeQuery()) { - } + while (rs.next()) { + pushCharacterRecord(rs); + charDelta = rs.getInt("event_number"); + } - public void run() { + return true; + } catch (SQLException e) { + Logger.error("Error with local DB connection: " + e.toString()); + e.printStackTrace(); + return false; + } + } - int recordCount = 0; - boolean writeSuccess = true; + private static boolean pushGuildRecords() { - if ( ConfigManager.MB_WORLD_WAREHOUSE_PUSH.getValue().equals("false")) { - Logger.info("WAREHOUSEPUSH DISABLED: EARLY EXIT"); - return; + try (Connection localConnection = DbManager.getConnection(); + PreparedStatement statement = GuildRecord.buildGuildQueryStatement(localConnection); + ResultSet rs = statement.executeQuery()) { + + while (rs.next()) { + pushGuildRecord(rs); + guildDelta = rs.getInt("event_number"); + } + + return true; + } catch (SQLException e) { + Logger.error("Error with local DB connection: " + e.toString()); + e.printStackTrace(); + return false; } + } - // Cache where we left off from the last push - // for each of the warehouse tables - - if (readWarehouseIndex() == false) - return; - - // Log run to console - - Logger.info( "Pushing records to remote..."); - - // Push records to remote database - - for (Enum.DataRecordType recordType : Enum.DataRecordType.values()) { - - switch (recordType) { - case PVP: - if (pushPvpRecords() == true) { - recordCount = Math.max(0, pvpDelta - pvpIndex); - pvpIndex += recordCount; - } else - writeSuccess = false; - break; - case CHARACTER: - if (pushCharacterRecords() == true) { - recordCount = Math.max(0, charDelta - charIndex); - charIndex += recordCount; - } else - writeSuccess = false; - break; - case REALM: - if (pushRealmRecords() == true) { - recordCount = Math.max(0, realmDelta - realmIndex); - realmIndex += recordCount; - } - else - writeSuccess = false; - break; - case GUILD: - if (pushGuildRecords() == true) { - recordCount = Math.max(0, guildDelta - guildIndex); - guildIndex += recordCount; - } - else - writeSuccess = false; - break; - case BANE: - if (pushBaneRecords() == true) { - recordCount = Math.max(0, baneDelta - baneIndex); - baneIndex += recordCount; - } - else - writeSuccess = false; - break; - case CITY: - if (pushCityRecords() == true) { - recordCount = Math.max(0, cityDelta - cityIndex); - cityIndex += recordCount; - } else - writeSuccess = false; - break; - case MINE: - if (pushMineRecords() == true) { - recordCount = Math.max(0, mineDelta - mineIndex); - mineIndex += recordCount; - } else - writeSuccess = false; - break; - default: - recordCount = 0; - writeSuccess = false; - break; // unhandled type - } - - if (writeSuccess == true) - Logger.info( recordCount + " " + recordType.name() + " records sent to remote"); - else - Logger.info( recordCount + " returning failed success"); - - } // Iterate switch - - // Update indices - - updateWarehouseIndex(); - - // Update dirty records - - Logger.info( "Pushing updates of dirty warehouse records"); - CharacterRecord.updateDirtyRecords(); - - if (charDelta > 0) - Logger.info( charDelta + " dirty character records were sent"); - ; - BaneRecord.updateDirtyRecords(); - - if (baneDelta > 0) - Logger.info( baneDelta + " dirty bane records were sent"); - - Logger.info( "Process has completed"); - - } - - public static boolean pushMineRecords() { - - try (Connection localConnection = DbManager.getConnection(); - PreparedStatement statement = MineRecord.buildMineQueryStatement(localConnection); - ResultSet rs = statement.executeQuery()) { - - while (rs.next()) { - pushMineRecord(rs); - mineDelta = rs.getInt("event_number"); - } - - return true; - } catch (SQLException e) { - Logger.error("Error with local DB connection: " + e.toString()); - e.printStackTrace(); - return false; - } - } - - public static boolean pushCharacterRecords() { - - try (Connection localConnection = DbManager.getConnection(); - PreparedStatement statement = CharacterRecord.buildCharacterQueryStatement(localConnection); - ResultSet rs = statement.executeQuery()) { - - while (rs.next()) { - pushCharacterRecord(rs); - charDelta = rs.getInt("event_number"); - } - - return true; - } catch (SQLException e) { - Logger.error("Error with local DB connection: " + e.toString()); - e.printStackTrace(); - return false; - } - } - - private static boolean pushGuildRecords() { - - try (Connection localConnection = DbManager.getConnection(); - PreparedStatement statement = GuildRecord.buildGuildQueryStatement(localConnection); - ResultSet rs = statement.executeQuery()) { - - while (rs.next()) { - pushGuildRecord(rs); - guildDelta = rs.getInt("event_number"); - } - - return true; - } catch (SQLException e) { - Logger.error("Error with local DB connection: " + e.toString()); - e.printStackTrace(); - return false; - } - } - - private static boolean pushMineRecord(ResultSet rs) { - - try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection(); - PreparedStatement statement = MineRecord.buildMinePushStatement(remoteConnection, rs)) { + private static boolean pushMineRecord(ResultSet rs) { - statement.execute(); - return true; + try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection(); + PreparedStatement statement = MineRecord.buildMinePushStatement(remoteConnection, rs)) { - } catch (SQLException e) { - Logger.error( e.toString()); - return false; - } - } + statement.execute(); + return true; - private static boolean pushGuildRecord(ResultSet rs) { + } catch (SQLException e) { + Logger.error(e.toString()); + return false; + } + } - try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection(); - PreparedStatement statement = GuildRecord.buildGuildPushStatement(remoteConnection, rs)) { + private static boolean pushGuildRecord(ResultSet rs) { - statement.execute(); - return true; + try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection(); + PreparedStatement statement = GuildRecord.buildGuildPushStatement(remoteConnection, rs)) { - } catch (SQLException e) { - Logger.error(e.toString()); - return false; - } - } + statement.execute(); + return true; - private static boolean pushBaneRecords() { + } catch (SQLException e) { + Logger.error(e.toString()); + return false; + } + } - try (Connection localConnection = DbManager.getConnection(); - PreparedStatement statement = BaneRecord.buildBaneQueryStatement(localConnection); - ResultSet rs = statement.executeQuery()) { + private static boolean pushBaneRecords() { - while (rs.next()) { - pushBaneRecord(rs); - baneDelta = rs.getInt("event_number"); - } + try (Connection localConnection = DbManager.getConnection(); + PreparedStatement statement = BaneRecord.buildBaneQueryStatement(localConnection); + ResultSet rs = statement.executeQuery()) { - return true; - } catch (SQLException e) { - Logger.error("Error with local DB connection: " + e.toString()); - e.printStackTrace(); - return false; - } - } - - private static boolean pushBaneRecord(ResultSet rs) { + while (rs.next()) { + pushBaneRecord(rs); + baneDelta = rs.getInt("event_number"); + } - try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection(); - PreparedStatement statement = BaneRecord.buildBanePushStatement(remoteConnection, rs)) { + return true; + } catch (SQLException e) { + Logger.error("Error with local DB connection: " + e.toString()); + e.printStackTrace(); + return false; + } + } - statement.execute(); - return true; + private static boolean pushBaneRecord(ResultSet rs) { - } catch (SQLException e) { - Logger.error(e.toString()); - return false; - } - } + try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection(); + PreparedStatement statement = BaneRecord.buildBanePushStatement(remoteConnection, rs)) { - private static boolean pushCityRecords() { + statement.execute(); + return true; - try (Connection localConnection = DbManager.getConnection(); - PreparedStatement statement = CityRecord.buildCityQueryStatement(localConnection); - ResultSet rs = statement.executeQuery()) { + } catch (SQLException e) { + Logger.error(e.toString()); + return false; + } + } - while (rs.next()) { - pushCityRecord(rs); - cityDelta = rs.getInt("event_number"); - } + private static boolean pushCityRecords() { - return true; - } catch (SQLException e) { - Logger.error("Error with local DB connection: " + e.toString()); - e.printStackTrace(); - return false; - } - } + try (Connection localConnection = DbManager.getConnection(); + PreparedStatement statement = CityRecord.buildCityQueryStatement(localConnection); + ResultSet rs = statement.executeQuery()) { - private static boolean pushPvpRecords() { + while (rs.next()) { + pushCityRecord(rs); + cityDelta = rs.getInt("event_number"); + } - try (Connection localConnection = DbManager.getConnection(); - PreparedStatement statement = PvpRecord.buildPvpQueryStatement(localConnection); - ResultSet rs = statement.executeQuery()) { + return true; + } catch (SQLException e) { + Logger.error("Error with local DB connection: " + e.toString()); + e.printStackTrace(); + return false; + } + } - while (rs.next()) { + private static boolean pushPvpRecords() { - if (pushPvpRecord(rs) == true) - pvpDelta = rs.getInt("event_number"); - } + try (Connection localConnection = DbManager.getConnection(); + PreparedStatement statement = PvpRecord.buildPvpQueryStatement(localConnection); + ResultSet rs = statement.executeQuery()) { - return true; - } catch (SQLException e) { - Logger.error("Error with local DB connection: " + e.toString()); - return false; - } - } + while (rs.next()) { - private static boolean pushPvpRecord(ResultSet rs) { + if (pushPvpRecord(rs) == true) + pvpDelta = rs.getInt("event_number"); + } - try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection(); - PreparedStatement statement = PvpRecord.buildPvpPushStatement(remoteConnection, rs)) { + return true; + } catch (SQLException e) { + Logger.error("Error with local DB connection: " + e.toString()); + return false; + } + } - statement.execute(); - return true; - } catch (SQLException e) { - Logger.error(e.toString()); - return false; - } + private static boolean pushPvpRecord(ResultSet rs) { - } + try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection(); + PreparedStatement statement = PvpRecord.buildPvpPushStatement(remoteConnection, rs)) { - private static boolean pushRealmRecords() { + statement.execute(); + return true; + } catch (SQLException e) { + Logger.error(e.toString()); + return false; + } - try (Connection localConnection = DbManager.getConnection(); - PreparedStatement statement = RealmRecord.buildRealmQueryStatement(localConnection); - ResultSet rs = statement.executeQuery()) { + } - while (rs.next()) { + private static boolean pushRealmRecords() { - if (pushRealmRecord(rs) == true) - realmDelta = rs.getInt("event_number"); - } + try (Connection localConnection = DbManager.getConnection(); + PreparedStatement statement = RealmRecord.buildRealmQueryStatement(localConnection); + ResultSet rs = statement.executeQuery()) { - return true; - } catch (SQLException e) { - Logger.error("Error with local DB connection: " + e.toString()); - e.printStackTrace(); - return false; - } - } + while (rs.next()) { - private static boolean pushRealmRecord(ResultSet rs) { + if (pushRealmRecord(rs) == true) + realmDelta = rs.getInt("event_number"); + } - try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection(); - PreparedStatement statement = RealmRecord.buildRealmPushStatement(remoteConnection, rs)) { - statement.execute(); - return true; + return true; + } catch (SQLException e) { + Logger.error("Error with local DB connection: " + e.toString()); + e.printStackTrace(); + return false; + } + } - } catch (SQLException e) { - Logger.error( e.toString()); - return false; - } + private static boolean pushRealmRecord(ResultSet rs) { - } + try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection(); + PreparedStatement statement = RealmRecord.buildRealmPushStatement(remoteConnection, rs)) { + statement.execute(); + return true; - private static boolean pushCharacterRecord(ResultSet rs) { + } catch (SQLException e) { + Logger.error(e.toString()); + return false; + } - try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection(); - PreparedStatement statement = CharacterRecord.buildCharacterPushStatement(remoteConnection, rs)) { + } - statement.execute(); - return true; + private static boolean pushCharacterRecord(ResultSet rs) { - } catch (SQLException e) { - Logger.error(e.toString()); - return false; - } + try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection(); + PreparedStatement statement = CharacterRecord.buildCharacterPushStatement(remoteConnection, rs)) { - } + statement.execute(); + return true; - private static boolean pushCityRecord(ResultSet rs) { + } catch (SQLException e) { + Logger.error(e.toString()); + return false; + } - try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection(); - PreparedStatement statement = CityRecord.buildCityPushStatement(remoteConnection, rs)) { + } - statement.execute(); - return true; + private static boolean pushCityRecord(ResultSet rs) { - } catch (SQLException e) { - Logger.error( e.toString()); - return false; - } - } + try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection(); + PreparedStatement statement = CityRecord.buildCityPushStatement(remoteConnection, rs)) { - private static boolean readWarehouseIndex() { + statement.execute(); + return true; - // Member variable declaration + } catch (SQLException e) { + Logger.error(e.toString()); + return false; + } + } + + private static boolean readWarehouseIndex() { + + // Member variable declaration + + String queryString; - String queryString; + queryString = "SELECT * FROM `warehouse_index`"; - queryString = "SELECT * FROM `warehouse_index`"; + try (Connection localConnection = DbManager.getConnection(); + CallableStatement statement = localConnection.prepareCall(queryString); + ResultSet rs = statement.executeQuery()) { - try (Connection localConnection = DbManager.getConnection(); - CallableStatement statement = localConnection.prepareCall(queryString); - ResultSet rs = statement.executeQuery()) { + while (rs.next()) { + charIndex = rs.getInt("charIndex"); + cityIndex = rs.getInt("cityIndex"); + guildIndex = rs.getInt("guildIndex"); + realmIndex = rs.getInt("realmIndex"); + baneIndex = rs.getInt("baneIndex"); + pvpIndex = rs.getInt("pvpIndex"); + mineIndex = rs.getInt("mineIndex"); + } - while (rs.next()) { - charIndex = rs.getInt("charIndex"); - cityIndex = rs.getInt("cityIndex"); - guildIndex = rs.getInt("guildIndex"); - realmIndex = rs.getInt("realmIndex"); - baneIndex = rs.getInt("baneIndex"); - pvpIndex = rs.getInt("pvpIndex"); - mineIndex = rs.getInt("mineIndex"); - } + return true; - return true; + } catch (SQLException e) { + Logger.error("Error reading warehouse index" + e.toString()); + e.printStackTrace(); + return false; + } + } + + private static boolean updateWarehouseIndex() { - } catch (SQLException e) { - Logger.error( "Error reading warehouse index" + e.toString()); - e.printStackTrace(); - return false; - } - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement statement = WarehousePushThread.buildIndexUpdateStatement(connection)) { - private static boolean updateWarehouseIndex() { + statement.execute(); + return true; + + } catch (SQLException e) { + Logger.error(e.toString()); + return false; + } + } - try (Connection connection = DbManager.getConnection(); - PreparedStatement statement = WarehousePushThread.buildIndexUpdateStatement(connection)) { + private static PreparedStatement buildIndexUpdateStatement(Connection connection) throws SQLException { - statement.execute(); - return true; + PreparedStatement outStatement = null; + String queryString = "UPDATE `warehouse_index` SET `charIndex` = ?, `cityIndex` = ?, `guildIndex` = ?, `realmIndex` = ?, `baneIndex` = ?, `pvpIndex` = ?, `mineIndex` = ?"; + outStatement = connection.prepareStatement(queryString); - } catch (SQLException e) { - Logger.error(e.toString()); - return false; - } - } + // Bind record data - private static PreparedStatement buildIndexUpdateStatement(Connection connection) throws SQLException { + outStatement.setInt(1, charIndex); + outStatement.setInt(2, cityIndex); + outStatement.setInt(3, guildIndex); + outStatement.setInt(4, realmIndex); + outStatement.setInt(5, baneIndex); + outStatement.setInt(6, pvpIndex); + outStatement.setInt(7, mineIndex); + return outStatement; + } - PreparedStatement outStatement = null; - String queryString = "UPDATE `warehouse_index` SET `charIndex` = ?, `cityIndex` = ?, `guildIndex` = ?, `realmIndex` = ?, `baneIndex` = ?, `pvpIndex` = ?, `mineIndex` = ?"; - outStatement = connection.prepareStatement(queryString); + public void run() { - // Bind record data + int recordCount = 0; + boolean writeSuccess = true; + + if (ConfigManager.MB_WORLD_WAREHOUSE_PUSH.getValue().equals("false")) { + Logger.info("WAREHOUSEPUSH DISABLED: EARLY EXIT"); + return; + } + + // Cache where we left off from the last push + // for each of the warehouse tables + + if (readWarehouseIndex() == false) + return; - outStatement.setInt(1, charIndex); - outStatement.setInt(2, cityIndex); - outStatement.setInt(3, guildIndex); - outStatement.setInt(4, realmIndex); - outStatement.setInt(5, baneIndex); - outStatement.setInt(6, pvpIndex); - outStatement.setInt(7, mineIndex); - return outStatement; - } + // Log run to console + + Logger.info("Pushing records to remote..."); + + // Push records to remote database + + for (Enum.DataRecordType recordType : Enum.DataRecordType.values()) { + + switch (recordType) { + case PVP: + if (pushPvpRecords() == true) { + recordCount = Math.max(0, pvpDelta - pvpIndex); + pvpIndex += recordCount; + } else + writeSuccess = false; + break; + case CHARACTER: + if (pushCharacterRecords() == true) { + recordCount = Math.max(0, charDelta - charIndex); + charIndex += recordCount; + } else + writeSuccess = false; + break; + case REALM: + if (pushRealmRecords() == true) { + recordCount = Math.max(0, realmDelta - realmIndex); + realmIndex += recordCount; + } else + writeSuccess = false; + break; + case GUILD: + if (pushGuildRecords() == true) { + recordCount = Math.max(0, guildDelta - guildIndex); + guildIndex += recordCount; + } else + writeSuccess = false; + break; + case BANE: + if (pushBaneRecords() == true) { + recordCount = Math.max(0, baneDelta - baneIndex); + baneIndex += recordCount; + } else + writeSuccess = false; + break; + case CITY: + if (pushCityRecords() == true) { + recordCount = Math.max(0, cityDelta - cityIndex); + cityIndex += recordCount; + } else + writeSuccess = false; + break; + case MINE: + if (pushMineRecords() == true) { + recordCount = Math.max(0, mineDelta - mineIndex); + mineIndex += recordCount; + } else + writeSuccess = false; + break; + default: + recordCount = 0; + writeSuccess = false; + break; // unhandled type + } + + if (writeSuccess == true) + Logger.info(recordCount + " " + recordType.name() + " records sent to remote"); + else + Logger.info(recordCount + " returning failed success"); + + } // Iterate switch + + // Update indices + + updateWarehouseIndex(); + + // Update dirty records + + Logger.info("Pushing updates of dirty warehouse records"); + CharacterRecord.updateDirtyRecords(); + + if (charDelta > 0) + Logger.info(charDelta + " dirty character records were sent"); + ; + BaneRecord.updateDirtyRecords(); + + if (baneDelta > 0) + Logger.info(baneDelta + " dirty bane records were sent"); + + Logger.info("Process has completed"); + + } }