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

@@ -8,9 +8,6 @@ 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 { BuffAttr, getBuffNum, SkillSet, SType } from "../common/config/SkillSet";
import { FightSet } from "../common/config/Mission";
import { Skill } from "../skills/Skill";
/** 角色实体 */
@ecs.register(`Hero`)
@@ -73,31 +70,32 @@ export class Hero extends ecs.Entity {
hv.box_group = BoxSet.HERO;
hv.hero_uuid= uuid;
hv.hero_name= hero.name;
hv.Attrs=getBuffNum()
hv.Attrs[BuffAttr.SPEED]=hv.speed = hero.speed;
hv.Attrs[BuffAttr.DIS]=hv.dis=hero.dis;
hv.Attrs[BuffAttr.ATK_CD]=hv.cd=hero.cd
hv.Attrs[BuffAttr.HP_MAX]=hv.hp=hv.hp_max=HeroInfo[uuid].hp;
hv.Attrs[BuffAttr.AP]=hv.ap=HeroInfo[uuid].ap;
hv.Attrs[BuffAttr.DEF]=HeroInfo[uuid].def;
hero.buff.forEach((buff:any)=>{
hv.apply_buff(buff.type,buff.value)
})
for(let i=0;i<hero.skills.length;i++){
if(SkillSet[hero.skills[i]].SType==SType.buff){
let buffs=SkillSet[hero.skills[i]].buffs
buffs.forEach((buff:any)=>{
hv.apply_buff(buff.buff, buff.buV)
})
continue
}else{
hv.skills.push({
cd:0,
uuid:hero.skills[i],
cd_max:i==0?hero.cd:SkillSet[hero.skills[i]].cd
})
}
}
hv.hp=hv.hp_max=hv.hp_base=HeroInfo[uuid].hp;
hv.mp=hv.mp_max=hv.mp_base=HeroInfo[uuid].mp;
// hv.Attrs=getBuffNum()
// hv.Attrs[BuffAttr.SPEED]=hv.speed = hero.speed;
// hv.Attrs[BuffAttr.DIS]=hv.dis=hero.dis;
// hv.Attrs[BuffAttr.ATK_CD]=hv.cd=hero.cd
// hv.Attrs[BuffAttr.AP]=hv.ap=HeroInfo[uuid].ap;
// hv.Attrs[BuffAttr.DEF]=HeroInfo[uuid].def;
// hero.buff.forEach((buff:any)=>{
// hv.apply_buff(buff.type,buff.value)
// })
// for(let i=0;i<hero.skills.length;i++){
// if(SkillSet[hero.skills[i]].SType==SType.buff){
// let buffs=SkillSet[hero.skills[i]].buffs
// buffs.forEach((buff:any)=>{
// hv.apply_buff(buff.buff, buff.buV)
// })
// continue
// }else{
// hv.skills.push({
// cd:0,
// uuid:hero.skills[i],
// cd_max:i==0?hero.cd:SkillSet[hero.skills[i]].cd
// })
// }
// }
return hv
}
}

View File

@@ -1,9 +1,7 @@
import { _decorator } 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 { GameEvent } from "../common/config/GameEvent";
import { HeroViewComp } from "./HeroViewComp";
import { BuffAttr } from "../common/config/SkillSet";
const { ccclass, property } = _decorator;

View File

