This repository has been archived on 2024-03-13. You can view files and clone it, but cannot push or open issues or pull requests.
timekeeper/store/index.js

272 lines
6.7 KiB
JavaScript
Raw Normal View History

import Decimal from 'break_infinity.js'
2022-01-07 22:28:21 +00:00
import Vue from 'vue'
2022-01-07 01:17:26 +00:00
export const state = () => ({
tabs: [
{
route: '/',
label: 'fas fa-clock',
title: 'Timekeeping Instruments',
2022-01-09 08:04:24 +00:00
darkColor: 'amber-900',
color: 'amber-400',
2022-01-09 08:04:24 +00:00
lightColor: 'amber-200',
locked: false,
2022-01-07 01:17:26 +00:00
},
{
route: '/apprentices',
label: 'fas fa-user-friends',
title: 'Apprentices',
2022-01-09 08:04:24 +00:00
darkColor: 'rose-900',
color: 'rose-400',
2022-01-09 08:04:24 +00:00
lightColor: 'rose-200',
locked: false,
2022-01-07 01:17:26 +00:00
},
{
route: '/missions',
label: 'fas fa-th-list',
2022-01-08 03:46:33 +00:00
title: 'Missions',
2022-01-09 08:04:24 +00:00
darkColor: 'sky-900',
color: 'sky-400',
2022-01-09 08:04:24 +00:00
lightColor: 'sky-200',
locked: false,
2022-01-07 01:17:26 +00:00
},
{
route: '/timemachine',
label: 'fas fa-fast-forward',
2022-01-08 03:46:33 +00:00
title: 'Time Machine',
2022-01-09 08:04:24 +00:00
darkColor: 'lime-900',
color: 'lime-400',
2022-01-07 01:17:26 +00:00
lightColor: 'lime-200',
locked: false,
2022-01-07 01:17:26 +00:00
},
{
route: '/timemagic',
label: 'fas fa-eye',
2022-01-08 03:46:33 +00:00
title: 'Time Magic',
2022-01-09 08:04:24 +00:00
darkColor: 'violet-900',
color: 'violet-400',
2022-01-09 08:04:24 +00:00
lightColor: 'violet-200',
locked: false,
2022-01-07 01:17:26 +00:00
},
{
route: '/wisdom',
label: 'fas fa-book-open',
title: 'Wisdom',
2022-01-09 08:04:24 +00:00
darkColor: 'teal-900',
color: 'teal-400',
2022-01-09 08:04:24 +00:00
lightColor: 'teal-100',
locked: false,
2022-01-07 01:17:26 +00:00
},
],
currency: new Decimal(0),
currencyTotal: new Decimal(0),
processes: [
{
instrument: 'Mechanical Clock',
worker: 'Engineer',
cost: 10,
created: false,
completion: 0, // how close it is to giving currency. 10 gained per second.
completionRequired: 10, // should be divisible by 10
baseReward: 5, // currency added when the bar is completed
workerLevel: 0, // 0 = not hired; 1+ = hired
nextWorkerCost: 25, // currency cost of next worker
nextWorkerFactor: 1.5, // worker cost *= this factor after each purchase
unlockThreshold: { tech: null, currency: 0 },
},
{
instrument: 'Hourglass',
worker: 'Glassblower',
cost: 100,
created: false,
2022-01-07 22:28:21 +00:00
completion: 0,
completionRequired: 20,
baseReward: 35,
workerLevel: 0,
nextWorkerCost: 200,
nextWorkerFactor: 1.6,
unlockThreshold: { tech: null, currency: 10000 },
},
{
instrument: 'Pocket Watch',
worker: 'Miniaturist',
cost: 1000,
created: false,
2022-01-07 22:28:21 +00:00
completion: 0,
completionRequired: 30,
baseReward: 80,
workerLevel: 0,
nextWorkerCost: 2000,
nextWorkerFactor: 1.8,
unlockThreshold: { tech: 0, currency: new Decimal(10e5) },
},
],
upgrades: [
{
name: 'Mathematics',
price: 100,
purchased: false,
},
],
2022-01-08 03:46:33 +00:00
missions: [
{
name: 'Create the Time Machine',
description: 'Soon you will be able to control time itself.',
completionCriteria: {
cost: 50000,
2022-01-08 03:46:33 +00:00
},
available: true,
viewed: false,
complete: false,
},
{
name: 'Time To Cheat Death',
description:
'Your body seems to be failing you. ' +
'Write a book to pass your knowedge to your younger self through the time machine. ' +
"Now where's your pen...",
appearanceCriteria: {
age: 100,
},
completionCriteria: {
cost: 150000,
},
2022-01-08 03:46:33 +00:00
available: true,
viewed: false,
complete: false,
},
],
gameDate: {
2022-01-09 23:34:50 +00:00
month: 12,
year: 1990,
},
playerAge: {
2022-01-09 23:34:50 +00:00
month: 0,
year: 34,
},
playerAgeMax: {
2022-01-09 23:34:50 +00:00
month: 0,
year: 80,
},
playerLivedTotal: {
2022-01-09 23:34:50 +00:00
month: 0,
year: 0,
},
wisdomGained: 0, // wisdom gained so far on this run, not applied until player sends the book.
wisdomApplied: 0, // wisdom from previous runs
totalLifetimes: 1,
2022-01-07 01:17:26 +00:00
})
export const getters = {
2022-01-10 03:28:09 +00:00
activeTab(state) {
return state.tabs.find(
// eslint-disable-next-line no-undef
(tab) => tab.route === $nuxt.$route.path
)
2022-01-07 01:17:26 +00:00
},
canTimeTravel: (state) => {
2022-01-09 23:34:50 +00:00
if (state.playerAge.year < state.playerAgeMax.year) return true
if (state.playerAge.year > state.playerAgeMax.year) return false
return state.playerAge.month < state.playerAgeMax.month
},
gameMonth: (state) => {
return {
1: 'Jan.',
2: 'Feb.',
3: 'Mar.',
4: 'Apr.',
5: 'May.',
6: 'Jun.',
7: 'Jul.',
8: 'Aug.',
9: 'Sep.',
10: 'Oct.',
11: 'Nov.',
12: 'Dec.',
}[state.gameDate.month]
},
currencySpent: (state) => {
return Decimal.subtract(state.currencyTotal, state.currency)
},
2022-01-07 01:17:26 +00:00
}
export const mutations = {
addCurrency: (state, value) => {
state.currency = Decimal.add(state.currency, value)
state.currencyTotal = Decimal.add(state.currencyTotal, value)
},
spendCurrency: (state, value) => {
value = Decimal.mul(value, -1)
state.currency = Decimal.add(state.currency, value)
},
createInstrument: (state, instrument) => {
const index = state.processes.findIndex((p) => p.instrument === instrument)
Vue.set(state.processes[index], 'created', true)
},
setProcessCompletion: (state, { index, value }) => {
Vue.set(state.processes[index], 'completion', value)
2022-01-07 22:28:21 +00:00
},
2022-01-08 03:46:33 +00:00
setMissionAvailable: (state, missionIndex) => {
Vue.set(state.missions[missionIndex], 'available', true)
},
setMissionViewed: (state, missionIndex) => {
Vue.set(state.missions[missionIndex], 'viewed', true)
},
completeMission: (state, missionIndex) => {
state.missions[missionIndex].complete = true
},
levelUpApprentice: (state, process) => {
if (process.nextWorkerCost > state.currency) {
return
}
const index = state.processes.findIndex((p) => p.worker === process.worker)
state.currency = Decimal.subtract(state.currency, process.nextWorkerCost)
Vue.set(state.processes[index], 'workerLevel', process.workerLevel + 1)
Vue.set(
state.processes[index],
'nextWorkerCost',
Math.floor(process.nextWorkerCost * process.nextWorkerFactor)
)
},
tickGameDate: (state) => {
let gameYear = state.gameDate.year
let gameMonth = state.gameDate.month + 1
// Intentional: Months are 1 through 12, ages are 0 through 11.
if (gameMonth > 12) {
2022-01-09 23:34:50 +00:00
gameMonth = 1
gameYear = gameYear + 1
}
let ageYear = state.playerAge.year
let ageMonth = state.playerAge.month + 1
let wisdomGained = 0
if (ageMonth >= 12) {
ageMonth = 0
2022-01-09 23:34:50 +00:00
ageYear = ageYear + 1
wisdomGained += 1
}
Vue.set(state.gameDate, 'year', gameYear)
Vue.set(state.gameDate, 'month', gameMonth)
Vue.set(state.playerAge, 'year', ageYear)
Vue.set(state.playerAge, 'month', ageMonth)
state.wisdomGained = state.wisdomGained + wisdomGained
},
travelGameDate: (state, { month, year }) => {
Vue.set(state.gameDate, 'month', month)
Vue.set(state.gameDate, 'year', year)
},
2022-01-07 01:17:26 +00:00
}