TakeGobletGlobalInstance.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. refreshFreezeWaterInit(): boolean {
  110. const { ice_thelimit } = LevelManager.instance.levelModel.levelConfig;
  111. const random = Math.random() * 100;
  112. return random <= ice_thelimit;
  113. }
  114. //生成单个冰冻水刷新概率
  115. refreshFreezeWater(freezeCount: number): boolean {
  116. const { ice_ceiling, ice_probability } = LevelManager.instance.levelModel.levelConfig;
  117. if (freezeCount >= ice_ceiling) {
  118. return false;
  119. }
  120. const random = Math.random() * 100;
  121. return random <= ice_probability;
  122. }
  123. //是否超过冰冻水上限
  124. isOverFreezeWaterCeiling(currrentFreezeCount: number): boolean {
  125. const { ice_ceiling } = LevelManager.instance.levelModel.levelConfig;
  126. return currrentFreezeCount >= ice_ceiling;
  127. }
  128. }
  129. /**道具类型
  130. * @param FillUp 补满
  131. * @param MoveOut 移出
  132. * @param Disturb 打乱
  133. */
  134. export enum TYPE_ITEM {
  135. FillUp = 1,
  136. MoveOut = 2,
  137. Refresh = 3,
  138. }
  139. export enum WaterColors {
  140. Purple = 1, // 紫
  141. Magenta = 2, // 紫红
  142. Pink = 3, // 粉
  143. Red = 4, // 红
  144. Yellow = 5, // 黄
  145. Green = 6, // 绿
  146. Cyan = 7, // 青
  147. Blue = 8, // 蓝
  148. DarkBlue = 9, // 深蓝
  149. Black = 10, // 黑
  150. }
  151. // 定义对应的十六进制颜色值
  152. export const WaterColorHex: Record<WaterColors, string> = {
  153. [WaterColors.Blue]: "#317EFE",
  154. [WaterColors.Green]: "#4CF02F",
  155. [WaterColors.Red]: "#FF3939",
  156. [WaterColors.Cyan]: "#37F5FD",
  157. [WaterColors.Yellow]: "#FEF344",
  158. [WaterColors.Pink]: "#FD9FD2",
  159. [WaterColors.Purple]: "#D62F9C",
  160. [WaterColors.Magenta]: "#EE60FE",
  161. [WaterColors.DarkBlue]: "#3052A1",
  162. [WaterColors.Black]: "#131313",
  163. };
  164. export const WaterColorLog: Record<WaterColors, string> = {
  165. [WaterColors.Blue]: "蓝色",
  166. [WaterColors.Green]: "绿色",
  167. [WaterColors.Red]: "红色",
  168. [WaterColors.Cyan]: "青色",
  169. [WaterColors.Yellow]: "黄色",
  170. [WaterColors.Pink]: "粉色",
  171. [WaterColors.Purple]: "紫色",
  172. [WaterColors.Magenta]: '紫红色',
  173. [WaterColors.DarkBlue]: '深蓝色',
  174. [WaterColors.Black]: '黑色'
  175. };
  176. /**杯子高度*/
  177. export enum CupHeight {
  178. One = 1,
  179. Two = 2,
  180. Three = 3,
  181. Four = 4,
  182. }