public async Task <IActionResult> Create([FromBody] BossFightBossStats bossFightBossStats) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.BossFightBossStats.Add(bossFightBossStats); await _context.SaveChangesAsync(); return(CreatedAtAction("Get", new { settingsId = bossFightBossStats.Id, gameId = bossFightBossStats.GameId }, bossFightBossStats)); }
public async Task <IActionResult> Create([FromBody] BossFightBossStats bossFightBossStats) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.BossFightBossStats.Add(bossFightBossStats); await _context.SaveChangesAsync(); return(NoContent()); }
public async Task CreateSettings(int broadcasterId, int?gameId, string twitchBotApiLink) { BossFightSettings freshBossFightSettings = new BossFightSettings { Broadcaster = broadcasterId }; freshBossFightSettings = await ApiBotRequest.PostExecuteTaskAsync(twitchBotApiLink + $"bossfightsettings/create", freshBossFightSettings); BossFightClassStats bossFightClassStats = new BossFightClassStats { SettingsId = freshBossFightSettings.Id }; bossFightClassStats = await ApiBotRequest.PostExecuteTaskAsync(twitchBotApiLink + $"bossfightclassstats/create", bossFightClassStats); BossFightBossStats bossFightBossStats = new BossFightBossStats { SettingsId = freshBossFightSettings.Id }; bossFightBossStats = await ApiBotRequest.PostExecuteTaskAsync(twitchBotApiLink + $"bossfightbossstats/create", bossFightBossStats); await LoadSettings(broadcasterId, gameId, twitchBotApiLink, freshBossFightSettings); }
public async Task <IActionResult> Get([FromRoute] int settingsId, [FromQuery] int?gameId = null) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } BossFightBossStats bossFightBossStats = await _context.BossFightBossStats.SingleOrDefaultAsync(m => m.SettingsId == settingsId && m.GameId == gameId); if (bossFightBossStats == null) { // User hasn't set the boss stats for a particular game that is in the game list // Try to get their general settings as a fallback bossFightBossStats = await _context.BossFightBossStats.SingleOrDefaultAsync(m => m.SettingsId == settingsId && m.GameId == null); if (bossFightBossStats == null) { return(NotFound()); } } return(Ok(bossFightBossStats)); }
public async Task <IActionResult> Update([FromRoute] int settingsId, [FromQuery] int id, [FromBody] BossFightBossStats bossFightBossStats) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != bossFightBossStats.Id && settingsId != bossFightBossStats.SettingsId) { return(BadRequest()); } _context.Entry(bossFightBossStats).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BossFightBossStatsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
/// <summary> /// Load all of the settings from the database for the boss fight mini-game /// </summary> /// <param name="broadcasterId"></param> /// <param name="gameId"></param> /// <param name="twitchBotApiLink"></param> /// <param name="bossFightSettings"></param> public async Task LoadSettings(int broadcasterId, int?gameId, string twitchBotApiLink, BossFightSettings bossFightSettings = null) { if (bossFightSettings == null) { bossFightSettings = await ApiBotRequest.GetExecuteTaskAsync <BossFightSettings>(twitchBotApiLink + $"bossfightsettings/get/{broadcasterId}"); if (bossFightSettings == null) { return; // check if settings were loaded successfully, else attempt to create new settings } } SettingsId = bossFightSettings.Id; BossFightClassStats bossFightClassStats = await ApiBotRequest.GetExecuteTaskAsync <BossFightClassStats>(twitchBotApiLink + $"bossfightclassstats/get/{SettingsId}"); BossFightBossStats bossFightBossStats = await ApiBotRequest.GetExecuteTaskAsync <BossFightBossStats>(twitchBotApiLink + $"bossfightbossstats/get/{SettingsId}?gameId={gameId}"); // refresh arrays and lists NextLevelMessages = new string[4]; Bosses = new Boss[] { new Boss { }, new Boss { }, new Boss { }, new Boss { }, new Boss { } }; ClassStats = new FighterClass[] { new FighterClass { }, new FighterClass { }, new FighterClass { }, new FighterClass { }, new FighterClass { } }; Fighters = new BlockingCollection <BossFighter>(); // entry messages and initial settings CooldownTimePeriodMinutes = bossFightSettings.CooldownPeriodMin; EntryPeriodSeconds = bossFightSettings.EntryPeriodSec; EntryMessage = bossFightSettings.EntryMessage; Cost = bossFightSettings.Cost; CooldownEntry = bossFightSettings.CooldownEntry; CooldownOver = bossFightSettings.CooldownOver; // next level messages NextLevelMessages[0] = bossFightSettings.NextLevelMessage2; NextLevelMessages[1] = bossFightSettings.NextLevelMessage3; NextLevelMessages[2] = bossFightSettings.NextLevelMessage4; NextLevelMessages[3] = bossFightSettings.NextLevelMessage5; // game outcomes GameStart = bossFightSettings.GameStart; ResultsMessage = bossFightSettings.ResultsMessage; SingleUserSuccess = bossFightSettings.SingleUserSuccess; SingleUserFail = bossFightSettings.SingleUserFail; Success100 = bossFightSettings.Success100; Success34 = bossFightSettings.Success34; Success1 = bossFightSettings.Success1; Success0 = bossFightSettings.Success0; // fighter class stats ClassStats[0].ChatterType = ChatterType.Viewer; ClassStats[0].Attack = bossFightClassStats.ViewerAttack; ClassStats[0].Defense = bossFightClassStats.ViewerDefense; ClassStats[0].Evasion = bossFightClassStats.ViewerEvasion; ClassStats[0].Health = bossFightClassStats.ViewerHealth; ClassStats[1].ChatterType = ChatterType.Follower; ClassStats[1].Attack = bossFightClassStats.FollowerAttack; ClassStats[1].Defense = bossFightClassStats.FollowerDefense; ClassStats[1].Evasion = bossFightClassStats.FollowerEvasion; ClassStats[1].Health = bossFightClassStats.FollowerHealth; ClassStats[2].ChatterType = ChatterType.RegularFollower; ClassStats[2].Attack = bossFightClassStats.RegularAttack; ClassStats[2].Defense = bossFightClassStats.RegularDefense; ClassStats[2].Evasion = bossFightClassStats.RegularEvasion; ClassStats[2].Health = bossFightClassStats.RegularHealth; ClassStats[3].ChatterType = ChatterType.Moderator; ClassStats[3].Attack = bossFightClassStats.ModeratorAttack; ClassStats[3].Defense = bossFightClassStats.ModeratorDefense; ClassStats[3].Evasion = bossFightClassStats.ModeratorEvasion; ClassStats[3].Health = bossFightClassStats.ModeratorHealth; ClassStats[4].ChatterType = ChatterType.Subscriber; ClassStats[4].Attack = bossFightClassStats.SubscriberAttack; ClassStats[4].Defense = bossFightClassStats.SubscriberDefense; ClassStats[4].Evasion = bossFightClassStats.SubscriberEvasion; ClassStats[4].Health = bossFightClassStats.SubscriberHealth; // boss stats Bosses[0].Name = bossFightBossStats.Name1; Bosses[0].MaxUsers = bossFightBossStats.MaxUsers1; Bosses[0].Attack = bossFightBossStats.Attack1; Bosses[0].Defense = bossFightBossStats.Defense1; Bosses[0].Evasion = bossFightBossStats.Evasion1; Bosses[0].Health = bossFightBossStats.Health1; Bosses[0].TurnLimit = bossFightBossStats.TurnLimit1; Bosses[0].Loot = bossFightBossStats.Loot1; Bosses[0].LastAttackBonus = bossFightBossStats.LastAttackBonus1; Bosses[1].Name = bossFightBossStats.Name2; Bosses[1].MaxUsers = bossFightBossStats.MaxUsers2; Bosses[1].Attack = bossFightBossStats.Attack2; Bosses[1].Defense = bossFightBossStats.Defense2; Bosses[1].Evasion = bossFightBossStats.Evasion2; Bosses[1].Health = bossFightBossStats.Health2; Bosses[1].TurnLimit = bossFightBossStats.TurnLimit2; Bosses[1].Loot = bossFightBossStats.Loot2; Bosses[1].LastAttackBonus = bossFightBossStats.LastAttackBonus2; Bosses[2].Name = bossFightBossStats.Name3; Bosses[2].MaxUsers = bossFightBossStats.MaxUsers3; Bosses[2].Attack = bossFightBossStats.Attack3; Bosses[2].Defense = bossFightBossStats.Defense3; Bosses[2].Evasion = bossFightBossStats.Evasion3; Bosses[2].Health = bossFightBossStats.Health3; Bosses[2].TurnLimit = bossFightBossStats.TurnLimit3; Bosses[2].Loot = bossFightBossStats.Loot3; Bosses[2].LastAttackBonus = bossFightBossStats.LastAttackBonus3; Bosses[3].Name = bossFightBossStats.Name4; Bosses[3].MaxUsers = bossFightBossStats.MaxUsers4; Bosses[3].Attack = bossFightBossStats.Attack4; Bosses[3].Defense = bossFightBossStats.Defense4; Bosses[3].Evasion = bossFightBossStats.Evasion4; Bosses[3].Health = bossFightBossStats.Health4; Bosses[3].TurnLimit = bossFightBossStats.TurnLimit4; Bosses[3].Loot = bossFightBossStats.Loot4; Bosses[3].LastAttackBonus = bossFightBossStats.LastAttackBonus4; Bosses[4].Name = bossFightBossStats.Name5; Bosses[4].MaxUsers = bossFightBossStats.MaxUsers5; Bosses[4].Attack = bossFightBossStats.Attack5; Bosses[4].Defense = bossFightBossStats.Defense5; Bosses[4].Evasion = bossFightBossStats.Evasion5; Bosses[4].Health = bossFightBossStats.Health5; Bosses[4].TurnLimit = bossFightBossStats.TurnLimit5; Bosses[4].Loot = bossFightBossStats.Loot5; Bosses[4].LastAttackBonus = bossFightBossStats.LastAttackBonus5; }