Bladeren bron

后端接口

cyzhao 1 jaar geleden
bovenliggende
commit
f3ead9161c

+ 14 - 0
Gameserver/App/base/CmdCode.php

@@ -143,6 +143,14 @@ class CmdCode {
     
     // </editor-fold>
     
+    // <editor-fold defaultstate="collapsed" desc="商城操作码 - 65xx">
+    /**
+     * 商城购买东西
+     */
+    const cmd_shop_BuyGift = 6501;
+    
+    // </editor-fold>
+    
     // <editor-fold defaultstate="collapsed" desc="战斗操作码 - 68xx">
     
     const cmd_fight_settle = 6801;
@@ -151,6 +159,12 @@ class CmdCode {
      * 章节宝箱的领取
      */
     const cmd_fight_PassGateTsPrizeReceive = 6802;
+    
+    /**
+     * 关卡选择
+     */
+    const cmd_fight_selectGate = 6803;
+    
     // </editor-fold>
     
     // <editor-fold defaultstate="collapsed" desc="    反射方法    ">

+ 12 - 0
Gameserver/App/base/ErrCode.php

@@ -342,6 +342,18 @@ class ErrCode {
     const user_store_NoEquip = 3301;
 // </editor-fold>
 //
+    
+    
+//   // <editor-fold defaultstate="collapsed" desc="    shop 3400    ">    
+
+    const user_shop_NotRepeatBuy = 3401;
+    
+    const user_shop_LimitNum = 3402;
+    
+    
+    
+// </editor-fold>
+//
 
 // <editor-fold defaultstate="collapsed" desc="    反射方法    ">
 

+ 2 - 1
Gameserver/App/base/OpeCode.php

@@ -19,7 +19,8 @@ class OpeCode {
     const User = 600;
     
     const Store = 604;
-
+    
+    const Shop = 605;
 
     // <editor-fold defaultstate="collapsed" desc="反射方法">
     //

+ 30 - 0
Gameserver/App/model/User/EnumShopGift.php

@@ -0,0 +1,30 @@
+<?php
+
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+namespace loyalsoft;
+
+/**
+ * Description of EnumShopGift
+ *
+ * @author c'y'zhao
+ */
+class EnumShopGift extends Enum{
+    
+    const GateGift_Shop = 1;
+
+    const Daily_Shop = 2;
+
+    const SJunBeiBox_Shop = 3;
+
+    const BujiBox_Shop = 4;
+
+    const Cash_Shop = 5;
+
+    const Gold_Shop = 6;
+
+}

+ 63 - 4
Gameserver/App/process/FightProc.php

@@ -22,15 +22,74 @@ class FightProc {
     public static function procMain($req) {
         switch ($req->cmd) {
             case CmdCode::cmd_fight_settle:                                     # 6801 战斗结算
-                return FightProc::settle();
+                return FightProc::Settle();
             case CmdCode::cmd_fight_PassGateTsPrizeReceive:                     # 6802 章节宝箱的领取
-                return FightProc::PassGateTsPrizeReceive();     
+                return FightProc::PassGateTsPrizeReceive(); 
+            case CmdCode::cmd_fight_selectGate:                                 # 6803 关卡选择
+                return FightProc::SelectGate();
             default:
                 Err(ErrCode::cmd_err);
         }
     }
     
-    public static function FightSettle() {
+    /**
+     * 关卡选择
+     * @return type
+     */
+    public static function SelectGate() {
+        list($gateId) = req()->paras;
+        
+        ctx()->gates->CurrentGateId = $gateId;
+        
+        UserProc::updateUserInfo();
+        $ret = array(          
+            'gates' => ctx()->gates,        
+            );
+        return Resp::ok($ret);
+    }
+    
+    /**
+     * 关卡战斗结算
+     * @return type
+     */
+    public static function Settle() {
+        list($resultType, $gateId,$gold,$exp,$curTs) = req()->paras;
+        
+        $gateMo = GameConfig::gate_getItem($gateId);
+        my_Assert($gateMo!=null, ErrCode::err_const_no);
+        my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::user_Gate_NoUserGateInfo);
+        $gateInfo = ctx()->gates->GateList->$gateId;
+        $ts = $gateInfo->MaxSeconds;
+        if($curTs >= $ts){
+            $gateInfo->MaxSeconds = $curTs;
+        }
+        
+        if($resultType){
+            StoreProc::AddMultiItemInStore($gateMo->reward_win);                      
+            $newGateId = $gateId+1;
+            if(!StlUtil::dictHasProperty(ctx()->gates->GateList, $newGateId)){
+                ctx()->gates->CurrentGateId = $newGateId;
+                ctx()->gates->UnlockedGatesMaxId = $newGateId;
+                $gate = new Ins_GateInfo();
+                $gate->GateId = $newGateId;
+                ctx()->gates->GateList->$newGateId = $gate;
+            }
+               
+        } else {
+            StoreProc::AddMultiItemInStore($gateMo->reward_fail);
+        }
+        
+        ctx()->baseInfo->Add_Gold($gold);
+        ctx()->baseInfo->Add_Exp($exp);
+        
+        
+        
+        UserProc::updateUserInfo();
+        $ret = array(          
+            'gates' => ctx()->gates, 
+            'store' => ctx()->store,
+            );
+        return Resp::ok($ret);
         
     }
     
@@ -86,7 +145,7 @@ class FightProc {
 
         UserProc::updateUserInfo();
         $ret = array(          
-            'gate' => $gateInfo, 
+            'gates' => ctx()->gates, 
             'store' => ctx()->store,
             );
         return Resp::ok($ret);

+ 147 - 0
Gameserver/App/process/ShopProc.php

@@ -0,0 +1,147 @@
+<?php
+
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+namespace loyalsoft;
+
+/**
+ * Description of ShopProc
+ *
+ * @author c'y'zhao
+ */
+class ShopProc {
+    /**
+     * 逻辑分发
+     * 所有的Proc中必须有这样一个方法
+     * @param Req $req
+     */
+    public static function procMain($req) {
+        switch ($req->cmd) {
+            case CmdCode::cmd_shop_BuyGift:                                     # 6501 商城购买东西
+                return StoreProc::ShopBuyGift();             
+            default:
+                Err(ErrCode::cmd_err);
+        }
+    }
+    
+    /**
+     * 装备
+     * @return type
+     */
+    public static function ShopBuyGift() {
+        list($type,$typeId) = req()->paras;
+        $user = ctx();
+
+        switch ($type) {
+            case EnumShopGift::GateGift_Shop://章节礼包
+                my_Assert(!in_array($typeId, ctx()->privateState->gateGiftReceived), ErrCode::user_shop_NotRepeatBuy);       
+                
+                $mo = GameConfig::shop_gategift_getItem($typeId);
+                my_Assert($mo != null, ErrCode::err_const_no);       
+                
+                StoreProc::AddMultiItemInStore($mo->reward);
+                ctx()->privateState->gateGiftReceived[] = $typeId;
+                break;
+            case EnumShopGift::Daily_Shop://每日商店                             
+                $mo = GameConfig::shop_daily_getItem($typeId);
+                my_Assert($mo != null, ErrCode::err_const_no);   
+                
+                my_Assert(in_array($typeId, $user->privateState->dailyShopRandItems), ErrCode::err_const_no);   
+                
+                $index = 0;
+                if(in_array($typeId, $user->privateState->dailyShopReceived)){
+                    foreach ($user->privateState->dailyShopReceived as $val) {
+                        if($val == $typeId){
+                            $index += 1;
+                        }
+                    }
+                                       
+                }
+                my_Assert($index<= $mo->limitNum, ErrCode::user_shop_LimitNum);
+                
+                $str = $typeId.',1';
+                StoreProc::AddMultiItemInStore($str);
+                ctx()->privateState->dailyShopReceived[] = $typeId;
+                
+                break;
+                
+            case EnumShopGift::SJunBeiBox_Shop://S级军备
+                
+                
+                break;
+            case EnumShopGift::BujiBox_Shop://补给箱
+                
+                
+                break;
+            case EnumShopGift::Cash_Shop://商城-钻石
+                
+                
+                break;           
+            case EnumShopGift::Gold_Shop://商城-金币
+                
+                
+                break;           
+            default:
+                break;
+        }
+        
+        
+        //my_Assert(StlUtil::dictHasProperty($user->store->equip, $uid), ErrCode::user_store_NoEquip);                  
+
+                      
+        UserProc::updateUserInfo();
+        return Resp::ok(array(                   
+                    'privateState' => $user->privateState,                   
+                    'store' => $user->store,));
+        
+    }
+    
+    /**
+     * 商城每日重置
+     */
+    public static function ShopDailyClear() {
+        
+    }
+    
+    /**
+     * 每日商城随机6个道具
+     * @return type
+     */
+    public static function DailyShopItemRand() {
+        $dataDic = new \stdClass();
+        
+        $dic = GameConfig::shop_daily();
+        if($dic == null){
+            return;
+        }
+              
+        foreach ($dic as $typeId => $mo) {
+            $type = $mo->type;
+            if(StlUtil::dictHasProperty($dataDic,$mo->type) ){
+                $list = $dataDic->$type;
+                $list[] = $typeId;
+            } else {
+                $list = array();
+                $dataDic->$type = $list;
+            }
+        }
+        $result = array();             
+        $arrType = array(1,2,3,2,4,3);
+        foreach ($arrType as $k) {            
+            if(StlUtil::dictHasProperty($dataDic,$k) && count($dataDic->$k) > 0){
+                $arr2 = $dataDic->$k;            
+                $num = rand(0, count($arr2)-1);
+                $result[] = $arr2[$num];
+                unset($arr2[$num]);
+                
+                $dataDic->$k = $arr2;                
+            }
+        }
+        ctx()->privateState->dailyShopRandItems = $result;        
+        
+    }
+}

+ 2 - 1
Gameserver/App/process/UserProc.php

@@ -254,7 +254,8 @@ class UserProc {
      * @param bool $isnew Description
      */
     static function OnNewDay($isnew) {
-       
+        ShopProc::DailyShopItemRand();
+        ShopProc::ShopDailyClear();
     }
 
 // <editor-fold defaultstate="collapsed" desc="创建新用户">