MoshouLogic.lua 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427
  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. human.db.moshou = human.db.moshou or {}
  677. if not xilianIsOpen(human) then
  678. return
  679. end
  680. if human.db.moshou.xilian and human.db.moshou.xilian.init then
  681. return
  682. end
  683. -- local weekDay = Util.getWeekDay()
  684. -- if weekDay ~= 4 and weekDay ~= 7 then
  685. -- return
  686. -- end
  687. local lv = human.db.moshou.lv or 0
  688. local isChange = false
  689. for index, config in ipairs(MoShouExcel.moshouxlCao) do
  690. if lv >= config.breakLv then
  691. breakXiLianCao(human, index)
  692. isChange = true
  693. end
  694. end
  695. human.db.moshou.xilian.init = 1
  696. if isChange then
  697. xilianZDLUpdate(human)
  698. if not human.db.moshou.xilian.initTime then
  699. human.db.moshou.xilian.initTime = os.time()
  700. end
  701. end
  702. end
  703. function moshouLvUpToXilianBreak(human)
  704. if not xilianIsOpen(human) then
  705. return
  706. end
  707. local lv = human.db.moshou.lv or 0
  708. initXilianDB(human)
  709. local isChange = false
  710. for index, config in ipairs(MoShouExcel.moshouxlCao) do
  711. if lv >= config.breakLv then
  712. breakXiLianCao(human, index)
  713. isChange = true
  714. end
  715. end
  716. if isChange then
  717. xilianZDLUpdate(human)
  718. if not human.db.moshou.xilian.initTime then
  719. human.db.moshou.xilian.initTime = os.time()
  720. end
  721. end
  722. end
  723. function breakXiLianCao(human, index)
  724. if not human.db.moshou then return end
  725. human.db.moshou.xilian = human.db.moshou.xilian or {}
  726. if not human.db.moshou.xilian.cnt then
  727. human.db.moshou.xilian.cnt = 0
  728. end
  729. if human.db.moshou.xilian[index] then return end
  730. local newKey
  731. local newValue
  732. local haveList = {}
  733. if human.db.moshou and human.db.moshou.xilian then
  734. for _, db in ipairs(human.db.moshou.xilian) do
  735. haveList[db.key] = 1
  736. end
  737. end
  738. human.db.moshou.xilian[index] = {}
  739. local xilian = human.db.moshou.xilian[index]
  740. xilian.id = math.random(1, 5)
  741. local newConfig = MoShouExcel.moshouXiLian[xilian.id]
  742. for k , v in pairs(newConfig.attrs1) do
  743. if v and not haveList[v[1]] then
  744. newKey = v[1]
  745. newValue = v[2]
  746. end
  747. end
  748. xilian.key = newKey
  749. xilian.value = newValue
  750. end
  751. function getXilianNeed(config, type, index)
  752. local need = config["need"..type]
  753. local templateConfig = MoShouExcel.moshouxlCao[index]
  754. return math.floor(need * templateConfig.add)
  755. end
  756. function CG_MOSHOU_XILIAN_QUERY(human, index)
  757. initXilianDB(human)
  758. if index == 0 then
  759. index = human.db.moshou and human.db.moshou.xilian and #human.db.moshou.xilian or 0
  760. end
  761. local msgRet = Msg.gc.GC_MOSHOU_XILIAN_QUERY
  762. makeXilianQuery(human, msgRet)
  763. msgRet.index = index
  764. msgRet.fjAttrs[0] = 0
  765. for k, config in ipairs(MoShouExcel.moshouxlCao) do
  766. msgRet.openLv[k] = config.breakLv
  767. end
  768. msgRet.openLv[0] = #MoShouExcel.moshouxlCao
  769. local bestCnt = getXilianBestCnt(human)
  770. if bestCnt > 0 then
  771. local config = MoShouExcel.moshouxlHx[bestCnt]
  772. for k, v in ipairs(config.attrs) do
  773. msgRet.fjAttrs[k].key = v[1]
  774. msgRet.fjAttrs[k].value = v[2]
  775. end
  776. msgRet.fjAttrs[0] = #config.attrs
  777. end
  778. -- Util.printTable(human.db.moshou.xilian)
  779. -- Msg.trace(msgRet)
  780. Msg.send(msgRet,human.fd)
  781. end
  782. function xilianRandom(type, cnt)
  783. local min = 0
  784. local max = 0
  785. local random = 0
  786. for k, v in ipairs(MoShouExcel.moshouxlRandom) do
  787. if cnt >= v.cnt then
  788. min = v.random[1]
  789. max = v.random[2]
  790. random = v["rareSum"..type]
  791. end
  792. end
  793. local random = math.random(1, random)
  794. for i = min, max do
  795. local config = MoShouExcel.moshouXiLian[i]
  796. if random <= config["rare"..type] then
  797. return i
  798. else
  799. random = random - config["rare"..type]
  800. end
  801. end
  802. end
  803. function CG_MOSHOU_XILIAN_OP(human, op, type, index)
  804. if op == MOSHOU_XILIAN_OP_1 then
  805. xilianDo(human, index, type)
  806. elseif op == MOSHOU_XILIAN_OP_2 then
  807. saveXilian(human, index)
  808. end
  809. end
  810. function randomXilian(id)
  811. local config = MoShouExcel.moshouXiLian[id]
  812. local random = math.random(1, config.attrRareMax)
  813. for k ,v in ipairs(config.attrs1) do
  814. if v and v[3] >= random then
  815. return v[1], v[2]
  816. else
  817. random = random - v[3]
  818. end
  819. end
  820. end
  821. function xilianDo(human, index, type)
  822. if not human.db.moshou or not human.db.moshou.xilian then
  823. return
  824. end
  825. local xilian = human.db.moshou.xilian[index]
  826. if not xilian then return end
  827. if type ~= MOSHOU_XILIAN_OP_1 then -- and type ~= MOSHOU_XILIAN_OP_2 取消钻石洗练
  828. return
  829. end
  830. -- print(" xilianDo xilianDo ", index , type)
  831. local oldConfig = MoShouExcel.moshouXiLian[xilian.id]
  832. -- 洗练方式 验证材料是否够
  833. local itemID
  834. if type == MOSHOU_XILIAN_OP_1 then
  835. itemID = ItemDefine.ITEM_LONGXUE_ID
  836. else
  837. itemID = ItemDefine.ITEM_ZUANSHI_ID
  838. end
  839. local itemCnt = BagLogic.getItemCnt(human, itemID)
  840. local needCnt = oldConfig["need"..type]
  841. if itemCnt < needCnt then
  842. return
  843. end
  844. local newId = xilianRandom(type, human.db.moshou.xilian.cnt or 0)
  845. if not newId then return end
  846. -- print(" new ID ", newId)
  847. local newConfig = MoShouExcel.moshouXiLian[newId]
  848. -- local random = math.random(1, #newConfig["attrs"..type])
  849. -- local key = newConfig["attrs"..type][random][1]
  850. -- local value = newConfig["attrs"..type][random][2]
  851. local key, value = randomXilian(newId)
  852. -- 除所需材料
  853. BagLogic.delItem(human, itemID, needCnt, "moshou")
  854. xilian.lastId = newId
  855. xilian.lastKey = key
  856. xilian.lastValue = value
  857. human.db.moshou.xilian.cnt = human.db.moshou.xilian.cnt + 1
  858. CG_MOSHOU_XILIAN_QUERY(human, index)
  859. end
  860. function saveXilian(human, index)
  861. if not human.db.moshou or not human.db.moshou.xilian then
  862. return
  863. end
  864. local xilian = human.db.moshou.xilian[index]
  865. if not xilian then return end
  866. if not xilian.lastId then return end
  867. local haveIndex
  868. if human.db.moshou and human.db.moshou.xilian then
  869. for k, v in ipairs(human.db.moshou.xilian) do
  870. if v.key == xilian.lastKey then
  871. haveIndex = k
  872. end
  873. end
  874. end
  875. if haveIndex then
  876. local haveDb = human.db.moshou.xilian[haveIndex]
  877. haveDb.id = xilian.lastId
  878. haveDb.key = xilian.lastKey
  879. haveDb.value = xilian.lastValue
  880. xilian.lastId = nil
  881. xilian.lastKey = nil
  882. xilian.lastValue = nil
  883. else
  884. xilian.id = xilian.lastId
  885. xilian.key = xilian.lastKey
  886. xilian.value = xilian.lastValue
  887. xilian.lastId = nil
  888. xilian.lastKey = nil
  889. xilian.lastValue = nil
  890. end
  891. CG_MOSHOU_XILIAN_QUERY(human, index)
  892. xilianZDLUpdate(human)
  893. end
  894. function CG_MOSHOU_XILIAN_GIFT_QUERY(human)
  895. local msgRet = Msg.gc.GC_MOSHOU_XILIAN_GIFT_QUERY
  896. local absAct = YunYingLogic.onCallBack(human, "onQueryLongXue", nil, true)
  897. local len = 0
  898. for k, config in pairs(MoShouExcel.xiLianGift) do
  899. len = len + 1
  900. for j = 1, #config.reward do
  901. Grid.makeItem(msgRet.list[len].item[j], config.reward[j][1], config.reward[j][2])
  902. end
  903. local absCnt = 0
  904. if absAct and absAct ~= 0 and absAct[config.buyID] then
  905. absCnt = absAct[config.buyID].cnt or 0
  906. end
  907. local intCnt = getXilianInitDoubleCnt(human, config.buyID)
  908. local isInitDouble = isXilianInitDouble(human)
  909. local absMax = absAct and absAct[config.buyID] and absAct[config.buyID].max or 0
  910. local initMax = isInitDouble and config.frequency or 0
  911. msgRet.list[len].item[0] = #config.reward
  912. msgRet.list[len].cnt = absCnt + intCnt
  913. msgRet.list[len].id = k
  914. msgRet.list[len].maxCnt = absMax + initMax
  915. msgRet.list[len].icon = config.icon or 0
  916. msgRet.list[len].name = config.name or ""
  917. local buyID = config.buyID
  918. msgRet.list[len].buyMsg[0] = 0
  919. msgRet.list[len].needItem[0] = 0
  920. BuyLogic.fontBuyItem(human, msgRet.list[len].buyMsg[1], buyID)
  921. msgRet.list[len].buyMsg[0] = 1
  922. end
  923. msgRet.list[0] = len
  924. Msg.send(msgRet, human.fd)
  925. end
  926. function isXilianInitDouble(human)
  927. if human.db.moshou.xilian.initTime then
  928. local now = os.time()
  929. local endTime = human.db.moshou.xilian.initTime + 24 * 60 * 60 * 3
  930. if now <= endTime then
  931. return true
  932. end
  933. end
  934. end
  935. function getXilianInitDoubleCnt(human, buyID)
  936. if human.db.moshou.xilian.initTime then
  937. local max = MoShouExcel.xiLianGift[buyID].frequency
  938. local now = os.time()
  939. local endTime = human.db.moshou.xilian.initTime + 24 * 60 * 60 * 3
  940. if now <= endTime then
  941. human.db.moshou.xilian.giftBuy = human.db.moshou.xilian.giftBuy or {}
  942. local oldCnt = human.db.moshou.xilian.giftBuy[buyID] or 0
  943. if oldCnt < max then
  944. return max - oldCnt
  945. end
  946. end
  947. end
  948. return 0
  949. end
  950. function xlianGiftBuy(human, buyID)
  951. local isDouble = false
  952. local doubleBuyCnt = 0
  953. local absCnt = YunYingLogic.onCallBack(human, "onBuyLongXue", buyID, true)
  954. if absCnt then
  955. isDouble = true
  956. end
  957. if human.db.moshou.xilian.initTime and not isDouble then
  958. local intCnt = getXilianInitDoubleCnt(human, buyID)
  959. if intCnt > 0 then
  960. human.db.moshou.xilian.giftBuy[buyID] = human.db.moshou.xilian.giftBuy[buyID] or 0
  961. human.db.moshou.xilian.giftBuy[buyID] = human.db.moshou.xilian.giftBuy[buyID] + 1
  962. isDouble = true
  963. end
  964. end
  965. BagLogic.cleanMomentItemList()
  966. for k, config in pairs(MoShouExcel.xiLianGift) do
  967. if config and config.buyID == buyID then
  968. for _, item in ipairs(config.reward) do
  969. local itemCnt = item[2]
  970. if isDouble then
  971. itemCnt = itemCnt * 2
  972. end
  973. BagLogic.updateMomentItem(1, item[1], itemCnt)
  974. end
  975. BagLogic.addMomentItemList(human, "moshouXlGift")
  976. return
  977. end
  978. end
  979. end
  980. -- 获取魔兽 洗练中有几条传说属性
  981. function getXilianBestCnt(human)
  982. if not human.db.moshou or not human.db.moshou.xilian then
  983. return 0
  984. end
  985. local cnt = 0
  986. for _, db in ipairs(human.db.moshou.xilian) do
  987. local config = MoShouExcel.moshouXiLian[db.id]
  988. if config and config.isSS == 1 then
  989. cnt = cnt + 1
  990. end
  991. end
  992. return cnt
  993. end
  994. -- 魔兽可升级红点
  995. function moshouLVupRed(human)
  996. local nowLV = getMoshouLv(human)
  997. local config = MoShouExcel.moshouLv[nowLV + 1]
  998. if not config then return end
  999. local lvUpNeed = config.lvUpNeed
  1000. local enough = nil
  1001. for i = 1, #lvUpNeed do
  1002. local itemID = lvUpNeed[i][1]
  1003. local itemCnt = lvUpNeed[i][2]
  1004. local now = BagLogic.getItemCnt(human, itemID)
  1005. if now >= itemCnt then
  1006. enough =(enough or 0) + 1
  1007. end
  1008. end
  1009. if enough and enough >= #lvUpNeed then return true end
  1010. end
  1011. function moshouSkillUpRed(human)
  1012. if not MoShouExcel.moshouActive[MOSHOU_ID1] then return end
  1013. if not MOSHOU_SKILL[MOSHOU_ID1] then return end
  1014. local moshouLV = getMoshouLv(human)
  1015. local skillLV = getMoShouSkillLv(human)
  1016. local config = MoShouExcel.moshouSkillLv
  1017. if skillLV >= #config then return end
  1018. local nextSkillLv = skillLV + 1
  1019. if not MOSHOU_SKILL[MOSHOU_ID1][1][nextSkillLv] then return end
  1020. local nowArgeCnt = nil
  1021. local canUpNeedType = config[nextSkillLv].canUpNeed[1] or 0
  1022. local canUpNeedValue = config[nextSkillLv].canUpNeed[2] or 0
  1023. if canUpNeedType == MOSHOU_SKILLLV_ARGE1 then
  1024. nowArgeCnt = moshouLV
  1025. else
  1026. return
  1027. end
  1028. if not nowArgeCnt then return end
  1029. if nowArgeCnt < canUpNeedValue then return end
  1030. local upCost = config[nextSkillLv].upCost
  1031. for i = 1, #upCost do
  1032. local itemID = upCost[i][1]
  1033. local itemCnt = upCost[i][2]
  1034. local nowCnt = BagLogic.getItemCnt(human, itemID)
  1035. if nowCnt < itemCnt then
  1036. return
  1037. end
  1038. end
  1039. return true
  1040. end
  1041. -- 魔兽可精炼红点
  1042. function moshouJinglianRed(human)
  1043. local jingLianLV = getMoShouJiLian(human)
  1044. local moshouLV = getMoshouLv(human)
  1045. local jingLianMaxLV = #MoShouExcel.moshouJingLian
  1046. if jingLianLV < jingLianMaxLV then
  1047. local nextConfig = MoShouExcel.moshouJingLian[jingLianLV + 1]
  1048. local lvUpNeed = nextConfig.lvUpNeed
  1049. local enough = nil
  1050. for i = 1, #lvUpNeed do
  1051. local itemID = lvUpNeed[i][1]
  1052. local itemCnt = lvUpNeed[i][2]
  1053. local nowCnt = BagLogic.getItemCnt(human, itemID, itemCnt)
  1054. if nowCnt >= itemCnt then
  1055. enough =(enough or 0) + 1
  1056. end
  1057. end
  1058. if enough and enough >= #lvUpNeed then return true end
  1059. end
  1060. end
  1061. -- 魔兽可铸魂红点
  1062. function moshouZhunHunRed(human)
  1063. local moshouLV = getMoshouLv(human)
  1064. local zhuHunCntMax = MoShouExcel.moshouLv[moshouLV].zhuHunCntMax
  1065. local nowUseCnt = human.db.moshou and human.db.moshou.zhuHun or 0
  1066. if nowUseCnt < zhuHunCntMax then
  1067. local config = MoShouExcel.moshouZhuHun[1]
  1068. local nowCnt = BagLogic.getItemCnt(human, config.costID)
  1069. if nowCnt > 0 then return true end
  1070. end
  1071. end
  1072. -- 魔兽洗练红点
  1073. function moshouXilianUpRed(human)
  1074. if human.db.moshou and human.db.moshou.xilian then
  1075. local itemCnt = BagLogic.getItemCnt(human, ItemDefine.ITEM_LONGXUE_ID)
  1076. for k, db in ipairs(human.db.moshou.xilian) do
  1077. local config = MoShouExcel.moshouXiLian[db.id]
  1078. if itemCnt >= config.need1 then
  1079. return true
  1080. end
  1081. end
  1082. end
  1083. end
  1084. function isDot(human)
  1085. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  1086. if not cjPrivilege then
  1087. return ChengjiuLogic.isFinish(human, 402)
  1088. end
  1089. -- 魔兽可升级
  1090. if moshouLVupRed(human) then return true end
  1091. -- 魔兽可精炼
  1092. if moshouJinglianRed(human) then return true end
  1093. -- 魔兽可铸魂
  1094. if moshouZhunHunRed(human) then return true end
  1095. -- 技能可升级
  1096. if moshouSkillUpRed(human) then return true end
  1097. end
  1098. ------------------------------外部接口相关-----------------------------------------
  1099. -- 创建魔兽结构体
  1100. function createCombatMoshow(human, combatType)
  1101. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  1102. if not cjPrivilege then return end
  1103. local id = CombatPosLogic.getCombatMoshou(human, combatType)
  1104. if not id or id < 1 then return end
  1105. if not MOSHOU_SKILL[MOSHOU_ID1][id] then return end
  1106. local config = MoShouExcel.moshouActive[MOSHOU_ID1]
  1107. local pet = { }
  1108. pet.isPet = true
  1109. pet.petID = MOSHOU_ID1
  1110. pet.id = id
  1111. pet.lv = getMoshouLv(human)
  1112. pet.body = config.body
  1113. pet.jinglianLV = getMoShouJiLian(human)
  1114. pet.zhuHun = getMoShouZhuHunNum(human)
  1115. pet.skillLV = getMoShouSkillLv(human)
  1116. if human.db.moshou and human.db.moshou.lvAttrsAdd then
  1117. pet.lvAttrsAdd = Util.copyTable(human.db.moshou.lvAttrsAdd)
  1118. else
  1119. pet.lvAttrsAdd = {}
  1120. end
  1121. if MOSHOU_SKILL[MOSHOU_ID1][id][pet.skillLV] then
  1122. local skillID = MOSHOU_SKILL[1][id][pet.skillLV]
  1123. local skillConfig = SkillExcel.skill[skillID]
  1124. local cd1 = skillConfig.cd[1] or 0
  1125. local cd2 = skillConfig.cd[2] or 0
  1126. pet.icon = skillID
  1127. pet.skillList = { }
  1128. pet.skillList[1] = { skillID, cd1, cd2 }
  1129. pet.cd = cd2
  1130. end
  1131. return pet
  1132. end
  1133. -- 获取出战魔兽的skillID
  1134. function getPutMoshouSkillID(human, combatType)
  1135. local putOnMoshou = CombatPosLogic.getCombatMoshou(human, combatType)
  1136. if not putOnMoshou or putOnMoshou < 1 then return end
  1137. if not MOSHOU_SKILL[MOSHOU_ID1][putOnMoshou] then return end
  1138. local skillLV = getMoShouSkillLv(human)
  1139. local skillID = MOSHOU_SKILL[MOSHOU_ID1][putOnMoshou][skillLV]
  1140. return skillID
  1141. end
  1142. -- 获取出战魔兽形象
  1143. function getCombatMoshouBody(human, combatType)
  1144. local id = CombatPosLogic.getCombatMoshou(human, combatType)
  1145. if not id or id < 1 then return 0 end
  1146. local config = MoShouExcel.moshouActive[MOSHOU_ID1]
  1147. return config and config.body or 0
  1148. end
  1149. -- 获取魔兽等级
  1150. function getMoshouLv(human)
  1151. if human.db.moshou and human.db.moshou.lv then
  1152. return human.db.moshou.lv
  1153. end
  1154. return 1
  1155. end
  1156. -- 获取精炼等级
  1157. function getMoShouJiLian(human)
  1158. return human.db.moshou and human.db.moshou.jingLian or 0
  1159. end
  1160. -- 获取技能等级
  1161. function getMoShouSkillLv(human)
  1162. if human.db.moshou and human.db.moshou.skillLV then
  1163. return human.db.moshou.skillLV
  1164. end
  1165. return 1
  1166. end
  1167. -- 获取铸魂数
  1168. function getMoShouZhuHunNum(human)
  1169. return human.db.moshou and human.db.moshou.zhuHun or 0
  1170. end
  1171. -- 出战界面
  1172. function setHelp(net, moshouID)
  1173. net.type = CombatDefine.HELP_TYPE1
  1174. net.id = moshouID
  1175. net.icon = MoShouExcel.moshouActive[MOSHOU_ID1].icon
  1176. end
  1177. function setPosHelp(net, moshouID)
  1178. net.type = CombatDefine.HELP_TYPE1
  1179. net.id = moshouID
  1180. net.icon = MoShouExcel.moshouActive[MOSHOU_ID1].icon
  1181. end
  1182. -- 战斗阵容封装
  1183. function setCombatHelp(net, moshouObj, pos)
  1184. net.pos = pos
  1185. net.id = moshouObj.petID
  1186. net.head = moshouObj.head
  1187. net.body = moshouObj.body
  1188. net.args[0] = 0
  1189. end
  1190. --
  1191. function setSkillAndBeskill(human, combatInfo)
  1192. for atkPos, atkObj in pairs(CombatImpl.helpList) do
  1193. local skill = human.db.moshou.putOnMoshou
  1194. if atkObj.side == CombatDefine.ATTACK_SIDE and skill then
  1195. atkObj.skillList = {skill}
  1196. atkObj.beSkillList = {}
  1197. end
  1198. --print("===============", atkPos, skill and skill.skillList, skill and skill.beSkillList)
  1199. end
  1200. end