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

Refactor Skill and Item usability and fix some incompatibilities #2380

Merged
merged 5 commits into from
Oct 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
12 changes: 12 additions & 0 deletions src/algo.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <lcf/rpg/fwd.h>
#include <lcf/rpg/system.h>
#include <lcf/rpg/saveactor.h>
#include <lcf/rpg/skill.h>
#include "game_battler.h"

class Game_Actor;
Expand Down Expand Up @@ -191,6 +192,17 @@ int CalcSkillCost(const lcf::rpg::Skill& skill, int max_sp, bool half_sp_cost);
bool IsSkillUsable(const lcf::rpg::Skill& skill,
bool require_states_persist);

/**
* Checks if the skill is a normal or subskill type.
*
* @param skill the skill to check
* @return true if a normal skill or a 2k3 subskill.
*/
inline bool IsNormalOrSubskill(const lcf::rpg::Skill& skill) {
return skill.type == lcf::rpg::Skill::Type_normal
|| skill.type >= lcf::rpg::Skill::Type_subskill;
}

} // namespace Algo


Expand Down
20 changes: 15 additions & 5 deletions src/game_party.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,6 @@ bool Game_Party::IsItemUsable(int item_id, const Game_Actor* target) const {
return false;
}

if (data.party.size() == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Does removing of this check have any practical use? You can't open the item scene in the menu when the party is empty and there is no event command to use items.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe not, but having it has no practical use either. It wasn't in RPG_RT so I took it out.

return false;
}

const auto* skill = lcf::ReaderUtil::GetElement(lcf::Data::skills, item->skill_id);
const bool in_battle = Game_Battle::IsBattleRunning();

Expand All @@ -280,7 +276,21 @@ bool Game_Party::IsItemUsable(int item_id, const Game_Actor* target) const {
case lcf::rpg::Item::Type_switch:
return in_battle ? item->occasion_battle : item->occasion_field2;
case lcf::rpg::Item::Type_special:
return skill && Algo::IsSkillUsable(*skill, false);
if (skill && Algo::IsSkillUsable(*skill, false)) {
// RPG_RT requires one actor in the party and alive who can use the item.
// But only if the item invokes a normal or subskill. This check is
// not performed for escape, teleport, or switch skills!
if (!Algo::IsNormalOrSubskill(*skill)) {
return true;
} else {
for (auto* actor: GetActors()) {
if (actor->CanAct() && actor->IsItemUsable(item_id)) {
return true;
}
}
}
}
return false;
default:
break;
}
Expand Down