Esempio n. 1
0
    public void MoveToNearestOpenSlot()
    {
        List <GameObject> rooms = new List <GameObject>(GameObject.FindGameObjectsWithTag("Rooms"));

        rooms.Sort(delegate(GameObject c1, GameObject c2){
            return(Vector3.Distance(this.transform.position, c1.transform.position).CompareTo
                       ((Vector3.Distance(this.transform.position, c2.transform.position))));
        });

        foreach (GameObject go in rooms)
        {
            bool success = go.GetComponentInParent <RoomBehavior>().HasSpace();
            if (success)
            {
                Debug.Log("Found nearest location " + go);
                if (currentRoom != null)
                {
                    currentRoom.Unregister(gameObject);
                }
                //register with new room
                go.GetComponentInParent <RoomBehavior>().Register(gameObject);
                currentRoom = go.GetComponentInParent <RoomBehavior>();
                this.intermediatePoints.Add(this.navigationTarget.gameObject);
                break;
            }
        }
    }
Esempio n. 2
0
        /// <summary>
        /// Loads this instance.
        /// </summary>
        public void Load()
        {
            var areaRepository = new AreaRepository();

            // @@@ TODO: Fix hack: http://www.wheelmud.net/tabid/59/aft/1622/Default.aspx
            string areaNumber = this.Parent.ID.Replace("area/", string.Empty);
            long persistedAreaID = long.Parse(areaNumber);
            ICollection<RoomRecord> rooms = areaRepository.GetRoomsForArea(persistedAreaID);

            foreach (var roomRecord in rooms)
            {
                // @@@ TODO: Fix hack: http://www.wheelmud.net/tabid/59/aft/1622/Default.aspx
                var roomBehavior = new RoomBehavior()
                {
                    ID = roomRecord.ID,
                };
                var currRoom = new Thing(roomBehavior)
                {
                    Name = roomRecord.Name,
                    Description = roomRecord.Description,
                    ID = "room/" + roomRecord.ID,
                };

                // Load this room and it's children.
                roomBehavior.Load();
                this.Parent.Add(currRoom);
            }
        }
Esempio n. 3
0
    public void RegisterWithRoom(RoomBehavior rb)
    {
        if (rb == this.currentRoom)
        {
            return;
        }
        ;

        //check if new room has space
        if (rb.HasSpace())
        {
            //deregister with current room
            if (currentRoom != null)
            {
                currentRoom.Unregister(gameObject);
            }
            //register with new room
            rb.Register(gameObject);
            this.currentRoom        = rb;
            this.intermediatePoints = this.pathFinder.FindPath(this.gameObject, this.navigationTarget.gameObject);
        }
        else
        {
            Debug.Log("Target Room has no space");
        }
    }
Esempio n. 4
0
        /// <summary>Populate the private fields used by the Guards() and Execute() methods.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        private void PreprocessInput(ActionInput actionInput)
        {
            sender = actionInput.Controller;

            argCount = actionInput.Params.Length;

            // Location of the sender of the command.
            var location = sender.Thing.Parent;

            if (location.HasBehavior <RoomBehavior>())
            {
                room     = location.Behaviors.FindFirst <RoomBehavior>();
                roomName = room.Parent.Name;
                roomId   = room.Parent.Id;
            }

            // "visuals" with no arguments will default to "visuals show".
            if (argCount == 0)
            {
                command = "show";
            }

            // Name of the sub-command, i.e. "add", "remove", or "show".
            if (argCount > 0)
            {
                string firstParam = actionInput.Params[0].ToLower();
                switch (firstParam)
                {
                case "add":
                    command = "add";
                    break;

                case "remove":
                    command = "remove";
                    break;

                case "show":
                    command = "show";
                    break;

                default:
                    // command remains null, and there is no more processing to do.
                    return;
                }
            }

            // Name of the visual being added or removed.
            if (argCount > 1)
            {
                visualName = actionInput.Params[1].ToLower();
            }

            // The remainder of the command text is assumed to be the description.
            if (argCount > 2)
            {
                string tail = actionInput.Tail.Substring(command.Length).TrimStart();
                tail = tail.Substring(visualName.Length).TrimStart();
                visualDescription = tail;
            }
        }
