catchingcontextfishingrodaction.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. class CatchingContextFishingRodAction : CatchingContextFishingBase
  2. {
  3. protected PlayerBase m_Player;
  4. //chances + modifiers
  5. protected float m_BaitLossChanceMod;
  6. protected float m_HookLossChanceMod;
  7. //times
  8. protected float m_SignalDurationMin; //seconds
  9. protected float m_SignalDurationMax; //seconds
  10. protected float m_SignalStartTimeMin; //seconds
  11. protected float m_SignalStartTimeMax; //seconds
  12. //important items
  13. protected EntityAI m_Hook;
  14. protected EntityAI m_Bait;
  15. protected EntityAI m_Rod;
  16. override protected void Init(Param par)
  17. {
  18. super.Init(par);
  19. m_Rod = m_MainItem; //only stable one, rest initialized on 'InitItemValues' periodically
  20. m_Player = PlayerBase.Cast(m_MainItem.GetHierarchyRootPlayer());
  21. m_SignalDurationMin = UAFishingConstants.SIGNAL_DURATION_MIN_BASE;
  22. m_SignalDurationMax = UAFishingConstants.SIGNAL_DURATION_MAX_BASE;
  23. m_SignalStartTimeMin = UAFishingConstants.SIGNAL_START_TIME_MIN_BASE;
  24. m_SignalStartTimeMax = UAFishingConstants.SIGNAL_START_TIME_MAX_BASE;
  25. }
  26. override protected void InitCatchMethodMask()
  27. {
  28. m_MethodMask = AnimalCatchingConstants.MASK_METHOD_ROD;
  29. }
  30. override protected void InitCatchEnviroMask()
  31. {
  32. if (m_IsSea)
  33. m_EnviroMask = AnimalCatchingConstants.MASK_ENVIRO_SEA;
  34. else
  35. m_EnviroMask = AnimalCatchingConstants.MASK_ENVIRO_POND;
  36. }
  37. override protected void CreateResultDataStructure()
  38. {
  39. m_Result = new CarchingResultFishingAction(m_MainItem);
  40. super.CreateResultDataStructure();
  41. }
  42. //! only clear stuff you need to update
  43. override protected void ClearCatchingItemData()
  44. {
  45. super.ClearCatchingItemData();
  46. m_SignalPoissonMean = UAFishingConstants.SIGNAL_CYCLE_MEAN_DEFAULT;
  47. m_HookLossChanceMod = 0.0;
  48. m_BaitLossChanceMod = 0.0;
  49. }
  50. override protected void InitItemValues(EntityAI item)
  51. {
  52. //skip ruined or deleted items entirely
  53. if (item.IsRuined() || item.IsSetForDeletion())
  54. return;
  55. string path = "" + CFG_VEHICLESPATH + " " + item.GetType() + " Fishing";
  56. if (GetGame().ConfigIsExisting(path))
  57. {
  58. if (GetGame().ConfigIsExisting(path + " signalCycleTarget"))
  59. m_SignalPoissonMean = Math.Min(m_SignalPoissonMean,GetGame().ConfigGetFloat(path + " signalCycleTarget"));
  60. if (GetGame().ConfigIsExisting(path + " resultQuantityBaseMod"))
  61. m_QualityBaseMod += GetGame().ConfigGetFloat(path + " resultQuantityBaseMod");
  62. if (GetGame().ConfigIsExisting(path + " resultQuantityDispersionMin"))
  63. m_QualityDispersionMinMod += GetGame().ConfigGetFloat(path + " resultQuantityDispersionMin");
  64. if (GetGame().ConfigIsExisting(path + " resultQuantityDispersionMax"))
  65. m_QualityDispersionMaxMod += GetGame().ConfigGetFloat(path + " resultQuantityDispersionMax");
  66. if (GetGame().ConfigIsExisting(path + " hookLossChanceMod"))
  67. m_HookLossChanceMod += GetGame().ConfigGetFloat(path + " hookLossChanceMod");
  68. if (GetGame().ConfigIsExisting(path + " baitLossChanceMod"))
  69. m_BaitLossChanceMod += GetGame().ConfigGetFloat(path + " baitLossChanceMod");
  70. int slotID;
  71. string slotName;
  72. if (item.GetInventory().GetCurrentAttachmentSlotInfo(slotID,slotName))
  73. {
  74. switch (slotName)
  75. {
  76. case "Bait":
  77. m_Bait = item;
  78. break;
  79. case "Hook":
  80. m_Hook = item;
  81. break;
  82. }
  83. }
  84. }
  85. }
  86. //! done locally on both sides, needs a synced random
  87. override void GenerateResult()
  88. {
  89. YieldItemBase yItem;
  90. int idx = m_Player.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAnimalCatching,0,m_ProbabilityArray.Count() - 1);
  91. Class.CastTo(yItem,m_YieldsMapAll.Get(m_ProbabilityArray[idx]));
  92. m_Result.SetYieldItem(yItem);
  93. }
  94. int GetResultParticleId()
  95. {
  96. if (m_Result)
  97. return m_Result.GetYieldItemParticleId();
  98. return ParticleList.INVALID;
  99. }
  100. override protected void RecalculateProcessingData()
  101. {
  102. m_Result.UpdateCatchChance(this);
  103. }
  104. float GetHookLossChanceModifierClamped()
  105. {
  106. return Math.Clamp(m_HookLossChanceMod,0.001,1);
  107. }
  108. float GetBaitLossChanceModifierClamped()
  109. {
  110. return Math.Clamp(m_BaitLossChanceMod,0,1);
  111. }
  112. float GetActionCycleTime()
  113. {
  114. return CarchingResultFishingAction.Cast(m_Result).GetCurrentCycleTime(this);
  115. }
  116. float RandomizeSignalDuration()
  117. {
  118. return m_Player.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAnimalCatching,m_SignalDurationMin,m_SignalDurationMax);
  119. }
  120. float RandomizeSignalStartTime()
  121. {
  122. return m_Player.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAnimalCatching,m_SignalStartTimeMin,m_SignalStartTimeMax);
  123. }
  124. override float GetChanceCoef()
  125. {
  126. return UAFishingConstants.SIGNAL_FISHING_CHANCE_COEF;
  127. }
  128. protected void TryHookLoss()
  129. {
  130. if (m_Hook && !m_Hook.IsSetForDeletion())
  131. {
  132. float lossChance = GetHookLossChanceModifierClamped();
  133. if (lossChance <= 0)
  134. return;
  135. float roll = m_Player.GetRandomGeneratorSyncManager().GetRandom01(RandomGeneratorSyncUsage.RGSAnimalCatching);
  136. if (lossChance >= 1 || roll < lossChance)
  137. {
  138. RemoveItemSafe(m_Hook);
  139. }
  140. }
  141. }
  142. protected void RemoveItemSafe(EntityAI item)
  143. {
  144. if (item && !m_Player.IsQuickFishing())
  145. {
  146. item.SetPrepareToDelete(); //should probably flag the bait too, but the action terminates anyway
  147. item.DeleteSafe();
  148. }
  149. }
  150. protected void TryBaitLoss()
  151. {
  152. if (m_Bait && !m_Bait.IsSetForDeletion())
  153. {
  154. float lossChance = GetBaitLossChanceModifierClamped();
  155. if (lossChance <= 0)
  156. return;
  157. float roll = m_Player.GetRandomGeneratorSyncManager().GetRandom01(RandomGeneratorSyncUsage.RGSAnimalCatching);
  158. if (lossChance >= 1 || roll < lossChance)
  159. {
  160. RemoveItemSafe(m_Bait);
  161. }
  162. }
  163. }
  164. protected void TryDamageItems()
  165. {
  166. if (!GetGame().IsMultiplayer() || GetGame().IsDedicatedServer())
  167. {
  168. if (m_Hook && !m_Hook.IsSetForDeletion())
  169. m_Hook.AddHealth("","Health",-UAFishingConstants.DAMAGE_HOOK);
  170. }
  171. }
  172. override EntityAI SpawnAndSetupCatch(out int yItemIdx, vector v = vector.Zero)
  173. {
  174. //hook check on catch
  175. if (m_Hook && !m_Hook.IsSetForDeletion())
  176. return super.SpawnAndSetupCatch(yItemIdx,v);
  177. return null;
  178. }
  179. //events
  180. void OnBeforeSpawnSignalHit()
  181. {
  182. TryHookLoss();
  183. }
  184. void OnAfterSpawnSignalHit()
  185. {
  186. RemoveItemSafe(m_Bait);
  187. TryDamageItems();
  188. UpdateCatchingItemData();
  189. }
  190. //! release without signal
  191. void OnSignalMiss()
  192. {
  193. TryHookLoss();
  194. TryBaitLoss();
  195. //RemoveItemSafe(m_Bait);
  196. //TryDamageItems();
  197. UpdateCatchingItemData();
  198. }
  199. void OnSignalPass()
  200. {
  201. //TryBaitLoss();
  202. RemoveItemSafe(m_Bait);
  203. TryDamageItems();
  204. UpdateCatchingItemData();
  205. }
  206. }