public NetworkPlayerSpawnContext(NetworkEntityGuid guid, INetPeer peer)
        {
            //TODO: Null tests

            NetworkGuid = guid;
            Peer        = peer;
        }
示例#2
0
        public bool TryInteract(NetworkEntityGuid entityInteracting)
        {
            //Send the interaction request for the server to handle.
            SendRequest(new EntityInteractionRequestPayload(guidContainer.NetworkGuid), DeliveryMethod.ReliableOrdered, false, 0);

            return(true);
        }
        public NetworkGameObjectPrefabSpawnContext(NetworkEntityGuid guid, GameObjectPrefab prefabId, INetPeer peer)
        {
            //TODO: Check refs

            PrefabId    = prefabId;
            NetworkGuid = guid;
            NetworkPeer = peer;
        }
 public EntityStateChangedEvent(byte state, NetworkEntityGuid entityGuid, float timeStamp)
 {
     //TODO: Check refs
     //TODO: Verify args
     State            = state;
     EntityGuid       = entityGuid;
     CurrentTimeStamp = timeStamp;
 }
 public EntityPositionUpdateEvent(Vector3Surrogate position, NetworkEntityGuid entityGuid, float timeStamp)
 {
     //TODO: Check refs
     //TODO: Verify args
     EntityGuid       = entityGuid;
     Position         = position;
     CurrentTimeStamp = timeStamp;
 }
        /// <summary>
        /// Creates a new <see cref="BoomaPayloadMessageType.PlayerSpawnResponse"/> payload.
        /// </summary>
        public PlayerSpawnResponsePayload(PlayerSpawnResponseCode code, Vector3Surrogate position, QuaternionSurrogate rotation, NetworkEntityGuid entityGuid)
        {
            //TODO: Check refs

            ResponseCode = code;
            EntityGuid   = entityGuid;
            Position     = position;
            Rotation     = rotation;
        }
 public GameObjectEntitySpawnEventPayload(NetworkEntityGuid entityGuid, Vector3Surrogate position, QuaternionSurrogate rotation,
                                          Vector3Surrogate scale, GameObjectPrefab prefabId, byte state)
     : base(entityGuid, position, rotation)
 {
     //TODO: Check values/refs
     Scale        = scale;
     PrefabId     = prefabId;
     CurrentState = state;
 }
示例#8
0
        /// <inheritdoc />
        public void Unlock(NetworkEntityGuid entityInteracting)
        {
            if (entityInteracting == null)
            {
                Unlock();
            }

            //TODO: Implement entity handling
        }
示例#9
0
        public bool TryInteract([NotNull] NetworkEntityGuid entityInteracting)
        {
            if (entityInteracting == null)
            {
                throw new ArgumentNullException(nameof(entityInteracting));
            }

            //TODO: Distance checking.
            return(TryInteract());
        }
示例#10
0
        protected override void OnIncomingHandlableMessage(IRequestMessage message, PlayerMoveRequestPayload payload, IMessageParameters parameters, InstanceClientSession peer)
        {
            NetworkEntityGuid guid = guidLookupService.Lookup(peer.PeerDetails.ConnectionID);

            if (guid == null)
            {
                throw new InvalidOperationException($"Couldn't find GUID for Connection ID: {peer.PeerDetails.ConnectionID}.");
            }

            entityCollection[guid].WorldObject.transform.position = payload.Position.ToVector3();
        }
示例#11
0
        public static void Test_Can_Build_Empty_Guid_With_0_Id()
        {
            //arrange
            NetworkEntityGuidBuilder builder = new NetworkEntityGuidBuilder();

            //act
            NetworkEntityGuid guid = builder.WithId(0).WithId(0).Build();

            //assert
            Assert.NotNull(guid);
            Assert.IsTrue(guid.isEmpty);
        }
