Exemple #1
0
        public override void Initialize()
        {
            var tag      = Magical ? "Research" : "Train";
            Act trainAct = Magical ? new Wrap(DoMagicResearch)
            {
                Name = "Magic research"
            } as Act :
            new MeleeAct(Agent, "Train")
            {
                Training = true, Timeout = new Timer(10.0f, false)
            };
            Act unreserveAct = new Wrap(() => Creature.Unreserve(tag));

            Tree = new Sequence(
                new Wrap(() => Creature.FindAndReserve(tag, tag)),
                new Sequence
                (
                    new GoToTaggedObjectAct(Agent)
            {
                Tag = tag, Teleport = false, TeleportOffset = new Vector3(1, 0, 0), ObjectName = tag
            },
                    trainAct,
                    unreserveAct
                ) | new Sequence(unreserveAct, false)
                ) | new Sequence(unreserveAct, false);
            base.Initialize();
        }
Exemple #2
0
        public override void Initialize()
        {
            Act trainAct = Magical ? new Wrap(DoMagicResearch)
            {
                Name = "Magic research"
            } as Act : new AttackAct(Agent, "training-object")
            {
                Training = true, Timeout = new Timer(10.0f, false)
            };
            Act unreserveAct = new Wrap(() => Creature.Unreserve("training-object"));

            Tree = new Sequence(
                new Wrap(() => Creature.FindAndReserve(Magical ? "Research" : "Train", "training-object")),
                new Sequence
                (
                    new GoToTaggedObjectAct(Agent)
            {
                Teleport = false, TeleportOffset = new Vector3(1, 0, 0), ObjectBlackboardName = "training-object"
            },
                    trainAct,
                    unreserveAct
                ) | new Sequence(unreserveAct, false)
                ) | new Sequence(unreserveAct, false);
            base.Initialize();
        }
        public override void Initialize()
        {
            var unreserveAct = new Wrap(UnReserve);
            var time         = 3 * (ItemType.BaseCraftTime / Creature.AI.Stats.Intelligence);
            var getResources = new Select(new Domain(() => Des.HasResources || Des.ResourcesReservedFor != null, true),
                                          new Domain(() => !Des.HasResources && (Des.ResourcesReservedFor == Agent || Des.ResourcesReservedFor == null),
                                                     new Sequence(
                                                         new Wrap(ReserveResources),
                                                         new GetResourcesOfApparentType(Agent, RawMaterials)
            {
                BlackboardEntry = "stashed-materials"
            })
                                                     | (new Wrap(UnReserve))
                                                     & false),
                                          new Domain(() => Des.HasResources || Des.ResourcesReservedFor != null, true));

            if (!String.IsNullOrEmpty(ItemType.CraftLocation))
            {
                Tree = new Sequence(
                    new Wrap(() => Creature.FindAndReserve(ItemType.CraftLocation, "craft-location")),
                    new ClearBlackboardData(Agent, "ResourcesStashed"),
                    getResources,
                    new Domain(ResourceStateValid,
                               new Sequence(
                                   ActHelper.CreateEquipmentCheckAct(Agent, "Tool", ActHelper.EquipmentFallback.AllowDefault, "Hammer"),
                                   new GoToTaggedObjectAct(Agent)
                {
                    Teleport             = true,
                    TeleportOffset       = new Vector3(0.5f, 0.0f, 0),
                    ObjectBlackboardName = "craft-location",
                    CheckForOcclusion    = true
                },
                                   new Wrap(() => DestroyResources(() => Agent.Position + MathFunctions.RandVector3Cube() * 0.5f)),
                                   new Wrap(WaitForResources)
                {
                    Name = "Wait for resources."
                },
                                   new Wrap(() => Creature.HitAndWait(true,
                                                                      () => 1.0f,         // Max Progress
                                                                      () => Des.Progress, // Current Progress
                                                                      () =>
                {                                                                         // Increment Progress
                    var location = Creature.AI.Blackboard.GetData <GameComponent>(ItemType.CraftLocation);

                    float workstationBuff = 1.0f;
                    if (location != null)
                    {
                        Creature.Physics.Face(location.Position);
                        if (location.GetComponent <SteamPipes.BuildBuff>().HasValue(out var buff))
                        {
                            workstationBuff = buff.GetBuffMultiplier();
                        }
                    }

                    // Todo: Account for environment buff & 'anvil' buff.

                    Des.Progress += (Creature.Stats.BuildSpeed * workstationBuff) / ItemType.BaseCraftTime;
                },
Exemple #4
0
        public override void Initialize()
        {
            Creature.OverrideCharacterMode = false;

            Tree = new Sequence(new ClearBlackboardData(Creature.AI, "Grave"),
                                new Wrap(() => Creature.FindAndReserve("Grave", "Grave")),
                                new GoToTaggedObjectAct(Creature.AI)
            {
                Tag = "Grave", Teleport = false, TeleportOffset = new Vector3(1.0f, 0.0f, 0), ObjectName = "Grave"
            },
                                new Wrap(WaitUntilBored),
                                new Wrap(() => Creature.Unreserve("Grave"))) | new Wrap(() => Creature.Unreserve("Grave"));
            base.Initialize();
        }
Exemple #5
0
        public override void Initialize()
        {
            Creature.OverrideCharacterMode = false;

            Tree = new Sequence(new ClearBlackboardData(Creature.AI, "Chair"),
                                new Wrap(() => Creature.FindAndReserve("Chair", "Chair")),
                                new GoToTaggedObjectAct(Creature.AI)
            {
                Tag = "Chair", Teleport = true, TeleportOffset = new Vector3(0, 0.1f, 0), ObjectName = "Chair", CheckForOcclusion = false
            },
                                new Wrap(WaitUntilBored),
                                new Wrap(() => Creature.Unreserve("Chair"))) | new Wrap(() => Creature.Unreserve("Chair"));
            base.Initialize();
        }
        public override void Initialize()
        {
            Creature.OverrideCharacterMode = false;

            Tree = new Domain(() => !Agent.IsDead && !Agent.Creature.Stats.IsAsleep,
                              new Sequence(new ClearBlackboardData(Creature.AI, "reserved-chair"),
                                           new Wrap(() => Creature.FindAndReserve("Chair", "reserved-chair")),
                                           new Domain(ValidateSit, new Sequence(
                                                          new GoToTaggedObjectAct(Creature.AI)
            {
                Teleport       = true,
                TeleportOffset = new Vector3(0, 0.1f, 0), ObjectBlackboardName = "reserved-chair", CheckForOcclusion = false
            },
                                                          new Wrap(WaitUntilBored))),
                                           new Wrap(() => Creature.Unreserve("reserved-chair")))) | new Wrap(() => Creature.Unreserve("reserved-chair"));
            base.Initialize();
        }
Exemple #7
0
        public override void Initialize()
        {
            Act unreserveAct = new Wrap(() => Creature.Unreserve("Research"));

            Tree = new Sequence(
                new Wrap(() => Creature.FindAndReserve("Research", "Research")),
                new Sequence
                (
                    new GoToTaggedObjectAct(Agent)
            {
                Tag = "Research", Teleport = false, TeleportOffset = new Vector3(1, 0, 0), ObjectName = "Research"
            },
                    new ResearchSpellAct(Agent, Spell),
                    unreserveAct
                ) | new Sequence(unreserveAct, false)
                ) | new Sequence(unreserveAct, false);
            base.Initialize();
        }
Exemple #8
0
        public override void Initialize()
        {
            Act unreserveAct = new Wrap(() => Creature.Unreserve("Train"));

            Tree = new Sequence(
                new Wrap(() => Creature.FindAndReserve("Train", "Train")),
                new Sequence
                (
                    new GoToTaggedObjectAct(Agent)
            {
                Tag = "Train", Teleport = false, TeleportOffset = new Vector3(1, 0, 0), ObjectName = "Train"
            },
                    new MeleeAct(Agent, "Train")
            {
                Training = true, Timeout = new Timer(10.0f, false)
            },
                    unreserveAct
                ) | new Sequence(unreserveAct, false)
                ) | new Sequence(unreserveAct, false);
            base.Initialize();
        }
Exemple #9
0
        public override void Initialize()
        {
            Act   unreserveAct = new Wrap(() => Creature.Unreserve("Anvil"));
            float time         = CraftLibrary.CraftItems[ItemType].BaseCraftTime / Creature.AI.Stats.BuffedInt;

            Tree = new Sequence(
                new Wrap(() => Creature.FindAndReserve("Anvil", "Anvil")),
                new GetResourcesAct(Agent, CraftLibrary.CraftItems[ItemType].RequiredResources),
                new Sequence
                (
                    new GoToTaggedObjectAct(Agent)
            {
                Tag = "Anvil", Teleport = false, TeleportOffset = new Vector3(1, 0, 0), ObjectName = "Anvil"
            },
                    new Wrap(() => WaitAndHit(time)),
                    new Wrap(DestroyResources),
                    unreserveAct,
                    new GoToVoxelAct(Voxel, PlanAct.PlanType.Adjacent, Agent),
                    new CreateCraftItemAct(Voxel, Creature.AI, ItemType)
                ) | new Sequence(unreserveAct, new Wrap(Creature.RestockAll), false)
                ) | new Sequence(unreserveAct, false);
            base.Initialize();
        }
        public override void Initialize()
        {
            Act   unreserveAct        = new Wrap(UnReserve);
            float time                = 3 * (Item.ItemType.BaseCraftTime / Creature.AI.Stats.Intelligence);
            bool  factionHasResources = Item.SelectedResources != null && Item.SelectedResources.Count > 0 && Creature.World.HasResources(Item.SelectedResources);
            Act   getResources        = null;

            if (Item.ExistingResource != null)
            {
                getResources = new Select(new Domain(() => Item.HasResources || Item.ResourcesReservedFor != null, true),
                                          new Domain(() => !Item.HasResources &&
                                                     (Item.ResourcesReservedFor == Agent || Item.ResourcesReservedFor == null),
                                                     new Select(
                                                         new Sequence(new Wrap(ReserveResources),
                                                                      new GetResourcesAct(Agent, new List <ResourceAmount>()
                {
                    new ResourceAmount(Item.ExistingResource)
                }),
                                                                      new Wrap(SetSelectedResources)),
                                                         new Sequence(new Wrap(UnReserve), Act.Status.Fail)
                                                         )
                                                     ),
                                          new Domain(() => Item.HasResources || Item.ResourcesReservedFor != null, true));
            }
            else if (!factionHasResources)
            {
                getResources = new Select(new Domain(() => Item.HasResources || Item.ResourcesReservedFor != null, true),
                                          new Domain(() => !Item.HasResources &&
                                                     (Item.ResourcesReservedFor == Agent || Item.ResourcesReservedFor == null),
                                                     new Select(
                                                         new Sequence(new Wrap(ReserveResources),
                                                                      new GetResourcesAct(Agent, Item.ItemType.RequiredResources),
                                                                      new Wrap(SetSelectedResources)),
                                                         new Sequence(new Wrap(UnReserve), Act.Status.Fail)
                                                         )
                                                     ),
                                          new Domain(() => Item.HasResources || Item.ResourcesReservedFor != null, true));
            }
            else
            {
                getResources = new Select(new Domain(() => Item.HasResources || Item.ResourcesReservedFor != null, true),
                                          new Domain(() => !Item.HasResources && (Item.ResourcesReservedFor == Agent || Item.ResourcesReservedFor == null),
                                                     new Sequence(new Wrap(ReserveResources), new GetResourcesAct(Agent, Item.SelectedResources)) | (new Wrap(UnReserve)) & false),
                                          new Domain(() => Item.HasResources || Item.ResourcesReservedFor != null, true));
            }

            if (Item.ItemType.Type == CraftItem.CraftType.Object)
            {
                Act buildAct = null;

                if (Item.ExistingResource != null)
                {
                    buildAct = new Always(Status.Success);
                }
                else
                {
                    buildAct = new Wrap(() => Creature.HitAndWait(true, () => 1.0f,
                                                                  () => Item.Progress, () => Item.Progress += Creature.Stats.BuildSpeed / Item.ItemType.BaseCraftTime, // Todo: Account for creature debuffs, environment buffs
                                                                  () => Item.Location.WorldPosition + Vector3.One * 0.5f, "Craft"))
                    {
                        Name = "Construct object."
                    };
                }

                Tree = new Domain(IsNotCancelled, new Sequence(
                                      new ClearBlackboardData(Agent, "ResourcesStashed"),
                                      getResources,
                                      new Sequence(new Domain(ResourceStateValid,
                                                              new Sequence(
                                                                  new GoToVoxelAct(Voxel, PlanAct.PlanType.Adjacent, Agent),
                                                                  new Wrap(() => DestroyResources(() => Item.Location.WorldPosition)),
                                                                  new Wrap(WaitForResources)
                {
                    Name = "Wait for resources."
                },
                                                                  buildAct,
                                                                  new CreateCraftItemAct(Voxel, Creature.AI, Item)
                                                                  )
                                                              ))
                                      )) |
                       new Sequence(new Wrap(Creature.RestockAll), unreserveAct, false);
            }
            else if (Item.ItemType.Type == CraftItem.CraftType.Resource)
            {
                if (!String.IsNullOrEmpty(Item.ItemType.CraftLocation))
                {
                    Tree = new Sequence(
                        new Wrap(() => Creature.FindAndReserve(Item.ItemType.CraftLocation, Item.ItemType.CraftLocation)),
                        new ClearBlackboardData(Agent, "ResourcesStashed"),
                        getResources,
                        new Domain(ResourceStateValid,
                                   new Sequence(
                                       new GoToTaggedObjectAct(Agent)
                    {
                        Tag               = Item.ItemType.CraftLocation,
                        Teleport          = true,
                        TeleportOffset    = new Vector3(0.5f, 0.0f, 0),
                        ObjectName        = Item.ItemType.CraftLocation,
                        CheckForOcclusion = true
                    },
                                       new Wrap(() => DestroyResources(() => Agent.Position + MathFunctions.RandVector3Cube() * 0.5f)),
                                       new Wrap(WaitForResources)
                    {
                        Name = "Wait for resources."
                    },
                                       new Wrap(() => MaybeCreatePreviewBody(Item.SelectedResources)),
                                       new Wrap(() => Creature.HitAndWait(true,
                                                                          () => 1.0f,          // Max Progress
                                                                          () => Item.Progress, // Current Progress
                                                                          () => {              // Increment Progress
                        var location          = Creature.AI.Blackboard.GetData <GameComponent>(Item.ItemType.CraftLocation);
                        float workstationBuff = 1.0f;
                        if (location != null)
                        {
                            Creature.Physics.Face(location.Position);
                            if (Item.PreviewResource != null)
                            {
                                Item.PreviewResource.LocalPosition = location.Position + Vector3.Up * 0.25f;
                            }
                            if (location.GetComponent <SteamPipes.BuildBuff>().HasValue(out var buff))
                            {
                                workstationBuff = buff.GetBuffMultiplier();
                            }
                        }

                        // Todo: Account for environment buff & 'anvil' buff.

                        Item.Progress += (Creature.Stats.BuildSpeed * workstationBuff) / Item.ItemType.BaseCraftTime;
                    },
Exemple #11
0
        public override void Initialize()
        {
            Act   unreserveAct = new Wrap(() => Creature.Unreserve(ItemType.CraftLocation));
            float time         = ItemType.BaseCraftTime / Creature.AI.Stats.BuffedInt;
            Act   getResources = null;

            if (ItemType.SelectedResources == null || ItemType.SelectedResources.Count == 0)
            {
                getResources = new GetResourcesAct(Agent, ItemType.RequiredResources);
            }
            else
            {
                getResources = new GetResourcesAct(Agent, ItemType.SelectedResources);
            }

            if (ItemType.Type == CraftItem.CraftType.Object)
            {
                Tree = new Sequence(
                    new Wrap(() => Creature.FindAndReserve(ItemType.CraftLocation, ItemType.CraftLocation)),
                    getResources,
                    new Sequence
                    (
                        new GoToTaggedObjectAct(Agent)
                {
                    Tag            = ItemType.CraftLocation,
                    Teleport       = false,
                    TeleportOffset = new Vector3(1, 0, 0),
                    ObjectName     = ItemType.CraftLocation
                },
                        new Wrap(() => WaitAndHit(time)),
                        new Wrap(DestroyResources),
                        unreserveAct,
                        new GoToVoxelAct(Voxel, PlanAct.PlanType.Adjacent, Agent),
                        new CreateCraftItemAct(Voxel, Creature.AI, ItemType.Name)
                    ) | new Sequence(unreserveAct, new Wrap(Creature.RestockAll), false)
                    ) | new Sequence(unreserveAct, false);
            }
            else
            {
                Tree = new Sequence(
                    new Wrap(() => Creature.FindAndReserve(ItemType.CraftLocation, ItemType.CraftLocation)),
                    getResources,
                    new Sequence
                    (
                        new GoToTaggedObjectAct(Agent)
                {
                    Tag            = ItemType.CraftLocation,
                    Teleport       = false,
                    TeleportOffset = new Vector3(1, 0, 0),
                    ObjectName     = ItemType.CraftLocation
                },
                        new Wrap(() => WaitAndHit(time)),
                        new Wrap(DestroyResources),
                        unreserveAct,
                        new Wrap(CreateResources),
                        new Wrap(Creature.RestockAll)
                    ) | new Sequence(unreserveAct, new Wrap(Creature.RestockAll), false)
                    ) | new Sequence(unreserveAct, false);
            }
            base.Initialize();
        }
Exemple #12
0
        public override void Initialize()
        {
            Act   unreserveAct = new Wrap(UnReserve);
            float time         = 3 * (Item.ItemType.BaseCraftTime / Creature.AI.Stats.BuffedInt);
            Act   getResources = null;

            if (Item.SelectedResources == null || Item.SelectedResources.Count == 0)
            {
                getResources = new Select(new Domain(() => Item.HasResources || Item.ResourcesReservedFor != null, true),
                                          new Domain(() => !Item.HasResources && (Item.ResourcesReservedFor == Agent || Item.ResourcesReservedFor == null),
                                                     new Sequence(new Wrap(ReserveResources), new GetResourcesAct(Agent, Item.ItemType.RequiredResources))),
                                          new Domain(() => Item.HasResources || Item.ResourcesReservedFor != null, true));
            }
            else
            {
                getResources = new Select(new Domain(() => Item.HasResources || Item.ResourcesReservedFor != null, true),
                                          new Domain(() => !Item.HasResources && (Item.ResourcesReservedFor == Agent || Item.ResourcesReservedFor == null),
                                                     new Sequence(new Wrap(ReserveResources), new GetResourcesAct(Agent, Item.SelectedResources))),
                                          new Domain(() => Item.HasResources || Item.ResourcesReservedFor != null, true));
            }

            if (Item.ItemType.Type == CraftItem.CraftType.Object)
            {
                if (!String.IsNullOrEmpty(Item.ItemType.CraftLocation))
                {
                    Tree = new Domain(IsNotCancelled, new Sequence(
                                          new Wrap(() => Creature.FindAndReserve(Item.ItemType.CraftLocation, Item.ItemType.CraftLocation)),
                                          getResources,
                                          new Domain(ResourceStateValid, new Sequence
                                                     (
                                                         new GoToTaggedObjectAct(Agent)
                    {
                        Tag               = Item.ItemType.CraftLocation,
                        Teleport          = true,
                        TeleportOffset    = new Vector3(0.5f, 0.0f, 0),
                        ObjectName        = Item.ItemType.CraftLocation,
                        CheckForOcclusion = true
                    },
                                                         new Wrap(() => DestroyResources(Item.Location.WorldPosition)),
                                                         new Wrap(WaitForResources)
                    {
                        Name = "Wait for resources."
                    },
                                                         new Wrap(() => Creature.HitAndWait(true, () => 1.0f,
                                                                                            () => Item.Progress, () => Item.Progress += Creature.Stats.BuildSpeed / Item.ItemType.BaseCraftTime,
                                                                                            () => Item.Location.WorldPosition + Vector3.One * 0.5f, "Craft", null, true)),
                                                         new CreateCraftItemAct(Voxel, Creature.AI, Item))),
                                          unreserveAct
                                          ) | new Sequence(unreserveAct, new Wrap(Creature.RestockAll), false)
                                      ) | new Sequence(unreserveAct, false);
                }
                else
                {
                    Tree = new Domain(IsNotCancelled, new Sequence(
                                          getResources,
                                          new Sequence(new Domain(ResourceStateValid,
                                                                  new Sequence(
                                                                      new GoToVoxelAct(Voxel, PlanAct.PlanType.Adjacent, Agent),
                                                                      new Wrap(() => DestroyResources(Item.Location.WorldPosition)),
                                                                      new Wrap(WaitForResources)
                    {
                        Name = "Wait for resources."
                    },
                                                                      new Wrap(() => Creature.HitAndWait(true, () => 1.0f,
                                                                                                         () => Item.Progress, () => Item.Progress += Creature.Stats.BuildSpeed / Item.ItemType.BaseCraftTime,
                                                                                                         () => Item.Location.WorldPosition + Vector3.One * 0.5f, "Craft"))
                    {
                        Name = "Construct object."
                    },
                                                                      new CreateCraftItemAct(Voxel, Creature.AI, Item)
                                                                      )
                                                                  ))
                                          )) |
                           new Sequence(new Wrap(Creature.RestockAll), unreserveAct, false);
                }
            }
            else
            {
                if (!String.IsNullOrEmpty(Item.ItemType.CraftLocation))
                {
                    Tree = new Sequence(
                        new Wrap(() => Creature.FindAndReserve(Item.ItemType.CraftLocation, Item.ItemType.CraftLocation)),
                        getResources,
                        new Domain(ResourceStateValid, new Sequence
                                   (
                                       new GoToTaggedObjectAct(Agent)
                    {
                        Tag               = Item.ItemType.CraftLocation,
                        Teleport          = true,
                        TeleportOffset    = new Vector3(0.5f, 0.0f, 0),
                        ObjectName        = Item.ItemType.CraftLocation,
                        CheckForOcclusion = true
                    },
                                       new Wrap(() => DestroyResources(Agent.Position + MathFunctions.RandVector3Cube() * 0.5f)),
                                       new Wrap(WaitForResources)
                    {
                        Name = "Wait for resources."
                    },
                                       new Wrap(() => Creature.HitAndWait(true, () => 1.0f,
                                                                          () => Item.Progress, () => Item.Progress += Creature.Stats.BuildSpeed / Item.ItemType.BaseCraftTime,
                                                                          () => Agent.Position, Noise))
                    {
                        Name = "Construct object."
                    },
                                       unreserveAct,
                                       new Wrap(CreateResources),
                                       new Wrap(Creature.RestockAll)
                                   )) | new Sequence(unreserveAct, new Wrap(Creature.RestockAll), false)
                        ) | new Sequence(unreserveAct, new Wrap(Creature.RestockAll), false);
                }
                else
                {
                    Tree = new Sequence(
                        getResources,
                        new Domain(ResourceStateValid, new Sequence(
                                       new Wrap(() => DestroyResources(Creature.Physics.Position + MathFunctions.RandVector3Cube() * 0.5f)),
                                       new Wrap(WaitForResources)
                    {
                        Name = "Wait for resources."
                    },
                                       new Wrap(() => Creature.HitAndWait(time, true, () => Creature.Physics.Position))
                    {
                        Name = "Construct object."
                    },
                                       new Wrap(CreateResources))
                                   )
                        ) | new Sequence(unreserveAct, new Wrap(Creature.RestockAll), false);
                }
            }
            base.Initialize();
        }