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

调整登录时添加本地玩家数据

johnclot69 7 месяцев назад
Родитель
Сommit
b4da56656d

+ 1 - 1
DotNet/Hotfix/Scenes/Game/Handler/C2G_BindPlayerHandler.cs

@@ -48,7 +48,7 @@ namespace ET.Server
             }
 
             // 绑定选择的玩家
-            session.GetComponent<SessionPlayerComponent>().BindPlayerId(request.PlayerId > 0 ? request.PlayerId : player.GetId());
+            session.GetComponent<SessionPlayerComponent>().BindPlayerId(player);
 
             // todo 分配场景
             Map map = MapHelper.BindPlayerDispatch(player);

+ 14 - 4
DotNet/Hotfix/Scenes/Game/Player/PlayerSystem.cs

@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 using System.Text.Json;
 using BattleIce;
 using JsonSerializer = System.Text.Json.JsonSerializer;
@@ -184,11 +185,20 @@ namespace ET.Server
             }
         }
 
-        /** 玩家登录事件 **/
+        /** 角色登录成功,加载完所有数据后,将角色相关的信息主动推送到客户端 **/
         public static void OnLogin(this WNPlayer self)
         {
-            self.ReadyFirst = true;
-            self.DomainScene().GetComponent<GamePlayerComponent>().Add(self.GetId(), self);
+            try
+            {
+                // todo 角色登陆成功 各组件调用
+                self.ReadyFirst = true;
+                // todo 设置角色登录时间
+
+            }
+            catch (Exception e)
+            {
+                Log.Debug($"OnLogin 出错:{e}");
+            }
         }
 
         /** 向客户端推送角色相关数据 **/

+ 3 - 3
DotNet/Hotfix/Scenes/Game/Player/PlayerTempDataComponentSystem.cs

@@ -14,9 +14,9 @@ namespace ET.Server
                 self.MapData = new PlayerMapInfo();
 
                 self.MapData.mapId = 10099;
-                self.MapData.x = 230;
-                self.MapData.y = 100;
-                self.MapData.direction = System.MathF.PI / 2;
+                self.MapData.x = 1586;
+                self.MapData.y = 1566;
+                // self.MapData.direction = System.MathF.PI / 2;
                 self.MapData.hp = PLAYER.initHp;
                 self.MapData.mp = PLAYER.initMp;
 

+ 6 - 4
DotNet/Hotfix/Scenes/Game/Session/SessionPlayerComponentSystem.cs

@@ -57,11 +57,13 @@ namespace ET.Server
         /// 绑定玩家id
         /// </summary>
         /// <param name="self"></param>
-        /// <param name="playerId"></param>
-        public static void BindPlayerId(this SessionPlayerComponent self, long playerId)
+        /// <param name="player"></param>
+        public static void BindPlayerId(this SessionPlayerComponent self, WNPlayer player)
         {
-            Log.Debug($"session玩家绑定组件 绑定玩家id={playerId}");
-            self.PlayerId = playerId;
+            Log.Debug($"session玩家绑定组件 绑定玩家id={player.GetId()}");
+            self.PlayerId = player.GetId();
+            // 添加本地玩家数据
+            self.DomainScene().GetComponent<GamePlayerComponent>().Add(player.GetId(), player);
         }
 
         /// <summary>