public static void SpawnOneEntityInChunkNonAlloc(SpawnableEntity se, EntityData?data, ChunkCoords cc) { //pick a position within the chunk coordinates Vector2 spawnPos = Vector2.zero; Vector2Pair range = ChunkCoords.GetCellArea(cc, EntityNetwork.CHUNK_SIZE); switch (se.posType) { case SpawnableEntity.SpawnPosition.Random: spawnPos.x = Random.Range(range.a.x, range.b.x); spawnPos.y = Random.Range(range.a.y, range.b.y); break; case SpawnableEntity.SpawnPosition.Center: spawnPos = ChunkCoords.GetCenterCell(cc, EntityNetwork.CHUNK_SIZE); break; } //spawn it Entity newEntity = Instantiate( se.prefab, spawnPos, Quaternion.identity, instance.holders[se.entityName].transform); newEntity.ApplyData(data); }
public static List <Entity> SpawnEntityInChunkNorthOfCamera(SpawnableEntity se, EntityData?data = null) { Vector3 cameraPos = Camera.main.transform.position; ChunkCoords cc = new ChunkCoords(cameraPos, EntityNetwork.CHUNK_SIZE); cc.y++; cc = cc.Validate(); return(SpawnEntityInChunk(se, data, cc)); }
private void UpdateMenuType(SpawnableEntity entity) { switch (entity.EntityType) { case EntityType.Resource: ChangeMenu(PlayerMenuType.Use); break; } }
public static List <Entity> SpawnEntityInChunkNorthOfCamera(string entityName) { Vector3 cameraPos = Camera.main.transform.position; ChunkCoords cc = new ChunkCoords(cameraPos, EntityNetwork.CHUNK_SIZE); cc.y++; cc = cc.Validate(); SpawnableEntity se = GetSpawnableEntity(entityName); return(SpawnEntityInChunk(se, null, cc)); }
public static List <Entity> SpawnEntity(EntityData data) { if (data.type == null) { return(null); } SpawnableEntity se = GetSpawnableEntity(data.type); return(SpawnEntity(se, data)); }
public static List <Entity> SpawnEntity(Entity e) { if (e == null) { return(null); } SpawnableEntity se = GetSpawnableEntity(e); return(SpawnEntity(se)); }
void SpawnEntity() { if (spawnQueue.Count > 0) { SpawnableEntity next = SpawnManager.instance.Search(spawnQueue.Dequeue()); next.Create(transform.position, Quaternion.identity); } else { Debug.LogWarning("Empty Queue"); } }
public static void SpawnEntityInChunkNonAlloc(SpawnableEntity se, EntityData?data, ChunkCoords cc) { if (se == null) { return; } //determine how many to spawn int numToSpawn = Random.Range(se.minSpawnCountInChunk, se.maxSpawnCountInChunk + 1); for (int j = 0; j < numToSpawn; j++) { SpawnOneEntityInChunkNonAlloc(se, data, cc); } }
private void CreateHolders() { for (int i = 0; i < Prefabs.Count; i++) { SpawnableEntity e = Prefabs[i]; if (holders.ContainsKey(e.entityName)) { continue; } holders.Add(e.entityName, new GameObject(e.entityName)); } Debug.Log("Entity Generator Loaded"); OnPrefabsLoaded?.Invoke(); OnPrefabsLoaded = null; }
public static List <Entity> SpawnEntityInChunk(SpawnableEntity se, EntityData?data, ChunkCoords cc) { if (se == null) { return(null); } //determine how many to spawn int numToSpawn = Random.Range(se.minSpawnCountInChunk, se.maxSpawnCountInChunk + 1); List <Entity> spawnedEntities = new List <Entity>(numToSpawn); for (int j = 0; j < numToSpawn; j++) { spawnedEntities.Add(SpawnOneEntityInChunk(se, data, cc)); } return(spawnedEntities); }
public void StartFindEnergySourceQuest() { if (MainChar == null) { return; } //create a deranged bot ChunkCoords emptyChunk = EntityGenerator.GetNearbyEmptyChunk(); SpawnableEntity se = EntityGenerator.GetSpawnableEntity("deranged bot"); Entity newEntity = EntityGenerator.SpawnOneEntityInChunk(se, null, emptyChunk); //set waypoint to new bot //attach dialogue prompt when player approaches bot VicinityTrigger entityPrompt = newEntity.GetComponentsInChildren <VicinityTrigger>() .Where(t => t.gameObject.layer == LayerMask.NameToLayer("VicinityTrigger")).FirstOrDefault(); Action <IActor> triggerEnterAction = null; triggerEnterAction = (IActor actor) => { if (!(actor is Shuttle)) { return; } StartDialogue(foundDerangedBotConversation, false); entityPrompt.OnEnteredTrigger -= triggerEnterAction; }; entityPrompt.OnEnteredTrigger += triggerEnterAction; List <QuestReward> qRewards = new List <QuestReward>(); List <QuestRequirement> qReqs = new List <QuestRequirement>(); Waypoint wp = Waypoint.CreateWaypoint(MainChar, entityPrompt, entityPrompt.PivotPosition); qReqs.Add(new GatheringQReq(Item.Type.CorruptedCorvorite, MainChar, "Find the nearby energy source.", wp)); Quest q = new Quest( "Acquire an Energy Source", "The ship appears intact, however it is in a powered-down state. We need to find an energy source.", MainQuester, qRewards, qReqs); q.OnQuestComplete += CompletedFindEnergySourceQuest; GiveQuest(MainQuester, q); }
public static List <Entity> SpawnEntity(SpawnableEntity se, EntityData?data = null) { if (se == null) { return(null); } ChunkCoords cc = instance.ClosestValidNonFilledChunk(se); if (cc == ChunkCoords.Invalid) { return(null); } ChunkCoords emptyChunk = GetNearbyEmptyChunk(); return(SpawnEntityInChunk(se, data, emptyChunk)); }
private List <SpawnableEntityChance> GetPrefabs(float distance) { cachedChances.Clear(); for (int i = 0; i < Prefabs.Count; i++) { SpawnableEntity se = Prefabs[i]; if (se.ignore) { continue; } float chance = se.GetChance(distance); if (chance == 0f) { continue; } cachedChances.Add(new SpawnableEntityChance(se, chance)); } return(cachedChances); }
void SpawnEntity() { if (spawnQueue.Count > 0) { SpawnableEntity next = SpawnManager.instance.Search(spawnQueue.Dequeue()); next.Create(transform.position, Quaternion.identity); variantTimer += currentDelta; spawnDelay = variantTimer; if (spawnQueue.Count <= 0 && spawnWaves.Count > 0) { FillQueue(); } } else { Debug.LogWarning("No more waves"); } }
private SpawnableEntity ChooseEntityToSpawn(float distance) { List <SpawnableEntityChance> validPrefabs = GetPrefabs(distance); float totalRarity = SpawnableEntityChance.GetTotalChance(validPrefabs); float randomChoose = Random.Range(0f, totalRarity); //choose which non priority entities to spawn for (int i = 0; i < validPrefabs.Count; i++) { SpawnableEntityChance sec = validPrefabs[i]; SpawnableEntity se = sec.entity; float chance = sec.chance; randomChoose -= chance; if (randomChoose <= 0f) { return(se); } } Debug.Log("No Spawnable Entity Chosen"); return(null); }
private void SpawnHelper(bool respawn) { if (!_shouldSpawn) { return; } SpawnableEntity entity = Spawn(_spawnLocation); if (RespawnOnEntityDestroy) { if (entity != null) { entity.transform.SetParent(transform); entity.OnDestroyed += () => { SpawnAfterTimeout(RespawnTimeoutSeconds, false); }; } } if (respawn) { SpawnAfterTimeout(RespawnTimeoutSeconds, respawn); } }
public static void FillChunk(ChunkCoords cc, bool excludePriority = false) { //don't bother if the given coordinates are not valid if (!cc.IsValid()) { return; } //if these coordinates have no been generated yet then reserve some space for the new coordinates instance.GenerateVoid(cc); //don't bother if the coordinates have already been filled if (instance.Chunk(cc)) { return; } //flag that this chunk coordinates was filled instance.Column(cc)[cc.y] = true; //look through the space priority entities and check if one may spawn SpawnableEntity se = instance.ChooseEntityToSpawn( ChunkCoords.GetCenterCell(cc, EntityNetwork.CHUNK_SIZE).magnitude); SpawnEntityInChunkNonAlloc(se, null, cc); }
private ChunkCoords ClosestValidNonFilledChunk(SpawnableEntity se) { int minRange = Mathf.Max(0, se.rarityZoneOffset); ChunkCoords coords = ChunkCoords.Invalid; while (coords == ChunkCoords.Invalid) { EntityNetwork.IterateCoordsOnRangeBorder(ChunkCoords.Zero, minRange, cc => { if (!Chunk(cc)) { coords = cc; return(true); } return(false); }, true); minRange++; } return(ChunkCoords.Invalid); }
public static List <Entity> SpawnEntity(string entityName) { SpawnableEntity se = GetSpawnableEntity(entityName); return(SpawnEntity(se)); }
public SpawnableEntityChance(SpawnableEntity se, float chance) { this.entity = se; this.chance = chance; }