예제 #1
0
        public static EntityTemplate CreatePlayerEntityTemplate(EntityId entityId, string workerId, byte[] serializedArguments)
        {
            var clientAttribute = EntityTemplate.GetWorkerAccessAttribute(workerId);
            var serverAttribute = UnityGameLogicConnector.WorkerType;

            var position = new Vector3(0, 1f, 0);
            var coords   = Coordinates.FromUnityVector(position);

            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(coords), clientAttribute);
            template.AddComponent(new Metadata.Snapshot("Player"), serverAttribute);

            PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, serverAttribute);
            TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, clientAttribute, position);

            const int serverRadius = 500;
            var       clientRadius = workerId.Contains(MobileClientWorkerConnector.WorkerType) ? 100 : 500;

            var serverQuery = InterestQuery.Query(Constraint.RelativeCylinder(serverRadius));
            var clientQuery = InterestQuery.Query(Constraint.RelativeCylinder(clientRadius));

            var interest = InterestTemplate.Create()
                           .AddQueries <Metadata.Component>(serverQuery)
                           .AddQueries <Position.Component>(clientQuery);

            template.AddComponent(interest.ToSnapshot(), serverAttribute);

            template.SetReadAccess(UnityClientConnector.WorkerType, MobileClientWorkerConnector.WorkerType, serverAttribute);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute);

            return(template);
        }
 /// <summary>
 ///     Adds the SpatialOS components used by the player lifecycle module to an entity template.
 /// </summary>
 /// <param name="template">The entity template to add player lifecycle components to.</param>
 /// <param name="clientWorkerId">The ID of the client-worker.</param>
 /// <param name="serverAccess">The server-worker write access attribute.</param>
 public static void AddPlayerLifecycleComponents(EntityTemplate template,
                                                 string clientWorkerId,
                                                 string serverAccess)
 {
     template.AddComponent(new PlayerHeartbeatClient.Snapshot(),
                           EntityTemplate.GetWorkerAccessAttribute(clientWorkerId));
     template.AddComponent(new PlayerHeartbeatServer.Snapshot(), serverAccess);
     template.AddComponent(new OwningWorker.Snapshot(clientWorkerId), serverAccess);
 }
예제 #3
0
 public AdvancedEntityPipeline(WorkerInWorld worker, string authPlayer, string nonAuthPlayer,
                               IEntityGameObjectCreator fallback)
 {
     this.worker         = worker;
     this.fallback       = fallback;
     workerIdAttribute   = EntityTemplate.GetWorkerAccessAttribute(worker.WorkerId);
     cachedAuthPlayer    = Resources.Load <GameObject>(authPlayer);
     cachedNonAuthPlayer = Resources.Load <GameObject>(nonAuthPlayer);
 }
예제 #4
0
 public EntityPipeline(
     Worker worker,
     GameObject authPlayerPrefab,
     GameObject nonAuthPlayerPrefab,
     IEntityGameObjectCreator fallback)
 {
     _worker              = worker;
     _fallback            = fallback;
     _authPlayerPrefab    = authPlayerPrefab;
     _nonAuthPlayerPrefab = nonAuthPlayerPrefab;
     _workerIdAttribute   = EntityTemplate.GetWorkerAccessAttribute(_worker.WorkerId);
 }
        public static EntityTemplate CreateAdvancedUnitEntityTemplate(string workerId, Coordinates coords, UnitSide side)
        {
            bool   isPlayer = workerId != null;
            string controllAttribute;

            if (isPlayer)
            {
                controllAttribute = EntityTemplate.GetWorkerAccessAttribute(workerId);
            }
            else
            {
                controllAttribute = WorkerUtils.UnityGameLogic;
            }

            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot {
                Coords = coords
            }, controllAttribute);
            template.AddComponent(new Metadata.Snapshot(isPlayer ? "Player": "AdvancedUnit"), WorkerUtils.UnityGameLogic);
            template.AddComponent(new BulletComponent.Snapshot(), controllAttribute);
            template.AddComponent(new AdvancedUnitController.Snapshot(), controllAttribute);
            template.AddComponent(new BaseUnitHealth.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new GunComponent.Snapshot {
                GunsDic = new Dictionary <PosturePoint, GunInfo>()
            }, WorkerUtils.UnityGameLogic);
            template.AddComponent(new FuelComponent.Snapshot(), WorkerUtils.UnityGameLogic);

            if (isPlayer)
            {
                template.AddComponent(new AdvancedPlayerInput.Snapshot(), controllAttribute);
                template.AddComponent(new PlayerInfo.Snapshot {
                    ClientWorkerId = workerId
                }, controllAttribute);
            }
            else
            {
                template.AddComponent(new AdvancedUnmannedInput.Snapshot(), controllAttribute);
            }

            template.AddComponent(new BaseUnitStatus.Snapshot {
                Type = UnitType.Advanced, Side = side, State = UnitState.Alive
            }, WorkerUtils.UnityGameLogic);

            TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, controllAttribute);
            PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, WorkerUtils.UnityGameLogic);

            template.SetReadAccess(UnityClientConnector.WorkerType, MobileClientWorkerConnector.WorkerType, WorkerUtils.UnityGameLogic);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);

            return(template);
        }
예제 #6
0
        public static EntityTemplate CreatePlayerEntityTemplate(EntityId entityId, string clientWorkerId, byte[] playerCreationArguments)
        {
            var clientAttribute = EntityTemplate.GetWorkerAccessAttribute(clientWorkerId);

            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(), clientAttribute);
            template.AddComponent(new Metadata.Snapshot("Character"), WorkerUtils.UnityGameLogic);
            template.AddComponent(new PlayerInput.Snapshot(), clientAttribute);
            template.AddComponent(new Launcher.Snapshot(100, 0), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Score.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new CubeSpawner.Snapshot(new List <EntityId>()), WorkerUtils.UnityGameLogic);

            TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, clientAttribute);
            PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, clientWorkerId, WorkerUtils.UnityGameLogic);

            var clientSelfInterest = InterestQuery.Query(Constraint.EntityId(entityId)).FilterResults(new[]
            {
                Position.ComponentId, Metadata.ComponentId, TransformInternal.ComponentId, CubeSpawner.ComponentId,
                Score.ComponentId, Launcher.ComponentId
            });

            var clientRangeInterest = InterestQuery.Query(Constraint.RelativeCylinder(radius: CheckoutRadius))
                                      .FilterResults(new[]
            {
                Position.ComponentId, Metadata.ComponentId, TransformInternal.ComponentId, Collisions.ComponentId,
                SpinnerColor.ComponentId, SpinnerRotation.ComponentId, CubeColor.ComponentId, Score.ComponentId,
                Launchable.ComponentId
            });

            var serverSelfInterest = InterestQuery.Query(Constraint.EntityId(entityId)).FilterResults(new[]
            {
                Position.ComponentId, Metadata.ComponentId, TransformInternal.ComponentId, Score.ComponentId
            });

            var serverRangeInterest = InterestQuery.Query(Constraint.RelativeCylinder(radius: CheckoutRadius))
                                      .FilterResults(new[]
            {
                Position.ComponentId, Metadata.ComponentId, TransformInternal.ComponentId, Collisions.ComponentId,
                SpinnerColor.ComponentId, SpinnerRotation.ComponentId, Score.ComponentId
            });

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

            template.AddComponent(interest.ToSnapshot());

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

            return(template);
        }
        public static EntityTemplate CreatePlayerEntityTemplate(EntityId entityId, string workerId, byte[] serializedArguments)
        {
            var clientAttribute = EntityTemplate.GetWorkerAccessAttribute(workerId);
            var serverAttribute = WorkerTypes.UnityGameLogic;

            var position = new Vector3(0, 1f, 0);
            var coords   = Coordinates.FromUnityVector(position);

            var template = new EntityTemplate();

            PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, serverAttribute);
            template.AddComponent(new Position.Snapshot(coords), serverAttribute);
            template.AddComponent(new Metadata.Snapshot("Player"), serverAttribute);
            template.AddComponent(new ServerUpdate.Snapshot(), serverAttribute);
            template.AddComponent(new ClientUpdate.Snapshot(), clientAttribute);

            var radius = 100;

            var clientSelfInterest = InterestQuery.Query(Constraint.EntityId(entityId)).FilterResults(new[]
            {
                ClientUpdate.ComponentId, ServerUpdate.ComponentId, Metadata.ComponentId, OwningWorker.ComponentId, Position.ComponentId
            });

            var clientRangeInterest = InterestQuery.Query(Constraint.RelativeCylinder(radius)).FilterResults(new[]
            {
                Metadata.ComponentId, Position.ComponentId
            });

            var serverSelfInterest = InterestQuery.Query(Constraint.EntityId(entityId)).FilterResults(new[]
            {
                ServerUpdate.ComponentId, ClientUpdate.ComponentId, Metadata.ComponentId, OwningWorker.ComponentId, Position.ComponentId
            });

            var serverRangeInterest = InterestQuery.Query(Constraint.RelativeCylinder(radius)).FilterResults(new[]
            {
                Metadata.ComponentId, Position.ComponentId
            });

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

            template.AddComponent(interest.ToSnapshot(), serverAttribute);

            template.SetReadAccess(WorkerTypes.UnityClient, serverAttribute);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute);

            return(template);
        }
