示例#1
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);
        }
        private static void AddHealer(Snapshot snapshot)
        {
            var healerAttribute = UnityHealerConnector.WorkerType;
//            var serverAttribute = UnityGameLogicConnector.WorkerType;

            var healer   = new Healer.HealValue.Snapshot(GameConstants.HealerValue);
            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(new Coordinates(6, 2, 0)), healerAttribute);
            template.AddComponent(new Metadata.Snapshot("Healer"), healerAttribute);
            template.AddComponent(new Persistence.Snapshot(), healerAttribute);
            template.AddComponent(healer, healerAttribute);
//            template.AddComponent(new Position.Snapshot(new Coordinates(6, 2, 0)), serverAttribute);
//            template.AddComponent(new Metadata.Snapshot("Healer"), serverAttribute);
//            template.AddComponent(new Persistence.Snapshot(), serverAttribute);
//            template.AddComponent(healer, serverAttribute);

            template.SetReadAccess(
                UnityClientConnector.WorkerType,
                UnityGameLogicConnector.WorkerType,
                MobileClientWorkerConnector.WorkerType,
                UnityHealerConnector.WorkerType);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, healerAttribute);
//            template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute);

            snapshot.AddEntity(template);
        }
示例#3
0
        private static void AddTree(Snapshot snapshot, Vector3f position)
        {
            var spawnRotation = (uint)Mathf.CeilToInt((float)rand.NextDouble() * 360.0f);
            var entity        = EntityTemplateFactory.CreateTreeTemplate(position, spawnRotation);

            snapshot.AddEntity(entity);
        }
示例#4
0
        public static void AddEggs(Snapshot snapshot, Coordinates position, float edgeLength)
        {
            float totalEggs = SimulationSettings.HQStartingEggTRexCount + SimulationSettings.HQStartingEggBrachioCount;

            for (int i = 0; i < totalEggs; i++)
            {
                Vector3 offset = new Vector3(Random.Range(-edgeLength / 2, edgeLength / 2), 0,
                                             Random.Range(-edgeLength / 2, edgeLength / 2));
                Coordinates coordinates = (position.ToVector3() + offset).ToCoordinates();

                EntityTemplate entity = null;
                if (i < SimulationSettings.HQStartingEggBrachioCount)
                {
                    entity = EntityTemplateFactory.CreateEggTemplate(coordinates, 0, EggTypeEnum.Brachiosaurus);
                }
                else
                {
                    entity = EntityTemplateFactory.CreateEggTemplate(coordinates, 0, EggTypeEnum.TRex);
                }

                if (entity != null)
                {
                    snapshot.AddEntity(entity);
                }
            }
            Debug.Log("Snapshot Dinosaur Eggs generated ! count<" + totalEggs + ">");
        }
示例#5
0
        public static void AddTrees(Snapshot snapshot, Texture2D sampler, float sampleThreshold, int countAproximate, float edgeLength, float placementJitter)
        {
            var treeCountSqrt      = Mathf.CeilToInt(Mathf.Sqrt(countAproximate));
            var spawnGridIntervals = edgeLength / treeCountSqrt;
            int countTree          = 0;

            for (var z = 0; z < treeCountSqrt; z++)
            {
                var zProportion = z / (float)treeCountSqrt;

                for (var x = 0; x < treeCountSqrt; x++)
                {
                    var xProportion = x / (float)treeCountSqrt;
                    var xPixel      = (int)(xProportion * sampler.width);
                    var zPixel      = (int)(zProportion * sampler.height);
                    var sample      = sampler.GetPixel(xPixel, zPixel).maxColorComponent;

                    if (sample > sampleThreshold && Random.value < sample)
                    {
                        var     xJitter        = Random.Range(-placementJitter, placementJitter);
                        var     zJitter        = Random.Range(-placementJitter, placementJitter);
                        Vector3 positionJitter = new Vector3(xJitter, 0f, zJitter);

                        Vector3f worldRoot           = new Vector3f(-edgeLength / 2, 0, -edgeLength / 2);
                        Vector3  offsetFromWorldRoot = new Vector3(x, 0f, z) * spawnGridIntervals;
                        Vector3f spawnPosition       = worldRoot + Vector3f.FromUnityVector(offsetFromWorldRoot + positionJitter);
                        AddTree(snapshot, spawnPosition);
                        countTree++;
                    }
                }
            }
            Debug.Log("Snapshot trees generated ! count<" + countTree + ">");
        }
        private static Snapshot CreateSnapshot()
        {
            var snapshot = new Snapshot();

            AddPlayerSpawner(snapshot);
            return(snapshot);
        }
 private static void AddFields(Snapshot snapshot, List <FieldSnapshot> fields)
 {
     foreach (var f in fields)
     {
         snapshot.AddEntity(FieldTemplate.CreateFieldEntityTemplate(f.pos.ToCoordinates(), f.range, f.highest, f.materialType, f.seeds));
     }
 }
