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

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("数据处理异常,请重试或重新登录")
}