Esempio n. 5
0
        /// <summary>Populate the private fields used by the Guards() and Execute() methods.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        private void PreprocessInput(ActionInput actionInput)
        {
            argCount = actionInput.Params.Length;

            // Location of the sender of the command.
            var location = actionInput.Actor.Parent;

            var foundRoomBehavior = location.FindBehavior <RoomBehavior>();

            if (foundRoomBehavior != null)
            {
                room     = foundRoomBehavior;
                roomName = room.Parent.Name;
                roomId   = room.Parent.Id;
            }

            // "visuals" with no arguments will default to "visuals show".
            if (argCount == 0)
            {
                command = "show";
            }

            // Name of the sub-command, i.e. "add", "remove", or "show".
            if (argCount > 0)
            {
                var firstParam = actionInput.Params[0].ToLower();
                switch (firstParam)
                {
                case "add":
                    command = "add";
                    break;

                case "remove":
                    command = "remove";
                    break;

                case "show":
                    command = "show";
                    break;

                default:
                    // command remains null, and there is no more processing to do.
                    return;
                }
            }

            // Name of the visual being added or removed.
            if (argCount > 1)
            {
                visualName = actionInput.Params[1].ToLower();
            }

            // The remainder of the command text is assumed to be the description.
            if (argCount > 2)
            {
                var tail = actionInput.Tail[command.Length..].TrimStart();
    private void RenderRoomBehaviorButtons()
    {
        roomBehaviorItems = new List <GameObject>();

        UnityEngine.Object buttonPrefab     = Resources.Load("UI/MenuLeft/ConstructionMenu/Button");
        Transform          contentTransform = this.transform.FindChild("Scroll View").FindChild("Viewport").FindChild("Content");

        BuildModeController buildModeController = WorldController.Instance.buildModeController;

        // For each furniture prototype in our world, create one instance
        // of the button to be clicked!
        foreach (string roomBehaviorKey in PrototypeManager.RoomBehavior.Keys)
        {
            if (PrototypeManager.RoomBehavior.Get(roomBehaviorKey).HasTypeTag("Non-buildable") && showAllFurniture == false)
            {
                continue;
            }

            GameObject gameObject = (GameObject)Instantiate(buttonPrefab);
            gameObject.transform.SetParent(contentTransform);
            roomBehaviorItems.Add(gameObject);

            RoomBehavior proto    = PrototypeManager.RoomBehavior.Get(roomBehaviorKey);
            string       objectId = roomBehaviorKey;

            gameObject.name = "Button - Designate " + objectId;

            gameObject.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(proto.LocalizationCode) };

            Button button = gameObject.GetComponent <Button>();

            button.onClick.AddListener(delegate
            {
                buildModeController.SetMode_DesignateRoomBehavior(objectId);
                menuLeft.CloseMenu();
            });

            // http://stackoverflow.com/questions/1757112/anonymous-c-sharp-delegate-within-a-loop
            string roomBehavior = roomBehaviorKey;
            LocalizationTable.CBLocalizationFilesChanged += delegate
            {
                gameObject.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(PrototypeManager.RoomBehavior.Get(roomBehavior).LocalizationCode) };
            };

            Image image = gameObject.transform.GetChild(0).GetComponentsInChildren <Image>().First();
            image.sprite = SpriteManager.GetSprite("RoomBehavior", roomBehaviorKey);
        }
    }
Esempio n. 7
0
    void Start()
    {
        rooms = new RoomBehavior[6];
        for (int i = 0; i < rooms.Length; i++)
        {
            rooms [i] = new RoomBehavior(i);
        }

        for (int i = 0; i < 5; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                roomGuys [i, j] = false;
            }
        }

        roomDsp = rooms;
    }
