hero 升级

This commit is contained in:
panw
2025-08-15 16:33:02 +08:00
parent 94231cb3b1
commit 739600de89
9 changed files with 3225 additions and 2159 deletions

View File

@@ -28,6 +28,7 @@ export class SingletonModuleComp extends ecs.Comp {
gold:100,
diamond:100,
meat:0,
exp:0,
}
fight_heros:any={
0:5001,
@@ -52,6 +53,7 @@ export class SingletonModuleComp extends ecs.Comp {
game_pause:false,
mission_data:{
gold:1000,//金币
exp:0,//经验
score:0,//分数
diamond:0,//钻石
mission:1,//关卡
@@ -379,12 +381,26 @@ export class SingletonModuleComp extends ecs.Comp {
this.data[property] = value;
this.vmdata.mission_data[property] = value;
console.log(`[SMC]: 设置游戏数据 ${property} = ${value}`);
if (autoSave) {
this.saveGameData();
}
}
addGameProperty(property: string, value: any, autoSave: boolean = true) {
this.data[property] = this.data[property] + value;
this.vmdata.mission_data[property] = this.data[property]
console.log(`[SMC]:增加游戏数据 ${property} = ${value}`);
if (autoSave) {
this.saveGameData();
}
}
spendGameProperty(property: string, value: any, autoSave: boolean = true) {
this.data[property] = this.data[property] - value;
this.vmdata.mission_data[property] = this.data[property]
console.log(`[SMC]: 消耗游戏数据 ${property} = ${value}`);
if (autoSave) {
this.saveGameData();
}
}
/**
* 获取游戏数据属性
* @param property 属性名
@@ -394,25 +410,14 @@ export class SingletonModuleComp extends ecs.Comp {
return this.data[property] !== undefined ? this.data[property] : defaultValue;
}
/**
* 增加金币
* @param amount 金币数量
* @param autoSave 是否自动保存 (默认true)
*/
addGold(amount: number, autoSave: boolean = true) {
const currentGold = this.getGameProperty("gold", 0);
const newGold = Math.max(0, currentGold + amount);
this.setGameProperty("gold", newGold, autoSave);
console.log(`[SMC]: 金币变更: ${currentGold} -> ${newGold} (${amount > 0 ? '+' : ''}${amount})`);
return newGold;
}
syncData(){
this.vmdata.mission_data.gold=this.getGameProperty("gold", 0)
this.vmdata.mission_data.meat=this.getGameProperty("meat", 0)
this.vmdata.mission_data.diamond=this.getGameProperty("diamond", 0)
this.vmdata.mission_data.mission=this.getGameProperty("mission", 1)
this.vmdata.mission_data.score=this.getGameProperty("score", 0)
this.vmdata.mission_data.exp=this.getGameProperty("exp", 0)
// 计算章节和关卡等级
const currentMission = this.getGameProperty("mission", 1)
this.vmdata.mission_data.chapter = Math.floor((currentMission - 1) / 10) + 1
@@ -430,6 +435,19 @@ export class SingletonModuleComp extends ecs.Comp {
this.vmdata.reward.ycard=0
}
/**
* 增加金币
* @param amount 金币数量
* @param autoSave 是否自动保存 (默认true)
*/
addGold(amount: number, autoSave: boolean = true) {
const currentGold = this.getGameProperty("gold", 0);
const newGold = Math.max(0, currentGold + amount);
this.setGameProperty("gold", newGold, autoSave);
console.log(`[SMC]: 金币变更: ${currentGold} -> ${newGold} (${amount > 0 ? '+' : ''}${amount})`);
return newGold;
}
/**
* 消耗金币
* @param amount 消耗数量
* @param autoSave 是否自动保存 (默认true)
@@ -446,12 +464,6 @@ export class SingletonModuleComp extends ecs.Comp {
return true;
}
/**
* 获取金币数量
*/
getGold(): number {
return this.getGameProperty("gold", 0);
}
/**
* 增加钻石
@@ -483,25 +495,6 @@ export class SingletonModuleComp extends ecs.Comp {
return true;
}
/**
* 获取钻石数量
*/
getDiamond(): number {
return this.getGameProperty("diamond", 0);
}
/**
* 设置关卡进度
* @param mission 关卡号
* @param autoSave 是否自动保存 (默认true)
*/
setMission(mission: number, autoSave: boolean = true) {
const currentMission = this.getGameProperty("mission", 1);
if (mission > currentMission) {
this.setGameProperty("mission", mission, autoSave);
console.log(`[SMC]: 关卡进度更新: ${currentMission} -> ${mission}`);
}
}
/**
* 增加关卡进度
@@ -519,12 +512,6 @@ export class SingletonModuleComp extends ecs.Comp {
return newMission;
}
/**
* 获取当前关卡进度
*/
getMission(): number {
return this.getGameProperty("mission", 1);
}
/**
* 增加分数
@@ -539,13 +526,6 @@ export class SingletonModuleComp extends ecs.Comp {
return newScore;
}
/**
* 获取当前分数
*/
getScore(): number {
return this.getGameProperty("score", 0);
}
/**
* 重置游戏数据为默认值
* @param autoSave 是否自动保存 (默认true)