예제 #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);
        }
예제 #2
0
        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);
        }
예제 #3
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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        public static InterestTemplate CreateQuery()
        {
            var radiusQuery = InterestQuery.Query(Constraint.RelativeSphere(100));

            InterestTemplate interestTemplate =
                InterestTemplate.Create().AddQueries <TankColor.Component>(radiusQuery);

            return(interestTemplate);
        }
예제 #6
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);
        }
예제 #7
0
        static void AddSymbolicTowerQuery <T>(InterestTemplate interest) where T : ISpatialComponentData
        {
            var towerQuery = InterestQuery.Query(
                Constraint.All(
                    Constraint.Component(SymbolicTower.ComponentId),
                    Constraint.RelativeSphere(FixedParams.WorldInterestLimit)))
                             .FilterResults(Position.ComponentId,
                                            SymbolicTower.ComponentId,
                                            Metadata.ComponentId)
                             .WithMaxFrequencyHz(FixedParams.WorldInterestFrequency);

            interest.AddQueries <T>(towerQuery);
        }
        public void Create_from_template_modifies_a_deep_copy()
        {
            var originalInterest = EmptyInterest
                                   .AddQueries <Position.Component>(BasicQuery)
                                   .AddQueries <Metadata.Component>(BasicQuery);

            var modifiedInterest = InterestTemplate
                                   .Create(originalInterest)
                                   .ClearQueries <Position.Component>()
                                   .AsComponentInterest();

            Assert.AreEqual(2, originalInterest.AsComponentInterest().Keys.Count);
            Assert.AreEqual(1, modifiedInterest.Keys.Count);
        }
        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);
        }
예제 #10
0
        static void AddMinimapQuery <T>(InterestTemplate interest) where T : ISpatialComponentData
        {
            var minimapQuery = InterestQuery.Query(
                Constraint.All(
                    Constraint.Any(Constraint.Component(CommanderStatus.ComponentId),
                                   Constraint.Component(StrongholdStatus.ComponentId),
                                   Constraint.Component(HeadQuarters.ComponentId)),
                    Constraint.RelativeSphere(FixedParams.WorldInterestLimit)))
                               .FilterResults(Position.ComponentId,
                                              BaseUnitStatus.ComponentId,
                                              TransformInternal.ComponentId)
                               .WithMaxFrequencyHz(FixedParams.WorldInterestFrequency);

            interest.AddQueries <T>(minimapQuery);
        }
예제 #11
0
        void Test()
        {
            var playerQuery = InterestQuery.Query(
                Constraint.All(
                    Constraint.Component <PlayerInfo.Component>(),
                    Constraint.RelativeSphere(20))
                ).FilterResults(Position.ComponentId, PlayerInfo.ComponentId);

            var minimapQuery = InterestQuery.Query(
                Constraint.All(
                    Constraint.Component <MinimapRepresentaion.Component>(),
                    Constraint.RelativeBox(50, double.PositiveInfinity, 50))
                ).FilterResults(Position.ComponentId, MinimapRepresentaion.ComponentId);

            var interestTemplate = InterestTemplate.Create()
                                   .AddQueries <PlayerControls.Component>(playerQuery, minimapQuery);

            var playerTemplate = new EntityTemplate();

            playerTemplate.AddComponent(interestTemplate.ToSnapshot(), WorkerUtils.UnityGameLogic);
        }
        private static EntityTemplate CreatePlayerEntityTemplate(string workerId, byte[] serializedArguments)
        {
            var clientAttribute = EntityTemplate.GetWorkerAccessAttribute(workerId);

            var resourceQuery    = InterestQuery.Query(Constraint.RelativeCylinder(50.0));
            var interestTemplate = InterestTemplate.Create();

            interestTemplate.AddQueries <Position.Component>(resourceQuery);

            var template = new EntityTemplate();

            // TODO: Don't give the client authority over the Position component.
            template.AddComponent(new Position.Snapshot(), clientAttribute);
            template.AddComponent(new Metadata.Snapshot("Player"), WorkerType);
            template.AddComponent(interestTemplate.ToSnapshot(), WorkerType);
            PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, WorkerType);

            template.SetReadAccess(WorkerUtils.AllWorkers);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerType);

            return(template);
        }
