Esempio n. 1
0
        private void ParseSetTactics(InputMessage message)
        {
            int attackMode = message.GetU8();
            int chaseMode  = message.GetU8();
            int secureMode = message.GetU8();
            int pvpMode    = message.GetU8();

            OpenTibiaUnity.GameManager.OnTacticsChangeEvent.Invoke(
                (CombatAttackModes)attackMode,
                (CombatChaseModes)chaseMode,
                secureMode == 1,
                (CombatPvPModes)pvpMode);
        }
Esempio n. 2
0
        private void ParsePreyData(InputMessage message)
        {
            byte slot  = message.GetU8();
            byte state = message.GetU8();

            switch (state)
            {
            case 0: {
                byte lockType = message.GetU8();
                break;
            }

            case 1: {
                break;
            }

            case 2: {
                message.GetString();
                ReadCreatureOutfit(message);
                message.GetU8();
                message.GetU16();
                message.GetU8();
                message.GetU16();
                break;
            }

            case 3: {
                byte size = message.GetU8();
                for (int i = 0; i < size; i++)
                {
                    message.GetString();
                    ReadCreatureOutfit(message);
                }
                break;
            }

            case 4: {
                message.GetU8();
                message.GetU16();
                message.GetU8();
                byte size = message.GetU8();
                for (int i = 0; i < size; i++)
                {
                    message.GetString();
                    ReadCreatureOutfit(message);
                }
                break;
            }

            default:
                break;
            }

            message.GetU16();
        }
Esempio n. 3
0
        private void ParseVipAdd(InputMessage message)
        {
            uint   creatureID  = message.GetU32();
            string name        = message.GetString();
            string desc        = message.GetString();
            uint   icon        = message.GetU32();
            byte   notifyLogin = message.GetU8();
            byte   status      = message.GetU8();

            byte groups = message.GetU8();

            for (int i = 0; i < groups; i++)
            {
                // parse groups
            }
        }
Esempio n. 4
0
        private void ParseCancelWalk(InputMessage message)
        {
            int direction = message.GetU8();

            var absolutePosition = m_Player.Position;

            if (absolutePosition == m_LastSnapback)
            {
                m_SnapbackCount++;
            }
            else
            {
                m_SnapbackCount = 0;
            }

            m_LastSnapback.Set(absolutePosition.x, absolutePosition.y, absolutePosition.z);
            if (m_SnapbackCount >= 16)
            {
                m_Player.StopAutowalk(true);
                m_CreatureStorage.SetAttackTarget(null, false);
                SendCancel();
                m_SnapbackCount = 0;
            }

            m_Player.AbortAutowalk((Directions)direction);
        }
Esempio n. 5
0
        private void ParseCreateOnMap(InputMessage message)
        {
            UnityEngine.Vector3Int absolutePosition = message.GetPosition();
            if (!m_WorldMapStorage.IsVisible(absolutePosition, true))
            {
                throw new System.Exception("ProtocolGame.ParseCreateOnMap: Co-ordinate " + absolutePosition + " is out of range.");
            }

            UnityEngine.Vector3Int mapPosition = m_WorldMapStorage.ToMap(absolutePosition);
            int stackPos = message.GetU8();
            int typeOrId = message.GetU16();

            Appearances.ObjectInstance obj;
            if (typeOrId == Appearances.AppearanceInstance.Creature || typeOrId == Appearances.AppearanceInstance.OutdatedCreature || typeOrId == Appearances.AppearanceInstance.UnknownCreature)
            {
                Creatures.Creature creature = ReadCreatureInstance(message, typeOrId);
                if (creature.ID == m_Player.ID)
                {
                    m_Player.StopAutowalk(true);
                }

                obj = m_AppearanceStorage.CreateObjectInstance(Appearances.AppearanceInstance.Creature, creature.ID);
            }
            else
            {
                obj = ReadObjectInstance(message, typeOrId);
            }

            if (stackPos == 255)
            {
                m_WorldMapStorage.PutObject(mapPosition, obj);
            }
            else
            {
                if (stackPos > Constants.MapSizeW)
                {
                    throw new System.Exception("ProtocolGame.ParseCreateOnMap: Invalid position.");
                }

                m_WorldMapStorage.InsertObject(mapPosition, stackPos, obj);
            }

            if (absolutePosition.z == m_MiniMapStorage.PositionZ)
            {
                m_WorldMapStorage.UpdateMiniMap(mapPosition);
                uint color = m_WorldMapStorage.GetMiniMapColour(mapPosition);
                int  cost  = m_WorldMapStorage.GetMiniMapCost(mapPosition);
                m_MiniMapStorage.UpdateField(absolutePosition, color, cost, false);
            }
        }
Esempio n. 6
0
        private void ParseTrackedQuestFlags(InputMessage message)
        {
            bool full = message.GetU8() == 1;

            if (full)
            {
                int unknown2 = message.GetU8();
                int size     = message.GetU8();
                for (int i = 0; i < size; i++)
                {
                    int    missionId          = message.GetU16();
                    string questName          = message.GetString();
                    string missionName        = message.GetString();
                    string missionDescription = message.GetString();
                }
            }
            else
            {
                int    missionId   = message.GetU16();
                string questName   = message.GetString();
                string missionName = message.GetString();
            }
        }
Esempio n. 7
0
 private void ParseVipState(InputMessage message)
 {
     uint creatureId = message.GetU32();
     byte status     = message.GetU8();
 }
Esempio n. 8
0
 private void ParseOtclientExtendedOpcode(InputMessage message)
 {
     message.GetU8();
     message.GetString();
 }
Esempio n. 9
0
        private void ParseCreatureMove(InputMessage message)
        {
            int x = message.GetU16();

            UnityEngine.Vector3Int oldAbsolutePosition;
            UnityEngine.Vector3Int oldMapPosition;
            int stackPos = -1;

            Appearances.ObjectInstance obj;
            Creatures.Creature         creature;

            if (x != 65535)
            {
                oldAbsolutePosition = message.GetPosition(x);
                if (!m_WorldMapStorage.IsVisible(oldAbsolutePosition, true))
                {
                    throw new System.Exception("ProtocolGame.ParseCreateOnMap: Start Co-ordinate " + oldAbsolutePosition + " is out of range.");
                }

                oldMapPosition = m_WorldMapStorage.ToMap(oldAbsolutePosition);
                stackPos       = message.GetU8();
                obj            = m_WorldMapStorage.GetObject(oldMapPosition, stackPos);
                if (!obj || !obj.IsCreature || !(creature = m_CreatureStorage.GetCreature(obj.Data)))
                {
                    throw new System.Exception("ProtocolGame.ParseCreatureMove: no creature at position " + oldAbsolutePosition);
                }
            }
            else
            {
                uint creatureID = message.GetU32();
                obj = m_AppearanceStorage.CreateObjectInstance(Appearances.AppearanceInstance.Creature, creatureID);
                if (!(creature = m_CreatureStorage.GetCreature(creatureID)))
                {
                    throw new System.Exception("ProtocolGame.ParseCreatureMove: Creature " + creatureID + " not found");
                }

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

                oldMapPosition = m_WorldMapStorage.ToMap(oldAbsolutePosition);
            }

            UnityEngine.Vector3Int newAbsolutePosition = message.GetPosition();
            if (!m_WorldMapStorage.IsVisible(newAbsolutePosition, true))
            {
                throw new System.Exception("ProtocolGame.ParseCreateOnMap: Target Co-ordinate " + oldAbsolutePosition + " is out of range.");
            }

            UnityEngine.Vector3Int newMapPosition = m_WorldMapStorage.ToMap(newAbsolutePosition);
            UnityEngine.Vector3Int delta          = newMapPosition - oldMapPosition;

            // if the movement is not actually a move (usually he is teleported)
            bool pushMovement = delta.z != 0 || System.Math.Abs(delta.x) > 1 || System.Math.Abs(delta.y) > 1;

            Appearances.ObjectInstance otherObj = null;
            if (!pushMovement && (!(otherObj = m_WorldMapStorage.GetObject(newMapPosition, 0)) || !otherObj.Type || !otherObj.Type.IsBank))
            {
                throw new System.Exception("ProtocolGame.ParseCreateOnMap: Target field " + newAbsolutePosition + " has no BANK.");
            }

            if (x != 65535)
            {
                m_WorldMapStorage.DeleteObject(oldMapPosition, stackPos);
            }

            m_WorldMapStorage.PutObject(newMapPosition, obj);
            creature.Position = newAbsolutePosition;

            if (pushMovement)
            {
                if (creature.ID == m_Player.ID)
                {
                    m_Player.StopAutowalk(true);
                }

                if (delta.x > 0)
                {
                    creature.Direction = Directions.East;
                }
                else if (delta.x < 0)
                {
                    creature.Direction = Directions.West;
                }
                else if (delta.y < 0)
                {
                    creature.Direction = Directions.North;
                }
                else if (delta.y > 0)
                {
                    creature.Direction = Directions.South;
                }

                if (creature.ID != m_Player.ID)
                {
                    creature.StopMovementAnimation();
                }
            }
            else
            {
                creature.StartMovementAnimation(delta.x, delta.y, (int)otherObj.Type.Waypoints);
            }

            m_CreatureStorage.MarkOpponentVisible(creature, true);
            m_CreatureStorage.InvalidateOpponents();

            if (oldAbsolutePosition.z == m_MiniMapStorage.PositionZ)
            {
                m_WorldMapStorage.UpdateMiniMap(oldMapPosition);
                uint color = m_WorldMapStorage.GetMiniMapColour(oldMapPosition);
                int  cost  = m_WorldMapStorage.GetMiniMapCost(oldMapPosition);
                m_MiniMapStorage.UpdateField(oldAbsolutePosition, color, cost, false);
            }

            if (newAbsolutePosition.z == m_MiniMapStorage.PositionZ)
            {
                m_WorldMapStorage.UpdateMiniMap(newMapPosition);
                uint color = m_WorldMapStorage.GetMiniMapColour(newMapPosition);
                int  cost  = m_WorldMapStorage.GetMiniMapCost(newMapPosition);
                m_MiniMapStorage.UpdateField(newAbsolutePosition, color, cost, false);
            }
        }
