Coder Social home page Coder Social logo

Comments (3)

Kalima avatar Kalima commented on August 24, 2024 1
import { EncounterData, TerrainEncounterMap } from '../models/encounter.model'

export const encounterTable: TerrainEncounterMap = {
  plains: {
    41: 1,
    42: 16,
    43: 2,
    44: 3,
    45: 4,
    46: 5,
    51: 6,
    52: 7,
    53: 34,
    54: 8,
    55: 9,
    56: 10,
    61: 11,
    62: 12,
    63: 13,
    64: 14,
    65: 15,
    66: 30,
  },
  forest: {
    41: 1,
    42: 16,
    43: 17,
    44: 18,
    45: 2,
    46: 28,
    51: 3,
    52: 6,
    53: 7,
    54: 34,
    55: 8,
    56: 24,
    61: 9,
    62: 10,
    63: 11,
    64: 12,
    65: 13,
    66: 26,
  },
  darkForest: {
    41: 1,
    42: 1,
    43: 18,
    44: 19,
    45: 20,
    46: 21,
    51: 3,
    52: 25,
    53: 24,
    54: 9,
    55: 9,
    56: 10,
    61: 11,
    62: 12,
    63: 13,
    64: 29,
    65: 27,
    66: 30,
  },
  hills: {
    41: 1,
    42: 2,
    43: 31,
    44: 21,
    45: 22,
    46: 3,
    51: 4,
    52: 5,
    53: 7,
    54: 33,
    55: 34,
    56: 24,
    61: 9,
    62: 32,
    63: 11,
    64: 12,
    65: 13,
    66: 14,
  },
  mountain: {
    41: 1,
    42: 35,
    43: 31,
    44: 21,
    45: 22,
    46: 4,
    51: 5,
    52: 23,
    53: 7,
    54: 33,
    55: 36,
    56: 24,
    61: 9,
    62: 32,
    63: 11,
    64: 12,
    65: 13,
    66: 37,
  },
  lake: {
    41: 0,
    42: 0,
    43: 1,
    44: 1,
    45: 38,
    46: 38,
    51: 4,
    52: 4,
    53: 39,
    54: 39,
    55: 39,
    56: 39,
    61: 5,
    62: 5,
    63: 40,
    64: 40,
    65: 41,
    66: 41,
  },
  swamp: {
    41: 1,
    42: 5,
    43: 9,
    44: 9,
    45: 11,
    46: 12,
    51: 12,
    52: 13,
    53: 16,
    54: 18,
    55: 21,
    56: 29,
    61: 30,
    62: 38,
    63: 40,
    64: 41,
    65: 42,
    66: 42,
  },
  mire: {
    41: 1,
    42: 4,
    43: 5,
    44: 7,
    45: 8,
    46: 9,
    51: 10,
    52: 11,
    53: 12,
    54: 13,
    55: 14,
    56: 16,
    61: 21,
    62: 23,
    63: 29,
    64: 30,
    65: 34,
    66: 42,
  },
  ruinCity: {
    41: 1,
    42: 4,
    43: 5,
    44: 6,
    45: 8,
    46: 9,
    51: 9,
    52: 9,
    53: 11,
    54: 12,
    55: 13,
    56: 21,
    61: 21,
    62: 24,
    63: 29,
    64: 30,
    65: 34,
    66: 43,
  },
}

export const allEncounters: EncounterData = {
  '0': { title: 'No Encounter', page: 142 },
  '1': { title: 'The Blood Mist', page: 143 },
  '2': { title: 'Duel in the Woods', page: 144 },
  '3': { title: 'The Orcish Fugitive', page: 144 },
  '4': { title: 'Death from Above', page: 144 },
  '5': { title: '`The Harpies' Feast`', page: 145 },
  '6': { title: 'The Horse', page: 145 },
  '7': { title: 'The Massacre Lure', page: 145 },
  '8': { title: 'The Great Insulter', page: 146 },
  '9': { title: 'The Ruins of Old', page: 146 },
  '10': { title: 'The Fox', page: 147 },
  '11': { title: 'The Forgotten Prince', page: 147 },
  '12': { title: 'The Hungry Robbers', page: 148 },
  '13': { title: 'The Plague Brother', page: 148 },
  '14': { title: 'Flagellants', page: 148 },
  '15': { title: 'Beggars', page: 149 },
  '16': { title: 'The Dwarf Balloon Pilot', page: 149 },
  '17': { title: 'Wedding', page: 150 },
  '18': { title: 'The Demon Baker', page: 150 },
  '19': { title: 'The Animal Sanctum', page: 151 },
  '20': { title: 'The Burial Procession', page: 151 },
  '21': { title: 'The Vengeful Spirit', page: 152 },
  '22': { title: 'The Glass-Blower', page: 152 },
  '23': { title: 'The Puppy', page: 153 },
  '24': { title: 'The Cursed Ogre', page: 153 },
  '25': { title: 'Candle-Makers', page: 153 },
  '26': { title: 'Forest Fire', page: 154 },
  '27': { title: 'Black Sand', page: 154 },
  '28': { title: 'The Empty House', page: 155 },
  '29': { title: 'The Rustle of Bones', page: 155 },
  '30': { title: 'Teramalda', page: 155 },
  '31': { title: 'The Stone Singers', page: 156 },
  '32': { title: 'Rats', page: 156 },
  '33': { title: '`The Minotaur's Lament`', page: 157 },
  '34': { title: 'The Restless Dead', page: 157 },
  '35': { title: 'The Sleepy Troll', page: 158 },
  '36': { title: 'The Furless', page: 158 },
  '37': { title: 'Roadblock', page: 159 },
  '38': { title: 'The Infected', page: 159 },
  '39': { title: 'The Stowaway', page: 160 },
  '40': { title: 'Death from Below', page: 160 },
  '41': { title: 'The Trader of Souls', page: 160 },
  '42': { title: 'The Lizard Hunters', page: 161 },
  '43': { title: 'Buried Alive', page: 161 },
}

