Exemplo n.º 1
0
        /// <summary>
        /// Layout a complete RDB block game object.
        /// </summary>
        /// <param name="blockName">Name of block to create.</param>
        /// <param name="textureTable">Optional texture table for dungeon.</param>
        /// <param name="allowExitDoors">Add exit doors to block (for start blocks).</param>
        /// <param name="dungeonType">Dungeon type for random encounters.</param>
        /// <param name="seed">Seed for random encounters.</param>
        /// <param name="cloneFrom">Clone and build on a prefab object template.</param>
        public static GameObject CreateRDBBlockGameObject(
            string blockName,
            int[] textureTable  = null,
            bool allowExitDoors = true,
            DFRegion.DungeonTypes dungeonType = DFRegion.DungeonTypes.HumanStronghold,
            float monsterPower           = 0.5f,
            int monsterVariance          = 4,
            int seed                     = 0,
            DaggerfallRDBBlock cloneFrom = null)
        {
            // Get DaggerfallUnity
            DaggerfallUnity dfUnity = DaggerfallUnity.Instance;

            if (!dfUnity.IsReady)
            {
                return(null);
            }

            Dictionary <int, RDBLayout.ActionLink> actionLinkDict = new Dictionary <int, RDBLayout.ActionLink>();

            // Create base object
            DFBlock    blockData;
            GameObject go = RDBLayout.CreateBaseGameObject(blockName, actionLinkDict, out blockData, textureTable, allowExitDoors, cloneFrom);

            // Add action doors
            RDBLayout.AddActionDoors(go, actionLinkDict, ref blockData, textureTable);

            // Add lights
            RDBLayout.AddLights(go, ref blockData);

            // Add flats
            DFBlock.RdbObject[] editorObjects;
            GameObject[]        startMarkers;
            GameObject[]        enterMarkers;
            RDBLayout.AddFlats(go, actionLinkDict, ref blockData, out editorObjects, out startMarkers, out enterMarkers);

            // Set start and enter markers
            DaggerfallRDBBlock dfBlock = go.GetComponent <DaggerfallRDBBlock>();

            if (dfBlock != null)
            {
                dfBlock.SetMarkers(startMarkers, enterMarkers);
            }

            // Add treasure
            RDBLayout.AddTreasure(go, editorObjects, ref blockData);

            // Add enemies
            RDBLayout.AddFixedEnemies(go, editorObjects, ref blockData);
            RDBLayout.AddRandomEnemies(go, editorObjects, dungeonType, monsterPower, ref blockData, monsterVariance, seed);

            // Link action nodes
            RDBLayout.LinkActionNodes(actionLinkDict);

            return(go);
        }
        public void CreateDungeonBlock()
        {
            DungeonGenerator myGen = GetComponent <DungeonRecord>().MyGenerator;

            Debug.LogWarning("Creating dungeon block: " + blockIndex + " isStarting block: " + isStartBlock);
            DaggerfallUnity dfUnity = DaggerfallUnity.Instance;

            if (!dfUnity.IsReady)
            {
                Debug.LogError("CreateDungeonBlock found dfUnity not ready; stopping");
                return;
            }

            // Create base object
            DFBlock blockData = dfUnity.ContentReader.BlockFileReader.GetBlock(blockIndex);

            if (blockData.Type != DFBlock.BlockTypes.Rdb)
            {
                Debug.LogError(string.Format("Invalid block index : {0} | block name: {1} | block type: {2}, returning", blockIndex, blockData.Name, blockData.Type));
                return;
            }

            GameObject go = RDBLayout.CreateBaseGameObject(blockData.Name, actLink, textureTable, true, cloneFrom);

            // Add exit doors
            if (isStartBlock)
            {
                StaticDoor[] doorsOut;
                RDBLayout.AddActionDoors(go, actLink, ref blockData, textureTable);
            }

            // Add action doors
            RDBLayout.AddActionDoors(go, actLink, ref blockData, textureTable);

            // Add lights
            RDBLayout.AddLights(go, ref blockData);

            // Add flats
            DFBlock.RdbObject[] editorObjectsOut = new DFBlock.RdbObject[0];
            GameObject[]        startMarkersOut  = null;
            GameObject[]        enterMarkersOut  = null;

            if (myGen.GenerateTreasure)
            {
                RDBLayout.AddFlats(go, actLink, ref blockData, out editorObjectsOut, out startMarkersOut, out enterMarkersOut, dungeonType);
            }

            // Set start markers
            DaggerfallRDBBlock dfBlock = (cloneFrom != null) ? cloneFrom : go.GetComponent <DaggerfallRDBBlock>();

            if (dfBlock != null)
            {
                dfBlock.SetMarkers(startMarkersOut, enterMarkersOut);
            }

            // Add enemies
            if (myGen.GenerateEnemies)
            {
                RDBLayout.AddRandomEnemies(go, editorObjectsOut, dungeonType, 0.5f, ref blockData, startMarkersOut);
            }

            go.transform.SetParent(this.transform);
            go.transform.localPosition = new Vector3(position.x, 0, position.y);
        }