Exemplo n.º 1
0
    public bool Execute(CommandEnv env, Command cmd)
    {
        switch (cmd.Type)
        {
        case CmdType.AddWith:
            var v1 = env.PopNum();
            env.PushNum(v1 + cmd.GetArgNum(0));
            break;

        case CmdType.MutiWith:
            v1 = env.PopNum();
            env.PushNum(v1 * cmd.GetArgNum(0));
            break;

        case CmdType.LessWith:
            v1 = env.PopNum();
            env.PushNum(v1 < cmd.GetArgNum(0) ? 0 : 1);
            break;

        case CmdType.EqualWith:
            v1 = env.PopNum();
            env.PushNum(v1 == cmd.GetArgNum(0) ? 0 : 1);
            break;

        case CmdType.GreaterWith:
            v1 = env.PopNum();
            env.PushNum(v1 > cmd.GetArgNum(0) ? 0 : 1);
            break;

        default:
            return(false);   // 没有处理
        }

        return(true);// 已经处理
    }
Exemplo n.º 2
0
    public bool Execute(CommandEnv env, Command cmd)
    {
        switch (cmd.Type)
        {
        // 算术
        case CmdType.Add:
            var v1 = env.PopNum();
            var v2 = env.PopNum();
            env.PushNum(v1 + v2);
            break;

        case CmdType.Muti:
            v1 = env.PopNum();
            v2 = env.PopNum();
            env.PushNum(v1 * v2);
            break;

        // 逻辑
        case CmdType.Neg:
            v1 = env.PopNum();
            env.PushNum(-v1);
            break;

        case CmdType.Less:
            v2 = env.PopNum();
            v1 = env.PopNum();
            env.PushNum(v1 < v2 ? 0 : 1);
            break;

        case CmdType.Equal:
            v2 = env.PopNum();
            v1 = env.PopNum();
            env.PushNum(v1 == v2 ? 0 : 1);
            break;

        case CmdType.Greater:
            v2 = env.PopNum();
            v1 = env.PopNum();
            env.PushNum(v1 > v2 ? 0 : 1);
            break;

        case CmdType.EqualStr:
            var s2 = env.PopStr();
            var s1 = env.PopStr();
            env.PushNum(s1 == s2 ? 0 : 1);
            break;

        // 栈操作
        case CmdType.PushNum:
            env.PushNum(cmd.GetArgNum(0));
            break;

        case CmdType.PushStr:
            env.PushStr(cmd.GetArgStr(0));
            break;

        // 指令控制
        case CmdType.JMP:
            env.SetPointer((int)cmd.GetArgNum(0));
            break;

        case CmdType.JGT:
            v1 = env.PopNum();
            if (v1 > 0)
            {
                env.SetPointer((int)cmd.GetArgNum(0));
            }
            break;

        case CmdType.JEQ:
            v1 = env.PopNum();
            if (v1 == 0)
            {
                env.SetPointer((int)cmd.GetArgNum(0));
            }
            break;

        case CmdType.JLE:
            v1 = env.PopNum();
            if (v1 < 0)
            {
                env.SetPointer((int)cmd.GetArgNum(0));
            }
            break;

        case CmdType.JNE:
            v1 = env.PopNum();
            if (v1 != 0)
            {
                env.SetPointer((int)cmd.GetArgNum(0));
            }
            break;

        case CmdType.JNG:
            v1 = env.PopNum();
            if (v1 <= 0)
            {
                env.SetPointer((int)cmd.GetArgNum(0));
            }
            break;

        case CmdType.JNL:
            v1 = env.PopNum();
            if (v1 >= 0)
            {
                env.SetPointer((int)cmd.GetArgNum(0));
            }
            break;

        //
        default:
            return(false);   // 没有处理
        }

        return(true);// 已经处理
    }
Exemplo n.º 3
0
    public bool Execute(CommandEnv env, Command cmd)
    {
        targets.Clear();
        if (cmd.ActType == ActionType.Self)
        {
            targets.Add(env.Self);
        }
        else if (cmd.ActType == ActionType.Enemy)
        {
            targets.Add(env.Enemy);
        }
        else if (cmd.ActType == ActionType.Both)
        {
            targets.Add(env.Self);
            targets.Add(env.Enemy);
        }

        switch (cmd.Type)
        {
        case CmdType.IsRoundOf:
            var a    = env.Self;
            var curr = (GameMgr.Instance.CurrState as BattleState).CurrentActor;
            env.PushNum(a == curr ? 0 : 1);
            break;

        // 血、蓝改变
        case CmdType.HpChange:
            var fArg = env.PopNum();
            foreach (var tar in targets)
            {
                tar.ChangeHp(fArg);
            }
            break;

        case CmdType.EpChange:
            fArg = env.PopNum();
            foreach (var tar in targets)
            {
                tar.ChangeAp(fArg);
            }
            break;

        // buff增加和移除
        case CmdType.AddBuff:
            fArg = env.PopNum();
            foreach (var tar in targets)
            {
                tar.AddBuff((int)fArg);
            }
            break;

        case CmdType.RemoveBuff:
            fArg = env.PopNum();
            foreach (var tar in targets)
            {
                tar.RemoveBuff((int)fArg);
            }
            break;

        //
        case CmdType.PlayFx:
            var sArg = env.PopStr();
            foreach (var tar in targets)
            {
                GameMgr.Instance.FxMgr.PlayFx(sArg, tar);
            }
            break;

        case CmdType.Say:
            sArg = env.PopStr();
            foreach (var tar in targets)
            {
                UnityEngine.Debug.LogFormat("{0}:{1}", tar, sArg);
            }
            break;

        default:
            return(false);   // 没有处理
        }

        return(true);// 已经处理
    }