Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
fishingrod_base.c
Go to the documentation of this file.
2 {
4  {
5  }
6 
7  override void SetActions()
8  {
9  super.SetActions();
10 
12  }
13 
14  float GetFishingEffectivityBonus()
15  {
16  return 0.0;
17  }
18 
19  override bool IsOpen()
20  {
21  return false;
22  }
23 
24  void AnimateFishingRod(bool state) {}
25 
26  override void OnDebugSpawn()
27  {
28  GetInventory().CreateAttachment("Bait");
29  for (int i = 0; i < 6; ++i)
30  {
31  GetGame().CreateObjectEx("Bait", GetPosition(), ECE_PLACE_ON_SURFACE);
32  }
33  }
34 }
35 
37 {
38  const string ANIM_PHASE_OPENED = "OpenRod";
39  const string ANIM_PHASE_CLOSED = "CloseRod";
40 
41  const float BREAK_PULL = 36;
42  const float TOO_MUCH_PULL = 32;
43  const float HIGH_PULL = 22;
44  const float LOW_PULL = 18;
45  const float TOO_FEW_PULL = 8;
46  const float LOOSE_PULL = 0;
47  const int LOSS_BREAK = 0;
48  const int LOSS_LOOSE = 1;
49  const int WIN = 2;
50  const int INTERUPTED = 3;
51  const float INIT_LINE_STRETCH = 15;
52  const float MIN_FISHING_TIME = 100;
53  const float MAX_FISHING_TIME = 150;
54  const int FISH_PULL_CHANCE = 15;
55  const int FISH_AGILITY = 15;
56 
58  bool m_Fishing;
61  float m_Pull;
62  float m_DeltaT;
65  float m_PullTime;
66  float m_FishPull;
70 
72  {
73  m_Fishing = false;
74  }
75 
76  void Init()
77  {
78  m_Player = PlayerBase.Cast( GetGame().GetPlayer() );
80  m_IsFishPulling = false;
81  //TIMERDEPRECATED - randomized time of fishing
85  //TIMERDEPRECATED
86  if(!m_Cycler)
87  {
88  m_Cycler = new Timer();
89  }
90  if(!m_CyclerCatching)
91  {
92  m_CyclerCatching = new Timer();
93  }
94  m_CyclerCatching.Run(4, this, "Catching", NULL,true);
95  m_Player.Message("I have started fishing.", "colorFriendly");
96  }
97 
99  {
100  return m_Fishing;
101  }
102 
104  {
105  m_Fishing = true;
106  //Init();
107  }
108 
110  {
111  End(INTERUPTED);
112  }
113 
114 
115 
116  void FishPull()
117  {
118  if ( !m_IsFishPulling )
119  {
120  float rand = Math.RandomInt(1, FISH_PULL_CHANCE);
121  if ( rand <= 2 && m_Pull <= TOO_MUCH_PULL && m_Pull >= TOO_FEW_PULL )
122  {
123  //TIMERDEPRECATED - randomizing timeframe to pull fish out
124  if ( Math.RandomInt(0, 1) )
125  {
126  m_FishPull = rand;
127  }
128  else
129  {
130  m_FishPull = -rand;
131  }
132  //TIMERDEPRECATED - randomizing timeframe to pull fish out
133  m_PullTime = Math.RandomInt(2, 6);
134  m_IsFishPulling = true;
135  }
136  }
137  else
138  {
139  m_PullTime--;
140  if (m_PullTime == 0)
141  {
142  m_IsFishPulling = false;
143  }
144  }
145  }
146 
147  void Catching()
148  {
149  if(m_FishProximity == 0 && m_WasPulled)
150  {
151  m_CyclerCatching.Stop();
152  m_Cycler.Run(0.3, this, "Pulling", NULL,true);
153  }
154  else
155  {
156  if (m_WasPulled)
157  {
158  m_WasPulled = false;
159  m_ChanceRange++;
160  }
161  //TIMERDEPRECATED - randomized proximity of fish to
162  m_FishProximity = Math.RandomInt(0,m_ChanceRange);
163  string fline = "";
164  for (int i = 0; i < m_FishProximity; i++)
165  {
166  fline += " .";
167  }
168  m_Player.Message("", "colorStatusChannel");
169  m_Player.Message("HOLD right mouse button to pull the fishing line", "colorAction");
170  m_Player.Message("", "colorStatusChannel");
171  m_Player.Message("", "colorStatusChannel");
172  m_Player.Message("", "colorStatusChannel");
173  m_Player.Message("Start pulling when J and <*)))>< meet:", "colorStatusChannel");
174  m_Player.Message("", "colorStatusChannel");
175  m_Player.Message("J"+fline+" <*)))><", "colorImportant");
176  if(m_ChanceRange > 0)
177  {
178  m_ChanceRange--;
179  }
180  }
181  }
182 
183  void Pulling()
184  {
185  float agent_speed_distance = vector.Distance("0 0 0",m_Player.GetModelSpeed());
186  if (m_Player.GetItemInHands() != this || !m_Player.IsInWater() || agent_speed_distance > 1 )
187  {
188  End(INTERUPTED);
189  }
190  else
191  {
192  if ( m_FishingTime <= 0)
193  {
194  ItemBase pcatch = ItemBase.Cast( m_Player.GetInventory().CreateInInventory("Carp") );
195  //ItemBase pcatch = ItemBase.Cast( m_Player.CreateInInventory("Carp","cargo_bait") );
196  pcatch.SetQuantity(800,false);
197  End(WIN);
198  }
199  else
200  {
201  FishPull();
202  if ( m_IsFishPulling )
203  {
204  m_Pull += m_FishPull;
205  }
206  if (m_WasPulled)
207  {
208  m_Pull += 1;
209  }
210  else
211  {
212  m_Pull -= 1;
213  }
214  m_WasPulled = false;
215  m_FishingTime--;
216  DisplayState();
217  if ( m_Pull <= LOOSE_PULL)
218  {
219  End(LOSS_LOOSE);
220  }
221  if ( m_Pull >= BREAK_PULL)
222  {
223  End(LOSS_BREAK);
224  }
225  }
226  }
227  }
228 
229  void End( int result )
230  {
231  m_Cycler.Stop();
232  m_CyclerCatching.Stop();
233  m_Fishing = false;
234 
235  switch (result)
236  {
237  case LOSS_BREAK:
238  m_Player.Message("", "colorStatusChannel");
239  m_Player.Message("", "colorStatusChannel");
240  m_Player.Message("", "colorStatusChannel");
241  m_Player.Message("The fish had broken the fishing line and swam away.", "colorImportant");
242  m_Player.Message("", "colorStatusChannel");
243  m_Player.Message("", "colorStatusChannel");
244  m_Player.Message("", "colorStatusChannel");
245  m_Player.Message("", "colorStatusChannel");
246  break;
247 
248  case LOSS_LOOSE:
249  m_Player.Message("", "colorStatusChannel");
250  m_Player.Message("", "colorStatusChannel");
251  m_Player.Message("", "colorStatusChannel");
252  m_Player.Message("The fish escaped.", "colorImportant");
253  m_Player.Message("", "colorStatusChannel");
254  m_Player.Message("", "colorStatusChannel");
255  m_Player.Message("", "colorStatusChannel");
256  m_Player.Message("", "colorStatusChannel");
257  break;
258 
259  case WIN:
260  m_Player.Message("", "colorStatusChannel");
261  m_Player.Message("", "colorStatusChannel");
262  m_Player.Message("", "colorStatusChannel");
263  m_Player.Message("I caught the fish!", "colorFriendly");
264  m_Player.Message("", "colorStatusChannel");
265  m_Player.Message("", "colorStatusChannel");
266  m_Player.Message("", "colorStatusChannel");
267  m_Player.Message("", "colorStatusChannel");
268  break;
269 
270  case INTERUPTED:
271  m_Player.Message("", "colorStatusChannel");
272  m_Player.Message("", "colorStatusChannel");
273  m_Player.Message("", "colorStatusChannel");
274  m_Player.Message("Fishing time is over.", "colorFriendly");
275  m_Player.Message("", "colorStatusChannel");
276  m_Player.Message("", "colorStatusChannel");
277  m_Player.Message("", "colorStatusChannel");
278  m_Player.Message("", "colorStatusChannel");
279  break;
280 
281  default:
282  Print("Wrong number");
283  break;
284  }
285  }
286 
287  void AddPull(float delta)
288  {
289  m_DeltaT = delta;
290  m_WasPulled = true;
291  }
292 
294  {
295  string fline = "";
296  for (int i = 0; i < m_Pull; i++)
297  {
298  fline += "-";
299  }
300  m_Player.Message("", "colorStatusChannel");
301  m_Player.Message("HOLD right mouse button to pull the fishing line", "colorAction");
302  m_Player.Message("RELEASE right mouse button to loosen the fishing line", "colorAction");
303  m_Player.Message("", "colorStatusChannel");
304  m_Player.Message("", "colorStatusChannel");
305  m_Player.Message("Fishing line stretch :", "colorStatusChannel");
306  m_Player.Message("", "colorStatusChannel");
307  if (m_Pull >= TOO_MUCH_PULL)
308  {
309  m_Player.Message("<"+fline+">", "colorImportant");
310  }
311  if ( m_Pull >= HIGH_PULL && m_Pull < TOO_MUCH_PULL)
312  {
313  m_Player.Message("<"+fline+">", "colorAction");
314  }
315  if ( m_Pull < HIGH_PULL && m_Pull > LOW_PULL)
316  {
317  m_Player.Message("<"+fline+">", "colorFriendly");
318  }
319  if ( m_Pull <= LOW_PULL && m_Pull > TOO_FEW_PULL)
320  {
321  m_Player.Message("<"+fline+">", "colorStatusChannel");
322  }
323  if (m_Pull <= TOO_FEW_PULL)
324  {
325  m_Player.Message("<"+fline+">", "colorImportant");
326  }
327  }
328 
329  // Conditions
330  override bool CanPutInCargo( EntityAI parent )
331  {
332  if( !super.CanPutInCargo(parent) ) {return false;}
333  if ( GetAnimationPhase(ANIM_PHASE_CLOSED) > 0.5 )
334  {
335  return true;
336  }
337  return false;
338  }
339 
340  override void SetActions()
341  {
342  super.SetActions();
343 
344  //AddAction(ActionToggleFishing);
345  //AddAction(ActionFishing);
346  //AddAction(ActionFishingNew);
347  }
348 
350  {
351  return 0.0;
352  }
353 }
ItemBase
Definition: inventoryitem.c:730
SetActions
override void SetActions()
Definition: fishingrod_base.c:340
GetGame
proto native CGame GetGame()
MIN_FISHING_TIME
const float MIN_FISHING_TIME
Definition: fishingrod_base.c:52
m_FishingTime
int m_FishingTime
Definition: fishingrod_base.c:67
LOOSE_PULL
const float LOOSE_PULL
Definition: fishingrod_base.c:46
m_WasPulled
bool m_WasPulled
Definition: fishingrod_base.c:63
WIN
const int WIN
Definition: fishingrod_base.c:49
m_Player
PlayerBase m_Player
Definition: fishingrod_base.c:68
HIGH_PULL
const float HIGH_PULL
Definition: fishingrod_base.c:43
Print
proto void Print(void var)
Prints content of variable to console/log.
TOO_FEW_PULL
const float TOO_FEW_PULL
Definition: fishingrod_base.c:45
ECE_PLACE_ON_SURFACE
const int ECE_PLACE_ON_SURFACE
Definition: centraleconomy.c:37
ActionFishingNew
Definition: actionfishingnew.c:182
m_Fishing
bool m_Fishing
Definition: fishingrod_base.c:58
AddPull
void AddPull(float delta)
Definition: fishingrod_base.c:287
FishPull
void FishPull()
Definition: fishingrod_base.c:116
FISH_PULL_CHANCE
const int FISH_PULL_CHANCE
Definition: fishingrod_base.c:54
INTERUPTED
const int INTERUPTED
Definition: fishingrod_base.c:50
LOSS_LOOSE
const int LOSS_LOOSE
Definition: fishingrod_base.c:48
INIT_LINE_STRETCH
const float INIT_LINE_STRETCH
Definition: fishingrod_base.c:51
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
IsFishingActive
bool IsFishingActive()
Definition: fishingrod_base.c:98
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
BREAK_PULL
const float BREAK_PULL
Definition: fishingrod_base.c:41
m_IsFishPulling
bool m_IsFishPulling
Definition: fishingrod_base.c:64
m_DeltaT
float m_DeltaT
Definition: fishingrod_base.c:62
MAX_FISHING_TIME
const float MAX_FISHING_TIME
Definition: fishingrod_base.c:53
ANIM_PHASE_OPENED
FishingRod_Base_New ANIM_PHASE_OPENED
m_ChanceRange
int m_ChanceRange
Definition: fishingrod_base.c:69
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
FishingRod_Base
void FishingRod_Base()
Definition: fishingrod_base.c:71
Catching
void Catching()
Definition: fishingrod_base.c:147
CanPutInCargo
override bool CanPutInCargo(EntityAI parent)
Definition: fishingrod_base.c:330
m_Cycler
ref Timer m_Cycler
Definition: fishingrod_base.c:60
ANIM_PHASE_CLOSED
const string ANIM_PHASE_CLOSED
Definition: fishingrod_base.c:39
ActivateFishing
void ActivateFishing()
Definition: fishingrod_base.c:103
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
Pulling
void Pulling()
Definition: fishingrod_base.c:183
m_Pull
float m_Pull
Definition: fishingrod_base.c:61
End
void End(int result)
Definition: fishingrod_base.c:229
LOSS_BREAK
const int LOSS_BREAK
Definition: fishingrod_base.c:47
m_FishPull
float m_FishPull
Definition: fishingrod_base.c:66
GetFishingEffectivityBonus
float GetFishingEffectivityBonus()
Definition: fishingrod_base.c:349
Timer
Definition: dayzplayerimplement.c:62
DeactivateFishing
void DeactivateFishing()
Definition: fishingrod_base.c:109
m_PullTime
float m_PullTime
Definition: fishingrod_base.c:65
m_CyclerCatching
ref Timer m_CyclerCatching
Definition: fishingrod_base.c:59
Init
void Init()
Launched from 'DayZGame.DeferredInit' to make earlier access, use, and updates impossible (downside o...
Definition: fishingrod_base.c:76
FishingRod_Base_New
Definition: fishingrod_base.c:1
Math
Definition: enmath.c:6
TOO_MUCH_PULL
const float TOO_MUCH_PULL
Definition: fishingrod_base.c:42
DisplayState
void DisplayState()
Definition: fishingrod_base.c:293
EntityAI
Definition: building.c:5
m_FishProximity
int m_FishProximity
Definition: fishingrod_base.c:57
LOW_PULL
const float LOW_PULL
Definition: fishingrod_base.c:44
FISH_AGILITY
const int FISH_AGILITY
Definition: fishingrod_base.c:55