buff需要重置

This commit is contained in:
panw
2025-10-16 16:52:27 +08:00
parent 31eedceeb3
commit d0cd9c1326
21 changed files with 153 additions and 958 deletions

View File

@@ -1,17 +1,13 @@
import { _decorator, Component, Node, ProgressBar, v3, Vec3 } from 'cc';
import { HeroViewComp } from './HeroViewComp';
import { BuffAttr,SKILL_CONST, SkillSet, SType, TGroup, } 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, FacSet } from '../common/config/BoxSet';
import { FacSet } from '../common/config/BoxSet';
import { smc } from '../common/SingletonModuleComp';
import { CCComp } from 'db://oops-framework/module/common/CCComp';
import { MonModelComp } from './MonModelComp';
import { HeroModelComp } from './HeroModelComp';
import { FightSet } from '../common/config/Mission';
import { Timer } from 'db://oops-framework/core/common/timer/Timer';
import { SkillEnt } from '../skill/SkillEnt';
const { ccclass, property } = _decorator;
@@ -28,7 +24,6 @@ export class SkillConComp extends CCComp {
onLoad(){
this.HeroView=this.node.getComponent(HeroViewComp)
// //console.log(this.HeroView.uid+"=>"+this.HeroView.hero_name+"=> SkillConComp onLoad")
}
start() {
// //console.log(this.HeroView.uuid+"=>"+this.HeroView.hero_name+"=> SkillConComp start")
@@ -42,28 +37,16 @@ export class SkillConComp extends CCComp {
let skills=this.HeroView.skills
for(let i=0;i<skills.length;i++){
skills[i].cd += dt;
if(skills[i].cd > (i==0?this.HeroView.Attrs[BuffAttr.ATK_CD]:skills[i].cd_max)){
if(skills[i].cd > skills[i].cd_max&&this.HeroView.mp >= skills[i].cost){
if(SkillSet[skills[i].uuid].SType==SType.damage&&this.HeroView.is_atking){
this.castSkill(SkillSet[skills[i].uuid])
this.HeroView.skills[i].cd = 0
this.HeroView.mp -= skills[i].cost
}
}
}
if(skills[1]){
if(this.HeroView.fac==FacSet.HERO) {
// console.log("[SkillConComp] 角色状态:",this.HeroView.hero_name+"=>能量:"+this.HeroView.power+"/"+this.HeroView.power_max,skills)
}
this.HeroView.power+=(1+this.HeroView.Attrs[BuffAttr.POWER_UP])*dt*SKILL_CONST.POWER_UP
let progress=this.HeroView.power/this.HeroView.power_max
this.HeroView.node.getChildByName("top").getChildByName("pow").getComponent(ProgressBar).progress=progress
if(this.HeroView.power>this.HeroView.power_max){
this.HeroView.power=0
}
}else{
if(this.HeroView.fac==FacSet.HERO) {
}
}
}
}
@@ -83,29 +66,15 @@ export class SkillConComp extends CCComp {
if (!this.node || !this.node.isValid || !this.HeroView || !this.HeroView.node || !this.HeroView.node.isValid) {
return;
}
let target:any=null
switch(config.TGroup){
case TGroup.Enemy: //单个敌人
target = this.filterFrontRow()
break
case TGroup.Ally: //所有敌人
target = this.selectAllyTargets()
break
case TGroup.Self: //自身
target = this.node.position
break
case TGroup.Team: //所有友方
target = this.node.position
break
case TGroup.All: //所有单位
break
let targets:any=null
if(config.TGroup==TGroup.Self){
targets = [this.node.position]
}
if(config.TGroup==TGroup.Enemy){
targets = this.selectTargets(config.t_num)
}
this.HeroView.playSkillEffect(config.uuid)
const sEnt = ecs.getEntity<SkillEnt>(SkillEnt);
const timerId = setTimeout(() => {
// 再次检查节点有效性
if (!this.node || !this.node.isValid || !this.HeroView || !this.HeroView.node || !this.HeroView.node.isValid) {
@@ -113,10 +82,10 @@ export class SkillConComp extends CCComp {
}
console.log("技能开始",sEnt)
sEnt.load(
new Vec3(this.HeroView.node.position.x,this.HeroView.node.position.y,0),
this.node.position,
this.node.parent,
config.uuid,
[new Vec3(target.x, target.y, 0)],
targets,
this.HeroView,
dmg
);
@@ -153,72 +122,52 @@ export class SkillConComp extends CCComp {
let keyEntity = entities.find(e => e.get(HeroViewComp).node.position.x === keyPos);
return keyEntity.get(HeroViewComp).node.position;
}
/** 筛选最前排单位 */
private filterFrontRow(): Vec3{
// 敌方最前排是x坐标最大的我方最前排是x坐标最小的,若目标不存在,敌人 取400,我方取-400
let pos=v3(0,0)
let entities=this.check_target()
if(entities.length==0){
if(this.HeroView.fac==FacSet.HERO){
return v3(400,0)
}else{
return v3(-400,0)
}
}
pos=v3(this.get_front(entities))
return pos
}
private selectAllyTargets( ): Vec3 {
// 敌方最前排是x坐标最大的+50我方最前排是x坐标最小的+50,若目标不存在,敌人 取320/2,我方取-320/2
let kp=50
if(this.HeroView.fac==FacSet.MON) kp=0
let pos=v3(0,0)
let entities=this.check_target()
if(entities.length==0){
if(this.HeroView.fac==FacSet.HERO){
return v3(320/2+kp,0)
}else{
return v3(-320/2-kp,0)
/**
* 选择目标(整合版)
* @param t_num 目标数量,第一个是最近的前排,后续随机(可重复)
* @returns 目标坐标数组
*/
private selectTargets(t_num: number): Vec3[] {
const targets: Vec3[] = [];
const entities = this.check_target();
// 如果没有目标实体
if (entities.length === 0) {
const defaultPos = this.HeroView.fac === FacSet.HERO ? v3(400, 0, 0) : v3(-400, 0, 0);
// 返回t_num个相同的默认位置
for (let i = 0; i < t_num; i++) {
targets.push(defaultPos.clone());
}
return targets;
}
pos=v3(this.get_front(entities).x+kp,this.get_front(entities).y-BoxSet.ATK_Y,0)
return pos
}
/** 随机选择目标 */
private pickRandomTarget(count: number): ecs.Entity[] {
let entities:any=null
if(this.HeroView.fac==FacSet.HERO){
entities = ecs.query(ecs.allOf(MonModelComp))
}else{
entities = ecs.query(ecs.allOf(HeroModelComp))
// 第一个目标:最前排(离施法者最近的)
const frontPos = this.get_front(entities);
targets.push(v3(frontPos.x, frontPos.y, 0));
// 后续目标:随机选择(可以重复)
for (let i = 1; i < t_num; i++) {
const randomEntity = entities[Math.floor(Math.random() * entities.length)];
const randomPos = randomEntity.get(HeroViewComp).node.position;
targets.push(v3(randomPos.x, randomPos.y, 0));
}
const shuffled = [...entities].sort(() => 0.5 - Math.random());
return shuffled.slice(0, count);
return targets;
}
public clear_timer() {
// console.log("[SkillConComp]:clear_timer",this.HeroView);
Object.values(this._timers).forEach(clearTimeout);
}
get_count(count:number,view:HeroViewComp){
let re=count+view.wfuny
if(re<1) re=1
return re
}
reset() {
this.clear_timer();
}
onDestroy() {
// 清理所有定时器
// console.log("[SkillConComp]:onDestroy:",this.node.name)