#textdomain wesnoth-ei

#define WEAPON_SPECIAL_GREATER_DRAIN
    [drains]
        id=greater drains
        name= _ "greater drains"
        description= _ "This unit drains health from living units, healing itself for the full amount of damage it deals."
        special_note={INTERNAL:SPECIAL_NOTES_DRAIN}
        value=100
    [/drains]
#enddef

# this is part of reanimation
#define GHOSTPLAGUE_IMPLEMENTATION
    [event]
        name=last breath
        first_time_only=no

        [filter_second]
            id=Mal-Ravanal
        [/filter_second]

        [filter_condition]
            {VARIABLE_CONDITIONAL ghostplague_no_recursion not_equals $unit.id}
        [/filter_condition]

        [fire_event]
            name=explain_ghostplague
        [/fire_event]

        {STORE_UNIT_VAR (id=$unit.id) x  ghostplague_x}
        {STORE_UNIT_VAR (id=$unit.id) y  ghostplague_y}
        {STORE_UNIT_VAR (id=$unit.id) id ghostplague_no_recursion}
        {KILL id=$unit.id FIRE_EVENT=yes} # otherwise we lose out on other potential die events (e.g. Mal-Ravanal kills Dacyn)
        {STORE_UNIT_VAR (id=Mal-Ravanal) side ghostplague_side}

        # "ghost of" in the ID so that we don't accidentally trigger events for Gweddry or something
        {RAVANAL_ATTACK2}
        [sound]
            name=wail.wav
        [/sound]

        {NAMED_UNIT $ghostplague_side Ghost $ghostplague_x $ghostplague_y "ghost of $unit.name" "$unit.name" ()}
        {MODIFY_UNIT x,y=$x,$y attacks_left 0}
        {MODIFY_UNIT x,y=$x,$y attacks_left 0}

        {CLEAR_VARIABLE ghostplague_x,ghostplague_y,ghostplague_side,ghostplague_no_recursion}
    [/event]

    [event]
        name=explain_ghostplague
        [message]
            speaker=Mal-Ravanal
            message= _ "Your soul is mine!!"
        [/message]
    [/event]
#enddef

#define REANIMATE_TO_UNIT OLD_TYPE NEW_TYPE
    [if]
        [variable]
            name=unit.type
            equals={OLD_TYPE}
        [/variable]
        [then]
            [fire_event]
                name=explain_reanimation
            [/fire_event]
            {RAVANAL_ATTACK}
            {GENERIC_UNIT $unit.side ({NEW_TYPE}) $unit.x $unit.y} {ANIMATE}
        [/then]
    [/if]
#enddef

# implementation for Mal-Ravanal's [dummy] Reanimation ability
#define REANIMATION_IMPLEMENTATION
    [event]
        name=die
        first_time_only=no
        [filter_condition]
            [have_unit] # either ravanal is on this side
                side=$unit.side
                id=Mal-Ravanal
            [/have_unit]
            [or] # or ravanal exists and this is ravanal_reanimate_side
                [variable]
                    name=unit.side
                    equals=$ravanal_reanimate_side
                [/variable]
                [have_unit]
                    id=Mal-Ravanal
                [/have_unit]
            [/or]
        [/filter_condition]

        {KILL id=$unit.id}

        {REANIMATE_TO_UNIT (Skeleton)       {ON_DIFFICULTY (Skeletal Corpse) (Skeletal Corpse)   (Skeletal Soulless)} }
        {REANIMATE_TO_UNIT (Revenant)       {ON_DIFFICULTY (Skeletal Corpse) (Skeletal Soulless) (Skeleton)         } }
        {REANIMATE_TO_UNIT (Deathblade)     {ON_DIFFICULTY (Skeletal Corpse) (Skeletal Soulless) (Skeleton)         } }
        {REANIMATE_TO_UNIT (Death Squire)   {ON_DIFFICULTY (Skeletal Corpse) (Skeletal Soulless) (Skeleton)         } }
        {REANIMATE_TO_UNIT (Draug)          {ON_DIFFICULTY (Skeletal Corpse) (Skeleton)          (Revenant)         } }
        {REANIMATE_TO_UNIT (Death Knight)   {ON_DIFFICULTY (Skeletal Corpse) (Skeleton)          (Death Squire)     } }
        {REANIMATE_TO_UNIT (Lich)           {ON_DIFFICULTY (Skeletal Corpse) (Skeleton)          (Deathblade)       } }

        {REANIMATE_TO_UNIT (Skeleton Archer){ON_DIFFICULTY (Skeletal Corpse) (Skeletal Corpse)   (Skeletal Soulless)} }
        {REANIMATE_TO_UNIT (Bone Shooter)   {ON_DIFFICULTY (Skeletal Corpse) (Skeletal Soulless) (Skeleton Archer)  } }
        {REANIMATE_TO_UNIT (Banebow)        {ON_DIFFICULTY (Skeletal Corpse) (Skeleton Archer)   (Bone Shooter)     } }

        {REANIMATE_TO_UNIT (Skeleton Rider) {ON_DIFFICULTY (Skeletal Corpse) (Skeletal Corpse)   (Skeletal Soulless)} }
        {REANIMATE_TO_UNIT (Bone Knight)    {ON_DIFFICULTY (Skeletal Corpse) (Skeletal Soulless) (Skeleton Rider)   } }
        {REANIMATE_TO_UNIT (Chocobone)      {ON_DIFFICULTY (Skeletal Corpse) (Skeleton Rider)    (Bone Knight)      } }

        {REANIMATE_TO_UNIT (Dark Adept)     {ON_DIFFICULTY (Walking Corpse)  (Walking Corpse)    (Soulless)         } }
        {REANIMATE_TO_UNIT (Dark Sorcerer)  {ON_DIFFICULTY (Walking Corpse)  (Soulless)          (Ghoul)            } }
        {REANIMATE_TO_UNIT (Necromancer)    {ON_DIFFICULTY (Walking Corpse)  (Ghoul)             (Necrophage)       } }

        {REANIMATE_TO_UNIT (Ghoul)          {ON_DIFFICULTY (Walking Corpse)  (Walking Corpse)    (Soulless)         } }
        {REANIMATE_TO_UNIT (Necrophage)     {ON_DIFFICULTY (Walking Corpse)  (Soulless)          (Ghoul)            } }
        {REANIMATE_TO_UNIT (Ghast)          {ON_DIFFICULTY (Walking Corpse)  (Ghoul)             (Necrophage)       } }

