public PushBackAction(Entity entity, Hit hit) : base(entity) { mHit = hit; }
/// <summary> /// Initializes a new TeleportAction for an unwillful teleport caused by a hit. /// </summary> /// <param name="entity">The <see cref="Entity"/> being teleported.</param> /// <param name="distance">The maximum distance teleported.</param> public TeleportAction(Entity entity, Hit hit, int distance) : this(entity, hit, distance, false) { }
public override void Hit(Action action, Hit hit) { bool madeContact = true; // give the entity a chance to dodge if (hit.CanDodge) { // ask the defender how hard it is to hit int strike = GetDodge(); // modify it by how good this entity is at hitting // subtract so that a positive bonus is good for the attacker strike -= hit.Attack.StrikeBonus; // keep it in bounds strike = strike.Clamp(5, 95); int strikeRoll = Rng.IntInclusive(1, 100); madeContact = (strikeRoll >= strike); } // see if we hit if (madeContact) { // damage the defender hit.SetDamage(ReceiveDamage(hit.Attack)); // if damage was actually done if (hit.Damage > 0) { // only need to add the effect here if it's conditional on dodging. otherwise it's already been addded if (hit.CanDodge) { action.AddEffect(hit.CreateEffect(Position)); } Hero actingHero = Dungeon.Game.ActingEntity as Hero; bool attackerIsHero = (actingHero != null); if (Health.Current <= 0) { action.Log(LogType.Good, hit.Attacker, "{subject} kill[s] {object}.", this); // if a monster was killed by the hero, tell the hero so he can gain experience Monster killed = this as Monster; if ((killed != null) && (actingHero != null)) { actingHero.Killed(action, killed); } Die(action); } else { action.Log(LogType.Good, hit.Attacker, "{subject} " + hit.Attack.Verb + " {object} for " + hit.Damage + " damage.", this); // tell the user about the resists float resist = OnGetResistance(hit.Attack.Element); string element = hit.Attack.Element.ToString().ToLower(); if (resist < 1.0f) { action.Log(LogType.Resist, this, "{subject} resist[s] " + element + "."); } else if (resist > 1.0f) { action.Log(LogType.Resist, this, "{subject} [are|is] weak against " + element + "."); } // tell the user about the slays float slays = OnGetSlays(hit.Attack.Flags); if (slays < 1.0f) { action.Log(LogType.Resist, "The attack is ineffective on {object}.", this); } else if (slays > 4.0f) { action.Log(LogType.Resist, "The attack is deadly against {object}.", this); } else if (slays > 2.0f) { action.Log(LogType.Resist, "The attack is especially effective against {object}.", this); } else if (slays > 1.0f) { action.Log(LogType.Resist, "The attack is effective against {object}.", this); } AfterDamage(action, hit); } } else { // tell why no damage was done float resist = OnGetResistance(hit.Attack.Element); string element = hit.Attack.Element.ToString().ToLower(); float slays = OnGetSlays(hit.Attack.Flags); if (resist == 0) { action.Log(LogType.Message, this, "{subject} [are|is] immune to " + element + "."); } else if (slays == 0) { action.Log(LogType.Message, this, "{subject} [are|is] impervious to the attack."); } else { // armor absorbed all of the damage action.Log(LogType.Message, this, "{subject} [are|is] unhurt by {object}.", hit.Attacker); } } } else { // miss action.Log(LogType.Message, hit.Attacker, "{subject} miss[es] {object}.", this); } }
protected virtual bool OnStandsFirm(Hit hit) { // default to failing return(false); }
public abstract void Hit(Action action, Hit hit);