Example #1
0
        public static EntityTemplate CreateCubeEntityTemplate(Vector3 location)
        {
            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(location.ToCoordinates()), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot("Cube"), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new CubeColor.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new CubeTargetVelocity.Snapshot(new Vector3f(-2.0f, 0, 0)),
                                  WorkerUtils.UnityGameLogic);
            template.AddComponent(new Launchable.Snapshot(), WorkerUtils.UnityGameLogic);

            TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, WorkerUtils.UnityGameLogic, Quaternion.identity, location);

            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);
        }
Example #2
0
        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);
        }
        // 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);
        }
Example #4
0
        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);
        }
 protected override void HandleWorkerConnectionEstablished()
 {
     PlayerLifecycleHelper.AddClientSystems(Worker.World);
     TransformSynchronizationHelper.AddClientSystems(Worker.World);
     GameObjectRepresentationHelper.AddSystems(Worker.World);
     GameObjectCreationHelper.EnableStandardGameObjectCreation(Worker.World);
 }
Example #6
0
        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);
        }
Example #7
0
 public static void AddGameLogicSystems(World world)
 {
     AddLifecycleSystems(world);
     TransformSynchronizationHelper.AddServerSystems(world);
     PlayerLifecycleHelper.AddServerSystems(world);
     GameObjectCreationHelper.EnableStandardGameObjectCreation(world);
 }
        // Defines the template for the PlayerCreator entity.
        public static EntityTemplate CreatePlayerCreatorTemplate()
        {
            var pos = new Coordinates(-5, 0, 0);

            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot()
            {
                Coords = pos
            }, WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot()
            {
                EntityType = SimulationSettings.PlayerCreatorPrefabName
            }, WorkerUtils.UnityGameLogic);
            template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new PlayerCreator.Snapshot(), WorkerUtils.UnityGameLogic);

            TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, WorkerUtils.UnityGameLogic, location: pos.ToUnityVector());


            template.SetReadAccess(WorkerUtils.AllWorkerAttributes);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);

            return(template);
        }
 protected override void HandleWorkerConnectionEstablished()
 {
     Worker.World.GetOrCreateManager <MetricSendSystem>();
     PlayerLifecycleHelper.AddServerSystems(Worker.World);
     GameObjectCreationHelper.EnableStandardGameObjectCreation(Worker.World);
     TransformSynchronizationHelper.AddServerSystems(Worker.World);
 }
Example #10
0
        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);
        }
Example #11
0
        public static void AddStrategyLogicSystems(World world, EntityRepresentationMapping entityRepresentationMapping)
        {
            TransformSynchronizationHelper.AddServerSystems(world);
            PlayerLifecycleHelper.AddServerSystems(world);
            GameObjectCreationHelper.EnableStandardGameObjectCreation(world, entityRepresentationMapping);

            world.GetOrCreateSystem <ProcessLaunchCommandSystem>();
            world.GetOrCreateSystem <MetricSendSystem>();
            //world.GetOrCreateSystem<ArmyCloudUpdateSystem>();
        }
        protected override void HandleWorkerConnectionEstablished()
        {
            PlayerLifecycleHelper.AddClientSystems(Worker.World);
            TransformSynchronizationHelper.AddClientSystems(Worker.World);

            IEntityGameObjectCreator fallbackCreator = new GameObjectCreatorFromMetadata(Worker.WorkerType, Worker.Origin, Worker.LogDispatcher);
            IEntityGameObjectCreator customCreator   = new PlayerGameObjectCreator(fallbackCreator, Worker.World, Worker.WorkerType);

            GameObjectCreationHelper.EnableStandardGameObjectCreation(Worker.World, customCreator);
        }
        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);
        }
Example #14
0
        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);
        }
Example #15
0
 public static void AddGameLogicSystems(World world)
 {
     AddLifecycleSystems(world);
     TransformSynchronizationHelper.AddServerSystems(world);
     PlayerLifecycleHelper.AddServerSystems(world);
     GameObjectCreationHelper.EnableStandardGameObjectCreation(world);
     world.GetOrCreateManager <CubeMovementSystem>();
     world.GetOrCreateManager <TriggerColorChangeSystem>();
     world.GetOrCreateManager <ProcessLaunchCommandSystem>();
     world.GetOrCreateManager <ProcessRechargeSystem>();
     world.GetOrCreateManager <MetricSendSystem>();
     world.GetOrCreateManager <ProcessScoresSystem>();
     world.GetOrCreateManager <CollisionProcessSystem>();
 }
Example #16
0
 public static void AddClientSystems(World world)
 {
     AddLifecycleSystems(world);
     TransformSynchronizationHelper.AddClientSystems(world);
     PlayerLifecycleHelper.AddClientSystems(world);
     GameObjectCreationHelper.EnableStandardGameObjectCreation(world);
     world.GetOrCreateSystem <ProcessColorChangeSystem>();
     world.GetOrCreateSystem <LocalPlayerInputSync>();
     world.GetOrCreateSystem <MoveLocalPlayerSystem>();
     world.GetOrCreateSystem <InitCameraSystem>();
     world.GetOrCreateSystem <FollowCameraSystem>();
     world.GetOrCreateSystem <UpdateUISystem>();
     world.GetOrCreateSystem <PlayerCommandsSystem>();
     world.GetOrCreateSystem <MetricSendSystem>();
 }
        protected override void HandleWorkerConnectionEstablished()
        {
            Worker.World.GetOrCreateSystem <MetricSendSystem>();
            PlayerLifecycleHelper.AddServerSystems(Worker.World);

            GameObjectCreationHelper.EnableStandardGameObjectCreation(Worker.World);

            TransformSynchronizationHelper.AddServerSystems(Worker.World);

            if (level == null)
            {
                return;
            }
            levelInstance = Instantiate(level, transform.position, transform.rotation);
        }
Example #18
0
        protected override void HandleWorkerConnectionEstablished()
        {
            Worker.World.GetOrCreateSystem <MetricSendSystem>();
            PlayerLifecycleHelper.AddClientSystems(Worker.World);
            var gameObjectCreator = new GameObjectCreatorFromTransform(WorkerType, transform.position);

            GameObjectCreationHelper.EnableStandardGameObjectCreation(Worker.World, gameObjectCreator, entityRepresentationMapping);
            TransformSynchronizationHelper.AddClientSystems(Worker.World);

            // if no level make one....
            if (level == null)
            {
                return;
            }
            levelInstance = Instantiate(level, transform.position, transform.rotation);
        }
 public static void AddClientSystems(World world, UnityEngine.GameObject gameObject, bool autoRequestPlayerCreation = true)
 {
     TransformSynchronizationHelper.AddClientSystems(world);
     PlayerLifecycleHelper.AddClientSystems(world, autoRequestPlayerCreation);
     GameObjectCreationHelper.EnableStandardGameObjectCreation(world, gameObject);
     world.GetOrCreateSystem <ProcessColorChangeSystem>();
     world.GetOrCreateSystem <AdvancedPlayerInputSync>();
     world.GetOrCreateSystem <MoveAdvancedUnitSystem>();
     world.GetOrCreateSystem <InitCameraSystem>();
     world.GetOrCreateSystem <FollowCameraSystem>();
     world.GetOrCreateSystem <InitUISystem>();
     world.GetOrCreateSystem <UpdateUISystem>();
     world.GetOrCreateSystem <PlayerCommandsSystem>();
     world.GetOrCreateSystem <MetricSendSystem>();
     world.GetOrCreateSystem <BulletMovementSystem>();
     world.GetOrCreateSystem <FieldQueryClientSystem>();
 }
        protected override void HandleWorkerConnectionEstablished()
        {
            Worker.World.GetOrCreateSystem <TankMovementSystem>();
            PlayerLifecycleHelper.AddClientSystems(Worker.World);

            var fallbackCreator = new GameObjectCreatorFromMetadata(Worker.WorkerType, Worker.Origin, Worker.LogDispatcher);
            var customCreator   = new CustomGameObjectCreator(fallbackCreator, Worker.World, Worker.WorkerType, Worker.Origin, Worker.LogDispatcher);

            GameObjectCreationHelper.EnableStandardGameObjectCreation(Worker.World, customCreator);
            TransformSynchronizationHelper.AddClientSystems(Worker.World);

            if (level == null)
            {
                return;
            }
            levelInstance = Instantiate(level, transform.position, transform.rotation);
        }
Example #21
0
        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);
        }
