actiondeploybase.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. override ActionData CreateActionData()
  41. {
  42. PlaceObjectActionData action_data = new PlaceObjectActionData();
  43. m_MovedItems = new array<ItemBase>();
  44. return action_data;
  45. }
  46. override Vector2 GetCameraUDAngle()
  47. {
  48. Vector2 udAngle = new Vector2(-80, -20);
  49. return udAngle;
  50. }
  51. override void OnFinishProgressServer(ActionData action_data)
  52. {
  53. PlaceObjectActionData poActionData;
  54. poActionData = PlaceObjectActionData.Cast(action_data);
  55. if (!poActionData)
  56. return;
  57. if (!action_data.m_MainItem)
  58. return;
  59. EntityAI entity_for_placing = action_data.m_MainItem;
  60. vector position;
  61. vector orientation;
  62. // In case of placement with hologram
  63. if (action_data.m_Player.GetHologramServer())
  64. {
  65. position = action_data.m_Player.GetLocalProjectionPosition();
  66. orientation = action_data.m_Player.GetLocalProjectionOrientation();
  67. action_data.m_Player.GetHologramServer().EvaluateCollision(action_data.m_MainItem);
  68. if (GetGame().IsMultiplayer() && action_data.m_Player.GetHologramServer().IsColliding())
  69. return;
  70. action_data.m_Player.GetHologramServer().PlaceEntity(entity_for_placing);
  71. if (GetGame().IsMultiplayer())
  72. action_data.m_Player.GetHologramServer().CheckPowerSource();
  73. }
  74. else
  75. {
  76. position = action_data.m_Player.GetPosition();
  77. orientation = action_data.m_Player.GetOrientation();
  78. position = position + (action_data.m_Player.GetDirection() * POSITION_OFFSET);
  79. }
  80. MoveEntityToFinalPosition(action_data, position, orientation);
  81. GetGame().ClearJunctureEx(action_data.m_Player, entity_for_placing);
  82. action_data.m_MainItem.SetIsBeingPlaced(false);
  83. poActionData.m_AlreadyPlaced = true;
  84. entity_for_placing.OnPlacementComplete(action_data.m_Player, position, orientation); //beware, this WILL fire on server before the item is moved to final position!
  85. action_data.m_Player.PlacingCompleteServer();
  86. m_MovedItems.Clear();
  87. }
  88. override void OnItemLocationChanged(ItemBase item)
  89. {
  90. super.OnItemLocationChanged(item);
  91. if (!GetGame().IsDedicatedServer())
  92. {
  93. if (m_MovedItems)
  94. m_MovedItems.Insert(item);
  95. }
  96. }
  97. override void OnUpdate(ActionData action_data)
  98. {
  99. super.OnUpdate(action_data);
  100. foreach (ItemBase item : m_MovedItems)
  101. {
  102. if (item == action_data.m_MainItem)
  103. {
  104. InventoryLocation loc = new InventoryLocation();
  105. item.GetInventory().GetCurrentInventoryLocation(loc);
  106. if (loc && loc.GetType() == InventoryLocationType.GROUND) // if main item is placed on ground during deploy, re-reserve it
  107. InventoryReservation(action_data);
  108. }
  109. }
  110. m_MovedItems.Clear();
  111. }
  112. void DropDuringPlacing(PlayerBase player)
  113. {
  114. ItemBase item;
  115. if (!Class.CastTo(item, player.GetItemInHands()))
  116. return;
  117. if (item.IsBasebuildingKit())
  118. return;
  119. player.PredictiveDropEntity(item);
  120. }
  121. void MoveEntityToFinalPosition(ActionData action_data, vector position, vector orientation)
  122. {
  123. if (action_data.m_MainItem.IsBasebuildingKit())
  124. return;
  125. EntityAI entity_for_placing = action_data.m_MainItem;
  126. vector rotation_matrix[3];
  127. float direction[4];
  128. InventoryLocation source = new InventoryLocation;
  129. InventoryLocation destination = new InventoryLocation;
  130. Math3D.YawPitchRollMatrix(orientation, rotation_matrix);
  131. Math3D.MatrixToQuat(rotation_matrix, direction);
  132. if (entity_for_placing.GetInventory().GetCurrentInventoryLocation(source))
  133. {
  134. destination.SetGroundEx(entity_for_placing, position, direction);
  135. if (GetGame().IsMultiplayer())
  136. action_data.m_Player.ServerTakeToDst(source, destination);
  137. else // singleplayer
  138. MoveEntityToFinalPositionSinglePlayer(action_data, source, destination);
  139. }
  140. }
  141. void MoveEntityToFinalPositionSinglePlayer(ActionData action_data, InventoryLocation source, InventoryLocation destination)
  142. {
  143. if (HasProgress())
  144. action_data.m_Player.GetInventory().TakeToDst(InventoryMode.LOCAL, source, destination); // from ground to target position
  145. else
  146. action_data.m_Player.GetDayZPlayerInventory().RedirectToHandEvent(InventoryMode.LOCAL, source, destination); // placing directly from inventory
  147. }
  148. }