继续新技能系统

This commit is contained in:
2025-10-15 08:01:11 +08:00
parent 070346fbe4
commit 2e2c9d82f9
10 changed files with 186 additions and 345 deletions

View File

@@ -67,62 +67,15 @@ export class AtkConCom extends CCComp {
this.initializeSkillConfig();
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
// this.on(ModuleEvent.Cmd, this.onHandler, this);
this.node.setPosition(this.startPos.x,this.startPos.y,0)
this.anim=this.node.getComponent(Animation)
this.on(GameEvent.MissionEnd, this.doDestroy, this);
this.node.active = true;
let collider = this.getComponent(Collider2D);
if(collider) {
collider.group = this.group;
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
}
let bm=this.node.getComponent(BezierMove)
// //console.log(this.group +"技能 collider ",collider);
switch(this.skillConfig.AType){
case AType.parabolic:
this.node.angle +=10
// bm.speed=700
if(this.group==BoxSet.MONSTER) {bm.controlPointSide=-1 }
bm.rotationSmoothness=0.6
bm.moveTo(this.targetPos)
break;
case AType.linear:
let s_x=this.startPos.x
let s_y=this.startPos.y
let t_x=this.targetPos.x
let t_y=this.targetPos.y
// 设定目标x
this.targetPos.x = 400;
if(this.group == BoxSet.MONSTER) {
bm.controlPointSide = -1;
this.targetPos.x = -400;
}
// 计算斜率
const k = (t_y - s_y) / (t_x - s_x);
// 按直线公式计算新的y
this.targetPos.y = k * (this.targetPos.x - s_x) + s_y;
bm.controlPointOffset=0
bm.rotationSmoothness=0.6
bm.moveTo(this.targetPos);
break;
case AType.StartEnd:
// 2段位移先升高然后移到目的地
this.node.setPosition(this.startPos.x > 360?300:this.startPos.x,0,0)
this.do_anim()
break;
case AType.fixedEnd:
this.node.setPosition(this.targetPos.x > 360?300:this.targetPos.x,0,0)
this.do_anim()
break;
case AType.fixedStart: //
if(this.s_uuid==6001){
console.log("skillcom startPos",this.startPos)
}
this.node.setPosition(this.startPos.x > 360?300:this.startPos.x,0,0)
this.do_anim()
break;
}
this.anim=this.node.getComponent(Animation)
this.on(GameEvent.MissionEnd, this.doDestroy, this);
this.node.active = true;
let collider = this.getComponent(Collider2D);
if(collider) {
collider.group = this.group;
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
}
}
do_anim(){
if(this.node.getComponent(Animation)){

View File

@@ -6,12 +6,13 @@ import { smc } from "../common/SingletonModuleComp";
import { FacSet } from "../common/config/BoxSet";
import { HType } from "../common/config/heroSet";
import { SkillViewCom } from "./SkillViewCom";
import { HeroViewComp } from "../hero/HeroViewComp";
/** SkillCon 模块 */
@ecs.register(`SkillCon`)
export class SkillCon extends ecs.Entity {
@ecs.register(`SkillEnt`)
export class SkillEnt extends ecs.Entity {
load(startPos: Vec3, parent: Node, uuid: number, targetPos: Vec3, caster:any=null, angle:number=0,dmg:number=0) {
load(startPos: Vec3, parent: Node, uuid: number, targetPos: any[], caster:HeroViewComp=null,dmg:number=0) {
const config = SkillSet[uuid];
if (!config) {
console.error("[Skill] 技能配置不存在:", uuid);
@@ -45,10 +46,8 @@ load(startPos: Vec3, parent: Node, uuid: number, targetPos: Vec3, caster:any=n
}
}
}
node.angle+=angle
// 添加技能组件
const SComp = node.getComponent(SkillViewCom); // 初始化技能参数
// 只设置必要的运行时属性,配置信息通过 SkillSet[uuid] 访问
Object.assign(SComp, {
// 核心标识
@@ -60,6 +59,7 @@ load(startPos: Vec3, parent: Node, uuid: number, targetPos: Vec3, caster:any=n
fac: caster.fac,
// 技能数值
ap: caster.Attrs[BuffAttr.AP],
caster: caster,
caster_crit: caster.Attrs[BuffAttr.CRITICAL],
caster_crit_d: caster.Attrs[BuffAttr.CRITICAL_DMG],
puncture: caster.Attrs[BuffAttr.PUNCTURE],
@@ -89,12 +89,3 @@ load(startPos: Vec3, parent: Node, uuid: number, targetPos: Vec3, caster:any=n
super.destroy();
}
}
/** SkillCon 模块业务逻辑系统组件,如无业务逻辑处理可删除此对象 */
export class EcsSkillConSystem extends ecs.System {
constructor() {
super();
// this.add(new ecs.ComblockSystem());
}
}

View File

@@ -1,7 +1,9 @@
import { _decorator } from "cc";
import { _decorator, instantiate, Node, Prefab } 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 { HeroViewComp } from "../hero/HeroViewComp";
import { BuffAttr, RType, SkillSet } from "../common/config/SkillSet";
import { AtkConCom } from "./AtkConCom";
const { ccclass, property } = _decorator;
@@ -10,18 +12,23 @@ const { ccclass, property } = _decorator;
@ecs.register('SkillView', false)
export class SkillViewCom extends CCComp {
/** 视图层逻辑代码分离演示 */
@property({ type: Prefab })
atkPrefab: Prefab = null!
@property({ type: Number })
runType: number = 0;
@property({ type: Boolean })
hasReady: boolean = false;
@property({ type: Number })
ReadyTime: number = 0;
@property({ type: Number })
postion_y: number = 0;
endTime: number = 0;
s_uuid:number=0;
s_count:number=1;
s_interval:number=0.2;
s_cd:number=0;
caster:HeroViewComp=null;
cName:string="";
target:HeroViewComp=null;
parent:Node=null;
target_postions:any[]=null
@@ -43,54 +50,104 @@ export class SkillViewCom extends CCComp {
debuff_up:number=0;
debuff_value:number=0;
debuff_count:number=0;
targetPos:any[]=null
start() {
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
// this.on(ModuleEvent.Cmd, this.onHandler, this);
this.cName = this.caster.hero_name
this.node.getChildByName("ready").active = this.hasReady
}
protected update(dt: number): void {
this.doTimer(dt)
this.move(dt)
this.doEnd(dt)
if(this.hasReady) {
this.doTimer(dt)
if(this.ReadyTime <= 0) {
this.doAtk(dt)
}
}{
this.doAtk(dt)
}
this.move(dt)
}
doEnd(dt: number) {
this.endTime += dt
if(this.endTime >= SkillSet[this.s_uuid].in) {
this.ent.destroy()
}
}
doTimer(dt: number){
if(this.ReadyTime <= 0) return
this.ReadyTime -= dt
if(this.ReadyTime > 0&&this.hasReady) this.ReadyTime -= dt
}
doAtk(dt:number): void {
// console.log(`${this.cName}_[SkillViewCom] doAtkC`)
if(this.s_cd <= 0&&this.s_count > 0) {
this.doSkill()
this.s_count--
this.s_cd = this.s_interval
}
this.s_cd -= dt
if(this.s_cd > 0) this.s_cd -= dt
}
doSkill(){
console.log("doSkill")
console.log(`${this.cName}_[SkillViewCom] doSkill`,this.atkPrefab)
if(this.atkPrefab!=null){
let atkNode:Node = instantiate(this.atkPrefab)
atkNode.parent = this.node.parent
atkNode.setPosition(this.node.position)
let atkCom=atkNode.getComponent(AtkConCom)
Object.assign(atkCom, {
// 核心标识
s_uuid: this.s_uuid,
// 位置和施法者信息
startPos: this.node.position,
targetPos: this.targetPos[0],
group: this.caster.box_group,
fac: this.caster.fac,
// 技能数值
ap: this.caster.Attrs[BuffAttr.AP],
caster: this.caster,
caster_crit: this.caster.Attrs[BuffAttr.CRITICAL],
caster_crit_d: this.caster.Attrs[BuffAttr.CRITICAL_DMG],
puncture: this.caster.Attrs[BuffAttr.PUNCTURE],
puncture_damage: this.caster.Attrs[BuffAttr.PUNCTURE_DMG],
burn_count: this.caster.Attrs[BuffAttr.BURN_COUNT],
burn_value: this.caster.Attrs[BuffAttr.BURN_VALUE],
stun_time: this.caster.Attrs[BuffAttr.STUN_TIME],
stun_ratio: this.caster.Attrs[BuffAttr.STUN_RATIO],
frost_time: this.caster.Attrs[BuffAttr.FROST_TIME],
frost_ratio: this.caster.Attrs[BuffAttr.FROST_RATIO],
debuff_up: this.caster.Attrs[BuffAttr.DEBUFF_UP],
debuff_value: this.caster.Attrs[BuffAttr.DEBUFF_VALUE],
debuff_count: this.caster.Attrs[BuffAttr.DEBUFF_COUNT],
});
switch(this.runType){
case RType.linear:
this.do_linear(atkNode)
break
case RType.bezier:
this.do_bezier(atkNode)
break
case RType.fixed:
this.do_fixed(atkNode)
break
}
}
}
move(dt: number): void {
if(this.caster == null) return
if(this.caster.is_dead) return
if(this.caster.node.isValid) return
this.node.setPosition(this.caster.node.position.x,this.caster.node.position.y+this.postion_y)
console.log("[skillview]move",this.caster.node.position,this.node.position)
do_linear(atkNode:any): void {
console.log(`${this.cName}_[SkillViewCom] skille run type: linear`)
}
do_bezier(atkNode:any): void {
console.log(`${this.cName}_[SkillViewCom] skille run type: bezier`)
}
do_fixed(atkNode:any): void {
console.log(`${this.cName}_[SkillViewCom] skille run type: fixed`)
}
/** 全局消息逻辑处理 */
// private onHandler(event: string, args: any) {
// switch (event) {
// case ModuleEvent.Cmd:
// break;
// }
// }
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
move(dt: number): void {
// console.log(`${this.cName}_[SkillViewCom] move`)
if(this.caster != null&&this.caster.node!=null) this.node.setPosition(this.caster.node.position.x,this.caster.node.position.y+this.postion_y)
// console.log(`${this.cName}_[skillview]move`,this.caster.node.position,this.node.position)
}
reset() {
this.node.destroy();
}