diff --git a/CMakeLists.txt b/CMakeLists.txt index 54f0d0dd..41d4219f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,6 +163,7 @@ set(INCLUDED_DIRECTORIES "dGame/dMission" "dGame/dEntity" "dGame/dPropertyBehaviors" + "dGame/dPropertyBehaviors/ControlBehaviorMessages" "dGame/dUtilities" "dPhysics" "dNavigation" diff --git a/dCommon/GeneralUtils.h b/dCommon/GeneralUtils.h index d43ad9b1..a2a52b45 100644 --- a/dCommon/GeneralUtils.h +++ b/dCommon/GeneralUtils.h @@ -15,6 +15,7 @@ #include "dLogger.h" enum eInventoryType : uint32_t; +enum class eReplicaComponentType : uint32_t; /*! \file GeneralUtils.hpp @@ -181,6 +182,11 @@ namespace GeneralUtils { return static_cast(std::stoul(value)); } + template <> + inline eReplicaComponentType Parse(const char* value) { + return static_cast(std::stoul(value)); + } + template bool TryParse(const char* value, T& dst) { try { diff --git a/dPhysics/Singleton.h b/dCommon/Singleton.h similarity index 100% rename from dPhysics/Singleton.h rename to dCommon/Singleton.h diff --git a/dCommon/dEnums/dCommonVars.h b/dCommon/dEnums/dCommonVars.h index c90fd8e6..2b7f63dc 100644 --- a/dCommon/dEnums/dCommonVars.h +++ b/dCommon/dEnums/dCommonVars.h @@ -43,8 +43,7 @@ typedef uint32_t LWOCLONEID; //!< Used for Clone IDs typedef uint16_t LWOMAPID; //!< Used for Map IDs typedef uint16_t LWOINSTANCEID; //!< Used for Instance IDs typedef uint32_t PROPERTYCLONELIST; //!< Used for Property Clone IDs -typedef uint32_t STRIPID; -typedef uint32_t BEHAVIORSTATE; +typedef uint32_t StripId; typedef int32_t PetTamingPiece; //!< Pet Taming Pieces @@ -65,11 +64,6 @@ typedef std::set TSetObjID; const float PI = 3.14159f; -#if defined(__unix) || defined(__APPLE__) -//For Linux: -typedef __int64_t __int64; -#endif - //============ STRUCTS ============== struct LWOSCENEID { @@ -262,20 +256,6 @@ enum eReplicaPacketType { PACKET_TYPE_DESTRUCTION //!< A destruction packet }; -enum ServerDisconnectIdentifiers { - SERVER_DISCON_UNKNOWN_SERVER_ERROR = 0, //!< Unknown server error - SERVER_DISCON_DUPLICATE_LOGIN = 4, //!< Used when another user with the same username is logged in (duplicate login) - SERVER_DISCON_SERVER_SHUTDOWN = 5, //!< Used when the server is shutdown - SERVER_DISCON_SERVER_MAP_LOAD_FAILURE = 6, //!< Used when the server cannot load a map - SERVER_DISCON_INVALID_SESSION_KEY = 7, //!< Used if the session is invalid - SERVER_DISCON_ACCOUNT_NOT_IN_PENDING_LIST = 8, //!< ??? - SERVER_DISCON_CHARACTER_NOT_FOUND = 9, //!< Used if a character that the server has is not found (i.e, corruption with user-player data) - SERVER_DISCON_CHARACTER_CORRUPTED = 10, //!< Similar to abovce - SERVER_DISCON_KICK = 11, //!< Used if the user is kicked from the server - SERVER_DISCON_FREE_TRIAL_EXPIRED = 12, //!< Used if the user's free trial expired - SERVER_DISCON_PLAY_SCHEDULE_TIME_DONE = 13 //!< Used if the user's play time is used up -}; - //! The Behavior Types for use with the AI system enum eCombatBehaviorTypes : uint32_t { PASSIVE = 0, //!< The object is passive @@ -380,57 +360,6 @@ enum eNotifyType { NOTIFY_TYPE_NAMINGPET }; -enum eReplicaComponentType : int32_t { - COMPONENT_TYPE_CONTROLLABLE_PHYSICS = 1, //!< The ControllablePhysics Component - COMPONENT_TYPE_RENDER = 2, //!< The Render Component - COMPONENT_TYPE_SIMPLE_PHYSICS = 3, //!< The SimplePhysics Component - COMPONENT_TYPE_CHARACTER = 4, //!< The Character Component - COMPONENT_TYPE_SCRIPT = 5, //!< The Script Component - COMPONENT_TYPE_BOUNCER = 6, //!< The Bouncer Component - COMPONENT_TYPE_BUFF = 7, //!< The Buff Component - COMPONENT_TYPE_SKILL = 9, //!< The Skill Component - COMPONENT_TYPE_ITEM = 11, //!< The Item Component - COMPONENT_TYPE_VENDOR = 16, //!< The Vendor Component - COMPONENT_TYPE_INVENTORY = 17, //!< The Inventory Component - COMPONENT_TYPE_SHOOTING_GALLERY = 19, //!< The Shooting Gallery Component - COMPONENT_TYPE_RIGID_BODY_PHANTOM_PHYSICS = 20, //!< The RigidBodyPhantomPhysics Component - COMPONENT_TYPE_COLLECTIBLE = 23, //!< The Collectible Component - COMPONENT_TYPE_MOVING_PLATFORM = 25, //!< The MovingPlatform Component - COMPONENT_TYPE_PET = 26, //!< The Pet Component - COMPONENT_TYPE_VEHICLE_PHYSICS = 30, //!< The VehiclePhysics Component - COMPONENT_TYPE_MOVEMENT_AI = 31, //!< The MovementAI Component - COMPONENT_TYPE_PROPERTY = 36, //!< The Property Component - COMPONENT_TYPE_SCRIPTED_ACTIVITY = 39, //!< The ScriptedActivity Component - COMPONENT_TYPE_PHANTOM_PHYSICS = 40, //!< The PhantomPhysics Component - COMPONENT_TYPE_MODEL = 42, //!< The Model Component - COMPONENT_TYPE_PROPERTY_ENTRANCE = 43, //!< The PhantomPhysics Component - COMPONENT_TYPE_PROPERTY_MANAGEMENT = 45, //!< The PropertyManagement Component - COMPONENT_TYPE_REBUILD = 48, //!< The Rebuild Component - COMPONENT_TYPE_SWITCH = 49, //!< The Switch Component - COMPONENT_TYPE_ZONE_CONTROL = 50, //!< The ZoneControl Component - COMPONENT_TYPE_PACKAGE = 53, //!< The Package Component - COMPONENT_TYPE_PLAYER_FLAG = 58, //!< The PlayerFlag Component - COMPONENT_TYPE_BASE_COMBAT_AI = 60, //!< The BaseCombatAI Component - COMPONENT_TYPE_MODULE_ASSEMBLY = 61, //!< The ModuleAssembly Component - COMPONENT_TYPE_PROPERTY_VENDOR = 65, //!< The PropertyVendor Component - COMPONENT_TYPE_ROCKET_LAUNCH = 67, //!< The RocketLaunch Component - COMPONENT_TYPE_TRIGGER = 69, - COMPONENT_TYPE_RACING_CONTROL = 71, //!< The RacingControl Component - COMPONENT_TYPE_MISSION_OFFER = 73, //!< The MissionOffer Component - COMPONENT_TYPE_EXHIBIT = 75, //!< The Exhibit Component - COMPONENT_TYPE_RACING_STATS = 74, //!< The Racing Stats Component - COMPONENT_TYPE_SOUND_TRIGGER = 77, //!< The Sound Trigger Component - COMPONENT_TYPE_PROXIMITY_MONITOR = 78, //!< The Proximity Monitor Component - COMPONENT_TYPE_MISSION = 84, //!< The Mission Component - COMPONENT_TYPE_ROCKET_LAUNCH_LUP = 97, //!< The LUP Launchpad Componen - COMPONENT_TYPE_RAIL_ACTIVATOR = 104, //!< The Rail Activator Component - COMPONENT_TYPE_PLAYER_FORCED_MOVEMENT = 106, //!< The Player Forced Movement Component - COMPONENT_TYPE_POSSESSABLE = 108, //!< The Possessable Component - COMPONENT_TYPE_LEVEL_PROGRESSION = 109, //!< The Level Progression Component - COMPONENT_TYPE_POSSESSOR = 110, //!< The Possessor Component - COMPONENT_TYPE_BUILD_BORDER = 114, //!< The Build Border Component - COMPONENT_TYPE_DESTROYABLE = 1000, //!< The Destroyable Component -}; enum class UseItemResponse : uint32_t { NoImaginationForPet = 1, diff --git a/dCommon/dEnums/dMessageIdentifiers.h b/dCommon/dEnums/dMessageIdentifiers.h index c1afc497..e11f9e7f 100644 --- a/dCommon/dEnums/dMessageIdentifiers.h +++ b/dCommon/dEnums/dMessageIdentifiers.h @@ -546,6 +546,8 @@ enum GAME_MSG : unsigned short { GAME_MSG_REMOVE_RUN_SPEED_MODIFIER = 1506, GAME_MSG_UPDATE_PROPERTY_PERFORMANCE_COST = 1547, GAME_MSG_PROPERTY_ENTRANCE_BEGIN = 1553, + GAME_MSG_SET_RESURRECT_RESTORE_VALUES = 1591, + GAME_MSG_VEHICLE_STOP_BOOST = 1617, GAME_MSG_REMOVE_BUFF = 1648, GAME_MSG_REQUEST_MOVE_ITEM_BETWEEN_INVENTORY_TYPES = 1666, GAME_MSG_RESPONSE_MOVE_ITEM_BETWEEN_INVENTORY_TYPES = 1667, diff --git a/dCommon/dEnums/eReplicaComponentType.h b/dCommon/dEnums/eReplicaComponentType.h new file mode 100644 index 00000000..3eee16f3 --- /dev/null +++ b/dCommon/dEnums/eReplicaComponentType.h @@ -0,0 +1,127 @@ +#ifndef __EREPLICACOMPONENTTYPE__H__ +#define __EREPLICACOMPONENTTYPE__H__ + +#include + +enum class eReplicaComponentType : uint32_t { + INVALID = 0, + CONTROLLABLE_PHYSICS, + RENDER, + SIMPLE_PHYSICS, + CHARACTER, + SCRIPT, + BOUNCER, + BUFF, // buff is really 98, this is DESTROYABLE + GHOST, + SKILL, + SPAWNER, + ITEM, + REBUILD, + REBUILD_START, + REBUILD_ACTIVATOR, + ICON_ONLY, + VENDOR, + INVENTORY, + PROJECTILE_PHYSICS, + SHOOTING_GALLERY, + RIGID_BODY_PHANTOM_PHYSICS, + DROP_EFFECT, + CHEST, + COLLECTIBLE, + BLUEPRINT, + MOVING_PLATFORM, + PET, + PLATFORM_BOUNDARY, + MODULE, + ARCADE, + VEHICLE_PHYSICS, // Havok demo based + MOVEMENT_AI, + EXHIBIT, + OVERHEAD_ICON, + PET_CONTROL, + MINIFIG, + PROPERTY, + PET_CREATOR, + MODEL_BUILDER, + SCRIPTED_ACTIVITY, + PHANTOM_PHYSICS, + SPRINGPAD, + MODEL, + PROPERTY_ENTRANCE, + FX, + PROPERTY_MANAGEMENT, + VEHICLE_PHYSICS_NEW, // internal physics based on havok + PHYSICS_SYSTEM, + QUICK_BUILD, + SWITCH, + ZONE_CONTROL, // Minigame + CHANGLING, + CHOICE_BUILD, + PACKAGE, + SOUND_REPEATER, + SOUND_AMBIENT_2D, + SOUND_AMBIENT_3D, + PRECONDITION, + PLAYER_FLAG, + CUSTOM_BUILD_ASSEMBLY, + BASE_COMBAT_AI, + MODULE_ASSEMBLY, + SHOWCASE_MODEL_HANDLER, + RACING_MODULE, + GENERIC_ACTIVATOR, + PROPERTY_VENDOR, + HF_LIGHT_DIRECTION_GADGET, + ROCKET_LAUNCH, + ROCKET_LANDING, + TRIGGER, + DROPPED_LOOT, + RACING_CONTROL, + FACTION_TRIGGER, + MISSION_OFFER, + RACING_STATS, + LUP_EXHIBIT, + BBB, + SOUND_TRIGGER, + PROXIMITY_MONITOR, + RACING_SOUND_TRIGGER, + CHAT, + FRIENDS_LIST, + GUILD, + LOCAL_SYSTEM, + MISSION, + MUTABLE_MODEL_BEHAVIORS, + PATHFINDING, + PET_TAMING_CONTROL, + PROPERTY_EDITOR, + SKINNED_RENDER, + SLASH_COMMAND, + STATUS_EFFECT, + TEAMS, + TEXT_EFFECT, + TRADE, + USER_CONTROL, + IGNORE_LIST, + ROCKET_LAUNCH_LUP, + BUFF_REAL, // the real buff component, should just be name BUFF + INTERACTION_MANAGER, + DONATION_VENDOR, + COMBAT_MEDIATOR, + COMMENDATION_VENDOR, + UNKNOWN_103, + RAIL_ACTIVATOR, + ROLLER, + PLAYER_FORCED_MOVEMENT, + CRAFTING, + POSSESSABLE, + LEVEL_PROGRESSION, + POSSESSOR, + MOUNT_CONTROL, + UNKNOWN_112, + PROPERTY_PLAQUE, + BUILD_BORDER, + UNKOWN_115, + CULLING_PLANE, + DESTROYABLE = 1000 // Actually 7 +}; + +#endif //!__EREPLICACOMPONENTTYPE__H__ diff --git a/dCommon/dEnums/eServerDisconnectIdentifiers.h b/dCommon/dEnums/eServerDisconnectIdentifiers.h new file mode 100644 index 00000000..99d2cd44 --- /dev/null +++ b/dCommon/dEnums/eServerDisconnectIdentifiers.h @@ -0,0 +1,24 @@ +#ifndef __ESERVERDISCONNECTIDENTIFIERS__H__ +#define __ESERVERDISCONNECTIDENTIFIERS__H__ + +#include + +enum class eServerDisconnectIdentifiers : uint32_t { + UNKNOWN_SERVER_ERROR = 0, + WRONG_GAME_VERSION, + WRONG_SERVER_VERSION, + CONNECTION_ON_INVALID_PORT, + DUPLICATE_LOGIN, + SERVER_SHUTDOWN, + SERVER_MAP_LOAD_FAILURE, + INVALID_SESSION_KEY, + ACCOUNT_NOT_IN_PENDING_LIST, + CHARACTER_NOT_FOUND, + CHARACTER_CORRUPTED, + KICK, + SAVE_FAILURE, + FREE_TRIAL_EXPIRED, + PLAY_SCHEDULE_TIME_DONE +}; + +#endif //!__ESERVERDISCONNECTIDENTIFIERS__H__ diff --git a/dDatabase/CDClientManager.cpp b/dDatabase/CDClientManager.cpp index 4b32e749..eeea686f 100644 --- a/dDatabase/CDClientManager.cpp +++ b/dDatabase/CDClientManager.cpp @@ -1,46 +1,80 @@ #include "CDClientManager.h" +#include "CDActivityRewardsTable.h" +#include "CDAnimationsTable.h" +#include "CDBehaviorParameterTable.h" +#include "CDBehaviorTemplateTable.h" +#include "CDComponentsRegistryTable.h" +#include "CDCurrencyTableTable.h" +#include "CDDestructibleComponentTable.h" +#include "CDEmoteTable.h" +#include "CDInventoryComponentTable.h" +#include "CDItemComponentTable.h" +#include "CDItemSetsTable.h" +#include "CDItemSetSkillsTable.h" +#include "CDLevelProgressionLookupTable.h" +#include "CDLootMatrixTable.h" +#include "CDLootTableTable.h" +#include "CDMissionNPCComponentTable.h" +#include "CDMissionTasksTable.h" +#include "CDMissionsTable.h" +#include "CDObjectSkillsTable.h" +#include "CDObjectsTable.h" +#include "CDPhysicsComponentTable.h" +#include "CDRebuildComponentTable.h" +#include "CDScriptComponentTable.h" +#include "CDSkillBehaviorTable.h" +#include "CDZoneTableTable.h" +#include "CDVendorComponentTable.h" +#include "CDActivitiesTable.h" +#include "CDPackageComponentTable.h" +#include "CDProximityMonitorComponentTable.h" +#include "CDMovementAIComponentTable.h" +#include "CDBrickIDTableTable.h" +#include "CDRarityTableTable.h" +#include "CDMissionEmailTable.h" +#include "CDRewardsTable.h" +#include "CDPropertyEntranceComponentTable.h" +#include "CDPropertyTemplateTable.h" +#include "CDFeatureGatingTable.h" +#include "CDRailActivatorComponent.h" -// Static Variables -CDClientManager* CDClientManager::m_Address = nullptr; - -//! Initializes the manager -void CDClientManager::Initialize(void) { - tables.insert(std::make_pair("ActivityRewards", new CDActivityRewardsTable())); - UNUSED(tables.insert(std::make_pair("Animations", new CDAnimationsTable()))); - tables.insert(std::make_pair("BehaviorParameter", new CDBehaviorParameterTable())); - tables.insert(std::make_pair("BehaviorTemplate", new CDBehaviorTemplateTable())); - tables.insert(std::make_pair("ComponentsRegistry", new CDComponentsRegistryTable())); - tables.insert(std::make_pair("CurrencyTable", new CDCurrencyTableTable())); - tables.insert(std::make_pair("DestructibleComponent", new CDDestructibleComponentTable())); - tables.insert(std::make_pair("EmoteTable", new CDEmoteTableTable())); - tables.insert(std::make_pair("InventoryComponent", new CDInventoryComponentTable())); - tables.insert(std::make_pair("ItemComponent", new CDItemComponentTable())); - tables.insert(std::make_pair("ItemSets", new CDItemSetsTable())); - tables.insert(std::make_pair("ItemSetSkills", new CDItemSetSkillsTable())); - tables.insert(std::make_pair("LevelProgressionLookup", new CDLevelProgressionLookupTable())); - tables.insert(std::make_pair("LootMatrix", new CDLootMatrixTable())); - tables.insert(std::make_pair("LootTable", new CDLootTableTable())); - tables.insert(std::make_pair("MissionNPCComponent", new CDMissionNPCComponentTable())); - tables.insert(std::make_pair("MissionTasks", new CDMissionTasksTable())); - tables.insert(std::make_pair("Missions", new CDMissionsTable())); - tables.insert(std::make_pair("ObjectSkills", new CDObjectSkillsTable())); - tables.insert(std::make_pair("Objects", new CDObjectsTable())); - tables.insert(std::make_pair("PhysicsComponent", new CDPhysicsComponentTable())); - tables.insert(std::make_pair("RebuildComponent", new CDRebuildComponentTable())); - tables.insert(std::make_pair("ScriptComponent", new CDScriptComponentTable())); - tables.insert(std::make_pair("SkillBehavior", new CDSkillBehaviorTable())); - tables.insert(std::make_pair("ZoneTable", new CDZoneTableTable())); - tables.insert(std::make_pair("VendorComponent", new CDVendorComponentTable())); - tables.insert(std::make_pair("Activities", new CDActivitiesTable())); - tables.insert(std::make_pair("PackageComponent", new CDPackageComponentTable())); - tables.insert(std::make_pair("ProximityMonitorComponent", new CDProximityMonitorComponentTable())); - tables.insert(std::make_pair("MovementAIComponent", new CDMovementAIComponentTable())); - tables.insert(std::make_pair("BrickIDTable", new CDBrickIDTableTable())); - tables.insert(std::make_pair("RarityTable", new CDRarityTableTable())); - tables.insert(std::make_pair("MissionEmail", new CDMissionEmailTable())); - tables.insert(std::make_pair("Rewards", new CDRewardsTable())); - tables.insert(std::make_pair("PropertyEntranceComponent", new CDPropertyEntranceComponentTable())); - tables.insert(std::make_pair("PropertyTemplate", new CDPropertyTemplateTable())); - tables.insert(std::make_pair("FeatureGating", new CDFeatureGatingTable())); - tables.insert(std::make_pair("RailActivatorComponent", new CDRailActivatorComponentTable())); +CDClientManager::CDClientManager() { + CDActivityRewardsTable::Instance(); + UNUSED(CDAnimationsTable::Instance()); + CDBehaviorParameterTable::Instance(); + CDBehaviorTemplateTable::Instance(); + CDComponentsRegistryTable::Instance(); + CDCurrencyTableTable::Instance(); + CDDestructibleComponentTable::Instance(); + CDEmoteTableTable::Instance(); + CDInventoryComponentTable::Instance(); + CDItemComponentTable::Instance(); + CDItemSetsTable::Instance(); + CDItemSetSkillsTable::Instance(); + CDLevelProgressionLookupTable::Instance(); + CDLootMatrixTable::Instance(); + CDLootTableTable::Instance(); + CDMissionNPCComponentTable::Instance(); + CDMissionTasksTable::Instance(); + CDMissionsTable::Instance(); + CDObjectSkillsTable::Instance(); + CDObjectsTable::Instance(); + CDPhysicsComponentTable::Instance(); + CDRebuildComponentTable::Instance(); + CDScriptComponentTable::Instance(); + CDSkillBehaviorTable::Instance(); + CDZoneTableTable::Instance(); + CDVendorComponentTable::Instance(); + CDActivitiesTable::Instance(); + CDPackageComponentTable::Instance(); + CDProximityMonitorComponentTable::Instance(); + CDMovementAIComponentTable::Instance(); + CDBrickIDTableTable::Instance(); + CDRarityTableTable::Instance(); + CDMissionEmailTable::Instance(); + CDRewardsTable::Instance(); + CDPropertyEntranceComponentTable::Instance(); + CDPropertyTemplateTable::Instance(); + CDFeatureGatingTable::Instance(); + CDRailActivatorComponentTable::Instance(); } diff --git a/dDatabase/CDClientManager.h b/dDatabase/CDClientManager.h index ea24a373..1754fe99 100644 --- a/dDatabase/CDClientManager.h +++ b/dDatabase/CDClientManager.h @@ -1,96 +1,24 @@ #pragma once -// Custom Classes #include "CDTable.h" -// Tables -#include "CDActivityRewardsTable.h" -#include "CDAnimationsTable.h" -#include "CDBehaviorParameterTable.h" -#include "CDBehaviorTemplateTable.h" -#include "CDComponentsRegistryTable.h" -#include "CDCurrencyTableTable.h" -#include "CDDestructibleComponentTable.h" -#include "CDEmoteTable.h" -#include "CDInventoryComponentTable.h" -#include "CDItemComponentTable.h" -#include "CDItemSetsTable.h" -#include "CDItemSetSkillsTable.h" -#include "CDLevelProgressionLookupTable.h" -#include "CDLootMatrixTable.h" -#include "CDLootTableTable.h" -#include "CDMissionNPCComponentTable.h" -#include "CDMissionTasksTable.h" -#include "CDMissionsTable.h" -#include "CDObjectSkillsTable.h" -#include "CDObjectsTable.h" -#include "CDPhysicsComponentTable.h" -#include "CDRebuildComponentTable.h" -#include "CDScriptComponentTable.h" -#include "CDSkillBehaviorTable.h" -#include "CDZoneTableTable.h" -#include "CDVendorComponentTable.h" -#include "CDActivitiesTable.h" -#include "CDPackageComponentTable.h" -#include "CDProximityMonitorComponentTable.h" -#include "CDMovementAIComponentTable.h" -#include "CDBrickIDTableTable.h" -#include "CDRarityTableTable.h" -#include "CDMissionEmailTable.h" -#include "CDRewardsTable.h" -#include "CDPropertyEntranceComponentTable.h" -#include "CDPropertyTemplateTable.h" -#include "CDFeatureGatingTable.h" -#include "CDRailActivatorComponent.h" +#include "Singleton.h" -// C++ -#include -#include - -/*! - \file CDClientManager.hpp - \brief A manager for the CDClient tables +/** + * Initialize the CDClient tables so they are all loaded into memory. */ - - //! Manages all data from the CDClient -class CDClientManager { -private: - static CDClientManager* m_Address; //!< The singleton address - - std::unordered_map tables; //!< The tables - +class CDClientManager : public Singleton { public: + CDClientManager(); - //! The singleton method - static CDClientManager* Instance() { - if (m_Address == 0) { - m_Address = new CDClientManager; - } - - return m_Address; - } - - //! Initializes the manager - void Initialize(void); - - //! Fetches a CDClient table - /*! - This function uses typename T which must be a subclass of CDTable. - It returns the class that conforms to the class name - - \param tableName The table name - \return The class or nullptr + /** + * Fetch a table from CDClient + * + * @tparam Table type to fetch + * @return A pointer to the requested table. */ template - T* GetTable(const std::string& tableName) { - static_assert(std::is_base_of::value, "T should inherit from CDTable!"); - - for (auto itr = this->tables.begin(); itr != this->tables.end(); ++itr) { - if (itr->first == tableName) { - return dynamic_cast(itr->second); - } - } - - return nullptr; + T* GetTable() { + return &T::Instance(); } }; diff --git a/dDatabase/Tables/CDActivitiesTable.cpp b/dDatabase/Tables/CDActivitiesTable.cpp index d6fa354e..e1660d66 100644 --- a/dDatabase/Tables/CDActivitiesTable.cpp +++ b/dDatabase/Tables/CDActivitiesTable.cpp @@ -1,6 +1,5 @@ #include "CDActivitiesTable.h" -//! Constructor CDActivitiesTable::CDActivitiesTable(void) { // First, get the size of the table @@ -48,15 +47,6 @@ CDActivitiesTable::CDActivitiesTable(void) { tableData.finalize(); } -//! Destructor -CDActivitiesTable::~CDActivitiesTable(void) {} - -//! Returns the table's name -std::string CDActivitiesTable::GetName(void) const { - return "Activities"; -} - -//! Queries the table with a custom "where" clause std::vector CDActivitiesTable::Query(std::function predicate) { std::vector data = cpplinq::from(this->entries) @@ -66,7 +56,6 @@ std::vector CDActivitiesTable::Query(std::function CDActivitiesTable::GetEntries(void) const { return this->entries; } diff --git a/dDatabase/Tables/CDActivitiesTable.h b/dDatabase/Tables/CDActivitiesTable.h index 51c560cf..4b60afbd 100644 --- a/dDatabase/Tables/CDActivitiesTable.h +++ b/dDatabase/Tables/CDActivitiesTable.h @@ -3,12 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDActivitiesTable.hpp - \brief Contains data for the Activities table - */ - - //! Activities Entry Struct struct CDActivities { unsigned int ActivityID; unsigned int locStatus; @@ -31,36 +25,14 @@ struct CDActivities { float optionalPercentage; }; - -//! Activities table -class CDActivitiesTable : public CDTable { +class CDActivitiesTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDActivitiesTable(void); - - //! Destructor - ~CDActivitiesTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDActivitiesTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ std::vector GetEntries(void) const; - }; diff --git a/dDatabase/Tables/CDActivityRewardsTable.cpp b/dDatabase/Tables/CDActivityRewardsTable.cpp index 3922d9fb..65ef1101 100644 --- a/dDatabase/Tables/CDActivityRewardsTable.cpp +++ b/dDatabase/Tables/CDActivityRewardsTable.cpp @@ -1,6 +1,5 @@ #include "CDActivityRewardsTable.h" -//! Constructor CDActivityRewardsTable::CDActivityRewardsTable(void) { // First, get the size of the table @@ -36,15 +35,6 @@ CDActivityRewardsTable::CDActivityRewardsTable(void) { tableData.finalize(); } -//! Destructor -CDActivityRewardsTable::~CDActivityRewardsTable(void) {} - -//! Returns the table's name -std::string CDActivityRewardsTable::GetName(void) const { - return "ActivityRewards"; -} - -//! Queries the table with a custom "where" clause std::vector CDActivityRewardsTable::Query(std::function predicate) { std::vector data = cpplinq::from(this->entries) @@ -54,7 +44,6 @@ std::vector CDActivityRewardsTable::Query(std::function CDActivityRewardsTable::GetEntries(void) const { return this->entries; } diff --git a/dDatabase/Tables/CDActivityRewardsTable.h b/dDatabase/Tables/CDActivityRewardsTable.h index 7f1e81a0..b5503fb6 100644 --- a/dDatabase/Tables/CDActivityRewardsTable.h +++ b/dDatabase/Tables/CDActivityRewardsTable.h @@ -3,12 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDActivityRewardsTable.hpp - \brief Contains data for the ActivityRewards table - */ - - //! ActivityRewards Entry Struct struct CDActivityRewards { unsigned int objectTemplate; //!< The object template (?) unsigned int ActivityRewardIndex; //!< The activity reward index @@ -19,36 +13,15 @@ struct CDActivityRewards { std::string description; //!< The description }; - -//! ActivityRewards table -class CDActivityRewardsTable : public CDTable { +class CDActivityRewardsTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDActivityRewardsTable(void); - - //! Destructor - ~CDActivityRewardsTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDActivityRewardsTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ std::vector GetEntries(void) const; }; diff --git a/dDatabase/Tables/CDAnimationsTable.cpp b/dDatabase/Tables/CDAnimationsTable.cpp index e21d44c5..e1227f39 100644 --- a/dDatabase/Tables/CDAnimationsTable.cpp +++ b/dDatabase/Tables/CDAnimationsTable.cpp @@ -1,6 +1,5 @@ #include "CDAnimationsTable.h" -//! Constructor CDAnimationsTable::CDAnimationsTable(void) { // First, get the size of the table @@ -42,15 +41,6 @@ CDAnimationsTable::CDAnimationsTable(void) { tableData.finalize(); } -//! Destructor -CDAnimationsTable::~CDAnimationsTable(void) {} - -//! Returns the table's name -std::string CDAnimationsTable::GetName(void) const { - return "Animations"; -} - -//! Queries the table with a custom "where" clause std::vector CDAnimationsTable::Query(std::function predicate) { std::vector data = cpplinq::from(this->entries) @@ -60,7 +50,6 @@ std::vector CDAnimationsTable::Query(std::function CDAnimationsTable::GetEntries(void) const { return this->entries; } diff --git a/dDatabase/Tables/CDAnimationsTable.h b/dDatabase/Tables/CDAnimationsTable.h index 24112985..43400abf 100644 --- a/dDatabase/Tables/CDAnimationsTable.h +++ b/dDatabase/Tables/CDAnimationsTable.h @@ -3,12 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDAnimationsTable.hpp - \brief Contains data for the Animations table - */ - - //! Animations Entry Struct struct CDAnimations { unsigned int animationGroupID; //!< The animation group ID std::string animation_type; //!< The animation type @@ -26,35 +20,14 @@ struct CDAnimations { }; -//! Animations table -class CDAnimationsTable : public CDTable { +class CDAnimationsTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDAnimationsTable(void); - - //! Destructor - ~CDAnimationsTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDAnimationsTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ std::vector GetEntries(void) const; - }; diff --git a/dDatabase/Tables/CDBehaviorParameterTable.cpp b/dDatabase/Tables/CDBehaviorParameterTable.cpp index b894688b..0713e740 100644 --- a/dDatabase/Tables/CDBehaviorParameterTable.cpp +++ b/dDatabase/Tables/CDBehaviorParameterTable.cpp @@ -1,7 +1,6 @@ #include "CDBehaviorParameterTable.h" #include "GeneralUtils.h" -//! Constructor CDBehaviorParameterTable::CDBehaviorParameterTable(void) { auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM BehaviorParameter"); uint32_t uniqueParameterId = 0; @@ -28,14 +27,6 @@ CDBehaviorParameterTable::CDBehaviorParameterTable(void) { tableData.finalize(); } -//! Destructor -CDBehaviorParameterTable::~CDBehaviorParameterTable(void) {} - -//! Returns the table's name -std::string CDBehaviorParameterTable::GetName(void) const { - return "BehaviorParameter"; -} - float CDBehaviorParameterTable::GetValue(const uint32_t behaviorID, const std::string& name, const float defaultValue) { auto parameterID = this->m_ParametersList.find(name); if (parameterID == this->m_ParametersList.end()) return defaultValue; diff --git a/dDatabase/Tables/CDBehaviorParameterTable.h b/dDatabase/Tables/CDBehaviorParameterTable.h index 5d0d8b72..b0715684 100644 --- a/dDatabase/Tables/CDBehaviorParameterTable.h +++ b/dDatabase/Tables/CDBehaviorParameterTable.h @@ -5,37 +5,18 @@ #include #include -/*! - \file CDBehaviorParameterTable.hpp - \brief Contains data for the BehaviorParameter table - */ - - //! BehaviorParameter Entry Struct struct CDBehaviorParameter { unsigned int behaviorID; //!< The Behavior ID std::unordered_map::iterator parameterID; //!< The Parameter ID float value; //!< The value of the behavior template }; -//! BehaviorParameter table -class CDBehaviorParameterTable : public CDTable { +class CDBehaviorParameterTable : public CDTable { private: std::unordered_map m_Entries; std::unordered_map m_ParametersList; public: - - //! Constructor - CDBehaviorParameterTable(void); - - //! Destructor - ~CDBehaviorParameterTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - + CDBehaviorParameterTable(); float GetValue(const uint32_t behaviorID, const std::string& name, const float defaultValue = 0); std::map GetParametersByBehaviorID(uint32_t behaviorID); diff --git a/dDatabase/Tables/CDBehaviorTemplateTable.cpp b/dDatabase/Tables/CDBehaviorTemplateTable.cpp index 4adb9bce..08bc86d1 100644 --- a/dDatabase/Tables/CDBehaviorTemplateTable.cpp +++ b/dDatabase/Tables/CDBehaviorTemplateTable.cpp @@ -1,6 +1,5 @@ #include "CDBehaviorTemplateTable.h" -//! Constructor CDBehaviorTemplateTable::CDBehaviorTemplateTable(void) { // First, get the size of the table @@ -40,15 +39,6 @@ CDBehaviorTemplateTable::CDBehaviorTemplateTable(void) { tableData.finalize(); } -//! Destructor -CDBehaviorTemplateTable::~CDBehaviorTemplateTable(void) {} - -//! Returns the table's name -std::string CDBehaviorTemplateTable::GetName(void) const { - return "BehaviorTemplate"; -} - -//! Queries the table with a custom "where" clause std::vector CDBehaviorTemplateTable::Query(std::function predicate) { std::vector data = cpplinq::from(this->entries) @@ -58,7 +48,6 @@ std::vector CDBehaviorTemplateTable::Query(std::function CDBehaviorTemplateTable::GetEntries(void) const { return this->entries; } diff --git a/dDatabase/Tables/CDBehaviorTemplateTable.h b/dDatabase/Tables/CDBehaviorTemplateTable.h index b2bd2521..f9ac9a09 100644 --- a/dDatabase/Tables/CDBehaviorTemplateTable.h +++ b/dDatabase/Tables/CDBehaviorTemplateTable.h @@ -5,12 +5,6 @@ #include #include -/*! - \file CDBehaviorTemplateTable.hpp - \brief Contains data for the BehaviorTemplate table - */ - - //! BehaviorTemplate Entry Struct struct CDBehaviorTemplate { unsigned int behaviorID; //!< The Behavior ID unsigned int templateID; //!< The Template ID (LOT) @@ -19,36 +13,16 @@ struct CDBehaviorTemplate { }; -//! BehaviorTemplate table -class CDBehaviorTemplateTable : public CDTable { +class CDBehaviorTemplateTable : public CDTable { private: std::vector entries; std::unordered_map entriesMappedByBehaviorID; std::unordered_set m_EffectHandles; public: - - //! Constructor - CDBehaviorTemplateTable(void); - - //! Destructor - ~CDBehaviorTemplateTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDBehaviorTemplateTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ std::vector GetEntries(void) const; const CDBehaviorTemplate GetByBehaviorID(uint32_t behaviorID); diff --git a/dDatabase/Tables/CDBrickIDTableTable.cpp b/dDatabase/Tables/CDBrickIDTableTable.cpp index 7cd3e86f..9ad24d39 100644 --- a/dDatabase/Tables/CDBrickIDTableTable.cpp +++ b/dDatabase/Tables/CDBrickIDTableTable.cpp @@ -1,6 +1,5 @@ #include "CDBrickIDTableTable.h" -//! Constructor CDBrickIDTableTable::CDBrickIDTableTable(void) { // First, get the size of the table @@ -31,15 +30,6 @@ CDBrickIDTableTable::CDBrickIDTableTable(void) { tableData.finalize(); } -//! Destructor -CDBrickIDTableTable::~CDBrickIDTableTable(void) {} - -//! Returns the table's name -std::string CDBrickIDTableTable::GetName(void) const { - return "BrickIDTable"; -} - -//! Queries the table with a custom "where" clause std::vector CDBrickIDTableTable::Query(std::function predicate) { std::vector data = cpplinq::from(this->entries) @@ -49,7 +39,6 @@ std::vector CDBrickIDTableTable::Query(std::function CDBrickIDTableTable::GetEntries(void) const { return this->entries; } diff --git a/dDatabase/Tables/CDBrickIDTableTable.h b/dDatabase/Tables/CDBrickIDTableTable.h index aefe332c..e2084caf 100644 --- a/dDatabase/Tables/CDBrickIDTableTable.h +++ b/dDatabase/Tables/CDBrickIDTableTable.h @@ -16,34 +16,14 @@ struct CDBrickIDTable { //! BrickIDTable table -class CDBrickIDTableTable : public CDTable { +class CDBrickIDTableTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDBrickIDTableTable(void); - - //! Destructor - ~CDBrickIDTableTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDBrickIDTableTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ std::vector GetEntries(void) const; - }; diff --git a/dDatabase/Tables/CDComponentsRegistryTable.cpp b/dDatabase/Tables/CDComponentsRegistryTable.cpp index 987c66ab..32012f6c 100644 --- a/dDatabase/Tables/CDComponentsRegistryTable.cpp +++ b/dDatabase/Tables/CDComponentsRegistryTable.cpp @@ -1,8 +1,8 @@ #include "CDComponentsRegistryTable.h" +#include "eReplicaComponentType.h" #define CDCLIENT_CACHE_ALL -//! Constructor CDComponentsRegistryTable::CDComponentsRegistryTable(void) { #ifdef CDCLIENT_CACHE_ALL @@ -25,29 +25,11 @@ CDComponentsRegistryTable::CDComponentsRegistryTable(void) { while (!tableData.eof()) { CDComponentsRegistry entry; entry.id = tableData.getIntField("id", -1); - entry.component_type = tableData.getIntField("component_type", -1); + entry.component_type = static_cast(tableData.getIntField("component_type", 0)); entry.component_id = tableData.getIntField("component_id", -1); this->mappedEntries.insert_or_assign(((uint64_t)entry.component_type) << 32 | ((uint64_t)entry.id), entry.component_id); - //this->entries.push_back(entry); - - /* - //Darwin's stuff: - const auto& it = this->mappedEntries.find(entry.id); - if (it != mappedEntries.end()) { - const auto& iter = it->second.find(entry.component_type); - if (iter == it->second.end()) { - it->second.insert(std::make_pair(entry.component_type, entry.component_id)); - } - } - else { - std::map map; - map.insert(std::make_pair(entry.component_type, entry.component_id)); - this->mappedEntries.insert(std::make_pair(entry.id, map)); - } - */ - tableData.nextRow(); } @@ -55,15 +37,7 @@ CDComponentsRegistryTable::CDComponentsRegistryTable(void) { #endif } -//! Destructor -CDComponentsRegistryTable::~CDComponentsRegistryTable(void) {} - -//! Returns the table's name -std::string CDComponentsRegistryTable::GetName(void) const { - return "ComponentsRegistry"; -} - -int32_t CDComponentsRegistryTable::GetByIDAndType(uint32_t id, uint32_t componentType, int32_t defaultValue) { +int32_t CDComponentsRegistryTable::GetByIDAndType(uint32_t id, eReplicaComponentType componentType, int32_t defaultValue) { const auto& iter = this->mappedEntries.find(((uint64_t)componentType) << 32 | ((uint64_t)id)); if (iter == this->mappedEntries.end()) { @@ -72,16 +46,6 @@ int32_t CDComponentsRegistryTable::GetByIDAndType(uint32_t id, uint32_t componen return iter->second; - /* - const auto& it = this->mappedEntries.find(id); - if (it != mappedEntries.end()) { - const auto& iter = it->second.find(componentType); - if (iter != it->second.end()) { - return iter->second; - } - } - */ - #ifndef CDCLIENT_CACHE_ALL // Now get the data std::stringstream query; diff --git a/dDatabase/Tables/CDComponentsRegistryTable.h b/dDatabase/Tables/CDComponentsRegistryTable.h index c3eb0ed2..990072c9 100644 --- a/dDatabase/Tables/CDComponentsRegistryTable.h +++ b/dDatabase/Tables/CDComponentsRegistryTable.h @@ -3,38 +3,19 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDComponentsRegistryTable.hpp - \brief Contains data for the ComponentsRegistry table - */ - - //! ComponentsRegistry Entry Struct +enum class eReplicaComponentType : uint32_t; struct CDComponentsRegistry { unsigned int id; //!< The LOT is used as the ID - unsigned int component_type; //!< See ComponentTypes enum for values + eReplicaComponentType component_type; //!< See ComponentTypes enum for values unsigned int component_id; //!< The ID used within the component's table (0 may either mean it's non-networked, or that the ID is actually 0 }; -//! ComponentsRegistry table -class CDComponentsRegistryTable : public CDTable { +class CDComponentsRegistryTable : public CDTable { private: - //std::vector entries; std::map mappedEntries; //id, component_type, component_id public: - - //! Constructor - CDComponentsRegistryTable(void); - - //! Destructor - ~CDComponentsRegistryTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - int32_t GetByIDAndType(uint32_t id, uint32_t componentType, int32_t defaultValue = 0); + CDComponentsRegistryTable(); + int32_t GetByIDAndType(uint32_t id, eReplicaComponentType componentType, int32_t defaultValue = 0); }; diff --git a/dDatabase/Tables/CDCurrencyTableTable.cpp b/dDatabase/Tables/CDCurrencyTableTable.cpp index 21870f00..78a716f9 100644 --- a/dDatabase/Tables/CDCurrencyTableTable.cpp +++ b/dDatabase/Tables/CDCurrencyTableTable.cpp @@ -34,15 +34,6 @@ CDCurrencyTableTable::CDCurrencyTableTable(void) { tableData.finalize(); } -//! Destructor -CDCurrencyTableTable::~CDCurrencyTableTable(void) {} - -//! Returns the table's name -std::string CDCurrencyTableTable::GetName(void) const { - return "CurrencyTable"; -} - -//! Queries the table with a custom "where" clause std::vector CDCurrencyTableTable::Query(std::function predicate) { std::vector data = cpplinq::from(this->entries) @@ -52,7 +43,6 @@ std::vector CDCurrencyTableTable::Query(std::function CDCurrencyTableTable::GetEntries(void) const { return this->entries; } diff --git a/dDatabase/Tables/CDCurrencyTableTable.h b/dDatabase/Tables/CDCurrencyTableTable.h index 5a856395..ec700320 100644 --- a/dDatabase/Tables/CDCurrencyTableTable.h +++ b/dDatabase/Tables/CDCurrencyTableTable.h @@ -18,34 +18,14 @@ struct CDCurrencyTable { }; //! CurrencyTable table -class CDCurrencyTableTable : public CDTable { +class CDCurrencyTableTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDCurrencyTableTable(void); - - //! Destructor - ~CDCurrencyTableTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDCurrencyTableTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ std::vector GetEntries(void) const; - }; diff --git a/dDatabase/Tables/CDDestructibleComponentTable.cpp b/dDatabase/Tables/CDDestructibleComponentTable.cpp index 2480fc24..4bbc8242 100644 --- a/dDatabase/Tables/CDDestructibleComponentTable.cpp +++ b/dDatabase/Tables/CDDestructibleComponentTable.cpp @@ -43,15 +43,6 @@ CDDestructibleComponentTable::CDDestructibleComponentTable(void) { tableData.finalize(); } -//! Destructor -CDDestructibleComponentTable::~CDDestructibleComponentTable(void) {} - -//! Returns the table's name -std::string CDDestructibleComponentTable::GetName(void) const { - return "DestructibleComponent"; -} - -//! Queries the table with a custom "where" clause std::vector CDDestructibleComponentTable::Query(std::function predicate) { std::vector data = cpplinq::from(this->entries) @@ -61,7 +52,6 @@ std::vector CDDestructibleComponentTable::Query(std::fu return data; } -//! Gets all the entries in the table std::vector CDDestructibleComponentTable::GetEntries(void) const { return this->entries; } diff --git a/dDatabase/Tables/CDDestructibleComponentTable.h b/dDatabase/Tables/CDDestructibleComponentTable.h index e89bbff8..e42cf486 100644 --- a/dDatabase/Tables/CDDestructibleComponentTable.h +++ b/dDatabase/Tables/CDDestructibleComponentTable.h @@ -3,12 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDDestructibleComponentTable.hpp - \brief Contains data for the DestructibleComponent table - */ - - //! ItemComponent Struct struct CDDestructibleComponent { unsigned int id; //!< The component ID from the ComponentsRegistry Table int faction; //!< The Faction ID of the object @@ -26,35 +20,14 @@ struct CDDestructibleComponent { int difficultyLevel; //!< ??? }; -//! ItemComponent table -class CDDestructibleComponentTable : public CDTable { +class CDDestructibleComponentTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDDestructibleComponentTable(void); - - //! Destructor - ~CDDestructibleComponentTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDDestructibleComponentTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ std::vector GetEntries(void) const; - }; diff --git a/dDatabase/Tables/CDEmoteTable.cpp b/dDatabase/Tables/CDEmoteTable.cpp index b97e02e8..aacbdd55 100644 --- a/dDatabase/Tables/CDEmoteTable.cpp +++ b/dDatabase/Tables/CDEmoteTable.cpp @@ -30,11 +30,6 @@ CDEmoteTableTable::~CDEmoteTableTable(void) { entries.clear(); } -//! Returns the table's name -std::string CDEmoteTableTable::GetName(void) const { - return "Emotes"; -} - CDEmoteTable* CDEmoteTableTable::GetEmote(int id) { for (auto e : entries) { if (e.first == id) return e.second; diff --git a/dDatabase/Tables/CDEmoteTable.h b/dDatabase/Tables/CDEmoteTable.h index 1f4fb246..be40c86f 100644 --- a/dDatabase/Tables/CDEmoteTable.h +++ b/dDatabase/Tables/CDEmoteTable.h @@ -4,12 +4,6 @@ #include "CDTable.h" #include -/*! - \file CDEmoteTable.hpp - \brief Contains data for the CDEmoteTable table - */ - - //! CDEmoteEntry Struct struct CDEmoteTable { CDEmoteTable() { ID = -1; @@ -32,25 +26,13 @@ struct CDEmoteTable { std::string gateVersion; }; -//! CDEmoteTable table -class CDEmoteTableTable : public CDTable { +class CDEmoteTableTable : public CDTable { private: std::map entries; public: - - //! Constructor - CDEmoteTableTable(void); - - //! Destructor - ~CDEmoteTableTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Returns an emote by ID + CDEmoteTableTable(); + ~CDEmoteTableTable(); + // Returns an emote by ID CDEmoteTable* GetEmote(int id); }; diff --git a/dDatabase/Tables/CDFeatureGatingTable.cpp b/dDatabase/Tables/CDFeatureGatingTable.cpp index 0abcdb25..05fe69bf 100644 --- a/dDatabase/Tables/CDFeatureGatingTable.cpp +++ b/dDatabase/Tables/CDFeatureGatingTable.cpp @@ -34,15 +34,6 @@ CDFeatureGatingTable::CDFeatureGatingTable(void) { tableData.finalize(); } -//! Destructor -CDFeatureGatingTable::~CDFeatureGatingTable(void) {} - -//! Returns the table's name -std::string CDFeatureGatingTable::GetName(void) const { - return "FeatureGating"; -} - -//! Queries the table with a custom "where" clause std::vector CDFeatureGatingTable::Query(std::function predicate) { std::vector data = cpplinq::from(this->entries) @@ -62,7 +53,6 @@ bool CDFeatureGatingTable::FeatureUnlocked(const std::string& feature) const { return false; } -//! Gets all the entries in the table std::vector CDFeatureGatingTable::GetEntries(void) const { return this->entries; } diff --git a/dDatabase/Tables/CDFeatureGatingTable.h b/dDatabase/Tables/CDFeatureGatingTable.h index 54e6d21b..7f536db5 100644 --- a/dDatabase/Tables/CDFeatureGatingTable.h +++ b/dDatabase/Tables/CDFeatureGatingTable.h @@ -3,11 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDFeatureGatingTable.hpp - */ - - //! ItemComponent Struct struct CDFeatureGating { std::string featureName; int32_t major; @@ -16,37 +11,16 @@ struct CDFeatureGating { std::string description; }; -//! ItemComponent table -class CDFeatureGatingTable : public CDTable { +class CDFeatureGatingTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDFeatureGatingTable(void); - - //! Destructor - ~CDFeatureGatingTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDFeatureGatingTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); bool FeatureUnlocked(const std::string& feature) const; - //! Gets all the entries in the table - /*! - \return The entries - */ std::vector GetEntries(void) const; - }; diff --git a/dDatabase/Tables/CDInventoryComponentTable.cpp b/dDatabase/Tables/CDInventoryComponentTable.cpp index cf956775..2dc375ab 100644 --- a/dDatabase/Tables/CDInventoryComponentTable.cpp +++ b/dDatabase/Tables/CDInventoryComponentTable.cpp @@ -33,15 +33,6 @@ CDInventoryComponentTable::CDInventoryComponentTable(void) { tableData.finalize(); } -//! Destructor -CDInventoryComponentTable::~CDInventoryComponentTable(void) {} - -//! Returns the table's name -std::string CDInventoryComponentTable::GetName(void) const { - return "InventoryComponent"; -} - -//! Queries the table with a custom "where" clause std::vector CDInventoryComponentTable::Query(std::function predicate) { std::vector data = cpplinq::from(this->entries) @@ -51,7 +42,6 @@ std::vector CDInventoryComponentTable::Query(std::function return data; } -//! Gets all the entries in the table std::vector CDInventoryComponentTable::GetEntries(void) const { return this->entries; } diff --git a/dDatabase/Tables/CDInventoryComponentTable.h b/dDatabase/Tables/CDInventoryComponentTable.h index c6117907..cbc04d99 100644 --- a/dDatabase/Tables/CDInventoryComponentTable.h +++ b/dDatabase/Tables/CDInventoryComponentTable.h @@ -3,12 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDInventoryComponentTable.hpp - \brief Contains data for the InventoryComponent table - */ - - //! ItemComponent Struct struct CDInventoryComponent { unsigned int id; //!< The component ID for this object unsigned int itemid; //!< The LOT of the object @@ -16,35 +10,14 @@ struct CDInventoryComponent { bool equip; //!< Whether or not to equip the item }; -//! ItemComponent table -class CDInventoryComponentTable : public CDTable { +class CDInventoryComponentTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDInventoryComponentTable(void); - - //! Destructor - ~CDInventoryComponentTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDInventoryComponentTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ std::vector GetEntries(void) const; - }; diff --git a/dDatabase/Tables/CDItemComponentTable.cpp b/dDatabase/Tables/CDItemComponentTable.cpp index a3cb4159..54afc417 100644 --- a/dDatabase/Tables/CDItemComponentTable.cpp +++ b/dDatabase/Tables/CDItemComponentTable.cpp @@ -74,14 +74,6 @@ CDItemComponentTable::CDItemComponentTable(void) { #endif } -//! Destructor -CDItemComponentTable::~CDItemComponentTable(void) {} - -//! Returns the table's name -std::string CDItemComponentTable::GetName(void) const { - return "ItemComponent"; -} - const CDItemComponent& CDItemComponentTable::GetItemComponentByID(unsigned int skillID) { const auto& it = this->entries.find(skillID); if (it != this->entries.end()) { diff --git a/dDatabase/Tables/CDItemComponentTable.h b/dDatabase/Tables/CDItemComponentTable.h index b3a2a5f4..11c34dd6 100644 --- a/dDatabase/Tables/CDItemComponentTable.h +++ b/dDatabase/Tables/CDItemComponentTable.h @@ -4,12 +4,6 @@ #include "CDTable.h" #include "dCommonVars.h" -/*! - \file CDItemComponentTable.hpp - \brief Contains data for the ItemComponent table - */ - - //! ItemComponent Struct struct CDItemComponent { unsigned int id; //!< The Component ID std::string equipLocation; //!< The equip location @@ -55,28 +49,15 @@ struct CDItemComponent { float SellMultiplier; //!< Something to do with early vendors perhaps (but replaced) }; -//! ItemComponent table -class CDItemComponentTable : public CDTable { +class CDItemComponentTable : public CDTable { private: std::map entries; public: - - //! Constructor - CDItemComponentTable(void); - - //! Destructor - ~CDItemComponentTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - + CDItemComponentTable(); static std::map ParseCraftingCurrencies(const CDItemComponent& itemComponent); - //! Gets an entry by ID + // Gets an entry by ID const CDItemComponent& GetItemComponentByID(unsigned int skillID); static CDItemComponent Default; diff --git a/dDatabase/Tables/CDItemSetSkillsTable.cpp b/dDatabase/Tables/CDItemSetSkillsTable.cpp index 107e25d9..f6b412ff 100644 --- a/dDatabase/Tables/CDItemSetSkillsTable.cpp +++ b/dDatabase/Tables/CDItemSetSkillsTable.cpp @@ -32,15 +32,6 @@ CDItemSetSkillsTable::CDItemSetSkillsTable(void) { tableData.finalize(); } -//! Destructor -CDItemSetSkillsTable::~CDItemSetSkillsTable(void) {} - -//! Returns the table's name -std::string CDItemSetSkillsTable::GetName(void) const { - return "ItemSetSkills"; -} - -//! Queries the table with a custom "where" clause std::vector CDItemSetSkillsTable::Query(std::function predicate) { std::vector data = cpplinq::from(this->entries) @@ -50,7 +41,6 @@ std::vector CDItemSetSkillsTable::Query(std::function CDItemSetSkillsTable::GetEntries(void) const { return this->entries; } @@ -65,4 +55,3 @@ std::vector CDItemSetSkillsTable::GetBySkillID(unsigned int Ski return toReturn; } - diff --git a/dDatabase/Tables/CDItemSetSkillsTable.h b/dDatabase/Tables/CDItemSetSkillsTable.h index bf05eea9..8328c66b 100644 --- a/dDatabase/Tables/CDItemSetSkillsTable.h +++ b/dDatabase/Tables/CDItemSetSkillsTable.h @@ -3,50 +3,22 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDItemSetSkillsTable.hpp - \brief Contains data for the ItemSetSkills table - */ - - //! ZoneTable Struct struct CDItemSetSkills { unsigned int SkillSetID; //!< The skill set ID unsigned int SkillID; //!< The skill ID unsigned int SkillCastType; //!< The skill cast type }; -//! ItemSets table -class CDItemSetSkillsTable : public CDTable { +class CDItemSetSkillsTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDItemSetSkillsTable(void); - - //! Destructor - ~CDItemSetSkillsTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDItemSetSkillsTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ std::vector GetEntries(void) const; std::vector GetBySkillID(unsigned int SkillSetID); - }; - diff --git a/dDatabase/Tables/CDItemSetsTable.cpp b/dDatabase/Tables/CDItemSetsTable.cpp index 1f9d7409..0632ef13 100644 --- a/dDatabase/Tables/CDItemSetsTable.cpp +++ b/dDatabase/Tables/CDItemSetsTable.cpp @@ -44,15 +44,6 @@ CDItemSetsTable::CDItemSetsTable(void) { tableData.finalize(); } -//! Destructor -CDItemSetsTable::~CDItemSetsTable(void) {} - -//! Returns the table's name -std::string CDItemSetsTable::GetName(void) const { - return "ItemSets"; -} - -//! Queries the table with a custom "where" clause std::vector CDItemSetsTable::Query(std::function predicate) { std::vector data = cpplinq::from(this->entries) @@ -62,7 +53,6 @@ std::vector CDItemSetsTable::Query(std::function p return data; } -//! Gets all the entries in the table std::vector CDItemSetsTable::GetEntries(void) const { return this->entries; } diff --git a/dDatabase/Tables/CDItemSetsTable.h b/dDatabase/Tables/CDItemSetsTable.h index ef12c7b4..6756e7fa 100644 --- a/dDatabase/Tables/CDItemSetsTable.h +++ b/dDatabase/Tables/CDItemSetsTable.h @@ -3,12 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDItemSetsTable.hpp - \brief Contains data for the ItemSets table - */ - - //! ZoneTable Struct struct CDItemSets { unsigned int setID; //!< The item set ID unsigned int locStatus; //!< The loc status @@ -27,36 +21,15 @@ struct CDItemSets { float priority; //!< The priority }; -//! ItemSets table -class CDItemSetsTable : public CDTable { +class CDItemSetsTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDItemSetsTable(void); - - //! Destructor - ~CDItemSetsTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDItemSetsTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ std::vector GetEntries(void) const; - }; diff --git a/dDatabase/Tables/CDLevelProgressionLookupTable.cpp b/dDatabase/Tables/CDLevelProgressionLookupTable.cpp index b3231308..47a8fc0e 100644 --- a/dDatabase/Tables/CDLevelProgressionLookupTable.cpp +++ b/dDatabase/Tables/CDLevelProgressionLookupTable.cpp @@ -32,14 +32,6 @@ CDLevelProgressionLookupTable::CDLevelProgressionLookupTable(void) { tableData.finalize(); } -//! Destructor -CDLevelProgressionLookupTable::~CDLevelProgressionLookupTable(void) {} - -//! Returns the table's name -std::string CDLevelProgressionLookupTable::GetName(void) const { - return "LevelProgressionLookup"; -} - //! Queries the table with a custom "where" clause std::vector CDLevelProgressionLookupTable::Query(std::function predicate) { diff --git a/dDatabase/Tables/CDLevelProgressionLookupTable.h b/dDatabase/Tables/CDLevelProgressionLookupTable.h index 391c9b37..070b2e0c 100644 --- a/dDatabase/Tables/CDLevelProgressionLookupTable.h +++ b/dDatabase/Tables/CDLevelProgressionLookupTable.h @@ -3,47 +3,21 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDLevelProgressionLookupTable.hpp - \brief Contains data for the LevelProgressionLookup table - */ - - //! LevelProgressionLookup Entry Struct struct CDLevelProgressionLookup { unsigned int id; //!< The Level ID unsigned int requiredUScore; //!< The required LEGO Score std::string BehaviorEffect; //!< The behavior effect attached to this }; -//! LevelProgressionLookup table -class CDLevelProgressionLookupTable : public CDTable { +class CDLevelProgressionLookupTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDLevelProgressionLookupTable(void); - - //! Destructor - ~CDLevelProgressionLookupTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDLevelProgressionLookupTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ + // Gets all the entries in the table std::vector GetEntries(void) const; - }; diff --git a/dDatabase/Tables/CDLootMatrixTable.cpp b/dDatabase/Tables/CDLootMatrixTable.cpp index 93a2fda1..8f25e8a3 100644 --- a/dDatabase/Tables/CDLootMatrixTable.cpp +++ b/dDatabase/Tables/CDLootMatrixTable.cpp @@ -38,15 +38,6 @@ CDLootMatrixTable::CDLootMatrixTable(void) { tableData.finalize(); } -//! Destructor -CDLootMatrixTable::~CDLootMatrixTable(void) {} - -//! Returns the table's name -std::string CDLootMatrixTable::GetName(void) const { - return "LootMatrix"; -} - -//! Queries the table with a custom "where" clause std::vector CDLootMatrixTable::Query(std::function predicate) { std::vector data = cpplinq::from(this->entries) @@ -56,7 +47,6 @@ std::vector CDLootMatrixTable::Query(std::function& CDLootMatrixTable::GetEntries(void) const { return this->entries; } diff --git a/dDatabase/Tables/CDLootMatrixTable.h b/dDatabase/Tables/CDLootMatrixTable.h index 7d311b3b..c6035841 100644 --- a/dDatabase/Tables/CDLootMatrixTable.h +++ b/dDatabase/Tables/CDLootMatrixTable.h @@ -3,12 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDLootMatrixTable.hpp - \brief Contains data for the ObjectSkills table - */ - - //! LootMatrix Struct struct CDLootMatrix { unsigned int LootMatrixIndex; //!< The Loot Matrix Index unsigned int LootTableIndex; //!< The Loot Table Index @@ -21,36 +15,15 @@ struct CDLootMatrix { UNUSED(std::string gate_version); //!< The Gate Version }; -//! MissionNPCComponent table -class CDLootMatrixTable : public CDTable { +class CDLootMatrixTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDLootMatrixTable(void); - - //! Destructor - ~CDLootMatrixTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDLootMatrixTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ const std::vector& GetEntries(void) const; - }; diff --git a/dDatabase/Tables/CDLootTableTable.cpp b/dDatabase/Tables/CDLootTableTable.cpp index 91cced47..0a46784a 100644 --- a/dDatabase/Tables/CDLootTableTable.cpp +++ b/dDatabase/Tables/CDLootTableTable.cpp @@ -35,14 +35,6 @@ CDLootTableTable::CDLootTableTable(void) { tableData.finalize(); } -//! Destructor -CDLootTableTable::~CDLootTableTable(void) {} - -//! Returns the table's name -std::string CDLootTableTable::GetName(void) const { - return "LootTable"; -} - //! Queries the table with a custom "where" clause std::vector CDLootTableTable::Query(std::function predicate) { diff --git a/dDatabase/Tables/CDLootTableTable.h b/dDatabase/Tables/CDLootTableTable.h index 3f1baf60..ba6f207e 100644 --- a/dDatabase/Tables/CDLootTableTable.h +++ b/dDatabase/Tables/CDLootTableTable.h @@ -3,12 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDLootTableTable.hpp - \brief Contains data for the LootTable table - */ - - //! LootTable Struct struct CDLootTable { unsigned int itemid; //!< The LOT of the item unsigned int LootTableIndex; //!< The Loot Table Index @@ -17,36 +11,15 @@ struct CDLootTable { unsigned int sortPriority; //!< The sorting priority }; -//! LootTable table -class CDLootTableTable : public CDTable { +class CDLootTableTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDLootTableTable(void); - - //! Destructor - ~CDLootTableTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDLootTableTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ const std::vector& GetEntries(void) const; - }; diff --git a/dDatabase/Tables/CDMissionEmailTable.cpp b/dDatabase/Tables/CDMissionEmailTable.cpp index 4fac7be2..ed855d8a 100644 --- a/dDatabase/Tables/CDMissionEmailTable.cpp +++ b/dDatabase/Tables/CDMissionEmailTable.cpp @@ -37,14 +37,6 @@ CDMissionEmailTable::CDMissionEmailTable(void) { tableData.finalize(); } -//! Destructor -CDMissionEmailTable::~CDMissionEmailTable(void) {} - -//! Returns the table's name -std::string CDMissionEmailTable::GetName(void) const { - return "MissionEmail"; -} - //! Queries the table with a custom "where" clause std::vector CDMissionEmailTable::Query(std::function predicate) { diff --git a/dDatabase/Tables/CDMissionEmailTable.h b/dDatabase/Tables/CDMissionEmailTable.h index 81a7a793..db2310d4 100644 --- a/dDatabase/Tables/CDMissionEmailTable.h +++ b/dDatabase/Tables/CDMissionEmailTable.h @@ -3,12 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDMissionEmailTable.hpp - \brief Contains data for the MissionEmail table - */ - - //! MissionEmail Entry Struct struct CDMissionEmail { unsigned int ID; unsigned int messageType; @@ -21,35 +15,14 @@ struct CDMissionEmail { }; -//! MissionEmail table -class CDMissionEmailTable : public CDTable { +class CDMissionEmailTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDMissionEmailTable(void); - - //! Destructor - ~CDMissionEmailTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDMissionEmailTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ std::vector GetEntries(void) const; - }; diff --git a/dDatabase/Tables/CDMissionNPCComponentTable.cpp b/dDatabase/Tables/CDMissionNPCComponentTable.cpp index 461cc909..5672ed67 100644 --- a/dDatabase/Tables/CDMissionNPCComponentTable.cpp +++ b/dDatabase/Tables/CDMissionNPCComponentTable.cpp @@ -34,14 +34,6 @@ CDMissionNPCComponentTable::CDMissionNPCComponentTable(void) { tableData.finalize(); } -//! Destructor -CDMissionNPCComponentTable::~CDMissionNPCComponentTable(void) {} - -//! Returns the table's name -std::string CDMissionNPCComponentTable::GetName(void) const { - return "MissionNPCComponent"; -} - //! Queries the table with a custom "where" clause std::vector CDMissionNPCComponentTable::Query(std::function predicate) { diff --git a/dDatabase/Tables/CDMissionNPCComponentTable.h b/dDatabase/Tables/CDMissionNPCComponentTable.h index 68c94ef0..a7aeb145 100644 --- a/dDatabase/Tables/CDMissionNPCComponentTable.h +++ b/dDatabase/Tables/CDMissionNPCComponentTable.h @@ -3,12 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDMissionNPCComponentTable.hpp - \brief Contains data for the ObjectSkills table - */ - - //! MissionNPCComponent Struct struct CDMissionNPCComponent { unsigned int id; //!< The ID unsigned int missionID; //!< The Mission ID @@ -17,35 +11,16 @@ struct CDMissionNPCComponent { std::string gate_version; //!< The gate version }; -//! MissionNPCComponent table -class CDMissionNPCComponentTable : public CDTable { +class CDMissionNPCComponentTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDMissionNPCComponentTable(void); - - //! Destructor - ~CDMissionNPCComponentTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDMissionNPCComponentTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ + // Gets all the entries in the table std::vector GetEntries(void) const; }; diff --git a/dDatabase/Tables/CDMissionTasksTable.cpp b/dDatabase/Tables/CDMissionTasksTable.cpp index c22da1ef..f32dca1b 100644 --- a/dDatabase/Tables/CDMissionTasksTable.cpp +++ b/dDatabase/Tables/CDMissionTasksTable.cpp @@ -42,15 +42,6 @@ CDMissionTasksTable::CDMissionTasksTable(void) { tableData.finalize(); } -//! Destructor -CDMissionTasksTable::~CDMissionTasksTable(void) {} - -//! Returns the table's name -std::string CDMissionTasksTable::GetName(void) const { - return "MissionTasks"; -} - -//! Queries the table with a custom "where" clause std::vector CDMissionTasksTable::Query(std::function predicate) { std::vector data = cpplinq::from(this->entries) @@ -74,7 +65,6 @@ std::vector CDMissionTasksTable::GetByMissionID(uint32_t missio return tasks; } -//! Gets all the entries in the table const std::vector& CDMissionTasksTable::GetEntries(void) const { return this->entries; } diff --git a/dDatabase/Tables/CDMissionTasksTable.h b/dDatabase/Tables/CDMissionTasksTable.h index 1a4bd361..fa213faf 100644 --- a/dDatabase/Tables/CDMissionTasksTable.h +++ b/dDatabase/Tables/CDMissionTasksTable.h @@ -3,12 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDMissionTasksTable.hpp - \brief Contains data for the MissionTasks table - */ - - //! ObjectSkills Struct struct CDMissionTasks { unsigned int id; //!< The Mission ID that the task belongs to UNUSED(unsigned int locStatus); //!< ??? @@ -25,37 +19,17 @@ struct CDMissionTasks { UNUSED(std::string gate_version); //!< ??? }; -//! ObjectSkills table -class CDMissionTasksTable : public CDTable { +class CDMissionTasksTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDMissionTasksTable(void); - - //! Destructor - ~CDMissionTasksTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDMissionTasksTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); std::vector GetByMissionID(uint32_t missionID); - //! Gets all the entries in the table - /*! - \return The entries - */ const std::vector& GetEntries(void) const; }; diff --git a/dDatabase/Tables/CDMissionsTable.cpp b/dDatabase/Tables/CDMissionsTable.cpp index a87b4327..d4ee40ae 100644 --- a/dDatabase/Tables/CDMissionsTable.cpp +++ b/dDatabase/Tables/CDMissionsTable.cpp @@ -85,15 +85,6 @@ CDMissionsTable::CDMissionsTable(void) { Default.id = -1; } -//! Destructor -CDMissionsTable::~CDMissionsTable(void) {} - -//! Returns the table's name -std::string CDMissionsTable::GetName(void) const { - return "Missions"; -} - -//! Queries the table with a custom "where" clause std::vector CDMissionsTable::Query(std::function predicate) { std::vector data = cpplinq::from(this->entries) @@ -103,7 +94,6 @@ std::vector CDMissionsTable::Query(std::function p return data; } -//! Gets all the entries in the table const std::vector& CDMissionsTable::GetEntries(void) const { return this->entries; } diff --git a/dDatabase/Tables/CDMissionsTable.h b/dDatabase/Tables/CDMissionsTable.h index 6d1c4a8f..e6a44b02 100644 --- a/dDatabase/Tables/CDMissionsTable.h +++ b/dDatabase/Tables/CDMissionsTable.h @@ -5,12 +5,6 @@ #include #include -/*! - \file CDMissionsTable.hpp - \brief Contains data for the Missions table - */ - - //! Missions Struct struct CDMissions { int id; //!< The Mission ID std::string defined_type; //!< The type of mission @@ -66,35 +60,16 @@ struct CDMissions { int reward_bankinventory; //!< The amount of bank space this mission rewards }; -//! Missions table -class CDMissionsTable : public CDTable { +class CDMissionsTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDMissionsTable(void); - - //! Destructor - ~CDMissionsTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDMissionsTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ + // Gets all the entries in the table const std::vector& GetEntries(void) const; const CDMissions* GetPtrByMissionID(uint32_t missionID) const; diff --git a/dDatabase/Tables/CDMovementAIComponentTable.cpp b/dDatabase/Tables/CDMovementAIComponentTable.cpp index 333ec202..3b9cc4f4 100644 --- a/dDatabase/Tables/CDMovementAIComponentTable.cpp +++ b/dDatabase/Tables/CDMovementAIComponentTable.cpp @@ -37,14 +37,6 @@ CDMovementAIComponentTable::CDMovementAIComponentTable(void) { tableData.finalize(); } -//! Destructor -CDMovementAIComponentTable::~CDMovementAIComponentTable(void) {} - -//! Returns the table's name -std::string CDMovementAIComponentTable::GetName(void) const { - return "MovementAIComponent"; -} - //! Queries the table with a custom "where" clause std::vector CDMovementAIComponentTable::Query(std::function predicate) { diff --git a/dDatabase/Tables/CDMovementAIComponentTable.h b/dDatabase/Tables/CDMovementAIComponentTable.h index 0064a98b..84896e2c 100644 --- a/dDatabase/Tables/CDMovementAIComponentTable.h +++ b/dDatabase/Tables/CDMovementAIComponentTable.h @@ -3,12 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDMovementAIComponentTable.hpp - \brief Contains data for the MovementAIComponent table - */ - - //! MovementAIComponent Struct struct CDMovementAIComponent { unsigned int id; std::string MovementType; @@ -20,36 +14,15 @@ struct CDMovementAIComponent { std::string attachedPath; }; -//! MovementAIComponent table -class CDMovementAIComponentTable : public CDTable { +class CDMovementAIComponentTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDMovementAIComponentTable(void); - - //! Destructor - ~CDMovementAIComponentTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDMovementAIComponentTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ + // Gets all the entries in the table std::vector GetEntries(void) const; - }; - diff --git a/dDatabase/Tables/CDObjectSkillsTable.cpp b/dDatabase/Tables/CDObjectSkillsTable.cpp index dc797529..2e8b3fb2 100644 --- a/dDatabase/Tables/CDObjectSkillsTable.cpp +++ b/dDatabase/Tables/CDObjectSkillsTable.cpp @@ -33,14 +33,6 @@ CDObjectSkillsTable::CDObjectSkillsTable(void) { tableData.finalize(); } -//! Destructor -CDObjectSkillsTable::~CDObjectSkillsTable(void) {} - -//! Returns the table's name -std::string CDObjectSkillsTable::GetName(void) const { - return "ObjectSkills"; -} - //! Queries the table with a custom "where" clause std::vector CDObjectSkillsTable::Query(std::function predicate) { @@ -55,4 +47,3 @@ std::vector CDObjectSkillsTable::Query(std::function CDObjectSkillsTable::GetEntries(void) const { return this->entries; } - diff --git a/dDatabase/Tables/CDObjectSkillsTable.h b/dDatabase/Tables/CDObjectSkillsTable.h index c2caf71b..4ceaa447 100644 --- a/dDatabase/Tables/CDObjectSkillsTable.h +++ b/dDatabase/Tables/CDObjectSkillsTable.h @@ -3,12 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDObjectSkillsTable.hpp - \brief Contains data for the ObjectSkills table - */ - - //! ObjectSkills Struct struct CDObjectSkills { unsigned int objectTemplate; //!< The LOT of the item unsigned int skillID; //!< The Skill ID of the object @@ -16,35 +10,16 @@ struct CDObjectSkills { unsigned int AICombatWeight; //!< ??? }; -//! ObjectSkills table -class CDObjectSkillsTable : public CDTable { +class CDObjectSkillsTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDObjectSkillsTable(void); - - //! Destructor - ~CDObjectSkillsTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDObjectSkillsTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ + // Gets all the entries in the table std::vector GetEntries(void) const; }; diff --git a/dDatabase/Tables/CDObjectsTable.cpp b/dDatabase/Tables/CDObjectsTable.cpp index 5133becc..c68c3e6a 100644 --- a/dDatabase/Tables/CDObjectsTable.cpp +++ b/dDatabase/Tables/CDObjectsTable.cpp @@ -43,14 +43,6 @@ CDObjectsTable::CDObjectsTable(void) { m_default.id = 0; } -//! Destructor -CDObjectsTable::~CDObjectsTable(void) {} - -//! Returns the table's name -std::string CDObjectsTable::GetName(void) const { - return "Objects"; -} - const CDObjects& CDObjectsTable::GetByID(unsigned int LOT) { const auto& it = this->entries.find(LOT); if (it != this->entries.end()) { diff --git a/dDatabase/Tables/CDObjectsTable.h b/dDatabase/Tables/CDObjectsTable.h index 333477bd..171eddef 100644 --- a/dDatabase/Tables/CDObjectsTable.h +++ b/dDatabase/Tables/CDObjectsTable.h @@ -3,12 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDObjectsTable.hpp - \brief Contains data for the Objects table - */ - - //! RebuildComponent Struct struct CDObjects { unsigned int id; //!< The LOT of the object std::string name; //!< The internal name of the object @@ -26,29 +20,14 @@ struct CDObjects { UNUSED(unsigned int HQ_valid); //!< Probably used for the Nexus HQ database on LEGOUniverse.com }; -//! ObjectSkills table -class CDObjectsTable : public CDTable { +class CDObjectsTable : public CDTable { private: - //std::vector entries; std::map entries; CDObjects m_default; public: - - //! Constructor - CDObjectsTable(void); - - //! Destructor - ~CDObjectsTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Gets an entry by ID + CDObjectsTable(); + // Gets an entry by ID const CDObjects& GetByID(unsigned int LOT); - }; diff --git a/dDatabase/Tables/CDPackageComponentTable.cpp b/dDatabase/Tables/CDPackageComponentTable.cpp index eabe68da..efb85eeb 100644 --- a/dDatabase/Tables/CDPackageComponentTable.cpp +++ b/dDatabase/Tables/CDPackageComponentTable.cpp @@ -32,14 +32,6 @@ CDPackageComponentTable::CDPackageComponentTable(void) { tableData.finalize(); } -//! Destructor -CDPackageComponentTable::~CDPackageComponentTable(void) {} - -//! Returns the table's name -std::string CDPackageComponentTable::GetName(void) const { - return "PackageComponent"; -} - //! Queries the table with a custom "where" clause std::vector CDPackageComponentTable::Query(std::function predicate) { diff --git a/dDatabase/Tables/CDPackageComponentTable.h b/dDatabase/Tables/CDPackageComponentTable.h index 763acf8c..6c11ab39 100644 --- a/dDatabase/Tables/CDPackageComponentTable.h +++ b/dDatabase/Tables/CDPackageComponentTable.h @@ -3,48 +3,20 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDPackageComponentTable.hpp - \brief Contains data for the PackageComponent table - */ - - //! PackageComponent Entry Struct struct CDPackageComponent { unsigned int id; unsigned int LootMatrixIndex; unsigned int packageType; }; - -//! PackageComponent table -class CDPackageComponentTable : public CDTable { +class CDPackageComponentTable : public CDTable { private: std::vector entries; public: - - //! Constructor CDPackageComponentTable(void); - - //! Destructor - ~CDPackageComponentTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ std::vector GetEntries(void) const; - }; diff --git a/dDatabase/Tables/CDPhysicsComponentTable.cpp b/dDatabase/Tables/CDPhysicsComponentTable.cpp index f85d83c4..bb21ed7f 100644 --- a/dDatabase/Tables/CDPhysicsComponentTable.cpp +++ b/dDatabase/Tables/CDPhysicsComponentTable.cpp @@ -28,7 +28,7 @@ CDPhysicsComponentTable::CDPhysicsComponentTable(void) { tableData.finalize(); } -CDPhysicsComponentTable::~CDPhysicsComponentTable(void) { +CDPhysicsComponentTable::~CDPhysicsComponentTable() { for (auto e : m_entries) { if (e.second) delete e.second; } @@ -36,10 +36,6 @@ CDPhysicsComponentTable::~CDPhysicsComponentTable(void) { m_entries.clear(); } -std::string CDPhysicsComponentTable::GetName(void) const { - return "PhysicsComponent"; -} - CDPhysicsComponent* CDPhysicsComponentTable::GetByID(unsigned int componentID) { for (auto e : m_entries) { if (e.first == componentID) return e.second; diff --git a/dDatabase/Tables/CDPhysicsComponentTable.h b/dDatabase/Tables/CDPhysicsComponentTable.h index c5805da3..e63d337d 100644 --- a/dDatabase/Tables/CDPhysicsComponentTable.h +++ b/dDatabase/Tables/CDPhysicsComponentTable.h @@ -21,12 +21,12 @@ struct CDPhysicsComponent { UNUSED(std::string gravityVolumeAsset); }; -class CDPhysicsComponentTable : public CDTable { +class CDPhysicsComponentTable : public CDTable { public: - CDPhysicsComponentTable(void); - ~CDPhysicsComponentTable(void); + CDPhysicsComponentTable(); + ~CDPhysicsComponentTable(); - std::string GetName(void) const override; + static const std::string GetTableName() { return "PhysicsComponent"; }; CDPhysicsComponent* GetByID(unsigned int componentID); private: diff --git a/dDatabase/Tables/CDPropertyEntranceComponentTable.cpp b/dDatabase/Tables/CDPropertyEntranceComponentTable.cpp index 127ebc9d..1fead45e 100644 --- a/dDatabase/Tables/CDPropertyEntranceComponentTable.cpp +++ b/dDatabase/Tables/CDPropertyEntranceComponentTable.cpp @@ -32,12 +32,6 @@ CDPropertyEntranceComponentTable::CDPropertyEntranceComponentTable() { tableData.finalize(); } -CDPropertyEntranceComponentTable::~CDPropertyEntranceComponentTable(void) = default; - -std::string CDPropertyEntranceComponentTable::GetName() const { - return "PropertyEntranceComponent"; -} - CDPropertyEntranceComponent CDPropertyEntranceComponentTable::GetByID(uint32_t id) { for (const auto& entry : entries) { if (entry.id == id) diff --git a/dDatabase/Tables/CDPropertyEntranceComponentTable.h b/dDatabase/Tables/CDPropertyEntranceComponentTable.h index fa0603c0..925fd1be 100644 --- a/dDatabase/Tables/CDPropertyEntranceComponentTable.h +++ b/dDatabase/Tables/CDPropertyEntranceComponentTable.h @@ -9,31 +9,13 @@ struct CDPropertyEntranceComponent { std::string groupType; }; -class CDPropertyEntranceComponentTable : public CDTable { +class CDPropertyEntranceComponentTable : public CDTable { public: - //! Constructor CDPropertyEntranceComponentTable(); - - //! Destructor - ~CDPropertyEntranceComponentTable(); - - //! Returns the table's name - /*! - \return The table name - */ - [[nodiscard]] std::string GetName() const override; - - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + // Queries the table with a custom "where" clause CDPropertyEntranceComponent GetByID(uint32_t id); - //! Gets all the entries in the table - /*! - \return The entries - */ + // Gets all the entries in the table [[nodiscard]] std::vector GetEntries() const { return entries; } private: std::vector entries{}; diff --git a/dDatabase/Tables/CDPropertyTemplateTable.cpp b/dDatabase/Tables/CDPropertyTemplateTable.cpp index bf56da7b..4caa6dc5 100644 --- a/dDatabase/Tables/CDPropertyTemplateTable.cpp +++ b/dDatabase/Tables/CDPropertyTemplateTable.cpp @@ -30,12 +30,6 @@ CDPropertyTemplateTable::CDPropertyTemplateTable() { tableData.finalize(); } -CDPropertyTemplateTable::~CDPropertyTemplateTable() = default; - -std::string CDPropertyTemplateTable::GetName() const { - return "PropertyTemplate"; -} - CDPropertyTemplate CDPropertyTemplateTable::GetByMapID(uint32_t mapID) { for (const auto& entry : entries) { if (entry.mapID == mapID) diff --git a/dDatabase/Tables/CDPropertyTemplateTable.h b/dDatabase/Tables/CDPropertyTemplateTable.h index a266932b..cb075dbf 100644 --- a/dDatabase/Tables/CDPropertyTemplateTable.h +++ b/dDatabase/Tables/CDPropertyTemplateTable.h @@ -8,12 +8,11 @@ struct CDPropertyTemplate { std::string spawnName; }; -class CDPropertyTemplateTable : public CDTable { +class CDPropertyTemplateTable : public CDTable { public: CDPropertyTemplateTable(); - ~CDPropertyTemplateTable(); - [[nodiscard]] std::string GetName() const override; + static const std::string GetTableName() { return "PropertyTemplate"; }; CDPropertyTemplate GetByMapID(uint32_t mapID); private: std::vector entries{}; diff --git a/dDatabase/Tables/CDProximityMonitorComponentTable.cpp b/dDatabase/Tables/CDProximityMonitorComponentTable.cpp index 98cde098..688de056 100644 --- a/dDatabase/Tables/CDProximityMonitorComponentTable.cpp +++ b/dDatabase/Tables/CDProximityMonitorComponentTable.cpp @@ -33,14 +33,6 @@ CDProximityMonitorComponentTable::CDProximityMonitorComponentTable(void) { tableData.finalize(); } -//! Destructor -CDProximityMonitorComponentTable::~CDProximityMonitorComponentTable(void) {} - -//! Returns the table's name -std::string CDProximityMonitorComponentTable::GetName(void) const { - return "ProximityMonitorComponent"; -} - //! Queries the table with a custom "where" clause std::vector CDProximityMonitorComponentTable::Query(std::function predicate) { diff --git a/dDatabase/Tables/CDProximityMonitorComponentTable.h b/dDatabase/Tables/CDProximityMonitorComponentTable.h index 007bb916..38b7d43b 100644 --- a/dDatabase/Tables/CDProximityMonitorComponentTable.h +++ b/dDatabase/Tables/CDProximityMonitorComponentTable.h @@ -3,12 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDProximityMonitorComponentTable.hpp - \brief Contains data for the ProximityMonitorComponent table - */ - - //! ProximityMonitorComponent Entry Struct struct CDProximityMonitorComponent { unsigned int id; std::string Proximities; @@ -16,36 +10,14 @@ struct CDProximityMonitorComponent { bool LoadOnServer; }; - -//! ProximityMonitorComponent table -class CDProximityMonitorComponentTable : public CDTable { +class CDProximityMonitorComponentTable : public CDTable { private: std::vector entries; public: - - //! Constructor CDProximityMonitorComponentTable(void); - - //! Destructor - ~CDProximityMonitorComponentTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ std::vector GetEntries(void) const; - }; diff --git a/dDatabase/Tables/CDRailActivatorComponent.cpp b/dDatabase/Tables/CDRailActivatorComponent.cpp index 4d1b5e7e..2ff8990d 100644 --- a/dDatabase/Tables/CDRailActivatorComponent.cpp +++ b/dDatabase/Tables/CDRailActivatorComponent.cpp @@ -43,12 +43,6 @@ CDRailActivatorComponentTable::CDRailActivatorComponentTable() { tableData.finalize(); } -CDRailActivatorComponentTable::~CDRailActivatorComponentTable() = default; - -std::string CDRailActivatorComponentTable::GetName() const { - return "RailActivatorComponent"; -} - CDRailActivatorComponent CDRailActivatorComponentTable::GetEntryByID(int32_t id) const { for (const auto& entry : m_Entries) { if (entry.id == id) diff --git a/dDatabase/Tables/CDRailActivatorComponent.h b/dDatabase/Tables/CDRailActivatorComponent.h index b8313e96..03dd0525 100644 --- a/dDatabase/Tables/CDRailActivatorComponent.h +++ b/dDatabase/Tables/CDRailActivatorComponent.h @@ -20,12 +20,10 @@ struct CDRailActivatorComponent { bool showNameBillboard; }; -class CDRailActivatorComponentTable : public CDTable { +class CDRailActivatorComponentTable : public CDTable { public: CDRailActivatorComponentTable(); - ~CDRailActivatorComponentTable(); - - std::string GetName() const override; + static const std::string GetTableName() { return "RailActivatorComponent"; }; [[nodiscard]] CDRailActivatorComponent GetEntryByID(int32_t id) const; [[nodiscard]] std::vector GetEntries() const; private: diff --git a/dDatabase/Tables/CDRarityTableTable.cpp b/dDatabase/Tables/CDRarityTableTable.cpp index cfa8d01c..0b1212c0 100644 --- a/dDatabase/Tables/CDRarityTableTable.cpp +++ b/dDatabase/Tables/CDRarityTableTable.cpp @@ -33,14 +33,6 @@ CDRarityTableTable::CDRarityTableTable(void) { tableData.finalize(); } -//! Destructor -CDRarityTableTable::~CDRarityTableTable(void) {} - -//! Returns the table's name -std::string CDRarityTableTable::GetName(void) const { - return "RarityTable"; -} - //! Queries the table with a custom "where" clause std::vector CDRarityTableTable::Query(std::function predicate) { diff --git a/dDatabase/Tables/CDRarityTableTable.h b/dDatabase/Tables/CDRarityTableTable.h index 55cfec4b..592346ed 100644 --- a/dDatabase/Tables/CDRarityTableTable.h +++ b/dDatabase/Tables/CDRarityTableTable.h @@ -3,12 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDRarityTableTable.hpp - \brief Contains data for the RarityTable table - */ - - //! RarityTable Entry Struct struct CDRarityTable { unsigned int id; float randmax; @@ -32,37 +26,15 @@ struct CDRarityTable { } }; - -//! RarityTable table -class CDRarityTableTable : public CDTable { +class CDRarityTableTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDRarityTableTable(void); - - //! Destructor - ~CDRarityTableTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDRarityTableTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ - const std::vector& GetEntries(void) const; - + const std::vector& GetEntries() const; }; diff --git a/dDatabase/Tables/CDRebuildComponentTable.cpp b/dDatabase/Tables/CDRebuildComponentTable.cpp index 111592d4..d5c386d1 100644 --- a/dDatabase/Tables/CDRebuildComponentTable.cpp +++ b/dDatabase/Tables/CDRebuildComponentTable.cpp @@ -39,14 +39,6 @@ CDRebuildComponentTable::CDRebuildComponentTable(void) { tableData.finalize(); } -//! Destructor -CDRebuildComponentTable::~CDRebuildComponentTable(void) {} - -//! Returns the table's name -std::string CDRebuildComponentTable::GetName(void) const { - return "RebuildComponent"; -} - //! Queries the table with a custom "where" clause std::vector CDRebuildComponentTable::Query(std::function predicate) { diff --git a/dDatabase/Tables/CDRebuildComponentTable.h b/dDatabase/Tables/CDRebuildComponentTable.h index bdc2da8a..db70a47d 100644 --- a/dDatabase/Tables/CDRebuildComponentTable.h +++ b/dDatabase/Tables/CDRebuildComponentTable.h @@ -3,12 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDRebuildComponentTable.hpp - \brief Contains data for the RebuildComponent table - */ - - //! RebuildComponent Struct struct CDRebuildComponent { unsigned int id; //!< The component Id float reset_time; //!< The reset time @@ -22,36 +16,15 @@ struct CDRebuildComponent { float time_before_smash; //!< The time before smash }; -//! ObjectSkills table -class CDRebuildComponentTable : public CDTable { +class CDRebuildComponentTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDRebuildComponentTable(void); - - //! Destructor - ~CDRebuildComponentTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDRebuildComponentTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ - std::vector GetEntries(void) const; - + std::vector GetEntries() const; }; diff --git a/dDatabase/Tables/CDRewardsTable.cpp b/dDatabase/Tables/CDRewardsTable.cpp index a53e02b5..55672add 100644 --- a/dDatabase/Tables/CDRewardsTable.cpp +++ b/dDatabase/Tables/CDRewardsTable.cpp @@ -26,10 +26,6 @@ CDRewardsTable::~CDRewardsTable(void) { m_entries.clear(); } -std::string CDRewardsTable::GetName(void) const { - return "Rewards"; -} - std::vector CDRewardsTable::GetByLevelID(uint32_t levelID) { std::vector result{}; for (const auto& e : m_entries) { diff --git a/dDatabase/Tables/CDRewardsTable.h b/dDatabase/Tables/CDRewardsTable.h index 2edfd2b3..2e079a83 100644 --- a/dDatabase/Tables/CDRewardsTable.h +++ b/dDatabase/Tables/CDRewardsTable.h @@ -11,12 +11,12 @@ struct CDRewards { int32_t count; }; -class CDRewardsTable : public CDTable { +class CDRewardsTable : public CDTable { public: - CDRewardsTable(void); - ~CDRewardsTable(void); + CDRewardsTable(); + ~CDRewardsTable(); - std::string GetName(void) const override; + static const std::string GetTableName() { return "Rewards"; }; std::vector GetByLevelID(uint32_t levelID); private: diff --git a/dDatabase/Tables/CDScriptComponentTable.cpp b/dDatabase/Tables/CDScriptComponentTable.cpp index d91dcee9..8050c139 100644 --- a/dDatabase/Tables/CDScriptComponentTable.cpp +++ b/dDatabase/Tables/CDScriptComponentTable.cpp @@ -29,14 +29,6 @@ CDScriptComponentTable::CDScriptComponentTable(void) { tableData.finalize(); } -//! Destructor -CDScriptComponentTable::~CDScriptComponentTable(void) {} - -//! Returns the table's name -std::string CDScriptComponentTable::GetName(void) const { - return "ScriptComponent"; -} - const CDScriptComponent& CDScriptComponentTable::GetByID(unsigned int id) { std::map::iterator it = this->entries.find(id); if (it != this->entries.end()) { diff --git a/dDatabase/Tables/CDScriptComponentTable.h b/dDatabase/Tables/CDScriptComponentTable.h index 92534cc0..77453939 100644 --- a/dDatabase/Tables/CDScriptComponentTable.h +++ b/dDatabase/Tables/CDScriptComponentTable.h @@ -3,44 +3,20 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDScriptComponentTable.hpp - \brief Contains data for the ScriptComponent table - */ - - //! ScriptComponent Struct struct CDScriptComponent { unsigned int id; //!< The component ID std::string script_name; //!< The script name std::string client_script_name; //!< The client script name }; -//! ObjectSkills table -class CDScriptComponentTable : public CDTable { +class CDScriptComponentTable : public CDTable { private: std::map entries; CDScriptComponent m_ToReturnWhenNoneFound; public: - //! Gets an entry by ID + CDScriptComponentTable(); + // Gets an entry by scriptID const CDScriptComponent& GetByID(unsigned int id); - - //! Constructor - CDScriptComponentTable(void); - - //! Destructor - ~CDScriptComponentTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ - }; diff --git a/dDatabase/Tables/CDSkillBehaviorTable.cpp b/dDatabase/Tables/CDSkillBehaviorTable.cpp index b6b601a1..c5df78ef 100644 --- a/dDatabase/Tables/CDSkillBehaviorTable.cpp +++ b/dDatabase/Tables/CDSkillBehaviorTable.cpp @@ -51,24 +51,8 @@ CDSkillBehaviorTable::CDSkillBehaviorTable(void) { tableData.finalize(); } -//! Destructor -CDSkillBehaviorTable::~CDSkillBehaviorTable(void) {} - -//! Returns the table's name -std::string CDSkillBehaviorTable::GetName(void) const { - return "SkillBehavior"; -} - //! Queries the table with a custom "where" clause std::vector CDSkillBehaviorTable::Query(std::function predicate) { - - /*std::vector data = cpplinq::from(this->entries) - >> cpplinq::where(predicate) - >> cpplinq::to_vector(); - - return data;*/ - - //Logger::LogDebug("CDSkillBehaviorTable", "The 'Query' function is no longer working! Please use GetSkillByID instead!"); std::vector data; //So MSVC shuts up return data; } diff --git a/dDatabase/Tables/CDSkillBehaviorTable.h b/dDatabase/Tables/CDSkillBehaviorTable.h index da8676db..eb3094e0 100644 --- a/dDatabase/Tables/CDSkillBehaviorTable.h +++ b/dDatabase/Tables/CDSkillBehaviorTable.h @@ -3,12 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDSkillBehaviorTable.hpp - \brief Contains data for the SkillBehavior table - */ - - //! ZoneTable Struct struct CDSkillBehavior { unsigned int skillID; //!< The Skill ID of the skill UNUSED(unsigned int locStatus); //!< ?? @@ -31,33 +25,17 @@ struct CDSkillBehavior { UNUSED(unsigned int cancelType); //!< The cancel type (?) }; -//! SkillBehavior table -class CDSkillBehaviorTable : public CDTable { +class CDSkillBehaviorTable : public CDTable { private: std::map entries; CDSkillBehavior m_empty; public: - - //! Constructor - CDSkillBehaviorTable(void); - - //! Destructor - ~CDSkillBehaviorTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDSkillBehaviorTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets an entry by ID + // Gets an entry by skillID const CDSkillBehavior& GetSkillByID(unsigned int skillID); }; diff --git a/dDatabase/Tables/CDTable.h b/dDatabase/Tables/CDTable.h index cd05782d..fca16eb8 100644 --- a/dDatabase/Tables/CDTable.h +++ b/dDatabase/Tables/CDTable.h @@ -1,9 +1,8 @@ #pragma once -// Custom Classes -#include "../CDClientDatabase.h" +#include "CDClientDatabase.h" +#include "Singleton.h" -// C++ #include #include #include @@ -19,23 +18,8 @@ #pragma warning (disable : 4244) //Disable double to float conversion warnings #pragma warning (disable : 4715) //Disable "not all control paths return a value" -#if defined(__unix) || defined(__APPLE__) -//For Linux: -typedef __int64_t __int64; -#endif - -/*! - \file CDTable.hpp - \brief A virtual class for CDClient Tables - */ - - //! The base class for all CD tables -class CDTable { -public: - - //! Returns the table's name - /*! - \return The table name - */ - virtual std::string GetName() const = 0; +template +class CDTable : public Singleton { +protected: + virtual ~CDTable() = default; }; diff --git a/dDatabase/Tables/CDVendorComponentTable.cpp b/dDatabase/Tables/CDVendorComponentTable.cpp index 86d87d4b..dfff2e20 100644 --- a/dDatabase/Tables/CDVendorComponentTable.cpp +++ b/dDatabase/Tables/CDVendorComponentTable.cpp @@ -34,14 +34,6 @@ CDVendorComponentTable::CDVendorComponentTable(void) { tableData.finalize(); } -//! Destructor -CDVendorComponentTable::~CDVendorComponentTable(void) {} - -//! Returns the table's name -std::string CDVendorComponentTable::GetName(void) const { - return "VendorComponent"; -} - //! Queries the table with a custom "where" clause std::vector CDVendorComponentTable::Query(std::function predicate) { diff --git a/dDatabase/Tables/CDVendorComponentTable.h b/dDatabase/Tables/CDVendorComponentTable.h index 2e0fb9e4..f2666d7e 100644 --- a/dDatabase/Tables/CDVendorComponentTable.h +++ b/dDatabase/Tables/CDVendorComponentTable.h @@ -3,12 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDVendorComponentTable.hpp - \brief Contains data for the VendorComponent table - */ - - //! VendorComponent Struct struct CDVendorComponent { unsigned int id; //!< The Component ID float buyScalar; //!< Buy Scalar (what does that mean?) @@ -17,36 +11,15 @@ struct CDVendorComponent { unsigned int LootMatrixIndex; //!< LootMatrixIndex of the vendor's items }; -//! VendorComponent table -class CDVendorComponentTable : public CDTable { +class CDVendorComponentTable : public CDTable { private: std::vector entries; public: - - //! Constructor - CDVendorComponentTable(void); - - //! Destructor - ~CDVendorComponentTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a custom "where" clause - /*! - \param predicate The predicate - */ + CDVendorComponentTable(); + // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - //! Gets all the entries in the table - /*! - \return The entries - */ std::vector GetEntries(void) const; - }; diff --git a/dDatabase/Tables/CDZoneTableTable.cpp b/dDatabase/Tables/CDZoneTableTable.cpp index 04f7d102..bafbf8fe 100644 --- a/dDatabase/Tables/CDZoneTableTable.cpp +++ b/dDatabase/Tables/CDZoneTableTable.cpp @@ -53,14 +53,6 @@ CDZoneTableTable::CDZoneTableTable(void) { tableData.finalize(); } -//! Destructor -CDZoneTableTable::~CDZoneTableTable(void) {} - -//! Returns the table's name -std::string CDZoneTableTable::GetName(void) const { - return "ZoneTable"; -} - //! Queries the table with a zoneID to find. const CDZoneTable* CDZoneTableTable::Query(unsigned int zoneID) { const auto& iter = m_Entries.find(zoneID); diff --git a/dDatabase/Tables/CDZoneTableTable.h b/dDatabase/Tables/CDZoneTableTable.h index c115a38a..f844fd25 100644 --- a/dDatabase/Tables/CDZoneTableTable.h +++ b/dDatabase/Tables/CDZoneTableTable.h @@ -3,12 +3,6 @@ // Custom Classes #include "CDTable.h" -/*! - \file CDZoneTableTable.hpp - \brief Contains data for the ZoneTable table - */ - - //! ZoneTable Struct struct CDZoneTable { unsigned int zoneID; //!< The Zone ID of the object unsigned int locStatus; //!< The Locale Status(?) @@ -39,28 +33,13 @@ struct CDZoneTable { UNUSED(bool mountsAllowed); //!< Whether or not mounts are allowed }; -//! ZoneTable table -class CDZoneTableTable : public CDTable { +class CDZoneTableTable : public CDTable { private: std::map m_Entries; public: + CDZoneTableTable(); - //! Constructor - CDZoneTableTable(void); - - //! Destructor - ~CDZoneTableTable(void); - - //! Returns the table's name - /*! - \return The table name - */ - std::string GetName(void) const override; - - //! Queries the table with a zoneID to find. - /*! - \param id The zoneID - */ + // Queries the table with a zoneID to find. const CDZoneTable* Query(unsigned int zoneID); }; diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 49f8a9d2..c36b0bd3 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -72,6 +72,19 @@ #include "TriggerComponent.h" #include "ItemComponent.h" #include "MutableModelBehaviorComponent.h" +#include "eReplicaComponentType.h" + +// Table includes +#include "CDComponentsRegistryTable.h" +#include "CDCurrencyTableTable.h" +#include "CDMovementAIComponentTable.h" +#include "CDProximityMonitorComponentTable.h" +#include "CDRebuildComponentTable.h" +#include "CDObjectSkillsTable.h" +#include "CDObjectsTable.h" +#include "CDScriptComponentTable.h" +#include "CDSkillBehaviorTable.h" +#include "CDZoneTableTable.h" Entity::Entity(const LWOOBJID& objectID, EntityInfo info, Entity* parentEntity) { m_ObjectID = objectID; @@ -137,7 +150,7 @@ void Entity::Initialize() { const auto triggerInfo = GetVarAsString(u"trigger_id"); - if (!triggerInfo.empty()) m_Components.emplace(COMPONENT_TYPE_TRIGGER, new TriggerComponent(this, triggerInfo)); + if (!triggerInfo.empty()) m_Components.emplace(eReplicaComponentType::TRIGGER, new TriggerComponent(this, triggerInfo)); /** * Setup groups @@ -159,30 +172,30 @@ void Entity::Initialize() { } // Get the registry table - CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance()->GetTable("ComponentsRegistry"); + CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance().GetTable(); /** * Special case for BBB models. They have components not corresponding to the registry. */ if (m_TemplateID == 14) { - const auto simplePhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_SIMPLE_PHYSICS); + const auto simplePhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SIMPLE_PHYSICS); SimplePhysicsComponent* comp = new SimplePhysicsComponent(simplePhysicsComponentID, this); - m_Components.insert(std::make_pair(COMPONENT_TYPE_SIMPLE_PHYSICS, comp)); + m_Components.insert(std::make_pair(eReplicaComponentType::SIMPLE_PHYSICS, comp)); ModelComponent* modelcomp = new ModelComponent(this); - m_Components.insert(std::make_pair(COMPONENT_TYPE_MODEL, modelcomp)); + m_Components.insert(std::make_pair(eReplicaComponentType::MODEL, modelcomp)); RenderComponent* render = new RenderComponent(this); - m_Components.insert(std::make_pair(COMPONENT_TYPE_RENDER, render)); + m_Components.insert(std::make_pair(eReplicaComponentType::RENDER, render)); auto destroyableComponent = new DestroyableComponent(this); destroyableComponent->SetHealth(1); destroyableComponent->SetMaxHealth(1.0f); destroyableComponent->SetFaction(-1, true); destroyableComponent->SetIsSmashable(true); - m_Components.insert(std::make_pair(COMPONENT_TYPE_DESTROYABLE, destroyableComponent)); + m_Components.insert(std::make_pair(eReplicaComponentType::DESTROYABLE, destroyableComponent)); // We have all our components. return; } @@ -195,47 +208,47 @@ void Entity::Initialize() { if (GetParentUser()) { auto missions = new MissionComponent(this); - m_Components.insert(std::make_pair(COMPONENT_TYPE_MISSION, missions)); + m_Components.insert(std::make_pair(eReplicaComponentType::MISSION, missions)); missions->LoadFromXml(m_Character->GetXMLDoc()); } - uint32_t petComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_PET); + uint32_t petComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PET); if (petComponentId > 0) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_PET, new PetComponent(this, petComponentId))); + m_Components.insert(std::make_pair(eReplicaComponentType::PET, new PetComponent(this, petComponentId))); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_ZONE_CONTROL) > 0) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_ZONE_CONTROL, nullptr)); + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ZONE_CONTROL) > 0) { + m_Components.insert(std::make_pair(eReplicaComponentType::ZONE_CONTROL, nullptr)); } - uint32_t possessableComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_POSSESSABLE); + uint32_t possessableComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::POSSESSABLE); if (possessableComponentId > 0) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_POSSESSABLE, new PossessableComponent(this, possessableComponentId))); + m_Components.insert(std::make_pair(eReplicaComponentType::POSSESSABLE, new PossessableComponent(this, possessableComponentId))); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_MODULE_ASSEMBLY) > 0) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_MODULE_ASSEMBLY, new ModuleAssemblyComponent(this))); + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MODULE_ASSEMBLY) > 0) { + m_Components.insert(std::make_pair(eReplicaComponentType::MODULE_ASSEMBLY, new ModuleAssemblyComponent(this))); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_RACING_STATS) > 0) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_RACING_STATS, nullptr)); + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RACING_STATS) > 0) { + m_Components.insert(std::make_pair(eReplicaComponentType::RACING_STATS, nullptr)); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_EXHIBIT, -1) >= 0) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_EXHIBIT, new LUPExhibitComponent(this))); + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::LUP_EXHIBIT, -1) >= 0) { + m_Components.insert(std::make_pair(eReplicaComponentType::LUP_EXHIBIT, new LUPExhibitComponent(this))); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_RACING_CONTROL) > 0) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_RACING_CONTROL, new RacingControlComponent(this))); + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RACING_CONTROL) > 0) { + m_Components.insert(std::make_pair(eReplicaComponentType::RACING_CONTROL, new RacingControlComponent(this))); } - const auto propertyEntranceComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_PROPERTY_ENTRANCE); + const auto propertyEntranceComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROPERTY_ENTRANCE); if (propertyEntranceComponentID > 0) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_PROPERTY_ENTRANCE, + m_Components.insert(std::make_pair(eReplicaComponentType::PROPERTY_ENTRANCE, new PropertyEntranceComponent(propertyEntranceComponentID, this))); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_CONTROLLABLE_PHYSICS) > 0) { + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::CONTROLLABLE_PHYSICS) > 0) { ControllablePhysicsComponent* controllablePhysics = new ControllablePhysicsComponent(this); if (m_Character) { @@ -270,68 +283,68 @@ void Entity::Initialize() { controllablePhysics->SetRotation(m_DefaultRotation); } - m_Components.insert(std::make_pair(COMPONENT_TYPE_CONTROLLABLE_PHYSICS, controllablePhysics)); + m_Components.insert(std::make_pair(eReplicaComponentType::CONTROLLABLE_PHYSICS, controllablePhysics)); } // If an entity is marked a phantom, simple physics is made into phantom phyics. bool markedAsPhantom = GetVar(u"markedAsPhantom"); - const auto simplePhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_SIMPLE_PHYSICS); + const auto simplePhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SIMPLE_PHYSICS); if (!markedAsPhantom && simplePhysicsComponentID > 0) { SimplePhysicsComponent* comp = new SimplePhysicsComponent(simplePhysicsComponentID, this); - m_Components.insert(std::make_pair(COMPONENT_TYPE_SIMPLE_PHYSICS, comp)); + m_Components.insert(std::make_pair(eReplicaComponentType::SIMPLE_PHYSICS, comp)); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_RIGID_BODY_PHANTOM_PHYSICS) > 0) { + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS) > 0) { RigidbodyPhantomPhysicsComponent* comp = new RigidbodyPhantomPhysicsComponent(this); - m_Components.insert(std::make_pair(COMPONENT_TYPE_RIGID_BODY_PHANTOM_PHYSICS, comp)); + m_Components.insert(std::make_pair(eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS, comp)); } - if (markedAsPhantom || compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_PHANTOM_PHYSICS) > 0) { + if (markedAsPhantom || compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PHANTOM_PHYSICS) > 0) { PhantomPhysicsComponent* phantomPhysics = new PhantomPhysicsComponent(this); phantomPhysics->SetPhysicsEffectActive(false); - m_Components.insert(std::make_pair(COMPONENT_TYPE_PHANTOM_PHYSICS, phantomPhysics)); + m_Components.insert(std::make_pair(eReplicaComponentType::PHANTOM_PHYSICS, phantomPhysics)); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_VEHICLE_PHYSICS) > 0) { + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::VEHICLE_PHYSICS) > 0) { VehiclePhysicsComponent* vehiclePhysicsComponent = new VehiclePhysicsComponent(this); - m_Components.insert(std::make_pair(COMPONENT_TYPE_VEHICLE_PHYSICS, vehiclePhysicsComponent)); + m_Components.insert(std::make_pair(eReplicaComponentType::VEHICLE_PHYSICS, vehiclePhysicsComponent)); vehiclePhysicsComponent->SetPosition(m_DefaultPosition); vehiclePhysicsComponent->SetRotation(m_DefaultRotation); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_SOUND_TRIGGER, -1) != -1) { + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SOUND_TRIGGER, -1) != -1) { auto* comp = new SoundTriggerComponent(this); - m_Components.insert(std::make_pair(COMPONENT_TYPE_SOUND_TRIGGER, comp)); + m_Components.insert(std::make_pair(eReplicaComponentType::SOUND_TRIGGER, comp)); } //Also check for the collectible id: m_CollectibleID = GetVarAs(u"collectible_id"); - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_BUFF) > 0) { + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::BUFF) > 0) { BuffComponent* comp = new BuffComponent(this); - m_Components.insert(std::make_pair(COMPONENT_TYPE_BUFF, comp)); + m_Components.insert(std::make_pair(eReplicaComponentType::BUFF, comp)); } - int collectibleComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_COLLECTIBLE); + int collectibleComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::COLLECTIBLE); if (collectibleComponentID > 0) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_COLLECTIBLE, nullptr)); + m_Components.insert(std::make_pair(eReplicaComponentType::COLLECTIBLE, nullptr)); } /** * Multiple components require the destructible component. */ - int buffComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_BUFF); - int rebuildComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_REBUILD); + int buffComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::BUFF); + int rebuildComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::QUICK_BUILD); int componentID = 0; if (collectibleComponentID > 0) componentID = collectibleComponentID; if (rebuildComponentID > 0) componentID = rebuildComponentID; if (buffComponentID > 0) componentID = buffComponentID; - CDDestructibleComponentTable* destCompTable = CDClientManager::Instance()->GetTable("DestructibleComponent"); + CDDestructibleComponentTable* destCompTable = CDClientManager::Instance().GetTable(); std::vector destCompData = destCompTable->Query([=](CDDestructibleComponent entry) { return (entry.id == componentID); }); if (buffComponentID > 0 || collectibleComponentID > 0) { @@ -343,7 +356,7 @@ void Entity::Initialize() { std::vector destCompData = destCompTable->Query([=](CDDestructibleComponent entry) { return (entry.id == componentID); }); if (destCompData.size() > 0) { - if (HasComponent(COMPONENT_TYPE_RACING_STATS)) { + if (HasComponent(eReplicaComponentType::RACING_STATS)) { destCompData[0].imagination = 60; } @@ -363,7 +376,7 @@ void Entity::Initialize() { uint32_t npcMinLevel = destCompData[0].level; uint32_t currencyIndex = destCompData[0].CurrencyIndex; - CDCurrencyTableTable* currencyTable = CDClientManager::Instance()->GetTable("CurrencyTable"); + CDCurrencyTableTable* currencyTable = CDClientManager::Instance().GetTable(); std::vector currencyValues = currencyTable->Query([=](CDCurrencyTable entry) { return (entry.currencyIndex == currencyIndex && entry.npcminlevel == npcMinLevel); }); if (currencyValues.size() > 0) { @@ -387,8 +400,8 @@ void Entity::Initialize() { comp->AddFaction(6); //Smashables // A race car has 60 imagination, other entities defaults to 0. - comp->SetImagination(HasComponent(COMPONENT_TYPE_RACING_STATS) ? 60 : 0); - comp->SetMaxImagination(HasComponent(COMPONENT_TYPE_RACING_STATS) ? 60 : 0); + comp->SetImagination(HasComponent(eReplicaComponentType::RACING_STATS) ? 60 : 0); + comp->SetMaxImagination(HasComponent(eReplicaComponentType::RACING_STATS) ? 60 : 0); } } @@ -406,43 +419,43 @@ void Entity::Initialize() { } } - m_Components.insert(std::make_pair(COMPONENT_TYPE_DESTROYABLE, comp)); + m_Components.insert(std::make_pair(eReplicaComponentType::DESTROYABLE, comp)); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_CHARACTER) > 0 || m_Character) { + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::CHARACTER) > 0 || m_Character) { // Character Component always has a possessor, level, and forced movement components - m_Components.insert(std::make_pair(COMPONENT_TYPE_POSSESSOR, new PossessorComponent(this))); + m_Components.insert(std::make_pair(eReplicaComponentType::POSSESSOR, new PossessorComponent(this))); // load in the xml for the level auto* levelComp = new LevelProgressionComponent(this); levelComp->LoadFromXml(m_Character->GetXMLDoc()); - m_Components.insert(std::make_pair(COMPONENT_TYPE_LEVEL_PROGRESSION, levelComp)); + m_Components.insert(std::make_pair(eReplicaComponentType::LEVEL_PROGRESSION, levelComp)); - m_Components.insert(std::make_pair(COMPONENT_TYPE_PLAYER_FORCED_MOVEMENT, new PlayerForcedMovementComponent(this))); + m_Components.insert(std::make_pair(eReplicaComponentType::PLAYER_FORCED_MOVEMENT, new PlayerForcedMovementComponent(this))); CharacterComponent* charComp = new CharacterComponent(this, m_Character); charComp->LoadFromXml(m_Character->GetXMLDoc()); - m_Components.insert(std::make_pair(COMPONENT_TYPE_CHARACTER, charComp)); + m_Components.insert(std::make_pair(eReplicaComponentType::CHARACTER, charComp)); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_INVENTORY) > 0 || m_Character) { + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::INVENTORY) > 0 || m_Character) { InventoryComponent* comp = nullptr; if (m_Character) comp = new InventoryComponent(this, m_Character->GetXMLDoc()); else comp = new InventoryComponent(this); - m_Components.insert(std::make_pair(COMPONENT_TYPE_INVENTORY, comp)); + m_Components.insert(std::make_pair(eReplicaComponentType::INVENTORY, comp)); } // if this component exists, then we initialize it. it's value is always 0 - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_ROCKET_LAUNCH_LUP, -1) != -1) { + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ROCKET_LAUNCH_LUP, -1) != -1) { auto comp = new RocketLaunchLupComponent(this); - m_Components.insert(std::make_pair(COMPONENT_TYPE_ROCKET_LAUNCH_LUP, comp)); + m_Components.insert(std::make_pair(eReplicaComponentType::ROCKET_LAUNCH_LUP, comp)); } /** * This is a bit of a mess */ - CDScriptComponentTable* scriptCompTable = CDClientManager::Instance()->GetTable("ScriptComponent"); - int32_t scriptComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_SCRIPT, -1); + CDScriptComponentTable* scriptCompTable = CDClientManager::Instance().GetTable(); + int32_t scriptComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SCRIPT, -1); std::string scriptName = ""; bool client = false; @@ -485,12 +498,12 @@ void Entity::Initialize() { } if (!scriptName.empty() || client || m_Character || scriptComponentID >= 0) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_SCRIPT, new ScriptComponent(this, scriptName, true, client && scriptName.empty()))); + m_Components.insert(std::make_pair(eReplicaComponentType::SCRIPT, new ScriptComponent(this, scriptName, true, client && scriptName.empty()))); } // ZoneControl script if (m_TemplateID == 2365) { - CDZoneTableTable* zoneTable = CDClientManager::Instance()->GetTable("ZoneTable"); + CDZoneTableTable* zoneTable = CDClientManager::Instance().GetTable(); const auto zoneID = dZoneManager::Instance()->GetZoneID(); const CDZoneTable* zoneData = zoneTable->Query(zoneID.GetMapID()); @@ -499,26 +512,26 @@ void Entity::Initialize() { CDScriptComponent zoneScriptData = scriptCompTable->GetByID(zoneScriptID); ScriptComponent* comp = new ScriptComponent(this, zoneScriptData.script_name, true); - m_Components.insert(std::make_pair(COMPONENT_TYPE_SCRIPT, comp)); + m_Components.insert(std::make_pair(eReplicaComponentType::SCRIPT, comp)); } } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_SKILL, -1) != -1 || m_Character) { + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SKILL, -1) != -1 || m_Character) { SkillComponent* comp = new SkillComponent(this); - m_Components.insert(std::make_pair(COMPONENT_TYPE_SKILL, comp)); + m_Components.insert(std::make_pair(eReplicaComponentType::SKILL, comp)); } - const auto combatAiId = compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_BASE_COMBAT_AI); + const auto combatAiId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::BASE_COMBAT_AI); if (combatAiId > 0) { BaseCombatAIComponent* comp = new BaseCombatAIComponent(this, combatAiId); - m_Components.insert(std::make_pair(COMPONENT_TYPE_BASE_COMBAT_AI, comp)); + m_Components.insert(std::make_pair(eReplicaComponentType::BASE_COMBAT_AI, comp)); } - if (int componentID = compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_REBUILD) > 0) { + if (int componentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::QUICK_BUILD) > 0) { RebuildComponent* comp = new RebuildComponent(this); - m_Components.insert(std::make_pair(COMPONENT_TYPE_REBUILD, comp)); + m_Components.insert(std::make_pair(eReplicaComponentType::QUICK_BUILD, comp)); - CDRebuildComponentTable* rebCompTable = CDClientManager::Instance()->GetTable("RebuildComponent"); + CDRebuildComponentTable* rebCompTable = CDClientManager::Instance().GetTable(); std::vector rebCompData = rebCompTable->Query([=](CDRebuildComponent entry) { return (entry.id == rebuildComponentID); }); if (rebCompData.size() > 0) { @@ -556,89 +569,88 @@ void Entity::Initialize() { } } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_SWITCH, -1) != -1) { + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SWITCH, -1) != -1) { SwitchComponent* comp = new SwitchComponent(this); - m_Components.insert(std::make_pair(COMPONENT_TYPE_SWITCH, comp)); + m_Components.insert(std::make_pair(eReplicaComponentType::SWITCH, comp)); } - if ((compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_VENDOR) > 0)) { + if ((compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::VENDOR) > 0)) { VendorComponent* comp = new VendorComponent(this); - m_Components.insert(std::make_pair(COMPONENT_TYPE_VENDOR, comp)); + m_Components.insert(std::make_pair(eReplicaComponentType::VENDOR, comp)); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_PROPERTY_VENDOR, -1) != -1) { + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROPERTY_VENDOR, -1) != -1) { auto* component = new PropertyVendorComponent(this); - m_Components.insert_or_assign(COMPONENT_TYPE_PROPERTY_VENDOR, component); + m_Components.insert_or_assign(eReplicaComponentType::PROPERTY_VENDOR, component); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_PROPERTY_MANAGEMENT, -1) != -1) { + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROPERTY_MANAGEMENT, -1) != -1) { auto* component = new PropertyManagementComponent(this); - m_Components.insert_or_assign(COMPONENT_TYPE_PROPERTY_MANAGEMENT, component); + m_Components.insert_or_assign(eReplicaComponentType::PROPERTY_MANAGEMENT, component); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_BOUNCER, -1) != -1) { // you have to determine it like this because all bouncers have a componentID of 0 + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::BOUNCER, -1) != -1) { // you have to determine it like this because all bouncers have a componentID of 0 BouncerComponent* comp = new BouncerComponent(this); - m_Components.insert(std::make_pair(COMPONENT_TYPE_BOUNCER, comp)); + m_Components.insert(std::make_pair(eReplicaComponentType::BOUNCER, comp)); } - if ((compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_RENDER) > 0 && m_TemplateID != 2365) || m_Character) { + if ((compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RENDER) > 0 && m_TemplateID != 2365) || m_Character) { RenderComponent* render = new RenderComponent(this); - m_Components.insert(std::make_pair(COMPONENT_TYPE_RENDER, render)); + m_Components.insert(std::make_pair(eReplicaComponentType::RENDER, render)); } - if ((compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_MISSION_OFFER) > 0) || m_Character) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_MISSION_OFFER, new MissionOfferComponent(this, m_TemplateID))); + if ((compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MISSION_OFFER) > 0) || m_Character) { + m_Components.insert(std::make_pair(eReplicaComponentType::MISSION_OFFER, new MissionOfferComponent(this, m_TemplateID))); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_BUILD_BORDER, -1) != -1) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_BUILD_BORDER, new BuildBorderComponent(this))); + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::BUILD_BORDER, -1) != -1) { + m_Components.insert(std::make_pair(eReplicaComponentType::BUILD_BORDER, new BuildBorderComponent(this))); } // Scripted activity component - int scriptedActivityID = compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_SCRIPTED_ACTIVITY); + int scriptedActivityID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SCRIPTED_ACTIVITY); if ((scriptedActivityID > 0)) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_SCRIPTED_ACTIVITY, new ScriptedActivityComponent(this, scriptedActivityID))); + m_Components.insert(std::make_pair(eReplicaComponentType::SCRIPTED_ACTIVITY, new ScriptedActivityComponent(this, scriptedActivityID))); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_MODEL, -1) != -1 && !(petComponentId > 0)) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_MODEL, new ModelComponent(this))); - if (m_Components.find(COMPONENT_TYPE_DESTROYABLE) == m_Components.end()) { + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MODEL, -1) != -1 && !(petComponentId > 0)) { + m_Components.insert(std::make_pair(eReplicaComponentType::MODEL, new ModelComponent(this))); + if (m_Components.find(eReplicaComponentType::DESTROYABLE) == m_Components.end()) { auto destroyableComponent = new DestroyableComponent(this); destroyableComponent->SetHealth(1); destroyableComponent->SetMaxHealth(1.0f); destroyableComponent->SetFaction(-1, true); destroyableComponent->SetIsSmashable(true); - m_Components.insert(std::make_pair(COMPONENT_TYPE_DESTROYABLE, destroyableComponent)); + m_Components.insert(std::make_pair(eReplicaComponentType::DESTROYABLE, destroyableComponent)); } } - - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_ITEM) > 0 && !(petComponentId > 0)) { - m_Components.emplace(COMPONENT_TYPE_ITEM, new ItemComponent(this)); + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ITEM) > 0 && !(petComponentId > 0)) { + m_Components.insert(std::make_pair(eReplicaComponentType::ITEM, nullptr)); } // Shooting gallery component - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_SHOOTING_GALLERY) > 0) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_SHOOTING_GALLERY, new ShootingGalleryComponent(this))); + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SHOOTING_GALLERY) > 0) { + m_Components.insert(std::make_pair(eReplicaComponentType::SHOOTING_GALLERY, new ShootingGalleryComponent(this))); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_PROPERTY, -1) != -1) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_PROPERTY, new PropertyComponent(this))); + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROPERTY, -1) != -1) { + m_Components.insert(std::make_pair(eReplicaComponentType::PROPERTY, new PropertyComponent(this))); } - const int rocketId = compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_ROCKET_LAUNCH); + const int rocketId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ROCKET_LAUNCH); if ((rocketId > 0)) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_ROCKET_LAUNCH, new RocketLaunchpadControlComponent(this, rocketId))); + m_Components.insert(std::make_pair(eReplicaComponentType::ROCKET_LAUNCH, new RocketLaunchpadControlComponent(this, rocketId))); } - const int32_t railComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_RAIL_ACTIVATOR); + const int32_t railComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RAIL_ACTIVATOR); if (railComponentID > 0) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_RAIL_ACTIVATOR, new RailActivatorComponent(this, railComponentID))); + m_Components.insert(std::make_pair(eReplicaComponentType::RAIL_ACTIVATOR, new RailActivatorComponent(this, railComponentID))); } - int movementAIID = compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_MOVEMENT_AI); + int movementAIID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MOVEMENT_AI); if (movementAIID > 0) { - CDMovementAIComponentTable* moveAITable = CDClientManager::Instance()->GetTable("MovementAIComponent"); + CDMovementAIComponentTable* moveAITable = CDClientManager::Instance().GetTable(); std::vector moveAIComp = moveAITable->Query([=](CDMovementAIComponent entry) {return (entry.id == movementAIID); }); if (moveAIComp.size() > 0) { @@ -661,7 +673,7 @@ void Entity::Initialize() { } } - m_Components.insert(std::make_pair(COMPONENT_TYPE_MOVEMENT_AI, new MovementAIComponent(this, moveInfo))); + m_Components.insert(std::make_pair(eReplicaComponentType::MOVEMENT_AI, new MovementAIComponent(this, moveInfo))); } } else if (petComponentId > 0 || combatAiId > 0 && GetComponent()->GetTetherSpeed() > 0) { MovementAIInfo moveInfo = MovementAIInfo(); @@ -672,7 +684,7 @@ void Entity::Initialize() { moveInfo.wanderDelayMax = 5; moveInfo.wanderDelayMin = 2; - m_Components.insert(std::make_pair(COMPONENT_TYPE_MOVEMENT_AI, new MovementAIComponent(this, moveInfo))); + m_Components.insert(std::make_pair(eReplicaComponentType::MOVEMENT_AI, new MovementAIComponent(this, moveInfo))); } std::string pathName = GetVarAsString(u"attached_path"); @@ -683,7 +695,7 @@ void Entity::Initialize() { // if we have a moving platform path, then we need a moving platform component if (path->pathType == PathType::MovingPlatform) { MovingPlatformComponent* plat = new MovingPlatformComponent(this, pathName); - m_Components.insert(std::make_pair(COMPONENT_TYPE_MOVING_PLATFORM, plat)); + m_Components.insert(std::make_pair(eReplicaComponentType::MOVING_PLATFORM, plat)); // else if we are a movement path } /*else if (path->pathType == PathType::Movement) { auto movementAIcomp = GetComponent(); @@ -695,14 +707,14 @@ void Entity::Initialize() { }*/ } - int proximityMonitorID = compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_PROXIMITY_MONITOR); + int proximityMonitorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROXIMITY_MONITOR); if (proximityMonitorID > 0) { - CDProximityMonitorComponentTable* proxCompTable = CDClientManager::Instance()->GetTable("ProximityMonitorComponent"); + CDProximityMonitorComponentTable* proxCompTable = CDClientManager::Instance().GetTable(); std::vector proxCompData = proxCompTable->Query([=](CDProximityMonitorComponent entry) { return (entry.id == proximityMonitorID); }); if (proxCompData.size() > 0) { std::vector proximityStr = GeneralUtils::SplitString(proxCompData[0].Proximities, ','); ProximityMonitorComponent* comp = new ProximityMonitorComponent(this, std::stoi(proximityStr[0]), std::stoi(proximityStr[1])); - m_Components.insert(std::make_pair(COMPONENT_TYPE_PROXIMITY_MONITOR, comp)); + m_Components.insert(std::make_pair(eReplicaComponentType::PROXIMITY_MONITOR, comp)); } } @@ -715,7 +727,7 @@ void Entity::Initialize() { if (!m_Character && EntityManager::Instance()->GetGhostingEnabled()) { // Don't ghost what is likely large scene elements - if (m_Components.size() == 2 && HasComponent(COMPONENT_TYPE_SIMPLE_PHYSICS) && HasComponent(COMPONENT_TYPE_RENDER)) { + if (m_Components.size() == 2 && HasComponent(eReplicaComponentType::SIMPLE_PHYSICS) && HasComponent(eReplicaComponentType::RENDER)) { goto no_ghosting; } @@ -727,14 +739,14 @@ void Entity::Initialize() { */ if ( !EntityManager::IsExcludedFromGhosting(GetLOT()) && - !HasComponent(COMPONENT_TYPE_SCRIPTED_ACTIVITY) && - !HasComponent(COMPONENT_TYPE_MOVING_PLATFORM) && - !HasComponent(COMPONENT_TYPE_PHANTOM_PHYSICS) && - !HasComponent(COMPONENT_TYPE_PROPERTY) && - !HasComponent(COMPONENT_TYPE_RACING_CONTROL) && - !HasComponent(COMPONENT_TYPE_VEHICLE_PHYSICS) + !HasComponent(eReplicaComponentType::SCRIPTED_ACTIVITY) && + !HasComponent(eReplicaComponentType::MOVING_PLATFORM) && + !HasComponent(eReplicaComponentType::PHANTOM_PHYSICS) && + !HasComponent(eReplicaComponentType::PROPERTY) && + !HasComponent(eReplicaComponentType::RACING_CONTROL) && + !HasComponent(eReplicaComponentType::VEHICLE_PHYSICS) ) - //if (HasComponent(COMPONENT_TYPE_BASE_COMBAT_AI)) + //if (HasComponent(eReplicaComponentType::BASE_COMBAT_AI)) { m_IsGhostingCandidate = true; } @@ -744,7 +756,7 @@ void Entity::Initialize() { } // Special case for collectibles in Ninjago - if (HasComponent(COMPONENT_TYPE_COLLECTIBLE) && Game::server->GetZoneID() == 2000) { + if (HasComponent(eReplicaComponentType::COLLECTIBLE) && Game::server->GetZoneID() == 2000) { m_IsGhostingCandidate = true; } } @@ -779,7 +791,7 @@ User* Entity::GetParentUser() const { return static_cast(this)->GetParentUser(); } -Component* Entity::GetComponent(int32_t componentID) const { +Component* Entity::GetComponent(eReplicaComponentType componentID) const { const auto& index = m_Components.find(componentID); if (index == m_Components.end()) { @@ -789,11 +801,11 @@ Component* Entity::GetComponent(int32_t componentID) const { return index->second; } -bool Entity::HasComponent(const int32_t componentId) const { +bool Entity::HasComponent(const eReplicaComponentType componentId) const { return m_Components.find(componentId) != m_Components.end(); } -void Entity::AddComponent(const int32_t componentId, Component* component) { +void Entity::AddComponent(const eReplicaComponentType componentId, Component* component) { if (HasComponent(componentId)) { return; } @@ -803,8 +815,8 @@ void Entity::AddComponent(const int32_t componentId, Component* component) { std::vector Entity::GetScriptComponents() { std::vector comps; - for (std::pair p : m_Components) { - if (p.first == COMPONENT_TYPE_SCRIPT) { + for (std::pair p : m_Components) { + if (p.first == eReplicaComponentType::SCRIPT) { comps.push_back(static_cast(p.second)); } } @@ -832,7 +844,7 @@ void Entity::SetProximityRadius(float proxRadius, std::string name) { ProximityMonitorComponent* proxMon = GetComponent(); if (!proxMon) { proxMon = new ProximityMonitorComponent(this); - m_Components.insert_or_assign(COMPONENT_TYPE_PROXIMITY_MONITOR, proxMon); + m_Components.insert_or_assign(eReplicaComponentType::PROXIMITY_MONITOR, proxMon); } proxMon->SetProximityRadius(proxRadius, name); } @@ -841,7 +853,7 @@ void Entity::SetProximityRadius(dpEntity* entity, std::string name) { ProximityMonitorComponent* proxMon = GetComponent(); if (!proxMon) { proxMon = new ProximityMonitorComponent(this); - m_Components.insert_or_assign(COMPONENT_TYPE_PROXIMITY_MONITOR, proxMon); + m_Components.insert_or_assign(eReplicaComponentType::PROXIMITY_MONITOR, proxMon); } proxMon->SetProximityRadius(entity, name); } @@ -929,7 +941,7 @@ void Entity::WriteBaseReplicaData(RakNet::BitStream* outBitStream, eReplicaPacke } TriggerComponent* triggerComponent; - if (TryGetComponent(COMPONENT_TYPE_TRIGGER, triggerComponent)) { + if (TryGetComponent(eReplicaComponentType::TRIGGER, triggerComponent)) { // has trigger component, check to see if we have events to handle auto* trigger = triggerComponent->GetTrigger(); outBitStream->Write(trigger && trigger->events.size() > 0); @@ -995,59 +1007,59 @@ void Entity::WriteComponents(RakNet::BitStream* outBitStream, eReplicaPacketType unsigned int flags = 0; PossessableComponent* possessableComponent; - if (TryGetComponent(COMPONENT_TYPE_POSSESSABLE, possessableComponent)) { + if (TryGetComponent(eReplicaComponentType::POSSESSABLE, possessableComponent)) { possessableComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } ModuleAssemblyComponent* moduleAssemblyComponent; - if (TryGetComponent(COMPONENT_TYPE_MODULE_ASSEMBLY, moduleAssemblyComponent)) { + if (TryGetComponent(eReplicaComponentType::MODULE_ASSEMBLY, moduleAssemblyComponent)) { moduleAssemblyComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } ControllablePhysicsComponent* controllablePhysicsComponent; - if (TryGetComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS, controllablePhysicsComponent)) { + if (TryGetComponent(eReplicaComponentType::CONTROLLABLE_PHYSICS, controllablePhysicsComponent)) { controllablePhysicsComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } SimplePhysicsComponent* simplePhysicsComponent; - if (TryGetComponent(COMPONENT_TYPE_SIMPLE_PHYSICS, simplePhysicsComponent)) { + if (TryGetComponent(eReplicaComponentType::SIMPLE_PHYSICS, simplePhysicsComponent)) { simplePhysicsComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } RigidbodyPhantomPhysicsComponent* rigidbodyPhantomPhysics; - if (TryGetComponent(COMPONENT_TYPE_RIGID_BODY_PHANTOM_PHYSICS, rigidbodyPhantomPhysics)) { + if (TryGetComponent(eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS, rigidbodyPhantomPhysics)) { rigidbodyPhantomPhysics->Serialize(outBitStream, bIsInitialUpdate, flags); } VehiclePhysicsComponent* vehiclePhysicsComponent; - if (TryGetComponent(COMPONENT_TYPE_VEHICLE_PHYSICS, vehiclePhysicsComponent)) { + if (TryGetComponent(eReplicaComponentType::VEHICLE_PHYSICS, vehiclePhysicsComponent)) { vehiclePhysicsComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } PhantomPhysicsComponent* phantomPhysicsComponent; - if (TryGetComponent(COMPONENT_TYPE_PHANTOM_PHYSICS, phantomPhysicsComponent)) { + if (TryGetComponent(eReplicaComponentType::PHANTOM_PHYSICS, phantomPhysicsComponent)) { phantomPhysicsComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } SoundTriggerComponent* soundTriggerComponent; - if (TryGetComponent(COMPONENT_TYPE_SOUND_TRIGGER, soundTriggerComponent)) { + if (TryGetComponent(eReplicaComponentType::SOUND_TRIGGER, soundTriggerComponent)) { soundTriggerComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } BuffComponent* buffComponent; - if (TryGetComponent(COMPONENT_TYPE_BUFF, buffComponent)) { + if (TryGetComponent(eReplicaComponentType::BUFF, buffComponent)) { buffComponent->Serialize(outBitStream, bIsInitialUpdate, flags); DestroyableComponent* destroyableComponent; - if (TryGetComponent(COMPONENT_TYPE_DESTROYABLE, destroyableComponent)) { + if (TryGetComponent(eReplicaComponentType::DESTROYABLE, destroyableComponent)) { destroyableComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } destroyableSerialized = true; } - if (HasComponent(COMPONENT_TYPE_COLLECTIBLE)) { + if (HasComponent(eReplicaComponentType::COLLECTIBLE)) { DestroyableComponent* destroyableComponent; - if (TryGetComponent(COMPONENT_TYPE_DESTROYABLE, destroyableComponent) && !destroyableSerialized) { + if (TryGetComponent(eReplicaComponentType::DESTROYABLE, destroyableComponent) && !destroyableSerialized) { destroyableComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } destroyableSerialized = true; @@ -1055,15 +1067,15 @@ void Entity::WriteComponents(RakNet::BitStream* outBitStream, eReplicaPacketType } PetComponent* petComponent; - if (TryGetComponent(COMPONENT_TYPE_PET, petComponent)) { + if (TryGetComponent(eReplicaComponentType::PET, petComponent)) { petComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } CharacterComponent* characterComponent; - if (TryGetComponent(COMPONENT_TYPE_CHARACTER, characterComponent)) { + if (TryGetComponent(eReplicaComponentType::CHARACTER, characterComponent)) { PossessorComponent* possessorComponent; - if (TryGetComponent(COMPONENT_TYPE_POSSESSOR, possessorComponent)) { + if (TryGetComponent(eReplicaComponentType::POSSESSOR, possessorComponent)) { possessorComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } else { // Should never happen, but just to be safe @@ -1071,7 +1083,7 @@ void Entity::WriteComponents(RakNet::BitStream* outBitStream, eReplicaPacketType } LevelProgressionComponent* levelProgressionComponent; - if (TryGetComponent(COMPONENT_TYPE_LEVEL_PROGRESSION, levelProgressionComponent)) { + if (TryGetComponent(eReplicaComponentType::LEVEL_PROGRESSION, levelProgressionComponent)) { levelProgressionComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } else { // Should never happen, but just to be safe @@ -1079,7 +1091,7 @@ void Entity::WriteComponents(RakNet::BitStream* outBitStream, eReplicaPacketType } PlayerForcedMovementComponent* playerForcedMovementComponent; - if (TryGetComponent(COMPONENT_TYPE_PLAYER_FORCED_MOVEMENT, playerForcedMovementComponent)) { + if (TryGetComponent(eReplicaComponentType::PLAYER_FORCED_MOVEMENT, playerForcedMovementComponent)) { playerForcedMovementComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } else { // Should never happen, but just to be safe @@ -1090,34 +1102,34 @@ void Entity::WriteComponents(RakNet::BitStream* outBitStream, eReplicaPacketType } ItemComponent* itemComponent; - if (TryGetComponent(COMPONENT_TYPE_ITEM, itemComponent)) { + if (TryGetComponent(eReplicaComponentType::ITEM, itemComponent)) { itemComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } InventoryComponent* inventoryComponent; - if (TryGetComponent(COMPONENT_TYPE_INVENTORY, inventoryComponent)) { + if (TryGetComponent(eReplicaComponentType::INVENTORY, inventoryComponent)) { inventoryComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } ScriptComponent* scriptComponent; - if (TryGetComponent(COMPONENT_TYPE_SCRIPT, scriptComponent)) { + if (TryGetComponent(eReplicaComponentType::SCRIPT, scriptComponent)) { scriptComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } SkillComponent* skillComponent; - if (TryGetComponent(COMPONENT_TYPE_SKILL, skillComponent)) { + if (TryGetComponent(eReplicaComponentType::SKILL, skillComponent)) { skillComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } BaseCombatAIComponent* baseCombatAiComponent; - if (TryGetComponent(COMPONENT_TYPE_BASE_COMBAT_AI, baseCombatAiComponent)) { + if (TryGetComponent(eReplicaComponentType::BASE_COMBAT_AI, baseCombatAiComponent)) { baseCombatAiComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } RebuildComponent* rebuildComponent; - if (TryGetComponent(COMPONENT_TYPE_REBUILD, rebuildComponent)) { + if (TryGetComponent(eReplicaComponentType::QUICK_BUILD, rebuildComponent)) { DestroyableComponent* destroyableComponent; - if (TryGetComponent(COMPONENT_TYPE_DESTROYABLE, destroyableComponent) && !destroyableSerialized) { + if (TryGetComponent(eReplicaComponentType::DESTROYABLE, destroyableComponent) && !destroyableSerialized) { destroyableComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } destroyableSerialized = true; @@ -1125,64 +1137,64 @@ void Entity::WriteComponents(RakNet::BitStream* outBitStream, eReplicaPacketType } MovingPlatformComponent* movingPlatformComponent; - if (TryGetComponent(COMPONENT_TYPE_MOVING_PLATFORM, movingPlatformComponent)) { + if (TryGetComponent(eReplicaComponentType::MOVING_PLATFORM, movingPlatformComponent)) { movingPlatformComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } SwitchComponent* switchComponent; - if (TryGetComponent(COMPONENT_TYPE_SWITCH, switchComponent)) { + if (TryGetComponent(eReplicaComponentType::SWITCH, switchComponent)) { switchComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } VendorComponent* vendorComponent; - if (TryGetComponent(COMPONENT_TYPE_VENDOR, vendorComponent)) { + if (TryGetComponent(eReplicaComponentType::VENDOR, vendorComponent)) { vendorComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } BouncerComponent* bouncerComponent; - if (TryGetComponent(COMPONENT_TYPE_BOUNCER, bouncerComponent)) { + if (TryGetComponent(eReplicaComponentType::BOUNCER, bouncerComponent)) { bouncerComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } ScriptedActivityComponent* scriptedActivityComponent; - if (TryGetComponent(COMPONENT_TYPE_SCRIPTED_ACTIVITY, scriptedActivityComponent)) { + if (TryGetComponent(eReplicaComponentType::SCRIPTED_ACTIVITY, scriptedActivityComponent)) { scriptedActivityComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } ShootingGalleryComponent* shootingGalleryComponent; - if (TryGetComponent(COMPONENT_TYPE_SHOOTING_GALLERY, shootingGalleryComponent)) { + if (TryGetComponent(eReplicaComponentType::SHOOTING_GALLERY, shootingGalleryComponent)) { shootingGalleryComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } RacingControlComponent* racingControlComponent; - if (TryGetComponent(COMPONENT_TYPE_RACING_CONTROL, racingControlComponent)) { + if (TryGetComponent(eReplicaComponentType::RACING_CONTROL, racingControlComponent)) { racingControlComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } LUPExhibitComponent* lupExhibitComponent; - if (TryGetComponent(COMPONENT_TYPE_EXHIBIT, lupExhibitComponent)) { + if (TryGetComponent(eReplicaComponentType::LUP_EXHIBIT, lupExhibitComponent)) { lupExhibitComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } ModelComponent* modelComponent; - if (TryGetComponent(COMPONENT_TYPE_MODEL, modelComponent)) { + if (TryGetComponent(eReplicaComponentType::MODEL, modelComponent)) { modelComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } RenderComponent* renderComponent; - if (TryGetComponent(COMPONENT_TYPE_RENDER, renderComponent)) { + if (TryGetComponent(eReplicaComponentType::RENDER, renderComponent)) { renderComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } if (modelComponent) { DestroyableComponent* destroyableComponent; - if (TryGetComponent(COMPONENT_TYPE_DESTROYABLE, destroyableComponent) && !destroyableSerialized) { + if (TryGetComponent(eReplicaComponentType::DESTROYABLE, destroyableComponent) && !destroyableSerialized) { destroyableComponent->Serialize(outBitStream, bIsInitialUpdate, flags); destroyableSerialized = true; } } - if (HasComponent(COMPONENT_TYPE_ZONE_CONTROL)) { + if (HasComponent(eReplicaComponentType::ZONE_CONTROL)) { outBitStream->Write(0x40000000); } @@ -1578,7 +1590,7 @@ void Entity::PickupItem(const LWOOBJID& objectID) { InventoryComponent* inv = GetComponent(); if (!inv) return; - CDObjectsTable* objectsTable = CDClientManager::Instance()->GetTable("Objects"); + CDObjectsTable* objectsTable = CDClientManager::Instance().GetTable(); auto& droppedLoot = static_cast(this)->GetDroppedLoot(); @@ -1591,10 +1603,10 @@ void Entity::PickupItem(const LWOOBJID& objectID) { const CDObjects& object = objectsTable->GetByID(p.second.lot); if (object.id != 0 && object.type == "Powerup") { - CDObjectSkillsTable* skillsTable = CDClientManager::Instance()->GetTable("ObjectSkills"); + CDObjectSkillsTable* skillsTable = CDClientManager::Instance().GetTable(); std::vector skills = skillsTable->Query([=](CDObjectSkills entry) {return (entry.objectTemplate == p.second.lot); }); for (CDObjectSkills skill : skills) { - CDSkillBehaviorTable* skillBehTable = CDClientManager::Instance()->GetTable("SkillBehavior"); + CDSkillBehaviorTable* skillBehTable = CDClientManager::Instance().GetTable(); CDSkillBehavior behaviorData = skillBehTable->GetSkillByID(skill.skillID); SkillComponent::HandleUnmanaged(behaviorData.behaviorID, GetObjectID()); diff --git a/dGame/Entity.h b/dGame/Entity.h index 0bde01e2..ae16fb82 100644 --- a/dGame/Entity.h +++ b/dGame/Entity.h @@ -31,6 +31,7 @@ class Item; class Character; class EntityCallbackTimer; enum class eTriggerEventType; +enum class eReplicaComponentType : uint32_t; namespace CppScripts { class Script; @@ -131,17 +132,17 @@ public: * Component management */ - Component* GetComponent(int32_t componentID) const; + Component* GetComponent(eReplicaComponentType componentID) const; template T* GetComponent() const; template - bool TryGetComponent(int32_t componentId, T*& component) const; + bool TryGetComponent(eReplicaComponentType componentId, T*& component) const; - bool HasComponent(int32_t componentId) const; + bool HasComponent(eReplicaComponentType componentId) const; - void AddComponent(int32_t componentId, Component* component); + void AddComponent(eReplicaComponentType componentId, Component* component); std::vector GetScriptComponents(); @@ -164,7 +165,7 @@ public: void AddToGroup(const std::string& group); bool IsPlayer() const; - std::unordered_map& GetComponents() { return m_Components; } // TODO: Remove + std::unordered_map& GetComponents() { return m_Components; } // TODO: Remove void WriteBaseReplicaData(RakNet::BitStream* outBitStream, eReplicaPacketType packetType); void WriteComponents(RakNet::BitStream* outBitStream, eReplicaPacketType packetType); @@ -314,7 +315,7 @@ protected: std::vector> m_DieCallbacks; std::vector> m_PhantomCollisionCallbacks; - std::unordered_map m_Components; //The int is the ID of the component + std::unordered_map m_Components; std::vector m_Timers; std::vector m_PendingTimers; std::vector m_CallbackTimers; @@ -344,7 +345,7 @@ protected: */ template -bool Entity::TryGetComponent(const int32_t componentId, T*& component) const { +bool Entity::TryGetComponent(const eReplicaComponentType componentId, T*& component) const { const auto& index = m_Components.find(componentId); if (index == m_Components.end()) { diff --git a/dGame/EntityManager.cpp b/dGame/EntityManager.cpp index dae27af6..e79ada25 100644 --- a/dGame/EntityManager.cpp +++ b/dGame/EntityManager.cpp @@ -20,6 +20,7 @@ #include "MessageIdentifiers.h" #include "dConfig.h" #include "eTriggerEventType.h" +#include "eReplicaComponentType.h" EntityManager* EntityManager::m_Address = nullptr; @@ -268,10 +269,10 @@ std::vector EntityManager::GetEntitiesInGroup(const std::string& group) return entitiesInGroup; } -std::vector EntityManager::GetEntitiesByComponent(const int componentType) const { +std::vector EntityManager::GetEntitiesByComponent(const eReplicaComponentType componentType) const { std::vector withComp; for (const auto& entity : m_Entities) { - if (componentType != -1 && !entity.second->HasComponent(componentType)) continue; + if (componentType != eReplicaComponentType::INVALID && !entity.second->HasComponent(componentType)) continue; withComp.push_back(entity.second); } diff --git a/dGame/EntityManager.h b/dGame/EntityManager.h index 8a930de3..0314cc09 100644 --- a/dGame/EntityManager.h +++ b/dGame/EntityManager.h @@ -11,6 +11,7 @@ class Entity; class EntityInfo; class Player; class User; +enum class eReplicaComponentType : uint32_t; struct SystemAddress; @@ -35,7 +36,7 @@ public: void DestroyEntity(Entity* entity); Entity* GetEntity(const LWOOBJID& objectId) const; std::vector GetEntitiesInGroup(const std::string& group); - std::vector GetEntitiesByComponent(int componentType) const; + std::vector GetEntitiesByComponent(eReplicaComponentType componentType) const; std::vector GetEntitiesByLOT(const LOT& lot) const; Entity* GetZoneControlEntity() const; diff --git a/dGame/LeaderboardManager.cpp b/dGame/LeaderboardManager.cpp index a0df940f..d85a95d4 100644 --- a/dGame/LeaderboardManager.cpp +++ b/dGame/LeaderboardManager.cpp @@ -8,6 +8,10 @@ #include "dLogger.h" #include "dConfig.h" #include "CDClientManager.h" +#include "GeneralUtils.h" +#include "Entity.h" + +#include "CDActivitiesTable.h" Leaderboard::Leaderboard(uint32_t gameID, uint32_t infoType, bool weekly, std::vector entries, LWOOBJID relatedPlayer, LeaderboardType leaderboardType) { @@ -273,7 +277,7 @@ void LeaderboardManager::SendLeaderboard(uint32_t gameID, InfoType infoType, boo } LeaderboardType LeaderboardManager::GetLeaderboardType(uint32_t gameID) { - auto* activitiesTable = CDClientManager::Instance()->GetTable("Activities"); + auto* activitiesTable = CDClientManager::Instance().GetTable(); std::vector activities = activitiesTable->Query([=](const CDActivities& entry) { return (entry.ActivityID == gameID); }); diff --git a/dGame/Player.cpp b/dGame/Player.cpp index 4f4bc951..2e194e6a 100644 --- a/dGame/Player.cpp +++ b/dGame/Player.cpp @@ -16,6 +16,7 @@ #include "User.h" #include "CppScripts.h" #include "Loot.h" +#include "eReplicaComponentType.h" std::vector Player::m_Players = {}; @@ -223,7 +224,7 @@ Player* Player::GetPlayer(const SystemAddress& sysAddr) { } Player* Player::GetPlayer(const std::string& name) { - const auto characters = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_CHARACTER); + const auto characters = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::CHARACTER); for (auto* character : characters) { if (!character->IsPlayer()) continue; @@ -289,7 +290,7 @@ Player::~Player() { script->OnPlayerExit(zoneControl, this); } - std::vector scriptedActs = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_SCRIPTED_ACTIVITY); + std::vector scriptedActs = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::SCRIPTED_ACTIVITY); for (Entity* scriptEntity : scriptedActs) { if (scriptEntity->GetObjectID() != zoneControl->GetObjectID()) { // Don't want to trigger twice on instance worlds for (CppScripts::Script* script : CppScripts::GetEntityScripts(scriptEntity)) { diff --git a/dGame/User.cpp b/dGame/User.cpp index 20cc3ab4..dc607cd0 100644 --- a/dGame/User.cpp +++ b/dGame/User.cpp @@ -5,6 +5,7 @@ #include "dLogger.h" #include "Game.h" #include "dZoneManager.h" +#include "eServerDisconnectIdentifiers.h" User::User(const SystemAddress& sysAddr, const std::string& username, const std::string& sessionKey) { m_AccountID = 0; @@ -126,6 +127,6 @@ void User::UserOutOfSync() { if (m_AmountOfTimesOutOfSync > m_MaxDesyncAllowed) { //YEET Game::logger->Log("User", "User %s was out of sync %i times out of %i, disconnecting for suspected speedhacking.", m_Username.c_str(), m_AmountOfTimesOutOfSync, m_MaxDesyncAllowed); - Game::server->Disconnect(this->m_SystemAddress, SERVER_DISCON_KICK); + Game::server->Disconnect(this->m_SystemAddress, eServerDisconnectIdentifiers::PLAY_SCHEDULE_TIME_DONE); } } diff --git a/dGame/dBehaviors/Behavior.cpp b/dGame/dBehaviors/Behavior.cpp index c8c1a1de..2a269ddc 100644 --- a/dGame/dBehaviors/Behavior.cpp +++ b/dGame/dBehaviors/Behavior.cpp @@ -73,13 +73,14 @@ #include "EntityManager.h" #include "RenderComponent.h" #include "DestroyableComponent.h" +#include "CDBehaviorTemplateTable.h" std::unordered_map Behavior::Cache = {}; CDBehaviorParameterTable* Behavior::BehaviorParameterTable = nullptr; Behavior* Behavior::GetBehavior(const uint32_t behaviorId) { if (BehaviorParameterTable == nullptr) { - BehaviorParameterTable = CDClientManager::Instance()->GetTable("BehaviorParameter"); + BehaviorParameterTable = CDClientManager::Instance().GetTable(); } const auto pair = Cache.find(behaviorId); @@ -290,7 +291,7 @@ Behavior* Behavior::CreateBehavior(const uint32_t behaviorId) { } BehaviorTemplates Behavior::GetBehaviorTemplate(const uint32_t behaviorId) { - auto behaviorTemplateTable = CDClientManager::Instance()->GetTable("BehaviorTemplate"); + auto behaviorTemplateTable = CDClientManager::Instance().GetTable(); BehaviorTemplates templateID = BehaviorTemplates::BEHAVIOR_EMPTY; // Find behavior template by its behavior id. Default to 0. @@ -398,7 +399,7 @@ void Behavior::PlayFx(std::u16string type, const LWOOBJID target, const LWOOBJID } Behavior::Behavior(const uint32_t behaviorId) { - auto behaviorTemplateTable = CDClientManager::Instance()->GetTable("BehaviorTemplate"); + auto behaviorTemplateTable = CDClientManager::Instance().GetTable(); CDBehaviorTemplate templateInDatabase{}; @@ -441,7 +442,7 @@ Behavior::Behavior(const uint32_t behaviorId) { float Behavior::GetFloat(const std::string& name, const float defaultValue) const { // Get the behavior parameter entry and return its value. - if (!BehaviorParameterTable) BehaviorParameterTable = CDClientManager::Instance()->GetTable("BehaviorParameter"); + if (!BehaviorParameterTable) BehaviorParameterTable = CDClientManager::Instance().GetTable(); return BehaviorParameterTable->GetValue(this->m_behaviorId, name, defaultValue); } @@ -469,7 +470,7 @@ Behavior* Behavior::GetAction(float value) const { std::map Behavior::GetParameterNames() const { std::map templatesInDatabase; // Find behavior template by its behavior id. - if (!BehaviorParameterTable) BehaviorParameterTable = CDClientManager::Instance()->GetTable("BehaviorParameter"); + if (!BehaviorParameterTable) BehaviorParameterTable = CDClientManager::Instance().GetTable(); if (BehaviorParameterTable) { templatesInDatabase = BehaviorParameterTable->GetParametersByBehaviorID(this->m_behaviorId); } diff --git a/dGame/dBehaviors/BehaviorContext.cpp b/dGame/dBehaviors/BehaviorContext.cpp index 26d1e9e6..397e0c72 100644 --- a/dGame/dBehaviors/BehaviorContext.cpp +++ b/dGame/dBehaviors/BehaviorContext.cpp @@ -15,6 +15,7 @@ #include "EchoSyncSkill.h" #include "PhantomPhysicsComponent.h" #include "RebuildComponent.h" +#include "eReplicaComponentType.h" BehaviorSyncEntry::BehaviorSyncEntry() { } @@ -311,13 +312,13 @@ std::vector BehaviorContext::GetValidTargets(int32_t ignoreFaction, in } } - if (ignoreFaction || includeFaction || (!entity->HasComponent(COMPONENT_TYPE_PHANTOM_PHYSICS) && targets.empty())) { + if (ignoreFaction || includeFaction || (!entity->HasComponent(eReplicaComponentType::PHANTOM_PHYSICS) && targets.empty())) { DestroyableComponent* destroyableComponent; - if (!entity->TryGetComponent(COMPONENT_TYPE_DESTROYABLE, destroyableComponent)) { + if (!entity->TryGetComponent(eReplicaComponentType::DESTROYABLE, destroyableComponent)) { return targets; } - auto entities = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS); + auto entities = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::CONTROLLABLE_PHYSICS); for (auto* candidate : entities) { const auto id = candidate->GetObjectID(); diff --git a/dGame/dBehaviors/HealBehavior.cpp b/dGame/dBehaviors/HealBehavior.cpp index 2799d2e2..66fe2c79 100644 --- a/dGame/dBehaviors/HealBehavior.cpp +++ b/dGame/dBehaviors/HealBehavior.cpp @@ -4,6 +4,7 @@ #include "dLogger.h" #include "EntityManager.h" #include "DestroyableComponent.h" +#include "eReplicaComponentType.h" void HealBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch) { @@ -15,7 +16,7 @@ void HealBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_strea return; } - auto* destroyable = static_cast(entity->GetComponent(COMPONENT_TYPE_DESTROYABLE)); + auto* destroyable = static_cast(entity->GetComponent(eReplicaComponentType::DESTROYABLE)); if (destroyable == nullptr) { Game::logger->Log("HealBehavior", "Failed to find destroyable component for %(llu)!", branch.target); diff --git a/dGame/dBehaviors/OverTimeBehavior.cpp b/dGame/dBehaviors/OverTimeBehavior.cpp index 20dd89af..5afbbd26 100644 --- a/dGame/dBehaviors/OverTimeBehavior.cpp +++ b/dGame/dBehaviors/OverTimeBehavior.cpp @@ -9,6 +9,8 @@ #include "CDClientDatabase.h" #include "CDClientManager.h" +#include "CDSkillBehaviorTable.h" + void OverTimeBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) { const auto originator = context->originator; @@ -39,7 +41,7 @@ void OverTimeBehavior::Load() { m_Action = GetInt("action"); // Since m_Action is a skillID and not a behavior, get is correlated behaviorID. - CDSkillBehaviorTable* skillTable = CDClientManager::Instance()->GetTable("SkillBehavior"); + CDSkillBehaviorTable* skillTable = CDClientManager::Instance().GetTable(); m_ActionBehaviorId = skillTable->GetSkillByID(m_Action).behaviorID; m_Delay = GetFloat("delay"); diff --git a/dGame/dBehaviors/RepairBehavior.cpp b/dGame/dBehaviors/RepairBehavior.cpp index a48141d3..ce2e5fd2 100644 --- a/dGame/dBehaviors/RepairBehavior.cpp +++ b/dGame/dBehaviors/RepairBehavior.cpp @@ -5,6 +5,7 @@ #include "EntityManager.h" #include "dLogger.h" #include "Game.h" +#include "eReplicaComponentType.h" void RepairBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch) { auto* entity = EntityManager::Instance()->GetEntity(branch.target); @@ -15,7 +16,7 @@ void RepairBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_str return; } - auto* destroyable = static_cast(entity->GetComponent(COMPONENT_TYPE_DESTROYABLE)); + auto* destroyable = static_cast(entity->GetComponent(eReplicaComponentType::DESTROYABLE)); if (destroyable == nullptr) { Game::logger->Log("RepairBehavior", "Failed to find destroyable component for %(llu)!", branch.target); diff --git a/dGame/dBehaviors/SpawnBehavior.cpp b/dGame/dBehaviors/SpawnBehavior.cpp index 8b2020b1..75c84f6c 100644 --- a/dGame/dBehaviors/SpawnBehavior.cpp +++ b/dGame/dBehaviors/SpawnBehavior.cpp @@ -9,6 +9,7 @@ #include "RebuildComponent.h" #include "Entity.h" #include "EntityInfo.h" +#include "eReplicaComponentType.h" void SpawnBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) { auto* origin = EntityManager::Instance()->GetEntity(context->originator); @@ -86,7 +87,7 @@ void SpawnBehavior::Timer(BehaviorContext* context, const BehaviorBranchContext return; } - auto* destroyable = static_cast(entity->GetComponent(COMPONENT_TYPE_DESTROYABLE)); + auto* destroyable = static_cast(entity->GetComponent(eReplicaComponentType::DESTROYABLE)); if (destroyable == nullptr) { entity->Smash(context->originator); diff --git a/dGame/dBehaviors/StunBehavior.cpp b/dGame/dBehaviors/StunBehavior.cpp index 065b7220..4e34d3a2 100644 --- a/dGame/dBehaviors/StunBehavior.cpp +++ b/dGame/dBehaviors/StunBehavior.cpp @@ -7,6 +7,7 @@ #include "Game.h" #include "dLogger.h" #include "DestroyableComponent.h" +#include "eReplicaComponentType.h" void StunBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) { @@ -32,7 +33,7 @@ void StunBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream * If our target is an enemy we can go ahead and stun it. */ - auto* combatAiComponent = static_cast(target->GetComponent(COMPONENT_TYPE_BASE_COMBAT_AI)); + auto* combatAiComponent = static_cast(target->GetComponent(eReplicaComponentType::BASE_COMBAT_AI)); if (combatAiComponent == nullptr) { return; @@ -55,7 +56,7 @@ void StunBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStr * See if we can stun ourselves */ - auto* combatAiComponent = static_cast(self->GetComponent(COMPONENT_TYPE_BASE_COMBAT_AI)); + auto* combatAiComponent = static_cast(self->GetComponent(eReplicaComponentType::BASE_COMBAT_AI)); if (combatAiComponent == nullptr) { return; @@ -90,7 +91,7 @@ void StunBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStr * If our target is an enemy we can go ahead and stun it. */ - auto* combatAiComponent = static_cast(target->GetComponent(COMPONENT_TYPE_BASE_COMBAT_AI)); + auto* combatAiComponent = static_cast(target->GetComponent(eReplicaComponentType::BASE_COMBAT_AI)); if (combatAiComponent == nullptr) { return; diff --git a/dGame/dComponents/BaseCombatAIComponent.cpp b/dGame/dComponents/BaseCombatAIComponent.cpp index 081496a4..64c739f5 100644 --- a/dGame/dComponents/BaseCombatAIComponent.cpp +++ b/dGame/dComponents/BaseCombatAIComponent.cpp @@ -22,6 +22,9 @@ #include "SkillComponent.h" #include "RebuildComponent.h" #include "DestroyableComponent.h" +#include "Metrics.hpp" +#include "CDComponentsRegistryTable.h" +#include "CDPhysicsComponentTable.h" BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id): Component(parent) { m_Target = LWOOBJID_EMPTY; @@ -104,10 +107,10 @@ BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id): int32_t collisionGroup = (COLLISION_GROUP_DYNAMIC | COLLISION_GROUP_ENEMY); - CDComponentsRegistryTable* componentRegistryTable = CDClientManager::Instance()->GetTable("ComponentsRegistry"); - auto componentID = componentRegistryTable->GetByIDAndType(parent->GetLOT(), COMPONENT_TYPE_CONTROLLABLE_PHYSICS); + CDComponentsRegistryTable* componentRegistryTable = CDClientManager::Instance().GetTable(); + auto componentID = componentRegistryTable->GetByIDAndType(parent->GetLOT(), eReplicaComponentType::CONTROLLABLE_PHYSICS); - CDPhysicsComponentTable* physicsComponentTable = CDClientManager::Instance()->GetTable("PhysicsComponent"); + CDPhysicsComponentTable* physicsComponentTable = CDClientManager::Instance().GetTable(); if (physicsComponentTable != nullptr) { auto* info = physicsComponentTable->GetByID(componentID); @@ -228,6 +231,18 @@ void BaseCombatAIComponent::Update(const float deltaTime) { void BaseCombatAIComponent::CalculateCombat(const float deltaTime) { + bool hasSkillToCast = false; + for (auto& entry : m_SkillEntries) { + if (entry.cooldown > 0.0f) { + entry.cooldown -= deltaTime; + } else { + hasSkillToCast = true; + } + } + + bool hadRemainingDowntime = m_SkillTime > 0.0f; + if (m_SkillTime > 0.0f) m_SkillTime -= deltaTime; + auto* rebuild = m_Parent->GetComponent(); if (rebuild != nullptr) { @@ -258,9 +273,7 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) { m_Stunned = false; } - if (m_Stunned) { - return; - } + if (m_Stunned || hadRemainingDowntime) return; auto newTarget = FindTarget(); @@ -325,27 +338,7 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) { SetAiState(AiState::idle); } - for (auto i = 0; i < m_SkillEntries.size(); ++i) { - auto entry = m_SkillEntries.at(i); - - if (entry.cooldown > 0) { - entry.cooldown -= deltaTime; - - m_SkillEntries[i] = entry; - } - } - - if (m_SkillTime > 0) { - m_SkillTime -= deltaTime; - - return; - } - - if (m_Downtime > 0) { - m_Downtime -= deltaTime; - - return; - } + if (!hasSkillToCast) return; if (m_Target == LWOOBJID_EMPTY) { SetAiState(AiState::idle); @@ -353,8 +346,6 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) { return; } - m_Downtime = 0.5f; - auto* target = GetTargetEntity(); if (target != nullptr) { diff --git a/dGame/dComponents/BaseCombatAIComponent.h b/dGame/dComponents/BaseCombatAIComponent.h index 1f17d562..8bf6140a 100644 --- a/dGame/dComponents/BaseCombatAIComponent.h +++ b/dGame/dComponents/BaseCombatAIComponent.h @@ -8,6 +8,7 @@ #include "dpWorld.h" #include "dpEntity.h" #include "Component.h" +#include "eReplicaComponentType.h" #include #include @@ -46,7 +47,7 @@ struct AiSkillEntry */ class BaseCombatAIComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_BASE_COMBAT_AI; + static const eReplicaComponentType ComponentType = eReplicaComponentType::BASE_COMBAT_AI; BaseCombatAIComponent(Entity* parentEntity, uint32_t id); ~BaseCombatAIComponent() override; @@ -245,7 +246,7 @@ private: /** * @brief Sets the AiState and prepares the entity for serialization next frame. - * + * */ void SetAiState(AiState newState); @@ -340,11 +341,6 @@ private: */ bool m_StunImmune = false; - /** - * Time taken between actions - */ - float m_Downtime = 0; - /** * How long this entity needs to execute its skill */ @@ -382,7 +378,7 @@ private: /** * Whether or not the Component has dirty information and should update next frame - * + * */ bool m_DirtyStateOrTarget = false; diff --git a/dGame/dComponents/BouncerComponent.h b/dGame/dComponents/BouncerComponent.h index f179998b..15665cc1 100644 --- a/dGame/dComponents/BouncerComponent.h +++ b/dGame/dComponents/BouncerComponent.h @@ -5,13 +5,14 @@ #include "RakNetTypes.h" #include "Entity.h" #include "Component.h" +#include "eReplicaComponentType.h" /** * Attached to bouncer entities, allowing other entities to bounce off of it */ class BouncerComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_BOUNCER; + static const eReplicaComponentType ComponentType = eReplicaComponentType::BOUNCER; BouncerComponent(Entity* parentEntity); ~BouncerComponent() override; diff --git a/dGame/dComponents/BuffComponent.cpp b/dGame/dComponents/BuffComponent.cpp index 974d0bd2..68b5182c 100644 --- a/dGame/dComponents/BuffComponent.cpp +++ b/dGame/dComponents/BuffComponent.cpp @@ -10,6 +10,7 @@ #include "ControllablePhysicsComponent.h" #include "EntityManager.h" #include "CDClientManager.h" +#include "CDSkillBehaviorTable.h" std::unordered_map> BuffComponent::m_Cache{}; @@ -101,7 +102,7 @@ void BuffComponent::ApplyBuff(const int32_t id, const float duration, const LWOO const auto& parameters = GetBuffParameters(id); for (const auto& parameter : parameters) { if (parameter.name == "overtime") { - auto* behaviorTemplateTable = CDClientManager::Instance()->GetTable("SkillBehavior"); + auto* behaviorTemplateTable = CDClientManager::Instance().GetTable(); behaviorID = behaviorTemplateTable->GetSkillByID(parameter.values[0]).behaviorID; stacks = static_cast(parameter.values[1]); diff --git a/dGame/dComponents/BuffComponent.h b/dGame/dComponents/BuffComponent.h index 7f7c6b0f..d9175883 100644 --- a/dGame/dComponents/BuffComponent.h +++ b/dGame/dComponents/BuffComponent.h @@ -7,6 +7,7 @@ #include #include #include "Component.h" +#include "eReplicaComponentType.h" class Entity; @@ -41,7 +42,7 @@ struct Buff */ class BuffComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_BUFF; + static const eReplicaComponentType ComponentType = eReplicaComponentType::BUFF; explicit BuffComponent(Entity* parent); diff --git a/dGame/dComponents/BuildBorderComponent.h b/dGame/dComponents/BuildBorderComponent.h index ba677e37..dc5afc8a 100644 --- a/dGame/dComponents/BuildBorderComponent.h +++ b/dGame/dComponents/BuildBorderComponent.h @@ -9,13 +9,14 @@ #include "BitStream.h" #include "Entity.h" #include "Component.h" +#include "eReplicaComponentType.h" /** * Component for the build border, allowing the user to start building when interacting with it */ class BuildBorderComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_BUILD_BORDER; + static const eReplicaComponentType ComponentType = eReplicaComponentType::BUILD_BORDER; BuildBorderComponent(Entity* parent); ~BuildBorderComponent() override; diff --git a/dGame/dComponents/CharacterComponent.h b/dGame/dComponents/CharacterComponent.h index 196dfa01..613f2322 100644 --- a/dGame/dComponents/CharacterComponent.h +++ b/dGame/dComponents/CharacterComponent.h @@ -9,6 +9,7 @@ #include #include "CDMissionsTable.h" #include "tinyxml2.h" +#include "eReplicaComponentType.h" /** * The statistics that can be achieved per zone @@ -59,7 +60,7 @@ enum StatisticID { */ class CharacterComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_CHARACTER; + static const eReplicaComponentType ComponentType = eReplicaComponentType::CHARACTER; CharacterComponent(Entity* parent, Character* character); ~CharacterComponent() override; diff --git a/dGame/dComponents/ControllablePhysicsComponent.h b/dGame/dComponents/ControllablePhysicsComponent.h index a05a11fd..a7359a26 100644 --- a/dGame/dComponents/ControllablePhysicsComponent.h +++ b/dGame/dComponents/ControllablePhysicsComponent.h @@ -10,6 +10,7 @@ #include "dpCollisionChecks.h" #include "PhantomPhysicsComponent.h" #include "eBubbleType.h" +#include "eReplicaComponentType.h" class Entity; class dpEntity; @@ -19,7 +20,7 @@ class dpEntity; */ class ControllablePhysicsComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_CONTROLLABLE_PHYSICS; + static const eReplicaComponentType ComponentType = eReplicaComponentType::CONTROLLABLE_PHYSICS; ControllablePhysicsComponent(Entity* entity); ~ControllablePhysicsComponent() override; diff --git a/dGame/dComponents/DestroyableComponent.cpp b/dGame/dComponents/DestroyableComponent.cpp index 4763c863..c2d72941 100644 --- a/dGame/dComponents/DestroyableComponent.cpp +++ b/dGame/dComponents/DestroyableComponent.cpp @@ -34,6 +34,8 @@ #include "WorldConfig.h" #include "eMissionTaskType.h" +#include "CDComponentsRegistryTable.h" + DestroyableComponent::DestroyableComponent(Entity* parent) : Component(parent) { m_iArmor = 0; m_fMaxArmor = 0.0f; @@ -74,18 +76,18 @@ DestroyableComponent::~DestroyableComponent() { } void DestroyableComponent::Reinitialize(LOT templateID) { - CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance()->GetTable("ComponentsRegistry"); + CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance().GetTable(); - int32_t buffComponentID = compRegistryTable->GetByIDAndType(templateID, COMPONENT_TYPE_BUFF); - int32_t collectibleComponentID = compRegistryTable->GetByIDAndType(templateID, COMPONENT_TYPE_COLLECTIBLE); - int32_t rebuildComponentID = compRegistryTable->GetByIDAndType(templateID, COMPONENT_TYPE_REBUILD); + int32_t buffComponentID = compRegistryTable->GetByIDAndType(templateID, eReplicaComponentType::BUFF); + int32_t collectibleComponentID = compRegistryTable->GetByIDAndType(templateID, eReplicaComponentType::COLLECTIBLE); + int32_t rebuildComponentID = compRegistryTable->GetByIDAndType(templateID, eReplicaComponentType::QUICK_BUILD); int32_t componentID = 0; if (collectibleComponentID > 0) componentID = collectibleComponentID; if (rebuildComponentID > 0) componentID = rebuildComponentID; if (buffComponentID > 0) componentID = buffComponentID; - CDDestructibleComponentTable* destCompTable = CDClientManager::Instance()->GetTable("DestructibleComponent"); + CDDestructibleComponentTable* destCompTable = CDClientManager::Instance().GetTable(); std::vector destCompData = destCompTable->Query([=](CDDestructibleComponent entry) { return (entry.id == componentID); }); if (componentID > 0) { @@ -810,7 +812,7 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType script->OnPlayerDied(zoneControl, m_Parent); } - std::vector scriptedActs = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_SCRIPTED_ACTIVITY); + std::vector scriptedActs = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::SCRIPTED_ACTIVITY); for (Entity* scriptEntity : scriptedActs) { if (scriptEntity->GetObjectID() != zoneControl->GetObjectID()) { // Don't want to trigger twice on instance worlds for (CppScripts::Script* script : CppScripts::GetEntityScripts(scriptEntity)) { diff --git a/dGame/dComponents/DestroyableComponent.h b/dGame/dComponents/DestroyableComponent.h index 854144d9..47be96a0 100644 --- a/dGame/dComponents/DestroyableComponent.h +++ b/dGame/dComponents/DestroyableComponent.h @@ -6,6 +6,7 @@ #include "tinyxml2.h" #include "Entity.h" #include "Component.h" +#include "eReplicaComponentType.h" namespace CppScripts { class Script; @@ -17,7 +18,7 @@ namespace CppScripts { */ class DestroyableComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_DESTROYABLE; + static const eReplicaComponentType ComponentType = eReplicaComponentType::DESTROYABLE; DestroyableComponent(Entity* parentEntity); ~DestroyableComponent() override; diff --git a/dGame/dComponents/InventoryComponent.cpp b/dGame/dComponents/InventoryComponent.cpp index 8925554e..dc8fdbdc 100644 --- a/dGame/dComponents/InventoryComponent.cpp +++ b/dGame/dComponents/InventoryComponent.cpp @@ -30,6 +30,12 @@ #include "CppScripts.h" #include "eMissionTaskType.h" +#include "CDComponentsRegistryTable.h" +#include "CDInventoryComponentTable.h" +#include "CDScriptComponentTable.h" +#include "CDObjectSkillsTable.h" +#include "CDSkillBehaviorTable.h" + InventoryComponent::InventoryComponent(Entity* parent, tinyxml2::XMLDocument* document): Component(parent) { this->m_Dirty = true; this->m_Equipped = {}; @@ -47,10 +53,10 @@ InventoryComponent::InventoryComponent(Entity* parent, tinyxml2::XMLDocument* do return; } - auto* compRegistryTable = CDClientManager::Instance()->GetTable("ComponentsRegistry"); - const auto componentId = compRegistryTable->GetByIDAndType(lot, COMPONENT_TYPE_INVENTORY); + auto* compRegistryTable = CDClientManager::Instance().GetTable(); + const auto componentId = compRegistryTable->GetByIDAndType(lot, eReplicaComponentType::INVENTORY); - auto* inventoryComponentTable = CDClientManager::Instance()->GetTable("InventoryComponent"); + auto* inventoryComponentTable = CDClientManager::Instance().GetTable(); auto items = inventoryComponentTable->Query([=](const CDInventoryComponent entry) { return entry.id == componentId; }); auto slot = 0u; @@ -181,7 +187,7 @@ void InventoryComponent::AddItem( inventoryType = Inventory::FindInventoryTypeForLot(lot); } - auto* missions = static_cast(this->m_Parent->GetComponent(COMPONENT_TYPE_MISSION)); + auto* missions = static_cast(this->m_Parent->GetComponent(eReplicaComponentType::MISSION)); auto* inventory = GetInventory(inventoryType); @@ -818,7 +824,7 @@ void InventoryComponent::EquipItem(Item* item, const bool skipChecks) { if (character != nullptr && !skipChecks) { // Hacky proximity rocket if (item->GetLot() == 6416) { - const auto rocketLauchPads = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_ROCKET_LAUNCH); + const auto rocketLauchPads = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::ROCKET_LAUNCH); const auto position = m_Parent->GetPosition(); @@ -912,11 +918,11 @@ void InventoryComponent::UnEquipItem(Item* item) { void InventoryComponent::EquipScripts(Item* equippedItem) { - CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance()->GetTable("ComponentsRegistry"); + CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance().GetTable(); if (!compRegistryTable) return; - int32_t scriptComponentID = compRegistryTable->GetByIDAndType(equippedItem->GetLot(), COMPONENT_TYPE_SCRIPT, -1); + int32_t scriptComponentID = compRegistryTable->GetByIDAndType(equippedItem->GetLot(), eReplicaComponentType::SCRIPT, -1); if (scriptComponentID > -1) { - CDScriptComponentTable* scriptCompTable = CDClientManager::Instance()->GetTable("ScriptComponent"); + CDScriptComponentTable* scriptCompTable = CDClientManager::Instance().GetTable(); CDScriptComponent scriptCompData = scriptCompTable->GetByID(scriptComponentID); auto* itemScript = CppScripts::GetScript(m_Parent, scriptCompData.script_name); if (!itemScript) { @@ -927,11 +933,11 @@ void InventoryComponent::EquipScripts(Item* equippedItem) { } void InventoryComponent::UnequipScripts(Item* unequippedItem) { - CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance()->GetTable("ComponentsRegistry"); + CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance().GetTable(); if (!compRegistryTable) return; - int32_t scriptComponentID = compRegistryTable->GetByIDAndType(unequippedItem->GetLot(), COMPONENT_TYPE_SCRIPT, -1); + int32_t scriptComponentID = compRegistryTable->GetByIDAndType(unequippedItem->GetLot(), eReplicaComponentType::SCRIPT, -1); if (scriptComponentID > -1) { - CDScriptComponentTable* scriptCompTable = CDClientManager::Instance()->GetTable("ScriptComponent"); + CDScriptComponentTable* scriptCompTable = CDClientManager::Instance().GetTable(); CDScriptComponent scriptCompData = scriptCompTable->GetByID(scriptComponentID); auto* itemScript = CppScripts::GetScript(m_Parent, scriptCompData.script_name); if (!itemScript) { @@ -1306,7 +1312,7 @@ bool InventoryComponent::IsTransferInventory(eInventoryType type) { } uint32_t InventoryComponent::FindSkill(const LOT lot) { - auto* table = CDClientManager::Instance()->GetTable("ObjectSkills"); + auto* table = CDClientManager::Instance().GetTable(); const auto results = table->Query([=](const CDObjectSkills& entry) { return entry.objectTemplate == static_cast(lot); @@ -1324,14 +1330,14 @@ uint32_t InventoryComponent::FindSkill(const LOT lot) { std::vector InventoryComponent::FindBuffs(Item* item, bool castOnEquip) const { std::vector buffs; if (item == nullptr) return buffs; - auto* table = CDClientManager::Instance()->GetTable("ObjectSkills"); - auto* behaviors = CDClientManager::Instance()->GetTable("SkillBehavior"); + auto* table = CDClientManager::Instance().GetTable(); + auto* behaviors = CDClientManager::Instance().GetTable(); const auto results = table->Query([=](const CDObjectSkills& entry) { return entry.objectTemplate == static_cast(item->GetLot()); }); - auto* missions = static_cast(m_Parent->GetComponent(COMPONENT_TYPE_MISSION)); + auto* missions = static_cast(m_Parent->GetComponent(eReplicaComponentType::MISSION)); for (const auto& result : results) { if (result.castOnType == 1) { diff --git a/dGame/dComponents/InventoryComponent.h b/dGame/dComponents/InventoryComponent.h index b660de15..d695737c 100644 --- a/dGame/dComponents/InventoryComponent.h +++ b/dGame/dComponents/InventoryComponent.h @@ -20,6 +20,7 @@ #include "eItemSetPassiveAbilityID.h" #include "PossessorComponent.h" #include "eInventoryType.h" +#include "eReplicaComponentType.h" class Entity; class ItemSet; @@ -36,7 +37,7 @@ enum class eItemType : int32_t; class InventoryComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_INVENTORY; + static const eReplicaComponentType ComponentType = eReplicaComponentType::INVENTORY; explicit InventoryComponent(Entity* parent, tinyxml2::XMLDocument* document = nullptr); void Update(float deltaTime) override; diff --git a/dGame/dComponents/LUPExhibitComponent.h b/dGame/dComponents/LUPExhibitComponent.h index 2d128f6c..587d1b2f 100644 --- a/dGame/dComponents/LUPExhibitComponent.h +++ b/dGame/dComponents/LUPExhibitComponent.h @@ -2,6 +2,7 @@ #include "Component.h" #include "Entity.h" +#include "eReplicaComponentType.h" /** * Component that handles the LOT that is shown in the LUP exhibit in the LUP world. Works by setting a timer and @@ -10,7 +11,7 @@ class LUPExhibitComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_EXHIBIT; + static const eReplicaComponentType ComponentType = eReplicaComponentType::EXHIBIT; LUPExhibitComponent(Entity* parent); ~LUPExhibitComponent(); diff --git a/dGame/dComponents/LevelProgressionComponent.cpp b/dGame/dComponents/LevelProgressionComponent.cpp index 6e6b823e..814a7a86 100644 --- a/dGame/dComponents/LevelProgressionComponent.cpp +++ b/dGame/dComponents/LevelProgressionComponent.cpp @@ -4,6 +4,8 @@ #include "CharacterComponent.h" #include "tinyxml2.h" +#include "CDRewardsTable.h" + LevelProgressionComponent::LevelProgressionComponent(Entity* parent) : Component(parent) { m_Parent = parent; m_Level = 1; @@ -42,7 +44,7 @@ void LevelProgressionComponent::Serialize(RakNet::BitStream* outBitStream, bool } void LevelProgressionComponent::HandleLevelUp() { - auto* rewardsTable = CDClientManager::Instance()->GetTable("Rewards"); + auto* rewardsTable = CDClientManager::Instance().GetTable(); const auto& rewards = rewardsTable->GetByLevelID(m_Level); bool rewardingItem = rewards.size() > 0; diff --git a/dGame/dComponents/LevelProgressionComponent.h b/dGame/dComponents/LevelProgressionComponent.h index dd3fbfbb..06908a81 100644 --- a/dGame/dComponents/LevelProgressionComponent.h +++ b/dGame/dComponents/LevelProgressionComponent.h @@ -4,6 +4,7 @@ #include "GameMessages.h" #include "Component.h" #include "eCharacterVersion.h" +#include "eReplicaComponentType.h" /** * Component that handles level progression and serilization. @@ -12,7 +13,7 @@ class LevelProgressionComponent : public Component { public: - static const uint32_t ComponentType = eReplicaComponentType::COMPONENT_TYPE_LEVEL_PROGRESSION; + static const eReplicaComponentType ComponentType = eReplicaComponentType::LEVEL_PROGRESSION; /** * Constructor for this component diff --git a/dGame/dComponents/MissionComponent.cpp b/dGame/dComponents/MissionComponent.cpp index cbae7f9f..0ae0f07e 100644 --- a/dGame/dComponents/MissionComponent.cpp +++ b/dGame/dComponents/MissionComponent.cpp @@ -265,7 +265,7 @@ void MissionComponent::ForceProgressValue(uint32_t missionId, uint32_t taskType, } bool MissionComponent::GetMissionInfo(uint32_t missionId, CDMissions& result) { - auto* missionsTable = CDClientManager::Instance()->GetTable("Missions"); + auto* missionsTable = CDClientManager::Instance().GetTable(); const auto missions = missionsTable->Query([=](const CDMissions& entry) { return entry.id == static_cast(missionId); @@ -319,8 +319,8 @@ bool MissionComponent::LookForAchievements(eMissionTaskType type, int32_t value, return any; #else - auto* missionTasksTable = CDClientManager::Instance()->GetTable("MissionTasks"); - auto* missionsTable = CDClientManager::Instance()->GetTable("Missions"); + auto* missionTasksTable = CDClientManager::Instance().GetTable(); + auto* missionsTable = CDClientManager::Instance().GetTable(); auto tasks = missionTasksTable->Query([=](const CDMissionTasks& entry) { return entry.taskType == static_cast(type); @@ -406,8 +406,8 @@ const std::vector& MissionComponent::QueryAchievements(eMissionTaskTyp } // Find relevent tables - auto* missionTasksTable = CDClientManager::Instance()->GetTable("MissionTasks"); - auto* missionsTable = CDClientManager::Instance()->GetTable("Missions"); + auto* missionTasksTable = CDClientManager::Instance().GetTable(); + auto* missionsTable = CDClientManager::Instance().GetTable(); std::vector result; diff --git a/dGame/dComponents/MissionComponent.h b/dGame/dComponents/MissionComponent.h index 231b3321..eeaaa726 100644 --- a/dGame/dComponents/MissionComponent.h +++ b/dGame/dComponents/MissionComponent.h @@ -16,6 +16,7 @@ #include "CDClientManager.h" #include "CDMissionsTable.h" #include "Component.h" +#include "eReplicaComponentType.h" class AchievementCacheKey; @@ -26,7 +27,7 @@ class AchievementCacheKey; class MissionComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_MISSION; + static const eReplicaComponentType ComponentType = eReplicaComponentType::MISSION; explicit MissionComponent(Entity* parent); ~MissionComponent() override; diff --git a/dGame/dComponents/MissionOfferComponent.cpp b/dGame/dComponents/MissionOfferComponent.cpp index f8446868..e4c94ebd 100644 --- a/dGame/dComponents/MissionOfferComponent.cpp +++ b/dGame/dComponents/MissionOfferComponent.cpp @@ -16,6 +16,8 @@ #include "MissionPrerequisites.h" #include "eMissionState.h" +#include "CDComponentsRegistryTable.h" + OfferedMission::OfferedMission(const uint32_t missionId, const bool offersMission, const bool acceptsMission) { this->missionId = missionId; this->offersMission = offersMission; @@ -38,15 +40,15 @@ bool OfferedMission::GetAcceptMission() const { //------------------------ MissionOfferComponent below ------------------------ MissionOfferComponent::MissionOfferComponent(Entity* parent, const LOT parentLot) : Component(parent) { - auto* compRegistryTable = CDClientManager::Instance()->GetTable("ComponentsRegistry"); + auto* compRegistryTable = CDClientManager::Instance().GetTable(); - auto value = compRegistryTable->GetByIDAndType(parentLot, COMPONENT_TYPE_MISSION_OFFER, -1); + auto value = compRegistryTable->GetByIDAndType(parentLot, eReplicaComponentType::MISSION_OFFER, -1); if (value != -1) { const uint32_t componentId = value; // Now lookup the missions in the MissionNPCComponent table - auto* missionNpcComponentTable = CDClientManager::Instance()->GetTable("MissionNPCComponent"); + auto* missionNpcComponentTable = CDClientManager::Instance().GetTable(); auto missions = missionNpcComponentTable->Query([=](const CDMissionNPCComponent& entry) { return entry.id == static_cast(componentId); @@ -77,7 +79,7 @@ void MissionOfferComponent::OnUse(Entity* originator) { void MissionOfferComponent::OfferMissions(Entity* entity, const uint32_t specifiedMissionId) { // First, get the entity's MissionComponent. If there is not one, then we cannot offer missions to this entity. - auto* missionComponent = static_cast(entity->GetComponent(COMPONENT_TYPE_MISSION)); + auto* missionComponent = static_cast(entity->GetComponent(eReplicaComponentType::MISSION)); if (!missionComponent) { Game::logger->Log("MissionOfferComponent", "Unable to get mission component for Entity %llu", entity->GetObjectID()); diff --git a/dGame/dComponents/MissionOfferComponent.h b/dGame/dComponents/MissionOfferComponent.h index 42aad3c4..6e22ca05 100644 --- a/dGame/dComponents/MissionOfferComponent.h +++ b/dGame/dComponents/MissionOfferComponent.h @@ -10,6 +10,7 @@ #include "Component.h" #include #include +#include "eReplicaComponentType.h" class Entity; @@ -60,7 +61,7 @@ private: */ class MissionOfferComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_MISSION_OFFER; + static const eReplicaComponentType ComponentType = eReplicaComponentType::MISSION_OFFER; MissionOfferComponent(Entity* parent, LOT parentLot); ~MissionOfferComponent() override; diff --git a/dGame/dComponents/ModelComponent.h b/dGame/dComponents/ModelComponent.h index 8f491168..08e2e47e 100644 --- a/dGame/dComponents/ModelComponent.h +++ b/dGame/dComponents/ModelComponent.h @@ -4,6 +4,7 @@ #include "NiPoint3.h" #include "NiQuaternion.h" #include "Component.h" +#include "eReplicaComponentType.h" class Entity; enum class ePhysicsBehaviorType : int32_t; @@ -13,7 +14,7 @@ enum class ePhysicsBehaviorType : int32_t; */ class ModelComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_MODEL; + static const eReplicaComponentType ComponentType = eReplicaComponentType::MODEL; ModelComponent(Entity* parent); diff --git a/dGame/dComponents/ModuleAssemblyComponent.h b/dGame/dComponents/ModuleAssemblyComponent.h index 24e1c1ee..c6e217ed 100644 --- a/dGame/dComponents/ModuleAssemblyComponent.h +++ b/dGame/dComponents/ModuleAssemblyComponent.h @@ -3,6 +3,7 @@ #include "BitStream.h" #include "Entity.h" #include "Component.h" +#include "eReplicaComponentType.h" /** * Component that belongs to an object that may be modularly built, like cars and rockets. Note that this is not the @@ -11,7 +12,7 @@ */ class ModuleAssemblyComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_MODULE_ASSEMBLY; + static const eReplicaComponentType ComponentType = eReplicaComponentType::MODULE_ASSEMBLY; ModuleAssemblyComponent(Entity* MSG_CHAT_INTERNAL_PLAYER_REMOVED_NOTIFICATION); ~ModuleAssemblyComponent() override; diff --git a/dGame/dComponents/MovementAIComponent.cpp b/dGame/dComponents/MovementAIComponent.cpp index 92397a55..278e9106 100644 --- a/dGame/dComponents/MovementAIComponent.cpp +++ b/dGame/dComponents/MovementAIComponent.cpp @@ -11,6 +11,9 @@ #include "SimplePhysicsComponent.h" #include "CDClientManager.h" +#include "CDComponentsRegistryTable.h" +#include "CDPhysicsComponentTable.h" + std::map MovementAIComponent::m_PhysicsSpeedCache = {}; MovementAIComponent::MovementAIComponent(Entity* parent, MovementAIInfo info) : Component(parent) { @@ -19,7 +22,7 @@ MovementAIComponent::MovementAIComponent(Entity* parent, MovementAIInfo info) : m_BaseCombatAI = nullptr; - m_BaseCombatAI = reinterpret_cast(m_Parent->GetComponent(COMPONENT_TYPE_BASE_COMBAT_AI)); + m_BaseCombatAI = reinterpret_cast(m_Parent->GetComponent(eReplicaComponentType::BASE_COMBAT_AI)); //Try and fix the insane values: if (m_Info.wanderRadius > 5.0f) m_Info.wanderRadius = m_Info.wanderRadius * 0.5f; @@ -93,7 +96,7 @@ void MovementAIComponent::Update(const float deltaTime) { NiPoint3 velocity = NiPoint3::ZERO; - if (AdvanceWaypointIndex()) // Do we have another waypoint to seek? + if (m_Acceleration > 0 && m_BaseSpeed > 0 && AdvanceWaypointIndex()) // Do we have another waypoint to seek? { m_NextWaypoint = GetCurrentWaypoint(); @@ -280,13 +283,13 @@ float MovementAIComponent::GetBaseSpeed(LOT lot) { return it->second; } - CDComponentsRegistryTable* componentRegistryTable = CDClientManager::Instance()->GetTable("ComponentsRegistry"); - CDPhysicsComponentTable* physicsComponentTable = CDClientManager::Instance()->GetTable("PhysicsComponent"); + CDComponentsRegistryTable* componentRegistryTable = CDClientManager::Instance().GetTable(); + CDPhysicsComponentTable* physicsComponentTable = CDClientManager::Instance().GetTable(); int32_t componentID; CDPhysicsComponent* physicsComponent = nullptr; - componentID = componentRegistryTable->GetByIDAndType(lot, COMPONENT_TYPE_CONTROLLABLE_PHYSICS, -1); + componentID = componentRegistryTable->GetByIDAndType(lot, eReplicaComponentType::CONTROLLABLE_PHYSICS, -1); if (componentID != -1) { physicsComponent = physicsComponentTable->GetByID(componentID); @@ -294,7 +297,7 @@ float MovementAIComponent::GetBaseSpeed(LOT lot) { goto foundComponent; } - componentID = componentRegistryTable->GetByIDAndType(lot, COMPONENT_TYPE_SIMPLE_PHYSICS, -1); + componentID = componentRegistryTable->GetByIDAndType(lot, eReplicaComponentType::SIMPLE_PHYSICS, -1); if (componentID != -1) { physicsComponent = physicsComponentTable->GetByID(componentID); diff --git a/dGame/dComponents/MovementAIComponent.h b/dGame/dComponents/MovementAIComponent.h index 82cd48a0..3c9044aa 100644 --- a/dGame/dComponents/MovementAIComponent.h +++ b/dGame/dComponents/MovementAIComponent.h @@ -13,6 +13,7 @@ #include "Game.h" #include "dLogger.h" #include "Component.h" +#include "eReplicaComponentType.h" #include class ControllablePhysicsComponent; @@ -56,7 +57,7 @@ struct MovementAIInfo { */ class MovementAIComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_MOVEMENT_AI; + static const eReplicaComponentType ComponentType = eReplicaComponentType::MOVEMENT_AI; MovementAIComponent(Entity* parentEntity, MovementAIInfo info); ~MovementAIComponent() override; diff --git a/dGame/dComponents/MovingPlatformComponent.h b/dGame/dComponents/MovingPlatformComponent.h index 38b15143..9e4c1ecf 100644 --- a/dGame/dComponents/MovingPlatformComponent.h +++ b/dGame/dComponents/MovingPlatformComponent.h @@ -14,6 +14,7 @@ #include "EntityManager.h" #include "Component.h" #include "eMovementPlatformState.h" +#include "eReplicaComponentType.h" class Path; @@ -105,7 +106,7 @@ public: */ class MovingPlatformComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_MOVING_PLATFORM; + static const eReplicaComponentType ComponentType = eReplicaComponentType::MOVING_PLATFORM; MovingPlatformComponent(Entity* parent, const std::string& pathName); ~MovingPlatformComponent() override; diff --git a/dGame/dComponents/PetComponent.h b/dGame/dComponents/PetComponent.h index efde0e8a..e3c1556b 100644 --- a/dGame/dComponents/PetComponent.h +++ b/dGame/dComponents/PetComponent.h @@ -4,6 +4,7 @@ #include "MovementAIComponent.h" #include "Component.h" #include "Preconditions.h" +#include "eReplicaComponentType.h" enum class PetAbilityType { @@ -20,7 +21,7 @@ enum class PetAbilityType class PetComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_PET; + static const eReplicaComponentType ComponentType = eReplicaComponentType::PET; explicit PetComponent(Entity* parentEntity, uint32_t componentId); ~PetComponent() override; diff --git a/dGame/dComponents/PhantomPhysicsComponent.cpp b/dGame/dComponents/PhantomPhysicsComponent.cpp index aa3ced46..75cef4fb 100644 --- a/dGame/dComponents/PhantomPhysicsComponent.cpp +++ b/dGame/dComponents/PhantomPhysicsComponent.cpp @@ -143,10 +143,10 @@ PhantomPhysicsComponent::PhantomPhysicsComponent(Entity* parent) : Component(par */ if (!m_HasCreatedPhysics) { - CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance()->GetTable("ComponentsRegistry"); - auto componentID = compRegistryTable->GetByIDAndType(m_Parent->GetLOT(), COMPONENT_TYPE_PHANTOM_PHYSICS); + CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance().GetTable(); + auto componentID = compRegistryTable->GetByIDAndType(m_Parent->GetLOT(), eReplicaComponentType::PHANTOM_PHYSICS); - CDPhysicsComponentTable* physComp = CDClientManager::Instance()->GetTable("PhysicsComponent"); + CDPhysicsComponentTable* physComp = CDClientManager::Instance().GetTable(); if (physComp == nullptr) return; @@ -253,10 +253,10 @@ void PhantomPhysicsComponent::CreatePhysics() { y = m_Parent->GetVar(u"primitiveModelValueY"); z = m_Parent->GetVar(u"primitiveModelValueZ"); } else { - CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance()->GetTable("ComponentsRegistry"); - auto componentID = compRegistryTable->GetByIDAndType(m_Parent->GetLOT(), COMPONENT_TYPE_PHANTOM_PHYSICS); + CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance().GetTable(); + auto componentID = compRegistryTable->GetByIDAndType(m_Parent->GetLOT(), eReplicaComponentType::PHANTOM_PHYSICS); - CDPhysicsComponentTable* physComp = CDClientManager::Instance()->GetTable("PhysicsComponent"); + CDPhysicsComponentTable* physComp = CDClientManager::Instance().GetTable(); if (physComp == nullptr) return; diff --git a/dGame/dComponents/PhantomPhysicsComponent.h b/dGame/dComponents/PhantomPhysicsComponent.h index 1e9a7b60..0b27db05 100644 --- a/dGame/dComponents/PhantomPhysicsComponent.h +++ b/dGame/dComponents/PhantomPhysicsComponent.h @@ -12,6 +12,7 @@ #include "CppScripts.h" #include "InvalidScript.h" #include "Component.h" +#include "eReplicaComponentType.h" class LDFBaseData; class Entity; @@ -25,7 +26,7 @@ class dpEntity; */ class PhantomPhysicsComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_PHANTOM_PHYSICS; + static const eReplicaComponentType ComponentType = eReplicaComponentType::PHANTOM_PHYSICS; PhantomPhysicsComponent(Entity* parent); ~PhantomPhysicsComponent() override; diff --git a/dGame/dComponents/PlayerForcedMovementComponent.h b/dGame/dComponents/PlayerForcedMovementComponent.h index 43b99997..90708c9a 100644 --- a/dGame/dComponents/PlayerForcedMovementComponent.h +++ b/dGame/dComponents/PlayerForcedMovementComponent.h @@ -2,6 +2,7 @@ #include "Entity.h" #include "Component.h" +#include "eReplicaComponentType.h" /** * Component that handles player forced movement @@ -9,7 +10,7 @@ */ class PlayerForcedMovementComponent : public Component { public: - static const uint32_t ComponentType = eReplicaComponentType::COMPONENT_TYPE_PLAYER_FORCED_MOVEMENT; + static const eReplicaComponentType ComponentType = eReplicaComponentType::PLAYER_FORCED_MOVEMENT; /** * Constructor for this component diff --git a/dGame/dComponents/PossessableComponent.h b/dGame/dComponents/PossessableComponent.h index e1dc5ccd..2026c11e 100644 --- a/dGame/dComponents/PossessableComponent.h +++ b/dGame/dComponents/PossessableComponent.h @@ -6,6 +6,7 @@ #include "Item.h" #include "PossessorComponent.h" #include "eAninmationFlags.h" +#include "eReplicaComponentType.h" /** * Represents an entity that can be controlled by some other entity, generally used by cars to indicate that some @@ -13,7 +14,7 @@ */ class PossessableComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_POSSESSABLE; + static const eReplicaComponentType ComponentType = eReplicaComponentType::POSSESSABLE; PossessableComponent(Entity* parentEntity, uint32_t componentId); diff --git a/dGame/dComponents/PossessorComponent.h b/dGame/dComponents/PossessorComponent.h index 00b24445..4456af27 100644 --- a/dGame/dComponents/PossessorComponent.h +++ b/dGame/dComponents/PossessorComponent.h @@ -3,6 +3,7 @@ #include "BitStream.h" #include "Entity.h" #include "Component.h" +#include "eReplicaComponentType.h" // possession types enum class ePossessionType : uint8_t { @@ -17,7 +18,7 @@ enum class ePossessionType : uint8_t { */ class PossessorComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_POSSESSOR; + static const eReplicaComponentType ComponentType = eReplicaComponentType::POSSESSOR; PossessorComponent(Entity* parent); ~PossessorComponent() override; diff --git a/dGame/dComponents/PropertyComponent.h b/dGame/dComponents/PropertyComponent.h index 2096a475..41f93677 100644 --- a/dGame/dComponents/PropertyComponent.h +++ b/dGame/dComponents/PropertyComponent.h @@ -9,6 +9,7 @@ #include "BitStream.h" #include "Entity.h" #include "Component.h" +#include "eReplicaComponentType.h" struct PropertyState { LWOOBJID ownerID; @@ -21,7 +22,7 @@ struct PropertyState { */ class PropertyComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_PROPERTY; + static const eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY; explicit PropertyComponent(Entity* parentEntity); ~PropertyComponent() override; [[nodiscard]] PropertyState* GetPropertyState() const { return m_PropertyState; }; diff --git a/dGame/dComponents/PropertyEntranceComponent.cpp b/dGame/dComponents/PropertyEntranceComponent.cpp index 9498a903..fa838ed7 100644 --- a/dGame/dComponents/PropertyEntranceComponent.cpp +++ b/dGame/dComponents/PropertyEntranceComponent.cpp @@ -16,7 +16,7 @@ PropertyEntranceComponent::PropertyEntranceComponent(uint32_t componentID, Entity* parent) : Component(parent) { this->propertyQueries = {}; - auto table = CDClientManager::Instance()->GetTable("PropertyEntranceComponent"); + auto table = CDClientManager::Instance().GetTable(); const auto& entry = table->GetByID(componentID); this->m_MapID = entry.mapID; diff --git a/dGame/dComponents/PropertyEntranceComponent.h b/dGame/dComponents/PropertyEntranceComponent.h index 4110e7d9..e37d1daa 100644 --- a/dGame/dComponents/PropertyEntranceComponent.h +++ b/dGame/dComponents/PropertyEntranceComponent.h @@ -6,13 +6,14 @@ #include "Entity.h" #include "EntityManager.h" #include "GameMessages.h" +#include "eReplicaComponentType.h" /** * Represents the launch pad that's used to select and browse properties */ class PropertyEntranceComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_PROPERTY_ENTRANCE; + static const eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY_ENTRANCE; explicit PropertyEntranceComponent(uint32_t componentID, Entity* parent); /** diff --git a/dGame/dComponents/PropertyManagementComponent.cpp b/dGame/dComponents/PropertyManagementComponent.cpp index ce2c8e5e..0b05b10e 100644 --- a/dGame/dComponents/PropertyManagementComponent.cpp +++ b/dGame/dComponents/PropertyManagementComponent.cpp @@ -255,7 +255,7 @@ void PropertyManagementComponent::OnStartBuilding() { LWOMAPID zoneId = 1100; - const auto entrance = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_PROPERTY_ENTRANCE); + const auto entrance = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::PROPERTY_ENTRANCE); originalPrivacyOption = privacyOption; diff --git a/dGame/dComponents/PropertyManagementComponent.h b/dGame/dComponents/PropertyManagementComponent.h index d9526015..2ee010a8 100644 --- a/dGame/dComponents/PropertyManagementComponent.h +++ b/dGame/dComponents/PropertyManagementComponent.h @@ -3,6 +3,7 @@ #include #include "Entity.h" #include "Component.h" +#include "eReplicaComponentType.h" /** * Information regarding which players may visit this property @@ -31,7 +32,7 @@ enum class PropertyPrivacyOption class PropertyManagementComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_PROPERTY_MANAGEMENT; + static const eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY_MANAGEMENT; PropertyManagementComponent(Entity* parent); static PropertyManagementComponent* Instance(); diff --git a/dGame/dComponents/PropertyVendorComponent.h b/dGame/dComponents/PropertyVendorComponent.h index f947d745..5055b445 100644 --- a/dGame/dComponents/PropertyVendorComponent.h +++ b/dGame/dComponents/PropertyVendorComponent.h @@ -2,6 +2,7 @@ #include "Entity.h" #include "Component.h" +#include "eReplicaComponentType.h" /** * The property guard that stands on a property before it's claimed, allows entities to attempt claiming this property. @@ -9,7 +10,7 @@ class PropertyVendorComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_PROPERTY_VENDOR; + static const eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY_VENDOR; explicit PropertyVendorComponent(Entity* parent); /** diff --git a/dGame/dComponents/ProximityMonitorComponent.h b/dGame/dComponents/ProximityMonitorComponent.h index a98397a2..2f51917d 100644 --- a/dGame/dComponents/ProximityMonitorComponent.h +++ b/dGame/dComponents/ProximityMonitorComponent.h @@ -11,6 +11,7 @@ #include "dpWorld.h" #include "dpEntity.h" #include "Component.h" +#include "eReplicaComponentType.h" /** * Utility component for detecting how close entities are to named proximities for this entity. Allows you to store @@ -18,7 +19,7 @@ */ class ProximityMonitorComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_PROXIMITY_MONITOR; + static const eReplicaComponentType ComponentType = eReplicaComponentType::PROXIMITY_MONITOR; ProximityMonitorComponent(Entity* parentEntity, int smallRadius = -1, int largeRadius = -1); ~ProximityMonitorComponent() override; diff --git a/dGame/dComponents/RacingControlComponent.cpp b/dGame/dComponents/RacingControlComponent.cpp index 4b27ac0f..fe4f1faf 100644 --- a/dGame/dComponents/RacingControlComponent.cpp +++ b/dGame/dComponents/RacingControlComponent.cpp @@ -306,30 +306,58 @@ void RacingControlComponent::OnRequestDie(Entity* player) { auto* vehicle = EntityManager::Instance()->GetEntity(racingPlayer.vehicleID); - if (vehicle == nullptr) { - return; - } + if (!vehicle) return; if (!racingPlayer.noSmashOnReload) { racingPlayer.smashedTimes++; + GameMessages::SendDie(vehicle, vehicle->GetObjectID(), LWOOBJID_EMPTY, true, + VIOLENT, u"", 0, 0, 90.0f, false, true, 0); + + auto* destroyableComponent = vehicle->GetComponent(); + uint32_t respawnImagination = 0; + // Reset imagination to half its current value, rounded up to the nearest value divisible by 10, as it was done in live. + // Do not actually change the value yet. Do that on respawn. + if (destroyableComponent) { + respawnImagination = static_cast(ceil(destroyableComponent->GetImagination() / 2.0f / 10.0f)) * 10.0f; + GameMessages::SendSetResurrectRestoreValues(vehicle, -1, -1, respawnImagination); + } + + // Respawn the player in 2 seconds, as was done in live. Not sure if this value is in a setting somewhere else... + vehicle->AddCallbackTimer(2.0f, [=]() { + if (!vehicle || !this->m_Parent) return; + GameMessages::SendRacingResetPlayerToLastReset( + m_Parent->GetObjectID(), racingPlayer.playerID, + UNASSIGNED_SYSTEM_ADDRESS); + + GameMessages::SendVehicleStopBoost(vehicle, player->GetSystemAddress(), true); + + GameMessages::SendRacingSetPlayerResetInfo( + m_Parent->GetObjectID(), racingPlayer.lap, + racingPlayer.respawnIndex, player->GetObjectID(), + racingPlayer.respawnPosition, racingPlayer.respawnIndex + 1, + UNASSIGNED_SYSTEM_ADDRESS); + + GameMessages::SendResurrect(vehicle); + auto* destroyableComponent = vehicle->GetComponent(); + // Reset imagination to half its current value, rounded up to the nearest value divisible by 10, as it was done in live. + if (destroyableComponent) destroyableComponent->SetImagination(respawnImagination); + EntityManager::Instance()->SerializeEntity(vehicle); + }); + + auto* characterComponent = player->GetComponent(); + if (characterComponent != nullptr) { + characterComponent->UpdatePlayerStatistic(RacingTimesWrecked); + } + } else { + GameMessages::SendRacingSetPlayerResetInfo( + m_Parent->GetObjectID(), racingPlayer.lap, + racingPlayer.respawnIndex, player->GetObjectID(), + racingPlayer.respawnPosition, racingPlayer.respawnIndex + 1, + UNASSIGNED_SYSTEM_ADDRESS); + GameMessages::SendRacingResetPlayerToLastReset( + m_Parent->GetObjectID(), racingPlayer.playerID, + UNASSIGNED_SYSTEM_ADDRESS); } - - // Reset player to last checkpoint - GameMessages::SendRacingSetPlayerResetInfo( - m_Parent->GetObjectID(), racingPlayer.lap, - racingPlayer.respawnIndex, player->GetObjectID(), - racingPlayer.respawnPosition, racingPlayer.respawnIndex + 1, - UNASSIGNED_SYSTEM_ADDRESS); - GameMessages::SendRacingResetPlayerToLastReset( - m_Parent->GetObjectID(), racingPlayer.playerID, - UNASSIGNED_SYSTEM_ADDRESS); - - auto* characterComponent = player->GetComponent(); - if (characterComponent != nullptr) { - characterComponent->UpdatePlayerStatistic(RacingTimesWrecked); - } - - return; } } @@ -348,19 +376,6 @@ void RacingControlComponent::OnRacingPlayerInfoResetFinished(Entity* player) { return; } - if (!racingPlayer.noSmashOnReload) { - GameMessages::SendDie(vehicle, LWOOBJID_EMPTY, LWOOBJID_EMPTY, true, - VIOLENT, u"", 0, 0, 0, true, false, 0); - - GameMessages::SendVehicleUnlockInput(racingPlayer.vehicleID, false, - UNASSIGNED_SYSTEM_ADDRESS); - GameMessages::SendVehicleSetWheelLockState( - racingPlayer.vehicleID, false, false, - UNASSIGNED_SYSTEM_ADDRESS); - - GameMessages::SendResurrect(vehicle); - } - racingPlayer.noSmashOnReload = false; return; diff --git a/dGame/dComponents/RacingControlComponent.h b/dGame/dComponents/RacingControlComponent.h index 933178cc..91ab2fd4 100644 --- a/dGame/dComponents/RacingControlComponent.h +++ b/dGame/dComponents/RacingControlComponent.h @@ -7,6 +7,7 @@ #include "BitStream.h" #include "Entity.h" #include "Component.h" +#include "eReplicaComponentType.h" /** * Information for each player in the race @@ -104,7 +105,7 @@ struct RacingPlayerInfo { */ class RacingControlComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_RACING_CONTROL; + static const eReplicaComponentType ComponentType = eReplicaComponentType::RACING_CONTROL; RacingControlComponent(Entity* parentEntity); ~RacingControlComponent(); diff --git a/dGame/dComponents/RailActivatorComponent.cpp b/dGame/dComponents/RailActivatorComponent.cpp index 25fad26e..49fc105d 100644 --- a/dGame/dComponents/RailActivatorComponent.cpp +++ b/dGame/dComponents/RailActivatorComponent.cpp @@ -10,8 +10,7 @@ RailActivatorComponent::RailActivatorComponent(Entity* parent, int32_t componentID) : Component(parent) { m_ComponentID = componentID; - const auto tableData = CDClientManager::Instance() - ->GetTable("RailActivatorComponent")->GetEntryByID(componentID); + const auto tableData = CDClientManager::Instance().GetTable()->GetEntryByID(componentID);; m_Path = parent->GetVar(u"rail_path"); m_PathDirection = parent->GetVar(u"rail_path_direction"); diff --git a/dGame/dComponents/RailActivatorComponent.h b/dGame/dComponents/RailActivatorComponent.h index 8f67e7e3..5d625d2a 100644 --- a/dGame/dComponents/RailActivatorComponent.h +++ b/dGame/dComponents/RailActivatorComponent.h @@ -4,6 +4,7 @@ #include #include "dCommonVars.h" #include "Component.h" +#include "eReplicaComponentType.h" /** * Component that handles the traveling using rails, e.g. the ninjago posts that can be used to travel using Spinjitzu. @@ -14,7 +15,7 @@ public: explicit RailActivatorComponent(Entity* parent, int32_t componentID); ~RailActivatorComponent() override; - static const uint32_t ComponentType = COMPONENT_TYPE_RAIL_ACTIVATOR; + static const eReplicaComponentType ComponentType = eReplicaComponentType::RAIL_ACTIVATOR; /** * Handles the OnUse event from some entity, initiates the rail movement diff --git a/dGame/dComponents/RebuildComponent.cpp b/dGame/dComponents/RebuildComponent.cpp index bf7bd3e5..abd21873 100644 --- a/dGame/dComponents/RebuildComponent.cpp +++ b/dGame/dComponents/RebuildComponent.cpp @@ -53,7 +53,7 @@ RebuildComponent::~RebuildComponent() { } void RebuildComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) { - if (m_Parent->GetComponent(COMPONENT_TYPE_DESTROYABLE) == nullptr) { + if (m_Parent->GetComponent(eReplicaComponentType::DESTROYABLE) == nullptr) { if (bIsInitialUpdate) { outBitStream->Write(false); } diff --git a/dGame/dComponents/RebuildComponent.h b/dGame/dComponents/RebuildComponent.h index bd3edd7d..a8e11e4c 100644 --- a/dGame/dComponents/RebuildComponent.h +++ b/dGame/dComponents/RebuildComponent.h @@ -9,6 +9,7 @@ #include "ScriptedActivityComponent.h" #include "Preconditions.h" #include "Component.h" +#include "eReplicaComponentType.h" class Entity; @@ -19,7 +20,7 @@ class Entity; */ class RebuildComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_REBUILD; + static const eReplicaComponentType ComponentType = eReplicaComponentType::QUICK_BUILD; RebuildComponent(Entity* entity); ~RebuildComponent() override; diff --git a/dGame/dComponents/RenderComponent.cpp b/dGame/dComponents/RenderComponent.cpp index 3002ae33..ee42acba 100644 --- a/dGame/dComponents/RenderComponent.cpp +++ b/dGame/dComponents/RenderComponent.cpp @@ -20,9 +20,9 @@ RenderComponent::RenderComponent(Entity* parent) : Component(parent) { return; /* - auto* table = CDClientManager::Instance()->GetTable("ComponentsRegistry"); + auto* table = CDClientManager::Instance().GetTable(); - const auto entry = table->GetByIDAndType(parent->GetLOT(), COMPONENT_TYPE_RENDER); + const auto entry = table->GetByIDAndType(parent->GetLOT(), eReplicaComponentType::RENDER); std::stringstream query; diff --git a/dGame/dComponents/RenderComponent.h b/dGame/dComponents/RenderComponent.h index e6184564..de8b2907 100644 --- a/dGame/dComponents/RenderComponent.h +++ b/dGame/dComponents/RenderComponent.h @@ -8,6 +8,7 @@ #include "AMFFormat.h" #include "Component.h" +#include "eReplicaComponentType.h" class Entity; @@ -55,7 +56,7 @@ struct Effect { */ class RenderComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_RENDER; + static const eReplicaComponentType ComponentType = eReplicaComponentType::RENDER; RenderComponent(Entity* entity); ~RenderComponent() override; diff --git a/dGame/dComponents/RigidbodyPhantomPhysicsComponent.h b/dGame/dComponents/RigidbodyPhantomPhysicsComponent.h index c8faa930..480f9b81 100644 --- a/dGame/dComponents/RigidbodyPhantomPhysicsComponent.h +++ b/dGame/dComponents/RigidbodyPhantomPhysicsComponent.h @@ -11,6 +11,7 @@ #include "NiPoint3.h" #include "NiQuaternion.h" #include "Component.h" +#include "eReplicaComponentType.h" /** * Component that handles rigid bodies that can be interacted with, mostly client-side rendered. An example is the @@ -18,7 +19,7 @@ */ class RigidbodyPhantomPhysicsComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_PHANTOM_PHYSICS; + static const eReplicaComponentType ComponentType = eReplicaComponentType::PHANTOM_PHYSICS; RigidbodyPhantomPhysicsComponent(Entity* parent); ~RigidbodyPhantomPhysicsComponent() override; diff --git a/dGame/dComponents/RocketLaunchLupComponent.h b/dGame/dComponents/RocketLaunchLupComponent.h index 3fc0b444..226fa1b2 100644 --- a/dGame/dComponents/RocketLaunchLupComponent.h +++ b/dGame/dComponents/RocketLaunchLupComponent.h @@ -3,6 +3,7 @@ #include "Entity.h" #include "GameMessages.h" #include "Component.h" +#include "eReplicaComponentType.h" /** * Component that handles the LUP/WBL rocket launchpad that can be interacted with to travel to WBL worlds. @@ -10,7 +11,7 @@ */ class RocketLaunchLupComponent : public Component { public: - static const uint32_t ComponentType = eReplicaComponentType::COMPONENT_TYPE_ROCKET_LAUNCH_LUP; + static const eReplicaComponentType ComponentType = eReplicaComponentType::ROCKET_LAUNCH_LUP; /** * Constructor for this component, builds the m_LUPWorlds vector diff --git a/dGame/dComponents/RocketLaunchpadControlComponent.h b/dGame/dComponents/RocketLaunchpadControlComponent.h index 8a10f0f7..84cff22d 100644 --- a/dGame/dComponents/RocketLaunchpadControlComponent.h +++ b/dGame/dComponents/RocketLaunchpadControlComponent.h @@ -9,6 +9,7 @@ #include "BitStream.h" #include "Entity.h" #include "Component.h" +#include "eReplicaComponentType.h" class PreconditionExpression; @@ -17,7 +18,7 @@ class PreconditionExpression; */ class RocketLaunchpadControlComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_ROCKET_LAUNCH; + static const eReplicaComponentType ComponentType = eReplicaComponentType::ROCKET_LAUNCH; RocketLaunchpadControlComponent(Entity* parent, int rocketId); ~RocketLaunchpadControlComponent() override; diff --git a/dGame/dComponents/ScriptedActivityComponent.cpp b/dGame/dComponents/ScriptedActivityComponent.cpp index 067446e7..bafa1faa 100644 --- a/dGame/dComponents/ScriptedActivityComponent.cpp +++ b/dGame/dComponents/ScriptedActivityComponent.cpp @@ -22,9 +22,13 @@ #include "Loot.h" #include "eMissionTaskType.h" +#include "CDCurrencyTableTable.h" +#include "CDActivityRewardsTable.h" +#include "CDActivitiesTable.h" + ScriptedActivityComponent::ScriptedActivityComponent(Entity* parent, int activityID) : Component(parent) { m_ActivityID = activityID; - CDActivitiesTable* activitiesTable = CDClientManager::Instance()->GetTable("Activities"); + CDActivitiesTable* activitiesTable = CDClientManager::Instance().GetTable(); std::vector activities = activitiesTable->Query([=](CDActivities entry) {return (entry.ActivityID == m_ActivityID); }); for (CDActivities activity : activities) { @@ -53,7 +57,7 @@ ScriptedActivityComponent::ScriptedActivityComponent(Entity* parent, int activit if (destroyableComponent) { // check for LMIs and set the loot LMIs - CDActivityRewardsTable* activityRewardsTable = CDClientManager::Instance()->GetTable("ActivityRewards"); + CDActivityRewardsTable* activityRewardsTable = CDClientManager::Instance().GetTable(); std::vector activityRewards = activityRewardsTable->Query([=](CDActivityRewards entry) {return (entry.LootMatrixIndex == destroyableComponent->GetLootMatrixID()); }); uint32_t startingLMI = 0; @@ -94,7 +98,7 @@ void ScriptedActivityComponent::Serialize(RakNet::BitStream* outBitStream, bool } void ScriptedActivityComponent::ReloadConfig() { - CDActivitiesTable* activitiesTable = CDClientManager::Instance()->GetTable("Activities"); + CDActivitiesTable* activitiesTable = CDClientManager::Instance().GetTable(); std::vector activities = activitiesTable->Query([=](CDActivities entry) {return (entry.ActivityID == m_ActivityID); }); for (auto activity : activities) { auto mapID = m_ActivityInfo.instanceMapID; @@ -137,7 +141,7 @@ void ScriptedActivityComponent::PlayerJoin(Entity* player) { } void ScriptedActivityComponent::PlayerJoinLobby(Entity* player) { - if (!m_Parent->HasComponent(COMPONENT_TYPE_REBUILD)) + if (!m_Parent->HasComponent(eReplicaComponentType::QUICK_BUILD)) GameMessages::SendMatchResponse(player, player->GetSystemAddress(), 0); // tell the client they joined a lobby LobbyPlayer* newLobbyPlayer = new LobbyPlayer(); newLobbyPlayer->entityID = player->GetObjectID(); @@ -557,14 +561,14 @@ void ActivityInstance::RewardParticipant(Entity* participant) { } // First, get the activity data - auto* activityRewardsTable = CDClientManager::Instance()->GetTable("ActivityRewards"); + auto* activityRewardsTable = CDClientManager::Instance().GetTable(); std::vector activityRewards = activityRewardsTable->Query([=](CDActivityRewards entry) { return (entry.objectTemplate == m_ActivityInfo.ActivityID); }); if (!activityRewards.empty()) { uint32_t minCoins = 0; uint32_t maxCoins = 0; - auto* currencyTableTable = CDClientManager::Instance()->GetTable("CurrencyTable"); + auto* currencyTableTable = CDClientManager::Instance().GetTable(); std::vector currencyTable = currencyTableTable->Query([=](CDCurrencyTable entry) { return (entry.currencyIndex == activityRewards[0].CurrencyIndex && entry.npcminlevel == 1); }); if (!currencyTable.empty()) { diff --git a/dGame/dComponents/ScriptedActivityComponent.h b/dGame/dComponents/ScriptedActivityComponent.h index 8bb17093..1d49a62d 100644 --- a/dGame/dComponents/ScriptedActivityComponent.h +++ b/dGame/dComponents/ScriptedActivityComponent.h @@ -11,6 +11,9 @@ #include "BitStream.h" #include "Entity.h" #include "Component.h" +#include "eReplicaComponentType.h" + +#include "CDActivitiesTable.h" /** * Represents an instance of an activity, having participants and score @@ -153,7 +156,7 @@ struct ActivityPlayer { */ class ScriptedActivityComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_SCRIPTED_ACTIVITY; + static const eReplicaComponentType ComponentType = eReplicaComponentType::SCRIPTED_ACTIVITY; ScriptedActivityComponent(Entity* parent, int activityID); ~ScriptedActivityComponent() override; diff --git a/dGame/dComponents/ShootingGalleryComponent.h b/dGame/dComponents/ShootingGalleryComponent.h index c43f20c2..c31575f1 100644 --- a/dGame/dComponents/ShootingGalleryComponent.h +++ b/dGame/dComponents/ShootingGalleryComponent.h @@ -3,6 +3,7 @@ #include "NiPoint3.h" #include "Entity.h" #include "Component.h" +#include "eReplicaComponentType.h" /** * Parameters for the shooting gallery that change during playtime @@ -72,7 +73,7 @@ struct StaticShootingGalleryParams { */ class ShootingGalleryComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_SHOOTING_GALLERY; + static const eReplicaComponentType ComponentType = eReplicaComponentType::SHOOTING_GALLERY; explicit ShootingGalleryComponent(Entity* parent); ~ShootingGalleryComponent(); diff --git a/dGame/dComponents/SimplePhysicsComponent.h b/dGame/dComponents/SimplePhysicsComponent.h index ebb8b124..51356710 100644 --- a/dGame/dComponents/SimplePhysicsComponent.h +++ b/dGame/dComponents/SimplePhysicsComponent.h @@ -11,6 +11,7 @@ #include "NiPoint3.h" #include "NiQuaternion.h" #include "Component.h" +#include "eReplicaComponentType.h" class Entity; @@ -27,7 +28,7 @@ enum class eClimbableType : int32_t { */ class SimplePhysicsComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_SIMPLE_PHYSICS; + static const eReplicaComponentType ComponentType = eReplicaComponentType::SIMPLE_PHYSICS; SimplePhysicsComponent(uint32_t componentID, Entity* parent); ~SimplePhysicsComponent() override; diff --git a/dGame/dComponents/SkillComponent.cpp b/dGame/dComponents/SkillComponent.cpp index 2391dc3b..23ef1bee 100644 --- a/dGame/dComponents/SkillComponent.cpp +++ b/dGame/dComponents/SkillComponent.cpp @@ -24,6 +24,8 @@ #include "DoClientProjectileImpact.h" #include "CDClientManager.h" +#include "CDSkillBehaviorTable.h" + ProjectileSyncEntry::ProjectileSyncEntry() { } @@ -128,7 +130,7 @@ void SkillComponent::RegisterPlayerProjectile(const LWOOBJID projectileId, Behav } void SkillComponent::Update(const float deltaTime) { - if (!m_Parent->HasComponent(COMPONENT_TYPE_BASE_COMBAT_AI) && m_Parent->GetLOT() != 1) { + if (!m_Parent->HasComponent(eReplicaComponentType::BASE_COMBAT_AI) && m_Parent->GetLOT() != 1) { CalculateUpdate(deltaTime); } @@ -220,7 +222,7 @@ bool SkillComponent::CastSkill(const uint32_t skillId, LWOOBJID target, const LW // if it's not in the cache look it up and cache it if (pair == m_skillBehaviorCache.end()) { - auto skillTable = CDClientManager::Instance()->GetTable("SkillBehavior"); + auto skillTable = CDClientManager::Instance().GetTable(); behaviorId = skillTable->GetSkillByID(skillId).behaviorID; m_skillBehaviorCache.insert_or_assign(skillId, behaviorId); } else { diff --git a/dGame/dComponents/SkillComponent.h b/dGame/dComponents/SkillComponent.h index 2bdcb88f..034e65ce 100644 --- a/dGame/dComponents/SkillComponent.h +++ b/dGame/dComponents/SkillComponent.h @@ -13,6 +13,7 @@ #include "Component.h" #include "Entity.h" #include "dLogger.h" +#include "eReplicaComponentType.h" struct ProjectileSyncEntry { LWOOBJID id = LWOOBJID_EMPTY; @@ -58,7 +59,7 @@ struct SkillExecutionResult { */ class SkillComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_SKILL; + static const eReplicaComponentType ComponentType = eReplicaComponentType::SKILL; explicit SkillComponent(Entity* parent); ~SkillComponent() override; diff --git a/dGame/dComponents/SoundTriggerComponent.h b/dGame/dComponents/SoundTriggerComponent.h index e1178150..954d8495 100644 --- a/dGame/dComponents/SoundTriggerComponent.h +++ b/dGame/dComponents/SoundTriggerComponent.h @@ -3,6 +3,7 @@ #include "Entity.h" #include "GUID.h" #include "Component.h" +#include "eReplicaComponentType.h" /** * Music that should be played by the client @@ -19,7 +20,7 @@ struct MusicCue { */ class SoundTriggerComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_SOUND_TRIGGER; + static const eReplicaComponentType ComponentType = eReplicaComponentType::SOUND_TRIGGER; explicit SoundTriggerComponent(Entity* parent); ~SoundTriggerComponent() override; diff --git a/dGame/dComponents/SwitchComponent.h b/dGame/dComponents/SwitchComponent.h index ea5955d8..fde3cfc0 100644 --- a/dGame/dComponents/SwitchComponent.h +++ b/dGame/dComponents/SwitchComponent.h @@ -9,13 +9,14 @@ #include "BouncerComponent.h" #include #include "Component.h" +#include "eReplicaComponentType.h" /** * A component for switches in game, including pet triggered switches. */ class SwitchComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_SWITCH; + static const eReplicaComponentType ComponentType = eReplicaComponentType::SWITCH; SwitchComponent(Entity* parent); ~SwitchComponent() override; diff --git a/dGame/dComponents/TriggerComponent.cpp b/dGame/dComponents/TriggerComponent.cpp index 4ed95a15..d98b2eea 100644 --- a/dGame/dComponents/TriggerComponent.cpp +++ b/dGame/dComponents/TriggerComponent.cpp @@ -161,21 +161,16 @@ void TriggerComponent::HandleSetPhysicsVolume(Entity* targetEntity, std::vector< } void TriggerComponent::HandleUpdateMission(Entity* targetEntity, std::vector argArray) { - CDMissionTasksTable* missionTasksTable = CDClientManager::Instance()->GetTable("MissionTasks"); + CDMissionTasksTable* missionTasksTable = CDClientManager::Instance().GetTable(); std::vector missionTasks = missionTasksTable->Query([=](CDMissionTasks entry) { - std::string lowerTargetGroup; - for (char character : entry.targetGroup) { - lowerTargetGroup.push_back(std::tolower(character)); // make lowercase to ensure it works - } - - return (lowerTargetGroup == argArray[4]); + return (entry.targetGroup == argArray.at(4)); }); for (const CDMissionTasks& task : missionTasks) { MissionComponent* missionComponent = targetEntity->GetComponent(); if (!missionComponent) continue; - missionComponent->ForceProgress(task.id, task.uid, std::stoi(argArray[2])); + missionComponent->ForceProgress(task.id, task.uid, std::stoi(argArray.at(2))); } } diff --git a/dGame/dComponents/TriggerComponent.h b/dGame/dComponents/TriggerComponent.h index d7711696..492b0449 100644 --- a/dGame/dComponents/TriggerComponent.h +++ b/dGame/dComponents/TriggerComponent.h @@ -2,6 +2,7 @@ #define __TRIGGERCOMPONENT__H__ #include "Component.h" +#include "eReplicaComponentType.h" namespace LUTriggers { struct Trigger; @@ -10,7 +11,7 @@ namespace LUTriggers { class TriggerComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_TRIGGER; + static const eReplicaComponentType ComponentType = eReplicaComponentType::TRIGGER; explicit TriggerComponent(Entity* parent, const std::string triggerInfo); diff --git a/dGame/dComponents/VehiclePhysicsComponent.h b/dGame/dComponents/VehiclePhysicsComponent.h index f5ab1917..551cce42 100644 --- a/dGame/dComponents/VehiclePhysicsComponent.h +++ b/dGame/dComponents/VehiclePhysicsComponent.h @@ -3,13 +3,14 @@ #include "BitStream.h" #include "Entity.h" #include "Component.h" +#include "eReplicaComponentType.h" /** * Physics component for vehicles. */ class VehiclePhysicsComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_VEHICLE_PHYSICS; + static const eReplicaComponentType ComponentType = eReplicaComponentType::VEHICLE_PHYSICS; VehiclePhysicsComponent(Entity* parentEntity); ~VehiclePhysicsComponent() override; diff --git a/dGame/dComponents/VendorComponent.cpp b/dGame/dComponents/VendorComponent.cpp index 96dfb2c0..c9178785 100644 --- a/dGame/dComponents/VendorComponent.cpp +++ b/dGame/dComponents/VendorComponent.cpp @@ -5,6 +5,11 @@ #include "Game.h" #include "dServer.h" +#include "CDComponentsRegistryTable.h" +#include "CDVendorComponentTable.h" +#include "CDLootMatrixTable.h" +#include "CDLootTableTable.h" + VendorComponent::VendorComponent(Entity* parent) : Component(parent) { SetupConstants(); RefreshInventory(true); @@ -59,13 +64,13 @@ void VendorComponent::RefreshInventory(bool isCreation) { return; } m_Inventory.clear(); - auto* lootMatrixTable = CDClientManager::Instance()->GetTable("LootMatrix"); + auto* lootMatrixTable = CDClientManager::Instance().GetTable(); std::vector lootMatrices = lootMatrixTable->Query([=](CDLootMatrix entry) { return (entry.LootMatrixIndex == m_LootMatrixID); }); if (lootMatrices.empty()) return; // Done with lootMatrix table - auto* lootTableTable = CDClientManager::Instance()->GetTable("LootTable"); + auto* lootTableTable = CDClientManager::Instance().GetTable(); for (const auto& lootMatrix : lootMatrices) { int lootTableID = lootMatrix.LootTableIndex; @@ -118,10 +123,10 @@ void VendorComponent::RefreshInventory(bool isCreation) { } void VendorComponent::SetupConstants() { - auto* compRegistryTable = CDClientManager::Instance()->GetTable("ComponentsRegistry"); - int componentID = compRegistryTable->GetByIDAndType(m_Parent->GetLOT(), COMPONENT_TYPE_VENDOR); + auto* compRegistryTable = CDClientManager::Instance().GetTable(); + int componentID = compRegistryTable->GetByIDAndType(m_Parent->GetLOT(), eReplicaComponentType::VENDOR); - auto* vendorComponentTable = CDClientManager::Instance()->GetTable("VendorComponent"); + auto* vendorComponentTable = CDClientManager::Instance().GetTable(); std::vector vendorComps = vendorComponentTable->Query([=](CDVendorComponent entry) { return (entry.id == componentID); }); if (vendorComps.empty()) return; m_BuyScalar = vendorComps[0].buyScalar; diff --git a/dGame/dComponents/VendorComponent.h b/dGame/dComponents/VendorComponent.h index 72a5816d..bf372bf2 100644 --- a/dGame/dComponents/VendorComponent.h +++ b/dGame/dComponents/VendorComponent.h @@ -7,13 +7,14 @@ #include "Entity.h" #include "GameMessages.h" #include "RakNetTypes.h" +#include "eReplicaComponentType.h" /** * A component for vendor NPCs. A vendor sells items to the player. */ class VendorComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_VENDOR; + static const eReplicaComponentType ComponentType = eReplicaComponentType::VENDOR; VendorComponent(Entity* parent); ~VendorComponent() override; diff --git a/dGame/dGameMessages/GameMessageHandler.cpp b/dGame/dGameMessages/GameMessageHandler.cpp index 16942ecc..5c05c28d 100644 --- a/dGame/dGameMessages/GameMessageHandler.cpp +++ b/dGame/dGameMessages/GameMessageHandler.cpp @@ -32,6 +32,7 @@ #include "EchoStartSkill.h" #include "EchoSyncSkill.h" #include "eMissionTaskType.h" +#include "eReplicaComponentType.h" using namespace std; @@ -122,7 +123,7 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream* inStream, const System destroyable->SetImagination(destroyable->GetImagination()); EntityManager::Instance()->SerializeEntity(entity); - std::vector racingControllers = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_RACING_CONTROL); + std::vector racingControllers = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::RACING_CONTROL); for (Entity* racingController : racingControllers) { auto* racingComponent = racingController->GetComponent(); if (racingComponent != nullptr) { @@ -135,7 +136,7 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream* inStream, const System script->OnPlayerLoaded(zoneControl, player); } - std::vector scriptedActs = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_SCRIPT); + std::vector scriptedActs = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::SCRIPT); for (Entity* scriptEntity : scriptedActs) { if (scriptEntity->GetObjectID() != zoneControl->GetObjectID()) { // Don't want to trigger twice on instance worlds for (CppScripts::Script* script : CppScripts::GetEntityScripts(scriptEntity)) { @@ -241,7 +242,7 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream* inStream, const System case GAME_MSG_REQUEST_RESURRECT: { GameMessages::SendResurrect(entity); - /*auto* dest = static_cast(entity->GetComponent(COMPONENT_TYPE_DESTROYABLE)); + /*auto* dest = static_cast(entity->GetComponent(eReplicaComponentType::DESTROYABLE)); if (dest) { dest->SetHealth(4); dest->SetArmor(0); @@ -285,7 +286,7 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream* inStream, const System comp->Progress(eMissionTaskType::USE_SKILL, startSkill.skillID); } - CDSkillBehaviorTable* skillTable = CDClientManager::Instance()->GetTable("SkillBehavior"); + CDSkillBehaviorTable* skillTable = CDClientManager::Instance().GetTable(); unsigned int behaviorId = skillTable->GetSkillByID(startSkill.skillID).behaviorID; bool success = false; diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 58d72d3c..33a7f104 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -80,6 +80,10 @@ #include "eBlueprintSaveResponseType.h" #include "eAninmationFlags.h" #include "AMFFormat_BitStream.h" +#include "eReplicaComponentType.h" + +#include "CDComponentsRegistryTable.h" +#include "CDObjectsTable.h" void GameMessages::SendFireEventClientSide(const LWOOBJID& objectID, const SystemAddress& sysAddr, std::u16string args, const LWOOBJID& object, int64_t param1, int param2, const LWOOBJID& sender) { CBITSTREAM; @@ -914,17 +918,25 @@ void GameMessages::SendSetJetPackMode(Entity* entity, bool use, bool bypassCheck } void GameMessages::SendResurrect(Entity* entity) { - DestroyableComponent* dest = static_cast(entity->GetComponent(COMPONENT_TYPE_DESTROYABLE)); + // Restore the players health after the animation for respawning has finished. + // This is when the health appered back in live, not immediately upon requesting respawn + // Add a half second in case someone decides to cheat and move during the death animation + // and just make sure the client has time to be ready. + constexpr float respawnTime = 3.66700005531311f + 0.5f; + entity->AddCallbackTimer(respawnTime, [=]() { + auto* destroyableComponent = entity->GetComponent(); - if (dest != nullptr && entity->GetLOT() == 1) { - auto* levelComponent = entity->GetComponent(); - if (levelComponent) { - dest->SetHealth(levelComponent->GetLevel() >= 45 ? 8 : 4); - dest->SetImagination(levelComponent->GetLevel() >= 45 ? 20 : 6); + if (destroyableComponent != nullptr && entity->GetLOT() == 1) { + auto* levelComponent = entity->GetComponent(); + if (levelComponent) { + destroyableComponent->SetHealth(levelComponent->GetLevel() >= 45 ? 8 : 4); + destroyableComponent->SetImagination(levelComponent->GetLevel() >= 45 ? 20 : 6); + } } - } + }); - auto cont = static_cast(entity->GetComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS)); + + auto cont = static_cast(entity->GetComponent(eReplicaComponentType::CONTROLLABLE_PHYSICS)); if (cont && entity->GetLOT() == 1) { cont->SetPosition(entity->GetRespawnPosition()); cont->SetRotation(entity->GetRespawnRotation()); @@ -1068,7 +1080,7 @@ void GameMessages::SendDropClientLoot(Entity* entity, const LWOOBJID& sourceID, // Currency and powerups should not sync if (team != nullptr && currency == 0) { - CDObjectsTable* objectsTable = CDClientManager::Instance()->GetTable("Objects"); + CDObjectsTable* objectsTable = CDClientManager::Instance().GetTable(); const CDObjects& object = objectsTable->GetByID(item); @@ -1121,7 +1133,7 @@ void GameMessages::SendPlayerReachedRespawnCheckpoint(Entity* entity, const NiPo bitStream.Write(position.y); bitStream.Write(position.z); - auto con = static_cast(entity->GetComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS)); + auto con = static_cast(entity->GetComponent(eReplicaComponentType::CONTROLLABLE_PHYSICS)); if (con) { auto rot = con->GetRotation(); bitStream.Write(rot.x); @@ -1256,7 +1268,7 @@ void GameMessages::SendVendorStatusUpdate(Entity* entity, const SystemAddress& s CBITSTREAM; CMSGHEADER; - VendorComponent* vendor = static_cast(entity->GetComponent(COMPONENT_TYPE_VENDOR)); + VendorComponent* vendor = static_cast(entity->GetComponent(eReplicaComponentType::VENDOR)); if (!vendor) return; std::map vendorItems = vendor->GetInventory(); @@ -1378,7 +1390,7 @@ void GameMessages::SendMoveInventoryBatch(Entity* entity, uint32_t stackCount, i CBITSTREAM; CMSGHEADER; - InventoryComponent* inv = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); + InventoryComponent* inv = static_cast(entity->GetComponent(eReplicaComponentType::INVENTORY)); if (!inv) return; Item* itemStack = inv->FindItemById(iObjID); @@ -1682,7 +1694,7 @@ void GameMessages::HandleActivityStateChangeRequest(RakNet::BitStream* inStream, Game::logger->Log("Activity State Change", "%s [%i, %i] from %i to %i", GeneralUtils::UTF16ToWTF8(stringValue).c_str(), value1, value2, entity->GetLOT(), assosiate != nullptr ? assosiate->GetLOT() : 0); - std::vector scriptedActs = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_SHOOTING_GALLERY); + std::vector scriptedActs = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::SHOOTING_GALLERY); for (Entity* scriptEntity : scriptedActs) { scriptEntity->OnActivityStateChangeRequest(objectID, value1, value2, stringValue); } @@ -2211,24 +2223,24 @@ void GameMessages::HandleQueryPropertyData(RakNet::BitStream* inStream, Entity* Game::logger->Log("HandleQueryPropertyData", "Entity (%i) requesting data", entity->GetLOT()); /* - auto entites = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_PROPERTY_VENDOR); + auto entites = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::PROPERTY_VENDOR); entity = entites[0]; */ - auto* propertyVendorComponent = static_cast(entity->GetComponent(COMPONENT_TYPE_PROPERTY_VENDOR)); + auto* propertyVendorComponent = static_cast(entity->GetComponent(eReplicaComponentType::PROPERTY_VENDOR)); if (propertyVendorComponent != nullptr) { propertyVendorComponent->OnQueryPropertyData(entity, sysAddr); } /* - entites = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_PROPERTY_MANAGEMENT); + entites = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::PROPERTY_MANAGEMENT); entity = entites[0]; */ - auto* propertyManagerComponent = static_cast(entity->GetComponent(COMPONENT_TYPE_PROPERTY_MANAGEMENT)); + auto* propertyManagerComponent = static_cast(entity->GetComponent(eReplicaComponentType::PROPERTY_MANAGEMENT)); if (propertyManagerComponent != nullptr) { propertyManagerComponent->OnQueryPropertyData(entity, sysAddr); @@ -2272,7 +2284,7 @@ void GameMessages::HandleSetBuildMode(RakNet::BitStream* inStream, Entity* entit } void GameMessages::HandleStartBuildingWithItem(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) { - if (!entity->HasComponent(COMPONENT_TYPE_PROPERTY_MANAGEMENT)) { + if (!entity->HasComponent(eReplicaComponentType::PROPERTY_MANAGEMENT)) { return; } @@ -2475,7 +2487,7 @@ void GameMessages::HandleControlBehaviors(RakNet::BitStream* inStream, Entity* e auto owner = PropertyManagementComponent::Instance()->GetOwner(); if (!owner) return; - ControlBehaviors::ProcessCommand(entity, sysAddr, static_cast(amfArguments.get()), command, owner); + ControlBehaviors::Instance().ProcessCommand(entity, sysAddr, static_cast(amfArguments.get()), command, owner); } void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) { @@ -2901,7 +2913,7 @@ void GameMessages::HandleCinematicUpdate(RakNet::BitStream* inStream, Entity* en inStream->Read(waypoint); } - std::vector scriptedActs = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_SCRIPT); + std::vector scriptedActs = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::SCRIPT); for (Entity* scriptEntity : scriptedActs) { scriptEntity->OnCinematicUpdate(scriptEntity, entity, event, pathName, pathTime, overallTime, waypoint); } @@ -3868,7 +3880,7 @@ void GameMessages::HandleMessageBoxResponse(RakNet::BitStream* inStream, Entity* racingControlComponent->HandleMessageBoxResponse(userEntity, GeneralUtils::UTF16ToWTF8(identifier)); } - for (auto* shootingGallery : EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_SHOOTING_GALLERY)) { + for (auto* shootingGallery : EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::SHOOTING_GALLERY)) { shootingGallery->OnMessageBoxResponse(userEntity, iButton, identifier, userData); } } @@ -4395,6 +4407,36 @@ void GameMessages::SendRacingResetPlayerToLastReset(LWOOBJID objectId, LWOOBJID SEND_PACKET; } +void GameMessages::SendVehicleStopBoost(Entity* targetEntity, const SystemAddress& playerSysAddr, bool affectPassive) { + CBITSTREAM; + CMSGHEADER; + + bitStream.Write(targetEntity->GetObjectID()); + bitStream.Write(GAME_MSG::GAME_MSG_VEHICLE_STOP_BOOST); + + bitStream.Write(affectPassive); + + SEND_PACKET_BROADCAST; +} + +void GameMessages::SendSetResurrectRestoreValues(Entity* targetEntity, int32_t armorRestore, int32_t healthRestore, int32_t imaginationRestore) { + CBITSTREAM; + CMSGHEADER; + + bitStream.Write(targetEntity->GetObjectID()); + bitStream.Write(GAME_MSG::GAME_MSG_SET_RESURRECT_RESTORE_VALUES); + + bitStream.Write(armorRestore != -1); + if (armorRestore != -1) bitStream.Write(armorRestore); + + bitStream.Write(healthRestore != -1); + if (healthRestore != -1) bitStream.Write(healthRestore); + + bitStream.Write(imaginationRestore != -1); + if (imaginationRestore != -1) bitStream.Write(imaginationRestore); + + SEND_PACKET_BROADCAST; +} void GameMessages::SendNotifyRacingClient(LWOOBJID objectId, int32_t eventType, int32_t param1, LWOOBJID paramObj, std::u16string paramStr, LWOOBJID singleClient, const SystemAddress& sysAddr) { CBITSTREAM; @@ -4665,7 +4707,7 @@ void GameMessages::HandleBuyFromVendor(RakNet::BitStream* inStream, Entity* enti Entity* player = EntityManager::Instance()->GetEntity(user->GetLoggedInChar()); if (!player) return; - auto* propertyVendorComponent = static_cast(entity->GetComponent(COMPONENT_TYPE_PROPERTY_VENDOR)); + auto* propertyVendorComponent = static_cast(entity->GetComponent(eReplicaComponentType::PROPERTY_VENDOR)); if (propertyVendorComponent != nullptr) { propertyVendorComponent->OnBuyFromVendor(player, bConfirmed, item, count); @@ -4675,16 +4717,16 @@ void GameMessages::HandleBuyFromVendor(RakNet::BitStream* inStream, Entity* enti const auto isCommendationVendor = entity->GetLOT() == 13806; - VendorComponent* vend = static_cast(entity->GetComponent(COMPONENT_TYPE_VENDOR)); + VendorComponent* vend = static_cast(entity->GetComponent(eReplicaComponentType::VENDOR)); if (!vend && !isCommendationVendor) return; - InventoryComponent* inv = static_cast(player->GetComponent(COMPONENT_TYPE_INVENTORY)); + InventoryComponent* inv = static_cast(player->GetComponent(eReplicaComponentType::INVENTORY)); if (!inv) return; - CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance()->GetTable("ComponentsRegistry"); - CDItemComponentTable* itemComponentTable = CDClientManager::Instance()->GetTable("ItemComponent"); + CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance().GetTable(); + CDItemComponentTable* itemComponentTable = CDClientManager::Instance().GetTable(); - int itemCompID = compRegistryTable->GetByIDAndType(item, COMPONENT_TYPE_ITEM); + int itemCompID = compRegistryTable->GetByIDAndType(item, eReplicaComponentType::ITEM); CDItemComponent itemComp = itemComponentTable->GetItemComponentByID(itemCompID); Character* character = player->GetCharacter(); @@ -4764,19 +4806,19 @@ void GameMessages::HandleSellToVendor(RakNet::BitStream* inStream, Entity* entit if (!player) return; Character* character = player->GetCharacter(); if (!character) return; - InventoryComponent* inv = static_cast(player->GetComponent(COMPONENT_TYPE_INVENTORY)); + InventoryComponent* inv = static_cast(player->GetComponent(eReplicaComponentType::INVENTORY)); if (!inv) return; - VendorComponent* vend = static_cast(entity->GetComponent(COMPONENT_TYPE_VENDOR)); + VendorComponent* vend = static_cast(entity->GetComponent(eReplicaComponentType::VENDOR)); if (!vend) return; Item* item = inv->FindItemById(iObjID); if (!item) return; - CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance()->GetTable("ComponentsRegistry"); - CDItemComponentTable* itemComponentTable = CDClientManager::Instance()->GetTable("ItemComponent"); + CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance().GetTable(); + CDItemComponentTable* itemComponentTable = CDClientManager::Instance().GetTable(); - int itemCompID = compRegistryTable->GetByIDAndType(item->GetLot(), COMPONENT_TYPE_ITEM); + int itemCompID = compRegistryTable->GetByIDAndType(item->GetLot(), eReplicaComponentType::ITEM); CDItemComponent itemComp = itemComponentTable->GetItemComponentByID(itemCompID); // Items with a base value of 0 or max int are special items that should not be sold if they're not sub items @@ -4814,19 +4856,19 @@ void GameMessages::HandleBuybackFromVendor(RakNet::BitStream* inStream, Entity* if (!player) return; Character* character = player->GetCharacter(); if (!character) return; - InventoryComponent* inv = static_cast(player->GetComponent(COMPONENT_TYPE_INVENTORY)); + InventoryComponent* inv = static_cast(player->GetComponent(eReplicaComponentType::INVENTORY)); if (!inv) return; - VendorComponent* vend = static_cast(entity->GetComponent(COMPONENT_TYPE_VENDOR)); + VendorComponent* vend = static_cast(entity->GetComponent(eReplicaComponentType::VENDOR)); if (!vend) return; Item* item = inv->FindItemById(iObjID); if (!item) return; - CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance()->GetTable("ComponentsRegistry"); - CDItemComponentTable* itemComponentTable = CDClientManager::Instance()->GetTable("ItemComponent"); + CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance().GetTable(); + CDItemComponentTable* itemComponentTable = CDClientManager::Instance().GetTable(); - int itemCompID = compRegistryTable->GetByIDAndType(item->GetLot(), COMPONENT_TYPE_ITEM); + int itemCompID = compRegistryTable->GetByIDAndType(item->GetLot(), eReplicaComponentType::ITEM); CDItemComponent itemComp = itemComponentTable->GetItemComponentByID(itemCompID); float sellScalar = vend->GetSellScalar(); @@ -4968,7 +5010,7 @@ void GameMessages::HandleRebuildCancel(RakNet::BitStream* inStream, Entity* enti inStream->Read(bEarlyRelease); inStream->Read(userID); - RebuildComponent* rebComp = static_cast(entity->GetComponent(COMPONENT_TYPE_REBUILD)); + RebuildComponent* rebComp = static_cast(entity->GetComponent(eReplicaComponentType::QUICK_BUILD)); if (!rebComp) return; rebComp->CancelRebuild(EntityManager::Instance()->GetEntity(userID), eFailReason::REASON_CANCELED_EARLY); @@ -5001,7 +5043,7 @@ void GameMessages::HandleRequestUse(RakNet::BitStream* inStream, Entity* entity, if (bIsMultiInteractUse) { if (multiInteractType == 0) { - auto* missionOfferComponent = static_cast(interactedObject->GetComponent(COMPONENT_TYPE_MISSION_OFFER)); + auto* missionOfferComponent = static_cast(interactedObject->GetComponent(eReplicaComponentType::MISSION_OFFER)); if (missionOfferComponent != nullptr) { missionOfferComponent->OfferMissions(entity, multiInteractID); @@ -5014,7 +5056,7 @@ void GameMessages::HandleRequestUse(RakNet::BitStream* inStream, Entity* entity, } //Perform use task if possible: - auto missionComponent = static_cast(entity->GetComponent(COMPONENT_TYPE_MISSION)); + auto missionComponent = static_cast(entity->GetComponent(eReplicaComponentType::MISSION)); if (missionComponent == nullptr) return; @@ -5050,7 +5092,7 @@ void GameMessages::HandlePlayEmote(RakNet::BitStream* inStream, Entity* entity) } } else { Game::logger->LogDebug("GameMessages", "Target ID is empty, using backup"); - const auto scriptedEntities = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_SCRIPT); + const auto scriptedEntities = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::SCRIPT); const auto& referencePoint = entity->GetPosition(); @@ -5062,7 +5104,7 @@ void GameMessages::HandlePlayEmote(RakNet::BitStream* inStream, Entity* entity) } } - CDEmoteTableTable* emotes = CDClientManager::Instance()->GetTable("EmoteTable"); + CDEmoteTableTable* emotes = CDClientManager::Instance().GetTable(); if (emotes) { CDEmoteTable* emote = emotes->GetEmote(emoteID); if (emote) sAnimationName = emote->animationName; @@ -5080,7 +5122,7 @@ void GameMessages::HandleModularBuildConvertModel(RakNet::BitStream* inStream, E if (!user) return; Entity* character = EntityManager::Instance()->GetEntity(user->GetLoggedInChar()); if (!character) return; - InventoryComponent* inv = static_cast(character->GetComponent(COMPONENT_TYPE_INVENTORY)); + InventoryComponent* inv = static_cast(character->GetComponent(eReplicaComponentType::INVENTORY)); if (!inv) return; auto* item = inv->FindItemById(modelID); @@ -5123,7 +5165,7 @@ void GameMessages::HandleRespondToMission(RakNet::BitStream* inStream, Entity* e inStream->Read(isDefaultReward); if (isDefaultReward) inStream->Read(reward); - MissionComponent* missionComponent = static_cast(entity->GetComponent(COMPONENT_TYPE_MISSION)); + MissionComponent* missionComponent = static_cast(entity->GetComponent(eReplicaComponentType::MISSION)); if (!missionComponent) { Game::logger->Log("GameMessages", "Unable to get mission component for entity %llu to handle RespondToMission", playerID); return; @@ -5166,7 +5208,7 @@ void GameMessages::HandleMissionDialogOK(RakNet::BitStream* inStream, Entity* en } // Get the player's mission component - MissionComponent* missionComponent = static_cast(player->GetComponent(COMPONENT_TYPE_MISSION)); + MissionComponent* missionComponent = static_cast(player->GetComponent(eReplicaComponentType::MISSION)); if (!missionComponent) { Game::logger->Log("GameMessages", "Unable to get mission component for entity %llu to handle MissionDialogueOK", player->GetObjectID()); return; @@ -5190,7 +5232,7 @@ void GameMessages::HandleRequestLinkedMission(RakNet::BitStream* inStream, Entit auto* player = EntityManager::Instance()->GetEntity(playerId); - auto* missionOfferComponent = static_cast(entity->GetComponent(COMPONENT_TYPE_MISSION_OFFER)); + auto* missionOfferComponent = static_cast(entity->GetComponent(eReplicaComponentType::MISSION_OFFER)); if (missionOfferComponent != nullptr) { missionOfferComponent->OfferMissions(player, 0); @@ -5204,7 +5246,7 @@ void GameMessages::HandleHasBeenCollected(RakNet::BitStream* inStream, Entity* e Entity* player = EntityManager::Instance()->GetEntity(playerID); if (!player || !entity || entity->GetCollectibleID() == 0) return; - MissionComponent* missionComponent = static_cast(player->GetComponent(COMPONENT_TYPE_MISSION)); + MissionComponent* missionComponent = static_cast(player->GetComponent(eReplicaComponentType::MISSION)); if (missionComponent) { missionComponent->Progress(eMissionTaskType::COLLECTION, entity->GetLOT(), entity->GetObjectID()); } @@ -5307,7 +5349,7 @@ void GameMessages::HandleEquipItem(RakNet::BitStream* inStream, Entity* entity) inStream->Read(immediate); //twice? inStream->Read(objectID); - InventoryComponent* inv = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); + InventoryComponent* inv = static_cast(entity->GetComponent(eReplicaComponentType::INVENTORY)); if (!inv) return; Item* item = inv->FindItemById(objectID); @@ -5326,7 +5368,7 @@ void GameMessages::HandleUnequipItem(RakNet::BitStream* inStream, Entity* entity inStream->Read(immediate); inStream->Read(objectID); - InventoryComponent* inv = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); + InventoryComponent* inv = static_cast(entity->GetComponent(eReplicaComponentType::INVENTORY)); if (!inv) return; auto* item = inv->FindItemById(objectID); @@ -5401,7 +5443,7 @@ void GameMessages::HandleRemoveItemFromInventory(RakNet::BitStream* inStream, En inStream->Read(iTradeIDIsDefault); if (iTradeIDIsDefault) inStream->Read(iTradeID); - InventoryComponent* inv = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); + InventoryComponent* inv = static_cast(entity->GetComponent(eReplicaComponentType::INVENTORY)); if (!inv) return; auto* item = inv->FindItemById(iObjID); @@ -5444,7 +5486,7 @@ void GameMessages::HandleMoveItemInInventory(RakNet::BitStream* inStream, Entity inStream->Read(responseCode); inStream->Read(slot); - InventoryComponent* inv = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); + InventoryComponent* inv = static_cast(entity->GetComponent(eReplicaComponentType::INVENTORY)); if (!inv) return; auto* item = inv->FindItemById(iObjID); @@ -5521,7 +5563,7 @@ void GameMessages::HandleModularBuildFinish(RakNet::BitStream* inStream, Entity* if (!user) return; Entity* character = EntityManager::Instance()->GetEntity(user->GetLoggedInChar()); if (!character) return; - InventoryComponent* inv = static_cast(character->GetComponent(COMPONENT_TYPE_INVENTORY)); + InventoryComponent* inv = static_cast(character->GetComponent(eReplicaComponentType::INVENTORY)); if (!inv) return; Game::logger->Log("GameMessages", "Build finished"); @@ -5586,7 +5628,7 @@ void GameMessages::HandleModularBuildFinish(RakNet::BitStream* inStream, Entity* } } - ScriptComponent* script = static_cast(entity->GetComponent(COMPONENT_TYPE_SCRIPT)); + ScriptComponent* script = static_cast(entity->GetComponent(eReplicaComponentType::SCRIPT)); for (CppScripts::Script* script : CppScripts::GetEntityScripts(entity)) { script->OnModularBuildExit(entity, character, count >= 3, modList); @@ -5609,7 +5651,7 @@ void GameMessages::HandleDoneArrangingWithItem(RakNet::BitStream* inStream, Enti if (!user) return; Entity* character = EntityManager::Instance()->GetEntity(user->GetLoggedInChar()); if (!character) return; - InventoryComponent* inv = static_cast(character->GetComponent(COMPONENT_TYPE_INVENTORY)); + InventoryComponent* inv = static_cast(character->GetComponent(eReplicaComponentType::INVENTORY)); if (!inv) return; /** @@ -5660,7 +5702,7 @@ void GameMessages::HandleDoneArrangingWithItem(RakNet::BitStream* inStream, Enti */ if (PropertyManagementComponent::Instance() != nullptr) { - const auto& buildAreas = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_BUILD_BORDER); + const auto& buildAreas = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::BUILD_BORDER); const auto& entities = EntityManager::Instance()->GetEntitiesInGroup("PropertyPlaque"); @@ -5727,7 +5769,7 @@ void GameMessages::HandleModularBuildMoveAndEquip(RakNet::BitStream* inStream, E inStream->Read(templateID); - InventoryComponent* inv = static_cast(character->GetComponent(COMPONENT_TYPE_INVENTORY)); + InventoryComponent* inv = static_cast(character->GetComponent(eReplicaComponentType::INVENTORY)); if (!inv) return; auto* item = inv->FindItemByLot(templateID, TEMP_MODELS); @@ -5768,7 +5810,7 @@ void GameMessages::HandleResurrect(RakNet::BitStream* inStream, Entity* entity) script->OnPlayerResurrected(zoneControl, entity); } - std::vector scriptedActs = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_SCRIPTED_ACTIVITY); + std::vector scriptedActs = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::SCRIPTED_ACTIVITY); for (Entity* scriptEntity : scriptedActs) { if (scriptEntity->GetObjectID() != zoneControl->GetObjectID()) { // Don't want to trigger twice on instance worlds for (CppScripts::Script* script : CppScripts::GetEntityScripts(scriptEntity)) { @@ -5779,13 +5821,13 @@ void GameMessages::HandleResurrect(RakNet::BitStream* inStream, Entity* entity) } void GameMessages::HandlePushEquippedItemsState(RakNet::BitStream* inStream, Entity* entity) { - InventoryComponent* inv = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); + InventoryComponent* inv = static_cast(entity->GetComponent(eReplicaComponentType::INVENTORY)); if (!inv) return; inv->PushEquippedItems(); } void GameMessages::HandlePopEquippedItemsState(RakNet::BitStream* inStream, Entity* entity) { - InventoryComponent* inv = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); + InventoryComponent* inv = static_cast(entity->GetComponent(eReplicaComponentType::INVENTORY)); if (!inv) return; inv->PopEquippedItems(); EntityManager::Instance()->SerializeEntity(entity); // so it updates on client side @@ -5797,7 +5839,7 @@ void GameMessages::HandleClientItemConsumed(RakNet::BitStream* inStream, Entity* inStream->Read(itemConsumed); - auto* inventory = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); + auto* inventory = static_cast(entity->GetComponent(eReplicaComponentType::INVENTORY)); if (inventory == nullptr) { return; @@ -5811,7 +5853,7 @@ void GameMessages::HandleClientItemConsumed(RakNet::BitStream* inStream, Entity* item->Consume(); - auto* missions = static_cast(entity->GetComponent(COMPONENT_TYPE_MISSION)); + auto* missions = static_cast(entity->GetComponent(eReplicaComponentType::MISSION)); if (missions != nullptr) { missions->Progress(eMissionTaskType::USE_ITEM, itemLot); } @@ -5823,7 +5865,7 @@ void GameMessages::HandleUseNonEquipmentItem(RakNet::BitStream* inStream, Entity inStream->Read(itemConsumed); - auto* inv = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); + auto* inv = static_cast(entity->GetComponent(eReplicaComponentType::INVENTORY)); if (!inv) return; @@ -5854,11 +5896,11 @@ void GameMessages::HandleMatchRequest(RakNet::BitStream* inStream, Entity* entit inStream->Read(type); inStream->Read(value); - std::vector scriptedActs = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_SCRIPTED_ACTIVITY); + std::vector scriptedActs = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::SCRIPTED_ACTIVITY); if (type == 0) { // join if (value != 0) { for (Entity* scriptedAct : scriptedActs) { - ScriptedActivityComponent* comp = static_cast(scriptedAct->GetComponent(COMPONENT_TYPE_SCRIPTED_ACTIVITY)); + ScriptedActivityComponent* comp = static_cast(scriptedAct->GetComponent(eReplicaComponentType::SCRIPTED_ACTIVITY)); if (!comp) continue; if (comp->GetActivityID() == value) { comp->PlayerJoin(entity); @@ -5869,7 +5911,7 @@ void GameMessages::HandleMatchRequest(RakNet::BitStream* inStream, Entity* entit } } else if (type == 1) { // ready/unready for (Entity* scriptedAct : scriptedActs) { - ScriptedActivityComponent* comp = static_cast(scriptedAct->GetComponent(COMPONENT_TYPE_SCRIPTED_ACTIVITY)); + ScriptedActivityComponent* comp = static_cast(scriptedAct->GetComponent(eReplicaComponentType::SCRIPTED_ACTIVITY)); if (!comp) continue; if (comp->PlayerIsInQueue(entity)) { comp->PlayerReady(entity, value); @@ -5987,7 +6029,7 @@ void GameMessages::HandleReportBug(RakNet::BitStream* inStream, Entity* entity) void GameMessages::HandleClientRailMovementReady(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) { - const auto possibleRails = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_RAIL_ACTIVATOR); + const auto possibleRails = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::RAIL_ACTIVATOR); for (const auto* possibleRail : possibleRails) { const auto* rail = possibleRail->GetComponent(); if (rail != nullptr) { @@ -5999,7 +6041,7 @@ GameMessages::HandleClientRailMovementReady(RakNet::BitStream* inStream, Entity* void GameMessages::HandleCancelRailMovement(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) { const auto immediate = inStream->ReadBit(); - const auto possibleRails = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_RAIL_ACTIVATOR); + const auto possibleRails = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::RAIL_ACTIVATOR); for (const auto* possibleRail : possibleRails) { auto* rail = possibleRail->GetComponent(); if (rail != nullptr) { @@ -6023,7 +6065,7 @@ void GameMessages::HandlePlayerRailArrivedNotification(RakNet::BitStream* inStre int32_t waypointNumber; inStream->Read(waypointNumber); - const auto possibleRails = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_RAIL_ACTIVATOR); + const auto possibleRails = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::RAIL_ACTIVATOR); for (auto* possibleRail : possibleRails) { for (CppScripts::Script* script : CppScripts::GetEntityScripts(possibleRail)) { script->OnPlayerRailArrived(possibleRail, entity, pathName, waypointNumber); diff --git a/dGame/dGameMessages/GameMessages.h b/dGame/dGameMessages/GameMessages.h index 0675ae76..5d199995 100644 --- a/dGame/dGameMessages/GameMessages.h +++ b/dGame/dGameMessages/GameMessages.h @@ -31,7 +31,8 @@ namespace GameMessages { void SendPlayerAllowedRespawn(LWOOBJID entityID, bool doNotPromptRespawn, const SystemAddress& systemAddress); void SendInvalidZoneTransferList(Entity* entity, const SystemAddress& sysAddr, const std::u16string& feedbackURL, const std::u16string& invalidMapTransferList, bool feedbackOnExit, bool feedbackOnInvalidTransfer); void SendKnockback(const LWOOBJID& objectID, const LWOOBJID& caster, const LWOOBJID& originator, int knockBackTimeMS, const NiPoint3& vector); - + // https://lcdruniverse.org/lu_packets/lu_packets/world/gm/client/struct.VehicleStopBoost.html + void SendVehicleStopBoost(Entity* targetEntity, const SystemAddress& playerSysAddr, bool affectPassive); void SendStartArrangingWithItem( Entity* entity, const SystemAddress& sysAddr, @@ -125,6 +126,9 @@ namespace GameMessages { void HandleUnUseModel(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr); void SendStartCelebrationEffect(Entity* entity, const SystemAddress& sysAddr, int celebrationID); + // https://lcdruniverse.org/lu_packets/lu_packets/world/gm/client/struct.SetResurrectRestoreValues.html + void SendSetResurrectRestoreValues(Entity* targetEntity, int32_t armorRestore, int32_t healthRestore, int32_t imaginationRestore); + /** * Sends a message to an Entity to smash itself, but not delete or destroy itself from the world * diff --git a/dGame/dGameMessages/PropertyDataMessage.cpp b/dGame/dGameMessages/PropertyDataMessage.cpp index e0b792ad..c3443f31 100644 --- a/dGame/dGameMessages/PropertyDataMessage.cpp +++ b/dGame/dGameMessages/PropertyDataMessage.cpp @@ -6,6 +6,8 @@ #include "dLogger.h" #include "CDClientManager.h" +#include "CDPropertyTemplateTable.h" + void GameMessages::PropertyDataMessage::Serialize(RakNet::BitStream& stream) const { stream.Write(0); // - property id @@ -101,8 +103,7 @@ void GameMessages::PropertyDataMessage::Serialize(RakNet::BitStream& stream) con } GameMessages::PropertyDataMessage::PropertyDataMessage(uint32_t mapID) { - const auto propertyTemplate = CDClientManager::Instance()-> - GetTable("PropertyTemplate")->GetByMapID(mapID); + const auto propertyTemplate = CDClientManager::Instance().GetTable()->GetByMapID(mapID); TemplateID = propertyTemplate.id; ZoneId = propertyTemplate.mapID; diff --git a/dGame/dInventory/Inventory.cpp b/dGame/dInventory/Inventory.cpp index 69a643ae..d752f87d 100644 --- a/dGame/dInventory/Inventory.cpp +++ b/dGame/dInventory/Inventory.cpp @@ -4,6 +4,9 @@ #include "Item.h" #include "InventoryComponent.h" #include "eItemType.h" +#include "eReplicaComponentType.h" + +#include "CDComponentsRegistryTable.h" std::vector Inventory::m_GameMasterRestrictedItems = { 1727, // GM Only - JetPack @@ -273,11 +276,11 @@ eInventoryType Inventory::FindInventoryTypeForLot(const LOT lot) { } const CDItemComponent& Inventory::FindItemComponent(const LOT lot) { - auto* registry = CDClientManager::Instance()->GetTable("ComponentsRegistry"); + auto* registry = CDClientManager::Instance().GetTable(); - auto* itemComponents = CDClientManager::Instance()->GetTable("ItemComponent"); + auto* itemComponents = CDClientManager::Instance().GetTable(); - const auto componentId = registry->GetByIDAndType(lot, COMPONENT_TYPE_ITEM); + const auto componentId = registry->GetByIDAndType(lot, eReplicaComponentType::ITEM); if (componentId == 0) { Game::logger->Log("Inventory", "Failed to find item component for (%i)!", lot); @@ -291,9 +294,9 @@ const CDItemComponent& Inventory::FindItemComponent(const LOT lot) { } bool Inventory::IsValidItem(const LOT lot) { - auto* registry = CDClientManager::Instance()->GetTable("ComponentsRegistry"); + auto* registry = CDClientManager::Instance().GetTable(); - const auto componentId = registry->GetByIDAndType(lot, COMPONENT_TYPE_ITEM); + const auto componentId = registry->GetByIDAndType(lot, eReplicaComponentType::ITEM); return componentId != 0; } diff --git a/dGame/dInventory/Inventory.h b/dGame/dInventory/Inventory.h index cd381db3..5e0ac8d6 100644 --- a/dGame/dInventory/Inventory.h +++ b/dGame/dInventory/Inventory.h @@ -6,7 +6,7 @@ #include #include - +#include "CDItemComponentTable.h" #include "CDClientManager.h" #include "dCommonVars.h" diff --git a/dGame/dInventory/Item.cpp b/dGame/dInventory/Item.cpp index 2a054ae8..acaecbf7 100644 --- a/dGame/dInventory/Item.cpp +++ b/dGame/dInventory/Item.cpp @@ -16,6 +16,12 @@ #include "AssetManager.h" #include "InventoryComponent.h" #include "Loot.h" +#include "eReplicaComponentType.h" + +#include "CDBrickIDTableTable.h" +#include "CDObjectSkillsTable.h" +#include "CDComponentsRegistryTable.h" +#include "CDPackageComponentTable.h" Item::Item(const LWOOBJID id, const LOT lot, Inventory* inventory, const uint32_t slot, const uint32_t count, const bool bound, const std::vector& config, const LWOOBJID parent, LWOOBJID subKey, eLootSourceType lootSourceType) { if (!Inventory::IsValidItem(lot)) { @@ -237,7 +243,7 @@ bool Item::IsEquipped() const { } bool Item::Consume() { - auto* skillsTable = CDClientManager::Instance()->GetTable("ObjectSkills"); + auto* skillsTable = CDClientManager::Instance().GetTable(); auto skills = skillsTable->Query([=](const CDObjectSkills entry) { return entry.objectTemplate == static_cast(lot); @@ -296,12 +302,12 @@ void Item::UseNonEquip(Item* item) { bool success = false; auto inventory = item->GetInventory(); if (inventory && inventory->GetType() == eInventoryType::ITEMS) { - auto* compRegistryTable = CDClientManager::Instance()->GetTable("ComponentsRegistry"); - const auto packageComponentId = compRegistryTable->GetByIDAndType(lot, COMPONENT_TYPE_PACKAGE); + auto* compRegistryTable = CDClientManager::Instance().GetTable(); + const auto packageComponentId = compRegistryTable->GetByIDAndType(lot, eReplicaComponentType::PACKAGE); if (packageComponentId == 0) return; - auto* packCompTable = CDClientManager::Instance()->GetTable("PackageComponent"); + auto* packCompTable = CDClientManager::Instance().GetTable(); auto packages = packCompTable->Query([=](const CDPackageComponent entry) {return entry.id == static_cast(packageComponentId); }); auto success = !packages.empty(); @@ -379,9 +385,9 @@ void Item::Disassemble(const eInventoryType inventoryType) { } void Item::DisassembleModel() { - auto* table = CDClientManager::Instance()->GetTable("ComponentsRegistry"); + auto* table = CDClientManager::Instance().GetTable(); - const auto componentId = table->GetByIDAndType(GetLot(), COMPONENT_TYPE_RENDER); + const auto componentId = table->GetByIDAndType(GetLot(), eReplicaComponentType::RENDER); auto query = CDClientDatabase::CreatePreppedStmt( "SELECT render_asset FROM RenderComponent WHERE id = ?;"); @@ -456,7 +462,7 @@ void Item::DisassembleModel() { currentBrick = currentBrick->NextSiblingElement(searchTerm.c_str()); } - auto* brickIDTable = CDClientManager::Instance()->GetTable("BrickIDTable"); + auto* brickIDTable = CDClientManager::Instance().GetTable(); for (unsigned int part : parts) { const auto brickID = brickIDTable->Query([=](const CDBrickIDTable& entry) { diff --git a/dGame/dInventory/ItemSet.cpp b/dGame/dInventory/ItemSet.cpp index e246f9f7..a8e58739 100644 --- a/dGame/dInventory/ItemSet.cpp +++ b/dGame/dInventory/ItemSet.cpp @@ -9,6 +9,8 @@ #include "eMissionTaskType.h" #include +#include "CDSkillBehaviorTable.h" + ItemSet::ItemSet(const uint32_t id, InventoryComponent* inventoryComponent) { this->m_ID = id; this->m_InventoryComponent = inventoryComponent; @@ -127,7 +129,7 @@ void ItemSet::OnEquip(const LOT lot) { auto* missionComponent = m_InventoryComponent->GetParent()->GetComponent(); for (const auto skill : skillSet) { - auto* skillTable = CDClientManager::Instance()->GetTable("SkillBehavior"); + auto* skillTable = CDClientManager::Instance().GetTable(); const auto behaviorId = skillTable->GetSkillByID(skill).behaviorID; @@ -159,7 +161,7 @@ void ItemSet::OnUnEquip(const LOT lot) { const auto& skillComponent = m_InventoryComponent->GetParent()->GetComponent(); for (const auto skill : skillSet) { - auto* skillTable = CDClientManager::Instance()->GetTable("SkillBehavior"); + auto* skillTable = CDClientManager::Instance().GetTable(); const auto behaviorId = skillTable->GetSkillByID(skill).behaviorID; diff --git a/dGame/dMission/Mission.cpp b/dGame/dMission/Mission.cpp index 0e1acdac..9cfdaaa7 100644 --- a/dGame/dMission/Mission.cpp +++ b/dGame/dMission/Mission.cpp @@ -23,7 +23,9 @@ #include "eMissionState.h" #include "eMissionTaskType.h" #include "eMissionLockState.h" +#include "eReplicaComponentType.h" +#include "CDMissionEmailTable.h" Mission::Mission(MissionComponent* missionComponent, const uint32_t missionId) { m_MissionComponent = missionComponent; @@ -38,7 +40,7 @@ Mission::Mission(MissionComponent* missionComponent, const uint32_t missionId) { m_State = eMissionState::UNKNOWN; - auto* missionsTable = CDClientManager::Instance()->GetTable("Missions"); + auto* missionsTable = CDClientManager::Instance().GetTable(); info = missionsTable->GetPtrByMissionID(missionId); @@ -48,7 +50,7 @@ Mission::Mission(MissionComponent* missionComponent, const uint32_t missionId) { return; } - auto* tasksTable = CDClientManager::Instance()->GetTable("MissionTasks"); + auto* tasksTable = CDClientManager::Instance().GetTable(); auto tasks = tasksTable->GetByMissionID(missionId); @@ -176,7 +178,7 @@ void Mission::UpdateXml(tinyxml2::XMLElement* element) { } bool Mission::IsValidMission(const uint32_t missionId) { - auto* table = CDClientManager::Instance()->GetTable("Missions"); + auto* table = CDClientManager::Instance().GetTable(); const auto missions = table->Query([=](const CDMissions& entry) { return entry.id == static_cast(missionId); @@ -186,7 +188,7 @@ bool Mission::IsValidMission(const uint32_t missionId) { } bool Mission::IsValidMission(const uint32_t missionId, CDMissions& info) { - auto* table = CDClientManager::Instance()->GetTable("Missions"); + auto* table = CDClientManager::Instance().GetTable(); const auto missions = table->Query([=](const CDMissions& entry) { return entry.id == static_cast(missionId); @@ -330,7 +332,7 @@ void Mission::Complete(const bool yieldRewards) { missionComponent->Progress(eMissionTaskType::RACING, info->id, (LWOOBJID)eRacingTaskParam::COMPLETE_TRACK_TASKS); - auto* missionEmailTable = CDClientManager::Instance()->GetTable("MissionEmail"); + auto* missionEmailTable = CDClientManager::Instance().GetTable(); const auto missionId = GetMissionId(); @@ -370,7 +372,7 @@ void Mission::CheckCompletion() { void Mission::Catchup() { auto* entity = GetAssociate(); - auto* inventory = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); + auto* inventory = static_cast(entity->GetComponent(eReplicaComponentType::INVENTORY)); for (auto* task : m_Tasks) { const auto type = task->GetType(); diff --git a/dGame/dMission/MissionPrerequisites.cpp b/dGame/dMission/MissionPrerequisites.cpp index 6b55151c..ec4522b9 100644 --- a/dGame/dMission/MissionPrerequisites.cpp +++ b/dGame/dMission/MissionPrerequisites.cpp @@ -163,7 +163,7 @@ bool MissionPrerequisites::CheckPrerequisites(uint32_t missionId, const std::uno return index->second->Execute(missions); } - auto* missionsTable = CDClientManager::Instance()->GetTable("Missions"); + auto* missionsTable = CDClientManager::Instance().GetTable(); const auto missionEntries = missionsTable->Query([=](const CDMissions& entry) { return entry.id == static_cast(missionId); }); diff --git a/dGame/dMission/MissionTask.cpp b/dGame/dMission/MissionTask.cpp index e339d232..344427c6 100644 --- a/dGame/dMission/MissionTask.cpp +++ b/dGame/dMission/MissionTask.cpp @@ -14,6 +14,7 @@ #include "InventoryComponent.h" #include "MissionComponent.h" #include "eMissionTaskType.h" +#include "eReplicaComponentType.h" MissionTask::MissionTask(Mission* mission, CDMissionTasks* info, uint32_t mask) { this->info = info; @@ -237,7 +238,7 @@ void MissionTask::Progress(int32_t value, LWOOBJID associate, const std::string& break; } - activity = static_cast(entity->GetComponent(COMPONENT_TYPE_REBUILD)); + activity = static_cast(entity->GetComponent(eReplicaComponentType::QUICK_BUILD)); if (activity == nullptr) { break; } diff --git a/dGame/dPropertyBehaviors/BehaviorStates.h b/dGame/dPropertyBehaviors/BehaviorStates.h index e09e45ba..80cb1dbb 100644 --- a/dGame/dPropertyBehaviors/BehaviorStates.h +++ b/dGame/dPropertyBehaviors/BehaviorStates.h @@ -3,12 +3,9 @@ #ifndef __BEHAVIORSTATES__H__ #define __BEHAVIORSTATES__H__ -#include #include -#include "dCommonVars.h" - -enum States : BEHAVIORSTATE { +enum class BehaviorState : uint32_t { HOME_STATE = 0, //!< The HOME behavior state CIRCLE_STATE, //!< The CIRCLE behavior state SQUARE_STATE, //!< The SQUARE behavior state diff --git a/dGame/dPropertyBehaviors/BlockDefinition.cpp b/dGame/dPropertyBehaviors/BlockDefinition.cpp new file mode 100644 index 00000000..2950ac82 --- /dev/null +++ b/dGame/dPropertyBehaviors/BlockDefinition.cpp @@ -0,0 +1,9 @@ +#include "BlockDefinition.h" + +BlockDefinition BlockDefinition::blockDefinitionDefault{}; + +BlockDefinition::BlockDefinition(std::string defaultValue, float minimumValue, float maximumValue) { + this->defaultValue = defaultValue; + this->minimumValue = minimumValue; + this->maximumValue = maximumValue; +} diff --git a/dGame/dPropertyBehaviors/BlockDefinition.h b/dGame/dPropertyBehaviors/BlockDefinition.h new file mode 100644 index 00000000..3a5a6bf1 --- /dev/null +++ b/dGame/dPropertyBehaviors/BlockDefinition.h @@ -0,0 +1,25 @@ +#ifndef __BLOCKDEFINITION__H__ +#define __BLOCKDEFINITION__H__ + +#include + +class AMFArrayValue; + +class BlockDefinition { +public: + BlockDefinition(std::string defaultValue = "", float minimumValue = 0.0f, float maximumValue = 0.0f); + static BlockDefinition blockDefinitionDefault; + + std::string& GetDefaultValue() { return defaultValue; }; + float GetMinimumValue() { return minimumValue; }; + float GetMaximumValue() { return maximumValue; }; + void SetDefaultValue(std::string value) { defaultValue = value; }; + void SetMinimumValue(float value) { minimumValue = value; }; + void SetMaximumValue(float value) { maximumValue = value; }; +private: + std::string defaultValue; + float minimumValue; + float maximumValue; +}; + +#endif //!__BLOCKDEFINITION__H__ diff --git a/dGame/dPropertyBehaviors/CMakeLists.txt b/dGame/dPropertyBehaviors/CMakeLists.txt index 4f5d60aa..5e33a5f5 100644 --- a/dGame/dPropertyBehaviors/CMakeLists.txt +++ b/dGame/dPropertyBehaviors/CMakeLists.txt @@ -1,4 +1,12 @@ set(DGAME_DPROPERTYBEHAVIORS_SOURCES + "BlockDefinition.cpp" "ControlBehaviors.cpp" - PARENT_SCOPE ) + +add_subdirectory(ControlBehaviorMessages) + +foreach(file ${DGAME_DPROPERTYBEHAVIORS_CONTROLBEHAVIORMESSAGES}) + set(DGAME_DPROPERTYBEHAVIORS_SOURCES ${DGAME_DPROPERTYBEHAVIORS_SOURCES} "ControlBehaviorMessages/${file}") +endforeach() + +set(DGAME_DPROPERTYBEHAVIORS_SOURCES ${DGAME_DPROPERTYBEHAVIORS_SOURCES} PARENT_SCOPE) diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.cpp new file mode 100644 index 00000000..7da286b0 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.cpp @@ -0,0 +1,31 @@ +#include "Action.h" + +Action::Action() { + type = ""; + valueParameterName = ""; + valueParameterString = ""; + valueParameterDouble = 0.0; +} + +Action::Action(AMFArrayValue* arguments) { + type = ""; + valueParameterName = ""; + valueParameterString = ""; + valueParameterDouble = 0.0; + for (auto& typeValueMap : arguments->GetAssociativeMap()) { + if (typeValueMap.first == "Type") { + if (typeValueMap.second->GetValueType() != AMFValueType::AMFString) continue; + type = static_cast(typeValueMap.second)->GetStringValue(); + } else { + valueParameterName = typeValueMap.first; + // Message is the only known string parameter + if (valueParameterName == "Message") { + if (typeValueMap.second->GetValueType() != AMFValueType::AMFString) continue; + valueParameterString = static_cast(typeValueMap.second)->GetStringValue(); + } else { + if (typeValueMap.second->GetValueType() != AMFValueType::AMFDouble) continue; + valueParameterDouble = static_cast(typeValueMap.second)->GetDoubleValue(); + } + } + } +} diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.h new file mode 100644 index 00000000..c97b4050 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.h @@ -0,0 +1,25 @@ +#ifndef __ACTION__H__ +#define __ACTION__H__ + +#include "BehaviorMessageBase.h" + +/** + * @brief Sent if a ControlBehavior message has an Action associated with it + * + */ +class Action { +public: + Action(); + Action(AMFArrayValue* arguments); + const std::string& GetType() { return type; }; + const std::string& GetValueParameterName() { return valueParameterName; }; + const std::string& GetValueParameterString() { return valueParameterString; }; + const double GetValueParameterDouble() { return valueParameterDouble; }; +private: + std::string type; + std::string valueParameterName; + std::string valueParameterString; + double valueParameterDouble; +}; + +#endif //!__ACTION__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.cpp new file mode 100644 index 00000000..480eef45 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.cpp @@ -0,0 +1,31 @@ +#include "ActionContext.h" + +#include + +#include "AMFFormat.h" + +ActionContext::ActionContext() { + stripId = 0; + stateId = BehaviorState::HOME_STATE; +} + +ActionContext::ActionContext(AMFArrayValue* arguments, std::string customStateKey, std::string customStripKey) { + stripId = 0; + stateId = BehaviorState::HOME_STATE; + stripId = GetStripIdFromArgument(arguments, customStripKey); + stateId = GetBehaviorStateFromArgument(arguments, customStateKey); +} + +BehaviorState ActionContext::GetBehaviorStateFromArgument(AMFArrayValue* arguments, const std::string& key) { + auto* stateIDValue = arguments->FindValue(key); + if (!stateIDValue) throw std::invalid_argument("Unable to find behavior state from argument \"" + key + "\""); + + return static_cast(stateIDValue->GetDoubleValue()); +} + +StripId ActionContext::GetStripIdFromArgument(AMFArrayValue* arguments, const std::string& key) { + auto* stripIdValue = arguments->FindValue(key); + if (!stripIdValue) throw std::invalid_argument("Unable to find strip ID from argument \"" + key + "\""); + + return static_cast(stripIdValue->GetDoubleValue()); +} diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.h new file mode 100644 index 00000000..5f46fd8c --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/ActionContext.h @@ -0,0 +1,26 @@ +#ifndef __ACTIONCONTEXT__H__ +#define __ACTIONCONTEXT__H__ + +#include "BehaviorStates.h" +#include "dCommonVars.h" + +class AMFArrayValue; + +/** + * @brief Sent if contextual State and Strip informationis needed for a ControlBehaviors message + * + */ +class ActionContext { +public: + ActionContext(); + ActionContext(AMFArrayValue* arguments, std::string customStateKey = "stateID", std::string customStripKey = "stripID"); + const StripId GetStripId() { return stripId; }; + const BehaviorState GetStateId() { return stateId; }; +private: + BehaviorState GetBehaviorStateFromArgument(AMFArrayValue* arguments, const std::string& key); + StripId GetStripIdFromArgument(AMFArrayValue* arguments, const std::string& key); + StripId stripId; + BehaviorState stateId; +}; + +#endif //!__ACTIONCONTEXT__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.cpp new file mode 100644 index 00000000..4fc7f82b --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.cpp @@ -0,0 +1,13 @@ +#include "AddActionMessage.h" + +AddActionMessage::AddActionMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { + actionContext = ActionContext(arguments); + actionIndex = GetActionIndexFromArgument(arguments); + + auto* actionValue = arguments->FindValue("action"); + if (!actionValue) return; + + action = Action(actionValue); + + Game::logger->LogDebug("AddActionMessage", "actionIndex %i stripId %i stateId %i type %s valueParameterName %s valueParameterString %s valueParameterDouble %f behaviorId %i", actionIndex, actionContext.GetStripId(), actionContext.GetStateId(), action.GetType().c_str(), action.GetValueParameterName().c_str(), action.GetValueParameterString().c_str(), action.GetValueParameterDouble(), behaviorId); +} diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.h new file mode 100644 index 00000000..4faf6a53 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddActionMessage.h @@ -0,0 +1,26 @@ +#ifndef __ADDACTIONMESSAGE__H__ +#define __ADDACTIONMESSAGE__H__ + +#include "Action.h" +#include "ActionContext.h" +#include "BehaviorMessageBase.h" + +class AMFArrayValue; + +/** + * @brief Send if a player takes an Action A from the toolbox and adds it to an already existing strip + * + */ +class AddActionMessage : public BehaviorMessageBase { +public: + AddActionMessage(AMFArrayValue* arguments); + const uint32_t GetActionIndex() { return actionIndex; }; + Action GetAction() { return action; }; + ActionContext GetActionContext() { return actionContext; }; +private: + uint32_t actionIndex; + ActionContext actionContext; + Action action; +}; + +#endif //!__ADDACTIONMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.cpp new file mode 100644 index 00000000..4f2123b4 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.cpp @@ -0,0 +1,11 @@ +#include "AddMessage.h" + +AddMessage::AddMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { + behaviorIndex = 0; + auto* behaviorIndexValue = arguments->FindValue("BehaviorIndex"); + + if (!behaviorIndexValue) return; + + behaviorIndex = static_cast(behaviorIndexValue->GetDoubleValue()); + Game::logger->LogDebug("AddMessage", "behaviorId %i index %i", behaviorId, behaviorIndex); +} diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.h new file mode 100644 index 00000000..a46d5f98 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddMessage.h @@ -0,0 +1,18 @@ +#ifndef __ADDMESSAGE__H__ +#define __ADDMESSAGE__H__ + +#include "BehaviorMessageBase.h" + +/** + * @brief Sent when a player adds a Behavior A from their inventory to a model. + * + */ +class AddMessage : public BehaviorMessageBase { +public: + AddMessage(AMFArrayValue* arguments); + const uint32_t GetBehaviorIndex() { return behaviorIndex; }; +private: + uint32_t behaviorIndex; +}; + +#endif //!__ADDMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp new file mode 100644 index 00000000..c4729c57 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp @@ -0,0 +1,25 @@ +#include "AddStripMessage.h" + +#include "Action.h" + +AddStripMessage::AddStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { + actionContext = ActionContext(arguments); + + position = StripUiPosition(arguments); + + auto* strip = arguments->FindValue("strip"); + if (!strip) return; + + auto* actions = strip->FindValue("actions"); + if (!actions) return; + + for (uint32_t actionNumber = 0; actionNumber < actions->GetDenseValueSize(); actionNumber++) { + auto* actionValue = actions->GetValueAt(actionNumber); + if (!actionValue) continue; + + actionsToAdd.push_back(Action(actionValue)); + + Game::logger->LogDebug("AddStripMessage", "xPosition %f yPosition %f stripId %i stateId %i behaviorId %i t %s valueParameterName %s valueParameterString %s valueParameterDouble %f", position.GetX(), position.GetY(), actionContext.GetStripId(), actionContext.GetStateId(), behaviorId, actionsToAdd.back().GetType().c_str(), actionsToAdd.back().GetValueParameterName().c_str(), actionsToAdd.back().GetValueParameterString().c_str(), actionsToAdd.back().GetValueParameterDouble()); + } + Game::logger->Log("AddStripMessage", "number of actions %i", actionsToAdd.size()); +} diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h new file mode 100644 index 00000000..db75aef7 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h @@ -0,0 +1,31 @@ +#ifndef __ADDSTRIPMESSAGE__H__ +#define __ADDSTRIPMESSAGE__H__ + +#include "ActionContext.h" +#include "BehaviorMessageBase.h" +#include "StripUiPosition.h" + +#include + +class Action; +class AMFArrayValue; + +/** + * @brief Sent in 2 contexts: + * A player adds an Action A from their toolbox without attaching it to an existing Strip. In this case, only 1 action is sent. + * A player moves a Strip from BehaviorState A directly to BehaviorState B. In this case, a list of actions are sent. + * + */ +class AddStripMessage : public BehaviorMessageBase { +public: + AddStripMessage(AMFArrayValue* arguments); + StripUiPosition GetPosition() { return position; }; + ActionContext GetActionContext() { return actionContext; }; + std::vector GetActionsToAdd() { return actionsToAdd; }; +private: + StripUiPosition position; + ActionContext actionContext; + std::vector actionsToAdd; +}; + +#endif //!__ADDSTRIPMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp new file mode 100644 index 00000000..b3d98d51 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp @@ -0,0 +1,33 @@ +#include "BehaviorMessageBase.h" + +#include "AMFFormat.h" +#include "BehaviorStates.h" +#include "dCommonVars.h" + +BehaviorMessageBase::BehaviorMessageBase(AMFArrayValue* arguments) { + behaviorId = 0; + behaviorId = GetBehaviorIdFromArgument(arguments); +} + +int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* arguments) { + const auto* key = "BehaviorID"; + auto* behaviorIDValue = arguments->FindValue(key); + int32_t behaviorID = -1; + + if (behaviorIDValue) { + behaviorID = std::stoul(behaviorIDValue->GetStringValue()); + } else if (!arguments->FindValue(key)) { + throw std::invalid_argument("Unable to find behavior ID"); + } + + return behaviorID; +} + +uint32_t BehaviorMessageBase::GetActionIndexFromArgument(AMFArrayValue* arguments, const std::string& keyName) { + auto* actionIndexAmf = arguments->FindValue(keyName); + if (!actionIndexAmf) { + throw std::invalid_argument("Unable to find actionIndex"); + } + + return static_cast(actionIndexAmf->GetDoubleValue()); +} diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h new file mode 100644 index 00000000..13b00a35 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h @@ -0,0 +1,29 @@ +#ifndef __BEHAVIORMESSAGEBASE__H__ +#define __BEHAVIORMESSAGEBASE__H__ + +#include +#include + +#include "AMFFormat.h" +#include "dCommonVars.h" + +#include "Game.h" +#include "dLogger.h" + +enum class BehaviorState : uint32_t; + +/** + * @brief The behaviorID target of this ControlBehaviors message + * + */ +class BehaviorMessageBase { +public: + const uint32_t GetBehaviorId() { return behaviorId; }; +protected: + BehaviorMessageBase(AMFArrayValue* arguments); + int32_t GetBehaviorIdFromArgument(AMFArrayValue* arguments); + uint32_t GetActionIndexFromArgument(AMFArrayValue* arguments, const std::string& keyName = "actionIndex"); + int32_t behaviorId = -1; +}; + +#endif //!__BEHAVIORMESSAGEBASE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/CMakeLists.txt b/dGame/dPropertyBehaviors/ControlBehaviorMessages/CMakeLists.txt new file mode 100644 index 00000000..49b0f460 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/CMakeLists.txt @@ -0,0 +1,20 @@ +set(DGAME_DPROPERTYBEHAVIORS_CONTROLBEHAVIORMESSAGES + "Action.cpp" + "ActionContext.cpp" + "AddActionMessage.cpp" + "AddMessage.cpp" + "AddStripMessage.cpp" + "BehaviorMessageBase.cpp" + "MergeStripsMessage.cpp" + "MigrateActionsMessage.cpp" + "MoveToInventoryMessage.cpp" + "RearrangeStripMessage.cpp" + "RemoveActionsMessage.cpp" + "RemoveStripMessage.cpp" + "RenameMessage.cpp" + "SplitStripMessage.cpp" + "StripUiPosition.cpp" + "UpdateActionMessage.cpp" + "UpdateStripUiMessage.cpp" + PARENT_SCOPE +) diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.cpp new file mode 100644 index 00000000..df50641a --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.cpp @@ -0,0 +1,11 @@ +#include "MergeStripsMessage.h" + +MergeStripsMessage::MergeStripsMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { + sourceActionContext = ActionContext(arguments, "srcStateID", "srcStripID"); + + destinationActionContext = ActionContext(arguments, "dstStateID", "dstStripID"); + dstActionIndex = GetActionIndexFromArgument(arguments, "dstActionIndex"); + + Game::logger->LogDebug("MergeStripsMessage", "srcstripId %i dststripId %i srcstateId %i dststateId %i dstactionIndex %i behaviorId %i", sourceActionContext.GetStripId(), destinationActionContext.GetStripId(), sourceActionContext.GetStateId(), destinationActionContext.GetStateId(), dstActionIndex, behaviorId); +} + diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.h new file mode 100644 index 00000000..0aff7f3a --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MergeStripsMessage.h @@ -0,0 +1,25 @@ +#ifndef __MERGESTRIPSMESSAGE__H__ +#define __MERGESTRIPSMESSAGE__H__ + +#include "ActionContext.h" +#include "BehaviorMessageBase.h" + +class AMFArrayValue; + +/** + * @brief Sent when a player adds the first Action of Strip A to a Strip B + * + */ +class MergeStripsMessage : public BehaviorMessageBase { +public: + MergeStripsMessage(AMFArrayValue* arguments); + const uint32_t GetDstActionIndex() { return dstActionIndex; }; + ActionContext GetSourceActionContext() { return sourceActionContext; }; + ActionContext GetDestinationActionContext() { return destinationActionContext; }; +private: + ActionContext sourceActionContext; + ActionContext destinationActionContext; + uint32_t dstActionIndex; +}; + +#endif //!__MERGESTRIPSMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.cpp new file mode 100644 index 00000000..08f830a4 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.cpp @@ -0,0 +1,11 @@ +#include "MigrateActionsMessage.h" + +MigrateActionsMessage::MigrateActionsMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { + sourceActionContext = ActionContext(arguments, "srcStateID", "srcStripID"); + srcActionIndex = GetActionIndexFromArgument(arguments, "srcActionIndex"); + + destinationActionContext = ActionContext(arguments, "dstStateID", "dstStripID"); + dstActionIndex = GetActionIndexFromArgument(arguments, "dstActionIndex"); + + Game::logger->LogDebug("MigrateActionsMessage", "srcactionIndex %i dstactionIndex %i srcstripId %i dststripId %i srcstateId %i dststateId %i behaviorId %i", srcActionIndex, dstActionIndex, sourceActionContext.GetStripId(), destinationActionContext.GetStripId(), sourceActionContext.GetStateId(), destinationActionContext.GetStateId(), behaviorId); +} diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.h new file mode 100644 index 00000000..f60e8748 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MigrateActionsMessage.h @@ -0,0 +1,27 @@ +#ifndef __MIGRATEACTIONSMESSAGE__H__ +#define __MIGRATEACTIONSMESSAGE__H__ + +#include "ActionContext.h" +#include "BehaviorMessageBase.h" + +class AMFArrayValue; + +/** + * @brief Sent when a player moves an Action after the first Action to a different Strip + * + */ +class MigrateActionsMessage : public BehaviorMessageBase { +public: + MigrateActionsMessage(AMFArrayValue* arguments); + const uint32_t GetSrcActionIndex() { return srcActionIndex; }; + const uint32_t GetDstActionIndex() { return dstActionIndex; }; + ActionContext GetSourceActionContext() { return sourceActionContext; }; + ActionContext GetDestinationActionContext() { return destinationActionContext; }; +private: + ActionContext sourceActionContext; + ActionContext destinationActionContext; + uint32_t srcActionIndex; + uint32_t dstActionIndex; +}; + +#endif //!__MIGRATEACTIONSMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.cpp new file mode 100644 index 00000000..92700076 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.cpp @@ -0,0 +1,9 @@ +#include "MoveToInventoryMessage.h" + +MoveToInventoryMessage::MoveToInventoryMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { + auto* behaviorIndexValue = arguments->FindValue("BehaviorIndex"); + if (!behaviorIndexValue) return; + + behaviorIndex = static_cast(behaviorIndexValue->GetDoubleValue()); + Game::logger->LogDebug("MoveToInventoryMessage", "behaviorId %i behaviorIndex %i", behaviorId, behaviorIndex); +} diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.h new file mode 100644 index 00000000..c48f7d17 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/MoveToInventoryMessage.h @@ -0,0 +1,21 @@ +#ifndef __MOVETOINVENTORYMESSAGE__H__ +#define __MOVETOINVENTORYMESSAGE__H__ + +#include "BehaviorMessageBase.h" + +class AMFArrayValue; + +/** + * @brief Sent when a player moves a Behavior A at position B to their inventory. + * + */ +#pragma warning("This Control Behavior Message does not have a test yet. Non-developers can ignore this warning.") +class MoveToInventoryMessage : public BehaviorMessageBase { +public: + MoveToInventoryMessage(AMFArrayValue* arguments); + const uint32_t GetBehaviorIndex() { return behaviorIndex; }; +private: + uint32_t behaviorIndex; +}; + +#endif //!__MOVETOINVENTORYMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.cpp new file mode 100644 index 00000000..4018a423 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.cpp @@ -0,0 +1,10 @@ +#include "RearrangeStripMessage.h" + +RearrangeStripMessage::RearrangeStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { + actionContext = ActionContext(arguments); + srcActionIndex = GetActionIndexFromArgument(arguments, "srcActionIndex"); + + dstActionIndex = GetActionIndexFromArgument(arguments, "dstActionIndex"); + + Game::logger->LogDebug("RearrangeStripMessage", "srcactionIndex %i dstactionIndex %i stripId %i behaviorId %i stateId %i", srcActionIndex, dstActionIndex, actionContext.GetStripId(), behaviorId, actionContext.GetStateId()); +} diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.h new file mode 100644 index 00000000..46819404 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RearrangeStripMessage.h @@ -0,0 +1,23 @@ +#ifndef __REARRANGESTRIPMESSAGE__H__ +#define __REARRANGESTRIPMESSAGE__H__ + +#include "ActionContext.h" +#include "BehaviorMessageBase.h" + +/** + * @brief Sent when a player moves an Action around in the same strip + * + */ +class RearrangeStripMessage : public BehaviorMessageBase { +public: + RearrangeStripMessage(AMFArrayValue* arguments); + const uint32_t GetSrcActionIndex() { return srcActionIndex; }; + const uint32_t GetDstActionIndex() { return dstActionIndex; }; + ActionContext GetActionContext() { return actionContext; }; +private: + ActionContext actionContext; + uint32_t srcActionIndex; + uint32_t dstActionIndex; +}; + +#endif //!__REARRANGESTRIPMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.cpp new file mode 100644 index 00000000..8f00d2b0 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.cpp @@ -0,0 +1,8 @@ +#include "RemoveActionsMessage.h" + +RemoveActionsMessage::RemoveActionsMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { + actionContext = ActionContext(arguments); + actionIndex = GetActionIndexFromArgument(arguments); + + Game::logger->LogDebug("RemoveActionsMessage", "behaviorId %i actionIndex %i stripId %i stateId %i", behaviorId, actionIndex, actionContext.GetStripId(), actionContext.GetStateId()); +} diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.h new file mode 100644 index 00000000..457ddba8 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveActionsMessage.h @@ -0,0 +1,23 @@ +#ifndef __REMOVEACTIONSMESSAGE__H__ +#define __REMOVEACTIONSMESSAGE__H__ + +#include "ActionContext.h" +#include "BehaviorMessageBase.h" + +class AMFArrayValue; + +/** + * @brief Sent when a player removes any Action after the first one from a Strip + * + */ +class RemoveActionsMessage : public BehaviorMessageBase { +public: + RemoveActionsMessage(AMFArrayValue* arguments); + const uint32_t GetActionIndex() { return actionIndex; }; + ActionContext GetActionContext() { return actionContext; }; +private: + ActionContext actionContext; + uint32_t actionIndex; +}; + +#endif //!__REMOVEACTIONSMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.cpp new file mode 100644 index 00000000..40288b07 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.cpp @@ -0,0 +1,7 @@ +#include "RemoveStripMessage.h" + +RemoveStripMessage::RemoveStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { + actionContext = ActionContext(arguments); + + Game::logger->LogDebug("RemoveStripMessage", "stripId %i stateId %i behaviorId %i", actionContext.GetStripId(), actionContext.GetStateId(), behaviorId); +} diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.h new file mode 100644 index 00000000..36e2e401 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RemoveStripMessage.h @@ -0,0 +1,19 @@ +#ifndef __REMOVESTRIPMESSAGE__H__ +#define __REMOVESTRIPMESSAGE__H__ + +#include "ActionContext.h" +#include "BehaviorMessageBase.h" + +/** + * @brief Sent when a player removes the first Action from a strip. + * + */ +class RemoveStripMessage : public BehaviorMessageBase { +public: + RemoveStripMessage(AMFArrayValue* arguments); + ActionContext GetActionContext() { return actionContext; }; +private: + ActionContext actionContext; +}; + +#endif //!__REMOVESTRIPMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.cpp new file mode 100644 index 00000000..0ea3b6d6 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.cpp @@ -0,0 +1,9 @@ +#include "RenameMessage.h" + +RenameMessage::RenameMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { + auto* nameAmf = arguments->FindValue("Name"); + if (!nameAmf) return; + + name = nameAmf->GetStringValue(); + Game::logger->LogDebug("RenameMessage", "behaviorId %i n %s", behaviorId, name.c_str()); +} diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.h new file mode 100644 index 00000000..ba181f63 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/RenameMessage.h @@ -0,0 +1,20 @@ +#ifndef __RENAMEMESSAGE__H__ +#define __RENAMEMESSAGE__H__ + +#include "BehaviorMessageBase.h" + +class AMFArrayValue; + +/** + * @brief Sent when a player renames this behavior + * + */ +class RenameMessage : public BehaviorMessageBase { +public: + RenameMessage(AMFArrayValue* arguments); + const std::string& GetName() { return name; }; +private: + std::string name; +}; + +#endif //!__RENAMEMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.cpp new file mode 100644 index 00000000..b4601a17 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.cpp @@ -0,0 +1,11 @@ +#include "SplitStripMessage.h" + +SplitStripMessage::SplitStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { + sourceActionContext = ActionContext(arguments, "srcStateID", "srcStripID"); + srcActionIndex = GetActionIndexFromArgument(arguments, "srcActionIndex"); + + destinationActionContext = ActionContext(arguments, "dstStateID", "dstStripID"); + destinationPosition = StripUiPosition(arguments, "dstStripUI"); + + Game::logger->LogDebug("SplitStripMessage", "behaviorId %i xPosition %f yPosition %f sourceStrip %i destinationStrip %i sourceState %i destinationState %i srcActindex %i", behaviorId, destinationPosition.GetX(), destinationPosition.GetY(), sourceActionContext.GetStripId(), destinationActionContext.GetStripId(), sourceActionContext.GetStateId(), destinationActionContext.GetStateId(), srcActionIndex); +} diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.h new file mode 100644 index 00000000..9210efb0 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/SplitStripMessage.h @@ -0,0 +1,28 @@ +#ifndef __SPLITSTRIPMESSAGE__H__ +#define __SPLITSTRIPMESSAGE__H__ + +#include "ActionContext.h" +#include "BehaviorMessageBase.h" +#include "StripUiPosition.h" + +class AMFArrayValue; + +/** + * @brief Sent when a player takes an Action from Strip A and does not add it to an existing strip + * + */ +class SplitStripMessage : public BehaviorMessageBase { +public: + SplitStripMessage(AMFArrayValue* arguments); + ActionContext GetSourceActionContext() { return sourceActionContext; }; + ActionContext GetDestinationActionContext() { return destinationActionContext; }; + const uint32_t GetSrcActionIndex() { return srcActionIndex; }; + StripUiPosition GetPosition() { return destinationPosition; }; +private: + ActionContext sourceActionContext; + ActionContext destinationActionContext; + uint32_t srcActionIndex; + StripUiPosition destinationPosition; +}; + +#endif //!__SPLITSTRIPMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.cpp new file mode 100644 index 00000000..4ddccc55 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.cpp @@ -0,0 +1,22 @@ +#include "StripUiPosition.h" + +#include "AMFFormat.h" + +StripUiPosition::StripUiPosition() { + xPosition = 0.0; + yPosition = 0.0; +} + +StripUiPosition::StripUiPosition(AMFArrayValue* arguments, std::string uiKeyName) { + xPosition = 0.0; + yPosition = 0.0; + auto* uiArray = arguments->FindValue(uiKeyName); + if (!uiArray) return; + + auto* xPositionValue = uiArray->FindValue("x"); + auto* yPositionValue = uiArray->FindValue("y"); + if (!xPositionValue || !yPositionValue) return; + + yPosition = yPositionValue->GetDoubleValue(); + xPosition = xPositionValue->GetDoubleValue(); +} diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.h new file mode 100644 index 00000000..809f8890 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/StripUiPosition.h @@ -0,0 +1,21 @@ +#ifndef __STRIPUIPOSITION__H__ +#define __STRIPUIPOSITION__H__ + +class AMFArrayValue; + +/** + * @brief The position of the first Action in a Strip + * + */ +class StripUiPosition { +public: + StripUiPosition(); + StripUiPosition(AMFArrayValue* arguments, std::string uiKeyName = "ui"); + double GetX() { return xPosition; }; + double GetY() { return yPosition; }; +private: + double xPosition; + double yPosition; +}; + +#endif //!__STRIPUIPOSITION__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.cpp new file mode 100644 index 00000000..53e2d570 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.cpp @@ -0,0 +1,15 @@ +#include "UpdateActionMessage.h" + +#include "Action.h" + +UpdateActionMessage::UpdateActionMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { + actionContext = ActionContext(arguments); + + auto* actionValue = arguments->FindValue("action"); + if (!actionValue) return; + + action = Action(actionValue); + actionIndex = GetActionIndexFromArgument(arguments); + + Game::logger->LogDebug("UpdateActionMessage", "type %s valueParameterName %s valueParameterString %s valueParameterDouble %f behaviorId %i actionIndex %i stripId %i stateId %i", action.GetType().c_str(), action.GetValueParameterName().c_str(), action.GetValueParameterString().c_str(), action.GetValueParameterDouble(), behaviorId, actionIndex, actionContext.GetStripId(), actionContext.GetStateId()); +} diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.h new file mode 100644 index 00000000..0a03ce9e --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateActionMessage.h @@ -0,0 +1,26 @@ +#ifndef __UPDATEACTIONMESSAGE__H__ +#define __UPDATEACTIONMESSAGE__H__ + +#include "Action.h" +#include "ActionContext.h" +#include "BehaviorMessageBase.h" + +class AMFArrayValue; + +/** + * @brief Sent when a player updates the value in an Action + * + */ +class UpdateActionMessage : public BehaviorMessageBase { +public: + UpdateActionMessage(AMFArrayValue* arguments); + const uint32_t GetActionIndex() { return actionIndex; }; + ActionContext GetActionContext() { return actionContext; }; + Action GetAction() { return action; }; +private: + uint32_t actionIndex; + ActionContext actionContext; + Action action; +}; + +#endif //!__UPDATEACTIONMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.cpp new file mode 100644 index 00000000..073db9b4 --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.cpp @@ -0,0 +1,8 @@ +#include "UpdateStripUiMessage.h" + +UpdateStripUiMessage::UpdateStripUiMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { + position = StripUiPosition(arguments); + actionContext = ActionContext(arguments); + + Game::logger->LogDebug("UpdateStripUIMessage", "xPosition %f yPosition %f stripId %i stateId %i behaviorId %i", position.GetX(), position.GetY(), actionContext.GetStripId(), actionContext.GetStateId(), behaviorId); +} diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.h new file mode 100644 index 00000000..6d96f90c --- /dev/null +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/UpdateStripUiMessage.h @@ -0,0 +1,24 @@ +#ifndef __UPDATESTRIPUIMESSAGE__H__ +#define __UPDATESTRIPUIMESSAGE__H__ + +#include "ActionContext.h" +#include "BehaviorMessageBase.h" +#include "StripUiPosition.h" + +class AMFArrayValue; + +/** + * @brief Sent when a player moves the first Action in a Strip + * + */ +class UpdateStripUiMessage : public BehaviorMessageBase { +public: + UpdateStripUiMessage(AMFArrayValue* arguments); + StripUiPosition GetPosition() { return position; }; + ActionContext GetActionContext() { return actionContext; }; +private: + StripUiPosition position; + ActionContext actionContext; +}; + +#endif //!__UPDATESTRIPUIMESSAGE__H__ diff --git a/dGame/dPropertyBehaviors/ControlBehaviors.cpp b/dGame/dPropertyBehaviors/ControlBehaviors.cpp index 278b6929..dfb22b59 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviors.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviors.cpp @@ -7,40 +7,30 @@ #include "ModelComponent.h" #include "../../dWorldServer/ObjectIDManager.h" #include "dLogger.h" +#include "BehaviorStates.h" +#include "AssetManager.h" +#include "BlockDefinition.h" #include "User.h" +#include "tinyxml2.h" +#include "CDClientDatabase.h" -uint32_t GetBehaviorIDFromArgument(AMFArrayValue* arguments, const std::string& key = "BehaviorID") { - auto* behaviorIDValue = arguments->FindValue(key); - uint32_t behaviorID = -1; +// Message includes +#include "Action.h" +#include "AddActionMessage.h" +#include "AddStripMessage.h" +#include "AddMessage.h" +#include "MigrateActionsMessage.h" +#include "MoveToInventoryMessage.h" +#include "MergeStripsMessage.h" +#include "RearrangeStripMessage.h" +#include "RemoveActionsMessage.h" +#include "RemoveStripMessage.h" +#include "RenameMessage.h" +#include "SplitStripMessage.h" +#include "UpdateActionMessage.h" +#include "UpdateStripUiMessage.h" - if (behaviorIDValue) { - behaviorID = std::stoul(behaviorIDValue->GetStringValue()); - } else if (arguments->FindValue(key) == nullptr){ - throw std::invalid_argument("Unable to find behavior ID from argument \"" + key + "\""); - } - - return behaviorID; -} - -BEHAVIORSTATE GetBehaviorStateFromArgument(AMFArrayValue* arguments, const std::string& key = "stateID") { - auto* stateIDValue = arguments->FindValue(key); - if (!stateIDValue) throw std::invalid_argument("Unable to find behavior state from argument \"" + key + "\""); - - BEHAVIORSTATE stateID = static_cast(stateIDValue->GetDoubleValue()); - - return stateID; -} - -STRIPID GetStripIDFromArgument(AMFArrayValue* arguments, const std::string& key = "stripID") { - auto* stripIDValue = arguments->FindValue(key); - if (!stripIDValue) throw std::invalid_argument("Unable to find strip ID from argument \"" + key + "\""); - - STRIPID stripID = static_cast(stripIDValue->GetDoubleValue()); - - return stripID; -} - -void RequestUpdatedID(int32_t behaviorID, ModelComponent* modelComponent, Entity* modelOwner, const SystemAddress& sysAddr) { +void ControlBehaviors::RequestUpdatedID(int32_t behaviorID, ModelComponent* modelComponent, Entity* modelOwner, const SystemAddress& sysAddr) { // auto behavior = modelComponent->FindBehavior(behaviorID); // if (behavior->GetBehaviorID() == -1 || behavior->GetShouldSetNewID()) { // ObjectIDManager::Instance()->RequestPersistentID( @@ -66,11 +56,7 @@ void RequestUpdatedID(int32_t behaviorID, ModelComponent* modelComponent, Entity // } } -void SendBehaviorListToClient( - Entity* modelEntity, - const SystemAddress& sysAddr, - Entity* modelOwner - ) { +void ControlBehaviors::SendBehaviorListToClient(Entity* modelEntity, const SystemAddress& sysAddr, Entity* modelOwner) { auto* modelComponent = modelEntity->GetComponent(); if (!modelComponent) return; @@ -98,7 +84,7 @@ void SendBehaviorListToClient( GameMessages::SendUIMessageServerToSingleClient(modelOwner, sysAddr, "UpdateBehaviorList", &behaviorsToSerialize); } -void ModelTypeChanged(AMFArrayValue* arguments, ModelComponent* ModelComponent) { +void ControlBehaviors::ModelTypeChanged(AMFArrayValue* arguments, ModelComponent* ModelComponent) { auto* modelTypeAmf = arguments->FindValue("ModelType"); if (!modelTypeAmf) return; @@ -107,292 +93,57 @@ void ModelTypeChanged(AMFArrayValue* arguments, ModelComponent* ModelComponent) //TODO Update the model type here } -void ToggleExecutionUpdates() { +void ControlBehaviors::ToggleExecutionUpdates() { //TODO do something with this info } -void AddStrip(AMFArrayValue* arguments) { - auto* strip = arguments->FindValue("strip"); - if (!strip) return; - - auto* actions = strip->FindValue("actions"); - if (!actions) return; - - auto* uiArray = arguments->FindValue("ui"); - if (!uiArray) return; - - auto* xPositionValue = uiArray->FindValue("x"); - if (!xPositionValue) return; - - double xPosition = xPositionValue->GetDoubleValue(); - - auto* yPositionValue = uiArray->FindValue("y"); - if (!yPositionValue) return; - - double yPosition = yPositionValue->GetDoubleValue(); - - STRIPID stripID = GetStripIDFromArgument(arguments); - - BEHAVIORSTATE stateID = GetBehaviorStateFromArgument(arguments); - - uint32_t behaviorID = GetBehaviorIDFromArgument(arguments); - - std::string type = ""; - std::string valueParameterName = ""; - std::string valueParameterString = ""; - double valueParameterDouble = 0.0; - for (uint32_t position = 0; position < actions->GetDenseValueSize(); position++) { - auto* actionAsArray = actions->GetValueAt(position); - if (!actionAsArray) continue; - - for (auto& typeValueMap : actionAsArray->GetAssociativeMap()) { - if (typeValueMap.first == "Type") { - if (typeValueMap.second->GetValueType() != AMFValueType::AMFString) continue; - - type = static_cast(typeValueMap.second)->GetStringValue(); - } else { - valueParameterName = typeValueMap.first; - // Message is the only known string parameter - if (valueParameterName == "Message") { - if (typeValueMap.second->GetValueType() != AMFValueType::AMFString) continue; - valueParameterString = static_cast(typeValueMap.second)->GetStringValue(); - } else { - if (typeValueMap.second->GetValueType() != AMFValueType::AMFDouble) continue; - valueParameterDouble = static_cast(typeValueMap.second)->GetDoubleValue(); - } - } - } - // modelComponent->AddStrip(stateID, stripID, type, behaviorID, valueParameterName, valueParameterString, valueParameterDouble, "", xPosition, yPosition); - type.clear(); - valueParameterName.clear(); - valueParameterString.clear(); - valueParameterDouble = 0.0; - } - // RequestUpdatedID(behaviorID); +void ControlBehaviors::AddStrip(AMFArrayValue* arguments) { + AddStripMessage addStripMessage(arguments); } -void RemoveStrip(AMFArrayValue* arguments) { - STRIPID stripID = GetStripIDFromArgument(arguments); - - BEHAVIORSTATE stateID = GetBehaviorStateFromArgument(arguments); - - uint32_t behaviorID = GetBehaviorIDFromArgument(arguments); - - // modelComponent->RemoveStrip(stateID, stripID, behaviorID); - - // RequestUpdatedID(behaviorID); +void ControlBehaviors::RemoveStrip(AMFArrayValue* arguments) { + RemoveStripMessage removeStrip(arguments); } -void MergeStrips(AMFArrayValue* arguments) { - STRIPID srcStripID = GetStripIDFromArgument(arguments, "srcStripID"); - - BEHAVIORSTATE dstStateID = GetBehaviorStateFromArgument(arguments, "dstStateID"); - - BEHAVIORSTATE srcStateID = GetBehaviorStateFromArgument(arguments, "srcStateID"); - - auto* dstActionIndexValue = arguments->FindValue("dstActionIndex"); - if (!dstActionIndexValue) return; - - uint32_t dstActionIndex = static_cast(dstActionIndexValue->GetDoubleValue()); - - STRIPID dstStripID = GetStripIDFromArgument(arguments, "dstStripID"); - - uint32_t behaviorID = GetBehaviorIDFromArgument(arguments); - - // modelComponent->MergeStrips(srcStripID, dstStripID, srcStateID, dstStateID, behaviorID, dstActionIndex); - - // RequestUpdatedID(behaviorID); +void ControlBehaviors::MergeStrips(AMFArrayValue* arguments) { + MergeStripsMessage mergeStripsMessage(arguments); } -void SplitStrip(AMFArrayValue* arguments) { - auto* srcActionIndexValue = arguments->FindValue("srcActionIndex"); - if (!srcActionIndexValue) return; - - uint32_t srcActionIndex = static_cast(srcActionIndexValue->GetDoubleValue()); - - STRIPID srcStripID = GetStripIDFromArgument(arguments, "srcStripID"); - - BEHAVIORSTATE srcStateID = GetBehaviorStateFromArgument(arguments, "srcStateID"); - - STRIPID dstStripID = GetStripIDFromArgument(arguments, "dstStripID"); - - BEHAVIORSTATE dstStateID = GetBehaviorStateFromArgument(arguments, "dstStateID"); - - auto* dstStripUIArray = arguments->FindValue("dstStripUI"); - if (!dstStripUIArray) return; - - auto* xPositionValue = dstStripUIArray->FindValue("x"); - auto* yPositionValue = dstStripUIArray->FindValue("y"); - if (!xPositionValue || !yPositionValue) return; - - // x and y position 15 are just where the game puts the strip by default if none is given. - double yPosition = yPositionValue->GetDoubleValue(); - double xPosition = xPositionValue->GetDoubleValue(); - - uint32_t behaviorID = GetBehaviorIDFromArgument(arguments); - - // modelComponent->SplitStrip(srcActionIndex, srcStripID, srcStateID, dstStripID, dstStateID, behaviorID, yPosition, xPosition); - - // RequestUpdatedID(behaviorID); +void ControlBehaviors::SplitStrip(AMFArrayValue* arguments) { + SplitStripMessage splitStripMessage(arguments); } -void UpdateStripUI(AMFArrayValue* arguments) { - auto* uiArray = arguments->FindValue("ui"); - if (!uiArray) return; - - auto* xPositionValue = uiArray->FindValue("x"); - auto* yPositionValue = uiArray->FindValue("y"); - if (!xPositionValue || !yPositionValue) return; - - double yPosition = yPositionValue->GetDoubleValue(); - double xPosition = xPositionValue->GetDoubleValue(); - - STRIPID stripID = GetStripIDFromArgument(arguments); - - BEHAVIORSTATE stateID = GetBehaviorStateFromArgument(arguments); - - uint32_t behaviorID = GetBehaviorIDFromArgument(arguments); - - // modelComponent->UpdateUIOfStrip(stateID, stripID, xPosition, yPosition, behaviorID); - - // RequestUpdatedID(behaviorID); +void ControlBehaviors::UpdateStripUI(AMFArrayValue* arguments) { + UpdateStripUiMessage updateStripUiMessage(arguments); } -void AddAction(AMFArrayValue* arguments) { - auto* actionIndexAmf = arguments->FindValue("actionIndex"); - if (!actionIndexAmf) return; - - uint32_t actionIndex = static_cast(actionIndexAmf->GetDoubleValue()); - - STRIPID stripID = GetStripIDFromArgument(arguments); - - BEHAVIORSTATE stateID = GetBehaviorStateFromArgument(arguments); - - std::string type = ""; - std::string valueParameterName = ""; - std::string valueParameterString = ""; - double valueParameterDouble = 0.0; - auto* action = arguments->FindValue("action"); - if (!action) return; - - for (auto& typeValueMap : action->GetAssociativeMap()) { - if (typeValueMap.first == "Type") { - if (typeValueMap.second->GetValueType() != AMFValueType::AMFString) continue; - type = static_cast(typeValueMap.second)->GetStringValue(); - } else { - valueParameterName = typeValueMap.first; - // Message is the only known string parameter - if (valueParameterName == "Message") { - if (typeValueMap.second->GetValueType() != AMFValueType::AMFString) continue; - valueParameterString = static_cast(typeValueMap.second)->GetStringValue(); - } else { - if (typeValueMap.second->GetValueType() != AMFValueType::AMFDouble) continue; - valueParameterDouble = static_cast(typeValueMap.second)->GetDoubleValue(); - } - } - } - - uint32_t behaviorID = GetBehaviorIDFromArgument(arguments); - - // modelComponent->AddAction(stateID, stripID, type, valueParameterName, valueParameterString, valueParameterDouble, "", actionIndex, behaviorID); - - // RequestUpdatedID(behaviorID); +void ControlBehaviors::AddAction(AMFArrayValue* arguments) { + AddActionMessage addActionMessage(arguments); } -void MigrateActions(AMFArrayValue* arguments) { - auto* srcActionIndexAmf = arguments->FindValue("srcActionIndex"); - if (!srcActionIndexAmf) return; - - uint32_t srcActionIndex = static_cast(srcActionIndexAmf->GetDoubleValue()); - - STRIPID srcStripID = GetStripIDFromArgument(arguments, "srcStripID"); - - BEHAVIORSTATE srcStateID = GetBehaviorStateFromArgument(arguments, "srcStateID"); - - auto* dstActionIndexAmf = arguments->FindValue("dstActionIndex"); - if (!dstActionIndexAmf) return; - - uint32_t dstActionIndex = static_cast(dstActionIndexAmf->GetDoubleValue()); - - STRIPID dstStripID = GetStripIDFromArgument(arguments, "dstStripID"); - - BEHAVIORSTATE dstStateID = GetBehaviorStateFromArgument(arguments, "dstStateID"); - - uint32_t behaviorID = GetBehaviorIDFromArgument(arguments); - - // modelComponent->MigrateActions(srcActionIndex, srcStripID, srcStateID, dstActionIndex, dstStripID, dstStateID, behaviorID); - - // RequestUpdatedID(behaviorID); +void ControlBehaviors::MigrateActions(AMFArrayValue* arguments) { + MigrateActionsMessage migrateActionsMessage(arguments); } -void RearrangeStrip(AMFArrayValue* arguments) { - auto* srcActionIndexValue = arguments->FindValue("srcActionIndex"); - uint32_t srcActionIndex = static_cast(srcActionIndexValue->GetDoubleValue()); - - uint32_t stripID = GetStripIDFromArgument(arguments); - - uint32_t behaviorID = GetBehaviorIDFromArgument(arguments); - - auto* dstActionIndexValue = arguments->FindValue("dstActionIndex"); - uint32_t dstActionIndex = static_cast(dstActionIndexValue->GetDoubleValue()); - - BEHAVIORSTATE stateID = GetBehaviorStateFromArgument(arguments); - - // modelComponent->RearrangeStrip(stateID, stripID, srcActionIndex, dstActionIndex, behaviorID); - - // RequestUpdatedID(behaviorID); +void ControlBehaviors::RearrangeStrip(AMFArrayValue* arguments) { + RearrangeStripMessage rearrangeStripMessage(arguments); } -void Add(AMFArrayValue* arguments) { - uint32_t behaviorID = GetBehaviorIDFromArgument(arguments); - - uint32_t behaviorIndex = 0; - auto* behaviorIndexAmf = arguments->FindValue("BehaviorIndex"); - - if (!behaviorIndexAmf) return; - - behaviorIndex = static_cast(behaviorIndexAmf->GetDoubleValue()); - - // modelComponent->AddBehavior(behaviorID, behaviorIndex, modelOwner); - - // SendBehaviorListToClient(); +void ControlBehaviors::Add(AMFArrayValue* arguments) { + AddMessage addMessage(arguments); } -void RemoveActions(AMFArrayValue* arguments) { - uint32_t behaviorID = GetBehaviorIDFromArgument(arguments); - - auto* actionIndexAmf = arguments->FindValue("actionIndex"); - if (!actionIndexAmf) return; - - uint32_t actionIndex = static_cast(actionIndexAmf->GetDoubleValue()); - - STRIPID stripID = GetStripIDFromArgument(arguments); - - BEHAVIORSTATE stateID = GetBehaviorStateFromArgument(arguments); - - // modelComponent->RemoveAction(stateID, stripID, actionIndex, behaviorID); - - // RequestUpdatedID(behaviorID); +void ControlBehaviors::RemoveActions(AMFArrayValue* arguments) { + RemoveActionsMessage removeActionsMessage(arguments); } -void Rename(Entity* modelEntity, const SystemAddress& sysAddr, Entity* modelOwner, AMFArrayValue* arguments) { - uint32_t behaviorID = GetBehaviorIDFromArgument(arguments); - - auto* nameAmf = arguments->FindValue("Name"); - if (!nameAmf) return; - - auto name = nameAmf->GetStringValue(); - - // modelComponent->Rename(behaviorID, name); - - SendBehaviorListToClient(modelEntity, sysAddr, modelOwner); - - // RequestUpdatedID(behaviorID); +void ControlBehaviors::Rename(Entity* modelEntity, const SystemAddress& sysAddr, Entity* modelOwner, AMFArrayValue* arguments) { + RenameMessage renameMessage(arguments); } // TODO This is also supposed to serialize the state of the behaviors in progress but those aren't implemented yet -void SendBehaviorBlocksToClient(ModelComponent* modelComponent, const SystemAddress& sysAddr, Entity* modelOwner, AMFArrayValue* arguments) { - uint32_t behaviorID = GetBehaviorIDFromArgument(arguments); +void ControlBehaviors::SendBehaviorBlocksToClient(ModelComponent* modelComponent, const SystemAddress& sysAddr, Entity* modelOwner, AMFArrayValue* arguments) { + // uint32_t behaviorID = ControlBehaviors::GetBehaviorIDFromArgument(arguments); // auto modelBehavior = modelComponent->FindBehavior(behaviorID); @@ -496,47 +247,31 @@ void SendBehaviorBlocksToClient(ModelComponent* modelComponent, const SystemAddr // GameMessages::SendUIMessageServerToSingleClient(modelOwner, sysAddr, "UpdateBehaviorBlocks", &behaviorInfo); } -void UpdateAction(AMFArrayValue* arguments) { - std::string type = ""; - std::string valueParameterName = ""; - std::string valueParameterString = ""; - double valueParameterDouble = 0.0; - auto* actionAsArray = arguments->FindValue("action"); - if (!actionAsArray) return; - for (auto& typeValueMap : actionAsArray->GetAssociativeMap()) { - if (typeValueMap.first == "Type") { - if (typeValueMap.second->GetValueType() != AMFValueType::AMFString) continue; - type = static_cast(typeValueMap.second)->GetStringValue(); - } else { - valueParameterName = typeValueMap.first; - // Message is the only known string parameter - if (valueParameterName == "Message") { - if (typeValueMap.second->GetValueType() != AMFValueType::AMFString) continue; - valueParameterString = static_cast(typeValueMap.second)->GetStringValue(); - } else { - if (typeValueMap.second->GetValueType() != AMFValueType::AMFDouble) continue; - valueParameterDouble = static_cast(typeValueMap.second)->GetDoubleValue(); - } - } +void ControlBehaviors::UpdateAction(AMFArrayValue* arguments) { + UpdateActionMessage updateActionMessage(arguments); + auto* blockDefinition = GetBlockInfo(updateActionMessage.GetAction().GetType()); + + if (!blockDefinition) { + Game::logger->Log("ControlBehaviors", "Received undefined block type %s. Ignoring.", updateActionMessage.GetAction().GetType().c_str()); + return; } - uint32_t behaviorID = GetBehaviorIDFromArgument(arguments); - - auto* actionIndexValue = arguments->FindValue("actionIndex"); - if (!actionIndexValue) return; - - uint32_t actionIndex = static_cast(actionIndexValue->GetDoubleValue()); - - STRIPID stripID = GetStripIDFromArgument(arguments); - - BEHAVIORSTATE stateID = GetBehaviorStateFromArgument(arguments); - - // modelComponent->UpdateAction(stateID, stripID, type, valueParameterName, valueParameterString, valueParameterDouble, "", actionIndex, behaviorID); - - // RequestUpdatedID(behaviorID); + if (updateActionMessage.GetAction().GetValueParameterString().size() > 0) { + if (updateActionMessage.GetAction().GetValueParameterString().size() < blockDefinition->GetMinimumValue() || + updateActionMessage.GetAction().GetValueParameterString().size() > blockDefinition->GetMaximumValue()) { + Game::logger->Log("ControlBehaviors", "Updated block %s is out of range. Ignoring update", updateActionMessage.GetAction().GetType().c_str()); + return; + } + } else { + if (updateActionMessage.GetAction().GetValueParameterDouble() < blockDefinition->GetMinimumValue() || + updateActionMessage.GetAction().GetValueParameterDouble() > blockDefinition->GetMaximumValue()) { + Game::logger->Log("ControlBehaviors", "Updated block %s is out of range. Ignoring update", updateActionMessage.GetAction().GetType().c_str()); + return; + } + } } -void MoveToInventory(ModelComponent* modelComponent, const SystemAddress& sysAddr, Entity* modelOwner, AMFArrayValue* arguments) { +void ControlBehaviors::MoveToInventory(ModelComponent* modelComponent, const SystemAddress& sysAddr, Entity* modelOwner, AMFArrayValue* arguments) { // This closes the UI menu should it be open while the player is removing behaviors AMFArrayValue args; @@ -545,20 +280,13 @@ void MoveToInventory(ModelComponent* modelComponent, const SystemAddress& sysAdd GameMessages::SendUIMessageServerToSingleClient(modelOwner, modelOwner->GetParentUser()->GetSystemAddress(), "ToggleBehaviorEditor", &args); - uint32_t behaviorID = GetBehaviorIDFromArgument(arguments); - - auto* behaviorIndexValue = arguments->FindValue("BehaviorIndex"); - if (!behaviorIndexValue) return; - - uint32_t behaviorIndex = static_cast(behaviorIndexValue->GetDoubleValue()); - - // modelComponent->MoveBehaviorToInventory(behaviorID, behaviorIndex, modelOwner); + MoveToInventoryMessage moveToInventoryMessage(arguments); SendBehaviorListToClient(modelComponent->GetParent(), sysAddr, modelOwner); } void ControlBehaviors::ProcessCommand(Entity* modelEntity, const SystemAddress& sysAddr, AMFArrayValue* arguments, std::string command, Entity* modelOwner) { - if (!modelEntity || !modelOwner || !arguments) return; + if (!isInitialized || !modelEntity || !modelOwner || !arguments) return; auto* modelComponent = modelEntity->GetComponent(); if (!modelComponent) return; @@ -600,3 +328,135 @@ void ControlBehaviors::ProcessCommand(Entity* modelEntity, const SystemAddress& else Game::logger->Log("ControlBehaviors", "Unknown behavior command (%s)\n", command.c_str()); } + +ControlBehaviors::ControlBehaviors() { + auto blocksDefStreamBuffer = Game::assetManager->GetFileAsBuffer("ui\\ingame\\blocksdef.xml"); + if (!blocksDefStreamBuffer.m_Success) { + Game::logger->Log("ControlBehaviors", "failed to open blocksdef"); + return; + } + std::istream blocksBuffer(&blocksDefStreamBuffer); + if (!blocksBuffer.good()) { + Game::logger->Log("ControlBehaviors", "Blocks buffer is not good!"); + return; + } + + tinyxml2::XMLDocument m_Doc; + + std::string read{}; + + std::string buffer{}; + bool commentBlockStart = false; + while (std::getline(blocksBuffer, read)) { + // tinyxml2 should handle comment blocks but the client has one that fails the processing. + // This preprocessing just removes all comments from the read file out of an abundance of caution. + if (read.find("") != std::string::npos) { + commentBlockStart = false; + continue; + } + if (!commentBlockStart) buffer += read; + } + + auto ret = m_Doc.Parse(buffer.c_str()); + if (ret == tinyxml2::XML_SUCCESS) { + Game::logger->LogDebug("ControlBehaviors", "Successfully parsed the blocksdef file!"); + } else { + Game::logger->Log("Character", "Failed to parse BlocksDef xmlData due to error %i!", ret); + return; + } + auto* blockLibrary = m_Doc.FirstChildElement(); + if (!blockLibrary) { + Game::logger->Log("ControlBehaviors", "No Block Library child element found."); + return; + } + + // Now parse the blocksdef for the cheat detection server side. + // The client does these checks, but a bad actor can bypass the client checks + auto* blockSections = blockLibrary->FirstChildElement(); + while (blockSections) { + auto* block = blockSections->FirstChildElement(); + std::string blockName{}; + while (block) { + blockName = block->Name(); + + BlockDefinition* blockDefinition = new BlockDefinition(); + std::string name{}; + std::string typeName{}; + + auto* argument = block->FirstChildElement("Argument"); + if (argument) { + auto* defaultDefinition = argument->FirstChildElement("DefaultValue"); + if (defaultDefinition) blockDefinition->SetDefaultValue(defaultDefinition->GetText()); + + auto* typeDefinition = argument->FirstChildElement("Type"); + if (typeDefinition) typeName = typeDefinition->GetText(); + + auto* nameDefinition = argument->FirstChildElement("Name"); + if (nameDefinition) name = nameDefinition->GetText(); + + // Now we parse the blocksdef file for the relevant information + if (typeName == "String") { + blockDefinition->SetMaximumValue(50); // The client has a hardcoded limit of 50 characters in a string field + } else if (typeName == "Float" || typeName == "Integer") { + auto* maximumDefinition = argument->FirstChildElement("Maximum"); + if (maximumDefinition) blockDefinition->SetMaximumValue(std::stof(maximumDefinition->GetText())); + + auto* minimumDefinition = argument->FirstChildElement("Minimum"); + if (minimumDefinition) blockDefinition->SetMinimumValue(std::stof(minimumDefinition->GetText())); + } else if (typeName == "Enumeration") { + auto* values = argument->FirstChildElement("Values"); + if (values) { + auto* value = values->FirstChildElement("Value"); + while (value) { + if (value->GetText() == blockDefinition->GetDefaultValue()) blockDefinition->GetDefaultValue() = std::to_string(blockDefinition->GetMaximumValue()); + blockDefinition->SetMaximumValue(blockDefinition->GetMaximumValue() + 1); + value = value->NextSiblingElement("Value"); + } + blockDefinition->SetMaximumValue(blockDefinition->GetMaximumValue() - 1); // Maximum value is 0 indexed + } else { + values = argument->FirstChildElement("EnumerationSource"); + if (!values) { + Game::logger->Log("ControlBehaviors", "Failed to parse EnumerationSource from block (%s)", blockName.c_str()); + continue; + } + + auto* serviceNameNode = values->FirstChildElement("ServiceName"); + if (!serviceNameNode) { + Game::logger->Log("ControlBehaviors", "Failed to parse ServiceName from block (%s)", blockName.c_str()); + continue; + } + + std::string serviceName = serviceNameNode->GetText(); + if (serviceName == "GetBehaviorSoundList") { + auto res = CDClientDatabase::ExecuteQuery("SELECT MAX(id) as countSounds FROM UGBehaviorSounds;"); + blockDefinition->SetMaximumValue(res.getIntField("countSounds")); + blockDefinition->SetDefaultValue("0"); + } else { + Game::logger->Log("ControlBehaviors", "Unsupported Enumeration ServiceType (%s)", serviceName.c_str()); + continue; + } + } + } else { + Game::logger->Log("ControlBehaviors", "Unsupported block value type (%s)!", typeName.c_str()); + continue; + } + } + blockTypes.insert(std::make_pair(blockName, blockDefinition)); + block = block->NextSiblingElement(); + } + blockSections = blockSections->NextSiblingElement(); + } + isInitialized = true; + Game::logger->LogDebug("ControlBehaviors", "Created all base block classes"); + for (auto b : blockTypes) { + Game::logger->LogDebug("ControlBehaviors", "block name is %s default %s min %f max %f", b.first.c_str(), b.second->GetDefaultValue().c_str(), b.second->GetMinimumValue(), b.second->GetMaximumValue()); + } +} + +BlockDefinition* ControlBehaviors::GetBlockInfo(const BlockName& blockName) { + auto blockDefinition = blockTypes.find(blockName); + return blockDefinition != blockTypes.end() ? blockDefinition->second : nullptr; +} diff --git a/dGame/dPropertyBehaviors/ControlBehaviors.h b/dGame/dPropertyBehaviors/ControlBehaviors.h index d487f929..a562aafe 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviors.h +++ b/dGame/dPropertyBehaviors/ControlBehaviors.h @@ -3,15 +3,23 @@ #ifndef __CONTROLBEHAVIORS__H__ #define __CONTROLBEHAVIORS__H__ +#include #include -#include "RakNetTypes.h" +#include "Singleton.h" -class Entity; class AMFArrayValue; +class BlockDefinition; +class Entity; class ModelComponent; +class SystemAddress; -namespace ControlBehaviors { +// Type definition to clarify what is used where +typedef std::string BlockName; //! A block name + +class ControlBehaviors: public Singleton { +public: + ControlBehaviors(); /** * @brief Main driver for processing Property Behavior commands * @@ -22,6 +30,39 @@ namespace ControlBehaviors { * @param modelOwner The owner of the model which sent this command */ void ProcessCommand(Entity* modelEntity, const SystemAddress& sysAddr, AMFArrayValue* arguments, std::string command, Entity* modelOwner); + + /** + * @brief Gets a blocks parameter values by the name + * No exception will be thrown in this function. + * + * @param blockName The block name to get the parameters of + * + * @return A pair of the block parameter name to its typing + */ + BlockDefinition* GetBlockInfo(const BlockName& blockName); +private: + void RequestUpdatedID(int32_t behaviorID, ModelComponent* modelComponent, Entity* modelOwner, const SystemAddress& sysAddr); + void SendBehaviorListToClient(Entity* modelEntity, const SystemAddress& sysAddr, Entity* modelOwner); + void ModelTypeChanged(AMFArrayValue* arguments, ModelComponent* ModelComponent); + void ToggleExecutionUpdates(); + void AddStrip(AMFArrayValue* arguments); + void RemoveStrip(AMFArrayValue* arguments); + void MergeStrips(AMFArrayValue* arguments); + void SplitStrip(AMFArrayValue* arguments); + void UpdateStripUI(AMFArrayValue* arguments); + void AddAction(AMFArrayValue* arguments); + void MigrateActions(AMFArrayValue* arguments); + void RearrangeStrip(AMFArrayValue* arguments); + void Add(AMFArrayValue* arguments); + void RemoveActions(AMFArrayValue* arguments); + void Rename(Entity* modelEntity, const SystemAddress& sysAddr, Entity* modelOwner, AMFArrayValue* arguments); + void SendBehaviorBlocksToClient(ModelComponent* modelComponent, const SystemAddress& sysAddr, Entity* modelOwner, AMFArrayValue* arguments); + void UpdateAction(AMFArrayValue* arguments); + void MoveToInventory(ModelComponent* modelComponent, const SystemAddress& sysAddr, Entity* modelOwner, AMFArrayValue* arguments); + std::map blockTypes{}; + + // If false, property behaviors will not be able to be edited. + bool isInitialized = false; }; #endif //!__CONTROLBEHAVIORS__H__ diff --git a/dGame/dUtilities/Loot.cpp b/dGame/dUtilities/Loot.cpp index 44e35a91..da0f2487 100644 --- a/dGame/dUtilities/Loot.cpp +++ b/dGame/dUtilities/Loot.cpp @@ -7,6 +7,8 @@ #include "CDLootMatrixTable.h" #include "CDLootTableTable.h" #include "CDRarityTableTable.h" +#include "CDActivityRewardsTable.h" +#include "CDCurrencyTableTable.h" #include "Character.h" #include "Entity.h" #include "GameMessages.h" @@ -14,14 +16,14 @@ #include "InventoryComponent.h" #include "MissionComponent.h" #include "eMissionState.h" - +#include "eReplicaComponentType.h" LootGenerator::LootGenerator() { - CDLootTableTable* lootTableTable = CDClientManager::Instance()->GetTable("LootTable"); - CDComponentsRegistryTable* componentsRegistryTable = CDClientManager::Instance()->GetTable("ComponentsRegistry"); - CDItemComponentTable* itemComponentTable = CDClientManager::Instance()->GetTable("ItemComponent"); - CDLootMatrixTable* lootMatrixTable = CDClientManager::Instance()->GetTable("LootMatrix"); - CDRarityTableTable* rarityTableTable = CDClientManager::Instance()->GetTable("RarityTable"); + CDLootTableTable* lootTableTable = CDClientManager::Instance().GetTable(); + CDComponentsRegistryTable* componentsRegistryTable = CDClientManager::Instance().GetTable(); + CDItemComponentTable* itemComponentTable = CDClientManager::Instance().GetTable(); + CDLootMatrixTable* lootMatrixTable = CDClientManager::Instance().GetTable(); + CDRarityTableTable* rarityTableTable = CDClientManager::Instance().GetTable(); // ============================== // Cache Item Rarities @@ -38,7 +40,7 @@ LootGenerator::LootGenerator() { uniqueItems.erase(std::unique(uniqueItems.begin(), uniqueItems.end()), uniqueItems.end()); for (const uint32_t itemID : uniqueItems) { - uint32_t itemComponentID = componentsRegistryTable->GetByIDAndType(itemID, COMPONENT_TYPE_ITEM); + uint32_t itemComponentID = componentsRegistryTable->GetByIDAndType(itemID, eReplicaComponentType::ITEM); const CDItemComponent& item = itemComponentTable->GetItemComponentByID(itemComponentID); m_ItemRarities.insert({ itemID, item.rarity }); @@ -292,7 +294,7 @@ void LootGenerator::GiveLoot(Entity* player, std::unordered_map& r } void LootGenerator::GiveActivityLoot(Entity* player, Entity* source, uint32_t activityID, int32_t rating) { - CDActivityRewardsTable* activityRewardsTable = CDClientManager::Instance()->GetTable("ActivityRewards"); + CDActivityRewardsTable* activityRewardsTable = CDClientManager::Instance().GetTable(); std::vector activityRewards = activityRewardsTable->Query([activityID](CDActivityRewards entry) { return (entry.objectTemplate == activityID); }); const CDActivityRewards* selectedReward = nullptr; @@ -308,7 +310,7 @@ void LootGenerator::GiveActivityLoot(Entity* player, Entity* source, uint32_t ac uint32_t minCoins = 0; uint32_t maxCoins = 0; - CDCurrencyTableTable* currencyTableTable = CDClientManager::Instance()->GetTable("CurrencyTable"); + CDCurrencyTableTable* currencyTableTable = CDClientManager::Instance().GetTable(); std::vector currencyTable = currencyTableTable->Query([selectedReward](CDCurrencyTable entry) { return (entry.currencyIndex == selectedReward->CurrencyIndex && entry.npcminlevel == 1); }); if (currencyTable.size() > 0) { @@ -362,7 +364,7 @@ void LootGenerator::DropLoot(Entity* player, Entity* killedObject, std::unordere } void LootGenerator::DropActivityLoot(Entity* player, Entity* source, uint32_t activityID, int32_t rating) { - CDActivityRewardsTable* activityRewardsTable = CDClientManager::Instance()->GetTable("ActivityRewards"); + CDActivityRewardsTable* activityRewardsTable = CDClientManager::Instance().GetTable(); std::vector activityRewards = activityRewardsTable->Query([activityID](CDActivityRewards entry) { return (entry.objectTemplate == activityID); }); const CDActivityRewards* selectedReward = nullptr; @@ -379,7 +381,7 @@ void LootGenerator::DropActivityLoot(Entity* player, Entity* source, uint32_t ac uint32_t minCoins = 0; uint32_t maxCoins = 0; - CDCurrencyTableTable* currencyTableTable = CDClientManager::Instance()->GetTable("CurrencyTable"); + CDCurrencyTableTable* currencyTableTable = CDClientManager::Instance().GetTable(); std::vector currencyTable = currencyTableTable->Query([selectedReward](CDCurrencyTable entry) { return (entry.currencyIndex == selectedReward->CurrencyIndex && entry.npcminlevel == 1); }); if (currencyTable.size() > 0) { diff --git a/dGame/dUtilities/Mail.cpp b/dGame/dUtilities/Mail.cpp index 48f21a5d..9490f748 100644 --- a/dGame/dUtilities/Mail.cpp +++ b/dGame/dUtilities/Mail.cpp @@ -25,6 +25,7 @@ #include "dZoneManager.h" #include "WorldConfig.h" #include "eMissionTaskType.h" +#include "eReplicaComponentType.h" void Mail::SendMail(const Entity* recipient, const std::string& subject, const std::string& body, const LOT attachment, const uint16_t attachmentCount) { @@ -196,7 +197,7 @@ void Mail::HandleSendMail(RakNet::BitStream* packet, const SystemAddress& sysAdd //Inventory::InventoryType itemType; int mailCost = dZoneManager::Instance()->GetWorldConfig()->mailBaseFee; int stackSize = 0; - auto inv = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); + auto inv = static_cast(entity->GetComponent(eReplicaComponentType::INVENTORY)); Item* item = nullptr; if (itemID > 0 && attachmentCount > 0 && inv) { @@ -355,7 +356,7 @@ void Mail::HandleAttachmentCollect(RakNet::BitStream* packet, const SystemAddres attachmentCount = res->getInt(2); } - auto inv = static_cast(player->GetComponent(COMPONENT_TYPE_INVENTORY)); + auto inv = static_cast(player->GetComponent(eReplicaComponentType::INVENTORY)); if (!inv) return; inv->AddItem(attachmentLOT, attachmentCount, eLootSourceType::LOOT_SOURCE_MAIL); diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index e558e19c..0278136b 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -74,6 +74,11 @@ #include "dMessageIdentifiers.h" #include "eMissionState.h" #include "TriggerComponent.h" +#include "eServerDisconnectIdentifiers.h" +#include "eReplicaComponentType.h" + +#include "CDObjectsTable.h" +#include "CDZoneTableTable.h" void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entity* entity, const SystemAddress& sysAddr) { std::string chatCommand; @@ -550,21 +555,42 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit return; } - if ((chatCommand == "setinventorysize" || chatCommand == "setinvsize") && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { - if (args.size() != 1) return; - + if ((chatCommand == "setinventorysize" || chatCommand == "setinvsize") && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() >= 1) { uint32_t size; - if (!GeneralUtils::TryParse(args[0], size)) { + if (!GeneralUtils::TryParse(args.at(0), size)) { ChatPackets::SendSystemMessage(sysAddr, u"Invalid size."); return; } - InventoryComponent* inventory = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); - if (inventory) { - auto* items = inventory->GetInventory(ITEMS); + eInventoryType selectedInventory = eInventoryType::ITEMS; - items->SetSize(size); + // a possible inventory was provided if we got more than 1 argument + if (args.size() >= 2) { + selectedInventory = eInventoryType::INVALID; + if (!GeneralUtils::TryParse(args.at(1), selectedInventory)) { + // In this case, we treat the input as a string and try to find it in the reflection list + std::transform(args.at(1).begin(), args.at(1).end(), args.at(1).begin(), ::toupper); + for (uint32_t index = 0; index < NUMBER_OF_INVENTORIES; index++) { + if (std::string_view(args.at(1)) == std::string_view(InventoryType::InventoryTypeToString(static_cast(index)))) selectedInventory = static_cast(index); + } + } + if (selectedInventory == eInventoryType::INVALID) { + ChatPackets::SendSystemMessage(sysAddr, u"Invalid inventory."); + return; + } + + ChatPackets::SendSystemMessage(sysAddr, u"Setting inventory " + + GeneralUtils::ASCIIToUTF16(args.at(1)) + + u" to size " + + GeneralUtils::to_u16string(size)); + } else ChatPackets::SendSystemMessage(sysAddr, u"Setting inventory ITEMS to size " + GeneralUtils::to_u16string(size)); + + auto* inventoryComponent = entity->GetComponent(); + if (inventoryComponent) { + auto* inventory = inventoryComponent->GetInventory(selectedInventory); + + inventory->SetSize(size); } return; @@ -579,10 +605,10 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit auto buf = Game::assetManager->GetFileAsBuffer(("macros/" + args[0] + ".scm").c_str()); - if (!buf.m_Success){ + if (!buf.m_Success) { ChatPackets::SendSystemMessage(sysAddr, u"Unknown macro! Is the filename right?"); return; - } + } std::istream infile(&buf); @@ -610,7 +636,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit return; } - auto comp = static_cast(entity->GetComponent(COMPONENT_TYPE_MISSION)); + auto comp = static_cast(entity->GetComponent(eReplicaComponentType::MISSION)); if (comp) comp->AcceptMission(missionID, true); return; } @@ -625,7 +651,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit return; } - auto comp = static_cast(entity->GetComponent(COMPONENT_TYPE_MISSION)); + auto comp = static_cast(entity->GetComponent(eReplicaComponentType::MISSION)); if (comp) comp->CompleteMission(missionID, true); return; } @@ -675,7 +701,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit return; } - auto* comp = static_cast(entity->GetComponent(COMPONENT_TYPE_MISSION)); + auto* comp = static_cast(entity->GetComponent(eReplicaComponentType::MISSION)); if (comp == nullptr) { return; @@ -752,7 +778,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } if (chatCommand == "getnavmeshheight" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { - auto control = static_cast(entity->GetComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS)); + auto control = static_cast(entity->GetComponent(eReplicaComponentType::CONTROLLABLE_PHYSICS)); if (!control) return; float y = dpWorld::Instance().GetNavMesh()->GetHeightAtPoint(control->GetPosition()); @@ -769,7 +795,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit return; } - InventoryComponent* inventory = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); + InventoryComponent* inventory = static_cast(entity->GetComponent(eReplicaComponentType::INVENTORY)); inventory->AddItem(itemLOT, 1, eLootSourceType::LOOT_SOURCE_MODERATION); } else if (args.size() == 2) { @@ -787,7 +813,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit return; } - InventoryComponent* inventory = static_cast(entity->GetComponent(COMPONENT_TYPE_INVENTORY)); + InventoryComponent* inventory = static_cast(entity->GetComponent(eReplicaComponentType::INVENTORY)); inventory->AddItem(itemLOT, count, eLootSourceType::LOOT_SOURCE_MODERATION); } else { @@ -933,7 +959,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit if (chatCommand == "tpall" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { const auto pos = entity->GetPosition(); - const auto characters = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_CHARACTER); + const auto characters = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::CHARACTER); for (auto* character : characters) { GameMessages::SendTeleport(character->GetObjectID(), pos, NiQuaternion(), character->GetSystemAddress()); @@ -1094,7 +1120,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit return; } - Game::server->Disconnect(player->GetSystemAddress(), SERVER_DISCON_KICK); + Game::server->Disconnect(player->GetSystemAddress(), eServerDisconnectIdentifiers::KICK); ChatPackets::SendSystemMessage(sysAddr, u"Kicked: " + username); } else { @@ -1140,7 +1166,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit delete userUpdate; if (player != nullptr) { - Game::server->Disconnect(player->GetSystemAddress(), SERVER_DISCON_KICK); + Game::server->Disconnect(player->GetSystemAddress(), eServerDisconnectIdentifiers::FREE_TRIAL_EXPIRED); } ChatPackets::SendSystemMessage(sysAddr, u"Banned: " + GeneralUtils::ASCIIToUTF16(args[0])); @@ -1152,7 +1178,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit //------------------------------------------------- if (chatCommand == "buffme" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { - auto dest = static_cast(entity->GetComponent(COMPONENT_TYPE_DESTROYABLE)); + auto dest = static_cast(entity->GetComponent(eReplicaComponentType::DESTROYABLE)); if (dest) { dest->SetHealth(999); dest->SetMaxHealth(999.0f); @@ -1176,7 +1202,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } if (chatCommand == "buffmed" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { - auto dest = static_cast(entity->GetComponent(COMPONENT_TYPE_DESTROYABLE)); + auto dest = static_cast(entity->GetComponent(eReplicaComponentType::DESTROYABLE)); if (dest) { dest->SetHealth(9); dest->SetMaxHealth(9.0f); @@ -1190,7 +1216,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit if (chatCommand == "refillstats" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { - auto dest = static_cast(entity->GetComponent(COMPONENT_TYPE_DESTROYABLE)); + auto dest = static_cast(entity->GetComponent(eReplicaComponentType::DESTROYABLE)); if (dest) { dest->SetHealth((int)dest->GetMaxHealth()); dest->SetArmor((int)dest->GetMaxArmor()); @@ -1223,7 +1249,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } if (chatCommand == "spawn" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() >= 1) { - ControllablePhysicsComponent* comp = static_cast(entity->GetComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS)); + ControllablePhysicsComponent* comp = static_cast(entity->GetComponent(eReplicaComponentType::CONTROLLABLE_PHYSICS)); if (!comp) return; uint32_t lot; @@ -1329,9 +1355,8 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit eLootSourceType lootType = eLootSourceType::LOOT_SOURCE_MODERATION; int32_t type; - if (args.size() >= 2 && GeneralUtils::TryParse(args[1], type)) - { - lootType = (eLootSourceType) type; + if (args.size() >= 2 && GeneralUtils::TryParse(args[1], type)) { + lootType = (eLootSourceType)type; } GameMessages::SendModifyLEGOScore(entity, entity->GetSystemAddress(), uscore, lootType); @@ -1654,18 +1679,18 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit if (chatCommand == "spawnphysicsverts" && entity->GetGMLevel() >= 6) { //Go tell physics to spawn all the vertices: - auto entities = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_PHANTOM_PHYSICS); + auto entities = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::PHANTOM_PHYSICS); for (auto en : entities) { - auto phys = static_cast(en->GetComponent(COMPONENT_TYPE_PHANTOM_PHYSICS)); + auto phys = static_cast(en->GetComponent(eReplicaComponentType::PHANTOM_PHYSICS)); if (phys) phys->SpawnVertices(); } } if (chatCommand == "reportproxphys" && entity->GetGMLevel() >= 6) { - auto entities = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_PROXIMITY_MONITOR); + auto entities = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::PROXIMITY_MONITOR); for (auto en : entities) { - auto phys = static_cast(en->GetComponent(COMPONENT_TYPE_PROXIMITY_MONITOR)); + auto phys = static_cast(en->GetComponent(eReplicaComponentType::PROXIMITY_MONITOR)); if (phys) { for (auto prox : phys->GetProximitiesData()) { if (!prox.second) continue; @@ -1759,7 +1784,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit Game::config->ReloadConfig(); VanityUtilities::SpawnVanity(); dpWorld::Instance().Reload(); - auto entities = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_SCRIPTED_ACTIVITY); + auto entities = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::SCRIPTED_ACTIVITY); for (auto entity : entities) { auto* scriptedActivityComponent = entity->GetComponent(); if (!scriptedActivityComponent) continue; @@ -1812,7 +1837,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit eInventoryType inventoryType = eInventoryType::INVALID; if (!GeneralUtils::TryParse(args[0], inventoryType)) { // In this case, we treat the input as a string and try to find it in the reflection list - std::transform(args[0].begin(), args[0].end(),args[0].begin(), ::toupper); + std::transform(args[0].begin(), args[0].end(), args[0].begin(), ::toupper); Game::logger->Log("SlashCommandHandler", "looking for inventory %s", args[0].c_str()); for (uint32_t index = 0; index < NUMBER_OF_INVENTORIES; index++) { if (std::string_view(args[0]) == std::string_view(InventoryType::InventoryTypeToString(static_cast(index)))) inventoryType = static_cast(index); @@ -1838,14 +1863,14 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit if (chatCommand == "inspect" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() >= 1) { Entity* closest = nullptr; - int32_t component; + eReplicaComponentType component; std::u16string ldf; bool isLDF = false; if (!GeneralUtils::TryParse(args[0], component)) { - component = -1; + component = eReplicaComponentType::INVALID; ldf = GeneralUtils::UTF8ToUTF16(args[0]); @@ -1890,7 +1915,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit EntityManager::Instance()->SerializeEntity(closest); - auto* table = CDClientManager::Instance()->GetTable("Objects"); + auto* table = CDClientManager::Instance().GetTable(); const auto& info = table->GetByID(closest->GetLOT()); @@ -1905,7 +1930,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit std::stringstream stream; - stream << "Component [" << std::to_string(id) << "]"; + stream << "Component [" << std::to_string(static_cast(id)) << "]"; ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(stream.str())); } @@ -1986,7 +2011,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } auto* triggerComponent = closest->GetComponent(); - if (triggerComponent){ + if (triggerComponent) { auto trigger = triggerComponent->GetTrigger(); if (trigger) { ChatPackets::SendSystemMessage(sysAddr, u"Trigger: " + (GeneralUtils::to_u16string(trigger->id))); @@ -1999,7 +2024,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit bool SlashCommandHandler::CheckIfAccessibleZone(const unsigned int zoneID) { //We're gonna go ahead and presume we've got the db loaded already: - CDZoneTableTable* zoneTable = CDClientManager::Instance()->GetTable("ZoneTable"); + CDZoneTableTable* zoneTable = CDClientManager::Instance().GetTable(); const CDZoneTable* zone = zoneTable->Query(zoneID); if (zone != nullptr) { return Game::assetManager->HasFile(("maps/" + zone->zoneName).c_str()); diff --git a/dMasterServer/InstanceManager.cpp b/dMasterServer/InstanceManager.cpp index b277adbf..fe62a5e5 100644 --- a/dMasterServer/InstanceManager.cpp +++ b/dMasterServer/InstanceManager.cpp @@ -369,7 +369,7 @@ Instance* InstanceManager::FindPrivateInstance(const std::string& password) { } int InstanceManager::GetSoftCap(LWOMAPID mapID) { - CDZoneTableTable* zoneTable = CDClientManager::Instance()->GetTable("ZoneTable"); + CDZoneTableTable* zoneTable = CDClientManager::Instance().GetTable(); if (zoneTable) { const CDZoneTable* zone = zoneTable->Query(mapID); @@ -382,7 +382,7 @@ int InstanceManager::GetSoftCap(LWOMAPID mapID) { } int InstanceManager::GetHardCap(LWOMAPID mapID) { - CDZoneTableTable* zoneTable = CDClientManager::Instance()->GetTable("ZoneTable"); + CDZoneTableTable* zoneTable = CDClientManager::Instance().GetTable(); if (zoneTable) { const CDZoneTable* zone = zoneTable->Query(mapID); diff --git a/dMasterServer/MasterServer.cpp b/dMasterServer/MasterServer.cpp index 77571e22..cc2bdd90 100644 --- a/dMasterServer/MasterServer.cpp +++ b/dMasterServer/MasterServer.cpp @@ -193,7 +193,7 @@ int main(int argc, char** argv) { //Get CDClient initial information try { - CDClientManager::Instance()->Initialize(); + CDClientManager::Instance(); } catch (CppSQLite3Exception& e) { Game::logger->Log("WorldServer", "Failed to initialize CDServer SQLite Database"); Game::logger->Log("WorldServer", "May be caused by corrupted file: %s", (Game::assetManager->GetResPath() / "CDServer.sqlite").string().c_str()); @@ -212,43 +212,81 @@ int main(int argc, char** argv) { std::cout << "Enter a username: "; std::cin >> username; + std::unique_ptr userLookupStatement(Database::CreatePreppedStmt("SELECT id FROM accounts WHERE name=? LIMIT 1;")); + userLookupStatement->setString(1, username.c_str()); + std::unique_ptr res(userLookupStatement->executeQuery()); + if (res->rowsCount() > 0) { + Game::logger->Log("MasterServer", "Account with name \"%s\" already exists", username.c_str()); + std::cout << "Do you want to change the password of that account? [y/n]?"; + std::string prompt = ""; + std::cin >> prompt; + if (prompt == "y" || prompt == "yes"){ + uint32_t accountId = 0; + res->next(); + accountId = res->getUInt(1); + if (accountId == 0) return EXIT_FAILURE; + + //Read the password from the console without echoing it. + #ifdef __linux__ + //This function is obsolete, but it only meant to be used by the + //sysadmin to create their first account. + password = getpass("Enter a password: "); + #else + std::cout << "Enter a password: "; + std::cin >> password; + #endif + + // Regenerate hash based on new password + char salt[BCRYPT_HASHSIZE]; + char hash[BCRYPT_HASHSIZE]; + int32_t bcryptState = ::bcrypt_gensalt(12, salt); + assert(bcryptState == 0); + bcryptState = ::bcrypt_hashpw(password.c_str(), salt, hash); + assert(bcryptState == 0); + + std::unique_ptr userUpdateStatement(Database::CreatePreppedStmt("UPDATE accounts SET password = ? WHERE id = ?;")); + userUpdateStatement->setString(1, std::string(hash, BCRYPT_HASHSIZE).c_str()); + userUpdateStatement->setUInt(2, accountId); + userUpdateStatement->execute(); + + Game::logger->Log("MasterServer", "Account \"%s\" password updated successfully!", username.c_str()); + } else { + Game::logger->Log("MasterServer", "Account \"%s\" was not updated.", username.c_str()); + } + return EXIT_SUCCESS; + } + //Read the password from the console without echoing it. -#ifdef __linux__ - //This function is obsolete, but it only meant to be used by the - //sysadmin to create their first account. - password = getpass("Enter a password: "); -#else - std::cout << "Enter a password: "; - std::cin >> password; -#endif + #ifdef __linux__ + //This function is obsolete, but it only meant to be used by the + //sysadmin to create their first account. + password = getpass("Enter a password: "); + #else + std::cout << "Enter a password: "; + std::cin >> password; + #endif //Generate new hash for bcrypt - char salt[BCRYPT_HASHSIZE]; char hash[BCRYPT_HASHSIZE]; - int32_t bcryptState = ::bcrypt_gensalt(12, salt); - assert(bcryptState == 0); - bcryptState = ::bcrypt_hashpw(password.c_str(), salt, hash); - assert(bcryptState == 0); //Create account + try { + std::unique_ptr statement(Database::CreatePreppedStmt("INSERT INTO accounts (name, password, gm_level) VALUES (?, ?, ?);")); + statement->setString(1, username.c_str()); + statement->setString(2, std::string(hash, BCRYPT_HASHSIZE).c_str()); + statement->setInt(3, 9); + statement->execute(); + } catch(sql::SQLException& e) { + Game::logger->Log("MasterServer", "A SQL error occurred!:\n %s", e.what()); + return EXIT_FAILURE; + } - auto* statement = Database::CreatePreppedStmt("INSERT INTO accounts (name, password, ""gm_level) VALUES (?, ?, ?);"); - statement->setString(1, username.c_str()); - statement->setString(2, std::string(hash, BCRYPT_HASHSIZE).c_str()); - statement->setInt(3, 9); - - statement->execute(); - - delete statement; - - std::cout << "Account created successfully!\n"; - - + Game::logger->Log("MasterServer", "Account created successfully!"); return EXIT_SUCCESS; } diff --git a/dNet/AuthPackets.cpp b/dNet/AuthPackets.cpp index 636f3fcf..4e7cb0a6 100644 --- a/dNet/AuthPackets.cpp +++ b/dNet/AuthPackets.cpp @@ -21,6 +21,7 @@ #include "Game.h" #include "dConfig.h" +#include "eServerDisconnectIdentifiers.h" void AuthPackets::HandleHandshake(dServer* server, Packet* packet) { RakNet::BitStream inStream(packet->data, packet->length, false); diff --git a/dNet/ClientPackets.cpp b/dNet/ClientPackets.cpp index 9e8153cc..100efac5 100644 --- a/dNet/ClientPackets.cpp +++ b/dNet/ClientPackets.cpp @@ -32,7 +32,7 @@ #include "CharacterComponent.h" #include "Database.h" #include "dMessageIdentifiers.h" - +#include "eReplicaComponentType.h" void ClientPackets::HandleChatMessage(const SystemAddress& sysAddr, Packet* packet) { User* user = UserManager::Instance()->GetUser(sysAddr); @@ -89,7 +89,7 @@ void ClientPackets::HandleClientPositionUpdate(const SystemAddress& sysAddr, Pac Entity* entity = EntityManager::Instance()->GetEntity(user->GetLastUsedChar()->GetObjectID()); if (!entity) return; - ControllablePhysicsComponent* comp = static_cast(entity->GetComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS)); + ControllablePhysicsComponent* comp = static_cast(entity->GetComponent(eReplicaComponentType::CONTROLLABLE_PHYSICS)); if (!comp) return; /* diff --git a/dNet/dServer.cpp b/dNet/dServer.cpp index a3961d45..c91c7508 100644 --- a/dNet/dServer.cpp +++ b/dNet/dServer.cpp @@ -164,7 +164,7 @@ void dServer::SendToMaster(RakNet::BitStream* bitStream) { mMasterPeer->Send(bitStream, SYSTEM_PRIORITY, RELIABLE_ORDERED, 0, mMasterSystemAddress, false); } -void dServer::Disconnect(const SystemAddress& sysAddr, uint32_t disconNotifyID) { +void dServer::Disconnect(const SystemAddress& sysAddr, eServerDisconnectIdentifiers disconNotifyID) { RakNet::BitStream bitStream; PacketUtils::WriteHeader(bitStream, SERVER, MSG_SERVER_DISCONNECT_NOTIFY); bitStream.Write(disconNotifyID); diff --git a/dNet/dServer.h b/dNet/dServer.h index d9e74d2e..797647b6 100644 --- a/dNet/dServer.h +++ b/dNet/dServer.h @@ -6,6 +6,7 @@ class dLogger; class dConfig; +enum class eServerDisconnectIdentifiers : uint32_t; enum class ServerType : uint32_t { Master, @@ -41,7 +42,7 @@ public: virtual void Send(RakNet::BitStream* bitStream, const SystemAddress& sysAddr, bool broadcast); void SendToMaster(RakNet::BitStream* bitStream); - void Disconnect(const SystemAddress& sysAddr, uint32_t disconNotifyID); + void Disconnect(const SystemAddress& sysAddr, eServerDisconnectIdentifiers disconNotifyID); bool IsConnected(const SystemAddress& sysAddr); const std::string& GetIP() const { return mIP; } diff --git a/dScripts/02_server/Enemy/AG/BossSpiderQueenEnemyServer.cpp b/dScripts/02_server/Enemy/AG/BossSpiderQueenEnemyServer.cpp index ef81c888..c584f05b 100644 --- a/dScripts/02_server/Enemy/AG/BossSpiderQueenEnemyServer.cpp +++ b/dScripts/02_server/Enemy/AG/BossSpiderQueenEnemyServer.cpp @@ -13,6 +13,7 @@ #include "GameMessages.h" #include "SkillComponent.h" +#include "eReplicaComponentType.h" #include @@ -27,9 +28,9 @@ void BossSpiderQueenEnemyServer::OnStartup(Entity* self) { //self:SetStatusImmunity{ StateChangeType = "PUSH", bImmuneToPullToPoint = true, bImmuneToKnockback = true, bImmuneToInterrupt = true } //Get our components: - destroyable = static_cast(self->GetComponent(COMPONENT_TYPE_DESTROYABLE)); - controllable = static_cast(self->GetComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS)); - combat = static_cast(self->GetComponent(COMPONENT_TYPE_BASE_COMBAT_AI)); + destroyable = static_cast(self->GetComponent(eReplicaComponentType::DESTROYABLE)); + controllable = static_cast(self->GetComponent(eReplicaComponentType::CONTROLLABLE_PHYSICS)); + combat = static_cast(self->GetComponent(eReplicaComponentType::BASE_COMBAT_AI)); if (!destroyable || !controllable) return; @@ -397,7 +398,7 @@ void BossSpiderQueenEnemyServer::RapidFireShooterManager(Entity* self) { void BossSpiderQueenEnemyServer::RunRapidFireShooter(Entity* self) { /* - const auto targets = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_CHARACTER); + const auto targets = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::CHARACTER); */ const auto targets = self->GetTargetsInPhantom(); diff --git a/dScripts/02_server/Enemy/General/BaseEnemyMech.cpp b/dScripts/02_server/Enemy/General/BaseEnemyMech.cpp index 8c200566..ce42585c 100644 --- a/dScripts/02_server/Enemy/General/BaseEnemyMech.cpp +++ b/dScripts/02_server/Enemy/General/BaseEnemyMech.cpp @@ -6,6 +6,7 @@ #include "EntityInfo.h" #include "GeneralUtils.h" #include "DestroyableComponent.h" +#include "eReplicaComponentType.h" void BaseEnemyMech::OnStartup(Entity* self) { auto* destroyableComponent = self->GetComponent(); @@ -15,7 +16,7 @@ void BaseEnemyMech::OnStartup(Entity* self) { } void BaseEnemyMech::OnDie(Entity* self, Entity* killer) { - ControllablePhysicsComponent* controlPhys = static_cast(self->GetComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS)); + ControllablePhysicsComponent* controlPhys = static_cast(self->GetComponent(eReplicaComponentType::CONTROLLABLE_PHYSICS)); if (!controlPhys) return; NiPoint3 newLoc = { controlPhys->GetPosition().x, dpWorld::Instance().GetNavMesh()->GetHeightAtPoint(controlPhys->GetPosition()), controlPhys->GetPosition().z }; diff --git a/dScripts/02_server/Map/AG/AgCagedBricksServer.cpp b/dScripts/02_server/Map/AG/AgCagedBricksServer.cpp index 6d1360de..3c400e5d 100644 --- a/dScripts/02_server/Map/AG/AgCagedBricksServer.cpp +++ b/dScripts/02_server/Map/AG/AgCagedBricksServer.cpp @@ -3,6 +3,7 @@ #include "GameMessages.h" #include "Character.h" #include "EntityManager.h" +#include "eReplicaComponentType.h" void AgCagedBricksServer::OnUse(Entity* self, Entity* user) { //Tell the client to spawn the baby spiderling: @@ -19,7 +20,7 @@ void AgCagedBricksServer::OnUse(Entity* self, Entity* user) { character->SetPlayerFlag(74, true); //Remove the maelstrom cube: - auto inv = static_cast(user->GetComponent(COMPONENT_TYPE_INVENTORY)); + auto inv = static_cast(user->GetComponent(eReplicaComponentType::INVENTORY)); if (inv) { inv->RemoveItem(14553, 1); diff --git a/dScripts/02_server/Map/AG/AgLaserSensorServer.cpp b/dScripts/02_server/Map/AG/AgLaserSensorServer.cpp index 9efae1ca..c09000be 100644 --- a/dScripts/02_server/Map/AG/AgLaserSensorServer.cpp +++ b/dScripts/02_server/Map/AG/AgLaserSensorServer.cpp @@ -5,10 +5,11 @@ #include "EntityManager.h" #include "AgMonumentLaserServer.h" #include "EntityManager.h" +#include "eReplicaComponentType.h" void AgLaserSensorServer::OnStartup(Entity* self) { - PhantomPhysicsComponent* physComp = static_cast(self->GetComponent(COMPONENT_TYPE_PHANTOM_PHYSICS)); + PhantomPhysicsComponent* physComp = static_cast(self->GetComponent(eReplicaComponentType::PHANTOM_PHYSICS)); physComp->SetPhysicsEffectActive(true); physComp->SetEffectType(2); // repulse (prolly should make definitions of these are in Entity.cpp) physComp->SetDirectionalMultiplier(static_cast(m_RepelForce)); @@ -25,7 +26,7 @@ void AgLaserSensorServer::OnCollisionPhantom(Entity* self, Entity* target) { Entity* laser = nullptr; - for (auto script : EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_SCRIPT)) { + for (auto script : EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::SCRIPT)) { AgMonumentLaserServer* hasLaser = (AgMonumentLaserServer*)script; diff --git a/dScripts/02_server/Map/AG/AgMonumentRaceGoal.cpp b/dScripts/02_server/Map/AG/AgMonumentRaceGoal.cpp index 78bbaee5..0dd91bf2 100644 --- a/dScripts/02_server/Map/AG/AgMonumentRaceGoal.cpp +++ b/dScripts/02_server/Map/AG/AgMonumentRaceGoal.cpp @@ -7,9 +7,9 @@ void AgMonumentRaceGoal::OnStartup(Entity* self) { } void AgMonumentRaceGoal::OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status) { - if (name == "RaceGoal" && entering->IsPlayer() && status == "ENTER") { - auto* manager = EntityManager::Instance()->GetEntitiesInGroup("race_manager")[0]; - - manager->OnFireEventServerSide(entering, "course_finish"); + if (name == "RaceGoal" && entering && entering->IsPlayer() && status == "ENTER") { + auto managers = EntityManager::Instance()->GetEntitiesInGroup("race_manager"); + if (managers.empty() || !managers.at(0)) return; + managers.at(0)->OnFireEventServerSide(entering, "course_finish"); } } diff --git a/dScripts/02_server/Map/AG/NpcNjAssistantServer.cpp b/dScripts/02_server/Map/AG/NpcNjAssistantServer.cpp index 183765d7..8ee2e988 100644 --- a/dScripts/02_server/Map/AG/NpcNjAssistantServer.cpp +++ b/dScripts/02_server/Map/AG/NpcNjAssistantServer.cpp @@ -4,6 +4,7 @@ #include "MissionComponent.h" #include "Item.h" #include "eMissionState.h" +#include "eReplicaComponentType.h" void NpcNjAssistantServer::OnMissionDialogueOK(Entity* self, Entity* target, int missionID, eMissionState missionState) { if (missionID != mailMission) return; @@ -11,7 +12,7 @@ void NpcNjAssistantServer::OnMissionDialogueOK(Entity* self, Entity* target, int if (missionState == eMissionState::COMPLETE || missionState == eMissionState::READY_TO_COMPLETE) { GameMessages::SendNotifyClientObject(self->GetObjectID(), u"switch", 0, 0, LWOOBJID_EMPTY, "", target->GetSystemAddress()); - auto* inv = static_cast(target->GetComponent(COMPONENT_TYPE_INVENTORY)); + auto* inv = static_cast(target->GetComponent(eReplicaComponentType::INVENTORY)); // If we are ready to complete our missions, we take the kit from you: if (inv && missionState == eMissionState::READY_TO_COMPLETE) { @@ -22,7 +23,7 @@ void NpcNjAssistantServer::OnMissionDialogueOK(Entity* self, Entity* target, int } } } else if (missionState == eMissionState::AVAILABLE) { - auto* missionComponent = static_cast(target->GetComponent(COMPONENT_TYPE_MISSION)); + auto* missionComponent = static_cast(target->GetComponent(eReplicaComponentType::MISSION)); missionComponent->CompleteMission(mailAchievement, true); } } diff --git a/dScripts/02_server/Map/AG/RemoveRentalGear.cpp b/dScripts/02_server/Map/AG/RemoveRentalGear.cpp index 6e7bd4de..18177e57 100644 --- a/dScripts/02_server/Map/AG/RemoveRentalGear.cpp +++ b/dScripts/02_server/Map/AG/RemoveRentalGear.cpp @@ -3,6 +3,7 @@ #include "Item.h" #include "eMissionState.h" #include "Character.h" +#include "eReplicaComponentType.h" /* -------------------------------------------------------------- @@ -21,7 +22,7 @@ void RemoveRentalGear::OnMissionDialogueOK(Entity* self, Entity* target, int mis if (missionID != defaultMission && missionID != 313) return; if (missionState == eMissionState::COMPLETE || missionState == eMissionState::READY_TO_COMPLETE) { - auto inv = static_cast(target->GetComponent(COMPONENT_TYPE_INVENTORY)); + auto inv = static_cast(target->GetComponent(eReplicaComponentType::INVENTORY)); if (!inv) return; //remove the inventory items diff --git a/dScripts/02_server/Map/FV/FvCandle.cpp b/dScripts/02_server/Map/FV/FvCandle.cpp index efd717ee..0c4344d0 100644 --- a/dScripts/02_server/Map/FV/FvCandle.cpp +++ b/dScripts/02_server/Map/FV/FvCandle.cpp @@ -1,11 +1,12 @@ #include "FvCandle.h" #include "MissionComponent.h" #include "RenderComponent.h" +#include "eReplicaComponentType.h" std::vector FvCandle::m_Missions = { 850, 1431, 1529, 1566, 1603 }; void FvCandle::OnStartup(Entity* self) { - auto* render = static_cast(self->GetComponent(COMPONENT_TYPE_RENDER)); + auto* render = static_cast(self->GetComponent(eReplicaComponentType::RENDER)); if (render == nullptr) return; @@ -22,7 +23,7 @@ void FvCandle::BlowOutCandle(Entity* self, Entity* blower) { if (self->GetBoolean(u"AmHit")) return; - auto* render = static_cast(self->GetComponent(COMPONENT_TYPE_RENDER)); + auto* render = static_cast(self->GetComponent(eReplicaComponentType::RENDER)); if (render == nullptr) return; @@ -46,7 +47,7 @@ void FvCandle::BlowOutCandle(Entity* self, Entity* blower) { void FvCandle::OnTimerDone(Entity* self, std::string timerName) { self->SetBoolean(u"AmHit", false); - auto* render = static_cast(self->GetComponent(COMPONENT_TYPE_RENDER)); + auto* render = static_cast(self->GetComponent(eReplicaComponentType::RENDER)); if (render == nullptr) return; diff --git a/dScripts/02_server/Map/GF/GfTikiTorch.cpp b/dScripts/02_server/Map/GF/GfTikiTorch.cpp index db7ee6b5..22420679 100644 --- a/dScripts/02_server/Map/GF/GfTikiTorch.cpp +++ b/dScripts/02_server/Map/GF/GfTikiTorch.cpp @@ -4,6 +4,7 @@ #include "MissionComponent.h" #include "RenderComponent.h" #include "eMissionTaskType.h" +#include "eReplicaComponentType.h" void GfTikiTorch::OnStartup(Entity* self) { LightTorch(self); @@ -42,7 +43,7 @@ void GfTikiTorch::OnTimerDone(Entity* self, std::string timerName) { } void GfTikiTorch::LightTorch(Entity* self) { - auto* renderComponent = static_cast(self->GetComponent(COMPONENT_TYPE_RENDER)); + auto* renderComponent = static_cast(self->GetComponent(eReplicaComponentType::RENDER)); if (renderComponent == nullptr) return; diff --git a/dScripts/02_server/Map/GF/MastTeleport.cpp b/dScripts/02_server/Map/GF/MastTeleport.cpp index dac5783c..6e50c6ec 100644 --- a/dScripts/02_server/Map/GF/MastTeleport.cpp +++ b/dScripts/02_server/Map/GF/MastTeleport.cpp @@ -2,6 +2,7 @@ #include "EntityManager.h" #include "GameMessages.h" #include "Preconditions.h" +#include "DestroyableComponent.h" #ifdef _WIN32 #define _USE_MATH_DEFINES @@ -19,6 +20,8 @@ void MastTeleport::OnRebuildComplete(Entity* self, Entity* target) { GameMessages::SendSetStunned(target->GetObjectID(), eStateChangeType::PUSH, target->GetSystemAddress(), LWOOBJID_EMPTY, true, true, true, true, true, true, true ); + auto* destroyableComponent = target->GetComponent(); + if (destroyableComponent) destroyableComponent->SetStatusImmunity(eStateChangeType::PUSH, true, true, true, true, true, false, false, true, true); self->AddTimer("Start", 3); } @@ -55,7 +58,7 @@ void MastTeleport::OnTimerDone(Entity* self, std::string timerName) { GameMessages::SendPlayFXEffect(playerId, 6039, u"hook", "hook", LWOOBJID_EMPTY, 1, 1, true); - GameMessages::SendPlayAnimation(player, u"crow-swing-no-equip"); + GameMessages::SendPlayAnimation(player, u"crow-swing-no-equip", 4.0f); GameMessages::SendPlayAnimation(self, u"swing"); @@ -84,5 +87,8 @@ void MastTeleport::OnTimerDone(Entity* self, std::string timerName) { GameMessages::SendSetStunned(playerId, eStateChangeType::POP, player->GetSystemAddress(), LWOOBJID_EMPTY, true, true, true, true, true, true, true ); + auto* destroyableComponent = player->GetComponent(); + if (destroyableComponent) destroyableComponent->SetStatusImmunity(eStateChangeType::POP, true, true, true, true, true, false, false, true, true); + EntityManager::Instance()->SerializeEntity(player); } } diff --git a/dScripts/02_server/Map/General/QbEnemyStunner.cpp b/dScripts/02_server/Map/General/QbEnemyStunner.cpp index 2b15a056..441d743c 100644 --- a/dScripts/02_server/Map/General/QbEnemyStunner.cpp +++ b/dScripts/02_server/Map/General/QbEnemyStunner.cpp @@ -3,6 +3,9 @@ #include "CDClientManager.h" #include "DestroyableComponent.h" +#include "CDObjectSkillsTable.h" +#include "CDSkillBehaviorTable.h" + void QbEnemyStunner::OnRebuildComplete(Entity* self, Entity* target) { auto* destroyable = self->GetComponent(); @@ -14,12 +17,12 @@ void QbEnemyStunner::OnRebuildComplete(Entity* self, Entity* target) { if (!skillComponent) return; // Get the skill IDs of this object. - CDObjectSkillsTable* skillsTable = CDClientManager::Instance()->GetTable("ObjectSkills"); + CDObjectSkillsTable* skillsTable = CDClientManager::Instance().GetTable(); auto skills = skillsTable->Query([=](CDObjectSkills entry) {return (entry.objectTemplate == self->GetLOT()); }); std::map skillBehaviorMap; // For each skill, cast it with the associated behavior ID. for (auto skill : skills) { - CDSkillBehaviorTable* skillBehaviorTable = CDClientManager::Instance()->GetTable("SkillBehavior"); + CDSkillBehaviorTable* skillBehaviorTable = CDClientManager::Instance().GetTable(); CDSkillBehavior behaviorData = skillBehaviorTable->GetSkillByID(skill.skillID); skillBehaviorMap.insert(std::make_pair(skill.skillID, behaviorData.behaviorID)); diff --git a/dScripts/02_server/Map/General/TokenConsoleServer.cpp b/dScripts/02_server/Map/General/TokenConsoleServer.cpp index f21938d1..5212a9b5 100644 --- a/dScripts/02_server/Map/General/TokenConsoleServer.cpp +++ b/dScripts/02_server/Map/General/TokenConsoleServer.cpp @@ -2,11 +2,12 @@ #include "InventoryComponent.h" #include "GameMessages.h" #include "Character.h" +#include "eReplicaComponentType.h" //2021-05-03 - max - added script, omitted some parts related to inheritance in lua which we don't need void TokenConsoleServer::OnUse(Entity* self, Entity* user) { - auto* inv = static_cast(user->GetComponent(COMPONENT_TYPE_INVENTORY)); + auto* inv = static_cast(user->GetComponent(eReplicaComponentType::INVENTORY)); //make sure the user has the required amount of infected bricks if (inv && inv->GetLotCount(6194) >= bricksToTake) { diff --git a/dScripts/02_server/Map/General/TouchMissionUpdateServer.cpp b/dScripts/02_server/Map/General/TouchMissionUpdateServer.cpp index 00c1b900..7b2495d0 100644 --- a/dScripts/02_server/Map/General/TouchMissionUpdateServer.cpp +++ b/dScripts/02_server/Map/General/TouchMissionUpdateServer.cpp @@ -4,6 +4,7 @@ #include "GameMessages.h" #include "MissionComponent.h" #include "eMissionState.h" +#include "eReplicaComponentType.h" void TouchMissionUpdateServer::OnStartup(Entity* self) { self->SetProximityRadius(20, "touchCheck"); // Those does not have a collider for some reason? @@ -16,7 +17,7 @@ void TouchMissionUpdateServer::OnCollisionPhantom(Entity* self, Entity* target) return; } - auto* missionComponent = static_cast(target->GetComponent(COMPONENT_TYPE_MISSION)); + auto* missionComponent = static_cast(target->GetComponent(eReplicaComponentType::MISSION)); if (missionComponent == nullptr) { return; diff --git a/dScripts/02_server/Map/NS/Waves/ZoneNsWaves.cpp b/dScripts/02_server/Map/NS/Waves/ZoneNsWaves.cpp index 6f78acb6..184132fe 100644 --- a/dScripts/02_server/Map/NS/Waves/ZoneNsWaves.cpp +++ b/dScripts/02_server/Map/NS/Waves/ZoneNsWaves.cpp @@ -439,7 +439,7 @@ std::vector ZoneNsWaves::GetWaves() { 5.0f, (uint32_t)-1, true, - 30, + 60, }, }; } diff --git a/dScripts/02_server/Map/NS/Waves/ZoneNsWaves.h b/dScripts/02_server/Map/NS/Waves/ZoneNsWaves.h index 06503d19..637aceb7 100644 --- a/dScripts/02_server/Map/NS/Waves/ZoneNsWaves.h +++ b/dScripts/02_server/Map/NS/Waves/ZoneNsWaves.h @@ -1,6 +1,8 @@ #pragma once #include "BaseWavesServer.h" +#include "dCommonVars.h" + enum SpawnerName { interior_A, interior_B, diff --git a/dScripts/02_server/Map/Property/AG_Small/EnemySpiderSpawner.cpp b/dScripts/02_server/Map/Property/AG_Small/EnemySpiderSpawner.cpp index 695bd92f..0d4f568e 100644 --- a/dScripts/02_server/Map/Property/AG_Small/EnemySpiderSpawner.cpp +++ b/dScripts/02_server/Map/Property/AG_Small/EnemySpiderSpawner.cpp @@ -3,6 +3,7 @@ #include "EntityManager.h" #include "EntityInfo.h" #include "DestroyableComponent.h" +#include "eReplicaComponentType.h" //---------------------------------------------- //--Initiate egg hatching on call @@ -14,7 +15,7 @@ void EnemySpiderSpawner::OnFireEventServerSide(Entity* self, Entity* sender, std GameMessages::SendPlayFXEffect(self->GetObjectID(), 2856, u"maelstrom", "test", LWOOBJID_EMPTY, 1.0f, 1.0f, true); // Make indestructible - auto dest = static_cast(self->GetComponent(COMPONENT_TYPE_DESTROYABLE)); + auto dest = static_cast(self->GetComponent(eReplicaComponentType::DESTROYABLE)); if (dest) { dest->SetFaction(-1); } diff --git a/dScripts/02_server/Map/Property/AG_Small/ZoneAgProperty.cpp b/dScripts/02_server/Map/Property/AG_Small/ZoneAgProperty.cpp index b6172df1..215e22c2 100644 --- a/dScripts/02_server/Map/Property/AG_Small/ZoneAgProperty.cpp +++ b/dScripts/02_server/Map/Property/AG_Small/ZoneAgProperty.cpp @@ -7,6 +7,7 @@ #include "RenderComponent.h" #include "MissionComponent.h" #include "eMissionState.h" +#include "eReplicaComponentType.h" void ZoneAgProperty::SetGameVariables(Entity* self) { self->SetVar(GuardGroup, "Guard"); @@ -256,7 +257,7 @@ void ZoneAgProperty::BaseTimerDone(Entity* self, const std::string& timerName) { DeactivateSpawner(self->GetVar(SpiderScreamSpawner)); DestroySpawner(self->GetVar(SpiderScreamSpawner)); - for (auto* player : EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_CHARACTER)) { + for (auto* player : EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::CHARACTER)) { GameMessages::SendStop2DAmbientSound(player, true, GUIDMaelstrom); GameMessages::SendPlay2DAmbientSound(player, GUIDPeaceful); } diff --git a/dScripts/02_server/Map/SS/SsModularBuildServer.cpp b/dScripts/02_server/Map/SS/SsModularBuildServer.cpp index 82c802cc..dfb29168 100644 --- a/dScripts/02_server/Map/SS/SsModularBuildServer.cpp +++ b/dScripts/02_server/Map/SS/SsModularBuildServer.cpp @@ -1,12 +1,13 @@ #include "SsModularBuildServer.h" #include "MissionComponent.h" #include "eMissionState.h" +#include "eReplicaComponentType.h" void SsModularBuildServer::OnModularBuildExit(Entity* self, Entity* player, bool bCompleted, std::vector modules) { int missionNum = 1732; if (bCompleted) { - MissionComponent* mission = static_cast(player->GetComponent(COMPONENT_TYPE_MISSION)); + MissionComponent* mission = static_cast(player->GetComponent(eReplicaComponentType::MISSION)); Mission* rocketMission = mission->GetMission(missionNum); if (rocketMission->GetMissionState() == eMissionState::ACTIVE) { diff --git a/dScripts/02_server/Objects/StinkyFishTarget.cpp b/dScripts/02_server/Objects/StinkyFishTarget.cpp index 21d92fac..459e0bbe 100644 --- a/dScripts/02_server/Objects/StinkyFishTarget.cpp +++ b/dScripts/02_server/Objects/StinkyFishTarget.cpp @@ -1,6 +1,7 @@ #include "StinkyFishTarget.h" #include "EntityManager.h" #include "EntityInfo.h" +#include "Entity.h" void StinkyFishTarget::OnStartup(Entity* self) { auto position = self->GetPosition(); @@ -16,6 +17,7 @@ void StinkyFishTarget::OnSkillEventFired(Entity* self, Entity* caster, const std self->SetVar(u"player", caster->GetObjectID()); EntityInfo entityInfo{}; + entityInfo.lot = SHARK_LOT; entityInfo.pos = self->GetPosition(); entityInfo.rot = self->GetRotation(); entityInfo.spawnerID = self->GetObjectID(); @@ -35,7 +37,7 @@ void StinkyFishTarget::OnTimerDone(Entity* self, std::string timerName) { const auto playerID = self->GetVar(u"player"); auto* fish = EntityManager::Instance()->GetEntity(self->GetVar(u"fish")); - if (fish != nullptr) { + if (fish) { fish->Smash(playerID); self->Smash(playerID); } diff --git a/dScripts/02_server/Objects/StinkyFishTarget.h b/dScripts/02_server/Objects/StinkyFishTarget.h index 6c52171d..b8f9e9ae 100644 --- a/dScripts/02_server/Objects/StinkyFishTarget.h +++ b/dScripts/02_server/Objects/StinkyFishTarget.h @@ -2,7 +2,10 @@ #include "CppScripts.h" class StinkyFishTarget : public CppScripts::Script { +public: void OnStartup(Entity* self) override; void OnSkillEventFired(Entity* self, Entity* caster, const std::string& message) override; void OnTimerDone(Entity* self, std::string timerName) override; +private: + const LOT SHARK_LOT = 8570; }; diff --git a/dScripts/BaseWavesServer.cpp b/dScripts/BaseWavesServer.cpp index ad40a77d..00340bd0 100644 --- a/dScripts/BaseWavesServer.cpp +++ b/dScripts/BaseWavesServer.cpp @@ -430,7 +430,7 @@ void BaseWavesServer::SpawnWave(Entity* self) { for (const auto& playerID : state.players) { auto* player = EntityManager::Instance()->GetEntity(playerID); - if (player != nullptr) { + if (player && player->GetIsDead()) { player->Resurrect(); } } diff --git a/dScripts/CppScripts.cpp b/dScripts/CppScripts.cpp index 745a74ae..24b30dee 100644 --- a/dScripts/CppScripts.cpp +++ b/dScripts/CppScripts.cpp @@ -281,6 +281,7 @@ #include "GemPack.h" #include "ShardArmor.h" #include "TeslaPack.h" +#include "StunImmunity.h" // Survival scripts #include "AgSurvivalStromling.h" @@ -846,6 +847,8 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr script = new ShardArmor(); else if (scriptName == "scripts\\equipmenttriggers\\coilbackpack.lua") script = new TeslaPack(); + else if (scriptName == "scripts\\EquipmentScripts\\stunImmunity.lua") + script = new StunImmunity(); // FB else if (scriptName == "scripts\\ai\\NS\\WH\\L_ROCKHYDRANT_BROKEN.lua") diff --git a/dScripts/EquipmentScripts/CMakeLists.txt b/dScripts/EquipmentScripts/CMakeLists.txt index c870ae31..696be03d 100644 --- a/dScripts/EquipmentScripts/CMakeLists.txt +++ b/dScripts/EquipmentScripts/CMakeLists.txt @@ -1,4 +1,4 @@ -set(DSCRIPTS_SOURCES_EQUIPMENTSCRIPTS +set(DSCRIPTS_SOURCES_EQUIPMENTSCRIPTS "Sunflower.cpp" "AnvilOfArmor.cpp" "FountainOfImagination.cpp" @@ -6,4 +6,5 @@ set(DSCRIPTS_SOURCES_EQUIPMENTSCRIPTS "PersonalFortress.cpp" "BuccaneerValiantShip.cpp" "FireFirstSkillonStartup.cpp" + "StunImmunity.cpp" PARENT_SCOPE) diff --git a/dScripts/EquipmentScripts/FireFirstSkillonStartup.cpp b/dScripts/EquipmentScripts/FireFirstSkillonStartup.cpp index dcccc337..389f3621 100644 --- a/dScripts/EquipmentScripts/FireFirstSkillonStartup.cpp +++ b/dScripts/EquipmentScripts/FireFirstSkillonStartup.cpp @@ -3,6 +3,7 @@ #include "SkillComponent.h" #include "CDClientDatabase.h" #include "CDObjectSkillsTable.h" +#include "CDSkillBehaviorTable.h" #include "CDClientManager.h" void FireFirstSkillonStartup::OnStartup(Entity* self) { @@ -10,12 +11,12 @@ void FireFirstSkillonStartup::OnStartup(Entity* self) { if (!skillComponent) return; // Get the skill IDs of this object. - CDObjectSkillsTable* skillsTable = CDClientManager::Instance()->GetTable("ObjectSkills"); + CDObjectSkillsTable* skillsTable = CDClientManager::Instance().GetTable(); std::vector skills = skillsTable->Query([=](CDObjectSkills entry) {return (entry.objectTemplate == self->GetLOT()); }); // For each skill, cast it with the associated behavior ID. for (auto skill : skills) { - CDSkillBehaviorTable* skillBehaviorTable = CDClientManager::Instance()->GetTable("SkillBehavior"); + CDSkillBehaviorTable* skillBehaviorTable = CDClientManager::Instance().GetTable(); CDSkillBehavior behaviorData = skillBehaviorTable->GetSkillByID(skill.skillID); // Should parent entity be null, make the originator self. diff --git a/dScripts/EquipmentScripts/StunImmunity.cpp b/dScripts/EquipmentScripts/StunImmunity.cpp new file mode 100644 index 00000000..f35fe261 --- /dev/null +++ b/dScripts/EquipmentScripts/StunImmunity.cpp @@ -0,0 +1,19 @@ +#include "StunImmunity.h" +#include "DestroyableComponent.h" +#include "ControllablePhysicsComponent.h" + +void StunImmunity::OnStartup(Entity* self) { + auto* destroyableComponent = self->GetComponent(); + if (destroyableComponent) { + destroyableComponent->SetStatusImmunity( + eStateChangeType::PUSH, false, false, true, true, false, false, false, false, true + ); + } + + auto* controllablePhysicsComponent = self->GetComponent(); + if (controllablePhysicsComponent) { + controllablePhysicsComponent->SetStunImmunity( + eStateChangeType::PUSH, self->GetObjectID(), true + ); + } +} diff --git a/dScripts/EquipmentScripts/StunImmunity.h b/dScripts/EquipmentScripts/StunImmunity.h new file mode 100644 index 00000000..0faaf061 --- /dev/null +++ b/dScripts/EquipmentScripts/StunImmunity.h @@ -0,0 +1,6 @@ +#pragma once +#include "CppScripts.h" + +class StunImmunity : public CppScripts::Script { + void OnStartup(Entity* self) override; +}; diff --git a/dScripts/NtFactionSpyServer.cpp b/dScripts/NtFactionSpyServer.cpp index 684e6a0e..dc62855a 100644 --- a/dScripts/NtFactionSpyServer.cpp +++ b/dScripts/NtFactionSpyServer.cpp @@ -5,6 +5,7 @@ #include "GameMessages.h" #include "MissionComponent.h" #include "eMissionState.h" +#include "eReplicaComponentType.h" void NtFactionSpyServer::OnStartup(Entity* self) { SetVariables(self); @@ -13,7 +14,7 @@ void NtFactionSpyServer::OnStartup(Entity* self) { auto* proximityMonitor = self->GetComponent(); if (proximityMonitor == nullptr) { proximityMonitor = new ProximityMonitorComponent(self, -1, -1); - self->AddComponent(COMPONENT_TYPE_PROXIMITY_MONITOR, proximityMonitor); + self->AddComponent(eReplicaComponentType::PROXIMITY_MONITOR, proximityMonitor); } proximityMonitor->SetProximityRadius(self->GetVar(m_SpyProximityVariable), m_ProximityName); diff --git a/dScripts/ScriptComponent.h b/dScripts/ScriptComponent.h index 94226627..77dff5bf 100644 --- a/dScripts/ScriptComponent.h +++ b/dScripts/ScriptComponent.h @@ -9,6 +9,7 @@ #include "CppScripts.h" #include "Component.h" #include +#include "eReplicaComponentType.h" class Entity; @@ -18,7 +19,7 @@ class Entity; */ class ScriptComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_SCRIPT; + static const eReplicaComponentType ComponentType = eReplicaComponentType::SCRIPT; ScriptComponent(Entity* parent, std::string scriptName, bool serialized, bool client = false); ~ScriptComponent() override; diff --git a/dScripts/ai/ACT/ActPlayerDeathTrigger.cpp b/dScripts/ai/ACT/ActPlayerDeathTrigger.cpp index 28f1ef43..0674f0dd 100644 --- a/dScripts/ai/ACT/ActPlayerDeathTrigger.cpp +++ b/dScripts/ai/ACT/ActPlayerDeathTrigger.cpp @@ -1,5 +1,7 @@ #include "ActPlayerDeathTrigger.h" +#include "Entity.h" + void ActPlayerDeathTrigger::OnCollisionPhantom(Entity* self, Entity* target) { if (!target->IsPlayer() || target->GetIsDead() || !target->GetPlayerReadyForUpdates()) return; //Don't kill already dead players or players not ready diff --git a/dScripts/ai/AG/AgFans.cpp b/dScripts/ai/AG/AgFans.cpp index 27d3b940..e05fe68d 100644 --- a/dScripts/ai/AG/AgFans.cpp +++ b/dScripts/ai/AG/AgFans.cpp @@ -4,6 +4,7 @@ #include "GameMessages.h" #include "PhantomPhysicsComponent.h" #include "RenderComponent.h" +#include "eReplicaComponentType.h" void AgFans::OnStartup(Entity* self) { self->SetVar(u"alive", true); @@ -11,7 +12,7 @@ void AgFans::OnStartup(Entity* self) { ToggleFX(self, false); - auto* renderComponent = static_cast(self->GetComponent(COMPONENT_TYPE_RENDER)); + auto* renderComponent = static_cast(self->GetComponent(eReplicaComponentType::RENDER)); if (renderComponent == nullptr) { return; @@ -24,7 +25,7 @@ void AgFans::ToggleFX(Entity* self, bool hit) { std::string fanGroup = self->GetGroups()[0]; std::vector fanVolumes = EntityManager::Instance()->GetEntitiesInGroup(fanGroup); - auto* renderComponent = static_cast(self->GetComponent(COMPONENT_TYPE_RENDER)); + auto* renderComponent = static_cast(self->GetComponent(eReplicaComponentType::RENDER)); if (renderComponent == nullptr) { return; @@ -39,7 +40,7 @@ void AgFans::ToggleFX(Entity* self, bool hit) { self->SetVar(u"on", false); for (Entity* volume : fanVolumes) { - PhantomPhysicsComponent* volumePhys = static_cast(volume->GetComponent(COMPONENT_TYPE_PHANTOM_PHYSICS)); + PhantomPhysicsComponent* volumePhys = static_cast(volume->GetComponent(eReplicaComponentType::PHANTOM_PHYSICS)); if (!volumePhys) continue; volumePhys->SetPhysicsEffectActive(false); EntityManager::Instance()->SerializeEntity(volume); @@ -55,7 +56,7 @@ void AgFans::ToggleFX(Entity* self, bool hit) { self->SetVar(u"on", true); for (Entity* volume : fanVolumes) { - PhantomPhysicsComponent* volumePhys = static_cast(volume->GetComponent(COMPONENT_TYPE_PHANTOM_PHYSICS)); + PhantomPhysicsComponent* volumePhys = static_cast(volume->GetComponent(eReplicaComponentType::PHANTOM_PHYSICS)); if (!volumePhys) continue; volumePhys->SetPhysicsEffectActive(true); EntityManager::Instance()->SerializeEntity(volume); diff --git a/dScripts/ai/AG/AgImagSmashable.cpp b/dScripts/ai/AG/AgImagSmashable.cpp index 195f7b9a..5e8331b1 100644 --- a/dScripts/ai/AG/AgImagSmashable.cpp +++ b/dScripts/ai/AG/AgImagSmashable.cpp @@ -4,12 +4,13 @@ #include "GameMessages.h" #include "EntityInfo.h" #include "DestroyableComponent.h" +#include "eReplicaComponentType.h" void AgImagSmashable::OnDie(Entity* self, Entity* killer) { bool maxImagGreaterThanZero = false; if (killer) { - DestroyableComponent* dest = static_cast(killer->GetComponent(COMPONENT_TYPE_DESTROYABLE)); + DestroyableComponent* dest = static_cast(killer->GetComponent(eReplicaComponentType::DESTROYABLE)); if (dest) { maxImagGreaterThanZero = dest->GetMaxImagination() > 0; } diff --git a/dScripts/ai/AG/AgJetEffectServer.cpp b/dScripts/ai/AG/AgJetEffectServer.cpp index 8c7eca3b..9546bc4d 100644 --- a/dScripts/ai/AG/AgJetEffectServer.cpp +++ b/dScripts/ai/AG/AgJetEffectServer.cpp @@ -2,6 +2,7 @@ #include "GameMessages.h" #include "EntityManager.h" #include "SkillComponent.h" +#include "eReplicaComponentType.h" void AgJetEffectServer::OnUse(Entity* self, Entity* user) { if (inUse) { @@ -86,12 +87,12 @@ void AgJetEffectServer::OnTimerDone(Entity* self, std::string timerName) { auto* mortar = entities[selected]; - Game::logger->Log("AgJetEffectServer", "Mortar (%i) (&d)", mortar->GetLOT(), mortar->HasComponent(COMPONENT_TYPE_SKILL)); + Game::logger->Log("AgJetEffectServer", "Mortar (%i) (&d)", mortar->GetLOT(), mortar->HasComponent(eReplicaComponentType::SKILL)); mortar->SetOwnerOverride(builder); SkillComponent* skillComponent; - if (!mortar->TryGetComponent(COMPONENT_TYPE_SKILL, skillComponent)) { + if (!mortar->TryGetComponent(eReplicaComponentType::SKILL, skillComponent)) { return; } diff --git a/dScripts/ai/AG/AgStromlingProperty.cpp b/dScripts/ai/AG/AgStromlingProperty.cpp index 36d8d378..9a9ae33b 100644 --- a/dScripts/ai/AG/AgStromlingProperty.cpp +++ b/dScripts/ai/AG/AgStromlingProperty.cpp @@ -1,5 +1,6 @@ #include "AgStromlingProperty.h" #include "MovementAIComponent.h" +#include "eReplicaComponentType.h" void AgStromlingProperty::OnStartup(Entity* self) { auto movementInfo = MovementAIInfo{ @@ -12,5 +13,5 @@ void AgStromlingProperty::OnStartup(Entity* self) { }; auto* movementAIComponent = new MovementAIComponent(self, movementInfo); - self->AddComponent(COMPONENT_TYPE_MOVEMENT_AI, movementAIComponent); + self->AddComponent(eReplicaComponentType::MOVEMENT_AI, movementAIComponent); } diff --git a/dScripts/ai/GF/GfCampfire.cpp b/dScripts/ai/GF/GfCampfire.cpp index 95e29a9a..6a10b39e 100644 --- a/dScripts/ai/GF/GfCampfire.cpp +++ b/dScripts/ai/GF/GfCampfire.cpp @@ -4,13 +4,14 @@ #include "MissionComponent.h" #include "RenderComponent.h" #include "EntityManager.h" +#include "eReplicaComponentType.h" void GfCampfire::OnStartup(Entity* self) { self->SetI32(u"counter", static_cast(0)); self->SetProximityRadius(2.0f, "placeholder"); self->SetBoolean(u"isBurning", true); - auto* render = static_cast(self->GetComponent(COMPONENT_TYPE_RENDER)); + auto* render = static_cast(self->GetComponent(eReplicaComponentType::RENDER)); if (render == nullptr) return; @@ -20,7 +21,7 @@ void GfCampfire::OnStartup(Entity* self) { void GfCampfire::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) { if (args == "physicsReady") { - auto* render = static_cast(self->GetComponent(COMPONENT_TYPE_RENDER)); + auto* render = static_cast(self->GetComponent(eReplicaComponentType::RENDER)); render->PlayEffect(295, u"running", "Burn"); } diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp index 2948ae3d..703c6bbd 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp @@ -14,6 +14,7 @@ #include "Loot.h" #include "InventoryComponent.h" #include "eMissionTaskType.h" +#include "eReplicaComponentType.h" void SGCannon::OnStartup(Entity* self) { Game::logger->Log("SGCannon", "OnStartup"); @@ -295,7 +296,7 @@ void SGCannon::OnActivityTimerDone(Entity* self, const std::string& name) { if (true) { auto* movementAI = new MovementAIComponent(enemy, {}); - enemy->AddComponent(COMPONENT_TYPE_MOVEMENT_AI, movementAI); + enemy->AddComponent(eReplicaComponentType::MOVEMENT_AI, movementAI); movementAI->SetSpeed(toSpawn.initialSpeed); movementAI->SetCurrentSpeed(toSpawn.initialSpeed); diff --git a/dScripts/ai/NP/NpcNpSpacemanBob.cpp b/dScripts/ai/NP/NpcNpSpacemanBob.cpp index d242d08f..2195f4b4 100644 --- a/dScripts/ai/NP/NpcNpSpacemanBob.cpp +++ b/dScripts/ai/NP/NpcNpSpacemanBob.cpp @@ -2,12 +2,13 @@ #include "DestroyableComponent.h" #include "MissionComponent.h" #include "eMissionState.h" +#include "eReplicaComponentType.h" void NpcNpSpacemanBob::OnMissionDialogueOK(Entity* self, Entity* target, int missionID, eMissionState missionState) { if (missionState == eMissionState::READY_TO_COMPLETE && missionID == 173) { - DestroyableComponent* destroyable = static_cast(target->GetComponent(COMPONENT_TYPE_DESTROYABLE)); + DestroyableComponent* destroyable = static_cast(target->GetComponent(eReplicaComponentType::DESTROYABLE)); destroyable->SetImagination(6); - MissionComponent* mission = static_cast(target->GetComponent(COMPONENT_TYPE_MISSION)); + MissionComponent* mission = static_cast(target->GetComponent(eReplicaComponentType::MISSION)); mission->CompleteMission(664); } diff --git a/dScripts/ai/NS/NsGetFactionMissionServer.cpp b/dScripts/ai/NS/NsGetFactionMissionServer.cpp index d759e3ad..cfecb249 100644 --- a/dScripts/ai/NS/NsGetFactionMissionServer.cpp +++ b/dScripts/ai/NS/NsGetFactionMissionServer.cpp @@ -2,6 +2,7 @@ #include "GameMessages.h" #include "MissionComponent.h" #include "Character.h" +#include "eReplicaComponentType.h" void NsGetFactionMissionServer::OnRespondToMission(Entity* self, int missionID, Entity* player, int reward) { if (missionID != 474) return; @@ -44,7 +45,7 @@ void NsGetFactionMissionServer::OnRespondToMission(Entity* self, int missionID, player->GetCharacter()->SetPlayerFlag(flagID, true); } - MissionComponent* mis = static_cast(player->GetComponent(COMPONENT_TYPE_MISSION)); + MissionComponent* mis = static_cast(player->GetComponent(eReplicaComponentType::MISSION)); for (int mission : factionMissions) { mis->AcceptMission(mission); diff --git a/dScripts/ai/NS/NsModularBuild.cpp b/dScripts/ai/NS/NsModularBuild.cpp index 2e00aa19..1922eb17 100644 --- a/dScripts/ai/NS/NsModularBuild.cpp +++ b/dScripts/ai/NS/NsModularBuild.cpp @@ -1,10 +1,11 @@ #include "NsModularBuild.h" #include "MissionComponent.h" #include "eMissionState.h" +#include "eReplicaComponentType.h" void NsModularBuild::OnModularBuildExit(Entity* self, Entity* player, bool bCompleted, std::vector modules) { if (bCompleted) { - MissionComponent* mission = static_cast(player->GetComponent(COMPONENT_TYPE_MISSION)); + MissionComponent* mission = static_cast(player->GetComponent(eReplicaComponentType::MISSION)); if (mission->GetMissionState(m_MissionNum) == eMissionState::ACTIVE) { for (LOT mod : modules) { diff --git a/dScripts/ai/SPEC/SpecialImaginePowerupSpawner.cpp b/dScripts/ai/SPEC/SpecialImaginePowerupSpawner.cpp index c6cab294..43ae9e89 100644 --- a/dScripts/ai/SPEC/SpecialImaginePowerupSpawner.cpp +++ b/dScripts/ai/SPEC/SpecialImaginePowerupSpawner.cpp @@ -4,6 +4,7 @@ #include "SkillComponent.h" #include "DestroyableComponent.h" #include "EntityManager.h" +#include "eReplicaComponentType.h" void SpecialImaginePowerupSpawner::OnStartup(Entity* self) { self->SetProximityRadius(1.5f, "powerupEnter"); @@ -26,7 +27,7 @@ void SpecialImaginePowerupSpawner::OnProximityUpdate(Entity* self, Entity* enter GameMessages::SendPlayFXEffect(self, -1, u"pickup", "", LWOOBJID_EMPTY, 1, 1, true); SkillComponent* skillComponent; - if (!self->TryGetComponent(COMPONENT_TYPE_SKILL, skillComponent)) { + if (!self->TryGetComponent(eReplicaComponentType::SKILL, skillComponent)) { return; } @@ -35,7 +36,7 @@ void SpecialImaginePowerupSpawner::OnProximityUpdate(Entity* self, Entity* enter skillComponent->CalculateBehavior(13, 20, source); DestroyableComponent* destroyableComponent; - if (!self->TryGetComponent(COMPONENT_TYPE_DESTROYABLE, destroyableComponent)) { + if (!self->TryGetComponent(eReplicaComponentType::DESTROYABLE, destroyableComponent)) { return; } diff --git a/dWorldServer/WorldServer.cpp b/dWorldServer/WorldServer.cpp index b655bef3..8a603878 100644 --- a/dWorldServer/WorldServer.cpp +++ b/dWorldServer/WorldServer.cpp @@ -63,6 +63,7 @@ #include "eBlueprintSaveResponseType.h" #include "AMFFormat.h" #include "NiPoint3.h" +#include "eServerDisconnectIdentifiers.h" #include "ZCompression.h" @@ -167,7 +168,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - CDClientManager::Instance()->Initialize(); + CDClientManager::Instance(); //Connect to the MySQL Database std::string mysql_host = Game::config->GetValue("mysql_host"); @@ -765,7 +766,7 @@ void HandlePacket(Packet* packet) { //Verify it: if (userHash != it->second.hash) { Game::logger->Log("WorldServer", "SOMEONE IS TRYING TO HACK? SESSION KEY MISMATCH: ours: %s != master: %s", userHash.c_str(), it->second.hash.c_str()); - Game::server->Disconnect(it->second.sysAddr, SERVER_DISCON_INVALID_SESSION_KEY); + Game::server->Disconnect(it->second.sysAddr, eServerDisconnectIdentifiers::INVALID_SESSION_KEY); return; } else { Game::logger->Log("WorldServer", "User %s authenticated with correct key.", username.c_str()); @@ -855,7 +856,7 @@ void HandlePacket(Packet* packet) { //Check the key: if (sessionKey != std::atoi(user->GetSessionKey().c_str())) { Game::logger->Log("WorldServer", "Got new session alert for user %s, but the session key is invalid.", username.c_str()); - Game::server->Disconnect(user->GetSystemAddress(), SERVER_DISCON_INVALID_SESSION_KEY); + Game::server->Disconnect(user->GetSystemAddress(), eServerDisconnectIdentifiers::INVALID_SESSION_KEY); return; } break; @@ -896,7 +897,7 @@ void HandlePacket(Packet* packet) { // Developers may skip this check if (gmLevel < 8 && clientDatabaseChecksum != databaseChecksum) { Game::logger->Log("WorldServer", "Client's database checksum does not match the server's, aborting connection."); - Game::server->Disconnect(packet->systemAddress, SERVER_DISCON_KICK); + Game::server->Disconnect(packet->systemAddress, eServerDisconnectIdentifiers::WRONG_GAME_VERSION); return; } } @@ -1184,7 +1185,7 @@ void HandlePacket(Packet* packet) { } } else { Game::logger->Log("WorldServer", "Couldn't find character to log in with for user %s (%i)!", user->GetUsername().c_str(), user->GetAccountID()); - Game::server->Disconnect(packet->systemAddress, SERVER_DISCON_CHARACTER_NOT_FOUND); + Game::server->Disconnect(packet->systemAddress, eServerDisconnectIdentifiers::CHARACTER_NOT_FOUND); } } else { Game::logger->Log("WorldServer", "Couldn't get user for level load complete!"); @@ -1269,7 +1270,7 @@ void HandlePacket(Packet* packet) { if (user) { user->UserOutOfSync(); } else { - Game::server->Disconnect(packet->systemAddress, SERVER_DISCON_KICK); + Game::server->Disconnect(packet->systemAddress, eServerDisconnectIdentifiers::KICK); } break; } @@ -1309,7 +1310,7 @@ void WorldShutdownProcess(uint32_t zoneId) { while (Game::server->GetReplicaManager()->GetParticipantCount() > 0) { const auto& player = Game::server->GetReplicaManager()->GetParticipantAtIndex(0); - Game::server->Disconnect(player, SERVER_DISCON_KICK); + Game::server->Disconnect(player, eServerDisconnectIdentifiers::SERVER_SHUTDOWN); } SendShutdownMessageToMaster(); } diff --git a/dZoneManager/Level.cpp b/dZoneManager/Level.cpp index dd38d208..55790592 100644 --- a/dZoneManager/Level.cpp +++ b/dZoneManager/Level.cpp @@ -162,7 +162,7 @@ void Level::ReadSceneObjectDataChunk(std::istream& file, Header& header) { uint32_t objectsCount = 0; BinaryIO::BinaryRead(file, objectsCount); - CDFeatureGatingTable* featureGatingTable = CDClientManager::Instance()->GetTable("FeatureGating"); + CDFeatureGatingTable* featureGatingTable = CDClientManager::Instance().GetTable(); for (uint32_t i = 0; i < objectsCount; ++i) { SceneObject obj; diff --git a/dZoneManager/Zone.cpp b/dZoneManager/Zone.cpp index c32f8447..28d3f0c8 100644 --- a/dZoneManager/Zone.cpp +++ b/dZoneManager/Zone.cpp @@ -164,7 +164,7 @@ void Zone::LoadZoneIntoMemory() { std::string Zone::GetFilePathForZoneID() { //We're gonna go ahead and presume we've got the db loaded already: - CDZoneTableTable* zoneTable = CDClientManager::Instance()->GetTable("ZoneTable"); + CDZoneTableTable* zoneTable = CDClientManager::Instance().GetTable(); const CDZoneTable* zone = zoneTable->Query(this->GetZoneID().GetMapID()); if (zone != nullptr) { std::string toReturn = "maps/" + zone->zoneName; diff --git a/dZoneManager/dZoneManager.cpp b/dZoneManager/dZoneManager.cpp index 0b7844a3..52008b5d 100644 --- a/dZoneManager/dZoneManager.cpp +++ b/dZoneManager/dZoneManager.cpp @@ -9,6 +9,7 @@ #include "GameMessages.h" #include "VanityUtilities.h" #include "WorldConfig.h" +#include "CDZoneTableTable.h" #include #include "../dWorldServer/ObjectIDManager.h" @@ -27,7 +28,7 @@ void dZoneManager::Initialize(const LWOZONEID& zoneID) { LOT zoneControlTemplate = 2365; - CDZoneTableTable* zoneTable = CDClientManager::Instance()->GetTable("ZoneTable"); + CDZoneTableTable* zoneTable = CDClientManager::Instance().GetTable(); if (zoneTable != nullptr) { const CDZoneTable* zone = zoneTable->Query(zoneID.GetMapID()); diff --git a/docs/Commands.md b/docs/Commands.md index 7dc11ff1..a9cd3e7c 100644 --- a/docs/Commands.md +++ b/docs/Commands.md @@ -92,7 +92,7 @@ These commands are primarily for development and testing. The usage of many of t |setcontrolscheme|`/setcontrolscheme `|Sets the character control scheme to the specified number.|8| |setcurrency|`/setcurrency `|Sets your coins.|8| |setflag|`/setflag (value) `|Sets the given inventory or health flag to the given value, where value can be one of "on" or "off". If no value is given, by default this adds the flag to your character (equivalent of calling `/setflag on `).|8| -|setinventorysize|`/setinventorysize `|Sets your inventory size to the given size. Alias: `/setinvsize`|8| +|setinventorysize|`/setinventorysize (inventory)`|Sets your inventory size to the given size. If `inventory` is provided, the number or string will be used to set that inventory to the requested size. Alias: `/setinvsize`|8| |setuistate|`/setuistate `|Changes UI state.|8| |spawn|`/spawn `|Spawns an object at your location by id.|8| |speedboost|`/speedboost `|Sets the speed multiplier to the given amount. `/speedboost 1.5` will set the speed multiplier to 1.5x the normal speed.|8| diff --git a/migrations/dlu/8_foreign_play_key.sql b/migrations/dlu/8_foreign_play_key.sql new file mode 100644 index 00000000..6f171bb5 --- /dev/null +++ b/migrations/dlu/8_foreign_play_key.sql @@ -0,0 +1 @@ +ALTER TABLE accounts MODIFY play_key_id INT DEFAULT NULL; diff --git a/tests/dCommonTests/AMFDeserializeTests.cpp b/tests/dCommonTests/AMFDeserializeTests.cpp index a823b0dc..3811a706 100644 --- a/tests/dCommonTests/AMFDeserializeTests.cpp +++ b/tests/dCommonTests/AMFDeserializeTests.cpp @@ -258,9 +258,9 @@ TEST(dCommonTests, AMFDeserializeLivePacketTest) { ASSERT_EQ(actionIndex->GetDoubleValue(), 0.0f); - auto stripIDExecution = stripsPosition0->FindValue("id"); + auto stripIdExecution = stripsPosition0->FindValue("id"); - ASSERT_EQ(stripIDExecution->GetDoubleValue(), 0.0f); + ASSERT_EQ(stripIdExecution->GetDoubleValue(), 0.0f); auto stateIDExecution = executionState->FindValue("stateID"); @@ -298,9 +298,9 @@ TEST(dCommonTests, AMFDeserializeLivePacketTest) { ASSERT_EQ(xPos->GetDoubleValue(), 103.0f); ASSERT_EQ(yPos->GetDoubleValue(), 82.0f); - auto stripID = firstStrip->FindValue("id"); + auto stripId = firstStrip->FindValue("id"); - ASSERT_EQ(stripID->GetDoubleValue(), 0.0f); + ASSERT_EQ(stripId->GetDoubleValue(), 0.0f); auto firstAction = dynamic_cast(actionsInFirstStrip[0]); diff --git a/tests/dGameTests/CMakeLists.txt b/tests/dGameTests/CMakeLists.txt index ba7d4d1c..b1fdaa07 100644 --- a/tests/dGameTests/CMakeLists.txt +++ b/tests/dGameTests/CMakeLists.txt @@ -8,6 +8,8 @@ list(APPEND DGAMETEST_SOURCES ${DCOMPONENTS_TESTS}) add_subdirectory(dGameMessagesTests) list(APPEND DGAMETEST_SOURCES ${DGAMEMESSAGES_TESTS}) +file(COPY ${GAMEMESSAGE_TESTBITSTREAMS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + # Add the executable. Remember to add all tests above this! add_executable(dGameTests ${DGAMETEST_SOURCES}) diff --git a/tests/dGameTests/dComponentsTests/DestroyableComponentTests.cpp b/tests/dGameTests/dComponentsTests/DestroyableComponentTests.cpp index 5448a4c2..7399456d 100644 --- a/tests/dGameTests/dComponentsTests/DestroyableComponentTests.cpp +++ b/tests/dGameTests/dComponentsTests/DestroyableComponentTests.cpp @@ -4,6 +4,7 @@ #include "BitStream.h" #include "DestroyableComponent.h" #include "Entity.h" +#include "eReplicaComponentType.h" class DestroyableTest : public GameDependenciesTest { protected: @@ -15,7 +16,7 @@ protected: SetUpDependencies(); baseEntity = new Entity(15, GameDependenciesTest::info); destroyableComponent = new DestroyableComponent(baseEntity); - baseEntity->AddComponent(COMPONENT_TYPE_DESTROYABLE, destroyableComponent); + baseEntity->AddComponent(eReplicaComponentType::DESTROYABLE, destroyableComponent); // Initialize some values to be not default destroyableComponent->SetMaxHealth(12345.0f); destroyableComponent->SetHealth(23); @@ -317,7 +318,7 @@ TEST_F(DestroyableTest, DestroyableComponentFactionTest) { TEST_F(DestroyableTest, DestroyableComponentValiditiyTest) { auto* enemyEntity = new Entity(19, info); auto* enemyDestroyableComponent = new DestroyableComponent(enemyEntity); - enemyEntity->AddComponent(COMPONENT_TYPE_DESTROYABLE, enemyDestroyableComponent); + enemyEntity->AddComponent(eReplicaComponentType::DESTROYABLE, enemyDestroyableComponent); enemyDestroyableComponent->AddFactionNoLookup(16); destroyableComponent->AddEnemyFaction(16); EXPECT_TRUE(destroyableComponent->IsEnemy(enemyEntity)); diff --git a/tests/dGameTests/dGameMessagesTests/CMakeLists.txt b/tests/dGameTests/dGameMessagesTests/CMakeLists.txt index 2417d29c..54c43777 100644 --- a/tests/dGameTests/dGameMessagesTests/CMakeLists.txt +++ b/tests/dGameTests/dGameMessagesTests/CMakeLists.txt @@ -5,5 +5,10 @@ SET(DGAMEMESSAGES_TESTS get_filename_component(thisFolderName ${CMAKE_CURRENT_SOURCE_DIR} NAME) list(TRANSFORM DGAMEMESSAGES_TESTS PREPEND "${thisFolderName}/") +# Copy test files to testing directory +add_subdirectory(TestBitStreams) +list(TRANSFORM GAMEMESSAGE_TESTBITSTREAMS PREPEND "${thisFolderName}/") +set(GAMEMESSAGE_TESTBITSTREAMS ${GAMEMESSAGE_TESTBITSTREAMS} PARENT_SCOPE) + # Export to parent scope set(DGAMEMESSAGES_TESTS ${DGAMEMESSAGES_TESTS} PARENT_SCOPE) diff --git a/tests/dGameTests/dGameMessagesTests/GameMessageTests.cpp b/tests/dGameTests/dGameMessagesTests/GameMessageTests.cpp index 3d8b2d04..631f0d2d 100644 --- a/tests/dGameTests/dGameMessagesTests/GameMessageTests.cpp +++ b/tests/dGameTests/dGameMessagesTests/GameMessageTests.cpp @@ -1,15 +1,49 @@ +#include "Action.h" +#include "AMFFormat.h" +#include "AMFDeserialize.h" #include "GameMessages.h" #include "GameDependencies.h" + #include -class GameMessageTests : public GameDependenciesTest { - protected: - void SetUp() override { - SetUpDependencies(); - } - void TearDown() override { - TearDownDependencies(); +// Message includes +#include "AddActionMessage.h" +#include "AddStripMessage.h" +#include "AddMessage.h" +#include "MigrateActionsMessage.h" +#include "MoveToInventoryMessage.h" +#include "MergeStripsMessage.h" +#include "RearrangeStripMessage.h" +#include "RemoveActionsMessage.h" +#include "RemoveStripMessage.h" +#include "RenameMessage.h" +#include "SplitStripMessage.h" +#include "UpdateActionMessage.h" +#include "UpdateStripUiMessage.h" + +class GameMessageTests: public GameDependenciesTest { +protected: + void SetUp() override { + SetUpDependencies(); + } + void TearDown() override { + TearDownDependencies(); + } + std::string ReadFromFile(std::string filename) { + std::ifstream file(filename, std::ios::binary); + std::string readFile; + while (file.good()) { + char readCharacter = file.get(); + readFile.push_back(readCharacter); } + return readFile; + } + AMFArrayValue* ReadArrayFromBitStream(RakNet::BitStream* inStream) { + AMFDeserialize des; + AMFValue* readArray = des.Read(inStream); + EXPECT_EQ(readArray->GetValueType(), AMFValueType::AMFArray); + return static_cast(readArray); + } }; /** @@ -50,3 +84,143 @@ TEST_F(GameMessageTests, SendBlueprintLoadItemResponse) { ASSERT_EQ(bitStream->GetNumberOfUnreadBits(), 0); } + +TEST_F(GameMessageTests, ControlBehaviorAddStrip) { + auto data = ReadFromFile("addStrip"); + RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); + AddStripMessage addStrip(ReadArrayFromBitStream(&inStream)); + ASSERT_FLOAT_EQ(addStrip.GetPosition().GetX(), 50.65); + ASSERT_FLOAT_EQ(addStrip.GetPosition().GetY(), 178.05); + ASSERT_EQ(addStrip.GetActionContext().GetStripId(), 0); + ASSERT_EQ(static_cast(addStrip.GetActionContext().GetStateId()), 0); + ASSERT_EQ(addStrip.GetBehaviorId(), -1); + ASSERT_EQ(addStrip.GetActionsToAdd().front().GetType(), "DropImagination"); + ASSERT_EQ(addStrip.GetActionsToAdd().front().GetValueParameterName(), "Amount"); + ASSERT_EQ(addStrip.GetActionsToAdd().front().GetValueParameterString(), ""); + ASSERT_FLOAT_EQ(addStrip.GetActionsToAdd().front().GetValueParameterDouble(), 1.0); +} + +TEST_F(GameMessageTests, ControlBehaviorRemoveStrip) { + auto data = ReadFromFile("removeStrip"); + RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); + RemoveStripMessage removeStrip(ReadArrayFromBitStream(&inStream)); + ASSERT_EQ(static_cast(removeStrip.GetActionContext().GetStripId()), 1); + ASSERT_EQ(static_cast(removeStrip.GetActionContext().GetStateId()), 0); + ASSERT_EQ(removeStrip.GetBehaviorId(), -1); +} + +TEST_F(GameMessageTests, ControlBehaviorMergeStrips) { + auto data = ReadFromFile("mergeStrips"); + RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); + MergeStripsMessage mergeStrips(ReadArrayFromBitStream(&inStream)); + ASSERT_EQ(mergeStrips.GetSourceActionContext().GetStripId(), 2); + ASSERT_EQ(mergeStrips.GetDestinationActionContext().GetStripId(), 0); + ASSERT_EQ(static_cast(mergeStrips.GetSourceActionContext().GetStateId()), 0); + ASSERT_EQ(static_cast(mergeStrips.GetDestinationActionContext().GetStateId()), 0); + ASSERT_EQ(mergeStrips.GetDstActionIndex(), 0); + ASSERT_EQ(mergeStrips.GetBehaviorId(), -1); +} + +TEST_F(GameMessageTests, ControlBehaviorSplitStrip) { + auto data = ReadFromFile("splitStrip"); + RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); + SplitStripMessage splitStrip(ReadArrayFromBitStream(&inStream)); + ASSERT_EQ(splitStrip.GetBehaviorId(), -1); + + ASSERT_FLOAT_EQ(splitStrip.GetPosition().GetX(), 275.65); + ASSERT_FLOAT_EQ(splitStrip.GetPosition().GetY(), 28.7); + ASSERT_EQ(splitStrip.GetSourceActionContext().GetStripId(), 0); + ASSERT_EQ(splitStrip.GetDestinationActionContext().GetStripId(), 2); + ASSERT_EQ(static_cast(splitStrip.GetSourceActionContext().GetStateId()), 0); + ASSERT_EQ(static_cast(splitStrip.GetDestinationActionContext().GetStateId()), 0); + ASSERT_EQ(splitStrip.GetSrcActionIndex(), 1); +} + +TEST_F(GameMessageTests, ControlBehaviorUpdateStripUI) { + auto data = ReadFromFile("updateStripUI"); + RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); + UpdateStripUiMessage updateStripUi(ReadArrayFromBitStream(&inStream)); + ASSERT_FLOAT_EQ(updateStripUi.GetPosition().GetX(), 116.65); + ASSERT_FLOAT_EQ(updateStripUi.GetPosition().GetY(), 35.35); + ASSERT_EQ(updateStripUi.GetActionContext().GetStripId(), 0); + ASSERT_EQ(static_cast(updateStripUi.GetActionContext().GetStateId()), 0); + ASSERT_EQ(updateStripUi.GetBehaviorId(), -1); +} + +TEST_F(GameMessageTests, ControlBehaviorAddAction) { + auto data = ReadFromFile("addAction"); + RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); + AddActionMessage addAction(ReadArrayFromBitStream(&inStream)); + ASSERT_EQ(addAction.GetActionIndex(), 3); + ASSERT_EQ(addAction.GetActionContext().GetStripId(), 0); + ASSERT_EQ(static_cast(addAction.GetActionContext().GetStateId()), 0); + ASSERT_EQ(addAction.GetAction().GetType(), "DoDamage"); + ASSERT_EQ(addAction.GetAction().GetValueParameterName(), ""); + ASSERT_EQ(addAction.GetAction().GetValueParameterString(), ""); + ASSERT_EQ(addAction.GetAction().GetValueParameterDouble(), 0.0); + ASSERT_EQ(addAction.GetBehaviorId(), -1); +} + +TEST_F(GameMessageTests, ControlBehaviorMigrateActions) { + auto data = ReadFromFile("migrateActions"); + RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); + MigrateActionsMessage migrateActions(ReadArrayFromBitStream(&inStream)); + ASSERT_EQ(migrateActions.GetSrcActionIndex(), 1); + ASSERT_EQ(migrateActions.GetDstActionIndex(), 2); + ASSERT_EQ(migrateActions.GetSourceActionContext().GetStripId(), 1); + ASSERT_EQ(migrateActions.GetDestinationActionContext().GetStripId(), 0); + ASSERT_EQ(static_cast(migrateActions.GetSourceActionContext().GetStateId()), 0); + ASSERT_EQ(static_cast(migrateActions.GetDestinationActionContext().GetStateId()), 0); + ASSERT_EQ(migrateActions.GetBehaviorId(), -1); +} + +TEST_F(GameMessageTests, ControlBehaviorRearrangeStrip) { + auto data = ReadFromFile("rearrangeStrip"); + RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); + RearrangeStripMessage rearrangeStrip(ReadArrayFromBitStream(&inStream)); + ASSERT_EQ(rearrangeStrip.GetSrcActionIndex(), 2); + ASSERT_EQ(rearrangeStrip.GetDstActionIndex(), 1); + ASSERT_EQ(rearrangeStrip.GetActionContext().GetStripId(), 0); + ASSERT_EQ(rearrangeStrip.GetBehaviorId(), -1); + ASSERT_EQ(static_cast(rearrangeStrip.GetActionContext().GetStateId()), 0); +} + +TEST_F(GameMessageTests, ControlBehaviorAdd) { + auto data = ReadFromFile("add"); + RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); + AddMessage add(ReadArrayFromBitStream(&inStream)); + ASSERT_EQ(add.GetBehaviorId(), 10446); + ASSERT_EQ(add.GetBehaviorIndex(), 0); +} + +TEST_F(GameMessageTests, ControlBehaviorRemoveActions) { + auto data = ReadFromFile("removeActions"); + RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); + RemoveActionsMessage removeActions(ReadArrayFromBitStream(&inStream)); + ASSERT_EQ(removeActions.GetBehaviorId(), -1); + ASSERT_EQ(removeActions.GetActionIndex(), 1); + ASSERT_EQ(removeActions.GetActionContext().GetStripId(), 0); + ASSERT_EQ(static_cast(removeActions.GetActionContext().GetStateId()), 0); +} + +TEST_F(GameMessageTests, ControlBehaviorRename) { + auto data = ReadFromFile("rename"); + RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); + RenameMessage rename(ReadArrayFromBitStream(&inStream)); + ASSERT_EQ(rename.GetName(), "test"); + ASSERT_EQ(rename.GetBehaviorId(), -1); +} + +TEST_F(GameMessageTests, ControlBehaviorUpdateAction) { + auto data = ReadFromFile("updateAction"); + RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); + UpdateActionMessage updateAction(ReadArrayFromBitStream(&inStream)); + ASSERT_EQ(updateAction.GetAction().GetType(), "FlyDown"); + ASSERT_EQ(updateAction.GetAction().GetValueParameterName(), "Distance"); + ASSERT_EQ(updateAction.GetAction().GetValueParameterString(), ""); + ASSERT_EQ(updateAction.GetAction().GetValueParameterDouble(), 50.0); + ASSERT_EQ(updateAction.GetBehaviorId(), -1); + ASSERT_EQ(updateAction.GetActionIndex(), 1); + ASSERT_EQ(updateAction.GetActionContext().GetStripId(), 0); + ASSERT_EQ(static_cast(updateAction.GetActionContext().GetStateId()), 0); +} diff --git a/tests/dGameTests/dGameMessagesTests/TestBitStreams/CMakeLists.txt b/tests/dGameTests/dGameMessagesTests/TestBitStreams/CMakeLists.txt new file mode 100644 index 00000000..e32ed3ef --- /dev/null +++ b/tests/dGameTests/dGameMessagesTests/TestBitStreams/CMakeLists.txt @@ -0,0 +1,24 @@ +set(GAMEMESSAGE_TESTBITSTREAMS +"sendBehaviorListToClient" +"modelTypeChanged" +"toggleExecutionUpdates" +"addStrip" +"removeStrip" +"mergeStrips" +"splitStrip" +"updateStripUI" +"addAction" +"migrateActions" +"rearrangeStrip" +"add" +"removeActions" +"rename" +"updateAction" +) + +# Get the folder name and prepend it to the files above +get_filename_component(thisFolderName ${CMAKE_CURRENT_SOURCE_DIR} NAME) +list(TRANSFORM GAMEMESSAGE_TESTBITSTREAMS PREPEND "${thisFolderName}/") + +# Export our list of files +set(GAMEMESSAGE_TESTBITSTREAMS ${GAMEMESSAGE_TESTBITSTREAMS} PARENT_SCOPE) diff --git a/tests/dGameTests/dGameMessagesTests/TestBitStreams/add b/tests/dGameTests/dGameMessagesTests/TestBitStreams/add new file mode 100644 index 00000000..13c0dd92 Binary files /dev/null and b/tests/dGameTests/dGameMessagesTests/TestBitStreams/add differ diff --git a/tests/dGameTests/dGameMessagesTests/TestBitStreams/addAction b/tests/dGameTests/dGameMessagesTests/TestBitStreams/addAction new file mode 100644 index 00000000..d91d0ee4 Binary files /dev/null and b/tests/dGameTests/dGameMessagesTests/TestBitStreams/addAction differ diff --git a/tests/dGameTests/dGameMessagesTests/TestBitStreams/addStrip b/tests/dGameTests/dGameMessagesTests/TestBitStreams/addStrip new file mode 100644 index 00000000..60ba6521 Binary files /dev/null and b/tests/dGameTests/dGameMessagesTests/TestBitStreams/addStrip differ diff --git a/tests/dGameTests/dGameMessagesTests/TestBitStreams/mergeStrips b/tests/dGameTests/dGameMessagesTests/TestBitStreams/mergeStrips new file mode 100644 index 00000000..062fd10b Binary files /dev/null and b/tests/dGameTests/dGameMessagesTests/TestBitStreams/mergeStrips differ diff --git a/tests/dGameTests/dGameMessagesTests/TestBitStreams/migrateActions b/tests/dGameTests/dGameMessagesTests/TestBitStreams/migrateActions new file mode 100644 index 00000000..217f44d9 Binary files /dev/null and b/tests/dGameTests/dGameMessagesTests/TestBitStreams/migrateActions differ diff --git a/tests/dGameTests/dGameMessagesTests/TestBitStreams/modelTypeChanged b/tests/dGameTests/dGameMessagesTests/TestBitStreams/modelTypeChanged new file mode 100644 index 00000000..ef282ce2 Binary files /dev/null and b/tests/dGameTests/dGameMessagesTests/TestBitStreams/modelTypeChanged differ diff --git a/tests/dGameTests/dGameMessagesTests/TestBitStreams/rearrangeStrip b/tests/dGameTests/dGameMessagesTests/TestBitStreams/rearrangeStrip new file mode 100644 index 00000000..06dda90b Binary files /dev/null and b/tests/dGameTests/dGameMessagesTests/TestBitStreams/rearrangeStrip differ diff --git a/tests/dGameTests/dGameMessagesTests/TestBitStreams/removeActions b/tests/dGameTests/dGameMessagesTests/TestBitStreams/removeActions new file mode 100644 index 00000000..56e158e5 Binary files /dev/null and b/tests/dGameTests/dGameMessagesTests/TestBitStreams/removeActions differ diff --git a/tests/dGameTests/dGameMessagesTests/TestBitStreams/removeStrip b/tests/dGameTests/dGameMessagesTests/TestBitStreams/removeStrip new file mode 100644 index 00000000..46ca0640 Binary files /dev/null and b/tests/dGameTests/dGameMessagesTests/TestBitStreams/removeStrip differ diff --git a/tests/dGameTests/dGameMessagesTests/TestBitStreams/rename b/tests/dGameTests/dGameMessagesTests/TestBitStreams/rename new file mode 100644 index 00000000..bc8827dc Binary files /dev/null and b/tests/dGameTests/dGameMessagesTests/TestBitStreams/rename differ diff --git a/tests/dGameTests/dGameMessagesTests/TestBitStreams/sendBehaviorListToClient b/tests/dGameTests/dGameMessagesTests/TestBitStreams/sendBehaviorListToClient new file mode 100644 index 00000000..fcca696d Binary files /dev/null and b/tests/dGameTests/dGameMessagesTests/TestBitStreams/sendBehaviorListToClient differ diff --git a/tests/dGameTests/dGameMessagesTests/TestBitStreams/splitStrip b/tests/dGameTests/dGameMessagesTests/TestBitStreams/splitStrip new file mode 100644 index 00000000..a23c1682 Binary files /dev/null and b/tests/dGameTests/dGameMessagesTests/TestBitStreams/splitStrip differ diff --git a/tests/dGameTests/dGameMessagesTests/TestBitStreams/toggleExecutionUpdates b/tests/dGameTests/dGameMessagesTests/TestBitStreams/toggleExecutionUpdates new file mode 100644 index 00000000..02a72181 Binary files /dev/null and b/tests/dGameTests/dGameMessagesTests/TestBitStreams/toggleExecutionUpdates differ diff --git a/tests/dGameTests/dGameMessagesTests/TestBitStreams/updateAction b/tests/dGameTests/dGameMessagesTests/TestBitStreams/updateAction new file mode 100644 index 00000000..e007d5e6 Binary files /dev/null and b/tests/dGameTests/dGameMessagesTests/TestBitStreams/updateAction differ diff --git a/tests/dGameTests/dGameMessagesTests/TestBitStreams/updateStripUI b/tests/dGameTests/dGameMessagesTests/TestBitStreams/updateStripUI new file mode 100644 index 00000000..7d0eed92 Binary files /dev/null and b/tests/dGameTests/dGameMessagesTests/TestBitStreams/updateStripUI differ