|
|
@@ -76,13 +76,6 @@ export class GameBlockSelection extends Component {
|
|
|
})
|
|
|
public cameraNode: Node = null;
|
|
|
|
|
|
- // 武器配置JsonAsset - 通过装饰器预加载
|
|
|
- // @property({
|
|
|
- // type: JsonAsset,
|
|
|
- // tooltip: '拖拽weapons.json文件到这里,实现配置预加载'
|
|
|
- // })
|
|
|
- // public weaponsConfig: JsonAsset = null;
|
|
|
-
|
|
|
// 武器配置数据,通过 BundleLoader 异步加载
|
|
|
private weaponsConfigData: any = null;
|
|
|
|
|
|
@@ -168,7 +161,18 @@ export class GameBlockSelection extends Component {
|
|
|
private getAddBallCost(): number {
|
|
|
// 优先从JSON配置中获取价格
|
|
|
if (this.ballPriceConfigData && this.ballPriceConfigData.addBallPricing) {
|
|
|
- return this.ballPriceConfigData.addBallPricing.initialPrice || this.DEFAULT_ADD_BALL_BASE_PRICE;
|
|
|
+ const config = this.ballPriceConfigData.addBallPricing;
|
|
|
+ const basePrice = config.initialPrice || this.DEFAULT_ADD_BALL_BASE_PRICE;
|
|
|
+ const increment = config.priceIncrement || this.DEFAULT_ADD_BALL_INCREMENT;
|
|
|
+ const maxPrice = config.maxPrice || this.DEFAULT_ADD_BALL_MAX_PRICE;
|
|
|
+
|
|
|
+ // 获取当前使用次数
|
|
|
+ const session = this.session || LevelSessionManager.inst;
|
|
|
+ const usageCount = session ? session.getAddBallUsageCount() : 0;
|
|
|
+
|
|
|
+ // 计算当前价格
|
|
|
+ const currentPrice = Math.min(basePrice + (usageCount * increment), maxPrice);
|
|
|
+ return currentPrice;
|
|
|
}
|
|
|
|
|
|
// 其次从装饰器绑定的节点获取价格
|
|
|
@@ -200,7 +204,18 @@ export class GameBlockSelection extends Component {
|
|
|
// 优先从JSON配置中获取价格
|
|
|
console.log('[GameBlockSelection] 刷新方块价格配置:', this.ballPriceConfigData?.refreshBlockPricing);
|
|
|
if (this.ballPriceConfigData && this.ballPriceConfigData.refreshBlockPricing) {
|
|
|
- return this.ballPriceConfigData.refreshBlockPricing.initialPrice || this.DEFAULT_REFRESH_BASE_PRICE;
|
|
|
+ const config = this.ballPriceConfigData.refreshBlockPricing;
|
|
|
+ const basePrice = config.initialPrice || this.DEFAULT_REFRESH_BASE_PRICE;
|
|
|
+ const increment = config.priceIncrement || this.DEFAULT_REFRESH_INCREMENT;
|
|
|
+ const maxPrice = config.maxPrice || this.DEFAULT_REFRESH_MAX_PRICE;
|
|
|
+
|
|
|
+ // 获取当前使用次数
|
|
|
+ const session = this.session || LevelSessionManager.inst;
|
|
|
+ const usageCount = session ? session.getRefreshUsageCount() : 0;
|
|
|
+
|
|
|
+ // 计算当前价格
|
|
|
+ const currentPrice = Math.min(basePrice + (usageCount * increment), maxPrice);
|
|
|
+ return currentPrice;
|
|
|
}
|
|
|
|
|
|
// 其次从装饰器绑定的节点获取价格
|
|
|
@@ -461,8 +476,8 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
this.updateCoinDisplay();
|
|
|
|
|
|
- // 更新价格配置(增加购买次数和价格)
|
|
|
- this.updateAddBallPrice();
|
|
|
+ // 更新价格显示
|
|
|
+ this.updatePriceDisplay();
|
|
|
|
|
|
// 通过事件系统创建新的小球
|
|
|
const eventBus = EventBus.getInstance();
|
|
|
@@ -518,8 +533,8 @@ export class GameBlockSelection extends Component {
|
|
|
// 成功扣除金币
|
|
|
this.updateCoinDisplay();
|
|
|
|
|
|
- // 更新价格配置(增加购买次数和价格)
|
|
|
- this.updateRefreshPrice();
|
|
|
+ // 更新价格显示
|
|
|
+ this.updatePriceDisplay();
|
|
|
|
|
|
// 刷新方块
|
|
|
if (this.blockManager) {
|
|
|
@@ -725,8 +740,8 @@ export class GameBlockSelection extends Component {
|
|
|
// 清理所有方块标签
|
|
|
BlockTag.clearAllTags();
|
|
|
|
|
|
- // 重置价格历史数据(局内数据,每局重置)
|
|
|
- this.resetPriceHistory();
|
|
|
+ // 更新价格显示(使用次数已在session中重置)
|
|
|
+ this.updatePriceDisplay();
|
|
|
|
|
|
// 更新金币显示
|
|
|
this.updateCoinDisplay();
|
|
|
@@ -1382,89 +1397,13 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
// === 价格配置管理方法 ===
|
|
|
|
|
|
- // 获取价格配置数据(如果装饰器配置不存在则返回默认值)
|
|
|
- private getPriceConfigData(): any {
|
|
|
- if (this.ballPriceConfigData && this.ballPriceConfigData.json) {
|
|
|
- return this.ballPriceConfigData.json;
|
|
|
- }
|
|
|
-
|
|
|
- // 返回默认配置
|
|
|
- return {
|
|
|
- addBallPricing: {
|
|
|
- initialPrice: this.DEFAULT_ADD_BALL_BASE_PRICE,
|
|
|
- priceIncrement: this.DEFAULT_ADD_BALL_INCREMENT,
|
|
|
- maxPrice: this.DEFAULT_ADD_BALL_MAX_PRICE
|
|
|
- },
|
|
|
- refreshBlockPricing: {
|
|
|
- initialPrice: this.DEFAULT_REFRESH_BASE_PRICE,
|
|
|
- priceIncrement: this.DEFAULT_REFRESH_INCREMENT,
|
|
|
- maxPrice: this.DEFAULT_REFRESH_MAX_PRICE
|
|
|
- },
|
|
|
- priceHistory: {
|
|
|
- addBallCurrentPrice: this.DEFAULT_ADD_BALL_BASE_PRICE,
|
|
|
- refreshBlockCurrentPrice: this.DEFAULT_REFRESH_BASE_PRICE,
|
|
|
- addBallPurchaseCount: 0,
|
|
|
- refreshBlockPurchaseCount: 0
|
|
|
- }
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- // 更新新增小球价格
|
|
|
- private updateAddBallPrice() {
|
|
|
- const configData = this.getPriceConfigData();
|
|
|
- const config = configData.addBallPricing;
|
|
|
- const history = configData.priceHistory;
|
|
|
-
|
|
|
- // 增加购买次数(局内数据,每局会重置)
|
|
|
- history.addBallPurchaseCount++;
|
|
|
-
|
|
|
- // 计算新价格(随购买次数增加,但有上限)
|
|
|
- const newPrice = Math.min(
|
|
|
- config.initialPrice + (history.addBallPurchaseCount * config.priceIncrement),
|
|
|
- config.maxPrice
|
|
|
- );
|
|
|
-
|
|
|
- history.addBallCurrentPrice = newPrice;
|
|
|
-
|
|
|
- // 更新UI显示
|
|
|
- this.updatePriceDisplay();
|
|
|
-
|
|
|
- // 保存配置(注意:装饰器配置是只读的,这里只是打印日志)
|
|
|
- this.saveBallPriceConfig();
|
|
|
-
|
|
|
- console.log(`[GameBlockSelection] 新增小球价格更新: ${newPrice}, 购买次数: ${history.addBallPurchaseCount}`);
|
|
|
- }
|
|
|
-
|
|
|
- // 更新刷新方块价格
|
|
|
- private updateRefreshPrice() {
|
|
|
- const configData = this.getPriceConfigData();
|
|
|
- const config = configData.refreshBlockPricing;
|
|
|
- const history = configData.priceHistory;
|
|
|
-
|
|
|
- // 增加购买次数
|
|
|
- history.refreshBlockPurchaseCount++;
|
|
|
-
|
|
|
- // 计算新价格
|
|
|
- const newPrice = Math.min(
|
|
|
- config.initialPrice + (history.refreshBlockPurchaseCount * config.priceIncrement),
|
|
|
- config.maxPrice
|
|
|
- );
|
|
|
-
|
|
|
- history.refreshBlockCurrentPrice = newPrice;
|
|
|
-
|
|
|
- // 更新UI显示
|
|
|
- this.updatePriceDisplay();
|
|
|
-
|
|
|
- // 保存配置(注意:装饰器配置是只读的,这里只是打印日志)
|
|
|
- this.saveBallPriceConfig();
|
|
|
-
|
|
|
- console.log(`[GameBlockSelection] 刷新方块价格更新: ${newPrice}, 购买次数: ${history.refreshBlockPurchaseCount}`);
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
// 更新价格显示
|
|
|
private updatePriceDisplay() {
|
|
|
// 更新新增小球价格显示 - 使用装饰器绑定的节点
|
|
|
if (this.addBallPriceNode) {
|
|
|
+ console.log(`[GameBlockSelection] 更新新增小球价格显示: ${this.getAddBallCost()}`);
|
|
|
const label = this.addBallPriceNode.getComponent(Label);
|
|
|
if (label) {
|
|
|
label.string = this.getAddBallCost().toString();
|
|
|
@@ -1482,6 +1421,7 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
// 更新刷新方块价格显示 - 使用装饰器绑定的节点
|
|
|
if (this.refreshBlockPriceNode) {
|
|
|
+ console.log(`[GameBlockSelection] 更新刷新方块价格显示: ${this.getRefreshCost()}`);
|
|
|
const label = this.refreshBlockPriceNode.getComponent(Label);
|
|
|
if (label) {
|
|
|
label.string = this.getRefreshCost().toString();
|
|
|
@@ -1522,32 +1462,5 @@ export class GameBlockSelection extends Component {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 保存价格配置(装饰器配置是只读的,这里只是打印日志用于调试)
|
|
|
- private saveBallPriceConfig() {
|
|
|
- const configData = this.getPriceConfigData();
|
|
|
- // 装饰器预加载的配置是只读的,无法直接修改
|
|
|
- // 在实际项目中,价格变化应该保存到本地存储或服务器
|
|
|
- console.log('[GameBlockSelection] 价格配置已更新:', JSON.stringify(configData, null, 2));
|
|
|
- }
|
|
|
-
|
|
|
- // 重置价格历史数据(每局开始时调用)
|
|
|
- private resetPriceHistory() {
|
|
|
- const configData = this.getPriceConfigData();
|
|
|
- const config = configData.addBallPricing;
|
|
|
- const refreshConfig = configData.refreshBlockPricing;
|
|
|
- const history = configData.priceHistory;
|
|
|
-
|
|
|
- // 重置购买次数
|
|
|
- history.addBallPurchaseCount = 0;
|
|
|
- history.refreshBlockPurchaseCount = 0;
|
|
|
-
|
|
|
- // 重置价格为初始价格
|
|
|
- history.addBallCurrentPrice = config.initialPrice;
|
|
|
- history.refreshBlockCurrentPrice = refreshConfig.initialPrice;
|
|
|
-
|
|
|
- // 更新UI显示
|
|
|
- this.updatePriceDisplay();
|
|
|
-
|
|
|
- console.log('[GameBlockSelection] 价格历史数据已重置到初始状态');
|
|
|
- }
|
|
|
+
|
|
|
}
|