Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace MyEngine
- {
- public class Grenade : ItemComponent
- {
- [ConfigVar]
- public float cookTimeInitial = 10;
- [SyncOnOwnerChange]
- public float cookTimeCurrent = 0;
- public bool CanRemovePin { get { return state == State.Safe; } }
- [SyncOnOwnerChange]
- public State state = State.Safe;
- [ConfigVar]
- public Trigger removeSafetyPin;
- public enum State
- {
- Safe,
- PinReleased,
- Exploding,
- Exploded,
- }
- void OnStart()
- {
- if (removeSafetyPin != null)
- {
- removeSafetyPin.makesSenseToInteract = () => CanRemovePin;
- removeSafetyPin.action = RemovePin;
- }
- }
- [CallOnOwner]
- public void RemovePin()
- {
- state = State.PinReleased;
- cookTimeCurrent = cookTimeInitial;
- entity.PlayEffectGlobal("grenade pin release");
- }
- void OnLogic_Owner(float deltaTime)
- {
- if (state == State.PinReleased)
- {
- cookTimeCurrent -= deltaTime;
- if (cookTimeCurrent < 0)
- {
- state = State.Exploding;
- }
- }
- if (state == State.Exploding)
- {
- state = State.Exploded;
- entity.PlayEffectGlobal("explosion grenade");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment