Created
December 18, 2016 22:07
-
-
Save rvegas/8ad455523af0d6d1dd6c01f63831f8fe to your computer and use it in GitHub Desktop.
Calculates final damage according to parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, jsonify | |
import random | |
app = Flask(__name__) | |
app.config['DEBUG'] = True | |
@app.route("/", methods=['GET']) | |
def damage(): | |
damage_type = request.args.get('type', default='melee') | |
distance_to_target = request.args.get('distance', default=0, type=int) | |
base_damage = request.args.get('base', default=0, type=int) | |
modifiers = request.args.getlist('modifiers[]') | |
damage = base_damage | |
if 'true_damage' not in modifiers: | |
damage = random.uniform(0.7, 1) * base_damage | |
if 'double_damage' in modifiers: | |
damage = 2 * damage | |
if 'critical_damage_1' in modifiers: | |
if random.uniform(0, 1) < 0.10: | |
damage = damage * random.uniform(1.5, 3) | |
if damage_type == 'melee' and distance_to_target != 0: | |
damage = 0 | |
return jsonify(data={"damage": damage}) | |
if __name__ == "__main__": | |
app.run(host="0.0.0.0") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment