Beispiel #1
0
        //A method to start a TradeRequest, called when a user first clicks a "Request Trade" button
        public async Task <IActionResult> StartRequest(int id)
        {
            //Creates a ViewModel so our data can persists when we switch to a new page
            TradeRequestViewModel model       = new TradeRequestViewModel();
            ApplicationUser       currentUser = await GetCurrentUserAsync();

            //Gets all the info of the Pokemon the user wishes to request
            model.DesiredPokemon = await _context.CaughtPokemon
                                   .Include(cp => cp.Pokemon)
                                   .Include(cp => cp.Gender)
                                   .Include(cp => cp.User)
                                   .Where(cp => cp.User.Id != currentUser.Id)
                                   .Where(cp => cp.isOwned == true)
                                   .Where(cp => cp.isHidden == false)
                                   .Where(cp => cp.isTradeOpen == true)
                                   .FirstOrDefaultAsync(cp => cp.Id == id);

            //If that Pokemon doesn't exist, return null
            if (model.DesiredPokemon == null)
            {
                return(NotFound());
            }

            //Sets the ID of this Pokemon to our ViewModel
            model.DesiredPokemonId = id;

            //Checks to see if the user owns a Pokemon of the same species as the desired Pokemon
            CaughtPokemon DesiredPokemonInUserCollection = await _context.CaughtPokemon
                                                           .Include(cp => cp.Pokemon)
                                                           .Include(cp => cp.Gender)
                                                           .Include(cp => cp.User)
                                                           .Where(cp => cp.User.Id == currentUser.Id)
                                                           .Where(cp => cp.isOwned == true)
                                                           .Where(cp => cp.isHidden == false)
                                                           .FirstOrDefaultAsync(cp => cp.PokemonId == model.DesiredPokemon.PokemonId);

            //If they do, we'll set a boolean to true, so that the Pokemon is highlighted as Caught
            if (DesiredPokemonInUserCollection != null)
            {
                model.isDesiredOwned = true;
            }

            //Fetches a list of all Pokemon the currently logged in user owns AND is marked for Trade. Users will be able to select a Pokemon to offer up in exchange for the Pokemon they're requesting
            model.TradeOpenPokemon = await _context.CaughtPokemon
                                     .Include(cp => cp.Pokemon)
                                     .Include(cp => cp.Gender)
                                     .Include(cp => cp.User)
                                     .Where(cp => cp.User.Id == currentUser.Id)
                                     .Where(cp => cp.isOwned == true)
                                     .Where(cp => cp.isHidden == false)
                                     .Where(cp => cp.isTradeOpen == true)
                                     .ToListAsync();

            //Sends our completed ViewModel to our View
            return(View(model));
        }
Beispiel #2
0
        public IActionResult ReleasePokemon(UserPokemonDetails model)
        {
            CaughtPokemon pokemon = _context.CaughtPokemon.Find(model.PokemonId);
            var           user    = _userContext.Users.Find(userManager.GetUserId(User));

            user.UniquePokemon = user.UniquePokemon - 1;
            _context.CaughtPokemon.Remove(pokemon);
            _userContext.SaveChanges();
            _context.SaveChanges();
            return(RedirectToAction("Pokemon", "Account"));
        }
