MoshouLogic.lua 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421
  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. Log.write(Log.LOGID_OSS_DRAGON_LEVEL, human.db._id, human.db.newUniqueTag, human.db.name, human.db.moshou.lv, getMoShouSkillLv(human))
  284. else
  285. human.db.moshou.lvAttrsAdd = human.db.moshou.lvAttrsAdd or {}
  286. for i=1,#lvAttrsAddCnf do
  287. local key = lvAttrsAddCnf[i][1]
  288. local value = lvAttrsAddCnf[i][2]
  289. human.db.moshou.lvAttrsAdd[key] = (human.db.moshou.lvAttrsAdd[key] or 0) + value
  290. end
  291. end
  292. local msgRet = Msg.gc.GC_MOSHOU_LVUP_UP
  293. makeMoshouLvAttrs(human,msgRet.lvAttrs)
  294. makeMoshouLvUp(human,msgRet.moshouLvUp)
  295. msgRet.moshouLv = getMoshouLv(human)
  296. Msg.send(msgRet,human.fd)
  297. moshouLvUpQuery(human)
  298. RoleAttr.cleanHeroAttrCache(human)
  299. RoleAttr.doCalc(human)
  300. ObjHuman.sendAttr(human, RoleDefine.ZHANDOULI)
  301. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2002)
  302. if lvUpState then
  303. moshouLvUpToXilianBreak(human)
  304. end
  305. end
  306. local function getLangByCanUpType(human,canUpType)
  307. if canUpType == MOSHOU_SKILLLV_ARGE1 then
  308. return Lang.MOSHOU_UP_DESC_MOSHOULV
  309. elseif canUpType == MOSHOU_SKILLLV_ARGE2 then
  310. return Lang.MOSHOU_UP_DESC_JUNZHU
  311. elseif canUpType == MOSHOU_JINGLIANLV_ARGE1 then
  312. return Lang.MOSHOU_UP_DESC_MOSHOULV
  313. elseif canUpType == MOSHOU_JINGLIANLV_ARGE2 then
  314. return Lang.MOSHOU_UP_DESC_JUYI
  315. end
  316. end
  317. local function getSkillCanUpNeed(human)
  318. local skillLV = getMoShouSkillLv(human)
  319. if skillLV >= #MoShouExcel.moshouSkillLv then
  320. return 0,0
  321. end
  322. local nextConf = MoShouExcel.moshouSkillLv[skillLV+1]
  323. return nextConf.canUpNeed[1] or 0,nextConf.canUpNeed[2] or 0
  324. end
  325. local function getSkillMaxLV(human)
  326. local moshouLV = getMoshouLv(human)
  327. local conf = MoShouExcel.moshouSkillLv
  328. local skillLV = getMoShouSkillLv(human)
  329. if skillLV >= #conf then
  330. return skillLV
  331. end
  332. for i=skillLV+1,#conf do
  333. local arge = conf[i].canUpNeed[1]
  334. local argeNeed = conf[i].canUpNeed[2]
  335. if arge == MOSHOU_SKILLLV_ARGE1 then
  336. if moshouLV < argeNeed then
  337. return i - 1
  338. end
  339. elseif arge == MOSHOU_SKILLLV_ARGE2 then
  340. return 0
  341. end
  342. end
  343. return #conf
  344. end
  345. function CG_MOSHOU_SKILL_QUERY(human, moshouID)
  346. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  347. if not cjPrivilege then return end
  348. if not MoShouExcel.moshouActive[MOSHOU_ID1] then return end
  349. local msgRet = Msg.gc.GC_MOSHOU_SKILL_QUERY
  350. msgRet.moshouID = MOSHOU_ID1
  351. makeMoshouSkill(human, msgRet.moshouSkill, MOSHOU_ID1)
  352. local moshouLV = getMoshouLv(human)
  353. local skillMaxLv = getSkillMaxLV(human)
  354. msgRet.skillMaxLv = skillMaxLv
  355. msgRet.needItem[0] = 0
  356. local skillLV = getMoShouSkillLv(human)
  357. local config = MoShouExcel.moshouSkillLv[skillLV + 1]
  358. if config and skillLV < skillMaxLv then
  359. msgRet.needItem[0] = #config.upCost
  360. for i = 1, #config.upCost do
  361. local itemID = config.upCost[i][1]
  362. local itemCnt = config.upCost[i][2]
  363. Grid.makeItem(msgRet.needItem[i], itemID, itemCnt)
  364. end
  365. end
  366. msgRet.skillCanUp = ""
  367. if skillLV >= #MoShouExcel.moshouSkillLv then
  368. msgRet.skillCanUp = Lang.MOSHOU_SKILL_LV_MAX
  369. else
  370. if skillLV >= skillMaxLv then
  371. local arge,argeNeed = getSkillCanUpNeed(human)
  372. local content = getLangByCanUpType(human,arge)
  373. if content then
  374. content = Util.format(content,argeNeed)
  375. msgRet.skillCanUp = content
  376. end
  377. end
  378. end
  379. Msg.send(msgRet, human.fd)
  380. end
  381. function CG_MOSHOU_SKILL_UP(human, moshouID)
  382. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  383. if not cjPrivilege then return end
  384. if not MoShouExcel.moshouActive[MOSHOU_ID1] then return end
  385. if not MOSHOU_SKILL[moshouID] then return end
  386. local moshouLV = getMoshouLv(human)
  387. local skillLV = getMoShouSkillLv(human)
  388. local config = MoShouExcel.moshouSkillLv
  389. if skillLV >= #config then return end
  390. local nextSkillLv = skillLV + 1
  391. if not MOSHOU_SKILL[moshouID][1][nextSkillLv] then return end
  392. local nowArgeCnt = nil
  393. local canUpNeedType = config[nextSkillLv].canUpNeed[1] or 0
  394. local canUpNeedValue = config[nextSkillLv].canUpNeed[2] or 0
  395. if canUpNeedType == MOSHOU_SKILLLV_ARGE1 then
  396. nowArgeCnt = moshouLV
  397. else
  398. return
  399. end
  400. if not nowArgeCnt then return end
  401. if nowArgeCnt < canUpNeedValue then return end
  402. local upCost = config[nextSkillLv].upCost
  403. for i = 1, #upCost do
  404. local itemID = upCost[i][1]
  405. local itemCnt = upCost[i][2]
  406. local nowCnt = BagLogic.getItemCnt(human, itemID)
  407. if nowCnt < itemCnt then return Broadcast.sendErr(human, Lang.MOSHOU_LV_UP_NOT) end
  408. end
  409. for i = 1, #upCost do
  410. local itemID = upCost[i][1]
  411. local itemCnt = upCost[i][2]
  412. BagLogic.delItem(human, itemID, itemCnt, "moshou")
  413. end
  414. human.db.moshou = human.db.moshou or {}
  415. human.db.moshou.skillLV = nextSkillLv
  416. --Log.write(Log.LOGID_OSS_DRAGON_LEVEL, human.db._id, human.db.account, human.db.name, human.db.moshou.lv, getMoShouSkillLv(human))
  417. Log.write(Log.LOGID_OSS_DRAGON_LEVEL, human.db._id, human.db.newUniqueTag, human.db.name, human.db.moshou.lv, getMoShouSkillLv(human))
  418. Broadcast.sendErr(human, Lang.MOSHOU_SKILL_LV_UP)
  419. moshouLvUpQuery(human)
  420. CG_MOSHOU_SKILL_QUERY(human, moshouID)
  421. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2002)
  422. end
  423. function CG_MOSHOU_JINGLIAN_QUERY(human)
  424. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  425. if not cjPrivilege then return end
  426. local msgRet = Msg.gc.GC_MOSHOU_JINGLIAN_QUERY
  427. local jinglianLV = getMoShouJiLian(human)
  428. local moshouLV = getMoshouLv(human)
  429. local jingLianConfig = MoShouExcel.moshouJingLian
  430. local jingLianCanLV = #jingLianConfig
  431. msgRet.jingLianCanLV = jingLianCanLV
  432. msgRet.nowLvData[0] = 0
  433. msgRet.nextLvData[0] = 0
  434. msgRet.needItem[0] = 0
  435. local nowLV = getMoShouJiLian(human)
  436. local nextConfig = MoShouExcel.moshouJingLian[nowLV + 1]
  437. if nextConfig then
  438. local showLeft = nextConfig.showLeft
  439. local showRight = nextConfig.showRight
  440. msgRet.nowLvData[0] = 1
  441. makeJingLianLvData(human, msgRet.nowLvData[1], showLeft, nowLV)
  442. msgRet.nextLvData[0] = 1
  443. makeJingLianLvData(human, msgRet.nextLvData[1], showRight, nowLV + 1)
  444. msgRet.needItem[0] = #nextConfig.lvUpNeed
  445. for i = 1, #nextConfig.lvUpNeed do
  446. local itemID = nextConfig.lvUpNeed[i][1]
  447. local itemCnt = nextConfig.lvUpNeed[i][2]
  448. Grid.makeItem(msgRet.needItem[i], itemID, itemCnt)
  449. end
  450. else
  451. local nowConfig = MoShouExcel.moshouJingLian[nowLV]
  452. msgRet.nowLvData[0] = 1
  453. makeJingLianLvData(human, msgRet.nowLvData[1], nowConfig.lvAttrs, nowLV)
  454. end
  455. msgRet.attrs[0] = 0
  456. local attrs = nil
  457. if jingLianConfig[jinglianLV] then
  458. attrs = { }
  459. for i = 1, jinglianLV do
  460. local key = jingLianConfig[i].lvAttrs[1]
  461. local value = jingLianConfig[i].lvAttrs[2]
  462. attrs[key] =(attrs[key] or 0) + value
  463. end
  464. end
  465. if attrs then
  466. for key, value in pairs(attrs) do
  467. msgRet.attrs[0] = msgRet.attrs[0] + 1
  468. local index = msgRet.attrs[0]
  469. msgRet.attrs[index].key = key
  470. msgRet.attrs[index].value = value
  471. end
  472. end
  473. -- Msg.trace(msgRet)
  474. Msg.send(msgRet, human.fd)
  475. end
  476. function CG_MOSHOU_JINGLIAN_DO(human)
  477. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  478. if not cjPrivilege then return end
  479. local jingLianLV = getMoShouJiLian(human)
  480. local moshouLV = getMoshouLv(human)
  481. local jingLianMaxLV = #MoShouExcel.moshouJingLian
  482. if jingLianLV >= jingLianMaxLV then return end
  483. local nextConfig = MoShouExcel.moshouJingLian[jingLianLV + 1]
  484. local lvUpNeed = nextConfig.lvUpNeed
  485. for i = 1, #lvUpNeed do
  486. local itemID = lvUpNeed[i][1]
  487. local itemCnt = lvUpNeed[i][2]
  488. local nowCnt = BagLogic.getItemCnt(human, itemID)
  489. if nowCnt < itemCnt then return Broadcast.sendErr(human, Lang.MOSHOU_LV_UP_NOT) end
  490. end
  491. for i = 1, #lvUpNeed do
  492. local itemID = lvUpNeed[i][1]
  493. local itemCnt = lvUpNeed[i][2]
  494. BagLogic.delItem(human, itemID, itemCnt, "moshou")
  495. end
  496. human.db.moshou = human.db.moshou or { }
  497. human.db.moshou.jingLian = jingLianLV + 1
  498. Broadcast.sendErr(human, Lang.MOSHOU_JINGLIAN_LV_UP)
  499. CG_MOSHOU_JINGLIAN_QUERY(human)
  500. RoleAttr.cleanHeroAttrCache(human)
  501. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2002)
  502. end
  503. function CG_MOSHOU_ZHUHUN_QUERY(human)
  504. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  505. if not cjPrivilege then return end
  506. local msgRet = Msg.gc.GC_MOSHOU_ZHUHUN_QUERY
  507. local config = MoShouExcel.moshouZhuHun[1]
  508. Grid.makeItem(msgRet.needItem, config.costID, 1)
  509. msgRet.nowAttr[0] = 0
  510. local nowUseCnt = human.db.moshou and human.db.moshou.zhuHun or 0
  511. if nowUseCnt > 0 then
  512. msgRet.nowAttr[0] = #config.zhuHunAttrs
  513. for i = 1, #config.zhuHunAttrs do
  514. msgRet.nowAttr[i].key = config.zhuHunAttrs[i][1]
  515. msgRet.nowAttr[i].value = config.zhuHunAttrs[i][2] + config.addZhuHun * nowUseCnt
  516. end
  517. end
  518. msgRet.nowUseCnt = nowUseCnt
  519. local moshouLV = getMoshouLv(human)
  520. local zhuHunCntMax = MoShouExcel.moshouLv[moshouLV].zhuHunCntMax
  521. msgRet.maxUseCan = zhuHunCntMax
  522. Msg.send(msgRet, human.fd)
  523. end
  524. function CG_MOSHOU_ZHUHUN_DO(human, useCnt)
  525. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  526. if not cjPrivilege then return end
  527. local moshouLV = getMoshouLv(human)
  528. local zhuHunCntMax = MoShouExcel.moshouLv[moshouLV].zhuHunCntMax
  529. local nowUseCnt = human.db.moshou and human.db.moshou.zhuHun or 0
  530. if nowUseCnt >= zhuHunCntMax or(nowUseCnt + useCnt) > zhuHunCntMax then return Broadcast.sendErr(human, Lang.MOSHOU_ZHUHUN_MAX) end
  531. local config = MoShouExcel.moshouZhuHun[1]
  532. local nowCnt = BagLogic.getItemCnt(human, config.costID)
  533. if useCnt > nowCnt then return Broadcast.sendErr(human, Lang.MOSHOU_LV_UP_NOT) end
  534. BagLogic.delItem(human, config.costID, useCnt, "moshou")
  535. human.db.moshou = human.db.moshou or { }
  536. human.db.moshou.zhuHun = nowUseCnt + useCnt
  537. Broadcast.sendErr(human, Lang.MOSHOU_ZHUHUN_LV_UP)
  538. CG_MOSHOU_ZHUHUN_QUERY(human)
  539. RoleAttr.cleanHeroAttrCache(human)
  540. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2002)
  541. end
  542. local function makeMoshouPutOn(human, net, moshouID)
  543. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  544. if not cjPrivilege then return end
  545. net.moshouID = MOSHOU_ID1
  546. local config = MoShouExcel.moshouActive[MOSHOU_ID1]
  547. net.moshouName = config.moshouName
  548. net.moshouIcon = config.icon
  549. net.moshouLv = getMoshouLv(human)
  550. makeMoshouSkill(human, net.moshouSkill, MOSHOU_ID1)
  551. end
  552. -- 上阵界面 查询魔兽信息
  553. function CG_MOSHOU_PUT_QUERY(human)
  554. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  555. if not cjPrivilege then return end
  556. local config = MoShouExcel.moshouActive
  557. local msgRet = Msg.gc.GC_MOSHOU_PUT_QUERY
  558. msgRet.moshouPutOn[0] = #config
  559. for i = 1, #config do
  560. makeMoshouPutOn(human, msgRet.moshouPutOn[i], i)
  561. end
  562. Msg.send(msgRet, human.fd)
  563. end
  564. function doCalcHero(human, heroGrid, attrs)
  565. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  566. if not cjPrivilege then return end
  567. -- 魔兽等级属性加成
  568. local nowLV = getMoshouLv(human)
  569. local moshouLvConfig = MoShouExcel.moshouLv[nowLV]
  570. if moshouLvConfig and #moshouLvConfig.lvAttrs > 0 then
  571. local lvAttrs = nil
  572. for i=1,#moshouLvConfig.lvAttrs do
  573. local key = moshouLvConfig.lvAttrs[i][1]
  574. local value = moshouLvConfig.lvAttrs[i][2]
  575. lvAttrs = lvAttrs or {}
  576. lvAttrs[key] = (lvAttrs[key] or 0) + value
  577. end
  578. if human.db.moshou and human.db.moshou.lvAttrsAdd then
  579. local lvAttrsAdd = human.db.moshou.lvAttrsAdd
  580. for k,v in pairs(lvAttrsAdd) do
  581. lvAttrs = lvAttrs or {}
  582. lvAttrs[k] = (lvAttrs[k] or 0) + v
  583. end
  584. end
  585. if lvAttrs then
  586. for k,v in pairs(lvAttrs) do
  587. RoleAttr.updateValue(k,v,attrs)
  588. end
  589. end
  590. end
  591. --魔兽精练等级属性加成
  592. local jingLianLV = human.db.moshou and human.db.moshou.jingLian or 0
  593. local jingLianConfig = MoShouExcel.moshouJingLian
  594. if jingLianConfig[jingLianLV] then
  595. for i=1,jingLianLV do
  596. local key = jingLianConfig[i].lvAttrs[1]
  597. local value = jingLianConfig[i].lvAttrs[2]
  598. RoleAttr.updateValue(key,value,attrs)
  599. end
  600. end
  601. --魔兽铸魂属性加成
  602. local zhuHun = human.db.moshou and human.db.moshou.zhuHun or 0
  603. local zhuHunConfig = MoShouExcel.moshouZhuHun[1]
  604. if zhuHun > 0 and #zhuHunConfig.zhuHunAttrs > 0 then
  605. for i=1,#zhuHunConfig.zhuHunAttrs do
  606. RoleAttr.updateValue(zhuHunConfig.zhuHunAttrs[i][1],zhuHunConfig.zhuHunAttrs[i][2] * zhuHun,attrs)
  607. end
  608. end
  609. -- 魔兽洗练的加成
  610. if human.db.moshou and human.db.moshou.xilian then
  611. for k, db in ipairs(human.db.moshou.xilian) do
  612. if db and db.key and db.value ~= 0 then
  613. RoleAttr.updateValue(db.key ,db.value ,attrs)
  614. end
  615. end
  616. local bestCnt = getXilianBestCnt(human)
  617. if bestCnt > 0 then
  618. local config = MoShouExcel.moshouxlHx[bestCnt]
  619. for k, v in ipairs(config.attrs) do
  620. RoleAttr.updateValue(v[1] ,v[2] ,attrs)
  621. end
  622. end
  623. end
  624. end
  625. function CG_MOSHOU_PREVIEW(human)
  626. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  627. if not cjPrivilege then return end
  628. local config = MoShouExcel.moshouActive
  629. local msgRet = Msg.gc.GC_MOSHOU_PREVIEW
  630. msgRet.preViews[0] = #config
  631. for i = 1, #config do
  632. msgRet.preViews[i].moshouID = i
  633. msgRet.preViews[i].name = config[i].moshouName
  634. msgRet.preViews[i].body = config[i].body
  635. end
  636. Msg.send(msgRet, human.fd)
  637. end
  638. -- 布阵界面查询魔兽
  639. function CG_MOSHOU_COMBAT_SKILL_QUERY(human, combatType)
  640. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  641. if not cjPrivilege then return end
  642. local posSkillID = CombatPosLogic.getCombatMoshou(human, combatType)
  643. local msgRet = Msg.gc.GC_MOSHOU_COMBAT_SKILL_QUERY
  644. local config = MoShouExcel.moshouSkill
  645. makeMoshouSkill(human, msgRet.skill, MOSHOU_ID1, posSkillID)
  646. Msg.send(msgRet,human.fd)
  647. end
  648. function xilianIsOpen(human)
  649. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_2003) then
  650. return 0
  651. end
  652. if not human.db.moshou then
  653. return 0
  654. end
  655. if human.db.moshou.xilian and human.db.moshou.xilian.init then
  656. return 1
  657. end
  658. return 0
  659. end
  660. function xilianZDLUpdate(human)
  661. RoleAttr.cleanHeroAttrCache(human)
  662. RoleAttr.doCalc(human)
  663. ObjHuman.sendAttr(human, RoleDefine.ZHANDOULI)
  664. end
  665. function onLogin(human)
  666. initXilianDB(human)
  667. end
  668. -- 魔兽 洗练
  669. function initXilianDB(human)
  670. if not human.db.moshou then
  671. return
  672. end
  673. if not xilianIsOpen(human) then
  674. return
  675. end
  676. if human.db.moshou.xilian and human.db.moshou.xilian.init then
  677. return
  678. end
  679. local weekDay = Util.getWeekDay()
  680. if weekDay ~= 4 and weekDay ~= 7 then
  681. return
  682. end
  683. local lv = human.db.moshou.lv or 0
  684. local isChange = false
  685. for index, config in ipairs(MoShouExcel.moshouxlCao) do
  686. if lv >= config.breakLv then
  687. breakXiLianCao(human, index)
  688. isChange = true
  689. end
  690. end
  691. human.db.moshou.xilian.init = 1
  692. if isChange then
  693. xilianZDLUpdate(human)
  694. if not human.db.moshou.xilian.initTime then
  695. human.db.moshou.xilian.initTime = os.time()
  696. end
  697. end
  698. end
  699. function moshouLvUpToXilianBreak(human)
  700. if not xilianIsOpen(human) then
  701. return
  702. end
  703. local lv = human.db.moshou.lv or 0
  704. initXilianDB(human)
  705. local isChange = false
  706. for index, config in ipairs(MoShouExcel.moshouxlCao) do
  707. if lv >= config.breakLv then
  708. breakXiLianCao(human, index)
  709. isChange = true
  710. end
  711. end
  712. if isChange then
  713. xilianZDLUpdate(human)
  714. if not human.db.moshou.xilian.initTime then
  715. human.db.moshou.xilian.initTime = os.time()
  716. end
  717. end
  718. end
  719. function breakXiLianCao(human, index)
  720. if not human.db.moshou then return end
  721. human.db.moshou.xilian = human.db.moshou.xilian or {}
  722. if not human.db.moshou.xilian.cnt then
  723. human.db.moshou.xilian.cnt = 0
  724. end
  725. if human.db.moshou.xilian[index] then return end
  726. local newKey
  727. local newValue
  728. local haveList = {}
  729. if human.db.moshou and human.db.moshou.xilian then
  730. for _, db in ipairs(human.db.moshou.xilian) do
  731. haveList[db.key] = 1
  732. end
  733. end
  734. human.db.moshou.xilian[index] = {}
  735. local xilian = human.db.moshou.xilian[index]
  736. xilian.id = math.random(1, 5)
  737. local newConfig = MoShouExcel.moshouXiLian[xilian.id]
  738. for k , v in pairs(newConfig.attrs1) do
  739. if v and not haveList[v[1]] then
  740. newKey = v[1]
  741. newValue = v[2]
  742. end
  743. end
  744. xilian.key = newKey
  745. xilian.value = newValue
  746. end
  747. function getXilianNeed(config, type, index)
  748. local need = config["need"..type]
  749. local templateConfig = MoShouExcel.moshouxlCao[index]
  750. return math.floor(need * templateConfig.add)
  751. end
  752. function CG_MOSHOU_XILIAN_QUERY(human, index)
  753. initXilianDB(human)
  754. if index == 0 then
  755. index = human.db.moshou and human.db.moshou.xilian and #human.db.moshou.xilian or 0
  756. end
  757. local msgRet = Msg.gc.GC_MOSHOU_XILIAN_QUERY
  758. makeXilianQuery(human, msgRet)
  759. msgRet.index = index
  760. msgRet.fjAttrs[0] = 0
  761. for k, config in ipairs(MoShouExcel.moshouxlCao) do
  762. msgRet.openLv[k] = config.breakLv
  763. end
  764. msgRet.openLv[0] = #MoShouExcel.moshouxlCao
  765. local bestCnt = getXilianBestCnt(human)
  766. if bestCnt > 0 then
  767. local config = MoShouExcel.moshouxlHx[bestCnt]
  768. for k, v in ipairs(config.attrs) do
  769. msgRet.fjAttrs[k].key = v[1]
  770. msgRet.fjAttrs[k].value = v[2]
  771. end
  772. msgRet.fjAttrs[0] = #config.attrs
  773. end
  774. -- Util.printTable(human.db.moshou.xilian)
  775. -- Msg.trace(msgRet)
  776. Msg.send(msgRet,human.fd)
  777. end
  778. function xilianRandom(type, cnt)
  779. local min = 0
  780. local max = 0
  781. local random = 0
  782. for k, v in ipairs(MoShouExcel.moshouxlRandom) do
  783. if cnt >= v.cnt then
  784. min = v.random[1]
  785. max = v.random[2]
  786. random = v["rareSum"..type]
  787. end
  788. end
  789. local random = math.random(1, random)
  790. for i = min, max do
  791. local config = MoShouExcel.moshouXiLian[i]
  792. if random <= config["rare"..type] then
  793. return i
  794. else
  795. random = random - config["rare"..type]
  796. end
  797. end
  798. end
  799. function CG_MOSHOU_XILIAN_OP(human, op, type, index)
  800. if op == MOSHOU_XILIAN_OP_1 then
  801. xilianDo(human, index, type)
  802. elseif op == MOSHOU_XILIAN_OP_2 then
  803. saveXilian(human, index)
  804. end
  805. end
  806. function randomXilian(id)
  807. local config = MoShouExcel.moshouXiLian[id]
  808. local random = math.random(1, config.attrRareMax)
  809. for k ,v in ipairs(config.attrs1) do
  810. if v and v[3] >= random then
  811. return v[1], v[2]
  812. else
  813. random = random - v[3]
  814. end
  815. end
  816. end
  817. function xilianDo(human, index, type)
  818. if not human.db.moshou or not human.db.moshou.xilian then
  819. return
  820. end
  821. local xilian = human.db.moshou.xilian[index]
  822. if not xilian then return end
  823. if type ~= MOSHOU_XILIAN_OP_1 then -- and type ~= MOSHOU_XILIAN_OP_2 取消钻石洗练
  824. return
  825. end
  826. -- print(" xilianDo xilianDo ", index , type)
  827. local oldConfig = MoShouExcel.moshouXiLian[xilian.id]
  828. -- 洗练方式 验证材料是否够
  829. local itemID
  830. if type == MOSHOU_XILIAN_OP_1 then
  831. itemID = ItemDefine.ITEM_LONGXUE_ID
  832. else
  833. itemID = ItemDefine.ITEM_ZUANSHI_ID
  834. end
  835. local itemCnt = BagLogic.getItemCnt(human, itemID)
  836. local needCnt = oldConfig["need"..type]
  837. if itemCnt < needCnt then
  838. return
  839. end
  840. local newId = xilianRandom(type, human.db.moshou.xilian.cnt or 0)
  841. if not newId then return end
  842. -- print(" new ID ", newId)
  843. local newConfig = MoShouExcel.moshouXiLian[newId]
  844. -- local random = math.random(1, #newConfig["attrs"..type])
  845. -- local key = newConfig["attrs"..type][random][1]
  846. -- local value = newConfig["attrs"..type][random][2]
  847. local key, value = randomXilian(newId)
  848. -- 除所需材料
  849. BagLogic.delItem(human, itemID, needCnt, "moshou")
  850. xilian.lastId = newId
  851. xilian.lastKey = key
  852. xilian.lastValue = value
  853. human.db.moshou.xilian.cnt = human.db.moshou.xilian.cnt + 1
  854. CG_MOSHOU_XILIAN_QUERY(human, index)
  855. end
  856. function saveXilian(human, index)
  857. if not human.db.moshou or not human.db.moshou.xilian then
  858. return
  859. end
  860. local xilian = human.db.moshou.xilian[index]
  861. if not xilian then return end
  862. if not xilian.lastId then return end
  863. local haveIndex
  864. if human.db.moshou and human.db.moshou.xilian then
  865. for k, v in ipairs(human.db.moshou.xilian) do
  866. if v.key == xilian.lastKey then
  867. haveIndex = k
  868. end
  869. end
  870. end
  871. if haveIndex then
  872. local haveDb = human.db.moshou.xilian[haveIndex]
  873. haveDb.id = xilian.lastId
  874. haveDb.key = xilian.lastKey
  875. haveDb.value = xilian.lastValue
  876. xilian.lastId = nil
  877. xilian.lastKey = nil
  878. xilian.lastValue = nil
  879. else
  880. xilian.id = xilian.lastId
  881. xilian.key = xilian.lastKey
  882. xilian.value = xilian.lastValue
  883. xilian.lastId = nil
  884. xilian.lastKey = nil
  885. xilian.lastValue = nil
  886. end
  887. CG_MOSHOU_XILIAN_QUERY(human, index)
  888. xilianZDLUpdate(human)
  889. end
  890. function CG_MOSHOU_XILIAN_GIFT_QUERY(human)
  891. local msgRet = Msg.gc.GC_MOSHOU_XILIAN_GIFT_QUERY
  892. local absAct = YunYingLogic.onCallBack(human, "onQueryLongXue", nil, true)
  893. local len = 0
  894. for k, config in pairs(MoShouExcel.xiLianGift) do
  895. len = len + 1
  896. for j = 1, #config.reward do
  897. Grid.makeItem(msgRet.list[len].item[j], config.reward[j][1], config.reward[j][2])
  898. end
  899. local absCnt = 0
  900. if absAct and absAct ~= 0 and absAct[config.buyID] then
  901. absCnt = absAct[config.buyID].cnt or 0
  902. end
  903. local intCnt = getXilianInitDoubleCnt(human, config.buyID)
  904. local isInitDouble = isXilianInitDouble(human)
  905. local absMax = absAct and absAct[config.buyID] and absAct[config.buyID].max or 0
  906. local initMax = isInitDouble and config.frequency or 0
  907. msgRet.list[len].item[0] = #config.reward
  908. msgRet.list[len].cnt = absCnt + intCnt
  909. msgRet.list[len].id = k
  910. msgRet.list[len].maxCnt = absMax + initMax
  911. msgRet.list[len].icon = config.icon or 0
  912. msgRet.list[len].name = config.name or ""
  913. local buyID = config.buyID
  914. msgRet.list[len].buyMsg[0] = 0
  915. msgRet.list[len].needItem[0] = 0
  916. BuyLogic.fontBuyItem(human, msgRet.list[len].buyMsg[1], buyID)
  917. msgRet.list[len].buyMsg[0] = 1
  918. end
  919. msgRet.list[0] = len
  920. Msg.send(msgRet, human.fd)
  921. end
  922. function isXilianInitDouble(human)
  923. if human.db.moshou.xilian.initTime then
  924. local now = os.time()
  925. local endTime = human.db.moshou.xilian.initTime + 24 * 60 * 60 * 3
  926. if now <= endTime then
  927. return true
  928. end
  929. end
  930. end
  931. function getXilianInitDoubleCnt(human, buyID)
  932. if human.db.moshou.xilian.initTime then
  933. local max = MoShouExcel.xiLianGift[buyID].frequency
  934. local now = os.time()
  935. local endTime = human.db.moshou.xilian.initTime + 24 * 60 * 60 * 3
  936. if now <= endTime then
  937. human.db.moshou.xilian.giftBuy = human.db.moshou.xilian.giftBuy or {}
  938. local oldCnt = human.db.moshou.xilian.giftBuy[buyID] or 0
  939. if oldCnt < max then
  940. return max - oldCnt
  941. end
  942. end
  943. end
  944. return 0
  945. end
  946. function xlianGiftBuy(human, buyID)
  947. local isDouble = false
  948. local doubleBuyCnt = 0
  949. local absCnt = YunYingLogic.onCallBack(human, "onBuyLongXue", buyID, true)
  950. if absCnt then
  951. isDouble = true
  952. end
  953. if human.db.moshou.xilian.initTime and not isDouble then
  954. local intCnt = getXilianInitDoubleCnt(human, buyID)
  955. if intCnt > 0 then
  956. human.db.moshou.xilian.giftBuy[buyID] = human.db.moshou.xilian.giftBuy[buyID] or 0
  957. human.db.moshou.xilian.giftBuy[buyID] = human.db.moshou.xilian.giftBuy[buyID] + 1
  958. isDouble = true
  959. end
  960. end
  961. BagLogic.cleanMomentItemList()
  962. for k, config in pairs(MoShouExcel.xiLianGift) do
  963. if config and config.buyID == buyID then
  964. for _, item in ipairs(config.reward) do
  965. local itemCnt = item[2]
  966. if isDouble then
  967. itemCnt = itemCnt * 2
  968. end
  969. BagLogic.updateMomentItem(1, item[1], itemCnt)
  970. end
  971. BagLogic.addMomentItemList(human, "moshouXlGift")
  972. return
  973. end
  974. end
  975. end
  976. -- 获取魔兽 洗练中有几条传说属性
  977. function getXilianBestCnt(human)
  978. if not human.db.moshou or not human.db.moshou.xilian then
  979. return 0
  980. end
  981. local cnt = 0
  982. for _, db in ipairs(human.db.moshou.xilian) do
  983. local config = MoShouExcel.moshouXiLian[db.id]
  984. if config and config.isSS == 1 then
  985. cnt = cnt + 1
  986. end
  987. end
  988. return cnt
  989. end
  990. -- 魔兽可升级红点
  991. function moshouLVupRed(human)
  992. local nowLV = getMoshouLv(human)
  993. local config = MoShouExcel.moshouLv[nowLV + 1]
  994. if not config then return end
  995. local lvUpNeed = config.lvUpNeed
  996. local enough = nil
  997. for i = 1, #lvUpNeed do
  998. local itemID = lvUpNeed[i][1]
  999. local itemCnt = lvUpNeed[i][2]
  1000. local now = BagLogic.getItemCnt(human, itemID)
  1001. if now >= itemCnt then
  1002. enough =(enough or 0) + 1
  1003. end
  1004. end
  1005. if enough and enough >= #lvUpNeed then return true end
  1006. end
  1007. function moshouSkillUpRed(human)
  1008. if not MoShouExcel.moshouActive[MOSHOU_ID1] then return end
  1009. if not MOSHOU_SKILL[MOSHOU_ID1] then return end
  1010. local moshouLV = getMoshouLv(human)
  1011. local skillLV = getMoShouSkillLv(human)
  1012. local config = MoShouExcel.moshouSkillLv
  1013. if skillLV >= #config then return end
  1014. local nextSkillLv = skillLV + 1
  1015. if not MOSHOU_SKILL[MOSHOU_ID1][1][nextSkillLv] then return end
  1016. local nowArgeCnt = nil
  1017. local canUpNeedType = config[nextSkillLv].canUpNeed[1] or 0
  1018. local canUpNeedValue = config[nextSkillLv].canUpNeed[2] or 0
  1019. if canUpNeedType == MOSHOU_SKILLLV_ARGE1 then
  1020. nowArgeCnt = moshouLV
  1021. else
  1022. return
  1023. end
  1024. if not nowArgeCnt then return end
  1025. if nowArgeCnt < canUpNeedValue then return end
  1026. local upCost = config[nextSkillLv].upCost
  1027. for i = 1, #upCost do
  1028. local itemID = upCost[i][1]
  1029. local itemCnt = upCost[i][2]
  1030. local nowCnt = BagLogic.getItemCnt(human, itemID)
  1031. if nowCnt < itemCnt then
  1032. return
  1033. end
  1034. end
  1035. return true
  1036. end
  1037. -- 魔兽可精炼红点
  1038. function moshouJinglianRed(human)
  1039. local jingLianLV = getMoShouJiLian(human)
  1040. local moshouLV = getMoshouLv(human)
  1041. local jingLianMaxLV = #MoShouExcel.moshouJingLian
  1042. if jingLianLV < jingLianMaxLV then
  1043. local nextConfig = MoShouExcel.moshouJingLian[jingLianLV + 1]
  1044. local lvUpNeed = nextConfig.lvUpNeed
  1045. local enough = nil
  1046. for i = 1, #lvUpNeed do
  1047. local itemID = lvUpNeed[i][1]
  1048. local itemCnt = lvUpNeed[i][2]
  1049. local nowCnt = BagLogic.getItemCnt(human, itemID, itemCnt)
  1050. if nowCnt >= itemCnt then
  1051. enough =(enough or 0) + 1
  1052. end
  1053. end
  1054. if enough and enough >= #lvUpNeed then return true end
  1055. end
  1056. end
  1057. -- 魔兽可铸魂红点
  1058. function moshouZhunHunRed(human)
  1059. local moshouLV = getMoshouLv(human)
  1060. local zhuHunCntMax = MoShouExcel.moshouLv[moshouLV].zhuHunCntMax
  1061. local nowUseCnt = human.db.moshou and human.db.moshou.zhuHun or 0
  1062. if nowUseCnt < zhuHunCntMax then
  1063. local config = MoShouExcel.moshouZhuHun[1]
  1064. local nowCnt = BagLogic.getItemCnt(human, config.costID)
  1065. if nowCnt > 0 then return true end
  1066. end
  1067. end
  1068. -- 魔兽洗练红点
  1069. function moshouXilianUpRed(human)
  1070. if human.db.moshou and human.db.moshou.xilian then
  1071. local itemCnt = BagLogic.getItemCnt(human, ItemDefine.ITEM_LONGXUE_ID)
  1072. for k, db in ipairs(human.db.moshou.xilian) do
  1073. local config = MoShouExcel.moshouXiLian[db.id]
  1074. if itemCnt >= config.need1 then
  1075. return true
  1076. end
  1077. end
  1078. end
  1079. end
  1080. function isDot(human)
  1081. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  1082. if not cjPrivilege then
  1083. return ChengjiuLogic.isFinish(human, 402)
  1084. end
  1085. -- 魔兽可升级
  1086. if moshouLVupRed(human) then return true end
  1087. -- 魔兽可精炼
  1088. if moshouJinglianRed(human) then return true end
  1089. -- 魔兽可铸魂
  1090. if moshouZhunHunRed(human) then return true end
  1091. -- 技能可升级
  1092. if moshouSkillUpRed(human) then return true end
  1093. end
  1094. ------------------------------外部接口相关-----------------------------------------
  1095. -- 创建魔兽结构体
  1096. function createCombatMoshow(human, combatType)
  1097. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  1098. if not cjPrivilege then return end
  1099. local id = CombatPosLogic.getCombatMoshou(human, combatType)
  1100. if not id or id < 1 then return end
  1101. if not MOSHOU_SKILL[MOSHOU_ID1][id] then return end
  1102. local config = MoShouExcel.moshouActive[MOSHOU_ID1]
  1103. local pet = { }
  1104. pet.isPet = true
  1105. pet.petID = MOSHOU_ID1
  1106. pet.id = id
  1107. pet.lv = getMoshouLv(human)
  1108. pet.body = config.body
  1109. pet.jinglianLV = getMoShouJiLian(human)
  1110. pet.zhuHun = getMoShouZhuHunNum(human)
  1111. pet.skillLV = getMoShouSkillLv(human)
  1112. if human.db.moshou and human.db.moshou.lvAttrsAdd then
  1113. pet.lvAttrsAdd = Util.copyTable(human.db.moshou.lvAttrsAdd)
  1114. else
  1115. pet.lvAttrsAdd = {}
  1116. end
  1117. if MOSHOU_SKILL[MOSHOU_ID1][id][pet.skillLV] then
  1118. local skillID = MOSHOU_SKILL[1][id][pet.skillLV]
  1119. local skillConfig = SkillExcel.skill[skillID]
  1120. local cd1 = skillConfig.cd[1] or 0
  1121. local cd2 = skillConfig.cd[2] or 0
  1122. pet.icon = skillID
  1123. pet.skillList = { }
  1124. pet.skillList[1] = { skillID, cd1, cd2 }
  1125. pet.cd = cd2
  1126. end
  1127. return pet
  1128. end
  1129. -- 获取出战魔兽的skillID
  1130. function getPutMoshouSkillID(human, combatType)
  1131. local putOnMoshou = CombatPosLogic.getCombatMoshou(human, combatType)
  1132. if not putOnMoshou or putOnMoshou < 1 then return end
  1133. if not MOSHOU_SKILL[MOSHOU_ID1][putOnMoshou] then return end
  1134. local skillLV = getMoShouSkillLv(human)
  1135. local skillID = MOSHOU_SKILL[MOSHOU_ID1][putOnMoshou][skillLV]
  1136. return skillID
  1137. end
  1138. -- 获取出战魔兽形象
  1139. function getCombatMoshouBody(human, combatType)
  1140. local id = CombatPosLogic.getCombatMoshou(human, combatType)
  1141. if not id or id < 1 then return 0 end
  1142. local config = MoShouExcel.moshouActive[MOSHOU_ID1]
  1143. return config and config.body or 0
  1144. end
  1145. -- 获取魔兽等级
  1146. function getMoshouLv(human)
  1147. if human.db.moshou and human.db.moshou.lv then
  1148. return human.db.moshou.lv
  1149. end
  1150. return 1
  1151. end
  1152. -- 获取精炼等级
  1153. function getMoShouJiLian(human)
  1154. return human.db.moshou and human.db.moshou.jingLian or 0
  1155. end
  1156. -- 获取技能等级
  1157. function getMoShouSkillLv(human)
  1158. if human.db.moshou and human.db.moshou.skillLV then
  1159. return human.db.moshou.skillLV
  1160. end
  1161. return 1
  1162. end
  1163. -- 获取铸魂数
  1164. function getMoShouZhuHunNum(human)
  1165. return human.db.moshou and human.db.moshou.zhuHun or 0
  1166. end
  1167. -- 出战界面
  1168. function setHelp(net, moshouID)
  1169. net.type = CombatDefine.HELP_TYPE1
  1170. net.id = moshouID
  1171. net.icon = MoShouExcel.moshouActive[MOSHOU_ID1].icon
  1172. end
  1173. function setPosHelp(net, moshouID)
  1174. net.type = CombatDefine.HELP_TYPE1
  1175. net.id = moshouID
  1176. net.icon = MoShouExcel.moshouActive[MOSHOU_ID1].icon
  1177. end
  1178. -- 战斗阵容封装
  1179. function setCombatHelp(net, moshouObj, pos)
  1180. net.pos = pos
  1181. net.id = moshouObj.petID
  1182. net.head = moshouObj.head
  1183. net.body = moshouObj.body
  1184. net.args[0] = 0
  1185. end
  1186. --
  1187. function setSkillAndBeskill(human, combatInfo)
  1188. for atkPos, atkObj in pairs(CombatImpl.helpList) do
  1189. local skill = human.db.moshou.putOnMoshou
  1190. if atkObj.side == CombatDefine.ATTACK_SIDE and skill then
  1191. atkObj.skillList = {skill}
  1192. atkObj.beSkillList = {}
  1193. end
  1194. --print("===============", atkPos, skill and skill.skillList, skill and skill.beSkillList)
  1195. end
  1196. end