2023-02-17 06:02:21 +00:00
|
|
|
|
from datetime import date, datetime, timedelta
|
|
|
|
|
from typing import Any, Dict
|
2023-03-03 22:46:29 +00:00
|
|
|
|
from random import randint
|
2023-02-17 06:02:21 +00:00
|
|
|
|
import pytz
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
from core.config import CoreConfig
|
|
|
|
|
from titles.ongeki.base import OngekiBase
|
|
|
|
|
from titles.ongeki.const import OngekiConstants
|
|
|
|
|
from titles.ongeki.config import OngekiConfig
|
|
|
|
|
|
|
|
|
|
|
2023-03-03 22:46:29 +00:00
|
|
|
|
class OngekiBright(OngekiBase):
|
2023-02-17 06:02:21 +00:00
|
|
|
|
def __init__(self, core_cfg: CoreConfig, game_cfg: OngekiConfig) -> None:
|
|
|
|
|
super().__init__(core_cfg, game_cfg)
|
|
|
|
|
self.version = OngekiConstants.VER_ONGEKI_BRIGHT
|
|
|
|
|
|
2024-01-09 08:07:04 +00:00
|
|
|
|
async def handle_get_game_setting_api_request(self, data: Dict) -> Dict:
|
|
|
|
|
ret = await super().handle_get_game_setting_api_request(data)
|
2023-02-17 06:02:21 +00:00
|
|
|
|
ret["gameSetting"]["dataVersion"] = "1.30.00"
|
|
|
|
|
ret["gameSetting"]["onlineDataVersion"] = "1.30.00"
|
|
|
|
|
return ret
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
2024-01-09 08:07:04 +00:00
|
|
|
|
async def handle_cm_get_user_data_api_request(self, data: Dict) -> Dict:
|
2023-03-05 22:54:13 +00:00
|
|
|
|
# check for a bright profile
|
2024-01-09 19:42:17 +00:00
|
|
|
|
p = await self.data.profile.get_profile_data(data["userId"], self.version)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
if p is None:
|
|
|
|
|
return {}
|
|
|
|
|
|
2024-01-09 19:42:17 +00:00
|
|
|
|
cards = await self.data.card.get_user_cards(data["userId"])
|
2023-03-03 22:46:29 +00:00
|
|
|
|
if cards is None or len(cards) == 0:
|
|
|
|
|
# This should never happen
|
|
|
|
|
self.logger.error(
|
2023-03-09 16:38:58 +00:00
|
|
|
|
f"handle_get_user_data_api_request: Internal error - No cards found for user id {data['userId']}"
|
|
|
|
|
)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
# get the dict representation of the row so we can modify values
|
|
|
|
|
user_data = p._asdict()
|
|
|
|
|
|
|
|
|
|
# remove the values the game doesn't want
|
|
|
|
|
user_data.pop("id")
|
|
|
|
|
user_data.pop("user")
|
|
|
|
|
user_data.pop("version")
|
|
|
|
|
|
|
|
|
|
# add access code that we don't store
|
|
|
|
|
user_data["accessCode"] = cards[0]["access_code"]
|
|
|
|
|
|
2023-07-12 09:25:46 +00:00
|
|
|
|
# add the compatible card maker version from config
|
|
|
|
|
card_maker_ver = self.game_cfg.version.version(self.version)
|
|
|
|
|
if card_maker_ver and card_maker_ver.get("card_maker"):
|
|
|
|
|
# Card Maker 1.30 = 1.30.01+
|
|
|
|
|
# Card Maker 1.35 = 1.35.03+
|
|
|
|
|
user_data["compatibleCmVersion"] = card_maker_ver.get("card_maker")
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
return {"userId": data["userId"], "userData": user_data}
|
|
|
|
|
|
2024-01-09 08:07:04 +00:00
|
|
|
|
async def handle_printer_login_api_request(self, data: Dict):
|
2023-03-03 22:46:29 +00:00
|
|
|
|
return {"returnCode": 1}
|
|
|
|
|
|
2024-01-09 08:07:04 +00:00
|
|
|
|
async def handle_printer_logout_api_request(self, data: Dict):
|
2023-03-03 22:46:29 +00:00
|
|
|
|
return {"returnCode": 1}
|
|
|
|
|
|
2024-01-09 08:07:04 +00:00
|
|
|
|
async def handle_cm_get_user_card_api_request(self, data: Dict) -> Dict:
|
2024-01-09 19:42:17 +00:00
|
|
|
|
user_cards = await self.data.item.get_cards(data["userId"])
|
2023-03-03 22:46:29 +00:00
|
|
|
|
if user_cards is None:
|
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
max_ct = data["maxCount"]
|
|
|
|
|
next_idx = data["nextIndex"]
|
|
|
|
|
start_idx = next_idx
|
|
|
|
|
end_idx = max_ct + start_idx
|
|
|
|
|
|
|
|
|
|
if len(user_cards[start_idx:]) > max_ct:
|
|
|
|
|
next_idx += max_ct
|
|
|
|
|
else:
|
|
|
|
|
next_idx = -1
|
|
|
|
|
|
|
|
|
|
card_list = []
|
|
|
|
|
for card in user_cards:
|
|
|
|
|
tmp = card._asdict()
|
|
|
|
|
tmp.pop("id")
|
|
|
|
|
tmp.pop("user")
|
|
|
|
|
card_list.append(tmp)
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"userId": data["userId"],
|
|
|
|
|
"length": len(card_list[start_idx:end_idx]),
|
|
|
|
|
"nextIndex": next_idx,
|
2023-03-09 16:38:58 +00:00
|
|
|
|
"userCardList": card_list[start_idx:end_idx],
|
2023-03-03 22:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-09 08:07:04 +00:00
|
|
|
|
async def handle_cm_get_user_character_api_request(self, data: Dict) -> Dict:
|
2024-01-09 19:42:17 +00:00
|
|
|
|
user_characters = await self.data.item.get_characters(data["userId"])
|
2023-03-03 22:46:29 +00:00
|
|
|
|
if user_characters is None:
|
2023-03-15 20:03:22 +00:00
|
|
|
|
return {
|
|
|
|
|
"userId": data["userId"],
|
|
|
|
|
"length": 0,
|
|
|
|
|
"nextIndex": 0,
|
2023-04-24 01:04:52 +00:00
|
|
|
|
"userCharacterList": [],
|
2023-03-15 20:03:22 +00:00
|
|
|
|
}
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
max_ct = data["maxCount"]
|
|
|
|
|
next_idx = data["nextIndex"]
|
|
|
|
|
start_idx = next_idx
|
|
|
|
|
end_idx = max_ct + start_idx
|
|
|
|
|
|
|
|
|
|
if len(user_characters[start_idx:]) > max_ct:
|
|
|
|
|
next_idx += max_ct
|
|
|
|
|
else:
|
|
|
|
|
next_idx = -1
|
|
|
|
|
|
|
|
|
|
character_list = []
|
|
|
|
|
for character in user_characters:
|
|
|
|
|
tmp = character._asdict()
|
|
|
|
|
tmp.pop("id")
|
|
|
|
|
tmp.pop("user")
|
|
|
|
|
character_list.append(tmp)
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"userId": data["userId"],
|
|
|
|
|
"length": len(character_list[start_idx:end_idx]),
|
|
|
|
|
"nextIndex": next_idx,
|
2023-03-09 16:38:58 +00:00
|
|
|
|
"userCharacterList": character_list[start_idx:end_idx],
|
2023-03-03 22:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-09 08:07:04 +00:00
|
|
|
|
async def handle_get_user_gacha_api_request(self, data: Dict) -> Dict:
|
2024-01-09 19:42:17 +00:00
|
|
|
|
user_gachas = await self.data.item.get_user_gachas(data["userId"])
|
2023-03-03 22:46:29 +00:00
|
|
|
|
if user_gachas is None:
|
2023-03-09 16:38:58 +00:00
|
|
|
|
return {"userId": data["userId"], "length": 0, "userGachaList": []}
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
user_gacha_list = []
|
|
|
|
|
for gacha in user_gachas:
|
|
|
|
|
tmp = gacha._asdict()
|
|
|
|
|
tmp.pop("id")
|
|
|
|
|
tmp.pop("user")
|
2023-03-09 16:38:58 +00:00
|
|
|
|
tmp["dailyGachaDate"] = datetime.strftime(tmp["dailyGachaDate"], "%Y-%m-%d")
|
2023-03-03 22:46:29 +00:00
|
|
|
|
user_gacha_list.append(tmp)
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"userId": data["userId"],
|
|
|
|
|
"length": len(user_gacha_list),
|
2023-03-09 16:38:58 +00:00
|
|
|
|
"userGachaList": user_gacha_list,
|
2023-03-03 22:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-09 08:07:04 +00:00
|
|
|
|
async def handle_cm_get_user_item_api_request(self, data: Dict) -> Dict:
|
2024-03-02 22:55:41 +00:00
|
|
|
|
return await self.handle_get_user_item_api_request(data)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
2024-01-09 08:07:04 +00:00
|
|
|
|
async def handle_cm_get_user_gacha_supply_api_request(self, data: Dict) -> Dict:
|
2023-03-03 22:46:29 +00:00
|
|
|
|
# not used for now? not sure what it even does
|
2024-01-09 19:42:17 +00:00
|
|
|
|
user_gacha_supplies = await self.data.item.get_user_gacha_supplies(data["userId"])
|
2023-03-03 22:46:29 +00:00
|
|
|
|
if user_gacha_supplies is None:
|
2023-03-09 16:38:58 +00:00
|
|
|
|
return {"supplyId": 1, "length": 0, "supplyCardList": []}
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
supply_list = [gacha["cardId"] for gacha in user_gacha_supplies]
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"supplyId": 1,
|
|
|
|
|
"length": len(supply_list),
|
2023-03-09 16:38:58 +00:00
|
|
|
|
"supplyCardList": supply_list,
|
2023-03-03 22:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-09 08:07:04 +00:00
|
|
|
|
async def handle_get_game_gacha_api_request(self, data: Dict) -> Dict:
|
2023-03-03 22:46:29 +00:00
|
|
|
|
"""
|
|
|
|
|
returns all current active banners (gachas)
|
|
|
|
|
"Select Gacha" requires maxSelectPoint set and isCeiling set to 1
|
|
|
|
|
"""
|
|
|
|
|
game_gachas = []
|
|
|
|
|
# for every gacha_id in the OngekiConfig, grab the banner from the db
|
|
|
|
|
for gacha_id in self.game_cfg.gachas.enabled_gachas:
|
2024-01-09 19:42:17 +00:00
|
|
|
|
game_gacha = await self.data.static.get_gacha(self.version, gacha_id)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
if game_gacha:
|
|
|
|
|
game_gachas.append(game_gacha)
|
|
|
|
|
|
|
|
|
|
# clean the database rows
|
|
|
|
|
game_gacha_list = []
|
|
|
|
|
for gacha in game_gachas:
|
|
|
|
|
tmp = gacha._asdict()
|
|
|
|
|
tmp.pop("id")
|
|
|
|
|
tmp.pop("version")
|
2023-03-09 16:38:58 +00:00
|
|
|
|
tmp["startDate"] = datetime.strftime(tmp["startDate"], "%Y-%m-%d %H:%M:%S")
|
|
|
|
|
tmp["endDate"] = datetime.strftime(tmp["endDate"], "%Y-%m-%d %H:%M:%S")
|
2023-03-03 22:46:29 +00:00
|
|
|
|
tmp["noticeStartDate"] = datetime.strftime(
|
2023-03-09 16:38:58 +00:00
|
|
|
|
tmp["noticeStartDate"], "%Y-%m-%d %H:%M:%S"
|
|
|
|
|
)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
tmp["noticeEndDate"] = datetime.strftime(
|
2023-03-09 16:38:58 +00:00
|
|
|
|
tmp["noticeEndDate"], "%Y-%m-%d %H:%M:%S"
|
|
|
|
|
)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
tmp["convertEndDate"] = datetime.strftime(
|
2023-03-09 16:38:58 +00:00
|
|
|
|
tmp["convertEndDate"], "%Y-%m-%d %H:%M:%S"
|
|
|
|
|
)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
# make sure to only show gachas for the current version
|
|
|
|
|
# so only up to bright, 1140 is the first bright memory gacha
|
2023-03-05 22:54:13 +00:00
|
|
|
|
if self.version == OngekiConstants.VER_ONGEKI_BRIGHT_MEMORY:
|
|
|
|
|
game_gacha_list.append(tmp)
|
2023-03-09 16:38:58 +00:00
|
|
|
|
elif (
|
|
|
|
|
self.version == OngekiConstants.VER_ONGEKI_BRIGHT
|
|
|
|
|
and tmp["gachaId"] < 1140
|
|
|
|
|
):
|
2023-03-03 22:46:29 +00:00
|
|
|
|
game_gacha_list.append(tmp)
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"length": len(game_gacha_list),
|
|
|
|
|
"gameGachaList": game_gacha_list,
|
|
|
|
|
# no clue
|
2023-03-09 16:38:58 +00:00
|
|
|
|
"registIdList": [],
|
2023-03-03 22:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-09 08:07:04 +00:00
|
|
|
|
async def handle_roll_gacha_api_request(self, data: Dict) -> Dict:
|
2023-03-03 22:46:29 +00:00
|
|
|
|
"""
|
|
|
|
|
Handle a gacha roll API request
|
|
|
|
|
"""
|
|
|
|
|
gacha_id = data["gachaId"]
|
|
|
|
|
num_rolls = data["times"]
|
|
|
|
|
# change_rate is the 5 gacha rool SR gurantee once a week
|
|
|
|
|
change_rate = data["changeRate"]
|
|
|
|
|
# SSR book which guarantees a SSR card, itemKind=15, itemId=1
|
|
|
|
|
book_used = data["bookUseCount"]
|
|
|
|
|
if num_rolls not in {1, 5, 11}:
|
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
# https://gamerch.com/ongeki/entry/462978
|
|
|
|
|
|
|
|
|
|
# 77% chance of gett ing a R card
|
|
|
|
|
# 20% chance of getting a SR card
|
|
|
|
|
# 3% chance of getting a SSR card
|
|
|
|
|
rarity = [1 for _ in range(77)]
|
|
|
|
|
rarity += [2 for _ in range(20)]
|
|
|
|
|
rarity += [3 for _ in range(3)]
|
|
|
|
|
|
|
|
|
|
# gachaId 1011 is "無料ガチャ" (free gacha), which requires GatchaTickets
|
|
|
|
|
# itemKind=11, itemId=1 and appearenty sucks
|
|
|
|
|
# 94% chance of getting a R card
|
|
|
|
|
# 5% chance of getting a SR card
|
|
|
|
|
# 1% chance of getting a SSR card
|
|
|
|
|
if gacha_id == 1011:
|
|
|
|
|
rarity = [1 for _ in range(94)]
|
|
|
|
|
rarity += [2 for _ in range(5)]
|
|
|
|
|
rarity += [3 for _ in range(1)]
|
|
|
|
|
|
|
|
|
|
# gachaId 1012 is "無料ガチャ(SR確定)" (SR confirmed! free gacha), which
|
|
|
|
|
# requires GatchaTickets itemKind=11, itemId=4 and always guarantees
|
|
|
|
|
# a SR card or higher
|
|
|
|
|
# 92% chance of getting a SR card
|
|
|
|
|
# 8% chance of getting a SSR card
|
|
|
|
|
elif gacha_id == 1012:
|
|
|
|
|
rarity = [2 for _ in range(92)]
|
|
|
|
|
rarity += [3 for _ in range(8)]
|
|
|
|
|
|
|
|
|
|
assert len(rarity) == 100
|
|
|
|
|
|
|
|
|
|
# uniform distribution to get the rarity of the card
|
2023-03-09 16:38:58 +00:00
|
|
|
|
rolls = [rarity[randint(0, len(rarity) - 1)] for _ in range(num_rolls)]
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
# if SSR book used, make sure you always get one SSR
|
|
|
|
|
if book_used == 1:
|
|
|
|
|
if rolls.count(3) == 0:
|
|
|
|
|
# if there is no SSR, re-roll
|
|
|
|
|
return self.handle_roll_gacha_api_request(data)
|
|
|
|
|
# make sure that 11 rolls always have at least 1 SR or SSR
|
|
|
|
|
elif (num_rolls == 5 and change_rate is True) or num_rolls == 11:
|
|
|
|
|
if rolls.count(2) == 0 and rolls.count(3) == 0:
|
|
|
|
|
# if there is no SR or SSR, re-roll
|
|
|
|
|
return self.handle_roll_gacha_api_request(data)
|
|
|
|
|
|
|
|
|
|
# get a list of cards for each rarity
|
2024-01-09 19:42:17 +00:00
|
|
|
|
cards_r = await self.data.static.get_cards_by_rarity(self.version, 1)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
cards_sr, cards_ssr = [], []
|
|
|
|
|
|
|
|
|
|
# free gachas are only allowed to get their specific cards! (R irrelevant)
|
|
|
|
|
if gacha_id in {1011, 1012}:
|
2024-01-09 19:42:17 +00:00
|
|
|
|
gacha_cards = await self.data.static.get_gacha_cards(gacha_id)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
for card in gacha_cards:
|
|
|
|
|
if card["rarity"] == 3:
|
2023-03-09 16:38:58 +00:00
|
|
|
|
cards_sr.append({"cardId": card["cardId"], "rarity": 2})
|
2023-03-03 22:46:29 +00:00
|
|
|
|
elif card["rarity"] == 4:
|
2023-03-09 16:38:58 +00:00
|
|
|
|
cards_ssr.append({"cardId": card["cardId"], "rarity": 3})
|
2023-03-03 22:46:29 +00:00
|
|
|
|
else:
|
2024-01-09 19:42:17 +00:00
|
|
|
|
cards_sr = await self.data.static.get_cards_by_rarity(self.version, 2)
|
|
|
|
|
cards_ssr = await self.data.static.get_cards_by_rarity(self.version, 3)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
# get the promoted cards for that gacha and add them multiple
|
|
|
|
|
# times to increase chances by factor chances
|
|
|
|
|
chances = 10
|
|
|
|
|
|
2024-01-09 19:42:17 +00:00
|
|
|
|
gacha_cards = await self.data.static.get_gacha_cards(gacha_id)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
for card in gacha_cards:
|
|
|
|
|
# make sure to add the cards to the corresponding rarity
|
|
|
|
|
if card["rarity"] == 2:
|
2023-03-09 16:38:58 +00:00
|
|
|
|
cards_r += [{"cardId": card["cardId"], "rarity": 1}] * chances
|
2023-03-03 22:46:29 +00:00
|
|
|
|
if card["rarity"] == 3:
|
2023-03-09 16:38:58 +00:00
|
|
|
|
cards_sr += [{"cardId": card["cardId"], "rarity": 2}] * chances
|
2023-03-03 22:46:29 +00:00
|
|
|
|
elif card["rarity"] == 4:
|
2023-03-09 16:38:58 +00:00
|
|
|
|
cards_ssr += [{"cardId": card["cardId"], "rarity": 3}] * chances
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
# get the card id for each roll
|
|
|
|
|
rolled_cards = []
|
|
|
|
|
for i in range(len(rolls)):
|
|
|
|
|
if rolls[i] == 1:
|
2023-03-09 16:38:58 +00:00
|
|
|
|
rolled_cards.append(cards_r[randint(0, len(cards_r) - 1)])
|
2023-03-03 22:46:29 +00:00
|
|
|
|
elif rolls[i] == 2:
|
2023-03-09 16:38:58 +00:00
|
|
|
|
rolled_cards.append(cards_sr[randint(0, len(cards_sr) - 1)])
|
2023-03-03 22:46:29 +00:00
|
|
|
|
elif rolls[i] == 3:
|
2023-03-09 16:38:58 +00:00
|
|
|
|
rolled_cards.append(cards_ssr[randint(0, len(cards_ssr) - 1)])
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
game_gacha_card_list = []
|
|
|
|
|
for card in rolled_cards:
|
2023-03-09 16:38:58 +00:00
|
|
|
|
game_gacha_card_list.append(
|
|
|
|
|
{
|
|
|
|
|
"gachaId": data["gachaId"],
|
|
|
|
|
"cardId": card["cardId"],
|
|
|
|
|
# +1 because Card Maker is weird
|
|
|
|
|
"rarity": card["rarity"] + 1,
|
|
|
|
|
"weight": 1,
|
|
|
|
|
"isPickup": False,
|
|
|
|
|
"isSelect": False,
|
|
|
|
|
}
|
|
|
|
|
)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"length": len(game_gacha_card_list),
|
2023-03-09 16:38:58 +00:00
|
|
|
|
"gameGachaCardList": game_gacha_card_list,
|
2023-03-03 22:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-09 08:07:04 +00:00
|
|
|
|
async def handle_cm_upsert_user_gacha_api_request(self, data: Dict):
|
2023-03-03 22:46:29 +00:00
|
|
|
|
upsert = data["cmUpsertUserGacha"]
|
|
|
|
|
user_id = data["userId"]
|
|
|
|
|
|
|
|
|
|
gacha_id = data["gachaId"]
|
|
|
|
|
gacha_count = data["gachaCnt"]
|
2023-03-09 16:38:58 +00:00
|
|
|
|
play_date = datetime.strptime(data["playDate"][:10], "%Y-%m-%d")
|
2023-03-03 22:46:29 +00:00
|
|
|
|
select_point = data["selectPoint"]
|
|
|
|
|
|
|
|
|
|
total_gacha_count, ceiling_gacha_count = 0, 0
|
2023-07-12 09:25:46 +00:00
|
|
|
|
# 0 = can still use Gacha Select, 1 = already used Gacha Select
|
|
|
|
|
use_select_point = 0
|
2023-03-03 22:46:29 +00:00
|
|
|
|
daily_gacha_cnt, five_gacha_cnt, eleven_gacha_cnt = 0, 0, 0
|
2023-03-09 16:38:58 +00:00
|
|
|
|
daily_gacha_date = datetime.strptime("2000-01-01", "%Y-%m-%d")
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
# check if the user previously rolled the exact same gacha
|
2024-01-09 19:42:17 +00:00
|
|
|
|
user_gacha = await self.data.item.get_user_gacha(user_id, gacha_id)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
if user_gacha:
|
|
|
|
|
total_gacha_count = user_gacha["totalGachaCnt"]
|
|
|
|
|
ceiling_gacha_count = user_gacha["ceilingGachaCnt"]
|
|
|
|
|
daily_gacha_cnt = user_gacha["dailyGachaCnt"]
|
|
|
|
|
five_gacha_cnt = user_gacha["fiveGachaCnt"]
|
|
|
|
|
eleven_gacha_cnt = user_gacha["elevenGachaCnt"]
|
2023-07-12 09:25:46 +00:00
|
|
|
|
# if the Gacha Select has been used, make sure to keep it
|
|
|
|
|
if user_gacha["useSelectPoint"] == 1:
|
|
|
|
|
use_select_point = 1
|
2023-03-03 22:46:29 +00:00
|
|
|
|
# parse just the year, month and date
|
|
|
|
|
daily_gacha_date = user_gacha["dailyGachaDate"]
|
|
|
|
|
|
|
|
|
|
# if the saved dailyGachaDate is different from the roll,
|
|
|
|
|
# reset dailyGachaCnt and change the date
|
|
|
|
|
if daily_gacha_date != play_date:
|
|
|
|
|
daily_gacha_date = play_date
|
|
|
|
|
daily_gacha_cnt = 0
|
|
|
|
|
|
2024-01-09 19:42:17 +00:00
|
|
|
|
await self.data.item.put_user_gacha(
|
2023-03-03 22:46:29 +00:00
|
|
|
|
user_id,
|
|
|
|
|
gacha_id,
|
|
|
|
|
totalGachaCnt=total_gacha_count + gacha_count,
|
|
|
|
|
ceilingGachaCnt=ceiling_gacha_count + gacha_count,
|
|
|
|
|
selectPoint=select_point,
|
2023-07-12 09:25:46 +00:00
|
|
|
|
useSelectPoint=use_select_point,
|
2023-03-03 22:46:29 +00:00
|
|
|
|
dailyGachaCnt=daily_gacha_cnt + gacha_count,
|
2023-03-09 16:38:58 +00:00
|
|
|
|
fiveGachaCnt=five_gacha_cnt + 1 if gacha_count == 5 else five_gacha_cnt,
|
|
|
|
|
elevenGachaCnt=eleven_gacha_cnt + 1
|
|
|
|
|
if gacha_count == 11
|
|
|
|
|
else eleven_gacha_cnt,
|
|
|
|
|
dailyGachaDate=daily_gacha_date,
|
2023-03-03 22:46:29 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if "userData" in upsert and len(upsert["userData"]) > 0:
|
|
|
|
|
# check if the profile is a bright memory profile
|
2024-01-09 19:42:17 +00:00
|
|
|
|
p = await self.data.profile.get_profile_data(data["userId"], self.version)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
if p is not None:
|
|
|
|
|
# save the bright memory profile
|
2024-01-09 19:42:17 +00:00
|
|
|
|
await self.data.profile.put_profile_data(
|
2023-03-09 16:38:58 +00:00
|
|
|
|
user_id, self.version, upsert["userData"][0]
|
|
|
|
|
)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
else:
|
|
|
|
|
# save the bright profile
|
2024-01-09 19:42:17 +00:00
|
|
|
|
await self.data.profile.put_profile_data(
|
2023-03-09 16:38:58 +00:00
|
|
|
|
user_id, self.version, upsert["userData"][0]
|
|
|
|
|
)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
if "userCharacterList" in upsert:
|
|
|
|
|
for x in upsert["userCharacterList"]:
|
2024-01-09 19:42:17 +00:00
|
|
|
|
await self.data.item.put_character(user_id, x)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
if "userItemList" in upsert:
|
|
|
|
|
for x in upsert["userItemList"]:
|
2024-01-09 19:42:17 +00:00
|
|
|
|
await self.data.item.put_item(user_id, x)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
if "userCardList" in upsert:
|
|
|
|
|
for x in upsert["userCardList"]:
|
2024-01-09 19:42:17 +00:00
|
|
|
|
await self.data.item.put_card(user_id, x)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
# TODO?
|
|
|
|
|
# if "gameGachaCardList" in upsert:
|
|
|
|
|
# for x in upsert["gameGachaCardList"]:
|
|
|
|
|
|
2023-03-09 16:38:58 +00:00
|
|
|
|
return {"returnCode": 1, "apiName": "CMUpsertUserGachaApi"}
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
2024-01-09 08:07:04 +00:00
|
|
|
|
async def handle_cm_upsert_user_select_gacha_api_request(self, data: Dict) -> Dict:
|
2023-03-03 22:46:29 +00:00
|
|
|
|
upsert = data["cmUpsertUserSelectGacha"]
|
|
|
|
|
user_id = data["userId"]
|
|
|
|
|
|
|
|
|
|
if "userData" in upsert and len(upsert["userData"]) > 0:
|
|
|
|
|
# check if the profile is a bright memory profile
|
2024-01-09 19:42:17 +00:00
|
|
|
|
p = await self.data.profile.get_profile_data(data["userId"], self.version)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
if p is not None:
|
|
|
|
|
# save the bright memory profile
|
2024-01-09 19:42:17 +00:00
|
|
|
|
await self.data.profile.put_profile_data(
|
2023-03-09 16:38:58 +00:00
|
|
|
|
user_id, self.version, upsert["userData"][0]
|
|
|
|
|
)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
else:
|
|
|
|
|
# save the bright profile
|
2024-01-09 19:42:17 +00:00
|
|
|
|
await self.data.profile.put_profile_data(
|
2023-03-09 16:38:58 +00:00
|
|
|
|
user_id, self.version, upsert["userData"][0]
|
|
|
|
|
)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
if "userCharacterList" in upsert:
|
|
|
|
|
for x in upsert["userCharacterList"]:
|
2024-01-09 19:42:17 +00:00
|
|
|
|
await self.data.item.put_character(user_id, x)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
if "userCardList" in upsert:
|
|
|
|
|
for x in upsert["userCardList"]:
|
2024-01-09 19:42:17 +00:00
|
|
|
|
await self.data.item.put_card(user_id, x)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
if "selectGachaLogList" in data:
|
|
|
|
|
for x in data["selectGachaLogList"]:
|
2024-01-09 19:42:17 +00:00
|
|
|
|
await self.data.item.put_user_gacha(
|
2023-03-03 22:46:29 +00:00
|
|
|
|
user_id,
|
|
|
|
|
x["gachaId"],
|
|
|
|
|
selectPoint=0,
|
2023-03-09 16:38:58 +00:00
|
|
|
|
useSelectPoint=x["useSelectPoint"],
|
2023-03-03 22:46:29 +00:00
|
|
|
|
)
|
|
|
|
|
|
2023-03-09 16:38:58 +00:00
|
|
|
|
return {"returnCode": 1, "apiName": "cmUpsertUserSelectGacha"}
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
2024-01-09 08:07:04 +00:00
|
|
|
|
async def handle_get_game_gacha_card_by_id_api_request(self, data: Dict) -> Dict:
|
2024-01-09 19:42:17 +00:00
|
|
|
|
game_gacha_cards = await self.data.static.get_gacha_cards(data["gachaId"])
|
2023-03-03 22:46:29 +00:00
|
|
|
|
if game_gacha_cards == []:
|
|
|
|
|
# fallback to be at least able to select that gacha
|
|
|
|
|
return {
|
|
|
|
|
"gachaId": data["gachaId"],
|
|
|
|
|
"length": 6,
|
|
|
|
|
"isPickup": False,
|
|
|
|
|
"gameGachaCardList": [
|
|
|
|
|
{
|
|
|
|
|
"gachaId": data["gachaId"],
|
|
|
|
|
"cardId": 100984,
|
|
|
|
|
"rarity": 4,
|
|
|
|
|
"weight": 1,
|
|
|
|
|
"isPickup": False,
|
2023-03-09 16:38:58 +00:00
|
|
|
|
"isSelect": True,
|
2023-03-03 22:46:29 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"gachaId": data["gachaId"],
|
|
|
|
|
"cardId": 100997,
|
|
|
|
|
"rarity": 3,
|
|
|
|
|
"weight": 2,
|
|
|
|
|
"isPickup": False,
|
2023-03-09 16:38:58 +00:00
|
|
|
|
"isSelect": True,
|
2023-03-03 22:46:29 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"gachaId": data["gachaId"],
|
|
|
|
|
"cardId": 100998,
|
|
|
|
|
"rarity": 3,
|
|
|
|
|
"weight": 2,
|
|
|
|
|
"isPickup": False,
|
2023-03-09 16:38:58 +00:00
|
|
|
|
"isSelect": True,
|
2023-03-03 22:46:29 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"gachaId": data["gachaId"],
|
|
|
|
|
"cardId": 101020,
|
|
|
|
|
"rarity": 2,
|
|
|
|
|
"weight": 3,
|
|
|
|
|
"isPickup": False,
|
2023-03-09 16:38:58 +00:00
|
|
|
|
"isSelect": True,
|
2023-03-03 22:46:29 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"gachaId": data["gachaId"],
|
|
|
|
|
"cardId": 101021,
|
|
|
|
|
"rarity": 2,
|
|
|
|
|
"weight": 3,
|
|
|
|
|
"isPickup": False,
|
2023-03-09 16:38:58 +00:00
|
|
|
|
"isSelect": True,
|
2023-03-03 22:46:29 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"gachaId": data["gachaId"],
|
|
|
|
|
"cardId": 101022,
|
|
|
|
|
"rarity": 2,
|
|
|
|
|
"weight": 3,
|
|
|
|
|
"isPickup": False,
|
2023-03-09 16:38:58 +00:00
|
|
|
|
"isSelect": True,
|
|
|
|
|
},
|
2023-03-03 22:46:29 +00:00
|
|
|
|
],
|
|
|
|
|
"emissionList": [],
|
|
|
|
|
"afterCalcList": [],
|
2023-03-09 16:38:58 +00:00
|
|
|
|
"ssrBookCalcList": [],
|
2023-03-03 22:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
game_gacha_card_list = []
|
|
|
|
|
for gacha_card in game_gacha_cards:
|
|
|
|
|
tmp = gacha_card._asdict()
|
|
|
|
|
tmp.pop("id")
|
|
|
|
|
game_gacha_card_list.append(tmp)
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"gachaId": data["gachaId"],
|
|
|
|
|
"length": len(game_gacha_card_list),
|
|
|
|
|
"isPickup": False,
|
|
|
|
|
"gameGachaCardList": game_gacha_card_list,
|
|
|
|
|
# again no clue
|
|
|
|
|
"emissionList": [],
|
|
|
|
|
"afterCalcList": [],
|
2023-03-09 16:38:58 +00:00
|
|
|
|
"ssrBookCalcList": [],
|
2023-03-03 22:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-09 08:07:04 +00:00
|
|
|
|
async def handle_get_game_theater_api_request(self, data: Dict) -> Dict:
|
2023-03-03 22:46:29 +00:00
|
|
|
|
"""
|
|
|
|
|
shows a banner after every print, not sure what its used for
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
return {
|
|
|
|
|
"length": 1,
|
|
|
|
|
"gameTheaterList": [{
|
|
|
|
|
"theaterId": 1,
|
|
|
|
|
"theaterName": "theaterName",
|
|
|
|
|
"startDate": "2018-01-01 00:00:00.0",
|
|
|
|
|
"endDate": "2038-01-01 00:00:00.0",
|
|
|
|
|
"gameSubTheaterList": [{
|
|
|
|
|
"theaterId": 1,
|
|
|
|
|
"id": 2,
|
|
|
|
|
"no": 4
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"registIdList": []
|
|
|
|
|
}
|
|
|
|
|
"""
|
|
|
|
|
|
2023-03-09 16:38:58 +00:00
|
|
|
|
return {"length": 0, "gameTheaterList": [], "registIdList": []}
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
2024-01-09 08:07:04 +00:00
|
|
|
|
async def handle_cm_upsert_user_print_playlog_api_request(self, data: Dict) -> Dict:
|
2023-03-03 22:46:29 +00:00
|
|
|
|
return {
|
|
|
|
|
"returnCode": 1,
|
|
|
|
|
"orderId": 0,
|
|
|
|
|
"serialId": "11111111111111111111",
|
2023-04-24 01:04:52 +00:00
|
|
|
|
"apiName": "CMUpsertUserPrintPlaylogApi",
|
2023-03-03 22:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-09 08:07:04 +00:00
|
|
|
|
async def handle_cm_upsert_user_printlog_api_request(self, data: Dict) -> Dict:
|
2023-03-03 22:46:29 +00:00
|
|
|
|
return {
|
|
|
|
|
"returnCode": 1,
|
|
|
|
|
"orderId": 0,
|
|
|
|
|
"serialId": "11111111111111111111",
|
2023-04-24 01:04:52 +00:00
|
|
|
|
"apiName": "CMUpsertUserPrintlogApi",
|
2023-03-03 22:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-09 08:07:04 +00:00
|
|
|
|
async def handle_cm_upsert_user_print_api_request(self, data: Dict) -> Dict:
|
2023-03-03 22:46:29 +00:00
|
|
|
|
user_print_detail = data["userPrintDetail"]
|
|
|
|
|
|
|
|
|
|
# generate random serial id
|
2023-03-09 16:38:58 +00:00
|
|
|
|
serial_id = "".join([str(randint(0, 9)) for _ in range(20)])
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
# not needed because are either zero or unset
|
|
|
|
|
user_print_detail.pop("orderId")
|
|
|
|
|
user_print_detail.pop("printNumber")
|
|
|
|
|
user_print_detail.pop("serialId")
|
|
|
|
|
user_print_detail["printDate"] = datetime.strptime(
|
2023-03-09 16:38:58 +00:00
|
|
|
|
user_print_detail["printDate"], "%Y-%m-%d"
|
2023-03-03 22:46:29 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# add the entry to the user print table with the random serialId
|
2024-01-09 19:42:17 +00:00
|
|
|
|
await self.data.item.put_user_print_detail(
|
2023-03-09 16:38:58 +00:00
|
|
|
|
data["userId"], serial_id, user_print_detail
|
2023-03-03 22:46:29 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"returnCode": 1,
|
|
|
|
|
"serialId": serial_id,
|
2023-03-09 16:38:58 +00:00
|
|
|
|
"apiName": "CMUpsertUserPrintApi",
|
2023-03-03 22:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-09 08:07:04 +00:00
|
|
|
|
async def handle_cm_upsert_user_all_api_request(self, data: Dict) -> Dict:
|
2023-03-03 22:46:29 +00:00
|
|
|
|
upsert = data["cmUpsertUserAll"]
|
|
|
|
|
user_id = data["userId"]
|
|
|
|
|
|
|
|
|
|
if "userData" in upsert and len(upsert["userData"]) > 0:
|
|
|
|
|
# check if the profile is a bright memory profile
|
2024-01-09 19:42:17 +00:00
|
|
|
|
p = await self.data.profile.get_profile_data(data["userId"], self.version)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
if p is not None:
|
|
|
|
|
# save the bright memory profile
|
2024-01-09 19:42:17 +00:00
|
|
|
|
await self.data.profile.put_profile_data(
|
2023-03-09 16:38:58 +00:00
|
|
|
|
user_id, self.version, upsert["userData"][0]
|
|
|
|
|
)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
else:
|
|
|
|
|
# save the bright profile
|
2024-01-09 19:42:17 +00:00
|
|
|
|
await self.data.profile.put_profile_data(
|
2023-03-09 16:38:58 +00:00
|
|
|
|
user_id, self.version, upsert["userData"][0]
|
|
|
|
|
)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
if "userActivityList" in upsert:
|
|
|
|
|
for act in upsert["userActivityList"]:
|
2024-01-09 19:42:17 +00:00
|
|
|
|
await self.data.profile.put_profile_activity(
|
2023-03-09 16:38:58 +00:00
|
|
|
|
user_id,
|
|
|
|
|
act["kind"],
|
|
|
|
|
act["id"],
|
|
|
|
|
act["sortNumber"],
|
|
|
|
|
act["param1"],
|
|
|
|
|
act["param2"],
|
|
|
|
|
act["param3"],
|
|
|
|
|
act["param4"],
|
|
|
|
|
)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
if "userItemList" in upsert:
|
|
|
|
|
for x in upsert["userItemList"]:
|
2024-01-09 19:42:17 +00:00
|
|
|
|
await self.data.item.put_item(user_id, x)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
|
|
|
|
if "userCardList" in upsert:
|
|
|
|
|
for x in upsert["userCardList"]:
|
2024-01-09 19:42:17 +00:00
|
|
|
|
await self.data.item.put_card(user_id, x)
|
2023-03-03 22:46:29 +00:00
|
|
|
|
|
2023-03-09 16:38:58 +00:00
|
|
|
|
return {"returnCode": 1, "apiName": "cmUpsertUserAll"}
|