From 2f69cece6b20bd51fa7a00e578d0b68773f764a6 Mon Sep 17 00:00:00 2001 From: squaresmile Date: Sun, 7 Jan 2024 17:20:23 -0500 Subject: [PATCH] Added battle bg to quest phase and stage --- app/core/nice/quest.py | 34 ++++++++++++++++++++++++++++++++++ app/db/helpers/quest.py | 17 +++++++++++++++++ app/models/raw.py | 13 +++++++++++++ app/rayshift/quest.py | 8 ++++---- app/schemas/nice.py | 10 ++++++++++ app/schemas/raw.py | 10 ++++++++++ 6 files changed, 88 insertions(+), 4 deletions(-) diff --git a/app/core/nice/quest.py b/app/core/nice/quest.py index e1fb2088..7b29682c 100644 --- a/app/core/nice/quest.py +++ b/app/core/nice/quest.py @@ -39,6 +39,7 @@ AssetURL, DeckType, EnemyDrop, + NiceBattleBg, NiceBgm, NiceQuest, NiceQuestHint, @@ -56,6 +57,7 @@ SupportServant, ) from ...schemas.raw import ( + MstBattleBg, MstBgm, MstBlankEarthSpot, MstClosedMessage, @@ -168,11 +170,22 @@ def get_nice_quest_restriction( ) +def get_nice_battle_bg(battle_bg: MstBattleBg) -> NiceBattleBg: + return NiceBattleBg( + id=battle_bg.id, + type=battle_bg.type, + priority=battle_bg.priority, + individuality=get_traits_list(battle_bg.individuality), + imageId=battle_bg.imageId, + ) + + def get_nice_stage( region: Region, raw_stage: MstStage, enemies: list[QuestEnemy], bgms: list[MstBgm], + bgs: list[MstBattleBg], waveStartMovies: dict[int, list[NiceStageStartMovie]], stage_cutins: dict[int, NiceStageCutIn], lang: Language, @@ -195,6 +208,17 @@ def get_nice_stage( limitAct=STAGE_LIMIT_ACT_TYPE_NAME[raw_stage.script["LimitAct"]] if "LimitAct" in raw_stage.script else None, + battleBg=next( + ( + get_nice_battle_bg(bg) + for bg in bgs + if bg.id == raw_stage.script["changeBgId"] + and bg.type == raw_stage.script["changeBgType"] + ), + None, + ) + if "changeBgId" in raw_stage.script and "changeBgType" in raw_stage.script + else None, NoEntryIds=raw_stage.script.get("NoEntryIds"), waveStartMovies=waveStartMovies.get(raw_stage.wave, []), cutin=stage_cutins.get(raw_stage.wave, None), @@ -386,6 +410,15 @@ async def get_nice_quest_phase_no_rayshift( "isNpcOnly": raw_quest.mstQuestPhase.isNpcOnly, "battleBgId": raw_quest.mstQuestPhase.battleBgId, "extraDetail": raw_quest.mstQuestPhase.script, + "battleBg": next( + ( + get_nice_battle_bg(bg) + for bg in raw_quest.mstBattleBg + if bg.id == raw_quest.mstQuestPhase.battleBgId + and bg.type == raw_quest.mstQuestPhase.battleBgType + ), + None, + ), "availableEnemyHashes": [], "scripts": [ get_nice_script_link(region, script) for script in sorted(raw_quest.scripts) @@ -655,6 +688,7 @@ def set_follower_data(followers: dict[int, QuestEnemy] | None) -> None: stage, enemies, db_data.raw.mstBgm, + db_data.raw.mstBattleBg, waveStartMovies, stage_cutins, lang, diff --git a/app/db/helpers/quest.py b/app/db/helpers/quest.py index bead0b8f..f74e5718 100644 --- a/app/db/helpers/quest.py +++ b/app/db/helpers/quest.py @@ -13,6 +13,7 @@ and_, any_, case, + cast, false, func, literal_column, @@ -24,6 +25,7 @@ from ...models.raw import ( ScriptFileList, + mstBattleBg, mstBgm, mstClosedMessage, mstGift, @@ -630,6 +632,20 @@ async def get_quest_phase_entity( ) .outerjoin(npcSvtEquip, npcFollower.c.svtEquipIds[1] == npcSvtEquip.c.id) .outerjoin(mstBgm, mstBgm.c.id == mstStage.c.bgmId) + .outerjoin( + mstBattleBg, + or_( + and_( + mstBattleBg.c.id == mstQuestPhase.c.battleBgId, + mstBattleBg.c.type == mstQuestPhase.c.battleBgType, + ), + and_( + mstBattleBg.c.id == cast(mstStage.c.script["changeBgId"], Integer), + mstBattleBg.c.type + == cast(mstStage.c.script["changeBgType"], Integer), + ), + ), + ) ) phases_select = ( @@ -699,6 +715,7 @@ async def get_quest_phase_entity( sql_jsonb_agg(mstQuestRelease), sql_jsonb_agg(mstQuestReleaseOverwrite), sql_jsonb_agg(mstClosedMessage), + sql_jsonb_agg(mstBattleBg), sql_jsonb_agg(mstGiftAlias, "mstGift"), sql_jsonb_agg(mstGiftAddAlias, "mstGiftAdd"), phases_select, diff --git a/app/models/raw.py b/app/models/raw.py index 4edfcab0..e736a819 100644 --- a/app/models/raw.py +++ b/app/models/raw.py @@ -2223,6 +2223,18 @@ ) +mstBattleBg = Table( + "mstBattleBg", + metadata, + Column("individuality", ARRAY(Integer)), + Column("script", JSONB), + Column("id", Integer), + Column("type", Integer), + Column("imageId", Integer), + Column("priority", Integer), +) + + mstStageRemap = Table( "mstStageRemap", metadata, @@ -2569,6 +2581,7 @@ [mstQuestRestriction, mstQuestRestrictionInfo, mstRestriction], [mstStage], [mstStageRemap], + [mstBattleBg], [npcFollower], [npcFollowerRelease], [npcSvtEquip], diff --git a/app/rayshift/quest.py b/app/rayshift/quest.py index 968a0b35..61e9a45e 100644 --- a/app/rayshift/quest.py +++ b/app/rayshift/quest.py @@ -117,10 +117,10 @@ def get_multiple_quests( time.sleep(sleep_time) r = client.get(f"{QUEST_ENDPOINT}/get", params=params) - try: - return QuestRayshiftResponse.parse_raw(r.content).response.questDetails - except ValidationError: # pragma: no cover - return {} + # try: + return QuestRayshiftResponse.parse_raw(r.content).response.questDetails + # except ValidationError: # pragma: no cover + return {} def get_all_quest_lists( diff --git a/app/schemas/nice.py b/app/schemas/nice.py index 478698d9..fe34f75a 100644 --- a/app/schemas/nice.py +++ b/app/schemas/nice.py @@ -2368,6 +2368,14 @@ class NiceStageCutIn(BaseModelORJson): drops: list[EnemyDrop] +class NiceBattleBg(BaseModelORJson): + id: int + type: int + priority: int + individuality: list[NiceTrait] + imageId: int + + class NiceStage(BaseModelORJson): wave: int bgm: NiceBgm @@ -2380,6 +2388,7 @@ class NiceStage(BaseModelORJson): limitAct: StageLimitActType | None = Field( None, title="Action after turn countdown is over" ) + battleBg: NiceBattleBg | None = None NoEntryIds: list[int] | None = None waveStartMovies: list[NiceStageStartMovie] = [] cutin: NiceStageCutIn | None = None @@ -2525,6 +2534,7 @@ class NiceQuestPhase(NiceQuest): enemyHash: str | None = None availableEnemyHashes: list[str] dropsFromAllHashes: bool | None = None + battleBg: NiceBattleBg | None = None extraDetail: NiceQuestPhaseExtraDetail scripts: list[ScriptLink] messages: list[NiceQuestMessage] diff --git a/app/schemas/raw.py b/app/schemas/raw.py index d51d921f..dd3191d1 100644 --- a/app/schemas/raw.py +++ b/app/schemas/raw.py @@ -1877,6 +1877,15 @@ class MstStageRemap(BaseModelORJson): remapWave: int +class MstBattleBg(BaseModelORJson): + individuality: list[int] + script: dict[str, Any] + id: int + type: int + imageId: int + priority: int + + class NpcFollower(BaseModelORJson): id: int questId: int @@ -2095,6 +2104,7 @@ class QuestPhaseEntity(QuestEntity): mstQuestMessage: list[MstQuestMessage] = [] scripts: list[str] mstStage: list[MstStage] + mstBattleBg: list[MstBattleBg] mstBgm: list[MstBgm] npcFollower: list[NpcFollower] npcFollowerRelease: list[NpcFollowerRelease]