Example #22
0
        protected override void HandleWorkerConnectionEstablished()
        {
            PlayerLifecycleHelper.AddClientSystems(Worker.World);
            TransformSynchronizationHelper.AddClientSystems(Worker.World);

            // Set the Worker gameObject to the ClientWorker so it can access PlayerCreater reader/writers
            var fallback = new GameObjectCreatorFromMetadata(Worker.WorkerType, Worker.Origin, Worker.LogDispatcher);

            GameObjectCreationHelper.EnableStandardGameObjectCreation(
                Worker.World,
                new AdvancedEntityPipeline(Worker, AuthPlayer, NonAuthPlayer, fallback),
                gameObject);



            JoinButton.GetComponent <Button>().interactable = true;
            JoinButton.SetActive(false);
            LeaveButton.SetActive(true);
        }
        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);
        }
Example #24
0
        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);
        }
Example #25
0
 public static void AddClientSystems(World world, bool autoRequestPlayerCreation = true)
 {
     TransformSynchronizationHelper.AddClientSystems(world);
     PlayerLifecycleHelper.AddClientSystems(world, autoRequestPlayerCreation);
     world.GetOrCreateSystem <LocalLockOnSystem>();
     world.GetOrCreateSystem <AimAnimationLocalSystem>();
     world.GetOrCreateSystem <AdvancedPlayerInputSync>();
     world.GetOrCreateSystem <MoveAdvancedUnitSystem>();
     world.GetOrCreateSystem <InitCameraSystem>();
     world.GetOrCreateSystem <FollowCameraSystem>();
     world.GetOrCreateSystem <PlayerCommandsSystem>();
     world.GetOrCreateSystem <MetricSendSystem>();
     world.GetOrCreateSystem <BulletMovementSystem>();
     world.GetOrCreateSystem <FieldQueryClientSystem>();
     world.GetOrCreateSystem <SpawnPointQuerySystem>();
     world.GetOrCreateSystem <UnitUIInfoSystem>();
     world.GetOrCreateSystem <MiniMapUISystem>();
     world.GetOrCreateSystem <LocalTimerUpdateSystem>();
     world.GetOrCreateSystem <SymbolicObjectSystem>();
 }
Example #26
0
 public static void AddGameLogicSystems(World world)
 {
     TransformSynchronizationHelper.AddServerSystems(world);
     PlayerLifecycleHelper.AddServerSystems(world);
     world.GetOrCreateSystem <ProcessLaunchCommandSystem>();
     world.GetOrCreateSystem <ProcessRechargeSystem>();
     world.GetOrCreateSystem <MetricSendSystem>();
     world.GetOrCreateSystem <ProcessScoresSystem>();
     world.GetOrCreateSystem <CollisionProcessSystem>();
     world.GetOrCreateSystem <RootPostureSyncSystem>();
     //world.GetOrCreateSystem<PostureAnimationSyncSystem>();
     world.GetOrCreateSystem <AimAnimationLocalSystem>();
     world.GetOrCreateSystem <BaseUnitMovementSystem>();
     world.GetOrCreateSystem <BaseUnitSightSystem>();
     //world.GetOrCreateSystem<BaseUnitPhysicsSystem>();
     world.GetOrCreateSystem <BaseUnitSearchSystem>();
     world.GetOrCreateSystem <BaseUnitActionSystem>();
     world.GetOrCreateSystem <CommanderUnitSearchSystem>();
     //world.GetOrCreateSystem<CommanderActionSystem>();
     //world.GetOrCreateSystem<BoidsUpdateSystem>();
     world.GetOrCreateSystem <UnitFactorySystem>();
     world.GetOrCreateSystem <StrategyOrderManagerSystem>();
     //world.GetOrCreateSystem<ResourceSupplyManagerSystem>();
     //world.GetOrCreateSystem<UnitArmyObserveSystem>();
     //world.GetOrCreateSystem<CommandersManagerSystem>();
     world.GetOrCreateSystem <StrategyHexAccessPortalUpdateSystem>();
     world.GetOrCreateSystem <DominationSystem>();
     world.GetOrCreateSystem <StrongholdSearchSystem>();
     world.GetOrCreateSystem <StrongholdActionSystem>();
     world.GetOrCreateSystem <BulletMovementSystem>();
     world.GetOrCreateSystem <BaseUnitReviveTimerSystem>();
     world.GetOrCreateSystem <FieldQueryServerSystem>();
     world.GetOrCreateSystem <HexBaseSystem>();
     world.GetOrCreateSystem <HexUpdateSystem>();
     world.GetOrCreateSystem <HexPowerUpdateSystem>();
     world.GetOrCreateSystem <TurretUpdateSystem>();
     world.GetOrCreateSystem <SleepUpdateSystem>();
     world.GetOrCreateSystem <VirtualArmyUpdateSystem>();
     world.GetOrCreateSystem <LocalTimerUpdateSystem>();
     world.GetOrCreateSystem <TimerSynchronizeSystem>();
 }
