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

Function SelectAutoBattleAction

src/autobattle.cpp:279–373  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

277}
278
279void SelectAutoBattleAction(Game_Actor& source,
280 Game_Battler::Weapon weapon,
281 lcf::rpg::System::BattleCondition cond,
282 bool do_skills,
283 bool attack_variance,
284 bool skill_variance,
285 bool emulate_bugs)
286{
287 double skill_rank = 0.0;
288 lcf::rpg::Skill* skill = nullptr;
289
290 // Find the highest ranking skill
291 if (do_skills) {
292 for (auto& skill_id: source.GetSkills()) {
293 auto* candidate_skill = lcf::ReaderUtil::GetElement(lcf::Data::skills, skill_id);
294 if (candidate_skill) {
295 const auto rank = CalcSkillAutoBattleRank(source, *candidate_skill, cond, skill_variance, emulate_bugs);
296 DebugLog("AUTOBATTLE: Actor {} Check Skill Rank : {}({}): {}", source.GetName(), candidate_skill->name, candidate_skill->ID, rank);
297 if (rank > skill_rank) {
298 skill_rank = rank;
299 skill = candidate_skill;
300 }
301 }
302 }
303 DebugLog("AUTOBATTLE: Actor {} Best Skill Rank : {}({}): {}", source.GetName(), skill ? skill->name : "None", skill ? skill->ID : 0, skill_rank);
304 }
305
306 double normal_attack_rank = CalcNormalAttackAutoBattleRank(source, weapon, cond, attack_variance, emulate_bugs);
307 DebugLog("AUTOBATTLE: Actor {} Normal Attack Rank : {}", source.GetName(), normal_attack_rank);
308
309 auto best_target_rank = 0.0;
310 Game_Battler* best_target = nullptr;
311 std::vector<Game_Battler*> targets;
312
313 if (skill != nullptr && normal_attack_rank < skill_rank) {
314 // Choose Skill Target
315 switch (skill->scope) {
316 case lcf::rpg::Skill::Scope_enemies:
317 DebugLog("AUTOBATTLE: Actor {} Select Skill Target : ALL ENEMIES", source.GetName());
318 source.SetBattleAlgorithm(std::make_shared<Game_BattleAlgorithm::Skill>(&source, Main_Data::game_enemyparty.get(), *skill));
319 return;
320 case lcf::rpg::Skill::Scope_party:
321 DebugLog("AUTOBATTLE: Actor {} Select Skill Target : ALL ALLIES", source.GetName());
322 source.SetBattleAlgorithm(std::make_shared<Game_BattleAlgorithm::Skill>(&source, Main_Data::game_party.get(), *skill));
323 return;
324 case lcf::rpg::Skill::Scope_enemy:
325 for (auto* target: Main_Data::game_enemyparty->GetEnemies()) {
326 const auto target_rank = CalcSkillDmgAutoBattleTargetRank(source, *target, *skill, cond, skill_variance, emulate_bugs);
327 if (target_rank > best_target_rank) {
328 best_target_rank = target_rank;
329 best_target = target;
330 }
331 }
332 break;
333 case lcf::rpg::Skill::Scope_ally:
334 for (auto* target: Main_Data::game_party->GetActors()) {
335 const auto target_rank = CalcSkillHealAutoBattleTargetRank(source, *target, *skill, cond, skill_variance, emulate_bugs);
336 if (target_rank > best_target_rank) {

Callers 2

vSetAutoBattleActionMethod · 0.85

Calls 12

CalcSkillAutoBattleRankFunction · 0.85
SetBattleAlgorithmMethod · 0.80
GetEnemiesMethod · 0.80
DebugLogFunction · 0.70
GetNameMethod · 0.45
getMethod · 0.45
GetActorsMethod · 0.45
HasAttackAllMethod · 0.45

Tested by

no test coverage detected