//****************************************************************************
// SPHERE by : Menasoft ©1997-2019
// www.sphereserver.net
// All SPHERE script files and formats are copyright Menasoft & Partners.
// This file may be freely edited for personal use, but may not be distributed
// in whole or in part, in any format without express written permission from
// Menasoft & Partners.  All donations and contributions
// become the property of Menasoft & Partners.
//****************************************************************************
// FILE LAST UPDATED: Tuesday, Feb 5, 2019
//
VERSION=0.56d


///////////////////////////
// Some Useful Functions //
///////////////////////////

[FUNCTION f_isHuman]
IF ( (<OBODY>==c_man) || (<OBODY>==c_woman) )
   RETURN 1
ENDIF
RETURN 0

[FUNCTION f_isElf]
IF ( (<OBODY>==c_elf_male) || (<OBODY>==c_elf_female) )
   RETURN 1
ENDIF
RETURN 0

[FUNCTION f_isGarg]
IF ( (<OBODY>==c_gargoyle_male) || (<OBODY>==c_gargoyle_female) )
   RETURN 1
ENDIF
RETURN 0

[FUNCTION f_isFemale]
if (<serv.chardef.<obody>.can>&mt_female)	//Checking on chardef directly here because if you change your body your Can flags won't be updated since they are now stored in the char itself when it creates.
	return 1
endif
return 0

[FUNCTION f_isCursed]
FORCHARLAYER 32
   IF (<BASEID>==i_rune_curse)
      RETURN 1
   ENDIF
ENDFOR
RETURN 0


[FUNCTION MODMAXHITS]
LOCAL.Result=<EVAL <ARGS>>
IF (<ISEMPTY <ARGS>>)
   RETURN <EVAL <TAG0.MODMAXHITS>>
ELSE
   TAG.MODMAXHITS=<EVAL <TAG0.MODMAXHITS>+<LOCAL.Result>>
   IF !(<TAG0.MODMAXHITS>)
      TAG.MODMAXHITS=
      MAXHITS=
   ELSE
      MAXHITS=<EVAL <MAXHITS>+<LOCAL.Result>>
   ENDIF
ENDIF

[FUNCTION MODMAXSTAM]
LOCAL.Result=<EVAL <ARGS>>
IF (<ISEMPTY <ARGS>>)
   RETURN <EVAL <TAG0.MODMAXSTAM>>
ELSE
   TAG.MODMAXSTAM=<EVAL <TAG0.MODMAXSTAM>+<LOCAL.Result>>
   IF !(<TAG0.MODMAXSTAM>)
      TAG.MODMAXSTAM=
      MAXSTAM=
   ELSE
      MAXSTAM=<EVAL <MAXSTAM>+<LOCAL.Result>>
   ENDIF
ENDIF

[FUNCTION MODMAXMANA]
LOCAL.Result=<EVAL <ARGS>>
IF (<ISEMPTY <ARGS>>)
   RETURN <EVAL <TAG0.MODMAXMANA>>
ELSE
   TAG.MODMAXMANA=<EVAL <TAG0.MODMAXMANA>+<LOCAL.Result>>
   IF !(<TAG0.MODMAXMANA>)
      TAG.MODMAXMANA=
      MAXMANA=
   ELSE
      MAXMANA=<EVAL <MAXMANA>+<LOCAL.Result>>
   ENDIF
ENDIF


////////////
// Events //
////////////

[EVENTS e_Undead]
ON=@EnvironChange
   Return 0
   // Enter "//" before Return 0, if you want to make script working
   // i like the dark
   if (<sector.isdark>) || (<flags>& (statf_nightsight|statf_indoors))
      if (!<tag0.lightstr>)
         return 0
      endif
      anim 011
      bark 4
      str=<tag.lightstr>   // restore me.
      hits=<str>
      tag.lightstr=
      karma=<tag0.lightkarma>
      tag.lightkarma=//just dispose of this.
      fame=<tag0.lightfame>
      tag.lightfame=
      flags ^= statf_conjured   // no loot if killed.
      return 0
   endif
   // i can't live in light areas. weaken me ? or destroy me ?
   anim 014
   bark 4
   if (<tag0.lightstr>)
      return 0
   endif
   if ( <flags>&statf_conjured   )
      remove
      return 1
   endif
   flags |= statf_conjured   // no loot if killed.
   tag.lightstr=<str>
   str=1
   hits=1   // very weak.
   tag.lightkarma=<karma>   // killing it means nothing now.
   karma=-2
   tag.lightfame=<fame>
   fame=10
   return 0

[EVENTS e_polymorphed_lich]
ON=@SPELLEFFECT
// Dispell spells will return a polymorphed lich into lich.
IF ((<SERV.SPELL.<ARGN1>.DEFNAME> == s_dispel) || (<SERV.SPELL.<ARGN1>.DEFNAME> == s_mass_dispel))
   TRYSRC <I.UID> SRC.EFFECT 2,i_fx_smoke_small,16,10,0
   I.BODY = c_lich
   I.EVENTS -e_polymorphed_lich
   TIMERF <I.TAG.BEHAVIOURDELAY>,I.f_lich_polymorph
