Exemplo n.º 1
0
        private void ParseMissleEffect(Internal.ByteArray message)
        {
            var  fromPosition = message.ReadPosition();
            var  toPosition   = message.ReadPosition();
            byte missleId     = message.ReadUnsignedByte();

            var missle = AppearanceStorage.CreateMissileInstance(missleId, fromPosition, toPosition);

            if (!missle)
            {
                throw new System.Exception("ProtocolGame.ParseMissleEffect: Unknown missle id: " + missleId);
            }

            WorldMapStorage.AppendEffect(fromPosition, missle);
        }
Exemplo n.º 2
0
        private void ParseTextEffect(Internal.ByteArray message)
        {
            var    position = message.ReadPosition();
            int    color    = message.ReadUnsignedByte();
            string text     = message.ReadString();

            WorldMapStorage.AddTextualEffect(position, color, text);
        }
Exemplo n.º 3
0
        private void ParseCreateOnMap(Internal.ByteArray 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 = ReadCreatureInstance(message, typeOrId, absolutePosition);
                if (creature.Id == Player.Id)
                {
                    Player.StopAutowalk(true);
                }

                @object = AppearanceStorage.CreateObjectInstance(Appearances.AppearanceInstance.Creature, creature.Id);
            }
            else
            {
                @object = 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);
            }
        }
Exemplo n.º 4
0
        private void ParseAutomapFlag(Internal.ByteArray message)
        {
            var absolutePosition = message.ReadPosition();
            int icon             = message.ReadUnsignedByte();
            var description      = message.ReadString();

            bool remove = false;

            if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameMinimapRemove))
            {
                remove = message.ReadBoolean();
            }
        }
Exemplo n.º 5
0
        private void ParseFullMap(Internal.ByteArray message)
        {
            UnityEngine.Vector3Int position = message.ReadPosition();

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

            ReadArea(message, 0, 0, Constants.MapSizeX - 1, Constants.MapSizeY - 1);
            WorldMapStorage.Valid = true;
        }
Exemplo n.º 6
0
        private void ParseGraphicalEffect(Internal.ByteArray message)
        {
            var  position = message.ReadPosition();
            byte effectId = message.ReadUnsignedByte();

            var effect = AppearanceStorage.CreateEffectInstance(effectId);

            if (!effect)
            {
                throw new System.Exception("ProtocolGame.ParseGraphicalEffect: Unknown effect id: " + effectId);
            }

            WorldMapStorage.AppendEffect(position, effect);
        }
Exemplo n.º 7
0
        private void ParseFieldData(Internal.ByteArray 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);
            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);
            }
        }
Exemplo n.º 8
0
        private void ParseTextMessage(Internal.ByteArray message)
        {
            var mode = TranslateMessageModeFromServer(message.ReadUnsignedByte());

            try {
                switch (mode)
                {
                case MessageModeType.ChannelManagement:
                    int    channelId = message.ReadUnsignedShort();
                    string text      = message.ReadString();
                    // TODO name filter
                    //var regex = new System.Text.RegularExpressions.Regex(@"^(.+?) invites you to |^You have been excluded from the channel ([^']+)'s Channel\.$");
                    //var match = regex.Match(text);
                    //string speaker = match != null && match.Success ? match.Value : null;

                    WorldMapStorage.AddOnscreenMessage(null, -1, null, 0, mode, text);
                    ChatStorage.AddChannelMessage(channelId, -1, null, 0, mode, text);
                    break;

                case MessageModeType.Guild:
                case MessageModeType.PartyManagement:
                case MessageModeType.Party:
                    channelId = message.ReadUnsignedShort();
                    text      = message.ReadString();
                    WorldMapStorage.AddOnscreenMessage(null, -1, null, 0, mode, text);
                    ChatStorage.AddChannelMessage(channelId, -1, null, 0, mode, text);
                    break;

                case MessageModeType.Login:
                case MessageModeType.Admin:
                case MessageModeType.Game:
                case MessageModeType.GameHighlight:
                case MessageModeType.Failure:
                case MessageModeType.Look:
                case MessageModeType.Status:
                case MessageModeType.Loot:
                case MessageModeType.TradeNpc:
                case MessageModeType.HotkeyUse:
                    channelId = -1;
                    text      = message.ReadString();
                    WorldMapStorage.AddOnscreenMessage(null, -1, null, 0, mode, text);
                    ChatStorage.AddChannelMessage(channelId, -1, null, 0, mode, text);
                    break;

                case MessageModeType.Market:
                    text = message.ReadString();
                    // TODO: market
                    break;

                case MessageModeType.Report:
                    // TODO
                    //ReportWidget.s_ReportTimestampReset();
                    text = message.ReadString();
                    WorldMapStorage.AddOnscreenMessage(null, -1, null, 0, mode, text);
                    ChatStorage.AddChannelMessage(-1, -1, null, 0, mode, text);
                    break;

                case MessageModeType.DamageDealed:
                case MessageModeType.DamageReceived:
                case MessageModeType.DamageOthers:
                    Vector3Int absolutePosition = message.ReadPosition();
                    int        value            = message.ReadInt();
                    int        color            = message.ReadUnsignedByte();
                    if (value > 0)
                    {
                        WorldMapStorage.AddOnscreenMessage(absolutePosition, -1, null, 0, mode, value, color);
                    }

                    value = message.ReadInt();
                    color = message.ReadUnsignedByte();
                    if (value > 0)
                    {
                        WorldMapStorage.AddOnscreenMessage(absolutePosition, -1, null, 0, mode, value, color);
                    }

                    text = message.ReadString();
                    ChatStorage.AddChannelMessage(-1, -1, null, 0, mode, text);
                    break;

                case MessageModeType.Heal:
                case MessageModeType.Mana:
                case MessageModeType.Exp:
                case MessageModeType.HealOthers:
                case MessageModeType.ExpOthers:
                    absolutePosition = message.ReadPosition();
                    value            = message.ReadInt();
                    color            = message.ReadUnsignedByte();
                    WorldMapStorage.AddOnscreenMessage(absolutePosition, -1, null, 0, mode, value, color);

                    text = message.ReadString();
                    ChatStorage.AddChannelMessage(-1, -1, null, 0, mode, text);
                    break;

                default:
                    text = message.ReadString();
                    ChatStorage.AddChannelMessage(-1, -1, null, 0, mode, text);
                    break;
                }
            } catch (System.Exception e) {
                throw new System.Exception("ProtocolGame.ParseTextMessage: Failed to add message of type " + mode + ": " + e.Message + "\n" + e.StackTrace);
            }
        }
Exemplo n.º 9
0
        private void ParseTalk(Internal.ByteArray message)
        {
            uint statementId = 0;

            if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameMessageStatements))
            {
                statementId = message.ReadUnsignedInt();
            }

            string speaker      = message.ReadString();
            ushort speakerLevel = 0;

            if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameMessageLevel))
            {
                speakerLevel = message.ReadUnsignedShort();
            }

            int             rawMode = message.ReadUnsignedByte();
            MessageModeType mode    = TranslateMessageModeFromServer(rawMode);

            Vector3Int?absolutePosition = null;

            Utils.UnionStrInt channelId = null;

            switch (mode)
            {
            case MessageModeType.Say:
            case MessageModeType.Whisper:
            case MessageModeType.Yell:
                absolutePosition = message.ReadPosition();
                channelId        = Chat.ChatStorage.LocalChannelId;
                break;

            case MessageModeType.PrivateFrom:
                channelId = speaker;
                break;

            case MessageModeType.Channel:
            case MessageModeType.ChannelManagement:
            case MessageModeType.ChannelHighlight:
                channelId = message.ReadUnsignedShort();
                break;

            case MessageModeType.Spell:
                absolutePosition = message.ReadPosition();
                channelId        = Chat.ChatStorage.LocalChannelId;
                break;

            case MessageModeType.NpcFromStartBlock:
                absolutePosition = message.ReadPosition();
                break;

            case MessageModeType.NpcFrom:
                break;

            case MessageModeType.GamemasterBroadcast:
                break;

            case MessageModeType.GamemasterChannel:
                channelId = message.ReadUnsignedShort();
                break;

            case MessageModeType.GamemasterPrivateFrom:
                channelId = speaker;
                break;

            case MessageModeType.BarkLow:
            case MessageModeType.BarkLoud:
            case MessageModeType.MonsterSay:
            case MessageModeType.MonsterYell:
                absolutePosition = message.ReadPosition();
                channelId        = -1;
                break;

            case MessageModeType.Game:
                break;

            case MessageModeType.RVRAnswer:
            case MessageModeType.RVRContinue:
                channelId = Chat.ChatStorage.RVRChannelId;
                break;

            case MessageModeType.RVRChannel:
                message.ReadUnsignedInt();
                channelId = Chat.ChatStorage.RVRChannelId;
                break;

            default:
                throw new System.Exception(string.Format("ProtocolGame.ParseTalk: invalid message mode (raw = {0}, mode = {1})", rawMode, mode));
            }

            string text = message.ReadString();

            if (mode != MessageModeType.NpcFromStartBlock && mode != MessageModeType.NpcFrom)
            {
                try {
                    WorldMapStorage.AddOnscreenMessage(absolutePosition, (int)statementId, speaker, speakerLevel, mode, text);
                    ChatStorage.AddChannelMessage(channelId, (int)statementId, speaker, speakerLevel, mode, text);
                } catch (System.Exception e) {
                    throw new System.Exception("ProtocolGame.ParseTalk: Failed to add message: " + e.Message + "\n" + e.StackTrace);
                }
            }
            else if (mode == MessageModeType.NpcFromStartBlock)
            {
                MessageStorage.StartMessageBlock(speaker, absolutePosition, text);
            }
            else if (mode == MessageModeType.NpcFrom)
            {
                MessageStorage.AddTextToBlock(speaker, text);
            }
        }
