MoshouLogic.lua 46 KB

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