Esempio n. 1
0
        private EasyB.Model.Record CreateRecord()
        {
            EasyB.Model.Record obj = new EasyB.Model.Record();
            obj.AutoUpdateLength = false;
            obj.Description      = "Account";
            obj.Name             = "AccountWF";
            obj.RecordType       = RecordType.FixedRecord;
            obj.Separator        = "";
            obj.CheckStatus      = CheckStatus.Default;

            FieldRecord fr = new FieldRecord();

            fr.Name      = "Id";
            fr.Length    = 0;
            fr.Guid      = Guid.Parse("9ae7d931-b14a-4855-b3ad-a0bdc8e9369f");
            fr.Start     = 0;
            fr.FieldType = "FieldType-guid-{248cb253-1bd1-4166-9285-f7749a2b5a8d}.EasyBpart";
            fr.End       = 0;
            obj.AddFieldRecord(fr);

            fr           = new FieldRecord();
            fr.Name      = "Id";
            fr.Length    = 10;
            fr.Guid      = Guid.Parse("9ae7d932-b14a-4855-b3ad-a0bdc8e9369f");
            fr.Start     = 0;
            fr.FieldType = "FieldType-guid-{248cb253-1bd1-4166-2285-f7749a2b5a8d}.EasyBpart";
            fr.End       = 0;
            obj.AddFieldRecord(fr);
            return(obj);
        }
Esempio n. 2
0
    /** Makes entire dungeon visible to player */
    public static void MakeDungeonVisible()
    {
        Util.Assert(CoM.ExploredDungeon != null, "Can not make dungeon visible, explored dungeon is null.");
        Util.Assert(CoM.Dungeon != null, "Can not make dungeon visible, dungeon is null.");
        Util.Assert(CoM.Dungeon.Floor.Length == CoM.ExploredDungeon.Floor.Length, "Can not make dungeon visible, dungeon and explored dungeon must have the same number of floors.");

        foreach (MDRMap map in CoM.Dungeon.Floor)
        {
            if (map == null)
            {
                continue;
            }

            MDRMap destinationMap = new MDRMap();
            destinationMap.Initialize(map.Width, map.Height);
            destinationMap.FloorNumber = map.FloorNumber;

            for (int y = 1; y <= map.Height; y++)
            {
                for (int x = 1; x <= map.Width; x++)
                {
                    FieldRecord source      = map.GetField(x, y);
                    FieldRecord destination = destinationMap.GetField(x, y);
                    destination.CopyFrom(source, TileCopyMode.STANDARD);
                }
            }

            CoM.ExploredDungeon.Floor[map.FloorNumber] = destinationMap;
        }
    }
Esempio n. 3
0
    /** Finds the best rotation for given object so that it either faces away from a wall, or towards a non wall. */
    private float AutoRotation(FieldRecord field)
    {
        int wallCount = 0;

        for (int lp = 0; lp < 4; lp++)
        {
            if (field.getWallRecord(lp))
            {
                wallCount++;
            }
        }

        // 1 wall face away from wall, 3 walls face towards open space.  Otherwise default to north.
        for (int lp = 0; lp < 4; lp++)
        {
            if (field.getWallRecord(lp).IsEmpty&& wallCount == 3)
            {
                return(lp * 90);
            }
            if (!field.getWallRecord(lp).IsEmpty&& wallCount == 1)
            {
                return(lp * 90 + 180);
            }
        }
        return(0);
    }
Esempio n. 4
0
            public async Task <long> Handle(CreateFieldRecordCommand request, CancellationToken cancellationToken)
            {
                var imageUrl = await _azureStorageService.UploadFileToStorage(request.PhotoBase64, request.PhotoName);

                var entity = new FieldRecord()
                {
                    FieldId  = request.ListId,
                    Note     = request.Note,
                    PhotoUrl = imageUrl
                };

                _context.FieldRecords.Add(entity);

                await _context.SaveChangesAsync(cancellationToken);

                return(entity.Id);
            }
