Skip to content

Commit

Permalink
Added eventSvt
Browse files Browse the repository at this point in the history
  • Loading branch information
squaresmile committed Jan 28, 2024
1 parent 9344260 commit e2cda0f
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/core/nice/common_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ def get_nice_common_release(release: MstCommonRelease) -> NiceCommonRelease:
)


def get_sorted_common_releases(
raw_releases: list[MstCommonRelease], release_id: int | None = None
) -> list[NiceCommonRelease]:
sorted_raw_releases = sorted(
raw_releases,
key=lambda release: (release.priority, release.condType, release.condNum),
)
return [
get_nice_common_release(release)
for release in sorted_raw_releases
if release_id is None or release.id == release_id
]


async def get_nice_common_releases_from_id(
conn: AsyncConnection, common_release_id: int
) -> list[NiceCommonRelease]:
Expand Down
5 changes: 5 additions & 0 deletions app/core/nice/event/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from .command_assist import get_nice_command_assist
from .cooltime import get_nice_event_cooltime
from .digging import get_nice_digging
from .event_svt import get_nice_event_svt
from .fortification import get_nice_fortification
from .heel_portrait import get_nice_heel_portrait
from .lottery import get_nice_lottery
Expand Down Expand Up @@ -237,6 +238,10 @@ async def get_nice_event(
eventAdds=[
get_nice_event_add(region, event_add) for event_add in raw_event.mstEventAdd
],
svts=[
get_nice_event_svt(event_svt, raw_event.mstCommonRelease)
for event_svt in raw_event.mstEventSvt
],
shop=[
get_nice_shop(
region,
Expand Down
54 changes: 54 additions & 0 deletions app/core/nice/event/event_svt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from typing import Any

from ....schemas.gameenums import EVENT_SVT_TYPE_NAME
from ....schemas.nice import NiceEventSvt, NiceEventSvtScript
from ....schemas.raw import MstCommonRelease, MstEventSvt
from ..common_release import get_sorted_common_releases


def get_nice_event_svt_script(
script: dict[str, Any], raw_releases: list[MstCommonRelease]
) -> NiceEventSvtScript:
out: dict[str, Any] = {}

for unchanged_key in (
"addGetMessage",
"joinQuestId",
"joinShopId",
"notPresentRarePri",
"ruby",
):
if unchanged_key in script:
out[unchanged_key] = script[unchanged_key]

for bool_key in ("isProtectedDuringEvent", "notPresentAnonymous"):
if bool_key in script:
out[bool_key] = script[bool_key] == 1

if "addMessageCommonReleaseId" in script:
out["addMessageReleaseConditions"] = get_sorted_common_releases(
raw_releases, script["addMessageCommonReleaseId"]
)

return NiceEventSvtScript.parse_obj(out)


def get_nice_event_svt(
event_svt: MstEventSvt, raw_releases: list[MstCommonRelease]
) -> NiceEventSvt:
return NiceEventSvt(
svtId=event_svt.svtId,
script=get_nice_event_svt_script(event_svt.script, raw_releases),
originalScript=event_svt.script,
type=EVENT_SVT_TYPE_NAME[event_svt.type],
joinMessage=event_svt.joinMessage,
getMessage=event_svt.getMessage,
leaveMessage=event_svt.leaveMessage,
name=event_svt.name,
battleName=event_svt.battleName,
releaseConditions=get_sorted_common_releases(
raw_releases, event_svt.commonReleaseId
),
startedAt=event_svt.startedAt,
endedAt=event_svt.endedAt,
)
10 changes: 10 additions & 0 deletions app/core/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
MstEventReward,
MstEventRewardScene,
MstEventRewardSet,
MstEventSvt,
MstEventTower,
MstEventVoicePlay,
MstFriendship,
Expand Down Expand Up @@ -1072,11 +1073,19 @@ async def get_event_entity(conn: AsyncConnection, event_id: int) -> EventEntity:
},
)

event_svts = await fetch.get_all(conn, MstEventSvt, event_id)
event_svt_release_ids = {svt.commonReleaseId for svt in event_svts} | {
svt.script["addMessageCommonReleaseId"]
for svt in event_svts
if "addMessageCommonReleaseId" in svt.script
}

common_release_ids = (
cooltime_release_ids
| recipe_release_ids
| fortification_release_ids
| command_assist_release_ids
| event_svt_release_ids
)
common_releases = await fetch.get_all_multiple(
conn, MstCommonRelease, common_release_ids
Expand Down Expand Up @@ -1183,6 +1192,7 @@ async def get_event_entity(conn: AsyncConnection, event_id: int) -> EventEntity:
mstEventPointActivity=await fetch.get_all(
conn, MstEventPointActivity, event_id
),
mstEventSvt=event_svts,
mstWarBoard=warboards,
mstWarBoardStage=warboard_stages,
mstWarBoardQuest=warboard_quests,
Expand Down
7 changes: 7 additions & 0 deletions app/db/helpers/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
mstEventReward,
mstEventRewardScene,
mstEventRewardSet,
mstEventSvt,
mstEventTower,
mstEventVoicePlay,
mstFriendship,
Expand Down Expand Up @@ -188,6 +189,7 @@
MstEventReward,
MstEventRewardScene,
MstEventRewardSet,
MstEventSvt,
MstEventTower,
MstEventVoicePlay,
MstFriendship,
Expand Down Expand Up @@ -532,6 +534,11 @@ async def get_one(
mstSvtOverwrite.c.svtId,
mstSvtOverwrite.c.priority,
),
MstEventSvt: (
mstEventSvt,
mstEventSvt.c.eventId,
mstEventSvt.c.svtId,
),
}

TFetchAll = TypeVar("TFetchAll", bound=BaseModelORJson)
Expand Down
19 changes: 19 additions & 0 deletions app/models/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,24 @@
)


