[DEFNAME TAMING_SETTINGS]
TAMING_RELEASED_REMOVETIME 60*60*24
TAMING_BONDED_CHECK_TIMER 3

[FUNCTION F_PETCONTROL]
IF (<TAMING> > 29.1)
	IF (!(<ARGN1>))
	REF1=<SRC>
	ELSE
	REF1=<ARGN1>
	ENDIF
FLOAT.EFFECTIVETAMING=<FLOATVAL ((<REF1.TAMING>*4)+<REF1.ANIMALLORE>)/5>
	IF (<BASEID> == c_m_lesser_hiryu)
	FLOAT.BUSHIDOEFFECTIVETAMING=<FLOATVAL <REF1.BUSHIDO>>
		IF (<FLOAT.EFFECTIVETAMING> < <FLOAT.BUSHIDOEFFECTIVETAMING>)
		FLOAT.EFFECTIVETAMING=<FLOAT.BUSHIDOEFFECTIVETAMING>
		ENDIF
	ENDIF
	IF (<FLOAT.EFFECTIVETAMING> <= <FLOATVAL <TAMING>>)
	FLOAT.PETCONTROL=<FLOATVAL (70+(14*(<FLOAT.EFFECTIVETAMING>-<TAMING>)))>
		IF (<FLOAT.PETCONTROL> < <FLOATVAL 10>)
		FLOAT.PETCONTROL=<FLOATVAL 10>
		ENDIF
	ELSE
	FLOAT.PETCONTROL=<FLOATVAL (70+(6*(<FLOAT.EFFECTIVETAMING>-<TAMING>)))>
		IF (<FEVAL <FLOAT.PETCONTROL>> > 100)
		FLOAT.PETCONTROL=<FLOATVAL 100>
		ENDIF
	ENDIF
ELSE
FLOAT.PETCONTROL=<FLOATVAL 100>
ENDIF
RETURN <FEVAL <FLOAT.PETCONTROL>>

[ITEMDEF i_taming_timer]
NAME=Taming Timer
ID=i_memory
TYPE=t_eq_script
LAYER=layer_special

ON=@create
attr=attr_invis|attr_decay

on=@equip
LOCAL.TIME=<EVAL (200-((<SRC.TAMING>/20)+(<SRC.ANIMALLORE>/20)))/15>
IF (<LOCAL.TIME> > 10)
LOCAL.TIME=10
ENDIF
MORE1=<LOCAL.TIME>
TIMER=1

ON=@Timer
IF (<LINK.ISEVENT.e_champion_minion>)
CONT.SYSMESSAGE @946,3,1 You can't tame a Champion Spawned creature!
CONT.EVENTS -e_taming_pod
REMOVE
RETURN 1
ENDIF
IF (<LINK.FLAGS>&statf_pet)
CONT.sysmessageloc -1,502467
CONT.EVENTS -e_taming_pod
REMOVE
RETURN 1
ENDIF
IF ((<LINK.DISTANCE <CONT>> > 4) || (!(<CONT.CANSEELOS <LINK>>)))
CONT.sysmessageloc -1,502795
CONT.EVENTS -e_taming_pod
REMOVE
RETURN 1
ENDIF
IF (((<LINK.TAG0.FOLLOWERCONSUME>) && (<EVAL <CONT.CURFOLLOWER>+<LINK.TAG0.FOLLOWERCONSUME>> > 5)) || ((!<LINK.TAG0.FOLLOWERCONSUME>) && (<EVAL <CONT.CURFOLLOWER>+1> > 5)))
CONT.sysmessage @946,3,1 You must release some pets before taming this one.
CONT.EVENTS -e_taming_pod
REMOVE
RETURN 1
ENDIF
IF !(<more1>)
	IF (<LINK.ISPK>)
	LOCAL.DIFF=<EVAL (<LINK.TAMING>/9)+55>
	ELSE
	LOCAL.DIFF=<EVAL (<LINK.TAMING>/9)+35>
	ENDIF
	IF (<EVAL ((<cont.taming>/2)+(<cont.animallore>/2))/10> >= <R<EVAL <LOCAL.DIFF>+250>>) || (<CONT.ISGM>)
	TRYSRC <CONT> LINK.MESSAGE @,,2 502799
		IF (<LINK.ISEVENT.E_PEACEMAKED>)
		LINK.TIMERF CLEAR
		LINK.EVENTS -E_PEACEMAKED
		ENDIF
	CONT.TAME <LINK>
	LINK.UPDATE
	CONT.SKILLGAIN Taming <EVAL (<LINK.TAMING>/10)+10>
	CONT.EVENTS -e_taming_pod
	REMOVE
	RETURN 1
	ELSE
	CONT.sysmessageloc -1,502798
	CONT.EVENTS -e_taming_pod
		IF (90 >= <R1,100>)
		CONT.SKILLGAIN Taming <EVAL (<LINK.TAMING>/10)+10>
		ENDIF
	REMOVE
	RETURN 1
	ENDIF
