//****************************************************************************
// SPHERE by : Menasoft ©1997-2017
// 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: Sunday, Dec 10, 2017
//
VERSION=0.56d

///////////
// Items //
///////////

[ITEMDEF 09706]
DEFNAME=i_chest_secret
NAME=secret chest
TYPE=t_container
TDATA2=058e
WEIGHT=5.0
CATEGORY=Provisions - Miscellaneous
SUBSECTION=Containers
DESCRIPTION=Secret Chest
DUPELIST=09707

ON=@DClick
IF !(<ISEMPTY <TAG.Password>>)
 IF (<SRC.ISGM>)
  MESSAGE It appears to be locked, but you open it with your godly powers.
  return 0
 ELIF (<TAG0.Player.<SRC>.PasswordTries> >= 3)
  MESSAGE You cannot access the chest now, having exhausted your number of attempts.
  return 1
 ELIF !(<TAG0.Player.<SRC>.PasswordInserted>)
  IF (<SRC.CTAG0.SecretChest.ChangePassword>)
   SRC.SYSMESSAGE You are already operating another chest.
  ELSE
   MESSAGE It appears to be locked.
   MESSAGE Enter the key number to open.
   SDIALOG d_secret_chest
  ENDIF
  return 1
 ENDIF
 MESSAGE You remember the key number of this chest, so you can open this now.
ENDIF

ON=@DropOn_Self
IF !(<ISEMPTY <TAG.Password>>) && !(<TAG0.Player.<SRC>.PasswordInserted>)
 MESSAGE You cannot place items into a locked chest!
 return 1
ENDIF

ON=@ClientTooltip
IF !(<ISEMPTY <TAG.Password>>)
 SRC.ADDCLILOC 1151610	//Locked
ENDIF

ON=@ContextMenuRequest
SRC.AddContextEntry 700,1151608,<QVAL (<TOPOBJ> == <SRC>)? 0:1>  //Set/Edit Key Number
SRC.AddContextEntry 701,1151609,<QVAL (<TOPOBJ> == <SRC>)? 0:1>  //Reset Key Number

ON=@ContextMenuSelect
IF (<TOPOBJ> != <SRC>)
 SRC.SYSMESSAGE You must have the object in your backpack to use it.
 return 1
ELIF (<ARGN> == 700)
 IF (<SRC.CTAG0.SecretChest.ChangePassword>)
  SRC.SYSMESSAGE You are already operating another chest.
 ELSE
  SRC.SYSMESSAGE Edit your key number. If you don't want to change current key number, click CANCEL button.
  SRC.CTAG.SecretChest.ChangePassword=1
  SDIALOG d_secret_chest
 ENDIF
 return 1
ELIF (<ARGN> == 701)
 IF (<ISEMPTY <TAG.Password>>)
  SRC.SYSMESSAGE The number key has not been set on this chest yet.
 ELSE
  SRC.SYSMESSAGE You have reset the number key of this chest. This is unlocked now.
  CLEARTAGS Player
  TAG.Password=
  RESENDTOOLTIP
 ENDIF
 return 1
ENDIF

[ITEMDEF 09707]
//secret chest
DUPEITEM=09706

/////////////
// Dialogs //
/////////////

[DIALOG d_secret_chest]
50,50
ARGS=<SRC.CTAG.SecretChest.PasswordInput>

gumppic 0 0 058d
FOR 0 4
 gumppic <eval 140+(<LOCAL._FOR>*24)> 150 <eval 058f+<ARGV[<LOCAL._FOR>]>>
 button <eval 142+(<LOCAL._FOR>*24)> 140 058c 058c 1 0 <eval 10+<LOCAL._FOR>>
 button <eval 142+(<LOCAL._FOR>*24)> 180 0599 0599 1 0 <eval 20+<LOCAL._FOR>>
ENDFOR
button 83 220 081a 081b 1 0 1
button 270 220 0819 0818 1 0 0

[DIALOG d_secret_chest BUTTON]
ON=0
SRC.CTAG.SecretChest.ChangePassword=

ON=1
IF (<SRC.CTAG0.SecretChest.ChangePassword>)
 TAG.Password=<MD5HASH <SRC.CTAG.SecretChest.PasswordInput>>
 SRC.CTAG.SecretChest.ChangePassword=
 SRC.CTAG.SecretChest.PasswordInput=
 RESENDTOOLTIP
 return 1
ELIF (STRCMP("<TAG.Password>","<MD5HASH <SRC.CTAG.SecretChest.PasswordInput>>"))
 TAG0.Player.<SRC>.PasswordTries ++
 SRC.SYSMESSAGE The number which you have entered is wrong. You still can't open this chest...
 IF (<TAG0.Player.<SRC>.PasswordTries> >= 3)
  SRC.SYSMESSAGE You have exhausted your unlock attempts for this chest; you must wait 24 hours to try again.
 ELSE
  SRC.SYSMESSAGE Number of tries left: <eval 3-<TAG0.Player.<SRC>.PasswordTries>>
 ENDIF
ELSE
 SRC.SYSMESSAGE You succeed at entering the correct key number; you may open the chest now.
 SRC.CTAG.SecretChest.PasswordInput=
 TAG.Player.<SRC>.PasswordTries=
 TAG.Player.<SRC>.PasswordInserted=1
 OPEN
ENDIF
TIMERF STOP,CLEARTAGS Player.<SRC>
TIMERF 86400,CLEARTAGS Player.<SRC>

ON=10 14
LOCAL.Button=<eval <ARGN>-10>
ARGS=<SRC.CTAG.SecretChest.PasswordInput>
FOR 0 4
 LOCAL.N<dLOCAL._FOR>=<ARGV[<LOCAL._FOR>]>
ENDFOR
LOCAL.N<dLOCAL.Button> ++
IF (<LOCAL.N<dLOCAL.Button>> > 9)
 LOCAL.N<dLOCAL.Button>=0
ENDIF
SRC.CTAG.SecretChest.PasswordInput=<dLOCAL.N0>,<dLOCAL.N1>,<dLOCAL.N2>,<dLOCAL.N3>,<dLOCAL.N4>
SDIALOG d_secret_chest

ON=20 24
LOCAL.Button=<eval <ARGN>-20>
ARGS=<SRC.CTAG.SecretChest.PasswordInput>
FOR 0 4
 LOCAL.N<dLOCAL._FOR>=<ARGV[<LOCAL._FOR>]>
ENDFOR
LOCAL.N<dLOCAL.Button> --
IF (<LOCAL.N<dLOCAL.Button>> < 0)
 LOCAL.N<dLOCAL.Button>=9
ENDIF
SRC.CTAG.SecretChest.PasswordInput=<dLOCAL.N0>,<dLOCAL.N1>,<dLOCAL.N2>,<dLOCAL.N3>,<dLOCAL.N4>
SDIALOG d_secret_chest

[EOF]