Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取事件对应的动画
        /// </summary>
        /// <param name="eventArg"></param>
        /// <returns></returns>
        public UIAnimation getEventAnim(IEventArg eventArg)
        {
            Type type = eventArg.GetType();

            if (animConstructorDic.ContainsKey(type))
            {
                UIAnimation anim = null;
                if (animConstructorDic[type].GetParameters().Length == 0)
                {
                    anim = animConstructorDic[type].Invoke(new object[0]) as UIAnimation;
                }
                else if (animConstructorDic[type].GetParameters().Length == 1)
                {
                    anim = animConstructorDic[type].Invoke(new object[] { eventArg }) as UIAnimation;
                }
                if (anim is EventAnimation tAnim)
                {
                    tAnim.eventArg = eventArg;
                    tAnim.init(this);
                }
                return(anim);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        public override Task <object[]> execute(IGame game, ICard card, IBuff buff, IEventArg eventArg, object[] args, object[] constValues)
        {
            LogicOperator op = (LogicOperator)constValues[0];

            switch (op)
            {
            case LogicOperator.not:
                return(Task.FromResult(new object[] { !(bool)args[0] }));

            case LogicOperator.and:
                foreach (var value in args.Cast <bool>())
                {
                    if (value == false)
                    {
                        return(Task.FromResult(new object[] { false }));
                    }
                }
                return(Task.FromResult(new object[] { true }));

            case LogicOperator.or:
                foreach (var value in args.Cast <bool>())
                {
                    if (value == true)
                    {
                        return(Task.FromResult(new object[] { true }));
                    }
                }
                return(Task.FromResult(new object[] { false }));

            default:
                throw new InvalidOperationException("未知的操作符" + op);
            }
        }
Exemplo n.º 4
0
        public static string getName(IEventArg eventArg)
        {
            string name = eventArg.GetType().Name;

            if (name.EndsWith("EventArg"))
            {
                name = string.Intern(name.Substring(0, name.Length - 3));
            }
            return(name);
        }
Exemplo n.º 5
0
 public static void getParentEventTest(ITriggerManager manager, IEventArg e1, IEventArg e2, IEventArg e3)
 {
     _ = manager.doEvent(e1, arg =>
     {
         _ = manager.doEvent(e2);
         _ = manager.doEvent(e3);
         return(Task.CompletedTask);
     });
     Assert.AreEqual(e1, e2.parent);
     Assert.AreEqual(e1, e3.parent);
 }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
0
        public override Task <object[]> execute(IGame game, ICard card, IBuff buff, IEventArg eventArg, object[] args, object[] constValues)
        {
            CompareOperator op = (CompareOperator)constValues[0];

            switch (op)
            {
            case CompareOperator.equals:
                return(Task.FromResult(new object[] { args[0] == args[1] }));

            case CompareOperator.unequals:
                return(Task.FromResult(new object[] { args[0] != args[1] }));

            default:
                throw new InvalidOperationException("未知的操作符" + op);
            }
        }
Exemplo n.º 9
0
        public override Task <object[]> execute(IGame game, ICard card, IBuff buff, IEventArg eventArg, object[] args, object[] constValues)
        {
            IntegerOperator op = (IntegerOperator)constValues[0];

            switch (op)
            {
            case IntegerOperator.add:
                return(Task.FromResult(new object[] { ((int[])args[0]).Sum(a => a) }));

            case IntegerOperator.sub:
                int[] numbers = (int[])args[0];
                int   result  = numbers[0];
                for (int i = 1; i < numbers.Length; i++)
                {
                    result -= numbers[i];
                }
                return(Task.FromResult(new object[] { result }));

            case IntegerOperator.mul:
                numbers = (int[])args[0];
                result  = 1;
                for (int i = 0; i < numbers.Length; i++)
                {
                    result *= numbers[i];
                }
                return(Task.FromResult(new object[] { result }));

            case IntegerOperator.div:
                numbers = (int[])args[0];
                result  = numbers[0];
                for (int i = 1; i < numbers.Length; i++)
                {
                    result /= numbers[i];
                }
                return(Task.FromResult(new object[] { result }));

            default:
                throw new InvalidOperationException("未知的操作符" + op);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 事件前处理
        /// </summary>
        /// <param name="arg"></param>
        private void onEventBefore(IEventArg arg)
        {
            UIAnimation anim;

            switch (arg)
            {
            case TouhouCardEngine.Card.AddModiEventArg addMod:
                anim = new AddModiAnim()
                {
                    eventArg = addMod
                };
                break;

            default:
                anim = getEventAnim(arg);
                break;
            }
            if (anim != null)
            {
                addAnim(anim);
            }
        }
Exemplo n.º 11
0
        private void onEventBefore(IEventArg arg)
        {
            switch (arg)
            {
            case THHPlayer.MoveEventArg move:
                _animationQueue.Add(new MoveServantAnimation(move));
                break;

            //case THHPlayer.CreateTokenEventArg createToken:
            //    _animationQueue.Add(new CreateTokenAnimation(createToken));
            //    break;
            case THHCard.AttackEventArg attack:
                _animationQueue.Add(new AttackServantAnimation(attack));
                break;

            case THHCard.DeathEventArg death:
                _animationQueue.Add(new DeathAnimation(death));
                break;

            default:
                //game.logger?.log("UI", "被忽略的事件结束:" + obj);
                break;
            }
        }
Exemplo n.º 12
0
 private void onEventAfter(IEventArg arg)
 {
 }
Exemplo n.º 13
0
 public void addChildEvent(IEventArg eventArg)
 {
     childEventList.Add(eventArg);
 }
Exemplo n.º 14
0
 public string getNameBefore(IEventArg eventArg)
 {
     return(getNameBefore(getName(eventArg)));
 }
Exemplo n.º 15
0
 public string getNameAfter(IEventArg eventArg)
 {
     return(getNameAfter(getName(eventArg)));
 }
Exemplo n.º 16
0
        private void onEventBefore(IEventArg arg)
        {
            switch (arg)
            {
            case THHGame.InitEventArg init:
                _animationQueue.Add(new InitAnimation(init));
                break;

            case THHPlayer.InitReplaceEventArg initReplace:
                _animationQueue.Add(new InitReplaceAnimation(initReplace));
                break;

            case THHGame.StartEventArg start:
                _animationQueue.Add(new StartAnimation(start));
                break;

            case THHGame.TurnStartEventArg turnStart:
                _animationQueue.Add(new TurnStartAnimation(turnStart));
                break;

            case THHPlayer.DrawEventArg draw:
                _animationQueue.Add(new DrawAnimation(draw));
                break;

            case THHPlayer.SetGemEventArg setGem:
                _animationQueue.Add(new SetGemAnimation(setGem));
                break;

            case THHPlayer.SetMaxGemEventArg setMaxGem:
                _animationQueue.Add(new SetMaxGemAnimation(setMaxGem));
                break;

            case THHPlayer.MoveEventArg move:
                _animationQueue.Add(new MoveServantAnimation(move));
                break;

            case THHPlayer.UseEventArg use:
                if (use.card.define.type == CardDefineType.SERVANT)
                {
                    _animationQueue.Add(new UseServantAnimation(use));
                }
                else if (use.card.define.type == CardDefineType.SPELL)
                {
                    _animationQueue.Add(new UseSpellAnimation(use));
                }
                break;

            case THHCard.HealEventArg heal:
                _animationQueue.Add(new HealAnimation(heal));
                break;

            //case THHPlayer.CreateTokenEventArg createToken:
            //    _animationQueue.Add(new CreateTokenAnimation(createToken));
            //    break;
            case THHCard.AttackEventArg attack:
                _animationQueue.Add(new ServantAttackAnimation(attack));
                break;

            case THHCard.DamageEventArg damage:
                _animationQueue.Add(new DamageAnimation(damage));
                break;

            case THHCard.DeathEventArg death:
                _animationQueue.Add(new DeathAnimation(death));
                break;

            case THHPlayer.ActiveEventArg active:
                foreach (var target in active.targets)
                {
                    if (target is TouhouCardEngine.Card card)
                    {
                        _animationQueue.Add(new SelectTargetAnimation(active));
                    }
                }
                break;

            case THHGame.TurnEndEventArg turnEnd:
                _animationQueue.Add(new TurnEndAnimation(turnEnd));
                break;

            case THHGame.GameEndEventArg gameEnd:
                _animationQueue.Add(new GameEndAnimation(gameEnd));
                break;

            default:
                game.logger?.log("UI", "没有动画的事件:" + arg);
                break;
            }
        }
Exemplo n.º 17
0
 public string getName(IEventArg eventArg)
 {
     return(getName(eventArg.GetType()));
 }
Exemplo n.º 18
0
		/// <summary>
		/// Initializes a new instance of the <see cref="EventArgs"/> class.
		/// </summary>
		/// <param name="descriptor">The descriptor.</param>
		/// <param name="native">The native.</param>
		protected EventArgs(EventArgDescriptor descriptor, IEventArg native)
			: this(native)
		{
			Native.SetOwner(this);
			Initialize(descriptor);
		}
Exemplo n.º 19
0
 public static string getNameAfter(IEventArg eventArg)
 {
     return(string.Intern("After" + getName(eventArg)));
 }
Exemplo n.º 20
0
 public abstract Task <object[]> execute(IGame game, ICard card, IBuff buff, IEventArg eventArg, object[] args, object[] constValues);
 public string getName(IEventArg eventArg)
 {
     return(eventArg.GetType().FullName);
 }
Exemplo n.º 22
0
 public static string getNameBefore(IEventArg eventArg)
 {
     return(string.Intern("Before" + getName(eventArg)));
 }
Exemplo n.º 23
0
 public override Task <object[]> execute(IGame game, ICard card, IBuff buff, IEventArg eventArg, object[] args, object[] constValues)
 {
     return(Task.FromResult(constValues));
 }
Exemplo n.º 24
0
        public override async Task <object[]> execute(IGame game, ICard card, IBuff buff, IEventArg eventArg, object[] args, object[] constValues)
        {
            object[] paramters  = new object[_paramsInfo.Length];
            int      argIndex   = 0;
            int      constIndex = 0;

            for (int i = 0; i < _paramsInfo.Length; i++)
            {
                var paramInfo = _paramsInfo[i];
                if (paramInfo.IsOut)
                {
                    //out参数输出留空
                    paramters[i] = null;
                }
                else if (paramInfo.GetCustomAttribute <ActionNodeParamAttribute>() is ActionNodeParamAttribute attribute)
                {
                    //指定了不能省略的参数
                    if (attribute.isConst)
                    {
                        paramters[i] = constValues[constIndex];
                        constIndex++;
                    }
                    else
                    {
                        paramters[i] = args[argIndex];
                        argIndex++;
                    }
                }
                else
                {
                    if (typeof(IGame).IsAssignableFrom(paramInfo.ParameterType))
                    {
                        paramters[i] = game;
                    }
                    else if (typeof(ICard).IsAssignableFrom(paramInfo.ParameterType))
                    {
                        //可以省略的Card
                        paramters[i] = card;
                    }
                    else if (typeof(IBuff).IsAssignableFrom(paramInfo.ParameterType))
                    {
                        //可以省略的Buff
                        paramters[i] = buff;
                    }
                    else if (typeof(IEventArg).IsAssignableFrom(paramInfo.ParameterType))
                    {
                        //可以省略的EventArg
                        paramters[i] = eventArg;
                    }
                    else
                    {
                        //不是可以省略的类型
                        paramters[i] = args[argIndex];
                        argIndex++;
                    }
                }
            }
            object returnValue = _methodInfo.Invoke(null, paramters);

            if (returnValue is Task task)
            {
                await task;
                //返回Task则视为返回null,返回Task<T>则返回对应值
                if (task.GetType().GetProperty(nameof(Task <object> .Result)) is PropertyInfo propInfo)
                {
                    return(new object[] { propInfo.GetValue(task) });
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                //不是Task,返回由返回值和out参数组成的数组
                List <object> outputList = new List <object>
                {
                    returnValue
                };
                for (int i = 0; i < _paramsInfo.Length; i++)
                {
                    var paramInfo = _paramsInfo[i];
                    if (paramInfo.IsOut)
                    {
                        outputList.Add(paramters[i]);
                    }
                }
                return(outputList.ToArray());
            }
        }