SkinGiftLogic.lua 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. -- 华丽皮肤礼包:仅直购,配置读取 excel.skin.skinGift
  2. local Msg = require("core.Msg")
  3. local Grid = require("bag.Grid")
  4. local BagLogic = require("bag.BagLogic")
  5. local BuyLogic = require("topup.BuyLogic")
  6. local Lang = require("common.Lang")
  7. local Broadcast = require("broadcast.Broadcast")
  8. local SkinGiftExcel = require("excel.skin").skinGift
  9. local LOGTAG = "skinGift"
  10. local GIFT_CFG_ID = 1
  11. local function getCfg()
  12. return SkinGiftExcel[GIFT_CFG_ID]
  13. end
  14. local function getCfgByBuyId(buyId)
  15. local cfg = getCfg()
  16. if cfg and cfg.buyID == buyId then
  17. return cfg
  18. end
  19. end
  20. local function getBuyCnt(human, buyId)
  21. local skinGiftData = human.db.skinGiftData
  22. return skinGiftData and skinGiftData[buyId] or 0
  23. end
  24. function Query(human)
  25. local cfg = getCfg()
  26. if not cfg then
  27. return
  28. end
  29. local msgRet = Msg.gc.GC_SKIN_GIFT_QUERY
  30. BuyLogic.fontBuyItem(human, msgRet.buyItem, cfg.buyID)
  31. msgRet.giftItem[0] = #cfg.rewards
  32. for i, item in ipairs(cfg.rewards) do
  33. Grid.makeItem(msgRet.giftItem[i], item[1], item[2])
  34. end
  35. Msg.send(msgRet, human.fd)
  36. end
  37. function onCharge(human, buyId, buyNum)
  38. local cfg = getCfgByBuyId(buyId)
  39. if not cfg then
  40. return
  41. end
  42. buyNum = buyNum or 1
  43. local nowBuyCnt = getBuyCnt(human, buyId)
  44. if cfg.amount > 0 and buyNum + nowBuyCnt > cfg.amount then
  45. return Broadcast.sendErr(human, Lang.ABS_GIFT_BUY_LIMIT)
  46. end
  47. local itemArr = {}
  48. for i, item in ipairs(cfg.rewards) do
  49. itemArr[i] = {item[1], item[2] * buyNum}
  50. end
  51. BagLogic.addItemList(human, itemArr, LOGTAG)
  52. local skinGiftData = human.db.skinGiftData or {}
  53. skinGiftData[buyId] = nowBuyCnt + buyNum
  54. human.db.skinGiftData = skinGiftData
  55. Query(human)
  56. end
  57. function GetRemainNum(human, buyId)
  58. local cfg = getCfgByBuyId(buyId)
  59. if not cfg then
  60. return 0
  61. end
  62. if cfg.amount == 0 then
  63. return 0
  64. end
  65. local nowBuyCnt = getBuyCnt(human, buyId)
  66. if cfg.amount > nowBuyCnt then
  67. return cfg.amount - nowBuyCnt
  68. end
  69. return 0
  70. end