public static Entity CreatePlayerTemplate(string clientWorkerId, string playerPrefabName)
        {
            var teamId         = (uint)Random.Range(0, SimulationSettings.TeamCount);
            var spawningOffset = new Vector3(Random.value - 0.5f, 0f, Random.value - 0.5f) * SimulationSettings.PlayerSpawnOffsetFactor;
            var hqPosition     = SimulationSettings.TeamHQLocations[teamId].ToVector3();
            var spawnPosition  = (hqPosition + spawningOffset).ToCoordinates();

            var template = EntityBuilder.Begin()
                           .AddPositionComponent(spawnPosition.ToUnityVector(), CommonRequirementSets.PhysicsOnly)
                           .AddMetadataComponent(playerPrefabName)
                           .SetPersistence(true)
                           .SetReadAcl(CommonRequirementSets.PhysicsOrVisual)
                           .AddComponent(new ClientAuthorityCheck.Data(), CommonRequirementSets.SpecificClientOnly(clientWorkerId))
                           .AddComponent(new UnityWorkerAuthorityCheck.Data(), CommonRequirementSets.PhysicsOnly)
                           .AddComponent(new TransformComponent.Data(0), CommonRequirementSets.PhysicsOnly)
                           .AddComponent(new PlayerInfo.Data(true, spawnPosition), CommonRequirementSets.PhysicsOnly)
                           .AddComponent(new PlayerControls.Data(spawnPosition), CommonRequirementSets.SpecificClientOnly(clientWorkerId))
                           .AddComponent(new Health.Data(SimulationSettings.PlayerMaxHealth, SimulationSettings.PlayerMaxHealth,
                                                         true), CommonRequirementSets.PhysicsOnly)
                           .AddComponent(new Flammable.Data(false, true, FireEffectType.SMALL), CommonRequirementSets.PhysicsOnly)
                           .AddComponent(
                new Spells.Data(new Map <SpellType, float> {
                { SpellType.LIGHTNING, 0f }, { SpellType.RAIN, 0f }
            }, true), CommonRequirementSets.PhysicsOnly)
                           .AddComponent(new Inventory.Data(0), CommonRequirementSets.PhysicsOnly)
                           .AddComponent(new ConnectionHeartbeat.Data(SimulationSettings.DefaultHeartbeatsBeforeTimeout), CommonRequirementSets.PhysicsOnly)
                           .AddComponent(new TeamAssignment.Data(teamId), CommonRequirementSets.PhysicsOnly)
                           .Build();

            return(template);
        }
        public static Entity CreatePlayerTemplate(string clientId)
        {
            var playerTemplate = EntityBuilder.Begin()
                                 .AddPositionComponent(Improbable.Coordinates.ZERO.ToUnityVector(), CommonRequirementSets.PhysicsOnly)
                                 .AddMetadataComponent(entityType: SimulationSettings.PlayerPrefabName)
                                 .SetPersistence(false)
                                 .SetReadAcl(CommonRequirementSets.PhysicsOrVisual)
                                 .AddComponent(new Rotation.Data(Quaternion.identity.ToNativeQuaternion()), CommonRequirementSets.PhysicsOnly)
                                 .AddComponent(new ClientAuthorityCheck.Data(), CommonRequirementSets.SpecificClientOnly(clientId))
                                 .AddComponent(new ClientConnection.Data(SimulationSettings.TotalHeartbeatsBeforeTimeout), CommonRequirementSets.PhysicsOnly)
                                 .Build();

            return(playerTemplate);
        }