ENDIF
RETURN 0

[EVENTS e_lich_death]
// Check for summoned skeletons to remove him.
ON=@DEATH
FOR 0 <EVAL <TAGCOUNT> - 1>
    // Loop hover tags. If the value is the UID of a c_skeleton, dispel it.
    LOCAL.UID = <TAGAT.<LOCAL._FOR>.VALUE>
    IF (<UID.<LOCAL.UID>>)
        IF (<UID.<LOCAL.UID>.DEFNAME> == c_skeleton)
            UID.<LOCAL.UID>.HITS = 0
        ENDIF
    ENDIF
ENDFOR
RETURN 0

[EVENTS e_skeleton_summoned_by_lich]
ON=@SPELLEFFECT
// Dispell spells will remove summoned skeletons.
IF ((<SERV.SPELL.<ARGN1>.DEFNAME> == s_dispel) || (<SERV.SPELL.<ARGN1>.DEFNAME> == s_mass_dispel))
   I.HITS = 0
ENDIF
RETURN 0

ON=@DEATH
REF1 = <TAG.MASTER>
// First check if c_lich exists.
IF (!<REF1>)
    RETURN 0
ENDIF
// We must check if the f_lich_summon_skeletons needs to be invoked.
LOCAL.LIMIT = <REF1.CURFOLLOWER> + <I.FOLLOWERSLOTS>
IF (<LOCAL.LIMIT> > <REF1.MAXFOLLOWER>)
    REF1.TIMERF <REF1.TAG.BEHAVIOURDELAY>,f_lich_summon_skeletons
ENDIF
REF1.TAG.SLOT_<I.UID> =
REF1.CURFOLLOWER = <EVAL <REF1.CURFOLLOWER> - <I.FOLLOWERSLOTS>>
RETURN 0

[EVENTS e_Carnivores]
// weak carnivores.

[EVENTS e_Carnivores2]
// normal carnivores.

[EVENTS e_Carnivores3]
// strong carnivores.

[EVENTS e_Terathan]

[EVENTS e_Ophidian]

[EVENTS e_Horses]

[EVENTS e_Notoriety]

[EVENTS e_Ostards]

[EVENTS e_Minotaurs]

[EVENTS e_poisonbite]
//Poison bite attack
ON=@Hit
   IF !(<SRC.FLAGS> & statf_poisoned)
      SRC.SPELLEFFECT s_poison,<POISONING>,1,<UID>
//      SRC.EFFECT 3,i_fx_sparkle,1,16,0,044
//      SRC.SOUND snd_spell_poison
   ENDIF

[EVENTS e_poisoned_spit]
//Poisoned Spit Defense
ON=@GetHit
   REF1=<SRC> // Source of damage
   REF2=<UID> // Victim of damage (the spitter)
   IF (<MANA> > 15) && (<DISTANCE> > 2) && !(<SRC.FLAGS> & statf_poisoned) && (<REF1> != <REF2>)
      MANA -= 15
      TRYSRC <REF2> EFFECT 0,i_fx_fireball,10,16,0,044,4
      REF1.SPELLEFFECT s_poison,<REF2.POISONING>,<REF2>
      REF1.DAMAGE <R15,25> <DEF.dam_poison> <QVAL <REF2>?<REF2>:0>
      REF1.SOUND snd_spell_poison
      REF1.SYSMESSAGELOC color_text,1070821,<NAME>//"~ spits a poisonous substance at you!"
   ENDIF

[EVENTS e_solen_spit]
//Acidic Spit Defense
ON=@GetHit
   REF1=<SRC>
   REF2=<UID>
   IF (<MANA> > 15) && (<DISTANCE> > 2) && (<REF1> != <REF2>)
      MANA -= 15
      TRYSRC <REF2> EFFECT 0,i_fx_fireball,10,16,0,044,4
      REF1.DAMAGE <R15,25> <DEF.dam_acidic> <QVAL <UID>?<UID>:0>
      REF1.SYSMESSAGELOC color_text,1071966//"The solen's damaged acid sac squirts acid!"
      REF1.SOUND snd_spell_poison
      SERV.NEWITEM i_pool_acid
      NEW.P=<REF1.P>
      NEW.ATTR=attr_decay|attr_move_never
      NEW.TIMER={5 10}
      NEW.LINK=<UID>
   ENDIF

[ITEMDEF i_pool_acid]
ID=021c
NAME=acid pool
TYPE=t_normal
CATEGORY=Monster
SUBSECTION=Attack
DESCRIPTION=Acid Pool
ON=@Create
   ATTR=attr_decay|attr_move_never
   TIMER={4 8}
ON=@Step
   IF (<SRC.ISPLAYER>)
      SRC.DAMAGE <R10,15> <DEF.dam_acidic> <QVAL <LINK>?<LINK>:0>
      SRC.SYSMESSAGELOC color_text,1077483//"The acid burns you!"
      //FIXME: Damage a random equipped item...
   ENDIF

