BaiZhanChengShenDefine.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. -- 百战成神 常量定义
  2. --
  3. -- 玩法概要:
  4. -- 跨服 5v5 积分 PvP, 5 种族独立阵容(COMBAT_TYPE39~43), 5 局 3 胜制。
  5. -- 开服>=45 天可参与; 周六 0:10 ~ 周日 23:00 可挑战; 每 21 天(3 周) 开新轮。
  6. -- 一次点击挑战仅扣 1 次(每日 5 次免费, 不足扣道具 115 x5)。
  7. -- 攻胜+20/攻负-10, 守胜+10/守负-20; 初始积分 3000。
  8. --
  9. -- 架构: 普通服 NS + 跨服 CS + Mongo DB(db_bzcs)
  10. -- 首次挑战完成 REGISTER; 阵容变更 UPDATE_SHOW; 积分/匹配/排行在跨服
  11. --------------------------------------------------------------------------------
  12. -- 活动时间 (Util.getWeekDay: 1=周日, 2=周一, 3=周二 ... 7=周六)
  13. --------------------------------------------------------------------------------
  14. BZCS_OPEN_WDAY_AREA = {7, 1} -- 可挑战星期: 周六~周日 (getWeekDay: 7=周六, 1=周日)
  15. BZCS_START_SEC = 600 -- 每日开始时刻: 0:10 (距 0 点秒数)
  16. BZCS_END_SEC = 82800 -- 每日结束时刻: 23:00
  17. BZCS_CYCLE_DAYS = 21 -- 两轮活动最小间隔(天), 即 3 周
  18. BZCS_OPEN_DAYS = 2 -- 单轮活动持续天数(周六+周日, 用于 IsRunning 校验)
  19. -- 开放结束日相对开始日的天数偏移(周六->周日为 1)
  20. function GetOpenEndDayOffset()
  21. local s = BZCS_OPEN_WDAY_AREA[1]
  22. local e = BZCS_OPEN_WDAY_AREA[2]
  23. if s <= e then
  24. return e - s
  25. end
  26. return e + 7 - s
  27. end
  28. --------------------------------------------------------------------------------
  29. -- 积分规则
  30. --------------------------------------------------------------------------------
  31. BZCS_INIT_SCORE = 3000 -- 每轮初始/重置积分
  32. BZCS_ATK_WIN_SCORE = 20 -- 进攻方整场获胜加分
  33. BZCS_ATK_LOSE_SCORE = -10 -- 进攻方整场失败扣分
  34. BZCS_DEF_WIN_SCORE = 10 -- 防守方整场获胜加分(对手进攻失败)
  35. BZCS_DEF_LOSE_SCORE = -20 -- 防守方整场失败扣分(对手进攻成功)
  36. --------------------------------------------------------------------------------
  37. -- 种族与战斗类型 (teamType 41~45, 见 excel/ssecy/combat.lua)
  38. -- race 1~5 与 camp 一致: 妖/人/兽/仙/魔
  39. --------------------------------------------------------------------------------
  40. BZCS_RACE_ORDER = {1, 2, 3, 4, 5}
  41. BZCS_RACE_COMBAT_TYPE = {39, 40, 41, 42, 43}
  42. BZCS_RACE_NAME = {"妖", "人", "兽", "仙", "魔"}
  43. BZCS_RACE_CNT = 5
  44. BZCS_WIN_TARGET = 3 -- 5 局 3 胜: 先赢 3 族或打满 5 族
  45. --------------------------------------------------------------------------------
  46. -- 挑战次数与门票
  47. --------------------------------------------------------------------------------
  48. BZCS_FREE_TIMES = 5 -- 每日免费挑战次数(0 点重置)
  49. BZCS_TICKET_ITEM_ID = 115 -- 挑战券道具 id
  50. BZCS_TICKET_COST = 5 -- 无免费时每次消耗数量
  51. --------------------------------------------------------------------------------
  52. -- 匹配与排行
  53. --------------------------------------------------------------------------------
  54. BZCS_OPPONENT_CNT = 3 -- 单次匹配对手数量
  55. BZCS_MATCH_CACHE_TTL = 30 -- 匹配列表内存缓存有效期(秒); 过期按 rank 轻量刷新展示
  56. BZCS_MATCH_STEP = 100 -- 积分匹配步进(每步 ±100 分扩大)
  57. BZCS_MATCH_MAX_STEP = 50 -- 最大扩大步数(最多 ±5000 分范围)
  58. BZCS_RANK_MAX = 100 -- 客户端展示排行榜条数(全服积分榜含机器人, 规模更大)
  59. -- 全服排行: 积分高者优先; 同分则 scoreTime 小者优先(先达到该积分)
  60. BZCS_REWARD_RANK_MAX = 9999 -- 周期发奖最大排名(超出不发)
  61. --------------------------------------------------------------------------------
  62. -- 准入与其它
  63. --------------------------------------------------------------------------------
  64. BZCS_OPEN_SVR_DAY = 45 -- 开服天数>=此值本服才可参与
  65. BZCS_WARREPORT_MAX = 20 -- 玩家本地战报条数(新记录在前, 超出删最老)
  66. -- 战报类型 warType(客户端展示用)
  67. BZCS_WAR_TYPE_ATK_WIN = 1 -- 主动挑战获胜
  68. BZCS_WAR_TYPE_ATK_LOSE = 2 -- 主动挑战失败
  69. BZCS_WAR_TYPE_DEF_WIN = 3 -- 被挑战, 己方获胜
  70. BZCS_WAR_TYPE_DEF_LOSE = 4 -- 被挑战, 己方失败
  71. BZCS_AWARD_MAIL_ID = 7038 -- 周期结算邮件 id(需在 excel/mail 配置)
  72. -- 机器人池数量 = 策划 robotList 条数(见 GetRobotListCount)
  73. BZCS_SVR_BASE_NUM = 810537 -- 协议 serverId 基准, 第几服 = serverId - 本值
  74. BZCS_ROBOT_DISPLAY_SERVER_ID = BZCS_SVR_BASE_NUM + 1 -- 机器人展示用区服值(810538=1服)
  75. -- 下发客户端的 serverId(机器人不写库, 临时映射为 BZCS_ROBOT_DISPLAY_SERVER_ID)
  76. function GetClientServerId(pinfo)
  77. if not pinfo then
  78. return 0
  79. end
  80. if pinfo.isRobot == 1 then
  81. return BZCS_ROBOT_DISPLAY_SERVER_ID
  82. end
  83. return pinfo.serverId or 0
  84. end
  85. --------------------------------------------------------------------------------
  86. -- 跨服 WL_BZCS_TIPS 错误码 (普通服收到后提示)
  87. --------------------------------------------------------------------------------
  88. BZCS_ERR_NOT_OPEN = 1 -- 活动未开启
  89. BZCS_ERR_NOT_ELIGIBLE = 2 -- 不满足参与条件
  90. BZCS_ERR_NO_TIMES = 3 -- 挑战次数不足
  91. BZCS_ERR_TARGET_INVALID = 4 -- 对手不存在
  92. BZCS_ERR_DATA = 5 -- 数据异常
  93. BZCS_ERR_IN_BATTLE = 6 -- 战斗中(重复挑战)
  94. --------------------------------------------------------------------------------
  95. -- LW_BZCS_UPDATE_SHOW 增量类型(showInfo 仅带变更字段, 跨服 MergeShowInfo 合并)
  96. --------------------------------------------------------------------------------
  97. BZCS_UPDATE_SHOW_NAME = 1 -- name
  98. BZCS_UPDATE_SHOW_HEAD = 3 -- head
  99. BZCS_UPDATE_SHOW_HEAD_FRAME = 4 -- headFrame
  100. BZCS_UPDATE_SHOW_LINEUP = 5 -- heroArr[race], 须配合 race 参数
  101. BZCS_UPDATE_SHOW_BODY = 6 -- body(形象, HEAD_TYPE_3)
  102. -- 将增量 showInfo 合并进跨服已有展示数据
  103. function MergeShowInfo(si, patch)
  104. if not si or not patch then return end
  105. if patch.name ~= nil then
  106. si.name = patch.name
  107. end
  108. if patch.head ~= nil then
  109. si.head = patch.head
  110. end
  111. if patch.headFrame ~= nil then
  112. si.headFrame = patch.headFrame
  113. end
  114. if patch.body ~= nil then
  115. si.body = patch.body
  116. end
  117. if patch.heroArr then
  118. si.heroArr = si.heroArr or {}
  119. for race, raceShow in pairs(patch.heroArr) do
  120. si.heroArr[race] = raceShow
  121. end
  122. end
  123. end
  124. --------------------------------------------------------------------------------
  125. -- robotList 配置(策划表 excel/ssecy/baiZhanChengShen.lua)
  126. -- score: 机器人积分
  127. -- monsterOutIDs[1..5]: 妖/人/兽/仙/魔 五族 monsterOutID, 每 ID 一支队伍(见 CombatLogic.getMonsterObjList)
  128. --------------------------------------------------------------------------------
  129. local BzcsConfig = require("excel.baiZhanChengShen")
  130. local CombatLogic = require("combat.CombatLogic")
  131. local robotListCount
  132. function GetRobotListCount()
  133. if robotListCount then
  134. return robotListCount
  135. end
  136. local max = 0
  137. for k in pairs(BzcsConfig.robotList or {}) do
  138. if type(k) == "number" and k > max then
  139. max = k
  140. end
  141. end
  142. robotListCount = max
  143. return max
  144. end
  145. -- bzcs_robot_N 与 robotList[N] 一一对应
  146. function GetRobotListIndex(uuid)
  147. if not uuid then return end
  148. local n = string.match(uuid, "^bzcs_robot_(%d+)$")
  149. if not n then return end
  150. local idx = tonumber(n)
  151. if not idx or idx < 1 or idx > GetRobotListCount() then return end
  152. return idx
  153. end
  154. function GetRobotListCfg(uuid)
  155. local idx = GetRobotListIndex(uuid)
  156. if not idx then return end
  157. return BzcsConfig.robotList[idx], idx
  158. end
  159. -- 由 monsterOutID 计算单族队伍战力(与战斗 getMonsterObjList 一致)
  160. function CalcMonsterOutPower(monsterOutID)
  161. if not monsterOutID then return 0 end
  162. local _, _, rolebase = CombatLogic.getMonsterObjList(monsterOutID)
  163. return rolebase and rolebase.zhandouli or 0
  164. end
  165. --------------------------------------------------------------------------------
  166. -- 战力与机器人阵容展开(机器人仅存 monsterOutID+racePower, 展示字段用时生成)
  167. --------------------------------------------------------------------------------
  168. local MonsterExcel
  169. local function getMonsterExcel()
  170. MonsterExcel = MonsterExcel or require("excel.monster")
  171. return MonsterExcel
  172. end
  173. -- 机器人单族仅存 monsterOutID+racePower, 有 monsterOutID 则需展开
  174. local function needExpandRaceShow(raceShow)
  175. return raceShow and raceShow.monsterOutID ~= nil
  176. end
  177. -- 由 monsterOut 展开英雄展示; racePower 均分到各英雄 heroPower(不修改入参)
  178. function ExpandBzcsRaceShow(raceShow)
  179. if not raceShow or not needExpandRaceShow(raceShow) then
  180. return raceShow
  181. end
  182. local excel = getMonsterExcel()
  183. local mout = excel.monsterOut[raceShow.monsterOutID]
  184. local racePower = raceShow.racePower or 0
  185. local heroArr = {}
  186. local cnt = 0
  187. if mout and mout.member then
  188. for idx, member in ipairs(mout.member) do
  189. if idx > 6 then break end
  190. cnt = cnt + 1
  191. end
  192. end
  193. local per = cnt > 0 and math.floor(racePower / cnt) or racePower
  194. local len = 0
  195. if mout and mout.member then
  196. for idx, member in ipairs(mout.member) do
  197. if idx > 6 then break end
  198. local mid = member[1]
  199. local mcf = excel.monster[mid]
  200. if mcf then
  201. len = len + 1
  202. heroArr[len] = {
  203. heroBody = mcf.body,
  204. heroStar = mcf.star or 0,
  205. heroLevel = member[2],
  206. heroCamp = mcf.camp or 0,
  207. heroIcon = mcf.head or 0,
  208. heroId = mid,
  209. heroQuality = mcf.heroQuality or 1,
  210. heroPower = per,
  211. }
  212. end
  213. end
  214. end
  215. if len == 0 then
  216. heroArr[1] = {
  217. heroPower = racePower,
  218. heroId = 0,
  219. heroBody = 0,
  220. heroStar = 0,
  221. heroLevel = 0,
  222. heroCamp = 0,
  223. heroIcon = 0,
  224. heroQuality = 1,
  225. }
  226. end
  227. return {
  228. heroArr = heroArr,
  229. formation = raceShow.formation or 1,
  230. helpSkillId = raceShow.helpSkillId or 0,
  231. elfList = raceShow.elfList,
  232. elfSkillIds = raceShow.elfSkillIds,
  233. monsterOutID = raceShow.monsterOutID,
  234. racePower = racePower,
  235. }
  236. end
  237. -- 单族队伍战力: 机器人用 racePower; 真人用 heroArr 内 heroPower 之和
  238. function CalcRaceTeamPower(raceShow)
  239. if not raceShow then return 0 end
  240. if raceShow.racePower then
  241. return raceShow.racePower
  242. end
  243. local sum = 0
  244. for _, h in ipairs(raceShow.heroArr or {}) do
  245. sum = sum + (h.heroPower or 0)
  246. end
  247. return sum
  248. end
  249. -- 玩家总战力 = 五族队伍战力之和
  250. function CalcPlayerPower(showInfo)
  251. if not showInfo then return 0 end
  252. local total = 0
  253. for _, race in ipairs(BZCS_RACE_ORDER) do
  254. total = total + CalcRaceTeamPower(showInfo.heroArr and showInfo.heroArr[race])
  255. end
  256. return total
  257. end