Exemple #1
0
 protected StateMachine()
 {
     for (var i = 0; i < MAX_PARAMS_COUNT; ++i)
     {
         m_parameters[i] = new StateMachineParam();
     }
 }
Exemple #2
0
    private TransitionInfo.Condition CheckConditions(TransitionInfo.Condition[] conditions, int s, int e, ref int paramIdx, ref StateMachineParam param)
    {
        for (int i = s; i < e; ++i) // Check item requirement
        {
            var c = conditions[i];

            var idx = m_paramIndex[i];
            if (idx != paramIdx)
            {
                param    = stateMachine.GetParam(idx);
                paramIdx = idx;
            }

            var check = c.isKey ? CheckKeyCondition(c, (int)param.longValue) : CheckCondition(c, param.longValue, param.doubleValue, param.boolValue);;
            if (!check)
            {
                return(c);
            }
        }
        return(null);
    }
Exemple #3
0
    /// <summary>
    /// Check current state transition
    /// </summary>
    /// <param name="now">Current state</param>
    /// <returns>High 8 bit: mask Low 8 bit: TransitionCheckResults</returns>
    public int Check(StateMachineState now)
    {
        if (!m_hasKeyCondition && stateMachine.keyIndex > 0)
        {
            return(FAILED);
        }

        forceTurn = false;

        if (target.level == 0 ||                                                         // state locked
            info.hasExitTime && !now.ended ||                                            // exit time check
            info.noSelfTransition && target == now ||                                    // self transition check
            !info.noExitCondition && !stateMachine.GetBool(StateMachineParam.exit) ||    // exit frame check
            !info.noDeadCondition && stateMachine.GetBool(StateMachineParam.isDead) ||   // dead check
            !info.noFreezCondition && stateMachine.freezing ||                           // freezing state check
            m_dismissKeyCondition && stateMachine.GetLong(StateMachineParam.process) > 1 // ignore key transition check
            )
        {
            return(FAILED);
        }

        var cool = target.coolingDown;

        if (!m_hasKeyCondition && cool)
        {
            return(FAILED);                            // pre cooldown check
        }
        var infoResult = m_hasKeyCondition && stateMachine.keyIsFirstCheck;

        var cs                  = info.conditions;
        var paramIdx            = -1;
        StateMachineParam param = null;

        TransitionInfo.Condition failed = null;

        failed = CheckConditions(cs, 0, info.itemConditionEnd, ref paramIdx, ref param); // Check group and item requirement
        if (failed != null)
        {
            return(FAILED);
        }

        failed = CheckConditions(cs, info.itemConditionEnd, info.keyConditionEnd, ref paramIdx, ref param);   // Check key condition
        if (failed != null)
        {
            return(FAILED);
        }

        if (cool)
        {
            return(infoResult ? SPELL_COOLING_DOWN : FAILED);
        }

        failed = CheckConditions(cs, info.keyConditionEnd, cs.Length, ref paramIdx, ref param);

        if (failed != null)
        {
            return(infoResult ? failed.isRage && rageCost > 0 || failed.isRageRate && rageRateCost > 0 ? NOT_ENOUGH_RAGE : failed.isEnergy && energyCost > 0 || failed.isEnergyRate && energyRateCost > 0 ? NOT_ENOUGH_ENERGY : info.forceUIResult != 0 ? info.forceUIResult : FAILED : FAILED);
        }

        var trace = target.info.trackDistance * 0.1; // dm -> m

        if (trace > 0)
        {
            var c   = stateMachine.creature;
            var tar = Util.SelectNearestTarget(c, trace, true);
            if (!tar)
            {
                return(info.forceUIResult != 0 ? info.forceUIResult : FAILED);
            }
            else
            {
                if (!c.TargetInFront(tar))
                {
                    c.TurnBack();
                }

                c.position_ = tar.position_;
            }
        }

        return(info.preventInputReset ? (1 << 8) : PASSED);
    }