woso_javan 2 miesięcy temu
rodzic
commit
50f0153747

+ 49 - 2
assets/module_storm_sunder/Script/Component/ButtonComponent.ts

@@ -3,7 +3,6 @@ import { GameEvent } from '../Enum/GameEvent';
 import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
 import { GlobalConfig } from 'db://assets/start/Config/GlobalConfig';
 import { AdvertMgr } from 'db://assets/core_tgx/base/ad/AdvertMgr';
-import { tgxUIAlert } from 'db://assets/core_tgx/tgx';
 import { StormSunderAudioMgr } from '../Manager/StormSunderAudioMgr';
 import { AttributeBonusMgr, BonusType } from '../Manager/AttributeBonusMgr';
 const { ccclass, property } = _decorator;
@@ -22,6 +21,7 @@ export class ButtonComponent extends Component {
         this.updateBtView(BonusType.ATTACK);
         this.updateBtView(BonusType.SPEED);
         this.updateBtView(BonusType.EXP);
+        this.onUpdateBtnsStatus();
     }
 
     private addUIEvent(): void {
@@ -31,8 +31,40 @@ export class ButtonComponent extends Component {
     }
 
     private onClickHandler(type: BonusType): void {
-        console.log("onClickHandler", type);
         StormSunderAudioMgr.playOneShot(StormSunderAudioMgr.getMusicIdName(2), 1.0);
+        const { userModel } = AttributeBonusMgr.inst;
+        const bonus = userModel.bonusData[type];
+
+        // 检查金额是否足够
+        if (!AttributeBonusMgr.inst.checkMoneyEnough(bonus.upgradeCost)) {
+            console.log("金额不足");
+            //DOTO 看广告
+            this.updateBtStatus(type);
+            return;
+        }
+
+        // 扣除金额
+        if (!AttributeBonusMgr.inst.consumeMoney(bonus.upgradeCost)) {
+            return;
+        }
+
+        // 升级逻辑
+        bonus.level++;
+        // 更新升级消耗
+        bonus.upgradeCost += AttributeBonusMgr.inst.getUpgradeCost(type);
+        AttributeBonusMgr.inst.updateBonus(type);
+
+        // 更新按钮状态
+        this.updateBtView(type);
+        this.onUpdateBtnsStatus();
+
+        EventDispatcher.instance.emit(GameEvent.EVENT_UPDATE_USER_MONEY);
+    }
+
+    private onUpdateBtnsStatus(): void {
+        this.updateBtStatus(BonusType.ATTACK);
+        this.updateBtStatus(BonusType.SPEED);
+        this.updateBtStatus(BonusType.EXP);
     }
 
     private updateBtView(type: BonusType, max?: boolean): void {
@@ -56,6 +88,21 @@ export class ButtonComponent extends Component {
         }
     }
 
+    private updateBtStatus(type: BonusType): void {
+        const { userModel } = AttributeBonusMgr.inst;
+        const bonus = userModel.bonusData[type];
+        const buttonNode = this.getButtonNodeByType(type);
+        const usedMoney = buttonNode.getChildByName('UsedMoney')!;
+        const usedAd = buttonNode.getChildByName('UsedAd')!;
+
+        // 检查金额是否足够
+        const canAfford = AttributeBonusMgr.inst.checkMoneyEnough(bonus.upgradeCost);
+
+        // 金额不够显示广告图标,够则显示金额
+        usedMoney.active = canAfford;
+        usedAd.active = !canAfford;
+    }
+
     private getButtonNodeByType(type: BonusType): Node {
         return {
             [BonusType.ATTACK]: this.btnAttack.node,

+ 3 - 0
assets/module_storm_sunder/Script/Enum/GameEvent.ts

@@ -4,6 +4,9 @@ export class GameEvent {
     /** 游戏开始*/
     static readonly EVENT_GAME_START = 'EVENT_GAME_START';
 
+    /* 更新用户金额*/
+    static readonly EVENT_UPDATE_USER_MONEY = 'EVENT_UPDATE_USER_MONEY';
+
     /** 龙卷风升级*/
     static readonly EVENT_STORM_LEVEL_UP = 'EVENT_STORM_LEVEL_UP';
 

+ 35 - 0
assets/module_storm_sunder/Script/HomeUI.ts

@@ -0,0 +1,35 @@
+import { Button, Component, Label, Node, NodeEventType, _decorator, find } from 'cc';
+import { AttributeBonusMgr } from './Manager/AttributeBonusMgr';
+import { EventDispatcher } from '../../core_tgx/easy_ui_framework/EventDispatcher';
+import { GameEvent } from './Enum/GameEvent';
+
+const { ccclass, property } = _decorator;
+
+/**
+ *HomeUI面板
+ */
+@ccclass('HomeUI')
+export class HomeUI extends Component {
+
+    lbUserMoney: Label = null;
+    lbUserName: Label = null;
+
+    protected onLoad(): void {
+        this.lbUserMoney = this.node.getChildByName("TopLeft").getChildByName("LbMoney").getComponent(Label)!;
+        this.rigisterEvent();
+    }
+
+    protected start(): void {
+        this.upadteUserInfo();
+    }
+
+    private rigisterEvent() {
+        EventDispatcher.instance.on(GameEvent.EVENT_UPDATE_USER_MONEY, this.upadteUserInfo, this);
+    }
+
+    private upadteUserInfo() {
+        const { money } = AttributeBonusMgr.inst.userModel;
+        this.lbUserMoney.string = money.toString();
+    }
+
+}

+ 9 - 0
assets/module_storm_sunder/Script/HomeUI.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "4.0.23",
+  "importer": "typescript",
+  "imported": true,
+  "uuid": "b0194d0d-cd3d-4dff-8770-31bd3cc378f5",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 47 - 0
assets/module_storm_sunder/Script/Manager/AttributeBonusMgr.ts

@@ -20,6 +20,53 @@ export class AttributeBonusMgr {
         this.developConfig = new DevelopConfigModel();
         this.userModel.initialize();
     }
+
+    /**
+     * 检查用户金额是否足够
+     * @param cost 需要消耗的金额
+     * @returns boolean
+     */
+    public checkMoneyEnough(cost: number): boolean {
+        const userMoney = this.userModel.money;
+        return userMoney >= cost;
+    }
+
+    /**
+     * 扣除用户金额
+     * @param cost 需要扣除的金额
+     * @returns boolean 扣除是否成功
+     */
+    public consumeMoney(cost: number): boolean {
+        if (!this.checkMoneyEnough(cost)) {
+            return false;
+        }
+
+        this.userModel.money -= cost;
+        return true;
+    }
+
+    /**
+     * 更新对应类型的加成数据
+     * @param type 加成类型
+     */
+    public updateBonus(type: BonusType): void {
+        const bonus = this.userModel.bonusData[type];
+        if (!bonus) return;
+
+        // 更新等级和升级消耗
+        this.userModel.bonusData[type] = {
+            ...bonus,
+            level: bonus.level,
+            upgradeCost: bonus.upgradeCost
+        };
+    }
+
+    /** 获取配置升级消耗增加金额*/
+    public getUpgradeCost(type: BonusType): number {
+        const config = this.developConfig.getConfigById(type);
+        if (!config) return 0;
+        return config.money_growth
+    }
 }
 
 //属性加成类型

+ 76 - 61
assets/module_storm_sunder/rooster_stormsunder.scene

@@ -29,7 +29,7 @@
     "_active": true,
     "_components": [],
     "_prefab": {
-      "__id__": 177
+      "__id__": 178
     },
     "_lpos": {
       "__type__": "cc.Vec3",
@@ -60,7 +60,7 @@
     },
     "autoReleaseAssets": false,
     "_globals": {
-      "__id__": 178
+      "__id__": 179
     },
     "_id": "be14c61f-22d8-4bb9-b444-ad9f29740469"
   },
@@ -1122,17 +1122,14 @@
         "__id__": 68
       },
       {
-        "__id__": 149
+        "__id__": 150
       },
       {
-        "__id__": 171
+        "__id__": 172
       }
     ],
     "_active": true,
     "_components": [
-      {
-        "__id__": 173
-      },
       {
         "__id__": 174
       },
@@ -1141,6 +1138,9 @@
       },
       {
         "__id__": 176
+      },
+      {
+        "__id__": 177
       }
     ],
     "_prefab": null,
