database support for prism

kaleidxScope Key Condition store
This commit is contained in:
SoulGateKey
2025-04-04 09:10:41 +08:00
parent 9a7fc007bc
commit c0df7cd084
4 changed files with 113 additions and 9 deletions

View File

@@ -49,6 +49,22 @@ class Mai2Prism(Mai2BuddiesPlus):
}
async def handle_get_user_kaleidx_scope_api_request(self, data: Dict) -> Dict:
# kaleidxscope keyget condition judgement
# player may get key before GateFound
for gate in range(1,7):
condition_list = await self.data.static.get_kaleidxscope_condition(gate)
if not condition_list:
continue
condition_satisfy = 0
for condition in condition_list:
score_list = await self.data.score.get_best_scores(user_id=data["userId"], song_id=condition[3])
if score_list:
condition_satisfy = condition_satisfy + 1
if len(condition_list) == condition_satisfy:
new_kaleidxscope = {'gateId': gate, "isKeyFound": True}
await self.data.score.put_user_kaleidxscope(data["userId"], new_kaleidxscope)
kaleidxscope = await self.data.score.get_user_kaleidxscope_list(data["userId"])
if kaleidxscope is None:

View File

@@ -48,8 +48,12 @@ class Mai2Reader(BaseReader):
self.logger.info(f"Read from {dir}")
await self.get_events(f"{dir}/event")
await self.disable_events(f"{dir}/information", f"{dir}/scoreRanking")
await self.read_music(f"{dir}/music")
#await self.read_music(f"{dir}/music")
await self.read_tickets(f"{dir}/ticket")
if self.version >= Mai2Constants.VER_MAIMAI_DX_PRISM:
for dir in data_dirs:
await self.read_kaleidxscope_condition(f"{dir}/kaleidxScopeKeyCondition")
else:
if not os.path.exists(f"{self.bin_dir}/tables"):
@@ -341,3 +345,31 @@ class Mai2Reader(BaseReader):
if scores is None or text is None:
return
# TODO
async def read_kaleidxscope_condition(self, base_dir: str) -> None :
self.logger.info(f"Reading KaleidxScope Key Conditions from {base_dir}...")
for root, dirs, files in os.walk(base_dir):
for dir in dirs:
if os.path.exists(f"{root}/{dir}/KaleidxScopeKeyCondition.xml"):
with open(f"{root}/{dir}/KaleidxScopeKeyCondition.xml", encoding="utf-8") as f:
troot = ET.fromstring(f.read())
condition_id = int(troot.find("name").find("id").text)
condition_name = troot.find("name").find("str").text
music_list = troot.find("musicIds").find("list")
for music in music_list.findall("StringID"):
music_id = int(music.find("id").text)
music_name = music.find("str").text
await self.data.static.put_kaleidxscope_condition(
condition_id,
condition_name,
music_id,
music_name
)
self.logger.info(
f"Add music {music_id} for condition {condition_id}"
)

View File

@@ -71,6 +71,17 @@ cards = Table(
mysql_charset="utf8mb4",
)
kaleidxscope_condition = Table(
"mai2_static_kaleidxscope_condition",
metadata,
Column("id", Integer, primary_key=True, nullable=False),
Column("conditionId", Integer),
Column("conditionName", String(255)),
Column("songId", Integer),
Column("songName", String(255)),
UniqueConstraint("conditionId", "conditionName", "songId", "songName", name="mai2_static_kaleidxscope_uk"),
mysql_charset="utf8mb4",
)
class Mai2StaticData(BaseData):
async def put_game_event(
@@ -264,3 +275,35 @@ class Mai2StaticData(BaseData):
result = await self.execute(event.update(event.c.id == table_id).values(enabled=is_enable, startDate = start_date))
if not result:
self.logger.error(f"Failed to update event {table_id} - {is_enable} {start_date}")
# new in prism
async def put_kaleidxscope_condition(
self,
condition_id: int,
condition_name: str,
music_id: int,
music_name: str
) -> Optional[int]:
sql = insert(kaleidxscope_condition).values(
conditionId = condition_id,
conditionName = condition_name,
songId = music_id,
songName = music_name,
)
conflict = sql.on_duplicate_key_update(conditionName=condition_name, songName=music_name)
result = await self.execute(conflict)
if result is None:
self.logger.warning(
f"put_kaleidxscope_condition: Failed to insert kaleidxScope Key Condition! conditionID {condition_id} songId {music_id}"
)
return result.lastrowid
async def get_kaleidxscope_condition(self, condition_id: int) -> None:
sql = kaleidxscope_condition.select(kaleidxscope_condition.c.conditionId == condition_id)
result = await self.execute(sql)
if result is None:
return None
return result.fetchall()