CopyLogic.lua 17 KB

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