示例#8
0
        public static void SpawnNpcsAroundPosition(Snapshot snapshot, Coordinates position, uint team, float edgeLength)
        {
            float totalNpcs = SimulationSettings.HQStartingTRexCount + SimulationSettings.HQStartingBrachioCount;

            for (int i = 0; i < totalNpcs; i++)
            {
                Vector3 offset = new Vector3(Random.Range(-edgeLength / 2, edgeLength / 2), 0,
                                             Random.Range(-edgeLength / 2, edgeLength / 2));
                Coordinates coordinates = (position.ToVector3() + offset).ToCoordinates();

                EntityTemplate entity = null;
                if (i < SimulationSettings.HQStartingBrachioCount)
                {
                    entity = EntityTemplateFactory.CreateDinoBrachioTemplate(coordinates, team, 70); // 成年恐龙
                }
                else
                {
                    entity = EntityTemplateFactory.CreateDinoTRexTemplate(coordinates, team, 70); // 成年恐龙
                }

                if (entity != null)
                {
                    snapshot.AddEntity(entity);
                }
            }
            Debug.Log("Snapshot Dinosaurs generated ! count<" + totalNpcs + ">");
        }
示例#9
0
 public static void AddNPCsAroundHQs(Snapshot snapshot, Coordinates[] locations, float edgeLength)
 {
     for (uint teamId = 0; teamId < locations.Length; teamId++)
     {
         SpawnNpcsAroundPosition(snapshot, locations[teamId], teamId, edgeLength);
     }
 }
示例#10
0
        private static Snapshot CreateSnapshot()
        {
            var snapshot = new Snapshot();

            SnapshotDefault.Build(snapshot);

            return(snapshot);
        }
示例#11
0
        private static void AddCube(Snapshot snapshot)
        {
            // Invoke our static function to create an entity template of our health pack with 100 heath.
            var cube = EntityTemplates.Cube(new Vector3f(-11, 6, 30));

            // Add the entity template to the snapshot.
            snapshot.AddEntity(cube);
        }
示例#12
0
        private static void AddBall(Snapshot snapshot)
        {
            // Invoke our static function to create an entity template of our ball.
            var ball = EntityTemplates.Ball(new Vector3f(-5, 5, 25));

            // Add the entity template to the snapshot.
            snapshot.AddEntity(ball);
        }
 private static void AddUnits(Snapshot snapshot, GetSnapshotHeight ground, List <UnitSnapshot> units)
 {
     foreach (var u in units)
     {
         var template = BaseUnitTemplate.CreateBaseUnitEntityTemplate(u.side, GroundCoordinates(u.pos.x, u.pos.y, u.pos.z), u.type);
         snapshot.AddEntity(template);
     }
 }
示例#14
0
        private static void AddTankUnitClient(Snapshot snapshot)
        {
            // Invoke our static function to create an entity template of our health pack with 100 heath.
            var tankUnitClient = EntityTemplates.TankUnitClient(new Vector3f(-5, 5, -5), 4, 4);

            // Add the entity template to the snapshot.
            snapshot.AddEntity(tankUnitClient);
        }
示例#15
0
        private static Snapshot CreateSnapshot()
        {
            var snapshot = new Snapshot();

            AddPlayerSpawner(snapshot);
            AddCube(snapshot);
            AddBall(snapshot);
            AddTankUnit(snapshot);
            AddTankUnitClient(snapshot);
            return(snapshot);
        }
        private static void AddWorldTimer(Snapshot snapshot, Coordinates location)
        {
            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(location), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot("WorldTimer"), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new WorldTimer.Snapshot(), WorkerUtils.UnityGameLogic);

            template.SetReadAccess(WorkerUtils.UnityGameLogic, WorkerUtils.UnityClient, WorkerUtils.MobileClient);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);
            snapshot.AddEntity(template);
        }
