UNPKG

kraft

Version:

A mysterious command line game with lots of secrets

50 lines (28 loc) 3.8 kB
/** * Created by vanraar on 24/09/16. */ const Locations = require(__base+'model/data/locations'); const Buildings = require(__base+'model/data/Buildings'); const Items = require(__base+'model/data/Items'); const Config = require(__base+'config/Config'); const Lenses = require(__base+'helpers/Lenses'); const P = require(__base+'model/player/PlayerModel'); exports.isIdle = () => !P.actionType.equals("idle") ? Output.show('You are already busy', P.actionType.view().red, '(',P.actionArguments.view().red,')') : undefined; exports.isNotIdle = () => P.actionType.equals("idle") ? Output.show('You are not doing anything! Not really productive...') : undefined; exports.isExistingLocation = (location) => !Locations[location] ? Output.show('You cannot travel to', (location || "unknown" ).red , 'because it does not seem to exist.') : undefined; exports.isAlreadyAtLocation = (location) => P.location.equals(location) ? Output.show('You are already in', location.green) : undefined; exports.isGathering = () => !P.actionType.equals("gathering") && !P.actionType.equals("mining") ? Output.show('You silly, you aren\'t gathering. You are', P.actionType.view().red) : undefined; exports.hasBuildingHere = (building) => !P.building(P.location.view(), building).view() ? Output.show('You do not have a ', building.red, ' in ', P.location.view().red) : undefined; exports.hasBuildingsAt = (location) => !P.locationBuildings(location) ? Output.show('You do not have buildings at', P.location.view().red):undefined; exports.hasEnoughResources = (amount, resource) => P.resource(resource).view() < amount ? Output.show('You do not have ', amount.toString().red, ' of ', resource.red) : undefined; exports.buildingHasEnoughResources = (building, amount, resource) => P.buildingResource(P.location.view(), building, resource).view() < amount ? Output.show('Your ', building.red, ' does not have enough ', resource.red) : undefined; exports.isValidBuilding = (building) => !Buildings[building] ? Output.show('Unknown building,', (building || "").red) : undefined; exports.isAlreadyBuiltAtLocation = (location, building) => P.building(location, building).view() ? Output.show('You already have a ', building.red, ' at ', location.red) : undefined; exports.isNotBuiltAtLocation = (location, building) => !P.building(location, building).view() ? Output.show(building.red, ' is not built at ', location.red) : undefined; exports.hasEnoughResourcesToBuild = (building) => R.keys(Buildings[building].requires).forEach((resource) => exports.hasEnoughResources(Buildings[building].requires[resource], resource)); exports.isValidItem = (item) => !Items[item] ? Output.show('Unknown item'.red) : undefined; exports.itemCanBeMadeAtBuilding = (building, item) => Items[item].requires.building !== building ? Output.show('You can not make', item.red, 'at', building.red, '. You need a', Items[item].requires.building.red):undefined; exports.alreadyCraftingAtBuilding = (location, building) => P.buildingActionType(location, building).view() === 'job' ? Output.show('You are already crafting', P.buildingActionArguments(location, building).view().red, 'at this', building.red):undefined; exports.noJobRunningAtBuildingAtLocation = (location, building) => P.buildingActionType(location, building).view() !== 'job' ? Output.show('You are not crafting anything at your', building.red):undefined; exports.doesBuildingGenerateResource = (building, resource) => !Buildings[building] || !Buildings[building].generates[resource] ? Output.show(building.red, ' cannot generate ', resource.red):undefined; exports.buildingIsNotGatheringAtLocation = (location, building) => P.buildingActionType(location, building).view() !== 'gathering' ? Output.show('You are not gathering anything at your', building.red):undefined;