Browse Source

免费次数

woso_javan 1 month ago
parent
commit
c80cc1ed57

+ 0 - 1
assets/module_aliens/RoosterAliens.ts

@@ -105,7 +105,6 @@ export class RoosterAliens extends Component {
         AliensGlobalInstance.instance.homeUI.active = false;
         AliensGlobalInstance.instance.battleUI.active = true;
         UserManager.instance.reducePower(1);
-        EventDispatcher.instance.emit(GameEvent.EVENT_REFRESH_PLAYER_INFO); //进入游戏
     }
 
     private testShoot(): void {

+ 61 - 0
assets/module_aliens/Script/BattleUI.ts

@@ -0,0 +1,61 @@
+import { _decorator, Component, Label, Node } from 'cc';
+import { UserManager } from './Manager/UserMgr';
+import { GameUtil } from './GameUtil';
+import { tgxUIMgr } from '../../core_tgx/tgx';
+import { UI_BattleGambit } from '../../scripts/UIDef';
+import { EventDispatcher } from '../../core_tgx/easy_ui_framework/EventDispatcher';
+import { GameEvent } from './Enum/GameEvent';
+const { ccclass, property } = _decorator;
+
+@ccclass('BattleUI')
+export class BattleUI extends Component {
+
+    @property(Node)
+    public renderAd: Node = null; 
+    @property(Label)
+    public lbRenderFreeCount: Label = null;
+
+    @property(Node)
+    public radarAd: Node = null; 
+    @property(Label)
+    public lbRadarFreeCount: Label = null;
+
+    protected onLoad(): void {
+        this.registerListener();
+    }
+
+    protected onDestroy(): void {
+        this.unregisterListener();
+    }
+
+    start() {
+        this.updateBtnsCountUI();
+    }
+
+    private registerListener() {
+        EventDispatcher.instance.on(GameEvent.EVENT_REFRESH_PLAYER_INFO,this.updateBtnsCountUI,this);
+    }
+
+    private updateBtnsCountUI(){
+        const {radarFreeCount,freeScreenShotCount} = UserManager.instance.userModel;
+        this.lbRenderFreeCount.string = `${freeScreenShotCount}`;
+        this.lbRadarFreeCount.string = `${radarFreeCount}`;
+
+        this.renderAd.active = false; //默认隐藏
+        this.radarAd.active = false; //默认隐藏
+
+        if(radarFreeCount <= 0){
+            this.lbRadarFreeCount.string = '';
+            this.radarAd.active = true; 
+        }
+        
+        if(freeScreenShotCount <= 0){
+            this.lbRenderFreeCount.string = '';
+            this.renderAd.active = true;
+        }
+    }
+
+    private unregisterListener() {
+        EventDispatcher.instance.off(GameEvent.EVENT_REFRESH_PLAYER_INFO,this.updateBtnsCountUI,this); 
+    }
+}

+ 9 - 0
assets/module_aliens/Script/BattleUI.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "4.0.23",
+  "importer": "typescript",
+  "imported": true,
+  "uuid": "d572a505-cb7b-4b1f-b4b1-049947a7f5f1",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 1 - 1
assets/module_aliens/Script/Components/RadarComponent.ts

@@ -16,7 +16,7 @@ export class RadarComponent extends Component {
     protected onLoad(): void {
         this.registerEvent();
     }
-    
+
     private registerEvent(){
         EventDispatcher.instance.on(GameEvent.EVENT_CAMERA_SCREENSHOT_RADAR,this.onRadar,this);
         EventDispatcher.instance.on(GameEvent.EVENT_CAMERA_SHOOT_ENEMY,this.cancelRadar,this);

+ 55 - 0
assets/module_aliens/Script/Manager/UserMgr.ts

@@ -1,5 +1,7 @@
 import { Node, Prefab, _decorator, assetManager, find, instantiate, sys } from 'cc';
 import { UserModel } from '../Model/UserModel';
+import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
+import { GameEvent } from '../Enum/GameEvent';
 const { ccclass, property } = _decorator;
 
 @ccclass('UserManager')
@@ -24,6 +26,7 @@ export class UserManager {
      */
     public addPower(value: number): number {
         this.userModel.powerCurrent = Math.min(this.userModel.powerCurrent + value, this.userModel.powerMax);
+        EventDispatcher.instance.emit(GameEvent.EVENT_REFRESH_PLAYER_INFO);
         return this.userModel.powerCurrent;
     }
 
@@ -35,8 +38,60 @@ export class UserManager {
     public reducePower(value: number): boolean {
         if (this.userModel.powerCurrent >= value) {
             this.userModel.powerCurrent -= value;
+            EventDispatcher.instance.emit(GameEvent.EVENT_REFRESH_PLAYER_INFO); 
             return true;
         }
         return false;
     }
+
+    /**
+     * 增加雷达免费次数
+     * @param value 增加的数量
+     * @returns 增加后的次数
+     */
+    public addRadarFreeCount(value: number): number {
+        this.userModel.radarFreeCount += value;
+        EventDispatcher.instance.emit(GameEvent.EVENT_REFRESH_PLAYER_INFO); 
+        return this.userModel.radarFreeCount;
+    }
+
+    /**
+     * 减少雷达免费次数
+     * @param value 减少的数量
+     * @returns 是否成功减少
+     */
+    public reduceRadarFreeCount(value: number): boolean {
+        if (this.userModel.radarFreeCount >= value) {
+            this.userModel.radarFreeCount -= value;
+            EventDispatcher.instance.emit(GameEvent.EVENT_REFRESH_PLAYER_INFO); 
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * 增加侦探免费次数
+     * @param value 增加的数量
+     * @returns 增加后的次数
+     */
+    public addFreeScreenShotCount(value: number): number {
+        this.userModel.freeScreenShotCount += value;
+        EventDispatcher.instance.emit(GameEvent.EVENT_REFRESH_PLAYER_INFO); 
+        return this.userModel.freeScreenShotCount;
+    }
+
+    /**
+     * 减少侦探免费次数
+     * @param value 减少的数量
+     * @returns 是否成功减少
+     */
+    public reduceFreeScreenShotCount(value: number): boolean {
+        if (this.userModel.freeScreenShotCount >= value) {
+            this.userModel.freeScreenShotCount -= value;
+            EventDispatcher.instance.emit(GameEvent.EVENT_REFRESH_PLAYER_INFO); 
+            return true;
+        }
+        return false;
+    }
+
 }

+ 9 - 0
assets/module_aliens/Script/Model/UserModel.ts

@@ -8,6 +8,12 @@ export class UserModel {
     //当前体力
     powerCurrent: number = 0;
 
+    //情报免费次数
+    radarFreeCount: number = 0;
+
+    //侦探免费次数
+    freeScreenShotCount: number = 0;
+
     constructor() {
     }
 
@@ -16,5 +22,8 @@ export class UserModel {
        this.powerRecoverTime = 3000;
        this.powerMax = 5;
        this.powerCurrent = 1;
+
+       this.radarFreeCount = 0;
+       this.freeScreenShotCount = 0;
     }
 }

File diff suppressed because it is too large
+ 400 - 121
assets/module_aliens/rooster_aliens.scene


Some files were not shown because too many files changed in this diff