async public static Task <HttpStatusCodeResult> CreateGladiator(GladiatorBindingModel model, string userId) { Gladiator gladiator = new Gladiator(model, userId); gladiator.Score = new GladiatorScore { Gladiator = gladiator }; //Count how many gladiators are still alive List <Gladiator> gladiators = await GetCurrentGladiators(userId); int amountOfGladiators = gladiators.Where(gtor => gtor.Health > 0).Count(); if (amountOfGladiators < 3 || gladiator.IsNPC) { db.Gladiators.Add(gladiator); await db.SaveChangesAsync(); return(new HttpStatusCodeResult(200, "Successfully created a new Gladiator.")); } else { return(new HttpStatusCodeResult(400, "Too many gladiators still alive.")); } }
async public static Task <HttpStatusCodeResult> EditGladiator(GladiatorBindingModel model, string userId, bool isAdmin) { Gladiator gladiator = await GetGladiator(model.Id); if (gladiator == null) { return(new HttpStatusCodeResult(404, "No gladiator found.")); } if (gladiator.Owner.Id != userId && !isAdmin) { return(new HttpStatusCodeResult(401, "Tried to edit another players gladiator.")); } gladiator.Update(model); db.Entry(gladiator).State = EntityState.Modified; await db.SaveChangesAsync(); return(new HttpStatusCodeResult(200, "Successfully Edited Gladiator.")); }
public static void ExecuteTurn(Match match) { Gladiator attacker = match.NextAttacker; //Reciever is the one that isn't the attacker Gladiator reciever = match.NextAttacker.Id == match.Gladiator.Id ? match.Opponent : match.Gladiator; (int damage, int roll) = CalculateDamage(attacker); reciever.TakeDamage(damage); bool recieverDied = reciever.Health < 1; //Check if reciever died if (recieverDied) { match.Winner = attacker; int exp = (1 + reciever.Level - attacker.Level) * 500; exp = exp < 0 ? 0 : exp; attacker.GainExp(exp); //Restore NPCs to full health on match end if (reciever.IsNPC) { //Reset levels on defeat (reciever as Opponent).Reset(); } else if (attacker.IsNPC) { attacker.Health = attacker.MaxHealth; } //Award score if (!reciever.IsNPC) { reciever.Owner.GainExp(50); reciever.Owner.Score.Add(50); } if (!attacker.IsNPC) { attacker.Owner.GainExp(100); attacker.Owner.Score.Add(100); } } match.ExecuteTurn(damage, roll, recieverDied); }
private static (int damage, int roll) CalculateDamage(Gladiator attacker) { //6 sided die int roll = 1 + RNG.Next(6); float damageMultiplier = 1; //Last stand bonus if (attacker.Health / attacker.MaxHealth < 0.1) { damageMultiplier += 0.5f; } if (attacker.IsNPC) { damageMultiplier -= 0.25f; } int damage = (int)((roll + attacker.Level) * damageMultiplier); return(damage, roll); }
public static void AttemptYield(Match match) { Gladiator attacker = match.NextAttacker; Gladiator reciever = match.NextAttacker.Id == match.Gladiator.Id ? match.Opponent : match.Gladiator; int roll = RNG.Next(100); bool success = roll < 50; if (success) { match.Winner = reciever; int exp = (1 + reciever.Level - attacker.Level) * 250; reciever.GainExp(exp); if (reciever.IsNPC) { reciever.Health = reciever.MaxHealth; } else { reciever.Owner.GainExp(25); reciever.Owner.Score.Add(25); } } match.ExecuteTurn(success, roll); }