示例#1
0
        public int Compare(object x, object y)
        {
            LocatedQuest q1 = (LocatedQuest)x;
            LocatedQuest q2 = (LocatedQuest)y;

            return((int)(q1.Distance - q2.Distance));
        }
示例#2
0
        private LocatedQuest _determineBestNearestQuestToDo()
        {
            Dictionary <int, NonPlayerEntity> npcs   = new Dictionary <int, NonPlayerEntity>();
            List <QuestDefinition>            quests = new List <QuestDefinition>(_questRep.FindByLevelRange(_character.PrimaryLevel, _character.PrimaryLevel + 1));
            //determine distance from current location
            SortableList locatedQuests = new SortableList(new LocatedQuestComparer());

            locatedQuests.KeepSorted    = true;
            locatedQuests.AddDuplicates = true;
            foreach (QuestDefinition quest in quests)
            {
                if (_character.CompletedQuests.Count(q => q.Id == quest.Id) > 0)
                {
                    continue;
                }

                if (quest.StarterId > 0)
                {
                    if (!npcs.ContainsKey(quest.StarterId))
                    {
                        NonPlayerEntity npc = _npeRep.GetAll().FirstOrDefault(npe => npe.RomId == quest.StarterId);

                        if (npc != null)
                        {
                            npcs.Add(quest.StarterId, npc);
                        }
                    }
                    if (npcs.ContainsKey(quest.StarterId))
                    {
                        NonPlayerEntity npc = npcs[quest.StarterId];
                        Vector3         loc = new Vector3(npc.X, npc.Y, npc.Z);
                        LocatedQuest    lQ  = new LocatedQuest()
                        {
                            Location = loc,
                            Quest    = quest,
                            Starter  = npc,
                            Distance = _state.Location.Distance(loc)
                        };
                        locatedQuests.Add(lQ); ////////store quest, item +locations.......
                    }
                }
            }

            if (locatedQuests.Count > 0)
            {
                return((LocatedQuest)locatedQuests[0]);
            }
            return(null);
        }