[DEFNAME OSITREASURESTUFF]
OSI_TREASURE_CHEST_MONSTER_LVL_1 {c_mongbat 1 c_ratman 1 c_headless 1 c_skeleton 1 c_zombie 1}
OSI_TREASURE_CHEST_MONSTER_LVL_2 {c_m_goblin_mage 1 c_gargoyle 1 c_gazer 1 c_elem_earth 1 c_m_hellhound 1}
OSI_TREASURE_CHEST_MONSTER_LVL_3 {c_liche 1 c_m_ogre_lord 1 c_dread_spider 1 c_elem_air 1 c_elem_fire 1}
OSI_TREASURE_CHEST_MONSTER_LVL_4 {c_dread_spider 1 c_m_liche_lord 1 c_daemon 1 c_m_ogre_lord 1 c_m_gazer_elder 1}
OSI_TREASURE_CHEST_MONSTER_LVL_5 {c_m_liche_lord 1 c_daemon 1 c_m_gazer_elder 1 c_m_elem_poison 1 c_m_elem_blood 1}
OSI_TREASURE_CHEST_MONSTER_LVL_6 {c_ancient_wyrm 1 c_m_balron 1 c_m_elem_poison 1 c_m_elem_blood 1 c_titan 1}
TREASUREMAPDROPCHANCE 0.008

[FUNCTION F_GETMAPLOCATION]
FILE.MODE.READFLAG=1
IF (<FILE.OPEN Data/TreasureMap.cfg>)
LOCAL.LINES=<FILE.FILELINES <FILE.FILEPATH>>
LOCAL.TEXT=<FILE.READLINE <R1,<LOCAL.LINES>>>
FILE.CLOSE
RETURN <LOCAL.TEXT>
ENDIF

[ITEMDEF i_osi_treasure_map]
ID=i_map
TYPE=T_MAP
NAME=treasure map

ON=@Create
TAG.LEVEL=<R1,5> //remove this and set the level on npc death and map addition to make levels appropriate to each npc
IF (<FLOATVAL 0.005> > <RANDOMDOUBLE>)
TAG0.LEVEL ++
ENDIF
MOREP=<F_GETMAPLOCATION> //get random map location from .cfg list
MORE1=((<MOREX>-180)*010000)+(<MOREY>-180)
MORE2=((<MOREX>+180)*010000)+(<MOREY>+180)
PIN=105,105

ON=@ClientToolTip
IF (<ISEMPTY <TAG.DECODER>>)
	IF (<TAG0.LEVEL> != 6)
	SRC.ADDCLILOC <EVAL 1041510+<TAG0.LEVEL>>
	ELSE
	SRC.ADDCLILOC 1063452
	ENDIF
ELSE
	IF (<TAG0.LEVEL> != 6)
	SRC.ADDCLILOC <EVAL 1041516+<TAG0.LEVEL>>
	ELSE
	SRC.ADDCLILOC 1063453
	ENDIF
