英雄召唤基本完成 下一步 满3个英雄后 不再出现其他英雄
This commit is contained in:
@@ -10,17 +10,25 @@ import { HeroInfo } from "../common/config/heroSet";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 英雄数据接口 */
|
||||
interface HeroData {
|
||||
uuid: number;
|
||||
name: string;
|
||||
type: number; // 1 被动 0 主动
|
||||
level: number;
|
||||
quality: number;
|
||||
cd: number;
|
||||
cd_time: number;
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
/** 视图层对象 */
|
||||
@ccclass('HeroUiComp')
|
||||
@ecs.register('HeroUi', false)
|
||||
export class HeroUiComp extends CCComp {
|
||||
@property(CCString)
|
||||
hero_slot:string="skill1"
|
||||
@property(CCInteger)
|
||||
hero_slot_index:number=1
|
||||
heroUi:any=null
|
||||
skill_cd_bar_progress:any=null
|
||||
max_show:boolean=false
|
||||
heroes: HeroData[] = []
|
||||
private readonly MAX_HEROES = 3
|
||||
private readonly HERO_NODE_NAMES = ['hero1', 'hero2', 'hero3']
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
onLoad() {
|
||||
this.on(GameEvent.FightReady,this.fight_ready,this)
|
||||
@@ -29,22 +37,30 @@ export class HeroUiComp extends CCComp {
|
||||
}
|
||||
start(){
|
||||
this.fight_ready()
|
||||
|
||||
}
|
||||
|
||||
fight_ready(){
|
||||
console.log("[HeroUiComp]: fight_ready",this.node)
|
||||
this.heroUi={
|
||||
uuid:0,
|
||||
name:"hero",
|
||||
type:0, //1 被动 0 主动
|
||||
level:0,
|
||||
quality:0,
|
||||
cd:0,
|
||||
cd_time:0,
|
||||
active:false,
|
||||
this.heroes = []
|
||||
for(let i = 0; i < this.MAX_HEROES; i++) {
|
||||
this.heroes.push(this.createDefaultHero())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private createDefaultHero(): HeroData {
|
||||
return {
|
||||
uuid: 0,
|
||||
name: "hero",
|
||||
type: 0, //1 被动 0 主动
|
||||
level: 1,
|
||||
quality: 0,
|
||||
cd: 0,
|
||||
cd_time: 0,
|
||||
active: false,
|
||||
}
|
||||
}
|
||||
|
||||
update(dt: number): void {
|
||||
if(!smc.mission.play||smc.mission.pause) return
|
||||
|
||||
@@ -52,17 +68,137 @@ export class HeroUiComp extends CCComp {
|
||||
}
|
||||
|
||||
|
||||
get_hero(e:GameEvent,data:any){
|
||||
console.log("[HeroUiComp]: get_hero",data)
|
||||
let hero=HeroInfo[data.uuid]
|
||||
let icon=this.node.getChildByName("icon")
|
||||
icon.active=true
|
||||
var icon_path = "game/heros/herois"
|
||||
get_hero(e: GameEvent, data: { uuid: number }) {
|
||||
console.log("[HeroUiComp]: get_hero", data)
|
||||
|
||||
// 尝试升级现有英雄
|
||||
if (this.tryUpgradeExistingHero(data.uuid)) {
|
||||
return
|
||||
}
|
||||
|
||||
// 添加新英雄
|
||||
this.addNewHero(data)
|
||||
}
|
||||
|
||||
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
||||
const sprite = icon.getComponent(Sprite);
|
||||
sprite.spriteFrame = atlas.getSpriteFrame(hero.path);
|
||||
});
|
||||
/**
|
||||
* 尝试升级现有英雄
|
||||
* @param uuid 英雄UUID
|
||||
* @returns 是否成功升级
|
||||
*/
|
||||
private tryUpgradeExistingHero(uuid: number): boolean {
|
||||
for (let i = 0; i < this.heroes.length; i++) {
|
||||
if (this.heroes[i].uuid === uuid) {
|
||||
this.heroes[i].level++
|
||||
// 播放升级动画
|
||||
this.playCardScaleAnimation(i)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加新英雄
|
||||
* @param data 英雄数据
|
||||
*/
|
||||
private addNewHero(data: { uuid: number }) {
|
||||
const heroInfo = HeroInfo[data.uuid]
|
||||
if (!heroInfo) {
|
||||
console.error("[HeroUiComp]: Hero info not found for uuid:", data.uuid)
|
||||
return
|
||||
}
|
||||
|
||||
// 查找空闲位置
|
||||
const emptySlotIndex = this.findEmptyHeroSlot()
|
||||
if (emptySlotIndex === -1) {
|
||||
console.warn("[HeroUiComp]: No empty slot available for new hero")
|
||||
return
|
||||
}
|
||||
|
||||
// 设置英雄数据
|
||||
this.heroes[emptySlotIndex] = {
|
||||
uuid: data.uuid,
|
||||
name: heroInfo.name,
|
||||
type: heroInfo.type,
|
||||
level: 1,
|
||||
quality: heroInfo.quality,
|
||||
cd: 0,
|
||||
cd_time: 0,
|
||||
active: false,
|
||||
}
|
||||
|
||||
// 更新UI
|
||||
this.updateHeroUI(emptySlotIndex, heroInfo)
|
||||
// 播放新卡牌动画
|
||||
this.playCardScaleAnimation(emptySlotIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找空闲英雄槽位
|
||||
* @returns 空闲槽位索引,-1表示没有空闲槽位
|
||||
*/
|
||||
private findEmptyHeroSlot(): number {
|
||||
for (let i = 0; i < this.heroes.length; i++) {
|
||||
if (this.heroes[i].uuid === 0) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新英雄UI(图标和信息)
|
||||
* @param heroIndex 英雄索引
|
||||
* @param heroInfo 英雄信息
|
||||
*/
|
||||
private updateHeroUI(heroIndex: number, heroInfo: { path: string }) {
|
||||
const heroNodeName = this.HERO_NODE_NAMES[heroIndex]
|
||||
const heroNode = this.node.getChildByName(heroNodeName)
|
||||
if (!heroNode) return
|
||||
|
||||
const iconNode = heroNode.getChildByName("icon")
|
||||
if (iconNode) {
|
||||
iconNode.active = true
|
||||
this.loadHeroIcon(iconNode, heroInfo.path)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载英雄图标
|
||||
* @param iconNode 图标节点
|
||||
* @param heroPath 英雄路径
|
||||
*/
|
||||
private loadHeroIcon(iconNode: Node, heroPath: string) {
|
||||
const iconPath = "game/heros/herois"
|
||||
resources.load(iconPath, SpriteAtlas, (err: any, atlas) => {
|
||||
if (err) {
|
||||
console.error("[HeroUiComp]: Failed to load hero icon atlas:", err)
|
||||
return
|
||||
}
|
||||
const sprite = iconNode.getComponent(Sprite)
|
||||
if (sprite && atlas) {
|
||||
sprite.spriteFrame = atlas.getSpriteFrame(heroPath)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 播放卡牌缩放动画
|
||||
* @param heroIndex 英雄索引
|
||||
*/
|
||||
private playCardScaleAnimation(heroIndex: number) {
|
||||
const heroNodeName = this.HERO_NODE_NAMES[heroIndex]
|
||||
const heroNode = this.node.getChildByName(heroNodeName)
|
||||
if (!heroNode) return
|
||||
|
||||
// 停止可能存在的动画
|
||||
tween(heroNode).stop()
|
||||
|
||||
// 播放缩放动画:放大 -> 恢复原始大小
|
||||
tween(heroNode)
|
||||
.to(0.1, { scale: v3(1.2, 1.2, 1) }, { easing: 'backOut' })
|
||||
.to(0.15, { scale: v3(1, 1, 1) }, { easing: 'backOut' })
|
||||
.start()
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -20,17 +20,27 @@ export class MissionHeroCompComp extends CCComp {
|
||||
timer:Timer=new Timer(2)
|
||||
Friend_is_dead:boolean=false
|
||||
current_hero_uuid:number=0
|
||||
current_hero_num:number=-1
|
||||
heros:any=[]
|
||||
onLoad(){
|
||||
this.on(GameEvent.UseHeroCard,this.call_hero,this)
|
||||
this.on(GameEvent.ChangeATK_EQUIP_SPECIAL_ATTR,this.change_equip_qpecial_attr,this)
|
||||
this.on(GameEvent.FightReady,this.fight_ready,this)
|
||||
this.on(GameEvent.Zhaohuan,this.zhao_huan,this)
|
||||
|
||||
}
|
||||
start() {
|
||||
// this.test_call()
|
||||
}
|
||||
fight_ready(){
|
||||
this.heros=[]
|
||||
for(let i=0;i<FightSet.HERO_MAX_NUM;i++){
|
||||
this.heros.push({
|
||||
uuid:0,
|
||||
count:0,
|
||||
quality:0,
|
||||
})
|
||||
}
|
||||
this.current_hero_num=-1
|
||||
this.current_hero_uuid=0
|
||||
}
|
||||
protected update(dt: number): void {
|
||||
if(smc.mission.status != 1) return
|
||||
@@ -38,9 +48,8 @@ export class MissionHeroCompComp extends CCComp {
|
||||
|
||||
}
|
||||
|
||||
change_equip_qpecial_attr(e:GameEvent,data:any){
|
||||
|
||||
}
|
||||
|
||||
|
||||
private zhao_huan(event: string, args: any){
|
||||
console.log("[MissionHeroComp]:zhaohuan",args)
|
||||
this.addHero(args.uuid,false)
|
||||
@@ -50,14 +59,48 @@ export class MissionHeroCompComp extends CCComp {
|
||||
|
||||
|
||||
call_hero(event: string, args: any){
|
||||
// console.log("call_hero",args)
|
||||
// let fight_pos=args
|
||||
// this.timer.reset()
|
||||
// let hero_list =HeroList
|
||||
// let x=RandomManager.instance.getRandomInt(0,hero_list.length,1)
|
||||
// // let uuid=args.uuid
|
||||
// // console.log("call_hero",uuid)
|
||||
this.addHero(args.uuid,false)
|
||||
console.log("[MissionHeroComp]:call_hero",this.heros,this.current_hero_num,args)
|
||||
|
||||
// 尝试升级现有英雄
|
||||
if (this.tryUpgradeExistingHero(args.uuid)) {
|
||||
return
|
||||
}
|
||||
|
||||
// 添加新英雄
|
||||
this.addNewHero(args.uuid)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 尝试升级现有英雄
|
||||
* @param uuid 英雄UUID
|
||||
* @returns 是否成功升级
|
||||
*/
|
||||
private tryUpgradeExistingHero(uuid: number): boolean {
|
||||
for (let i = 0; i < this.heros.length; i++) {
|
||||
console.log("[MissionHeroComp]:tryUpgradeExistingHero",this.heros,i,uuid)
|
||||
if (this.heros[i].uuid === uuid) {
|
||||
this.heros[i].count++
|
||||
smc.vmdata[`hero${i+1}`].count=this.heros[i].count
|
||||
oops.message.dispatchEvent(GameEvent.HeroLvUp, { uuid: uuid })
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加新英雄到当前槽位
|
||||
* @param uuid 英雄UUID
|
||||
*/
|
||||
private addNewHero(uuid: number) {
|
||||
this.current_hero_num++
|
||||
if(this.current_hero_num >= FightSet.HERO_MAX_NUM) return
|
||||
this.current_hero_uuid = uuid
|
||||
this.heros[this.current_hero_num].uuid = uuid
|
||||
this.heros[this.current_hero_num].count = 1
|
||||
this.heros[this.current_hero_num].quality = 0
|
||||
this.addHero(uuid, false)
|
||||
}
|
||||
|
||||
/** 添加英雄 */
|
||||
|
||||
Reference in New Issue
Block a user