示例#17
0
        private static Snapshot CreateSnapshot()
        {
            var snapshot = new Snapshot();

            AddPlayerSpawner(snapshot);

            snapshot.AddEntity(EntityCreationTemplate.CreateLandEntity());
            for (int i = 0; i < 10; i++)
            {
                snapshot.AddEntity(EntityCreationTemplate.CreateNPCEntity());
            }
            return(snapshot);
        }
示例#18
0
        private static void AddSpheres(Snapshot snapshot)
        {
            AddSphere(snapshot, new Vector3(-10f, 0.5f, 10f));
            AddSphere(snapshot, new Vector3(10f, 5f, 10f));
            AddSphere(snapshot, new Vector3(25f, 0.5f, 0f));

            var rotation = new Quaternion
            {
                eulerAngles = new Vector3(90, 0, 0)
            };

            AddSphere(snapshot, new Vector3(-4f, 0.5f, 4f), rotation);
            AddSphere(snapshot, new Vector3(-4f, 0.5f, 7f));
        }
示例#19
0
        private static void AddPlayerSpawner(Snapshot snapshot)
        {
            var playerCreator   = PlayerCreator.Component.CreateSchemaComponentData();
            var serverAttribute = UnityGameLogicConnector.WorkerType;

            var spawner = EntityBuilder.Begin()
                          .AddPosition(0, 0, 0, serverAttribute)
                          .AddMetadata("PlayerCreator", serverAttribute)
                          .SetPersistence(true)
                          .SetReadAcl(UnityWorkers)
                          .AddComponent(playerCreator, serverAttribute)
                          .Build();

            snapshot.AddEntity(spawner);
        }
        private static void AddCubeGrid(Snapshot snapshot, int cubeCount, GetSnapshotHeight ground = null)
        {
            // Calculate grid size
            var gridLength = (int)Math.Ceiling(Math.Sqrt(cubeCount));

            if (gridLength % 2 == 1) // To make sure nothing is in (0, 0)
            {
                gridLength += 1;
            }

            var cubesToSpawn = cubeCount;

            for (var x = -gridLength + 1; x <= gridLength - 1; x += 2)
            {
                for (var z = -gridLength + 1; z <= gridLength - 1; z += 2)
                {
                    // Leave the centre empty
                    if (x == 0 && z == 0)
                    {
                        continue;
                    }

                    // Exit when we've hit our cube limit
                    if (cubesToSpawn-- <= 0)
                    {
                        return;
                    }

                    UnitSide side = x < 0 ? UnitSide.A : UnitSide.B;
                    int      nx;
                    if (x < 0)
                    {
                        nx = x - 3;
                    }
                    else
                    {
                        nx = x + 3;
                    }

                    double pos_x          = nx * scale;
                    double pos_z          = z * scale;
                    var    entityTemplate = BaseUnitTemplate.CreateBaseUnitEntityTemplate(side, GroundCoordinates(pos_x, pos_z, ground), UnitType.Soldier);
                    snapshot.AddEntity(entityTemplate);
                }
            }

            AddDefaultUnits(snapshot, ground);
        }
        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.SetReadAccess(WorkerUtils.UnityGameLogic, WorkerUtils.UnityClient, WorkerUtils.MobileClient);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);

            snapshot.AddEntity(template);
        }
        public static Snapshot GenerateGroundSnapshot(float fieldSize, GetSnapshotHeight ground = null)
        {
            var snapshot = new Snapshot();

            int count = (int)Mathf.Round(fieldSize / standardSize) * 2;

            for (int i = 0; i <= count; i++)
            {
                for (int j = 0; j <= count; j++)
                {
                    var length_x = standardSize * (i - (count - 1) / 2.0f);
                    var length_z = standardSize * (j - (count - 1) / 2.0f);
                    AddPlayerSpawner(snapshot, GroundCoordinates(length_x, length_z, ground));
                }
            }

            return(snapshot);
        }
