2019-12-08 22:43:49 +01:00
|
|
|
# vim: set fileencoding=utf-8
|
|
|
|
from typing import Dict, List, Optional, Union
|
2021-09-07 19:56:15 +02:00
|
|
|
from typing_extensions import Final
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
from bemani.backend.ddr.base import DDRBase
|
|
|
|
from bemani.backend.ddr.ddrx2 import DDRX2
|
|
|
|
from bemani.backend.ddr.common import (
|
|
|
|
DDRGameAreaHiscoreHandler,
|
|
|
|
DDRGameFriendHandler,
|
|
|
|
DDRGameHiscoreHandler,
|
|
|
|
DDRGameLoadCourseHandler,
|
|
|
|
DDRGameLoadDailyHandler,
|
|
|
|
DDRGameLoadHandler,
|
|
|
|
DDRGameLockHandler,
|
|
|
|
DDRGameLogHandler,
|
|
|
|
DDRGameMessageHandler,
|
|
|
|
DDRGameNewHandler,
|
|
|
|
DDRGameOldHandler,
|
|
|
|
DDRGameRankingHandler,
|
|
|
|
DDRGameSaveCourseHandler,
|
|
|
|
DDRGameSaveHandler,
|
|
|
|
DDRGameScoreHandler,
|
|
|
|
DDRGameShopHandler,
|
|
|
|
DDRGameTraceHandler,
|
|
|
|
)
|
2021-08-20 06:43:13 +02:00
|
|
|
from bemani.common import Profile, VersionConstants, Time, intish
|
2019-12-08 22:43:49 +01:00
|
|
|
from bemani.data import Achievement, Score, UserID
|
|
|
|
from bemani.protocol import Node
|
|
|
|
|
|
|
|
|
|
|
|
class DDRX3(
|
|
|
|
DDRGameAreaHiscoreHandler,
|
|
|
|
DDRGameFriendHandler,
|
|
|
|
DDRGameHiscoreHandler,
|
|
|
|
DDRGameLockHandler,
|
|
|
|
DDRGameLoadCourseHandler,
|
|
|
|
DDRGameLoadDailyHandler,
|
|
|
|
DDRGameLoadHandler,
|
|
|
|
DDRGameLogHandler,
|
|
|
|
DDRGameMessageHandler,
|
|
|
|
DDRGameNewHandler,
|
|
|
|
DDRGameOldHandler,
|
|
|
|
DDRGameRankingHandler,
|
|
|
|
DDRGameSaveCourseHandler,
|
|
|
|
DDRGameSaveHandler,
|
|
|
|
DDRGameScoreHandler,
|
|
|
|
DDRGameShopHandler,
|
|
|
|
DDRGameTraceHandler,
|
|
|
|
DDRBase,
|
|
|
|
):
|
2022-10-15 20:56:30 +02:00
|
|
|
name: str = "DanceDanceRevolution X3 VS 2ndMIX"
|
2021-09-07 19:56:15 +02:00
|
|
|
version: int = VersionConstants.DDR_X3_VS_2NDMIX
|
|
|
|
|
|
|
|
GAME_STYLE_SINGLE: Final[int] = 0
|
|
|
|
GAME_STYLE_DOUBLE: Final[int] = 1
|
|
|
|
GAME_STYLE_VERSUS: Final[int] = 2
|
|
|
|
|
|
|
|
GAME_RANK_AAA: Final[int] = 1
|
|
|
|
GAME_RANK_AA: Final[int] = 2
|
|
|
|
GAME_RANK_A: Final[int] = 3
|
|
|
|
GAME_RANK_B: Final[int] = 4
|
|
|
|
GAME_RANK_C: Final[int] = 5
|
|
|
|
GAME_RANK_D: Final[int] = 6
|
|
|
|
GAME_RANK_E: Final[int] = 7
|
|
|
|
|
|
|
|
GAME_CHART_SINGLE_BEGINNER: Final[int] = 0
|
|
|
|
GAME_CHART_SINGLE_BASIC: Final[int] = 1
|
|
|
|
GAME_CHART_SINGLE_DIFFICULT: Final[int] = 2
|
|
|
|
GAME_CHART_SINGLE_EXPERT: Final[int] = 3
|
|
|
|
GAME_CHART_SINGLE_CHALLENGE: Final[int] = 4
|
|
|
|
GAME_CHART_DOUBLE_BASIC: Final[int] = 5
|
|
|
|
GAME_CHART_DOUBLE_DIFFICULT: Final[int] = 6
|
|
|
|
GAME_CHART_DOUBLE_EXPERT: Final[int] = 7
|
|
|
|
GAME_CHART_DOUBLE_CHALLENGE: Final[int] = 8
|
|
|
|
|
|
|
|
GAME_HALO_NONE: Final[int] = 0
|
|
|
|
GAME_HALO_FULL_COMBO: Final[int] = 1
|
|
|
|
GAME_HALO_PERFECT_COMBO: Final[int] = 2
|
|
|
|
GAME_HALO_MARVELOUS_COMBO: Final[int] = 3
|
|
|
|
|
|
|
|
GAME_PLAY_MODE_NORMAL: Final[int] = 1
|
|
|
|
GAME_PLAY_MODE_2NDMIX: Final[int] = 5
|
|
|
|
|
|
|
|
GAME_MAX_SONGS: Final[int] = 700
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def previous_version(self) -> Optional[DDRBase]:
|
|
|
|
return DDRX2(self.data, self.config, self.model)
|
|
|
|
|
|
|
|
def game_to_db_rank(self, game_rank: int) -> int:
|
|
|
|
return {
|
|
|
|
self.GAME_RANK_AAA: self.RANK_AAA,
|
|
|
|
self.GAME_RANK_AA: self.RANK_AA,
|
|
|
|
self.GAME_RANK_A: self.RANK_A,
|
|
|
|
self.GAME_RANK_B: self.RANK_B,
|
|
|
|
self.GAME_RANK_C: self.RANK_C,
|
|
|
|
self.GAME_RANK_D: self.RANK_D,
|
|
|
|
self.GAME_RANK_E: self.RANK_E,
|
|
|
|
}[game_rank]
|
|
|
|
|
|
|
|
def db_to_game_rank(self, db_rank: int) -> int:
|
|
|
|
return {
|
|
|
|
self.RANK_AAA: self.GAME_RANK_AAA,
|
|
|
|
self.RANK_AA_PLUS: self.GAME_RANK_AA,
|
|
|
|
self.RANK_AA: self.GAME_RANK_AA,
|
|
|
|
self.RANK_AA_MINUS: self.GAME_RANK_A,
|
|
|
|
self.RANK_A_PLUS: self.GAME_RANK_A,
|
|
|
|
self.RANK_A: self.GAME_RANK_A,
|
|
|
|
self.RANK_A_MINUS: self.GAME_RANK_B,
|
|
|
|
self.RANK_B_PLUS: self.GAME_RANK_B,
|
|
|
|
self.RANK_B: self.GAME_RANK_B,
|
|
|
|
self.RANK_B_MINUS: self.GAME_RANK_C,
|
|
|
|
self.RANK_C_PLUS: self.GAME_RANK_C,
|
|
|
|
self.RANK_C: self.GAME_RANK_C,
|
|
|
|
self.RANK_C_MINUS: self.GAME_RANK_D,
|
|
|
|
self.RANK_D_PLUS: self.GAME_RANK_D,
|
|
|
|
self.RANK_D: self.GAME_RANK_D,
|
|
|
|
self.RANK_E: self.GAME_RANK_E,
|
|
|
|
}[db_rank]
|
|
|
|
|
|
|
|
def game_to_db_chart(self, game_chart: int) -> int:
|
|
|
|
return {
|
|
|
|
self.GAME_CHART_SINGLE_BEGINNER: self.CHART_SINGLE_BEGINNER,
|
|
|
|
self.GAME_CHART_SINGLE_BASIC: self.CHART_SINGLE_BASIC,
|
|
|
|
self.GAME_CHART_SINGLE_DIFFICULT: self.CHART_SINGLE_DIFFICULT,
|
|
|
|
self.GAME_CHART_SINGLE_EXPERT: self.CHART_SINGLE_EXPERT,
|
|
|
|
self.GAME_CHART_SINGLE_CHALLENGE: self.CHART_SINGLE_CHALLENGE,
|
|
|
|
self.GAME_CHART_DOUBLE_BASIC: self.CHART_DOUBLE_BASIC,
|
|
|
|
self.GAME_CHART_DOUBLE_DIFFICULT: self.CHART_DOUBLE_DIFFICULT,
|
|
|
|
self.GAME_CHART_DOUBLE_EXPERT: self.CHART_DOUBLE_EXPERT,
|
|
|
|
self.GAME_CHART_DOUBLE_CHALLENGE: self.CHART_DOUBLE_CHALLENGE,
|
|
|
|
}[game_chart]
|
|
|
|
|
|
|
|
def db_to_game_chart(self, db_chart: int) -> int:
|
|
|
|
return {
|
|
|
|
self.CHART_SINGLE_BEGINNER: self.GAME_CHART_SINGLE_BEGINNER,
|
|
|
|
self.CHART_SINGLE_BASIC: self.GAME_CHART_SINGLE_BASIC,
|
|
|
|
self.CHART_SINGLE_DIFFICULT: self.GAME_CHART_SINGLE_DIFFICULT,
|
|
|
|
self.CHART_SINGLE_EXPERT: self.GAME_CHART_SINGLE_EXPERT,
|
|
|
|
self.CHART_SINGLE_CHALLENGE: self.GAME_CHART_SINGLE_CHALLENGE,
|
|
|
|
self.CHART_DOUBLE_BASIC: self.GAME_CHART_DOUBLE_BASIC,
|
|
|
|
self.CHART_DOUBLE_DIFFICULT: self.GAME_CHART_DOUBLE_DIFFICULT,
|
|
|
|
self.CHART_DOUBLE_EXPERT: self.GAME_CHART_DOUBLE_EXPERT,
|
|
|
|
self.CHART_DOUBLE_CHALLENGE: self.GAME_CHART_DOUBLE_CHALLENGE,
|
|
|
|
}[db_chart]
|
|
|
|
|
|
|
|
def db_to_game_halo(self, db_halo: int) -> int:
|
|
|
|
if db_halo == self.HALO_MARVELOUS_FULL_COMBO:
|
|
|
|
combo_type = self.GAME_HALO_MARVELOUS_COMBO
|
|
|
|
elif db_halo == self.HALO_PERFECT_FULL_COMBO:
|
|
|
|
combo_type = self.GAME_HALO_PERFECT_COMBO
|
|
|
|
elif db_halo == self.HALO_GREAT_FULL_COMBO:
|
|
|
|
combo_type = self.GAME_HALO_FULL_COMBO
|
|
|
|
else:
|
|
|
|
combo_type = self.GAME_HALO_NONE
|
|
|
|
return combo_type
|
|
|
|
|
|
|
|
def handle_game_common_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
for flagid in range(256):
|
2022-10-15 20:56:30 +02:00
|
|
|
flag = Node.void("flag")
|
2019-12-08 22:43:49 +01:00
|
|
|
game.add_child(flag)
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
flag.set_attribute("id", str(flagid))
|
|
|
|
flag.set_attribute("s2", "0")
|
|
|
|
flag.set_attribute("s1", "0")
|
|
|
|
flag.set_attribute("t", "0")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
hit_chart = self.data.local.music.get_hit_chart(
|
|
|
|
self.game, self.music_version, self.GAME_MAX_SONGS
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
counts_by_reflink = [0] * self.GAME_MAX_SONGS
|
2023-02-17 04:02:41 +01:00
|
|
|
for reflink, plays in hit_chart:
|
2019-12-08 22:43:49 +01:00
|
|
|
if reflink >= 0 and reflink < self.GAME_MAX_SONGS:
|
|
|
|
counts_by_reflink[reflink] = plays
|
2022-10-15 20:56:30 +02:00
|
|
|
game.add_child(Node.u32_array("cnt_music", counts_by_reflink))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
return game
|
|
|
|
|
|
|
|
def handle_game_load_m_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
extid = intish(request.attribute("code"))
|
|
|
|
refid = request.attribute("refid")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
if extid is not None:
|
|
|
|
# Rival score loading
|
|
|
|
userid = self.data.remote.user.from_extid(self.game, self.version, extid)
|
|
|
|
else:
|
|
|
|
# Self score loading
|
|
|
|
userid = self.data.remote.user.from_refid(self.game, self.version, refid)
|
|
|
|
|
|
|
|
if userid is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
scores = self.data.remote.music.get_scores(
|
|
|
|
self.game, self.music_version, userid
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
old_scores = [
|
2022-10-15 20:56:30 +02:00
|
|
|
score
|
|
|
|
for score in self.data.local.user.get_achievements(
|
|
|
|
self.game, self.music_version, userid
|
|
|
|
)
|
|
|
|
if score.type == "2ndmix"
|
2019-12-08 22:43:49 +01:00
|
|
|
]
|
|
|
|
else:
|
|
|
|
scores = []
|
|
|
|
old_scores = []
|
|
|
|
|
|
|
|
sortedscores: Dict[int, Dict[int, Dict[str, Union[Score, Achievement]]]] = {}
|
|
|
|
|
|
|
|
for score in scores:
|
|
|
|
if score.id not in sortedscores:
|
|
|
|
sortedscores[score.id] = {}
|
|
|
|
if score.chart not in sortedscores[score.id]:
|
|
|
|
sortedscores[score.id][score.chart] = {}
|
2022-10-15 20:56:30 +02:00
|
|
|
sortedscores[score.id][score.chart]["score"] = score
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
for oldscore in old_scores:
|
|
|
|
songid = int(oldscore.id / 100)
|
|
|
|
chart = int(oldscore.id % 100)
|
|
|
|
if songid not in sortedscores:
|
|
|
|
sortedscores[songid] = {}
|
|
|
|
if chart not in sortedscores[songid]:
|
|
|
|
sortedscores[songid][chart] = {}
|
2022-10-15 20:56:30 +02:00
|
|
|
sortedscores[songid][chart]["oldscore"] = oldscore
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
for song in sortedscores:
|
2022-10-15 20:56:30 +02:00
|
|
|
music = Node.void("music")
|
2019-12-08 22:43:49 +01:00
|
|
|
game.add_child(music)
|
2022-10-15 20:56:30 +02:00
|
|
|
music.set_attribute("reclink", str(song))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
for chart in sortedscores[song]:
|
|
|
|
try:
|
|
|
|
gamechart = self.db_to_game_chart(chart)
|
|
|
|
except KeyError:
|
|
|
|
# Don't support this chart in this game
|
|
|
|
continue
|
|
|
|
scoredict = sortedscores[song][chart]
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
if "score" in scoredict:
|
2019-12-08 22:43:49 +01:00
|
|
|
# We played the normal version of this song
|
2022-10-15 20:56:30 +02:00
|
|
|
gamerank = self.db_to_game_rank(
|
|
|
|
scoredict["score"].data.get_int("rank")
|
|
|
|
)
|
|
|
|
combo_type = self.db_to_game_halo(
|
|
|
|
scoredict["score"].data.get_int("halo")
|
|
|
|
)
|
|
|
|
points = scoredict["score"].points # type: ignore
|
|
|
|
plays = scoredict["score"].plays # type: ignore
|
2019-12-08 22:43:49 +01:00
|
|
|
else:
|
|
|
|
# We only played 2nd mix version of this song
|
|
|
|
gamerank = 0
|
|
|
|
combo_type = self.GAME_HALO_NONE
|
|
|
|
points = 0
|
|
|
|
plays = 0
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
if "oldscore" in scoredict:
|
2019-12-08 22:43:49 +01:00
|
|
|
# We played the 2nd mix version of this song
|
2022-10-15 20:56:30 +02:00
|
|
|
oldpoints = scoredict["oldscore"].data.get_int("points")
|
|
|
|
oldrank = scoredict["oldscore"].data.get_int("rank")
|
|
|
|
oldplays = scoredict["oldscore"].data.get_int("plays")
|
2019-12-08 22:43:49 +01:00
|
|
|
else:
|
|
|
|
oldpoints = 0
|
|
|
|
oldrank = 0
|
|
|
|
oldplays = 0
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
typenode = Node.void("type")
|
2019-12-08 22:43:49 +01:00
|
|
|
music.add_child(typenode)
|
2022-10-15 20:56:30 +02:00
|
|
|
typenode.set_attribute("diff", str(gamechart))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
typenode.add_child(Node.u32("score", points))
|
|
|
|
typenode.add_child(Node.u16("count", plays))
|
|
|
|
typenode.add_child(Node.u8("rank", gamerank))
|
|
|
|
typenode.add_child(Node.u8("combo_type", combo_type))
|
|
|
|
typenode.add_child(Node.u32("score_2nd", oldpoints))
|
|
|
|
typenode.add_child(Node.u8("rank_2nd", oldrank))
|
|
|
|
typenode.add_child(Node.u16("cnt_2nd", oldplays))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
return game
|
|
|
|
|
|
|
|
def handle_game_save_m_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.attribute("refid")
|
|
|
|
songid = int(request.attribute("mid"))
|
|
|
|
chart = self.game_to_db_chart(int(request.attribute("mtype")))
|
2019-12-08 22:43:49 +01:00
|
|
|
userid = self.data.remote.user.from_refid(self.game, self.version, refid)
|
|
|
|
|
|
|
|
# Calculate statistics
|
2022-10-15 20:56:30 +02:00
|
|
|
data = request.child("data")
|
|
|
|
playmode = int(data.attribute("playmode"))
|
2019-12-08 22:43:49 +01:00
|
|
|
if playmode == self.GAME_PLAY_MODE_2NDMIX:
|
|
|
|
if userid is not None:
|
|
|
|
# These are special cased and treated like achievements
|
2022-10-15 20:56:30 +02:00
|
|
|
points = int(data.attribute("score_2nd"))
|
|
|
|
combo = int(data.attribute("combo_2nd"))
|
|
|
|
rank = int(data.attribute("rank_2nd"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Grab the old 2nd mix score
|
|
|
|
existingscore = self.data.local.user.get_achievement(
|
|
|
|
self.game,
|
|
|
|
self.music_version,
|
|
|
|
userid,
|
|
|
|
(songid * 100) + chart,
|
2022-10-15 20:56:30 +02:00
|
|
|
"2ndmix",
|
2019-12-08 22:43:49 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
if existingscore is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
highscore = points > existingscore.get_int("points")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
plays = existingscore.get_int("plays", 0) + 1
|
|
|
|
points = max(points, existingscore.get_int("points"))
|
2019-12-08 22:43:49 +01:00
|
|
|
if not highscore:
|
2022-10-15 20:56:30 +02:00
|
|
|
combo = existingscore.get_int("combo", combo)
|
|
|
|
rank = existingscore.get_int("rank", rank)
|
2019-12-08 22:43:49 +01:00
|
|
|
else:
|
|
|
|
plays = 1
|
|
|
|
|
|
|
|
self.data.local.user.put_achievement(
|
|
|
|
self.game,
|
|
|
|
self.music_version,
|
|
|
|
userid,
|
|
|
|
(songid * 100) + chart,
|
2022-10-15 20:56:30 +02:00
|
|
|
"2ndmix",
|
2019-12-08 22:43:49 +01:00
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"points": points,
|
|
|
|
"combo": combo,
|
|
|
|
"rank": rank,
|
|
|
|
"plays": plays,
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
else:
|
2022-10-15 20:56:30 +02:00
|
|
|
points = int(data.attribute("score"))
|
|
|
|
combo = int(data.attribute("combo"))
|
|
|
|
rank = self.game_to_db_rank(int(data.attribute("rank")))
|
|
|
|
if int(data.attribute("full")) == 0:
|
2019-12-08 22:43:49 +01:00
|
|
|
halo = self.HALO_NONE
|
2022-10-15 20:56:30 +02:00
|
|
|
elif int(data.attribute("perf")) == 0:
|
2019-12-08 22:43:49 +01:00
|
|
|
halo = self.HALO_GREAT_FULL_COMBO
|
|
|
|
elif points < 1000000:
|
|
|
|
halo = self.HALO_PERFECT_FULL_COMBO
|
|
|
|
else:
|
|
|
|
halo = self.HALO_MARVELOUS_FULL_COMBO
|
2022-10-15 20:56:30 +02:00
|
|
|
trace = request.child_value("trace")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Save the score, regardless of whether we have a refid. If we save
|
|
|
|
# an anonymous score, it only goes into the DB to count against the
|
|
|
|
# number of plays for that song/chart.
|
|
|
|
self.update_score(
|
|
|
|
userid,
|
|
|
|
songid,
|
|
|
|
chart,
|
|
|
|
points,
|
|
|
|
rank,
|
|
|
|
halo,
|
|
|
|
combo,
|
|
|
|
trace,
|
|
|
|
)
|
|
|
|
|
|
|
|
# No response needed
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
return game
|
|
|
|
|
2021-08-20 06:43:13 +02:00
|
|
|
def format_profile(self, userid: UserID, profile: Profile) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Look up play stats we bridge to every mix
|
|
|
|
play_stats = self.get_play_statistics(userid)
|
|
|
|
|
|
|
|
# Basic game settings
|
2022-10-15 20:56:30 +02:00
|
|
|
root.add_child(Node.string("seq", ""))
|
|
|
|
root.add_child(Node.u32("code", profile.extid))
|
|
|
|
root.add_child(Node.string("name", profile.get_str("name")))
|
|
|
|
root.add_child(
|
|
|
|
Node.u8("area", profile.get_int("area", self.get_machine_region()))
|
|
|
|
)
|
|
|
|
root.add_child(Node.u32("cnt_s", play_stats.get_int("single_plays")))
|
|
|
|
root.add_child(Node.u32("cnt_d", play_stats.get_int("double_plays")))
|
|
|
|
root.add_child(
|
|
|
|
Node.u32("cnt_b", play_stats.get_int("battle_plays"))
|
|
|
|
) # This could be wrong, its a guess
|
|
|
|
root.add_child(Node.u32("cnt_m0", play_stats.get_int("cnt_m0")))
|
|
|
|
root.add_child(Node.u32("cnt_m1", play_stats.get_int("cnt_m1")))
|
|
|
|
root.add_child(Node.u32("cnt_m2", play_stats.get_int("cnt_m2")))
|
|
|
|
root.add_child(Node.u32("cnt_m3", play_stats.get_int("cnt_m3")))
|
|
|
|
root.add_child(Node.u32("cnt_m4", play_stats.get_int("cnt_m4")))
|
|
|
|
root.add_child(Node.u32("cnt_m5", play_stats.get_int("cnt_m5")))
|
|
|
|
root.add_child(Node.u32("exp", play_stats.get_int("exp")))
|
|
|
|
root.add_child(Node.u32("exp_o", profile.get_int("exp_o")))
|
|
|
|
root.add_child(Node.u32("star", profile.get_int("star")))
|
|
|
|
root.add_child(Node.u32("star_c", profile.get_int("star_c")))
|
|
|
|
root.add_child(Node.u8("combo", profile.get_int("combo", 0)))
|
|
|
|
root.add_child(Node.u8("timing_diff", profile.get_int("early_late", 0)))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Character stuff
|
2022-10-15 20:56:30 +02:00
|
|
|
chara = Node.void("chara")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(chara)
|
2022-10-15 20:56:30 +02:00
|
|
|
chara.set_attribute("my", str(profile.get_int("chara", 30)))
|
|
|
|
root.add_child(
|
|
|
|
Node.u16_array(
|
|
|
|
"chara_opt", profile.get_int_array("chara_opt", 96, [208] * 96)
|
|
|
|
)
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Drill rankings
|
2022-10-15 20:56:30 +02:00
|
|
|
if "title_gr" in profile:
|
|
|
|
title_gr = Node.void("title_gr")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(title_gr)
|
2022-10-15 20:56:30 +02:00
|
|
|
title_grdict = profile.get_dict("title_gr")
|
|
|
|
if "t" in title_grdict:
|
|
|
|
title_gr.set_attribute("t", str(title_grdict.get_int("t")))
|
|
|
|
if "s" in title_grdict:
|
|
|
|
title_gr.set_attribute("s", str(title_grdict.get_int("s")))
|
|
|
|
if "d" in title_grdict:
|
|
|
|
title_gr.set_attribute("d", str(title_grdict.get_int("d")))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Calorie mode
|
2022-10-15 20:56:30 +02:00
|
|
|
if "weight" in profile:
|
2019-12-08 22:43:49 +01:00
|
|
|
workouts = self.data.local.user.get_time_based_achievements(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
userid,
|
2022-10-15 20:56:30 +02:00
|
|
|
achievementtype="workout",
|
2019-12-08 22:43:49 +01:00
|
|
|
since=Time.now() - Time.SECONDS_IN_DAY,
|
|
|
|
)
|
2022-10-15 20:56:30 +02:00
|
|
|
total = sum([w.data.get_int("calories") for w in workouts])
|
|
|
|
workout = Node.void("workout")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(workout)
|
2022-10-15 20:56:30 +02:00
|
|
|
workout.set_attribute("weight", str(profile.get_int("weight")))
|
|
|
|
workout.set_attribute("day", str(total))
|
|
|
|
workout.set_attribute("disp", "1")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Daily play counts
|
2022-10-15 20:56:30 +02:00
|
|
|
daycount = Node.void("daycount")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(daycount)
|
2022-10-15 20:56:30 +02:00
|
|
|
daycount.set_attribute("playcount", str(play_stats.today_plays))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Daily combo stuff, unknown how this works
|
2022-10-15 20:56:30 +02:00
|
|
|
dailycombo = Node.void("dailycombo")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(dailycombo)
|
2022-10-15 20:56:30 +02:00
|
|
|
dailycombo.set_attribute("daily_combo", str(0))
|
|
|
|
dailycombo.set_attribute("daily_combo_lv", str(0))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Last cursor settings
|
2022-10-15 20:56:30 +02:00
|
|
|
last = Node.void("last")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(last)
|
2022-10-15 20:56:30 +02:00
|
|
|
lastdict = profile.get_dict("last")
|
|
|
|
last.set_attribute("rival1", str(lastdict.get_int("rival1", -1)))
|
|
|
|
last.set_attribute("rival2", str(lastdict.get_int("rival2", -1)))
|
|
|
|
last.set_attribute("rival3", str(lastdict.get_int("rival3", -1)))
|
|
|
|
last.set_attribute(
|
|
|
|
"fri", str(lastdict.get_int("rival1", -1))
|
|
|
|
) # This literally goes to the same memory in X3
|
|
|
|
last.set_attribute("style", str(lastdict.get_int("style")))
|
|
|
|
last.set_attribute("mode", str(lastdict.get_int("mode")))
|
|
|
|
last.set_attribute("cate", str(lastdict.get_int("cate")))
|
|
|
|
last.set_attribute("sort", str(lastdict.get_int("sort")))
|
|
|
|
last.set_attribute("mid", str(lastdict.get_int("mid")))
|
|
|
|
last.set_attribute("mtype", str(lastdict.get_int("mtype")))
|
|
|
|
last.set_attribute("cid", str(lastdict.get_int("cid")))
|
|
|
|
last.set_attribute("ctype", str(lastdict.get_int("ctype")))
|
|
|
|
last.set_attribute("sid", str(lastdict.get_int("sid")))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Result stars
|
2022-10-15 20:56:30 +02:00
|
|
|
result_star = Node.void("result_star")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(result_star)
|
2022-10-15 20:56:30 +02:00
|
|
|
result_stars = profile.get_int_array("result_stars", 9)
|
2019-12-08 22:43:49 +01:00
|
|
|
for i in range(9):
|
2022-10-15 20:56:30 +02:00
|
|
|
result_star.set_attribute(f"slot{i + 1}", str(result_stars[i]))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Target stuff
|
2022-10-15 20:56:30 +02:00
|
|
|
target = Node.void("target")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(target)
|
2022-10-15 20:56:30 +02:00
|
|
|
target.set_attribute("flag", str(profile.get_int("target_flag")))
|
|
|
|
target.set_attribute("setnum", str(profile.get_int("target_setnum")))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Groove gauge level-ups
|
2022-10-15 20:56:30 +02:00
|
|
|
gr_s = Node.void("gr_s")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(gr_s)
|
|
|
|
index = 1
|
2022-10-15 20:56:30 +02:00
|
|
|
for entry in profile.get_int_array("gr_s", 5):
|
|
|
|
gr_s.set_attribute(f"gr{index}", str(entry))
|
2019-12-08 22:43:49 +01:00
|
|
|
index = index + 1
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
gr_d = Node.void("gr_d")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(gr_d)
|
|
|
|
index = 1
|
2022-10-15 20:56:30 +02:00
|
|
|
for entry in profile.get_int_array("gr_d", 5):
|
|
|
|
gr_d.set_attribute(f"gr{index}", str(entry))
|
2019-12-08 22:43:49 +01:00
|
|
|
index = index + 1
|
|
|
|
|
|
|
|
# Options in menus
|
2022-10-15 20:56:30 +02:00
|
|
|
root.add_child(Node.s16_array("opt", profile.get_int_array("opt", 16)))
|
|
|
|
root.add_child(Node.s16_array("opt_ex", profile.get_int_array("opt_ex", 16)))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Unlock flags
|
2022-10-15 20:56:30 +02:00
|
|
|
root.add_child(
|
|
|
|
Node.u8_array("flag", profile.get_int_array("flag", 256, [1] * 256))
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Ranking display?
|
2022-10-15 20:56:30 +02:00
|
|
|
root.add_child(Node.u16_array("rank", profile.get_int_array("rank", 100)))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Rivals
|
|
|
|
links = self.data.local.user.get_links(self.game, self.version, userid)
|
|
|
|
for link in links:
|
2022-10-15 20:56:30 +02:00
|
|
|
if link.type[:7] != "friend_":
|
2019-12-08 22:43:49 +01:00
|
|
|
continue
|
|
|
|
|
|
|
|
pos = int(link.type[7:])
|
|
|
|
friend = self.get_profile(link.other_userid)
|
|
|
|
play_stats = self.get_play_statistics(link.other_userid)
|
|
|
|
if friend is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
friendnode = Node.void("friend")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(friendnode)
|
2022-10-15 20:56:30 +02:00
|
|
|
friendnode.set_attribute("pos", str(pos))
|
|
|
|
friendnode.set_attribute("vs", "0")
|
|
|
|
friendnode.set_attribute("up", "0")
|
|
|
|
friendnode.add_child(Node.u32("code", friend.extid))
|
|
|
|
friendnode.add_child(Node.string("name", friend.get_str("name")))
|
|
|
|
friendnode.add_child(
|
|
|
|
Node.u8("area", friend.get_int("area", self.get_machine_region()))
|
|
|
|
)
|
|
|
|
friendnode.add_child(Node.u32("exp", play_stats.get_int("exp")))
|
|
|
|
friendnode.add_child(Node.u32("star", friend.get_int("star")))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Drill rankings
|
2022-10-15 20:56:30 +02:00
|
|
|
if "title" in friend:
|
|
|
|
title = Node.void("title")
|
2019-12-08 22:43:49 +01:00
|
|
|
friendnode.add_child(title)
|
2022-10-15 20:56:30 +02:00
|
|
|
titledict = friend.get_dict("title")
|
|
|
|
if "t" in titledict:
|
|
|
|
title.set_attribute("t", str(titledict.get_int("t")))
|
|
|
|
if "s" in titledict:
|
|
|
|
title.set_attribute("s", str(titledict.get_int("s")))
|
|
|
|
if "d" in titledict:
|
|
|
|
title.set_attribute("d", str(titledict.get_int("d")))
|
|
|
|
|
|
|
|
if "title_gr" in friend:
|
|
|
|
title_gr = Node.void("title_gr")
|
2019-12-08 22:43:49 +01:00
|
|
|
friendnode.add_child(title_gr)
|
2022-10-15 20:56:30 +02:00
|
|
|
title_grdict = friend.get_dict("title_gr")
|
|
|
|
if "t" in title_grdict:
|
|
|
|
title_gr.set_attribute("t", str(title_grdict.get_int("t")))
|
|
|
|
if "s" in title_grdict:
|
|
|
|
title_gr.set_attribute("s", str(title_grdict.get_int("s")))
|
|
|
|
if "d" in title_grdict:
|
|
|
|
title_gr.set_attribute("d", str(title_grdict.get_int("d")))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Groove gauge level-ups
|
2022-10-15 20:56:30 +02:00
|
|
|
gr_s = Node.void("gr_s")
|
2019-12-08 22:43:49 +01:00
|
|
|
friendnode.add_child(gr_s)
|
|
|
|
index = 1
|
2022-10-15 20:56:30 +02:00
|
|
|
for entry in friend.get_int_array("gr_s", 5):
|
|
|
|
gr_s.set_attribute(f"gr{index}", str(entry))
|
2019-12-08 22:43:49 +01:00
|
|
|
index = index + 1
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
gr_d = Node.void("gr_d")
|
2019-12-08 22:43:49 +01:00
|
|
|
friendnode.add_child(gr_d)
|
|
|
|
index = 1
|
2022-10-15 20:56:30 +02:00
|
|
|
for entry in friend.get_int_array("gr_d", 5):
|
|
|
|
gr_d.set_attribute(f"gr{index}", str(entry))
|
2019-12-08 22:43:49 +01:00
|
|
|
index = index + 1
|
|
|
|
|
|
|
|
# Play area
|
2022-10-15 20:56:30 +02:00
|
|
|
areas = profile.get_int_array("play_area", 55)
|
|
|
|
play_area = Node.void("play_area")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(play_area)
|
|
|
|
for i in range(len(areas)):
|
2022-10-15 20:56:30 +02:00
|
|
|
play_area.set_attribute(f"play_cnt{i}", str(areas[i]))
|
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:
|
2021-09-07 19:56:15 +02:00
|
|
|
newprofile = oldprofile.clone()
|
2019-12-08 22:43:49 +01:00
|
|
|
play_stats = self.get_play_statistics(userid)
|
|
|
|
|
|
|
|
# Grab last node and accessories so we can make decisions based on type
|
2022-10-15 20:56:30 +02:00
|
|
|
last = request.child("last")
|
|
|
|
lastdict = newprofile.get_dict("last")
|
|
|
|
mode = int(last.attribute("mode"))
|
|
|
|
style = int(last.attribute("style"))
|
2019-12-08 22:43:49 +01:00
|
|
|
is_dp = style == self.GAME_STYLE_DOUBLE
|
|
|
|
|
|
|
|
# Drill rankings
|
2022-10-15 20:56:30 +02:00
|
|
|
title = request.child("title")
|
|
|
|
title_gr = request.child("title_gr")
|
|
|
|
titledict = newprofile.get_dict("title")
|
|
|
|
title_grdict = newprofile.get_dict("title_gr")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Groove radar level ups
|
2022-10-15 20:56:30 +02:00
|
|
|
gr = request.child("gr")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Set the correct values depending on if we're single or double play
|
|
|
|
if is_dp:
|
2022-10-15 20:56:30 +02:00
|
|
|
play_stats.increment_int("double_plays")
|
2019-12-08 22:43:49 +01:00
|
|
|
if gr is not None:
|
|
|
|
newprofile.replace_int_array(
|
2022-10-15 20:56:30 +02:00
|
|
|
"gr_d",
|
2019-12-08 22:43:49 +01:00
|
|
|
5,
|
|
|
|
[
|
2022-10-15 20:56:30 +02:00
|
|
|
intish(gr.attribute("gr1")),
|
|
|
|
intish(gr.attribute("gr2")),
|
|
|
|
intish(gr.attribute("gr3")),
|
|
|
|
intish(gr.attribute("gr4")),
|
|
|
|
intish(gr.attribute("gr5")),
|
2019-12-08 22:43:49 +01:00
|
|
|
],
|
|
|
|
)
|
|
|
|
if title is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
titledict.replace_int("d", title.value)
|
|
|
|
newprofile.replace_dict("title", titledict)
|
2019-12-08 22:43:49 +01:00
|
|
|
if title_gr is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
title_grdict.replace_int("d", title.value)
|
|
|
|
newprofile.replace_dict("title_gr", title_grdict)
|
2019-12-08 22:43:49 +01:00
|
|
|
else:
|
2022-10-15 20:56:30 +02:00
|
|
|
play_stats.increment_int("single_plays")
|
2019-12-08 22:43:49 +01:00
|
|
|
if gr is not None:
|
|
|
|
newprofile.replace_int_array(
|
2022-10-15 20:56:30 +02:00
|
|
|
"gr_s",
|
2019-12-08 22:43:49 +01:00
|
|
|
5,
|
|
|
|
[
|
2022-10-15 20:56:30 +02:00
|
|
|
intish(gr.attribute("gr1")),
|
|
|
|
intish(gr.attribute("gr2")),
|
|
|
|
intish(gr.attribute("gr3")),
|
|
|
|
intish(gr.attribute("gr4")),
|
|
|
|
intish(gr.attribute("gr5")),
|
2019-12-08 22:43:49 +01:00
|
|
|
],
|
|
|
|
)
|
|
|
|
if title is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
titledict.replace_int("s", title.value)
|
|
|
|
newprofile.replace_dict("title", titledict)
|
2019-12-08 22:43:49 +01:00
|
|
|
if title_gr is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
title_grdict.replace_int("s", title.value)
|
|
|
|
newprofile.replace_dict("title_gr", title_grdict)
|
|
|
|
play_stats.increment_int(f"cnt_m{mode}")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Result stars
|
2022-10-15 20:56:30 +02:00
|
|
|
result_star = request.child("result_star")
|
2019-12-08 22:43:49 +01:00
|
|
|
if result_star is not None:
|
|
|
|
newprofile.replace_int_array(
|
2022-10-15 20:56:30 +02:00
|
|
|
"result_stars",
|
2019-12-08 22:43:49 +01:00
|
|
|
9,
|
|
|
|
[
|
2022-10-15 20:56:30 +02:00
|
|
|
intish(result_star.attribute("slot1")),
|
|
|
|
intish(result_star.attribute("slot2")),
|
|
|
|
intish(result_star.attribute("slot3")),
|
|
|
|
intish(result_star.attribute("slot4")),
|
|
|
|
intish(result_star.attribute("slot5")),
|
|
|
|
intish(result_star.attribute("slot6")),
|
|
|
|
intish(result_star.attribute("slot7")),
|
|
|
|
intish(result_star.attribute("slot8")),
|
|
|
|
intish(result_star.attribute("slot9")),
|
2019-12-08 22:43:49 +01:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
# Target stuff
|
2022-10-15 20:56:30 +02:00
|
|
|
target = request.child("target")
|
2019-12-08 22:43:49 +01:00
|
|
|
if target is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
newprofile.replace_int("target_flag", intish(target.attribute("flag")))
|
|
|
|
newprofile.replace_int("target_setnum", intish(target.attribute("setnum")))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Update last attributes
|
2022-10-15 20:56:30 +02:00
|
|
|
lastdict.replace_int("rival1", intish(last.attribute("rival1")))
|
|
|
|
lastdict.replace_int("rival2", intish(last.attribute("rival2")))
|
|
|
|
lastdict.replace_int("rival3", intish(last.attribute("rival3")))
|
|
|
|
lastdict.replace_int("style", intish(last.attribute("style")))
|
|
|
|
lastdict.replace_int("mode", intish(last.attribute("mode")))
|
|
|
|
lastdict.replace_int("cate", intish(last.attribute("cate")))
|
|
|
|
lastdict.replace_int("sort", intish(last.attribute("sort")))
|
|
|
|
lastdict.replace_int("mid", intish(last.attribute("mid")))
|
|
|
|
lastdict.replace_int("mtype", intish(last.attribute("mtype")))
|
|
|
|
lastdict.replace_int("cid", intish(last.attribute("cid")))
|
|
|
|
lastdict.replace_int("ctype", intish(last.attribute("ctype")))
|
|
|
|
lastdict.replace_int("sid", intish(last.attribute("sid")))
|
|
|
|
newprofile.replace_dict("last", lastdict)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Grab character options
|
2022-10-15 20:56:30 +02:00
|
|
|
chara = request.child("chara")
|
2019-12-08 22:43:49 +01:00
|
|
|
if chara is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
newprofile.replace_int("chara", intish(chara.attribute("my")))
|
|
|
|
chara_opt = request.child("chara_opt")
|
2019-12-08 22:43:49 +01:00
|
|
|
if chara_opt is not None:
|
|
|
|
# A bug in old versions of AVS returns the wrong number for set
|
2022-10-15 20:56:30 +02:00
|
|
|
newprofile.replace_int_array("chara_opt", 96, chara_opt.value[:96])
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Options
|
2022-10-15 20:56:30 +02:00
|
|
|
opt = request.child("opt")
|
2019-12-08 22:43:49 +01:00
|
|
|
if opt is not None:
|
|
|
|
# A bug in old versions of AVS returns the wrong number for set
|
2022-10-15 20:56:30 +02:00
|
|
|
newprofile.replace_int_array("opt", 16, opt.value[:16])
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Experience and stars
|
2022-10-15 20:56:30 +02:00
|
|
|
exp = request.child_value("exp")
|
2019-12-08 22:43:49 +01:00
|
|
|
if exp is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
play_stats.replace_int("exp", play_stats.get_int("exp") + exp)
|
|
|
|
star = request.child_value("star")
|
2019-12-08 22:43:49 +01:00
|
|
|
if star is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
newprofile.replace_int("star", newprofile.get_int("star") + star)
|
|
|
|
star_c = request.child_value("star_c")
|
2019-12-08 22:43:49 +01:00
|
|
|
if star_c is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
newprofile.replace_int("star_c", newprofile.get_int("star_c") + exp)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Update game flags
|
|
|
|
for child in request.children:
|
2022-10-15 20:56:30 +02:00
|
|
|
if child.name != "flag":
|
2019-12-08 22:43:49 +01:00
|
|
|
continue
|
|
|
|
try:
|
2022-10-15 20:56:30 +02:00
|
|
|
value = int(child.attribute("data"))
|
|
|
|
offset = int(child.attribute("no"))
|
2019-12-08 22:43:49 +01:00
|
|
|
except ValueError:
|
|
|
|
continue
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
flags = newprofile.get_int_array("flag", 256, [1] * 256)
|
2019-12-08 22:43:49 +01:00
|
|
|
if offset < 0 or offset >= len(flags):
|
|
|
|
continue
|
|
|
|
flags[offset] = value
|
2022-10-15 20:56:30 +02:00
|
|
|
newprofile.replace_int_array("flag", 256, flags)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Workout mode support
|
|
|
|
newweight = -1
|
2022-10-15 20:56:30 +02:00
|
|
|
oldweight = newprofile.get_int("weight")
|
2019-12-08 22:43:49 +01:00
|
|
|
for child in request.children:
|
2022-10-15 20:56:30 +02:00
|
|
|
if child.name != "weight":
|
2019-12-08 22:43:49 +01:00
|
|
|
continue
|
|
|
|
newweight = child.value
|
|
|
|
if newweight < 0:
|
|
|
|
newweight = oldweight
|
|
|
|
|
|
|
|
# Either update or unset the weight depending on the game
|
|
|
|
if newweight == 0:
|
|
|
|
# Weight is unset or we declined to use this feature, remove from profile
|
2022-10-15 20:56:30 +02:00
|
|
|
if "weight" in newprofile:
|
|
|
|
del newprofile["weight"]
|
2019-12-08 22:43:49 +01:00
|
|
|
else:
|
|
|
|
# Weight has been set or previously retrieved, we should save calories
|
2022-10-15 20:56:30 +02:00
|
|
|
newprofile.replace_int("weight", newweight)
|
2019-12-08 22:43:49 +01:00
|
|
|
total = 0
|
|
|
|
for child in request.children:
|
2022-10-15 20:56:30 +02:00
|
|
|
if child.name != "calory":
|
2019-12-08 22:43:49 +01:00
|
|
|
continue
|
|
|
|
total += child.value
|
|
|
|
self.data.local.user.put_time_based_achievement(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
userid,
|
|
|
|
0,
|
2022-10-15 20:56:30 +02:00
|
|
|
"workout",
|
2019-12-08 22:43:49 +01:00
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"calories": total,
|
|
|
|
"weight": newweight,
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
# Look up old friends
|
|
|
|
oldfriends: List[Optional[UserID]] = [None] * 10
|
|
|
|
links = self.data.local.user.get_links(self.game, self.version, userid)
|
|
|
|
for link in links:
|
2022-10-15 20:56:30 +02:00
|
|
|
if link.type[:7] != "friend_":
|
2019-12-08 22:43:49 +01:00
|
|
|
continue
|
|
|
|
|
|
|
|
pos = int(link.type[7:])
|
|
|
|
oldfriends[pos] = link.other_userid
|
|
|
|
|
|
|
|
# Save any rivals that were added/removed/changed
|
|
|
|
newfriends = oldfriends[:]
|
|
|
|
for child in request.children:
|
2022-10-15 20:56:30 +02:00
|
|
|
if child.name != "friend":
|
2019-12-08 22:43:49 +01:00
|
|
|
continue
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
code = int(child.attribute("code"))
|
|
|
|
pos = int(child.attribute("pos"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
if pos >= 0 and pos < 10:
|
|
|
|
if code == 0:
|
|
|
|
# We cleared this friend
|
|
|
|
newfriends[pos] = None
|
|
|
|
else:
|
|
|
|
# Try looking up the userid
|
2022-10-15 20:56:30 +02:00
|
|
|
newfriends[pos] = self.data.remote.user.from_extid(
|
|
|
|
self.game, self.version, code
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Diff the set of links to determine updates
|
|
|
|
for i in range(10):
|
|
|
|
if newfriends[i] == oldfriends[i]:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if newfriends[i] is None:
|
|
|
|
# Kill the rival in this location
|
|
|
|
self.data.local.user.destroy_link(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
userid,
|
2022-10-15 20:56:30 +02:00
|
|
|
f"friend_{i}",
|
2019-12-08 22:43:49 +01:00
|
|
|
oldfriends[i],
|
|
|
|
)
|
|
|
|
elif oldfriends[i] is None:
|
|
|
|
# Add rival in this location
|
|
|
|
self.data.local.user.put_link(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
userid,
|
2022-10-15 20:56:30 +02:00
|
|
|
f"friend_{i}",
|
2019-12-08 22:43:49 +01:00
|
|
|
newfriends[i],
|
|
|
|
{},
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
# Changed the rival here, kill the old one, add the new one
|
|
|
|
self.data.local.user.destroy_link(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
userid,
|
2022-10-15 20:56:30 +02:00
|
|
|
f"friend_{i}",
|
2019-12-08 22:43:49 +01:00
|
|
|
oldfriends[i],
|
|
|
|
)
|
|
|
|
self.data.local.user.put_link(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
userid,
|
2022-10-15 20:56:30 +02:00
|
|
|
f"friend_{i}",
|
2019-12-08 22:43:49 +01:00
|
|
|
newfriends[i],
|
|
|
|
{},
|
|
|
|
)
|
|
|
|
|
|
|
|
# Play area counter
|
2022-10-15 20:56:30 +02:00
|
|
|
shop_area = int(request.attribute("shop_area"))
|
2019-12-08 22:43:49 +01:00
|
|
|
if shop_area >= 0 and shop_area < 55:
|
2022-10-15 20:56:30 +02:00
|
|
|
areas = newprofile.get_int_array("play_area", 55)
|
2019-12-08 22:43:49 +01:00
|
|
|
areas[shop_area] = areas[shop_area] + 1
|
2022-10-15 20:56:30 +02:00
|
|
|
newprofile.replace_int_array("play_area", 55, areas)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Keep track of play statistics
|
|
|
|
self.update_play_statistics(userid, play_stats)
|
|
|
|
|
|
|
|
return newprofile
|