DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
ActionAttachOnSelection.c
См. документацию.
2{
4 {
5 m_Text = "#attach";
6 }
7
8 override void CreateConditionComponents()
9 {
12 }
13
15 {
16 AttachActionData action_data = new AttachActionData();
17 return action_data;
18 }
19
21 {
22 EntityAI targetEntity = EntityAI.Cast(target.GetObject());
23 if (targetEntity && item)
24 {
25 GameInventory inv = targetEntity.GetInventory();
26 if (!inv)
28
29 int slotsCount = item.GetInventory().GetSlotIdCount();
30 array<string> selections = new array<string>();
31 targetEntity.GetActionComponentNameList(target.GetComponentIndex(), selections);
32
33 foreach (string selection : selections)
34 {
35 int slotId = -1;
36 if (!targetEntity.TranslateSlotFromSelection(selection, slotId))
37 slotId = InventorySlots.GetSlotIdFromString(selection);
38
39 if (slotId == -1)
40 continue;
41
42 for (int i=0; i < slotsCount; ++i)
43 {
44 int itemSlotId = item.GetInventory().GetSlotId(i);
45 if (slotId == itemSlotId)
46 {
47 ItemBase currentAttachment = ItemBase.Cast(inv.FindAttachment(slotId));
48 if (currentAttachment)
49 {
50 if (currentAttachment.CanBeCombined(item))
51 return itemSlotId;
52 }
53 else
54 {
55 if (inv.CanAddAttachment(item))
56 return itemSlotId;
57 }
58 }
59 }
60 }
61 }
62
64 }
65
66
67 override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data = null)
68 {
69 int attSlotId = InventorySlots.INVALID;
70 if (!GetGame().IsDedicatedServer() )
71 {
72 attSlotId = FindSlotIdToAttachOrCombine(player, target, item);
73 }
74
75 if (super.SetupAction( player, target, item, action_data, extra_data))
76 {
77 if (!GetGame().IsDedicatedServer())
78 {
79 if (attSlotId != InventorySlots.INVALID)
80 {
81 AttachActionData action_data_a = AttachActionData.Cast(action_data);
82 action_data_a.m_AttSlot = attSlotId;
83
84 return true;
85 }
86
87 return false;
88 }
89
90 return true;
91 }
92
93 return false;
94 }
95
96 override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
97 {
98 if (GetGame().IsMultiplayer() && GetGame().IsServer())
99 return true;
100
101 if (target.GetObject() && target.GetObject().CanUseConstruction())
102 return false;
103
104 return FindSlotIdToAttachOrCombine(player, target, item) != InventorySlots.INVALID;
105 }
106
107 override void OnExecuteServer( ActionData action_data )
108 {
109 if (GetGame().IsMultiplayer())
110 return;
111
112 ClearInventoryReservationEx(action_data);
113
114 AttachActionData action_data_a = AttachActionData.Cast(action_data);
115 EntityAI entity;
116
117 if (action_data.m_Target.IsProxy())
118 {
119 entity = EntityAI.Cast(action_data.m_Target.GetParent());
120 }
121 else
122 {
123 entity = EntityAI.Cast(action_data.m_Target.GetObject());
124 }
125
126 if (entity && action_data.m_MainItem)
127 {
128 action_data.m_Player.PredictiveTakeEntityToTargetAttachmentEx(entity, action_data_a.m_MainItem, action_data_a.m_AttSlot);
129 }
130 }
131
132 override void OnExecuteClient(ActionData action_data)
133 {
134 ClearInventoryReservationEx(action_data);
135 EntityAI targetEntity = EntityAI.Cast(action_data.m_Target.GetObject());
136 EntityAI itemEntity = action_data.m_MainItem;
137
138 AttachActionData action_data_a = AttachActionData.Cast(action_data);
139
140 ItemBase attachment = ItemBase.Cast(targetEntity.GetInventory().FindAttachment(action_data_a.m_AttSlot));
141 if (attachment)
142 {
143 attachment.CombineItemsClient(itemEntity);
144 }
145 else
146 {
147 ItemBase item_base = ItemBase.Cast( itemEntity );
148 float stackable = item_base.GetTargetQuantityMax( action_data_a.m_AttSlot );
149
150 if (stackable == 0 || stackable >= item_base.GetQuantity())
151 {
152 action_data.m_Player.PredictiveTakeEntityToTargetAttachmentEx(targetEntity, itemEntity, action_data_a.m_AttSlot);
153 }
154 else if (stackable != 0 && stackable < item_base.GetQuantity())
155 {
156 item_base.SplitIntoStackMaxClient(targetEntity, action_data_a.m_AttSlot);
157 }
158 }
159 }
160}
ActionBase ActionData
Определения ActionBase.c:30
class ActionTargets ActionTarget
override void CreateConditionComponents()
Определения ActionAttachOnSelection.c:8
override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data=null)
Определения ActionAttachOnSelection.c:67
int FindSlotIdToAttachOrCombine(PlayerBase player, ActionTarget target, ItemBase item)
Определения ActionAttachOnSelection.c:20
void ActionAttachOnSelection()
Определения ActionAttachOnSelection.c:3
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
Определения ActionAttachOnSelection.c:96
override void OnExecuteServer(ActionData action_data)
Определения ActionAttachOnSelection.c:107
override ActionData CreateActionData()
Определения ActionAttachOnSelection.c:14
override void OnExecuteClient(ActionData action_data)
Определения ActionAttachOnSelection.c:132
string m_Text
Определения ActionBase.c:58
ref CCIBase m_ConditionItem
Определения ActionBase.c:64
void ClearInventoryReservationEx(ActionData action_data)
Определения ActionBase.c:1025
ref CCTBase m_ConditionTarget
Определения ActionBase.c:65
void ActionSingleUseBase()
Определения ActionSingleUseBase.c:31
int m_AttSlot
Определения ActionAttach.c:3
Определения ActionAttach.c:2
Определения CCINonRuined.c:2
Определения CCTCursor.c:2
Определения Building.c:6
proto native bool CanAddAttachment(notnull EntityAI e)
Check if attachment can be added to any slot.
proto native EntityAI FindAttachment(int slot)
Returns attached entity in slot (you can use InventorySlots.GetSlotIdFromString(name) to get slot id)
script counterpart to engine's class Inventory
Определения Inventory.c:79
const int INVALID
Invalid slot (-1)
Определения InventorySlots.c:17
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id
provides access to slot configuration
Определения InventorySlots.c:6
override bool CanBeCombined(EntityAI other_item, bool reservation_check=true, bool stack_max_limit=false)
Определения Rag.c:61
Определения InventoryItem.c:731
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Определения param.c:12
Определения PlayerBaseClient.c:2
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()