예제 #1
0
        public bool IsValid(CraftDesignation designation)
        {
            if (IsDesignation(designation.Location))
            {
                World.ShowToolPopup("Something is already being built there!");
                return(false);
            }

            if (Faction.GetNearestRoomOfType(WorkshopRoom.WorkshopName, designation.Location.Position) == null)
            {
                World.ShowToolPopup("Can't build, no workshops!");
                return(false);
            }

            if (!Faction.HasResources(designation.ItemType.RequiredResources))
            {
                string neededResources = "";

                foreach (Quantitiy <Resource.ResourceTags> amount in designation.ItemType.RequiredResources)
                {
                    neededResources += "" + amount.NumResources + " " + amount.ResourceType.ToString() + " ";
                }

                World.ShowToolPopup("Not enough resources! Need " + neededResources + ".");
                return(false);
            }

            Voxel[] neighbors = new Voxel[4];
            foreach (CraftItem.CraftPrereq req in designation.ItemType.Prerequisites)
            {
                switch (req)
                {
                case CraftItem.CraftPrereq.NearWall:
                {
                    designation.Location.Chunk.Get2DManhattanNeighbors(neighbors,
                                                                       (int)designation.Location.GridPosition.X,
                                                                       (int)designation.Location.GridPosition.Y, (int)designation.Location.GridPosition.Z);

                    bool neighborFound = neighbors.Any(voxel => voxel != null && !voxel.IsEmpty);

                    if (!neighborFound)
                    {
                        World.ShowToolPopup("Must be built next to wall!");
                        return(false);
                    }

                    break;
                }

                case CraftItem.CraftPrereq.OnGround:
                {
                    Voxel below = new Voxel();
                    designation.Location.GetNeighbor(Vector3.Down, ref below);

                    if (below.IsEmpty)
                    {
                        World.ShowToolPopup("Must be built on solid ground!");
                        return(false);
                    }
                    break;
                }
                }
            }

            return(true);
        }