From 6f42e218a3c603d96374159f8ca35c5121329f5f Mon Sep 17 00:00:00 2001 From: Joël Simoneau Date: Wed, 19 Mar 2025 07:38:08 -0400 Subject: Adding Ping --- rules.js | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'rules.js') diff --git a/rules.js b/rules.js index 360284b..2117504 100644 --- a/rules.js +++ b/rules.js @@ -155,7 +155,8 @@ exports.view = function (state, role) { else view.prompt = "Unknown state: " + game.state - if (states[game.state] && !states[game.state].disable_negotiation) { + if (states[game.state]) + if (!states[game.state].disable_negotiation) { view.actions.ask_resources = 1 if (game.resources[game.current] > 0) view.actions.transfer_resources = 1 @@ -169,6 +170,13 @@ exports.view = function (state, role) { view.actions.ask_cavalry = 1 else view.actions.ask_cavalry = 0 + view.actions.ping = 1 + } else { + view.actions.ask_resources = 0 + view.actions.transfer_resources = 0 + view.actions.ask_cavalry = 0 + view.actions.transfer_cavalry = 0 + view.actions.ping = 1 } if (view.actions.undo === undefined) { @@ -200,6 +208,8 @@ exports.action = function (state, role, action, arg) { action_transfer_resources() else if (action === "transfer_cavalry") action_transfer_cavalry() + else if (action === "ping") + action_ping() else throw new Error("Invalid action: " + action) } @@ -3351,6 +3361,59 @@ function gen_choose_faction(faction) { } } +/* PING */ + +function action_ping() { + if (!game.ping) + game.ping = { save_current: game.current, save_state: game.state } + game.state = "ping" +} + +states.ping = { + disable_negotiation: true, + inactive: "Ping", + prompt() { + view.prompt = "Ping which faction to respond to chat?" + if (game.current !== DS) + view.actions.ds = 1 + if (game.current !== BK) + view.actions.bk = 1 + if (game.current !== VE) + view.actions.ve = 1 + view.actions.undo = 1 + }, + ds() { + game.current = DS + game.state = "pong" + }, + bk() { + game.current = BK + game.state = "pong" + }, + ve() { + game.current = VE + game.state = "pong" + }, + undo() { + states.pong.resume() + }, +} + +states.pong = { + disable_negotiation: true, + inactive: "Ping", + prompt() { + view.prompt = faction_name[game.ping.save_current] + " has requested your response in chat." + view.actions.resume = 1 + view.actions.undo = 0 + }, + resume() { + game.current = game.ping.save_current + game.state = game.ping.save_state + delete game.ping + }, +} + /* LOGGING */ function log(msg) { -- cgit v1.2.3