예제 #13
0
        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.AddComponent(new WorldTimer.Snapshot(), WorkerUtils.UnityGameLogic);

            var query    = InterestQuery.Query(Constraint.RelativeCylinder(500));
            var interest = InterestTemplate.Create()
                           .AddQueries <Position.Component>(query);

            template.AddComponent(interest.ToSnapshot(), WorkerUtils.UnityGameLogic);

            template.SetReadAccess(WorkerUtils.UnityGameLogic, WorkerUtils.UnityClient, WorkerUtils.MobileClient);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);
            snapshot.AddEntity(template);
        }
예제 #14
0
        public static EntityTemplate CreateSphereTemplate(Quaternion rotation, Vector3 position = default)
        {
            var serverAttribute = UnityGameLogicConnector.WorkerType;

            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(Coordinates.FromUnityVector(position)), serverAttribute);
            template.AddComponent(new Metadata.Snapshot("Sphere"), serverAttribute);
            template.AddComponent(new Persistence.Snapshot(), serverAttribute);

            TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, serverAttribute, rotation, position);

            const int serverRadius = 500;

            var query    = InterestQuery.Query(Constraint.RelativeCylinder(serverRadius));
            var interest = InterestTemplate.Create().AddQueries <Position.Component>(query);

            template.AddComponent(interest.ToSnapshot());

            template.SetReadAccess(UnityClientConnector.WorkerType, MobileClientWorkerConnector.WorkerType, serverAttribute);

            return(template);
        }