Exemplo n.º 10
0
        private void ParseCreatureMove(Internal.ByteArray message)
        {
            int x = message.ReadUnsignedShort();

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

            Appearances.ObjectInstance @object;
            Creatures.Creature         creature;

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

                oldMapPosition = WorldMapStorage.ToMap(oldAbsolutePosition);
                stackPos       = message.ReadUnsignedByte();
                @object        = WorldMapStorage.GetObject(oldMapPosition, stackPos);
                if (!@object || [email protected] || !(creature = CreatureStorage.GetCreature(@object.Data)))
                {
                    throw new System.Exception("ProtocolGame.ParseCreatureMove: No creature at position " + oldAbsolutePosition);
                }
            }
            else
            {
                uint creatureId = message.ReadUnsignedInt();
                @object = AppearanceStorage.CreateObjectInstance(Appearances.AppearanceInstance.Creature, creatureId);
                if (!(creature = CreatureStorage.GetCreature(creatureId)))
                {
                    throw new System.Exception("ProtocolGame.ParseCreatureMove: Creature " + creatureId + " not found");
                }

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

                oldMapPosition = WorldMapStorage.ToMap(oldAbsolutePosition);
            }

            var newAbsolutePosition = message.ReadPosition();

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

            var newMapPosition = WorldMapStorage.ToMap(newAbsolutePosition);
            var 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 = WorldMapStorage.GetObject(newMapPosition, 0)) || !otherObj.Type || !otherObj.Type.IsGround))
            {
                throw new System.Exception("ProtocolGame.ParseCreatureMove: Target field " + newAbsolutePosition + " has no BANK.");
            }

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

            WorldMapStorage.PutObject(newMapPosition, @object);
            creature.Position = newAbsolutePosition;

            if (pushMovement)
            {
                if (creature.Id == Player.Id)
                {
                    Player.StopAutowalk(true);
                }

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

                if (creature.Id != Player.Id)
                {
                    creature.StopMovementAnimation();
                }
            }
            else
            {
                creature.StartMovementAnimation(delta.x, delta.y, (int)otherObj.Type.GroundSpeed);
            }

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

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

            if (newAbsolutePosition.z == MiniMapStorage.PositionZ)
            {
                WorldMapStorage.UpdateMiniMap(newMapPosition);
                uint color = WorldMapStorage.GetMiniMapColour(newMapPosition);
                int  cost  = WorldMapStorage.GetMiniMapCost(newMapPosition);
                MiniMapStorage.UpdateField(newAbsolutePosition, color, cost, false);
            }
        }
Exemplo n.º 11
0
        private void ParseDeleteOnMap(Internal.ByteArray 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.ParseDeleteOnMap: Co-oridnate ({absolutePosition.x}, {absolutePosition.y}, {absolutePosition.z}) is out of range.");
                }

                mapPosition = WorldMapStorage.ToMap(absolutePosition);

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

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

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

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

                mapPosition = WorldMapStorage.ToMap(absolutePosition);
            }

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

            if (absolutePosition.z == MiniMapStorage.Position.z)
            {
                WorldMapStorage.UpdateMiniMap(mapPosition);
                uint color = WorldMapStorage.GetMiniMapColour(mapPosition);
                int  cost  = WorldMapStorage.GetMiniMapCost(mapPosition);
                MiniMapStorage.UpdateField(absolutePosition, color, cost, false);
            }
        }
Exemplo n.º 12
0
        private void ParseChangeOnMap(Internal.ByteArray 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       = ReadCreatureInstance(message, typeOrId, absolutePosition);
                    objectInstance = AppearanceStorage.CreateObjectInstance(Appearances.AppearanceInstance.Creature, creature.Id);
                }
                else
                {
                    objectInstance = 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 = 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);
            }
        }