Пример #1
0
    /// <summary>
    /// Set new random spawn position
    /// </summary>
    private void SetSpawnPosition()
    {
        SpawnPoint sp = SpawnPoints.GetRandomSpawnPoint();

        transform.position = sp.Position;
        transform.rotation = sp.Rotation;
    }
Пример #2
0
    private void SpawnOnCooldown()
    {
        if (Time.time >= lastSpawnTime)
        {
            var   selectedSpawnPoint = spawnPoints.GetRandomSpawnPoint();
            var   selectedEnemy      = spawnableEnemies.GetRandomEnemy();
            var   enemyDestination   = enemyDestinations.GetRandomDestination();
            float cooldownRandomness = UnityEngine.Random.Range(-cooldownRandomFactor, cooldownRandomFactor + 1);

            PlayBaseSpawningVfx();

            var spawned = Instantiate(
                selectedEnemy,
                selectedSpawnPoint.transform.position,
                selectedEnemy.transform.rotation
                );

            spawned.transform.parent = transform;
            spawned.SetDestination(enemyDestination);
            spawned.Invoke("PushTowardsPlayerBase", holdTime);

            lastSpawnTime = Time.time + spawnCooldown + holdTime + cooldownRandomness;
        }
    }
Пример #3
0
 private void SpawnEnemy()
 {
     Instantiate(enemies[Random.Range(0, enemies.Length)], SpawnPoints.GetRandomSpawnPoint().position, Quaternion.identity);
     // TODO: instantiate spawn particle effect
 }
        public static EntityTemplate Player(string workerId, byte[] args)
        {
            var client = EntityTemplate.GetWorkerAccessAttribute(workerId);

            var(spawnPosition, spawnYaw, spawnPitch) = SpawnPoints.GetRandomSpawnPoint();

            var serverResponse = new ServerResponse
            {
                Position = spawnPosition.ToVector3Int()
            };

            var rotationUpdate = new RotationUpdate
            {
                Yaw   = spawnYaw.ToInt1k(),
                Pitch = spawnPitch.ToInt1k()
            };

            var pos = new Position.Snapshot {
                Coords = Coordinates.FromUnityVector(spawnPosition)
            };
            var serverMovement = new ServerMovement.Snapshot {
                Latest = serverResponse
            };
            var clientMovement = new ClientMovement.Snapshot {
                Latest = new ClientRequest()
            };
            var clientRotation = new ClientRotation.Snapshot {
                Latest = rotationUpdate
            };
            var shootingComponent = new ShootingComponent.Snapshot();
            var gunComponent      = new GunComponent.Snapshot {
                GunId = PlayerGunSettings.DefaultGunIndex
            };
            var gunStateComponent = new GunStateComponent.Snapshot {
                IsAiming = false
            };
            var healthComponent = new HealthComponent.Snapshot
            {
                Health    = PlayerHealthSettings.MaxHealth,
                MaxHealth = PlayerHealthSettings.MaxHealth,
            };

            var healthRegenComponent = new HealthRegenComponent.Snapshot
            {
                CooldownSyncInterval = PlayerHealthSettings.SpatialCooldownSyncInterval,
                DamagedRecently      = false,
                RegenAmount          = PlayerHealthSettings.RegenAmount,
                RegenCooldownTimer   = PlayerHealthSettings.RegenAfterDamageCooldown,
                RegenInterval        = PlayerHealthSettings.RegenInterval,
                RegenPauseTime       = 0,
            };

            var sessionQuery  = InterestQuery.Query(Constraint.Component <Improbable.Gdk.Session.Session.Component>());
            var checkoutQuery = InterestQuery.Query(Constraint.RelativeCylinder(150));

            var interestTemplate  = InterestTemplate.Create().AddQueries <ClientMovement.Component>(sessionQuery, checkoutQuery);
            var interestComponent = interestTemplate.ToSnapshot();

            var playerName = Encoding.ASCII.GetString(args);

            var playerStateComponent = new PlayerState.Snapshot
            {
                Name   = playerName,
                Kills  = 0,
                Deaths = 0,
            };

            var template = new EntityTemplate();

            template.AddComponent(pos, WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot {
                EntityType = "Player"
            }, WorkerUtils.UnityGameLogic);
            template.AddComponent(serverMovement, WorkerUtils.UnityGameLogic);
            template.AddComponent(clientMovement, client);
            template.AddComponent(clientRotation, client);
            template.AddComponent(shootingComponent, client);
            template.AddComponent(gunComponent, WorkerUtils.UnityGameLogic);
            template.AddComponent(gunStateComponent, client);
            template.AddComponent(healthComponent, WorkerUtils.UnityGameLogic);
            template.AddComponent(healthRegenComponent, WorkerUtils.UnityGameLogic);
            template.AddComponent(playerStateComponent, WorkerUtils.UnityGameLogic);
            template.AddComponent(interestComponent, WorkerUtils.UnityGameLogic);

            PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, WorkerUtils.UnityGameLogic);

            template.SetReadAccess(WorkerUtils.UnityClient, WorkerUtils.UnityGameLogic, WorkerUtils.MobileClient);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);

            return(template);
        }
