Skip to content

Commit

Permalink
Added battle bg to quest phase and stage
Browse files Browse the repository at this point in the history
  • Loading branch information
squaresmile committed Jan 7, 2024
1 parent 21c5661 commit 2f69cec
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 4 deletions.
34 changes: 34 additions & 0 deletions app/core/nice/quest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
AssetURL,
DeckType,
EnemyDrop,
NiceBattleBg,
NiceBgm,
NiceQuest,
NiceQuestHint,
Expand All @@ -56,6 +57,7 @@
SupportServant,
)
from ...schemas.raw import (
MstBattleBg,
MstBgm,
MstBlankEarthSpot,
MstClosedMessage,
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions app/db/helpers/quest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
and_,
any_,
case,
cast,
false,
func,
literal_column,
Expand All @@ -24,6 +25,7 @@

from ...models.raw import (
ScriptFileList,
mstBattleBg,
mstBgm,
mstClosedMessage,
mstGift,
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions app/models/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -2569,6 +2581,7 @@
[mstQuestRestriction, mstQuestRestrictionInfo, mstRestriction],
[mstStage],
[mstStageRemap],
[mstBattleBg],
[npcFollower],
[npcFollowerRelease],
[npcSvtEquip],
Expand Down
8 changes: 4 additions & 4 deletions app/rayshift/quest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions app/schemas/nice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down
10 changes: 10 additions & 0 deletions app/schemas/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 2f69cec

Please sign in to comment.