角色buff 动画控制交由 buffcomp
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,13 +22,14 @@ import { Tooltip } from "../skills/Tooltip";
|
||||
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
|
||||
import { TimerManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/TimerManager";
|
||||
import { HeroSet } from "../common/config/heroSet";
|
||||
import { BuffComp } from "./BuffComp";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 角色显示组件 */
|
||||
@ccclass('HeroViewComp') // 定义为 Cocos Creator 组件
|
||||
@ecs.register('HeroView', false) // 定义为 ECS 组件
|
||||
export class HeroViewComp extends CCComp {
|
||||
|
||||
BUFFCOMP:any=null!;
|
||||
enemy_pos:Vec3=null!;
|
||||
enemy:any=null!;
|
||||
|
||||
@@ -127,7 +128,10 @@ export class HeroViewComp extends CCComp {
|
||||
} /** 视图层逻辑代码分离演示 */
|
||||
|
||||
start () {
|
||||
|
||||
this.as.idle()
|
||||
this.BUFFCOMP=this.node.getComponent(BuffComp);
|
||||
|
||||
/** 方向 */
|
||||
this.node.setScale(this.scale,1);
|
||||
this.node.getChildByName("top").setScale(this.scale,1);
|
||||
@@ -218,7 +222,6 @@ export class HeroViewComp extends CCComp {
|
||||
this.at += dt;
|
||||
this.check_enemy_alive()
|
||||
this.in_atk(dt);
|
||||
this.hp_show()
|
||||
this.move(dt);
|
||||
this.check_mission_buf()
|
||||
}
|
||||
@@ -311,15 +314,6 @@ export class HeroViewComp extends CCComp {
|
||||
this.node.setPosition(this.node.position.x+dt*this.speed*this.scale, this.node.position.y+dt*this.dir_y, this.node.position.z);
|
||||
}
|
||||
|
||||
hp_show(){
|
||||
let hp_progress= this.hp/this.rhp_max;
|
||||
this.node.getChildByName("top").getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
|
||||
if(this.hp == this.rhp_max){
|
||||
this.node.getChildByName("top").getChildByName("hp").active = false;
|
||||
} else{
|
||||
this.node.getChildByName("top").getChildByName("hp").active = true;
|
||||
}
|
||||
}
|
||||
skill_pos(){
|
||||
return v3(0,35)
|
||||
}
|
||||
@@ -360,8 +354,8 @@ export class HeroViewComp extends CCComp {
|
||||
if(skill.is_crit){
|
||||
l_hp = l_hp * (150+skill.crit_add)/100
|
||||
}
|
||||
l_hp=-1*Math.ceil(l_hp)
|
||||
this.hp_change(l_hp,skill.is_crit);
|
||||
l_hp=Math.ceil(l_hp)
|
||||
this.hp_less(l_hp,skill.is_crit);
|
||||
}
|
||||
//能量判断
|
||||
check_power(){
|
||||
@@ -389,7 +383,7 @@ export class HeroViewComp extends CCComp {
|
||||
{
|
||||
let i = RandomManager.instance.getRandomInt(0,100,3)
|
||||
if(i < this.crit_max){
|
||||
this.tooltip(5,"*会心一击*");
|
||||
this.BUFFCOMP.tooltip(5,"*会心一击*");
|
||||
this.crit_count += 1
|
||||
this.exp_add(this.cexp) // 暴击经验
|
||||
this.power_add(this.cpw)
|
||||
@@ -409,7 +403,7 @@ export class HeroViewComp extends CCComp {
|
||||
let i = RandomManager.instance.getRandomInt(0,100,3)
|
||||
if(i < this.dodge_max){
|
||||
// console.log("闪避触发: i="+i+":dodge="+dodge);
|
||||
this.tooltip(5,"闪避");
|
||||
this.BUFFCOMP.tooltip(5,"闪避");
|
||||
this.exp_add(this.doexp) // 闪避经验
|
||||
this.power_add(this.dopw)
|
||||
this.dodge_count += 1
|
||||
@@ -512,7 +506,7 @@ export class HeroViewComp extends CCComp {
|
||||
handle_skill(skill:number){
|
||||
this.as.max()
|
||||
this.at = 0;
|
||||
this.tooltip(3,SkillSet[skill].name,skill);
|
||||
this.BUFFCOMP.tooltip(3,SkillSet[skill].name,skill);
|
||||
|
||||
switch (SkillSet[skill].tg) {
|
||||
case 0: //自己
|
||||
@@ -605,52 +599,30 @@ export class HeroViewComp extends CCComp {
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
heathed(){
|
||||
this.node.getChildByName("heathed").active=true
|
||||
}
|
||||
hp_max_add(){
|
||||
console.log("hp_max_add 动画");
|
||||
}
|
||||
add_hp(hp: number=0){
|
||||
this.heathed();
|
||||
this.BUFFCOMP.heathed();
|
||||
this.hp+=hp;
|
||||
if(this.hp > this.rhp_max){
|
||||
this.hp = this.rhp_max;
|
||||
}
|
||||
this.tooltip(2,hp.toFixed(0));
|
||||
this.BUFFCOMP.tooltip(2,hp.toFixed(0));
|
||||
}
|
||||
add_hp_max(hp: number=0){
|
||||
this.hp_max_add()
|
||||
this.hp += hp/100*this.hp_max;
|
||||
}
|
||||
hp_change(hp: number,is_crit:boolean=false){
|
||||
hp_less(hp: number,is_crit:boolean=false){
|
||||
if(this.is_dead){
|
||||
return;
|
||||
}
|
||||
|
||||
this.hp += hp;
|
||||
|
||||
this.hp -= hp;
|
||||
if(is_crit){
|
||||
this.tooltip(4,hp.toFixed(0),250);
|
||||
this.BUFFCOMP.tooltip(4,hp.toFixed(0),250);
|
||||
}else{
|
||||
this.tooltip(1,hp.toFixed(0),250);
|
||||
this.BUFFCOMP.tooltip(1,hp.toFixed(0),250);
|
||||
}
|
||||
|
||||
if(this.hp > this.rhp_max){
|
||||
@@ -692,18 +664,7 @@ export class HeroViewComp extends CCComp {
|
||||
add_shield(shield:number){
|
||||
this.shield =shield
|
||||
console.log("shield:",shield);
|
||||
if(this.shield > 0){
|
||||
this.node.getChildByName("shielded").active=true
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
/** 静止时间 */
|
||||
in_stop (dt: number) {
|
||||
if(this.stop_cd > 0){
|
||||
@@ -716,24 +677,14 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
|
||||
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;
|
||||
this.BUFFCOMP.in_atked()
|
||||
// this.as.atked();
|
||||
this.atked_count++;
|
||||
this.exp_add(this.uaexp)
|
||||
this.power_add(this.uapw)
|
||||
}
|
||||
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);
|
||||
this.BUFFCOMP.dead()
|
||||
this.exp_add(this.dexp)
|
||||
this.power_add(this.dpw)
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ export class TooltipCom extends CCComp {
|
||||
this.node.getChildByName("loss_life").active=true;
|
||||
tween(this.node).to(
|
||||
this.alive_time,
|
||||
{position:v3(this.node.position.x-10,this.node.position.y+20), },
|
||||
{position:v3(this.node.position.x,this.node.position.y+20), },
|
||||
{
|
||||
onComplete:()=>{ this.ent.destroy()},
|
||||
easing:"linear"
|
||||
@@ -69,7 +69,7 @@ export class TooltipCom extends CCComp {
|
||||
this.node.getChildByName("bloss").active=true;
|
||||
tween(this.node).to(
|
||||
this.alive_time,
|
||||
{position:v3(this.node.position.x-10,this.node.position.y+20), },
|
||||
{position:v3(this.node.position.x,this.node.position.y+20), },
|
||||
{
|
||||
onComplete:()=>{ this.ent.destroy()},
|
||||
easing:"linear"
|
||||
|
||||
Reference in New Issue
Block a user