refactor(hero): 重构英雄属性同步机制和任务组件

- 在HeroAttrsComp中添加smc.updateHeroInfo调用以同步英雄数据
- 移除MissionComp中冗余的UI状态管理代码
- 在SingletonModuleComp中新增updateHeroInfo方法集中处理英雄数据同步
- 调整heroSet中英雄基础防御值为0
- 添加任务时间倒计时功能
This commit is contained in:
walkpan
2026-01-02 22:12:43 +08:00
parent a9e7b5c464
commit f5ded0d314
5 changed files with 2019 additions and 1932 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,9 @@ import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/O
import { WxCloudApi } from "../wx_clound_client_api/WxCloudApi";
import { GameEvent } from "./config/GameEvent";
import * as exp from "constants";
import { HeroAttrsComp } from "../hero/HeroAttrsComp";
import { Attrs } from "./config/HeroAttrs";
import { time } from "console";
/**
* 用远程数据覆盖本地数据(统一方法)
* @param remoteData 远程数据(云端或本地调试)
@@ -59,6 +62,7 @@ export class SingletonModuleComp extends ecs.Comp {
level:1,//关卡等级
max_mission:4,//最大关卡
coin:0,
time:15*60,//游戏时间
},
hero:{
name:'',
@@ -67,7 +71,8 @@ export class SingletonModuleComp extends ecs.Comp {
type:0,
lv:0,
exp:0,
exp_max:0,
exp_max:100,
exp_pre:0,
hp:50,
hp_max:100,
mp:50,
@@ -208,6 +213,38 @@ export class SingletonModuleComp extends ecs.Comp {
return true
}
/**
* 更新主角英雄数据到 VM
* @param heroAttrs 英雄属性组件
*/
updateHeroInfo(heroAttrs: HeroAttrsComp) {
if (!heroAttrs || !heroAttrs.is_master) return;
const h = this.vmdata.hero;
// 基础信息
h.name = heroAttrs.hero_name;
h.type = heroAttrs.type;
h.lv = heroAttrs.lv;
// 动态属性
h.hp = Math.floor(heroAttrs.hp);
h.mp = Math.floor(heroAttrs.mp);
// 计算属性
h.hp_max = Math.floor(heroAttrs.Attrs[Attrs.HP_MAX] || 0);
h.mp_max = Math.floor(heroAttrs.Attrs[Attrs.MP_MAX] || 0);
h.def = Math.floor(heroAttrs.Attrs[Attrs.DEF] || 0);
h.ap = Math.floor(heroAttrs.Attrs[Attrs.AP] || 0);
h.dis = Math.floor(heroAttrs.Attrs[Attrs.DIS] || 0);
h.speed = Math.floor(heroAttrs.Attrs[Attrs.SPEED] || 0);
h.crt = Math.floor(heroAttrs.Attrs[Attrs.CRITICAL] || 0);
h.as = Math.floor(heroAttrs.Attrs[Attrs.AS] || 0);
}
updateHeroExp(exp:number){
this.vmdata.hero.exp += exp;
this.vmdata.hero.exp_pre =Math.floor(this.vmdata.hero.exp/this.vmdata.hero.exp_max)
}
error(){
oops.gui.toast("数据处理异常,请重试或重新登录")
}

View File

@@ -126,37 +126,37 @@ export const HeroInfo: Record<number, heroInfo> = {
// 刘邦 - 领导型战士(善于用人,知人善任)
5001:{uuid:5001,name:"刘邦",path:"hk1", fac:FacSet.HERO, kind:1,as:1.5,
type:HType.warrior,lv:1,hp:200,mp:200,def:9,ap:15,dis:100,speed:120,skills:[6001,6001],
type:HType.warrior,lv:1,hp:200,mp:200,def:0,ap:15,dis:100,speed:120,skills:[6001,6001],
buff:[],tal:[],info:"楚汉争霸领袖,领导统御型战士"},
// 荆轲 - 刺客(敏捷型,高速度和暴击率)
5002:{uuid:5002,name:"荆轲",path:"hc1", fac:FacSet.HERO, kind:1,as:1.5,
type:HType.assassin,lv:1,hp:80,mp:60,def:3,ap:22,dis:120,speed:180,skills:[6002,6001],
type:HType.assassin,lv:1,hp:80,mp:60,def:0,ap:22,dis:120,speed:180,skills:[6002,6001],
buff:[],tal:[],info:"战国刺客,刺杀专精敏捷型刺客"},
// 赵武灵王 - 远程射手(胡服骑射,机动型高移动速度和远程攻击)
5005:{uuid:5005,name:"赵武灵王",path:"ha1", fac:FacSet.HERO, kind:2,as:1.5,
type:HType.remote,lv:1,hp:100,mp:80,def:6,ap:18,dis:450,speed:140,skills:[6002,6001],
type:HType.remote,lv:1,hp:100,mp:80,def:0,ap:18,dis:450,speed:140,skills:[6002,6001],
buff:[],tal:[],info:"胡服骑射改革者,机动型高远程输出"},
// 张良 - 智谋法师(运筹帷幄,智谋型法师)
5007:{uuid:5007,name:"张良",path:"hh1", fac:FacSet.HERO, kind:2,as:1.5,
type:HType.mage,lv:1,hp:88,mp:135,def:5,ap:15,dis:350,speed:100,skills:[6002,6001],
type:HType.mage,lv:1,hp:88,mp:135,def:0,ap:15,dis:350,speed:100,skills:[6002,6001],
buff:[],tal:[],info:"运筹帷幄谋士,智谋型法师"},
// 屈原 - 元素法师(离骚诗韵,元素型高魔法输出)
5008:{uuid:5008,name:"屈原",path:"hm1", fac:FacSet.HERO, kind:2,as:1.5,
type:HType.mage,lv:1,hp:85,mp:140,def:4,ap:16,dis:400,speed:90,skills:[6002,6001],
type:HType.mage,lv:1,hp:85,mp:140,def:0,ap:16,dis:400,speed:90,skills:[6002,6001],
buff:[],tal:[],info:"离骚诗韵,元素型高魔法输出"},
// 孙膑 - 谋略法师(兵法谋略,谋略型法师)
5009:{uuid:5009,name:"孙膑",path:"hm2", fac:FacSet.HERO, kind:2,as:1.5,
type:HType.mage,lv:1,hp:92,mp:135,def:6,ap:14,dis:420,speed:95,skills:[6002,6001],
type:HType.mage,lv:1,hp:92,mp:135,def:0,ap:14,dis:420,speed:95,skills:[6002,6001],
buff:[],tal:[],info:"兵法谋略,谋略型法师"},
// 萧何 - 后勤辅助(后勤保障,后勤型辅助)
5010:{uuid:5010,name:"萧何",path:"hz1", fac:FacSet.HERO, kind:2,as:1.5,
type:HType.support,lv:1,hp:115,mp:145,def:10,ap:8,dis:380,speed:105,skills:[6002,6001],
type:HType.support,lv:1,hp:115,mp:145,def:0,ap:8,dis:380,speed:105,skills:[6002,6001],
buff:[],tal:[],info:"后勤保障,后勤型辅助"},

View File

@@ -3,6 +3,7 @@ import { Attrs, AttrsType, BType, NeAttrs } from "../common/config/HeroAttrs";
import { BuffConf } from "../common/config/SkillSet";
import { HeroInfo, AttrSet } from "../common/config/heroSet";
import { HeroSkillsComp } from "./HeroSkills";
import { smc } from "../common/SingletonModuleComp";
interface talTrigger{
@@ -118,6 +119,7 @@ export class HeroAttrsComp extends ecs.Comp {
this.addBuff(buffConf);
}
}
smc.updateHeroInfo(this);
}
/*******************基础属性管理********************/
@@ -137,6 +139,7 @@ export class HeroAttrsComp extends ecs.Comp {
this.hp += addValue;
this.hp = Math.max(0, Math.min(this.hp, this.Attrs[Attrs.HP_MAX]));
this.dirty_hp = true; // ✅ 仅标记需要更新
smc.updateHeroInfo(this);
console.log(`[HeroAttrs] HP变更: ${this.hero_name}, 变化=${addValue.toFixed(1)}, ${oldHp.toFixed(1)} -> ${this.hp.toFixed(1)}`);
}
add_mp(value:number,isValue:boolean){
@@ -587,6 +590,7 @@ export class HeroAttrsComp extends ecs.Comp {
this.dirty_hp = false;
this.dirty_mp = false;
this.dirty_shield = false;
smc.updateHeroInfo(this);
}

View File

@@ -21,10 +21,6 @@ export class MissionComp extends CCComp {
// reward:number = 0;
// reward_num:number = 0;
rewards:any[]=[]
info:any=null
hp_bar:any=null
mp_bar:any=null
exp_bar:any=null
game_data:any={
exp:0,
gold:0,
@@ -37,10 +33,6 @@ export class MissionComp extends CCComp {
this.on(GameEvent.FightEnd,this.fight_end,this)
this.on(GameEvent.MissionEnd,this.mission_end,this)
this.on(GameEvent.DO_AD_BACK,this.do_ad,this)
this.info=this.node.getChildByName("info")
this.hp_bar=this.info.getChildByName("hp_bar").getChildByName("bar")
this.mp_bar=this.info.getChildByName("mp_bar").getChildByName("bar")
this.exp_bar=this.info.getChildByName("exp_bar").getChildByName("bar")
// this.on(GameEvent.CanUpdateLv,this.show_uplv_button,this)
}
protected update(dt: number): void {
@@ -49,14 +41,10 @@ export class MissionComp extends CCComp {
}
if(smc.mission.in_fight){
smc.vmdata.mission_data.fight_time+=dt
smc.vmdata.mission_data.time-=dt
}
this.update_info()
}
update_info(){
this.hp_bar.getComponent(ProgressBar).progress=smc.vmdata.hero.hp/smc.vmdata.hero.hp_max
this.mp_bar.getComponent(ProgressBar).progress=smc.vmdata.hero.mp/smc.vmdata.hero.mp_max
this.exp_bar.getComponent(ProgressBar).progress=smc.vmdata.hero.exp/smc.vmdata.hero.exp_max
}
//奖励发放
do_reward(){
// 奖励发放
@@ -144,7 +132,7 @@ export class MissionComp extends CCComp {
smc.vmdata.mission_data.in_fight=false
smc.vmdata.mission_data.fight_time=0
smc.vmdata.mission_data.level=0
smc.vmdata.mission_data.time=15*60
this.rewards=[] // 改为数组,用于存储掉落物品列表
// console.log("[MissionComp]局内数据初始化",smc.vmdata.mission_data)
}