示例#1
0
 public override void execute(TouhouCardEngine.CardEngine engine)
 {
     Thread.Sleep((int)time * 1000);
     //强制结束回合
     engine.doEvent(new TimeOutEvent(player));
     engine.turnEnd(player);
 }
示例#2
0
 public override async Task onDisable(CardEngine game, Card card, Buff buff)
 {
     for (int i = 0; i < effectList.Count; i++)
     {
         await effectList[i].onEnable(game, card, buff);
     }
 }
示例#3
0
        public override EventWitness getWitness(TouhouCardEngine.CardEngine engine, Player player)
        {
            EventWitness witness = new TimeOutWitness();

            witness.setVar("playerIndex", engine.getPlayerIndex(this.player));
            return(witness);
        }
示例#4
0
 public override void execute(TouhouCardEngine.CardEngine engine)
 {
     engine.setGem(player, player.getProp <int>("gem") - card.define.getProp <int>("cost"));
     if (card.define is ServantCardDefine || (card.define is GeneratedCardDefine && (card.define as GeneratedCardDefine).type == CardDefineType.servant))
     {
         //随从卡,将卡置入战场
         engine.summon(player, card, targetPosition);
         if (card.define.effects != null && card.define.effects.Length > 0)
         {
             Effect effect = card.define.effects.FirstOrDefault(e => { return(card.pile.name == e.pile && e.trigger == "onUse"); });
             if (effect != null)
             {
                 effect.execute(engine, player, card, targetCards);
             }
         }
     }
     else if (card.define is SpellCardDefine || (card.define is GeneratedCardDefine && (card.define as GeneratedCardDefine).type == CardDefineType.spell))
     {
         //法术卡,释放效果然后丢进墓地
         player["Hand"].moveTo(card, player["Warp"], player["Warp"].count);
         if (card.define.effects != null && card.define.effects.Length > 0)
         {
             Effect effect = card.define.effects.FirstOrDefault(e => { return(card.pile.name == e.pile && e.trigger == "onUse"); });
             if (effect != null)
             {
                 effect.execute(engine, player, card, targetCards);
             }
         }
         player["Warp"].moveTo(card, player["Grave"], player["Grave"].count);
     }
 }
 public override void execute(TouhouCardEngine.CardEngine engine)
 {
     //抽牌
     card = player["Deck"].top;
     player["Deck"].moveTo(card, player["Hand"], player["Hand"].count);
     engine.registerCard(card);
 }
 public override void execute(TouhouCardEngine.CardEngine engine)
 {
     foreach (Player player in engine.getProp <Player[]>("sortedPlayers"))
     {
         player["Init"].moveTo(player["Init"][0, player["Init"].count - 1], player["Hand"], 0);
     }
 }
 public override void execute(TouhouCardEngine.CardEngine engine)
 {
     card.setProp("attackTimes", PropertyChangeType.add, 1);
     if (card.getProp <int>("attack") > 0 && targetCard.getProp <int>("attack") > 0)
     {
         Card[] cards   = new Card[2];
         int[]  amounts = new int[2];
         if (card.id < targetCard.id)
         {
             cards[0]   = card;
             amounts[0] = targetCard.getProp <int>("attack");
             cards[1]   = targetCard;
             amounts[1] = card.getProp <int>("attack");
         }
         else
         {
             cards[0]   = targetCard;
             amounts[0] = card.getProp <int>("attack");
             cards[1]   = card;
             amounts[1] = card.getProp <int>("attack");
         }
         engine.damage(cards, amounts);
     }
     else if (card.getProp <int>("attack") > 0)
     {
         engine.damage(targetCard, card.getProp <int>("attack"));
     }
     else if (targetCard.getProp <int>("attack") > 0)
     {
         engine.damage(card, targetCard.getProp <int>("attack"));
     }
 }
        public override EventWitness getWitness(TouhouCardEngine.CardEngine engine, Player player)
        {
            EventWitness witness = new GameEndWitness();

            witness.setVar("winnerPlayersIndex", winnerPlayers.Select(p => { return(engine.getPlayerIndex(p)); }).ToArray());
            return(witness);
        }