Exemple #3
0
        // Defines the template for the PlayerShip entity.
        public static Entity CreatePlayerShipTemplate(string clientWorkerId, Vector3 initialPosition)
        {
            var playerEntityTemplate = EntityBuilder.Begin()
                                       // Add components to the entity, then set the access permissions for the component on the entity relative to the client or server worker ids.
                                       .AddPositionComponent(initialPosition, CommonRequirementSets.SpecificClientOnly(clientWorkerId))
                                       .AddMetadataComponent(SimulationSettings.PlayerShipPrefabName)
                                       .SetPersistence(false)
                                       .SetReadAcl(CommonRequirementSets.PhysicsOrVisual)
                                       .AddComponent(new Rotation.Data(0), CommonRequirementSets.SpecificClientOnly(clientWorkerId))
                                       .AddComponent(new ClientConnection.Data(SimulationSettings.TotalHeartbeatsBeforeTimeout), CommonRequirementSets.PhysicsOnly)
                                       .AddComponent(new ShipControls.Data(0, 0), CommonRequirementSets.SpecificClientOnly(clientWorkerId))
                                       .AddComponent(new ClientAuthorityCheck.Data(), CommonRequirementSets.SpecificClientOnly(clientWorkerId))
                                       .Build();

            return(playerEntityTemplate);
        }
Exemple #4
0
        public static Entity CreatePlayerTemplate(string clientId, Vector3 initialPosition)
        {
            var playerTemplate = EntityBuilder.Begin()
                                 .AddPositionComponent(initialPosition, CommonRequirementSets.PhysicsOnly)
                                 .AddMetadataComponent(entityType: SimulationSettings.PlayerPrefabName)
                                 .SetPersistence(false)
                                 .SetReadAcl(CommonRequirementSets.PhysicsOrVisual)
                                 .AddComponent(new Rotation.Data(Quaternion.identity.ToNativeQuaternion()), CommonRequirementSets.PhysicsOnly)
                                 .AddComponent(new ClientAuthorityCheck.Data(), CommonRequirementSets.SpecificClientOnly(clientId))
                                 .AddComponent(new ClientConnection.Data(SimulationSettings.TotalHeartbeatsBeforeTimeout), CommonRequirementSets.PhysicsOnly)
                                 .AddComponent(new PlayerInput.Data(new Joystick(xAxis: 0, yAxis: 0)), CommonRequirementSets.SpecificClientOnly(clientId))
                                 .AddComponent(new Touching.Data(), CommonRequirementSets.PhysicsOnly)
                                 .AddComponent(new Health.Data(100), CommonRequirementSets.PhysicsOnly)
                                 .Build();

            return(playerTemplate);
        }
        public static Entity CreatePlayerTemplate(string clientId, EntityId playerCreatorId, IComponentData <PlatformPosition> platformPosiionData)
        {
            var playerTemplate = EntityBuilder.Begin()
                                 .AddPositionComponent(Coordinates.ZERO.ToUnityVector(), CommonRequirementSets.PhysicsOnly)
                                 .AddMetadataComponent(entityType: SimulationSettings.PlayerPrefabName)
                                 .SetPersistence(false)
                                 .SetReadAcl(CommonRequirementSets.PhysicsOrVisual)
                                 .AddComponent(new Rotation.Data(UnityEngine.Quaternion.identity.ToNativeQuaternion()), CommonRequirementSets.PhysicsOnly)
                                 .AddComponent(new ClientAuthorityCheck.Data(), CommonRequirementSets.SpecificClientOnly(clientId))
                                 .AddComponent(new ClientConnection.Data(SimulationSettings.TotalHeartbeatsBeforeTimeout, clientId, playerCreatorId), CommonRequirementSets.PhysicsOnly)
                                 .AddComponent(new WalkControls.Data(new Vector3f(0.0f, 0.0f, 0.0f)), CommonRequirementSets.SpecificClientOnly(clientId))
                                 .AddComponent(new PilotControls.Data(0.0f, 0.0f, false), CommonRequirementSets.SpecificClientOnly(clientId))
                                 .AddComponent(platformPosiionData, CommonRequirementSets.PhysicsOnly)
                                 .Build();

            return(playerTemplate);
        }
        public static Entity CreatePlayerTemplate(string clientId)
        {
            var playerTemplate = EntityBuilder.Begin()
                                 .AddPositionComponent(new Improbable.Coordinates(0, 2, 0).ToUnityVector(), CommonRequirementSets.PhysicsOnly)
                                 .AddMetadataComponent(entityType: SimulationSettings.PlayerPrefabName)
                                 .SetPersistence(false)
                                 .SetReadAcl(CommonRequirementSets.PhysicsOrVisual)
                                 .AddComponent(new Rotation.Data(Quaternion.identity.ToNativeQuaternion()), CommonRequirementSets.PhysicsOnly)
                                 .AddComponent(new ClientAuthorityCheck.Data(), CommonRequirementSets.SpecificClientOnly(clientId))
                                 .AddComponent(new ClientConnection.Data(SimulationSettings.TotalHeartbeatsBeforeTimeout), CommonRequirementSets.PhysicsOnly)
                                 .AddComponent(new PlayerInput.Data(new Joystick(xAxis: 0, yAxis: 0, shift: false, w: false, s: false, space: false)), CommonRequirementSets.SpecificClientOnly(clientId))
                                 .AddComponent(new Health.Data(health: 100), CommonRequirementSets.PhysicsOnly)
                                 .AddComponent(new Scores.Data(scores: 0), CommonRequirementSets.PhysicsOnly)
                                 .AddComponent(new Death.Data(death: false), CommonRequirementSets.PhysicsOnly)
                                 .Build();

            return(playerTemplate);
        }
        public static Entity CreatePlayerTemplate(string clientId, EntityId playerCreatorId, Vector3d position)
        {
            var rotation        = Quaternion.identity;
            var scale           = new Vector3d(1.0, 1.0, 1.0);
            var spatialPosition = position / Scales.spatialFactor;

            var playerTemplate = EntityBuilder.Begin()
                                 .AddPositionComponent((Vector3)spatialPosition, CommonRequirementSets.SpecificClientOnly(clientId))
                                 .AddMetadataComponent(entityType: SimulationSettings.PlayerPrefabName)
                                 .SetPersistence(false)
                                 .SetReadAcl(CommonRequirementSets.PhysicsOrVisual)
                                 .AddComponent(new TransformInfo.Data(position.ToImprobable(), rotation.ToImprobable(), scale.ToImprobable()), CommonRequirementSets.SpecificClientOnly(clientId))
                                 .AddComponent(new ShipControls.Data(0, 0, 0), CommonRequirementSets.SpecificClientOnly(clientId))
                                 .AddComponent(new ClientAuthorityCheck.Data(), CommonRequirementSets.SpecificClientOnly(clientId))
                                 .AddComponent(new ClientConnection.Data(SimulationSettings.TotalHeartbeatsBeforeTimeout, clientId, playerCreatorId), CommonRequirementSets.PhysicsOnly)
                                 .Build();

            return(playerTemplate);
        }
