import { VM } from "../../../../extensions/oops-plugin-framework/assets/libs/model-view/ViewModel"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { Initialize } from "../initialize/Initialize"; import { GameMap } from "../map/GameMap"; import { HeroUI, VmInfo } from "./config/Mission"; import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; import { WxCloudApi } from "../wx_clound_client_api/WxCloudApi"; import { gameDataSyncManager } from "./GameDataSyncManager"; import { GameSet } from "./config/BoxSet"; import { Test } from "./Test"; // import { Role } from "../role/Role"; // import { data } from "../data/data"; /** 游戏模块 */ @ecs.register('SingletonModule') export class SingletonModuleComp extends ecs.Comp { /** 游戏初始化模块 */ initialize: Initialize = null!; /** 游戏地图 */ map: GameMap = null!; /** 游戏数据同步管理器 */ private gameDataSyncManager = gameDataSyncManager; mission:any={ status:0, //0:未开始 1:进行中 2:胜利 3:失败 play:false, pause:false, in_select:false, in_fight:false, }; data:any={ score:0, mission:1, gold:100, //升级主要资源 diamond:100, //商店购买 及 双倍奖励资源 meat:0, exp:0, //升级经验 ghstone:0, //英雄石 绿色 普通英雄升星 bhstone:0, //英雄石 蓝色 稀有英雄升星 phlestone:0, //英雄石 紫色 史诗英雄升星 rhstone:0, //英雄石 红色 传说英雄升星 herocard:0, //英雄卡,抽卡凭证 ckey:0, //铜钥匙 解锁稀有英雄 也可以直接兑换金币 skey:0, //银钥匙 解锁史诗英雄 也可以直接兑换金币 gkey:0, //金钥匙 解锁传说英雄 也可以直接兑换金币 } fight_heros:any={ 0:5001, 1:5005, 2:0, 3:0, 4:0, } heros:any = { 5001:{uuid:5001,lv:1}, 5005:{uuid:5005,lv:1}, 5007:{uuid:5007,lv:1}, }; itmes:any={ } tals:any={ } equips:any={ } monsters:any = []; sk_info:any = [] monsters_dead:any = [] heros_dead:any = [] enhancements:any=[] vmdata: any = { game_over:false, game_pause:false, data:{ score:0, mission:1, gold:100, //升级主要资源 diamond:100, //商店购买 及 双倍奖励资源 meat:0, exp:0, //升级经验 ghstone:0, //英雄石 绿色 普通英雄升星 bhstone:0, //英雄石 蓝色 稀有英雄升星 phlestone:0, //英雄石 紫色 史诗英雄升星 rhstone:0, //英雄石 红色 传说英雄升星 herocard:0, //英雄卡,抽卡凭证 ckey:0, //铜钥匙 解锁稀有英雄 也可以直接兑换金币 skey:0, //银钥匙 解锁史诗英雄 也可以直接兑换金币 gkey:0, //金钥匙 解锁传说英雄 也可以直接兑换金币 }, mission_data:{ mon_num:0,//怪物数量 hero_num:0,//英雄数量 wave_time_num:0,//波次时间 in_fight:false, fight_time:0,//战斗时间 level:1,//关卡等级 max_mission:4,//最大关卡 }, reward:{ score:0, mission:0, gold:0, //升级主要资源 diamond:0, //商店购买 及 双倍奖励资源 meat:0, exp:0, //升级经验 ghstone:0, //英雄石 绿色 普通英雄升星 bhstone:0, //英雄石 蓝色 稀有英雄升星 phlestone:0, //英雄石 紫色 史诗英雄升星 rhstone:0, //英雄石 红色 传说英雄升星 herocard:0, //英雄卡,抽卡凭证 ckey:0, //铜钥匙 解锁稀有英雄 也可以直接兑换金币 skey:0, //银钥匙 解锁史诗英雄 也可以直接兑换金币 gkey:0, //金钥匙 解锁传说英雄 也可以直接兑换金币 } }; vmAdd() { VM.add(this.vmdata, "data"); } reset() { for (var key in this.vmdata) { delete this.vmdata[key]; } } // ==================== 数据管理方法 ==================== /** * 同步数据到vmdata */ syncData(){ this.vmdata.data = this.data; } /** * 判断是否为微信客户端 */ private isWxClient(): boolean { // 检查是否存在微信API return typeof wx !== 'undefined' && typeof (wx as any).getSystemInfoSync === 'function'; } //调试用 syncDataFromLocal(){ if(this.isWxClient()) return const loginResult = new Test().load_data_from_local() this.gameDataSyncManager.overrideLocalDataWithRemote(loginResult, "本地调试"); } setFightHero(position:number,heroId:number,autoSave:boolean=true){ this.fight_heros[position] = heroId; if(autoSave){ this.updateFightHeros() } } updateFightHeros(){ this.gameDataSyncManager.updateFightHeros(this.fight_heros); } resetFightHeros(){ this.gameDataSyncManager.resetFightHeros(); } getHasHeroUUID(){ let heros=this.heros let heros_uuid=[] for(let key in heros){ heros_uuid.push(heros[key].uuid) } return heros_uuid } levelUpHero(heroId:number,exp:number,gold:number){ let result=this.gameDataSyncManager.levelUpHero(heroId,exp,gold); if(result){ this.heros[heroId].lv++; } return result; } // ==================== 统一的数据操作接口 ==================== /** * 增加游戏数据属性(统一接口) * @param property 属性名 * @param value 增加的值 * @param autoSave 是否自动保存 (默认true) * @returns 操作结果 */ async addGameProperty(property: string, value: any, autoSave: boolean = true): Promise { const currentValue = this.data[property] || 0; const newValue = currentValue + value; this.data[property] = newValue; this.vmdata.data[property] = newValue; console.log(`[SMC]: 增加游戏数据 ${property} = ${value}, 当前值: ${newValue}`); return newValue; } /** * 消耗游戏数据属性(统一接口) * @param property 属性名 * @param value 消耗的值 * @param autoSave 是否自动保存 (默认true) * @returns 是否成功消耗 */ async spendGameProperty(property: string, value: any, autoSave: boolean = true): Promise { const currentValue = this.data[property] || 0; if (currentValue < value) { console.warn(`[SMC]: ${property} 不足,当前: ${currentValue}, 需要: ${value}`); return false; } const newValue = currentValue - value; this.data[property] = newValue; this.vmdata.data[property] = newValue; console.log(`[SMC]: 消耗游戏数据 ${property} = ${value}, 当前值: ${newValue}`); return true; } } export var smc: SingletonModuleComp = ecs.getSingleton(SingletonModuleComp);