角色buff 动画控制交由 buffcomp

This commit is contained in:
2024-12-30 16:59:05 +08:00
parent ed12d4d428
commit a66e61c313
20 changed files with 606 additions and 400 deletions

View File

@@ -1,17 +1,170 @@
import { _decorator, Component, Node } from 'cc';
import { _decorator, Component, instantiate, Label, Node, Prefab, ProgressBar, v3 } from 'cc';
import { HeroViewComp } from './HeroViewComp';
import { oops } from 'db://oops-framework/core/Oops';
import { ecs } from 'db://oops-framework/libs/ecs/ECS';
import { Tooltip } from '../skills/Tooltip';
const { ccclass, property } = _decorator;
@ccclass('BuffComp')
export class BuffComp extends Component {
heroView: any=null;
buff_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;
s_index=0
speek_time:number=0;
start() {
this.heroView = this.node.getComponent(HeroViewComp);
this.node.getChildByName("top").getChildByName("buff").getChildByName("ap").active = false;
this.node.getChildByName("top").getChildByName("buff").getChildByName("cd").active = false;
this.node.getChildByName("top").getChildByName("buff").getChildByName("def").active = false;
this.node.getChildByName("top").getChildByName("buff").getChildByName("hp").active = false;
this.node.getChildByName("top").getChildByName("buff").getChildByName("crit").active = false;
}
update(deltaTime: number) {
if(this.ap_cd > 0 ) this.ap_cd -= deltaTime;
if(this.ap_cd <= 0 && this.node.getChildByName("top").getChildByName("buff").getChildByName("ap").active){
this.node.getChildByName("top").getChildByName("buff").getChildByName("ap").active = false;
this.node.getChildByName("top").getChildByName("buff").getChildByName("ap").setSiblingIndex(0);
this.s_index--
if(this.s_index< 0) this.s_index=0
}
if(this.cd_cd > 0 ) this.cd_cd -= deltaTime;
if(this.cd_cd <= 0 && this.node.getChildByName("top").getChildByName("buff").getChildByName("cd").active) {
this.node.getChildByName("top").getChildByName("buff").getChildByName("cd").active = false;
this.node.getChildByName("top").getChildByName("buff").getChildByName("cd").setSiblingIndex(0);
this.s_index--
if(this.s_index< 0) this.s_index=0
}
if(this.def_cd > 0 ) this.def_cd -= deltaTime;
if(this.def_cd <= 0 && this.node.getChildByName("top").getChildByName("buff").getChildByName("def").active){
this.node.getChildByName("top").getChildByName("buff").getChildByName("def").active = false;
this.node.getChildByName("top").getChildByName("buff").getChildByName("def").setSiblingIndex(0);
this.s_index--
if(this.s_index< 0) this.s_index=0
}
if(this.hp_cd > 0 ) this.hp_cd -= deltaTime;
if(this.hp_cd <= 0 && this.node.getChildByName("top").getChildByName("buff").getChildByName("hp").active){
this.node.getChildByName("top").getChildByName("buff").getChildByName("hp").active = false;
this.node.getChildByName("top").getChildByName("buff").getChildByName("hp").setSiblingIndex(0);
this.s_index--
if(this.s_index< 0) this.s_index=0
}
if(this.crit_cd > 0 ) this.crit_cd -= deltaTime;
if(this.crit_cd <= 0 && this.node.getChildByName("top").getChildByName("buff").getChildByName("crit").active){
this.node.getChildByName("top").getChildByName("buff").getChildByName("crit").active = false;
this.node.getChildByName("top").getChildByName("buff").getChildByName("crit").setSiblingIndex(0);
this.s_index--
if(this.s_index< 0) this.s_index=0
}
this.hp_show()
this.in_speek(deltaTime)
if(this.heroView.shield > 0){
this.node.getChildByName("shielded").active=true
}else{
this.node.getChildByName("shielded").active=false
}
}
show_ap(t:number=2){
this.ap_cd = t;
this.node.getChildByName("top").getChildByName("buff").getChildByName("ap").active = true;
this.node.getChildByName("top").getChildByName("buff").getChildByName("ap").setSiblingIndex(this.s_index);
console.log("show_ap",this.node.getChildByName("top").getChildByName("buff").getChildByName("ap"))
this.s_index++
}
show_cd(t:number=2){
this.cd_cd = t;
this.node.getChildByName("top").getChildByName("buff").getChildByName("cd").active = true;
this.node.getChildByName("top").getChildByName("buff").getChildByName("cd").setSiblingIndex(this.s_index);
this.s_index++
}
show_def(t:number=2){
this.def_cd = t;
this.node.getChildByName("top").getChildByName("buff").getChildByName("def").active = true;
this.node.getChildByName("top").getChildByName("buff").getChildByName("def").setSiblingIndex(this.s_index);
this.s_index++
}
show_hp(t:number=2){
this.hp_cd = t;
this.node.getChildByName("top").getChildByName("buff").getChildByName("hp").active = true;
this.node.getChildByName("top").getChildByName("buff").getChildByName("hp").setSiblingIndex(this.s_index);
this.s_index++
}
show_crit(t:number=2){
this.crit_cd = t;
this.node.getChildByName("top").getChildByName("buff").getChildByName("crit").active = true;
this.node.getChildByName("top").getChildByName("buff").getChildByName("crit").setSiblingIndex(this.s_index);
this.s_index++
}
hp_show(){
let hp_progress= this.heroView.hp/this.heroView.rhp_max;
this.node.getChildByName("top").getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
if(this.heroView.hp == this.heroView.rhp_max){
this.node.getChildByName("top").getChildByName("hp").active = false;
} else{
this.node.getChildByName("top").getChildByName("hp").active = true;
}
}
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;
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;
}
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,0);
pos.y=pos.y+y;
tip.load(pos,type,value,s_uuid,this.node);
}
heathed(){
this.node.getChildByName("heathed").active=true
}
}