buff 添加

This commit is contained in:
2024-08-27 17:42:35 +08:00
parent 007b85fe7f
commit 5b1991c90f

View File

@@ -21,6 +21,7 @@ import { SkillCom } from "../skills/SkillCom";
import { SkillSet } from "../common/config/SkillSet"; import { SkillSet } from "../common/config/SkillSet";
import { BoxRangComp } from "./BoxRangComp"; import { BoxRangComp } from "./BoxRangComp";
import { Tooltip } from "../skills/Tooltip"; import { Tooltip } from "../skills/Tooltip";
import { MonsterViewComp } from "./MonsterViewComp";
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
/** 角色显示组件 */ /** 角色显示组件 */
@@ -29,15 +30,28 @@ const { ccclass, property } = _decorator;
export class MonsterBuffComp extends CCComp { export class MonsterBuffComp extends CCComp {
/** 角色动画 */ /** 角色动画 */
as: MonsterSpine = null!; as: MonsterSpine = null!;
num:number=0; mv!: MonsterViewComp;
timer:Timer = new Timer(0.5);
timer:Timer = new Timer(0.1);
buffs:Array<number>=[];
buffs_arr:any=[];
/**
skill_uuid:number=0;
atk:number=0;
hp:number=0;
shield:number=0;
time:number=0;
**/
onLoad() { onLoad() {
this.as = this.getComponent(MonsterSpine); this.as = this.node.getComponent(MonsterSpine);
this.mv= this.getComponent(MonsterViewComp);
} /** 视图层逻辑代码分离演示 */ } /** 视图层逻辑代码分离演示 */
start () { start () {
console.log("MonsterBuffComp start nmu:"+this.num);
// 注册单个碰撞体的回调函数 // 注册单个碰撞体的回调函数
let collider = this.getComponent(Collider2D); let collider = this.getComponent(Collider2D);
if (collider) { if (collider) {
@@ -77,11 +91,9 @@ export class MonsterBuffComp extends CCComp {
} }
} }
update(dt: number){ update(dt: number){
if (this.timer.update(dt)) { if (this.timer.update(dt)) {
this.num++; this.buff_update()
} }
} }
@@ -90,4 +102,21 @@ export class MonsterBuffComp extends CCComp {
this.node.destroy(); this.node.destroy();
} }
buff_add(time:number,atk:number){
}
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;
}
buff_update(){
this.buffs_arr.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);
}
} }