InventoryComponent pass

- reduce scope usage
- bouncing returns
- std::for_each in some contexts
- extra nullptr checks
- constiness
- extra logs
- scoped enum type for eItemType
- lol serialization.
This commit is contained in:
David Markowitz 2023-06-28 01:20:41 -07:00
parent 0544eeba1f
commit 81404d9671
5 changed files with 216 additions and 383 deletions

View File

@ -60,6 +60,7 @@ const LOT LOT_ZONE_CONTROL = 2365;
const LOT LOT_3D_AMBIENT_SOUND = 6368; const LOT LOT_3D_AMBIENT_SOUND = 6368;
const LOT LOT_MODEL_IN_WORLD = 14; const LOT LOT_MODEL_IN_WORLD = 14;
const LOT LOT_THINKING_CAP = 6086; const LOT LOT_THINKING_CAP = 6086;
const LOT LOT_ROCKET = 6416;
const float PI = 3.14159f; const float PI = 3.14159f;

View File

@ -1,6 +1,8 @@
#include "CDItemComponentTable.h" #include "CDItemComponentTable.h"
#include "GeneralUtils.h" #include "GeneralUtils.h"
#include "eItemType.h"
CDItemComponent CDItemComponentTable::Default = {}; CDItemComponent CDItemComponentTable::Default = {};
//! Constructor //! Constructor
@ -98,7 +100,7 @@ const CDItemComponent& CDItemComponentTable::GetItemComponentByID(unsigned int i
entry.baseValue = tableData.getIntField("baseValue", -1); entry.baseValue = tableData.getIntField("baseValue", -1);
entry.isKitPiece = tableData.getIntField("isKitPiece", -1) == 1 ? true : false; entry.isKitPiece = tableData.getIntField("isKitPiece", -1) == 1 ? true : false;
entry.rarity = tableData.getIntField("rarity", 0); entry.rarity = tableData.getIntField("rarity", 0);
entry.itemType = tableData.getIntField("itemType", -1); entry.itemType = static_cast<eItemType>(tableData.getIntField("itemType", -1));
entry.itemInfo = tableData.getInt64Field("itemInfo", -1); entry.itemInfo = tableData.getInt64Field("itemInfo", -1);
entry.inLootTable = tableData.getIntField("inLootTable", -1) == 1 ? true : false; entry.inLootTable = tableData.getIntField("inLootTable", -1) == 1 ? true : false;
entry.inVendor = tableData.getIntField("inVendor", -1) == 1 ? true : false; entry.inVendor = tableData.getIntField("inVendor", -1) == 1 ? true : false;

View File

@ -4,13 +4,15 @@
#include "CDTable.h" #include "CDTable.h"
#include "dCommonVars.h" #include "dCommonVars.h"
enum class eItemType : int32_t;
struct CDItemComponent { struct CDItemComponent {
unsigned int id; //!< The Component ID unsigned int id; //!< The Component ID
std::string equipLocation; //!< The equip location std::string equipLocation; //!< The equip location
unsigned int baseValue; //!< The monetary base value of the item unsigned int baseValue; //!< The monetary base value of the item
bool isKitPiece; //!< Whether or not the item belongs to a kit bool isKitPiece; //!< Whether or not the item belongs to a kit
unsigned int rarity; //!< The rarity of the item unsigned int rarity; //!< The rarity of the item
unsigned int itemType; //!< The item type eItemType itemType; //!< The item type
int64_t itemInfo; //!< The item info int64_t itemInfo; //!< The item info
bool inLootTable; //!< Whether or not the item is in a loot table bool inLootTable; //!< Whether or not the item is in a loot table
bool inVendor; //!< Whether or not the item is in a vendor inventory bool inVendor; //!< Whether or not the item is in a vendor inventory

File diff suppressed because it is too large Load Diff

View File

@ -45,7 +45,7 @@ public:
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags); void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
void LoadXml(tinyxml2::XMLDocument* document); void LoadXml(tinyxml2::XMLDocument* document);
void UpdateXml(tinyxml2::XMLDocument* document) override; void UpdateXml(tinyxml2::XMLDocument* document) override;
void ResetFlags(); void ResetFlags() { m_Dirty = false; };
/** /**
* Returns an inventory of the specified type, if it exists * Returns an inventory of the specified type, if it exists
@ -58,10 +58,12 @@ public:
* Returns all the inventories this entity has, indexed by type * Returns all the inventories this entity has, indexed by type
* @return all the inventories this entity has, indexed by type * @return all the inventories this entity has, indexed by type
*/ */
const std::map<eInventoryType, Inventory*>& GetInventories() const; const std::map<eInventoryType, Inventory*>& GetInventories() const { return m_Inventories; }
/** /**
* Returns the amount of items this entity possesses of a certain LOT * Returns the amount of items this entity possesses of a certain LOT
* This method counts the lot count for all inventories, including inventories the player may not be able to see.
* If you need the count in a specific inventory, call the inventory equivalent.
* @param lot the lot to search for * @param lot the lot to search for
* @return the amount of items this entity possesses the specified LOT * @return the amount of items this entity possesses the specified LOT
*/ */
@ -79,7 +81,7 @@ public:
* Returns the items that are currently equipped by this entity * Returns the items that are currently equipped by this entity
* @return the items that are currently equipped by this entity * @return the items that are currently equipped by this entity
*/ */
const EquipmentMap& GetEquippedItems() const; const EquipmentMap& GetEquippedItems() const { return m_Equipped; }
/** /**
* Adds an item to the inventory of the entity * Adds an item to the inventory of the entity
@ -206,7 +208,7 @@ public:
* @param item the Item to unequip * @param item the Item to unequip
* @return if we were successful * @return if we were successful
*/ */
void HandlePossession(Item* item); void HandlePossession(Item* item) const;
/** /**
* Adds a buff related to equipping a lot to the entity * Adds a buff related to equipping a lot to the entity
@ -247,13 +249,13 @@ public:
* Sets the current consumable lot * Sets the current consumable lot
* @param lot the lot to set as consumable * @param lot the lot to set as consumable
*/ */
void SetConsumable(LOT lot); void SetConsumable(LOT lot) { m_Consumable = lot; };
/** /**
* Returns the current consumable lot * Returns the current consumable lot
* @return the current consumable lot * @return the current consumable lot
*/ */
LOT GetConsumable() const; LOT GetConsumable() const { return m_Consumable; }
/** /**
* Finds all the buffs related to a lot * Finds all the buffs related to a lot
@ -285,7 +287,7 @@ public:
* Triggers one of the passive abilities from the equipped item set * Triggers one of the passive abilities from the equipped item set
* @param trigger the trigger to fire * @param trigger the trigger to fire
*/ */
void TriggerPassiveAbility(PassiveAbilityTrigger trigger, Entity* target = nullptr); void TriggerPassiveAbility(PassiveAbilityTrigger trigger, Entity* target = nullptr) const;
/** /**
* Returns if the entity has any of the passed passive abilities equipped * Returns if the entity has any of the passed passive abilities equipped
@ -325,13 +327,13 @@ public:
* @param id the id of the object to check for * @param id the id of the object to check for
* @return if the provided object ID is in this inventory and is a pet * @return if the provided object ID is in this inventory and is a pet
*/ */
bool IsPet(LWOOBJID id) const; bool IsPet(const LWOOBJID& id) const { return m_Pets.find(id) != m_Pets.end(); }
/** /**
* Removes pet database information from the item with the specified object id * Removes pet database information from the item with the specified object id
* @param id the object id to remove pet info for * @param id the object id to remove pet info for
*/ */
void RemoveDatabasePet(LWOOBJID id); void RemoveDatabasePet(const LWOOBJID& id) { m_Pets.erase(id); }
/** /**
* Returns the current behavior slot active for the passed item type * Returns the current behavior slot active for the passed item type
@ -359,14 +361,14 @@ public:
* *
* @param equippedItem The item script to lookup and call equip on * @param equippedItem The item script to lookup and call equip on
*/ */
void EquipScripts(Item* equippedItem); void EquipScripts(Item* equippedItem) const;
/** /**
* Call this when you unequip an item. This calls OnFactionTriggerItemUnequipped for any scripts found on the items. * Call this when you unequip an item. This calls OnFactionTriggerItemUnequipped for any scripts found on the items.
* *
* @param unequippedItem The item script to lookup and call unequip on * @param unequippedItem The item script to lookup and call unequip on
*/ */
void UnequipScripts(Item* unequippedItem); void UnequipScripts(Item* unequippedItem) const;
~InventoryComponent() override; ~InventoryComponent() override;