public override void Initialize()
        {
            GameComponent closestItem = Agent.Faction.FindNearestItemWithTags("Bed", Agent.Position, true, Agent);
            Zone          closestZone = Agent.World.FindNearestZone(Agent.Position);

            if (!Agent.Stats.Energy.IsSatisfied() && closestItem != null)
            {
                closestItem.ReservedFor = Agent;
                Creature.AI.Blackboard.SetData("Bed", closestItem);
                closestItem.ReservedFor = Agent;
                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.Stats.Energy.IsSatisfied() && closestItem == null && closestZone != null)
            {
                Creature.AddThought("I slept on the ground.", new TimeSpan(0, 8, 0, 0), -6.0f);

                Tree = new Sequence(new GoToZoneAct(Creature.AI, closestZone),
                                    new SleepAct(Creature.AI)
                {
                    RechargeRate = 1.0f
                });
            }
            else if (!Agent.Stats.Energy.IsSatisfied() && closestItem == null && closestZone == null)
            {
                Creature.AddThought("I slept on the ground.", new TimeSpan(0, 8, 0, 0), -6.0f);

                Tree = new SleepAct(Creature.AI)
                {
                    RechargeRate = 1.0f
                };
            }
            else
            {
                Tree = null;
            }
            base.Initialize();
        }
Esempio n. 2
0
        public IEnumerable <Act.Status> PlaceOnBed(GameComponent bed)
        {
            Ally.ResetPositionConstraint();
            var pos = bed.GetRotatedBoundingBox().Center() + Vector3.Up * 0.5f;

            Ally.Physics.LocalPosition = pos;
            Ally.PositionConstraint    = new BoundingBox(pos - new Vector3(0.5f, 0.0f, 0.5f), Agent.Position + new Vector3(0.5f, 0.5f, 0.5f));
            yield return(Act.Status.Success);
        }
        public override void Initialize()
        {
            GameComponent closestItem = Agent.Faction.FindNearestItemWithTags("Bed", Agent.Position, true, Agent);


            if (closestItem != null && !Creature.Stats.Health.IsCritical())
            {
                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.UserInterface.MakeWorldPopup(String.Format("{0} passed out.", Agent.Stats.FullName), Agent.Physics, -10, 10);
                    Agent.World.TaskManager.AddTask(new HealAllyTask(Agent)
                    {
                        Priority = TaskPriority.High
                    });
                }
                Tree = new SleepAct(Creature.AI)
                {
                    HealRate = 0.4f, RechargeRate = 1.0f, Teleport = false, Type = SleepAct.SleepType.Heal
                };
            }
            base.Initialize();
        }
Esempio n. 4
0
        public KillEntityAct(GameComponent entity, CreatureAI creature) :
            base(creature)
        {
            Entity = entity;
            Name   = "Kill Entity";

            // Get the closest structure that we might defend from.
            closestDefensiveStructure = creature.Faction.OwnedObjects.Where(b => !b.IsReserved && b.Tags.Contains("Defensive")).OrderBy(b => (b.Position - Entity.Position).LengthSquared()).FirstOrDefault();

            // Do not attempt to defend from faraway structures
            if (closestDefensiveStructure != null)
            {
                float distToStructure = (closestDefensiveStructure.Position - creature.Position).Length();
                float distToEntity    = (Entity.Position - creature.Position).Length();

                if (distToStructure > 1.5f * distToEntity || distToStructure > 20.0f)
                {
                    closestDefensiveStructure = null;
                }
            }

            PlanAct.PlanType planType = PlanAct.PlanType.Adjacent;
            float            radius   = 0.0f;

            if (creature.Creature.Attacks[0].Weapon.Mode == Weapon.AttackMode.Ranged)
            {
                planType = PlanAct.PlanType.Radius;
                radius   = creature.Creature.Attacks[0].Weapon.Range;
            }

            if (creature.Movement.IsSessile)
            {
                Tree =
                    new Domain(() => Verify(creature),
                               new Sequence
                               (
                                   new MeleeAct(Agent, entity)
                               ) | new Wrap(() => OnAttackEnd(creature))
                               );
            }
            else
            {
                if (closestDefensiveStructure == null || (closestDefensiveStructure.Position - creature.Position).Length() > 20.0f)
                {
                    Tree =
                        new Domain(() => Verify(creature),
                                   new Sequence
                                   (
                                       new GoToEntityAct(entity, creature)
                    {
                        MovingTarget = true,
                        PlanType     = planType,
                        Radius       = radius
                    } | new Wrap(() => OnAttackEnd(creature)),
                                       new MeleeAct(Agent, entity),
                                       new Wrap(() => OnAttackEnd(creature))
                                   ));
                }
                else
                {
                    closestDefensiveStructure.ReservedFor = creature;
                    Tree =
                        new Domain(() => Verify(creature),
                                   new Sequence
                                   (
                                       new GoToEntityAct(closestDefensiveStructure, creature)
                    {
                        PlanType = PlanAct.PlanType.Into,
                    } | new Wrap(() => OnAttackEnd(creature)),
                                       new TeleportAct(Creature.AI)
                    {
                        Location = closestDefensiveStructure.GetRotatedBoundingBox().Center(), Type = TeleportAct.TeleportType.Lerp
                    },
                                       new MeleeAct(Agent, entity)
                    {
                        DefensiveStructure = closestDefensiveStructure
                    },
                                       new Wrap(() => OnAttackEnd(creature))
                                   ));
                }
            }
        }
Esempio n. 5
0
        public static bool IsValidPlacement(
            VoxelHandle Location,
            ResourceType CraftType,
            WorldManager World,
            GameComponent PreviewBody,
            String Verb,
            String PastParticple)
        {
            if (CraftType == null)
            {
                return(false);
            }

            switch (CraftType.Placement_PlacementRequirement)
            {
            case ResourceType.PlacementRequirement.NearWall:
            {
                var neighborFound = VoxelHelpers.EnumerateManhattanNeighbors2D(Location.Coordinate)
                                    .Select(c => new VoxelHandle(World.ChunkManager, c))
                                    .Any(v => v.IsValid && !v.IsEmpty);

                if (!neighborFound)
                {
                    World.UserInterface.ShowTooltip("Must be " + PastParticple + " next to wall!");
                    return(false);
                }

                break;
            }

            case ResourceType.PlacementRequirement.OnGround:
            {
                var below = VoxelHelpers.GetNeighbor(Location, new GlobalVoxelOffset(0, -1, 0));

                if (!below.IsValid || below.IsEmpty)
                {
                    World.UserInterface.ShowTooltip("Must be " + PastParticple + " on solid ground!");
                    return(false);
                }
                break;
            }
            }

            if (PreviewBody != null)
            {
                // Just check for any intersecting body in octtree.

                var previewBox = PreviewBody.GetRotatedBoundingBox();
                var sensorBox  = previewBox;

                GenericVoxelListener sensor;
                if (PreviewBody.GetComponent <GenericVoxelListener>().HasValue(out sensor))
                {
                    sensorBox = sensor.GetRotatedBoundingBox();
                }

                if (Debugger.Switches.DrawToolDebugInfo)
                {
                    Drawer3D.DrawBox(sensorBox, Color.Yellow, 0.1f, false);
                }

                foreach (var intersectingObject in World.EnumerateIntersectingObjects(sensorBox, CollisionType.Static))
                {
                    if (Object.ReferenceEquals(intersectingObject, sensor))
                    {
                        continue;
                    }
                    var objectRoot = intersectingObject.GetRoot() as GameComponent;
                    if (objectRoot is WorkPile)
                    {
                        continue;
                    }
                    if (objectRoot == PreviewBody)
                    {
                        continue;
                    }
                    if (objectRoot.IsDead)
                    {
                        continue;
                    }
                    if (objectRoot != null && objectRoot.GetRotatedBoundingBox().Intersects(previewBox))
                    {
                        World.UserInterface.ShowTooltip("Can't " + Verb + " here: intersects " + objectRoot.Name);
                        return(false);
                    }
                }

                bool intersectsWall = VoxelHelpers.EnumerateCoordinatesInBoundingBox
                                          (PreviewBody.GetRotatedBoundingBox().Expand(-0.1f)).Any(
                    v =>
                {
                    var tvh = new VoxelHandle(World.ChunkManager, v);
                    return(tvh.IsValid && !tvh.IsEmpty);
                });

                var  current    = new VoxelHandle(World.ChunkManager, GlobalVoxelCoordinate.FromVector3(PreviewBody.Position));
                bool underwater = current.IsValid && current.LiquidType != LiquidType.None;

                if (underwater)
                {
                    World.UserInterface.ShowTooltip("Can't " + Verb + " here: underwater or in lava.");
                    return(false);
                }

                if (intersectsWall && CraftType.Placement_PlacementRequirement != ResourceType.PlacementRequirement.NearWall)
                {
                    World.UserInterface.ShowTooltip("Can't " + Verb + " here: intersects wall.");
                    return(false);
                }
            }
            World.UserInterface.ShowTooltip("");
            return(true);
        }