aeroson

Untitled

Nov 6th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6.  
  7. namespace MyEngine
  8. {
  9. public class Grenade : ItemComponent
  10. {
  11. [ConfigVar]
  12. public float cookTimeInitial = 10;
  13.  
  14. [SyncOnOwnerChange]
  15. public float cookTimeCurrent = 0;
  16.  
  17. public bool CanRemovePin { get { return state == State.Safe; } }
  18.  
  19. [SyncOnOwnerChange]
  20. public State state = State.Safe;
  21.  
  22. [ConfigVar]
  23. public Trigger removeSafetyPin;
  24.  
  25.  
  26. public enum State
  27. {
  28. Safe,
  29. PinReleased,
  30. Exploding,
  31. Exploded,
  32. }
  33.  
  34.  
  35. void OnStart()
  36. {
  37. if (removeSafetyPin != null)
  38. {
  39. removeSafetyPin.makesSenseToInteract = () => CanRemovePin;
  40. removeSafetyPin.action = RemovePin;
  41. }
  42. }
  43.  
  44. [CallOnOwner]
  45. public void RemovePin()
  46. {
  47. state = State.PinReleased;
  48. cookTimeCurrent = cookTimeInitial;
  49. entity.PlayEffectGlobal("grenade pin release");
  50. }
  51.  
  52.  
  53. void OnLogic_Owner(float deltaTime)
  54. {
  55. if (state == State.PinReleased)
  56. {
  57. cookTimeCurrent -= deltaTime;
  58. if (cookTimeCurrent < 0)
  59. {
  60. state = State.Exploding;
  61. }
  62. }
  63. if (state == State.Exploding)
  64. {
  65. state = State.Exploded;
  66. entity.PlayEffectGlobal("explosion grenade");
  67. }
  68. }
  69. }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment