OpenServerActPowerUp.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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. if not tDBPrize[nID] then
  86. tDBPrize[nID] = POWERGIFT_STATE_NONE
  87. end
  88. return tDBPrize[nID]
  89. end
  90. -- 设置某个数据状态
  91. local function ActPowerUp_SetDBIDState(human, nID, nState)
  92. if not human or 0 >= nID then
  93. return false
  94. end
  95. local tDBPrize = ActPowerUp_GetDB(human)
  96. if nil == tDBPrize then
  97. return false
  98. end
  99. tDBPrize[nID] = nState
  100. return true
  101. end
  102. ----------------------------------------- 内部函数判断 -------------------------------------
  103. -- 获取配置
  104. local function ActPowerUp_GetConfig()
  105. return OpenActExcel.PowerUp
  106. end
  107. -- 日志写入
  108. local function ActPowerUp_WriteLog(szText)
  109. Log.write(Log.LOGID_OSS_OPENSERVER_ACT, szText)
  110. end
  111. -- 报错打印
  112. local function ActPowerUp_PrintInfo(szFuncName,szText)
  113. print(szFuncName.." "..szText)
  114. end
  115. -- 客户端回包
  116. local function ActPowerUp_SendClient(fd, data)
  117. Msg.send(data, fd)
  118. ActPowerUp_PrintInfo("[ActPowerUp_SendClient]", "发送给客户端结束")
  119. end
  120. -- 活动是否开启
  121. local function ActPowerUp_IsOpen(human)
  122. local szFuncName = "ActPowerUp_IsOpen"
  123. local szText = ""
  124. if not human then
  125. szText = "参数不正确 "
  126. ActPowerUp_PrintInfo(szFuncName, szText)
  127. return false
  128. end
  129. local nOpenLv = YunYingLogic.getOpenLvByPanelID(PanelDefine.PANEL_ID_3609)
  130. if human.db.lv < nOpenLv then
  131. return false
  132. end
  133. local flag = OpenAct.getOpenActTime(OpenAct.OPEN_ACT_SERVER_GIFT)
  134. if not flag then
  135. return false
  136. end
  137. return true
  138. end
  139. -- 活动剩余时间
  140. local function ActPowerUp_GetLeftTime()
  141. local openDay = CommonDB.getServerOpenDay()
  142. if openDay == nil then
  143. return 0
  144. end
  145. local OpenActConfig = OpenActExcel.openAct[1]
  146. if not OpenActConfig then return 0 end
  147. local sDay = OpenActConfig.sDay
  148. local eDay = OpenActConfig.eDay
  149. if openDay >= sDay and openDay <= eDay then
  150. local time = os.time()
  151. local openTime = CommonDB.getServerOpenTime()
  152. if openTime == 0 then
  153. return 0
  154. end
  155. local endTime = Util.getDayStartTime(openTime) + eDay * 86400
  156. return endTime - time
  157. end
  158. return 0
  159. end
  160. -- 红点
  161. local function ActPowerUp_CheckRed(human)
  162. local szFuncName = "ActPowerUp_CheckRed"
  163. local szText = ""
  164. if not human then
  165. szText = "参数不正确"
  166. ActPowerUp_PrintInfo(szFuncName, szText)
  167. return false
  168. end
  169. ActPowerUp_CreateDB(human)
  170. local tDBData = ActPowerUp_GetDB(human)
  171. if not tDBData then
  172. szText = "获取玩家DB奖励数据状态表失败"
  173. ActPowerUp_PrintInfo(szFuncName, szText)
  174. return false
  175. end
  176. for k, v in pairs(tDBData) do
  177. if POWERGIFT_STATE_CANGET == v then
  178. return true
  179. end
  180. end
  181. return false
  182. end
  183. ----------------------------------------- 活动模板调用 -------------------------------------
  184. -- 是否开启
  185. function isOpen(human, YYInfo, funcConfig)
  186. print("[ActPowerUp_isOpen] 进入了判断")
  187. return ActPowerUp_IsOpen(human)
  188. end
  189. -- 活动剩余时间
  190. function getLeftTime()
  191. print("[ActPowerUp_getLeftTime] 获取剩余时间")
  192. return ActPowerUp_GetLeftTime()
  193. end
  194. -- 是否存在红点
  195. function isRed(human)
  196. print("[ActPowerUp_isRed] 获取红点")
  197. return ActPowerUp_CheckRed(human)
  198. end
  199. ----------------------------------------- 客户端协议请求 -------------------------------------
  200. -- 请求活动协议
  201. function ActPowerUp_Query(human)
  202. if not human then
  203. return
  204. end
  205. local nCreatRet = ActPowerUp_CreateDB(human)
  206. if false == nCreatRet then
  207. ActPowerUp_PrintInfo("[ActPowerUp_Query]", "初始化DB数据失败")
  208. return
  209. end
  210. local tPrize = ActPowerUp_GetConfig()
  211. if not tPrize then
  212. return
  213. end
  214. local tMsgData = Msg.gc.GC_PRESENT_OPEN_POWERUP_QUERY
  215. tMsgData.nNowPower = human.db.zhandouli
  216. tMsgData.list[0] = 0
  217. for nID, v in pairs(tPrize) do
  218. tMsgData.list[0] = tMsgData.list[0] + 1
  219. local tPrizeData = tMsgData.list[tMsgData.list[0]]
  220. tPrizeData.nID = nID
  221. tPrizeData.nNeedPower = v.nPower
  222. tPrizeData.nState = ActPowerUp_GetDBIDState(human, nID)
  223. local nPrizeLne = #v.tPrize
  224. tPrizeData.item[0] = nPrizeLne
  225. -- ActPowerUp_PrintInfo("[ActPowerUp_Query]", "遍历的奖励信息 nID = "
  226. -- .. nID .." nPower = "..v.nPower .. " nState = ".. tPrizeData.nState.." nPrizeLne = "..nPrizeLne)
  227. for j = 1, nPrizeLne do
  228. local nGoodsID = v.tPrize[j][1]
  229. local nGoodsNum = v.tPrize[j][2]
  230. ActPowerUp_PrintInfo("[ActPowerUp_Query]", "物品信息 nGoodsID = "..nGoodsID .. " nGoodsNum = "..nGoodsNum)
  231. Grid.makeItem(tPrizeData.item[j], nGoodsID, nGoodsNum)
  232. if v.tPrize[j][3] then
  233. tPrizeData.item[j].rare = v.tPrize[j][3]
  234. end
  235. end
  236. end
  237. -- local tPrintTable = Util.printTable(tMsgData)
  238. Msg.send(tMsgData, human.fd)
  239. ActPowerUp_PrintInfo("[ActPowerUp_Query]", "获取到的奖励长度为 nIndex = "..tMsgData.list[0])
  240. end
  241. -- 请求领取奖励
  242. function ActPowerUp_GetPrize(human, nID)
  243. if not human or 0 >= nID then
  244. return
  245. end
  246. if not tPrizeByID or not tPrizeByID[nID] then
  247. return
  248. end
  249. local nNowPower = human.db.zhandouli
  250. local tMsgData = Msg.gc.GC_PRESENT_OPEN_POWERUP_GETPRIZE
  251. tMsgData.nID = nID
  252. local nNowState = ActPowerUp_GetDBIDState(human, nID)
  253. if POWERGIFT_STATE_CANGET ~= nNowState then
  254. ActPowerUp_PrintInfo("ActPowerUp_GetPrize", "请求领取的奖励状态不正确 nID = "..nID)
  255. tMsgData.nState = 0
  256. ActPowerUp_SendClient(human.fd, tMsgData)
  257. return
  258. end
  259. local tGoodsInfo = tPrizeByID[nID].tPrize
  260. -- if nNowPower < tGoodsInfo.nPower then
  261. -- ActPowerUp_PrintInfo("ActPowerUp_GetPrize", "战斗力不足不应该领取 nID = "..nID)
  262. -- return
  263. -- end
  264. tMsgData.nState = 1
  265. -- 设置状态
  266. if false == ActPowerUp_SetDBIDState(human, nID, POWERGIFT_STATE_FINISH) then
  267. ActPowerUp_PrintInfo("ActPowerUp_GetPrize", "设置数据状态失败 nID = "..nID)
  268. tMsgData.nState = 0
  269. ActPowerUp_SendClient(human.fd, tMsgData)
  270. return
  271. end
  272. -- 发奖励
  273. local tItems = {}
  274. for _, v in pairs(tGoodsInfo) do
  275. table.insert(tItems, v)
  276. end
  277. -- for i = 1, #tGoodsInfo do
  278. -- local nGoodsID = tGoodsInfo[i][1]
  279. -- local nGoodsNum = tGoodsInfo[i][2]
  280. -- BagLogic.addItem(human, nGoodsID, nGoodsNum,"open_server_PowerUpPrize")
  281. -- end
  282. BagLogic.addItemList(human, tItems, "open_server_PowerUpPrize")
  283. BagLogic.sendItemGetList(human, tItems, "open_server_PowerUpPrize")
  284. for k, v in pairs(funcID) do
  285. YunYingLogic.updateIcon(YYInfo[k], human)
  286. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3605)
  287. break
  288. end
  289. ActPowerUp_Query(human)
  290. end
  291. ----------------------------------------- 其他模块调用 -------------------------------------
  292. -- 用于起服时映射奖励ID对应配置
  293. function Init()
  294. local tPrize = ActPowerUp_GetConfig()
  295. if not tPrize then
  296. ActPowerUp_PrintInfo("Init", "起服获取不到配置")
  297. return
  298. end
  299. tPrizeByID = {}
  300. -- Util.printTable(tPrize)
  301. for nID, v in pairs(tPrize) do
  302. if tPrizeByID[nID] then
  303. ActPowerUp_PrintInfo("Init", "配置了重复的奖励ID")
  304. return
  305. end
  306. tPrizeByID[nID] = v
  307. end
  308. end
  309. -- 战力改变回调
  310. function ActPowerUp_PowerChange(human, nNewPower)
  311. -- 活动未开启
  312. if false == ActPowerUp_IsOpen(human) then
  313. return
  314. end
  315. if not human or 0 >= nNewPower then
  316. return
  317. end
  318. local tPrizeConfig = ActPowerUp_GetConfig()
  319. if not tPrizeConfig then
  320. return
  321. end
  322. local nSendClient = false
  323. for nID, v in pairs(tPrizeConfig) do
  324. local nState = ActPowerUp_GetDBIDState(human, nID)
  325. if POWERGIFT_STATE_NONE == nState then
  326. if nNewPower >= v.nPower then
  327. ActPowerUp_SetDBIDState(human, nID, POWERGIFT_STATE_CANGET)
  328. nSendClient = true
  329. end
  330. end
  331. end
  332. if true == nSendClient then
  333. ActPowerUp_Query(human)
  334. end
  335. return
  336. end
  337. function ActPowerUp_GMClear(human)
  338. ActPowerUp_DelDB(human)
  339. print("[ActPowerUp_GMClear] 战力冲刺数据清空结束")
  340. end