예제 #1
0
        public virtual bool checkCondition(IGame game, ICard card, IBuff buff, IEventArg eventArg)
        {
            TriggerGraph trigger = triggerList.FirstOrDefault(t => t.eventName == game.triggers.getName(eventArg));

            if (trigger != null)
            {
                if (trigger.condition == null)
                {
                    return(true);
                }
                var task = game.doActionAsync(card, buff, eventArg, trigger.condition.action);
                if (task.IsCompleted)
                {
                    object[] returnValues = task.Result;
                    if (returnValues[trigger.condition.index] is bool b)
                    {
                        return(b);
                    }
                    else
                    {
                        throw new InvalidCastException(returnValues[trigger.condition.index] + "不是真值类型");
                    }
                }
                else
                {
                    throw new InvalidOperationException("不能在条件中调用需要等待的动作");
                }
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
        public virtual Task execute(IGame game, ICard card, IBuff buff, IEventArg eventArg)
        {
            TriggerGraph trigger = triggerList.FirstOrDefault(t => t.eventName == game.triggers.getName(eventArg));

            if (trigger != null)
            {
                return(game.doActionsAsync(card, buff, eventArg, trigger.action));
            }
            else
            {
                return(Task.CompletedTask);
            }
        }
예제 #3
0
        /// <summary>
        /// 检查目标卡牌是否是效果的合法目标
        /// </summary>
        /// <param name="game"></param>
        /// <param name="card">目标卡牌</param>
        /// <param name="buff"></param>
        /// <param name="eventArg"></param>
        /// <param name="invalidMsg"></param>
        /// <returns></returns>
        public virtual bool checkTarget(IGame game, ICard card, IBuff buff, IEventArg eventArg, out string invalidMsg)
        {
            TriggerGraph trigger = triggerList.FirstOrDefault(t => t.eventName == game.triggers.getName(eventArg));

            if (trigger != null)
            {
                invalidMsg = null;
                //如果触发不包含任何目标,那么目标肯定不是合法目标
                if (trigger.targetCheckerList == null || trigger.targetCheckerList.Count < 1)
                {
                    return(false);
                }
                foreach (var targetChecker in trigger.targetCheckerList)
                {
                    if (targetChecker.condition.action == null)
                    {
                        continue;
                    }
                    var task = game.doActionAsync(card, buff, eventArg, targetChecker.condition.action);
                    if (task.IsCompleted)
                    {
                        object[] returnValues = game.doActionAsync(card, buff, eventArg, targetChecker.condition.action).Result;
                        if (returnValues[targetChecker.condition.index] is bool b)
                        {
                            if (b == false)
                            {
                                //有条件没有通过,不是合法目标
                                invalidMsg = targetChecker.errorTip;
                                return(false);
                            }
                        }
                        else
                        {
                            throw new InvalidCastException(returnValues[targetChecker.condition.index] + "不是真值类型");
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException("不能在条件中调用需要等待的动作");
                    }
                }
                //有目标并且没有条件不通过或者没有条件,返回真
                return(true);
            }
            else
            {
                invalidMsg = null;
                return(false);
            }
        }
예제 #4
0
 /// <summary>
 /// 构造一个包含一个触发器的被动效果
 /// </summary>
 /// <param name="piles"></param>
 /// <param name="trigger"></param>
 public GeneratedEffect(IEnumerable <string> piles, TriggerGraph trigger) : this(piles.ToArray(), null, null, new TriggerGraph[] { trigger }, new string[0])
 {
 }