示例#9
0
        public static T random <T>(this IEnumerable <T> e, CardEngine game)
        {
            int count = e.Count();

            if (count < 1)
            {
                return(default);
示例#10
0
        public override EventWitness getWitness(TouhouCardEngine.CardEngine engine, Player player)
        {
            EventWitness witness = new DamageWitness();

            witness.setVar("cardsRID", cards.Select(c => { return(c.id); }).ToArray());
            witness.setVar("amounts", amounts);
            return(witness);
        }
示例#11
0
 public object getProp(CardEngine game, string propName)
 {
     if (propDict.TryGetValue(propName, out object value))
     {
         return(value);
     }
     return(null);
 }
        public override EventWitness getWitness(TouhouCardEngine.CardEngine engine, Player player)
        {
            EventWitness witness = new MaxGemChangeWitness();

            witness.setVar("playerIndex", engine.getPlayerIndex(this.player));
            witness.setVar("value", this.player.getProp <int>("maxGem"));
            return(witness);
        }
        public override EventWitness getWitness(TouhouCardEngine.CardEngine engine, Player player)
        {
            EventWitness witness = new AttackWitness();

            witness.setVar("playerIndex", engine.getPlayerIndex(this.player));
            witness.setVar("cardRID", card.id);
            witness.setVar("targetCardRID", targetCard.id);
            return(witness);
        }
示例#14
0
 public T getProp <T>(CardEngine game, string propName)
 {
     if (propDict.TryGetValue(propName, out object value) && value is T t)
     {
         return(t);
     }
     else
     {
         return(default);
示例#15
0
 public void shuffle(CardEngine engine)
 {
     for (int i = 0; i < cardList.Count; i++)
     {
         int  index = engine.randomInt(i, cardList.Count - 1);
         Card card  = cardList[i];
         cardList[i]     = cardList[index];
         cardList[index] = card;
     }
 }
        public override EventWitness getWitness(TouhouCardEngine.CardEngine engine, Player player)
        {
            EventWitness witness = new SummonWitness();

            witness.setVar("playerIndex", engine.getPlayerIndex(this.player));
            witness.setVar("cardRID", card.id);
            witness.setVar("cardDID", card.define.id);
            witness.setVar("position", position);
            return(witness);
        }
示例#17
0
        public override EventWitness getWitness(TouhouCardEngine.CardEngine engine, Player player)
        {
            EventWitness witness = new UseWitness();

            witness.setVar("playerIndex", engine.getPlayerIndex(this.player));
            witness.setVar("cardRID", card.id);
            witness.setVar("cardDID", card.define.id);
            witness.setVar("targetPosition", targetPosition);
            witness.setVar("targetCardsRID", targetCards.Select(targetCard => { return(targetCard != null ? targetCard.id : -1); }).ToArray());
            return(witness);
        }
        public override EventWitness getWitness(TouhouCardEngine.CardEngine engine, Player player)
        {
            EventWitness witness = new DrawWitness();

            witness.setVar("playerIndex", engine.getPlayerIndex(this.player));
            if (player == this.player)
            {
                witness.setVar("cardDID", card.define.id);
            }
            witness.setVar("cardRID", card.id);
            return(witness);
        }
 public override void execute(TouhouCardEngine.CardEngine engine)
 {
     player.setProp("gem", value);
     if (player.getProp <int>("gem") < 0)
     {
         player.setProp("gem", 0);
     }
     else if (player.getProp <int>("gem") > 10)
     {
         player.setProp("gem", 10);
     }
 }
示例#20
0
 public static IEnumerable <T> shuffle <T>(this IEnumerable <T> enumrable, CardEngine engine)
 {
     T[] array = enumrable.ToArray();
     for (int i = 0; i < array.Length; i++)
     {
         int index = engine.randomInt(i, array.Length - 1);
         T   t     = array[i];
         array[i]     = array[index];
         array[index] = t;
     }
     return(array);
 }
示例#21
0
 public Pile getPile(CardEngine game)
 {
     for (int i = 0; i < game.playerCount; i++)
     {
         Player player = game.getPlayerAt(i);
         foreach (Pile pile in player.getPiles())
         {
             if (pile.Contains(this))
             {
                 return(pile);
             }
         }
     }
     return(null);
 }
        public override EventWitness getWitness(TouhouCardEngine.CardEngine engine, Player player)
        {
            EventWitness witness = new InitReplaceWitness();

            witness.setVar("playerIndex", engine.getPlayerIndex(this.player));
            witness.setVar("originCardsRID", originCards.Select(c => { return(c.id); }).ToArray());
            if (player == this.player)
            {
                //自己
                witness.setVar("replacedCardsDID", replacedCards.Select(c => { return(c.define.id); }).ToArray());
            }
            //其他玩家
            witness.setVar("replacedCardsRID", replacedCards.Select(c => { return(c.id); }).ToArray());
            return(witness);
        }
 public override void execute(TouhouCardEngine.CardEngine engine)
 {
     card.pile.moveTo(card, player["Field"], position);
     if (card.define is ServantCardDefine)
     {
         card.setProp("life", (card.define as ServantCardDefine).life);
         card.setProp("attack", (card.define as ServantCardDefine).attack);
         card.setProp("isReady", false);
     }
     else if (card.define is GeneratedCardDefine)
     {
         card.setProp("life", card.define.getProp <int>("life"));
         card.setProp("attack", card.define.getProp <int>("attack"));
         card.setProp("isReady", false);
     }
 }
示例#24
0
 /// <summary>
 /// 将牌堆中的一些牌与目标牌堆中随机的一些牌相替换。
 /// </summary>
 /// <param name="engine">用于提供随机功能的引擎</param>
 /// <param name="originalCards">要进行替换的卡牌</param>
 /// <param name="pile">目标牌堆</param>
 /// <returns>返回替换原有卡牌的卡牌数组,顺序与替换的顺序相同</returns>
 public async Task <Card[]> replaceByRandom(CardEngine engine, Card[] originalCards, Pile pile)
 {
     Card[] replaced = new Card[originalCards.Length];
     for (int i = 0; i < originalCards.Length; i++)
     {
         replaced[i] = pile.getCardByRandom(engine);
         await replace(engine, originalCards[i], replaced[i]);
     }
     return(replaced);
     //int[] indexArray = new int[originalCards.Length];
     //for (int i = 0; i < originalCards.Length; i++)
     //{
     //    //记录当前牌堆中的空位
     //    Card card = originalCards[i];
     //    indexArray[i] = indexOf(card);
     //    if (indexArray[i] < 0)
     //        throw new IndexOutOfRangeException(this + "中不存在" + card + "," + this + ":" + string.Join(",", cardList));
     //    //把牌放回去
     //    pile.cardList.Insert(engine.randomInt(0, pile.cardList.Count), card);
     //    foreach (IPassiveEffect effect in card.define.effects.OfType<IPassiveEffect>())
     //    {
     //        if (effect.piles.Contains(pile.name))
     //            effect.onEnable(engine, card);
     //    }
     //}
     //for (int i = 0; i < indexArray.Length; i++)
     //{
     //    //将牌堆中的随机卡片填入空位
     //    int targetIndex = engine.randomInt(0, pile.count - 1);
     //    cardList[indexArray[i]] = pile.cardList[targetIndex];
     //    Card card = cardList[indexArray[i]];
     //    foreach (IPassiveEffect effect in card.define.effects.OfType<IPassiveEffect>())
     //    {
     //        if (effect.piles.Contains(name))
     //            effect.onEnable(engine, card);
     //    }
     //    //并将其从牌堆中移除
     //    pile.cardList.RemoveAt(targetIndex);
     //    foreach (IPassiveEffect effect in card.define.effects.OfType<IPassiveEffect>())
     //    {
     //        if (effect.piles.Contains(pile.name))
     //            effect.onDisable(engine, card);
     //    }
     //}
     //return indexArray.Select(i => cardList[i]).ToArray();
 }
示例#25
0
        public override EventWitness getWitness(TouhouCardEngine.CardEngine engine, Player player)
        {
            EventWitness witness = new InitWitness();

            //双方玩家所使用的卡组主人公
            witness.setVar("masterCardsRID", engine.getPlayers().Select(p => { return(p["Master"][0].id); }).ToArray());
            witness.setVar("masterCardsDID", engine.getPlayers().Select(p => { return(p["Master"][0].define.id); }).ToArray());
            //双方玩家所使用的技能
            witness.setVar("skillCardsRID", engine.getPlayers().Select(p => { return(p["Skill"][0].id); }).ToArray());
            witness.setVar("skillCardsDID", engine.getPlayers().Select(p => { return(p["Skill"][0].define.id); }).ToArray());
            //然后是玩家的先后行动顺序
            witness.setVar("sortedPlayersIndex", engine.getProp <Player[]>("sortedPlayers").Select(p => { return(engine.getPlayerIndex(p)); }).ToArray());
            //接着是初始手牌
            witness.setVar("initCardsRID", engine.getPlayers().Select(p => { return(p["Init"].Select(c => { return c.id; }).ToArray()); }).ToArray());
            witness.setVar("initCardsDID", player["Init"].Select(e => { return(e.define.id); }).ToArray());
            //剩余卡组
            witness.setVar("deck", player["Deck"].OrderBy(c => { return(c.define.id); }).Select(c => { return(c.define.id); }).ToArray());
            return(witness);
        }
示例#26
0
        public override void execute(TouhouCardEngine.CardEngine engine)
        {
            //造成伤害
            List <Card> deathList = new List <Card>();

            for (int i = 0; i < cards.Length; i++)
            {
                if (amounts[i] > cards[i].getProp <int>("life"))
                {
                    amounts[i] = cards[i].getProp <int>("life");
                }
                cards[i].setProp("life", PropertyChangeType.add, -amounts[i]);
                if (cards[i].getProp <int>("life") <= 0)
                {
                    deathList.Add(cards[i]);
                }
            }
            if (deathList.Count > 0)
            {
                engine.doEvent(new DeathEvent(deathList.ToArray()));
            }
        }
示例#27
0
 public override void execute(TouhouCardEngine.CardEngine engine)
 {
     //玩家的最大能量加1但是不超过10,充满玩家的能量。
     engine.setProp("currentPlayer", player);
     engine.setMaxGem(player, player.getProp <int>("maxGem") + 1);
     engine.setGem(player, player.getProp <int>("maxGem"));
     //抽一张牌
     engine.draw(player);
     //使随从可以攻击
     foreach (Card card in player["Field"])
     {
         card.setProp("isReady", true);
         card.setProp("attackTimes", 0);
     }
     //开始烧绳倒计时
     //Task.Run(() =>
     //{
     //    Thread.Sleep(20000);
     //    //开始烧绳
     //    engine.doEvent(new CountDownEvent(player, 10));
     //});
 }
示例#28
0
        public override void execute(TouhouCardEngine.CardEngine engine)
        {
            //决定玩家行动顺序
            List <Player> remainedList = new List <Player>(engine.getPlayers());

            Player[] sortedPlayers = new Player[remainedList.Count];
            for (int i = 0; i < sortedPlayers.Length; i++)
            {
                int index = engine.randomInt(0, remainedList.Count - 1);
                sortedPlayers[i] = remainedList[index];
                remainedList.RemoveAt(index);
            }
            engine.setProp("sortedPlayers", sortedPlayers);
            //创建主人公和技能卡
            Card[] masterCards = sortedPlayers.Select(p => { return(p["Master"][0]); }).ToArray();
            foreach (Card card in masterCards)
            {
                card.setProp("life", 10);
                engine.registerCard(card);
            }
            Card[] skillCards = sortedPlayers.Select(p => { return(p["Skill"][0]); }).ToArray();
            foreach (Card card in skillCards)
            {
                engine.registerCard(card);
            }
            //洗牌,然后抽初始卡牌
            for (int i = 0; i < sortedPlayers.Length; i++)
            {
                if (engine.getProp <bool>("shuffle"))
                {
                    sortedPlayers[i]["Deck"].shuffle(engine);
                }
                int    count = i == 0 ? 3 : 4;
                Card[] cards = sortedPlayers[i]["Deck"][sortedPlayers[i]["Deck"].count - count, sortedPlayers[i]["Deck"].count - 1];
                sortedPlayers[i]["Deck"].moveTo(cards, sortedPlayers[i]["Init"], 0);
                engine.registerCards(cards);
            }
        }
示例#29
0
            public override void execute(CardEngine game)
            {
                //执行一个触发器
                //获取已经执行的触发器集合
                HashSet <SyncTrigger> executedTriggerSet = game.trigger.currentTask.context.getVar <HashSet <SyncTrigger> >(nameof(executedTriggerSet));

                if (executedTriggerSet == null)
                {
                    executedTriggerSet = new HashSet <SyncTrigger>();
                    game.trigger.currentTask.context.setVar(nameof(executedTriggerSet), executedTriggerSet);
                }
                //获取触发器集合
                var triggers = getTriggers(game);

                triggers = triggers.Where(trigFilter);
                bool trigFilter(SyncTrigger t)
                {
                    return(!executedTriggerSet.Contains(t) &&                    //这个触发器没有被执行过
                           (t.condition == null || t.condition.evaluate(game))); //这个触发器符合条件
                }

                triggers = triggers.OrderByDescending(t => t.getPrior != null ? t.getPrior.evaluate(game) : 0);//按照优先级升序排列
                //获取当前要执行的触发器
                var trigger = triggers.FirstOrDefault();

                if (trigger != null)
                {
                    //有的话就执行触发器内容
                    game.trigger.doTask(game.trigger.currentTask.context, trigger.actions);
                    executedTriggerSet.Add(trigger);
                }
                else
                {
                    //没有的话就退出循环
                    game.trigger.currentTask.curActionIndex = game.trigger.currentTask.actions.indexOf(this) + 1;
                }
            }
示例#30
0
 public override void execute(TouhouCardEngine.CardEngine engine)
 {
     //空事件
 }