コード例 #1
0
        private void ParseCreatureMarks(Internal.CommunicationStream message)
        {
            int length;

            if (OpenTibiaUnity.GameManager.ClientVersion >= 1035)
            {
                length = 1;
            }
            else
            {
                length = message.ReadUnsignedByte();
            }

            for (int i = 0; i < length; i++)
            {
                uint creatureId = message.ReadUnsignedInt();
                bool permenant  = message.ReadUnsignedByte() != 1;
                byte mark       = message.ReadUnsignedByte();

                var creature = CreatureStorage.GetCreature(creatureId);
                if (!!creature)
                {
                    creature.Marks.SetMark(permenant ? MarkType.Permenant : MarkType.OneSecondTemp, mark);
                    CreatureStorage.InvalidateOpponents();
                }/*else {
                  * throw new System.Exception("ProtocolGame.ParseCreatureMarks: Unknown creature id: " + creatureId);
                  * }*/
            }
        }
コード例 #2
0
        private void ParseCancelWalk(Internal.ByteArray message)
        {
            int direction = message.ReadUnsignedByte();

            var absolutePosition = Player.Position;

            if (absolutePosition == _lastSnapback)
            {
                _snapbackCount++;
            }
            else
            {
                _snapbackCount = 0;
            }

            _lastSnapback.Set(absolutePosition.x, absolutePosition.y, absolutePosition.z);
            if (_snapbackCount >= 16)
            {
                Player.StopAutowalk(true);
                CreatureStorage.SetAttackTarget(null, false);
                SendCancel();
                _snapbackCount = 0;
            }

            Player.AbortAutowalk((Direction)direction);
        }
コード例 #3
0
        public static void HandleCreatureQueryResponse(Packet packet)
        {
            Creature c     = new Creature();
            var      entry = packet.ReadEntryKey("Entry");

            if (entry.Value)
            {
                return;
            }

            c.Entry = entry.Key;

            c.Name = packet.ReadCString("Name");

            for (var i = 0; i < 7; i++)
            {
                packet.ReadString();
            }

            /*
             * for (var i = 0; i < 4; i++)
             *  c.Name[i] = packet.ReadCString("Name " + i);
             *
             * for (var i = 0; i < 4; i++)
             *  c.Name[i] = packet.ReadCString("Unk string " + i);*/

            c.SubName  = packet.ReadCString("Sub Name");
            c.IconName = packet.ReadCString("Icon Name");

            c.TypeFlags1 = packet.ReadEnum <CreatureTypeFlag>("Type Flags1");
            c.TypeFlags2 = packet.ReadEnum <CreatureTypeFlag>("Type Flags2");
            c.Type       = packet.ReadEnum <CreatureType>("Type");

            c.Family = packet.ReadEnum <CreatureFamily>("Family");
            //int val = packet.ReadInt32("Unk int");
            c.Rank        = packet.ReadEnum <CreatureRank>("Rank");
            c.KillCredit1 = packet.ReadInt32("Kill Credit 1");
            c.KillCredit2 = packet.ReadInt32("Kill Credit 2");

            for (var i = 0; i < 4; i++)
            {
                c.DisplayIDs[i] = packet.ReadInt32("Display ID " + i);
            }

            c.HealthModifier = packet.ReadSingle("Health Modifier");
            c.ManaModifier   = packet.ReadSingle("Mana Modifier");
            c.RacialLeader   = packet.ReadBoolean("Racial Leader");

            for (var i = 0; i < 6; i++)
            {
                c.QuestItems[i] = packet.ReadInt32("Quest Item " + i);
            }

            c.MovementID = packet.ReadInt32("Movement ID");
            c.Exp        = packet.ReadInt32("Expansion ID");
            CreatureStorage.GetSingleton().Add(c);
        }
コード例 #4
0
ファイル: Creatures.cs プロジェクト: Cjaker/TibiaUnity3D
        private void ParseCreatureShield(Internal.CommunicationStream message)
        {
            uint creatureId = message.ReadUnsignedInt();
            var  partyFlag  = message.ReadEnum <PartyFlag>();

            var creature = CreatureStorage.GetCreatureById(creatureId);

            if (!!creature)
            {
                creature.SetPartyFlag(partyFlag);
            }/*else {
              * throw new System.Exception("ProtocolGame.ParseCreatureShield: Unknown creature id: " + creatureId);
              * }*/
        }
