123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- class ActionDetachFromTarget: ActionInteractBase
- {
-
- override void CreateConditionComponents()
- {
- m_ConditionItem = new CCINone;
- m_ConditionTarget = new CCTCursor;
- }
-
- void ActionDetachFromTarget()
- {
- m_Text = "#take_to_hands";
- }
-
- override typename GetInputType()
- {
- return ContinuousInteractActionInput;
- }
-
- override ActionData CreateActionData()
- {
- DetachActionData action_data = new DetachActionData;
- return action_data;
- }
-
- int FindSlotIdToDetach(PlayerBase player, ActionTarget target, ItemBase item)
- {
- EntityAI target_entity = EntityAI.Cast(target.GetObject());
-
- if ( player && target_entity )
- {
- array<string> selections = new array<string>();
- target_entity.GetActionComponentNameList( target.GetComponentIndex(),selections );
-
- if ( target_entity && target_entity.GetInventory() && target_entity.GetInventory().AttachmentCount() > 0 )
- {
- for(int i = 0; i < selections.Count(); i++ )
- {
- int target_slot_id = InventorySlots.GetSlotIdFromString( selections[i] );
- EntityAI att = target_entity.GetInventory().FindAttachment(target_slot_id);
-
- if ( att && player.GetInventory().CanAddEntityIntoHands(att) )
- {
- if ( att.CanDetachAttachment( target_entity ) && target_entity.CanReleaseAttachment( att ) )
- return target_slot_id;
- }
- }
- }
- }
- return InventorySlots.INVALID;
- }
-
- override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data = NULL)
- {
- int attSlotId = InventorySlots.INVALID;
- if (!GetGame().IsDedicatedServer() )
- {
- attSlotId = FindSlotIdToDetach(player, target, item);
- }
-
- if ( super.SetupAction( player, target, item, action_data, extra_data))
- {
- if (!GetGame().IsDedicatedServer())
- {
- if(attSlotId != InventorySlots.INVALID)
- {
- DetachActionData action_data_a = DetachActionData.Cast(action_data);
- action_data_a.m_AttSlot = attSlotId;
- return true;
- }
- return false;
- }
- return true;
- }
- return false;
- }
-
- override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
- {
- if ( GetGame().IsMultiplayer() && GetGame().IsServer() ) return true;
-
- return FindSlotIdToDetach(player, target, item) != InventorySlots.INVALID);
- }
-
- override Object GetDisplayInteractObject(PlayerBase player, ActionTarget target)
- {
- int target_slot_id = FindSlotIdToDetach(player, target, null);
- EntityAI target_entity = EntityAI.Cast( target.GetObject() );
-
- if(target_slot_id != InventorySlots.INVALID)
- {
- return target_entity.GetInventory().FindAttachment(target_slot_id);
- }
- return null;
- }
-
- override void OnExecute(ActionData action_data)
- {
- if (GetGame().IsDedicatedServer())
- {
- ClearActionJuncture(action_data);
- return;
- }
-
- Process(action_data);
- }
- void Process( ActionData action_data )
- {
- ClearInventoryReservationEx(action_data);
-
- DetachActionData action_data_a = DetachActionData.Cast(action_data);
- EntityAI target_entity = EntityAI.Cast( action_data_a.m_Target.GetObject() );
-
- ItemBase attachment = ItemBase.Cast(target_entity.GetInventory().FindAttachment(action_data_a.m_AttSlot));
-
- if(attachment)
- {
- float stackable = attachment.GetTargetQuantityMax();
- if( stackable == 0 || stackable >= attachment.GetQuantity() )
- {
- //take to hands
- action_data.m_Player.PredictiveTakeEntityToHands( attachment );
- }
- else if( stackable != 0 && stackable < attachment.GetQuantity() )
- {
- //split and take to hands
- attachment.SplitIntoStackMaxHandsClient( action_data.m_Player );
- }
- }
- }
- }
- class ActionDetachFromTarget_SpecificSlot: ActionDetachFromTarget
- {
- string m_slotToDetach;
-
- override int FindSlotIdToDetach(PlayerBase player, ActionTarget target, ItemBase item)
- {
- EntityAI target_entity = EntityAI.Cast(target.GetObject());
-
- if ( player && target_entity )
- {
- array<string> selections = new array<string>();
- target_entity.GetActionComponentNameList( target.GetComponentIndex(),selections );
-
- if ( target_entity && target_entity.GetInventory() && target_entity.GetInventory().AttachmentCount() > 0 )
- {
- for(int i = 0; i < selections.Count(); i++ )
- {
- if( selections[i] == m_slotToDetach )
- {
- int target_slot_id = InventorySlots.GetSlotIdFromString( selections[i] );
- EntityAI att = target_entity.GetInventory().FindAttachment(target_slot_id);
-
- if ( att && player.GetInventory().CanAddEntityIntoHands(att) )
- {
- if ( att.CanDetachAttachment( target_entity ) && target_entity.CanReleaseAttachment( att ) )
- return target_slot_id;
- }
- }
- }
- }
- }
- return InventorySlots.INVALID;
- }
- }
- class ActionDetachFromTarget_SpecificSlotsCategory: ActionDetachFromTarget
- {
- string m_slotsToDetach;
-
- override int FindSlotIdToDetach(PlayerBase player, ActionTarget target, ItemBase item)
- {
- EntityAI target_entity = EntityAI.Cast(target.GetObject());
-
- if ( player && target_entity )
- {
- array<string> selections = new array<string>();
- target_entity.GetActionComponentNameList( target.GetComponentIndex(),selections );
-
- if ( target_entity && target_entity.GetInventory() && target_entity.GetInventory().AttachmentCount() > 0 )
- {
- for(int i = 0; i < selections.Count(); i++ )
- {
- if (selections[i].Contains(m_slotsToDetach))
- {
- int target_slot_id = InventorySlots.GetSlotIdFromString( selections[i] );
- EntityAI att = target_entity.GetInventory().FindAttachment(target_slot_id);
-
- if ( att && player.GetInventory().CanAddEntityIntoHands(att) )
- {
- if ( att.CanDetachAttachment( target_entity ) && target_entity.CanReleaseAttachment( att ) )
- return target_slot_id;
- }
- }
- }
- }
- }
- return InventorySlots.INVALID;
- }
- }
- class ActionDetachFromTarget_SpecificSlot_WoodenLogs: ActionDetachFromTarget_SpecificSlot
- {
- void ActionDetachFromTarget_SpecificSlot_WoodenLogs ()
- {
- m_slotToDetach = "truck_01_woodenlogs";
- }
- }
- class ActionDetachFromTarget_SpecificSlot_WoodenPlanks: ActionDetachFromTarget_SpecificSlot
- {
- void ActionDetachFromTarget_SpecificSlot_WoodenPlanks ()
- {
- m_slotToDetach = "truck_01_woodenplanks";
- }
- }
- class ActionDetachFromTarget_SpecificSlot_MetalSheets: ActionDetachFromTarget_SpecificSlot
- {
- void ActionDetachFromTarget_SpecificSlot_MetalSheets ()
- {
- m_slotToDetach = "truck_01_metalsheets";
- }
- }
- class ActionDetachFromTarget_SpecificSlotsCategory_Barrel: ActionDetachFromTarget_SpecificSlotsCategory
- {
- void ActionDetachFromTarget_SpecificSlotsCategory_Barrel ()
- {
- m_slotsToDetach = "truck_01_barrel";
- }
- }
- class ActionDetachFromTarget_SpecificSlotsCategory_WoodenCrate: ActionDetachFromTarget_SpecificSlotsCategory
- {
- void ActionDetachFromTarget_SpecificSlotsCategory_WoodenCrate ()
- {
- m_slotsToDetach = "truck_01_woodencrate";
- }
- }
|