Exemple #8
0
        public static Entity CreatePlayerTemplate(string clientId)
        {
            var template = EntityBuilder.Begin()
                           .AddPositionComponent(Vector3.zero, CommonRequirementSets.SpecificClientOnly(clientId))
                           .AddMetadataComponent(SimulationSettings.PlayerPrefabName)
                           .SetPersistence(true)
                           .SetReadAcl(CommonRequirementSets.PhysicsOrVisual)
                           .AddComponent(new ClientAuthorityCheck.Data(), CommonRequirementSets.SpecificClientOnly(clientId))
                           .AddComponent(new ClientConnection.Data(SimulationSettings.TotalHeartbeatsBeforeTimeout), CommonRequirementSets.PhysicsOnly)
                           .AddComponent(new PlayerRotation.Data(yaw: 0), CommonRequirementSets.SpecificClientOnly(clientId))
                           .AddComponent(new PlayerMovement.Data(), CommonRequirementSets.SpecificClientOnly(clientId))
                           .AddComponent(new Instructions.Data(true, "Waiting for other players"), CommonRequirementSets.PhysicsOnly)
                           .AddComponent(new PlayerMovement.Data(), CommonRequirementSets.SpecificClientOnly(clientId))
                           .AddComponent(new Health.Data(1000), CommonRequirementSets.PhysicsOnly)
                           .AddComponent(new PlayerActions.Data(new Improbable.Collections.Map <EntityId, bool>(), 20), CommonRequirementSets.SpecificClientOnly(clientId))
                           .Build();

            return(template);
        }