@@ -11,8 +11,7 @@ import { oops } from "db://oops-framework/core/Oops";
import { GameEvent } from "../common/config/GameEvent";
import { FightSet, getExpDrops, getStoneDrops, TooltipTypes } from "../common/config/Mission";
import { RandomManager } from "db://oops-framework/core/common/random/RandomManager";
import { Items, MonsterDropManager } from "../common/config/Items";
import { HeroInfo } from "../common/config/heroSet";
import { HeroInfo, HeroUpSet } from "../common/config/heroSet";
const { ccclass, property } = _decorator;
@@ -45,9 +44,12 @@ export class HeroViewComp extends CCComp {
speed_base: number = 100; /** 角色初始速度 */
power:number=0;
power_max:number=100;
mp: number = 0;
mp_max: number = 100;
mp_base: number = 100;
hp: number = 100; /** 血量 */
hp_max: number = 100; /** 最大血量 */
hp_base:number=0;
hp_base:number=100; /** 基础最大血量 */
shield:number=0; //当前护甲值
shield_max:number=0; //最大护甲值
ap: number = 10; /**攻击力 */
@@ -152,14 +154,13 @@ export class HeroViewComp extends CCComp {
// this.ent.destroy();
// return
// }
this.BaseUp(dt)
if(this.DEBUFF_FROST > 0){
this.DEBUFF_FROST -=dt;
}
if(this.DEBUFF_STUN > 0){
this.DEBUFF_STUN -=dt;
}
// 更新所有按时间减少的buff和debuff
this.updateBuffsAndDebuffs(dt);
this.in_stop(dt);
@@ -167,6 +168,12 @@ export class HeroViewComp extends CCComp {
this.processDamageQueue();
}
BaseUp(dt:number){
this.mp += HeroUpSet.MP*dt
this.hp += HeroUpSet.HP*dt
if(this.mp > this.mp_max) this.mp = this.mp_max
if(this.hp > this.hp_max) this.hp = this.hp_max
}
do_fight_end(){
this.as.do_buff()
}
@@ -202,7 +209,7 @@ export class HeroViewComp extends CCComp {
add_hp(hp: number = 0,is_num:boolean=true) {
this.BUFFCOMP.heathed();
let real_hp=0
let hp_max=this.Attrs[BuffAttr.HP_MAX]
let hp_max=this.hp_max
let lost_hp=hp_max-this.hp
if(is_num){
if(lost_hp > hp){
@@ -221,7 +228,7 @@ export class HeroViewComp extends CCComp {
this.hp+=real_hp;
this.BUFFCOMP.tooltip(TooltipTypes.health,real_hp.toFixed(0));
}
this.BUFFCOMP.hp_show(this.hp,this.Attrs[BuffAttr.HP_MAX])
this.BUFFCOMP.hp_show(this.hp,this.hp_max)
// this.update_vm
}
@@ -269,30 +276,7 @@ export class HeroViewComp extends CCComp {
}
do_drop(){
let drop_item=MonsterDropManager.calculateMonsterDrops(this.hero_uuid,smc.data.mission,1)
this.scheduleOnce(()=>{
if(smc.guides[2]==0&&smc.current_guide==2&&smc.guides[1]==1) {
drop_item.push({item_uuid:Items[1008].uuid,count:20})
}
},0.1)
let {exp,gold,diamond}=MonsterDropManager.calculateBaseResourceDrops(HeroInfo[this.hero_uuid].quality,smc.data.mission,this.BUFFS.length)
oops.message.dispatchEvent(GameEvent.MonDead,{mon_uuid:this.hero_uuid,drops:drop_item,game_data:{exp:exp, gold:gold, diamond:diamond}})
if(drop_item.length>0){
for(let i=0;i<drop_item.length;i++){
let d_item=drop_item[i]
smc.addItem(d_item.item_uuid,d_item.count)
}
}
if(exp>0){
smc.addExp(exp)
}
if(gold>0){
smc.addGold(gold)
}
if(diamond>0){
smc.addDiamond(diamond)
}
// console.log("[HeroViewComp]:do_drop",this.hero_uuid,drop_item,exp,gold,diamond)
}
add_debuff(type:number,deV:number,deC:number,deR:number){
let n_deR=deR-this.Attrs[BuffAttr.DEBUFF_DOWN]
@@ -325,8 +309,9 @@ export class HeroViewComp extends CCComp {
// this.is_stop=true
break
case DebuffAttr.DEHP:
this.Attrs[BuffAttr.HP_MAX]-=deV/100*this.Attrs[BuffAttr.HP_MAX]
if(this.hp-this.Attrs[BuffAttr.HP_MAX]>0) this.hp=this.Attrs[BuffAttr.HP_MAX]
this.Attrs[BuffAttr.HP_MAX]-=deV
this.hp_max=Math.floor(this.hp_base*(100+this.Attrs[BuffAttr.HP_MAX]))
if(this.hp-this.hp_max>0) this.hp=this.hp_max
break
case DebuffAttr.DEATK: //99为具体数字 并且局内永久生效,其他为百分比
if(deC == 99){
@@ -409,8 +394,10 @@ export class HeroViewComp extends CCComp {
case BuffAttr.ATK_CD: //攻击速度百分比
this.Attrs[BuffAttr.ATK_CD]+=buff_value/100*this.cd
break
case BuffAttr.HP: //血量百分比
this.Attrs[BuffAttr.HP_MAX]+=Math.floor(buff_value/100*this.hp_max)
case BuffAttr.HP_MAX: //血量百分比
this.Attrs[BuffAttr.HP_MAX]+=buff_value
this.hp_max=Math.floor(this.hp_base*(100+this.Attrs[BuffAttr.HP_MAX]))
if(this.hp-this.hp_max>0) this.hp=this.hp_max
break
default:
this.Attrs[buff_type]+=buff_value

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)