Просмотр исходного кода

调通接口generalExpUp,updateMission

zouyong 5 лет назад
Родитель
Сommit
a7b0681e21

+ 1 - 1
tower_sanguo/assets/MOKA/net/HttpManager.ts

@@ -28,7 +28,7 @@ export default class HttpManager {
                 GameController.errorM.dealError(url + ":" + response.errcode, ERROR_DEAL.POP);
             }
             response = self.checkData(response);
-            callback && callback(response);
+            callback && callback(response,data);
         };
         this.sendRequest(url, 'POST', JSON.stringify(dataN), checkData, false, errorPop, async);
     }

+ 69 - 7
tower_sanguo/assets/scripts/data/GameData.ts

@@ -4,7 +4,7 @@ import CheckpointRedBagModle from "../module/checkpointRedBag/CheckpointRedBagMo
 import FightData from "../module/fight/FightData";
 import TaskModel from "../module/task/TaskModel";
 import turntableModel from "../module/turntable/turntableModel";
-import HttpCommand, { UpdatePlayerProps } from "../net/HttpCommand";
+import HttpCommand, { MsgAddGeneralExp, UpdatePlayerProps } from "../net/HttpCommand";
 import AddItemResponse from "../net/msg/AddItemResponse";
 import BaseMsg from "../net/msg/BaseResponse";
 import GeneralProp from "../net/msg/GeneralProp";
@@ -852,6 +852,68 @@ export default class GameData {
         }
 
     }