#ifndef EASY
        {REANIMATE_TO_UNIT (Wraith)         {ON_DIFFICULTY (n/a)             (Ghost)             (Ghost)            } }
        {REANIMATE_TO_UNIT (Shadow)         {ON_DIFFICULTY (n/a)             (Ghost)             (Ghost)            } }
#endif
        {REANIMATE_TO_UNIT (Spectre)        {ON_DIFFICULTY (Ghost)           (Ghost)             (Wraith)           } }
        {REANIMATE_TO_UNIT (Nightgaunt)     {ON_DIFFICULTY (Ghost)           (Ghost)             (Shadow)           } }
    [/event]
    [event]
        name=explain_reanimation
        [message]
            speaker=Mal-Ravanal
            message= _ "Funny thing about the undead. If you know what you’re doing, they’re really very easy to put back together."
        [/message]
    [/event]
#enddef

#define WEAPON_SPECIAL_SWIFT
    [attacks]
        id=swift
        name= _ "swift"
        description= _ "This attack is exceptionally swift. When this attack is used on offense, the opponent will be unable to retaliate."
        value=0
        active_on=offense
        apply_to=opponent
    [/attacks]
#enddef

#define WEAPON_SPECIAL_SHOCK
    [attacks]
        id=shock
        name= _ "shock"
        description= _ "The crushing power of this attack overwhelms enemies. When used on offense, the opponent can only retaliate with one strike."
        value=1
        active_on=offense
        apply_to=opponent
    [/attacks]
#enddef

#define NOTE_SHOCK
    [special_note]
        note=_"This unit’s melee attack can overwhelm enemies’ defenses, preventing them from retaliating as effectively."
    [/special_note]
#enddef

#define ABILITY_VANGUARD
    [dummy]
        id=vanguard
        name= _ "vanguard"
        description=_ "This unit fights best in the heart of battle, surrounded by friends and foes alike.

Deals an additional 25% damage for each adjacent ally and/or enemy after the first."
    [/dummy]
    [leadership]
        id=vanguard1
        affect_self=yes
        affect_allies=no
        add=25
        [filter_self]
            [filter_adjacent]
                count=2
            [/filter_adjacent]
        [/filter_self]
    [/leadership]
    [leadership]
        id=vanguard2
        affect_self=yes
        affect_allies=no
        add=50
        [filter_self]
            [filter_adjacent]
                count=3
            [/filter_adjacent]
        [/filter_self]
    [/leadership]
    [leadership]
        id=vanguard3
        affect_self=yes
        affect_allies=no
        add=75
        [filter_self]
            [filter_adjacent]
                count=4
            [/filter_adjacent]
        [/filter_self]
    [/leadership]
    [leadership]
        id=vanguard4
        affect_self=yes
        affect_allies=no
        add=100
        [filter_self]
            [filter_adjacent]
                count=5
            [/filter_adjacent]
        [/filter_self]
    [/leadership]
    [leadership]
        id=vanguard5
        affect_self=yes
        affect_allies=no
        add=125
        [filter_self]
            [filter_adjacent]
                count=6
            [/filter_adjacent]
        [/filter_self]
    [/leadership]
