Пример #1
0
        public Item GetRewardBonusForLevel(RandomItemSettings settings, IEnumerable <Item> chooseItemsFrom, int level)
        {
            Dictionary <string, Item> tempDic = chooseItemsFrom.ToDictionary(i => i.name, i => i);
            int readLevel = 0;

            var levelFiltered = from j in tempDic
                                let lastUnderscore = j.Key.LastIndexOf('_')
                                                     let strLast = lastUnderscore > 0 ?
                                                                   j.Key.Substring(lastUnderscore + 1) : String.Empty
                                                                   let lastIsChar = strLast.Length < 2 ? false :
                                                                                    Char.IsLetter(strLast[strLast.Length - 1])
                                                                                    let strLevel = lastIsChar ? strLast.Remove(strLast.Length - 1, 1)
                                                          : strLast
                                                                                                   let hadLevel                         = Int32.TryParse(strLevel, out readLevel)
                                                                                                                              let found = hadLevel && readLevel <= level + 10 && readLevel >= level
                                                                                                                                          where found
                                                                                                                                          select j.Value;

            Item result = levelFiltered.FirstOrDefault();

            if (result != null)
            {
                result = result.Clone();
                result.ChooseItemsFrom = levelFiltered;
            }
            return(result);
        }
Пример #2
0
        public Item GetRewardBonusItem(int level, bool light, string questExtraCategory, string bonusName,
            out int minLevel)
        {
            minLevel = 0;

            if (String.IsNullOrEmpty(bonusName) || !bonusName.StartsWith("%Quest_"))
                return null;

            // save Search
            var randomSettings = new RandomItemSettings()
            {
                BonusName = bonusName,
                ExtraCategory = questExtraCategory,
                IsLight = light,
                Level = level
            };

            var bonusMagicWords = bonusName.Split('_').Select(w => w.ToLower()).ToArray();
            int searchKeyStart = 2;
            bool isQuestL = false;
            string additionalFilter = String.Empty;

            if (bonusMagicWords[1].Length == 1)
                isQuestL = bonusMagicWords[1] == "l";
            else {
                if (bonusMagicWords[1].Length != 2) // ws etc.
                    return null;
                additionalFilter = String.Format("_{0}_", bonusMagicWords[1]);
                isQuestL = light;
            }

            int last = bonusMagicWords.Length - 1;
            if (last < 2)
                return null;

            string levelSuffix = bonusMagicWords[last];
            if (levelSuffix == "lf2a") { // only one such quest in Theobomos
                additionalFilter = levelSuffix;
                // %Quest_L_Recipe_20a_LF2A
                last--;
                levelSuffix = bonusMagicWords[last];
                Array.Resize(ref bonusMagicWords, last + 1);
            } else if (levelSuffix == "woman" || levelSuffix == "man") {
                if (bonusMagicWords[last - 1] == "christmas")
                    return new Item() { name = "X" };
            }

            if (Char.IsLetter(levelSuffix[levelSuffix.Length - 1]))
                levelSuffix = levelSuffix.Remove(levelSuffix.Length - 1, 1);
            int maxLevel = Int32.Parse(levelSuffix);

            // if the strict level, search items between that level and next
            minLevel = maxLevel;
            if (maxLevel % 10 != 0) {
                maxLevel -= maxLevel % 10;
            }

            if (level > minLevel)
                minLevel = level;

            if (level > 0)
                maxLevel += 10;
            else
                maxLevel = Int32.MaxValue; // search all

            level = minLevel;

            string[] wordsBetween = new String[bonusMagicWords.Length - searchKeyStart - 1];
            Array.Copy(bonusMagicWords, searchKeyStart, wordsBetween, 0, wordsBetween.Length);
            string searchKey = String.Join("_", wordsBetween);

            Dictionary<string, Item> searchDictionary;

            switch (questExtraCategory) {
                case "coin_quest":
                    // what does "_w_" and "_m_" mean ?
                    if (searchKey == "medal")
                        searchDictionary = medals;
                    else {
                        searchKey = searchKey.Remove(searchKey.Length - 2, 2);
                        if (searchKey != "coin")
                            return null;
                        searchDictionary = coins;
                    }
                    level = minLevel = 0;
                    break;
                case "draconic_recipe_quest":
                    if (searchKey != "master_recipe_quest")
                        return null;
                    searchDictionary = recipes;
                    break;
                case "gold_quest":
                    if (searchKey.StartsWith("rnd_"))
                        searchKey = searchKey.Remove(0, 4);
                    if (searchKey != "redeem")
                        return null;
                    searchDictionary = redeems;
                    level = minLevel = 0;
                    break;
                default:
                    if (searchKey == "fortress") {
                        // For fortress return medals;
                        searchDictionary = medals;
                        level = minLevel = 0;
                    } else if (searchKey == "island" || searchKey == "boss" || searchKey == "task") {
                        return null;
                    } else if (searchKey == "recipe") {
                        // %Quest_L_Recipe_20a_LF2A
                        searchDictionary = recipes;
                    } else if (searchKey == "matter_option") {
                        searchDictionary = matterOptions;
                    } else if (searchKey == "food") {
                        searchDictionary = food;
                    } else if (searchKey == "magical") {
                        searchDictionary = magicals;
                    } else if (searchKey == "medicine") {
                        searchDictionary = medicines;
                    } else if (searchKey == "rnd_redeem") {
                        searchDictionary = redeems;
                        level = minLevel = 0;
                    } else if (searchKey == "material") {
                        searchDictionary = materials;
                    } else if (searchKey == "master") {
                        searchDictionary = masterReceipts;
                    } else {
                        return null;
                    }
                    break;
            }

            if (!String.IsNullOrEmpty(additionalFilter)) {
                searchDictionary = searchDictionary.Where(p => p.Key.Contains(additionalFilter,
                                                               StringComparison.InvariantCultureIgnoreCase))
                                                   .ToDictionary(p => p.Key, p => p.Value);
            }

            string includeFilter, excludeFilter, raceFilter;
            if (isQuestL) {
                includeFilter = "_l_";
                excludeFilter = "_d_";
                raceFilter = "pc_light";
            } else {
                includeFilter = "_d_";
                if (searchKey == "rnd_redeem")
                    excludeFilter = "junk_redeem_jewelry";
                else
                    excludeFilter = "_l_";
                raceFilter = "pc_dark";
            }

            var include = searchDictionary.Where(p => p.Key.Contains(includeFilter,
                                                      StringComparison.InvariantCultureIgnoreCase));
            var theRest = searchDictionary.Except(include);
            var exclude = theRest.Where(p => !p.Key.Contains(excludeFilter,
                                             StringComparison.InvariantCultureIgnoreCase) &&
                                             p.Value.race_permitted.Contains(raceFilter));
            var joined = include.Concat(exclude);

            int readLevel = 0;
            var levelFiltered = from j in joined
                                let lastUnderscore = j.Key.LastIndexOf('_')
                                let strLast = lastUnderscore > 0 ?
                                              j.Key.Substring(lastUnderscore + 1) : String.Empty
                                let lastIsChar = strLast.Length < 2 ? false :
                                                 Char.IsLetter(strLast[strLast.Length - 1])
                                let strLevel = lastIsChar ? strLast.Remove(strLast.Length - 1, 1)
                                                          : strLast
                                let hadLevel = Int32.TryParse(strLevel, out readLevel)
                                let found = hadLevel && readLevel < maxLevel && readLevel >= level
                                where found
                                select j.Value;

            Item result = levelFiltered.FirstOrDefault();
            if (result != null) {
                result = result.Clone();
                result.ChooseItemsFrom = levelFiltered;
                randomSettings.Level = minLevel;
                result.RandomSettings = randomSettings;
            }
            return result;
        }
