Combat

Combat in this game is turn-based and takes place on a grid of square tiles in isometric 2D.

## Combat actions

Characters can do 3 types of actions in a turn :

* **Main action** : Most spells, abilities and attacks fall into that category.

* **Movement** : Using the character's movement points to move to a different tile. A few movement abilities also fall into that category.

* **Quick action** : analyzing the enemy, using a consumable and some fast-casting spells or fast attacks

### Action points

Most characters have 1 Main Action point, 1 Movement point and 1 Quick Action point. Those points are refreshed when a character starts their turn. Unused points do not persist between multiple turns. Performing any of the actions above consumes the corresponding point, meaning an action of the same type cannot be performed again this turn. Some characters may obtain bonus points, or have abilities that can refresh some of them.

### Basic attack

A basic attack is an attack any character can make and counts as a Main Action. It will use the character's weapon if they're using one.

### Channeled actions

A channeled action is an action that is usually more powerful than most but also has a long wind-up time. It uses up the character's Main Action point, and ends their turn.

When a channeled action is performed, it only takes effect after a certain delay. During this delay, the character can be interrupted by being pushed back, suffering from a status effect that would normally prevent them from initiating the action, or being hit by an attack or spell that has the specific property of interrupting channeled attacks.

### Defending

If a character hasn't performed a Main Action during their turn, they can end it by Defending. It gives them a bonus to Block and allows them to get another turn faster. While a character's Main Action point hasn't been used, the End Turn button on the UI is replaced by the Defend button.

### Movement

Characters can move a number of tiles equal to their Movement attribute. This uses their Movement point regardless of the distance moved, which means that for example, a character with 5 Movement cannot move 3 tiles, then attack, then move 2 tiles.

The game provides basic pathfinding when moving from one tile to another. However, the player may wish to move to a tile by passing through specific tiles that would not be chosen by the pathfinding algorithm. The game allows that by offering a system of waypoints that the player can place along the path they wish to use, forcing the pathfinding algorithm to pass through the specified tiles.

This may allow them to avoid dangerous terrain and walking on Traps or provoking an Attack of opportunity. It can also be used to avoid being detected when hiding from other characters by staying in the shadows during movement.

### Sprinting

A character may choose to sprint, consuming both their Main Action point and their Movement point to move by up to twice their normal movement range.

If a character has already used their Movement point this turn but not their Main Action point, they can use their Main Action point to sprint.

## Turn order

Time in combat is divided in "beats", and each character gets a turn every few beats. The delay between each of a character's turns is calculated like this :

```
Base turn delay - character speed + action delay + other modifiers

```

The base turn delay is a constant value, currently 20. (not that it really matters)

Action delay is a value that can be positive or negative depending on the main action performed by the character during their turn. Some actions incur a higher turn delay, usually very powerful or channeled actions, while some others can actually let the character play faster. For example, ending your turn by Defending reduces the character's turn delay by a lot. Something like 5 I think.

Other modifiers can further alter a character's turn delay like status effects or various buffs/debuffs.

### Timeline

The game features a timeline showing the turn order for the various characters participating in a fight. Because the game has a system based on character speed and action delay, it shows a bit more detail than standard Tactical RPG timelines.

On this ugly mockup made in five minutes, the player is currently playing the turn of the red character. The character's turn is happening on beat 30; most characters have already played a few times in this fight.

The player has selected an action that brings the total turn delay for the red character to 10, setting them up to play again on beat 40, right before the blue character on beat 41 and a bit after the green character on beat 37.

If the player selected a slower action, their turn delay may increase and set them up to play between the blue and the purple character, or maybe even after the gray character.

## Character direction

When they're on the battlefield characters can look in four different directions, as the game functions on a square grid. This has an impact on a few things:

* **Vision**: While a character's line of sight is not affected (as in they can see all around them) by the direction they're looking in, their vision is considered to be better in the direction they're looking. This has an impact for the Stealth mechanic.
* **Relative positioning**: depending on the direction a character is looking, other characters will be either in front of them, on their side, or behind them. This is relevant for the mechanics of character attacks and for Stealth.

When the player clicks a tile to move to, the game will show a little arrow on the destination tile indicating the direction the character will be looking in when they reach the tile. This direction can be changed by the player by moving their cursor, as the arrow follows the player's cursor.