コード例 #5
0
ファイル: Creatures.cs プロジェクト: Cjaker/TibiaUnity3D
        private void ParseCreatureHealth(Internal.CommunicationStream message)
        {
            uint creatureId    = message.ReadUnsignedInt();
            byte healthPercent = message.ReadUnsignedByte();

            var creature = CreatureStorage.GetCreatureById(creatureId);

            if (!!creature)
            {
                creature.SetSkill(SkillType.HealthPercent, healthPercent);
            }/*else {
              * throw new System.Exception("ProtocolGame.ParseCreatureHealth: Unknown creature id: " + creatureId);
              * }*/
        }
コード例 #6
0
ファイル: Creatures.cs プロジェクト: Cjaker/TibiaUnity3D
        private void ParseCreatureMark(Internal.CommunicationStream message)
        {
            uint creatureId = message.ReadUnsignedInt();
            byte mark       = message.ReadUnsignedByte();

            var creature = CreatureStorage.GetCreatureById(creatureId);

            if (!!creature)
            {
                creature.Marks.SetMark(MarkType.OneSecondTemp, mark);
            }/*else {
              * throw new System.Exception("ProtocolGame.ParseCreatureMark: Unknown creature id: " + creatureId);
              * }*/
        }
コード例 #7
0
        private void ParseCreatureUnpass(Internal.CommunicationStream message)
        {
            uint creatureId = message.ReadUnsignedInt();
            bool unpass     = message.ReadBoolean();

            var creature = CreatureStorage.GetCreature(creatureId);

            if (!!creature)
            {
                creature.Unpassable = unpass;
            }/*else {
              * throw new System.Exception("ProtocolGame.ParseCreatureUnpass: Unknown creature id: " + creatureId);
              * }*/
        }
コード例 #8
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;
        }
コード例 #9
0
ファイル: Creatures.cs プロジェクト: Cjaker/TibiaUnity3D
        private void ParseCreatureSkull(Internal.CommunicationStream message)
        {
            uint creatureId = message.ReadUnsignedInt();
            byte pkFlag     = message.ReadUnsignedByte();

            var creature = CreatureStorage.GetCreatureById(creatureId);

            if (!!creature)
            {
                creature.SetPKFlag((PkFlag)pkFlag);
            }/*else {
              * throw new System.Exception("ProtocolGame.ParseCreatureSkull: Unknown creature id: " + creatureId);
              * }*/
        }
コード例 #10
0
        public void SendGo(List <int> pathSteps)
        {
            if (pathSteps == null)
            {
                return;
            }

            CreatureStorage.ClearTargets();
            var message = _packetWriter.CreateMessage();

            if (pathSteps.Count == 1)
            {
                switch ((PathDirection)(pathSteps[0] & 65535))
                {
                case PathDirection.East: message.WriteEnum(GameclientMessageType.GoEast); break;

                case PathDirection.NorthEast: message.WriteEnum(GameclientMessageType.GoNorthEast); break;

                case PathDirection.North: message.WriteEnum(GameclientMessageType.GoNorth); break;

                case PathDirection.NorthWest: message.WriteEnum(GameclientMessageType.GoNorthWest); break;

                case PathDirection.West: message.WriteEnum(GameclientMessageType.GoWest); break;

                case PathDirection.SouthWest: message.WriteEnum(GameclientMessageType.GoSouthWest); break;

                case PathDirection.South: message.WriteEnum(GameclientMessageType.GoSouth); break;

                case PathDirection.SouthEast: message.WriteEnum(GameclientMessageType.GoSouthEast); break;

                default: return;
                }
            }
            else
            {
                int pathMaxSteps = (byte)System.Math.Min(byte.MaxValue, pathSteps.Count);

                message.WriteEnum(GameclientMessageType.GoPath);
                message.WriteUnsignedByte((byte)pathMaxSteps);
                int i = 0;
                while (i < pathMaxSteps)
                {
                    message.WriteUnsignedByte((byte)(pathSteps[i] & 65535));
                    i++;
                }
            }

            _packetWriter.FinishMessage();
        }
コード例 #11
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;
        }
コード例 #12
0
        private void ParsePlayerHelpers(Internal.CommunicationStream message)
        {
            uint   creatureId = message.ReadUnsignedInt();
            ushort helpers    = message.ReadUnsignedShort();

            var creature = CreatureStorage.GetCreature(creatureId);

            if (!!creature)
            {
                creature.NumberOfPvPHelpers = helpers;
            }

            /*else
             *  throw new System.Exception("ProtocolGame.ParsePlayerHelpers: Unknown creature id: " + creatureId);*/
        }
