Design for item_statistic_function - uchicago-cs/chiventure GitHub Wiki

The Item statistic function is one of the 4 main atomic effects in the effect.c file in skilltrees. The premise behind item statistic function is that the player is able to execute a skill which will then effect the the main data regarding the item. This can be figures such as the durability of the item, the life of the item, the strength etc... The implementations of item_stat_effect will be very similar to that of the player_stat_effect.

We will first start by designing the struct that the item_statistic_function which will take in.

item_stat_effect struct

Defines an effect that changes the statistic of an item. An item stat effect should take an item and a list of statistics and mods and apply the mods to the statistics in the item's statistic hash table.

typedef struct item_stat_effect {

`/* The ID of the parent object */`
`item_t* item; `

`/* Takes the array of statistics that must be  */`
`stats_t** stats; `

`/* Modifies the statistic by this number */`
`double* modifications;         `

`/* The array of durations for how long the effect should be applied */`
`int* durations;    `

`/* Number of statistic that will be modified */`
`int num_stats; `

} item_stat_effect_t;

define item_stat_effect

Takes in parameters of the struct and returns: A pointer to the created item stat modifying effect. This is the trickiest part, as you need to find the statistics in the items stat hash table using HASH_FIND_STR. Currently items do not accomodate a statistics field. Future implementation could look into changing the statistics of a battle item instead specified in the battle struct.

item_stat_effect_t* define_item_stat_effect(item_t* item, char** stat_names, double* modifications, int* durations, int num_stats, chiventure_ctx_t* ctx);

make_item_stat_effect

Takes the given item statistic modifying effect and converts it into an effect. Parameters: item_stat_effect_t* item_stat_effect - Pointer to the item statistic modifying effect. Returns: A pointer to an effect

effect_t* make_item_stat_effect(item_stat_effect_t* item_stat_effect);

Execute item_stat_effect

Takes the given attribute modifying effect and executes it. Parameters: item_stat_effect_t* item_stat_effect - a pointer to the item stat modifying effect. Returns: 0 is the execution was successful, 1 otherwise

int execute_item_stat_effect(item_stat_effect_t* item_stat_effect, chiventure_ctx_t* ctx);

Overall this implementation is very similar to that of the player statistic effect. The most difficult part of this code will be the define_item_stat_effect as the statistics hash table for an item is not very clear.

Testing

After implementation testing needs to be done to see if code is executed coherently and according to the predefined nature of chiventure