TakeGobletGlobalInstance.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. resLoader.loadAsync(resLoader.gameBundleName, `Prefabs/Cup/Original/Original${numStr}`, Prefab).then((prefab: Prefab) => {
  50. resolve(prefab);
  51. })
  52. })
  53. }
  54. /** 生成原浆杯高度*/
  55. public generateOriginCupHeight(): CupHeight {
  56. const { measuringcup } = LevelManager.instance.levelModel.levelConfig;
  57. if (!measuringcup || measuringcup.length < 3) return CupHeight.Three;
  58. const totalWeight = measuringcup.reduce((a, b) => a + b, 0);
  59. if (totalWeight <= 0) return CupHeight.Three;
  60. const randomValue = Math.random() * totalWeight;
  61. let accumulated = 0;
  62. for (let i = 0; i < measuringcup.length; i++) {
  63. accumulated += measuringcup[i];
  64. if (randomValue <= accumulated) {
  65. // 根据索引映射到正确的CupHeight值
  66. switch (i) {
  67. case 0: return CupHeight.Two;
  68. case 1: return CupHeight.Three;
  69. case 2: return CupHeight.Four;
  70. default: return CupHeight.Three;
  71. }
  72. }
  73. }
  74. return CupHeight.Three;
  75. }
  76. public levels: Node = null;
  77. getInitialCupsConfig(): { height: CupHeight; count: number }[] {
  78. const { levelConfig } = LevelManager.instance.levelModel;
  79. const wineglass = levelConfig.wineglass;
  80. return [
  81. { height: CupHeight.Two, count: wineglass[0] },
  82. { height: CupHeight.Three, count: wineglass[1] },
  83. { height: CupHeight.Four, count: wineglass[2] }
  84. ];
  85. }
  86. //获取调酒杯规则
  87. cocktailCupRule(): number[] {
  88. const { wineglass_color } = LevelManager.instance.levelModel.levelConfig;
  89. return wineglass_color;
  90. }
  91. }
  92. /**道具类型
  93. * @param FillUp 补满
  94. * @param MoveOut 移出
  95. * @param Disturb 打乱
  96. */
  97. export enum TYPE_ITEM {
  98. FillUp = 1,
  99. MoveOut = 2,
  100. Refresh = 3,
  101. }
  102. export enum WaterColors {
  103. Purple = 1, // 紫
  104. Magenta = 2, // 紫红
  105. Pink = 3, // 粉
  106. Red = 4, // 红
  107. Yellow = 5, // 黄
  108. Green = 6, // 绿
  109. Cyan = 7, // 青
  110. Blue = 8, // 蓝
  111. DarkBlue = 9, // 深蓝
  112. }
  113. // 定义对应的十六进制颜色值
  114. export const WaterColorHex: Record<WaterColors, string> = {
  115. [WaterColors.Blue]: "#317EFE",
  116. [WaterColors.Green]: "#4CF02F",
  117. [WaterColors.Red]: "#FF3939",
  118. [WaterColors.Cyan]: "#37F5FD",
  119. [WaterColors.Yellow]: "#FEF344",
  120. [WaterColors.Pink]: "#FD9FD2",
  121. [WaterColors.Purple]: "#D62F9C",
  122. [WaterColors.Magenta]: "#EE60FE",
  123. [WaterColors.DarkBlue]: "#3052A1",
  124. };
  125. export const WaterColorLog: Record<WaterColors, string> = {
  126. [WaterColors.Blue]: "蓝色",
  127. [WaterColors.Green]: "绿色",
  128. [WaterColors.Red]: "红色",
  129. [WaterColors.Cyan]: "青色",
  130. [WaterColors.Yellow]: "黄色",
  131. [WaterColors.Pink]: "粉色",
  132. [WaterColors.Purple]: "紫色",
  133. [WaterColors.Magenta]: '紫红色',
  134. [WaterColors.DarkBlue]: '深蓝色'
  135. };
  136. /**杯子高度*/
  137. export enum CupHeight {
  138. One = 1,
  139. Two = 2,
  140. Three = 3,
  141. Four = 4,
  142. }