- 将出战英雄配置由数组改为单个英雄编号,简化相关接口和数据结构 - 统一出战英雄设置和获取方法,移除冗余多英雄管理逻辑 - 增加怪物生成时的强度倍率参数,支持怪物属性随关卡进度递增调整 - 扩展肉鸽模式配置,实现关卡类型区分及怪物数量动态计算 - 新增随机事件系统,支持事件关卡随机触发宝箱、陷阱、增益、减益等事件 - 优化怪物生成流程,整合怪物配置、等级和强度倍率信息,增强游戏体验
161 lines
4.7 KiB
TypeScript
161 lines
4.7 KiB
TypeScript
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 { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
|
import { GameData, WxCloudApi } from "../wx_clound_client_api/WxCloudApi";
|
|
import { gameDataSyncManager } from "./GameDataSyncManager";
|
|
import { Test } from "./Test";
|
|
import { GameEvent } from "./config/GameEvent";
|
|
|
|
|
|
// 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,
|
|
};
|
|
guides:any=[0,0,0,0,0]
|
|
current_guide:number=0
|
|
data:any={
|
|
score:0,
|
|
mission:1,
|
|
gold:100, //升级主要资源
|
|
diamond:100, //商店购买 及 双倍奖励资源
|
|
meat:0,
|
|
exp:0,
|
|
task:0,
|
|
}
|
|
|
|
fight_hero: number = 5001; // 单个出战英雄
|
|
heros:any = {
|
|
5001:{uuid:5001,lv:1},
|
|
5005:{uuid:5005,lv:1},
|
|
};
|
|
monsters:any = [];
|
|
sk_info:any = []
|
|
monsters_dead:any = []
|
|
heros_dead:any = []
|
|
enhancements:any=[]
|
|
items: any = {}; // 物品数据
|
|
vmdata: any = {
|
|
game_over:false,
|
|
game_pause:false,
|
|
mission_data:{
|
|
mon_num:0,//怪物数量
|
|
hero_num:0,//英雄数量
|
|
wave_time_num:0,//波次时间
|
|
in_fight:false,
|
|
fight_time:0,//战斗时间
|
|
level:1,//关卡等级
|
|
max_mission:4,//最大关卡
|
|
},
|
|
};
|
|
vmAdd() {
|
|
VM.add(this.vmdata, "data");
|
|
}
|
|
reset() {
|
|
for (var key in this.vmdata) {
|
|
delete this.vmdata[key];
|
|
}
|
|
}
|
|
|
|
// ==================== 数据管理方法 ====================
|
|
|
|
/**
|
|
* 判断是否为微信客户端
|
|
*/
|
|
private isWxClient(): boolean {
|
|
// 检查是否存在微信API
|
|
return typeof wx !== 'undefined' && typeof (wx as any).getSystemInfoSync === 'function';
|
|
}
|
|
|
|
finishGuide(index:number){
|
|
smc.guides[index]=1
|
|
this.syncGuide()
|
|
}
|
|
|
|
syncGuide(){
|
|
//存储到远程服务器 后续再添加
|
|
}
|
|
//调试用
|
|
syncDataFromLocal(){
|
|
if(this.isWxClient()) return
|
|
const loginResult = new Test().load_data_from_local()
|
|
this.gameDataSyncManager.overrideLocalDataWithRemote(loginResult, "本地调试");
|
|
}
|
|
|
|
addHero(hero_uuid:number,autoSave:boolean=true){
|
|
if(this.isWxClient()){
|
|
if(this.gameDataSyncManager.addHero(hero_uuid)){
|
|
this.heros[hero_uuid]={ uuid:hero_uuid, lv:1, }
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
this.heros[hero_uuid]={ uuid:hero_uuid, lv:1, }
|
|
return true
|
|
}
|
|
|
|
// 设置单个出战英雄
|
|
setFightHero(heroId: number, autoSave: boolean = true) {
|
|
this.fight_hero = heroId;
|
|
if (this.isWxClient()) {
|
|
this.gameDataSyncManager.updateFightHeros({ 0: heroId }); // 适配原有接口
|
|
}
|
|
}
|
|
|
|
// 获取出战英雄
|
|
getFightHero(): number {
|
|
return this.fight_hero;
|
|
}
|
|
|
|
error(){
|
|
oops.gui.toast("数据处理异常,请重试或重新登录")
|
|
}
|
|
|
|
addGold(gold:number,autoSave:boolean=true){
|
|
if(this.isWxClient()){
|
|
if(this.gameDataSyncManager.addGameProperty("gold",gold)){
|
|
this.data.gold+=gold
|
|
oops.message.dispatchEvent(GameEvent.GOLD_UPDATE)
|
|
return true
|
|
}
|
|
this.error()
|
|
return false
|
|
}
|
|
this.data.gold+=gold
|
|
oops.message.dispatchEvent(GameEvent.GOLD_UPDATE)
|
|
return true
|
|
}
|
|
|
|
spendGold(gold:number,autoSave:boolean=true){
|
|
if(this.isWxClient()){
|
|
if(this.gameDataSyncManager.spendGameProperty("gold",gold)){
|
|
this.data.gold-=gold
|
|
oops.message.dispatchEvent(GameEvent.GOLD_UPDATE)
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
this.data.gold-=gold
|
|
oops.message.dispatchEvent(GameEvent.GOLD_UPDATE)
|
|
return true
|
|
}
|
|
|
|
|
|
}
|
|
|
|
export var smc: SingletonModuleComp = ecs.getSingleton(SingletonModuleComp); |