Exemplo n.º 1
0
 public override void Destroy()
 {
     // stops the timmer
     IdleTimer.Reset();
     LifetimeTimer.Reset();
     base.Destroy();
 }
Exemplo n.º 2
0
        public override Task DestroyAsync()
        {
            // stops the timer
            IdleTimer.Reset();
            LifetimeTimer.Reset();

            return(base.DestroyAsync());
        }
Exemplo n.º 3
0
        public override async Task DestroyAsync()
        {
            // stops the timer
            IdleTimer.Reset();
            LifetimeTimer.Reset();

            await base.DestroyAsync();
        }
Exemplo n.º 4
0
        public override void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera)
        {
            IdleTimer.Update(gameTime);
            SpeakTimer.Update(gameTime);

            OrderEnemyAttack();
            DeleteBadTasks();
            PreEmptTasks();

            if (Status.Energy.IsUnhappy() && PlayState.Time.IsNight())
            {
                Task toReturn = new SatisfyTirednessTask();
                toReturn.SetupScript(Creature);
                if (!Tasks.Contains(toReturn))
                {
                    Tasks.Add(toReturn);
                }
            }

            if (Status.Hunger.IsUnhappy() && Faction.CountResourcesWithTag(Resource.ResourceTags.Food) > 0)
            {
                Task toReturn = new SatisfyHungerTask();
                toReturn.SetupScript(Creature);
                if (!Tasks.Contains(toReturn))
                {
                    Tasks.Add(toReturn);
                }
            }


            if (CurrentTask != null && CurrentAct != null)
            {
                Act.Status status = CurrentAct.Tick();


                bool retried = false;
                if (status == Act.Status.Fail)
                {
                    if (CurrentTask.ShouldRetry(Creature))
                    {
                        if (!Tasks.Contains(CurrentTask))
                        {
                            CurrentTask.Priority = Task.PriorityType.Eventually;
                            Tasks.Add(CurrentTask);
                            CurrentTask.SetupScript(Creature);
                            retried = true;
                        }
                    }
                }

                if (status != Act.Status.Running && !retried)
                {
                    CurrentTask = null;
                }
            }
            else
            {
                bool tantrum = false;
                if (Status.Happiness.IsUnhappy())
                {
                    tantrum = MathFunctions.Rand(0, 1) < 0.25f;
                }

                Task goal = GetEasiestTask(Tasks);
                if (goal != null)
                {
                    if (tantrum)
                    {
                        Creature.DrawIndicator(IndicatorManager.StandardIndicators.Sad);
                        if (Creature.Allies == "Dwarf")
                        {
                            PlayState.AnnouncementManager.Announce(Stats.FullName + " (" + Stats.CurrentLevel.Name + ")" + " refuses to work!",
                                                                   "Our employee is unhappy, and would rather not work!", ZoomToMe);
                        }
                        CurrentTask = null;
                    }
                    else
                    {
                        IdleTimer.Reset(IdleTimer.TargetTimeSeconds);
                        goal.SetupScript(Creature);
                        CurrentTask = goal;
                        Tasks.Remove(goal);
                    }
                }
                else
                {
                    CurrentTask = ActOnIdle();
                }
            }


            PlannerTimer.Update(gameTime);
            UpdateThoughts();
            UpdateXP();

            base.Update(gameTime, chunks, camera);
        }
Exemplo n.º 5
0
        public virtual Task ActOnIdle()
        {
            if(GatherManager.VoxelOrders.Count == 0 && (GatherManager.StockOrders.Count == 0 || !Faction.HasFreeStockpile()))
            {
                // Find a room to train in
                if (Stats.CurrentClass.HasAction(GameMaster.ToolMode.Attack) && MathFunctions.RandEvent(0.01f))
                {
                    Body closestTraining = Faction.FindNearestItemWithTags("Train", Position, true);

                    if (closestTraining != null)
                    {
                        return new ActWrapperTask(new GoTrainAct(this));    
                    }
                }

                // Otherwise, try to find a chair to sit in
                if (IdleTimer.HasTriggered && MathFunctions.RandEvent(0.25f))
                {
                    return new ActWrapperTask(new GoToChairAndSitAct(this)) { Priority = Task.PriorityType.Eventually, AutoRetry = false };
                }
                else if (IdleTimer.HasTriggered)
                {
                    IdleTimer.Reset(IdleTimer.TargetTimeSeconds);
                    return new ActWrapperTask(new WanderAct(this, 2, 0.5f + MathFunctions.Rand(-0.25f, 0.25f), 1.0f))
                    {
                        Priority = Task.PriorityType.Eventually
                    };
                }
                Physics.Velocity *= 0.0f;
                return null;
            }
            // If we have no more build orders, look for gather orders
            else if (GatherManager.VoxelOrders.Count == 0)
            {
                GatherManager.StockOrder order = GatherManager.StockOrders[0];
                GatherManager.StockOrders.RemoveAt(0);
                return new ActWrapperTask(new StockResourceAct(this, order.Resource))
                {
                    Priority = Task.PriorityType.Low
                };
            }
            // Otherwise handle build orders.
            else
            {
                List<Voxel> voxels = new List<Voxel>();
                List<VoxelType> types = new List<VoxelType>();
                foreach (GatherManager.BuildVoxelOrder order in GatherManager.VoxelOrders)
                {
                   voxels.Add(order.Voxel);
                    types.Add(order.Type);
                }

                GatherManager.VoxelOrders.Clear();
                return new ActWrapperTask(new BuildVoxelsAct(this, voxels, types))
                {
                    Priority = Task.PriorityType.Low,
                    AutoRetry = true
                };

            }
        }