import { TextLike, Verb, Noun, ProperNoun } from './language' import { Entity } from './entity' import { Creature } from './creature' import moment, { Moment, Duration } from 'moment' import { LogEntry, LogLine, LogLines } from './interface' import { Encounter } from './combat' export enum Direction { Northwest = "Northwest", North = "North", Northeast = "Northeast", West = "West", East = "East", Southwest = "Southwest", South = "South", Southeast = "Southeast" } export function reverse (dir: Direction): Direction { switch (dir) { case Direction.Northwest: return Direction.Southeast case Direction.North: return Direction.South case Direction.Northeast: return Direction.Southwest case Direction.West: return Direction.East case Direction.East: return Direction.West case Direction.Southwest: return Direction.Northeast case Direction.South: return Direction.North case Direction.Southeast: return Direction.Northwest } } export class Choice { constructor (public name: TextLike, public desc: TextLike, public execute: (world: World, executor: Creature) => LogEntry) { } visible (world: World): boolean { return true } accessible (world: World): boolean { return true } } export class Connection { constructor (public src: Place, public dst: Place, public name: TextLike = "Travel", public desc: TextLike = "Go there lol") { } visible (world: World, traveler: Creature): boolean { return true } accessible (world: World, traveler: Creature): boolean { return true } travel (world: World, traveler: Creature): LogEntry { const advanceLogs = world.advance(moment.duration(5, "minutes")) traveler.location = this.dst return new LogLines( advanceLogs, `${traveler.name.capital} ${traveler.name.conjugate(new Verb('travel'))} to ${this.dst.name}.` ) } } export class Place { connections: {[key in Direction]?: Connection} = {} choices: Choice[] = [] constructor (public name: Noun, public desc: TextLike) { } connect (dir: Direction, dst: Place) { this.connections[dir] = new Connection(this, dst) } biconnect (dir: Direction, dst: Place) { this.connect(dir, dst) dst.connect(reverse(dir), this) } } export const Nowhere = new Place( new ProperNoun("Nowhere"), "This isn't anywhere!" ) export class World { time: Moment creatures: Creature[] = [] encounter: Encounter|null = null constructor (public player: Creature) { this.time = moment.utc([500, 1, 1, 9, 0, 0, 0]) this.creatures.push(player) } advance (dt: Duration): LogEntry { this.time.add(dt) return new LogLines( ...this.player.containers.map( container => container.tick(dt.asSeconds()) ) ) } }