|
@@ -8,6 +8,7 @@ import { WeaponInfo } from './WeaponInfo';
|
|
|
import { SkillManager } from '../SkillSelection/SkillManager';
|
|
import { SkillManager } from '../SkillSelection/SkillManager';
|
|
|
import { Audio } from '../../AudioManager/AudioManager';
|
|
import { Audio } from '../../AudioManager/AudioManager';
|
|
|
import { AdManager } from '../../Ads/AdManager';
|
|
import { AdManager } from '../../Ads/AdManager';
|
|
|
|
|
+import { BundleLoader } from '../../Core/BundleLoader';
|
|
|
|
|
|
|
|
import EventBus, { GameEvents } from '../../Core/EventBus';
|
|
import EventBus, { GameEvents } from '../../Core/EventBus';
|
|
|
const { ccclass, property } = _decorator;
|
|
const { ccclass, property } = _decorator;
|
|
@@ -82,12 +83,22 @@ export class GameBlockSelection extends Component {
|
|
|
})
|
|
})
|
|
|
public weaponsConfig: JsonAsset = null;
|
|
public weaponsConfig: JsonAsset = null;
|
|
|
|
|
|
|
|
- // 小球价格配置JsonAsset - 通过装饰器预加载
|
|
|
|
|
|
|
+ // 小球价格配置数据 - 通过BundleLoader动态加载
|
|
|
|
|
+ private ballPriceConfigData: any = null;
|
|
|
|
|
+
|
|
|
|
|
+ // 新增小球价格显示节点 - 对应addBallPricing
|
|
|
@property({
|
|
@property({
|
|
|
- type: JsonAsset,
|
|
|
|
|
- tooltip: '拖拽ball_price_config.json文件到这里,实现价格配置预加载'
|
|
|
|
|
|
|
+ type: Node,
|
|
|
|
|
+ tooltip: '拖拽Canvas/GameLevelUI/BlockSelectionUI/diban/ann001/Ball/db01/Price节点到这里'
|
|
|
|
|
+ })
|
|
|
|
|
+ public addBallPriceNode: Node = null;
|
|
|
|
|
+
|
|
|
|
|
+ // 刷新方块价格显示节点 - 对应refreshBlockPricing
|
|
|
|
|
+ @property({
|
|
|
|
|
+ type: Node,
|
|
|
|
|
+ tooltip: '拖拽Canvas/GameLevelUI/BlockSelectionUI/diban/ann003/Ball/db01/Price节点到这里'
|
|
|
})
|
|
})
|
|
|
- public ballPriceConfig: JsonAsset = null;
|
|
|
|
|
|
|
+ public refreshBlockPriceNode: Node = null;
|
|
|
|
|
|
|
|
// 常量定义
|
|
// 常量定义
|
|
|
private readonly ADD_COIN_AMOUNT = 80;
|
|
private readonly ADD_COIN_AMOUNT = 80;
|
|
@@ -102,18 +113,29 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
|
|
// 价格获取方法
|
|
// 价格获取方法
|
|
|
private getAddBallCost(): number {
|
|
private getAddBallCost(): number {
|
|
|
- if (this.ballPriceConfig && this.ballPriceConfig.json && this.ballPriceConfig.json.priceHistory) {
|
|
|
|
|
- return this.ballPriceConfig.json.priceHistory.addBallCurrentPrice || this.DEFAULT_ADD_BALL_BASE_PRICE;
|
|
|
|
|
|
|
+ // 优先从JSON配置中获取价格
|
|
|
|
|
+ if (this.ballPriceConfigData && this.ballPriceConfigData.addBallPricing) {
|
|
|
|
|
+ return this.ballPriceConfigData.addBallPricing.initialPrice || this.DEFAULT_ADD_BALL_BASE_PRICE;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 其次从装饰器绑定的节点获取价格
|
|
|
try {
|
|
try {
|
|
|
- const priceNode = find('Canvas/GameLevelUI/BlockSelectionUI/diban/ann001/Ball/db01/Price');
|
|
|
|
|
- if (priceNode) {
|
|
|
|
|
- const label = priceNode.getComponent(Label);
|
|
|
|
|
|
|
+ if (this.addBallPriceNode) {
|
|
|
|
|
+ const label = this.addBallPriceNode.getComponent(Label);
|
|
|
if (label) {
|
|
if (label) {
|
|
|
const price = parseInt(label.string);
|
|
const price = parseInt(label.string);
|
|
|
return isNaN(price) ? this.DEFAULT_ADD_BALL_BASE_PRICE : price;
|
|
return isNaN(price) ? this.DEFAULT_ADD_BALL_BASE_PRICE : price;
|
|
|
}
|
|
}
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 回退到find方法(兼容性)
|
|
|
|
|
+ const priceNode = find('Canvas/GameLevelUI/BlockSelectionUI/diban/ann001/Ball/db01/Price');
|
|
|
|
|
+ if (priceNode) {
|
|
|
|
|
+ const label = priceNode.getComponent(Label);
|
|
|
|
|
+ if (label) {
|
|
|
|
|
+ const price = parseInt(label.string);
|
|
|
|
|
+ return isNaN(price) ? this.DEFAULT_ADD_BALL_BASE_PRICE : price;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.warn('[GameBlockSelection] 获取新增小球价格失败:', error);
|
|
console.warn('[GameBlockSelection] 获取新增小球价格失败:', error);
|
|
@@ -121,19 +143,32 @@ export class GameBlockSelection extends Component {
|
|
|
return this.DEFAULT_ADD_BALL_BASE_PRICE; // 默认价格
|
|
return this.DEFAULT_ADD_BALL_BASE_PRICE; // 默认价格
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private getRefreshCost(): number {
|
|
|
|
|
- if (this.ballPriceConfig && this.ballPriceConfig.json && this.ballPriceConfig.json.priceHistory) {
|
|
|
|
|
- return this.ballPriceConfig.json.priceHistory.refreshBlockCurrentPrice || this.DEFAULT_REFRESH_BASE_PRICE;
|
|
|
|
|
|
|
+ public getRefreshCost(): number {
|
|
|
|
|
+ // 优先从JSON配置中获取价格
|
|
|
|
|
+ console.log('[GameBlockSelection] 刷新方块价格配置:', this.ballPriceConfigData?.refreshBlockPricing);
|
|
|
|
|
+ if (this.ballPriceConfigData && this.ballPriceConfigData.refreshBlockPricing) {
|
|
|
|
|
+ return this.ballPriceConfigData.refreshBlockPricing.initialPrice || this.DEFAULT_REFRESH_BASE_PRICE;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 其次从装饰器绑定的节点获取价格
|
|
|
try {
|
|
try {
|
|
|
- const priceNode = find('Canvas/GameLevelUI/BlockSelectionUI/diban/ann003/Ball/db01/Price');
|
|
|
|
|
- if (priceNode) {
|
|
|
|
|
- const label = priceNode.getComponent(Label);
|
|
|
|
|
|
|
+ if (this.refreshBlockPriceNode) {
|
|
|
|
|
+ console.log('[GameBlockSelection] 刷新方块价格节点:', this.refreshBlockPriceNode);
|
|
|
|
|
+ const label = this.refreshBlockPriceNode.getComponent(Label);
|
|
|
if (label) {
|
|
if (label) {
|
|
|
const price = parseInt(label.string);
|
|
const price = parseInt(label.string);
|
|
|
return isNaN(price) ? this.DEFAULT_REFRESH_BASE_PRICE : price;
|
|
return isNaN(price) ? this.DEFAULT_REFRESH_BASE_PRICE : price;
|
|
|
}
|
|
}
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 回退到find方法(兼容性)
|
|
|
|
|
+ const priceNode = find('Canvas/GameLevelUI/BlockSelectionUI/diban/ann003/Ball/db01/Price');
|
|
|
|
|
+ if (priceNode) {
|
|
|
|
|
+ const label = priceNode.getComponent(Label);
|
|
|
|
|
+ if (label) {
|
|
|
|
|
+ const price = parseInt(label.string);
|
|
|
|
|
+ return isNaN(price) ? this.DEFAULT_REFRESH_BASE_PRICE : price;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.warn('[GameBlockSelection] 获取刷新方块价格失败:', error);
|
|
console.warn('[GameBlockSelection] 获取刷新方块价格失败:', error);
|
|
@@ -186,7 +221,18 @@ export class GameBlockSelection extends Component {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private initializeComponent() {
|
|
|
|
|
|
|
+ private async initializeComponent() {
|
|
|
|
|
+ // 异步加载小球价格配置
|
|
|
|
|
+ try {
|
|
|
|
|
+ const bundleLoader = BundleLoader.getInstance();
|
|
|
|
|
+ const ballPriceConfigAsset = await bundleLoader.loadDataJson('ball_price_config');
|
|
|
|
|
+ this.ballPriceConfigData = ballPriceConfigAsset.json;
|
|
|
|
|
+ console.log('[GameBlockSelection] 小球价格配置加载成功:', this.ballPriceConfigData);
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.warn('[GameBlockSelection] 小球价格配置加载失败:', error);
|
|
|
|
|
+ this.ballPriceConfigData = null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 获取管理器实例
|
|
// 获取管理器实例
|
|
|
this.session = LevelSessionManager.inst;
|
|
this.session = LevelSessionManager.inst;
|
|
|
|
|
|
|
@@ -603,6 +649,9 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
|
|
// 清理所有方块标签
|
|
// 清理所有方块标签
|
|
|
BlockTag.clearAllTags();
|
|
BlockTag.clearAllTags();
|
|
|
|
|
+
|
|
|
|
|
+ // 重置价格历史数据(局内数据,每局重置)
|
|
|
|
|
+ this.resetPriceHistory();
|
|
|
|
|
|
|
|
// 更新金币显示
|
|
// 更新金币显示
|
|
|
this.updateCoinDisplay();
|
|
this.updateCoinDisplay();
|
|
@@ -1260,8 +1309,8 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
|
|
// 获取价格配置数据(如果装饰器配置不存在则返回默认值)
|
|
// 获取价格配置数据(如果装饰器配置不存在则返回默认值)
|
|
|
private getPriceConfigData(): any {
|
|
private getPriceConfigData(): any {
|
|
|
- if (this.ballPriceConfig && this.ballPriceConfig.json) {
|
|
|
|
|
- return this.ballPriceConfig.json;
|
|
|
|
|
|
|
+ if (this.ballPriceConfigData && this.ballPriceConfigData.json) {
|
|
|
|
|
+ return this.ballPriceConfigData.json;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 返回默认配置
|
|
// 返回默认配置
|
|
@@ -1291,10 +1340,10 @@ export class GameBlockSelection extends Component {
|
|
|
const config = configData.addBallPricing;
|
|
const config = configData.addBallPricing;
|
|
|
const history = configData.priceHistory;
|
|
const history = configData.priceHistory;
|
|
|
|
|
|
|
|
- // 增加购买次数
|
|
|
|
|
|
|
+ // 增加购买次数(局内数据,每局会重置)
|
|
|
history.addBallPurchaseCount++;
|
|
history.addBallPurchaseCount++;
|
|
|
|
|
|
|
|
- // 计算新价格
|
|
|
|
|
|
|
+ // 计算新价格(随购买次数增加,但有上限)
|
|
|
const newPrice = Math.min(
|
|
const newPrice = Math.min(
|
|
|
config.initialPrice + (history.addBallPurchaseCount * config.priceIncrement),
|
|
config.initialPrice + (history.addBallPurchaseCount * config.priceIncrement),
|
|
|
config.maxPrice
|
|
config.maxPrice
|
|
@@ -1339,22 +1388,38 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
|
|
// 更新价格显示
|
|
// 更新价格显示
|
|
|
private updatePriceDisplay() {
|
|
private updatePriceDisplay() {
|
|
|
- // 更新新增小球价格显示
|
|
|
|
|
- const addBallPriceNode = find('Canvas/GameLevelUI/BlockSelectionUI/diban/ann001/Ball/db01/Price');
|
|
|
|
|
- if (addBallPriceNode) {
|
|
|
|
|
- const label = addBallPriceNode.getComponent(Label);
|
|
|
|
|
|
|
+ // 更新新增小球价格显示 - 使用装饰器绑定的节点
|
|
|
|
|
+ if (this.addBallPriceNode) {
|
|
|
|
|
+ const label = this.addBallPriceNode.getComponent(Label);
|
|
|
if (label) {
|
|
if (label) {
|
|
|
label.string = this.getAddBallCost().toString();
|
|
label.string = this.getAddBallCost().toString();
|
|
|
}
|
|
}
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 回退到find方法(兼容性)
|
|
|
|
|
+ const addBallPriceNode = find('Canvas/GameLevelUI/BlockSelectionUI/diban/ann001/Ball/db01/Price');
|
|
|
|
|
+ if (addBallPriceNode) {
|
|
|
|
|
+ const label = addBallPriceNode.getComponent(Label);
|
|
|
|
|
+ if (label) {
|
|
|
|
|
+ label.string = this.getAddBallCost().toString();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 更新刷新方块价格显示
|
|
|
|
|
- const refreshPriceNode = find('Canvas/GameLevelUI/BlockSelectionUI/diban/ann003/Ball/db01/Price');
|
|
|
|
|
- if (refreshPriceNode) {
|
|
|
|
|
- const label = refreshPriceNode.getComponent(Label);
|
|
|
|
|
|
|
+ // 更新刷新方块价格显示 - 使用装饰器绑定的节点
|
|
|
|
|
+ if (this.refreshBlockPriceNode) {
|
|
|
|
|
+ const label = this.refreshBlockPriceNode.getComponent(Label);
|
|
|
if (label) {
|
|
if (label) {
|
|
|
label.string = this.getRefreshCost().toString();
|
|
label.string = this.getRefreshCost().toString();
|
|
|
}
|
|
}
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 回退到find方法(兼容性)
|
|
|
|
|
+ const refreshPriceNode = find('Canvas/GameLevelUI/BlockSelectionUI/diban/ann003/Ball/db01/Price');
|
|
|
|
|
+ if (refreshPriceNode) {
|
|
|
|
|
+ const label = refreshPriceNode.getComponent(Label);
|
|
|
|
|
+ if (label) {
|
|
|
|
|
+ label.string = this.getRefreshCost().toString();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1365,4 +1430,25 @@ export class GameBlockSelection extends Component {
|
|
|
// 在实际项目中,价格变化应该保存到本地存储或服务器
|
|
// 在实际项目中,价格变化应该保存到本地存储或服务器
|
|
|
console.log('[GameBlockSelection] 价格配置已更新:', JSON.stringify(configData, null, 2));
|
|
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] 价格历史数据已重置到初始状态');
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|