/// <summary> /// Add experience and calcul the characteristics of the user. /// </summary> /// <param name="beerUser"></param> /// <param name="weapon"></param> /// <param name="experience"></param> /// <returns></returns> public static BeerUser AddExperience(BeerUser beerUser, Weapon weapon) { if (beerUser.Level < 10) { beerUser.Experience += beerUser.Level; } else if (beerUser.Level >= 10 && beerUser.Level < 50) { beerUser.Experience += beerUser.Level / 10; } else if (beerUser.Level >= 50) { beerUser.Experience = 0; } if (beerUser.Experience >= beerUser.MaxExperience && beerUser.Level < 50) { beerUser.Level++; beerUser.Experience = 0; } beerUser = CharacteristicsCalculation(beerUser, weapon); return(beerUser); }
//BeerUsers public void CreateBeerUser(string clientId, GamerType gamerType, string pseudonym) { if (GetGamerTypeById(gamerType.Id) == null) { throw new BeerException("The gamer type doesn't exist."); } if (GetBeerUserByPseudonym(pseudonym) != null) { throw new BeerException("The pseudonym " + pseudonym + " is not avaible."); } var beerUser = new BeerUser(); beerUser.ClientId = clientId; beerUser.GamerType = gamerType; beerUser.Pseudonym = pseudonym; beerUser.Level = 1; beerUser.Experience = 0; beerUser.Money = 10; beerUser.Attack = gamerType.Attack; beerUser.Defense = gamerType.Defense; beerUser.Life = gamerType.Defense; _context.BeerUsers.Add(beerUser); if (_context.SaveChanges() == 0) { throw new BeerException("An error occured when creating BeerUser."); } }
/// <summary> /// Return false if beerUser lose or true if he win. /// </summary> /// <param name="beerUser"></param> /// <param name="beerUserEnemy"></param> /// <returns></returns> public static bool Fight(BeerUser beerUser, BeerUser beerUserEnemy) { bool result = false; bool turn = true; // True == beerUser && False == beerUserEnemy int beerUserLife = beerUser.Life; int beerUserEnemyLife = beerUserEnemy.Life; do { if (randomBool()) { if (turn) { beerUserEnemyLife -= beerUser.Attack - (int)(beerUserEnemy.Defense * 0.8); } else { beerUserLife -= beerUserEnemy.Attack - (int)(beerUser.Defense * 0.8); } } turn = !turn; } while (beerUserLife > 0 && beerUserEnemyLife > 0); if (beerUserLife <= 0) // beerUser lost { result = false; } else { result = true; } return(result); }
public async Task <Guid?> CreateUser(String username, String password, String displayName, String profilePictureUrl) { Guid userId = Guid.NewGuid(); var user = new BeerUser { UserName = username, Id = userId.ToString() }; //DisplayName = displayName, ProfilePictureUrl = profilePictureUrl }; var result = await _userManager.CreateAsync(user, password); if (result.Succeeded == true) { await _userManager.AddClaimsAsync(user, new Claim[] { new Claim(CustomClaimTypes.DisplayClaimsType, displayName), new Claim(CustomClaimTypes.ProfilePictureUrl, profilePictureUrl), });; return(userId); } else { return(null); } }
public void DeleteBeerUser(BeerUser beerUser) { _context.BeerUsers.Remove(beerUser); if (_context.SaveChanges() == 0) { throw new BeerException("An error occured when deleting BeerUser."); } }
public List <Weapon> GetUserWeaponsAsListOfWeapon(BeerUser beerUser) { List <Weapon> weapons = new List <Weapon>(); foreach (UserWeapon uW in GetUserWeapons(beerUser)) { weapons.Add(uW.Weapon); } return(weapons); }
public BeerUser UpdateBeerUser(BeerUser beerUser) { var user = _context.BeerUsers.FirstOrDefault(u => u.Id == beerUser.Id); user = beerUser; if (_context.SaveChanges() < 0) { throw new BeerException("An error occured when updating BeerUser."); } else { return(beerUser); } }
public UserWeapon GetUserWeaponInUse(BeerUser beerUser) { var userWeapon = _context.GetUserWeaponInUse(beerUser); if (userWeapon == null) { _context.GetWeaponByAttackMore(beerUser.GamerType.WeaponType, 2); return(_context.GetUserWeaponInUse(beerUser)); } else { return(userWeapon); } }
public void SailWeapon(BeerUser beerUser, int userWeaponId) { var userWeapon = GetUserWeaponById(userWeaponId); beerUser.Money += (userWeapon.Weapon.Cost / 2); UpdateBeerUserInformations(beerUser); if (userWeapon == null) { throw new BeerException("Weapon not found !"); } if (userWeapon.InUse == true) { throw new BeerException("You can't sail a weapon that is in use !"); } DeleteUserWeapon(userWeapon); }
public List <UserWeapon> GetUserWeapons(BeerUser beerUser) { var userWeapons = _context.GetUserWeapons(beerUser); if (userWeapons == null || userWeapons.Count == 0) { var weapon = _context.GetWeaponByAttackMore(beerUser.GamerType.WeaponType, 2); UserWeapon userWeapon = new UserWeapon(beerUser, weapon, true); AddUserWeapon(userWeapon); return(_context.GetUserWeapons(beerUser)); } else { return(userWeapons); } }
public void BuyWeapon(BeerUser beerUser, int weaponId) { var weapon = GetWeaponById(weaponId); if (beerUser.Money < weapon.Cost) { throw new BeerException("You doesn't have enought money !"); } if (weapon == null) { throw new BeerException("Weapon not found !"); } AddUserWeapon(new UserWeapon(beerUser, weapon, false)); beerUser.Money -= weapon.Cost; UpdateBeerUserInformations(beerUser); }
/// <summary> /// Calcul of Attack, Defense, Life and MaxExperience of a user. /// </summary> /// <param name="beerUser"></param> /// <param name="weapon"></param> /// <returns></returns> public static BeerUser CharacteristicsCalculation(BeerUser beerUser, Weapon weapon) { beerUser.Attack = (int)(beerUser.GamerType.Attack + (beerUser.GamerType.Attack / 11) + weapon.AttackMore + ((beerUser.GamerType.Attack + (beerUser.Level * 3.5)) * 1.3)); beerUser.Defense = (int)(beerUser.GamerType.Defense + (beerUser.GamerType.Defense / 9.60) + ((beerUser.GamerType.Defense + (beerUser.Level * 3.5)) * 1.3)); beerUser.Life = (int)(beerUser.GamerType.Life + (beerUser.GamerType.Life / 10) + ((beerUser.GamerType.Life + (beerUser.Level * 3.5)) * 1.3)); if (beerUser.Level >= 50) { beerUser.MaxExperience = 0; } else { beerUser.MaxExperience = (int)(beerUser.Level * 10.6); } return(beerUser); }
public void UpdateBeerUserCharacteristics(BeerUser beerUser, Weapon weapon) { BeerCalculationService.CharacteristicsCalculation(beerUser, weapon); _context.UpdateBeerUser(beerUser); }
public void UpdateBeerUserInformations(BeerUser beerUser) { _context.UpdateBeerUser(beerUser); }
public BeerUser UpdateBeerUserAddExperienceAndMoney(BeerUser beerUser, Weapon weapon) { BeerCalculationService.AddExperience(beerUser, weapon); beerUser.Money += 10; return(_context.UpdateBeerUser(beerUser)); }
public UserWeapon GetUserWeaponInUse(BeerUser beerUser) { return(_context.UserWeapons.Include(w => w.Weapon).FirstOrDefault(w => w.User.Id == beerUser.Id && w.InUse == true)); }
public List <UserWeapon> GetUserWeapons(BeerUser beerUser) { return(_context.UserWeapons.Where(w => w.User.Id == beerUser.Id).OrderBy(w => w.Weapon.MinimumLevel).ToList()); }
public List <BeerUser> RemoveBeerUserFromBeerUsersList(BeerUser beerUser, List <BeerUser> beerUsers) { beerUsers.RemoveAll(u => u.Id == beerUser.Id); return(beerUsers); }