Conditions in Battles #815

Merged
merged 10 commits into from Mar 14, 2016

Projects

None yet

4 participants

@Tondorian
Contributor

Conditions are applied to battle_actors now.
GainMoneyMessage only shown if money >0

I only tested it with rpg Maker 2k but should work on 2k3...

@Tondorian Tondorian Conditions are applied to battle_actors now.
GainMoneyMessage only shown if money >0
eaab481
@carstene1ns carstene1ns and 1 other commented on an outdated diff Mar 12, 2016
src/game_battlealgorithm.cpp
@@ -312,6 +312,21 @@ 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();
@carstene1ns
carstene1ns Mar 12, 2016 Member

Stray spaces detected.

@Tondorian
Tondorian Mar 12, 2016 Contributor

Should be fixed

@Tondorian Tondorian Condition Messages are only shown if there is a message
f75f9b4
@Ghabry
Member
Ghabry commented Mar 12, 2016

Jenkins: Test this please

@Ghabry
Member
Ghabry commented Mar 12, 2016

One reason speaking against ::Apply is that under RPG2k3 all actors get damage at the begin of a battle action (doesn't matter if ally or enemy). With Apply only the current one doing the action gets damage.

I suggest moving this to a function in Game_Battler and when invoking that function it directly alters SP and MP of that Battler.

For RPG2k you can place the call in ... maybe BattleActionState_ConditionHeal (for the FirstAttack case)

So for RPG2k3 I suggest placing the call to this function (and displaying the damage number (for HP only!) as a floating number) in the BattleActionState_Start for the "IsFirstAttack" case.

The RPG2k3 battle system also shows that damaging due to states happens before the action is executed.

@Tondorian
Contributor

git commit --amend failed again 👎

@Ghabry
Member
Ghabry commented Mar 12, 2016

git reset HEAD~1 :D should work

Because you use Windows you should consider tortoise git

@Tondorian Tondorian Move ContitionAplliying into Game_Battler.cpp
RPG_RT2k3 should show damage numbers now
97ee082
@Ghabry
Member
Ghabry commented Mar 12, 2016

Jenkins: Test this please

@Ghabry Ghabry commented on an outdated diff Mar 12, 2016
src/scene_battle_rpg2k3.cpp
@@ -532,6 +532,15 @@ bool Scene_Battle_Rpg2k3::ProcessBattleAction(Game_BattleAlgorithm::AlgorithmBas
if (action->IsFirstAttack() && action->GetStartSe()) {
Game_System::SePlay(*action->GetStartSe());
@Ghabry
Ghabry Mar 12, 2016 Member

The damageTaken codepath depends on action->GetStartSe()

@Ghabry Ghabry and 1 other commented on an outdated diff Mar 12, 2016
src/scene_battle_rpg2k3.cpp
@@ -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);
+ }
}
@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
}
@Tondorian
Tondorian Mar 12, 2016 Contributor

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

@Ghabry Ghabry commented on an outdated diff Mar 12, 2016
src/game_battler.cpp
@@ -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]];
@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 commented on an outdated diff Mar 12, 2016
src/game_battler.cpp
@@ -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;
@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 and 1 other commented on an outdated diff Mar 12, 2016
src/game_battler.cpp
+ 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);
+ }
@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.

@Tondorian
Tondorian Mar 12, 2016 Contributor

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

@Ghabry
Ghabry Mar 12, 2016 Member

Yeah, 0 change

@Ghabry Ghabry commented on an outdated diff Mar 12, 2016
src/game_battler.cpp
+ }
+ 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;
@Ghabry
Ghabry Mar 12, 2016 Member

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

@Ghabry
Member
Ghabry commented Mar 12, 2016

Test case for RPG Maker 2003 (add a RPG_RT.exe):
BattleTest with Monster Party 2.

rpg2k3 testcase.zip

Command Line for Player: "BattleTest 2"

@Ghabry
Member
Ghabry commented Mar 12, 2016

Test case for RPG Maker 2000
BattleTest with Monster Party 1.

rpg2k battletest.zip

@Ghabry Ghabry commented on the diff Mar 12, 2016
src/scene_battle_rpg2k.cpp
return false;
}
// Reset variables
- battle_action_state = BattleActionState_Start;
+ battle_action_state = BattleActionState_ConditionHeal;
@Ghabry
Ghabry Mar 12, 2016 Member

