feat(技能): 将技能卡释放逻辑移至独立组件并添加UI显示
- 新增 MissSkillsComp 组件,用于管理场景中释放的技能卡 - 将技能卡释放监听从 MissionHeroComp 移至 MissSkillsComp - 新增 SkillBoxComp 组件,负责单个技能卡的表现和触发逻辑 - 在 role_controller.prefab 中添加 miss_skill_node 节点引用 - 技能卡现在会在场景中显示图标和剩余回合信息 - 支持即时技能和持续多回合技能的不同触发机制
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import { mLogger } from "../common/Logger";
|
||||
import { _decorator, Node, Prefab } from "cc";
|
||||
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 { CardType } from "../common/config/CardSet";
|
||||
import { SkillCardList } 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)
|
||||
@@ -16,16 +16,149 @@ 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);
|
||||
}
|
||||
|
||||
start() {
|
||||
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 = SkillCardList[uuid];
|
||||
if (config) {
|
||||
this.is_instant = config.is_instant ?? true;
|
||||
this.trigger_times = config.trigger_times ?? 1;
|
||||
this.trigger_interval = config.trigger_interval ?? 0;
|
||||
this.duration_rounds = config.duration_rounds ?? 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() {
|
||||
|
||||
Reference in New Issue
Block a user