Example #27
0
        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);
        }
Example #28
0
        public static EntityTemplate CreateCubeEntityTemplate()
        {
            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot {
                EntityType = "Cube"
            }, WorkerUtils.UnityGameLogic);
            template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new CubeColor.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new CubeTargetVelocity.Snapshot {
                TargetVelocity = new Vector3f(-2.0f, 0, 0)
            },
                                  WorkerUtils.UnityGameLogic);
            template.AddComponent(new Launchable.Snapshot(), WorkerUtils.UnityGameLogic);
            TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, WorkerUtils.UnityGameLogic);

            template.SetReadAccess(WorkerUtils.UnityGameLogic, WorkerUtils.UnityClient);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);

            return(template);
        }
Example #29
0
        public static void AddClientSystems(World world)
        {
            AddLifecycleSystems(world);
            TransformSynchronizationHelper.AddClientSystems(world);
            PlayerLifecycleHelper.AddClientSystems(world);
            GameObjectRepresentationHelper.AddSystems(world);
            GameObjectCreationHelper.EnableStandardGameObjectCreation(world);

            /*
             * world.GetOrCreateManager<ProcessColorChangeSystem>();
             * world.GetOrCreateManager<LocalPlayerInputSync>();
             * world.GetOrCreateManager<MoveLocalPlayerSystem>();
             * world.GetOrCreateManager<InitCameraSystem>();
             * world.GetOrCreateManager<FollowCameraSystem>();
             * world.GetOrCreateManager<InitUISystem>();
             * world.GetOrCreateManager<UpdateUISystem>();
             */
            world.GetOrCreateManager <PlayerCommandsSystem>();
            world.GetOrCreateManager <ProcessPlayerResponseSystem>();//process preauth responses from server

            world.GetOrCreateManager <MetricSendSystem>();
        }
Example #30
0
        public static EntityTemplate CreateBaseUnitEntityTemplate(UnitSide side, UnitType type, Coordinates coords, CompressedQuaternion?rotation = null, FixedPointVector3?scale = null, OrderType?order = null, uint?rank = null)
        {
            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(coords), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot(metaDic[type]), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new PostureRoot.Snapshot()
            {
                RootTrans = PostureUtils.ConvertTransform(coords, rotation, scale)
            }, WorkerUtils.UnityGameLogic);

            template.AddComponent(new BaseUnitSight.Snapshot(), WorkerUtils.UnityGameLogic);
            //template.AddComponent(new BaseUnitAction.Snapshot { EnemyPositions = new List<FixedPointVector3>() }, WorkerUtils.UnityGameLogic);
            template.AddComponent(new BaseUnitStatus.Snapshot(side, type, UnitState.Alive, order == null ? orderDic[type] : order.Value, GetRank(rank, type)), WorkerUtils.UnityGameLogic);
            template.AddComponent(new BaseUnitTarget.Snapshot().DefaultSnapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Launchable.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new BaseUnitHealth.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new GunComponent.Snapshot {
                GunsDic = new Dictionary <int, GunInfo>()
            }, WorkerUtils.UnityGameLogic);
            template.AddComponent(new FuelComponent.Snapshot(), WorkerUtils.UnityGameLogic);

            if (type.BaseType() == UnitBaseType.Moving)
            {
                template.AddComponent(new BaseUnitMovement.Snapshot(), WorkerUtils.UnityGameLogic);
                template.AddComponent(new BaseUnitReviveTimer.Snapshot {
                    IsStart = false, RestTime = 0.0f
                }, WorkerUtils.UnityGameLogic);
            }

            SwitchType(template, type, WorkerUtils.UnityGameLogic);
            TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, WorkerUtils.UnityGameLogic);

            template.SetReadAccess(GetReadAttributes(type));
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);

            return(template);
        }