feat(card): 新增卡牌系统核心组件与配置
- 新增 CardComp 组件用于卡牌视图展示 - 新增 CardSet 配置文件,包含卡牌类型、种类枚举和完整卡池配置 - 重构 HSkillComp 组件,优化技能调试面板布局和交互逻辑 - 更新 MissionCardComp 组件,移除旧卡牌类型依赖 - 调整 GameSet 配置文件,移除 CardType 和 CardKind 枚举 - 更新卡牌预制体结构,优化 UI 布局和组件绑定 - 新增特殊卡牌效果系统,支持抽英雄和重复使用等特殊能力 - 实现卡牌按权重抽取算法和卡池等级管理机制
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
import { _decorator, Animation, AnimationClip, Component, instantiate, Label, Node, Prefab, resources, Sprite, SpriteFrame, v3, tween, Vec3, ProgressBar, SpriteAtlas } from 'cc';
|
||||
import { oops } from 'db://oops-framework/core/Oops';
|
||||
import { getHeroList, getPreAttr, HeroConf, HeroInfo, HType, HTypeName } from '../common/config/heroSet';
|
||||
import { smc } from '../common/SingletonModuleComp';
|
||||
import { GameEvent } from '../common/config/GameEvent';
|
||||
import { _decorator, instantiate, Label, Node, Prefab, UITransform, v3, Vec3 } from 'cc';
|
||||
import { CCComp } from 'db://oops-framework/module/common/CCComp';
|
||||
import { ecs } from 'db://oops-framework/libs/ecs/ECS';
|
||||
import { SkillSet } from '../common/config/SkillSet';
|
||||
import { BoxSet, FacSet } from '../common/config/GameSet';
|
||||
import { smc } from '../common/SingletonModuleComp';
|
||||
import { Skill } from '../skill/Skill';
|
||||
import { mLogger } from '../common/Logger';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -13,46 +12,185 @@ const { ccclass, property } = _decorator;
|
||||
@ecs.register('HSkillComp', false)
|
||||
export class HSkillComp extends CCComp {
|
||||
debugMode: boolean = false;
|
||||
private readonly panelName: string = 'skill_debug_panel';
|
||||
private readonly panelWidth: number = 680;
|
||||
private readonly panelHeight: number = 1180;
|
||||
private readonly colCount: number = 4;
|
||||
private readonly cellWidth: number = 160;
|
||||
private readonly cellHeight: number = 68;
|
||||
private readonly startX: number = -240;
|
||||
private readonly startY: number = 560;
|
||||
@property(Prefab)
|
||||
btnPrefab: Prefab | null = null;
|
||||
|
||||
h_uuid:number=0
|
||||
private uiconsAtlas: SpriteAtlas | null = null;
|
||||
|
||||
private panelNode: Node | null = null;
|
||||
private buttonNodes: Node[] = [];
|
||||
private mockCasterNode: Node | null = null;
|
||||
private mockCasterView: any = null;
|
||||
private currentSkill: Skill | null = null;
|
||||
|
||||
protected onLoad(): void {
|
||||
this.ensurePanel();
|
||||
}
|
||||
|
||||
|
||||
start() {
|
||||
|
||||
this.renderSkillButtons();
|
||||
}
|
||||
|
||||
start_test(){
|
||||
this.node.active=true
|
||||
this.node.parent.getChildByName("mission_home").active=false
|
||||
start_test() {
|
||||
this.node.active = true;
|
||||
const home = this.node.parent?.getChildByName('mission_home');
|
||||
if (home) {
|
||||
home.active = false;
|
||||
}
|
||||
this.renderSkillButtons();
|
||||
}
|
||||
|
||||
end_test(){
|
||||
this.node.parent.getChildByName("mission_home").active=true
|
||||
this.node.active=false
|
||||
end_test() {
|
||||
const home = this.node.parent?.getChildByName('mission_home');
|
||||
if (home) {
|
||||
home.active = true;
|
||||
}
|
||||
this.node.active = false;
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
update_data(uuid:number){
|
||||
|
||||
update_data(uuid: number) {
|
||||
this.renderSkillButtons();
|
||||
}
|
||||
|
||||
load_hui(uuid:number){
|
||||
var path = "game/gui/hui";
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
// 将节点添加到父节点下
|
||||
this.node.addChild(node);
|
||||
// 设置节点位置
|
||||
private ensurePanel() {
|
||||
let panel = this.node.getChildByName(this.panelName);
|
||||
if (!panel) {
|
||||
panel = new Node(this.panelName);
|
||||
panel.parent = this.node;
|
||||
const transform = panel.addComponent(UITransform);
|
||||
transform.setContentSize(this.panelWidth, this.panelHeight);
|
||||
panel.setPosition(0, 640, 0);
|
||||
}
|
||||
this.panelNode = panel;
|
||||
}
|
||||
|
||||
private renderSkillButtons() {
|
||||
this.ensurePanel();
|
||||
const prefab = this.getBtnPrefab();
|
||||
if (!prefab || !this.panelNode || !this.panelNode.isValid) {
|
||||
return;
|
||||
}
|
||||
this.clearButtons();
|
||||
const skillIds = Object.keys(SkillSet).map(Number).sort((a, b) => a - b);
|
||||
skillIds.forEach((skillId, index) => {
|
||||
const btnNode = instantiate(prefab);
|
||||
btnNode.parent = this.panelNode;
|
||||
const row = Math.floor(index / this.colCount);
|
||||
const col = index % this.colCount;
|
||||
btnNode.setPosition(
|
||||
this.startX + col * this.cellWidth,
|
||||
this.startY - row * this.cellHeight,
|
||||
0
|
||||
);
|
||||
const label = btnNode.getChildByName('Label')?.getComponent(Label);
|
||||
if (label) {
|
||||
const conf = SkillSet[skillId];
|
||||
label.string = `${skillId} ${conf?.name ?? ''}`;
|
||||
}
|
||||
btnNode.on(Node.EventType.TOUCH_END, () => this.playDebugSkill(skillId), this);
|
||||
this.buttonNodes.push(btnNode);
|
||||
});
|
||||
}
|
||||
|
||||
private clearButtons() {
|
||||
this.buttonNodes.forEach(node => {
|
||||
if (!node || !node.isValid) {
|
||||
return;
|
||||
}
|
||||
node.off(Node.EventType.TOUCH_END);
|
||||
node.destroy();
|
||||
});
|
||||
this.buttonNodes.length = 0;
|
||||
}
|
||||
|
||||
private getBtnPrefab(): Prefab | null {
|
||||
if (this.btnPrefab) {
|
||||
return this.btnPrefab;
|
||||
}
|
||||
mLogger.error(this.debugMode, 'HSkillComp', '[HSkillComp] 未绑定 Btn 预制体,请在编辑器中设置 btnPrefab');
|
||||
return null;
|
||||
}
|
||||
|
||||
private getSkillParent(): Node {
|
||||
const layer = smc.map?.MapView?.scene?.entityLayer?.node?.getChildByName('SKILL');
|
||||
if (layer && layer.isValid) {
|
||||
return layer;
|
||||
}
|
||||
return this.node;
|
||||
}
|
||||
|
||||
private ensureMockCaster(parent: Node, startPos: Vec3): any {
|
||||
if (!this.mockCasterNode || !this.mockCasterNode.isValid) {
|
||||
this.mockCasterNode = new Node('debug_caster');
|
||||
this.mockCasterNode.parent = parent;
|
||||
this.mockCasterNode.setScale(v3(1, 1, 1));
|
||||
this.mockCasterNode.active = false;
|
||||
} else if (this.mockCasterNode.parent !== parent) {
|
||||
this.mockCasterNode.parent = parent;
|
||||
}
|
||||
this.mockCasterNode.setPosition(startPos);
|
||||
const mockAttrs = {
|
||||
hero_name: '技能调试器',
|
||||
ap: 100,
|
||||
critical: 0,
|
||||
critical_dmg: 50,
|
||||
freeze_chance: 0,
|
||||
stun_chance: 0,
|
||||
back_chance: 0,
|
||||
slow_chance: 0,
|
||||
puncture: 0,
|
||||
puncture_dmg: 0,
|
||||
wfuny: 0,
|
||||
fac: FacSet.HERO
|
||||
};
|
||||
const mockEntity = {
|
||||
eid: -10086,
|
||||
get: () => mockAttrs
|
||||
};
|
||||
this.mockCasterView = {
|
||||
node: this.mockCasterNode,
|
||||
box_group: BoxSet.HERO,
|
||||
ent: mockEntity
|
||||
};
|
||||
return this.mockCasterView;
|
||||
}
|
||||
|
||||
private playDebugSkill(skillId: number) {
|
||||
const conf = SkillSet[skillId];
|
||||
if (!conf) {
|
||||
return;
|
||||
}
|
||||
this.destroyCurrentSkill();
|
||||
const parent = this.getSkillParent();
|
||||
const startPos = v3(-260, -40, 0);
|
||||
const targetPos = v3(260, -40, 0);
|
||||
const caster = this.ensureMockCaster(parent, startPos);
|
||||
const skill = ecs.getEntity<Skill>(Skill);
|
||||
skill.load(startPos.clone(), parent, skillId, targetPos, caster, 0);
|
||||
this.currentSkill = skill;
|
||||
}
|
||||
|
||||
private destroyCurrentSkill() {
|
||||
if (!this.currentSkill) {
|
||||
return;
|
||||
}
|
||||
this.currentSkill.destroy();
|
||||
this.currentSkill = null;
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.node.destroy()
|
||||
this.destroyCurrentSkill();
|
||||
this.clearButtons();
|
||||
if (this.mockCasterNode && this.mockCasterNode.isValid) {
|
||||
this.mockCasterNode.destroy();
|
||||
this.mockCasterNode = null;
|
||||
}
|
||||
this.node.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user