public static SnapshotEntity GeneratePlayerSnapshotEntityTemplate(string workerId) { // Set name of Unity prefab associated with this entity var playerEntity = new SnapshotEntity { Prefab = "PlayerPrefab" }; // Define componetns attached to snapshot entity playerEntity.Add( new PlayerComponent.Data( new PlayerComponentData( Coordinates.ZERO, playerEntity.DefaultTransformData(), playerEntity.DefaultTransformData(), playerEntity.DefaultTransformData() ) ) ); var specificClientPredicate = CommonPredicates.SpecificClientOnly(workerId); var acl = Acl.Build() // Both FSim (server) workers and client workers granted read access over all states .SetReadAccess(CommonPredicates.PhysicsOrVisual) // Only the local client worker (local authority) granted write access over PlayerComponent component .SetWriteAccess <PlayerComponent>(specificClientPredicate); playerEntity.SetAcl(acl); return(playerEntity); }
public void GainControl(EntityId entityId, string workerId) { Debug.LogWarning(workerId + " is attempting to gain control of: " + entityId); EntityAclWriter.Send( Acl.Build() .SetReadAccess(CommonPredicates.PhysicsOrVisual) .SetWriteAccess <EntityAcl>(CommonPredicates.PhysicsOnly) .SetWriteAccess <Crate>(CommonPredicates.PhysicsOnly) .SetWriteAccess <WorldTransform>(CommonPredicates.SpecificClientOnly(workerId)) .SetWriteAccess <Controllable>(CommonPredicates.PhysicsOnly) ); // Ensure crate is kinematic if (!GetComponent <Rigidbody>().isKinematic) { GetComponent <Rigidbody>().isKinematic = true; } }
// Template definition for a PlayerShip snapshot entity static public Entity GeneratePlayerShipEntityTemplate(string clientWorkerId, Coordinates initialPosition) { var playerEntityTemplate = new Entity(); // Define components attached to entity playerEntityTemplate.Add(new WorldTransform.Data(new WorldTransformData(initialPosition, 0))); playerEntityTemplate.Add(new PlayerLifecycle.Data(new PlayerLifecycleData(0, 3, 10))); playerEntityTemplate.Add(new ShipControls.Data(new ShipControlsData(0, 0))); // Grant component access permissions var acl = Acl.Build() .SetReadAccess(CommonPredicates.PhysicsOrVisual) .SetWriteAccess <WorldTransform>(CommonPredicates.SpecificClientOnly(clientWorkerId)) .SetWriteAccess <ShipControls>(CommonPredicates.SpecificClientOnly(clientWorkerId)) .SetWriteAccess <PlayerLifecycle>(CommonPredicates.PhysicsOnly); playerEntityTemplate.SetAcl(acl); return(playerEntityTemplate); }
public static Entity CreatePlayerTemplate(string clientWorkerId, Coordinates initialPosition, uint teamId) { var template = new Entity(); template.Add(new ClientAuthorityCheck.Data()); template.Add(new FSimAuthorityCheck.Data()); template.Add(new TransformComponent.Data(initialPosition, 0)); template.Add(new PlayerInfo.Data(true, initialPosition)); template.Add(new PlayerControls.Data(initialPosition)); template.Add(new Health.Data(SimulationSettings.PlayerMaxHealth, SimulationSettings.PlayerMaxHealth, true)); template.Add(new Flammable.Data(false, true, FireEffectType.SMALL)); template.Add(new Spells.Data(new Map <SpellType, float> { { SpellType.LIGHTNING, 0f }, { SpellType.RAIN, 0f } }, true)); template.Add(new Inventory.Data(0)); template.Add(new Chat.Data()); template.Add(new Heartbeat.Data(SimulationSettings.HeartbeatMax)); template.Add(new TeamAssignment.Data(teamId)); template.Add(new Flammable.Data(false, true, FireEffectType.SMALL)); var specificClientPredicate = CommonPredicates.SpecificClientOnly(clientWorkerId); var permissions = Acl.Build() .SetReadAccess(CommonPredicates.PhysicsOrVisual) .SetWriteAccess <ClientAuthorityCheck>(specificClientPredicate) .SetWriteAccess <FSimAuthorityCheck>(CommonPredicates.PhysicsOnly) .SetWriteAccess <TransformComponent>(CommonPredicates.PhysicsOnly) .SetWriteAccess <PlayerInfo>(CommonPredicates.PhysicsOnly) .SetWriteAccess <PlayerControls>(specificClientPredicate) .SetWriteAccess <Health>(CommonPredicates.PhysicsOnly) .SetWriteAccess <Flammable>(CommonPredicates.PhysicsOnly) .SetWriteAccess <Spells>(CommonPredicates.PhysicsOnly) .SetWriteAccess <Inventory>(CommonPredicates.PhysicsOnly) .SetWriteAccess <Chat>(CommonPredicates.PhysicsOnly) .SetWriteAccess <Heartbeat>(CommonPredicates.PhysicsOnly) .SetWriteAccess <TeamAssignment>(CommonPredicates.PhysicsOnly); template.SetAcl(permissions); return(template); }