示例#12
0
        public EntityContainer([NotNull] NetworkEntityGuid networkGuid, [NotNull] GameObject worldObject)
        {
            if (networkGuid == null)
            {
                throw new ArgumentNullException(nameof(networkGuid));
            }
            if (worldObject == null)
            {
                throw new ArgumentNullException(nameof(worldObject));
            }

            NetworkGuid = networkGuid;
            WorldObject = worldObject;
        }
示例#13
0
        public static void Test_Can_Build_Guid_With_Provided_EntityType(EntityType type)
        {
            //arrange
            NetworkEntityGuidBuilder builder = new NetworkEntityGuidBuilder();

            //act
            NetworkEntityGuid guid = builder.WithType(type).WithType(type).Build();

            //assert
            Assert.NotNull(guid);
            //won't be empty with an entity type.

            Assert.AreEqual(type, guid.EntityType);
        }
示例#14
0
        public static void Test_Can_Build_Guid_With_Provided_Id(int id)
        {
            //arrange
            NetworkEntityGuidBuilder builder = new NetworkEntityGuidBuilder();

            //act
            NetworkEntityGuid guid = builder.WithId(Math.Max(65, id - 5)).WithId(id).Build();

            //assert
            Assert.NotNull(guid);
            Assert.IsFalse(guid.isEmpty);

            Assert.AreEqual(id, guid.EntityId);
        }
示例#15
0
        private void OnEntityLevelChanged([JetBrains.Annotations.NotNull] NetworkEntityGuid entity, [JetBrains.Annotations.NotNull] EntityDataChangedArgs <int> changeData)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }
            if (changeData == null)
            {
                throw new ArgumentNullException(nameof(changeData));
            }

            IWorldObject worldObject = WorldObjectMappable.RetrieveEntity(entity);

            worldObject.SetLevel(changeData.NewValue);
        }
示例#16
0
        /// <summary>
        /// Creates a new payload for the <see cref="BoomaPayloadMessageType.EntitySpawnEvent"/> packet.
        /// </summary>
        /// <param name="entityGuid">The entity's GUID.</param>
        /// <param name="position">Position of the entity.</param>
        /// <param name="rotation">Rotation of the entity.</param>
        public EntitySpawnEventPayload(NetworkEntityGuid entityGuid, Vector3Surrogate position, QuaternionSurrogate rotation)
        {
            if (position == null)
            {
                throw new ArgumentNullException(nameof(position), $"Provided {nameof(Vector3Surrogate)} must not be null.");
            }

            if (rotation == null)
            {
                throw new ArgumentNullException(nameof(rotation), $"Provided {nameof(QuaternionSurrogate)} must not be null.");
            }

            EntityGuid = entityGuid;
            Position   = position;
            Rotation   = rotation;
        }
示例#17
0
        protected override void OnIncomingHandlableMessage(IRequestMessage message, PlayerSpawnRequestPayload payload, IMessageParameters parameters, InstanceClientSession peer)
        {
            //TODO: Right now we don't have a full handshake for entering an instance. So we need to make up a GUID for the entering player
            //Important to check if we've actually already created an entity for this connection
            //We don't have that implemenented though for the demo

            //rely on the factory implementation to handle placement details such as position and rotation
            NetworkEntityGuid   guid    = entityGuidFactory.Create(EntityType.Player);
            IEntitySpawnResults details = playerEntityFactory.SpawnPlayerEntity(new NetworkPlayerSpawnContext(guid, peer));

            if (details.Result != SpawnResult.Success)
            {
                throw new InvalidOperationException($"Failed to create Entity for {peer.ToString()}. Failure: {details.Result.ToString()}");
            }

            //TODO: This is temporary stuff for demo
            entityCollection.Add(guid, new EntityContainer(guid, details.EntityGameObject));
            peerCollection.Add(peer);
            connectionRegistry.Register(peer.PeerDetails.ConnectionID, guid);

            //TODO: Clean this up
            Vector3Surrogate pos = details.EntityGameObject.transform.position.ToSurrogate();

            QuaternionSurrogate rot = details.EntityGameObject.transform.rotation.ToSurrogate();

            //Send the response to the player who requested to spawn
            peer.SendResponse(new PlayerSpawnResponsePayload(PlayerSpawnResponseCode.Success, pos, rot, guid), DeliveryMethod.ReliableUnordered, true, 0);

            //TODO: Remove this. This is demo code.
            foreach (var entity in entityCollection.Values.Where(e => e.NetworkGuid.EntityType == EntityType.GameObject))
            {
                ITagProvider <GameObjectPrefab> prefabTag = entity.WorldObject.GetComponent <ITagProvider <GameObjectPrefab> >();
                IEntityStateContainer           state     = entity.WorldObject.GetComponentInChildren <IEntityStateContainer>();

                peer.SendEvent(new GameObjectEntitySpawnEventPayload(entity.NetworkGuid, entity.WorldObject.transform.position.ToSurrogate(),
                                                                     entity.WorldObject.transform.rotation.ToSurrogate(), entity.WorldObject.transform.localScale.ToSurrogate(), prefabTag.Tag, state.State),
                               DeliveryMethod.ReliableOrdered, false, 0);
            }
        }
