Inventory interactions and refinements - UQdeco2800/2022-studio-2 GitHub Wiki

This wiki page will walk you through the newly updated sprint 3 features and refinements of inventory

unequip weapon and armour

In sprint 2, weapon and armours can only be equipped but not taken down. In sprint 3, I implemented unequip to allow the player to take off the current equipped weapon/armour. Unequipping will change the player's stat back.

public boolean unequipItem(int itemSlot) {
    boolean unequipped = false;
    if (inventory.size() == inventorySize) {
        logger.info("Inventory if full, cannot unequip");
    } else if (equipables[itemSlot] != null) {
        Entity item = equipables[itemSlot];
        if (item.checkEntityType(EntityTypes.WEAPON)) {
            applyWeaponEffect(item, unequipped);
            //CANCEL_ANIMATION
            cancelAnimation();
        } else if (item.checkEntityType(EntityTypes.ARMOUR)) {
            applyArmourEffect(item, unequipped);
        }
        addItem(item);
        equipables[itemSlot] = null;
        unequipped = true;
    }
    return unequipped;
}

Sorting algorithm

Live display updates

On each operation that may change the inventory. The hot update method is called to rerender the inventory menu and lively update changes.

The update method will clear the existing actors in the inventoryGroup and adding them back based off current inventory's state.

public void updateInventoryDisplay() {
    inventoryGroup.clear();
    ServiceLocator.getInventoryArea().displayInventoryMenu();
    ServiceLocator.getInventoryArea().displayItems();
    ServiceLocator.getInventoryArea().displayEquipables();
}

The following are the methods that will trigger updates: equipItem unequip addToQuickBar dropItem

Equippable display

Button interactions in inventory pop-up menu

Swapping weapons and armours

Swapping weapons and armours was not supported in early sprint 3. In the previous process of swapping an equipped item, the player has to unequip and equip an item. Now, the player can swap equipped items by only doing equip.

public void swapItem(Entity item) {
    int itemSlot = item.checkEntityType(EntityTypes.WEAPON)? 0 : 1;
    Entity swappedItem = equipables[itemSlot];
    if (swappedItem != null) {
        if (itemSlot == 0) {
            applyWeaponEffect(swappedItem, false);
            //CANCEL_ANIMATION
            cancelAnimation();
            //Swap
            applyWeaponEffect(item, true);
            registerAnimation(item);
            equipables[0] = item;
        } else if (itemSlot == 1) {
            applyArmourEffect(swappedItem, false);
            //Swap
            applyArmourEffect(item, true);
            equipables[1] = item;
        }
        removeItem(item);
        addItem(swappedItem);
    }
}

Back to Inventory Page

Author

  • Li-Sung Ou
  • GitHub: @PeterOu8
  • Discord: Secret Agent Randy Beans#6754
  • Slack: Li-Sung Ou
⚠️ **GitHub.com Fallback** ⚠️