Esempio n. 8
0
    //private void ReceivedJoinResponse(Hashtable response)
    //{
    //    JoinLobbyResponseParameter param = new JoinLobbyResponseParameter();
    //    param.InitialParameterObjectFromHashtable(response);

    //    for (int i = 0; i < param.Rooms.Count; i++)
    //    {
    //        RoomInformation roomInfo = param.Rooms[i];

    //        int row = i / this.m_RoomsPerRow;
    //        int column = i % this.m_RoomsPerRow;

    //        Vector3 offset = new Vector3(column * this.m_ColumnDistance, -row * this.m_RowDistance, 0);
    //        GameObject room = GameObject.Instantiate(this.m_RoomPrefab) as GameObject;

    //        room.transform.position = this.m_InitialPosition + offset;
    //        RoomBehavior rb = room.GetComponent<RoomBehavior>();
    //        rb.RoomInformation = roomInfo;
    //        this.m_RoomManager.RegisterRoom(rb, roomInfo.RoomNo);
    //    }
    //}

    private void ReceivedJoinResponse(Hashtable response)
    {
        JoinLobbyResponseParameter param = new JoinLobbyResponseParameter();

        param.InitialParameterObjectFromHashtable(response);
        //maxVisibleItems = m_RoomsPerColumn * m_RoomsPerRow + m_RoomsPerRow;
        maxVisibleItems = param.Rooms.Count;
        for (int i = 0; i < param.Rooms.Count; ++i)
        {
            #region test
            RoomInformation roomInfo = param.Rooms[i];
            GameObject      room     = Instantiate(m_RoomPrefab) as GameObject;
            RoomBehavior    rb       = room.GetComponent <RoomBehavior>();
            rb.RoomInformation = roomInfo;
            this.m_RoomManager.RegisterRoom(rb, roomInfo.RoomNo);


            #endregion

            room.transform.parent = scrollableArea.contentContainer.transform;
            int row    = i / this.m_RoomsPerRow;
            int column = i % this.m_RoomsPerRow;
            room.transform.localPosition = new Vector3(column * this.m_ColumnDistance, -row * this.m_RowDistance, 0);

            //DoSetActive(room.transform, false);
            //unusedContentItems.Add(room.transform);
        }
        // SetItemCount(param.Rooms.Count, param.Rooms);
        #region  test
        int itemPerPage = m_RoomsPerRow * m_RoomsPerColumn;
        int pages       = Mathf.CeilToInt((float)maxVisibleItems / itemPerPage);
        scrollableArea.ContentLength = pages * this.m_RowDistance * m_RoomsPerColumn;


        #endregion
    }
