Ejemplo n.º 1
0
        private void ParseCreateOnMap(Internal.CommunicationStream message)
        {
            var absolutePosition = message.ReadPosition();

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

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

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

            int typeOrId = message.ReadUnsignedShort();

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

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

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

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

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

            WorldMapStorage.CacheRefresh = true;
        }