Пример #3
0
        public Item GetRewardBonusForLevel(RandomItemSettings settings, IEnumerable<Item> chooseItemsFrom, int level)
        {
            Dictionary<string, Item> tempDic = chooseItemsFrom.ToDictionary(i => i.name, i => i);
            int readLevel = 0;

            var levelFiltered = from j in tempDic
                                let lastUnderscore = j.Key.LastIndexOf('_')
                                let strLast = lastUnderscore > 0 ?
                                              j.Key.Substring(lastUnderscore + 1) : String.Empty
                                let lastIsChar = strLast.Length < 2 ? false :
                                                 Char.IsLetter(strLast[strLast.Length - 1])
                                let strLevel = lastIsChar ? strLast.Remove(strLast.Length - 1, 1)
                                                          : strLast
                                let hadLevel = Int32.TryParse(strLevel, out readLevel)
                                let found = hadLevel && readLevel <= level + 10 && readLevel >= level
                                where found
                                select j.Value;

            Item result = levelFiltered.FirstOrDefault();
            if (result != null) {
                result = result.Clone();
                result.ChooseItemsFrom = levelFiltered;
            }
            return result;
        }
Пример #4
0
        void AddRewardItem(ref List <Item> itemList, string itemData)
        {
            if (String.IsNullOrEmpty(itemData))
            {
                return;
            }
            string[] data  = itemData.Split(' ');
            int      count = 0;

            if (data.Length != 2 || !Int32.TryParse(data[1], out count))
            {
                count = 1;
            }

            Item item = null;

            if (data[0].StartsWith("%Quest_"))
            {
                int  minLevel;
                bool isLight = this.race_permitted.Contains("pc_light");
                item = Utility.ItemIndex.GetRewardBonusItem(0, isLight, this.extra_category, data[0],
                                                            out minLevel);
                if (item == null)   // not implemented
                {
                    item = new Item()
                    {
                        name = "Not implemented"
                    };
                    item.desc_long = "Decision made reward";
                }
                else
                {
                    if (item.name == "X")
                    {
                        RandomItemSettings settings = new RandomItemSettings()
                        {
                            Level     = 10,
                            BonusName = "Christmas",
                            IsLight   = isLight
                        };
                        item.RandomSettings = settings;
                        item.name           = "Christmas scene";
                        item.desc_long      = "Christmas cut scene for boys and girls";
                        item.level          = 10;
                        List <Item> movies = new List <Item>();
                        Item        it     = item.Clone();
                        it.id    = 135;
                        it.name += "_10";
                        movies.Add(it);
                        it       = item.Clone();
                        it.name += "_11";
                        it.id    = 136;
                        movies.Add(it);
                        it       = item.Clone();
                        it.name += "_12";
                        it.id    = 103;
                        movies.Add(it);
                        it       = item.Clone();
                        it.name += "_13";
                        it.id    = 136;
                        movies.Add(it);
                        item.ChooseItemsFrom = movies;
                    }
                    else
                    {
                        item.name      = "Random reward";
                        item.desc_long = "Decision made reward";
                    }
                }
                item.icon_name = "icon_quest_dummy01";
            }
            else
            {
                item = Utility.ItemIndex.GetItem(data[0]);
            }
            if (item != null)
            {
                Item addItem = item.Clone();
                addItem.Count = count;
                itemList.Add(addItem);
            }
        }
