broom.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. class BroomBase : FlammableBase
  2. {
  3. override void Init()
  4. {
  5. super.Init();
  6. m_DecraftResult = "LongWoodenStick";
  7. m_ParticleLocalPos = Vector(0, 1.2, 0);
  8. }
  9. override void SetActions()
  10. {
  11. super.SetActions();
  12. AddAction(ActionClapBearTrapWithThisItem);
  13. AddAction(ActionBreakLongWoodenStick);
  14. }
  15. override bool CanReceiveUpgrade()
  16. {
  17. return false;
  18. }
  19. override void OnWorkStart()
  20. {
  21. super.OnWorkStart();
  22. CalculateQuantity();
  23. }
  24. override void ApplyResultModifications(ItemBase result)
  25. {
  26. result.SetHealth(result.GetHealthLevelValue(2,""));
  27. result.SetQuantity(1);
  28. }
  29. override bool CanTransformIntoStick()
  30. {
  31. if ( GetGame().IsServer() && !IsIgnited() && GetEnergy() < 1 && !IsSetForDeletion())
  32. return true;
  33. else
  34. return false;
  35. }
  36. override void EEHitBy(TotalDamageResult damageResult, int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos, float speedCoef)
  37. {
  38. super.EEHitBy(damageResult, damageType, source, component, dmgZone, ammo, modelPos, speedCoef);
  39. GetCompEM().SetEnergy0To1(GetHealth01("",""));
  40. }
  41. override void CalculateQuantity()
  42. {
  43. if (GetGame().IsServer())
  44. {
  45. float currentHealth01 = GetHealth01();
  46. float currentEnergy01 = GetCompEM().GetEnergy0To1();
  47. //Health needs to copy internal energy, but only if that means it will be going down from its current value(the item can't heal itself after obtaining damage just because it has full internal energy)
  48. SetHealth01("","",Math.Min(currentHealth01,currentEnergy01));
  49. //Energy needs to copy health, but only if it is higher(in 01 terms) than health, that means if an item with full energy gets damaged and lit, the internal energy needs to be adjusted to follow the health. Situations where internal energy is lower than health are handled on the line above
  50. GetCompEM().SetEnergy0To1(GetHealth01());
  51. }
  52. }
  53. override void UpdateParticle()
  54. {
  55. float normalizedQuant = GetQuantity() / GetQuantityMax();
  56. if (!m_FireParticle)
  57. {
  58. m_FireParticle = ParticleManager.GetInstance().PlayOnObject(ParticleList.BROOM_TORCH_T1, this, m_ParticleLocalPos);
  59. }
  60. m_FireParticle.ScaleParticleParamFromOriginal(EmitorParam.VELOCITY, 1.0);
  61. m_FireParticle.ScaleParticleParamFromOriginal(EmitorParam.VELOCITY_RND, 1.0);
  62. if (m_FireParticle)
  63. {
  64. float scale = Math.Max(normalizedQuant * 2.4, 0.4);
  65. m_FireParticle.ScaleParticleParamFromOriginal(EmitorParam.SIZE, scale);
  66. }
  67. }
  68. // DEBUG BELLOW
  69. void DebugSetHealthAndEnergy(float time)
  70. {
  71. float max_energy = GetCompEM().GetEnergyMaxPristine();
  72. float health01 = Math.InverseLerp(0, max_energy, time);
  73. SetHealth01("","", health01);
  74. GetCompEM().SetEnergy( time );
  75. }
  76. override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
  77. {
  78. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.BROOM_BURN_VERY_SHORT, "SetBurnTimeTo15Secs", FadeColors.LIGHT_GREY));
  79. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.BROOM_BURN_SHORT, "SetBurnTimeTo1Min", FadeColors.LIGHT_GREY));
  80. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.BROOM_BURN_MEDIUM, "SetBurnTimeTo10Min", FadeColors.LIGHT_GREY));
  81. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.BROOM_BURN_LONG, "SetBurnTimeToMax", FadeColors.LIGHT_GREY));
  82. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.LIGHT_GREY));
  83. super.GetDebugActions(outputList);
  84. }
  85. override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
  86. {
  87. if (super.OnAction(action_id, player, ctx))
  88. return true;
  89. if (GetGame().IsServer() || !GetGame().IsMultiplayer())
  90. {
  91. if (action_id == EActions.BROOM_BURN_VERY_SHORT)
  92. {
  93. DebugSetHealthAndEnergy(15);
  94. OnIgnitedThis(null);
  95. }
  96. else if (action_id == EActions.BROOM_BURN_SHORT)
  97. {
  98. DebugSetHealthAndEnergy(60);
  99. OnIgnitedThis(null);
  100. }
  101. else if (action_id == EActions.BROOM_BURN_MEDIUM)
  102. {
  103. DebugSetHealthAndEnergy(600);
  104. OnIgnitedThis(null);
  105. }
  106. else if (action_id == EActions.BROOM_BURN_LONG)
  107. {
  108. DebugSetHealthAndEnergy(GetCompEM().GetEnergyMaxPristine());
  109. OnIgnitedThis(null);
  110. }
  111. }
  112. return false;
  113. }
  114. }
  115. class Broom: BroomBase
  116. {
  117. override string GetBurningMaterial()
  118. {
  119. return "DZ\\gear\\tools\\data\\broom_emissive.rvmat";
  120. }
  121. override string GetBurntMaterial()
  122. {
  123. return "DZ\\gear\\tools\\data\\broom_burn.rvmat";
  124. }
  125. };