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/ai/runtime/AiGemSocketStore.ts

67 lines
1.8 KiB

11 hours ago
import { GEM_SLOT_COUNT } from '../../../game/GameDataEnums';
/** 五行数量 */
const ELEMENT_COUNT = 5;
/**
* 本局 AI 宝石镶嵌存档:五行 × 4 槽。
* 开战灌入,局内只读,结束清空。
*/
export class AiGemSocketStore {
/** element(1~5) → 长度 4 的宝石 id */
private readonly _slots: number[][] = [];
constructor() {
this.clear();
}
/** 清空全部槽 */
clear(): void {
this._slots.length = 0;
for (let e = 0; e <= ELEMENT_COUNT; e++) {
this._slots[e] = [0, 0, 0, 0];
}
}
/**
* 读某五行 4 槽(副本)。
* @param element Hero.herotype 1~5
*/
getElementSlots(element: number): number[] {
const e = Math.floor(Number(element) || 0);
const out = [0, 0, 0, 0];
if (e < 1 || e > ELEMENT_COUNT) return out;
const src = this._slots[e];
for (let i = 0; i < GEM_SLOT_COUNT; i++) {
out[i] = Math.max(0, Math.floor(Number(src[i]) || 0));
}
return out;
}
/**
* 写入单槽。
* @param element 五行 1~5
* @param slot 槽 0~3
* @param gemId Weapon.id;0=空
*/
setSlot(element: number, slot: number, gemId: number): boolean {
const e = Math.floor(Number(element) || 0);
const s = Math.floor(Number(slot) || 0);
if (e < 1 || e > ELEMENT_COUNT || s < 0 || s >= GEM_SLOT_COUNT) return false;
this._slots[e][s] = Math.max(0, Math.floor(Number(gemId) || 0));
return true;
}
/** 已镶嵌槽数(gemId>0) */
countFilled(): number {
let n = 0;
for (let e = 1; e <= ELEMENT_COUNT; e++) {
const row = this._slots[e];
for (let s = 0; s < GEM_SLOT_COUNT; s++) {
if (row[s] > 0) n++;
}
}
return n;
}
}