Files
heros/assets/script/game/monster/MonsterBuffComp.ts

130 lines
4.1 KiB
TypeScript

/*
* @Author: dgflash
* @Date: 2021-11-18 17:42:59
* @LastEditors: dgflash
* @LastEditTime: 2022-08-17 12:36:18
*/
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";
import { Monster } from "./Monster";
import { Hero } from "./Hero";
import { MonsterModelComp } from "./MonsterModelComp";
import { BoxSet } from "../common/config/BoxSet";
import { smc } from "../common/SingletonModuleComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { Skill } from "../skills/Skill";
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
import { SkillCom } from "../skills/SkillCom";
import { BoxRangComp } from "./BoxRangComp";
import { Tooltip } from "../skills/Tooltip";
import { MonsterViewComp } from "./MonsterViewComp";
const { ccclass, property } = _decorator;
/** 角色显示组件 */
@ccclass('MonsterBuffComp') // 定义为 Cocos Creator 组件
@ecs.register('MonsterBuff', false) // 定义为 ECS 组件
export class MonsterBuffComp extends CCComp {
/** 角色动画 */
as: MonsterSpine = null!;
mv!: MonsterViewComp;
timer:Timer = new Timer(0.1);
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 () {
}
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);
}
}
if(eid ==0 && group == this.group){
this.buff_add(new_buff);
}
}
update(dt: number){
if (this.timer.update(dt)) {
this.buff_update()
}
}
reset() {
this.node.destroy();
}
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[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.forEach((buff:any,index:number)=>{
buff.time -= 0.1;
if(buff.time <= 0){
this.buff_remove(index);
}
})
this.buffs = this.buffs.filter((buff:any) => buff.time > 0);
// console.log(this.buffs,this.buffs);
}
}