修复 buff 逻辑处理 bug : 预制体不能设置全局监听oops.message.on,会一直执行

This commit is contained in:
2024-08-28 00:09:55 +08:00
parent 5b1991c90f
commit 4096a17330
15 changed files with 195 additions and 143 deletions

View File

@@ -5,7 +5,7 @@
* @LastEditTime: 2022-08-17 12:36:18
*/
import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite} from "cc";
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 { MonsterSpine } from "./MonsterSpine";
@@ -18,9 +18,8 @@ import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/O
import { Skill } from "../skills/Skill";
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
import { SkillCom } from "../skills/SkillCom";
import { SkillSet } from "../common/config/SkillSet";
import { BoxRangComp } from "./BoxRangComp";
import { Tooltip } from "../skills/Tooltip";
import { Tooltip } from "../skills/Tooltip";
import { MonsterViewComp } from "./MonsterViewComp";
const { ccclass, property } = _decorator;
@@ -33,64 +32,49 @@ export class MonsterBuffComp extends CCComp {
mv!: MonsterViewComp;
timer:Timer = new Timer(0.1);
buffs:Array<number>=[];
buffs_arr:any=[];
buffs:any=[];
group:number=0;
/**
skill_uuid:number=0;
atk:number=0;
hp:number=0;
shield:number=0;
time:number=0;
**/
onLoad() {
this.as = this.node.getComponent(MonsterSpine);
this.mv= this.getComponent(MonsterViewComp);
} /** 视图层逻辑代码分离演示 */
start () {
// 注册单个碰撞体的回调函数
let collider = this.getComponent(Collider2D);
if (collider) {
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
collider.on(Contact2DType.PRE_SOLVE, this.onPreSolve, this);
collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
}
// this.node.getChildByName("level").getChildByName("level").getComponent(Label).string = this.level.toString();
}
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D) {
if(otherCollider.tag==BoxSet.SKILL_TAG &&selfCollider.tag!=BoxSet.SKILL_TAG){
if(selfCollider.group != otherCollider.group){
add_buff(uuid:number=0,eid:number=0,group:number=0){
// console.log("add_buff",event,args,smc.skills[uuid]);
let new_buff={
skill_uuid:uuid,
skill_name:smc.skills[uuid].name,
atk:smc.skills[uuid].atk,
hp:smc.skills[uuid].hp,
shield:smc.skills[uuid].shield,
time:smc.skills[uuid].bsd,
bcd:smc.skills[uuid].bcd,
sk_uuid:smc.skills[uuid].uuid,
}
if(eid !=0 && group ==0 ){
if(this.mv.ent.eid == eid){
this.buff_add(new_buff);
}
}
}
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D) { }
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
}
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
if(selfCollider.group == otherCollider.group&&otherCollider.tag == 0&&selfCollider.tag == 0){
let self_pos=selfCollider.node.getPosition();
let other_pos=otherCollider.node.getPosition();
// console.log('monster view group 相同');
switch (selfCollider.group) {
case BoxSet.HERO:
break;
case BoxSet.MONSTER:
break
}
if(eid ==0 && group == this.group){
this.buff_add(new_buff);
}
}
update(dt: number){
if (this.timer.update(dt)) {
this.buff_update()
@@ -102,21 +86,45 @@ export class MonsterBuffComp extends CCComp {
this.node.destroy();
}
buff_add(time:number,atk:number){
buff_add(buff:any){
// console.log("buff add:",this.buffs);
if(!this.node.isValid){ return }
let i = 0
if(this.buffs.length >=0){
this.buffs.forEach((b:any,index:number)=>{
if(b.skill_uuid==buff.skill_uuid){
b.time=buff.time;
this.mv.atk+=(buff.atk-b.atk);
this.mv.hp+=(buff.hp-b.hp);
this.mv.hp_max+=(buff.hp-b.hp);
this.mv.shield=buff.shield-b.shield;
i=index
}
})
}
if (i==0||this.buffs.length==0) {
this.buffs.push(buff);
this.mv.atk+=buff.atk;
this.mv.hp+=buff.hp;
this.mv.hp_max+=buff.hp;
this.mv.shield+=buff.shield;
}
// console.log("buff add:"+this.mv.ent.eid,this.node);
}
buff_remove(index:number){
this.mv.atk=this.mv.atk-this.buffs_arr[index].atk;
this.mv.hp=this.mv.hp-this.buffs_arr[index].hp;
this.mv.shield=this.mv.shield-this.buffs_arr[index].shield;
this.mv.atk=this.mv.atk-this.buffs[index].atk;
this.mv.hp_max=this.mv.hp_max-this.buffs[index].hp;
this.mv.shield=this.mv.shield-this.buffs[index].shield;
// console.log("buff remove:"+this.mv.ent.eid,this.node)
}
buff_update(){
this.buffs_arr.forEach((buff:any,index:number)=>{
this.buffs.forEach((buff:any,index:number)=>{
buff.time -= 0.1;
if(buff.time <= 0){
this.buff_remove(index);
}
})
this.buffs_arr = this.buffs_arr.filter((buff:any) => buff.time > 0);
this.buffs = this.buffs.filter((buff:any) => buff.time > 0);
// console.log(this.buffs,this.buffs);
}
}