#textdomain wesnoth-dw

# This copy of OBJ_TRIDENT_STORM is only the object, it doesn't include the event for picking it up. This trident is used in the wolf_coast scenario, which uses a campaign-specific set of events for picking it up.

#define STORM_TRIDENT X Y ID
    [object]
        id={ID}
        name= _ "Storm Trident"
        image=items/storm-trident.png
        duration=forever
        description= _ "This trident gives merfolk the power to throw lightning at their enemies."
        silent=yes
        cannot_use_message= _ "Only merfolk can use this item."
        [filter]
            race=merman
            x={X}
            y={Y}
        [/filter]
        [then]
            [remove_item]
                x={X}
                y={Y}
            [/remove_item]
        [/then]
        [effect]
            apply_to=new_attack
            name="storm trident"
            description= _ "storm trident"
            # need a better attack image, but this will do for now, replaced fireball with lightingbolt
            icon=attacks/lightning.png
            type=fire
            range=ranged
            [specials]
                {WEAPON_SPECIAL_MAGICAL}
            [/specials]
            damage=14
            number=2
        [/effect]
        [effect]
            apply_to=overlay
            add="overlays/storm-trident-icon.png"
        [/effect]

        {LIGHTNING_ANIMATION "storm trident" 1}
        {LIGHTNING_ANIMATION "storm trident" 2}
        {LIGHTNING_ANIMATION "storm trident" 3}
    [/object]
#enddef

#define FLAMING_SWORD X Y ID
    [object]
        id={ID}
        name= _ "Flaming Sword"
        image=items/flame-sword.png
        duration=forever
        silent=yes
        [filter]
            x={X}
            y={Y}
        [/filter]
        [then]
            [remove_item]
                x={X}
                y={Y}
            [/remove_item]
        [/then]
        [effect]
            apply_to=new_attack
            name="flaming sword"
            description= _ "flaming sword"
            icon=attacks/sword-flaming.png
            type=fire
            range=melee
            [specials]
                {WEAPON_SPECIAL_MAGICAL}
            [/specials]
            damage=8
            number=4
        [/effect]
        [effect]
            apply_to=overlay
            add="overlays/flame-sword-icon.png"
        [/effect]
    [/object]
#enddef

#define ANKH_NECKLACE X Y ID
    [object]
        id={ID}
        name= _ "Ankh Necklace"
        image=items/ankh-necklace.png
        duration=forever
        silent=yes
        [filter]
            x={X}
            y={Y}
        [/filter]
        [then]
            [remove_item]
                x={X}
                y={Y}
                image=items/ankh-necklace.png
            [/remove_item]
        [/then]
        [effect]
            apply_to=resistance
            replace=yes
            [resistance]
                arcane=30
            [/resistance]
        [/effect]
        [effect]
            apply_to="overlay"
            add="overlays/arcane-icon.png"
        [/effect]
    [/object]
#enddef

# The ring of strength belongs to Mal-Kevek who appears in the second
# scenario. If he lives through that scenario, he appears again in the
# last. All the associated events need to be in both scenarios, so a
# macro is called for.