ENDIF
IF (<ISEVENT.T_ITEM_INSURED>)
SRC.ADDCLILOC 1061682
ENDIF
SRC.ADDCLILOC 1041502 //for somewhere in felucca
IF (!(<ISEMPTY <TAG.COMPLETED>>)
SRC.ADDCLILOC 1041507,<TAG.COMPLETED>
ENDIF
RETURN 1

ON=@DClick
IF (<SRC.MAP> != 0)
SRC.SYSMESSAGE @,3,1 You must be on Felucca to read this map.
RETURN 1
ENDIF
IF (<ISEMPTY <TAG.DECODER>>)
	IF (<CONT> != <SRC.FINDLAYER.layer_pack>) || ((!(<CONT>)) && (<DISTANCE> < 2))
	SRC.MESSAGE @,,2 1019045
	RETURN 1
	ENDIF
	DOSWITCH <EVAL <TAG0.LEVEL>-1>
	LOCAL.REQUIREDSKILL=27.0
	LOCAL.REQUIREDSKILL=71.0
	LOCAL.REQUIREDSKILL=81.0
	LOCAL.REQUIREDSKILL=91.0
	LOCAL.REQUIREDSKILL=100.0
	LOCAL.REQUIREDSKILL=100.0
	ENDDO
	IF (<SRC.CARTOGRAPHY> < <LOCAL.REQUIREDSKILL>)
	SRC.SYSMESSAGE @,,2 503013 // The map is too difficult to attempt to decode.
	ELSE
	FLOAT.CHANCE=<FLOATVAL (<SRC.CARTOGRAPHY>-((<dLOCAL.REQUIREDSKILL>/10)/2))/100>
		IF (<FLOAT.CHANCE> <= <RANDOMDOUBLE>)
		SRC.MESSAGE @03b2,,2 503018 // You fail to make anything of the map.
		ELSE
		SRC.MESSAGE @03b2,,2 503019 // You successfully decode a treasure map!
		SRC.SYSMESSAGELOC -1,503017 // The treasure is marked by the red pin. Grab a shovel and go dig it up!
		TAG.DECODER=<SRC.NAME>
		RESENDTOOLTIP 1
		ENDIF
	SRC.SKILLGAIN Cartography <EVAL (<SRC.CARTOGRAPHY>/10)+1>
	ENDIF
RETURN 1
ELSE
	IF (!(<ISEMPTY <TAG.COMPLETED>>)
	RETURN 1
	ENDIF
ENDIF

ON=@TargOn_Ground
IF !(<SRC.FINDTYPE.t_newtreasure_shovel>)
SRC.SYSMESSAGE @,3,1 You must have a digging tool to dig for treasure.
RETURN 1
ENDIF
IF (<SRC.MINING> >= 100.0)
LOCAL.MAXRANGE=4
ELIF (<SRC.MINING> >= 81.0)
LOCAL.MAXRANGE=3
ELIF (<SRC.MINING> >= 51.0)
LOCAL.MAXRANGE=2
ELSE
LOCAL.MAXRANGE=1
ENDIF
IF (<SRC.P.X> == <MOREX>) && (<SRC.P.Y> == <MOREY>)
SRC.SYSMESSAGELOC -1,503030
RETURN 1
ENDIF
IF (!(<ISEMPTY <TAG.COMPLETED>>))
SRC.SYSMESSAGELOC -1,503028 // The treasure for this map has already been found.
RETURN 1
ELIF (<SRC.TAG0.NoMoveTill>)
SRC.SYSMESSAGELOC -1,503020 // You are already digging treasure.
RETURN 1
ELIF (<ISEMPTY <TAG.DECODER>>)
SRC.SYSMESSAGELOC -1,503031 // You did not decode this map and have no clue where to look for the treasure.
RETURN 1
ELIF (<SRC.DISTANCEP <MOREX>,<MOREY>,<dLOCAL.MAXRANGE>> <= <LOCAL.MAXRANGE>)
TAG.COMPLETED=<SRC.NAME>
SRC.CTAG.DIGGINGTREASURE=4
SRC.TAG.NoMoveTill=<EVAL <SERV.TIME>+40>
SRC.SOUND 0125
SRC.F_START_DIGGING <MOREX>,<MOREY>,<TAG0.LEVEL>
//treasure stuff
ELIF (<SRC.DISTANCEP <MOREX>,<MOREY>,<dLOCAL.MAXRANGE>> <= 10)
SRC.SYSMESSAGELOC -1,503032 //You dig and dig but no treasure seems to be here.
ELSE
SRC.SYSMESSAGELOC -1,501861 //You dig and dig but fail to find any treasure.
ENDIF
RETURN 1

ON=@ContextMenuRequest
IF (<ARGN> == 1)
SRC.AddContextEntry 300,6150
SRC.AddContextEntry 301,6148
ENDIF

ON=@ContextMenuSelect
IF (<ARGN1> == 300)
SRC.DCLICK <UID>
ELIF (<ARGN1> == 301)
TARGETG
SRC.SYSMESSAGELOC -1,503033
ENDIF

[FUNCTION F_SET_TREASURE_CONTENT]
LOCAL.OLDNEW=<NEW>
DOSWITCH <ARGN1>
LOCAL.ITEMS=1
LOCAL.ITEMS=5
LOCAL.ITEMS=10
LOCAL.ITEMS=15
LOCAL.ITEMS=38
LOCAL.ITEMS=50
LOCAL.ITEMS=60
ENDDO
FOR <dLOCAL.ITEMS>
	IF (<FLOATVAL 0.90> > <RANDOMDOUBLE>)
	RANDMAGICITEM
	ELSE
	RANDMAGICITEMGREAT
	ENDIF
ENDFOR
FOR <EVAL 4*<ARGN1>>
SERV.NEWITEM=random_scroll
NEW.CONT=<UID>
ENDFOR
FOR <EVAL 150*<ARGN1>>
SERV.NEWITEM=random_reagent
NEW.CONT=<UID>
ENDFOR
SERV.NEWITEM=i_gold,<EVAL <ARGN1>*2>,<UID>
IF (<ARGN1> == 6) || ((<ARGN1> == 5) && (<FLOATVAL 0.0725> > <RANDOMDOUBLE>)) || ((<ARGN1> == 4) && (<FLOATVAL 0.001> > <RANDOMDOUBLE>))
SERV.NEWITEM=<HVAL <DEF.MINORARTIS>>
NEW.CONT=<UID>
ELSEIF (<FLOATVAL 0.00087> > <RANDOMDOUBLE>)
SERV.NEWITEM=<HVAL <DEF.MINORARTIS>>
NEW.CONT=<UID>
ENDIF
IF (<FLOATVAL 0.005> > <RANDOMDOUBLE>)
SERV.NEWITEM=i_power_scroll,1,<UID>
NEW.MORE1=<HVAL {24 1 33 1}>
ENDIF
NEW=<LOCAL.OLDNEW>

[ITEMDEF i_osi_treasure_chest]
ID=i_chest_metal
NAME=Treasure Chest
TYPE=T_CONTAINER_LOCKED

ON=@DropOn_Self
RETURN 1

ON=@PickUp_Self
IF (<FLOATVAL 0.06> > <RANDOMDOUBLE>)
SERV.NEWNPC <HVAL <DEF.OSI_TREASURE_CHEST_MONSTER_LVL_<dTAG0.LEVEL>>>
NEW.P=<SRC.P>
NEW.HOME=<NEW.P>
NEW.HOMEDIST=5
NEW.REMOVETIMER=<EVAL 60*60>
NEW.FIX
ENDIF

[FUNCTION F_START_DIGGING]
CTAG0.DIGGINGTREASURE --
IF (!(<CTAG0.DIGGINGTREASURE>))
CTAG.DIGGINGTREASURE=
TAG.NOMOVETILL=
LOCAL.OLDNEW=<NEW>
SERV.NEWITEM=0912
NEW.ATTR=attr_move_never|attr_decay
NEW.TIMER=60*60*1
NEW.P=<ARGV[0]>,<ARGV[1]>
NEW.FIX
	IF (<ARGV[0]> == 3417) && (<ARGV[1]> == 2675)
	NEW.Z=51
	ELIF (<ARGV[0]> == 1529) && (<ARGV[1]> == 753)
	NEW.Z=16
	ENDIF
SERV.NEWITEM=0914
NEW.ATTR=attr_move_never|attr_decay
NEW.TIMER=60*60*1
NEW.P=<ARGV[0]>,<ARGV[1]>
NEW.FIX
SERV.NEWITEM=i_osi_treasure_chest
NEW.TYPE=T_CONTAINER_LOCKED
NEW.MORE2=70.0
NEW.TAG.LEVEL=<ARGV[2]> //chest level
NEW.F_SET_TREASURE_CONTENT <NEW.dTAG0.LEVEL>
NEW.ATTR=attr_move_never|attr_decay
NEW.TIMER=60*60*1
NEW.P=<ARGV[0]>,<ARGV[1]>
NEW.FIX
REF1=<NEW.UID>
FOR 3
SERV.NEWNPC <HVAL <DEF.OSI_TREASURE_CHEST_MONSTER_LVL_<REF1.dTAG0.LEVEL>>>
	DORAND 2
	NEW.P=<SRC.P>
	NEW.P=<REF1.P>
	ENDDO
NEW.HOME=<NEW.P>
NEW.HOMEDIST=6
NEW.REMOVETIMER=<EVAL 60*60>
REF1.SOUND=033B
ENDFOR
NEW=<LOCAL.OLDNEW>
RETURN
ELSE
	IF (<CTAG0.DIGGINGTREASURE> == 2)
	SOUND=0125
	ELIF (<CTAG0.DIGGINGTREASURE> == 1)
	SOUND=0126
	ENDIF
TIMERF 1,F_START_DIGGING <ARGV[0]>,<ARGV[1]>,<ARGV[2]>
ENDIF

[TYPEDEF t_newtreasure_shovel]
ON=@DClick
TARGET
SRC.SYSMESSAGELOC -1,503033
RETURN 1

ON=@TargOn_Item
IF (<ARGO.BASEID> != i_osi_treasure_map)
RETURN 1
ENDIF
IF (<TOPOBJ.UID> != <SRC.UID>)
SRC.SYSMESSAGE @,3,1 You must have a digging tool to dig for treasure.
RETURN 1
ENDIF
IF (!(<ISEMPTY <ARGO.TAG.COMPLETED>>))
SRC.SYSMESSAGELOC -1,503028 // The treasure for this map has already been found.
ELIF (<ISEMPTY <ARGO.TAG.DECODER>>)
SRC.SYSMESSAGELOC -1,503031 // You did not decode this map and have no clue where to look for the treasure.
ELIF (<SRC.TAG0.NoMoveTill>)
SRC.SYSMESSAGELOC -1,503020 // You are already digging treasure.
ELSE
ARGO.TARGETG
SRC.SYSMESSAGELOC -1,503033
ENDIF
RETURN 1

[EOF]
