英雄召唤基本完成 下一步 满3个英雄后 不再出现其他英雄

This commit is contained in:
2025-08-05 22:28:24 +08:00
parent 6f9529ada2
commit 97bba4edb7
8 changed files with 3112 additions and 1365 deletions

View File

@@ -73,6 +73,7 @@ export enum FightSet {
MORE_RC=10,//更多次数 广告获取的次数
TAL_NUM=3,//天赋数量
HEARTPOS=-240,//基地位置
HERO_MAX_NUM=3,//英雄最大数量
// ATK_TO_ATK_RATIO=0.1,
// ATK_TO_HP_RATIO=0.2,
// ATK_TO_SHIELD_RATIO=2,

View File

@@ -70,8 +70,8 @@ export class BuffComp extends Component {
}
hp_show(){
// if(this.node.getComponent(HeroViewComp).fac == 0) return
let hp=this.HeroView.hp;
let hp_max=this.HeroView.hp_max;
let hp=this.HeroView.currentHp;
let hp_max=this.HeroView.currentHpMax;
let hp_progress= hp/hp_max;
this.hp_bar.progress = hp_progress;
if(this.HeroView.is_boss) return
@@ -91,11 +91,11 @@ export class BuffComp extends Component {
let view_atk = 0 //临时buff
let view_deatk = 0 //临时debuff
if(is_hp){
info.hp=this.HeroView.hp
info.hp_max=this.HeroView.hp_max
info.hp=this.HeroView.currentHp
info.hp_max=this.HeroView.currentHpMax
}else{
info.hp=this.HeroView.hp
info.hp_max=this.HeroView.hp_max
info.hp=this.HeroView.currentHp
info.hp_max=this.HeroView.currentHpMax
for(let i=0;i<this.HeroView.BUFF_ATKS.length;i++){
view_atk += this.HeroView.BUFF_ATKS[i].value

View File

@@ -10,8 +10,9 @@ import { BattleMoveComp } from "../common/ecs/position/BattleMoveComp";
import { FriendModelComp } from "./FriendModel";
import { MasterModelComp } from "./MasterModel";
import { GameEvent } from "../common/config/GameEvent";
import { BuffAttr } from "../common/config/SkillSet";
import { BuffAttr, SkillSet } from "../common/config/SkillSet";
import { FightSet } from "../common/config/Mission";
import { Skill } from "../skills/Skill";
/** 角色实体 */
@ecs.register(`Hero`)
@@ -39,20 +40,29 @@ export class Hero extends ecs.Entity {
super.destroy();
}
/**
* 获取所有英雄槽位
* @returns 英雄槽位数组
*/
private getHeroSlots(): any[] {
return [smc.vmdata.hero1, smc.vmdata.hero2, smc.vmdata.hero3]
}
/**
* 查找可用的英雄槽位
* @returns 可用的英雄槽位对象如果没有可用槽位则返回null
*/
private findAvailableHeroSlot(): any {
return this.getHeroSlots().find(slot => slot.uuid === 0) || null
}
/** 加载角色 */
load(pos: Vec3 = Vec3.ZERO,scale:number = 1,uuid:number=1001,info:any={ap:0,hp:0,lv:1,crit:0,crit_d:0,dod:0,dod_no:false,crit_no:false},fight_pos:number=1) {
// console.log("英雄加载:",uuid,pos,scale,info)
scale = 1
if(smc.vmdata.hero1.uuid==0){
this.vmHero=smc.vmdata.hero1
}else if(smc.vmdata.hero2.uuid==0){
this.vmHero=smc.vmdata.hero2
}else if(smc.vmdata.hero3.uuid==0){
this.vmHero=smc.vmdata.hero3
}else{
// 查找空闲英雄槽位
this.vmHero = this.findAvailableHeroSlot()
if (!this.vmHero) {
console.log("[Hero] 英雄已满")
return
}
@@ -95,7 +105,7 @@ export class Hero extends ecs.Entity {
hv.hero_name= hero.name;
hv.speed =hv.ospeed = hero.speed;
hv.dis = hero.dis;
this.vmHero.cd_max=hv.cd = hv.cd_base = hero.cd
hv.cd = hv.cd_base = hero.cd
this.vmHero.hp=this.vmHero.hp_max= hv.hp = hv.hp_max = hv.hp_base=hero.hp+info.hp
hv.ap = hv.ap_base=hero.ap+info.ap;
hero.buff.forEach((buff:any)=>{
@@ -151,6 +161,8 @@ export class Hero extends ecs.Entity {
}
})
hv.atk_skill=hero.skills[0]
hv.skills=hero.skills
this.vmHero.cd_max=SkillSet[hv.skills[1]].cd
return hv
}

View File

@@ -39,6 +39,48 @@ export class HeroViewComp extends CCComp {
vmHero:any={}
/**
* 获取当前血量 - 根据阵营选择正确的变量
*/
get currentHp(): number {
if (this.fac === FacSet.HERO) {
return this.vmHero.hp || 0;
}
return this.hp;
}
/**
* 设置当前血量 - 根据阵营选择正确的变量
*/
set currentHp(value: number) {
if (this.fac === FacSet.HERO) {
this.vmHero.hp = value;
} else {
this.hp = value;
}
}
/**
* 获取最大血量 - 根据阵营选择正确的变量
*/
get currentHpMax(): number {
if (this.fac === FacSet.HERO) {
return this.vmHero.hp_max || 0;
}
return this.hp_max;
}
/**
* 设置最大血量 - 根据阵营选择正确的变量
*/
set currentHpMax(value: number) {
if (this.fac === FacSet.HERO) {
this.vmHero.hp_max = value;
} else {
this.hp_max = value;
}
}
box_group:number = BoxSet.HERO;
is_dead:boolean = false; //是否摧毁
@@ -68,6 +110,7 @@ export class HeroViewComp extends CCComp {
dis: number = 80;
at: number = 0; /** 冷却时间 */
atk_skill:number=0;
skills:any[]=[]
puncture:number=0; //穿刺敌人伤害后方敌人个数
puncture_damage:number=0; //后伤害加成
def: number = 0; //免伤
@@ -156,6 +199,7 @@ export class HeroViewComp extends CCComp {
this.as = this.getComponent(HeroSpine);
//console.log("[HeroViewComp]:hero view comp ",this.FIGHTCON)
this.on(GameEvent.EXPUP,this.exp_up,this)
this.on(GameEvent.HeroLvUp,this.to_update_lv,this)
const collider = this.node.getComponent(BoxCollider2D);
this.scheduleOnce(()=>{
if (collider) collider.enabled = true; // 先禁用
@@ -311,7 +355,6 @@ export class HeroViewComp extends CCComp {
return this.cd_base/((this.cd_buff+this.TALENT[BuffAttr.ATK_CD])/100+1)
case BuffAttr.HP:
return Math.floor(this.hp_base*(100+this.hp_buff+this.TALENT[BuffAttr.HP])/100)
}
}
@@ -326,9 +369,9 @@ export class HeroViewComp extends CCComp {
// this.update_vmdata()
break
case BuffAttr.HP:
let diff=this.check_atrr(BuffAttr.HP)-this.hp_max
this.hp_max=this.check_atrr(BuffAttr.HP)
this.hp+=diff
let diff=this.check_atrr(BuffAttr.HP)-this.currentHpMax
this.currentHpMax=this.check_atrr(BuffAttr.HP)
this.currentHp+=diff
// this.update_vmdata()
break
}
@@ -363,7 +406,7 @@ export class HeroViewComp extends CCComp {
}
add_hp_max(hp: number=0,is_num:boolean=false){
// console.log("[HeroViewComp]:add_hp_max add:",hp,this.hp_max)
// console.log("[HeroViewComp]:add_hp_max add:",hp,this.currentHpMax)
if(is_num){
this.hp_base += Math.floor(hp) ;
}else{
@@ -374,7 +417,7 @@ export class HeroViewComp extends CCComp {
}
de_hp_max(hp: number=0,is_num:boolean=true){ //最大值 只存在数值添加, 比例通过hp_buff处理
//console.log("[HeroViewComp]:de_hp_max de:",hp,this.hp_max)
//console.log("[HeroViewComp]:de_hp_max de:",hp,this.currentHpMax)
this.hp_base -= Math.floor(hp) ;
this.count_atrr(BuffAttr.HP)
// this.update_vm
@@ -383,8 +426,8 @@ export class HeroViewComp extends CCComp {
add_hp(hp: number = 0,is_num:boolean=true) {
this.BUFFCOMP.heathed();
let real_hp=0
let hp_max=Math.floor(this.hp_max*(100+this.hp_buff)/100)
let lost_hp=hp_max-this.hp
let hp_max=Math.floor(this.currentHpMax*(100+this.hp_buff)/100)
let lost_hp=hp_max-this.currentHp
if(is_num){
if(lost_hp > hp){
real_hp=Math.floor(hp);
@@ -399,7 +442,7 @@ export class HeroViewComp extends CCComp {
}
}
if(real_hp > 0){
this.hp+=real_hp;
this.currentHp+=real_hp;
this.BUFFCOMP.tooltip(TooltipTypes.health,real_hp.toFixed(0));
}
// this.update_vm
@@ -486,8 +529,8 @@ export class HeroViewComp extends CCComp {
// this.is_stop=true
break
case DebuffAttr.DEHP:
this.hp_max-=deV/100*this.hp_max
if(this.hp-this.hp_max>0) this.hp=this.hp_max
this.currentHpMax-=deV/100*this.currentHpMax
if(this.currentHp-this.currentHpMax>0) this.currentHp=this.currentHpMax
break
case DebuffAttr.DEATK: //99为具体数字 并且局内永久生效,其他为百分比
if(deC == 99){
@@ -610,11 +653,11 @@ export class HeroViewComp extends CCComp {
damage = Math.floor(damage * (1 + (FightSet.CRIT_DAMAGE+crit_d)/100))
if(this.fac==FacSet.MON) smc.vmdata.hero.power+=smc.vmdata.hero.POWER_UP+FightSet.CRIT_TO_POWER //暴击涨能量 怪物被暴击,因为只有一个英雄 直接处理
}
this.hp -= damage;
this.currentHp -= damage;
if(this.fac==FacSet.HERO) smc.vmdata.hero.power+=smc.vmdata.hero.POWER_UP+FightSet.ATKED_TO_POWER //被攻击涨能量
if(this.fac==FacSet.MON) smc.vmdata.hero.power+=smc.vmdata.hero.POWER_UP+FightSet.ATK_TO_POWER //攻击命中涨能量 因为是只有1个英雄 直接处理
if(this.hp <= 0) {
if(this.currentHp <= 0) {
if(this == null) return;
this.is_dead=true
this.BUFFCOMP.dead()
@@ -727,7 +770,7 @@ export class HeroViewComp extends CCComp {
}
// to_alive(){
// this.is_dead=false
// this.hp=this.hp_max*(100+this.hp_buff)/100
// this.currentHp=this.currentHpMax*(100+this.hp_buff)/100
// this.BUFFCOMP.vmdata_update(true)
// this.node.setPosition(HeroPos[this.fight_pos].pos)
// this.BUFFCOMP.heathed()
@@ -775,14 +818,18 @@ export class HeroViewComp extends CCComp {
// smc.vmdata.hero.next_exp=getUpExp(this.lv)
if(smc.vmdata.hero.exp >= smc.vmdata.hero.next_exp){
// console.log("[HeroViewComp]:升级")
this.to_update()
this.to_update_lv("seft",data)
oops.message.dispatchEvent(GameEvent.CanUpdateLv)
}
}
to_update(){
to_update_lv(event:string,data:any){
if(this.fac==FacSet.MON) return
console.log("[HeroViewComp]:升级",this.BUFFCOMP)
if(this.hero_uuid!=data.uuid) return
this.add_ap(HeroInfo[data.uuid].ap,true)
this.add_hp_max(HeroInfo[data.uuid].hp,true)
this.BUFFCOMP.lv_up()
// this.BUFFCOMP.tooltip(TooltipTypes.lvup)
}

View File

@@ -47,8 +47,16 @@ export class SkillConComp extends CCComp {
update(dt: number) {
if(!smc.mission.play||smc.mission.pause) return
if(this.HeroView.DEBUFF_STUN <= 0&&this.HeroView.DEBUFF_FROST <= 0) this.HeroView.at += dt;
if(this.HeroView.DEBUFF_STUN <= 0&&this.HeroView.DEBUFF_FROST <= 0) {
this.HeroView.at += dt;
this.HeroView.vmHero.cd += dt
}
if(this.HeroView.vmHero.cd > this.HeroView.vmHero.cd_max){
let sc=SkillSet[this.HeroView.skills[1]]
if(!sc) return
this.castSkill(sc,false,0)
this.HeroView.vmHero.cd = 0
}
let cd = this.count_cd(this.HeroView.cd,this.HeroView)
if (this.HeroView.is_atking &&(this.HeroView.at > cd)) {
if(this.HeroView.is_dead) return

View File

@@ -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()
}

View File

@@ -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)
}
/** 添加英雄 */