+
+    getExpUpGeneral() {
+        //保护等级  INT[(上阵最大等级-兵营等级)/3+兵营等级],向下取整
+        let barracklv = this.player.getProp(PLAYERPROP.BARRACK);
+        let protectLv = Math.floor((this.getGeneralLvMax() - barracklv) / 3 + barracklv);
+        //选择武将
+        let g = this.getAddExpGeneral(protectLv);
+        if (g == null) {
+            return null;
+        }
+        //计算增加经验
+        let exp = 1 / Math.pow(2, g.lv - barracklv) * 100;
+        let lv = g.lv;
+        //未升级 直接加
+        if (g.exp + exp < 100) {
+            exp = g.exp + exp;
+        }
+        else {//升级溢出部分 /2加上
+            exp = (g.exp + exp - 100);
+            lv = g.lv + 1;
+        }
+        return { gui: g.id, exp: exp, lv: lv } as MsgAddGeneralExp;
+    }
+    private getGeneralLvMax() {
+        let lv = 0;
+        for (let i = 0; i < this.player.generals.length; i++) {
+            let ggg = this.player.generals[i];
+            if (ggg == null) {
+                continue;
+            }
+            let g = this.player.generals_bag[ggg.id];
+            if (g && g && g.lv > lv) {
+                lv = g.lv;
+            }
+        }
+        return lv;
+    }
+    private getAddExpGeneral(protectlv: number): GeneralVO {
+        let arr = [];
+        let brr = [];
+        for (let i = 0; i < this.player.generals.length; i++) {
+            let ggg = this.player.generals[i];
+            if (ggg == null) {
+                continue;
+            }
+            let g = this.player.generals_bag[ggg.id];
+            if (g) {
+                if (g.lv < protectlv) {
+                    arr.push(g);
+                }
+                brr.push(g);
+            }
+        }
+        if (arr.length > 0) {
+            return arr[Math.floor(Math.random() * arr.length)];
+        }
+        if (brr.length > 0) {
+            return brr[Math.floor(Math.random() * brr.length)];
+        }
+        return null;
+    }
+
     // 更新武将属性
     updateGeneral(arr_embattle: Array<GeneralVO> = []) {
         const count = arr_embattle.length;
@@ -892,8 +954,8 @@ export default class GameData {
      */
     updateProp(type: PLAYERPROP, value, add: boolean = false, callback = null) {
         //这两个后端无法处理,要求单独做接口
-        if(type == PLAYERPROP.FOOD || type == PLAYERPROP.USESKILL_TIME){
-            this.updatePropSpecial(type,value,add,callback);
+        if (type == PLAYERPROP.FOOD || type == PLAYERPROP.USESKILL_TIME) {
+            this.updatePropSpecial(type, value, add, callback);
             return;
         }
         let prop = {} as UpdatePlayerProps;
@@ -903,12 +965,12 @@ export default class GameData {
         this.updateProps([prop], callback);
     }
 
-    updatePropSpecial(type: PLAYERPROP, value, add: boolean = false, callback = null){
+    updatePropSpecial(type: PLAYERPROP, value, add: boolean = false, callback = null) {
         //这两个后端无法处理,要求单独做接口
-        if(type == PLAYERPROP.FOOD){
+        if (type == PLAYERPROP.FOOD) {
 
         }
-        else if(type == PLAYERPROP.USESKILL_TIME){
+        else if (type == PLAYERPROP.USESKILL_TIME) {
 
         }
     }
@@ -924,7 +986,7 @@ export default class GameData {
             let arr = data.data.playPropBackList;
             for (let i = 0; i < arr.length; i++) {
                 let prop = arr[i];
-                let v = typeof prop.propValue == 'string' ? parseInt(prop.propValue) : prop.propValue; 
+                let v = typeof prop.propValue == 'string' ? parseInt(prop.propValue) : prop.propValue;
                 self.player.setProp(prop.propType, v);
             }
 

+ 21 - 15
tower_sanguo/assets/scripts/module/fight/FightUI.ts

@@ -24,6 +24,7 @@ import PiggyBankModel from "../piggyBank/PiggyBankModel";
 import GeneralUI from "../general/GeneralUI";
 import { ViewZorder } from "../../../MOKA/data/ViewZOrder";
 import GeneralUIModel from "../general/GeneralUIModel";
+import { MsgAddGeneralExp } from "../../net/HttpCommand";
 
 const { ccclass, property } = cc._decorator;
 
@@ -632,7 +633,7 @@ export default class FightUI extends BaseUI {
         }
     }
     private missionPass(msg: MissionUpdateResponse) {
-        this.realEndMission(msg.errorcode == 0, msg.rewards);
+        this.realEndMission(msg.data.code == 1, msg.data.sward);
     }
     private realEndMission(win, rewards = null) {
         this.clearGame();
@@ -655,23 +656,28 @@ export default class FightUI extends BaseUI {
         m.clear();
     }
 
-    addGeneralExp(msg: GeneralExpUpResponse) {
+    addGeneralExp(msg: GeneralExpUpResponse,params:any) {
         if (msg.errorcode != 0) {
             return;
         }
+        if(!params || !params.generalExpUps || params.generalExpUps.length == 0){
+            return;
+        }
+        let data = params.generalExpUps[0];
+        GameController.gameData.updateProp(PLAYERPROP.FOOD, -GameController.gameData.player.getProp(PLAYERPROP.FOODCONSUME), true);
 
-        GameController.gameData.player.setProp(PLAYERPROP.FOOD, msg.food);
-
-        //保护等级  INT[(上阵最大等级-兵营等级)/3+兵营等级],向下取整
-        let barracklv = GameController.gameData.player.getProp(PLAYERPROP.BARRACK);
-        let protectLv = Math.floor((this.getLvMax() - barracklv) / 3 + barracklv);
-        //选择武将
-        let g: General = this.getAddExpGeneral(protectLv);
+        let g:General;
+        for(let i=0;i<this.general_arr.length;i++){
+            let general = this.general_arr[i];
+            if(general && general.vo && data.gui == general.vo.id){
+                g = general;
+                break;
+            }
+        }
+        
         if (!g) {
             return;
         }
-        //计算增加经验
-        let exp = 1 / Math.pow(2, g.vo.lv - barracklv) * 100;
 
         var node = new cc.Node("New Sprite");
         node.y = -667;
@@ -681,7 +687,7 @@ export default class FightUI extends BaseUI {
         cc.tween(node).to(1, { x: g.node.x, y: g.node.y }).call(() => {
             node.parent = null;
             node.destroy();
-            g.addExp(exp);
+            g.addExp(data.exp);
         }).start();
 
         // 训练武将次数增加
@@ -1192,17 +1198,17 @@ export default class FightUI extends BaseUI {
     }
     /** 关闭武将界面时,检查武将羁绊变更,有则展示羁特效 */
     private onCheckFetterChange() {
-        cc.log('检查羁绊效果'+GeneralUIModel.is_change_embattle)
+        cc.log('检查羁绊效果' + GeneralUIModel.is_change_embattle)
         if (GeneralUIModel.is_change_embattle) {
             // 拦截羁绊刷新
         } else {
-            
+
         }
         // this.initGenerals();
         // this.clearGame();
         // this.checkFsSkill();
         this.checkFetterSkill();
-        
+
     }
 }
 

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

@@ -286,7 +286,14 @@ export default class MainUI extends BaseUI {
 
     clickGeneralExpUp() {
         if (GameController.gameData.player.getProp(PLAYERPROP.FOOD) >= GameController.gameData.player.getProp(PLAYERPROP.FOODCONSUME)) {
-            GameController.http.addGeneralExp(this.fightui.addGeneralExp.bind(this.fightui));
+            let data = GameController.gameData.getExpUpGeneral();
+            if (data) {
+                GameController.http.addGeneralExp(this.fightui.addGeneralExp.bind(this.fightui), [data]);
+            }
+            else {
+                console.log("没有合适的武将");
+
+            }
         }
         else {
             console.log("粮草不足");

+ 20 - 17
tower_sanguo/assets/scripts/net/HttpCommand.ts

@@ -5,6 +5,7 @@ import { PLAYERPROP } from "../data/GameDefinition";
 import StorageData, { STORAGE_KEY } from "../data/StorageData";
 import GameController from "../GameController";
 import InviteHelper from "../module/invite/InviteHelper";
+import GeneralVO from "../vo/GeneralVO";
 import AddItemRequest from "./msg/AddItemRequest";
 import GeneralExpUpRequest from "./msg/GeneralExpUpRequest";
 import GeneralPropUpdateRequest from "./msg/GeneralPropUpdateRequest";
@@ -17,10 +18,10 @@ import ServerManager from "./servertest/ServerManager";
 export default class HttpCommand {
     constructor() {
         this.httpM = new HttpManager();
-        if(HttpCommand.serverType == 0){
+        if (HttpCommand.serverType == 0) {
             this.serverUrl = 'http://172.16.15.97:9092/';//李杨
         }
-        else if(HttpCommand.serverType == 1){
+        else if (HttpCommand.serverType == 1) {
             this.serverUrl = 'http://172.16.15.91:9092/';//悍国
         }
     }
@@ -31,7 +32,7 @@ export default class HttpCommand {
     isTry = '';
 
     /** 服务器地址类型 0测试服 1测试服 2其他 */
-    static serverType:number = 1;
+    static serverType: number = 1;
 
     /**
      * 第一次握手
@@ -49,7 +50,7 @@ export default class HttpCommand {
     connectTest(callback) {
         GameController.commonData.ranKey = Utils.randomString()
         let data = {
-            "mac": "c3:65:e2:1c:b0:25,f6:60:e4:1a:b7:27",            
+            "mac": "c9:65:e2:1c:b0:25,f6:60:e4:1a:b7:27",
             "psk": GameController.commonData.ranKey,
             "appId": GameController.commonData.appid
         }
@@ -248,29 +249,22 @@ export default class HttpCommand {
     /** 更新武将属性 */
     updateGeneralProp(callback, msg: GeneralPropUpdateRequest) {
         let data = {
-            
+
         };
         this.sendData(HTTPTYPE.updateGeneralProp, data, callback);
     }
-    /** 升级武将星级 */
-    updateGeneralSX(callback, msg: GeneralStarUpRequest) {
-        let data = {
-            
-        };
-        this.sendData(HTTPTYPE.updateGeneralXS, data, callback);
-    }
 
     /** 更新布阵信息 */
     updateEmbattle(callback, arr: { gid: number, pos: number }[]) {
         let data = {
-            changeEmbattles:arr
+            changeEmbattles: arr
         };
         this.sendData(HTTPTYPE.changeEmbattle, data, callback);
     }
     /** 合成武将 */
     composeGeneral(callback, id: number) {
         let data = {
-            id:id
+            id: id
         };
         this.sendData(HTTPTYPE.composeGeneral, data, callback);
     }
@@ -322,9 +316,12 @@ export default class HttpCommand {
         this.sendData(HTTPTYPE.updateMission, data, callback);
     }
 
-    addGeneralExp(callback) {
-        this.sendData(HTTPTYPE.generalExpUp, {}, callback);
-        
+    addGeneralExp(callback, arr: MsgAddGeneralExp[]) {
+        let data = {
+            generalExpUps: arr
+        };
+        this.sendData(HTTPTYPE.generalExpUp, data, callback);
+
     }
 
     /** 兵营升级 */
@@ -513,4 +510,10 @@ export interface UpdatePlayerProps {
 
     propType: number,//服务器不根据文档改字段名字,仅用于发送给服务器
     propValue: number,//服务器不根据文档改字段名字,仅用于发送给服务器
+}
+
+export interface MsgAddGeneralExp {
+    exp: number,
+    gui: number,//general_id
+    lv: number,
 }

+ 1 - 1
tower_sanguo/assets/scripts/net/msg/MissionUpdateResponse.ts

@@ -12,6 +12,6 @@ import BaseResponse from "./BaseResponse";
      }
      
      /** boss过关奖励,小怪关没有 */
-     rewards:string;
+     sward:string;
  
  }

+ 2 - 1
tower_sanguo/assets/scripts/net/servertest/ServerManager.ts

@@ -269,7 +269,8 @@ export default class ServerManager {
             this.player.mission_arrive = id;
             this.player.mission_passed = id;
             if (vo.type == 2) {
-                msg.rewards = "1:100;2:200,3:300;4:114016;5:123008:66";
+                msg.data = {};
+                msg.data.sward = "1:100;2:200,3:300;4:114016;5:123008:66";
             }
         }
         msg.errorcode = pass ? 0 : 1;