ENDIF
MORE1 --
REF1=<CONT.UID>
REF2=<LINK.FINDID.i_released_remove_timer.UID>
REF3=<LINK.FINDID.i_owner_check.UID>
	DORAND 4
	CONT.SAY=@,,2 502790
	CONT.SAY=@,,2 502791
	CONT.SAY=@,,2 502792
	CONT.SAY=@,,2 502793
	ENDDO
CONT.SKILLGAIN AnimalLore <EVAL (<CONT.ANIMALLORE>/10)+1>
IF (<LINK.KARMA> > 6000)
LINK.ATTACK=<CONT.UID>
ENDIF
IF (<REF2>)
REF2.TIMER=<DEF.TAMING_RELEASED_REMOVETIME>
ENDIF
IF (<REF3>)
REF3.TIMER=30
ENDIF
CONT.FACE <LINK>
TIMER=1
RETURN 1

[EVENTS e_taming_pod]
ON=@LogOut
FINDID.i_taming_timer.REMOVE
EVENTS -e_taming_pod

ON=@SkillStart
sysmessageloc -1,502798
FINDID.i_taming_timer.REMOVE
EVENTS -e_taming_pod

ON=@Death
sysmessageloc -1,502798
FINDID.i_taming_timer.REMOVE
EVENTS -e_taming_pod

ON=@SpellCast
sysmessageloc -1,502798
FINDID.i_taming_timer.REMOVE
EVENTS -e_taming_pod

[ITEMDEF i_released_remove_timer]
ID=i_memory
NAME=Released remove
TYPE=T_EQ_SCRIPT

ON=@Timer
CONT.REMOVE
RETURN 1

[ITEMDEF i_bonded_check]
ID=i_memory
NAME=Bonded Check
TYPE=T_EQ_SCRIPT

ON=@Timer
IF (<CONT.UID>)
	IF ((!(<CONT.FLAGS>&statf_pet)) && (!(<CONT.FLAGS>&statf_ridden)))
	CONT.TIMERF 1,REMOVE
	ELIF (<CONT.FOOD> < <EVAL <CONT.MAXFOOD>-10>)
	CONT.TAG.BONDEDTIME=56
	TIMER=<EVAL 60*60*<DEF.TAMING_BONDED_CHECK_TIMER>>
	ELSE
	CONT.TAG0.BONDEDTIME --
		IF (<CONT.TAG0.BONDEDTIME> <= 0)
		CONT.MEMORYFINDTYPE.memory_ipet.LINK.SYSMESSAGELOC -1,1049666
		CONT.EVENTS +e_bonded
		CONT.TAG.BONDED=1
		CONT.UPDATE 1
		LOCAL.BOOGALOO=1
		ENDIF
	ENDIF
	IF (!(<LOCAL.BOOGALOO>))
	TIMER <EVAL 60*60*<DEF.TAMING_BONDED_CHECK_TIMER>>
	ELSE
	REMOVE
	ENDIF
ENDIF
RETURN 1

[ITEMDEF i_owner_check]
ID=i_memory
NAME=Owner Check
TYPE=T_EQ_SCRIPT

ON=@Timer
IF (!(<CONT.TAG0.DONO>))
REF1=<CONT.OWNER> //Owner
ELSE
REF1=<CONT.TAG0.DONO>
ENDIF
IF (<REF1.ISPLAYER>)
	IF (!(<REF1.ISONLINE>)) && (!(<CONT.FLAGS>&STATF_STONE)) && (!(<CONT.FLAGS>&STATF_CONJURED))
	CONT.FLAGS |= <def.statf_insubstantial>
	CONT.STONE 1
	CONT.UPDATE
	ELIF (<REF1.ISONLINE>) && (<CONT.FLAGS>&STATF_STONE)
	CONT.FLAGS &= ~<def.statf_insubstantial>
	CONT.STONE 0
	CONT.UPDATE
	ELIF (<REF1.ISONLINE>) && ((<CONT.DISTANCE <REF1>> > 30) || (<CONT.MAP> != <REF1.MAP>)) && (!(<CONT.FLAGS>&statf_ridden)) && (!(<CONT.FLAGS>&STATF_CONJURED)) && (!(<CONT.TAG0.NOCONTROL>)) && (!(<CONT.ISEVENT.e_animated_dead>))
	CONT.GOUID <REF1>
	ENDIF
ENDIF
TIMER=1
RETURN 1

