Class TInventoryItem
Unit
Declaration
type TInventoryItem = class(TComponent)
Description
An item that can be used, kept in the inventory, or (using PutOnWorld that wraps it in TItemOnWorld) dropped on 3D world. Thanks to the Quantity property, this may actually represent many "stacked" items, all having the same properties.
Hierarchy
- TObject
- TPersistent
- TComponent
- TInventoryItem
Overview
Methods
![]() |
procedure Stack(var Item: TInventoryItem); virtual; |
![]() |
procedure Picked(const NewOwner: TAliveWithInventory); virtual; |
![]() |
procedure Use; virtual; |
![]() |
function Split(QuantitySplit: Cardinal): TInventoryItem; |
![]() |
function PutOnWorld( const ALevel: TAbstractLevel; const APosition: TVector3): TItemOnWorld; |
Properties
![]() |
property Resource: TItemResource read FResource; |
![]() |
property Quantity: Cardinal read FQuantity write FQuantity; |
![]() |
property Owner3D: TCastleTransform read FOwner3D; |
Description
Methods
![]() |
procedure Stack(var Item: TInventoryItem); virtual; |
|
Try to sum ( Various games, and various items, may require various approaches: for example, maybe you don't want some items to You can here increase the Quantity of current item, decrease the Quantity of parameter Item. In case the parameter Item no longer exists (it's Quantity reaches 0) you have to free it and set to The default implementation of this in TInventoryItem class allows stacking always, as long as the Resource matches. This means that, by default, every TItemResource is existing at most once in TAliveWithInventory.Inventory. | |
![]() |
procedure Picked(const NewOwner: TAliveWithInventory); virtual; |
|
Item is You can override this to cause different behavior (for example, to consume some items right at pickup). Remember that this method must take care of memory management of this item. | |
![]() |
function Split(QuantitySplit: Cardinal): TInventoryItem; |
|
Splits item (with Quantity >= 2) into two items. It returns newly created object with the same properties as this object, and with Quantity set to QuantitySplit. And it lowers our Quantity by QuantitySplit. Always QuantitySplit must be >= 1 and < Quantity. | |
![]() |
function PutOnWorld( const ALevel: TAbstractLevel; const APosition: TVector3): TItemOnWorld; |
|
Create TItemOnWorld instance referencing this item, and add this to the given 3D AWorld. Although normal item knows (through Owner3D) the world it lives in, but this method may be used for items that don't have an owner yet, so we take AWorld parameter explicitly. This is how you should create new TItemOnWorld instances. It is analogous to TCreatureResource.CreateCreature, but now for items. | |
Properties
![]() |
property Resource: TItemResource read FResource; |
![]() |
property Quantity: Cardinal read FQuantity write FQuantity; |
|
Quantity of this item. This must always be >= 1. | |
![]() |
property Owner3D: TCastleTransform read FOwner3D; |
|
3D owner of the item, like a player or creature (if the item is in the backpack) or the TItemOnWorld instance (if the item is lying on the world, pickable). May be The owner is always responsible for freeing this TInventoryItem instance (in case of TItemOnWorld, it does it directly; in case of player or creature, it does it by TInventory). | |
Generated by PasDoc 0.16.0.

