[EVENTS e_npcs]
ON=@Click
IF (<TAG0.NAME.HUE>)
LOCAL.COLOR=<TAG0.NAME.HUE>
ELIF ((((<REGION.FLAGS>&region_flag_guarded) || (<REGION.FLAGS>&region_flag_safe)) && ((<BODY>==c_man) || (<BODY>==c_woman) || (<ISVENDOR>))) || (<FLAGS>&statf_invul))
LOCAL.COLOR=04ac
ELIF ((<NOTOGETFLAG <SRC>,0> == 4) || (<NOTOGETFLAG <SRC>,0> == 3) || (<NOTOGETFLAG <SRC>,0> == 6))  //criminal
LOCAL.COLOR=946
ELIF (<NOTOGETFLAG <SRC>,0> == 1)
LOCAL.COLOR=88
ELIF (<NOTOGETFLAG <SRC>,0> == 2)
LOCAL.COLOR=044
ELIF (<NOTOGETFLAG <SRC>,0> == 5)
LOCAL.COLOR=02b
ENDIF
LOCAL.REALNAME=<NAME>
IF (STRMATCH(* the*,<SERV.CHARDEF.<BASEID>.NAME>)) && !(STRMATCH(* the*,<NAME>))
LOCAL.REALNAME .= , <STRSUB <HVAL (StrIndexOf(<SERV.CHARDEF.<BASEID>.NAME>,the,0))> 99 <SERV.CHARDEF.<BASEID>.NAME>>
ENDIF
MESSAGE @<LOCAL.COLOR>,3,1 <LOCAL.REALNAME>
RETURN 1

ON=@NPCActFight //mage AI
IF (<FLOATVAL <HITS>/<MAXHITS>> < <FLOATVAL 0.1>) //Flee to Spawn Point.
	IF (<FLAGS>&STATF_SPAWNED)
		IF (<MAGERY>)
		SPELLEFFECT S_GREATER_HEAL,<MAGERY>,<UID>
		ENDIF
	ACTION=067
	TIMERF 1,GOTO <HOME>
	ENDIF
