refactor(mission): 优化肉鸽关卡及怪物生成逻辑
- 将出战英雄配置由数组改为单个英雄编号,简化相关接口和数据结构 - 统一出战英雄设置和获取方法,移除冗余多英雄管理逻辑 - 增加怪物生成时的强度倍率参数,支持怪物属性随关卡进度递增调整 - 扩展肉鸽模式配置,实现关卡类型区分及怪物数量动态计算 - 新增随机事件系统,支持事件关卡随机触发宝箱、陷阱、增益、减益等事件 - 优化怪物生成流程,整合怪物配置、等级和强度倍率信息,增强游戏体验
This commit is contained in:
@@ -38,30 +38,18 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
exp:0,
|
||||
task:0,
|
||||
}
|
||||
shop:any={
|
||||
daily:[1001,1004,1002,1005],
|
||||
weekly:[],
|
||||
monthly:[],
|
||||
special:[],
|
||||
goods_count:[1,1,3,3,10,10,10,10,10,10,10,10],
|
||||
|
||||
}
|
||||
fight_heros:any={ 0:5001, 1:5005, 2:0, 3:0, 4:0, }
|
||||
|
||||
fight_hero: number = 5001; // 单个出战英雄
|
||||
heros:any = {
|
||||
5001:{uuid:5001,lv:1},
|
||||
5005:{uuid:5005,lv:1},
|
||||
};
|
||||
items:any={
|
||||
}
|
||||
tals:any={
|
||||
}
|
||||
equips:any={
|
||||
}
|
||||
monsters:any = [];
|
||||
sk_info:any = []
|
||||
monsters_dead:any = []
|
||||
heros_dead:any = []
|
||||
enhancements:any=[]
|
||||
items: any = {}; // 物品数据
|
||||
vmdata: any = {
|
||||
game_over:false,
|
||||
game_pause:false,
|
||||
@@ -121,57 +109,23 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
return true
|
||||
}
|
||||
|
||||
setFightHero(position:number,heroId:number,autoSave:boolean=true){
|
||||
this.fight_heros[position] = heroId;
|
||||
if(this.isWxClient()){
|
||||
this.updateFightHeros()
|
||||
// 设置单个出战英雄
|
||||
setFightHero(heroId: number, autoSave: boolean = true) {
|
||||
this.fight_hero = heroId;
|
||||
if (this.isWxClient()) {
|
||||
this.gameDataSyncManager.updateFightHeros({ 0: heroId }); // 适配原有接口
|
||||
}
|
||||
}
|
||||
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){
|
||||
if(this.isWxClient()){
|
||||
let result=this.gameDataSyncManager.levelUpHero(heroId);
|
||||
if(result){
|
||||
this.heros[heroId].lv++;
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
else{
|
||||
this.heros[heroId].lv++;
|
||||
return true
|
||||
}
|
||||
// 获取出战英雄
|
||||
getFightHero(): number {
|
||||
return this.fight_hero;
|
||||
}
|
||||
|
||||
error(){
|
||||
oops.gui.toast("数据处理异常,请重试或重新登录")
|
||||
}
|
||||
addExp(exp:number,autoSave:boolean=true){
|
||||
if(this.isWxClient()){
|
||||
if(this.gameDataSyncManager.addGameProperty("exp",exp)){
|
||||
this.data.exp+=exp
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
this.data.exp+=exp
|
||||
return true
|
||||
}
|
||||
|
||||
addGold(gold:number,autoSave:boolean=true){
|
||||
if(this.isWxClient()){
|
||||
if(this.gameDataSyncManager.addGameProperty("gold",gold)){
|
||||
@@ -187,45 +141,6 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
return true
|
||||
}
|
||||
|
||||
addDiamond(diamond:number,autoSave:boolean=true){
|
||||
if(this.isWxClient()){
|
||||
if(this.gameDataSyncManager.addGameProperty("diamond",diamond)){
|
||||
this.data.diamond+=diamond
|
||||
oops.message.dispatchEvent(GameEvent.DIAMOND_UPDATE)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
this.data.diamond+=diamond
|
||||
oops.message.dispatchEvent(GameEvent.DIAMOND_UPDATE)
|
||||
return true
|
||||
}
|
||||
|
||||
addMission(mission:number,autoSave:boolean=true){
|
||||
if(this.isWxClient()){
|
||||
if(this.gameDataSyncManager.addGameProperty("mission",mission)){
|
||||
this.data.mission+=mission
|
||||
oops.message.dispatchEvent(GameEvent.MISSION_UPDATE)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
this.data.mission+=mission
|
||||
oops.message.dispatchEvent(GameEvent.MISSION_UPDATE)
|
||||
return true
|
||||
}
|
||||
|
||||
spendExp(exp:number,autoSave:boolean=true){
|
||||
if(this.isWxClient()){
|
||||
if(this.gameDataSyncManager.spendGameProperty("exp",exp)){
|
||||
this.data.exp-=exp
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
this.data.exp-=exp
|
||||
return true
|
||||
}
|
||||
spendGold(gold:number,autoSave:boolean=true){
|
||||
if(this.isWxClient()){
|
||||
if(this.gameDataSyncManager.spendGameProperty("gold",gold)){
|
||||
@@ -239,78 +154,6 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
oops.message.dispatchEvent(GameEvent.GOLD_UPDATE)
|
||||
return true
|
||||
}
|
||||
spendDiamond(diamond:number,autoSave:boolean=true){
|
||||
if(this.isWxClient()){
|
||||
if(this.gameDataSyncManager.spendGameProperty("diamond",diamond)){
|
||||
this.data.diamond-=diamond
|
||||
oops.message.dispatchEvent(GameEvent.DIAMOND_UPDATE)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
this.data.diamond-=diamond
|
||||
oops.message.dispatchEvent(GameEvent.DIAMOND_UPDATE)
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* 消耗游戏数据属性(统一接口)
|
||||
* 处理多个字段:spendGameProperty({ gold: 10, exp: 5 })
|
||||
*/
|
||||
async spendGameProperty(property: Record<string, number>, autoSave: boolean = true): Promise<boolean> {
|
||||
if(this.isWxClient()){
|
||||
if(this.gameDataSyncManager.spendGameProperty(property)){
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
// 多字段扣除(原子性:全部满足才扣)
|
||||
const deductions = property as Record<string, number>;
|
||||
// 1) 校验是否全部满足
|
||||
for (const key in deductions) {
|
||||
if (!Object.prototype.hasOwnProperty.call(deductions, key)) continue;
|
||||
const need = deductions[key] ?? 0;
|
||||
const current = this.data[key] || 0;
|
||||
if (current < need) {
|
||||
console.warn(`[SMC]: ${key} 不足,当前: ${current}, 需要: ${need}`);
|
||||
oops.gui.toast(`${key} 不足,当前: ${current}, 需要: ${need}`)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 2) 统一扣减
|
||||
for (const key in deductions) {
|
||||
if (!Object.prototype.hasOwnProperty.call(deductions, key)) continue;
|
||||
const need = deductions[key] ?? 0;
|
||||
const current = this.data[key] || 0;
|
||||
const next = current - need;
|
||||
this.data[key] = next;
|
||||
// console.log(`[SMC]: 消耗游戏数据 ${key} = ${need}, 当前值: ${next}`);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
addItem(item_uuid:number,count:number,autoSave:boolean=true){
|
||||
if(this.isWxClient()){
|
||||
if(this.gameDataSyncManager.addItem(item_uuid,count)){
|
||||
this.items[item_uuid] = (this.items[item_uuid] || 0) + count;
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
this.items[item_uuid] = (this.items[item_uuid] || 0) + count;
|
||||
return true
|
||||
}
|
||||
spendItem(item_uuid:number,count:number,autoSave:boolean=true){
|
||||
if(this.isWxClient()){
|
||||
if(this.gameDataSyncManager.consumeItem(item_uuid,count)){
|
||||
this.items[item_uuid] = (this.items[item_uuid] || 0) - count;
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
this.items[item_uuid] = (this.items[item_uuid] || 0) - count;
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user