fp: Add cooldowns to attacks
This commit is contained in:
@@ -723,3 +723,29 @@ FP_GameFindClosestEntityResult FP_Game_FindClosestEntityWithType(FP_Game *game,
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool FP_Game_CanEntityAttack(FP_GameEntity *entity, uint64_t current_time_ms)
|
||||
{
|
||||
bool result = (current_time_ms - entity->last_attack_timestamp) >= entity->attack_cooldown_ms;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void FP_Game_EntityTransitionState(FP_Game *game, FP_GameEntity *entity, uint32_t desired_state)
|
||||
{
|
||||
switch (desired_state) {
|
||||
case FP_EntityClingerState_Attack: {
|
||||
if (entity->type == FP_EntityType_ClubTerry) {
|
||||
break;
|
||||
}
|
||||
if (!FP_Game_CanEntityAttack(entity, game->clock_ms)) {
|
||||
// NOTE: Cooldown not met do not transition
|
||||
return;
|
||||
}
|
||||
|
||||
entity->last_attack_timestamp = game->clock_ms;
|
||||
} break;
|
||||
}
|
||||
// NOTE: If no returns are hit above we proceed with the state change
|
||||
entity->action.next_state = desired_state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user