예제 #1
0
        /// <summary>
        /// Updates the Creature and checks if it needs food/water.
        /// Updates the behaviour block if there is none, add the GoToBonfire Behaviour block.
        /// </summary>
        protected override void Update()
        {
            base.Update();
            CreatureStats.Update();

            if (CreatureStats.NeedsFood() && !IsAlreadyGoingToEat())
            {
                BehaviourBlockQueue.AddFirst(new FindAndEat(this));
                if (CurrentCreatureBehaviourBlock != null)
                {
                    if (CurrentCreatureBehaviourBlock.GetType() != typeof(FindAndDrink) && CurrentCreatureBehaviourBlock.GetType() != typeof(FindAndEat))
                    {
                        CurrentCreatureBehaviourBlock = null;
                    }
                }
            }

            if (CreatureStats.NeedsDrink() && !IsAlreadyGoingToDrink())
            {
                BehaviourBlockQueue.AddFirst(new FindAndDrink(this));
                if (CurrentCreatureBehaviourBlock != null)
                {
                    if (CurrentCreatureBehaviourBlock.GetType() != typeof(FindAndDrink) && CurrentCreatureBehaviourBlock.GetType() != typeof(FindAndEat))
                    {
                        CurrentCreatureBehaviourBlock = null;
                    }
                }
            }

            if (CurrentCreatureBehaviourBlock != null)
            {
                if (!CurrentCreatureBehaviourBlock.AllDone())
                {
                    CurrentCreatureBehaviourBlock.Update();
                }
                else
                {
                    LastCompletedBehaviourBlock   = CurrentCreatureBehaviourBlock;
                    CurrentCreatureBehaviourBlock = null;
                }
            }
            else
            {
                if (BehaviourBlockQueue.Count > 0)
                {
                    CurrentCreatureBehaviourBlock = BehaviourBlockQueue.First().DeepCopy();
                    BehaviourBlockQueue.RemoveFirst();
                }
                else if (BehaviourBlockQueue.Count <= 0 && this.GetType() == typeof(VillagerAI))
                {
                    if (LastCompletedBehaviourBlock != null)
                    {
                        if (LastCompletedBehaviourBlock.GetType() != typeof(MoveToClosestBuildingOfType <Bonfire>))
                        {
                            BehaviourBlockQueue.AddFirst(new GoToBonfire(this));
                        }
                        else
                        {
                            BehaviourBlockQueue.AddFirst(new GoToBonfire(this));
                        }
                    }
                }
            }

            LastPosition = transform.position;
        }