2019-12-08 22:43:49 +01:00
|
|
|
from typing import Any, Dict, 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.reflec.base import ReflecBeatBase
|
|
|
|
|
2021-08-20 06:43:13 +02:00
|
|
|
from bemani.common import Profile, VersionConstants, ID, Time
|
2019-12-08 22:43:49 +01:00
|
|
|
from bemani.data import UserID
|
|
|
|
from bemani.protocol import Node
|
|
|
|
|
|
|
|
|
|
|
|
class ReflecBeat(ReflecBeatBase):
|
|
|
|
|
2021-09-07 19:56:15 +02:00
|
|
|
name: str = "REFLEC BEAT"
|
|
|
|
version: int = VersionConstants.REFLEC_BEAT
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Clear types according to the game
|
2021-09-07 19:56:15 +02:00
|
|
|
GAME_CLEAR_TYPE_NO_PLAY: Final[int] = 0
|
|
|
|
GAME_CLEAR_TYPE_PLAYED: Final[int] = 2
|
|
|
|
GAME_CLEAR_TYPE_FULL_COMBO: Final[int] = 3
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2021-09-10 21:15:03 +02:00
|
|
|
# Reflec Beat has no profile succession
|
|
|
|
supports_expired_profiles: bool = False
|
|
|
|
|
2019-12-08 22:43:49 +01:00
|
|
|
@classmethod
|
|
|
|
def get_settings(cls) -> Dict[str, Any]:
|
|
|
|
"""
|
|
|
|
Return all of our front-end modifiably settings.
|
|
|
|
"""
|
|
|
|
return {
|
2022-10-15 20:56:30 +02:00
|
|
|
"bools": [
|
2019-12-08 22:43:49 +01:00
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"name": "Force Song Unlock",
|
|
|
|
"tip": "Force unlock all songs.",
|
|
|
|
"category": "game_config",
|
|
|
|
"setting": "force_unlock_songs",
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
],
|
2022-10-15 20:56:30 +02:00
|
|
|
"ints": [],
|
2019-12-08 22:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
def __db_to_game_clear_type(self, db_clear_type: int, db_combo_type: int) -> int:
|
|
|
|
if db_clear_type == self.CLEAR_TYPE_NO_PLAY:
|
|
|
|
return self.GAME_CLEAR_TYPE_NO_PLAY
|
|
|
|
if db_clear_type == self.CLEAR_TYPE_FAILED:
|
|
|
|
return self.GAME_CLEAR_TYPE_PLAYED
|
|
|
|
if db_clear_type in [
|
|
|
|
self.CLEAR_TYPE_CLEARED,
|
|
|
|
self.CLEAR_TYPE_HARD_CLEARED,
|
|
|
|
self.CLEAR_TYPE_S_HARD_CLEARED,
|
|
|
|
]:
|
|
|
|
if db_combo_type in [
|
|
|
|
self.COMBO_TYPE_NONE,
|
|
|
|
self.COMBO_TYPE_ALMOST_COMBO,
|
|
|
|
]:
|
|
|
|
return self.GAME_CLEAR_TYPE_PLAYED
|
|
|
|
if db_combo_type in [
|
|
|
|
self.COMBO_TYPE_FULL_COMBO,
|
|
|
|
self.COMBO_TYPE_FULL_COMBO_ALL_JUST,
|
|
|
|
]:
|
|
|
|
return self.GAME_CLEAR_TYPE_FULL_COMBO
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(f"Invalid db_combo_type {db_combo_type}")
|
|
|
|
raise Exception(f"Invalid db_clear_type {db_clear_type}")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
def __game_to_db_clear_type(
|
|
|
|
self, game_clear_type: int, game_achievement_rate: int
|
|
|
|
) -> Tuple[int, int]:
|
2019-12-08 22:43:49 +01:00
|
|
|
if game_clear_type == self.GAME_CLEAR_TYPE_NO_PLAY:
|
|
|
|
return (self.CLEAR_TYPE_NO_PLAY, self.COMBO_TYPE_NONE)
|
|
|
|
if game_clear_type == self.GAME_CLEAR_TYPE_PLAYED:
|
|
|
|
if game_achievement_rate >= 7000:
|
|
|
|
return (self.CLEAR_TYPE_CLEARED, self.COMBO_TYPE_NONE)
|
|
|
|
else:
|
|
|
|
return (self.CLEAR_TYPE_FAILED, self.COMBO_TYPE_NONE)
|
|
|
|
if game_clear_type == self.GAME_CLEAR_TYPE_FULL_COMBO:
|
|
|
|
return (self.CLEAR_TYPE_CLEARED, self.COMBO_TYPE_FULL_COMBO)
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(f"Invalid game_clear_type {game_clear_type}")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def handle_log_pcb_status_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("log")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def handle_log_opsetting_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("log")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def handle_log_play_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("log")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def handle_pcbinfo_get_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
shop_id = ID.parse_machine_id(request.child_value("lid"))
|
2019-12-08 22:43:49 +01:00
|
|
|
machine = self.get_machine_by_id(shop_id)
|
|
|
|
if machine is not None:
|
|
|
|
machine_name = machine.name
|
2022-10-15 20:56:30 +02:00
|
|
|
close = machine.data.get_bool("close")
|
|
|
|
hour = machine.data.get_int("hour")
|
|
|
|
minute = machine.data.get_int("minute")
|
|
|
|
pref = machine.data.get_int("pref", self.get_machine_region())
|
2019-12-08 22:43:49 +01:00
|
|
|
else:
|
2022-10-15 20:56:30 +02:00
|
|
|
machine_name = ""
|
2019-12-08 22:43:49 +01:00
|
|
|
close = False
|
|
|
|
hour = 0
|
|
|
|
minute = 0
|
2021-09-07 04:48:57 +02:00
|
|
|
pref = self.get_machine_region()
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("pcbinfo")
|
|
|
|
info = Node.void("info")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(info)
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
info.add_child(Node.string("name", machine_name))
|
|
|
|
info.add_child(Node.s16("pref", pref))
|
|
|
|
info.add_child(Node.bool("close", close))
|
|
|
|
info.add_child(Node.u8("hour", hour))
|
|
|
|
info.add_child(Node.u8("min", minute))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
return root
|
|
|
|
|
|
|
|
def handle_pcbinfo_set_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
self.update_machine_name(request.child_value("info/name"))
|
|
|
|
self.update_machine_data(
|
|
|
|
{
|
|
|
|
"close": request.child_value("info/close"),
|
|
|
|
"hour": request.child_value("info/hour"),
|
|
|
|
"minute": request.child_value("info/min"),
|
|
|
|
"pref": request.child_value("info/pref"),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
return Node.void("pcbinfo")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def __add_event_info(self, request: Node) -> None:
|
|
|
|
events: Dict[int, int] = {}
|
|
|
|
|
2021-07-07 00:29:41 +02:00
|
|
|
for (_eventid, _phase) in events.items():
|
2022-10-15 20:56:30 +02:00
|
|
|
data = Node.void("data")
|
2019-12-08 22:43:49 +01:00
|
|
|
request.add_child(data)
|
2022-10-15 20:56:30 +02:00
|
|
|
data.add_child(Node.s32("type", -1))
|
|
|
|
data.add_child(Node.s32("value", -1))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def handle_sysinfo_get_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("sysinfo")
|
|
|
|
trd = Node.void("trd")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(trd)
|
|
|
|
|
|
|
|
# Add event info
|
|
|
|
self.__add_event_info(trd)
|
|
|
|
|
|
|
|
return root
|
|
|
|
|
|
|
|
def handle_sysinfo_fan_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
sysinfo = Node.void("sysinfo")
|
|
|
|
sysinfo.add_child(Node.u8("pref", self.get_machine_region()))
|
|
|
|
sysinfo.add_child(Node.string("lid", request.child_value("lid")))
|
2019-12-08 22:43:49 +01:00
|
|
|
return sysinfo
|
|
|
|
|
|
|
|
def handle_lobby_entry_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("lobby")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Create a lobby entry for this user
|
2022-10-15 20:56:30 +02:00
|
|
|
extid = request.child_value("e/uid")
|
2019-12-08 22:43:49 +01:00
|
|
|
userid = self.data.remote.user.from_extid(self.game, self.version, extid)
|
|
|
|
if userid is not None:
|
|
|
|
profile = self.get_profile(userid)
|
|
|
|
self.data.local.lobby.put_lobby(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
userid,
|
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"mid": request.child_value("e/mid"),
|
|
|
|
"ng": request.child_value("e/ng"),
|
|
|
|
"lid": request.child_value("e/lid"),
|
|
|
|
"sn": request.child_value("e/sn"),
|
|
|
|
"pref": request.child_value("e/pref"),
|
|
|
|
"ga": request.child_value("e/ga"),
|
|
|
|
"gp": request.child_value("e/gp"),
|
|
|
|
"la": request.child_value("e/la"),
|
|
|
|
},
|
2019-12-08 22:43:49 +01:00
|
|
|
)
|
|
|
|
lobby = self.data.local.lobby.get_lobby(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
userid,
|
|
|
|
)
|
2022-10-15 20:56:30 +02:00
|
|
|
root.add_child(Node.s32("eid", lobby.get_int("id")))
|
|
|
|
e = Node.void("e")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(e)
|
2022-10-15 20:56:30 +02:00
|
|
|
e.add_child(Node.s32("eid", lobby.get_int("id")))
|
|
|
|
e.add_child(Node.u16("mid", lobby.get_int("mid")))
|
|
|
|
e.add_child(Node.u8("ng", lobby.get_int("ng")))
|
|
|
|
e.add_child(Node.s32("uid", profile.extid))
|
|
|
|
e.add_child(Node.string("pn", profile.get_str("name")))
|
|
|
|
e.add_child(Node.s32("exp", profile.get_int("exp")))
|
|
|
|
e.add_child(Node.u8("mg", profile.get_int("mg")))
|
|
|
|
e.add_child(Node.s32("tid", lobby.get_int("tid")))
|
|
|
|
e.add_child(Node.string("tn", lobby.get_str("tn")))
|
|
|
|
e.add_child(Node.string("lid", lobby.get_str("lid")))
|
|
|
|
e.add_child(Node.string("sn", lobby.get_str("sn")))
|
|
|
|
e.add_child(Node.u8("pref", lobby.get_int("pref")))
|
|
|
|
e.add_child(Node.u8_array("ga", lobby.get_int_array("ga", 4)))
|
|
|
|
e.add_child(Node.u16("gp", lobby.get_int("gp")))
|
|
|
|
e.add_child(Node.u8_array("la", lobby.get_int_array("la", 4)))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
return root
|
|
|
|
|
|
|
|
def handle_lobby_read_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("lobby")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Look up all lobbies matching the criteria specified
|
2022-10-15 20:56:30 +02:00
|
|
|
mg = request.child_value("m_grade") # noqa: F841
|
|
|
|
extid = request.child_value("uid")
|
|
|
|
limit = request.child_value("max")
|
2019-12-08 22:43:49 +01:00
|
|
|
userid = self.data.remote.user.from_extid(self.game, self.version, extid)
|
|
|
|
if userid is not None:
|
|
|
|
lobbies = self.data.local.lobby.get_all_lobbies(self.game, self.version)
|
|
|
|
for (user, lobby) in lobbies:
|
|
|
|
if limit <= 0:
|
|
|
|
break
|
|
|
|
|
|
|
|
if user == userid:
|
|
|
|
# If we have our own lobby, don't return it
|
|
|
|
continue
|
|
|
|
|
|
|
|
profile = self.get_profile(user)
|
|
|
|
if profile is None:
|
|
|
|
# No profile info, don't return this lobby
|
|
|
|
continue
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
e = Node.void("e")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(e)
|
2022-10-15 20:56:30 +02:00
|
|
|
e.add_child(Node.s32("eid", lobby.get_int("id")))
|
|
|
|
e.add_child(Node.u16("mid", lobby.get_int("mid")))
|
|
|
|
e.add_child(Node.u8("ng", lobby.get_int("ng")))
|
|
|
|
e.add_child(Node.s32("uid", profile.extid))
|
|
|
|
e.add_child(Node.string("pn", profile.get_str("name")))
|
|
|
|
e.add_child(Node.s32("exp", profile.get_int("exp")))
|
|
|
|
e.add_child(Node.u8("mg", profile.get_int("mg")))
|
|
|
|
e.add_child(Node.s32("tid", lobby.get_int("tid")))
|
|
|
|
e.add_child(Node.string("tn", lobby.get_str("tn")))
|
|
|
|
e.add_child(Node.string("lid", lobby.get_str("lid")))
|
|
|
|
e.add_child(Node.string("sn", lobby.get_str("sn")))
|
|
|
|
e.add_child(Node.u8("pref", lobby.get_int("pref")))
|
|
|
|
e.add_child(Node.u8_array("ga", lobby.get_int_array("ga", 4)))
|
|
|
|
e.add_child(Node.u16("gp", lobby.get_int("gp")))
|
|
|
|
e.add_child(Node.u8_array("la", lobby.get_int_array("la", 4)))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
limit = limit - 1
|
|
|
|
|
|
|
|
return root
|
|
|
|
|
|
|
|
def handle_lobby_delete_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
eid = request.child_value("eid")
|
2019-12-08 22:43:49 +01:00
|
|
|
self.data.local.lobby.destroy_lobby(eid)
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("lobby")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def handle_player_start_request(self, request: Node) -> Node:
|
|
|
|
# Add a dummy entry into the lobby setup so we can clean up on end play
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.child_value("rid")
|
2019-12-08 22:43:49 +01:00
|
|
|
userid = self.data.remote.user.from_refid(self.game, self.version, refid)
|
|
|
|
if userid is not None:
|
|
|
|
self.data.local.lobby.put_play_session_info(
|
2022-10-15 20:56:30 +02:00
|
|
|
self.game, self.version, userid, {}
|
2019-12-08 22:43:49 +01:00
|
|
|
)
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("player")
|
|
|
|
root.add_child(Node.bool("is_suc", True))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Add event info
|
|
|
|
self.__add_event_info(root)
|
|
|
|
|
|
|
|
return root
|
|
|
|
|
|
|
|
def handle_player_delete_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("player")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def handle_player_end_request(self, request: Node) -> Node:
|
|
|
|
# Destroy play session based on info from the request
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.child_value("rid")
|
2019-12-08 22:43:49 +01:00
|
|
|
userid = self.data.remote.user.from_refid(self.game, self.version, refid)
|
|
|
|
if userid is not None:
|
|
|
|
# Kill any lingering lobbies by this user
|
|
|
|
lobby = self.data.local.lobby.get_lobby(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
userid,
|
|
|
|
)
|
|
|
|
if lobby is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
self.data.local.lobby.destroy_lobby(lobby.get_int("id"))
|
|
|
|
self.data.local.lobby.destroy_play_session_info(
|
|
|
|
self.game, self.version, userid
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("player")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def handle_player_read_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.child_value("rid")
|
2019-12-08 22:43:49 +01:00
|
|
|
profile = self.get_profile_by_refid(refid)
|
|
|
|
if profile:
|
|
|
|
return profile
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("player")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def handle_player_write_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.child_value("rid")
|
2019-12-08 22:43:49 +01:00
|
|
|
profile = self.put_profile_by_refid(refid, request)
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("player")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
if profile is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
root.add_child(Node.s32("uid", 0))
|
2019-12-08 22:43:49 +01:00
|
|
|
else:
|
2022-10-15 20:56:30 +02:00
|
|
|
root.add_child(Node.s32("uid", profile.extid))
|
|
|
|
root.add_child(Node.s32("time", Time.now()))
|
2019-12-08 22:43:49 +01:00
|
|
|
return root
|
|
|
|
|
2021-08-20 06:43:13 +02:00
|
|
|
def format_profile(self, userid: UserID, profile: Profile) -> Node:
|
2019-12-08 22:43:49 +01:00
|
|
|
statistics = self.get_play_statistics(userid)
|
|
|
|
game_config = self.get_game_config()
|
2022-10-15 20:56:30 +02:00
|
|
|
achievements = self.data.local.user.get_achievements(
|
|
|
|
self.game, self.version, userid
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
scores = self.data.remote.music.get_scores(self.game, self.version, userid)
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("player")
|
|
|
|
pdata = Node.void("pdata")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(pdata)
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
base = Node.void("base")
|
2019-12-08 22:43:49 +01:00
|
|
|
pdata.add_child(base)
|
2022-10-15 20:56:30 +02:00
|
|
|
base.add_child(Node.s32("uid", profile.extid))
|
|
|
|
base.add_child(Node.string("name", profile.get_str("name")))
|
|
|
|
base.add_child(Node.s16("lv", profile.get_int("lvl")))
|
|
|
|
base.add_child(Node.s32("exp", profile.get_int("exp")))
|
|
|
|
base.add_child(Node.s16("mg", profile.get_int("mg")))
|
|
|
|
base.add_child(Node.s16("ap", profile.get_int("ap")))
|
|
|
|
base.add_child(Node.s32("flag", profile.get_int("flag")))
|
|
|
|
|
|
|
|
con = Node.void("con")
|
2019-12-08 22:43:49 +01:00
|
|
|
pdata.add_child(con)
|
2022-10-15 20:56:30 +02:00
|
|
|
con.add_child(Node.s32("day", statistics.today_plays))
|
|
|
|
con.add_child(Node.s32("cnt", statistics.total_plays))
|
|
|
|
con.add_child(Node.s32("last", statistics.last_play_timestamp))
|
|
|
|
con.add_child(Node.s32("now", Time.now()))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
team = Node.void("team")
|
2019-12-08 22:43:49 +01:00
|
|
|
pdata.add_child(team)
|
2022-10-15 20:56:30 +02:00
|
|
|
team.add_child(Node.s32("id", -1))
|
|
|
|
team.add_child(Node.string("name", ""))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
custom = Node.void("custom")
|
|
|
|
customdict = profile.get_dict("custom")
|
2019-12-08 22:43:49 +01:00
|
|
|
pdata.add_child(custom)
|
2022-10-15 20:56:30 +02:00
|
|
|
custom.add_child(Node.u8("bgm_m", customdict.get_int("bgm_m")))
|
|
|
|
custom.add_child(Node.u8("st_f", customdict.get_int("st_f")))
|
|
|
|
custom.add_child(Node.u8("st_bg", customdict.get_int("st_bg")))
|
|
|
|
custom.add_child(Node.u8("st_bg_b", customdict.get_int("st_bg_b")))
|
|
|
|
custom.add_child(Node.u8("eff_e", customdict.get_int("eff_e")))
|
|
|
|
custom.add_child(Node.u8("se_s", customdict.get_int("se_s")))
|
|
|
|
custom.add_child(Node.u8("se_s_v", customdict.get_int("se_s_v")))
|
|
|
|
|
|
|
|
released = Node.void("released")
|
2019-12-08 22:43:49 +01:00
|
|
|
pdata.add_child(released)
|
|
|
|
|
|
|
|
for item in achievements:
|
2022-10-15 20:56:30 +02:00
|
|
|
if item.type[:5] != "item_":
|
2019-12-08 22:43:49 +01:00
|
|
|
continue
|
|
|
|
itemtype = int(item.type[5:])
|
2022-10-15 20:56:30 +02:00
|
|
|
if game_config.get_bool("force_unlock_songs") and itemtype == 0:
|
2019-12-08 22:43:49 +01:00
|
|
|
# Don't echo unlocks when we're force unlocking, we'll do it later
|
|
|
|
continue
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
info = Node.void("info")
|
2019-12-08 22:43:49 +01:00
|
|
|
released.add_child(info)
|
2022-10-15 20:56:30 +02:00
|
|
|
info.add_child(Node.u8("type", itemtype))
|
|
|
|
info.add_child(Node.u16("id", item.id))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
if game_config.get_bool("force_unlock_songs"):
|
|
|
|
songs = {
|
|
|
|
song.id
|
|
|
|
for song in self.data.local.music.get_all_songs(self.game, self.version)
|
|
|
|
}
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
for songid in songs:
|
2022-10-15 20:56:30 +02:00
|
|
|
info = Node.void("info")
|
2019-12-08 22:43:49 +01:00
|
|
|
released.add_child(info)
|
2022-10-15 20:56:30 +02:00
|
|
|
info.add_child(Node.u8("type", 0))
|
|
|
|
info.add_child(Node.u16("id", songid))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Scores
|
2022-10-15 20:56:30 +02:00
|
|
|
record = Node.void("record")
|
2019-12-08 22:43:49 +01:00
|
|
|
pdata.add_child(record)
|
|
|
|
|
|
|
|
for score in scores:
|
2022-10-15 20:56:30 +02:00
|
|
|
rec = Node.void("rec")
|
2019-12-08 22:43:49 +01:00
|
|
|
record.add_child(rec)
|
2022-10-15 20:56:30 +02:00
|
|
|
rec.add_child(Node.u16("mid", score.id))
|
|
|
|
rec.add_child(Node.u8("ng", score.chart))
|
|
|
|
rec.add_child(Node.s32("win", score.data.get_dict("stats").get_int("win")))
|
|
|
|
rec.add_child(
|
|
|
|
Node.s32("lose", score.data.get_dict("stats").get_int("lose"))
|
|
|
|
)
|
|
|
|
rec.add_child(
|
|
|
|
Node.s32("draw", score.data.get_dict("stats").get_int("draw"))
|
|
|
|
)
|
|
|
|
rec.add_child(
|
|
|
|
Node.u8(
|
|
|
|
"ct",
|
|
|
|
self.__db_to_game_clear_type(
|
|
|
|
score.data.get_int("clear_type"),
|
|
|
|
score.data.get_int("combo_type"),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
rec.add_child(
|
|
|
|
Node.s16("ar", int(score.data.get_int("achievement_rate") / 10))
|
|
|
|
)
|
|
|
|
rec.add_child(Node.s16("bs", score.points))
|
|
|
|
rec.add_child(Node.s16("mc", score.data.get_int("combo")))
|
|
|
|
rec.add_child(Node.s16("bmc", score.data.get_int("miss_count")))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# In original ReflecBeat, the entire battle log was returned for each battle.
|
|
|
|
# We don't support storing all of that info, so don't return anything here.
|
2022-10-15 20:56:30 +02:00
|
|
|
blog = Node.void("blog")
|
2019-12-08 22:43:49 +01:00
|
|
|
pdata.add_child(blog)
|
|
|
|
|
|
|
|
# Comment (seems unused?)
|
2022-10-15 20:56:30 +02:00
|
|
|
pdata.add_child(Node.string("cmnt", ""))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
return root
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
def unformat_profile(
|
|
|
|
self, userid: UserID, request: Node, oldprofile: Profile
|
|
|
|
) -> Profile:
|
2019-12-08 22:43:49 +01:00
|
|
|
game_config = self.get_game_config()
|
2021-09-07 19:56:15 +02:00
|
|
|
newprofile = oldprofile.clone()
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
newprofile.replace_int("lid", ID.parse_machine_id(request.child_value("lid")))
|
|
|
|
newprofile.replace_str("name", request.child_value("pdata/base/name"))
|
|
|
|
newprofile.replace_int("lvl", request.child_value("pdata/base/lv"))
|
|
|
|
newprofile.replace_int("exp", request.child_value("pdata/base/exp"))
|
|
|
|
newprofile.replace_int("mg", request.child_value("pdata/base/mg"))
|
|
|
|
newprofile.replace_int("ap", request.child_value("pdata/base/ap"))
|
|
|
|
newprofile.replace_int("flag", request.child_value("pdata/base/flag"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
customdict = newprofile.get_dict("custom")
|
|
|
|
custom = request.child("pdata/custom")
|
2019-12-08 22:43:49 +01:00
|
|
|
if custom:
|
2022-10-15 20:56:30 +02:00
|
|
|
customdict.replace_int("bgm_m", custom.child_value("bgm_m"))
|
|
|
|
customdict.replace_int("st_f", custom.child_value("st_f"))
|
|
|
|
customdict.replace_int("st_bg", custom.child_value("st_bg"))
|
|
|
|
customdict.replace_int("st_bg_b", custom.child_value("st_bg_b"))
|
|
|
|
customdict.replace_int("eff_e", custom.child_value("eff_e"))
|
|
|
|
customdict.replace_int("se_s", custom.child_value("se_s"))
|
|
|
|
customdict.replace_int("se_s_v", custom.child_value("se_s_v"))
|
|
|
|
newprofile.replace_dict("custom", customdict)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Music unlocks and other stuff
|
2022-10-15 20:56:30 +02:00
|
|
|
released = request.child("pdata/released")
|
2019-12-08 22:43:49 +01:00
|
|
|
if released:
|
|
|
|
for child in released.children:
|
2022-10-15 20:56:30 +02:00
|
|
|
if child.name != "info":
|
2019-12-08 22:43:49 +01:00
|
|
|
continue
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
item_id = child.child_value("id")
|
|
|
|
item_type = child.child_value("type")
|
|
|
|
if game_config.get_bool("force_unlock_songs") and item_type == 0:
|
2019-12-08 22:43:49 +01:00
|
|
|
# Don't save unlocks when we're force unlocking
|
|
|
|
continue
|
|
|
|
|
|
|
|
self.data.local.user.put_achievement(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
userid,
|
|
|
|
item_id,
|
2022-10-15 20:56:30 +02:00
|
|
|
f"item_{item_type}",
|
2019-12-08 22:43:49 +01:00
|
|
|
{},
|
|
|
|
)
|
|
|
|
|
|
|
|
# Grab any new records set during this play session. Reflec Beat original only sends
|
|
|
|
# the top record back for songs that were played at least once during the session.
|
|
|
|
# Note that it sends the top record, so if you play the song twice, it will return
|
|
|
|
# only one record. Also, if you get a lower score than a previous try, it will return
|
|
|
|
# the previous try. So, we must also look at the battle log for the actual play scores,
|
|
|
|
# and combine the data if we can.
|
|
|
|
savedrecords: Dict[int, Dict[int, Dict[str, int]]] = {}
|
2022-10-15 20:56:30 +02:00
|
|
|
songplays = request.child("pdata/record")
|
2019-12-08 22:43:49 +01:00
|
|
|
if songplays:
|
|
|
|
for child in songplays.children:
|
2022-10-15 20:56:30 +02:00
|
|
|
if child.name != "rec":
|
2019-12-08 22:43:49 +01:00
|
|
|
continue
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
songid = child.child_value("mid")
|
|
|
|
chart = child.child_value("ng")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# These don't get sent with the battle logs, so we try to construct
|
|
|
|
# the values here.
|
|
|
|
if songid not in savedrecords:
|
|
|
|
savedrecords[songid] = {}
|
|
|
|
savedrecords[songid][chart] = {
|
2022-10-15 20:56:30 +02:00
|
|
|
"achievement_rate": child.child_value("ar") * 10,
|
|
|
|
"points": child.child_value("bs"),
|
|
|
|
"combo": child.child_value("mc"),
|
|
|
|
"miss_count": child.child_value("bmc"),
|
|
|
|
"win": child.child_value("win"),
|
|
|
|
"lose": child.child_value("lose"),
|
|
|
|
"draw": child.child_value("draw"),
|
2019-12-08 22:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Now, see the actual battles that were played. If we can, unify the data with a record.
|
|
|
|
# We only do that when the record achievement rate and score matches the battle achievement
|
|
|
|
# rate and score, so we know for a fact that that record was generated by this battle.
|
2022-10-15 20:56:30 +02:00
|
|
|
battlelogs = request.child("pdata/blog")
|
2019-12-08 22:43:49 +01:00
|
|
|
if battlelogs:
|
|
|
|
for child in battlelogs.children:
|
2022-10-15 20:56:30 +02:00
|
|
|
if child.name != "log":
|
2019-12-08 22:43:49 +01:00
|
|
|
continue
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
songid = child.child_value("mid")
|
|
|
|
chart = child.child_value("ng")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
clear_type = child.child_value("myself/ct")
|
|
|
|
achievement_rate = child.child_value("myself/ar") * 10
|
|
|
|
points = child.child_value("myself/s")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
clear_type, combo_type = self.__game_to_db_clear_type(
|
|
|
|
clear_type, achievement_rate
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
combo = None
|
|
|
|
miss_count = -1
|
|
|
|
stats = None
|
|
|
|
|
|
|
|
if songid in savedrecords:
|
|
|
|
if chart in savedrecords[songid]:
|
|
|
|
data = savedrecords[songid][chart]
|
|
|
|
|
|
|
|
if (
|
2022-10-15 20:56:30 +02:00
|
|
|
data["achievement_rate"] == achievement_rate
|
|
|
|
and data["points"] == points
|
2019-12-08 22:43:49 +01:00
|
|
|
):
|
|
|
|
# This is the same record! Use the stats from it to update our
|
|
|
|
# internal representation.
|
2022-10-15 20:56:30 +02:00
|
|
|
combo = data["combo"]
|
|
|
|
miss_count = data["miss_count"]
|
2019-12-08 22:43:49 +01:00
|
|
|
stats = {
|
2022-10-15 20:56:30 +02:00
|
|
|
"win": data["win"],
|
|
|
|
"lose": data["lose"],
|
|
|
|
"draw": data["draw"],
|
2019-12-08 22:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
self.update_score(
|
|
|
|
userid,
|
|
|
|
songid,
|
|
|
|
chart,
|
|
|
|
points,
|
|
|
|
achievement_rate,
|
|
|
|
clear_type,
|
|
|
|
combo_type,
|
|
|
|
miss_count,
|
|
|
|
combo=combo,
|
|
|
|
stats=stats,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Keep track of play statistics
|
|
|
|
self.update_play_statistics(userid)
|
|
|
|
|
|
|
|
return newprofile
|