//TODO Need to add magical defense dice!! public void Defend(Enumerations.AttackDie[] die, Enumerations.DamageType damageType, ICombatant attacker) { print("Defending"); Enumerations.DefenseDie[] defendDice; if (damageType == Enumerations.DamageType.Physical) { var set = new int[6] { 0, 0, 1, 1, 2, 3 }; defendDice = new Enumerations.DefenseDie[defenceDice]; for (var i = 0; i < defenceDice; i++) { var j = set[Utilities.RollDice(1) - 1]; defendDice[i] = (Enumerations.DefenseDie)j; print("Defense die " + i + ":" + defendDice[i]); } } else if (damageType == Enumerations.DamageType.Magical) { defendDice = new Enumerations.DefenseDie[magicalDefenceDice]; for (var i = 0; i < magicalDefenceDice; i++) { defendDice[i] = (Enumerations.DefenseDie)Utilities.RollDice(1); } } else { defendDice = new Enumerations.DefenseDie[0]; } for (var i = 0; i < die.Length; i++) { if (die[i] == Enumerations.AttackDie.Hit) { for (var j = 0; j < defendDice.Length; j++) { if (defendDice[j] == Enumerations.DefenseDie.Block) { die[i] = Enumerations.AttackDie.Blank; defendDice[j] = Enumerations.DefenseDie.Fail; break; } else if (defendDice[j] == Enumerations.DefenseDie.Evade) { //play miss sound die[i] = Enumerations.AttackDie.Blank; defendDice[j] = Enumerations.DefenseDie.Fail; break; } else if (defendDice[j] == Enumerations.DefenseDie.Retaliate) { die[i] = Enumerations.AttackDie.Blank; defendDice[j] = Enumerations.DefenseDie.Fail; if (attacker != null) { attacker.TakeDamage(1); } break; //Attacker take damage. } else { TakeDamage(1); } } if (die[i] == Enumerations.AttackDie.Hit) { TakeDamage(1); } } else if (die[i] == Enumerations.AttackDie.Critical) { for (var j = 0; j < defendDice.Length; j++) { if (defendDice[j] == Enumerations.DefenseDie.Block) { die[i] = Enumerations.AttackDie.Blank; defendDice[j] = Enumerations.DefenseDie.Fail; break; } else if (defendDice[j] == Enumerations.DefenseDie.Evade) { //play miss sound die[i] = Enumerations.AttackDie.Blank; defendDice[j] = Enumerations.DefenseDie.Fail; break; } else if (defendDice[j] == Enumerations.DefenseDie.Retaliate) { die[i] = Enumerations.AttackDie.Blank; defendDice[j] = Enumerations.DefenseDie.Fail; if (attacker != null) { attacker.TakeDamage(2); } break; //Attacker take damage. } else { TakeDamage(2); } } if (die[i] == Enumerations.AttackDie.Critical) { TakeDamage(2); } } else if (die[i] == Enumerations.AttackDie.Pierce) { for (var j = 0; j < defendDice.Length; j++) { if (defendDice[j] == Enumerations.DefenseDie.Block) { die[i] = Enumerations.AttackDie.Hit; defendDice[j] = Enumerations.DefenseDie.Fail; TakeDamage(1); break; } else if (defendDice[j] == Enumerations.DefenseDie.Evade) { //play miss sound die[i] = Enumerations.AttackDie.Blank; defendDice[j] = Enumerations.DefenseDie.Fail; break; } else if (defendDice[j] == Enumerations.DefenseDie.Retaliate) { die[i] = Enumerations.AttackDie.Blank; defendDice[j] = Enumerations.DefenseDie.Fail; if (attacker != null) { attacker.TakeDamage(1); } break; //Attacker take damage. } else { TakeDamage(1); } } if (die[i] == Enumerations.AttackDie.Hit) { TakeDamage(1); } } } _hitpointsField.text = myHitpoints.ToString(); }
//Throws defense dice for the corresponding damageType. Pure is unblockable. public void Defend(Enumerations.AttackDie[] attackerDice, Enumerations.DamageType damageType, scr_CombatController attacker) { print(name + "is defending."); Enumerations.DefenseDie[] defenderDice; if (damageType == Enumerations.DamageType.Physical) { var set = new int[6] { 0, 0, 1, 1, 2, 3 }; defenderDice = new Enumerations.DefenseDie[physicalDefense]; for (var i = 0; i < physicalDefense; i++) { var j = set[Utilities.RollDice(1) - 1]; defenderDice[i] = (Enumerations.DefenseDie)j; print("Defense die " + i + ":" + defenderDice[i]); } } else if (damageType == Enumerations.DamageType.Magical) { defenderDice = new Enumerations.DefenseDie[magicalDefense]; for (var i = 0; i < magicalDefense; i++) { defenderDice[i] = (Enumerations.DefenseDie)Utilities.RollDice(1); } } else { defenderDice = new Enumerations.DefenseDie[0]; } for (var i = 0; i < attackerDice.Length; i++) { if (attackerDice[i] == Enumerations.AttackDie.Hit) { if (defenderDice.Length > i && defenderDice[i] == Enumerations.DefenseDie.Block) { } else if (defenderDice.Length > i && defenderDice[i] == Enumerations.DefenseDie.Evade) { //play miss sound } else if (defenderDice.Length > i && defenderDice[i] == Enumerations.DefenseDie.Retaliate) { if (attacker != null) { attacker.TakeDamage(1); } } else { TakeDamage(1); } } else if (attackerDice[i] == Enumerations.AttackDie.Critical) { if (defenderDice.Length > i && defenderDice[i] == Enumerations.DefenseDie.Block) { } else if (defenderDice.Length > i && defenderDice[i] == Enumerations.DefenseDie.Evade) { //play miss sound } else if (defenderDice.Length > i && defenderDice[i] == Enumerations.DefenseDie.Retaliate) { if (attacker != null) { attacker.TakeDamage(2); } } else { TakeDamage(2); } } else if (attackerDice[i] == Enumerations.AttackDie.Pierce) { if (defenderDice.Length > i && defenderDice[i] == Enumerations.DefenseDie.Block) { TakeDamage(1); } else if (defenderDice.Length > i && defenderDice[i] == Enumerations.DefenseDie.Evade) { //play miss sound } else if (defenderDice.Length > i && defenderDice[i] == Enumerations.DefenseDie.Retaliate) { if (attacker != null) { attacker.TakeDamage(1); } } else { TakeDamage(1); } } } }