WolfSoul.lua 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. -- 狼魂要塞副本
  2. WolfSoul = {}
  3. local this = {}
  4. local WOLF_SOUL_ALL_MAP = "G$狼魂战盟2副本映射"
  5. local WOLF_SOUL_SCORE_KEY = "score_key_"
  6. -- @description 请求进入狼魂要塞
  7. -- @param 玩家对象;副本配置id
  8. -- @return
  9. function WolfSoul.ReqEnterWolfSoul(actor)
  10. --限制条件
  11. --玩家必须加入战盟
  12. local unionId = getbaseinfo(actor, "guildid")
  13. if unionId == 0 then
  14. return
  15. end
  16. --战盟副本必须存在
  17. local union2Dup = getsysvar(WOLF_SOUL_ALL_MAP)
  18. local dupId = union2Dup[unionId]
  19. if dupId == nil then
  20. tipinfo(actor, "当前不在活动时间")
  21. return
  22. end
  23. local dupInfo = getduplicate(dupId)
  24. if dupInfo == nil then
  25. tipinfo(actor, "当前不在活动时间")
  26. return
  27. end
  28. local configId = dupInfo["dupcfgid"]
  29. local state = dupInfo["state"]
  30. if state ~= DuplicateState.PREPARE and state ~= DuplicateState.FIGHT then
  31. tipinfo(actor, "当前不在活动时间")
  32. return
  33. end
  34. --回蓝回血
  35. DuplicateCommon.RecoverHPMP(actor)
  36. --进入副本
  37. local x, y = DuplicateCommon.GetEnterPointXYCommon(configId)
  38. enterduplicate(actor, dupId, x, y)
  39. end
  40. -- @description 请求召唤守护者
  41. -- @param 玩家对象;守护者id
  42. -- @return
  43. function WolfSoul.ReqSummonWarder(actor, monsterId)
  44. -- 获取副本信息
  45. local mapId = getbaseinfo(actor, "unimapid")
  46. local dupInfo = getduplicate(mapId)
  47. if dupInfo == nil then
  48. return
  49. end
  50. if dupInfo["state"] ~= DuplicateState.PREPARE then
  51. return
  52. end
  53. local repId = dupInfo["dupcfgid"]
  54. local needPos = ConfigDataManager.getTableValue("cfg_wolf_soul", "post", "repId", repId)
  55. local needPosList = string.split(needPos, "#")
  56. -- 玩家职位限制
  57. local unionInfo = getunioninfo(actor)
  58. local position = unionInfo["unionposition"]
  59. position = tostring(position)
  60. if not array.contains(needPosList, position) then
  61. return
  62. end
  63. -- 召唤的是第几个守护者,守护者位置
  64. local oldCount = getenvirvar(mapId, DuplicateVarConst.WOLF_SOUL_WARDER_COUNT)
  65. local maxCount = tonumber(ConfigDataManager.getTableValue("cfg_wolf_soul", "guardians", "repId", repId))
  66. if oldCount >= maxCount then
  67. return
  68. end
  69. -- 守护者消耗配置
  70. local itemId, itemCount
  71. local guardiansType = ConfigDataManager.getTableValue("cfg_wolf_soul", "guardiansType", "repId", repId)
  72. local guardiansTypeList = string.split(guardiansType, "|")
  73. for _, value in pairs(guardiansTypeList) do
  74. local valueList = string.split(value, "#")
  75. local monId = tonumber(valueList[1])
  76. if monId == tonumber(monsterId) then
  77. itemId = tonumber(valueList[2])
  78. itemCount = tonumber(valueList[3])
  79. break
  80. end
  81. end
  82. local bagCount = getbagitemcountbyid(actor, itemId)
  83. if tonumber(bagCount) < tonumber(itemCount) then
  84. return
  85. end
  86. -- 扣除道具,刷怪
  87. local guardiansPosition = ConfigDataManager.getTableValue("cfg_wolf_soul", "guardiansPosition", "repId", repId)
  88. local guardiansPositionList = string.split(guardiansPosition, "|")
  89. local nowPos = guardiansPositionList[oldCount + 1]
  90. local nowPosList = string.split(nowPos, "#")
  91. local x = nowPosList[1]
  92. local y = nowPosList[2]
  93. local dir = nowPosList[3]
  94. removeitemfrombag(actor, itemId, itemCount, 0, 9999, '狼魂要塞')
  95. local monsterActor = mongen(mapId, x, y, 0, monsterId, 1)
  96. setmapobjectdir(monsterActor[1], dir)
  97. setenvirvar(mapId, DuplicateVarConst.WOLF_SOUL_WARDER_COUNT, oldCount + 1)
  98. --同步消息
  99. this.SendAllPreparePanel(mapId)
  100. end
  101. -- @description 活动开启创建副本
  102. -- @param
  103. -- @return
  104. function WolfSoul.OpenDuplicate(system)
  105. -- 一个战盟一个副本
  106. -- 根据服务器开服天数,开启进入不同得副本ID
  107. local repId
  108. local severOpenDays = tonumber(getbaseinfo("serveropendays"))
  109. local wolfSoulConfigList = ConfigDataManager.getList("cfg_wolf_soul")
  110. for key, config in pairs(wolfSoulConfigList) do
  111. local dayStr = config["numberday"]
  112. local dayList = string.split(dayStr, "#")
  113. local startDay = tonumber(dayList[1])
  114. local endDay = tonumber(dayList[2])
  115. if startDay <= severOpenDays and severOpenDays <= endDay then
  116. repId = tonumber(config["repid"])
  117. end
  118. end
  119. if repId == nil then
  120. error("WolfSoul.OpenDuplicate() cant find config")
  121. return
  122. end
  123. local unionId2DupMap = {}
  124. local allUninonInfo = getallunionsummary()
  125. for key, unionInfo in pairs(allUninonInfo) do
  126. local unionId = unionInfo["unionid"]
  127. local mapId = DuplicateCommon.CreateDupMapCommon(system, repId, true)
  128. unionId2DupMap[unionId] = mapId
  129. end
  130. setsysvar(WOLF_SOUL_ALL_MAP, unionId2DupMap)
  131. end
  132. -- @description 玩家进入副本后
  133. -- @param 玩家对象;地图唯一id;副本类型;副本阶段(1-准备 2-战斗 3-结算);下一阶段开始时间戳;配置id(cfg_rep的id)
  134. -- @return
  135. function WolfSoul.AfterEnterWolfSoul(actor, mapId, state, nextStateStartTime, configId)
  136. -- 记录参与的玩家
  137. local rid = actor:toString()
  138. local players = getenvirvar(mapId, DuplicateVarConst.WOLF_SOUL_ALL_PLAYERS)
  139. if type(players) ~= "table" then
  140. players = {}
  141. end
  142. if not array.contains(players, rid) then
  143. table.insert(players, rid)
  144. setenvirvar(mapId, WOLF_SOUL_SCORE_KEY .. actor:toString(), 0)
  145. end
  146. setenvirvar(mapId, DuplicateVarConst.WOLF_SOUL_ALL_PLAYERS, players)
  147. -- 发送面板信息
  148. if state == DuplicateState.PREPARE then
  149. this.SendStateInfo(actor, configId, state, nextStateStartTime)
  150. this.SendPreparePanel(actor, mapId, nextStateStartTime)
  151. elseif state == DuplicateState.FIGHT then
  152. this.SendStateInfo(actor, configId, state, nextStateStartTime)
  153. this.SendFightPanel(actor, mapId)
  154. elseif state == DuplicateState.FINISH then
  155. this.SendStateInfo(actor, configId, state, nextStateStartTime)
  156. end
  157. end
  158. -- @description 副本阶段更新
  159. -- @param 系统id;地图唯一id;副本类型;副本阶段(1-准备 2-战斗 3-结算);下一阶段开始时间戳;配置id(cfg_rep的id)
  160. -- @return
  161. function WolfSoul.DupStateUpdate(system, mapId, state, nextStateStartTime, configId)
  162. if state == DuplicateState.PREPARE then
  163. local WolfSoulId = ConfigDataManager.getTableValue("cfg_wolf_soul", "id", "repId", configId)
  164. -- 刷雕像
  165. local platformId = ConfigDataManager.getTableValue("cfg_wolf_soul", "platformID", "id", WolfSoulId)
  166. local platformPos = ConfigDataManager.getTableValue("cfg_wolf_soul", "platformPosition", "id", WolfSoulId)
  167. local platformPosSplit = string.split(platformPos, "#")
  168. local platformX = tonumber(platformPosSplit[1])
  169. local platformY = tonumber(platformPosSplit[2])
  170. local platformDir = tonumber(platformPosSplit[3])
  171. local monsterActor = mongen(mapId, platformX, platformY, 0, platformId, 1)
  172. setmapobjectdir(monsterActor[1], platformDir)
  173. setenvirvar(mapId, DuplicateVarConst.WOLF_SOUL_STATUE, monsterActor[1])
  174. -- 初始化召唤物数量
  175. setenvirvar(mapId, DuplicateVarConst.WOLF_SOUL_WARDER_COUNT, 0)
  176. elseif state == DuplicateState.FIGHT then
  177. -- 挑战阶段副本无人直接关闭副本
  178. local playerCount = getplaycountinmap(mapId)
  179. if playerCount <= 0 then
  180. setduplicatestate(mapId, SetDuplicateStateConst.TO_CLOSED)
  181. return
  182. end
  183. this.SendAllStateInfo(mapId, configId, state, nextStateStartTime)
  184. -- 刷怪
  185. local repMonCfg = ConfigDataManager.getTableValue("cfg_rep", "monster", "id", configId)
  186. this.GenMonster(mapId, repMonCfg)
  187. elseif state == DuplicateState.FINISH then
  188. --结算阶段
  189. this.SendAllStateInfo(mapId, configId, state, nextStateStartTime)
  190. -- 如果雕像存活,则胜利;如果雕像死亡,则失败
  191. local statue = getenvirvar(mapId, DuplicateVarConst.WOLF_SOUL_STATUE)
  192. local monsterInfo = getmonsterinfo(statue)
  193. if monsterInfo == nil then
  194. -- 雕像死亡
  195. this.Settlement(mapId, configId, false)
  196. else
  197. --雕像存活
  198. this.Settlement(mapId, configId, true)
  199. end
  200. end
  201. end
  202. -- @Deprecated 改成心跳检测了
  203. function WolfSoul.MonsterHPChange(performer, currHP, maxHP, performerType)
  204. if performerType ~= MapObjectType.MONSTER then
  205. return
  206. end
  207. local mapId = getbaseinfo(performer, "unimapid")
  208. if mapId == nil then
  209. return
  210. end
  211. local dupInfo = getduplicate(mapId)
  212. if dupInfo == nil then
  213. return
  214. end
  215. local dupType = dupInfo["type"]
  216. if dupType ~= DuplicateType.WOLF_SOUL then
  217. return
  218. end
  219. local repId = dupInfo["dupcfgid"]
  220. local monsterInfo = getmonsterinfo(performer)
  221. local monCfgId = monsterInfo["cfgid"]
  222. local platformID = ConfigDataManager.getTableValue("cfg_wolf_soul", "platformID", "repId", repId)
  223. if tonumber(platformID) ~= tonumber(monCfgId) then
  224. return
  225. end
  226. this.SendAllFightPanel(mapId)
  227. end
  228. -- @description 副本地图怪物死亡移除
  229. -- @param killer有可能是守护者
  230. -- @return
  231. function WolfSoul.MapMonsterRemove(mapId, killer, monCfgId)
  232. local dupInfo = getduplicate(mapId)
  233. local state = dupInfo["state"]
  234. if state == DuplicateState.FIGHT then
  235. local repId = dupInfo["dupcfgid"]
  236. -- 如果是神狼雕像,任务失败
  237. local platformID = ConfigDataManager.getTableValue("cfg_wolf_soul", "platformID", "repId", repId)
  238. if tonumber(monCfgId) == tonumber(platformID) then
  239. -- 任务失败
  240. setduplicatestate(mapId, SetDuplicateStateConst.TO_FINISH)
  241. return
  242. end
  243. -- 给击杀者加积分
  244. --击杀者需要是玩家
  245. local killerType = getbaseinfo(killer, "mapobjecttype")
  246. if tonumber(killerType) == MapObjectType.PLAYER then
  247. local killerId = killer:toString()
  248. local score = getenvirvar(mapId, WOLF_SOUL_SCORE_KEY .. killerId)
  249. if score == nil or score <= 0 then
  250. score = 0
  251. end
  252. local killPoint = ConfigDataManager.getTableValue("cfg_wolf_soul", "killPoint", "repId", repId)
  253. local killPointList = string.split(killPoint, "|")
  254. for _, value in pairs(killPointList) do
  255. local valueList = string.split(value, "#")
  256. local monId = valueList[1]
  257. local addScore = tonumber(valueList[2])
  258. if tonumber(monId) == tonumber(monCfgId) then
  259. score = score + addScore
  260. break
  261. end
  262. end
  263. setenvirvar(mapId, WOLF_SOUL_SCORE_KEY .. killerId, score)
  264. --刷新任务面板
  265. this.SendFightPanel(killer, mapId)
  266. end
  267. -- 没有怪了就刷新下一波怪
  268. -- 雕像和守护者也是怪
  269. local monCount = getmoncount(mapId)
  270. local guardians = getenvirvar(mapId, DuplicateVarConst.WOLF_SOUL_WARDER_COUNT)
  271. monCount = monCount - guardians - 1
  272. if monCount <= 0 then
  273. local genMonData = getenvirvar(mapId, DuplicateVarConst.WOLF_SOUL_GEN_MONSTER)
  274. if genMonData ~= nil then
  275. local repMonCfg = genMonData[1]
  276. local nextId = tonumber(ConfigDataManager.getTableValue("cfg_repMonster", "nextID", "id", repMonCfg))
  277. if nextId ~= nil then
  278. -- 给奖励
  279. this.DefendSuccess(mapId, repMonCfg)
  280. this.GenMonster(mapId, nextId)
  281. else
  282. -- 如果没有下一波怪,则胜利
  283. this.DefendSuccess(mapId, repMonCfg)
  284. -- 任务成功
  285. setduplicatestate(mapId, SetDuplicateStateConst.TO_FINISH)
  286. end
  287. end
  288. end
  289. end
  290. end
  291. -- @description 副本秒钟心跳
  292. -- @param 地图id;副本配置;副本阶段
  293. -- @return
  294. function WolfSoul.SecondHeart(mapId, dupConfig, state)
  295. if state == DuplicateState.PREPARE then
  296. elseif state == DuplicateState.FIGHT then
  297. -- 战斗阶段
  298. -- 血量变化改成心跳
  299. this.SendAllFightPanel(mapId)
  300. -- 经过指定时间刷下一波怪
  301. local nowMillis = getbaseinfo("now")
  302. local genMonData = getenvirvar(mapId, DuplicateVarConst.WOLF_SOUL_GEN_MONSTER)
  303. if genMonData == nil then
  304. return
  305. end
  306. local repMonCfg = genMonData[1]
  307. local nextGenTime = genMonData[2]
  308. if nowMillis >= nextGenTime then
  309. local nextId = tonumber(ConfigDataManager.getTableValue("cfg_repMonster", "nextID", "id", repMonCfg))
  310. if nextId ~= nil then
  311. this.DefendSuccess(mapId, repMonCfg)
  312. this.GenMonster(mapId, nextId)
  313. end
  314. end
  315. end
  316. end
  317. -- @description 被攻击事件
  318. -- @param 地图对象;参数
  319. -- @return
  320. -- function WolfSoul.PerformerBeAttacked(actor, fightParam)
  321. -- local targetType = fightParam["targettype"]
  322. -- if targetType ~= 2 then
  323. -- return
  324. -- end
  325. -- local mapId = fightParam["mapid"]
  326. -- local dupInfo = getduplicate(mapId)
  327. -- if dupInfo == nil then
  328. -- return
  329. -- end
  330. -- local type = dupInfo["type"]
  331. -- if type ~= DuplicateType.WOLF_SOUL then
  332. -- return
  333. -- end
  334. -- local monsterId = fightParam["targetcfgid"]
  335. -- local repId = dupInfo["dupcfgid"]
  336. -- local platformId = ConfigDataManager.getTableValue("cfg_wolf_soul", "platformID", "repId", repId)
  337. -- if tonumber(monsterId) ~= tonumber(platformId) then
  338. -- return
  339. -- end
  340. -- --todo 雕像被攻击了
  341. -- this.SendAllFightPanel(mapId)
  342. -- end
  343. function this.GenMonster(mapId, repMonCfg)
  344. -- 非战斗阶段
  345. local dupInfo = getduplicate(mapId)
  346. if dupInfo["state"] ~= DuplicateState.FIGHT then
  347. return
  348. end
  349. -- 刷怪记录当前刷怪配置和时间
  350. local nowMillis = getbaseinfo("now")
  351. local nextId = tonumber(ConfigDataManager.getTableValue("cfg_repMonster", "nextID", "id", repMonCfg))
  352. local time
  353. if nextId ~= nil then
  354. time = tonumber(ConfigDataManager.getTableValue("cfg_repMonster", "time", "id", repMonCfg)) * 1000
  355. else
  356. time = 24 * 60 * 60 * 1000
  357. end
  358. local nextGenTime = nowMillis + time
  359. local genMonData = { repMonCfg, nextGenTime }
  360. setenvirvar(mapId, DuplicateVarConst.WOLF_SOUL_GEN_MONSTER, genMonData)
  361. local monsterList = DuplicateCommon.DupGenMonsterCommon(mapId, repMonCfg)
  362. local statue = getenvirvar(mapId, DuplicateVarConst.WOLF_SOUL_STATUE)
  363. local monsterInfo = getmonsterinfo(statue)
  364. if monsterInfo == nil then
  365. return
  366. end
  367. --仇恨值
  368. local hate = ConfigDataManager.getTableValue("cfg_repGlobal", "value", "id", RepGlobalConfig.WOLF_SOUL_HATE_TO_PLATFORM)
  369. -- 怪物需要攻击神像
  370. for _, monster in pairs(monsterList) do
  371. addthreat(monster, statue, hate, 1)
  372. end
  373. this.SendAllFightPanel(mapId)
  374. end
  375. function this.SendStateInfo(actor, repId, state, nextStateStartTime)
  376. sendluamsg(actor, LuaMessageIdToClient.RES_WOLF_SOUL_STATE, { repId, state, tostring(nextStateStartTime) })
  377. end
  378. function this.SendAllStateInfo(mapId, repId, state, nextStateStartTime)
  379. local allPlayers = getmapplayer(mapId)
  380. if #allPlayers > 0 then
  381. for _, actor in pairs(allPlayers) do
  382. this.SendStateInfo(actor, repId, state, nextStateStartTime)
  383. end
  384. end
  385. end
  386. -- @description 发送准备阶段面板信息
  387. -- @param
  388. -- @return
  389. function this.SendPreparePanel(actor, mapId, nextStateStartTime)
  390. -- 召唤物数量
  391. local warderCount = getenvirvar(mapId, DuplicateVarConst.WOLF_SOUL_WARDER_COUNT)
  392. -- 发送协议包
  393. sendluamsg(actor, LuaMessageIdToClient.RES_WOLF_SOUL_PREPARE_PANEL, { warderCount })
  394. end
  395. function this.SendAllPreparePanel(mapId)
  396. local dupInfo = getduplicate(mapId)
  397. local players = dupInfo["players"]
  398. for _, actor in pairs(players) do
  399. this.SendPreparePanel(actor, mapId)
  400. end
  401. end
  402. -- @description 发送战斗阶段面板信息
  403. -- @param
  404. -- @return
  405. function this.SendFightPanel(actor, mapId)
  406. -- 雕像生命值万分比
  407. local statue = getenvirvar(mapId, DuplicateVarConst.WOLF_SOUL_STATUE)
  408. local statueMonster = getmonsterinfo(statue)
  409. local hpPercent
  410. if statueMonster == nil then
  411. hpPercent = 0
  412. else
  413. local nowHP = getbaseinfo(statue, "hp")
  414. local maxHP = getbaseinfo(statue, "maxhp")
  415. hpPercent = math.ceil(nowHP / maxHP * 10000)
  416. end
  417. -- 击杀积分
  418. local score = getenvirvar(mapId, WOLF_SOUL_SCORE_KEY .. actor:toString())
  419. -- 个人排名
  420. local rank = this.GetPlayerRank(actor, mapId)
  421. -- 剩余波数
  422. local genMonData = getenvirvar(mapId, DuplicateVarConst.WOLF_SOUL_GEN_MONSTER)
  423. local repMonCfg = genMonData[1]
  424. local leftWaves = this.GetLeftWaves(repMonCfg)
  425. -- 下一波倒计时
  426. local nextGenTime = genMonData[2]
  427. if leftWaves <= 0 then
  428. local dupInfo = getduplicate(mapId)
  429. nextGenTime = dupInfo["nextstatetime"]
  430. end
  431. local resMsg = { hp = hpPercent, score = score, rank = rank, nextGenTime = tostring(nextGenTime), left = leftWaves }
  432. -- 发送消息
  433. sendluamsg(actor, LuaMessageIdToClient.RES_WOLF_SOUL_FIGHT_PANEL, resMsg)
  434. end
  435. function this.SendAllFightPanel(mapId)
  436. local dupInfo = getduplicate(mapId)
  437. local players = dupInfo["players"]
  438. for _, actor in pairs(players) do
  439. this.SendFightPanel(actor, mapId)
  440. end
  441. end
  442. -- @description 波次防守成功
  443. -- @param 地图id;刷怪配置
  444. -- @return
  445. function this.DefendSuccess(mapId, repMonCfg)
  446. local mapPlayers = getmapplayer(mapId)
  447. local reward = ConfigDataManager.getTableValue("cfg_repMonster", "reward", "id", repMonCfg)
  448. if reward == "" then
  449. return
  450. end
  451. local itemMap = string.toIntIntMap(reward, "#", "|")
  452. for _, actor in pairs(mapPlayers) do
  453. additemmaptobag(actor, itemMap, 0, 9999, '狼魂要塞')
  454. GameTips.sendGetRewardMsg(actor, itemMap)
  455. end
  456. end
  457. -- @description 副本结算
  458. -- @param 地图id;副本配置;true-成功,false-失败
  459. -- @return
  460. function this.Settlement(mapId, repId, success)
  461. local allPlayers = getenvirvar(mapId, DuplicateVarConst.WOLF_SOUL_ALL_PLAYERS)
  462. -- 检查 allPlayers 是否为非空表
  463. if not (type(allPlayers) == "table" and #allPlayers > 0) then
  464. return
  465. end
  466. -- 所有参与过的玩家,发积分奖励
  467. local ranks = this.CalcuPlayerRank(mapId)
  468. local resMsg = {}
  469. local rankList = {}
  470. for rid, rank in pairs(ranks) do
  471. local innerData = {}
  472. --rid
  473. innerData["rid"] = tostring(rid)
  474. --排名
  475. innerData["rank"] = rank
  476. --玩家名字
  477. local actor = getactor(rid)
  478. local name = getbaseinfo(actor, "rolename")
  479. innerData["name"] = name
  480. --职业
  481. local career = getbaseinfo(actor, "getbasecareer")
  482. innerData["career"] = career
  483. --等级
  484. local level = getbaseinfo(actor, "level")
  485. innerData["level"] = level
  486. --击杀积分
  487. local score = tonumber(getenvirvar(mapId, WOLF_SOUL_SCORE_KEY .. rid))
  488. if score == nil then
  489. score = 0
  490. end
  491. innerData["score"] = score
  492. table.insert(rankList, innerData)
  493. -- 发邮件
  494. this.SettleMentReward(actor, repId, rank, success)
  495. end
  496. resMsg["list"] = rankList
  497. resMsg["success"] = success
  498. -- 还在副本内的玩家,发结算面板
  499. local mapPlayers = getmapplayer(mapId)
  500. for _, actor in pairs(mapPlayers) do
  501. -- 发送消息
  502. sendluamsg(actor, LuaMessageIdToClient.RES_WOLF_SOUL_SETTLEMENT_PANEL, resMsg)
  503. end
  504. end
  505. -- @description 发送结算奖励
  506. -- @param 玩家对象;副本配置id;排名;true-成功,false-失败
  507. -- @return
  508. function this.SettleMentReward(actor, repId, rank, success)
  509. local rewardConfigStr
  510. if success then
  511. rewardConfigStr = ConfigDataManager.getTableValue("cfg_wolf_soul", "victoryReward", "repId", repId)
  512. else
  513. rewardConfigStr = ConfigDataManager.getTableValue("cfg_wolf_soul", "defeatReward", "repId", repId)
  514. end
  515. local rewardConfigList = string.split(rewardConfigStr, "|")
  516. local itemBing = ConfigDataManager.getTableValue("cfg_bind", "bind", "id", BindConfig.WOLF_SOUL)
  517. for _, rankReward in pairs(rewardConfigList) do
  518. local rankSplit = string.split(rankReward, "#")
  519. local min = tonumber(rankSplit[1])
  520. local max = tonumber(rankSplit[2])
  521. local times = (#rankSplit - 2) / 2
  522. local start = 3
  523. local itemMap = {}
  524. for i = 1, times do
  525. local itemId = tonumber(rankSplit[start])
  526. local itemCount = tonumber(rankSplit[start + 1])
  527. if itemId ~= nil then
  528. itemMap[itemId] = itemCount
  529. end
  530. start = start + 2
  531. end
  532. local itemId = tonumber(rankSplit[3])
  533. local itemCount = tonumber(rankSplit[4])
  534. if min <= rank and rank <= max then
  535. if success then
  536. sendconfigmailbyrid(actor, actor:toString(), MailConfig.WOLF_SOUL_SUCCESS, itemMap, rank, itemBing)
  537. else
  538. sendconfigmailbyrid(actor, actor:toString(), MailConfig.WOLF_SOUL_FAIL, itemMap, rank, itemBing)
  539. end
  540. end
  541. end
  542. end
  543. -- @description 获取剩余波数
  544. -- @param cfg_repMonster表id
  545. -- @return 次数
  546. function this.GetLeftWaves(repMonCfg)
  547. local leftWaves = 0
  548. local flag = true
  549. while flag do
  550. local nextId = ConfigDataManager.getTableValue("cfg_repMonster", "nextID", "id", repMonCfg)
  551. if not tonumber(nextId) then
  552. flag = false
  553. else
  554. repMonCfg = nextId
  555. leftWaves = leftWaves + 1
  556. -- 防止出错无限循环
  557. if leftWaves >= 10000 then
  558. flag = false
  559. end
  560. end
  561. end
  562. return leftWaves
  563. end
  564. -- @description 获取指定玩家的积分排名
  565. -- @param 玩家对象;地图id
  566. -- @return 排名
  567. function this.GetPlayerRank(actor, mapId)
  568. local ranking = this.CalcuPlayerRank(mapId)
  569. return ranking[actor:toString()]
  570. end
  571. -- @description 获取积分排名列表
  572. -- @param 地图id
  573. -- @return 列表<玩家id字符串;排名>
  574. function this.CalcuPlayerRank(mapId)
  575. local players = getenvirvar(mapId, DuplicateVarConst.WOLF_SOUL_ALL_PLAYERS)
  576. local playerList = {}
  577. for index, actor in ipairs(players) do
  578. local score = getenvirvar(mapId, WOLF_SOUL_SCORE_KEY .. actor)
  579. table.insert(playerList, { rid = actor, score = score })
  580. end
  581. -- 按积分从高到低排序,如果积分相同,保持原有顺序
  582. table.sort(
  583. playerList,
  584. function(a, b)
  585. return a.score > b.score
  586. end
  587. )
  588. -- 计算排名
  589. local ranks = {}
  590. local rank = 1 -- 当前排名
  591. for i = 1, #playerList do
  592. local player = playerList[i]
  593. -- 每次循环都增加排名
  594. ranks[player.rid] = rank
  595. rank = rank + 1
  596. end
  597. return ranks
  598. end