protected MobSpawn GetSeedChar(BaseMapGenContext map, SpawnList <MobSpawn> specialMobs) { //the contents of that theme can be selected randomly, MobSpawn seedSpawn = null; //or, to add some sensibility, make it seeded from a random spawn that can already be found in the map if (map.TeamSpawns.CanPick) { TeamSpawner spawn = map.TeamSpawns.Pick(map.Rand); if (spawn != null) { List <MobSpawn> exampleList = spawn.ChooseSpawns(map.Rand); if (exampleList.Count > 0) { seedSpawn = exampleList[map.Rand.Next(exampleList.Count)]; } } } //choose the spawn, then seed the theme with it //the theme will take the aspects of the seedspawn and then be ready to spit out a list if (seedSpawn == null && specialMobs.CanPick) { seedSpawn = specialMobs.Pick(map.Rand); } return(seedSpawn); }
protected override IEnumerable <int> GetSpecies(BaseMapGenContext map, SpawnList <MobSpawn> specialMobs) { foreach (int specie in Species) { yield return(specie); } }
protected override List <int> GetTypes(BaseMapGenContext map, SpawnList <MobSpawn> specialMobs) { List <int> result = new List <int>(); foreach (int type in Types) { result.Add(type); } return(result); }
public override List <MapItem> GenerateItems(BaseMapGenContext map, SpawnList <MapItem> specialItems) { int itemCount = Amount.Pick(map.Rand); List <MapItem> spawners = new List <MapItem>(); SpawnList <MapItem> subList = new SpawnList <MapItem>(); if (UseSpecialItems) { for (int ii = 0; ii < specialItems.Count; ii++) { MapItem spawn = specialItems.GetSpawn(ii); if (!spawn.IsMoney) { ItemEntrySummary itemEntry = DataManager.Instance.DataIndices[DataManager.DataType.Item].Entries[spawn.Value] as ItemEntrySummary; if (itemEntry.UsageType == UseType) { subList.Add(spawn, specialItems.GetSpawnRate(ii)); } } } } if (UseMapItems) { foreach (string key in map.ItemSpawns.Spawns.GetKeys()) { SpawnList <InvItem> spawns = map.ItemSpawns.Spawns.GetSpawn(key); for (int ii = 0; ii < spawns.Count; ii++) { //TODO: spawn rate is somewhat distorted here InvItem spawn = spawns.GetSpawn(ii); ItemEntrySummary itemEntry = DataManager.Instance.DataIndices[DataManager.DataType.Item].Entries[spawn.ID] as ItemEntrySummary; if (itemEntry.UsageType == UseType) { subList.Add(new MapItem(spawn), spawns.GetSpawnRate(ii)); } } } } if (subList.Count == 0) { return(spawners); } for (int ii = 0; ii < itemCount; ii++) { spawners.Add(subList.Pick(map.Rand)); } return(spawners); }
public override List <MapItem> GenerateItems(BaseMapGenContext map, SpawnList <MapItem> specialItems) { int itemCount = Amount.Pick(map.Rand); List <MapItem> spawners = new List <MapItem>(); for (int ii = 0; ii < itemCount; ii++) { spawners.Add(new MapItem(true, Math.Max(1, map.MoneyAmount.Pick(map.Rand).Amount *Multiplier / 100))); } return(spawners); }
public override List <MapItem> GenerateItems(BaseMapGenContext map, SpawnList <MapItem> specialItems) { List <MapItem> spawners = new List <MapItem>(); foreach (ItemTheme theme in Themes) { List <MapItem> items = theme.GenerateItems(map, specialItems); spawners.AddRange(items); } return(spawners); }
public override List <MapItem> GenerateItems(BaseMapGenContext map, SpawnList <MapItem> specialItems) { int itemCount = Amount.Pick(map.Rand); List <MapItem> spawners = new List <MapItem>(); SpawnList <MapItem> subList = new SpawnList <MapItem>(); if (UseSpecialItems) { for (int ii = 0; ii < specialItems.Count; ii++) { MapItem spawn = specialItems.GetSpawn(ii); if (!spawn.IsMoney) { if (Range.Min <= spawn.Value && spawn.Value < Range.Max) { subList.Add(spawn, specialItems.GetSpawnRate(ii)); } } } } if (UseMapItems) { foreach (string key in map.ItemSpawns.Spawns.GetKeys()) { SpawnList <InvItem> spawns = map.ItemSpawns.Spawns.GetSpawn(key); for (int ii = 0; ii < spawns.Count; ii++) { //TODO: spawn rate is somewhat distorted here InvItem spawn = spawns.GetSpawn(ii); //ItemData data = DataManager.Instance.GetItem(spawn.ID); if (Range.Min <= spawn.ID && spawn.ID < Range.Max) { subList.Add(new MapItem(spawn), spawns.GetSpawnRate(ii)); } } } } if (subList.Count == 0) { return(spawners); } for (int ii = 0; ii < itemCount; ii++) { spawners.Add(subList.Pick(map.Rand)); } return(spawners); }
protected override IEnumerable <int> GetSpecies(BaseMapGenContext map, SpawnList <MobSpawn> specialMobs) { MobSpawn baseMob = GetSeedChar(map, specialMobs); if (baseMob != null) { int earliestBaseStage = baseMob.BaseForm.Species; MonsterFeatureData featureIndex = DataManager.Instance.UniversalData.Get <MonsterFeatureData>(); FormFeatureSummary baseData = featureIndex.FeatureData[earliestBaseStage][0]; yield return(baseData.Family); } }
protected override List <int> GetTypes(BaseMapGenContext map, SpawnList <MobSpawn> specialMobs) { Dictionary <int, int> elementFrequency = new Dictionary <int, int>(); for (int ii = 0; ii < map.TeamSpawns.Count; ii++) { SpawnList <MobSpawn> mobSpawns = map.TeamSpawns.GetSpawn(ii).GetPossibleSpawns(); foreach (MobSpawn spawn in mobSpawns.EnumerateOutcomes()) { MonsterFeatureData featureIndex = DataManager.Instance.UniversalData.Get <MonsterFeatureData>(); FormFeatureSummary baseData = featureIndex.FeatureData[spawn.BaseForm.Species][Math.Max(0, spawn.BaseForm.Form)]; if (baseData.Element1 != 00) { MathUtils.AddToDictionary(elementFrequency, baseData.Element1, 1); } if (baseData.Element2 != 00) { MathUtils.AddToDictionary(elementFrequency, baseData.Element2, 1); } } } if (elementFrequency.Count == 0) { for (int ii = 0; ii < specialMobs.Count; ii++) { MobSpawn spawn = specialMobs.GetSpawn(ii); MonsterFeatureData featureIndex = DataManager.Instance.UniversalData.Get <MonsterFeatureData>(); FormFeatureSummary baseData = featureIndex.FeatureData[spawn.BaseForm.Species][Math.Max(0, spawn.BaseForm.Form)]; if (baseData.Element1 != 00) { MathUtils.AddToDictionary(elementFrequency, baseData.Element1, 1); } if (baseData.Element2 != 00) { MathUtils.AddToDictionary(elementFrequency, baseData.Element2, 1); } } } List <int> result = new List <int>(); if (elementFrequency.Count > 0) { //choose randomly from the top 3 types List <(int, int)> elements = new List <(int, int)>(); foreach (int key in elementFrequency.Keys) { elements.Add((key, elementFrequency[key]));
protected bool CheckIfAllowed(BaseMapGenContext map, MobSpawn spawn, IEnumerable <int> species) { MonsterFeatureData featureIndex = DataManager.Instance.UniversalData.Get <MonsterFeatureData>(); FormFeatureSummary baseData = featureIndex.FeatureData[spawn.BaseForm.Species][0]; foreach (int baseStage in species) { if (baseStage == baseData.Family) { return(true); } } return(false); }
public override List <MapItem> GenerateItems(BaseMapGenContext map, SpawnList <MapItem> specialItems) { int itemCount = Amount.Pick(map.Rand); List <MapItem> spawners = new List <MapItem>(); for (int ii = 0; ii < itemCount; ii++) { if (specialItems.Count > 0 && map.Rand.Next(100) < SpecialRatio) { spawners.Add(specialItems.Pick(map.Rand)); } else if (map.ItemSpawns.CanPick) { spawners.Add(new MapItem(map.ItemSpawns.Pick(map.Rand))); } } return(spawners); }
public static void TestFloor(Stopwatch watch, ZoneSegmentBase structure, ZoneGenContext zoneContext, Dictionary <int, int> generatedItems, Dictionary <int, int> generatedEnemies, List <TimeSpan> generationTimes) { TimeSpan before = watch.Elapsed; watch.Start(); IGenContext context = structure.GetMap(zoneContext); watch.Stop(); TimeSpan diff = watch.Elapsed - before; generationTimes.Add(diff); BaseMapGenContext mapContext = context as BaseMapGenContext; if (generatedItems != null) { foreach (MapItem mapItem in mapContext.Map.Items) { if (mapItem.IsMoney) { MathUtils.AddToDictionary <int>(generatedItems, -1, mapItem.Value); MathUtils.AddToDictionary <int>(generatedItems, 0, 1); } else { MathUtils.AddToDictionary <int>(generatedItems, mapItem.Value, 1); } } } if (generatedEnemies != null) { foreach (Team team in mapContext.Map.MapTeams) { foreach (Character character in team.Players) { MathUtils.AddToDictionary <int>(generatedEnemies, character.BaseForm.Species, 1); } } } }
public override List <MobSpawn> GenerateMobs(BaseMapGenContext map, SpawnList <MobSpawn> specialMobs) { int mobCount = Amount.Pick(map.Rand); List <MobSpawn> spawners = new List <MobSpawn>(); IEnumerable <int> species = GetSpecies(map, specialMobs); SpawnList <MobSpawn> subList = new SpawnList <MobSpawn>(); for (int ii = 0; ii < specialMobs.Count; ii++) { MobSpawn spawn = specialMobs.GetSpawn(ii); if (CheckIfAllowed(map, spawn, species)) { subList.Add(spawn, specialMobs.GetSpawnRate(ii)); } } for (int ii = 0; ii < map.TeamSpawns.Count; ii++) { SpawnList <MobSpawn> memberSpawns = map.TeamSpawns.GetSpawn(ii).GetPossibleSpawns(); for (int jj = 0; ii < memberSpawns.Count; jj++) { MobSpawn spawn = memberSpawns.GetSpawn(jj); if (CheckIfAllowed(map, spawn, species)) { subList.Add(spawn, memberSpawns.GetSpawnRate(jj)); } } } if (subList.Count > 0) { for (int ii = 0; ii < mobCount; ii++) { spawners.Add(subList.Pick(map.Rand)); } } return(spawners); }
public override List <MobSpawn> GenerateMobs(BaseMapGenContext map, SpawnList <MobSpawn> specialMobs) { int mobCount = Amount.Pick(map.Rand); List <MobSpawn> spawners = new List <MobSpawn>(); for (int ii = 0; ii < mobCount; ii++) { if (specialMobs.Count > 0 && map.Rand.Next(100) < SpecialRatio) { spawners.Add(specialMobs.Pick(map.Rand)); } else if (map.TeamSpawns.CanPick) { List <MobSpawn> exampleList = map.TeamSpawns.Pick(map.Rand).ChooseSpawns(map.Rand); if (exampleList.Count > 0) { spawners.Add(exampleList[map.Rand.Next(exampleList.Count)]); } } } return(spawners); }
public static void MapMenu(string prevState, int zoneIndex, SegLoc floorIndex, ZoneSegmentBase structure) { ulong zoneSeed = MathUtils.Rand.NextUInt64(); try { ulong newSeed; if (UInt64.TryParse((string)Registry.GetValue(DiagManager.REG_PATH, "SeedChoice", ""), out newSeed)) { zoneSeed = newSeed; } Registry.SetValue(DiagManager.REG_PATH, "SeedChoice", zoneSeed.ToString()); while (true) { Console.Clear(); ConsoleKey key = ConsoleKey.Enter; string state = prevState + ">" + floorIndex.ID + ": "; bool threwException = false; try { ZoneGenContext newContext = CreateZoneGenContext(zoneSeed, zoneIndex, floorIndex, structure); IGenContext context = structure.GetMap(newContext); ExampleDebug.SteppingIn = false; BaseMapGenContext stairsMap = context as BaseMapGenContext; state += stairsMap.Map.Name.DefaultText.Replace('\n', ' '); string seedMsg = "ZSeed: " + zoneSeed + " MSeed: " + newContext.Seed; //Console.WriteLine(state); key = ExampleDebug.PrintTiles(context, state + "\n" + "Arrow Keys=Navigate|Enter=Retry|ESC=Back|F2=Stress Test|F3=Custom Seed|F4=Step In" + "\n" + seedMsg, true, true, true); } catch (Exception ex) { DiagManager.Instance.LogInfo("ERROR at F" + floorIndex.ID + " SEED:" + zoneSeed); PrintError(ex); Console.WriteLine("Press Enter to retry error scenario."); key = Console.ReadKey().Key; threwException = true; } if (key == ConsoleKey.Escape) { Registry.SetValue(DiagManager.REG_PATH, "SeedChoice", ""); break; } else if (key == ConsoleKey.F2) { while (true) { Console.Clear(); Console.WriteLine(state + ">Bulk Gen"); Console.WriteLine("Specify amount to bulk gen"); int amt = GetInt(false); if (amt > -1) { Console.WriteLine("Generating floor " + amt + " times."); StressTestFloor(structure, zoneIndex, floorIndex, amt); ConsoleKeyInfo afterKey = Console.ReadKey(); if (afterKey.Key == ConsoleKey.Escape) { break; } } else if (amt == -1) { break; } } } else if (key == ConsoleKey.F3) { Console.Clear(); Console.WriteLine(state + ">Custom Seed"); Console.WriteLine("Specify a ZONE seed value"); string input = Console.ReadLine(); ulong customSeed; if (UInt64.TryParse(input, out customSeed)) { zoneSeed = customSeed; } } else if (key == ConsoleKey.F4) { ExampleDebug.SteppingIn = true; } else if (key == ConsoleKey.Enter) { if (!threwException) { zoneSeed = MathUtils.Rand.NextUInt64(); } } Registry.SetValue(DiagManager.REG_PATH, "SeedChoice", zoneSeed.ToString()); } } catch (Exception ex) { DiagManager.Instance.LogInfo("ERROR at F" + floorIndex.ID + " ZSEED:" + zoneSeed); PrintError(ex); Registry.SetValue(DiagManager.REG_PATH, "SeedChoice", ""); Console.ReadKey(); } }
public static ConsoleKey PrintTiles(IGenContext map, string msg, bool printDebug, bool printViewer, bool forcePrint) { BaseMapGenContext context = map as BaseMapGenContext; StairsMapGenContext stairsContext = map as StairsMapGenContext; if (context == null) { return(ConsoleKey.Enter); } if (!context.TilesInitialized) { return(ConsoleKey.Enter); } StringBuilder str = new StringBuilder(); for (int yy = 0; yy < context.Height; yy++) { if (yy > 0) { str.Append('\n'); } for (int xx = 0; xx < context.Width; xx++) { Loc loc = new Loc(xx, yy); char tileChar = ' '; Tile tile = (Tile)context.GetTile(loc); if (tile.ID <= 0)//floor { tileChar = '.'; } else if (tile.ID == 1)//unbreakable { tileChar = 'X'; } else if (tile.ID == 2)//wall { tileChar = '#'; } else if (tile.ID == 3)//water { tileChar = '~'; } else if (tile.ID == 4)//lava { tileChar = '^'; } else if (tile.ID == 5)//abyss { tileChar = '_'; } else { tileChar = '?'; } if (tile.Effect.ID > -1)//traps always override { tileChar = '='; } if (stairsContext != null) { for (int ii = 0; ii < ((IViewPlaceableGenContext <MapGenEntrance>)stairsContext).Count; ii++) { if (((IViewPlaceableGenContext <MapGenEntrance>)stairsContext).GetLoc(ii) == loc) { tileChar = '<'; break; } } for (int ii = 0; ii < ((IViewPlaceableGenContext <MapGenExit>)stairsContext).Count; ii++) { if (((IViewPlaceableGenContext <MapGenExit>)stairsContext).GetLoc(ii) == loc) { tileChar = '>'; break; } } } foreach (MapItem item in context.Map.Items) { if (item.TileLoc == loc) { if (item.IsMoney) { tileChar = '*'; } else { ItemData itemEntry = DataManager.Instance.GetItem(item.Value); if (itemEntry.ItemStates.Contains <FoodState>()) { tileChar = ';'; } else if (itemEntry.ItemStates.Contains <EdibleState>()) { tileChar = '!'; } else if (itemEntry.ItemStates.Contains <OrbState>() || itemEntry.ItemStates.Contains <WandState>()) { tileChar = '/'; } else if (itemEntry.ItemStates.Contains <RecruitState>()) { tileChar = '?'; } else if (itemEntry.UsageType == ItemData.UseType.Learn || itemEntry.ItemStates.Contains <UtilityState>() || itemEntry.ItemStates.Contains <MachineState>()) { tileChar = '%'; } else { tileChar = '$'; } } break; } } foreach (Team team in context.Map.MapTeams) { foreach (Character character in team.Players) { if (character.CharLoc == loc) { tileChar = character.Name[0]; break; } } } str.Append(tileChar); } } string newStr = str.ToString(); if (tileDebugString[currentDepth].MapString == newStr && !forcePrint) { return(ConsoleKey.Enter); } tileDebugString[currentDepth].MapString = newStr; if (printDebug) { Debug.WriteLine(msg); Debug.Print(newStr); } if (printViewer) { //TODO: print with highlighting (use the bounds variable) //TODO: print with color SteppingIn = false; Console.Clear(); Console.WriteLine(msg); Loc start = new Loc(Console.CursorLeft, Console.CursorTop); Console.Write(newStr); Loc end = new Loc(Console.CursorLeft, Console.CursorTop + 1); Console.SetCursorPosition(start.X, start.Y); int prevFarthestPrint = end.Y; while (true) { int farthestPrint = end.Y; Loc mapLoc = new Loc(Console.CursorLeft, Console.CursorTop) - start; rewriteLine(farthestPrint, String.Format("X:{0} Y:{1}", mapLoc.X.ToString("D3"), mapLoc.Y.ToString("D3"))); farthestPrint++; Tile tile = context.Tiles[mapLoc.X][mapLoc.Y]; rewriteLine(farthestPrint, String.Format("Terrain {0}: {1}", tile.Data.GetID(), tile.Data.GetID() > -1 ? tile.Data.GetData().Name.ToLocal() : "---")); farthestPrint++; rewriteLine(farthestPrint, String.Format("Tile {0}: {1}", tile.Effect.GetID(), tile.Effect.GetID() > -1 ? tile.Effect.GetData().Name.ToLocal() : "---")); farthestPrint++; for (int ii = 0; ii < context.Map.EntryPoints.Count; ii++) { if (context.Map.EntryPoints[ii].Loc == mapLoc) { rewriteLine(farthestPrint, String.Format("***Entrance {0}***", ii)); farthestPrint++; } } foreach (MapItem item in context.Map.Items) { if (item.TileLoc == mapLoc) { if (item.IsMoney) { rewriteLine(farthestPrint, String.Format("Money: {0}", item.Value)); } else { rewriteLine(farthestPrint, String.Format("Item: {0}", item.GetDungeonName().Replace("\u000D7", "(X)"))); } farthestPrint++; } } foreach (Team team in context.Map.MapTeams) { foreach (Character character in team.Players) { if (character.CharLoc == mapLoc) { rewriteLine(farthestPrint, String.Format("Monster:")); farthestPrint++; string nameString = String.Format(" Lv.{0} {1} ", character.Level, character.BaseName); foreach (int status in character.StatusEffects.Keys) { nameString += String.Format("[{0}]", ((StatusData)character.StatusEffects[status].GetData()).Name.ToLocal()); } rewriteLine(farthestPrint, nameString); farthestPrint++; rewriteLine(farthestPrint, String.Format(" @{0} *{1} ?{2}", character.EquippedItem.ID > -1 ? ((ItemData)character.EquippedItem.GetData()).Name.ToLocal() : "---", character.Intrinsics[0].Element.ID > -1 ? ((IntrinsicData)character.Intrinsics[0].Element.GetData()).Name.ToLocal() : "---", character.Tactic.Name)); farthestPrint++; rewriteLine(farthestPrint, String.Format(" {0}{1} {2}{3} {4}{5} {6}{7}", character.Skills[0].Element.Enabled ? "+" : "-", character.BaseSkills[0].SkillNum > -1 ? DataManager.Instance.GetSkill(character.Skills[0].Element.SkillNum).Name.ToLocal() : "---", character.Skills[1].Element.Enabled ? "+" : "-", character.BaseSkills[1].SkillNum > -1 ? DataManager.Instance.GetSkill(character.Skills[1].Element.SkillNum).Name.ToLocal() : "---", character.Skills[2].Element.Enabled ? "+" : "-", character.BaseSkills[2].SkillNum > -1 ? DataManager.Instance.GetSkill(character.Skills[2].Element.SkillNum).Name.ToLocal() : "---", character.Skills[3].Element.Enabled ? "+" : "-", character.BaseSkills[3].SkillNum > -1 ? DataManager.Instance.GetSkill(character.Skills[3].Element.SkillNum).Name.ToLocal() : "---")); farthestPrint++; } } } for (int ii = farthestPrint; ii < prevFarthestPrint; ii++) { clearLine(ii); } prevFarthestPrint = farthestPrint; Console.SetCursorPosition(start.X + mapLoc.X, start.Y + mapLoc.Y); ConsoleKeyInfo key = Console.ReadKey(true); if (key.Key == ConsoleKey.UpArrow) { Console.SetCursorPosition(Console.CursorLeft, Math.Max(start.Y, Console.CursorTop - 1)); } else if (key.Key == ConsoleKey.DownArrow) { Console.SetCursorPosition(Console.CursorLeft, Math.Min(Console.CursorTop + 1, end.Y - 1)); } else if (key.Key == ConsoleKey.LeftArrow) { Console.SetCursorPosition(Math.Max(start.X, Console.CursorLeft - 1), Console.CursorTop); } else if (key.Key == ConsoleKey.RightArrow) { Console.SetCursorPosition(Math.Min(Console.CursorLeft + 1, end.X - 1), Console.CursorTop); } else { return(key.Key); } } } else { return(ConsoleKey.Enter); } }
public abstract List <MobSpawn> GenerateMobs(BaseMapGenContext map, SpawnList <MobSpawn> specialMobs);
public abstract List <MapItem> GenerateItems(BaseMapGenContext map, SpawnList <MapItem> specialItems);
protected abstract IEnumerable <int> GetSpecies(BaseMapGenContext map, SpawnList <MobSpawn> specialMobs);