/////////////////////////////////////////////////////////////////////////////////
////  Zombie Infection script
////    by Capes 2018-5-10
/////////////////////////////////////////////////////////////////////////////////
[COMMENT zombie_infection_info]
An infected zombie 
    - moves faster
    - npc's & player's hit by them must pass a 50% check else they become infected (A permanent buff).
    - when that npc/player dies it's corpse becomes an infected zombie, with all the inventory on them
    - once infected there is no cure
    - dropping a lit torch on an infected corpse will destroy this infection
[DEFNAME infection_settings]
CORPSE_to_ZOMBIE_delay = 120 //2 mins
INFECTION_rate = 10    //10 secs
INFECTION_chance = 50 //% 1-100
/////////////////////////////////////////////////////////////////////////////////    
[EVENTS e_zInfection]    
ON=@Timer
    //not infected quit
    if !(<src.tag0._is_infected>)
        return
    endif
    //inform player their rotting away
    src.sysmessage @33 Your flesh is rotting!
    
    //we are infected so slowly take 10 damage (player starts to turn)
    src.damage= 10 (<DEF.dam_poison>)
    
    //run timer again
    src.timerf <def.INFECTION_rate> f_infection_timer
    
ON=@Hit
    //only run if this is an infected zombie
    if !(<defname>==c_infected_zombie)
        return
    endif
    
    //if target already infected quit
    if (<src.tag0._is_infected>)
        return
    endif
    
    //disease check else infect them
    if (<eval RAND(100)+1> <= <def.INFECTION_chance>)
        return
    endif
    
    //set infected flag
    src.tag0._is_infected = 1
    
    //add infected event
    src.events +e_zInfection
    src.sysmessage @30 You have been infected.
    
    //add buf icon if player
    if (<src.isplayer>)
        src.addbuff 1017,3010160,1053096,0,
    endif
    
    //start timer for rotting
    src.timerf <def.INFECTION_rate> f_infection_timer
    
ON=@DeathCorpse 
    //quit if c_infected_zombie
    if (<defname>==c_infected_zombie)
        return
    end
    
    //we died while infected so turn corpse into zombie in x amount of time
    argo.timerf <def.CORPSE_to_ZOMBIE_delay> f_turn_to_infected <src.name>
    
    //remove this infection from player
    src.events -e_zInfection
    src.tag0._is_infected =
    
    //remove buf icon if player
    if (<src.isplayer>)
        src.removebuff 1017
    endif
    
    //remove f_infection_timer
    src.timerf STOP,f_infection_timer
ON=@Logout
    //we are infected and logging out
        //stop timer
    timerf STOP,f_infection_timer
    
ON=@Login 
    //since this is triggering, we are infected and loging in
        //add the infection buf & fire timer if not present
    addbuff 1017,3010160,1053096,0,
    timerf <def.INFECTION_rate> f_infection_timer
/////////////////////////////////////////////////////////////////////////////////
[FUNCTION f_turn_to_infected]    
    //we died while infected so turn corpse into infected zombie
        //transfer all possessions & name to new zombie
    SERV.newnpc c_infected_zombie
    new.name = The infected corpse of <args>
    new.p = <p>
    FORCONT <uid> 0  //we don't need to search in the subcontainers, just grab them.
        //serv.log <name>
            new.bounce <uid>
    ENDFOR
    //remove corpse
    remove
    new.updatex
    
/////////////////////////////////////////////////////////////////////////////////    
[FUNCTION f_infection_timer]
    I.trigger @timer
    
    
/////////////////////////////////////////////////////////////////////////////////        
[CHARDEF c_infected_zombie]
ID=c_zombie
NAME=infected zombie
ICON=i_pet_zombie
SOUND=snd_monster_zombie1
CAN=MT_WALK|MT_RUN
DAM=3,7
ARMOR=18
DESIRES=r_graveyards,t_coin,t_gold,t_gem,t_potion
AVERSIONS=t_trap,r_civilization
RESOURCES=1 i_reag_bone
TAG.SlayerGroup=UNDEAD
TEVENTS=e_undead
TEVENTS=e_carnivores
TEVENTS=e_zInfection
MOVERATE={180 240}
CATEGORY=Monsters
SUBSECTION=Undead
DESCRIPTION=Zombie
ON=@Create
   NPC=brain_monster
   FAME=600
   KARMA=-600
   STR={45 70}
   DEX={30 50}
   INT={25 40}
   MAXHITS={30 45}
   WRESTLING={35.1 50.0}
   TACTICS={35.1 50.0}
   MAGICRESISTANCE={15.1 40.0}
   RESPHYSICAL={15 20}
   RESFIRE=0
   RESCOLD={20 30}
   RESPOISON={5 10}
   RESENERGY=0
ON=@NPCRestock
   //ITEM=loot_zombie    
    
/////////////////////////////////////////////////////////////////////////////////    
[ITEMDEF 0a12]
DEFNAME=i_torch_lit
TYPE=t_light_lit
TDATA3=i_torch
FLIP=1
CATEGORY=Decoration - Lightsources
SUBSECTION=Torches
DESCRIPTION=Torch (Lit)
DUPELIST=0a13,0a14
ON=@Create
   MOREZ=2
ON=@DropOn_Item 
    //set corpse on fire & remove infection if any
    if (<argo.baseid> == i_corpse) 
    
        //place fire effect & play sound
        serv.newitem i_fire
        new.p = <argo.p>
        new.attr = 08010
        new.timerf 10,remove
        sfx 054
        
        //turn corpse black (charring)
        argo.color = 1899
        argo.timerf STOP,f_turn_to_infected
        
        //add scorch marks
        serv.newitem 0f34
        new.name = scorch marks
        new.attr = 08010
        new.color = 1
        new.p = <argo.p>
        new.timerf 20,remove
        
        src.sysmessage You burn the corpse.
        return 1
    endif