Пример #1
0
        private void ReceiveExteriorChunk(BinaryReader reader)
        {
            int x = reader.ReadInt16() * Overworld.ChunkWidth;
            int y = reader.ReadInt16() * Overworld.ChunkHeight;

            OverworldTile tile = Overworld.GetOverworldTile(x, y);

            tile.LoadChunks(reader);
        }
Пример #2
0
        private void ReceiveDiscardChunk(BinaryReader reader)
        {
            int x = reader.ReadInt16() * Overworld.ChunkWidth;
            int y = reader.ReadInt16() * Overworld.ChunkHeight;

            OverworldTile tile = Overworld.GetOverworldTile(x, y);

            tile.UnloadChunks();
        }
Пример #3
0
        public void SendDiscardChunk(OverworldTile tile)
        {
            BinaryWriter writer = GetWriter();

            writer.Write((byte)PacketID.DiscardChunk);
            writer.Write((Int16)(tile.X / GameServer.Overworld.ChunkWidth));
            writer.Write((Int16)(tile.Y / GameServer.Overworld.ChunkHeight));
            SendPacket();
        }
Пример #4
0
    private OverworldTile SetTileBoundaries(Tilemap map, Vector3Int localPlace, OverworldTile tile)
    {
        var playableBoundary = playableCollider.bounds;

        // Determine if Tile is outside of boundaries
        if (localPlace.x >= playableBoundary.min.x && localPlace.x < playableBoundary.max.x &&
            localPlace.y >= playableBoundary.min.y && localPlace.y < playableBoundary.max.y)
        {
            tile.IsMoveable = true;
        }
        else
        {
            tile.IsMoveable = false;
        }
        return(tile);
    }
    public virtual IEnumerator MoveToTile(Vector2 position)
    {
        //check if we can move there
        Tilemap map = OverworldManager.instance.tilemap;

        TileBase tile = map.GetTile(new Vector3Int((int)position.x - 1, (int)position.y - 1, 0));

        if (tile.GetType() == typeof(OverworldTile) || tile.GetType().BaseType == typeof(OverworldTile))
        {
            OverworldTile oTile = (OverworldTile)tile;
            if (!oTile.getPassable())
            {
                //maybe play that pokemon OOMPH sound when you walk into something

                yield break;
            }
        }
        Vector2 direction = (position - (Vector2)transform.position).normalized;

        //check if they are on a space with a mapObject
        OverworldObject[] overworldObjects = GameObject.FindObjectsOfType <OverworldObject>();
        foreach (OverworldObject oObject in overworldObjects)
        {
            if ((Vector2)transform.position + direction == (Vector2)oObject.transform.position)
            {
                //cant walk here

                yield break;
            }
        }

        isMoving = true;

        while (Vector2.Distance(transform.position, position) > 0.1f)
        {
            transform.position = (Vector2)transform.position + direction * 4f * Time.deltaTime;
            yield return(new WaitForEndOfFrame());
        }


        transform.position = position;
        isMoving           = false;

        yield break;
    }
Пример #6
0
    // Use this for initialization
    private void GenerateOverworldTiles()
    {
        tiles = new Dictionary <Vector3, OverworldTile>();
        foreach (Tilemap map in tilemaps)
        {
            foreach (Vector3Int pos in map.cellBounds.allPositionsWithin)
            {
                var localPlace = new Vector3Int(pos.x, pos.y, pos.z);

                if (!map.HasTile(localPlace))
                {
                    continue;
                }

                // TODO: Create factory that allows for different types of terrain.
                var tile = new OverworldTile
                {
                    LocalPlace    = localPlace,
                    WorldLocation = map.CellToWorld(localPlace),
                    TileBase      = map.GetTile(localPlace),
                    TilemapMember = map,
                    Name          = OverworldTileTypes.Plain,
                    Cost          = 1, // TODO: Change this with the proper cost from ruletile
                };

                tile = SetTileBoundaries(map, localPlace, tile);

                //if (!tile.IsMoveable)
                //print("Immovable x:" + localPlace.x + " y: " + localPlace.y);

                // Update or Add new tiles to running list
                if (tiles.ContainsKey(tile.WorldLocation))
                {
                    tiles[tile.WorldLocation] = tile;
                }
                else
                {
                    tiles.Add(tile.WorldLocation, tile);
                }
            }
        }
    }
Пример #7
0
        public OverworldMap(int width, int height)
        {
            SingletonRandom.DefaultRNG = new Troschuetz.Random.Generators.XorShift128Generator(Data.World.GetSeed());
            Width           = width;
            Height          = height;
            RawOverworldMap = new ArrayMap <bool>(Width, Height);
            voronoiNoiseMap = ZoneGenerator.Generate(width, height);
            OverWorld       = new OverworldTile[Width * Height];
            masterNoise     = new PerlinGenerator(Width, Height);
            masterNoise.ConfigureAll(4, 1, 0.25D, 2);
            CellularAutomataAreaGenerator.Generate(RawOverworldMap, null, 45, 8, 2);
            OrderedMapAreaConnector.Connect(RawOverworldMap, AdjacencyRule.EIGHT_WAY);
            DeadEndTrimmer.Trim(RawOverworldMap);
            RemoveLandmassByVoronoiNoise(RawOverworldMap);
            var perspnoise = masterNoise.Generate();

            rainNoise = perspnoise;
            NormalizePersp();
            BuildOverWorld(RawOverworldMap, OverWorld);
        }
