DayZ 1.30
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 (!g_Game.IsDedicatedServer() )
71 {
72 attSlotId = FindSlotIdToAttachOrCombine(player, target, item);
73 }
74
75 if (super.SetupAction( player, target, item, action_data, extra_data))
76 {
77 if (!g_Game.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 (g_Game.IsMultiplayer() && g_Game.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 (g_Game.IsMultiplayer())
110 {
111 ClearActionJuncture(action_data);
112 return;
113 }
114
115 ClearInventoryReservationEx(action_data);
116
117 AttachActionData action_data_a = AttachActionData.Cast(action_data);
118 EntityAI entity;
119
120 if (action_data.m_Target.IsProxy())
121 {
122 entity = EntityAI.Cast(action_data.m_Target.GetParent());
123 }
124 else
125 {
126 entity = EntityAI.Cast(action_data.m_Target.GetObject());
127 }
128
129 if (entity && action_data.m_MainItem)
130 {
131 action_data.m_Player.PredictiveTakeEntityToTargetAttachmentEx(entity, action_data_a.m_MainItem, action_data_a.m_AttSlot);
132 }
133 }
134
135 override void OnExecuteClient(ActionData action_data)
136 {
137 ClearInventoryReservationEx(action_data);
138 EntityAI targetEntity = EntityAI.Cast(action_data.m_Target.GetObject());
139 EntityAI itemEntity = action_data.m_MainItem;
140
141 AttachActionData action_data_a = AttachActionData.Cast(action_data);
142
143 ItemBase attachment = ItemBase.Cast(targetEntity.GetInventory().FindAttachment(action_data_a.m_AttSlot));
144 if (attachment)
145 {
146 attachment.CombineItemsClient(itemEntity);
147 }
148 else
149 {
150 ItemBase item_base = ItemBase.Cast( itemEntity );
151 float stackable = item_base.GetTargetQuantityMax( action_data_a.m_AttSlot );
152
153 if (stackable == 0 || stackable >= item_base.GetQuantity())
154 {
155 action_data.m_Player.PredictiveTakeEntityToTargetAttachmentEx(targetEntity, itemEntity, action_data_a.m_AttSlot);
156 }
157 else if (stackable != 0 && stackable < item_base.GetQuantity())
158 {
159 item_base.SplitIntoStackMaxClient(targetEntity, action_data_a.m_AttSlot);
160 }
161 }
162 }
163}
string m_Text
Определения ActionBase.c:57
ref CCIBase m_ConditionItem
Определения ActionBase.c:63
ref CCTBase m_ConditionTarget
Определения ActionBase.c:64
void ClearInventoryReservationEx(ActionData action_data)
Определения ActionBase.c:1120
void ClearActionJuncture(ActionData action_data)
Определения ActionBase.c:1207
void ActionTarget(Object object, Object parent, int componentIndex, vector cursorHitPos, float utility, string surfaceName="")
Определения ActionTargets.c:125
DayZGame g_Game
Определения DayZGame.c:4074
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:135
PlayerBase m_Player
Определения ActionBase.c:40
ref ActionTarget m_Target
Определения ActionBase.c:39
ItemBase m_MainItem
Определения ActionBase.c:35
Определения ActionBase.c:22
void ActionSingleUseBase()
Определения ActionSingleUseBase.c:31
int m_AttSlot
Определения ActionAttach.c:3
Определения ActionAttach.c:2
Определения CCINonRuined.c:2
Определения CCTCursor.c:2
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
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
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.