Esempio n. 5
0
        /** Draws a fragment of a map tile (i.e. door etc) */
        private void DrawFragment(Vector2 location, int index)
        {
            int offsetX;
            int offsetY;

            offsetX = offsetY = 0;

            if (FieldRecord.isEastWallBit(index))
            {
                offsetX = +7;
            }

            if (FieldRecord.isNorthWallBit(index))
            {
                offsetY = +7;
            }

            TextureMagic.BlitWithAlpha(MapIcons[index], MapCanvas, (int)location.x + offsetX, (int)location.y + offsetY);
        }
        private void ReportField(FieldRecord field)
        {
            Type key = field.info.ReflectedType;
            List <FieldRecord> entries;

            if (fields.TryGetValue(key, out entries))
            {
                entries.Add(field);
                fields[key] = entries;
            }
            else
            {
                entries = new List <FieldRecord>();
                entries.Add(field);
                fields.Add(key, entries);
            }

            if (generateTooltipToDoItems && field.tooltip == null)
            {
                Debug.LogWarning(field.info.Name + " in " + field.info.ReflectedType + " needs a ToolTip.", field.script);
            }
        }
Esempio n. 7
0
        /**
         * Reads the next map from the file.
         * levelNumberToLoad is the level to load, 1 being the first.
         */
        public MDRMap ReadMap(int levelNumberToLoad)
        {
            MDRMap map = new MDRMap();

            data.Seek(0, SeekOrigin.Begin);

            // find how many levels there are
            int numberOfLevels = data.ReadMDRWord();

            if ((levelNumberToLoad <= 0) || (levelNumberToLoad > numberOfLevels))
            {
                data.Close();
                throw new Exception("Invalid level number " + levelNumberToLoad);
            }

            // get the offset
            data.RecordSeek(1 + levelNumberToLoad);
            int levelOffset = data.ReadMDRWord();

            // load in the map header
            data.RecordSeek(levelOffset);
            int width       = data.ReadWord();
            int height      = data.ReadWord();
            int floorNumber = data.ReadWord();

            if (floorNumber != levelNumberToLoad)
            {
                data.Close();
                throw new Exception("Level number in file wrong, expecting " + levelNumberToLoad + " but found " + floorNumber);
            }

            NumberOfAreas     = data.ReadWord();
            NumberOfChutes    = data.ReadWord();
            NumberOfTeleports = data.ReadWord();

            // make sure we got some resonable results
            if ((width <= 0) || (width > 256) || (height <= 0) || (height > 256))
            {
                data.Close();
                throw new Exception("Level dimentions invalid, found " + width + "x" + height + ", maximum size is 256x256");
            }

            if (NumberOfAreas > MDRMap.MAX_AREAS)
            {
                data.Close();
                throw new Exception("Too many areas in level, found " + NumberOfAreas + " but maximum is " + MDRMap.MAX_AREAS);
            }

            if (NumberOfChutes > MDRMap.MAX_CHUTES)
            {
                data.Close();
                throw new Exception("Too many chutes in level, found " + NumberOfChutes + " but maximum is " + MDRMap.MAX_CHUTES);
            }

            if (NumberOfTeleports > MDRMap.MAX_TELEPORTS)
            {
                data.Close();
                throw new Exception("Too many teleports in level, found " + NumberOfTeleports + " but maximum is " + MDRMap.MAX_TELEPORTS);
            }

            // initialize map with a rock frame
            FieldRecord rockTile = new FieldRecord(0, 0, null);

            rockTile.Rock = true;
            map.Initialize(width + 2, height + 2);
            map.FloorNumber = floorNumber;

            var AreaLocation = new Vector2[MDRMap.MAX_AREAS];

            // load field records
            data.RecordSeek(levelOffset + 1);

            for (int ylp = 1; ylp <= height; ylp++)
            {
                for (int xlp = 1; xlp <= width; xlp++)
                {
                    FieldRecord fieldRecord = new FieldRecord(xlp, ylp, map);

                    fieldRecord.AreaNumber = (ushort)data.ReadWord();

                    //read the field bitvalues as a currency type, and the convert to byte data
                    decimal decValue = data.ReadCurrency();
                    Int64   value    = Convert.ToInt64(decValue);
                    byte[]  bitData  = BitConverter.GetBytes(value);

                    AreaLocation[fieldRecord.AreaNumber] = new Vector2(xlp, ylp);

                    fieldRecord.BitMask = new BitArray(bitData);

                    // custom adjustment for grass
                    if (fieldRecord.Dirt && fieldRecord.Water)
                    {
                        fieldRecord.Dirt  = false;
                        fieldRecord.Water = false;
                        fieldRecord.Grass = true;
                    }

                    // adjust for new wall types
                    if (fieldRecord._alt)
                    {
                        if (fieldRecord.NorthWall.Door)
                        {
                            fieldRecord.NorthWall = new WallRecord(WallType.Arch);
                        }
                        if (fieldRecord.NorthWall.Secret)
                        {
                            fieldRecord.NorthWall = new WallRecord(WallType.Gate);
                        }
                        if (fieldRecord.EastWall.Door)
                        {
                            fieldRecord.EastWall = new WallRecord(WallType.Arch);
                        }
                        if (fieldRecord.EastWall.Secret)
                        {
                            fieldRecord.EastWall = new WallRecord(WallType.Gate);
                        }
                    }

                    // stub: remove traps
                    fieldRecord.Chute      = false;
                    fieldRecord.Pit        = false;
                    fieldRecord.Teleporter = false;
                    fieldRecord.FaceEast   = false;
                    fieldRecord.FaceWest   = false;
                    fieldRecord.FaceNorth  = false;
                    fieldRecord.FaceSouth  = false;

                    map[xlp, ylp] = fieldRecord;

                    map[xlp, ylp].Explored = true;

                    // skip the unused bytes in this 20 byte record
                    data.NextRecord();
                }
            }

            // rock outline
            WallRecord wall = new WallRecord(WallType.Wall);

            for (int lp = 0; lp <= width + 1; lp++)
            {
                map[lp, 0].Rock               = true;
                map[lp, 0].NorthWall          = wall;
                map[lp, height + 1].Rock      = true;
                map[lp, height + 1].SouthWall = wall;
            }
            for (int lp = 0; lp <= height + 1; lp++)
            {
                map[0, lp].Rock             = true;
                map[0, lp].EastWall         = wall;
                map[width + 1, lp].Rock     = true;
                map[width + 1, lp].WestWall = wall;
            }

            // Load areas.
            int localAreaCount = data.ReadMDRWord();

            NumberOfAreas = localAreaCount;
            //if (localAreaCount != NumberOfAreas)
            //	Trace.LogWarning("Area count missmatch expecting " + NumberOfAreas + " but found " + localAreaCount + " assuming " + NumberOfAreas);

            for (int lp = 0; lp < NumberOfAreas; lp++)
            {
                MDRArea area = new MDRArea();

                area.Origion = new MDRLocation((int)AreaLocation[lp].x, (int)AreaLocation[lp].y, floorNumber);

                area.SpawnMask = new MDRSpawnMask(data.ReadUInt32());
                int lairID = data.ReadWord();
                if (lairID != 0)
                {
                    area.LairedMonster = CoM.Monsters.ByID(lairID);
                    if (area.LairedMonster == null)
                    {
                        Trace.LogWarning("Import Error [Missing Monster]: Can not find monster of ID:{0} for lair{2} at [{1}].", lairID, area.Origion, lp);
                    }
                }

                // some areas will be invalid, so ignore areas with no spawnmask or lair id.
                if (!(area.SpawnMask.Mask.Count == 0 && lairID == 0))
                {
                    map.Area.Add(area);
                    area.Map = map;
                    area.ID  = lp;
                }

                data.NextRecord();
            }

            data.SkipRecords(200 - NumberOfAreas);
            data.SkipRecords(1);             // no idea why this is necessary, but there is a blank record here before we start with the teleporters

            // load teleports
            int localTeleportCount = data.ReadMDRWord();

            if (localTeleportCount != NumberOfTeleports)
            {
                Trace.LogWarning("Teleport count missmatch expecting " + NumberOfTeleports + " but found " + localTeleportCount + " assuming " + NumberOfTeleports);
            }

            for (int lp = 0; lp < NumberOfTeleports; lp++)
            {
                TeleportTrapInfo teleport = new TeleportTrapInfo();
                teleport.X         = data.ReadWord();
                teleport.Y         = data.ReadWord();
                teleport.DestX     = data.ReadWord();
                teleport.DestY     = data.ReadWord();
                teleport.DestFloor = data.ReadWord();

                data.NextRecord();

                if (teleport.IsValid)
                {
                    map.Teleport.Add(teleport);
                }
            }

            // load chutes
            int localChuteCount = data.ReadMDRWord();

            if (localChuteCount != NumberOfChutes)
            {
                Trace.LogWarning("Chute count missmatch expecting " + NumberOfChutes + " but found " + localChuteCount + " assuming " + NumberOfChutes);
            }

            for (int lp = 0; lp < NumberOfChutes; lp++)
            {
                ChuteTrapInfo chute = new ChuteTrapInfo();
                chute.X         = data.ReadWord();
                chute.Y         = data.ReadWord();
                chute.DropDepth = data.ReadWord();

                data.NextRecord();

                if (chute.IsValid)
                {
                    map.Chute.Add(chute);
                }
            }
            return(map);
        }
