public async Task <ActionResult> Update(string?id, string?date, [FromQuery] string[] itemnames, [FromQuery] string[] removeid)
        {
            foreach (var name in itemnames)
            {
                if (id != null)
                {
                    var labID   = Int16.Parse(id ?? "0");
                    var type    = Int16.Parse(name.Split(' ').Last());
                    int itemIDs = ItemDB.Add(new Item(name.Split(' ')[0], (ItemTypes)type));
                    LabItemDB.AddItem(labID, itemIDs);
                }
            }

            if (id != null)
            {
                foreach (var removeID in removeid)
                {
                    var labID  = Int16.Parse(id ?? "0");
                    var itemID = Int16.Parse(removeID ?? "0");
                    var itemDB = await ItemDB.GetByIDAsync(itemID);

                    var labItemDB = await LabItemDB.GetAllByLabIDAsync(labID);

                    var    db          = new SoftwareStudioContext();
                    string queryString = $"DELETE FROM laboratory_items WHERE item_id = {itemID}; DELETE FROM items WHERE uuid = {itemID}; ";
                    // var items = await db.itemDetails.FromSqlRaw(queryString).ToListAsync();
                    await db.Database.ExecuteSqlRawAsync(queryString);
                }
            }
            return(RedirectToAction("Detail", new { id = id, date = date }));
        }
예제 #2
0
        private async Task Overwrite(HttpClient httpClient)
        {
            var wikiUtils = new WikiUtils(httpClient);
            var gemTasks  = await wikiUtils.SelectFromGemsAsync(ParseGemTable);

            foreach (var task in gemTasks)
            {
                var gem = await task;
                if (gem == null)
                {
                    continue;
                }
                ItemDB.Add(gem);
            }
        }
예제 #3
0
        private async Task UpdateSingle(string singleGemName)
        {
            var fetched = await _gemReader.FetchGemAsync(singleGemName);

            if (fetched == null)
            {
                return;
            }
            if (!LoadOld())
            {
                return;
            }
            var old = ItemDB.GetGem(singleGemName);

            if (old == null)
            {
                ItemDB.Add(fetched);
            }
            else
            {
                old.Merge(fetched);
            }
        }
예제 #4
0
        protected override async Task LoadAsync()
        {
            await LoadRePoEAsync();

            foreach (var gemId in _gemsJson.Properties().Select(p => p.Name))
            {
                var gemObj = _gemsJson.Value <JObject>(gemId);
                if (gemObj["base_item"].Type == JTokenType.Null)
                {
                    Log.Info($"Skipping gem without base item with id {gemId}");
                    continue;
                }
                var baseItem = gemObj.Value <JObject>("base_item");
                if (baseItem.Value <string>("release_state") == "unreleased")
                {
                    Log.Info($"Skipping unreleased gem with id {gemId}");
                    continue;
                }

                var tooltipObj    = _gemTooltipsJson.Value <JObject>(gemId);
                var tooltipStatic = tooltipObj.Value <JObject>("static");
                if (tooltipStatic.Count == 0)
                {
                    Log.Warn($"Skipping gem with id {gemId} because 'static' is empty");
                    continue;
                }

                // Gem.Name
                var name = tooltipStatic.Value <string>("name");
                // Gem.Tags
                var tags = tooltipStatic.Value <JArray>("properties").Value <string>(0);
                // Gem.Attributes
                var attributes   = new List <ItemDB.Attribute>();
                var levelProps   = tooltipObj.Value <JObject>("per_level").Properties().ToList();
                var levelInts    = levelProps.Select(p => p.Name.ParseInt()).ToList();
                var levelObjects = levelProps.Select(p => p.Value).Cast <JObject>().ToList();
                // properties
                // skip line with gem tags and line with gem level
                attributes.AddRange(ParseAttributes(levelInts, levelObjects, "properties", 2));
                // quality stats
                attributes.AddRange(ParseAttributes(levelInts, levelObjects, "quality_stats", atQuality: 1));
                // stats
                attributes.AddRange(ParseAttributes(levelInts, levelObjects, "stats"));
                var gem = new ItemDB.Gem
                {
                    Name       = name,
                    Tags       = tags,
                    Attributes = attributes
                };

                var activeSkill = gemObj["active_skill"];
                if (activeSkill != null)
                {
                    // Gem.RequiresEquippedShield, RequiredHand, StrikesWithBothWeapons
                    var types = activeSkill.Value <JArray>("types").Values <string>().ToHashSet();
                    if (types.Contains("shield_only"))
                    {
                        gem.RequiresEquippedShield = true;
                    }
                    if (types.Contains("dual_wield_only"))
                    {
                        gem.RequiredHand = Compute.WeaponHand.DualWielded;
                    }
                    else if (types.Contains("uses_main_hand_when_dual_wielding"))
                    {
                        gem.RequiredHand = Compute.WeaponHand.Main;
                    }
                    // Reposte doesn't have the the active skill type
                    else if (types.Contains("uses_both_at_once_when_dual_wielding") || gem.Name == "Riposte")
                    {
                        gem.StrikesWithBothWeapons = true;
                    }
                    // Gem.RequiredWeapon
                    if (types.Contains("attack"))
                    {
                        var weaponRestrictions = activeSkill.Value <JArray>("weapon_restrictions").Values <string>().ToList();
                        foreach (var restriction in weaponRestrictions)
                        {
                            // map game's ItemClass to our WeaponType
                            var w = restriction;
                            if (w == "Thrusting One Hand Sword")
                            {
                                w = "One Hand Sword";
                            }
                            else if (w == "Sceptre")
                            {
                                w = "One Hand Mace";
                            }
                            w = Regex.Replace(w, @"([a-z]) ([A-Z])", "$1$2");
                            Compute.WeaponType weaponType;
                            if (Enum.TryParse(w, out weaponType))
                            {
                                gem.RequiredWeapon |= weaponType;
                            }
                            else
                            {
                                Log.Error("Unknown weapon type: " + w);
                            }
                        }
                    }
                }

                ItemDB.Add(gem);
            }

            ItemDB.WriteToCompletePath(SavePath);
        }
