2018-03-29 17:01:57 -04:00
2019-07-07 20:56:15 +00:00
# include <StdAfx.h>
2018-03-29 17:01:57 -04:00
# include "UseManager.h"
# include "WeenieObject.h"
2018-12-23 09:31:46 -06:00
# include "Animate.h"
2018-03-29 17:01:57 -04:00
# include "World.h"
# include "Container.h"
# include "Player.h"
// TODO fix memory leak with use data
CUseEventData : : CUseEventData ( )
{
}
void CUseEventData : : Update ( )
{
CheckTimeout ( ) ;
2018-12-23 09:31:46 -06:00
if ( _move_to & & InUseRange ( ) )
{
_weenie - > DoForcedMotion ( Motion_Ready ) ;
HandleMoveToDone ( WERROR_NONE ) ;
}
2018-03-29 17:01:57 -04:00
}
void CUseEventData : : SetupUse ( )
{
2018-07-12 14:41:21 -07:00
CWeenieObject * target = GetTarget ( ) ;
2018-12-14 23:09:22 -05:00
if ( target & & _max_use_distance = = FLT_MAX ) //change max use distance only if still the initialized value. Otherwise this has already been defined.)
2018-03-29 17:01:57 -04:00
{
_max_use_distance = target - > InqFloatQuality ( USE_RADIUS_FLOAT , 0.0 ) ;
}
_timeout = Timer : : cur_time + 15.0 ;
}
void CUseEventData : : Begin ( )
{
SetupUse ( ) ;
if ( _target_id )
{
2018-07-12 14:41:21 -07:00
CWeenieObject * target = GetTarget ( ) ;
2018-03-29 17:01:57 -04:00
if ( ! target )
{
Cancel ( WERROR_OBJECT_GONE ) ;
return ;
}
if ( target - > IsContained ( ) )
{
bool bInViewedContainer = false ;
2018-07-12 14:41:21 -07:00
if ( ! _weenie - > FindContainedItem ( target - > GetID ( ) ) )
2018-03-29 17:01:57 -04:00
{
bool bInViewedContainer = false ;
2018-07-12 14:41:21 -07:00
if ( CContainerWeenie * externalContainer = target - > GetWorldTopLevelContainer ( ) )
2018-03-29 17:01:57 -04:00
{
2018-07-12 14:41:21 -07:00
if ( externalContainer - > _openedById = = _weenie - > GetID ( ) )
2018-03-29 17:01:57 -04:00
{
bInViewedContainer = true ;
}
}
if ( ! bInViewedContainer )
{
Cancel ( WERROR_OBJECT_GONE ) ;
return ;
}
}
OnReadyToUse ( ) ;
}
else
{
if ( InUseRange ( ) )
{
OnReadyToUse ( ) ;
}
else
{
MoveToUse ( ) ;
}
}
}
else
{
OnReadyToUse ( ) ;
}
}
void CUseEventData : : MoveToUse ( )
{
_move_to = true ;
MovementParameters params ;
2018-07-15 19:07:37 -05:00
params . min_distance = _max_use_distance ;
2018-07-11 04:53:32 +00:00
params . action_stamp = + + _weenie - > m_wAnimSequence ;
_weenie - > last_move_was_autonomous = false ;
2020-02-08 12:15:07 -05:00
//if (CWeenieObject *target = GetTarget())
//{
// if (target->AsPortal())
// {
// params.use_spheres = 0; // if we're using a portal we want to get to the center of it, not collide with it's sphere
// }
//}
2018-07-15 19:07:37 -05:00
2018-07-11 04:53:32 +00:00
_weenie - > MoveToObject ( _target_id , & params ) ;
2018-03-29 17:01:57 -04:00
}
void CUseEventData : : CheckTimeout ( )
{
if ( Timer : : cur_time > _timeout )
{
if ( _move_to )
Cancel ( WERROR_MOVED_TOO_FAR ) ;
2018-12-23 14:24:57 -06:00
else if ( _recall_event )
{
// If you're in the max use range during a recall event, then the recall should still trigger. Otherwise you've moved too far.
if ( InMoveRange ( ) )
OnUseAnimSuccess ( _active_use_anim ) ;
else
Cancel ( WERROR_MOVED_TOO_FAR ) ;
}
2018-03-29 17:01:57 -04:00
else
Cancel ( 0 ) ;
}
}
2018-12-23 14:24:57 -06:00
bool CUseEventData : : InMoveRange ( )
{
return _weenie - > m_Position . distance ( _initial_use_position ) < = _max_use_distance ? true : false ;
}
void CUseEventData : : SetupRecall ( )
{
_max_use_distance = 5.0f ;
_initial_use_position = _weenie - > m_Position ;
_recall_event = true ;
}
2019-07-07 20:56:15 +00:00
void CUseEventData : : Cancel ( uint32_t error )
2018-03-29 17:01:57 -04:00
{
CancelMoveTo ( ) ;
_manager - > OnUseCancelled ( error ) ;
}
void CUseEventData : : CancelMoveTo ( )
{
if ( _move_to )
{
2018-07-12 14:41:21 -07:00
_weenie - > cancel_moveto ( ) ;
_weenie - > Animation_MoveToUpdate ( ) ;
2018-03-29 17:01:57 -04:00
_move_to = false ;
}
}
double CUseEventData : : DistanceToTarget ( )
{
2018-07-12 14:41:21 -07:00
if ( ! _target_id | | _target_id = = _weenie - > GetID ( ) )
2018-03-29 17:01:57 -04:00
return 0.0 ;
2018-07-12 14:41:21 -07:00
CWeenieObject * target = GetTarget ( ) ;
2018-03-29 17:01:57 -04:00
if ( ! target )
return FLT_MAX ;
2018-07-11 04:53:32 +00:00
2020-02-08 12:15:07 -05:00
//if (target->AsPortal())
//{
// return _weenie->DistanceTo(target, false);
//}
2018-07-15 19:07:37 -05:00
2020-03-16 19:52:28 -07:00
return _weenie - > DistanceTo ( target , _max_use_distance > = 0 ) ;
2018-03-29 17:01:57 -04:00
}
double CUseEventData : : HeadingDifferenceToTarget ( )
{
2018-07-12 14:41:21 -07:00
if ( ! _target_id | | _target_id = = _weenie - > GetID ( ) )
2018-03-29 17:01:57 -04:00
return 0.0 ;
2018-07-12 14:41:21 -07:00
CWeenieObject * target = GetTarget ( ) ;
2018-03-29 17:01:57 -04:00
if ( ! target )
return 0.0 ;
2018-07-12 14:41:21 -07:00
return _weenie - > get_heading ( ) ;
2018-03-29 17:01:57 -04:00
}
bool CUseEventData : : InUseRange ( )
{
2018-07-12 14:41:21 -07:00
CWeenieObject * target = GetTarget ( ) ;
if ( target & & ( _weenie - > IsContainedWithinViewable ( target - > GetID ( ) ) ) )
2018-03-29 17:01:57 -04:00
return true ;
2018-07-15 19:07:37 -05:00
if ( ( _max_use_distance + F_EPSILON ) < DistanceToTarget ( ) )
2018-03-29 17:01:57 -04:00
return false ;
return true ;
}
2018-07-12 14:41:21 -07:00
CWeenieObject * CUseEventData : : GetTarget ( )
2018-03-29 17:01:57 -04:00
{
return g_pWorld - > FindObject ( _target_id ) ;
}
2018-07-12 14:41:21 -07:00
CWeenieObject * CUseEventData : : GetTool ( )
2018-03-29 17:01:57 -04:00
{
return g_pWorld - > FindObject ( _tool_id ) ;
}
2018-12-23 12:16:39 +00:00
CWeenieObject * CUseEventData : : GetSourceItem ( )
{
return g_pWorld - > FindObject ( _source_item_id ) ;
}
2019-07-07 20:56:15 +00:00
void CUseEventData : : HandleMoveToDone ( uint32_t error )
2018-03-29 17:01:57 -04:00
{
_move_to = false ;
if ( error )
{
Cancel ( error ) ;
return ;
}
if ( ! InUseRange ( ) )
{
Cancel ( WERROR_TOO_FAR ) ;
return ;
}
OnReadyToUse ( ) ;
}
2019-07-07 20:56:15 +00:00
void CUseEventData : : OnMotionDone ( uint32_t motion , BOOL success )
2018-03-29 17:01:57 -04:00
{
if ( _move_to | | ! _active_use_anim )
return ;
if ( motion = = _active_use_anim )
{
_active_use_anim = 0 ;
if ( success )
{
OnUseAnimSuccess ( motion ) ;
}
else
{
2018-12-23 14:24:57 -06:00
if ( ! _recall_event ) // Don't cancel recall events on motion interrupts, such as jumping.
Cancel ( ) ;
2018-03-29 17:01:57 -04:00
}
}
}
2019-07-07 20:56:15 +00:00
void CUseEventData : : OnUseAnimSuccess ( uint32_t motion )
2018-03-29 17:01:57 -04:00
{
Done ( ) ;
}
2019-07-07 20:56:15 +00:00
void CUseEventData : : Done ( uint32_t error )
2018-03-29 17:01:57 -04:00
{
_manager - > OnUseDone ( error ) ;
}
2019-07-07 20:56:15 +00:00
void CUseEventData : : ExecuteUseAnimation ( uint32_t motion , MovementParameters * params )
2018-03-29 17:01:57 -04:00
{
assert ( ! _move_to ) ;
assert ( ! _active_use_anim ) ;
2018-07-12 14:41:21 -07:00
if ( _weenie - > IsDead ( ) | | _weenie - > IsInPortalSpace ( ) )
2018-03-29 17:01:57 -04:00
{
Cancel ( WERROR_ACTIONS_LOCKED ) ;
return ;
}
_active_use_anim = motion ;
2019-07-07 20:56:15 +00:00
uint32_t error = _weenie - > DoForcedMotion ( motion , params ) ;
2018-03-29 17:01:57 -04:00
if ( error )
{
Cancel ( error ) ;
}
}
2018-10-05 02:47:19 +00:00
bool CUseEventData : : QuestRestrictions ( CWeenieObject * target )
{
2018-12-05 20:26:29 -05:00
std : : string restriction ;
2018-12-05 21:14:03 -05:00
if ( target - > m_Qualities . InqString ( QUEST_RESTRICTION_STRING , restriction ) & & ! restriction . empty ( ) ) //Allows for restrition of pickup if you are NOT flagged. (IE must have flag for use)
2018-12-05 20:26:29 -05:00
{
if ( CPlayerWeenie * player = _weenie - > AsPlayer ( ) )
{
if ( ! player - > InqQuest ( restriction . c_str ( ) ) )
{
_weenie - > DoForcedStopCompletely ( ) ;
Cancel ( WERROR_QUEST_RESRICTION_UNSOLVED ) ; // Sends -> This item requires you to complete a specific quest before you can pick it up!
return true ;
}
}
}
2018-10-05 02:47:19 +00:00
std : : string questString ;
2018-12-05 20:26:29 -05:00
if ( target - > m_Qualities . InqString ( QUEST_STRING , questString ) & & ! questString . empty ( ) ) //Used for restriction of pickup if quest is already solved. Common use is for timer restrictions.
2018-10-05 02:47:19 +00:00
{
if ( _weenie - > InqQuest ( questString . c_str ( ) ) )
{
int timeTilOkay = _weenie - > InqTimeUntilOkayToComplete ( questString . c_str ( ) ) ;
if ( timeTilOkay > 0 )
{
std : : string cdTime = ( " You cannot complete this quest for another " + TimeToString ( timeTilOkay ) + " . " ) ;
_weenie - > SendText ( cdTime . c_str ( ) , LTT_DEFAULT ) ;
}
_weenie - > DoForcedStopCompletely ( ) ;
Cancel ( WERROR_QUEST_SOLVED_TOO_RECENTLY ) ;
return true ;
}
_weenie - > StampQuest ( questString . c_str ( ) ) ;
target - > m_Qualities . SetString ( QUEST_STRING , " " ) ;
}
return false ;
}
2018-03-29 17:01:57 -04:00
void CGenericUseEvent : : OnReadyToUse ( )
{
if ( _do_use_animation )
{
ExecuteUseAnimation ( _do_use_animation ) ;
}
else
{
Finish ( ) ;
}
}
2019-07-07 20:56:15 +00:00
void CGenericUseEvent : : OnUseAnimSuccess ( uint32_t motion )
2018-03-29 17:01:57 -04:00
{
Finish ( ) ;
}
void CGenericUseEvent : : Finish ( )
{
2018-07-12 14:41:21 -07:00
CWeenieObject * target = GetTarget ( ) ;
2018-03-29 17:01:57 -04:00
if ( ! target & & _target_id )
{
Cancel ( WERROR_OBJECT_GONE ) ;
return ;
}
2018-07-12 14:41:21 -07:00
CWeenieObject * tool = GetTool ( ) ;
2018-03-29 17:01:57 -04:00
if ( ! tool & & _tool_id )
{
Cancel ( WERROR_OBJECT_GONE ) ;
return ;
}
int error = WERROR_NONE ;
if ( target )
{
if ( ! InUseRange ( ) )
{
Cancel ( WERROR_TOO_FAR ) ;
return ;
}
2018-11-22 23:37:16 -06:00
// Prevent items like Head of the Homunculus, Wallbound Niffis, Tursh Totem, etc. from being used in packs.
if ( target - > InqIntQuality ( HOOK_GROUP_INT , 0 ) )
{
Cancel ( WERROR_HOOKER_NOT_USEABLE_OFF_HOOK ) ;
return ;
}
2019-02-09 13:25:07 -06:00
2019-07-07 20:56:15 +00:00
uint32_t createWcid ;
2019-02-09 13:25:07 -06:00
if ( target - > m_Qualities . InqDataID ( USE_CREATE_ITEM_DID , createWcid ) )
{
CPlayerWeenie * player = g_pWorld - > FindPlayer ( _weenie - > GetID ( ) ) ;
if ( player )
{
2020-02-01 21:11:57 +00:00
if ( ! player - > SpawnInContainer ( createWcid , target - > InqIntQuality ( USE_CREATE_QUANTITY_INT , 1 ) ) )
2019-02-09 13:25:07 -06:00
{
player - > SendText ( " Not enough pack space! " , LTT_ERROR ) ;
Done ( error ) ;
return ;
}
}
}
2018-03-29 17:01:57 -04:00
if ( _do_use_response )
{
if ( _tool_id )
{
2018-07-12 14:41:21 -07:00
error = tool - > DoUseWithResponse ( _weenie , target ) ;
2018-03-29 17:01:57 -04:00
}
else
{
2018-07-12 14:41:21 -07:00
error = target - > DoUseResponse ( _weenie ) ;
2018-03-29 17:01:57 -04:00
}
}
if ( error = = WERROR_NONE & & _do_use_emote )
{
2018-07-12 14:41:21 -07:00
target - > DoUseEmote ( _weenie ) ;
2018-03-29 17:01:57 -04:00
}
if ( _do_use_message )
{
if ( error = = WERROR_NONE )
{
std : : string useMessage ;
if ( target - > m_Qualities . InqString ( USE_MESSAGE_STRING , useMessage ) )
{
2018-07-12 14:41:21 -07:00
_weenie - > SendText ( useMessage . c_str ( ) , LTT_MAGIC ) ;
2018-03-29 17:01:57 -04:00
}
}
else
{
std : : string failMessage ;
if ( target - > m_Qualities . InqString ( ACTIVATION_FAILURE_STRING , failMessage ) )
{
2018-07-12 14:41:21 -07:00
_weenie - > SendText ( failMessage . c_str ( ) , LTT_MAGIC ) ;
2018-03-29 17:01:57 -04:00
}
}
}
}
Done ( error ) ;
}
void CActivationUseEvent : : OnReadyToUse ( )
{
2018-07-12 14:41:21 -07:00
CWeenieObject * target = GetTarget ( ) ;
2018-03-29 17:01:57 -04:00
if ( target )
{
2018-07-12 14:41:21 -07:00
target - > Activate ( _weenie - > GetID ( ) ) ;
2018-09-07 18:06:53 -05:00
target - > DoUseEmote ( _weenie ) ;
2018-03-29 17:01:57 -04:00
}
Done ( ) ;
}
void CInventoryUseEvent : : SetupUse ( )
{
_max_use_distance = 1.0 ;
_timeout = Timer : : cur_time + 15.0 ;
}
//-------------------------------------------------------------------------------------
void CPickupInventoryUseEvent : : OnReadyToUse ( )
{
2018-07-12 14:41:21 -07:00
CWeenieObject * target = GetTarget ( ) ;
2018-05-02 21:11:29 -05:00
if ( target - > HasOwner ( ) ) {
2018-07-12 14:41:21 -07:00
if ( this - > _target_container_id = = _weenie - > GetID ( ) )
2018-05-02 21:11:29 -05:00
target = target - > GetWorldTopLevelOwner ( ) ;
else
target = g_pWorld - > FindObject ( this - > _target_container_id ) ;
}
float z1 = target - > m_Position . frame . m_origin . z ;
2018-07-12 14:41:21 -07:00
float z2 = _weenie - > m_Position . frame . m_origin . z ;
2018-05-02 21:11:29 -05:00
if ( z1 - z2 > = 1.9 )
ExecuteUseAnimation ( Motion_Pickup20 ) ;
else if ( z1 - z2 > = 1.4 )
ExecuteUseAnimation ( Motion_Pickup15 ) ;
else if ( z1 - z2 > = 0.9 )
ExecuteUseAnimation ( Motion_Pickup10 ) ;
else
ExecuteUseAnimation ( Motion_Pickup ) ;
2018-03-29 17:01:57 -04:00
}
2019-07-07 20:56:15 +00:00
void CPickupInventoryUseEvent : : OnUseAnimSuccess ( uint32_t motion )
2018-03-29 17:01:57 -04:00
{
2018-07-12 14:41:21 -07:00
CWeenieObject * target = GetTarget ( ) ;
2018-03-29 17:01:57 -04:00
if ( ! target & & _target_id )
{
Cancel ( WERROR_OBJECT_GONE ) ;
return ;
}
if ( ! InUseRange ( ) )
{
Cancel ( WERROR_TOO_FAR ) ;
return ;
}
2018-10-05 02:47:19 +00:00
if ( QuestRestrictions ( target ) )
2018-03-29 17:01:57 -04:00
{
2018-10-05 02:47:19 +00:00
return ;
2018-03-29 17:01:57 -04:00
}
2018-07-12 14:41:21 -07:00
bool success = _weenie - > AsPlayer ( ) - > MoveItemToContainer ( _source_item_id , _target_container_id , _target_slot , true ) ;
2018-03-29 17:01:57 -04:00
2018-07-12 14:41:21 -07:00
_weenie - > DoForcedStopCompletely ( ) ;
2018-03-29 17:01:57 -04:00
if ( ! success )
Cancel ( ) ;
else
Done ( ) ;
}
//-------------------------------------------------------------------------------------
void CDropInventoryUseEvent : : OnReadyToUse ( )
{
ExecuteUseAnimation ( Motion_Pickup ) ;
}
2019-07-07 20:56:15 +00:00
void CDropInventoryUseEvent : : OnUseAnimSuccess ( uint32_t motion )
2018-03-29 17:01:57 -04:00
{
2018-07-12 14:41:21 -07:00
CWeenieObject * target = GetTarget ( ) ;
2018-03-29 17:01:57 -04:00
if ( ! target & & _target_id )
{
Cancel ( WERROR_OBJECT_GONE ) ;
return ;
}
if ( ! InUseRange ( ) )
{
Cancel ( WERROR_TOO_FAR ) ;
return ;
}
if ( target - > IsAttunedOrContainsAttuned ( ) )
{
Cancel ( WERROR_ATTUNED_ITEM ) ;
return ;
}
2018-07-12 14:41:21 -07:00
bool success = _weenie - > AsPlayer ( ) - > MoveItemTo3D ( _target_id , true ) ;
2018-05-31 18:00:27 +01:00
2018-07-12 14:41:21 -07:00
_weenie - > DoForcedStopCompletely ( ) ;
2018-03-29 17:01:57 -04:00
if ( ! success )
Cancel ( ) ;
else
Done ( ) ;
}
//-------------------------------------------------------------------------------------
void CMoveToWieldInventoryUseEvent : : OnReadyToUse ( )
{
ExecuteUseAnimation ( Motion_Pickup ) ;
}
2019-07-07 20:56:15 +00:00
void CMoveToWieldInventoryUseEvent : : OnUseAnimSuccess ( uint32_t motion )
2018-03-29 17:01:57 -04:00
{
2018-07-12 14:41:21 -07:00
CWeenieObject * target = GetTarget ( ) ;
2018-03-29 17:01:57 -04:00
if ( ! target & & _target_id )
{
Cancel ( WERROR_OBJECT_GONE ) ;
return ;
}
if ( ! InUseRange ( ) )
{
Cancel ( WERROR_TOO_FAR ) ;
return ;
}
2018-10-05 02:47:19 +00:00
if ( QuestRestrictions ( target ) )
2018-03-29 17:01:57 -04:00
{
2018-10-05 02:47:19 +00:00
return ;
2018-03-29 17:01:57 -04:00
}
2018-07-12 14:41:21 -07:00
bool success = _weenie - > AsPlayer ( ) - > MoveItemToWield ( _sourceItemId , _targetLoc , true ) ;
2018-03-29 17:01:57 -04:00
2018-07-12 14:41:21 -07:00
_weenie - > DoForcedStopCompletely ( ) ;
2018-03-29 17:01:57 -04:00
if ( ! success )
Cancel ( ) ;
else
Done ( ) ;
}
//-------------------------------------------------------------------------------------
void CStackMergeInventoryUseEvent : : OnReadyToUse ( )
{
ExecuteUseAnimation ( Motion_Pickup ) ;
}
2019-07-07 20:56:15 +00:00
void CStackMergeInventoryUseEvent : : OnUseAnimSuccess ( uint32_t motion )
2018-03-29 17:01:57 -04:00
{
2018-07-12 14:41:21 -07:00
CWeenieObject * target = GetTarget ( ) ;
2018-03-29 17:01:57 -04:00
if ( ! target & & _target_id )
{
Cancel ( WERROR_OBJECT_GONE ) ;
return ;
}
if ( ! InUseRange ( ) )
{
Cancel ( WERROR_TOO_FAR ) ;
return ;
}
2018-10-05 02:47:19 +00:00
if ( QuestRestrictions ( target ) )
2018-03-29 17:01:57 -04:00
{
2018-10-05 02:47:19 +00:00
return ;
2018-03-29 17:01:57 -04:00
}
2019-07-07 20:56:15 +00:00
uint32_t owner = 0 ;
2018-09-28 19:07:44 -07:00
if ( target - > m_Qualities . InqInstanceID ( OWNER_IID , owner ) & & owner ! = _weenie - > GetID ( ) )
{
_weenie - > NotifyInventoryFailedEvent ( _sourceItemId , WERROR_OBJECT_GONE ) ;
_weenie - > DoForcedStopCompletely ( ) ;
2018-03-29 17:01:57 -04:00
Cancel ( ) ;
2018-09-28 19:07:44 -07:00
}
2018-03-29 17:01:57 -04:00
else
2018-09-28 19:07:44 -07:00
{
bool success = _weenie - > AsPlayer ( ) - > MergeItem ( _sourceItemId , _targetItemId , _amountToTransfer , true ) ;
_weenie - > DoForcedStopCompletely ( ) ;
if ( ! success )
Cancel ( ) ;
else
Done ( ) ;
}
2018-03-29 17:01:57 -04:00
}
//-------------------------------------------------------------------------------------
void CStackSplitToContainerInventoryUseEvent : : OnReadyToUse ( )
{
ExecuteUseAnimation ( Motion_Pickup ) ;
}
2019-07-07 20:56:15 +00:00
void CStackSplitToContainerInventoryUseEvent : : OnUseAnimSuccess ( uint32_t motion )
2018-03-29 17:01:57 -04:00
{
2018-07-12 14:41:21 -07:00
CWeenieObject * target = GetTarget ( ) ;
2018-03-29 17:01:57 -04:00
if ( ! target & & _target_id )
{
Cancel ( WERROR_OBJECT_GONE ) ;
return ;
}
if ( ! InUseRange ( ) )
{
Cancel ( WERROR_TOO_FAR ) ;
return ;
}
2018-10-05 02:47:19 +00:00
if ( QuestRestrictions ( target ) )
2018-03-29 17:01:57 -04:00
{
2018-10-05 02:47:19 +00:00
return ;
2018-03-29 17:01:57 -04:00
}
2018-07-12 14:41:21 -07:00
bool success = _weenie - > AsPlayer ( ) - > SplitItemToContainer ( _sourceItemId , _targetContainerId , _targetSlot , _amountToTransfer , true ) ;
2018-03-29 17:01:57 -04:00
2018-07-12 14:41:21 -07:00
_weenie - > DoForcedStopCompletely ( ) ;
2018-03-29 17:01:57 -04:00
if ( ! success )
Cancel ( ) ;
else
Done ( ) ;
}
//-------------------------------------------------------------------------------------
void CStackSplitTo3DInventoryUseEvent : : OnReadyToUse ( )
{
ExecuteUseAnimation ( Motion_Pickup ) ;
}
2019-07-07 20:56:15 +00:00
void CStackSplitTo3DInventoryUseEvent : : OnUseAnimSuccess ( uint32_t motion )
2018-03-29 17:01:57 -04:00
{
2018-07-12 14:41:21 -07:00
CWeenieObject * target = GetTarget ( ) ;
2018-03-29 17:01:57 -04:00
if ( ! target & & _target_id )
{
Cancel ( WERROR_OBJECT_GONE ) ;
return ;
}
if ( ! InUseRange ( ) )
{
Cancel ( WERROR_TOO_FAR ) ;
return ;
}
2018-10-05 02:47:19 +00:00
if ( QuestRestrictions ( target ) )
2018-03-29 17:01:57 -04:00
{
2018-10-05 02:47:19 +00:00
return ;
2018-03-29 17:01:57 -04:00
}
2018-07-12 14:41:21 -07:00
bool success = _weenie - > AsPlayer ( ) - > SplitItemto3D ( _sourceItemId , _amountToTransfer , true ) ;
2018-03-29 17:01:57 -04:00
2018-07-12 14:41:21 -07:00
_weenie - > DoForcedStopCompletely ( ) ;
2018-03-29 17:01:57 -04:00
if ( ! success )
Cancel ( ) ;
else
Done ( ) ;
}
//-------------------------------------------------------------------------------------
void CStackSplitToWieldInventoryUseEvent : : OnReadyToUse ( )
{
ExecuteUseAnimation ( Motion_Pickup ) ;
}
2019-07-07 20:56:15 +00:00
void CStackSplitToWieldInventoryUseEvent : : OnUseAnimSuccess ( uint32_t motion )
2018-03-29 17:01:57 -04:00
{
2018-07-12 14:41:21 -07:00
CWeenieObject * target = GetTarget ( ) ;
2018-03-29 17:01:57 -04:00
if ( ! target & & _target_id )
{
Cancel ( WERROR_OBJECT_GONE ) ;
return ;
}
if ( ! InUseRange ( ) )
{
Cancel ( WERROR_TOO_FAR ) ;
return ;
}
2018-10-05 02:47:19 +00:00
if ( QuestRestrictions ( target ) )
2018-03-29 17:01:57 -04:00
{
2018-10-05 02:47:19 +00:00
return ;
2018-03-29 17:01:57 -04:00
}
2018-07-12 14:41:21 -07:00
bool success = _weenie - > AsPlayer ( ) - > SplitItemToWield ( _sourceItemId , _targetLoc , _amountToTransfer , true ) ;
2018-03-29 17:01:57 -04:00
2018-07-12 14:41:21 -07:00
_weenie - > DoForcedStopCompletely ( ) ;
2018-03-29 17:01:57 -04:00
if ( ! success )
Cancel ( ) ;
else
Done ( ) ;
}
//-------------------------------------------------------------------------------------
2018-12-23 12:16:39 +00:00
void CGiveEvent : : OnReadyToUse ( )
{
ExecuteUseAnimation ( Motion_Ready ) ;
}
2019-07-07 20:56:15 +00:00
void CGiveEvent : : OnUseAnimSuccess ( uint32_t motion )
2018-12-23 12:16:39 +00:00
{
2018-12-26 16:12:26 -06:00
CWeenieObject * giveTarget = GetTarget ( ) ;
if ( giveTarget )
2018-12-23 12:16:39 +00:00
{
2018-12-26 16:12:26 -06:00
CContainerWeenie * target = giveTarget - > AsContainer ( ) ;
2019-01-25 19:52:17 -06:00
CWeenieObject * source = GetSourceItem ( ) ;
if ( ! target | | ! source )
2018-12-26 16:12:26 -06:00
{
_weenie - > NotifyInventoryFailedEvent ( _source_item_id , WERROR_NONE ) ;
return Done ( WERROR_OBJECT_GONE ) ;
}
2019-01-25 19:52:17 -06:00
_weenie - > AsMonster ( ) - > FinishGiveItem ( target , source , _transfer_amount ) ;
2018-12-26 16:12:26 -06:00
Done ( ) ;
}
2018-12-26 16:15:25 -06:00
else
{
_weenie - > NotifyInventoryFailedEvent ( _source_item_id , WERROR_NONE ) ;
return Done ( WERROR_OBJECT_GONE ) ;
}
2018-12-23 12:16:39 +00:00
}
2019-07-07 20:56:15 +00:00
void CGiveEvent : : Cancel ( uint32_t error ) //This override will capture all Use_Manger/Movement Errors and tack on an inventory failed event so we don't get stuck in a busy state if our give action is cancelled.
2018-12-23 12:16:39 +00:00
{
CancelMoveTo ( ) ;
_weenie - > NotifyInventoryFailedEvent ( _source_item_id , WERROR_NONE ) ;
_manager - > OnUseCancelled ( error ) ;
}
//-------------------------------------------------------------------------------------
void CTradeUseEvent : : OnReadyToUse ( )
{
ExecuteUseAnimation ( Motion_Ready ) ;
}
2019-07-07 20:56:15 +00:00
void CTradeUseEvent : : OnUseAnimSuccess ( uint32_t motion )
2018-12-23 12:16:39 +00:00
{
CPlayerWeenie * target = GetTarget ( ) - > AsPlayer ( ) ;
if ( ! target )
return Done ( WERROR_OBJECT_GONE ) ;
TradeManager * tm = TradeManager : : RegisterTrade ( _weenie - > AsPlayer ( ) , target ) ;
_weenie - > AsPlayer ( ) - > SetTradeManager ( tm ) ;
target - > SetTradeManager ( tm ) ;
Done ( ) ;
}
//-------------------------------------------------------------------------------------
2018-07-12 14:41:21 -07:00
UseManager : : UseManager ( CWeenieObject * weenie )
2018-03-29 17:01:57 -04:00
{
_weenie = weenie ;
}
UseManager : : ~ UseManager ( )
{
SafeDelete ( _useData ) ;
SafeDelete ( _cleanupData ) ;
}
void UseManager : : MarkForCleanup ( CUseEventData * data )
{
if ( _cleanupData & & _cleanupData ! = data )
{
delete _cleanupData ;
}
_cleanupData = data ;
}
void UseManager : : Cancel ( )
{
if ( _useData )
{
_useData - > Cancel ( ) ;
}
}
2019-07-07 20:56:15 +00:00
void UseManager : : OnUseCancelled ( uint32_t error )
2018-03-29 17:01:57 -04:00
{
if ( _useData )
{
if ( ! _useData - > IsInventoryEvent ( ) )
{
2018-07-12 14:41:21 -07:00
_weenie - > NotifyUseDone ( error ) ;
2018-03-29 17:01:57 -04:00
}
else
{
2018-07-12 14:41:21 -07:00
_weenie - > NotifyInventoryFailedEvent ( _useData - > _target_id , error ) ;
2018-03-29 17:01:57 -04:00
}
MarkForCleanup ( _useData ) ;
_useData = NULL ;
}
}
2019-07-07 20:56:15 +00:00
void UseManager : : OnUseDone ( uint32_t error )
2018-03-29 17:01:57 -04:00
{
if ( _useData )
{
if ( ! _useData - > IsInventoryEvent ( ) )
{
2018-07-12 14:41:21 -07:00
_weenie - > NotifyUseDone ( error ) ;
2018-03-29 17:01:57 -04:00
}
else
{
}
MarkForCleanup ( _useData ) ;
_useData = NULL ;
}
}
void UseManager : : Update ( )
{
if ( _useData )
{
_useData - > Update ( ) ;
}
SafeDelete ( _cleanupData ) ;
}
2019-07-07 20:56:15 +00:00
void UseManager : : OnDeath ( uint32_t killer_id )
2018-03-29 17:01:57 -04:00
{
Cancel ( ) ;
}
2019-07-07 20:56:15 +00:00
void UseManager : : HandleMoveToDone ( uint32_t error )
2018-03-29 17:01:57 -04:00
{
if ( _useData )
{
_useData - > HandleMoveToDone ( error ) ;
}
}
2019-07-07 20:56:15 +00:00
void UseManager : : OnMotionDone ( uint32_t motion , BOOL success )
2018-03-29 17:01:57 -04:00
{
if ( _useData )
{
_useData - > OnMotionDone ( motion , success ) ;
}
}
bool UseManager : : IsUsing ( )
{
return _useData ! = NULL ? true : false ;
}
2018-12-23 09:31:46 -06:00
bool UseManager : : IsMoving ( )
{
return IsUsing ( ) & & _useData - > _move_to ! = 0 ? true : false ;
}
2018-03-29 17:01:57 -04:00
void UseManager : : BeginUse ( CUseEventData * data )
{
if ( _useData )
{
// already busy
if ( ! data - > IsInventoryEvent ( ) )
{
2018-07-12 14:41:21 -07:00
_weenie - > NotifyWeenieError ( WERROR_ACTIONS_LOCKED ) ;
_weenie - > NotifyUseDone ( 0 ) ;
2018-03-29 17:01:57 -04:00
}
else
{
2018-07-12 14:41:21 -07:00
_weenie - > NotifyInventoryFailedEvent ( _useData - > _target_id , WERROR_ACTIONS_LOCKED ) ;
2018-03-29 17:01:57 -04:00
}
delete data ;
return ;
}
_useData = data ;
_useData - > Begin ( ) ;
}