module_fun.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. -- 模块通用函数
  2. -- 需要加载其他模块的放这里
  3. local common_fun = require "model.common_fun"
  4. local asset = require "model.asset"
  5. local currency
  6. local module_fun = {}
  7. function module_fun.get_goods_num(character, id)
  8. currency = currency or require "model.currency"
  9. if not id then
  10. return 0
  11. end
  12. local gtype = common_fun.goods_type(id)
  13. if gtype == GOODS_MONEY then
  14. return currency.get_money(character, id)
  15. end
  16. return 0
  17. end
  18. function module_fun.reward_check(list)
  19. if type(list) ~= "table" then
  20. return STD_ERR.COMMON_AWARD_FORMAT_ERR
  21. end
  22. for _, v in ipairs(list or {}) do
  23. if type(v) ~= "table" then
  24. return STD_ERR.COMMON_AWARD_FORMAT_ERR
  25. end
  26. local id = v.id
  27. local num = v.num
  28. if not id or not num or num < 0 then
  29. return STD_ERR.COMMON_AWARD_FORMAT_ERR
  30. end
  31. local errno = common_fun.goods_check(id)
  32. if errno ~= 0 then
  33. return errno
  34. end
  35. end
  36. return 0
  37. end
  38. function module_fun.paymeny_check(character, list)
  39. currency = currency or require "model.currency"
  40. if not next(list or {}) then
  41. return STD_ERR.PAYMENT_NUM_ERR -- 消耗数量异常
  42. end
  43. for _, v in ipairs(list) do
  44. if type(v) ~= "table" then
  45. return STD_ERR.PAYMENT_LIST_ERR -- 支付格式异常
  46. end
  47. local num = v.num
  48. local id = v.id
  49. if not num or not id then
  50. return STD_ERR.PAYMENT_LIST_ERR -- 支付格式异常
  51. end
  52. if num <= 0 then
  53. return STD_ERR.PAYMENT_NUM_ERR -- 消耗数量异常
  54. end
  55. local gtype = common_fun.goods_type(id)
  56. if gtype == GOODS_MONEY then
  57. local errno = currency.check_money(character, id, num)
  58. if errno ~= 0 then
  59. return errno
  60. end
  61. else
  62. return STD_ERR.PAYMENT_UNKNOWN_ITEM -- 支付未注册的道具
  63. end
  64. return 0
  65. end
  66. end
  67. function module_fun.buy_gift(character, conf)
  68. if not conf then
  69. return STD_ERR.COMMON_PARM_ERR
  70. end
  71. end
  72. function module_fun.simple_role(character)
  73. return {
  74. uid = character.uid,
  75. nickname = character.nickname,
  76. avatar = character.avatar,
  77. level = character.level
  78. }
  79. end
  80. return module_fun