Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actiondiginstash.c
Go to the documentation of this file.
2 {
3  override void CreateActionComponent()
4  {
5  m_ActionData.m_ActionComponent = new CAContinuousTime(UATimeSpent.DIG_STASH);
6  }
7 };
8 
10 {
11  static float m_DigStashSlopeTolerance = 0.6;
12 
13  void ActionDigInStash()
14  {
15  m_CallbackClass = ActionDigInStashCB;
16  m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DIGMANIPULATE;
17  m_FullBody = true;
18  m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT;
20  m_Text = "#bury";
21  }
22 
23  override void CreateConditionComponents()
24  {
27  }
28 
29  override bool Can(PlayerBase player, ActionTarget target, ItemBase item, int condition_mask)
30  {
31  if (!super.Can(player, target, item, condition_mask))
32  return false;
33 
34  return player.CheckFreeSpace(vector.Forward, 1.0, false);
35  }
36 
37  override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
38  {
39  ItemBase targetIB;
40  if (Class.CastTo(targetIB, target.GetObject()) && targetIB.CanBeDigged())
41  {
42  if (player.IsPlacingLocal())
43  {
44  return false;
45  }
46 
47  if (targetIB.IsRuined() || targetIB.GetInventory().IsAttachment())
48  {
49  return false;
50  }
51 
52  if (targetIB.GetInventory().IsAttachment())
53  {
54  return false;
55  }
56 
57  if (targetIB.IsInherited(UndergroundStash))
58  {
59  return false;
60  }
61 
63  EntityAI entityToCheck = targetIB;
64  if (targetIB.GetInventory().IsInCargo())
65  entityToCheck = player;
66 
67  // here we check if a stash is nearby and block digging a new one in close proximity
68  array<Object> excludedObjects = new array<Object>;
69  excludedObjects.Insert(targetIB);
70  array<Object> nearbyObjects = new array<Object>;
71  // For now we exclude an area of 2 X 2 X 2 meters
72  if (GetGame().IsBoxColliding(entityToCheck.GetPosition(), entityToCheck.GetOrientation(), "2 2 2", excludedObjects, nearbyObjects))
73  {
74  for (int i = 0; i < nearbyObjects.Count(); i++)
75  {
76  if (nearbyObjects[i].IsInherited(UndergroundStash))
77  {
78  return false;
79  }
80  }
81  }
82 
83  // Check surface
84  int liquidType;
85  string surfaceType;
86  GetGame().SurfaceUnderObject(entityToCheck, surfaceType, liquidType);
87  if (!GetGame().IsSurfaceDigable(surfaceType))
88  {
89  return false;
90  }
91  else
92  {
94  vector position = entityToCheck.GetPosition();
95 
96  array<vector> positions = new array<vector>;
97  positions.Insert(position + "0.5 0 0.5");
98  positions.Insert(position + "-0.5 0 0.5");
99  positions.Insert(position + "0.5 0 -0.5");
100  positions.Insert(position + "-0.5 0 -0.5");
101 
102  float difference = GetGame().GetHighestSurfaceYDifference(positions);
103 
104  return difference < m_DigStashSlopeTolerance;
105  }
106  }
107 
108  return false;
109  }
110 
111  override void OnExecuteClient(ActionData action_data)
112  {
113  super.OnExecuteClient(action_data);
114 
115  SpawnParticleShovelRaise(action_data);
116  }
117 
118  override void OnExecuteServer(ActionData action_data)
119  {
120  super.OnExecuteServer(action_data);
121 
122  if (!GetGame().IsMultiplayer())
123  {
124  SpawnParticleShovelRaise(action_data);
125  }
126  }
127 
128  void SpawnParticleShovelRaise(ActionData action_data)
129  {
130  ParticleManager.GetInstance().PlayOnObject(ParticleList.DIGGING_STASH, action_data.m_Player);
131  }
132 
133  override void OnFinishProgressServer(ActionData action_data)
134  {
135  EntityAI targetEntity = EntityAI.Cast(action_data.m_Target.GetObject());
136  if (!targetEntity)
137  {
138  ErrorEx("Cannot get entity=" + targetEntity);
139  return;
140  }
141 
142  InventoryLocation targetIL = new InventoryLocation();
143  if (!targetEntity.GetInventory().GetCurrentInventoryLocation(targetIL))
144  {
145  ErrorEx("Cannot get inventory location of entity=" + targetEntity);
146  return;
147  }
148 
149  UndergroundStash stash = UndergroundStash.Cast(GetGame().CreateObjectEx("UndergroundStash", targetEntity.GetPosition(), ECE_PLACE_ON_SURFACE));
150  if (stash)
151  {
152  stash.PlaceOnGround();
153  if (GameInventory.LocationCanRemoveEntity(targetIL))
154  {
155  action_data.m_Player.ServerTakeEntityToTargetCargo(stash, targetEntity);
156  }
157  else
158  {
159  Debug.Log(string.Format("Cannot remove entity=%1 obj from current location=%2", targetEntity, InventoryLocation.DumpToStringNullSafe(targetIL)));
160  }
161  }
162  else
163  {
164  ErrorEx("Stash not spawned!");
165  }
166 
167  //Apply tool damage
168  MiscGameplayFunctions.DealAbsoluteDmg(action_data.m_MainItem, 10);
169  action_data.m_Player.GetSoftSkillsManager().AddSpecialty(m_SpecialtyWeight);
170  }
171 
172  override string GetAdminLogMessage(ActionData action_data)
173  {
174  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());
175  }
176 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
CAContinuousTime
Definition: cacontinuoustime.c:1
UASoftSkillsWeight
Definition: actionconstants.c:118
CCTObject
Definition: cctobject.c:1
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
ECE_PLACE_ON_SURFACE
const int ECE_PLACE_ON_SURFACE
Definition: centraleconomy.c:37
UAMaxDistances
Definition: actionconstants.c:104
ErrorEx
enum ShapeType ErrorEx
ActionDigInStashCB
Definition: actiondiginstash.c:1
m_FullBody
protected bool m_FullBody
Definition: actionbase.c:52
ParticleList
Definition: particlelist.c:11
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
ActionDigInStash
Definition: actiondiginstash.c:9
UATimeSpent
Definition: actionconstants.c:26
ActionContinuousBaseCB
Definition: actioncontinuousbase.c:1
array< Object >
m_Text
protected string m_Text
Definition: actionbase.c:49
Debug
Definition: debug.c:13
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
ActionContinuousBase
Definition: actioncontinuousbase.c:132
CCINonRuined
Definition: ccinonruined.c:1
m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition: actionbase.c:56
ParticleManager
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
Definition: particlemanager.c:84
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
m_SpecialtyWeight
protected float m_SpecialtyWeight
Definition: actionbase.c:68
m_StanceMask
protected int m_StanceMask
Definition: actionbase.c:53
EntityAI
Definition: building.c:5
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78