#enddef

#define NOTE_VANGUARD
    [special_note]
        note=_"This unit gains increased damage for each adjacent ally and/or enemy."
    [/special_note]
#enddef

#define ABILITY_DARKENS
    [illuminates]
        id=darkens
        value=-25
        min_value=-25
        cumulative=no
        name= _ "darkens"
        description= _ "This unit darkens the surrounding area, making chaotic units fight better, and lawful units fight worse.

Any units adjacent to this unit will fight as if it were dusk when it is day, and as if it were night when it is dusk."
        affect_self=yes
    [/illuminates]
#enddef

#define ABILITY_OBFUSCATES
    [illuminates]
        id=obfuscation
        value=-50
        min_value=-50
        cumulative=no
        name= _ "obfuscates"
        description= _ "This unit obfuscates the surrounding area, making chaotic units fight much better, and lawful units fight much worse."
        affect_self=yes
    [/illuminates]
#enddef

#define ABILITY_NIGHTSKIRMISH
    # like skirmisher, but only at night
    [skirmisher]
        id=nightskirmish
        name= _ "nightskirmish"
        female_name= _ "female^nightskirmish"
        description= _ "This unit is skilled in moving past enemies quickly and ignores all enemy Zones of Control, but only at night."
        special_note={INTERNAL:SPECIAL_NOTES_SKIRMISHER}
        affect_self=yes
        [filter]
            [filter_location]
                time_of_day=chaotic
            [/filter_location]
        [/filter]
    [/skirmisher]
#enddef

#define ABILITY_TERROR
    [dummy]
        id=terror
        name= _ "terror"
        description= _ "This unit can frighten enemies in a 2 hex radius, making them fight worse. Units with the fearless trait are unaffected.

When an enemy unit of lower level within a 2 hex radius engages in combat, its attacks do 25% less damage times the difference in their levels."
    [/dummy]
#enddef

#define TERROR_EFFECT FILT MODIFIER
    [effect]
        [filter]
            {FILT}

            [not]
                trait=fearless,audacious
            [/not]
        [/filter]
        apply_to=new_ability
        [abilities]
            [leadership] # use leadership instead of increase_damage, because we want allied leadership to help counteract the effect
                {MODIFIER}
            [/leadership]
        [/abilities]
    [/effect]
#enddef
#define OBJECT_TERROR_L4
    [object]
        id=terrified
        duration=scenario # just in case it somehow doesn't get removed
        {TERROR_EFFECT level=0 sub=100}
        {TERROR_EFFECT level=1 sub=75}
        {TERROR_EFFECT level=2 sub=50}
        {TERROR_EFFECT level=3 sub=25}
    [/object]
#enddef
#define OBJECT_TERROR_L5
    [object]
        id=terrified
        duration=scenario # just in case it somehow doesn't get removed
        {TERROR_EFFECT level=0 sub=125}
        {TERROR_EFFECT level=1 sub=100}
        {TERROR_EFFECT level=2 sub=75}
        {TERROR_EFFECT level=3 sub=50}
        {TERROR_EFFECT level=4 sub=25}
    [/object]
#enddef

#define VISUALIZE_TERROR X Y
    [remove_item]
        image=terror_aura
    [/remove_item]
    [item] # looks like the halo is still visible even with visible_in_fog=no
        x,y={X},{Y}
        visible_in_fog=no
        name=terror_aura
        halo=halo/terror/terrorCW-[21~45].png~O(0.10):100,  halo/terror/terrorCW-[1~20].png~O(0.10):100
    [/item]
    [item]
        x,y={X},{Y}
        visible_in_fog=no
        name=terror_aura
        halo=halo/terror/terrorCCW-[1~45].png~O(0.10)~FL():175
    [/item]
    [item]
        x,y={X},{Y}
        visible_in_fog=no
        name=terror_aura
        halo=halo/terror/terrorCCW-[1~45].png~O(0.10):100
    [/item]
