/// <summary> Applies specified dice operation to the given roll values. </summary> /// <remarks> <see cref="DiceOperation.Plus"/> and <see cref="DiceOperation.Minus"/> are modifying roll totals, /// so there isn't any good way to shove them in. For these operations /// <paramref name="opValueProvider"/>'s value is being added to the first roll value.</remarks> /// <param name="rolls">Roll values to modify.</param> /// <param name="operation"></param> /// <param name="opValueProvider">Rolls a value which will be used for modification.</param> /// <returns>Rolls modified with <paramref name="opValueProvider"/>'s value according to the given operation. /// </returns> public static IEnumerable<double> ApplyOperation(IEnumerable<double> rolls, DiceOperation operation, IDie opValueProvider) { Contract.Requires(rolls != null); Contract.Requires(operation != DiceOperation.None); Contract.Requires(opValueProvider != null); Contract.Ensures(Contract.Result<IEnumerable<double>>() != null); // Plus and Minus are modifying roll totals, so there isn't any good way to shove them in. // Let's just add them to first value. if (operation == DiceOperation.Minus || operation == DiceOperation.Plus) { bool applied = false; foreach (var roll in rolls) { if (!applied) { yield return PerformRollCombination(roll, operation, opValueProvider.Roll()); applied = true; } else { yield return roll; } } // If rolls were empty, return the total modifier as is: if (!applied) { var value = opValueProvider.Roll(); yield return (operation == DiceOperation.Minus) ? -value : value; } } else { // For other operations just modify each roll value using the value provider. foreach (var roll in rolls) { yield return PerformRollCombination(roll, operation, opValueProvider.Roll()); } } }
private void CurrentCharacter_OnDie(IDie character) { currentCharacter.OnHealthChanged -= HandleHealthChanged; currentCharacter.OnDie -= CurrentCharacter_OnDie; gameObject.SetActive(false); currentCharacter = null; }
public void Init(IDie iDie, Transform transform, int maxHP) { _MaxHP = maxHP; _iDie = iDie; _transform = transform; Reset(_MaxHP); }
/// <summary> Initializes a new instance of the <see cref="SeveralDice"/> class. </summary> /// <param name="rollValueProvider">Something which can provide roll value.</param> /// <param name="rollCountProvider">Something which can provide amount of rolls. Null value means 1 roll. /// </param> public SeveralDice(IDie rollValueProvider, IDie rollCountProvider) { Contract.Requires(rollValueProvider != null); RollValueProvider = rollValueProvider; RollCountProvider = rollCountProvider; }
public WhiteSegment(IDie whiteDie) { Hits = 4; Cost = 0; IsDamaged = false; AssociatedDie = whiteDie; }
private void Player_OnCharacterChanged(IDie character) { currentCharacter = character; currentCharacter.OnHealthChanged += HandleHealthChanged; currentCharacter.OnDie += CurrentCharacter_OnDie; gameObject.SetActive(true); }
public void DisconnectDie(IDie die, System.Action <IDie, bool, string> onDisconnectionResult) { operations.Enqueue(new OperationDisconnect() { die = die, onDisconnectionResult = onDisconnectionResult }); TryPerformOneOperation(); }
/// <summary> /// Writes data to a connected die /// </summary> /// <param name="die">The die to write to</param> /// <param name="bytes">The data to write</param> /// <param name="length">The length of the data (can be less than the buffer length)</param> /// <param name="bytesWrittenCallback">Callback for when the data is written</param> public void WriteDie(IDie die, byte[] bytes, int length, System.Action <IDie, bool, string> bytesWrittenCallback) { operations.Enqueue(new OperationWriteDie() { die = die, bytes = bytes, length = length, bytesWrittenCallback = bytesWrittenCallback }); TryPerformOneOperation(); }
public Die(IDie die) { this.state = State.Advertising; this.die = die; this.startTime = float.MaxValue; this.deviceConnected = false; this.messageWriteCharacteristicFound = false; this.messageReadCharacteristicFound = false; }
private void OnTriggerEnter2D(Collider2D collision) { IDie dieObject = collision.GetComponent <IDie>(); if (dieObject != null) { dieObject.Die(); } }
/// <summary> Initializes a new instance of the <see cref="DiceChainSetup" /> struct. </summary> /// <param name="amountProvider">The amount of dice added to the created <see cref="DiceChain" />.</param> /// <param name="previousOperation">The operation to use with previous <see cref="DiceChain"/>.</param> /// <param name="previousDice">The previous <see cref="DiceChain"/> to carry on to next one.</param> public DiceChainSetup(IDie amountProvider, DiceOperation previousOperation, DiceChain previousDice) { Contract.Requires(previousOperation != DiceOperation.None); Contract.Requires(amountProvider != null); Amount = amountProvider; PreviousOperation = previousOperation; PreviousDice = previousDice; }
/// <summary> /// Initializes a new instance of the <see cref="VirtualDieRollResult" /> class. /// </summary> /// <param name="die">The die.</param> /// <param name="rolledNumber">The rolled number.</param> /// <param name="criticalSuccess">if set to <c>true</c> the result is marked as a critical success.</param> /// <param name="criticalFailure">if set to <c>true</c> the result is marked as a critical failure.</param> // ReSharper disable once TooManyDependencies public VirtualDieRollResult(IDie die, int rolledNumber, bool criticalSuccess, bool criticalFailure) { Die = die; _RolledNumber = rolledNumber; _Value = new ResultValueSet { { "Number", rolledNumber } }; _IsCriticalFailure = criticalFailure; _IsCriticalSuccess = criticalSuccess; }
private void OnTriggerEnter2D(Collider2D collision) { IDie victim = collision.GetComponentInParent <IDie>(); if (victim != null) { victim.Dead(transform.position); GetComponent <Disabler>().Destroy(); } }
public DefaultMove(IBoardLane lane, int laneIndex, IDie die) { if (lane == null) throw new ArgumentNullException(nameof(lane)); if (die == null) throw new ArgumentNullException(nameof(die)); this.Lane = (IGameBoardLane)lane; this.LaneIndex = laneIndex; this.Die = die; }
/// <inheritdoc/> public bool Remove(IDie item) { var success = _Storage.Remove(item); if (_Storage.Count == 0) { Sides = 0; } return(success); }
public void ConnectDie( IDie die, System.Action <IDie, bool, string> connectionResultCallback, System.Action <IDie, byte[]> onDataCallback, System.Action <IDie, string> onUnexpectedDisconnectionCallback) { operations.Enqueue(new OperationConnect() { die = die, connectionResultCallback = connectionResultCallback, onDataCallback = onDataCallback, onUnexpectedDisconnectionCallback = onUnexpectedDisconnectionCallback }); TryPerformOneOperation(); }
public void Init(EnemyData enemyData) { dieEvent = null; this.enemyData = enemyData; this.nowHP = enemyData.hp; this.nowSpeed = enemyData.speed; this.navMeshAgent = this.gameObject.GetComponent <NavMeshAgent>(); novaEffect.SetActive(false); slowDownPer = 0; speedUpPer = 0; InitAnim(); StartCoroutine(Move()); }
public void AddToKill(IDie objectToKill) { if (!mToKill.ContainsKey(objectToKill.DeathOrder)) { mToKill[objectToKill.DeathOrder] = new List <IDie>(); } // we want don't want to add the same object twice if somewhere FlagForDeath was called twice by accident. // killing the object twice even though it should only die once could lead in massive null pointer problems and stuff. if (mToKill[objectToKill.DeathOrder].Contains(objectToKill)) { return; } mToKill[objectToKill.DeathOrder].Add(objectToKill); }
public IEnumerable<IDie> CreateDieEnumerable(params int[] diceValues) { var dice = new IDie[diceValues.Length]; var counter = 0; foreach (var value in diceValues) { var mock = new Mock<IDie>(); mock.Setup(x => x.Value).Returns(value); dice[counter] = mock.Object; counter++; } return dice.AsEnumerable(); }
public bool Attack(IDie die, Character attackedCharacter) { var rollTotal = die.GetRoll(); var modifier = AbilitiesScores.AbilityScore[this.strength]; var didHit = CheckHit(rollTotal, modifier, attackedCharacter); if (didHit) { attackedCharacter.hitPoints -= CalculateDamage(rollTotal, modifier); this.XP += 10; this.hitPoints = this.level * 5; } return(didHit); }
/// <summary> /// Initializes a new instance of the <see cref="DieRollResult"/> class. /// </summary> /// <param name="die">The die.</param> /// <param name="rolledNumber">The rolled number.</param> public DieRollResult(IDie die, int rolledNumber) { Die = die; _RolledNumber = rolledNumber; _ValueSet = new ResultValueSet { { "Number", rolledNumber } }; if (rolledNumber == 1) { _CriticalFailure = true; } if (rolledNumber == die.Sides) { _CriticalSuccess = true; } }
public IEnumerable <IDie> CreateDieEnumerable(params int[] diceValues) { var dice = new IDie[diceValues.Length]; var counter = 0; foreach (var value in diceValues) { var mock = new Mock <IDie>(); mock.Setup(x => x.Value).Returns(value); dice[counter] = mock.Object; counter++; } return(dice.AsEnumerable()); }
/// <inheritdoc/> /// <exception cref="T:System.ArgumentNullException"><paramref name="item"/> is <see langword="null"/></exception> /// <exception cref="T:Org.Edgerunner.Dice.Exceptions.DiceMismatchException">A dice set cannot contain dice with differing numbers of sides</exception> public void Add(IDie item) { if (item == null) { throw new ArgumentNullException(nameof(item)); } if (Sides == 0) { Sides = item.Sides; } else if (Sides != item.Sides) { throw new DiceMismatchException("A dice set cannot contain dice with differing numbers of sides"); } _Storage.Add(item); }
/// <summary> /// Writes data to a connected die /// </summary> /// <param name="die">The die to write to</param> /// <param name="bytes">The data to write</param> /// <param name="length">The length of the data (can be less than the buffer length)</param> /// <param name="bytesWrittenCallback">Callback for when the data is written</param> public void WriteDie(IDie die, byte[] bytes, int length, System.Action bytesWrittenCallback) { if (_dice.TryGetValue(die.address, out Die ddie)) { if (ddie.state != Die.State.Ready) { Debug.LogError("Die " + die.name + " in invalid state " + ddie.state); return; } // Write the data! System.Action <string> onWritten = (ignore) => bytesWrittenCallback?.Invoke(); BluetoothLEHardwareInterface.WriteCharacteristic(die.address, serviceGUID, writeCharacteristic, bytes, length, false, onWritten); } else { Debug.LogError("Unknown die " + die.name + " received data!"); } }
/// <summary> /// Disconnect from a given die /// </summary> public void DisconnectDie(IDie die) { if (_dice.TryGetValue(die.address, out Die ddie)) { if (ddie.state == Die.State.Advertising) { Debug.LogError("Die " + die.name + " in invalid state " + ddie.state); return; } // And kick off the disconnection! ddie.state = Die.State.Disconnecting; BluetoothLEHardwareInterface.DisconnectPeripheral(die.address, null); } else { Debug.LogError("Trying to disconnect unknown die " + die.name); } }
/// <summary> Applies specified dice operation to the given roll values. </summary> /// <remarks> <see cref="DiceOperation.Plus"/> and <see cref="DiceOperation.Minus"/> are modifying roll totals, /// so there isn't any good way to shove them in. For these operations /// <paramref name="opValueProvider"/>'s value is being added to the first roll value.</remarks> /// <param name="rolls">Roll values to modify.</param> /// <param name="operation"></param> /// <param name="opValueProvider">Rolls a value which will be used for modification.</param> /// <returns>Rolls modified with <paramref name="opValueProvider"/>'s value according to the given operation. /// </returns> public static IEnumerable <double> ApplyOperation(IEnumerable <double> rolls, DiceOperation operation, IDie opValueProvider) { Contract.Requires(rolls != null); Contract.Requires(operation != DiceOperation.None); Contract.Requires(opValueProvider != null); Contract.Ensures(Contract.Result <IEnumerable <double> >() != null); // Plus and Minus are modifying roll totals, so there isn't any good way to shove them in. // Let's just add them to first value. if (operation == DiceOperation.Minus || operation == DiceOperation.Plus) { bool applied = false; foreach (var roll in rolls) { if (!applied) { yield return(PerformRollCombination(roll, operation, opValueProvider.Roll())); applied = true; } else { yield return(roll); } } // If rolls were empty, return the total modifier as is: if (!applied) { var value = opValueProvider.Roll(); yield return((operation == DiceOperation.Minus) ? -value : value); } } else // For other operations just modify each roll value using the value provider. { foreach (var roll in rolls) { yield return(PerformRollCombination(roll, operation, opValueProvider.Roll())); } } }
/// <summary> /// Kijkt of de hero iets dodelijk heeft aangeraakt /// </summary> /// <param name="collideObjects">Lijst met alle objecten waar we mee kunnen colliden</param> /// <param name="canDieObject">bewegend object dat kan colliden</param> private static void DetectHeroDeath(List <ICollide> collideObjects, IDie canDieObject) { foreach (IDeathBlock deathBlock in collideObjects.OfType <IDeathBlock>()) { if (canDieObject.CollisionRectangle.Intersects(deathBlock.CollisionRectangle)) { canDieObject.IsHit = true; } } foreach (Enemy enemy in collideObjects.OfType <Enemy>()) { if (canDieObject.CollisionRectangle.Intersects(enemy.CollisionRectangle)) { if (enemy.CurrentAnimation != enemy.DeathAnimation) { canDieObject.IsHit = true; enemy.Attack = true; } } } }
private DiceChain AppendDie(IDie die) { Contract.Requires(die != null); var result = PreviousDice; if (result != null) { if (PreviousOperation == DiceOperation.None) { throw new InvalidOperationException("Can't append dice with unknown operation."); } result.Append(PreviousOperation, new SeveralDice(die, Amount)); } else { result = new DiceChain(new SeveralDice(die, Amount)); } return(result); }
/// <summary> /// Disconnect from a given die /// </summary> void DoDisconnectDie(IDie die, System.Action <IDie, bool, string> onDisconnectionResult) { if (_dice.TryGetValue(die.address, out Die ddie)) { Debug.Log("Disconnecting die " + die.name); if (ddie.state == Die.State.Advertising) { Debug.LogError("Die " + die.name + " in invalid state " + ddie.state); return; } _state = State.Disconnecting; // And kick off the disconnection! ddie.state = Die.State.Disconnecting; ddie.onDisconnectionResult = onDisconnectionResult; BluetoothLEHardwareInterface.DisconnectPeripheral(die.address, null); // <-- we don't use this callback, we already have one } else { Debug.LogError("Trying to disconnect unknown die " + die.name); } }
/// <summary> /// Connect to a die /// </summary> void DoConnectDie( IDie die, System.Action <IDie, bool, string> connectionResultCallback, System.Action <IDie, byte[]> onDataCallback, System.Action <IDie, string> onUnexpectedDisconnectionCallback) { if (_dice.TryGetValue(die.address, out Die ddie)) { if (ddie.state != Die.State.Advertising) { Debug.LogError("Die " + die.name + " in invalid state " + ddie.state); return; } ddie.state = Die.State.Connecting; ddie.startTime = Time.time; ddie.deviceConnected = false; ddie.messageReadCharacteristicFound = false; ddie.messageWriteCharacteristicFound = false; ddie.onConnectionResult = connectionResultCallback; ddie.onData = onDataCallback; ddie.onUnexpectedDisconnection = onUnexpectedDisconnectionCallback; Debug.Log("Connecting to die " + ddie.name); _state = State.Connecting; // And kick off the connection! BluetoothLEHardwareInterface.ConnectToPeripheral(die.address, OnDeviceConnected, OnServiceDiscovered, OnCharacteristicDiscovered, OnDeviceDisconnected); } else { string errorMessage = "Trying to connect to unknown die " + die.name; Debug.LogError(errorMessage); connectionResultCallback?.Invoke(die, false, errorMessage); } }
/// <summary> /// Connect to a die /// </summary> public void ConnectDie(IDie die) { if (_dice.TryGetValue(die.address, out Die ddie)) { if (ddie.state != Die.State.Advertising) { Debug.LogError("Die " + die.name + " in invalid state " + ddie.state); return; } ddie.state = Die.State.Connecting; ddie.startTime = Time.time; ddie.deviceConnected = false; ddie.messageReadCharacteristicFound = false; ddie.messageWriteCharacteristicFound = false; // And kick off the connection! BluetoothLEHardwareInterface.ConnectToPeripheral(die.address, OnDeviceConnected, OnServiceDiscovered, OnCharacteristicDiscovered, OnDeviceDisconnected); } else { Debug.LogError("Trying to connect to unknown die " + die.name); } }
public Attack(IDie attackRoll, IDamage damage) { AttackRoll = attackRoll ?? throw new ArgumentNullException(nameof(attackRoll)); Damage = damage ?? throw new ArgumentNullException(nameof(damage)); }
private ITurn UseDie(IPlayer player, IDie usedDie) { var actualDie = this.Turn.Dice.First(x => x.Equals(usedDie)); return new DefaultTurn(player, this.Turn.Dice.Select(x => object.ReferenceEquals(x, actualDie) ? new DefaultDie(true, x.Value) : x).ToList()); }
private Class1 GetDamageCalculator(IDie die) { return new Class1(die); }
/// <summary> Initializes a new instance of the <see cref="SeveralDice"/> class. </summary> /// <param name="rollValueProvider">Something which can provide roll value.</param> public SeveralDice(IDie rollValueProvider) : this(rollValueProvider, null) { Contract.Requires(rollValueProvider != null); }
/// <summary> Appends a value provider to the dice chain which will be added to the previous chain value. </summary> /// <param name="valueProvider">The provider of the value to add.</param> /// <returns>Dice chain with a value provider appended.</returns> public DiceChain Plus(IDie valueProvider) { Contract.Requires(valueProvider != null); return Append(DiceOperation.Plus, new SeveralDice(valueProvider)); }
/// <summary> Prepares appending of several dice to the dice chain. They will be added to /// the previous chain value. </summary> /// <param name="amountProvider">Provider of the amount of dice to append to the dice chain.</param> public DiceChainSetup PlusTake(IDie amountProvider) { Contract.Requires(amountProvider != null); return new DiceChainSetup(amountProvider, DiceOperation.Plus, this); }
protected void SetUp() { _die = Substitute.For<IDie>(); _hitGenerator = new HitGenerator(_die); _units = new Dictionary<CombatUnitType,int>() { {TestUtils.CreateInfantryType(), 1 } }; }
public HitGenerator(IDie die) { _die = die; }
private DiceChain AppendDie(IDie die) { Contract.Requires(die != null); var result = PreviousDice; if (result != null) { if (PreviousOperation == DiceOperation.None) { throw new InvalidOperationException("Can't append dice with unknown operation."); } result.Append(PreviousOperation, new SeveralDice(die, Amount)); } else { result = new DiceChain(new SeveralDice(die, Amount)); } return result; }
/// <summary> Initializes a new instance of the <see cref="DiceChainSetup" /> struct. </summary> /// <param name="amountProvider">The amount of dice added to the created <see cref="DiceChain" />.</param> public DiceChainSetup(IDie amountProvider) : this(amountProvider, DiceOperation.Plus, null) { Contract.Requires(amountProvider != null); }
/// <summary> Initializes a new instance of the <see cref="SeveralDice"/> class. </summary> /// <param name="rollValueProvider">Something which can provide roll value.</param> /// <param name="rollCount">Amount of rolls. </param> public SeveralDice(IDie rollValueProvider, int rollCount) : this(rollValueProvider, new FixedDie(rollCount)) { Contract.Requires(rollValueProvider != null); Contract.Requires(rollCount > 0); }
/// <summary> Takes a specified amount of untyped dice from the box. </summary> /// <param name="amountProvider">The provider of an amount of dice to take.</param> public static DiceChainSetup Take(IDie amountProvider) { Contract.Requires(amountProvider != null); return(new DiceChainSetup(amountProvider)); }
public Class1(IDie die) { this.die = die; }
public void SetUp() { _die = new D10Die(); }
public void Add(IDie die) { throw new System.NotImplementedException(); }