Exemple #1
0
    public void Rebuild()
    {
        m_cachedParamIndex = 0;
        m_cachedParams.Clear();

        AddParam("section", StateMachineParamTypes.Long);                    // Current animation section
        AddParam("process", StateMachineParamTypes.Long);                    // Current process
        AddParam("key", StateMachineParamTypes.Long);                        // The first valid input in current state
        AddParam("exit", StateMachineParamTypes.Bool);                       // Current animation can exit ?
        AddParam("moveBreak", StateMachineParamTypes.Bool);                  // Current animation can break by movement ?
        AddParam("moving", StateMachineParamTypes.Bool);                     // Are we in moving state ?
        AddParam("state", StateMachineParamTypes.Long);                      // Current state
        AddParam("groupMask", StateMachineParamTypes.Long);                  // Current state group mask
        AddParam("prevGroupMask", StateMachineParamTypes.Long);              // Prev state group mask
        AddParam("targetGroupMask", StateMachineParamTypes.Long);            // Target group mask after hit (target passive state)
        AddParam("targetHitGroupMask", StateMachineParamTypes.Long);         // Target group mask when hit
        AddParam("configID", StateMachineParamTypes.Long);                   // Config ID (If statemachine is player, configID is player class)
        AddParam("targetConfigID", StateMachineParamTypes.Long);             // Target config ID
        AddParam("forcePassive", StateMachineParamTypes.Long);               // Force translate passive state
        AddParam("isDead", StateMachineParamTypes.Bool);                     // Creature dead (health < 1) ?
        AddParam("realDead", StateMachineParamTypes.Bool);                   // Creature real dead (health < 1 and dead animation ended) ?
        AddParam("hit", StateMachineParamTypes.Bool);                        // Hit target ?
        AddParam("hited", StateMachineParamTypes.Long);                      // Hited by other target ?
        AddParam("frame", StateMachineParamTypes.Long);                      // Current frame
        AddParam("rage", StateMachineParamTypes.Double);                     // Current rage
        AddParam("rageRate", StateMachineParamTypes.Double);                 // Current rage rate
        AddParam("weak", StateMachineParamTypes.Bool);                       // Creature in weak state ?
        AddParam("tough", StateMachineParamTypes.Bool);                      // Creature in tough state ?
        AddParam("fatal", StateMachineParamTypes.Long);                      // Creature in other creature's fatal radius ?
        AddParam("catchState", StateMachineParamTypes.Bool);                 // Creature in catch state ?
        AddParam("passiveCatchState", StateMachineParamTypes.Bool);          // Creature in passive catch state ?
        AddParam("immuneDeath", StateMachineParamTypes.Bool);                // Immune death
        AddParam("speedRun", StateMachineParamTypes.Double);                 // Creature run speed
        AddParam("speedAttack", StateMachineParamTypes.Double);              // Creature attack speed
        AddParam("weaponItemID", StateMachineParamTypes.Long);               // Current weapon item id
        AddParam("offWeaponItemID", StateMachineParamTypes.Long);            // Current off-hand weapon item id
        AddParam("hasLaydownTime", StateMachineParamTypes.Bool);             // Current state has laydown time ?
        AddParam("nextLayDownTime", StateMachineParamTypes.Long);            // Next laydown state time
        AddParam("prevEthreal", StateMachineParamTypes.Long);                // Prev state ethreal count
        AddParam("prevPassiveEthreal", StateMachineParamTypes.Long);         // Prev state passive ethreal count
        AddParam("stateType", StateMachineParamTypes.Long);                  // Current state type   0 = normal  1 = off  2 = passive
        AddParam("loopCount", StateMachineParamTypes.Long);                  // Current loop count, first loop is 0
        AddParam("totalFrame", StateMachineParamTypes.Long);                 // Current frame count
        AddParam("freezing", StateMachineParamTypes.Bool);                   // StateMachine freezing ?
        AddParam("onGround", StateMachineParamTypes.Bool);                   // Creature on ground ?
        AddParam("morph", StateMachineParamTypes.Long);                      // Creature morph, see CreatureMorphs
        AddParam("energy", StateMachineParamTypes.Long);                     // Current energy
        AddParam("energyRate", StateMachineParamTypes.Double);               // Current energy rate

        CollectHitAndDeadEffects();
        CreateStates();
        CreateTransitions();

        currentState = states[0];
        currentState.Enter();

        onEnterState?.Invoke(null, currentState);
        onRebuild?.Invoke();
    }
Exemple #2
0
    private bool TranslateTo(StateMachineState state, int type = 0, bool checkCooldown = false, float blendTime = -1)
    {
        if (checkCooldown && state.coolingDown)
        {
            return(false);
        }

        #region Debug log

        #if (DEVELOPMENT_BUILD || UNITY_EDITOR) && DETAIL_BATTLE_LOG
        if (type != 0 && creature.isCombat)
        {
            var msg = Util.Format("[{2}:{3}-{4}], [{5}:{6}] Enter state {0} from {1}, type:{7}", state.name, currentState.name, Level.levelTime, creature.frameTime, creature.frameCount, creature.id, creature.name, type);
            if (type > 0)
            {
                Logger.LogChat(msg);
            }
            else
            {
                Logger.LogWarning(msg);
            }
        }
        #endif

        #if AI_LOG
        if (type != 0 && creature.isCombat)
        {
            Module_AI.LogBattleMsg(creature, true, "[Enter state {0} from {1}, type:{2}", state.name, currentState.name, type);
        }
        #endif
        #endregion

        FightRecordManager.RecordLog <LogStateTranslate>(l =>
        {
            l.tag          = (byte)TagType.StateTranslate;
            l.form         = currentState.name;
            l.roleId       = creature.Identify;
            l.to           = state.name;
            l.currentFrame = (ushort)currentState.currentFrame;
            l.frameCount   = (ushort)currentState.frameCount;
        }, true);

        var old = currentState;
        old.Quit();

        onQuitState?.Invoke(old, state, blendTime);

        currentState = state;
        currentState.Enter();

        onEnterState?.Invoke(old, currentState, blendTime);

        if (m_nextPendingTime > 0)
        {
            Pending(m_nextPendingTime, false, m_preventShake);
            m_nextPendingTime = 0;
        }
        else
        {
            pending = false;
        }

        return(true);
    }