예제 #5
0
        // Main entry point.
        static int Main(string[] arguments)
        {
            bool   exit           = false;
            int    argFile        = -1;
            int    argGem         = -1;
            int    argMerge       = -1;
            string optFileName    = null;
            string optGemName     = null;
            string optMergeName   = null;
            bool   assetsDownload = false;
            bool   noBackup       = false;

            // Get options.
            if (arguments.Length > 0)
            {
                List <string> args = new List <string>(arguments);
                int           pos  = 0;

                for (var i = 0; i < args.Count && !exit;)
                {
                    string arg = args[i];

                    if (arg.Length == 0)
                    {
                        args.RemoveAt(0);   // Ignore empty argument.
                    }
                    else if (arg[0] == '/') // Decode switch.
                    {
                        switch (arg.ToUpperInvariant())
                        {
                        case "/?":
                            Console.WriteLine("Updates item database.\r\n");
                            Console.WriteLine("UPDATEDB [/F file] [[/G string] | [/M file]] [/N] [/Q | /V]\r\n");
                            Console.WriteLine("UPDATEDB /A\r\n");
                            Console.WriteLine("/A\tDownloads skill tree assets into current directory.");
                            Console.WriteLine("/F\tUpdate specified file instead of default file \"Items.xml\".");
                            Console.WriteLine("/G\tUpdate single gem specified by string.");
                            Console.WriteLine("/M\tMerge data of specified file instead of update.");
                            Console.WriteLine("/N\tDoes not create backup of file being updated before writing changes.");
                            Console.WriteLine("/Q\tDoes not display any output.");
                            Console.WriteLine("/V\tEnables verbose output.");
                            exit = true;
                            break;

                        case "/A":
                            assetsDownload = true;
                            break;

                        case "/F":
                            argFile = pos++;
                            break;

                        case "/G":
                            argGem = pos++;
                            break;

                        case "/M":
                            argMerge = pos++;
                            break;

                        case "/N":
                            noBackup = true;
                            break;

                        case "/Q":
                            Verbosity = VerbosityLevel.Quiet;
                            break;

                        case "/V":
                            Verbosity = VerbosityLevel.Verbose;
                            break;

                        default:
                            Console.WriteLine("Invalid switch - \"" + (arg.Length > 1 ? arg[1].ToString() : "") + "\"");
                            exit = true;
                            break;
                        }

                        args.RemoveAt(i);
                    }
                    else
                    {
                        ++i;  // Skip non-switch argument.
                    }
                }

                // Download assets if requested.
                if (assetsDownload)
                {
                    try
                    {
                        // Download Skill tree assets into current directory.
                        AppData.SetApplicationData(Environment.CurrentDirectory);

                        Info("Downloading skill tree assets...");
                        SkillTree.CreateSkillTree();
                        Info("Done.");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error: " + e.Message);

                        return(1);
                    }

                    return(0);
                }

                // Consume non-switch arguments in order of their switch appearance.
                if (argFile >= 0)
                {
                    if (args.Count < argFile + 1)
                    {
                        Console.WriteLine("Missing name of file to update");
                        exit = true;
                    }
                    else
                    {
                        optFileName = args[argFile];
                    }
                }
                if (argGem >= 0)
                {
                    if (args.Count < argGem + 1)
                    {
                        Console.WriteLine("Missing gem name");
                        exit = true;
                    }
                    else
                    {
                        optGemName = args[argGem];
                    }
                }
                if (argMerge >= 0)
                {
                    if (args.Count < argMerge + 1)
                    {
                        Console.WriteLine("Missing name of file to merge");
                        exit = true;
                    }
                    else
                    {
                        optMergeName = args[argMerge];
                    }
                }
            }
            if (exit)
            {
                return(1);
            }

            string appDataPath    = AppData.GetFolder(true);
            string updateFileName = optFileName == null ? "Items.xml" : optFileName;

            if (!File.Exists(appDataPath + updateFileName))
            {
                Console.WriteLine("File not found: " + appDataPath + updateFileName);

                return(1);
            }
            if (optMergeName != null && !File.Exists(appDataPath + optMergeName))
            {
                Console.WriteLine("File not found: " + appDataPath + optMergeName);

                return(1);
            }

            ItemDB.Load(updateFileName);

            bool   modified = false;
            Reader reader   = new GamepediaReader();

            if (optMergeName != null)
            {
                ItemDB.Merge(optMergeName);

                modified = true;
            }
            else if (optGemName != null)
            {
                Gem fetched = reader.FetchGem(optGemName);
                if (fetched != null)
                {
                    Gem gem = ItemDB.GetGem(optGemName);
                    if (gem == null)
                    {
                        ItemDB.Add(fetched);
                    }
                    else
                    {
                        gem.Merge(fetched);
                    }

                    modified = true;
                }
            }
            else
            {
                foreach (Gem gem in ItemDB.GetAllGems())
                {
                    Gem fetched = reader.FetchGem(gem.Name);
                    if (fetched != null)
                    {
                        gem.Merge(fetched);
                        modified = true;
                    }
                }
            }

            if (modified)
            {
                if (!noBackup)
                {
                    File.Copy(appDataPath + updateFileName, appDataPath + updateFileName + ".bak", true);
                }
                ItemDB.WriteTo(updateFileName);
            }

            return(0);
        }
예제 #6
0
 public JsonResult Add(ItemDB item)
 {
     return(Json(itemDB.Add(item), JsonRequestBehavior.AllowGet));
 }