Beispiel #3
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            if (Level != 0)
            {
                hash ^= Level.GetHashCode();
            }
            if (avatar_ != null)
            {
                hash ^= Avatar.GetHashCode();
            }
            if (TeamColor != 0)
            {
                hash ^= TeamColor.GetHashCode();
            }
            if (BattlesWon != 0)
            {
                hash ^= BattlesWon.GetHashCode();
            }
            if (KmWalked != 0F)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(KmWalked);
            }
            if (CaughtPokemon != 0)
            {
                hash ^= CaughtPokemon.GetHashCode();
            }
            if (GymBadgeType != 0)
            {
                hash ^= GymBadgeType.GetHashCode();
            }
            hash ^= badges_.GetHashCode();
            if (Experience != 0L)
            {
                hash ^= Experience.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Beispiel #4
0
        public async Task <IActionResult> CaughtPokemon(int id, bool isShiny, int areaId)
        {
            Pokemon model = await _context.Pokemon.FindAsync(id);

            CaughtPokemon caught = new CaughtPokemon
            {
                UserID      = _userManager.GetUserId(User),
                PokemonName = model.PokemonName,
                IsShiny     = isShiny,
                CatchDate   = DateTime.UtcNow,
            };

            PokePCUser user = await _userContext.Users.FindAsync(_userManager.GetUserId(User));

            ViewData["PrevExperience"] = user.Experience;
            var levelup = false;
            int areaExp = _context.Areas.Find(areaId).ExpPerCatch;
            // Calculate the experience that the player's next level requires
            double nextLvlExp = (user.Level * 1000) * (1.5);

            // Add the experience from catching the Pokémon
            user.Experience = user.Experience + areaExp;

            // Calculate the experience the user needs to level up // Ternary operator to account for if user experience is over the next level experience, which sets required exp to 0
            double expToLvl = nextLvlExp - user.Experience < 0 ? 0 : nextLvlExp - user.Experience;

            // If the user's experience exceeds the amount required for their next level, level them up by 1
            if (user.Experience >= nextLvlExp)
            {
                user.Level = user.Level + 1;
                levelup    = true;
            }
            user.UniquePokemon = user.UniquePokemon + 1;
            _userContext.SaveChanges();
            _context.Add(caught);
            _context.SaveChanges();
            ViewData["IsShiny"]       = isShiny;
            ViewData["NewExperience"] = user.Experience;
            ViewData["LevelUp"]       = levelup;
            ViewData["Level"]         = user.Level;
            ViewData["ExpGain"]       = areaExp;
            ViewData["ExpLeft"]       = expToLvl;
            return(PartialView("_CaughtPokemon", model));
        }
Beispiel #5
0
        public async Task <IActionResult> Register(Register obj)
        {
            if (ModelState.IsValid)
            {
                if (!roleManager.RoleExistsAsync("Standard").Result)
                {
                    PokePCRoles role = new PokePCRoles();
                    role.Name = "Standard";
                    IdentityResult roleResult = roleManager.CreateAsync(role).Result;
                }
                PokePCUser user = new PokePCUser();
                user.UserName      = obj.UserName;
                user.Email         = obj.Email;
                user.CreationDate  = DateTime.UtcNow;
                user.UniquePokemon = 1;
                user.Money         = 1000;
                user.Level         = 1;
                user.Experience    = 0;
                IdentityResult result = userManager.CreateAsync(user, obj.Password).Result;
                if (result.Succeeded)
                {
                    userManager.AddToRoleAsync(user, "Standard").Wait();

                    CaughtPokemon starter = new CaughtPokemon
                    {
                        UserID      = user.Id,
                        PokemonName = obj.Starter,
                        IsShiny     = false,
                        CatchDate   = DateTime.UtcNow,
                    };
                    _context.Add(starter);
                    _context.SaveChanges();
                    return(RedirectToAction("Login", "Account"));
                }
                else
                {
                    ModelState.AddModelError("", "Invalid user details");
                }
            }
            ViewData["Starters"] = await _context.Pokemon.Where(e => (e.PokedexNum == 1 || e.PokedexNum == 4 || e.PokedexNum == 7)).ToListAsync();

            return(View(obj));
        }
Beispiel #6
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            if (Level != 0)
            {
                hash ^= Level.GetHashCode();
            }
            if (avatar_ != null)
            {
                hash ^= Avatar.GetHashCode();
            }
            if (TeamColor != 0)
            {
                hash ^= TeamColor.GetHashCode();
            }
            if (BattlesWon != 0)
            {
                hash ^= BattlesWon.GetHashCode();
            }
            if (KmWalked != 0F)
            {
                hash ^= KmWalked.GetHashCode();
            }
            if (CaughtPokemon != 0)
            {
                hash ^= CaughtPokemon.GetHashCode();
            }
            if (GymBadgeType != 0)
            {
                hash ^= GymBadgeType.GetHashCode();
            }
            return(hash);
        }