DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
ConstructionActionData.c
См. документацию.
2{
4
5 //base building
8
9 int m_PartIndex; //used on client only, action synchronizes it to server to avoid mismatch
13
14 //combination lock
16
17 //attaching
20 //detaching
22
25
27
29 {
32 m_PartIndex = 0;
33
36
37 if ( GetGame().IsClient() || !GetGame().IsMultiplayer() )
38 {
40 m_ActionVariantManager.GetOnUpdateInvoker().Clear();
41 m_ActionVariantManager.GetOnUpdateInvoker().Insert(OnUpdateActions);
42
44 m_ActionNoToolVariantManager.GetOnUpdateInvoker().Clear();
45 m_ActionNoToolVariantManager.GetOnUpdateInvoker().Insert(OnUpdateActionsNoTool);
46 }
47 }
48
50 {
51 if (GetGame() && (GetGame().IsClient() || !GetGame().IsMultiplayer()))
52 {
54 {
55 m_ActionVariantManager.GetOnUpdateInvoker().Remove(OnUpdateActions);
56 }
57
59 {
60 m_ActionNoToolVariantManager.GetOnUpdateInvoker().Remove(OnUpdateActionsNoTool);
61 }
62 }
63 }
64
65 //************************************************/
66 // Base building
67 //************************************************/
69 {
70 return m_MainPartName;
71 }
72
74 {
76 }
77
78 void SetTarget( Object target )
79 {
80 m_Target = target;
81 }
82
84 {
85 return m_Target;
86 }
87
88 void SetTargetPart( ConstructionPart target_part )
89 {
90 m_TargetPart = target_part;
91 }
92
97
98 void SetSlotId( int slot_id )
99 {
100 m_SlotId = slot_id;
101 }
102
104 {
105 return m_SlotId;
106 }
107
108 void SetActionInitiator( PlayerBase action_initiator )
109 {
110 m_ActionInitiator = action_initiator;
111 }
112
117
118 // deprecated
120 {
121 }
122
123 // deprecated
124 void RefreshPartsToBuild( string main_part_name, ItemBase tool, bool use_tool = true )
125 {
126
127 }
128
129 void OnUpdateActions( Object item, Object target, int component_index )
130 {
131 ItemBase tool = ItemBase.Cast( item );
132 if ( tool )
133 {
134 BaseBuildingBase base_building_object = BaseBuildingBase.Cast( target );
135 if ( base_building_object )
136 {
137 string main_part_name = target.GetActionComponentName( component_index );
138 base_building_object.GetConstruction().GetConstructionPartsToBuild( main_part_name, m_BuildParts, tool, m_MainPartName, true );
139 m_ActionVariantManager.SetActionVariantCount(m_BuildParts.Count());
140 }
141 else
142 {
143 m_BuildParts.Clear();
145 }
146
147 }
148 else
149 {
150 m_BuildParts.Clear();
152 }
153 //not needed
154 //m_Target = target;
155 }
156
157 void OnUpdateActionsNoTool( Object item, Object target, int component_index )
158 {
159 BaseBuildingBase base_building_object = BaseBuildingBase.Cast( target );
160 if ( base_building_object )
161 {
162 string main_part_name = target.GetActionComponentName( component_index );
163 base_building_object.GetConstruction().GetConstructionPartsToBuild( main_part_name, m_BuildPartsNoTool, null, m_MainPartNameNoTool, false );
164 m_ActionNoToolVariantManager.SetActionVariantCount(m_BuildPartsNoTool.Count());
165 }
166 else
167 {
168 m_BuildPartsNoTool.Clear();
170 }
171 }
172
174 {
175 return m_BuildParts.Count();
176 }
177
178 // deprecated
180 {
181 return null;
182 }
183
185 {
186 if( m_BuildParts.Count() > idx )
187 {
188 return m_BuildParts.Get( idx );
189 }
190 return null;
191 }
192
194 {
195 if( m_BuildPartsNoTool.Count() > idx )
196 {
197 return m_BuildPartsNoTool.Get( idx );
198 }
199 return null;
200 }
201
202 //************************************************/
203 // Combination lock
204 //************************************************/
209
210 void SetCombinationLock( CombinationLock combination_lock )
211 {
212 m_CombinationLock = CombinationLock.Cast( combination_lock );
213 }
214
216 {
217 string dial_text;
218
219 if ( m_CombinationLock )
220 {
221 string combination_text = m_CombinationLock.GetCombination().ToString();
222
223 //insert zeros to dials with 0 value
224 int length_diff = m_CombinationLock.GetLockDigits() - combination_text.Length();
225 for ( int i = 0; i < length_diff; ++i )
226 {
227 combination_text = "0" + combination_text;
228 }
229
230 //assemble the whole combination with selected part
231 for ( int j = 0; j < m_CombinationLock.GetLockDigits(); ++j )
232 {
233 if ( j == m_CombinationLock.GetDialIndex() )
234 {
235 dial_text += string.Format( "[%1]", combination_text.Get( j ) );
236 }
237 else
238 {
239 dial_text += string.Format( " %1 ", combination_text.Get( j ) );
240 }
241 }
242 }
243
244 return dial_text;
245 }
246
247 //************************************************/
248 // Attach/Detach actions
249 //************************************************/
250 int GetAttachmentSlotFromSelection( PlayerBase player, EntityAI target, ItemBase item_to_attach, string selection )
251 {
252 string cfg_path = "cfgVehicles" + " " + target.GetType() + " "+ "GUIInventoryAttachmentsProps";
253
254 if ( GetGame().ConfigIsExisting( cfg_path ) )
255 {
256 int child_count = GetGame().ConfigGetChildrenCount( cfg_path );
257
258 for ( int i = 0; i < child_count; i++ )
259 {
260 string child_name;
261 GetGame().ConfigGetChildName( cfg_path, i, child_name );
262
263 string child_selection;
264 GetGame().ConfigGetText( cfg_path + " " + child_name + " " + "selection", child_selection );
265
266 if ( selection == child_selection )
267 {
268 ref array<string> attachment_slots = new array<string>;
269 GetGame().ConfigGetTextArray( cfg_path + " " + child_name + " " + "attachmentSlots", attachment_slots );
270
271 for ( int j = 0; j < attachment_slots.Count(); ++j )
272 {
273 int target_slot_id = InventorySlots.GetSlotIdFromString( attachment_slots.Get( j ) );
274 int item_slot_count = item_to_attach.GetInventory().GetSlotIdCount();
275
276 for ( int k = 0; k < item_slot_count; ++k )
277 {
278 int item_slot_id = item_to_attach.GetInventory().GetSlotId( k );
279 ItemBase attachment_item = ItemBase.Cast( target.GetInventory().FindAttachment( item_slot_id ) );
280
281 if ( target_slot_id == item_slot_id )
282 {
283 if ( target.GetInventory().CanAddAttachmentEx( item_to_attach, item_slot_id ) && target.CanReceiveAttachment( item_to_attach, item_slot_id ) || attachment_item && attachment_item.CanBeCombined( item_to_attach ) )
284 {
285 if(target.CanDisplayAttachmentSlot(target_slot_id))
286 return item_slot_id;
287 else
288 return -1;
289 }
290 }
291 }
292 }
293 }
294 }
295 }
296
297 return -1;
298 }
299
300 void GetAttachmentsFromSelection( EntityAI target, string selection, out array<EntityAI> attachments )
301 {
302 attachments.Clear(); //clear output
303
304 string cfg_path = "cfgVehicles" + " " + target.GetType() + " "+ "GUIInventoryAttachmentsProps";
305 if ( GetGame().ConfigIsExisting( cfg_path ) )
306 {
307 int child_count = GetGame().ConfigGetChildrenCount( cfg_path );
308
309 for ( int i = 0; i < child_count; i++ )
310 {
311 string child_name;
312 GetGame().ConfigGetChildName( cfg_path, i, child_name );
313
314 string child_selection;
315 GetGame().ConfigGetText( cfg_path + " " + child_name + " " + "selection", child_selection );
316
317 if ( selection == child_selection )
318 {
319 ref array<string> attachment_slots = new array<string>;
320 GetGame().ConfigGetTextArray( cfg_path + " " + child_name + " " + "attachmentSlots", attachment_slots );
321
322 for ( int j = 0; j < attachment_slots.Count(); ++j )
323 {
324 int target_slot_id = InventorySlots.GetSlotIdFromString( attachment_slots.Get( j ) );
325
326 //is attached and can be detached
327 EntityAI attachment = target.GetInventory().FindAttachment( target_slot_id );
328 if ( attachment && target.GetInventory().CanRemoveAttachmentEx( attachment, target_slot_id ) && !target.GetInventory().GetSlotLock( target_slot_id ) )
329 {
330 attachments.Insert( attachment );
331 }
332 }
333 }
334 }
335 }
336 }
337
338 void CombineItems( ItemBase target, ItemBase item )
339 {
340 if ( target.ConfigGetBool( "canBeSplit" ) && item && !target.IsFullQuantity() )
341 {
342 int quantity_used = target.ComputeQuantityUsed( item, true );
343 if( quantity_used != 0 )
344 {
345 target.AddQuantity( quantity_used );
346 item.AddQuantity( -quantity_used );
347 }
348 }
349 }
350
351 void RefreshAttachmentsToDetach( EntityAI target, string main_part_name )
352 {
353 GetAttachmentsFromSelection( target, main_part_name, m_Attachments );
354 }
355
357 {
358 if ( GetAttachmentsToDetachCount() > 1 )
359 {
361 {
363 }
365 {
367 }
368 }
369 else
370 {
372 }
373 }
374
376 {
377 return m_Attachments.Count();
378 }
379
381 {
382 if ( GetAttachmentsToDetachCount() > 0 )
383 {
385
387 {
388 return m_Attachments.Get( m_AttachmentsIndex );
389 }
390 }
391
392 return NULL;
393 }
394
395 //************************************************/
396 // Common
397 //************************************************/
399 {
400 m_PartIndex = 0;
402 }
403}
static ActionVariantManager GetVariantManager(typename actionName)
Определения ActionManagerClient.c:255
Определения Fence.c:2
proto bool ConfigGetChildName(string path, int index, out string name)
Get name of subclass in config class on path.
proto native void ConfigGetTextArray(string path, out TStringArray values)
Get array of strings from config on path.
proto bool ConfigGetText(string path, out string value)
Get string value from config on path.
proto native int ConfigGetChildrenCount(string path)
Get count of subclasses in config class on path.
string m_MainPartName
Определения ConstructionActionData.c:10
ref array< EntityAI > m_Attachments
Определения ConstructionActionData.c:21
void ResetActionIndexes()
Определения ConstructionActionData.c:398
ref array< ConstructionPart > m_BuildParts
Определения ConstructionActionData.c:6
EntityAI GetActualAttachmentToDetach()
Определения ConstructionActionData.c:380
string GetMainPartName()
Определения ConstructionActionData.c:68
void SetCombinationLock(CombinationLock combination_lock)
Определения ConstructionActionData.c:210
void ConstructionActionData()
Определения ConstructionActionData.c:28
ConstructionPart GetCurrentBuildPart()
Определения ConstructionActionData.c:179
CombinationLock m_CombinationLock
Определения ConstructionActionData.c:15
string GetDialNumberText()
Определения ConstructionActionData.c:215
CombinationLock GetCombinationLock()
Определения ConstructionActionData.c:205
Object GetTarget()
Определения ConstructionActionData.c:83
int GetAttachmentsToDetachCount()
Определения ConstructionActionData.c:375
string GetMainPartNameNoTool()
Определения ConstructionActionData.c:73
string m_MainPartNameNoTool
Определения ConstructionActionData.c:11
ActionVariantManager m_ActionNoToolVariantManager
Определения ConstructionActionData.c:24
ConstructionPart GetBuildPartNoToolAtIndex(int idx)
Определения ConstructionActionData.c:193
void ~ConstructionActionData()
Определения ConstructionActionData.c:49
int GetConstructionPartsCount()
Определения ConstructionActionData.c:173
void CombineItems(ItemBase target, ItemBase item)
Определения ConstructionActionData.c:338
void RefreshPartsToBuild(string main_part_name, ItemBase tool, bool use_tool=true)
Определения ConstructionActionData.c:124
void SetTarget(Object target)
Определения ConstructionActionData.c:78
void OnUpdateActionsNoTool(Object item, Object target, int component_index)
Определения ConstructionActionData.c:157
int GetAttachmentSlotFromSelection(PlayerBase player, EntityAI target, ItemBase item_to_attach, string selection)
Определения ConstructionActionData.c:250
ActionVariantManager m_ActionVariantManager
Определения ConstructionActionData.c:23
void SetSlotId(int slot_id)
Определения ConstructionActionData.c:98
ConstructionPart GetBuildPartAtIndex(int idx)
Определения ConstructionActionData.c:184
void SetNextAttachmentIndex()
Определения ConstructionActionData.c:356
PlayerBase GetActionInitiator()
Определения ConstructionActionData.c:113
ConstructionPart GetTargetPart()
Определения ConstructionActionData.c:93
void GetAttachmentsFromSelection(EntityAI target, string selection, out array< EntityAI > attachments)
Определения ConstructionActionData.c:300
void SetActionInitiator(PlayerBase action_initiator)
Определения ConstructionActionData.c:108
PlayerBase m_ActionInitiator
Определения ConstructionActionData.c:19
void RefreshAttachmentsToDetach(EntityAI target, string main_part_name)
Определения ConstructionActionData.c:351
ref ConstructionPart m_TargetPart
Определения ConstructionActionData.c:12
void OnUpdateActions(Object item, Object target, int component_index)
Определения ConstructionActionData.c:129
ref array< ConstructionPart > m_BuildPartsNoTool
Определения ConstructionActionData.c:7
void SetTargetPart(ConstructionPart target_part)
Определения ConstructionActionData.c:88
Определения Building.c:6
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
Определения EnMath.c:7
Определения ObjectTyped.c:2
Определения PlayerBaseClient.c:2
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
proto native int Length()
Returns length of string.
proto string Get(int index)
Gets n-th character from string.
static proto string Format(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
Gets n-th character from string.