## Initiative

At the start of combat, each character takes their turn based on their initiative score.

The base value for the initiative score is :

```
Character's Speed + Dexterity modifier + Mind modifier

```

An additional modifier is applied if the character's Party is ambushing the enemy or being ambushed by the enemy, giving a big advantage to the ambusher.

## Preparation phase

Before combat starts, the preparation phase allows the player and enemies to take position. The player can also change their equipment, Weapon sets and Belt contents so they're better prepared for the fight.

If it is an Ambush, then the ambushing party will get a wider, more aggressive zone they can take position in, while the ambushed party's zone will be more restricted.

## Attacking

When attacking a character with a melee attack, a ranged attack or a projectile spell, the attacker passes an accuracy check and if they miss the attack fails.

This is decided with a roll of a twenty-sided die against the attacker's Accuracy and the defender's Dodge.
The hit is successful if :

```
d20 < 20 + Attacker's Accuracy - Defender's Dodge

```

### Distance

If the attack is a ranged attack, each tile of distance between the characters adds a penalty of 1 to the accuracy check.

### Poor Visibility

If the attacker can't see the defender well, their accuracy is reduced by the shadow value of the tile (the inverse of the tile's light value) the defender is standing on. This penalty can be mitigated by the attacker's Vision attribute. (so because a tile's light value is 4 at maximum, a character with 4 Vision will never suffer from poor visibility)

If the attacker can't see the defender at all, their chances of hitting are **severely** reduced, from base 100% to 25%. This can be mitigated if the attacker has good Hearing. Hitting an unseen character uses this formula:

```
d20 < 5 + Attacker's Accuracy + Attacker's Hearing - Defender's Dodge

```

### Block

If an attack doesn't miss, the defender has a chance of blocking it, negating physical damage.
The block is successful if :

```
d20 < Defender's Block

```

### Critical hit

If an attack or a spellcast rolls a score equal or lower to the character's Critical attribute, it is considered a critical result, and is an automatic success. It cannot miss, cannot be dodged and cannot be blocked.

Physical effects multiply their damage by like 1.5, and probably inflict a condition or debuff based on the weapon type.
Magic effects get increased affinity and bonus effect duration (if any).

### Cover

If a character is adjacent to an obstacle with a height of 1 tile, any ranged attacks made from that obstacle's direction have -4 Accuracy. If the obstacle is 2 tiles high or more, ranged attacks made from that direction have -8 Accuracy instead.

### Flanking and Backstabs

A character hitting another character from the side reduces their Dodge and Block value by 3 and hitting them from behind reduces their Dodge and Block value by 6.

As shown on the picture above, the different zones for flanking, backstabbing and normal attacks are not symmetrical.

* The standard attack zone is wider than the flanking zone, as it also covers the diagonals in front of the defender
* The backstab zone is narrower, as it requires the attacker to really be in the back of the defender. The flanking zone includes the diagonals behind the defender.

## Attack of Opportunity

A character moving next to another character will trigger an attack of opportunity from them if they're not wielding a ranged weapon. It is a basic attack, that doesn't cost a Main Action point. It can only be performed once per turn.

In some cases, a character may be unable to perform an Attack of Opportunity even if another character passes by them:

* the character is currently channeling an attack or spell
* the character is sleeping, stunned, blind or petrified
* they haven't detected the other character

## Hearing

In combat, a character A can hear another character B if this formula is true:

```
Character A's Hearing + Character B's Noise >= distance between the 2 characters

```

That means a character with a Hearing of 2 can hear a character with a Noise of 5 up to 7 tiles away for example.

This allows characters to detect other characters out of their line of sight and hear stealthy characters creeping up on them.

It also gives them a bonus to hitting enemies they cannot see, for example if the enemy character is invisible, or the character is Blind. If they can hear an unseen enemy, a character gains bonus Accuracy equal to their Hearing when trying to hit them. *Note that a character's base Accuracy is reduced to 5 when trying to hit an unseen enemy (see the Blind status effect)*

## Stealth

Any character is capable of hiding, but only some of them are actually capable of moving without being detected. It is generally much easier for a character to stay undetected if they remain in poorly lit areas of the battlefield or if they simply do not move.

