|
|
@@ -7,6 +7,7 @@ import { BlockTag } from './BlockTag';
|
|
|
import { WeaponInfo } from './WeaponInfo';
|
|
|
import { SkillManager } from '../SkillSelection/SkillManager';
|
|
|
import { Audio } from '../../AudioManager/AudioManager';
|
|
|
+import { AdManager } from '../../Ads/AdManager';
|
|
|
|
|
|
import EventBus, { GameEvents } from '../../Core/EventBus';
|
|
|
const { ccclass, property } = _decorator;
|
|
|
@@ -81,10 +82,64 @@ export class GameBlockSelection extends Component {
|
|
|
})
|
|
|
public weaponsConfig: JsonAsset = null;
|
|
|
|
|
|
+ // 小球价格配置JsonAsset - 通过装饰器预加载
|
|
|
+ @property({
|
|
|
+ type: JsonAsset,
|
|
|
+ tooltip: '拖拽ball_price_config.json文件到这里,实现价格配置预加载'
|
|
|
+ })
|
|
|
+ public ballPriceConfig: JsonAsset = null;
|
|
|
+
|
|
|
// 常量定义
|
|
|
- private readonly ADD_BALL_COST = 80;
|
|
|
private readonly ADD_COIN_AMOUNT = 80;
|
|
|
- private readonly REFRESH_COST = 5;
|
|
|
+
|
|
|
+ // 价格配置默认值
|
|
|
+ private readonly DEFAULT_ADD_BALL_BASE_PRICE = 80;
|
|
|
+ private readonly DEFAULT_ADD_BALL_INCREMENT = 10;
|
|
|
+ private readonly DEFAULT_ADD_BALL_MAX_PRICE = 500;
|
|
|
+ private readonly DEFAULT_REFRESH_BASE_PRICE = 5;
|
|
|
+ private readonly DEFAULT_REFRESH_INCREMENT = 2;
|
|
|
+ private readonly DEFAULT_REFRESH_MAX_PRICE = 50;
|
|
|
+
|
|
|
+ // 价格获取方法
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ 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) {
|
|
|
+ console.warn('[GameBlockSelection] 获取新增小球价格失败:', error);
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ 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) {
|
|
|
+ console.warn('[GameBlockSelection] 获取刷新方块价格失败:', error);
|
|
|
+ }
|
|
|
+ return this.DEFAULT_REFRESH_BASE_PRICE; // 默认价格
|
|
|
+ }
|
|
|
|
|
|
private session: LevelSessionManager = null;
|
|
|
private ballController: BallController = null;
|
|
|
@@ -134,6 +189,7 @@ export class GameBlockSelection extends Component {
|
|
|
private initializeComponent() {
|
|
|
// 获取管理器实例
|
|
|
this.session = LevelSessionManager.inst;
|
|
|
+
|
|
|
// 获取BallController
|
|
|
if (this.ballControllerNode) {
|
|
|
this.ballController = this.ballControllerNode.getComponent(BallController);
|
|
|
@@ -176,6 +232,9 @@ export class GameBlockSelection extends Component {
|
|
|
// 设置事件监听器
|
|
|
this.setupEventListeners();
|
|
|
|
|
|
+ // 更新价格显示
|
|
|
+ this.updatePriceDisplay();
|
|
|
+
|
|
|
// 标记为已初始化
|
|
|
this.isInitialized = true;
|
|
|
|
|
|
@@ -276,8 +335,9 @@ export class GameBlockSelection extends Component {
|
|
|
private onAddBallClicked() {
|
|
|
// 播放UI点击音效
|
|
|
Audio.playUISound('data/弹球音效/ui play');
|
|
|
- // 应用便宜技能效果计算实际费用
|
|
|
- const actualCost = this.getActualCost(this.ADD_BALL_COST);
|
|
|
+ // 从UI节点获取价格并应用便宜技能效果计算实际费用
|
|
|
+ const baseCost = this.getAddBallCost();
|
|
|
+ const actualCost = this.getActualCost(baseCost);
|
|
|
|
|
|
if (!this.canSpendCoins(actualCost)) {
|
|
|
this.showInsufficientCoinsUI();
|
|
|
@@ -288,6 +348,9 @@ export class GameBlockSelection extends Component {
|
|
|
if (this.session.spendCoins(actualCost)) {
|
|
|
this.updateCoinDisplay();
|
|
|
|
|
|
+ // 更新价格配置(增加购买次数和价格)
|
|
|
+ this.updateAddBallPrice();
|
|
|
+
|
|
|
// 通过事件系统创建新的小球
|
|
|
const eventBus = EventBus.getInstance();
|
|
|
eventBus.emit(GameEvents.BALL_CREATE_ADDITIONAL);
|
|
|
@@ -299,19 +362,30 @@ export class GameBlockSelection extends Component {
|
|
|
private onAddCoinClicked() {
|
|
|
// 播放UI点击音效
|
|
|
Audio.playUISound('data/弹球音效/ui play');
|
|
|
- // 免费增加金币(模拟看广告获得奖励)
|
|
|
- const coinsToAdd = 80; // 免费获得的金币数量
|
|
|
- this.session.addCoins(coinsToAdd);
|
|
|
- // 更新显示
|
|
|
- this.updateCoinDisplay();
|
|
|
+
|
|
|
+ // 显示激励视频广告
|
|
|
+ AdManager.getInstance().showRewardedVideoAd(
|
|
|
+ () => {
|
|
|
+ // 广告观看完成,增加金币
|
|
|
+ const coinsToAdd = 80; // 广告奖励的金币数量
|
|
|
+ this.session.addCoins(coinsToAdd);
|
|
|
+ // 更新显示
|
|
|
+ this.updateCoinDisplay();
|
|
|
+ },
|
|
|
+ (error) => {
|
|
|
+ console.error('[GameBlockSelection] 广告显示失败:', error);
|
|
|
+ // 广告失败时不给予奖励
|
|
|
+ }
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
// 刷新方块按钮点击
|
|
|
private onRefreshClicked() {
|
|
|
// 播放UI点击音效
|
|
|
Audio.playUISound('data/弹球音效/ui play');
|
|
|
- // 应用便宜技能效果计算实际费用
|
|
|
- const actualCost = this.getActualCost(this.REFRESH_COST);
|
|
|
+ // 从UI节点获取价格并应用便宜技能效果计算实际费用
|
|
|
+ const baseCost = this.getRefreshCost();
|
|
|
+ const actualCost = this.getActualCost(baseCost);
|
|
|
|
|
|
if (!this.canSpendCoins(actualCost)) {
|
|
|
this.showInsufficientCoinsUI();
|
|
|
@@ -323,6 +397,9 @@ export class GameBlockSelection extends Component {
|
|
|
// 成功扣除金币
|
|
|
this.updateCoinDisplay();
|
|
|
|
|
|
+ // 更新价格配置(增加购买次数和价格)
|
|
|
+ this.updateRefreshPrice();
|
|
|
+
|
|
|
// 刷新方块
|
|
|
if (this.blockManager) {
|
|
|
console.log('[GameBlockSelection] 开始刷新方块流程');
|
|
|
@@ -1178,4 +1255,114 @@ export class GameBlockSelection extends Component {
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+ // === 价格配置管理方法 ===
|
|
|
+
|
|
|
+ // 获取价格配置数据(如果装饰器配置不存在则返回默认值)
|
|
|
+ private getPriceConfigData(): any {
|
|
|
+ if (this.ballPriceConfig && this.ballPriceConfig.json) {
|
|
|
+ return this.ballPriceConfig.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() {
|
|
|
+ // 更新新增小球价格显示
|
|
|
+ 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 (label) {
|
|
|
+ label.string = this.getRefreshCost().toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存价格配置(装饰器配置是只读的,这里只是打印日志用于调试)
|
|
|
+ private saveBallPriceConfig() {
|
|
|
+ const configData = this.getPriceConfigData();
|
|
|
+ // 装饰器预加载的配置是只读的,无法直接修改
|
|
|
+ // 在实际项目中,价格变化应该保存到本地存储或服务器
|
|
|
+ console.log('[GameBlockSelection] 价格配置已更新:', JSON.stringify(configData, null, 2));
|
|
|
+ }
|
|
|
}
|