Esempio n. 1
0
        private void ParseDeleteInContainer(Internal.CommunicationStream message)
        {
            byte   containerId = message.ReadUnsignedByte();
            ushort slot;

            Appearances.ObjectInstance appendObject = null;

            if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameContainerPagination))
            {
                slot = message.ReadUnsignedShort();
                ushort itemId = message.ReadUnsignedShort();

                if (itemId != 0)
                {
                    appendObject = ProtocolGameExtentions.ReadObjectInstance(message, itemId);
                }
            }
            else
            {
                slot = message.ReadUnsignedByte();
            }

            var containerView = ContainerStorage.GetContainerView(containerId);

            if (!!containerView)
            {
                containerView.RemoveObject(slot, appendObject);
            }
        }
Esempio n. 2
0
 private void ReadCyclopediaCharacterInfoBaseInformation(Internal.CommunicationStream message)
 {
     string characterName = message.ReadString();
     string vocation      = message.ReadString();
     ushort level         = message.ReadUnsignedShort();
     var    outfit        = ProtocolGameExtentions.ReadCreatureOutfit(message);
 }
Esempio n. 3
0
        private void ParseCreateOnMap(Internal.CommunicationStream message)
        {
            var absolutePosition = message.ReadPosition();

            if (!WorldMapStorage.IsVisible(absolutePosition, true))
            {
                throw new System.Exception("ProtocolGame.ParseCreateOnMap: Co-ordinate " + absolutePosition + " is out of range.");
            }

            var mapPosition = WorldMapStorage.ToMap(absolutePosition);
            int stackPos    = 255;

            if (OpenTibiaUnity.GameManager.ClientVersion >= 841)
            {
                stackPos = message.ReadUnsignedByte();
            }

            int typeOrId = message.ReadUnsignedShort();

            Appearances.ObjectInstance @object;
            if (typeOrId == Appearances.AppearanceInstance.Creature || typeOrId == Appearances.AppearanceInstance.OutdatedCreature || typeOrId == Appearances.AppearanceInstance.UnknownCreature)
            {
                var creature = ProtocolGameExtentions.ReadCreatureInstance(message, typeOrId, absolutePosition);
                if (creature.Id == Player.Id)
                {
                    Player.StopAutowalk(true);
                }

                @object = AppearanceStorage.CreateObjectInstance(Appearances.AppearanceInstance.Creature, creature.Id);
            }
            else
            {
                @object = ProtocolGameExtentions.ReadObjectInstance(message, typeOrId);
            }

            if (stackPos == 255)
            {
                WorldMapStorage.PutObject(mapPosition, @object);
            }
            else
            {
                if (stackPos > Constants.MapSizeW)
                {
                    throw new System.Exception("ProtocolGame.ParseCreateOnMap: Invalid stack position (" + stackPos + ").");
                }

                WorldMapStorage.InsertObject(mapPosition, stackPos, @object);
            }

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

            WorldMapStorage.CacheRefresh = true;
        }
Esempio n. 4
0
        private void ParsePreyData(Internal.CommunicationStream message)
        {
            int slot  = message.ReadUnsignedByte();
            var state = message.ReadEnum <PreySlotStates>();

            switch (state)
            {
            case PreySlotStates.Locked: {
                message.ReadEnum <PreySlotUnlockType>();
                break;
            }

            case PreySlotStates.Inactive: {
                break;
            }

            case PreySlotStates.Active: {
                string monsterName   = message.ReadString();
                var    monsterOutfit = ProtocolGameExtentions.ReadCreatureOutfit(message);
                var    bonusType     = message.ReadEnum <PreyBonusTypes>();
                int    bonusValue    = message.ReadUnsignedShort();
                int    bonusGrade    = message.ReadUnsignedByte();
                int    timeLeft      = message.ReadUnsignedShort();
                break;
            }

            case PreySlotStates.Selection: {
                byte size = message.ReadUnsignedByte();
                for (int i = 0; i < size; i++)
                {
                    string monsterName   = message.ReadString();
                    var    monsterOutfit = ProtocolGameExtentions.ReadCreatureOutfit(message);
                }
                break;
            }

            case PreySlotStates.SelectionChangeMonster: {
                var  bonusType  = message.ReadEnum <PreyBonusTypes>();
                int  bonusValue = message.ReadUnsignedShort();
                int  bonusGrade = message.ReadUnsignedByte();
                byte size       = message.ReadUnsignedByte();
                for (int i = 0; i < size; i++)
                {
                    string monsterName   = message.ReadString();
                    var    monsterOutfit = ProtocolGameExtentions.ReadCreatureOutfit(message);
                }
                break;
            }

            default:
                break;
            }

            message.ReadUnsignedShort(); // timeUntilFreeListReroll
            if (OpenTibiaUnity.GameManager.ClientVersion >= 1190)
            {
                message.ReadUnsignedByte(); // preyWildCards
            }
        }