Esempio n. 9
0
    public void DoBuild(Tile tile)
    {
        if (buildMode == BuildMode.ROOMBEHAVIOR)
        {
            string roomBehaviorType = buildModeType;

            if (tile.Room != null && WorldController.Instance.World.IsRoomBehaviorValidForRoom(roomBehaviorType, tile.Room))
            {
                RoomBehavior proto = PrototypeManager.RoomBehavior.Get(roomBehaviorType);
                tile.Room.DesignateRoomBehavior(proto.Clone());
            }
        }
        else if (buildMode == BuildMode.FURNITURE)
        {
            // Create the Furniture and assign it to the tile
            // Can we build the furniture in the selected tile?
            // Run the ValidPlacement function!
            string furnitureType = buildModeType;

            if (
                World.Current.FurnitureManager.IsPlacementValid(furnitureType, tile, CurrentPreviewRotation) &&
                World.Current.FurnitureManager.IsWorkSpotClear(furnitureType, tile) &&
                DoesFurnitureBuildJobOverlapExistingBuildJob(tile, furnitureType, CurrentPreviewRotation) == false)
            {
                // This tile position is valid for this furniture

                // Check if there is existing furniture in this tile. If so delete it.
                if (tile.Furniture != null)
                {
                    tile.Furniture.SetDeconstructJob();
                }

                // Create a job for it to be build
                Job job;

                Furniture   toBuildProto = PrototypeManager.Furniture.Get(furnitureType);
                OrderAction orderAction  = toBuildProto.GetOrderAction <Build>();
                if (orderAction != null)
                {
                    job = orderAction.CreateJob(tile, furnitureType);
                    if (useCratedObject)
                    {
                        // We want to use a crated furniture, so set requested items to crated version.
                        job.RequestedItems.Clear();
                        job.RequestedItems.Add(this.buildModeType, new ProjectPorcupine.Jobs.RequestedItem(this.buildModeType, 1));
                        useCratedObject = false;
                    }

                    // this is here so OrderAction can be used for utility as well as furniture
                    job.OnJobCompleted += (theJob) => World.Current.FurnitureManager.ConstructJobCompleted(theJob);
                }
                else
                {
                    UnityDebugger.Debugger.LogError("BuildModeController", "There is no furniture job prototype for '" + furnitureType + "'");
                    job             = new Job(tile, furnitureType, World.Current.FurnitureManager.ConstructJobCompleted, 0.1f, null, Job.JobPriority.High);
                    job.adjacent    = true;
                    job.Description = "job_build_" + furnitureType + "_desc";
                }

                Furniture furnitureToBuild = PrototypeManager.Furniture.Get(furnitureType).Clone();
                furnitureToBuild.SetRotation(CurrentPreviewRotation);
                job.buildablePrototype = furnitureToBuild;

                // Add the job to the queue or build immediately if in Dev mode
                if (SettingsKeyHolder.DeveloperMode)
                {
                    World.Current.FurnitureManager.PlaceFurniture(furnitureToBuild, job.tile);
                }
                else
                {
                    for (int x_off = tile.X; x_off < (tile.X + job.buildablePrototype.Width); x_off++)
                    {
                        for (int y_off = tile.Y; y_off < (tile.Y + job.buildablePrototype.Height); y_off++)
                        {
                            // FIXME: I don't like having to manually and explicitly set
                            // flags that prevent conflicts. It's too easy to forget to set/clear them!
                            Tile          offsetTile       = World.Current.GetTileAt(x_off, y_off, tile.Z);
                            HashSet <Job> pendingBuildJobs = WorldController.Instance.World.GetTileAt(x_off, y_off, tile.Z).PendingBuildJobs;
                            if (pendingBuildJobs != null)
                            {
                                // if the existing buildJobs furniture is replaceable by the current furnitureType,
                                // we can pretend it does not overlap with the new build

                                // We should only have 1 furniture building job per tile, so this should return that job and only that job
                                IEnumerable <Job> pendingFurnitureJob = pendingBuildJobs.Where(pendingJob => pendingJob.buildablePrototype.GetType() == typeof(Furniture));
                                if (pendingFurnitureJob.Count() == 1)
                                {
                                    pendingFurnitureJob.Single().CancelJob();
                                }
                            }

                            offsetTile.PendingBuildJobs.Add(job);
                            job.OnJobStopped += (theJob) => offsetTile.PendingBuildJobs.Remove(job);
                        }
                    }

                    World.Current.jobQueue.Enqueue(job);

                    // Let our workspot tile know it is reserved for us
                    World.Current.ReserveTileAsWorkSpot((Furniture)job.buildablePrototype, job.tile);
                }
            }
        }
        else if (buildMode == BuildMode.UTILITY)
        {
            // Create the Furniture and assign it to the tile
            // Can we build the furniture in the selected tile?
            // Run the ValidPlacement function!
            string utilityType = buildModeType;
            if (
                World.Current.UtilityManager.IsPlacementValid(utilityType, tile) &&
                DoesSameUtilityTypeAlreadyExist(utilityType, tile) == false &&
                DoesUtilityBuildJobOverlapExistingBuildJob(utilityType, tile) == false)
            {
                // This tile position is valid for this furniture

                // Create a job for it to be build
                Job job;

                Utility     toBuildProto = PrototypeManager.Utility.Get(utilityType);
                OrderAction orderAction  = toBuildProto.GetOrderAction <Build>();
                if (orderAction != null)
                {
                    job = orderAction.CreateJob(tile, utilityType);

                    // this is here so OrderAction can be used for utility as well as furniture
                    job.OnJobCompleted += (theJob) => World.Current.UtilityManager.ConstructJobCompleted(theJob);
                }
                else
                {
                    UnityDebugger.Debugger.LogError("BuildModeController", "There is no furniture job prototype for '" + utilityType + "'");
                    job             = new Job(tile, utilityType, World.Current.UtilityManager.ConstructJobCompleted, 0.1f, null, Job.JobPriority.High);
                    job.Description = "job_build_" + utilityType + "_desc";
                }

                job.buildablePrototype = PrototypeManager.Utility.Get(utilityType);

                // Add the job to the queue or build immediately if in dev mode
                if (SettingsKeyHolder.DeveloperMode)
                {
                    World.Current.UtilityManager.PlaceUtility(job.Type, job.tile, true);
                }
                else
                {
                    // FIXME: I don't like having to manually and explicitly set
                    // flags that preven conflicts. It's too easy to forget to set/clear them!
                    Tile offsetTile = World.Current.GetTileAt(tile.X, tile.Y, tile.Z);
                    offsetTile.PendingBuildJobs.Add(job);
                    job.OnJobStopped += (theJob) => offsetTile.PendingBuildJobs.Remove(job);

                    World.Current.jobQueue.Enqueue(job);
                }
            }
        }
        else if (buildMode == BuildMode.FLOOR)
        {
            // We are in tile-changing mode.
            ////t.Type = buildModeTile;

            TileType tileType = buildModeTile;

            if (
                tile.Type != tileType &&
                tile.Furniture == null &&
                tile.PendingBuildJobs.Count == 0 &&
                tileType.CanBuildHere(tile))
            {
                // This tile position is valid tile type

                // Create a job for it to be build
                Job buildingJob = tileType.BuildingJob;

                buildingJob.tile = tile;

                // Add the job to the queue or build immediately if in Dev mode
                if (SettingsKeyHolder.DeveloperMode)
                {
                    buildingJob.tile.SetTileType(buildingJob.JobTileType);
                }
                else
                {
                    buildingJob.OnJobStopped += (theJob) => theJob.tile.PendingBuildJobs.Remove(theJob);

                    WorldController.Instance.World.jobQueue.Enqueue(buildingJob);
                }
            }
        }
        else if (buildMode == BuildMode.DECONSTRUCT)
        {
            bool canDeconstructAll = SettingsKeyHolder.DeveloperMode;

            if (tile.Furniture != null && (canDeconstructAll || tile.Furniture.HasTypeTag("Non-deconstructible") == false))
            {
                // check if this is a WALL neighbouring a pressured and pressureless environment, and if so, bail
                if (IsTilePartOfPressuredRoom(tile))
                {
                    return;
                }

                tile.Furniture.SetDeconstructJob();
            }
            else if (tile.PendingBuildJobs != null && tile.PendingBuildJobs.Count > 0)
            {
                tile.PendingBuildJobs.Last().CancelJob();
            }
            else if (tile.Utilities.Count > 0)
            {
                tile.Utilities.Last().Value.SetDeconstructJob();
            }
        }
        else if (buildMode == BuildMode.MINE)
        {
            if (tile.Furniture != null)
            {
                Job  existingMineJob;
                bool hasMineJob = tile.Furniture.Jobs.HasJobWithPredicate(x => x.OrderName == typeof(Mine).Name, out existingMineJob);
                if (!hasMineJob)
                {
                    OrderAction mineAction = tile.Furniture.GetOrderAction <Mine>();
                    if (mineAction != null)
                    {
                        // check if this is a WALL neighbouring a pressured and pressureless environment, and if so, bail
                        if (IsTilePartOfPressuredRoom(tile))
                        {
                            return;
                        }

                        Job job = mineAction.CreateJob(tile, null);
                        if (SettingsKeyHolder.DeveloperMode)
                        {
                            // complete job right away, needs buildable
                            job.buildable = tile.Furniture;
                            job.DoWork(0);
                        }
                        else
                        {
                            tile.Furniture.Jobs.Add(job);
                        }
                    }
                }
            }
        }
        else
        {
            UnityDebugger.Debugger.LogError("BuildModeController", "UNIMPLEMENTED BUILD MODE");
        }
    }
