Added last_single_ontime_hours achievement logic #268_achievements

This commit is contained in:
Sven Heidemann 2023-07-15 14:48:04 +02:00
parent 189128f0d3
commit a71e3e4720
2 changed files with 10 additions and 1 deletions

View File

@ -44,3 +44,7 @@ class AchievementAttributeResolver:
def get_played_on_game_server(self, user: User) -> List[str]: def get_played_on_game_server(self, user: User) -> List[str]:
joins = self._user_joined_game_server.get_user_joined_game_servers_by_user_id(user.id) joins = self._user_joined_game_server.get_user_joined_game_servers_by_user_id(user.id)
return joins.select(lambda x: x.game_server.name) return joins.select(lambda x: x.game_server.name)
def get_last_ontime_hours(self, user: User) -> int:
ujvs = self._user_joined_voice_channels.get_user_joined_voice_channels_by_user_id(user.id)
return int(str(ujvs.max(lambda join: (join.leaved_on - join.joined_on).total_seconds() / 3600)))

View File

@ -48,7 +48,9 @@ class AchievementService:
AchievementAttribute( AchievementAttribute(
"played_on_game_server", lambda user: resolver.get_played_on_game_server(user), "GameServer" "played_on_game_server", lambda user: resolver.get_played_on_game_server(user), "GameServer"
), ),
AchievementAttribute("last_single_ontime_hours", lambda user: user.level, "GameServer"), AchievementAttribute(
"last_single_ontime_hours", lambda user: resolver.get_last_ontime_hours(user), "number"
),
] ]
) )
@ -62,6 +64,9 @@ class AchievementService:
"contains": lambda value, expected_value: expected_value in value, "contains": lambda value, expected_value: expected_value in value,
} }
def add_achievement_attribute(self, atr: AchievementAttribute):
self._attributes.add(atr)
def get_operators(self) -> list[str]: def get_operators(self) -> list[str]:
return [x for x in self._operators.keys()] return [x for x in self._operators.keys()]