コード例 #1
0
        public static async Task GenerateUB3List()
        {
            var ub3List = new List <UB3Object>();
            var list    = await AvastarObject.GetSeriesList();

            foreach (var ava in list)
            {
                ava.traits.Remove("background_color");
                ava.traits.Remove("backdrop");
                var kp = ava.traits.ToList();
                for (int i = 0; i < kp.Count - 2; i++)
                {
                    for (int j = i + 1; j < kp.Count - 1; j++)
                    {
                        for (int k = j + 1; k < kp.Count; k++)
                        {
                            var combo = ub3List.FirstOrDefault(c => c.CheckCombo(kp[i].Key, kp[j].Key, kp[k].Key, kp[i].Value, kp[j].Value, kp[k].Value));
                            if (combo == null)
                            {
                                ub3List.Add(new UB3Object(kp[i].Key, kp[j].Key, kp[k].Key, kp[i].Value, kp[j].Value, kp[k].Value, ava.id));
                            }
                            else
                            {
                                combo.Match.Add(ava.id);
                            }
                        }
                    }
                }
            }
            var ub3Collec = DatabaseConnection.GetDb().GetCollection <UB3Object>("UB3Collection");
            await ub3Collec.InsertManyAsync(ub3List);
        }
コード例 #2
0
        public static async Task <List <UB3Object> > GetUB3CombosForId(int id)
        {
            var ub3List   = new List <UB3Object>();
            var ub3Collec = DatabaseConnection.GetDb().GetCollection <UB3Object>("UB3Collection");
            var ava       = await AvastarObject.GetAva(id);

            var gender = ava.Gender;

            ava.traits.Remove("background_color");
            ava.traits.Remove("backdrop");
            var kp = ava.traits.ToList();

            for (int i = 0; i < kp.Count - 2; i++)
            {
                for (int j = i + 1; j < kp.Count - 1; j++)
                {
                    for (int k = j + 1; k < kp.Count; k++)
                    {
                        var combo = (await ub3Collec.FindAsync(c => c.Trait1Name == kp[i].Key && c.Trait2Name == kp[j].Key && c.Trait3Name == kp[k].Key && c.Trait1Type == kp[i].Value && c.Trait2Type == kp[j].Value && c.Trait3Type == kp[k].Value)).FirstOrDefault();
                        ub3List.Add(combo);
                    }
                }
            }
            return(ub3List);
        }
コード例 #3
0
ファイル: AvastarObject.cs プロジェクト: cesarsld/AvastarBot
        public static async Task CreateAva(int id)
        {
            var ava = new AvastarObject();

            ava.id = id;
            string metadatastr = "";

            using (System.Net.WebClient wc = new System.Net.WebClient()) {
                try {
                    metadatastr = await wc.DownloadStringTaskAsync("https://avastars.io/metadata/" + id.ToString());
                }
                catch (Exception e) {
                    Console.WriteLine(e.Message);
                }
            }
            if (metadatastr.StartsWith("Invalid"))
            {
                return;
            }
            var traitJson    = JObject.Parse(DiscordKeyGetter.GetFileData("app/create-traits-nosvg.json"));
            var metadataJson = JObject.Parse(metadatastr);

            ava.id     = id;
            ava.Gender = (string)metadataJson["attributes"][0]["value"];
            ava.Score  = (int)metadataJson["attributes"][5]["value"];
            ava.traits = new Dictionary <string, string>();
            for (int i = 7; i < 19; i++)
            {
                ava.traits.Add((string)metadataJson["attributes"][i]["trait_type"], (string)metadataJson["attributes"][i]["value"]);
            }
            var disp = AvastarCommands.ReturnTraitDisparity(metadataJson, traitJson);

            ava.Owner = "";
            ava.RarityDistribution = new Dictionary <string, int>();
            ava.RarityDistribution.Add("Common", disp[0]);
            ava.RarityDistribution.Add("Uncommon", disp[1]);
            ava.RarityDistribution.Add("Rare", disp[2]);
            ava.RarityDistribution.Add("Epic", disp[3]);
            ava.RarityDistribution.Add("Legendary", disp[4]);
            ava.FillTraitDictionary(traitJson, metadataJson);
            var collec = DatabaseConnection.GetDb().GetCollection <AvastarObject>("AvastarCollection");
            await collec.InsertOneAsync(ava);

            var ub2List = await UB2Object.UpdateUb2List(ava);

            var ub3List = await UB3Object.UpdateUb3List(ava);

            await AvaUBObject.UpdateAvaUbList(ava, ub2List, ub3List);
        }