You changed all the battle_action_state transitions. This is super super risky, pls don't do this unless you are 100% certain this is required. Because this must be tested with every available battle action available (Normal, different items, different skills, defend) to proof that it doesn't break anything or added a subtil bug.

One problem I already noticed is, that you introduced some delay before everybodys turn.

@Tondorian
Tondorian Mar 12, 2016 Contributor

Yeah i needed to change them to get poisen effect working before the battlers attack.
think need to double check, if waiting is needed

@Ghabry
Ghabry Mar 12, 2016 Member

I reverted all the state changes and I only took your code from line 370 to 388 and it still works fine for me.

@Tondorian
Tondorian Mar 12, 2016 Contributor

so it shows conditioneffct, Clean enemyAttacks, Damage clean to you?
Takes me 2h yesterday to get it shown correct

@Ghabry
Ghabry Mar 12, 2016 Member

In my tests your state changes broke the message box. At the beginning it shows an empty message box with a delay and between battle actions, too.

And after an enemy finished his battle animation the delay got removed.

@Tondorian Tondorian RPG2k3 everybody get damages if anyone does his turn
RPG2k Message Delay fixed
Cleanup ConditionApply() and fixed damage calculation
4e501f6
@Ghabry

The damage applying is still depending on "action->GetStartSe()".

@Ghabry
Member
Ghabry commented Mar 13, 2016

The delay is still wrong here.

Normal attacks without any states have a 30 frame delay before anything happens -> Must be 0.

And after battle animations the feedback is now instant instead of a delay. (After showing the attack animation, e.g. the sword slash, the old version had a 30 frame delay).

And sometimes enemy attacks give me now a negative amount and heal me :O

Tondorian added some commits Mar 13, 2016
@Tondorian Tondorian [rpg20k3] damage applying does not depend on action->GetStartSe() any…
…more
2e30257
@Tondorian Tondorian [rpg2k] fixed delaying issue
78ca22a
@Tondorian
Contributor

I think it should work as expected now
if you can confirm, i'll clean up my branch

@Ghabry
Member
Ghabry commented Mar 13, 2016

I will prepare an emscripten test case for both battle systems this evening.
Then it's easier to verify this (also for future pull requests).

But I think you are getting closer now :D

@Ghabry Ghabry added this to the 0.4.1 milestone Mar 13, 2016
@Tondorian Tondorian added missing include
fix another timing error
1933224
@Ghabry
Member
Ghabry commented Mar 14, 2016

Jenkins: Test this please

@fdelapena Maybe we should whitelist him ;)

@Tondorian
Contributor

And sometimes enemy attacks give me now a negative amount and heal me :O

See this on your Emscripten Testcase first time
I think i did not change anything on this part game_battlealgoithm.cpp

@fdelapena
Member

@fdelapena Maybe we should whitelist him ;)

Done!

I think i did not change anything on this part game_battlealgoithm.cpp

Yeah, Ghabry commented on IRC this also happens with the current upstream master version.

@Tondorian
Contributor

but i messed up dead enemys in rpg2k3 :D if they are dead they get 1hp ^^
will fix this part now

@Tondorian Tondorian Dead Battlers stay Dead now
970810d
@Ghabry
Member
Ghabry commented Mar 14, 2016

Okay, looks fine now. The negative HP after attacks and poison are strange but this already happens in Master... :(.
@Tondorian Is the PR ready?

@Tondorian Tondorian should fix negativ Damage on attack and condition appyement
a9fdd28
@Ghabry

This change is not required. When effect is set to 0, the change equation will be 0, too.

@Ghabry
Member
Ghabry commented Mar 14, 2016

The problem for that "-5" is the skill damage code in Game_BattleAlgorithm::Skill::Execute()

We need a "effect < 0 -> = 0" check before the line with rand().

@Tondorian Tondorian Fixed more damage <0 bugs
95e8532
@Ghabry Ghabry merged commit 118e900 into EasyRPG:master Mar 14, 2016

5 checks passed

Android Build finished.
Details
Linux Build finished.
Details
OSX Build finished.
Details
Windows Build finished.
Details
web Build finished.
Details
@Tondorian Tondorian deleted the Tondorian:mergeRequest branch Mar 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment