Ejemplo n.º 1
0
        public override void Initialize()
        {
            Body closestItem = Agent.Faction.FindNearestItemWithTags("Bed", Agent.Position, true, Agent);
            Zone closestZone = Agent.Faction.GetNearestRoom(Agent.Position);

            if (!Agent.Status.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.Status.Energy.IsSatisfied() && closestItem == null && closestZone != null)
            {
                Creature.AddThought(Thought.ThoughtType.SleptOnGround);

                Tree = new Sequence(new GoToZoneAct(Creature.AI, closestZone),
                                    new SleepAct(Creature.AI)
                {
                    RechargeRate = 1.0f
                });
            }
            else if (!Agent.Status.Energy.IsSatisfied() && closestItem == null && closestZone == null)
            {
                Creature.AddThought(Thought.ThoughtType.SleptOnGround);

                Tree = new SleepAct(Creature.AI)
                {
                    RechargeRate = 1.0f
                };
            }
            else
            {
                Tree = null;
            }
            base.Initialize();
        }
Ejemplo n.º 2
0
        public IEnumerable <Act.Status> PlaceOnBed(Body 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);
        }
Ejemplo n.º 3
0
        public override void Initialize()
        {
            Body closestItem = Agent.Faction.FindNearestItemWithTags("Bed", Agent.Position, true, Agent);


            if (closestItem != null && !Creature.Status.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.MakeWorldPopup(String.Format("{0} passed out.", Agent.Stats.FullName), Agent.Physics, -10, 10);
                    Agent.World.Master.TaskManager.AddTask(new HealAllyTask(Agent)
                    {
                        Priority = Task.PriorityType.High
                    });
                }
                Tree = new SleepAct(Creature.AI)
                {
                    HealRate = 0.1f, RechargeRate = 1.0f, Teleport = false, Type = SleepAct.SleepType.Heal
                };
            }
            base.Initialize();
        }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
        public static bool IsValidPlacement(
            VoxelHandle Location,
            CraftItem CraftType,
            GameMaster Player,
            Body PreviewBody,
            String Verb,
            String PastParticple)
        {
            if (CraftType == null)
            {
                return(false);
            }

            if (!String.IsNullOrEmpty(CraftType.CraftLocation) &&
                Player.Faction.FindNearestItemWithTags(CraftType.CraftLocation, Location.WorldPosition, false, null) == null)
            {
                Player.World.ShowTooltip("Can't " + Verb + ", need " + CraftType.CraftLocation);
                return(false);
            }

            foreach (var req in CraftType.Prerequisites)
            {
                switch (req)
                {
                case CraftItem.CraftPrereq.NearWall:
                {
                    var neighborFound = VoxelHelpers.EnumerateManhattanNeighbors2D(Location.Coordinate)
                                        .Select(c => new VoxelHandle(Player.World.ChunkManager.ChunkData, c))
                                        .Any(v => v.IsValid && !v.IsEmpty);

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

                    break;
                }

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

                    if (!below.IsValid || below.IsEmpty)
                    {
                        Player.World.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;
                var sensor     = PreviewBody.GetComponent <GenericVoxelListener>();
                if (sensor != null)
                {
                    sensorBox = sensor.GetRotatedBoundingBox();
                }
                if (Debugger.Switches.DrawToolDebugInfo)
                {
                    Drawer3D.DrawBox(sensorBox, Color.Yellow, 0.1f, false);
                }

                foreach (var intersectingObject in Player.World.EnumerateIntersectingObjects(sensorBox, CollisionType.Static))
                {
                    if (Object.ReferenceEquals(intersectingObject, sensor))
                    {
                        continue;
                    }
                    var objectRoot = intersectingObject.GetRoot() as Body;
                    if (objectRoot is WorkPile)
                    {
                        continue;
                    }
                    if (objectRoot != null && objectRoot.GetRotatedBoundingBox().Intersects(previewBox))
                    {
                        Player.World.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(Player.World.ChunkManager.ChunkData, v);
                    return(tvh.IsValid && !tvh.IsEmpty);
                });
                var  current    = new VoxelHandle(Player.World.ChunkManager.ChunkData, GlobalVoxelCoordinate.FromVector3(PreviewBody.Position));
                bool underwater = current.IsValid && current.LiquidType != LiquidType.None;
                if (underwater)
                {
                    Player.World.ShowTooltip("Can't " + Verb + " here: underwater or in lava.");
                    return(false);
                }
                if (intersectsWall && !CraftType.Prerequisites.Contains(CraftItem.CraftPrereq.NearWall))
                {
                    Player.World.ShowTooltip("Can't " + Verb + " here: intersects wall.");
                    return(false);
                }
            }
            Player.World.ShowTooltip("");
            return(true);
        }
Ejemplo n.º 6
0
        public KillEntityAct(Body 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].Mode == Attack.AttackMode.Ranged)
            {
                planType = PlanAct.PlanType.Radius;
                radius   = creature.Creature.Attacks[0].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))
                                   ));
                }
            }
        }