示例#1
0
文件: Bot.cs 项目: zneel/TheNoobBot
        public static void LaunchTaxi()
        {
            try
            {
                if (_availableTaxis == null)
                {
                    _availableTaxis = XmlSerializer.Deserialize <List <Taxi> >(Application.StartupPath + @"\Data\TaxiList.xml");
                }
                if (_availableTaxiLinks == null)
                {
                    _availableTaxiLinks = XmlSerializer.Deserialize <List <TaxiLink> >(Application.StartupPath + @"\Data\TaxiLinks.xml");
                }
                uint firstTaxiId = 0;
                while (true)
                {
                    _availableTaxis     = XmlSerializer.Deserialize <List <Taxi> >(Application.StartupPath + @"\Data\TaxiList.xml");
                    _availableTaxiLinks = XmlSerializer.Deserialize <List <TaxiLink> >(Application.StartupPath + @"\Data\TaxiLinks.xml");
                    if (IsTaxiOpen())
                    {
                        if (firstTaxiId != 0 && firstTaxiId == ObjectManager.Me.Target.GetWoWId)
                        {
                            Logging.Write("The continent have been parsed !");
                            break;
                        }
                        if (firstTaxiId == 0)
                        {
                            firstTaxiId = ObjectManager.Me.Target.GetWoWId;
                        }
                        if (TaxiListContainsTaxiId(ObjectManager.Me.Target.GetWoWId))
                        {
                            Logging.WriteDebug("The taxi from NPC " + ObjectManager.Target.Name + " is already in our database.");
                            Taxi myTaxi = GetTaxiFromTaxiId(ObjectManager.Me.Target.GetWoWId);
                            if (myTaxi.Faction != Npc.FactionType.Neutral && ObjectManager.Me.PlayerFaction != myTaxi.Faction.ToString())
                            {
                                for (int i = 0; i < _availableTaxis.Count; i++)
                                {
                                    if (myTaxi.Id == _availableTaxis[i].Id)
                                    {
                                        _availableTaxis[i].Faction = Npc.FactionType.Neutral;
                                    }
                                }
                            }
                        }
                        else
                        {
                            var localTaxi = new Taxi();
                            localTaxi.Id       = ObjectManager.Me.Target.GetWoWId;
                            localTaxi.Position = ObjectManager.Target.Position;
                            string taxiInfo = ExtractCurrentTaxiInfo();
                            localTaxi.Name        = taxiInfo.Split('#')[0];
                            localTaxi.ContinentId = Usefuls.ContinentId;
                            localTaxi.Xcoord      = taxiInfo.Split('#')[1].Split('^')[0];
                            localTaxi.Ycoord      = taxiInfo.Split('^')[1].Split('@')[0];
                            localTaxi.Faction     = ObjectManager.Me.PlayerFaction == "Alliance" ? Npc.FactionType.Alliance : Npc.FactionType.Horde;
                            _availableTaxis.Add(localTaxi);
                            foreach (TaxiLink taxiLink in _availableTaxiLinks)
                            {
                                if (taxiLink.PointB == 0 && taxiLink.PointB_XY == localTaxi.Xcoord + localTaxi.Ycoord)
                                {
                                    taxiLink.PointB    = localTaxi.Id;
                                    taxiLink.PointB_XY = "";
                                }
                            }
                        }

                        foreach (string ctaxi in ExtractDirectPathTaxiInfoList())
                        {
                            string taxiInfo  = ctaxi;
                            var    localTaxi = new Taxi();
                            localTaxi.Name        = taxiInfo.Split('#')[0];
                            localTaxi.ContinentId = Usefuls.ContinentId;
                            localTaxi.Xcoord      = taxiInfo.Split('#')[1].Split('^')[0];
                            localTaxi.Ycoord      = taxiInfo.Split('^')[1].Split('@')[0];
                            bool taxiExist = false;
                            var  taxiFound = new Taxi();
                            foreach (Taxi taxi in _availableTaxis)
                            {
                                if (taxi.Xcoord == localTaxi.Xcoord && taxi.Ycoord == localTaxi.Ycoord)
                                {
                                    // this taxi exist in the list so we have its ID
                                    taxiExist = true;
                                    taxiFound = taxi;
                                }
                            }
                            bool found = false;
                            foreach (TaxiLink taxiLink in _availableTaxiLinks)
                            {
                                if (taxiExist && taxiLink.PointA == ObjectManager.Me.Target.GetWoWId && taxiLink.PointB == taxiFound.Id)
                                {
                                    found = true;
                                    break;
                                }
                                if (taxiExist && taxiLink.PointB == ObjectManager.Me.Target.GetWoWId && taxiLink.PointA == taxiFound.Id)
                                {
                                    found = true;
                                    break;
                                }
                                if (taxiLink.PointA == ObjectManager.Me.Target.GetWoWId && taxiLink.PointB_XY == localTaxi.Xcoord + localTaxi.Ycoord)
                                {
                                    found = true;
                                    break;
                                }
                            }
                            if (!found)
                            {
                                _availableTaxiLinks.Add(taxiExist
                                    ? new TaxiLink {
                                    PointA = ObjectManager.Me.Target.GetWoWId, PointB = taxiFound.Id
                                }
                                    : new TaxiLink {
                                    PointA = ObjectManager.Me.Target.GetWoWId, PointB_XY = localTaxi.Xcoord + localTaxi.Ycoord
                                });
                            }
                        }

                        XmlSerializer.Serialize(Application.StartupPath + @"\Data\TaxiList.xml", _availableTaxis);
                        XmlSerializer.Serialize(Application.StartupPath + @"\Data\TaxiLinks.xml", _availableTaxiLinks);
                        string nextHop = ExtractNextTaxiInfo();
                        Logging.Write("Taking taxi from " + ExtractCurrentTaxiInfo().Split('#')[0] + " to " + nextHop.Split('#')[0]);
                        Gossip.TakeTaxi(nextHop.Split('#')[1].Split('^')[0], nextHop.Split('^')[1].Split('@')[0]);
                        Thread.Sleep(1000);
                    }
                    if (ObjectManager.Me.OnTaxi)
                    {
                        Travel.TravelPatientlybyTaxiOrPortal(true);
                        Thread.Sleep(2000);
                        continue;
                    }
                    WoWUnit taxiUnit    = ObjectManager.GetNearestWoWUnit(ObjectManager.GetWoWUnitFlightMaster());
                    uint    baseAddress = MovementManager.FindTarget(taxiUnit);
                    if (MovementManager.InMovement)
                    {
                        continue;
                    }
                    if (baseAddress > 0)
                    {
                        Interact.InteractWith(baseAddress);
                        Thread.Sleep(500);
                        if (!Gossip.IsTaxiWindowOpen())
                        {
                            Gossip.SelectGossip(Gossip.GossipOption.Taxi);
                            Thread.Sleep(250 + Usefuls.Latency);
                        }
                    }
                    Thread.Sleep(200);
                }
            }
            catch (Exception e)
            {
                Logging.WriteDebug(e.ToString());
            }
        }