public static async Task <bool> tryAttack(this Card card, THHGame game, THHPlayer player, Card target) { if (!card.canAttack(game)) { game.logger.log(card + "无法进行攻击"); return(false); } if (!card.isAttackable(game, player, target, out var reason)) { game.logger.log(card + "无法攻击" + target + ",因为" + reason); return(false); } await game.triggers.doEvent(new AttackEventArg() { card = card, target = target }, async arg => { game.logger.log(arg.card + "攻击" + arg.target); arg.card.setAttackTimes(arg.card.getAttackTimes() + 1); if (arg.card.getAttack() > 0) { await arg.target.damage(game, arg.card, arg.card.getAttack()); } if (arg.target.getAttack() > 0) { await arg.card.damage(game, arg.target, arg.target.getAttack()); } if (arg.card.isDrain()) { await player.master.heal(game, arg.card.getAttack()); } if (arg.target.isDrain()) { await(arg.target.owner as THHPlayer).master.heal(game, arg.target.getAttack()); } if (arg.card.isPoisonous() && arg.target.owner != null) { DamageEventArg damage = game.triggers.getRecordedEvents().LastOrDefault(e => e is THHCard.DamageEventArg) as THHCard.DamageEventArg; //剧毒角色造成伤害后,对方死亡 if (damage.value > 0) { await arg.target.die(game, new DeathEventArg.Info() { card = target, player = (THHPlayer)arg.target.owner, position = player.field.indexOf(card) }); } } if (arg.target.isPoisonous() && arg.card != player.master) { DamageEventArg damage = game.triggers.getRecordedEvents().LastOrDefault(e => e is THHCard.DamageEventArg) as THHCard.DamageEventArg; if (damage.value > 0) { await arg.card.die(game, new DeathEventArg.Info() { card = card, player = player, position = player.field.indexOf(card) }); } } }); await game.updateDeath(); return(true); }
public static async Task <DamageEventArg> damage(this IEnumerable <Card> cards, THHGame game, Card source, int value) { DamageEventArg eventArg = new DamageEventArg() { cards = cards.ToArray(), source = source, value = value }; await game.triggers.doEvent(eventArg, arg => { cards = arg.cards; source = arg.source; value = arg.value; if (source != null && source.isStealth(game)) { source.setStealth(false); } if (value < 1) { arg.isCanceled = true; return(Task.CompletedTask); } foreach (Card card in cards) { if (card.isShield(game)) { game.logger.log(card + "受到伤害,失去圣盾"); card.setShield(false); } else { int damageReduce = card.getDamageReduce(game); int damage; if (damageReduce > 0) { damage = value - damageReduce; game.logger.log(card + "的伤害抵消" + damageReduce + "使伤害" + value + "=>" + damage); } else { damage = value; } if (damage > 0) { card.setCurrentLife(card.getCurrentLife(game) - damage); game.logger.log(card + "受到" + damage + "点伤害,生命值=>" + card.getCurrentLife(game)); if (source != null && source.isPoisonous(game)) { card.setDead(true); } arg.infoDic.Add(card, new DamageEventArg.Info() { damagedValue = damage, currentLife = card.getCurrentLife(game) }); } else { game.logger.log(card + "的伤害" + value + "被减伤" + damageReduce + "抵消"); } } } return(Task.CompletedTask); }); return(eventArg); }
private void Modified(object sender, DamageEventArg e) { PlayerStocks.text = e.Stocks.ToString(); PlayerPercent.text = (e.Damage * 100).ToString("N0") + " %"; }