JjcLogic.lua 41 KB

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