コード例 #13
0
        private void ParseCreatureShield(Internal.ByteArray message)
        {
            uint creatureId = message.ReadUnsignedInt();
            byte partyFlag  = message.ReadUnsignedByte();

            var creature = CreatureStorage.GetCreature(creatureId);

            if (!!creature)
            {
                creature.SetPartyFlag((PartyFlag)partyFlag);
            }
            else
            {
                throw new System.Exception("ProtocolGame.ParseCreatureShield: Unknown creature id: " + creatureId);
            }
        }
コード例 #14
0
ファイル: Startup.cs プロジェクト: Hengle/OpenTibia-Unity
        private void ParseWorldEntered(Internal.ByteArray message)
        {
            bool hasLoginPendingFeature = OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameLoginPending);

            if ((hasLoginPendingFeature && m_ConnectionState == ConnectionState.Pending) ||
                (!hasLoginPendingFeature && m_ConnectionState > ConnectionState.Disconnected && m_ConnectionState != ConnectionState.Game))
            {
                MiniMapStorage.Position  = Vector3Int.zero;
                WorldMapStorage.Position = Vector3Int.zero;
                WorldMapStorage.ResetMap();
                CreatureStorage.Reset();
                WorldMapStorage.Valid = false;
            }

            SetConnectionState(ConnectionState.Game);
        }
コード例 #15
0
        private void ParseCreatureUnpass(Internal.ByteArray message)
        {
            uint creatureID = message.ReadUnsignedInt();
            bool unpass     = message.ReadBoolean();

            var creature = CreatureStorage.GetCreature(creatureID);

            if (!!creature)
            {
                creature.Unpassable = unpass;
            }
            else
            {
                throw new System.Exception("ProtocolGame.ParseCreatureUnpass: Unknown creature id: " + creatureID);
            }
        }
コード例 #16
0
        private void ParsePlayerHelpers(Internal.ByteArray message)
        {
            uint   creatureID = message.ReadUnsignedInt();
            ushort helpers    = message.ReadUnsignedShort();

            var creature = CreatureStorage.GetCreature(creatureID);

            if (!!creature)
            {
                creature.NumberOfPvPHelpers = helpers;
            }
            else
            {
                throw new System.Exception("ProtocolGame.ParsePlayerHelpers: Unknown creature id: " + creatureID);
            }
        }
コード例 #17
0
        private void ParseCreatureLight(Internal.CommunicationStream message)
        {
            uint creatureId = message.ReadUnsignedInt();

            byte intensity = message.ReadUnsignedByte();
            byte color     = message.ReadUnsignedByte();

            var creature = CreatureStorage.GetCreature(creatureId);

            if (!!creature)
            {
                creature.Brightness = intensity;
                creature.LightColor = Colors.ColorFrom8Bit(color);
            }/*else {
              * throw new System.Exception("ProtocolGame.ParseCreatureLight: Unknown creature id: " + creatureId);
              * }*/
        }
コード例 #18
0
        private void ParseTrappers(Internal.CommunicationStream message)
        {
            int n = message.ReadUnsignedByte();
            List <Creatures.Creature> trappers = new List <Creatures.Creature>();

            for (int i = 0; i < n; i++)
            {
                var creatureId = message.ReadUnsignedInt();
                var creature   = CreatureStorage.GetCreature(creatureId);
                if (creature)
                {
                    trappers.Add(creature);
                }
            }

            CreatureStorage.SetTrappers(trappers);
        }
コード例 #19
0
        private void ParseCreatureHealth(Internal.ByteArray message)
        {
            uint creatureId    = message.ReadUnsignedInt();
            byte healthPercent = message.ReadUnsignedByte();

            var creature = CreatureStorage.GetCreature(creatureId);

            if (!!creature)
            {
                creature.SetSkill(SkillType.HealthPercent, healthPercent);
                CreatureStorage.InvalidateOpponents();
            }
            else
            {
                throw new System.Exception("ProtocolGame.ParseCreatureHealth: Unknown creature id: " + creatureId);
            }
        }
コード例 #20
0
        private void ParseCreatureMark(Internal.ByteArray message)
        {
            uint creatureId = message.ReadUnsignedInt();
            byte mark       = message.ReadUnsignedByte();

            var creature = CreatureStorage.GetCreature(creatureId);

            if (!!creature)
            {
                creature.Marks.SetMark(MarkType.OneSecondTemp, mark);
                CreatureStorage.InvalidateOpponents();
            }
            else
            {
                throw new System.Exception("ProtocolGame.ParseCreatureMarks: Unknown creature id: " + creatureId);
            }
        }