Esempio n. 8
0
 public void LoadGame(FieldRecord battleRecord)
 {
 }
Esempio n. 9
0
        /**
         * Renders a single tile to the map canvas.  The canvas will not be updated so you will need to call
         * mapCanvas.Apply() in order to see the results
         *
         * @param accent.  Draws tile is a different way, used to indicate newly discovered tiles.
         */
        public void RenderTile(int tileX, int tileY, TileRenderMode mode = TileRenderMode.Normal, bool accent = false)
        {
            if (!Map.InBounds(tileX, tileY))
            {
                throw new Exception("Tile (" + tileX + "," + tileY + ") out of bounds");
            }

            FieldRecord field    = Map.GetField(tileX, tileY);
            Vector2     location = TileToTexel(tileX, tileY);

            const int startIndex = 0;
            const int endIndex   = 38;

            if (mode == TileRenderMode.Normal || mode == TileRenderMode.Full)
            {
                if (!field.Explored)
                {
                    TextureMagic.FillRect(MapCanvas, (int)location.x, (int)location.y, TILE_SIZE, TILE_SIZE, Colors.MAP_UNEXPLOREDTILE_COLOR);
                }
                else
                {
                    if (accent)
                    {
                        TextureMagic.FillRect(MapCanvas, (int)location.x, (int)location.y, TILE_SIZE, TILE_SIZE, new Color(0f, 0f, 0f, 0.5f));
                        TextureMagic.FillRect(MapCanvas, (int)location.x + 1, (int)location.y + 1, TILE_SIZE - 1, TILE_SIZE - 1, new Color(1f, 0f, 0.5f, 0.25f));
                    }
                    else
                    {
                        TextureMagic.FillRect(MapCanvas, (int)location.x, (int)location.y, TILE_SIZE, TILE_SIZE, Color.clear);
                    }
                }
            }

            for (int index = startIndex; index < endIndex; index++)
            {
                if (mode == TileRenderMode.EastWall && !FieldRecord.isEastWallBit(index))
                {
                    continue;
                }

                if (mode == TileRenderMode.NorthWall && !FieldRecord.isNorthWallBit(index))
                {
                    continue;
                }

                if (field.GetBit(index))
                {
                    DrawFragment(location, index);
                }
            }

            if (mode == TileRenderMode.Full)
            {
                if (tileX >= 1)
                {
                    RenderTile(tileX - 1, tileY, TileRenderMode.EastWall);
                }
                if (tileY >= 1)
                {
                    RenderTile(tileX, tileY - 1, TileRenderMode.NorthWall);
                }
            }
        }
