forked from Hay1tsme/artemis
pokken: save most profile data
This commit is contained in:
parent
a89247cdd6
commit
432177957a
@ -8,6 +8,7 @@ from core import CoreConfig
|
|||||||
from .config import PokkenConfig
|
from .config import PokkenConfig
|
||||||
from .proto import jackal_pb2
|
from .proto import jackal_pb2
|
||||||
from .database import PokkenData
|
from .database import PokkenData
|
||||||
|
from .const import PokkenConstants
|
||||||
|
|
||||||
|
|
||||||
class PokkenBase:
|
class PokkenBase:
|
||||||
@ -301,11 +302,11 @@ class PokkenBase:
|
|||||||
battle = req.battle_data
|
battle = req.battle_data
|
||||||
mon = req.pokemon_data
|
mon = req.pokemon_data
|
||||||
|
|
||||||
self.data.profile.update_support_team(user_id, 1, req.support_set_1[0], req.support_set_1[1])
|
p = self.data.profile.touch_profile(user_id)
|
||||||
self.data.profile.update_support_team(user_id, 2, req.support_set_2[0], req.support_set_2[1])
|
if p is None or not p:
|
||||||
self.data.profile.update_support_team(user_id, 3, req.support_set_3[0], req.support_set_3[1])
|
self.data.profile.create_profile(user_id)
|
||||||
|
|
||||||
if req.trainer_name_pending: # we're saving for the first time
|
if req.trainer_name_pending is not None and req.trainer_name_pending: # we're saving for the first time
|
||||||
self.data.profile.set_profile_name(user_id, req.trainer_name_pending, req.avatar_gender if req.avatar_gender else None)
|
self.data.profile.set_profile_name(user_id, req.trainer_name_pending, req.avatar_gender if req.avatar_gender else None)
|
||||||
|
|
||||||
for tut_flg in req.tutorial_progress_flag:
|
for tut_flg in req.tutorial_progress_flag:
|
||||||
@ -329,6 +330,46 @@ class PokkenBase:
|
|||||||
for reward in req.reward_data:
|
for reward in req.reward_data:
|
||||||
self.data.item.add_reward(user_id, reward.get_category_id, reward.get_content_id, reward.get_type_id)
|
self.data.item.add_reward(user_id, reward.get_category_id, reward.get_content_id, reward.get_type_id)
|
||||||
|
|
||||||
|
self.data.profile.add_profile_points(user_id, get_rank_pts, get_money, get_score_pts, grade_max)
|
||||||
|
|
||||||
|
self.data.profile.update_support_team(user_id, 1, req.support_set_1[0], req.support_set_1[1])
|
||||||
|
self.data.profile.update_support_team(user_id, 2, req.support_set_2[0], req.support_set_2[1])
|
||||||
|
self.data.profile.update_support_team(user_id, 3, req.support_set_3[0], req.support_set_3[1])
|
||||||
|
|
||||||
|
self.data.profile.put_pokemon(user_id, mon.char_id, mon.illustration_book_no, mon.bp_point_atk, mon.bp_point_res, mon.bp_point_def, mon.bp_point_sp)
|
||||||
|
self.data.profile.add_pokemon_xp(user_id, mon.char_id, mon.get_pokemon_exp)
|
||||||
|
|
||||||
|
for x in range(len(battle.play_mode)):
|
||||||
|
self.data.profile.put_pokemon_battle_result(
|
||||||
|
user_id,
|
||||||
|
mon.char_id,
|
||||||
|
PokkenConstants.BATTLE_TYPE(battle.play_mode[x]),
|
||||||
|
PokkenConstants.BATTLE_RESULT(battle.result[x])
|
||||||
|
)
|
||||||
|
|
||||||
|
self.data.profile.put_stats(
|
||||||
|
user_id,
|
||||||
|
battle.ex_ko_num,
|
||||||
|
battle.wko_num,
|
||||||
|
battle.timeup_win_num,
|
||||||
|
battle.cool_ko_num,
|
||||||
|
battle.perfect_ko_num,
|
||||||
|
num_continues
|
||||||
|
)
|
||||||
|
|
||||||
|
self.data.profile.put_extra(
|
||||||
|
user_id,
|
||||||
|
extra_counter,
|
||||||
|
evt_reward_get_flg,
|
||||||
|
total_play_days,
|
||||||
|
awake_num,
|
||||||
|
use_support_ct,
|
||||||
|
beat_num,
|
||||||
|
aid_skill,
|
||||||
|
last_evt
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
return res.SerializeToString()
|
return res.SerializeToString()
|
||||||
|
|
||||||
def handle_save_ingame_log(self, data: jackal_pb2.Request) -> bytes:
|
def handle_save_ingame_log(self, data: jackal_pb2.Request) -> bytes:
|
||||||
|
@ -137,6 +137,14 @@ pokemon_data = Table(
|
|||||||
|
|
||||||
|
|
||||||
class PokkenProfileData(BaseData):
|
class PokkenProfileData(BaseData):
|
||||||
|
def touch_profile(self, user_id: int) -> Optional[int]:
|
||||||
|
sql = select([profile.c.id]).where(profile.c.user == user_id)
|
||||||
|
|
||||||
|
result = self.execute(sql)
|
||||||
|
if result is None:
|
||||||
|
return None
|
||||||
|
return result.fetchone()['id']
|
||||||
|
|
||||||
def create_profile(self, user_id: int) -> Optional[int]:
|
def create_profile(self, user_id: int) -> Optional[int]:
|
||||||
sql = insert(profile).values(user=user_id)
|
sql = insert(profile).values(user=user_id)
|
||||||
conflict = sql.on_duplicate_key_update(user=user_id)
|
conflict = sql.on_duplicate_key_update(user=user_id)
|
||||||
@ -158,6 +166,33 @@ class PokkenProfileData(BaseData):
|
|||||||
f"Failed to update pokken profile name for user {user_id}!"
|
f"Failed to update pokken profile name for user {user_id}!"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def put_extra(
|
||||||
|
self,
|
||||||
|
user_id: int,
|
||||||
|
extra_counter: int,
|
||||||
|
evt_reward_get_flg: int,
|
||||||
|
total_play_days: int,
|
||||||
|
awake_num: int,
|
||||||
|
use_support_ct: int,
|
||||||
|
beat_num: int,
|
||||||
|
aid_skill: int,
|
||||||
|
last_evt: int
|
||||||
|
) -> None:
|
||||||
|
sql = update(profile).where(profile.c.user == user_id).values(
|
||||||
|
extra_counter=extra_counter,
|
||||||
|
event_reward_get_flag=evt_reward_get_flg,
|
||||||
|
total_play_days=total_play_days,
|
||||||
|
awake_num=awake_num,
|
||||||
|
use_support_num=use_support_ct,
|
||||||
|
beat_num=beat_num,
|
||||||
|
aid_skill=aid_skill,
|
||||||
|
last_play_event_id=last_evt
|
||||||
|
)
|
||||||
|
|
||||||
|
result = self.execute(sql)
|
||||||
|
if result is None:
|
||||||
|
self.logger.error(f"Failed to put extra data for user {user_id}")
|
||||||
|
|
||||||
def update_profile_tutorial_flags(self, user_id: int, tutorial_flags: List) -> None:
|
def update_profile_tutorial_flags(self, user_id: int, tutorial_flags: List) -> None:
|
||||||
sql = update(profile).where(profile.c.user == user_id).values(
|
sql = update(profile).where(profile.c.user == user_id).values(
|
||||||
tutorial_progress_flag=tutorial_flags,
|
tutorial_progress_flag=tutorial_flags,
|
||||||
@ -192,9 +227,14 @@ class PokkenProfileData(BaseData):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def add_profile_points(
|
def add_profile_points(
|
||||||
self, user_id: int, rank_pts: int, money: int, score_pts: int
|
self, user_id: int, rank_pts: int, money: int, score_pts: int, grade_max: int
|
||||||
) -> None:
|
) -> None:
|
||||||
pass
|
sql = update(profile).where(profile.c.user == user_id).values(
|
||||||
|
trainer_rank_point = profile.c.trainer_rank_point + rank_pts,
|
||||||
|
fight_money = profile.c.fight_money + money,
|
||||||
|
score_point = profile.c.score_point + score_pts,
|
||||||
|
grade_max_num = grade_max
|
||||||
|
)
|
||||||
|
|
||||||
def get_profile(self, user_id: int) -> Optional[Row]:
|
def get_profile(self, user_id: int) -> Optional[Row]:
|
||||||
sql = profile.select(profile.c.user == user_id)
|
sql = profile.select(profile.c.user == user_id)
|
||||||
@ -294,7 +334,18 @@ class PokkenProfileData(BaseData):
|
|||||||
"""
|
"""
|
||||||
Records profile stats
|
Records profile stats
|
||||||
"""
|
"""
|
||||||
pass
|
sql = update(profile).where(profile.c.user==user_id).values(
|
||||||
|
ex_ko_num=profile.c.ex_ko_num + exkos,
|
||||||
|
wko_num=profile.c.wko_num + wkos,
|
||||||
|
timeup_win_num=profile.c.timeup_win_num + timeout_wins,
|
||||||
|
cool_ko_num=profile.c.cool_ko_num + cool_kos,
|
||||||
|
perfect_ko_num=profile.c.perfect_ko_num + perfects,
|
||||||
|
continue_num=continues,
|
||||||
|
)
|
||||||
|
|
||||||
|
result = self.execute(sql)
|
||||||
|
if result is None:
|
||||||
|
self.logger.warn(f"Failed to update stats for user {user_id}")
|
||||||
|
|
||||||
def update_support_team(self, user_id: int, support_id: int, support1: int = 4294967295, support2: int = 4294967295) -> None:
|
def update_support_team(self, user_id: int, support_id: int, support1: int = 4294967295, support2: int = 4294967295) -> None:
|
||||||
sql = update(profile).where(profile.c.user==user_id).values(
|
sql = update(profile).where(profile.c.user==user_id).values(
|
||||||
|
Loading…
Reference in New Issue
Block a user