public static EntityTemplate CreatePlayerEntityTemplate(string workerId, Improbable.Vector3f position) { var clientAttribute = $"workerId:{workerId}"; var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot(), clientAttribute); template.AddComponent(new Metadata.Snapshot { EntityType = "User" }, UnityGameLogicConnector.WorkerType); template.AddComponent(new Player.PlayerInput.Snapshot(), clientAttribute); /* * template.AddComponent(new Launcher.Snapshot { EnergyLeft = 100, RechargeTimeLeft = 0 }, * UnityGameLogicConnector.WorkerType); * template.AddComponent(new Score.Snapshot(), WorkerUtils.UnityGameLogic); * template.AddComponent(new CubeSpawner.Snapshot { SpawnedCubes = new List<EntityId>() }, * UnityGameLogicConnector.WorkerType); */ template.AddComponent(new Player.PlayerAuth.Snapshot { IsAuthed = false, PlayerName = "unauthorized player" }, "GRPCManager"); TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, clientAttribute); PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, clientAttribute, UnityGameLogicConnector.WorkerType); template.SetReadAccess(UnityClientConnector.WorkerType, UnityGameLogicConnector.WorkerType, "GRPCManager"); template.SetComponentWriteAccess(EntityAcl.ComponentId, UnityGameLogicConnector.WorkerType); return(template); }
static public EntityTemplate CreatePlayerEntityTemplate(string workerId, byte[] playerCreationArguments) { //Decide spawn position GameObject[] playerSpawnPoints = GameObject.FindGameObjectsWithTag("SpawnPoint"); Vector3 spawnPos = playerSpawnPoints[Random.Range(0, playerSpawnPoints.Length - 1)].transform.position; //Setup SpatialOS entity and components var clientAttribute = $"workerId:{workerId}"; var serverAttribute = WorkerUtils.UnityGameLogic; var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot { Coords = new Coordinates(spawnPos.x, spawnPos.y, spawnPos.z) }, serverAttribute); template.AddComponent(new Metadata.Snapshot { EntityType = "Player" }, serverAttribute); template.AddComponent(new PlayerInput.Snapshot { TargetPosition = Vector3f.Zero }, clientAttribute); template.AddComponent(new PlayerHealth.Snapshot { Health = 100 }, serverAttribute); template.AddComponent(new Chat.Snapshot(), WorkerUtils.ChatManager); TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, serverAttribute); PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, clientAttribute, serverAttribute); template.SetReadAccess(WorkerUtils.UnityClient, WorkerUtils.ChatManager, /*AndroidClientWorkerConnector.WorkerType, iOSClientWorkerConnector.WorkerType,*/ serverAttribute); template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute); return(template); }
public static EntityTemplate CreatePlayerEntityTemplate(string workerId, Improbable.Vector3f position) { var clientAttribute = $"workerId:{workerId}"; var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot(), clientAttribute); template.AddComponent(new Metadata.Snapshot { EntityType = "Character" }, WorkerUtils.UnityGameLogic); template.AddComponent(new PlayerInput.Snapshot(), clientAttribute); template.AddComponent(new Launcher.Snapshot { EnergyLeft = 100, RechargeTimeLeft = 0 }, WorkerUtils.UnityGameLogic); template.AddComponent(new Score.Snapshot(), WorkerUtils.UnityGameLogic); template.AddComponent(new CubeSpawner.Snapshot { SpawnedCubes = new List <EntityId>() }, WorkerUtils.UnityGameLogic); TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, clientAttribute); PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, clientAttribute, WorkerUtils.UnityGameLogic); template.SetReadAccess(WorkerUtils.UnityClient, WorkerUtils.UnityGameLogic); template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic); return(template); }
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); }
// Defines the template for the PlayerShip entity. public static EntityTemplate CreatePlayerShipTemplate(string clientWorkerId, byte[] serializedArguments) { var clientAttribute = EntityTemplate.GetWorkerAccessAttribute(clientWorkerId);// CommonRequirementSets.SpecificClientOnly(_clientWorkerId); //set position to random for now var position = new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f)); var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot() { Coords = position.ToCoordinates() }, WorkerUtils.UnityGameLogic); template.AddComponent(new Metadata.Snapshot() { EntityType = SimulationSettings.PlayerShipPrefabName }, WorkerUtils.UnityGameLogic); template.AddComponent(new ShipControls.Snapshot(), clientAttribute); template.AddComponent(new ClientAuthorityCheck.Snapshot(), clientAttribute); PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, clientWorkerId, WorkerUtils.UnityGameLogic); TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, WorkerUtils.UnityGameLogic, location: position); template.SetReadAccess(WorkerUtils.AllWorkerAttributes); template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic); return(template); }
public static EntityTemplate Player(string workerType, byte[] args) { //TODO: Add all gameplay components var client = $"workerId:{workerType}"; var template = CreateDefaultEntity(EntityUtils.PlayerEntityType); var healthComp = new HealthComponent.Snapshot( health: PlayerHealthConfig.MaxHealth, maxHealth: PlayerHealthConfig.MaxHealth); var healthRegenComponent = new HealthRegenComponent.Snapshot { CooldownSyncInterval = PlayerHealthConfig.SpatialCooldownSyncInterval, DamagedRecently = false, RegenAmount = PlayerHealthConfig.RegenAmount, RegenCooldownTimer = PlayerHealthConfig.RegenAfterDamageCooldown, RegenInterval = PlayerHealthConfig.RegenInterval, RegenPauseTime = 0, }; template.AddComponent(healthComp, WorkerUtils.UnityGameLogic); template.AddComponent(healthRegenComponent, WorkerUtils.UnityGameLogic); PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerType, client, WorkerUtils.UnityGameLogic); template.SetReadAccess(WorkerUtils.UnityClient, WorkerUtils.UnityGameLogic); return(template); }
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 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); }
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); }
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); }
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(), clientAttribute); template.AddComponent(new Metadata.Snapshot("Player"), serverAttribute); PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, serverAttribute); template.SetReadAccess(UnityClientConnector.WorkerType, MobileClientWorkerConnector.WorkerType, serverAttribute); template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute); return(template); }
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); }
private static EntityTemplate CreatePlayerEntityTemplate(string workerId, Improbable.Vector3f position) { var clientAttribute = $"workerId:{workerId}"; var serverAttribute = WorkerType; var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot(), clientAttribute); template.AddComponent(new Metadata.Snapshot { EntityType = "Player" }, serverAttribute); TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, clientAttribute); PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, clientAttribute, serverAttribute); template.SetReadAccess(UnityClientConnector.WorkerType, AndroidClientWorkerConnector.WorkerType, iOSClientWorkerConnector.WorkerType, serverAttribute); template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute); return(template); }
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); }
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); }
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); }
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); }