예제 #1
0
 public static void SetCurrentHealth(this Health.Writer health, int newHealth)
 {
     if (health.Data.canBeChanged)
     {
         health.Send(new Health.Update().SetCurrentHealth(Mathf.Max(newHealth, 0)));
     }
 }
예제 #2
0
 public BarracksConstructionFinishedState(BarracksStateMachine owner,
                                          Health.Writer inHealth,
                                          NPCSpawnerBehaviour inNPCSpawnerBehaviour) : base(owner)
 {
     health = inHealth;
     npcSpawnerBehaviour = inNPCSpawnerBehaviour;
 }
        public BarracksStateMachine(BarracksInfo.Writer inBarracksInfo,
                                    StockpileDepository.Writer inStockpile,
                                    Health.Writer inHealth,
                                    FlammableBehaviour inFlammableBehaviour,
                                    NPCSpawnerBehaviour npcSpawnerBehaviour)
        {
            barracksInfo       = inBarracksInfo;
            stockpile          = inStockpile;
            health             = inHealth;
            flammableBehaviour = inFlammableBehaviour;

            var stateList = new Dictionary <BarracksState, IFsmState>
            {
                { BarracksState.UNDER_CONSTRUCTION, new BarracksUnderConstructionState(this, inHealth, npcSpawnerBehaviour) },
                { BarracksState.CONSTRUCTION_FINISHED, new BarracksConstructionFinishedState(this, inHealth, npcSpawnerBehaviour) }
            };

            SetStates(stateList);

            var allowedTransitions = new Dictionary <BarracksState, IList <BarracksState> >()
            {
                { BarracksState.UNDER_CONSTRUCTION, new List <BarracksState> {
                      BarracksState.CONSTRUCTION_FINISHED
                  } },
                { BarracksState.CONSTRUCTION_FINISHED, new List <BarracksState> {
                      BarracksState.UNDER_CONSTRUCTION
                  } }
            };

            SetTransitions(allowedTransitions);
        }
예제 #4
0
 public static void AddCurrentHealthDelta(this Health.Writer health, int delta)
 {
     if (health.Data.canBeChanged)
     {
         if (health.TryingToDecreaseHealthBelowZero(delta))
         {
             return;
         }
         health.Send(new Health.Update().SetCurrentHealth(Mathf.Max(health.Data.currentHealth + delta, 0)));
     }
 }
예제 #5
0
        public TreeStateMachine(
            TreeBehaviour owner,
            TreeState.Writer inTree,
            Health.Writer health,
            FlammableBehaviour flammableInterface,
            Flammable.Writer flammable
            )
        {
            tree = inTree;

            var healthyState = new TreeHealthyState(this, flammable, health);
            var burningState = new TreeBurningState(this, flammable, health);
            var burntState   = new TreeBurntState(this, owner, flammable, flammableInterface);
            var stumpState   = new TreeStumpState(this, owner, flammable);

            var stateList = new Dictionary <TreeFSMState, IFsmState>();

            stateList.Add(TreeFSMState.HEALTHY, healthyState);
            stateList.Add(TreeFSMState.BURNING, burningState);
            stateList.Add(TreeFSMState.BURNT, burntState);
            stateList.Add(TreeFSMState.STUMP, stumpState);

            SetStates(stateList);

            var allowedTransitions = new Dictionary <TreeFSMState, IList <TreeFSMState> >();

            allowedTransitions.Add(TreeFSMState.HEALTHY, new List <TreeFSMState>()
            {
                TreeFSMState.BURNING,
                TreeFSMState.STUMP
            });

            allowedTransitions.Add(TreeFSMState.BURNING, new List <TreeFSMState>()
            {
                TreeFSMState.HEALTHY,
                TreeFSMState.BURNT
            });

            allowedTransitions.Add(TreeFSMState.BURNT, new List <TreeFSMState>()
            {
                TreeFSMState.HEALTHY
            });

            allowedTransitions.Add(TreeFSMState.STUMP, new List <TreeFSMState>()
            {
                TreeFSMState.HEALTHY
            });

            SetTransitions(allowedTransitions);
        }
예제 #6
0
 public static void SetCanBeChanged(this Health.Writer health, bool canBeChanged)
 {
     health.Send(new Health.Update().SetCanBeChanged(canBeChanged));
 }
예제 #7
0
 public TreeHealthyState(TreeStateMachine owner, Flammable.Writer inFlammable, Health.Writer inHealth)
     : base(owner)
 {
     flammable = inFlammable;
     health    = inHealth;
 }