Planeshift
|
This class handles the details behind a character's inventory system. More...
#include <pscharinventory.h>
Classes | |
class | psCharacterInventoryItem |
struct | psEquipInfo |
Public Member Functions | |
bool | Add (psItem *&item, bool test=false, bool stack=true, INVENTORY_SLOT_NUMBER slot=PSCHARACTER_SLOT_NONE, gemContainer *container=NULL, bool precise=true, bool skip_requirements=false) |
Put an item into the bulk inventory, and stack if needed. | |
bool | AddLoadedItem (uint32 parentID, INVENTORY_SLOT_NUMBER slot, psItem *item) |
Places loaded items into the correct locations when loading from database. | |
bool | AddOrDrop (psItem *&item, bool stack=true) |
Add an item to the inventory, or drop if inventory is full. | |
psItem * | AddStacked (psItem *&item, int &added) |
Attempt to stack an item on an existing one if Add failed. | |
void | AddStorageItem (psItem *&item) |
Adds the passed item to the storage. | |
bool | BeginExchange () |
Copies current inventory to backup inventory. | |
void | CalculateLimits () |
Uses Mathscript formulas to determine the proper max weight and max space limits. | |
bool | CanItemAttack (INVENTORY_SLOT_NUMBER slot) |
Check to see if a particular slot can be attacked. | |
bool | CheckSlotRequirements (psItem *item, INVENTORY_SLOT_NUMBER proposedSlot, unsigned short stackCount=0) |
void | CommitExchange () |
Make sure inventory knows that an exchange is completed. | |
void | CreateGlyphList (csArray< glyphSlotInfo > &slots) |
Make an array of types of glyphs in the inventory - prefer purified. | |
void | Equip (psItem *item) |
bool | EquipItem (psItem *newItem, INVENTORY_SLOT_NUMBER slotID) |
Track what is equipped where here. | |
psCharacterInventoryItem * | FindExchangeSlotOffered (int slotID) |
INVENTORY_SLOT_NUMBER | FindFreeEquipSlot (psItem *itemToPlace) |
Return a free equipment slot which the proposed item will fit in. | |
psItem * | FindItemID (uint32 itemID, bool storage=false) |
Finds an item inside the bulk inventory or the storage. | |
size_t | FindItemStatIndex (psItemStats *itemstats, size_t startAt=1) |
Return the direct index into inventory of the defined item. | |
INVENTORY_SLOT_NUMBER | FindSlotHoldingItem (psItem *item) |
Get the equip slot of the specified item, if equipped. | |
psCharacterInventoryItem * | GetCharInventoryItem (INVENTORY_SLOT_NUMBER slot) |
size_t | GetContainedItemCount (psItem *container) |
float | GetContainedSize (psItem *container) |
float | GetContainedWeight (psItem *container) |
int | GetCurrentMaxSpace () |
int | GetCurrentTotalSpace () |
float | GetCurrentTotalWeight () |
bool | GetDoRestrictions () |
Get the status of the weight/capacity restrictions. | |
psItem * | GetEffectiveArmorInSlot (INVENTORY_SLOT_NUMBER slot) |
Gets the item in the slot. | |
psItem * | GetEffectiveWeaponInSlot (INVENTORY_SLOT_NUMBER slot, bool includeShield=false) |
Checks the equipment slot to see if it is a weapon. | |
psEquipInfo & | GetEquipmentObject (INVENTORY_SLOT_NUMBER idx) |
Acquire a reference to the equipment object inside inventory. | |
psCharacterInventoryItem * | GetIndexCharInventoryItem (size_t index) |
Returns the exchange info and the item in the index specified. | |
psInventoryCacheServer * | GetInventoryCacheServer (void) |
Get the inventory cache handler. | |
size_t | GetInventoryIndexCount () |
Return a count of items in the base inventory array. | |
psItem * | GetInventoryIndexItem (size_t which) |
Return the psItem at the inventory index specified. | |
psItem * | GetInventoryItem (INVENTORY_SLOT_NUMBER slot) |
Get an item that is in the equipment inventory. | |
uint32 | GetInventoryVersion () const |
psItem * | GetItem (psItem *container, INVENTORY_SLOT_NUMBER slot) |
Get an item that is in the bulk inventory. | |
psItem * | GetItemHeld () |
Get item held, either in right or left hand. | |
csArray< psItem * > | GetItemsInCategory (psItemCategory *category, bool storage=false) |
Iterates over the entire inventory to get a list of all the items from a particular category. | |
int | GetOfferedStackCount (psItem *item) |
float | GetTotalSizeOfItemsInContainer (psItem *container=NULL) |
bool | HasEnoughUnusedSpace (float desiredSpace) |
Check to see if the player has a required amount of carrying capacity. | |
bool | HasEnoughUnusedWeight (float requiredWeight) |
Check to see if the player has the ability to carry and additional weight. | |
bool | hasItemCategory (psItemCategory *category, bool includeEquipment, bool includeBulk, bool includeStorage=false) |
Check if the item of a certain category is in the character inventory. | |
bool | hasItemCategory (csString &categoryname, bool includeEquipment, bool includeBulk, bool includeStorage=false, int amountMin=1, int amountMax=-1, float qualityMin=0, float qualityMax=0) |
Check if the item of a certain category is in the character inventory. | |
bool | hasItemsWithName (csString &itemname, bool includeEquipment, bool includeBulk, int amountMin=1, int amountMax=-1, float qualityMin=0, float qualityMax=0) |
Check if the item of a certain name is in the character inventory. | |
bool | HasPurifiedGlyphs (const glyphList_t glyphsToCheck) |
Check if the character has a list of required purified glyphs. | |
bool | HaveKeyForLock (uint32 lock) |
Checks to see if anything in inventoy counts as the key for a lock. | |
size_t | HowManyCanFit (psItem *item) |
How may items can fit. | |
void | IncreaseInventoryVersion () |
Updates (increases) the current inventory version. | |
bool | IsItemAutoAttack (INVENTORY_SLOT_NUMBER slot) |
Query if a slot is auto attack. | |
bool | Load (PID id) |
Load the inventory using a particular ID. | |
bool | Load () |
Load the inventory for the owner. | |
float | MaxWeight () |
psCharacterInventory (psCharacter *owner) | |
void | PurgeOffered () |
bool | QuickLoad (PID id) |
Load the bare minimum to know what this character is looks like. | |
psItem * | RemoveInventoryItem (INVENTORY_SLOT_NUMBER slot, int count=-1) |
Removes an item that is in the equipment inventory. | |
psItem * | RemoveItem (psItem *container, INVENTORY_SLOT_NUMBER bulkslot, int count=-1) |
Remove an item from the bulk slots. | |
psItem * | RemoveItemID (uint32 itemID, int count=-1, bool storage=false) |
Remove an item from the bulk slots. | |
psItem * | RemoveItemIndex (size_t index, int count=-1, bool storage=false) |
The one true way to remove an item or split a stack from inventory. | |
void | RestoreAllInventoryQuality () |
Restore all items in this inventory to their max quality. | |
void | RollbackExchange () |
Cancel pending inventory exchange and rollback to original start point of inv. | |
void | RunEquipScripts () |
Iterates over the equipped items running any scripts on them. | |
void | SetBasicArmor (psRaceInfo *race=NULL) |
Sets the basic armor when not equipped depending on the passed race. | |
void | SetBasicWeapon (psRaceInfo *race=NULL) |
Sets the basic weapon when not equipped depending on the passed race. | |
void | SetDoRestrictions (bool v) |
Changes this inventories handling of weight/capacity restrictions. | |
void | SetExchangeOfferSlot (psItem *Container, INVENTORY_SLOT_NUMBER slot, int toSlot, int stackCount) |
psItem * | StackNumberItems (const csString &itemname, int count, bool container) |
Iterates over the inventory, stacking items. | |
unsigned int | TotalStackOfItem (psItemStats *item) |
Find the total stack count in inventory for a particular type of item. | |
void | Unequip (psItem *item) |
void | UpdateEncumbrance () |
Update encumbrance/OVERWEIGHT mode to match current status. | |
void | WriteAllInventory (iDocumentNode *npcRoot) |
This creates an xml tree for npcloader saving. | |
~psCharacterInventory () | |
Static Public Member Functions | |
static psItem * | GetItemFactory (psItemStats *stats) |
Allocate either a psItem or a psGlyph. | |
Public Attributes | |
csString | lastError |
Contain error messge for last function failing. | |
psCharacter * | owner |
Current owner of the inventory. | |
Protected Attributes | |
bool | doRestrictions |
Do weight/capacity restrictions? | |
psEquipInfo | equipment [PSCHARACTER_SLOT_BULK1] |
Items player is using in various slots. | |
bool | inExchangeMode |
Exchange mode flag. | |
csArray< psCharacterInventoryItem > | inventory |
Flat array of all items owned in this inventory. | |
bool | loaded |
Has this inventory been fully loaded yet? | |
float | maxSize |
Max capacity in inventory. | |
float | maxWeight |
Max weight the inventory can hold. | |
csArray< psItem * > | storageInventory |
Array with all the items stored by the character. | |
uint32 | version |
Inventory version. |
This class handles the details behind a character's inventory system.
Definition at line 81 of file pscharinventory.h.
psCharacterInventory::psCharacterInventory | ( | psCharacter * | owner | ) |
psCharacterInventory::~psCharacterInventory | ( | ) |
bool psCharacterInventory::Add | ( | psItem *& | item, |
bool | test = false , |
||
bool | stack = true , |
||
INVENTORY_SLOT_NUMBER | slot = PSCHARACTER_SLOT_NONE , |
||
gemContainer * | container = NULL , |
||
bool | precise = true , |
||
bool | skip_requirements = false |
||
) |
Put an item into the bulk inventory, and stack if needed.
item | The item we want to place into the slot. |
test | Are we just testing if we can put this into the slot |
stack | Should the item be stacked? |
slot | The slot in which we want to place an item. (may be a slot number, or PSCHARACTER_SLOT_NONE) |
container | Pointer to container. |
precise | Says whatever if the stacking should be precise and not ignore properties like quality. |
skip_requirements | If set, don't check the slot requirements in order to place the item in the slot. |
bool psCharacterInventory::AddLoadedItem | ( | uint32 | parentID, |
INVENTORY_SLOT_NUMBER | slot, | ||
psItem * | item | ||
) |
Places loaded items into the correct locations when loading from database.
parentID | The parent. |
slot | Name where item should go. |
item | The item we are placing. |
bool psCharacterInventory::AddOrDrop | ( | psItem *& | item, |
bool | stack = true |
||
) |
Add an item to the inventory, or drop if inventory is full.
Attempt to stack an item on an existing one if Add failed.
item | The item we want to place into the slot. |
added | number of items that have been taken off the stack |
void psCharacterInventory::AddStorageItem | ( | psItem *& | item | ) |
Adds the passed item to the storage.
The item will be accessible only from storage npc.
item | The item to be added to the storage. |
bool psCharacterInventory::BeginExchange | ( | ) |
Copies current inventory to backup inventory.
void psCharacterInventory::CalculateLimits | ( | ) |
Uses Mathscript formulas to determine the proper max weight and max space limits.
bool psCharacterInventory::CanItemAttack | ( | INVENTORY_SLOT_NUMBER | slot | ) |
Check to see if a particular slot can be attacked.
slot | The slot to query. |
bool psCharacterInventory::CheckSlotRequirements | ( | psItem * | item, |
INVENTORY_SLOT_NUMBER | proposedSlot, | ||
unsigned short | stackCount = 0 |
||
) |
void psCharacterInventory::CommitExchange | ( | ) |
Make sure inventory knows that an exchange is completed.
void psCharacterInventory::CreateGlyphList | ( | csArray< glyphSlotInfo > & | slots | ) |
Make an array of types of glyphs in the inventory - prefer purified.
void psCharacterInventory::Equip | ( | psItem * | item | ) |
bool psCharacterInventory::EquipItem | ( | psItem * | newItem, |
INVENTORY_SLOT_NUMBER | slotID | ||
) |
Track what is equipped where here.
The item must already be in inventory to equip, and if something is in the equip slot already, it is removed with no effect on anything else.
psCharacterInventoryItem* psCharacterInventory::FindExchangeSlotOffered | ( | int | slotID | ) |
INVENTORY_SLOT_NUMBER psCharacterInventory::FindFreeEquipSlot | ( | psItem * | itemToPlace | ) |
Return a free equipment slot which the proposed item will fit in.
psItem* psCharacterInventory::FindItemID | ( | uint32 | itemID, |
bool | storage = false |
||
) |
Finds an item inside the bulk inventory or the storage.
itemID | The UID of the item we are looking for. |
storage | TRUE if we have to look in the item storage. |
size_t psCharacterInventory::FindItemStatIndex | ( | psItemStats * | itemstats, |
size_t | startAt = 1 |
||
) |
Return the direct index into inventory of the defined item.
INVENTORY_SLOT_NUMBER psCharacterInventory::FindSlotHoldingItem | ( | psItem * | item | ) |
Get the equip slot of the specified item, if equipped.
item | The item that we want to find. |
psCharacterInventoryItem* psCharacterInventory::GetCharInventoryItem | ( | INVENTORY_SLOT_NUMBER | slot | ) |
size_t psCharacterInventory::GetContainedItemCount | ( | psItem * | container | ) |
int psCharacterInventory::GetCurrentMaxSpace | ( | ) |
int psCharacterInventory::GetCurrentTotalSpace | ( | ) |
float psCharacterInventory::GetCurrentTotalWeight | ( | ) |
bool psCharacterInventory::GetDoRestrictions | ( | ) | [inline] |
Get the status of the weight/capacity restrictions.
Definition at line 498 of file pscharinventory.h.
psItem* psCharacterInventory::GetEffectiveArmorInSlot | ( | INVENTORY_SLOT_NUMBER | slot | ) |
Gets the item in the slot.
slot | The equipment slot to checks. |
psItem* psCharacterInventory::GetEffectiveWeaponInSlot | ( | INVENTORY_SLOT_NUMBER | slot, |
bool | includeShield = false |
||
) |
Checks the equipment slot to see if it is a weapon.
An item is considered a weapon if: IsMeleeWeapon() || GetIsRangeWeapon()
slot | The equipment slot to check weapon status. |
includeShield | Tell if a shield can be returned as a weapon, useful when calculating the shield blocking like a weapon. |
psEquipInfo& psCharacterInventory::GetEquipmentObject | ( | INVENTORY_SLOT_NUMBER | idx | ) |
Acquire a reference to the equipment object inside inventory.
This function does NOT do bounds checking so idx has to be in range.
idx | The equipment slot we want the equipment structure for. |
psCharacterInventoryItem* psCharacterInventory::GetIndexCharInventoryItem | ( | size_t | index | ) | [inline] |
Returns the exchange info and the item in the index specified.
Definition at line 564 of file pscharinventory.h.
psInventoryCacheServer* psCharacterInventory::GetInventoryCacheServer | ( | void | ) | [inline] |
Get the inventory cache handler.
Definition at line 504 of file pscharinventory.h.
size_t psCharacterInventory::GetInventoryIndexCount | ( | ) | [inline] |
Return a count of items in the base inventory array.
This should be used only for debug output.
Definition at line 548 of file pscharinventory.h.
psItem* psCharacterInventory::GetInventoryIndexItem | ( | size_t | which | ) | [inline] |
Return the psItem at the inventory index specified.
This should be used only for debug output
Definition at line 558 of file pscharinventory.h.
psItem* psCharacterInventory::GetInventoryItem | ( | INVENTORY_SLOT_NUMBER | slot | ) |
Get an item that is in the equipment inventory.
slot | The slot in which we want to retrive the item ( if any ). |
uint32 psCharacterInventory::GetInventoryVersion | ( | ) | const [inline] |
Definition at line 227 of file pscharinventory.h.
psItem* psCharacterInventory::GetItem | ( | psItem * | container, |
INVENTORY_SLOT_NUMBER | slot | ||
) |
Get an item that is in the bulk inventory.
container | The container of the slot, if any. NULL if normal bulk. |
slot | The slot in which we want to retrive the item ( if any ). |
static psItem* psCharacterInventory::GetItemFactory | ( | psItemStats * | stats | ) | [static] |
psItem* psCharacterInventory::GetItemHeld | ( | ) |
Get item held, either in right or left hand.
csArray<psItem*> psCharacterInventory::GetItemsInCategory | ( | psItemCategory * | category, |
bool | storage = false |
||
) |
Iterates over the entire inventory to get a list of all the items from a particular category.
This is useful for npc merchants/storage when you want to get a list of all the items they have.
category | A pointer to the category that we want to match against. |
storage | A boolean telling if we have to look in the storage in place of the main inventory. |
bool psCharacterInventory::HasEnoughUnusedSpace | ( | float | desiredSpace | ) |
Check to see if the player has a required amount of carrying capacity.
desiredSpace | The amount of space that we want to check. |
bool psCharacterInventory::HasEnoughUnusedWeight | ( | float | requiredWeight | ) |
Check to see if the player has the ability to carry and additional weight.
requiredWeight | The amount of weight that we want to check. |
bool psCharacterInventory::hasItemCategory | ( | psItemCategory * | category, |
bool | includeEquipment, | ||
bool | includeBulk, | ||
bool | includeStorage = false |
||
) |
Check if the item of a certain category is in the character inventory.
category | pointer to the psItemCategory structure to search for. |
includeEquipment | include equipment in the search. |
includeBulk | include bulk in the search. |
includeStorage | include storage in the search. |
bool psCharacterInventory::hasItemCategory | ( | csString & | categoryname, |
bool | includeEquipment, | ||
bool | includeBulk, | ||
bool | includeStorage = false , |
||
int | amountMin = 1 , |
||
int | amountMax = -1 , |
||
float | qualityMin = 0 , |
||
float | qualityMax = 0 |
||
) |
Check if the item of a certain category is in the character inventory.
categoryname | The name of the category of item to search for. |
includeEquipment | include equipment in the search. |
includeBulk | searches for the item only in the equipment if true. |
includeStorage | include storage in the search. |
amountMin | The minimum amount of this item that the inventory must have, 1 is default. |
amountMax | The maximum amount of this item that the inventory can have, -1 to ignore. |
qualityMin | The minimum quality the item must have, 0 to ignore. |
qualityMax | The maximum quality the item must have, 0 to ignore. |
bool psCharacterInventory::hasItemsWithName | ( | csString & | itemname, |
bool | includeEquipment, | ||
bool | includeBulk, | ||
int | amountMin = 1 , |
||
int | amountMax = -1 , |
||
float | qualityMin = 0 , |
||
float | qualityMax = 0 |
||
) |
Check if the item of a certain name is in the character inventory.
itemname | The name of the item to search for. |
includeEquipment | include equipment in the search. |
includeBulk | include bulk in the search. |
amountMin | The minimum amount of items that must be in the inventory |
amountMax | The maximum amount of items that can be in the inventory, -1 to ignore |
qualityMin | The minimum quality the item must have, 0 to ignore. |
qualityMax | The maximum quality the item must have, 0 to ignore. |
bool psCharacterInventory::HasPurifiedGlyphs | ( | const glyphList_t | glyphsToCheck | ) |
Check if the character has a list of required purified glyphs.
bool psCharacterInventory::HaveKeyForLock | ( | uint32 | lock | ) |
Checks to see if anything in inventoy counts as the key for a lock.
lock | The lock we want to try and open. |
size_t psCharacterInventory::HowManyCanFit | ( | psItem * | item | ) |
How may items can fit.
item | the item to check for. |
void psCharacterInventory::IncreaseInventoryVersion | ( | ) | [inline] |
Updates (increases) the current inventory version.
Definition at line 235 of file pscharinventory.h.
bool psCharacterInventory::IsItemAutoAttack | ( | INVENTORY_SLOT_NUMBER | slot | ) |
Query if a slot is auto attack.
slot | The slot to query. |
bool psCharacterInventory::Load | ( | PID | id | ) |
Load the inventory using a particular ID.
This is useful for NPCs that have their own inventory as well as a common base one they need to load.
id | The key into the character table for the character who's inventory we should load. |
bool psCharacterInventory::Load | ( | ) |
Load the inventory for the owner.
float psCharacterInventory::MaxWeight | ( | ) | [inline] |
Definition at line 208 of file pscharinventory.h.
void psCharacterInventory::PurgeOffered | ( | ) |
bool psCharacterInventory::QuickLoad | ( | PID | id | ) |
Load the bare minimum to know what this character is looks like.
psItem* psCharacterInventory::RemoveInventoryItem | ( | INVENTORY_SLOT_NUMBER | slot, |
int | count = -1 |
||
) |
Removes an item that is in the equipment inventory.
slot | The slot we want to remove the item from. |
count | The number we want to take. -1 Means the entire stack. |
psItem* psCharacterInventory::RemoveItem | ( | psItem * | container, |
INVENTORY_SLOT_NUMBER | bulkslot, | ||
int | count = -1 |
||
) |
Remove an item from the bulk slots.
container | |
bulkslot | The slot we want to remove the item from. |
count | The number we want to take. -1 Means the entire stack. |
Remove an item from the bulk slots.
itemID | The UID of the item we are looking for. |
count | The number we want to take. -1 Means the entire stack. |
storage | TRUE if we are looking in the storage. |
psItem* psCharacterInventory::RemoveItemIndex | ( | size_t | index, |
int | count = -1 , |
||
bool | storage = false |
||
) |
The one true way to remove an item or split a stack from inventory.
Other removal functions all find the index and call this.
index | The index to remove |
count | The number of items from that index to remove. |
storage | A boolean TRUE if we are removing from the storage in place of the inventory. |
void psCharacterInventory::RestoreAllInventoryQuality | ( | ) |
Restore all items in this inventory to their max quality.
This function is usually used by npc at their respawn after death.
void psCharacterInventory::RollbackExchange | ( | ) |
Cancel pending inventory exchange and rollback to original start point of inv.
void psCharacterInventory::RunEquipScripts | ( | ) |
Iterates over the equipped items running any scripts on them.
void psCharacterInventory::SetBasicArmor | ( | psRaceInfo * | race = NULL | ) |
Sets the basic armor when not equipped depending on the passed race.
race | Pointer to the race to use to set the basic armor. |
void psCharacterInventory::SetBasicWeapon | ( | psRaceInfo * | race = NULL | ) |
Sets the basic weapon when not equipped depending on the passed race.
race | Pointer to the race to use to set the basic armor. |
void psCharacterInventory::SetDoRestrictions | ( | bool | v | ) |
Changes this inventories handling of weight/capacity restrictions.
void psCharacterInventory::SetExchangeOfferSlot | ( | psItem * | Container, |
INVENTORY_SLOT_NUMBER | slot, | ||
int | toSlot, | ||
int | stackCount | ||
) |
psItem* psCharacterInventory::StackNumberItems | ( | const csString & | itemname, |
int | count, | ||
bool | container | ||
) |
Iterates over the inventory, stacking items.
itemname | Name of the item to be stacked |
count | quantity up to which items should be stacked |
container | decide whether to look into containers in the inventory |
unsigned int psCharacterInventory::TotalStackOfItem | ( | psItemStats * | item | ) |
Find the total stack count in inventory for a particular type of item.
item | The base stats of the item we want to count. |
void psCharacterInventory::Unequip | ( | psItem * | item | ) |
void psCharacterInventory::UpdateEncumbrance | ( | ) |
Update encumbrance/OVERWEIGHT mode to match current status.
void psCharacterInventory::WriteAllInventory | ( | iDocumentNode * | npcRoot | ) |
This creates an xml tree for npcloader saving.
bool psCharacterInventory::doRestrictions [protected] |
Do weight/capacity restrictions?
Definition at line 126 of file pscharinventory.h.
psEquipInfo psCharacterInventory::equipment[PSCHARACTER_SLOT_BULK1] [protected] |
Items player is using in various slots.
Definition at line 123 of file pscharinventory.h.
bool psCharacterInventory::inExchangeMode [protected] |
Exchange mode flag.
Definition at line 138 of file pscharinventory.h.
Flat array of all items owned in this inventory.
Definition at line 109 of file pscharinventory.h.
csString psCharacterInventory::lastError |
Contain error messge for last function failing.
Definition at line 492 of file pscharinventory.h.
bool psCharacterInventory::loaded [protected] |
Has this inventory been fully loaded yet?
Definition at line 129 of file pscharinventory.h.
float psCharacterInventory::maxSize [protected] |
Max capacity in inventory.
Definition at line 135 of file pscharinventory.h.
float psCharacterInventory::maxWeight [protected] |
Max weight the inventory can hold.
Definition at line 132 of file pscharinventory.h.
Current owner of the inventory.
Definition at line 85 of file pscharinventory.h.
csArray<psItem*> psCharacterInventory::storageInventory [protected] |
Array with all the items stored by the character.
Definition at line 112 of file pscharinventory.h.
uint32 psCharacterInventory::version [protected] |
Inventory version.
Definition at line 141 of file pscharinventory.h.