void GenerateHeightmap(BiomeTypes[,] biomes) { int resolution = ThisTerain.terrainData.heightmapResolution; Heightmap = new float[resolution, resolution]; List <LibNoise.ModuleBase> modules = new List<ModuleBase>(); for (int i = 0; i < availblebiomes.Count; i++) { if (!modules.Contains(Biome.FindBiome(availblebiomes[i]).Generate(noisehelper))) { modules.Add(Biome.FindBiome(availblebiomes[i]).Generate(noisehelper)); } } for (int i = 1; i < modules.Count; i++) { if (modules[i] != null) { modules[i][0] = modules[i - 1]; } } Noise2D heightMap = new Noise2D(resolution, resolution, modules[0]); heightMap.GeneratePlanar(yOffset, yOffset + 1.0f, xOffset, xOffset + 1.0f); for (int y = 0; y < resolution; y++) { for (int x = 0; x < resolution; x++) { Heightmap[x, y] = (((heightMap[x, y]) * 0.5f) + 0.5f);// (float)((FlatNoiseMap[x, y] * 0.5f) + 0.5f); } } ThisTerain.terrainData.SetHeights(0, 0, Heightmap); ThisTerain.Flush(); }
void Awake() { biomeGenerator = this; biomeProperties desertBiome = new biomeProperties(); desertBiome.defaultCube = CubeProperties.itemIDs.sand; desertBiome.defaultGrass = CubeProperties.itemIDs.sand; desertBiome.defaultTree = CubeProperties.itemIDs.cactus; desertBiome.gradiant = 4; biomeTypeDict.Add (biomeType.desert, desertBiome); biomeProperties plainsBiome = new biomeProperties(); plainsBiome.defaultCube = CubeProperties.itemIDs.dirt; plainsBiome.defaultGrass = CubeProperties.itemIDs.grass; plainsBiome.defaultTree = CubeProperties.itemIDs.wood; plainsBiome.gradiant = 10; biomeTypeDict.Add (biomeType.plains, plainsBiome); biomeProperties mountainBiome = new biomeProperties(); mountainBiome.defaultCube = CubeProperties.itemIDs.dirt; mountainBiome.defaultGrass = CubeProperties.itemIDs.grass; mountainBiome.defaultTree = CubeProperties.itemIDs.wood; mountainBiome.gradiant = 60; biomeTypeDict.Add (biomeType.mountains, mountainBiome); biomeProperties snowyMountainBiome = new biomeProperties(); snowyMountainBiome.defaultCube = CubeProperties.itemIDs.dirt; snowyMountainBiome.defaultGrass = CubeProperties.itemIDs.snowGrass; snowyMountainBiome.defaultTree = CubeProperties.itemIDs.wood; snowyMountainBiome.gradiant = 60; biomeTypeDict.Add (biomeType.snowyMountains, snowyMountainBiome); }
private void Update() { //Sets current biome _checkTimer.Time += Time.deltaTime; if (_checkTimer.Expired()) { BiomeTypes thisBiome = Player.GetCurrentBiome(); if (thisBiome != _currentBiomeType) { _currentBiomeType = thisBiome; _changeTimer.Reset(); oldColor = RenderSettings.fogColor; _currentlySet = false; } _checkTimer.Reset(); } //Change fog if (!_currentlySet) { _changeTimer.Time += Time.deltaTime; RenderSettings.fogColor = Color.Lerp(oldColor, _biomeFogColors[(int)_currentBiomeType], _changeTimer.Ratio()); if (_changeTimer.Expired()) { _currentlySet = true; } } }
public TileInfo(byte[,] previousWeights) { Created = true; BiomeWeights = new byte[3]; for (int i = 0; i < previousWeights.GetLength(0); i++) { for (int j = 0; j < previousWeights.GetLength(1); j++) { if (BiomeWeights[j] <= previousWeights[i, j]) { BiomeWeights[j] = previousWeights[i, j]; } } } int biomeIndex = 0; for (int o = 0; o < BiomeWeights.GetLength(0); o++) { if (BiomeWeights[biomeIndex] <= BiomeWeights[o]) { biomeIndex = o; } } Biome = (BiomeTypes)biomeIndex; }
public static void GenerateBiome(this Map map) { foreach (var center in map.Centers.Values.Where(x => x.Props.Has(ObjectProp.Land))) { var bio = BiomeTypes.BiomeSelector(center.Props, 1000, center.Point.y, center.Moisture); center.Biome = bio; } }
public Biome(Texture2D _texture, Texture2D _normal, BiomeTypes _type, GameObject[] _decoration, int[] _decorationcount) { Decorations = _decoration; Texture = _texture; Normal = _normal; Type = _type; Decorations = _decoration; Decorationscount = _decorationcount; }
public SpawnMinion(string mobid, double chance, BiomeTypes biomeconditions, SpawnConditions spawnconditions, bool isboss = false, bool unittocheckkillamount = true) { MobID = mobid; Chance = chance; SpawnConditions = spawnconditions; BiomeConditions = biomeconditions; isBoss = isboss; UnitToCheckKillAmount = unittocheckkillamount; }
public CustomNPCSpawning(int spawnrate, float mindepth, float maxdepth, SpawnConditions spawnconditions, bool useterrariaspawn = true, BiomeTypes spawnbiome = BiomeTypes.None, string spawnregion = "", double spawnchance = 100.0) { spawnBiome = spawnbiome; spawnRegion = spawnregion; spawnRate = spawnrate; spawnChance = spawnchance; spawnConditions = spawnconditions; useTerrariaSpawn = useterrariaspawn; minDepth = mindepth; maxDepth = maxdepth; }
public Vector2 getRandomTexture(BiomeTypes biome) { switch (biome) { case BiomeTypes.TropicalForest: return TerrainTextureGroups.tropical_forest[(int)(UnityEngine.Random.Range(0, TerrainTextureGroups.tropical_forest.Count))]; break; case BiomeTypes.ConiferousForest: return TerrainTextureGroups.coniferous_forest[(int)(UnityEngine.Random.Range(0, TerrainTextureGroups.coniferous_forest.Count))]; break; } return Vector2.zero; }
/// <summary> /// Attempts to spawn the given minion for every player online, where applicable. /// </summary> /// <param name="spawnRegion"></param> /// <param name="minion"></param> /// <param name="npcdef"></param> /// <param name="attempts"></param> private static void SpawnMinion(Rectangle spawnRegion, SpawnMinion minion, CustomNPCDefinition npcdef, int attempts) { //Loop through players foreach (TSPlayer player in TShock.Players) { if (player == null || player.Dead || !player.Active || !NPCManager.Chance(minion.Chance)) { continue; } //Check if the minions can spawn anywhere, or if we need to check if players see them. if (!CurrentWave.SpawnAnywhere) { Rectangle playerFrame = new Rectangle((int)player.TPlayer.position.X, (int)player.TPlayer.position.Y, player.TPlayer.width, player.TPlayer.height); if (!playerFrame.Intersects(spawnRegion)) { continue; } } //Check biomes if (minion.BiomeConditions != BiomeTypes.None) { BiomeTypes biomes = player.GetCurrentBiomes(); if ((minion.BiomeConditions & biomes) == 0) { continue; } } int mobid = -1; //Try max attempts times. This gives attempts*50 spawn attempts at random positions. for (int i = 0; mobid == -1 && i < attempts; i++) { mobid = NPCManager.SpawnMobAroundPlayer(player, npcdef); } //Spawning failed :( if (mobid == -1) { continue; } NPCManager.GetCustomNPCByIndex(mobid).isInvasion = true; } }
private bool Econimicboon(BiomeTypes biomeTypes) { switch (biomeTypes) { case BiomeTypes.Forest: case BiomeTypes.TropicalRainForest: case BiomeTypes.TemperateRainForest: case BiomeTypes.Bare: case BiomeTypes.Beach: case BiomeTypes.Taiga: return(true); default: return(false); } }
public Vector2 getRandomTexture(BiomeTypes biome) { switch (biome) { case BiomeTypes.TropicalForest: return(TerrainTextureGroups.tropical_forest[(int)(UnityEngine.Random.Range(0, TerrainTextureGroups.tropical_forest.Count))]); break; case BiomeTypes.ConiferousForest: return(TerrainTextureGroups.coniferous_forest[(int)(UnityEngine.Random.Range(0, TerrainTextureGroups.coniferous_forest.Count))]); break; } return(Vector2.zero); }
private void AddCustomNPCToBiome(BiomeTypes biome, string id, CustomNPCSpawning spawning) { List <Tuple <string, CustomNPCSpawning> > spawns; if (!BiomeSpawns.TryGetValue(biome, out spawns)) { spawns = new List <Tuple <string, CustomNPCSpawning> >(); BiomeSpawns[biome] = spawns; } var pair = Tuple.Create(id, spawning); if (!spawns.Contains(pair)) { spawns.Add(pair); } }
internal static void SpawnMobsInBiomeAndRegion() { //loop through all players foreach (TSPlayer player in TShock.Players) { //Check if player exist and is connected if (player == null || !player.ConnectionAlive) { continue; } //Log.ConsoleInfo("{0} - Checking spawn for player", player.Name); //Check all biome spawns BiomeTypes biomes = player.GetCurrentBiomes(); foreach (BiomeTypes biome in availableBiomes.Where(x => biomes.HasFlag(x))) { //Log.ConsoleInfo("{0} - Checking biome for player", biome.ToString()); //Get list of mobs that can be spawned in that biome List <Tuple <string, CustomNPCSpawning> > biomeSpawns; if (!Data.BiomeSpawns.TryGetValue(biome, out biomeSpawns)) { continue; } foreach (Tuple <string, CustomNPCSpawning> obj in biomeSpawns) { //Log.ConsoleInfo("{0} - Checking mob spawn", obj.Item1); //Check spawn conditions if (!CheckSpawnConditions(obj.Item2.spawnConditions)) { //Log.ConsoleInfo("False Conditions"); continue; } CustomNPCDefinition customnpc = Data.GetNPCbyID(obj.Item1); if (customnpc.maxSpawns <= -1) { customnpc.currSpawnsVar++; } //Make sure not spawning more then maxSpawns if (customnpc.maxSpawns != -1 && customnpc.currSpawnsVar >= customnpc.maxSpawns) { continue; } //Get the last spawn attempt DateTime lastSpawnAttempt; if (!Data.LastSpawnAttempt.TryGetValue(customnpc.customID, out lastSpawnAttempt)) { lastSpawnAttempt = default(DateTime); Data.LastSpawnAttempt[customnpc.customID] = lastSpawnAttempt; } //If not enough time has passed, we skip and go to the next NPC. if ((DateTime.Now - lastSpawnAttempt).TotalSeconds < obj.Item2.spawnRate) { continue; } //Check spawn chance if (!NPCManager.Chance(obj.Item2.spawnChance)) { continue; } // Check Player Depth if (player.TileY > obj.Item2.minDepth && player.TileY < obj.Item2.maxDepth || obj.Item2.minDepth == -1 || obj.Item2.maxDepth == -1) { //Check spawn method if (obj.Item2.useTerrariaSpawn) { //All checks completed --> spawn mob int npcid = SpawnMobAroundPlayer(player, customnpc); if (npcid != -1) { Main.npc[npcid].target = player.Index; Data.LastSpawnAttempt[customnpc.customID] = DateTime.Now; customnpc.currSpawnsVar++; } } else { //All checks completed --> spawn mob int spawnX; int spawnY; TShock.Utils.GetRandomClearTileWithInRange(player.TileX, player.TileY, 50, 50, out spawnX, out spawnY); int npcid = SpawnNPCAtLocation((spawnX * 16) + 8, spawnY * 16, customnpc); if (npcid == -1) { continue; } Data.LastSpawnAttempt[customnpc.customID] = DateTime.Now; Main.npc[npcid].target = player.Index; customnpc.currSpawnsVar++; } } } } //Then check regions as well Rectangle playerRectangle = new Rectangle(player.TileX, player.TileY, player.TPlayer.width, player.TPlayer.height); foreach (Region obj in Data.RegionSpawns.Keys.Select(name => TShock.Regions.GetRegionByName(name)).Where(region => region != null && region.InArea(playerRectangle))) { List <Tuple <string, CustomNPCSpawning> > regionSpawns; if (!Data.RegionSpawns.TryGetValue(obj.Name, out regionSpawns)) { continue; } foreach (Tuple <string, CustomNPCSpawning> obj2 in regionSpawns) { //Invalid spawn conditions if (!CheckSpawnConditions(obj2.Item2.spawnConditions)) { continue; } CustomNPCDefinition customnpc = Data.GetNPCbyID(obj2.Item1); //Make sure not spawning more then maxSpawns if (customnpc.maxSpawns != -1 && customnpc.currSpawnsVar >= customnpc.maxSpawns) { continue; } //Get the last spawn attempt DateTime lastSpawnAttempt; if (!Data.LastSpawnAttempt.TryGetValue(customnpc.customID, out lastSpawnAttempt)) { lastSpawnAttempt = default(DateTime); Data.LastSpawnAttempt[customnpc.customID] = lastSpawnAttempt; } //If not enough time passed, we skip and go to the next NPC. if ((DateTime.Now - lastSpawnAttempt).TotalSeconds < obj2.Item2.spawnRate) { continue; } Data.LastSpawnAttempt[customnpc.customID] = DateTime.Now; if (!NPCManager.Chance(obj2.Item2.spawnChance)) { continue; } // Check Player Depth if (player.TileY > obj2.Item2.minDepth && player.TileY < obj2.Item2.maxDepth || obj2.Item2.minDepth == -1 || obj2.Item2.maxDepth == -1) { var region = TShock.Regions.GetRegionByName(obj2.Item2.spawnRegion); ActiveArenas.Add(region); ActiveArenas.Count(); var arenaX = region.Area.X + (region.Area.Width / 2); var arenaY = region.Area.Y + (region.Area.Height / 2); var rangeX = region.Area.Width / 2; var rangeY = region.Area.Height / 2; int spawnX; int spawnY; TShock.Utils.GetRandomClearTileWithInRange(arenaX, arenaY, rangeX, rangeY, out spawnX, out spawnY); int npcid = SpawnNPCAtLocation((spawnX * 16) + 8, spawnY * 16, customnpc); if (npcid == -1) { continue; } Main.npc[npcid].target = player.Index; customnpc.currSpawnsVar++; ActiveArenas.Remove(region); continue; } } } } }
public static BiomeTypes GetCurrentBiomes(this TSPlayer player) { BiomeTypes biome = BiomeTypes.None; if (player.TPlayer.ZoneCorrupt) { biome |= BiomeTypes.Corruption; } if (player.TPlayer.ZoneCrimson) { biome |= BiomeTypes.Crimsion; } if (player.TPlayer.ZoneDesert) { biome |= BiomeTypes.Desert; } if (player.TPlayer.ZoneDungeon) { biome |= BiomeTypes.Dungeon; } if (player.TPlayer.ZoneGlowshroom) { biome |= BiomeTypes.Glowshroom; } if (player.TPlayer.ZoneHoly) { biome |= BiomeTypes.Holy; } if (player.TPlayer.ZoneJungle) { biome |= BiomeTypes.Jungle; } if (player.TPlayer.ZoneMeteor) { biome |= BiomeTypes.Meteor; } if (player.TPlayer.ZonePeaceCandle) { biome |= BiomeTypes.PeaceCandle; } if (player.TPlayer.ZoneSnow) { biome |= BiomeTypes.Snow; } if (player.TPlayer.ZoneTowerNebula) { biome |= BiomeTypes.TowerNebula; } if (player.TPlayer.ZoneTowerSolar) { biome |= BiomeTypes.TowerSolar; } if (player.TPlayer.ZoneTowerStardust) { biome |= BiomeTypes.TowerStardust; } if (player.TPlayer.ZoneTowerVortex) { biome |= BiomeTypes.TowerVortex; } if (player.TPlayer.ZoneUndergroundDesert) { biome |= BiomeTypes.UndergroundDesert; } if (player.TPlayer.ZoneWaterCandle) { biome |= BiomeTypes.WaterCandle; } if (player.TPlayer.ZoneBeach) { biome |= BiomeTypes.Beach; } if (player.TPlayer.ZoneSandstorm) { biome |= BiomeTypes.Sandstorm; } if (biome == BiomeTypes.None) { biome = BiomeTypes.Grass; } return(biome); }
private void InvasionTimer_Elapsed(object sender, ElapsedEventArgs e) { if (TShock.Utils.ActivePlayers() == 0) { return; } int spawnFails = 0; int spawnsThisWave = 0; int spawnX = Main.spawnTileX - 150; int spawnY = Main.spawnTileY - 150; Rectangle SpawnRegion = new Rectangle(spawnX, spawnY, 300, 300); foreach (SpawnMinion minions in CurrentWave.SpawnGroup.SpawnMinions) { var npcdef = NPCManager.Data.GetNPCbyID(minions.MobID); if (npcdef == null) { TShock.Log.ConsoleError("[CustomNPC]: Error! The custom mob id \"{0}\" does not exist!", minions.MobID); continue; } // Check spawn conditions if (minions.SpawnConditions != SpawnConditions.None) { if (NPCManager.CheckSpawnConditions(minions.SpawnConditions)) { continue; } } foreach (TSPlayer player in TShock.Players) { //Skip spawning more NPCs when we have likely hit the server's mob limit. if (spawnFails > 40 && spawnsThisWave >= 150) { continue; } if (player == null || player.Dead || !player.Active || !NPCManager.Chance(minions.Chance)) { continue; } Rectangle playerframe = new Rectangle((int)player.TPlayer.position.X, (int)player.TPlayer.position.Y, player.TPlayer.width, player.TPlayer.height); if (!playerframe.Intersects(SpawnRegion)) { continue; } if (minions.BiomeConditions != BiomeTypes.None) { BiomeTypes biomes = player.GetCurrentBiomes(); if ((minions.BiomeConditions & biomes) == 0) { continue; } } // Prevent multiple bosses from spawning during invasions if (minions.isBoss && NPCManager.AliveCount(minions.MobID) > 0) { continue; } int mobid = -1; //Try max 3 times. Since every try checks 50 positions around the player to spawn the mob, //3 tries means a maximum of 150 spawn attempts. for (int i = 0; mobid == -1 && i < 3; i++) { mobid = NPCManager.SpawnMobAroundPlayer(player, npcdef); } if (mobid == -1) { spawnFails++; continue; } NPCManager.GetCustomNPCByIndex(mobid).isInvasion = true; spawnsThisWave++; } } if (spawnFails > 0) { TShock.Log.ConsoleInfo("[CustomNPC]: Failed to spawn {0} npcs this wave!", spawnFails); } }
public static int FindTexture(BiomeTypes biome) { return DataBaseHandler.DataBase.biomes.FindIndex(b => b.Type == biome); }
public static Biome FindBiome(BiomeTypes biome) { return DataBaseHandler.DataBase.biomes.First(b => b.Type == biome); }
public void SetBiomes(BiomeTypes[,] bt) { Biomes = bt; }
public BiomeTranslator(BiomeTypes[,] biomemap, BiomeTypes mask, double _xminval, double _xmaxval, double _yminval, double _ymaxval) : base(0) { BiomeMap = new double[DataBaseHandler.HeighMapSize, DataBaseHandler.HeighMapSize]; xminval = _xminval; xmaxval = _xmaxval; yminval = _yminval; ymaxval = _ymaxval; for (int i = 0; i < DataBaseHandler.HeighMapSize; i++) { for (int j = 0; j < DataBaseHandler.HeighMapSize; j++) { BiomeTypes bt = biomemap[(int)(((double)DataBaseHandler.BiomeMapSize / (double)DataBaseHandler.HeighMapSize) * (double)i), (int)(((double)DataBaseHandler.BiomeMapSize / (double)DataBaseHandler.HeighMapSize) * (double)j)]; if (bt == mask) { BiomeMap[i, j] = 1.0; } else { BiomeMap[i, j] = -1.0; } } } //int[,] weight = new int[,] //{ // {05, 04, 2,}, // {12, 09, 4,}, // {15, 12, 5,}, // {28, 21, 15, 12} // {15, 12, 5,}, // {12, 09, 4,}, // {05, 04, 2,}, //}; int smoothlenght = 8; for (int q = 0; q < 1; q++) { double[,] temp = new double[DataBaseHandler.HeighMapSize, DataBaseHandler.HeighMapSize]; for (int i = 0; i < BiomeMap.GetLength(0); i++) { for (int j = 0; j < BiomeMap.GetLength(1); j++) { double sum = 0; double divider = 0; for (int k = -smoothlenght; k <= smoothlenght; k++) { for (int l = -smoothlenght; l <= smoothlenght; l++) { if (i + k >= 0 && j + l >= 0 && i + k < BiomeMap.GetLength(0) - 1 && j + l < BiomeMap.GetLength(1) - 1) { int c = (int)((((Mathf.Cos(((float)Mathf.Abs(k) / 16.0f) * Mathf.PI) * 32) + 32) + ((Mathf.Cos(((float)Mathf.Abs(l) / 16.0f) * Mathf.PI) * 32) + 32)) / 2); sum += BiomeMap[i + k, j + l] * c; divider += c; } } } temp[i, j] = sum / divider; } } BiomeMap = temp; } }
public BorealForest(Texture2D _texture, Texture2D _normal, BiomeTypes _type, GameObject[] _decoration, int[] _decorationcount) : base(_texture, _normal, _type, _decoration, _decorationcount) { }
void GenerateAlphamap(BiomeTypes[,] Biomes) { int resolution = ThisTerain.terrainData.alphamapHeight; float[, ,] amap = new float[ThisTerain.terrainData.alphamapResolution, ThisTerain.terrainData.alphamapResolution, ThisTerain.terrainData.splatPrototypes.Length]; for (int hX = 0; hX < ThisTerain.terrainData.alphamapResolution; hX++) { for (int hY = 0; hY < ThisTerain.terrainData.alphamapResolution; hY++) { amap[hX, hY, Biome.FindTexture(Biomes[hX, hY])] = 1; } } ThisTerain.terrainData.SetAlphamaps(0, 0, amap); ThisTerain.Flush(); }