cacontinuousempty.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. class CAContinuousEmpty : CAContinuousBase
  2. {
  3. protected float m_TargetUnits;
  4. protected float m_SpentQuantity;
  5. protected float m_SpentQuantity_total;
  6. protected float m_AdjustedQuantityEmptiedPerSecond;
  7. protected float m_QuantityEmptiedPerSecond;
  8. protected bool m_WringingClothes;
  9. protected ref Param1<float> m_SpentUnits;
  10. protected float m_TimeElpased;
  11. protected float m_DefaultTimeStep = 0.25;
  12. void CAContinuousEmpty( float quantity_emptied_per_second )
  13. {
  14. m_QuantityEmptiedPerSecond = quantity_emptied_per_second;
  15. }
  16. override void Setup( ActionData action_data )
  17. {
  18. if ( !m_SpentUnits )
  19. {
  20. m_SpentUnits = new Param1<float>(0);
  21. }
  22. else
  23. {
  24. m_SpentUnits.param1 = 0;
  25. }
  26. if ( action_data.m_MainItem.IsClothing() )
  27. {
  28. m_WringingClothes = true;
  29. m_SpentQuantity = action_data.m_MainItem.GetWetMax() - action_data.m_MainItem.GetWet();
  30. m_TargetUnits = action_data.m_MainItem.GetWetMax();
  31. }
  32. else
  33. {
  34. m_WringingClothes = false;
  35. m_SpentQuantity = action_data.m_MainItem.GetQuantityMin();
  36. m_TargetUnits = action_data.m_MainItem.GetQuantity();
  37. }
  38. m_AdjustedQuantityEmptiedPerSecond = m_QuantityEmptiedPerSecond;//removed softskills
  39. }
  40. override int Execute( ActionData action_data )
  41. {
  42. if ( !action_data.m_Player )
  43. {
  44. return UA_ERROR;
  45. }
  46. if ( m_WringingClothes && action_data.m_MainItem.GetWet() >= action_data.m_MainItem.GetWetMax() )
  47. {
  48. return UA_FINISHED;
  49. }
  50. else
  51. {
  52. if ( m_SpentQuantity_total <= m_TargetUnits )
  53. {
  54. m_SpentQuantity += m_AdjustedQuantityEmptiedPerSecond * action_data.m_Player.GetDeltaT();
  55. m_TimeElpased += action_data.m_Player.GetDeltaT();
  56. if ( m_TimeElpased >= m_DefaultTimeStep )
  57. {
  58. CalcAndSetQuantity( action_data );
  59. m_TimeElpased = 0;
  60. }
  61. return UA_PROCESSING;
  62. }
  63. else
  64. {
  65. CalcAndSetQuantity( action_data );
  66. OnCompletePogress(action_data);
  67. return UA_FINISHED;
  68. }
  69. }
  70. }
  71. override int Cancel( ActionData action_data )
  72. {
  73. if ( !action_data.m_Player || !action_data.m_MainItem )
  74. {
  75. return UA_ERROR;
  76. }
  77. CalcAndSetQuantity( action_data );
  78. return UA_CANCEL;
  79. }
  80. override float GetProgress()
  81. {
  82. return m_SpentQuantity_total / m_TargetUnits;
  83. }
  84. //---------------------------------------------------------------------------
  85. void CalcAndSetQuantity( ActionData action_data )
  86. {
  87. m_SpentQuantity_total += m_SpentQuantity;
  88. if (GetGame().IsServer())
  89. {
  90. if ( m_SpentUnits )
  91. {
  92. m_SpentUnits.param1 = m_SpentQuantity;
  93. SetACData(m_SpentUnits);
  94. }
  95. if (action_data.m_MainItem.GetQuantity() > 0.0)
  96. action_data.m_MainItem.AddQuantity(-m_SpentQuantity);
  97. }
  98. m_SpentQuantity = 0;
  99. }
  100. };