|
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
import { isValid, Node, UIOpacity, UITransform, Vec3 } from 'cc'; |
|
|
|
|
import { GBundle } from '../../game/ConfigRes'; |
|
|
|
|
import { ConstNumType } from '../../game/GameDataEnums'; |
|
|
|
|
import type { MapManager } from './legacy/MapManager'; |
|
|
|
|
import type { MapGrid } from './legacy/MapGrid'; |
|
|
|
|
|
|
|
|
|
@ -7,8 +8,6 @@ import type { MapGrid } from './legacy/MapGrid'; |
|
|
|
|
const CHEST_TIP_PATH = 'prefab/'; |
|
|
|
|
/** 宝箱预制名(原格子锁) */ |
|
|
|
|
const CHEST_TIP_NAME = '宝箱'; |
|
|
|
|
/** 每局埋宝箱数 */ |
|
|
|
|
const CHEST_COUNT = 6; |
|
|
|
|
/** tip 世界坐标复用 */ |
|
|
|
|
const _tipWorld = new Vec3(); |
|
|
|
|
/** tip 本地坐标复用 */ |
|
|
|
|
@ -45,7 +44,7 @@ export class MapDigChestHost { |
|
|
|
|
private _dugChestCount = 0; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 开战埋 6 个宝箱(仅逻辑),并刷新 Dig 皮为默认无皮。 |
|
|
|
|
* 开战埋宝箱(个数读 Const38),并刷新 Dig 皮为默认无皮。 |
|
|
|
|
* @param map 地图 |
|
|
|
|
*/ |
|
|
|
|
init(map: MapManager): void { |
|
|
|
|
@ -65,6 +64,11 @@ export class MapDigChestHost { |
|
|
|
|
console.warn('[MapDigChestHost] 无可开挖格,未埋宝箱'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
const want = this._resolveChestCount(); |
|
|
|
|
if (want <= 0) { |
|
|
|
|
console.warn('[MapDigChestHost] Const38 宝箱个数无效,未埋宝箱', want); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
const shuffled = digs.slice(); |
|
|
|
|
for (let i = shuffled.length - 1; i > 0; i--) { |
|
|
|
|
const j = Math.floor(Math.random() * (i + 1)); |
|
|
|
|
@ -72,9 +76,9 @@ export class MapDigChestHost { |
|
|
|
|
shuffled[i] = shuffled[j]; |
|
|
|
|
shuffled[j] = tmp; |
|
|
|
|
} |
|
|
|
|
const n = Math.min(CHEST_COUNT, shuffled.length); |
|
|
|
|
if (shuffled.length < CHEST_COUNT) { |
|
|
|
|
console.warn('[MapDigChestHost] 可开挖格不足', shuffled.length, '目标', CHEST_COUNT); |
|
|
|
|
const n = Math.min(want, shuffled.length); |
|
|
|
|
if (shuffled.length < want) { |
|
|
|
|
console.warn('[MapDigChestHost] 可开挖格不足', shuffled.length, '目标', want); |
|
|
|
|
} |
|
|
|
|
for (let i = 0; i < n; i++) { |
|
|
|
|
this._slots.push({ |
|
|
|
|
@ -87,6 +91,15 @@ export class MapDigChestHost { |
|
|
|
|
console.log('[MapDigChestHost] 埋宝箱', n, this._slots.map((s) => s.index)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** Const38 关卡技能宝箱个数 */ |
|
|
|
|
private _resolveChestCount(): number { |
|
|
|
|
if (typeof gg === 'undefined' || !gg.data?.table?.getConst) { |
|
|
|
|
console.warn('[MapDigChestHost] gg.data.table 未就绪,无法读 Const38'); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
return Math.floor(Number(gg.data.table.getConst(ConstNumType.BattleDigChestCount)) || 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param index 格 Index |
|
|
|
|
* @returns 是否仍有未铲宝箱 |
|
|
|
|
|