fishingrod_base.c 8.8 KB

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