コード例 #1
0
        private void ParseTile()
        {
            var tile = new OtTile(message.ReadLocation());

            //Console.WriteLine("[Debug] Tile received, location: " + tile.Location);

            var thingCount = message.ReadByte();

            for (int i = 0; i < thingCount; i++)
            {
                var thingType = message.ReadByte();
                if (thingType == 0x01) //Creature
                {
                    var id   = message.ReadUInt();
                    var name = message.ReadString();
                    var type = (CreatureType)message.ReadByte();

                    if (type != CreatureType.PLAYER)
                    {
                        map.AddCreature(new OtCreature {
                            Id = id, Name = name, Type = type, Location = tile.Location
                        });
                    }
                }
                else
                {
                    var id      = message.ReadUShort();
                    var subType = message.ReadByte();

                    var itemType = items.GetItemBySpriteId(id);
                    if (itemType != null)
                    {
                        var item = OtItem.Create(itemType);

                        if (item.Type.IsStackable)
                        {
                            item.SetAttribute(OtItemAttribute.COUNT, subType);
                        }
                        else if (item.Type.Group == OtItemGroup.Splash || item.Type.Group == OtItemGroup.FluidContainer)
                        {
                            item.SetAttribute(OtItemAttribute.COUNT, OtConverter.TibiaFluidToOtFluid(subType));
                        }

                        tile.AddItem(item);
                    }
                }
            }

            if (map.GetTile(tile.Location) == null)
            {
                map.SetTile(tile);
            }
        }
