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); template.SetReadAccess(WorkerUtils.UnityGameLogic); template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic); return(template); }
public void TryGetComponent_should_return_true_if_component_exists() { var template = GetBasicTemplate(); var component = new Metadata.Snapshot { EntityType = "something" }; template.AddComponent(component); Assert.IsTrue(template.TryGetComponent <Metadata.Snapshot>(out var metadata)); Assert.AreEqual("something", metadata.EntityType); Assert.IsTrue(template.TryGetComponent(Metadata.ComponentId, out var boxedMetadata)); Assert.IsInstanceOf <Metadata.Snapshot>(boxedMetadata); Assert.AreEqual("something", ((Metadata.Snapshot)boxedMetadata).EntityType); }
public static EntityTemplate DeploymentState() { const uint sessionTimeSeconds = 300; var position = new Position.Snapshot(); var metadata = new Metadata.Snapshot { EntityType = "DeploymentState" }; var template = new EntityTemplate(); template.AddComponent(position, WorkerUtils.UnityGameLogic); template.AddComponent(metadata, WorkerUtils.UnityGameLogic); template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic); template.AddComponent(new Session.Snapshot(Status.LOBBY), WorkerUtils.UnityGameLogic); template.AddComponent(new Deployment.Snapshot(), WorkerUtils.DeploymentManager); template.AddComponent(new Timer.Snapshot(0, sessionTimeSeconds), WorkerUtils.UnityGameLogic); template.SetReadAccess(WorkerUtils.UnityGameLogic, WorkerUtils.DeploymentManager, WorkerUtils.UnityClient, WorkerUtils.MobileClient); template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic); return(template); }
public static EntityTemplate PolEntity(Vector3f position, uint tribe) { var metadata = new Metadata.Snapshot { EntityType = "PolEntity" }; var rotationUpdate = new RotationUpdate { Yaw = 0, Pitch = 0 }; var serverResponse = new ServerResponse { Position = position.ToUnityVector3().ToIntAbsolute() }; var template = new EntityTemplate(); template.AddComponent(new Position.Snapshot(new Coordinates(position.X, position.Y, position.Z)), WorkerUtils.UnityGameLogic); template.AddComponent(metadata, WorkerUtils.UnityGameLogic); var clientRotation = new ClientRotation.Snapshot { Latest = rotationUpdate }; template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic); template.AddComponent(new Pol.PolEntityData.Snapshot(true, tribe, 1, Behaviors.Behavior1), WorkerUtils.UnityGameLogic); var serverMovement = new ServerMovement.Snapshot { Latest = serverResponse }; var clientMovement = new ClientMovement.Snapshot { Latest = new ClientRequest() }; template.SetReadAccess(WorkerUtils.UnityGameLogic, WorkerUtils.UnityClient); template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic); var playerInterest = new ComponentInterest { Queries = new List <ComponentInterest.Query> { new ComponentInterest.Query { Constraint = new ComponentInterest.QueryConstraint { ComponentConstraint = Pol.PolController.ComponentId, AndConstraint = new List <ComponentInterest.QueryConstraint>(), OrConstraint = new List <ComponentInterest.QueryConstraint>() }, FullSnapshotResult = true, ResultComponentId = new List <uint>(), } } }; var interestComponent = new Interest.Snapshot { ComponentInterest = new Dictionary <uint, ComponentInterest> { { PolEntityData.ComponentId, playerInterest }, }, }; template.AddComponent(interestComponent, WorkerUtils.UnityGameLogic); template.AddComponent(serverMovement, WorkerUtils.UnityGameLogic); template.AddComponent(clientMovement, WorkerUtils.UnityGameLogic); template.AddComponent(clientRotation, WorkerUtils.UnityGameLogic); return(template); }