Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
trap_rabbitsnare.c
Go to the documentation of this file.
1 class Trap_RabbitSnare extends TrapSpawnBase
2 {
3  void Trap_RabbitSnare()
4  {
5  m_DefectRate = 15; //Added damage after trap activation
6 
7  m_InitWaitTime = Math.RandomInt(60, 900);
8  m_UpdateWaitTime = 30;
9  m_IsFoldable = true;
10  m_IsUsable = true;
11  m_MinimalDistanceFromPlayersToCatch = 10;
12 
13  m_BaitCatchProb = 85;
14  m_NoBaitCatchProb = 15;
15 
16  m_AnimationPhaseSet = "inventory";
17  m_AnimationPhaseTriggered = "placing";
18  m_AnimationPhaseUsed = "triggered";
19 
20  m_WaterSurfaceForSetup = false;
21 
22  m_CatchesGroundAnimal = new multiMap<string, float>;
23  m_CatchesGroundAnimal.Insert("DeadRooster", 1);
24  m_CatchesGroundAnimal.Insert("DeadChicken_White", 1);
25  m_CatchesGroundAnimal.Insert("DeadChicken_Spotted", 1);
26  m_CatchesGroundAnimal.Insert("DeadChicken_Brown", 1);
27  // ALWAYS keep rabbit last as that is how it gets the rabbit in case of rabbit specific bait
28  m_CatchesGroundAnimal.Insert("DeadRabbit", 1);
29  }
30 
31  override bool CanBePlaced(Man player, vector position)
32  {
33  if (m_IsBeingPlaced)
34  return true;
35 
36  int liquidType;
37  string surfaceType;
38  g_Game.SurfaceUnderObject(PlayerBase.Cast(player).GetHologramLocal().GetProjectionEntity(), surfaceType, liquidType);
39 
40  return g_Game.IsSurfaceDigable(surfaceType);
41  }
42 
43  override void OnVariablesSynchronized()
44  {
45  super.OnVariablesSynchronized();
46 
47  if (IsPlaceSound())
48  {
50  }
51  }
52 
53  override void SetupTrap()
54  {
55  if ( GetGame().IsServer() )
56  {
57  if ( GetHierarchyRootPlayer().CanDropEntity( this ) )
58  {
59  if ( IsRuined() )
60  {
61  PlayerBase player = PlayerBase.Cast( GetHierarchyRootPlayer() );
62  }
63  else
64  {
65  PlayerBase owner_player = PlayerBase.Cast( GetHierarchyRootPlayer() );
66 
67  //GetDirection
68  vector trapPos = owner_player.GetDirection();
69  trapPos[1] = 0;
70  SetPosition( owner_player.GetPosition() + trapPos );
71 
72  SetActive();
73 
74  SetOrientation( owner_player.GetOrientation() );
75  }
76  }
77  }
78  }
79 
80  override void SpawnCatch()
81  {
82  super.SpawnCatch();
83 
84  if ( m_CanCatch )
85  {
86  multiMap<string, float> catches;
87 
88  // We read the relevant catch map
89  ItemBase catch;
90  catches = m_CatchesGroundAnimal;
91 
92  // The catch map contains data
93  if ( catches && catches.Count() > 0 )
94  {
95  // select random object from catches
96  int count = catches.Count() - 1;
97  int randomCatchIndex = Math.RandomInt( 0, count );
98 
99  if ( Math.RandomFloat(0, 100) < m_FinalCatchProb )
100  {
101  if ( m_Bait )
102  {
103  if ( m_Bait.IsInherited( Worm ) )
104  {
105  // We can only catch chicken, so exclude the rabbit
106  randomCatchIndex = Math.RandomInt( 0, count - 1 );
107  catch = ItemBase.Cast( GetGame().CreateObjectEx( catches.GetKeyByIndex( randomCatchIndex ), m_PreyPos, ECE_PLACE_ON_SURFACE ) );
108  }
109  else
110  {
111  // Get the last index, which is the rabbit
112  randomCatchIndex = count;
113  catch = ItemBase.Cast( GetGame().CreateObjectEx( catches.GetKeyByIndex( randomCatchIndex ), m_PreyPos, ECE_PLACE_ON_SURFACE ) );
114  }
115  }
116  else
117  {
118  // No bait, 50 / 50 rabbit
119  randomCatchIndex = Math.RandomIntInclusive( 0, 1 );
120  if ( randomCatchIndex == 0 )
121  {
122  randomCatchIndex = Math.RandomInt( 0, count - 1 );
123  catch = ItemBase.Cast( GetGame().CreateObjectEx( catches.GetKeyByIndex( randomCatchIndex ), m_PreyPos, ECE_PLACE_ON_SURFACE ) );
124  }
125  else
126  {
127  randomCatchIndex = count;
128  catch = ItemBase.Cast( GetGame().CreateObjectEx( catches.GetKeyByIndex( randomCatchIndex ), m_PreyPos, ECE_PLACE_ON_SURFACE ) );
129  }
130  }
131 
132  // We set quantity of prey
133  if ( catch )
134  CatchSetQuant( catch );
135  }
136 
137  // We update the state
138  SetUsed();
139 
140  // We remove the bait from this trap
141  if ( m_Bait )
142  m_Bait.Delete();
143  }
144 
145  // We damage the trap
146  AddDefect();
147  }
148  }
149 
150  //================================================================
151  // ADVANCED PLACEMENT
152  //================================================================
153 
154  override void OnPlacementComplete( Man player, vector position = "0 0 0", vector orientation = "0 0 0" )
155  {
156  super.OnPlacementComplete( player, position, orientation );
157  SetOrientation(orientation);
158  SetIsPlaceSound( true );
159  }
160 
161  override bool IsDeployable()
162  {
163  return true;
164  }
165 
166  override string GetDeploySoundset()
167  {
168  return "placeRabbitSnareTrap_SoundSet";
169  }
170 
171  override string GetLoopDeploySoundset()
172  {
173  return "rabbitsnare_deploy_SoundSet";
174  }
175 
176  override void SetActions()
177  {
178  super.SetActions();
179 
180  // We remove the hunting trap deploy action in order to all advanced placement
182 
185  }
186 
187  // ===============================================================
188  // ===================== DEPRECATED ============================
189  // ===============================================================
190 
191  override void AlignCatch( ItemBase obj, string catch_name )
192  {
193  if ( catch_name == "Animal_LepusEuropaeus" )
194  {
195  obj.SetOrientation( GetOrientation() );
196 
197  vector forward_vec = GetDirection();
198  vector side_vec = forward_vec.Perpend( ) * -0.22;
199  forward_vec = forward_vec * -0.3;
200 
201  vector chatch_pos = obj.GetPosition() + forward_vec + side_vec;
202  obj.SetPosition( chatch_pos );
203  }
204  }
205 }
206 
207 class RabbitSnareTrap extends Trap_RabbitSnare
208 {
209 
210 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
m_IsBeingPlaced
bool m_IsBeingPlaced
Definition: itembase.c:52
ActionDeployObject
PlaceObjectActionReciveData ActionReciveData ActionDeployObject()
Definition: actiondeployobject.c:9
SetActive
void SetActive()
Definition: trapbase.c:437
RemoveAction
void RemoveAction(typename actionName)
Definition: advancedcommunication.c:118
OnVariablesSynchronized
override void OnVariablesSynchronized()
Definition: anniversarymusicsource.c:42
ActionDeployHuntingTrap
Definition: actiondeployhuntingtrap.c:1
ECE_PLACE_ON_SURFACE
const int ECE_PLACE_ON_SURFACE
Definition: centraleconomy.c:37
IsPlaceSound
bool IsPlaceSound()
Definition: itembase.c:4288
SetupTrap
void SetupTrap()
Definition: trapbase.c:402
TrapSpawnBase
Definition: trap_fishnet.c:1
OnPlacementComplete
override void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
Definition: explosivesbase.c:133
m_AnimationPhaseSet
string m_AnimationPhaseSet
Definition: trapbase.c:33
GetLoopDeploySoundset
override string GetLoopDeploySoundset()
Definition: largetent.c:151
ActionTogglePlaceObject
Definition: actiontoggleplaceobject.c:1
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
PlayPlaceSound
void PlayPlaceSound()
Definition: itembase.c:4348
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
CanBePlaced
override bool CanBePlaced(Man player, vector position)
Definition: trapbase.c:605
SetActions
void SetActions()
Definition: advancedcommunication.c:79
SetIsPlaceSound
void SetIsPlaceSound(bool is_place_sound)
Definition: itembase.c:4283
IsDeployable
override bool IsDeployable()
Definition: basebuildingbase.c:339
SetPosition
proto native void SetPosition(vector position)
Set the world position of the Effect.
Definition: effect.c:436
AddDefect
void AddDefect()
Definition: trapbase.c:429
Math
Definition: enmath.c:6
m_DefectRate
float m_DefectRate
Definition: trapbase.c:19
m_AnimationPhaseTriggered
string m_AnimationPhaseTriggered
Definition: trapbase.c:34
m_InitWaitTime
float m_InitWaitTime
Definition: trapbase.c:17
GetDeploySoundset
override string GetDeploySoundset()
Definition: largetent.c:146
GetOrientation
vector GetOrientation()
Definition: areadamagemanager.c:306