# -*- fundamental -*-

include "sounds.txt"   # defines the "snd_*" actions (sound effects)


# Time Scale
ts = 140

zap     = [FlashScreen() snd_pentagram]
wandzap = [FlashScreen() snd_pentagram] 


#
# Weapons
#

i_sword = {
    type = "held"
    overlay = [g_sword_north, g_sword_east, g_sword_south, g_sword_west]

    melee_backswing_time = ts*2
    melee_downswing_time = ts*2
    melee_damage = d2
    melee_stun_time = ts*(d3+1)
    melee_tile_damage = 1
    parry_chance = 86
}

i_hammer = {
    type = "held"
    graphic = g_hammer
    overlay = [g_hammer_north, g_hammer_east, g_hammer_south, g_hammer_west]

    melee_backswing_time = 3*ts
    melee_downswing_time = 4*ts
    melee_damage = d4
    melee_stun_time = ts*(d3+3)
    melee_tile_damage = 1000
}

i_staff = {
    type = "held"
    graphic = g_staff
    overlay = [g_staff_north, g_staff_east, g_staff_south, g_staff_west]
    parry_chance = 90
    open_traps = 1
}

i_axe = {
    type = "held"
    graphic = g_axe
    overlay = [g_axe_north, g_axe_east, g_axe_south, g_axe_west]

    melee_backswing_time = 2*ts
    melee_downswing_time = 3*ts
    melee_damage         = d3     # Beefed up compared to Knights (which has d2)
    melee_stun_time      = ts*(d4+1)
    melee_tile_damage    = 5      # Slightly less effective than in Knights, I think
    parry_chance         = 80

    can_throw         = 1
    missile_anim      = a_axe
    missile_range     = 5
    missile_speed     = 250
    missile_hit_multiplier = 5
    missile_access_chance = 0
    missile_backswing_time = 2*ts
    missile_downswing_time = 3*ts
    missile_damage    = d3-1
    missile_stun_time = ts*(d3+1)
}

i_dagger = {
    type = "backpack"
    graphic = g_dagger
    stack_graphic = g_daggers
    backpack_graphic = g_inv_dagger
    backpack_overdraw = g_inv_overdraw_small
    backpack_slot = 13
    overlay = [g_dagger_north, g_dagger_east, g_dagger_south, g_dagger_west]

    max_stack = 10

    can_throw         = 1
    missile_anim      = a_dagger
    missile_range     = 10
    missile_speed     = 350 
    missile_hit_multiplier = 1
    missile_access_chance = 50
    missile_backswing_time = ts    # (TODO) may need to 
    missile_downswing_time = ts    # tweak these values...
    missile_damage    = Random(1,1,2)
    missile_stun_time = ts*(d2+1)

    control = {
        action = Throw()
        menu_icon = g_menu_dagger
        menu_direction = "right"
        continuous = 1
    }
}

i_crossbow = {
    type = "held"
    graphic = g_crossbow

    ammo = i_bolts
    reload_time = ts*26
    reload_action      = snd_click
    reload_action_time = ts
}

# used by the crossbow
i_bolts = {
    type = "backpack"
    graphic = g_bolts
    backpack_graphic = g_inv_bolt
    backpack_overdraw = g_inv_overdraw_small
    backpack_slot = 14
    max_stack = 10

    missile_anim = a_bolt
    missile_range = 50
    missile_speed = 440
    missile_hit_multiplier = 1
    missile_access_chance = 75
    missile_damage = d4
    missile_stun_time = d4+2
}

# used by traps etc
i_bolt_trap = i_bolts

#
# Wands
#

basic_wand = {
    type = "held"
    graphic = g_wand
    overlay = [g_wand_north, g_wand_east, g_wand_south, g_wand_west]

    melee_backswing_time = ts
    melee_downswing_time = ts
    melee_tile_damage = 0
    melee_action = wandzap
    on_pick_up = UpdateQuestStatus()
    on_drop = UpdateQuestStatus()
}

i_wand_of_destruction = basic_wand & {
    melee_damage = 1000
    melee_stun_time = ts*(d2+1)
    melee_tile_damage = 1000
}

