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 item id.

  • 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's id.

  • ConsumedItemEntity: Represents a consumed item's type and value.

State

  • items: Maps ItemKey to ItemEntity, representing the items each player owns.

  • equippedItems: Maps EquippedItemKey to EquippedItemEntity, representing the items each player has equipped.

  • consumedItems: Maps ConsumedItemKey to ConsumedItemEntity, 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