TakeGobletGlobalInstance.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import { _decorator, assetManager, Component, Node, Prefab } from 'cc';
  2. import { resLoader } from '../../core_tgx/base/ResLoader';
  3. import { ResourcePool } from './ResourcePool';
  4. import { LevelManager } from './Manager/LevelMgr';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('TakeGobletGlobalInstance')
  7. export class TakeGobletGlobalInstance {
  8. private static _instance: TakeGobletGlobalInstance;
  9. public static get instance() {
  10. if (this._instance) {
  11. return this._instance;
  12. }
  13. this._instance = new TakeGobletGlobalInstance();
  14. return this._instance;
  15. }
  16. /** 异步加载调酒杯预设*/
  17. async loadAsyncCocktail(height: CupHeight): Promise<Prefab> {
  18. return new Promise((resolve, reject) => {
  19. const bundle = assetManager.getBundle(resLoader.gameBundleName);
  20. if (!bundle) {
  21. console.error("module_nut is null!");
  22. reject();
  23. }
  24. let numStr = 'Two';
  25. if (height == CupHeight.Three) {
  26. numStr = 'Three';
  27. } else if (height == CupHeight.Four) {
  28. numStr = 'Four';
  29. }
  30. resLoader.loadAsync(resLoader.gameBundleName, `Prefabs/Cup/Cocktail/Cocktail${numStr}`, Prefab).then((prefab: Prefab) => {
  31. resolve(prefab);
  32. })
  33. })
  34. }
  35. /** 异步加载调酒杯预设*/
  36. async loadAsyncOriginCup(height: CupHeight): Promise<Prefab> {
  37. return new Promise((resolve, reject) => {
  38. const bundle = assetManager.getBundle(resLoader.gameBundleName);
  39. if (!bundle) {
  40. console.error("module_nut is null!");
  41. reject();
  42. }
  43. let numStr = 'Two';
  44. if (height == CupHeight.Three) {
  45. numStr = 'Three';
  46. } else if (height == CupHeight.Four) {
  47. numStr = 'Four';
  48. }
  49. // console.log(`异步加载原浆杯预设: Original${numStr}`);
  50. resLoader.loadAsync(resLoader.gameBundleName, `Prefabs/Cup/Original/Original${numStr}`, Prefab).then((prefab: Prefab) => {
  51. resolve(prefab);
  52. })
  53. })
  54. }
  55. /** 生成原浆杯高度*/
  56. public generateOriginCupHeight(): CupHeight {
  57. const { measuringcup } = LevelManager.instance.levelModel.levelConfig;
  58. if (!measuringcup || measuringcup.length < 3) return CupHeight.Three;
  59. const totalWeight = measuringcup.reduce((a, b) => a + b, 0);
  60. if (totalWeight <= 0) return CupHeight.Three;
  61. const randomValue = Math.random() * totalWeight;
  62. let accumulated = 0;
  63. for (let i = 0; i < measuringcup.length; i++) {
  64. accumulated += measuringcup[i];
  65. if (randomValue <= accumulated) {
  66. // 根据索引映射到正确的CupHeight值
  67. switch (i) {
  68. case 0: return CupHeight.Two;
  69. case 1: return CupHeight.Three;
  70. case 2: return CupHeight.Four;
  71. default: return CupHeight.Three;
  72. }
  73. }
  74. }
  75. return CupHeight.Three;
  76. }
  77. public levels: Node = null;
  78. getInitialCupsConfig(): { height: CupHeight; count: number }[] {
  79. const { levelConfig } = LevelManager.instance.levelModel;
  80. const wineglass = levelConfig.wineglass;
  81. return [
  82. { height: CupHeight.Two, count: wineglass[0] },
  83. { height: CupHeight.Three, count: wineglass[1] },
  84. { height: CupHeight.Four, count: wineglass[2] }
  85. ];
  86. }
  87. //获取调酒杯规则
  88. cocktailCupRule(): number[] {
  89. const { wineglass_color } = LevelManager.instance.levelModel.levelConfig;
  90. return wineglass_color;
  91. }
  92. }
  93. /**道具类型
  94. * @param FillUp 补满
  95. * @param MoveOut 移出
  96. * @param Disturb 打乱
  97. */
  98. export enum TYPE_ITEM {
  99. FillUp = 1,
  100. MoveOut = 2,
  101. Refresh = 3,
  102. }
  103. export enum WaterColors {
  104. Purple = 1, // 紫
  105. Magenta = 2, // 紫红
  106. Pink = 3, // 粉
  107. Red = 4, // 红
  108. Yellow = 5, // 黄
  109. Green = 6, // 绿
  110. Cyan = 7, // 青
  111. Blue = 8, // 蓝
  112. DarkBlue = 9, // 深蓝
  113. }
  114. // 定义对应的十六进制颜色值
  115. export const WaterColorHex: Record<WaterColors, string> = {
  116. [WaterColors.Blue]: "#317EFE",
  117. [WaterColors.Green]: "#4CF02F",
  118. [WaterColors.Red]: "#FF3939",
  119. [WaterColors.Cyan]: "#37F5FD",
  120. [WaterColors.Yellow]: "#FEF344",
  121. [WaterColors.Pink]: "#FD9FD2",
  122. [WaterColors.Purple]: "#D62F9C",
  123. [WaterColors.Magenta]: "#EE60FE",
  124. [WaterColors.DarkBlue]: "#3052A1",
  125. };
  126. export const WaterColorLog: Record<WaterColors, string> = {
  127. [WaterColors.Blue]: "蓝色",
  128. [WaterColors.Green]: "绿色",
  129. [WaterColors.Red]: "红色",
  130. [WaterColors.Cyan]: "青色",
  131. [WaterColors.Yellow]: "黄色",
  132. [WaterColors.Pink]: "粉色",
  133. [WaterColors.Purple]: "紫色",
  134. [WaterColors.Magenta]: '紫红色',
  135. [WaterColors.DarkBlue]: '深蓝色'
  136. };
  137. /**杯子高度*/
  138. export enum CupHeight {
  139. One = 1,
  140. Two = 2,
  141. Three = 3,
  142. Four = 4,
  143. }