CopyLogic.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. local Lang = require("common.Lang")
  2. local Msg = require("core.Msg")
  3. local ObjHuman = require("core.ObjHuman")
  4. local Util = require("common.Util")
  5. local CopyExcel = require("excel.copy")
  6. local Grid = require("bag.Grid")
  7. local RoleDefine = require("role.RoleDefine")
  8. local BagLogic = require("bag.BagLogic")
  9. local CombatDefine = require("combat.CombatDefine")
  10. local CombatLogic = require("combat.CombatLogic")
  11. local DailyTaskLogic = require("dailyTask.DailyTaskLogic")
  12. local ItemDefine = require("bag.ItemDefine")
  13. local Broadcast = require("broadcast.Broadcast")
  14. local Log = require("common.Log")
  15. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  16. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  17. local VipLogic = require("vip.VipLogic")
  18. local CombatPosLogic = require("combat.CombatPosLogic")
  19. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  20. local DragonNestLogic = require("copy.DragonNestLogic")
  21. local MengxinLogic = require("present.MengxinLogic")
  22. local YunYingLogic = require("yunying.YunYingLogic")
  23. COPY_TYPE_JINBI = 1 --金币挑战
  24. COPY_TYPE_EXP = 2 --经验挑战
  25. COPY_TYPE_SUIPIAN = 3 --英雄挑战
  26. COPY_TYPE_MOSHENG = 4 --魔神挑战
  27. COPY_TYPE_FUWEN = 5 --符文挑战
  28. COPY_TYPE_MAX = 5
  29. COPY_SAODANG_CAN = 1 --可扫荡
  30. function updateDaily(human)
  31. DragonNestLogic.updateDaily(human)
  32. if not human.db.copy then return end
  33. for i = COPY_TYPE_JINBI , COPY_TYPE_MAX do
  34. if human.db.copy[i] then
  35. human.db.copy[i].cnt = 0
  36. human.db.copy[i].buyCnt = 0
  37. end
  38. end
  39. end
  40. -- 挑战查询
  41. function isOpenByType(human,copyType,noSend)
  42. local copyConfig = CopyExcel.richang[copyType]
  43. if not copyConfig then return end
  44. if human.db.lv < copyConfig.lv then
  45. return
  46. end
  47. return true
  48. end
  49. function getMinZDLByType(copyType)
  50. for _,config in ipairs(CopyExcel.copy ) do
  51. if config.type == copyType then
  52. return config.zhandouliNeed
  53. end
  54. end
  55. return 0
  56. end
  57. local function isDotByType(human,copyType)
  58. if not isOpenByType(human, copyType, true) then
  59. return
  60. end
  61. local copyConfig = CopyExcel.copy[copyType]
  62. local zhandouli = CombatPosLogic.getCombatHeroZDL(human, CombatDefine.COMBAT_TYPE1)
  63. local minZDL = getMinZDLByType(copyType)
  64. if zhandouli < minZDL then
  65. return
  66. end
  67. local leftCnt = getLeftCnt(human, copyType)
  68. if leftCnt > 0 then
  69. return true
  70. end
  71. end
  72. local function getMaxID(human, copyType)
  73. local copyDB = human.db.copy
  74. if not copyDB then return 0 end
  75. return copyDB[copyType] and copyDB[copyType].maxID or 0
  76. end
  77. local function canSaoDang(human,copyType, id)
  78. return getMaxID(human, copyType) >= id and COPY_SAODANG_CAN or 0
  79. end
  80. -- 根据副本类型和等级获取copyID
  81. local TYPE_2_COPYLIST = nil
  82. local function getCopyIDByLv(copyType, level)
  83. if not TYPE_2_COPYLIST then
  84. TYPE_2_COPYLIST = {}
  85. for copyID, config in pairs(CopyExcel.copy) do
  86. if not TYPE_2_COPYLIST[config.type] then
  87. TYPE_2_COPYLIST[config.type] = {}
  88. end
  89. TYPE_2_COPYLIST[config.type][config.level] = copyID
  90. end
  91. end
  92. if not TYPE_2_COPYLIST[copyType] then
  93. return
  94. end
  95. return TYPE_2_COPYLIST[copyType][level]
  96. end
  97. function challengeQuery(human, copyType)
  98. local config = CopyExcel.richang[copyType]
  99. if not config then return end
  100. ObjHuman.updateDaily(human)
  101. local msgRet = Msg.gc.GC_COPY_CHALLENGE_QUERY
  102. msgRet.copyType = copyType
  103. msgRet.leftCnt = getLeftCnt(human, copyType)
  104. msgRet.maxCnt = getCurMaxCnt(human, copyType)
  105. msgRet.vipBuy = getCanBuyCnt(human, copyType)
  106. msgRet.vipNeed = config.zuanshi
  107. msgRet.vipBuyUpLv = VipLogic.getUpPowerNeedLv(human, VipLogic.VIP_POWER13) or 0
  108. msgRet.redList[0] = #CopyExcel.richang
  109. msgRet.copyList[0] = #CopyExcel.richang
  110. for i=1,#CopyExcel.richang do
  111. msgRet.redList[i] = isDotByType(human,i) and 1 or 0
  112. msgRet.copyList[i] = CopyExcel.richang[i].lv
  113. end
  114. local now = os.time()
  115. local ts1 = Util.getDayStartTime(now)
  116. msgRet.nextRefreshTime = 24 * 60 * 60 - (now - ts1)
  117. local j = 0 -- 存储相同副本类型的数量
  118. for i=1, #CopyExcel.copy do
  119. local copyConfig = CopyExcel.copy[i]
  120. if copyConfig and copyType == copyConfig.type then
  121. j = j + 1
  122. msgRet.list[j].id = i
  123. msgRet.list[j].level = copyConfig.level
  124. msgRet.list[j].lvNeed = copyConfig.lvNeed
  125. msgRet.list[j].zhandouliNeed = copyConfig.zhandouliNeed
  126. msgRet.list[j].reward[0] = #copyConfig.reward
  127. msgRet.list[j].saodang = canSaoDang(human,copyType,i) or 0
  128. for key,value in ipairs (copyConfig.reward) do
  129. local itemID = value[1]
  130. local itemCnt = value[2]
  131. Grid.makeItem(msgRet.list[j].reward[key], itemID, itemCnt)
  132. end
  133. end
  134. end
  135. msgRet.list[0] = j
  136. Msg.send(msgRet, human.fd)
  137. --Msg.trace(msgRet)
  138. end
  139. -- 挑战
  140. function fight(human, args)
  141. local isok, id, copyConfig = checkCombatPos(human, args)
  142. if not isok then return end
  143. -- 调用战斗接口
  144. CombatLogic.combatBegin(human, copyConfig.mapID, args, CombatDefine.COMBAT_TYPE7, id)
  145. end
  146. -- 获取当前地图ID
  147. function getMapID(human, args)
  148. local isok, id, copyConfig = checkCombatPos(human, args)
  149. if not isok then return end
  150. return copyConfig.mapID
  151. end
  152. function doFightEnd(human,copyID,combatInfo, touch)
  153. local copyConfig = CopyExcel.copy[copyID]
  154. if not copyConfig then return end
  155. ObjHuman.updateDaily(human)
  156. local copyType = copyConfig.type
  157. touch = tonumber(touch or 0)
  158. -- 金币挑战
  159. if copyType == COPY_TYPE_JINBI then
  160. Log.write(Log.LOGID_OSS_BATTLE_GOLD, human.db._id, human.db.account, human.db.name, human.db.lv)
  161. end
  162. -- 经验挑战
  163. if copyType == COPY_TYPE_EXP then
  164. Log.write(Log.LOGID_OSS_BATTLE_EXP, human.db._id, human.db.account, human.db.name, human.db.lv)
  165. end
  166. -- 碎片挑战
  167. if copyType == COPY_TYPE_SUIPIAN then
  168. Log.write(Log.LOGID_OSS_BATTLE_HERO, human.db._id, human.db.account, human.db.name, human.db.lv)
  169. end
  170. local leftCnt = getLeftCnt(human, copyType)
  171. local canBuy = getCanBuyCnt(human, copyType)
  172. local fightCnt = touch == 0 and 1 or leftCnt
  173. -- 改db
  174. human.db.copy = human.db.copy or {}
  175. human.db.copy[copyType] = human.db.copy[copyType] or {}
  176. local cnt = human.db.copy[copyType].cnt or 0
  177. human.db.copy[copyType].cnt = cnt + fightCnt
  178. local maxCopy = human.db.copy[copyType].maxID or 0
  179. if copyID > maxCopy then
  180. human.db.copy[copyType].maxID = copyID --实现成功挑战一次可扫荡逻辑
  181. end
  182. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1206)
  183. -- 给奖励
  184. local rewardRate = double and 2 or 1
  185. local itemList = {}
  186. for i = 1, #copyConfig.reward do
  187. local itemID = copyConfig.reward[i][1]
  188. local itemCnt = copyConfig.reward[i][2]
  189. BagLogic.addItem(human, itemID, itemCnt * rewardRate * fightCnt, "copy_win")
  190. local index = #itemList+1
  191. itemList[index] = {}
  192. itemList[index][1] = itemID
  193. itemList[index][2] = itemCnt * rewardRate * fightCnt
  194. if combatInfo and combatInfo.rewardItem then --为nil时是扫荡调用这个方法
  195. for j = 1, rewardRate do
  196. local nowTotalCnt = #combatInfo.rewardItem
  197. combatInfo.rewardItem[nowTotalCnt + 1] = {}
  198. combatInfo.rewardItem[nowTotalCnt + 1][1] = itemID
  199. combatInfo.rewardItem[nowTotalCnt + 1][2] = itemCnt * rewardRate * fightCnt
  200. end
  201. combatInfo.double = double and 2 or 0
  202. end
  203. end
  204. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_10, fightCnt)
  205. MengxinLogic.onCallBack(human,MengxinLogic.MX_TASK_TYPE_9,1)
  206. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1206)
  207. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  208. YunYingLogic.onCallBack(human, "onCopyFight", fightCnt)
  209. YunYingLogic.onCallBack(human, "onCopyChallenge",fightCnt)
  210. return itemList
  211. end
  212. -- 挑战结束
  213. function onFightEnd(human, result, combatType, copyID, combatInfo)
  214. local copyConfig = CopyExcel.copy[copyID]
  215. if not copyConfig then return end
  216. -- todo 太难打了,先改成必定打赢,晚点改回去
  217. if CombatDefine.RESULT_WIN == result then
  218. doFightEnd(human,copyID,combatInfo)
  219. end
  220. local copyTypeConfig = CopyExcel.richang[copyConfig.type]
  221. if copyTypeConfig then
  222. combatInfo.defender.name = copyTypeConfig.name
  223. combatInfo.panelID = copyTypeConfig.panelID
  224. end
  225. YunYingLogic.onCallBack(human, "onCopyChallenge",1)
  226. end
  227. -- 查询购买次数
  228. function buyChallengeQuery(human, copyType)
  229. do return end
  230. --[[
  231. local vipLv = VipLogic.getVipLv(human)
  232. if vipLv < 1 then
  233. return Broadcast.sendErr(human, Lang.COPY_BUY_CNT_ERR_VIP)
  234. end
  235. -- 次数判断
  236. local leftBuyCnt = getMaxBuyCnt(human) - getCurBuyCnt(human, copyType)
  237. if leftBuyCnt < 1 then
  238. return Broadcast.sendErr(human, Lang.COPY_BUY_CNT_ERR_CNT)
  239. end
  240. local msgRet = Msg.gc.GC_COPY_BUY_CHALLENGE_QUERY
  241. msgRet.copyType = copyType
  242. msgRet.needItemID = ItemDefine.ITEM_ZUANSHI_ID
  243. msgRet.needItemCnt = CopyExcel.richangDefine[1].zuanshi
  244. msgRet.curBuyCnt = getCurBuyCnt(human, copyType)
  245. msgRet.maxBuyCnt = getMaxBuyCnt(human)
  246. Msg.send(msgRet, human.fd)
  247. ]]
  248. end
  249. -- 购买挑战次数
  250. function buyChallengeCnt(human, copyType, buyCnt)
  251. do return end
  252. --[[
  253. if buyCnt < 1 then return end
  254. ObjHuman.updateDaily(human)
  255. -- 条件判断
  256. local maxBuyCnt = getMaxBuyCnt(human)
  257. local curBuyCnt = getCurBuyCnt(human, copyType)
  258. -- 最大购买次数判断
  259. if maxBuyCnt - curBuyCnt < buyCnt then
  260. return Broadcast.sendErr(human, Lang.COPY_BUY_CNT_ERR_CNT)
  261. end
  262. -- 钻石判断
  263. local needZuanshi = buyCnt * CopyExcel.richangDefine[1].zuanshi
  264. if not ObjHuman.checkRMB(human, needZuanshi) then
  265. return
  266. end
  267. local oldRed = isDotByType(human,copyType)
  268. -- 扣钻石
  269. ObjHuman.decZuanshi(human, -needZuanshi, "buy_challenge_cnt")
  270. -- 改db
  271. human.db.copy = human.db.copy or {}
  272. human.db.copy[copyType] = human.db.copy[copyType] or {}
  273. human.db.copy[copyType].buyCnt = curBuyCnt + buyCnt
  274. -- 通知客户端
  275. local msgRet = Msg.gc.GC_COPY_BUY_CHALLENGE_CNT
  276. msgRet.copyType = copyType
  277. msgRet.leftCnt = getLeftCnt(human, copyType)
  278. msgRet.maxCnt = getMaxCnt(human, copyType)
  279. Msg.send(msgRet, human.fd)
  280. local nowRed = isDotByType(human,copyType)
  281. if oldRed ~= nowRed then
  282. refreshRed(human,copyType,nowRed)
  283. end
  284. ]]
  285. end
  286. function getLeftCnt(human, copyType)
  287. local maxCnt = getMaxCnt(human, copyType)
  288. local nowCnt = 0
  289. if human.db.copy and human.db.copy[copyType] then
  290. nowCnt = human.db.copy[copyType].cnt or 0
  291. end
  292. return maxCnt - nowCnt
  293. end
  294. function getCurMaxCnt(human, copyType)
  295. local challengeCnt = CopyExcel.richang[copyType].challengeCnt
  296. local buyCnt = getMaxBuyCnt(human, copyType)
  297. local nowCnt = 0
  298. if human.db.copy and human.db.copy[copyType] then
  299. nowCnt = human.db.copy[copyType].cnt or 0
  300. end
  301. return buyCnt + challengeCnt - nowCnt
  302. end
  303. function getMaxCnt(human, copyType)
  304. local curBuyCnt = getCurBuyCnt(human, copyType)
  305. local challengeCnt = CopyExcel.richang[copyType].challengeCnt
  306. return challengeCnt + curBuyCnt
  307. end
  308. function getCanBuyCnt(human, copyType)
  309. return getMaxBuyCnt(human, copyType) - getCurBuyCnt(human, copyType)
  310. end
  311. function getCurBuyCnt(human, copyType)
  312. if human.db.copy == nil or human.db.copy[copyType] == nil or
  313. human.db.copy[copyType].buyCnt == nil then
  314. return 0
  315. end
  316. return human.db.copy[copyType].buyCnt
  317. end
  318. function getMaxBuyCnt(human, copyType)
  319. return VipLogic.getPowerArgs(human, VipLogic.VIP_POWER13) or 0
  320. end
  321. -- 副本列表日常副本红点
  322. function isDot(human)
  323. for i=1,#CopyExcel.richang do
  324. if isOpenByType(human,i,true) and isDotByType(human, i) then
  325. return true
  326. end
  327. end
  328. end
  329. function CG_COPY_CHALLENGE_SAODANG(human,copyID,touch)
  330. local copyConfig = CopyExcel.copy[copyID]
  331. if not copyConfig then return end
  332. local copyType = copyConfig.type
  333. if not canSaoDang(human,copyType,copyID) then return end
  334. local oldRed = isDotByType(human,copyType)
  335. if touch ~= 0 then
  336. if human.db.lv < 110 then return end
  337. end
  338. local args = {}
  339. args[1] = copyID
  340. args[2] = touch or 0
  341. local isok, id, copyConfig = checkCombatPos(human, args)
  342. if not isok then return end
  343. local itemList = doFightEnd(human,copyID, nil, args[2])
  344. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1206)
  345. local msgRet = Msg.gc.GC_COPY_CHALLENGE_SAODANG
  346. msgRet.copyType = copyType
  347. msgRet.copyID = copyID
  348. msgRet.double = double and 1 or 0
  349. msgRet.leftCnt = getLeftCnt(human, copyType)
  350. Msg.send(msgRet,human.fd)
  351. BagLogic.sendItemGetList(human,itemList, "copy_win")
  352. local nowRed = isDotByType(human,copyType)
  353. if oldRed ~= nowRed then
  354. refreshRed(human,copyType,nowRed)
  355. end
  356. challengeQuery(human, copyType)
  357. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1206)
  358. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  359. end
  360. function refreshRed(human,copyType,nowRed)
  361. local msgRet = Msg.gc.GC_COPY_CHALLENGE_RED
  362. msgRet.copyType = copyType
  363. msgRet.isRed = nowRed and 1 or 0
  364. Msg.send(msgRet,human.fd)
  365. end
  366. --------------------------------------------- combat ----------------------------------------------
  367. function getCombatMonsterOutID(human, side, args)
  368. if side ~= CombatDefine.DEFEND_SIDE then return end
  369. local id = tonumber(args[1] or 0)
  370. local copyConfig = CopyExcel.copy[id]
  371. if not copyConfig then return end
  372. return copyConfig.monsterOutID
  373. end
  374. function checkCombatPos(human, args)
  375. local id = tonumber(args[1] or 0)
  376. local touch = tonumber(args[2] or 0)
  377. local copyConfig = CopyExcel.copy[id]
  378. if not copyConfig then return end
  379. -- 等级判断
  380. if human.db.lv < copyConfig.lvNeed then
  381. return Broadcast.sendErr(human, Util.format(Lang.COMMON_SYSTEM_OPENTIP, copyConfig.lvNeed))
  382. end
  383. --获取全身 最高战力 6人组
  384. if human.db.zhandouli < copyConfig.zhandouliNeed then
  385. return Broadcast.sendErr(human, Util.format(Lang.COMMON_SYSTEM_OPENZHANLI, copyConfig.zhandouliNeed))
  386. end
  387. -- 前置副本要先打过
  388. local preCopyID = getCopyIDByLv(copyConfig.type, copyConfig.level - 1)
  389. if preCopyID and getMaxID(human, copyConfig.type) < preCopyID then
  390. return Broadcast.sendErr(human, Lang.COPY_FIGHT_ERR_PREID)
  391. end
  392. ObjHuman.updateDaily(human)
  393. local copyType = copyConfig.type
  394. local leftCnt = getLeftCnt(human, copyType)
  395. if touch == 0 then
  396. if leftCnt < 1 then
  397. local canBuy = getCanBuyCnt(human, copyType)
  398. if canBuy < 1 then
  399. return Broadcast.sendErr(human, Lang.COPY_FIGHT_ERR_NO_CNT)
  400. end
  401. -- 钻石判断
  402. local needZuanshi = CopyExcel.richang[copyType].zuanshi
  403. if not ObjHuman.checkRMB(human, needZuanshi) then
  404. return Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
  405. end
  406. -- 扣钻石
  407. ObjHuman.decZuanshi(human, -needZuanshi, "buy_challenge_cnt")
  408. -- 改db
  409. human.db.copy = human.db.copy or {}
  410. human.db.copy[copyType] = human.db.copy[copyType] or {}
  411. human.db.copy[copyType].buyCnt = human.db.copy[copyType].buyCnt or 0
  412. human.db.copy[copyType].buyCnt = human.db.copy[copyType].buyCnt + 1
  413. end
  414. else
  415. local canBuy = getCanBuyCnt(human, copyType)
  416. if canBuy < 1 then
  417. return Broadcast.sendErr(human, Lang.COPY_FIGHT_ERR_NO_CNT)
  418. end
  419. -- 钻石判断
  420. local needZuanshi = CopyExcel.richang[copyType].zuanshi * canBuy
  421. if not ObjHuman.checkRMB(human, needZuanshi) then
  422. return Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
  423. end
  424. -- 扣钻石
  425. ObjHuman.decZuanshi(human, -needZuanshi, "buy_challenge_cnt")
  426. -- 改db
  427. human.db.copy = human.db.copy or {}
  428. human.db.copy[copyType] = human.db.copy[copyType] or {}
  429. human.db.copy[copyType].buyCnt = human.db.copy[copyType].buyCnt or 0
  430. human.db.copy[copyType].buyCnt = human.db.copy[copyType].buyCnt + canBuy
  431. end
  432. return true, id, copyConfig
  433. end
  434. function onUpdatePos(human)
  435. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1206)
  436. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  437. end