proxyUtils.lua 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. local utils = {}
  2. local tSort = table.sort
  3. local mAbs = math.abs
  4. -- RS_ENEMY = 1, -- 敌人
  5. -- RS_NO = 2, -- 非敌人,没有关系
  6. -- RS_GROUP = 3, -- 同队伍
  7. -- RS_GUILD = 4, -- 同行会
  8. -- RS_CAMP = 5, -- 同阵营
  9. -- RS_ALLIANCE = 6, -- 同盟
  10. -- RS_NATION = 7, -- 国家
  11. local CHECK_ENEMY_VALUE = {
  12. -- 获取最终的actor的主人玩家actor player
  13. [0] = function( targetActor )
  14. local masterActor = nil
  15. if targetActor:IsHero() or targetActor:IsPet() or targetActor:IsHumanoid() then
  16. local tMasterID = targetActor:GetMasterID()
  17. local tMasterActor = global.actorManager:GetActor( tMasterID )
  18. if tMasterActor and targetActor:IsHumanoid() and tMasterActor:IsHero() then
  19. tMasterID = targetActor:GetMasterID()
  20. tMasterActor = global.actorManager:GetActor( tMasterID )
  21. end
  22. if tMasterActor and tMasterActor:IsPlayer() then
  23. masterActor = tMasterActor
  24. end
  25. end
  26. return masterActor or targetActor
  27. end,
  28. }
  29. local CHECK_ENEMY_FUNC = {
  30. -- 全体
  31. [global.MMO.HAM_ALL] = function( mainPlayer, targetActor )
  32. return global.MMO.RS_ENEMY
  33. end,
  34. -- 行会
  35. [global.MMO.HAM_GUILD] = function( mainPlayer, targetActor )
  36. local tMasterActor = CHECK_ENEMY_VALUE[0]( targetActor )
  37. local mGuildID = mainPlayer:GetGuildID()
  38. local tGuildID = tMasterActor and tMasterActor:GetGuildID()
  39. local GuildProxy = global.Facade:retrieveProxy( global.ProxyTable.GuildProxy )
  40. if tGuildID and tGuildID ~= "" and mGuildID and mGuildID ~= "" and (mGuildID == tGuildID or GuildProxy:isGuildAlly(tGuildID)) then
  41. return global.MMO.RS_GUILD
  42. end
  43. return global.MMO.RS_ENEMY
  44. end,
  45. -- 队伍
  46. [global.MMO.HAM_GROUP] = function( mainPlayer, targetActor )
  47. local tMasterActor = CHECK_ENEMY_VALUE[0]( targetActor )
  48. local teamProxy = global.Facade:retrieveProxy( global.ProxyTable.TeamProxy )
  49. local actorID = tMasterActor and tMasterActor:GetID()
  50. if actorID and teamProxy:IsTeamMember( actorID) then
  51. return global.MMO.RS_GROUP
  52. end
  53. return global.MMO.RS_ENEMY
  54. end,
  55. -- 阵营
  56. [global.MMO.HAM_CAMP] = function( mainPlayer, targetActor )
  57. local tMasterActor = CHECK_ENEMY_VALUE[0]( targetActor )
  58. local mFaction = mainPlayer:GetFaction()
  59. if mFaction and mFaction > 0 and mFaction == tMasterActor:GetFaction() then
  60. return global.MMO.RS_CAMP
  61. end
  62. return global.MMO.RS_ENEMY
  63. end,
  64. -- 善恶
  65. [global.MMO.HAM_SHANE] = function( mainPlayer, targetActor )
  66. local tMasterActor = CHECK_ENEMY_VALUE[0]( targetActor )
  67. local mPKLv = mainPlayer:GetPKLv()
  68. local tPKLv = tMasterActor:GetPKLv()
  69. if not mPKLv or not tPKLv then
  70. return global.MMO.RS_NO
  71. end
  72. -- 白: 0 1 红 2 灰 3
  73. -- 白可以攻击灰/红 灰可以攻击灰
  74. if ( mPKLv == 0 or mPKLv == 1 or mPKLv == 3 ) and ( tPKLv == 2 or tPKLv == 3 ) then
  75. return global.MMO.RS_ENEMY
  76. end
  77. -- 红可以攻击红
  78. if mPKLv == 2 and tPKLv == 2 then
  79. return global.MMO.RS_ENEMY
  80. end
  81. return global.MMO.RS_NO
  82. end,
  83. -- 区服
  84. [global.MMO.HAM_SERVER] = function( mainPlayer, targetActor )
  85. local tMasterActor = CHECK_ENEMY_VALUE[0]( targetActor )
  86. if mainPlayer:GetServerID() == tMasterActor:GetServerID() then
  87. return global.MMO.RS_SERVER
  88. end
  89. return global.MMO.RS_ENEMY
  90. end,
  91. -- 国家
  92. [global.MMO.HAM_NATION] = function( mainPlayer, targetActor )
  93. local mNationID = mainPlayer:GetNationID()
  94. local tMasterActor = CHECK_ENEMY_VALUE[0]( targetActor )
  95. local tNationID = nil
  96. if tMasterActor:IsPlayer() then
  97. tNationID = tMasterActor:GetNationID()
  98. elseif tMasterActor:IsMonster() and tMasterActor:IsNationEnemyPK() then
  99. tNationID = tMasterActor:GetNationID()
  100. end
  101. if mNationID and mNationID > 0 and mNationID == tNationID then
  102. return global.MMO.RS_NATION
  103. end
  104. return global.MMO.RS_ENEMY
  105. end,
  106. -- 夫妻
  107. [global.MMO.HAM_DEAR] = function( mainPlayer, targetActor )
  108. local tMasterActor = CHECK_ENEMY_VALUE[0]( targetActor )
  109. local dearID = tMasterActor and tMasterActor:GetID()
  110. if dearID and dearID ~= "" and mainPlayer:GetDearID() == dearID then
  111. return global.MMO.RS_DEAR
  112. end
  113. return global.MMO.RS_ENEMY
  114. end,
  115. -- 师徒
  116. [global.MMO.HAM_MASTER] = function( mainPlayer, targetActor )
  117. local tMasterActor = CHECK_ENEMY_VALUE[0]( targetActor )
  118. local masterID = tMasterActor and targetActor:GetID()
  119. if masterID and masterID ~= "" and mainPlayer:GetSiTuID() == masterID then
  120. return global.MMO.RS_MASTER
  121. end
  122. return global.MMO.RS_ENEMY
  123. end,
  124. -- 和平
  125. [global.MMO.HAM_PEACE] = function(mainPlayer, targetActor)
  126. local autoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
  127. if not autoProxy:IsAFKState() and not autoProxy:IsAutoFightState() then -- 非自动战斗
  128. return global.MMO.RS_ENEMY
  129. end
  130. return global.MMO.RS_NO
  131. end,
  132. }
  133. utils.checkEnemyTag = function( actor )
  134. if not actor then
  135. return global.MMO.RS_NO
  136. end
  137. -- 1. oneself
  138. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  139. if not mainPlayer or ( actor:IsPlayer() and actor:IsMainPlayer() ) then
  140. return global.MMO.RS_NO
  141. end
  142. -- 除全体模式 可以锁定自己人外 别的模式不能锁定 走game表配置 默认可锁定
  143. local pkModeLocl = global.ConstantConfig.pk_mode_lock or 0
  144. if pkModeLocl == 1 and (actor:IsPlayer() or actor:IsMonster()) then
  145. return global.MMO.RS_ENEMY
  146. end
  147. -- check pk mode
  148. local playerPropertyProxy = global.Facade:retrieveProxy( global.ProxyTable.PlayerProperty )
  149. local pkState = playerPropertyProxy:GetPKMode()
  150. if actor:IsMonster() and global.MMO.HAM_NATION ~= pkState then
  151. return global.MMO.RS_ENEMY
  152. end
  153. if actor:IsHumanoid() and global.MMO.HAM_NATION ~= pkState then
  154. return global.MMO.RS_ENEMY
  155. end
  156. if CHECK_ENEMY_FUNC[pkState] then
  157. return CHECK_ENEMY_FUNC[pkState]( mainPlayer, actor )
  158. end
  159. return global.MMO.RS_NO
  160. end
  161. utils.checkMemberByID = function( targetID )
  162. local targetActor = global.actorManager:GetActor( targetID )
  163. if nil == targetActor then
  164. return false
  165. end
  166. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  167. if not mainPlayer then
  168. return false
  169. end
  170. if targetActor:IsPlayer() then
  171. return true
  172. elseif targetActor:IsMonster() then
  173. return targetActor:IsHaveMaster()
  174. end
  175. return false
  176. end
  177. utils.checkLaunchTarget = function( targetActor )
  178. -- player & monster, only!!!!
  179. if false == targetActor:IsPlayer() and false == targetActor:IsMonster() then
  180. return false
  181. end
  182. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  183. if not mainPlayer then
  184. return false
  185. end
  186. local playerPropertyProxy = global.Facade:retrieveProxy( global.ProxyTable.PlayerProperty )
  187. local pkState = playerPropertyProxy:GetPKMode()
  188. local autoProxy = global.Facade:retrieveProxy( global.ProxyTable.Auto )
  189. if autoProxy:IsAutoFightState() then --所有模式 可以攻击自己的宝宝
  190. ---- hero player / matser is main hero
  191. local HeroPropertyProxy = global.Facade:retrieveProxy( global.ProxyTable.HeroPropertyProxy )
  192. local heroID = HeroPropertyProxy:GetRoleUID()
  193. if heroID and (targetActor:GetID() == heroID or targetActor:GetMasterID() == heroID) then
  194. return false
  195. end
  196. -- main player / matser is main player
  197. if ( targetActor:IsPlayer() and targetActor:IsMainPlayer() ) or targetActor:GetMasterID() == mainPlayer:GetID() then
  198. return false
  199. end
  200. end
  201. -- dead & born
  202. if targetActor:IsDie() or targetActor:IsDeath() or targetActor:IsBorn() or targetActor:IsCave() then
  203. return false
  204. end
  205. -- 去掉 0 血的判断, 引擎那边已经做了处理, 保证不再出现假怪该问题, 20206-7-13 sun tong
  206. -- 还是会出现 0 血攻击的情况, 加个开关
  207. -- hp 0
  208. local noCheckZeroHP = SL:GetMetaValue("GAME_DATA","no_check_zero_hp") == 1
  209. if not noCheckZeroHP and targetActor:GetHP() <= 0 then
  210. return false
  211. end
  212. -- humanoid
  213. if targetActor:IsPlayer() and targetActor:IsHumanoid() then
  214. if targetActor:GetMasterID() and utils.checkEnemyTag(targetActor) ~= 1 then --人性怪如果有MasterID, 要判断Master是否是敌友
  215. return false
  216. end
  217. return true
  218. end
  219. -- player, check is enmey
  220. if targetActor:IsPlayer() and utils.checkEnemyTag(targetActor) ~= 1 then
  221. return false
  222. end
  223. if targetActor:IsHero() and utils.checkEnemyTag(targetActor) ~= 1 then
  224. return false
  225. end
  226. if targetActor:IsMonster() and pkState == global.MMO.HAM_NATION and utils.checkEnemyTag(targetActor) ~= 1 then
  227. return false
  228. end
  229. -- 采集物
  230. if targetActor:IsCollection() then
  231. return false
  232. end
  233. return true
  234. end
  235. utils.checkLaunchTargetByID = function( targetID )
  236. local targetActor = global.actorManager:GetActor( targetID )
  237. if nil == targetActor then
  238. return false
  239. end
  240. return utils.checkLaunchTarget( targetActor )
  241. end
  242. utils.checkAutoTargetEnableByID = function( targetID )
  243. local targetActor = global.actorManager:GetActor( targetID )
  244. if nil == targetActor then
  245. return false
  246. end
  247. -- 被忽略
  248. if targetActor:IsIngored() then
  249. return false
  250. end
  251. -- 1.可攻击
  252. if false == utils.checkLaunchTargetByID(targetID) then
  253. return false
  254. end
  255. -- 2.守卫/宝宝 -- 有主人的人型怪也不打,分身等
  256. if false == targetActor:IsHero() and (true == targetActor:IsDefender() or true == targetActor:IsHaveMaster()) then
  257. return false
  258. end
  259. -- 3.归属不是自己的 且不是队友的
  260. local OwnerID = targetActor:GetOwnerID()
  261. local function checkInMyTeam(actorID)
  262. local teamProxy = global.Facade:retrieveProxy(global.ProxyTable.TeamProxy)
  263. return teamProxy:IsTeamMember(actorID)
  264. end
  265. if CHECK_SETTING(global.MMO.SETTING_IDX_NO_ATTACK_HAVE_BELONG) == 1 and OwnerID ~= "" and OwnerID ~= -1 and OwnerID ~= global.gamePlayerController:GetMainPlayerID() and not checkInMyTeam(OwnerID) then
  266. return false
  267. end
  268. --内挂忽略的怪
  269. local ignoreNames = CHECK_SETTING(global.MMO.SETTING_IDX_IGNORE_MONSTER)--
  270. local name = targetActor:GetName()
  271. if not ignoreNames or (type(ignoreNames) ~= "table") then
  272. ignoreNames = {}
  273. end
  274. if name and ignoreNames[name] then
  275. return false
  276. end
  277. return true
  278. end
  279. -- 校验 player 公会名字
  280. utils.checkPlayerGuildName = function( guildName, jobName, castlename )
  281. local ret = guildName
  282. if guildName and string.len( guildName ) > 0 then
  283. if jobName and jobName ~= "" then -- 行会职位 自定义职位名称
  284. local showJobName = string.format(GET_STRING(1086), jobName)
  285. ret = ret .. " " .. showJobName
  286. end
  287. if castlename and castlename ~= "" then -- 沙城行会
  288. ret = GET_STRING(800702) .. ret
  289. end
  290. end
  291. return ret
  292. end
  293. local CHECK_ITEM_AUTOPICK_EXTRA = function(itemIndex, bySprite)
  294. if GUIFunction and GUIFunction.CheckAutoPickItemEnable_Extra then
  295. local value = GUIFunction:CheckAutoPickItemEnable_Extra(itemIndex, bySprite == true)
  296. if type(value) == "boolean" then
  297. return value
  298. end
  299. end
  300. return true
  301. end
  302. -- 道具是否能自动拾取 isSprite:是否小精灵自动拾取
  303. function utils:AutoPickItemEnable(dropItem, mainPlayerID, isSprite)
  304. if not dropItem then
  305. return false
  306. end
  307. if not mainPlayerID then
  308. mainPlayerID = global.gamePlayerController:GetMainPlayerID()
  309. end
  310. if not mainPlayerID then
  311. return false
  312. end
  313. local actorID = dropItem:GetID()
  314. local bPick = GetActorAttr(dropItem, global.MMO.ACTOR_ATTR_PICK)
  315. if not bPick then
  316. return false
  317. end
  318. local typeIndex = (dropItem:GetTypeIndex() == 0 and 1 or dropItem:GetTypeIndex())
  319. local GameSettingProxy = global.Facade:retrieveProxy( global.ProxyTable.GameSettingProxy )
  320. local group = GameSettingProxy:GetGroupIdByIndex(typeIndex)--是否配了组别
  321. if group or typeIndex ~= 1 then--金币不判断 开关 配置了组别的需要检测
  322. if not CHECK_ITEM_AUTO_PICK(typeIndex) or not CHECK_ITEM_PICK(typeIndex) then
  323. return false
  324. end
  325. end
  326. if typeIndex ~= 1 then --不是金币 判断一下背包负重
  327. local itemData = SL:GetMetaValue("ITEM_DATA", typeIndex)
  328. if itemData.Weight then
  329. local maxbw = SL:GetMetaValue("MAXBW")
  330. local bw = SL:GetMetaValue("BW")
  331. if bw + itemData.Weight >= maxbw then
  332. return false
  333. end
  334. end
  335. end
  336. --自己丢弃的物品不要自动拾取了
  337. local BagProxy = global.Facade:retrieveProxy( global.ProxyTable.Bag )
  338. local drops = BagProxy:GetSelfDropItems()
  339. for i,v in ipairs(drops) do
  340. if v == dropItem:GetMakeIndex() then
  341. return false
  342. end
  343. end
  344. local HeroBagProxy = global.Facade:retrieveProxy( global.ProxyTable.HeroBagProxy )
  345. local drops2 = HeroBagProxy:GetSelfDropItems()
  346. for i,v in ipairs(drops2) do
  347. if v == dropItem:GetMakeIndex() then
  348. return false
  349. end
  350. end
  351. local ItemConfigProxy = global.Facade:retrieveProxy( global.ProxyTable.ItemConfigProxy )
  352. local itemData = ItemConfigProxy:GetItemDataByIndex(typeIndex)
  353. local ConditionProxy = global.Facade:retrieveProxy( global.ProxyTable.ConditionProxy )
  354. local conditionsList = string.split(itemData.pickCondition or "", "|")
  355. if not ConditionProxy:CheckCondition(conditionsList[1] or "") then
  356. return false
  357. end
  358. -- 道具能否小精灵自动拾取
  359. if isSprite then
  360. if conditionsList[2] and tonumber(conditionsList[2]) == 1 then
  361. return false
  362. end
  363. end
  364. if dropItem:CheckOwnerID( mainPlayerID ) then
  365. if not CHECK_ITEM_AUTOPICK_EXTRA(typeIndex, isSprite) then
  366. return false
  367. end
  368. return true
  369. end
  370. local teamProxy = global.Facade:retrieveProxy( global.ProxyTable.TeamProxy )
  371. if teamProxy:IsTeamMember( dropItem:GetOwnerID() ) then -- owner is not team member
  372. if not CHECK_ITEM_AUTOPICK_EXTRA(typeIndex, isSprite) then
  373. return false
  374. end
  375. return true
  376. end
  377. return false
  378. end
  379. -- 道具是否能拾取
  380. function utils:DropItemPickEnable( dropItem )
  381. if not dropItem then
  382. return false
  383. end
  384. local typeIndex = (dropItem:GetTypeIndex() == 0 and 1 or dropItem:GetTypeIndex())
  385. if not CHECK_ITEM_PICK(typeIndex) then
  386. return false
  387. end
  388. return true
  389. end
  390. utils.isDrug = function(itemIndex)
  391. for _, v in ipairs(SL:GetMetaValue("GAME_DATA","drugSHY")) do
  392. if itemIndex == v then
  393. return true,1
  394. end
  395. end
  396. for _, v in ipairs(SL:GetMetaValue("GAME_DATA","drugHY")) do
  397. if itemIndex == v then
  398. return true,2
  399. end
  400. end
  401. for _, v in ipairs(SL:GetMetaValue("GAME_DATA","drugLY")) do
  402. if itemIndex == v then
  403. return true,3
  404. end
  405. end
  406. return false
  407. end
  408. utils.isStone = function(itemIndex)
  409. for _, v in ipairs(SL:GetMetaValue("GAME_DATA","cityStone")) do
  410. if itemIndex == v then
  411. return true
  412. end
  413. end
  414. for _, v in ipairs(SL:GetMetaValue("GAME_DATA","randStone")) do
  415. if itemIndex == v then
  416. return true
  417. end
  418. end
  419. return false
  420. end
  421. utils.findItemByIndex = function(index)
  422. local bagProxy = global.Facade:retrieveProxy( global.ProxyTable.Bag )
  423. local QuickUseProxy = global.Facade:retrieveProxy( global.ProxyTable.QuickUseProxy )
  424. local itemData = QuickUseProxy:GetQucikUseDataByIndex(index)
  425. if itemData and itemData[1] then
  426. return itemData[1]
  427. end
  428. local itemData = bagProxy:GetItemDataByItemIndex(index)
  429. if itemData and itemData[1] then
  430. return itemData[1]
  431. end
  432. return nil
  433. end
  434. utils.findItemByIndex_Hero = function(index)
  435. local bagProxy = global.Facade:retrieveProxy( global.ProxyTable.HeroBagProxy )
  436. local itemData = bagProxy:GetItemDataByItemIndex(index)
  437. if itemData and itemData[1] then
  438. return itemData[1]
  439. end
  440. return nil
  441. end
  442. utils.findItemCountByIndex = function(index)
  443. local bagProxy = global.Facade:retrieveProxy( global.ProxyTable.Bag )
  444. local QuickUseProxy = global.Facade:retrieveProxy( global.ProxyTable.QuickUseProxy )
  445. local count = 0
  446. local itemData = QuickUseProxy:GetQucikUseDataByIndex(index)
  447. if itemData and itemData[1] then
  448. count = count + #itemData
  449. end
  450. local itemData = bagProxy:GetItemDataByItemIndex(index)
  451. if itemData and itemData[1] then
  452. count = count + #itemData
  453. end
  454. return count
  455. end
  456. utils.findItemCountByIndex_Hero = function(index)
  457. local bagProxy = global.Facade:retrieveProxy( global.ProxyTable.HeroBagProxy )
  458. local count = 0
  459. local itemData = bagProxy:GetItemDataByItemIndex(index)
  460. if itemData and itemData[1] then
  461. count = count + #itemData
  462. end
  463. return count
  464. end
  465. utils.findBagCountByIndex = function(index)
  466. local bagProxy = global.Facade:retrieveProxy( global.ProxyTable.Bag )
  467. local QuickUseProxy = global.Facade:retrieveProxy( global.ProxyTable.QuickUseProxy )
  468. local count = 0
  469. local itemData = bagProxy:GetItemDataByItemIndex(index)
  470. if itemData and itemData[1] then
  471. count = count + #itemData
  472. end
  473. return count
  474. end
  475. utils.unpackDrugByIndex = function(itemIndex, ignoreCount)
  476. local bagProxy = global.Facade:retrieveProxy( global.ProxyTable.Bag )
  477. local ItemUseProxy = global.Facade:retrieveProxy( global.ProxyTable.ItemUseProxy )
  478. local QuickUseProxy = global.Facade:retrieveProxy( global.ProxyTable.QuickUseProxy )
  479. local ItemConfigProxy = global.Facade:retrieveProxy( global.ProxyTable.ItemConfigProxy )
  480. -- 药品才有解包逻辑 + 回城/随机
  481. local drug,drugType = utils.isDrug(itemIndex)
  482. if not drug and not utils.isStone(itemIndex) then
  483. return false
  484. end
  485. -- 背包有,不需要解包
  486. local itemCount = utils.findItemCountByIndex(itemIndex)
  487. if itemCount >= 1 and not ignoreCount then
  488. return false
  489. end
  490. -- 没有配置药品包
  491. if #SL:GetMetaValue("GAME_DATA","allDrugPack") == 0 then
  492. return false
  493. end
  494. local PlayerProperty = global.Facade:retrieveProxy( global.ProxyTable.PlayerProperty )
  495. if not PlayerProperty then
  496. return false
  497. end
  498. if drugType == 3 then
  499. local roleLevel = PlayerProperty:GetRoleLevel()
  500. local roleJob = PlayerProperty:GetRoleJob()
  501. if roleLevel < 28 and roleJob == global.MMO.ACTOR_PLAYER_JOB_FIGHTER then
  502. return false
  503. end
  504. end
  505. -- 解包时格子数
  506. local limitCount = bagProxy:GetMaxBag() + QuickUseProxy:GetQuickUseSize()--global.MMO.QUICK_USE_SIZE
  507. local totalCount = bagProxy:GetTotalItemCount() + QuickUseProxy:GetQuickUseItemTotalCount()
  508. -- 找解包药
  509. local unpackItem = nil
  510. local unpackItemCount = nil
  511. local function findPackItem(item)
  512. if unpackItem then
  513. return
  514. end
  515. if item.AniCount == 0 then
  516. return
  517. end
  518. for k, v in pairs(SL:GetMetaValue("GAME_DATA","allDrugPack")) do
  519. if v.Shape == item.AniCount and v.Index ~= item.Index then
  520. local itemData = bagProxy:GetItemDataByItemIndex(v.Index)
  521. if itemData and itemData[1] then
  522. -- 找到可以解包了
  523. unpackItem = itemData[1]
  524. unpackItemCount = unpackItem.nUnPackCount
  525. if unpackItem.OverLap and unpackItem.OverLap > 0 then
  526. unpackItemCount = 1
  527. end
  528. else
  529. -- 未找到,继续向上套
  530. findPackItem(v)
  531. end
  532. break
  533. end
  534. end
  535. end
  536. -- 解包
  537. unpackItem = nil
  538. findPackItem(ItemConfigProxy:GetItemDataByIndex(itemIndex))
  539. if unpackItem then
  540. local calcCount = totalCount + (unpackItemCount or 1) -1
  541. if calcCount <= limitCount then
  542. ItemUseProxy:UseItem(unpackItem)
  543. print("UNPACK", unpackItem.Name)
  544. return true
  545. end
  546. end
  547. return false
  548. end
  549. utils.unpackDrugByIndex_Hero = function(itemIndex, ignoreCount,notuse)
  550. local bagProxy = global.Facade:retrieveProxy( global.ProxyTable.HeroBagProxy )
  551. local ItemUseProxy = global.Facade:retrieveProxy( global.ProxyTable.ItemUseProxy )
  552. -- local QuickUseProxy = global.Facade:retrieveProxy( global.ProxyTable.QuickUseProxy )
  553. local ItemConfigProxy = global.Facade:retrieveProxy( global.ProxyTable.ItemConfigProxy )
  554. -- 药品才有解包逻辑
  555. if not utils.isDrug(itemIndex) then
  556. return false
  557. end
  558. -- 背包有,不需要解包
  559. local itemCount = utils.findItemCountByIndex_Hero(itemIndex)
  560. if itemCount >= 1 and not ignoreCount then
  561. return false
  562. end
  563. -- 没有配置药品包
  564. if #SL:GetMetaValue("GAME_DATA","allDrugPack") == 0 then
  565. return false
  566. end
  567. -- 解包时格子数
  568. local limitCount = bagProxy:getBagMaxNum()--global.MMO.MAX_ITEM_NUMBER --+ global.MMO.QUICK_USE_SIZE
  569. local totalCount = bagProxy:GetTotalItemCount() --+ QuickUseProxy:GetQuickUseItemTotalCount()
  570. -- 找解包药
  571. local unpackItem = nil
  572. local function findPackItem(item)
  573. if unpackItem then
  574. return
  575. end
  576. if item.AniCount == 0 then
  577. return
  578. end
  579. for k, v in pairs(SL:GetMetaValue("GAME_DATA","allDrugPack")) do
  580. if v.Shape == item.AniCount then
  581. local itemData = bagProxy:GetItemDataByItemIndex(v.Index)
  582. if itemData and itemData[1] then
  583. -- 找到可以解包了
  584. unpackItem = itemData[1]
  585. else
  586. -- 未找到,继续向上套
  587. findPackItem(v)
  588. end
  589. break
  590. end
  591. end
  592. end
  593. -- 解包
  594. unpackItem = nil
  595. findPackItem(ItemConfigProxy:GetItemDataByIndex(itemIndex))
  596. if unpackItem then
  597. local calcCount = totalCount + (unpackItem.nUnPackCount or 1) -1
  598. if calcCount <= limitCount and not notuse then
  599. ItemUseProxy:HeroUseItem(unpackItem)
  600. print("UNPACK", unpackItem.Name)
  601. return true
  602. end
  603. end
  604. return false
  605. end
  606. utils.autoUnpackDrug = function()
  607. for _, v in ipairs(SL:GetMetaValue("GAME_DATA","drugSHY")) do
  608. if utils.unpackDrugByIndex(v) then
  609. return true
  610. end
  611. end
  612. for _, v in ipairs(SL:GetMetaValue("GAME_DATA","drugHY")) do
  613. if utils.unpackDrugByIndex(v) then
  614. return true
  615. end
  616. end
  617. for _, v in ipairs(SL:GetMetaValue("GAME_DATA","drugLY")) do
  618. if utils.unpackDrugByIndex(v) then
  619. return true
  620. end
  621. end
  622. return false
  623. end
  624. function utils:getFixItemDrug()
  625. local bagProxy = global.Facade:retrieveProxy( global.ProxyTable.Bag )
  626. local QuickUseProxy = global.Facade:retrieveProxy( global.ProxyTable.QuickUseProxy )
  627. for _, v in ipairs( SL:GetMetaValue("GAME_DATA","fixItemDrug") ) do
  628. local itemData = QuickUseProxy:GetQucikUseDataByIndex(v)
  629. if itemData and itemData[1] then
  630. return itemData[1]
  631. end
  632. local itemData = bagProxy:GetItemDataByItemIndex(v)
  633. if itemData and itemData[1] then
  634. return itemData[1]
  635. end
  636. end
  637. return nil
  638. end
  639. -- 是否能采集
  640. function utils:CheckCollectionEnable( collection, mainPlayer )
  641. -- 死亡
  642. if collection:IsDie() then
  643. return false
  644. end
  645. return true
  646. end
  647. -- 是否能挖肉
  648. function utils:checkDigEnable(target, mainPlayer)
  649. return GUIFunction:CheckTargetDigAble(target:GetID())
  650. end
  651. --英雄选中的目标是否能锁定
  652. function utils:checkHeroLockTargetEnable(target)
  653. return utils.checkLaunchTarget(target)
  654. end
  655. --内挂 范围内是否有足够怪物 不拾取
  656. function utils:checkIsEnoughMonster(target)
  657. local values
  658. local EnoughCount = 1
  659. local distance = 1
  660. values = GET_SETTING(global.MMO.SETTING_IDX_N_RANGE_NO_PICK,true)
  661. distance = tonumber(values[2]) or 0
  662. local enable = values[1] and values[1] == 1
  663. if not enable then
  664. return false
  665. end
  666. local mainPlayerID = global.gamePlayerController:GetMainPlayerID()
  667. return utils.checkIsEnoughEnemy(mainPlayerID,EnoughCount,distance)
  668. end
  669. --四周是否有足够的敌人
  670. utils.checkIsEnoughEnemy = function(targetID,count,distance)
  671. local targetActor = global.actorManager:GetActor( targetID )
  672. if not targetActor then
  673. return false
  674. end
  675. local enoughCount = tonumber(count) or 3
  676. local count = 0
  677. local actors, actorNums = global.actorManager:GetActors()
  678. local pMapX = targetActor:GetMapX()
  679. local pMapY = targetActor:GetMapY()
  680. distance = distance or 2 -- 多少格之内
  681. for i = 1, actorNums do
  682. local actor = actors[i]
  683. if actor then
  684. if (actor:IsPlayer() or actor:IsMonster()) and mAbs(actor:GetMapX() - pMapX) <= distance and mAbs(actor:GetMapY() - pMapY) <= distance and utils.checkLaunchTargetByID(actor:GetID()) then
  685. count = count + 1
  686. end
  687. if count >= enoughCount then
  688. return true
  689. end
  690. end
  691. end
  692. return false
  693. end
  694. --四周是否有足够的敌人(人物)
  695. utils.checkIsEnoughEnemyPlayer = function(targetID, count, distance)
  696. local targetActor = global.actorManager:GetActor( targetID )
  697. if not targetActor then
  698. return false
  699. end
  700. local enoughCount = tonumber(count) or 3
  701. local count = 0
  702. local actors, actorNums = global.playerManager:GetPlayersInCurrViewField()
  703. local pMapX = targetActor:GetMapX()
  704. local pMapY = targetActor:GetMapY()
  705. distance = distance or 2 -- 多少格之内
  706. for i = 1, actorNums do
  707. local actor = actors[i]
  708. if actor and not actor:IsHumanoid() then
  709. if actor and mAbs(actor:GetMapX() - pMapX) <= distance and mAbs(actor:GetMapY() - pMapY) <= distance and utils.checkLaunchTargetByID(actor:GetID()) then
  710. count = count + 1
  711. end
  712. if count >= enoughCount then
  713. return true
  714. end
  715. end
  716. end
  717. return false
  718. end
  719. --四周是否有足够的红名
  720. utils.checkIsEnoughRedNameEnemy = function(targetID,count,distance)
  721. local targetActor = global.actorManager:GetActor( targetID )
  722. if not targetActor then
  723. return false
  724. end
  725. local enoughCount = tonumber(count) or 3
  726. local count = 0
  727. local actors, actorNums = global.playerManager:GetPlayersInCurrViewField()
  728. local pMapX = targetActor:GetMapX()
  729. local pMapY = targetActor:GetMapY()
  730. distance = distance or 2 -- 多少格之内
  731. for i = 1, actorNums do
  732. local actor = actors[i]
  733. if actor then
  734. if actor and mAbs(actor:GetMapX() - pMapX) <= distance and mAbs(actor:GetMapY() - pMapY) <= distance and utils.checkLaunchTargetByID(actor:GetID()) and actor:GetPKLv() == 2 then
  735. count = count + 1
  736. end
  737. if count >= enoughCount then
  738. return true
  739. end
  740. end
  741. end
  742. return false
  743. end
  744. --人物是否需要放弃自动拾取
  745. utils.checkIsPlayerAbandonPickup = function()
  746. local PickupSpriteProxy = global.Facade:retrieveProxy( global.ProxyTable.PickupSpriteProxy )
  747. if not PickupSpriteProxy or not PickupSpriteProxy:getPickupSpriteState() then
  748. return false
  749. end
  750. local mode = PickupSpriteProxy:getPickSpriteMode()
  751. if mode == 0 or mode == 1 then
  752. return false
  753. end
  754. return true --模式 2 3 是一个个拾取 需要放弃
  755. end
  756. return utils