protected override async ETTask Run(Session session, C2G_EnterMap request, G2C_EnterMap response, Action reply) { Player player = session.GetComponent <SessionPlayerComponent>().GetMyPlayer(); // 在Gate上动态创建一个Map Scene,把Unit从DB中加载放进来,然后传送到真正的Map中,这样登陆跟传送的逻辑就完全一样了 GateMapComponent gateMapComponent = player.AddComponent <GateMapComponent>(); gateMapComponent.Scene = await SceneFactory.Create(gateMapComponent, "GateMap", SceneType.Map); Scene scene = gateMapComponent.Scene; // 这里可以从DB中加载Unit Unit unit = UnitFactory.Create(scene, player.Id, UnitType.Player); unit.AddComponent <UnitGateComponent, long>(session.InstanceId); StartSceneConfig startSceneConfig = StartSceneConfigCategory.Instance.GetBySceneName(session.DomainZone(), "Map1"); response.MyId = player.Id; reply(); // 开始传送 await TransferHelper.Transfer(unit, startSceneConfig.InstanceId, startSceneConfig.Name); }
public override void EndInit() { foreach (StartSceneConfig startSceneConfig in this.GetAll().Values) { this.ProcessScenes.Add(startSceneConfig.Process, startSceneConfig); if (!this.ZoneScenesByName.ContainsKey(startSceneConfig.Zone)) { this.ZoneScenesByName.Add(startSceneConfig.Zone, new Dictionary <string, StartSceneConfig>()); } this.ZoneScenesByName[startSceneConfig.Zone].Add(startSceneConfig.Name, startSceneConfig); switch (startSceneConfig.Type) { case SceneType.Gate: this.Gates.Add(startSceneConfig.Zone, startSceneConfig); break; case SceneType.Location: this.LocationConfig = startSceneConfig; break; } } }
public static async ETTask <Scene> Create(Entity parent, long id, int zone, string name, SceneType sceneType, StartSceneConfig startSceneConfig = null) { await ETTask.CompletedTask; Scene scene = EntitySceneFactory.CreateScene(id, zone, sceneType, name); scene.Parent = parent; scene.AddComponent <MailBoxComponent, MailboxType>(MailboxType.UnOrderMessageDispatcher); switch (scene.SceneType) { case SceneType.Realm: scene.AddComponent <NetKcpComponent, IPEndPoint>(startSceneConfig.OuterIPPort); break; case SceneType.Gate: scene.AddComponent <NetKcpComponent, IPEndPoint>(startSceneConfig.OuterIPPort); scene.AddComponent <PlayerComponent>(); scene.AddComponent <GateSessionKeyComponent>(); break; case SceneType.Map: scene.AddComponent <UnitComponent>(); //scene.AddComponent<RecastPathComponent>(); break; case SceneType.Location: scene.AddComponent <LocationComponent>(); break; } return(scene); }
public static async ETTask <Scene> Create(Entity parent, long id, long instanceId, int zone, string name, SceneType sceneType, StartSceneConfig startSceneConfig = null) { await ETTask.CompletedTask; Scene scene = EntitySceneFactory.CreateScene(id, instanceId, zone, sceneType, name, parent); scene.AddComponent <MailBoxComponent, MailboxType>(MailboxType.UnOrderMessageDispatcher); switch (scene.SceneType) { case SceneType.Realm: scene.AddComponent <NetKcpComponent, IPEndPoint, int>(new IPEndPoint(IPAddress.Any, startSceneConfig.OuterPort), SessionStreamDispatcherType.SessionStreamDispatcherServerOuter); break; case SceneType.Gate: scene.AddComponent <NetKcpComponent, IPEndPoint, int>(startSceneConfig.InnerIPOutPort, SessionStreamDispatcherType.SessionStreamDispatcherServerOuter); scene.AddComponent <PlayerComponent>(); scene.AddComponent <GateSessionKeyComponent>(); break; case SceneType.Map: scene.AddComponent <UnitComponent>(); scene.AddComponent <AOISceneComponent, int>(9); break; case SceneType.Location: scene.AddComponent <LocationComponent>(); break; case SceneType.Router: Log.Debug("Router:" + startSceneConfig.OuterPort); scene.AddComponent <RouterServiceComponent, IPEndPoint>(new IPEndPoint(IPAddress.Any, startSceneConfig.OuterPort)); scene.AddComponent <RouterServiceInnerComponent>(); break; } return(scene); }