Ejemplo n.º 1
0
        private int ReadFloor(Internal.ByteArray message, int z, int skip)
        {
            for (int x = 0; x <= Constants.MapSizeX - 1; x++)
            {
                for (int y = 0; y <= Constants.MapSizeY - 1; y++)
                {
                    if (skip > 0)
                    {
                        skip--;
                    }
                    else
                    {
                        skip = ReadField(message, x, y, z);
                    }

                    UnityEngine.Vector3Int mapPosition      = new UnityEngine.Vector3Int(x, y, z);
                    UnityEngine.Vector3Int absolutePosition = WorldMapStorage.ToAbsolute(mapPosition);

                    if (absolutePosition.z == MiniMapStorage.PositionZ)
                    {
                        WorldMapStorage.UpdateMiniMap(mapPosition);
                        uint color = WorldMapStorage.GetMiniMapColour(mapPosition);
                        int  cost  = WorldMapStorage.GetMiniMapCost(mapPosition);
                        MiniMapStorage.UpdateField(absolutePosition, color, cost, false);
                    }
                }
            }

            return(skip);
        }
Ejemplo n.º 2
0
        private int ReadField(Internal.ByteArray message, int x, int y, int z)
        {
            var mapPosition      = new UnityEngine.Vector3Int(x, y, z);
            var absolutePosition = WorldMapStorage.ToAbsolute(mapPosition);

            int  typeOrId;
            int  stackPos  = 0;
            bool gotEffect = false;

            while (true)
            {
                typeOrId = message.ReadUnsignedShort();
                if (typeOrId >= 65280)
                {
                    break;
                }

                if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameEnvironmentEffect) && !gotEffect)
                {
                    var effectObject = AppearanceStorage.CreateEnvironmentalEffect((uint)typeOrId);
                    WorldMapStorage.SetEnvironmentalEffect(mapPosition, effectObject);
                    gotEffect = true;
                    continue;
                }

                if (typeOrId == AppearanceInstance.UnknownCreature || typeOrId == AppearanceInstance.OutdatedCreature ||
                    typeOrId == AppearanceInstance.Creature)
                {
                    var creature = ReadCreatureInstance(message, typeOrId, absolutePosition);

                    var @object = AppearanceStorage.CreateObjectInstance(AppearanceInstance.Creature, creature.ID);
                    if (stackPos < Constants.MapSizeW)
                    {
                        WorldMapStorage.AppendObject(mapPosition, @object);
                    }
                }
                else
                {
                    var @object = ReadObjectInstance(message, typeOrId);
                    if (stackPos < Constants.MapSizeW)
                    {
                        WorldMapStorage.AppendObject(mapPosition, @object);
                    }
                    else
                    {
                        throw new System.Exception("ProtocolGameUtility.ReadField: Expected creatures but received regular object.");
                    }
                }

                stackPos++;
            }

            return(typeOrId - 65280);
        }
Ejemplo n.º 3
0
        private int ReadArea(Internal.ByteArray message, int startx, int starty, int endx, int endy)
        {
            UnityEngine.Vector3Int position = WorldMapStorage.Position;

            int z, endz, zstep;

            if (position.z <= Constants.GroundLayer)
            {
                z     = 0;
                endz  = Constants.GroundLayer + 1;
                zstep = 1;
            }
            else
            {
                z     = 2 * Constants.UndergroundLayer;
                endz  = System.Math.Max(-1, position.z - Constants.MapMaxZ + 1);
                zstep = -1;
            }

            int skip = 0;

            for (; z != endz; z += zstep)
            {
                for (int x = startx; x <= endx; x++)
                {
                    for (int y = starty; y <= endy; y++)
                    {
                        if (skip > 0)
                        {
                            skip--;
                        }
                        else
                        {
                            skip = ReadField(message, x, y, z);
                        }

                        UnityEngine.Vector3Int mapPosition      = new UnityEngine.Vector3Int(x, y, z);
                        UnityEngine.Vector3Int absolutePosition = WorldMapStorage.ToAbsolute(mapPosition);

                        if (absolutePosition.z == MiniMapStorage.PositionZ)
                        {
                            WorldMapStorage.UpdateMiniMap(mapPosition);
                            uint color = WorldMapStorage.GetMiniMapColour(mapPosition);
                            int  cost  = WorldMapStorage.GetMiniMapCost(mapPosition);
                            MiniMapStorage.UpdateField(absolutePosition, color, cost, false);
                        }
                    }
                }
            }

            return(skip);
        }
