AutoFindNPCCommand.lua 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. local AutoFindNPCCommand = class('AutoFindNPCCommand', framework.SimpleCommand)
  2. function AutoFindNPCCommand:ctor()
  3. end
  4. function AutoFindNPCCommand:execute(notification)
  5. local facade = global.Facade
  6. local autoProxy = facade:retrieveProxy( global.ProxyTable.Auto )
  7. local targetIndex = autoProxy:GetTargetIndex()
  8. local targetNpc = nil
  9. local npcVec, ncount = global.npcManager:GetNpcInCurrViewField()
  10. for i = 1, ncount do
  11. local npc = npcVec[i]
  12. if npc then
  13. if type(targetIndex) == "number" then
  14. if npc:GetTypeIndex() == targetIndex then
  15. targetNpc = npc
  16. break
  17. end
  18. elseif type(targetIndex) == "table" then
  19. for j = 1, #targetIndex do
  20. local index = targetIndex[j]
  21. if index and index == npc:GetTypeIndex() then
  22. targetNpc = npc
  23. break
  24. end
  25. end
  26. end
  27. end
  28. end
  29. if not targetNpc then
  30. return false
  31. end
  32. local NPCProxy = facade:retrieveProxy( global.ProxyTable.NPC )
  33. NPCProxy:CheckTalk( targetNpc:GetID(), true )
  34. -- input idle
  35. facade:sendNotification(global.NoticeTable.ClearAllInputState)
  36. facade:sendNotification(global.NoticeTable.ClearAllAutoState)
  37. facade:sendNotification(global.NoticeTable.InputIdle)
  38. autoProxy:ClearAFKState()
  39. autoProxy:ClearAllState()
  40. autoProxy:ClearPickState()
  41. end
  42. return AutoFindNPCCommand