GraphLine.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace DunGen.Graph
  5. {
  6. /// <summary>
  7. /// A line segment on the dungeon flow graph, representing a series of tiles forming a path through the dungeon
  8. /// </summary>
  9. [Serializable]
  10. public class GraphLine
  11. {
  12. public DungeonFlow Graph;
  13. /// <summary>
  14. /// A collection of dungeon archetypes, of which one will be chosen to populate this segment of the dungeon
  15. /// </summary>
  16. public List<DungeonArchetype> DungeonArchetypes = new List<DungeonArchetype>();
  17. /// <summary>
  18. /// This segment's normalized position on the graph (0-1)
  19. /// </summary>
  20. public float Position;
  21. /// <summary>
  22. /// This segment's normalized length (0-1)
  23. /// </summary>
  24. public float Length;
  25. /// <summary>
  26. /// A list of possible keys to be placed in this area
  27. /// </summary>
  28. public List<KeyLockPlacement> Keys = new List<KeyLockPlacement>();
  29. /// <summary>
  30. /// A list of possible locked doors to be placed in this area
  31. /// </summary>
  32. public List<KeyLockPlacement> Locks = new List<KeyLockPlacement>();
  33. public GraphLine(DungeonFlow graph)
  34. {
  35. Graph = graph;
  36. }
  37. public DungeonArchetype GetRandomArchetype(RandomStream randomStream, IEnumerable<DungeonArchetype> usedArchetypes)
  38. {
  39. var validArchetypes = DungeonArchetypes.Where(a => !a.Unique || !usedArchetypes.Contains(a));
  40. if (!validArchetypes.Any())
  41. validArchetypes = DungeonArchetypes;
  42. int index = randomStream.Next(0, validArchetypes.Count());
  43. return validArchetypes.ElementAt(index);
  44. }
  45. }
  46. }