MoshouLogic.lua 44 KB

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