薛鸿潇 5 лет назад
Родитель
Сommit
45d3187d37

+ 7 - 6
tower_sanguo/assets/scripts/module/checkpointRedBag/CheckpointRedBagBtn.ts

@@ -1,9 +1,3 @@
-// Learn TypeScript:
-//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
-// Learn Attribute:
-//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
-// Learn life-cycle callbacks:
-//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
 
 import { AUDIO_TYPE } from "../../data/GameDefinition";
 import GameController from "../../GameController";
@@ -24,6 +18,7 @@ export default class CheckpointRedBagBtn extends cc.Component {
         XXEvent.on('event-get-checkpoint-redbag', this.onAddRedBag, this);
         XXEvent.on('event-monster-died', this.onMonsterDied, this);
         XXEvent.on(XXConst.EventNewMissionStart, this.onNewMissionStart, this)// 新的一波开始了
+        XXEvent.on('http-stage-getStageReward', this.onReciveTVRewardCall, this);
     }
 
     start() {
@@ -53,6 +48,12 @@ export default class CheckpointRedBagBtn extends cc.Component {
     /** 点击到通关红包 */
     private onClickChPoRedBag() {
         GameController.audioM.playEffect(AUDIO_TYPE.button);
+        GameController.http.getStageReward();
+    }
+    /** 看视频领取通关红包回调 */
+    private onReciveTVRewardCall(reply) {
+        cc.log(reply)
+        // 处理数据
         CheckpointRedBagModle.onClickCal();
 
         let time = CheckpointRedBagModle.redbag_data.cur_count - this.targetProgress;

+ 0 - 6
tower_sanguo/assets/scripts/module/checkpointRedBag/CheckpointRedBagItem.ts

@@ -1,9 +1,3 @@
-// Learn TypeScript:
-//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
-// Learn Attribute:
-//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
-// Learn life-cycle callbacks:
-//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
 
 import GameController from "../../GameController";
 import MainUI from "../main/MainUI";

+ 39 - 11
tower_sanguo/assets/scripts/module/checkpointRedBag/CheckpointRedBagModle.ts

@@ -86,19 +86,47 @@ export default class CheckpointRedBagModle {
         if (!this.isGetRedBag()) return;
         if (this.redbag_data.cumulative_count >= this.redbag_data.limit_count) return;
         if (this.redbag_data.cur_count >= this.redbag_data.limit_count) return;
+        this.redBag_world_pos = world_pos;
+        // 掉落请求
+        GameController.http.saveStageReward();
+    }
+    /** 红包币世界坐标 */
+    private static redBag_world_pos: cc.Vec2 = null!;
+    /** 掉落请求回调 
+     *  - 服务端回复
+            // "stageRewardNum": Integer, (用户通关红包剩余数量)
+            // "stageRewardRedBag": Integer, (用户当前通关红包币数量)
+            // "stageRewardDrop": Integer, (用户当天红包掉落次数)
+            // "stageRewardLastTime": Long, (用户最后更新通关红包的时间)
+            // "stageRewardVideoTime": Integer (用户通关红包视频次数)
+    */
+    public static saveStageRewardCall(reply) {
+        cc.log('怪物掉落红包币:', reply)
+        let data = reply.data;
+        if (data && data.code === 1) {
+            let data2 = data.data;
+            this.redbag_data.cur_count = data2.stageRewardRedBag;
+            this.redbag_data.cumulative_count = data2.stageRewardDrop;
+            let t_limit_count = data2.stageRewardNum + data2.stageRewardDrop;// 限制次数 = 剩余次数 + 当日累计
+            this.redbag_data.limit_count = t_limit_count;
 
-        this.redbag_data.cumulative_count++;
-        this.cur_is_get = true;
-        // 模拟数据,直接出现
-        let red_bag_path = 'module/checkpointRedBag/btn_chPo_RedBag';
-        XXLoader.loadAssetByType(red_bag_path, cc.Prefab, (asset) => {
-            if (!this.comp_main) this.comp_main = GameController.uiM.getUI(MainUI);
-            let node_red = cc.instantiate(asset);
-            node_red.parent = this.comp_main.node;
-            let node_pos = node_red.parent.convertToNodeSpaceAR(world_pos);
-            node_red.setPosition(node_pos);
-        })
+
+            // this.redbag_data.cumulative_count++;
+            this.cur_is_get = true;
+            // 模拟数据,直接出现
+            let red_bag_path = 'module/checkpointRedBag/btn_chPo_RedBag';
+            XXLoader.loadAssetByType(red_bag_path, cc.Prefab, (asset) => {
+                if (!this.comp_main) this.comp_main = GameController.uiM.getUI(MainUI);
+                let node_red = cc.instantiate(asset);
+                node_red.parent = this.comp_main.node;
+                let node_pos = node_red.parent.convertToNodeSpaceAR(this.redBag_world_pos);
+                node_red.setPosition(node_pos);
+            })
+        } else {
+
+        }
     }
+
     /** 点击通关红包币事件触发 */
     public static onClickCal() {
         if (!this.redbag_data.cur_count) {

+ 6 - 1
tower_sanguo/assets/scripts/module/main/MainUI.ts

@@ -165,7 +165,8 @@ export default class MainUI extends BaseUI {
 
         XXEvent.on("MainUIUpdateQiPaoMarshal", this.updateQiPaoMarshal, this);
         XXEvent.on("open-guide", this.openGuideUI, this);
-        XXEvent.on('http-piggyBox-savePiggyBox', this.onGetPiggyData, this);
+        XXEvent.on('http-piggyBox-savePiggyBox', this.onGetPiggyData, this);// 存钱罐入账
+        XXEvent.on('http-stage-saveStageReward', this.onCheckPointRedBagData, this);// 掉落通关红包
         if (PiggyBankModel.bank_cash_value) {
             GameController.uiM.openUI(PiggyBankUI)
         }
@@ -476,6 +477,10 @@ export default class MainUI extends BaseUI {
     private onGetPiggyData(reply) {
         PiggyBankModel.getRedBagCount(reply);
     }
+    /** 通关获得红包币 */
+    private onCheckPointRedBagData(reply) {
+        CheckpointRedBagModle.saveStageRewardCall(reply)
+    }
 
     onDestroy() {
         XXEvent.off("MainUIUpdateQiPaoMarshal", this.updateQiPaoMarshal, this);

+ 2 - 2
tower_sanguo/assets/scripts/net/HttpCommand.ts

@@ -376,7 +376,7 @@ export default class HttpCommand {
 
         };
         this.sendData(HTTPTYPE.getStageReward, data, (data) => {
-            XXEvent.emit(HTTPTYPE.getStageReward,data)
+            XXEvent.emit('http-stage-getStageReward',data)
         });
     }
 
@@ -388,7 +388,7 @@ export default class HttpCommand {
 
         };
         this.sendData(HTTPTYPE.saveStageReward, data, (data) => {
-            XXEvent.emit(HTTPTYPE.saveStageReward,data)
+            XXEvent.emit('http-stage-saveStageReward',data)
         });
     }