示例#1
0
        public override void Run()
        {
            if (_listOfTeachers.Count <= 0)
            {
                return;
            }
            Npc bestTeacher = new Npc();

            for (int i = 0; i < _listOfTeachers.Count; i++)
            {
                Npc teacher = _listOfTeachers[i];
                if (bestTeacher.Entry > 0)
                {
                    // priority checks first
                    switch (Products.Products.ProductName)
                    {
                    case "Gatherer":
                        if (bestTeacher.Type == Npc.NpcType.MiningTrainer && teacher.Type != Npc.NpcType.RidingTrainer)
                        {
                            continue;
                        }
                        if (bestTeacher.Type == Npc.NpcType.HerbalismTrainer && teacher.Type != Npc.NpcType.RidingTrainer && teacher.Type != Npc.NpcType.MiningTrainer)
                        {
                            continue;
                        }
                        if (bestTeacher.Type == Npc.NpcType.SkinningTrainer && teacher.Type != Npc.NpcType.RidingTrainer && teacher.Type != Npc.NpcType.MiningTrainer &&
                            teacher.Type != Npc.NpcType.HerbalismTrainer)
                        {
                            continue;
                        }
                        if (teacher.Type == Npc.NpcType.RidingTrainer)
                        {
                            bestTeacher = teacher;
                        }
                        else if (teacher.Type == Npc.NpcType.MiningTrainer && bestTeacher.Type != Npc.NpcType.RidingTrainer)
                        {
                            bestTeacher = teacher;
                        }
                        else if (teacher.Type == Npc.NpcType.HerbalismTrainer && bestTeacher.Type != Npc.NpcType.RidingTrainer && bestTeacher.Type != Npc.NpcType.MiningTrainer)
                        {
                            bestTeacher = teacher;
                        }
                        else if (teacher.Type == Npc.NpcType.SkinningTrainer && bestTeacher.Type != Npc.NpcType.RidingTrainer && bestTeacher.Type != Npc.NpcType.MiningTrainer &&
                                 bestTeacher.Type != Npc.NpcType.HerbalismTrainer)
                        {
                            bestTeacher = teacher;
                        }
                        break;

                    case "Quester":
                    case "Grinder":
                        if (bestTeacher.Type == Npc.NpcType.SkinningTrainer && teacher.Type != Npc.NpcType.RidingTrainer)
                        {
                            continue;
                        }
                        if (bestTeacher.Type == Npc.NpcType.MiningTrainer && teacher.Type != Npc.NpcType.RidingTrainer && teacher.Type != Npc.NpcType.SkinningTrainer)
                        {
                            continue;
                        }
                        if (bestTeacher.Type == Npc.NpcType.HerbalismTrainer && teacher.Type != Npc.NpcType.RidingTrainer && teacher.Type != Npc.NpcType.SkinningTrainer &&
                            teacher.Type != Npc.NpcType.MiningTrainer)
                        {
                            continue;
                        }
                        if (teacher.Type == Npc.NpcType.RidingTrainer)
                        {
                            bestTeacher = teacher;
                        }
                        else if (teacher.Type == Npc.NpcType.SkinningTrainer && bestTeacher.Type != Npc.NpcType.RidingTrainer)
                        {
                            bestTeacher = teacher;
                        }
                        else if (teacher.Type == Npc.NpcType.MiningTrainer && bestTeacher.Type != Npc.NpcType.RidingTrainer && bestTeacher.Type != Npc.NpcType.SkinningTrainer)
                        {
                            bestTeacher = teacher;
                        }
                        else if (teacher.Type == Npc.NpcType.HerbalismTrainer && bestTeacher.Type != Npc.NpcType.RidingTrainer && bestTeacher.Type != Npc.NpcType.SkinningTrainer &&
                                 bestTeacher.Type != Npc.NpcType.MiningTrainer)
                        {
                            bestTeacher = teacher;
                        }
                        break;
                    }
                    if (bestTeacher == teacher)
                    {
                        continue; // We just set a best from priority checks, so distance check is not important anymore
                    }
                    if (ObjectManager.ObjectManager.Me.Position.DistanceTo(teacher.Position) < ObjectManager.ObjectManager.Me.Position.DistanceTo(bestTeacher.Position))
                    {
                        bestTeacher = teacher; // We do not have priority between teacher and the actual bestTeacher, so we use distance instead
                    }
                }
                else
                {
                    bestTeacher = teacher;
                }
            }

            if (bestTeacher.Position.DistanceTo(ObjectManager.ObjectManager.Me.Position) > 800)
            {
                if (Quest.TravelToQuestZone(bestTeacher.Position, ref _doTravel, bestTeacher.ContinentIdInt, false, bestTeacher.Type.ToString()))
                {
                    return;
                }
            }
            uint baseAddress = MovementManager.FindTarget(ref bestTeacher);

            if (MovementManager.InMovement)
            {
                return;
            }
            if (baseAddress == 0 && bestTeacher.Position.DistanceTo(ObjectManager.ObjectManager.Me.Position) < 10)
            {
                NpcDB.DelNpc(bestTeacher);
            }
            else if (baseAddress > 0)
            {
                if (bestTeacher.Position.DistanceTo(ObjectManager.ObjectManager.Me.Position) > 5f)
                {
                    return;
                }
                string[] skillInfo = bestTeacher.InternalData.Split(',');
                if (skillInfo.Length == 2)
                {
                    SkillLine skillLine = (SkillLine)Others.ToInt32(skillInfo[0]);
                    SkillRank skillRank = (SkillRank)Others.ToInt32(skillInfo[1]);
                    SkillRank nextRank;
                    if (skillRank == SkillRank.ZenMaster)
                    {
                        nextRank = skillRank + 100;
                    }
                    else
                    {
                        nextRank = skillRank + 75;
                    }
                    string oldRank = "";
                    if (skillRank != SkillRank.None)
                    {
                        oldRank = " We were only " + skillRank.ToString() + " of " + skillLine.ToString() + ".";
                    }
                    Logging.Write("We have just reached the Teacher of " + skillLine.ToString() + ", " + bestTeacher.Name + ". We are now going to learn " + nextRank.ToString() +
                                  " of " + skillLine.ToString() + "." + oldRank);
                }
                Interact.InteractWith(baseAddress);
                Thread.Sleep(500 + Usefuls.Latency);
                Quest.CompleteQuest();
                Gossip.TrainAllAvailableSpells();
                TeacherFoundNoSpam.Remove(bestTeacher);
                SpellManager.UpdateSpellBook();
                _doTravel = true;
            }
            // still on the road, but not in movement for some reasons
        }