Files
heros/assets/script/game/hero/BuffComp.ts
2025-07-31 15:46:25 +08:00

245 lines
7.9 KiB
TypeScript

import { _decorator, Component, instantiate, Label, Node, Prefab, ProgressBar, tween, UITransform, v3, Vec3 } from 'cc';
import { oops } from 'db://oops-framework/core/Oops';
import { ecs } from 'db://oops-framework/libs/ecs/ECS';
import { Tooltip } from '../skills/Tooltip';
import { timedCom } from '../skills/timedCom';
import { smc } from '../common/SingletonModuleComp';
import { HeroViewComp } from './HeroViewComp';
import { GameEvent } from '../common/config/GameEvent';
const { ccclass, property } = _decorator;
@ccclass('BuffComp')
export class BuffComp extends Component {
top_node:any=null;
ap_node:any=null;
cd_node:any=null;
def_node:any=null;
hp_node:any=null;
crit_node:any=null;
ap_cd:number=0;
cd_cd:number=0;
def_cd:number=0;
hp_cd:number=0;
crit_cd:number=0;
deap_cd:number=0;
decd_cd:number=0;
dedef_cd:number=0;
dehp_cd:number=0;
decrit_cd:number=0;
buff_cd:number=0;
wind_cd:number=0;
speek_time:number=0;
HeroView:HeroViewComp=null!
hp_bar:any=null
protected onLoad(): void {
}
start() {
this.info_init()
}
info_init(){
this.HeroView=this.node.getComponent(HeroViewComp)
this.top_node = this.node.getChildByName("top");
let hp_y=this.node.getComponent(UITransform).height+20
this.top_node.setPosition(0,hp_y,0)
this.hp_bar=this.top_node.getChildByName("hp").getComponent(ProgressBar)
// this.top_node.getChildByName("hp").active=(this.node.getComponent(HeroViewComp).fac == 1 ? true : false)
this.vmdata_update()
}
to_update_vmdata(){
this.vmdata_update(false)
}
update(deltaTime: number) {
if(smc.mission.pause) return
this.hp_show()
if(this.wind_cd > 0 ) this.wind_cd -= deltaTime;
if(this.wind_cd <= 0 && this.node.getChildByName("wind").active){
this.node.getChildByName("wind").active = false;
}
if(this.buff_cd > 0 ) this.buff_cd -= deltaTime;
if(this.buff_cd <= 0 && this.node.getChildByName("buff").active){
this.node.getChildByName("buff").active = false;
}
// this.in_speek(deltaTime)
// this.vmdata_update()
}
hp_show(){
// if(this.node.getComponent(HeroViewComp).fac == 0) return
let hp=this.HeroView.hp;
let hp_max=this.HeroView.hp_max;
let hp_progress= hp/hp_max;
this.hp_bar.progress = hp_progress;
if(this.HeroView.is_boss) return
this.top_node.getChildByName("hp").active = (hp == hp_max) ? false : true;
}
show_shield(val:boolean){
this.node.getChildByName("shielded").active=val
}
vmdata_update(is_hp:boolean=false){
// console.log("[BuffComp]:to_update_vmdata:"+this.HeroView.hero_name)
let info= null
if(!this.HeroView) return
if(!this.HeroView.is_master) return
info=smc.vmdata.hero
if(info==null) return
let view_atk = 0 //临时buff
let view_deatk = 0 //临时debuff
if(is_hp){
info.hp=this.HeroView.hp
info.hp_max=this.HeroView.hp_max
}else{
info.hp=this.HeroView.hp
info.hp_max=this.HeroView.hp_max
for(let i=0;i<this.HeroView.BUFF_ATKS.length;i++){
view_atk += this.HeroView.BUFF_ATKS[i].value
}
for(let i=0;i<this.HeroView.DEBUFF_DEATKS.length;i++){
view_deatk += this.HeroView.DEBUFF_DEATKS[i].value
}
info.ap=this.HeroView.ap
// info.lv=this.HeroView.lv
info.cd=Number(this.HeroView.cd.toFixed(2))
info.buff_ap=view_atk
info.debuff_ap=view_deatk
info.damage=this.HeroView.ap*(100+view_atk-view_deatk)/100
info.crit=this.HeroView.crit
info.crit_d=this.HeroView.crit_d
info.dod=this.HeroView.dod
info.def=this.HeroView.def
info.wind=this.HeroView.wfuny
}
}
update_info_lv(){
}
show_wind(t:number=1){
this.wind_cd = t;
this.node.getChildByName("wind").active = true;
}
show_buff(t:number=1){
this.buff_cd = t;
this.node.getChildByName("buff").active = true;
}
max_show(name:string){
var path = "game/skills/"+name;
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
node.parent = this.node;
}
lv_up(){
var path = "game/skills/lvup";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
node.parent = this.node;
}
show_do_buff(name:string){
var path = "game/skills/"+name;
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
let pos = v3(this.node.position.x,this.node.position.y+20,this.node.position.z);
node.parent = this.node.parent;
node.setPosition(pos);
}
dead(){
var path = "game/skills/dead";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
let pos = v3(this.node.position.x,this.node.position.y+30,this.node.position.z);
node.parent = this.node.parent;
node.setPosition(pos);
}
in_atked() {
var path = "game/skills/atked";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
let pos =v3(15,30);
node.setPosition(pos)
node.parent = this.node;
}
in_iced(t:number=1,ap:number=0) {
console.log("[buffcomp]:in_iced",this.HeroView.hero_name,t,ap)
var path = "game/skills/iced";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
node.getComponent(timedCom).time = t;
node.getComponent(timedCom).ap = ap;
node.parent = this.node;
}
in_fired(t:number=1,ap:number=0) {
var path = "game/skills/fired";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
node.getComponent(timedCom).time = t;
node.getComponent(timedCom).ap = ap;
node.parent = this.node;
}
in_yun(t:number=1,ap:number=0) {
var path = "game/skills/yun";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
node.setPosition(v3(0,0));
node.getComponent(timedCom).time = t;
node.getComponent(timedCom).ap = ap;
node.parent = this.node;
}
to_speek(words:string,time:number=0.5){
this.speek_time=0.5
this.node.getChildByName("tooltip").active=true
this.node.getChildByName("tooltip").getChildByName("words").getComponent(Label)!.string = words
}
in_speek(dt: number){
if(this.speek_time <= 0){
return;
}
this.speek_time -= dt;
if(this.speek_time <= 0){
this.speek_time = 0;
this.node.getChildByName("tooltip").getChildByName("words").getComponent(Label)!.string = "";
this.node.getChildByName("tooltip").active=false;
}
}
tooltip(type:number=1,value:string="",s_uuid:number=1001,y:number=90){
// console.log("tooltip",type);
let tip =ecs.getEntity<Tooltip>(Tooltip);
let pos = v3(0,10);
pos.y=pos.y+y;
tip.load(pos,type,value,s_uuid,this.node);
}
hp_tip(type:number=1,value:string="",s_uuid:number=1001,y:number=90){
let tip =ecs.getEntity<Tooltip>(Tooltip);
let x=this.node.position.x;
let ny=this.node.getComponent(UITransform).height-20;
let pos = v3(x,ny,0);
tip.load(pos,type,value,s_uuid,this.node.parent);
}
heathed(){
var path = "game/skills/heathed";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
node.parent = this.node;
}
}