Esempio n. 5
0
        private void ParseOpenContainer(Internal.CommunicationStream message)
        {
            byte   containerId     = message.ReadUnsignedByte();
            var    objectIcon      = ProtocolGameExtentions.ReadObjectInstance(message);
            string name            = message.ReadString();
            byte   nOfSlotsPerPage = message.ReadUnsignedByte(); // capacity of shown view
            bool   isSubContainer  = message.ReadBoolean();

            bool canUseDepotSearch    = false;
            bool isDragAndDropEnabled = true;
            bool isPaginationEnabled  = false;
            int  nOfTotalObjects;
            int  indexOfFirstObject = 0;
            int  nOfContentObjects; // objects in the current shown view //

            if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameContainerPagination))
            {
                if (OpenTibiaUnity.GameManager.ClientVersion >= 1220)
                {
                    canUseDepotSearch = message.ReadBoolean();
                }

                isDragAndDropEnabled = message.ReadBoolean();
                isPaginationEnabled  = message.ReadBoolean();
                nOfTotalObjects      = message.ReadUnsignedShort();
                indexOfFirstObject   = message.ReadUnsignedShort();
                nOfContentObjects    = message.ReadUnsignedByte();

                if (nOfContentObjects > nOfSlotsPerPage)
                {
                    throw new System.Exception("ProtocolGame.ParseOpenContainer: Number of content objects " + nOfContentObjects + " exceeds number of slots per page " + nOfSlotsPerPage);
                }

                if (nOfContentObjects > nOfTotalObjects)
                {
                    throw new System.Exception("ProtocolGame.ParseOpenContainer: Number of content objects " + nOfContentObjects + " exceeds number of total objects " + nOfTotalObjects);
                }
            }
            else
            {
                nOfContentObjects = message.ReadUnsignedByte();
                nOfTotalObjects   = nOfContentObjects;

                if (nOfContentObjects > nOfSlotsPerPage)
                {
                    throw new System.Exception("ProtocolGame.ParseOpenContainer: Number of content objects " + nOfContentObjects + " exceeds the capaciy " + nOfSlotsPerPage);
                }
            }

            var containerView = ContainerStorage.CreateContainerView(containerId, objectIcon, name, isSubContainer,
                                                                     isDragAndDropEnabled, isPaginationEnabled, nOfSlotsPerPage,
                                                                     nOfTotalObjects - nOfContentObjects, indexOfFirstObject, nOfContentObjects);

            for (int i = 0; i < nOfContentObjects; i++)
            {
                containerView.AddObject(indexOfFirstObject + i, ProtocolGameExtentions.ReadObjectInstance(message));
            }
        }
Esempio n. 6
0
        public void ParseKillTracking(Internal.CommunicationStream message)
        {
            string name      = message.ReadString();
            var    outfit    = ProtocolGameExtentions.ReadCreatureOutfit(message);
            int    lootCount = message.ReadUnsignedByte();

            for (int i = 0; i < lootCount; i++)
            {
                var @object = ProtocolGameExtentions.ReadObjectInstance(message);
            }
        }
Esempio n. 7
0
        private void ParseMapLeftRow(Internal.CommunicationStream message)
        {
            UnityEngine.Vector3Int position = WorldMapStorage.Position;
            position.x--;

            WorldMapStorage.Position = position;
            MiniMapStorage.Position  = position;
            WorldMapStorage.ScrollMap(1, 0);
            WorldMapStorage.InvalidateOnscreenMessages();
            ProtocolGameExtentions.ReadArea(message, 0, 0, 0, Constants.MapSizeY - 1);
            WorldMapStorage.CacheRefresh = true;
        }
Esempio n. 8
0
        private void ParseFullMap(Internal.CommunicationStream message)
        {
            UnityEngine.Vector3Int position = message.ReadPosition();

            Player.StopAutowalk(true);
            CreatureStorage.MarkAllOpponentsVisible(false);
            MiniMapStorage.Position = position;
            WorldMapStorage.ResetMap();
            WorldMapStorage.InvalidateOnscreenMessages();
            WorldMapStorage.Position = position;

            ProtocolGameExtentions.ReadArea(message, 0, 0, Constants.MapSizeX - 1, Constants.MapSizeY - 1);
            WorldMapStorage.Valid        = true;
            WorldMapStorage.CacheRefresh = true;
        }
Esempio n. 9
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;
        }
Esempio n. 10
0
        private void ParseCreateInContainer(Internal.CommunicationStream message)
        {
            byte   containerId = message.ReadUnsignedByte();
            ushort slot        = 0;

            if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameContainerPagination))
            {
                slot = message.ReadUnsignedShort();
            }
            var @object = ProtocolGameExtentions.ReadObjectInstance(message);

            var containerView = ContainerStorage.GetContainerView(containerId);

            if (!!containerView)
            {
                containerView.AddObject(slot, @object);
            }
        }
