GuideWeakData.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { Data } from "../../../mk/data/Data";
  2. import GuideWeak from "../../module/guideWeak/GuideWeak";
  3. /**
  4. * 弱引导数据
  5. * - 主界面-弱引导
  6. 1. 弱引导启动:用户在主界面超过10秒未操作【配置】。
  7. 2. 弱引导效果:自动弹出以下界面中的一种:气泡红包界面、福袋界面、互推界面……【配置】
  8. 3. 配置需支持配置界面ID和对应的弹出概率。
  9. - 关卡界面-弱引导
  10. 1. 弱引导启动:用户在关卡界面超过10秒未操作【配置】。
  11. 2. 弱引导效果:自动弹出以下界面中的一种:气泡红包界面、福袋界面、互推界面……【配置】
  12. 3. 配置需支持配置界面ID和对应的弹出概率。
  13. * @author 薛鸿潇
  14. */
  15. export default class GuideWeakData {
  16. /**
  17. * 数据初始化
  18. */
  19. public init() {
  20. // this.data_config = data_config;
  21. if (gData.gameData.configs.ServerConfig.triggerTime)
  22. this.data_config.triggerTime = parseInt(gData.gameData.configs.ServerConfig.triggerTime);
  23. if (gData.gameData.configs.ServerConfig.panelWeight) {
  24. // 8:70,5:30
  25. this.data_config.panelWeight = {}
  26. let new_weight = gData.gameData.configs.ServerConfig.panelWeight.split(',')
  27. for (let i = 0; i < new_weight.length; i++) {
  28. const item_str = new_weight[i].split(':');
  29. this.data_config.panelWeight[item_str[0]] = parseInt(item_str[1]);
  30. }
  31. }
  32. }
  33. /**
  34. * 星云数据配置
  35. * - 面板权重
  36. * - 触发时间
  37. */
  38. public data_config = {
  39. panelWeight: {
  40. },
  41. triggerTime: 5
  42. }
  43. /** 功能是否启动 */
  44. public enable: boolean = false;
  45. /** 引导正在运行 */
  46. /** 样式类 */
  47. public guideStyle: GuideWeak = null;
  48. /**
  49. * 玩家静默时间
  50. * - 即:未进行任何操作的时间
  51. */
  52. public silent_time: number = 0;
  53. /** 当前打开的界面id */
  54. public cur_guide_id: number = 0;
  55. /** 当前打开的界面名字 */
  56. public cur_guide_panel: string = null;
  57. public initGuideId() {
  58. // gData.guideWeakData.cur_guide_id = 1 + 1;
  59. const panelWeight = this.data_config.panelWeight;
  60. let p_count = 0;
  61. let total_weight = 0;
  62. for (const key in panelWeight) {
  63. total_weight += panelWeight[key];
  64. p_count++;
  65. }
  66. /** 累计零时权重 */
  67. let temp_weight_sum = 0;
  68. // 根据奖池权重随机物品
  69. let random = mk.math.random(1, total_weight);
  70. for (const key in panelWeight) {
  71. temp_weight_sum += panelWeight[key];
  72. if (random < temp_weight_sum) {
  73. // 中奖了
  74. gData.guideWeakData.cur_guide_id = parseInt(key);
  75. break;
  76. }
  77. }
  78. }
  79. public openPanelByBtn() {
  80. const panel_id = gData.guideWeakData.cur_guide_id
  81. if (gData.gameData.funBtns['btn' + panel_id])
  82. gData.gameData.funBtns['btn' + panel_id].emit('click')
  83. }
  84. public panel_name_config = {
  85. moreGame: 1,
  86. turnable: 2,
  87. none: 3,
  88. pigBank: 4,
  89. blessingBag: 5,
  90. sign: 6,
  91. redBagCash: 7,
  92. rewardLuck: 8,
  93. }
  94. }