10 protected bool m_RemoveFromLocationPassed =
false;
11 private bool m_RemoveNetworkObjectInfoPassed =
false;
16 m_NewItemType = new_item_type;
21 m_NewLocation = newLocation;
24 void VerifyItemTypeBySlotType() {}
26 protected bool WantCreateNewEntity()
28 return m_NewLocation && m_NewItemType !=
string.Empty;
31 protected bool CanExecuteLambda()
43 protected bool PrepareLocations()
45 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[inv] ReplaceItemWithNewLambdaBase Step A) Prepare inventory locations, old_item=" + m_OldItem);
47 if (m_OldItem.GetInventory().GetCurrentInventoryLocation(m_OldLocation))
49 if (m_NewLocation ==
null)
52 m_NewLocation.CopyLocationFrom(m_OldLocation,
true);
55 if (!m_NewLocation.GetParent())
58 Math3D.MatrixIdentity4(m4);
59 m4[3] = m_NewLocation.GetPos();
66 m_OldLocation.GetDir(dir);
67 m_NewLocation.SetGroundEx(
null,m_NewLocation.GetPos(),dir);
71 m_NewLocation.SetGround(
null,m4);
78 Error(
"[inv] ReplaceItemWithNewLambdaBase Step A.1) failed to get old_item inventory location");
86 protected void RemoveOldItemFromLocation()
90 Error(
"[inv] ReplaceItemWithNewLambdaBase Step B) failed to remove old_item rom current inventory location");
91 m_RemoveFromLocationPassed =
false;
93 Print(
"[inv] ReplaceItemWithNewLambdaBase Step B) remove OK, loc=" +
InventoryLocation.DumpToStringNullSafe(m_OldLocation));
94 m_RemoveFromLocationPassed =
true;
96 protected void UndoRemoveOldItemFromLocation()
99 Error(
"[inv] ReplaceItemWithNewLambdaBase Step B) failed to undo remove");
100 Print(
"[inv] ReplaceItemWithNewLambdaBase Step B) undo remove OK, loc=" +
InventoryLocation.DumpToStringNullSafe(m_OldLocation));
107 protected void RemoveNetworkObjectInfo()
109 GetGame().RemoteObjectTreeDelete(m_OldItem);
111 m_RemoveNetworkObjectInfoPassed =
true;
113 protected void UndoRemoveNetworkObjectInfo()
115 GetGame().RemoteObjectTreeCreate(m_OldItem);
123 protected EntityAI CreateNewEntity()
125 if (WantCreateNewEntity())
127 VerifyItemTypeBySlotType();
130 switch (m_NewLocation.GetType())
138 new_item.SetOrientation(m_OldItem.GetOrientation());
143 m_NewLocation.SetAttachment(m_NewLocation.GetParent(),
null, m_NewLocation.GetSlot());
151 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[inv] ReplaceItemWithNewLambdaBase Step D) Created new new_item=" + new_item);
187 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[inv] ReplaceItemWithNewLambdaBase Step E) Copying props " + old_item +
" --> " + new_item);
193 protected void DeleteOldEntity()
195 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[inv] ReplaceItemWithNewLambdaBase Step F) delete old item=" + m_OldItem);
196 m_OldItem.DeleteSafe();
204 protected void CreateNetworkObjectInfo(
EntityAI new_item)
206 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[inv] ReplaceItemWithNewLambdaBase Step G) CreateNetworkObjectInfo =" + new_item);
208 GetGame().RemoteObjectTreeCreate(new_item);
216 protected void OnSuccess(
EntityAI new_item)
218 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[inv] ReplaceItemWithNewLambdaBase Step H) OnSuccess=" + new_item);
226 protected void OnAbort()
228 Print(
"Error [inv] ReplaceItemWithNewLambdaBase OnAbort");
237 bool prepared = PrepareLocations();
239 if (prepared && CanExecuteLambda())
242 RemoveOldItemFromLocation();
243 if (!m_RemoveFromLocationPassed)
245 Error(
"[inv] ReplaceItemWithNewLambdaBase Step B) ABORT - failed while rm old item from loc=" +
InventoryLocation.DumpToStringNullSafe(m_OldLocation));
248 fsm_to_notify.ProcessHandAbortEvent(
new HandEventHumanCommandActionAborted(fsm_to_notify.GetManOwner()));
254 RemoveNetworkObjectInfo();
257 EntityAI new_item = CreateNewEntity();
258 if (WantCreateNewEntity() && new_item ==
null)
261 Print(
"Error [inv] ReplaceItemWithNewLambdaBase Step D) ABORT - wanted to create=" + m_NewItemType +
" at loc=" +
InventoryLocation.DumpToStringNullSafe(m_NewLocation) +
", but failed");
262 if (m_RemoveFromLocationPassed)
263 UndoRemoveOldItemFromLocation();
264 if (m_RemoveNetworkObjectInfoPassed)
265 UndoRemoveNetworkObjectInfo();
269 fsm_to_notify.ProcessHandAbortEvent(
new HandEventHumanCommandActionAborted(fsm_to_notify.GetManOwner()));
274 CopyOldPropertiesToNew(m_OldItem, new_item);
280 CreateNetworkObjectInfo(new_item);
287 Print(
"[syncinv] warning, lambda cannot be executed, skipping!");
289 fsm_to_notify.ProcessHandAbortEvent(
new HandEventHumanCommandActionAborted(fsm_to_notify.GetManOwner()));
295 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[syncinv] te=" + te +
" lambda.Execute end, exec time=" + dt);
298 string DumpToString()
300 string s =
"{ old=" + m_OldItem +
" newType=" + m_NewItemType +
"}";