fryingpan.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. class FryingPan : Inventory_Base
  2. {
  3. // Cooking data
  4. protected CookingMethodType m_CookingMethod;
  5. protected bool m_CookingIsDone;
  6. protected bool m_CookingIsEmpty;
  7. protected bool m_CookingIsBurned;
  8. // Particles
  9. protected Particle m_ParticleCooking;
  10. protected int m_ParticlePlaying = ParticleList.INVALID;
  11. protected int PARTICLE_BAKING_START = ParticleList.COOKING_BAKING_START;
  12. protected int PARTICLE_BAKING_DONE = ParticleList.COOKING_BAKING_DONE;
  13. protected int PARTICLE_DRYING_START = ParticleList.COOKING_DRYING_START;
  14. protected int PARTICLE_DRYING_DONE = ParticleList.COOKING_DRYING_DONE;
  15. protected int PARTICLE_BURNING_DONE = ParticleList.COOKING_BURNING_DONE;
  16. void FryingPan()
  17. {
  18. RegisterNetSyncVariableInt( "m_CookingMethod", CookingMethodType.NONE, CookingMethodType.COUNT );
  19. RegisterNetSyncVariableBool( "m_CookingIsDone" );
  20. RegisterNetSyncVariableBool( "m_CookingIsEmpty" );
  21. RegisterNetSyncVariableBool( "m_CookingIsBurned" );
  22. }
  23. void ~FryingPan() {}
  24. override bool IsContainer()
  25. {
  26. return true;
  27. }
  28. override bool IsCookware()
  29. {
  30. return true;
  31. }
  32. override bool CanHaveTemperature()
  33. {
  34. return true;
  35. }
  36. override float GetQuantityNormalizedScripted()
  37. {
  38. return 1.0;
  39. }
  40. override bool CanPutInCargo( EntityAI parent )
  41. {
  42. if ( !super.CanPutInCargo( parent ) )
  43. return false;
  44. if ( parent && IsCargoException4x3( parent ) )
  45. return false;
  46. //is 'parent' somewhere in cargo?
  47. if (parent && !parent.GetInventory().AreChildrenAccessible())
  48. return false;
  49. return true;
  50. }
  51. override bool CanReceiveItemIntoCargo( EntityAI item )
  52. {
  53. if ( !super.CanReceiveItemIntoCargo( item ) )
  54. return false;
  55. if ( IsCargoException4x3( item ) )
  56. return false;
  57. //is 'this' somewhere in cargo?
  58. if (!GetInventory().AreChildrenAccessible())
  59. return false;
  60. //can 'this' be attached to the item (->assumed smaller size than item)?
  61. int slotId;
  62. for (int i = 0; i < GetInventory().GetSlotIdCount(); i++)
  63. {
  64. slotId = GetInventory().GetSlotId(i);
  65. if (item.GetInventory().HasAttachmentSlot(slotId))
  66. {
  67. //Print("CanReceiveItemIntoCargo | item " + item + " matches in slot name: " + InventorySlots.GetSlotName(slotId) + " of " + this);
  68. return false;
  69. }
  70. }
  71. return true;
  72. }
  73. override bool CanLoadItemIntoCargo( EntityAI item )
  74. {
  75. if ( !super.CanLoadItemIntoCargo( item ) )
  76. return false;
  77. if ( IsCargoException4x3( item ) )
  78. return false;
  79. //can 'this' be attached to the item (->assumed smaller size than item)?
  80. int slotId;
  81. for (int i = 0; i < GetInventory().GetSlotIdCount(); i++)
  82. {
  83. slotId = GetInventory().GetSlotId(i);
  84. if (item.GetInventory().HasAttachmentSlot(slotId))
  85. {
  86. //Print("CanLoadItemIntoCargo | item " + item + " matches in slot name: " + InventorySlots.GetSlotName(slotId) + " of " + this);
  87. return false;
  88. }
  89. }
  90. return true;
  91. }
  92. override void SetActions()
  93. {
  94. super.SetActions();
  95. AddAction(ActionCreateIndoorFireplace);
  96. AddAction(ActionCreateIndoorOven);
  97. AddAction(ActionAttach);
  98. AddAction(ActionDetach);
  99. }
  100. override void EEDelete( EntityAI parent )
  101. {
  102. super.EEDelete( parent );
  103. //remove audio visuals
  104. RemoveAudioVisuals();
  105. }
  106. void Synchronize()
  107. {
  108. if ( GetGame() && GetGame().IsServer() )
  109. {
  110. SetSynchDirty();
  111. }
  112. }
  113. override void OnVariablesSynchronized()
  114. {
  115. super.OnVariablesSynchronized();
  116. //refresh audio visuals
  117. if ( m_CookingMethod != CookingMethodType.NONE )
  118. {
  119. RefreshAudioVisuals( m_CookingMethod, m_CookingIsDone, m_CookingIsEmpty, m_CookingIsBurned );
  120. }
  121. else
  122. {
  123. RemoveAudioVisuals();
  124. }
  125. }
  126. override void RemoveAudioVisualsOnClient()
  127. {
  128. m_CookingMethod = CookingMethodType.NONE;
  129. Synchronize();
  130. }
  131. override void RefreshAudioVisualsOnClient( CookingMethodType cooking_method, bool is_done, bool is_empty, bool is_burned )
  132. {
  133. m_CookingMethod = cooking_method;
  134. m_CookingIsDone = is_done;
  135. m_CookingIsEmpty = is_empty;
  136. m_CookingIsBurned = is_burned;
  137. Synchronize();
  138. }
  139. void RefreshAudioVisuals( CookingMethodType cooking_method, bool is_done, bool is_empty, bool is_burned )
  140. {
  141. int particleId;
  142. //if at least one of the food items is burned
  143. if (is_burned)
  144. {
  145. particleId = PARTICLE_BURNING_DONE;
  146. }
  147. //proper cooking methods
  148. else
  149. {
  150. if (cooking_method == CookingMethodType.BAKING)
  151. {
  152. if (is_done)
  153. particleId = PARTICLE_BAKING_DONE;
  154. else
  155. particleId = PARTICLE_BAKING_START;
  156. }
  157. else if (cooking_method == CookingMethodType.DRYING)
  158. {
  159. if (is_done)
  160. particleId = PARTICLE_DRYING_DONE;
  161. else
  162. particleId = PARTICLE_DRYING_START;
  163. }
  164. }
  165. ParticleCookingStart(particleId);
  166. }
  167. void RemoveAudioVisuals()
  168. {
  169. ParticleCookingStop();
  170. }
  171. void ParticleCookingStart( int particle_id )
  172. {
  173. if ( m_ParticlePlaying != particle_id )
  174. {
  175. //stop previous particles
  176. ParticleCookingStop();
  177. //create new
  178. if ( GetGame() && ( !GetGame().IsDedicatedServer() ) )
  179. {
  180. vector local_pos = MiscGameplayFunctions.GetSteamPosition( GetHierarchyParent() );
  181. //TODO set steam position to pot (proxy) memory point (new hierarchy needed)
  182. //m_ParticleCooking = Particle.Create( particle_id, this, local_pos );
  183. m_ParticleCooking = ParticleManager.GetInstance().PlayInWorld( particle_id, local_pos );
  184. m_ParticlePlaying = particle_id;
  185. }
  186. }
  187. }
  188. void ParticleCookingStop()
  189. {
  190. if ( m_ParticleCooking && GetGame() && ( !GetGame().IsDedicatedServer() ) )
  191. {
  192. m_ParticleCooking.Stop();
  193. m_ParticleCooking = NULL;
  194. m_ParticlePlaying = ParticleList.INVALID;
  195. }
  196. }
  197. /////////////////////////////////////////////////
  198. // DEPRECATED STUFF
  199. // Sounds
  200. protected SoundOnVehicle m_SoundCooking; //! DEPRECATED
  201. protected EffectSound m_SoundEffectCooking; //! DEPRECATED
  202. protected string m_SoundPlaying = ""; //! DEPRECATED
  203. const string SOUND_BAKING_START = "Baking_SoundSet"; //! DEPRECATED
  204. const string SOUND_BAKING_DONE = "Baking_Done_SoundSet"; //! DEPRECATED
  205. const string SOUND_DRYING_START = "Drying_SoundSet"; //! DEPRECATED
  206. const string SOUND_DRYING_DONE = "Drying_Done_SoundSet"; //! DEPRECATED
  207. const string SOUND_BURNING_DONE = "Food_Burning_SoundSet"; //! DEPRECATED
  208. protected void SoundCookingStart(string sound_name); //! DEPRECATED
  209. protected void SoundCookingStop(); //! DEPRECATED
  210. }