示例#23
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 {
                EntityType = "PlayerCreator"
            }, serverAttribute);
            template.AddComponent(new Persistence.Snapshot(), serverAttribute);
            template.AddComponent(new PlayerCreator.Snapshot(), serverAttribute);

            template.SetReadAccess(UnityClientConnector.WorkerType, UnityGameLogicConnector.WorkerType, MobileClientWorkerConnector.WorkerType);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute);

            snapshot.AddEntity(template);
        }
        private static void CreateSpinner(Snapshot snapshot, Coordinates coords)
        {
            const string entityType = "Spinner";

            var transform = Improbable.Gdk.TransformSynchronization.TransformUtils.CreateTransformSnapshot(coords.ToUnityVector(), Quaternion.identity);

            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(coords), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot(entityType), WorkerUtils.UnityGameLogic);
            template.AddComponent(transform, WorkerUtils.UnityGameLogic);
            template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Collisions.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new SpinnerRotation.Snapshot(), WorkerUtils.UnityGameLogic);

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

            snapshot.AddEntity(template);
        }
        private static void AddUnits(Snapshot snapshot, GetSnapshotHeight ground, List <UnitSnapshot> units)
        {
            foreach (var u in units)
            {
                var template = BaseUnitTemplate.CreateBaseUnitEntityTemplate(u.side, u.type, GroundCoordinates(u.pos.x, u.pos.y, u.pos.z), u.rotate.ToCompressedQuaternion());
                if (u.attachments != null)
                {
                    foreach (var attach in u.attachments)
                    {
                        attach.AddComponent(template);
                    }
                }

                snapshot.AddEntity(template);

                //if (u.type == UnitType.HeadQuarter)
                //{
                //    template = BaseUnitTemplate.CreateBaseUnitEntityTemplate(u.side, new Coordinates(u.pos.x, FixedParams.StrategyHeight, u.pos.z), UnitType.ArmyCloud);
                //}
            }
        }
        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);

            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);
        }
        private static void AddDefaultUnits(Snapshot snapshot, GetSnapshotHeight ground = null)
        {
            var gridLength = (int)Math.Ceiling(Math.Sqrt(16));
            var len        = gridLength * scale;
            var templateA  = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.A, GroundCoordinates(-len * 3, 0, ground), UnitType.Stronghold);
            var templateB  = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.B, GroundCoordinates(len * 3, 0, ground), UnitType.Stronghold);

            snapshot.AddEntity(templateA);
            snapshot.AddEntity(templateB);

            var templateCa = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.A, GroundCoordinates(-len * 2, 0, ground), UnitType.Commander);
            var templateCb = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.B, GroundCoordinates(len * 2, 0, ground), UnitType.Commander);

            snapshot.AddEntity(templateCa);
            snapshot.AddEntity(templateCb);

            var templateHa = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.A, GroundCoordinates(-len * 3.5, 0, ground), UnitType.HeadQuarter);
            var templateHb = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.B, GroundCoordinates(len * 3.5, 0, ground), UnitType.HeadQuarter);

            snapshot.AddEntity(templateHa);
            snapshot.AddEntity(templateHb);
        }
        private static Snapshot CreateSnapshot(GetSnapshotHeight ground = null, float fieldSize = standardSize, List <UnitSnapshot> units = null, List <FieldSnapshot> fields = null)
        {
            var snapshot = new Snapshot();

            int count = (int)Mathf.Round(fieldSize / standardSize) * 2;

            for (int i = 0; i <= count; i++)
            {
                for (int j = 0; j <= count; j++)
                {
                    var length_x = standardSize * (i - (count - 1) / 2.0f);
                    var length_z = standardSize * (j - (count - 1) / 2.0f);
                    AddPlayerSpawner(snapshot, GroundCoordinates(length_x, length_z, ground));
                }
            }

            AddWorldTimer(snapshot, Coordinates.Zero);
            if (units == null)
            {
                AddDefaultUnits(snapshot, ground);
            }
            else
            {
                AddUnits(snapshot, ground, units);
            }

            if (fields == null)
            {
                AddField(snapshot, Coordinates.Zero);
            }
            else
            {
                AddFields(snapshot, fields);
            }

            return(snapshot);
        }
示例#29
0
        // Now takes an optional rotation argument.
        private static void AddSphere(Snapshot snapshot, Vector3 position, Quaternion rotation)
        {
            var template = EntityTemplates.CreateSphereTemplate(rotation, position);

            snapshot.AddEntity(template);
        }
示例#30
0
 private static void AddSphere(Snapshot snapshot, Vector3 position)
 {
     AddSphere(snapshot, position, Quaternion.identity);
 }