コード例 #2
0
        private void Map_Updated(object sender, MapUpdatedEventArgs e)
        {
            try
            {
                lock (map)
                {
                    miniMap.BeginUpdate();

                    foreach (var tile in e.Tiles)
                    {
                        if (ShareTrackedMap && !client.IsClinentless && !client.IsOpenTibiaServer)
                        {
                            mapShare.Add(tile);
                        }

                        if (TrackOnlyCurrentFloor && tile.Location.Z != Client.PlayerLocation.Z)
                        {
                            continue;
                        }

                        var index = tile.Location.ToIndex();

                        OtTile mapTile = map.GetTile(tile.Location);
                        if (mapTile != null && !RetrackTiles)
                        {
                            continue;
                        }
                        else if (mapTile == null)
                        {
                            mapTile = new OtTile(tile.Location);
                        }

                        mapTile.Clear();

                        for (int i = 0; i < tile.ThingCount; i++)
                        {
                            var thing = tile.GetThing(i);

                            if (thing is Creature)
                            {
                                var creature = thing as Creature;

                                if (creature.Type == CreatureType.PLAYER || (!TrackMonsters && creature.Type == CreatureType.MONSTER) || (!TrackNPCs && creature.Type == CreatureType.NPC))
                                {
                                    continue;
                                }

                                map.AddCreature(new OtCreature {
                                    Id = creature.Id, Location = creature.Location, Name = creature.Name, Type = creature.Type
                                });
                            }
                            else if (thing is Item)
                            {
                                var item = tile.GetThing(i) as Item;

                                var itemType = otItems.GetItemBySpriteId((ushort)item.Id);
                                if (itemType == null)
                                {
                                    Trace.TraceWarning("Tibia item not in items.otb. Details: item id " + item.Id.ToString());
                                    continue;
                                }

                                if (item.Type.IsMoveable && !TrackMoveableItems)
                                {
                                    continue;
                                }
                                if (item.IsSplash && !TrackSplashes)
                                {
                                    continue;
                                }

                                OtItem mapItem = OtItem.Create(itemType);

                                if (mapItem.Type.IsStackable)
                                {
                                    mapItem.SetAttribute(OtItemAttribute.COUNT, item.Count);
                                }
                                else if (mapItem.Type.Group == OtItemGroup.Splash || mapItem.Type.Group == OtItemGroup.FluidContainer)
                                {
                                    mapItem.SetAttribute(OtItemAttribute.COUNT, OtConverter.TibiaFluidToOtFluid(item.SubType));
                                }

                                mapTile.AddItem(mapItem);
                            }
                        }

                        map.SetTile(mapTile);
                    }

                    miniMap.CenterLocation = Client.PlayerLocation;
                    miniMap.EndUpdate();

                    UpdateCounters(map.TileCount, map.NpcCount, map.MonsterCount);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("[Error] Unable to convert tibia tile to open tibia tile. Details: " + ex.Message);
            }
        }
コード例 #3
0
ファイル: NpcInfo.cs プロジェクト: joseamaya1/SharpMapTracker
        public void SaveScript(string fileName)
        {
            var builder = new StringBuilder();

            builder.Append("local keywordHandler = KeywordHandler:new()\n");
            builder.Append("local npcHandler = NpcHandler:new(keywordHandler)\n");
            builder.Append("NpcSystem.parseParameters(npcHandler)\n");
            builder.Append("\n");
            builder.Append("function onCreatureAppear(cid)			npcHandler:onCreatureAppear(cid)			end\n");
            builder.Append("function onCreatureDisappear(cid)		npcHandler:onCreatureDisappear(cid)			end\n");
            builder.Append("function onCreatureSay(cid, type, msg)	npcHandler:onCreatureSay(cid, type, msg)	end\n");
            builder.Append("function onThink()						npcHandler:onThink()						end\n");
            builder.Append("\n");

            if (Statements.ContainsKey("hi"))
            {
                builder.Append("npcHandler:setMessage(MESSAGE_GREET, '").Append(Statements["hi"]).Append("')\n");
            }
            else if (Statements.ContainsKey("bye"))
            {
                builder.Append("npcHandler:setMessage(MESSAGE_FAREWELL, '").Append(Statements["bye"]).Append("')\n");
            }
            else if (Statements.ContainsKey("trade"))
            {
                builder.Append("npcHandler:setMessage(MESSAGE_SENDTRADE, '").Append("')\n");
            }

            builder.Append("\n");

            foreach (var statement in Statements)
            {
                if (statement.Key.Equals("hi") || statement.Key.Equals("bye") || statement.Key.Equals("trade"))
                {
                    continue;
                }

                builder.Append("keywordHandler:addKeyword({'").Append(statement.Key)
                .Append("'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = '")
                .Append(statement.Value).Append("'})\n");
            }

            if (Shop != null)
            {
                builder.Append("\n");
                builder.Append("local shopModule = ShopModule:new()\n");
                builder.Append("npcHandler:addModule(shopModule)\n");
                builder.Append("\n");

                foreach (var item in Shop.Items.Where(x => x.IsBuyable))
                {
                    var otItem = items.GetItemBySpriteId(item.Id);

                    if (otItem == null)
                    {
                        continue;
                    }

                    builder.Append("shopModule:addBuyableItem({'").Append(item.Name.ToLower()).
                    Append("'}, ").Append(otItem.Id).Append(", ").Append(item.BuyPrice).Append(", ");

                    if (otItem.Group == OtItemGroup.Splash || otItem.Group == OtItemGroup.FluidContainer)
                    {
                        builder.Append(OtConverter.TibiaFluidToOtFluid(item.SubType)).Append(", ");
                    }

                    builder.Append('\'').Append(item.Name.ToLower()).Append("')\n");
                }

                builder.Append("\n");

                foreach (var item in Shop.Items.Where(x => x.IsSellable))
                {
                    var otItem = items.GetItemBySpriteId(item.Id);

                    if (otItem == null)
                    {
                        continue;
                    }

                    builder.Append("shopModule:addSellableItem({'").Append(item.Name.ToLower()).
                    Append("'}, ").Append(otItem.Id).Append(", ").Append(item.SellPrice).Append(", ");

                    if (otItem.Group == OtItemGroup.Splash || otItem.Group == OtItemGroup.FluidContainer)
                    {
                        builder.Append(OtConverter.TibiaFluidToOtFluid(item.SubType)).Append(", ");
                    }

                    builder.Append('\'').Append(item.Name.ToLower()).Append("')\n");
                }
            }


            builder.Append("\n");
            builder.Append("npcHandler:addModule(FocusModule:new())");

            File.WriteAllText(fileName, builder.ToString());
        }