feat(战斗系统): 实现英雄复活机制并优化结算界面
- 在MissionComp中添加复活次数管理及复活成功回调 - 修改VictoryComp支持复活功能,包括广告复活和英雄状态恢复 - 调整结算界面布局和按钮显示逻辑 - 优化游戏结束流程,合并FightEnd逻辑 - 修改HeroViewComp中realDeadTime为更合理的值
This commit is contained in:
@@ -5,6 +5,10 @@ import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/O
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
import { it } from "node:test";
|
||||
import { HeroAttrsComp } from "../hero/HeroAttrsComp";
|
||||
import { HeroViewComp } from "../hero/HeroViewComp";
|
||||
import { FacSet } from "../common/config/GameSet";
|
||||
import { Attrs } from "../common/config/HeroAttrs";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -20,24 +24,38 @@ export class VictoryComp extends CCComp {
|
||||
exp:0,
|
||||
gold:0,
|
||||
diamond:0
|
||||
}
|
||||
}
|
||||
|
||||
// 复活相关配置
|
||||
private canRevive: boolean = false; // 是否可以复活(由MissionComp传入)
|
||||
// private reviveCount: number = 0; // 已复活次数 - 移交 MissionComp 管理
|
||||
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
protected onLoad(): void {
|
||||
|
||||
// this.canRevive = true;
|
||||
// this.reviveCount = 0;
|
||||
}
|
||||
|
||||
onAdded(args: any) {
|
||||
// console.log("[VictoryComp] onAdded",args,smc.items)
|
||||
console.log("[VictoryComp] onAdded",args)
|
||||
if(args.game_data){
|
||||
this.game_data=args.game_data
|
||||
}
|
||||
this.node.getChildByName("btns").getChildByName("next").active=false
|
||||
this.scheduleOnce(()=>{
|
||||
this.node.getChildByName("btns").getChildByName("next").active=true
|
||||
},0.2)
|
||||
|
||||
// 接收复活参数
|
||||
if (args.can_revive !== undefined) {
|
||||
this.canRevive = args.can_revive;
|
||||
} else {
|
||||
this.canRevive = false; // 默认不可复活
|
||||
}
|
||||
|
||||
this.node.getChildByName("btns").getChildByName("next").active=!args.can_revive
|
||||
this.node.getChildByName("btns").getChildByName("alive").active=args.can_revive
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
victory_end(){
|
||||
this.clear_data()
|
||||
oops.message.dispatchEvent(GameEvent.MissionEnd)
|
||||
@@ -53,9 +71,82 @@ export class VictoryComp extends CCComp {
|
||||
double_reward(){
|
||||
// console.log("[VictoryComp]double_reward",smc.items,this.rewards)
|
||||
}
|
||||
|
||||
/** 看广告复活 */
|
||||
watch_ad_revive() {
|
||||
if (!this.canRevive) {
|
||||
console.log("已经复活过,无法再次复活");
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: 接入广告SDK,这里先模拟广告播放成功回调
|
||||
this.onAdReviveSuccess();
|
||||
}
|
||||
|
||||
/** 广告复活成功回调 */
|
||||
private onAdReviveSuccess() {
|
||||
console.log("[VictoryComp] 广告复活成功");
|
||||
|
||||
// 1. 标记已复活
|
||||
// this.reviveCount++;
|
||||
this.canRevive = false;
|
||||
|
||||
// 2. 执行复活逻辑
|
||||
this.doReviveHero();
|
||||
|
||||
// 2.1 通知 MissionComp 扣除次数
|
||||
oops.message.dispatchEvent(GameEvent.ReviveSuccess);
|
||||
|
||||
// 3. 恢复游戏状态
|
||||
// smc.mission.play = true;
|
||||
smc.mission.stop_mon_action = false;
|
||||
|
||||
// 4. 关闭结算界面
|
||||
oops.gui.removeByNode(this.node);
|
||||
}
|
||||
|
||||
/** 执行英雄复活逻辑 */
|
||||
private doReviveHero() {
|
||||
// 查找所有英雄实体并复活
|
||||
const heroes = ecs.query(ecs.allOf(HeroAttrsComp, HeroViewComp));
|
||||
let hasRevived = false;
|
||||
|
||||
heroes.forEach(e => {
|
||||
const attrs = e.get(HeroAttrsComp);
|
||||
const view = e.get(HeroViewComp);
|
||||
|
||||
if (attrs.fac === FacSet.HERO && attrs.is_dead) {
|
||||
// 重置属性
|
||||
attrs.is_dead = false;
|
||||
attrs.hp = attrs.Attrs[Attrs.HP_MAX]; // 满血复活
|
||||
attrs.mp = attrs.Attrs[Attrs.MP_MAX];
|
||||
attrs.is_reviving = false;
|
||||
|
||||
// 视图层复活
|
||||
if (view) {
|
||||
view.alive();
|
||||
}
|
||||
|
||||
hasRevived = true;
|
||||
console.log(`[VictoryComp] 复活英雄: ${attrs.hero_name}`);
|
||||
}
|
||||
});
|
||||
|
||||
if (hasRevived) {
|
||||
// 发送复活事件(如果有需要)
|
||||
// oops.message.dispatchEvent(GameEvent.HeroRevived);
|
||||
} else {
|
||||
console.warn("[VictoryComp] 未找到可复活的英雄实体");
|
||||
}
|
||||
}
|
||||
|
||||
restart(){
|
||||
this.clear_data()
|
||||
oops.message.dispatchEvent(GameEvent.MissionStart)
|
||||
// 确保游戏结束事件被触发,以便重置状态
|
||||
oops.message.dispatchEvent(GameEvent.MissionEnd)
|
||||
this.scheduleOnce(()=>{
|
||||
oops.message.dispatchEvent(GameEvent.MissionStart)
|
||||
},0.5)
|
||||
oops.gui.removeByNode(this.node)
|
||||
}
|
||||
item_show(e:any,val:any){
|
||||
|
||||
Reference in New Issue
Block a user