Kaynağa Gözat

fixed: 对手信息, 言灵和武器数据.

gwang 5 yıl önce
ebeveyn
işleme
faca10578a

+ 15 - 0
Gameserver/Amfphp/base/Object_ext.php

@@ -28,6 +28,21 @@ class Object_ext {
         }
     }
 
+    /**
+     * 从对象加载数据(赋值给自己的字段)
+     * @param array/Object $obj
+     */
+    public function LoadFrom($obj) {
+        if (func_num_args() != 1 || is_null($obj)) {
+            die("too many args or arg obj was null!");
+        }
+        $para = is_array($obj) ? $obj : (array) $obj;                           # 转关联数组
+        $vars = get_class_vars(get_class($this));                               # 后期绑定,获得实例的实际类名称=>属性数组
+        foreach ($vars as $name => $value) {
+            $this->$name = isset($para[$name]) ? $para[$name] : $value;         # 取参数中的或者默认值
+        }
+    }
+
     public function __toString() {
         return $this->toString();
     }

+ 39 - 0
Gameserver/Amfphp/base/RedisHashSaver.php

@@ -0,0 +1,39 @@
+<?php
+
+namespace loyalsoft;
+
+/**
+ * 对象字段将以hash表结构存入Redis中.
+ * 以达到拆分读写各个子节点的目标, 最终能够节省(带宽、内存、运算)消耗,提升性能.
+ * @author gwang 
+ * @version 1.0.0 创建. 2年以前就跟高健讨论过的理念,我一直没有落到实处(高健已经使用了). --gwang 2020.4.24
+ */
+class RedisHashSaver extends Object_ext {
+    //
+    //
+    // <editor-fold defaultstate="collapsed">
+
+    /**
+     * 自定义的数据加载方式
+     * @param type $tag
+     */
+    function readDataFromMem($mem_key) {
+        $ret = gMem()->hgetall($mem_key);                                       # 已JSON解析
+        my_Assert(null != $ret, ErrCode::err_mem);                              # 未找到数据
+        $this->LoadFrom($ret);
+    }
+
+    /**
+     * 存储数据到redis
+     */
+    function updateData($mem_key) {
+        $array = array();                                                       # 
+        $vars = get_class_vars(get_class($this));                               # 获得实例的实际类名称=>属性数组
+        foreach ($vars as $name => $value) {
+            $array[$name] = $value;                                             # 取参数中的或者默认值
+        }
+        gMem()->hmset($mem_key, $array);
+    }
+
+    // </editor-fold>
+}

+ 2 - 2
Gameserver/Amfphp/process/FightProc/PVPProc.php

@@ -38,8 +38,8 @@ class PVPProc {
             'level' => my_null_default($uinfo->game->level, 1),
             'headImg' => my_null_default($uinfo->game->img, ""),
 //            'skills' => null, #                                                  # skills暂时没有实例数据 
-            'equipment' => my_null_default($uinfo->game->store->equipment, new \stdClass()), # 武器
-            'yanling' => my_null_default($uinfo->game->store->yanling, new \stdClass()), # 言灵
+            'equipment' => array("equipments" => my_null_default($uinfo->game->store->equipment, new \stdClass())), # 武器
+            'yanling' => array("items" => my_null_default($uinfo->game->store->yanling, new \stdClass())), # 言灵
             'heros' => my_null_default($heros, new \stdClass()), #              # 英雄集合
         );
 

+ 16 - 6
Gameserver/Amfphp/test.php

@@ -7,10 +7,20 @@ include __DIR__ . '/main.php';
 //header('X-Accel-Buffering: no');                                              # nginx 控制头, 关闭buffer
 //set_time_limit(15);                                                           # 设置执行超时时间
 echoLine("phpver:" . PHP_VERSION);
-$power = (int) 3.3;
-var_dump($power);
-var_dump(intval($power));
 
-$t = gMem()->hget("gate", "31");
-var_dump($t);
-gMem()->zadd("t", array("wg" => $t));
+class ABC extends Object_ext {
+
+    public $name;
+
+    public function __construct($args) {
+        parent::__construct($args);
+        $this->LoadFrom(array('name' => "wanggangzero"));
+    }
+
+}
+
+$arr = array(
+    'name' => '王刚'
+);
+var_dump(new ABC($arr));
+

+ 16 - 9
Gameserver/Amfphp/util/StlUtil.php

@@ -275,14 +275,21 @@ class StlUtil {
 
 }
 
-//\
-if (isEditor()) {
+/**
+ * 函数式写法
+ * @param type $arr
+ * @param type $item
+ * @return type
+ */
+function array_contains($arr, $item) {
+    return StlUtil::arrayContains($arr, $item);
+}
 
-    /**
-     * 关联数组, json_encode之后转为{}
-     */
-    class asoc_array {
-        
-    }
+//\
 
-}
+/**
+ * 关联数组, json_encode之后转为{}
+ */
+class asoc_array {
+    
+}

+ 7 - 9
Gameserver/nbproject/private/private.xml

@@ -13,21 +13,19 @@
     <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
         <group>
             <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/process/UserProc.php</file>
+            <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/process/HeroProc.php</file>
             <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/index.php</file>
-            <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/util/CRedisUtil.php</file>
-            <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/base/CmdCode.php</file>
             <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/process/FightProc/PVPProc.php</file>
             <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/process/FightProc.php</file>
-            <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/process/RankProc.php</file>
-            <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/model/User/StoreModel.php</file>
+            <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/process/StoreProc.php</file>
+            <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/service_call/cmemdata/kvflush.php</file>
+            <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/util/HttpUtil.php</file>
             <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/base/Resp.php</file>
-            <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/base/Req.php</file>
-            <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/util/CMemBase.php</file>
+            <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/model/User/HeroModel.php</file>
             <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/base/ErrCode.php</file>
             <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/base/MemKey_GameRun.php</file>
-            <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/test.php</file>
-            <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/main.php</file>
-            <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/base/MemKey_User.php</file>
+            <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/model/User/UserHeroModel.php</file>
+            <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/service_call/pay/charge_info.php</file>
         </group>
     </open-files>
 </project-private>