Browse Source

小球价格优化

181404010226 2 months ago
parent
commit
c4b1aa4ad1

+ 3 - 2
assets/Scenes/GameLevel.scene

@@ -31016,7 +31016,7 @@
     "_prefab": null,
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 11.744140624999998,
+      "x": 11.744140625000002,
       "y": 0,
       "z": 0
     },
@@ -31143,7 +31143,7 @@
     "_right": 0,
     "_top": 4.062999999999998,
     "_bottom": 0.37195384615384625,
-    "_horizontalCenter": 0.06382685122282608,
+    "_horizontalCenter": 0.0638268512228261,
     "_verticalCenter": 0,
     "_isAbsLeft": true,
     "_isAbsRight": true,
@@ -35824,6 +35824,7 @@
     "refreshBlockPriceNode": {
       "__id__": 1112
     },
+    "addCoinRewardNode": null,
     "debugDrawSnapRange": true,
     "_id": "ealiXZigZIgrXLo2NL22Ns"
   },

+ 6 - 0
assets/data/ball_price_config.json

@@ -10,5 +10,11 @@
     "priceIncrement": 2,
     "maxPrice": 45,
     "description": "刷新方块的价格配置"
+  },
+  "addCoinReward": {
+    "initialPrice": 60,
+    "priceIncrement": 10,
+    "maxPrice": 200,
+    "description": "观看广告获得的金币奖励配置"
   }
 }

+ 16 - 0
assets/data/excel/ball_price_config_manager.py

@@ -189,6 +189,22 @@ class BallPriceConfigManager:
                 config['refreshBlockPricing'] = refresh_block_config
                 print(f"解析刷新方块配置: {refresh_block_config}")
             
+            # 解析增加金币奖励配置
+            add_coin_reward_config = {}
+            if '观看广告奖励初始价格' in config_map:
+                add_coin_reward_config['initialPrice'] = int(config_map['观看广告奖励初始价格'])
+            if '观看广告奖励价格增量' in config_map:
+                add_coin_reward_config['priceIncrement'] = int(config_map['观看广告奖励价格增量'])
+            if '观看广告奖励最大价格' in config_map:
+                add_coin_reward_config['maxPrice'] = int(config_map['观看广告奖励最大价格'])
+            
+            # 添加描述
+            add_coin_reward_config['description'] = "观看广告获得的金币奖励配置"
+            
+            if add_coin_reward_config and 'initialPrice' in add_coin_reward_config:
+                config['addCoinReward'] = add_coin_reward_config
+                print(f"解析增加金币奖励配置: {add_coin_reward_config}")
+            
             # 解析其他配置项(如果需要)
             other_config = {}
             for key, value in config_map.items():

BIN
assets/data/excel/小球价格配置/小球价格配置表.xlsx


+ 92 - 4
assets/scripts/CombatSystem/BlockSelection/GameBlockSelection.ts

@@ -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();

+ 16 - 1
assets/scripts/Core/LevelSessionManager.ts

@@ -11,6 +11,9 @@ export interface LevelRuntimeData {
   startTime: number;
 
   sessionCoins: number;          // 本局金币(购买方块)
+  addBallUsageCount: number;     // 添加小球使用次数
+  refreshUsageCount: number;     // 刷新方块使用次数
+  addCoinUsageCount: number;     // 观看广告奖励使用次数
 }
 
 export class LevelSessionManager {
@@ -32,7 +35,10 @@ export class LevelSessionManager {
       currentWave: 1,
       //drops: [],
       startTime: Date.now(),
-      sessionCoins: initialCoins
+      sessionCoins: initialCoins,
+      addBallUsageCount: 0,
+      refreshUsageCount: 0,
+      addCoinUsageCount: 0
     };
     console.log(`[LevelSessionManager] 初始化完成,关卡${levelId}初始金币设置为: ${this.data.sessionCoins}`);
   }
@@ -74,4 +80,13 @@ export class LevelSessionManager {
   public addCoins(amt:number){ if(this.data) this.data.sessionCoins += amt; }
   /** 成功返回true */
   public spendCoins(amt:number):boolean{ if(!this.data || amt<=0) return false; if(this.data.sessionCoins<amt) return false; this.data.sessionCoins-=amt; return true; }
+  
+  // ======== 使用次数接口 ========
+  public getAddBallUsageCount(): number { return this.data?.addBallUsageCount ?? 0; }
+  public getRefreshUsageCount(): number { return this.data?.refreshUsageCount ?? 0; }
+  public getAddCoinUsageCount(): number { return this.data?.addCoinUsageCount ?? 0; }
+  
+  public incrementAddBallUsageCount(): void { if(this.data) this.data.addBallUsageCount++; }
+  public incrementRefreshUsageCount(): void { if(this.data) this.data.refreshUsageCount++; }
+  public incrementAddCoinUsageCount(): void { if(this.data) this.data.addCoinUsageCount++; }
 }