diff --git a/app/pylocal/actions.py b/app/pylocal/actions.py index ada9259..cf2ae01 100644 --- a/app/pylocal/actions.py +++ b/app/pylocal/actions.py @@ -12,8 +12,14 @@ def dice_roll(min=0, max=100, modifiers=[]): return result -@core.app.route("/act/steal/", methods=["POST"]) -def steal_resource(resource): +@core.app.route("/act/steal//", methods=["POST"]) +def steal_resource(resource, target): return flask.Response(json.dumps({ "success": (dice_roll() >= 50) + }), status=200, content_type="application/json") + +@core.app.route("/act/recruit", methods=["POST"]) +def recruit(): + return flask.Response(json.dumps({ + "success": (dice_roll() >= 65) }), status=200, content_type="application/json") \ No newline at end of file diff --git a/app/pylocal/desktop.py b/app/pylocal/desktop.py index 02988da..972560c 100644 --- a/app/pylocal/desktop.py +++ b/app/pylocal/desktop.py @@ -5,7 +5,8 @@ from . import core path_storagedir = pathlib.Path() class JS_API: - debug_mode = False + def __init__(self): + self.debug_mode = False def load_data(self, key): if not (path_storagedir / key).exists(): diff --git a/app/pylocal/tick.py b/app/pylocal/tick.py index 92cffb7..ea3e8ee 100644 --- a/app/pylocal/tick.py +++ b/app/pylocal/tick.py @@ -24,6 +24,7 @@ tick_event_list = [] tick_event_list.append(TickEvent(0, 16, "XYZZY")) # nothing happens tick_event_list.append(TickEvent(1, 1, "FLAVOR")) # procedurally generated event of no consequence tick_event_list.append(TickEvent(10, 2, "ENCHUMAN")) # encounter: human +tick_event_list.append(TickEvent(11, 2, "ENCGULL")) @core.app.route("/tick") def tick(): @@ -50,6 +51,13 @@ def tick(): "food": items.generate_item_list("food", "humans", 0, 2), "shinies": items.generate_item_list("shinies", "humans", 0, 2) } + case 11: # ENCGULL + result["items"] = { + # TODO: read ranges from XML rule files + "food": items.generate_item_list("food", "seagulls", 0, 2), + "shinies": items.generate_item_list("shinies", "seagulls", 0, 2) + } + result["recruit_cost"] = round(random.uniform(0, 10), 2) case _: core.log.warning("undefined tick: {0}".format(result["event_type"])) diff --git a/app/rant/flavor.rant b/app/rant/flavor.rant index 6ca4407..d98c487 100644 --- a/app/rant/flavor.rant +++ b/app/rant/flavor.rant @@ -1,9 +1,14 @@ @require "wordlist" +[$title: str] @text { + <$split_str = [split: ]> + [cat: [upper: ] [lower: [join: ]]] +} + { You meet { a `[pick: ] | - `{ + [title: `{ [pick: ] | [pick: ] | [pick: ] | @@ -12,7 +17,7 @@ [pick: ] | [pick: ] | [pick: ] - } the `[pick: ] + }] the `[pick: ] }. { It completely ignores you. | You have a polite conversation about birdly affairs. | diff --git a/app/rant/food/seagulls.rant b/app/rant/food/seagulls.rant new file mode 100644 index 0000000..cbab629 --- /dev/null +++ b/app/rant/food/seagulls.rant @@ -0,0 +1,55 @@ +@require "wordlist" +[$desc_food] @text { + { + [pick: ] @weight 1.25 | + [pick: ] @weight 1.1 | + [pick: ] @weight 1.1 | + [pick: ] @weight 0.9 | + [pick: ] @weight 0.75 | + [pick: ] @weight 0.5 | + { # stuffed/filled/covered + `{ + [pick: ] @weight 1 | + [pick: ] @weight 1 | + [pick: ] @weight 1 | + [pick: ] @weight 1 | + [pick: ] @weight 1 | + [pick: ] @weight 0.5 | + [pick: ] @weight 0.5 | + [pick: ] @weight 0.25 | + [pick: ] @weight 0.33 | + [pick: ] @weight 0.25 + } `{stuffed|filled|covered|dipped|coated} + } @weight 1 # stuffed/filled/covered + } +} + +[$get_entree] @text { + { + [pick: ] | + [pick: ] + } +} + +## +[$mod_order] @text { + { + add | no | sub | extra | + half | left | right | side + } `{ + [pick: ] | + [pick: ] | + [pick: ] | + [pick: ] | + [pick: ] + } +} +## + +{ + a piece of `[pick: ] cheese | + part of a `{ + [if: [maybe]{[desc_food]}] [get_entree] | + [pick: ] + } +} \ No newline at end of file diff --git a/app/rant/shinies/seagulls.rant b/app/rant/shinies/seagulls.rant new file mode 100644 index 0000000..434fe01 --- /dev/null +++ b/app/rant/shinies/seagulls.rant @@ -0,0 +1,4 @@ +{ + a watch | + a bracelet +} \ No newline at end of file diff --git a/static/js/seagull.js b/static/js/seagull.js index aba8740..bcc4496 100644 --- a/static/js/seagull.js +++ b/static/js/seagull.js @@ -93,6 +93,9 @@ function update_ui() { page_elements["lbl_class"].innerHTML = gamestate["class"]; page_elements["lbl_xp"].innerHTML = gamestate["xp"]; page_elements["lbl_xp_next"].innerHTML = gamestate["xp_next"]; + page_elements["lbl_level"].innerHTML = gamestate["level"]; + page_elements["menu_enc_human"].value = gamestate["enc_human"]; + page_elements["menu_enc_seagull"].value = gamestate["enc_seagull"]; } var dev_toolbox_open = false; @@ -128,18 +131,32 @@ function reward_xp(amount) { } } -async function steal_resource(resource, amount, itemstr) { +async function steal_resource(resource, target, amount, itemstr) { var items = itemstr.split(",") - var stealdata = await fetch("/act/steal/" + resource, {method: "POST", body: JSON.stringify({gamestate: gamestate})}) + var stealdata = await fetch(`/act/steal/${resource}/${target}`, {method: "POST", body: JSON.stringify({gamestate: gamestate})}) .then(res => { return res.json(); }) .catch(e => { throw e; }); if (stealdata["success"] && amount > 0) { gamestate[resource] += amount; reward_xp(2); - record_log("Stole " + resource + " from a human: " + items.join(", ")); + record_log(`Stole ${resource} from a ${target}: ${items.join(", ")}`); } - else { record_log("Didn't steal " + resource + " from a human"); } + else { record_log(`Didn't steal ${resource} from a ${target}`); } +} + +async function recruit(amount) { + var stealdata = await fetch("/act/recruit", {method: "POST", body: JSON.stringify({gamestate: gamestate})}) + .then(res => { return res.json(); }) + .catch(e => { throw e; }); + + if (stealdata["success"] && amount > 0) { + gamestate["shinies"] -= amount; + reward_xp(5); + gamestate["colony"] += 1; + record_log("Successfully recruited a seagull into the colony"); + } + else { record_log("The other gull wasn't impressed. Recruiting failed."); } } async function game_tick() { @@ -193,24 +210,83 @@ async function game_tick() { logstring += "\nWhat would you like to do?"; record_log_with_choices(logstring, - "Steal food", `steal_resource('food', ${total_food}, "${food_descs.toString()}")`, - "Steal shinies", `steal_resource('shinies', ${total_shinies}, "${shinies_descs.toString()}")` + "Steal food", `steal_resource('food', 'humans', ${total_food}, "${food_descs.toString()}")`, + "Steal shinies", `steal_resource('shinies', 'humans', ${total_shinies}, "${shinies_descs.toString()}")` ) break; case "steal-food": + record_log("You have encountered a human. Attempting to steal food."); tickdata.items.food.forEach((item) => { total_food += item["amount"]; food_descs.push(item["desc"]); }) - steal_resource("food", total_food, food_descs.toString()); + steal_resource("food", "humans", total_food, food_descs.toString()); break; case "steal-shinies": + record_log("You have encountered a human. Attempting to steal shinies."); tickdata.items.shinies.forEach((item) => { total_shinies += item["amount"]; shinies_descs.push(item["desc"]); }) - steal_resource("shinies", total_shinies, shinies_descs.toString()); + steal_resource("shinies", "humans", total_shinies, shinies_descs.toString()); + break; + default: + console.error("undefined action " + page_elements["menu_enc_human"]); + break; + } + } else if (tickdata["event_type"] == 11) { // ENCGULL + var total_food = 0; + var food_descs = []; + var total_shinies = 0; + var shinies_descs = []; + + switch (page_elements["menu_enc_seagull"].value) { + case "pause": + tickdata.items.food.forEach((item) => { + total_food += item["amount"]; + food_descs.push(item["desc"]); + }); + tickdata.items.shinies.forEach((item) => { + total_shinies += item["amount"]; + shinies_descs.push(item["desc"]); + }); + + var logstring = "You have encountered a seagull. It is carrying these resources:\n\n" + logstring += "
    \n" + if (total_food > 0) { + logstring += `
  1. ${total_food.toFixed(2)} food: ${food_descs.join(", ")}
  2. \n`; + } + if (total_shinies > 0) { + logstring += `
  3. ${total_shinies.toFixed(2)} shinies: ${shinies_descs.join(", ")}
  4. \n`; + } + logstring += "
\nWhat would you like to do?"; + + record_log_with_choices(logstring, + "Recruit", `recruit(${tickdata.recruit_cost})`, + "Steal food", `steal_resource('food', 'seagulls', ${total_food}, "${food_descs.toString()}")`, + "Steal shinies", `steal_resource('shinies', 'seagulls', ${total_shinies}, "${shinies_descs.toString()}")` + ) + + break; + case "recruit": + recruit(tickdata.recruit_cost); + break + case "steal-food": + record_log("You have encountered a seagull. Attempting to steal food."); + tickdata.items.food.forEach((item) => { + total_food += item["amount"]; + food_descs.push(item["desc"]); + }) + steal_resource("food", "seagulls", total_food, food_descs.toString()); + break; + case "steal-shinies": + record_log("You have encountered a seagull. Attempting to steal shinies."); + tickdata.items.shinies.forEach((item) => { + total_shinies += item["amount"]; + shinies_descs.push(item["desc"]); + }) + steal_resource("shinies", "seagulls", total_shinies, shinies_descs.toString()); break; default: console.error("undefined action " + page_elements["menu_enc_human"]); @@ -244,6 +320,9 @@ else { target = document; } +function update_action(enc, value) { + gamestate[`enc_${enc}`] = value; +} target.addEventListener(start_event, function (ev) { page_elements["div_log"] = document.querySelector("#main-log"); @@ -259,9 +338,13 @@ target.addEventListener(start_event, function (ev) { page_elements["lbl_tick"] = document.querySelector("#main-day-counter"); page_elements["lbl_xp"] = document.querySelector("#lbl-seagull-xp-current"); page_elements["lbl_xp_next"] = document.querySelector("#lbl-seagull-xp-next"); + page_elements["lbl_level"] = document.querySelector("#lbl-seagull-lvl"); page_elements["menu_enc_human"] = document.querySelector("#menu-enc-human"); page_elements["menu_enc_seagull"] = document.querySelector("#menu-enc-seagull"); + page_elements["menu_enc_human"].addEventListener("change", (ev) => {update_action("human", ev.target.value)}) + page_elements["menu_enc_seagull"].addEventListener("change", (ev) => {update_action("seagull", ev.target.value)}) + prepare_gamestate(); record_log("seagull game ver. " + ver_string);