MCPcopy Create free account
hub / github.com/EasyRPG/Player / IsActionValid

Function IsActionValid

src/enemyai.cpp:218–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

216}
217
218bool IsActionValid(const Game_Enemy& source, const lcf::rpg::EnemyAction& action) {
219 if (action.kind == action.Kind_skill) {
220 if (!source.IsSkillUsable(action.skill_id)) {
221 return false;
222 }
223 }
224
225 switch (action.condition_type) {
226 case lcf::rpg::EnemyAction::ConditionType_always:
227 return true;
228 case lcf::rpg::EnemyAction::ConditionType_switch:
229 return Main_Data::game_switches->Get(action.switch_id);
230 case lcf::rpg::EnemyAction::ConditionType_turn:
231 {
232 int turns = Game_Battle::GetTurn();
233 return Game_Battle::CheckTurns(turns, action.condition_param2, action.condition_param1);
234 }
235 case lcf::rpg::EnemyAction::ConditionType_actors:
236 {
237 std::vector<Game_Battler*> battlers;
238 Main_Data::game_enemyparty->GetActiveBattlers(battlers);
239 int count = (int)battlers.size();
240 return count >= action.condition_param1 && count <= action.condition_param2;
241 }
242 case lcf::rpg::EnemyAction::ConditionType_hp:
243 {
244 int hp_percent = source.GetHp() * 100 / source.GetMaxHp();
245 return hp_percent >= action.condition_param1 && hp_percent <= action.condition_param2;
246 }
247 case lcf::rpg::EnemyAction::ConditionType_sp:
248 {
249 int sp_percent = source.GetSp() * 100 / source.GetMaxSp();
250 return sp_percent >= action.condition_param1 && sp_percent <= action.condition_param2;
251 }
252 case lcf::rpg::EnemyAction::ConditionType_party_lvl:
253 {
254 int party_lvl = Main_Data::game_party->GetAverageLevel();
255 return party_lvl >= action.condition_param1 && party_lvl <= action.condition_param2;
256 }
257 case lcf::rpg::EnemyAction::ConditionType_party_fatigue:
258 {
259 int party_exh = Main_Data::game_party->GetFatigue();
260 return party_exh >= action.condition_param1 && party_exh <= action.condition_param2;
261 }
262 default:
263 return true;
264 }
265}
266
267static bool IsSkillEffectiveOnAnyTarget(Game_Enemy& source, int skill_id, bool emulate_bugs) {
268 const auto* skill = lcf::ReaderUtil::GetElement(lcf::Data::skills, skill_id);

Callers 1

Calls 10

GetActiveBattlersMethod · 0.80
GetMaxHpMethod · 0.80
GetMaxSpMethod · 0.80
GetAverageLevelMethod · 0.80
GetFatigueMethod · 0.80
IsSkillUsableMethod · 0.45
GetMethod · 0.45
sizeMethod · 0.45
GetHpMethod · 0.45
GetSpMethod · 0.45

Tested by

no test coverage detected