Esempio n. 10
0
        private void ParseDeleteOnMap(InputMessage message)
        {
            int x = message.GetU16();

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

            UnityEngine.Vector3Int absolutePosition;
            UnityEngine.Vector3Int mapPosition;

            if (x != 0xFFFF)
            {
                absolutePosition = message.GetPosition(x);

                if (!m_WorldMapStorage.IsVisible(absolutePosition, true))
                {
                    throw new System.Exception($"ProtocolGame.ParseDeleteOnMap: Co-oridnate ({absolutePosition.x}, {absolutePosition.y}, {absolutePosition.z}) is out of range.");
                }

                mapPosition = m_WorldMapStorage.ToMap(absolutePosition);

                int stackPos = message.GetU8();
                if (!(objectInstance = m_WorldMapStorage.GetObject(mapPosition, stackPos)))
                {
                    throw new System.Exception($"ProtocolGame.ParseDeleteOnMap: Object not found.");
                }

                if (objectInstance.ID == Appearances.AppearanceInstance.Creature && (creature = m_CreatureStorage.GetCreature(objectInstance.Data)) == null)
                {
                    throw new System.Exception($"ProtocolGame.ParseDeleteOnMap: Creature not found.");
                }

                m_WorldMapStorage.DeleteObject(mapPosition, stackPos);
            }
            else
            {
                uint creatureId = message.GetU32();
                if ((creature = m_CreatureStorage.GetCreature(creatureId)) == null)
                {
                    throw new System.Exception($"ProtocolGame.ParseDeleteOnMap: Object not found.");
                }

                absolutePosition = creature.Position;
                if (!m_WorldMapStorage.IsVisible(absolutePosition, true))
                {
                    throw new System.Exception($"ProtocolGame.ParseDeleteOnMap: Co-oridnate ({absolutePosition.x}, {absolutePosition.y}, {absolutePosition.z}) is out of range.");
                }

                mapPosition = m_WorldMapStorage.ToMap(absolutePosition);
            }

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

            if (absolutePosition.z == m_MiniMapStorage.Position.z)
            {
                m_WorldMapStorage.UpdateMiniMap(mapPosition);
                uint color = m_WorldMapStorage.GetMiniMapColour(mapPosition);
                int  cost  = m_WorldMapStorage.GetMiniMapCost(mapPosition);
                m_MiniMapStorage.UpdateField(absolutePosition, color, cost, false);
            }
        }
Esempio n. 11
0
        private void ParseChangeOnMap(InputMessage message)
        {
            int x = message.GetU16();

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

            UnityEngine.Vector3Int absolutePosition;
            UnityEngine.Vector3Int mapPosition;

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

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

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

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

                int typeOrId = message.GetU16();
                if (typeOrId == Appearances.AppearanceInstance.UnknownCreature ||
                    typeOrId == Appearances.AppearanceInstance.OutdatedCreature ||
                    typeOrId == Appearances.AppearanceInstance.Creature)
                {
                    creature       = ReadCreatureInstance(message, typeOrId, absolutePosition);
                    objectInstance = m_AppearanceStorage.CreateObjectInstance(Appearances.AppearanceInstance.Creature, creature.ID);
                }
                else
                {
                    objectInstance = ReadObjectInstance(message, typeOrId);
                }

                m_WorldMapStorage.ChangeObject(mapPosition, stackPos, objectInstance);
            }
            else
            {
                uint creatureID = message.GetU32();
                if (!(creature = m_CreatureStorage.GetCreature(creatureID)))
                {
                    throw new System.Exception("ProtocolGame.ParseChangeOnMap: Creature " + creatureID + " not found");
                }

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

                mapPosition = m_WorldMapStorage.ToMap(absolutePosition);
                m_CreatureStorage.MarkOpponentVisible(creature, false);

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

            if (absolutePosition.z == m_MiniMapStorage.PositionZ)
            {
                m_WorldMapStorage.UpdateMiniMap(mapPosition);
                uint color = m_WorldMapStorage.GetMiniMapColour(mapPosition);
                int  cost  = m_WorldMapStorage.GetMiniMapCost(mapPosition);
                m_MiniMapStorage.UpdateField(absolutePosition, color, cost, false);
            }
        }
Esempio n. 12
0
 private void ParsePreyFreeListRerollAvailability(InputMessage message)
 {
     byte   slot    = message.GetU8();
     ushort minutes = message.GetU16();
 }
Esempio n. 13
0
 private void ParsePreyTimeLeft(InputMessage message)
 {
     byte   slot    = message.GetU8();
     ushort minutes = message.GetU16();
 }