Files
pixelheros/assets/script/game/map/VictoryComp.ts
panw 3a8f015a78 refactor: 移除调试日志并统一使用日志工具
- 删除多个文件中的 console.log/console.warn/console.error 调试输出
- 将日志输出统一替换为 mLogger 工具,支持调试模式控制
- 清理注释掉的调试代码和空方法体
2026-02-03 16:49:24 +08:00

213 lines
7.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { _decorator, instantiate, Label ,Prefab,Node} from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
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";
import { ScoreWeights } from "../common/config/ScoreSet";
import { mLogger } from "../common/Logger";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('VictoryComp')
@ecs.register('Victory', false)
export class VictoryComp extends CCComp {
debugMode: boolean = false;
reward_lv:number=1
reward_num:number=2
rewards:any[]=[]
game_data:any={
exp:0,
gold:0,
diamond:0
}
// 复活相关配置
private canRevive: boolean = false; // 是否可以复活由MissionComp传入
// private reviveCount: number = 0; // 已复活次数 - 移交 MissionComp 管理
/** 视图层逻辑代码分离演示 */
protected onLoad(): void {
this.node.getChildByName("loading").active=false
// this.canRevive = true;
// this.reviveCount = 0;
}
onAdded(args: any) {
this.node.getChildByName("loading").active=false
mLogger.log(this.debugMode, 'VictoryComp', "[VictoryComp] onAdded",args)
if(args.game_data){
this.game_data=args.game_data
}
// 接收复活参数
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
// 只有在不能复活(彻底结算)时才计算总分
if (!this.canRevive) {
this.calculateTotalScore();
}
}
/**
* 计算单局总分并更新到 smc.scores.score
*/
private calculateTotalScore() {
const s = smc.vmdata.scores;
let totalScore = 0;
// 1. 战斗行为分
totalScore += s.crt_count * ScoreWeights.CRT_KILL;
totalScore += s.wf_count * ScoreWeights.WF_TRIGGER;
totalScore += s.dod_count * ScoreWeights.DODGE_SUCCESS;
totalScore += s.back_count * ScoreWeights.BACK_SUCCESS;
totalScore += s.stun_count * ScoreWeights.STUN_SUCCESS;
totalScore += s.freeze_count * ScoreWeights.FREEZE_SUCCESS;
// 2. 伤害转化分
totalScore += s.total_dmg * ScoreWeights.DMG_FACTOR;
totalScore += s.avg_dmg * ScoreWeights.AVG_DMG_FACTOR;
totalScore += s.thorns_dmg * ScoreWeights.THORNS_DMG_FACTOR;
totalScore += s.crit_dmg_total * ScoreWeights.CRIT_DMG_FACTOR;
// 3. 击杀得分
totalScore += s.melee_kill_count * ScoreWeights.KILL_MELEE;
totalScore += s.remote_kill_count * ScoreWeights.KILL_REMOTE;
totalScore += s.elite_kill_count * ScoreWeights.KILL_ELITE;
totalScore += s.boss_kill_count * ScoreWeights.KILL_BOSS;
// 4. 生存得分
totalScore += s.heal_total * ScoreWeights.HEAL_FACTOR;
totalScore += s.lifesteal_total * ScoreWeights.LIFESTEAL_FACTOR;
// 5. 资源得分
totalScore += s.exp_total * ScoreWeights.EXP_FACTOR;
totalScore += s.gold_total * ScoreWeights.GOLD_FACTOR;
// 更新总分(向下取整)
s.score = Math.floor(totalScore);
mLogger.log(this.debugMode, 'VictoryComp', `[VictoryComp] 结算总分: ${s.score}`);
}
victory_end(){
this.clear_data()
oops.message.dispatchEvent(GameEvent.MissionEnd)
oops.gui.removeByNode(this.node)
}
clear_data(){
smc.mission.pause=false
}
//看广告双倍
watch_ad(){
return true
}
double_reward(){
}
/** 看广告复活 */
watch_ad_revive() {
if (!this.canRevive) {
mLogger.log(this.debugMode, 'VictoryComp', "已经复活过,无法再次复活");
return;
}
// TODO: 接入广告SDK这里先模拟广告播放成功回调
this.onAdReviveSuccess();
}
/** 广告复活成功回调 */
private onAdReviveSuccess() {
mLogger.log(this.debugMode, 'VictoryComp', "[VictoryComp] 广告复活成功");
mLogger.log(this.debugMode, 'VictoryComp', "[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.pause = 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;
mLogger.log(this.debugMode, 'VictoryComp', `[VictoryComp] 复活英雄: ${attrs.hero_name}`);
}
});
if (hasRevived) {
// 发送复活事件(如果有需要)
// oops.message.dispatchEvent(GameEvent.HeroRevived);
} else {
mLogger.log(this.debugMode, 'VictoryComp', "[VictoryComp] 未找到可复活的英雄实体");
}
}
restart(){
this.clear_data()
// 确保游戏结束事件被触发,以便重置状态
oops.message.dispatchEvent(GameEvent.MissionEnd)
this.node.getChildByName("loading").active=true
this.scheduleOnce(()=>{
oops.message.dispatchEvent(GameEvent.MissionStart)
this.node.getChildByName("loading").active=false
oops.gui.removeByNode(this.node)
},0.5)
}
item_show(e:any,val:any){
mLogger.log(this.debugMode, 'VictoryComp', "item_show",val)
}
protected onDestroy(): void {
mLogger.log(this.debugMode, 'VictoryComp', "释放胜利界面");
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy()
}
}