Esempio n. 10
0
        /// <summary>Verifies that the proposed command can be performed by the acting entity.</summary>
        /// <param name="command">The issued command to be carried out.</param>
        /// <returns>A string defining why the permission was not given, else null if permission is given.</returns>
        public static string VerifyCommandPermission(ScriptingCommand command)
        {
            if (command.SecurityRole == SecurityRole.none)
            {
                // If you are debugging here after trying to set up your own action,
                // you probably forgot to assign an appropriate [ActionSecurity(...)]
                // attribute for your new GameAction class.
                return(string.Format("Nobody can use '{0}' right now!", command.Name));
            }

            Thing entity = command.ActionInput.Controller.Thing;

            if (entity == null)
            {
                return("You must exist before issuing commands!");
            }

            PlayerBehavior player = entity.Behaviors.FindFirst <PlayerBehavior>();

            if (player != null)
            {
                // @@@ TODO: Ascertain the ACTUAL player's specific permissions, so we can
                //     check for fullAdmin, fullBuilder, etc, instead of assuming just
                //     'SecurityRole.player'
                SecurityRole playerRoles = SecurityRole.player | SecurityRole.minorBuilder |
                                           SecurityRole.fullBuilder | SecurityRole.minorAdmin | SecurityRole.fullAdmin;

                // If any of the command's security roles and the player's security roles
                // overlap (such as the command is marked with 'minorBuilder' and the
                // player has the 'minorBuilder' flag) then we permit the command.
                if ((command.SecurityRole & playerRoles) != SecurityRole.none)
                {
                    return(null);
                }

                // Otherwise, this player does not have permission; we do not want to
                // check the mobile/item/room security role on players, so we're done.
                return(string.Format("You do not have permission to use '{0}' right now.", command.Name));
            }

            MobileBehavior mobile = entity.Behaviors.FindFirst <MobileBehavior>();

            if (mobile != null)
            {
                if ((command.SecurityRole & SecurityRole.mobile) != SecurityRole.none)
                {
                    return(null);
                }

                return(string.Format("A mobile can not use '{0}' right now!", command.Name));
            }

            RoomBehavior room = entity.Behaviors.FindFirst <RoomBehavior>();

            if (room != null)
            {
                if ((command.SecurityRole & SecurityRole.room) == SecurityRole.none)
                {
                    return(null);
                }

                return(string.Format("A room can not use '{0}' right now!", command.Name));
            }

            // @@@ For now, everything else which doesn't meet any above category will need the 'item' security
            //     role. (Do we need an ItemBehavior or is there something else relevant... CanPickupBehavior etc?)
            if ((command.SecurityRole & SecurityRole.item) != SecurityRole.none)
            {
                return(null);
            }

            return(string.Format("An item (or unrecognized entity) can not use '{0}' right now!", command.Name));
        }
    public void DoBuild(Tile tile)
    {
        if (buildMode == BuildMode.ROOMBEHAVIOR)
        {
            string roomBehaviorType = buildModeType;

            if (tile.Room != null && WorldController.Instance.World.IsRoomBehaviorValidForRoom(roomBehaviorType, tile.Room))
            {
                RoomBehavior proto = PrototypeManager.RoomBehavior.Get(roomBehaviorType);
                tile.Room.DesignateRoomBehavior(proto.Clone());
            }
        }
        else if (buildMode == BuildMode.FURNITURE)
        {
            // Create the Furniture and assign it to the tile
            // Can we build the furniture in the selected tile?
            // Run the ValidPlacement function!
            string furnitureType = buildModeType;

            if (
                World.Current.FurnitureManager.IsPlacementValid(furnitureType, tile, CurrentPreviewRotation) &&
                World.Current.FurnitureManager.IsWorkSpotClear(furnitureType, tile) &&
                DoesFurnitureBuildJobOverlapExistingBuildJob(tile, furnitureType, CurrentPreviewRotation) == false)
            {
                // This tile position is valid for this furniture

                // Check if there is existing furniture in this tile. If so delete it.
                if (tile.Furniture != null)
                {
                    tile.Furniture.SetDeconstructJob();
                }

                // Create a job for it to be build
                Job job;

                if (PrototypeManager.FurnitureConstructJob.Has(furnitureType))
                {
                    // Make a clone of the job prototype
                    job = PrototypeManager.FurnitureConstructJob.Get(furnitureType).Clone();

                    // Assign the correct tile.
                    job.tile = tile;
                }
                else
                {
                    Debug.ULogErrorChannel("BuildModeController", "There is no furniture job prototype for '" + furnitureType + "'");
                    job             = new Job(tile, furnitureType, World.Current.FurnitureManager.ConstructJobCompleted, 0.1f, null, Job.JobPriority.High);
                    job.adjacent    = true;
                    job.Description = "job_build_" + furnitureType + "_desc";
                }

                Furniture furnituteToBuild = PrototypeManager.Furniture.Get(furnitureType).Clone();
                furnituteToBuild.SetRotation(CurrentPreviewRotation);
                job.buildablePrototype = furnituteToBuild;

                // Add the job to the queue or build immediately if in Dev mode
                if (Settings.GetSetting("DialogBoxSettings_developerModeToggle", false))
                {
                    World.Current.FurnitureManager.PlaceFurniture(furnituteToBuild, job.tile);
                }
                else
                {
                    for (int x_off = tile.X; x_off < (tile.X + job.buildablePrototype.Width); x_off++)
                    {
                        for (int y_off = tile.Y; y_off < (tile.Y + job.buildablePrototype.Height); y_off++)
                        {
                            // FIXME: I don't like having to manually and explicitly set
                            // flags that prevent conflicts. It's too easy to forget to set/clear them!
                            Tile          offsetTile       = World.Current.GetTileAt(x_off, y_off, tile.Z);
                            HashSet <Job> pendingBuildJobs = WorldController.Instance.World.GetTileAt(x_off, y_off, tile.Z).PendingBuildJobs;
                            if (pendingBuildJobs != null)
                            {
                                // if the existing buildJobs furniture is replaceable by the current furnitureType,
                                // we can pretend it does not overlap with the new build

                                // We should only have 1 furniture building job per tile, so this should return that job and only that job
                                IEnumerable <Job> pendingFurnitureJob = pendingBuildJobs.Where(pendingJob => pendingJob.buildablePrototype.GetType() == typeof(Furniture));
                                if (pendingFurnitureJob.Count() == 1)
                                {
                                    pendingFurnitureJob.Single().CancelJob();
                                }
                            }

                            offsetTile.PendingBuildJobs.Add(job);
                            job.OnJobStopped += (theJob) => offsetTile.PendingBuildJobs.Remove(job);
                        }
                    }

                    World.Current.jobQueue.Enqueue(job);

                    // Let our workspot tile know it is reserved for us
                    World.Current.ReserveTileAsWorkSpot((Furniture)job.buildablePrototype, job.tile);
                }
            }
        }
        else if (buildMode == BuildMode.UTILITY)
        {
            // Create the Furniture and assign it to the tile
            // Can we build the furniture in the selected tile?
            // Run the ValidPlacement function!
            string utilityType = buildModeType;

            // TODO: Reimplement this later: DoesBuildJobOverlapExistingBuildJob(t, furnitureType) == false)
            if (
                World.Current.UtilityManager.IsPlacementValid(utilityType, tile) &&
                DoesSameUtilityTypeAlreadyExist(utilityType, tile) == false &&
                DoesUtilityBuildJobOverlapExistingBuildJob(utilityType, tile) == false)
            {
                // This tile position is valid for this furniture

                // Create a job for it to be build
                Job job;

                if (PrototypeManager.UtilityConstructJob.Has(utilityType))
                {
                    // Make a clone of the job prototype
                    job = PrototypeManager.UtilityConstructJob.Get(utilityType).Clone();

                    // Assign the correct tile.
                    job.tile = tile;
                }
                else
                {
                    Debug.ULogErrorChannel("BuildModeController", "There is no furniture job prototype for '" + utilityType + "'");
                    job             = new Job(tile, utilityType, World.Current.UtilityManager.ConstructJobCompleted, 0.1f, null, Job.JobPriority.High);
                    job.Description = "job_build_" + utilityType + "_desc";
                }

                job.buildablePrototype = PrototypeManager.Utility.Get(utilityType);

                // Add the job to the queue or build immediately if in dev mode
                if (Settings.GetSetting("DialogBoxSettings_developerModeToggle", false))
                {
                    World.Current.UtilityManager.PlaceUtility(job.Type, job.tile, true);
                }
                else
                {
                    // FIXME: I don't like having to manually and explicitly set
                    // flags that preven conflicts. It's too easy to forget to set/clear them!
                    Tile offsetTile = World.Current.GetTileAt(tile.X, tile.Y, tile.Z);
                    offsetTile.PendingBuildJobs.Add(job);
                    job.OnJobStopped += (theJob) => offsetTile.PendingBuildJobs.Remove(job);

                    World.Current.jobQueue.Enqueue(job);
                }
            }
        }
        else if (buildMode == BuildMode.FLOOR)
        {
            // We are in tile-changing mode.
            ////t.Type = buildModeTile;

            TileType tileType = buildModeTile;

            if (
                tile.Type != tileType &&
                tile.Furniture == null &&
                tile.PendingBuildJobs.Count == 0 &&
                tileType.CanBuildHere(tile))
            {
                // This tile position is valid tile type

                // Create a job for it to be build
                Job buildingJob = tileType.BuildingJob;

                buildingJob.tile = tile;

                // Add the job to the queue or build immediately if in Dev mode
                if (Settings.GetSetting("DialogBoxSettings_developerModeToggle", false))
                {
                    buildingJob.tile.SetTileType(buildingJob.JobTileType);
                }
                else
                {
                    buildingJob.OnJobStopped += (theJob) => theJob.tile.PendingBuildJobs.Remove(theJob);

                    WorldController.Instance.World.jobQueue.Enqueue(buildingJob);
                }
            }
        }
        else if (buildMode == BuildMode.DECONSTRUCT)
        {
            // TODO
            bool canDeconstructAll = Settings.GetSetting("DialogBoxSettings_developerModeToggle", false);
            if (tile.Furniture != null && (canDeconstructAll || tile.Furniture.HasTypeTag("Non-deconstructible") == false))
            {
                // check if this is a WALL neighbouring a pressured and pressureless environment, and if so, bail
                if (tile.Furniture.HasTypeTag("Wall"))
                {
                    Tile[] neighbors          = tile.GetNeighbours(); // diagOkay??
                    int    pressuredNeighbors = 0;
                    int    vacuumNeighbors    = 0;
                    foreach (Tile neighbor in neighbors)
                    {
                        if (neighbor != null && neighbor.Room != null)
                        {
                            if (neighbor.Room.IsOutsideRoom() || MathUtilities.IsZero(neighbor.Room.GetTotalGasPressure()))
                            {
                                vacuumNeighbors++;
                            }
                            else
                            {
                                pressuredNeighbors++;
                            }
                        }
                    }

                    if (vacuumNeighbors > 0 && pressuredNeighbors > 0)
                    {
                        Debug.ULogChannel("BuildModeController", "Someone tried to deconstruct a wall between a pressurized room and vacuum!");
                        return;
                    }
                }

                tile.Furniture.SetDeconstructJob();
            }
            else if (tile.PendingBuildJobs != null)
            {
                tile.PendingBuildJobs.Last().CancelJob();
            }
            else if (tile.Utilities.Count > 0)
            {
                tile.Utilities.Last().Value.SetDeconstructJob();
            }
        }
        else
        {
            Debug.ULogErrorChannel("BuildModeController", "UNIMPLEMENTED BUILD MODE");
        }
    }
