diff --git a/server/src/modules/content/constants.service.ts b/server/src/modules/content/constants.service.ts index fc04b9f..847fad7 100644 --- a/server/src/modules/content/constants.service.ts +++ b/server/src/modules/content/constants.service.ts @@ -276,7 +276,7 @@ export class ConstantsService { this.worshipDuration = +this.configService.get( 'WORSHIP_DURATION', - 24, + 1, ); this.worshipCoinBoost = +this.configService.get( diff --git a/server/src/modules/content/content.service.ts b/server/src/modules/content/content.service.ts index f4cfc4a..f1989ff 100644 --- a/server/src/modules/content/content.service.ts +++ b/server/src/modules/content/content.service.ts @@ -142,6 +142,10 @@ export class ContentService { return Object.values(this.resources ?? {}); } + public isResource(resourceId: string): boolean { + return !!this.resources[resourceId]; + } + public getResource(resourceId: string): IResource { const resourceRef = this.resources[resourceId]; if (!resourceRef) diff --git a/server/src/modules/gameplay/worship.service.ts b/server/src/modules/gameplay/worship.service.ts index b8a86d7..0ad8059 100644 --- a/server/src/modules/gameplay/worship.service.ts +++ b/server/src/modules/gameplay/worship.service.ts @@ -54,7 +54,7 @@ export class WorshipService { await this.statsService.incrementStat(userId, 'worships' as TrackedStat, 1); await this.statsService.incrementStat( - deity, + userId, `worship${capitalize(deity)}` as TrackedStat, 1, ); diff --git a/server/src/modules/market/market.service.ts b/server/src/modules/market/market.service.ts index 1385966..376f260 100644 --- a/server/src/modules/market/market.service.ts +++ b/server/src/modules/market/market.service.ts @@ -59,13 +59,14 @@ export class MarketService { const user = await this.userService.findUserById(userId); if (!user) throw new NotFoundException(`User ${userId} not found`); - const isResource = this.contentService.getResource(instanceId); + const isResource = this.contentService.isResource(instanceId); let itemRef: IItem | undefined; let itemId = ''; if (isResource) { - itemRef = isResource; - itemId = isResource.itemId; + const resourceRef = this.contentService.getResource(instanceId); + itemRef = resourceRef; + itemId = resourceRef.itemId; } else { const inventoryItem = await this.inventoryService.getInventoryItemForUser( userId, @@ -341,7 +342,7 @@ export class MarketService { const user = await this.userService.findUserById(userId); if (!user) throw new NotFoundException(`User ${userId} not found`); - const isResource = this.contentService.getResource(listing.itemId); + const isResource = this.contentService.isResource(listing.itemId); if (!this.playerHelper.hasCoins(player, listing.price)) return userError('Not enough coins'); @@ -487,7 +488,7 @@ export class MarketService { if (listing.userId !== userId) throw new BadRequestException('You cannot remove this listing'); - const isResource = this.contentService.getResource(listing.itemId); + const isResource = this.contentService.isResource(listing.itemId); const isInventoryFull = await this.inventoryService.isInventoryFull(userId); if (!isResource && isInventoryFull) return userError('Your inventory is full!'); diff --git a/server/src/utils/leaderboard-queries.ts b/server/src/utils/leaderboard-queries.ts index 71ba948..6c23201 100644 --- a/server/src/utils/leaderboard-queries.ts +++ b/server/src/utils/leaderboard-queries.ts @@ -102,4 +102,53 @@ export const leaderboardQueries = [ }; }, })), + ...[ + { + name: 'Worship: Most Faithful', + singleUserName: 'Total Worships', + stat: 'worships', + }, + { + name: 'Worship: Most Buibui Worships', + singleUserName: 'Buibui Worships', + stat: 'worshipCoins', + }, + { + name: 'Worship: Most Eindew Worships', + singleUserName: 'Eindew Worships', + stat: 'worshipXp', + }, + { + name: `Worship: Most Gra'Chl Worships`, + singleUserName: `Gra'Chl Worships`, + stat: 'worshipDefense', + }, + { + name: 'Worship: Most Parthe Worships', + singleUserName: 'Parthe Worships', + stat: 'worshipTravel', + }, + { + name: 'Worship: Most Ruspoo Worships', + singleUserName: 'Ruspoo Worships', + stat: 'worshipOffense', + }, + { + name: 'Worship: Most Spoodles Worships', + singleUserName: 'Spoodles Worships', + stat: 'worshipNothing', + }, + ].map(({ name, singleUserName, stat }) => ({ + name, + singleUserName, + query: { [`stats.${stat}`]: { $gt: 0 } }, + fields: { ...alwaysFields, [`stats.${stat}`]: 1 }, + params: { sort: { [`stats.${stat}`]: -1 }, limit: numPlayersPerCategory }, + formatter: (data) => { + return { + ...alwaysData(data), + value: data.stats?.[stat]?.toLocaleString() ?? '0', + }; + }, + })), ]; diff --git a/utils/headless-runner/play.ts b/utils/headless-runner/play.ts index d8a045d..b7db1a7 100644 --- a/utils/headless-runner/play.ts +++ b/utils/headless-runner/play.ts @@ -16,6 +16,7 @@ import { sellRandomItem, sellRandomResource, } from './market'; +import { canWorship, worshipRandomDeity } from './worship'; export async function gameloop(playerApi: PlayerApi) { try { @@ -28,6 +29,10 @@ export async function gameloop(playerApi: PlayerApi) { console.error('Error... server down? Skipping action...'); } + if (canWorship(playerApi)) { + await worshipRandomDeity(playerApi); + } + if (hasResources(playerApi) && hasEnoughCoins(playerApi)) { await sellRandomResource(playerApi); } diff --git a/utils/headless-runner/worship.ts b/utils/headless-runner/worship.ts new file mode 100644 index 0000000..fe58d15 --- /dev/null +++ b/utils/headless-runner/worship.ts @@ -0,0 +1,17 @@ +import { PlayerApi } from './_types'; + +export function canWorship(playerApi: PlayerApi): boolean { + return (playerApi.player.player.deityPrayerCooldown ?? 0) < Date.now(); +} + +export async function worshipRandomDeity(playerApi: PlayerApi): Promise { + const deities = ['travel', 'xp', 'coins', 'offense', 'defense', 'nothing']; + const randomDeity = deities[Math.floor(Math.random() * deities.length)]; + + console.info(`${playerApi.name} is worshipping: ${randomDeity}...`); + + return playerApi.api + .url(`/gameplay/worship`) + .post({ deity: randomDeity }) + .json(); +}