Esempio n. 11
0
        private void ParseInspectionList(Internal.CommunicationStream message)
        {
            bool isPlayer = message.ReadBoolean();

            int size = message.ReadUnsignedByte();

            for (int i = 0; i < size; i++)
            {
                var @object = ProtocolGameExtentions.ReadObjectInstance(message);
                if (isPlayer)
                {
                    var slot = message.ReadEnum <ClothSlots>();
                }

                int imbuementSlots = message.ReadUnsignedByte();
                for (int j = 0; j < imbuementSlots; j++)
                {
                    int imbuementId = message.ReadUnsignedByte();
                }

                int details = message.ReadUnsignedByte();
                for (int j = 0; j < details; j++)
                {
                    string name        = message.ReadString();
                    string description = message.ReadString();
                }
            }

            if (isPlayer)
            {
                string playerName = message.ReadString();
                var    outfit     = ProtocolGameExtentions.ReadCreatureOutfit(message);

                int details = message.ReadUnsignedByte();
                for (int j = 0; j < details; j++)
                {
                    string name        = message.ReadString();
                    string description = message.ReadString();
                }
            }
        }
Esempio n. 12
0
        private void ParseFieldData(Internal.CommunicationStream message)
        {
            UnityEngine.Vector3Int absolutePosition = message.ReadPosition();
            if (!WorldMapStorage.IsVisible(absolutePosition, true))
            {
                throw new System.Exception("ProtocolGame.ParseFieldData: Co-ordinate " + absolutePosition + " is out of range.");
            }

            var mapPosition = WorldMapStorage.ToMap(absolutePosition);

            WorldMapStorage.ResetField(mapPosition, true, false);
            ProtocolGameExtentions.ReadField(message, mapPosition.x, mapPosition.y, mapPosition.z);

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

            WorldMapStorage.CacheRefresh = true;
        }
Esempio n. 13
0
 private void ParseItemLooted(Internal.CommunicationStream message)
 {
     var    @object = ProtocolGameExtentions.ReadObjectInstance(message);
     string name    = message.ReadString();
 }
Esempio n. 14
0
        private void ParseChangeOnMap(Internal.CommunicationStream message)
        {
            int x = message.ReadUnsignedShort();

            Appearances.ObjectInstance objectInstance;
            Creatures.Creature         creature = null;

            UnityEngine.Vector3Int absolutePosition;
            UnityEngine.Vector3Int mapPosition;

            if (x != 65535)
            {
                absolutePosition = message.ReadPosition(x);
                if (!WorldMapStorage.IsVisible(absolutePosition, true))
                {
                    throw new System.Exception("ProtocolGame.ParseChangeOnMap: Co-ordinate " + absolutePosition + " is out of range.");
                }

                mapPosition = WorldMapStorage.ToMap(absolutePosition);
                int stackPos = message.ReadUnsignedByte();
                if (!(objectInstance = WorldMapStorage.GetObject(mapPosition, stackPos)))
                {
                    throw new System.Exception("ProtocolGame.ParseChangeOnMap: Object not found.");
                }

                if (objectInstance.IsCreature && !(creature = CreatureStorage.GetCreature(objectInstance.Data)))
                {
                    throw new System.Exception("ProtocolGame.ParseChangeOnMap: Creature not found: " + objectInstance.Data);
                }

                if (!!creature)
                {
                    CreatureStorage.MarkOpponentVisible(creature, false);
                }

                int typeOrId = message.ReadUnsignedShort();
                if (typeOrId == Appearances.AppearanceInstance.UnknownCreature ||
                    typeOrId == Appearances.AppearanceInstance.OutdatedCreature ||
                    typeOrId == Appearances.AppearanceInstance.Creature)
                {
                    creature       = ProtocolGameExtentions.ReadCreatureInstance(message, typeOrId, absolutePosition);
                    objectInstance = AppearanceStorage.CreateObjectInstance(Appearances.AppearanceInstance.Creature, creature.Id);
                }
                else
                {
                    objectInstance = ProtocolGameExtentions.ReadObjectInstance(message, typeOrId);
                }

                WorldMapStorage.ChangeObject(mapPosition, stackPos, objectInstance);
            }
            else
            {
                uint creatureId = message.ReadUnsignedInt();

                if (!(creature = CreatureStorage.GetCreature(creatureId)))
                {
                    throw new System.Exception("ProtocolGame.ParseChangeOnMap: Creature " + creatureId + " not found");
                }

                absolutePosition = creature.Position;
                if (!WorldMapStorage.IsVisible(absolutePosition, true))
                {
                    throw new System.Exception("ProtocolGame.ParseChangeOnMap: Co-ordinate " + absolutePosition + " is out of range.");
                }

                mapPosition = WorldMapStorage.ToMap(absolutePosition);
                CreatureStorage.MarkOpponentVisible(creature, false);

                int otherType = message.ReadUnsignedShort();
                if (otherType == Appearances.AppearanceInstance.Creature || otherType == Appearances.AppearanceInstance.OutdatedCreature ||
                    otherType == Appearances.AppearanceInstance.UnknownCreature)
                {
                    creature = ProtocolGameExtentions.ReadCreatureInstance(message, otherType);
                }
                else
                {
                    throw new System.Exception("ProtocolGame.ParseChangeOnMap: Received object of type " + otherType + " when a creature was expected.");
                }
            }

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

            WorldMapStorage.CacheRefresh = true;
        }