[EVENTS e_bleed_attack]
ON=@Hit
   //Bleed attack
   IF (<MANA> >= 25)&&(RAND(10)==1)
      MANA -= 25
      SERV.NEWITEM=i_bleed_timer
      NEW.LINK=<UID>
      SRC.EQUIP <NEW>
   ENDIF

[ITEMDEF i_bleed_timer]
//1060202//"*Bleeding*"
ID=0122a
NAME=bleed timer
TYPE=t_eq_script
LAYER=layer_special
WEIGHT=0
ON=@Create
   ATTR=attr_decay
   MORE1=6
ON=@Equip
   ATTR=attr_decay
   TIMER=2
ON=@Timer
   IF (<CONT>)
      IF !(<CONT.HITS>)
         MORE1=0
      ELSE
         MORE1 -= 1
      ENDIF
      DOSWITCH <MORE1>
         BEGIN // MORE1=0
            CONT.SYSMESSAGELOC color_text,1060167//"The bleeding wounds have healed, you are no longer bleeding!"
            REMOVE
         END
         BEGIN // MORE1=1
            CONT.EMOTE bleed slowly
            CONT.DAMAGE {1 2} <DEF.dam_god> <QVAL <LINK>?<LINK>:0>
            TIMER=2
         END
         BEGIN // MORE1=2
            CONT.EMOTE bleed slowly
            CONT.DAMAGE {2 4} <DEF.dam_god> <QVAL <LINK>?<LINK>:0>
            TIMER=2
         END
         BEGIN // MORE1=3
            CONT.EMOTE bleed moderately
            CONT.DAMAGE {3 6} <DEF.dam_god> <QVAL <LINK>?<LINK>:0>
            TIMER=2
         END
         BEGIN // MORE1=4
            CONT.EMOTE bleed heavily
            CONT.DAMAGE {4 9} <DEF.dam_god> <QVAL <LINK>?<LINK>:0>
            TIMER=2
         END
         BEGIN // MORE1=5
            CONT.EMOTE bleed profusely
            CONT.DAMAGE {5 12} <DEF.dam_god> <QVAL <LINK>?<LINK>:0>
            TIMER=2
         END
      ENDDO
   ENDIF
   RETURN 1

[ITEMDEF i_summon_mem]
ID=i_rune_summon_creature
NAME=custom summon memory
TYPE=t_spell
LAYER=41
WEIGHT=0
ON=@Create
   MOREX=40
   MOREY=900
   TIMER=20
   ATTR=026

[FUNCTION f_NPCRemovalTimer]
SERV.NEWITEM i_removetimer_mem
EQUIP <NEW>
NEW.TIMER=<ARGN1>

[ITEMDEF i_removetimer_mem]
ID=i_memory
NAME=remove timer
TYPE=t_eq_script
ON=@Timer
   CONT.REMOVE
   RETURN 1

[ITEMDEF i_mem_vicious_bite]
ID=0e23
NAME=Vicious bite memory
TYPE=t_eq_script
LAYER=layer_special
WEIGHT=0
ON=@Create
   ATTR=attr_decay
   TIMER=2
ON=@Timer
   IF (<MORE1> > 0)
      MORE1 -= 1
      CONT.DAMAGE 5 <DEF.dam_poison> <QVAL <LINK>?<LINK>:0>
      CONT.SYSMESSAGELOC color_text,1112473//"Your vicious wound is festering!"
      TIMER=20
      RETURN 1
   ENDIF

[ITEMDEF i_blockheal_timer]
//
// Ideally Healing Spells and Bandages should look for this timer and prevent
// the healing attempt.
//
ID=i_bandage
NAME=block heal timer
TYPE=t_eq_script
LAYER=layer_special
WEIGHT=0
ON=@Equip
   ATTR=attr_decay
   IF (<CONT.NPC>)
      MORE1=12
   ELSE
      MORE1=6
   ENDIF
   TIMER=1
ON=@Timer
   IF (<MORE1>) && !(<CONT.FLAGS> & statf_dead)
      CONT.ACTION = -1 //stop all actions
      MORE1 -= 1
      TIMER=1
   ELSE
      CONT.SYSMESSAGELOC color_text,1060208//"You are no longer mortally wounded."
      REMOVE
   ENDIF
   RETURN 1

[ITEMDEF i_parablow_timer]
ID=01d8c
NAME=paralyzing blow timer
TYPE=t_eq_script
LAYER=layer_special
WEIGHT=0
ON=@Equip
   ATTR=attr_decay
   IF (<CONT.NPC>)
      MORE1=6
   ELSE
      MORE1=3
   ENDIF
   CONT.SYSMESSAGELOC color_text,1072221//"You have been hit by a paralyzing blow."
   TIMER=1
ON=@Timer
   IF (<MORE1>) && !(<CONT.FLAGS> & statf_dead)
      CONT.ACTION = -1 //stop all actions
      CONT.FLAGS |= statf_freeze
      MORE1 -= 1
      TIMER=1
   ELSE
      CONT.FLAGS &= ~statf_freeze
      REMOVE
   ENDIF
   RETURN 1

[EVENTS e_angry_fire]

[EOF]
