Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
 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));
     }
 }
Ejemplo n.º 5
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 + ">");
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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 + ">");
        }
 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);
     }
 }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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);
        }
        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);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        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);
                //}
            }
        }
Ejemplo n.º 19
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);

            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 void AddField(Snapshot snapshot, Coordinates location)
 {
     snapshot.AddEntity(FieldTemplate.CreateFieldEntityTemplate(location, 3000, 500, FieldMaterialType.None));
 }
Ejemplo n.º 22
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);
        }
Ejemplo n.º 23
0
        public static void AddPlayerSpawner(Snapshot snapshot)
        {
            var entity = EntityTemplateFactory.CreatePlayerTemplate(snapshot);

            snapshot.AddEntity(entity);
        }