TheStarsLogic.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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 i, heroUuid in ipairs(heroList or {}) do
  140. if i >= CombatDefine.COMBAT_HERO_CNT then -- 不显示援军
  141. break
  142. end
  143. local heroGrid = HeroLogic.getHeroGridByUuid(targetHuman, heroUuid)
  144. if heroGrid then
  145. len = len + 1
  146. msgRet.monsterList[0] = len
  147. local heroCfg = HeroExcel.hero[heroGrid.id]
  148. msgRet.monsterList[len].body = heroGrid.body or heroCfg.body
  149. msgRet.monsterList[len].lv = heroGrid.lv or 0
  150. msgRet.monsterList[len].camp = heroCfg.camp
  151. end
  152. end
  153. end
  154. else
  155. local monsterOutID = getMonsterOutID(throne.id, throne.lv)
  156. local monsterOutConfig = MonsterExcel.monsterOut[monsterOutID]
  157. local count = #monsterOutConfig.member
  158. for i = 1,count do
  159. local monsterID = monsterOutConfig.member[i][1]
  160. local lv = monsterOutConfig.member[i][2]
  161. local mcf = MonsterExcel.monster[monsterID]
  162. msgRet.monsterList[i].body = mcf.body
  163. msgRet.monsterList[i].lv = throne.lv
  164. msgRet.monsterList[i].camp = mcf.camp
  165. end
  166. msgRet.monsterList[0] = count
  167. end
  168. Msg.send(msgRet, human.fd)
  169. end
  170. local function getFightCoolTime(human)
  171. if not human.db.throneTime then
  172. return 0
  173. end
  174. local sec = os.time() - human.db.throneTime
  175. return math.max(FAIL_COMBAT_CD - sec, 0)
  176. end
  177. local function getNewLvExp(id, lv, exp, evolveCnt)
  178. local starsCf = ThroneExcel.theStars[lv]
  179. exp = evolveCnt * starsCf.evolveExp + exp
  180. while exp >= starsCf.exp do
  181. lv = lv + 1
  182. exp = exp - starsCf.exp
  183. end
  184. local cf = ThroneExcel.throne[id]
  185. lv = math.min(cf.maxLv, lv)
  186. return lv, exp
  187. end
  188. function checkCombatPos(human, args)
  189. if not isOpen(human,true) then return end
  190. local id = tonumber(args[1] or 0)
  191. local evolveCnt = tonumber(args[2] or 0)
  192. local vestId = args[3]
  193. -- if evolveCnt < 1 then return end -- 升级次数小于1,怀疑有人作弊
  194. local cf = ThroneExcel.throne[id]
  195. if not cf then return end
  196. local throne = TheStarsDBLogic.getThroneByVestId(vestId)
  197. if not throne or throne.id ~= id then
  198. return -- 参数不对!
  199. end
  200. local leftTime = getFightCoolTime(human)
  201. if leftTime > 0 then
  202. return Broadcast.sendErr(human, Util.format(Lang.THRONE_CHALLENGE_TIME_INIT, math.ceil(leftTime / 60)))
  203. end
  204. if human.db._id == throne.uuid then --不能挑战自己
  205. return Broadcast.sendErr(human, Lang.THRONE_CANT_CHALLENGE_SELF)
  206. end
  207. local jjcRank = JjcDB.getRank(human.db._id)
  208. if jjcRank < cf.minRank or jjcRank > cf.maxRank then
  209. Broadcast.sendErr(human, Lang.JJC_RANK_NOT_ENOUGH) -- reyes todo temp
  210. return false
  211. end
  212. local lv = throne.lv
  213. local exp = throne.exp or 0
  214. lv, exp = getNewLvExp(id, lv, exp, evolveCnt)
  215. return true, cf, throne, lv, exp
  216. end
  217. function fight(human, args)
  218. local heroList = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE1)
  219. if #heroList < 1 then return Broadcast.sendErr(human, Lang.THESTAR_SET_HEROS) end
  220. local isok, cf, throne, lv, exp = checkCombatPos(human, args)
  221. if not isok then return end
  222. local monsterOutID = getMonsterOutID(throne.id, lv)
  223. cbParam = {}
  224. cbParam.newLv = lv
  225. cbParam.exp = exp
  226. cbParam.vestId = throne._id
  227. cbParam.id = throne.id
  228. cbParam.evolveCnt = tonumber(args[2] or 0)
  229. args[#args+1] = throne.uuid
  230. CombatLogic.combatBegin(human, cf.mapID, args, CombatDefine.COMBAT_TYPE5, cbParam)
  231. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE13, 1)
  232. end
  233. -- 获取当前地图ID
  234. function getMapID(human, args)
  235. local isok, cf, throne, lv, exp = checkCombatPos(human, args)
  236. if not isok then return end
  237. return cf.mapID
  238. end
  239. function onFightEnd(human, result, type, cbParam, combatInfo)
  240. local config = ThroneExcel.throne[cbParam.id]
  241. local throne = TheStarsDBLogic.getThroneByVestId(cbParam.vestId)
  242. local evolveCnt = 0
  243. if not throne or not config then return end
  244. combatInfo.time = os.time()
  245. if result == CombatDefine.RESULT_WIN then
  246. local time = os.time()
  247. local param2 = os.date("%Y/%m/%d %H:%M:%S")
  248. local param3 = nil
  249. if cbParam.id == 1 then
  250. param3 = Lang.THE_STAR_KING
  251. elseif cbParam.id == 2 then
  252. param3 = Lang.THE_STAR_MASTER
  253. elseif cbParam.id == 3 then
  254. param3 = Lang.THE_STAR_MASTER
  255. else
  256. param3 = Lang.THE_STAR_BRAVE
  257. end
  258. if throne.uuid ~= nil then -- 干掉王座之前占领者的信息并发邮件
  259. RoleHeadLogic.unActive(throne.uuid, RoleHeadLogic.HEAD_TYPE_4, config.chenghaoID)
  260. local title = MailExcel.mail[MailDefine.MAIL_ID_CHENGHAO].title
  261. local content = Util.format(MailExcel.mail[MailDefine.MAIL_ID_CHENGHAO].content,human.db.name,param2,param3)
  262. local senderName = MailExcel.mail[MailDefine.MAIL_ID_CHENGHAO].senderName
  263. MailManager.add(MailManager.SYSTEM, throne.uuid, title, content, nil, senderName)
  264. end
  265. local body = human.db.body
  266. evolveCnt = cbParam.evolveCnt + (throne.evolve or 0)
  267. TheStarsDBLogic.setThroneRole(cbParam.id, human.db._id, body, cbParam.newLv, cbParam.exp, evolveCnt)
  268. RoleHeadLogic.active(human, RoleHeadLogic.HEAD_TYPE_4, config.chenghaoID)
  269. RoleHeadLogic.setHead(human, config.chenghaoID, RoleHeadLogic.HEAD_TYPE_4)
  270. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE25, param3)
  271. local chconfig = RoleExcel.chenghao[config.chenghaoID]
  272. local key1Value = chconfig.attrs[1][2]
  273. local key2Value = chconfig.attrs[2][2]
  274. combatInfo.endParam = ItemExcel[config.chenghaoID].icon.."|"..key1Value.."|"..key2Value
  275. -- 重新设置敌人名字
  276. -- combatInfo.defender.name = Util.format(Lang.THE_STARS_DEFINCER, cbParam.newLv)
  277. CombatVideo.saveThroneVideo(throne.id, combatInfo,cbParam.evolveCnt)
  278. else
  279. human.db.throneTime = os.time() -- 失败刷新CD
  280. end
  281. end
  282. function recordQuery(human,vestId)
  283. local throne = TheStarsDBLogic.getThroneByVestId(vestId)
  284. if not throne then print(" not have " ) return end
  285. local recordList = CombatVideo.getCombatVideosByType(CombatVideo.VIDEOTYPE_THRONE, throne.id)
  286. local msgRet = Msg.gc.GC_THE_STARS_RECORD_QUERY
  287. msgRet.recordList[0] = 0
  288. for i = 1, #recordList do
  289. if msgRet.recordList[0] < #msgRet.recordList then
  290. msgRet.recordList[0] = msgRet.recordList[0] + 1
  291. local combatVideo = recordList[i]
  292. local combatInfo = combatVideo.combatInfo
  293. local net = msgRet.recordList[msgRet.recordList[0]]
  294. RoleLogic.makeRoleBase(combatInfo.attacker, net.atkData)
  295. net.heroList[0] = 0
  296. for _,pos in ipairs(CombatDefine.SIDE2POS[CombatDefine.ATTACK_SIDE]) do
  297. local grid = combatInfo.objList and combatInfo.objList[pos]
  298. if grid and grid.id ~= 0 then
  299. net.heroList[0] = net.heroList[0] + 1
  300. local index = net.heroList[0]
  301. HeroGrid.makeHeroInfo(net.heroList[index], grid)
  302. end
  303. end
  304. net.videoUuid = combatVideo._id
  305. net.time = combatInfo.time
  306. net.result = combatInfo.isWin == true and 1 or 0
  307. net.evolveCnt = combatVideo.evolveCnt or 0
  308. local formationConfig = CombatPosLogic.getFormationConfig(combatInfo.atkFormation)
  309. net.formation = formationConfig.name
  310. end
  311. end
  312. Msg.send(msgRet,human.fd)
  313. end
  314. --------------------------------------------- combat ----------------------------------------------
  315. function getCombatMonsterOutID(human, side, args)
  316. if side ~= CombatDefine.DEFEND_SIDE then return end
  317. local id = tonumber(args[1] or 0)
  318. local evolveCnt = tonumber(args[2] or 0)
  319. local vestId = args[3]
  320. local cf = ThroneExcel.throne[id]
  321. if not cf then return end
  322. local throne = TheStarsDBLogic.getThroneByVestId(vestId)
  323. if not throne or throne.id ~= id then
  324. return -- 参数不对!
  325. end
  326. if evolveCnt < 1 then return end
  327. local exp = throne.exp or 0
  328. local newLv = getNewLvExp(id, throne.lv, exp, evolveCnt)
  329. return getMonsterOutID(throne.id, newLv)
  330. end
  331. function getCombatObjList(human,side, args)
  332. -- if side ~= CombatDefine.ATTACK_SIDE then return end
  333. local h
  334. if side == CombatDefine.ATTACK_SIDE then
  335. h = human
  336. else
  337. local playerUuuid = args and args[#args]
  338. h = getTargetHuman(playerUuuid)
  339. end
  340. if not h then
  341. return
  342. end
  343. -- return CombatLogic.getHumanObjList(human, CombatDefine.COMBAT_TYPE1)
  344. return CombatLogic.getHumanObjList(h, CombatDefine.COMBAT_TYPE1)
  345. end
  346. local attrInput = {}
  347. function getMonsterLvAttr(monsterIndex, throneID, evolveCnt)
  348. monsterIndex = tonumber(monsterIndex)
  349. throneID = tonumber(throneID)
  350. evolveCnt = tonumber(evolveCnt)
  351. if throneID == nil then
  352. return
  353. end
  354. local list = TheStarsDBLogic.getThroneList()
  355. if list[throneID] == nil then
  356. return
  357. end
  358. local throne = list[throneID]
  359. local lv = throne.lv or 0
  360. local exp = throne.exp or 0
  361. lv = getNewLvExp(throneID, lv, exp, evolveCnt)
  362. Util.cleanTable(attrInput)
  363. local monsterAttrID = nil
  364. local monsterAttrIDNext = nil
  365. local attrLvBegin = nil
  366. local attrLvEnd = nil
  367. local attrInputCnt = 0
  368. -- 为了节省配置表 王者试炼的怪物的属性只配置了1/101/201级的 中间的等级的怪物属性是根据等级 从上下两端动态算出来的
  369. for i = 1, #ThroneExcel.guard do
  370. if lv < ThroneExcel.guard[i].lv then
  371. monsterAttrID = ThroneExcel.guard[i-1].monsterAttrID[throneID]
  372. attrLvBegin = ThroneExcel.guard[i-1].lv
  373. monsterAttrIDNext = ThroneExcel.guard[i].monsterAttrID[throneID]
  374. attrLvEnd = ThroneExcel.guard[i].lv
  375. break
  376. end
  377. end
  378. if monsterAttrID == nil or monsterAttrIDNext == nil then
  379. return
  380. end
  381. local attrConf = MonsterExcel.monsterAttr[monsterAttrID]
  382. local attrConfNext = MonsterExcel.monsterAttr[monsterAttrIDNext]
  383. for i = 1, #attrConf.attrs do
  384. local key = attrConf.attrs[i][1]
  385. local val1 = attrConf.attrs[i][2]
  386. local val2 = nil
  387. for j = 1, #attrConfNext.attrs do
  388. if key == attrConfNext.attrs[j][1] then
  389. val2 = attrConfNext.attrs[j][2]
  390. break
  391. end
  392. end
  393. attrInputCnt = attrInputCnt + 1
  394. local valFinal = val1
  395. if val2 then
  396. valFinal = val1 + math.floor((val2-val1)/(attrLvEnd-attrLvBegin)*(lv-attrLvBegin))
  397. end
  398. attrInput[attrInputCnt] = {key, valFinal}
  399. end
  400. return lv, attrInput
  401. end
  402. function fontActArgs(args, human)
  403. args[0] = 1
  404. local rank,score = JjcLogic.getActRank(human)
  405. args[1] = rank
  406. end