RogueLife/src/comp/fighter.h

80 lines
2.4 KiB
C

//---
// fighter: Component for entities that participate in fights
//
// This component gives combat statistics and leveling properties to entities.
//---
#pragma once
#include "comp/entity.h"
#include "fixed.h"
typedef struct
{
/* Hit Points */
fixed_t HP;
/* Physical attack */
fixed_t ATK;
/* Magical attack */
fixed_t MAG;
/* Physical and magical defense */
fixed_t DEF;
} fighter_stat_model_t;
typedef struct
{
/* Current attack's effect area */
entity_t *current_attack;
/* Whether attack follows movement */
uint8_t attack_follows_movement;
/* Pointer to enemy data (NULL if player) */
struct enemy_data *enemy;
/* Pointer to player data (NULL if enemy) */
struct player_data *player;
/* Combat statistics */
uint16_t HP, ATK, MAG, DEF, HP_max;
/* Number of hits in main attack's combo (TODO: Delegate to weapon?) */
uint8_t combo_length;
/* Next hit to be dealt */
uint8_t combo_next;
/* Delay until ideal time to start next hit */
fixed_t combo_delay;
/* List of skills or equipped items. The first entry (skills[0]) usually
means the normal attack and might be handled separately because of the
combo system */
int skills[6];
/* Cooldown; positive while waiting, zero when the skill/item is ready */
fixed_t actions_cooldown[6];
/* Current status effects */
fixed_t stun_delay;
fixed_t invulnerability_delay;
} fighter_t;
/* Multiply equipment stat modifiers */
fighter_stat_model_t fighter_stat_model_mul(int amount, ...);
/* Instantiate a statistics model with optional equipment and HP multiplier */
fighter_stat_model_t fighter_stat_model_instantiate(
fighter_stat_model_t const *model, fighter_stat_model_t const *equipment,
int level, fixed_t hp_multiplier);
/* Initialize fighter's stats by using the instantiated stat model */
void fighter_set_stats(fighter_t *f, fighter_stat_model_t const *instance);
/* Damage entity for that amount of raw strength. Returns actual damage after
DES is subtracted, and randomization. */
int fighter_damage(entity_t *e, int base_damage);
/* Stun the fighter for a specified duration. */
void fighter_stun(entity_t *e, fixed_t duration);
/* Make the fighter invulnerable for a specified duration. */
void fighter_invulnerability(entity_t *e, fixed_t duration);
/* Free dynamic data (enemy info). */
void fighter_destroy(entity_t *e);