Пример #5
0
        public Item GetRewardBonusItem(int level, bool light, string questExtraCategory, string bonusName,
                                       out int minLevel)
        {
            minLevel = 0;

            if (String.IsNullOrEmpty(bonusName) || !bonusName.StartsWith("%Quest_"))
            {
                return(null);
            }

            // save Search
            var randomSettings = new RandomItemSettings()
            {
                BonusName     = bonusName,
                ExtraCategory = questExtraCategory,
                IsLight       = light,
                Level         = level
            };

            var    bonusMagicWords  = bonusName.Split('_').Select(w => w.ToLower()).ToArray();
            int    searchKeyStart   = 2;
            bool   isQuestL         = false;
            string additionalFilter = String.Empty;

            if (bonusMagicWords[1].Length == 1)
            {
                isQuestL = bonusMagicWords[1] == "l";
            }
            else
            {
                if (bonusMagicWords[1].Length != 2) // ws etc.
                {
                    return(null);
                }
                additionalFilter = String.Format("_{0}_", bonusMagicWords[1]);
                isQuestL         = light;
            }

            int last = bonusMagicWords.Length - 1;

            if (last < 2)
            {
                return(null);
            }

            string levelSuffix = bonusMagicWords[last];

            if (levelSuffix == "lf2a")   // only one such quest in Theobomos
            {
                additionalFilter = levelSuffix;
                // %Quest_L_Recipe_20a_LF2A
                last--;
                levelSuffix = bonusMagicWords[last];
                Array.Resize(ref bonusMagicWords, last + 1);
            }
            else if (levelSuffix == "woman" || levelSuffix == "man")
            {
                if (bonusMagicWords[last - 1] == "christmas")
                {
                    return new Item()
                           {
                               name = "X"
                           }
                }
                ;
            }

            if (Char.IsLetter(levelSuffix[levelSuffix.Length - 1]))
            {
                levelSuffix = levelSuffix.Remove(levelSuffix.Length - 1, 1);
            }
            int maxLevel = Int32.Parse(levelSuffix);

            // if the strict level, search items between that level and next
            minLevel = maxLevel;
            if (maxLevel % 10 != 0)
            {
                maxLevel -= maxLevel % 10;
            }

            if (level > minLevel)
            {
                minLevel = level;
            }

            if (level > 0)
            {
                maxLevel += 10;
            }
            else
            {
                maxLevel = Int32.MaxValue; // search all
            }
            level = minLevel;

            string[] wordsBetween = new String[bonusMagicWords.Length - searchKeyStart - 1];
            Array.Copy(bonusMagicWords, searchKeyStart, wordsBetween, 0, wordsBetween.Length);
            string searchKey = String.Join("_", wordsBetween);

            Dictionary <string, Item> searchDictionary;

            switch (questExtraCategory)
            {
            case "coin_quest":
                // what does "_w_" and "_m_" mean ?
                if (searchKey == "medal")
                {
                    searchDictionary = medals;
                }
                else
                {
                    searchKey = searchKey.Remove(searchKey.Length - 2, 2);
                    if (searchKey != "coin")
                    {
                        return(null);
                    }
                    searchDictionary = coins;
                }
                level = minLevel = 0;
                break;

            case "draconic_recipe_quest":
                if (searchKey != "master_recipe_quest")
                {
                    return(null);
                }
                searchDictionary = recipes;
                break;

            case "gold_quest":
                if (searchKey.StartsWith("rnd_"))
                {
                    searchKey = searchKey.Remove(0, 4);
                }
                if (searchKey != "redeem")
                {
                    return(null);
                }
                searchDictionary = redeems;
                level            = minLevel = 0;
                break;

            default:
                if (searchKey == "fortress")
                {
                    // For fortress return medals;
                    searchDictionary = medals;
                    level            = minLevel = 0;
                }
                else if (searchKey == "island" || searchKey == "boss" || searchKey == "task")
                {
                    return(null);
                }
                else if (searchKey == "recipe")
                {
                    // %Quest_L_Recipe_20a_LF2A
                    searchDictionary = recipes;
                }
                else if (searchKey == "matter_option")
                {
                    searchDictionary = matterOptions;
                }
                else if (searchKey == "food")
                {
                    searchDictionary = food;
                }
                else if (searchKey == "magical")
                {
                    searchDictionary = magicals;
                }
                else if (searchKey == "medicine")
                {
                    searchDictionary = medicines;
                }
                else if (searchKey == "rnd_redeem")
                {
                    searchDictionary = redeems;
                    level            = minLevel = 0;
                }
                else if (searchKey == "material")
                {
                    searchDictionary = materials;
                }
                else if (searchKey == "master")
                {
                    searchDictionary = masterReceipts;
                }
                else
                {
                    return(null);
                }
                break;
            }

            if (!String.IsNullOrEmpty(additionalFilter))
            {
                searchDictionary = searchDictionary.Where(p => p.Key.Contains(additionalFilter,
                                                                              StringComparison.InvariantCultureIgnoreCase))
                                   .ToDictionary(p => p.Key, p => p.Value);
            }

            string includeFilter, excludeFilter, raceFilter;

            if (isQuestL)
            {
                includeFilter = "_l_";
                excludeFilter = "_d_";
                raceFilter    = "pc_light";
            }
            else
            {
                includeFilter = "_d_";
                if (searchKey == "rnd_redeem")
                {
                    excludeFilter = "junk_redeem_jewelry";
                }
                else
                {
                    excludeFilter = "_l_";
                }
                raceFilter = "pc_dark";
            }

            var include = searchDictionary.Where(p => p.Key.Contains(includeFilter,
                                                                     StringComparison.InvariantCultureIgnoreCase));
            var theRest = searchDictionary.Except(include);
            var exclude = theRest.Where(p => !p.Key.Contains(excludeFilter,
                                                             StringComparison.InvariantCultureIgnoreCase) &&
                                        p.Value.race_permitted.Contains(raceFilter));
            var joined = include.Concat(exclude);

            int readLevel     = 0;
            var levelFiltered = from j in joined
                                let lastUnderscore = j.Key.LastIndexOf('_')
                                                     let strLast = lastUnderscore > 0 ?
                                                                   j.Key.Substring(lastUnderscore + 1) : String.Empty
                                                                   let lastIsChar = strLast.Length < 2 ? false :
                                                                                    Char.IsLetter(strLast[strLast.Length - 1])
                                                                                    let strLevel = lastIsChar ? strLast.Remove(strLast.Length - 1, 1)
                                                          : strLast
                                                                                                   let hadLevel                         = Int32.TryParse(strLevel, out readLevel)
                                                                                                                              let found = hadLevel && readLevel < maxLevel && readLevel >= level
                                                                                                                                          where found
                                                                                                                                          select j.Value;

            Item result = levelFiltered.FirstOrDefault();

            if (result != null)
            {
                result = result.Clone();
                result.ChooseItemsFrom = levelFiltered;
                randomSettings.Level   = minLevel;
                result.RandomSettings  = randomSettings;
            }
            return(result);
        }