Пример #8
0
        public void SendExteriorChunk(OverworldTile tile)
        {
            if (!tile.ChunksLoaded)
            {
                return;
            }

            BinaryWriter writer = GetWriter();

            writer.Write((byte)PacketID.ExteriorChunk);
            writer.Write((Int16)(tile.X / GameServer.Overworld.ChunkWidth));
            writer.Write((Int16)(tile.Y / GameServer.Overworld.ChunkHeight));

            for (int x = 0; x < GameServer.Overworld.ChunkWidth / OverworldTile.SubChunkSize; ++x)
            {
                for (int y = 0; y < GameServer.Overworld.ChunkHeight / OverworldTile.SubChunkSize; ++y)
                {
                    tile.Chunks[x, y].Save(writer.BaseStream, false);
                }
            }

            SendPacket();
        }
Пример #9
0
        private void AssignBiomes(ArrayMap <bool> rawOverworldMap, OverworldTile[] OverWorld)
        {
            foreach (var pos in rawOverworldMap.Positions())
            {
                OverworldTile tile = null;
                int           glyph;
                calculatedBiome = DefineBiomeAt(pos);
                if (rawOverworldMap[pos]) // land tiles
                {
                    Color fgd          = Color.White;
                    Color bgd          = Color.DarkGray;
                    var   fgdColdBiome = new Color(53, 79, 0);
                    var   bkgColdBiome = new Color(141, 182, 0);
                    var   bkgTempBiome = new Color(46, 110, 18);
                    var   fgdTempBiome = new Color(00, 68, 00);
                    var   bkgWarmBiome = new Color(45, 136, 45);
                    var   fgdWarmBiome = new Color(0, 68, 0);
                    switch (calculatedBiome)
                    {
                    case Biome.Cold | Biome.Arid:
                        fgd   = fgdColdBiome; //AzureMist
                        bgd   = bkgColdBiome; // Apple Green
                        glyph = 44;           // ','
                        break;

                    case Biome.Cold | Biome.SemiArid:
                        fgd   = fgdColdBiome;
                        bgd   = bkgColdBiome; // Apple Green
                        glyph = 46;           // '.'
                        break;

                    case Biome.Cold | Biome.SemiHumid:
                        fgd   = fgdColdBiome;
                        bgd   = bkgColdBiome;
                        glyph = 15;     // '☼'
                        break;

                    case Biome.Cold | Biome.Humid:
                        fgd   = fgdColdBiome;
                        bgd   = bkgColdBiome;
                        glyph = 42;     // '*'
                        break;

                    case Biome.Temperate | Biome.Arid:
                        fgd   = new Color(121, 182, 0);
                        bgd   = bkgTempBiome;
                        glyph = 15;     // '☼'
                        break;

                    case Biome.Temperate | Biome.SemiArid:
                        fgd   = fgdTempBiome;
                        bgd   = bkgTempBiome;
                        glyph = 6;     // '♠'
                        break;

                    case Biome.Temperate | Biome.SemiHumid:
                        fgd   = fgdTempBiome;
                        bgd   = bkgTempBiome;
                        glyph = 6;     // '♠'
                        break;

                    case Biome.Temperate | Biome.Humid:
                        fgd   = fgdTempBiome;
                        bgd   = bkgTempBiome;
                        glyph = 5;     // '♣'
                        break;

                    case Biome.Warm | Biome.Arid:
                        fgd   = fgdWarmBiome;
                        bgd   = bkgWarmBiome;
                        glyph = 44;     // ','
                        break;

                    case Biome.Warm | Biome.SemiArid:
                        fgd   = fgdWarmBiome;
                        bgd   = bkgWarmBiome;
                        glyph = 46;     // '.'
                        break;

                    case Biome.Warm | Biome.SemiHumid:
                        fgd   = fgdWarmBiome;
                        bgd   = bkgWarmBiome;
                        glyph = 6;     // '♠'
                        break;

                    case Biome.Warm | Biome.Humid:
                        fgd   = fgdWarmBiome;
                        bgd   = bkgWarmBiome;
                        glyph = 5;     // '♣'
                        break;

                    default:
                        glyph = 63;     // '?'
                        break;
                    }
                    tile = new OverworldTile($"Land - {glyph}", pos, glyph)
                    {
                        ZoneNoise     = voronoiNoiseMap[pos.X, pos.Y],
                        RainNoise     = rainNoise[pos.X, pos.Y],
                        Biome         = calculatedBiome,
                        Foreground    = fgd,
                        Background    = bgd,
                        IsWalkable    = true,
                        IsTransparent = true
                    };
                }
                else if (rawOverworldMap[pos] == false) // air tiles
                {
                    glyph = 126;                        // '~'
                    var bkg = new Color(93, 138, 168);
                    var fgd = Color.Aquamarine;
                    tile = new OverworldTile($"Air - {glyph}", pos, glyph)
                    {
                        ZoneNoise     = voronoiNoiseMap[pos.X, pos.Y],
                        RainNoise     = rainNoise[pos.X, pos.Y],
                        Biome         = calculatedBiome,
                        Foreground    = fgd,
                        Background    = bkg,
                        IsWalkable    = false,
                        IsTransparent = true
                    };
                }
                if (tile != null)
                {
                    OverWorld[Coord.ToIndex(pos.X, pos.Y, Width)] = tile;
                    //if (voronoiNoiseMap[pos.X, pos.Y] >= (voronoiNoiseMap.Data.Max() - HotSpotLowerLimit))
                    //{
                    //    if (rainNoise[pos.X, pos.Y] > 0.5)
                    //        riverCandidates.Add(OverWorld[Coord.ToIndex(pos.X, pos.Y, Width)]);
                    //}
                    bool candidate = rainNoise[pos.X, pos.Y] > MinPersp && (voronoiNoiseMap[pos.X, pos.Y] >= (voronoiNoiseMap.Data.Max() - HotSpotLowerLimit));
                    switch (tile.Biome)
                    {
                    case Biome.Cold | Biome.SemiHumid:
                        if (candidate)
                        {
                            RiverCandidates.Add(OverWorld[Coord.ToIndex(pos.X, pos.Y, Width)]);
                        }
                        break;

                    case Biome.Cold | Biome.Humid:
                        if (candidate)
                        {
                            RiverCandidates.Add(OverWorld[Coord.ToIndex(pos.X, pos.Y, Width)]);
                        }
                        break;

                    case Biome.Temperate | Biome.SemiHumid:
                        if (candidate)
                        {
                            RiverCandidates.Add(OverWorld[Coord.ToIndex(pos.X, pos.Y, Width)]);
                        }
                        break;

                    case Biome.Temperate | Biome.Humid:
                        if (candidate)
                        {
                            RiverCandidates.Add(OverWorld[Coord.ToIndex(pos.X, pos.Y, Width)]);
                        }
                        break;

                    case Biome.Warm | Biome.SemiHumid:
                        if (candidate)
                        {
                            RiverCandidates.Add(OverWorld[Coord.ToIndex(pos.X, pos.Y, Width)]);
                        }
                        break;

                    case Biome.Warm | Biome.Humid:
                        if (candidate)
                        {
                            RiverCandidates.Add(OverWorld[Coord.ToIndex(pos.X, pos.Y, Width)]);
                        }
                        break;

                    default:
                        break;
                    }
                    //if (tile.Biome == Biome.Humid || tile.Biome == Biome.SemiHumid)
                    //{
                    //    riverCandidates.Add(OverWorld[Coord.ToIndex(pos.X, pos.Y, Width)]);
                    //}
                }
                else
                {
                    new Exception($"{tile.ID} is null.");
                }
            }
        }
