Files
heros/assets/script/game/hero/Hero.ts
walkpan 3710f7f695 feat(英雄系统): 添加天赋组件及配套功能
实现英雄天赋系统核心功能,包括:
1. 新增 TalComp 组件管理天赋的获取、触发和效果应用
2. 重构 TalSet 配置结构,完善天赋类型和效果枚举
3. 在 Hero/Monster 实体中集成天赋组件
4. 为 SkillConComp 和 HeroViewComp 添加天赋相关引用
2025-10-28 00:07:50 +08:00

102 lines
3.6 KiB
TypeScript

import { instantiate, Node, Prefab, Vec3 ,v3,resources,SpriteFrame,Sprite,SpriteAtlas} from "cc";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { smc } from "../common/SingletonModuleComp";
import { HeroModelComp } from "./HeroModelComp";
import { HeroViewComp } from "./HeroViewComp";
import { BoxSet, FacSet } from "../common/config/BoxSet";
import { HeroInfo, HeroPos, HType } from "../common/config/heroSet";
import { BattleMoveComp } from "../common/ecs/position/BattleMoveComp";
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`)
export class Hero extends ecs.Entity {
HeroModel!: HeroModelComp;
HeroView!: HeroViewComp;
BattleMove!: BattleMoveComp;
protected init() {
this.addComponents<ecs.Comp>(
BattleMoveComp,
HeroModelComp,
TalComp
);
}
destroy(): void {
this.remove(HeroViewComp);
this.remove(HeroModelComp);
this.remove(TalComp);
super.destroy();
}
/** 加载角色 */
load(pos: Vec3 = Vec3.ZERO,scale:number = 1,uuid:number=1001,fight_pos:number=1) {
// console.log("英雄加载:",uuid,pos,scale,info)
scale = 1
// 查找空闲英雄槽位
var path = "game/heros/"+HeroInfo[uuid].path;
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
var scene = smc.map.MapView.scene;
node.parent = scene.entityLayer!.node!
node.setPosition(pos)
// console.log("hero load",pos)
var hv = this.hero_init(uuid,node)
this.add(hv);
oops.message.dispatchEvent(GameEvent.MasterCalled,{uuid:uuid})
const move = this.get(BattleMoveComp);
move.direction = 1; // 向右移动
move.targetX = 0; // 右边界'
if(HeroInfo[uuid].type==HType.remote){
move.targetX = -100; // 右边界'
}
if(HeroInfo[uuid].type==HType.mage){
move.targetX = -200; // 右边界'
}
smc.vmdata.mission_data.hero_num++
}
hero_init(uuid:number=1001,node:Node) {
var hv = node.getComponent(HeroViewComp)!;
let hero= HeroInfo[uuid] // 共用英雄数据
hv.scale = 1;
hv.is_master=true;
hv.lv=hero.lv?hero.lv:1
hv.fac = FacSet.HERO;
hv.type = hero.type;
hv.box_group = BoxSet.HERO;
hv.hero_uuid= uuid;
hv.hero_name= hero.name;
for(let i=0;i<hero.skills.length;i++){
let skill={ uuid:SkillSet[hero.skills[i]].uuid, cd_max:SkillSet[hero.skills[i]].cd,cost:SkillSet[hero.skills[i]].cost,cd:0 }
hv.skills.push(skill)
}
hv.base_ap=hero.ap
hv.base_map=hero.mp
hv.base_def=hero.def
hv.base_hp=hero.hp
hv.base_mp=hero.mp
hv.base_dis=hero.dis
hv.base_speed=hero.speed
hv.Attrs=getAttrs()
hv.NeAttrs=getNeAttrs()
hv.hp=hv.Attrs[Attrs.HP_MAX]=hv.base_hp
hv.mp=hv.Attrs[Attrs.MP_MAX]=hv.base_mp
hv.Attrs[Attrs.DEF]=hv.base_def
hv.Attrs[Attrs.AP]=hv.base_ap
hv.Attrs[Attrs.MAP]=hv.base_map
hv.Attrs[Attrs.SPEED]=hero.speed
hv.Attrs[Attrs.DIS]=hero.dis
// 初始化 buff/debuff 系统
hv.initAttrs();
return hv
}
}