Skip to content

Commit

Permalink
Added achievement for playing multiple games with different players
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipTzannis committed Sep 3, 2024
1 parent 606e076 commit 9527c88
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions games/achievements.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import zoneinfo
from collections import Counter
from enum import StrEnum

from django.db.models import Q
Expand Down Expand Up @@ -188,6 +189,36 @@ def get_level(user):
return AchievementLevel.NO_LEVEL


class TheMoreTheMerrierAchievement(Achievement):
name = "The More The Merrier"
description = (
"Play atleast 5/10/15/20 games with as many different players"
)
icon = "merrier.svg"
def get_level(user):
played_with_count = Counter()
for game in user.games.filter():
for player in game.players.all():
if player != user:
played_with_count[player.username] += 1

top20 = sorted(
({"x": k, "y": v} for k, v in played_with_count.items()),
key=lambda x: -x["y"],
)[:30]
if len(top20) < 20:
return AchievementLevel.NO_LEVEL
if top20[19].get("y") >= 20:
return AchievementLevel.GOLD
elif top20[14].get("y") >= 15:
return AchievementLevel.SILVER
elif top20[9].get("y") >= 10:
return AchievementLevel.BRONZE
elif top20[4].get("y") >= 5:
return AchievementLevel.BASE
else:
return AchievementLevel.NO_LEVEL

class PilfingerAchievement(Achievement):
name = "Pilfinger"
description = "Stille stille stille, Pille pille pille"
Expand Down

0 comments on commit 9527c88

Please sign in to comment.