Esempio n. 10
0
 private static RowField <TType> CreateRowField <TType>(FieldRecord <TType> fieldRecord) => new(fieldRecord);
Esempio n. 11
0
        private void Rebuild()
        {
            RowsProportions.Clear();
            Widgets.Clear();
            _records.Clear();

            if (_object == null)
            {
                return;
            }

            var properties = from p in _object.GetType().GetProperties() select p;
            var records    = new List <Record>();

            foreach (var property in properties)
            {
                if (property.GetGetMethod() == null ||
                    !property.GetGetMethod().IsPublic ||
                    property.GetGetMethod().IsStatic)
                {
                    continue;
                }

                var hasSetter = property.GetSetMethod() != null &&
                                property.GetSetMethod().IsPublic;

                var browsableAttr = property.FindAttribute <BrowsableAttribute>();
                if (browsableAttr != null && !browsableAttr.Browsable)
                {
                    continue;
                }

                var hiddenAttr = property.FindAttribute <HiddenInEditorAttribute>();
                if (hiddenAttr != null)
                {
                    continue;
                }

                var readOnlyAttr = property.FindAttribute <ReadOnlyAttribute>();
                if (readOnlyAttr != null && readOnlyAttr.IsReadOnly)
                {
                    hasSetter = false;
                }

                var record = new PropertyRecord(property)
                {
                    HasSetter = hasSetter
                };

                var selectionAttr = property.FindAttribute <SelectionAttribute>();
                if (selectionAttr != null)
                {
                    record.ItemsProvider = (IItemsProvider)Activator.CreateInstance(selectionAttr.ItemsProviderType, _object);
                }

                var categoryAttr = property.FindAttribute <EditCategoryAttribute>();
                record.Category = categoryAttr != null ? categoryAttr.Name : DefaultCategoryName;

                records.Add(record);
            }

            var fields = from f in _object.GetType().GetFields() select f;

            foreach (var field in fields)
            {
                if (!field.IsPublic || field.IsStatic)
                {
                    continue;
                }

                var categoryAttr = field.FindAttribute <EditCategoryAttribute>();


                var hasSetter    = true;
                var readOnlyAttr = field.FindAttribute <ReadOnlyAttribute>();
                if (readOnlyAttr != null && readOnlyAttr.IsReadOnly)
                {
                    hasSetter = false;
                }


                var record = new FieldRecord(field)
                {
                    HasSetter = hasSetter,
                    Category  = categoryAttr != null ? categoryAttr.Name : DefaultCategoryName
                };

                records.Add(record);
            }

            // Sort by categories
            for (var i = 0; i < records.Count; ++i)
            {
                var record = records[i];

                List <Record> categoryRecords;
                if (!_records.TryGetValue(record.Category, out categoryRecords))
                {
                    categoryRecords           = new List <Record>();
                    _records[record.Category] = categoryRecords;
                }

                categoryRecords.Add(record);
            }

            // Sort by names within categories
            foreach (var category in _records)
            {
                category.Value.Sort((a, b) => Comparer <string> .Default.Compare(a.Name, b.Name));
            }

            var ordered = _records.OrderBy(key => key.Key);

            var           y = 0;
            List <Record> defaultCategoryRecords;


            if (_records.TryGetValue(Category, out defaultCategoryRecords))
            {
                FillSubGrid(ref y, defaultCategoryRecords);
            }

            if (Category != DefaultCategoryName)
            {
                return;
            }

            foreach (var category in ordered)
            {
                if (category.Key == DefaultCategoryName)
                {
                    continue;
                }

                var subGrid = new SubGrid(this, Object, category.Key, category.Key, null)
                {
                    GridSpanX     = 2,
                    GridPositionY = y
                };

                Widgets.Add(subGrid);

                if (_expandedCategories.Contains(category.Key))
                {
                    subGrid.Mark.IsPressed = true;
                }

                var rp = new Proportion(ProportionType.Auto);
                RowsProportions.Add(rp);

                y++;
            }
        }