Stealth is a mechanic that happens for every character without requiring specific actions or abilities. At the end of a character's turn, every enemy in line of sight checks whether they can see that character or not. That is what is called a Detection check.

If no enemy can detect the character, that character is **hidden**. Otherwise the character is **visible**.

All characters also get opportunities to detect hidden enemy characters:

* When a hidden character uses a Main Action, every enemy in line of sight makes a detection check
* When a character starts their turn, they make a detection check for every hidden enemy in line of sight

### Detection check

On a successful check, the hidden character is detected and becomes visible. A detection check is made using a roll of a twenty-sided die and is successful if:

```
d20 < lighting bonus + Hidden character's Visibility + Detecting character's Vision

```

* Lighting bonus is the **light value of the tile** the hiding character is standing on **multiplied by 4**. Tile **light value goes** **from 0 to 4,** with 0 being completely dark, and 4 being fully lit.
* For every condition that holds true, an extra bonus of +5 is applied:
	+ the detecting character can Hear the hidden character
	+ the hiding character is **in front** of the detecting character and **3 tiles or less away**
	+ the detection check was triggered by a hidden character using a Main Action
	+ during their turn, the character trying to hide was seen by the detecting character
		- *Note: that means this doesn't apply to detection checks triggered by a Main Action or a character's turn start*

*Most characters have around 10 natural Visibility so without a way to lower it, they'll usually only be able to hide well by standing in total darkness.*

### Stealth indicator

The game will display an eye-shaped indicator and a percentage showing how likely the player is to hide in two situations:

* the player character is hiding, and the player has selected an action to perform or a tile to move to
* the player character is not hiding, and the player has selected a tile that would allow them to hide
	+ *Note : a tile where the character can hide is a tile where no enemy has 100% chance of detecting them*

The eye will appear above each enemy that could potentially detect them and the chance of being detected by that enemy.

In this example, the player character is hidden, has a Visibility of 10 and the player is about to walk on a tile with lighting 2. The detecting character has no vision bonus. The total is 18/20, which is a 90% chance of being detected.

Depending on how likely the enemy is to detect the player's character, the eye's color will change :

* **Green** : chance of being detected is 25% or less
* **Yellow** : chance of being detected is 50% or less
* **Red** : chance of being detected is more than 50%

In this example, the hidden character is moving to a tile with 0 Light and has 10 Visibility. That's a base 50% chance of being detected. The white-haired character has a Vision of 6, making them 30% more likely to detect the hidden character. The blue-haired character is blind as a bat: they have -6 Vision. That leaves them with only 20% chance of detecting the hidden character.

## Damage types

### Physical

* **Standard**

Physical damage is usually inflicted by weapon attacks and some class skills and is reduced by the value of the defender's armor.
* **Silver**

Silver damage is inflicted by weapon attacks made with a silver weapon. It deals additional damage to some creatures, notably vampires and demons.
* **Armor-piercing**

Armor-piercing damage is like normal physical damage but it ignores part of the defender's armor. The armor-piercing score of the attack determines how much of the defender's Armor is ignored.

### Elemental

* **Fire**

Can inflict burns. Removes freezing status. Can ignite parts of the environment and flammable liquids.
* **Cold**

Can inflict freeze. Can freeze liquids.
* **Lightning**

Inflicted by lightning spells, some traps and some weapons. Has a chance of causing stuns.
When lightning damage is inflicted on a water tile (or a character standing in a water tile), that damage spreads to all contiguous water tiles and stun is guaranteed.
* **Nature**

Inflicted by most poisons and some spells
* **Arcane**

"Standard" magical damage.
* **Blood**

Inflicted by some spells, blood mage class skills and bleeding effects.
### Pure

Pure damage is inflicted by knockback, and some divine powers, spells and abilities.
It can only be reduced by stuff that reduces all damage taken.

## Resistances

### Armor

Gives a flat reduction on physical damage received equal to the defender's Armor attribute.

### Elemental resistance

When receiving elemental damage, it is multiplied by a factor based on the defender's corresponding Elemental Resistance.

Elemental resistance multipliers

### Debuff resistance

* **Toughness**

