RedBagCashData.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import { Data } from "../../../mk/data/Data";
  2. import { GameProp } from "../GameData";
  3. /**
  4. * 红包提现数据
  5. * - 跨Index不可提现,提示:请按顺序提现。
  6. * @author 薛鸿潇
  7. */
  8. export class RedBagCashData extends Data {
  9. /**
  10. * 数据初始化
  11. */
  12. public init() {
  13. // 签到进度
  14. this.cash_bar = gData.gameData.getProp(GameProp.redBag_cash_bar);
  15. // 签到配置表
  16. if (gData.gameData.configs.CashCfg) {
  17. gData.gameData.configs.CashCfg.forEach(item_data => {
  18. for (const key in item_data) {
  19. item_data[key] = parseInt(item_data[key])
  20. }
  21. });
  22. this.c_data = gData.gameData.configs.CashCfg;
  23. this.sortList();
  24. this.init_list = true;
  25. }
  26. // this.cash_bar = gData.gameData.gameData.cashIndex;// 服务端数据
  27. }
  28. /** 标志位:初始化列表 */
  29. public init_list: boolean = false;
  30. /** 配置表数据 */
  31. public c_data: Array<CDataType> = [];
  32. private _cash_bar: number = 0;
  33. /** 提现进度 */
  34. set cash_bar(value: number) {
  35. this._cash_bar = value;
  36. this.init_list = true;
  37. }
  38. get cash_bar() {
  39. return this._cash_bar;
  40. }
  41. /**
  42. * 提现操作
  43. */
  44. public cashOP() {
  45. /** 提现档位 */
  46. const cash_index = this.cash_bar;
  47. this.cash_bar++;
  48. gData.gameData.setProp(GameProp.redBag_cash_bar, this.cash_bar);
  49. // 扣除红包
  50. this.sortList();
  51. let item_data = this.getItemDataByIndex(cash_index);
  52. gData.gameData.gameData.redMoney -= item_data.type_value;
  53. }
  54. /**
  55. * 排序
  56. * - 已提条目放最后
  57. */
  58. private sortList() {
  59. const l_count = this.c_data.length;
  60. let index = 0;
  61. for (let i = 0; i < l_count; i++) {
  62. if (this.c_data[index].index <= gData.redBagCash.cash_bar) {
  63. let item_data = this.c_data.splice(index, 1);
  64. this.c_data.push(item_data[0]);
  65. index--;
  66. }
  67. index++;
  68. }
  69. }
  70. /**
  71. * 获取条目,通过index
  72. * @param cash_index 对应id
  73. * @returns
  74. */
  75. private getItemDataByIndex(cash_index: number): CDataType {
  76. const l_count = this.c_data.length;
  77. for (let i = 0; i < l_count; i++) {
  78. if (this.c_data[i].index === cash_index) {
  79. return this.c_data[i]
  80. }
  81. }
  82. }
  83. // /** 客户端造的假数据 */
  84. // private initCData() {
  85. // for (let i = 0; i < 20; i++) {
  86. // const id = i + 1;
  87. // let obj = {
  88. // index: id,
  89. // /** 毛币数量? */
  90. // money: id,
  91. // /** 红包数量 */
  92. // type_value: id * 1000,
  93. // time: id,
  94. // directVideoTime: id,
  95. // delayVideoTimes: id,
  96. // money_type: id,
  97. // num: id,
  98. // moneyshow: id,
  99. // summoney: id
  100. // };
  101. // this.c_data.push(obj)
  102. // }
  103. // this.init_list = true;
  104. // }
  105. }
  106. /** 配置表数据内容 */
  107. export type CDataType = {
  108. /** id */
  109. index: number,
  110. /** 毛币数量,单位分 */
  111. money: number,
  112. /** 红包币数量 */
  113. type_value: number,
  114. time: number,
  115. directVideoTime: number,
  116. delayVideoTimes: number,
  117. money_type: number,
  118. num: number,
  119. moneyshow: number,
  120. summoney: number
  121. }