Esempio n. 12
0
    /**
     * Deletes then recreates all objects for given map.
     * Custom added objects will remain.
     */
    private void rebuildMap(int mapIndex)
    {
        if (!IsInitialized)
        {
            throw new Exception("Can not rebuild map, dungeon not initialized.");
        }

        if (!isValidMapIndex(mapIndex))
        {
            return;
        }

        Trace.Log("Rebuilding map {0} with Ceiling: {1}", mapIndex, GenerateCeiling);

        UnityEngine.Random.seed = Seed + (mapIndex);

        var startTime = DateTime.Now;

        clearMap(mapIndex);

        objectsCreated = 0;
        var lightsCreated = 0;

        var fabNode     = getFabNode(mapIndex);
        var detailsNode = getDetailNode(mapIndex);

        //create map objects
        int mapHeight = (MaxSize == 0) ? Map(mapIndex).Height : Util.ClampInt(Map(mapIndex).Height, 1, MaxSize);
        int mapWidth  = (MaxSize == 0) ? Map(mapIndex).Width : Util.ClampInt(Map(mapIndex).Width, 1, MaxSize);

        for (int ylp = 0; ylp <= mapHeight; ylp++)
        {
            for (int xlp = 0; xlp <= mapWidth; xlp++)
            {
                // floor
                FieldRecord field = Map(mapIndex).GetField(xlp, ylp);

                if (field == null)
                {
                    continue;
                }

                if (GenerateCeiling)
                {
                    int roll = (int)(Util.SeededRandom("ceiling", xlp, ylp) * 16);

                    var ceilingTile   = CeilingTile;
                    var ceilingObject = InstantiateObject(fabNode, ceilingTile, xlp, ylp);
                    ceilingObject.transform.Rotate(ceilingObject.transform.up, 90 * (int)(roll / 4));

                    // generate the cross beams
                    if (CrossBeam != null)
                    {
                        InstantiateObject(fabNode, CrossBeam, xlp, ylp, "North");
                        InstantiateObject(fabNode, CrossBeam, xlp, ylp, "East");
                    }
                }

                if (GenerateFloor)
                {
                    // Floor:
                    if (field.Water)
                    {
                        InstantiateObject(fabNode, WaterObject, xlp, ylp);
                    }
                    else if (field.Grass)
                    {
                        InstantiateObject(fabNode, GrassTile, xlp, ylp);
                    }
                    else if (field.Dirt)
                    {
                        var floorObject = DirtTiles[Util.Roll(DirtTiles.Count) - 1];
                        InstantiateObject(fabNode, floorObject, xlp, ylp);
                    }
                    else if (!field.Rock)
                    {
                        var floorObject = FloorTiles[Util.Roll(FloorTiles.Count) - 1];
                        InstantiateObject(fabNode, floorObject, xlp, ylp);
                    }

                    // Tile Edges:
                    bool stepNorth = (field.EdgeHeight < field.North.EdgeHeight);
                    bool stepSouth = (field.EdgeHeight < field.South.EdgeHeight);
                    bool stepEast  = (field.EdgeHeight < field.East.EdgeHeight);
                    bool stepWest  = (field.EdgeHeight < field.West.EdgeHeight);

                    if (stepNorth)
                    {
                        InstantiateObject(fabNode, field.NorthWall ? WaterEdgeHalf : WaterEdge, xlp, ylp, "North");
                    }
                    if (stepSouth)
                    {
                        InstantiateObject(fabNode, field.SouthWall ? WaterEdgeHalf : WaterEdge, xlp, ylp, "South");
                    }
                    if (stepEast)
                    {
                        InstantiateObject(fabNode, field.EastWall ? WaterEdgeHalf : WaterEdge, xlp, ylp, "East");
                    }
                    if (stepWest)
                    {
                        InstantiateObject(fabNode, field.WestWall ? WaterEdgeHalf : WaterEdge, xlp, ylp, "West");
                    }

                    if (stepNorth || stepEast)
                    {
                        InstantiateObject(fabNode, WaterEdgeCorner, xlp + 0.5f, ylp + 0.5f);
                    }
                    if (stepNorth || stepWest)
                    {
                        InstantiateObject(fabNode, WaterEdgeCorner, xlp - 0.5f, ylp + 0.5f);
                    }
                    if (stepSouth || stepEast)
                    {
                        InstantiateObject(fabNode, WaterEdgeCorner, xlp + 0.5f, ylp - 0.5f);
                    }
                    if (stepSouth || stepWest)
                    {
                        InstantiateObject(fabNode, WaterEdgeCorner, xlp - 0.5f, ylp - 0.5f);
                    }

                    // stairs
                    GameObject stairs = null;
                    if (field.StairsUp)
                    {
                        stairs = InstantiateObject(fabNode, StairsUp, xlp, ylp);
                    }
                    if (field.StairsDown)
                    {
                        stairs = InstantiateObject(fabNode, StairsDown, xlp, ylp);
                    }
                    if (stairs != null)
                    {
                        float stairDirection = AutoRotation(field);
                        stairs.transform.RotateAround(new Vector3(xlp, 0, ylp), new Vector3(0, 1f, 0), stairDirection);
                        markReference(stairs, xlp, ylp, new Direction(stairDirection));
                    }
                }

                if (GenerateWalls)
                {
                    // Wall:
                    if (field.NorthWall.Wall)
                    {
                        InstantiateObject(fabNode, WallObject, xlp, ylp, "North", "Wall");
                    }
                    if (field.NorthWall.Secret)
                    {
                        InstantiateObject(fabNode, SecretDoorObject, xlp, ylp, "North", "Secret");
                    }

                    if (field.EastWall.Wall)
                    {
                        InstantiateObject(fabNode, WallObject, xlp, ylp, "East", "Wall");
                    }
                    if (field.EastWall.Secret)
                    {
                        InstantiateObject(fabNode, SecretDoorObject, xlp, ylp, "East", "Secret");
                    }

                    // Columns:
                    if (!field.NorthWall.IsEmpty || !field.EastWall.IsEmpty)
                    {
                        InstantiateObject(fabNode, ColumnObject, xlp + 0.5f, ylp + 0.5f);
                    }
                    if (!field.NorthWall.IsEmpty)
                    {
                        InstantiateObject(fabNode, ColumnObject, xlp - 0.5f, ylp + 0.5f);
                    }
                    if (!field.EastWall.IsEmpty)
                    {
                        InstantiateObject(fabNode, ColumnObject, xlp + 0.5f, ylp - 0.5f);
                    }


                    // sidewalks
                    if (!field.Rock && !field.Water && !field.Dirt && !field.Grass)
                    {
                        for (int lp = 0; lp < 4; lp++)
                        {
                            if (field.getWallRecord(lp).Wall || field.getWallRecord(lp).Secret)
                            {
                                InstantiateObject(fabNode, SidewalkWall, xlp, ylp, directionNames[lp]);
                            }
                        }
                    }

                    // doors
                    if (field.NorthWall.Door)
                    {
                        InstantiateObject(fabNode, DoorFrameObject, xlp, ylp, "North");
                        InstantiateObject(fabNode, DoorObject, xlp, ylp, "North", "Door");
                    }

                    if (field.EastWall.Door)
                    {
                        InstantiateObject(fabNode, DoorFrameObject, xlp, ylp, "East");
                        InstantiateObject(fabNode, DoorObject, xlp, ylp, "East", "Door");
                    }

                    // gates
                    if (field.NorthWall.Gate)
                    {
                        InstantiateObject(fabNode, DoorFrameObject, xlp, ylp, "North");
                        InstantiateObject(fabNode, IronBarGateObject, xlp, ylp, "North", "Gate");
                    }

                    if (field.EastWall.Gate)
                    {
                        InstantiateObject(fabNode, DoorFrameObject, xlp, ylp, "East");
                        InstantiateObject(fabNode, IronBarGateObject, xlp, ylp, "East", "Gate");
                    }


                    // arches
                    if (field.NorthWall.Arch)
                    {
                        InstantiateObject(fabNode, DoorFrameObject, xlp, ylp, "North");
                    }

                    if (field.EastWall.Arch)
                    {
                        InstantiateObject(fabNode, DoorFrameObject, xlp, ylp, "East");
                    }

                    // lightsfloorObject
                    if (field.Light)
                    {
                        lightsCreated++;
                        InstantiateObject(fabNode, CeilingLight, xlp, ylp);
                    }

                    if (GenerateDetails)
                    {
                        generateFurnishings(detailsNode, field);
                    }
                }
            }
        }

        isBuilt[mapIndex] = true;

        Trace.Log("Rebuilt map {2}, created {0} objects {1} lights, took {3:0.00} seconds.", objectsCreated, lightsCreated, mapIndex, (DateTime.Now - startTime).TotalSeconds);
    }
