public KAILogic GetAILogic(int nAIType) { KAIInfo pInfo = null; KAILogic pLogic = null; if (!m_AITable.ContainsKey(nAIType)) { goto Exit0; } pInfo = m_AITable[nAIType]; if (pInfo == null) { goto Exit0; } if (pInfo.pLogic == null) { pInfo.pLogic = CreateAI(nAIType); } pLogic = pInfo.pLogic; Exit0: return(pLogic); }
public bool Setup(KCharacter pCharacter, int nAIType) { bool bResult = false; bool bRetCode = false; KAILogic pAILogic = null; int nInitState = 0; if (m_nCurrentEvent != 0) { goto Exit0; } m_pOwner = pCharacter; if (nAIType == 0) { // 清除原有AI类型 m_pAILogic = null; goto Exit1; } pAILogic = FirstFightMgr.Instance().m_AIManager.GetAILogic(nAIType); if (pAILogic == null) { //error goto Exit0; } m_nAIType = nAIType; m_pAILogic = pAILogic; nInitState = m_pAILogic.GetInitState(); bRetCode = SetState(nInitState); if (bRetCode == false) { //error goto Exit0; } m_nPrimaryTimerFrame = 0; m_nSecondaryTimerFrame = 0; m_nTertiaryTimerFrame = 0; m_nCurrentEvent = 0; FireEvent((int)KAI_EVENT.aevOnPrimaryTimer, m_pOwner.m_dwID, FirstFightMgr.Instance().m_nGameLoop); Exit1: bResult = true; Exit0: return(bResult); }
private KAILogic CreateAI(int nType) { bool bRetCode = false; KAILogic pResult = null; KAILogic pAI = null; pAI = new KAILogic(); if (pAI == null) { goto Exit0; } bRetCode = pAI.Setup(nType); if (bRetCode == false) { goto Exit0; } pResult = pAI; Exit0: return(pResult); }
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; }
public KAIState(KAILogic pAILogic) { m_pAILogic = pAILogic; }
public static void Setup(int nType, KAILogic pAI) { const int PRISONER_INIT = 100; const int PRISONER_IDLE = 20; const int PRISONER_FIGHT = 30; if (pAI == null) { return; } KAIAction pAIAction = null; KAIState pAIState = null; pAIState = pAI.NewState(PRISONER_INIT); pAIState.HandleEvent((int)KAI_EVENT.aevOnPrimaryTimer, 101); pAIAction = pAI.NewAction(101, (int)KAI_ACTION_KEY.eakRecordOriginPosition); pAIAction.SetBranch(28); pAIState = pAI.NewState(PRISONER_IDLE); pAIState.HandleEvent((int)KAI_EVENT.aevOnPrimaryTimer, 21); pAIAction = pAI.NewAction(21, (int)KAI_ACTION_KEY.eakSearchEnemy); pAIAction.SetParam(50); pAIAction.SetBranch(23, 22); pAIAction = pAI.NewAction(22, (int)KAI_ACTION_KEY.eakKeepOriginDirection); pAIAction.SetBranch(28); pAIAction = pAI.NewAction(23, (int)KAI_ACTION_KEY.eakAddTargetToThreatList); pAIAction.SetBranch(24); pAIAction = pAI.NewAction(24, (int)KAI_ACTION_KEY.eakRecordReturnPosition); pAIAction.SetBranch(31); pAIAction = pAI.NewAction(28, (int)KAI_ACTION_KEY.eakSetPrimaryTimer); pAIAction.SetParam(16); pAIAction.SetBranch(29); pAIAction = pAI.NewAction(29, (int)KAI_ACTION_KEY.eakSetState); pAIAction.SetParam(PRISONER_IDLE); pAIAction = pAI.NewAction(31, (int)KAI_ACTION_KEY.eakIsInFight); pAIAction.SetBranch(219, 41); // 选技能 pAIAction = pAI.NewAction(219, (int)KAI_ACTION_KEY.eakNpcStandardSkillSelector); pAIAction.SetBranch(1120, 998); pAIAction = pAI.NewAction(1120, (int)KAI_ACTION_KEY.eakIsTargetExist); pAIAction.SetBranch(225, 28); pAIAction = pAI.NewAction(225, (int)KAI_ACTION_KEY.eakNpcKeepSkillCastRange); pAIAction.SetBranch(230, 38); pAIAction = pAI.NewAction(230, (int)KAI_ACTION_KEY.eakStand); pAIAction.SetBranch(231); pAIAction = pAI.NewAction(231, (int)KAI_ACTION_KEY.eakNpcCastSelectSkill); pAIAction.SetBranch(755, 38); // 动画播放时间就算了 //pAIAction = pAI.NewAction(532..................................................) pAIAction = pAI.NewAction(755, (int)KAI_ACTION_KEY.eakSetPrimaryTimer); pAIAction.SetParam(8); pAIAction.SetBranch(39); pAIAction = pAI.NewAction(38, (int)KAI_ACTION_KEY.eakSetPrimaryTimer); pAIAction.SetParam(2); pAIAction.SetBranch(39); pAIAction = pAI.NewAction(39, (int)KAI_ACTION_KEY.eakSetState); pAIAction.SetParam(PRISONER_FIGHT); pAI.SetInitState(PRISONER_INIT); }