add encounters roll
This commit is contained in:
parent
4e9cd5593a
commit
8671ae5262
36
app.py
36
app.py
@ -2,7 +2,9 @@ from flask import Flask
|
||||
from flask_cors import CORS
|
||||
from flask_restx import Api, Resource
|
||||
from marshmallow import Schema, fields, validate
|
||||
from models import dice_model, ability_model, hp_model, character_model
|
||||
from models import dice_model, ability_model, hp_model, character_model, encounter_model
|
||||
|
||||
from encounters import EncounterTable
|
||||
from mutations import Mutations
|
||||
import random
|
||||
|
||||
@ -17,11 +19,13 @@ dice = api.namespace('dice', description='Dice operations')
|
||||
ability = api.namespace('ability', description='Ability operations')
|
||||
hp = api.namespace('hp', description='HP operations')
|
||||
character = api.namespace('character', description='Character operations')
|
||||
encounter = api.namespace('encounter', description='Encounter operations')
|
||||
|
||||
dice_model = dice.model('Dice', dice_model)
|
||||
ability_model = ability.model('Ability', ability_model)
|
||||
hp_model = hp.model('HP', hp_model)
|
||||
character_model = character.model('Character', character_model)
|
||||
encounter_model = encounter.model('Encounter', encounter_model)
|
||||
|
||||
|
||||
class DiceSchema(Schema):
|
||||
@ -49,6 +53,17 @@ class CharacterSchema(Schema):
|
||||
character_schema = CharacterSchema()
|
||||
|
||||
|
||||
class EncounterSchema(Schema):
|
||||
terrain = fields.String(
|
||||
required=True,
|
||||
validate=validate.OneOf(["clear", "mountains", "forest", "desert", "watery", "ruins", "deathlands"]),
|
||||
description='The terrain traversed at the time of the encounter roll'
|
||||
)
|
||||
|
||||
|
||||
encounter_schema = EncounterSchema()
|
||||
|
||||
|
||||
@api.route('/roll/dice', methods=['POST'])
|
||||
class RollDice(Resource):
|
||||
@dice.expect(dice_model)
|
||||
@ -94,6 +109,25 @@ class RollHP(Resource):
|
||||
return roll_dices(conscore, geometry, False), 200
|
||||
|
||||
|
||||
@api.route('/roll/encounter', methods=['POST'])
|
||||
class RollEncounter(Resource):
|
||||
@encounter.expect(encounter_model)
|
||||
def post(self):
|
||||
data = api.payload
|
||||
errors = encounter_schema.validate(data)
|
||||
if errors:
|
||||
return errors, 400
|
||||
|
||||
terrain = data.get('terrain').lower()
|
||||
roll = roll_dices(1, 20, False).get('result')
|
||||
et = EncounterTable()
|
||||
creature = et.get_encounter(roll, terrain)
|
||||
if creature is None:
|
||||
creature = "All clear!"
|
||||
|
||||
return {"encounter": creature}, 200
|
||||
|
||||
|
||||
@api.route('/roll/tohit', methods=['GET'])
|
||||
class RollToHit(Resource):
|
||||
def get(self):
|
||||
|
30
encounters.py
Normal file
30
encounters.py
Normal file
@ -0,0 +1,30 @@
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
|
||||
class EncounterTable:
|
||||
def __init__(self):
|
||||
self.table = {
|
||||
'clear': ['zarn', 'yexil', 'android', 'badder', 'sleeth', 'arn', 'herp', 'podog', 'podog', 'jaget',
|
||||
'centisteed', 'rakox', 'rakox', 'brutorz', 'hoop', 'hawkoid', 'hopper', 'hopper', None, None],
|
||||
'mountains': ['hisser', 'blight', 'parn', 'zarn', 'manta', 'orlen', 'zeethh', 'sep', 'arn', 'yexil', 'herp',
|
||||
'wardent', 'kep plant', 'crep plant', 'cal then', 'ark', 'hawkoid', 'podog', 'carrin', None],
|
||||
'forest': ['hisser', 'sep', 'blaash', 'blackun', 'terl', 'winseen', 'pineto', 'perth', 'obb', 'kailin',
|
||||
'grens', 'badder', 'arn', 'lil', 'blood bird', 'horl choo', 'soul besh', 'dabber', 'centisteed',
|
||||
None],
|
||||
'desert': ['serf', 'kamodo', 'blight', 'perth', 'parn', 'zarn', 'yexil', 'hisser', 'sep', 'calthen',
|
||||
'manta', 'kep plant', 'carrin', 'podog', None, None, None, None, None, None],
|
||||
'watery': ['winseen', 'crep plant', 'seroon loo', 'terl', 'ert telden', 'barl nep', 'ert', 'fleshin',
|
||||
'keeshin', 'narlep', 'menarl', 'herkel', 'berlep', 'crentosh', 'fen', 'gator', None, None, None,
|
||||
None],
|
||||
'ruins': ['arn', 'obb', 'hoop', 'android', 'badder', 'serf', 'blaash', 'yexil', 'manta', 'ark', 'orlen',
|
||||
'dabber', 'sleeth', 'carrin', 'squeeker', 'squeeker', 'squeeker', None, None, None],
|
||||
'deathlands': ['android', 'hisser', 'blight', 'zarn', 'perth', 'blaash', 'serf', 'parn', 'squeeker',
|
||||
'squeekr', None, None, None, None, None, None, None, None, None, None]
|
||||
}
|
||||
self.table_dataframe = pd.DataFrame(self.table)
|
||||
self.table_dataframe.index = np.arange(1, len(self.table_dataframe) + 1)
|
||||
self.table_dataframe.columns = self.table_dataframe.columns.str.lower()
|
||||
|
||||
def get_encounter(self, roll, environ):
|
||||
return self.table_dataframe.loc[roll, environ]
|
@ -30,3 +30,11 @@ character_model = {
|
||||
default="random",
|
||||
description='The attribute emphasis of your character. Choices: "physical", "mental", "random"')
|
||||
}
|
||||
|
||||
encounter_model = {
|
||||
'terrain': fields.String(
|
||||
required=True,
|
||||
default="clear",
|
||||
description='The terrain being traversed by the party when the encounter roll is made'
|
||||
)
|
||||
}
|
||||
|
@ -3,3 +3,4 @@ flask-restx~=1.3.0
|
||||
marshmallow~=3.21.3
|
||||
pandas~=2.2.2
|
||||
flask-cors~=4.0.1
|
||||
numpy~=2.0.0
|
Loading…
Reference in New Issue
Block a user