Feast 2.0!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

111 lines
2.6 KiB

  1. import { TextLike, Verb, Noun, ProperNoun } from '@/game/language'
  2. import { Creature } from '@/game/creature'
  3. import moment, { Moment, Duration } from 'moment'
  4. import { LogEntry, LogLines } from '@/game/interface'
  5. import { Encounter } from '@/game/combat'
  6. export enum Direction {
  7. Northwest = "Northwest",
  8. North = "North",
  9. Northeast = "Northeast",
  10. West = "West",
  11. East = "East",
  12. Southwest = "Southwest",
  13. South = "South",
  14. Southeast = "Southeast"
  15. }
  16. export function reverse (dir: Direction): Direction {
  17. switch (dir) {
  18. case Direction.Northwest: return Direction.Southeast
  19. case Direction.North: return Direction.South
  20. case Direction.Northeast: return Direction.Southwest
  21. case Direction.West: return Direction.East
  22. case Direction.East: return Direction.West
  23. case Direction.Southwest: return Direction.Northeast
  24. case Direction.South: return Direction.North
  25. case Direction.Southeast: return Direction.Northwest
  26. }
  27. }
  28. export class Choice {
  29. constructor (public name: TextLike, public desc: TextLike, public execute: (world: World, executor: Creature) => LogEntry) {
  30. }
  31. visible (): boolean {
  32. return true
  33. }
  34. accessible (): boolean {
  35. return true
  36. }
  37. }
  38. export class Connection {
  39. constructor (public src: Place, public dst: Place, public name: TextLike = "Travel", public desc: TextLike = "Go there lol") {
  40. }
  41. visible (): boolean {
  42. return true
  43. }
  44. accessible (): boolean {
  45. return true
  46. }
  47. travel (world: World, traveler: Creature): LogEntry {
  48. const advanceLogs = world.advance(moment.duration(5, "minutes"))
  49. traveler.location = this.dst
  50. return new LogLines(
  51. advanceLogs,
  52. `${traveler.name.capital} ${traveler.name.conjugate(new Verb('travel'))} to ${this.dst.name}.`
  53. )
  54. }
  55. }
  56. export class Place {
  57. connections: {[key in Direction]?: Connection} = {}
  58. choices: Choice[] = []
  59. constructor (public name: Noun, public desc: TextLike) {
  60. }
  61. connect (dir: Direction, dst: Place) {
  62. this.connections[dir] = new Connection(this, dst)
  63. }
  64. biconnect (dir: Direction, dst: Place) {
  65. this.connect(dir, dst)
  66. dst.connect(reverse(dir), this)
  67. }
  68. }
  69. export const Nowhere = new Place(
  70. new ProperNoun("Nowhere"),
  71. "This isn't anywhere!"
  72. )
  73. export class World {
  74. time: Moment
  75. creatures: Creature[] = []
  76. encounter: Encounter|null = null
  77. party: Creature[] = []
  78. constructor (public player: Creature) {
  79. this.time = moment.utc([500, 1, 1, 9, 0, 0, 0])
  80. this.creatures.push(player)
  81. }
  82. advance (dt: Duration): LogEntry {
  83. this.time.add(dt)
  84. return new LogLines(
  85. ...this.player.containers.map(
  86. container => container.tick(dt.asSeconds())
  87. )
  88. )
  89. }
  90. }