DarkflameServer/dGame/dInventory/Item.h

287 lines
6.9 KiB
C
Raw Permalink Normal View History

2022-08-06 03:01:59 +00:00
#pragma once
#include "dCommonVars.h"
#include "Inventory.h"
#include "LDFFormat.h"
#include "CDClientManager.h"
#include "Logger.h"
#include "Preconditions.h"
#include "eInventoryType.h"
#include "eLootSourceType.h"
namespace tinyxml2 {
class XMLElement;
};
/**
* An item that can be stored in an inventory and optionally consumed or equipped
* TODO: ideally this should be a component
*/
class Item final
{
public:
2022-07-28 13:39:57 +00:00
/**
* Creates an item, should be used if the item is not picked up but already exists
* @param id the object ID of the item to create
* @param lot the LOT of the item
* @param inventory the inventory to add this item to
* @param slot the slot in the inventory to add this item to
* @param count the amount of items to add to the inventory
* @param bound if the item should be bound
* @param config config data for this item, e.g. for rockets
* @param parent optional parent of this item, e.g. for proxy items
* @param subKey optional subkey for this item, e.g. for pets
*/
explicit Item(
LWOOBJID id,
LOT lot,
Inventory* inventory,
uint32_t slot,
uint32_t count,
bool bound,
const std::vector<LDFBaseData*>& config,
LWOOBJID parent,
2022-04-23 12:13:06 +00:00
LWOOBJID subKey,
eLootSourceType lootSourceType = eLootSourceType::NONE
);
2022-07-28 13:39:57 +00:00
/**
* Creates an item, should be used if the item is picked up / added to the inventory after load
* @param lot the LOT of the item
* @param inventory the inventory to add this item to
* @param slot the slot in the inventory to add this item to
* @param count the amount of items to add to the inventory
* @param config config data for this item, e.g. for rockets
* @param parent optional parent of this item, e.g. for proxy items
* @param showFlyingLoot show UI animation of the item being added
* @param isModMoveAndEquip equips the item
* @param subKey optional subkey for this item, e.g. for pets
* @param bound if the item should be bound
*/
explicit Item(
LOT lot,
Inventory* inventory,
uint32_t slot = 0,
uint32_t count = 1,
const std::vector<LDFBaseData*>& config = {},
LWOOBJID parent = LWOOBJID_EMPTY,
bool showFlyingLoot = true,
bool isModMoveAndEquip = false,
LWOOBJID subKey = LWOOBJID_EMPTY,
2022-04-23 12:13:06 +00:00
bool bound = false,
eLootSourceType lootSourceType = eLootSourceType::NONE
);
2022-07-28 13:39:57 +00:00
~Item();
2022-07-28 13:39:57 +00:00
/**
* Returns the object ID of this item
* @return the object ID of this item
*/
LWOOBJID GetId() const;
2022-07-28 13:39:57 +00:00
/**
* Returns the lot of this item
* @return the lot of this item
*/
LOT GetLot() const;
2022-07-28 13:39:57 +00:00
/**
* Sets the number of items this item represents
* @param value the number to update by
* @param silent if true, the client will not be notified of the change with GMs
* @param disassemble if items were removed, this returns all the sub parts of the item individually if it had assembly part lots
* @param showFlyingLoot shows flying loot to the client, if not silent
*/
void SetCount(uint32_t value, bool silent = false, bool disassemble = true, bool showFlyingLoot = true, eLootSourceType lootSourceType = eLootSourceType::NONE);
2022-07-28 13:39:57 +00:00
/**
* Returns the number of items this item represents (e.g. for stacks)
* @return the number of items this item represents
*/
uint32_t GetCount() const;
2022-07-28 13:39:57 +00:00
/**
* Sets the slot this item is stored in
* @param value the slot this item is stored in
*/
void SetSlot(uint32_t value);
2022-07-28 13:39:57 +00:00
/**
* Returns the slot this item is in
* @return the slot this item is in
*/
uint32_t GetSlot() const;
2022-07-28 13:39:57 +00:00
/**
* Returns current config info for this item, e.g. for rockets
* @return current config info for this item
*/
std::vector<LDFBaseData*>& GetConfig();
/**
* Returns current config info for this item, e.g. for rockets
* @return current config info for this item
*/
std::vector<LDFBaseData*> GetConfig() const;
2022-07-28 13:39:57 +00:00
/**
* Returns the database info for this item
* @return the database info for this item
*/
const CDItemComponent& GetInfo() const;
2022-07-28 13:39:57 +00:00
/**
* Sets if the item is bound
* @param value if the item is bound
*/
void SetBound(bool value);
2022-07-28 13:39:57 +00:00
/**
* Returns if the item is bound
* @return if the item is bound
*/
bool GetBound() const;
2022-07-28 13:39:57 +00:00
/**
* Sets the inventory this item belongs to
* @param value the inventory this item belongs to
*/
void SetInventory(Inventory* value);
2022-07-28 13:39:57 +00:00
/**
* Returns the inventory this item belongs to
* @return the inventory this item belongs to
*/
Inventory* GetInventory() const;
2022-07-28 13:39:57 +00:00
/**
* Returns the parent of this item, e.g. for proxy items
* @return the parent of this item
*/
LWOOBJID GetParent() const;
2022-07-28 13:39:57 +00:00
/**
* Sets the subkey for this item, e.g. for pets
* @param value the subkey for this item
*/
void SetSubKey(LWOOBJID value);
2022-07-28 13:39:57 +00:00
/**
* Returns the sub key this item has, e.g. for pets
* @return the sub key this item has
*/
LWOOBJID GetSubKey() const;
2022-07-28 13:39:57 +00:00
/**
* Returns the preconditions that must be met before this item may be used
* @return the preconditions that must be met before this item may be used
*/
PreconditionExpression* GetPreconditionExpression() const;
2022-07-28 13:39:57 +00:00
/**
* Equips this item into the linked inventory
* @param skipChecks skips equip checks for special items like rockets and cars
*/
void Equip(bool skipChecks = false);
2022-07-28 13:39:57 +00:00
/**
* Unequps the item from the linked inventory
*/
void UnEquip();
2022-07-28 13:39:57 +00:00
/**
* Returns if the item is equipped in the linked inventory
* @return if the item is equipped
*/
bool IsEquipped() const;
2022-07-28 13:39:57 +00:00
/**
* Attempts to consume one of this item, applying its skills
* @return whether the consumption was successful, e.g. the skill was cast
*/
bool Consume();
2022-07-28 13:39:57 +00:00
/**
* Uses this item if its non equip, essentially an interface for the linked GM
*/
void UseNonEquip(Item* item);
2022-07-28 13:39:57 +00:00
/**
* Disassembles the part LOTs of this item back into the inventory, if it has any
* @param inventoryType the inventory to dissassemble into
*/
void Disassemble(eInventoryType inventoryType = INVALID);
2022-07-28 13:39:57 +00:00
/**
* Disassembles this item into bricks
*/
void DisassembleModel(uint32_t numToDismantle);
2022-07-28 13:39:57 +00:00
/**
* Removes the item from the linked inventory
*/
void RemoveFromInventory();
void SaveConfigXml(tinyxml2::XMLElement& i) const;
void LoadConfigXml(const tinyxml2::XMLElement& i);
private:
2022-07-28 13:39:57 +00:00
/**
* The object ID of this item
*/
LWOOBJID id;
2022-07-28 13:39:57 +00:00
/**
* The LOT of this item
*/
LOT lot;
2022-07-28 13:39:57 +00:00
/**
* The number of items this represents
*/
uint32_t count;
2022-07-28 13:39:57 +00:00
/**
* The slot this item is stored in
*/
uint32_t slot;
2022-07-28 13:39:57 +00:00
/**
* If this item is bound
*/
bool bound;
2022-07-28 13:39:57 +00:00
/**
* A potential parent of this item, if this item is a subitem
*/
LWOOBJID parent;
2022-07-28 13:39:57 +00:00
/**
* A potential subkey of this item, e.g. for pets
*/
LWOOBJID subKey;
2022-07-28 13:39:57 +00:00
/**
* Config data for this item, e.g. for rocket parts and car parts
*/
std::vector<LDFBaseData*> config;
2022-07-28 13:39:57 +00:00
/**
* The inventory this item belongs to
*/
Inventory* inventory;
2022-07-28 13:39:57 +00:00
/**
* The database information of this item
*/
const CDItemComponent* info;
2022-07-28 13:39:57 +00:00
/**
* A precondition to using this item
*/
PreconditionExpression* preconditions = nullptr;
};