refactor(hero): 移除天赋系统和相关属性,简化英雄架构
- 删除 SCDSystem、HeroAttrSystem 等独立系统,将功能整合到现有组件 - 移除 TalComp 天赋组件及相关配置(TalSet、AttrSet、CardSet) - 清理 HeroAttrs 中未使用的属性枚举,保留核心战斗属性 - 简化 Hero 实体创建逻辑,不再为主角挂载天赋组件 - 移除 SingletonModuleComp 中与天赋、经验、收集相关的数据管理
This commit is contained in:
@@ -5,12 +5,7 @@ import { GameMap } from "../map/GameMap";
|
||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
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, GameScoreStats } from "./config/HeroAttrs";
|
||||
import { count, time } from "console";
|
||||
import { getLevelExp } from "../map/RogueConfig";
|
||||
import { FightSet } from "./config/GameSet";
|
||||
import { GameScoreStats } from "./config/HeroAttrs";
|
||||
import { mLogger } from "./Logger";
|
||||
/**
|
||||
* 用远程数据覆盖本地数据(统一方法)
|
||||
@@ -107,126 +102,13 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
elite_kill_count: 0, // 精英怪击杀数量
|
||||
boss_kill_count: 0, // Boss击杀数
|
||||
} as GameScoreStats,
|
||||
hero:{
|
||||
name:'',
|
||||
path:'',
|
||||
as:0,
|
||||
type:0,
|
||||
lv:1,
|
||||
exp:0,
|
||||
exp_max:100,
|
||||
exp_pre:0,
|
||||
hp:50,
|
||||
hp_max:100,
|
||||
mp:50,
|
||||
mp_max:100,
|
||||
def:0,
|
||||
ap:0,
|
||||
crt:0,
|
||||
dodge:0,
|
||||
skills:[],
|
||||
buff:[],
|
||||
tal:[],
|
||||
info:'',
|
||||
},
|
||||
// 收集记录
|
||||
collection: {
|
||||
talents: {} as Record<number, number>,
|
||||
skill: {uuid:0,count:0},
|
||||
friend:{uuid:0,count:0},
|
||||
},
|
||||
|
||||
gold: 0, // 金币数据(MVVM绑定字段)
|
||||
};
|
||||
|
||||
|
||||
|
||||
// 全局属性加成 {attrIndex: [value, count]}
|
||||
global_attrs: Record<number, [number, number]> = {
|
||||
[Attrs.AP]: [1, 0], // 攻击力
|
||||
[Attrs.HP_MAX]: [10, 10], // 生命上限
|
||||
[Attrs.DEF]: [1, 0], // 防御
|
||||
[Attrs.DODGE]: [1, 0], // 闪避率
|
||||
[Attrs.CRITICAL]: [1, 0], // 暴击率
|
||||
[Attrs.STUN_CHANCE]: [1, 0], // 眩晕率
|
||||
[Attrs.WFUNY]: [1, 0], // 风怒率
|
||||
};
|
||||
|
||||
/** 主角实体引用 */
|
||||
// role: ecs.Entity | null = null;
|
||||
|
||||
/**
|
||||
* 记录天赋获取
|
||||
* @param id 天赋ID
|
||||
*/
|
||||
addTalentRecord(id: number) {
|
||||
if (!this.vmdata.collection.talents[id]) {
|
||||
this.vmdata.collection.talents[id] = 0;
|
||||
}
|
||||
this.vmdata.collection.talents[id]++;
|
||||
mLogger.log(this.debugMode, 'SMC', `[SMC] 记录天赋获取: ID=${id}, 次数=${this.vmdata.collection.talents[id]}`);
|
||||
oops.message.dispatchEvent(GameEvent.UpdateCollection);
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录技能获取
|
||||
* @param id 技能ID
|
||||
*/
|
||||
addSkillRecord(id: number) {
|
||||
if (!this.vmdata.collection.skill.uuid) {
|
||||
this.vmdata.collection.skill.uuid = id;
|
||||
}
|
||||
this.vmdata.collection.skill.count++;
|
||||
mLogger.log(this.debugMode, 'SMC', `[SMC] 记录技能获取: ID=${id}, 次数=${this.vmdata.collection.skill.count}`);
|
||||
oops.message.dispatchEvent(GameEvent.UpdateCollection);
|
||||
}
|
||||
/**
|
||||
* 记录好友获取
|
||||
* @param id 好友ID
|
||||
*/
|
||||
addFriendHero(id: number) {
|
||||
if (!this.vmdata.collection.friend.uuid) {
|
||||
this.vmdata.collection.friend.uuid = id;
|
||||
}
|
||||
this.vmdata.collection.friend.count++;
|
||||
mLogger.log(this.debugMode, 'SMC', `[SMC] 记录好友获取: ID=${id}, 次数=${this.vmdata.collection.friend.count}`);
|
||||
oops.message.dispatchEvent(GameEvent.UpdateCollection);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加经验并处理升级逻辑
|
||||
* @param exp 获得的经验值
|
||||
*/
|
||||
addExp(exp: number) {
|
||||
if (exp <= 0) return;
|
||||
|
||||
const h = this.vmdata.hero;
|
||||
// 确保等级至少为1
|
||||
if (h.lv < 1) h.lv = 1;
|
||||
// 确保经验上限正确
|
||||
if (h.exp_max <= 0) h.exp_max = getLevelExp(h.lv);
|
||||
|
||||
h.exp += exp;
|
||||
|
||||
// 检查升级
|
||||
let isLevelUp = false;
|
||||
while (h.exp >= h.exp_max) {
|
||||
h.exp -= h.exp_max;
|
||||
h.lv++;
|
||||
isLevelUp = true;
|
||||
|
||||
// 更新下一级所需经验
|
||||
h.exp_max = getLevelExp(h.lv);
|
||||
|
||||
mLogger.log(this.debugMode, 'SMC', `[SMC] 升级! Lv.${h.lv - 1} -> Lv.${h.lv}, 下级所需: ${h.exp_max}`);
|
||||
}
|
||||
h.exp_pre=Math.round(h.exp/h.exp_max*100)
|
||||
if (isLevelUp) {
|
||||
mLogger.log(this.debugMode, 'SMC', `[SMC] 触发升级事件: Lv.${h.lv}`);
|
||||
// 发送升级事件
|
||||
oops.message.dispatchEvent(GameEvent.CanUpdateLv, { lv: h.lv });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
vmAdd() {
|
||||
VM.add(this.vmdata, "data");
|
||||
// mLogger.log(this.debugMode, 'SMC', "[MissionComp]局内数据初始化",smc.vmdata.mission_data)
|
||||
@@ -332,19 +214,7 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
|
||||
return true
|
||||
}
|
||||
// 设置单个出战英雄
|
||||
updateFihgtHero(heroId: number) {
|
||||
this.fight_hero = heroId;
|
||||
if(this.isWxClient()){
|
||||
let res = this.updateCloudData()
|
||||
if (res){
|
||||
return true
|
||||
}else{
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
updateGold(gold:number, is_sync: boolean = true){
|
||||
this.vmdata.gold += gold;
|
||||
if(this.isWxClient() && is_sync){
|
||||
@@ -361,56 +231,6 @@ 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;
|
||||
|
||||
// 防止 ECS 旧数据覆盖 VM 新数据 (如果 VM 里的等级更高,说明刚升级还没同步到 ECS)
|
||||
if (heroAttrs.lv > h.lv) {
|
||||
h.lv = heroAttrs.lv;
|
||||
} else if (h.lv > heroAttrs.lv) {
|
||||
// 此时应该反向同步?或者等待 CanUpdateLv 事件处理
|
||||
// 这里暂时保持 VM 的高等级,不被 ECS 覆盖
|
||||
} else {
|
||||
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.dodge = Math.floor(heroAttrs.Attrs[Attrs.DODGE] || 0);
|
||||
h.crt = Math.floor(heroAttrs.Attrs[Attrs.CRITICAL] || 0);
|
||||
h.as = Math.floor(heroAttrs.Attrs[Attrs.AS] || 0);
|
||||
|
||||
// 强制触发 VM 更新
|
||||
// 如果 VM 监听的是 smc.vmdata.hero 的属性变化,上面的赋值应该有效。
|
||||
// 但如果 UI 绑定的是 hero 整体对象,或者因为深层监听问题,可能需要手动通知。
|
||||
// 为了保险,我们可以重新赋值一次(如果是对象引用可能不会触发),或者使用 VM 提供的 set 方法
|
||||
// 这里尝试直接重新赋值整个对象属性来触发更新,或者假设 VM 已经处理好了深层监听。
|
||||
// 如果 UI 没变,可能是 VM 没有检测到深层属性变化。
|
||||
|
||||
// 尝试手动通知或重新赋值关键路径
|
||||
// 注意:Oops Framework 的 VM 通常支持对象属性修改的监听,前提是初始化时已经建立了监听。
|
||||
// 这里我们尝试显式调用 VM.modify 来通知更新(如果有这个 API),或者重新赋值给 vmdata
|
||||
|
||||
// 方案:重新设置 vmdata.hero 来触发根节点的更新通知
|
||||
this.vmdata.hero = h;
|
||||
}
|
||||
error(){
|
||||
oops.gui.toast("数据处理异常,请重试或重新登录")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user