148 lines
5.1 KiB
TypeScript
148 lines
5.1 KiB
TypeScript
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(){
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
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()
|
||
}
|
||
} |