fix: 收敛战斗内存增长并强化战斗结束清理

This commit is contained in:
panw
2026-03-18 16:46:52 +08:00
parent 56227d8f3f
commit 035066752c
7 changed files with 155 additions and 58 deletions

View File

@@ -59,6 +59,7 @@ export class HeroViewComp extends CCComp {
}> = [];
private isProcessingDamage: boolean = false;
private damageInterval: number = 0.01; // 伤害数字显示间隔
private effectLifeTime: number = 0.8;
onLoad() {
this.as = this.getComponent(HeroSpine);
const collider = this.node.getComponent(BoxCollider2D);
@@ -206,28 +207,19 @@ export class HeroViewComp extends CCComp {
/** 升级特效 */
private lv_up() {
var path = "game/skill/buff/buff_lvup";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
node.parent = this.node;
this.spawnEffect("game/skill/buff/buff_lvup", this.node, 1.0);
}
/** 攻击力提升特效 */
private ap_up() {
var path = "game/skill/buff/buff_apup";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
node.parent = this.node;
this.spawnEffect("game/skill/buff/buff_apup", this.node, 1.0);
}
/** 显示 Buff 特效 */
private show_do_buff(name: string) {
var path = "game/skill/buff/" + 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);
this.spawnEffect(path, this.node.parent, 1.0, pos);
}
@@ -244,24 +236,22 @@ export class HeroViewComp extends CCComp {
/** 冰冻特效 */
private in_iced(t: number = 1, ap: number = 0) {
var path = "game/skill/buff/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;
const node = this.spawnEffect("game/skill/buff/buff_iced", this.node, t);
if (!node) return;
const timer = node.getComponent(timedCom) || node.addComponent(timedCom);
timer.time = t;
timer.ap = ap;
}
/** 眩晕特效 */
private in_yun(t: number = 1, ap: number = 0) {
var path = "game/skill/buff/buff_yun";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
const node = this.spawnEffect("game/skill/buff/buff_yun", this.node, t);
if (!node) return;
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;
const timer = node.getComponent(timedCom) || node.addComponent(timedCom);
timer.time = t;
timer.ap = ap;
}
/** 技能提示 */
@@ -294,39 +284,42 @@ export class HeroViewComp extends CCComp {
public palayBuff(anm: string = ""){
if(anm==="") return;
var path = "game/skill/buff/" + anm;
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
node.parent = this.node;
this.spawnEffect(path, this.node, this.effectLifeTime);
}
public playReady(anm: string = ""){
if(anm==="") return;
var path = "game/skill/ready/" + anm;
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
node.parent = this.node;
this.spawnEffect(path, this.node, this.effectLifeTime);
}
public playEnd(anm: string = ""){
if(anm==="") return;
var path = "game/skill/end/" + anm;
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
node.parent = this.node;
this.spawnEffect(path, this.node, this.effectLifeTime);
}
/** 治疗特效 */
private heathed() {
var path = "game/skill/buff/heathed";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
node.parent = this.node;
this.spawnEffect("game/skill/buff/heathed", this.node, 1.0);
}
private deaded(){
var path = "game/skill/end/atked";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
node.parent = this.node;
this.spawnEffect("game/skill/end/atked", this.node, this.effectLifeTime);
}
private spawnEffect(path: string, parent: Node | null, life: number = 0.8, worldPos?: Vec3): Node | null {
if (!parent || !parent.isValid) return null;
const prefab: Prefab = oops.res.get(path, Prefab)!;
if (!prefab) return null;
const node = instantiate(prefab);
if (!node || !node.isValid) return null;
node.parent = parent;
if (worldPos) {
node.setWorldPosition(worldPos);
}
const timer = node.getComponent(timedCom) || node.addComponent(timedCom);
timer.time = Math.max(0.2, life);
timer.ap = 0;
return node;
}
// 注意BaseUp 逻辑已移到 HeroAttrSystem.update()
// 注意updateTemporaryBuffsDebuffs 逻辑已移到 HeroAttrSystem.update()