- 移除独立的 SkillCardList 配置,将技能卡属性直接集成到 CardPoolList - 更新 SkillBoxComp 和 CardComp 中技能卡配置的获取方式,改为从 CardPoolList 查找 - 统一技能卡属性命名(如 is_inst 替代 is_instant),提升配置一致性
168 lines
5.4 KiB
TypeScript
168 lines
5.4 KiB
TypeScript
import { mLogger } from "../common/Logger";
|
|
import { _decorator, Node, Prefab, Sprite, Label, Vec3, resources, SpriteAtlas } from "cc";
|
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
|
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
|
import { CardPoolList } from "../common/config/CardSet";
|
|
import { SkillSet } from "../common/config/SkillSet";
|
|
import { oops } from "db://oops-framework/core/Oops";
|
|
import { GameEvent } from "../common/config/GameEvent";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('SkillBoxComp')
|
|
@ecs.register('SkillBoxComp', false)
|
|
export class SkillBoxComp extends CCComp {
|
|
private debugMode: boolean = true;
|
|
@property({type: Node})
|
|
private icon_node:Node= null;
|
|
@property(Label)
|
|
private info_label: Label = null;
|
|
|
|
private s_uuid: number = 0;
|
|
private card_lv: number = 1;
|
|
private is_instant: boolean = true;
|
|
private trigger_times: number = 1;
|
|
private trigger_interval: number = 0;
|
|
private duration_rounds: number = 1;
|
|
|
|
private current_round: number = 0;
|
|
private current_trigger_times: number = 0;
|
|
private timer: number = 0;
|
|
private in_combat: boolean = false;
|
|
private initialized: boolean = false;
|
|
|
|
onLoad() {
|
|
oops.message.on(GameEvent.FightStart, this.onFightStart, this);
|
|
oops.message.on(GameEvent.MissionEnd, this.onMissionEnd, this);
|
|
this.node.on(GameEvent.NewWave, this.onNewWave, this);
|
|
oops.message.on(GameEvent.NewWave, this.onNewWaveGlobal, this);
|
|
}
|
|
|
|
onDestroy() {
|
|
oops.message.off(GameEvent.FightStart, this.onFightStart, this);
|
|
oops.message.off(GameEvent.MissionEnd, this.onMissionEnd, this);
|
|
this.node.off(GameEvent.NewWave, this.onNewWave, this);
|
|
oops.message.off(GameEvent.NewWave, this.onNewWaveGlobal, this);
|
|
}
|
|
|
|
init(uuid: number, card_lv: number) {
|
|
this.s_uuid = uuid;
|
|
this.card_lv = card_lv;
|
|
|
|
const config = CardPoolList.find(c => c.uuid === uuid);
|
|
if (config) {
|
|
this.is_instant = config.is_inst ?? true;
|
|
this.trigger_times = config.t_times ?? 1;
|
|
this.trigger_interval = config.t_inv ?? 0;
|
|
this.duration_rounds = config.d_rds ?? 1;
|
|
}
|
|
|
|
this.current_round = 0;
|
|
this.current_trigger_times = 0;
|
|
this.timer = 0;
|
|
this.initialized = true;
|
|
|
|
this.updateUI();
|
|
|
|
if (this.is_instant) {
|
|
// 即时起效:立即触发
|
|
this.triggerSkill();
|
|
this.current_trigger_times++;
|
|
if (this.current_trigger_times >= this.trigger_times) {
|
|
this.scheduleOnce(() => {
|
|
this.node.destroy();
|
|
}, 1.0); // 稍微延迟销毁,保证表现
|
|
}
|
|
}
|
|
}
|
|
|
|
updateUI() {
|
|
if (this.icon_node) {
|
|
const iconId = SkillSet[this.s_uuid]?.icon || `${this.s_uuid}`;
|
|
resources.load("gui/uicons", SpriteAtlas, (err, atlas) => {
|
|
if (err || !atlas) return;
|
|
const frame = atlas.getSpriteFrame(iconId);
|
|
if (frame && this.icon_node && this.icon_node.isValid) {
|
|
const sprite = this.icon_node.getComponent(Sprite) || this.icon_node.addComponent(Sprite);
|
|
sprite.spriteFrame = frame;
|
|
}
|
|
});
|
|
}
|
|
|
|
if (this.info_label) {
|
|
if (!this.is_instant) {
|
|
this.info_label.string = `${this.duration_rounds - this.current_round}回`;
|
|
} else {
|
|
this.info_label.string = "";
|
|
}
|
|
}
|
|
}
|
|
|
|
private onFightStart() {
|
|
if (!this.initialized) return;
|
|
this.in_combat = true;
|
|
|
|
if (!this.is_instant) {
|
|
this.timer = this.trigger_interval; // 确保第一次能立即或按间隔触发
|
|
this.current_trigger_times = 0;
|
|
}
|
|
}
|
|
|
|
private onNewWave() {
|
|
this.handleNewWave();
|
|
}
|
|
|
|
private onNewWaveGlobal() {
|
|
this.handleNewWave();
|
|
}
|
|
|
|
private handleNewWave() {
|
|
if (!this.initialized) return;
|
|
this.in_combat = false;
|
|
|
|
if (!this.is_instant) {
|
|
this.current_round++;
|
|
this.updateUI();
|
|
if (this.current_round >= this.duration_rounds) {
|
|
this.node.destroy();
|
|
}
|
|
}
|
|
}
|
|
|
|
private onMissionEnd() {
|
|
this.node.destroy();
|
|
}
|
|
|
|
update(dt: number) {
|
|
if (!this.initialized || !this.in_combat || this.is_instant) return;
|
|
if (!smc.mission.play || smc.mission.pause) return;
|
|
|
|
if (this.current_trigger_times < this.trigger_times) {
|
|
this.timer += dt;
|
|
if (this.timer >= this.trigger_interval) {
|
|
this.timer = 0;
|
|
this.triggerSkill();
|
|
this.current_trigger_times++;
|
|
}
|
|
}
|
|
}
|
|
|
|
private triggerSkill() {
|
|
// 使用固定的全局坐标
|
|
const targetPos = new Vec3(-340, 30, 0);
|
|
|
|
oops.message.dispatchEvent(GameEvent.TriggerSkill, {
|
|
s_uuid: this.s_uuid,
|
|
isCardSkill: true,
|
|
card_lv: this.card_lv,
|
|
targetPos: targetPos
|
|
});
|
|
}
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
}
|