加hp 有问题

This commit is contained in:
panw
2025-04-24 16:59:08 +08:00
parent dcc1a98b3b
commit 0d697c488d
3 changed files with 49 additions and 47 deletions

View File

@@ -5,10 +5,12 @@ import { Tooltip } from '../skills/Tooltip';
import { timedCom } from '../skills/timedCom'; import { timedCom } from '../skills/timedCom';
import { smc } from '../common/SingletonModuleComp'; import { smc } from '../common/SingletonModuleComp';
import { BuffGet } from '../skills/BuffGet'; import { BuffGet } from '../skills/BuffGet';
import { HeroViewComp } from './HeroViewComp';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass('BuffComp') @ccclass('BuffComp')
export class BuffComp extends Component { export class BuffComp extends Component {
top_node:any=null;
ap_node:any=null; ap_node:any=null;
cd_node:any=null; cd_node:any=null;
def_node:any=null; def_node:any=null;
@@ -31,22 +33,21 @@ export class BuffComp extends Component {
speek_time:number=0; speek_time:number=0;
start() { start() {
// this.buff_get("dodge") this.info_init()
// 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; info_init(){
// this.node.getChildByName("top").getChildByName("buff").getChildByName("hp").active = false; this.top_node = this.node.getChildByName("top");
let hp_node = this.node.getChildByName("top").getChildByName("hp"); this.top_node.getChildByName("ihp").getChildByName("num").getComponent(Label)!.string = this.node.getComponent(HeroViewComp).hp.toFixed(0)
// hp_node.setPosition(hp_node.position.x,hp_node.position.y-140) this.top_node.getChildByName("iap").getChildByName("num").getComponent(Label)!.string = this.node.getComponent(HeroViewComp).ap.toFixed(0)
} }
update(deltaTime: number) { update(deltaTime: number) {
if(smc.mission.pause) return if(smc.mission.pause) return
this.hp_show()
if(this.wind_cd > 0 ) this.wind_cd -= deltaTime; if(this.wind_cd > 0 ) this.wind_cd -= deltaTime;
if(this.wind_cd <= 0 && this.node.getChildByName("wind").active){ if(this.wind_cd <= 0 && this.node.getChildByName("wind").active){
this.node.getChildByName("wind").active = false; this.node.getChildByName("wind").active = false;
} }
if(this.buff_cd > 0 ) this.buff_cd -= deltaTime; if(this.buff_cd > 0 ) this.buff_cd -= deltaTime;
@@ -57,18 +58,31 @@ export class BuffComp extends Component {
this.in_speek(deltaTime) this.in_speek(deltaTime)
} }
hp_show(){
let hp=this.node.getComponent(HeroViewComp).hp;
let hp_max=this.node.getComponent(HeroViewComp).hp_max;
let hp_progress= hp/hp_max;
this.top_node.getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
if(this.node.getComponent(HeroViewComp).is_boss) return
this.top_node.getChildByName("hp").active = (hp == hp_max) ? false : true;
}
show_shield(val:boolean){ show_shield(val:boolean){
this.node.getChildByName("shielded").active=val this.node.getChildByName("shielded").active=val
} }
buff_get(name:string){
var path = "game/skills/buffget/buffget"; update_info_hp(){
var prefab: Prefab = oops.res.get(path, Prefab)!; let ihp_node = this.top_node.getChildByName("ihp");
var node = instantiate(prefab); ihp_node.getChildByName("num").getComponent(Label)!.string = this.node.getComponent(HeroViewComp).hp.toFixed(0)
node.parent = this.node.getChildByName("top").getChildByName("buff");
let comp=node.getComponent(BuffGet)
comp.init(name)
} }
update_info_ap(){
let iap_node = this.top_node.getChildByName("iap");
iap_node.getChildByName("num").getComponent(Label)!.string = this.node.getComponent(HeroViewComp).ap.toFixed(0)
}
show_wind(t:number=1){ show_wind(t:number=1){
this.wind_cd = t; this.wind_cd = t;
this.node.getChildByName("wind").active = true; this.node.getChildByName("wind").active = true;

View File

@@ -86,6 +86,8 @@ export class HeroViewComp extends CCComp {
}> = []; }> = [];
private isProcessingDamage: boolean = false; private isProcessingDamage: boolean = false;
private damageInterval: number = 0.2; // 伤害数字显示间隔 private damageInterval: number = 0.2; // 伤害数字显示间隔
private timer:Timer=new Timer(1);
onLoad() { onLoad() {
this.as = this.getComponent(HeroSpine); this.as = this.getComponent(HeroSpine);
@@ -131,7 +133,10 @@ export class HeroViewComp extends CCComp {
// this.ent.destroy(); // this.ent.destroy();
// return // return
// } // }
this.hp_show() if(this.timer.update(dt)){
this.add_ap(10)
this.add_hp_max(20)
};
if(this.ice_cd > 0){ if(this.ice_cd > 0){
this.ice_cd -=dt; this.ice_cd -=dt;
return return
@@ -153,16 +158,7 @@ export class HeroViewComp extends CCComp {
this.node.getChildByName("top").getChildByName("ihp").active = false; this.node.getChildByName("top").getChildByName("ihp").active = false;
this.node.getChildByName("top").getChildByName("iap").active = false; this.node.getChildByName("top").getChildByName("iap").active = false;
} }
hp_show(){ //状态切换
let hp_progress= this.hp/this.hp_max;
this.node.getChildByName("top").getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
if(this.is_boss) return
this.node.getChildByName("top").getChildByName("hp").active = (this.hp == this.hp_max) ? false : true;
}
//移动
//状态切换
status_change(type:string){ status_change(type:string){
this.status=type this.status=type
if(type == "idle"){ if(type == "idle"){
@@ -190,33 +186,25 @@ export class HeroViewComp extends CCComp {
*/ */
add_ap(ap: number){ add_ap(ap: number){
this.ap += Math.floor(ap); this.ap += Math.floor(ap);
this.BUFFCOMP.buff_get("ap") this.BUFFCOMP.update_info_ap()
} }
de_ap(ap: number){ de_ap(ap: number){
this.ap -= Math.floor(ap); this.ap -= Math.floor(ap);
this.BUFFCOMP.buff_get("deap") this.BUFFCOMP.update_info_ap()
}
/**
* 增加英雄的闪避率。
* @param dodge 要增加的闪避率。
*/
add_dodge(dodgeRate: number) {
this.dodge += Math.floor(dodgeRate);
this.BUFFCOMP.buff_get("dodge");
}
de_dodge(dodgeRate: number) {
this.dodge += Math.floor(dodgeRate);
this.BUFFCOMP.buff_get("dedodge");
} }
add_hp_max(hprate: number=0){ add_hp_max(hprate: number=0){
this.BUFFCOMP.buff_get("hp") this.hp_max += Math.floor(hprate) ;
this.hp_max += Math.floor(hprate/100*this.hp_max) ;
this.add_hp2(hprate) this.add_hp2(hprate)
this.BUFFCOMP.update_info_hp()
} }
de_hp_max(hprate: number=0){ de_hp_max(hprate: number=0){
this.BUFFCOMP.buff_get("dehp") this.hp_max -= Math.floor(hprate) ;
this.hp_max -= Math.floor(hprate/100*this.hp_max) ; this.BUFFCOMP.update_info_hp()
} }
add_hp(hp: number = 0) { add_hp(hp: number = 0) {
this.BUFFCOMP.heathed(); this.BUFFCOMP.heathed();
this.hp+=Math.floor(hp); this.hp+=Math.floor(hp);

View File

@@ -15,7 +15,7 @@ const { ccclass, property } = _decorator;
@ccclass('MissionMonCompComp') @ccclass('MissionMonCompComp')
@ecs.register('MissionMonComp', false) @ecs.register('MissionMonComp', false)
export class MissionMonCompComp extends CCComp { export class MissionMonCompComp extends CCComp {
timer:Timer=new Timer(3) timer:Timer=new Timer(10)
// 添加刷怪队列 // 添加刷怪队列
private monsterQueue: Array<{uuid: number, position: number, isBoss: boolean}> = []; private monsterQueue: Array<{uuid: number, position: number, isBoss: boolean}> = [];
private isSpawning: boolean = false; private isSpawning: boolean = false;