private Vector3 GetRandomZonePos(PlayerZone zone) { var world = GameManager.Instance.World; Vector3 pos = new Vector3(); Vector3 spawnPos = new Vector3(); for (int i = 0; i < 10; i++) { pos.x = _prng.Get(zone.minsSpawnBlock.x, zone.maxsSpawnBlock.x); pos.z = _prng.Get(zone.minsSpawnBlock.z, zone.maxsSpawnBlock.z); int height = world.GetTerrainHeight((int)pos.x, (int)pos.z); spawnPos.x = pos.x; spawnPos.y = height + 1.0f; spawnPos.z = pos.z; if (world.CanMobsSpawnAtPos(spawnPos)) { return(spawnPos); } } return(Vector3.zero); }
private void RequestActiveZombie(ZombieAgent zombie, PlayerZone zone) { ZombieSpawnRequest spawn = new ZombieSpawnRequest(); spawn.zombie = zombie; spawn.zone = zone; lock (_spawnQueue) { _spawnQueue.Enqueue(spawn); } }
void RequestActiveZombie(ZombieAgent zombie, PlayerZone zone) { zombie.state = ZombieAgent.State.Active; ZombieSpawnRequest spawn = new ZombieSpawnRequest(); spawn.zombie = zombie; spawn.zone = zone; lock (_spawnQueue) { _spawnQueue.Enqueue(spawn); } }
bool CreateZombie(ZombieAgent zombie, PlayerZone zone) { if (!CanSpawnActiveZombie()) { return(false); } var world = GameManager.Instance.World; Chunk chunk = (Chunk)world.GetChunkSync(World.toChunkXZ(Mathf.FloorToInt(zombie.pos.x)), 0, World.toChunkXZ(Mathf.FloorToInt(zombie.pos.z))); if (chunk == null) { #if DEBUG Log.Out("[WalkerSim] Chunk not loaded at {0} {1}", zombie.pos, zombie.pos.z); #endif return(false); } int height = world.GetTerrainHeight(Mathf.FloorToInt(zombie.pos.x), Mathf.FloorToInt(zombie.pos.z)); Vector3 spawnPos = new Vector3(zombie.pos.x, height + 1.0f, zombie.pos.z); if (!CanZombieSpawnAt(spawnPos)) { #if DEBUG Log.Out("[WalkerSim] Unable to spawn zombie at {0}, CanMobsSpawnAtPos failed", spawnPos); #endif return(false); } if (zombie.classId == -1) { zombie.classId = _biomeData.GetZombieClass(world, chunk, (int)spawnPos.x, (int)spawnPos.z, _prng); if (zombie.classId == -1) { int lastClassId = -1; zombie.classId = EntityGroups.GetRandomFromGroup("ZombiesAll", ref lastClassId); #if DEBUG Log.Out("Used fallback for zombie class!"); #endif } } EntityZombie zombieEnt = EntityFactory.CreateEntity(zombie.classId, spawnPos) as EntityZombie; if (zombieEnt == null) { #if DEBUG Log.Error("[WalkerSim] Unable to create zombie entity!, Entity Id: {0}, Pos: {1}", zombie.classId, spawnPos); #endif return(false); } zombieEnt.bIsChunkObserver = true; // TODO: Figure out a better way to make them walk towards something. if (true) { // Send zombie towards a random position in the zone. Vector3 targetPos = GetRandomZonePos(zone); if (targetPos == Vector3.zero) { zombieEnt.SetInvestigatePosition(zone.center, 6000, false); } else { zombieEnt.SetInvestigatePosition(targetPos, 6000, false); } } // If the zombie was previously damaged take health to this one. if (zombie.health != -1) { zombieEnt.Health = zombie.health; } else { zombie.health = zombieEnt.Health; } zombieEnt.IsHordeZombie = true; zombieEnt.IsBloodMoon = _state.IsBloodMoon; zombieEnt.SetSpawnerSource(EnumSpawnerSource.StaticSpawner); world.SpawnEntityInWorld(zombieEnt); zombie.entityId = zombieEnt.entityId; zombie.currentZone = zone; zombie.lifeTime = world.GetWorldTime(); zone.numZombies++; #if DEBUG Log.Out("[WalkerSim] Spawned zombie {0} at {1}", zombieEnt, spawnPos); #endif lock (_activeZombies) { _activeZombies.Add(zombie); } return(true); }
public ZombieSpawnRequest(ZombieAgent zombie, PlayerZone zone) { this.zombie = zombie; this.zone = zone; }