Ejemplo n.º 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.GetCreatureById(creatureId);
                if (!!creature)
                {
                    creature.Marks.SetMark(permenant ? MarkType.Permenant : MarkType.OneSecondTemp, mark);
                }/*else {
                  * throw new System.Exception("ProtocolGame.ParseCreatureMarks: Unknown creature id: " + creatureId);
                  * }*/
            }
        }
Ejemplo n.º 2
0
        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);
              * }*/
        }
Ejemplo n.º 3
0
        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);
              * }*/
        }
Ejemplo n.º 4
0
        private void ParseCreatureUnpass(Internal.CommunicationStream message)
        {
            uint creatureId = message.ReadUnsignedInt();
            bool unpass     = message.ReadBoolean();

            var creature = CreatureStorage.GetCreatureById(creatureId);

            if (!!creature)
            {
                creature.Unpassable = unpass;
            }/*else {
              * throw new System.Exception("ProtocolGame.ParseCreatureUnpass: Unknown creature id: " + creatureId);
              * }*/
        }
Ejemplo n.º 5
0
        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);
              * }*/
        }
Ejemplo n.º 6
0
        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);
              * }*/
        }
Ejemplo n.º 7
0
        private void ParsePlayerHelpers(Internal.CommunicationStream message)
        {
            uint   creatureId = message.ReadUnsignedInt();
            ushort helpers    = message.ReadUnsignedShort();

            var creature = CreatureStorage.GetCreatureById(creatureId);

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

            /*else
             *  throw new System.Exception("ProtocolGame.ParsePlayerHelpers: Unknown creature id: " + creatureId);*/
        }
Ejemplo n.º 8
0
        private void ParseCreatureLight(Internal.CommunicationStream message)
        {
            uint creatureId = message.ReadUnsignedInt();

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

            var creature = CreatureStorage.GetCreatureById(creatureId);

            if (!!creature)
            {
                creature.Brightness = intensity;
                creature.LightColor = Colors.ColorFrom8Bit(color);
            }/*else {
              * throw new System.Exception("ProtocolGame.ParseCreatureLight: Unknown creature id: " + creatureId);
              * }*/
        }
Ejemplo n.º 9
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.GetCreatureById(creatureId);
                if (creature)
                {
                    trappers.Add(creature);
                }
            }

            CreatureStorage.SetTrappers(trappers);
        }
Ejemplo n.º 10
0
        private void ParseCreatureOutfit(Internal.CommunicationStream message)
        {
            uint creatureId = message.ReadUnsignedInt();
            var  outfit     = ProtocolGameExtentions.ReadCreatureOutfit(message);

            var creature = CreatureStorage.GetCreatureById(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);
              * }*/
        }
Ejemplo n.º 11
0
        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);
              * }*/
        }
Ejemplo n.º 12
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.GetCreatureById(creatureId);

            if (!!creature)
            {
                creature.Type = (CreatureType)type;
                creature.SetSummonerId(master);
            }/*else {
              * throw new System.Exception("ProtocolGame.ParseCreatureType: Unknown creature id: " + creatureId);
              * }*/
        }
Ejemplo n.º 13
0
        private void ParseCreatureMove(Internal.CommunicationStream 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.GetCreatureById(@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.GetCreatureById(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, false);
            }

            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);
            }

            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);
            }

            WorldMapStorage.CacheRefresh = true;
        }
Ejemplo n.º 14
0
        private void ParseDeleteOnMap(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.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.GetCreatureById(objectInstance.Data)) == null)
                {
                    throw new System.Exception($"ProtocolGame.ParseDeleteOnMap: Creature not found.");
                }

                WorldMapStorage.DeleteObject(mapPosition, stackPos);
            }
            else
            {
                uint creatureId = message.ReadUnsignedInt();
                if ((creature = CreatureStorage.GetCreatureById(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);
            }

            WorldMapStorage.CacheRefresh = true;
        }
Ejemplo n.º 15
0
        private void ParseChangeOnMap(Internal.CommunicationStream message)
        {
            int x = message.ReadUnsignedShort();

            Appearances.ObjectInstance objectInstance;
            Creatures.Creature         creature = null;
            Creatures.Creature         other    = 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.GetCreatureById(objectInstance.Data)))
                {
                    throw new System.Exception("ProtocolGame.ParseChangeOnMap: Creature not found: " + objectInstance.Data);
                }

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

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

                if (!(creature = CreatureStorage.GetCreatureById(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);

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

            // most of the time it updates the same creature
            // so set the creature's visiblity when nessecary
            if (!!creature && creature != other)
            {
                CreatureStorage.MarkOpponentVisible(creature, false);
            }

            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;
        }