ENDIF
IF (<MAGERY>)
	IF (<CANSEELOS>) && (<TAG0.LASTCASTING> <= <SERV.TIME>) && (<FLOATVAL 0.35> > <RANDOMDOUBLE>) //harmful spells
		WHILE (!(<LOCAL.SPELL>))
			DORAND 16
				BEGIN
					IF (<SRC.FLAGS>&STATF_CONJURED) && (<FLOATVAL 0.5> > <RANDOMDOUBLE>)
					LOCAL.SPELL=s_dispel
					ENDIF
				END
				BEGIN
					IF (!(<SRC.FINDID.i_rune_curse>)) && (!(<SRC.FINDID.i_rune_feeblemind>)) && (!(<SRC.FINDID.i_rune_weaken>))
					LOCAL.SPELL=s_feeblemind
					ENDIF
				END
				BEGIN
					IF (!(<SRC.FINDID.i_rune_curse>)) && (!(<SRC.FINDID.i_rune_feeblemind>)) && (!(<SRC.FINDID.i_rune_weaken>))
					LOCAL.SPELL=s_weaken
					ENDIF
				END
				BEGIN
					IF (<MAGERY> <= 50.0)
					LOCAL.SPELL=s_magic_arrow
					ENDIF
				END
				BEGIN
					IF (<DISTANCE> <= 2)
					LOCAL.SPELL=s_harm
					ENDIF
				END
				BEGIN
					IF (!(<SRC.FLAGS>&STATF_POISONED))
					LOCAL.SPELL=s_poison
					ENDIF
				END
				BEGIN
					IF (!(<SRC.FINDID.i_rune_curse>)) && (!(<SRC.FINDID.i_rune_feeblemind>)) && (!(<SRC.FINDID.i_rune_weaken>))
					LOCAL.SPELL=s_curse
					ENDIF
				END
				BEGIN
					IF (!(<SRC.FLAGS>&statf_freeze)) && (<DISTANCE> >= 3)
					LOCAL.SPELL=s_paralyze
					ELSE
					LOCAL.SPELL=s_explosion
					ENDIF
				END
				BEGIN
					IF (<MAGERY> >= 70.0) && (<SRC.ISPLAYER>)
					LOCAL.SPELL=s_mana_vampire
					ENDIF
				END
				BEGIN
					IF (<MAGERY> >= 70.0)
					LOCAL.SPELL=s_flamestrike
					ENDIF
				END
			LOCAL.SPELL=s_fireball
			LOCAL.SPELL=s_lightning
			LOCAL.SPELL=s_mind_blast
			LOCAL.SPELL=s_energy_bolt
			LOCAL.SPELL=s_explosion
			LOCAL.SPELL=s_chain_lightning
			ENDDO
		ENDWHILE
	TAG.LASTCASTING=<EVAL <SERV.TIME>+50>
	ANIM <R13,14>
	SRC.SPELLEFFECT <LOCAL.SPELL>,<MAGERY>,<UID>
		IF ((<LOCAL.SPELL> == s_explosion) || (<LOCAL.SPELL> == s_mind_blast)) && (<FLOATVAL 0.2> > <RANDOMDOUBLE>) && (<MAGERY> > 75.0)
		SRC.TIMERF 2,F_GETNPC_COMBOFS <UID>
		TAG.LASTCASTING=<EVAL <SERV.TIME>+68>
		ENDIF
		IF (<SERV.SPELL.<LOCAL.SPELL>.FLAGS>&spellflag_dir_anim) && (!(<SERV.SPELL.<LOCAL.SPELL>.FLAGS>&spellflag_fx_targ))
		EFFECT 0,<SERV.SPELL.<LOCAL.SPELL>.EFFECT_ID>,5,0,1
		ELIF (<SERV.SPELL.<LOCAL.SPELL>.EFFECT_ID>)
		SRC.EFFECT 3,<SERV.SPELL.<LOCAL.SPELL>.EFFECT_ID>,8,30
		ENDIF
	ENDIF
	IF (<FLOATVAL 0.11> > <RANDOMDOUBLE>) && (<TAG0.NextGoodSpell> <= <SERV.TIME>)
		WHILE (!(<LOCAL.SPELL>))
			DORAND 5
				BEGIN
					IF (!(<FINDID.i_rune_bless>))
					LOCAL.SPELL=s_bless
					ENDIF
				END
				BEGIN
					IF (<MAGERY> > 50.0)
					LOCAL.SPELL=s_greater_heal
					ELSE
					LOCAL.SPELL=s_heal
					ENDIF
				END
				BEGIN
					IF (<FLAGS>&STATF_POISONED)
					LOCAL.SPELL=s_archcure
					ENDIF
				END
				BEGIN
					IF (<FLAGS>&STATF_POISONED)
					LOCAL.SPELL=s_cure
					ENDIF
				END
			ENDDO
		ENDWHILE
	TAG.NextGoodSpell=<EVAL <SERV.TIME>+65>
	SPELLEFFECT <LOCAL.SPELL>,<MAGERY>,<UID>
	ENDIF
ENDIF

ON=@Attack
IF (<SRC.ISEVENT.e_young>)
	IF (!(<SRC.TAG0.EVENT.ID>))
		IF (!(0<SRC.ISFIGHTINGME <UID>>))
		ACTION -1
		RETURN 1
		ENDIF
	ENDIF
ENDIF
MANA=0

ON=@PersonalSpace
ARGN1=0

ON=@Death
SERV.LOG <NAME> (<UID>) died at <REGION.NAME>!
REF101=<MEMORYFINDTYPE.memory_ispawned.LINK>
IF (<REF101>)
REF101.TIMER=<EVAL {<REF101.MOREX> <REF101.MOREY>}*60>
ENDIF
IF (<ATTACKER.LAST>)
	IF (<MEMORYFINDTYPE.MEMORY_FIGHT>)
		FORCHARMEMORYTYPE MEMORY_FIGHT
		COLOR |= <DEF.memory_harmedby>
		ENDFOR
	ENDIF
ENDIF
FOR <R1,3>
RANDMAGICITEM
ENDFOR
IF (!(STRCMPI(Doom,<REGION.NAME>)))
NEWLOOT i_reag_daemon_bone,<HVAL (<maxhits>/17)+(<dex>/13)+(<int>/12)>
ENDIF
if (<MAGERY>) && (33 > <R100>)
NEWLOOT=random_scroll
endif
IF (3 > <R100>)
NEWLOOT=i_bracelet_binding
ENDIF
IF (4 > <R100>)
NEWLOOT=i_crystal_ball_pet_summoning
ENDIF
IF (<TAG0.TREASUREMAP.LEVEL>) && (<FLOATVAL <DEF.TREASUREMAPDROPCHANCE>> > <RANDOMDOUBLE>)
NEWLOOT=i_osi_treasure_map
ENDIF