コード例 #4
0
        //TODO improve function to prevent 220 db calls...
        public static async Task <List <UB3Object> > UpdateUb3List(AvastarObject ava)
        {
            var ub3Collec  = DatabaseConnection.GetDb().GetCollection <UB3Object>("UB3Collection");
            var returnList = new List <UB3Object>();

            ava.traits.Remove("background_color");
            ava.traits.Remove("backdrop");
            var kp = ava.traits.ToList();

            for (int i = 0; i < kp.Count - 2; i++)
            {
                for (int j = i + 1; j < kp.Count - 1; j++)
                {
                    for (int k = j + 1; k < kp.Count; k++)
                    {
                        var combo = (await ub3Collec.FindAsync(c => c.Trait1Name == kp[i].Key && c.Trait2Name == kp[j].Key && c.Trait3Name == kp[k].Key && c.Trait1Type == kp[i].Value && c.Trait2Type == kp[j].Value && c.Trait3Type == kp[k].Value)).FirstOrDefault();

                        if (combo == null)
                        {
                            var obj = new UB3Object(kp[i].Key, kp[j].Key, kp[k].Key, kp[i].Value, kp[j].Value, kp[k].Value, ava.id);
                            returnList.Add(obj);
                            await ub3Collec.InsertOneAsync(obj);
                        }
                        else
                        {
                            if (!combo.Match.Contains(ava.id))
                            {
                                combo.Match.Add(ava.id);
                                var update = Builders <UB3Object> .Update.Set(c => c.Match, combo.Match);

                                await ub3Collec.FindOneAndUpdateAsync(c => c.id == combo.id, update);
                            }
                            returnList.Add(combo);
                        }
                    }
                }
            }
            return(returnList);
        }
コード例 #5
0
        public static async Task GenerateAvaUbList()
        {
            var avaList = await AvastarObject.GetSeriesList();

            var ub2TotalList = await UB2Object.GetUb2List();

            var avaUBList = new List <AvaUBObject>();
            //Ub2 List Generation
            var count = avaList.Count;
            var index = 0;

            foreach (var ava in avaList)
            {
                Console.WriteLine($"{index} out of {count}");
                ava.traits.Remove("background_color");
                ava.traits.Remove("backdrop");
                var gender  = ava.Gender;
                var ub2List = new List <UB2Object>();
                var kp      = ava.traits.ToList();
                for (int i = 0; i < kp.Count - 1; i++)
                {
                    for (int j = i + 1; j < kp.Count; j++)
                    {
                        var combo = ub2TotalList.Where(c => c.Trait1Name == kp[i].Key && c.Trait2Name == kp[j].Key && c.Trait1Type == kp[i].Value && c.Trait2Type == kp[j].Value).FirstOrDefault();
                        ub2List.Add(combo);
                    }
                }
                var ub2Many = ub2List.Where(ub2 => ub2.Match.Count > 1).ToList();
                ub2List = ub2List.Where(ub2 => ub2.Match.Count == 1).ToList();
                foreach (var ubs in ub2Many)
                {
                    bool uniqueGender = true;
                    foreach (var token in ubs.Match)
                    {
                        if (token != ava.id && avaList.Where(a => a.id == token).FirstOrDefault().Gender == gender)
                        {
                            uniqueGender = false;
                            break;
                        }
                    }
                    if (uniqueGender)
                    {
                        ub2List.Add(ubs);
                    }
                }
                avaUBList.Add(new AvaUBObject(ava.id, ub2List));
                Console.SetCursorPosition(0, 2 - 1);
                index++;
            }
            index = 0;
            var ub3TotalList = await UB3Object.GetUb3List();

            //Generating Ub3 list
            foreach (var ava in avaList)
            {
                Console.WriteLine($"{index} out of {count}");
                var gender  = ava.Gender;
                var ub3List = new List <UB3Object>();
                var kp      = ava.traits.ToList();
                for (int i = 0; i < kp.Count - 2; i++)
                {
                    for (int j = i + 1; j < kp.Count - 1; j++)
                    {
                        for (int k = j + 1; k < kp.Count; k++)
                        {
                            var combo = ub3TotalList.Where(c => c.Trait1Name == kp[i].Key && c.Trait2Name == kp[j].Key && c.Trait3Name == kp[k].Key && c.Trait1Type == kp[i].Value && c.Trait2Type == kp[j].Value && c.Trait3Type == kp[k].Value).FirstOrDefault();
                            ub3List.Add(combo);
                        }
                    }
                }
                var ub3Many = ub3List.Where(ub3 => ub3.Match.Count > 1).ToList();
                ub3List = ub3List.Where(ub3 => ub3.Match.Count == 1).ToList();
                foreach (var ubs in ub3Many)
                {
                    bool uniqueGender = true;
                    foreach (var token in ubs.Match)
                    {
                        if (token != ava.id && avaList.Where(a => a.id == token).FirstOrDefault().Gender == gender)
                        {
                            uniqueGender = false;
                            break;
                        }
                    }
                    if (uniqueGender)
                    {
                        ub3List.Add(ubs);
                    }
                    avaUBList.Where(a => a.id == ava.id).FirstOrDefault().ub3List = ub3List.Select(ub => ub.id.ToString()).ToList();
                }
                Console.SetCursorPosition(0, 3 - 1);
                index++;
            }
            var collec = DatabaseConnection.GetDb().GetCollection <AvaUBObject>("AvaUbCollection");
            await collec.InsertManyAsync(avaUBList);
        }
