去掉了 技能系统,技能由单个精灵独立处理
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { oops } from "db://oops-framework/core/Oops";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { HeroViewComp } from "./HeroViewComp";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
|
||||
/**
|
||||
* 角色属性数据
|
||||
@@ -9,6 +11,9 @@ export class HartModelComp extends ecs.Comp {
|
||||
onLoad(){
|
||||
console.log("HartModel加载",this)
|
||||
}
|
||||
start(){
|
||||
oops.message.dispatchEvent(GameEvent.FightReady,this)
|
||||
}
|
||||
reset() {
|
||||
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import { HeroViewComp } from "./HeroViewComp";
|
||||
import { BoxSet } from "../common/config/BoxSet";
|
||||
import { HeroInfo } from "../common/config/heroSet";
|
||||
import { BattleMoveComp } from "../common/ecs/position/BattleMoveComp";
|
||||
import { HeroSkillsComp } from "../skill/heroSkillsComp";
|
||||
import { HartModelComp } from "./HartModelComp";
|
||||
import { SkillConComp } from "./SkillConComp";
|
||||
/** 角色实体 */
|
||||
@ecs.register(`Hero`)
|
||||
|
||||
@@ -20,12 +20,13 @@ export class Hero extends ecs.Entity {
|
||||
protected init() {
|
||||
this.addComponents<ecs.Comp>(
|
||||
BattleMoveComp,
|
||||
HeroModelComp
|
||||
HeroModelComp,
|
||||
);
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
this.remove(HeroViewComp);
|
||||
this.remove(HeroModelComp);
|
||||
super.destroy();
|
||||
}
|
||||
hart_load() {
|
||||
@@ -36,7 +37,7 @@ export class Hero extends ecs.Entity {
|
||||
var node = instantiate(prefab);
|
||||
var scene = smc.map.MapView.scene;
|
||||
node.parent = scene.entityLayer!.node!
|
||||
let pos=v3(-277,150,0)
|
||||
let pos=v3(-277,0,0)
|
||||
node.setPosition(pos)
|
||||
var hv = node.getComponent(HeroViewComp)!;
|
||||
hv.scale = 1;
|
||||
@@ -97,31 +98,5 @@ export class Hero extends ecs.Entity {
|
||||
}
|
||||
|
||||
|
||||
// 添加技能
|
||||
public addSkill(skillId: number) {
|
||||
const comp = this.get(HeroSkillsComp);
|
||||
if (comp.skills.indexOf(skillId) === -1) {
|
||||
comp.skills.push(skillId);
|
||||
comp.cooldowns.set(skillId, 0);
|
||||
comp.counters.set(skillId, 0);
|
||||
console.log(`技能${skillId}初始化完成`,
|
||||
'当前cooldowns:', comp.cooldowns,
|
||||
'当前counters:', comp.counters);
|
||||
}
|
||||
}
|
||||
|
||||
// 移除技能
|
||||
public removeSkill(skillId: number) {
|
||||
const comp = this.get(HeroSkillsComp);
|
||||
comp.skills = comp.skills.filter(id => id !== skillId);
|
||||
}
|
||||
|
||||
public levelUp() {
|
||||
// ...升级逻辑...
|
||||
const comp = this.get(HeroSkillsComp);
|
||||
comp.skills.forEach(skillId => {
|
||||
comp.resetCooldown(skillId);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,16 +10,16 @@ export default class HeroAnmComp extends Component{
|
||||
private _hasStop = true;
|
||||
onLoad () {
|
||||
var spine = this.spine = this.getComponent('sp.Skeleton') as sp.Skeleton;
|
||||
// this._setMix('Walking', 'Idle');
|
||||
// this._setMix('Walking', 'Attacking');
|
||||
// this._setMix('Walking', 'Taunt');
|
||||
// this._setMix('Idle', 'Attacking');
|
||||
// this._setMix('Idle', 'Taunt');
|
||||
// this._setMix('Idle', 'Walking');
|
||||
// this._setMix('Attacking', 'Idle');
|
||||
// this._setMix('Attacking', 'Walking');
|
||||
// this._setMix('Taunt', 'Walking');
|
||||
// this._setMix('Taunt', 'Idle');
|
||||
this._setMix('Walking', 'Idle');
|
||||
this._setMix('Walking', 'Attacking');
|
||||
this._setMix('Walking', 'Taunt');
|
||||
this._setMix('Idle', 'Attacking');
|
||||
this._setMix('Idle', 'Taunt');
|
||||
this._setMix('Idle', 'Walking');
|
||||
this._setMix('Attacking', 'Idle');
|
||||
this._setMix('Attacking', 'Walking');
|
||||
this._setMix('Taunt', 'Walking');
|
||||
this._setMix('Taunt', 'Idle');
|
||||
|
||||
spine.setCompleteListener((trackEntry) => {
|
||||
var animationName = trackEntry.animation ? trackEntry.animation.name : "";
|
||||
@@ -92,8 +92,8 @@ export default class HeroAnmComp extends Component{
|
||||
this.spine?.setAnimation(0, 'Idle', true);
|
||||
}
|
||||
|
||||
// _setMix (anim1: string, anim2: string) {
|
||||
// this.spine?.setMix(anim1, anim2, this.mixTime);
|
||||
// this.spine?.setMix(anim2, anim1, this.mixTime);
|
||||
// }
|
||||
_setMix (anim1: string, anim2: string) {
|
||||
this.spine?.setMix(anim1, anim2, this.mixTime);
|
||||
this.spine?.setMix(anim2, anim1, this.mixTime);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import { RandomManager } from "../../../../extensions/oops-plugin-framework/asse
|
||||
import { HeroSet } from "../common/config/heroSet";
|
||||
import { BuffComp } from "./BuffComp";
|
||||
import { getMonsterDrops, MonsterType } from "../common/config/RewardSet";
|
||||
import { HeroSkillsComp } from "../skill/heroSkillsComp";
|
||||
import { oops } from "db://oops-framework/core/Oops";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
const { ccclass, property } = _decorator;
|
||||
@@ -332,11 +331,7 @@ export class HeroViewComp extends CCComp {
|
||||
break
|
||||
}
|
||||
}
|
||||
public revive() {
|
||||
this.hp = this.hp_max;
|
||||
const skills = this.ent.get(HeroSkillsComp);
|
||||
skills.resetAllCooldowns();
|
||||
}
|
||||
|
||||
|
||||
to_update(){
|
||||
this.ap=this.ap*this.lv
|
||||
|
||||
@@ -7,6 +7,7 @@ import { BoxSet } from "../common/config/BoxSet";
|
||||
import { HeroInfo } from "../common/config/heroSet";
|
||||
import { MonModelComp } from "./MonModelComp";
|
||||
import { BattleMoveComp } from "../common/ecs/position/BattleMoveComp";
|
||||
import { SkillConComp } from "./SkillConComp";
|
||||
/** 角色实体 */
|
||||
@ecs.register(`Monster`)
|
||||
export class Monster extends ecs.Entity {
|
||||
@@ -17,12 +18,13 @@ export class Monster extends ecs.Entity {
|
||||
protected init() {
|
||||
this.addComponents<ecs.Comp>(
|
||||
BattleMoveComp,
|
||||
MonModelComp
|
||||
MonModelComp,
|
||||
);
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
this.remove(HeroViewComp);
|
||||
this.remove(MonModelComp);
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
@@ -67,8 +69,6 @@ export class Monster extends ecs.Entity {
|
||||
hv.cd = hero.a_cd
|
||||
hv.atk_skill=hero.skills[0]
|
||||
this.add(hv);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
129
assets/script/game/hero/SkillConComp.ts
Normal file
129
assets/script/game/hero/SkillConComp.ts
Normal file
@@ -0,0 +1,129 @@
|
||||
import { _decorator, Component, Node, Vec3 } from 'cc';
|
||||
import { HeroViewComp } from './HeroViewComp';
|
||||
import { SkillSet, TargetGroup, TargetType } from '../common/config/SkillSet';
|
||||
import { Skill } from '../skills/Skill';
|
||||
import { ecs } from 'db://oops-framework/libs/ecs/ECS';
|
||||
import { oops } from 'db://oops-framework/core/Oops';
|
||||
import { GameEvent } from '../common/config/GameEvent';
|
||||
import { BoxSet } from '../common/config/BoxSet';
|
||||
import { smc } from '../common/SingletonModuleComp';
|
||||
import { CCComp } from 'db://oops-framework/module/common/CCComp';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('SkillCon')
|
||||
@ecs.register('SkillCon')
|
||||
export class SkillConComp extends CCComp {
|
||||
|
||||
HeroView:any=null;
|
||||
HeroEntity:any=null;
|
||||
private _timers: { [key: string]: number } = {};
|
||||
private _damageQueue: Array<{ timer: number; callback: () => void }> = [];
|
||||
init(): void {
|
||||
oops.message.on(GameEvent.FightEnd, this.clear_timer, this);
|
||||
}
|
||||
start() {
|
||||
// console.log("SkillConComp start")
|
||||
this.HeroView=this.node.getComponent(HeroViewComp)
|
||||
this.HeroEntity=this.HeroView.ent
|
||||
}
|
||||
|
||||
update(dt: number) {
|
||||
if(!smc.mission.play||smc.mission.pause) return
|
||||
if (this.HeroView.is_atking &&this.HeroView.at > this.HeroView.cd) {
|
||||
const config = SkillSet[this.HeroView.atk_skill];
|
||||
if (!config) return;
|
||||
this.castSkill(this.HeroView, this.HeroView.atk_skill, config);
|
||||
this.HeroView.at = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/** 施放技能 */
|
||||
private castSkill(view: HeroViewComp, skillId: number, config: typeof SkillSet[keyof typeof SkillSet]) {
|
||||
// console.log(view.uuid+"=>"+view.hero_name+"施放技能:"+config.uuid);
|
||||
if (config.TargetGroup === TargetGroup.Enemy) {
|
||||
view.playSkillEffect(config.uuid);
|
||||
this.doSkill(view,config);
|
||||
}
|
||||
|
||||
if (config.TargetGroup === TargetGroup.Ally) {
|
||||
const targets = this.selectAllyTargets(view, config);
|
||||
if (targets.length === 0) return;
|
||||
|
||||
}
|
||||
if (config.TargetGroup === TargetGroup.Self) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
private doSkill(view: HeroViewComp, config: typeof SkillSet[keyof typeof SkillSet]) {
|
||||
|
||||
const skillEntity = ecs.getEntity<Skill>(Skill);
|
||||
const targets = this.selectEnemyTargets(view, config);
|
||||
if (targets.length === 0) return;
|
||||
skillEntity.load(
|
||||
new Vec3(view.node.position.x, view.node.position.y+BoxSet.ATK_Y, 0), // 起始位置
|
||||
view.box_group, // 阵营
|
||||
view.node.parent, // 父节点
|
||||
config.uuid, // 技能ID
|
||||
new Vec3(targets[0]?.get(HeroViewComp).node.position.x, targets[0]?.get(HeroViewComp).node.position.y, 0), // 目标位置
|
||||
view
|
||||
);
|
||||
// console.log("技能:"+config.uuid+"=>"+targets[0]?.get(HeroViewComp).hero_name);
|
||||
}
|
||||
|
||||
private selectEnemyTargets(View: HeroViewComp, config: typeof SkillSet[keyof typeof SkillSet]): ecs.Entity[] {
|
||||
const team = View.fac;
|
||||
const isEnemyTeam = team === 0 ? 1 : 0;
|
||||
const candidates= ecs.query(ecs.allOf(HeroViewComp)).filter(e => e.get(HeroViewComp).fac !== team);
|
||||
return this.filterFrontRow(candidates, isEnemyTeam);
|
||||
}
|
||||
|
||||
/** 筛选最前排单位 */
|
||||
private filterFrontRow(entities: ecs.Entity[], isEnemyTeam: number): ecs.Entity[] {
|
||||
// 敌方最前排是x坐标最大的,我方最前排是x坐标最小的
|
||||
const keyPos = isEnemyTeam ?
|
||||
Math.min(...entities.map(e => e.get(HeroViewComp).node.position.x)) :
|
||||
Math.max(...entities.map(e => e.get(HeroViewComp).node.position.x));
|
||||
|
||||
return entities.filter(e =>
|
||||
Math.abs(e.get(HeroViewComp).node.position.x - keyPos) < 10
|
||||
);
|
||||
}
|
||||
private selectAllyTargets(View: HeroViewComp, config: typeof SkillSet[keyof typeof SkillSet]): ecs.Entity[] {
|
||||
const team = View.fac;
|
||||
const candidates= ecs.query(ecs.allOf(HeroViewComp)).filter(e => e.get(HeroViewComp).fac === team);
|
||||
// 第二阶段:位置/血量等精细筛选
|
||||
switch(config.TargetType) {
|
||||
case TargetType.Melee:
|
||||
return candidates.filter(e => e.get(HeroViewComp).type === 0);
|
||||
case TargetType.Ranged:
|
||||
return candidates.filter(e => e.get(HeroViewComp).type === 1);
|
||||
case TargetType.SupportClass:
|
||||
return candidates.filter(e => e.get(HeroViewComp).type === 2);
|
||||
case TargetType.Random:
|
||||
return this.pickRandomTarget(candidates, config.count || 1);
|
||||
default:
|
||||
return candidates;
|
||||
}
|
||||
}
|
||||
/** 随机选择目标 */
|
||||
private pickRandomTarget(entities: ecs.Entity[], count: number): ecs.Entity[] {
|
||||
const shuffled = [...entities].sort(() => 0.5 - Math.random());
|
||||
return shuffled.slice(0, count);
|
||||
}
|
||||
public clear_timer() {
|
||||
// console.log("clear_timer");
|
||||
Object.values(this._timers).forEach(clearTimeout);
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.clear_timer();
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
// console.log("SkillConComp onDestroy")
|
||||
Object.values(this._timers).forEach(clearTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
9
assets/script/game/hero/SkillConComp.ts.meta
Normal file
9
assets/script/game/hero/SkillConComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "6f882a1f-6f5a-4ef5-9ea0-21a0192c2785",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user