Enemy Behavior

It isn't entirely known how enemies operate in regards to the action system. Supposedly, they are also restricted by a hidden AP value, however they are subjected to different AP costs for movement and skill activation.

Enemies seem to function according to certain recognizable patterns:

1. Enemies will always try to perform the actions dictated by their preferred behavior if possible.
	* Enemies will only remain in place if there is no other optimal location accessible to them.
	* If they can, enemies will always move according to their preferred behavior.
	* If they can, they will always attack their preferred target.
	* If while trying to reach said preferred target, an enemy stops moving in range of only non-preferred targets, the enemy will *not* engage a non-preferred target.
	* If an enemy is currently engaged with a target, it CAN disengage it to seek a preferred one. **(Needs confirmation)**
		+ An enemy engaged in combat may still also seek an optimal location that is not a target, as is the example with enemies that prefer to avoid the daughters.
2. Enemies always try to perform 2 *direct actions* (attack or movement ) per turn.
	* Only one of these 2 *direct actions* can be the Movement action.
	* If an enemy can't move to a more optimal location and has no valid attack targets in range, they will do no *direct actions*.
	* If an enemy can move to a more optimal location but stops with no valid attack targets in range, their only *direct action* was that Movement.
	* If an enemy can move to a more optimal location with valid attack targets in range, it will use both *direct actions*, one to Move and one to Attack.
	* If an enemy is at their optimal location, or cannot seek it, and has valid targets in range, it will use 1 *direct action* to Attack if the valid target is a preferred one (otherwise it will pass), then:
		+ If the enemy is still at their optimal location, or cannot seek it, and there are still valid preferred targets in range, it will Attack again with his 2nd *direct action.*
		+ If the enemy can seek a more optimal location, it will use its 2nd *direct action* to move towards it.
	* During an enemy's first turn, whether they just spawned or were originally on the map, an enemy can only perform 1 *direct action,* unless an enemy is already in range.
		+ If the enemy can move to a more optimal location, it will Move.
		+ If the enemy can't or doesn't need to move to a more optimal location and has valid targets in range, it will Attack.
		+ If the enemy can't or doesn't need to move to a more optimal location and has no valid attack targets in range, it will perform no *direct actions*.
		+ The Infected and Infested are an exception to this rule as they may Spawn, move, and attack in the same turn. This is because their ranged attacks (Ranged Destruction and Ranged Disruption, respectively) are coded as debuffs, and therefore count as *indirect actions*.
3. Enemies can perform up to 2 *indirect actions* (Buffs, Debuffs, delayed actions, traversal actions, reactions, interruptions, summons) per turn **in addition** to the standard 2 *direct actions*.
	* Only one of these can be a Buff, such as an ability that grants armor or health to another unit.
	* As happens with the Attacks, an enemy will always attempt to move to an optimal location before performing an indirect action.
	* An enemy will always perform their indirect actions if/when the necessary conditions are met (target, conditions, resources, location, proximity, etc).
4. Bosses are also subjected to rules 1~4 **(Needs Confirmation)**

## SImple Movement and Attack Zones

The following statements assume a melee enemy's preferred target positioning on the map relative to that enemy.

* Ending a unit's turn inside or adjacently (orthogonal touching) to a tile the enemy can reach will result in the enemy moving to the tile nearest the unit and attacking it.
* Ending a unit's turn 2 otrhogonal or diagonal tiles away from the last tile an enemy can reach is always safe from a standard melee attack.
* Ending a unit's turn 1 diagonal tile away from the last tile an enemy can reach, will result in the enemy moving to it and attacking the unit if doing so does not expend more AP than the enemy currently has, otherwise the enemy will move and stop 2 tiles away from the unit.

## Notes

1. When a codex description mentions an enemy targeting a unit with most or least Health, the stat being referred to is Percentage Health (%HP), not Maximum Health, not Current Health. This means that an enemy going after the unit with most health may target a Soulslinger with 500 (100%) HP instead of a Shieldbearer with 650 (90%) HP.