CopyLogic.lua 18 KB

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