private static void AddPlayerSpawner(Snapshot snapshot) { var serverAttribute = UnityGameLogicConnector.WorkerType; var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot(), serverAttribute); template.AddComponent(new Metadata.Snapshot("PlayerCreator"), serverAttribute); template.AddComponent(new Persistence.Snapshot(), serverAttribute); template.AddComponent(new PlayerCreator.Snapshot(), serverAttribute); var query = InterestQuery.Query(Constraint.RelativeCylinder(500)); var interest = InterestTemplate.Create() .AddQueries <Position.Component>(query); template.AddComponent(interest.ToSnapshot(), serverAttribute); template.SetReadAccess( UnityClientConnector.WorkerType, UnityGameLogicConnector.WorkerType, MobileClientWorkerConnector.WorkerType); template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute); snapshot.AddEntity(template); }
private static void AddHealer(Snapshot snapshot) { var healerAttribute = UnityHealerConnector.WorkerType; // var serverAttribute = UnityGameLogicConnector.WorkerType; var healer = new Healer.HealValue.Snapshot(GameConstants.HealerValue); var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot(new Coordinates(6, 2, 0)), healerAttribute); template.AddComponent(new Metadata.Snapshot("Healer"), healerAttribute); template.AddComponent(new Persistence.Snapshot(), healerAttribute); template.AddComponent(healer, healerAttribute); // template.AddComponent(new Position.Snapshot(new Coordinates(6, 2, 0)), serverAttribute); // template.AddComponent(new Metadata.Snapshot("Healer"), serverAttribute); // template.AddComponent(new Persistence.Snapshot(), serverAttribute); // template.AddComponent(healer, serverAttribute); template.SetReadAccess( UnityClientConnector.WorkerType, UnityGameLogicConnector.WorkerType, MobileClientWorkerConnector.WorkerType, UnityHealerConnector.WorkerType); template.SetComponentWriteAccess(EntityAcl.ComponentId, healerAttribute); // template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute); snapshot.AddEntity(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 = "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(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); }
public static EntityTemplate Drone(AxialCoordinate position, string playerId) { // Calculate the world position based off the grid position. var worldPosition = HexUtils.GridToWorld(position); var entityTemplate = new EntityTemplate(); entityTemplate.AddComponent( new Drone.Snapshot { Owner = playerId, CommandQueue = new List <Command>() }, WorkerUtils.UnityGameLogic); entityTemplate.AddComponent( new Position.Snapshot(new Coordinates { X = worldPosition.x, Z = worldPosition.y }), WorkerUtils.UnityGameLogic); entityTemplate.AddComponent( new PlayerInventory.Snapshot(0, 0), WorkerUtils.UnityGameLogic); entityTemplate.AddComponent(new Metadata.Snapshot("Drone"), WorkerUtils.UnityGameLogic); entityTemplate.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic); entityTemplate.SetReadAccess(WorkerUtils.AllWorkers); entityTemplate.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic); return(entityTemplate); }
private EntityTemplate GetTemplate() { var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot(), "some-worker"); template.AddComponent(new Metadata.Snapshot("AReferenceType"), "some-worker"); return(template); }
private static EntityTemplate GetTemplate() { var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot(), "worker"); template.AddComponent(new TestCommands.Snapshot(), "worker"); return(template); }
private EntityTemplate GetTemplate(string metadata) { var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot()); template.AddComponent(new Metadata.Snapshot(metadata)); return(template); }
private EntityTemplate GetOwnedEntity(string workerId) { var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot(), "worker"); template.AddComponent(new OwningWorker.Snapshot(workerId), "worker"); return(template); }
private void CreateEntity() { var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot(), "worker"); template.AddComponent(new DependentDataComponent.Snapshot(), "worker"); connectionHandler.CreateEntity(EntityId, template); }
public override void AddComponent(EntityTemplate template) { bool isDominatable = false; bool isFactory = false; bool isResource = false; SpawnType spawnType = SpawnType.None; switch (attribute) { case HexAttribute.Field: isDominatable = true; break; case HexAttribute.ForwardBase: isDominatable = true; isFactory = true; spawnType = SpawnType.Revive; break; case HexAttribute.CentralBase: isFactory = true; spawnType = SpawnType.Start; isResource = true; break; case HexAttribute.NotBelong: break; } if (isDominatable) { template.AddComponent(new DominationStamina.Snapshot().DefaultSnapshot(), writeAccess); } if (isFactory) { template.AddComponent(new UnitFactory.Snapshot().DefaultSnapshot(), writeAccess); } if (isFactory || isDominatable) { template.AddComponent(new HexFacility.Snapshot(hexIndex: hexIndex), writeAccess); } if (spawnType != SpawnType.None) { template.AddComponent(new SpawnPoint.Snapshot { Type = spawnType }, writeAccess); } if (isResource) { template.AddComponent(new HexPowerResource.Snapshot { Level = 1 }, writeAccess); } }
/// <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); }
public override void Setup() { base.Setup(); var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot(), "TestWorkerType"); template.AddComponent(new TransformInternal.Snapshot(), "TestWorkerType"); ConnectionHandler.CreateEntity(EntityId, template); ReceiveSystem.Update(); }
public static EntityTemplate CreatePlayerSpawnerEntityTemplate(Coordinates playerSpawnerLocation) { var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot(playerSpawnerLocation), WorkerUtils.UnityGameLogic); template.AddComponent(new Metadata.Snapshot("PlayerCreator"), WorkerUtils.UnityGameLogic); template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic); template.AddComponent(new PlayerCreator.Snapshot(), WorkerUtils.UnityGameLogic); return(template); }
public void AddComponent_overrides_preexisting_components() { var entityTemplate = new EntityTemplate(); entityTemplate.AddComponent(new Position.Snapshot(new Coordinates(10, 10, 10)), "worker"); entityTemplate.AddComponent(new PlayerHeartbeatClient.Snapshot(), "test"); var snapshot = entityTemplate.GetEntitySnapshot(); snapshot.AddComponentSnapshot(new Position.Snapshot(new Coordinates(100, 100, 100))); Assert.IsTrue(snapshot.TryGetComponentSnapshot <Position.Snapshot>(out var outPosition)); Assert.AreEqual(outPosition.Coords.X, 100, Double.Epsilon); }
private static void AddWorldTimer(Snapshot snapshot, Coordinates location) { var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot(location), WorkerUtils.UnityGameLogic); template.AddComponent(new Metadata.Snapshot("WorldTimer"), WorkerUtils.UnityGameLogic); template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic); template.AddComponent(new WorldTimer.Snapshot(), WorkerUtils.UnityGameLogic); template.SetReadAccess(WorkerUtils.UnityGameLogic, WorkerUtils.UnityClient, WorkerUtils.MobileClient); template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic); snapshot.AddEntity(template); }
private static void AddStrongholdTypeComponents(EntityTemplate template, string writeAccess) { template.AddComponent(new StrongholdSight.Snapshot { TargetStrongholds = new Dictionary <EntityId, UnitBaseInfo>(), FrontLineCorners = new List <FrontLineInfo>(), TargetHexes = new Dictionary <uint, TargetHexInfo>() }, writeAccess); template.AddComponent(new ResourceComponent.Snapshot(), writeAccess); template.AddComponent(new ResourceSupplyer.Snapshot(), writeAccess); template.AddComponent(new TurretHub.Snapshot { TurretsDatas = new Dictionary <EntityId, TurretInfo>() }, writeAccess); }
public static EntityTemplate CreateSpinnerEntityTemplate(Coordinates coords) { var transform = TransformUtils.CreateTransformSnapshot(coords.ToUnityVector(), Quaternion.identity); var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot(coords), WorkerUtils.UnityGameLogic); template.AddComponent(new Metadata.Snapshot("Spinner"), WorkerUtils.UnityGameLogic); template.AddComponent(transform, WorkerUtils.UnityGameLogic); template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic); template.AddComponent(new Collisions.Snapshot(), WorkerUtils.UnityGameLogic); template.AddComponent(new SpinnerColor.Snapshot(Color.BLUE), WorkerUtils.UnityGameLogic); template.AddComponent(new SpinnerRotation.Snapshot(), WorkerUtils.UnityGameLogic); var query = InterestQuery.Query(Constraint.RelativeCylinder(radius: CheckoutRadius)).FilterResults(new[] { Position.ComponentId, Metadata.ComponentId, TransformInternal.ComponentId }); var interest = InterestTemplate.Create() .AddQueries <Position.Component>(query); template.AddComponent(interest.ToSnapshot()); template.SetReadAccess(WorkerUtils.MobileClient, WorkerUtils.UnityClient, WorkerUtils.UnityGameLogic); return(template); }
public void Can_create_from_entity_template() { // Note this tests the internal EntitySnapshot(Entity entity) constructor too! var entityTemplate = new EntityTemplate(); entityTemplate.AddComponent(new Position.Snapshot(new Coordinates(10, 10, 10)), "worker"); entityTemplate.AddComponent(new PlayerHeartbeatClient.Snapshot(), "test"); var snapshot = entityTemplate.GetEntitySnapshot(); Assert.IsTrue(snapshot.TryGetComponentSnapshot <Position.Snapshot>(out var position)); Assert.IsTrue(snapshot.TryGetComponentSnapshot <PlayerHeartbeatClient.Snapshot>(out var playerHeartbeat)); Assert.AreEqual(position.Coords.X, 10, Double.Epsilon); }
public static EntityTemplate CreateDinoBrachioTemplate(Coordinates initialPosition, long ownerId, int age) { var serverAttribute = UnityGameLogicConnector.WorkerType; var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot(initialPosition), serverAttribute); template.AddComponent(new Metadata.Snapshot(SimulationSettings.Dino_Brachio_PrefabName), serverAttribute); template.AddComponent(new Persistence.Snapshot(), serverAttribute); var spawnRotation = (uint)Mathf.CeilToInt(Random.Range(0, 360)); //Debug.Log("DinoBrachio rotation : "+spawnRotation); template.AddComponent(new TransformComponent.Snapshot(spawnRotation), serverAttribute); template.AddComponent(new DinoAiData.Snapshot(), serverAttribute); template.AddComponent(new DinoAttrs.Snapshot(false, 0f, 0f, 0f, 0f, 0, initialPosition.ToUnityVector().ToVector3f(), ownerId, 0f, 0f, 0f), serverAttribute); template.AddComponent(new Health.Snapshot(), serverAttribute); template.AddComponent(new Age.Snapshot(age, SimulationSettings.NPCAgeMax, SimulationSettings.NPCAgeGrowUp), serverAttribute); // template.AddComponent(new Flammable.Snapshot(false, true, FireEffectType.SMALL), serverAttribute); // template.AddComponent(new Inventory.Snapshot(0), serverAttribute); // template.AddComponent(new DinoBrachio.Snapshot(), serverAttribute); template.SetReadAccess(UnityClientConnector.WorkerType, UnityGameLogicConnector.WorkerType, MobileClientWorkerConnector.WorkerType); template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute); return(template); }
public static EntityTemplate Spawner(Coordinates spawnerCoordinates) { var position = new Position.Snapshot(spawnerCoordinates); var metadata = new Metadata.Snapshot("PlayerCreator"); var template = new EntityTemplate(); template.AddComponent(position, WorkerUtils.UnityGameLogic); template.AddComponent(metadata, WorkerUtils.UnityGameLogic); template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic); template.AddComponent(new PlayerCreator.Snapshot(), 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 void SwitchType(EntityTemplate template, ObjectType type, string writeAccess) { switch (type) { case ObjectType.Tree: template.AddComponent(new TreeComponent.Snapshot { Trees = new List <TreeInfo>() }, writeAccess); break; case ObjectType.Tower: template.AddComponent(new SymbolicTower.Snapshot(), writeAccess); break; } }
public static void AddPlayerLifecycleComponents(EntityTemplate template, string workerId, string clientAccess, string serverAccess) { var clientHeartbeat = new PlayerHeartbeatClient.Snapshot(); var serverHeartbeat = new PlayerHeartbeatServer.Snapshot(); var owningComponent = new OwningWorker.Snapshot { WorkerId = workerId }; template.AddComponent(clientHeartbeat, clientAccess); template.AddComponent(serverHeartbeat, serverAccess); template.AddComponent(owningComponent, serverAccess); }
public static EntityTemplate Ball(Vector3f position) { // Create a ball component snapshot which is initially active. var ballComponent = new Balls.Ball.Snapshot();//Cubes.Cube.Snapshot(); //Cubes.cube.Snapshot(true); var entityTemplate = new EntityTemplate(); entityTemplate.AddComponent(new Position.Snapshot(new Coordinates(position.X, position.Y, position.Z)), WorkerUtils.UnityGameLogic); entityTemplate.AddComponent(new Metadata.Snapshot("Ball"), WorkerUtils.UnityGameLogic); entityTemplate.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic); entityTemplate.AddComponent(ballComponent, WorkerUtils.UnityGameLogic); entityTemplate.SetReadAccess(WorkerUtils.UnityGameLogic, WorkerUtils.UnityClient); entityTemplate.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic); return(entityTemplate); }
private static void AddSpawnController(Snapshot snapshot) { var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot(), WorkerUtils.UnityGameLogic); template.AddComponent( new Metadata.Snapshot { EntityType = "SpawnController" }, WorkerUtils.UnityGameLogic); template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic); template.AddComponent(new SpawnController.Snapshot(), WorkerUtils.UnityGameLogic); template.SetReadAccess(WorkerUtils.AllWorkers); template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic); snapshot.AddEntity(template); }
private EntityTemplate GetBasicTemplate() { var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot(), "write-acesss"); return(template); }
private static void AddPlayerSpawner(Snapshot snapshot, Coordinates playerSpawnerLocation) { var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot(playerSpawnerLocation), WorkerUtils.UnityGameLogic); template.AddComponent(new Metadata.Snapshot { EntityType = "PlayerCreator" }, WorkerUtils.UnityGameLogic); template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic); template.AddComponent(new PlayerCreator.Snapshot(), WorkerUtils.UnityGameLogic); template.SetReadAccess(WorkerUtils.UnityGameLogic, WorkerUtils.UnityClient, WorkerUtils.MobileClient); template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic); snapshot.AddEntity(template); }
private EntityTemplate GetEntityTemplate() { var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot(), "worker"); return(template); }