AI (XC2)

The of Xenoblade Chronicles 2 and Torna ~ The Golden Country uses AI to determine party member and behaviour. Each playable character besides the player-controlled one, and each enemy, uses a script which sets their current action (possibly probabilistically) depending upon the current state of battle.
==Overview==
Each playable character has their own AI behaviour which often differs from that of other playable characters. Multiple enemies often share the same AI script. However, two enemies may have different behaviour even when using the same script, e.g. if it has instructions that are conditional on the user's .
AI determines the user's movement (including where and when they position themselves around their opponent, and when they run to pick up HP Potions), their use of Driver Arts/Vanguard Arts/s, and when they perform Blade Switches/Vanguard Switches. It does not affect party member use of s, which are fully controlled by the player both in and out of s.
While each party member has a given AI script, the exact actions the script instructs them to take are dependent upon many factors:
* The the character is currently using, and (if relevant) the Driver Arts they have equipped;
* The character's current , that of their allies, and that of the enemy;
* Whether the character is currently in the window of an ;
* The distance between the character and the enemy, and whether they are at the enemy's front, side, or back;
* The status of any Driver Combos or Blade Combos on the enemy;
* The number of enemies in battle, and the number which are currently ing the character;
* The of the character.
==Example==
The full AI scripts are complicated and not easy to display. The following is an example of a small section of 's AI, written in pseudocode: how he decides which Driver Art to use when wielding the Aegis Sword.
if Rex's HP is below 50% AND enemy's HP is above 15% AND Rex has aggro:
	AggroRisk = True
else:
	AggroRisk = False
if enemy is suffering from Break and Anchor Shot is available:
	use Anchor Shot
else if any party member is below 50% HP and Anchor Shot is available:
	30% probability to use Anchor Shot
else if AggroRisk = False and Rolling Smash is available:
	50% probability to use Rolling Smash
else if Rex is at enemy's back, AggroRisk = False, and Sword Bash is available:
	use Sword Bash
else if Sword Bash is available:
	10% probability to use Sword Bash
else if Rex is at enemy's side, AggroRisk = False, and Double Spinning Edge is available:
	use Double Spinning Edge
else if Double Spinning Edge is available:
	10% probability to use Double Spinning Edge
==Party member AI==
===Blade Switching===
The priority with which AI-controlled Drivers in Xenoblade Chronicles 2 switch between s is as follows.
Drivers with a with " Blade switch AI" (i.e. those with at least two Blades, of which at least 50% are HLR role) will switch to (or stay on) a Blade with a healing Art when any party member is below 30% .
Otherwise, Drivers will switch to prioritise Blade Combos and/or Driver Combos. The following are aspects which can potentially cause a Driver to choose a particular Blade over another:
* Driver Combo: The chosen Blade can continue the current Driver Combo, or start one if none is active. This takes into account enemy immunities. Active Blades do not count if the Driver Combo-inflicting Art is less than 70% recharged.
* Direct Blade Combo: The chosen Blade is of an which can immediately continue the current Blade Combo.
* Indirect Blade Combo: The chosen Blade is of an element which cannot immediately continue the current Blade Combo, but may be able to later if the combo advances in an appropriate way. This applies to all Blades if no Blade Combo is active.
* New Blade Combo: The chosen Blade is of an element which can continue a Blade Combo via a path such that the resulting element orb is not already on the enemy.
* Old Blade Combo: The chosen Blade is of an element which can only continue the Blade Combo down a path that repeats an element orb currently on the enemy.
* Cooldown: The chosen Blade is not the current Blade, and the current Blade has all Driver Arts on cooldown.
* Time: The chosen Blade is not the current Blade, and the current Blade has been active for at least 15 seconds. (The check has a 1% chance to be acted upon every second.)
* Slot: The chosen Blade is in a lower slot of the Equip Blades menu.
Male Drivers (, , and ) use the following priority system, switching to whatever Blade satisfies the highest condition (or the next-highest in case of a tie, and so on):
# New direct Blade Combo AND Driver Combo
# Old direct Blade Combo AND Driver Combo
# Driver Combo
# New direct Blade Combo
# Cooldown
# Old direct Blade Combo
# Time
# New indirect Blade Combo
# Old indirect Blade Combo
# Slot
Female Drivers ( and ) use the following priority system:
# New direct Blade Combo AND Driver Combo
# New direct Blade Combo
# Old direct Blade Combo AND Driver Combo
# Old direct Blade Combo
# New indirect Blade Combo
# Old indirect Blade Combo
# Cooldown
# Driver Combo
# Time
# Slot
In short: Female Drivers prioritise switching for Blade Combos, and male Drivers prioritise switching for Driver Combos.
===Other notes===
* 's AI has him use most Arts with 50% probability. This includes all of his Driver Combo Arts; therefore, while he will always switch to a Poppi form which can continue a Driver Combo (due to the Blade Switching priorities given above), there is no way to guarantee that he will actually use the relevant Driver Art to continue the combo if he is not being player-controlled.
* When equipped with any -restricted s aside from , AI party members will use the Driver Arts in order of the buttons they are assigned to (X -> Y -> B), overriding any other AI order such as Driver Combo precedence.
* In Torna ~ The Golden Country, holding the R button brings up options which affect the AI party member behaviour, which are selected via the D-pad (for example, R and D-pad up has all party members target the enemy targeted by the player-controlled character). The options corresponding to D-pad left and right are assumed to have been intended to control whether the AI focuses on Driver Combos or Blade Combos, due to their icons. However, they do not affect this, and are believed to have no effect at all.
==Enemy AI==
Category:Battle mechanics (XC2)Category:Battle mechanics (TTGC)