Exemplo n.º 1
0
        private static void InitializeIdleTasks()
        {
            if (IdleTasks == null)
            {
                IdleTasks = new List <IdleTask>();

                IdleTasks.Add(new IdleTask // Join dice game - actually should be checked before even looking for an idle task.
                {
                    Name            = "Join Gamble",
                    PreferWhenBored = true,
                    Chance          = () => 100.0f, // This is only available while a game is in progress... so make it highly likely.
                    Create          = (AI) =>
                    {
                        var task = new Scripting.GambleTask()
                        {
                            Priority = TaskPriority.High
                        };
                        if (task.IsFeasible(AI.Creature) == Feasibility.Feasible)
                        {
                            return(task);
                        }
                        return(null);
                    },
                    Available = (AI, World) => World.GamblingState.State == Scripting.Gambling.Status.Gaming ||
                                World.GamblingState.State == Scripting.Gambling.Status.WaitingForPlayers && World.GamblingState.Participants.Count > 0
                });

                IdleTasks.Add(new IdleTask
                {
                    Name            = "Go on a walk",
                    PreferWhenBored = true,
                    Chance          = () => GameSettings.Current.IdleBehavior_Walk,
                    Create          = (AI) =>
                    {
                        return(new ActWrapperTask(new LongWanderAct(AI)
                        {
                            PathLength = 20,
                            Radius = 10,
                            Name = "Go on a walk",
                            Is2D = true,
                            SpeedAdjust = 0.5f
                        })
                        {
                            AutoRetry = false,
                            Name = "Go on a walk.",
                            Priority = TaskPriority.High,
                            BoredomIncrease = GameSettings.Current.Boredom_Walk,
                            EnergyDecrease = GameSettings.Current.Energy_Refreshing,
                        });
                    }
                });

                IdleTasks.Add(new IdleTask
                {
                    Name            = "Binge drink",
                    PreferWhenBored = true,
                    Chance          = () => GameSettings.Current.IdleBehavior_Binge,
                    Create          = (AI) =>
                    {
                        return(new ActWrapperTask(
                                   new Repeat(
                                       new FindAndEatFoodAct(AI, true)
                        {
                            FoodTag = "Alcohol",
                            FallbackTag = "Alcohol"
                        },
                                       3, false)
                        {
                            Name = "Binge drink."
                        })
                        {
                            Name = "Binge drink.",
                            Priority = TaskPriority.High,
                            BoredomIncrease = GameSettings.Current.Boredom_Eat,
                            EnergyDecrease = GameSettings.Current.Energy_Restful,
                        });
                    },
                    Available = (AI, World) => World.GetResourcesWithTag("Alcohol").Count > 0
                });

                IdleTasks.Add(new IdleTask
                {
                    Name            = "Binge eat",
                    PreferWhenBored = true,
                    Chance          = () => GameSettings.Current.IdleBehavior_Binge,
                    Create          = (AI) =>
                    {
                        return(new ActWrapperTask(new Repeat(new FindAndEatFoodAct(AI, true), 3, false)
                        {
                            Name = "Binge eat."
                        })
                        {
                            Name = "Binge eat.",
                            Priority = TaskPriority.High,
                            BoredomIncrease = GameSettings.Current.Boredom_Eat,
                            EnergyDecrease = GameSettings.Current.Energy_Restful,
                        });
                    },
                    Available = (AI, World) => !AI.Stats.Hunger.IsSatisfied()
                });

                IdleTasks.Add(new IdleTask
                {
                    Name            = "Relax",
                    PreferWhenBored = true,
                    Chance          = () => GameSettings.Current.IdleBehavior_Relax,
                    Create          = (AI) =>
                    {
                        return(new ActWrapperTask(new GoToChairAndSitAct(AI)
                        {
                            SitTime = 15,
                            Name = "Relax."
                        })
                        {
                            Name = "Relax.",
                            Priority = TaskPriority.High,
                            BoredomIncrease = GameSettings.Current.Boredom_Sleep,
                            EnergyDecrease = GameSettings.Current.Energy_Restful
                        });
                    }
                });

                IdleTasks.Add(new IdleTask
                {
                    Name            = "Start Dice Game",
                    PreferWhenBored = true,
                    Chance          = () => GameSettings.Current.IdleBehavior_Gamble,
                    Create          = (AI) =>
                    {
                        var task = new Scripting.GambleTask()
                        {
                            Priority = TaskPriority.High
                        };
                        if (task.IsFeasible(AI.Creature) == Feasibility.Feasible)
                        {
                            return(task);
                        }
                        return(null);
                    },
                    Available = (AI, world) => AI.Stats.Boredom.IsDissatisfied()
                });

                IdleTasks.Add(new IdleTask
                {
                    Name            = "Heal Allies",
                    PreferWhenBored = true,
                    Chance          = () => GameSettings.Current.IdleBehavior_Heal,
                    Create          = (AI) =>
                    {
                        var minion = AI.Faction.Minions.FirstOrDefault(m => m != AI && !m.Stats.Health.IsSatisfied());
                        if (minion != null)
                        {
                            return(new MagicHealAllyTask(minion));
                        }
                        return(null);
                    },
                    Available = (AI, world) => AI.Stats.CurrentLevel.HealingPower > 0 && AI.Faction.Minions.Any(minion => !minion.Creature.Stats.Health.IsSatisfied())
                });

                IdleTasks.Add(new IdleTask
                {
                    Name            = "Craft",
                    PreferWhenBored = true,
                    Chance          = () => GameSettings.Current.IdleBehavior_Craft,
                    Create          = (AI) =>
                    {
                        if (Library.GetRandomApplicableCraftable(AI.Faction, AI.World).HasValue(out var item))
                        {
                            var resources = new List <Resource>();
                            var allow     = true;
                            foreach (var resource in item.RequiredResources)
                            {
                                var available = AI.World.GetResourcesWithTag(resource.Tag);
                                if (available.Count == 0)
                                {
                                    allow = false;
                                }
                                else
                                {
                                    resources.Add(Datastructures.SelectRandom(available));
                                }
                            }

                            if (allow && resources.Count > 0)
                            {
                                return new CraftResourceTask(item, 1, 1, resources.Select(r => new ResourceApparentTypeAmount(r.DisplayName, 1)).ToList())
                                {
                                    IsAutonomous = true, Priority = TaskPriority.Low
                                }
                            }
                            ;
                        }

                        return(null);
                    },
                    Available = (AI, World) => GameSettings.Current.AllowIdleCrafting && AI.Stats.IsTaskAllowed(TaskCategory.CraftItem)
                });

                IdleTasks.Add(new IdleTask
                {
                    Name            = "Train",
                    PreferWhenBored = true,
                    Chance          = () => GameSettings.Current.IdleBehavior_Train,
                    Create          = (AI) =>
                    {
                        var closestTraining = AI.Faction.FindNearestItemWithTags("Train", AI.Position, true, AI);
                        if (closestTraining != null)
                        {
                            return new ActWrapperTask(new GoTrainAct(AI))
                            {
                                Name = "train", ReassignOnDeath = false, Priority = TaskPriority.Medium
                            }
                        }
                        ;
                        return(null);
                    },
                    Available = (AI, World) => AI.Stats.IsTaskAllowed(TaskCategory.Attack)
                });
Exemplo n.º 2
0
        private Task SatisfyBoredom()
        {
            if (World.GamblingState.State == Scripting.Gambling.Status.Gaming ||
                World.GamblingState.State == Scripting.Gambling.Status.WaitingForPlayers && World.GamblingState.Participants.Count > 0)
            {
                var task = new Scripting.GambleTask()
                {
                    Priority = TaskPriority.High
                };
                if (task.IsFeasible(Creature) == Feasibility.Feasible)
                {
                    return(task);
                }
            }

            switch (MathFunctions.RandInt(0, 5))
            {
            case 0:
            {
                return(new ActWrapperTask(new LongWanderAct(this)
                    {
                        PathLength = 50,
                        Radius = 30,
                        Name = "Go on a walk",
                        Is2D = true
                    })
                    {
                        Name = "Go on a walk.",
                        Priority = TaskPriority.High,
                        BoredomIncrease = GameSettings.Default.Boredom_Walk,
                        EnergyDecrease = GameSettings.Default.Energy_Refreshing,
                    });
            }

            case 1:
            {
                if (World.ListResourcesWithTag(Resource.ResourceTags.Alcohol).Count > 0)
                {
                    return new ActWrapperTask(
                        new Repeat(
                            new FindAndEatFoodAct(this, true)
                        {
                            FoodTag     = Resource.ResourceTags.Alcohol,
                            FallbackTag = Resource.ResourceTags.Alcohol
                        },
                            3, false)
                        {
                            Name = "Binge drink."
                        })
                           {
                               Name            = "Binge drink.",
                               Priority        = TaskPriority.High,
                               BoredomIncrease = GameSettings.Default.Boredom_Eat,
                               EnergyDecrease  = GameSettings.Default.Energy_Refreshing,
                           }
                }
                ;

                if (!Stats.Hunger.IsSatisfied())
                {
                    return new ActWrapperTask(new Repeat(new FindAndEatFoodAct(this, true), 3, false)
                        {
                            Name = "Binge eat."
                        })
                           {
                               Name            = "Binge eat.",
                               Priority        = TaskPriority.High,
                               BoredomIncrease = GameSettings.Default.Boredom_Eat,
                               EnergyDecrease  = GameSettings.Default.Energy_Refreshing
                           }
                }
                ;

                return(ActOnIdle());
            }

            case 2:
            {
                return(new ActWrapperTask(new GoToChairAndSitAct(this)
                    {
                        SitTime = 60,
                        Name = "Relax."
                    })
                    {
                        Name = "Relax.",
                        Priority = TaskPriority.High,
                        BoredomIncrease = GameSettings.Default.Boredom_Sleep,
                        EnergyDecrease = GameSettings.Default.Energy_Restful
                    });
            }

            case 3:
            {
                var task = new Scripting.GambleTask()
                {
                    Priority = TaskPriority.High
                };
                if (task.IsFeasible(Creature) == Feasibility.Feasible)
                {
                    return(task);
                }

                break;
            }

            case 4:
            {
                return(ActOnIdle());
            }
            }

            return(ActOnIdle());
        }