#enddef
#define APPLY_TERROR UNIT_FILTER
    [if]
        [have_unit]
            ability=terror
            level=4
        [/have_unit]

        [then]
            [modify_unit]
                [filter]
                    side=1
                    {UNIT_FILTER}
                [/filter]

                {OBJECT_TERROR_L4}
            [/modify_unit]
        [/then]
    [/if]
    [if]
        [have_unit]
            ability=terror
            level=5
        [/have_unit]

        [then]
            [modify_unit]
                [filter]
                    side=1
                    {UNIT_FILTER}
                [/filter]

                {OBJECT_TERROR_L5}
            [/modify_unit]
        [/then]
    [/if]
#enddef

# note that this doesn't work with multiple overlapping terror auras. Doesn't happen in EIR so not going to worry about it
#define GLOBAL__ABILITY_TERROR
    #------------------------
    # TERROR-UNIT SPAWNS
    #------------------------
    [event]
        name=unit placed
        first_time_only=no

        [filter]
            ability=terror
        [/filter]

        {VISUALIZE_TERROR $unit.x $unit.y}
        {APPLY_TERROR (
            [filter_location]
                x,y=$unit.x,$unit.y
                radius=2

                [filter]
                    ability=terror
                [/filter]
            [/filter_location]
        )
        }
    [/event]
    [event]
        name=die,last breath,terror_despawn #last breath makes this trigger before mal-ravanal's very tedious death animation
        first_time_only=no

        [filter]
            ability=terror
            [or]
                id=Mal-Ravanal
            [/or]
        [/filter]

        [remove_item]
            image=terror_aura
        [/remove_item]
        [remove_object]
            object_id=terrified
        [/remove_object]
    [/event]

    #------------------------
    # TERORR-UNIT MOVES
    #------------------------
    [event]
        name=moveto
        first_time_only=no

        [filter]
            ability=terror
        [/filter]

        {VISUALIZE_TERROR $unit.x $unit.y}
        [fire_event]
            name=terror_refresh
        [/fire_event]
    [/event]

    [event]
        name=exit hex
        first_time_only=no

        [filter]
            ability=terror
        [/filter]

        [remove_item]
            image=terror_aura
        [/remove_item]
    [/event]

    #------------------------
    # VICTIM MOVES
    #------------------------
    [event]
        name=moveto
        first_time_only=no

        [filter_condition]
            [have_unit]
                ability=terror
            [/have_unit]
        [/filter_condition]

        [fire_event]
            name=terror_refresh
        [/fire_event]
        [on_undo]
            [fire_event]
                name=terror_refresh
            [/fire_event]
        [/on_undo]
        [allow_undo]
        [/allow_undo]
    [/event]

    [event]
        name=terror_refresh
        first_time_only=no
        [remove_object]
            [not]
                [filter_location]
                    radius=2

                    [filter]
                        ability=terror
                    [/filter]
                [/filter_location]
            [/not]

            object_id=terrified
        [/remove_object]
        {APPLY_TERROR (
            [filter_location]
                radius=2

                [filter]
                    ability=terror
                [/filter]
            [/filter_location]
        )
        }
    [/event]
#enddef

#define ABILITY_SHROUD
    [resistance]
        id=shroud
        name= _ "shroud"
        description= _ "While defending, this unit has 50% fire and arcane resistance."
        affect_self=yes
        active_on=defense
        value=50
        max_value=50
        apply_to=fire,arcane
    [/resistance]
#enddef

#define COMMON_ARCANE
    alternative_type=arcane
    active_on=offense
    [filter_opponent]
        [not]
            [experimental_filter_ability_active]
                tag_name=resistance
                id=shroud
            [/experimental_filter_ability_active]
        [/not]
    [/filter_opponent]
#enddef

#define WEAPON_SPECIAL_ARCANE_EI
    [damage_type]
        id=arcane_damage
        #textdomain wesnoth-help
        name= _ "arcane"
        description= _ "This attack combines the arcane type with the type of weapon used so that resistance to the arcane type does not penalize the user."
        special_note=_ "This unit can use the arcane type when the opponent is particularly sensitive to it in relation to the weapon on which it is applied."
        #textdomain wesnoth-ei
        {COMMON_ARCANE}
    [/damage_type]
    [damage_type]
        id=arcane_damage_defense
        alternative_type=arcane
        active_on=defense
    [/damage_type]
#enddef

#define ABILITY_ARCANE_EI
    [damage_type]
        id=arcane_blessing
        overlay_image="misc/arcane-icon.png"
        {COMMON_ARCANE}
    [/damage_type]
    [damage_type]
        id=arcane_blessing_defense
        alternative_type=arcane
        active_on=defense
    [/damage_type]
#enddef
