ZhanbuLogic.lua 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. local ZhanbuExcel = require("excel.zhanbu")
  2. local Msg = require("core.Msg")
  3. local BagLogic = require("bag.BagLogic")
  4. local HeroGrid = require("hero.HeroGrid")
  5. local Util = require("common.Util")
  6. local ObjHuman = require("core.ObjHuman")
  7. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  8. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  9. local Lang = require("common.Lang")
  10. local Broadcast = require("broadcast.Broadcast")
  11. local SysParameter = require("common.SysParameter")
  12. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  13. local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
  14. local HeroExcel = require("excel.hero")
  15. local HeroBook = require("hero.HeroBook")
  16. local DropExchangeLogic = require("absAct.DropExchangeLogic")
  17. local HeroGrowUp = require("absAct.HeroGrowUp")
  18. local MengxinLogic = require("present.MengxinLogic")
  19. local AbsZhanbuLunpanLogic = require("absAct.AbsZhanbuLunpanLogic")
  20. local YunYingLogic = require("yunying.YunYingLogic")
  21. local TalismanLogic = require("talisman.TalismanLogic")
  22. local RecommendLineup = require("drawCard.RecommendLineup")
  23. --[[
  24. pool ����
  25. hand ����
  26. handCnt ��������
  27. money ӵ�е�������
  28. lv ���صȼ�
  29. refreshCnt ˢ�´���
  30. ts ���߻ظ���ʱ
  31. isGuide �Ƿ���������
  32. handMaxCnt ���Ƹ���
  33. heartHero ����Ӣ��
  34. ]]
  35. local CARD_POOL_MAX_CNT = 5 -- ����Ӣ������
  36. local AUTO_GET_MONEY_MAX = 99 -- �Զ��ظ�����������
  37. local CARD_POOL_REFRESH = 2 -- ˢ�¿������������
  38. local AUTO_GET_MONEY_TS = 300 -- �Զ��ظ�����ʱ��
  39. CARD_POOL = CARD_POOL or {}
  40. --初始时hand拥有的数量
  41. local INITIALHANDCNT = 4
  42. --hand最大拥有的数量
  43. local MAXHANDCNT = 7
  44. --获取来自秘宝的加成
  45. local function getTalismanAdd(human, addType)
  46. local addValue = TalismanLogic.getTalismanAdd(human, addType) or 0
  47. return addValue
  48. end
  49. local function getHandInfo(human)
  50. local isUnlock = false
  51. local extraPosList = {}
  52. local realyHandCnt = INITIALHANDCNT
  53. for i=INITIALHANDCNT+1, MAXHANDCNT do
  54. isUnlock = false
  55. if i == 5 then
  56. if ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_7) then
  57. isUnlock = true
  58. end
  59. elseif i == 6 then
  60. if getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.ZHANBU_POS6) > 0 then
  61. isUnlock = true
  62. end
  63. elseif i == 7 then
  64. if getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.ZHANBU_POS7) > 0 then
  65. isUnlock = true
  66. end
  67. end
  68. if isUnlock then
  69. extraPosList[i] = i
  70. realyHandCnt = realyHandCnt + 1
  71. end
  72. end
  73. return realyHandCnt, extraPosList
  74. end
  75. function initAfterStart()
  76. for i = 1,#ZhanbuExcel.pool do
  77. local grade = ZhanbuExcel.pool[i].grade
  78. local heroID = ZhanbuExcel.pool[i].heroID
  79. local weight = ZhanbuExcel.pool[i].weight
  80. CARD_POOL[grade] = CARD_POOL[grade] or {}
  81. CARD_POOL[grade].weight = CARD_POOL[grade].weight or 0
  82. CARD_POOL[grade].weight = CARD_POOL[grade].weight + ZhanbuExcel.pool[i].weight
  83. CARD_POOL[grade].pool = CARD_POOL[grade].pool or {}
  84. CARD_POOL[grade].pool[#CARD_POOL[grade].pool + 1] = {heroID,weight,i}
  85. end
  86. end
  87. local function initDB(human)
  88. if human.db.zhanbu == nil then
  89. local maxPointsAdd = getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.ZHANBU_MAX_POINTS)
  90. human.db.zhanbu = {}
  91. local zhanbu = human.db.zhanbu
  92. zhanbu.hand = {}
  93. zhanbu.handCnt = 0
  94. --zhanbu.handMaxCnt = 4 -- ���������Ϊ4��
  95. zhanbu.handMaxCnt = MAXHANDCNT --直接改成最大值方便一点
  96. zhanbu.money = AUTO_GET_MONEY_MAX + maxPointsAdd
  97. zhanbu.lv = 1
  98. zhanbu.isGuide = 1
  99. zhanbu.refreshCnt = 0
  100. zhanbu.heartHero = {}
  101. zhanbu.pool = {}
  102. refreshPool(human)
  103. end
  104. --处理老号
  105. if human.db.zhanbu and human.db.zhanbu.handMaxCnt < MAXHANDCNT then
  106. human.db.zhanbu.handMaxCnt = MAXHANDCNT
  107. end
  108. -- ���û�û��heartHero
  109. if human.db.zhanbu.heartHero == nil then
  110. human.db.zhanbu.heartHero = {}
  111. end
  112. --屏蔽这里的判断, 改为通过 getHandInfo() 获取数据后进行判断
  113. -- local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_7)
  114. -- if cjPrivilege then
  115. -- -- �Ѽ������Ȩ����Ϊ5��
  116. -- human.db.zhanbu.handMaxCnt = 5
  117. -- else
  118. -- if human.db.zhanbu.hand[5] ~= nil then
  119. -- -- ������ҵ��������������ߣ�Ĭ�ϼ���
  120. -- human.db.zhanbu.handMaxCnt = 5
  121. -- else
  122. -- human.db.zhanbu.handMaxCnt = 4
  123. -- end
  124. -- end
  125. end
  126. function refreshPool(human)
  127. -- ��ʼ������
  128. initDB(human)
  129. local totalWeight = 0
  130. local weightConfig = ZhanbuExcel.poolLv[human.db.zhanbu.lv]
  131. for i = 1,#weightConfig.weight do
  132. totalWeight = totalWeight + weightConfig.weight[i]
  133. end
  134. -- ����һ��
  135. local cardPoolTb = Util.copyTable(CARD_POOL)
  136. for i = 1,#cardPoolTb[3].pool do
  137. if cardPoolTb[3].pool[i][1] == human.db.zhanbu.heartHero[1] or
  138. cardPoolTb[3].pool[i][1] == human.db.zhanbu.heartHero[2] or
  139. cardPoolTb[3].pool[i][1] == human.db.zhanbu.heartHero[3] then
  140. local newWeight = math.floor(cardPoolTb[3].pool[i][2] * 20 / 100)
  141. cardPoolTb[3].weight = cardPoolTb[3].weight + newWeight
  142. cardPoolTb[3].pool[i][2] = cardPoolTb[3].pool[i][2] + newWeight
  143. end
  144. end
  145. -- �������ſ�
  146. for i = 1,CARD_POOL_MAX_CNT do
  147. local randomGrade = math.random(1,totalWeight)
  148. -- ��ȡ���� R or SR or SSR
  149. for j = 1,#weightConfig.weight do
  150. if randomGrade <= weightConfig.weight[j] then
  151. local randomCard = math.random(1,cardPoolTb[j].weight)
  152. -- ��ȡ��
  153. for k = 1,#cardPoolTb[j].pool do
  154. if randomCard <= cardPoolTb[j].pool[k][2] then
  155. human.db.zhanbu.pool[i] = cardPoolTb[j].pool[k][3]
  156. break
  157. end
  158. randomCard = randomCard - cardPoolTb[j].pool[k][2]
  159. end
  160. break
  161. end
  162. randomGrade = randomGrade - weightConfig.weight[j]
  163. end
  164. end
  165. end
  166. function zhanbuQuery(human)
  167. -- ��ʼ������
  168. initDB(human)
  169. local msgRet = Msg.gc.GC_ZHANBU_QUERY
  170. local len = 0
  171. for i = 1,CARD_POOL_MAX_CNT do
  172. if human.db.zhanbu.pool[i] ~= nil then
  173. len = len + 1
  174. local index = human.db.zhanbu.pool[i]
  175. local config = ZhanbuExcel.pool[index]
  176. HeroGrid.makeHeroSimpleByID(msgRet.heroPool[len].heroInfo, config.heroID)
  177. msgRet.heroPool[len].price = config.price
  178. msgRet.heroPool[len].index = i
  179. end
  180. end
  181. msgRet.isGuide = human.db.zhanbu.isGuide or 0
  182. -- ��������������������ݷŵ�������
  183. if human.db.zhanbu.isGuide == 1 then
  184. len = 0
  185. sysHeroList = SysParameter.getSysParameterTb(SysParameter.PARAMETER_16)
  186. for i = 1,#sysHeroList do
  187. len = len + 1
  188. local index = sysHeroList[i]
  189. local config = ZhanbuExcel.pool[index]
  190. human.db.zhanbu.pool[i] = index
  191. HeroGrid.makeHeroSimpleByID(msgRet.heroPool[len].heroInfo, config.heroID)
  192. msgRet.heroPool[len].price = config.price
  193. msgRet.heroPool[len].index = i
  194. end
  195. human.db.zhanbu.isGuide = 0
  196. end
  197. msgRet.heroPool[0] = len
  198. -- msgRet.isLock = 1
  199. -- if human.db.zhanbu.handMaxCnt == 5 then
  200. -- msgRet.isLock = 0
  201. -- end
  202. len = MAXHANDCNT - INITIALHANDCNT
  203. msgRet.isLock[0] = len
  204. local _, extraPosList = getHandInfo(human)
  205. for i=MAXHANDCNT, INITIALHANDCNT+1, -1 do
  206. msgRet.isLock[len] = 1
  207. if extraPosList[i] then
  208. msgRet.isLock[len] = 0
  209. end
  210. len = len - 1
  211. end
  212. len = 0
  213. for i = 1,human.db.zhanbu.handMaxCnt do
  214. if human.db.zhanbu.hand[i] ~= nil then
  215. len = len + 1
  216. local index = human.db.zhanbu.hand[i]
  217. local config = ZhanbuExcel.pool[index]
  218. HeroGrid.makeHeroSimpleByID(msgRet.hand[len].heroInfo, config.heroID)
  219. msgRet.hand[len].price = config.price
  220. msgRet.hand[len].index = i
  221. end
  222. end
  223. msgRet.hand[0] = len
  224. local maxPointsAdd = getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.ZHANBU_MAX_POINTS)
  225. msgRet.cardRate = Util.copyTable(ZhanbuExcel.poolLv[human.db.zhanbu.lv].weight)
  226. msgRet.cardRate[0] = 3
  227. msgRet.lv = human.db.zhanbu.lv
  228. msgRet.money = human.db.zhanbu.money
  229. msgRet.moneyMax = AUTO_GET_MONEY_MAX + maxPointsAdd
  230. msgRet.moneyCost = 1
  231. msgRet.nextRecover = AUTO_GET_MONEY_TS
  232. msgRet.recoverTs = AUTO_GET_MONEY_TS
  233. if human.db.zhanbu.ts then
  234. local now = os.time()
  235. msgRet.nextRecover = human.db.zhanbu.ts + AUTO_GET_MONEY_TS - now
  236. if msgRet.nextRecover < 0 then
  237. msgRet.nextRecover = 0
  238. end
  239. end
  240. msgRet.hasRed = xinyiDot(human) and 1 or 0
  241. Msg.send(msgRet,human.fd)
  242. end
  243. function buyCard(human,index,heroID)
  244. -- �������ݶ�û�У��Ҹ�
  245. if human.db.zhanbu == nil or human.db.zhanbu.pool == nil then
  246. return
  247. end
  248. local heroIndex = human.db.zhanbu.pool[index]
  249. -- �������ݶԲ���
  250. local config = ZhanbuExcel.pool[heroIndex]
  251. if not config or config.heroID ~= heroID then
  252. return
  253. end
  254. -- �ж��Ƿ�ɺϳ���Ƭ
  255. local sameCnt = 0
  256. for i = 1,human.db.zhanbu.handMaxCnt do
  257. if human.db.zhanbu.hand[i] ~= nil and
  258. human.db.zhanbu.hand[i] == heroIndex then
  259. sameCnt = sameCnt + 1
  260. end
  261. end
  262. -- �ж������Ƿ�
  263. if human.db.zhanbu.money < config.price then
  264. return Broadcast.sendErr(human,Lang.ABS_ITEM_ERR)
  265. end
  266. local msgRet = Msg.gc.GC_ZHANBU_BUY_CARD
  267. -- �ɺϳ���Ƭ
  268. local maxPointsAdd = getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.ZHANBU_MAX_POINTS)
  269. if sameCnt >= 2 then
  270. -- �۳�����
  271. human.db.zhanbu.money = human.db.zhanbu.money - config.price
  272. RoleSystemLogic.onDot(human,RoleSystemDefine.ROLE_SYS_ID_502)
  273. -- �Զ��ظ���ʱ
  274. if human.db.zhanbu.money < AUTO_GET_MONEY_MAX + maxPointsAdd then
  275. human.db.zhanbu.ts = human.db.zhanbu.ts or os.time()
  276. end
  277. -- �۳�����
  278. for i = 1,human.db.zhanbu.handMaxCnt do
  279. if human.db.zhanbu.hand[i] ~= nil and
  280. human.db.zhanbu.hand[i] == heroIndex then
  281. human.db.zhanbu.hand[i] = nil
  282. human.db.zhanbu.handCnt = human.db.zhanbu.handCnt - 1
  283. end
  284. end
  285. -- �ӿ�����ɾ��
  286. human.db.zhanbu.pool[index] = nil
  287. -- ������Ƭ
  288. local randomCnt = math.random(config.chipCnt[1],config.chipCnt[2])
  289. randomCnt = randomCnt + getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.ZHANBU_FRAGMENT)
  290. local item = {}
  291. item[config.heroID] = randomCnt
  292. BagLogic.addItem(human, config.heroID, randomCnt, "zhanbu")
  293. if config.grade == 3 then
  294. DropExchangeLogic.drawSSR(human, item, 1)
  295. end
  296. local zhanbuActItemID,zhanbuActCnt = AbsZhanbuLunpanLogic.getZhanbuComposeCnt(human, config.grade)
  297. if zhanbuActCnt and zhanbuActCnt > 0 then
  298. item[zhanbuActItemID] = zhanbuActCnt
  299. BagLogic.addItem(human, zhanbuActItemID, zhanbuActCnt, "zhanbu")
  300. end
  301. BagLogic.sendItemGetList(human, item, "zhanbu")
  302. msgRet.index = 0
  303. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE3, 1)
  304. MengxinLogic.onCallBack(human,MengxinLogic.MX_TASK_TYPE_6,1)
  305. YunYingLogic.onCallBack(human, "ZhanBuHecheng",1)
  306. else
  307. -- �ж������Ƿ�����
  308. -- if human.db.zhanbu.handCnt >= human.db.zhanbu.handMaxCnt then
  309. -- return Broadcast.sendErr(human,Lang.ZHANBU_HAND_CARD_FULL)
  310. -- end
  311. local realyHandCnt, extraPosList = getHandInfo(human)
  312. if human.db.zhanbu.handCnt >= realyHandCnt then
  313. return Broadcast.sendErr(human,Lang.ZHANBU_HAND_CARD_FULL)
  314. end
  315. -- �۳�����
  316. human.db.zhanbu.money = human.db.zhanbu.money - config.price
  317. RoleSystemLogic.onDot(human,RoleSystemDefine.ROLE_SYS_ID_502)
  318. -- �Զ��ظ���ʱ
  319. if human.db.zhanbu.money < AUTO_GET_MONEY_MAX + maxPointsAdd then
  320. human.db.zhanbu.ts = human.db.zhanbu.ts or os.time()
  321. end
  322. -- �ӿ�����ɾ��
  323. human.db.zhanbu.pool[index] = nil
  324. local bl = true
  325. for i = 1,human.db.zhanbu.handMaxCnt do
  326. if human.db.zhanbu.hand[i] == nil then
  327. bl = true
  328. if i >= INITIALHANDCNT + 1 and not extraPosList[i] then
  329. bl = false
  330. end
  331. if bl then
  332. human.db.zhanbu.handCnt = human.db.zhanbu.handCnt + 1
  333. human.db.zhanbu.hand[i] = heroIndex
  334. msgRet.index = i
  335. break
  336. end
  337. end
  338. end
  339. end
  340. -- ֪ͨ�ͻ��˹���ɹ�
  341. Msg.send(msgRet,human.fd)
  342. -- ˢ�½���
  343. zhanbuQuery(human)
  344. YunYingLogic.onCallBack(human, "onZhanBuBuyCard", config.price)
  345. end
  346. function sellCard(human,index,heroID)
  347. -- �������ݶ�û�У��Ҹ�
  348. if human.db.zhanbu == nil or human.db.zhanbu.hand == nil then
  349. return
  350. end
  351. -- У�鿨�ĺϷ���
  352. local heroIndex = human.db.zhanbu.hand[index]
  353. local config = ZhanbuExcel.pool[heroIndex]
  354. if heroIndex == nil or config == nil then
  355. return
  356. end
  357. -- ɾ������
  358. human.db.zhanbu.hand[index] = nil
  359. human.db.zhanbu.handCnt = human.db.zhanbu.handCnt - 1
  360. -- ���ӵ���
  361. human.db.zhanbu.money = human.db.zhanbu.money + config.price
  362. RoleSystemLogic.onDot(human,RoleSystemDefine.ROLE_SYS_ID_502)
  363. -- �Զ��ظ���ʱ
  364. local maxPointsAdd = getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.ZHANBU_MAX_POINTS)
  365. if human.db.zhanbu.money >= AUTO_GET_MONEY_MAX + maxPointsAdd then
  366. human.db.zhanbu.ts = nil
  367. end
  368. -- ֪ͨ�ͻ����۳��ɹ�
  369. Msg.send(Msg.gc.GC_ZHANBU_SELL_CARD,human.fd)
  370. -- ˢ�½���
  371. zhanbuQuery(human)
  372. YunYingLogic.onCallBack(human, "onZhanBuBuyCard", -config.price)
  373. end
  374. function changePos(human,posList)
  375. -- �������ݶ�û�У��Ҹ�
  376. if human.db.zhanbu == nil or human.db.zhanbu.hand == nil then
  377. return
  378. end
  379. -- ��������λ���Ƿ�Ϸ�
  380. local tb = Util.split(posList, "|")
  381. -- ���Ȳ��ԣ����Ϸ�
  382. if #tb > human.db.zhanbu.handMaxCnt then
  383. return
  384. end
  385. local _, extraPosList = getHandInfo(human)
  386. for i = 1,#tb do
  387. -- ���ܽ���ɾ��
  388. tb[i] = tonumber(tb[i])
  389. local pos = tb[i]
  390. if pos == 0 and human.db.zhanbu.hand[i] ~= nil then
  391. return
  392. end
  393. -- ��λ�ò��Ϸ�
  394. if pos > human.db.zhanbu.handMaxCnt then
  395. return
  396. end
  397. if pos >= INITIALHANDCNT + 1 and not extraPosList[pos] then
  398. return
  399. end
  400. end
  401. -- �����
  402. local dataList = Util.copyTable(human.db.zhanbu.hand)
  403. human.db.zhanbu.hand = {}
  404. for i = 1,human.db.zhanbu.handMaxCnt do
  405. if tb[i] and tb[i] ~= 0 then
  406. human.db.zhanbu.hand[tb[i]] = dataList[i]
  407. end
  408. end
  409. zhanbuQuery(human)
  410. end
  411. function refreshCardPool(human)
  412. -- �������ݶ�û�У��Ҹ�
  413. if human.db.zhanbu == nil or human.db.zhanbu.hand == nil then
  414. return
  415. end
  416. -- У����ϲ���
  417. if human.db.zhanbu.money < CARD_POOL_REFRESH then
  418. return Broadcast.sendErr(human,Lang.ABS_ITEM_ERR)
  419. end
  420. -- �۳�����
  421. human.db.zhanbu.money = human.db.zhanbu.money - CARD_POOL_REFRESH
  422. RoleSystemLogic.onDot(human,RoleSystemDefine.ROLE_SYS_ID_502)
  423. -- �Զ��ظ���ʱ
  424. local maxPointsAdd = getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.ZHANBU_MAX_POINTS)
  425. if human.db.zhanbu.money < AUTO_GET_MONEY_MAX + maxPointsAdd then
  426. human.db.zhanbu.ts = human.db.zhanbu.ts or os.time()
  427. end
  428. -- ˢ��
  429. refreshPool(human)
  430. -- ˢ�³ɹ�������+1
  431. onLv(human)
  432. -- ˢ�½���
  433. zhanbuQuery(human)
  434. --ռ�����̻ ˢ�º�ص�
  435. AbsZhanbuLunpanLogic.onZhanbuRefresh(human)
  436. YunYingLogic.onCallBack(human, "onZhanBuBuyCard", CARD_POOL_REFRESH)
  437. end
  438. -- ����Ӣ��
  439. function zhanbuHeartHeroQuery(human)
  440. -- �������ݶ�û�У��Ҹ�
  441. if human.db.zhanbu == nil or human.db.zhanbu.hand == nil then
  442. return
  443. end
  444. local msgRet = Msg.gc.GC_ZHANBU_HEART_HERO_QUERY
  445. for i = 1,3 do
  446. local heroID = human.db.zhanbu.heartHero[i]
  447. msgRet.heroInfo[i] = heroID or 0
  448. end
  449. msgRet.heroInfo[0] = 3
  450. local len = 0
  451. for heroID,v in pairs(human.db.heroBook) do
  452. local heroConfig = HeroExcel.hero[heroID]
  453. if heroConfig and heroConfig.grade >= 4 then
  454. len = len + 1
  455. msgRet.heroList[len] = heroID
  456. end
  457. end
  458. msgRet.heroList[0] = len
  459. Msg.send(msgRet,human.fd)
  460. end
  461. -- ��������Ӣ��
  462. function setHeartHero(human,heroList)
  463. -- �������ݶ�û�У��Ҹ�
  464. if human.db.zhanbu == nil or human.db.zhanbu.hand == nil then
  465. return
  466. end
  467. -- ��������λ���Ƿ�Ϸ�
  468. local tb = Util.split(heroList, "|")
  469. -- ���Ȳ��ԣ����Ϸ�
  470. local len = #tb
  471. if len > 3 then
  472. return
  473. end
  474. -- У��Ӣ���Ƿ���ͼ���У��Ƿ���SSR
  475. for i = 1,len do
  476. tb[i] = tonumber(tb[i])
  477. local heroID = tb[i]
  478. if heroID ~= 0 then
  479. local heroConfig = HeroExcel.hero[heroID]
  480. -- �����Ѽ���ͼ���У�����
  481. if not HeroBook.isGet(human, heroID,heroConfig.star) then
  482. return
  483. end
  484. -- ����SSR������
  485. if heroConfig.grade < 4 then
  486. return
  487. end
  488. end
  489. end
  490. -- �������������
  491. human.db.zhanbu.heartHero = {}
  492. for i = 1,len do
  493. if tb[i] ~= 0 then
  494. human.db.zhanbu.heartHero[i] = tb[i]
  495. end
  496. end
  497. -- ˢ������Ӣ������
  498. zhanbuHeartHeroQuery(human)
  499. end
  500. function onLv(human)
  501. human.db.zhanbu.refreshCnt = human.db.zhanbu.refreshCnt + 1
  502. if human.db.zhanbu.refreshCnt >= ZhanbuExcel.poolLv[human.db.zhanbu.lv].cnt and
  503. human.db.zhanbu.lv < #ZhanbuExcel.poolLv then
  504. human.db.zhanbu.lv = human.db.zhanbu.lv + 1
  505. local msgRet = Msg.gc.GC_ZHANBU_LVUP
  506. msgRet.cardRate = Util.copyTable(ZhanbuExcel.poolLv[human.db.zhanbu.lv].weight)
  507. msgRet.cardRate[0] = 3
  508. msgRet.lv = human.db.zhanbu.lv
  509. Msg.send(msgRet,human.fd)
  510. end
  511. end
  512. function checkRecover()
  513. local now = os.time()
  514. for _,human in pairs(ObjHuman.onlineUuid) do
  515. if human.db.zhanbu and human.db.zhanbu.ts then
  516. local maxPointsAdd = getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.ZHANBU_MAX_POINTS)
  517. local finalMaxPoints = maxPointsAdd + AUTO_GET_MONEY_MAX
  518. local ts = now - human.db.zhanbu.ts
  519. local cnt = math.floor(ts/AUTO_GET_MONEY_TS)
  520. if cnt >= 1 and human.db.zhanbu.money < finalMaxPoints then
  521. human.db.zhanbu.money = human.db.zhanbu.money + cnt
  522. human.db.zhanbu.ts = human.db.zhanbu.ts + AUTO_GET_MONEY_TS * cnt
  523. if human.db.zhanbu.money >= finalMaxPoints then
  524. human.db.zhanbu.ts = nil
  525. human.db.zhanbu.money = finalMaxPoints
  526. end
  527. RoleSystemLogic.onDot(human,RoleSystemDefine.ROLE_SYS_ID_502)
  528. elseif human.db.zhanbu.money >= finalMaxPoints then
  529. human.db.zhanbu.ts = nil
  530. end
  531. end
  532. end
  533. end
  534. function isDot(human)
  535. if human.db.lv < 14 then
  536. return
  537. end
  538. initDB(human)
  539. if human.db.zhanbu and human.db.zhanbu.money >= 30 then
  540. return true
  541. end
  542. if xinyiDot(human) then
  543. return true
  544. end
  545. return
  546. end
  547. function updateDaily(human)
  548. if human.db.zhanbu == nil then
  549. return
  550. end
  551. human.db.zhanbu.lv = 1
  552. human.db.zhanbu.refreshCnt = 0
  553. if human.db.zhanbu and human.db.zhanbu.money then
  554. local ts = human.db.zhanbu.ts
  555. local maxPointsAdd = getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.ZHANBU_MAX_POINTS)
  556. if not ts and human.db.zhanbu.money < AUTO_GET_MONEY_MAX + maxPointsAdd then
  557. human.db.zhanbu.ts = os.time()
  558. end
  559. end
  560. end
  561. function onLogin(human)
  562. --处理mone达到老的上限值后, human.db.zhanbu.ts为nil,导致后面获得秘宝时,无法获得秘宝加成情况
  563. if human.db.zhanbu and human.db.zhanbu.money then
  564. local ts = human.db.zhanbu.ts
  565. local maxPointsAdd = getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.ZHANBU_MAX_POINTS)
  566. if not ts and human.db.zhanbu.money < AUTO_GET_MONEY_MAX + maxPointsAdd then
  567. human.db.zhanbu.ts = os.time()
  568. end
  569. end
  570. RecommendLineup.RecommendLineup_UpDate(human)
  571. end
  572. function addZhanbuItem(human,cnt)
  573. -- ��ʼ������
  574. initDB(human)
  575. human.db.zhanbu.money = human.db.zhanbu.money + cnt
  576. end
  577. function xinyiDot(human)
  578. if human.db.heroBook == nil then return end
  579. local count = 0
  580. for k ,v in pairs(human.db.heroBook) do
  581. if type(k) == "number" then
  582. if HeroExcel.hero[k].grade >= 4 then
  583. count = count + 1
  584. end
  585. end
  586. end
  587. local xinyiCount = 0
  588. for i = 1, 3 do
  589. if human.db.zhanbu.heartHero[i] ~= nil then
  590. xinyiCount = xinyiCount + 1
  591. end
  592. end
  593. if xinyiCount < count and xinyiCount < 3 then
  594. return true
  595. end
  596. end