MoshouLogic.lua 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417
  1. -- 魔兽 --
  2. Json = Json or require("common.Json")
  3. local Log = require("common.Log")
  4. local MoShouExcel = require("excel.moshou")
  5. local Msg = require("core.Msg")
  6. local Grid = require("bag.Grid")
  7. local CommonDB = require("common.CommonDB")
  8. local Broadcast = require("broadcast.Broadcast")
  9. local Lang = require("common.Lang")
  10. local ItemDefine = require("bag.ItemDefine")
  11. local RoleDefine = require("role.RoleDefine")
  12. local BagLogic = require("bag.BagLogic")
  13. local RoleAttr = require("role.RoleAttr")
  14. local SkillExcel = require("excel.skill")
  15. local HeroExcel = require("excel.hero")
  16. local ObjHuman = require("core.ObjHuman")
  17. local SkillExcel = require("excel.skill")
  18. local Util = require("common.Util")
  19. local CombatPosLogic = require("combat.CombatPosLogic")
  20. local CombatDefine = require("combat.CombatDefine")
  21. local CombatImpl = require("combat.CombatImpl")
  22. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  23. local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
  24. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  25. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  26. local BuyLogic = require("topup.BuyLogic")
  27. local YunYingLogic = require("yunying.YunYingLogic")
  28. -- human.db.moshou = {
  29. -- lv = nil --等级
  30. -- lvExp = nil --魔兽等级经验
  31. -- jingLian = nil --精炼
  32. -- zhuHun = nil --铸魂
  33. -- skillLV = nil --魔兽技能等级
  34. -- putOnMoshou = nil --已上阵魔兽
  35. -- xilian = nil -- 洗练
  36. -- }
  37. -- human.db.moshou[moshouID] = {
  38. -- taskGet = nil --魔兽激活任务领取
  39. -- }
  40. -- human.db.moshou[moshouID].taskGet[taskID] = nil --任务领取奖励即记录
  41. -- human.db.moshou.jingLian = jingLianLV --精炼等级
  42. -- human.db.moshou.zhuHun = zhuHunCnt --铸魂石已使用个数
  43. -- human.db.moshou.task[taskType] = cnt --任务类型->已完成数
  44. MOSHOU_SKILLLV_ARGE1 = 1 --魔兽技能等级限制 魔兽等级
  45. MOSHOU_SKILLLV_ARGE2 = 2 --魔兽技能等级限制 君主等级
  46. MOSHOU_JINGLIANLV_ARGE1 = 1 --魔兽精炼等级限制 魔兽等级
  47. MOSHOU_JINGLIANLV_ARGE2 = 2 --魔兽精炼等级限制 聚义厅等级
  48. MOSHOU_ID1 = 1 -- 魔兽ID
  49. MOSHOU_MIN_LEVEL = 4 -- 魔兽技能使用最低要求
  50. MOSHOU_SKILL = MOSHOU_SKILL or {}
  51. MOSHOU_XILIAN_OP_1 = 1 -- 洗练
  52. MOSHOU_XILIAN_OP_2 = 2 -- 保存洗练
  53. local function initMoShouSkill(moshouID)
  54. local moshouSkillExcel = MoShouExcel.moshouSkill
  55. if not MOSHOU_SKILL[moshouID] then
  56. for k, v in ipairs(moshouSkillExcel) do
  57. if v.moshouId == moshouID then
  58. MOSHOU_SKILL[moshouID] = MOSHOU_SKILL[moshouID] or {}
  59. MOSHOU_SKILL[moshouID][k] = v.moshouSkill
  60. end
  61. end
  62. end
  63. end
  64. function initXilian()
  65. for _, config in ipairs(MoShouExcel.moshouxlRandom) do
  66. config.rareSum1 = 0
  67. config.rareSum2 = 0
  68. for i = config.random[1], config.random[2] do
  69. local templeConfig = MoShouExcel.moshouXiLian[i]
  70. config.rareSum1 = config.rareSum1 + templeConfig.rare1
  71. config.rareSum2 = config.rareSum2 + templeConfig.rare2
  72. end
  73. end
  74. for _, config in ipairs(MoShouExcel.moshouXiLian) do
  75. local rare = 0
  76. for k, v in ipairs(config.attrs1) do
  77. rare = rare + v[3]
  78. end
  79. config.attrRareMax = rare
  80. end
  81. end
  82. function initAfterHot()
  83. initMoShouSkill(MOSHOU_ID1)
  84. initXilian()
  85. end
  86. local function makeMoshouLvAttrs(human, net, moshouID)
  87. net[0] = 0
  88. local nowLV = getMoshouLv(human)
  89. local config = MoShouExcel.moshouLv[nowLV]
  90. if config then
  91. net[0] = #config.lvAttrs
  92. for i = 1, #config.lvAttrs do
  93. net[i].key = config.lvAttrs[i][1]
  94. net[i].value = config.lvAttrs[i][2]
  95. end
  96. end
  97. local lvAttrsAdd = human.db.moshou and human.db.moshou.lvAttrsAdd or nil
  98. if lvAttrsAdd then
  99. for k,v in pairs(lvAttrsAdd) do
  100. for i=1,#config.lvAttrs do
  101. if net[i].key == k then
  102. net[i].value = net[i].value + v
  103. end
  104. end
  105. end
  106. end
  107. end
  108. local function makeMoshouLvUp(human, net)
  109. net[0] = 0
  110. local nowLV = getMoshouLv(human)
  111. if nowLV >= #MoShouExcel.moshouLv then return end
  112. net[0] = 1
  113. net[1].nowJinDu = human.db.moshou and human.db.moshou.lvExp or 0
  114. local nextConfig = MoShouExcel.moshouLv[nowLV + 1]
  115. net[1].needJinDu = nextConfig.needJinDu
  116. net[1].needItem[0] = #nextConfig.lvUpNeed
  117. for i = 1, #nextConfig.lvUpNeed do
  118. local itemID = nextConfig.lvUpNeed[i][1]
  119. local itemCnt = nextConfig.lvUpNeed[i][2]
  120. Grid.makeItem(net[1].needItem[i], itemID, itemCnt)
  121. end
  122. end
  123. local function makeMoshouLvUpNet(net, human, moshouID)
  124. local config = MoShouExcel.moshouActive[MOSHOU_ID1]
  125. net.moshouID = moshouID
  126. net.name = config.moshouName
  127. net.body = config.body
  128. net.moshouLv = getMoshouLv(human)
  129. makeMoshouLvAttrs(human, net.lvAttrs, moshouID)
  130. makeMoshouLvUp(human, net.moshouLvUp)
  131. end
  132. local function makeMoshouReds(net, human)
  133. net.lvUpRed = moshouLVupRed(human) and 1 or 0
  134. net.jinglianRed = moshouJinglianRed(human) and 1 or 0
  135. net.zhuHunRed = moshouZhunHunRed(human) and 1 or 0
  136. net.skillRed = moshouSkillUpRed(human) and 1 or 0
  137. net.xilianRed = moshouXilianUpRed(human) and 1 or 0
  138. end
  139. local function makeJingLianLvData(human, net, attr, targrtLv)
  140. net.lv = targrtLv
  141. net.attr.key = attr[1]
  142. net.attr.value = attr[2]
  143. end
  144. function moshouLvUpQuery(human, moshouID)
  145. local msgRet = Msg.gc.GC_MOSHOU_LVUP_QUERY
  146. local config = MoShouExcel.moshouActive[MOSHOU_ID1]
  147. if not config then return end
  148. makeMoshouLvUpNet(msgRet.moshouLv, human, MOSHOU_ID1)
  149. makeMoshouReds(msgRet.moshouReds, human)
  150. msgRet.jingLianLvData[0] = 0
  151. local nowLV = getMoShouJiLian(human)
  152. local nowConfig = MoShouExcel.moshouJingLian[nowLV]
  153. if nowConfig then
  154. msgRet.jingLianLvData[0] = 1
  155. makeJingLianLvData(human, msgRet.jingLianLvData[1], nowConfig.lvAttrs, nowLV)
  156. end
  157. msgRet.xilianOpen = xilianIsOpen(human)
  158. Msg.send(msgRet, human.fd)
  159. end
  160. local function makeMoshouSkill(human, net, moshouID, posSkillID)
  161. local len = 0
  162. local skillLV = getMoShouSkillLv(human)
  163. for k, v in ipairs(MOSHOU_SKILL[moshouID]) do
  164. local skillID = v[skillLV]
  165. if skillID then
  166. local skillConfig = SkillExcel.skill[skillID]
  167. len = len + 1
  168. if len > #net then
  169. break
  170. end
  171. net[len].id = skillID
  172. net[len].icon = skillConfig.icon
  173. net[len].name = skillConfig.name
  174. net[len].desc = skillConfig.desc
  175. net[len].lv = skillLV
  176. net[len].index = k
  177. net[len].state = 1
  178. if k == posSkillID then
  179. net[len].state = 2
  180. end
  181. end
  182. end
  183. net[0] = len
  184. end
  185. function makeXilianQuery(human, msgRet)
  186. msgRet.list[0] = 0
  187. if human.db.moshou and human.db.moshou.xilian then
  188. for k, db in ipairs(human.db.moshou.xilian) do
  189. local net = msgRet.list[k]
  190. local config = MoShouExcel.moshouXiLian[db.id]
  191. net.id = db.id
  192. net.index = k
  193. net.rare = config.pinzhiLv
  194. net.name = config.name
  195. net.lv = config.pinzhi
  196. -- print(" net.rare ", net.rare , net.lv, db.type)
  197. net.attrs[1].key = db.key
  198. net.attrs[1].value = db.value
  199. net.attrs[0] = 1
  200. net.needZuanshi = getXilianNeed(config, MOSHOU_XILIAN_OP_2, k)
  201. Grid.makeItem(net.item, ItemDefine.ITEM_LONGXUE_ID , getXilianNeed(config, MOSHOU_XILIAN_OP_1, k))
  202. net.nextRate = 0
  203. net.nextAttr[0] = 0
  204. net.nextName = ""
  205. local lastID = db.lastId
  206. if lastID and db.lastKey then
  207. local lastConfig = MoShouExcel.moshouXiLian[lastID]
  208. net.nextRate = lastConfig.pinzhiLv
  209. net.nextAttr[1].key = db.lastKey
  210. net.nextAttr[1].value = db.lastValue
  211. net.nextAttr[0] = 1
  212. net.nextName = lastConfig.name
  213. end
  214. end
  215. msgRet.list[0] = #human.db.moshou.xilian
  216. end
  217. end
  218. -- 刚打开魔兽界面查询 moshouID默认1
  219. -- 魔兽已全部激活 返回升级界面协议
  220. -- 魔兽未全部激活 返回魔兽激活任务协议(已激活的魔兽+正在完成任务的魔兽)
  221. function CG_MOSHOU_QUERY(human, moshouID)
  222. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  223. if not cjPrivilege then return end
  224. -- 升级界面协议
  225. moshouLvUpQuery(human, moshouID)
  226. end
  227. function CG_MOSHOU_LVUP_UP(human, upType)
  228. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  229. if not cjPrivilege then return end
  230. local nowLV = getMoshouLv(human)
  231. local maxLV = #MoShouExcel.moshouLv
  232. if nowLV >= maxLV then
  233. Broadcast.sendErr(human,Lang.MOSHOU_LV_UP_ERR)
  234. return
  235. end
  236. local config = MoShouExcel.moshouLv[nowLV+1]
  237. local lvUpNeed = config.lvUpNeed
  238. for i=1,#lvUpNeed do
  239. local itemID = lvUpNeed[i][1]
  240. local itemCnt = lvUpNeed[i][2]
  241. local now = BagLogic.getItemCnt(human, itemID)
  242. if now < itemCnt then
  243. Broadcast.sendErr(human,Lang.MOSHOU_LV_UP_NOT)
  244. return
  245. end
  246. end
  247. for i=1,#lvUpNeed do
  248. local itemID = lvUpNeed[i][1]
  249. local itemCnt = lvUpNeed[i][2]
  250. BagLogic.delItem(human, itemID, itemCnt, "moshou")
  251. end
  252. local nowConf = MoShouExcel.moshouLv[nowLV]
  253. local upGetJinDuCnf = nowConf.upGetJinDu
  254. local totalWeight = nil
  255. for i=1,#upGetJinDuCnf do
  256. totalWeight = (totalWeight or 0) + upGetJinDuCnf[i][2]
  257. end
  258. if not totalWeight then return end
  259. local weight = nil
  260. local upGetJinDuIndex = nil
  261. local randWeight = math.random(1,totalWeight)
  262. for i=1,#upGetJinDuCnf do
  263. weight = (weight or 0) + upGetJinDuCnf[i][2]
  264. if randWeight <= weight then
  265. upGetJinDuIndex = i
  266. break
  267. end
  268. end
  269. if not upGetJinDuIndex then return end
  270. local upGetJinDu = upGetJinDuCnf[upGetJinDuIndex][1]
  271. local lvAttrsAddCnf = nowConf.lvAttrsAdd[upGetJinDuIndex]
  272. local lvUpState = false
  273. human.db.moshou = human.db.moshou or {}
  274. human.db.moshou.lvExp = (human.db.moshou.lvExp or 0) + upGetJinDu
  275. if human.db.moshou.lvExp >= config.needJinDu * config.upNeedRate then
  276. human.db.moshou.lv = getMoshouLv(human)
  277. human.db.moshou.lv = human.db.moshou.lv + 1
  278. human.db.moshou.lvExp = 0
  279. human.db.moshou.lvAttrsAdd = nil
  280. lvUpState = true
  281. -- 守护之龙的等级记录
  282. Log.write(Log.LOGID_OSS_DRAGON_LEVEL, human.db._id, human.db.account, human.db.name, human.db.moshou.lv, getMoShouSkillLv(human))
  283. else
  284. human.db.moshou.lvAttrsAdd = human.db.moshou.lvAttrsAdd or {}
  285. for i=1,#lvAttrsAddCnf do
  286. local key = lvAttrsAddCnf[i][1]
  287. local value = lvAttrsAddCnf[i][2]
  288. human.db.moshou.lvAttrsAdd[key] = (human.db.moshou.lvAttrsAdd[key] or 0) + value
  289. end
  290. end
  291. local msgRet = Msg.gc.GC_MOSHOU_LVUP_UP
  292. makeMoshouLvAttrs(human,msgRet.lvAttrs)
  293. makeMoshouLvUp(human,msgRet.moshouLvUp)
  294. msgRet.moshouLv = getMoshouLv(human)
  295. Msg.send(msgRet,human.fd)
  296. moshouLvUpQuery(human)
  297. RoleAttr.cleanHeroAttrCache(human)
  298. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2002)
  299. if lvUpState then
  300. moshouLvUpToXilianBreak(human)
  301. end
  302. end
  303. local function getLangByCanUpType(human,canUpType)
  304. if canUpType == MOSHOU_SKILLLV_ARGE1 then
  305. return Lang.MOSHOU_UP_DESC_MOSHOULV
  306. elseif canUpType == MOSHOU_SKILLLV_ARGE2 then
  307. return Lang.MOSHOU_UP_DESC_JUNZHU
  308. elseif canUpType == MOSHOU_JINGLIANLV_ARGE1 then
  309. return Lang.MOSHOU_UP_DESC_MOSHOULV
  310. elseif canUpType == MOSHOU_JINGLIANLV_ARGE2 then
  311. return Lang.MOSHOU_UP_DESC_JUYI
  312. end
  313. end
  314. local function getSkillCanUpNeed(human)
  315. local skillLV = getMoShouSkillLv(human)
  316. if skillLV >= #MoShouExcel.moshouSkillLv then
  317. return 0,0
  318. end
  319. local nextConf = MoShouExcel.moshouSkillLv[skillLV+1]
  320. return nextConf.canUpNeed[1] or 0,nextConf.canUpNeed[2] or 0
  321. end
  322. local function getSkillMaxLV(human)
  323. local moshouLV = getMoshouLv(human)
  324. local conf = MoShouExcel.moshouSkillLv
  325. local skillLV = getMoShouSkillLv(human)
  326. if skillLV >= #conf then
  327. return skillLV
  328. end
  329. for i=skillLV+1,#conf do
  330. local arge = conf[i].canUpNeed[1]
  331. local argeNeed = conf[i].canUpNeed[2]
  332. if arge == MOSHOU_SKILLLV_ARGE1 then
  333. if moshouLV < argeNeed then
  334. return i - 1
  335. end
  336. elseif arge == MOSHOU_SKILLLV_ARGE2 then
  337. return 0
  338. end
  339. end
  340. return #conf
  341. end
  342. function CG_MOSHOU_SKILL_QUERY(human, moshouID)
  343. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  344. if not cjPrivilege then return end
  345. if not MoShouExcel.moshouActive[MOSHOU_ID1] then return end
  346. local msgRet = Msg.gc.GC_MOSHOU_SKILL_QUERY
  347. msgRet.moshouID = MOSHOU_ID1
  348. makeMoshouSkill(human, msgRet.moshouSkill, MOSHOU_ID1)
  349. local moshouLV = getMoshouLv(human)
  350. local skillMaxLv = getSkillMaxLV(human)
  351. msgRet.skillMaxLv = skillMaxLv
  352. msgRet.needItem[0] = 0
  353. local skillLV = getMoShouSkillLv(human)
  354. local config = MoShouExcel.moshouSkillLv[skillLV + 1]
  355. if config and skillLV < skillMaxLv then
  356. msgRet.needItem[0] = #config.upCost
  357. for i = 1, #config.upCost do
  358. local itemID = config.upCost[i][1]
  359. local itemCnt = config.upCost[i][2]
  360. Grid.makeItem(msgRet.needItem[i], itemID, itemCnt)
  361. end
  362. end
  363. msgRet.skillCanUp = ""
  364. if skillLV >= #MoShouExcel.moshouSkillLv then
  365. msgRet.skillCanUp = Lang.MOSHOU_SKILL_LV_MAX
  366. else
  367. if skillLV >= skillMaxLv then
  368. local arge,argeNeed = getSkillCanUpNeed(human)
  369. local content = getLangByCanUpType(human,arge)
  370. if content then
  371. content = Util.format(content,argeNeed)
  372. msgRet.skillCanUp = content
  373. end
  374. end
  375. end
  376. Msg.send(msgRet, human.fd)
  377. end
  378. function CG_MOSHOU_SKILL_UP(human, moshouID)
  379. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  380. if not cjPrivilege then return end
  381. if not MoShouExcel.moshouActive[MOSHOU_ID1] then return end
  382. if not MOSHOU_SKILL[moshouID] then return end
  383. local moshouLV = getMoshouLv(human)
  384. local skillLV = getMoShouSkillLv(human)
  385. local config = MoShouExcel.moshouSkillLv
  386. if skillLV >= #config then return end
  387. local nextSkillLv = skillLV + 1
  388. if not MOSHOU_SKILL[moshouID][1][nextSkillLv] then return end
  389. local nowArgeCnt = nil
  390. local canUpNeedType = config[nextSkillLv].canUpNeed[1] or 0
  391. local canUpNeedValue = config[nextSkillLv].canUpNeed[2] or 0
  392. if canUpNeedType == MOSHOU_SKILLLV_ARGE1 then
  393. nowArgeCnt = moshouLV
  394. else
  395. return
  396. end
  397. if not nowArgeCnt then return end
  398. if nowArgeCnt < canUpNeedValue then return end
  399. local upCost = config[nextSkillLv].upCost
  400. for i = 1, #upCost do
  401. local itemID = upCost[i][1]
  402. local itemCnt = upCost[i][2]
  403. local nowCnt = BagLogic.getItemCnt(human, itemID)
  404. if nowCnt < itemCnt then return Broadcast.sendErr(human, Lang.MOSHOU_LV_UP_NOT) end
  405. end
  406. for i = 1, #upCost do
  407. local itemID = upCost[i][1]
  408. local itemCnt = upCost[i][2]
  409. BagLogic.delItem(human, itemID, itemCnt, "moshou")
  410. end
  411. human.db.moshou = human.db.moshou or {}
  412. human.db.moshou.skillLV = nextSkillLv
  413. Log.write(Log.LOGID_OSS_DRAGON_LEVEL, human.db._id, human.db.account, human.db.name, human.db.moshou.lv, getMoShouSkillLv(human))
  414. Broadcast.sendErr(human, Lang.MOSHOU_SKILL_LV_UP)
  415. moshouLvUpQuery(human)
  416. CG_MOSHOU_SKILL_QUERY(human, moshouID)
  417. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2002)
  418. end
  419. function CG_MOSHOU_JINGLIAN_QUERY(human)
  420. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  421. if not cjPrivilege then return end
  422. local msgRet = Msg.gc.GC_MOSHOU_JINGLIAN_QUERY
  423. local jinglianLV = getMoShouJiLian(human)
  424. local moshouLV = getMoshouLv(human)
  425. local jingLianConfig = MoShouExcel.moshouJingLian
  426. local jingLianCanLV = #jingLianConfig
  427. msgRet.jingLianCanLV = jingLianCanLV
  428. msgRet.nowLvData[0] = 0
  429. msgRet.nextLvData[0] = 0
  430. msgRet.needItem[0] = 0
  431. local nowLV = getMoShouJiLian(human)
  432. local nextConfig = MoShouExcel.moshouJingLian[nowLV + 1]
  433. if nextConfig then
  434. local showLeft = nextConfig.showLeft
  435. local showRight = nextConfig.showRight
  436. msgRet.nowLvData[0] = 1
  437. makeJingLianLvData(human, msgRet.nowLvData[1], showLeft, nowLV)
  438. msgRet.nextLvData[0] = 1
  439. makeJingLianLvData(human, msgRet.nextLvData[1], showRight, nowLV + 1)
  440. msgRet.needItem[0] = #nextConfig.lvUpNeed
  441. for i = 1, #nextConfig.lvUpNeed do
  442. local itemID = nextConfig.lvUpNeed[i][1]
  443. local itemCnt = nextConfig.lvUpNeed[i][2]
  444. Grid.makeItem(msgRet.needItem[i], itemID, itemCnt)
  445. end
  446. else
  447. local nowConfig = MoShouExcel.moshouJingLian[nowLV]
  448. msgRet.nowLvData[0] = 1
  449. makeJingLianLvData(human, msgRet.nowLvData[1], nowConfig.lvAttrs, nowLV)
  450. end
  451. msgRet.attrs[0] = 0
  452. local attrs = nil
  453. if jingLianConfig[jinglianLV] then
  454. attrs = { }
  455. for i = 1, jinglianLV do
  456. local key = jingLianConfig[i].lvAttrs[1]
  457. local value = jingLianConfig[i].lvAttrs[2]
  458. attrs[key] =(attrs[key] or 0) + value
  459. end
  460. end
  461. if attrs then
  462. for key, value in pairs(attrs) do
  463. msgRet.attrs[0] = msgRet.attrs[0] + 1
  464. local index = msgRet.attrs[0]
  465. msgRet.attrs[index].key = key
  466. msgRet.attrs[index].value = value
  467. end
  468. end
  469. -- Msg.trace(msgRet)
  470. Msg.send(msgRet, human.fd)
  471. end
  472. function CG_MOSHOU_JINGLIAN_DO(human)
  473. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  474. if not cjPrivilege then return end
  475. local jingLianLV = getMoShouJiLian(human)
  476. local moshouLV = getMoshouLv(human)
  477. local jingLianMaxLV = #MoShouExcel.moshouJingLian
  478. if jingLianLV >= jingLianMaxLV then return end
  479. local nextConfig = MoShouExcel.moshouJingLian[jingLianLV + 1]
  480. local lvUpNeed = nextConfig.lvUpNeed
  481. for i = 1, #lvUpNeed do
  482. local itemID = lvUpNeed[i][1]
  483. local itemCnt = lvUpNeed[i][2]
  484. local nowCnt = BagLogic.getItemCnt(human, itemID)
  485. if nowCnt < itemCnt then return Broadcast.sendErr(human, Lang.MOSHOU_LV_UP_NOT) end
  486. end
  487. for i = 1, #lvUpNeed do
  488. local itemID = lvUpNeed[i][1]
  489. local itemCnt = lvUpNeed[i][2]
  490. BagLogic.delItem(human, itemID, itemCnt, "moshou")
  491. end
  492. human.db.moshou = human.db.moshou or { }
  493. human.db.moshou.jingLian = jingLianLV + 1
  494. Broadcast.sendErr(human, Lang.MOSHOU_JINGLIAN_LV_UP)
  495. CG_MOSHOU_JINGLIAN_QUERY(human)
  496. RoleAttr.cleanHeroAttrCache(human)
  497. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2002)
  498. end
  499. function CG_MOSHOU_ZHUHUN_QUERY(human)
  500. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  501. if not cjPrivilege then return end
  502. local msgRet = Msg.gc.GC_MOSHOU_ZHUHUN_QUERY
  503. local config = MoShouExcel.moshouZhuHun[1]
  504. Grid.makeItem(msgRet.needItem, config.costID, 1)
  505. msgRet.nowAttr[0] = 0
  506. local nowUseCnt = human.db.moshou and human.db.moshou.zhuHun or 0
  507. if nowUseCnt > 0 then
  508. msgRet.nowAttr[0] = #config.zhuHunAttrs
  509. for i = 1, #config.zhuHunAttrs do
  510. msgRet.nowAttr[i].key = config.zhuHunAttrs[i][1]
  511. msgRet.nowAttr[i].value = config.zhuHunAttrs[i][2] + config.addZhuHun * nowUseCnt
  512. end
  513. end
  514. msgRet.nowUseCnt = nowUseCnt
  515. local moshouLV = getMoshouLv(human)
  516. local zhuHunCntMax = MoShouExcel.moshouLv[moshouLV].zhuHunCntMax
  517. msgRet.maxUseCan = zhuHunCntMax
  518. Msg.send(msgRet, human.fd)
  519. end
  520. function CG_MOSHOU_ZHUHUN_DO(human, useCnt)
  521. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  522. if not cjPrivilege then return end
  523. local moshouLV = getMoshouLv(human)
  524. local zhuHunCntMax = MoShouExcel.moshouLv[moshouLV].zhuHunCntMax
  525. local nowUseCnt = human.db.moshou and human.db.moshou.zhuHun or 0
  526. if nowUseCnt >= zhuHunCntMax or(nowUseCnt + useCnt) > zhuHunCntMax then return Broadcast.sendErr(human, Lang.MOSHOU_ZHUHUN_MAX) end
  527. local config = MoShouExcel.moshouZhuHun[1]
  528. local nowCnt = BagLogic.getItemCnt(human, config.costID)
  529. if useCnt > nowCnt then return Broadcast.sendErr(human, Lang.MOSHOU_LV_UP_NOT) end
  530. BagLogic.delItem(human, config.costID, useCnt, "moshou")
  531. human.db.moshou = human.db.moshou or { }
  532. human.db.moshou.zhuHun = nowUseCnt + useCnt
  533. Broadcast.sendErr(human, Lang.MOSHOU_ZHUHUN_LV_UP)
  534. CG_MOSHOU_ZHUHUN_QUERY(human)
  535. RoleAttr.cleanHeroAttrCache(human)
  536. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2002)
  537. end
  538. local function makeMoshouPutOn(human, net, moshouID)
  539. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  540. if not cjPrivilege then return end
  541. net.moshouID = MOSHOU_ID1
  542. local config = MoShouExcel.moshouActive[MOSHOU_ID1]
  543. net.moshouName = config.moshouName
  544. net.moshouIcon = config.icon
  545. net.moshouLv = getMoshouLv(human)
  546. makeMoshouSkill(human, net.moshouSkill, MOSHOU_ID1)
  547. end
  548. -- 上阵界面 查询魔兽信息
  549. function CG_MOSHOU_PUT_QUERY(human)
  550. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  551. if not cjPrivilege then return end
  552. local config = MoShouExcel.moshouActive
  553. local msgRet = Msg.gc.GC_MOSHOU_PUT_QUERY
  554. msgRet.moshouPutOn[0] = #config
  555. for i = 1, #config do
  556. makeMoshouPutOn(human, msgRet.moshouPutOn[i], i)
  557. end
  558. Msg.send(msgRet, human.fd)
  559. end
  560. function doCalcHero(human, heroGrid, attrs)
  561. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  562. if not cjPrivilege then return end
  563. -- 魔兽等级属性加成
  564. local nowLV = getMoshouLv(human)
  565. local moshouLvConfig = MoShouExcel.moshouLv[nowLV]
  566. if moshouLvConfig and #moshouLvConfig.lvAttrs > 0 then
  567. local lvAttrs = nil
  568. for i=1,#moshouLvConfig.lvAttrs do
  569. local key = moshouLvConfig.lvAttrs[i][1]
  570. local value = moshouLvConfig.lvAttrs[i][2]
  571. lvAttrs = lvAttrs or {}
  572. lvAttrs[key] = (lvAttrs[key] or 0) + value
  573. end
  574. if human.db.moshou and human.db.moshou.lvAttrsAdd then
  575. local lvAttrsAdd = human.db.moshou.lvAttrsAdd
  576. for k,v in pairs(lvAttrsAdd) do
  577. lvAttrs = lvAttrs or {}
  578. lvAttrs[k] = (lvAttrs[k] or 0) + v
  579. end
  580. end
  581. if lvAttrs then
  582. for k,v in pairs(lvAttrs) do
  583. RoleAttr.updateValue(k,v,attrs)
  584. end
  585. end
  586. end
  587. --魔兽精练等级属性加成
  588. local jingLianLV = human.db.moshou and human.db.moshou.jingLian or 0
  589. local jingLianConfig = MoShouExcel.moshouJingLian
  590. if jingLianConfig[jingLianLV] then
  591. for i=1,jingLianLV do
  592. local key = jingLianConfig[i].lvAttrs[1]
  593. local value = jingLianConfig[i].lvAttrs[2]
  594. RoleAttr.updateValue(key,value,attrs)
  595. end
  596. end
  597. --魔兽铸魂属性加成
  598. local zhuHun = human.db.moshou and human.db.moshou.zhuHun or 0
  599. local zhuHunConfig = MoShouExcel.moshouZhuHun[1]
  600. if zhuHun > 0 and #zhuHunConfig.zhuHunAttrs > 0 then
  601. for i=1,#zhuHunConfig.zhuHunAttrs do
  602. RoleAttr.updateValue(zhuHunConfig.zhuHunAttrs[i][1],zhuHunConfig.zhuHunAttrs[i][2] * zhuHun,attrs)
  603. end
  604. end
  605. -- 魔兽洗练的加成
  606. if human.db.moshou and human.db.moshou.xilian then
  607. for k, db in ipairs(human.db.moshou.xilian) do
  608. if db and db.key and db.value ~= 0 then
  609. RoleAttr.updateValue(db.key ,db.value ,attrs)
  610. end
  611. end
  612. local bestCnt = getXilianBestCnt(human)
  613. if bestCnt > 0 then
  614. local config = MoShouExcel.moshouxlHx[bestCnt]
  615. for k, v in ipairs(config.attrs) do
  616. RoleAttr.updateValue(v[1] ,v[2] ,attrs)
  617. end
  618. end
  619. end
  620. end
  621. function CG_MOSHOU_PREVIEW(human)
  622. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  623. if not cjPrivilege then return end
  624. local config = MoShouExcel.moshouActive
  625. local msgRet = Msg.gc.GC_MOSHOU_PREVIEW
  626. msgRet.preViews[0] = #config
  627. for i = 1, #config do
  628. msgRet.preViews[i].moshouID = i
  629. msgRet.preViews[i].name = config[i].moshouName
  630. msgRet.preViews[i].body = config[i].body
  631. end
  632. Msg.send(msgRet, human.fd)
  633. end
  634. -- 布阵界面查询魔兽
  635. function CG_MOSHOU_COMBAT_SKILL_QUERY(human, combatType)
  636. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  637. if not cjPrivilege then return end
  638. local posSkillID = CombatPosLogic.getCombatMoshou(human, combatType)
  639. local msgRet = Msg.gc.GC_MOSHOU_COMBAT_SKILL_QUERY
  640. local config = MoShouExcel.moshouSkill
  641. makeMoshouSkill(human, msgRet.skill, MOSHOU_ID1, posSkillID)
  642. Msg.send(msgRet,human.fd)
  643. end
  644. function xilianIsOpen(human)
  645. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_2003) then
  646. return 0
  647. end
  648. if not human.db.moshou then
  649. return 0
  650. end
  651. if human.db.moshou.xilian and human.db.moshou.xilian.init then
  652. return 1
  653. end
  654. return 0
  655. end
  656. function xilianZDLUpdate(human)
  657. RoleAttr.cleanHeroAttrCache(human)
  658. RoleAttr.doCalc(human)
  659. ObjHuman.sendAttr(human, RoleDefine.ZHANDOULI)
  660. end
  661. function onLogin(human)
  662. initXilianDB(human)
  663. end
  664. -- 魔兽 洗练
  665. function initXilianDB(human)
  666. if not human.db.moshou then
  667. return
  668. end
  669. if not xilianIsOpen(human) then
  670. return
  671. end
  672. if human.db.moshou.xilian and human.db.moshou.xilian.init then
  673. return
  674. end
  675. local weekDay = Util.getWeekDay()
  676. if weekDay ~= 4 and weekDay ~= 7 then
  677. return
  678. end
  679. local lv = human.db.moshou.lv or 0
  680. local isChange = false
  681. for index, config in ipairs(MoShouExcel.moshouxlCao) do
  682. if lv >= config.breakLv then
  683. breakXiLianCao(human, index)
  684. isChange = true
  685. end
  686. end
  687. human.db.moshou.xilian.init = 1
  688. if isChange then
  689. xilianZDLUpdate(human)
  690. if not human.db.moshou.xilian.initTime then
  691. human.db.moshou.xilian.initTime = os.time()
  692. end
  693. end
  694. end
  695. function moshouLvUpToXilianBreak(human)
  696. if not xilianIsOpen(human) then
  697. return
  698. end
  699. local lv = human.db.moshou.lv or 0
  700. initXilianDB(human)
  701. local isChange = false
  702. for index, config in ipairs(MoShouExcel.moshouxlCao) do
  703. if lv >= config.breakLv then
  704. breakXiLianCao(human, index)
  705. isChange = true
  706. end
  707. end
  708. if isChange then
  709. xilianZDLUpdate(human)
  710. if not human.db.moshou.xilian.initTime then
  711. human.db.moshou.xilian.initTime = os.time()
  712. end
  713. end
  714. end
  715. function breakXiLianCao(human, index)
  716. if not human.db.moshou then return end
  717. human.db.moshou.xilian = human.db.moshou.xilian or {}
  718. if not human.db.moshou.xilian.cnt then
  719. human.db.moshou.xilian.cnt = 0
  720. end
  721. if human.db.moshou.xilian[index] then return end
  722. local newKey
  723. local newValue
  724. local haveList = {}
  725. if human.db.moshou and human.db.moshou.xilian then
  726. for _, db in ipairs(human.db.moshou.xilian) do
  727. haveList[db.key] = 1
  728. end
  729. end
  730. human.db.moshou.xilian[index] = {}
  731. local xilian = human.db.moshou.xilian[index]
  732. xilian.id = math.random(1, 5)
  733. local newConfig = MoShouExcel.moshouXiLian[xilian.id]
  734. for k , v in pairs(newConfig.attrs1) do
  735. if v and not haveList[v[1]] then
  736. newKey = v[1]
  737. newValue = v[2]
  738. end
  739. end
  740. xilian.key = newKey
  741. xilian.value = newValue
  742. end
  743. function getXilianNeed(config, type, index)
  744. local need = config["need"..type]
  745. local templateConfig = MoShouExcel.moshouxlCao[index]
  746. return math.floor(need * templateConfig.add)
  747. end
  748. function CG_MOSHOU_XILIAN_QUERY(human, index)
  749. initXilianDB(human)
  750. if index == 0 then
  751. index = human.db.moshou and human.db.moshou.xilian and #human.db.moshou.xilian or 0
  752. end
  753. local msgRet = Msg.gc.GC_MOSHOU_XILIAN_QUERY
  754. makeXilianQuery(human, msgRet)
  755. msgRet.index = index
  756. msgRet.fjAttrs[0] = 0
  757. for k, config in ipairs(MoShouExcel.moshouxlCao) do
  758. msgRet.openLv[k] = config.breakLv
  759. end
  760. msgRet.openLv[0] = #MoShouExcel.moshouxlCao
  761. local bestCnt = getXilianBestCnt(human)
  762. if bestCnt > 0 then
  763. local config = MoShouExcel.moshouxlHx[bestCnt]
  764. for k, v in ipairs(config.attrs) do
  765. msgRet.fjAttrs[k].key = v[1]
  766. msgRet.fjAttrs[k].value = v[2]
  767. end
  768. msgRet.fjAttrs[0] = #config.attrs
  769. end
  770. -- Util.printTable(human.db.moshou.xilian)
  771. -- Msg.trace(msgRet)
  772. Msg.send(msgRet,human.fd)
  773. end
  774. function xilianRandom(type, cnt)
  775. local min = 0
  776. local max = 0
  777. local random = 0
  778. for k, v in ipairs(MoShouExcel.moshouxlRandom) do
  779. if cnt >= v.cnt then
  780. min = v.random[1]
  781. max = v.random[2]
  782. random = v["rareSum"..type]
  783. end
  784. end
  785. local random = math.random(1, random)
  786. for i = min, max do
  787. local config = MoShouExcel.moshouXiLian[i]
  788. if random <= config["rare"..type] then
  789. return i
  790. else
  791. random = random - config["rare"..type]
  792. end
  793. end
  794. end
  795. function CG_MOSHOU_XILIAN_OP(human, op, type, index)
  796. if op == MOSHOU_XILIAN_OP_1 then
  797. xilianDo(human, index, type)
  798. elseif op == MOSHOU_XILIAN_OP_2 then
  799. saveXilian(human, index)
  800. end
  801. end
  802. function randomXilian(id)
  803. local config = MoShouExcel.moshouXiLian[id]
  804. local random = math.random(1, config.attrRareMax)
  805. for k ,v in ipairs(config.attrs1) do
  806. if v and v[3] >= random then
  807. return v[1], v[2]
  808. else
  809. random = random - v[3]
  810. end
  811. end
  812. end
  813. function xilianDo(human, index, type)
  814. if not human.db.moshou or not human.db.moshou.xilian then
  815. return
  816. end
  817. local xilian = human.db.moshou.xilian[index]
  818. if not xilian then return end
  819. if type ~= MOSHOU_XILIAN_OP_1 then -- and type ~= MOSHOU_XILIAN_OP_2 取消钻石洗练
  820. return
  821. end
  822. -- print(" xilianDo xilianDo ", index , type)
  823. local oldConfig = MoShouExcel.moshouXiLian[xilian.id]
  824. -- 洗练方式 验证材料是否够
  825. local itemID
  826. if type == MOSHOU_XILIAN_OP_1 then
  827. itemID = ItemDefine.ITEM_LONGXUE_ID
  828. else
  829. itemID = ItemDefine.ITEM_ZUANSHI_ID
  830. end
  831. local itemCnt = BagLogic.getItemCnt(human, itemID)
  832. local needCnt = oldConfig["need"..type]
  833. if itemCnt < needCnt then
  834. return
  835. end
  836. local newId = xilianRandom(type, human.db.moshou.xilian.cnt or 0)
  837. if not newId then return end
  838. -- print(" new ID ", newId)
  839. local newConfig = MoShouExcel.moshouXiLian[newId]
  840. -- local random = math.random(1, #newConfig["attrs"..type])
  841. -- local key = newConfig["attrs"..type][random][1]
  842. -- local value = newConfig["attrs"..type][random][2]
  843. local key, value = randomXilian(newId)
  844. -- 除所需材料
  845. BagLogic.delItem(human, itemID, needCnt, "moshou")
  846. xilian.lastId = newId
  847. xilian.lastKey = key
  848. xilian.lastValue = value
  849. human.db.moshou.xilian.cnt = human.db.moshou.xilian.cnt + 1
  850. CG_MOSHOU_XILIAN_QUERY(human, index)
  851. end
  852. function saveXilian(human, index)
  853. if not human.db.moshou or not human.db.moshou.xilian then
  854. return
  855. end
  856. local xilian = human.db.moshou.xilian[index]
  857. if not xilian then return end
  858. if not xilian.lastId then return end
  859. local haveIndex
  860. if human.db.moshou and human.db.moshou.xilian then
  861. for k, v in ipairs(human.db.moshou.xilian) do
  862. if v.key == xilian.lastKey then
  863. haveIndex = k
  864. end
  865. end
  866. end
  867. if haveIndex then
  868. local haveDb = human.db.moshou.xilian[haveIndex]
  869. haveDb.id = xilian.lastId
  870. haveDb.key = xilian.lastKey
  871. haveDb.value = xilian.lastValue
  872. xilian.lastId = nil
  873. xilian.lastKey = nil
  874. xilian.lastValue = nil
  875. else
  876. xilian.id = xilian.lastId
  877. xilian.key = xilian.lastKey
  878. xilian.value = xilian.lastValue
  879. xilian.lastId = nil
  880. xilian.lastKey = nil
  881. xilian.lastValue = nil
  882. end
  883. CG_MOSHOU_XILIAN_QUERY(human, index)
  884. xilianZDLUpdate(human)
  885. end
  886. function CG_MOSHOU_XILIAN_GIFT_QUERY(human)
  887. local msgRet = Msg.gc.GC_MOSHOU_XILIAN_GIFT_QUERY
  888. local absAct = YunYingLogic.onCallBack(human, "onQueryLongXue", nil, true)
  889. local len = 0
  890. for k, config in pairs(MoShouExcel.xiLianGift) do
  891. len = len + 1
  892. for j = 1, #config.reward do
  893. Grid.makeItem(msgRet.list[len].item[j], config.reward[j][1], config.reward[j][2])
  894. end
  895. local absCnt = 0
  896. if absAct and absAct[config.buyID] then
  897. absCnt = absAct[config.buyID].cnt or 0
  898. end
  899. local intCnt = getXilianInitDoubleCnt(human, config.buyID)
  900. local isInitDouble = isXilianInitDouble(human)
  901. local absMax = absAct and absAct[config.buyID] and absAct[config.buyID].max or 0
  902. local initMax = isInitDouble and config.frequency or 0
  903. msgRet.list[len].item[0] = #config.reward
  904. msgRet.list[len].cnt = absCnt + intCnt
  905. msgRet.list[len].id = k
  906. msgRet.list[len].maxCnt = absMax + initMax
  907. msgRet.list[len].icon = config.icon or 0
  908. msgRet.list[len].name = config.name or ""
  909. local buyID = config.buyID
  910. msgRet.list[len].buyMsg[0] = 0
  911. msgRet.list[len].needItem[0] = 0
  912. BuyLogic.fontBuyItem(human, msgRet.list[len].buyMsg[1], buyID)
  913. msgRet.list[len].buyMsg[0] = 1
  914. end
  915. msgRet.list[0] = len
  916. Msg.send(msgRet, human.fd)
  917. end
  918. function isXilianInitDouble(human)
  919. if human.db.moshou.xilian.initTime then
  920. local now = os.time()
  921. local endTime = human.db.moshou.xilian.initTime + 24 * 60 * 60 * 3
  922. if now <= endTime then
  923. return true
  924. end
  925. end
  926. end
  927. function getXilianInitDoubleCnt(human, buyID)
  928. if human.db.moshou.xilian.initTime then
  929. local max = MoShouExcel.xiLianGift[buyID].frequency
  930. local now = os.time()
  931. local endTime = human.db.moshou.xilian.initTime + 24 * 60 * 60 * 3
  932. if now <= endTime then
  933. human.db.moshou.xilian.giftBuy = human.db.moshou.xilian.giftBuy or {}
  934. local oldCnt = human.db.moshou.xilian.giftBuy[buyID] or 0
  935. if oldCnt < max then
  936. return max - oldCnt
  937. end
  938. end
  939. end
  940. return 0
  941. end
  942. function xlianGiftBuy(human, buyID)
  943. local isDouble = false
  944. local doubleBuyCnt = 0
  945. local absCnt = YunYingLogic.onCallBack(human, "onBuyLongXue", buyID, true)
  946. if absCnt then
  947. isDouble = true
  948. end
  949. if human.db.moshou.xilian.initTime and not isDouble then
  950. local intCnt = getXilianInitDoubleCnt(human, buyID)
  951. if intCnt > 0 then
  952. human.db.moshou.xilian.giftBuy[buyID] = human.db.moshou.xilian.giftBuy[buyID] or 0
  953. human.db.moshou.xilian.giftBuy[buyID] = human.db.moshou.xilian.giftBuy[buyID] + 1
  954. isDouble = true
  955. end
  956. end
  957. BagLogic.cleanMomentItemList()
  958. for k, config in pairs(MoShouExcel.xiLianGift) do
  959. if config and config.buyID == buyID then
  960. for _, item in ipairs(config.reward) do
  961. local itemCnt = item[2]
  962. if isDouble then
  963. itemCnt = itemCnt * 2
  964. end
  965. BagLogic.updateMomentItem(1, item[1], itemCnt)
  966. end
  967. BagLogic.addMomentItemList(human, "moshouXlGift")
  968. return
  969. end
  970. end
  971. end
  972. -- 获取魔兽 洗练中有几条传说属性
  973. function getXilianBestCnt(human)
  974. if not human.db.moshou or not human.db.moshou.xilian then
  975. return 0
  976. end
  977. local cnt = 0
  978. for _, db in ipairs(human.db.moshou.xilian) do
  979. local config = MoShouExcel.moshouXiLian[db.id]
  980. if config and config.isSS == 1 then
  981. cnt = cnt + 1
  982. end
  983. end
  984. return cnt
  985. end
  986. -- 魔兽可升级红点
  987. function moshouLVupRed(human)
  988. local nowLV = getMoshouLv(human)
  989. local config = MoShouExcel.moshouLv[nowLV + 1]
  990. if not config then return end
  991. local lvUpNeed = config.lvUpNeed
  992. local enough = nil
  993. for i = 1, #lvUpNeed do
  994. local itemID = lvUpNeed[i][1]
  995. local itemCnt = lvUpNeed[i][2]
  996. local now = BagLogic.getItemCnt(human, itemID)
  997. if now >= itemCnt then
  998. enough =(enough or 0) + 1
  999. end
  1000. end
  1001. if enough and enough >= #lvUpNeed then return true end
  1002. end
  1003. function moshouSkillUpRed(human)
  1004. if not MoShouExcel.moshouActive[MOSHOU_ID1] then return end
  1005. if not MOSHOU_SKILL[MOSHOU_ID1] then return end
  1006. local moshouLV = getMoshouLv(human)
  1007. local skillLV = getMoShouSkillLv(human)
  1008. local config = MoShouExcel.moshouSkillLv
  1009. if skillLV >= #config then return end
  1010. local nextSkillLv = skillLV + 1
  1011. if not MOSHOU_SKILL[MOSHOU_ID1][1][nextSkillLv] then return end
  1012. local nowArgeCnt = nil
  1013. local canUpNeedType = config[nextSkillLv].canUpNeed[1] or 0
  1014. local canUpNeedValue = config[nextSkillLv].canUpNeed[2] or 0
  1015. if canUpNeedType == MOSHOU_SKILLLV_ARGE1 then
  1016. nowArgeCnt = moshouLV
  1017. else
  1018. return
  1019. end
  1020. if not nowArgeCnt then return end
  1021. if nowArgeCnt < canUpNeedValue then return end
  1022. local upCost = config[nextSkillLv].upCost
  1023. for i = 1, #upCost do
  1024. local itemID = upCost[i][1]
  1025. local itemCnt = upCost[i][2]
  1026. local nowCnt = BagLogic.getItemCnt(human, itemID)
  1027. if nowCnt < itemCnt then
  1028. return
  1029. end
  1030. end
  1031. return true
  1032. end
  1033. -- 魔兽可精炼红点
  1034. function moshouJinglianRed(human)
  1035. local jingLianLV = getMoShouJiLian(human)
  1036. local moshouLV = getMoshouLv(human)
  1037. local jingLianMaxLV = #MoShouExcel.moshouJingLian
  1038. if jingLianLV < jingLianMaxLV then
  1039. local nextConfig = MoShouExcel.moshouJingLian[jingLianLV + 1]
  1040. local lvUpNeed = nextConfig.lvUpNeed
  1041. local enough = nil
  1042. for i = 1, #lvUpNeed do
  1043. local itemID = lvUpNeed[i][1]
  1044. local itemCnt = lvUpNeed[i][2]
  1045. local nowCnt = BagLogic.getItemCnt(human, itemID, itemCnt)
  1046. if nowCnt >= itemCnt then
  1047. enough =(enough or 0) + 1
  1048. end
  1049. end
  1050. if enough and enough >= #lvUpNeed then return true end
  1051. end
  1052. end
  1053. -- 魔兽可铸魂红点
  1054. function moshouZhunHunRed(human)
  1055. local moshouLV = getMoshouLv(human)
  1056. local zhuHunCntMax = MoShouExcel.moshouLv[moshouLV].zhuHunCntMax
  1057. local nowUseCnt = human.db.moshou and human.db.moshou.zhuHun or 0
  1058. if nowUseCnt < zhuHunCntMax then
  1059. local config = MoShouExcel.moshouZhuHun[1]
  1060. local nowCnt = BagLogic.getItemCnt(human, config.costID)
  1061. if nowCnt > 0 then return true end
  1062. end
  1063. end
  1064. -- 魔兽洗练红点
  1065. function moshouXilianUpRed(human)
  1066. if human.db.moshou and human.db.moshou.xilian then
  1067. local itemCnt = BagLogic.getItemCnt(human, ItemDefine.ITEM_LONGXUE_ID)
  1068. for k, db in ipairs(human.db.moshou.xilian) do
  1069. local config = MoShouExcel.moshouXiLian[db.id]
  1070. if itemCnt >= config.need1 then
  1071. return true
  1072. end
  1073. end
  1074. end
  1075. end
  1076. function isDot(human)
  1077. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  1078. if not cjPrivilege then
  1079. return ChengjiuLogic.isFinish(human, 402)
  1080. end
  1081. -- 魔兽可升级
  1082. if moshouLVupRed(human) then return true end
  1083. -- 魔兽可精炼
  1084. if moshouJinglianRed(human) then return true end
  1085. -- 魔兽可铸魂
  1086. if moshouZhunHunRed(human) then return true end
  1087. -- 技能可升级
  1088. if moshouSkillUpRed(human) then return true end
  1089. end
  1090. ------------------------------外部接口相关-----------------------------------------
  1091. -- 创建魔兽结构体
  1092. function createCombatMoshow(human, combatType)
  1093. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  1094. if not cjPrivilege then return end
  1095. local id = CombatPosLogic.getCombatMoshou(human, combatType)
  1096. if not id or id < 1 then return end
  1097. if not MOSHOU_SKILL[MOSHOU_ID1][id] then return end
  1098. local config = MoShouExcel.moshouActive[MOSHOU_ID1]
  1099. local pet = { }
  1100. pet.isPet = true
  1101. pet.petID = MOSHOU_ID1
  1102. pet.id = id
  1103. pet.lv = getMoshouLv(human)
  1104. pet.body = config.body
  1105. pet.jinglianLV = getMoShouJiLian(human)
  1106. pet.zhuHun = getMoShouZhuHunNum(human)
  1107. pet.skillLV = getMoShouSkillLv(human)
  1108. if human.db.moshou and human.db.moshou.lvAttrsAdd then
  1109. pet.lvAttrsAdd = Util.copyTable(human.db.moshou.lvAttrsAdd)
  1110. else
  1111. pet.lvAttrsAdd = {}
  1112. end
  1113. if MOSHOU_SKILL[MOSHOU_ID1][id][pet.skillLV] then
  1114. local skillID = MOSHOU_SKILL[1][id][pet.skillLV]
  1115. local skillConfig = SkillExcel.skill[skillID]
  1116. local cd1 = skillConfig.cd[1] or 0
  1117. local cd2 = skillConfig.cd[2] or 0
  1118. pet.icon = skillID
  1119. pet.skillList = { }
  1120. pet.skillList[1] = { skillID, cd1, cd2 }
  1121. pet.cd = cd2
  1122. end
  1123. return pet
  1124. end
  1125. -- 获取出战魔兽的skillID
  1126. function getPutMoshouSkillID(human, combatType)
  1127. local putOnMoshou = CombatPosLogic.getCombatMoshou(human, combatType)
  1128. if not putOnMoshou or putOnMoshou < 1 then return end
  1129. if not MOSHOU_SKILL[MOSHOU_ID1][putOnMoshou] then return end
  1130. local skillLV = getMoShouSkillLv(human)
  1131. local skillID = MOSHOU_SKILL[MOSHOU_ID1][putOnMoshou][skillLV]
  1132. return skillID
  1133. end
  1134. -- 获取出战魔兽形象
  1135. function getCombatMoshouBody(human, combatType)
  1136. local id = CombatPosLogic.getCombatMoshou(human, combatType)
  1137. if not id or id < 1 then return 0 end
  1138. local config = MoShouExcel.moshouActive[MOSHOU_ID1]
  1139. return config and config.body or 0
  1140. end
  1141. -- 获取魔兽等级
  1142. function getMoshouLv(human)
  1143. if human.db.moshou and human.db.moshou.lv then
  1144. return human.db.moshou.lv
  1145. end
  1146. return 1
  1147. end
  1148. -- 获取精炼等级
  1149. function getMoShouJiLian(human)
  1150. return human.db.moshou and human.db.moshou.jingLian or 0
  1151. end
  1152. -- 获取技能等级
  1153. function getMoShouSkillLv(human)
  1154. if human.db.moshou and human.db.moshou.skillLV then
  1155. return human.db.moshou.skillLV
  1156. end
  1157. return 1
  1158. end
  1159. -- 获取铸魂数
  1160. function getMoShouZhuHunNum(human)
  1161. return human.db.moshou and human.db.moshou.zhuHun or 0
  1162. end
  1163. -- 出战界面
  1164. function setHelp(net, moshouID)
  1165. net.type = CombatDefine.HELP_TYPE1
  1166. net.id = moshouID
  1167. net.icon = MoShouExcel.moshouActive[MOSHOU_ID1].icon
  1168. end
  1169. function setPosHelp(net, moshouID)
  1170. net.type = CombatDefine.HELP_TYPE1
  1171. net.id = moshouID
  1172. net.icon = MoShouExcel.moshouActive[MOSHOU_ID1].icon
  1173. end
  1174. -- 战斗阵容封装
  1175. function setCombatHelp(net, moshouObj, pos)
  1176. net.pos = pos
  1177. net.id = moshouObj.petID
  1178. net.head = moshouObj.head
  1179. net.body = moshouObj.body
  1180. net.args[0] = 0
  1181. end
  1182. --
  1183. function setSkillAndBeskill(human, combatInfo)
  1184. for atkPos, atkObj in pairs(CombatImpl.helpList) do
  1185. local skill = human.db.moshou.putOnMoshou
  1186. if atkObj.side == CombatDefine.ATTACK_SIDE and skill then
  1187. atkObj.skillList = {skill}
  1188. atkObj.beSkillList = {}
  1189. end
  1190. --print("===============", atkPos, skill and skill.skillList, skill and skill.beSkillList)
  1191. end
  1192. end