コード例 #21
0
        private void ParseCreatureOutfit(Internal.CommunicationStream message)
        {
            uint creatureId = message.ReadUnsignedInt();
            var  outfit     = ProtocolGameExtentions.ReadCreatureOutfit(message);

            var creature = CreatureStorage.GetCreature(creatureId);

            if (!!creature)
            {
                creature.Outfit = outfit;
                if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GamePlayerMounts))
                {
                    creature.MountOutfit = ProtocolGameExtentions.ReadMountOutfit(message, creature.MountOutfit);
                }
            }/*else {
              * throw new System.Exception("ProtocolGame.ParseCreatureOutfit: Unknown creature id: " + creatureId);
              * }*/
        }
コード例 #22
0
        private void ParseClearTarget(Internal.CommunicationStream message)
        {
            uint creatureId = 0;

            if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameAttackSeq))
            {
                creatureId = message.ReadUnsignedInt();
            }

            Creatures.Creature creature;
            if (!!(creature = CreatureStorage.AttackTarget) && (creature.Id == creatureId || creatureId == 0))
            {
                CreatureStorage.SetAttackTarget(null, false);
            }
            else if (!!(creature = CreatureStorage.FollowTarget) && (creature.Id == creatureId || creatureId == 0))
            {
                CreatureStorage.SetFollowTarget(null, false);
            }
        }
コード例 #23
0
        private void ParseCreatureOutfit(Internal.ByteArray message)
        {
            uint creatureID = message.ReadUnsignedInt();
            var  outfit     = ReadCreatureOutfit(message);

            var creature = CreatureStorage.GetCreature(creatureID);

            if (!!creature)
            {
                creature.Outfit = outfit;
                if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GamePlayerMounts))
                {
                    creature.MountOutfit = ReadMountOutfit(message, creature.MountOutfit);
                }
            }
            else
            {
                throw new System.Exception("ProtocolGame.ParseCreatureOutfit: Unknown creature id: " + creatureID);
            }
        }
コード例 #24
0
        private void ParseCreatureType(Internal.CommunicationStream message)
        {
            uint creatureId = message.ReadUnsignedInt();
            byte type       = message.ReadUnsignedByte();
            uint master     = 0;

            if (OpenTibiaUnity.GameManager.ClientVersion >= 1120 && type == (int)CreatureType.Summon)
            {
                master = message.ReadUnsignedInt();
            }

            var creature = CreatureStorage.GetCreature(creatureId);

            if (!!creature)
            {
                creature.Type = (CreatureType)type;
                creature.SetSummonerId(master);
            }/*else {
              * throw new System.Exception("ProtocolGame.ParseCreatureType: Unknown creature id: " + creatureId);
              * }*/
        }
コード例 #25
0
ファイル: Creatures.cs プロジェクト: Cjaker/TibiaUnity3D
        private void ParseCreatureSpeed(Internal.CommunicationStream message)
        {
            uint creatureId = message.ReadUnsignedInt();
            int  baseSpeed  = -1;

            if (OpenTibiaUnity.GameManager.ClientVersion >= 1059)
            {
                baseSpeed = message.ReadUnsignedShort();
            }

            int speed = message.ReadUnsignedShort();

            var creature = CreatureStorage.GetCreatureById(creatureId);

            if (!!creature)
            {
                creature.SetSkill(SkillType.Speed, speed, baseSpeed);
            }/*else {
              * throw new System.Exception("ProtocolGame.ParseCreatureSpeed: Unknown creature id: " + creatureId);
              * }*/
        }
