refactor(game): 重构天赋系统配置和组件逻辑
重构天赋系统配置,包括: 1. 调整天赋类型枚举和效果枚举 2. 移除旧的天赋配置数据 3. 简化天赋组件实现 4. 更新设计文档中的天赋描述 同时修正地图组件中的英雄位置坐标和缩放值
This commit is contained in:
@@ -1,33 +1,13 @@
|
||||
import { _decorator } from "cc";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||
import { ItalConf, TalType, TalEType, talConf } from "../common/config/TalSet";
|
||||
import { BuffConf, SkillSet } from "../common/config/SkillSet";
|
||||
import { HeroInfo } from "../common/config/heroSet";
|
||||
import { HeroViewComp } from "./HeroViewComp";
|
||||
|
||||
const { ccclass } = _decorator;
|
||||
|
||||
/**
|
||||
* 天赋触发统计接口
|
||||
* 记录各种触发条件的计数器,用于判断天赋是否满足触发条件
|
||||
*/
|
||||
interface FightStats {
|
||||
aCount: number; // 普通攻击计数 - 用于 ACTION_COUNT 类型天赋
|
||||
sCount: number; // 技能使用计数 - 用于 SKILL_COUNT 类型天赋
|
||||
dCount: number; // 受伤次数计数 - 用于 DAMAGE_COUNT 类型天赋
|
||||
level: number; // 当前等级 - 用于 LEVEL/LEVEL_UP 类型天赋
|
||||
}
|
||||
|
||||
/**
|
||||
* 天赋效果实例接口
|
||||
* 记录已激活天赋的当前状态,包括堆叠层数和最后触发时间
|
||||
*/
|
||||
interface TalEffect {
|
||||
uuid: number; // 天赋uuid
|
||||
stack: number; // 当前堆叠层数,用于可堆叠天赋
|
||||
lTTime: number; // 上次触发时间戳,可用于时效判断
|
||||
}
|
||||
|
||||
/**
|
||||
* 天赋系统组件类
|
||||
@@ -43,127 +23,16 @@ export class TalComp extends ecs.Comp {
|
||||
/** 英雄唯一标识符,用于从配置中获取英雄信息 */
|
||||
private heroUuid: number = 0;
|
||||
|
||||
/** 天赋触发统计,记录各种触发条件的当前状态 */
|
||||
private FStats: FightStats = { aCount: 0, sCount: 0, dCount: 0, level: 1 };
|
||||
|
||||
/** 活跃天赋效果映射,存储已激活的天赋实例 */
|
||||
private activeTals: TalEffect[] = [];
|
||||
private talEffects: ItalConf[] = [];
|
||||
/** 初始化标志,防止重复初始化 */
|
||||
private isInitialized: boolean = false;
|
||||
|
||||
|
||||
/**
|
||||
* 组件生命周期函数 - 启动时调用
|
||||
* 获取英雄视图组件并初始化天赋系统
|
||||
*/
|
||||
start() {
|
||||
// 运行时获取组件,避免编译时循环引用
|
||||
this.heroView = this.ent.get(HeroViewComp);
|
||||
if (this.heroView) {
|
||||
this.heroUuid = this.heroView.hero_uuid;
|
||||
this.initializeTalents();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private initializeTalents(): void {
|
||||
if (this.isInitialized || !this.heroView) return;
|
||||
this.FStats.level = this.heroView.lv || 1;
|
||||
this.getHeroTalents()
|
||||
this.isInitialized = true;
|
||||
}
|
||||
|
||||
private getHeroTalents(): ItalConf[] {
|
||||
this.activeTals = [];
|
||||
this.talEffects = [];
|
||||
if (!this.heroView) return [];
|
||||
const heroInfo = HeroInfo[this.heroUuid];
|
||||
if (!heroInfo?.tal) return [];
|
||||
for(let id of heroInfo.tal){
|
||||
let conf = talConf[id];
|
||||
if(conf){
|
||||
this.talEffects.push(conf)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private doTalEffect(tal:ItalConf){
|
||||
console.log("doTalEffect",tal)
|
||||
if(tal.triggerType == TalEType.ATTRS){
|
||||
console.log("doTalEffect ATTRS",tal)
|
||||
let buff:BuffConf = {
|
||||
buff:tal.e_name,
|
||||
BType:tal.e_type,
|
||||
value:tal.e_value,
|
||||
time:0,
|
||||
chance:tal.chance,
|
||||
}
|
||||
this.heroView.addBuff(buff)
|
||||
}
|
||||
|
||||
if(tal.triggerType == TalEType.SKILL){
|
||||
console.log("doTalEffect SKILL",tal)
|
||||
let skill = SkillSet[tal.e_value];
|
||||
if(this.skillCon){
|
||||
this.skillCon.doSkill(skill,false,0)
|
||||
}
|
||||
}
|
||||
|
||||
if(tal.triggerType == TalEType.SKILL_MORE){
|
||||
console.log("doTalEffect SKILL_MORE",tal)
|
||||
this.heroView.skills.push(tal.e_value)
|
||||
}
|
||||
|
||||
}
|
||||
private checkTrigger(tal:ItalConf) {
|
||||
let stats = this.FStats;
|
||||
switch (tal.type) {
|
||||
case TalType.LEVEL: return stats.level >= tal.t_value;
|
||||
case TalType.LEVEL_UP: return stats.level % tal.t_value === 0;
|
||||
case TalType.ACTION_COUNT: return stats.aCount >= tal.t_value;
|
||||
case TalType.SKILL_COUNT: return stats.sCount >= tal.t_value;
|
||||
case TalType.DAMAGE_COUNT: return stats.dCount >= tal.t_value;
|
||||
case TalType.INIT: return true;
|
||||
case TalType.DEAD: return false; // 单独处理
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
private checkHasTal(TalType:TalType) {
|
||||
for(let tal of this.talEffects){
|
||||
if(TalType == tal.type){
|
||||
if (this.checkTrigger(tal)){
|
||||
this.doTalEffect(tal)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public onAction(): void {
|
||||
this.FStats.aCount++;
|
||||
this.checkHasTal(TalType.ACTION_COUNT);
|
||||
}
|
||||
|
||||
public onSkillUse(): void {
|
||||
this.FStats.sCount++;
|
||||
this.checkHasTal(TalType.SKILL_COUNT);
|
||||
}
|
||||
|
||||
public onDamageTaken(): void {
|
||||
this.FStats.dCount++;
|
||||
this.checkHasTal(TalType.DAMAGE_COUNT);
|
||||
}
|
||||
|
||||
public onLevelUp(newLevel: number): void {
|
||||
this.FStats.level = newLevel;
|
||||
this.checkHasTal(TalType.LEVEL);
|
||||
this.checkHasTal(TalType.LEVEL_UP);
|
||||
}
|
||||
|
||||
public onDeath(): void {
|
||||
this.checkHasTal(TalType.DEAD);
|
||||
}
|
||||
|
||||
|
||||
|
||||
reset() {
|
||||
this.isInitialized = false;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user