CopyLogic.lua 19 KB

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