i_wand_of_undeath = basic_wand & {
    melee_damage = 0
    melee_stun_time = ts
    melee_action = [ wandzap,
                     ZombifyTarget(), 
                     OnSuccess(snd_zombie),
                     ZombieKill(),
                     OnSuccess(snd_zombie),
                   ]
}

i_wand_of_open_ways = basic_wand & {
    melee_damage = d3
    melee_stun_time = ts*(d4+1)
    melee_action = [ OpenWays(), wandzap ]
    allow_strength = 0  # Prevent the usual destruction of doors/chests when knight has strength
}

i_wand_of_securing = basic_wand & {
    melee_damage = 0
    melee_stun_time = ts*(d6+5)
    melee_action = [ wandzap Secure(t_wall_normal) ]
}

all_wands = [i_wand_of_destruction, i_wand_of_undeath, i_wand_of_open_ways, 
             i_wand_of_securing]


#
# Books
#

i_basic_book = { 
    # Tome of Gnomes or Lost Book of Ashur
    type = "held"
    graphic = g_book
    overlay = [g_book_north, g_book_east, g_book_south, g_book_west]
    editor_label = "G"
    on_pick_up = UpdateQuestStatus()
    on_drop = UpdateQuestStatus()
}

i_book_of_knowledge = i_basic_book & {
    # Ancient Book of Knowledge
    on_pick_up = [ MagicMapping(), RevealStart(), UpdateQuestStatus() ]
    on_drop   =  [ RevealStop(), UpdateQuestStatus() ]
    editor_label = "K"
}

i_necronomicon = i_basic_book & { 
    # Necronomicon
    # Note on Necromancy: first number is the number of zombies to generate (I have increased
    # this slightly compared to the original Knights), and second number is the range (in squares). 
    on_pick_up = [ Necromancy(10, 7),    # Attempt to raise nearby zombies. (Will only work the first time.)
                   OnSuccess(wandzap),   # Flash screen if necromancy actually took place.
                   FullZombieActivity(), # Always set full zombie activity while necronomicon is held.
                   UpdateQuestStatus() ]
    on_drop = [ NormalZombieActivity(), UpdateQuestStatus() ]
    editor_label = "N"
}


all_books = [i_basic_book, i_book_of_knowledge, i_necronomicon]


#
# Traps
#

i_bear_trap = {
    type = "held"
    graphic = g_closed_bear_trap
    overlay = [g_beartrap_north, g_beartrap_east, g_beartrap_south, g_beartrap_west]
    control = { 
        action = [SetBearTrap(i_bear_trap_open), snd_click]
        menu_icon = g_menu_beartrap
        menu_direction = "left"
    }
}

i_bear_trap_open = {
    type = "nopickup"
    graphic = g_open_bear_trap
    on_walk_over = [Damage(1, ts*(d6+14), 1), ChangeItem(i_bear_trap), snd_bear_trap]
    on_hit = [ChangeItem(i_bear_trap), snd_bear_trap]
}

i_poison_trap = {
    type = "backpack"
    graphic = g_poison_trap
    backpack_graphic = g_menu_poison_trap
    backpack_overdraw = g_inv_overdraw_big
    backpack_slot = 11
    control = {
        action = [SetPoisonTrap(), snd_click]
        menu_icon = g_menu_poison_trap
        menu_direction = "left"
    }
}

i_blade_trap = {
    type = "backpack"
    graphic = g_blade_trap
    backpack_graphic = g_menu_blade_trap
    backpack_overdraw = g_inv_overdraw_big
    backpack_slot = 12
    control = {
        action = [SetBladeTrap(i_bolt_trap), snd_click]
        menu_icon = g_menu_blade_trap
        menu_direction = "right"
    }
}


#
# Keys
#

basic_key = {
    type = "backpack"
    graphic = g_key
}

i_key1 = basic_key & {
    backpack_graphic = g_inv_key1
    backpack_slot = 20
    key = 1
}

i_key2 = basic_key & {
    backpack_graphic = g_inv_key2
    backpack_slot = 21
    key = 2
}