Пример #5
0
        public static EntityTemplate Player(EntityId entityId, string workerId, byte[] args)
        {
            var client = EntityTemplate.GetWorkerAccessAttribute(workerId);

            var(spawnPosition, spawnYaw, spawnPitch) = SpawnPoints.GetRandomSpawnPoint();

            var serverResponse = new ServerResponse
            {
                Position = spawnPosition.ToVector3Int()
            };

            var rotationUpdate = new RotationUpdate
            {
                Yaw   = spawnYaw.ToInt1k(),
                Pitch = spawnPitch.ToInt1k()
            };

            var pos = new Position.Snapshot {
                Coords = Coordinates.FromUnityVector(spawnPosition)
            };
            var serverMovement = new ServerMovement.Snapshot {
                Latest = serverResponse
            };
            var clientMovement = new ClientMovement.Snapshot {
                Latest = new ClientRequest()
            };
            var clientRotation = new ClientRotation.Snapshot {
                Latest = rotationUpdate
            };
            var shootingComponent = new ShootingComponent.Snapshot();
            var gunComponent      = new GunComponent.Snapshot {
                GunId = PlayerGunSettings.DefaultGunIndex
            };
            var gunStateComponent = new GunStateComponent.Snapshot {
                IsAiming = false
            };
            var healthComponent = new HealthComponent.Snapshot
            {
                Health    = PlayerHealthSettings.MaxHealth,
                MaxHealth = PlayerHealthSettings.MaxHealth,
            };

            var healthRegenComponent = new HealthRegenComponent.Snapshot
            {
                CooldownSyncInterval = PlayerHealthSettings.SpatialCooldownSyncInterval,
                DamagedRecently      = false,
                RegenAmount          = PlayerHealthSettings.RegenAmount,
                RegenCooldownTimer   = PlayerHealthSettings.RegenAfterDamageCooldown,
                RegenInterval        = PlayerHealthSettings.RegenInterval,
                RegenPauseTime       = 0,
            };

            var template = new EntityTemplate();

            template.AddComponent(pos, WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot {
                EntityType = "Player"
            }, WorkerUtils.UnityGameLogic);
            template.AddComponent(serverMovement, WorkerUtils.UnityGameLogic);
            template.AddComponent(clientMovement, client);
            template.AddComponent(clientRotation, client);
            template.AddComponent(shootingComponent, client);
            template.AddComponent(gunComponent, WorkerUtils.UnityGameLogic);
            template.AddComponent(gunStateComponent, client);
            template.AddComponent(healthComponent, WorkerUtils.UnityGameLogic);
            template.AddComponent(healthRegenComponent, WorkerUtils.UnityGameLogic);

            PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, WorkerUtils.UnityGameLogic);

            const int serverRadius = 150;
            var       clientRadius = workerId.Contains(WorkerUtils.MobileClient) ? 60 : 150;

            // Position, Metadata, OwningWorker and ServerMovement are included in all queries, since these
            // components are required by the GameObject creator.

            // HealthComponent is needed by the LookAtRagdoll script for respawn behaviour.
            // GunComponent is needed by the GunManager script.
            var clientSelfInterest = InterestQuery.Query(Constraint.EntityId(entityId)).FilterResults(new[]
            {
                Position.ComponentId, Metadata.ComponentId, OwningWorker.ComponentId,
                ServerMovement.ComponentId, HealthComponent.ComponentId, GunComponent.ComponentId
            });

            // ClientRotation is used for rendering other players.
            // GunComponent is required by the GunManager script.
            // GunStateComponent and ShootingComponent are needed for rendering other players' shots.
            var clientRangeInterest = InterestQuery.Query(Constraint.RelativeCylinder(clientRadius)).FilterResults(new[]
            {
                Position.ComponentId, Metadata.ComponentId, OwningWorker.ComponentId,
                ServerMovement.ComponentId, ClientRotation.ComponentId, HealthComponent.ComponentId,
                GunComponent.ComponentId, GunStateComponent.ComponentId, ShootingComponent.ComponentId
            });

            // ClientMovement is used by the ServerMovementDriver script.
            // ShootingComponent is used by the ServerShootingSystem.
            var serverSelfInterest = InterestQuery.Query(Constraint.EntityId(entityId)).FilterResults(new[]
            {
                ClientMovement.ComponentId, ShootingComponent.ComponentId
            });

            // ClientRotation is used for driving player proxies.
            // HealthComponent is required by the VisiblityAndCollision script.
            // ShootingComponent is used by the ServerShootingSystem.
            var serverRangeInterest = InterestQuery.Query(Constraint.RelativeCylinder(serverRadius)).FilterResults(new[]
            {
                Position.ComponentId, Metadata.ComponentId, OwningWorker.ComponentId,
                ServerMovement.ComponentId, ClientRotation.ComponentId, HealthComponent.ComponentId,
                ShootingComponent.ComponentId
            });

            var interest = InterestTemplate.Create()
                           .AddQueries <ClientMovement.Component>(clientSelfInterest, clientRangeInterest)
                           .AddQueries <ServerMovement.Component>(serverSelfInterest, serverRangeInterest);

            template.AddComponent(interest.ToSnapshot());

            template.SetReadAccess(WorkerUtils.UnityClient, WorkerUtils.UnityGameLogic, WorkerUtils.MobileClient);

            return(template);
        }