Skip to content

Commit

Permalink
Other: Implement/unstub some things and cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikuAuahDark committed Apr 6, 2024
1 parent 33d2a4b commit 25bcc32
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 33 deletions.
15 changes: 8 additions & 7 deletions npps4/game/exchange.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from .. import idol
from .. import util

import pydantic

from .. import idol
from ..system import exchange
from ..system import user


class ExchangePointResponse(pydantic.BaseModel):
exchange_point_list: list
exchange_point_list: list[exchange.ExchangePointInfo]


@idol.register("exchange", "owningPoint")
async def exchange_owningpoint(context: idol.SchoolIdolUserParams) -> ExchangePointResponse:
# TODO
util.stub("exchange", "owningPoint", context.raw_request_data)
return ExchangePointResponse(exchange_point_list=[])
return ExchangePointResponse(
exchange_point_list=await exchange.get_exchange_points_response(context, await user.get_current(context))
)
2 changes: 1 addition & 1 deletion npps4/game/livese.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class LiveSEInfoResponse(pydantic.BaseModel):
async def livese_liveseinfo(context: idol.SchoolIdolUserParams) -> LiveSEInfoResponse:
# TODO
util.stub("livese", "liveseInfo", context.raw_request_data)
return LiveSEInfoResponse(live_se_list=[1, 2, 3])
return LiveSEInfoResponse(live_se_list=[1, 2, 3, 99])
12 changes: 7 additions & 5 deletions npps4/game/secretbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ..system import advanced
from ..system import album
from ..system import common
from ..system import item
from ..system import museum
from ..system import reward
from ..system import secretbox
Expand Down Expand Up @@ -68,12 +69,11 @@ class CustomSecretBoxResponse(pydantic.BaseModel):
item_list: list[common.ItemCount]
gauge_info: secretbox_model.SecretboxGaugeInfo = pydantic.Field(
default_factory=secretbox_model.SecretboxGaugeInfo
) # TODO
)
member_category_list: list[dict[str, Any]]

