blowtorch.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. class Blowtorch extends ItemBase
  2. {
  3. const string TEXTURE_FLAME = "dz\\gear\\cooking\\data\\flame_butane_ca.paa";
  4. const string ANIM_PHASE_FLAME = "FlameHide";
  5. const string SOUND_BURNING = "Blowtorch_Loop_SoundSet";
  6. protected BlowtorchLight m_Light;
  7. protected EffectSound m_SoundBurningLoop;
  8. override void OnWorkStart()
  9. {
  10. super.OnWorkStart();
  11. #ifndef SERVER
  12. m_Light = BlowtorchLight.Cast(ScriptedLightBase.CreateLight(BlowtorchLight, "0 0 0"));
  13. m_Light.AttachOnMemoryPoint(this, "light");
  14. #endif
  15. RefreshFlameVisual(true);
  16. SoundBurningStart();
  17. }
  18. override void OnWorkStop()
  19. {
  20. #ifndef SERVER
  21. if (m_Light)
  22. {
  23. m_Light.FadeOut();
  24. }
  25. #endif
  26. RefreshFlameVisual(false);
  27. SoundBurningStop();
  28. }
  29. protected void RefreshFlameVisual(bool working = false)
  30. {
  31. if (working)
  32. {
  33. SetObjectTexture(0, TEXTURE_FLAME);
  34. SetAnimationPhase(ANIM_PHASE_FLAME, 0.0);
  35. }
  36. else
  37. {
  38. SetObjectTexture(0, "");
  39. SetAnimationPhase(ANIM_PHASE_FLAME, 1.0);
  40. }
  41. }
  42. protected void SoundBurningStart()
  43. {
  44. PlaySoundSetLoop(m_SoundBurningLoop, SOUND_BURNING, 0.1, 0.0);
  45. }
  46. protected void SoundBurningStop()
  47. {
  48. StopSoundSet(m_SoundBurningLoop);
  49. }
  50. override bool CanPutInCargo(EntityAI parent)
  51. {
  52. if (!super.CanPutInCargo(parent))
  53. {
  54. return false;
  55. }
  56. return !GetCompEM().IsSwitchedOn();
  57. }
  58. override bool CanRemoveFromCargo(EntityAI parent)
  59. {
  60. return true;
  61. }
  62. override bool IsIgnited()
  63. {
  64. return GetCompEM().IsWorking();
  65. }
  66. override void OnIgnitedTarget(EntityAI target_item)
  67. {
  68. if (GetGame().IsServer())
  69. {
  70. if (GetGasCanister())
  71. {
  72. ComponentEnergyManager canisterEM = GetGasCanister().GetCompEM();
  73. if (canisterEM)
  74. canisterEM.AddEnergy(-1 * (GetCompEM().GetEnergyUsage() * UATimeSpent.FIREPLACE_IGNITE));
  75. }
  76. }
  77. }
  78. override bool CanIgniteItem(EntityAI ignite_target = NULL)
  79. {
  80. return ignite_target.CanBeIgnitedBy(this);
  81. }
  82. override void SetActions()
  83. {
  84. super.SetActions();
  85. AddAction(ActionLightItemOnFireWithBlowtorch);
  86. AddAction(ActionRepairCarEngineWithBlowtorch);
  87. AddAction(ActionRepairCarChassisWithBlowtorch);
  88. AddAction(ActionRepairCarPartWithBlowtorch);
  89. AddAction(ActionRepairItemWithBlowtorch);
  90. AddAction(ActionRepairBoatEngine);
  91. }
  92. protected EntityAI GetGasCanister()
  93. {
  94. if (GetInventory().AttachmentCount() != 0)
  95. {
  96. return GetInventory().GetAttachmentFromIndex(0);
  97. }
  98. return null;
  99. }
  100. bool HasEnoughEnergyForRepair(float pTime)
  101. {
  102. if (GetGasCanister())
  103. {
  104. ComponentEnergyManager canisterEM = GetGasCanister().GetCompEM();
  105. if (canisterEM)
  106. {
  107. return canisterEM.GetEnergy() > GetCompEM().GetEnergyUsage() * pTime;
  108. }
  109. }
  110. return false;
  111. }
  112. override void OnDebugSpawn()
  113. {
  114. GetInventory().CreateInInventory("LargeGasCanister");
  115. }
  116. }