hero 升级
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -11,21 +11,21 @@ export enum UIID {
|
||||
/** 资源加载界面 */
|
||||
Loading = 1,
|
||||
/** 弹窗界面 */
|
||||
Window,
|
||||
// Window,
|
||||
/** 加载与延时提示界面 */
|
||||
Netinstable,
|
||||
/** 角色控制 */
|
||||
Role_Controller,
|
||||
// /** 提示窗 */
|
||||
// Toast,
|
||||
HeroInfo,
|
||||
Shop_page,
|
||||
Hero_page,
|
||||
}
|
||||
|
||||
/** 打开界面方式的配置数据 */
|
||||
export var UIConfigData: { [key: number]: UIConfig } = {
|
||||
[UIID.Loading]: { layer: LayerType.UI, prefab: "loading/prefab/loading", bundle: "resources" },
|
||||
[UIID.Netinstable]: { layer: LayerType.PopUp, prefab: "common/prefab/netinstable" },
|
||||
[UIID.Window]: { layer: LayerType.Dialog, prefab: "common/prefab/window" },
|
||||
// [UIID.Window]: { layer: LayerType.Dialog, prefab: "common/prefab/window" },
|
||||
[UIID.Role_Controller]: { layer: LayerType.UI, prefab: "gui/role_controller" },
|
||||
[UIID.HeroInfo]: { layer: LayerType.UI, prefab: "gui/Hinfo" },
|
||||
// [UIID.Toast]: { layer: LayerType.PopUp, prefab: "common/prefab/toast" },
|
||||
|
||||
@@ -359,3 +359,76 @@ export const getMultipleHeroStatsByLevel = (
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 升级资源配置
|
||||
export const UpgradeResourceConfig = {
|
||||
// 经验值配置
|
||||
experience: {
|
||||
base: 100, // 初始值:1级升2级所需经验
|
||||
growth: 1.5, // 增长值:每级增长倍数
|
||||
bonus: 0.2 // 增长值提升比例:5级倍数提升20%
|
||||
},
|
||||
|
||||
// 金币配置
|
||||
gold: {
|
||||
base: 50, // 初始值:1级升2级所需金币
|
||||
growth: 1.3, // 增长值:每级增长倍数
|
||||
bonus: 0.15 // 增长值提升比例:5级倍数提升15%
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取指定等级升级所需的经验值
|
||||
* @param level 当前等级
|
||||
* @returns 升级所需经验值
|
||||
*/
|
||||
export const getUpgradeExperience = (level: number): number => {
|
||||
if (level <= 0) return 0;
|
||||
|
||||
const config = UpgradeResourceConfig.experience;
|
||||
let result = config.base * Math.pow(config.growth, level - 1);
|
||||
|
||||
// 5级倍数提升
|
||||
if (level % 5 === 0) {
|
||||
result = result * (1 + config.bonus);
|
||||
}
|
||||
|
||||
return Math.floor(result);
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取指定等级升级所需的金币
|
||||
* @param level 当前等级
|
||||
* @returns 升级所需金币
|
||||
*/
|
||||
export const getUpgradeGold = (level: number): number => {
|
||||
if (level <= 0) return 0;
|
||||
|
||||
const config = UpgradeResourceConfig.gold;
|
||||
let result = config.base * Math.pow(config.growth, level - 1);
|
||||
|
||||
// 5级倍数提升
|
||||
if (level % 5 === 0) {
|
||||
result = result * (1 + config.bonus);
|
||||
}
|
||||
|
||||
return Math.floor(result);
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取指定等级升级所需的所有资源
|
||||
* @param level 当前等级
|
||||
* @returns 升级资源信息 {experience, gold}
|
||||
*/
|
||||
export const getUpgradeResources = (level: number) => {
|
||||
return {
|
||||
experience: getUpgradeExperience(level),
|
||||
gold: getUpgradeGold(level)
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user