human theft now reads from xml rules file
This commit is contained in:
@@ -88,8 +88,8 @@ function update_ui() {
|
||||
page_elements["lbl_name"].innerHTML = gamestate["name"];
|
||||
page_elements["lbl_tick"].innerHTML = gamestate["tick"];
|
||||
page_elements["lbl_colony"].innerHTML = gamestate["colony"];
|
||||
page_elements["lbl_shinies"].innerHTML = gamestate["shinies"];
|
||||
page_elements["lbl_food"].innerHTML = gamestate["food"];
|
||||
page_elements["lbl_shinies"].innerHTML = gamestate["shinies"].toFixed(2);
|
||||
page_elements["lbl_food"].innerHTML = gamestate["food"].toFixed(2);
|
||||
page_elements["lbl_class"].innerHTML = gamestate["class"];
|
||||
page_elements["lbl_xp"].innerHTML = gamestate["xp"];
|
||||
page_elements["lbl_xp_next"].innerHTML = gamestate["xp_next"];
|
||||
@@ -118,13 +118,25 @@ function dev_toolbox(open) {
|
||||
dev_toolbox_open = open;
|
||||
}
|
||||
|
||||
async function steal_resource(resource, amount, items) {
|
||||
function reward_xp(amount) {
|
||||
gamestate["xp"] += amount;
|
||||
if (gamestate["xp"] >= gamestate["xp_next"]) {
|
||||
old_xp_next = gamestate["xp_next"];
|
||||
gamestate["xp"] -= old_xp_next;
|
||||
gamestate["level"] += 1;
|
||||
gamestate["xp_next"] = (old_xp_next * 1.5) + (gamestate["level"] * 5);
|
||||
}
|
||||
}
|
||||
|
||||
async function steal_resource(resource, amount, itemstr) {
|
||||
var items = itemstr.split(",")
|
||||
var stealdata = await fetch("/act/steal/" + resource, {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(", "));
|
||||
}
|
||||
else { record_log("Didn't steal " + resource + " from a human"); }
|
||||
@@ -164,24 +176,25 @@ async function game_tick() {
|
||||
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 human. It is carrying these resources:\n\n"
|
||||
logstring += "<ol>\n"
|
||||
if (total_food > 0) {
|
||||
logstring += `<li><b>${total_food} food:</b> ${food_descs.join(", ")}</li>\n`;
|
||||
logstring += `<li><b>${total_food.toFixed(2)} food:</b> ${food_descs.join(", ")}</li>\n`;
|
||||
}
|
||||
if (total_shinies > 0) {
|
||||
logstring += `<li><b>${total_shinies} shinies:</b> ${shinies_descs.join(", ")}</li>\n`;
|
||||
logstring += `<li><b>${total_shinies.toFixed(2)} shinies:</b> ${shinies_descs.join(", ")}</li>\n`;
|
||||
}
|
||||
logstring += "</ol>\nWhat would you like to do?";
|
||||
|
||||
record_log_with_choices(logstring,
|
||||
"Steal food", `steal_resource('food', ${total_food}, ${JSON.stringify(food_descs)})`,
|
||||
"Steal shinies", `steal_resource('shinies', ${total_shinies}, ${JSON.stringify(shinies_descs)})`
|
||||
"Steal food", `steal_resource('food', ${total_food}, "${food_descs.toString()}")`,
|
||||
"Steal shinies", `steal_resource('shinies', ${total_shinies}, "${shinies_descs.toString()}")`
|
||||
)
|
||||
|
||||
break;
|
||||
@@ -190,14 +203,14 @@ async function game_tick() {
|
||||
total_food += item["amount"];
|
||||
food_descs.push(item["desc"]);
|
||||
})
|
||||
steal_resource("food", total_food, food_descs);
|
||||
steal_resource("food", total_food, food_descs.toString());
|
||||
break;
|
||||
case "steal-shinies":
|
||||
tickdata.items.shinies.forEach((item) => {
|
||||
total_shinies += item["amount"];
|
||||
shinies_descs.push(item["desc"]);
|
||||
})
|
||||
steal_resource("shinies", total_shinies, shinies_descs);
|
||||
steal_resource("shinies", total_shinies, shinies_descs.toString());
|
||||
break;
|
||||
default:
|
||||
console.error("undefined action " + page_elements["menu_enc_human"]);
|
||||
@@ -249,13 +262,15 @@ target.addEventListener(start_event, function (ev) {
|
||||
page_elements["menu_enc_human"] = document.querySelector("#menu-enc-human");
|
||||
page_elements["menu_enc_seagull"] = document.querySelector("#menu-enc-seagull");
|
||||
|
||||
prepare_gamestate().then(update_ui());
|
||||
prepare_gamestate();
|
||||
|
||||
record_log("seagull game ver. " + ver_string);
|
||||
|
||||
const interval = setInterval(() => {
|
||||
if (tick_meter_running) { game_tick(); }
|
||||
}, 1200);
|
||||
|
||||
update_ui();
|
||||
});
|
||||
|
||||
function change_seagull_name() {
|
||||
|
Reference in New Issue
Block a user