2019-12-08 22:43:49 +01:00
|
|
|
# vim: set fileencoding=utf-8
|
|
|
|
from typing import Tuple
|
2021-09-07 19:56:15 +02:00
|
|
|
from typing_extensions import Final
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
from bemani.backend.iidx.base import IIDXBase
|
|
|
|
from bemani.common import ValidatedDict
|
|
|
|
from bemani.data import UserID
|
|
|
|
|
|
|
|
|
|
|
|
class IIDXCourse(IIDXBase):
|
|
|
|
|
2021-09-07 19:56:15 +02:00
|
|
|
COURSE_TYPE_SECRET: Final[str] = 'secret_course'
|
|
|
|
COURSE_TYPE_INTERNET_RANKING: Final[str] = 'ir_course'
|
|
|
|
COURSE_TYPE_CLASSIC: Final[str] = 'classic_course'
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def id_and_chart_from_courseid(self, courseid: int) -> Tuple[int, int]:
|
|
|
|
return (int(courseid / 6), courseid % 6)
|
|
|
|
|
|
|
|
def update_course(
|
|
|
|
self,
|
|
|
|
userid: UserID,
|
|
|
|
coursetype: str,
|
|
|
|
courseid: int,
|
|
|
|
chart: int,
|
|
|
|
clear_status: int,
|
|
|
|
pgreats: int,
|
|
|
|
greats: int,
|
|
|
|
) -> None:
|
|
|
|
# Range check course type
|
|
|
|
if coursetype not in [
|
|
|
|
self.COURSE_TYPE_SECRET,
|
|
|
|
self.COURSE_TYPE_INTERNET_RANKING,
|
|
|
|
self.COURSE_TYPE_CLASSIC,
|
|
|
|
]:
|
2020-01-07 22:29:07 +01:00
|
|
|
raise Exception(f"Invalid course type value {coursetype}")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Range check medals
|
|
|
|
if clear_status not in [
|
|
|
|
self.CLEAR_STATUS_NO_PLAY,
|
|
|
|
self.CLEAR_STATUS_FAILED,
|
|
|
|
self.CLEAR_STATUS_ASSIST_CLEAR,
|
|
|
|
self.CLEAR_STATUS_EASY_CLEAR,
|
|
|
|
self.CLEAR_STATUS_CLEAR,
|
|
|
|
self.CLEAR_STATUS_HARD_CLEAR,
|
|
|
|
self.CLEAR_STATUS_EX_HARD_CLEAR,
|
|
|
|
self.CLEAR_STATUS_FULL_COMBO,
|
|
|
|
]:
|
2020-01-07 22:29:07 +01:00
|
|
|
raise Exception(f"Invalid clear status value {clear_status}")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Update achievement to track course statistics
|
|
|
|
course_score = self.data.local.user.get_achievement(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
userid,
|
|
|
|
courseid * 6 + chart,
|
|
|
|
coursetype,
|
|
|
|
)
|
|
|
|
if course_score is None:
|
|
|
|
course_score = ValidatedDict()
|
|
|
|
course_score.replace_int('clear_status', max(clear_status, course_score.get_int('clear_status')))
|
|
|
|
old_ex_score = (course_score.get_int('pgnum') * 2) + course_score.get_int('gnum')
|
|
|
|
if old_ex_score < ((pgreats * 2) + greats):
|
|
|
|
course_score.replace_int('pgnum', pgreats)
|
|
|
|
course_score.replace_int('gnum', greats)
|
|
|
|
|
|
|
|
self.data.local.user.put_achievement(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
userid,
|
|
|
|
courseid * 6 + chart,
|
|
|
|
coursetype,
|
|
|
|
course_score,
|
|
|
|
)
|