Skip to content
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

Albeleon's Battle Fixes 2 of N #1448

Merged
merged 16 commits into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
2713cae
"3.9: RM2000: If an absorb skill doesn't take anything, it automatica…
Albeleon Jun 23, 2018
b941b60
"4.10: RM2000: If a technique misses, it doesn't generate EVASION sou…
Albeleon Jun 23, 2018
506d9f3
"4.11: RM2000: If you keep CANCEL pressed while in State_Battle, the …
Albeleon Jun 23, 2018
bc40101
2.6 + 3.7
Albeleon Jun 23, 2018
9be1f65
"2.23: RM2000 + RM2003: When screen shakes in a battle, the borders s…
Albeleon Jun 24, 2018
7278e7c
"2.25: RM2000: Skills and items that affect whole groups should only …
Albeleon Jun 29, 2018
956d66f
"2.26: RM2000 + RM2003: When calculating an actor's state probability…
Albeleon Jul 4, 2018
5b84c36
"2.27: RM2000 + RM2003: If all the player party is in a state that ha…
Albeleon Jul 4, 2018
aa17110
"2.31: RM2000: Items that miss shouldn't print any message at all."
Albeleon Jul 4, 2018
1605f7c
"2.38: RM2000 + RM2003: Skills with physical attributes can only be t…
Albeleon Jul 6, 2018
cbd34e9
"2.39: RM2000 + RM2003: Half Cost SP is always rounded to the ceil nu…
Albeleon Jul 6, 2018
6c3a01c
"3.12: RM2000 + RM2003: Protection equipment against an element shoul…
Albeleon Jul 7, 2018
eb8a6ec
"3.14: RM2000 + RM2003: After a battle is over, heal all the states t…
Albeleon Jul 7, 2018
a0fcb1b
"4.13: RM2000: If you keep pressed DECISION while in State_Battle, th…
Albeleon Jul 7, 2018
d38d6e5
Not show EXP line in victory message if there wasn't.
Albeleon Jul 16, 2018
d8445c4
Make an "All enemy" attack not affect hidden enemies.
Albeleon Jul 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions src/game_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,13 @@ bool Game_Actor::IsSkillUsable(int skill_id) const {
for (size_t i = 0; i < skill->attribute_effects.size(); ++i) {
bool required = skill->attribute_effects[i] && Data::attributes[i].type == RPG::Attribute::Type_physical;
if (required) {
if (item && i < item->attribute_set.size()) {
if (!item->attribute_set[i]) {
return false;
}
} else if (item2 && i < item2->attribute_set.size()) {
if (!item2->attribute_set[i]) {
return false;
}
} else {
return false;
if (item && i < item->attribute_set.size() && item->attribute_set[i]) {
continue;
}
if (item2 && i < item2->attribute_set.size() && item2->attribute_set[i]) {
continue;
}
return false;
}
}

Expand All @@ -190,7 +186,7 @@ int Game_Actor::GetSpCostModifier() const {
}

int Game_Actor::CalculateSkillCost(int skill_id) const {
return Game_Battler::CalculateSkillCost(skill_id) / GetSpCostModifier();
return std::ceil(Game_Battler::CalculateSkillCost(skill_id) / (float) GetSpCostModifier());
}

bool Game_Actor::LearnSkill(int skill_id) {
Expand Down Expand Up @@ -573,15 +569,25 @@ int Game_Actor::GetNextExp(int level) const {
}

int Game_Actor::GetStateProbability(int state_id) const {
int rate = 2; // C - default
int rate = 2, mul = 100; // C - default

const uint8_t* r = ReaderUtil::GetElement(GetActor().state_ranks, state_id);
if (r) {
rate = *r;
}

// This takes the armor of the character with the most resistance for that particular state
for (const auto equipment : GetWholeEquipment()) {
RPG::Item* item = ReaderUtil::GetElement(Data::items, equipment);
if (item != nullptr && (item->type == RPG::Item::Type_shield || item->type == RPG::Item::Type_armor
|| item->type == RPG::Item::Type_helmet || item->type == RPG::Item::Type_accessory)
&& state_id <= item->state_set.size() && item->state_set[state_id - 1]) {
mul = std::min(mul, 100 - item->state_chance);
}
}

// GetStateRate verifies the state_id
return GetStateRate(state_id, rate);
return GetStateRate(state_id, rate) * mul / 100;
}

int Game_Actor::GetAttributeModifier(int attribute_id) const {
Expand All @@ -602,6 +608,16 @@ int Game_Actor::GetAttributeModifier(int attribute_id) const {
}

rate += *shift;
for (auto id_object : GetWholeEquipment()) {
RPG::Item *object = ReaderUtil::GetElement(Data::items, id_object);
if (object != nullptr && (object->type == RPG::Item::Type_shield || object->type == RPG::Item::Type_armor
|| object->type == RPG::Item::Type_helmet || object->type == RPG::Item::Type_accessory)
&& object->attribute_set.size() >= attribute_id && object->attribute_set[attribute_id - 1]) {
rate++;
break;
}
}

if (rate < 0) {
rate = 0;
} else if (rate > 4) {
Expand Down
21 changes: 20 additions & 1 deletion src/game_battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,26 @@ bool Game_Battle::CheckWin() {
}

bool Game_Battle::CheckLose() {
return !Main_Data::game_party->IsAnyActive();
if (!Main_Data::game_party->IsAnyActive())
return true;

// If there are active characters, but all of them are in a state with Restriction "Do Nothing" and 0% recovery probability, it's game over
// Physical recovery doesn't matter in this case
int character_number = 0;
std::vector<Game_Battler*> actors;

Main_Data::game_party->GetActiveBattlers(actors);
for (auto actor : actors) {
for (auto id_state : actor->GetInflictedStates()) {
RPG::State *state = ReaderUtil::GetElement(Data::states, id_state);
if (state->restriction == RPG::State::Restriction_do_nothing && state->auto_release_prob == 0) {
++character_number;
break;
}
}
}

return character_number == actors.size();
}

Spriteset_Battle& Game_Battle::GetSpriteset() {
Expand Down
37 changes: 23 additions & 14 deletions src/game_battlealgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,12 @@ void Game_BattleAlgorithm::AlgorithmBase::GetResultMessages(std::vector<std::str
}
}
}

// If enemy is killed, it ends here
if (killed_by_attack_damage) {
out.push_back(GetDeathMessage());
return;
}
}

if (GetAffectedSp() != -1) {
Expand Down Expand Up @@ -635,7 +641,7 @@ bool Game_BattleAlgorithm::AlgorithmBase::IsTargetValid() const {
return false;
}

return (!GetTarget()->IsDead());
return GetTarget()->Exists();
mateofio marked this conversation as resolved.
Show resolved Hide resolved
}

int Game_BattleAlgorithm::AlgorithmBase::GetSourceAnimationState() const {
Expand Down Expand Up @@ -843,7 +849,7 @@ void Game_BattleAlgorithm::Normal::Apply() {
Game_Actor* src = static_cast<Game_Actor*>(source);
const RPG::Item* weapon = ReaderUtil::GetElement(Data::items, src->GetWeaponId());
if (weapon) {
source->ChangeSp(-weapon->sp_cost / src->GetSpCostModifier());
source->ChangeSp(std::ceil(-weapon->sp_cost / (float) src->GetSpCostModifier()));
}
}
}
Expand Down Expand Up @@ -1021,8 +1027,12 @@ bool Game_BattleAlgorithm::Skill::Execute() {

this->success = (GetAffectedHp() != -1 && !IsAbsorb()) || (GetAffectedHp() > 0 && IsAbsorb()) || GetAffectedSp() > 0 || GetAffectedAttack() > 0
|| GetAffectedDefense() > 0 || GetAffectedSpirit() > 0 || GetAffectedAgility() > 0;

if (IsAbsorb() && !success)
return this->success;
}

// Conditions:
for (int i = 0; i < (int) skill.state_effects.size(); i++) {
if (!skill.state_effects[i])
continue;
Expand All @@ -1044,23 +1054,17 @@ bool Game_BattleAlgorithm::Skill::Execute() {
assert(false && "Unsupported skill type");
}

if (IsAbsorb() && sp != -1) {
if (GetTarget()->GetSp() == 0) {
this->success = false;
}
}

return this->success;
}

void Game_BattleAlgorithm::Skill::Apply() {
AlgorithmBase::Apply();

if (item) {
Main_Data::game_party->ConsumeItemUse(item->ID);
}
else {
if (first_attack) {
if (IsFirstAttack()) {
if (item) {
Main_Data::game_party->ConsumeItemUse(item->ID);
}
else {
source->ChangeSp(-source->CalculateSkillCost(skill.ID));
}
}
Expand Down Expand Up @@ -1129,6 +1133,10 @@ const RPG::Sound* Game_BattleAlgorithm::Skill::GetStartSe() const {
}
}

const RPG::Sound* Game_BattleAlgorithm::Skill::GetResultSe() const {
return !success && skill.failure_message != 3 ? NULL : AlgorithmBase::GetResultSe();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This magic number should probably be resolved to some SkillFailureMessage_Physical in the future.

}

void Game_BattleAlgorithm::Skill::GetResultMessages(std::vector<std::string>& out) const {
if (!success) {
switch (skill.failure_message) {
Expand Down Expand Up @@ -1304,7 +1312,8 @@ int Game_BattleAlgorithm::Item::GetSourceAnimationState() const {
}

void Game_BattleAlgorithm::Item::GetResultMessages(std::vector<std::string>& out) const {
AlgorithmBase::GetResultMessages(out);
if (success)
AlgorithmBase::GetResultMessages(out);
}

const RPG::Sound* Game_BattleAlgorithm::Item::GetStartSe() const {
Expand Down
1 change: 1 addition & 0 deletions src/game_battlealgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ class Skill : public AlgorithmBase {
std::string GetStartMessage() const override;
int GetSourceAnimationState() const override;
const RPG::Sound* GetStartSe() const override;
const RPG::Sound* GetResultSe() const override;
void GetResultMessages(std::vector<std::string>& out) const override;
int GetPhysicalDamageRate() const override;
bool IsReflected() const override;
Expand Down
6 changes: 3 additions & 3 deletions src/game_battler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,11 @@ void Game_Battler::RemoveBattleStates() {
// If death is non-permanent change HP to 1
if (IsDead() &&
non_permanent(1)) {
ChangeHp(1);
RemoveState(1);
}

for (size_t i = 0; i < states.size(); ++i) {
if (non_permanent(i + 1)) {
for (size_t i = 1; i < states.size(); ++i) {
if (non_permanent(i + 1) || ReaderUtil::GetElement(Data::states, i + 1)->auto_release_prob > 0) {
states[i] = 0;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/scene_battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ void Scene_Battle::TransitionOut() {
}
}

void Scene_Battle::DrawBackground() {
DisplayUi->CleanDisplay();
}

void Scene_Battle::CreateUi() {
std::vector<std::string> commands;
commands.push_back(Data::terms.battle_fight);
Expand Down
1 change: 1 addition & 0 deletions src/scene_battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Scene_Battle : public Scene {

void TransitionIn() override;
void TransitionOut() override;
void DrawBackground() override;

enum State {
/** Battle has started (Display encounter message) */
Expand Down
25 changes: 21 additions & 4 deletions src/scene_battle_rpg2k.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,11 @@ bool Scene_Battle_Rpg2k::ProcessBattleAction(Game_BattleAlgorithm::AlgorithmBase
Sprite_Battler* source_sprite;
Sprite_Battler* target_sprite;

if (battle_action_wait) {
if (Input::IsPressed(Input::DECISION)) {
--battle_action_wait;
}

if (battle_action_wait > 0) {
if (--battle_action_wait) {
return false;
}
Expand All @@ -362,6 +366,10 @@ bool Scene_Battle_Rpg2k::ProcessBattleAction(Game_BattleAlgorithm::AlgorithmBase
}
}

if (Input::IsPressed(Input::CANCEL)) {
return false;
}
mateofio marked this conversation as resolved.
Show resolved Hide resolved

switch (battle_action_state) {
case BattleActionState_Start:
battle_action_wait = GetDelayForWindow();
Expand Down Expand Up @@ -539,8 +547,7 @@ void Scene_Battle_Rpg2k::ProcessInput() {
if (Input::IsTriggered(Input::DECISION)) {
switch (state) {
case State_Start:
// Skip current message
encounter_message_sleep_until = Player::GetFrames();
// no-op
break;
case State_SelectOption:
// Interpreter message boxes pop up in this state
Expand Down Expand Up @@ -686,6 +693,10 @@ void Scene_Battle_Rpg2k::Escape() {
begin_escape = false;
}
else {
if (Input::IsPressed(Input::DECISION)) {
++escape_counter;
}

++escape_counter;

if (escape_counter > 60) {
Expand Down Expand Up @@ -874,6 +885,10 @@ bool Scene_Battle_Rpg2k::DisplayMonstersInMessageWindow() {
encounter_message_first_monster = false;
}

if (Input::IsPressed(Input::DECISION)) {
--encounter_message_sleep_until;
}

if (encounter_message_sleep_until > -1) {
if (Player::GetFrames() >= encounter_message_sleep_until) {
// Sleep over
Expand Down Expand Up @@ -1000,7 +1015,9 @@ bool Scene_Battle_Rpg2k::CheckWin() {
Game_Message::texts.push_back(Data::terms.victory + Player::escape_symbol + "|");

std::stringstream ss;
PushExperienceGainedMessage(exp);
if (exp > 0) {
PushExperienceGainedMessage(exp);
}
if (money > 0) {
PushGoldReceivedMessage(money);
}
Expand Down
6 changes: 4 additions & 2 deletions src/scene_battle_rpg2k3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,8 +983,10 @@ bool Scene_Battle_Rpg2k3::CheckWin() {
std::string space = Player::IsRPG2k3E() ? " " : "";

std::stringstream ss;
ss << exp << space << Data::terms.exp_received;
Game_Message::texts.push_back(ss.str());
if (exp > 0) {
ss << exp << space << Data::terms.exp_received;
Game_Message::texts.push_back(ss.str());
}
if (money > 0) {
ss.str("");
ss << Data::terms.gold_recieved_a << " " << money << Data::terms.gold << Data::terms.gold_recieved_b;
Expand Down