예제 #8
0
        private static EntityTemplate CreatePlayerEntityTemplate(string workerId, byte[] serializedArguments)
        {
            var clientAttribute = EntityTemplate.GetWorkerAccessAttribute(workerId);
            var serverAttribute = WorkerType;

            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(), clientAttribute);
            template.AddComponent(new Metadata.Snapshot("Player"), serverAttribute);
            TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, clientAttribute);
            PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, serverAttribute);

            template.SetReadAccess(UnityClientConnector.WorkerType, AndroidClientWorkerConnector.WorkerType, iOSClientWorkerConnector.WorkerType, serverAttribute);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute);

            return(template);
        }
예제 #9
0
        public static EntityTemplate CreateCubeEntityTemplate(string workerId, byte[] serializedArguments)
        {
            var clientAttribute = EntityTemplate.GetWorkerAccessAttribute(workerId);
            var serverAttribute = UnityGameLogicConnector.WorkerType;

            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(), clientAttribute);
            template.AddComponent(new Metadata.Snapshot("Cube"), serverAttribute);

            //TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, serverAttribute);

            template.SetReadAccess(UnityGameLogicConnector.WorkerType, UnityClientConnector.WorkerType, MobileClientWorkerConnector.WorkerType, serverAttribute);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute);

            return(template);
        }
        public static EntityTemplate CreatePlayerEntityTemplate(string workerId, byte[] serializedArguments)
        {
            var clientAttribute = EntityTemplate.GetWorkerAccessAttribute(workerId);
            var serverAttribute = UnityGameLogicConnector.WorkerType;

            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(), serverAttribute);
            template.AddComponent(new Metadata.Snapshot("Player"), serverAttribute);
            template.AddComponent(new Vitruvius.Generated.Player.PlayerAchors.Snapshot(), clientAttribute);
            template.AddComponent(new Vitruvius.Generated.Player.ClientPlayerMovementUpdate.Snapshot(), clientAttribute);
            PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, serverAttribute);

            template.SetReadAccess(UnityClientConnector.WorkerType, MobileClientWorkerConnector.WorkerType, serverAttribute);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute);

            return(template);
        }
예제 #11
0
        public static EntityTemplate CreatePlayerEntityTemplate(EntityId id, string workerId, byte[] serializedArguments)
        {
            IList <Vector3> spawnPoints = new List <Vector3>();

            spawnPoints.Add(new Vector3(-35, 0, 20));
            spawnPoints.Add(new Vector3(-37, 0, -35));
            spawnPoints.Add(new Vector3(39, 0, 33));
            spawnPoints.Add(new Vector3(23, 0, -35));
            var     clientAttribute = EntityTemplate.GetWorkerAccessAttribute(workerId);
            var     serverAttribute = UnityGameLogicConnector.WorkerType;
            Vector3 position        = spawnPoints[Random.Range(0, 3)];

            var turretRotationComponent = new TurretRotation.Snapshot();
            var colorComponent          = new TankColor.Snapshot();
            var healthComponent         = new Health.Snapshot(GameConstants.MaxHealth);
            var weaponsComponent        = new Weapons.Snapshot(GameConstants.MachineGunDamage, GameConstants.CannonDamage);
            var weaponsFxComponent      = new WeaponsFx.Snapshot();
            var fireCannon   = new FireCannonball.Snapshot();
            var tankVelocity = new TankVelocityAndRotation.Snapshot();

            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(position.ToCoordinates()), clientAttribute);
            template.AddComponent(new Metadata.Snapshot("Player"), serverAttribute);

            template.AddComponent(turretRotationComponent, clientAttribute);
            template.AddComponent(colorComponent, clientAttribute);
            template.AddComponent(healthComponent, serverAttribute);
            template.AddComponent(weaponsComponent, serverAttribute);
            template.AddComponent(weaponsFxComponent, clientAttribute);
            template.AddComponent(fireCannon, clientAttribute);
            template.AddComponent(tankVelocity, clientAttribute);
            template.AddComponent(CreateQuery().ToSnapshot(), clientAttribute);


            PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, serverAttribute);
            TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, clientAttribute, position);

            template.SetReadAccess(UnityClientConnector.WorkerType, MobileClientWorkerConnector.WorkerType, serverAttribute, UnityHealerConnector.WorkerType);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute);

            return(template);
        }
