DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
ActionAttachToConstruction.c
См. документацию.
5
7{
8 // Used specifically because I didn't want to create an array on every run of the condition.
9 // Is NOT meant to transfer data between methods, doing that in member variables of actions would be incredibly dangerous!
11
13 {
14 m_Text = "#attach";
16 }
17
19 {
22 }
23
25 {
27 return actionData;
28 }
29
30 override bool Post_SetupAction( ActionData action_data )
31 {
32 if (!super.Post_SetupAction(action_data))
33 return false;
34
35 if (!g_Game.IsDedicatedServer())
36 {
37 int slotID = FindAndTranslateAttachmentSlot(action_data.m_Player, action_data.m_Target, action_data.m_MainItem);
38 AttachToConstructionActionData.Cast(action_data).m_SlotID = slotID;
39 return slotID != InventorySlots.INVALID;
40 }
41
42 return true;
43 }
44
45 override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
46 {
47 EntityAI targetEntity = EntityAI.Cast(target.GetObject());
48 if (targetEntity && targetEntity.CanUseConstruction())
49 {
50 int slotID = FindAndTranslateAttachmentSlot(player, target, item);
51 return slotID != InventorySlots.INVALID;
52 }
53
54 return false;
55 }
56
57 override void OnStartClient(ActionData action_data)
58 {
59 //set action initiator
60 ConstructionActionData constructionActionData = action_data.m_Player.GetConstructionActionData();
61 constructionActionData.SetActionInitiator(action_data.m_Player);
62 }
63
64 protected void OnExecuteImpl( ActionData action_data )
65 {
66 EntityAI targetEntity = EntityAI.Cast(action_data.m_Target.GetObject());
67
68 int slotId = AttachToConstructionActionData.Cast(action_data).m_SlotID;
69
70 if (slotId != InventorySlots.INVALID)
71 {
72 ItemBase attachment = ItemBase.Cast(targetEntity.GetInventory().FindAttachment(slotId));
73
74 if (attachment)
75 {
76 //combine
77 attachment.CombineItemsClient(action_data.m_MainItem);
78 }
79 else
80 {
81 float stackable = action_data.m_MainItem.GetTargetQuantityMax(slotId);
82
83 if (stackable == 0 || stackable >= action_data.m_MainItem.GetQuantity())
84 {
85 action_data.m_Player.PredictiveTakeEntityToTargetAttachmentEx(targetEntity, action_data.m_MainItem, slotId);
86 }
87 else if (stackable != 0 && stackable < action_data.m_MainItem.GetQuantity())
88 {
89 action_data.m_MainItem.SplitIntoStackMax(targetEntity, slotId, action_data.m_Player);
90 }
91 }
92 }
93 }
94
95 override void OnExecuteClient(ActionData action_data)
96 {
97 ClearInventoryReservationEx(action_data);
98 OnExecuteImpl(action_data);
99 }
100
101 override void OnExecuteServer(ActionData action_data)
102 {
103 if (!g_Game.IsMultiplayer())
104 {
105 ClearInventoryReservationEx(action_data);
106 OnExecuteImpl(action_data); // single player
107 }
108 else
109 {
110 ClearActionJuncture(action_data);
111 }
112 }
113
116 {
117 int slotId = InventorySlots.INVALID;
118 int count;
119 Building building;
120 BaseBuildingBase baseBuilding;
121 ConstructionActionData constructionActionData = player.GetConstructionActionData();
123 bool found;
124 EntityAI targetEntity = EntityAI.Cast(target.GetObject());
125 if (Class.CastTo(baseBuilding, targetEntity)) //BaseBuildingBase entities
126 {
127 if (item.IsExternalLockType()) // External lock handling of base building objects
128 {
129 loc = new InventoryLocation();
130 found = baseBuilding.GetInventory().FindFreeLocationFor(item, FindInventoryLocationType.ATTACHMENT, loc);
131 slotId = loc.GetSlot();
132 if (found && slotId != InventorySlots.INVALID)
133 {
134 return slotId;
135 }
136 }
137 else
138 {
139 string selection = baseBuilding.GetActionComponentName(target.GetComponentIndex());
140 slotId = constructionActionData.GetAttachmentSlotFromSelection(player, baseBuilding, item, selection);
141
142 if (slotId != InventorySlots.INVALID)
143 {
144 if (baseBuilding.CheckSlotVerticalDistance(slotId, player) && baseBuilding.IsPlayerInside(player,""))
145 {
146 return slotId;
147 }
148 }
149 }
150 }
151 else if (Class.CastTo(building, targetEntity) && building.CanUseConstruction()) // Building entities
152 {
153 if (item.IsExternalLockType()) // External lock handling of building objects with doors and lock attachments and internal locks
154 {
155 int doorIndex = building.GetDoorIndex(target.GetComponentIndex());
156 if (doorIndex > -1 && !building.IsDoorLocked(doorIndex) && !building.IsDoorOpen(doorIndex))
157 {
158 AdditionalDoorInfo doorInfo = building.GetDoorInfo(doorIndex);
159 if (!doorInfo || !doorInfo.m_RelatedInventorySlotNames)
160 return InventorySlots.INVALID;
161
162 foreach (string slotName: doorInfo.m_RelatedInventorySlotNames)
163 {
164 EntityAI slotEntity = building.FindAttachmentBySlotName(slotName);
165 if (slotEntity)
166 continue;
167
169 GameInventory inventory = building.GetInventory();
170 if (inventory && inventory.CanAddAttachmentEx(item, slotId))
171 break;
172
173 slotId = InventorySlots.INVALID; //invalidate after unsuccessful check
174 }
175
176 if (slotId != InventorySlots.INVALID)
177 {
178 return slotId;
179 }
180 }
181 }
182 else //presumed material, that is only allowed on 'materials slot' selection. Using GUIInventoryAttachmentsProps structure
183 {
184 m_ComponentNames.Clear();
185 building.GetActionComponentNameList(target.GetComponentIndex(), m_ComponentNames, LOD.NAME_VIEW);
186 count = m_ComponentNames.Count();
187 if (count > 0)
188 {
189 foreach (string sel : m_ComponentNames)
190 {
191 slotId = constructionActionData.GetAttachmentSlotFromSelection(player, building, item, sel);
192 if (slotId != InventorySlots.INVALID)
193 return slotId;
194 }
195 }
196 }
197 }
198 else // Everything else
199 {
200 m_ComponentNames.Clear();
201 targetEntity.GetActionComponentNameList(target.GetComponentIndex(), m_ComponentNames, LOD.NAME_VIEW);
202 count = m_ComponentNames.Count();
203 if (count > 0)
204 {
205 foreach (string sel2 : m_ComponentNames)
206 {
207 slotId = constructionActionData.GetAttachmentSlotFromSelection(player, targetEntity, item, sel2);
208 if (slotId != InventorySlots.INVALID)
209 {
210 return slotId;
211 }
212 }
213 }
214 }
215
216 return InventorySlots.INVALID;
217 }
218}
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
PlayerSpawnPreset slotName
DayZGame g_Game
Определения DayZGame.c:4074
FindInventoryLocationType
flags for searching locations in inventory
Определения InventoryLocation.c:18
override void OnStartClient(ActionData action_data)
Определения ActionAttachToConstruction.c:57
void OnExecuteImpl(ActionData action_data)
Определения ActionAttachToConstruction.c:64
override ActionData CreateActionData()
Определения ActionAttachToConstruction.c:24
ref array< string > m_ComponentNames
Определения ActionAttachToConstruction.c:10
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
Определения ActionAttachToConstruction.c:45
int FindAndTranslateAttachmentSlot(PlayerBase player, ActionTarget target, ItemBase item)
where appropriate, returns valid attachment slot ID even without proper selection
Определения ActionAttachToConstruction.c:115
override bool Post_SetupAction(ActionData action_data)
Определения ActionAttachToConstruction.c:30
override void OnExecuteServer(ActionData action_data)
Определения ActionAttachToConstruction.c:101
override void CreateConditionComponents()
Определения ActionAttachToConstruction.c:18
override void OnExecuteClient(ActionData action_data)
Определения ActionAttachToConstruction.c:95
PlayerBase m_Player
Определения ActionBase.c:40
ref ActionTarget m_Target
Определения ActionBase.c:39
ItemBase m_MainItem
Определения ActionBase.c:35
void ActionData()
Определения ActionBase.c:23
Определения ActionBase.c:22
void ActionSingleUseBase()
Определения ActionSingleUseBase.c:31
ref TStringArray m_RelatedInventorySlotNames
Lock compatibility type, now in door config. Lockpick enabled by default if undefined.
Определения AdditionalDoorsInfo.c:12
Single door info.
Определения AdditionalDoorsInfo.c:3
override bool IsPlayerInside(PlayerBase player, string selection)
Определения Fence.c:661
override bool CheckSlotVerticalDistance(int slot_id, PlayerBase player)
Определения Watchtower.c:300
Определения Fence.c:2
AdditionalDoorInfo GetDoorInfo(int doorIdx)
proto native bool IsDoorLocked(int index)
When the door is locked.
proto native bool IsDoorOpen(int index)
When the door is requested to be fully open (animation wanted phase is greater than 0....
proto native int GetDoorIndex(int componentIndex)
Gets the index of the door based on the view geometry component index.
Определения CCINonRuined.c:2
Определения CCTCursor.c:2
Super root of all classes in Enforce script.
Определения EnScript.c:11
int GetAttachmentSlotFromSelection(PlayerBase player, EntityAI target, ItemBase item_to_attach, string selection)
Определения ConstructionActionData.c:469
void SetActionInitiator(PlayerBase action_initiator)
Определения ConstructionActionData.c:131
proto native bool CanAddAttachmentEx(notnull EntityAI e, int slot)
Check if attachment can be added to slot @NOTE: Note that slot index IS NOT slot ID!...
script counterpart to engine's class Inventory
proto native int GetSlot()
returns slot id if current type is Attachment
InventoryLocation.
Определения InventoryLocation.c:30
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
static const string NAME_VIEW
Определения gameplay.c:207
LOD class.
Определения gameplay.c:204
Определения PlayerBaseClient.c:2
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.