public string Roll() { int randomNumber = NumberGen.gen(1, 13); switch (randomNumber) { case 1: return($"You were turned into a toad and remained in that form for {DiceRoll.roll(1, 4)} weeks."); case 2: return("You were petrified and remained a stone statue for a time until someone freed you."); case 3: return($"You were enslaved by a hag, a satyr, or some other being and lived in that creature’s thrall for {DiceRoll.roll(1, 6)} years."); case 4: return($"A dragon held you as a prisoner for {DiceRoll.roll(1, 4)} months until adventurers killed it."); case 5: return("You were taken captive by a race of evil humanoids such as drow, kuo-toa, or quaggoths. You lived as a slave in the Underdark until you escaped."); case 6: return("You served a powerful adventurer as a hireling. You have only recently left that service. Use the supplemental tables and work with your DM to determine the basic details about your former employer." + $"\n{Individual.generateIndividual().getString()}"); case 7: return($"You went insane for {DiceRoll.roll(1, 6)} years and recently regained your sanity. A tic or some other bit of odd behavior might linger."); case 8: return("A lover of yours was secretly a silver dragon."); case 9: return("You were captured by a cult and nearly sacrificed on an altar to the foul being the cultists served. You escaped, but you fear they will find you."); case 10: return("You met a demigod, an archdevil, an archfey, a demon lord, or a titan, and you lived to tell the tale."); case 11: return("You were swallowed by a giant fish and spent a month in its gullet before you escaped."); case 12: return("A powerful being granted you a wish, but you squandered it on something frivolous."); default: return(""); } }
public virtual void PrepareRoll(DiceRoll diceRoll) { diceRoll.RollScope = RollScope; diceRoll.DiceDtos = DiceDtos; diceRoll.HiddenThreshold = HiddenThreshold; diceRoll.IsMagic = IsMagic; }
public string GetValue() { var partsSum = new DiceRoll(); var conditionSum = new DiceRoll(); foreach (var diceRoll in Parts) { partsSum += diceRoll.Value; conditionSum += diceRoll.Value; } var partStr = partsSum.ToString(); partStr = string.IsNullOrWhiteSpace(partStr) ? "0" : partStr; if (!Circumstances.Any()) { return(string.Format("{0}", partStr)); } foreach (var diceRoll in Circumstances) { conditionSum += diceRoll.Value; } var conditionSumStr = conditionSum.ToString(); conditionSumStr = string.IsNullOrWhiteSpace(conditionSumStr) ? "0" : conditionSumStr; return(string.Format("{0} ({1})", partStr, conditionSumStr)); }
private void AddIfNotZero(string name, DiceRoll value) { if (value.GetFixedAmount() != 0 || (value.Dice != null && value.Dice.Any())) { Parts.Add(new KeyValuePair <string, DiceRoll>(name, value)); } }
private void ChangeCritsToHits(DiceRoll diceroll) { if (Combat.ChosenWeapon is UpgradesList.FirstEdition.HeavyLaserCannon) { diceroll.ChangeAll(DieSide.Crit, DieSide.Success); } }
public override void ConditionRoll(DiceRoll diceRoll) { if (diceRoll.RollID == stampedeDieRollGuid) { remindDungeonMasterTimer.Stop(); } }
private static DiceRoll GetNewViewerRoll() { DiceRoll diceRoll = viewerRollQueue.Dequeue(); UpdateInGameViewerRollQueue(); return(diceRoll); }
public DieRoll GetDominantDie(DiceRoll diceRoll) { var groupped = diceRoll.AllDice.ToIntArray().GroupBy(x => x); var ordered = groupped.OrderByDescending(x => x.Count()); return((DieRoll)ordered.First().First()); }
void AssertRoll(string spellName, Character player, int spellSlotLevel, DiceRollType expectedDiceRollType, string expectedDice) { DiceRoll roll = DiceRollHelper.GetSpellFrom(spellName, player, spellSlotLevel); Assert.AreEqual(expectedDiceRollType, roll.Type); Assert.AreEqual(expectedDice, roll.DamageHealthExtraDice); }
private void RegisterAbility(DiceRoll diceroll) { if (Combat.AttackStep == CombatStep.Attack && Combat.Attacker == HostShip) { RegisterAbilityTrigger(TriggerTypes.OnImmediatelyAfterRolling, Ability); } }
public static void CompareDiceSidesAgainstServer(DieSide[] dieSides) { if (!IsServer) { DiceRoll clientDiceRoll = DiceRoll.CurrentDiceRoll; bool syncIsNeeded = false; for (int i = 0; i < clientDiceRoll.DiceList.Count; i++) { if (clientDiceRoll.DiceList[i].GetModelFace() != dieSides[i]) { syncIsNeeded = true; clientDiceRoll.DiceList[i].SetSide(dieSides[i]); clientDiceRoll.DiceList[i].SetModelSide(dieSides[i]); } } if (syncIsNeeded) { clientDiceRoll.OrganizeDicePositions(); Messages.ShowInfo("Dice results are synchronized with server"); } /*else * { * Messages.ShowInfo("NO PROBLEMS"); * }*/ } Network.FinishTask(); }
static void Main(string[] args) { //Fighter 1 (from 5e pregens ) Vs bugbear DiceRoll a = DiceRoll.CustomOperation(( rolls) => { if (rolls[0] == 20) { return(rolls[1] + rolls[2] + 3); } if (rolls[0] + 3 >= 16) { return(rolls[1] + 3); } else { return(0); } }, DiceRoll.d20(), DiceRoll.d12(), DiceRoll.d12()); Graph g = new Graph("Figure 2", "Damage Dealt against a Bugbear by a typical level 1 fighter (5e)", false); g.AddRolls(a, "", Colours.Blue, true); g.export("damage.svg"); a.rolls.Remove(0); g = new Graph("Figure 3", "Damage Dealt against a Bugbear by a typical level 1 fighter (5e) (miss removed)", false); g.AddRolls(a, ""); g.export("damage2.svg"); }
private static void PrepareForSavingThrow(DiceRoll diceRoll, int dieOwnerId, string rollData, ref string dieBackColorOverride, ref string dieTextColorOverride, ref double modifier, ref string diePlayerName, ref double scaleOverride, ref int dieOwnerOverride) { Ability savingThrowAbility = DndUtils.ToAbility(rollData); if (savingThrowAbility == Ability.none) { return; } // We have a saving throw! Creature targetCreature = DndUtils.GetCreatureById(dieOwnerId); if (targetCreature == null) { return; } dieOwnerOverride = dieOwnerId; diePlayerName = targetCreature.Name; if (scaleOverride > 1) { scaleOverride = 1; // Player dice are always thrown at no more than 100% scale. } modifier = targetCreature.GetSavingThrowModifier(savingThrowAbility); dieBackColorOverride = GetDieBackColor(targetCreature); dieTextColorOverride = GetDieTextColor(targetCreature, dieBackColorOverride); diceRoll.SavingThrow = savingThrowAbility; diceRoll.Type = DiceRollType.DamagePlusSavingThrow; diceRoll.HiddenThreshold = INT_ViewerSpellCasterDC; diceRoll.TrailingEffects.Clear(); // No viewer trailing effects on saving throws. diceRoll.DieTotalMessage = ""; }
private static DiceDto AddDieStr(DiceRoll diceRoll, CardDto cardDto, DndViewer viewer, string dieStr, string dieLabelOverride = null, int targetCharacterId = int.MinValue) { string dieBackColorOverride = viewer.DieBackColor; string dieTextColorOverride = viewer.DieTextColor; int parenIndex = dieStr.IndexOf("("); DamageType damageType = DamageType.None; DieCountsAs dieCountsAs = DieCountsAs.totalScore; string diePlayerName = cardDto.Card.UserName; double modifier = 0; double scaleOverride = viewer.Reputation + 0.30; int dieOwnerOverride = int.MinValue; if (parenIndex >= 0) { ProcessDieDetails(diceRoll, targetCharacterId, ref dieStr, ref dieBackColorOverride, ref dieTextColorOverride, parenIndex, ref damageType, ref dieCountsAs, ref modifier, ref diePlayerName, ref scaleOverride, ref dieOwnerOverride); } string[] dieParts = dieStr.Split('d'); if (dieParts.Length != 2) { return(null); } string dieLabel; if (string.IsNullOrWhiteSpace(dieLabelOverride) || dieLabelOverride.Trim() == "\"\"") { dieLabel = $"{cardDto.Card.UserName}"; } else { dieLabel = dieLabelOverride.Trim().TrimStart('"').TrimEnd('"'); } int quantity; int sides; if (!int.TryParse(dieParts[0], out quantity) || !int.TryParse(dieParts[1], out sides)) { return(null); } DiceDto diceDto = new DiceDto() { PlayerName = diePlayerName, CreatureId = dieOwnerOverride, Sides = sides, Quantity = quantity, Label = dieLabel.Replace("target_name", DndUtils.GetFirstName(diePlayerName)), Scale = scaleOverride, Modifier = modifier, DamageType = damageType, BackColor = dieBackColorOverride, FontColor = dieTextColorOverride, DieCountsAs = dieCountsAs, Data = cardDto.Card.Guid }; diceRoll.DiceDtos.Add(diceDto); return(diceDto); }
private void RollDice() { DiceRoll DiceRollCombat; DiceRollCombat = new DiceRoll(diceType, diceCount, DiceRollCheckType.Combat, Selection.ActiveShip.Owner.PlayerNo); DiceRollCombat.Roll(delegate { ImmediatelyAfterRolling(); }); }
private void Start() { blueDice = GetComponentInParent <BlueHome>().dr; //playerSpecificHome = GetComponentInParent<BlueHome>().Home[]; blueIndex = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 52, 53, 54, 55, 56, 57 }; currentPos = 0; }
private void SetDiceToggles(DiceRoll dr) { diceGroup.SetAllTogglesOff(); switch (dr.dice) { case Dice.d2: d2.isOn = true; break; case Dice.d4: d4.isOn = true; break; case Dice.d6: d6.isOn = true; break; case Dice.d8: d8.isOn = true; break; case Dice.d10: d10.isOn = true; break; case Dice.d12: d12.isOn = true; break; } activeDiceType = dr.dice; }
// Allow selected player to move public void move() { if (currPlayer.doneRoll == true) { return; } Tile currTileInstance = Tiles[currPlayer.getTileIndex()]; int diceResult1 = (int)DiceRoll.rollDice(); print("diceResult: " + diceResult1 + ", tileIndex: " + currPlayer.getTileIndex() + ", loopTileIndex: " + (currPlayer.getTileIndex() + diceResult1) % Tiles.Length); currTileInstance.gameObject.GetComponent <MeshRenderer>().enabled = false; // Set old tile to be invisible currPlayer.Move(diceResult1, Tiles[(PlayerGroup[playerTurn].getTileIndex() + diceResult1) % Tiles.Length].gameObject.transform.position); currTileInstance = Tiles[currPlayer.getTileIndex()]; currTileInstance.gameObject.GetComponent <MeshRenderer>().enabled = true; if (DiceRoll.getDoubles()) { //Don't do any uneeded computation print("Player got doubles, rolling again"); move(); } else { // Do card effect on player tileEffect(currTileInstance); currPlayer.doneRoll = true; } }
private IEnumerator SpawnDice(DiceRoll rollToSpawn, AfterRollAction nextAction) { List <GameObject> currentDice = new List <GameObject>(); //A list of the dice we are about to spawn so we can keep track of them waitingResult = 0; //The number of dice which have yet to settle totalResult = 0; //The total number we roll diceSound.pitch = 1f + Random.Range(-GameController.control.maxPitchVariance, GameController.control.maxPitchVariance); //We ranomize the pitch based on the maxPitchVariance variable in the GameController diceSound.Play(); //Play the dice sound GameObject diceToSpawn = (dice.SingleOrDefault(toCheck => toCheck.type == rollToSpawn.dice)).dicePrefab; //This line uses LINQ to get the appropriate dice from the list for (int i = 0; i < rollToSpawn.amount; i++) //We loop for each dice in the roll { GameObject newDice = Instantiate(diceToSpawn, transform.position, Random.rotation); //Spawn a new dice of the type we determined above. The random rotation is what makes the roll random newDice.GetComponent <Dice>().owner = this; //We tell the new dice that it should report its result to this script currentDice.Add(newDice); //We add the newly created dice to the list that keeps track of the dice this roll waitingResult++; //Increment the number of dice for which results are yet to come in yield return(new WaitForSeconds(0.2f)); //Wait a bit before continuing so that dice don't spawn inside one another } while (waitingResult > 0) //As long as there are still dice that haven't settled we yield { yield return(new WaitForEndOfFrame()); } nextAction(totalResult); //When all dice have settled we return to the GameController by calling the function we are told to do next yield return(new WaitForSeconds(1f)); //We wait a second before destroying the dice objects for (int i = 0; i < currentDice.Count; i++) //Destroys all the dice from this roll { Destroy(currentDice[i]); } }
public void CallOnImmediatelyAfterRolling(DiceRoll diceroll) { if (OnImmediatelyAfterRolling != null) { OnImmediatelyAfterRolling(diceroll); } }
private void ChangeCritsToHits(DiceRoll diceroll) { if (Combat.ChosenWeapon == this) { diceroll.ChangeAll(DieSide.Crit, DieSide.Success); } }
public void ReturnsRandomNumberD4() { DiceRoll dice = new DiceRoll(); int actual = dice.D4(); Assert.IsNotNull(actual); }
public Die(DiceRoll diceRoll, DiceKind type, DieSide side = DieSide.Unknown) { ParentDiceRoll = diceRoll; Type = type; Sides = new List <DieSide> { DieSide.Blank, DieSide.Blank, DieSide.Focus, DieSide.Focus, DieSide.Success, DieSide.Success, DieSide.Success }; if (type == DiceKind.Attack) { Sides.Add(DieSide.Crit); } if (type == DiceKind.Defence) { Sides.Add(DieSide.Blank); } if (side != DieSide.Unknown) { Side = side; } else { Side = Sides[Random.Range(0, 8)]; } }
// No more "once per round". protected override void AddAbility(DiceRoll diceroll) { if (diceroll.DiceList.All(die => die.Side == diceroll.DiceList.First().Side)) { HostShip.OnGenerateDiceModifications += AddAvailableActionEffect; } }
private void RollDice() { DiceRoll DiceRollCombat; DiceRollCombat = new DiceRoll(diceType, diceCount, DiceRollCheckType.Combat); DiceRollCombat.Roll(SyncDiceResults); }
public ObtainingATwoPair() { var diceSet = new DiceRoll(_bothPairs); var pairRule = new PairRule(); result = pairRule.CountPoints(diceSet); }
private DieRollResult GetResult(DieRoll die) { var diceSet = new DiceRoll(FakeDiceRollFactory.GetSetOfRolls(die, 3)); var threeOfAKind = new ThreeOfAKindRule(); return(threeOfAKind.CountPoints(diceSet)); }
public static void ConditionRoll(DiceRoll diceRoll) { foreach (CardEventQueue cardEventQueue in allCardEventQueues) { cardEventQueue.ConditionRoll(diceRoll); } }
protected virtual void CheckResults(DiceRoll diceRoll) { CurentDiceRoll = diceRoll; Selection.ActiveShip = (Combat.AttackStep == CombatStep.Attack) ? Combat.Defender : Combat.Attacker; Combat.DiceModifications.Next(); }
private void ChangeCritsToHits(DiceRoll diceroll) { if (Combat.ChosenWeapon is HeavyLaserCannon) { diceroll.ChangeAll(DieSide.Crit, DieSide.Success); } }
public int GetLevel2AndUpHitPontsD10(int conMod) { DiceRoll dice = new DiceRoll(); int result = dice.D10() + conMod; if (result >= 1) return result; return 1; }
public void DiceRollsAreComparable() { var r1 = new DiceRoll(2); var r2 = new DiceRoll(3); var r3 = new DiceRoll(3); Assert.That(r1.CompareTo(r2), Is.LessThan(0)); Assert.That(r2.CompareTo(r1), Is.GreaterThan(0)); Assert.That(r2.CompareTo(r3), Is.EqualTo(0)); }
public void TestParse(DiceRoll expected, string toParse) { var actual = DiceRoll.Parse(toParse); Assert.That(actual.D4, Is.EqualTo(expected.D4), "Number of d4s should match."); Assert.That(actual.D6, Is.EqualTo(expected.D6), "Number of d6s should match."); Assert.That(actual.D8, Is.EqualTo(expected.D8), "Number of d8s should match."); Assert.That(actual.D10, Is.EqualTo(expected.D10), "Number of d10s should match."); Assert.That(actual.D12, Is.EqualTo(expected.D12), "Number of d12s should match."); Assert.That(actual.Modifier, Is.EqualTo(expected.Modifier), "Modifiers should match."); }
public static DiceRoll RollDice(int count, int faces) { var rolls = new DiceRoll(); for (int i = 0; i < count; i++) { rolls.Add(rand.Next(faces) + 1); } return rolls; }
public void DiceRollsCanBeComparedWithOperators() { var r1 = new DiceRoll(2); var r2 = new DiceRoll(3); var r3 = new DiceRoll(3); Assert.That(r1 < r2); Assert.That(r1 <= r2); Assert.That(r2 > r1); Assert.That(r2 >= r1); Assert.That(r2 >= r3); Assert.That(r2 <= r3); Assert.That(r3 >= r2); Assert.That(r3 <= r2); }
public void TestEquals() { var rand = new Random(); var a = new DiceRoll( d4: (uint)rand.Next(), d6: (uint)rand.Next(), d8: (uint)rand.Next(), d10: (uint)rand.Next(), d12: (uint)rand.Next(), modifier: rand.Next()); var b = new DiceRoll( d4: a.D4, d6: a.D6, d8: a.D8, d10: a.D10, d12: a.D12, modifier: a.Modifier); var c = new DiceRoll( d4: (uint)rand.Next(), d6: (uint)rand.Next(), d8: (uint)rand.Next(), d10: (uint)rand.Next(), d12: (uint)rand.Next(), modifier: rand.Next()); // Strongly typed version Assert.That(a.Equals(a), Is.True); Assert.That(a.Equals(b), Is.True); Assert.That(b.Equals(a), Is.True); Assert.That(a.Equals(c), Is.False); Assert.That(c.Equals(a), Is.False); Assert.That(a.Equals(null), Is.False); // Object version Assert.That(((object)a).Equals(a), Is.True); Assert.That(((object)a).Equals(b), Is.True); Assert.That(((object)b).Equals(a), Is.True); Assert.That(((object)a).Equals(c), Is.False); Assert.That(((object)c).Equals(a), Is.False); Assert.That(((object)a).Equals(null), Is.False); }
public void TestToString(DiceRoll dice, string expected) { Assert.That(dice.ToString(), Is.EqualTo(expected)); }
public DiceRoll AddChildDice(int Dice, int Sides, int Modifier, DiceOperator Operator) { DiceRoll Child = new DiceRoll(Dice, Sides, Modifier); ChildDice.Add(Child, Operator); return Child; }
public void DiceRollContainsNumber() { var roll = new DiceRoll(4); Assert.That(roll.Number, Is.EqualTo(4)); }
public void TestOperatorNotEquals() { var rand = new Random(); var a = new DiceRoll( d4: (uint)rand.Next(), d6: (uint)rand.Next(), d8: (uint)rand.Next(), d10: (uint)rand.Next(), d12: (uint)rand.Next(), modifier: rand.Next()); var b = new DiceRoll( d4: a.D4, d6: a.D6, d8: a.D8, d10: a.D10, d12: a.D12, modifier: a.Modifier); var c = new DiceRoll( d4: (uint)rand.Next(), d6: (uint)rand.Next(), d8: (uint)rand.Next(), d10: (uint)rand.Next(), d12: (uint)rand.Next(), modifier: rand.Next()); Assert.That(a != a, Is.False); Assert.That(a != b, Is.False); Assert.That(b != a, Is.False); Assert.That(a != c, Is.True); Assert.That(c != a, Is.True); Assert.That(a != null, Is.True); Assert.That(null != a, Is.True); }
public void TestGetHashCode() { var rand = new Random(); var a = new DiceRoll( d4: (uint)rand.Next(), d6: (uint)rand.Next(), d8: (uint)rand.Next(), d10: (uint)rand.Next(), d12: (uint)rand.Next(), modifier: rand.Next()); var b = new DiceRoll( d4: a.D4, d6: a.D6, d8: a.D8, d10: a.D10, d12: a.D12, modifier: a.Modifier); var c = new DiceRoll( d4: (uint)rand.Next(), d6: (uint)rand.Next(), d8: (uint)rand.Next(), d10: (uint)rand.Next(), d12: (uint)rand.Next(), modifier: rand.Next()); Assert.That(a.GetHashCode(), Is.EqualTo(a.GetHashCode())); Assert.That(a.GetHashCode(), Is.EqualTo(b.GetHashCode())); Assert.That(a.GetHashCode(), Is.Not.EqualTo(c.GetHashCode())); }
public void TestMaximumRoll() { var actual = new DiceRoll( d4: 2, d6: 4, d8: 1, d10: 2, d12: 1, modifier: 5); Assert.That(actual.MaximumRoll, Is.EqualTo(77), "MaximumRoll should be the sum of (size * number of dice of that size) plus modifier."); }
// RANDOM DICES public DiceRoll RollDice(int size, DiceRoll.DiceType type) { DiceRoll roll = new DiceRoll(size, type, ref _rand); //Debug.Log(roll.TypeToString()); //Debug.Log(roll.RollToString()); //Debug.Log(roll.Sum()); return roll; }