mirror of
https://gitea.tendokyu.moe/Hay1tsme/artemis.git
synced 2026-04-24 15:18:47 -05:00
idac: consolidate common mode result processing across game modes
This commit is contained in:
parent
0d10e445b9
commit
b355fc74c3
|
|
@ -1840,82 +1840,151 @@ class IDACSeason1(IDACBase):
|
|||
await self.data.profile.put_profile(user_id, self.version, data)
|
||||
|
||||
return {"status_code": "0"}
|
||||
|
||||
async def _process_common_mode_result(
|
||||
self,
|
||||
user_id: int,
|
||||
data: Dict,
|
||||
mode_specific_car_count_field: str = None,
|
||||
mode_play_count_field: str = None
|
||||
) -> Dict:
|
||||
"""
|
||||
Process common data updates shared across all game modes.
|
||||
|
||||
Args:
|
||||
user_id: User ID from session
|
||||
data: Request data dict (will be modified in-place by popping values)
|
||||
mode_specific_car_count_field: Optional field name for mode-specific car use count
|
||||
(e.g., 'story_use_count', 'vs_use_count', 'theory_use_count', 'timetrial_use_count')
|
||||
mode_play_count_field: Optional field name for mode-specific play count in tips
|
||||
|
||||
Returns:
|
||||
Dict with processing status and results
|
||||
"""
|
||||
# Check for guest user
|
||||
if user_id == "default":
|
||||
return {"is_guest": True}
|
||||
|
||||
# Extract common data from request
|
||||
stock_data = data.pop("stock_obj", {})
|
||||
ticket_data = data.pop("ticket_data", [])
|
||||
reward_dist_data = data.pop("reward_dist_obj", {})
|
||||
rank_data = data.pop("mode_rank_obj", {})
|
||||
driver_debut_data = data.pop("driver_debut_obj", {})
|
||||
stamp_event_data = data.pop("stamp_event_data", [])
|
||||
|
||||
# save stamp data (only in Season 1, after Season 2 it was moved to it's own request)
|
||||
for stamp in stamp_event_data:
|
||||
await self.data.item.put_stamp(user_id, stamp)
|
||||
|
||||
# save stock data
|
||||
await self._save_stock_data(user_id, stock_data)
|
||||
|
||||
# save tickets
|
||||
for ticket in ticket_data:
|
||||
await self.data.item.put_ticket(user_id, ticket)
|
||||
|
||||
# Merge rank and reward dist data
|
||||
rank_data.update(reward_dist_data)
|
||||
await self.data.profile.put_profile_rank(user_id, self.version, rank_data)
|
||||
|
||||
# Get and update profile data
|
||||
profile = await self.data.profile.get_profile(user_id, self.version)
|
||||
total_play = profile["total_play"] + 1
|
||||
|
||||
profile_updates = {
|
||||
"total_play": total_play,
|
||||
"last_play_date": datetime.now(),
|
||||
"mileage": data.pop("mileage"),
|
||||
"cash": data.pop("cash"),
|
||||
"total_cash": data.pop("total_cash"),
|
||||
"dressup_point": data.pop("dressup_point"),
|
||||
"avatar_point": data.pop("avatar_point"),
|
||||
"aura_id": data.pop("aura_id"),
|
||||
"aura_color_id": data.pop("aura_color_id"),
|
||||
"aura_line_id": data.pop("aura_line_id"),
|
||||
}
|
||||
|
||||
await self.data.profile.put_profile(user_id, self.version, profile_updates)
|
||||
|
||||
# Handle car updates
|
||||
rental_flag = data.get("rental_flag", 0)
|
||||
car_mileage = data.pop("car_mileage", 0)
|
||||
|
||||
# Only process car updates if not a rental (rental_flag exists in Season 3+)
|
||||
if rental_flag == 0:
|
||||
style_car_id = data.get("style_car_id")
|
||||
|
||||
if style_car_id:
|
||||
car_data = await self.data.item.get_car(user_id, self.version, style_car_id)
|
||||
|
||||
car_updates = {
|
||||
"style_car_id": style_car_id,
|
||||
"car_mileage": car_mileage,
|
||||
"use_count": car_data["use_count"] + 1,
|
||||
}
|
||||
|
||||
# Add mode-specific use count if specified
|
||||
if mode_specific_car_count_field:
|
||||
car_updates[mode_specific_car_count_field] = (
|
||||
car_data[mode_specific_car_count_field] + 1
|
||||
)
|
||||
|
||||
# Handle Season 1 tune point/level (if present in data)
|
||||
if "tune_point" in data:
|
||||
car_updates["tune_point"] = data.pop("tune_point", car_data["tune_point"])
|
||||
if "tune_level" in data:
|
||||
car_updates["tune_level"] = data.pop("tune_level", car_data["tune_level"])
|
||||
|
||||
await self.data.item.put_car(user_id, self.version, car_updates)
|
||||
|
||||
if mode_play_count_field:
|
||||
# Update tips play count for the specific mode
|
||||
tips = await self.data.profile.get_profile_tips(user_id, self.version)
|
||||
if tips and mode_play_count_field in tips:
|
||||
await self.data.profile.put_profile_tips(
|
||||
user_id,
|
||||
self.version,
|
||||
{mode_play_count_field: tips[mode_play_count_field] + 1},
|
||||
)
|
||||
|
||||
return {"is_guest": False}
|
||||
|
||||
async def handle_user_updatetimetrialresult_request(
|
||||
self, data: Dict, headers: Dict
|
||||
):
|
||||
user_id = headers["session"]
|
||||
|
||||
stock_data: Dict = data.pop("stock_obj")
|
||||
ticket_data: List = data.pop("ticket_data")
|
||||
reward_dist_data: Dict = data.pop("reward_dist_obj")
|
||||
driver_debut_data = data.pop("driver_debut_obj")
|
||||
rank_data: Dict = data.pop("mode_rank_obj")
|
||||
|
||||
stamp_event_data = data.pop("stamp_event_data", [])
|
||||
for stamp in stamp_event_data:
|
||||
await self.data.item.put_stamp(user_id, stamp)
|
||||
|
||||
# save stock data in database
|
||||
await self._save_stock_data(user_id, stock_data)
|
||||
|
||||
# save tickets in database
|
||||
for ticket in ticket_data:
|
||||
await self.data.item.put_ticket(user_id, ticket)
|
||||
|
||||
# save mode rank data in database
|
||||
rank_data.update(reward_dist_data)
|
||||
await self.data.profile.put_profile_rank(user_id, self.version, rank_data)
|
||||
|
||||
# get the profile data, update total_play and daily_play, and save it
|
||||
profile = await self.data.profile.get_profile(user_id, self.version)
|
||||
total_play = profile["total_play"] + 1
|
||||
|
||||
# update profile
|
||||
await self.data.profile.put_profile(
|
||||
user_id,
|
||||
self.version,
|
||||
{
|
||||
"total_play": total_play,
|
||||
"last_play_date": datetime.now(),
|
||||
"aura_id": data.pop("aura_id"),
|
||||
"aura_color_id": data.pop("aura_color_id"),
|
||||
"aura_line_id": data.pop("aura_line_id"),
|
||||
"cash": data.pop("cash"),
|
||||
"total_cash": data.pop("total_cash"),
|
||||
"dressup_point": data.pop("dressup_point"),
|
||||
"avatar_point": data.pop("avatar_point"),
|
||||
"mileage": data.pop("mileage"),
|
||||
},
|
||||
# Process common data shared across all game modes
|
||||
result = await self._process_common_mode_result(
|
||||
user_id,
|
||||
data,
|
||||
"timetrial_use_count",
|
||||
"timetrial_play_count"
|
||||
)
|
||||
|
||||
# get the use_count and story_use_count of the used car
|
||||
style_car_id = data.get("style_car_id")
|
||||
car_id = data.pop("car_id", style_car_id)
|
||||
car_mileage = data.pop("car_mileage")
|
||||
used_car = await self.data.item.get_car(user_id, self.version, style_car_id)
|
||||
used_car = used_car._asdict()
|
||||
|
||||
# increase the use_count and story_use_count of the used car
|
||||
used_car["use_count"] += 1
|
||||
used_car["timetrial_use_count"] += 1
|
||||
used_car["car_mileage"] = car_mileage
|
||||
|
||||
# save the used car in database
|
||||
await self.data.item.put_car(user_id, self.version, used_car)
|
||||
|
||||
# skill_level_exp is the "course proeficiency" and is saved
|
||||
# in the course table
|
||||
|
||||
# Early return for guest users
|
||||
if result["is_guest"]:
|
||||
return {
|
||||
"status_code": "0",
|
||||
"course_rank": 0,
|
||||
"course_car_rank": 0,
|
||||
"location_course_store_rank": 0,
|
||||
"car_use_count": [],
|
||||
"maker_use_count": [],
|
||||
}
|
||||
|
||||
# Time trial-specific logic starts here
|
||||
|
||||
# Handle course proficiency (skill_level_exp)
|
||||
course_id = data.get("course_id")
|
||||
run_counts = 1
|
||||
skill_level_exp = data.pop("skill_level_exp")
|
||||
|
||||
# get the course data
|
||||
run_counts = 1
|
||||
|
||||
course = await self.data.item.get_course(user_id, course_id)
|
||||
if course:
|
||||
# update run_counts
|
||||
run_counts = course["run_counts"] + 1
|
||||
|
||||
|
||||
await self.data.item.put_course(
|
||||
user_id,
|
||||
{
|
||||
|
|
@ -1924,49 +1993,38 @@ class IDACSeason1(IDACBase):
|
|||
"skill_level_exp": skill_level_exp,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
# Calculate rankings
|
||||
style_car_id = data.get("style_car_id")
|
||||
goal_time = data.get("goal_time")
|
||||
# grab the ranking data and count the numbers of rows with a faster time
|
||||
# than the current goal_time
|
||||
|
||||
course_rank = await self.data.item.get_time_trial_ranking_by_course(
|
||||
self.version, course_id, limit=None
|
||||
)
|
||||
course_rank = len([r for r in course_rank if r["goal_time"] < goal_time]) + 1
|
||||
|
||||
|
||||
car_course_rank = await self.data.item.get_time_trial_ranking_by_course(
|
||||
self.version, course_id, style_car_id, limit=None
|
||||
)
|
||||
car_course_rank = (
|
||||
len([r for r in car_course_rank if r["goal_time"] < goal_time]) + 1
|
||||
)
|
||||
|
||||
# only update the time if its better than the best time and also not 0
|
||||
if data.get("goal_time") > 0:
|
||||
# get the current best goal time
|
||||
|
||||
# Save best time if improved (and goal_time > 0)
|
||||
if goal_time > 0:
|
||||
best_time_trial = (
|
||||
await self.data.item.get_time_trial_user_best_time_by_course_car(
|
||||
self.version, user_id, course_id, style_car_id
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if (
|
||||
best_time_trial is None
|
||||
or data.get("goal_time") < best_time_trial["goal_time"]
|
||||
or goal_time < best_time_trial["goal_time"]
|
||||
):
|
||||
# now finally save the time trial with updated timestamp
|
||||
data["play_dt"] = datetime.now()
|
||||
await self.data.item.put_time_trial(self.version, user_id, data)
|
||||
|
||||
ver_str = self._headers_to_version(headers)
|
||||
|
||||
# update the tips play count
|
||||
tips = await self.data.profile.get_profile_tips(user_id, self.version)
|
||||
await self.data.profile.put_profile_tips(
|
||||
user_id,
|
||||
self.version,
|
||||
{"timetrial_play_count": tips["timetrial_play_count"] + 1},
|
||||
)
|
||||
|
||||
|
||||
return {
|
||||
"status_code": "0",
|
||||
"course_rank": course_rank,
|
||||
|
|
@ -1979,27 +2037,20 @@ class IDACSeason1(IDACBase):
|
|||
async def handle_user_updatestoryresult_request(self, data: Dict, headers: Dict):
|
||||
user_id = headers["session"]
|
||||
|
||||
stock_data: Dict = data.pop("stock_obj")
|
||||
ticket_data: List = data.pop("ticket_data")
|
||||
reward_dist_data: Dict = data.pop("reward_dist_obj")
|
||||
driver_debut_data = data.pop("driver_debut_obj")
|
||||
rank_data: Dict = data.pop("mode_rank_obj")
|
||||
|
||||
stamp_event_data = data.pop("stamp_event_data", [])
|
||||
|
||||
for stamp in stamp_event_data:
|
||||
await self.data.item.put_stamp(user_id, stamp)
|
||||
|
||||
# save stock data in database
|
||||
await self._save_stock_data(user_id, stock_data)
|
||||
|
||||
# save tickets in database
|
||||
for ticket in ticket_data:
|
||||
await self.data.item.put_ticket(user_id, ticket)
|
||||
|
||||
# save mode rank data in database
|
||||
rank_data.update(reward_dist_data)
|
||||
await self.data.profile.put_profile_rank(user_id, self.version, rank_data)
|
||||
result = await self._process_common_mode_result(
|
||||
user_id,
|
||||
data,
|
||||
"story_use_count",
|
||||
"story_play_count"
|
||||
)
|
||||
|
||||
if result["is_guest"]:
|
||||
return {
|
||||
"status_code": "0",
|
||||
"story_data": [],
|
||||
"car_use_count": [],
|
||||
"maker_use_count": [],
|
||||
}
|
||||
|
||||
# save the current story progress in database
|
||||
max_loop = data.get("chapter_loop_max")
|
||||
|
|
@ -2068,55 +2119,6 @@ class IDACSeason1(IDACBase):
|
|||
},
|
||||
)
|
||||
|
||||
# get the use_count and story_use_count of the used car
|
||||
style_car_id = data.get("style_car_id")
|
||||
car_mileage = data.get("car_mileage")
|
||||
used_car = await self.data.item.get_car(user_id, self.version, style_car_id)
|
||||
used_car = used_car._asdict()
|
||||
|
||||
# for season 1 tune point and tune level handling
|
||||
tune_point = data.pop("tune_point", used_car["tune_point"])
|
||||
tune_level = data.pop("tune_level", used_car["tune_level"])
|
||||
|
||||
used_car["tune_point"] = tune_point
|
||||
used_car["tune_level"] = tune_level
|
||||
|
||||
# increase the use_count and story_use_count of the used car
|
||||
used_car["use_count"] += 1
|
||||
used_car["story_use_count"] += 1
|
||||
used_car["car_mileage"] = car_mileage
|
||||
|
||||
# save the used car in database
|
||||
await self.data.item.put_car(user_id, self.version, used_car)
|
||||
|
||||
# get the profile data, update total_play and daily_play, and save it
|
||||
profile = await self.data.profile.get_profile(user_id, self.version)
|
||||
total_play = profile["total_play"] + 1
|
||||
|
||||
# save user profile in database
|
||||
await self.data.profile.put_profile(
|
||||
user_id,
|
||||
self.version,
|
||||
{
|
||||
"total_play": total_play,
|
||||
"last_play_date": datetime.now(),
|
||||
"mileage": data.pop("mileage"),
|
||||
"cash": data.pop("cash"),
|
||||
"total_cash": data.pop("total_cash"),
|
||||
"dressup_point": data.pop("dressup_point"),
|
||||
"avatar_point": data.pop("avatar_point"),
|
||||
"aura_id": data.pop("aura_id"),
|
||||
"aura_color_id": data.pop("aura_color_id"),
|
||||
"aura_line_id": data.pop("aura_line_id"),
|
||||
},
|
||||
)
|
||||
|
||||
# update the tips play count
|
||||
tips = await self.data.profile.get_profile_tips(user_id, self.version)
|
||||
await self.data.profile.put_profile_tips(
|
||||
user_id, self.version, {"story_play_count": tips["story_play_count"] + 1}
|
||||
)
|
||||
|
||||
return {
|
||||
"status_code": "0",
|
||||
"story_data": await self._generate_story_data(user_id),
|
||||
|
|
@ -2128,91 +2130,32 @@ class IDACSeason1(IDACBase):
|
|||
self, data: Dict, headers: Dict
|
||||
):
|
||||
user_id = headers["session"]
|
||||
|
||||
stock_data: Dict = data.pop("stock_obj")
|
||||
ticket_data: List = data.pop("ticket_data")
|
||||
reward_dist_data: Dict = data.pop("reward_dist_obj")
|
||||
driver_debut_data = data.pop("driver_debut_obj")
|
||||
rank_data: Dict = data.pop("mode_rank_obj")
|
||||
|
||||
rental_flag = data.get("rental_flag", 0)
|
||||
car_mileage = data.pop("car_mileage", 0)
|
||||
style_car_id = data.pop("style_car_id")
|
||||
|
||||
stamp_event_data = data.pop("stamp_event_data", [])
|
||||
|
||||
for stamp in stamp_event_data:
|
||||
await self.data.item.put_stamp(user_id, stamp)
|
||||
|
||||
# unused
|
||||
hint_display_flag: int = data.pop("hint_display_flag", 0)
|
||||
|
||||
# only save car data if not a rental car
|
||||
if rental_flag == 0:
|
||||
# get the vs use count from database and update it
|
||||
car_data = await self.data.item.get_car(user_id, self.version, style_car_id)
|
||||
story_use_count = car_data["story_use_count"] + 1
|
||||
|
||||
# for season 1 tune point and tune level handling
|
||||
tune_point = data.pop("tune_point", car_data["tune_point"])
|
||||
tune_level = data.pop("tune_level", car_data["tune_level"])
|
||||
|
||||
await self.data.item.put_car(
|
||||
user_id,
|
||||
self.version,
|
||||
{
|
||||
"style_car_id": style_car_id,
|
||||
"car_mileage": car_mileage,
|
||||
"story_use_count": story_use_count,
|
||||
"tune_point": tune_point,
|
||||
"tune_level": tune_level,
|
||||
},
|
||||
)
|
||||
|
||||
# get the profile data, update total_play and daily_play, and save it
|
||||
profile = await self.data.profile.get_profile(user_id, self.version)
|
||||
total_play = profile["total_play"] + 1
|
||||
|
||||
# save user profile in database
|
||||
await self.data.profile.put_profile(
|
||||
user_id,
|
||||
self.version,
|
||||
{
|
||||
"total_play": total_play,
|
||||
"last_play_date": datetime.now(),
|
||||
"mileage": data.pop("mileage"),
|
||||
"cash": data.pop("cash"),
|
||||
"total_cash": data.pop("total_cash"),
|
||||
"dressup_point": data.pop("dressup_point"),
|
||||
"avatar_point": data.pop("avatar_point"),
|
||||
"aura_id": data.pop("aura_id"),
|
||||
"aura_color_id": data.pop("aura_color_id"),
|
||||
"aura_line_id": data.pop("aura_line_id"),
|
||||
},
|
||||
# Process common data shared across all game modes
|
||||
result = await self._process_common_mode_result(
|
||||
user_id,
|
||||
data,
|
||||
"story_use_count",
|
||||
"special_play_count"
|
||||
)
|
||||
|
||||
# save stock data in database
|
||||
await self._save_stock_data(user_id, stock_data)
|
||||
|
||||
# save ticket data in database
|
||||
for ticket in ticket_data:
|
||||
await self.data.item.put_ticket(user_id, ticket)
|
||||
|
||||
# save mode_rank and reward_dist data in database
|
||||
rank_data.update(reward_dist_data)
|
||||
await self.data.profile.put_profile_rank(user_id, self.version, rank_data)
|
||||
|
||||
# finally save the special mode with story_type=4 in database
|
||||
|
||||
# Early return for guest users
|
||||
if result["is_guest"]:
|
||||
return {
|
||||
"status_code": "0",
|
||||
"special_mode_data": [],
|
||||
"car_use_count": [],
|
||||
"maker_use_count": [],
|
||||
}
|
||||
|
||||
# Special mode-specific logic starts here
|
||||
|
||||
# Remove unused hint_display_flag
|
||||
hint_display_flag = data.pop("hint_display_flag", 0)
|
||||
|
||||
# Save the special mode challenge data
|
||||
await self.data.item.put_challenge(user_id, data)
|
||||
|
||||
# update the tips play count
|
||||
tips = await self.data.profile.get_profile_tips(user_id, self.version)
|
||||
await self.data.profile.put_profile_tips(
|
||||
user_id,
|
||||
self.version,
|
||||
{"special_play_count": tips["special_play_count"] + 1},
|
||||
)
|
||||
|
||||
|
||||
return {
|
||||
"status_code": "0",
|
||||
"special_mode_data": await self._generate_special_data(user_id, headers),
|
||||
|
|
@ -2566,53 +2509,54 @@ class IDACSeason1(IDACBase):
|
|||
|
||||
async def handle_user_updatetheoryresult_request(self, data: Dict, headers: Dict):
|
||||
user_id = headers["session"]
|
||||
|
||||
stock_data: Dict = data.pop("stock_obj")
|
||||
ticket_data: List = data.pop("ticket_data")
|
||||
reward_dist_data: Dict = data.pop("reward_dist_obj")
|
||||
rank_data: Dict = data.pop("mode_rank_obj")
|
||||
driver_debut_data: Dict = data.pop("driver_debut_obj")
|
||||
|
||||
stamp_event_data = data.pop("stamp_event_data", [])
|
||||
|
||||
for stamp in stamp_event_data:
|
||||
await self.data.item.put_stamp(user_id, stamp)
|
||||
|
||||
# save stock data in database
|
||||
await self._save_stock_data(user_id, stock_data)
|
||||
|
||||
# save tickets in database
|
||||
for ticket in ticket_data:
|
||||
await self.data.item.put_ticket(user_id, ticket)
|
||||
|
||||
# save rank dist data in database
|
||||
rank_data.update(reward_dist_data)
|
||||
await self.data.profile.put_profile_rank(user_id, self.version, rank_data)
|
||||
|
||||
# save the profile theory data in database
|
||||
# Process common data shared across all game modes
|
||||
result = await self._process_common_mode_result(
|
||||
user_id,
|
||||
data,
|
||||
"theory_use_count",
|
||||
"theory_play_count"
|
||||
)
|
||||
|
||||
# Early return for guest users
|
||||
if result["is_guest"]:
|
||||
return {
|
||||
"status_code": "0",
|
||||
"played_powerhouse_lv": 0,
|
||||
"car_use_count": [],
|
||||
"maker_use_count": [],
|
||||
"play_count": 0,
|
||||
"play_count_multi": 0,
|
||||
"win_count": 0,
|
||||
"win_count_multi": 0,
|
||||
}
|
||||
|
||||
# Theory-specific logic starts here
|
||||
|
||||
# Calculate play and win counts
|
||||
play_count = 1
|
||||
play_count_multi = 1
|
||||
win_count = 0
|
||||
win_count_multi = 0
|
||||
|
||||
|
||||
theory_data = await self.data.profile.get_profile_theory(user_id, self.version)
|
||||
if theory_data:
|
||||
play_count = theory_data["play_count"] + 1
|
||||
play_count_multi = theory_data["play_count_multi"] + 1
|
||||
win_count = theory_data["win_count"]
|
||||
win_count_multi = theory_data["win_count_multi"]
|
||||
|
||||
# check all advantages and see if one of them is larger than 0
|
||||
# if so, we won
|
||||
|
||||
# Check all advantages - if any > 0, player won
|
||||
if (
|
||||
data.get("advantage_1") > 0
|
||||
or data.get("advantage_2") > 0
|
||||
or data.get("advantage_3") > 0
|
||||
or data.get("advantage_4") > 0
|
||||
data.get("advantage_1", 0) > 0
|
||||
or data.get("advantage_2", 0) > 0
|
||||
or data.get("advantage_3", 0) > 0
|
||||
or data.get("advantage_4", 0) > 0
|
||||
):
|
||||
win_count += 1
|
||||
win_count_multi += 1
|
||||
|
||||
|
||||
# Save profile theory data
|
||||
await self.data.profile.put_profile_theory(
|
||||
user_id,
|
||||
self.version,
|
||||
|
|
@ -2625,29 +2569,26 @@ class IDACSeason1(IDACBase):
|
|||
"practice_start_rank": data.get("practice_start_rank"),
|
||||
"general_flag": data.get("general_flag"),
|
||||
"vs_history": data.get("vs_history"),
|
||||
# no idea?
|
||||
"vs_history_multi": data.get("vs_history"),
|
||||
"win_count": win_count,
|
||||
"win_count_multi": win_count_multi,
|
||||
},
|
||||
)
|
||||
|
||||
# save theory course in database
|
||||
|
||||
# Save theory course data
|
||||
await self.data.item.put_theory_course(
|
||||
user_id,
|
||||
{
|
||||
"course_id": data.get("course_id"),
|
||||
"max_victory_grade": data.get("max_victory_grade"),
|
||||
# always add 1?
|
||||
"run_count": 1,
|
||||
"powerhouse_lv": data.get("powerhouse_lv"),
|
||||
"powerhouse_exp": data.get("powerhouse_exp"),
|
||||
# not sure if the played_powerhouse_lv is the same as powerhouse_lv
|
||||
"played_powerhouse_lv": data.get("powerhouse_lv"),
|
||||
},
|
||||
)
|
||||
|
||||
# save the theory partner in database
|
||||
|
||||
# Save theory partner data
|
||||
await self.data.item.put_theory_partner(
|
||||
user_id,
|
||||
{
|
||||
|
|
@ -2656,8 +2597,8 @@ class IDACSeason1(IDACBase):
|
|||
"fellowship_exp": data.get("fellowship_exp"),
|
||||
},
|
||||
)
|
||||
|
||||
# save the theory running in database?
|
||||
|
||||
# Save theory running data
|
||||
await self.data.item.put_theory_running(
|
||||
user_id,
|
||||
{
|
||||
|
|
@ -2669,49 +2610,7 @@ class IDACSeason1(IDACBase):
|
|||
"trick_flag": data.get("trick_flag"),
|
||||
},
|
||||
)
|
||||
|
||||
# get the use_count and theory_use_count of the used car
|
||||
style_car_id = data.get("style_car_id")
|
||||
car_mileage = data.get("car_mileage")
|
||||
used_car = await self.data.item.get_car(user_id, self.version, style_car_id)
|
||||
used_car = used_car._asdict()
|
||||
|
||||
# increase the use_count and theory_use_count of the used car
|
||||
used_car["use_count"] += 1
|
||||
used_car["theory_use_count"] += 1
|
||||
used_car["car_mileage"] = car_mileage
|
||||
|
||||
# save the used car in database
|
||||
await self.data.item.put_car(user_id, self.version, used_car)
|
||||
|
||||
# get the profile data, update total_play and daily_play, and save it
|
||||
profile = await self.data.profile.get_profile(user_id, self.version)
|
||||
total_play = profile["total_play"] + 1
|
||||
|
||||
# save the profile in database
|
||||
await self.data.profile.put_profile(
|
||||
user_id,
|
||||
self.version,
|
||||
{
|
||||
"total_play": total_play,
|
||||
"last_play_date": datetime.now(),
|
||||
"mileage": data.get("mileage"),
|
||||
"aura_id": data.get("aura_id"),
|
||||
"aura_color_id": data.get("aura_color_id"),
|
||||
"aura_line_id": data.get("aura_line_id"),
|
||||
"cash": data.get("cash"),
|
||||
"total_cash": data.get("total_cash"),
|
||||
"dressup_point": data.get("dressup_point"),
|
||||
"avatar_point": data.get("avatar_point"),
|
||||
},
|
||||
)
|
||||
|
||||
# update the tips play count
|
||||
tips = await self.data.profile.get_profile_tips(user_id, self.version)
|
||||
await self.data.profile.put_profile_tips(
|
||||
user_id, self.version, {"theory_play_count": tips["theory_play_count"] + 1}
|
||||
)
|
||||
|
||||
|
||||
return {
|
||||
"status_code": "0",
|
||||
"played_powerhouse_lv": data.get("powerhouse_lv"),
|
||||
|
|
@ -2734,81 +2633,37 @@ class IDACSeason1(IDACBase):
|
|||
self, data: Dict, headers: Dict
|
||||
):
|
||||
user_id = headers["session"]
|
||||
|
||||
stamp_event_data = data.pop("stamp_event_data", [])
|
||||
|
||||
for stamp in stamp_event_data:
|
||||
await self.data.item.put_stamp(user_id, stamp)
|
||||
|
||||
stock_data: Dict = data.pop("stock_obj")
|
||||
# save stock data in database
|
||||
await self._save_stock_data(user_id, stock_data)
|
||||
|
||||
ticket_data: List = data.pop("ticket_data")
|
||||
for ticket in ticket_data:
|
||||
await self.data.item.put_ticket(user_id, ticket)
|
||||
|
||||
reward_dist_data: Dict = data.pop("reward_dist_obj")
|
||||
rank_data: Dict = data.pop("mode_rank_obj")
|
||||
|
||||
# save rank dist data in database
|
||||
rank_data.update(reward_dist_data)
|
||||
await self.data.profile.put_profile_rank(user_id, self.version, rank_data)
|
||||
|
||||
driver_debut_data = data.pop("driver_debut_obj")
|
||||
|
||||
# get the use_count and net_vs_use_count of the used car
|
||||
style_car_id = data.get("style_car_id")
|
||||
car_mileage = data.pop("car_mileage")
|
||||
used_car = await self.data.item.get_car(user_id, self.version, style_car_id)
|
||||
used_car = used_car._asdict()
|
||||
|
||||
# increase the use_count and net_vs_use_count of the used car
|
||||
used_car["use_count"] += 1
|
||||
used_car["net_vs_use_count"] += 1
|
||||
used_car["car_mileage"] = car_mileage
|
||||
|
||||
# save the used car in database
|
||||
await self.data.item.put_car(user_id, self.version, used_car)
|
||||
|
||||
# get the profile data, update total_play and daily_play, and save it
|
||||
profile = await self.data.profile.get_profile(user_id, self.version)
|
||||
total_play = profile["total_play"] + 1
|
||||
|
||||
# save the profile in database
|
||||
await self.data.profile.put_profile(
|
||||
user_id,
|
||||
self.version,
|
||||
{
|
||||
"total_play": total_play,
|
||||
"last_play_date": datetime.now(),
|
||||
"mileage": data.pop("mileage"),
|
||||
"aura_id": data.pop("aura_id"),
|
||||
"aura_color_id": data.pop("aura_color_id"),
|
||||
"aura_line_id": data.pop("aura_line_id"),
|
||||
"cash": data.pop("cash"),
|
||||
"total_cash": data.pop("total_cash"),
|
||||
"dressup_point": data.pop("dressup_point"),
|
||||
"avatar_point": data.pop("avatar_point"),
|
||||
},
|
||||
# Process common data shared across all game modes
|
||||
result = await self._process_common_mode_result(
|
||||
user_id,
|
||||
data,
|
||||
"net_vs_use_count",
|
||||
"online_battle_play_count"
|
||||
)
|
||||
|
||||
|
||||
# Early return for guest users (even though they shouldn't reach here lol)
|
||||
if result["is_guest"]:
|
||||
return {
|
||||
"status_code": "0",
|
||||
"vsinfo_data": {},
|
||||
"round_event": [],
|
||||
"car_use_count": [],
|
||||
"maker_use_count": [],
|
||||
}
|
||||
|
||||
# Online battle-specific logic starts here
|
||||
|
||||
# Update VS info for online battles
|
||||
vs_info = await self._update_vs_info(
|
||||
user_id, IDACConstants.BATTLE_MODE_ONLINE, data
|
||||
)
|
||||
|
||||
# update the tips play count
|
||||
tips = await self.data.profile.get_profile_tips(user_id, self.version)
|
||||
await self.data.profile.put_profile_tips(
|
||||
user_id,
|
||||
self.version,
|
||||
{"online_battle_play_count": tips["online_battle_play_count"] + 1},
|
||||
)
|
||||
|
||||
|
||||
# Update round event info
|
||||
round_info = await self._update_round_info(
|
||||
user_id, self.round_event_id, data.pop("round_point"), data.pop("win_flg")
|
||||
)
|
||||
|
||||
|
||||
return {
|
||||
"status_code": "0",
|
||||
"vsinfo_data": vs_info,
|
||||
|
|
@ -2821,91 +2676,46 @@ class IDACSeason1(IDACBase):
|
|||
self, data: Dict, headers: Dict
|
||||
):
|
||||
user_id = headers["session"]
|
||||
|
||||
stock_data: Dict = data.pop("stock_obj")
|
||||
ticket_data: List = data.pop("ticket_data")
|
||||
reward_dist_data: Dict = data.pop("reward_dist_obj")
|
||||
rank_data: Dict = data.pop("mode_rank_obj")
|
||||
driver_debut_data: Dict = data.pop("driver_debut_obj")
|
||||
|
||||
stamp_event_data = data.pop("stamp_event_data", [])
|
||||
|
||||
for stamp in stamp_event_data:
|
||||
await self.data.item.put_stamp(user_id, stamp)
|
||||
|
||||
# save the received battle gift in database, hopefully that works
|
||||
battle_gift_event_id = data.pop("battle_gift_event_id")
|
||||
gift_id = data.pop("gift_id")
|
||||
|
||||
await self.data.item.put_battle_gift(
|
||||
user_id,
|
||||
{
|
||||
"battle_gift_event_id": battle_gift_event_id,
|
||||
"gift_id": gift_id,
|
||||
"gift_status": 1, # aquired
|
||||
},
|
||||
# Extract battle gift data before common processing (it's mode-specific)
|
||||
battle_gift_event_id = data.pop("battle_gift_event_id", None)
|
||||
gift_id = data.pop("gift_id", None)
|
||||
|
||||
# Process common data shared across all game modes
|
||||
result = await self._process_common_mode_result(
|
||||
user_id,
|
||||
data,
|
||||
"vs_use_count",
|
||||
"store_battle_play_count"
|
||||
)
|
||||
|
||||
# save stock data in database
|
||||
await self._save_stock_data(user_id, stock_data)
|
||||
|
||||
# save tickets in database
|
||||
for ticket in ticket_data:
|
||||
await self.data.item.put_ticket(user_id, ticket)
|
||||
|
||||
# save rank dist data in database
|
||||
rank_data.update(reward_dist_data)
|
||||
await self.data.profile.put_profile_rank(user_id, self.version, rank_data)
|
||||
|
||||
# get the use_count and net_vs_use_count of the used car
|
||||
style_car_id = data.get("style_car_id")
|
||||
car_mileage = data.pop("car_mileage")
|
||||
used_car = await self.data.item.get_car(user_id, self.version, style_car_id)
|
||||
used_car = used_car._asdict()
|
||||
|
||||
# increase the use_count and net_vs_use_count of the used car
|
||||
used_car["use_count"] += 1
|
||||
used_car["vs_use_count"] += 1
|
||||
used_car["car_mileage"] = car_mileage
|
||||
|
||||
# save the used car in database
|
||||
await self.data.item.put_car(user_id, self.version, used_car)
|
||||
|
||||
# get the profile data, update total_play and daily_play, and save it
|
||||
profile = await self.data.profile.get_profile(user_id, self.version)
|
||||
total_play = profile["total_play"] + 1
|
||||
|
||||
# save the profile in database
|
||||
await self.data.profile.put_profile(
|
||||
user_id,
|
||||
self.version,
|
||||
{
|
||||
"total_play": total_play,
|
||||
"last_play_date": datetime.now(),
|
||||
"mileage": data.pop("mileage"),
|
||||
"aura_id": data.pop("aura_id"),
|
||||
"aura_color_id": data.pop("aura_color_id"),
|
||||
"aura_line_id": data.pop("aura_line_id"),
|
||||
"cash": data.pop("cash"),
|
||||
"total_cash": data.pop("total_cash"),
|
||||
"dressup_point": data.pop("dressup_point"),
|
||||
"avatar_point": data.pop("avatar_point"),
|
||||
},
|
||||
)
|
||||
|
||||
# save vs_info in database
|
||||
|
||||
# Early return for guest users
|
||||
if result["is_guest"]:
|
||||
return {
|
||||
"status_code": "0",
|
||||
"vsinfo_data": {},
|
||||
"car_use_count": [],
|
||||
"maker_use_count": [],
|
||||
}
|
||||
|
||||
# Store battle-specific logic starts here
|
||||
|
||||
# Save battle gift if present
|
||||
if battle_gift_event_id is not None and gift_id is not None:
|
||||
await self.data.item.put_battle_gift(
|
||||
user_id,
|
||||
{
|
||||
"battle_gift_event_id": battle_gift_event_id,
|
||||
"gift_id": gift_id,
|
||||
"gift_status": 1, # acquired
|
||||
},
|
||||
)
|
||||
|
||||
# Update VS info for offline/store battles
|
||||
vs_info = await self._update_vs_info(
|
||||
user_id, IDACConstants.BATTLE_MODE_OFFLINE, data
|
||||
)
|
||||
|
||||
# update the tips play count
|
||||
tips = await self.data.profile.get_profile_tips(user_id, self.version)
|
||||
await self.data.profile.put_profile_tips(
|
||||
user_id,
|
||||
self.version,
|
||||
{"store_battle_play_count": tips["store_battle_play_count"] + 1},
|
||||
)
|
||||
|
||||
|
||||
return {
|
||||
"status_code": "0",
|
||||
"vsinfo_data": vs_info,
|
||||
|
|
|
|||
|
|
@ -335,62 +335,26 @@ class IDACSeason2(IDACSeason1):
|
|||
self, data: Dict, headers: Dict
|
||||
):
|
||||
user_id = headers["session"]
|
||||
|
||||
stock_data: Dict = data.pop("stock_obj")
|
||||
ticket_data: List = data.pop("ticket_data")
|
||||
reward_dist_data: Dict = data.pop("reward_dist_obj")
|
||||
driver_debut_data = data.pop("driver_debut_obj")
|
||||
rank_data: Dict = data.pop("mode_rank_obj")
|
||||
|
||||
# get the vs use count from database and update it
|
||||
style_car_id = data.get("style_car_id")
|
||||
car_data = await self.data.item.get_car(user_id, self.version, style_car_id)
|
||||
story_use_count = car_data["story_use_count"] + 1
|
||||
|
||||
# save car data in database
|
||||
await self.data.item.put_car(
|
||||
user_id,
|
||||
self.version,
|
||||
{
|
||||
"style_car_id": style_car_id,
|
||||
"car_mileage": data.pop("car_mileage"),
|
||||
"story_use_count": story_use_count,
|
||||
},
|
||||
|
||||
# Process common data shared across all game modes
|
||||
result = await self._process_common_mode_result(
|
||||
user_id,
|
||||
data,
|
||||
"story_use_count",
|
||||
"challenge_play_count"
|
||||
)
|
||||
|
||||
# get the profile data, update total_play and daily_play, and save it
|
||||
profile = await self.data.profile.get_profile(user_id, self.version)
|
||||
total_play = profile["total_play"] + 1
|
||||
|
||||
# save user profile in database
|
||||
await self.data.profile.put_profile(
|
||||
user_id,
|
||||
self.version,
|
||||
{
|
||||
"total_play": total_play,
|
||||
"last_play_date": datetime.now(),
|
||||
"mileage": data.pop("mileage"),
|
||||
"cash": data.pop("cash"),
|
||||
"total_cash": data.pop("total_cash"),
|
||||
"dressup_point": data.pop("dressup_point"),
|
||||
"avatar_point": data.pop("avatar_point"),
|
||||
"aura_id": data.pop("aura_id"),
|
||||
"aura_color_id": data.pop("aura_color_id"),
|
||||
"aura_line_id": data.pop("aura_line_id"),
|
||||
},
|
||||
)
|
||||
|
||||
# save stock data in database
|
||||
await self._save_stock_data(user_id, stock_data)
|
||||
|
||||
# save ticket data in database
|
||||
for ticket in ticket_data:
|
||||
await self.data.item.put_ticket(user_id, ticket)
|
||||
|
||||
# save mode_rank and reward_dist data in database
|
||||
rank_data.update(reward_dist_data)
|
||||
await self.data.profile.put_profile_rank(user_id, self.version, rank_data)
|
||||
|
||||
|
||||
# Early return for guest users
|
||||
if result["is_guest"]:
|
||||
return {
|
||||
"status_code": "0",
|
||||
"challenge_mode_data": [],
|
||||
"car_use_count": [],
|
||||
"maker_use_count": [],
|
||||
}
|
||||
|
||||
# Challenge mode-specific logic starts here
|
||||
|
||||
# get the challenge mode data from database
|
||||
challenge_data = await self.data.item.get_challenge(
|
||||
user_id, data.get("vs_type"), data.get("play_difficulty")
|
||||
|
|
@ -404,14 +368,6 @@ class IDACSeason2(IDACSeason1):
|
|||
# finally save the challenge mode with story_type=3 in database
|
||||
await self.data.item.put_challenge(user_id, data)
|
||||
|
||||
# update the tips play count
|
||||
tips = await self.data.profile.get_profile_tips(user_id, self.version)
|
||||
await self.data.profile.put_profile_tips(
|
||||
user_id,
|
||||
self.version,
|
||||
{"challenge_play_count": tips["challenge_play_count"] + 1},
|
||||
)
|
||||
|
||||
return {
|
||||
"status_code": "0",
|
||||
"challenge_mode_data": await self._generate_challenge_data(user_id),
|
||||
|
|
|
|||
|
|
@ -299,8 +299,17 @@ class IDACSeason4(IDACSeason3):
|
|||
self, data: Dict, headers: Dict
|
||||
):
|
||||
user_id = headers["session"]
|
||||
|
||||
if user_id == "default":
|
||||
|
||||
# Process common data shared across all game modes
|
||||
result = await self._process_common_mode_result(
|
||||
user_id,
|
||||
data,
|
||||
"story_use_count",
|
||||
"special_play_count"
|
||||
)
|
||||
|
||||
# Early return for guest users
|
||||
if result["is_guest"]:
|
||||
return {
|
||||
"status_code": "0",
|
||||
"expansion_mode_data": [],
|
||||
|
|
@ -308,68 +317,16 @@ class IDACSeason4(IDACSeason3):
|
|||
"maker_use_count": [],
|
||||
}
|
||||
|
||||
# Expansion mode-specific logic starts here
|
||||
|
||||
league_info = await self._process_team_parameters_and_update_league(user_id, data)
|
||||
|
||||
stock_data: Dict = data.pop("stock_obj")
|
||||
ticket_data: List = data.pop("ticket_data")
|
||||
reward_dist_data: Dict = data.pop("reward_dist_obj")
|
||||
driver_debut_data = data.pop("driver_debut_obj")
|
||||
rank_data: Dict = data.pop("mode_rank_obj")
|
||||
next_position_id_list_data: List = data.pop("next_position_id_list") # this tells us which positions are unlocked, we'll have to add them ourselves
|
||||
|
||||
|
||||
next_position_id_list_data: List = data.pop("next_position_id_list")
|
||||
|
||||
# Store content_id and map_id for creating new positions
|
||||
content_id = data.get("content_id")
|
||||
map_id = data.get("map_id")
|
||||
|
||||
# get the car use count from database and update it
|
||||
style_car_id = data.get("style_car_id")
|
||||
car_data = await self.data.item.get_car(user_id, self.version, style_car_id)
|
||||
story_use_count = car_data["story_use_count"] + 1
|
||||
|
||||
# save car data in database (assume rental_flag is always 0)
|
||||
await self.data.item.put_car(
|
||||
user_id,
|
||||
self.version,
|
||||
{
|
||||
"style_car_id": style_car_id,
|
||||
"car_mileage": data.pop("car_mileage"),
|
||||
"story_use_count": story_use_count,
|
||||
},
|
||||
)
|
||||
|
||||
# get the profile data, update total_play and save it
|
||||
profile = await self.data.profile.get_profile(user_id, self.version)
|
||||
total_play = profile["total_play"] + 1
|
||||
|
||||
# save user profile in database
|
||||
await self.data.profile.put_profile(
|
||||
user_id,
|
||||
self.version,
|
||||
{
|
||||
"total_play": total_play,
|
||||
"last_play_date": datetime.now(),
|
||||
"mileage": data.pop("mileage"),
|
||||
"cash": data.pop("cash"),
|
||||
"total_cash": data.pop("total_cash"),
|
||||
"dressup_point": data.pop("dressup_point"),
|
||||
"avatar_point": data.pop("avatar_point"),
|
||||
"aura_id": data.pop("aura_id"),
|
||||
"aura_color_id": data.pop("aura_color_id"),
|
||||
"aura_line_id": data.pop("aura_line_id"),
|
||||
},
|
||||
)
|
||||
|
||||
# save stock data in database
|
||||
await self._save_stock_data(user_id, stock_data)
|
||||
|
||||
# save ticket data in database
|
||||
for ticket in ticket_data:
|
||||
await self.data.item.put_ticket(user_id, ticket)
|
||||
|
||||
# save mode_rank and reward_dist data in database
|
||||
rank_data.update(reward_dist_data)
|
||||
await self.data.profile.put_profile_rank(user_id, self.version, rank_data)
|
||||
|
||||
|
||||
# get the expansion mode data from database
|
||||
expansion_data = await self.data.item.get_expansion(
|
||||
user_id, data.get("content_id"), data.get("map_id"), data.get("position_id")
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user