Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actionfishingnew.c
Go to the documentation of this file.
2 {
3  const float FISHING_SUCCESS = 0.2;
4  const float FISHING_BAIT_LOSS = 0.02;
5  const float FISHING_HOOK_LOSS = 0.015;
6  const float FISHING_DAMAGE = 1.5;
7  const float FISHING_GARBAGE_CHANCE = 0.2;
8 
9  bool m_IsSurfaceSea;
10  bool m_IsBaitAnEmptyHook;
11  int m_FishingResult = -1;
12  float m_RodQualityModifier = 0;
13  ItemBase m_Bait;
14 
15  void InitBait(ItemBase item)
16  {
17  m_Bait = item;
18  m_IsBaitAnEmptyHook = !m_Bait.ConfigIsExisting("hookType");
19  }
20 
21  bool IsBaitEmptyHook()
22  {
23  return m_IsBaitAnEmptyHook;
24  }
25 }
26 
27 class ActionFishingNewCB : ActionContinuousBaseCB
28 {
31  "Wellies_Black",
32  "Wellies_Brown",
33  "Wellies_Green",
34  "Wellies_Grey",
35  "Pot"
36  };
37 
38  override void CreateActionComponent()
39  {
41  m_ActionData.m_ActionComponent = new CAContinuousRepeatFishing(3.0);
42  }
43 
44  override void EndActionComponent()
45  {
46  m_ActionDataFishing = FishingActionData.Cast(m_ActionData);
47 
49  {
50  super.EndActionComponent();
51  return;
52  }
53 
54  if (m_ActionDataFishing.m_State == UA_FINISHED)
55  {
56  if (m_ActionDataFishing.m_FishingResult == 1)
57  SetCommand(DayZPlayerConstants.CMD_ACTIONINT_END);
58  else if (m_ActionDataFishing.m_FishingResult == 0)
59  SetCommand(DayZPlayerConstants.CMD_ACTIONINT_FINISH);
60  }
61  else if (m_ActionDataFishing.m_State == UA_CANCEL)
62  {
64  if (action.HasAlternativeInterrupt())
65  {
66  SetCommand(DayZPlayerConstants.CMD_ACTIONINT_FINISH);
67  }
68  else
69  {
70  SetCommand(DayZPlayerConstants.CMD_ACTIONINT_END);
71  }
72 
73  m_Canceled = true;
74  return;
75  }
76  else
77  {
78  if (m_ActionDataFishing.m_FishingResult == 1)
79  SetCommand(DayZPlayerConstants.CMD_ACTIONINT_END);
80  else if (m_ActionDataFishing.m_FishingResult == 0)
81  SetCommand(DayZPlayerConstants.CMD_ACTIONINT_FINISH);
82  }
83 
85  }
86 
88  {
89  if (!GetGame().IsMultiplayer() || GetGame().IsServer())
90  {
91  ItemBase fish;
92 
93  if (!m_ActionDataFishing.m_Bait)
94  m_ActionDataFishing.InitBait(ItemBase.Cast(m_ActionDataFishing.m_MainItem.FindAttachmentBySlotName("Hook")));
95 
96  if (!m_ActionDataFishing.IsBaitEmptyHook())
97  {
98  m_ActionDataFishing.m_Bait.AddHealth(-m_ActionDataFishing.FISHING_DAMAGE);
99  MiscGameplayFunctions.TurnItemIntoItem(m_ActionDataFishing.m_Bait,m_ActionDataFishing.m_Bait.ConfigGetString("hookType"),m_ActionDataFishing.m_Player);
100  }
101  else
102  {
103  m_ActionDataFishing.m_Bait.AddHealth(-m_ActionDataFishing.FISHING_DAMAGE);
104  }
105 
106  float rnd = Math.RandomFloatInclusive(0.0, 1.0);
107  if (rnd > m_ActionDataFishing.FISHING_GARBAGE_CHANCE)
108  {
109  if (m_ActionDataFishing.m_IsSurfaceSea)
110  fish = ItemBase.Cast(GetGame().CreateObjectEx("Mackerel",m_ActionDataFishing.m_Player.GetPosition(), ECE_PLACE_ON_SURFACE));
111  else
112  fish = ItemBase.Cast(GetGame().CreateObjectEx("Carp",m_ActionDataFishing.m_Player.GetPosition(), ECE_PLACE_ON_SURFACE));
113  }
114  else
115  {
116  if ( !m_ActionDataFishing.m_IsSurfaceSea )
117  {
118  string junkType = m_JunkTypes.Get(Math.RandomInt(0, m_JunkTypes.Count()));
119  fish = ItemBase.Cast(GetGame().CreateObjectEx(junkType, m_ActionDataFishing.m_Player.GetPosition(), ECE_PLACE_ON_SURFACE));
120  fish.SetHealth("", "Health", fish.GetMaxHealth("", "Health") * 0.1);
121  }
122  }
123 
124  if (fish)
125  {
126  //Print("---Caught something: " + fish + "---");
127  fish.SetWet(0.3);
128  if (fish.HasQuantity())
129  {
130  float coef = Math.RandomFloatInclusive(0.5, 1.0);
131  float item_quantity = fish.GetQuantityMax() * coef;
132  item_quantity = Math.Round(item_quantity);
133  fish.SetQuantity( item_quantity );
134  fish.InsertAgent(eAgents.CHOLERA);
135  }
136  }
137 
138  m_ActionDataFishing.m_MainItem.AddHealth(-m_ActionDataFishing.FISHING_DAMAGE);
139  }
140  }
141 
143  {
144  if (!GetGame().IsMultiplayer() || GetGame().IsServer())
145  {
146  if (!m_ActionDataFishing.m_Bait)
147  m_ActionDataFishing.InitBait(ItemBase.Cast(m_ActionDataFishing.m_MainItem.FindAttachmentBySlotName("Hook")));
148 
149  if (Math.RandomFloatInclusive(0.0,1.0) > m_ActionDataFishing.FISHING_HOOK_LOSS) //loss of worm only
150  {
151  if (!m_ActionDataFishing.IsBaitEmptyHook())
152  {
153  m_ActionDataFishing.m_Bait.AddHealth(-m_ActionDataFishing.FISHING_DAMAGE);
154  MiscGameplayFunctions.TurnItemIntoItem(m_ActionDataFishing.m_Bait,m_ActionDataFishing.m_Bait.ConfigGetString("hookType"),m_ActionDataFishing.m_Player);
155  }
156  }
157  else //loss of the entire hook
158  {
159  m_ActionDataFishing.m_Bait.Delete();
160  }
161 
162  m_ActionDataFishing.m_MainItem.AddHealth(-m_ActionDataFishing.FISHING_DAMAGE);
163  }
164  }
165 
166  override void OnStateChange(int pOldState, int pCurrentState)
167  {
168  if (pCurrentState == STATE_NONE && m_ActionDataFishing)
169  {
170  if (m_ActionDataFishing.m_FishingResult == 1 && pOldState == STATE_LOOP_END)
171  {
173  }
174  else if (m_ActionDataFishing.m_FishingResult == 0 && pOldState == STATE_LOOP_END2)
175  {
177  }
178  }
179  }
180 };
181 
183 {
184  private const string ALLOWED_WATER_SURFACES = string.Format("%1|%2", UAWaterType.SEA, UAWaterType.FRESH);
185 
186  void ActionFishingNew()
187  {
188  m_CallbackClass = ActionFishingNewCB;
189  m_SpecialtyWeight = UASoftSkillsWeight.PRECISE_MEDIUM;
190  m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_FISHING;
191  m_FullBody = true;
192  m_StanceMask = DayZPlayerConstants.STANCEMASK_CROUCH;
193  m_Text = "#start_fishing";
194  }
195 
196  override void CreateConditionComponents()
197  {
200  }
201 
202  override bool HasTarget()
203  {
204  return true;
205  }
206 
207  override bool HasAlternativeInterrupt()
208  {
209  return true;
210  }
211 
212  override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item )
213  {
214  ItemBase bait;
215  FishingRod_Base_New rod = FishingRod_Base_New.Cast(item);
216 
217  if (rod)
218  bait = ItemBase.Cast(rod.FindAttachmentBySlotName("Hook"));
219 
220  if (bait && !bait.IsRuined())
221  return true;
222 
223  return false;
224  }
225 
226  override ActionData CreateActionData()
227  {
228  FishingActionData actionData = new FishingActionData();
229  return actionData;
230  }
231 
232  override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data = null)
233  {
234  if (super.SetupAction(player, target, item, action_data, extra_data))
235  {
236  vector cursorPosition = action_data.m_Target.GetCursorHitPos();
237  if (cursorPosition == vector.Zero)
238  cursorPosition = player.GetPosition();
239 
240  if (GetGame().SurfaceIsSea(cursorPosition[0], cursorPosition[2]))
241  {
242  FishingActionData.Cast(action_data).m_IsSurfaceSea = true;
243  }
244 
245  FishingRod_Base_New rod = FishingRod_Base_New.Cast(action_data.m_MainItem);
246  if (rod)
247  {
248  FishingActionData.Cast(action_data).m_RodQualityModifier = rod.GetFishingEffectivityBonus();
249  FishingActionData.Cast(action_data).InitBait(ItemBase.Cast(action_data.m_MainItem.FindAttachmentBySlotName("Hook")));
250  }
251  return true;
252  }
253  return false;
254  }
255 
256  override void OnFinishProgressServer( ActionData action_data )
257  {
258  action_data.m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_ACTION);
259  FishingActionData.Cast(action_data).m_FishingResult = EvaluateFishingResult(action_data);
260  }
261 
262  override void OnFinishProgressClient( ActionData action_data )
263  {
264  action_data.m_Callback.InternalCommand(DayZPlayerConstants.CMD_ACTIONINT_ACTION);
265  FishingActionData.Cast(action_data).m_FishingResult = EvaluateFishingResult(action_data);
266  }
267 
268  override void OnStartClient( ActionData action_data )
269  {
270  FishingRod_Base_New rod = FishingRod_Base_New.Cast(action_data.m_MainItem);
271  rod.AnimateFishingRod(true);
272  }
273  override void OnStartServer( ActionData action_data )
274  {
275  FishingRod_Base_New rod = FishingRod_Base_New.Cast(action_data.m_MainItem);
276  rod.AnimateFishingRod(true);
277  }
278 
279  override void OnEndClient( ActionData action_data )
280  {
281  FishingRod_Base_New rod = FishingRod_Base_New.Cast(action_data.m_MainItem);
282  rod.AnimateFishingRod(false);
283  }
284  override void OnEndServer( ActionData action_data )
285  {
286  FishingRod_Base_New rod = FishingRod_Base_New.Cast(action_data.m_MainItem);
287  rod.AnimateFishingRod(false);
288  }
289 
290  override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
291  {
292  super.WriteToContext(ctx, action_data);
293 
294  if (HasTarget())
295  {
296  ctx.Write(action_data.m_Target.GetCursorHitPos());
297  }
298  }
299 
300  override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
301  {
302  super.ReadFromContext(ctx, action_recive_data);
303 
304  if (HasTarget())
305  {
306  vector cursor_position;
307  if (!ctx.Read(cursor_position))
308  return false;
309 
310  action_recive_data.m_Target.SetCursorHitPos(cursor_position);
311  }
312  return true;
313  }
314 
315  int EvaluateFishingResult(ActionData action_data)
316  {
317  if (action_data.m_Player.IsQuickFishing())
318  return 1;
319 
320  FishingActionData fad = FishingActionData.Cast(action_data);
321  float rnd = fad.m_Player.GetRandomGeneratorSyncManager().GetRandom01(RandomGeneratorSyncUsage.RGSGeneric);
322  float daytimeModifier = 1;
323  float hookModifier = 1;
324  float chance;
325 
326  daytimeModifier = GetGame().GetDayTime();
327  if ((daytimeModifier > 18 && daytimeModifier < 22) || (daytimeModifier > 5 && daytimeModifier < 9))
328  {
329  daytimeModifier = 1;
330  }
331  else
332  {
333  daytimeModifier = 0.5;
334  }
335 
336  //fishing with an empty hook
337  if (fad.IsBaitEmptyHook())
338  {
339  hookModifier = 0.05;
340  }
341 
342  chance = 1 - (((fad.FISHING_SUCCESS * daytimeModifier) + fad.m_RodQualityModifier)) * hookModifier;
343 
344  if (rnd > chance)
345  {
346  return 1;
347  }
348  else if (rnd < fad.FISHING_BAIT_LOSS && !fad.IsBaitEmptyHook()) // restricts the loss of an empty hook (low chance is enough)
349  {
350  return 0;
351  }
352 
353  return -1;
354  }
355 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
m_ActionDataFishing
FishingActionData m_ActionDataFishing
Param
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition: param.c:11
CCTWaterSurface
Definition: cctwatersurface.c:1
HandleFishingResultFailure
void HandleFishingResultFailure()
Definition: actionfishingnew.c:142
UASoftSkillsWeight
Definition: actionconstants.c:118
EnableStateChangeCallback
proto native void EnableStateChangeCallback()
enables state change callback OnStateChange
EndActionComponent
override void EndActionComponent()
Definition: actionfishingnew.c:44
CAContinuousRepeatFishing
Definition: cacontinuousrepeatfishing.c:1
ECE_PLACE_ON_SURFACE
const int ECE_PLACE_ON_SURFACE
Definition: centraleconomy.c:37
CreateActionComponent
override void CreateActionComponent()
Definition: actionfishingnew.c:38
ActionFishingNew
Definition: actionfishingnew.c:182
UAWaterType
Definition: actionconstants.c:144
UAMaxDistances
Definition: actionconstants.c:104
UA_CANCEL
const int UA_CANCEL
Definition: constants.c:437
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
m_FullBody
protected bool m_FullBody
Definition: actionbase.c:52
RandomGeneratorSyncUsage
RandomGeneratorSyncUsage
Definition: randomgeneratorsyncmanager.c:1
m_Canceled
bool m_Canceled
Definition: smptanimmeta.c:16
PlayerBase
Definition: playerbaseclient.c:1
eAgents
eAgents
Definition: eagents.c:2
vector
Definition: enconvert.c:105
UA_FINISHED
const int UA_FINISHED
Definition: constants.c:436
FishingActionData
Definition: actionfishingnew.c:1
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
ActionContinuousBaseCB
Definition: actioncontinuousbase.c:1
array< string >
ALLOWED_WATER_SURFACES
const protected string ALLOWED_WATER_SURFACES
Definition: actiondrinkpondcontinuous.c:12
m_Text
protected string m_Text
Definition: actionbase.c:49
m_JunkTypes
ref array< string > m_JunkTypes
Definition: actionfishingnew.c:30
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
ActionContinuousBase
Definition: actioncontinuousbase.c:132
CCINonRuined
Definition: ccinonruined.c:1
HandleFishingResultSuccess
void HandleFishingResultSuccess()
Definition: actionfishingnew.c:87
FishingRod_Base_New
Definition: fishingrod_base.c:1
Math
Definition: enmath.c:6
m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition: actionbase.c:56
OnStateChange
override void OnStateChange(int pOldState, int pCurrentState)
Definition: actionfishingnew.c:166
m_SpecialtyWeight
protected float m_SpecialtyWeight
Definition: actionbase.c:68
m_StanceMask
protected int m_StanceMask
Definition: actionbase.c:53