New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditions in Battles #815

Merged
merged 10 commits into from Mar 14, 2016

Move ContitionAplliying into Game_Battler.cpp

RPG_RT2k3 should show damage numbers now
  • Loading branch information...
Tondorian committed Mar 12, 2016
commit 97ee0829ede1ffe8f004ddcf7e6d73e1dd22f87e
@@ -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();
View
@@ -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]];

This comment has been minimized.

@Ghabry

Ghabry Mar 12, 2016

Member

The loop can be easier written as:

for (int16_t inflicted : inflictedStates) {
    RPG::State state = Data::states[inflicted - 1];

and the if (inflictedStates.size() != 0) { check is not needed

@Ghabry

Ghabry Mar 12, 2016

Member

The loop can be easier written as:

for (int16_t inflicted : inflictedStates) {
    RPG::State state = Data::states[inflicted - 1];

and the if (inflictedStates.size() != 0) { check is not needed

int hp = state.hp_change_val;
int sp = state.sp_change_val;

This comment has been minimized.

@Ghabry

Ghabry Mar 12, 2016

Member

This calculation ignores the "Percentage of max HP/SP". In other sections of code where this is required we do something like this:

int hp = state.hp_change_val + (int)(std::ceil(GetMaxHp() * state.hp_change_max / 100.0));```
@Ghabry

Ghabry Mar 12, 2016

Member

This calculation ignores the "Percentage of max HP/SP". In other sections of code where this is required we do something like this:

int hp = state.hp_change_val + (int)(std::ceil(GetMaxHp() * state.hp_change_max / 100.0));```
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 comment has been minimized.

@Ghabry

Ghabry Mar 12, 2016

Member

RPG2k3 added RPG::State::ChangeType_gain, which is what you handle in your ELSE case. But RPG::State::ChangeType_none (No change at all) is not handled.

@Ghabry

Ghabry Mar 12, 2016

Member

RPG2k3 added RPG::State::ChangeType_gain, which is what you handle in your ELSE case. But RPG::State::ChangeType_none (No change at all) is not handled.

This comment has been minimized.

@Tondorian

Tondorian Mar 12, 2016

Member

in ChangeType_none case i only need to set src_s/hp = 0?

@Tondorian

Tondorian Mar 12, 2016

Member

in ChangeType_none case i only need to set src_s/hp = 0?

This comment has been minimized.

@Ghabry

Ghabry Mar 12, 2016

Member

Yeah, 0 change

@Ghabry

Ghabry Mar 12, 2016

Member

Yeah, 0 change

this->ChangeHp(src_hp);
this->ChangeSp(src_sp);
damageTaken += src_hp;
}
}
return damageTaken;

This comment has been minimized.

@Ghabry

Ghabry Mar 12, 2016

Member

The return value must be negated (return a negative value for damage currently)

@Ghabry

Ghabry Mar 12, 2016

Member

The return value must be negated (return a negative value for damage currently)

}
void Game_Battler::RemoveBattleStates() {
std::vector<int16_t>& states = GetStates();
View
@@ -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
@@ -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) {
@@ -532,6 +532,15 @@ bool Scene_Battle_Rpg2k3::ProcessBattleAction(Game_BattleAlgorithm::AlgorithmBas
if (action->IsFirstAttack() && action->GetStartSe()) {
Game_System::SePlay(*action->GetStartSe());

This comment has been minimized.

@Ghabry

Ghabry Mar 12, 2016

Member

The damageTaken codepath depends on action->GetStartSe()

@Ghabry

Ghabry Mar 12, 2016

Member

The damageTaken codepath depends on 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);
}
}

This comment has been minimized.

@Ghabry

Ghabry Mar 12, 2016

Member

Everytime anybody does his turn all allies and enemies get state heal/damage. So should be something like this:

std::vector<Game_Battler*> battlers;
Main_Data::game_party->GetBattlers(battlers);
Main_Data::game_enemyparty->GetBattlers(battlers);

for (auto& b : battlers) {
  // Your damageTaken code
}
@Ghabry

Ghabry Mar 12, 2016

Member

Everytime anybody does his turn all allies and enemies get state heal/damage. So should be something like this:

std::vector<Game_Battler*> battlers;
Main_Data::game_party->GetBattlers(battlers);
Main_Data::game_enemyparty->GetBattlers(battlers);

for (auto& b : battlers) {
  // Your damageTaken code
}

This comment has been minimized.

@Tondorian

Tondorian Mar 12, 2016

Member

Oh there is also an bug in my line should be action->GetSource()->GetBattleX()
but your solution is even better

@Tondorian

Tondorian Mar 12, 2016

Member

Oh there is also an bug in my line should be action->GetSource()->GetBattleX()
but your solution is even better

battle_action_state = BattleActionState_Result;
ProTip! Use n and p to navigate between commits in a pull request.