Skip to content

Commit

Permalink
Move ContitionAplliying into Game_Battler.cpp
Browse files Browse the repository at this point in the history
RPG_RT2k3 should show damage numbers now
  • Loading branch information
Tondorian committed Mar 12, 2016
1 parent f75f9b4 commit 97ee082
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
15 changes: 0 additions & 15 deletions src/game_battlealgorithm.cpp
Expand Up @@ -312,21 +312,6 @@ void Game_BattleAlgorithm::AlgorithmBase::SetTarget(Game_Battler* target) {
}

void Game_BattleAlgorithm::AlgorithmBase::Apply() {
std::vector<int16_t> inflictedStates = source->GetInflictedStates();
if (inflictedStates.size() != 0) {
for (int i = 0; i<inflictedStates.size(); ++i) {
RPG::State state = Data::states[inflictedStates[i]];
int hp = state.hp_change_val;
int sp = state.sp_change_val;
int source_hp = source->GetHp();
int source_sp = source->GetSp();
int src_hp = std::min(source_hp + 1, IsPositive() ? hp : -hp);
int src_sp = std::min(source_sp, IsPositive() ? sp : -sp);
source->ChangeHp(src_hp);
source->ChangeSp(src_sp);
}
}

if (GetAffectedHp() != -1) {
int hp = GetAffectedHp();
int target_hp = (*current_target)->GetHp();
Expand Down
34 changes: 34 additions & 0 deletions src/game_battler.cpp
Expand Up @@ -327,6 +327,40 @@ static bool non_permanent(int state_id) {
return Data::states[state_id - 1].type == RPG::State::Persistence_ends;
}

int Game_Battler::ApplyConditions()
{
int damageTaken = 0;
std::vector<int16_t> inflictedStates = this->GetInflictedStates();
if (inflictedStates.size() != 0) {
for (int i = 0; i<inflictedStates.size(); ++i) {
RPG::State state = Data::states[inflictedStates[i]];
int hp = state.hp_change_val;
int sp = state.sp_change_val;
int source_hp = this->GetHp();
int source_sp = this->GetSp();
int src_hp = 0;
int src_sp = 0;
if (state.hp_change_type == state.ChangeType_lose) {
src_hp = -std::min(source_hp + 1, hp);
}
else {
src_hp = std::min(source_hp, hp);
}
if (state.sp_change_type == state.ChangeType_lose) {
source_sp = -std::min(source_sp, sp);
}
else {
source_sp = std::min(source_sp, sp);
}
this->ChangeHp(src_hp);
this->ChangeSp(src_sp);
damageTaken += src_hp;
}
}
return damageTaken;
}


void Game_Battler::RemoveBattleStates() {
std::vector<int16_t>& states = GetStates();

Expand Down
7 changes: 7 additions & 0 deletions src/game_battler.h
Expand Up @@ -58,6 +58,13 @@ class Game_Battler {
*/
std::vector<int16_t> GetInflictedStates() const;

/**
* Apply effects of Conditions to Battler
*
* @return Damage taken to Battler from conditions
*/
int ApplyConditions();

/**
* Gets battler states.
* This returns the raw state list with not inflected states set to 0 and
Expand Down
1 change: 1 addition & 0 deletions src/scene_battle_rpg2k.cpp
Expand Up @@ -370,6 +370,7 @@ bool Scene_Battle_Rpg2k::ProcessBattleAction(Game_BattleAlgorithm::AlgorithmBase
if (action->IsFirstAttack()) {
std::vector<int16_t> states_to_heal = action->GetSource()->NextBattleTurn();
std::vector<int16_t> states_remaining = action->GetSource()->GetInflictedStates();
action->GetSource()->ApplyConditions();
if (!states_to_heal.empty() || !states_remaining.empty()) {
battle_message_window->Clear();
for (std::vector<int16_t>::iterator it = states_to_heal.begin(); it != states_to_heal.end(); ++it) {
Expand Down
9 changes: 9 additions & 0 deletions src/scene_battle_rpg2k3.cpp
Expand Up @@ -532,6 +532,15 @@ bool Scene_Battle_Rpg2k3::ProcessBattleAction(Game_BattleAlgorithm::AlgorithmBas

if (action->IsFirstAttack() && action->GetStartSe()) {
Game_System::SePlay(*action->GetStartSe());
int damageTaken = action->GetSource()->ApplyConditions();
if (damageTaken != 0) {
DrawFloatText(
action->GetTarget()->GetBattleX(),
action->GetTarget()->GetBattleY(),
0,
boost::lexical_cast<std::string>(damageTaken),
30);
}
}

battle_action_state = BattleActionState_Result;
Expand Down

0 comments on commit 97ee082

Please sign in to comment.