Skip to content

Commit

Permalink
Added BattleMassage and BattleMessageGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
narumi147 committed Feb 1, 2024
1 parent dfaa69f commit 90d0fdb
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 0 deletions.
63 changes: 63 additions & 0 deletions app/core/nice/battle_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from sqlalchemy.ext.asyncio import AsyncConnection

from ...schemas.nice import NiceBattleMessage, NiceBattleMessageGroup
from ...schemas.raw import (
BattleMessageEntity,
BattleMessageGroupEntity,
MstBattleMessage,
MstCommonRelease,
)
from .. import raw
from .common_release import get_nice_common_releases


def get_nice_battle_message(
message: MstBattleMessage, raw_releases: list[MstCommonRelease]
) -> NiceBattleMessage:
return NiceBattleMessage(
id=message.id,
idx=message.idx,
priority=message.priority,
releaseConditions=get_nice_common_releases(
raw_releases, message.commonReleaseId
),
motionId=message.motionId,
message=message.message,
script=message.script,
)


async def get_nice_battle_messages(
conn: AsyncConnection,
message_id: int,
mstBattleMessage: BattleMessageEntity | None = None,
) -> list[NiceBattleMessage]:
if not mstBattleMessage:
mstBattleMessage = await raw.get_battle_message_entity(conn, message_id)
return [
get_nice_battle_message(message, mstBattleMessage.mstCommonRelease)
for message in mstBattleMessage.mstBattleMessage
]


async def get_nice_battle_message_groups(
conn: AsyncConnection,
group_id: int,
mstBattleMessageGroup: BattleMessageGroupEntity | None = None,
) -> list[NiceBattleMessageGroup]:
if not mstBattleMessageGroup:
mstBattleMessageGroup = await raw.get_battle_message_group_entity(
conn, group_id
)
return [
NiceBattleMessageGroup(
groupId=group.groupId,
probability=group.probability,
messages=[
get_nice_battle_message(message, mstBattleMessageGroup.mstCommonRelease)
for message in mstBattleMessageGroup.mstBattleMessage
if message.id == group.messageId
],
)
for group in mstBattleMessageGroup.mstBattleMessageGroup
]
43 changes: 43 additions & 0 deletions app/core/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
AiCollection,
AiEntity,
BattleMasterImageEntity,
BattleMessageEntity,
BattleMessageGroupEntity,
BgmEntity,
BuffEntity,
BuffEntityNoReverse,
Expand All @@ -53,6 +55,8 @@
ItemEntity,
MasterMissionEntity,
MstBattleMasterImage,
MstBattleMessage,
MstBattleMessageGroup,
MstBgm,
MstBgmRelease,
MstBlankEarthSpot,
Expand Down Expand Up @@ -721,6 +725,45 @@ async def get_battle_master_image_entity(
)


async def get_battle_message_entity(
conn: AsyncConnection, message_id: int
) -> BattleMessageEntity:
mstBattleMessage = await fetch.get_all(conn, MstBattleMessage, message_id)
if not mstBattleMessage:
raise HTTPException(status_code=404, detail="Battle Message not found")

common_release_ids = {message.commonReleaseId for message in mstBattleMessage}
common_releases = await fetch.get_all_multiple(
conn, MstCommonRelease, common_release_ids
)
return BattleMessageEntity(
mstBattleMessage=mstBattleMessage,
mstCommonRelease=common_releases,
)


async def get_battle_message_group_entity(
conn: AsyncConnection, group_id: int
) -> BattleMessageGroupEntity:
mstBattleMessageGroup = await fetch.get_all(conn, MstBattleMessageGroup, group_id)
if not mstBattleMessageGroup:
raise HTTPException(status_code=404, detail="Battle Message Group not found")

message_ids = {group.messageId for group in mstBattleMessageGroup}

messages = await fetch.get_all_multiple(conn, MstBattleMessage, message_ids)

common_release_ids = {message.commonReleaseId for message in messages}
common_releases = await fetch.get_all_multiple(
conn, MstCommonRelease, common_release_ids
)
return BattleMessageGroupEntity(
mstBattleMessageGroup=mstBattleMessageGroup,
mstBattleMessage=messages,
mstCommonRelease=common_releases,
)


