Files
heros/assets/script/game/hero/BuffComp.ts

223 lines
7.6 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';
import { Timer } from 'db://oops-framework/core/common/timer/Timer';
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;
timer:Timer=new Timer(2);
buff_keys:any[]=["by1","by2","by3"]
key_index:number=0;
protected onLoad(): void {
}
start() {
this.info_init()
}
info_init(){
this.top_node = this.node.getChildByName("top");
let hp_y=this.node.getComponent(UITransform).height
this.top_node.setPosition(0,hp_y,0)
// 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
// if(this.timer.update(deltaTime)){
// this.timer.reset()
// this.show_buff(this.buff_keys[this.key_index])
// this.key_index++
// if(this.key_index>=this.buff_keys.length) this.key_index=0
// }
// this.in_speek(deltaTime)
// this.vmdata_update()
}
show_shield(shield:number=0,shield_max:number=0){
let shield_progress= shield/shield_max;
this.node.getChildByName("shielded").active=shield > 0
this.node.getChildByName("top").getChildByName("shield").active=shield > 0
this.node.getChildByName("top").getChildByName("shield").getComponent(ProgressBar).progress = shield_progress;
this.scheduleOnce(()=>{
this.node.getChildByName("top").getChildByName("shield").getChildByName("pb").getComponent(ProgressBar).progress = shield_progress;
},0.15)
}
hp_show(hp:number,hp_max:number){
// if(this.node.getComponent(HeroViewComp).fac == 0) return
let hp_progress= hp/hp_max;
this.node.getChildByName("top").getChildByName("hp").getComponent(ProgressBar).progress = hp_progress;
this.scheduleOnce(()=>{
this.node.getChildByName("top").getChildByName("hp").getChildByName("hpb").getComponent(ProgressBar).progress = hp_progress;
},0.15)
// this.node.getChildByName("top").getChildByName("hp").active = (hp == hp_max) ? false : true;
}
update_info_lv(){
}
show_wind(t:number=1){
this.wind_cd = t;
}
show_buff(key:string="bb"){
this.node.getChildByName("buff").getChildByName("by1").active = key == "by1"
this.node.getChildByName("buff").getChildByName("by2").active = key == "by2"
this.node.getChildByName("buff").getChildByName("by3").active = key == "by3"
}
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/buff_lvup";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
node.parent = this.node;
}
ap_up(){
var path = "game/skills/buff_apup";
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);
node.setScale(node.scale.x*0.5,node.scale.y*0.5)
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(anm:string="atked",scale:number=1) {
var path = "game/skills/"+anm;
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
node.setScale(node.scale.x*scale,node.scale.y)
node.setPosition(this.node.position.x,this.node.position.y+30,this.node.position.z)
node.parent = this.node.parent;
}
in_iced(t:number=1,ap:number=0) {
var path = "game/skills/buff_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/buff_yun";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
let height=this.node.getComponent(UITransform).height
node.setPosition(v3(0,height));
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;
}
}