예제 #12
0
        public static EntityTemplate CreatePlayerEntityTemplate(string clientWorkerId, byte[] playerCreationArguments)
        {
            var clientAttribute = EntityTemplate.GetWorkerAccessAttribute(clientWorkerId);

            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(), clientAttribute);
            template.AddComponent(new Metadata.Snapshot("Character"), WorkerUtils.UnityGameLogic);
            template.AddComponent(new PlayerInput.Snapshot(), clientAttribute);
            template.AddComponent(new Launcher.Snapshot(100, 0), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Score.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new CubeSpawner.Snapshot(new List <EntityId>()), WorkerUtils.UnityGameLogic);

            TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, clientAttribute);
            PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, clientWorkerId, WorkerUtils.UnityGameLogic);

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

            return(template);
        }
예제 #13
0
        private static EntityTemplate CreatePlayerEntityTemplate(EntityId entityId, string workerId, byte[] serializedArguments)
        {
            var clientAttribute = EntityTemplate.GetWorkerAccessAttribute(workerId);

            var initInfo = SerializeUtils.DeserializeArguments <PlayerInitInfo>(serializedArguments);

            return(BaseUnitTemplate.CreateAdvancedUnitEntityTemplate(workerId, initInfo.pos.ToCoordinates(), initInfo.side));
            //var template = new EntityTemplate();
            //template.AddComponent(new Position.Snapshot { Coords = initInfo.pos.ToCoordinates() }, clientAttribute);
            //template.AddComponent(new Metadata.Snapshot("Player"), serverAttribute);
            //template.AddComponent(new BulletComponent.Snapshot(), clientAttribute);
            //template.AddComponent(new PlayerInput.Snapshot(), clientAttribute);
            //template.AddComponent(new BaseUnitStatus.Snapshot { Side = initInfo.side }, serverAttribute);

            //TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, clientAttribute);
            //PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, serverAttribute);

            //template.SetReadAccess(UnityClientConnector.WorkerType, MobileClientWorkerConnector.WorkerType, serverAttribute);
            //template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute);

            //return template;
        }
        private static EntityTemplate CreatePlayerEntityTemplate(string workerId, byte[] serializedArguments)
        {
            var clientAttribute = EntityTemplate.GetWorkerAccessAttribute(workerId);

            var resourceQuery    = InterestQuery.Query(Constraint.RelativeCylinder(50.0));
            var interestTemplate = InterestTemplate.Create();

            interestTemplate.AddQueries <Position.Component>(resourceQuery);

            var template = new EntityTemplate();

            // TODO: Don't give the client authority over the Position component.
            template.AddComponent(new Position.Snapshot(), clientAttribute);
            template.AddComponent(new Metadata.Snapshot("Player"), WorkerType);
            template.AddComponent(interestTemplate.ToSnapshot(), WorkerType);
            PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, WorkerType);

            template.SetReadAccess(WorkerUtils.AllWorkers);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerType);

            return(template);
        }
예제 #15
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);
        }
        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.ToIntAbsolute()
            };

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

            var pos = new Position.Snapshot {
                Coords = spawnPosition.ToSpatialCoordinates()
            };
            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 <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 playerResComponent      = new Pickups.PlayerRes.Snapshot(0);
            var soldierManagerComponent = new Soldiers.SoldierManager.Snapshot();


            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);

            template.AddComponent(playerResComponent, WorkerUtils.UnityGameLogic);
            template.AddComponent(soldierManagerComponent, WorkerUtils.UnityGameLogic);


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

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

            return(template);
        }
        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.ToIntAbsolute()
            };

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

            var pos = new Position.Snapshot {
                Coords = spawnPosition.ToSpatialCoordinates()
            };
            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);

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

            return(template);
        }