actiondiginstash.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. class ActionDigInStashCB : ActionContinuousBaseCB
  2. {
  3. override void CreateActionComponent()
  4. {
  5. m_ActionData.m_ActionComponent = new CAContinuousTime(UATimeSpent.DIG_STASH);
  6. }
  7. };
  8. class ActionDigInStash: ActionContinuousBase
  9. {
  10. static float m_DigStashSlopeTolerance = 0.6;
  11. void ActionDigInStash()
  12. {
  13. m_CallbackClass = ActionDigInStashCB;
  14. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DIGMANIPULATE;
  15. m_FullBody = true;
  16. m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT;
  17. m_SpecialtyWeight = UASoftSkillsWeight.ROUGH_LOW;
  18. m_Text = "#bury";
  19. }
  20. override void CreateConditionComponents()
  21. {
  22. m_ConditionTarget = new CCTObject(UAMaxDistances.DEFAULT);
  23. m_ConditionItem = new CCINonRuined();
  24. }
  25. override bool Can(PlayerBase player, ActionTarget target, ItemBase item, int condition_mask)
  26. {
  27. if (!super.Can(player, target, item, condition_mask))
  28. return false;
  29. return player.CheckFreeSpace(vector.Forward, 1.0, false);
  30. }
  31. override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
  32. {
  33. ItemBase targetIB;
  34. if (Class.CastTo(targetIB, target.GetObject()) && targetIB.CanBeDigged())
  35. {
  36. if (player.IsPlacingLocal())
  37. {
  38. return false;
  39. }
  40. if (targetIB.IsRuined() || targetIB.GetInventory().IsAttachment())
  41. {
  42. return false;
  43. }
  44. if (targetIB.GetInventory().IsAttachment())
  45. {
  46. return false;
  47. }
  48. if (targetIB.IsInherited(UndergroundStash))
  49. {
  50. return false;
  51. }
  52. //! was initialized from inventory?
  53. EntityAI entityToCheck = targetIB;
  54. if (targetIB.GetInventory().IsInCargo())
  55. entityToCheck = player;
  56. // here we check if a stash is nearby and block digging a new one in close proximity
  57. array<Object> excludedObjects = new array<Object>();
  58. excludedObjects.Insert(targetIB);
  59. array<Object> nearbyObjects = new array<Object>();
  60. // For now we exclude an area of 2 X 2 X 2 meters
  61. if (GetGame().IsBoxColliding(entityToCheck.GetPosition(), entityToCheck.GetOrientation(), "2 2 2", excludedObjects, nearbyObjects))
  62. {
  63. foreach (Object nearbyObject : nearbyObjects)
  64. {
  65. if (nearbyObject.IsInherited(UndergroundStash))
  66. return false;
  67. }
  68. }
  69. // Check surface
  70. int liquidType;
  71. string surfaceType;
  72. GetGame().SurfaceUnderObject(entityToCheck, surfaceType, liquidType);
  73. if (!GetGame().IsSurfaceDigable(surfaceType))
  74. {
  75. return false;
  76. }
  77. else
  78. {
  79. //! Check slope angle
  80. vector position = entityToCheck.GetPosition();
  81. array<vector> positions = new array<vector>;
  82. positions.Insert(position + "0.5 0 0.5");
  83. positions.Insert(position + "-0.5 0 0.5");
  84. positions.Insert(position + "0.5 0 -0.5");
  85. positions.Insert(position + "-0.5 0 -0.5");
  86. float difference = GetGame().GetHighestSurfaceYDifference(positions);
  87. return difference < m_DigStashSlopeTolerance;
  88. }
  89. }
  90. return false;
  91. }
  92. override void OnExecuteClient(ActionData action_data)
  93. {
  94. super.OnExecuteClient(action_data);
  95. SpawnParticleShovelRaise(action_data);
  96. }
  97. override void OnExecuteServer(ActionData action_data)
  98. {
  99. super.OnExecuteServer(action_data);
  100. if (!GetGame().IsMultiplayer())
  101. {
  102. SpawnParticleShovelRaise(action_data);
  103. }
  104. }
  105. void SpawnParticleShovelRaise(ActionData action_data)
  106. {
  107. ParticleManager.GetInstance().PlayOnObject(ParticleList.DIGGING_STASH, action_data.m_Player);
  108. }
  109. override void OnFinishProgressServer(ActionData action_data)
  110. {
  111. EntityAI targetEntity = EntityAI.Cast(action_data.m_Target.GetObject());
  112. if (!targetEntity)
  113. {
  114. ErrorEx("Cannot get entity=" + targetEntity);
  115. return;
  116. }
  117. InventoryLocation targetIL = new InventoryLocation();
  118. if (!targetEntity.GetInventory().GetCurrentInventoryLocation(targetIL))
  119. {
  120. ErrorEx("Cannot get inventory location of entity=" + targetEntity);
  121. return;
  122. }
  123. EntityAI entityToCheck = targetEntity;
  124. if (targetEntity.GetInventory().IsInCargo())
  125. entityToCheck = action_data.m_Player;
  126. int liquidType;
  127. string surfaceType;
  128. GetGame().SurfaceUnderObject(entityToCheck, surfaceType, liquidType);
  129. string undergroundStashType;
  130. GetGame().GetSurfaceDigPile(surfaceType, undergroundStashType);
  131. if (undergroundStashType == "")
  132. undergroundStashType = "UndergroundStash";
  133. UndergroundStash stash = UndergroundStash.Cast(GetGame().CreateObjectEx(undergroundStashType, targetEntity.GetPosition(), ECE_PLACE_ON_SURFACE));
  134. if (stash)
  135. {
  136. ClearActionJuncture(action_data);
  137. stash.PlaceOnGround();
  138. InventoryLocation ilj = new InventoryLocation;
  139. stash.GetInventory().GetCurrentInventoryLocation(ilj);
  140. if (GameInventory.LocationCanRemoveEntity(targetIL))
  141. {
  142. GetGame().AddInventoryJunctureEx(action_data.m_Player, targetEntity, ilj, true, 10000);
  143. GetGame().ClearJunctureEx(action_data.m_Player, targetEntity);
  144. if (!GetGame().IsMultiplayer())
  145. {
  146. ClearInventoryReservationEx(action_data);
  147. action_data.m_Player.LocalTakeEntityToTargetCargo(stash, targetEntity);
  148. }
  149. else
  150. action_data.m_Player.ServerTakeEntityToTargetCargo(stash, targetEntity);
  151. }
  152. else
  153. {
  154. Debug.Log(string.Format("Cannot remove entity=%1 obj from current location=%2", targetEntity, InventoryLocation.DumpToStringNullSafe(targetIL)));
  155. }
  156. }
  157. else
  158. {
  159. ErrorEx("Stash not spawned!");
  160. }
  161. //Apply tool damage
  162. MiscGameplayFunctions.DealEvinronmentAdjustedDmg(action_data.m_MainItem, action_data.m_Player, 10);
  163. }
  164. override string GetAdminLogMessage(ActionData action_data)
  165. {
  166. return string.Format("Player %1 Dug in %2 at position %3", action_data.m_Player, action_data.m_Target.GetObject(), action_data.m_Target.GetObject().GetPosition());
  167. }
  168. }