New additions
Temp-change votes cancel each other out. More achievements. Better !buy layout. 2 new buyableItems. More advanced command flags. Centralize user and coin fetching for commands. Display hvacker's owned soul count. Rank leaderboard by prestige, then CPS. Start centralize some settings. Add: - Quack Store - Lore - Horror mode. - hidden payloads to messages. - Lightning strikes. - Cups game. - Emojis in non-dm !a calls. - Human-readable numbers. - Gamble-loss mockery. - Chaos. - Prestige emojis.
This commit is contained in:
parent
8577f6f272
commit
4e15721803
|
@ -6,8 +6,9 @@ const url = ''
|
|||
const headers = new Headers()
|
||||
headers.append('Authorization', 'Basic ' + base64.encode(config.honeywellKey + ':' + config.honeywellSecret))
|
||||
|
||||
fetch(url, {method:'GET',
|
||||
headers: headers,
|
||||
//credentials: 'user:passwd'
|
||||
fetch(url, {
|
||||
method: 'GET',
|
||||
headers: headers
|
||||
// credentials: 'user:passwd'
|
||||
}).then(response => response.json())
|
||||
.then(json => console.log(json));
|
||||
.then(json => console.log(json))
|
||||
|
|
|
@ -5,17 +5,17 @@ const fs = require('fs')
|
|||
const fileName = 'hvackerconfig.json'
|
||||
|
||||
const configPaths = [
|
||||
path.join('/secrets', fileName),
|
||||
path.join(homedir, '.add123', fileName)
|
||||
path.join('/secrets', fileName),
|
||||
path.join(homedir, '.add123', fileName)
|
||||
]
|
||||
|
||||
const getConfigData = () => {
|
||||
const configPath = configPaths.find(fs.existsSync)
|
||||
if (!configPath) {
|
||||
throw 'Could not find a config file!'
|
||||
}
|
||||
const config = fs.readFileSync(configPath, 'utf8')
|
||||
return JSON.parse(config)
|
||||
const configPath = configPaths.find(fs.existsSync)
|
||||
if (!configPath) {
|
||||
throw 'Could not find a config file!'
|
||||
}
|
||||
const config = fs.readFileSync(configPath, 'utf8')
|
||||
return JSON.parse(config)
|
||||
}
|
||||
|
||||
module.exports = getConfigData()
|
|
@ -1,12 +1,12 @@
|
|||
const routine = require('./routine')
|
||||
|
||||
const emptyBoard = [
|
||||
[' ', ' ', ' ', ' ', ' ', ' ', ' ',],
|
||||
[' ', ' ', ' ', ' ', ' ', ' ', ' ',],
|
||||
[' ', ' ', ' ', ' ', ' ', ' ', ' ',],
|
||||
[' ', ' ', ' ', ' ', ' ', ' ', ' ',],
|
||||
[' ', ' ', ' ', ' ', ' ', ' ', ' ',],
|
||||
[' ', ' ', ' ', ' ', ' ', ' ', ' ',]
|
||||
[' ', ' ', ' ', ' ', ' ', ' ', ' '],
|
||||
[' ', ' ', ' ', ' ', ' ', ' ', ' '],
|
||||
[' ', ' ', ' ', ' ', ' ', ' ', ' '],
|
||||
[' ', ' ', ' ', ' ', ' ', ' ', ' '],
|
||||
[' ', ' ', ' ', ' ', ' ', ' ', ' '],
|
||||
[' ', ' ', ' ', ' ', ' ', ' ', ' ']
|
||||
]
|
||||
|
||||
const textFromBoard = board => {
|
||||
|
@ -30,7 +30,7 @@ const checkRows = board => {
|
|||
|
||||
const checkColumns = board => {
|
||||
const colToText = i =>
|
||||
board[0][i] +
|
||||
board[0][i] +
|
||||
board[1][i] +
|
||||
board[2][i] +
|
||||
board[3][i] +
|
||||
|
@ -54,7 +54,7 @@ const checkDiagonals = board => {
|
|||
board[row][col] === board[row + 1][col + 1] &&
|
||||
board[row][col] === board[row + 2][col + 2] &&
|
||||
board[row][col] === board[row + 3][col + 3]
|
||||
){
|
||||
) {
|
||||
return board[row][col]
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ const checkDiagonals = board => {
|
|||
board[row][col] === board[row + 1][col - 1] &&
|
||||
board[row][col] === board[row + 2][col - 2] &&
|
||||
board[row][col] === board[row + 3][col - 3]
|
||||
){
|
||||
) {
|
||||
return board[row][col]
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ const placeAt = (i, board, char) => {
|
|||
}
|
||||
|
||||
const makeMove = (emoji, board) =>
|
||||
placeAt(numEmojis.indexOf(emoji), board, getTurn(board))
|
||||
placeAt(numEmojis.indexOf(emoji), board, getTurn(board))
|
||||
|
||||
routine.build({
|
||||
startTriggers: ['connect 4', 'c4'],
|
||||
|
|
|
@ -2,12 +2,12 @@ module.exports = {
|
|||
leaderBoardViewer: {
|
||||
name: 'Leaderboard-Viewer',
|
||||
description: 'Thank you for viewing the leaderboard!',
|
||||
emoji: 'trophy',
|
||||
emoji: 'trophy'
|
||||
},
|
||||
seeTheQuade: {
|
||||
name: 'See the Quade',
|
||||
description: 'Quade has appeared in your buyables',
|
||||
emoji: 'quade',
|
||||
emoji: 'quade'
|
||||
},
|
||||
greenCoin: {
|
||||
name: 'Lucky Green Coin',
|
||||
|
@ -46,7 +46,7 @@ module.exports = {
|
|||
emoji: 'mouse2'
|
||||
},
|
||||
weAllNeedHelp: {
|
||||
name: `View the '!coin' help`,
|
||||
name: 'View the \'!coin\' help',
|
||||
description: 'We all need a little help sometimes',
|
||||
emoji: 'grey_question'
|
||||
},
|
||||
|
@ -71,9 +71,19 @@ module.exports = {
|
|||
description: 'You absolutely know how to party.',
|
||||
emoji: 'sunglasses'
|
||||
},
|
||||
itsOverNineHundred: {
|
||||
name: 'Play the HVAC game 1000 times',
|
||||
description: 'It\'s over nine hundred and ninety-nine!',
|
||||
emoji: 'chart_with_upwards_trend'
|
||||
},
|
||||
youDisgustMe: {
|
||||
name: 'You disgust me',
|
||||
description: 'Like, wow.',
|
||||
emoji: 'nauseated_face'
|
||||
},
|
||||
bookWorm: {
|
||||
name: 'Take a peek at the lore',
|
||||
description: 'It\'t gotta be worth your time somehow.',
|
||||
emoji: 'books'
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const buyableItems = require('./buyableItems');
|
||||
const { commas, saveGame, setHighestCoins, addAchievement, getCoins, getUser, singleItemCps } = require('./utils');
|
||||
const buyableItems = require('./buyableItems')
|
||||
const { commas, saveGame, setHighestCoins, addAchievement, getUser, singleItemCps, chaosFilter } = require('./utils')
|
||||
const slack = require('../../slack')
|
||||
|
||||
const calculateCost = ({ itemName, user, quantity = 1 }) => {
|
||||
|
@ -29,37 +29,71 @@ const buildBlock = ({ user, itemName, cost, cps }) => ({
|
|||
type: 'section',
|
||||
text: {
|
||||
type: 'mrkdwn',
|
||||
text: `${itemName} :${buyableItems[itemName].emoji}:x${user.items[itemName] || 0} - 𝕳${commas(cost)} - ${commas(cps)} CPS\n_${buyableItems[itemName].description}_`
|
||||
text: `${itemName} :${buyableItems[itemName].emoji}:x${user.items[itemName] || 0} - H${commas(cost)} - ${commas(cps)} CPS\n_${buyableItems[itemName].description}_`
|
||||
},
|
||||
accessory: {
|
||||
type: 'button',
|
||||
text: {
|
||||
type: 'plain_text',
|
||||
text: 'Buy 1',
|
||||
text: '1',
|
||||
emoji: true
|
||||
},
|
||||
value: 'buy_' + itemName,
|
||||
action_id: 'buy_' + itemName
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
const buildBlock2 = ({ user, itemName, cost, cps }) => ({
|
||||
type: 'actions',
|
||||
elements: [
|
||||
{
|
||||
type: 'button',
|
||||
text: {
|
||||
type: 'plain_text',
|
||||
text: 'Buy 1',
|
||||
emoji: true
|
||||
},
|
||||
value: 'buy_' + itemName,
|
||||
action_id: 'buy_' + itemName
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
text: {
|
||||
type: 'plain_text',
|
||||
text: 'Buy 1',
|
||||
emoji: true
|
||||
},
|
||||
value: 'buy_' + itemName,
|
||||
action_id: 'buy_' + itemName
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
const buyText2 = (highestCoins, user) => {
|
||||
return ({
|
||||
text: buyableText(highestCoins, user),
|
||||
blocks: Object.entries(buyableItems)
|
||||
.filter(canView(highestCoins))
|
||||
.map(([itemName, item]) => {
|
||||
const cost = calculateCost({ itemName, user, quantity: 1 })
|
||||
const cps = Math.round(singleItemCps(user, itemName))
|
||||
return ({ user, itemName, cost, cps })
|
||||
}).map(buildBlock)
|
||||
.filter(canView(highestCoins))
|
||||
.map(([itemName, item]) => {
|
||||
const cost = calculateCost({ itemName, user, quantity: 1 })
|
||||
const cps = Math.round(singleItemCps(user, itemName))
|
||||
return ({ user, itemName, cost, cps })
|
||||
}).map(buildBlock)
|
||||
})
|
||||
}
|
||||
|
||||
const buyRoute = async ({ event, say, words }) => {
|
||||
const user = getUser(event.user)
|
||||
const maxQuantity = ({ itemName, user, currentCoins }) => {
|
||||
let quantity = 1
|
||||
while (calculateCost({ itemName, user, quantity: quantity + 1 }) <= currentCoins) {
|
||||
quantity++
|
||||
}
|
||||
return quantity
|
||||
}
|
||||
|
||||
const buyRoute = async ({ event, say, words, user }) => {
|
||||
const buying = words[1]
|
||||
setHighestCoins(event.user)
|
||||
|
||||
if (!buying) {
|
||||
const highestCoins = user.highestEver || user.coins || 1
|
||||
if (buyableItems.quade.baseCost < highestCoins * 100) {
|
||||
|
@ -75,14 +109,13 @@ const buyRoute = async ({ event, say, words }) => {
|
|||
return
|
||||
}
|
||||
|
||||
let quantity = 1
|
||||
const currentCoins = getCoins(event.user)
|
||||
let quantity
|
||||
const currentCoins = user.coins
|
||||
const max = maxQuantity({ itemName: buying, user, currentCoins })
|
||||
if (words[2] === 'max') {
|
||||
while (calculateCost({ itemName: buying, user, quantity: quantity + 1 }) <= currentCoins) {
|
||||
quantity++
|
||||
}
|
||||
quantity = max
|
||||
} else {
|
||||
quantity = parseInt(words[2] || '1')
|
||||
quantity = Math.round(chaosFilter(parseInt(words[2] || '1'), 0.2, user, max) || 1)
|
||||
}
|
||||
if (!quantity || quantity < 1) {
|
||||
await say('Quantity must be a positive integer')
|
||||
|
@ -97,15 +130,17 @@ const buyRoute = async ({ event, say, words }) => {
|
|||
user.coins -= realCost
|
||||
user.items[buying] = user.items[buying] || 0
|
||||
user.items[buying] += quantity
|
||||
console.log(buying, user.items.mouse)
|
||||
|
||||
if (buying === 'mouse' && user.items.mouse >= 100) {
|
||||
addAchievement(user, 'ratGod', say)
|
||||
}
|
||||
|
||||
if (quantity === 1) {
|
||||
await say(`You bought one :${buyable.emoji}:`)
|
||||
} else {
|
||||
await say(`You bought ${quantity} :${buyable.emoji}:`)
|
||||
}
|
||||
|
||||
saveGame()
|
||||
}
|
||||
|
||||
|
@ -114,11 +149,11 @@ const buyButton = async ({ body, ack, say, payload }) => {
|
|||
const buying = payload.action_id.substring(4)
|
||||
console.log(`buyButton ${buying} clicked`)
|
||||
const event = {
|
||||
user: body.user.id,
|
||||
user: body.user.id
|
||||
}
|
||||
const user = getUser(event.user)
|
||||
const words = ['', buying, '1']
|
||||
await buyRoute({ event, say, words })
|
||||
const words = ['', buying, body.actions[0].text]
|
||||
await buyRoute({ event, say, words, user })
|
||||
const highestCoins = user.highestEver || user.coins || 1
|
||||
await slack.app.client.chat.update({
|
||||
channel: body.channel.id,
|
||||
|
|
|
@ -71,4 +71,16 @@ module.exports = {
|
|||
emoji: 'question',
|
||||
description: 'The elusive creator of Hvacker takes a favorable look at your CPS.'
|
||||
},
|
||||
smallBusiness: {
|
||||
baseCost: 2_210_000_000_000_000,
|
||||
earning: 2_845_000_000,
|
||||
emoji: 'convenience_store',
|
||||
description: 'The place where the creator of Hvacker goes to work.'
|
||||
},
|
||||
bigBusiness: {
|
||||
baseCost: 26_210_000_000_000_000,
|
||||
earning: 23_650_000_000,
|
||||
emoji: 'office',
|
||||
description: 'The place where the smallBusiness goes to work.'
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,113 @@
|
|||
const { setHighestCoins, addAchievement, chaosFilter, commas, saveGame, getUser } = require('./utils')
|
||||
const slack = require('../../slack')
|
||||
|
||||
let loreCount = 0
|
||||
const l = (text, {correctReactions, correctResponse, incorrectResponse, jumpTo} = {}) => {
|
||||
loreCount += 1
|
||||
return {
|
||||
text,
|
||||
correctReactions,
|
||||
correctResponse,
|
||||
incorrectResponse,
|
||||
jumpTo
|
||||
}
|
||||
}
|
||||
|
||||
const lore = [
|
||||
l(`Allow me to tell you a story.`),
|
||||
l(`Once upon a time, there were two young ducks named Genevieve and Isaiah.`),
|
||||
l(`Isaiah was known mostly for being a big butthole whomst no one liked.`),
|
||||
l(`Genevieve was known for a singing voice that could peel the paint off your car.`),
|
||||
l(`Nevertheless, there's was a passionate love affair.`),
|
||||
l(`_Honking_`),
|
||||
l(`...`),
|
||||
l(`Hey you know, it's rather cold, don't you think? Could you start a fire for us?`, {
|
||||
correctReactions: ['fire'],
|
||||
correctResponse: `Thank you.`,
|
||||
incorrectResponse: `Well, you're looking in the right place, anyway.`,
|
||||
}),
|
||||
|
||||
l(`Anyway, together they laid nine eggs.`),
|
||||
l(`The first to hatch was Rick, who grew up into a fine bird with beautiful feathers.`),
|
||||
l(`The second was Claire, who grew into an even finer bird, glowing with Duckish beauty.`),
|
||||
l(`The third was Marf, who developed a severe addiction to Elmer's glue.`),
|
||||
l(`Bird four was Yoink, who considered Tupperware a hobby.`),
|
||||
l(`The fifth was Big Bob.`),
|
||||
l(`The sixth was Jess, who became the number one checkers player in the world.`),
|
||||
l(`The seventh was Small Bob.`),
|
||||
l(`The eighth was Maurice, who had quite a few words to say about the French, and was eventually elected president.`),
|
||||
l(`And the ninth...`),
|
||||
l(`Well, the ninth might actually amount to something.`),
|
||||
l(`https://i.imgur.com/eFreg7Y.gif\n`),
|
||||
]
|
||||
|
||||
slack.onReaction(async ({ event, say }) => {
|
||||
try {
|
||||
const user = getUser(event.user)
|
||||
const item = await slack.getMessage({ channel: event.item.channel, ts: event.item.ts })
|
||||
const message = item.messages[0].text
|
||||
const loreData = slack.decodeData('lore', message)
|
||||
if (!loreData || user.lore !== loreData.index || !loreData.correctReactions) {
|
||||
return
|
||||
}
|
||||
if (!loreData.correctReactions.includes(event.reaction)) {
|
||||
if (lore[user.lore].incorrectResponse) {
|
||||
await say(lore[user.lore].incorrectResponse + encodeLore(user.lore))
|
||||
}
|
||||
return
|
||||
}
|
||||
console.log(lore[user.lore])
|
||||
await say(lore[user.lore].correctResponse)
|
||||
user.lore += 1
|
||||
saveGame()
|
||||
} catch (e) {console.error(e)}
|
||||
})
|
||||
|
||||
const encodeLore = loreNumber => lore[loreNumber].text.startsWith(':') && lore[loreNumber].text.endsWith(':') ? '' :
|
||||
slack.encodeData('lore', {
|
||||
index: loreNumber,
|
||||
correctReactions: lore[loreNumber].correctReactions
|
||||
})
|
||||
|
||||
const loreMessage = (user, say) => {
|
||||
if (lore[user.lore]) {
|
||||
return lore[user.lore].text + encodeLore(user.lore)
|
||||
}
|
||||
addAchievement(user, 'bookWorm', say)
|
||||
return `Sorry. I'd love to tell you more, but I'm tired. Please check back later.`
|
||||
}
|
||||
|
||||
const loreRoute = async ({ say, words, user, isAdmin }) => {
|
||||
user.lore ??= 0
|
||||
if (!words[1]) {
|
||||
const message = loreMessage(user, say)
|
||||
await say(message)
|
||||
if (!lore[user.lore]?.correctReactions) {
|
||||
user.lore += 1
|
||||
}
|
||||
saveGame()
|
||||
console.log('Sent ' + user.name + ':\n' + message)
|
||||
return
|
||||
}
|
||||
if (words[1] === 'reset') {
|
||||
user.lore = 0
|
||||
saveGame()
|
||||
return say(`I have reset your place in the story.`)
|
||||
}
|
||||
if (isAdmin) {
|
||||
if (words[1] === 'all') {
|
||||
let loreMessage = ''
|
||||
for (let i = 0; i < user.lore; i++) {
|
||||
loreMessage += lore[i].text + (lore[i].correctResponse || '') + '\n'
|
||||
}
|
||||
return say(loreMessage)
|
||||
}
|
||||
const jumpTo = parseInt(words[1])
|
||||
if (!isNaN(jumpTo)) {
|
||||
user.lore = jumpTo
|
||||
saveGame()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = loreRoute
|
|
@ -1,111 +1,107 @@
|
|||
const { getUser, getCoins, commas, saveGame } = require('./utils');
|
||||
const quackStore = require('./quackstore');
|
||||
const { commas, saveGame, quackGradeMultiplier, prestigeMultiplier, makeBackup } = require('./utils')
|
||||
const { quackStore } = require('./quackstore')
|
||||
|
||||
const possiblePrestige = coins => {
|
||||
let p = 0
|
||||
while (tpcRec(p + 1) <= coins) {
|
||||
while (totalCostForPrestige(p + 1) <= coins) {
|
||||
p += 1
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
const totalCostForPrestige = prestigeLevel => {
|
||||
let cost = 0
|
||||
while (prestigeLevel) {
|
||||
cost += 1_000_000_000_000 * Math.pow(prestigeLevel, 3)
|
||||
prestigeLevel -= 1
|
||||
}
|
||||
return cost
|
||||
}
|
||||
|
||||
const tpcRecMemo = []
|
||||
const tpcRec = prestigeLevel => {
|
||||
const totalCostForPrestige = prestigeLevel => {
|
||||
if (prestigeLevel === 0) {
|
||||
return 0
|
||||
}
|
||||
return (tpcRecMemo[prestigeLevel]) || (tpcRecMemo[prestigeLevel] = 1_000_000_000_000 * Math.pow(prestigeLevel, 3) + tpcRec(prestigeLevel - 1))
|
||||
return (tpcRecMemo[prestigeLevel]) || (tpcRecMemo[prestigeLevel] = 1_000_000_000_000 * Math.pow(prestigeLevel, 3) + totalCostForPrestige(prestigeLevel - 1))
|
||||
}
|
||||
|
||||
// TODO
|
||||
const prestigeRoute = async ({ event, say, words }) => {
|
||||
const user = getUser(event.user)
|
||||
getCoins(event.user)
|
||||
const possible = possiblePrestige(user.coinsAllTime)
|
||||
const current = user.prestige ??= 0
|
||||
if (words[1] === 'me') {
|
||||
await say(
|
||||
'This will permanently remove all of your items, upgrades, and coins!\n\n' +
|
||||
const prestigeRoute = async ({ say, words, user }) => {
|
||||
const possible = possiblePrestige(user.coinsAllTime)
|
||||
const current = user.prestige ??= 0
|
||||
if (words[1] === 'me') {
|
||||
await say(
|
||||
'This will permanently remove all of your items, upgrades, and coins!\n\n' +
|
||||
'Say \'!!prestige me\' to confirm.'
|
||||
)
|
||||
} else {
|
||||
await say(
|
||||
`Current Prestige: ${commas(current)}\n\n` +
|
||||
`Quacks gained if you prestige now: ${commas(possible - current)}\n\n` +
|
||||
`HVAC until next quack: ${commas(Math.round(tpcRec(possible + 1) - user.coinsAllTime))}\n\n` +
|
||||
'Say \'!prestige me\' to start the prestige process.'
|
||||
)
|
||||
}
|
||||
}//, true, adminOnly)
|
||||
)
|
||||
} else {
|
||||
await say(
|
||||
`Current Prestige: ${commas(current)}\n\n` +
|
||||
`Quacks gained if you prestige now: ${commas(possible - current)}\n\n` +
|
||||
`HVAC until next quack: ${commas(totalCostForPrestige(possible + 1) - user.coinsAllTime)}\n\n` +
|
||||
'Say \'!prestige me\' to start the prestige process.' +
|
||||
`\n\nYour prestige is currently boosting your CPS by ${commas((prestigeMultiplier(user) - 1) * 100)}%`
|
||||
)
|
||||
}
|
||||
}//, true, adminOnly)
|
||||
|
||||
// TODO
|
||||
const prestigeConfirmRoute = async ({ event, say, words }) => {
|
||||
const user = getUser(event.user)
|
||||
getCoins(event.user)
|
||||
const possible = possiblePrestige(user.coinsAllTime)
|
||||
const current = user.prestige
|
||||
if (possible <= current) {
|
||||
await say('You don\'t have enough HVAC to prestige right now!')
|
||||
return
|
||||
}
|
||||
if (event?.text !== '!!prestige me') {
|
||||
await say('Say exactly \'!!prestige me\' to confirm')
|
||||
return
|
||||
}
|
||||
console.log('possible', possible)
|
||||
console.log('user.prestige', user.prestige)
|
||||
user.quacks ??= 0
|
||||
user.quacks += (possible - user.prestige)
|
||||
console.log('user.quacks', user.quacks)
|
||||
user.prestige = possible
|
||||
user.coins = 0
|
||||
user.items = {}
|
||||
user.upgrades = {}
|
||||
saveGame()
|
||||
await say('You prestiged! Check out !quackstore to see what you can buy!')
|
||||
}
|
||||
const prestigeConfirmRoute = async ({ event, say, user }) => {
|
||||
const possible = possiblePrestige(user.coinsAllTime)
|
||||
const current = user.prestige
|
||||
if (possible <= current) {
|
||||
await say('You don\'t have enough HVAC to prestige right now!')
|
||||
return
|
||||
}
|
||||
if (event?.text !== '!!prestige me') {
|
||||
await say('Say exactly \'!!prestige me\' to confirm')
|
||||
return
|
||||
}
|
||||
await makeBackup()
|
||||
|
||||
const quackStoreListing = ([name, upgrade]) =>
|
||||
`:${upgrade.emoji}: *${name}* - Costs *${upgrade.cost} Quack.*\n\n_${upgrade.description}_`
|
||||
user.quacks ??= 0
|
||||
user.quacks += (possible - user.prestige)
|
||||
|
||||
user.prestige = possible
|
||||
user.coins = 0
|
||||
user.items = {}
|
||||
user.upgrades = {}
|
||||
|
||||
saveGame()
|
||||
await say('You prestiged! Check out !quackstore to see what you can buy!')
|
||||
}
|
||||
|
||||
const quackStoreListing = (showCost = true) => ([name, upgrade]) =>
|
||||
showCost
|
||||
? `:${upgrade.emoji}: *${name}* - Costs *${upgrade.cost} Quack.*\n\n_${upgrade.description}_`
|
||||
: `:${upgrade.emoji}: *${name}* - Worth *${upgrade.cost} Quack.*\n\n_${upgrade.description}_`
|
||||
|
||||
const allUserQuackUpgrades = user =>
|
||||
Object.entries(user.quackUpgrades || {})
|
||||
.map(([type, upgrades]) => upgrades)
|
||||
Object.entries(user.quackUpgrades || {})
|
||||
.map(([type, upgrades]) => upgrades).flatMap(x => x)
|
||||
|
||||
const hasPreReqs = user => ([name, upgrade]) => {
|
||||
if (!upgrade.preReqs) {
|
||||
return true
|
||||
}
|
||||
const allUserUpgrades = allUserQuackUpgrades(user)
|
||||
console.log(allUserUpgrades)
|
||||
return upgrade.preReqs.every(preReq => allUserUpgrades.includes(preReq))
|
||||
}
|
||||
|
||||
const quackStoreText = user =>
|
||||
Object.entries(quackStore)
|
||||
.filter(hasPreReqs(user))
|
||||
.map(quackStoreListing)
|
||||
.join('\n\n')
|
||||
const owns = (user, [name, upgrade]) => allUserQuackUpgrades(user).includes(name)
|
||||
|
||||
const quackStoreRoute = async ({ event, say, words }) => {
|
||||
const user = getUser(event.user)
|
||||
const ownedQuackItems = user => Object.entries(quackStore).filter(upgrade => owns(user, upgrade))
|
||||
|
||||
const unownedQuackItems = user => Object.entries(quackStore).filter(upgrade => !owns(user, upgrade))
|
||||
|
||||
const quackStoreText = user =>
|
||||
unownedQuackItems(user)
|
||||
.filter(hasPreReqs(user))
|
||||
.map(quackStoreListing(true))
|
||||
.join('\n\n') +
|
||||
`\n\nYou have ${user.quacks ??= 0} quacks to spend.` +
|
||||
`\nQuackStore upgrades are currently boosting your CPS by ${commas((quackGradeMultiplier(user) - 1) * 100)}%`
|
||||
|
||||
const quackStoreRoute = async ({ user, say, words }) => {
|
||||
user.quackUpgrades ??= {}
|
||||
const quacks = user.quacks ??= 0
|
||||
if (!words[1]) {
|
||||
await say(quackStoreText(user))
|
||||
return
|
||||
}
|
||||
console.log(`Trying to buy ${words[1]}`)
|
||||
const quackItem = quackStore[words[1]]
|
||||
if (!quackItem) {
|
||||
if (!quackItem || !unownedQuackItems(user).find(([name]) => name === words[1])) {
|
||||
await say(`'${words[1]}' is not available in the quack store!`)
|
||||
return
|
||||
}
|
||||
|
@ -113,13 +109,28 @@ const quackStoreRoute = async ({ event, say, words }) => {
|
|||
await say(`${words[1]} costs ${quackItem.cost} Quacks, but you only have ${quacks}!`)
|
||||
return
|
||||
}
|
||||
user.quacks -= quackItem.cost
|
||||
user.quackUpgrades[quackItem.type] ??= []
|
||||
user.quackUpgrades[quackItem.type].push(words[1])
|
||||
saveGame()
|
||||
}
|
||||
|
||||
const ownedQuacksText = user =>
|
||||
ownedQuackItems(user)
|
||||
.filter(hasPreReqs(user))
|
||||
.map(quackStoreListing(false))
|
||||
.join('\n\n') +
|
||||
`\n\nQuackStore upgrades are currently boosting your CPS by ${commas((quackGradeMultiplier(user) - 1) * 100)}%`
|
||||
|
||||
const ownedQuacksRoute = async ({ say, user }) => {
|
||||
user.quackUpgrades ??= {}
|
||||
user.quacks ??= 0
|
||||
await say(ownedQuacksText(user))
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
quackStoreRoute,
|
||||
prestigeRoute,
|
||||
prestigeConfirmRoute
|
||||
prestigeConfirmRoute,
|
||||
ownedQuacksRoute
|
||||
}
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
const getRandomFromArray = array => array[Math.floor(Math.random() * array.length)]
|
||||
|
||||
const chaosCpsMods = [3, 2, 0.1, 1, 1.5, 1.6, 0, 1.1, 1.1, 1.26]
|
||||
const chaosAvg = () => chaosCpsMods.reduce((total, next) => total + next, 0) / chaosCpsMods.length
|
||||
//const getChaos = offset => chaosCpsMods[(Math.floor(new Date().getSeconds() / chaosCpsMods.length) + offset) % chaosCpsMods.length]
|
||||
const getChaos = offset => chaosCpsMods[(Math.floor(new Date().getSeconds() / chaosCpsMods.length)) % chaosCpsMods.length]
|
||||
|
||||
const quackStore = {
|
||||
ascent: {
|
||||
name: 'Ascent',
|
||||
|
@ -16,5 +23,24 @@ const quackStore = {
|
|||
effect: cps => cps * 1.2,
|
||||
cost: 5
|
||||
},
|
||||
chaos: {
|
||||
name: 'Chaos',
|
||||
type: 'cps',
|
||||
emoji: 'eye',
|
||||
description: 'Awaken. Gives a random modifier to your CPS every six seconds. May have other consequences...',
|
||||
//+ '_\n_Averages a 26% CPS boost.',
|
||||
preReqs: ['nuclearFuel'],
|
||||
effect: (cps, user) => {
|
||||
if (user.name !== 'Sage') {
|
||||
console.log('Chaos Multiplier', getChaos(Math.round(user.interactions / 50)))
|
||||
}
|
||||
return cps * getChaos(Math.round(user.interactions / 50))
|
||||
},
|
||||
cost: 10
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
quackStore,
|
||||
getChaos: user => getChaos(user.interactions || 0)
|
||||
}
|
||||
module.exports = quackStore
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
horrorEnabled: false
|
||||
}
|
|
@ -11,191 +11,209 @@ module.exports = {
|
|||
type: 'mouse',
|
||||
description: 'Doubles the power of mice',
|
||||
count: 1,
|
||||
cost: 1_000,
|
||||
cost: 1_000
|
||||
}),
|
||||
stinkierCheese: basic({
|
||||
type: 'mouse',
|
||||
description: 'Mice are doubly motivated to hunt down HVAC Coins',
|
||||
count: 10,
|
||||
cost: 21_000,
|
||||
count: 10,
|
||||
cost: 21_000
|
||||
}),
|
||||
biggerTeeth: basic({
|
||||
type: 'mouse',
|
||||
description: 'Mice can intimidate twice as much HVAC out of their victims.',
|
||||
count: 25,
|
||||
cost: 50_000,
|
||||
count: 25,
|
||||
cost: 50_000
|
||||
}),
|
||||
|
||||
fasterComputers: basic({
|
||||
type: 'accountant',
|
||||
description: 'Accountants can ~steal~ optimize twice as much HVAC!',
|
||||
count: 1,
|
||||
cost: 11_000,
|
||||
cost: 11_000
|
||||
}),
|
||||
lackOfMorality: basic({
|
||||
type: 'accountant',
|
||||
description: 'Accountants are taking a hint from nearby CEOs.',
|
||||
count: 10,
|
||||
cost: 200_000,
|
||||
count: 10,
|
||||
cost: 200_000
|
||||
}),
|
||||
widerBrains: basic({
|
||||
type: 'accountant',
|
||||
description: 'For accountant do double of thinking.',
|
||||
count: 25,
|
||||
cost: 550_000,
|
||||
count: 25,
|
||||
cost: 550_000
|
||||
}),
|
||||
|
||||
biggerBlowhole: basic({
|
||||
type: 'whale',
|
||||
description: 'With all that extra air, whales have double power!',
|
||||
count: 1,
|
||||
cost: 120_000,
|
||||
cost: 120_000
|
||||
}),
|
||||
sassyWhales: basic({
|
||||
type: 'whale',
|
||||
description: 'These are the kind of whales that know how to get twice as much done',
|
||||
count: 10,
|
||||
cost: 3_000_000,
|
||||
count: 10,
|
||||
cost: 3_000_000
|
||||
}),
|
||||
thinnerWater: basic({
|
||||
type: 'whale',
|
||||
description: 'Whales can move twice as quickly through this physics-defying liquid',
|
||||
count: 25,
|
||||
cost: 6_000_000,
|
||||
count: 25,
|
||||
cost: 6_000_000
|
||||
}),
|
||||
|
||||
greasyTracks: basic({
|
||||
type: 'train',
|
||||
description: 'Lets trains deliver HVAC twice as efficiently',
|
||||
count: 1,
|
||||
cost: 1_300_000,
|
||||
cost: 1_300_000
|
||||
}),
|
||||
rocketThrusters: basic({
|
||||
type: 'train',
|
||||
description: 'That\'ll put some quack on your track',
|
||||
count: 10,
|
||||
cost: 22_000_000,
|
||||
count: 10,
|
||||
cost: 22_000_000
|
||||
}),
|
||||
loudConductors: basic({
|
||||
type: 'train',
|
||||
description: 'Conductors can onboard twice as much HVAC',
|
||||
count: 25,
|
||||
cost: 65_000_000,
|
||||
count: 25,
|
||||
cost: 65_000_000
|
||||
}),
|
||||
|
||||
gasolineFire: basic({
|
||||
type: 'fire',
|
||||
description: 'Extremely good for breathing in.',
|
||||
count: 1,
|
||||
cost: 14_000_000,
|
||||
cost: 14_000_000
|
||||
}),
|
||||
extremelyDryFuel: basic({
|
||||
type: 'fire',
|
||||
description: 'Use the ignite command for a secret achievement.',
|
||||
count: 10,
|
||||
cost: 163_000_000,
|
||||
cost: 163_000_000
|
||||
}),
|
||||
cavemanFire: basic({
|
||||
type: 'fire',
|
||||
description: 'They just don\'t make \'em like they used to.',
|
||||
count: 25,
|
||||
cost: 700_000_000,
|
||||
count: 25,
|
||||
cost: 700_000_000
|
||||
}),
|
||||
|
||||
spoonerang: basic({
|
||||
type: 'boomerang',
|
||||
description: 'Scoops up HVAC mid-flight',
|
||||
count: 1,
|
||||
cost: 200_000_000,
|
||||
cost: 200_000_000
|
||||
}),
|
||||
boomerAng: basic({
|
||||
type: 'boomerang',
|
||||
description: 'It\'s... old.',
|
||||
count: 10,
|
||||
cost: 1_200_000_000,
|
||||
cost: 1_200_000_000
|
||||
}),
|
||||
doubleRang: basic({
|
||||
type: 'boomerang',
|
||||
description: 'You throw one, but somehow catch two',
|
||||
count: 25,
|
||||
cost: 10_000_000_000,
|
||||
count: 25,
|
||||
cost: 10_000_000_000
|
||||
}),
|
||||
|
||||
lunarPower: basic({
|
||||
type: 'moon',
|
||||
description: 'Out with the sol, in with the lun!',
|
||||
count: 1,
|
||||
cost: 3_300_000_000,
|
||||
cost: 3_300_000_000
|
||||
}),
|
||||
womanOnTheMoon: basic({
|
||||
type: 'moon',
|
||||
description: 'There\'s no reason for it not to be a woman!',
|
||||
count: 10,
|
||||
cost: 39_700_000_000,
|
||||
cost: 39_700_000_000
|
||||
}),
|
||||
doubleCraters: basic({
|
||||
type: 'moon',
|
||||
description: 'Making every side look like the dark side.',
|
||||
count: 25,
|
||||
cost: 165_000_000_000,
|
||||
count: 25,
|
||||
cost: 165_000_000_000
|
||||
}),
|
||||
|
||||
glassButterfly: basic({
|
||||
type: 'butterfly',
|
||||
description: 'Not your grandma\'s universe manipulation.',
|
||||
count: 1,
|
||||
cost: 51_000_000_000,
|
||||
cost: 51_000_000_000
|
||||
}),
|
||||
monarchMigration: basic({
|
||||
type: 'butterfly',
|
||||
description: 'This upgrade brought to you by milkweed.',
|
||||
count: 10,
|
||||
cost: 870_000_000_000,
|
||||
cost: 870_000_000_000
|
||||
}),
|
||||
quadWing: basic({
|
||||
type: 'butterfly',
|
||||
description: 'Sounds a lot like a trillion bees buzzing inside your head.',
|
||||
count: 25,
|
||||
cost: 2_550_000_000_000,
|
||||
count: 25,
|
||||
cost: 2_550_000_000_000
|
||||
}),
|
||||
|
||||
silverMirror: basic({
|
||||
type: 'mirror',
|
||||
description: 'Excellent for stabbing vampires.',
|
||||
count: 1,
|
||||
cost: 750_000_000_000,
|
||||
cost: 750_000_000_000
|
||||
}),
|
||||
pocketMirror: basic({
|
||||
type: 'mirror',
|
||||
description: 'Take your self-reflection on the go!',
|
||||
count: 10,
|
||||
cost: 18_000_000_000_000
|
||||
}),
|
||||
window: basic({
|
||||
type: 'mirror',
|
||||
description: 'Only through looking around you can you acquire the self reflection necessary to control the thermostat.',
|
||||
count: 25,
|
||||
cost: 37_500_000_000_000,
|
||||
count: 25,
|
||||
cost: 37_500_000_000_000
|
||||
}),
|
||||
|
||||
fzero: basic({
|
||||
type: 'quade',
|
||||
description: 'Brings out his competitive spirit.',
|
||||
count: 1,
|
||||
cost: 10_000_000_000_000,
|
||||
cost: 10_000_000_000_000
|
||||
}),
|
||||
triHumpCamel: basic({
|
||||
type: 'quade',
|
||||
description: 'YEE HAW :trimedary_camel:',
|
||||
count: 10,
|
||||
cost: 200_000_000_000_000
|
||||
}),
|
||||
adam: basic({
|
||||
type: 'quade',
|
||||
description: 'He could probably reach the thermostat if he wanted.',
|
||||
count: 25,
|
||||
cost: 500_000_000_000_000,
|
||||
count: 25,
|
||||
cost: 500_000_000_000_000
|
||||
}),
|
||||
|
||||
latestNode: basic({
|
||||
type: 'hvacker',
|
||||
description: 'The old one has terrible ergonomics, tsk tsk.',
|
||||
count: 1,
|
||||
cost: 140_000_000_000_000,
|
||||
count: 1,
|
||||
cost: 140_000_000_000_000
|
||||
}),
|
||||
nativeFunctions: basic({
|
||||
type: 'hvacker',
|
||||
description: 'Sometimes javascript just isn\'t fast enough.',
|
||||
count: 10,
|
||||
cost: 3_300_000_000_000_000
|
||||
}),
|
||||
gitCommits: basic({
|
||||
type: 'hvacker',
|
||||
description: 'The heads of multiple people in a company are better than, for example, merely one head.',
|
||||
count: 25,
|
||||
cost: 7_000_000_000_000_000,
|
||||
count: 25,
|
||||
cost: 7_000_000_000_000_000
|
||||
}),
|
||||
|
||||
homage: {
|
||||
|
@ -204,7 +222,7 @@ module.exports = {
|
|||
condition: user => Object.entries(user.items).reduce((total, [, countOwned]) => countOwned + total, 0) >= 200,
|
||||
emoji: 'cookie',
|
||||
cost: 10_000_000_000,
|
||||
effect: (itemCps, user) => Math.ceil(itemCps * 1.1)
|
||||
effect: (itemCps, user) => itemCps * 1.1
|
||||
},
|
||||
iLoveHvac: {
|
||||
type: 'general',
|
||||
|
@ -212,7 +230,7 @@ module.exports = {
|
|||
condition: user => Object.entries(user.items).reduce((total, [, countOwned]) => countOwned + total, 0) >= 400,
|
||||
emoji: 'heart',
|
||||
cost: 100_000_000_000_000,
|
||||
effect: (itemCps, user) => Math.ceil(itemCps * 1.1)
|
||||
effect: (itemCps, user) => itemCps * 1.1
|
||||
}
|
||||
|
||||
// moreUpgrades: {
|
||||
|
@ -224,4 +242,3 @@ module.exports = {
|
|||
// effect: nothing
|
||||
// },
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +1,38 @@
|
|||
const fs = require('fs')
|
||||
const jokes = require('../jokes')
|
||||
const achievements = require('./achievements');
|
||||
const buyableItems = require("./buyableItems");
|
||||
const upgrades = require("./upgrades");
|
||||
const quackStore = require("./quackstore");
|
||||
//const jokes = require('../jokes')
|
||||
const achievements = require('./achievements')
|
||||
const buyableItems = require('./buyableItems')
|
||||
const upgrades = require('./upgrades')
|
||||
const { quackStore, getChaos } = require('./quackstore')
|
||||
|
||||
const saveFile = 'hvacoins.json'
|
||||
|
||||
const logError = msg => msg ? console.error(msg) : () => { /* Don't log empty message */ }
|
||||
|
||||
const loadGame = () => parseOr(fs.readFileSync('./' + saveFile, 'utf-8'),
|
||||
() => ({
|
||||
users: {},
|
||||
nfts: [],
|
||||
squad: {}
|
||||
}))
|
||||
const loadGame = () => {
|
||||
const game = parseOr(fs.readFileSync('./' + saveFile, 'utf-8'),
|
||||
() => ({
|
||||
users: {},
|
||||
nfts: [],
|
||||
squad: {},
|
||||
horrors: {}
|
||||
}))
|
||||
game.horrors ??= {}
|
||||
return game
|
||||
}
|
||||
|
||||
const chaosFilter = (num, odds, user, max = Infinity) => {
|
||||
const userQuackgrades = user.quackUpgrades?.cps || []
|
||||
const hasChaos = userQuackgrades.includes('chaos')
|
||||
if (!hasChaos || Math.random() < odds) {
|
||||
return num
|
||||
}
|
||||
const chaosed = num * getChaos(user)
|
||||
if (chaosed > max) {
|
||||
return max
|
||||
}
|
||||
return chaosed
|
||||
}
|
||||
|
||||
const parseOr = (parseable, orFunc) => {
|
||||
try {
|
||||
|
@ -25,10 +43,16 @@ const parseOr = (parseable, orFunc) => {
|
|||
}
|
||||
}
|
||||
|
||||
const makeBackup = () => {
|
||||
const fileName = './backups/' + saveFile + new Date().toLocaleString().replace(/[^a-z0-9]/gi, '_')
|
||||
console.log(`Making backup file: ${fileName}`)
|
||||
fs.writeFileSync(fileName, JSON.stringify(game))
|
||||
}
|
||||
|
||||
let saves = 0
|
||||
const saveGame = () => {
|
||||
if (saves % 100 === 0) {
|
||||
fs.writeFileSync('./backups/' + saveFile + new Date().toLocaleString().replace(/[^a-z0-9]/gi, '_'), JSON.stringify(game))
|
||||
makeBackup()
|
||||
}
|
||||
saves += 1
|
||||
fs.writeFileSync('./' + saveFile, JSON.stringify(game, null, 2))
|
||||
|
@ -54,7 +78,82 @@ const idFromWord = word => {
|
|||
|
||||
const getSeconds = () => new Date().getTime() / 1000
|
||||
|
||||
const commas = num => num.toLocaleString()
|
||||
const bigNumberWords = [
|
||||
['tredecillion', 1_000_000_000_000_000_000_000_000_000_000_000_000_000_000],
|
||||
['duodecillion', 1_000_000_000_000_000_000_000_000_000_000_000_000_000],
|
||||
['undecillion', 1_000_000_000_000_000_000_000_000_000_000_000_000],
|
||||
['decillion', 1_000_000_000_000_000_000_000_000_000_000_000],
|
||||
['nonillion', 1_000_000_000_000_000_000_000_000_000_000],
|
||||
['octillion', 1_000_000_000_000_000_000_000_000_000],
|
||||
['septtillion', 1_000_000_000_000_000_000_000_000],
|
||||
['sextillion', 1_000_000_000_000_000_000_000],
|
||||
['quintillion', 1_000_000_000_000_000_000],
|
||||
['quadrillion', 1_000_000_000_000_000],
|
||||
['trillion', 1_000_000_000_000],
|
||||
['billion', 1_000_000_000],
|
||||
['million', 1_000_000],
|
||||
]
|
||||
|
||||
const commas = (num, precise = false) => {
|
||||
num = Math.round(num)
|
||||
const bigNum = bigNumberWords.find(([, base]) => num >= base)
|
||||
if (bigNum && !precise) {
|
||||
const [name, base] = bigNum
|
||||
const nummed = (num / base).toPrecision(3)
|
||||
return `${nummed} ${name}`
|
||||
}
|
||||
return num.toLocaleString()
|
||||
}
|
||||
|
||||
const parseAll = (str, allNum) => {
|
||||
if (!str) {
|
||||
return NaN
|
||||
}
|
||||
|
||||
str = str.toLowerCase()?.replace(/,/g, '')
|
||||
|
||||
if (str === 'all') {
|
||||
return allNum
|
||||
}
|
||||
|
||||
switch (str) {
|
||||
case 'my soul':
|
||||
return allNum
|
||||
case 'sex':
|
||||
case 'sex number':
|
||||
return 69_000_000
|
||||
case ':maple_leaf:':
|
||||
case ':herb:':
|
||||
case 'weed':
|
||||
case 'weed number':
|
||||
return 420_000_000
|
||||
case 'a milli':
|
||||
return 1_000_000
|
||||
case 'a band':
|
||||
return 1000
|
||||
case ':100:':
|
||||
case 'one hunna':
|
||||
return 100
|
||||
}
|
||||
|
||||
console.log('STR', str)
|
||||
if (str.match(/^\d+$/)) {
|
||||
console.log('parseInt()')
|
||||
return parseInt(str)
|
||||
}
|
||||
|
||||
if (str.match(/^\d+\.\d+$/)) {
|
||||
console.log('parseFloat()')
|
||||
return Math.round(parseFloat(str))
|
||||
}
|
||||
|
||||
const bigNum = bigNumberWords.find(([name]) => str.endsWith(name))
|
||||
if (bigNum && str.match(/^\d+(\.\d+)?/)) {
|
||||
return Math.round(parseFloat(str) * bigNum[1])
|
||||
}
|
||||
|
||||
return NaN
|
||||
}
|
||||
|
||||
const game = loadGame()
|
||||
const { users, nfts, squad } = game
|
||||
|
@ -107,7 +206,7 @@ const getCoins = userId => {
|
|||
const lastCheck = user.lastCheck || currentTime
|
||||
const secondsPassed = currentTime - lastCheck
|
||||
|
||||
const increase = getCPS(userId) * secondsPassed
|
||||
const increase = getCPS(user) * secondsPassed
|
||||
user.coins += increase
|
||||
user.coinsAllTime += increase
|
||||
user.coins = Math.floor(user.coins)
|
||||
|
@ -118,8 +217,7 @@ const getCoins = userId => {
|
|||
return user.coins
|
||||
}
|
||||
|
||||
const getCPS = userId => {
|
||||
const user = getUser(userId)
|
||||
const getCPS = user => {
|
||||
const userItems = user?.items || {}
|
||||
return Math.round(Object.keys(userItems).reduce((total, itemName) => total + getItemCps(user, itemName), 0))
|
||||
}
|
||||
|
@ -130,14 +228,14 @@ const squadUpgrades = {
|
|||
tastyKeyboards: {
|
||||
name: 'Tasty Keyboards',
|
||||
description: 'Delicious and sticky. Boosts CPS by 20% for everyone.',
|
||||
effect: cps => Math.ceil(cps * 1.2),
|
||||
effect: cps => cps * 1.2,
|
||||
cost: 10_000_000_000_000,
|
||||
emoji: 'keyboard'
|
||||
},
|
||||
copyPasteMacro: {
|
||||
name: 'Copy-Paste Macro.',
|
||||
description: 'Don\'t actually use this. Boosts CPS by 20% for everyone.',
|
||||
effect: cps => Math.ceil(cps * 1.2),
|
||||
effect: cps => cps * 1.2,
|
||||
cost: 100_000_000_000_000,
|
||||
emoji: 'printer'
|
||||
}
|
||||
|
@ -147,35 +245,122 @@ const squadHas = ([name]) => squad.upgrades[name] === true
|
|||
const squadIsMissing = name => !squadHas(name)
|
||||
|
||||
const getCompletedSquadgrades = () =>
|
||||
Object.entries(squadUpgrades)
|
||||
.filter(squadHas)
|
||||
.map(([, upgrade]) => upgrade)
|
||||
Object.entries(squadUpgrades)
|
||||
.filter(squadHas)
|
||||
.map(([, upgrade]) => upgrade)
|
||||
|
||||
const prestigeMultiplier = user => 1 + ((user.prestige || 0) * 0.01)
|
||||
|
||||
const quackGradeMultiplier = user => {
|
||||
const userQuackgrades = user.quackUpgrades?.cps || []
|
||||
return userQuackgrades.reduce((total, upgrade) => quackStore[upgrade].effect(total, user), 1)
|
||||
}
|
||||
|
||||
const singleItemCps = (user, itemName) => {
|
||||
const baseCps = buyableItems[itemName].earning
|
||||
// console.log('')
|
||||
// console.log(`${itemName} CPS:`)
|
||||
// console.log('baseCps', baseCps)
|
||||
|
||||
const itemUpgrades = (user.upgrades[itemName] || []).map(name => upgrades[name])
|
||||
const itemUpgradeCps = itemUpgrades.reduce((totalCps, upgrade) => upgrade.effect(totalCps, user), baseCps)
|
||||
const itemUpgradeCps = itemUpgrades.reduce((totalCps, upgrade) => upgrade.effect(totalCps, user), 1)
|
||||
// console.log('itemUpgradeCps', itemUpgradeCps)
|
||||
|
||||
const userGeneralUpgrades = user.upgrades.general || []
|
||||
const generalUpgradeCps = Object.entries(userGeneralUpgrades).reduce((total, [, upgradeName]) => upgrades[upgradeName].effect(total, user), itemUpgradeCps)
|
||||
const generalUpgradeCps = Object.entries(userGeneralUpgrades).reduce((total, [, upgradeName]) => upgrades[upgradeName].effect(total, user), 1)
|
||||
// console.log('generalUpgradeCps', generalUpgradeCps)
|
||||
|
||||
const achievementCount = Object.keys(user.achievements || {}).length
|
||||
const achievementMultiplier = Math.pow(1.01, achievementCount)
|
||||
// console.log('achievementMultiplier', achievementMultiplier)
|
||||
|
||||
const userQuackgrades = user.quackUpgrades?.cps || []
|
||||
const quackMultiplier = userQuackgrades.reduce((total, upgrade) => quackStore[upgrade].effect(total, user), 1)
|
||||
const quackGrade = quackGradeMultiplier(user)
|
||||
// console.log('quackgrade', quackGrade)
|
||||
|
||||
const prestigeMultiplier = 1 + ((user.prestige || 0) * 0.01)
|
||||
const pMult = prestigeMultiplier(user)
|
||||
// console.log('prestigeMultiplier', pMult)
|
||||
|
||||
return achievementMultiplier *
|
||||
quackMultiplier *
|
||||
prestigeMultiplier *
|
||||
getCompletedSquadgrades().reduce((cps, upgrade) => upgrade.effect(cps), generalUpgradeCps)
|
||||
const squadGradeMultiplier = getCompletedSquadgrades().reduce((cps, upgrade) => upgrade.effect(cps), 1)
|
||||
// console.log('squadGradeMultiplier', squadGradeMultiplier)
|
||||
|
||||
const total =
|
||||
baseCps *
|
||||
achievementMultiplier *
|
||||
itemUpgradeCps *
|
||||
generalUpgradeCps *
|
||||
quackGrade *
|
||||
pMult *
|
||||
squadGradeMultiplier
|
||||
|
||||
// console.log('Single Item CPS:', total)
|
||||
|
||||
return total
|
||||
}
|
||||
|
||||
const shuffle = str => str.split('').sort(() => 0.5 - Math.random()).join('')
|
||||
|
||||
const shufflePercent = (str, percentOdds) => {
|
||||
const shuffled = shuffle(str)
|
||||
let partiallyShuffled = ''
|
||||
const shuffleChar = () => Math.random() < percentOdds
|
||||
|
||||
let isEmoji = false
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
if (str[i] === ':') {
|
||||
isEmoji = !isEmoji
|
||||
}
|
||||
if (isEmoji) { // Less likely to shuffle emojis
|
||||
partiallyShuffled += (shuffleChar() && shuffleChar()) ? shuffled[i] : str[i]
|
||||
} else {
|
||||
partiallyShuffled += shuffleChar() ? shuffled[i] : str[i]
|
||||
}
|
||||
}
|
||||
|
||||
return partiallyShuffled
|
||||
}
|
||||
|
||||
const definitelyShuffle = (str, percentOdds) => {
|
||||
if (!str) {
|
||||
return str
|
||||
}
|
||||
if (!percentOdds) {
|
||||
percentOdds = 0.01
|
||||
}
|
||||
let shuffled = str
|
||||
while (shuffled === str) {
|
||||
shuffled = shufflePercent(str, percentOdds)
|
||||
}
|
||||
return shuffled
|
||||
}
|
||||
|
||||
const getRandomFromArray = array => array[Math.floor(Math.random() * array.length)]
|
||||
|
||||
/**
|
||||
* Adds reactions to the given message, in order.
|
||||
* If adding any reaction is a failure, it will continue on to the next.
|
||||
*
|
||||
* @param app The slack bolt app
|
||||
* @param channelId The id of the channel the message is in
|
||||
* @param timestamp The timestamp of the message
|
||||
* @param reactions An array of reactions to add
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const addReactions = async ({ app, channelId, timestamp, reactions }) => {
|
||||
for (const reaction of reactions) {
|
||||
try {
|
||||
await app.client.reactions.add({
|
||||
channel: channelId,
|
||||
timestamp,
|
||||
name: reaction
|
||||
})
|
||||
} catch (e) {
|
||||
logError(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports = {
|
||||
saveGame,
|
||||
makeBackup,
|
||||
logError,
|
||||
parseOr,
|
||||
maybeNews,
|
||||
|
@ -190,5 +375,13 @@ module.exports = {
|
|||
getItemCps,
|
||||
squadUpgrades,
|
||||
squadIsMissing,
|
||||
prestigeMultiplier,
|
||||
quackGradeMultiplier,
|
||||
shufflePercent,
|
||||
definitelyShuffle,
|
||||
parseAll,
|
||||
getRandomFromArray,
|
||||
chaosFilter,
|
||||
addReactions,
|
||||
game
|
||||
}
|
|
@ -46,10 +46,10 @@ const addCommand = ({ commandNames, helpText, action, condition, hidden }) => {
|
|||
console.log(' rate limited')
|
||||
return
|
||||
}
|
||||
console.log(` went through for ${slack.ourUsers[event.user]}`)
|
||||
console.log(` went through for ${slack.users[event.user]}`)
|
||||
userGetter.users[event.user].lastApiCall = currentTime
|
||||
|
||||
await action({event, say, words})
|
||||
await action({ event, say, words })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
await say(e.stack)
|
||||
|
|
|
@ -22,7 +22,9 @@ const buildGameStarter = ({ startTriggers, dataName, gameName, textFromBoard, in
|
|||
if (event.channel_type === 'im') {
|
||||
const eventText = event.text?.toLowerCase()
|
||||
if (eventText && startTriggers.find(keyword => eventText.startsWith('!' + keyword))) {
|
||||
console.log('Trigger found')
|
||||
const opponent = event.text.toUpperCase().match(/<@[^>]*>/)[0]
|
||||
console.log('Messaging opponent ' + slack.users[opponent.substring(2, opponent.length - 1)])
|
||||
const msg = messageFromBoard({
|
||||
dataName,
|
||||
gameName,
|
||||
|
@ -50,7 +52,8 @@ const getMessages = winner => {
|
|||
}
|
||||
|
||||
const buildTurnHandler = ({ gameName, dataName, checkWinner, textFromBoard, turnChoiceEmojis, makeMove }) => async ({ event, say }) => {
|
||||
if (event.item_user !== slack.hvackerBotUserId || !turnChoiceEmojis.includes(event.reaction)) {
|
||||
if (event.item_user !== slack.users.Hvacker || !turnChoiceEmojis.includes(event.reaction)) {
|
||||
console.log('bad item_user/reaction')
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -61,12 +64,14 @@ const buildTurnHandler = ({ gameName, dataName, checkWinner, textFromBoard, turn
|
|||
|
||||
const game = decodeGame(dataName, message.messages[0].text)
|
||||
if (!game) {
|
||||
console.log('could not decode game')
|
||||
return
|
||||
}
|
||||
|
||||
const { board, players } = game
|
||||
let winner = checkWinner(board)
|
||||
if (winner) {
|
||||
console.log('winner found: ' + winner)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -101,6 +106,7 @@ const buildTurnHandler = ({ gameName, dataName, checkWinner, textFromBoard, turn
|
|||
name: emojiName
|
||||
})
|
||||
turnChoiceEmojis.forEach(removeEmoji)
|
||||
console.log('SENDING to ' + opponent)
|
||||
const sentBoard = await slack.app.client.chat.postMessage({
|
||||
channel: opponent,
|
||||
text: boardMessage + winnerMessages.opponent
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
const routine = require("./routine");
|
||||
const routine = require('./routine')
|
||||
|
||||
const emptyBoard = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
|
||||
|
||||
const textFromBoard = board =>
|
||||
` ${board[0]} | ${board[1]} | ${board[2]} \n` +
|
||||
`-----------\n` +
|
||||
'-----------\n' +
|
||||
` ${board[3]} | ${board[4]} | ${board[5]} \n` +
|
||||
`-----------\n` +
|
||||
'-----------\n' +
|
||||
` ${board[6]} | ${board[7]} | ${board[8]}`
|
||||
|
||||
const numEmojis = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
|
||||
|
@ -21,7 +21,7 @@ const winningThrees = [
|
|||
[2, 5, 8],
|
||||
|
||||
[0, 4, 8],
|
||||
[2, 4, 6],
|
||||
[2, 4, 6]
|
||||
]
|
||||
|
||||
const checkWinner = board => {
|
||||
|
@ -71,4 +71,3 @@ routine.build({
|
|||
makeMove: applyTurn,
|
||||
checkWinner
|
||||
})
|
||||
|
||||
|
|
10
src/index.js
10
src/index.js
|
@ -26,12 +26,12 @@ onTempChangeRequested(change => {
|
|||
case 'Hotter': {
|
||||
lowTemp += 2
|
||||
highTemp += 2
|
||||
break;
|
||||
break
|
||||
}
|
||||
case 'Colder': {
|
||||
lowTemp -= 2
|
||||
highTemp -= 2
|
||||
break;
|
||||
break
|
||||
}
|
||||
case 'Good': {
|
||||
return
|
||||
|
@ -42,9 +42,9 @@ onTempChangeRequested(change => {
|
|||
lowTemp = cleanTemp(lowTemp)
|
||||
|
||||
const mode =
|
||||
indoorTemperature < lowTemp ? heatMode : // Heat if lower than low
|
||||
indoorTemperature > highTemp ? coolMode : // Cool if hotter than high
|
||||
change === 'Hotter' ? heatMode : coolMode // Otherwise (lower priority) follow the requested change
|
||||
indoorTemperature < lowTemp ? heatMode // Heat if lower than low
|
||||
: indoorTemperature > highTemp ? coolMode // Cool if hotter than high
|
||||
: change === 'Hotter' ? heatMode : coolMode // Otherwise (lower priority) follow the requested change
|
||||
|
||||
if (!mode) {
|
||||
return
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
const { App: SlackApp } = require('@slack/bolt')
|
||||
const config = require('../config')
|
||||
const { addReactions } = require('../games/hvacoins/utils')
|
||||
|
||||
const temperatureChannelId = 'C034156CE03'
|
||||
const hvackerBotUserId = 'U0344TFA7HQ'
|
||||
const sageUserId = 'U028BMEBWBV'
|
||||
|
||||
const pollingMinutes = 5
|
||||
const pollingPeriod = 1000 * 60 * pollingMinutes
|
||||
|
@ -41,6 +40,7 @@ const sendHelp = async (say, prefix) => {
|
|||
await say({
|
||||
text: prefix +
|
||||
`Sending a message matching any of \`${pollTriggers.join('`, `')}\` will start a temperature poll.\n` +
|
||||
'\'Hotter\' and \'Colder\' votes offset. E.g. with votes Hotter - 4, Colder - 3, and Content - 2, the temp won\'t change.\n' +
|
||||
'At this time I am not capable of actually changing the temperature. Go bug Quade.'
|
||||
})
|
||||
}
|
||||
|
@ -58,22 +58,38 @@ app.event('reaction_added', async ({ event, context, client, say }) => {
|
|||
}
|
||||
})
|
||||
|
||||
const ourUsers = {
|
||||
const users = {
|
||||
U028BMEBWBV: 'Sage',
|
||||
U02U15RFK4Y: 'Adam',
|
||||
U02AAB54V34: 'Houston',
|
||||
U02KYLVK1GV: 'Quade',
|
||||
U017PG4EL1Y: 'Max',
|
||||
UTDLFGZA5: 'Tyler',
|
||||
U017CB5L1K3: 'Andres'
|
||||
U017CB5L1K3: 'Andres',
|
||||
U0344TFA7HQ: 'Hvacker',
|
||||
U0X0ZQCN6: 'Caleb',
|
||||
U03BBTD4CQZ: 'Fernando',
|
||||
|
||||
Sage: 'U028BMEBWBV',
|
||||
Adam: 'U02U15RFK4Y',
|
||||
Houston: 'U02AAB54V34',
|
||||
Quade: 'U02KYLVK1GV',
|
||||
Max: 'U017PG4EL1Y',
|
||||
Tyler: 'UTDLFGZA5',
|
||||
Andres: 'U017CB5L1K3',
|
||||
Caleb: 'U0X0ZQCN6',
|
||||
Hvacker: 'U0344TFA7HQ',
|
||||
Fernando: 'U03BBTD4CQZ',
|
||||
}
|
||||
|
||||
const activePolls = {}
|
||||
const testId = 'U028BMEBWBV_TEST'
|
||||
let testMode = false
|
||||
app.event('message', async ({ event, context, client, say }) => {
|
||||
console.log(event)
|
||||
if (event.user === sageUserId) {
|
||||
if (event.subtype !== 'message_changed') {
|
||||
console.log(event)
|
||||
}
|
||||
if (event?.user === users.Sage) {
|
||||
if (event?.text.startsWith('!')) {
|
||||
if (testMode) {
|
||||
await messageSage('Currently in test mode!')
|
||||
|
@ -89,13 +105,14 @@ app.event('message', async ({ event, context, client, say }) => {
|
|||
if (testMode) {
|
||||
event.user = testId
|
||||
}
|
||||
// console.log(event.blocks[0].elements[0])
|
||||
}
|
||||
for (const listener of messageListeners) {
|
||||
listener({ event, say })
|
||||
}
|
||||
console.log('MSG', ourUsers[event.user], "'" + event.text + "'", new Date().toLocaleTimeString())
|
||||
if (event.user === 'U028BMEBWBV' && event.channel === 'D0347Q4H9FE') {
|
||||
if (event.user) {
|
||||
console.log('MSG', users[event.user], "'" + event.text + "'", new Date().toLocaleTimeString())
|
||||
}
|
||||
if (event.user === users.Sage && event.channel === 'D0347Q4H9FE') {
|
||||
if (event.text === '!!kill') {
|
||||
process.exit()
|
||||
}
|
||||
|
@ -103,18 +120,10 @@ app.event('message', async ({ event, context, client, say }) => {
|
|||
await postToTechThermostatChannel(event.text.substring(4).trim())
|
||||
return
|
||||
}
|
||||
if (event.text?.startsWith('!saytoq ')) {
|
||||
await messageQuade(event.text.substring(7).trim())
|
||||
return
|
||||
}
|
||||
if (event.text?.startsWith('!saytos')) {
|
||||
await messageSage(event.text.substring(7).trim())
|
||||
return
|
||||
}
|
||||
}
|
||||
const eventText = event.text?.toLowerCase() || ''
|
||||
|
||||
if (eventText.startsWith('!help')) {
|
||||
if (eventText === '!help') {
|
||||
await sendHelp(say)
|
||||
return
|
||||
}
|
||||
|
@ -139,21 +148,51 @@ app.event('message', async ({ event, context, client, say }) => {
|
|||
timestamp: pollTs,
|
||||
full: true
|
||||
})
|
||||
|
||||
const reactPosters = {}
|
||||
reactions.message.reactions.forEach(r => r.users.forEach(user => {
|
||||
reactPosters[user] ??= []
|
||||
reactPosters[user].push(r.name)
|
||||
}))
|
||||
|
||||
const reactCounts = {}
|
||||
reactions.message.reactions.forEach(reaction => { reactCounts[reaction.name] = reaction.count })
|
||||
Object.entries(reactPosters).forEach(([id, votes]) => {
|
||||
votes = votes.filter(v => [goodEmoji, hotterEmoji, colderEmoji].includes(v))
|
||||
if (votes.length === 1) {
|
||||
reactCounts[votes[0]] ??= 0
|
||||
reactCounts[votes[0]] += 1
|
||||
}
|
||||
})
|
||||
|
||||
const contentVotes = reactCounts[goodEmoji]
|
||||
const hotterVotes = reactCounts[hotterEmoji]
|
||||
const colderVotes = reactCounts[colderEmoji]
|
||||
const contentVotes = reactCounts[goodEmoji] || 0
|
||||
let hotterVotes = reactCounts[hotterEmoji] || 0
|
||||
let colderVotes = reactCounts[colderEmoji] || 0
|
||||
console.log('before contentVotes', contentVotes)
|
||||
console.log('before colderVotes', colderVotes)
|
||||
console.log('before hotterVotes', hotterVotes)
|
||||
|
||||
let text = 'The people have spoken, and would like to '
|
||||
if (hotterVotes > colderVotes) {
|
||||
hotterVotes -= colderVotes
|
||||
colderVotes = 0
|
||||
} else if (colderVotes > hotterVotes) {
|
||||
colderVotes -= hotterVotes
|
||||
hotterVotes = 0
|
||||
}
|
||||
console.log('after contentVotes', contentVotes)
|
||||
console.log('after colderVotes', colderVotes)
|
||||
console.log('after hotterVotes', hotterVotes)
|
||||
|
||||
let text
|
||||
if (hotterVotes > colderVotes && hotterVotes > contentVotes) {
|
||||
text = `<@${users.Quade}> The people have spoken, and would like to `
|
||||
text += 'raise the temperature, quack.'
|
||||
requestTempChange('Hotter')
|
||||
} else if (colderVotes > hotterVotes && colderVotes > contentVotes) {
|
||||
text = `<@${users.Quade}> The people have spoken, and would like to `
|
||||
text += 'lower the temperature, quack quack.'
|
||||
requestTempChange('Colder')
|
||||
} else {
|
||||
text = `The people have spoken, and would like to `
|
||||
text += 'keep the temperature as-is, quaaack.'
|
||||
requestTempChange('Good')
|
||||
}
|
||||
|
@ -166,9 +205,6 @@ app.event('message', async ({ event, context, client, say }) => {
|
|||
;(async () => {
|
||||
await app.start().catch(console.error)
|
||||
console.log('Slack Bolt has started')
|
||||
// setTimeout(async () => {
|
||||
// await messageSage('<https://i.imgur.com/VCvfvdz.png|...>')
|
||||
// }, 2000)
|
||||
})()
|
||||
|
||||
const postToTechThermostatChannel = async optionsOrText => {
|
||||
|
@ -180,8 +216,7 @@ const postToTechThermostatChannel = async optionsOrText => {
|
|||
return app.client.chat.postMessage({ ...optionsOrText, channel: temperatureChannelId })
|
||||
}
|
||||
|
||||
const messageSage = async optionsOrText => messageIn(sageUserId, optionsOrText)
|
||||
const messageQuade = async optionsOrText => messageIn('U02KYLVK1GV', optionsOrText)
|
||||
const messageSage = async optionsOrText => messageIn(users.Sage, optionsOrText)
|
||||
|
||||
const messageIn = async (channel, optionsOrText) => {
|
||||
if (optionsOrText === null || typeof optionsOrText !== 'object') {
|
||||
|
@ -196,17 +231,14 @@ const startPoll = async () => {
|
|||
const sent = await postToTechThermostatChannel({
|
||||
text: `<!here|here> Temperature poll requested! In ${pollingMinutes} minutes the temperature will be adjusted.\n` +
|
||||
`Pick :${colderEmoji}: if you want it colder, :${hotterEmoji}: if you want it hotter, or :${goodEmoji}: if you like it how it is.` +
|
||||
`\n(Note that I can't actually change the temperature yet. Make Quade do it!)`
|
||||
'\n(Note that I can\'t actually change the temperature yet. Make Quade do it!)'
|
||||
})
|
||||
await addReactions({
|
||||
app,
|
||||
channelId: temperatureChannelId,
|
||||
timestamp: sent.ts,
|
||||
reactions: [colderEmoji, hotterEmoji, goodEmoji]
|
||||
})
|
||||
const addReaction = async emojiName =>
|
||||
app.client.reactions.add({
|
||||
channel: temperatureChannelId,
|
||||
timestamp: sent.ts,
|
||||
name: emojiName
|
||||
})
|
||||
await addReaction(colderEmoji)
|
||||
await addReaction(hotterEmoji)
|
||||
await addReaction(goodEmoji)
|
||||
return sent.ts
|
||||
}
|
||||
|
||||
|
@ -234,19 +266,18 @@ const decodeData = (key, message) => {
|
|||
const onReaction = listener => reactionListeners.push(listener)
|
||||
|
||||
onReaction(async ({ event }) => {
|
||||
if (event.user === sageUserId && event.reaction === 'x') {
|
||||
console.log(event)
|
||||
try {
|
||||
await app.client.chat.delete({channel: event.item.channel, ts: event.item.ts})
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
if (event.user === users.Sage) {
|
||||
if (event.reaction === 'x') {
|
||||
try {
|
||||
await app.client.chat.delete({ channel: event.item.channel, ts: event.item.ts })
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = {
|
||||
app,
|
||||
hvackerBotUserId,
|
||||
temperatureChannelId,
|
||||
onAction: app.action,
|
||||
getMessage,
|
||||
|
@ -257,10 +288,9 @@ module.exports = {
|
|||
onReaction,
|
||||
encodeData,
|
||||
decodeData,
|
||||
sageUserId,
|
||||
messageSage,
|
||||
messageIn,
|
||||
testMode,
|
||||
testId,
|
||||
ourUsers
|
||||
users
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue