27 lines
982 B
Python
27 lines
982 B
Python
from flask import request
|
|
from flask_restx import Resource, Namespace
|
|
|
|
from app.functions.roll_encounter import roll_encounter
|
|
|
|
namespace = Namespace('gameplay', description='Gamma World Game Play')
|
|
|
|
VALID_TERRAINS = ["clear", "mountains", "forest", "desert", "watery", "ruins", "deathlands"]
|
|
|
|
|
|
@namespace.route('/encounter') # resolves to: /gameplay/encounter
|
|
class RollEncounter(Resource):
|
|
@namespace.doc(params={'terrain': 'The terrain type for the encounter'})
|
|
def get(self):
|
|
terrain = request.args.get('terrain', default=None, type=str)
|
|
|
|
if terrain:
|
|
if terrain.lower() in VALID_TERRAINS:
|
|
return roll_encounter(terrain.lower()), 200
|
|
else:
|
|
return {
|
|
'error': 'Invalid terrain type provided.',
|
|
'valid_terrains': VALID_TERRAINS
|
|
}, 400
|
|
else:
|
|
return {'error': 'No terrain type provided', 'valid_terrains': VALID_TERRAINS}, 400
|