-
Notifications
You must be signed in to change notification settings - Fork 7
Added achievement for playing multiple games with different players #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
@@ -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 equally as many unique 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] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why 30? |
||
| if len(top20) < 20: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic is wrong. If a player has only ever played with the same 5 players, they should be able to get the base level. |
||
| 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" | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think something is wrong with the icon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
played_with_count.most_common()