源战役
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
7.5 KiB

  1. %%%-------------------------------------------------------------------
  2. %%% @doc 扭蛋-头文件
  3. %%% Module : capsule_egg.hrl
  4. %%% Created : 2020-06-24
  5. %%% @Author : tyl
  6. %%%-------------------------------------------------------------------
  7. %% 抽奖池类型
  8. -define(POOL_TYPE_DRAGON, 1). %% 龙神宝库
  9. -define(POOL_TYPE_WEAPON, 2). %% 炫武宝库
  10. -define(POOL_TYPE_CLOTH, 3). %% 华裳宝库
  11. -define(POOL_TYPE_LIST, [1,2,3]). %% 所有奖池
  12. %% 连抽次数
  13. -define(DRAW_TIMES_LIST, [1,10,50]).
  14. %% 单抽免费时间间隔
  15. -define(FREE_DRAW_INTERVAL, 86400).
  16. %% 目前所有档位 - 0/1/2/3
  17. %% 0/1/2档划分为一类,第3档划分为二类,其他档位不上电视
  18. %% 抽奖上电视最低档位
  19. -define(TV_GRADE, 3).
  20. %% 一类最低档位
  21. -define(TV_TOP, 2).
  22. %% 置顶档位列表
  23. -define(TV_TOP_LIST, [1,2]).
  24. %% 一二类记录限制条数(保底,具体看常量配置)
  25. -define(TV_ONE, data_capsule_egg:get_capsule_egg_kv_cfg(show_num_one)).
  26. -define(TV_TWO, data_capsule_egg:get_capsule_egg_kv_cfg(show_num_two)).
  27. %% 临时仓库将满提醒
  28. -define(CAPSULE_EGG_NULL_CELL, 50).
  29. %% 全服最大幸运值
  30. -define(SERVER_MAX_LUCKY, 999).
  31. %% 概率加成类型
  32. -define(RAND_ADD_PERSONAL, 1). %% 个人
  33. -define(RAND_ADD_SERVER, 2). %% 全服
  34. %% 积分商城兑换限制类型
  35. -define(SCORE_STORE_LIMIT_DAILY, 1). %% 每日次数限制
  36. -define(SCORE_STORE_LIMIT_WEEK, 2). %% 每周次数限制
  37. -define(SCORE_STORE_LIMIT_LIFE, 3). %% 终身次数限制
  38. %% 玩家扭蛋数据
  39. -record(status_capsule_egg, {
  40. capsule_egg_map = #{} %% 扭蛋数据(共三个抽奖池) #{pool_type => #capsule_egg_data{}}
  41. ,score = 0 %% 总抽奖积分,用于兑换积分商城物品
  42. }).
  43. %% 扭蛋抽奖数据
  44. -record(capsule_egg_data, {
  45. pool_type = 0 %% 抽奖池类型
  46. ,next_free_time = 0 %% 下次免费时间
  47. ,draw_times = 0 %% 抽奖次数(计算必得)
  48. ,lucky_score = 0 %% 个人幸运值, 计算动态权重(获得一二档之后清0)
  49. ,top_lucky_score= 0 %% 0当奖励的个人幸运值(获得0档之后清0)
  50. ,times_reward = [] %% 次数奖励[{times,status}...] status-1 已领取
  51. }).
  52. %% 全服扭蛋数据
  53. -record(capsule_egg_state, {
  54. lucky_score_map = #{} %% 全服幸运值 #{pool_type => server_score}
  55. ,show_lucky_map = #{} %% 展示给前端的全服幸运值 #{pool_type => show_score}
  56. ,record_map = #{} %% 二类(3档)抽奖记录 #{pool_type => [#draw_record{}]}
  57. ,top_record_map = #{} %% 一类(1/2档)抽奖记录 #{pool_type => [#draw_record{}]}
  58. ,weekly_refresh_ref = [] %% 周期清理定时器
  59. }).
  60. %% 抽奖记录
  61. -record(draw_record, {
  62. pool_type = 0 %% 抽奖池类型
  63. ,role_id = 0 %% 角色Id
  64. ,role_name = 0 %% 角色名称
  65. ,reward_cfg_id = 0 %% 奖励配置Id
  66. ,draw_time = 0 %% 抽奖时间
  67. }).
  68. %% ==================================== 后台配置 ===========================
  69. %% 扭蛋基础配置表
  70. -record(capsule_egg_kv_cfg, {
  71. id = 0 %% Id
  72. ,key = "" %% 主键
  73. ,value = "" %% 值
  74. ,remark = "" %% 备注
  75. }).
  76. %% 抽奖物品配置表
  77. -record(capsule_egg_reward_cfg, {
  78. id = 0 %% Id
  79. ,pool_type = 0 %% 奖池类型
  80. ,color = 0 %% 档位(品质)
  81. ,reward = [] %% 奖励列表
  82. ,weight = 0 %% 权重
  83. ,client_pos = 0 %% 客户端推荐展示位置
  84. }).
  85. %% 动态概率配置表
  86. -record(capsule_egg_ratio_cfg, {
  87. pool_type = 0 %% 奖池类型
  88. ,color = 0 %% 档位
  89. ,type = 0 %% 概率类型 1-个人 2-全服
  90. ,low = 0 %% 下限(抽奖次数)
  91. ,high = 0 %% 上限
  92. ,add_weight = 0 %% 权重加成
  93. }).
  94. %% 次数必得配置表
  95. -record(capsule_egg_times_cfg, {
  96. pool_type = 0 %% 奖池类型
  97. ,draw_times = 0 %% 抽奖次数
  98. ,select_color = 0 %% 必得物品品质
  99. }).
  100. %% 积分商城兑换配置表
  101. -record(capsule_egg_exchange_cfg, {
  102. id = 0 %% 序号
  103. ,reward = [] %% 兑换物品
  104. ,cost_score = 0 %% 消耗积分
  105. ,exchange_times = 0 %% 可兑换次数
  106. ,limit_type = 0 %% 限购类型 1-日 2-周 3-终身
  107. }).
  108. %% 次数奖励配置表
  109. -record(capsule_egg_times_reward_cfg, {
  110. pool_type = 0 %% 奖池类型
  111. ,draw_times = 0 %% 抽奖次数
  112. ,reward = [] %% 奖励
  113. }).
  114. %% ============================= 数据库操作 =============================
  115. %% 个人抽奖数据
  116. -define(SQL_INSERT_CAPSULE_EGG, <<"REPLACE INTO capsule_egg_data (`role_id`, `pool_type`, `next_free_time`, `draw_times`, `lucky_score`, `top_lucky_score`) VALUES (~p, ~p, ~p, ~p, ~p, ~p)">>).
  117. -define(SQL_SELECT_CAPSULE_EGG, <<"SELECT `pool_type`, `next_free_time`, `draw_times`, `lucky_score`, `top_lucky_score` FROM capsule_egg_data WHERE `role_id` = ~p">>).
  118. -define(SQL_UPDATE_CAPSULE_EGG, <<"UPDATE capsule_egg_data SET `next_free_time` = ~p, `draw_times` = ~p WHERE `role_id` = ~p AND `pool_type` = ~p">>).
  119. -define(SQL_UPDATE_FREE_TIME, <<"UPDATE capsule_egg_data SET `next_free_time` = ~p WHERE `role_id` = ~p AND `pool_type` = ~p">>).
  120. -define(SQL_UPDATE_DRAW_TIMES, <<"UPDATE capsule_egg_data SET `draw_times`= 0">>).
  121. %% 个人抽奖积分
  122. -define(SQL_INSERT_CAPSULE_EGG_PERSON_SCORE, <<"REPLACE INTO capsule_egg_person_score (`role_id`, `score`) VALUES (~p, ~p)">>).
  123. -define(SQL_SELECT_CAPSULE_EGG_PERSON_SCORE, <<"SELECT `score` FROM capsule_egg_person_score WHERE `role_id` = ~p LIMIT 1">>).
  124. %% 全服抽奖幸运值积分
  125. -define(SQL_INSERT_CAPSULE_EGG_SERVER_LUCKY, <<"REPLACE INTO capsule_egg_server_score (`pool_type`, `score`, `show_score`) VALUES (~p, ~p, ~p)">>).
  126. -define(SQL_SELECT_CAPSULE_EGG_SERVER_LUCKY, <<"SELECT `pool_type`,`score`, `show_score` FROM capsule_egg_server_score">>).
  127. %% 0档奖励全服抽奖幸运值积分(暂时未使用)
  128. -define(SQL_INSERT_CAPSULE_EGG_TOP_SERVER_LUCKY, <<"REPLACE INTO capsule_egg_top_server_score (`pool_type`, `score`) VALUES (~p, ~p)">>).
  129. -define(SQL_SELECT_CAPSULE_EGG_TOP_SERVER_LUCKY, <<"SELECT `pool_type`,`score` FROM capsule_egg_top_server_score">>).
  130. %% 全服抽奖记录
  131. -define(SQL_INSERT_CAPSULE_EGG_DRAW_LOG, <<"REPLACE INTO capsule_egg_draw_log (`pool_type`, `role_id`, `reward_cfg_id`, `color`, `time`) VALUES (~p, ~p, ~p, ~p, ~p)">>).
  132. -define(SQL_BATCH_INSERT_CAPSULE_EGG_DRAW_LOG, <<"REPLACE INTO capsule_egg_draw_log (`pool_type`, `role_id`, `reward_cfg_id`, `color`, `time`) VALUES ~ts">>).
  133. -define(SQL_BATCH_INSERT_CAPSULE_EGG_DRAW_LOG_VALUE, <<"(~p, ~p, ~p, ~p, ~p)">>).
  134. -define(SQL_SELECT_CAPSULE_EGG_DRAW_LOG, <<"SELECT `pool_type`, `role_id`, `reward_cfg_id`, `color`, `time` FROM capsule_egg_draw_log WHERE `time` >= ~p AND `color` = 3 ORDER BY `time` desc LIMIT ~p">>).
  135. -define(SQL_SELECT_TOP_CAPSULE_EGG_DRAW_LOG, <<"SELECT `pool_type`, `role_id`, `reward_cfg_id`, `color`, `time` FROM capsule_egg_draw_log WHERE `time` >= ~p AND `color` < 3 ORDER BY `time` desc LIMIT ~p">>).
  136. %% 次数奖励
  137. -define(SQL_INSERT_CAPSULE_EGG_TIMES_REWARD, <<"REPLACE INTO capsule_egg_times_reward (`role_id`, `pool_type`, `draw_times`, `status`) VALUES (~p, ~p, ~p, ~p)">>).
  138. -define(SQL_SELECT_CAPSULE_EGG_TIMES_REWARD, <<"SELECT `draw_times`, `status` from capsule_egg_times_reward WHERE `role_id` = ~p AND `pool_type` = ~p">>).
  139. -define(SQL_DELETE_CAPSULE_EGG_TIMES_REWARD, <<"TRUNCATE table capsule_egg_times_reward">>).
  140. %% 查询玩家名称
  141. -define(SQL_SELECT_PLAYER_NAME, <<"select nickname from player_low where id = '~w' limit 1">>).
  142. %% capsule_egg_data, capsule_egg_person_score, capsule_egg_server_score, capsule_egg_draw_log