/// <summary> /// Купить награду /// </summary> /// <param name="_pers">Персонаж</param> /// <param name="costProperty">Цена награды</param> public void BuyReward(Pers _pers, int costProperty) { StaticMetods.PlaySound(Properties.Resources.coin); var editableReward = this; ObservableCollection <Revard> shopItems = _pers.ShopItems; List <Revard> uni = (_pers.InventoryItems.Union(_pers.ShopItems)).ToList(); var vc = new ViewChangesClass(uni); vc.GetValBefore(); _pers.GoldProperty -= costProperty; _pers.InventoryItems.Add(editableReward); vc.GetValAfter(); var header = $"{editableReward.GetTypeOfRevard()} \"{editableReward.NameOfProperty}\" добавлен в инвентарь!!!"; Brush col = Brushes.Green; var itemImageProperty = StaticMetods.pathToImage(Path.Combine(Directory.GetCurrentDirectory(), "Images", "good.png")); vc.ShowChanges(header, col, itemImageProperty); if (editableReward.IsArtefact) { shopItems.Remove(editableReward); } StaticMetods.AbillitisRefresh(_pers); StaticMetods.refreshShopItems(_pers); }
public static void SetDefoultImages() { DefoultTaskImage = StaticMetods.pathToImage(Path.Combine(Directory.GetCurrentDirectory(), "Images", "Task.png")); DefoultAbilImage = StaticMetods.pathToImage( Path.Combine(Directory.GetCurrentDirectory(), "Images", "AbDefoult.png")); DefoultCharactImage = StaticMetods.pathToImage( Path.Combine(Directory.GetCurrentDirectory(), "Images", "ChaDefoult.jpg")); DefoultQwestImage = StaticMetods.pathToImage(Path.Combine(Directory.GetCurrentDirectory(), "Images", "mission.jpg")); DefoultRewImage = StaticMetods.pathToImage(Path.Combine(Directory.GetCurrentDirectory(), "Images", "gold.png")); // Картинки DefoultTaskPic = StaticMetods.getImagePropertyFromImage(DefoultTaskImage); DefoultAbilPic = StaticMetods.getImagePropertyFromImage(DefoultAbilImage); DefoultCharactPic = StaticMetods.getImagePropertyFromImage(DefoultCharactImage); DefoultQwestPic = StaticMetods.getImagePropertyFromImage(DefoultQwestImage); DefoultRewPic = StaticMetods.getImagePropertyFromImage(DefoultRewImage); }
public static byte[] ImageByWord(string id) { // Поиск в базе string pathToImgBase = @"Images\ElementsImages"; Fastenshtein.Levenshtein lev = new Fastenshtein.Levenshtein(id.ToLower()); var fls = Directory.GetFiles(pathToImgBase).Select(n => new { name = Path.GetFileNameWithoutExtension(n), path = n, dist = lev.DistanceFrom(Path.GetFileNameWithoutExtension(n).ToLower()) }).OrderBy(n => n.dist).ToList(); var fod = fls.FirstOrDefault(); if (fod?.dist <= 2) { return(StaticMetods.pathToImage(fod.path)); } else { var tryes = 0; bool isSuccess = false; byte[] img = null; while (!isSuccess && tryes < 10) { try { string html = GetHtmlCode(id); List <string> urls = GetUrls(html).ToList(); int randomUrl = rnd.Next(0, urls.Count - 1); string luckyUrl = urls[randomUrl]; img = GetImage(luckyUrl); isSuccess = true; } catch { tryes++; } } return(img); } }