gammatools/app/routes/ability_check.py

28 lines
1.1 KiB
Python
Raw Normal View History

from flask import request
from flask_restx import Resource, Namespace, reqparse
from app.functions.roll_ability_check import roll_ability_check
namespace = Namespace('gameplay', description='Gamma World Rules')
# Define the parser and request args:
parser = reqparse.RequestParser()
parser.add_argument('score', type=int, required=True,
help='The score of the ability to be checked (3 - 21)')
parser.add_argument('multiplier', type=int, required=True,
help='The score multiplier for this check attempt (2 - 10)')
@namespace.route('/ability/check') # resolves to: /gameplay/ability/check
class AbilityCheck(Resource):
@namespace.expect(parser)
def get(self):
score = request.args.get('score', type=int)
multiplier = request.args.get('multiplier', type=float)
if score < 3 or score > 21:
return {'message': 'Ability score must be between 3 and 21'}, 400
if multiplier < 2 or multiplier > 10:
return {'message': 'Multiplier must be between 2 and 10'}, 400
outcome = roll_ability_check(score, multiplier)
return outcome, 200