fryingpan.c 6.0 KB

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