Esempio n. 1
0
        /// <inheritdoc />
        public INetworkItem CreateEntity(int id, Vector3 position, Quaternion rotation)
        {
            if (id < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(id), $"The {nameof(id)} for the item must be above 0.");
            }

            IGameObjectContextualBuilder builder = GameObjectFactory.CreateBuilder();

            //TODO: Create entity identify for items
            //Create the player GameObject and provide an identiy object to it.
            INetworkItem item = builder
                                .With(Service <IEntityIdentity> .As(new EntityIdentity(id, EntityType.Item)))
                                .Create(TemporaryItemPrefab, position, rotation)
                                .GetComponent(typeof(INetworkItem)) as INetworkItem;

            if (item == null)
            {
                throw new InvalidOperationException($"Failed to create a {nameof(INetworkItem)}. The prefab was missing the component.");
            }

            //Now we must register it in the player registry
            ItemWorldRegistery.AddEntity(id, item);

            return(item);
        }
Esempio n. 2
0
        /// <inheritdoc />
        public INetworkPlayer CreateLocalPlayer()
        {
            Transform spawnpoint = SpawnPointStrategy.GetSpawnpoint();

            if (spawnpoint == null)
            {
                throw new InvalidOperationException($"The {this.GetType().Name} tried to load a spawnpoint from {nameof(SpawnPointStrategy)} but the point was null.");
            }

            IGameObjectContextualBuilder builder = GameObjectFactory.CreateBuilder();

            //TODO: Implement local player spawning.
            //Create the player GameObject and provide an identiy object to it.
            INetworkPlayer player = builder
                                    .With(Service <IEntityIdentity> .As(context => new LocalPlayerEntityIdentity(context.Resolve <ICharacterSlotSelectedModel>())))
                                    .Create(LocalPlayerLobbyPrefab, spawnpoint.position, spawnpoint.rotation)
                                    .GetComponent(typeof(INetworkPlayer)) as INetworkPlayer;

            if (player == null)
            {
                throw new InvalidOperationException($"Failed to create a {nameof(INetworkPlayer)}. The prefab was missing the component.");
            }

            if (player.Identity == null)
            {
                throw new InvalidOperationException($"The identity was null.");
            }

            //Now we must register it in the player registry
            PlayerRegistery.AddEntity(player.Identity.EntityId, player);
            Rooms.DefaultRoom.TryEnter(player);

            return(player);
        }
Esempio n. 3
0
        /// <inheritdoc />
        public INetworkPlayer CreateEntity(int id, Vector3 position, Quaternion rotation)
        {
            if (id < 0 || id > byte.MaxValue)
            {
                throw new ArgumentOutOfRangeException(nameof(id), $"The {nameof(id)} for the player must not exceed 255 or be below 0.");
            }

            IGameObjectContextualBuilder builder = GameObjectFactory.CreateBuilder();

            //Create the player GameObject and provide an identiy object to it.
            INetworkPlayer player = builder
                                    .With(Service <IEntityIdentity> .As(new PlayerEntityIdentity((byte)id)))
                                    .Create(NetworkPlayerLobbyPrefab, position, rotation)
                                    .GetComponent(typeof(INetworkPlayer)) as INetworkPlayer;

            if (player == null)
            {
                throw new InvalidOperationException($"Failed to create a {nameof(INetworkPlayer)}. The prefab was missing the component.");
            }

            //Now we must register it in the player registry
            PlayerRegistery.AddEntity(id, player);
            Rooms.DefaultRoom.TryEnter(player);

            return(player);
        }
Esempio n. 4
0
        public IGameObjectContextualBuilder ProvideContext([NotNull] IGameObjectContextualBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.With(Service <NetworkEntityGuid> .As(EntityGuid))
                   .With(Service <INetPeer> .As(OwnerPeer)));
        }
 public IGameObjectContextualBuilder ProvideContext(IGameObjectContextualBuilder builder)
 {
     return(builder.With(Service <NetworkEntityGuid> .As(NetworkGuid))
            .With(Service <INetPeer> .As(Peer)));
 }
 /// <summary>
 /// Adds the <see cref="ISpawnContext"/> to the <see cref="IGameObjectContextualBuilder"/>.
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public static IGameObjectContextualBuilder With(this IGameObjectContextualBuilder builder, ISpawnContext context)
 {
     //Add the context and return the builder.
     return(context.ProvideContext(builder));
 }
 protected virtual IGameObjectContextualBuilder OnEntityConstruction(IPlayerSpawnContext context, IGameObjectContextualBuilder builder)
 {
     //Access point that allows implementers of this type to extend the construction process.
     return(builder);
 }