Skip to content

Refactor inventory system

wsxmr1234 edited this page Oct 4, 2022 · 3 revisions

In sprint3, interacting with NPCs involves submitting relevant clue items to NPCs, which are not supported by the previous inventory system. Because in the previous inventory system, a unique id was not allocated to items in the game, the two existing items time item and scales were distinguished by different components bound to these two entities, which is very inconvenient. Therefore, the inventory system is reconstructed to achieve necessary functions.

UML diagram

image

First, we assign ids to each item in the game, and manage items in the form of configuration files. The path of the configuration file is configs/items.json.

{
  "itemList": [
    {
      "class": "com.deco2800.game.components.player.entity.ConsumableItem",
      "id": 1,
      "name": "Time Item",
      "description": "Time Item - This item can be used to increase the countdown clock!",
      "textureLocation": "images/inventory/time_item.png"
    },
    .....
    .....
    .....
    {
      "class": "com.deco2800.game.components.player.entity.ClueItem",
      "id": 9,
      "name": "Mysterious Key",
      "description": "Mysterious Key - This key can be used to win the game!",
      "textureLocation": "images/KEY.png"
    }
  ]
}

The configuration file will be read when the InventoryComponent is loaded, and each object in items.json will be serialized into an Item class object. In this way we combine the item's id, description and material path in one object. Compared with the previous inventory system, the information of an item is scattered in different classes, which improves the degree of aggregation of information and is more in line with the object-oriented idea.

I defined an Inventory interface to specify various basic functions that the inventory system should have. The InventoryComponent class and the Backpack class implement this interface. At the same time, the Backpack class is aggregated in the InventoryComponent class. In InventoryComponent class, the implementation of abstract methods in Inventory is to call the corresponding method in backpack property. In addition, in the add(int id) method, we have added log related operations before calling the method corresponding to the backpack. This uses the static proxy design pattern.

@Override
public boolean add(int id) {
  boolean ret = backpack.add(id);
  logger.info(backpack.toString());
  return ret;
}

Before designing the Item class. I analyzed the possible types of items in the game, and finally divided the items into three types, consumable items, clue items and equipment items. At the same time, I also wrote instructions about adding new items to the game to help other students add new item in the future. Instructions on how to use the inventory system

For the display of inventory in the game, in the previous system, when the player picked up two identical items, two identical item icons would be displayed on the backpack interface. After the code refactoring, we can clearly know the library quantity of an item, so when there are multiple items of the same item, only one icon will be displayed and the number of the item hovered over by the mouse will be displayed in front of the item description. image

Table of Contents

Home

Game Design

User survey

Sprint 4

Eviction Menu and Win/lose Logic: Polishing tasks (Team 7)

Button Sounds and Ending Menu improve (Team 3)

Sound effect and Fixing the clue bug (Team 6)

Improvement of Enemy and Attack (Team 1)

Add Features When The Player Get Attacked and Overall UI Improvement (Team 8)

Sprint 1

Achievement System (Team 2)

Player Eviction Menu (Team 7)

Countdown Clock (Team 4)

Music (Team3)

Map (Team6)

Sprint 2

Player Eviction Menu (Team 7)

Character Design & Animation (Team 1)

Music (Team 3)

Inventory System and Consumables Items (Team 8)

Scenario design

Achievement System(team 2)

Storyline (Team 5)

Countdown Clock (Team 4)

Sprint 3

Ending Menu (Team 3)

NPC interaction (Team 2)

Win/lose Condition (Based on Eviction Menu) (Team 7)

Player Profile (Team 4)

Game Logo (Team 8)

Clue storage (Team 6)

Enemy Design and Attack (Team 1)

Scenario design for village(Team5)

Game design
Entities and Components

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally