| 216 | } |
| 217 | |
| 218 | bool 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 | |
| 267 | static bool IsSkillEffectiveOnAnyTarget(Game_Enemy& source, int skill_id, bool emulate_bugs) { |
| 268 | const auto* skill = lcf::ReaderUtil::GetElement(lcf::Data::skills, skill_id); |
no test coverage detected