Пример #1
0
    public KAIActionHandle GetEventHandler(int nEvent)
    {
        KAIActionHandle pResult = new KAIActionHandle();

        pResult.nAIActionID = KAIAction.KAI_ACTION_ID_NONE;
        pResult.pAIAction   = null;

        for (int i = 0; i < m_EventHandleVector.Count; i++)
        {
            if (m_EventHandleVector[i].nEvent == nEvent)
            {
                if (m_EventHandleVector[i].ActionKey.pAIAction == null)
                {
                    KAIAction pAction = null;

                    pAction = m_pAILogic.GetAction(m_EventHandleVector[i].ActionKey.nAIActionID);
                    if (pAction == null)
                    {
                        //error
                        return(null);
                    }

                    m_EventHandleVector[i].ActionKey.pAIAction = pAction;
                }
                pResult = m_EventHandleVector[i].ActionKey;
                break;
            }
        }


        return(pResult);
    }
Пример #2
0
    public void FireEvent(int nEvent, uint dwEventSrc, uint nEventParam)
    {
        int nEventBlock = m_nCurrentEvent;
        int nCallCount  = 0;

        KAIActionHandle pActionKey = null;

        if (m_pAILogic == null)
        {
            goto Exit0;
        }

        if (m_pOwner == null)
        {
            goto Exit0;
        }

        if (m_pState == null)
        {
            goto Exit0;
        }

        // 触发的事件预先判断在当前状态是否有托管
        pActionKey = m_pState.GetEventHandler(nEvent);
        if (pActionKey == null)
        {
            goto Exit0;
        }

        if (pActionKey.nAIActionID == KAIAction.KAI_ACTION_ID_NONE)
        {
            goto Exit1;
        }

        if (nEventBlock != (int)KAI_EVENT.aevInvalid)
        {
            // 重复事件替代
            if (m_nPendingEvent == (int)KAI_EVENT.aevInvalid || m_nPendingEvent == nEvent)
            {
                m_nPendingEvent      = nEvent;
                m_dwPendingEventSrc  = dwEventSrc;
                m_nPendingEventParam = nEventParam;
            }
            goto Exit0;
        }

        m_nCurrentEvent = nEventBlock;


        while (pActionKey.nAIActionID != KAIAction.KAI_ACTION_ID_NONE)
        {
            KAIActionHandle pNextActionKey = null;
            if (nCallCount > MAX_ACTION_CALL)
            {
                // 死循环检测
                break;
            }

            pNextActionKey = m_pAILogic.CallAction(m_pOwner, pActionKey);
            if (pNextActionKey.nAIActionID == KAIAction.KAI_ACTION_ID_ERROR)
            {
                m_pAILogic = null;  // 出错的时候就把AI清掉.
                break;
            }

            pActionKey  = pNextActionKey;
            m_nActionID = pActionKey.nAIActionID;
            nCallCount++;
        }


Exit1:
Exit0:
        m_nCurrentEvent = nEventBlock;

        return;
    }
Пример #3
0
    public KAIActionHandle CallAction(KCharacter pCharacter, KAIActionHandle pActionKey)
    {
        KAIActionHandle pResult     = new KAIActionHandle();
        KAIActionHandle pNextAction = new KAIActionHandle();

        KAIAction pAction    = pActionKey.pAIAction;
        int       nActionKey = 0;

        if (pAction == null)
        {
            pAction = GetAction(pActionKey.nAIActionID);
        }

        if (pAction == null)
        {
            //error
            goto Exit0;
        }

        nActionKey = pAction.m_nKey;

        if (nActionKey < KAIAction.KAI_USER_ACTION)
        {
            int   nBranchIndex    = 0;
            ulong ulPrevTickCount = 0;
            ulong ulPostTickCount = 0;
            KAIManager.KAI_ACTION_FUNC PAction = null;

            PAction = FirstFightMgr.Instance().m_AIManager.GetActionFunction(nActionKey);
            if (PAction == null)
            {
                //error
                goto Exit0;
            }


            nBranchIndex = PAction(pCharacter, pAction);

            if (nBranchIndex > 0 && nBranchIndex <= KAIAction.KAI_ACTION_BRANCH_NUM)
            {
                int       nNextActionID   = pAction.m_nBranch[nBranchIndex - 1];
                KAIAction pNextActionTemp = pAction.m_pBranch[nBranchIndex - 1];

                if (pNextActionTemp == null)
                {
                    pNextActionTemp = GetAction(nNextActionID);
                    pAction.m_pBranch[nBranchIndex - 1] = pNextActionTemp;
                }
                pNextAction.nAIActionID = nNextActionID;
                pNextAction.pAIAction   = pNextActionTemp;
            }
            if (nBranchIndex == -1)
            {
                pNextAction.nAIActionID = KAIAction.KAI_ACTION_ID_NONE;
                pNextAction.pAIAction   = null;
            }
        }
        else
        {
            // 没做
            //error
        }


        pResult = pNextAction;
Exit0:
        return(pResult);
    }