فهرست منبع

代码整理.

gwang 4 سال پیش
والد
کامیت
ebbcb87f37

+ 22 - 0
Gameserver/Amfphp/base/HashSaver.php

@@ -9,6 +9,17 @@ namespace loyalsoft;
  * @version 1.0.0 创建. 2年以前就跟高健讨论过的理念,我一直没有落到实处(高健已经使用了). --gwang 2020.4.24
  */
 class HashSaver extends Object_ext {
+
+    private static $save_tag = array();
+
+    /**
+     * 添加回存记录
+     * @param type $name
+     */
+    protected static function save_tag($name) {
+        self::$save_tag[] = $name;
+    }
+
     //
     // <editor-fold defaultstate="collapsed">
 
@@ -33,5 +44,16 @@ class HashSaver extends Object_ext {
         return gMem()->hmset($mem_key, $this);
     }
 
+    /**
+     * 存储数据到redis
+     */
+    function updateData2($mem_key) {
+        $data = array();
+        foreach (self::$save_tag as $k) {
+            $data[$k] = $this->$k;
+        }
+        return gMem()->hmset($mem_key, $data);
+    }
+
     // </editor-fold>
 }

+ 2 - 2
Gameserver/Amfphp/base/Object_ext.php

@@ -32,7 +32,7 @@ class Object_ext {
      * 从对象加载数据(赋值给自己的字段)
      * @param array/Object $obj
      */
-    public function LoadFrom($obj) {
+    protected function LoadFrom($obj) {
         if (func_num_args() != 1 || is_null($obj)) {
             die("too many args or arg obj was null!");
         }
@@ -48,7 +48,7 @@ class Object_ext {
         return $this->toString();
     }
 
-    public function toString() {
+    protected function toString() {
         $str = JsonUtil::encode($this);
         return $str;
     }

+ 197 - 41
Gameserver/Amfphp/model/User/Data_UserGame.php

@@ -22,10 +22,15 @@ class Data_UserGame extends HashSaver {
 
     /**
      * 商城
-     * @var {}
+     * @var Info_UserShop
      */
     public $shopdata;
 
+    /**
+     * @var Info_UserSecretshop 玩家神秘商城数据
+     */
+    public $userSecretshop;
+
     /**
      * 英雄
      * @var Info_UserGameHero
@@ -38,11 +43,6 @@ class Data_UserGame extends HashSaver {
      */
     public $privateState;
 
-    /**
-     * @var Info_UserSecretshop 玩家神秘商城数据
-     */
-    public $userSecretshop;
-
     /**
      * 关卡
      * @var Info_UserGateDifficulty
@@ -84,11 +84,11 @@ class Data_UserGame extends HashSaver {
      */
     public $NewbieGuide;
 
-    /**
-     * 新手引导是否已经结束
-     * @var type 
-     */
-    public $NewbieGuideOver = 1;
+//    /**
+//     * 新手引导是否已经结束
+//     * @var type 
+//     */
+//    public $NewbieGuideOver = 1;
 
     /**
      * @var Data_UserProfile 角色画像
@@ -137,8 +137,8 @@ class Data_UserGame extends HashSaver {
             $this->gates = new Info_UserGateDifficulty();                            # 初始化关卡默认数据
             $this->map = new Info_Map();                                        # 初始化地图解锁数据
 //            $this->heroManual = new HeroManualModel();                          # 初始化图鉴数据结构
-            $this->NewbieGuide = ObjectInit();                                  # 初始化新手引导结构
-//            $this->pvp = new UserPVPModel();                                    # 初始化pvp模块
+            $this->NewbieGuide = new Info_NewbieGuide();                        # 初始化新手引导结构
+//            $this->pvp = new UserPVPModel();                                  # 初始化pvp模块
             $this->userSecretshop = new Info_UserSecretshop();                  # 神秘商店
 //            $this->task = new Info_UserTask();                                   # 任务数据
             $this->taskCardShop = new Info_TaskCard_Shop();                     # 任务卡商店
@@ -162,33 +162,6 @@ class Data_UserGame extends HashSaver {
 
     // <editor-fold defaultstate="collapsed" desc="   functions   ">
 
-    /**
-     * 设置钻石数
-     * @param Data_UserGame $user
-     * @param int $amt 数量
-     */
-    static public function set_Cash($user, $amt) {
-        my_Assert($amt >= 0, "数量小于0");
-        my_Assert($user, "user为空");
-        my_Assert(isset($user->cash), "找不到cash字段");
-        $user->cash = $amt;                                                     # 实际逻辑
-    }
-
-    /**
-     * 扣除玩家晶石
-     * @param Data_UserGame $user
-     * @param int $amt
-     */
-    static public function Consume_Spar($user, $amt) {
-        if ($amt > 0 && isset($user) && isset($user->spar)) {
-            if ($user->spar - $amt >= 0) {
-                $user->spar -= $amt;
-                return true;
-            }
-        }
-        return false;
-    }
-
     /**
      * 扣除玩家钻石
      * @param Info_UserBase $user
@@ -364,7 +337,190 @@ class Data_UserGame extends HashSaver {
     }
 
 // </editor-fold>
-    // <editor-fold defaultstate="collapsed" desc="私有方法">
+    // <editor-fold defaultstate="collapsed" desc="实例方法">
+
+    /**
+     * 基础信息
+     * @param bool $save 是否需要回存
+     * @return Info_UserBase
+     */
+    public function base($save = false) {
+        $this->baseInfo = new Info_UserBase($this->baseInfo);
+        if ($save) {
+            self::save_tag("baseInfo");
+        }
+        return $this->baseInfo;
+    }
+
+    /**
+     * 玩家仓库
+     * @param bool $save 是否需要回存
+     * @return Info_Store
+     */
+    public function store($save = false) {
+        $this->store = new Info_Store($this->store);
+        if ($save) {
+            self::save_tag("store");
+        }
+        return $this->store;
+    }
+
+    /**
+     * 商店数据
+     * @param bool $save 是否需要回存
+     * @return Info_UserShop
+     */
+    public function shop($save = false) {
+        $this->shopdata = new Info_UserShop($this->shopdata);
+        if ($save) {
+            self::save_tag("shopdata");
+        }
+        return $this->shopdata;
+    }
+
+    /**
+     * 神秘商店
+     * @param bool $save 是否需要回存
+     * @return Info_UserSecretshop
+     */
+    public function secretshop($save = false) {
+        $this->userSecretshop = new Info_UserSecretshop($this->userSecretshop);
+        if ($save) {
+            self::save_tag("userSecretshop");
+        }
+        return $this->userSecretshop;
+    }
+
+    /**
+     * 英雄数据
+     * @param bool $save 是否需要回存
+     * @return Info_UserGameHero
+     */
+    public function heros($save = false) {
+        $this->heros = new Info_UserGameHero($this->heros);
+        if ($save) {
+            self::save_tag("heros");
+        }
+        return $this->heros;
+    }
+
+    /**
+     * 私有数据
+     * @param bool $save 是否需要回存
+     * @return Info_PrivateState
+     */
+    public function private($save = false) {
+        $this->privateState = new Info_PrivateState($this->privateState);
+        if ($save) {
+            self::save_tag("privateState");
+        }
+        return $this->privateState;
+    }
+
+    /**
+     * 关卡数据
+     * @param bool $save 是否需要回存
+     * @return Info_UserGateDifficulty
+     */
+    public function gates($save = false) {
+        $this->gates = new Info_UserGateDifficulty($this->gates);
+        if ($save) {
+            self::save_tag("gates");
+        }
+        return $this->gates;
+    }
+
+    /**
+     * 地图数据
+     * @param bool $save 是否需要回存
+     * @return Info_Map
+     */
+    public function map($save = false) {
+        $this->map = new Info_Map($this->map);
+        if ($save) {
+            self::save_tag("map");
+        }
+        return $this->map;
+    }
+
+    /**
+     * 任务卡商店
+     * @param bool $save 是否需要回存
+     * @return Info_TaskCard_Shop
+     */
+    public function taskCardShop($save = false) {
+        $this->taskCardShop = new Info_TaskCard_Shop($this->taskCardShop);
+        if ($save) {
+            self::save_tag("taskCardShop");
+        }
+        return $this->taskCardShop;
+    }
+
+    /**
+     * pvp数据
+     * @param bool $save 是否需要回存
+     * @return Info_UserPVP
+     */
+    public function pvp($save = false) {
+        $this->pvp = new Info_UserPVP($this->pvp);
+        if ($save) {
+            self::save_tag("pvp");
+        }
+        return $this->pvp;
+    }
+
+    /**
+     * 角色画像数据
+     * @param bool $save 是否需要回存
+     * @return Data_UserProfile
+     */
+    public function profile($save = false) {
+        $this->profile = new Data_UserProfile($this->profile);
+        if ($save) {
+            self::save_tag("profile");
+        }
+        return $this->profile;
+    }
+
+    /**
+     * 圣哲学院
+     * @param bool $save 是否需要回存
+     * @return Info_College
+     */
+    public function college($save = false) {
+        $this->college = new Info_College($this->college);
+        if ($save) {
+            self::save_tag("college");
+        }
+        return $this->college;
+    }
+
+    /**
+     * 新手引导
+     * @param bool $save 是否需要回存
+     * @return Info_NewbieGuide
+     */
+    public function newbieGuide($save = false) {
+        $this->NewbieGuide = new Info_NewbieGuide($this->NewbieGuide);
+        if ($save) {
+            self::save_tag("NewbieGuide");
+        }
+        return $this->NewbieGuide;
+    }
+
+    /**
+     * 战队配置
+     * @param bool $save 是否需要回存
+     * @return Info_NewbieGuide
+     */
+    public function &teamConfig($save = false) {
+//        $this->NewbieGuide = new Info_NewbieGuide($this->NewbieGuide);
+        if ($save) {
+            self::save_tag("heroTeamConfig");
+        }
+        return $this->heroTeamConfig;
+    }
+
     // 
 // </editor-fold>
 }

+ 15 - 0
Gameserver/Amfphp/model/User/Info_NewbieGuide.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace loyalsoft;
+
+/**
+ * Description of Info_NewbieGuide
+ * 新手引导
+ * @author gwang
+ */
+class Info_NewbieGuide extends Object_ext {
+
+    //put your code here
+    public $guideStep;
+
+}

+ 3 - 3
Gameserver/Amfphp/model/User/Info_UserBase.php

@@ -6,7 +6,7 @@ namespace loyalsoft;
  * 玩家基本信息
  * @author gwang(wanggangzero@qq.com)
  */
-class Info_UserBase {
+class Info_UserBase extends Object_ext {
     //put your code here
 
     /**
@@ -100,12 +100,12 @@ class Info_UserBase {
      * @var int 游戏内赠送游戏币总额
      */
     public $gift_cash = 0;  //
-    
+
     /**
      * 言灵等级消耗的资源点
      * @var type
      */
-    public $resPoint = 0;  
+    public $resPoint = 0;
 
     public function initialize() {
         my_Assert(GameConfig::primordial_data(), "找不到账号初始化数据");         # 防御

+ 46 - 57
Gameserver/Amfphp/process/UserProc.php

@@ -32,8 +32,8 @@ class UserProc {
                 return UserProc::completeNewbieGuide();
 //            case CmdCode::cmd_user_setNewbieGuideCards:                         # 6008 发放新手引导所需卡牌
 //                return self::SetNewbieGuideCards($req);                
-            case CmdCode::cmd_user_setNewbieGuideOver:                          # 6009 跳过新手引导
-                return UserProc::setNewbieGuideOver();
+//            case CmdCode::cmd_user_setNewbieGuideOver:                          # 6009 跳过新手引导
+//                return UserProc::setNewbieGuideOver();
             case CmdCode::cmd_user_setNickname:                                 # 6010 设置/修改玩家昵称
                 return self::SetUserNickname();
             case CmdCode::cmd_user_SetUserHeadImageBorder:                      # 6011 修改玩家头像框
@@ -103,50 +103,50 @@ class UserProc {
 // </editor-fold>
 //
 // <editor-fold defaultstate="collapsed" desc="新手引导">
+//    /**
+//     * [6009] 新手引导 发送n张碎片到玩家身上 
+//     */
+//    static function SetNewbieGuideCards() {
+//        Err(ErrCode::function_notopen_msg);                                     # 功能已经废弃 -wg
+//        $private = req()->userInfo->game->privateState;
+//        if (!property_exists($private, 'newbieguideCards')) {                   # 逻辑检查, 是否已经发放过
+//            $private->newbieguideCards = true;
+//            req()->userInfo->game->privateState = $private;                      # 回写私有数据
+//            $sp = explode(';', glc()->User_SetNewbieGuideCards);                # 碎片
+//            foreach ($sp as $cardinfo) {
+//                $arr = explode(',', $cardinfo);
+//                $itemid = $arr[0];
+//                $num = $arr[1];
+//                StoreProc::addSegmentIntoStore(req()->userInfo->game->store, $itemid, $num);
+//            }
+//            $exp = explode(';', glc()->User_SetNewbieGuideExps);                # 经验卡
+//            foreach ($exp as $expinfo) {
+//                $arr = explode(',', $expinfo);
+//                $itemid = $arr[0];
+//                $num = $arr[1];
+//                StoreProc::PutOverlyingItemInStore($itemid, $num);
+//            }
+//            UserProc::updateUserInfo();                                         # 回存玩家数据
+//            return Resp::ok(array('store' => req()->userInfo->game->store));
+//        }
+//        return Resp::err(ErrCode::active_hasgetted);
+//    }
 
     /**
-     * [6009] 新手引导 发送n张碎片到玩家身上 
-     */
-    static function SetNewbieGuideCards() {
-        Err(ErrCode::function_notopen_msg);                                     # 功能已经废弃 -wg
-        $private = req()->userInfo->game->privateState;
-        if (!property_exists($private, 'newbieguideCards')) {                   # 逻辑检查, 是否已经发放过
-            $private->newbieguideCards = true;
-            req()->userInfo->game->privateState = $private;                      # 回写私有数据
-            $sp = explode(';', glc()->User_SetNewbieGuideCards);                # 碎片
-            foreach ($sp as $cardinfo) {
-                $arr = explode(',', $cardinfo);
-                $itemid = $arr[0];
-                $num = $arr[1];
-                StoreProc::addSegmentIntoStore(req()->userInfo->game->store, $itemid, $num);
-            }
-            $exp = explode(';', glc()->User_SetNewbieGuideExps);                # 经验卡
-            foreach ($exp as $expinfo) {
-                $arr = explode(',', $expinfo);
-                $itemid = $arr[0];
-                $num = $arr[1];
-                StoreProc::PutOverlyingItemInStore($itemid, $num);
-            }
-            UserProc::updateUserInfo();                                         # 回存玩家数据
-            return Resp::ok(array('store' => req()->userInfo->game->store));
-        }
-        return Resp::err(ErrCode::active_hasgetted);
-    }
-
-    /**
-     * [6011] 增加 设置引导结束的标志位 
+     * [6009] 增加 设置引导结束的标志位 
      */
     public static function setNewbieGuideOver() {
-        $user = new Data_UserGame(req()->userInfo->game);                        # user
-        if (!CommUtil::isPropertyExists($user, "NewbieGuideOver")) {            # 防御: 变量未初始化
-            $user->NewbieGuideOver = 1;
-        }
-        $user->NewbieGuideOver = 1;
-        req()->userInfo->game = $user;
-        UserProc::updateUserInfo();                                         # 回写数据
-        return Resp::ok(array(#                                                 # 返回值
-                    'result' => "succeed"
-        ));
+        Err(ErrCode::function_notopen_msg);                                     # 功能已经废弃 -wg
+//        $user = new Data_UserGame(req()->userInfo->game);                        # user
+//        if (!CommUtil::isPropertyExists($user, "NewbieGuideOver")) {            # 防御: 变量未初始化
+//            $user->NewbieGuideOver = 1;
+//        }
+//        $user->NewbieGuideOver = 1;
+//        req()->userInfo->game = $user;
+//        UserProc::updateUserInfo();                                         # 回写数据
+//        return Resp::ok(array(#                                                 # 返回值
+//                    'result' => "succeed"
+//        ));
     }
 
     /**
@@ -154,26 +154,15 @@ class UserProc {
      * 第一阶段的引导 
      */
     public static function completeNewbieGuide() {
-        $guideIndex = req()->paras[0];                                           # 参数: 新手引导步骤
-        $user = new Data_UserGame(req()->userInfo->game);                        # user
-        if (!CommUtil::isPropertyExists($user, "NewbieGuide")) {                # 防御: 变量未初始化
-            $user->NewbieGuide = ObjectInit();
-        }
+        $guideIndex = req()->paras[0];                                          # 参数: 新手引导步骤
+        $user = new Data_UserGame(req()->userInfo->game);                       # user
+        my_default_Obj($user->NewbieGuide);                                     # 防御: 变量未初始化
         $NewbieGuide = $user->NewbieGuide;
         if (!CommUtil::isPropertyExists($NewbieGuide, "guideStep")) {           # 防御: 变量未初始化
             $NewbieGuide->guideStep = 0;
         }
         my_Assert($guideIndex >= $NewbieGuide->guideStep, ErrCode::user_settutorialscompletedfail_err);
-        if ($guideIndex == 1) {
-//            $huid = 10001;                                                      # 初始英雄
-//            $pos = 1;
-//            $newYanlingTypeId = 4020001;                                        # 普通上官雀
-//
-//            $hero = $user->heros->collectHeros->$huid;
-//            $oldYanlingUId = $hero->yanling->$pos->itemuid;
-//            $user->store->yanling->$oldYanlingUId->typeId = $newYanlingTypeId;  # 直接修改类型变为普通言灵
-//              $info= json_decode( '{"1":4011101,"2":4011201,"3":4011301}');
-        }
+
         $NewbieGuide->guideStep = $guideIndex;
         $user->NewbieGuide = $NewbieGuide;
         req()->userInfo->game = $user;

+ 25 - 7
Gameserver/Amfphp/test.php

@@ -11,8 +11,8 @@ echoLine("phpver: " . PHP_VERSION . PHP_EOL);
 //
 // 
 echo number_format(1.0125, 2, '.', '');
-$arr = GameConfig::plot_getItem(1001, 0);               # 查找对应的剧情
-var_dump($arr);
+//$arr = GameConfig::plot_getItem(1001, 0);               # 查找对应的剧情
+//var_dump($arr);
 //foreach ($arr as $plot) {
 //    isEditor() and $plot = new \sm_plot();
 //    var_dump($plot);
@@ -23,10 +23,28 @@ $i = 9;
 var_dump($i++);
 var_dump($i);
 $user = ObjectInit();
+$user->name = "wg";
 
-my_default_Obj($user->heros->recordUnLockHeroDic);
-//if (!CommUtil::isPropertyExists($user->heros, "recordUnLockHeroDic")) {
-//    $user->heros->recordUnLockHeroDic = ObjectInit();
-//}
-var_dump($user);
+class A {
+
+    public $B = "王刚";
+
+    function &B() {
+
+        echoLine(__FUNCTION__);
+        echoLine(__METHOD__);
+        $name = __FUNCTION__;
+        echoLine($this->$name);
+        echoLine(nameof($this->B));
+        return $this->B;
+    }
+
+}
+
+function ctx() {
+    return req()->userInfo->game;
+}
+
+ctx()->base(true);
+var_dump(nameof($user->name));
 //var_dump(Resp::err(3503, "时尚杂志opencv"));

+ 51 - 0
Gameserver/Amfphp/util/CommUtil.php

@@ -273,6 +273,57 @@ class CommUtil {
         return iconv(mb_detect_encoding($str), 'UTF-8//IGNORE', $str);
     }
 
+    /**
+     * 查找变量/对象的引用名称
+     * @param mixed $var 变量/对象
+     * @return type
+     */
+    static function getReference(&$var, $scope = false) {
+        if (is_object($var)) {
+            $var->___uniqid = uniqid();
+        } else {
+            $var = serialize($var);
+        }
+        if (!$scope) {
+            $scope = $GLOBALS;
+        }
+        $name = self::getReference_traverse($var, $scope);
+        if (is_object($var)) {
+            unset($var->___uniqid);
+        } else {
+            $var = unserialize($var);
+        }
+        return "\${$name}";
+    }
+
+    private static function getReference_traverse(&$var, $arr) {
+        $name = array_search($var, $arr, true);
+        if (false !== $name) {
+            return "{$name}";
+        }
+        foreach ($arr as $key => $value) {
+            if (is_object($value)) {
+                $name = self::getReference_traverse($var, get_object_vars($value));
+                if (false !== $name) {
+                    return "{$key}->{$name}";
+                }
+            }
+        }
+        return "-";
+    }
+
+}
+
+/**
+ * 仿C#的nameof
+ * @param type $var
+ * @return type
+ */
+function nameof(&$var, $scope = false) {
+    if (!$scope) {
+        $scope = $GLOBALS;
+    }
+    return CommUtil::getReference($var, $scope);
 }
 
 function arr2obj($arr) {