2025-08-05 17:57:43 -07:00
|
|
|
import json
|
|
|
|
import random
|
|
|
|
|
|
|
|
import flask
|
|
|
|
|
|
|
|
from . import core
|
|
|
|
|
2025-09-29 20:31:42 -07:00
|
|
|
## \brief Rolls a random integer between `min` and `max`, and applies all described `modifiers`.
|
|
|
|
# \param min The lowest possible number. Default is 0.
|
|
|
|
# \param max The highest possible number. Default is 100.
|
|
|
|
# \param modifiers
|
|
|
|
# \return The result of the dice roll, after modifiers.
|
|
|
|
#
|
|
|
|
# Dice roll is actually a slight misnomer; the game primarily uses percentages for chance
|
|
|
|
# calculations. However, the recognized term for these chance calculations, "dice rolls",
|
|
|
|
# is D&D old, so is used here for mental ease.
|
2025-08-05 17:57:43 -07:00
|
|
|
def dice_roll(min=0, max=100, modifiers=[]):
|
|
|
|
result = random.randint(min, max)
|
|
|
|
for _, mod in modifiers:
|
|
|
|
result += mod
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
2025-09-29 20:31:42 -07:00
|
|
|
def calculate_speed(agl):
|
|
|
|
return 3+(agl * 1.5)
|
|
|
|
|
|
|
|
## \brief Attempts to steal a given resource from a target.
|
|
|
|
# \param resource The resource to steal.
|
|
|
|
# \param target The class of target to steal from.
|
|
|
|
# \api{POST} /act/steal/`<resource>`/`<target>`
|
|
|
|
# \apidata Gamestate.
|
2025-08-07 15:37:23 -07:00
|
|
|
@core.app.route("/act/steal/<resource>/<target>", methods=["POST"])
|
|
|
|
def steal_resource(resource, target):
|
2025-09-29 20:31:42 -07:00
|
|
|
core.log.debug(flask.request.get_data())
|
|
|
|
gamestate = flask.request.get_json()["gamestate"]
|
|
|
|
agl = gamestate["agility"]
|
|
|
|
roll = dice_roll()
|
|
|
|
speed = calculate_speed(agl)
|
|
|
|
result = (roll + speed) + (agl/4)
|
2025-08-05 17:57:43 -07:00
|
|
|
return flask.Response(json.dumps({
|
2025-09-29 20:31:42 -07:00
|
|
|
"success": (result >= 50)
|
2025-08-07 15:37:23 -07:00
|
|
|
}), status=200, content_type="application/json")
|
|
|
|
|
2025-09-29 20:31:42 -07:00
|
|
|
## \brief Attempts to recruit a seagull.
|
|
|
|
# \api{POST} /act/recruit
|
|
|
|
# \apidata Gamestate.
|
2025-08-07 15:37:23 -07:00
|
|
|
@core.app.route("/act/recruit", methods=["POST"])
|
|
|
|
def recruit():
|
|
|
|
return flask.Response(json.dumps({
|
|
|
|
"success": (dice_roll() >= 65)
|
2025-08-05 17:57:43 -07:00
|
|
|
}), status=200, content_type="application/json")
|