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/battle/combat/TowerPositiveBuffState.ts

63 lines
2.4 KiB

import { membershipFromArray } from '../../../mx/tools/MembershipSet';
import type { BattleSession } from 'db://assets/mx/module/battle';
import { AttributeComp } from 'db://assets/mx/module/battle/ecs/Components';
import { COUNT_BUFF_GROUP } from 'db://assets/mx/module/battle/combat/DamagePipeline';
import type { EntityId } from 'db://assets/mx/module/ecs';
import type { Player } from '../../game/Player';
import type { MapManager } from '../map/legacy/MapManager';
import { findCompositionForEntity, findGridIndexForEntity } from '../runtime/DeployEntityQuery';
import { ATK_FAST_ASPD_GROUP, TIMED_BUFF_GROUP } from './EntryBuffGroups';
export const WANGMU_ULT_BUFF_GROUP = 'wangmu_ult';
const TIMED_POSITIVE_BUFF_GROUPS = membershipFromArray([TIMED_BUFF_GROUP, ATK_FAST_ASPD_GROUP, WANGMU_ULT_BUFF_GROUP]);
/** 己方单位是否持有需要格子表现的临时正面 buff */
export function entityHasActivePositiveBuff(session: BattleSession, entityId: EntityId): boolean {
const world = session.world;
if (!world.isAlive(entityId)) return false;
const attr = world.getComponent(entityId, AttributeComp);
if (!attr) return false;
return attr.modifiers.some(m => {
if (m.group === COUNT_BUFF_GROUP && (m.charges ?? 0) > 0) return true;
return m.remain != null
&& m.remain > 0
&& m.group != null
&& TIMED_POSITIVE_BUFF_GROUPS.has(m.group);
});
}
/** 实体占用的全部地图格(多字英雄返回全部字格 index) */
export function resolveGridIndicesForEntity(
entityId: EntityId,
session: BattleSession,
map: MapManager,
player: Player | null,
): number[] {
const out: number[] = [];
forEachGridIndexForEntity(entityId, session, map, player, (idx) => out.push(idx));
return out;
}
/** 遍历实体占格,不分配中间数组(buff 同步等热路径用) */
export function forEachGridIndexForEntity(
entityId: EntityId,
session: BattleSession,
map: MapManager,
player: Player | null,
fn: (gridIndex: number) => void,
): void {
if (player) {
const comp = findCompositionForEntity(entityId, player, session, map);
if (comp?.gridIndices.length) {
for (let i = 0; i < comp.gridIndices.length; i++) {
fn(comp.gridIndices[i]);
}
return;
}
}
if (!player) return;
const idx = findGridIndexForEntity(entityId, player, session, map);
if (idx != null) fn(idx);
}