feat(英雄系统): 添加天赋组件及配套功能
实现英雄天赋系统核心功能,包括: 1. 新增 TalComp 组件管理天赋的获取、触发和效果应用 2. 重构 TalSet 配置结构,完善天赋类型和效果枚举 3. 在 Hero/Monster 实体中集成天赋组件 4. 为 SkillConComp 和 HeroViewComp 添加天赋相关引用
This commit is contained in:
@@ -11,6 +11,7 @@ import { GameEvent } from "../common/config/GameEvent";
|
||||
import { SkillSet } from "../common/config/SkillSet";
|
||||
import { time } from "console";
|
||||
import { getNeAttrs, getAttrs ,Attrs} from "../common/config/HeroAttrs";
|
||||
import { TalComp } from "./TalComp";
|
||||
/** 角色实体 */
|
||||
@ecs.register(`Hero`)
|
||||
|
||||
@@ -22,14 +23,14 @@ export class Hero extends ecs.Entity {
|
||||
this.addComponents<ecs.Comp>(
|
||||
BattleMoveComp,
|
||||
HeroModelComp,
|
||||
TalComp
|
||||
);
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
this.remove(HeroViewComp);
|
||||
this.remove(HeroModelComp);
|
||||
|
||||
|
||||
this.remove(TalComp);
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import { FightSet, TooltipTypes } from "../common/config/Mission";
|
||||
import { RandomManager } from "db://oops-framework/core/common/random/RandomManager";
|
||||
import { AttrSet, HeroInfo, HeroUpSet } from "../common/config/heroSet";
|
||||
import { Attrs, AttrsType, BType, NeAttrs } from "../common/config/HeroAttrs";
|
||||
import { TalComp } from "./TalComp";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
@@ -73,6 +74,7 @@ export interface BuffInfo {
|
||||
@ecs.register('HeroView', false) // 定义ECS 组件
|
||||
export class HeroViewComp extends CCComp {
|
||||
BUFFCOMP:BuffComp=null!
|
||||
TALCOMP:any=null!
|
||||
as: HeroSpine = null!
|
||||
status:String = "idle"
|
||||
hero_uuid:number = 1001;
|
||||
@@ -143,6 +145,7 @@ export class HeroViewComp extends CCComp {
|
||||
start () {
|
||||
this.as.idle()
|
||||
this.BUFFCOMP=this.node.getComponent(BuffComp);
|
||||
this.TALCOMP=this.node.getComponent(TalComp);
|
||||
// console.log("[HeroViewComp]:heroview"+this.hero_name,this.Attrs)
|
||||
/** 方向 */
|
||||
this.node.setScale(this.scale,1);
|
||||
|
||||
@@ -10,6 +10,7 @@ import { BattleMoveComp } from "../common/ecs/position/BattleMoveComp";
|
||||
import { SkillConComp } from "./SkillConComp";
|
||||
import { SkillSet } from "../common/config/SkillSet";
|
||||
import { getNeAttrs, getAttrs ,Attrs} from "../common/config/HeroAttrs";
|
||||
import { TalComp } from "./TalComp";
|
||||
/** 角色实体 */
|
||||
@ecs.register(`Monster`)
|
||||
export class Monster extends ecs.Entity {
|
||||
@@ -21,12 +22,14 @@ export class Monster extends ecs.Entity {
|
||||
this.addComponents<ecs.Comp>(
|
||||
BattleMoveComp,
|
||||
MonModelComp,
|
||||
TalComp,
|
||||
);
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
this.remove(HeroViewComp);
|
||||
this.remove(MonModelComp);
|
||||
this.remove(TalComp);
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import { MonModelComp } from './MonModelComp';
|
||||
import { HeroModelComp } from './HeroModelComp';
|
||||
import { SkillEnt } from '../skill/SkillEnt';
|
||||
import { Attrs } from '../common/config/HeroAttrs';
|
||||
import { TalComp } from './TalComp';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('SkillCon')
|
||||
@@ -17,6 +18,7 @@ const { ccclass, property } = _decorator;
|
||||
export class SkillConComp extends CCComp {
|
||||
HeroView:any=null;
|
||||
HeroEntity:any=null;
|
||||
TALCOMP:any=null;
|
||||
skill_cd=0
|
||||
private _timers: { [key: string]: any } = {};
|
||||
init(): void {
|
||||
@@ -24,6 +26,7 @@ export class SkillConComp extends CCComp {
|
||||
}
|
||||
onLoad(){
|
||||
this.HeroView=this.node.getComponent(HeroViewComp)
|
||||
this.TALCOMP=this.node.getComponent(TalComp)
|
||||
}
|
||||
start() {
|
||||
this.HeroEntity=this.HeroView.ent
|
||||
|
||||
170
assets/script/game/hero/TalComp.ts
Normal file
170
assets/script/game/hero/TalComp.ts
Normal file
@@ -0,0 +1,170 @@
|
||||
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";
|
||||
|
||||
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; // 上次触发时间戳,可用于时效判断
|
||||
}
|
||||
|
||||
/**
|
||||
* 天赋系统组件类
|
||||
* 继承自 CCComp,作为 ECS 架构中的组件存在
|
||||
* 负责管理英雄的天赋系统,包括天赋获取、触发、效果应用等
|
||||
*/
|
||||
@ccclass('TalComp')
|
||||
@ecs.register('TalComp', false)
|
||||
export class TalComp extends CCComp {
|
||||
/** 英雄视图组件引用,运行时获取避免循环引用 */
|
||||
private heroView: any = null;
|
||||
private skillCon:any=null;
|
||||
/** 英雄唯一标识符,用于从配置中获取英雄信息 */
|
||||
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.node.getComponent("HeroViewComp" as any);
|
||||
this.skillCon = this.node.getComponent("SkillConComp" as any);
|
||||
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;
|
||||
this.node.destroy();
|
||||
}
|
||||
}
|
||||
9
assets/script/game/hero/TalComp.ts.meta
Normal file
9
assets/script/game/hero/TalComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "5944233e-8492-4880-9084-77083cfdf326",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user