When a character would receive a physical status effect or debuff, a Toughness check is performed with a roll of a twenty-sided dice.
If the result of the dice roll is inferior to the character's Toughness attribute, they resist the ailment.
* **Mental resistance**

When a character would receive a mental status effect or magical ailment, a Mental resistance check is performed with a roll of a twenty-sided dice.
If the result of the dice roll is inferior to the character's Mental resistance attribute, they resist the ailment.
### Magic shield

Any attack taken by a character hits their magic shield first if they have one. It depletes as many points from the shield as it deals damage. Any remaining damage is dealt to the character normally. (basically works like any magic shield in any game)

## Status effects

Status effects can deal damage to a character and alter their fighting abilities and decision-making.

They are categorized as either physical or mental.

When a character would receive a physical effect, a Toughness check is performed with a roll of a twenty-sided dice.
If the result of the dice roll is inferior to the character's Toughness attribute, they resist the ailment.

It works the same way for mental effects, but using the character's Mental resistance attribute instead of Toughness.

### Physical effects

* **Silence**

Character can't use their voice or cast spells.
* **Bleeding**

Bleeding is a status effect that makes the character lose a small amount of Hit points at the start of each of their turns. Multiple bleeding effects can be active on a character at the same time.
* **Poison**

The effects of poisons vary wildly. They can deal damage or reduce some of a character's attributes for example. Multiple different poison effects can be active on a character, but applying a poison that is already active only refreshes its duration.
* **Burn**

Burning inflicts a lot of damage to the character at the start of their turn. Comparatively, burning effects are usually shorter than bleeding effects. Burning can be removed from a character if they walk into a tile of water or get splashed with water.
* **Freeze**

Increases a character's turn delay and Dodge. The afflicted character becomes vulnerable to Shattering.
* **Slow**

Reduces the character's Movement.
* **Stun**

The character skips their next turn.
Hmmmmmmm that's not great. Maybe something like -> you only get one action point.
idk
* **Root**

The character cannot use their Movement point while afflicted by this status effect.
* **Stagger**

The character has reduced Dodge and Accuracy and any knockback effects will knock them back one tile farther. Taking damage from being pushed against a wall or another character will inflict a stun and remove the staggered state.
* **Blind**

The character cannot see so they can only perceive other characters using their Hearing. Because every character is considered to be unseen, that means all their attacks have severely reduced Accuracy, from 20 base Accuracy to 5.
* **Petrification**

The character cannot move or act until cured or the petrification ends. The afflicted character becomes vulnerable to Shattering.
Lower difficulties should have much fewer sources of petrification, and shorter petrification lengths.
Highest difficulty will have permanent petrification.
### Mental effects

* **Confusion**

While a character is confused, casting spells will result in a failed cast.
* **Fear**

A character suffering from Fear has a penalty of 1 to their Accuracy, Speed and Mental resistance for every enemy character standing 3 tiles or less away from them. *I'm not sure yet about those stats but the principle should be fine*
* **Taunt**

A character that's been Taunted has to attack the character that inflicted that status effect upon them. This is generally not something enemies do, just the player characters.
* **Rage**

A character that's been enraged always attacks the nearest character, whether it's an ally or an enemy. They also inflict and receive more damage while the effect is active. *(amounts TBD)*
* **Sleep**

The character skips a number of turns (usually pretty high), but any damage wakes them up. At the start of their turn, succeeding a Mental Resistance check wakes them up.
* **Hallucination**

The character sees randomized sprites for characters, objects, terrain etc. The stat displays also show wrong information about other characters.
The randomized sprites will still show stuff from the same "class" :
* Humanoids have their parts randomized into other humanoids with random equipment and color tints
* Monsters are randomized into other monsters
* Objects and room fixtures are randomized into other monsters
* Floor tiles get a random tileset and appearance

## Quick Access

Characters cannot directly access their inventory in combat

### Belt

Belts are equippable items that allows characters to equip items and consumables to use during combat. Higher quality belt will have a larger number of item slots and maybe other bonuses.

They also ensure your character's pants don't fall off.

### Weapon sets

Characters can have multiple weapon sets that they can switch between during combat so they can have a bit more versatility.

The base number of available weapon sets is 2 but it can go higher, either with class bonuses or some equipment, for example a special combat belt.