Bläddra i källkod

武器商店和探索领取奖励

cyzhao 3 år sedan
förälder
incheckning
6a46ced956

+ 13 - 0
Gameserver/Amfphp/base/CmdCode.php

@@ -665,6 +665,16 @@ class CmdCode {
      * 背包扩展
      */
     const cmd_store_unlockStore = 6428;
+    
+    /**
+     * 购买武器
+     */
+    public const map_buyWeapon = 6429;
+    
+    /**
+     * 获取商店武器信息
+     */
+    public const map_getShopWeapon = 6430;
 
 // </editor-fold>
     //
@@ -1341,6 +1351,9 @@ class CmdCode {
      * 领取探索奖励
      */
     public const map_reviceExplorerReward = 7506;
+    
+    
+    
 // 
 // // </editor-fold>
 // 

+ 2 - 0
Gameserver/Amfphp/base/ErrCode.php

@@ -588,6 +588,8 @@ class ErrCode {
      */
     const store_YanLingNotGem = 3422;
     const store_YanLingHaveGem = 3423;
+    
+    const store_weaponCantBuy = 3424;
 // </editor-fold>
     //  
     // <editor-fold defaultstate="collapsed" desc="   任务错误码 35xx系列   ">

+ 19 - 4
Gameserver/Amfphp/configs/GameConfig.php

@@ -1,14 +1,13 @@
 <?php
-
-namespace loyalsoft;
-
 ////////////////////
  // 由CodeGenerator创建。
  // Copyright (C) gwang (wanggangzero@qq.com), Loyalsoft@sjz Inc
  // author: gwang 
- // 日期: 2022-04-08 09:34:06
+ // 日期: 2022-04-11 13:52:51
 ////////////////////
 
+namespace loyalsoft;
+
 /**
  * 常量配置数据 
  */
@@ -1707,6 +1706,22 @@ class GameConfig {
         return self::get_hash_item('map_explorer', $key);
     }
     /**
+    * 武器商店
+    * @return \shop_weapon
+    */
+    public static function shop_weapon()
+    { 
+        static $a = null; 
+        return self::initValue($a, 'shop_weapon');
+    }
+    /**
+    * @return \sm_shop_weapon shop_weapon itemArray 
+    */
+    public static function shop_weapon_getItemArray($key)
+    { 
+        return self::get_hash_item('shop_weapon', $key);
+    }
+    /**
     * 当前版本(时间戳)
     * @return \ver
     */

+ 17 - 1
Gameserver/Amfphp/model/Const/GameConfig.php

@@ -3,7 +3,7 @@
  // 由CodeGenerator创建。
  // Copyright (C) gwang (wanggangzero@qq.com), Loyalsoft@sjz Inc
  // author: gwang 
- // 日期: 2022-04-08 09:34:06
+ // 日期: 2022-04-11 14:18:34
 ////////////////////
 
 /**
@@ -1704,6 +1704,22 @@ class GameConfig {
         return self::get_hash_item('map_explorer', $key);
     }
     /**
+    * 武器商店
+    * @return \shop_weapon
+    */
+    public static function shop_weapon()
+    { 
+        static $a = null; 
+        return self::initValue($a, 'shop_weapon');
+    }
+    /**
+    * @return \sm_shop_weapon shop_weapon itemArray 
+    */
+    public static function shop_weapon_getItemArray($key)
+    { 
+        return self::get_hash_item('shop_weapon', $key);
+    }
+    /**
     * 当前版本(时间戳)
     * @return \ver
     */

+ 47 - 0
Gameserver/Amfphp/model/Const/sm_shop_weapon.php

@@ -0,0 +1,47 @@
+<?php
+////////////////////
+ // 由CodeGenerator创建。
+ // Copyright (C) gwang (wanggangzero@qq.com), Loyalsoft@sjz Inc
+ // author: gwang 
+ // 日期: 2022-04-11 13:45:01
+////////////////////
+
+
+/**
+ * Static Model shop_weapon 武器商店
+ */
+class sm_shop_weapon
+{
+
+    /**
+    * @var Int32 用途未知!!请到数据库中添加字段注释。 default(0) 
+    */
+    public $id;
+
+    /**
+    * @var String 武器池子: id,per;  
+    */
+    public $weaponlist;
+
+    /**
+    * @var Int32 不同地区npc不同武器池子不同 default(0) 
+    */
+    public $npc;
+
+    /**
+    * @var String 用途未知!!请到数据库中添加字段注释。  
+    */
+    public $cost;
+
+    /**
+    * @var Int32 抽取数量 default(0) 
+    */
+    public $num;
+
+    /**
+    * @var String 用途未知!!请到数据库中添加字段注释。  
+    */
+    public $etc;
+
+}
+

+ 16 - 0
Gameserver/Amfphp/model/User/Info_Store.php

@@ -51,6 +51,19 @@ class Info_Store extends Object_ext {
      */
     public $triggerLimitTsGift = array();
 
+    /**
+     * 商店武器每日刷新出的武器id----不同地区npc不同
+     * @var type
+     */
+    public $weaponPool = null;
+    
+    /**
+     * 万一所有的武器都随机完了那,只能在重置武器池重新刷新,这个就是保存购买记录的
+     * @var type
+     */
+    public $weaponReward = null;
+
+
     /**
      * 玩家注册时初始化
      */
@@ -62,6 +75,9 @@ class Info_Store extends Object_ext {
         $this->equipment = JsonUtil::decode(GameConfig::primordial_data()->User_Store_equipment); # 装备初始化数据
         $this->yanling = JsonUtil::decode(GameConfig::primordial_data()->User_Store_yanling);     # 言灵初始化数据
         $this->segement = JsonUtil::decode(GameConfig::primordial_data()->User_Store_segment);    # 碎片
+        
+        $this->weaponPool = ObjectInit();
+        $this->weaponReward = ObjectInit();
     }
 
     /**

+ 2 - 2
Gameserver/Amfphp/process/MapProc.php

@@ -28,8 +28,8 @@ class MapProc {
             case CmdCode::map_unlockInfoSva:                                    #  [7505] 保存mapid下已经解锁的
                 return self::unlockInfoSva();    
             case CmdCode::map_reviceExplorerReward:                             #  [7506] 领取探索奖励
-                return self::reviceExplorerReward();
-            default:                                                            #  err: 未知的命令码
+                return self::reviceExplorerReward();           
+                default:                                                            #  err: 未知的命令码
                 return Resp::err(ErrCode::cmd_err);
         }
     }

+ 155 - 0
Gameserver/Amfphp/process/StoreProc.php

@@ -75,10 +75,165 @@ class StoreProc {
                 return StoreProc::GemRemoveYanLing();
             case CmdCode::cmd_store_unlockStore:
                 return StoreProc::unlockStore();
+            case CmdCode::map_buyWeapon:                                        #  [7507] 购买武器map_getShopWeapon
+                return self::buyWeapon();    
+            case CmdCode::map_getShopWeapon:                                    #  [7507] 购买武器
+                return self::getShopWeapon();    
             default:
                 Err(ErrCode::cmd_err);
         }
     }
+    
+    /**
+     * 
+     */
+    public static function getShopWeapon() {
+        $npcid = req()->paras[0];   # 提取参数
+        
+        self::DailyRefreshWeapon($npcid);
+        
+        UserProc::updateUserInfo();
+        return Resp::ok();
+    }
+    
+    public static function buyWeapon() {
+        $npcid = req()->paras[0];   # 提取参数	
+        $weaponId = req()->paras[1];   # 提取参数	
+        
+        $store = req()->userInfo->game->store();         
+        $type = 0;
+        
+        $tag = true;
+        if(StlUtil::dictHasProperty($store->weaponReward, $npcid)){
+            $dic = $store->weaponReward->$npcid;
+            foreach ($dic as $k => $list) {
+                if(in_array($weaponId, $list)){
+                    $tag = false;
+                    break;
+                }              
+            }
+        } else {
+            $tag = false;               
+        }
+        
+        my_Assert($tag == true, ErrCode::store_weaponCantBuy);  
+        
+        $list = GameConfig::shop_weapon_getItemArray($npcid);
+        
+        
+        req()->userInfo->game->newMap = $newMap;
+        
+        UserProc::updateUserInfo();
+        return Resp::ok($newMap);
+    }
+    
+    /*
+     * 每日刷新武器
+     */
+    public static function DailyRefreshWeapon($npcid = null) {       
+            if($npcid != null ){//&& !StlUtil::dictHasProperty(req()->userInfo->game->store()->weaponPool, $npcid)         
+            $retArr = array();
+            $ret = new \stdClass();
+            $list = GameConfig::shop_weapon_getItemArray($npcid);
+            
+            $ret2 = new \stdClass();
+            foreach ($list as $value) {               
+                $arr = $value->weaponlist;     
+                foreach ($arr as $item) {
+                    $itemList = explode(';',$item); 
+                    foreach ($itemList as $val) {
+                        $valList = explode(',',$val); 
+                        $id = $valList[0];
+                        $per = $valList[1];
+                        $ret->$id = $per;                                                       
+                    }
+                }
+                
+                $ret2 = $ret;
+                $type = $value->id;
+                if(StlUtil::dictHasProperty(req()->userInfo->game->store()->weaponReward, $npcid)){
+                    $weaponList = req()->userInfo->game->store()->weaponReward->$npcid->$type;                   
+                    foreach ($weaponList as $wid) {
+                        if(StlUtil::dictHasProperty($ret, $wid)){
+                            StlUtil::dictRemove($ret, $id);
+                        }
+                    }
+                    
+                }
+                                  
+                $temp = $ret;
+                if(count($ret)< $value->num){
+                    $temp = $ret2;
+                    req()->userInfo->game->store()->weaponReward->$npcid->$type = array();                   
+                }
+                $pArr = self::randweapon($temp, $value->num);
+                //数组合并
+                $retArr = array_merge($retArr, $pArr);
+                req()->userInfo->game->store()->weaponPool->$npcid->$type = $retArr;                                        
+            }
+            
+        } else {
+            
+            $dic = req()->userInfo->game->store()->weaponPool;
+            foreach ($dic as $npcid => $val) {
+                $ret = array();
+                $retArr= array();
+                $list = GameConfig::shop_weapon_getItemArray($npcid);
+                foreach ($list as $value) {               
+                    $arr = $value->weaponlist;     
+                    foreach ($arr as $item) {
+                        $itemList = explode(';',$item); 
+                        foreach ($itemList as $val) {
+                            $valList = explode(',',$val); 
+                            $id = $valList[0];
+                            $per = $valList[1];
+                            $ret->$id = $per;                                                       
+                        }
+                    }
+                    
+                    req()->userInfo->game->store()->weaponPool->$npcid = array();
+                    $pArr = self::randweapon($ret, $value->num);
+                    
+                    $retArr = array_merge($retArr, $pArr);                   
+                }
+                
+                $type = $value->id;
+                req()->userInfo->game->store()->weaponPool->$npcid->$type = $retArr;
+            }            
+        }       
+    }
+    
+    static function randweapon($temp,$limit) {
+        $retArr = array();
+        $num = 0;
+                while (true) {
+                    $total = 0;
+                    foreach ($temp as $k => $v) {
+                            $total += $v;
+                    }
+                    
+                    $n = rand(1,$total);                   
+                    $start = 0;
+                    foreach ($temp as $id => $per) {                                                                                          
+                        $start += $per;
+                        if($n<=$start){
+                            if(in_array($id, $retArr)){
+                                StlUtil::dictRemove($temp, $id);
+                            } else {
+                                $retArr[] = $id;
+                                $num += 1;    
+                                break;                                                                                        
+                            }
+                        }
+                    }
+                    
+                    if($num >= $limit){
+                        break;
+                    }
+                }
+                
+                return $retArr;
+    }
 
     /**
      * 扩容