Skip to content

Commit

Permalink
feat(explore): you can only wave at a person once every 12 hours, closes
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Sep 14, 2023
1 parent c626ddc commit 6400445
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ we love eating our oats
- `EXPLORE_EVENT_WAVE_PERCENT_BOOST` - the percent boost to wave events happening (default: 0)
- `EXPLORE_SPEED_MULTIPLIER` - the multiplier for explore speed [percent] (default: 100)
- `EXPLORE_XP_MULTIPLIER` - the multiplier for explore XP [percent] (default: 100)
- `EXPLORE_EVENT_WAVE_COOLDOWN` - the hour cooldown between waves (default: 12)

#### Finding Items

Expand Down
2 changes: 2 additions & 0 deletions server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { GameplayModule } from './modules/gameplay/gameplay.module';
import { LeaderboardModule } from './modules/leaderboard/leaderboard.module';
import { MarketModule } from './modules/market/market.module';
import { UpdateAuthTimeInterceptor } from './utils/updatetime.interceptor';
import { WaveModule } from './modules/wave/wave.module';

const logLevel = process.env.LOG_LEVEL || 'trace';

Expand Down Expand Up @@ -97,6 +98,7 @@ const logLevel = process.env.LOG_LEVEL || 'trace';
AggregatorModule,
EventsModule,
LeaderboardModule,
WaveModule,
],
controllers: [AppController, GameplayController],
providers: [
Expand Down
2 changes: 2 additions & 0 deletions server/src/modules/config/mikro-orm-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Notification } from '@modules/notification/notification.schema';
import { Player } from '@modules/player/player.schema';
import { Stats } from '@modules/stats/stats.schema';
import { User } from '@modules/user/user.schema';
import { PlayerWave } from '@modules/wave/playerwave.schema';
import { ConfigService } from '@nestjs/config';

