private void Calculate() { if (Strenght == 0) { //This is an item do not calculate. calculated = true; return; } //Not an Equipment EquipmentSlot = EquipmentSlot.None; for (int i = 0; i < Vitality; i++) { DiceExpression diceExpression = new DiceExpression().Constant(1).Dice(1, 2); Health += diceExpression.Roll().Value; Energy += diceExpression.Roll().Value; } MaxHealth = Health; MaxEnergy = Energy; double atk = 0; for (int i = 0; i < Strenght; i++) { DiceExpression diceExpression = new DiceExpression().Dice(1, 2); atk += diceExpression.Roll().Value / 2.0; } Attack = (int)atk; double def = 0; for (int i = 0; i < Strenght; i++) { DiceExpression diceExpression = new DiceExpression().Dice(1, 2); def += (diceExpression.Roll().Value / 2.0) * 0.80; } Defence = (int)def; double atk_c = 50.0 + (Intelligence * 0.3); for (int i = 0; i < Dexterity; i++) { DiceExpression diceExpression = new DiceExpression().Dice(2, 3, 1, choose: 1); atk_c += diceExpression.Roll().Value; } AttackChance = (int)atk_c; double def_c = 20.0 + (Intelligence * 0.3); for (int i = 0; i < Dexterity; i++) { DiceExpression diceExpression = new DiceExpression().Dice(2, 3, 1, choose: 1); def_c += diceExpression.Roll().Value; } DefenceChance = (int)def_c; Awareness = (int)(2.0 + (Intelligence * 0.3)); Speed = (int)(15.0 - (Dexterity * 0.4)); _hpRegen = (Vitality + Intelligence) * 0.005; _enRegen = (Vitality + Intelligence) * 0.041; StatusChanged(); calculated = true; }
private float ResolveAttack() { if (GetComponent <Statistic>(ComponentType.Stats).Energy < 2) { return(0f); } GetComponent <Statistic>(ComponentType.Stats).Energy -= 2; float hitPercent = 0; DiceExpression attackDice = new DiceExpression().Dice(AttackValue, 100); DiceResult attackResult = attackDice.Roll(); foreach (TermResult termResult in attackResult.Results) { if (termResult.Value >= (100 - Stats.AttackChance)) { hitPercent++; } } float hp = hitPercent / (float)AttackValue; System.Console.WriteLine("HitPercent:{0}", hp); return(hp); }
/// <summary> /// The attacker rolls based on his stats to see if he gets any hits /// </summary> /// <param name="attacker"></param> /// <param name="defender"></param> /// <param name="attackMessage"></param> /// <returns></returns> private static int ResolveAttack(Actor attacker, Actor defender, StringBuilder attackMessage) { int hits = 0; // Roll a number of 100-sided dice equal to the Attack value of the attacking actor DiceExpression attackDice = new DiceExpression().Dice(attacker.Attack, 100); DiceResult attackResult = attackDice.Roll(); // Look at the face value of each single die that was rolled foreach (TermResult termResult in attackResult.Results) { // Compare the value to 100 minus the attack chance and add a hit if it's greater if (termResult.Value >= 100 - attacker.AttackChance) { hits++; } } // TODO: Different messages based on how many hits were made if (hits == attacker.Attack) { attackMessage.AppendFormat("{0} slams into {1} with full force!", attacker.Name, defender.Name); } else if (hits > 0) { attackMessage.AppendFormat("{0} lunges at {1}.", attacker.Name, defender.Name); } else { attackMessage.AppendFormat("{0} launches offbalance toward {1}.", attacker.Name, defender.Name); } return(hits); }
private int ResolveDefense(Actor defender, int hits, StringBuilder attackMsg, StringBuilder defenseMsg) { int blocks = 0; if (hits > 0) { attackMsg.AppendFormat("Атака с рейтингом {0} попадания.", hits); defenseMsg.AppendFormat(" {0} защищается с рейтингом: ", defender.Name); DiceExpression defenseDice = new DiceExpression().Dice(defender.Defense, 100); DiceResult defenseRoll = defenseDice.Roll(); foreach (TermResult termResult in defenseRoll.Results) { defenseMsg.Append(termResult.Value + ", "); if (termResult.Value >= 100 - defender.DefenseChance) { blocks++; } defenseMsg.AppendFormat("{0}.", blocks); } } else { attackMsg.Append("и полностью промахивается."); } return(blocks); }
// El defensor tira el dado basado en sus estadísticas para ver si // bloquea cuaqluiera de los golpes del atacante. private static int ResolveDefense( Actor defender, int hits, StringBuilder attackMessage, StringBuilder defenderMessage) { int blocks = 0; if ( hits > 0 ) { attackMessage.AppendFormat("puntuación {0} golpes.", hits); defenderMessage.AppendFormat(" {0} defiende y tira: ", defender.Name); // Rodamos un número de 100 dados de igual lado con el valor de la // defensa del defensor. DiceExpression defenseDice = new DiceExpression().Dice(defender.Defensa, 100); DiceResult defenseRoll = defenseDice.Roll(); // Miramos el valor de la cara de cada dado que fue rodado. foreach( TermResult termResult in defenseRoll.Results ) { defenderMessage.Append(termResult.Value + ", "); // Comparamos el valor a 100, menos la probabilidad de // defender y añadimos un bloqueo si este es mayor. if ( termResult.Value >= 100 - defender.DefensaChance ) { blocks += 1; } } defenderMessage.AppendFormat("resultando en {0} bloqueo(s).", blocks); } else { attackMessage.Append("y falla completamente."); } return blocks; }
private float ResolveDefence() { if (GetComponent <Statistic>(ComponentType.Stats).Energy < 3) { return(0f); } GetComponent <Statistic>(ComponentType.Stats).Energy -= 3; float blockPercent = 0; DiceExpression blockDice = new DiceExpression().Dice(Stats.Defence, 100); DiceResult blockResult = blockDice.Roll(); foreach (TermResult termResult in blockResult.Results) { if (termResult.Value >= (100 - Stats.DefenceChance)) { blockPercent++; } } var bp = blockPercent / (float)Stats.Defence; if (bp == 1 && Stats.Defence >= 20) { return(1); } bp = bp * (float)0.80; System.Console.WriteLine("BlockPercent:{0}", bp); return(bp); }
// El atacante tira en función de sus estadísticas para ver si obtiene // algún resultado. private static int ResolveAttack( Actor attacker, Actor defender, StringBuilder attackMessage) { int hits = 0; attackMessage.AppendFormat("{0} ataca a {1} y tira: ", attacker.Name, defender.Name); // Rodamos un número de 100 dados de igual lados, que será igual al valor de // ataque del atacante {attacker}. DiceExpression attackDice = new DiceExpression().Dice(attacker.Attack, 100); DiceResult attackResult = attackDice.Roll(); // Miramos el valor de la cara de cada dado que fue rodado. foreach ( TermResult termResult in attackResult.Results ) { attackMessage.Append(termResult.Value + ", "); // Comparamos el valor a 100, menos la probabilidad de // ataque y añadimos el golpe si este es mayor. if ( termResult.Value >= 100 - attacker.AttackChance ) { hits += 1; } } return hits; }
private static int ResolveDefense(Actor defender, int hits, StringBuilder attackMessage, StringBuilder defenseMessage) { int blocks = 0; if (hits > 0) { attackMessage.AppendFormat("scoring {0} hits.", hits); defenseMessage.AppendFormat(" {0} defends and rolls: ", defender.Name); DiceExpression defenseDice = new DiceExpression().Dice(defender.Defense, 100); DiceResult defenseRoll = defenseDice.Roll(); foreach (TermResult termResult in defenseRoll.Results) { defenseMessage.Append(termResult.Value + ", "); if (termResult.Value >= 100 - defender.DefenseChance) { blocks++; } } defenseMessage.AppendFormat("resulting in {0} blocks.", blocks); } else { attackMessage.Append("and misses completely."); } return(blocks); }
// The defender rolls based on his stats to see if he blocks any of the hits from the attacker private int ResolveDefense(Actor defender, int hits, StringBuilder attackMessage, StringBuilder defenseMessage) { int blocks = 0; if (hits > 0) { attackMessage.AppendFormat("scoring {0} hits.", hits); defenseMessage.AppendFormat(" {0} defends and rolls: ", defender.Name); // Roll a number of 100-sided dice equal to the Defense value of the defendering actor DiceExpression defenseDice = new DiceExpression().Dice(defender.Defense, 100); DiceResult defenseRoll = defenseDice.Roll(); // Look at the face value of each single die that was rolled foreach (TermResult termResult in defenseRoll.Results) { defenseMessage.Append(termResult.Value + ", "); // Compare the value to 100 minus the defense chance and add a block if it's greater if (termResult.Value >= 100 - defender.DefenseChance) { blocks++; } } defenseMessage.AppendFormat("resulting in {0} blocks.", blocks); } else { attackMessage.Append("and misses completely."); } return(blocks); }
//check too see how many hits the attacker got on the defender and displays message private static int ResolveAttack(Actor attacker, Actor defender, StringBuilder attackMessage) { int hits = 0; //displays message of who is attacking which defender //attackMessage.AppendFormat("{0} attacks {1} and rolls: ", attacker.Name, defender.Name); //Roll a number 100-dice equal to the attack value of the attacking actor //gets the dice for that attacker DiceExpression attackDice = new DiceExpression().Dice(attacker.Attack, 100); //rolls the attackers dice and gets the dice result DiceResult attackResult = attackDice.Roll(); //foreach dice roll in the attackers results foreach (TermResult termResult in attackResult.Results) { //appends the attack message adding the current attack dice value attackMessage.Append(termResult.Value + ", "); //if the current attack dice roll result was more than 100 - the attackers attack chance //it was a success and a hit is added if (termResult.Value >= 100 - attacker.AttackChance) { hits++; } } return(hits); }
private static int ResolveDefense(Actor defender, int hits, StringBuilder attackMessage, StringBuilder defenseMessage) { int blocks = 0; if (hits > 0) { attackMessage.AppendFormat("atingindo {0} golpes", hits); defenseMessage.AppendFormat(" {0} defende e rola: ", defender.Name); DiceExpression defenseDice = new DiceExpression().Dice(defender.Defense, 100); DiceResult defenseRoll = defenseDice.Roll(); foreach (TermResult termResult in defenseRoll.Results) { defenseMessage.Append(termResult.Value + ", "); if (termResult.Value >= 100 - defender.DefenseChance) { blocks++; } } defenseMessage.AppendFormat("resultando em {0} bloqueios", blocks); } else { attackMessage.Append("e erra completamente"); } return(blocks); }
private static void AssertReturnedInRange(DiceExpression expr, int min, int max) { for (var i = 0; i < 100; i++) { var result = expr.Roll(); Assert.True(result >= min && result <= max); } }
public void Roll_ExpressionBuiltFluently_ReturnsCorrectNumberOfResults() { DiceExpression diceExpression = new DiceExpression() .Constant( 5 ) .Die( 8 ) .Dice( 4, 6, choose: 3 ); const int expectedNumberOfTerms = 1 + 1 + 3; DiceResult result = diceExpression.Roll( new DotNetRandom() ); Assert.AreEqual( expectedNumberOfTerms, result.Results.Count ); }
public void Roll_ExpressionBuiltFluently_ReturnsCorrectNumberOfResults() { DiceExpression diceExpression = new DiceExpression() .Constant(5) .Die(8) .Dice(4, 6, choose: 3); const int expectedNumberOfTerms = 1 + 1 + 3; DiceResult result = diceExpression.Roll(new DotNetRandom()); Assert.AreEqual(expectedNumberOfTerms, result.Results.Count); }
public void ContainsAndReturnsCorrectNumberOfValues() { DiceExpression diceExpression = new DiceExpression() .Constant(5) .Die(8) .Dice(4, 6, choose: 3); DiceResult result = diceExpression.Roll(new StandardDieRoller(new Random())); const int expectedNumberOfTerms = 1 + 1 + 3; Assert.AreEqual(expectedNumberOfTerms, result.Results.Count); }
private static int CountAtk(Actor attacker, Actor defender, StringBuilder attackMessage) { int hits = 0; DiceExpression atkRoll = new DiceExpression().Dice(attacker.Attack, 100); DiceResult atk = atkRoll.Roll(); foreach (TermResult termResult in atk.Results) { if (termResult.Value >= 100 - attacker.AtkChance) { hits++; } } return(hits); }
private void PlaceItems() { int keyPlaced = 1; int roomIndex = 0; int roomCount = _map.Rooms.Count(); int previousCheckpoint = 0; foreach (var room in _map.Rooms) { // Making sure that the 3 keys are placed if (roomIndex > 0 && roomIndex < roomCount - 1 && keyPlaced < 4) { int checkpoint = keyPlaced * (roomCount - 2) / 3; Point randomRoomLocation = _map.GetRandomWalkableLocationInRoom(room); if (randomRoomLocation != Point.Zero) { if (roomIndex >= checkpoint) { Item key = new Key(randomRoomLocation.X, randomRoomLocation.Y, keyPlaced - 1); _map.AddItem(key); keyPlaced++; previousCheckpoint = checkpoint; } else { int diceNb = (roomIndex <= previousCheckpoint) ? 1 : roomIndex - previousCheckpoint; DiceExpression dice = new DiceExpression() .Dice(diceNb, 2 * (checkpoint - previousCheckpoint - 1)); if (dice.Roll().Value > 8) { Item key = new Key(randomRoomLocation.X, randomRoomLocation.Y, keyPlaced - 1); _map.AddItem(key); keyPlaced++; previousCheckpoint = checkpoint; } } } } // Placer les items restants if (Dice.Roll("1D10") < 8) { PlaceItems(room.GetAllCells(_map), 3); } roomIndex++; } }
private static int ResolveAttack(Actor attacker, Actor defender) { int hits = 0; DiceExpression attackDice = new DiceExpression().Dice(attacker.Damage, 100); DiceResult attackResult = attackDice.Roll(); foreach (TermResult termResult in attackResult.Results) { if (termResult.Value >= 100 - attacker.Accuracy) { hits++; } } return(hits); }
public static int ResolveAttack(Actor attacker, Actor defender, StringBuilder attackMessage) { int hits = 0; attackMessage.AppendFormat("{0} attacks {1} and rolls: ", attacker.Name, defender.Name); DiceExpression attackDice = new DiceExpression().Dice(attacker.Attack, 100); DiceResult attackResult = attackDice.Roll(); foreach (TermResult termResult in attackResult.Results) { attackMessage.Append(termResult.Value + ", "); if (termResult.Value >= 100 - attacker.AttackChance) { hits++; } } return(hits); }
public void TestKeepDropModifier() { var de = new DiceExpression("4d6dl1", new RandomMock()); Assert.AreEqual(9, de.Roll()); Assert.AreEqual(12.2, de.GetExpected(), 0.15); de = new DiceExpression("4d6kl1", new RandomMock()); Assert.AreEqual(1, de.Roll()); Assert.AreEqual(1.8, de.GetExpected(), 0.15); de = new DiceExpression("4d6dh1", new RandomMock()); Assert.AreEqual(6, de.Roll()); Assert.AreEqual(8.8, de.GetExpected(), 0.15); de = new DiceExpression("4d6kh1", new RandomMock()); Assert.AreEqual(4, de.Roll()); Assert.AreEqual(5.2, de.GetExpected(), 0.15); de = new DiceExpression("4d6dl2", new RandomMock()); Assert.AreEqual(7, de.Roll()); de = new DiceExpression("4d6kl2", new RandomMock()); Assert.AreEqual(3, de.Roll()); de = new DiceExpression("4d6dh2", new RandomMock()); Assert.AreEqual(3, de.Roll()); de = new DiceExpression("4d6kh2", new RandomMock()); Assert.AreEqual(7, de.Roll()); de = new DiceExpression("4d6kl2", new Random()); var exp = de.GetExpected(10000); Console.WriteLine(exp); Assert.AreEqual(4.66, exp, 0.05); de = new DiceExpression("4d6kh2", new Random()); exp = de.GetExpected(10000); Console.WriteLine(exp); Assert.AreEqual(9.34, exp, 0.05); }
private static int ResolveDefense(Actor defender, int hits) { int blocks = 0; if (hits > 0) { DiceExpression defenseDice = new DiceExpression().Dice(defender.Defense, 100); DiceResult defenseRoll = defenseDice.Roll(); foreach (TermResult termResult in defenseRoll.Results) { if (termResult.Value >= 100 - defender.BlockChance) { blocks++; } } } return(blocks); }
public void TestDieExpression() { var de = new DiceExpression("1d6"); Assert.AreEqual(3.5, de.GetExpected()); Assert.AreEqual(1, de.GetMin()); Assert.AreEqual(6, de.GetMax()); de = new DiceExpression("2d6"); Assert.AreEqual(7, de.GetExpected()); Assert.AreEqual(2, de.GetMin()); Assert.AreEqual(12, de.GetMax()); de = new DiceExpression("1d12"); Assert.AreEqual(6.5, de.GetExpected()); Assert.AreEqual(1, de.GetMin()); Assert.AreEqual(12, de.GetMax()); de = new DiceExpression("1d6", new Random(0)); var results = new Dictionary <int, int>() { { 1, 0 }, { 2, 0 }, { 3, 0 }, { 4, 0 }, { 5, 0 }, { 6, 0 } }; for (var i = 0; i < 6000; i++) { results[(int)de.Roll()]++; } Assert.LessOrEqual(Math.Abs(results[1] - 1000), 50); Assert.LessOrEqual(Math.Abs(results[2] - 1000), 50); Assert.LessOrEqual(Math.Abs(results[3] - 1000), 50); Assert.LessOrEqual(Math.Abs(results[4] - 1000), 50); Assert.LessOrEqual(Math.Abs(results[5] - 1000), 50); Assert.LessOrEqual(Math.Abs(results[6] - 1000), 50); }
private int ResolveAttack(Actor attacker, Actor defender, StringBuilder attackMsg) { int hits = 0; attackMsg.AppendFormat("{0} атакует {1} с рейтингом: ", attacker.Name, defender.Name); DiceExpression attackDice = new DiceExpression().Dice(attacker.Attack, 100); DiceResult attackRoll = attackDice.Roll(); foreach (TermResult termResult in attackRoll.Results) { attackMsg.Append(termResult.Value + ", "); if (termResult.Value >= 100 - attacker.AttackChance) { hits++; } } return(hits); }
/// <summary> /// The attacker rolls based on his stats to see if he gets any hits. /// </summary> /// <param name="attacker"></param> /// <param name="defender"></param> /// <param name="attackMessage"></param> /// <returns></returns> private int ResolveAttack (Actor attacker, Actor defender, StringBuilder attackMessage) { int hits = 0; attackMessage.AppendFormat ("{0} attacks {1} and rolls: ", attacker.Name, defender.Name); // Roll a number of 100-sided dice equal to the Attack value of the attacking actor DiceExpression attackDice = new DiceExpression ().Dice (attacker.Attack, 100); DiceResult attackResult = attackDice.Roll (); // Look at the face value of each single die that was rolled foreach (TermResult termResult in attackResult.Results) { attackMessage.Append (termResult.Value + ", "); // Compare the value to 100 minus the attack chance and add a hit if it's greater if (termResult.Value >= 100 - attacker.AttackChance) { hits++; } } return hits; }
// The defender rolls based on his stats to see if he blocks any of the hits from the attacker private static int ResolveDefense(Actor defender, int hits, StringBuilder attackMessage, StringBuilder defenseMessage) { int blocks = 0; //if hits were over 0 if (hits > 0) { //display how many hits //attackMessage.AppendFormat("scoring {0} hits", hits); //defenseMessage.AppendFormat(" {0} defends and rolls:", defender.Name); //Roll a number of 100-sided dice equal to the defense value of the defending actor //gets the dice for that defender DiceExpression defenseDice = new DiceExpression().Dice(defender.Defense, 100); DiceResult defenseRoll = defenseDice.Roll(); //Looks at the face value of each single die that was rolled foreach (TermResult termResult in defenseRoll.Results) { defenseMessage.Append(termResult.Value + ", "); //if the current dice result was more than or equal too 100 - the defense chance than it was a success //and we add a block if (termResult.Value >= 100 - defender.DefenseChance) { blocks++; } } //display how many blocks the defender made //defenseMessage.AppendFormat("resulting in {0} blocks", blocks); } //if hits were less thanor equal to 0 display this message else { //attackMessage.Append("and misses completely."); } return(blocks); }
// Roll the number of hits private static int ResolveAttack(Actor attacker, Actor defender, StringBuilder attackMessage) { int hits = 0; attackMessage.AppendFormat("{0} attacks {1} and rolls: ", attacker.Name, defender.Name); // Roll a number of 100-sided dice equall to the the Attack val of the attacking actor DiceExpression attackDice = new DiceExpression().Dice(attacker.Attack, 100); DiceResult attackResult = attackDice.Roll(); // Check the value of each singe rolled dice foreach (TermResult termResult in attackResult.Results) { attackMessage.Append(termResult.Value + ", "); if (termResult.Value >= 100 - attacker.AttackChance) { hits++; } } return(hits); }
private static int CountDef(Actor defender, int hits, StringBuilder atkLog, StringBuilder defLog) { int blocks = 0; if (hits > 0) { DiceExpression defRoll = new DiceExpression().Dice(defender.Defense, 100); DiceResult def = defRoll.Roll(); foreach (TermResult termResult in def.Results) { if (termResult.Value >= 100 - defender.DefChance) { blocks++; } } } else { } return(blocks); }
private static int ResolveAttack(Actor attacker, Actor defender, StringBuilder attackMessage) { int hits = 0; if (attacker.AttackMessages != null) { Random random = new Random(); int i = random.Next(0, attacker.AttackMessages.Length); if (attacker is Player) { Game.MessageLog.Add($"{attacker.AttackMessages[i]} {defender.Name}"); } else { Game.MessageLog.Add($"{attacker.AttackMessages[i]}"); } } else { Game.MessageLog.Add($"{attacker.Name} attacks {defender.Name}"); // attackMessage.AppendFormat("{0} attacks {1}", attacker.Name, defender.Name); // debug - previously: ": and rolls: " at end } DiceExpression attackDice = new DiceExpression().Dice(attacker.Attack, 100); DiceResult attackResult = attackDice.Roll(); foreach (TermResult termResult in attackResult.Results) { // attackMessage.Append(termResult.Value + ", "); // debug if (termResult.Value >= 100 - attacker.AttackChance) { hits++; } } return(hits); }
/// <summary> /// The defender rolls based on his stats to see if he blocks any of the hits from the attacker /// </summary> /// <param name="defender"></param> /// <param name="hits"></param> /// <param name="attackMessage"></param> /// <param name="defenseMessage"></param> /// <returns></returns> private static int ResolveDefense(Actor defender, int hits, StringBuilder attackMessage, StringBuilder defenseMessage) { int blocks = 0; if (hits > 0) { // Roll a number of 100-sided dice equal to the Defense value of the defendering actor DiceExpression defenseDice = new DiceExpression().Dice(defender.Defense, 100); DiceResult defenseRoll = defenseDice.Roll(); // Look at the face value of each single die that was rolled foreach (TermResult termResult in defenseRoll.Results) { // Compare the value to 100 minus the defense chance and add a block if it's greater if (termResult.Value >= 100 - defender.DefenseChance) { blocks++; } } // TODO: Different messages based on how many hits were made if (blocks == defender.Defense) { defenseMessage.AppendFormat("{0} absorbs the blows with ease.", defender.Name); } else if (blocks > 0) { defenseMessage.AppendFormat("The defense of {0} falls for just a moment.", defender.Name); } } else { defenseMessage.AppendFormat("{0} was totally unaware!", defender.Name); } return(blocks); }