Пример #1
0
        public async Task ExtendBonus(string bonusName)
        {
            ShopBonus shopBonus = await this.GetShopBonus(bonusName);

            if (shopBonus == null || shopBonus.CrystalsPrice <= 0)
            {
                throw new FarmHeroesException(
                          "Such option doesn't exist",
                          "You probably tried to extend a non-existing bonus.",
                          "/Hero");
            }

            Hero hero = await this.heroService.GetHero();

            HeroBonus heroBonus = hero.Inventory.Bonuses.SingleOrDefault(b => b.Name == shopBonus.Name);

            if (heroBonus == null)
            {
                hero.Inventory.Bonuses.Add(this.GenerateHeroBonus(shopBonus));
            }
            else
            {
                heroBonus.ActiveUntil = shopBonus.IsPermanent ? DateTime.MaxValue
                    : heroBonus.ActiveUntil < DateTime.UtcNow ? DateTime.UtcNow.AddDays(shopBonus.Days)
                    : heroBonus.ActiveUntil.AddDays(shopBonus.Days);
            }

            await this.resourcePouchService.DecreaseResource(ResourceNames.Crystals, shopBonus.CrystalsPrice);

            await this.context.SaveChangesAsync();

            this.tempDataDictionaryFactory
            .GetTempData(this.httpContext.HttpContext)
            .Add("Alert", $"You extended your rent on {shopBonus.Name}.");
        }
Пример #2
0
 public void Init(ShopBonus sb)
 {
     _shopObject            = sb;
     ItemName.text          = sb.BonusName;
     ItemCost.text          = sb.BonusCost + "";
     ItemPreview.sprite     = sb.BonusImg;
     ByeButton.interactable = Player.Instance.Money >= sb.BonusCost;
     InfoButton.onClick.AddListener(ShowInfo);
     ByeButton.onClick.AddListener(Buy);
 }
Пример #3
0
 private HeroBonus GenerateHeroBonus(ShopBonus shopBonus)
 {
     return(new HeroBonus
     {
         Name = shopBonus.Name,
         ImageUrl = shopBonus.ImageUrl,
         Description = shopBonus.Description,
         Bonus = shopBonus.InitialBonus,
         Type = shopBonus.Type,
         ActiveUntil = shopBonus.IsPermanent ? DateTime.MaxValue : DateTime.UtcNow.AddDays(shopBonus.Days),
     });
 }
Пример #4
0
        public async Task SeedAsync(FarmHeroesDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (dbContext.ShopBonuses.Any())
            {
                return;
            }

            ShopBonus[] bonuses = new ShopBonus[]
            {
                new ShopBonus()
                {
                    Name = "Gold Safe", Description = "In case of a loss, the enemy will only steal half of what he would do usually.", InitialBonus = 0.5, CrystalsPrice = 250, ImageUrl = "/images/village/hut/gold-safe.jpg", AttainableFrom = "Hut", Days = 14, IsPermanent = false, Type = BonusType.Other
                },
                new ShopBonus()
                {
                    Name = "Gold Totem", Description = "Increases your characteristics by 30% during fights.", InitialBonus = 0.3, CrystalsPrice = 350, ImageUrl = "/images/village/hut/gold-totem.jpg", AttainableFrom = "Hut", Days = 14, IsPermanent = false, Type = BonusType.Characteristics
                },
            };

            await dbContext.ShopBonuses.AddRangeAsync(bonuses);
        }
Пример #5
0
    public void Buy(object shopObject)
    {
        switch (shopObject.GetType().ToString())
        {
        case "ModuleHolder":
            ModuleHolder moduleHolder = (ModuleHolder)shopObject;
            Player.Instance.Money -= moduleHolder.Cost;
            if (moduleHolder.moduleType == ModuleHolder.ModuleType.Simple)
            {
                Player.Instance.Modules.Add(new SimpleModule(moduleHolder));
            }
            else
            {
                Player.Instance.Modules.Add(new ComplexModule(moduleHolder));
            }
            break;

        case "SnakeSkin":
            SnakeSkin snakeSkin = (SnakeSkin)shopObject;
            Player.Instance.Money -= snakeSkin.SkinCost;
            Player.Instance.AddSkin(snakeSkin);
            break;

        case "LogicElement":
            LogicElement logicElement = (LogicElement)shopObject;
            Player.Instance.Money -= logicElement.ElementCost;
            Player.Instance.AddElements(logicElement, 1);
            break;

        case "ShopBonus":
            ShopBonus bonus = (ShopBonus)shopObject;
            Player.Instance.Money -= bonus.BonusCost;
            Player.Instance.AddBonus(bonus);
            break;
        }
    }
Пример #6
0
 public void AddBonus(ShopBonus bonus)
 {
 }
Пример #7
0
        private async Task <ShopBonus> GetShopBonus(string bonusName)
        {
            ShopBonus shopBonus = await this.context.ShopBonuses.SingleOrDefaultAsync(b => b.Name == bonusName);

            return(shopBonus);
        }