summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authorJoël Simoneau <simoneaujoel@gmail.com>2025-03-19 07:38:08 -0400
committerJoël Simoneau <simoneaujoel@gmail.com>2025-03-19 07:38:08 -0400
commit6f42e218a3c603d96374159f8ca35c5121329f5f (patch)
tree1cab16b85524813475de273891736e42758434ac /rules.js
parent3bdc5569381c9de216a0ec1481266c433bf00df5 (diff)
downloadvijayanagara-6f42e218a3c603d96374159f8ca35c5121329f5f.tar.gz
Adding Ping
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js65
1 files changed, 64 insertions, 1 deletions
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) {