public override void Initialize() { Body closestItem = Agent.Faction.FindNearestItemWithTags("Bed", Agent.Position, true); if (Agent.Status.Energy.IsUnhappy() && closestItem != null) { closestItem.ReservedFor = Agent; Creature.AI.Blackboard.SetData("Bed", closestItem); Act unreserveAct = new Wrap(() => Creature.Unreserve("Bed")); Tree = new Sequence ( new GoToEntityAct(closestItem, Creature.AI), new TeleportAct(Creature.AI) {Location = closestItem.GetRotatedBoundingBox().Center() + new Vector3(-0.0f, 0.75f, -0.0f)}, new SleepAct(Creature.AI) { RechargeRate = 1.0f, Teleport = true, TeleportLocation = closestItem.GetRotatedBoundingBox().Center() + new Vector3(-0.0f, 0.75f, -0.0f) }, unreserveAct ) | unreserveAct; } else if(Agent.Status.Energy.IsUnhappy() && closestItem == null) { Creature.AI.AddThought(Thought.ThoughtType.SleptOnGround); Tree = new SleepAct(Creature.AI) { RechargeRate = 1.0f }; } else { Tree = null; } base.Initialize(); }
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(); }
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(); }
public override void Initialize() { bool hasAllResources = true; foreach(ResourceAmount resource in Resources) { if (!Creature.Inventory.Resources.HasResource(resource)) { hasAllResources = false; } } if(!hasAllResources) { Stockpile nearestStockpile = Agent.Faction.GetNearestStockpile(Agent.Position); if(nearestStockpile == null) { Tree = null; return; } else { Tree = new Sequence(new GoToZoneAct(Agent, nearestStockpile), new StashResourcesAct(Agent, Resources) ); } } else { Tree = new Wrap(AlwaysTrue); } base.Initialize(); }
public override void Initialize() { Body closestItem = Agent.Faction.FindNearestItemWithTags("Bed", Agent.Position, true); if (closestItem != null) { closestItem.ReservedFor = Agent; Creature.AI.Blackboard.SetData("Bed", closestItem); Act unreserveAct = new Wrap(() => Creature.Unreserve("Bed")); Tree = new Sequence ( new GoToEntityAct(closestItem, Creature.AI), new TeleportAct(Creature.AI) { Location = closestItem.GetRotatedBoundingBox().Center() + new Vector3(-0.0f, 0.75f, -0.0f) }, new SleepAct(Creature.AI) { HealRate = 1.0f, RechargeRate = 1.0f, Teleport = true, TeleportLocation = closestItem.GetRotatedBoundingBox().Center() + new Vector3(-0.0f, 0.75f, -0.0f), Type = SleepAct.SleepType.Heal }, unreserveAct ) | unreserveAct; } else { if (Agent.Faction == Agent.World.PlayerFaction) { Agent.World.MakeAnnouncement(String.Format("{0} passed out.", Agent.Stats.FullName)); } Tree = new SleepAct(Creature.AI) { HealRate = 0.1f, RechargeRate = 1.0f, Teleport = false, Type = SleepAct.SleepType.Heal }; } base.Initialize(); }
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; },
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(); }
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(); }
public override void Initialize() { var unreserveAct = new Wrap(UnReserve); var time = 3 * (ItemType.Craft_BaseCraftTime / Creature.AI.Stats.Intelligence); var getResources = new Select( new Domain(() => Des.HasResources || Des.ResourcesReservedFor != null, new Always(Status.Success)), new Domain(() => !Des.HasResources && (Des.ResourcesReservedFor == Agent || Des.ResourcesReservedFor == null), new Sequence( new Select( new Sequence( new Wrap(ReserveResources), new GetResourcesOfApparentType(Agent, RawMaterials) { BlackboardEntry = "stashed-materials" }), (new Wrap(UnReserve))), new Always(Status.Fail))), new Domain(() => Des.HasResources || Des.ResourcesReservedFor != null, new Always(Status.Success))); if (!String.IsNullOrEmpty(ItemType.Craft_Location)) { Tree = new Select(new Sequence( new Wrap(() => Creature.FindAndReserve(ItemType.Craft_Location, "craft-location")), new ClearBlackboardData(Agent, "ResourcesStashed"), getResources, new Select(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.Craft_Location); 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.Craft_BaseCraftTime; },
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(); }