예제 #1
0
        private void GetNextPerk(out PriorityPerkRequest next, out int pos)
        {
            PriorityPerkRequest candidate = null;
            int candidatePriority         = Int32.MaxValue;
            int candidatePos = -1;

            for (int i = 0; i < _queue.Count; ++i)
            {
                PriorityPerkRequest ppr = _queue[i];
                if (ppr.Priority < candidatePriority && _currentLevel >= ppr.RequiredCharacterLevel)
                {
                    candidate         = ppr;
                    candidatePriority = ppr.Priority;
                    candidatePos      = i;
                }
            }

            next = candidate;
            pos  = candidatePos;
        }
예제 #2
0
        private bool AddPerkToQueue(string perk, int pri, int lineNum)
        {
            string[] parts = perk.Split('-');
            if (parts.Length < 1 || parts.Length > 2)
            {
                Console.Error.WriteLine($"Invalid specification {perk} on line #{lineNum}");
                return(false);
            }

            int    specifiedLevel = 0;
            string perkName       = parts[0].Trim();
            Perk   match          = null;

            if (parts.Length > 1)
            {
                if (!Int32.TryParse(parts[1], out specifiedLevel))
                {
                    Console.Error.WriteLine($"Invalid max rank {parts[1]} on line #{lineNum}, is not a number.");
                    return(false);
                }
            }

            if (IsSpecial(perkName))
            {
                if (specifiedLevel == 0)
                {
                    specifiedLevel = 10;
                }
                else
                {
                    if (specifiedLevel < 0 || specifiedLevel > 10)
                    {
                        Console.Error.WriteLine($"Level {specifiedLevel} for Special {perkName} is invalid. Must be between 1 and 10.");
                        return(false);
                    }
                }
            }
            else
            {
                IEnumerable <Perk> matches = _data.perks.Where(x => x.name == perkName);
                if (matches.Count() <= 0)
                {
                    string closestName = GetClosestPerkName(perkName);
                    Console.Error.WriteLine($"Perk {perkName} does not exist on line #{lineNum}. Did you mean {closestName}?");
                    return(false);
                }

                match = matches.First();

                int maxLevel = GetMaxLevelForPerk(perkName);

                if (specifiedLevel > 0)
                {
                    if (specifiedLevel > maxLevel)
                    {
                        Console.Error.WriteLine($"Level {specifiedLevel} is greater than max level {maxLevel} for perk {perkName}");
                        return(false);
                    }
                }
                else
                {
                    specifiedLevel = maxLevel;
                }
            }
            for (int i = 1; i <= specifiedLevel; ++i)
            {
                // Specials have no match, keep it at 0
                int requiredLevel = 0;
                if (match != null)
                {
                    Rank currentRank = match.ranks.Where(x => x.rank == i).First();
                    requiredLevel = currentRank.levelPreReq;
                }

                PriorityPerkRequest pi = new PriorityPerkRequest()
                {
                    Perk      = perkName,
                    PerkLevel = i,
                    Priority  = pri,
                    RequiredCharacterLevel = requiredLevel
                };

                if (IsSpecial(perkName) && i == 1)
                {
                    // Skip specials for rank 1, already have it by default
                    continue;
                }

                _queue.Add(pi);
            }

            return(true);
        }