|
|
|
|
import type { EntityId } from 'db://assets/mx/module/battle';
|
|
|
|
|
import type { Vec3 } from 'cc';
|
|
|
|
|
import { BattleBuffCarryStore } from '../../manager/battleBuff/BattleBuffCarryStore';
|
|
|
|
|
import { rollCarriedKillCoinBonus } from '../../manager/battleBuff/BattleBuffPassiveSkillUtil';
|
|
|
|
|
import type { ProjectBattleHandle } from '../../battle/runtime/BattleRuntime';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 赏金令:击杀小怪概率额外金币飞币表现。
|
|
|
|
|
*/
|
|
|
|
|
export class BattleGameKillPeachPresenter {
|
|
|
|
|
private _battle: ProjectBattleHandle | null = null;
|
|
|
|
|
private _playLocalCoinFly: ((fromWorld: Readonly<Vec3>, amount: number) => void) | null = null;
|
|
|
|
|
private _resolveDeathWorldPos: ((victim: EntityId) => Vec3 | null) | null = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 绑定击杀事件上下文。
|
|
|
|
|
* @param battle 战斗
|
|
|
|
|
* @param playLocalCoinFly 本机飞币(挂起 UI,到达后刷新)
|
|
|
|
|
* @param resolveDeathWorldPos 死亡世界坐标
|
|
|
|
|
*/
|
|
|
|
|
bind(
|
|
|
|
|
battle: ProjectBattleHandle,
|
|
|
|
|
playLocalCoinFly: (fromWorld: Readonly<Vec3>, amount: number) => void,
|
|
|
|
|
resolveDeathWorldPos: (victim: EntityId) => Vec3 | null,
|
|
|
|
|
): void {
|
|
|
|
|
this.unbind();
|
|
|
|
|
this._battle = battle;
|
|
|
|
|
this._playLocalCoinFly = playLocalCoinFly;
|
|
|
|
|
this._resolveDeathWorldPos = resolveDeathWorldPos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 解除绑定 */
|
|
|
|
|
unbind(): void {
|
|
|
|
|
this._battle = null;
|
|
|
|
|
this._playLocalCoinFly = null;
|
|
|
|
|
this._resolveDeathWorldPos = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* EntityKilled:本机赏金令额外金币。
|
|
|
|
|
* @param killer 击杀者
|
|
|
|
|
* @param victim 死亡实体
|
|
|
|
|
*/
|
|
|
|
|
onEntityKilled(killer: EntityId, victim: EntityId): void {
|
|
|
|
|
const battle = this._battle;
|
|
|
|
|
if (!battle) return;
|
|
|
|
|
if (!battle.isSmallMonsterVictim(victim)) return;
|
|
|
|
|
const ownerId = battle.resolveKillPeachOwnerPlayerId(killer, victim);
|
|
|
|
|
if (ownerId !== battle.localPlayerId) return;
|
|
|
|
|
const bonus = rollCarriedKillCoinBonus(BattleBuffCarryStore.getPassives(ownerId));
|
|
|
|
|
if (bonus <= 0) return;
|
|
|
|
|
battle.addPlayerGold(ownerId, bonus);
|
|
|
|
|
const from = this._resolveDeathWorldPos?.(victim);
|
|
|
|
|
if (!from) {
|
|
|
|
|
console.log('[KillCoin] 击杀额外金币无死亡坐标', victim);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this._playLocalCoinFly?.(from, bonus);
|
|
|
|
|
}
|
|
|
|
|
}
|