Beispiel #1
0
        private bool ReceivedMapPacket(IncomingPacket packet)
        {
            bool trackMovable      = uxTrackMovable.Checked;
            bool trackSplashes     = uxTrackSplashes.Checked;
            bool trackCurrentFloor = uxTrackCurrentFloor.Checked;
            bool enableRetracking  = uxEnableRetracking.Checked;


            lock (this)
            {
                MapPacket p = (MapPacket)packet;

                foreach (PacketCreature creature in p.Creatures)
                {
                    if (creature.Type == PacketCreatureType.Unknown)
                    {
                        if (trackCurrentFloor && creature.Location.Z
                            != client.PlayerLocation.Z)
                        {
                            continue;
                        }

                        if (enableRetracking || !mapCreatures.ContainsKey(creature.Location))
                        {
                            mapCreatures[creature.Location] = creature;
                            trackedCreatureCount++;
                        }
                    }
                }

                foreach (Tile tile in p.Tiles)
                {
                    if (trackCurrentFloor && tile.Location.Z
                        != client.PlayerLocation.Z)
                    {
                        continue;
                    }

                    OtMapTile existingMapTile = null;
                    bool      isExisting      = mapTiles.TryGetValue(tile.Location, out existingMapTile);

                    if (!enableRetracking && isExisting)
                    {
                        continue;
                    }

                    SetNewMapBounds(tile.Location);
                    OtMapTile mapTile = new OtMapTile();
                    mapTile.Location = tile.Location;
                    mapTile.MapColor = Tibia.Misc.GetAutomapColor(tile.Ground.AutomapColor);

                    if (MapTracker.Properties.Settings.Default.ReverseItemOrder)
                    {
                        tile.Items.Reverse();
                    }

                    tile.Items.Insert(0, tile.Ground);

                    foreach (Item item in tile.Items)
                    {
                        if (item == null)
                        {
                            continue;
                        }

                        Color color = Tibia.Misc.GetAutomapColor(item.AutomapColor);
                        if (color != Color.Black)
                        {
                            mapTile.MapColor = color;
                        }

                        ItemInfo info = ItemInfo.GetItemInfo((ushort)item.Id);

                        if (info == null)
                        {
                            Log("ClientId not in items.otb: " + item.Id.ToString());
                            continue;
                        }

                        if (!trackMovable && !item.GetFlag(Tibia.Addresses.DatItem.Flag.IsImmovable))
                        {
                            continue;
                        }
                        if (!trackSplashes && item.GetFlag(Tibia.Addresses.DatItem.Flag.IsSplash))
                        {
                            continue;
                        }

                        if (info.Group == ItemGroup.Ground)
                        {
                            mapTile.TileId = info.Id;
                            continue;
                        }

                        OtMapItem mapItem = new OtMapItem();
                        mapItem.AttrType = AttrType.None;

                        mapItem.ItemId = info.Id;

                        if (item.HasExtraByte)
                        {
                            byte extra = item.Count;
                            if (item.GetFlag(Tibia.Addresses.DatItem.Flag.IsRune))
                            {
                                mapItem.AttrType = AttrType.Charges;
                                mapItem.Extra    = extra;
                            }
                            else if (item.GetFlag(Tibia.Addresses.DatItem.Flag.IsStackable) ||
                                     item.GetFlag(Tibia.Addresses.DatItem.Flag.IsSplash))
                            {
                                mapItem.AttrType = AttrType.Count;
                                mapItem.Extra    = extra;
                            }
                        }
                        mapTile.Items.Add(mapItem);
                    }

                    if (isExisting)
                    {
                        trackedItemCount -= existingMapTile.Items.Count;
                    }
                    else
                    {
                        trackedTileCount++;
                    }

                    trackedItemCount       += mapTile.Items.Count;
                    mapTiles[tile.Location] = mapTile;

                    if (!mapCreatures.ContainsKey(tile.Location))
                    {
                        mapCreatures.Add(tile.Location, null);
                    }
                }
                UpdateStats();
            }
            return(true);
        }
