/// <summary> /// 魔法/技能攻击产生伤害 /// </summary> public void CastingToHurt(Sprite obj,MagicArgs args) { //各种伤害情况判断(实际不这么写,需要真实的数值公式计算) int damage = Global.random.Next(this.MAG + args.DamageMin, this.MAG + args.DamageMax); obj.ChangeLife(-damage, ValueEffects.Decrease); //伤害后如果对象生命为0 if (obj.Life == 0) { obj.ChangeLife(0, ValueEffects.Death); obj.IsAlive = false; if (State == States.Attack) { this.Stand(); } this.Target = null; } else { //显示魔法装饰特效 if (args.SpecialEffect != SpecialEffects.None) { Animation animation = new Animation() { Code = (int)args.SpecialEffect, Coordinate = obj.Center }; EventHandler handler = null; animation.Disposed += handler = delegate { animation.Disposed -= handler; obj.RemoveTemporaryEffect(); }; obj.AddTemporaryEffect(animation); } //魔法附加效果 switch (args.AdditionalEffect) { case AdditionalEffects.Injure: obj.Injure(); break; case AdditionalEffects.Bounce: obj.BeBounce(Scene.GetGameCoordinate(args.Coordinate), 100, 500); break; case AdditionalEffects.BeKnock: obj.BeKnock(40); break; } } }
/// <summary> /// 普通攻击使对方造成伤害 /// </summary> /// <param name="obj">对方精灵</param> public void AttackToHurt(Sprite obj) { int damage = this.ATK - obj.DEF < 0 ? 0 : this.ATK - obj.DEF + Global.random.Next(-30, 30); //各种伤害情况判断(实际不这么写,需要真实的数值公式计算) if (damage == 0 || Global.random.Next(100) < obj.DEX) { obj.ChangeLife(0, ValueEffects.Failure); } else if (Global.random.Next(100) == 99) { obj.ChangeLife(-damage * 2, ValueEffects.DoubleDecrease); obj.Injure(); } else { obj.ChangeLife(-damage, ValueEffects.Decrease); } //伤害后如果对象生命为0 if (obj.Life == 0) { obj.ChangeLife(0, ValueEffects.Death); obj.IsAlive = false; this.Stand(); this.Target = null; } else { //附加被攻击特效 if (this.AttactEffect != -1) { Animation animation = new Animation() { Code = this.AttactEffect, Coordinate = obj.Center }; EventHandler handler = null; animation.Disposed += handler = delegate { animation.Disposed -= handler; obj.RemoveTemporaryEffect(); }; obj.AddTemporaryEffect(animation); } } }