Items ~ Equipment ~ Design Document - uchicago-cs/chiventure GitHub Wiki

Battle Items and Equipment Design Document

The goal of this implementation is to align our battle items with the current stats. This would allow battle items to modify stats beyond hp, attack, and defense. We would also like to implement equipment. Equipment enhances a combatants stats. We would like to have a combatant to have three pieces of equipment: a weapon, armor, and an accessory.

Currently our battle_item_t struct looks like this

typedef struct battle_item {

int id;

bool is_weapon;

int effectiveness_decrement;

int quantity;

int durability;

char* name;

char* description;

bool battle;

int attack;

int defense;

int hp;

struct battle_item *next;

struct battle_item *prev;

} battle_item_t;

Here are the changes we would like to make to this data type, as well as adding an equipment data type.

Here is the definition for the equipment_type enum, which will be used for the battle_equipment struct:

//An ENUM that labels the type of equipment.
enum equipment_type{
    ACCESSORY,
    ARMOR,
    WEAPON
};

Here is the definition for the battle equipment struct:

//A data structure of a piece of equipment
typedef struct battle_equipment{
    int id; // the id of the equipment, should be unique for each individual type of equipment.
    char *name; // the name of the equipment
    char *description; // the description of the equipment
    stat_changes_t *attributes; // the stats that are changed by the equipment
    equipment_type type; // determines the type of equipment (armor, weapon, accessory)
} battle_equipment_t;

Here is the definition for the new combatant struct. It allows a combatant to have three types equipment:

typedef struct combatant
{
    char *name;
    bool is_friendly;
    class_t *class_type;
    stat_t *stats;
    move_t *moves;
    battle_item_t *items;
    difficulty_t ai;
    battle_equipment_t *weapon;
    battle_equipment_t *accessory;
    battle_equipment_t *armor;
    struct combatant *next;
    struct combatant *prev;
} combatant_t;

We will also have to update battle_player_t to accommodate for the new equipment struct.

/* Stub for the player struct in game-state */
typedef struct battle_player {
    // Other fields: hash handle, inventory, other stats
    char *player_id;
    class_t *class_type;
    stat_t *stats;
    move_t *moves;
    battle_item_t *items;
    battle_equipment_t *weapon;
    battle_equipment_t *accessory;
    battle_equipment_t *armor;
} battle_player_t;

Here is the definition for the new battle item struct (a consumable):

typedef struct battle_item{
    int id; // the id of the item, should be unique for each individual type of item.
    char *name; // the name of the item
    char *description; // the description of the item
    stat_changes_t *attributes; // the stats that are changed by the item
    int quantity; // the amount of items we have of this item
    bool attack; // determines whether the item is used as an attack against the enemy, or as a defensive item for player
    struct battle_item *next; // the next battle item
    struct battle_item *prev; // the previous battle item
} battle_item_t;

Functions and Files to Be Changed

battle_default_objects.c

We will need to change the following functions:

  • get_random_default_weapon() //needs to account for new fields
  • get_random_default_consumable() //needs to account for new fields

Additionally, we will need to add a function:

  • get_random_equipment_set() //gives random equipment set

battle_flow.c

  • set_battle_player() //needs to account for equipment stat changes.
  • set_enemy() //needs to account for equipment stat changes.
  • battle_flow_item() //needs to account for new fields

battle_flow_structs.c

  • new_ctx_player() //needs to account for equipment

battle_logic.c

  • consume_battle_item() // needs to account for new fields
  • use_battle_item() // needs to account for new fields
  • stat_changes_add_item_node // needs to account for new fields

Things to be moved to this file:

  • apply_stat_changes() //move from battle_flow.c

battle_print.c

  • print_battle_items() // needs to account for new fields
  • print_battle_action_menu() // needs to account for new fields

battle_state.c

  • combatant_new() // needs to account for new fields
  • combatant_init() // needs to account for new fields
  • combatant_free() //needs to account for new fields