You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AdLike2048/assets/script/ui/BattleGame/BattleGameKillPeachPresente...

68 lines
2.5 KiB

3 weeks ago
import type { EntityId } from 'db://assets/mx/module/battle';
import { BattleBuffCarryStore } from '../../manager/battleBuff/BattleBuffCarryStore';
import { rollCarriedKillCoinBonus } from '../../manager/battleBuff/BattleBuffPassiveSkillUtil';
3 weeks ago
import type { ProjectBattleHandle } from '../../battle/runtime/BattleRuntime';
import type { CocosBagBoardView } from '../../battle/view/CocosBagBoardView';
3 weeks ago
import type { BattlePeachCoinFlyPresenter } from './BattlePeachCoinFlyPresenter';
/**
* 赏金令:击杀小怪概率额外金币飞币表现。
3 weeks ago
*/
export class BattleGameKillPeachPresenter {
private _battle: ProjectBattleHandle | null = null;
private _bagView: CocosBagBoardView | null = null;
private _coinFly: BattlePeachCoinFlyPresenter | null = null;
private _resolveDeathWorldPos: ((victim: EntityId) => import('cc').Vec3 | null) | null = null;
3 weeks ago
/**
* 绑定击杀事件上下文。
* @param battle 战斗
* @param bagView 棋盘
* @param coinFly 飞币
* @param resolveDeathWorldPos 死亡世界坐标
*/
3 weeks ago
bind(
battle: ProjectBattleHandle,
3 weeks ago
bagView: CocosBagBoardView | null,
coinFly: BattlePeachCoinFlyPresenter | null,
resolveDeathWorldPos: (victim: EntityId) => import('cc').Vec3 | null,
3 weeks ago
): void {
this.unbind();
this._battle = battle;
this._bagView = bagView;
this._coinFly = coinFly;
3 weeks ago
this._resolveDeathWorldPos = resolveDeathWorldPos;
}
/** 解除绑定 */
3 weeks ago
unbind(): void {
this._battle = null;
this._bagView = null;
this._coinFly = null;
3 weeks ago
this._resolveDeathWorldPos = null;
}
/**
* EntityKilled:本机赏金令额外金币。
3 weeks ago
* @param killer 击杀者
* @param victim 死亡实体
*/
onEntityKilled(killer: EntityId, victim: EntityId): void {
const battle = this._battle;
if (!battle) return;
3 weeks ago
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;
const from = this._resolveDeathWorldPos?.(victim);
if (!from) {
console.log('[KillCoin] 击杀额外金币无死亡坐标', victim);
battle.addPlayerGold(ownerId, bonus);
3 weeks ago
return;
}
this._coinFly?.playKillDrop(from, bonus);
battle.addPlayerGold(ownerId, bonus);
3 weeks ago
}
}