Item
The Item
class is responsible for managing the in-game items, their attributes, and interactions.
Structures
ItemKey: Unique identifier for items, consisting of the owner's
PublicKey
and itemid
.ItemEntity: Represents an item's properties, including stats, type, and state (e.g., consumable, upgradable).
EquippedItemKey: Identifier for equipped items, consisting of the owner's
PublicKey
and the slot number.EquippedItemEntity: Represents an equipped item's
itemid
.ConsumedItemKey: Identifier for consumed items, consisting of the owner's
PublicKey
and the item'sid
.ConsumedItemEntity: Represents a consumed item's type and value.
State
items
: MapsItemKey
toItemEntity
, representing the items each player owns.equippedItems
: MapsEquippedItemKey
toEquippedItemEntity
, representing the items each player has equipped.consumedItems
: MapsConsumedItemKey
toConsumedItemEntity
, representing the items each player has consumed.itemCount
: Tracks the total number of items created.
Methods
createNewSwordItem()
Creates a new sword item with predefined attributes.
Functionality:
Increments the
itemCount
.Adds a new sword item to the player's items with initial attributes (e.g.,
damage: 1
).
createNewShieldItem()
Creates a new shield item with predefined attributes.
Functionality:
Increments the
itemCount
.Adds a new shield item to the player's items with initial attributes (e.g.,
defense: 1
).
equipItem(equippeditemslot: UInt32, itemid: UInt32)
Equips an item to the specified slot.
Parameters:
equippeditemslot
: The slot number to equip the item to.itemid
: The ID of the item to equip.
Functionality:
Verifies the existence of the item and the emptiness of the slot.
Equips the item to the specified slot.
unequipItem(equipeditemslot: UInt32)
Unequips an item from the specified slot.
Parameters:
equipeditemslot
: The slot number to unequip the item from.
Functionality:
Verifies that the slot is not already empty.
Unequips the item from the specified slot.
getEquippedItem(equipeditemslot: UInt32)
Retrieves the item equipped in the specified slot.
Parameters:
equipeditemslot
: The slot number to retrieve the item from.
Returns:
The
itemid
of the equipped item.
upgradeDamage(id: UInt32)
Upgrades the damage attribute of an item.
Parameters:
id
: The ID of the item to upgrade.
Functionality:
Verifies the existence of the item and sufficient
statxp
.Upgrades the item's damage attribute.
upgradeDefense(id: UInt32)
Upgrades the defense attribute of an item.
Parameters:
id
: The ID of the item to upgrade.
Functionality:
Verifies the existence of the item and sufficient
statxp
.Upgrades the item's defense attribute.
consumeItem(id: UInt32)
Consumes an item, changing its state and registering it as consumed.
Parameters:
id
: The ID of the item to consume.
Functionality:
Verifies the item's existence, consumability, and non-consumed state.
Changes the item's state to consumed and registers it in
consumedItems
.
Last updated