Exemple #9
0
        public static Entity CreateSpecatorPlayerTemplate(string clientId)
        {
            var entityTemplate = new SnapshotEntity {
                Prefab = SimulationSettings.SpectatorPlayerPrefabName
            };

            entityTemplate.Add(new WorldTransform.Data(Coordinates.ZERO + new Vector3d(0, 4, 0), new Quaternion(0, 0, 0, 0)));
            entityTemplate.Add(new ClientAuthorityCheck.Data());
            entityTemplate.Add(new ClientConnection.Data(SimulationSettings.TotalHeartbeatsBeforeTimeout));

            var acl = Acl.Build()
                      .SetReadAccess(CommonRequirementSets.PhysicsOrVisual)
                      .SetWriteAccess <WorldTransform>(CommonRequirementSets.SpecificClientOnly(clientId))
                      .SetWriteAccess <ClientAuthorityCheck>(CommonRequirementSets.SpecificClientOnly(clientId))
                      .SetWriteAccess <ClientConnection>(CommonRequirementSets.PhysicsOnly);

            entityTemplate.SetAcl(acl);

            return(entityTemplate);
        }
Exemple #10
0
        public static Entity CreateVrPlayerTemplate(string clientId)
        {
            var entityTemplate = EntityBuilder.Begin()
                                 .AddPositionComponent(Improbable.Coordinates.ZERO.ToUnityVector(), CommonRequirementSets.SpecificClientOnly(clientId))
                                 .AddMetadataComponent(entityType: SimulationSettings.VrPlayerPrefabName)
                                 .SetPersistence(false)
                                 .SetReadAcl(CommonRequirementSets.PhysicsOrVisual)
                                 .AddComponent(new Rotation.Data(Quaternion.identity.ToNativeQuaternion()), CommonRequirementSets.SpecificClientOnly(clientId))
                                 .AddComponent(new VRPeripheralOffsets.Data(
                                                   head: new TransformOffset(Improbable.Vector3f.ZERO, Improbable.Vector3f.ZERO),
                                                   leftController: new TransformOffset(Improbable.Vector3f.ZERO, Improbable.Vector3f.ZERO),
                                                   rightController: new TransformOffset(Improbable.Vector3f.ZERO, Improbable.Vector3f.ZERO)
                                                   ), CommonRequirementSets.SpecificClientOnly(clientId))
                                 .AddComponent(new ClientAuthorityCheck.Data(), CommonRequirementSets.SpecificClientOnly(clientId))
                                 .AddComponent(new ClientConnection.Data(SimulationSettings.TotalHeartbeatsBeforeTimeout), CommonRequirementSets.PhysicsOnly)
                                 .AddComponent(new Grab.Data(new Map <ControllerSide, EntityId>()), CommonRequirementSets.SpecificClientOnly(clientId))
                                 .Build();

            return(entityTemplate);
        }
        public static Entity CreatePlayerTemplate(string clientId)
        {
            var playerTemplate = EntityBuilder.Begin()
                                 .AddPositionComponent(new Improbable.Coordinates(0, SimulationSettings.PlayerSpawnHeight, 0).ToUnityVector(), CommonRequirementSets.PhysicsOnly)
                                 .AddMetadataComponent(entityType: SimulationSettings.PlayerPrefabName)
                                 .SetPersistence(false)
                                 .SetReadAcl(CommonRequirementSets.PhysicsOrVisual)
                                 .AddComponent(new Rotation.Data(SimulationSettings.PlayerRotation.ToNativeQuaternion()), CommonRequirementSets.PhysicsOnly)
                                 .AddComponent(new ClientAuthorityCheck.Data(), CommonRequirementSets.SpecificClientOnly(clientId))
                                 .AddComponent(new ClientConnection.Data(SimulationSettings.TotalHeartbeatsBeforeTimeout), CommonRequirementSets.PhysicsOnly)
                                 .AddComponent(new PlayerInput.Data(new Joystick(xAxis: 0, yAxis: 0), false, false), CommonRequirementSets.SpecificClientOnly(clientId))
                                 .AddComponent(new Health.Data(SimulationSettings.PlayerSpawnHealth), CommonRequirementSets.PhysicsOnly)
                                 .AddComponent(new Score.Data(0), CommonRequirementSets.PhysicsOnly)
                                 .AddComponent(new Size.Data(1.0F), CommonRequirementSets.PhysicsOnly)
                                 .AddComponent(new NoticeCreator.Data(), CommonRequirementSets.SpecificClientOnly(clientId))
                                 .AddComponent(new ArrowCreator.Data(), CommonRequirementSets.SpecificClientOnly(clientId))
                                 .Build();

            return(playerTemplate);
        }
