Beispiel #1
0
        public IEnumerable <Act.Status> RemoveAnimal(GameComponent animal)
        {
            if (!Animals.Contains(animal))
            {
                yield return(Act.Status.Fail);

                yield break;
            }
            Animals.Remove(animal);
            animal.GetComponent <CreatureAI>().ResetPositionConstraint();
            Species = animal.GetComponent <Creature>().Stats.CurrentClass.Name;
            yield return(Act.Status.Success);
        }
Beispiel #2
0
        public IEnumerable <Act.Status> AddAnimal(GameComponent animal, WorldManager World)
        {
            Animals.Add(animal);
            BoundingBox animalBounds = GetBoundingBox();

            animalBounds        = animalBounds.Expand(-0.25f);
            animalBounds.Max.Y += 2;
            animalBounds.Min.Y -= 0.25f;
            animal.GetComponent <Physics>().ReservedFor           = null;;
            animal.GetComponent <CreatureAI>().PositionConstraint = animalBounds;
            World.PersistentData.Designations.RemoveEntityDesignation(animal.GetComponent <Physics>(), DesignationType.Wrangle);
            yield return(Act.Status.Success);
        }
Beispiel #3
0
        public IEnumerable <Act.Status> RemoveAnimal(GameComponent animal)
        {
            if (!Animals.Contains(animal))
            {
                yield return(Act.Status.Fail);

                yield break;
            }

            Animals.Remove(animal);

            if (animal.GetComponent <CreatureAI>().HasValue(out var animalAI))
            {
                animalAI.ResetPositionConstraint();
            }

            if (animal.GetComponent <Creature>().HasValue(out var creature))
            {
                Species = creature.Stats.CurrentClass.Name;
            }

            yield return(Act.Status.Success);
        }
Beispiel #4
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);
        }