Esempio n. 13
0
    /** Adds details to given tile. */
    private void generateFurnishings(Transform detailsNode, FieldRecord tile)
    {
        if (Furnishings == null || Furnishings.Count == 0)
        {
            return;
        }

        if (tile.Empty || tile.Rock)
        {
            return;
        }

        // Groups used for this tile.
        var groupsUsed = new List <int>();

        // process walls...
        for (int wallIndex = 0; wallIndex < 4; wallIndex++)
        {
            if (!tile.getWallRecord(wallIndex).Wall)
            {
                continue;
            }

            for (int lp = 0; lp < Furnishings.Count; lp++)
            {
                var item = Furnishings[lp];
                if (!item.Enabled || item.Source == null || item.Chance == 0 || item.Placement != DetailPlacementMethod.Wall)
                {
                    continue;
                }

                var groupID = (item.GroupID % 65536) + ((1 + wallIndex) * 65536);

                if (groupsUsed.Contains(groupID))
                {
                    continue;
                }

                float diceRoll = Util.SeededRandom(tile.X + tile.Y + "wall_detail" + lp + wallIndex) * 100f;

                if (diceRoll < item.Chance)
                {
                    var offsetVector = new Vector3(0, 0, 0);
                    if (item.PositionVariation)
                    {
                        offsetVector.x = Util.SeededRandom(tile.X + tile.Y + "offset" + lp + wallIndex) * 0.6f - 0.3f;
                    }

                    InstantiateObject(detailsNode, item.Source, tile.X, tile.Y, directionNames[wallIndex], item.Source.name, offsetVector);
                    groupsUsed.Add(groupID);
                }
            }
        }

        // process corners...
        for (int wallIndex = 0; wallIndex < 4; wallIndex++)
        {
            if (!(tile.getWallRecord(wallIndex).Wall&& tile.getWallRecord((wallIndex + 3) % 4).Wall))
            {
                continue;
            }

            for (int lp = 0; lp < Furnishings.Count; lp++)
            {
                string seedBase = tile.X + " " + tile.Y + " " + wallIndex + " " + lp + ":";

                var item = Furnishings[lp];
                if (!item.Enabled || item.Source == null || item.Chance == 0 || item.Placement != DetailPlacementMethod.Corner)
                {
                    continue;
                }

                var groupID = (item.GroupID % 65536) + ((5 + wallIndex) * 65536);

                if (groupsUsed.Contains(groupID))
                {
                    continue;
                }

                float diceRoll = Util.SeededRandom(seedBase, "corner_detail", wallIndex) * 100f;

                if (diceRoll < item.Chance)
                {
                    var offsetVector = new Vector3(0, 0, 0);
                    if (item.PositionVariation)
                    {
                        offsetVector.x = Util.SeededRandom(seedBase, "offsetx") * 0.3f - 0.15f;
                        offsetVector.z = Util.SeededRandom(seedBase, "offsetz") * 0.3f - 0.15f;
                    }

                    var rotationVector = new Vector3(0, 0, 0);
                    if (item.RotationVariation)
                    {
                        rotationVector.y = Util.SeededRandom(seedBase, "rotation") * 360f;
                    }

                    var createdObject = InstantiateObject(detailsNode, item.Source, tile.X, tile.Y, cornerNames[wallIndex], item.Source.name, offsetVector);

                    createdObject.transform.localRotation = Quaternion.Euler(createdObject.transform.localRotation.eulerAngles + rotationVector);

                    groupsUsed.Add(groupID);
                }
            }
        }

        // process floor...

        if (!(tile.Water || tile.Dirt || tile.Grass))
        {
            for (int lp = 0; lp < Furnishings.Count; lp++)
            {
                var item = Furnishings[lp];
                if (!item.Enabled || item.Source == null || item.Chance == 0 || item.Placement != DetailPlacementMethod.Floor)
                {
                    continue;
                }

                var groupID = (item.GroupID % 65536) + ((0) * 65536);

                if (groupsUsed.Contains(groupID))
                {
                    continue;
                }

                float diceRoll = (Util.SeededRandom(tile.X, tile.Y, "floor_detail" + lp) * 100f);

                if (diceRoll < item.Chance)
                {
                    var offsetVector = new Vector3(0, 0, 0);
                    if (item.PositionVariation)
                    {
                        offsetVector.x = Util.SeededRandom(tile.X, tile.Y, "offsetx" + lp) * 0.8f - 0.4f;
                        offsetVector.z = Util.SeededRandom(tile.X, tile.Y, "offsetz" + lp) * 0.8f - 0.4f;
                    }

                    var rotationVector = new Vector3(0, 0, 0);
                    if (item.RotationVariation)
                    {
                        rotationVector.y = Util.SeededRandom(tile.X, tile.Y, "rotation" + lp) * 360f;
                    }

                    var createdObject = InstantiateObject(detailsNode, item.Source, tile.X, tile.Y, "Center", item.Source.name, offsetVector);

                    createdObject.transform.localRotation = Quaternion.Euler(createdObject.transform.localRotation.eulerAngles + rotationVector);

                    groupsUsed.Add(groupID);
                }
            }
        }
    }