示例#1
0
 public BlockRecord(string name, int index, bool hasStartFlags, DFBlock.BlockTypes blockType, DFBlock.RdbTypes rdbtype)
 {
     this.name          = name;
     this.index         = index;
     this.hasStartFlags = hasStartFlags;
     this.blockType     = blockType;
     this.RdBType       = rdbtype;
 }
        /// <summary>
        /// Grabs the relevant data from a DFBlock struct and creates a BlockRecord
        /// </summary>
        /// <param name="recordOut"></param>
        /// <param name="blockData"></param>
        public void CreateBlockRecordFromDFBlock(out BlockRecord recordOut, DFBlock blockData)
        {
            DFBlock.RdbTypes RdBType = DaggerfallUnity.Instance.ContentReader.BlockFileReader.GetRdbType(blockData.Name);

            bool hasStartMarkers = false;

            if (blockData.Type == DFBlock.BlockTypes.Rdb && !startMarkerFilter.Contains(blockData.Name) && !blockData.Name.StartsWith("B"))
            {
                hasStartMarkers = true;
            }
            recordOut = new BlockRecord(blockData.Name, blockData.Index, hasStartMarkers, blockData.Type, RdBType);
        }
 /// <summary>
 /// Gets a random block based on rdb type.  Will recursively try and find unique block
 /// Returns null on error
 /// </summary>
 /// <param name="rdbType"></param>
 /// <param name="count"></param>
 /// <returns></returns>
 BlockRecord GetRandomBlock(DFBlock.RdbTypes rdbType = DFBlock.RdbTypes.Unknown, int count = 0)
 {
     try
     {
         count++;
         var usedIndices = GetUsedIndices();
         if (rdbType == DFBlock.RdbTypes.Start) //get random start block
         {
             BlockRecord record = blockCollection.GetRandomBlock(blockCollection.GetStartBlocks(blockCollection.blockRecords));
             if (usedIndices.Contains(record.index))
             {
                 if (count < 100)
                 {
                     return(GetRandomBlock(rdbType, count));
                 }
                 else
                 {
                     Debug.LogWarning("Failed to find unique block");
                     record = new BlockRecord(record.name, record.index, record.hasStartFlags, record.blockType, record.RdBType);
                     return(record);
                 }
             }
             else
             {
                 return(record);
             }
         }
         else if (rdbType == DFBlock.RdbTypes.Border) //Get a random border block
         {
             BlockRecord record = blockCollection.GetRandomBlock(blockCollection.FilterRDBBlocks(blockCollection.blockRecords, rdbType));
             if (usedIndices.Contains(record.index))
             {
                 if (count < 100)
                 {
                     return(GetRandomBlock(rdbType, count));
                 }
                 else
                 {
                     Debug.LogWarning("Failed to find unique block ");
                     record = new BlockRecord(record.name, record.index, record.hasStartFlags, record.blockType, record.RdBType);
                     return(record);
                 }
             }
             else
             {
                 return(record);
             }
         }
         else// Get non-border blocks
         {
             BlockRecord record = blockCollection.GetRandomBlock(blockCollection.FilterRDBBlocks(blockCollection.blockRecords, DFBlock.RdbTypes.Border, true));
             if (usedIndices.Contains(record.index))
             {
                 if (count < 100)
                 {
                     return(GetRandomBlock(rdbType, count));
                 }
                 else
                 {
                     Debug.LogWarning("Failed to find unique block");
                     record = new BlockRecord(record.name, record.index, record.hasStartFlags, record.blockType, record.RdBType);
                     return(record);
                 }
             }
             else
             {
                 return(record);
             }
         }
     }
     catch (System.Exception ex)
     {
         Debug.LogError(ex.Message);
         return(null);
     }
 }
 public List <BlockRecord> FilterRDBBlocks(List <BlockRecord> blockRecords, DFBlock.RdbTypes rdbType, bool reverseFilter = false)
 {
     return(this.blockRecords.Where(block => block.blockType == DFBlock.BlockTypes.Rdb && ((block.RdBType == rdbType) != reverseFilter)).ToList <BlockRecord>());
 }