import { Vec3 } from 'cc'; import { schedulePresentation } from '../../battle/skill/BattlePresentationClock'; import type { CocosBagBoardView } from '../../battle/view/CocosBagBoardView'; import { rollCarriedTreasureShovelPeachCount } from '../../manager/battleBuff/BattleBuffPassiveSkillUtil'; import type { BattlePeachCoinFlyPresenter } from './BattlePeachCoinFlyPresenter'; /** 逐枚出现间隔(逻辑秒;固定节奏,与枚数无关) */ const DIG_PEACH_INTERVAL_SEC = 0.15; /** * 掘宝仙铲(functiontype=10):铲挖开格后在格心逐枚弹出 coinFly(与击杀掉桃一致)并飞向 ui_money。 */ export class BattleGameTreasureShovelPresenter { private _bagView: CocosBagBoardView | null = null; private _peachFly: BattlePeachCoinFlyPresenter | null = null; /** 并行倒计时世代(unbind 时递增以作废待触发回调) */ private _scheduleGen = 0; /** 绑定背包视图与飘桃演出 */ bind(bagView: CocosBagBoardView | null, peachFly: BattlePeachCoinFlyPresenter | null): void { this.unbind(); this._bagView = bagView; this._peachFly = peachFly; bagView?.setShovelDigRewardHandler(this._onShovelDig.bind(this)); } /** 注销并中断进行中的演出 */ unbind(): void { this._scheduleGen++; this._bagView?.setShovelDigRewardHandler(null); this._bagView = null; this._peachFly = null; } /** 铲挖开 Dig 格:随机蟠桃数量并播放击杀同款 coinFly 掉桃 */ private _onShovelDig(gridIndex: number): void { const bagView = this._bagView; const peachFly = this._peachFly; if (!bagView || !peachFly) return; const peachCount = rollCarriedTreasureShovelPeachCount(); if (peachCount <= 0) return; const startWorld = bagView.getMapGridWorldPosition(gridIndex); if (!startWorld) { console.log('[TreasureShovel] 挖格坐标缺失', gridIndex); return; } this._playDigPeachSequence(startWorld, peachCount); } /** 格心逐枚弹出 coinFly;开格后立即首枚,之后按固定间隔依次蹦出 */ private _playDigPeachSequence(startWorld: Readonly, peachCount: number): void { const bagView = this._bagView; const peachFly = this._peachFly; if (!bagView || !peachFly) return; const scheduleGen = ++this._scheduleGen; for (let i = 0; i < peachCount; i++) { const delay = i * DIG_PEACH_INTERVAL_SEC; schedulePresentation(delay, () => { if (scheduleGen !== this._scheduleGen) return; peachFly.playKillDrop(startWorld, 1); bagView.grantBattlePeach(1); }); } } }