@idol.register("secretbox", "all")
async def secretbox_all_stub(context: idol.SchoolIdolUserParams) -> CustomSecretBoxResponse:
# TODO
util.stub("secretbox", "all")
with open("secretbox.json", "r", encoding="utf-8") as f:
return CustomSecretBoxResponse(
Expand All @@ -84,12 +84,12 @@ async def secretbox_all_stub(context: idol.SchoolIdolUserParams) -> CustomSecret

@idol.register("secretbox", "all")
async def secretbox_all(context: idol.SchoolIdolUserParams) -> SecretboxAllResponse:
util.stub("secretbox", "all")
current_user = await user.get_current(context)
item_list = await item.get_item_list(context, current_user)
return SecretboxAllResponse(
use_cache=0,
is_unit_max=await unit.is_unit_max(context, current_user),
item_list=[], # TODO
item_list=item_list[0],
member_category_list=await secretbox.get_all_secretbox_data_response(context, current_user),
)

Expand Down Expand Up @@ -161,6 +161,8 @@ async def secretbox_gachapon(context: idol.SchoolIdolUserParams, request: Secret
if umi_rare_mode:
unit_data_list[0].unit_rarity_id = 4

item_list = await item.get_item_list(context, current_user)

return SecretboxPonResponse(
before_user_info=before_user,
after_user_info=await user.get_user_info(context, current_user),
Expand All @@ -173,7 +175,7 @@ async def secretbox_gachapon(context: idol.SchoolIdolUserParams, request: Secret
),
new_achievement_cnt=len(achievement_list.new),
is_unit_max=current_unit_count >= current_user.unit_max,
item_list=[], # TODO
item_list=item_list[0],
button_list=await secretbox.get_secretbox_button_response(context, current_user, secretbox_data),
secret_box_info=await secretbox.get_secretbox_info_response(context, current_user, secretbox_data),
secret_box_items=SecretboxItems(unit=unit_data_list, item=[]),
Expand Down
13 changes: 4 additions & 9 deletions npps4/game/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,12 @@ class UnitRankUpRequest(pydantic.BaseModel):
unit_owning_user_ids: list[int]


class UnitGetExchangePoint(pydantic.BaseModel):
rarity: int
exchange_point: int


class UnitRankUpResponse(achievement.AchievementMixin, common.TimestampMixin, user.UserDiffMixin):
before: unit_model.UnitInfoData
after: unit_model.UnitInfoData
use_game_coin: int
unlocked_subscenario_ids: list[int]
get_exchange_point_list: list[UnitGetExchangePoint]
get_exchange_point_list: list[exchange.ExchangePointInfo]
unit_removable_skill: unit_model.RemovableSkillOwningInfo
museum_info: museum.MuseumInfoData
present_cnt: int
Expand All @@ -119,7 +114,7 @@ class UnitSaleResponse(common.TimestampMixin, user.UserDiffMixin):
total: int
detail: list[UnitSaleDetail]
reward_box_flag: bool
get_exchange_point_list: list[UnitGetExchangePoint]
get_exchange_point_list: list[exchange.ExchangePointInfo]
unit_removable_skill: unit_model.RemovableSkillOwningInfo


Expand Down Expand Up @@ -474,10 +469,10 @@ async def unit_sale(context: idol.SchoolIdolUserParams, request: UnitSaleRequest
raise idol.error.IdolError(detail="invalid unit amount")

# Give stickers
get_exchange_point_list: list[UnitGetExchangePoint] = []
get_exchange_point_list: list[exchange.ExchangePointInfo] = []
for exchange_point_id, amount in exchange_point.items():
await exchange.add_exchange_point(context, current_user, exchange_point_id, amount)
get_exchange_point_list.append(UnitGetExchangePoint(rarity=exchange_point_id, exchange_point=amount))
get_exchange_point_list.append(exchange.ExchangePointInfo(rarity=exchange_point_id, exchange_point=amount))

# Give coin
reward_box_flag = not bool(await advanced.add_item(context, current_user, item.game_coin(total)))
Expand Down
11 changes: 1 addition & 10 deletions npps4/system/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,7 @@ async def update(
album = result.scalar()

if album is None:
album = main.Album(
user_id=user.id,
unit_id=unit_id,
rank_max_flag=False,
love_max_flag=False,
rank_level_max_flag=False,
highest_love_per_unit=0, # TODO
favorite_point=0, # TODO
sign_flag=False,
)
album = main.Album(user_id=user.id, unit_id=unit_id)
context.db.main.add(album)

album.rank_max_flag = rank_max or album.rank_max_flag
Expand Down
15 changes: 15 additions & 0 deletions npps4/system/exchange.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import pydantic
import sqlalchemy

from .. import idol
from ..db import exchange
from ..db import main


class ExchangePointInfo(pydantic.BaseModel):
rarity: int
exchange_point: int


async def is_festival_unit(context: idol.BasicSchoolIdolContext, /, unit_id: int):
test = await context.db.exchange.get(exchange.ExchangeFestivalPointUnit, unit_id)
return test is not None
Expand Down Expand Up @@ -59,3 +66,11 @@ async def sub_exchange_point(
return True

return False


async def get_exchange_points_response(context: idol.BasicSchoolIdolContext, /, user: main.User):
q = sqlalchemy.select(main.ExchangePointItem).where(
main.ExchangePointItem.user_id == user.id, main.ExchangePointItem.amount > 0
)
result = await context.db.main.execute(q)
return [ExchangePointInfo(rarity=e.exchange_point_id, exchange_point=e.amount) for e in result.scalars()]
1 change: 0 additions & 1 deletion npps4/system/secretbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ async def get_all_secretbox_data_response(context: idol.BasicSchoolIdolContext,
member_category_list: dict[int, list[secretbox_model.SecretboxAllPage]] = {}

for secretbox in server_data.secretbox_data.values():
secretbox_id = secretbox.secretbox_id
page = secretbox_model.SecretboxAllPage(
menu_asset=_determine_en_path(context, secretbox.menu_asset, secretbox.menu_asset_en),
page_order=secretbox.order,
Expand Down

0 comments on commit 25bcc32

Please sign in to comment.