# Combat

This describes how combat is realized in the game. It contains low-level programmer explanation, and therefore might not be suitable for a random visitor.

This topic is extremely difficult and complex, even for me to wrap the head around. You have been warned. ×

This is sub-layout for documentation pages

## Contents

[hide]
Top

#### [UNDEFINED ID (href) #intro]

As the game engine was written, there are abilities, that character might use.
They are divided into different groups, but the basic idea is, that whatever damage/combat action is taking place, an ability is being used. If some new element would be added to game (for example burn damage over time, or poison damage over time), then simply new ability would be added to database, hidden from players (as poison might not be used as ability by player/monster, since it will be only the resulting effect of some damage.

Therefore, if a weapon or standard attack shall poison enemy or set it on fire, a new instance of such ability is created, and attached to the player object.

#### [UNDEFINED ID (href) #abilities]

Abilities are divided to 2 groups: basic and non-basic. They are further divided to following categories according to their type:

• Meele ability
• Projectile ability
• Missible ability
• Aura ability
• Area of effect (AOE) ability

#### [UNDEFINED ID (href) #basic-ability]

A basic ability can be any ability of any ability type described above. To know, whether it is basic ability, in a database is in a table containing ability info column with a bit, telling whether the ability is basic or not.
All basic abilities are assigned to every character in-game world. That includes the Player, Monster. There might be a restriction for using the basic ability, such as level, or something else. Simply put, basic ability does not require rune to be equipped.

#### [UNDEFINED ID (href) #non-basic-ability]

A non-basic ability requires rune to be equipped. Rune is a special item that provides some specific ability. Rune can be leveled up, making the ability stronger.
If the character does not possess the required rune, or he does not have it equipped, the ability can not be used.

#### [UNDEFINED ID (href) #ability-structures]

To describe abilities, the structures used by abilities must be described first. Here, structure is just a set of information that relates to an ability.

#### [UNDEFINED ID (href) #ability-structures-info]

Every ability has this related set of information. Ability info structure contains general information about the ability, such as whether it is basic ability, or not, cooldown time ...
Damage info is held in table dol_abilityInfo in the database

#### [UNDEFINED ID (href) #ability-structures-damage]

Damage info structure contains information related to damage that the ability might deal. Surprisingly, not all abilities have that (such as aura, which might not deal any damage at all).
Damage info is held in table dol_abilityDamageInfo in the database

#### [UNDEFINED ID (href) #ability-structures-aoe]

AOE info structure contains information related to only area of effect ability
That info is held in table dol_abilityAoeInfo in the database

#### [UNDEFINED ID (href) #ability-structures-aura]

Aura info structure contains information related to the only aura ability. Contains info such as the foreign key to stats modifier, or whether the aura is a repetitive effect, available targets...
That info is held in table dol_abilityAuraInfo in the database

#### [UNDEFINED ID (href) #ability-structures-projectile]

Projectile info structure contains information related to the only projectile ability. Contains info such as the maximum lifetime of projectile
That info is held in table dol_abilityProjectileInfo in the database

#### [UNDEFINED ID (href) #melee-ability]

Melee ability might be used only when a character is near to the target (= exists incident path node to the target's current path node, and the attacker is standing on it).
Note: Of course, there are other restrictions, such as level, freeze effect, etc.
Melee ability has related damage structure and ability info structure

#### [UNDEFINED ID (href) #projectile-ability]

Projectile ability creates a projectile, which heads in some direction. The behavior of the projectile depends on the projectile class structure.
The projectile, however, never chases the target. Projectile ability has related damage structure, projectile info structure and ability info structure

#### [UNDEFINED ID (href) #missile-ability]

Missile ability is Projectile ability (the structures and databse structure stays same), only has different behavior of projectile.
The casted projectile has target character assigned, and chases the character forever.

In database is bit telling whether projectile ability is a missile
Projectile ability has related damage structure, projectile info structure and ability info structure

TODO

TODO

#### [UNDEFINED ID (href) #clearing-target-motivation]

Let's imagine, that we have 3 players, where 2 players attack the third:

Let's imagine, that player 3 dies.
Because he dies, he will respawn, and as he is respawned, calling function to ask, whether he is valid target will return true (because he is alive...).
This would result in fact, that even after death, monsters will continue to attack you, which is unwanted behavior.

#### [UNDEFINED ID (href) #clearing-target-naive-solution]

To solve this, there must be somehow removed reference from player 1 and player 2 to player 3 in order to stop attack.

Naive solution would be as follows:

• When player dies, iterate all monsters and players, and order them to remove chracter of id [X] from targets

Obviously, considering $N$ players and monsters, the complexity is $O(N)$
That is unwanted, as it would execute at each death. Considering 1 000 players, where everyone dies in same moment, System would execute tormendous $1 000 * 1 000 = 1 000 000$ operations, which just can not be...

#### [UNDEFINED ID (href) #clearing-target-professionalSolution]

The idea is to keep a key in each character (Player / Monster), which will be copied to attacker.

Attacker will attack target, if keys match (plus some other game checks for rules).
If we want to stop anyone from attacking some specific character, then we simply change the key.

Once attacker want's to attack target, and keys do not match, then attacker will remove the target reference, and will no longer attempt to attack him.
The complexity of this solution is $O(1)$