2019-07-07 20:56:15 +00:00
# include <StdAfx.h>
2018-03-29 17:01:57 -04:00
# include "Key.h"
# include "UseManager.h"
# include "Player.h"
2019-01-19 19:55:46 -06:00
# include "Config.h"
2018-03-29 17:01:57 -04:00
CKeyWeenie : : CKeyWeenie ( )
{
}
CKeyWeenie : : ~ CKeyWeenie ( )
{
}
2018-07-12 14:41:21 -07:00
int CKeyWeenie : : UseWith ( CPlayerWeenie * player , CWeenieObject * with )
2018-03-29 17:01:57 -04:00
{
CGenericUseEvent * useEvent = new CGenericUseEvent ;
useEvent - > _target_id = with - > GetID ( ) ;
useEvent - > _tool_id = GetID ( ) ;
useEvent - > _max_use_distance = 1.0 ;
player - > ExecuteUseEvent ( useEvent ) ;
return WERROR_NONE ;
}
2018-07-12 14:41:21 -07:00
int CKeyWeenie : : DoUseWithResponse ( CWeenieObject * player , CWeenieObject * with )
2018-03-29 17:01:57 -04:00
{
2018-07-12 14:41:21 -07:00
if ( CPlayerWeenie * player_weenie = player - > AsPlayer ( ) )
2018-03-29 17:01:57 -04:00
{
if ( ! with - > IsLocked ( ) )
{
if ( with - > IsContainer ( ) )
{
return WERROR_CHEST_ALREADY_UNLOCKED ;
}
}
else
{
std : : string lockCode ;
2019-07-07 20:56:15 +00:00
if ( ( with - > m_Qualities . InqString ( LOCK_CODE_STRING , lockCode ) & & ! stricmp ( lockCode . c_str ( ) , InqStringQuality ( KEY_CODE_STRING , " " ) . c_str ( ) ) | | InqBoolQuality ( OPENS_ANY_LOCK_BOOL , FALSE ) ) )
2018-03-29 17:01:57 -04:00
{
DecrementStackOrStructureNum ( ) ;
with - > SetLocked ( FALSE ) ;
with - > EmitSound ( Sound_LockSuccess , 1.0f ) ;
2019-01-19 19:55:46 -06:00
with - > m_Qualities . SetInstanceID ( LAST_UNLOCKER_IID , player - > id ) ;
if ( with - > IsContainer ( ) & & with - > _nextReset < 0 )
{
2019-01-19 22:45:18 -06:00
// Unlocked chests have 10 minutes before the chest resets.
with - > _nextReset = Timer : : cur_time + 600 ;
2019-01-19 19:55:46 -06:00
}
2018-03-29 17:01:57 -04:00
int structureNum = 0 ;
if ( m_Qualities . InqInt ( STRUCTURE_INT , structureNum , TRUE ) & & structureNum > 0 )
{
player - > SendText ( csprintf ( " The %s has been unlocked. \n Your key has %d %s left. " , with - > GetName ( ) . c_str ( ) , structureNum , structureNum ! = 1 ? " uses " : " use " ) , LTT_DEFAULT ) ;
}
else
{
player - > SendText ( csprintf ( " The %s has been unlocked. \n Your key is used up. " , with - > GetName ( ) . c_str ( ) ) , LTT_DEFAULT ) ;
}
return WERROR_NONE ;
}
else
{
return WERROR_CHEST_WRONG_KEY ;
}
}
}
return WERROR_NONE ;
}