add Kaleidx Scope Support

This commit is contained in:
2025-04-02 09:42:08 +08:00
parent d77d02c2dd
commit 3d84e32892
3 changed files with 67 additions and 3 deletions

View File

@ -282,6 +282,12 @@ class Mai2DX(Mai2Base):
for intimate in upsert["userIntimateList"]:
await self.data.profile.put_intimacy(user_id, intimate["partnerId"], intimate["intimateLevel"], intimate["intimateCountRewarded"])
# added in PRiSM
if "userKaleidxScopeList" in upsert and len(upsert["userKaleidxScopeList"]) > 0:
for kaleidx_scope in upsert["userKaleidxScopeList"]:
await self.data.score.put_user_kaleidx_scope(user_id, kaleidx_scope)
return {"returnCode": 1, "apiName": "UpsertUserAllApi"}
async def handle_get_user_data_api_request(self, data: Dict) -> Dict:

View File

@ -4,6 +4,8 @@ from core.config import CoreConfig
from titles.mai2.buddiesplus import Mai2BuddiesPlus
from titles.mai2.const import Mai2Constants
from titles.mai2.config import Mai2Config
from titles.mai2.schema.score import kaleidx_scope
class Mai2Prism(Mai2BuddiesPlus):
def __init__(self, cfg: CoreConfig, game_cfg: Mai2Config) -> None:
@ -48,10 +50,18 @@ class Mai2Prism(Mai2BuddiesPlus):
}
async def handle_get_user_kaleidx_scope_api_request(self, data: Dict) -> Dict:
user_id = data["userId"]
kaleidx_scope = await self.data.score.get_user_kaleidx_scope_list(data["userId"])
if kaleidx_scope is None:
return {"userId": data["userId"], "userKaleidxScopeList":[]}
kaleidx_scope_list = []
for kaleidx_scope_data in kaleidx_scope:
tmp = kaleidx_scope_data._asdict()
tmp.pop("user")
tmp.pop("id")
kaleidx_scope_list.append(tmp)
return {
"userId": user_id,
"userKaleidxScopeList": []
"userId": data["userId"],
"userKaleidxScopeList": kaleidx_scope_list
}

View File

@ -1,3 +1,4 @@
from configparser import Interpolation
from typing import Dict, List, Optional
from sqlalchemy import Column, Table, UniqueConstraint, and_
@ -174,6 +175,34 @@ playlog_2p = Table(
mysql_charset="utf8mb4",
)
kaleidx_scope = Table(
"mai2_score_kaleidx_scope",
metadata,
Column("id", Integer, primary_key=True, nullable=False),
Column(
"user",
ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"),
nullable=False,
),
Column("gateId", Integer),
Column("isGateFound", Boolean),
Column("isKeyFound", Boolean),
Column("isClear", Boolean),
Column("totalRestLife", Integer),
Column("totalAchievement", Integer),
Column("totalDeluxscore", Integer),
Column("bestAchievement", Integer),
Column("bestDeluxscore", Integer),
Column("bestAchievementDate", String(25)),
Column("bestDeluxscoreDate", String(25)),
Column("playCount", Integer),
Column("clearDate", String(25)),
Column("lastPlayDate", String(25)),
Column("isInfoWatched", Boolean),
UniqueConstraint("user", "gateId", name="mai2_score_best_uk"),
mysql_charset="utf8mb4"
)
course = Table(
"mai2_score_course",
metadata,
@ -451,3 +480,22 @@ class Mai2ScoreData(BaseData):
self.logger.warning(f"aime_id {aime_id} has no playlog ")
return None
return result.scalar()
async def get_user_kaleidx_scope_list(self, user_id: int) -> Optional[List[Row]]:
sql = kaleidx_scope.select(kaleidx_scope.c.user == user_id)
result = await self.execute(sql)
if result is None:
return None
return result.fetchall()
async def put_user_kaleidx_scope(self, user_id: int, user_kaleidx_scope_data: Dict) -> Optional[int]:
user_kaleidx_scope_data["user"] = user_id
sql = insert(kaleidx_scope).values(**user_kaleidx_scope_data)
conflict = sql.on_duplicate_key_update(**user_kaleidx_scope_data)
result = await self.execute(conflict)
if result is None:
self.logger.error(f"put_user_kaleidx_scope: Failed to insert! user_id {user_id}")
return None
return result.lastrowid