i_key3 = basic_key & {
    backpack_graphic = g_inv_key3
    backpack_slot = 22
    key = 3
}

i_lockpicks = basic_key & {
    backpack_graphic = g_inv_lockpicks
    backpack_slot = 23
    control = {
        action = [PickLock(2, 140), snd_lock]
        continuous = 1
        menu_icon = g_menu_lockpicks
        menu_direction = "up"
    }
}


#
# Gems
#

i_gem = {
    type = "backpack"
    graphic = g_gem
    backpack_graphic = g_menu_drop_gem
    backpack_slot = 30
    on_pick_up = UpdateQuestStatus()
    on_drop = UpdateQuestStatus()
}


#
# Magic Items
#

# Teleportation needs to play a sound effect as well (ditto zombification)
# N.B. We play the sound *after* the teleport occurs. This ensures that the sound goes to both players.
# For zombification we play the sound *before* zombifying (i.e. while the actor still exists!)
my_teleport = [Teleport(), snd_teleport]
my_attractor = [Attractor(), snd_teleport]
my_zombify = [snd_zombie, ZombifyActor()]

# These potion and scroll effects have been designed to be exactly equivalent to what 
# the original Knights does, which is why they are a bit complicated.

dispel_magic = DispelMagic("Dispel Magic")
healing = Healing("Healing")
invisibility = Invisibility(pot_dur, "Invisibility")
invulnerability = Invulnerability(invuln_dur, "Invulnerability")
paralyzation = Paralyzation(para_dur)
poison = Poison("Poison")
poison_immunity = PoisonImmunity(pi_dur, "Poison Immunity")
quickness = Quickness(pot_dur, "Quickness")
regeneration = Regeneration(pot_dur, "Regeneration")
strength = Strength(pot_dur, "Strength")
super = Super(pot_dur, "Super")

potion_para = Random( paralyzation:2, 
                      [paralyzation healing]:2, 
                      [healing poison_immunity]:1 )
potion_side = Random( Nop():2, healing:2, [healing poison_immunity]:1 )
potion_main = Random( Nop():3, regeneration:2, 
                      quickness:2, strength:2, 
                      invisibility:2, super:2 )
potion_effect = Random( poison:1, potion_para:2, [potion_side potion_main]:13 )

# Durations for potions and other magics
pot_dur = 1000 * (10 + d100)           # 11s -- 1m50s, av 1m
pi_dur  = 1000 * (20 + d140)           # 21s -- 2m40s, av 1m30s
invuln_dur = 1000 * Random(5+d10, 8+d10, 15+d15, 30+d30)  # 6s -- 1m, av 23s
para_dur = 1000*Random(d10, d20, d30)  # 1s  -- 30s, av 10.5s
see_kt_dur = 1000 * (20 + d120)        # 21s -- 2m20s,  av 1m20s
see_item_dur = 1000 * 60 * 5           # fixed duration of 5m

scroll_nice       = Random( invulnerability, my_teleport, my_attractor, 
                            quickness, strength,
                            invisibility, my_zombify, SenseItems(see_item_dur), 
                            MagicMapping() )
scroll_nasty      = Random( Nop():5, WipeMap():1 )
scroll_very_nasty = [scroll_nasty  dispel_magic]
scroll_sensing    = [Random(RevealLocation(see_kt_dur):1, Nop():2),
                     Random(SenseKnight(see_kt_dur), Nop())]

scroll_1      = [Random(scroll_nice:9, scroll_nasty:2)  scroll_sensing]
scroll_2      = Random(scroll_nice:9, scroll_very_nasty:2)
scroll_effect = Random(scroll_1, scroll_2)

pentagram_effect = Random(my_teleport, invisibility, invulnerability,
                          my_zombify)

i_potion = {
    type       = "magic"
    graphic    = g_potion
    fragile    = 1
    on_pick_up = [snd_drink, After(750, potion_effect)]
}

i_scroll = {
    type       = "magic"
    graphic    = g_scroll
    on_pick_up = [zap, scroll_effect]
}