Пример #6
0
        void AddRewardItem(ref List<Item> itemList, string itemData)
        {
            if (String.IsNullOrEmpty(itemData))
                return;
            string[] data = itemData.Split(' ');
            int count = 0;
            if (data.Length != 2 || !Int32.TryParse(data[1], out count))
                count = 1;

            Item item = null;
            if (data[0].StartsWith("%Quest_")) {
                int minLevel;
                bool isLight = this.race_permitted.Contains("pc_light");
                item = Utility.ItemIndex.GetRewardBonusItem(0, isLight, this.extra_category, data[0],
                                                            out minLevel);
                if (item == null) { // not implemented
                    item = new Item() { name = "Not implemented" };
                    item.desc_long = "Decision made reward";
                } else {
                    if (item.name == "X") {
                        RandomItemSettings settings = new RandomItemSettings()
                        {
                            Level = 10,
                            BonusName = "Christmas",
                            IsLight = isLight
                        };
                        item.RandomSettings = settings;
                        item.name = "Christmas scene";
                        item.desc_long = "Christmas cut scene for boys and girls";
                        item.level = 10;
                        List<Item> movies = new List<Item>();
                        Item it = item.Clone();
                        it.id = 135;
                        it.name += "_10";
                        movies.Add(it);
                        it = item.Clone();
                        it.name += "_11";
                        it.id = 136;
                        movies.Add(it);
                        it = item.Clone();
                        it.name += "_12";
                        it.id = 103;
                        movies.Add(it);
                        it = item.Clone();
                        it.name += "_13";
                        it.id = 136;
                        movies.Add(it);
                        item.ChooseItemsFrom = movies;
                    } else {
                        item.name = "Random reward";
                        item.desc_long = "Decision made reward";
                    }
                }
                item.icon_name = "icon_quest_dummy01";
            } else {
                item = Utility.ItemIndex.GetItem(data[0]);
            }
            if (item != null) {
                Item addItem = item.Clone();
                addItem.Count = count;
                itemList.Add(addItem);
            }
        }