export const MIKRO_ORM_CONFIG = Symbol('MIKRO_ORM_CONFIG');
Expand Down Expand Up @@ -42,6 +43,7 @@ function mikroOrmConfigFactory(
MarketItem,
MarketSale,
Fight,
PlayerWave,
],
dbName: process.env.NODE_ENV === 'production' ? 'ateoat' : 'ateoattest',
type: 'mongo',
Expand Down
5 changes: 5 additions & 0 deletions server/src/modules/content/constants.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class ConstantsService {
public readonly baseExploreSpeed: number = 3;

public readonly wavePercentBoost: number = 0;
public readonly waveHourCooldown: number = 12;
public readonly itemFindPercentBoost: number = 0;
public readonly collectibleFindPercentBoost: number = 0;
public readonly resourceFindPercentBoost: number = 0;
Expand Down Expand Up @@ -83,6 +84,10 @@ export class ConstantsService {
'EXPLORE_EVENT_WAVE_PERCENT_BOOST',
0,
);
this.waveHourCooldown = +this.configService.get<number>(
'EXPLORE_EVENT_WAVE_COOLDOWN',
12,
);
this.itemFindPercentBoost = +this.configService.get<number>(
'EXPLORE_EVENT_ITEM_FIND_PERCENT_BOOST',
0,
Expand Down
6 changes: 4 additions & 2 deletions server/src/modules/gameplay/gameplay.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { InventoryModule } from '@modules/inventory/inventory.module';
import { NotificationModule } from '@modules/notification/notification.module';
import { PlayerModule } from '@modules/player/player.module';
import { StatsModule } from '@modules/stats/stats.module';
import { WaveModule } from '@modules/wave/wave.module';
import { Module } from '@nestjs/common';
import { ItemService } from './item.service';
import { NpcService } from './npc.service';
Expand All @@ -25,20 +26,21 @@ import { TravelService } from './travel.service';
PlayerModule,
CraftingModule,
FightModule,
WaveModule,
],
providers: [
GameplayService,
TravelService,
WaveService,
ItemService,
NpcService,
WaveService,
],
exports: [
GameplayService,
TravelService,
WaveService,
ItemService,
NpcService,
WaveService,
],
})
export class GameplayModule {}
4 changes: 4 additions & 0 deletions server/src/modules/gameplay/wave.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { NotificationService } from '@modules/notification/notification.service'
import { Player } from '@modules/player/player.schema';
import { PlayerService } from '@modules/player/player.service';
import { StatsService } from '@modules/stats/stats.service';
import { WaveDBService } from '@modules/wave/wavedb.service';
import {
ForbiddenException,
Injectable,
Expand All @@ -22,6 +23,7 @@ export class WaveService {
private readonly analyticsService: AnalyticsService,
private readonly events: EventEmitter2,
private readonly notificationService: NotificationService,
private readonly waveDBService: WaveDBService,
) {}

async waveToPlayerFromExplore(userId: string): Promise<UserResponse> {
Expand Down Expand Up @@ -141,6 +143,8 @@ export class WaveService {

this.logger.verbose(`Player ${userId} waved to ${targetUserId}.`);

await this.waveDBService.addWave(userId, targetUserId);

return { player: playerPatches };
}
}
2 changes: 2 additions & 0 deletions server/src/modules/player/player.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { NpcService } from '@modules/player/npc.service';
import { PlayerController } from '@modules/player/player.controller';
import { Player } from '@modules/player/player.schema';
import { PlayerService } from '@modules/player/player.service';
import { WaveModule } from '@modules/wave/wave.module';
import { Module } from '@nestjs/common';

@Module({
Expand All @@ -15,6 +16,7 @@ import { Module } from '@nestjs/common';
ContentModule,
InventoryModule,
DiscoveriesModule,
WaveModule,
],
providers: [PlayerService, NpcService],
exports: [PlayerService],
Expand Down
8 changes: 8 additions & 0 deletions server/src/modules/player/player.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Inventory } from '@modules/inventory/inventory.schema';
import { InventoryService } from '@modules/inventory/inventory.service';
import { NpcService } from '@modules/player/npc.service';
import { Player } from '@modules/player/player.schema';
import { WaveDBService } from '@modules/wave/wavedb.service';
import {
BadRequestException,
ForbiddenException,
Expand All @@ -43,6 +44,7 @@ export class PlayerService {
private readonly discoveriesService: DiscoveriesService,
private readonly npcService: NpcService,
private readonly events: EventEmitter2,
private readonly waveDBService: WaveDBService,
) {}

async getPlayerForUser(userId: string): Promise<Player | undefined> {
Expand Down Expand Up @@ -437,6 +439,12 @@ export class PlayerService {

if (!randomPlayer) return;

const existingWave = await this.waveDBService.getExistingWave(
player.userId,
randomPlayer.userId,
);
if (existingWave) return;

this.setPlayerAction(player, {
text: 'Wave',
action: 'wave',
Expand Down
41 changes: 41 additions & 0 deletions server/src/modules/wave/playerwave.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {
Entity,
Index,
PrimaryKey,
Property,
SerializedPrimaryKey,
} from '@mikro-orm/core';
import { ObjectId } from '@mikro-orm/mongodb';

@Entity()
export class PlayerWave {
@PrimaryKey({ hidden: true })
_id!: ObjectId;

@SerializedPrimaryKey({ hidden: true })
id!: string;

@Index()
@Property()
playerWaving: string;

@Index()
@Property()
playerWavingAt: string;

@Property()
@Index({ options: { expireAfterSeconds: 0 } })
expiresAt: Date;

constructor(
playerWaving: string,
playerWavingAt: string,
expiresAfterHours = 12,
) {
this.playerWaving = playerWaving;
this.playerWavingAt = playerWavingAt;

this.expiresAt = new Date();
this.expiresAt.setHours(this.expiresAt.getHours() + expiresAfterHours);
}
}
11 changes: 11 additions & 0 deletions server/src/modules/wave/wave.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { PlayerWave } from '@modules/wave/playerwave.schema';
import { Module } from '@nestjs/common';
import { WaveDBService } from './wavedb.service';

@Module({
imports: [MikroOrmModule.forFeature([PlayerWave])],
providers: [WaveDBService],
exports: [WaveDBService],
})
export class WaveModule {}
27 changes: 27 additions & 0 deletions server/src/modules/wave/wavedb.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { EntityRepository } from '@mikro-orm/mongodb';
import { InjectRepository } from '@mikro-orm/nestjs';
import { PlayerWave } from '@modules/wave/playerwave.schema';
import { Injectable } from '@nestjs/common';

@Injectable()
export class WaveDBService {
constructor(
@InjectRepository(PlayerWave)
private readonly playerWaves: EntityRepository<PlayerWave>,
) {}

async getExistingWave(
waver: string,
wavedAt: string,
): Promise<PlayerWave | null> {
return this.playerWaves.findOne({
playerWaving: waver,
playerWavingAt: wavedAt,
});
}

async addWave(waver: string, wavedAt: string): Promise<void> {
const wave = new PlayerWave(waver, wavedAt);
await this.playerWaves.create(wave);
}
}

0 comments on commit 6400445

Please sign in to comment.