DayZ 1.29
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
ReplaceItemWithNewLambdaBase.c
См. документацию.
1
5{
10 protected bool m_RemoveFromLocationPassed = false;
11 private bool m_RemoveNetworkObjectInfoPassed = false;
12
13 void ReplaceItemWithNewLambdaBase(EntityAI old_item, string new_item_type)
14 {
15 m_OldItem = old_item;
16 m_NewItemType = new_item_type;
17 }
18
20 {
21 m_NewLocation = newLocation;
22 }
23
25
26 protected bool WantCreateNewEntity()
27 {
28 return m_NewLocation && m_NewItemType != string.Empty;
29 }
30
31 protected bool CanExecuteLambda()
32 {
33 if (m_OldItem)
35 //if (WantCreateNewEntity() GameInventory.LocationTestAddEntityType(m_NewItemType, true, true, false, true))
36 return true;
37 return false;
38 }
39
43 protected bool PrepareLocations()
44 {
45 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] ReplaceItemWithNewLambdaBase Step A) Prepare inventory locations, old_item=" + m_OldItem);
47 if (m_OldItem.GetInventory().GetCurrentInventoryLocation(m_OldLocation)) // A.1) store old location
48 {
49 if (m_NewLocation == null)
50 {
52 m_NewLocation.CopyLocationFrom(m_OldLocation, true); // A.2) prepare new location from old
53
54 //setting proper location type for ground pos
55 if (!m_NewLocation.GetParent())
56 {
57 vector m4[4];
59 m4[3] = m_NewLocation.GetPos();
60 string path = "" + CFG_VEHICLESPATH + " " + m_NewItemType + " inherit_rotation";
61 bool keep_rotation = g_Game.ConfigIsExisting(path) && g_Game.ConfigGetInt(path) > 0;
62
63 if (m_OldLocation.GetType() == InventoryLocationType.GROUND && keep_rotation)
64 {
65 float dir[4];
66 m_OldLocation.GetDir(dir);
67 m_NewLocation.SetGroundEx(null,m_NewLocation.GetPos(),dir);
68 }
69 else
70 {
71 m_NewLocation.SetGround(null,m4);
72 }
73 }
74 }
75 return true;
76 }
77 else
78 Error("[inv] ReplaceItemWithNewLambdaBase Step A.1) failed to get old_item inventory location");
79 return false;
80 }
81
87 {
88 if (!GameInventory.LocationRemoveEntity(m_OldLocation)) // B) remove entity from old inventory location (making it free for new item)
89 {
90 Error("[inv] ReplaceItemWithNewLambdaBase Step B) failed to remove old_item rom current inventory location");
92 }
93 else
94 {
95 Print("[inv] ReplaceItemWithNewLambdaBase Step B) remove OK, loc=" + InventoryLocation.DumpToStringNullSafe(m_OldLocation));
97 }
98 }
100 {
102 {
103 Error("[inv] ReplaceItemWithNewLambdaBase Step B) failed to undo remove");
104 }
105 else
106 {
107 Print("[inv] ReplaceItemWithNewLambdaBase Step B) undo remove OK, loc=" + InventoryLocation.DumpToStringNullSafe(m_OldLocation));
108 }
109 }
110
115 protected void RemoveNetworkObjectInfo()
116 {
117 g_Game.RemoteObjectTreeDelete(m_OldItem); // C) this forces server to send DeleteObject Message to client. This is needed for preserving the appearance of network operations on client (so that DeleteObject(old) arrives before CreateVehicle(new)). @NOTE: this does not delete the object on server, only it's network representation.
118 // @NOTE: the item is not deleted right now on server, but rather after copying the properties in Step E)
120 }
122 {
123 g_Game.RemoteObjectTreeCreate(m_OldItem);
124 }
125
132 {
134 {
136 EntityAI new_item;
137
138 switch (m_NewLocation.GetType())
139 {
140 case InventoryLocationType.GROUND:
141 new_item = EntityAI.Cast(g_Game.CreateObjectEx(m_NewItemType,m_NewLocation.GetPos(),ECE_PLACE_ON_SURFACE|ECE_LOCAL));
142 string path = "" + CFG_VEHICLESPATH + " " + m_NewItemType + " inherit_rotation";
143 bool keep_rotation = g_Game.ConfigIsExisting(path) && g_Game.ConfigGetInt(path) > 0;
144 if (keep_rotation)
145 {
146 new_item.SetOrientation(m_OldItem.GetOrientation()); //this one actually works...debug InventoryLocation
147 }
148 break;
149 case InventoryLocationType.ATTACHMENT:
150 // forces rawlocation in C++ to make location Valid
151 m_NewLocation.SetAttachment(m_NewLocation.GetParent(), null, m_NewLocation.GetSlot());
153 break;
154 default:
156 break;
157 }
158
159 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] ReplaceItemWithNewLambdaBase Step D) Created new new_item=" + new_item);
160 if (new_item)
161 {
162 return new_item;
163 }
164 else
165 {
166 return null;
167
168 /*InventoryLocation backupLocation = new InventoryLocation;
169 vector mtx[4];
170 Math3D.MatrixIdentity4(mtx);
171 mtx[3] = m_OldItem.GetPosition();
172 backupLocation.SetGround(null, mtx);
173 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] ReplaceItemWithNewLambdaBase Step D) plan B - creating=" + m_NewItemType + " at bkp loc=" + backupLocation.DumpToString() + ", but failed");
174 new_item = GameInventory.LocationCreateLocalEntity(backupLocation, m_NewItemType,ECE_OBJECT_SWAP,RF_NONE); // create LOCAL new one on ground
175 if (!new_item)
176 {
177 Error("[inv] ReplaceItemWithNewLambdaBase Step D) plan B - wanted to create=" + m_NewItemType + " at bkp loc=" + backupLocation.DumpToString() + ", but failed");
178 return null;
179 }
180 return new_item;*/
181 }
182 }
183
184 // user did not asked for new entity
185 return null;
186 }
187
193 void CopyOldPropertiesToNew(notnull EntityAI old_item, EntityAI new_item)
194 {
195 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] ReplaceItemWithNewLambdaBase Step E) Copying props " + old_item + " --> " + new_item);
196 }
197
201 protected void DeleteOldEntity()
202 {
203 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] ReplaceItemWithNewLambdaBase Step F) delete old item=" + m_OldItem);
204 m_OldItem.DeleteSafe();
205 }
206
212 protected void CreateNetworkObjectInfo(EntityAI new_item)
213 {
214 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] ReplaceItemWithNewLambdaBase Step G) CreateNetworkObjectInfo =" + new_item);
215 if (new_item)
216 g_Game.RemoteObjectTreeCreate(new_item); // G) this forces server to send CreateVehicle Message to client. This is needed for preserving the appearance of network operations on client (so that DeleteObject(old) arrives before CreateVehicle(new)). @NOTE: this does not delete the object on server, only it's network representation.
217 }
218
224 protected void OnSuccess(EntityAI new_item)
225 {
226 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] ReplaceItemWithNewLambdaBase Step H) OnSuccess=" + new_item);
227 }
228
234 protected void OnAbort()
235 {
236 Print("Error [inv] ReplaceItemWithNewLambdaBase OnAbort");
237 }
238
239 void Execute(HumanInventoryWithFSM fsm_to_notify = null)
240 {
241 int t = g_Game.GetTime();
242 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[syncinv] t=" + t + " lambda.Execute start ");
243
244 // A) init
245 bool prepared = PrepareLocations();
246
247 if (prepared && CanExecuteLambda())
248 {
249 // B) rm old (and delete on client)
252 {
253 Error("[inv] ReplaceItemWithNewLambdaBase Step B) ABORT - failed while rm old item from loc=" + InventoryLocation.DumpToStringNullSafe(m_OldLocation));
254
255 if (fsm_to_notify)
256 fsm_to_notify.ProcessHandAbortEvent(new HandEventHumanCommandActionAborted(fsm_to_notify.GetManOwner()));
257 OnAbort();
258 return;
259 }
260
261 // C) rm NetworkObjectInfo from old item (+ send delete object tree to clients)
263
264 // D) mk new in place of old
265 EntityAI new_item = CreateNewEntity();
266 if (WantCreateNewEntity() && new_item == null)
267 {
268 //Error("[inv] ReplaceItemWithNewLambdaBase Step D) ABORT - wanted to create=" + m_NewItemType + " at loc=" + m_NewLocation.DumpToString() + ", but failed");
269 Print("Error [inv] ReplaceItemWithNewLambdaBase Step D) ABORT - wanted to create=" + m_NewItemType + " at loc=" + InventoryLocation.DumpToStringNullSafe(m_NewLocation) + ", but failed");
274
275 OnAbort();
276 if (fsm_to_notify)
277 fsm_to_notify.ProcessHandAbortEvent(new HandEventHumanCommandActionAborted(fsm_to_notify.GetManOwner()));
278 return;
279 }
280
281 // E) cpy props
283
284 // F) del old
286
287 // G) mk new NetworkObjectInfo
288 CreateNetworkObjectInfo(new_item);
289
290 // H) notification
291 OnSuccess(new_item);
292 }
293 else
294 {
295 Print("[syncinv] warning, lambda cannot be executed, skipping!");
296 if (fsm_to_notify)
297 fsm_to_notify.ProcessHandAbortEvent(new HandEventHumanCommandActionAborted(fsm_to_notify.GetManOwner()));
298 OnAbort();
299 return;
300 }
301 int te = g_Game.GetTime();
302 int dt = te - t;
303 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[syncinv] te=" + te + " lambda.Execute end, exec time=" + dt);
304 }
305
307 {
308 string s = "{ old=" + m_OldItem + " newType=" + m_NewItemType + "}";
309 return s;
310 }
311};
312
313
315{
316};
const int RF_NONE
Определения CentralEconomy.c:45
const int ECE_OBJECT_SWAP
Определения CentralEconomy.c:38
const int ECE_LOCAL
Определения CentralEconomy.c:24
const int ECE_PLACE_ON_SURFACE
Определения CentralEconomy.c:37
DayZGame g_Game
Определения DayZGame.c:3942
void hndDebugPrint(string s)
Определения HandFSM.c:1
InventoryLocationType
types of Inventory Location
Определения InventoryLocation.c:4
string path
Определения OptionSelectorMultistate.c:142
static proto native EntityAI LocationCreateLocalEntity(notnull InventoryLocation inv_loc, string type, int iSetupFlags, int iRotation)
creates new local item directly at location @NOTE: the item is created localy, i.e....
static proto native EntityAI LocationCreateEntity(notnull InventoryLocation inv_loc, string type, int iSetupFlags, int iRotation)
creates new item directly at location
static proto native bool LocationAddEntity(notnull InventoryLocation inv_loc)
adds item to inventory location
static proto native bool LocationCanRemoveEntity(notnull InventoryLocation inv_loc)
queries if the entity contained in inv_loc.m_item can be removed from ground/attachment/cargo/hands/....
static proto native bool LocationRemoveEntity(notnull InventoryLocation inv_loc)
removes item from inventory location
script counterpart to engine's class Inventory
HumanInventory... with FSM (synchronous, no anims)
Определения HumanInventoryWithFSM.c:6
static string DumpToStringNullSafe(InventoryLocation loc)
Определения InventoryLocation.c:233
InventoryLocation.
Определения InventoryLocation.c:30
static bool IsInventoryHFSMLogEnable()
Определения 3_Game/DayZ/tools/Debug.c:766
Определения EnMath3D.c:28
void ReplaceItemWithNewLambdaBase(EntityAI old_item, string new_item_type)
Определения ReplaceItemWithNewLambdaBase.c:13
void DeleteOldEntity()
Step F. - deletes physically old item.
Определения ReplaceItemWithNewLambdaBase.c:201
void OverrideNewLocation(InventoryLocation newLocation)
Определения ReplaceItemWithNewLambdaBase.c:19
void OnAbort()
Step Out - notification on abort.
Определения ReplaceItemWithNewLambdaBase.c:234
ref InventoryLocation m_OldLocation
Определения ReplaceItemWithNewLambdaBase.c:8
void CreateNetworkObjectInfo(EntityAI new_item)
Step G. - create NetworkObjectInfo for new item.
Определения ReplaceItemWithNewLambdaBase.c:212
ref InventoryLocation m_NewLocation
Определения ReplaceItemWithNewLambdaBase.c:9
void RemoveOldItemFromLocation()
Step B. - free location for new item @NOTE this operation does not delete the object,...
Определения ReplaceItemWithNewLambdaBase.c:86
void Execute(HumanInventoryWithFSM fsm_to_notify=null)
Определения ReplaceItemWithNewLambdaBase.c:239
void OnSuccess(EntityAI new_item)
Step H. - notification on finish.
Определения ReplaceItemWithNewLambdaBase.c:224
void CopyOldPropertiesToNew(notnull EntityAI old_item, EntityAI new_item)
Step E. copy properties from old object to the created one.
Определения ReplaceItemWithNewLambdaBase.c:193
EntityAI CreateNewEntity()
Step D. - create new entity (LOCAL) with specified type.
Определения ReplaceItemWithNewLambdaBase.c:131
bool PrepareLocations()
Step A. - prepare inventory locations.
Определения ReplaceItemWithNewLambdaBase.c:43
void RemoveNetworkObjectInfo()
Step C. - remove network part of the object @NOTE this operation does not delete the object,...
Определения ReplaceItemWithNewLambdaBase.c:115
Определения EnConvert.c:119
void Error(string err)
Messagebox with error message.
Определения EnDebug.c:90
proto void Print(void var)
Prints content of variable to console/log.
static void MatrixIdentity4(out vector mat[4])
Creates identity matrix.
Определения EnMath3D.c:256
const string CFG_VEHICLESPATH
Определения 3_Game/DayZ/constants.c:220