コード例 #26
0
        private Creatures.Creature ReadCreatureInstance(Internal.ByteArray message, int type    = -1,
                                                        UnityEngine.Vector3Int?absolutePosition = null)
        {
            if (type == -1)
            {
                type = message.ReadUnsignedShort();
            }

            if (type != AppearanceInstance.Creature && type != AppearanceInstance.OutdatedCreature && type != AppearanceInstance.UnknownCreature)
            {
                throw new System.Exception("ProtocolGame.ReadCreatureInstance: Invalid creature type");
            }

            var gameManager = OpenTibiaUnity.GameManager;

            Creatures.Creature creature;
            switch (type)
            {
            case AppearanceInstance.UnknownCreature:
            case AppearanceInstance.OutdatedCreature: {
                if (type == AppearanceInstance.UnknownCreature)
                {
                    uint         removeID = message.ReadUnsignedInt();
                    uint         newID    = message.ReadUnsignedInt();
                    CreatureType creatureType;

                    if (gameManager.ClientVersion >= 910)
                    {
                        creatureType = message.ReadEnum <CreatureType>();
                    }
                    else
                    {
                        if (newID >= Constants.PlayerStartID && newID < Constants.PlayerEndID)
                        {
                            creatureType = CreatureType.Player;
                        }
                        else if (newID >= Constants.MonsterStartID && newID < Constants.MonsterEndID)
                        {
                            creatureType = CreatureType.Monster;
                        }
                        else
                        {
                            creatureType = CreatureType.NPC;
                        }
                    }

                    if (newID == Player.ID)
                    {
                        creature = Player;
                    }
                    else
                    {
                        creature = new Creatures.Creature(newID);
                    }

                    creature = CreatureStorage.ReplaceCreature(creature, removeID);
                    if (!creature)
                    {
                        throw new System.Exception("ProtocolGame.ReadCreatureInstance: Failed to append creature.");
                    }

                    creature.Type = creatureType;
                    if (gameManager.ClientVersion >= 1120)
                    {
                        creature.SetSummonerID(creature.IsSummon ? message.ReadUnsignedInt() : 0);
                    }

                    creature.Name = message.ReadString();
                }
                else
                {
                    uint creatureId = message.ReadUnsignedInt();
                    creature = CreatureStorage.GetCreature(creatureId);
                    if (!creature)
                    {
                        throw new System.Exception("ProtocolGame.ReadCreatureInstance: Outdated creature not found.");
                    }
                }

                creature.SetSkill(SkillType.HealthPercent, message.ReadUnsignedByte());
                creature.Direction = message.ReadEnum <Direction>();
                creature.Outfit    = ReadCreatureOutfit(message, creature.Outfit);
                if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GamePlayerMounts))
                {
                    creature.MountOutfit = ReadMountOutfit(message, creature.MountOutfit);
                }
                creature.Brightness = message.ReadUnsignedByte();
                creature.LightColor = Colors.ColorFrom8Bit(message.ReadUnsignedByte());
                creature.SetSkill(SkillType.Speed, message.ReadUnsignedShort());
                creature.SetPKFlag(message.ReadEnum <PKFlag>());
                creature.SetPartyFlag(message.ReadEnum <PartyFlag>());

                if (gameManager.GetFeature(GameFeature.GameCreatureEmblems) && type == AppearanceInstance.UnknownCreature)
                {
                    creature.SetGuildFlag(message.ReadEnum <GuildFlag>());
                }

                if (gameManager.GetFeature(GameFeature.GameCreatureMarks))
                {
                    creature.Type = message.ReadEnum <CreatureType>();
                    if (gameManager.ClientVersion >= 1120)
                    {
                        creature.SetSummonerID(creature.IsSummon ? message.ReadUnsignedInt() : 0);
                    }
                }

                if (gameManager.GetFeature(GameFeature.GameCreatureIcons))
                {
                    creature.SetSpeechCategory(message.ReadEnum <SpeechCategory>());
                }

                if (gameManager.GetFeature(GameFeature.GameCreatureMarks))
                {
                    creature.Marks.SetMark(MarkType.Permenant, message.ReadUnsignedByte());

                    if (gameManager.GetFeature(GameFeature.GameInspectionWindow))
                    {
                        message.ReadUnsignedByte();     // inspection state
                    }
                    if (gameManager.ClientVersion < 1185)
                    {
                        creature.NumberOfPvPHelpers = message.ReadUnsignedShort();
                    }
                }

                if (gameManager.ClientVersion >= 854)
                {
                    creature.Unpassable = message.ReadUnsignedByte() != 0;
                }
                else
                {
                    creature.Unpassable = true;
                }
                break;
            }

            case AppearanceInstance.Creature: {
                uint creatureId = message.ReadUnsignedInt();
                creature = CreatureStorage.GetCreature(creatureId);
                if (!creature)
                {
                    throw new System.Exception(string.Format("ProtocolGame.ReadCreatureInstance: Known creature not found ({0}).", creatureId));
                }

                creature.Direction = message.ReadEnum <Direction>();

                if (gameManager.ClientVersion >= 953)
                {
                    creature.Unpassable = message.ReadUnsignedByte() != 0;
                }
                break;
            }

            default:
                throw new System.Exception("ProtocolGame.ReadCreatureInstance: unknown creature identity type.");
            }

            if (absolutePosition.HasValue)
            {
                creature.Position = absolutePosition.Value;
            }

            CreatureStorage.MarkOpponentVisible(creature, true);
            CreatureStorage.InvalidateOpponents();
            return(creature);
        }
コード例 #27
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);
            }
        }
コード例 #28
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);
            }
        }
コード例 #29
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);
            }
        }
コード例 #30
0
 private void processAnimals_Click(object sender, EventArgs e)
 {
     CreatureStorage.Add("Animal", 1);
 }