from yxans-klagan.

Kalima avatar Kalima commented on August 24, 2024

EN Translation for encounter.page.tsx

import React, { useState } from 'react'
import 'twin.macro'
import { Button, PageHeader } from '../components'
import { Encounter } from '../components/encounter'
import { getRandomEncounter } from '../functions/encounter.functions'
import { getTerrainName } from '../functions/terrain.functions'
import { EncounterViewModel } from '../models/encounter.model'
import { getTerrainKeys, Terrain } from '../models/terrain.model'

export const EncounterPage = () => {
  const [encounter, setEncounter] = useState<EncounterViewModel | undefined>(
    undefined,
  )

  const [oldTerrain, setOldTerrain] = useState<Terrain | undefined>(undefined)

  const [encounterLog, setEncounterLog] = useState<
    (EncounterViewModel & { timeStamp: number })[]
  >([])

  const handleClick = (terrain: Terrain) => {
    const randomEncounter = getRandomEncounter(terrain)
    setEncounter(randomEncounter)

    if (
      (terrain === undefined && oldTerrain === undefined) ||
      terrain === oldTerrain
    ) {
      setEncounterLog([
        { ...randomEncounter, timeStamp: new Date().getTime() },
        ...encounterLog,
      ])
    } else {
      setEncounterLog([{ ...randomEncounter, timeStamp: new Date().getTime() }])
    }
    setOldTerrain(terrain)
  }

  return (
    <div tw="flex flex-col gap-y-8 w-full items-center">
      <PageHeader>Encounters</PageHeader>
      <div tw="w-full bg-gray-200 p-2 grid grid-cols-2 md:grid-cols-3 lg:(flex) gap-2">
        {getTerrainKeys().map((t) => (
          <Button
            key={t}
            isSmall
            onClick={() => {
              handleClick(t)
            }}
          >
            {getTerrainName(t)}
          </Button>
        ))}
      </div>

      <div tw="w-full grid md:grid-flow-col auto-cols-auto gap-16">
        {encounter && (
          <div tw="max-w-prose lg:(w-[65ch])">
            <Encounter encounter={{ ...encounter }}></Encounter>
          </div>
        )}
        {!encounter && <div></div>}
        {!encounterLog && <div></div>}
        {encounterLog && (
          <ul tw="flex flex-col gap-1">
            {encounterLog.map((el) => (
              <li tw="flex gap-1" key={el.timeStamp}>
                <div tw="font-medium">
                  {el.id}: {el.title}
                </div>
                <div>(s. {el.page})</div>
              </li>
            ))}
          </ul>
        )}
      </div>
    </div>
  )
}

from yxans-klagan.

syradar avatar syradar commented on August 24, 2024

From @Kalima

const terrain = [
  'plains',
  'forest',
  'darkForest',
  'hills',
  'mountain',
  'lake',
  'swamp',
  'mire',
  'ruinCity',
] as const
export type Terrain = typeof terrain[number]

export type TerrainNameMap = { [T in Terrain]: string }

export const getTerrainKeys = (): Terrain[] => [...terrain]

export const terrainNameMap: TerrainNameMap = {
  plains: 'plains',
  forest: 'forest',
  darkForest: 'dark forest',
  hills: 'hills',
  mountain: 'mountains',
  lake: 'lake',
  swamp: 'marshlands',
  mire: 'quagmire',
  ruinCity: 'ruins',
}

from yxans-klagan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.