MoshouLogic.lua 45 KB

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