[FUNCTION tame]
LOCAL.TMP <NEW>
REF1=<ARGS>
REF1.REMOVEALLMEMS memory_war_targ
REF1.FLAGS &= ~statf_war
REF1.TRIGGER @TAME
REF1.FLAGS |= statf_pet
REF1.FINDID.i_released_remove_timer.REMOVE
REF1.FINDID.i_owner_check.REMOVE
REF1.FINDID.i_bonded_check.REMOVE
REF1.TAG.DONO=<UID>
REF1.TAG.OVERRIDE.MOVERATE=20
REF1.SPIRITSPEAK=100.0
REF1.KARMA=4000
REF1.FAME=3000
	IF (<REF1.NPC> == brain_dragon)
	REF1.NPC=brain_monster
	ENDIF
SERV.NEWITEM i_memory
NEW.LINK <UID>
NEW.MORE2 <TIME>
NEW.COLOR 042
NEW.MOREP <REF1.P>
REF1.EQUIP <NEW>

SERV.NEWITEM i_owner_check
NEW.CONT=<REF1.UID>
NEW.TIMER=5


IF ((!(<REF1.TAG0.BONDEDTIME>)) && (!(<REF1.ISEVENT.e_bonded>)))
REF1.TAG.BONDEDTIME=56
SERV.NEWITEM i_bonded_check
NEW.CONT=<REF1.UID>
NEW.TIMER=<EVAL 60*60*<DEF.TAMING_BONDED_CHECK_TIMER>>
ENDIF
IF ((<REF1.TAG0.STATDROPTAME>) && (!(<REF1.TAG0.JADROPOUSTAT>)))
MESSAGE @946,3,1 <REF1.NAME> had his stats droped.
REF1.TAG.JADROPOUSTAT=1
REF1.TAG.CANTRAINSTRTO=<FEVAL <FLOATVAL <REF1.OSTR>*0.60>>
REF1.OSTR -= <EVAL <FLOATVAL <REF1.OSTR>*0.50>/1000000>
REF1.MAXHITS=<EVAL <REF1.OSTR>+1>
ELIF (!(<REF1.TAG0.STATDROPTAME>))
	IF (<REF1.MAXHITS> > 600)
	REF1.MAXHITS=600
	ENDIF
ENDIF
REF1.HITS=<REF1.MAXHITS>
IF !(STRMATCH(*e_Horses*,<REF1.TEVENTS>)) && !(<REF1.ISEVENT.e_horses>)
REF1.EVENTS +E_HORSES
ENDIF
IF (<REF1.TAG0.FOLLOWERCONSUME>)
CURFOLLOWER += <REF1.TAG0.FOLLOWERCONSUME>
ELSE
CURFOLLOWER ++
ENDIF
REF1.HOME -1,-1
REF1.UPDATE
NEW <LOCAL.TMP>

[EVENTS e_bonded]
ON=@Death
SPELLEFFECT S_CURE,1000,<UID>
FLAGS &= ~statf_war
REMOVEALLMEMS memory_war_targ
REMOVEALLMEMS memory_fight
LOCAL.NEW=<NEW>
SERV.NEWITEM i_bonded_remove
EQUIP <NEW>
TAG.LASTCOR=<COLOR>
COLOR=colors_gray
HITS=<MAXHITS>
FINDID.i_pet_rampage.REMOVE
FLAGS |= <def.statf_invul>
UPDATE 1
ACTION -1
NEW=<LOCAL.NEW>
RETURN 1

ON=@Dclick
IF (<FLAGS>&statf_invul)
RETURN 1
ENDIF

ON=@Attack
IF (<FLAGS>&statf_invul)
ACTION -1
RETURN 1
ENDIF

ON=@Hittry
IF (<FLAGS>&statf_invul)
ACTION -1
RETURN 1
ENDIF

ON=@Spellcast
IF (<FLAGS>&statf_invul)
RETURN 1
ENDIF

ON=@GetHit
IF (<FLAGS>&statf_invul)
RETURN 1
ENDIF

ON=@SpellEffect
IF (<ARGN1> == 59)
FLAGS &= ~statf_invul
FINDID.i_bonded_remove.REMOVE
COLOR=<TAG0.LASTCOR>
TAG.LASTCOR
TIMERF 1,HITS=<EVAL (20*<MAXHITS>)/100>
ENDIF

ON=@ClientToolTip
SRC.ADDCLILOC 1049608
IF (<FLAGS>&statf_invul)
SRC.ADDCLILOC 1074242
ENDIF

ON=@NpcActFight
IF (<FLAGS>&statf_invul)
RETURN 1
ENDIF

[ITEMDEF i_bonded_remove]
ID=i_memory
TYPE=T_EQ_SCRIPT
NAME=Bond remove

ON=@Equip
TIMER=<EVAL 60*60*24>

ON=@Timer
CONT.REMOVE
RETURN 1

[EOF]