public async Task <ActionResult> LevelUp() { //Increment player level var cUser = await userManager.GetUserAsync(User); var cChar = db.Characters.First(x => x.UserId == cUser.Id); while (cChar.Experience >= experienceToLevel) { cChar.Rank += 1; cChar.Strength += 1; cChar.Dexterity += 1; cChar.Intelligence += 1; cChar.MaxHealth += 10; var hp = ((cChar.MaxHealth - cChar.CurrentHealth) > 30) ? cChar.CurrentHealth + 30 : cChar.MaxHealth; cChar.CurrentHealth = hp; cChar.Experience -= experienceToLevel; db.SaveChanges(); AddToAction("You gained a level! You are now level " + cChar.Rank, txtSuccess); AddToAction("You have been healed by 30 points, gained a point to all skills and hp points", txtSuccess); } return(RedirectToAction("Play", "Game")); }
public async Task <IActionResult> DeleteCharacter() { var optionsBuilder = new DbContextOptionsBuilder <AmarathContext>(); var db = new AmarathContext(optionsBuilder.Options); var cUser = await userManager.GetUserAsync(User); var cChar = db.Characters.First(x => x.UserId == cUser.Id); var inventories = from i in db.Inventories select i; foreach (Inventory inv in inventories) { if (inv.CharID == cChar.CharId) { db.Inventories.Remove(inv); } } //Absolutly brutal db.Characters.Remove(cChar); db.SaveChanges(); HttpContext.Session.Remove("Dialog"); HttpContext.Session.Remove("Action"); HttpContext.Session.Remove("Choices"); return(RedirectToAction("Death", "Game")); }
public async Task <ActionResult> CreateCharacterAsync(CharacterViewModel viewModel) { if (ModelState.IsValid) { var optionsBuilder = new DbContextOptionsBuilder <AmarathContext>(); var db = new AmarathContext(optionsBuilder.Options); var cUser = await userManager.GetUserAsync(User); var character = new Character { UserId = cUser.Id, ClassTypeId = viewModel.ClassTypeId, Name = viewModel.Name, Rank = 1, Strength = viewModel.Strength, Intelligence = viewModel.Intelligence, Dexterity = viewModel.Dexterity, CurrentHealth = 100, MaxHealth = 100, Experience = 0, DungeonLevel = 0, TotalAttack = 0, TotalDefense = 0, TotalDexterity = viewModel.Dexterity, TotalStrength = viewModel.Strength, TotalIntelligence = viewModel.Intelligence }; db.Characters.Add(character); db.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(View(viewModel)); }