Exemple #12
0
        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 = CommonRequirementSets.SpecificClientOnly(clientWorkerId);

            var permissions = Acl.Build()
                              .SetReadAccess(CommonRequirementSets.PhysicsOrVisual)
                              .SetWriteAccess <ClientAuthorityCheck>(specificClientPredicate)
                              .SetWriteAccess <FSimAuthorityCheck>(CommonRequirementSets.PhysicsOnly)
                              .SetWriteAccess <TransformComponent>(CommonRequirementSets.PhysicsOnly)
                              .SetWriteAccess <PlayerInfo>(CommonRequirementSets.PhysicsOnly)
                              .SetWriteAccess <PlayerControls>(specificClientPredicate)
                              .SetWriteAccess <Health>(CommonRequirementSets.PhysicsOnly)
                              .SetWriteAccess <Flammable>(CommonRequirementSets.PhysicsOnly)
                              .SetWriteAccess <Spells>(CommonRequirementSets.PhysicsOnly)
                              .SetWriteAccess <Inventory>(CommonRequirementSets.PhysicsOnly)
                              .SetWriteAccess <Chat>(CommonRequirementSets.PhysicsOnly)
                              .SetWriteAccess <Heartbeat>(CommonRequirementSets.PhysicsOnly)
                              .SetWriteAccess <TeamAssignment>(CommonRequirementSets.PhysicsOnly);

            template.SetAcl(permissions);

            return(template);
        }
        public static Entity CreatePlayerTemplate(string clientId, string color, string name)
        {
            float x              = 36.0f;
            float y              = 36.0f;
            float xCoord         = Random.Range(x, -x);
            float yCoord         = Random.Range(y, -y);
            var   playerTemplate = EntityBuilder.Begin()
                                   .AddPositionComponent(new Improbable.Coordinates(xCoord, SimulationSettings.PlayerSpawnHeight, yCoord).ToUnityVector(), CommonRequirementSets.PhysicsOnly)

                                   .AddMetadataComponent(entityType: SimulationSettings.PlayerPrefabName)
                                   .SetPersistence(false)
                                   .SetReadAcl(CommonRequirementSets.PhysicsOrVisual)
                                   .AddComponent(new Scale.Data(1), CommonRequirementSets.PhysicsOnly)
                                   .AddComponent(new Status.Data(), CommonRequirementSets.PhysicsOnly)
                                   .AddComponent(new Rotation.Data(Quaternion.identity.ToNativeQuaternion()), CommonRequirementSets.PhysicsOnly)
                                   .AddComponent(new ClientAuthorityCheck.Data(), CommonRequirementSets.SpecificClientOnly(clientId))
                                   .AddComponent(new ClientConnection.Data(SimulationSettings.TotalHeartbeatsBeforeTimeout), CommonRequirementSets.PhysicsOnly)
                                   .AddComponent(new PlayerInput.Data(new Joystick(xAxis: 0, yAxis: 0)), CommonRequirementSets.SpecificClientOnly(clientId))
                                   .AddComponent(new PlayerData.Data(color, name), CommonRequirementSets.PhysicsOnly)
                                   .AddComponent(new Scoreboard.Data(), CommonRequirementSets.SpecificClientOnly(clientId))
                                   .Build();

            return(playerTemplate);
        }
