DayZ 1.24
Loading...
Searching...
No Matches
ActionAttachOnSelection Class Reference
Inheritance diagram for ActionAttachOnSelection:
[legend]
Collaboration diagram for ActionAttachOnSelection:
[legend]

Private Member Functions

void ActionAttachOnSelection ()
 
override void CreateConditionComponents ()
 
override ActionData CreateActionData ()
 
int FindSlotIdToAttachOrCombine (PlayerBase player, ActionTarget target, ItemBase item)
 
override bool SetupAction (PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data=null)
 
override bool ActionCondition (PlayerBase player, ActionTarget target, ItemBase item)
 
override void OnExecuteServer (ActionData action_data)
 
override void OnExecuteClient (ActionData action_data)
 

Detailed Description

Definition at line 1 of file ActionAttachOnSelection.c.

Constructor & Destructor Documentation

◆ ActionAttachOnSelection()

void ActionAttachOnSelection::ActionAttachOnSelection ( )
inlineprivate

Definition at line 3 of file ActionAttachOnSelection.c.

4 {
5 m_Text = "#attach";
6 }
string m_Text
Definition ActionBase.c:49

References m_Text.

Member Function Documentation

◆ ActionCondition()

override bool ActionAttachOnSelection::ActionCondition ( PlayerBase player,
ActionTarget target,
ItemBase item )
inlineprivate

Definition at line 93 of file ActionAttachOnSelection.c.

94 {
95 if (GetGame().IsMultiplayer() && GetGame().IsServer())
96 return true;
97
98 if (target.GetObject() && target.GetObject().CanUseConstruction())
99 return false;
100
102 }
int FindSlotIdToAttachOrCombine(PlayerBase player, ActionTarget target, ItemBase item)
provides access to slot configuration
const int INVALID
Invalid slot (-1)
proto native CGame GetGame()

References FindSlotIdToAttachOrCombine(), GetGame(), and InventorySlots::INVALID.

◆ CreateActionData()

override ActionData ActionAttachOnSelection::CreateActionData ( )
inlineprivate

Definition at line 14 of file ActionAttachOnSelection.c.

◆ CreateConditionComponents()

override void ActionAttachOnSelection::CreateConditionComponents ( )
inlineprivate

Definition at line 8 of file ActionAttachOnSelection.c.

9 {
12 }
ref CCIBase m_ConditionItem
Definition ActionBase.c:55
ref CCTBase m_ConditionTarget
Definition ActionBase.c:56

References m_ConditionItem, and m_ConditionTarget.

◆ FindSlotIdToAttachOrCombine()

int ActionAttachOnSelection::FindSlotIdToAttachOrCombine ( PlayerBase player,
ActionTarget target,
ItemBase item )
inlineprivate

Definition at line 20 of file ActionAttachOnSelection.c.

21 {
22 EntityAI targetEntity = EntityAI.Cast(target.GetObject());
23 if (targetEntity && item)
24 {
25 if (!targetEntity.GetInventory())
27
28 int slotsCount = item.GetInventory().GetSlotIdCount();
30 targetEntity.GetActionComponentNameList(target.GetComponentIndex(), selections);
31
32 foreach (string selection : selections)
33 {
34 int slotId = -1;
35 if (!targetEntity.TranslateSlotFromSelection(selection, slotId))
37
38 if (slotId == -1)
39 continue;
40
41 for (int i = 0; i < slotsCount; ++i)
42 {
43 int itemSlotId = item.GetInventory().GetSlotId(i);
44 if (slotId == itemSlotId)
45 {
46 ItemBase currentAttachment = ItemBase.Cast(targetEntity.GetInventory().FindAttachment(slotId));
48 {
49 if (currentAttachment.CanBeCombined(item))
50 return itemSlotId;
51 }
52 else
53 {
54 if (targetEntity.GetInventory() && targetEntity.GetInventory().CanAddAttachment(item))
55 return itemSlotId;
56 }
57 }
58 }
59 }
60 }
61
63 }
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id

References InventorySlots::GetSlotIdFromString(), and InventorySlots::INVALID.

Referenced by ActionCondition(), and SetupAction().

◆ OnExecuteClient()

override void ActionAttachOnSelection::OnExecuteClient ( ActionData action_data)
inlineprivate

Definition at line 123 of file ActionAttachOnSelection.c.

124 {
126 EntityAI targetEntity = EntityAI.Cast(action_data.m_Target.GetObject());
127 EntityAI itemEntity = action_data.m_MainItem;
128
130
131 ItemBase attachment = ItemBase.Cast(targetEntity.GetInventory().FindAttachment(action_data_a.m_AttSlot));
132 if (attachment)
133 attachment.CombineItemsClient(itemEntity);
134 else
135 {
137 float stackable = item_base.GetTargetQuantityMax(action_data_a.m_AttSlot);
138
139 if (stackable == 0 || stackable >= item_base.GetQuantity())
140 action_data.m_Player.PredictiveTakeEntityToTargetAttachmentEx(targetEntity, itemEntity, action_data_a.m_AttSlot);
141 else if (stackable != 0 && stackable < item_base.GetQuantity())
142 item_base.SplitIntoStackMaxClient(targetEntity, action_data_a.m_AttSlot);
143 }
144 }
void ClearInventoryReservationEx(ActionData action_data)
Definition ActionBase.c:790

References ClearInventoryReservationEx().

◆ OnExecuteServer()

override void ActionAttachOnSelection::OnExecuteServer ( ActionData action_data)
inlineprivate

Definition at line 104 of file ActionAttachOnSelection.c.

105 {
106 if (GetGame().IsMultiplayer())
107 return;
108
110
113
114 if (action_data.m_Target.IsProxy())
115 entity = EntityAI.Cast(action_data.m_Target.GetParent());
116 else
117 entity = EntityAI.Cast(action_data.m_Target.GetObject());
118
119 if (entity && action_data.m_MainItem)
120 action_data.m_Player.PredictiveTakeEntityToTargetAttachmentEx(entity, action_data_a.m_MainItem, action_data_a.m_AttSlot);
121 }

References ClearInventoryReservationEx(), and GetGame().

◆ SetupAction()

override bool ActionAttachOnSelection::SetupAction ( PlayerBase player,
ActionTarget target,
ItemBase item,
out ActionData action_data,
Param extra_data = null )
inlineprivate

Definition at line 66 of file ActionAttachOnSelection.c.

67 {
69 if (!GetGame().IsDedicatedServer())
71
72 if (super.SetupAction(player, target, item, action_data, extra_data))
73 {
74 if (!GetGame().IsDedicatedServer())
75 {
77 {
79 action_data_a.m_AttSlot = attSlotId;
80
81 return true;
82 }
83
84 return false;
85 }
86
87 return true;
88 }
89
90 return false;
91 }

References FindSlotIdToAttachOrCombine(), GetGame(), and InventorySlots::INVALID.


The documentation for this class was generated from the following file: