Example #1
0
        public IActionResult PurchaseBackground(string backgroundSkinName)
        {
            bool result = false;

            BackgroundSkin backgroundSkin = _context.BackgroundSkins.FirstOrDefault(s => s.SkinName == backgroundSkinName);
            AsteroidUser   curUser        = GetCurrentUser();

            if (backgroundSkin != null &&
                curUser != null &&
                curUser.Coins >= backgroundSkin.SkinCost)
            {
                // Adjust users coins and add ship to database
                AdjustCoins(-backgroundSkin.SkinCost);

                OwnedBackground purchasedBackground = new OwnedBackground {
                    AsteroidUser = curUser, BackgroundSkinId = backgroundSkin.BackgroundSkinId
                };
                _context.OwnedBackgrounds.Add(purchasedBackground);
                _context.Users.Update(curUser);
                _context.SaveChanges();

                // Succeeded purchasing
                return(new JsonResult(new { success = result, background = backgroundSkin }));
            }
            else
            {
                return(BadRequest(new JsonResult(new
                                                 { success = false, message = "Not enough coins." })));
            }
        }
    private void Awake()
    {
        Instance = this;
        // levelCoefficient = Mathf.Min(0.02285714f * PrefsManager.LastLevel, .8f);
        offset         = 0.03f;
        dir            = -1;
        lvl            = GameManager.Instance.Data.GetLevelData(PrefsManager.LastLevel, ref levelCoefficient);
        currentSkin    = GameManager.Instance.CurrentSkin;
        backgroundSkin = GameManager.Instance.CurrentBackgroundSkin;


        spawner.transform.position  = new Vector2(0, currentSkin.SpawnerPosY);
        hitObject.position          = new Vector2(0, currentSkin.HitPosY);
        Camera.main.backgroundColor = currentSkin.BackgroundColor;

        if (backgroundSkin.BackgroundTexture != null)
        {
            backGroundImage.sprite = backgroundSkin.BackgroundTexture;
        }



        // state = State.PERFECT;
        ShootController.OnHit += HitDetect;
    }
Example #3
0
        public IActionResult SetCurrentBackground(string backgroundSkinName)
        {
            bool result = false;

            BackgroundSkin backgroundSkin = _context.BackgroundSkins.FirstOrDefault(s => s.SkinName == backgroundSkinName);
            AsteroidUser   curUser        = GetCurrentUser();

            // Check if skin and user are valid. Lastly, verify that user actually owns this skin
            if (backgroundSkin != null &&
                curUser != null &&
                curUser.OwnedBackgrounds.ToList().Exists(os => os.BackgroundSkinId == backgroundSkin.BackgroundSkinId))
            {
                // Update and save user's current background
                curUser.CurrentBackgrounId = backgroundSkin.BackgroundSkinId;
                _context.Users.Update(curUser);
                _context.SaveChanges();

                // Succeeded purchasing
                result = true;
            }

            return(new JsonResult(new { success = result, background = backgroundSkin }));
        }