add check roll
This commit is contained in:
parent
5dc73d949c
commit
e765b4723c
29
app.py
29
app.py
@ -2,9 +2,10 @@ from flask import Flask
|
||||
from flask_cors import CORS
|
||||
from flask_restx import Api, Resource
|
||||
|
||||
from models import dice_model, ability_model, hp_model, character_model, encounter_model, ma_model, mutation_model
|
||||
from models import dice_model, ability_model, hp_model, character_model, encounter_model, ma_model, mutation_model, \
|
||||
check_model
|
||||
from schemas import DiceSchema, CharacterSchema, EncounterSchema, MentalAttackSchema, AbilitySchema, HPSchema, \
|
||||
MutationSchema
|
||||
MutationSchema, CheckSchema
|
||||
|
||||
from encounters import EncounterTable
|
||||
from mentattack import MentalAttackMatrix
|
||||
@ -27,6 +28,10 @@ ma = api.namespace('ma', description='Mental Attack operations')
|
||||
mut = api.namespace('mut', description='Mutation operations')
|
||||
character = api.namespace('character', description='Character operations')
|
||||
encounter = api.namespace('encounter', description='Encounter operations')
|
||||
check = api.namespace('check', description='Check operations')
|
||||
|
||||
check_model = check.model('Check', check_model )
|
||||
check_schema = CheckSchema()
|
||||
|
||||
ability_model = ability.model('Ability', ability_model)
|
||||
ability_schema = AbilitySchema()
|
||||
@ -164,6 +169,26 @@ class RollMentalAttack(Resource):
|
||||
return result, 200
|
||||
|
||||
|
||||
@api.route('/roll/check', methods=['POST'])
|
||||
class RollCheck(Resource):
|
||||
@check.expect(check_model)
|
||||
def post(self):
|
||||
data = api.payload
|
||||
errors = check_schema.validate(data)
|
||||
if errors:
|
||||
return errors, 400
|
||||
|
||||
ability_score = data.get('ability_score')
|
||||
multiplier = data.get('multiplier')
|
||||
|
||||
threshold = ability_score * multiplier
|
||||
rolled = roll_dices(1, 100, False).get('result')
|
||||
if rolled < threshold:
|
||||
return {'threshold': threshold, 'rolled': rolled, 'success': True}, 200
|
||||
else:
|
||||
return {'threshold': threshold, 'rolled': rolled, 'success': False}, 200
|
||||
|
||||
|
||||
@api.route('/roll/tohit', methods=['GET'])
|
||||
class RollToHit(Resource):
|
||||
@staticmethod
|
||||
|
17
models.py
17
models.py
@ -15,6 +15,23 @@ conscore_field = fields.Integer(
|
||||
description='The characters constitution score'
|
||||
)
|
||||
|
||||
check_model = {
|
||||
'ability_score': fields.Integer(
|
||||
required=True,
|
||||
default=10,
|
||||
min=3,
|
||||
max=21,
|
||||
description='The score of the ability to check against'
|
||||
),
|
||||
'multiplier': fields.Integer(
|
||||
required=True,
|
||||
default=4,
|
||||
min=2, max=8,
|
||||
description='Sets the threshold for the check. In general, the higher the multiplier, the higher the '
|
||||
'likelihood of success. Range: 2 - 7'
|
||||
)
|
||||
}
|
||||
|
||||
# Mutations Model
|
||||
mutation_model = {
|
||||
'conscore': conscore_field,
|
||||
|
16
schemas.py
16
schemas.py
@ -59,6 +59,22 @@ class AbilitySchema(Schema):
|
||||
)
|
||||
|
||||
|
||||
class CheckSchema(Schema):
|
||||
ability_score = fields.Integer(
|
||||
required=True,
|
||||
default=10,
|
||||
validate=validate.Range(min=3, max=21),
|
||||
description='The score of the ability to be checked against'
|
||||
)
|
||||
multiplier = fields.Integer(
|
||||
required=True,
|
||||
default=4,
|
||||
validate=validate.Range(min=2, max=8),
|
||||
description='Sets the threshold for the check. In general, the higher the multiplier, the higher the '
|
||||
'likelihood of success. Range: 2 - 7'
|
||||
)
|
||||
|
||||
|
||||
class EncounterSchema(Schema):
|
||||
terrain = fields.String(
|
||||
required=True,
|
||||
|
Loading…
Reference in New Issue
Block a user