|
|
@@ -100,8 +100,12 @@ export class GameBlockSelection extends Component {
|
|
|
})
|
|
|
public refreshBlockPriceNode: Node = null;
|
|
|
|
|
|
- // 常量定义
|
|
|
- private readonly ADD_COIN_AMOUNT = 80;
|
|
|
+ // 增加金币奖励显示节点 - 对应addCoinReward
|
|
|
+ @property({
|
|
|
+ type: Node,
|
|
|
+ tooltip: '拖拽Canvas/GameLevelUI/BlockSelectionUI/diban/ann002/db01/addCoin节点到这里'
|
|
|
+ })
|
|
|
+ public addCoinRewardNode: Node = null;
|
|
|
|
|
|
// 价格配置默认值
|
|
|
private readonly DEFAULT_ADD_BALL_BASE_PRICE = 80;
|
|
|
@@ -110,6 +114,52 @@ export class GameBlockSelection extends Component {
|
|
|
private readonly DEFAULT_REFRESH_BASE_PRICE = 5;
|
|
|
private readonly DEFAULT_REFRESH_INCREMENT = 2;
|
|
|
private readonly DEFAULT_REFRESH_MAX_PRICE = 50;
|
|
|
+ private readonly DEFAULT_ADD_COIN_BASE_REWARD = 60;
|
|
|
+ private readonly DEFAULT_ADD_COIN_INCREMENT = 10;
|
|
|
+ private readonly DEFAULT_ADD_COIN_MAX_REWARD = 200;
|
|
|
+
|
|
|
+ // 获取增加金币奖励数量
|
|
|
+ private getAddCoinReward(): number {
|
|
|
+ // 优先从JSON配置中获取奖励数量
|
|
|
+ if (this.ballPriceConfigData && this.ballPriceConfigData.addCoinReward) {
|
|
|
+ const config = this.ballPriceConfigData.addCoinReward;
|
|
|
+ const baseReward = config.initialPrice || this.DEFAULT_ADD_COIN_BASE_REWARD;
|
|
|
+ const increment = config.priceIncrement || this.DEFAULT_ADD_COIN_INCREMENT;
|
|
|
+ const maxReward = config.maxPrice || this.DEFAULT_ADD_COIN_MAX_REWARD;
|
|
|
+
|
|
|
+ // 获取当前使用次数
|
|
|
+ const session = this.session || LevelSessionManager.inst;
|
|
|
+ const usageCount = session ? session.getAddCoinUsageCount() : 0;
|
|
|
+
|
|
|
+ // 计算当前奖励数量
|
|
|
+ const currentReward = Math.min(baseReward + (usageCount * increment), maxReward);
|
|
|
+ return currentReward;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 其次从装饰器绑定的节点获取奖励数量
|
|
|
+ try {
|
|
|
+ if (this.addCoinRewardNode) {
|
|
|
+ const label = this.addCoinRewardNode.getComponent(Label);
|
|
|
+ if (label) {
|
|
|
+ const reward = parseInt(label.string);
|
|
|
+ return isNaN(reward) ? this.DEFAULT_ADD_COIN_BASE_REWARD : reward;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 回退到find方法(兼容性)
|
|
|
+ const rewardNode = find('Canvas/GameLevelUI/BlockSelectionUI/diban/ann002/db01/addCoin');
|
|
|
+ if (rewardNode) {
|
|
|
+ const label = rewardNode.getComponent(Label);
|
|
|
+ if (label) {
|
|
|
+ const reward = parseInt(label.string);
|
|
|
+ return isNaN(reward) ? this.DEFAULT_ADD_COIN_BASE_REWARD : reward;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.warn('[GameBlockSelection] 获取增加金币奖励失败:', error);
|
|
|
+ }
|
|
|
+ return this.DEFAULT_ADD_COIN_BASE_REWARD; // 默认奖励
|
|
|
+ }
|
|
|
|
|
|
// 价格获取方法
|
|
|
private getAddBallCost(): number {
|
|
|
@@ -281,6 +331,9 @@ export class GameBlockSelection extends Component {
|
|
|
// 更新价格显示
|
|
|
this.updatePriceDisplay();
|
|
|
|
|
|
+ // 更新奖励显示
|
|
|
+ this.updateRewardDisplay();
|
|
|
+
|
|
|
// 标记为已初始化
|
|
|
this.isInitialized = true;
|
|
|
|
|
|
@@ -392,6 +445,9 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
// 扣除金币
|
|
|
if (this.session.spendCoins(actualCost)) {
|
|
|
+ // 增加使用次数
|
|
|
+ this.session.incrementAddBallUsageCount();
|
|
|
+
|
|
|
this.updateCoinDisplay();
|
|
|
|
|
|
// 更新价格配置(增加购买次数和价格)
|
|
|
@@ -413,10 +469,15 @@ export class GameBlockSelection extends Component {
|
|
|
AdManager.getInstance().showRewardedVideoAd(
|
|
|
() => {
|
|
|
// 广告观看完成,增加金币
|
|
|
- const coinsToAdd = 80; // 广告奖励的金币数量
|
|
|
- this.session.addCoins(coinsToAdd);
|
|
|
+ const coinsToAdd = this.getAddCoinReward(); // 从配置中获取广告奖励的金币数量
|
|
|
+ this.session.addCoins(coinsToAdd);
|
|
|
+
|
|
|
+ // 增加使用次数
|
|
|
+ this.session.incrementAddCoinUsageCount();
|
|
|
+
|
|
|
// 更新显示
|
|
|
this.updateCoinDisplay();
|
|
|
+ this.updateRewardDisplay();
|
|
|
},
|
|
|
(error) => {
|
|
|
console.error('[GameBlockSelection] 广告显示失败:', error);
|
|
|
@@ -440,6 +501,9 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
// 扣除金币
|
|
|
if (this.session.spendCoins(actualCost)) {
|
|
|
+ // 增加使用次数
|
|
|
+ this.session.incrementRefreshUsageCount();
|
|
|
+
|
|
|
// 成功扣除金币
|
|
|
this.updateCoinDisplay();
|
|
|
|
|
|
@@ -1423,6 +1487,30 @@ export class GameBlockSelection extends Component {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 更新奖励显示
|
|
|
+ private updateRewardDisplay() {
|
|
|
+ // 更新增加金币奖励显示 - 使用装饰器绑定的节点
|
|
|
+ if (this.addCoinRewardNode) {
|
|
|
+ const label = this.addCoinRewardNode.getComponent(Label);
|
|
|
+ if (label) {
|
|
|
+ label.string = this.getAddCoinReward().toString();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 回退到find方法(兼容性)
|
|
|
+ try {
|
|
|
+ const rewardNode = find('Canvas/GameLevelUI/BlockSelectionUI/diban/ann002/db01/addCoin');
|
|
|
+ if (rewardNode) {
|
|
|
+ const label = rewardNode.getComponent(Label);
|
|
|
+ if (label) {
|
|
|
+ label.string = this.getAddCoinReward().toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.warn('[GameBlockSelection] 更新增加金币奖励显示失败:', error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 保存价格配置(装饰器配置是只读的,这里只是打印日志用于调试)
|
|
|
private saveBallPriceConfig() {
|
|
|
const configData = this.getPriceConfigData();
|