Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
trap_smallfish.c
Go to the documentation of this file.
1 class Trap_SmallFish extends TrapSpawnBase
2 {
3  void Trap_SmallFish()
4  {
5  m_DefectRate = 15; //Added damage after trap activation
6 
7  m_InitWaitTime = Math.RandomFloat(900,1500);
8  m_UpdateWaitTime = 30;
9 
10  m_AnimationPhaseSet = "inventory";
11  m_AnimationPhaseTriggered = "placing";
12  m_AnimationPhaseUsed = "triggered";
13 
14  m_MinimalDistanceFromPlayersToCatch = 15;
15 
16  m_BaitCatchProb = 85;
17  m_NoBaitCatchProb = 15;
18 
19  m_WaterSurfaceForSetup = true;
20 
21  m_CatchesPond = new multiMap<string, float>;
22  m_CatchesPond.Insert("Bitterlings", 1);
23 
24  m_CatchesSea = new multiMap<string, float>;
25  m_CatchesSea.Insert("Sardines",1);
26  }
27 
28  override void OnVariablesSynchronized()
29  {
30  super.OnVariablesSynchronized();
31 
32  if ( IsPlaceSound() )
33  {
35  }
36  }
37 
38  override void SpawnCatch()
39  {
40  super.SpawnCatch();
41 
42  if ( m_CanCatch )
43  {
44  // We get the prey position for spawning
45  multiMap<string, float> catches;
46  vector pos = GetPosition();
47 
48  ItemBase catch;
49  // Select catch type depending on water type ( FRESH VS SALT )
50  if ( GetGame().SurfaceIsSea( pos[0], pos[2] ) )
51  {
52  catches = m_CatchesSea;
53  }
54  else if ( GetGame().SurfaceIsPond( pos[0], pos[2] ) )
55  {
56  catches = m_CatchesPond;
57  }
58 
59  if ( catches && catches.Count() > 0 )
60  {
61  // select random object from catches
62  int count = catches.Count() - 1;
63  int randomCatchIndex = Math.RandomInt( 0, count );
64 
65  if ( Math.RandomFloat(0, 100) < m_FinalCatchProb )
66  {
67  catch = ItemBase.Cast( GetGame().CreateObjectEx( catches.GetKeyByIndex(randomCatchIndex), m_PreyPos, ECE_NONE ) );
68 
69  // Set the quantity of caught prey
70  if ( catch )
71  CatchSetQuant( catch );
72  }
73 
74  // We change the trap state and visuals
75  SetUsed();
76 
77  // We remove the bait from this trap
78  if ( m_Bait )
79  m_Bait.Delete();
80  }
81 
82  // Deal damage to trap
83  AddDefect();
84  }
85  }
86 
87  //========================================================
88  //============= PLACING AND INVENTORY EVENTS =============
89  //========================================================
90 
91  override bool IsPlaceableAtPosition( vector position )
92  {
93  return IsSurfaceWater( position );
94  }
95 
96  override bool CanReceiveAttachment( EntityAI attachment, int slotId )
97  {
98  if ( !attachment.IsInherited( Worm ) )
99  return false;
100 
101  return super.CanReceiveAttachment( attachment, slotId );
102  }
103 
104  #ifdef PLATFORM_WINDOWS
105  // How one sees the tripwire when in vicinity
106  override int GetViewIndex()
107  {
108  if ( MemoryPointExists( "invView2" ) )
109  {
111  GetInventory().GetCurrentInventoryLocation( il );
112  InventoryLocationType type = il.GetType();
113  switch ( type )
114  {
115  case InventoryLocationType.CARGO:
116  {
117  return 0;
118  }
119  case InventoryLocationType.ATTACHMENT:
120  {
121  return 1;
122  }
123  case InventoryLocationType.HANDS:
124  {
125  return 0;
126  }
127  case InventoryLocationType.GROUND:
128  {
129  // Different view index depending on deployment state
130  if ( IsDeployed() )
131  return 1;
132 
133  // When folded
134  return 0;
135  }
136  case InventoryLocationType.PROXYCARGO:
137  {
138  return 0;
139  }
140  default:
141  {
142  if ( IsDeployed() )
143  return 1;
144 
145  // When folded
146  return 0;
147  }
148  }
149  }
150  return 0;
151  }
152  #endif
153 }
154 
155 class SmallFishTrap extends Trap_SmallFish
156 {
157  // DEPRECATED
159 
160  //================================================================
161  // ADVANCED PLACEMENT
162  //================================================================
163 
164  override void OnPlacementComplete( Man player, vector position = "0 0 0", vector orientation = "0 0 0" )
165  {
166  super.OnPlacementComplete( player, position, orientation );
167 
168  SetIsPlaceSound( true );
169  }
170 
171  override bool IsDeployable()
172  {
173  return true;
174  }
175 
176  override string GetDeploySoundset()
177  {
178  return "placeSmallFishTrap_SoundSet";
179  }
180 
181  override string GetLoopDeploySoundset()
182  {
183  return "fishtrap_deploy_SoundSet";
184  }
185 
186  override bool DoPlacingHeightCheck()
187  {
188  return true; //has to be able to catch rain, default distance raycast
189  }
190 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
IsDeployable
override bool IsDeployable()
Definition: trap_smallfish.c:171
GetLoopDeploySoundset
override string GetLoopDeploySoundset()
Definition: trap_smallfish.c:181
DoPlacingHeightCheck
override bool DoPlacingHeightCheck()
Definition: trap_smallfish.c:186
GetDeploySoundset
override string GetDeploySoundset()
Definition: trap_smallfish.c:176
IsPlaceableAtPosition
bool IsPlaceableAtPosition(vector position)
Definition: trapbase.c:207
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
OnVariablesSynchronized
override void OnVariablesSynchronized()
Definition: anniversarymusicsource.c:42
IsPlaceSound
bool IsPlaceSound()
Definition: itembase.c:4288
TrapSpawnBase
Definition: trap_fishnet.c:1
m_AnimationPhaseSet
string m_AnimationPhaseSet
Definition: trapbase.c:33
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
vector
Definition: enconvert.c:105
ECE_NONE
const int ECE_NONE
Definition: centraleconomy.c:7
InventoryLocationType
InventoryLocationType
types of Inventory Location
Definition: inventorylocation.c:3
RainProcurementManager
DEPRECATED, done through the RainProcurementHandler / component instead.
Definition: rainprocurementmanager.c:2
PlayPlaceSound
void PlayPlaceSound()
Definition: itembase.c:4348
SetIsPlaceSound
void SetIsPlaceSound(bool is_place_sound)
Definition: itembase.c:4283
m_RainProcurement
class Trap_SmallFish extends TrapSpawnBase m_RainProcurement
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
CanReceiveAttachment
override bool CanReceiveAttachment(EntityAI attachment, int slotId)
Definition: basebuildingbase.c:895
EntityAI
Definition: building.c:5
OnPlacementComplete
override void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
Definition: trap_smallfish.c:164