TheStarsLogic.lua 14 KB

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