@@ -1293,6 +1293,9 @@
       },
       {
         "__id__": 148
+      },
+      {
+        "__id__": 149
       }
     ],
     "_prefab": null,
@@ -4571,6 +4574,18 @@
     "_lockFlags": 0,
     "_id": "57BgqIz2ZNuYVEyJq1nSWl"
   },
+  {
+    "__type__": "b01940NzT1N/4dwMb08w3j1",
+    "_name": "",
+    "_objFlags": 0,
+    "__editorExtras__": {},
+    "node": {
+      "__id__": 68
+    },
+    "_enabled": true,
+    "__prefab": null,
+    "_id": "92RzEuTW5LhrB6ATxhqyuA"
+  },
   {
     "__type__": "cc.Node",
     "_name": "BattleUI",
@@ -4581,25 +4596,25 @@
     },
     "_children": [
       {
-        "__id__": 150
+        "__id__": 151
       },
       {
-        "__id__": 153
+        "__id__": 154
       },
       {
-        "__id__": 163
+        "__id__": 164
       },
       {
-        "__id__": 166
+        "__id__": 167
       }
     ],
     "_active": false,
     "_components": [
       {
-        "__id__": 169
+        "__id__": 170
       },
       {
-        "__id__": 170
+        "__id__": 171
       }
     ],
     "_prefab": null,
@@ -4638,16 +4653,16 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
-      "__id__": 149
+      "__id__": 150
     },
     "_children": [],
     "_active": true,
     "_components": [
       {
-        "__id__": 151
+        "__id__": 152
       },
       {
-        "__id__": 152
+        "__id__": 153
       }
     ],
     "_prefab": null,
@@ -4686,7 +4701,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 150
+      "__id__": 151
     },
     "_enabled": true,
     "__prefab": null,
