actiondeploybase.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. class PlaceObjectActionData : ActionData
  2. {
  3. vector m_Position;
  4. vector m_Orientation;
  5. bool m_AlreadyPlaced;
  6. }
  7. class ActiondeployObjectCB : ActionContinuousBaseCB
  8. {
  9. override void CreateActionComponent()
  10. {
  11. m_ActionData.m_ActionComponent = new CAContinuousTime(m_ActionData.m_MainItem.GetDeployTime());
  12. }
  13. //!DEPRECATED
  14. void DropDuringPlacing();
  15. }
  16. class ActionDeployBase : ActionContinuousBase
  17. {
  18. protected const float POSITION_OFFSET = 0.5; // The forward offset at which the item will be placed (if not using hologram)
  19. protected ref array<ItemBase> m_MovedItems;
  20. void ActionDeployBase()
  21. {
  22. m_CallbackClass = ActiondeployObjectCB;
  23. m_SpecialtyWeight = UASoftSkillsWeight.PRECISE_LOW;
  24. m_FullBody = true;
  25. m_Text = "#deploy_object";
  26. }
  27. override void CreateConditionComponents()
  28. {
  29. m_ConditionItem = new CCINone();
  30. m_ConditionTarget = new CCTNone();
  31. }
  32. override bool HasTarget()
  33. {
  34. return false;
  35. }
  36. override bool HasProgress()
  37. {
  38. return true;
  39. }
  40. //base CAN function without hologram, but inherited action should use it
  41. bool ActionUsesHologram()
  42. {
  43. return false;
  44. }
  45. override ActionData CreateActionData()
  46. {
  47. PlaceObjectActionData action_data = new PlaceObjectActionData();
  48. m_MovedItems = new array<ItemBase>();
  49. return action_data;
  50. }
  51. override Vector2 GetCameraUDAngle()
  52. {
  53. Vector2 udAngle = new Vector2(-80, -20);
  54. return udAngle;
  55. }
  56. override void OnFinishProgressServer(ActionData action_data)
  57. {
  58. PlaceObjectActionData poActionData = PlaceObjectActionData.Cast(action_data);
  59. if (!poActionData)
  60. return;
  61. if (!poActionData.m_MainItem)
  62. return;
  63. EntityAI entity_for_placing = poActionData.m_MainItem;
  64. vector position = vector.Zero;
  65. vector orientation = vector.Zero;
  66. // In case of placement action that requires hologram, look for it, or fail
  67. if (ActionUsesHologram())
  68. {
  69. if (poActionData.m_Player.GetHologramServer())
  70. {
  71. position = poActionData.m_Position;
  72. orientation = poActionData.m_Orientation;
  73. poActionData.m_Player.GetHologramServer().EvaluateCollision(poActionData.m_MainItem);
  74. if (GetGame().IsMultiplayer() && poActionData.m_Player.GetHologramServer().IsColliding())
  75. return;
  76. poActionData.m_Player.GetHologramServer().PlaceEntity(entity_for_placing);
  77. if (GetGame().IsMultiplayer())
  78. poActionData.m_Player.GetHologramServer().CheckPowerSource();
  79. #ifdef DEVELOPER
  80. if (IsCLIParam("hologramLogs"))
  81. {
  82. Debug.Log(string.Format("Hologram of %1 found, deployment successful.", poActionData.m_MainItem), "hologramLogs");
  83. Debug.Log(string.Format("Pos Comparison | player: %1 | hologram: %2 | action data: %3", poActionData.m_Player.GetPosition(),poActionData.m_Player.GetLocalProjectionPosition(),position), "hologramLogs");
  84. }
  85. #endif
  86. }
  87. else
  88. {
  89. Debug.Log(string.Format("Expected hologram of %1 not found, failing deployment!", poActionData.m_MainItem), Type().ToString());
  90. return;
  91. }
  92. }
  93. else //action does NOT require hologram in the first place, take player's info instead
  94. {
  95. position = poActionData.m_Player.GetPosition();
  96. orientation = poActionData.m_Player.GetOrientation();
  97. position = position + (poActionData.m_Player.GetDirection() * POSITION_OFFSET);
  98. }
  99. MoveEntityToFinalPosition(poActionData, position, orientation);
  100. GetGame().ClearJunctureEx(poActionData.m_Player, entity_for_placing);
  101. poActionData.m_MainItem.SetIsBeingPlaced(false);
  102. poActionData.m_AlreadyPlaced = true;
  103. entity_for_placing.OnPlacementComplete(poActionData.m_Player, position, orientation); //beware, this WILL fire on server before the item is moved to final position!
  104. poActionData.m_Player.PlacingCompleteServer();
  105. m_MovedItems.Clear();
  106. }
  107. override void OnItemLocationChanged(ItemBase item)
  108. {
  109. super.OnItemLocationChanged(item);
  110. if (!GetGame().IsDedicatedServer())
  111. {
  112. if (m_MovedItems)
  113. m_MovedItems.Insert(item);
  114. }
  115. }
  116. override void OnUpdate(ActionData action_data)
  117. {
  118. super.OnUpdate(action_data);
  119. foreach (ItemBase item : m_MovedItems)
  120. {
  121. if (item == action_data.m_MainItem)
  122. {
  123. InventoryLocation loc = new InventoryLocation();
  124. item.GetInventory().GetCurrentInventoryLocation(loc);
  125. if (loc && loc.GetType() == InventoryLocationType.GROUND) // if main item is placed on ground during deploy, re-reserve it
  126. InventoryReservation(action_data);
  127. }
  128. }
  129. m_MovedItems.Clear();
  130. }
  131. void DropDuringPlacing(PlayerBase player)
  132. {
  133. ItemBase item;
  134. if (!Class.CastTo(item, player.GetItemInHands()))
  135. return;
  136. if (item.IsBasebuildingKit())
  137. return;
  138. player.PredictiveDropEntity(item);
  139. }
  140. void MoveEntityToFinalPosition(ActionData action_data, vector position, vector orientation)
  141. {
  142. if (action_data.m_MainItem.IsBasebuildingKit())
  143. return;
  144. EntityAI entity_for_placing = action_data.m_MainItem;
  145. vector rotation_matrix[3];
  146. float direction[4];
  147. InventoryLocation source = new InventoryLocation;
  148. InventoryLocation destination = new InventoryLocation;
  149. Math3D.YawPitchRollMatrix(orientation, rotation_matrix);
  150. Math3D.MatrixToQuat(rotation_matrix, direction);
  151. if (entity_for_placing.GetInventory().GetCurrentInventoryLocation(source))
  152. {
  153. destination.SetGroundEx(entity_for_placing, position, direction);
  154. if (GetGame().IsMultiplayer())
  155. action_data.m_Player.ServerTakeToDst(source, destination);
  156. else // singleplayer
  157. MoveEntityToFinalPositionSinglePlayer(action_data, source, destination);
  158. }
  159. }
  160. void MoveEntityToFinalPositionSinglePlayer(ActionData action_data, InventoryLocation source, InventoryLocation destination)
  161. {
  162. if (HasProgress())
  163. action_data.m_Player.GetInventory().TakeToDst(InventoryMode.LOCAL, source, destination); // from ground to target position
  164. else
  165. action_data.m_Player.GetDayZPlayerInventory().RedirectToHandEvent(InventoryMode.LOCAL, source, destination); // placing directly from inventory
  166. }
  167. }