GuideWeakData.ts 3.3 KB

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