Removes some duplicate code in player.c

This commit is contained in:
Linus Probert 2018-03-01 06:13:43 +01:00
parent c42e6fa621
commit da2ec32981
1 changed files with 12 additions and 10 deletions

View File

@ -242,6 +242,16 @@ handle_movement_input(Player *player, RoomMatrix *matrix, SDL_Event *event)
} }
} }
static void
use_skill(Skill *skill, SkillData *skillData)
{
skill->active = false;
skill->use(skill, skillData);
if (skill->actionRequired)
player_step(skillData->player);
skill->resetCountdown = skill->resetTime;
}
static void static void
check_skill_activation(Player *player, RoomMatrix *matrix, SDL_Event *event) check_skill_activation(Player *player, RoomMatrix *matrix, SDL_Event *event)
{ {
@ -274,11 +284,7 @@ check_skill_activation(Player *player, RoomMatrix *matrix, SDL_Event *event)
skill->active = (selected - 1) == i && !skill->active && skill->resetCountdown == 0; skill->active = (selected - 1) == i && !skill->active && skill->resetCountdown == 0;
if (skill->active && skill->instantUse) { if (skill->active && skill->instantUse) {
SkillData skillData = { player, matrix, VECTOR2D_NODIR }; SkillData skillData = { player, matrix, VECTOR2D_NODIR };
skill->active = false; use_skill(skill, &skillData);
skill->use(skill, &skillData);
if (skill->actionRequired)
player_step(player);
skill->resetCountdown = skill->resetTime;
} }
} }
} }
@ -310,11 +316,7 @@ check_skill_trigger(Player *player, RoomMatrix *matrix, SDL_Event *event)
return false; return false;
SkillData skillData = { player, matrix, dir }; SkillData skillData = { player, matrix, dir };
player->skills[activeSkill]->use(player->skills[activeSkill], &skillData); use_skill(player->skills[activeSkill], &skillData);
player->skills[activeSkill]->active = false;
if (player->skills[activeSkill]->actionRequired)
player_step(player);
player->skills[activeSkill]->resetCountdown = player->skills[activeSkill]->resetTime;
return true; return true;
} }