ON=@DeathCorpse
TAG.LASTCASTING=
IF (STRMATCH(*<BASEID>*,<DEF.UNDEAD_SLAYER>))
ARGO.TAG.UNDEADREMAINS=1
ENDIF
ARGO.TAG.OWNER.FAME=<FAME>
LOCAL.OLDNEW=<NEW>
IF (<ATTACKER>)
REF5=<ATTACKER.MAX>
	IF (!(<FLAGS>&STATF_CONJURED))
	SERV.NEWITEM=i_gold,<EVAL (<maxhits>/14)+(<dex>/10)+(<int>/9)>,<ARGO.UID>
		IF (<REF5.TAG0.GOLDINCREASE>)
		SERV.NEWITEM=i_gold,<R1,<EVAL (<ARGO.RESCOUNT i_gold>*<REF5.TAG0.GOLDINCREASE>)/100>>,<ARGO.UID>
		ENDIF
		IF (<REF5.UID>)
			IF (<REF5.ISPLAYER>)
				IF (<REGION.TAG0.VIRTUEDUNGEON>)
				FLOAT.DROPCHANCE=<FLOATVAL 0.001+(<REF5.LUCK>/500000)>
					IF (<FLOAT.DROPCHANCE> > <RANDOMDOUBLE>)
					LOCAL.OLDNEW=<NEW>
					SERV.NEWITEM <HVAL <DEF.virtue_artifacts>>
					REF5.BOUNCE <NEW>
					REF5.SYSMESSAGELOC -1,1062317
					LOCAL.ALREADYGAVEARTY=1
					NEW=<LOCAL.OLDNEW>
					ENDIF
				ENDIF
				IF (<REF5.GUILD>)
				LOCAL.ALLYPOINTS=<EVAL (<maxhits>/14)+(<dex>/14)+(<int>/14)+(<skilltotal>/200)>
				REF5.GUILD.TAG0.ALLYPOINTS += <LOCAL.ALLYPOINTS>
				REF5.SYSMESSAGE @,3,1 You just gained <dLOCAL.ALLYPOINTS> alliance points for your guild.
				ENDIF
				FOR <R3,4>
					IF (<REF5.LUCK> >= <R<EVAL (220*<dLOCAL._FOR>)+300>>)
					ARGO.RANDMAGICITEM
					ENDIF
				ENDFOR
			ENDIF
		ENDIF
		FOR y 0 <EVAL <ATTACKER>-1>
			IF (<ATTACKER.<dLOCAL.Y>>)
				IF (<ATTACKER.<dLOCAL.Y>.DAM>)
				REF400=<ATTACKER.<dLOCAL.Y>>
					//Looting Rights
					IF (!(<REF400.ISINPARTY>))
					ARGO.TAG.LOOTRIGHTLIST .= <REF400>;
					ELSE
					//get party members
					ARGO.TAG.LOOTRIGHTLIST .= <REF400.F_LIST_ALLPARTYMEMBERS>
					ENDIF
					//Treasures of Tokuno
					IF (<DEF0.ToTs_Are_Active>)
					LOCAL.POINTS=<REF400.dTAG0.ToTPoints>
					FLOAT.FAME=<FLOATVAL ((<FAME>*1.1)*(1+((SQRT(<REF400.LUCK>))/100)>
					LOCAL.POINTS=<EVAL <LOCAL.POINTS>+(<FEVAL <FLOAT.FAME>>)>
					REF400.TAG.ToTPoints=<dLOCAL.POINTS>
					FLOAT.CONSTA=0.000863
					FLOAT.CONSTB=0.000004
					FLOAT.CHANCE=<FLOATVAL (<FLOAT.CONSTA>*(10@(<FLOAT.CONSTB>*<dLOCAL.POINTS>)))>
						IF (<FLOAT.CHANCE> > <RANDOMDOUBLE>)
						REF400.SYSMESSAGELOC -1,1062317
						REF400.CREATEITEM LesserTots
						REF400.TAG.ToTPoints=
						ENDIF
					ENDIF
					//Quest Handling stuff
					IF (<REF400.TAG0.QUESTS>)
						FOR <REF400.TAG0.QUESTS>
							FOR x 1 <DEF.QUEST_<EVAL <REF400.TAG0.QUEST<EVAL <LOCAL._FOR>>.ID>>_OBJECTIVEAMOUNT>
								IF (<DEF.QUEST_<EVAL <REF400.TAG0.QUEST<EVAL <LOCAL._FOR>>.ID>>_OBJECTIVE<EVAL <LOCAL.X>>_TYPE>==2)
									IF (<BASEID> == <STREAT <DEF.QUEST_<EVAL <REF400.TAG0.QUEST<EVAL <LOCAL._FOR>>.ID>>_OBJECTIVE<EVAL <LOCAL.X>>>>)
									LOCAL.SLAY=<REF400.TAG0.QUEST<EVAL <LOCAL._FOR>>.SLAY<STREAT <DEF.QUEST_<EVAL <REF400.TAG0.QUEST<EVAL <LOCAL._FOR>>.ID>>_OBJECTIVE<EVAL <LOCAL.X>>>>>
										IF (<LOCAL.SLAY>)
											IF (!(STRMATCH(*<REF400>;*,<LOCAL.UIDSGIVENKILLCOUNT>)))
												IF !(<ISEMPTY <DEF.QUEST_<EVAL <REF400.TAG0.QUEST<EVAL <LOCAL._FOR>>.ID>>_OBJECTIVE<EVAL <LOCAL.X>>_LOCATION>>)
													IF (STRMATCH(*<DEF.QUEST_<EVAL <REF400.TAG0.QUEST<EVAL <LOCAL._FOR>>.ID>>_OBJECTIVE<EVAL <LOCAL.X>>_LOCATION>*,<REGION.NAME>))
													TRY REF400.TAG.QUEST<dLOCAL._FOR>.SLAY<STREAT <DEF.QUEST_<EVAL <REF400.TAG0.QUEST<dLOCAL._FOR>.ID>>_OBJECTIVE<dLOCAL.X>>>=<HVAL <LOCAL.SLAY>-1>
													ENDIF
												ELSE
												TRY REF400.TAG.QUEST<dLOCAL._FOR>.SLAY<STREAT <DEF.QUEST_<EVAL <REF400.TAG0.QUEST<dLOCAL._FOR>.ID>>_OBJECTIVE<dLOCAL.X>>>=<HVAL <LOCAL.SLAY>-1>
												ENDIF
											LOCAL.UIDSGIVENKILLCOUNT .= <REF400>;
												IF (<EVAL (<LOCAL.SLAY>-1)> <= 0)
												TRY REF400.TAG.QUEST<dLOCAL._FOR>.SLAY<STREAT <DEF.QUEST_<EVAL <REF400.TAG0.QUEST<dLOCAL._FOR>.ID>>_OBJECTIVE<EVAL <LOCAL.X>>>>
												REF400.sysmessageloc -1,1075050
												ELSE
												REF400.sysmessageloc -1,1075051,<EVAL (<LOCAL.SLAY>-1)>
												ENDIF
											ENDIF
										ENDIF
									ENDIF
								ENDIF
							ENDFOR
						ENDFOR
					ENDIF
				ENDIF
			ENDIF
		ENDFOR
	ENDIF
ENDIF
NEW=<LOCAL.OLDNEW>
TIMERF CLEAR

ON=@GetHit
//SERV.LOG Taking damage : <NAME> (<UID>) from <SRC.NAME> (<SRC.UID>)
IF (<SRC.TAG0.SPECIALMOVE>)
LOCAL.COMBATSKILLSUM=<EVAL <SRC.SWORDSMANSHIP>+<SRC.MACEFIGHTING>+<SRC.FENCING>+<SRC.ARCHERY>+<SRC.PARRYING>+<SRC.LUMBERJACKING>+<SRC.STEALTH>+<SRC.POISONING>+<SRC.BUSHIDO>+<SRC.NINJITSU>>
	IF (<LOCAL.COMBATSKILLSUM> > 300.0)
	LOCAL.BONUSMANA=10
	ELIF (<LOCAL.COMBATSKILLSUM> > 200.0)
	LOCAL.BONUSMANA=5
	ENDIF
ENDIF
IF (<REGION.SAFE> == 1)
RETURN 0
ENDIF
IF (!(<TAG0.GOTHIT>))
	IF (<FLAGS>&STATF_PET)
		IF (<ISMYPET>)
		RETURN 1
		ENDIF
	ENDIF
	IF ((<SRC.ISPLAYER>) || (<SRC.FLAGS>&STATF_PET))
		IF (((<REGION.FLAGS>&region_flag_guarded) && ((<BODY>==c_man) || (<BODY>==c_woman))) || (((<ISVENDOR>) || (<NPC> == brain_banker)) && (!(<KARMA> < -1000))))
		ARGN1=1
		HITS ++
		RETURN 0
		ENDIF
		IF ((<SRC.REGION.FLAGS>&region_flag_guarded) && (!(<REGION.FLAGS>&region_flag_guarded)))
		GO <HOME>
		SPELLEFFECT S_CURE,1000
		SPELLEFFECT S_DISPEL,1000
		RETURN 1
		ENDIF
		IF (<SRC.ISEVENT.e_young>)
			IF !(0<SRC.ISFIGHTINGME <UID>>)
			SRC.ATTACK <UID>
			ENDIF
		ENDIF
	ENDIF
	IF (<FLAGS>&STATF_FREEZE)
		IF (<FLOATVAL 0.05> > <RANDOMDOUBLE>)
		SPELLEFFECT S_DISPEL,<MAGERY>,<UID>
			IF (<ISNEARTYPE T_SPELL 2>)
				IF (10 > <R100>)
				REMOVESPELLFIELD
				ENDIF
			ENDIF
		ENDIF
	ENDIF
	IF (<TAG0.GOTHITBYSPELL>)
		IF (!(<SRC.ISPLAYER>))
			IF (!(<SRC.EVALUATINGINTEL>))
			SRC.EVALUATINGINTEL=<SRC.MAGERY>
			ENDIF
		ENDIF
	FLOAT.SPELLBASEDAMAGE=<FLOATVAL <R<SERV.SPELL.<dTAG0.GOTHITBYSPELL>.EFFECT>>>
	FLOAT.EVALUATEINTELBONUS=<FLOATVAL (((<SRC.EVALUATINGINTEL>*3)/100)+1)>
	FLOAT.SPELLDAMAGEINCREASE=<FLOATVAL <SRC.INT>/10>
		IF (<SRC.INSCRIPTION> >= 100.0)
		FLOAT.SPELLDAMAGEINCREASE=<FLOATVAL <FLOAT.SPELLDAMAGEINCREASE>+10>
		ENDIF
		IF (<SRC.TAG0.MAGICDAMINCREASE>)
		LOCAL.ITEMSPELLDAMAGEINCREASE=<SRC.TAG0.MAGICDAMINCREASE>
		FLOAT.SPELLDAMAGEINCREASE=<FLOATVAL <FLOAT.SPELLDAMAGEINCREASE>+<dLOCAL.ITEMSPELLDAMAGEINCREASE>>
		ENDIF
	FLOAT.SPELLBASEDAMAGE=<FLOATVAL ((<FLOAT.SPELLBASEDAMAGE>*<FLOAT.EVALUATEINTELBONUS>)*((<FLOAT.SPELLDAMAGEINCREASE>/100)+1))>
	ARGN1=<FEVAL <FLOAT.SPELLBASEDAMAGE>>
		IF (<TAG0.GOTHITBYSPELL> == 12) //harm
			IF (<DISTANCE> == 2)
			ARGN1 /= 2
			ELIF (<DISTANCE> > 2)
			ARGN1 /= 4
			ENDIF
		ENDIF
	TAG.GOTHITBYSPELL
	ENDIF
	IF (<SRC.ISPLAYER>)
		IF (!(<ISEMPTY <SRC.TAG.SLAYERGROUP>>))
			IF (STRMATCH(*<BASEID>*,<DEF.<SRC.TAG0.SLAYERGROUP>_SLAYER>))
			ARGN1 *= 2
			EFFECT 3,i_fx_glow,16,20,,55
			ENDIF
		ENDIF
		IF (!(<ISEMPTY <SRC.TAG.SLAYERGROUP2>>))
			IF (STRMATCH(*<BASEID>*,<DEF.<SRC.TAG0.SLAYERGROUP2>_SLAYER>))
			ARGN1 *= 2
			EFFECT 3,i_fx_glow,16,20,,55
			ENDIF
		ENDIF
	ENDIF
	IF (<MODAR> < 0)
	LOCAL.DEFEND=<EVAL <AC>+<MODAR>>
	ELSE
	LOCAL.DEFEND=<AC>
	ENDIF
	IF (<LOCAL.DEFEND> > 80)
	LOCAL.DEFEND=80
	ENDIF
	IF (<SRC.TAG0.SPECIALMOVE> == 1)
	LOCAL.MANACOST=<FEVAL <FLOATVAL ((30-<dLOCAL.BONUSMANA>)*(1-(<SRC.TAG0.LOWERMANACOST>/100)))>>
		IF (<SRC.MANA> >= <LOCAL.MANACOST>)
		LOCAL.DEFEND=0
		SRC.SYSMESSAGELOC -1,1060076
			IF (<LOCAL.MANACOST> > 0)
			SRC.MANA -= <LOCAL.MANACOST>
			ENDIF
		ELSE
		SRC.SYSMESSAGELOC -1,1060174,<dLOCAL.MANACOST>
		ENDIF
		SRC.TAG.SPECIALMOVE
		SRC.F_CANCELSPECIALMOVE
		SRC.EVENTS -E_SPECIAL_MOVE
	ENDIF
	IF (!(<ARGN2>&<DEF.DAM_GOD>))
	ARGN1=<FEVAL <FLOATVAL <ARGN1>*(1-(<dLOCAL.DEFEND>/100))>>
	ENDIF
	IF (<ARGN2> == 04088)
		IF (<ARGN1> > 22)
		ARGN1=22
		ENDIF
	ENDIF
	TAG.GOTHIT=1
	FINDID.i_rune_paralyze.TIMERD=1
	IF (<FLAGS>&statf_freeze)
	FLAGS &= ~statf_freeze
	ENDIF
	IF (<TAG0.PROVOKER>)
	DAMAGE <ARGN1> <HVAL <ARGN2>|<DEF.DAM_GOD>|<DEF.dam_noreveal>> <TAG0.PROVOKER>
	ELIF (!(<SRC.OWNER>))
	DAMAGE <ARGN1> <HVAL <ARGN2>|<DEF.DAM_GOD>> <SRC>
	ELSE
	DAMAGE <ARGN1> <HVAL <ARGN2>|<DEF.dam_noreveal>|<DEF.DAM_GOD>> <SRC.OWNER>
		IF (<KARMA> >= 0)
		ATTACK <SRC.UID>
		ENDIF
	ENDIF
RETURN 1
ELSE
SRC.TRIGGER @GaveDamage,<def.TAT_AS_ARGN>,<ARGN1>,<ARGN2>,<UID>
TAG.GOTHIT
ENDIF

ON=@SpellEffect
IF (<src> != <UID>)
	IF (<ISRESISTSPELL <ARGN1>>)
		IF (<EVAL <MagicResistance>/20> >= <R1,<EVAL (<ARGN2>/10)+20>>)
		effect 3,i_fx_glow,16,20
		RETURN 1
		ENDIF
		IF (<MAGICRESISTANCE> > 5.0)
		ARGN2 -= <EVAL ((<MAGICRESISTANCE>/4)-5.0)>
		ENDIF
		IF (<ARGN2> < 1.0)
		ARGN2=1.0
		ENDIF
	ENDIF
	IF (<ISDAMAGESPELL <ARGN1>>)
	TAG.GOTHITBYSPELL=<ARGN1>
	ENDIF
ENDIF

ON=@HitTry
MANA=0
IF ((<ACTION> != SKILL_WRESTLING) && (<ARGO.SPEED>))
FLOAT.FINALWEAPONSPEED=<FLOATVAL (<ARGO.SPEED>*(1+(<dTAG0.SWINGINCREASE>/100)))>
ELSE
FLOAT.FINALWEAPONSPEED=<FLOATVAL (50*(1+(<dTAG0.SWINGINCREASE>/100)))>
ENDIF
FLOAT.SWINGSPEED=<FLOATVAL ((80000/((<STAM>+100)*<FLOAT.FINALWEAPONSPEED>))/4)-0.5>
ARGN1=<EVAL <FLOAT.SWINGSPEED>/100000>
IF (<ARGN1> < 12)
ARGN1=12
ENDIF

LOCAL.ANATOMYEVALINT=<EVAL (((<SRC.ANATOMY>+<SRC.EVALUATINGINTEL>)/10)+20)/2>
FLOAT.ATTACKERABILITY=<FLOATVAL ((<I.<SERV.SKILL.<ACTION>.KEY>>+20.0)*(1+(<dLOCAL.HITCHANCEINCREASE>/100)))>
REF1=<SRC.WEAPON>
IF (<REF1.TAG0.USEBESTWEAPONSKILL>)
LOCAL.SKILL1=<REF1.TAG0.USEBESTWEAPONSKILL>
ELSE
LOCAL.SKILL1=<REF1.SKILL>
ENDIF
LOCAL.DEFENSECHANCEINCREASE=<SRC.TAG0.HITCHANCEDECREASE>
IF (<LOCAL.DEFENSECHANCEINCREASE> > 50)
LOCAL.DEFENSECHANCEINCREASE=50
ENDIF
IF (!(<REF1>))
	IF (<EVAL <SRC.WRESTLING>/10> > <LOCAL.ANATOMYEVALINT>)
	FLOAT.DEFENDERABILITY=<FLOATVAL (((<SRC.WRESTLING>+20.0)*(1+(<dLOCAL.DEFENSECHANCEINCREASE>/100)))*2.0)>
	LOCAL.SKILLTOCOMPARE=<SRC.WRESTLING>
	ELSE
	FLOAT.DEFENDERABILITY=<FLOATVAL (((<dLOCAL.ANATOMYEVALINT>+20.0)*(1+(<dLOCAL.DEFENSECHANCEINCREASE>/100)))*2.0)>
	LOCAL.SKILLTOCOMPARE=<LOCAL.ANATOMYEVALINT>
	ENDIF
ELSE
FLOAT.DEFENDERABILITY=<FLOATVAL (((<SRC.<SERV.SKILL.<dLOCAL.SKILL1>.KEY>>+20.0)*(1+(<dLOCAL.DEFENSECHANCEINCREASE>/100)))*2.0)>
LOCAL.SKILLTOCOMPARE=<SRC.<SERV.SKILL.<dLOCAL.SKILL1>.KEY>>
ENDIF
FLOAT.HITCHANCE=<FLOATVAL (<FLOAT.ATTACKERABILITY>/<FLOAT.DEFENDERABILITY>)>
IF (<FLOAT.HITCHANCE> < <FLOATVAL 0.020000>)
FLOAT.HITCHANCE=<FLOATVAL 0.020000>
ENDIF
SKILLGAIN <SERV.SKILL.<ACTION>.KEY> <EVAL <LOCAL.SKILLTOCOMPARE>/10>
SKILLGAIN TACTICS <EVAL <LOCAL.SKILLTOCOMPARE>/10>
IF (<FLOAT.HITCHANCE> > <RANDOMDOUBLE>)
ACTDIFF=500
ELSE
ACTDIFF=-500
ENDIF

IF (<SRC.ISPLAYER>)
IF (<SRC.FINDLAYER.2.TYPE> == T_SHIELD)
LOCAL.BASEPARRYCHANCE=<EVAL (<SRC.PARRYING>/40)>
	IF (<LOCAL.BASEPARRYCHANCE> <= 0)
	LOCAL.BASEPARRYCHANCE=1
	ENDIF
ELIF (<SRC.FINDLAYER.1.ISWEAPON>)
	LOCAL.BUSHIDOGAIN=1
	LOCAL.PARRYNEW=<EVAL (<SRC.PARRYING>*<SRC.BUSHIDO>)/48000>
	LOCAL.PARRYLEGACY=<EVAL <SRC.PARRYING>/80>
		IF (<LOCAL.PARRYNEW> > <LOCAL.PARRYLEGACY>)
		LOCAL.BASEPARRYCHANCE=<EVAL <LOCAL.PARRYNEW>+1>
		ELSE
		LOCAL.BASEPARRYCHANCE=<EVAL <LOCAL.PARRYLEGACY>+1>
		ENDIF
ELIF (<SRC.FINDLAYER.2.ISWEAPON>)
	LOCAL.BUSHIDOGAIN=1
	LOCAL.PARRYNEW=<EVAL (<SRC.PARRYING>*<SRC.BUSHIDO>)/41140>
	LOCAL.PARRYLEGACY=<EVAL <SRC.PARRYING>/80>
		IF (<LOCAL.PARRYNEW> > <LOCAL.PARRYLEGACY>)
		LOCAL.BASEPARRYCHANCE=<EVAL <LOCAL.PARRYNEW>+1>
		ELSE
		LOCAL.BASEPARRYCHANCE=<EVAL <LOCAL.PARRYLEGACY>+1>
		ENDIF
ENDIF
ENDIF
IF (<LOCAL.BASEPARRYCHANCE>)
	SRC.SKILLGAIN Parrying <EVAL <I.<SERV.SKILL.<ACTION>.KEY>>/10>
		IF (<LOCAL.BUSHIDOGAIN>)
		SRC.SKILLGAIN bushido <EVAL <I.<SERV.SKILL.<ACTION>.KEY>>/10>
		ENDIF
	IF (<SRC.PARRYING> >= 100.0) || (<SRC.BUSHIDO> >= 100.0)
	LOCAL.BASEPARRYCHANCE += 5
	ENDIF
	IF (<LOCAL.BASEPARRYCHANCE> > <R100>)
	ACTDIFF=-500
	ENDIF
ENDIF

ON=@Hit
LOCAL.BASEDAMAGE=<R<DAM>>
	IF (<TACTICS> < 100.0)
	FLOAT.TACTICSBONUS=<FLOATVAL <TACTICS>/1.6>
	ELSE
	FLOAT.TACTICSBONUS=<FLOATVAL (<TACTICS>/1.6)+6.25>
	ENDIF
FLOAT.ANATOMYBONUS=<FLOATVAL (<ANATOMY>/2)+5>
	IF (<STR> < 100)
	FLOAT.STRBONUS=<FLOATVAL <STR>*0.3>
	ELSE
	FLOAT.STRBONUS=<FLOATVAL (<STR>*0.3)+5>
	ENDIF
LOCAL.ITEMDAMAGEINCREASE=<dTAG0.DAMINCREASE>
	IF (<LOCAL.ITEMDAMAGEINCREASE> > 125)
	LOCAL.ITEMDAMAGEINCREASE=125
	ENDIF
FLOAT.TOTALDAMAGEBONUS=<FLOATVAL <FLOAT.TACTICSBONUS>+<FLOAT.ANATOMYBONUS>+<FLOAT.LUMBERBONUS>+<FLOAT.STRBONUS>+<dLOCAL.ITEMDAMAGEINCREASE>>
FLOAT.FINALDAMAGE=<FLOATVAL <dLOCAL.BASEDAMAGE>*(1+(<FLOAT.TOTALDAMAGEBONUS>/100))>
ARGN1=<EVAL <FEVAL <FLOAT.FINALDAMAGE>>+1>
ENDIF
IF ((<TAG0.LIFELEECH>) || (<TAG0.STAMLEECH>) || (<TAG0.MANALEECH>))
	LOCAL.REALDEF=<SRC.AC>
	IF ((<LOCAL.REALDEF> > 80) && (!(<SRC.ISPLAYER>)))
	LOCAL.REALDEF=80
	ELIF ((<LOCAL.REALDEF> > 70) && (<SRC.ISPLAYER>))
	LOCAL.REALDEF=70
	ENDIF
LOCAL.DAMAGEGIVEN=<FEVAL <FLOATVAL <ARGN1>*(1-(<dLOCAL.REALDEF>/100))>>
	IF (<TAG0.LIFELEECH>)
	HITS += <R0,<FEVAL <FLOATVAL ((<dLOCAL.DAMAGEGIVEN>*0.45)*(<dTAG0.LIFELEECH>/100))>>>
		IF (<HITS> > <MAXHITS>)
		HITS=<MAXHITS>
		ENDIF
	ENDIF
	IF (<TAG0.STAMLEECH>)
		IF (<TAG0.STAMLEECH> >= <R1,100>)
		STAM += <dLOCAL.DAMAGEGIVEN>
			IF (<STAM> > <MAXSTAM>)
			STAM=<MAXSTAM>
			ENDIF
		ENDIF
	ENDIF
	IF (<TAG0.MANALEECH>)
	MANA += <R0,<FEVAL <FLOATVAL ((<dLOCAL.DAMAGEGIVEN>*0.45)*(<dTAG0.MANALEECH>/100))>>>
		IF (<MANA> > <MAXMANA>)
		MANA=<MAXMANA>
		ENDIF
	ENDIF
ENDIF

/////////////////////////////////////////

[FUNCTION REMOVESPELLFIELD] //dispel a field spell
LOCAL.CASTER=<UID>
FORITEMS 1
	IF (<TYPE> == t_spell)
	SPELLEFFECT S_DISPEL_FIELD,1000,<LOCAL.CASTER>
	ENDIF
ENDFOR

[FUNCTION F_GETNPC_COMBOFS] //Combo!
REF1=<ARGS>
IF (!(<REF1>))
RETURN
ENDIF
IF (<REF1.CANSEELOS <UID>>) && (!(<FLAGS>&STATF_HIDDEN)) && (!(<FLAGS>&statf_invisible))
SPELLEFFECT S_FLAMESTRIKE,<REF1.MAGERY>,<REF1.UID>
ENDIF

[EOF]