138 lines
4.7 KiB
TypeScript
138 lines
4.7 KiB
TypeScript
import { _decorator,Sprite ,Color} 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 { RoleViewComp } from "./RoleViewComp";
|
|
import { RoleSpine } from "./RoleSpine";
|
|
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('RoleBuffComp')
|
|
@ecs.register('RoleBuff', false)
|
|
export class RoleBuffComp extends CCComp {
|
|
as: RoleSpine = null!;
|
|
mv!: RoleViewComp
|
|
|
|
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(RoleSpine);
|
|
this.mv= this.getComponent(RoleViewComp);
|
|
} /** 视图层逻辑代码分离演示 */
|
|
start () {
|
|
|
|
|
|
}
|
|
add_buff(uuid:number=0,args:any[]){
|
|
// console.log("add_buff",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,
|
|
args:args
|
|
}
|
|
this.buff_add(new_buff);
|
|
}
|
|
|
|
|
|
update(dt: number){
|
|
if (this.timer.update(dt)) {
|
|
this.buff_update()
|
|
}
|
|
}
|
|
|
|
reset() {
|
|
|
|
this.node.destroy();
|
|
}
|
|
|
|
buff_add(buff:any){
|
|
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;
|
|
if(buff.atk>0){
|
|
this.node.getChildByName("avatar").setScale(1.2,1.2)
|
|
// this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite).color= new Color().fromHEX("#F16F6F");
|
|
this.mv.atk+=(buff.atk+buff.args.atk-b.atk);
|
|
}
|
|
if(buff.hp>0){
|
|
this.mv.hp+=(buff.hp+buff.args.hp);
|
|
this.mv.add_hp(buff.hp+buff.args.hp);
|
|
// this.mv.hp_max+=(buff.hp-b.hp);
|
|
}
|
|
if(buff.shield>0){
|
|
this.mv.shield=(buff.shield+buff.args.shield);
|
|
// this.mv.shield_max=(buff.shield+buff.args.shield);
|
|
}
|
|
|
|
i=index
|
|
}
|
|
})
|
|
}
|
|
if (i==0||this.buffs.length==0) {
|
|
this.buffs.push(buff);
|
|
if(buff.atk>0){
|
|
this.mv.atk+=(buff.atk+buff.args.atk);
|
|
this.node.getChildByName("avatar").setScale(1.2,1.2)
|
|
// this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite).color= new Color().fromHEX("#F16F6F");
|
|
}
|
|
if(buff.hp>0){
|
|
this.mv.hp+=(buff.hp+buff.args.hp);
|
|
this.mv.add_hp(buff.hp+buff.args.hp);
|
|
// this.mv.hp_max+=buff.hp;
|
|
}
|
|
if(buff.shield>0){
|
|
this.mv.shield=(buff.shield+buff.args.shield);
|
|
// this.mv.shield_max=(buff.shield+buff.args.shield);
|
|
}
|
|
|
|
}
|
|
console.log("buff add:",this.mv);
|
|
}
|
|
buff_remove(index:number){
|
|
if(this.buffs[index].atk>0){
|
|
this.mv.atk-=(this.buffs[index].atk+this.buffs[index].args.atk);
|
|
this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite).color= new Color().fromHEX("#FFFFFF");
|
|
this.node.getChildByName("avatar").setScale(1,1)
|
|
}
|
|
if(this.buffs[index].shield>0){
|
|
this.mv.shield=0
|
|
// this.mv.shield_max-=(this.buffs[index].shield+this.buffs[index].args.shield);
|
|
}
|
|
// if(this.buffs[index].hp>0){
|
|
// this.mv.hp_max-=this.buffs[index].hp;
|
|
// }
|
|
console.log("buff remove:",this.mv,this.buffs[index]);
|
|
}
|
|
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);
|
|
}
|
|
} |