Example #1
0
        public static async Task <bool> tryAttack(this Card card, THHGame game, Card target)
        {
            if (!card.canAttack())
            {
                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.getAttack());
                }
                if (arg.target.getAttack() > 0)
                {
                    await arg.card.damage(game, arg.target.getAttack());
                }
            });

            await game.updateDeath();

            return(true);
        }
Example #2
0
        public async Task <bool> tryUse(THHGame game, Card card, int position, params Card[] targets)
        {
            if (!card.isUsable(game, this, out _))
            {
                return(false);
            }
            card.setUsed(true);
            await setGem(game, gem - card.getCost());

            await game.triggers.doEvent(new UseEventArg()
            {
                player = this, card = card, position = position, targets = targets
            }, async arg =>
            {
                THHPlayer player = arg.player;
                card             = arg.card;
                targets          = arg.targets;
                game.logger.log(arg.player + "使用" + arg.card + (targets.Length > 0 ? ",目标:" + string.Join <Card>(",", targets) : null));
                if (arg.card.define is ServantCardDefine || (card.define is GeneratedCardDefine && (card.define as GeneratedCardDefine).type == CardDefineType.SERVANT))
                {
                    //随从卡,将卡置入战场
                    await tryPutIntoField(game, arg.player.hand, arg.card, arg.position);
                    IEffect effect = arg.card.define.getEffectOn <ActiveEventArg>(game.triggers);
                    if (effect != null)
                    {
                        ActiveEventArg active = new ActiveEventArg(player, card, targets);
                        await game.triggers.doEvent(active, activeLogic);
                        async Task activeLogic(ActiveEventArg eventArg)
                        {
                            await effect.execute(game, player, card, new object[] { eventArg }, targets);
                        }
                    }
                    //IEffect effect = arg.card.define.getEffectOn<BattleCryEventArg>(game.triggers);
                    //if (effect != null)
                    //{
                    //    await game.triggers.doEvent(new BattleCryEventArg() { player = arg.player, card = arg.card, effect = effect, targets = arg.targets }, arg2 =>
                    //    {
                    //        return arg2.effect.execute(game, arg2.player, arg2.card, new object[] { arg2 }, arg2.targets);
                    //    });
                    //}
                }
                else if (card.define is SkillCardDefine)
                {
                    IEffect effect = arg.card.define.getEffectOn <ActiveEventArg>(game.triggers);
                    await effect.execute(game, arg.player, arg.card, new object[] { new ActiveEventArg(player, card, targets) }, arg.targets);
                }
                else if (card.define is SpellCardDefine || (card.define is GeneratedCardDefine && (card.define as GeneratedCardDefine).type == CardDefineType.SPELL))
                {
                    //法术卡,释放效果然后丢进墓地
                    player.hand.remove(game, card);
                    IEffect effect = arg.card.define.getEffectOn <ActiveEventArg>(game.triggers);
                    await effect.execute(game, player, card, new object[] { new ActiveEventArg(player, card, targets) }, targets);
                    player.grave.add(game, card);
                }
            });

            await game.updateDeath();

            return(true);
        }
Example #3
0
        public static async Task <bool> tryAttack(this Card card, THHGame game, THHPlayer player, Card target)
        {
            if (!card.canAttack(game, player))
            {
                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.getAttack());
                }
                if (arg.target.getAttack() > 0)
                {
                    await arg.card.damage(game, arg.target.getAttack());
                }
            });

            await game.updateDeath();

            return(true);
        }
Example #4
0
 public Task draw(THHGame game, Card card)
 {
     if (!deck.Contains(card))
     {
         return(Task.CompletedTask);
     }
     if (hand.count >= hand.maxCount)
     {
         return(game.triggers.doEvent(new BurnEventArg()
         {
             player = this, card = card
         }, arg =>
         {
             card = arg.card;
             arg.player.deck.moveTo(game, card, arg.player.grave, arg.player.grave.count);
             game.logger.log(arg.player + "的手牌已经满了," + card + "被送入墓地");
             return Task.CompletedTask;
         }));
     }
     else
     {
         return(game.triggers.doEvent(new DrawEventArg()
         {
             player = this, card = card
         }, async arg =>
         {
             THHPlayer player = arg.player;
             card = arg.card;
             if (card.define is SpellCardDefine spell && card.getProp <bool>(game, Keyword.AUTOCAST))
             {
                 await player.deck.moveTo(game, card, player.warp);
                 await card.activeEffect(game, player, new Card[0]);
                 await player.warp.moveTo(game, card, player.grave);
                 await game.updateDeath();
             }
Example #5
0
        public Task draw(THHGame game)
        {
            if (deck.count < 1)//无牌可抽,疲劳!
            {
                return(game.triggers.doEvent(new FatigueEventArg()
                {
                    player = this
                }, onFatigue));

                async Task onFatigue(FatigueEventArg arg)
                {
                    arg.player.fatigue++;
                    game.logger.log(arg.player + "已经没有卡牌了,当前疲劳值:" + arg.player.fatigue);
                    await arg.player.master.damage(game, null, arg.player.fatigue);

                    await game.updateDeath();
                }
            }
            else
            {
                return(draw(game, deck.top));
            }
        }
Example #6
0
        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);
        }