예제 #15
0
        public static EntityTemplate Player(EntityId entityId, string workerId, byte[] args)
        {
            var client = EntityTemplate.GetWorkerAccessAttribute(workerId);

            var(spawnPosition, spawnYaw, spawnPitch) = SpawnPoints.GetRandomSpawnPoint();

            var serverResponse = new ServerResponse
            {
                Position = spawnPosition.ToVector3Int()
            };

            var rotationUpdate = new RotationUpdate
            {
                Yaw   = spawnYaw.ToInt1k(),
                Pitch = spawnPitch.ToInt1k()
            };

            var pos = new Position.Snapshot {
                Coords = Coordinates.FromUnityVector(spawnPosition)
            };
            var serverMovement = new ServerMovement.Snapshot {
                Latest = serverResponse
            };
            var clientMovement = new ClientMovement.Snapshot {
                Latest = new ClientRequest()
            };
            var clientRotation = new ClientRotation.Snapshot {
                Latest = rotationUpdate
            };
            var shootingComponent = new ShootingComponent.Snapshot();
            var gunComponent      = new GunComponent.Snapshot {
                GunId = PlayerGunSettings.DefaultGunIndex
            };
            var gunStateComponent = new GunStateComponent.Snapshot {
                IsAiming = false
            };
            var healthComponent = new HealthComponent.Snapshot
            {
                Health    = PlayerHealthSettings.MaxHealth,
                MaxHealth = PlayerHealthSettings.MaxHealth,
            };

            var healthRegenComponent = new HealthRegenComponent.Snapshot
            {
                CooldownSyncInterval = PlayerHealthSettings.SpatialCooldownSyncInterval,
                DamagedRecently      = false,
                RegenAmount          = PlayerHealthSettings.RegenAmount,
                RegenCooldownTimer   = PlayerHealthSettings.RegenAfterDamageCooldown,
                RegenInterval        = PlayerHealthSettings.RegenInterval,
                RegenPauseTime       = 0,
            };

            var template = new EntityTemplate();

            template.AddComponent(pos, WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot {
                EntityType = "Player"
            }, WorkerUtils.UnityGameLogic);
            template.AddComponent(serverMovement, WorkerUtils.UnityGameLogic);
            template.AddComponent(clientMovement, client);
            template.AddComponent(clientRotation, client);
            template.AddComponent(shootingComponent, client);
            template.AddComponent(gunComponent, WorkerUtils.UnityGameLogic);
            template.AddComponent(gunStateComponent, client);
            template.AddComponent(healthComponent, WorkerUtils.UnityGameLogic);
            template.AddComponent(healthRegenComponent, WorkerUtils.UnityGameLogic);

            PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, WorkerUtils.UnityGameLogic);

            const int serverRadius = 150;
            var       clientRadius = workerId.Contains(WorkerUtils.MobileClient) ? 60 : 150;

            // Position, Metadata, OwningWorker and ServerMovement are included in all queries, since these
            // components are required by the GameObject creator.

            // HealthComponent is needed by the LookAtRagdoll script for respawn behaviour.
            // GunComponent is needed by the GunManager script.
            var clientSelfInterest = InterestQuery.Query(Constraint.EntityId(entityId)).FilterResults(new[]
            {
                Position.ComponentId, Metadata.ComponentId, OwningWorker.ComponentId,
                ServerMovement.ComponentId, HealthComponent.ComponentId, GunComponent.ComponentId
            });

            // ClientRotation is used for rendering other players.
            // GunComponent is required by the GunManager script.
            // GunStateComponent and ShootingComponent are needed for rendering other players' shots.
            var clientRangeInterest = InterestQuery.Query(Constraint.RelativeCylinder(clientRadius)).FilterResults(new[]
            {
                Position.ComponentId, Metadata.ComponentId, OwningWorker.ComponentId,
                ServerMovement.ComponentId, ClientRotation.ComponentId, HealthComponent.ComponentId,
                GunComponent.ComponentId, GunStateComponent.ComponentId, ShootingComponent.ComponentId
            });

            // ClientMovement is used by the ServerMovementDriver script.
            // ShootingComponent is used by the ServerShootingSystem.
            var serverSelfInterest = InterestQuery.Query(Constraint.EntityId(entityId)).FilterResults(new[]
            {
                ClientMovement.ComponentId, ShootingComponent.ComponentId
            });

            // ClientRotation is used for driving player proxies.
            // HealthComponent is required by the VisiblityAndCollision script.
            // ShootingComponent is used by the ServerShootingSystem.
            var serverRangeInterest = InterestQuery.Query(Constraint.RelativeCylinder(serverRadius)).FilterResults(new[]
            {
                Position.ComponentId, Metadata.ComponentId, OwningWorker.ComponentId,
                ServerMovement.ComponentId, ClientRotation.ComponentId, HealthComponent.ComponentId,
                ShootingComponent.ComponentId
            });

            var interest = InterestTemplate.Create()
                           .AddQueries <ClientMovement.Component>(clientSelfInterest, clientRangeInterest)
                           .AddQueries <ServerMovement.Component>(serverSelfInterest, serverRangeInterest);

            template.AddComponent(interest.ToSnapshot());

            template.SetReadAccess(WorkerUtils.UnityClient, WorkerUtils.UnityGameLogic, WorkerUtils.MobileClient);

            return(template);
        }
        public static EntityTemplate Player(string workerId, byte[] args)
        {
            var client = EntityTemplate.GetWorkerAccessAttribute(workerId);

            var(spawnPosition, spawnYaw, spawnPitch) = SpawnPoints.GetRandomSpawnPoint();

            var serverResponse = new ServerResponse
            {
                Position = spawnPosition.ToIntAbsolute()
            };

            var rotationUpdate = new RotationUpdate
            {
                Yaw   = spawnYaw.ToInt1k(),
                Pitch = spawnPitch.ToInt1k()
            };

            var pos = new Position.Snapshot {
                Coords = spawnPosition.ToSpatialCoordinates()
            };
            var serverMovement = new ServerMovement.Snapshot {
                Latest = serverResponse
            };
            var clientMovement = new ClientMovement.Snapshot {
                Latest = new ClientRequest()
            };
            var clientRotation = new ClientRotation.Snapshot {
                Latest = rotationUpdate
            };
            var shootingComponent = new ShootingComponent.Snapshot();
            var gunComponent      = new GunComponent.Snapshot {
                GunId = PlayerGunSettings.DefaultGunIndex
            };
            var gunStateComponent = new GunStateComponent.Snapshot {
                IsAiming = false
            };
            var healthComponent = new HealthComponent.Snapshot
            {
                Health    = PlayerHealthSettings.MaxHealth,
                MaxHealth = PlayerHealthSettings.MaxHealth,
            };

            var healthRegenComponent = new HealthRegenComponent.Snapshot
            {
                CooldownSyncInterval = PlayerHealthSettings.SpatialCooldownSyncInterval,
                DamagedRecently      = false,
                RegenAmount          = PlayerHealthSettings.RegenAmount,
                RegenCooldownTimer   = PlayerHealthSettings.RegenAfterDamageCooldown,
                RegenInterval        = PlayerHealthSettings.RegenInterval,
                RegenPauseTime       = 0,
            };

            var sessionQuery  = InterestQuery.Query(Constraint.Component <Session.Component>());
            var checkoutQuery = InterestQuery.Query(Constraint.RelativeCylinder(150));

            var interestTemplate  = InterestTemplate.Create().AddQueries <ClientMovement.Component>(sessionQuery, checkoutQuery);
            var interestComponent = interestTemplate.ToSnapshot();

            var playerName = Encoding.ASCII.GetString(args);

            var playerStateComponent = new PlayerState.Snapshot
            {
                Name   = playerName,
                Kills  = 0,
                Deaths = 0,
            };


            var playerResComponent      = new Pickups.PlayerRes.Snapshot(0);
            var soldierManagerComponent = new Soldiers.SoldierManager.Snapshot();


            var template = new EntityTemplate();

            template.AddComponent(pos, WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot {
                EntityType = "Player"
            }, WorkerUtils.UnityGameLogic);
            template.AddComponent(serverMovement, WorkerUtils.UnityGameLogic);
            template.AddComponent(clientMovement, client);
            template.AddComponent(clientRotation, client);

            template.AddComponent(shootingComponent, client);
            template.AddComponent(gunComponent, WorkerUtils.UnityGameLogic);
            template.AddComponent(gunStateComponent, client);
            template.AddComponent(healthComponent, WorkerUtils.UnityGameLogic);
            template.AddComponent(healthRegenComponent, WorkerUtils.UnityGameLogic);
            template.AddComponent(playerStateComponent, WorkerUtils.UnityGameLogic);

            template.AddComponent(interestComponent, WorkerUtils.UnityGameLogic);

            template.AddComponent(playerResComponent, WorkerUtils.UnityGameLogic);
            template.AddComponent(soldierManagerComponent, WorkerUtils.UnityGameLogic);


            PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, WorkerUtils.UnityGameLogic);

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

            return(template);
        }
