예제 #1
0
        private bool OnPlayerJoins(WorldServiceEvents.PlayerJoinRoomEvent evt)
        {
            if (isLocalPlayer(evt.SessionId))
            {
                return(false);
            }
            DataEntityHandle handle = PlayerDataEntityFactory.CreateRemotePlayerEntity(dataEntityCollection, evt.Name, evt.SessionId);

            PlayerDataEntityFactory.AddCommonDataComponents(dataEntityCollection, handle);
            PlayerDataEntityFactory.AddCommonZoneScopeDataComponents(dataEntityCollection, handle);
            if (!dataEntityCollection.HasComponent <RemotePlayerData>(handle))
            {
                dataEntityCollection.AddComponent <RemotePlayerData>(handle);
            }
            if (!dataEntityCollection.HasComponent <ParticipationData>(handle))
            {
                dataEntityCollection.AddComponent <ParticipationData>(handle);
            }
            PresenceData component = dataEntityCollection.GetComponent <PresenceData>(handle);

            if (dataEntityCollection.TryGetComponent <PresenceData>(dataEntityCollection.LocalPlayerHandle, out var component2))
            {
                component.World             = component2.World;
                component.Room              = component2.Room;
                component.ContentIdentifier = component2.ContentIdentifier;
                component.InstanceRoom      = component2.InstanceRoom;
            }
            component.IsDisconnecting = false;
            eventDispatcher.DispatchEvent(new NetworkControllerEvents.RemotePlayerJoinedRoomEvent(handle));
            return(false);
        }
예제 #2
0
        protected virtual bool onRoomJoined(WorldServiceEvents.SelfRoomJoinedEvent evt)
        {
            DataEntityHandle localPlayerHandle = dataEntityCollection.LocalPlayerHandle;

            if (localPlayerHandle.IsNull)
            {
                throw new MissingReferenceException("The local player handle does not exist!");
            }
            PlayerDataEntityFactory.AddCommonDataComponents(dataEntityCollection, localPlayerHandle);
            PlayerDataEntityFactory.AddCommonZoneScopeDataComponents(dataEntityCollection, localPlayerHandle);
            dataEntityCollection.AddComponent <LocalPlayerInZoneData>(localPlayerHandle);
            PresenceData component2 = dataEntityCollection.GetComponent <PresenceData>(localPlayerHandle);

            if (string.IsNullOrEmpty(evt.Room.zoneId.instanceId))
            {
                component2.World             = evt.Room.world;
                component2.Room              = evt.Room.zoneId.name;
                component2.ContentIdentifier = evt.Room.contentIdentifier;
                component2.InstanceRoom      = null;
            }
            else
            {
                component2.InstanceRoom = evt.Room.zoneId;
            }
            DataEntityHandle[] remotePlayerHandles = dataEntityCollection.GetRemotePlayerHandles();
            for (int i = 0; i < remotePlayerHandles.Length; i++)
            {
                PresenceData component3 = dataEntityCollection.GetComponent <PresenceData>(remotePlayerHandles[i]);
                if (string.IsNullOrEmpty(evt.Room.zoneId.instanceId))
                {
                    component3.World             = evt.Room.world;
                    component3.Room              = evt.Room.zoneId.name;
                    component3.ContentIdentifier = evt.Room.contentIdentifier;
                    component3.InstanceRoom      = null;
                }
                else
                {
                    component3.InstanceRoom = evt.Room.zoneId;
                }
            }
            if (dataEntityCollection.TryGetComponent <SessionIdData>(localPlayerHandle, out var component4))
            {
                component4.SessionId = evt.SessionId;
            }
            else
            {
                component4 = dataEntityCollection.AddComponent(localPlayerHandle, delegate(SessionIdData component)
                {
                    component.SessionId = evt.SessionId;
                });
            }
            eventDispatcher.DispatchEvent(new NetworkControllerEvents.LocalPlayerJoinedRoomEvent(localPlayerHandle, evt.Room.world, evt.Room.zoneId.name));
            return(false);
        }