//{ // if (attack == null) // return; // LastAttack = attack; // if (LastAttack.IsAMiss) // return; // HitPoint.Current -= LastAttack.Hit; // // Reward the team for having killed the entity // if (IsDead && attack.Striker is Hero) // { // (attack.Striker as Hero).Team.AddExperience(Reward); // } //} /// <summary> /// Make damage to the hero /// </summary> /// <param name="damage">Attack roll</param> /// <param name="type">Type of saving throw</param> /// <param name="difficulty">Difficulty</param> public void Damage(Dice damage, SavingThrowType type, int difficulty) { if (damage == null) { return; } int save = Dice.GetD20(1); // No damage if (save == 20 || save + SavingThrow(type) > difficulty) { return; } HitPoint.Current -= damage.Roll(); }
/// <summary> /// Returns the result of a saving throw /// </summary> /// <param name="type">Type of throw</param> /// <returns>Saving throw value</returns> public int SavingThrow(SavingThrowType type) { int ret = BaseSaveBonus; switch (type) { case SavingThrowType.Fortitude: ret += Constitution.Modifier; break; case SavingThrowType.Reflex: ret += Dexterity.Modifier; break; case SavingThrowType.Will: ret += Wisdom.Modifier; break; } ret += Dice.GetD20(1); return(ret); }
/// <summary> /// Constructor /// </summary> /// <param name="striker">Striker entity</param> /// <param name="Attacked">Attacked entity</param> /// <param name="item">Item used as a weapon. Use null for a hand attack</param> /// http://nwn2.wikia.com/wiki/Attack_sequence public Attack(Entity striker, Entity target, Item item) { Team team = GameScreen.Team; Time = DateTime.Now; Striker = striker; Target = target; Item = item; if (striker == null || target == null) { return; } // Ranged attack ? DungeonLocation from = null; DungeonLocation to = null; if (striker is Hero) { from = team.Location; } else { from = ((Monster)striker).Location; } if (target is Hero) { to = team.Location; } else { to = ((Monster)target).Location; } Range = (int)Math.Sqrt((from.Coordinate.Y - to.Coordinate.Y) * (from.Coordinate.Y - to.Coordinate.Y) + (from.Coordinate.X - to.Coordinate.X) * (from.Coordinate.X - to.Coordinate.X)); // Attack roll int attackdie = Dice.GetD20(1); // Critical fail ? if (attackdie == 1) { attackdie = -100000; } // Critical Hit ? if (attackdie == 20) { attackdie = 100000; } // Base attack bonus int baseattackbonus = 0; int modifier = 0; // modifier int sizemodifier = 0; // Size modifier int rangepenality = 0; // Range penality if (striker is Hero) { baseattackbonus = ((Hero)striker).BaseAttackBonus; } else if (striker is Monster) { Monster monster = striker as Monster; //sizemodifier = (int)monster.Size; } // Range penality if (RangedAttack) { modifier = striker.Dexterity.Modifier; //TODO : Add range penality } else { modifier = striker.Strength.Modifier; } // Attack bonus int attackbonus = baseattackbonus + modifier + sizemodifier + rangepenality; if (target.ArmorClass > attackdie + attackbonus) { return; } if (item != null) { Hit = item.Damage.Roll(); } else { Dice dice = new Dice(1, 4, 0); Hit = dice.Roll(); } if (IsAHit) { Target.Hit(this); } }