예제 #17
0
        static void AddBasicQuery <T>(InterestTemplate interest) where T : ISpatialComponentData
        {
            var basicQuery = InterestQuery.Query(Constraint.RelativeSphere(FixedParams.PlayerInterestLimit));

            interest.AddQueries <T>(basicQuery);
        }
        private static void SwitchType(EntityTemplate template, UnitType type, string writeAccess)
        {
            switch (type)
            {
            case UnitType.Soldier:
                template.AddComponent(new BulletComponent.Snapshot(), writeAccess);
                template.AddComponent(new BaseUnitPosture.Snapshot {
                    Posture = new PostureInfo {
                        Datas = new Dictionary <PosturePoint, PostureData>()
                    }
                }, writeAccess);
                break;

            case UnitType.Commander:
                template.AddComponent(new BulletComponent.Snapshot(), writeAccess);
                template.AddComponent(new CommanderStatus.Snapshot {
                    Order = new OrderPair {
                        Self = OrderType.Idle, Upper = OrderType.Idle
                    },
                    Rank = 0,
                }, writeAccess);
                template.AddComponent(new CommanderTeam.Snapshot {
                    FollowerInfo = new FollowerInfo {
                        Followers = new List <EntityId>(), UnderCommanders = new List <EntityId>()
                    },
                    SuperiorInfo = new SuperiorInfo()
                }, writeAccess);
                template.AddComponent(new CommanderSight.Snapshot {
                    WarPowers = new List <WarPower>()
                }, writeAccess);
                template.AddComponent(new CommanderAction.Snapshot {
                    ActionType = CommandActionType.None
                }, writeAccess);
                template.AddComponent(new BaseUnitPosture.Snapshot {
                    Posture = new PostureInfo {
                        Datas = new Dictionary <PosturePoint, PostureData>()
                    }
                }, writeAccess);
                template.AddComponent(new DominationDevice.Snapshot {
                    Type = DominationDeviceType.Capturing, Speed = 0.0f,
                }, writeAccess);
                break;

            case UnitType.Stronghold:
                template.AddComponent(new StrongholdUnitStatus.Snapshot(), writeAccess);
                template.AddComponent(new UnitFactory.Snapshot {
                    FollowerOrders = new List <FollowerOrder>(), SuperiorOrders = new List <SuperiorOrder>()
                }, writeAccess);
                template.AddComponent(new UnitArmyObserver.Snapshot(), writeAccess);
                template.AddComponent(new DominationStamina.Snapshot {
                    SideStaminas = new Dictionary <UnitSide, float>()
                }, writeAccess);
                break;

            case UnitType.HeadQuarter:
                //template.AddComponent(new HeadQuarters.Snapshot { UpperRank = 0,
                //                                                 FactoryDatas = new FactoryMap { Reserves = new Dictionary<EntityId,ReserveMap>() },
                //                                                 Orders = new List<OrganizeOrder>() }, writeAccess);
                template.AddComponent(new CommandersManager.Snapshot {
                    State          = CommanderManagerState.None,
                    CommanderDatas = new Dictionary <EntityId, TeamInfo>()
                }, writeAccess);
                var strongholdQuery = InterestQuery.Query(Constraint.Component <StrongholdUnitStatus.Component>())
                                      .FilterResults(Position.ComponentId, BaseUnitStatus.ComponentId);
                var interestTemplate = InterestTemplate.Create().AddQueries <CommandersManager.Component>(strongholdQuery);
                template.AddComponent(interestTemplate.ToSnapshot(), writeAccess);
                break;
            }
        }
예제 #19
0
        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 {
                IsPlayer = isPlayer
            }, controllAttribute);
            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);

            InterestTemplate interest = InterestTemplate.Create();

            if (isPlayer)
            {
                template.AddComponent(new AdvancedPlayerInput.Snapshot(), controllAttribute);
                template.AddComponent(new PlayerInfo.Snapshot {
                    ClientWorkerId = workerId
                }, controllAttribute);
                PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, WorkerUtils.UnityGameLogic);

                // for minimap QBI
                template.AddComponent(new MinimapComponent.Snapshot(), controllAttribute);
                AddMinimapQuery <MinimapComponent.Component>(interest);

                // for symbolic_tower QBI
                template.AddComponent(new SymbolicTowerSight.Snapshot(), controllAttribute);
                AddSymbolicTowerQuery <SymbolicTowerSight.Component>(interest);
            }
            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);

            // 共通QBI
            AddBasicQuery <Position.Component>(interest);
            template.AddComponent(interest.ToSnapshot(), controllAttribute);

            template.SetReadAccess(UnityClientConnector.WorkerType, MobileClientWorkerConnector.WorkerType, WorkerUtils.UnityGameLogic);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);

            return(template);
        }