コード例 #6
0
        public static async Task UpdateAvaUbList(AvastarObject ava, List <UB2Object> ub2List, List <UB3Object> ub3List)
        {
            var ub2Copy = ub2List;
            var ub3Copy = ub3List;
            var avaList = await AvastarObject.GetSeriesList();

            var avaUbList = await GetAvaUbList();

            var gender = ava.Gender;
            //Computuing UB2s
            var ub2Many = ub2List.Where(ub2 => ub2.Match.Count > 1).ToList();

            ub2List = ub2List.Where(ub2 => ub2.Match.Count == 1).ToList();
            foreach (var ubs in ub2Many)
            {
                bool uniqueGender = true;
                foreach (var token in ubs.Match)
                {
                    if (token != ava.id && avaList.Where(a => a.id == token).FirstOrDefault().Gender == gender)
                    {
                        uniqueGender = false;
                        break;
                    }
                }
                if (uniqueGender)
                {
                    ub2List.Add(ubs);
                }
            }
            var avaUbObj           = new AvaUBObject(ava.id, ub2List);
            var collec             = DatabaseConnection.GetDb().GetCollection <AvaUBObject>("AvaUbCollection");
            var avaUbObjFromCollec = await(await collec.FindAsync(auo => auo.id == ava.id)).FirstOrDefaultAsync();

            if (avaUbObjFromCollec == null)
            {
                await collec.InsertOneAsync(avaUbObj);
            }
            else
            {
                await collec.FindOneAndReplaceAsync(auo => auo.id == ava.id, avaUbObj);
            }
            avaUbList.Add(avaUbObj);
            foreach (var ub in ub2List)
            {
                ub2Copy.Remove(ub);
            }
            // ub2Copy contains all combos that are duplicates
            // get all ID in each combo, find only the ones that are same gender
            // access avaubdata and remove ID of combo
            try
            {
                foreach (var ub in ub2Copy)
                {
                    foreach (var id in ub.Match)
                    {
                        var tempAva = avaList.Where(a => a.id == id).FirstOrDefault();
                        if (tempAva == null)
                        {
                            continue;
                        }
                        if (tempAva.Gender == ava.Gender)
                        {
                            var tempAvaUb = avaUbList.Where(a => a.id == id).FirstOrDefault();
                            if (tempAvaUb == null)
                            {
                                continue;
                            }
                            if (tempAvaUb.ub2List.Remove(ub.id.ToString()))
                            {
                                var update = Builders <AvaUBObject> .Update.Set(a => a.ub2List, tempAvaUb.ub2List);

                                await collec.UpdateOneAsync(a => a.id == tempAvaUb.id, update);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            //Computing UB3s
            try
            {
                var ub3Many = ub3List.Where(ub3 => ub3.Match.Count > 1).ToList();
                ub3List = ub3List.Where(ub3 => ub3.Match.Count == 1).ToList();
                foreach (var ubs in ub3Many)
                {
                    bool uniqueGender = true;
                    foreach (var token in ubs.Match)
                    {
                        if (token != ava.id && avaList.Where(a => a.id == token).FirstOrDefault().Gender == gender)
                        {
                            uniqueGender = false;
                            break;
                        }
                    }
                    if (uniqueGender)
                    {
                        ub3List.Add(ubs);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            avaUbObj.ub3List = ub3List.Select(a => a.id.ToString()).ToList();
            var ub3Update = Builders <AvaUBObject> .Update.Set(a => a.ub3List, avaUbObj.ub3List);

            await collec.UpdateOneAsync(a => a.id == ava.id, ub3Update);

            foreach (var ub in ub3List)
            {
                ub3Copy.Remove(ub);
            }
            foreach (var ub in ub3Copy)
            {
                foreach (var id in ub.Match)
                {
                    var tempAva = avaList.Where(a => a.id == id).FirstOrDefault();
                    if (tempAva == null)
                    {
                        continue;
                    }
                    if (tempAva.Gender == ava.Gender)
                    {
                        var tempAvaUb = avaUbList.Where(a => a.id == id).FirstOrDefault();
                        if (tempAvaUb == null)
                        {
                            continue;
                        }
                        if (tempAvaUb.ub3List.Remove(ub.id.ToString()))
                        {
                            var update = Builders <AvaUBObject> .Update.Set(a => a.ub3List, tempAvaUb.ub3List);

                            await collec.UpdateOneAsync(a => a.id == tempAvaUb.id, update);
                        }
                    }
                }
            }
        }
コード例 #7
0
ファイル: AvastarObject.cs プロジェクト: cesarsld/AvastarBot
        public static async Task MigrateAva(int id)
        {
            var oldAva = await AvastarObject.GetAva(id);

            var ava = new AvastarObject();

            ava.id           = oldAva.id;
            ava.Gender       = oldAva.Gender;
            ava.Score        = oldAva.Score;
            ava.traits       = oldAva.traits;
            ava.Owner        = "";// await Blockchain.ChainWatcher.GetOwnerOf(id);
            ava.TraitsRarity = new Dictionary <string, string>();
            var traitJson = JObject.Parse(DiscordKeyGetter.GetFileData("app/create-traits-nosvg.json"));

            foreach (var pair in ava.traits)
            {
                var traitType     = pair.Key;
                var traitName     = pair.Value;
                var traitRarity   = "";
                var traitTypeName = AvastarCommands.Capitalise(traitType.Replace('_', ' '));
                foreach (var trait in traitJson[traitTypeName])
                {
                    if (trait.Type == JTokenType.Null)
                    {
                        continue;
                    }
                    if ((string)trait["name"] == traitName)
                    {
                        traitRarity = (string)trait["rarity"];
                        break;
                    }
                }
                ava.TraitsRarity.Add(traitType, traitRarity);
            }
            ava.RarityDistribution = new Dictionary <string, int>();
            ava.RarityDistribution.Add("Common", 0);
            ava.RarityDistribution.Add("Uncommon", 0);
            ava.RarityDistribution.Add("Rare", 0);
            ava.RarityDistribution.Add("Epic", 0);
            ava.RarityDistribution.Add("Legendary", 0);
            foreach (var pair in ava.TraitsRarity)
            {
                switch (pair.Value)
                {
                case "Common":
                    ava.RarityDistribution["Common"]++;
                    break;

                case "Uncommon":
                    ava.RarityDistribution["Uncommon"]++;
                    break;

                case "Rare":
                    ava.RarityDistribution["Rare"]++;
                    break;

                case "Epic":
                    ava.RarityDistribution["Epic"]++;
                    break;

                case "Legendary":
                    ava.RarityDistribution["Legendary"]++;
                    break;
                }
            }
            var collec = DatabaseConnection.GetDb().GetCollection <AvastarObject>("AvastarCollection");
            await collec.ReplaceOneAsync(a => a.id == id, ava);
        }