Esempio n. 12
0
 public void RegisterRoom(RoomBehavior room, int roomNo)
 {
     this.m_Rooms.Add(roomNo, room);
     room.transform.parent = this.transform;
 }
Esempio n. 13
0
        /// <summary>
        /// Populate the private fields used by the Guards() and Execute() methods.
        /// </summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        private void PreprocessInput(ActionInput actionInput)
        {
            this.sender = actionInput.Controller;

            this.argCount = actionInput.Params.Length;

            // Location of the sender of the command.
            var location = this.sender.Thing.Parent;

            if (location.HasBehavior<RoomBehavior>())
            {
                this.room = location.Behaviors.FindFirst<RoomBehavior>();
                this.roomName = this.room.Parent.Name;
                this.roomId = this.room.Parent.ID;
            }

            // "visuals" with no arguments will default to "visuals show".
            if (this.argCount == 0)
            {
                this.command = "show";
            }

            // Name of the sub-command, i.e. "add", "remove", or "show".
            if (this.argCount > 0)
            {
                string firstParam = actionInput.Params[0].ToLower();
                switch (firstParam)
                {
                    case "add":
                        this.command = "add";
                        break;
                    case "remove":
                        this.command = "remove";
                        break;
                    case "show":
                        this.command = "show";
                        break;
                    default:
                        // this.command remains null, and there is no more processing to do.
                        return;
                }
            }

            // Name of the visual being added or removed.
            if (this.argCount > 1)
            {
                this.visualName = actionInput.Params[1].ToLower();
            }

            // The remainder of the command text is assumed to be the description.
            if (this.argCount > 2)
            {
                string tail = actionInput.Tail.Substring(this.command.Length).TrimStart();
                tail = tail.Substring(this.visualName.Length).TrimStart();
                this.visualDescription = tail;
            }
        }
