Exemple #1
0
        private void Initialize(T[] spawnedArray, int index, ISpawnPoint spawnPoint)
        {
            Poolable <T> poolable = poolableArray[index];

            Initialize(poolable, spawnPoint);
            spawnedArray[index] = poolable.Target;
        }
Exemple #2
0
        private void CreateSpawnPoint()
        {
            if (this.Name == null || this.Location.Equals(UnsetLocation))
            {
                spawnCreationDeferred = true;
                l.Error("TODO: Follow through with deferred spawn creation. Spawn will not be created");
            }

            this.SpawnEntity = this.Galaxy.EntityController.CreateNow(new PEntity("VanillaSpawner")
            {
                EntityName = Name,
                State      = new EntityState
                {
                    TeamId  = this.TeamId,
                    Physics = new PhysicsBodyState(this.Location),
                    Module  = new ModuleStateNode
                    {
                        Children =
                        {
                            new ModuleStateNode(typeof(Spawner), new SpawnerState()),
                        },
                    },
                }
            });
            this.SpawnPoint = SpawnEntity.RootModule.ModulesOfType <Spawner>().First();
        }
Exemple #3
0
 /// <summary>
 /// Constructs a weapon pickup
 /// </summary>
 /// <param name="weapon">Weapon</param>
 /// <param name="spawnPoint">Spawn point</param>
 /// <param name="entity">Entity</param>
 /// <param name="remainingRespawnTime">Remaining respawn time</param>
 public WeaponPickup(IWeapon weapon, ISpawnPoint spawnPoint, double respawnTime, IServerLobby serverLobby)
 {
     if (weapon == null)
     {
         throw new ArgumentNullException(nameof(weapon));
     }
     if (!weapon.IsValid)
     {
         throw new ArgumentException("Weapon is not valid.", nameof(weapon));
     }
     if (respawnTime < 0.0f)
     {
         throw new ArgumentException("Respawn time can't be negative", nameof(respawnTime));
     }
     if (serverLobby == null)
     {
         throw new ArgumentNullException(nameof(serverLobby));
     }
     if (!serverLobby.IsValid)
     {
         throw new ArgumentException("Server lobby is not valid.", nameof(serverLobby));
     }
     Weapon           = weapon;
     SpawnPoint       = spawnPoint ?? throw new ArgumentNullException(nameof(spawnPoint));
     RespawnTime      = respawnTime;
     this.serverLobby = serverLobby;
     Respawn();
 }
        public override IEnumerable <IEnemy> Spawn()
        {
            List <IEnemy> enemies = new List <IEnemy>();

            for (uint i = 0; i < enemiesPerWave; i++)
            {
                ISpawnPoint spawnPoint = SelectRandomSpawnPoint();
                if (spawnPoint != null)
                {
                    enemies.Add(new DefaultEnemy(spawnPoint.Position));
                }
            }

            // float used so that the enemiesPerWave doesn't grow too fast
            enemiesPerWave *= 1.5f;

            // float overflow
            if (enemiesPerWave < 0)
            {
                // uint because that's used in the for loop above
                // and uint.MaxValue < float.MaxValue
                enemiesPerWave = uint.MaxValue;
            }
            return(enemies);
        }
Exemple #5
0
        public T Spawn(ISpawnPoint spawnPoint)
        {
            Assert.IsNotNull(spawnPoint);

            Poolable <T> poolable = pool.Retrieve();

            Initialize(poolable, spawnPoint);

            return(poolable.Target);
        }
Exemple #6
0
        public override IEnumerable <IEnemy> Spawn()
        {
            List <IEnemy> enemies    = new List <IEnemy>();
            ISpawnPoint   spawnPoint = SelectRandomSpawnPoint();

            if (spawnPoint != null)
            {
                enemies.Add(new DefaultEnemy(spawnPoint.Position));
            }

            return(enemies);
        }
