public async Task OnPostToggle(int id, bool inCombat) { var newCombatStatus = !inCombat; (await _context.Rooms.FindAsync(id)).InCombat = newCombatStatus; var characters = _context.Characters.Where(c => c.RoomId == id); if (!newCombatStatus) { await characters.ForEachAsync(c => { c.Initiative = 0; c.TurnNumber = 0; }); } else { await characters.ForEachAsync(c => c.Initiative = DiceRoller.RollD20(c.Dex)); } await _context.SaveChangesAsync(); }
private void btnRollDice_Click(object sender, EventArgs e) { List <int> diceList = new List <int>(); int sum = 0; int grandTotal = 0; string showWork = string.Empty; string lineBreaker = Environment.NewLine + "------------------------------------------------------------------------------------------------------" + Environment.NewLine; diceList = DiceRoller.RollD2((uint)nudNumD2.Value, out sum); showWork += "D2: "; foreach (int diceRoll in diceList) { showWork += diceRoll.ToString() + ", "; } showWork = showWork.Remove(showWork.Length - 2, 2); showWork += " : Total: " + sum.ToString() + lineBreaker; grandTotal += sum; diceList = DiceRoller.RollD3((uint)nudNumD3.Value, out sum); showWork += "D3: "; foreach (int diceRoll in diceList) { showWork += diceRoll.ToString() + ", "; } showWork = showWork.Remove(showWork.Length - 2, 2); showWork += " : Total: " + sum.ToString() + lineBreaker; grandTotal += sum; diceList = DiceRoller.RollD4((uint)nudNumD4.Value, out sum); showWork += "D4: "; foreach (int diceRoll in diceList) { showWork += diceRoll.ToString() + ", "; } showWork = showWork.Remove(showWork.Length - 2, 2); showWork += " : Total: " + sum.ToString() + lineBreaker; grandTotal += sum; diceList = DiceRoller.RollD6((uint)nudNumD6.Value, out sum); showWork += "D6: "; foreach (int diceRoll in diceList) { showWork += diceRoll.ToString() + ", "; } showWork = showWork.Remove(showWork.Length - 2, 2); showWork += " : Total: " + sum.ToString() + lineBreaker; grandTotal += sum; diceList = DiceRoller.RollD8((uint)nudNumD8.Value, out sum); showWork += "D8: "; foreach (int diceRoll in diceList) { showWork += diceRoll.ToString() + ", "; } showWork = showWork.Remove(showWork.Length - 2, 2); showWork += " : Total: " + sum.ToString() + lineBreaker; grandTotal += sum; diceList = DiceRoller.RollD10((uint)nudNumD10.Value, out sum); showWork += "D10: "; foreach (int diceRoll in diceList) { showWork += diceRoll.ToString() + ", "; } showWork = showWork.Remove(showWork.Length - 2, 2); showWork += " : Total: " + sum.ToString() + lineBreaker; grandTotal += sum; diceList = DiceRoller.RollD12((uint)nudNumD12.Value, out sum); showWork += "D12: "; foreach (int diceRoll in diceList) { showWork += diceRoll.ToString() + ", "; } showWork = showWork.Remove(showWork.Length - 2, 2); showWork += " : Total: " + sum.ToString() + lineBreaker; grandTotal += sum; diceList = DiceRoller.RollD20((uint)nudNumD20.Value, out sum); showWork += "D20: "; foreach (int diceRoll in diceList) { showWork += diceRoll.ToString() + ", "; } showWork = showWork.Remove(showWork.Length - 2, 2); showWork += " : Total: " + sum.ToString() + lineBreaker; grandTotal += sum; diceList = DiceRoller.RollD100((uint)nudNumD100.Value, out sum); showWork += "D100: "; foreach (int diceRoll in diceList) { showWork += diceRoll.ToString() + ", "; } showWork = showWork.Remove(showWork.Length - 2, 2); showWork += " : Total: " + sum.ToString() + lineBreaker; grandTotal += sum; showWork += "Grand Total: " + grandTotal.ToString(); tbDiceBox.Text = showWork; }