Esempio n. 14
0
        /// <summary>Verifies that the proposed command can be performed by the acting entity.</summary>
        /// <param name="command">The issued command to be carried out.</param>
        /// <returns>A string defining why the permission was not given, else null if permission is given.</returns>
        public static string VerifyCommandPermission(ScriptingCommand command)
        {
            if (command.SecurityRole == SecurityRole.none)
            {
                // If you are debugging here after trying to set up your own action,
                // you probably forgot to assign an appropriate [ActionSecurity(...)]
                // attribute for your new GameAction class.
                return(string.Format("Nobody can use '{0}' right now!", command.Name));
            }

            Thing entity = command.ActionInput.Actor;

            if (entity == null)
            {
                return("You must exist before issuing commands!");
            }

            var user = entity.FindBehavior <UserControlledBehavior>();

            if (user != null)
            {
                // If any of the command security roles and the user security roles overlap (such as the command is
                // marked with 'minorBuilder' and the user has the 'minorBuilder' flag) then we permit the command.
                if ((command.SecurityRole & user.SecurityRoles) != SecurityRole.none)
                {
                    return(null);
                }

                // Otherwise, this player does not have permission; we do not want to
                // check the mobile/item/room security role on players, so we're done.
                return(string.Format("You do not have permission to use '{0}' right now.", command.Name));
            }

            MobileBehavior mobile = entity.FindBehavior <MobileBehavior>();

            if (mobile != null)
            {
                if ((command.SecurityRole & SecurityRole.mobile) != SecurityRole.none)
                {
                    return(null);
                }

                return(string.Format("A mobile can not use '{0}' right now!", command.Name));
            }

            RoomBehavior room = entity.FindBehavior <RoomBehavior>();

            if (room != null)
            {
                if ((command.SecurityRole & SecurityRole.room) == SecurityRole.none)
                {
                    return(null);
                }

                return(string.Format("A room can not use '{0}' right now!", command.Name));
            }

            // TODO: For now, everything else which doesn't meet any above category will need the 'item' security
            //       role. (Do we need an ItemBehavior or is there something else relevant... CanPickupBehavior etc?)
            if ((command.SecurityRole & SecurityRole.item) != SecurityRole.none)
            {
                return(null);
            }

            return(string.Format("An item (or unrecognized entity) can not use '{0}' right now!", command.Name));
        }