Feast 2.0!
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

111 строки
2.7 KiB

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