public void initEquipView(Hero hero) { this.View.PotionSV.Width = 450; this.View.ShieldSV.Width = 450; this.View.WeaponSV.Width = 450; this.View.ToShieldButton.Click += ToShieldEquipButton_Click; this.View.ToWeaponButton.Click += ToWeaponEquipButton_Click; this.View.ToPotionButton.Click += ToPotionEquipButton_Click; foreach (Shield shield in GameViewModel.Instance.MainCastle.ShieldStock) { ShieldViewModel newShieldViewModel = new ShieldViewModel(shield, hero); newShieldViewModel.InitEquipView(); this.View.BuyShieldSP.Children.Add(newShieldViewModel.View); } foreach (Weapon weapon in GameViewModel.Instance.MainCastle.WeaponStock) { WeaponViewModel newWeaponViewModel = new WeaponViewModel(weapon, hero); newWeaponViewModel.InitEquipView(); this.View.BuyWeaponSP.Children.Add(newWeaponViewModel.View); } foreach (Potion potion in GameViewModel.Instance.MainCastle.PotionStock) { PotionViewModel newPotionViewModel = new PotionViewModel(potion, hero); newPotionViewModel.InitEquipView(); this.View.BuyPotionSP.Children.Add(newPotionViewModel.View); } }
public void RemoveHerbs(PotionViewModel potion) { var userName = User.Identity.Name; foreach (var herb in potion.Herbs) { if (new[] { "Common", "Uncommon", "Rare", "VeryRare" }.Contains(herb.HerbName)) { var ids = herbInfoRepository.GetHerbIdsByRarity((Rarity)Enum.Parse(typeof(Rarity), herb.HerbName, true)); List <int> finalIds = new List <int>(); foreach (var id in ids) { int count = herbCountRepository.GetHerb(id, userName).Count; finalIds.AddRange(Enumerable.Repeat(id, count)); } finalIds.Sort((a, b) => rand.Next(-1, 2)); finalIds = finalIds.Take(herb.Amount).ToList(); foreach (var id in finalIds) { herbCountRepository.RemoveHerbsById(id, 1, userName); } } else { herbCountRepository.RemoveHerbsByName(herb.HerbName, herb.Amount, userName); } } return; }
public bool IsCraftable(PotionViewModel potion, Dictionary <Rarity, int> herbsByRarity, string userName) { var herbInfos = context.HerbInfos.AsNoTracking().ToList(); var herbCounts = context.HerbCounts.AsNoTracking().ToList(); bool craftable = true; foreach (var herb in potion.Herbs) { if (new[] { "Common", "Uncommon", "Rare", "VeryRare" }.Contains(herb.HerbName)) { switch (herb.HerbName) { case "Common": if (herbsByRarity[Rarity.Common] < herb.Amount) { craftable = false; } break; case "Uncommon": if (herbsByRarity[Rarity.Uncommon] < herb.Amount) { craftable = false; } break; case "Rare": if (herbsByRarity[Rarity.Rare] < herb.Amount) { craftable = false; } break; case "VeryRare": if (herbsByRarity[Rarity.VeryRare] < herb.Amount) { craftable = false; } break; } } else { var herbInfo = herbInfos.Where(x => x.HerbName == herb.HerbName).FirstOrDefault(); var herbId = herbInfo.Id; var eHerbId = herbInfos.Where(x => x.Rarity == herbInfo.Rarity && x.Location == Location.Extra).FirstOrDefault().Id; var herbCount = herbCounts.Where(x => x.HerbId == herbId && x.UserName == userName).FirstOrDefault().Count; var eHerbCount = herbCounts.Where(x => x.HerbId == eHerbId && x.UserName == userName).FirstOrDefault().Count; if (herbCount + eHerbCount < herb.Amount) { craftable = false; break; } } } return(craftable); }
private void PotionStockGenerator() { foreach (Potion potion in this.HealerHouse.PotionList) { PotionViewModel newPVM = new PotionViewModel(potion); newPVM.IniBuyView(); this.View.ItemsSP.Children.Add(newPVM.View); } }
internal Response(PotionViewModel potion) { Potion = potion; }