Monster CreateRandomMonster(Vector2 location) { Monster monster = null; if (Game1.isDarkOut() && CanHazMonster(Settings.Monsters.Bat)) { monster = new Bat(new Vector2()); } else if (Game1.isDarkOut() && CanHazMonster(Settings.Monsters.Ghost)) { monster = new Ghost(new Vector2()); } else if (CanHazMonster(Settings.Monsters.BigSlime)) { monster = new BigSlime(new Vector2(), GetSlimeLevel()); } else if (CanHazMonster(Settings.Monsters.Grub)) { monster = new Grub(new Vector2(), true); } else if (CanHazMonster(Settings.Monsters.Fly)) { monster = new Fly(new Vector2(), true); } else if (CanHazMonster(Settings.Monsters.Brute)) { monster = new ShadowBrute(new Vector2()); } else if (CanHazMonster(Settings.Monsters.Golem)) { monster = new RockGolem(new Vector2(), deepWoods.GetCombatLevel()); } else if (CanHazMonster(Settings.Monsters.RockCrab)) { monster = new RockCrab(new Vector2(), GetRockCrabType()); } else { foreach (var modMonster in DeepWoodsAPI.ToShuffledList(ModEntry.GetAPI().Monsters)) { if (modMonster.Item1(deepWoods, location)) { monster = modMonster.Item2(); break; } } if (monster == null) { monster = new GreenSlime(new Vector2(), GetSlimeLevel()); } } if (deepWoods.level.Value >= Settings.Level.MinLevelForBuffedMonsters && !this.random.CheckChance(Settings.Monsters.ChanceForUnbuffedMonster)) { BuffMonster(monster); } return(monster); }
public DeepWoods(DeepWoods parent, int level, EnterDirection enterDir) : this() { base.isOutdoors.Value = true; base.ignoreDebrisWeather.Value = true; base.ignoreOutdoorLighting.Value = true; this.hasReceivedNetworkData.Value = true; this.uniqueMultiplayerID.Value = Game1.MasterPlayer.UniqueMultiplayerID; this.seed = DeepWoodsRandom.CalculateSeed(level, enterDir, parent?.Seed); if (level == 1) { base.name.Value = "DeepWoods"; } else { base.name.Value = "DeepWoods_" + this.seed; } this.parentName.Value = parent?.Name; this.ParentExitLocation = parent?.GetExit(EnterDirToExitDir(enterDir))?.Location ?? new Location(); this.level.Value = level; DeepWoodsState.LowestLevelReached = Math.Max(DeepWoodsState.LowestLevelReached, this.level.Value - 1); this.EnterDir = enterDir; this.spawnTime.Value = Game1.timeOfDay; this.spawnedFromObelisk.Value = parent?.spawnedFromObelisk?.Value ?? false; ModEntry.GetAPI().CallOnCreate(this); CreateSpace(); DetermineExits(); updateMap(); ModEntry.GetAPI().CallBeforeFill(this); if ((this.isLichtung.Value && this.lichtungHasLake.Value) || !ModEntry.GetAPI().CallOverrideFill(this)) { DeepWoodsStuffCreator.AddStuff(this, new DeepWoodsRandom(this, this.seed ^ Game1.currentGameTime.TotalGameTime.Milliseconds ^ Game1.random.Next())); } ModEntry.GetAPI().CallAfterFill(this); ModEntry.GetAPI().CallBeforeMonsterGeneration(this); if (!ModEntry.GetAPI().CallOverrideMonsterGeneration(this)) { DeepWoodsMonsters.AddMonsters(this, new DeepWoodsRandom(this, this.seed ^ Game1.currentGameTime.TotalGameTime.Milliseconds ^ Game1.random.Next())); } ModEntry.GetAPI().CallAfterMonsterGeneration(this); if (parent == null && level > 1 && !this.HasExit(CastEnterDirToExitDir(this.EnterDir))) { this.exits.Add(new DeepWoodsExit(this, CastEnterDirToExitDir(this.EnterDir), this.EnterLocation)); } if (parent != null) { ModEntry.Log($"Child spawned, time: {Game1.timeOfDay}, name: {this.Name}, level: {this.level}, parent: {this.parentName}, enterDir: {this.EnterDir}, enterLocation: {this.EnterLocation.X}, {this.EnterLocation.Y}", LogLevel.Trace); } }
public override void updateMap() { // Always create an empty map, to avoid crashes // (give it maximum size, so game doesn't mess with warp locations on network) if (this.map == null) { this.map = CreateEmptyMap("DEEPWOODSEMPTY", Settings.Map.MaxMapWidth, Settings.Map.MaxMapHeight); } // Check if level is properly initialized if (this.Seed == 0) { return; } // Check that network data has been sent and initialized by server if (!this.HasReceivedNetworkData) { return; } // Check if map is already created if (this.map != null && this.map.Id == this.Name) { return; } // Check that mapWidth and mapHeight are set if (mapWidth.Value == 0 || mapHeight.Value == 0) { return; } // Create map with proper size this.map = CreateEmptyMap(this.Name, mapWidth, mapHeight); // Build the map! ModEntry.GetAPI().CallBeforeMapGeneration(this); if (ModEntry.GetAPI().CallOverrideMapGeneration(this)) { this.isOverrideMap.Value = true; // Make sure map id is our name, otherwise game will reload the map every frame crashing the game this.map.Id = this.Name; } else { DeepWoodsBuilder.Build(this, this.map, DeepWoodsEnterExit.CreateExitDictionary(this.EnterDir, this.EnterLocation, this.exits)); } ModEntry.GetAPI().CallAfterMapGeneration(this); }
protected override void resetLocalState() { base.resetLocalState(); // TODO: Better critter spawning in forest this.tryToAddCritters(false); ModEntry.GetAPI().CallBeforeDebrisCreation(this); if (!ModEntry.GetAPI().CallOverrideDebrisCreation(this)) { DeepWoodsDebris.Initialize(this); } ModEntry.GetAPI().CallAfterDebrisCreation(this); foreach (Vector2 lightSource in this.lightSources) { Game1.currentLightSources.Add(new LightSource(LightSource.indoorWindowLight, lightSource * 64f, 1.0f)); } DeepWoodsManager.FixLighting(); }
public override object GetApi() { return(ModEntry.GetAPI()); }
Monster CreateRandomMonster(Vector2 location) { Monster monster = null; if (Game1.isDarkOut() && CanHazMonster(Settings.Monsters.Bat)) { monster = new Bat(new Vector2()); } else if (Game1.isDarkOut() && CanHazMonster(Settings.Monsters.Ghost)) { monster = new Ghost(new Vector2()); } else if (CanHazMonster(Settings.Monsters.BigSlime)) { monster = new BigSlime(new Vector2(), GetSlimeLevel()); } else if (CanHazMonster(Settings.Monsters.Grub)) { monster = new Grub(new Vector2(), true); } else if (CanHazMonster(Settings.Monsters.Fly)) { monster = new Fly(new Vector2(), true); } else if (CanHazMonster(Settings.Monsters.Brute)) { monster = new ShadowBrute(new Vector2()); } else if (CanHazMonster(Settings.Monsters.Golem)) { monster = new RockGolem(new Vector2(), deepWoods.GetCombatLevel()); } else if (CanHazMonster(Settings.Monsters.RockCrab)) { monster = new RockCrab(new Vector2(), GetRockCrabType()); } else if (CanHazMonster(Settings.Monsters.Bug)) { monster = new Bug(new Vector2(), 121); monster.isHardModeMonster.Value = true; } else if (CanHazMonster(Settings.Monsters.ArmoredBug)) { monster = new Bug(new Vector2(), 121); monster.isHardModeMonster.Value = true; } else if (Game1.isDarkOut() && CanHazMonster(Settings.Monsters.PutridGhost)) { monster = new Ghost(new Vector2(), "Putrid Ghost"); } else if (Game1.isDarkOut() && CanHazMonster(Settings.Monsters.DustSprite)) { monster = new DustSpirit(new Vector2()); new Leaper(); } else if (Game1.isDarkOut() && CanHazMonster(Settings.Monsters.Spider)) { monster = new Leaper(new Vector2()); } else { foreach (var modMonster in DeepWoodsAPI.ToShuffledList(ModEntry.GetAPI().Monsters)) { // Item1 is a mod provided function that returns true if the mod wants to spawn a custom monster at this location. // Item2 is a mod provided function that returns the custom monster. if (modMonster.Item1(deepWoods, location)) { monster = modMonster.Item2(); break; } } } // No other monster was selected and no mod provided a monster, default to green slime if (monster == null) { monster = new GreenSlime(new Vector2(), GetSlimeLevel()); } if (!Settings.Monsters.DisableBuffedMonsters && deepWoods.level.Value >= Settings.Level.MinLevelForBuffedMonsters && !this.random.CheckChance(Settings.Monsters.ChanceForUnbuffedMonster)) { BuffMonster(monster); } if (!Settings.Monsters.DisableDangerousMonsters && deepWoods.level.Value >= Settings.Level.MinLevelForDangerousMonsters && !this.random.CheckChance(Settings.Monsters.ChanceForNonDangerousMonster)) { monster.isHardModeMonster.Value = true; } monster.faceDirection(this.random.GetRandomValue(0, 4)); return(monster); }
private void AddModOrGrass(Vector2 location) { // We have 4 kinds of things that a mod can add: // largeterrainfeatures, terrainfeatures, resourceclumps and objects. // To create a truly random order, we shuffle the kind of things (using lambdas in a list), // and then we shuffle the callbacks provided by mods. foreach (var action in DeepWoodsAPI.ToShuffledList(new List <Func <bool> >() { () => { foreach (var modLargeTerrainFeature in DeepWoodsAPI.ToShuffledList(ModEntry.GetAPI().LargeTerrainFeatures)) { if (modLargeTerrainFeature.Item1(deepWoods, location)) { deepWoods.largeTerrainFeatures.Add(modLargeTerrainFeature.Item2()); return(true); } } return(false); }, () => { foreach (var modResourceClump in DeepWoodsAPI.ToShuffledList(ModEntry.GetAPI().ResourceClumps)) { if (modResourceClump.Item1(deepWoods, location)) { deepWoods.resourceClumps.Add(modResourceClump.Item2()); return(true); } } return(false); }, () => { foreach (var modTerrainFeature in DeepWoodsAPI.ToShuffledList(ModEntry.GetAPI().TerrainFeatures)) { if (modTerrainFeature.Item1(deepWoods, location)) { deepWoods.terrainFeatures[location] = modTerrainFeature.Item2(); return(true); } } return(false); }, () => { foreach (var modObject in DeepWoodsAPI.ToShuffledList(ModEntry.GetAPI().Objects)) { if (modObject.Item1(deepWoods, location)) { deepWoods.objects[location] = modObject.Item2(); return(true); } } return(false); } })) { if (action()) { // A mod added something, return return; } } // Mods didn't add anything, add grass deepWoods.terrainFeatures[location] = new LootFreeGrass(GetSeasonGrassType(), this.random.GetRandomValue(1, 3)); }