Ejemplo n.º 4
0
        private void ParseMapBottomFloor(Internal.CommunicationStream message)
        {
            UnityEngine.Vector3Int position = WorldMapStorage.Position;
            position.x--; position.y--; position.z++;

            WorldMapStorage.Position = position;
            MiniMapStorage.Position  = position;

            if (position.z > Constants.GroundLayer + 1)
            {
                WorldMapStorage.ScrollMap(0, 0, 1);

                if (position.z <= Constants.MapMaxZ - Constants.UndergroundLayer)
                {
                    ProtocolGameExtentions.ReadFloor(message, 2 * Constants.UndergroundLayer, 0);
                }
            }
            else if (position.z == Constants.GroundLayer + 1)
            {
                WorldMapStorage.ScrollMap(0, 0, Constants.UndergroundLayer + 1);
                int skip = 0;
                for (int zposition = Constants.UndergroundLayer; zposition >= 0; zposition--)
                {
                    skip = ProtocolGameExtentions.ReadFloor(message, zposition, skip);
                }
            }

            Player.StopAutowalk(true);
            WorldMapStorage.InvalidateOnscreenMessages();

            var mapPosition = WorldMapStorage.ToMap(position);

            for (int x = 0; x < Constants.MapSizeX; x++)
            {
                for (int y = 0; y < Constants.MapSizeY; y++)
                {
                    mapPosition.x = x;
                    mapPosition.y = y;

                    var absolutePosition = WorldMapStorage.ToAbsolute(mapPosition);
                    WorldMapStorage.UpdateMiniMap(mapPosition);
                    uint color = WorldMapStorage.GetMiniMapColour(mapPosition);
                    int  cost  = WorldMapStorage.GetMiniMapCost(mapPosition);
                    MiniMapStorage.UpdateField(absolutePosition, color, cost, false);
                }
            }

            WorldMapStorage.CacheRefresh = true;
        }
Ejemplo n.º 5
0
        private void ParseMapBottomFloor(Internal.ByteArray message)
        {
            UnityEngine.Vector3Int position = WorldMapStorage.Position;
            position.x--; position.y--; position.z++;

            WorldMapStorage.Position = position;
            MiniMapStorage.Position  = position;

            if (position.z > Constants.GroundLayer + 1)
            {
                WorldMapStorage.ScrollMap(0, 0, 1);
                if (position.z <= Constants.MapMaxZ - Constants.UndergroundLayer)
                {
                    ReadFloor(message, 2 * Constants.UndergroundLayer, 0);
                }
            }
            else if (position.z == Constants.GroundLayer + 1)
            {
                WorldMapStorage.ScrollMap(0, 0, Constants.UndergroundLayer + 1);
                int skip = 0;
                for (int zposition = Constants.UndergroundLayer; zposition >= 0; zposition--)
                {
                    skip = ReadFloor(message, zposition, skip);
                }
            }

            Player.StopAutowalk(true);
            WorldMapStorage.InvalidateOnscreenMessages();

            UnityEngine.Vector3Int tmpPosition = WorldMapStorage.ToMap(position);

            for (int x = 0; x < Constants.MapSizeX; x++)
            {
                for (int y = 0; x < Constants.MapSizeY; y++)
                {
                    tmpPosition.x = x;
                    tmpPosition.y = y;

                    UnityEngine.Vector3Int absolutePosition = WorldMapStorage.ToAbsolute(tmpPosition);
                    WorldMapStorage.UpdateMiniMap(tmpPosition);
                    uint color = WorldMapStorage.GetMiniMapColour(tmpPosition);
                    int  cost  = WorldMapStorage.GetMiniMapCost(tmpPosition);
                    MiniMapStorage.UpdateField(absolutePosition, color, cost, false);
                }
            }
        }