TakeGobletGlobalInstance.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. //获取调酒杯规则 若干个X调酒杯出现的颜色种类y上限
  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. refreshFreezeWater(freezeCount: number): boolean {
  110. const { currentOriginCup } = LevelManager.instance.levelModel;
  111. const { ice_ceiling, ice_probability, ice_thelimit } = LevelManager.instance.levelModel.levelConfig;
  112. if (freezeCount >= ice_ceiling || currentOriginCup >= ice_thelimit) {
  113. return false;
  114. }
  115. const random = Math.random() * 100;
  116. return random <= ice_probability;
  117. }
  118. //是否超过冰冻水上限
  119. isOverFreezeWaterCeiling(currrentFreezeCount: number): boolean {
  120. const { ice_ceiling } = LevelManager.instance.levelModel.levelConfig;
  121. return currrentFreezeCount >= ice_ceiling;
  122. }
  123. }
  124. /**道具类型
  125. * @param FillUp 补满
  126. * @param MoveOut 移出
  127. * @param Disturb 打乱
  128. */
  129. export enum TYPE_ITEM {
  130. FillUp = 1,
  131. MoveOut = 2,
  132. Refresh = 3,
  133. }
  134. export enum WaterColors {
  135. Red = 1, // 红
  136. Orange = 2, // 橙
  137. Yellow = 3, // 黄
  138. Green = 4, // 绿
  139. Cyan = 5, // 青
  140. Blue = 6, // 蓝
  141. Purple = 7, // 紫
  142. Palm = 8, // 棕
  143. Pink = 9, // 粉
  144. Black = 10, // 黑
  145. White = 11, // 白
  146. }
  147. // 定义对应的十六进制颜色值
  148. export const WaterColorHex: Record<WaterColors, string> = {
  149. [WaterColors.Blue]: "#0160FF",
  150. [WaterColors.Green]: "#37FF13",
  151. [WaterColors.Red]: "#FF0707",
  152. [WaterColors.Cyan]: "#00F5FF",
  153. [WaterColors.Yellow]: "#FFF10A",
  154. [WaterColors.Purple]: "#E500FF",
  155. [WaterColors.Orange]: "#FF9202",
  156. [WaterColors.Pink]: "#FF61B7",
  157. [WaterColors.Palm]: "#B45422",
  158. [WaterColors.Black]: "#131313",
  159. [WaterColors.White]: "#FFFFFF"
  160. };
  161. export const WaterColorLog: Record<WaterColors, string> = {
  162. [WaterColors.Blue]: "蓝色",
  163. [WaterColors.Green]: "绿色",
  164. [WaterColors.Red]: "红色",
  165. [WaterColors.Cyan]: "青色",
  166. [WaterColors.Yellow]: "黄色",
  167. [WaterColors.Pink]: "粉色",
  168. [WaterColors.Purple]: "紫色",
  169. [WaterColors.Orange]: '橙色',
  170. [WaterColors.Palm]: '棕色',
  171. [WaterColors.Black]: '黑色',
  172. [WaterColors.White]: '白色'
  173. };
  174. /**杯子高度*/
  175. export enum CupHeight {
  176. One = 1,
  177. Two = 2,
  178. Three = 3,
  179. Four = 4,
  180. }