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/debug/GmBattlePreset.ts

98 lines
3.5 KiB

import { TableNames } from '../../game/ConfigTableData';
import type { Player } from '../../game/Player';
import type { SkillPickApplier } from '../skill/SkillPickApplier';
import { WeaponComposeConfigProvider } from '../bag/WeaponComposeConfigProvider';
type GmSkillEntry = number | { id?: number };
/** GM 调试:开战前 gg.game.playerSkillIdArray → Player.selectedSkills(词条表已删,仅记录) */
export function applyGmPresetSkills(player: Player, applier: SkillPickApplier): number {
const raw = gg.game.playerSkillIdArray as GmSkillEntry[];
if (!raw?.length) return 0;
let applied = 0;
for (const entry of raw) {
const skillId = typeof entry === 'number' ? entry : entry?.id;
if (!skillId) continue;
const row = gg.data.table.getTableData<ITableSkill>(TableNames.Skill, skillId);
if (!row || !player.addSelectedSkill(row)) continue;
applied++;
}
if (applied > 0) {
applier.materializePlayerSkillsToTowers(player.playerId, player);
}
return applied;
}
/** GM 是否配置了预设词条(开战前写入 playerSkillIdArray) */
export function hasGmPresetSkills(): boolean {
return (gg.game.playerSkillIdArray?.length ?? 0) > 0;
}
/** GM 是否配置了预设武器(开战前写入 playerWeaponIdArray) */
export function hasGmPresetWeapons(): boolean {
return (gg.game.playerWeaponIdArray?.length ?? 0) > 0;
}
/**
* PopGM 勾选的 Hero → 按勾选顺序展开为 Text 队列(单字按 group 顺序)。
* 每次背包刷新优先从队首取字,取完后走正常刷新逻辑。
*/
export function buildGmWeaponPresetQueue(): number[] {
const weapon1Ids = gg.game.playerWeaponIdArray;
if (!weapon1Ids?.length) return [];
const provider = WeaponComposeConfigProvider.instance;
provider.load();
const queue: number[] = [];
for (const w1Id of weapon1Ids) {
for (const w2Id of provider.getWeapon1Group(w1Id)) {
const id = Number(w2Id);
if (Number.isFinite(id) && id > 0) {
queue.push(id);
}
}
}
return queue;
}
/**
* GM:解析 AI Battlebuff.id 列表(逗号/顿号/空格分隔);空或 0 表示关闭覆盖。
* @param raw 输入框字符串
* @param expectType 1=主动 2=被动
* @returns id 列表;关闭覆盖时 null
*/
export function parseGmAiBattleBuffIds(raw: string, expectType: 1 | 2): number[] | null {
const trimmed = String(raw ?? '').trim();
if (!trimmed || trimmed === '0') return null;
const ids: number[] = [];
const parts = trimmed.split(/[,|,、\s]+/);
for (let i = 0; i < parts.length; i++) {
const token = parts[i].trim();
if (!token) continue;
const id = Math.floor(Number(token));
if (!Number.isFinite(id) || id <= 0) continue;
let dup = false;
for (let j = 0; j < ids.length; j++) {
if (ids[j] === id) {
dup = true;
break;
}
}
if (dup) continue;
const row = gg.data.table.getTableData<ITableBattlebuff>(TableNames.Battlebuff, id);
if (!row) {
console.log('[GM] Battlebuff 缺失', id);
continue;
}
if (Math.floor(Number(row.type) || 0) !== expectType) {
console.log('[GM] Battlebuff type 不符', id, row.type, 'expect', expectType);
continue;
}
ids.push(id);
}
if (ids.length <= 0) return null;
return ids;
}