async def get_command_code_entity(
conn: AsyncConnection,
cc_id: int,
Expand Down
15 changes: 15 additions & 0 deletions app/db/helpers/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from ...models.raw import (
AssetStorage,
mstBattleMasterImage,
mstBattleMessage,
mstBattleMessageGroup,
mstBgm,
mstBgmRelease,
mstBlankEarthSpot,
Expand Down Expand Up @@ -130,6 +132,8 @@
from ...schemas.raw import (
AssetStorageLine,
MstBattleMasterImage,
MstBattleMessage,
MstBattleMessageGroup,
MstBgm,
MstBgmRelease,
MstBlankEarthSpot,
Expand Down Expand Up @@ -381,6 +385,12 @@ async def get_one(
mstBattleMasterImage.c.id,
mstBattleMasterImage.c.type,
),
MstBattleMessage: (mstBattleMessage, mstBattleMessage.c.id, mstBattleMessage.c.idx),
MstBattleMessageGroup: (
mstBattleMessageGroup,
mstBattleMessageGroup.c.groupId,
mstBattleMessageGroup.c.messageId,
),
MstEventAdd: (mstEventAdd, mstEventAdd.c.eventId, mstEventAdd.c.priority),
MstEventMission: (
mstEventMission,
Expand Down Expand Up @@ -603,6 +613,11 @@ async def get_all(
mstClosedMessage.c.id,
[mstClosedMessage.c.id],
),
MstBattleMessage: (
mstBattleMessage,
mstBattleMessage.c.id,
[mstBattleMessage.c.id, mstBattleMessage.c.idx],
),
MstShop: (mstShop, mstShop.c.id, [mstShop.c.id]),
MstQuest: (mstQuest, mstQuest.c.id, [mstQuest.c.id]),
MstSvtScript: (mstSvtScript, mstSvtScript.c.id, [mstSvtScript.c.id]),
Expand Down
24 changes: 24 additions & 0 deletions app/models/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -2178,6 +2178,28 @@
)


mstBattleMessage = Table(
"mstBattleMessage",
metadata,
Column("id", Integer, index=True),
Column("idx", Integer),
Column("priority", Integer),
Column("commonReleaseId", Integer),
Column("motionId", Integer),
Column("message", String),
Column("script", JSONB),
)


mstBattleMessageGroup = Table(
"mstBattleMessageGroup",
metadata,
Column("groupId", Integer, index=True),
Column("messageId", Integer),
Column("probability", Integer),
)


mstQuestConsumeItem = Table(
"mstQuestConsumeItem",
metadata,
Expand Down Expand Up @@ -2275,6 +2297,7 @@
Column("enemyInfo", Integer),
Column("bgmId", Integer, index=True),
Column("startEffectId", Integer),
Column("stageCutinGroupIds", ARRAY(Integer)),
Index(
"ix_mstStage_script_GIN",
text('"script" jsonb_path_ops'),
Expand Down Expand Up @@ -2595,6 +2618,7 @@
[mstBoxGacha, mstBoxGachaBase, mstBoxGachaTalk],
[mstClassRelationOverwrite, mstBuffConvert],
[mstClosedMessage],
[mstBattleMessage, mstBattleMessageGroup],
[mstCombineAppendPassiveSkill],
[mstCombineCostume],
[mstCombineLimit],
Expand Down
41 changes: 41 additions & 0 deletions app/routers/nice.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from ..core import search
from ..core.nice import (
ai,
battle_message,
bgm,
cc,
class_board,
Expand Down Expand Up @@ -33,6 +34,8 @@
NiceAiCollection,
NiceBaseFunctionReverse,
NiceBattleMasterImage,
NiceBattleMessage,
NiceBattleMessageGroup,
NiceBgmEntity,
NiceBuffReverse,
NiceClassBoard,
Expand Down Expand Up @@ -1024,6 +1027,44 @@ async def get_battle_master_image(
)


@router.get(
"/{region}/battle-message/{message_id}",
summary="Get Battle Message data",
response_description="Nice Battle Message Entity",
response_model=list[NiceBattleMessage],
response_model_exclude_unset=True,
responses=get_error_code([404]),
)
@cache()
async def get_battle_message(
region: Region,
message_id: int,
) -> Response:
async with get_db(region) as conn:
return list_response(
await battle_message.get_nice_battle_messages(conn, message_id)
)


@router.get(
"/{region}/battle-message-group/{group_id}",
summary="Get Battle Message Group data",
response_description="Nice Battle Message Group Entity",
response_model=list[NiceBattleMessageGroup],
response_model_exclude_unset=True,
responses=get_error_code([404]),
)
@cache()
async def get_battle_message_group(
region: Region,
group_id: int,
) -> Response:
async with get_db(region) as conn:
return list_response(
await battle_message.get_nice_battle_message_groups(conn, group_id)
)


@router.get(
"/{region}/class-board/{class_board_id}",
summary="Get Class Board data",
Expand Down
46 changes: 46 additions & 0 deletions app/routers/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from ..schemas.raw import (
AiCollection,
BattleMasterImageEntity,
BattleMessageEntity,
BattleMessageGroupEntity,
BgmEntity,
BuffEntity,
ClassBoardEntity,
Expand Down Expand Up @@ -852,6 +854,50 @@ async def get_battle_master_image(
return item_response(battle_master_image_entity)


@router.get(
"/{region}/battle-message/{message_id}",
summary="Get Battle Message data",
response_description="Battle Message entity",
response_model=BattleMessageEntity,
response_model_exclude_unset=True,
responses=get_error_code([404]),
)
@cache()
async def get_battle_message(
region: Region,
message_id: int,
) -> Response:
"""
Get Battle Message info from ID
"""
async with get_db(region) as conn:
battle_message_entity = await raw.get_battle_message_entity(conn, message_id)
return item_response(battle_message_entity)


@router.get(
"/{region}/battle-message-group/{group_id}",
summary="Get Battle Message Group data",
response_description="Battle Message Group entity",
response_model=BattleMessageGroupEntity,
response_model_exclude_unset=True,
responses=get_error_code([404]),
)
@cache()
async def get_battle_message_group(
region: Region,
group_id: int,
) -> Response:
"""
Get Battle Message Group info from ID
"""
async with get_db(region) as conn:
battle_message_group_entity = await raw.get_battle_message_group_entity(
conn, group_id
)
return item_response(battle_message_group_entity)


@router.get(
"/{region}/class-board/{class_board_id}",
summary="Get Class Board data",
Expand Down
16 changes: 16 additions & 0 deletions app/schemas/nice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2470,6 +2470,22 @@ class NiceQuestMessage(BaseModelORJson):
targetNum: int


class NiceBattleMessage(BaseModelORJson):
id: int
idx: int
priority: int
releaseConditions: list[NiceCommonRelease]
motionId: int
message: str
script: dict[str, Any]


class NiceBattleMessageGroup(BaseModelORJson):
groupId: int
probability: int
messages: list[NiceBattleMessage]


class NiceQuestHint(BaseModelORJson):
title: str
message: str
Expand Down
Loading

0 comments on commit 90d0fdb

Please sign in to comment.