JjcLogic.lua 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  1. -- 竞技场逻辑
  2. -- 开始结束赛季 给赛季奖励 ok
  3. -- 设置防守阵容 ok
  4. -- 查询基础 ok
  5. -- 战斗 ok
  6. -- 积分 ok
  7. -- 排行 根据排行给奖励 ok
  8. -- 保存战斗记录和查询战斗记录
  9. -- 门票购买 ok
  10. --[=[
  11. ------JjcDB---------
  12. jjcDB.initAfterStart()开始
  13. 如果是第一次开启
  14. 1.设定本轮活动结束时间, 即开服时间 + 7*86400 - 10800
  15. 2.jjcDB.initJJCDB()——>jjcDB.resetJJCDB()——>jjcDB.addNpc() 生成机器人,缓存到RANK_2_JJCDATA 和 ROBOT_LIST,并把机器人数据插入到数据库 db_jjc 中
  16. 非第一次开启
  17. 把竞技场玩家和npc数据读取到内存
  18. --------JjcLogin.lua-----------
  19. onHour() 定时整点函数
  20. 4点, 删除符合条件的战斗视频数据
  21. 21点, 发放当日排行奖励
  22. 如果本轮活动结束, 发放排行奖励, 重置数据(包括删除竞技场战斗视频数据), 设置新一轮活动结束时间。
  23. 每次查询或者战斗时, 检测如果玩家如果没有加入竞技场, 且设置了竞技场的防守阵容, 则会把玩家加入竞技场, 排名为现有竞技场人数(包含npc) + 1。
  24. 挑战胜利, 则更新对战双方的积分和排名。
  25. ]=]--
  26. local Util = require("common.Util")
  27. local HtmlUtil = require("common.HtmlUtil")
  28. local Lang = require("common.Lang")
  29. local CommonDB = require("common.CommonDB")
  30. local JjcExcel = require("excel.jjc")
  31. local MonsterExcel = require("excel.monster")
  32. local MailExcel = require("excel.mail")
  33. local Msg = require("core.Msg")
  34. local ObjHuman = require("core.ObjHuman")
  35. local Broadcast = require("broadcast.Broadcast")
  36. local Grid = require("bag.Grid")
  37. local BagLogic = require("bag.BagLogic")
  38. local ItemDefine = require("bag.ItemDefine")
  39. local JjcDB = require("jjc.JjcDB")
  40. local JjcActLogic = require("jjc.JjcActLogic")
  41. local RoleDBLogic = require("role.RoleDBLogic")
  42. local HeroDefine = require("hero.HeroDefine")
  43. local HeroGrid = require("hero.HeroGrid")
  44. local CombatDefine = require("combat.CombatDefine")
  45. local CombatLogic = require("combat.CombatLogic")
  46. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  47. local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
  48. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  49. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  50. local MailManager = require("mail.MailManager")
  51. local DailyTaskLogic = require("dailyTask.DailyTaskLogic")
  52. local MonthHzz = require("monthAct.MonthHzz")
  53. local UnionDBLogic = require("union.UnionDBLogic")
  54. local HeroExcel = require("excel.hero").hero
  55. local HeroLogic = require("hero.HeroLogic")
  56. local CombatPosLogic = require("combat.CombatPosLogic")
  57. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  58. local RoleDefine = require("role.RoleDefine")
  59. local RoleLogic = require("role.RoleLogic")
  60. local CombatVideo = require("combat.CombatVideo")
  61. local WarReportLogic = require("warReport.WarReportLogic")
  62. local LiLianLogic = require("dailyTask.LiLianLogic")
  63. local MailDefine = require("mail.MailIdDefine")
  64. local HeroLogLogic = require("absAct.HeroLogLogic")
  65. local HeroGrowUp = require("absAct.HeroGrowUp")
  66. local MengxinLogic = require("present.MengxinLogic")
  67. local YunYingLogic = require("yunying.YunYingLogic")
  68. local Timer = require("core.Timer")
  69. local WarOrder = require("shop.WarOrder")
  70. local TriggerDefine = require("trigger.TriggerDefine")
  71. local TriggerLogic = require("trigger.TriggerLogic")
  72. local ARENA_ORDER_TYPE = 4
  73. JJC_TARGET_CNT = 15 -- 每次找15个对手
  74. JJC_FREE_DAILY_CNT = 3 -- 每天3次免费战斗次数
  75. JJC_WORSHIP_CNT = 10 -- 每天10次膜拜次数
  76. JJC_WORSHIP_DOT_CNT = 3 -- 每天膜拜3次后红点消失
  77. JJC_WORSHIP_JINBI_CNT = 3000 -- 膜拜成功给金币数量
  78. JJC_COST_ITEM_CNT = 10 -- 竞技场挑战花费数量
  79. JJC_OPEN_QUICK = 20
  80. JJC_DOUBLE_CNT = 20 -- 双倍奖励次数
  81. JJC_COOL_TIME = 60
  82. JJC_RESULT_DEF_FAIL = 0
  83. JJC_RESULT_ATK_WIN = 1
  84. JJC_RESULT_ATK_FAIL = 2
  85. JJC_RESULT_DEF_WIN = 3
  86. local QUICK_COND_TIMES = 10 -- 跳过战斗需要战斗次数
  87. -- 检查是否加入竞技场
  88. function checkNeedJoin(human)
  89. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1301) then
  90. return
  91. end
  92. -- 如果还没参加竞技场 并且已经设置过防守阵容 那么加入竞技场
  93. local data = JjcDB.getJjcData(human.db._id)
  94. if data then return end
  95. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE3, nil, true)
  96. if not combatHero or not next(combatHero) then return end
  97. JjcDB.addPlayer(human)
  98. end
  99. -- 构造成员结构体
  100. function fontMemberNet(net, rank, data,worshipCnt,worshipState)
  101. net.rank = rank
  102. net.jifen = data and data.point or 0
  103. net.worshipCnt = worshipCnt
  104. net.worshipState = worshipState
  105. if data.monsterOutID then
  106. RoleLogic.makeRoleBase(data, net.roleBase)
  107. else
  108. RoleLogic.getRoleBaseByUuid(data._id, net.roleBase, CombatDefine.COMBAT_TYPE3)
  109. end
  110. end
  111. -- 竞技场查询
  112. function query(human)
  113. local flag, config = RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1301)
  114. if flag ~= true then
  115. --return Broadcast.sendErr(human, Lang.JJC_OPEN_NEED_LV)
  116. return Broadcast.sendErr(human, Util.format(Lang.COMMON_NEED_LEVEL, config.lv))
  117. end
  118. local leftSec = getLeftSec()
  119. if leftSec == nil then
  120. return Broadcast.sendErr(human, Lang.JJC_NOT_SET_OPEN_TIME)
  121. end
  122. -- 检查是否加入到竞技场
  123. checkNeedJoin(human)
  124. local seasonBox = JjcDB.getJjcSeasonBox(human.db._id)
  125. local totalFight = JjcDB.getJjcTotalFight(human.db._id)
  126. local totalFightCnt = JjcDB.getTotalFightCnt(human.db._id)
  127. local msgRet = Msg.gc.GC_JJC_QUERY
  128. msgRet.leftSec = leftSec
  129. msgRet.ownRank = JjcDB.getRank(human.db._id)
  130. msgRet.ownJifen = JjcDB.getJjcPoint(human.db._id)
  131. msgRet.defZDL = CombatPosLogic.getCombatHeroZDL(human, CombatDefine.COMBAT_TYPE3)
  132. msgRet.atkZDL = CombatPosLogic.getCombatHeroZDL(human, CombatDefine.COMBAT_TYPE1)
  133. msgRet.dotList[0] = 3
  134. msgRet.dotList[1] = championChallengeDot(human)
  135. msgRet.dotList[2] = championBillboardDot(human)
  136. msgRet.dotList[3] = championRecordDot(human)
  137. msgRet.challengeCnt = totalFight
  138. Grid.makeItem(msgRet.challengeCostItem,ItemDefine.ITEM_JJC_TICKET_ID,JJC_COST_ITEM_CNT)
  139. msgRet.isQuick = human.db.combatQuick[CombatDefine.COMBAT_TYPE2] or 0
  140. if human.db.combatQuick[CombatDefine.COMBAT_TYPE2] == nil then
  141. if totalFightCnt >= QUICK_COND_TIMES then
  142. human.db.combatQuick[CombatDefine.COMBAT_TYPE2] = 0
  143. else
  144. msgRet.isQuick = -1
  145. end
  146. end
  147. local boxExcel = JjcExcel.seasonBox
  148. local boxLen = #boxExcel
  149. for i = 1,boxLen do
  150. local v = boxExcel[i]
  151. local net = msgRet.jjcBox[i]
  152. net.reachCnt = v.reachCnt
  153. if seasonBox == nil or seasonBox[i] == nil then
  154. -- 未领取
  155. if totalFight >= v.reachCnt then
  156. -- 已达标
  157. net.state = 1
  158. else
  159. net.state = 0
  160. end
  161. else
  162. -- 已领取
  163. net.state = 2
  164. end
  165. local itemLen = #v.item
  166. for j = 1,itemLen do
  167. Grid.makeItem(net.item[j],v.item[j][1],v.item[j][2])
  168. end
  169. net.item[0] = itemLen
  170. end
  171. msgRet.jjcBox[0] = boxLen
  172. Msg.send(msgRet, human.fd)
  173. local nowRank = JjcDB.getRank(human.db._id)
  174. if nowRank > 0 and ((human.db.jjcBestRank or 0) <= 0 or nowRank < (human.db.jjcBestRank or 0)) then
  175. human.db.jjcBestRank = nowRank
  176. end
  177. end
  178. function getQuick(human, combatType)
  179. local totalFight = JjcDB.getJjcTotalFight(human.db._id)
  180. if totalFight > JJC_OPEN_QUICK then
  181. return 1
  182. end
  183. return 0
  184. end
  185. -- 挑战记录查询
  186. function recordQuery(human)
  187. local msgRet = Msg.gc.GC_JJC_RECORD_QUERY
  188. local recordList = JjcDB.getJjcRecordList(human.db._id)
  189. local nowFightCnt = human.db.jjcDailyFight or 0
  190. msgRet.leftFreeCnt = math.max(JJC_FREE_DAILY_CNT - nowFightCnt, 0)
  191. msgRet.recordList[0] = 0
  192. if not recordList then
  193. Msg.send(msgRet, human.fd)
  194. return
  195. end
  196. for i = 1, #recordList do
  197. local videoUuid = recordList[i]
  198. local combatVideo = CombatVideo.getCombatVideo(videoUuid)
  199. if combatVideo then
  200. msgRet.recordList[0] = msgRet.recordList[0] + 1
  201. local net = msgRet.recordList[msgRet.recordList[0]]
  202. local combatInfo = combatVideo.combatInfo
  203. local parms = combatInfo.endParam and Util.split(combatInfo.endParam, "|")
  204. net.time = combatInfo.time
  205. net.identity = combatVideo._id
  206. if combatInfo.attacker.uuid == human.db._id then
  207. RoleLogic.makeRoleBase(combatInfo.defender, net.roleBase)
  208. net.result = combatInfo.isWin and JJC_RESULT_ATK_WIN or JJC_RESULT_ATK_FAIL
  209. net.jifenChange = tonumber(parms and parms[3]) or 0
  210. else
  211. RoleLogic.makeRoleBase(combatInfo.attacker, net.roleBase)
  212. net.result = (not combatInfo.isWin) and JJC_RESULT_DEF_WIN or JJC_RESULT_DEF_FAIL
  213. net.jifenChange = tonumber(parms and parms[4]) or 0
  214. end
  215. end
  216. end
  217. Msg.send(msgRet, human.fd)
  218. -- 记录点开战斗记录时间
  219. human.db.jjcNewestRecord = os.time()
  220. RoleSystemLogic.onDot(human,RoleSystemDefine.ROLE_SYS_ID_1300)
  221. end
  222. --[[-- 计算分数
  223. function calcPoint(comBatResult, atkPoint, defPoint)
  224. -- 赢 加积分 扣对方积分
  225. local addPoint = 0
  226. local delPoint = 0
  227. if comBatResult == CombatDefine.RESULT_WIN then
  228. if defPoint > 0 then
  229. if atkPoint >= defPoint then
  230. local tp1 = (defPoint/atkPoint)^2 * (1250/atkPoint) * 25
  231. local tp2 = 1 + math.floor((defPoint-atkPoint)/50 + 0.5) / 10
  232. addPoint = math.ceil (tp1 * tp2)
  233. delPoint = math.ceil(addPoint * (atkPoint/defPoint))
  234. else
  235. --我方积分较低的胜场
  236. addPoint = math.ceil((defPoint/atkPoint)^2 * (1250/atkPoint)*25)
  237. delPoint = math.ceil(addPoint * (atkPoint/defPoint))
  238. end
  239. end
  240. if addPoint <= 0 or delPoint <= 0 then
  241. addPoint = 0
  242. delPoint = 0
  243. else
  244. addPoint = addPoint > 100 and 100 or addPoint
  245. delPoint = delPoint > 100 and 100 or delPoint
  246. end
  247. atkPoint = atkPoint + addPoint --我方积分
  248. defPoint = defPoint - delPoint --防守方积分
  249. else
  250. -- 输 减积分 加对方积分
  251. local scal = 15
  252. if atkPoint >= defPoint then
  253. scal = 25
  254. end
  255. if defPoint > 0 then
  256. addPoint = math.ceil((atkPoint / defPoint) * scal)
  257. delPoint = math.ceil(addPoint * (atkPoint/defPoint))
  258. end
  259. if addPoint <= 0 or delPoint <= 0 then
  260. addPoint = 0
  261. delPoint = 0
  262. else
  263. addPoint = addPoint > 100 and 100 or addPoint
  264. delPoint = delPoint > 100 and 100 or delPoint
  265. end
  266. atkPoint = atkPoint - addPoint
  267. defPoint = defPoint + delPoint
  268. end
  269. if atkPoint < 0 then
  270. atkPoint = 1
  271. end
  272. if defPoint < 0 then
  273. defPoint = 1
  274. end
  275. return atkPoint, defPoint
  276. end]]
  277. -- 计算分数
  278. function calcPoint(comBatResult, atkPoint, defPoint)
  279. -- 赢 加积分 扣对方积分
  280. local addPoint = 0
  281. local delPoint = 0
  282. addPoint = math.ceil(22/(atkPoint/defPoint)^2)
  283. delPoint = math.ceil(22/(atkPoint/defPoint)^2 - 5)
  284. if addPoint <= 1 then
  285. addPoint = 1
  286. end
  287. if defPoint <= 1 then
  288. defPoint = 1
  289. end
  290. if comBatResult == CombatDefine.RESULT_WIN then
  291. atkPoint = atkPoint + addPoint --我方积分
  292. defPoint = defPoint - delPoint --防守方积分
  293. end
  294. if atkPoint < 0 then
  295. atkPoint = 1
  296. end
  297. if defPoint < 0 then
  298. defPoint = 1
  299. end
  300. return atkPoint, defPoint
  301. end
  302. function rewardQuery(human, type)
  303. if type ~= 1 and type ~= 2 then
  304. return
  305. end
  306. local msgRet = Msg.gc.GC_JJC_DAY_REWARD_QUERY
  307. msgRet.type = type
  308. msgRet.rank = JjcDB.getRank(human.db._id)
  309. msgRet.canGet[0] = 0
  310. if type == 1 then
  311. -- 每日奖励
  312. for i = 1, #JjcExcel.dayReward do
  313. local configTemp = JjcExcel.dayReward[i]
  314. msgRet.list[i].maxRank = configTemp.rankMax
  315. msgRet.list[i].minRank = configTemp.rankMin
  316. local len = #configTemp.reward
  317. msgRet.list[i].items[0] = len
  318. for j = 1, len do
  319. local itemID = configTemp.reward[j][1]
  320. local itemCnt = configTemp.reward[j][2]
  321. Grid.makeItem(msgRet.list[i].items[j], itemID, itemCnt)
  322. end
  323. if msgRet.rank >= configTemp.rankMin and msgRet.rank <= configTemp.rankMax then
  324. for j = 1, len do
  325. local itemID = configTemp.reward[j][1]
  326. local itemCnt = configTemp.reward[j][2]
  327. Grid.makeItem(msgRet.canGet[j], itemID, itemCnt)
  328. end
  329. msgRet.canGet[0] = len
  330. end
  331. end
  332. msgRet.list[0] = #JjcExcel.dayReward
  333. local now = os.time()
  334. local ts1 = Util.getDayHourTime(now, 21)
  335. if now >= ts1 then
  336. msgRet.leftSec = ts1 + 24 * 3600 - now
  337. else
  338. msgRet.leftSec = ts1 - now
  339. end
  340. else
  341. -- 赛季奖励
  342. for i = 1, #JjcExcel.seasonReward do
  343. local configTemp = JjcExcel.seasonReward[i]
  344. msgRet.list[i].maxRank = configTemp.rankMax
  345. msgRet.list[i].minRank = configTemp.rankMin
  346. local len = #configTemp.reward
  347. msgRet.list[i].items[0] = len
  348. for j = 1, len do
  349. local itemID = configTemp.reward[j][1]
  350. local itemCnt = configTemp.reward[j][2]
  351. Grid.makeItem(msgRet.list[i].items[j], itemID, itemCnt)
  352. end
  353. if msgRet.rank >= configTemp.rankMin and msgRet.rank <= configTemp.rankMax then
  354. for j = 1, len do
  355. local itemID = configTemp.reward[j][1]
  356. local itemCnt = configTemp.reward[j][2]
  357. Grid.makeItem(msgRet.canGet[j], itemID, itemCnt)
  358. end
  359. msgRet.canGet[0] = len
  360. end
  361. end
  362. msgRet.list[0] = #JjcExcel.seasonReward
  363. msgRet.leftSec = 0
  364. end
  365. Msg.send(msgRet, human.fd)
  366. end
  367. --[[
  368. -- 查找对手
  369. function targetFind(human)
  370. ObjHuman.updateDaily(human)
  371. local rank = 0
  372. local len = 0
  373. local tempRank = {}
  374. local targetIndexs = {}
  375. local nowFightCnt = human.db.jjcDailyFight or 0
  376. local leftFreeCnt = 0
  377. if JJC_FREE_DAILY_CNT > nowFightCnt then
  378. leftFreeCnt = JJC_FREE_DAILY_CNT - nowFightCnt
  379. end
  380. local msgRet = Msg.gc.GC_JJC_TARGET_FIND
  381. msgRet.leftFreeCnt = leftFreeCnt
  382. --没有加入队列
  383. local humanRank = JjcDB.getRank(human.db._id)
  384. if humanRank < 1 then
  385. --随机取机器人
  386. local randomCount = #JjcDB.ROBOT_LIST - 30
  387. local randomIndex = math.random(1, randomCount)
  388. local randomEnd = randomIndex + 30
  389. for i = randomIndex, randomEnd do
  390. local dataTemp = JjcDB.ROBOT_LIST[i]
  391. if dataTemp ~= nil then
  392. if len >= 30 then
  393. break
  394. end
  395. len = len + 1
  396. fontMemberNet(msgRet.targetList[len], rank, dataTemp,0,0)
  397. end
  398. end
  399. msgRet.targetList[0] = len
  400. Msg.send(msgRet, human.fd)
  401. return
  402. end
  403. local leftCnt = 8 -- 往前取8个
  404. local rightCnt = JJC_TARGET_CNT - leftCnt -- 往后取7个
  405. if humanRank <= leftCnt then
  406. leftCnt = humanRank - 1
  407. rightCnt = JJC_TARGET_CNT - leftCnt
  408. end
  409. if humanRank >= #JjcDB.RANK_2_JJCDATA - rightCnt then
  410. rightCnt = #JjcDB.RANK_2_JJCDATA - humanRank
  411. leftCnt = JJC_TARGET_CNT - rightCnt
  412. end
  413. if leftCnt > 0 then
  414. for i = humanRank - leftCnt, humanRank - 1 do
  415. table.insert(targetIndexs, i)
  416. end
  417. end
  418. if rightCnt > 0 then
  419. for i = humanRank + 1, humanRank + rightCnt do
  420. table.insert(targetIndexs, i)
  421. end
  422. end
  423. for i = 1, JJC_TARGET_CNT do
  424. rank = targetIndexs[i]
  425. if rank > 0 then
  426. tempRank[rank] = rank
  427. end
  428. end
  429. -- 自己的前20位 再随机 取5个
  430. local rankMin= humanRank - 20
  431. local rankMax = humanRank - 1
  432. if rankMin > 0 and rankMax > 0 then
  433. local randIndex = math.random(rankMin, rankMax)
  434. local endRank = randIndex + 5
  435. for i = randIndex, endRank do
  436. if tempRank[i] == nil and i ~= humanRank and JjcDB.RANK_2_JJCDATA[i] ~= nil then
  437. tempRank[i] = i
  438. end
  439. end
  440. end
  441. -- 自己的后100位 再随机 取10个
  442. rankMin = humanRank + 1
  443. rankMax = humanRank + 300
  444. if rankMin > 0 and rankMax > 0 then
  445. local randIndex = math.random(rankMin, rankMax)
  446. local endRank = randIndex + 10
  447. for i = randIndex, endRank do
  448. if tempRank[i] == nil and i ~= humanRank and JjcDB.RANK_2_JJCDATA[i] ~= nil then
  449. tempRank[i] = i
  450. end
  451. end
  452. end
  453. local unionUuid = ""
  454. for k, rank in pairs(tempRank) do
  455. local dataTemp = JjcDB.RANK_2_JJCDATA[rank]
  456. if dataTemp ~= nil and rank ~= humanRank then
  457. if len >= 30 then
  458. break
  459. end
  460. len = len + 1
  461. local db = RoleDBLogic.getDb(dataTemp._id)
  462. if db == nil then
  463. fontMemberNet(msgRet.targetList[len], rank, dataTemp,0,0)
  464. else
  465. local worshipCnt = db.jjcBeWorship and db.jjcBeWorship or 0
  466. local worshipState = 0
  467. if db._id ~= human.db._id and (human.db.jjcWorship == nil or human.db.jjcWorship[dataTemp._id] == nil) then
  468. worshipState = 1
  469. end
  470. fontMemberNet(msgRet.targetList[len], rank, dataTemp,worshipCnt,worshipState)
  471. end
  472. end
  473. end
  474. msgRet.targetList[0] = len
  475. Msg.send(msgRet, human.fd)
  476. end
  477. ]]
  478. -- 查找对手
  479. function targetFind(human,type)
  480. ObjHuman.updateDaily(human)
  481. local rank = 0
  482. local len = 0
  483. local targetIndexs = {}
  484. local nowFightCnt = human.db.jjcDailyFight or 0
  485. local leftFreeCnt = 0
  486. if JJC_FREE_DAILY_CNT > nowFightCnt then
  487. leftFreeCnt = JJC_FREE_DAILY_CNT - nowFightCnt
  488. end
  489. local msgRet = Msg.gc.GC_JJC_TARGET_FIND
  490. msgRet.leftFreeCnt = leftFreeCnt
  491. --没有加入队列
  492. local humanPoint = JjcDB.getJjcPoint(human.db._id)
  493. local areaList = {}
  494. local choseUuid = {}
  495. local count = 0
  496. local jjcRival = JjcDB.getJjcRival(human.db._id)
  497. if jjcRival ~= nil and #jjcRival ~= 0 and type == 0 then
  498. for k,v in pairs(jjcRival) do
  499. local rank = JjcDB.getRank(v)
  500. local jjcData = JjcDB.RANK_2_JJCDATA[rank]
  501. len = len + 1
  502. local db = RoleDBLogic.getDb(v)
  503. if db == nil then
  504. fontMemberNet(msgRet.targetList[len], rank, jjcData,0,0)
  505. else
  506. local worshipCnt = db.jjcBeWorship and db.jjcBeWorship or 0
  507. local worshipState = 0
  508. if db._id ~= human.db._id and (human.db.jjcWorship == nil or human.db.jjcWorship[v] == nil) then
  509. worshipState = 1
  510. end
  511. fontMemberNet(msgRet.targetList[len], rank, jjcData,worshipCnt,worshipState)
  512. end
  513. if len >= 3 then
  514. break
  515. end
  516. end
  517. else
  518. local minRate = 95
  519. local maxRate = 110
  520. while true do
  521. local minPoint = math.floor(humanPoint*minRate/100)
  522. local maxPoint = math.floor(humanPoint*maxRate/100)
  523. for k,v in pairs(JjcDB.RANK_2_JJCDATA) do
  524. if v.point > minPoint and v.point < maxPoint and v._id ~= human.db._id and choseUuid[v._id] == nil then
  525. count = count + 1
  526. areaList[count] = v._id
  527. choseUuid[v._id] = 1
  528. end
  529. end
  530. if count < 10 then
  531. minRate = minRate - 10
  532. maxRate = maxRate + 10
  533. else
  534. break
  535. end
  536. end
  537. for i = 1,3 do
  538. local index = 0
  539. while true do
  540. index = math.random(1,count)
  541. if areaList[index] ~= nil then
  542. break
  543. end
  544. end
  545. local uuid = areaList[index]
  546. areaList[index] = nil
  547. local rank = JjcDB.getRank(uuid)
  548. local v = JjcDB.RANK_2_JJCDATA[rank]
  549. local db = RoleDBLogic.getDb(uuid)
  550. if db == nil then
  551. fontMemberNet(msgRet.targetList[i], rank, v,0,0)
  552. else
  553. local worshipCnt = db.jjcBeWorship and db.jjcBeWorship or 0
  554. local worshipState = 0
  555. if db._id ~= human.db._id and (human.db.jjcWorship == nil or human.db.jjcWorship[v._id] == nil) then
  556. worshipState = 1
  557. end
  558. fontMemberNet(msgRet.targetList[i], rank, v,worshipCnt,worshipState)
  559. end
  560. JjcDB.updateRival(human.db._id,i,v._id)
  561. end
  562. end
  563. msgRet.targetList[0] = 3
  564. Msg.send(msgRet, human.fd)
  565. end
  566. -- 获取竞技场箱子奖励
  567. function getChampionBoxReward(human,index)
  568. local leftSec = getLeftSec()
  569. -- 竞技场未开,返回
  570. if leftSec == nil then
  571. return
  572. end
  573. local seasonBox = JjcDB.getJjcSeasonBox(human.db._id)
  574. local totalFight = JjcDB.getJjcTotalFight(human.db._id)
  575. if not seasonBox then
  576. return
  577. end
  578. local tItem = {}
  579. for nIndex, v in ipairs(JjcExcel.seasonBox) do
  580. -- 奖励已被领取
  581. if seasonBox[nIndex] == nil and totalFight >= v.reachCnt then
  582. JjcDB.updateSeasonBox(human.db._id, nIndex)
  583. for _, tData in ipairs(v.item) do
  584. if not tItem[tData[1]] then
  585. tItem[tData[1]] = 0
  586. end
  587. tItem[tData[1]] = tItem[tData[1]] + tData[2]
  588. end
  589. end
  590. end
  591. if nil ~= _G.next(tItem) then
  592. local tGoods = {}
  593. for nGoodID, nGoodNum in pairs(tItem) do
  594. table.insert(tGoods, {nGoodID, nGoodNum})
  595. end
  596. BagLogic.addItemList(human, tGoods, "jjc_season_box")
  597. RoleSystemLogic.onDot(human,RoleSystemDefine.ROLE_SYS_ID_1300)
  598. query(human)
  599. end
  600. -- -- 奖励已被领取
  601. -- if seasonBox and seasonBox[index] ~= nil then
  602. -- return
  603. -- end
  604. -- -- 参数错误
  605. -- local v = JjcExcel.seasonBox[index]
  606. -- if v == nil then
  607. -- return
  608. -- end
  609. -- -- 奖励未达成
  610. -- if totalFight < v.reachCnt then
  611. -- return
  612. -- end
  613. -- -- 写DB
  614. -- JjcDB.updateSeasonBox(human.db._id,index)
  615. -- -- 给物品
  616. -- BagLogic.addItemList(human, v.item, "jjc_season_box")
  617. -- RoleSystemLogic.onDot(human,RoleSystemDefine.ROLE_SYS_ID_1300)
  618. -- query(human)
  619. end
  620. function championWorship(human,uuid)
  621. -- 不能膜拜自己
  622. if uuid == human.db._id then
  623. return
  624. end
  625. -- 初始化膜拜数据
  626. human.db.jjcWorship = human.db.jjcWorship or {}
  627. human.db.jjcWorship.count = human.db.jjcWorship.count or 0
  628. -- 每日膜拜已达上限
  629. if human.db.jjcWorship.count >= JJC_WORSHIP_CNT then
  630. return Broadcast.sendErr(human, Lang.GODWAR_MOBAI_ERR)
  631. end
  632. -- 已膜拜过此玩家
  633. if human.db.jjcWorship[uuid] ~= nil then
  634. return Broadcast.sendErr(human, Lang.GODWAR_MOBAI_HAD)
  635. end
  636. -- 写数据库
  637. human.db.jjcWorship[uuid] = 1
  638. human.db.jjcWorship.count = human.db.jjcWorship.count + 1
  639. -- 写被膜拜玩家数据库
  640. local worshipCnt = 0
  641. local db = RoleDBLogic.getDb(uuid)
  642. if db == nil then
  643. JjcDB.updateWorshipCnt(uuid)
  644. worshipCnt = JjcDB.getWorshipCnt(uuid)
  645. else
  646. db.jjcBeWorship = db.jjcBeWorship or 0
  647. db.jjcBeWorship = db.jjcBeWorship + 1
  648. RoleDBLogic.saveRole(db)
  649. worshipCnt = db.jjcBeWorship
  650. end
  651. -- 给奖励
  652. BagLogic.addItem(human, ItemDefine.ITEM_JINBI_ID, JJC_WORSHIP_JINBI_CNT, "jjc_worship")
  653. Broadcast.sendErr(human, Util.format(Lang.JJC_WORSHIP_GOOD, JJC_WORSHIP_JINBI_CNT))
  654. local msgRet = Msg.gc.GC_JJC_CHAMPION_WORSHIP
  655. msgRet.worshipCnt = worshipCnt
  656. msgRet.dot = 1
  657. if human.db.jjcWorship.count >= 3 or human.db.lv < 9 then
  658. msgRet.dot = 0
  659. end
  660. Msg.send(msgRet,human.fd)
  661. end
  662. function championBillboardQuery(human)
  663. local flag = RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1301)
  664. if flag ~= true then
  665. return Broadcast.sendErr(human, Lang.JJC_OPEN_NEED_LV)
  666. end
  667. local leftSec = getLeftSec()
  668. if leftSec == nil then
  669. return Broadcast.sendErr(human, Lang.JJC_NOT_SET_OPEN_TIME)
  670. end
  671. local seasonBox = JjcDB.getJjcSeasonBox(human.db._id)
  672. local totalFight = JjcDB.getJjcTotalFight(human.db._id)
  673. local msgRet = Msg.gc.GC_JJC_CHAMPION_BILLBOARD_QUERY
  674. msgRet.leftSec = leftSec
  675. msgRet.topList[0] = 0
  676. for i = 1, #JjcDB.RANK_2_JJCDATA do
  677. if i > 100 then
  678. break
  679. end
  680. msgRet.topList[0] = msgRet.topList[0] + 1
  681. local dataTemp = JjcDB.RANK_2_JJCDATA[i]
  682. local db = RoleDBLogic.getDb(dataTemp._id)
  683. if db == nil then
  684. local worshipCnt = dataTemp.worshipCnt or 0
  685. local worshipState = 0
  686. if dataTemp._id ~= human.db._id and (human.db.jjcWorship == nil or human.db.jjcWorship[dataTemp._id] == nil) then
  687. worshipState = 1
  688. end
  689. fontMemberNet(msgRet.topList[msgRet.topList[0]], i, dataTemp,worshipCnt,worshipState)
  690. else
  691. local worshipCnt = db.jjcBeWorship or 0
  692. local worshipState = 0
  693. if db._id ~= human.db._id and (human.db.jjcWorship == nil or human.db.jjcWorship[dataTemp._id] == nil) then
  694. worshipState = 1
  695. end
  696. fontMemberNet(msgRet.topList[msgRet.topList[0]], i, dataTemp,worshipCnt,worshipState)
  697. end
  698. end
  699. local rank = JjcDB.UUID_2_RANK[human.db._id]
  700. local jjcData = JjcDB.RANK_2_JJCDATA[rank] or {}
  701. local worshipCnt = human.db.jjcBeWorship and human.db.jjcBeWorship or 0
  702. fontMemberNet(msgRet.ownRank, rank, jjcData,worshipCnt,0)
  703. msgRet.dotList[0] = 3
  704. msgRet.dotList[1] = championChallengeDot(human)
  705. msgRet.dotList[2] = championBillboardDot(human)
  706. msgRet.dotList[3] = championRecordDot(human)
  707. Msg.send(msgRet, human.fd)
  708. if rank > 0 and ((human.db.jjcBestRank or 0) <= 0 or rank < (human.db.jjcBestRank or 0)) then
  709. human.db.jjcBestRank = rank
  710. end
  711. end
  712. function onHour(hour)
  713. -- 判断是赛季结束还是每日结束
  714. if _G.is_middle == true then
  715. return
  716. end
  717. if hour == 4 then -- 错开整点一些处理
  718. Timer.addLater(11, JjcDB.cleanOldVideos)
  719. return
  720. end
  721. local openDay = CommonDB.getServerOpenDay()
  722. if openDay == nil then return end
  723. if hour == 21 then
  724. -- 发每日奖励
  725. local mailConfig = MailExcel.mail[MailDefine.MAIL_ID_JJC_DAY]
  726. local title = mailConfig.title
  727. local senderName = mailConfig.senderName
  728. local nowDateStr = HtmlUtil.getDataStr(os.time())
  729. -- 发每日奖励
  730. for i = 1, #JjcExcel.dayReward do
  731. local config = JjcExcel.dayReward[i]
  732. for j = config.rankMin, config.rankMax do
  733. local data = JjcDB.RANK_2_JJCDATA[j]
  734. if data == nil then
  735. break
  736. end
  737. if data.monsterOutID == nil then
  738. local content = Util.format(mailConfig.content, nowDateStr, j)
  739. MailManager.add(MailManager.SYSTEM, data._id, title, content, config.reward, senderName)
  740. end
  741. end
  742. end
  743. if openDay % JjcDB.SEASON_KEEP_DAY == 0 then
  744. -- 赛季结束结算
  745. Msg.sendWorld(Msg.gc.GC_JJC_SEASON_END)
  746. local mailConfig = MailExcel.mail[MailDefine.MAIL_ID_JJC_SEASON]
  747. local title = mailConfig.title
  748. local senderName = mailConfig.senderName
  749. -- 发每日奖励
  750. for i = 1, #JjcExcel.seasonReward do
  751. local config = JjcExcel.seasonReward[i]
  752. for j = config.rankMin, config.rankMax do
  753. local data = JjcDB.RANK_2_JJCDATA[j]
  754. if data == nil then
  755. break
  756. end
  757. if data.monsterOutID == nil then
  758. local content = Util.format(mailConfig.content, j)
  759. MailManager.add(MailManager.SYSTEM, data._id, title, content, config.reward, senderName)
  760. end
  761. end
  762. end
  763. -- reset数据
  764. JjcDB.resetJJCDB()
  765. -- 开启新赛季
  766. JjcDB.setSeasonEndTime()
  767. end
  768. return
  769. end
  770. end
  771. -- 获取剩余时间
  772. function getLeftSec()
  773. local endTime = JjcDB.getSeasonEndTime()
  774. if not endTime then return end
  775. return endTime - os.time()
  776. end
  777. function getHeroShareMonster(uuid, heroIndex)
  778. local jjcData = JjcDB.getJjcData(uuid)
  779. if not jjcData then return end
  780. if not jjcData.monsterOutID then return end
  781. local monsterOutConfig = MonsterExcel.monsterOut[jjcData.monsterOutID]
  782. if not monsterOutConfig then return end
  783. local mcf = monsterOutConfig.member[heroIndex]
  784. if not mcf then return end
  785. local monsterID = mcf[1]
  786. if not monsterID or monsterID < 1 then return end
  787. return monsterID, jjcData.lv
  788. end
  789. --------------- 以下内容是竞技场列表显示要用到的 start ---------------------------
  790. -- 额外参数设置
  791. function fontActArgs(args, human)
  792. args[0] = 2
  793. local rank,score = getActRank(human)
  794. args[1] = rank
  795. args[2] = score
  796. end
  797. function getActRank(human)
  798. local rank = JjcDB.getRank(human.db._id)
  799. local score = JjcDB.getJjcPoint(human.db._id)
  800. return math.max(rank, 0), math.max(score, 0) -- 0表示未上榜
  801. end
  802. function getActZhandouli(human)
  803. return CombatPosLogic.getCombatHeroZDL(human, CombatDefine.COMBAT_TYPE3, true)
  804. end
  805. -- 赛季开始时间段
  806. function getActDesc(desc)
  807. local endTime, startTime = JjcDB.getSeasonEndTime()
  808. if not endTime or not startTime then
  809. return Lang.COMMON_SYSTEM_NEED_OPENTIME
  810. end
  811. local d1 = os.date("*t", startTime)
  812. local d2 = os.date("*t", endTime)
  813. return Util.format(desc, d1.month .. "月" .. d1.day.."日", d2.month .. "月" .. d2.day.."日")
  814. end
  815. -- 活动状态
  816. function getActState()
  817. local endTime = JjcDB.getSeasonEndTime()
  818. if not endTime then
  819. return JjcActLogic.STATE_NOOPEN, 0
  820. end
  821. return JjcActLogic.STATE_START, endTime - os.time()
  822. end
  823. -- 红点
  824. function isActRed(human)
  825. if human.db.lv < 9 then
  826. return false
  827. end
  828. if championChallengeDot(human) == 1 then
  829. return true
  830. end
  831. if championBillboardDot(human) == 1 then
  832. return true
  833. end
  834. if championRecordDot(human) == 1 then
  835. return true
  836. end
  837. end
  838. function getCombatObjList(human, side, args)
  839. if side ~= CombatDefine.DEFEND_SIDE then return end
  840. local uuid = args[1]
  841. local jjcData = JjcDB.getJjcData(uuid)
  842. if not jjcData then return end
  843. if jjcData.monsterOutID then return end
  844. local target = CombatLogic.createCombatFakeHuman(uuid)
  845. if not target then return end
  846. return CombatLogic.getHumanObjList(target, CombatDefine.COMBAT_TYPE3)
  847. end
  848. function getCombatMonsterOutID(human, side, args)
  849. if side ~= CombatDefine.DEFEND_SIDE then return end
  850. local uuid = args[1]
  851. local jjcData = JjcDB.getJjcData(uuid)
  852. if not jjcData then return end
  853. if not jjcData.monsterOutID then return end
  854. return jjcData.monsterOutID, jjcData.zhandouli
  855. end
  856. function checkCombatPos(human, args, combatType)
  857. if combatType == CombatDefine.COMBAT_TYPE3 then
  858. return true
  859. end
  860. local uuid = args[1]
  861. local leftSec = getLeftSec()
  862. if leftSec == nil then
  863. return Broadcast.sendErr(human, Lang.JJC_NOT_SET_OPEN_TIME)
  864. end
  865. local jjcData = JjcDB.getJjcData(uuid)
  866. if not jjcData then return end
  867. -- 判断是否免费
  868. ObjHuman.updateDaily(human)
  869. local nowFightCnt = human.db.jjcDailyFight or 0
  870. if JJC_FREE_DAILY_CNT <= nowFightCnt then
  871. -- 判断是否有门票
  872. if BagLogic.getItemCnt(human, ItemDefine.ITEM_JJC_TICKET_ID) < 1 then
  873. return Broadcast.sendErr(human, Lang.JJC_ERR_FIGHT_NO_ITEM)
  874. end
  875. end
  876. return true, uuid
  877. end
  878. function fight(human, args, combatType)
  879. if combatType ~= CombatDefine.COMBAT_TYPE2 then return end
  880. local isok, uuid = checkCombatPos(human, args, combatType)
  881. if not isok then return end
  882. local nowFightCnt = human.db.jjcDailyFight or 0
  883. if JJC_FREE_DAILY_CNT <= nowFightCnt then
  884. -- 扣门票
  885. BagLogic.delItem(human, ItemDefine.ITEM_JJC_TICKET_ID, 1, "jjc_fight")
  886. end
  887. human.db.jjcDailyFight = (human.db.jjcDailyFight or 0) + 1
  888. JjcDB.updateTotalFight(human.db._id)
  889. JjcDB.updateTotalFightCnt(human.db._id)
  890. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE2, nil, true)
  891. if not combatHero or not next(combatHero) then
  892. CombatPosLogic.copyCombatHeros(human, CombatDefine.COMBAT_TYPE1, CombatDefine.COMBAT_TYPE2)
  893. end
  894. checkNeedJoin(human)
  895. CombatLogic.combatBegin(human, nil, args, CombatDefine.COMBAT_TYPE2, uuid)
  896. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_4, 1)
  897. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_5,1)
  898. MengxinLogic.onCallBack(human,MengxinLogic.MX_TASK_TYPE_3,1)
  899. HeroLogLogic.finishTaskCB(human,HeroLogLogic.HERO_LOG_TYPE_2,1)
  900. YunYingLogic.onCallBack(human, "onJjcFight",1)
  901. TriggerLogic.PublishEvent(TriggerDefine.EVENT_TYPE_CHAMPIONSNUM, human.db._id, 1)
  902. end
  903. -- 挑战结束
  904. function onFightEnd(human, result, combatType, defUuid, combatInfo)
  905. local defData = JjcDB.getJjcData(defUuid)
  906. local atkPoint = JjcDB.getJjcPoint(human.db._id)
  907. local defPoint = JjcDB.getJjcPoint(defUuid)
  908. local oldAtkPoint = atkPoint
  909. local oldDefPoint = defPoint
  910. local defHuman = ObjHuman.onlineUuid[defUuid]
  911. if result == CombatDefine.RESULT_WIN then
  912. if defHuman ~= nil then
  913. defHuman.jjcWinCount = nil
  914. end
  915. human.jjcWinCount = (human.jjcWinCount or 0) + 1
  916. JjcDB.cleanRival(human.db._id)
  917. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE8, human.jjcWinCount)
  918. LiLianLogic.onCallbackByCombat(human,combatInfo)
  919. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_15,1)
  920. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE7, 1)
  921. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE11, combatInfo)
  922. WarOrder.trigger(human,ARENA_ORDER_TYPE)
  923. else
  924. human.jjcWinCount = nil
  925. end
  926. MonthHzz.addJjcFight(human, result)
  927. atkPoint, defPoint = calcPoint(result, atkPoint, defPoint)
  928. -- 重置名字和头像
  929. if defData.monsterOutID then
  930. combatInfo.defender.head = defData.head
  931. combatInfo.defender.name = defData.name
  932. combatInfo.defender.lv = defData.lv
  933. combatInfo.defender.zhandouli = defData.zhandouli
  934. combatInfo.defender.uuid = defData._id
  935. end
  936. combatInfo.endParam = atkPoint .. "|" .. defPoint .. "|" .. (atkPoint - oldAtkPoint) .. "|" .. (defPoint - oldDefPoint)
  937. JjcDB.updatePlayerPoint(human.db._id, atkPoint, true)
  938. JjcDB.updatePlayerPoint(defUuid, defPoint, nil)
  939. -- 保存战斗记录
  940. JjcDB.addJjcRecord(human.db._id, defUuid, combatInfo)
  941. -- 保存战报 名次前20次
  942. local rank = JjcDB.getRank(human.db._id)
  943. if rank <= WarReportLogic.WAR_JJC_RANK then
  944. local defRank = JjcDB.getRank(defUuid)
  945. WarReportLogic.add(WarReportLogic.WAR_REPORT_1, combatInfo, rank, defRank)
  946. end
  947. -- 给奖励
  948. local totalWeight = 0
  949. for i = 1, #JjcExcel.fightReward do
  950. totalWeight = totalWeight + JjcExcel.fightReward[i].weight
  951. end
  952. local msgRet = Msg.gc.GC_JJC_AFTER_FIGHT
  953. msgRet.atkPoint = atkPoint
  954. msgRet.atkPointChange = atkPoint - oldAtkPoint
  955. msgRet.defPoint = defPoint
  956. msgRet.defPointChange = defPoint - oldDefPoint
  957. RoleLogic.makeRoleBase(combatInfo.defender,msgRet.defRole)
  958. RoleLogic.makeRoleBase(combatInfo.attacker,msgRet.atkRole)
  959. msgRet.items[0] = 1
  960. local randNum = math.random(1, totalWeight)
  961. local indexTemp = 1
  962. for i = 1, #JjcExcel.fightReward do
  963. if randNum <= JjcExcel.fightReward[i].weight then
  964. indexTemp = i
  965. break
  966. end
  967. randNum = randNum - JjcExcel.fightReward[i].weight
  968. end
  969. local itemID = JjcExcel.fightReward[indexTemp].itemID
  970. local itemCntMin = JjcExcel.fightReward[indexTemp].itemCnt1
  971. local itemCntMax = JjcExcel.fightReward[indexTemp].itemCnt2
  972. local itemCnt = math.random(itemCntMin, itemCntMax)
  973. -- 双倍结算
  974. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1301)
  975. local isDouble
  976. if double and (not human.db.jjcDailyFight or human.db.jjcDailyFight <= JJC_DOUBLE_CNT) then
  977. itemCnt = itemCnt * 2
  978. isDouble = true
  979. end
  980. BagLogic.addItem(human, itemID, itemCnt, "jjc_fight")
  981. Grid.makeItem(msgRet.items[1], itemID, itemCnt)
  982. msgRet.double = isDouble and 1 or 0
  983. msgRet.result = result
  984. Msg.send(msgRet, human.fd)
  985. human.db.jjcNewestRecord = os.time()
  986. -- 当被挑战玩家在线时,向被挑战玩家发送协议告知玩家被挑战
  987. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1300)
  988. if defHuman ~= nil then
  989. local msg = Msg.gc.GC_JJC_CHAMPION_BE_CHALLENGE
  990. Msg.send(msg, defHuman.fd)
  991. RoleSystemLogic.onDot(defHuman, RoleSystemDefine.ROLE_SYS_ID_1300)
  992. end
  993. end
  994. -- 获取 竞技场 剩余双倍次数
  995. function getJJCDoubleCnt(human)
  996. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1301)
  997. if double then
  998. if human.db.jjcDailyFight then
  999. local cnt = JJC_DOUBLE_CNT - human.db.jjcDailyFight
  1000. return cnt > 0 and cnt or 0
  1001. end
  1002. return JJC_DOUBLE_CNT
  1003. end
  1004. return 0
  1005. end
  1006. --------------------- about dot -------------------------------------
  1007. -- 冠军联赛挑战记录红点
  1008. function championRecordDot(human)
  1009. if human.db.lv < 9 then
  1010. return 0
  1011. end
  1012. -- 没有战斗记录,红点不亮
  1013. local recordList = JjcDB.getJjcRecordList(human.db._id)
  1014. if not recordList then
  1015. return 0
  1016. end
  1017. -- 有战斗记录,玩家没点开过战斗记录,红点亮
  1018. if human.db.jjcNewestRecord == nil then
  1019. return 1
  1020. end
  1021. local videoUuid = recordList[1]
  1022. local combatInfo = CombatVideo.getCombatVideo(videoUuid)
  1023. -- 最新一条战斗记录时间比上次点开战斗记录时间大,红点亮
  1024. if combatInfo and combatInfo.combatInfo.time > human.db.jjcNewestRecord then
  1025. return 1
  1026. end
  1027. -- 否则不亮
  1028. return 0
  1029. end
  1030. -- 冠军联赛挑战红点
  1031. function championChallengeDot(human)
  1032. if human.db.lv < 9 then
  1033. return 0
  1034. end
  1035. -- 今日挑战次数小于免费次数,红点亮
  1036. if human.db.jjcDailyFight == nil or human.db.jjcDailyFight < JJC_FREE_DAILY_CNT then
  1037. return 1
  1038. end
  1039. return boxRewardDot(human)
  1040. end
  1041. -- 冠军联赛排行榜红点
  1042. function championBillboardDot(human)
  1043. if human.db.lv < 9 then
  1044. return 0
  1045. end
  1046. -- 今日膜拜次数小于3次,红点亮
  1047. if human.db.jjcWorship == nil or human.db.jjcWorship.count < JJC_WORSHIP_DOT_CNT then
  1048. return 1
  1049. end
  1050. return 0
  1051. end
  1052. function boxRewardDot(human)
  1053. if human.db.lv < 9 then
  1054. return 0
  1055. end
  1056. local seasonBox = JjcDB.getJjcSeasonBox(human.db._id)
  1057. local totalFight = JjcDB.getJjcTotalFight(human.db._id)
  1058. local len = #JjcExcel.seasonBox
  1059. for i = 1,len do
  1060. if not seasonBox or not seasonBox[i] then
  1061. if totalFight >= JjcExcel.seasonBox[i].reachCnt then
  1062. return 1
  1063. end
  1064. end
  1065. end
  1066. return 0
  1067. end