Beispiel #2
0
        private bool ReceivedMapPacket(IncomingPacket packet)
        {
            bool trackMovable = uxTrackMovable.Checked;
            bool trackSplashes = uxTrackSplashes.Checked;
            bool trackCurrentFloor = uxTrackCurrentFloor.Checked;
            bool enableRetracking = uxEnableRetracking.Checked;


            lock (this)
            {
                MapPacket p = (MapPacket)packet;

                foreach (PacketCreature creature in p.Creatures)
                {
                    if (creature.Type == PacketCreatureType.Unknown)
                    {
                        if (trackCurrentFloor && creature.Location.Z 
                            != client.PlayerLocation.Z)
                            continue;

                        if (enableRetracking || !mapCreatures.ContainsKey(creature.Location))
                        {
                            mapCreatures[creature.Location] = creature;
                            trackedCreatureCount++;
                        }
                    }
                }

                foreach (Tile tile in p.Tiles)
                {
                    if (trackCurrentFloor && tile.Location.Z
                        != client.PlayerLocation.Z)
                        continue;

                    OtMapTile existingMapTile = null;
                    bool isExisting = mapTiles.TryGetValue(tile.Location, out existingMapTile);

                    if (!enableRetracking && isExisting)
                        continue;

                    SetNewMapBounds(tile.Location);
                    OtMapTile mapTile = new OtMapTile();
                    mapTile.Location = tile.Location;
                    mapTile.MapColor = Tibia.Misc.GetAutomapColor(tile.Ground.AutomapColor);

                    if (MapTracker.Properties.Settings.Default.ReverseItemOrder)
                        tile.Items.Reverse();

                    tile.Items.Insert(0, tile.Ground);

                    foreach (Item item in tile.Items)
                    {
                        if (item == null)
                            continue;

                        Color color = Tibia.Misc.GetAutomapColor(item.AutomapColor);
                        if (color != Color.Black)
                            mapTile.MapColor = color;

                        ItemInfo info = ItemInfo.GetItemInfo((ushort)item.Id);

                        if (info == null)
                        {
                            Log("ClientId not in items.otb: " + item.Id.ToString());
                            continue;
                        }

                        if (!trackMovable && !item.GetFlag(Tibia.Addresses.DatItem.Flag.IsImmovable))
                            continue;
                        if (!trackSplashes && item.GetFlag(Tibia.Addresses.DatItem.Flag.IsSplash))
                            continue;

                        if (info.Group == ItemGroup.Ground)
                        {
                            mapTile.TileId = info.Id;
                            continue;
                        }
                        
                        OtMapItem mapItem = new OtMapItem();
                        mapItem.AttrType = AttrType.None;

                        mapItem.ItemId = info.Id;

                        if (item.HasExtraByte)
                        {
                            byte extra = item.Count;
                            if (item.GetFlag(Tibia.Addresses.DatItem.Flag.IsRune))
                            {
                                mapItem.AttrType = AttrType.Charges;
                                mapItem.Extra = extra;
                            }
                            else if (item.GetFlag(Tibia.Addresses.DatItem.Flag.IsStackable) ||
                                item.GetFlag(Tibia.Addresses.DatItem.Flag.IsSplash))
                            {
                                mapItem.AttrType = AttrType.Count;
                                mapItem.Extra = extra;
                            }
                        }
                        mapTile.Items.Add(mapItem);
                    }

                    if (isExisting)
                    {
                        trackedItemCount -= existingMapTile.Items.Count;
                    }
                    else
                    {
                        trackedTileCount++;
                    }

                    trackedItemCount += mapTile.Items.Count;
                    mapTiles[tile.Location] = mapTile;

                    if (!mapCreatures.ContainsKey(tile.Location))
                    {
                        mapCreatures.Add(tile.Location, null);
                    }
                }
                UpdateStats();
            }
            return true;
        }