TheStarsLogic.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. -----------------------------------------------------------
  2. -- 星空争霸/王者争霸
  3. -----------------------------------------------------------
  4. local MonsterExcel = require("excel.monster")
  5. local ThroneExcel = require("excel.throne")
  6. local MailExcel = require("excel.mail")
  7. local RoleExcel = require("excel.role")
  8. -- local Lang = require("common.Lang")
  9. local Util = require("common.Util")
  10. local Lang = require("common.Lang")
  11. local Msg = require("core.Msg")
  12. local ObjHuman = require("core.ObjHuman")
  13. local Broadcast = require("broadcast.Broadcast")
  14. local CombatLogic = require("combat.CombatLogic")
  15. local CombatDefine = require("combat.CombatDefine")
  16. local CombatPosLogic = require("combat.CombatPosLogic")
  17. local CombatVideo = require("combat.CombatVideo")
  18. local HeroGrid = require("hero.HeroGrid")
  19. local JjcDB = require("jjc.JjcDB")
  20. local RoleDefine = require("role.RoleDefine")
  21. local RoleLogic = require("role.RoleLogic")
  22. local RoleDBLogic = require("role.RoleDBLogic")
  23. local RoleHeadLogic = require("role.RoleHeadLogic")
  24. local RoleAttr = require("role.RoleAttr")
  25. local MailManager = require("mail.MailManager")
  26. local TheStarsDBLogic = require("theStars.TheStarsDBLogic")
  27. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  28. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  29. -- local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  30. -- local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
  31. local JjcLogic = require("jjc.JjcLogic")
  32. local ItemExcel = require("excel.item").item
  33. local MailDefine = require("mail.MailIdDefine")
  34. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  35. local HeroGrowUp = require("absAct.HeroGrowUp")
  36. local HeroLogic = require("hero.HeroLogic")
  37. local HeroExcel = require("excel.hero")
  38. local FAIL_COMBAT_CD = 1200 -- 失败后冷却CD 1200
  39. local function getTargetHuman(playerUuid)
  40. local targetHuman = ObjHuman.onlineUuid[playerUuid]
  41. if not targetHuman then
  42. local db = RoleDBLogic.getDb(playerUuid)
  43. if db then
  44. targetHuman = {}
  45. targetHuman.db = db
  46. end
  47. end
  48. return targetHuman
  49. end
  50. function isOpen(human,sendErr)
  51. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1303,sendErr) then
  52. return
  53. end
  54. return true
  55. end
  56. -- 根据等级和id获取怪物组
  57. function getMonsterOutID(id, lv)
  58. for i = 1, #ThroneExcel.guard do
  59. local configTemp = ThroneExcel.guard[i]
  60. if lv <= configTemp.lv then
  61. return configTemp.monsterOutID[id]
  62. end
  63. end
  64. end
  65. function theStarsQuery(human)
  66. if not isOpen(human,true) then return end
  67. -- 取王座信息
  68. local list = TheStarsDBLogic.getThroneList()
  69. -- 写入数据
  70. local msgRet = Msg.gc.GC_THE_STARS_QUERY
  71. msgRet.throneMsg[0] = #list
  72. for i, throne in ipairs(list) do
  73. local cf = ThroneExcel.throne[i]
  74. local throneNet = msgRet.throneMsg[i]
  75. if throne.uuid ~= nil then
  76. -- 王座有占领者
  77. local db = RoleDBLogic.getDb(throne.uuid, "name")
  78. throneNet.name = db and db.name or ""
  79. throneNet.bodyID = throne.body or 0
  80. else
  81. -- 王座虚位以待
  82. throneNet.name = Lang.IS_EMPTY
  83. throneNet.bodyID = cf.monsterShow
  84. end
  85. throneNet.id = throne.id
  86. throneNet.vestId = throne._id
  87. local chconfig = ItemExcel[cf.chenghaoID]
  88. throneNet.chenghaoIcon = chconfig.icon
  89. end
  90. --Msg.trace(msgRet)
  91. Msg.send(msgRet,human.fd)
  92. end
  93. function theStarsThroneQuery(human, id, vestId)
  94. if not isOpen(human,true) then return end
  95. local cf = ThroneExcel.throne[id]
  96. if not cf then return end
  97. -- 取出王座数据
  98. local throne = TheStarsDBLogic.getThroneByVestId(vestId)
  99. if not throne or throne.id ~= id then
  100. return Broadcast.sendErr(human, Lang.THRONE_INFO_NOT_INIT)
  101. end
  102. local msgRet = Msg.gc.GC_THE_STARS_THRONE_QUERY
  103. msgRet.needRank = cf.maxRank
  104. -- 取占领者信息
  105. msgRet.isKing = 0
  106. msgRet.roleData[0] = 0
  107. if throne.uuid then
  108. msgRet.roleData[0] = 1
  109. RoleLogic.getRoleBaseByUuid(throne.uuid, msgRet.roleData[1])
  110. if throne.uuid == human.db._id then
  111. msgRet.isKing = 1
  112. end
  113. end
  114. local list = TheStarsDBLogic.getThroneList()
  115. for i, v in ipairs(list) do
  116. if v.uuid ~= nil and v.uuid == human.db._id and msgRet.isKing == 0 then
  117. msgRet.isKing = 2
  118. break
  119. end
  120. end
  121. local chconfig = RoleExcel.chenghao[cf.chenghaoID]
  122. -- 取王座属性
  123. msgRet.attrs[0] = #chconfig.attrs
  124. for i = 1, msgRet.attrs[0] do
  125. local net = msgRet.attrs[i]
  126. net.key = chconfig.attrs[i][1]
  127. net.value = chconfig.attrs[i][2]
  128. end
  129. local jjcRank = JjcDB.getRank(human.db._id)
  130. msgRet.rank = jjcRank >= 0 and jjcRank or 0
  131. msgRet.lv = throne.lv
  132. msgRet.nowEvolveCnt = throne.evolve or 0
  133. msgRet.monsterList[0] = 0
  134. if throne.uuid then
  135. local targetHuman = getTargetHuman(throne.uuid)
  136. if targetHuman then
  137. local len = 0
  138. local heroList = CombatPosLogic.getCombatHeros(targetHuman, CombatDefine.COMBAT_TYPE5)
  139. for _, heroUuid in pairs(heroList or {}) do
  140. local heroGrid = HeroLogic.getHeroGridByUuid(targetHuman, heroUuid)
  141. if heroGrid then
  142. len = len + 1
  143. msgRet.monsterList[0] = len
  144. local heroCfg = HeroExcel.hero[heroGrid.id]
  145. msgRet.monsterList[len].body = heroGrid.body or heroCfg.body
  146. msgRet.monsterList[len].lv = heroGrid.lv or 0
  147. msgRet.monsterList[len].camp = heroCfg.camp
  148. end
  149. end
  150. end
  151. else
  152. local monsterOutID = getMonsterOutID(throne.id, throne.lv)
  153. local monsterOutConfig = MonsterExcel.monsterOut[monsterOutID]
  154. local count = #monsterOutConfig.member
  155. for i = 1,count do
  156. local monsterID = monsterOutConfig.member[i][1]
  157. local lv = monsterOutConfig.member[i][2]
  158. local mcf = MonsterExcel.monster[monsterID]
  159. msgRet.monsterList[i].body = mcf.body
  160. msgRet.monsterList[i].lv = throne.lv
  161. msgRet.monsterList[i].camp = mcf.camp
  162. end
  163. msgRet.monsterList[0] = count
  164. end
  165. Msg.send(msgRet, human.fd)
  166. end
  167. local function getFightCoolTime(human)
  168. if not human.db.throneTime then
  169. return 0
  170. end
  171. local sec = os.time() - human.db.throneTime
  172. return math.max(FAIL_COMBAT_CD - sec, 0)
  173. end
  174. local function getNewLvExp(id, lv, exp, evolveCnt)
  175. local starsCf = ThroneExcel.theStars[lv]
  176. exp = evolveCnt * starsCf.evolveExp + exp
  177. while exp >= starsCf.exp do
  178. lv = lv + 1
  179. exp = exp - starsCf.exp
  180. end
  181. local cf = ThroneExcel.throne[id]
  182. lv = math.min(cf.maxLv, lv)
  183. return lv, exp
  184. end
  185. function checkCombatPos(human, args)
  186. if not isOpen(human,true) then return end
  187. local id = tonumber(args[1] or 0)
  188. local evolveCnt = tonumber(args[2] or 0)
  189. local vestId = args[3]
  190. -- if evolveCnt < 1 then return end -- 升级次数小于1,怀疑有人作弊
  191. local cf = ThroneExcel.throne[id]
  192. if not cf then return end
  193. local throne = TheStarsDBLogic.getThroneByVestId(vestId)
  194. if not throne or throne.id ~= id then
  195. return -- 参数不对!
  196. end
  197. local leftTime = getFightCoolTime(human)
  198. if leftTime > 0 then
  199. return Broadcast.sendErr(human, Util.format(Lang.THRONE_CHALLENGE_TIME_INIT, math.ceil(leftTime / 60)))
  200. end
  201. if human.db._id == throne.uuid then --不能挑战自己
  202. return Broadcast.sendErr(human, Lang.THRONE_CANT_CHALLENGE_SELF)
  203. end
  204. local jjcRank = JjcDB.getRank(human.db._id)
  205. if jjcRank < cf.minRank or jjcRank > cf.maxRank then
  206. Broadcast.sendErr(human, Lang.JJC_RANK_NOT_ENOUGH) -- reyes todo temp
  207. return false
  208. end
  209. local lv = throne.lv
  210. local exp = throne.exp or 0
  211. lv, exp = getNewLvExp(id, lv, exp, evolveCnt)
  212. return true, cf, throne, lv, exp
  213. end
  214. function fight(human, args)
  215. local heroList = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE1)
  216. if #heroList < 1 then return Broadcast.sendErr(human, Lang.THESTAR_SET_HEROS) end
  217. local isok, cf, throne, lv, exp = checkCombatPos(human, args)
  218. if not isok then return end
  219. local monsterOutID = getMonsterOutID(throne.id, lv)
  220. cbParam = {}
  221. cbParam.newLv = lv
  222. cbParam.exp = exp
  223. cbParam.vestId = throne._id
  224. cbParam.id = throne.id
  225. cbParam.evolveCnt = tonumber(args[2] or 0)
  226. args[#args+1] = throne.uuid
  227. CombatLogic.combatBegin(human, cf.mapID, args, CombatDefine.COMBAT_TYPE5, cbParam)
  228. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE13, 1)
  229. end
  230. -- 获取当前地图ID
  231. function getMapID(human, args)
  232. local isok, cf, throne, lv, exp = checkCombatPos(human, args)
  233. if not isok then return end
  234. return cf.mapID
  235. end
  236. function onFightEnd(human, result, type, cbParam, combatInfo)
  237. local config = ThroneExcel.throne[cbParam.id]
  238. local throne = TheStarsDBLogic.getThroneByVestId(cbParam.vestId)
  239. local evolveCnt = 0
  240. if not throne or not config then return end
  241. combatInfo.time = os.time()
  242. if result == CombatDefine.RESULT_WIN then
  243. local time = os.time()
  244. local param2 = os.date("%Y/%m/%d %H:%M:%S")
  245. local param3 = nil
  246. if cbParam.id == 1 then
  247. param3 = Lang.THE_STAR_KING
  248. elseif cbParam.id == 2 then
  249. param3 = Lang.THE_STAR_MASTER
  250. elseif cbParam.id == 3 then
  251. param3 = Lang.THE_STAR_MASTER
  252. else
  253. param3 = Lang.THE_STAR_BRAVE
  254. end
  255. if throne.uuid ~= nil then -- 干掉王座之前占领者的信息并发邮件
  256. RoleHeadLogic.unActive(throne.uuid, RoleHeadLogic.HEAD_TYPE_4, config.chenghaoID)
  257. local title = MailExcel.mail[MailDefine.MAIL_ID_CHENGHAO].title
  258. local content = Util.format(MailExcel.mail[MailDefine.MAIL_ID_CHENGHAO].content,human.db.name,param2,param3)
  259. local senderName = MailExcel.mail[MailDefine.MAIL_ID_CHENGHAO].senderName
  260. MailManager.add(MailManager.SYSTEM, throne.uuid, title, content, nil, senderName)
  261. end
  262. local body = human.db.body
  263. evolveCnt = cbParam.evolveCnt + (throne.evolve or 0)
  264. TheStarsDBLogic.setThroneRole(cbParam.id, human.db._id, body, cbParam.newLv, cbParam.exp, evolveCnt)
  265. RoleHeadLogic.active(human, RoleHeadLogic.HEAD_TYPE_4, config.chenghaoID)
  266. RoleHeadLogic.setHead(human, config.chenghaoID, RoleHeadLogic.HEAD_TYPE_4)
  267. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE25, param3)
  268. local chconfig = RoleExcel.chenghao[config.chenghaoID]
  269. local key1Value = chconfig.attrs[1][2]
  270. local key2Value = chconfig.attrs[2][2]
  271. combatInfo.endParam = ItemExcel[config.chenghaoID].icon.."|"..key1Value.."|"..key2Value
  272. -- 重新设置敌人名字
  273. -- combatInfo.defender.name = Util.format(Lang.THE_STARS_DEFINCER, cbParam.newLv)
  274. CombatVideo.saveThroneVideo(throne.id, combatInfo,cbParam.evolveCnt)
  275. else
  276. human.db.throneTime = os.time() -- 失败刷新CD
  277. end
  278. end
  279. function recordQuery(human,vestId)
  280. local throne = TheStarsDBLogic.getThroneByVestId(vestId)
  281. if not throne then print(" not have " ) return end
  282. local recordList = CombatVideo.getCombatVideosByType(CombatVideo.VIDEOTYPE_THRONE, throne.id)
  283. local msgRet = Msg.gc.GC_THE_STARS_RECORD_QUERY
  284. msgRet.recordList[0] = 0
  285. for i = 1, #recordList do
  286. if msgRet.recordList[0] < #msgRet.recordList then
  287. msgRet.recordList[0] = msgRet.recordList[0] + 1
  288. local combatVideo = recordList[i]
  289. local combatInfo = combatVideo.combatInfo
  290. local net = msgRet.recordList[msgRet.recordList[0]]
  291. RoleLogic.makeRoleBase(combatInfo.attacker, net.atkData)
  292. net.heroList[0] = 0
  293. for _,pos in ipairs(CombatDefine.SIDE2POS[CombatDefine.ATTACK_SIDE]) do
  294. local grid = combatInfo.objList and combatInfo.objList[pos]
  295. if grid and grid.id ~= 0 then
  296. net.heroList[0] = net.heroList[0] + 1
  297. local index = net.heroList[0]
  298. HeroGrid.makeHeroInfo(net.heroList[index], grid)
  299. end
  300. end
  301. net.videoUuid = combatVideo._id
  302. net.time = combatInfo.time
  303. net.result = combatInfo.isWin == true and 1 or 0
  304. net.evolveCnt = combatVideo.evolveCnt or 0
  305. local formationConfig = CombatPosLogic.getFormationConfig(combatInfo.atkFormation)
  306. net.formation = formationConfig.name
  307. end
  308. end
  309. Msg.send(msgRet,human.fd)
  310. end
  311. --------------------------------------------- combat ----------------------------------------------
  312. function getCombatMonsterOutID(human, side, args)
  313. if side ~= CombatDefine.DEFEND_SIDE then return end
  314. local id = tonumber(args[1] or 0)
  315. local evolveCnt = tonumber(args[2] or 0)
  316. local vestId = args[3]
  317. local cf = ThroneExcel.throne[id]
  318. if not cf then return end
  319. local throne = TheStarsDBLogic.getThroneByVestId(vestId)
  320. if not throne or throne.id ~= id then
  321. return -- 参数不对!
  322. end
  323. if evolveCnt < 1 then return end
  324. local exp = throne.exp or 0
  325. local newLv = getNewLvExp(id, throne.lv, exp, evolveCnt)
  326. return getMonsterOutID(throne.id, newLv)
  327. end
  328. function getCombatObjList(human,side, args)
  329. -- if side ~= CombatDefine.ATTACK_SIDE then return end
  330. local h
  331. if side == CombatDefine.ATTACK_SIDE then
  332. h = human
  333. else
  334. local playerUuuid = args and args[#args]
  335. h = getTargetHuman(playerUuuid)
  336. end
  337. if not h then
  338. return
  339. end
  340. -- return CombatLogic.getHumanObjList(human, CombatDefine.COMBAT_TYPE1)
  341. return CombatLogic.getHumanObjList(h, CombatDefine.COMBAT_TYPE1)
  342. end
  343. local attrInput = {}
  344. function getMonsterLvAttr(monsterIndex, throneID, evolveCnt)
  345. monsterIndex = tonumber(monsterIndex)
  346. throneID = tonumber(throneID)
  347. evolveCnt = tonumber(evolveCnt)
  348. if throneID == nil then
  349. return
  350. end
  351. local list = TheStarsDBLogic.getThroneList()
  352. if list[throneID] == nil then
  353. return
  354. end
  355. local throne = list[throneID]
  356. local lv = throne.lv or 0
  357. local exp = throne.exp or 0
  358. lv = getNewLvExp(throneID, lv, exp, evolveCnt)
  359. Util.cleanTable(attrInput)
  360. local monsterAttrID = nil
  361. local monsterAttrIDNext = nil
  362. local attrLvBegin = nil
  363. local attrLvEnd = nil
  364. local attrInputCnt = 0
  365. -- 为了节省配置表 王者试炼的怪物的属性只配置了1/101/201级的 中间的等级的怪物属性是根据等级 从上下两端动态算出来的
  366. for i = 1, #ThroneExcel.guard do
  367. if lv < ThroneExcel.guard[i].lv then
  368. monsterAttrID = ThroneExcel.guard[i-1].monsterAttrID[throneID]
  369. attrLvBegin = ThroneExcel.guard[i-1].lv
  370. monsterAttrIDNext = ThroneExcel.guard[i].monsterAttrID[throneID]
  371. attrLvEnd = ThroneExcel.guard[i].lv
  372. break
  373. end
  374. end
  375. if monsterAttrID == nil or monsterAttrIDNext == nil then
  376. return
  377. end
  378. local attrConf = MonsterExcel.monsterAttr[monsterAttrID]
  379. local attrConfNext = MonsterExcel.monsterAttr[monsterAttrIDNext]
  380. for i = 1, #attrConf.attrs do
  381. local key = attrConf.attrs[i][1]
  382. local val1 = attrConf.attrs[i][2]
  383. local val2 = nil
  384. for j = 1, #attrConfNext.attrs do
  385. if key == attrConfNext.attrs[j][1] then
  386. val2 = attrConfNext.attrs[j][2]
  387. break
  388. end
  389. end
  390. attrInputCnt = attrInputCnt + 1
  391. local valFinal = val1
  392. if val2 then
  393. valFinal = val1 + math.floor((val2-val1)/(attrLvEnd-attrLvBegin)*(lv-attrLvBegin))
  394. end
  395. attrInput[attrInputCnt] = {key, valFinal}
  396. end
  397. return lv, attrInput
  398. end
  399. function fontActArgs(args, human)
  400. args[0] = 1
  401. local rank,score = JjcLogic.getActRank(human)
  402. args[1] = rank
  403. end