edible_base.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972
  1. class Edible_Base : ItemBase
  2. {
  3. const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
  4. const string SOUND_BAKING_START = "Baking_SoundSet";
  5. const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
  6. const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
  7. protected bool m_MakeCookingSounds;
  8. protected SoundOnVehicle m_SoundCooking; //! DEPRECATED
  9. protected EffectSound m_SoundEffectCooking;
  10. protected string m_SoundPlaying;
  11. ref FoodStage m_FoodStage;
  12. protected float m_DecayTimer;
  13. protected float m_DecayDelta = 0.0;
  14. protected FoodStageType m_LastDecayStage = FoodStageType.NONE;
  15. protected ParticleSource m_HotVaporParticle;
  16. private CookingMethodType m_CookedByMethod;
  17. void Edible_Base()
  18. {
  19. if (HasFoodStage())
  20. {
  21. m_FoodStage = new FoodStage(this);
  22. RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
  23. RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
  24. m_SoundPlaying = "";
  25. m_CookedByMethod = CookingMethodType.NONE;
  26. RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
  27. RegisterNetSyncVariableBool("m_MakeCookingSounds");
  28. }
  29. }
  30. override void EEInit()
  31. {
  32. super.EEInit();
  33. UpdateVisualsEx(true); //forced init visuals, mostly for debugs and SP
  34. }
  35. override void EEDelete(EntityAI parent)
  36. {
  37. super.EEDelete(parent);
  38. RemoveAudio();
  39. if (m_HotVaporParticle)
  40. m_HotVaporParticle.Stop();
  41. }
  42. override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
  43. {
  44. super.EEItemLocationChanged(oldLoc, newLoc);
  45. //! disable sounds (from cooking)
  46. if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
  47. {
  48. switch (oldLoc.GetParent().GetType())
  49. {
  50. case "FryingPan":
  51. case "Pot":
  52. case "Cauldron":
  53. case "SharpWoodenStick":
  54. MakeSoundsOnClient(false);
  55. break;
  56. }
  57. //! check for DirectCooking slot name
  58. if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
  59. {
  60. MakeSoundsOnClient(false);
  61. }
  62. }
  63. if (oldLoc.IsValid())
  64. ResetCookingTime();
  65. if (CanHaveTemperature())
  66. UpdateVaporParticle();
  67. }
  68. void UpdateVisualsEx(bool forced = false)
  69. {
  70. if (GetFoodStage())
  71. GetFoodStage().UpdateVisualsEx(forced);
  72. }
  73. bool Consume(float amount, PlayerBase consumer)
  74. {
  75. AddQuantity(-amount, false, false);
  76. OnConsume(amount, consumer);
  77. return true;
  78. }
  79. void OnConsume(float amount, PlayerBase consumer)
  80. {
  81. if (GetTemperature() > PlayerConstants.CONSUMPTION_DAMAGE_TEMP_THRESHOLD)
  82. {
  83. consumer.ProcessDirectDamage(DamageType.CUSTOM, this, "", "EnviroDmg", "0 0 0", PlayerConstants.CONSUMPTION_DAMAGE_PER_BITE);
  84. }
  85. }
  86. //! Filter agents from the item (override on higher implements)
  87. int FilterAgents(int agentsIn)
  88. {
  89. return agentsIn;
  90. }
  91. //food staging
  92. override bool CanBeCooked()
  93. {
  94. return false;
  95. }
  96. override bool CanBeCookedOnStick()
  97. {
  98. return false;
  99. }
  100. override float GetTemperatureFreezeTime()
  101. {
  102. if (GetFoodStage())
  103. {
  104. switch (m_FoodStage.GetFoodStageType())
  105. {
  106. case FoodStageType.DRIED:
  107. return super.GetTemperatureFreezeTime() * GameConstants.TEMPERATURE_FREEZE_TIME_COEF_DRIED;
  108. case FoodStageType.BURNED:
  109. return super.GetTemperatureFreezeTime() * GameConstants.TEMPERATURE_FREEZE_TIME_COEF_BURNED;
  110. default:
  111. return super.GetTemperatureFreezeTime();
  112. }
  113. }
  114. return super.GetTemperatureFreezeTime();
  115. }
  116. override float GetTemperatureThawTime()
  117. {
  118. if (GetFoodStage())
  119. {
  120. switch (m_FoodStage.GetFoodStageType())
  121. {
  122. case FoodStageType.DRIED:
  123. return super.GetTemperatureThawTime() * GameConstants.TEMPERATURE_THAW_TIME_COEF_DRIED;
  124. case FoodStageType.BURNED:
  125. return super.GetTemperatureThawTime() * GameConstants.TEMPERATURE_THAW_TIME_COEF_BURNED;
  126. default:
  127. return super.GetTemperatureThawTime();
  128. }
  129. }
  130. return super.GetTemperatureThawTime();
  131. }
  132. override bool CanItemOverheat()
  133. {
  134. return super.CanItemOverheat() && (!GetFoodStage() || (IsFoodBurned() || !GetFoodStage().CanTransitionToFoodStageType(FoodStageType.BURNED))); //for foodstaged items - either is burned, or it can't get burned
  135. }
  136. //================================================================
  137. // SYNCHRONIZATION
  138. //================================================================
  139. void Synchronize()
  140. {
  141. SetSynchDirty();
  142. }
  143. override void OnVariablesSynchronized()
  144. {
  145. super.OnVariablesSynchronized();
  146. //UpdateVisualsEx(); //performed on client only
  147. //update audio
  148. if (m_MakeCookingSounds)
  149. {
  150. RefreshAudio();
  151. }
  152. else
  153. {
  154. RemoveAudio();
  155. }
  156. if (CanHaveTemperature())
  157. UpdateVaporParticle();
  158. }
  159. //================================================================
  160. // AUDIO EFFECTS (WHEN ON DCS)
  161. //================================================================
  162. void MakeSoundsOnClient(bool soundstate, CookingMethodType cookingMethod = CookingMethodType.NONE)
  163. {
  164. m_MakeCookingSounds = soundstate;
  165. m_CookedByMethod = cookingMethod;
  166. Synchronize();
  167. }
  168. protected void RefreshAudio()
  169. {
  170. string soundName = "";
  171. FoodStageType nextFoodState = GetNextFoodStageType(m_CookedByMethod);
  172. switch (GetFoodStageType())
  173. {
  174. case FoodStageType.RAW:
  175. soundName = SOUND_BAKING_START;
  176. if (nextFoodState == FoodStageType.BOILED)
  177. soundName = "";
  178. break;
  179. case FoodStageType.BAKED:
  180. soundName = SOUND_BAKING_DONE;
  181. break;
  182. case FoodStageType.BURNED:
  183. soundName = SOUND_BURNING_DONE;
  184. break;
  185. default:
  186. soundName = "";
  187. break;
  188. }
  189. SoundCookingStart(soundName);
  190. }
  191. protected void RemoveAudio()
  192. {
  193. m_MakeCookingSounds = false;
  194. SoundCookingStop();
  195. }
  196. //================================================================
  197. // SERIALIZATION
  198. //================================================================
  199. override void OnStoreSave(ParamsWriteContext ctx)
  200. {
  201. super.OnStoreSave(ctx);
  202. if (GetFoodStage())
  203. {
  204. GetFoodStage().OnStoreSave(ctx);
  205. }
  206. // food decay
  207. ctx.Write(m_DecayTimer);
  208. ctx.Write(m_LastDecayStage);
  209. }
  210. override bool OnStoreLoad(ParamsReadContext ctx, int version)
  211. {
  212. if (!super.OnStoreLoad(ctx, version))
  213. return false;
  214. if (GetFoodStage())
  215. {
  216. if (!GetFoodStage().OnStoreLoad(ctx, version))
  217. return false;
  218. }
  219. if (version >= 115)
  220. {
  221. if (!ctx.Read(m_DecayTimer))
  222. {
  223. m_DecayTimer = 0.0;
  224. return false;
  225. }
  226. if (!ctx.Read(m_LastDecayStage))
  227. {
  228. m_LastDecayStage = FoodStageType.NONE;
  229. return false;
  230. }
  231. }
  232. UpdateVisualsEx(true); //forced init visuals
  233. Synchronize();
  234. return true;
  235. }
  236. override void AfterStoreLoad()
  237. {
  238. super.AfterStoreLoad();
  239. Synchronize();
  240. }
  241. //get food stage
  242. override FoodStage GetFoodStage()
  243. {
  244. return m_FoodStage;
  245. }
  246. //food types
  247. override bool IsMeat()
  248. {
  249. return false;
  250. }
  251. override bool IsCorpse()
  252. {
  253. return false;
  254. }
  255. override bool IsFruit()
  256. {
  257. return false;
  258. }
  259. override bool IsMushroom()
  260. {
  261. return false;
  262. }
  263. //================================================================
  264. // NUTRITIONAL VALUES
  265. //================================================================
  266. //food properties
  267. static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
  268. {
  269. Edible_Base food_item = Edible_Base.Cast(item);
  270. if (food_item && food_item.GetFoodStage())
  271. {
  272. return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
  273. }
  274. else if (classname != "" && food_stage)
  275. {
  276. return FoodStage.GetFullnessIndex(null, food_stage, classname);
  277. }
  278. string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
  279. return GetGame().ConfigGetFloat( class_path + " fullnessIndex" );
  280. }
  281. static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
  282. {
  283. Edible_Base food_item = Edible_Base.Cast(item);
  284. if (food_item && food_item.GetFoodStage())
  285. {
  286. return FoodStage.GetEnergy(food_item.GetFoodStage());
  287. }
  288. else if (classname != "" && food_stage)
  289. {
  290. return FoodStage.GetEnergy(null, food_stage, classname);
  291. }
  292. string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
  293. return GetGame().ConfigGetFloat( class_path + " energy" );
  294. }
  295. static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
  296. {
  297. Edible_Base food_item = Edible_Base.Cast(item);
  298. if (food_item && food_item.GetFoodStage())
  299. {
  300. return FoodStage.GetWater(food_item.GetFoodStage());
  301. }
  302. else if (classname != "" && food_stage)
  303. {
  304. return FoodStage.GetWater(null, food_stage, classname);
  305. }
  306. string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
  307. return GetGame().ConfigGetFloat( class_path + " water" );
  308. }
  309. static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
  310. {
  311. Edible_Base food_item = Edible_Base.Cast(item);
  312. if (food_item && food_item.GetFoodStage())
  313. {
  314. return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
  315. }
  316. else if (classname != "" && food_stage)
  317. {
  318. return FoodStage.GetNutritionalIndex(null, food_stage, classname);
  319. }
  320. string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
  321. return GetGame().ConfigGetFloat( class_path + " nutritionalIndex" );
  322. }
  323. static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
  324. {
  325. Edible_Base food_item = Edible_Base.Cast(item);
  326. if (food_item && food_item.GetFoodStage())
  327. {
  328. return FoodStage.GetToxicity(food_item.GetFoodStage());
  329. }
  330. else if (classname != "" && food_stage)
  331. {
  332. return FoodStage.GetToxicity(null, food_stage, classname);
  333. }
  334. string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
  335. return GetGame().ConfigGetFloat( class_path + " toxicity" );
  336. }
  337. static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
  338. {
  339. Edible_Base food_item = Edible_Base.Cast(item);
  340. if (food_item && food_item.GetFoodStage())
  341. {
  342. return FoodStage.GetAgents(food_item.GetFoodStage());
  343. }
  344. else if (classname != "" && food_stage)
  345. {
  346. return FoodStage.GetAgents(null, food_stage, classname);
  347. }
  348. string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
  349. return GetGame().ConfigGetInt( class_path + " agents" );
  350. }
  351. static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
  352. {
  353. Edible_Base food_item = Edible_Base.Cast(item);
  354. if (food_item && food_item.GetFoodStage())
  355. {
  356. return FoodStage.GetDigestibility(food_item.GetFoodStage());
  357. }
  358. else if (classname != "" && food_stage)
  359. {
  360. return FoodStage.GetDigestibility(null, food_stage, classname);
  361. }
  362. string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
  363. return GetGame().ConfigGetInt( class_path + " digestibility" );
  364. }
  365. static NutritionalProfile GetNutritionalProfile(ItemBase item, string classname = "", int food_stage = 0)
  366. {
  367. return new NutritionalProfile(GetFoodEnergy(item, classname, food_stage),GetFoodWater(item, classname, food_stage),GetFoodNutritionalIndex(item, classname, food_stage),GetFoodTotalVolume(item, classname, food_stage), GetFoodToxicity(item, classname, food_stage), GetFoodAgents(item, classname,food_stage), GetFoodDigestibility(item, classname,food_stage));
  368. }
  369. //================================================================
  370. // FOOD STAGING
  371. //================================================================
  372. FoodStageType GetFoodStageType()
  373. {
  374. return GetFoodStage().GetFoodStageType();
  375. }
  376. //food stage states
  377. bool IsFoodRaw()
  378. {
  379. if ( GetFoodStage() )
  380. {
  381. return GetFoodStage().IsFoodRaw();
  382. }
  383. return false;
  384. }
  385. bool IsFoodBaked()
  386. {
  387. if ( GetFoodStage() )
  388. {
  389. return GetFoodStage().IsFoodBaked();
  390. }
  391. return false;
  392. }
  393. bool IsFoodBoiled()
  394. {
  395. if ( GetFoodStage() )
  396. {
  397. return GetFoodStage().IsFoodBoiled();
  398. }
  399. return false;
  400. }
  401. bool IsFoodDried()
  402. {
  403. if ( GetFoodStage() )
  404. {
  405. return GetFoodStage().IsFoodDried();
  406. }
  407. return false;
  408. }
  409. bool IsFoodBurned()
  410. {
  411. if ( GetFoodStage() )
  412. {
  413. return GetFoodStage().IsFoodBurned();
  414. }
  415. return false;
  416. }
  417. bool IsFoodRotten()
  418. {
  419. if ( GetFoodStage() )
  420. {
  421. return GetFoodStage().IsFoodRotten();
  422. }
  423. return false;
  424. }
  425. //food stage change
  426. void ChangeFoodStage( FoodStageType new_food_stage_type )
  427. {
  428. GetFoodStage().ChangeFoodStage( new_food_stage_type );
  429. }
  430. FoodStageType GetNextFoodStageType( CookingMethodType cooking_method )
  431. {
  432. return GetFoodStage().GetNextFoodStageType( cooking_method );
  433. }
  434. string GetFoodStageName( FoodStageType food_stage_type )
  435. {
  436. return GetFoodStage().GetFoodStageName( food_stage_type );
  437. }
  438. bool CanChangeToNewStage( CookingMethodType cooking_method )
  439. {
  440. return GetFoodStage().CanChangeToNewStage( cooking_method );
  441. }
  442. //Use this to receive food stage from another Edible_Base
  443. void TransferFoodStage( notnull Edible_Base source )
  444. {
  445. if ( !source.GetFoodStage())
  446. return;
  447. m_LastDecayStage = source.GetLastDecayStage();
  448. ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
  449. m_DecayTimer = source.GetDecayTimer();
  450. m_DecayDelta = source.GetDecayDelta();
  451. }
  452. //! called on server
  453. void OnFoodStageChange(FoodStageType stageOld, FoodStageType stageNew)
  454. {
  455. HandleFoodStageChangeAgents(stageOld,stageNew);
  456. UpdateVisualsEx(); //performed on server only
  457. }
  458. //! removes select agents on foodstage transitions
  459. void HandleFoodStageChangeAgents(FoodStageType stageOld, FoodStageType stageNew)
  460. {
  461. switch (stageNew)
  462. {
  463. case FoodStageType.BAKED:
  464. case FoodStageType.BOILED:
  465. case FoodStageType.DRIED:
  466. RemoveAllAgentsExcept(eAgents.BRAIN|eAgents.HEAVYMETAL);
  467. break;
  468. case FoodStageType.BURNED:
  469. RemoveAllAgentsExcept(eAgents.HEAVYMETAL);
  470. break;
  471. }
  472. }
  473. //================================================================
  474. // COOKING
  475. //================================================================
  476. //cooking time
  477. float GetCookingTime()
  478. {
  479. return GetFoodStage().GetCookingTime();
  480. }
  481. void SetCookingTime( float time )
  482. {
  483. GetFoodStage().SetCookingTime( time );
  484. //synchronize when calling on server
  485. Synchronize();
  486. }
  487. void ResetCookingTime()
  488. {
  489. if (GetFoodStage())
  490. {
  491. GetFoodStage().SetCookingTime(0);
  492. Synchronize();
  493. }
  494. }
  495. //replace edible with new item (opening cans)
  496. void ReplaceEdibleWithNew( string typeName )
  497. {
  498. PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
  499. if (player)
  500. {
  501. ReplaceEdibleWithNewLambda lambda = new ReplaceEdibleWithNewLambda(this, typeName, player);
  502. player.ServerReplaceItemInHandsWithNew(lambda);
  503. }
  504. else
  505. Error("ReplaceEdibleWithNew - cannot use edible without player");
  506. }
  507. override void SetActions()
  508. {
  509. super.SetActions();
  510. AddAction(ActionAttach);
  511. AddAction(ActionDetach);
  512. }
  513. protected void SoundCookingStart(string sound_name)
  514. {
  515. #ifndef SERVER
  516. if (m_SoundPlaying != sound_name)
  517. {
  518. SoundCookingStop();
  519. m_SoundEffectCooking = SEffectManager.PlaySound(sound_name, GetPosition(), 0, 0, true);
  520. m_SoundPlaying = sound_name;
  521. }
  522. #endif
  523. }
  524. protected void SoundCookingStop()
  525. {
  526. #ifndef SERVER
  527. if (m_SoundEffectCooking)
  528. {
  529. m_SoundEffectCooking.Stop();
  530. m_SoundEffectCooking = null;
  531. m_SoundPlaying = "";
  532. }
  533. #endif
  534. }
  535. override bool CanDecay()
  536. {
  537. return false;
  538. }
  539. override bool CanProcessDecay()
  540. {
  541. return !GetIsFrozen() && ( GetFoodStageType() != FoodStageType.ROTTEN );
  542. }
  543. override void ProcessDecay( float delta, bool hasRootAsPlayer )
  544. {
  545. m_DecayDelta = 0.0;
  546. delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
  547. m_DecayDelta += ( 1 + ( 1 - GetHealth01( "", "" ) ) );
  548. if ( hasRootAsPlayer )
  549. m_DecayDelta += GameConstants.DECAY_RATE_ON_PLAYER;
  550. /*Print( "-------------------------" );
  551. Print( this );
  552. Print( m_DecayTimer );
  553. Print( m_DecayDelta );
  554. Print( m_LastDecayStage );*/
  555. if ( IsFruit() || IsMushroom() )
  556. {
  557. // fruit, vegetables and mushrooms
  558. if ( m_LastDecayStage != GetFoodStageType() )
  559. {
  560. switch ( GetFoodStageType() )
  561. {
  562. case FoodStageType.RAW:
  563. m_DecayTimer = ( GameConstants.DECAY_FOOD_RAW_FRVG + ( Math.RandomFloat01() * ( GameConstants.DECAY_FOOD_RAW_FRVG * ( GameConstants.DECAY_TIMER_RANDOM_PERCENTAGE / 100.0 ) ) ) );
  564. m_LastDecayStage = FoodStageType.RAW;
  565. break;
  566. case FoodStageType.BOILED:
  567. m_DecayTimer = ( GameConstants.DECAY_FOOD_BOILED_FRVG + ( Math.RandomFloat01() * ( GameConstants.DECAY_FOOD_BOILED_FRVG * ( GameConstants.DECAY_TIMER_RANDOM_PERCENTAGE / 100.0 ) ) ) );
  568. m_LastDecayStage = FoodStageType.BOILED;
  569. break;
  570. case FoodStageType.BAKED:
  571. m_DecayTimer = ( GameConstants.DECAY_FOOD_BAKED_FRVG + ( Math.RandomFloat01() * ( GameConstants.DECAY_FOOD_BAKED_FRVG * ( GameConstants.DECAY_TIMER_RANDOM_PERCENTAGE / 100.0 ) ) ) );
  572. m_LastDecayStage = FoodStageType.BAKED;
  573. break;
  574. case FoodStageType.DRIED:
  575. case FoodStageType.BURNED:
  576. case FoodStageType.ROTTEN:
  577. default:
  578. m_DecayTimer = -1;
  579. m_LastDecayStage = FoodStageType.NONE;
  580. return;
  581. }
  582. //m_DecayTimer = m_DecayTimer / 1000.0;
  583. }
  584. m_DecayTimer -= ( delta * m_DecayDelta );
  585. if ( m_DecayTimer <= 0 )
  586. {
  587. if ( m_LastDecayStage != FoodStageType.NONE )
  588. {
  589. // switch to decayed stage
  590. if ( ( m_LastDecayStage == FoodStageType.BOILED ) || ( m_LastDecayStage == FoodStageType.BAKED ) )
  591. {
  592. ChangeFoodStage( FoodStageType.ROTTEN );
  593. }
  594. if ( m_LastDecayStage == FoodStageType.RAW )
  595. {
  596. int rng = Math.RandomIntInclusive( 0, 100 );
  597. if ( rng > GameConstants.DECAY_FOOD_FRVG_DRIED_CHANCE )
  598. {
  599. ChangeFoodStage( FoodStageType.ROTTEN );
  600. }
  601. else
  602. {
  603. if ( CanChangeToNewStage( FoodStageType.DRIED ) )
  604. {
  605. ChangeFoodStage( FoodStageType.DRIED );
  606. }
  607. else
  608. {
  609. ChangeFoodStage( FoodStageType.ROTTEN );
  610. }
  611. }
  612. }
  613. }
  614. }
  615. }
  616. else if ( IsMeat() )
  617. {
  618. // meat
  619. if ( m_LastDecayStage != GetFoodStageType() )
  620. {
  621. switch ( GetFoodStageType() )
  622. {
  623. case FoodStageType.RAW:
  624. m_DecayTimer = ( GameConstants.DECAY_FOOD_RAW_MEAT + ( Math.RandomFloat01() * ( GameConstants.DECAY_FOOD_RAW_MEAT * ( GameConstants.DECAY_TIMER_RANDOM_PERCENTAGE / 100.0 ) ) ) );
  625. m_LastDecayStage = FoodStageType.RAW;
  626. break;
  627. case FoodStageType.BOILED:
  628. m_DecayTimer = ( GameConstants.DECAY_FOOD_BOILED_MEAT + ( Math.RandomFloat01() * ( GameConstants.DECAY_FOOD_BOILED_MEAT * ( GameConstants.DECAY_TIMER_RANDOM_PERCENTAGE / 100.0 ) ) ) );
  629. m_LastDecayStage = FoodStageType.BOILED;
  630. break;
  631. case FoodStageType.BAKED:
  632. m_DecayTimer = ( GameConstants.DECAY_FOOD_BAKED_MEAT + ( Math.RandomFloat01() * ( GameConstants.DECAY_FOOD_BAKED_MEAT * ( GameConstants.DECAY_TIMER_RANDOM_PERCENTAGE / 100.0 ) ) ) );
  633. m_LastDecayStage = FoodStageType.BAKED;
  634. break;
  635. case FoodStageType.DRIED:
  636. m_DecayTimer = ( GameConstants.DECAY_FOOD_DRIED_MEAT + ( Math.RandomFloat01() * ( GameConstants.DECAY_FOOD_DRIED_MEAT * ( GameConstants.DECAY_TIMER_RANDOM_PERCENTAGE / 100.0 ) ) ) );
  637. m_LastDecayStage = FoodStageType.DRIED;
  638. break;
  639. case FoodStageType.BURNED:
  640. case FoodStageType.ROTTEN:
  641. default:
  642. m_DecayTimer = -1;
  643. m_LastDecayStage = FoodStageType.NONE;
  644. return;
  645. }
  646. }
  647. m_DecayTimer -= ( delta * m_DecayDelta );
  648. if ( m_DecayTimer <= 0 )
  649. {
  650. if ( m_LastDecayStage != FoodStageType.NONE )
  651. {
  652. // switch to decayed stage
  653. if ( ( m_LastDecayStage == FoodStageType.DRIED ) || ( m_LastDecayStage == FoodStageType.RAW ) || ( m_LastDecayStage == FoodStageType.BOILED ) || ( m_LastDecayStage == FoodStageType.BAKED ) )
  654. {
  655. ChangeFoodStage( FoodStageType.ROTTEN );
  656. }
  657. }
  658. }
  659. }
  660. else if ( IsCorpse() )
  661. {
  662. // corpse
  663. if ( m_LastDecayStage != GetFoodStageType() )
  664. {
  665. switch ( GetFoodStageType() )
  666. {
  667. case FoodStageType.RAW:
  668. m_DecayTimer = ( GameConstants.DECAY_FOOD_RAW_CORPSE + ( Math.RandomFloat01() * ( GameConstants.DECAY_FOOD_RAW_CORPSE * ( GameConstants.DECAY_TIMER_RANDOM_PERCENTAGE / 100.0 ) ) ) );
  669. m_LastDecayStage = FoodStageType.RAW;
  670. break;
  671. case FoodStageType.BURNED:
  672. case FoodStageType.ROTTEN:
  673. default:
  674. m_DecayTimer = -1;
  675. m_LastDecayStage = FoodStageType.NONE;
  676. return;
  677. }
  678. }
  679. m_DecayTimer -= ( delta * m_DecayDelta );
  680. if ( m_DecayTimer <= 0 )
  681. {
  682. if ( m_LastDecayStage != FoodStageType.NONE )
  683. {
  684. // switch to decayed stage
  685. if ( ( m_LastDecayStage == FoodStageType.DRIED ) || ( m_LastDecayStage == FoodStageType.RAW ) || ( m_LastDecayStage == FoodStageType.BOILED ) || ( m_LastDecayStage == FoodStageType.BAKED ) )
  686. {
  687. ChangeFoodStage( FoodStageType.ROTTEN );
  688. }
  689. }
  690. }
  691. }
  692. else
  693. {
  694. // opened cans
  695. m_DecayTimer -= ( delta * m_DecayDelta );
  696. if ( ( m_DecayTimer <= 0 ) && ( m_LastDecayStage == FoodStageType.NONE ) )
  697. {
  698. m_DecayTimer = ( GameConstants.DECAY_FOOD_CAN_OPEN + ( Math.RandomFloat01() * ( GameConstants.DECAY_FOOD_DRIED_MEAT * ( GameConstants.DECAY_TIMER_RANDOM_PERCENTAGE / 100.0 ) ) ) );
  699. m_LastDecayStage = FoodStageType.RAW;
  700. //m_DecayTimer = m_DecayTimer / 1000.0;
  701. }
  702. else
  703. {
  704. if ( m_DecayTimer <= 0 )
  705. {
  706. InsertAgent(eAgents.FOOD_POISON, 1);
  707. m_DecayTimer = -1;
  708. }
  709. }
  710. }
  711. }
  712. protected void UpdateVaporParticle()
  713. {
  714. if (GetGame().IsDedicatedServer())
  715. return;
  716. if (m_VarTemperature >= GameConstants.STATE_HOT_LVL_TWO && !m_HotVaporParticle)
  717. {
  718. InventoryLocation invLoc = new InventoryLocation();
  719. GetInventory().GetCurrentInventoryLocation(invLoc);
  720. if (invLoc && (invLoc.GetType() == InventoryLocationType.GROUND || invLoc.GetType() == InventoryLocationType.HANDS))
  721. {
  722. ParticleManager ptcMgr = ParticleManager.GetInstance();
  723. if (ptcMgr)
  724. {
  725. m_HotVaporParticle = ParticleManager.GetInstance().PlayOnObject(ParticleList.ITEM_HOT_VAPOR, this);
  726. m_HotVaporParticle.SetParticleParam(EmitorParam.SIZE, 0.3);
  727. m_HotVaporParticle.SetParticleParam(EmitorParam.BIRTH_RATE, 10);
  728. m_HotVaporParticle.SetParticleAutoDestroyFlags(ParticleAutoDestroyFlags.ON_STOP);
  729. }
  730. }
  731. }
  732. else if (m_HotVaporParticle)
  733. {
  734. if (m_VarTemperature <= GameConstants.STATE_HOT_LVL_TWO)
  735. {
  736. m_HotVaporParticle.Stop();
  737. m_HotVaporParticle = null;
  738. return;
  739. }
  740. InventoryLocation inventoryLoc = new InventoryLocation();
  741. GetInventory().GetCurrentInventoryLocation(inventoryLoc);
  742. if (invLoc && (invLoc.GetType() != InventoryLocationType.GROUND && invLoc.GetType() != InventoryLocationType.HANDS))
  743. {
  744. m_HotVaporParticle.Stop();
  745. m_HotVaporParticle = null;
  746. }
  747. }
  748. }
  749. override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
  750. {
  751. super.GetDebugActions(outputList);
  752. if (GetFoodStage())
  753. {
  754. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
  755. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
  756. }
  757. }
  758. override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
  759. {
  760. super.OnAction(action_id, player, ctx);
  761. if ( GetGame().IsServer() )
  762. {
  763. if ( action_id == EActions.FOOD_STAGE_PREV )
  764. {
  765. int food_stage_prev = GetFoodStageType() - 1;
  766. if (food_stage_prev <= 0)
  767. {
  768. food_stage_prev = FoodStageType.COUNT - 1;
  769. }
  770. ChangeFoodStage(food_stage_prev);
  771. return true;
  772. }
  773. else if ( action_id == EActions.FOOD_STAGE_NEXT )
  774. {
  775. int food_stage_next = GetFoodStageType() + 1;
  776. if (food_stage_next >= FoodStageType.COUNT )
  777. {
  778. food_stage_next = FoodStageType.RAW;
  779. }
  780. ChangeFoodStage(food_stage_next);
  781. return true;
  782. }
  783. }
  784. return false;
  785. }
  786. override string GetDebugText()
  787. {
  788. string debug_output;
  789. debug_output = super.GetDebugText();
  790. debug_output+="m_CookedByMethod:"+m_CookedByMethod+"\n";
  791. debug_output+="m_MakeCookingSounds:"+m_MakeCookingSounds+"\n";
  792. return debug_output;
  793. }
  794. //================================================================
  795. // GENERAL GETTERS
  796. //================================================================
  797. override float GetBaitEffectivity()
  798. {
  799. float ret = super.GetBaitEffectivity();
  800. if (IsFoodRotten())
  801. {
  802. ret *= 0.5;
  803. }
  804. return ret;
  805. }
  806. float GetDecayTimer()
  807. {
  808. return m_DecayTimer;
  809. }
  810. float GetDecayDelta()
  811. {
  812. return m_DecayDelta;
  813. }
  814. FoodStageType GetLastDecayStage()
  815. {
  816. return m_LastDecayStage;
  817. }
  818. //////////////////////////////////////////
  819. //DEPRECATED
  820. //////////////////////////////////////////
  821. void UpdateVisuals()
  822. {
  823. UpdateVisualsEx();
  824. }
  825. }
  826. class ReplaceEdibleWithNewLambda : TurnItemIntoItemLambda
  827. {
  828. void ReplaceEdibleWithNewLambda(EntityAI old_item, string new_item_type, PlayerBase player) { }
  829. };