ZhanbuLogic.lua 24 KB

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