public void Execute(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (npc.GetAIEnable()) { NpcAiStateInfo npcAi = npc.GetAiStateInfo(); if (npcAi.CommandQueue.Count <= 0) { int curState = npcAi.CurState; if (curState > (int)AiStateId.Invalid && curState < (int)AiStateId.MaxNum) { NpcAiStateHandler handler; if (m_Handlers.TryGetValue(curState, out handler)) { if (null != handler) { handler(npc, aiCmdDispatcher, deltaTime); } } else { LogSystem.Error("Illegal ai state: " + curState + " npc:" + npc.GetId()); } } else { OnStateLogicInit(npc, aiCmdDispatcher, deltaTime); ChangeToState(npc, (int)AiStateId.Idle); } } ExecuteCommandQueue(npc, deltaTime); } }
public void UpdateTarget(NpcInfo npc) { if (npc.GetAIEnable()) { NpcAiStateInfo npcAi = npc.GetAiStateInfo(); long curTime = TimeUtility.GetServerMilliseconds(); if (npcAi.Target > 0) { if (curTime > npcAi.LastChangeTargetTime + m_ChangeTargetCD && curTime > npc.GetCombatStatisticInfo().LastHitTime + m_MaxChaseTime) { npcAi.Target = 0; NotifyNpcTargetChange(npc); npcAi.LastChangeTargetTime = curTime; LogSystem.Debug("Npc {0} changed target", npc.GetId()); } } } }