From 13d0a6d190c557d0c298d617a3d6fc6a1204e50a Mon Sep 17 00:00:00 2001 From: panfudan Date: Mon, 11 Aug 2025 23:13:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=80=E8=83=BDcd=20=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../game/common/EnhancedButtonTouchLong.ts | 102 ----- .../script/game/common/SingletonModuleComp.ts | 8 - assets/script/game/hero/Hero.ts | 1 - assets/script/game/hero/HeroViewComp.ts | 4 +- assets/script/game/hero/Mon.ts | 1 - assets/script/game/hero/SkillConComp.ts | 49 +-- assets/script/game/map/MissionComp copy.ts | 413 ------------------ assets/script/game/skills/SkillCom-001.ts | 338 -------------- 8 files changed, 22 insertions(+), 894 deletions(-) delete mode 100644 assets/script/game/common/EnhancedButtonTouchLong.ts delete mode 100644 assets/script/game/map/MissionComp copy.ts delete mode 100644 assets/script/game/skills/SkillCom-001.ts diff --git a/assets/script/game/common/EnhancedButtonTouchLong.ts b/assets/script/game/common/EnhancedButtonTouchLong.ts deleted file mode 100644 index abf6942c..00000000 --- a/assets/script/game/common/EnhancedButtonTouchLong.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { EventHandler, EventTouch, _decorator } from "cc"; -import { ButtonTouchLong } from "../../../../extensions/oops-plugin-framework/assets/libs/gui/button/ButtonTouchLong"; - -const { ccclass, property, menu } = _decorator; - -/** - * 增强版长按按钮组件 - * 支持长按触发和放开后触发两种事件 - */ -@ccclass("EnhancedButtonTouchLong") -@menu('ui/button/EnhancedButtonTouchLong') -export class EnhancedButtonTouchLong extends ButtonTouchLong { - - @property({ - type: [EventHandler], - tooltip: "放开后触发的事件" - }) - releaseEvents: EventHandler[] = []; - - @property({ - tooltip: "是否在长按后放开时触发事件" - }) - triggerOnRelease: boolean = true; - - @property({ - tooltip: "是否在短按时也触发放开事件" - }) - triggerOnShortPress: boolean = false; - - private _wasLongPressed: boolean = false; - private _hasTriggeredRelease: boolean = false; - - onLoad() { - super.onLoad(); - this._wasLongPressed = false; - this._hasTriggeredRelease = false; - } - - /** 触摸开始 */ - onTouchtStart(event: EventTouch) { - this._wasLongPressed = false; - this._hasTriggeredRelease = false; - super.onTouchtStart(event); - } - - /** 触摸结束 */ - onTouchEnd(event: EventTouch) { - // 检查是否已经长按过 - if (this._passTime > this.time) { - this._wasLongPressed = true; - } - - // 触发放开事件 - if (this.triggerOnRelease && !this._hasTriggeredRelease) { - if (this._wasLongPressed || this.triggerOnShortPress) { - this._hasTriggeredRelease = true; - this.onReleaseTrigger(); - } - } - - super.onTouchEnd(event); - } - - /** 引擎更新事件 */ - update(dt: number) { - super.update(dt); - - // 在父类的update中,如果触发了长按事件,标记为已长按 - if (this._passTime >= this.time && !this._isTouchLong) { - this._wasLongPressed = true; - } - } - - /** - * 放开触发回调 - */ - protected onReleaseTrigger() { - // 发送自定义事件 - this.node.emit('releaseTrigger', this); - - // 触发配置的事件 - this.releaseEvents.forEach(event => { - event.emit([event.customEventData]); - }); - - console.log('放开触发!'); - } - - /** - * 获取是否已经长按过 - */ - wasLongPressed(): boolean { - return this._wasLongPressed; - } - - /** - * 获取当前按住时间 - */ - getPassTime(): number { - return this._passTime; - } -} \ No newline at end of file diff --git a/assets/script/game/common/SingletonModuleComp.ts b/assets/script/game/common/SingletonModuleComp.ts index 356c77d1..4a0e9c31 100644 --- a/assets/script/game/common/SingletonModuleComp.ts +++ b/assets/script/game/common/SingletonModuleComp.ts @@ -43,20 +43,12 @@ export class SingletonModuleComp extends ecs.Comp { game_pause:false, mission_data:{ }, hero:{ }, - hero1:{}, - hero2:{}, - hero3:{}, boss:{ }, }; vmAdd() { this.vmdata.mission_data=JSON.parse(JSON.stringify(MissionData)) this.vmdata.hero=JSON.parse(JSON.stringify(VmInfo)) - this.vmdata.boss=JSON.parse(JSON.stringify(VmInfo)) - this.vmdata.hero1=JSON.parse(JSON.stringify(HeroUI)) - this.vmdata.hero2=JSON.parse(JSON.stringify(HeroUI)) - this.vmdata.hero3=JSON.parse(JSON.stringify(HeroUI)) VM.add(this.vmdata, "data"); - } reset() { for (var key in this.vmdata) { diff --git a/assets/script/game/hero/Hero.ts b/assets/script/game/hero/Hero.ts index 8a02e6a0..ecaf2379 100644 --- a/assets/script/game/hero/Hero.ts +++ b/assets/script/game/hero/Hero.ts @@ -137,7 +137,6 @@ export class Hero extends ecs.Entity { break } }) - hv.atk_skill=hero.skills[0] for(let i=0;i0) return - this.at=0 // 眩晕 cd归零 + this.skills[0].cd=0 // 眩晕 cd归零 this.BUFFCOMP.in_yun(deV+FightSet.STUN_TIME) // 眩晕时间 this.DEBUFF_STUN+=deV+FightSet.STUN_TIME // 眩晕时间 // this.is_stop=true diff --git a/assets/script/game/hero/Mon.ts b/assets/script/game/hero/Mon.ts index fbff4974..e8de2a2f 100644 --- a/assets/script/game/hero/Mon.ts +++ b/assets/script/game/hero/Mon.ts @@ -103,7 +103,6 @@ export class Monster extends ecs.Entity { } hv.cd = hero.cd - hv.atk_skill=hero.skills[0] for(let i=0;i"+this.HeroView.hero_name+"=> SkillConComp onLoad") - this.on(GameEvent.CastHeroSkill,this.cast_master_skill,this) - this.on(GameEvent.MaxSkill,this.use_max_skill,this) + } start() { @@ -51,11 +50,11 @@ export class SkillConComp extends CCComp { if(this.HeroView.DEBUFF_STUN <= 0&&this.HeroView.DEBUFF_FROST <= 0) { for(let i=0;i this.HeroView.skills[i].cd_max){ + if(this.HeroView.skills[i].cd > (i==0?this.count_cd(this.HeroView.skills[i].cd_max,this.HeroView):this.HeroView.skills[i].cd_max)){ let sc=SkillSet[this.HeroView.skills[i].uuid] if(!sc) return if(sc.SType==SType.damage&&!this.HeroView.is_atking) return - this.castSkill(sc,false,0) + this.castSkill(sc) this.HeroView.skills[i].cd = 0 } } @@ -91,35 +90,29 @@ export class SkillConComp extends CCComp { } } - cast_master_skill(e:string,uuid:any){ - if(!this.HeroView) return - if(this.HeroView.fac==FacSet.MON) return - //console.log("hart cast_skill",uuid ,e) - const config = SkillSet[uuid]; - this.castSkill(config,false,this.HeroView.skill_dmg) + count_cd(cd:number,view:HeroViewComp){ + + // 汇总DEBUFF_DECD,不再按次数减少,改为按时间减少 + let decd = 0; + for (let i = view.DEBUFF_DECDS.length - 1; i >= 0; i--) { + decd += view.DEBUFF_DECDS[i].value; + // 不再在这里减少duration,改为在update中按时间减少 + } + let bcd=0 + for (let i = view.BUFF_CDS.length - 1; i >= 0; i--) { + bcd += view.BUFF_CDS[i].value; + // 不再在这里减少duration,改为在update中按时间减少 + } + return cd/((bcd+decd)/100+1) } /** 施放技能 */ - castSkill(config: typeof SkillSet[keyof typeof SkillSet],is_wfuny:boolean=false,dmg:number=0) { + castSkill(config: typeof SkillSet[keyof typeof SkillSet]) { // //console.log(view.uuid+"=>"+view.hero_name+"施放技能:"+config.uuid); - - this.doSkill(config,is_wfuny,dmg); - - + let wfuny=this.check_wfuny() + let dmg=0 + this.doSkill(config,wfuny,dmg); } - use_max_skill(e:GameEvent,data:any){ - if(!this.HeroView) return - if(this.HeroView.fac==FacSet.MON) return - //console.log("[SkillConComp]:use_max_skill:",data) - this.skill_id_counter++; - this.aoe_queues.push({ - id: this.skill_id_counter, - s_uuid:data.uuid, - count:SkillSet[data.uuid].maxC, - damage:0}) - // 初始化该技能的计时器 - this.aoe_timers.set(this.skill_id_counter, 0); - } private doSkill(config: typeof SkillSet[keyof typeof SkillSet],is_wfuny:boolean=false,dmg:number=0) { // 添加节点有效性检查 diff --git a/assets/script/game/map/MissionComp copy.ts b/assets/script/game/map/MissionComp copy.ts deleted file mode 100644 index 8b8fe7b0..00000000 --- a/assets/script/game/map/MissionComp copy.ts +++ /dev/null @@ -1,413 +0,0 @@ -import { _decorator,Button,EventHandler,EventTouch,Label,NodeEventType,resources,Sprite,SpriteAtlas,tween,UITransform,v3, Vec3,Animation, UI, instantiate, Prefab, screen } 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 { smc } from "../common/SingletonModuleComp"; -import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; -import { FightSet, HeroUI, MissionData, VmInfo} from "../common/config/Mission"; -import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer"; -import { GameEvent } from "../common/config/GameEvent"; -import { HeroViewComp } from "../hero/HeroViewComp"; -import { Hero } from "../hero/Hero"; -import { defaultEnhancements, EnhancementOptions } from "../common/config/LevelUp"; -import { MonModelComp } from "../hero/MonModelComp"; -import { TalentSlot } from "../common/config/TalentSet"; -import { RogueTalWave } from "./RogueConfig"; -import { cardType, getRandomCardsByType, SuperCards, SuperCardsList, SuperCardsType } from "../common/config/CardSet"; -import { LuckCardComp } from "./LuckCardComp"; -const { ccclass, property } = _decorator; - - -//@todo this is a test - -/** 视图层对象 */ -@ccclass('MissionComp') -@ecs.register('MissionComp', false) -export class MissionComp extends CCComp { - // VictoryComp:any = null; - // reward:number = 0; - // reward_num:number = 0; - GlodAddTimer:Timer = new Timer(1); - normal_max_wave:number = 10; - is_fight:boolean = false; - enhancements:any=[0,0,0,0,0] - update_count:number = 0; - is_show_time:boolean = false; - time_num:number = 0; - time_cd:Timer=new Timer(1); - - next_func?:Function; - wave_time_num:number = 0; - wave_time_cd:Timer=new Timer(1); - is_in_wave:boolean = false; - tals:any={ - 0:false, - 1:false, - 2:false, - 3:false, - 4:false, - 5:false, - } - heros:any={ - 0:{uuid:0,count:0}, - 1:{uuid:0,count:0}, - 2:{uuid:0,count:0}, - } - func_queue:any=[] - - - onLoad(){ - this.on(GameEvent.MissionStart,this.mission_start,this) - this.on(GameEvent.MasterCalled,this.ready_to_fight,this) - // this.on(GameEvent.CardsClose,this.after_used_skill_card,this) - this.on(GameEvent.MonDead,this.do_mon_dead,this) - - this.on(GameEvent.FightEnd,this.fight_end,this) - this.on(GameEvent.MissionEnd,this.mission_end,this) - this.on(GameEvent.DO_AD_BACK,this.do_ad,this) - // this.on(GameEvent.CanUpdateLv,this.show_uplv_button,this) - this.on(GameEvent.UseHeroCard,this.hero_called,this) - } - - protected update(dt: number): void { - if(!smc.mission.play||smc.mission.pause){ - return - } - if(smc.vmdata.mission_data.in_fight){ - smc.vmdata.mission_data.fight_time+=dt - if(this.GlodAddTimer.update(dt)){ - smc.vmdata.mission_data.gold+=(smc.vmdata.mission_data.add_gold+smc.vmdata.mission_data.buff_add_gold) - } - } - if(this.is_show_time){ - if(this.time_cd.update(dt)){ - this.run_time() - } - } - // if(this.is_in_wave){ - // if(this.wave_time_cd.update(dt)){ - // smc.vmdata.mission_data.wave_time_num-- - // if(smc.vmdata.mission_data.wave_time_num<=0){ - // this.hide_wave_time() - // this.show_time(this.do_next_wave.bind(this)) - // } - // } - // } - } - //奖励发放 - do_reward(){ - // 奖励发放 - } - hero_called(event: any, data: any) { - // 查找空位或已存在的英雄 - const heroIndex = this.findHeroSlot(data.uuid); - - if (heroIndex !== -1) { - // 找到英雄位置,增加数量 - this.heros[heroIndex].count += 1; - } else { - // 查找空位 - const emptySlot = this.findEmptySlot(); - if (emptySlot !== -1) { - // 有空位,添加新英雄 - this.heros[emptySlot].uuid = data.uuid; - this.heros[emptySlot].count = 1; - } else { - console.log("[MissionComp] 英雄已满"); - } - } - } - - /** - * 查找英雄位置 - * @param uuid 英雄UUID - * @returns 英雄索引,未找到返回-1 - */ - private findHeroSlot(uuid: number): number { - for (let i = 0; i < 3; i++) { - if (this.heros[i].uuid === uuid) { - return i; - } - } - return -1; - } - - /** - * 查找空位 - * @returns 空位索引,无空位返回-1 - */ - private findEmptySlot(): number { - for (let i = 0; i < 3; i++) { - if (this.heros[i].uuid === 0) { - return i; - } - } - return -1; - } - - count_tal(){ - let count=0 - for(let i=0;i{ - loading.active=false - this.node.getChildByName("ending").active=false - },0.5) - this.to_ready() - - - } - to_ready(){ - console.log("[MissionComp] ** 2 ** to_ready") - oops.message.dispatchEvent(GameEvent.HeroSelect,{called:[]}) - } - ready_to_fight(){ - console.log("[MissionComp] ** 3 ** ready_to_fight") - this.time_num=5 - this.show_time(this.to_fight.bind(this)) - } - // show_uplv_button(){ - // this.update_count++ - // this.node.getChildByName("uplv").active=true - // } - // hide_uplv_button(){ - // this.update_count-- - // if(this.update_count > 0) return - // this.node.getChildByName("uplv").active=false - // } - // to_uplv(){ - // oops.message.dispatchEvent(GameEvent.EnhancementSelect) - // } - to_call_friend(){ - let called = Object.values(this.heros).filter((item: any) => item.uuid != 0) - oops.message.dispatchEvent(GameEvent.HeroSelect,{called:called}) - } - - to_fight(){ - console.log("[MissionComp] ** 4 ** to_fight") - smc.vmdata.mission_data.in_fight=true - oops.message.dispatchEvent(GameEvent.FightStart) //MissionMonComp 监听刷怪 - this.do_next_wave() - } - - - to_end_fight(){ - oops.message.dispatchEvent(GameEvent.FightEnd) - } - - - fight_end(){ - console.log("任务结束") - this.node.getChildByName("ending").active=true - this.node.getChildByName("ending").getComponent(Animation).play("endFight") - // 延迟0.5秒后执行任务结束逻辑 - this.scheduleOnce(() => { - smc.mission.play=false - smc.mission.pause=false - this.cleanComponents() - }, 0.5) - } - - mission_end(){ - this.node.getChildByName("ending").active=false - this.node.active=false - } - - data_init(){ - //局内数据初始化 smc 数据初始化 - smc.mission.play = true; - smc.vmdata.mission_data = JSON.parse(JSON.stringify(MissionData)); - smc.vmdata.hero = JSON.parse(JSON.stringify(VmInfo)); - smc.vmdata.boss = JSON.parse(JSON.stringify(VmInfo)); - this.update_count=0 - this.GlodAddTimer=new Timer(smc.vmdata.mission_data.refrsh_time) - smc.enhancements=defaultEnhancements() - this.heros={ - 0:{uuid:0,count:0}, - 1:{uuid:0,count:0}, - 2:{uuid:0,count:0}, - } - - this.clear_time() - this.hide_wave_time() - this.tals={ - 0:false, - 1:false, - 2:false, - 3:false, - 4:false, - 5:false, - } - smc.vmdata.mission_data.wave_time_num=FightSet.ONE_WAVE_TIME - console.log("局内数据初始化",smc.enhancements,defaultEnhancements()) - - } - - - card_init(){ - oops.message.dispatchEvent(GameEvent.CardRefresh) - } - - card_refresh(){ - let mission_data=smc.vmdata.mission_data - if(mission_data.gold < (mission_data.refresh_gold+mission_data.buff_refresh_gold)){ - oops.gui.toast("金币不足", false); - return - } - oops.message.dispatchEvent(GameEvent.CardRefresh) - mission_data.gold-=(mission_data.refresh_gold+mission_data.buff_refresh_gold) - - } - call_friend_card(){ - oops.message.dispatchEvent(GameEvent.HeroSelect) - } - call_tal_card(){ - oops.message.dispatchEvent(GameEvent.TalentSelect) - } - call_func_card(){ - if(smc.vmdata.mission_data.gold < smc.vmdata.mission_data.lucky_gold){ - oops.gui.toast("金币不足", false); - return - } - this.do_lucky_card() - - } - do_lucky_card(){ - smc.vmdata.mission_data.gold-=smc.vmdata.mission_data.lucky_gold - let list=getRandomCardsByType(cardType.SPECIAL,1) - let card=SuperCards[list[0].uuid] - console.log("[MissionComp] do_lucky_card",card) - this.show_lucky_gold(card) - oops.message.dispatchEvent(GameEvent.LuckCardUsed,card) - } - show_lucky_gold(card:any){ - // this.node.getChildByName("luckybox").getComponent(Animation).play("luckyopen") - var path = "game/gui/lcard"; - var prefab: Prefab = oops.res.get(path, Prefab)!; - var node = instantiate(prefab); - node.setScale(0,0,0) - node.getComponent(LuckCardComp).show_card(card) - node.parent = this.node - node.setPosition(v3(this.node.getChildByName("luckybox").position.x,this.node.getChildByName("luckybox").position.y)); - let height=this.node.getComponent(UITransform).height - tween(node) .to(1, { - scale: v3(1,1,1), - position: v3(0, height-300), - }, {easing:"backOut"}) - .start(); - - } - private cleanComponents() { - smc.vmdata.hero1=JSON.parse(JSON.stringify(HeroUI)) - smc.vmdata.hero2=JSON.parse(JSON.stringify(HeroUI)) - smc.vmdata.hero3=JSON.parse(JSON.stringify(HeroUI)) - ecs.query(ecs.allOf(HeroViewComp)).forEach(entity => {entity.remove(HeroViewComp);entity.destroy()}); - } - - - /** 视图层逻辑代码分离演示 */ - - /** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */ - reset() { - this.node.destroy(); - } -} \ No newline at end of file diff --git a/assets/script/game/skills/SkillCom-001.ts b/assets/script/game/skills/SkillCom-001.ts deleted file mode 100644 index 2897f1d5..00000000 --- a/assets/script/game/skills/SkillCom-001.ts +++ /dev/null @@ -1,338 +0,0 @@ -import { _decorator,Collider2D ,Contact2DType,v3,IPhysics2DContact,Vec3, tween, math, RigidBody2D, Animation, sp, Tween} 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 { smc } from "../common/SingletonModuleComp"; -import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; -import { GameEvent } from "../common/config/GameEvent"; -import { AType, DTType, EType, RType, SkillSet, SType, TGroup } from "../common/config/SkillSet"; -import { BoxSet, FacSet } from "../common/config/BoxSet"; -import { HeroViewComp } from "../hero/HeroViewComp"; -import { BezierMove } from "../BezierMove/BezierMove"; -import { MonModelComp } from "../hero/MonModelComp"; -import { FightSet } from "../common/config/Mission"; -import { HeroModelComp } from "../hero/HeroModelComp"; -import { Skill } from "./Skill"; - - -const { ccclass, property } = _decorator; - -/** 视图层对象 */ -@ccclass('SkillCom') -@ecs.register('SkillCom') -export class SkillCom extends CCComp { - s_uuid:number = 0; - s_name:string = ""; - hero:number = 0; - speed:number = 200; - scale:number = 1; - angle:number = 0; - atk_count:number = 0; - is_destroy:boolean = false; - enemys:any = []; - AType: number = 0; // 运动类型 - startPos: Vec3 = v3(); // 起始位置 - targetPos: Vec3 = v3(); // 目标位置 - duration: number = 0; // 技能持续时间 - prefabName: string = ""; // 预制体名称 - animName: string = ""; - group:number = 0; //阵营 - fac:number=0; //阵营 - caster:any=null; - distance_x:number=0; - distance_y:number=0; - ap:number=0; - buV:number=0; - buC:number=0; - buR:number=0; - burn_count:number=0; - burn_value:number=0; - stun_time:number=0; - stun_ratto:number=0; - frost_ratto:number=0; - frost_time:number=0; - run_time:number=0; - hited_time:number=0; - hit_count:number=0; - spine:sp.Skeleton=null; - anim:Animation=null; - tweenInstance:Tween = null; - t_end_x:number=0; - caster_crit:number=0; - caster_crit_d:number=0; - puncture:number=0; - puncture_damage:number=0; - EType:any=null - private moveDirection: Vec3 | null = null; // 添加一个属性来存储移动方向 - - protected onLoad(): void { - - } - - start() { - this.EType=SkillSet[this.s_uuid].EType - this.node.setPosition(this.startPos.x,this.startPos.y,0) - if(this.node.getChildByName('anm')){ - this.spine=this.node.getChildByName('anm').getComponent('sp.Skeleton') as sp.Skeleton; - }else{ - this.anim=this.node.getComponent(Animation) - } - this.on(GameEvent.MissionEnd, this.doDestroy, this); - this.node.active = true; - //console.log("[SkillCom]:caster",this.caster) - - - 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(SkillSet[this.s_uuid].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.executeTwoStageMovement(); - break; - case AType.fixedEnd: - this.node.setPosition(this.targetPos.x > 360?300:this.targetPos.x,0,0) - if(this.node.getComponent(Animation)){ - let anim = this.node.getComponent(Animation); - //console.log("[SkillCom]:has anim",anim) - anim.on(Animation.EventType.FINISHED, this.onAnimationFinished, this); - } - if(this.node.getChildByName('anm')){ - if(this.node.getChildByName('anm').getComponent('sp.Skeleton')){ - //console.log("[SkillCom]:has spine",this.spine) - this.spine.setCompleteListener((trackEntry) => { - this.onAnimationFinished() - //console.log("[SkillCom]:[track %s][animation %s] complete: %s", trackEntry.trackIndex); - }); - } - } - break; - case AType.fixedStart: // - - this.node.setPosition(this.startPos.x > 360?300:this.startPos.x,0,0) - - if(this.node.getComponent(Animation)){ - let anim = this.node.getComponent(Animation); - //console.log("[SkillCom]:has anim",anim) - anim.on(Animation.EventType.FINISHED, this.onAnimationFinished, this); - } - if(this.node.getChildByName('anm')){ - if(this.node.getChildByName('anm').getComponent('sp.Skeleton')){ - //console.log("[SkillCom]:has spine",this.spine) - this.spine.setCompleteListener((trackEntry) => { - this.onAnimationFinished() - //console.log("[SkillCom]:[track %s][animation %s] complete: %s", trackEntry.trackIndex); - }); - } - } - break; - } - - - } - - onAnimationFinished(){ - console.log("[SkillCom]:onAnimationFinished",this.s_uuid) - if(SkillSet[this.s_uuid].EType==EType.timeEnd) return - this.is_destroy=true - } - //范围伤害 - range_damage(){ - // console.log("[SkillCom]:range_damage",this.s_uuid) - let enemys=ecs.query(ecs.allOf(MonModelComp)) - if(this.fac==FacSet.MON) enemys=ecs.query(ecs.allOf(HeroModelComp)) - enemys.forEach(entity => { - let view=entity.get(HeroViewComp) - if(view){ - let dis_x =Math.abs(this.node.position.x-view.node.position.x) - let dis_y =Math.abs(this.node.position.y-view.node.position.y) - if(dis_x > SkillSet[this.s_uuid].with||dis_y > SkillSet[this.s_uuid].with) return - this.single_damage(view,true) - } - }); - } - //单体伤害 - single_damage(target:HeroViewComp,is_range:boolean=false){ - // //console.log("[SkillCom]:onBeginContact hit_count:",this.hit_count,SkillSet[this.s_uuid].hit) - // if(this.hit_count > 0&&!is_range) this.ap=this.ap*(50+this.puncture_damage)/100 // 穿刺后 伤害减半,过滤范围伤害 - if(target == null) return; - let ap=this.ap - if(this.hit_count > 0 &&!is_range ){ - ap=ap*(50+this.puncture_damage)/100 - } - target.do_atked(ap,this.caster_crit,this.caster_crit_d, - this.burn_count,this.burn_value, - this.stun_time,this.stun_ratto, - this.frost_time,this.frost_ratto) // ap 及暴击 属性已经在skill.ts 处理 - // console.log("[SkillCom]:single_damage t:tp:rtp",this.node.position,this.targetPos,target.node.position) - if(SkillSet[this.s_uuid].debuff>0){ - let debuff=SkillSet[this.s_uuid] - let dev=debuff.deV*(100+this.caster.DEBUFF_VALUE)/100 - let deR=debuff.deR+this.caster.DEBUFF_UP - dev=Math.round(dev*100)/100 - let deC=debuff.deC+this.caster.DEBUFF_COUNT //dec只作为次数叠加 - // //console.log("[SkillCom]:debuff",SkillSet[this.s_uuid].name,debuff.debuff,deUP.deV,deUP.deC) - target.add_debuff(debuff.debuff,dev,deC,deR) - } - this.hit_count++ - // console.log("[SkillCom]:碰撞次数:技能次数:穿刺次数",this.hit_count,SkillSet[this.s_uuid].hit,this.puncture) - if(this.hit_count>=(SkillSet[this.s_uuid].hit+this.puncture)&&(SkillSet[this.s_uuid].DTType!=DTType.range)&&(SkillSet[this.s_uuid].EType!=EType.animationEnd)) this.is_destroy=true // 技能命中次数 - } - - onBeginContact (seCol: Collider2D, oCol: Collider2D) { - // console.log(this.scale+"碰撞开始 ",seCol,oCol); - if(seCol.node.position.x-oCol.node.position.x > 100 ) return - let target = oCol.getComponent(HeroViewComp) - if(oCol.group!=this.group){ - if(target == null) return; - // console.log("[SkillCom]:onBeginContact oCol||seCol",oCol.node.position,seCol.node.position) - this.single_damage(target,SkillSet[this.s_uuid].DTType==DTType.range?true:false) - // this.ent.destroy() - } - } - - - /** - * 执行2段位移:先升高,然后移到目的地 - */ - private executeTwoStageMovement() { - const totalDuration = SkillSet[this.s_uuid].in-0.1 - const firstStageDuration = totalDuration * 0.4; // 第一段占40%时间 - const secondStageDuration = totalDuration * 0.6; // 第二段占60%时间 - - // 第一段:升高 - const riseHeight = 100; // 升高高度 - const midPosition = v3(this.node.position.x, this.node.position.y + riseHeight, 0); - - // 第二段:移动到目标位置 - const finalPosition = v3(this.targetPos.x, this.targetPos.y, 0); - - // 创建缓动序列 - tween(this.node) - // 第一段:升高 - .to(firstStageDuration, { position: midPosition }, { - easing: 'quadOut' // 使用二次缓出效果,让上升更自然 - }) - // 第二段:移动到目标位置 - .to(secondStageDuration, { position: finalPosition }, { - easing: 'quadInOut' // 使用二次缓入缓出效果 - }).call(()=>{ - this.do_buff() - }) - .start(); - } - private do_buff(){ - //console.log("[SkillCom]:do_buff") - let teams=ecs.query(ecs.allOf(HeroModelComp)) - if(this.fac==FacSet.MON) teams=ecs.query(ecs.allOf(MonModelComp)) - if(SkillSet[this.s_uuid].TGroup==TGroup.Team||SkillSet[this.s_uuid].TGroup==TGroup.Self) { - teams.forEach(entity => { - let view=entity.get(HeroViewComp) - if(view.node.position.x==this.targetPos.x){ - if(SkillSet[this.s_uuid].SType==SType.heal){ - view.add_hp(this.buV,false) - } - if(SkillSet[this.s_uuid].SType==SType.shield){ - view.add_shield(this.buV) - } - } - }); - } - } - - update(deltaTime: number) { - let config=SkillSet[this.s_uuid] - if(smc.mission.pause) { - if(this.spine) this.spine.paused=true - if(this.anim) this.anim.pause() - return; - } - if(this.anim) this.anim.resume() - if(this.spine) this.spine.paused=false - if (!this.node || !this.node.isValid) return; - if(config.EType==EType.timeEnd){ - this.run_time+=deltaTime - if(this.run_time>config.in){ - // //console.log("[SkillCom]: timeEnd destroy",this.s_uuid,this.run_time) - this.is_destroy=true - } - } - //范围伤害 - this.hited_time+=deltaTime - if(this.hited_time>config.hited&&(SkillSet[this.s_uuid].DTType==DTType.range)){ - this.hited_time=0 - this.range_damage() - } - //直线移动 - // if(this.AType == AType.linear) this.startLinearMove(deltaTime); - this.toDestroy(); - } - - toDestroy() { - if(this.is_destroy){ - if (this.ent) { - this.ent.destroy(); - } else { - // 如果ent不存在,直接销毁节点 - if (this.node && this.node.isValid) { - this.node.destroy(); - } - } - } - } - doDestroy(){ - // //console.log("[SkillCom]:doDestroy") - this.is_destroy=true - } - to_console(value:any,value2:any=null,value3:any=null){ - //console.log("[SkillCom]:["+this.s_name+this.s_uuid+"]:",value,value2,value3) - } - - /** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */ - reset() { - this.is_destroy = false; - this.AType = 0; - this.speed = 0; - this.startPos.set(); - this.targetPos.set(); - this.moveDirection = null; // 重置移动方向 - // 先移除所有碰撞回调 - const collider = this.getComponent(Collider2D); - if (collider) { - collider.off(Contact2DType.BEGIN_CONTACT); - } - this.scheduleOnce(() => { - this.node.destroy(); - }, 0); - } - -} \ No newline at end of file