UNPKG

kraft

Version:

A mysterious command line game with lots of secrets

39 lines (25 loc) 1.44 kB
const Lenses = require(__base+'helpers/Lenses'); const Flow = require(__base+'helpers/Flow'); const Output = require(__base+'helpers/Output'); const Config = require(__base+'config/Config'); const Items = require(__base+'model/data/Items'); const Locations = require(__base+'model/data/Locations'); const P = require(__base+'model/player/PlayerModel'); const getCurrentMillis = () => new Date().getTime(); const sanitizeNumber = (input) => input ? input : 0; const updateGatheringForBuilding = (building) => { const resource = P.buildingActionArguments(P.location.view(), building).view(); const ticks = (getCurrentMillis() - P.buildingActionStart(P.location.view(), building).view()) / Config.resourceRate; const amount = Math.floor(sanitizeNumber(Locations[P.location.view()].resources[resource]) * ticks); // Add the resource to the building P.buildingResource(P.location.view(), building, resource).add(amount); // Restart the job P.buildingActionStart(P.location.view(), building).set(getCurrentMillis()); }; exports.checkCurrentGatherings = () => { const buildings = P.locationBuildings(P.location.view()).view() || []; const filtered = R.keys(buildings).filter((building) => P.buildingActionType(P.location.view(), building).view() === 'gathering'); filtered.forEach(updateGatheringForBuilding); // Save but show no output Output.saveWithoutOutput(Lenses.config()); };