2024-07-01 00:56:11 +00:00
|
|
|
from flask import request
|
2024-07-01 10:26:54 +00:00
|
|
|
from flask_restx import Resource, Namespace, reqparse
|
2024-07-01 00:56:11 +00:00
|
|
|
|
|
|
|
from app.functions.roll_ability_check import roll_ability_check
|
|
|
|
|
|
|
|
namespace = Namespace('gameplay', description='Gamma World Rules')
|
2024-07-01 10:26:54 +00:00
|
|
|
# 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)')
|
2024-07-01 00:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
@namespace.route('/ability/check') # resolves to: /gameplay/ability/check
|
|
|
|
class AbilityCheck(Resource):
|
2024-07-01 10:26:54 +00:00
|
|
|
@namespace.expect(parser)
|
2024-07-01 00:56:11 +00:00
|
|
|
def get(self):
|
|
|
|
score = request.args.get('score', type=int)
|
|
|
|
multiplier = request.args.get('multiplier', type=float)
|
2024-07-01 10:26:54 +00:00
|
|
|
if score < 3 or score > 21:
|
|
|
|
return {'message': 'Ability score must be between 3 and 21'}, 400
|
2024-07-14 22:04:58 +00:00
|
|
|
if multiplier < 1 or multiplier > 10:
|
2024-07-01 10:26:54 +00:00
|
|
|
return {'message': 'Multiplier must be between 2 and 10'}, 400
|
2024-07-01 00:56:11 +00:00
|
|
|
|
|
|
|
outcome = roll_ability_check(score, multiplier)
|
|
|
|
return outcome, 200
|