Gorilla.Utils.Inventory
Unit Gorilla.Utils.Inventory.pasClasses
- TGorillaInventoryIngredientList = class ( {System.Generics.Collections}TObjectList<Gorilla.Utils.Inventory.TGorillaInventoryIngredient> )
- TGorillaInventoryLanguageMap = class ( TGorillaLanguageMap )
- TGorillaInventoryParameters = class ( {System.Generics.Collections}TDictionary<System.string,System.Rtti.TValue> )
- TGorillaInventoryLoadingCache = class ( TObject )
- TGorillaInventoryCustomItem = class ( TCollectionItem )
- TGorillaInventoryCustomCollection = class ( TOwnedCollection )
- TGorillaInventoryItem = class ( TGorillaInventoryCustomItem )
- TGorillaInventoryItemTemplate = class ( TGorillaInventoryItem )
- TGorillaInventoryCollectable = class ( TGorillaInventoryItem )
- TGorillaInventoryItemCollection = class ( TGorillaInventoryCustomCollection )
- TGorillaInventoryCollectablesCollection = class ( TGorillaInventoryItemCollection )
- TGorillaInventoryGroup = class ( TGorillaInventoryCustomItem )
- TGorillaInventoryGroupCollection = class ( TGorillaInventoryCustomCollection )
- TGorillaInventoryIngredient = class ( TObject )
- TGorillaInventoryManufacturingProcess = class ( TObject )
- TGorillaInventoryManufacturer = class ( TGorillaInventoryCustomItem )
- TGorillaInventoryManufacturerCollection = class ( TGorillaInventoryCustomCollection )
- TGorillaInventory = class ( TComponent )
Enumerations
- enum TGorillaInventoryCollectState = ( None, Allowed, Collected, QuantityExceeded, Disabled, NotFound, Missing ) ;
- enum TGorillaInventoryManufacturingState = ( Undefined, Processing, Completed, Failed ) ;
- enum TManufacturingProcessKind = ( NewItem, Upgrading, Downgrading ) ;
- enum TManufacturingNotificationType = ( mntStarted, mntPaused, mntAborted, mntCompleted, mntProcessing ) ;
Constants
TGorillaInventoryIngredientList
TGorillaInventoryLanguageMap
TGorillaInventoryParameters
TGorillaInventoryLoadingCache
InventoryLoadingCache is needed for circular loading references. f.e.: sometimes templates are not loaded yet, when they are referenced.
Ancestors
Members
Fields
- protected FInventory :
TGorillaInventory
- protected FReferences :
TLoadingCacheMap
- protected FUpgrade :
TLoadingCacheMap
- protected FDowngrade :
TLoadingCacheMap
Methods
- public constructor Create ( const AInventory : TGorillaInventory ) ;
- public destructor Destroy ( ) ;
- public procedure Resolve
(
)
;
virtual;
Resolves all open references.
Properties
TGorillaInventoryCustomItem
The custom class for all item classes.
Ancestors
Members
Fields
- protected FId :
string
- protected FName :
TGorillaInventoryLanguageMap
- protected FEnabled :
Boolean
- protected FData :
TValue
Methods
- public constructor Create ( ACollection : TCollection ) ;
- public destructor Destroy ( ) ;
- protected function GetInventory ( ) : TGorillaInventory ;
- public function GetIdentifier ( ) : string ; class abstract virtual;
- public function GetCurrentName ( ) : string ; virtual;
- public function ToXml ( const AParent : TMz_XmlElement ) : TMz_XmlElement ; virtual;
- public procedure FromXml ( const ANode : TMz_XmlElement; const ACache : TGorillaInventoryLoadingCache ) ; virtual;
Properties
TGorillaInventoryCustomCollection
Custom inventory collection with a connection to the inventory component.
Ancestors
Members
TGorillaInventoryItem
Abstract basic class for item templates and collectables
Ancestors
Members
Fields
Methods
- public constructor Create ( ACollection : TCollection ) ;
- public destructor Destroy ( ) ;
- public function GetIdentifier ( ) : string ; class override;
- public function ToXml ( const AParent : TMz_XmlElement ) : TMz_XmlElement ; override;
- public procedure FromXml ( const ANode : TMz_XmlElement; const ACache : TGorillaInventoryLoadingCache ) ; override;
Properties
- published Parameters : TGorillaInventoryParameters
A list of parameters with variant values. Every parameter is identified by a unique name. The value is a TValue record with variable content.
read FParameters
write FParameters
TGorillaInventoryItemTemplate
Is a kind of prototype for all collectable items. Need to be pre-instanciated when creating the inventory.
Ancestors
Members
Fields
- protected FGroup :
TGorillaInventoryGroup
- protected FMaxQuantity :
Integer
- protected FWeight :
Single
- protected FMaxWeight :
Single
- protected FIsPooled :
Boolean
- protected FDependency :
TGorillaInventoryIngredientList
- protected FUpgradeItem :
TGorillaInventoryItemTemplate
- protected FDowngradeItem :
TGorillaInventoryItemTemplate
- protected FImageIndex :
Integer
Methods
- public constructor Create ( ACollection : TCollection ) ;
- public destructor Destroy ( ) ;
- public function GetIdentifier ( ) : string ; class override;
- public function Build
(
)
: TGorillaInventoryCollectable
;
virtual;
Build a collectable item on basis of this template.
- public function AddDependency
(
const
ATemplateId :
string; const
AQuantity :
Integer
)
: TGorillaInventoryIngredient
;
overload virtual;
Adds a new dependency for this template id. Dependencies are check on collecting process.
- public function AddDependency
(
const
ATemplate :
TGorillaInventoryItemTemplate; const
AQuantity :
Integer
)
: TGorillaInventoryIngredient
;
overload virtual;
Adds a new dependency for this template. Dependencies are check on collecting process.
- public procedure RemoveDependency
(
const
ATemplateId :
string
)
;
overload virtual;
Removes a template dependency by template id
- public procedure RemoveDependency
(
const
ATemplate :
TGorillaInventoryItemTemplate
)
;
overload virtual;
Removes a template dependency by a specific template
- public procedure ClearDependencies
(
)
;
virtual;
Clears the complete dependency list. Afterwards no more dependencies are available in the specific template.
- public function ToXml ( const AParent : TMz_XmlElement ) : TMz_XmlElement ; override;
- public procedure FromXml ( const ANode : TMz_XmlElement; const ACache : TGorillaInventoryLoadingCache ) ; override;
Properties
- published Group : TGorillaInventoryGroup
- published MaxQuantity : Integer
- published Weight : Single
- published MaxWeight : Single
- published IsPooled : Boolean
- published Dependency : TGorillaInventoryIngredientList
- published UpgradeItem : TGorillaInventoryItemTemplate
upgrade system, to make an item to another item you can define an item to upgrade to
read FUpgradeItem
write FUpgradeItem - published DowngradeItem : TGorillaInventoryItemTemplate
upgrade system, to make an item to another item you can define an item to downgrade to
read FDowngradeItem
write FDowngradeItem - published ImageIndex : Integer
Defines an index inside of a TImageList. The instanciated collectable will load automatically an image from that list, if ImageIndex > -1
read FImageIndex
write FImageIndex
TGorillaInventoryCollectable
Represents collected items with a reference to the item template
Ancestors
Members
Fields
- protected FTemplate :
TGorillaInventoryItemTemplate
- protected FQuantity :
Integer
- protected FWeight :
Single
Methods
- public constructor Create ( ACollection : TCollection ) ;
- public destructor Destroy ( ) ;
- public function GetIdentifier ( ) : string ; class override;
- public function GetCurrentName ( ) : string ; override;
- public function IsUpgradable
(
)
: Boolean
;
virtual;
Checks if a collected item is upgradable
- public function IsDowngradable
(
)
: Boolean
;
virtual;
Checks if a collected item is downgradable
- public function ToXml ( const AParent : TMz_XmlElement ) : TMz_XmlElement ; override;
- public procedure FromXml ( const ANode : TMz_XmlElement; const ACache : TGorillaInventoryLoadingCache ) ; override;
Properties
TGorillaInventoryItemCollection
The basic collection for item-templates and collectables
Ancestors
TGorillaInventoryCollectablesCollection
This is an extended collection of TGorillaInventoryItemCollection. We now have a "ToArray" function to easily return an array of all collectables to submit it to the manufacture() method.
Ancestors
Members
TGorillaInventoryGroup
An inventory group represents a categorization of specific items, f.e. weapons, keys, diary, notes, ...
Ancestors
Members
Fields
Methods
- public constructor Create ( ACollection : TCollection ) ;
- public destructor Destroy ( ) ;
- public function GetIdentifier ( ) : string ; class override;
- public function CountCollectables
(
)
: Integer
;
virtual;
Counts all currently available collected items belonging to this group.
- public function ToXml ( const AParent : TMz_XmlElement ) : TMz_XmlElement ; override;
- public procedure FromXml ( const ANode : TMz_XmlElement; const ACache : TGorillaInventoryLoadingCache ) ; override;
Properties
TGorillaInventoryGroupCollection
Collection of inventory item groups
Ancestors
TGorillaInventoryIngredient
An inventory ingredient is used f.e. for manufacturing multiple items to a single item, f.e. you have 1 bough + 1 elastic band = 1 slingshot For every ingredient you can set a quantity to define how many of this specific item is needed. By default this value is 1.
Ancestors
Members
Fields
Methods
- public constructor Create ( const ATemplate : TGorillaInventoryItemTemplate; const AQuantity : Integer = $1 ) ;
- public destructor Destroy ( ) ;
- public function ToXml ( const AParent : TMz_XmlElement ) : TMz_XmlElement ; virtual;
- public procedure FromXml ( const ANode : TMz_XmlElement; const ACache : TGorillaInventoryLoadingCache ) ; virtual;
Properties
TGorillaInventoryManufacturingProcess
For every manufacturing process inside of the manufacturer a new instance will be created to manage multiple processing on the same manufacturer. For example: You want to build 5 cars from ingredients parallel.
Ancestors
Members
Fields
- protected FManufacturer :
TGorillaInventoryManufacturer
- protected FKind :
TManufacturingProcessKind
- protected FIsInTimer :
Boolean
- protected FManufacturingProgress :
Integer
- protected FManufacturingTimer :
TTimer
- protected FCollectables :
TGorillaInventoryCollectablesCollection
Methods
- public constructor Create ( const AManufacturer : TGorillaInventoryManufacturer; const AKind : TManufacturingProcessKind ) ;
- public destructor Destroy ( ) ;
- protected function GetProgress ( ) : Integer ;
- protected procedure DoOnManufacturingProcess ( ASender : TObject ) ;
- protected procedure MoveItemsToLocalList
(
const
AItemList :
TArray<Gorilla.Utils.Inventory.TGorillaInventoryCollectable>
)
;
This method will move all necessary items from the input array to a local collectable list. On process destruction these items will be destroyed. If AItemList contains more items than necessary, those will not be moved!
- public procedure Start
(
const
AItemList :
TArray<Gorilla.Utils.Inventory.TGorillaInventoryCollectable>
)
;
Start manufacturing process
- public procedure Pause
(
)
;
virtual;
Pause manufacturing process
- public procedure Abort
(
const
ADestroyOnFinish :
Boolean
)
;
virtual;
Abort manufacturing process
- public procedure Complete
(
)
;
virtual;
Completes the manufacturing process
Properties
TGorillaInventoryManufacturer
Used to combine a specific number of items to a new item. The component offers a timespan to simulate a manufacturing process. If TimeNeeded > 0: a timer-event will be started When this event is thrown, the new item will be available. If TimeNeeded <= 0: the manufacturing process will be executed immediatly
Ancestors
Members
Fields
- protected FIngredients :
TGorillaInventoryIngredientList
- protected FResultItem :
TGorillaInventoryIngredient
- protected FKind :
TManufacturingProcessKind
- protected FTimeNeeded :
Integer
- protected FProcesses :
TObjectList<Gorilla.Utils.Inventory.TGorillaInventoryManufacturingProcess>
- protected FOnNotify :
TOnManufacturingNotify
- protected FOnProduced :
TOnManufacturingProduced
Methods
- public constructor Create ( ACollection : TCollection ) ;
- public destructor Destroy ( ) ;
- protected function GetIngredientsInfoMap ( ) : TGorillaInventoryManufacturer.TIngredientsMap ;
- protected function GetCollectablesInfoMap ( const AItemList : TArray<Gorilla.Utils.Inventory.TGorillaInventoryCollectable> ) : TGorillaInventoryManufacturer.TIngredientsMap ;
- protected procedure RemoveProcess
(
const
AProcess :
TGorillaInventoryManufacturingProcess
)
;
virtual;
Removes a manufacturing process from manufacturer. This method will automatically be executed by the process itself.
- public function GetIdentifier ( ) : string ; class override;
- public function Verify
(
const
AItemList :
TArray<Gorilla.Utils.Inventory.TGorillaInventoryCollectable>
)
: Boolean
;
virtual;
Verifies if this manufacturer is suitable with this array of collected items. TRUE, if all ingredients are give by the array. FALSE, if the number of ingredients is not correct or a specific ingredient is missing.
- public procedure AddIngredient
(
const
ATemplateId :
string; const
AQuantity :
Integer
=
$1
)
;
overload virtual;
Adds an existing template as ingredient with a quantity, which defines how many of those items are needed.
- public procedure AddIngredient
(
const
ATemplate :
TGorillaInventoryItemTemplate; const
AQuantity :
Integer
=
$1
)
;
overload virtual;
Adds an existing template as ingredient with a quantity, which defines how many of those items are needed.
- public procedure RemoveIngredient
(
const
ATemplateId :
string
)
;
overload virtual;
Removes an ingredient from manufacturer by template id.
- public procedure RemoveIngredient
(
const
ATemplate :
TGorillaInventoryItemTemplate
)
;
overload virtual;
Removes an ingredient from manufacturer by template.
- public procedure ClearIngredients
(
)
;
virtual;
Clears all added ingredients
- public function Produce
(
)
: TGorillaInventoryCollectable
;
virtual;
Will produce the result item immediatly. This method will automatically be called by Complete()
- public function Start
(
const
AItemList :
TArray<Gorilla.Utils.Inventory.TGorillaInventoryCollectable>
)
: TGorillaInventoryManufacturingProcess
;
virtual;
Starts and returns a manufacturing process instance. This is a handle on which you should request the progress or pause, abort, ...
- public function GetDescriptionString
(
)
: string
;
virtual;
This method builds a string, describing which ingredients and quantities needed, and what item will be created. f.e.: Wood(3) + Stone(2) + Grass(1) => Campfire(1)
- public function ToXml ( const AParent : TMz_XmlElement ) : TMz_XmlElement ; override;
- public procedure FromXml ( const ANode : TMz_XmlElement; const ACache : TGorillaInventoryLoadingCache ) ; override;
Properties
- published Ingredients : TGorillaInventoryIngredientList
- published ResultItem : TGorillaInventoryIngredient
A item template which will be buid by this manufacturer, if all necessary ingredients are available.
read FResultItem
write FResultItem - published Kind : TManufacturingProcessKind
- published TimeNeeded : Integer
Time needed to build the result item in milliseconds. If this value is > 0, a timer will be started. At the end, the result item will be produced. The default value is 3000 (= 3 second)
read FTimeNeeded
write FTimeNeeded
TGorillaInventoryManufacturerCollection
Collection of manufacturing processes
Ancestors
TGorillaInventory
Inventory component for managing templates, collected items, groups and manufacturing processes.
Ancestors
Members
Fields
- protected FItemTemplates :
TGorillaInventoryItemCollection
- protected FGroups :
TGorillaInventoryGroupCollection
- protected FManufacturers :
TGorillaInventoryManufacturerCollection
- protected FCollectedItems :
TGorillaInventoryCollectablesCollection
- protected FLanguage :
Integer
- protected FOnItemNotify :
TOnInventoryItemNotify
- protected FOnAddManufacturing :
TOnInventoryAddManufacturing
Methods
- public constructor Create ( AOwner : TComponent ) ;
- public destructor Destroy ( ) ;
- protected function DoManufactureUnverified
(
const
AManufacturer :
TGorillaInventoryManufacturer; const
AItemList :
TArray<Gorilla.Utils.Inventory.TGorillaInventoryCollectable>
)
: TGorillaInventoryManufacturingProcess
;
virtual;
Creates a manufacturing process without previous manufactuer verification of ingredients and submitted items.
- public function Clone
(
)
: TGorillaInventory
;
virtual;
Creates a cloned instance of a specific inventory with all its components.
- public procedure Clear
(
)
;
virtual;
Destroys all templates, groups, manufacturers and collected items
- public function GetCurrentLanguageName
(
)
: string
;
virtual;
Get the current language locale code, f.e. "en-us", "de-de"
- public function AddItemTemplate
(
const
ATemplateId :
string
)
: TGorillaInventoryItemTemplate
;
virtual;
Adds a new and empty item template.
- public procedure RemoveItemTemplate
(
const
ATemplateId :
string
)
;
overload virtual;
Removes an item templates by id and destroys all collected items using this specific template. Also all dependencies are check and eventually removed from those.
- public procedure RemoveItemTemplate
(
const
ATemplate :
TGorillaInventoryItemTemplate
)
;
overload virtual;
Removes an item templates and destroys all collected items using this specific template. Also all dependencies are check and eventually removed from those.
- public function FindItemTemplate
(
const
ATemplateId :
string
)
: TGorillaInventoryItemTemplate
;
virtual;
Searches for an item template by its id
- public function FindCollectedItems
(
const
AId :
string
)
: TArray<Gorilla.Utils.Inventory.TGorillaInventoryCollectable>
;
overload virtual;
Searches for all collected items inherited by this specific template
- public function FindCollectedItems
(
const
ATemplate :
TGorillaInventoryItemTemplate
)
: TArray<Gorilla.Utils.Inventory.TGorillaInventoryCollectable>
;
overload virtual;
Searches for all collected items inherited by this specific template
- public function FindFirstCollectedItem
(
const
AId :
string
)
: TGorillaInventoryCollectable
;
overload virtual;
Searches for the first collected item inherited by a specific template. This method is used for pooled items, so we don't have to scan the complete list.
- public function FindFirstCollectedItem
(
const
ATemplate :
TGorillaInventoryItemTemplate
)
: TGorillaInventoryCollectable
;
overload virtual;
Searches for the first collected item inherited by a specific template. This method is used for pooled items, so we don't have to scan the complete list.
- public function AddGroup
(
const
AGroupId :
string
)
: TGorillaInventoryGroup
;
Adds a new group with a submitted id.
- public procedure RemoveGroup
(
const
AGroupId :
string
)
;
overload virtual;
Removes a group by id and unlinks it from all templates.
- public procedure RemoveGroup
(
const
AGroup :
TGorillaInventoryGroup
)
;
overload virtual;
Removes a group and unlinks it from all templates.
- public function FindGroup
(
const
AGroupId :
string
)
: TGorillaInventoryGroup
;
Searches for a specific item group by its id
- public function AddManufacturer
(
const
AManId :
string
)
: TGorillaInventoryManufacturer
;
Adds and returns a new manufacturer to the inventory system. Afterwards you need to add ingredients, result-type and time-needed.
- public procedure RemoveManufacturer
(
const
AManId :
string
)
;
overload virtual;
Removes a specific manufacturer by id from inventory.
- public procedure RemoveManufacturer
(
const
AMan :
TGorillaInventoryManufacturer
)
;
overload virtual;
Removes a specific manufacturer from inventory.
- public function FindManufacturer
(
const
AId :
string
)
: TGorillaInventoryManufacturer
;
Searches for a specific manufacturer by its id
- public function IsCollectable
(
const
ATemplateId :
string
)
: TGorillaInventoryCollectState
;
overload;
Checks if an item is collectable, specified by its template. The method checks if it's allowed to pick up an item. It will return a collection state.
- public function IsCollectable
(
const
ATemplate :
TGorillaInventoryItemTemplate
)
: TGorillaInventoryCollectState
;
overload;
Checks if an item is collectable, specified by its template. The method checks if it's allowed to pick up an item. It will return a collection state.
- public function Collect
(
const
ATemplateId :
string
)
: TGorillaInventoryCollectable
;
overload virtual;
Trys to collect an item, specified by its template. The method will execute the IsCollectable() routine to check if it is allowed to pick it up. The method returns a state of collection, f.e. QuantityExceeded, Collected, ... in the out-parameter AState The method will return a collectable item instance, if AState = "Collected"
- public function Collect
(
const
ATemplate :
TGorillaInventoryItemTemplate; out
AState :
TGorillaInventoryCollectState
)
: TGorillaInventoryCollectable
;
overload virtual;
Trys to collect an item, specified by its template. The method will execute the IsCollectable() routine to check if it is allowed to pick it up. The method returns a state of collection, f.e. QuantityExceeded, Collected, ... in the out-parameter AState The method will return a collectable item instance, if AState = "Collected"
- public procedure DropCollectedItem
(
const
AItem :
string; const
ADropAll :
Boolean
)
;
overload virtual;
Removes a collected item from inventory.
- public procedure DropCollectedItem
(
const
AItem :
TGorillaInventoryCollectable; const
ACount :
Integer
=
$FFFFFFFF
)
;
overload virtual;
Removes a collected item from inventory.
- public procedure DropCollectedItem
(
const
ATemplate :
TGorillaInventoryItemTemplate; const
ADropAll :
Boolean
)
;
overload virtual;
Removes a collected item from inventory.
- public function GetSuitableManufacturer
(
const
AItemList :
TArray<Gorilla.Utils.Inventory.TGorillaInventoryCollectable>
)
: TGorillaInventoryManufacturer
;
virtual;
Depending on the given list of collected items - the method tries to find a suitable manufacturer. It will only return the first suitable manufacturer! If you're using multiple manufacturers with equivalent ingredients use GetSuitableManufacturers() method to get all suitable instances.
- public function GetSuitableManufacturers
(
const
AItemList :
TArray<Gorilla.Utils.Inventory.TGorillaInventoryCollectable>
)
: TList<Gorilla.Utils.Inventory.TGorillaInventoryManufacturer>
;
virtual;
Depending on the given list of collected items - the method tries to find all suitable manufacturers.
- public function Manufacture
(
const
AItemList :
TArray<Gorilla.Utils.Inventory.TGorillaInventoryCollectable>
)
: TGorillaInventoryManufacturingProcess
;
overload virtual;
Use this method if you only have a number of collected items. The method will try to find a suitable manufacturer and will automatically execute manufacturing process. The result is the manufacturing process instance.
- public function Manufacture
(
const
AManufacturer :
TGorillaInventoryManufacturer; const
AItemList :
TArray<Gorilla.Utils.Inventory.TGorillaInventoryCollectable>
)
: TGorillaInventoryManufacturingProcess
;
overload virtual;
Use this method if you have a specific manufacturer. The method will check for you, if your collected items suits the conditions (including quantities). It will automatically execute manufacturing process. The result is the manufacturing process instance.
- public function Upgrade
(
const
AItem :
TGorillaInventoryCollectable
)
: TGorillaInventoryManufacturingProcess
;
virtual;
Level up a specific collectable item.
- public function Downgrade
(
const
AItem :
TGorillaInventoryCollectable
)
: TGorillaInventoryManufacturingProcess
;
virtual;
Level down a specific collectable item.
- public procedure SaveToFile
(
const
AFilename :
string
)
;
virtual;
Store inventory including templates, groups, manufacturers, collected items to xml file.
- public procedure SaveToStream
(
const
AStream :
TStream
)
;
virtual;
Store inventory including templates, groups, manufacturers, collected items to xml stream.
- public procedure LoadFromFile
(
const
AFilename :
string
)
;
virtual;
Load an inventory from xml file format. all components will be added to the current inventory.
- public procedure LoadFromStream
(
const
AStream :
TStream
)
;
virtual;
Load an inventory from xml file format. all components will be added to the current inventory.
Properties
- published ItemTemplates : TGorillaInventoryItemCollection
add here all possibly available items this represents NOT the collected items of the user.
read FItemTemplates
write FItemTemplates - published Groups : TGorillaInventoryGroupCollection
- published Manufacturers : TGorillaInventoryManufacturerCollection
add here all possibly available item combinations. f.e. you have 1 bough + 1 elastic band = 1 slingshot
read FManufacturers
write FManufacturers - published CollectedItems : TGorillaInventoryCollectablesCollection
add here all collected items the user should see these items will be displayed as inventory items.
read FCollectedItems
write FCollectedItems - published Language : Integer