Skip to content

Commit

Permalink
feat(explore): collectible rarity now matters
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Jun 29, 2023
1 parent cc9627a commit 92220bd
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions server/src/modules/player/player.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ILocation,
INotificationAction,
IPatchUser,
Rarity,
} from '@interfaces';
import { EntityManager, EntityRepository } from '@mikro-orm/mongodb';
import { InjectRepository } from '@mikro-orm/nestjs';
Expand Down Expand Up @@ -331,12 +332,29 @@ export class PlayerService {
player: Player,
location: ILocation,
): Promise<any> {
const randomCollectibleForLocation = sample(
this.contentService
.allCollectibles()
.filter((coll) => coll.location === location.name),
);
const collectibleRarityCommonality: Record<Rarity, number> = {
Common: 100,
Uncommon: 75,
Unusual: 50,
Rare: 25,
Epic: 10,
Arcane: 5,
Divine: 3,
Masterful: 2,
Unique: 1,
};

const allCollectibles = this.contentService
.allCollectibles()
.filter((coll) => coll.location === location.name);

const allCollectiblesWithRarity = allCollectibles
.map((coll) =>
Array(collectibleRarityCommonality[coll.rarity] ?? 1).fill(coll),
)
.flat();

const randomCollectibleForLocation = sample(allCollectiblesWithRarity);
if (!randomCollectibleForLocation) return;

this.setPlayerAction(player, {
Expand Down

0 comments on commit 92220bd

Please sign in to comment.