mstEventSvt = Table(
"mstEventSvt",
metadata,
Column("script", JSONB),
Column("eventId", Integer),
Column("svtId", Integer),
Column("type", Integer),
Column("joinMessage", String),
Column("getMessage", String),
Column("leaveMessage", String),
Column("name", String),
Column("battleName", String),
Column("commonReleaseId", Integer),
Column("startedAt", Integer),
Column("endedAt", Integer),
)


mstWarBoard = Table(
"mstWarBoard",
metadata,
Expand Down Expand Up @@ -2646,6 +2664,7 @@
[mstEventBulletinBoard, mstEventBulletinBoardRelease],
[mstEventRecipe, mstEventRecipeGift],
[mstEventFortification, mstEventFortificationDetail, mstEventFortificationSvt],
[mstEventSvt],
[mstVoice],
[mstVoicePlayCond],
[mstSvt],
Expand Down
24 changes: 24 additions & 0 deletions app/schemas/gameenums.py
Original file line number Diff line number Diff line change
Expand Up @@ -5406,3 +5406,27 @@ class NiceGachaFlag(StrEnum):
2: NiceGachaFlag.pcMessage,
8: NiceGachaFlag.bonusSelect,
}


class EventSvtType(IntEnum):
NONE = 0
JOIN = 1
COND_JOIN = 2
DIRECT_JOIN = 3


class NiceEventSvtType(StrEnum):
"""Event Svt Type"""

none = "none"
join_ = "join"
condJoin = "condJoin"
directJoin = "directJoin"


EVENT_SVT_TYPE_NAME: dict[int, NiceEventSvtType] = {
0: NiceEventSvtType.none,
1: NiceEventSvtType.join_,
2: NiceEventSvtType.condJoin,
3: NiceEventSvtType.directJoin,
}
28 changes: 28 additions & 0 deletions app/schemas/nice.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
NiceEventFortificationSvtType,
NiceEventOverwriteType,
NiceEventRewardSceneFlag,
NiceEventSvtType,
NiceEventType,
NiceEventWorkType,
NiceFrequencyType,
Expand Down Expand Up @@ -2037,6 +2038,32 @@ class NiceEventAdd(BaseModelORJson):
endedAt: int


class NiceEventSvtScript(BaseModelORJson):
addGetMessage: str | None = None
addMessageReleaseConditions: list[NiceCommonRelease] | None = None
isProtectedDuringEvent: bool | None = None
joinQuestId: int | None = None
joinShopId: int | None = None
notPresentAnonymous: bool | None = None
notPresentRarePri: int | None = None
ruby: str | None = None


class NiceEventSvt(BaseModelORJson):
svtId: int
script: NiceEventSvtScript
originalScript: dict[str, Any]
type: NiceEventSvtType
joinMessage: str
getMessage: str
leaveMessage: str
name: str
battleName: str
releaseConditions: list[NiceCommonRelease]
startedAt: int
endedAt: int


class NiceWarBoardTreasure(BaseModelORJson):
warBoardTreasureId: int
rarity: NiceWarBoardTreasureRarity
Expand Down Expand Up @@ -2082,6 +2109,7 @@ class NiceEvent(BaseModelORJson):
materialOpenedAt: int
warIds: list[int]
eventAdds: list[NiceEventAdd]
svts: list[NiceEventSvt]
shop: list[NiceShop]
rewards: list[NiceEventReward]
rewardScenes: list[NiceEventRewardScene]
Expand Down
16 changes: 16 additions & 0 deletions app/schemas/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,21 @@ class MstEventAdd(BaseModelORJson):
endedAt: int


class MstEventSvt(BaseModelORJson):
script: dict[str, Any]
eventId: int
svtId: int
type: int
joinMessage: str
getMessage: str
leaveMessage: str
name: str
battleName: str
commonReleaseId: int
startedAt: int
endedAt: int


class MstWarBoard(BaseModelORJson):
id: int
backGroundId: int
Expand Down Expand Up @@ -2198,6 +2213,7 @@ class EventEntity(BaseModelORJson):
mstHeelPortrait: list[MstHeelPortrait]
mstEventMural: list[MstEventMural]
mstEventPointActivity: list[MstEventPointActivity]
mstEventSvt: list[MstEventSvt]
mstWarBoard: list[MstWarBoard]
mstWarBoardStage: list[MstWarBoardStage]
mstWarBoardQuest: list[MstWarBoardQuest]
Expand Down
7 changes: 7 additions & 0 deletions scripts/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1833,3 +1833,10 @@ export enum NiceGachaFlag {
PC_MESSAGE = "pcMessage",
BONUS_SELECT = "bonusSelect",
}

export enum NiceEventSvtType {
NONE = "none",
JOIN = "join",
COND_JOIN = "condJoin",
DIRECT_JOIN = "directJoin",
}
8 changes: 8 additions & 0 deletions scripts/extract_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"CENTER": "center_",
"SET": "set_",
"NAME": "name_",
"JOIN": "join_",
}


Expand Down Expand Up @@ -602,6 +603,13 @@ def cs_enum_to_ts(cs_enums: list[str], raw_class: str, nice_class: str) -> list[
"Gacha Flag",
"GACHA_FLAG_NAME",
),
(
"EventServantEntity.TYPE",
"EventSvtType",
"NiceEventSvtType",
"Event Svt Type",
"EVENT_SVT_TYPE_NAME",
),
]


Expand Down

0 comments on commit e2cda0f

Please sign in to comment.