OpenServerActPowerUp.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. --------------------------------
  2. -- 文件名 : OpenServerActPowerUp.lua
  3. -- 文件说明 : 开服7天活动 - 战力冲刺
  4. -- 创建时间 : 2024/11/14
  5. -- 创建人 : FC
  6. --------------------------------
  7. local Util = require("common.Util")
  8. local Lang = require("common.Lang")
  9. local Broadcast = require("broadcast.Broadcast")
  10. local OpenAct = require("present.OpenAct")
  11. local PresentExcel = require("excel.present")
  12. local OpenActExcel = require("excel.openAct")
  13. local MailExcel = require("excel.mail")
  14. local Msg = require("core.Msg")
  15. local ObjHuman = require("core.ObjHuman")
  16. local MailManager = require("mail.MailManager")
  17. local BagLogic = require("bag.BagLogic")
  18. local Grid = require("bag.Grid")
  19. local KingWorldLogic = require("present.KingWorldLogic")
  20. local YunYingLogic = require("yunying.YunYingLogic")
  21. local PanelDefine = require("broadcast.PanelDefine")
  22. local SevenDayGiftLogic = require("present.SevenDayGiftLogic")
  23. local CommonDB = require("common.CommonDB")
  24. local BuyLogic = require("topup.BuyLogic")
  25. local GuideLogic = require("guide.GuideLogic")
  26. local Log = require("common.Log")
  27. local tPrizeByID = nil
  28. POWERGIFT_STATE_NONE = 0 -- 不可领取
  29. POWERGIFT_STATE_CANGET = 1 -- 可领取
  30. POWERGIFT_STATE_FINISH = 2 -- 已领取
  31. ----------------------------------------- DB数据操作 -------------------------------------
  32. -- 初始化DB数据
  33. local function ActPowerUp_InitDB(human)
  34. if not human then
  35. return false
  36. end
  37. human.db.PowerGift = {}
  38. return true
  39. end
  40. -- 获取DB数据
  41. local function ActPowerUp_GetDB(human)
  42. if not human or not human.db.PowerGift then
  43. return nil
  44. end
  45. return human.db.PowerGift
  46. end
  47. -- 删除DB数据
  48. local function ActPowerUp_DelDB(human)
  49. if not human or not human.db.PowerGift then
  50. return
  51. end
  52. human.db.PowerGift = nil
  53. end
  54. -- 创建DB数据
  55. local function ActPowerUp_CreateDB(human)
  56. if not human then
  57. return false
  58. end
  59. if not human.db.PowerGift then
  60. local bRet = ActPowerUp_InitDB(human)
  61. if false == bRet then
  62. print("[ActPowerUp_CreateDB] 初始化BD数据失败")
  63. return false
  64. end
  65. if tPrizeByID then
  66. for nID, value in pairs(tPrizeByID) do
  67. human.db.PowerGift[nID] = POWERGIFT_STATE_NONE
  68. end
  69. else
  70. print("[ActPowerUp_CreateDB] 不存在对应的ID对应配置")
  71. return false
  72. end
  73. end
  74. return true
  75. end
  76. -- 获取某个数据状态
  77. local function ActPowerUp_GetDBIDState(human, nID)
  78. if not human or 0 >= nID then
  79. return POWERGIFT_STATE_NONE
  80. end
  81. local tDBPrize = ActPowerUp_GetDB(human)
  82. if nil == tDBPrize then
  83. return POWERGIFT_STATE_NONE
  84. end
  85. return tDBPrize[nID]
  86. end
  87. -- 设置某个数据状态
  88. local function ActPowerUp_SetDBIDState(human, nID, nState)
  89. if not human or 0 >= nID then
  90. return false
  91. end
  92. local tDBPrize = ActPowerUp_GetDB(human)
  93. if nil == tDBPrize then
  94. return false
  95. end
  96. tDBPrize[nID] = nState
  97. return true
  98. end
  99. ----------------------------------------- 内部函数判断 -------------------------------------
  100. -- 获取配置
  101. local function ActPowerUp_GetConfig()
  102. return OpenActExcel.PowerUp
  103. end
  104. -- 日志写入
  105. local function ActPowerUp_WriteLog(szText)
  106. Log.write(Log.LOGID_OSS_OPENSERVER_ACT, szText)
  107. end
  108. -- 报错打印
  109. local function ActPowerUp_PrintInfo(szFuncName,szText)
  110. print(szFuncName.." "..szText)
  111. end
  112. -- 客户端回包
  113. local function ActPowerUp_SendClient(fd, data)
  114. Msg.send(data, fd)
  115. ActPowerUp_PrintInfo("[ActPowerUp_SendClient]", "发送给客户端结束")
  116. end
  117. -- 活动是否开启
  118. local function ActPowerUp_IsOpen(human)
  119. local szFuncName = "ActPowerUp_IsOpen"
  120. local szText = ""
  121. if not human then
  122. szText = "参数不正确 "
  123. ActPowerUp_PrintInfo(szFuncName, szText)
  124. return false
  125. end
  126. local nOpenLv = YunYingLogic.getOpenLvByPanelID(PanelDefine.PANEL_ID_3609)
  127. if human.db.lv < nOpenLv then
  128. return false
  129. end
  130. local flag = OpenAct.getOpenActTime(OpenAct.OPEN_ACT_SERVER_GIFT)
  131. if not flag then
  132. return false
  133. end
  134. return true
  135. end
  136. -- 活动剩余时间
  137. local function ActPowerUp_GetLeftTime()
  138. local openDay = CommonDB.getServerOpenDay()
  139. if openDay == nil then
  140. return 0
  141. end
  142. local OpenActConfig = OpenActExcel.openAct[1]
  143. if not OpenActConfig then return 0 end
  144. local sDay = OpenActConfig.sDay
  145. local eDay = OpenActConfig.eDay
  146. if openDay >= sDay and openDay <= eDay then
  147. local time = os.time()
  148. local openTime = CommonDB.getServerOpenTime()
  149. if openTime == 0 then
  150. return 0
  151. end
  152. local endTime = Util.getDayStartTime(openTime) + eDay * 86400
  153. return endTime - time
  154. end
  155. return 0
  156. end
  157. -- 红点
  158. local function ActPowerUp_CheckRed(human)
  159. local szFuncName = "ActPowerUp_CheckRed"
  160. local szText = ""
  161. if not human then
  162. szText = "参数不正确"
  163. ActPowerUp_PrintInfo(szFuncName, szText)
  164. return false
  165. end
  166. ActPowerUp_CreateDB(human)
  167. local tDBData = ActPowerUp_GetDB(human)
  168. if not tDBData then
  169. szText = "获取玩家DB奖励数据状态表失败"
  170. ActPowerUp_PrintInfo(szFuncName, szText)
  171. return false
  172. end
  173. for k, v in pairs(tDBData) do
  174. if POWERGIFT_STATE_CANGET == v then
  175. return true
  176. end
  177. end
  178. return false
  179. end
  180. ----------------------------------------- 活动模板调用 -------------------------------------
  181. -- 是否开启
  182. function isOpen(human, YYInfo, funcConfig)
  183. print("[ActPowerUp_isOpen] 进入了判断")
  184. return ActPowerUp_IsOpen(human)
  185. end
  186. -- 活动剩余时间
  187. function getLeftTime()
  188. print("[ActPowerUp_getLeftTime] 获取剩余时间")
  189. return ActPowerUp_GetLeftTime()
  190. end
  191. -- 是否存在红点
  192. function isRed(human)
  193. print("[ActPowerUp_isRed] 获取红点")
  194. return ActPowerUp_CheckRed(human)
  195. end
  196. ----------------------------------------- 客户端协议请求 -------------------------------------
  197. -- 请求活动协议
  198. function ActPowerUp_Query(human)
  199. if not human then
  200. return
  201. end
  202. local nCreatRet = ActPowerUp_CreateDB(human)
  203. if false == nCreatRet then
  204. ActPowerUp_PrintInfo("[ActPowerUp_Query]", "初始化DB数据失败")
  205. return
  206. end
  207. local tPrize = ActPowerUp_GetConfig()
  208. if not tPrize then
  209. return
  210. end
  211. local tMsgData = Msg.gc.GC_PRESENT_OPEN_POWERUP_QUERY
  212. tMsgData.nNowPower = human.db.zhandouli
  213. tMsgData.list[0] = 0
  214. for nID, v in pairs(tPrize) do
  215. tMsgData.list[0] = tMsgData.list[0] + 1
  216. local tPrizeData = tMsgData.list[tMsgData.list[0]]
  217. tPrizeData.nID = nID
  218. tPrizeData.nNeedPower = v.nPower
  219. tPrizeData.nState = ActPowerUp_GetDBIDState(human, nID)
  220. local nPrizeLne = #v.tPrize
  221. tPrizeData.item[0] = nPrizeLne
  222. -- ActPowerUp_PrintInfo("[ActPowerUp_Query]", "遍历的奖励信息 nID = "
  223. -- .. nID .." nPower = "..v.nPower .. " nState = ".. tPrizeData.nState.." nPrizeLne = "..nPrizeLne)
  224. for j = 1, nPrizeLne do
  225. local nGoodsID = v.tPrize[j][1]
  226. local nGoodsNum = v.tPrize[j][2]
  227. ActPowerUp_PrintInfo("[ActPowerUp_Query]", "物品信息 nGoodsID = "..nGoodsID .. " nGoodsNum = "..nGoodsNum)
  228. Grid.makeItem(tPrizeData.item[j], nGoodsID, nGoodsNum)
  229. if v.tPrize[j][3] then
  230. tPrizeData.item[j].rare = v.tPrize[j][3]
  231. end
  232. end
  233. end
  234. -- local tPrintTable = Util.printTable(tMsgData)
  235. Msg.send(tMsgData, human.fd)
  236. ActPowerUp_PrintInfo("[ActPowerUp_Query]", "获取到的奖励长度为 nIndex = "..tMsgData.list[0])
  237. end
  238. -- 请求领取奖励
  239. function ActPowerUp_GetPrize(human, nID)
  240. if not human or 0 >= nID then
  241. return
  242. end
  243. if not tPrizeByID or not tPrizeByID[nID] then
  244. return
  245. end
  246. local nNowPower = human.db.zhandouli
  247. local tMsgData = Msg.gc.GC_PRESENT_OPEN_POWERUP_GETPRIZE
  248. tMsgData.nID = nID
  249. local nNowState = ActPowerUp_GetDBIDState(human, nID)
  250. if POWERGIFT_STATE_CANGET ~= nNowState then
  251. ActPowerUp_PrintInfo("ActPowerUp_GetPrize", "请求领取的奖励状态不正确 nID = "..nID)
  252. tMsgData.nState = 0
  253. ActPowerUp_SendClient(human.fd, tMsgData)
  254. return
  255. end
  256. local tGoodsInfo = tPrizeByID[nID].tPrize
  257. -- if nNowPower < tGoodsInfo.nPower then
  258. -- ActPowerUp_PrintInfo("ActPowerUp_GetPrize", "战斗力不足不应该领取 nID = "..nID)
  259. -- return
  260. -- end
  261. tMsgData.nState = 1
  262. -- 设置状态
  263. if false == ActPowerUp_SetDBIDState(human, nID, POWERGIFT_STATE_FINISH) then
  264. ActPowerUp_PrintInfo("ActPowerUp_GetPrize", "设置数据状态失败 nID = "..nID)
  265. tMsgData.nState = 0
  266. ActPowerUp_SendClient(human.fd, tMsgData)
  267. return
  268. end
  269. -- 发奖励
  270. local tItems = {}
  271. for _, v in pairs(tGoodsInfo) do
  272. table.insert(tItems, v)
  273. end
  274. -- for i = 1, #tGoodsInfo do
  275. -- local nGoodsID = tGoodsInfo[i][1]
  276. -- local nGoodsNum = tGoodsInfo[i][2]
  277. -- BagLogic.addItem(human, nGoodsID, nGoodsNum,"open_server_PowerUpPrize")
  278. -- end
  279. BagLogic.addItemList(human, tItems, "open_server_PowerUpPrize")
  280. BagLogic.sendItemGetList(human, tItems, "open_server_PowerUpPrize")
  281. for k, v in pairs(funcID) do
  282. YunYingLogic.updateIcon(YYInfo[k], human)
  283. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3605)
  284. break
  285. end
  286. ActPowerUp_Query(human)
  287. end
  288. ----------------------------------------- 其他模块调用 -------------------------------------
  289. -- 用于起服时映射奖励ID对应配置
  290. function Init()
  291. local tPrize = ActPowerUp_GetConfig()
  292. if not tPrize then
  293. ActPowerUp_PrintInfo("Init", "起服获取不到配置")
  294. return
  295. end
  296. tPrizeByID = {}
  297. -- Util.printTable(tPrize)
  298. for nID, v in pairs(tPrize) do
  299. if tPrizeByID[nID] then
  300. ActPowerUp_PrintInfo("Init", "配置了重复的奖励ID")
  301. return
  302. end
  303. tPrizeByID[nID] = v
  304. end
  305. end
  306. -- 战力改变回调
  307. function ActPowerUp_PowerChange(human, nNewPower)
  308. -- 活动未开启
  309. if false == ActPowerUp_IsOpen(human) then
  310. return
  311. end
  312. if not human or 0 >= nNewPower then
  313. return
  314. end
  315. local tPrizeConfig = ActPowerUp_GetConfig()
  316. if not tPrizeConfig then
  317. return
  318. end
  319. local nSendClient = false
  320. for nID, v in pairs(tPrizeConfig) do
  321. local nState = ActPowerUp_GetDBIDState(human, nID)
  322. if POWERGIFT_STATE_NONE == nState then
  323. if nNewPower >= v.nPower then
  324. ActPowerUp_SetDBIDState(human, nID, POWERGIFT_STATE_CANGET)
  325. nSendClient = true
  326. end
  327. end
  328. end
  329. if true == nSendClient then
  330. ActPowerUp_Query(human)
  331. end
  332. return
  333. end
  334. function ActPowerUp_GMClear(human)
  335. ActPowerUp_DelDB(human)
  336. print("[ActPowerUp_GMClear] 战力冲刺数据清空结束")
  337. end