forked from Kohaku/maimaiDX-Api
138 lines
5.5 KiB
Python
138 lines
5.5 KiB
Python
# ログインボーナス!やったね!
|
|
# セガ秘 内部使用のみ(トレードマーク)
|
|
|
|
import json
|
|
from loguru import logger
|
|
|
|
from Config import *
|
|
from API_TitleServer import apiSDGB
|
|
from HelperLogInOut import apiLogin, apiLogout, generateTimestamp
|
|
from HelperFullPlay import implFullPlayAction
|
|
|
|
def apiQueryLoginBonus(userId:int) -> str:
|
|
"""ログインボーナスを取得する API"""
|
|
data = json.dumps({
|
|
"userId": int(userId),
|
|
"nextIndex": 0,
|
|
"maxCount": 2000
|
|
})
|
|
return apiSDGB(data, "GetUserLoginBonusApi", userId)
|
|
|
|
def implLoginBonus(userId: int, currentLoginTimestamp:int, currentLoginResult, bonusGenerateMode=1):
|
|
"""
|
|
ログインボーナスデータをアップロードする
|
|
bonusGenerateMode は、ログインボーナスを生成する方法を指定します。
|
|
1: 選択したボーナスのみ MAX にする(選択したボーナスはないの場合は False を返す)
|
|
2: 全部 MAX にする
|
|
"""
|
|
musicData = {
|
|
"musicId": 674, # Magical Flavor
|
|
"level": 0,
|
|
"playCount": 2,
|
|
"achievement": 0,
|
|
"comboStatus": 0,
|
|
"syncStatus": 0,
|
|
"deluxscoreMax": 0,
|
|
"scoreRank": 0,
|
|
"extNum1": 0
|
|
}
|
|
# サーバーからログインボーナスデータを取得
|
|
data = json.dumps({
|
|
"userId": int(userId),
|
|
"nextIndex": 0,
|
|
"maxCount": 2000
|
|
})
|
|
UserLoginBonusResponse = json.loads(apiSDGB(data, "GetUserLoginBonusApi", userId))
|
|
# ログインボーナスリストを生成、それから処理してアップロード
|
|
UserLoginBonusList = UserLoginBonusResponse['userLoginBonusList']
|
|
finalBonusList = generateLoginBonusList(UserLoginBonusList, bonusGenerateMode)
|
|
if not finalBonusList:
|
|
return False #ログインボーナスを選択していないから失敗
|
|
# UserAllのパッチ
|
|
userAllPatches = {
|
|
"upsertUserAll": {
|
|
"userMusicDetailList": [musicData],
|
|
"isNewMusicDetailList": "1", #上書きしない
|
|
"userLoginBonusList": finalBonusList,
|
|
"isNewLoginBonusList": "0" * len(finalBonusList)
|
|
}}
|
|
result = implFullPlayAction(userId, currentLoginTimestamp, currentLoginResult, musicData, userAllPatches)
|
|
return result
|
|
|
|
def generateLoginBonusList(UserLoginBonusList, generateMode=1):
|
|
"""
|
|
ログインボーナスリストを生成します。
|
|
generateMode は、ログインボーナスを生成する方法を指定します。
|
|
1: 選択したボーナスのみ MAX にする(選択したボーナスはないの場合は False を返す)
|
|
2: 全部 MAX にする
|
|
"""
|
|
# HDDから、ログインボーナスデータを読み込む
|
|
# アップデートがある場合、このファイルを更新する必要があります
|
|
# 必ず最新のデータを使用してください
|
|
with open('./Data/loginBonus.json', encoding='utf-8') as file:
|
|
cache = json.load(file)
|
|
loginBonusIdList = [item['id'] for item in cache]
|
|
logger.debug(f"ログインボーナスIDリスト: {loginBonusIdList}")
|
|
|
|
# ログインボーナスの MAX POINT は5の場合があります
|
|
# その全部のボーナスIDをこのリストに追加してください
|
|
# 必ず最新のデータを使用してください
|
|
Bonus5Id = [12, 29, 30, 38, 43, 604]
|
|
|
|
# UserBonusList から bonusId を取得
|
|
UserLoginBonusIdList = [item['bonusId'] for item in UserLoginBonusList]
|
|
|
|
# 存在しないボーナス
|
|
NonExistingBonuses = list(set(loginBonusIdList) - set(UserLoginBonusIdList))
|
|
logger.debug(f"存在しないボーナス: {NonExistingBonuses}")
|
|
|
|
bonusList = []
|
|
if generateMode == 1: #選択したボーナスのみ MAX にする
|
|
for item in UserLoginBonusList:
|
|
if item['isCurrent'] and not item['isComplete']:
|
|
point = 4 if item['bonusId'] in Bonus5Id else 9
|
|
data = {
|
|
"bonusId": item['bonusId'],
|
|
"point": point,
|
|
"isCurrent": True,
|
|
"isComplete": False
|
|
}
|
|
bonusList.append(data)
|
|
if len(bonusList) == 0:
|
|
logger.warning("このユーザーはログインボーナスを選択していませんから失敗")
|
|
return False
|
|
elif generateMode == 2: #全部 MAX にする
|
|
# 存在しているボーナスを追加
|
|
for item in UserLoginBonusList:
|
|
if not item['isComplete']:
|
|
data = {
|
|
"bonusId": item['bonusId'],
|
|
"point": 4 if item['bonusId'] in Bonus5Id else 9,
|
|
"isCurrent": item['isCurrent'],
|
|
"isComplete": False
|
|
}
|
|
bonusList.append(data)
|
|
elif item['bonusId'] == 999:
|
|
data = {
|
|
"bonusId": 999,
|
|
"point": (item['point'] // 10) * 10 + 9,
|
|
"isCurrent": item['isCurrent'],
|
|
"isComplete": False
|
|
}
|
|
bonusList.append(data)
|
|
# 存在しないボーナスを追加
|
|
for bonusId in NonExistingBonuses:
|
|
data = {
|
|
"bonusId": bonusId,
|
|
"point": 4 if bonusId in Bonus5Id else 9,
|
|
"isCurrent": False,
|
|
"isComplete": False
|
|
}
|
|
bonusList.append(data)
|
|
else:
|
|
logger.error("generateMode は 1 または 2 でなければなりません")
|
|
return False
|
|
|
|
logger.debug(f"ログインボーナスリスト: {bonusList}")
|
|
return bonusList
|