import type { BattleSession } from 'db://assets/mx/module/battle'; import type { EntityId } from 'db://assets/mx/module/ecs'; import { AttrId, AttributeComp } from 'db://assets/mx/module/battle/ecs/Components'; /** 将 base_attr 语义的属性写入实体(与 SkillPickApplier 一致) */ export function applyBondAttrsToEntity( session: BattleSession, entityId: EntityId, attrs: ReadonlyArray<{ type: number; value: number }>, source: string, stackCount = 1, ): void { const world = session.world; if (!world.isAlive(entityId)) return; if (!world.getComponent(entityId, AttributeComp)) { world.addComponent(entityId, new AttributeComp()); } const attrSvc = session.attributes; for (const { type, value } of attrs) { const scaled = value * stackCount; switch (type) { case 1: attrSvc.addModifier(entityId, { attr: AttrId.Attack, op: 'Mul', value: 1 + scaled / 10000, source, }); break; case 2: attrSvc.addModifier(entityId, { attr: 'aspd_add', op: 'Add', value: scaled, source, }); break; case 3: attrSvc.addModifier(entityId, { attr: AttrId.CritRate, op: 'Add', value: scaled / 10000, source, }); break; case 4: attrSvc.addModifier(entityId, { attr: AttrId.CritDamage, op: 'Add', value: scaled / 10000, source, }); break; case 5: attrSvc.addModifier(entityId, { attr: 'cd_add', op: 'Add', value: scaled, source, }); break; case 6: attrSvc.addModifier(entityId, { attr: 'dmg_mul', op: 'Add', value: scaled - stackCount, source, }); break; default: break; } } } export function removeBondModifiers(session: BattleSession, entityId: EntityId): void { const attr = session.world.getComponent(entityId, AttributeComp); if (!attr) return; attr.modifiers = attr.modifiers.filter(m => !String(m.source ?? '').startsWith('bond_entry_')); }