Exemple #14
0
        public static Entity CreateVrPlayerTemplate(string clientId)
        {
            var entityTemplate = new SnapshotEntity {
                Prefab = SimulationSettings.VrPlayerPrefabName
            };

            entityTemplate.Add(new WorldTransform.Data(Coordinates.ZERO, new Quaternion(0, 0, 0, 0)));
            entityTemplate.Add(new VRPeripheralOffsets.Data(new TransformOffset(Vector3f.ZERO, Vector3f.ZERO), new TransformOffset(Vector3f.ZERO, Vector3f.ZERO), new TransformOffset(Vector3f.ZERO, Vector3f.ZERO)));
            entityTemplate.Add(new ClientAuthorityCheck.Data());
            entityTemplate.Add(new ClientConnection.Data(SimulationSettings.TotalHeartbeatsBeforeTimeout));
            entityTemplate.Add(new Grab.Data(new Map <ControllerSide, EntityId>()));

            var acl = Acl.Build()
                      .SetReadAccess(CommonRequirementSets.PhysicsOrVisual)
                      .SetWriteAccess <WorldTransform>(CommonRequirementSets.SpecificClientOnly(clientId))
                      .SetWriteAccess <VRPeripheralOffsets>(CommonRequirementSets.SpecificClientOnly(clientId))
                      .SetWriteAccess <ClientAuthorityCheck>(CommonRequirementSets.SpecificClientOnly(clientId))
                      .SetWriteAccess <ClientConnection>(CommonRequirementSets.PhysicsOnly)
                      .SetWriteAccess <Grab>(CommonRequirementSets.SpecificClientOnly(clientId));

            entityTemplate.SetAcl(acl);

            return(entityTemplate);
        }
Exemple #15
0
        // Template definition for a Player snapshot entity
        static public Entity GeneratePlayerEntityTemplate(string clientWorkerId, Coordinates initialPosition)
        {
            Vector3f playerInitialRotation = new Vector3f(0.0f, 0.0f, 0.0f);


            var playerEntityTemplate = new Entity();

            // Define components attached to entity
            playerEntityTemplate.Add(new WorldTransform.Data(new WorldTransformData(initialPosition, playerInitialRotation, 0)));
            playerEntityTemplate.Add(new PlayerLifecycle.Data(new PlayerLifecycleData(0, 3, 10)));                      //No missed heartbeats, upto 3 missed Hbs allowed, HB interval = 10
            playerEntityTemplate.Add(new PlayerControls.Data(new PlayerControlsData(0, 0, 0, 0)));


            // Grant component access permissions
            var acl = Acl.Build()
                      .SetReadAccess(CommonRequirementSets.PhysicsOrVisual)                                                //Both Server and Client workers have read access to all the components of PlayerShip
                      .SetWriteAccess <WorldTransform> (CommonRequirementSets.SpecificClientOnly(clientWorkerId))          //only UnityClient has access
                      .SetWriteAccess <PlayerControls> (CommonRequirementSets.SpecificClientOnly(clientWorkerId))          //only UnityClient has access
                      .SetWriteAccess <PlayerLifecycle>(CommonRequirementSets.PhysicsOnly);                                //UnityWorker has access

            playerEntityTemplate.SetAcl(acl);

            return(playerEntityTemplate);
        }