TakeGobletGlobalInstance.ts 5.8 KB

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