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 + ">"); }
private static void GenerateDefaultSnapshot() { var snapshotEntities = new Dictionary <EntityId, Entity>(); var currentEntityId = 1; snapshotEntities.Add(new EntityId(currentEntityId++), EntityTemplateFactory.CreatePlayerCreatorTemplate()); // create the planets for (uint i = 0; i < 9; ++i) { snapshotEntities.Add(new EntityId(currentEntityId++), EntityTemplateFactory.CreatePlanetTemplate(i)); } // create the asteroid belt for (int i = 0; i < 1000; ++i) { float angle = Random.Range(-180f, 180f); // asteroids are in a belt that's from 2 to 3.2 AU from the sun double orbitRadius = Random.Range(2.0f, 3.2f) * Scales.au2km; // TODO: make this a distribution where most are near 1 km in size but a tiny few can be as large as 100 km double diameter = Random.Range(10000f, 60000f); snapshotEntities.Add(new EntityId(currentEntityId++), EntityTemplateFactory.CreateAsteroidTemplate(angle, orbitRadius, diameter)); } SaveSnapshot(snapshotEntities); }
private void CreateSpectatorPlayer(string clientWorkerId, EntityId entityId) { var spectatorPlayerEntityTemplate = EntityTemplateFactory.CreateSpecatorPlayerTemplate(clientWorkerId); SpatialOS.Commands.CreateEntity(PlayerCreationWriter, entityId, SimulationSettings.SpectatorPlayerPrefabName, spectatorPlayerEntityTemplate) .OnFailure(failure => OnFailedPlayerCreation(failure, clientWorkerId, entityId, PlayerType.SPECTATORPLAYER)); }
private void CreateVrPlayer(string clientWorkerId, EntityId entityId) { var vrPlayerEntityTemplate = EntityTemplateFactory.CreateVrPlayerTemplate(clientWorkerId); SpatialOS.Commands.CreateEntity(PlayerCreationWriter, entityId, vrPlayerEntityTemplate) .OnFailure(failure => OnFailedPlayerCreation(failure, clientWorkerId, entityId, PlayerType.VRPLAYER)); }
private static void GenerateDefaultSnapshot() { var snapshotEntities = new Dictionary <EntityId, Entity>(); var currentEntityId = 1; snapshotEntities.Add(new EntityId(currentEntityId++), EntityTemplateFactory.CreatePlayerCreatorTemplate()); float startX = -142.5f, startZ = -142.5f; for (int i = 0; i < 20; ++i) { for (int j = 0; j < 20; ++j) { snapshotEntities.Add(new EntityId(currentEntityId++), EntityTemplateFactory.CreateTileTemplate(new Vector3(startX + i * 15f, 0, startZ + j * 15f))); } } // Inner circle snapshotEntities.Add(new EntityId(currentEntityId++), EntityTemplateFactory.CreateTankTemplate(new Vector3(-5, 0, -5))); for (int i = 1; i < 10; ++i) { Vector3 posVector = Vector3.forward * 15 * i; snapshotEntities.Add(new EntityId(currentEntityId++), EntityTemplateFactory.CreateTankTemplate(Quaternion.Euler(0, Random.Range(1, 90), 0) * posVector)); snapshotEntities.Add(new EntityId(currentEntityId++), EntityTemplateFactory.CreateTankTemplate(Quaternion.Euler(0, Random.Range(91, 180), 0) * posVector)); snapshotEntities.Add(new EntityId(currentEntityId++), EntityTemplateFactory.CreateTankTemplate(Quaternion.Euler(0, Random.Range(181, 270), 0) * posVector)); snapshotEntities.Add(new EntityId(currentEntityId++), EntityTemplateFactory.CreateTankTemplate(Quaternion.Euler(0, Random.Range(271, 360), 0) * posVector)); } SaveSnapshot(snapshotEntities); }
public static void AddCountry(SnapshotBuilder snapshot, Coordinates coordinates) { var entityId = snapshot.GenerateId(); var entity = EntityTemplateFactory.CreateCountryTemplate(coordinates); snapshot.Add(entityId, entity); }
// Create large fish entities public static void PopulateSnapshotWithLargeFish(ref Dictionary <EntityId, Entity> snapshotEntities, ref int nextAvailableId) { foreach (var location in SimulationSettings.LargeFishStartingLocations) { snapshotEntities.Add(new EntityId(nextAvailableId++), EntityTemplateFactory.GenerateLargeFishTemplate(location)); } }
public static void SpawnNpcsAroundPosition(SnapshotBuilder snapshot, Coordinates position, uint team) { float totalNpcs = SimulationSettings.HQStartingWizardsCount + SimulationSettings.HQStartingLumberjacksCount; float radiusFromHQ = SimulationSettings.NPCSpawnDistanceToHQ; for (int i = 0; i < totalNpcs; i++) { float radians = (i / totalNpcs) * 2 * Mathf.PI; Vector3 offset = new Vector3(Mathf.Cos(radians), 0, Mathf.Sin(radians)); offset *= radiusFromHQ; Coordinates coordinates = (position.ToVector3() + offset).ToCoordinates(); Entity entity = null; if (i < SimulationSettings.HQStartingLumberjacksCount) { entity = EntityTemplateFactory.CreateNPCLumberjackTemplate(coordinates, team); } else { entity = EntityTemplateFactory.CreateNPCWizardTemplate(coordinates, team); } var id = snapshot.GenerateId(); snapshot.Add(id, entity); } }
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 AddTree(Snapshot snapshot, Vector3f position) { var spawnRotation = (uint)Mathf.CeilToInt((float)rand.NextDouble() * 360.0f); var entity = EntityTemplateFactory.CreateTreeTemplate(position, spawnRotation); snapshot.AddEntity(entity); }
// Create and island entity for each island prefab at its given world coordinates public static void PopulateSnapshotWithIslandTerrainEntities(ref Dictionary <EntityId, Entity> snapshotEntities, ref int nextAvailableId) { foreach (var item in SimulationSettings.IslandsEntityPlacements) { snapshotEntities.Add(new EntityId(nextAvailableId++), EntityTemplateFactory.GenerateIslandEntityTemplate(item.Value, item.Key)); } }
public static void PopulateSnapshotWithHPBoxContainerEntities(ref Dictionary <EntityId, Entity> snapshotEntities, ref int nextavailableId) { for (var i = 0; i < 5; i++) { var HPBoxcoors = new Vector3((Random.Range(-1f, 1f) * 0.5f) * Random.Range(-200f, 200f), -5f, (Random.Range(-1f, 1f) * 0.5f) * Random.Range(-200f, 200f)); snapshotEntities.Add(new EntityId(nextavailableId++), EntityTemplateFactory.CreateHPBoxContainerTemplate(HPBoxcoors)); } }
public static void AddTree(SnapshotBuilder snapshot, Coordinates position) { var treeEntityId = snapshot.GenerateId(); var spawnRotation = (uint)Mathf.CeilToInt((float)rand.NextDouble() * 360.0f); var entity = EntityTemplateFactory.CreateTreeTemplate(position, spawnRotation); snapshot.Add(treeEntityId, entity); }
private void Create(CreateArrowData args) { var arrowTemplate = EntityTemplateFactory.CreateArrowTemplate( gameObject.EntityId(), args.initialPosition, args.angle); SpatialOS.Commands.CreateEntity(PositionWriter, arrowTemplate); }
private void CreatePlayer(string clientWorkerId, EntityId entityId) { // Initial position is slightly randomised to prevent colliders interpenetrating at start var initialPosition = new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f)); var playerEntityTemplate = EntityTemplateFactory.CreatePlayerShipTemplate(clientWorkerId, initialPosition); SpatialOS.Commands.CreateEntity(PlayerCreationWriter, entityId, playerEntityTemplate) .OnFailure(failure => OnFailedPlayerCreation(failure, clientWorkerId, entityId)); }
private void OnCreatePlayer(ResponseHandle <PlayerCreation.Commands.CreatePlayer, CreatePlayerRequest, CreatePlayerResponse> responseHandle) { var clientWorkerId = responseHandle.CallerInfo.CallerWorkerId; var playerEntityTemplate = EntityTemplateFactory.CreatePlayerTemplate(clientWorkerId); SpatialOS.Commands.CreateEntity(PlayerCreationWriter, playerEntityTemplate) .OnSuccess(_ => responseHandle.Respond(new CreatePlayerResponse((int)StatusCode.Success))) .OnFailure(failure => responseHandle.Respond(new CreatePlayerResponse((int)failure.StatusCode))); }
public static void AddHQs(SnapshotBuilder snapshot, Coordinates[] locations) { for (uint teamId = 0; teamId < locations.Length; teamId++) { var position = locations[teamId]; var entity = EntityTemplateFactory.CreateHQTemplate(position, 0, teamId); snapshot.Add(snapshot.GenerateId(), entity); } }
private static void GenerateDefaultSnapshot() { var snapshotEntities = new Dictionary <EntityId, Entity>(); var currentEntityId = 1; snapshotEntities.Add(new EntityId(currentEntityId++), EntityTemplateFactory.CreatePlayerCreatorTemplate()); snapshotEntities.Add(new EntityId(currentEntityId++), EntityTemplateFactory.CreateCubeTemplate()); SaveSnapshot(snapshotEntities); }
private void OnCreatePlayer(ResponseHandle <PlayerCreation.Commands.CreatePlayer, CreatePlayerRequest, CreatePlayerResponse> responseHandle) { var clientWorkerId = responseHandle.CallerInfo.CallerWorkerId; Vector3 initialPosition = new Vector3((Random.Range(-1f, 1f) * 0.5f) * Random.Range(-200f, 200f), -5f, (Random.Range(-1f, 1f) * 0.5f) * Random.Range(-200f, 200f)); var playerEntityTemplate = EntityTemplateFactory.CreatePlayerTemplate(clientWorkerId, initialPosition); SpatialOS.Commands.CreateEntity(PlayerCreationWriter, playerEntityTemplate) .OnSuccess(_ => responseHandle.Respond(new CreatePlayerResponse((int)StatusCode.Success))) .OnFailure(failure => responseHandle.Respond(new CreatePlayerResponse((int)failure.StatusCode))); }
private static void GenerateDefaultSnapshot() { var snapshotEntities = new Dictionary <EntityId, Entity>(); var currentEntityId = 1; snapshotEntities.Add(new EntityId(currentEntityId++), EntityTemplateFactory.CreatePlayerCreatorTemplate()); PopulateSnapshotWithWeaponBoxContainerEntities(ref snapshotEntities, ref currentEntityId); PopulateSnapshotWithSpeedBoostBoxContainerEntities(ref snapshotEntities, ref currentEntityId); PopulateSnapshotWithHPBoxContainerEntities(ref snapshotEntities, ref currentEntityId); SaveSnapshot(snapshotEntities); }
private void SpawnPlayer(string clientWorkerId, EntityId entityId) { var playerEntityTemplate = EntityTemplateFactory.CreatePlayerTemplate(clientWorkerId, SimulationSettings.PlayerPrefabName); SpatialOS.Commands.CreateEntity(playerSpawning, entityId, playerEntityTemplate) .OnFailure(_ => { Debug.LogError("Failed to Create Player Entity. Retrying..."); SpawnPlayer(clientWorkerId, entityId); }); }
private static void AddVehicles(ref int currentEntityId, Dictionary <EntityId, Entity> snapshotEntities, ISnapshot snapshot) { var index = 0; for (var i = 0; i < snapshot.VehicleCount; i++) { var angle = 2 * Mathf.PI * i / snapshot.VehicleCount; var x = SimulationSettings.TrackRadius * Mathf.Cos(angle); var y = SimulationSettings.TrackRadius * Mathf.Sin(angle); var position = new Vector3(x, 0f, y); var quaternion = Quaternion.AngleAxis(-angle * 180 / Mathf.PI, Vector3.up); var data = new VehicleControlData(); data.maxSpeed = RandomRange(snapshot.MaxSpeed); data.maxAcceleration = RandomRange(snapshot.MaxAcceleration); data.responseScaling = RandomRange(snapshot.ResponseScaling); data.panicDistance = RandomRange(snapshot.PanicDistance); data.reactionTime = RandomRange(snapshot.ReactionTime); var sensorData = new SensorData(); sensorData.sensorRange = RandomRange(snapshot.SensorRange); data.colourRed = 1f; data.colourGreen = 1f; data.colourBlue = 1f; data.speed = 0f; data.desiredSpeed = data.maxSpeed; data.reactionBuffer = Bytes.FromBackingArray(new byte[data.reactionTime * sizeof(float)]); var id = currentEntityId; if (snapshot.SpecialVehicles.Any(v => v.Id == id)) { PopulateSpecial(ref data, ref sensorData, snapshot.SpecialVehicles.Single(v => v.Id == id)); index += 1; } else if (index < snapshot.SpecialVehicles.Count) { if (snapshot.SpecialVehicles[index].Id == null) { PopulateSpecial(ref data, ref sensorData, snapshot.SpecialVehicles[index]); } index += 1; } snapshotEntities.Add( new EntityId(currentEntityId++), EntityTemplateFactory.CreateVehicleTemplate(position, quaternion, data, sensorData)); } }
private void SpawnLumberjack(Coordinates position) { var lumberjackCount = GetLumberjackCount(); if (lumberjackCount >= 20) { return; } var template = EntityTemplateFactory.CreateNPCLumberjackTemplate(position, teamAssignment.Data.teamId); SpatialOS.Commands.CreateEntity(npcSpawner, template); }
private static void GenerateDefaultSnapshot() { var snapshotEntities = new Dictionary <EntityId, Entity>(); var currentEntityId = 1; snapshotEntities.Add(new EntityId(currentEntityId++), EntityTemplateFactory.CreatePlayerCreatorTemplate()); PopulateSnapshotWithIslandTerrainEntities(ref snapshotEntities, ref currentEntityId); PopulateSnapshotWithSmallFishGroups(ref snapshotEntities, ref currentEntityId); PopulateSnapshotWithLargeFish(ref snapshotEntities, ref currentEntityId); SaveSnapshot(snapshotEntities); }
private static int ShowNoFlyZones(Improbable.Controller.NoFlyZone noFlyZone, Dictionary <EntityId, Entity> snapshotEntities, int currentEntityId) { foreach (Vector3f vertex in noFlyZone.vertices) { snapshotEntities.Add( new EntityId(currentEntityId++), EntityTemplateFactory.CreateNfzNodeTemplate(vertex.ToCoordinates()) ); } return(currentEntityId); }
private void CreateBanana() { Debug.Log("CREATING BANANA"); var x = Random.Range(-35, 30); var z = Random.Range(-35, 30); var bananaCoordinates = new Vector3(x, 0.3f, z); // Debug.LogError(HealthWriter.HasAuthority); SpatialOS.Commands.CreateEntity(HealthWriter, EntityTemplateFactory.CreateBananaTemplate(bananaCoordinates)) .OnSuccess(entityId => Debug.Log("Created entity with ID: " + entityId)) .OnFailure(errorDetails => Debug.LogError("Failed to create entity with error: " + errorDetails.ErrorMessage)); }
private void CreatePlayerEntity(string clientWorkerId, ResponseHandle <PlayerCreation.Commands.CreatePlayer, CreatePlayerRequest, CreatePlayerResponse> responseHandle) { var playerEntityTemplate = EntityTemplateFactory.CreatePlayerTemplate(clientWorkerId, gameObject.EntityId()); SpatialOS.Commands.CreateEntity(PlayerCreationWriter, playerEntityTemplate) .OnSuccess(response => { AddPlayerEntityId(clientWorkerId, response.CreatedEntityId); RequestEnded(responseHandle, ResponseCode.SuccessfullyCreated); }) .OnFailure(failure => RequestEnded(responseHandle, ResponseCode.Failure, failure.StatusCode)); }
// Create shoal of small fish entities around given coordinates public static void PopulateSnapshotWithSmallFishGroups(ref Dictionary <EntityId, Entity> snapshotEntities, ref int nextAvailableId) { foreach (var location in SimulationSettings.FishShoalStartingLocations) { for (var i = 0; i < SimulationSettings.TotalFishInShoal; i++) { var nextFishCoodinates = new Vector3(location.x + Random.Range(-SimulationSettings.ShoalRadius, SimulationSettings.ShoalRadius), location.y + Random.Range(SimulationSettings.ShoalMinDepth, SimulationSettings.ShoalMaxDepth), location.z + Random.Range(-SimulationSettings.ShoalRadius, SimulationSettings.ShoalRadius)); snapshotEntities.Add(new EntityId(nextAvailableId++), EntityTemplateFactory.GenerateSmallFishTemplate(nextFishCoodinates)); } } }
public static void PopulateSnapshotWithAlienEntities(ref Dictionary <EntityId, Entity> snapshotEntities, ref int nextAvailableId) { //var positionArray = new [] { new Vector3(167f,0.02f,-88f),new Vector3(-55f,0.02f,84f),new Vector3(-166f,0.02f,-106f), new Vector3(98f,0.02f,59f)}; for (var i = 0; i < SimulationSettings.TotalAliens; i++) { // Choose a starting position for this pirate entity var alienCoordinates = new Vector3(0f, 0f, 0f); float alienRotation = Random.Range(0f, 360f); snapshotEntities.Add(new EntityId(nextAvailableId++), EntityTemplateFactory.CreateAlienTemplate(alienCoordinates, alienRotation)); } }
// Create a pirate entity public static void PopulateSnapshotWithPirateEntities(ref Dictionary <EntityId, Entity> snapshotEntities, ref int nextAvailableId) { for (var i = 0; i < SimulationSettings.TotalPirates; i++) { // Choose a starting position for this pirate entity var pirateCoordinates = new Vector3((Random.value - 0.5f) * SimulationSettings.PiratesSpawnDiameter, 0, (Random.value - 0.5f) * SimulationSettings.PiratesSpawnDiameter); var pirateRotation = System.Convert.ToUInt32(Random.value * 360); snapshotEntities.Add(new EntityId(nextAvailableId++), EntityTemplateFactory.CreatePirateEntityTemplate(pirateCoordinates, pirateRotation)); } }