RedBagCashData.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import { Data } from "../../../mk/data/Data";
  2. import { GameProp, RewardState } 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. this.cash_bar = gData.gameData.playerProp.cashIndex;// 服务端数据
  16. // this.initCData();// 假数据列表
  17. // 签到配置表
  18. if (gData.gameData.configs.CashCfg) {
  19. gData.gameData.configs.CashCfg.forEach(item_data => {
  20. for (const key in item_data) {
  21. item_data[key] = parseInt(item_data[key])
  22. }
  23. });
  24. this.c_data = gData.gameData.configs.CashCfg;
  25. this.sortList();
  26. this.initState();
  27. this.init_list = true;
  28. }
  29. }
  30. /** 标志位:初始化列表 */
  31. public init_list: boolean = false;
  32. public update_list: boolean = false;
  33. /** 配置表数据 */
  34. public c_data: Array<CDataType> = [];
  35. private _cash_bar: number = 1;
  36. /** 提现进度 */
  37. set cash_bar(value: number) {
  38. this._cash_bar = value;
  39. this.init_list = true;
  40. }
  41. get cash_bar() {
  42. return this._cash_bar;
  43. }
  44. /**
  45. * 排序
  46. * - 已提条目放最后
  47. */
  48. private sortList() {
  49. const l_count = this.c_data.length;
  50. let index = 0;
  51. for (let i = 0; i < l_count; i++) {
  52. if (this.c_data[index].index < gData.redBagCash.cash_bar) {
  53. let item_data = this.c_data.splice(index, 1);
  54. this.c_data.push(item_data[0]);
  55. index--;
  56. }
  57. index++;
  58. }
  59. }
  60. /**
  61. * 初始化状态
  62. */
  63. public initState() {
  64. let total = gData.gameData.playerProp.redMoney + 0;
  65. const l_count = this.c_data.length;
  66. for (let i = 0; i < l_count; i++) {
  67. // 已提现
  68. if (this.c_data[i].index < gData.redBagCash.cash_bar) {
  69. this.c_data[i].state = RewardState.none;
  70. } else {
  71. total = this.itemAllowCash(total, this.c_data[i].redMoney);
  72. if (total > 0) {
  73. this.c_data[i].state = RewardState.unlock;
  74. } else {
  75. this.c_data[i].state = RewardState.lock;
  76. }
  77. }
  78. }
  79. }
  80. /**
  81. * 当前红包币足够提现多少条
  82. * @param total 兑换后的红包币数量,逐条递减
  83. * @param type_value 条目要求的红包币数量
  84. * @returns
  85. */
  86. private itemAllowCash(total: number, type_value: number): number {
  87. if (total >= type_value) {
  88. total -= type_value;
  89. return total;
  90. } else {
  91. return 0;
  92. }
  93. }
  94. /**
  95. * 获取条目,通过index
  96. * @param cash_index 对应id
  97. * @returns
  98. */
  99. public getItemDataByIndex(cash_index: number): CDataType {
  100. const l_count = this.c_data.length;
  101. for (let i = 0; i < l_count; i++) {
  102. if (this.c_data[i].index === cash_index) {
  103. return this.c_data[i]
  104. }
  105. }
  106. }
  107. /** 客户端造的假数据 */
  108. private initCData() {
  109. for (let i = 0; i < 20; i++) {
  110. const id = i + 1;
  111. let obj = {
  112. index: id,
  113. /** 毛币数量? */
  114. money: id,
  115. /** 红包数量 */
  116. redMoney: id * 1000,
  117. time: id,
  118. directVideoTime: id,
  119. delayVideoTimes: id,
  120. money_type: id,
  121. num: id,
  122. moneyshow: id,
  123. summoney: id,
  124. state: 1
  125. };
  126. this.c_data.push(obj)
  127. }
  128. this.init_list = true;
  129. }
  130. /**
  131. * 红点功能
  132. */
  133. public redPoint(): boolean {
  134. const redbag_count = gData.gameData.playerProp.redMoney;
  135. const d_count = this.c_data.length;
  136. for (let i = 0; i < d_count; i++) {
  137. if (this.c_data[i].index < gData.redBagCash.cash_bar) continue;// 已提现
  138. if (redbag_count >= this.c_data[i].redMoney) return true;// 可提现
  139. }
  140. return false;
  141. }
  142. }
  143. /** 配置表数据内容 */
  144. export type CDataType = {
  145. /** id */
  146. index: number,
  147. /** 毛币数量,单位分 */
  148. money: number,
  149. /** 红包币数量 */
  150. redMoney: number,
  151. time: number,
  152. directVideoTime: number,
  153. delayVideoTimes: number,
  154. money_type: number,
  155. num: number,
  156. moneyshow: number,
  157. summoney: number,
  158. /** 提现状态 - 客户端加 */
  159. state: number,
  160. }