refactor(hero): 移除英雄等级、简化配置并删除HInfoComp组件

- 删除 HInfoComp.ts 及其 meta 文件,移除英雄信息界面组件
- 从 Hero 和 Monster 类中移除 back_chance 属性设置
- 将 Hero 类中的等级初始化为固定值 1,移除从配置读取的逻辑
- 简化 heroSet.ts 配置:移除 AttrSet、getHeroList、getMonList、MonSet、HeroConf、JobUpConf 等配置项
- 优化 heroInfo 接口:将 icon、kind、lv 字段设为可选,移除已删除的配置引用
- 扩展英雄列表,新增 5008-5015 共8个英雄配置
- 移除与 smc 模块的耦合,简化英雄选择逻辑
This commit is contained in:
walkpan
2026-03-19 23:59:16 +08:00
parent b531ade090
commit b241be0314
5 changed files with 36 additions and 557 deletions

View File

@@ -1,10 +1,6 @@
import { v3 } from "cc"
import { BoxSet, FacSet } from "./GameSet"
import { smc } from "../SingletonModuleComp"
export enum AttrSet {
ATTR_MAX = 85,
}
export enum HType {
Melee = 0,
Mid = 1,
@@ -17,28 +13,6 @@ export const HTypeName ={
2:"远程",
}
//fac:FacSet.HERO
export const getHeroList = ()=>{
const filteredHeros = Object.values(HeroInfo).filter(item=>{
const facMatch = item.fac === FacSet.HERO;
return facMatch;
});
// 根据smc.heros中的数据分离拥有和未拥有的英雄
// smc.heros是一个包含英雄ID的数组如[5001, 5002]
const ownedHeros = filteredHeros.filter(item => smc.heros.includes(item.uuid));
const unownedHeros = filteredHeros.filter(item => !smc.heros.includes(item.uuid));
// 合并列表:拥有的在前,未拥有的在后
return [...ownedHeros, ...unownedHeros].map(item => item.uuid);
}
//fac:FacSet.MON
export const getMonList = ()=>{
return Object.values(HeroInfo).filter(item=>{
const facMatch = item.fac === FacSet.MON;
return facMatch ;
}).map(item=>item.uuid)
}
export const HeroPos={
0:{pos:v3(-320,BoxSet.GAME_LINE,0)},
@@ -64,20 +38,6 @@ export const resolveFormationTargetX = (fac: FacSet, type: HType): number => {
return FormationPointX[resolvedRangeType] * side;
}
export const MonSet = {
0:{pos:v3(360,BoxSet.GAME_LINE+10,0)},
1:{pos:v3(360,BoxSet.GAME_LINE-10,0)},
2:{pos:v3(360,BoxSet.GAME_LINE+10,0)},
3:{pos:v3(360,BoxSet.GAME_LINE-10,0)},
4:{pos:v3(360,BoxSet.GAME_LINE+10,0)},
5:{pos:v3(360,BoxSet.GAME_LINE-10,0)},
6:{pos:v3(360,BoxSet.GAME_LINE+10,0)},
7:{pos:v3(360,BoxSet.GAME_LINE-10,0)},
8:{pos:v3(360,BoxSet.GAME_LINE+10,0)},
9:{pos:v3(360,BoxSet.GAME_LINE-10,0)},
10:{pos:v3(360,BoxSet.GAME_LINE+10,0)},
11:{pos:v3(360,BoxSet.GAME_LINE-10,0)},
}
export enum MonStart {
SLINE_1=140, //上线y
@@ -88,35 +48,6 @@ export enum MonStart {
START_I=90, //x轴间隔
}
export enum HeroConf{
COST=0,
MAX_HP=500,
MAX_MP=100,
MAX_AP=200,
MAX_DEF=100,
}
export const getPreAttr = (uuid:number)=>{
let hp=HeroInfo[uuid].hp/HeroConf.MAX_HP
let ap=HeroInfo[uuid].ap/HeroConf.MAX_AP
return {hp:hp,ap:ap,}
}
export enum HRegen {
HP=0.5
}
/**
* 不同职业升级属性加成配置
* 战士:高血量成长,低攻击成长
* 远程:低血量成长,高攻击成长
* 法师:低血量成长,高攻击成长
* 辅助:中血量成长,中攻击成长
* 刺客:极低血量成长,极高攻击成长
*/
export const JobUpConf: Record<HType, { hp: number; ap: number; def: number }> = {
[HType.Melee]: { hp: 50, ap: 5, def: 2 },
[HType.Mid]: { hp: 30, ap: 6, def: 1 },
[HType.Long]: { hp: 25, ap: 7, def: 1 },
};
/**
* 英雄/怪物基础信息接口
@@ -124,14 +55,13 @@ export const JobUpConf: Record<HType, { hp: number; ap: number; def: number }> =
export interface heroInfo {
uuid: number; // 唯一标识英雄5000段怪物5200段
name: string; // 显示名称
icon: string; // 图标名称(对应美术资源名)
icon?: string; // 图标名称(对应美术资源名)
path: string; // 资源路径(对应美术资源名)
fac: FacSet; // 阵营FacSet.HERO 或 FacSet.MON
kind: number; // 未使用
kind?: number; // 未使用
as: number; // 攻击间隔(越小越快)
ss:number; // 技能间隔
type: HType; // 攻击定位(近战/中程/远程)
lv: number; // 初始等级
hp: number; // 生命值上限
ap: number; // 攻击力
// dis: number; // 攻击距离(像素)
@@ -140,67 +70,57 @@ export interface heroInfo {
info: string; // 描述文案
}
export const CanSelectHeros: Record<number, number[]> = {
1: [5001, 5002],
2: [5003],
3: [5004],
4: [5005],
5: [5006],
6: [5007],
// 默认全开(或根据需要留空)
99: [5001, 5002, 5003, 5004, 5005, 5006, 5007]
};
export const HeroInfo: Record<number, heroInfo> = {
// ========== 英雄角色 ==========
5001:{uuid:5001,name:"盾战士",icon:"1001",path:"hk1", fac:FacSet.HERO, kind:1,as:1,ss:5,
type:HType.Melee,lv:1,hp:300,ap:25,speed:120,skills:[6001,6004],info:"盾战士"},
5001:{uuid:5001,name:"盾战士",path:"hk1", fac:FacSet.HERO, as:1,ss:5,type:HType.Melee,hp:300,ap:25,speed:120,skills:[6001,6004],info:""},
5002:{uuid:5002,name:"奥术法师",icon:"1001",path:"hm2", fac:FacSet.HERO, kind:2,as:1,ss:5,
type:HType.Long,lv:1,hp:150,ap:40,speed:95,skills:[6003,6101],info:"奥术法师"},
5002:{uuid:5002,name:"奥术法师",path:"hm2", fac:FacSet.HERO, as:1,ss:5,type:HType.Long,hp:150,ap:40,speed:95,skills:[6003,6101],info:""},
5003:{uuid:5003,name:"射手",icon:"1001",path:"ha1", fac:FacSet.HERO, kind:2,as:1,ss:5,
type:HType.Long,lv:1,hp:180,ap:30,speed:140,skills:[6005,6008],info:"射手"},
5003:{uuid:5003,name:"射手",path:"ha1", fac:FacSet.HERO, as:1,ss:5,type:HType.Long,hp:180,ap:30,speed:140,skills:[6005,6008],info:""},
5005:{uuid:5005,name:"牧师",icon:"1001",path:"hh1", fac:FacSet.HERO, kind:2,as:1,ss:5,
type:HType.Long,lv:1,hp:160,ap:25,speed:100,skills:[6003,6100],info:"牧师"},
5005:{uuid:5005,name:"牧师",path:"hh1", fac:FacSet.HERO, as:1,ss:5,type:HType.Long,hp:160,ap:25,speed:100,skills:[6003,6100],info:""},
5004:{uuid:5004,name:"火焰法师",icon:"1001",path:"hm1", fac:FacSet.HERO, kind:2,as:1,ss:5,
type:HType.Long,lv:1,hp:150,ap:45,speed:90,skills:[6003,6101],info:"火焰法师"},
5004:{uuid:5004,name:"火焰法师",path:"hm1", fac:FacSet.HERO, as:1,ss:5,type:HType.Long,hp:150,ap:45,speed:90,skills:[6003,6101],info:""},
5006:{uuid:5006,name:"召唤法师",icon:"1001",path:"hz1", fac:FacSet.HERO, kind:2,as:1,ss:5,
type:HType.Long,lv:1,hp:200,ap:20,speed:105,skills:[6003,6101],info:"召唤法师"},
5006:{uuid:5006,name:"召唤法师",path:"hz1", fac:FacSet.HERO, as:1,ss:5,type:HType.Long,hp:200,ap:20,speed:105,skills:[6003,6101],info:""},
5007:{uuid:5007,name:"刺客",icon:"1001",path:"hc1", fac:FacSet.HERO, kind:1,as:1,ss:5,
type:HType.Melee,lv:1,hp:140,ap:50,speed:180,skills:[6001,6004],info:"刺客"},
5007:{uuid:5007,name:"刺客",path:"hc1", fac:FacSet.HERO, as:1,ss:5,type:HType.Melee,hp:140,ap:50,speed:180,skills:[6001,6004],info:""},
5008:{uuid:5008,name:"圣骑士",path:"", fac:FacSet.HERO, as:1,ss:5,type:HType.Melee,hp:340,ap:22,speed:115,skills:[6001,6201],info:""},
5009:{uuid:5009,name:"游侠",path:"", fac:FacSet.HERO, as:1,ss:5,type:HType.Long,hp:170,ap:32,speed:145,skills:[6002,6106],info:""},
5010:{uuid:5010,name:"寒霜术士",path:"", fac:FacSet.HERO, as:1,ss:5,type:HType.Long,hp:160,ap:36,speed:105,skills:[6005,6107],info:""},
5011:{uuid:5011,name:"炎爆法师",path:"", fac:FacSet.HERO, as:1,ss:5,type:HType.Long,hp:155,ap:42,speed:95,skills:[6007,6108],info:""},
5012:{uuid:5012,name:"战地医师",path:"", fac:FacSet.HERO, as:1,ss:5,type:HType.Mid,hp:220,ap:24,speed:120,skills:[6004,6204],info:""},
5013:{uuid:5013,name:"守护祭司",path:"", fac:FacSet.HERO, as:1,ss:5,type:HType.Mid,hp:240,ap:20,speed:110,skills:[6006,6203],info:""},
5014:{uuid:5014,name:"风行剑士",path:"", fac:FacSet.HERO, as:1,ss:5,type:HType.Melee,hp:210,ap:38,speed:170,skills:[6001,6103],info:""},
5015:{uuid:5015,name:"秘法贤者",path:"", fac:FacSet.HERO, as:1,ss:5,type:HType.Long,hp:175,ap:34,speed:100,skills:[6003,6207],info:""},
// 1. 基础近战型
5201:{uuid:5201,name:"兽人战士",icon:"1001",path:"mo1", fac:FacSet.MON, kind:1,as:3.0,ss:10,
type:HType.Melee,lv:1,hp:60,ap:8,speed:180,skills:[6001,6003],info:"标准炮灰确保英雄能完成3次普攻积累天赋计数"},
5201:{uuid:5201,name:"兽人战士",path:"mo1", fac:FacSet.MON, as:3.0,ss:10,type:HType.Melee,hp:60,ap:8,speed:180,skills:[6001,6003],info:""},
// 2. 快速突击型
5301:{uuid:5301,name:"兽人斥候",icon:"1001",path:"mo1", fac:FacSet.MON, kind:1,as:1.2,ss:10,
type:HType.Melee,lv:1,hp:40,ap:12,speed:400,skills:[6001,6003],info:"快速突击:极高移速贴脸,检测护盾(7102)刷新率"},
5301:{uuid:5301,name:"兽人斥候",path:"mo1", fac:FacSet.MON, as:1.2,ss:10,type:HType.Melee,hp:40,ap:12,speed:400,skills:[6001,6003],info:""},
// 3. 重型坦克型
5401:{uuid:5401,name:"兽人卫士",icon:"1001",path:"mo3", fac:FacSet.MON, kind:1,as:5.0,ss:10,
type:HType.Melee,lv:1,hp:200,ap:15,speed:60,skills:[6001,6003],info:"重型坦克:数值墙,检测玩家破甲(7008)与持续输出"},
5401:{uuid:5401,name:"兽人卫士",path:"mo3", fac:FacSet.MON, as:5.0,ss:10,type:HType.Melee,hp:200,ap:15,speed:60,skills:[6001,6003],info:""},
// 4. 远程骚扰型
5501:{uuid:5501,name:"兽人射手",icon:"1001",path:"mo1", fac:FacSet.MON, kind:1,as:3.0,ss:10,
type:HType.Long,lv:1,hp:50,ap:10,speed:90,skills:[6001,6003],info:"远程骚扰:跨屏打击,迫使阵地分散或移动英雄"},
5501:{uuid:5501,name:"兽人射手",path:"mo1", fac:FacSet.MON, as:3.0,ss:10,type:HType.Long,hp:50,ap:10,speed:90,skills:[6001,6003],info:""},
// 5. 特殊机制型
5601:{uuid:5601,name:"兽人自爆兵",icon:"1001",path:"mo1", fac:FacSet.MON, kind:1,as:3.0,ss:10,
type:HType.Melee,lv:1,hp:80,ap:200,speed:220,skills:[6001,6003],info:"特殊机制:极端伤害,漏怪即秒杀,检测减伤(7103)"},
5602:{uuid:5602,name:"兽人召唤师",icon:"1001",path:"mo1", fac:FacSet.MON, kind:1,as:3.0,ss:10,
type:HType.Melee,lv:1,hp:150,ap:10,speed:100,skills:[6001,6003],info:"战术目标:持续召唤小怪,检测英雄大招清场频率"},
5603:{uuid:5603,name:"兽人祭司",icon:"1001",path:"mo1", fac:FacSet.MON, kind:1,as:3.0,ss:10,
type:HType.Melee,lv:1,hp:150,ap:10,speed:105,skills:[6001,6003],info:"战术目标:为怪群回血,检测玩家沉默(7006)覆盖率"},
5604:{uuid:5604,name:"兽人图腾师",icon:"1001",path:"mo1", fac:FacSet.MON, kind:1,as:3.0,ss:10,
type:HType.Melee,lv:1,hp:150,ap:10,speed:110,skills:[6001,6003],info:"战术目标:提供加速光环,改变怪群推进节奏"},
5601:{uuid:5601,name:"兽人自爆兵",path:"mo1", fac:FacSet.MON, as:3.0,ss:10,type:HType.Melee,hp:80,ap:200,speed:220,skills:[6001,6003],info:""},
5602:{uuid:5602,name:"兽人召唤师",path:"mo1", fac:FacSet.MON, as:3.0,ss:10,type:HType.Melee,hp:150,ap:10,speed:100,skills:[6001,6003],info:""},
5603:{uuid:5603,name:"兽人祭司",path:"mo1", fac:FacSet.MON, as:3.0,ss:10,type:HType.Melee,hp:150,ap:10,speed:105,skills:[6001,6003],info:""},
5604:{uuid:5604,name:"兽人图腾师",path:"mo1", fac:FacSet.MON, as:3.0,ss:10,type:HType.Melee,hp:150,ap:10,speed:110,skills:[6001,6003],info:""},
// 6. 精英/BOSS型
5701:{uuid:5701,name:"兽人首领(BOSS)",icon:"1001",path:"mo4", fac:FacSet.MON, kind:1,as:2.5,ss:10,
type:HType.Melee,lv:3,hp:2000,ap:60,speed:120,skills:[6002,6004],info:"终极考验极高HP检测大招重置与辐射协同输出"},
5701:{uuid:5701,name:"兽人首领(BOSS)",path:"mo4", fac:FacSet.MON, as:2.5,ss:10,type:HType.Melee,hp:2000,ap:60,speed:120,skills:[6002,6004],info:""},
};

View File

@@ -67,7 +67,7 @@ export class Hero extends ecs.Entity {
// 设置 Model 层属性(数据相关)
model.hero_uuid = uuid;
model.hero_name = hero.name;
model.lv = hero.lv ? hero.lv : 1;
model.lv = 1
model.type = hero.type;
model.fac = FacSet.HERO;
// 只有主角才挂载天赋组件
@@ -89,7 +89,6 @@ export class Hero extends ecs.Entity {
// 初始化 buff/debuff 系统
model.initAttrs();
model.back_chance=FightSet.BACK_CHANCE
this.add(hv);
oops.message.dispatchEvent(GameEvent.MasterCalled,{uuid:uuid})
const move = this.get(MoveComp);

View File

@@ -143,7 +143,6 @@ export class Monster extends ecs.Entity {
}
model.a_cd_max=hero.as
model.s_cd_max=hero.ss
model.back_chance=FightSet.BACK_CHANCE
// ✅ 初始化技能数据(迁移到 HeroSkillsComp
if(hero.skills[0]) model.atk_id=hero.skills[0]
if(hero.skills[1]) model.skill_id=hero.skills[1]

View File

@@ -1,430 +0,0 @@
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 { CCComp } from 'db://oops-framework/module/common/CCComp';
import { ecs } from 'db://oops-framework/libs/ecs/ECS';
import { SkillSet } from '../common/config/SkillSet';
import { mLogger } from '../common/Logger';
const { ccclass, property } = _decorator;
@ccclass('HInfoComp')
@ecs.register('HInfoComp', false)
export class HInfoComp extends CCComp {
debugMode: boolean = false;
h_uuid:number=0
private uiconsAtlas: SpriteAtlas | null = null;
name_node:any=null
type_node:any=null
ap_node:any=null
hp_node:any=null
def_node:any=null
mp_node:any=null
skill1_node:any=null
skill2_node:any=null
// 重新定义节点映射,使名称更清晰
// 当前显示的英雄节点数组7个位置
heroNodes: (Node | null)[] = [null, null, null, null, null, null, null];
// 英雄位置定义
hero_pos:any={
0:v3(500,0,0), // 不在屏幕内
1:v3(500,0,0),
2:v3(250,0,0),
3:v3(0,-30,0),
4:v3(-250,0,0),
5:v3(-500,0,0),
6:v3(-500,0,0), // 不在屏幕内
}
// 动画锁定标志:防止快速点击导致的动画冲突
private isMoving: boolean = false;
// 保存待处理的setTimeout句柄用于取消前一个异步操作
private moveTimeoutId: any = null;
protected onLoad(): void {
// this.on(GameEvent.MissionStart,this.mission_start,this)
}
// 位置索引常量
private static center_pos = 3;
/**
* 根据位置索引获取英雄缩放值
* @param posIndex 位置索引 (0-6)
* @returns Vec3 缩放向量
*/
private getHeroScale(posIndex: number): Vec3 {
switch(posIndex) {
case 2:
case 4:
return v3(-2.2, 2.2, 1); // 2、4位置1.5倍缩放
case 3:
return v3(-2.5, 2.5, 1); // 3位置中心1.5倍缩放
default:
return v3(-2.2, 2.2, 1); // 其他位置1.8倍缩放
}
}
start() {
this.name_node=this.node.getChildByName("hname").getChildByName("name")
this.type_node=this.node.getChildByName("hname").getChildByName("type")
this.hp_node=this.node.getChildByName("info").getChildByName("base").getChildByName("bgs").getChildByName("hp")
this.mp_node=this.node.getChildByName("info").getChildByName("base").getChildByName("bgs").getChildByName("mp")
this.ap_node=this.node.getChildByName("info").getChildByName("base").getChildByName("bgs").getChildByName("ap")
this.def_node=this.node.getChildByName("info").getChildByName("base").getChildByName("bgs").getChildByName("def")
this.skill1_node=this.node.getChildByName("info").getChildByName("base").getChildByName("skills").getChildByName("skill1")
this.skill2_node=this.node.getChildByName("info").getChildByName("base").getChildByName("skills").getChildByName("skill2")
this.h_uuid=smc.fight_hero
this.update_data(this.h_uuid)
this.load_all_hero(this.h_uuid)
this.showInfo()
this.close_buy()
this.close_ranks()
}
update(deltaTime: number) {
}
update_data(uuid:number){
this.h_uuid=uuid
let skill1=SkillSet[HeroInfo[uuid].skills[0]]
let skill2=SkillSet[HeroInfo[uuid].skills[1]]
this.skill1_node.getChildByName("info").getChildByName("Label").getComponent(Label).string=skill1.info
this.skill1_node.getChildByName("info").getChildByName("name").getComponent(Label).string=skill1.name
this.skill2_node.getChildByName("info").getChildByName("Label").getComponent(Label).string=skill2.info
this.skill2_node.getChildByName("info").getChildByName("name").getComponent(Label).string=skill2.name
this.name_node.getComponent(Label).string=HeroInfo[uuid].name
this.type_node.getComponent(Label).string=HTypeName[HeroInfo[uuid].type]
this.ap_node.getChildByName("num").getComponent(Label).string=HeroInfo[uuid].ap.toString()
this.hp_node.getChildByName("num").getComponent(Label).string=HeroInfo[uuid].hp.toString()
let bar_num=getPreAttr(uuid)
this.ap_node.getChildByName("bar").getComponent(ProgressBar).progress=bar_num.ap
this.hp_node.getChildByName("bar").getComponent(ProgressBar).progress=bar_num.hp
// 更新技能图标
this.updateSkillIcon(this.skill1_node, skill1.icon);
this.updateSkillIcon(this.skill2_node, skill2.icon);
}
/**
* 更新技能图标
* @param node 技能节点
* @param iconId 图标ID
*/
private updateSkillIcon(node: Node, iconId: string) {
if (!node || !iconId) return;
mLogger.log(this.debugMode, 'HInfoComp', "iconId",iconId)
const iconNode = node.getChildByName("icon");
mLogger.log(this.debugMode, 'HInfoComp', "iconNode",iconNode)
if (!iconNode) return;
const sprite = iconNode.getComponent(Sprite);
mLogger.log(this.debugMode, 'HInfoComp', "sprite",sprite)
if (!sprite) return;
if (this.uiconsAtlas) {
mLogger.log(this.debugMode, 'HInfoComp', "this.uiconsAtlas",this.uiconsAtlas)
const frame = this.uiconsAtlas.getSpriteFrame(iconId);
if (frame) {
sprite.spriteFrame = frame;
}
} else {
// 加载图集
resources.load("gui/uicons", SpriteAtlas, (err, atlas) => {
if (err) {
mLogger.log(this.debugMode, 'HInfoComp', "[HInfoComp] Failed to load uicons atlas", err);
return;
}
this.uiconsAtlas = atlas;
mLogger.log(this.debugMode, 'HInfoComp', "atlas",atlas)
const frame = atlas.getSpriteFrame(iconId);
if (frame) {
sprite.spriteFrame = frame;
}
});
}
}
load_all_hero(uuid:number){
// 清除之前的英雄节点
this.claear_hero();
// 获取英雄列表(优先显示拥有的英雄)
let heros = getHeroList();
let currentIndex = heros.indexOf(uuid);
// 载入7个英雄节点当前英雄及前后各3个
for(let i = 0; i < 7; i++) {
// 计算索引位置(考虑循环)
let indexOffset = i - 3; // -3, -2, -1, 0, 1, 2, 3
let heroIndex = currentIndex + indexOffset;
// 处理循环边界
if(heroIndex < 0) {
heroIndex = heros.length + heroIndex;
} else if(heroIndex >= heros.length) {
heroIndex = heroIndex - heros.length;
}
// 获取英雄UUID
let heroUuid = heros[heroIndex];
// 载入英雄预制体并设置位置
this.heroNodes[i] = this.load_hui(heroUuid, i);
// 添加初始缩放动画,根据位置设置不同的缩放值
if (this.heroNodes[i]) {
let targetScale = this.getHeroScale(i);
tween(this.heroNodes[i])
.to(0.2, { scale: targetScale })
.start();
}
}
this.show_lock()
}
load_hui(uuid:number, pos_index: number){
var path = "game/gui/hui";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
// 将节点添加到父节点下
this.node.getChildByName("hero").addChild(node);
// 设置节点位置
node.setPosition(this.hero_pos[pos_index]);
// node.setSiblingIndex(0);
// 根据位置设置不同的缩放值
node.setScale(this.getHeroScale(pos_index));
// 加载并播放动画
let anm_path=HeroInfo[uuid].path;
resources.load("game/heros/hero/"+anm_path+"/idle", AnimationClip, (err, clip) => {
if (!err && clip) {
let animComponent = node.getComponent(Animation);
if(animComponent) {
animComponent.addClip(clip);
animComponent.play("idle");
}
} else {
mLogger.log(this.debugMode, 'HInfoComp', ` Failed to load animation for hero ${uuid}`, err);
}
});
return node;
}
mission_start(){
this.claear_hero()
}
is_own(){
return smc.heros.includes(this.h_uuid)
}
show_lock(){
this.node.getChildByName("buy").active=!this.is_own()
}
showInfo(){
this.node.getChildByName("info").active=smc.data.showInfo
this.node.getChildByName("hname").getChildByName("more").getChildByName("no").active=smc.data.showInfo
}
btnShowInfo(){
smc.data.showInfo=!smc.data.showInfo
this.showInfo()
}
claear_hero(){
for (let i = 0; i < this.heroNodes.length; i++) {
if (this.heroNodes[i]) {
this.heroNodes[i].destroy();
this.heroNodes[i] = null;
}
}
}
next_hero(){
// 检查是否正在动画中,防止快速点击导致的冲突
if (this.isMoving) return;
// 获取英雄列表(优先显示拥有的英雄)
let heros = getHeroList();
let index = heros.indexOf(this.h_uuid);
index++;
if(index == heros.length) index = 0;
let nextHero = heros[index];
// 更新数据
this.h_uuid = nextHero;
this.update_data(nextHero);
// 执行平滑移动动画
this.moveHeroesRight();
this.show_lock()
}
prev_hero(){
// 检查是否正在动画中,防止快速点击导致的冲突
if (this.isMoving) return;
// 获取英雄列表(优先显示拥有的英雄)
let heros = getHeroList();
let index = heros.indexOf(this.h_uuid);
index--;
if(index == -1) index = heros.length - 1;
let prevHero = heros[index];
// 更新数据
this.h_uuid = prevHero;
this.update_data(prevHero);
// 执行平滑移动动画
this.moveHeroesLeft();
this.show_lock()
}
show_buy(){
this.node.getChildByName("unlock").active=true
}
close_buy(){
this.node.getChildByName("unlock").active=false
}
show_ranks(){
this.node.getChildByName("ranks").active=true
}
close_ranks(){
this.node.getChildByName("ranks").active=false
}
buy_hero(){
mLogger.log(this.debugMode, 'HInfoComp', "buy_hero",this.h_uuid)
if(smc.data.gold < HeroConf.COST) {
oops.gui.toast("金币不足")
return
}
smc.addHero(this.h_uuid)
this.load_all_hero(this.h_uuid)
this.show_lock()
this.close_buy()
}
moveHeroesLeft() {
// 取消前一个待处理的异步操作
if (this.moveTimeoutId !== null) {
clearTimeout(this.moveTimeoutId);
}
// 设置动画锁定
this.isMoving = true;
// 在动画开始前直接销毁hero_pos[6]上的节点
mLogger.log(this.debugMode, 'HInfoComp', "hero_pos[6]",this.hero_pos[6])
if (this.heroNodes[6]) {
this.heroNodes[6].destroy();
this.heroNodes[6] = null;
}
// 移动所有现有节点向左除了已销毁的heroNodes[6]
for (let i = 0; i < 6; i++) {
if (this.heroNodes[i]) {
mLogger.log(this.debugMode, 'HInfoComp', "i",i)
// 计算目标位置:向左移动
let targetPos = this.hero_pos[i + 1];
// 使用Tween执行平滑移动和缩放动画
let targetScale = this.getHeroScale(i + 1);
tween(this.heroNodes[i])
.to(0.2, { position: targetPos, scale: targetScale })
.start();
}
}
// 延迟重排数组和创建新节点,等待动画完成
this.moveTimeoutId = setTimeout(() => {
// 移动数组元素(向后平移)
for (let i = 6; i > 0; i--) {
mLogger.log(this.debugMode, 'HInfoComp', "i",i)
this.heroNodes[i] = this.heroNodes[i - 1];
}
// 创建新节点放在hero_pos[0]位置
let heros = getHeroList();
mLogger.log(this.debugMode, 'HInfoComp', "heros",heros)
let currentIndex = heros.indexOf(this.h_uuid);
let newIndex = currentIndex - 3; // 新的最左侧英雄索引
// 处理循环边界
if (newIndex < 0) {
newIndex = heros.length + newIndex;
}
this.heroNodes[0] = this.load_hui(heros[newIndex], 0);
// 确保新创建的节点使用正确的缩放值
if (this.heroNodes[0]) {
mLogger.log(this.debugMode, 'HInfoComp', "this.heroNodes[0]",this.heroNodes[0])
this.heroNodes[0].setScale(this.getHeroScale(0));
}
// 动画完成,解除锁定
this.isMoving = false;
this.moveTimeoutId = null;
}, 200); // 与动画时间保持一致
}
moveHeroesRight() {
// 取消前一个待处理的异步操作
if (this.moveTimeoutId !== null) {
clearTimeout(this.moveTimeoutId);
}
// 设置动画锁定
this.isMoving = true;
// 在动画开始前直接销毁hero_pos[0]上的节点
if (this.heroNodes[0]) {
this.heroNodes[0].destroy();
this.heroNodes[0] = null;
}
// 移动所有现有节点向右除了已销毁的heroNodes[0]
for (let i = 1; i < this.heroNodes.length; i++) {
if (this.heroNodes[i]) {
// 计算目标位置:向右移动
let targetPos = this.hero_pos[i - 1];
// 使用Tween执行平滑移动和缩放动画
let targetScale = this.getHeroScale(i - 1);
tween(this.heroNodes[i])
.to(0.2, { position: targetPos, scale: targetScale })
.start();
}
}
// 延迟重排数组和创建新节点,等待动画完成
this.moveTimeoutId = setTimeout(() => {
// 移动数组元素(向前平移)
for (let i = 0; i < 6; i++) {
this.heroNodes[i] = this.heroNodes[i + 1];
}
// 创建新节点放在hero_pos[6]位置
let heros = getHeroList();
let currentIndex = heros.indexOf(this.h_uuid);
let newIndex = currentIndex + 3; // 新的最右侧英雄索引
// 处理循环边界
if (newIndex >= heros.length) {
newIndex = newIndex - heros.length;
}
this.heroNodes[6] = this.load_hui(heros[newIndex], 6);
// 确保新创建的节点使用正确的缩放值
if (this.heroNodes[6]) {
this.heroNodes[6].setScale(this.getHeroScale(6));
}
// 动画完成,解除锁定
this.isMoving = false;
this.moveTimeoutId = null;
}, 200); // 与动画时间保持一致
}
reset() {
this.node.destroy()
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "f8dd2383-61ab-4cf9-9879-0d0fe2cd6c2f",
"files": [],
"subMetas": {},
"userData": {}
}