Skip to main content

Backend logic for DND 5e(2014)

Project description

Mind Goblin

⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣠⣤⣤⣀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣤⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀
⠀⠀⠀⠀⠀⠀⠀⢀⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀
⠀⠀⠀⠀⢀⣀⢾⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢋⣭⡍⣿⣿⣿⣿⣿⣿⠀
⠀⢀⣴⣶⣶⣝⢷⡝⢿⣿⣿⣿⠿⠛⠉⠀⠀⣰⣿⣿⢣⣿⣿⣿⣿⣿⣿⡇
⢀⣾⣿⣿⣿⣿⣧⠻⡌⠿⠋⠁⠀⠀⠀⠀⢰⣿⣿⡏⣸⣿⣿⣿⣿⣿⣿⣿
⣼⣿⣿⣿⣿⣿⣿⡇⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⠇⢻⣿⣿⣿⣿⣿⣿⡟
⠙⢹⣿⣿⣿⠿⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⣿⣿⡿⠟⠁
⠀⠀⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

Initial Idea

  1. Set of random generation tools (use DMG tables for reference)
  • random dungeon generation
  • random encounter generation
  • random npc generation
  • random villain generation
  • random adventure genration
  • have options to lock/freeze certain features and re-roll others
  • have option to pipe output to a json file on "save"
  • ea. sub-table used in any of the above generation must be accessible on its own

terminal input or API

stretch goal: UI (fuck this shit)

  1. Combat DM utils
  • hell, write a fucking engine for combat that takes an excel sheet and randomly rolls initiative scores for all monsters, sorts them according to initiative and updates the same sheet
  1. Story DM utils
  • weather rolls
  • random encounter rolls
  1. Encounter planning utils
  • calculate "difficulty" of an encounter
  • generate equivalent difficulty of encounter, according to parameters:
    • monsters given as input
    • number of monsters
    • specific categories of monsters ! will need DB full of monsters

Better Goals, to also help with Assessment

Pick a web python framework

Pick from the following:

  1. Django
  • fucking complex, piece of shit
  • fucking complex, piece of shit, I hate it
  • ORM and signals and shit
  1. Flask
  • simple
  • SQL alchemy ORM
  • we use on the project 1. FastAPI + lightweight + tight overlap with what I do for work

Tables should be stored in model layer, via ORM

I can also fucking model the combat encounter data

  • calls monster manual
  • conditions model
  • AC mechanism

I can also store a bestiary or see if there is any open-source API that has these fucks that I can call

https://www.dnd5eapi.co/

Deliverables

DM utils

  1. Encounter automation
  • intiative calculation
  • ordering by initiative
  • need to take this as json artifact, have another middleware service that converts to excel-like
  • then writes this data into an excel spreadsheet
  • input: monster, number
  1. Set of random generation tools (use DMG tables for reference)
  • random dungeon generation
  • random encounter generation
  • random npc generation
  • random villain generation
  • random adventure genration
  • story randomization
  • have options to lock/freeze certain features and re-roll others
  • have option to pipe output to a json file on "save"
  • ea. sub-table used in any of the above generation must be accessible on its own
  1. (stretch) I want something like a query processor:
  • input: a term that I am searching for, with fuzzy search
  • output: a description of its mechanics (str output), along with source of reference
  1. Encounter planning utils
https://github.com/fantasycalendar/kobold-plus-fight-club/tree/master
https://koboldplus.club/
  • poach this

  • fuck the ui

  • calculate "difficulty" of an encounter

  • generate equivalent difficulty of encounter, according to parameters:

    • monsters given as input
    • number of monsters
    • specific categories of monsters

Prerequisites

  1. DB of monsters

https://github.com/5e-bits/5e-database

  • poach this, convert to relational mapping, practice ORM techniques
  1. DB of active effects

https://github.com/5e-bits/5e-database

  • poach this, convert to relational mapping, practice ORM techniques

Implementation

  1. Web Framework: Flask

  2. DB Layer/ORM: sqlAlchemy

  3. Architecturally I want to have 3 major components:

    1. Self-contained, monolithic backend logic that can be interfaced with

    dungeons_logic

    1. CLI interface: basic unix input handling and shit

    dungeons_local

    1. MVC REST API that makes contact with the monolith

    dungeons_web

TODO

  • deploy everything in docker image, create db dynamically

Working with Alebic

  1. Generate migration scripts to review: this also serves to check any "compilation errors" in the models
alembic revision --autogenerate -m "description of your migration"
  • --autogenerate: Tells Alembic to automatically compare the database schema and the models to generate migration instructions.

  • -m: Specifies a short message describing the migration, such as "add new column to users table".

  1. Update/fix the migration generated in alembic/versions

NOTE: upgrade, downgrade functions contain steps for upgrading and downgrading respectively

  1. If satisfied, run
alembic upgrade head

Reverting Migrations

Latest Migration

Run

alembic downgrade -1

This command will undo the last migration, rolling back the database schema to its previous state.

Migration by id

alembic downgrade <revision_id>

Show History

alembic history --verbose

Pending Migrations

alembic heads

Versioning and Poetry

Use semver

Poetry

At the time of this commit, I am new to Poetry, as such some practices listed below may be non-optimal. Who fucking cococares.

Workflow

  • Use pip and requirements.txt for local development
  • Maintain requirements.txt in parity with pyproject.toml
  • To update pyproject.toml dependencies with those in requirements.txt
poetry add $(cat requirements.txt)

Pushing new releases

I have not implemented a workflow for releases to be pushed on commits to the main branch. Should do that later.

Currently, need to manually tag and release tags from CLI:

git tag <x.y.z>
git push origin --tags

semper fi

Deleting tags if build fails

Locally

git tag -d <x.y.z>

Remotely

git push origin --delete <tag-name>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dungeons_logic-0.0.2.tar.gz (33.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dungeons_logic-0.0.2-py3-none-any.whl (53.8 kB view details)

Uploaded Python 3

File details

Details for the file dungeons_logic-0.0.2.tar.gz.

File metadata

  • Download URL: dungeons_logic-0.0.2.tar.gz
  • Upload date:
  • Size: 33.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for dungeons_logic-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f03593db1249b5ffd82c090e05a7fca253e78a30e834fb048a1dd161e6c4b83c
MD5 b0e439db849064ed13c133d9b5791411
BLAKE2b-256 ef0102cd30ab91c81dde918301b4d19b4074b36d5a0dba9e051a310e5b474cf4

See more details on using hashes here.

Provenance

The following attestation bundles were made for dungeons_logic-0.0.2.tar.gz:

Publisher: release.yaml on nickchkonia/dungeons_logic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dungeons_logic-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: dungeons_logic-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 53.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for dungeons_logic-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d53cdabf33b5759af0a33218e87f847c58acc73d54e41a133848c5452a2f4cc0
MD5 a814caf01199316e7d8b436d6b835702
BLAKE2b-256 38798b12869aff7565b1b83eeb0c48eaaaa8cc427e0475482f90c245c4e8059b

See more details on using hashes here.

Provenance

The following attestation bundles were made for dungeons_logic-0.0.2-py3-none-any.whl:

Publisher: release.yaml on nickchkonia/dungeons_logic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page