@@ -4708,7 +4723,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 150
+      "__id__": 151
     },
     "_enabled": true,
     "__prefab": null,
@@ -4773,23 +4788,23 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
-      "__id__": 149
+      "__id__": 150
     },
     "_children": [
       {
-        "__id__": 154
+        "__id__": 155
       }
     ],
     "_active": true,
     "_components": [
-      {
-        "__id__": 160
-      },
       {
         "__id__": 161
       },
       {
         "__id__": 162
+      },
+      {
+        "__id__": 163
       }
     ],
     "_prefab": null,
@@ -4828,20 +4843,20 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
-      "__id__": 153
+      "__id__": 154
     },
     "_children": [
       {
-        "__id__": 155
+        "__id__": 156
       }
     ],
     "_active": true,
     "_components": [
       {
-        "__id__": 158
+        "__id__": 159
       },
       {
-        "__id__": 159
+        "__id__": 160
       }
     ],
     "_prefab": null,
@@ -4880,16 +4895,16 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
-      "__id__": 154
+      "__id__": 155
     },
     "_children": [],
     "_active": true,
     "_components": [
       {
-        "__id__": 156
+        "__id__": 157
       },
       {
-        "__id__": 157
+        "__id__": 158
       }
     ],
     "_prefab": null,
@@ -4928,7 +4943,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 155
+      "__id__": 156
     },
     "_enabled": true,
     "__prefab": null,
@@ -4950,7 +4965,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 155
+      "__id__": 156
     },
     "_enabled": true,
     "__prefab": null,
@@ -4989,7 +5004,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 154
+      "__id__": 155
     },
     "_enabled": true,
     "__prefab": null,
@@ -5011,7 +5026,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 154
+      "__id__": 155
     },
     "_enabled": true,
     "__prefab": null,
@@ -5050,7 +5065,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 153
+      "__id__": 154
     },
     "_enabled": true,
     "__prefab": null,
@@ -5072,15 +5087,15 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 153
+      "__id__": 154
     },
     "_enabled": true,
     "__prefab": null,
     "joystickPoint": {
-      "__id__": 157
+      "__id__": 158
     },
     "joyStickBg": {
-      "__id__": 159
+      "__id__": 160
     },
     "radius": 130,
     "_id": "70CN/qqbZNT4fFkA/n48Bb"
@@ -5091,7 +5106,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 153
+      "__id__": 154
     },
     "_enabled": true,
     "__prefab": null,
@@ -5121,16 +5136,16 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
-      "__id__": 149
+      "__id__": 150
     },
     "_children": [],
     "_active": true,
     "_components": [
       {
-        "__id__": 164
+        "__id__": 165
       },
       {
-        "__id__": 165
+        "__id__": 166
       }
     ],
     "_prefab": null,
@@ -5169,7 +5184,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 163
+      "__id__": 164
     },
     "_enabled": true,
     "__prefab": null,
@@ -5191,7 +5206,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 163
+      "__id__": 164
     },
     "_enabled": true,
     "__prefab": null,
@@ -5221,16 +5236,16 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
-      "__id__": 149
+      "__id__": 150
     },
     "_children": [],
     "_active": true,
     "_components": [
       {
-        "__id__": 167
+        "__id__": 168
       },
       {
-        "__id__": 168
+        "__id__": 169
       }
     ],
     "_prefab": null,
@@ -5269,7 +5284,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 166
+      "__id__": 167
     },
     "_enabled": true,
     "__prefab": null,
@@ -5291,7 +5306,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 166
+      "__id__": 167
     },
     "_enabled": true,
     "__prefab": null,
@@ -5321,7 +5336,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 149
+      "__id__": 150
     },
     "_enabled": true,
     "__prefab": null,
@@ -5343,7 +5358,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 149
+      "__id__": 150
     },
     "_enabled": true,
     "__prefab": null,
@@ -5379,7 +5394,7 @@
     "_active": true,
     "_components": [
       {
-        "__id__": 172
+        "__id__": 173
       }
     ],
     "_prefab": null,
@@ -5418,7 +5433,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 171
+      "__id__": 172
     },
     "_enabled": true,
     "__prefab": null,
@@ -5528,28 +5543,28 @@
   {
     "__type__": "cc.SceneGlobals",
     "ambient": {
-      "__id__": 179
+      "__id__": 180
     },
     "shadows": {
-      "__id__": 180
+      "__id__": 181
     },
     "_skybox": {
-      "__id__": 181
+      "__id__": 182
     },
     "fog": {
-      "__id__": 182
+      "__id__": 183
     },
     "octree": {
-      "__id__": 183
+      "__id__": 184
     },
     "skin": {
-      "__id__": 184
+      "__id__": 185
     },
     "lightProbeInfo": {
-      "__id__": 185
+      "__id__": 186
     },
     "postSettings": {
-      "__id__": 186
+      "__id__": 187
     },
     "bakedWithStationaryMainLight": false,
     "bakedWithHighpLightmap": false

+ 9 - 0
assets/scripts/game/manager.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.2.0",
+  "importer": "directory",
+  "imported": true,
+  "uuid": "dd593236-eb09-40e2-8e12-6b47dc9b528d",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}