#define RING_OF_STRENGTH_EVENTS
    [event]
        name=prestart

        [if]
            [variable]
                name=MD_dead
                not_equals=yes
            [/variable]

            [then]
                [object]
                    id=power_ring1
                    silent=yes

                    [effect]
                        apply_to=attack
                        increase_damage=1
                    [/effect]

                    [effect]
                        apply_to=hitpoints
                        increase=3
                        increase_total=3
                    [/effect]

                    [filter]
                        id=Mel Daveth
                    [/filter]
                [/object]
            [/then]
        [/if]

        [set_variable]
            name=ring_x
            value=999
        [/set_variable]
    [/event]

    [event]
        name=moveto
        first_time_only=no

        [filter]
            x=$ring_x
            y=$ring_y
            side=1
        [/filter]

        [if]
            [have_unit]
                x,y=$x1,$y1
                race=bats
            [/have_unit]
            [then]
                [if]
                    [variable]
                        name=seen_ring_description
                        not_equals=yes
                    [/variable]
                    [then]
                        [message]
                            speaker=narrator
                            message= _ "The bat slips the ring over a claw, and flies straight up, flapping powerfully."
                            image=wesnoth-icon.png
                        [/message]

                        [message]
                            speaker=narrator
                            message= _ "The ring of power increases the damage of all its owner’s attacks by one, and adds three hitpoints."
                            image=wesnoth-icon.png
                        [/message]

                        [set_variable]
                            name=seen_ring_description
                            value=yes
                        [/set_variable]
                    [/then]
                [/if]

                [message]
                    speaker=Kai Krellis
                    [option]
                        label= _ "We will let the bat have the ring. It will make him more helpful."
                        [command]
                            [set_variable]
                                name=get_ring
                                value=yes
                            [/set_variable]
                        [/command]
                    [/option]
                    [option]
                        label= _ "Someone take that off him before he hurts himself."
                    [/option]
                [/message]
            [/then]

            [else]
                [if]
                    [have_unit]
                        x,y=$x1,$y1
                        race=monster
                    [/have_unit]
                    [then]
                        [if]
                            [variable]
                                name=seen_ring_description
                                not_equals=yes
                            [/variable]
                            [then]
                                [message]
                                    speaker=Kai Krellis
                                    message= _ "Leave it."
                                [/message]
                            [/then]
                        [/if]
                    [/then]

                    [else]
                        [if]
                            [variable]
                                name=seen_ring_description
                                not_equals=yes
                            [/variable]
                            [then]
                                [message]
                                    speaker=unit
                                    message= _ "I’ll try on the ring."
                                [/message]

                                [message]
                                    speaker=unit
                                    message= _ "I feel different, and all my weapons are lighter!"
                                [/message]

                                [message]
                                    speaker=narrator
                                    message= _ "The ring of power increases the damage of all its owner’s attacks by one, and adds three hitpoints."
                                    image=wesnoth-icon.png
                                [/message]
                                [set_variable]
                                    name=seen_ring_description
                                    value=yes
                                [/set_variable]
                            [/then]
                        [/if]

                        [message]
                            speaker=unit
                            [option]
                                label= _ "I’ll take this ring, and you can rely on my strength."
                                [command]
                                    [set_variable]
                                        name=get_ring
                                        value=yes
                                    [/set_variable]
                                [/command]
                            [/option]
                            [option]
                                label= _ "This thing makes me dizzy. Someone else can have it."
                            [/option]
                        [/message]
                    [/else]
                [/if]
            [/else]
        [/if]

        [if]
            [variable]
                name=get_ring
                not_equals=yes
            [/variable]

            [then]
                [allow_undo][/allow_undo]
            [/then]

            [else]  # Get the ring
                [object]
                    id=power_ring2
                    name= _ "Ring of Power"
                    image=items/ring-silver.png
                    duration=forever
                    silent=yes
                    [filter]
                        x=$ring_x
                        y=$ring_y
                    [/filter]
                    [then]
                        [remove_item]
                            x=$ring_x
                            y=$ring_y
                        [/remove_item]
                    [/then]
                    [effect]
                        apply_to=attack
                        increase_damage=1
                    [/effect]
                    [effect]
                        apply_to=hitpoints
                        increase_total=3
                        increase=3
                    [/effect]
                    [effect]
                        apply_to=overlay
                        add="overlays/silver-ring-icon.png"
                    [/effect]
                [/object]
                {CLEAR_VARIABLE get_ring}
                {CLEAR_VARIABLE seen_ring_description}

                # This keeps it from being picked up a second time.
                [set_variable]
                    name=ring_x
                    value=999
                [/set_variable]

                # This [if] only applies to the second scenario. That is where this variable might be set to "yes".
                [if]
                    [variable]
                        name=end_level_when_ring_picked_up
                        equals=yes
                    [/variable]

                    [then]
                        # End level:
                        [message]
                            speaker=Cylanna
                            message= _ "Killing these enemies was good, but there are many more on the way. I’m sure it is still unsafe here."
                        [/message]

                        [message]
                            speaker=Kai Krellis
                            message= _ "I agree. I hate to leave our home, but we will return."
                        [/message]

                        [clear_variable]
                            name=ring_x
                        [/clear_variable]
                        [clear_variable]
                            name=ring_y
                        [/clear_variable]
                        [clear_variable]
                            name=KK
                        [/clear_variable]
                        [clear_variable]
                            name=get_ring
                        [/clear_variable]

                        [endlevel]
                            result=victory
                            bonus=yes
                            {NEW_GOLD_CARRYOVER 40}
                        [/endlevel]

                        [clear_variable]
                            name=end_level_when_ring_picked_up
                        [/clear_variable]
                    [/then]
                [/if]
            [/else]
        [/if]
    [/event]
#enddef

#define RING_OF_STRENGTH_APPEARS
    [if]
        [variable]
            name=MD_dead
            not_equals=yes
        [/variable]

        [then]
            [set_variable]
                name=ring_x
                value=$x1
            [/set_variable]
            [set_variable]
                name=ring_y
                value=$y1
            [/set_variable]

            {PLACE_IMAGE items/ring-silver.png $ring_x $ring_y}
            [delay]
                time=600
                # Gives you half a second to see the ring before the message (possibly) covers it up.
            [/delay]

            [if]
                [have_unit]
                    x,y=$x2,$y2
                    race=monster,bats
                [/have_unit]
                [then]
                    [message]
                        speaker=Kai Krellis
                        message= _ "The human wizard was wearing a ring! Maybe it is magic. Someone should try it on to see what it does."
                    [/message]
                [/then]
                [else]
                    [message]
                        speaker=second_unit
                        message= _ "The human wizard was wearing a ring! Maybe it is magic. Someone should try it on to see what it does."
                    [/message]
                [/else]
            [/if]
        [/then]
    [/if]
#enddef
