Skip to content

Instantly share code, notes, and snippets.

@zbee
Last active October 9, 2019 10:25
A monitor for A Dark Room (doublespeakgames/adarkroom)
// ==UserScript==
// @name Dark Monitor
// @namespace https://gist.github.com/Zbee/0df652f096b670ec13a6
// @version 0.3.6
// @description A monitor for A Dark Room (doublespeakgames/adarkroom)
// @author Zbee
// @match http://adarkroom.doublespeakgames.com/
// @grant none
// ==/UserScript==
//--------------------------------------------------------------------------------------------//
//Modules
//Stores
// @description Checks store levels
// @depends-on null
// @default on
// @added 2015-06-15
// @finished 2016-08-30
// @modified 2019-10-09
// @author zbee
//Advice
// @description Gives advice on keeping store levels steady
// @depends-on Stores
// @default on
// @added 2016-08-30
// @finished null
// @modified null
// @author zbee
//--------------------------------------------------------------------------------------------//
//Change Log
//0.3.6
//Accounts for the new total value of a store generation in the tooltip
//Minimize errors in TamperMonkey
//Utilize #notifications
//Support fur advice
//Support advice to remove assigned villagers
//0.3.5
//Basics for advice module
//0.3
//Changed over to object orientation
//Added stores to be tracked
//0.2
//Finalized stores to display
//0.1
//Initial monitor
//--------------------------------------------------------------------------------------------//
//Table of Contents
//(type) : (name) : (description) : (module, if any)
//DarkMonitor
//////Monitor
//////////array : allStores : all stores to be tracked : stores
//////////func : checkStores : background function for stores function : stores
//////////func : stores : checks change for each store : stores
//////Compute
//////////obj : storeModifiers : villager jobs and their affects on stores : advice
//////////func : modifierAmounts : check amounts of each villager job : advice
//////////func : advice : checks each store change and suggests ways to level them out : advice
//////Display
//////////func : setup : setups up for displaying date :
//////////obj : monitor : jQuery object of display div :
//////////func : advice : display advice from compute method container : advice
//////Controller
//////////func : stores : starts stores module : stores
//////////func : advice : starts advice module : advice
//////////func : start : starts modules based on options :
//--------------------------------------------------------------------------------------------//
var $ = window.jQuery;
$("#location_outside").click(function () { $("#monitor").show(); });
$("#location_room, #location_path").click(function () { $("#monitor").hide(); });
var DarkMonitor = DarkMonitor || {};
//--------------------------------------------------------------------------------------------//
DarkMonitor.Monitor = {
allStores: [
["bait", 0], ["coal", 0], ["cured-meat", 0], ["fur", 0], ["iron", 0], ["leather", 0],
["meat", 0], ["steel", 0], ["wood", 0], ["scales", 0], ["cloth", 0], ["teeth", 0]
],
checkStore: function(store) {
var income = 0;
store = "#row_" + store;
//Skip non-set stores
if ($(store).length === 0) return 0;
//Track source for each store
$(store + " .tooltip .row_val").each(function () {
if ($(this).hasClass("total")) {
income += parseInt($(this).html().split(" ")[0]);
}
});
//Set up to display sources
var incomeTxt = income > 0 ? "+" + income : income;
//???
var curText = $(store + " > .row_key").html().split(" ").length > 1 ?
$(store + " > .row_key").html().split(" ")[1] :
$(store + " > .row_key").html().split(" ")[0];
//Display the sources for the store
$(store + " > .row_key").html("(" + incomeTxt + ") " + curText);
return income;
},
stores: function () {
console.log("DM.Monitor.stores");
//Ask for an update on each store
DarkMonitor.Monitor.allStores.forEach(function(element, index) {
DarkMonitor.Monitor.allStores[index][1] = DarkMonitor.Monitor.checkStore(element[0]);
});
}
};
//--------------------------------------------------------------------------------------------//
DarkMonitor.Compute = {
storeModifiers: {
"wood": [
{"from": "gatherer", "change": 1, "rate": 10, "limit": 0, "amount": 0},
{"from": "builder", "change": 2, "rate": 10, "limit": 1, "amount": 0}
],
"meat": [
{"from": "hunter", "change": 0.5, "rate": 10, "limit": 0, "amount": 0}
],
"fur": [
{"from": "hunter", "change": 0.5, "rate": 10, "limit": 0, "amount": 0},
{"from": "tanner", "change": -5, "rate": 10, "limit": 0, "amount": 0}
]
},
modifierAmounts: function () {
},
advice: function () {
console.log("DM.Compute.advice");
var advice = {"notification": "", "monitor": ""};
DarkMonitor.Monitor.allStores.forEach(function(store) {
var storeQuantity = store[1];
store = store[0];
if (storeQuantity < 0) {
if (!(store in DarkMonitor.Compute.storeModifiers)) {
console.warn("DM.Compute.advice: " + store + " is NOT yet implemented");
return;
}
var modifier = DarkMonitor.Compute.storeModifiers[store];
modifier = modifier[Math.floor(Math.random() * modifier.length)];
var change = Math.abs(storeQuantity) / modifier.change;
var changeWord = "add";
if (change < 0) { changeWord = "remove"; }
change = Math.ceil(Math.abs(change));
advice.monitor = changeWord + " " + change + " " + modifier.from;
advice.notification = "you should " + advice.monitor + "s.";
}
});
return advice;
}
};
//--------------------------------------------------------------------------------------------//
DarkMonitor.Display = {
setup: function () {
console.log("DM.Display.setup");
$("body").prepend("<div id='monitor' style='float:left;display:none;opacity:0;'></div>");
},
monitor: $("#monitor"),
advice: function (advice) {
console.log("DM.Display.advice");
DarkMonitor.Display.monitor.append(advice.monitor);
$("#monitor").html(advice.monitor);
//Display notification if not shown last
if (advice.notification != $("#notifications .notification:first-of-type").text()) {
$("#notifications").prepend("<div class='notification'>" + advice.notification + "</div>");
}
}
};
//--------------------------------------------------------------------------------------------//
DarkMonitor.Controller = {
stores: function () {
console.log("DM.Controller.stores");
window.setInterval(function(){
DarkMonitor.Monitor.stores();
}, 500); //Half second
},
advice: function () {
console.log("DM.Controller.advice");
window.setInterval(function(){
var advice = DarkMonitor.Compute.advice();
DarkMonitor.Display.advice(advice);
}, 5000); //5 seconds
},
start: function (opts) {
console.log("DM.Controller.start");
DarkMonitor.Display.setup();
if (opts.stores === true) DarkMonitor.Controller.stores();
if (opts.advice === true) DarkMonitor.Controller.advice();
}
};
//--------------------------------------------------------------------------------------------//
DarkMonitor.Controller.start({
stores: true,
advice: true
});
@zbee
Copy link
Author

zbee commented Jun 15, 2015

Features:

  • Show income for different resources
  • Suggest ways to stabilize / optimize incomes
  • Grey out or in some way denote things that cannot be afforded

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment