refactor(游戏逻辑): 拆分游戏暂停和播放状态的检查条件
将多处 `if(!smc.mission.play || smc.mission.pause)` 条件判断拆分为独立的if语句 在VictoryComp中正确设置pause状态 移除MissionComp中多余的pause状态重置
This commit is contained in:
@@ -51,9 +51,10 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
|||||||
* 处理伤害队列中的所有伤害事件
|
* 处理伤害队列中的所有伤害事件
|
||||||
*/
|
*/
|
||||||
update(e: ecs.Entity): void {
|
update(e: ecs.Entity): void {
|
||||||
if(!smc.mission.play || smc.mission.pause) return;
|
if(!smc.mission.play ) return
|
||||||
const TAttrsComp = e.get(HeroAttrsComp);
|
if(smc.mission.pause) return
|
||||||
const damageQueue = e.get(DamageQueueComp);
|
const TAttrsComp = e.get(HeroAttrsComp)
|
||||||
|
const damageQueue = e.get(DamageQueueComp)
|
||||||
|
|
||||||
if (!TAttrsComp || !damageQueue || damageQueue.isEmpty()) return;
|
if (!TAttrsComp || !damageQueue || damageQueue.isEmpty()) return;
|
||||||
|
|
||||||
|
|||||||
@@ -23,11 +23,12 @@ export class HeroAttrEventSystem extends ecs.ComblockSystem
|
|||||||
return ecs.allOf(HeroAttrsComp,HeroAttrEvent);
|
return ecs.allOf(HeroAttrsComp,HeroAttrEvent);
|
||||||
}
|
}
|
||||||
entityEnter(e: ecs.Entity): void {
|
entityEnter(e: ecs.Entity): void {
|
||||||
if(!smc.mission.play || smc.mission.pause) return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update(e: ecs.Entity): void {
|
update(e: ecs.Entity): void {
|
||||||
if(!smc.mission.play || smc.mission.pause) return;
|
if(!smc.mission.play ) return;
|
||||||
|
if(smc.mission.pause) return
|
||||||
const model = e.get(HeroAttrsComp);
|
const model = e.get(HeroAttrsComp);
|
||||||
if (!model || model.is_dead) return;
|
if (!model || model.is_dead) return;
|
||||||
const event = e.get(HeroAttrEvent);
|
const event = e.get(HeroAttrEvent);
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ export class HeroAttrSystem extends ecs.ComblockSystem
|
|||||||
* 实体首次进入系统时调用(每个实体只调用一次)
|
* 实体首次进入系统时调用(每个实体只调用一次)
|
||||||
*/
|
*/
|
||||||
entityEnter(e: ecs.Entity): void {
|
entityEnter(e: ecs.Entity): void {
|
||||||
if(!smc.mission.play || smc.mission.pause) return;
|
|
||||||
const model = e.get(HeroAttrsComp);
|
const model = e.get(HeroAttrsComp);
|
||||||
if (!model) return;
|
if (!model) return;
|
||||||
|
|
||||||
@@ -64,7 +63,8 @@ export class HeroAttrSystem extends ecs.ComblockSystem
|
|||||||
* - 这是正确的设计,不是 bug
|
* - 这是正确的设计,不是 bug
|
||||||
*/
|
*/
|
||||||
update(e: ecs.Entity): void {
|
update(e: ecs.Entity): void {
|
||||||
if(!smc.mission.play || smc.mission.pause) return;
|
if(!smc.mission.play ) return;
|
||||||
|
if(smc.mission.pause) return
|
||||||
const model = e.get(HeroAttrsComp);
|
const model = e.get(HeroAttrsComp);
|
||||||
if (!model || model.is_dead || model.is_reviving) return;
|
if (!model || model.is_dead || model.is_reviving) return;
|
||||||
|
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ export class HeroMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
|||||||
}
|
}
|
||||||
|
|
||||||
update(e: ecs.Entity) {
|
update(e: ecs.Entity) {
|
||||||
if (!smc.mission.play || smc.mission.pause) return;
|
if (!smc.mission.play ) return;
|
||||||
|
if(smc.mission.pause) return
|
||||||
const move = e.get(HeroMoveComp);
|
const move = e.get(HeroMoveComp);
|
||||||
const model = e.get(HeroAttrsComp);
|
const model = e.get(HeroAttrsComp);
|
||||||
const view = e.get(HeroViewComp);
|
const view = e.get(HeroViewComp);
|
||||||
|
|||||||
@@ -126,8 +126,8 @@ export class HeroViewComp extends CCComp {
|
|||||||
* 注意:数据更新逻辑已移到 HeroAttrSystem,这里只负责显示
|
* 注意:数据更新逻辑已移到 HeroAttrSystem,这里只负责显示
|
||||||
*/
|
*/
|
||||||
update(dt: number){
|
update(dt: number){
|
||||||
if(!smc.mission.play || smc.mission.pause) return;
|
if(!smc.mission.play ) return;
|
||||||
|
if(smc.mission.pause) return
|
||||||
// 🔥 修复:添加安全检查,防止在实体销毁过程中访问null的model
|
// 🔥 修复:添加安全检查,防止在实体销毁过程中访问null的model
|
||||||
if(!this.ent) return;
|
if(!this.ent) return;
|
||||||
if (!this.model) return;
|
if (!this.model) return;
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ export class MonMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpda
|
|||||||
}
|
}
|
||||||
|
|
||||||
update(e: ecs.Entity) {
|
update(e: ecs.Entity) {
|
||||||
if (!smc.mission.play || smc.mission.pause) return;
|
if (!smc.mission.play ) return;
|
||||||
|
if(smc.mission.pause) return
|
||||||
const view = e.get(HeroViewComp);
|
const view = e.get(HeroViewComp);
|
||||||
|
|
||||||
// 如果英雄死亡(停止怪物行动标志为true),则停止怪物移动
|
// 如果英雄死亡(停止怪物行动标志为true),则停止怪物移动
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat
|
|||||||
}
|
}
|
||||||
|
|
||||||
update(e: ecs.Entity): void {
|
update(e: ecs.Entity): void {
|
||||||
if(!smc.mission.play || smc.mission.pause) return;
|
if(!smc.mission.play ) return;
|
||||||
|
if(smc.mission.pause) return
|
||||||
const skills = e.get(HeroSkillsComp);
|
const skills = e.get(HeroSkillsComp);
|
||||||
if (!skills) return;
|
if (!skills) return;
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ export class SkillCDSystem extends ecs.ComblockSystem implements ecs.ISystemUpda
|
|||||||
}
|
}
|
||||||
|
|
||||||
update(e: ecs.Entity): void {
|
update(e: ecs.Entity): void {
|
||||||
if(!smc.mission.play || smc.mission.pause) return;
|
if(!smc.mission.play ) return;
|
||||||
|
if(smc.mission.pause) return
|
||||||
const skills = e.get(HeroSkillsComp);
|
const skills = e.get(HeroSkillsComp);
|
||||||
if (!skills) return;
|
if (!skills) return;
|
||||||
const attrsCom = e.get(HeroAttrsComp);
|
const attrsCom = e.get(HeroAttrsComp);
|
||||||
|
|||||||
@@ -43,9 +43,8 @@ export class MissionComp extends CCComp {
|
|||||||
this.on(GameEvent.ReviveSuccess, this.onReviveSuccess, this)
|
this.on(GameEvent.ReviveSuccess, this.onReviveSuccess, this)
|
||||||
}
|
}
|
||||||
protected update(dt: number): void {
|
protected update(dt: number): void {
|
||||||
if(!smc.mission.play||smc.mission.pause){
|
if(!smc.mission.play) return
|
||||||
return
|
if(smc.mission.pause) return
|
||||||
}
|
|
||||||
if(smc.mission.in_fight){
|
if(smc.mission.in_fight){
|
||||||
smc.vmdata.mission_data.fight_time+=dt
|
smc.vmdata.mission_data.fight_time+=dt
|
||||||
smc.vmdata.mission_data.time-=dt
|
smc.vmdata.mission_data.time-=dt
|
||||||
@@ -188,7 +187,6 @@ export class MissionComp extends CCComp {
|
|||||||
// 延迟0.5秒后执行任务结束逻辑
|
// 延迟0.5秒后执行任务结束逻辑
|
||||||
this.scheduleOnce(() => {
|
this.scheduleOnce(() => {
|
||||||
smc.mission.play=false
|
smc.mission.play=false
|
||||||
smc.mission.pause=false
|
|
||||||
this.cleanComponents()
|
this.cleanComponents()
|
||||||
}, 0.5)
|
}, 0.5)
|
||||||
}
|
}
|
||||||
@@ -197,7 +195,6 @@ export class MissionComp extends CCComp {
|
|||||||
// console.log("[MissionComp] mission_end")
|
// console.log("[MissionComp] mission_end")
|
||||||
// 合并 FightEnd 逻辑:清理组件、停止游戏循环
|
// 合并 FightEnd 逻辑:清理组件、停止游戏循环
|
||||||
smc.mission.play=false
|
smc.mission.play=false
|
||||||
smc.mission.pause=false
|
|
||||||
this.cleanComponents()
|
this.cleanComponents()
|
||||||
|
|
||||||
this.node.active=false
|
this.node.active=false
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ export class MissionMonCompComp extends CCComp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected update(dt: number): void {
|
protected update(dt: number): void {
|
||||||
if(!smc.mission.play||smc.mission.pause) return
|
if(!smc.mission.play) return
|
||||||
|
if(smc.mission.pause) return
|
||||||
// 如果英雄死亡(停止怪物行动标志为true),则停止刷怪逻辑
|
// 如果英雄死亡(停止怪物行动标志为true),则停止刷怪逻辑
|
||||||
if(smc.mission.stop_mon_action) return;
|
if(smc.mission.stop_mon_action) return;
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ export class VictoryComp extends CCComp {
|
|||||||
|
|
||||||
this.node.getChildByName("btns").getChildByName("next").active=!args.can_revive
|
this.node.getChildByName("btns").getChildByName("next").active=!args.can_revive
|
||||||
this.node.getChildByName("btns").getChildByName("alive").active=args.can_revive
|
this.node.getChildByName("btns").getChildByName("alive").active=args.can_revive
|
||||||
|
smc.mission.pause=true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ export class VictoryComp extends CCComp {
|
|||||||
oops.gui.removeByNode(this.node)
|
oops.gui.removeByNode(this.node)
|
||||||
}
|
}
|
||||||
clear_data(){
|
clear_data(){
|
||||||
|
smc.mission.pause=false
|
||||||
}
|
}
|
||||||
//看广告双倍
|
//看广告双倍
|
||||||
watch_ad(){
|
watch_ad(){
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ export class SMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
|||||||
}
|
}
|
||||||
|
|
||||||
entityEnter(entity: ecs.Entity): void {
|
entityEnter(entity: ecs.Entity): void {
|
||||||
if(!smc.mission.play || smc.mission.pause) return;
|
|
||||||
const moveComp = entity.get(SMoveDataComp);
|
const moveComp = entity.get(SMoveDataComp);
|
||||||
const skillView = entity.get(SkillView);
|
const skillView = entity.get(SkillView);
|
||||||
|
|
||||||
@@ -107,7 +106,8 @@ export class SMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
|||||||
}
|
}
|
||||||
|
|
||||||
update(entity: ecs.Entity): void {
|
update(entity: ecs.Entity): void {
|
||||||
if(!smc.mission.play || smc.mission.pause) return;
|
if(!smc.mission.play ) return;
|
||||||
|
if(smc.mission.pause) return
|
||||||
const moveComp = entity.get(SMoveDataComp);
|
const moveComp = entity.get(SMoveDataComp);
|
||||||
const skillView = entity.get(SkillView);
|
const skillView = entity.get(SkillView);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user