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/manager/battleBuff/BattleBuffSideResolve.ts

28 lines
1.2 KiB

import type { EntityId } from 'db://assets/mx/module/ecs';
import { BattleTeamId, TeamComp, type BattleSession } from 'db://assets/mx/module/battle';
import { AI_PLAYER_ID } from '../../battle/ai/runtime/AiCampArea';
/**
* 战斗 Buff 阵营语义(见 docs/需求-战斗Buff阵营语义.md):
* - 我方单位:己侧场上塔/神将
* - 我方出征兵:进攻对面基地的行军怪(画面常在对面半场)
* - 我方基地:己侧扣墙血区域
*/
/**
* 行军怪的「出征方」playerId。
* Team.ownerId = 被进攻方;双人局出征方 = 1 - ownerId。
* @param session 战斗会话
* @param entityId 行军实体
* @returns 0=本机出征,1=AI 出征;非敌军或无法判定返回 -1
*/
export function resolveMarchOwnerPlayerId(session: BattleSession, entityId: EntityId): number {
const world = session.world;
if (!world.isAlive(entityId)) return -1;
const team = world.getComponent(entityId, TeamComp);
if (!team || !BattleTeamId.isEnemyTeam(team.team)) return -1;
const targetId = Math.max(0, Math.floor(Number(team.ownerId) || 0));
if (targetId === 0) return AI_PLAYER_ID;
if (targetId === 1) return 0;
return -1;
}