Exemple #7
0
        public void SpawnMany(T[] spawnedArray, int count, ISpawnPoint spawnPoint)
        {
            Assert.IsNotNull(spawnedArray);
            Assert.IsTrue(count <= spawnedArray.Length);

            CheckPoolableArraySize(count);
            pool.RetrieveMany(poolableArray, count);

            for (int i = 0; i < count; i++)
            {
                Initialize(spawnedArray, i, spawnPoint);
            }
        }
        /// <summary>
        /// Spawns the specified user
        /// </summary>
        /// <param name="gameUser">Game user</param>
        private void SpawnUser(IDeathmatchGameUser gameUser)
        {
            ISpawnPoint spawn_point = PlayerCharacterSpawnPoints.NextSpawnPoint;

            if (spawn_point != null)
            {
                gameUser.SetSpectatingState(false);
                gameUser.Heal();
                gameUser.SetPosition(spawn_point.Position);
                gameUser.SetRotation(spawn_point.Rotation);
                gameUser.SetVelocity(Vector3.Zero);
                gameUser.SetAngularVelocity(Vector3.Zero);
            }
        }
Exemple #9
0
        private void Initialize(Poolable <T> poolable, ISpawnPoint spawnPoint)
        {
            T spawned = poolable.Target;

            Assert.IsNotNull(spawned);

            spawnPoint.Apply(spawned);
            spawnedPoolables[spawned] = poolable;

            foreach (var listener in spawnListeners)
            {
                listener.OnSpawned(spawned);
            }
        }
 /// <summary>
 /// Constructs a deathmatch game resource
 /// </summary>
 public DeathmatchGameResource()
 {
     Assets.AddAssetLoader <string[], ICharacters>((data) => new Characters(data), () => new Characters());
     Assets.AddAssetLoader <RulesData, IRules>((data) => new Rules(new Vector3(data.OutOfMapPosition.X, data.OutOfMapPosition.Y, data.OutOfMapPosition.Z), new Quaternion(data.OutOfMapRotation.X, data.OutOfMapRotation.Y, data.OutOfMapRotation.Z, data.OutOfMapRotation.W), data.PlayerCharacterHealth, data.PlayerCharacterRespawnTime, data.RoundTime, data.WeaponPickupRadius, data.WeaponPickupRespawnTime), () => new Rules());
     Assets.AddAssetLoader <SpawnPointData[], ISpawnPoints>
     (
         (data) =>
     {
         ISpawnPoint[] spawn_points = new ISpawnPoint[data.Length];
         Parallel.For(0, spawn_points.Length, (index) =>
         {
             SpawnPointData spawn_point_data = data[index];
             if ((spawn_point_data == null) || !spawn_point_data.IsValid)
             {
                 throw new InvalidDataException("Spawn points contain invalid entries.");
             }
             spawn_points[index] = new SpawnPoint(new Vector3(spawn_point_data.Position.X, spawn_point_data.Position.Y, spawn_point_data.Position.Z), new Quaternion(spawn_point_data.Rotation.X, spawn_point_data.Rotation.Y, spawn_point_data.Rotation.Z, spawn_point_data.Rotation.W));
         });
         return(new SpawnPoints(spawn_points));
     },
         () => new SpawnPoints()
     );
     Assets.AddAssetLoader <WeaponData[], IWeapons>
     (
         (data) =>
     {
         IWeapon[] weapons = new IWeapon[data.Length];
         Parallel.For(0, weapons.Length, (index) =>
         {
             WeaponData weapon = data[index];
             if ((weapon == null) || !weapon.IsValid)
             {
                 throw new InvalidDataException("Weapons contain invalid weapon entries.");
             }
             weapons[index] = new Weapon(weapon.Name, weapon.Damage, weapon.UsageCount);
         });
         return(new Weapons(weapons));
     },
         () => new Weapons()
     );
 }
		/// <summary>
		/// Spawn the specified spawnPoint.
		/// </summary>
		/// <param name="spawnPoint">Spawn point.</param>
		/// <param name="rotate">If set to <c>true</c> rotate.</param>
		
		public void Spawn(ISpawnPoint spawnPoint, bool rotate = false) {
			
			// Set the position of the object to the spawn point

			SetPosition (spawnPoint.transform.position);
			
			// Set rotation
			if(rotate) {
				SetRotation(spawnPoint.transform.rotation);
			}
		}
Exemple #12
0
 public void SpawnMany(T[] spawnedArray, ISpawnPoint spawnPoint)
 {
     SpawnMany(spawnedArray, spawnedArray.Length, spawnPoint);
 }
Exemple #13
0
        public T Spawn()
        {
            ISpawnPoint spawnPoint = SelectSpawnPoint();

            return(Spawn(spawnPoint));
        }