示例#18
0
        public void InitializeAvatar([NotNull] NetworkEntityGuid entityGuidOwner, [NotNull] Task <string> entityName)
        {
            if (entityGuidOwner == null)
            {
                throw new ArgumentNullException(nameof(entityGuidOwner));
            }
            if (entityName == null)
            {
                throw new ArgumentNullException(nameof(entityName));
            }

            //We can't really recover from this but we can log
            try
            {
                UnityAsyncHelper.UnityMainThreadContext.PostAsync(async() =>
                {
                    try
                    {
                        string avatarName = await entityName
                                            .ConfigureAwaitFalse();

                        await InitializeAvatarRenderers(avatarName)
                        .ConfigureAwaitFalseVoid();
                    }
                    catch (Exception e)
                    {
                        Debug.LogError($"Failed to query GaiaOnline for avatar data. Reason: {e.ToString()}");
                        throw;
                    }
                });
            }
            catch (Exception e)
            {
                //TODO: Add username/id info
                Debug.LogError($"Encountered error when attempting to load the avatar: {e.Message}");
                throw;
            }
        }
示例#19
0
 public EntityWorldObjectCreatedEventArgs([NotNull] NetworkEntityGuid entityGuid,
                                          [NotNull] IWorldObject worldReprensetation)
 {
     EntityGuid          = entityGuid ?? throw new ArgumentNullException(nameof(entityGuid));
     WorldReprensetation = worldReprensetation ?? throw new ArgumentNullException(nameof(worldReprensetation));
 }
示例#20
0
 /// <summary>
 /// Creates a new <see cref="BoomaPayloadMessageType.PlayerMoveRequestPayload"/> payload.
 /// </summary>
 public EntityInteractionRequestPayload(NetworkEntityGuid guidOfEntityToInteractWith)
 {
     //TODO: Check refs
     NetworkGuid = guidOfEntityToInteractWith;
 }
示例#21
0
 TInstanceModelType IEntityGuidMappable <NetworkEntityGuid, TInstanceModelType> .this[NetworkEntityGuid key]
 {
     get => GetCreatureInstance(key);
示例#22
0
 public void Register(int connectionId, NetworkEntityGuid guid)
 {
     GuidToConnectionMap[guid]         = connectionId;
     ConnectionToGuidMap[connectionId] = guid;
 }
示例#23
0
 public int Lookup(NetworkEntityGuid guid)
 {
     return(GuidToConnectionMap[guid]);
 }
示例#24
0
 public bool Contains(NetworkEntityGuid guid)
 {
     return(GuidToConnectionMap.ContainsKey(guid));
 }
示例#25
0
 public PlayerEntitySpawnEventPayload(NetworkEntityGuid entityGuid, Vector3Surrogate position, QuaternionSurrogate rotation)
     : base(entityGuid, position, rotation)
 {
     //Nothing at the moment. Can extend for future use.
 }