Пример #10
0
        public void FindLocalOverworldTiles(OverworldTile startTile = null)
        {
            if (CurrentMap is OverworldMap)
            {
                startTile = startTile ?? GameServer.Overworld.GetOverworldTile(PlayerEntity.OriginX, PlayerEntity.OriginY);
            }

            List <OverworldTile> oldTiles = LocalOverworldTiles;

            LocalOverworldTiles = new List <OverworldTile>();

            if (CurrentMap is OverworldMap)
            {
                int minX = startTile.X - GameServer.Overworld.ChunkWidth;
                int minY = startTile.Y - GameServer.Overworld.ChunkHeight;
                int maxX = startTile.X + GameServer.Overworld.ChunkWidth;
                int maxY = startTile.Y + GameServer.Overworld.ChunkHeight;

                for (int x = minX; x <= maxX; x += GameServer.Overworld.ChunkWidth)
                {
                    for (int y = minY; y <= maxY; y += GameServer.Overworld.ChunkHeight)
                    {
                        OverworldTile tile = GameServer.Overworld.GetOverworldTile(x, y);
                        LocalOverworldTiles.Add(tile);

                        if (!tile.ChunksLoaded)
                        {
                            tile.LoadChunks();
                        }

                        if (!oldTiles.Contains(tile))
                        {
                            SendExteriorChunk(tile);
                        }
                        else
                        {
                            oldTiles.Remove(tile);
                        }
                    }
                }
            }

            foreach (OverworldTile tile in oldTiles)
            {
                SendDiscardChunk(tile);

                bool dispose = true;

                foreach (ClientBase client in GameServer.Clients)
                {
                    if (client != this && client.LocalOverworldTiles.Contains(tile))
                    {
                        dispose = false;
                        break;
                    }
                }

                if (dispose)
                {
                    tile.UnloadChunks();
                }
            }
        }