|
| 1 | +from sqlalchemy.ext.asyncio import AsyncConnection |
| 2 | + |
| 3 | +from ...config import Settings |
| 4 | +from ...schemas.common import Language, Region |
| 5 | +from ...schemas.enums import get_class_name |
| 6 | +from ...schemas.gameenums import COND_TYPE_NAME |
| 7 | +from ...schemas.nice import NiceGrandGraph, NiceGrandGraphDetail |
| 8 | +from ...schemas.raw import MstGrandGraph, MstGrandGraphDetail |
| 9 | +from .. import raw |
| 10 | +from .item import get_nice_item_amount, get_nice_item_from_raw |
| 11 | + |
| 12 | + |
| 13 | +settings = Settings() |
| 14 | + |
| 15 | + |
| 16 | +def get_nice_grand_graph_detail(detail: MstGrandGraphDetail) -> NiceGrandGraphDetail: |
| 17 | + return NiceGrandGraphDetail( |
| 18 | + baseClassId=detail.baseClassId, |
| 19 | + grandClassId=detail.grandClassId, |
| 20 | + baseClass=get_class_name(detail.baseClassId), |
| 21 | + grandClass=get_class_name(detail.grandClassId), |
| 22 | + adjustHp=detail.adjustHp, |
| 23 | + adjustAtk=detail.adjustAtk, |
| 24 | + condType=COND_TYPE_NAME[detail.condType], |
| 25 | + condTargetId=detail.condTargetId, |
| 26 | + condNum=detail.condNum, |
| 27 | + ) |
| 28 | + |
| 29 | + |
| 30 | +async def get_nice_grand_graph( |
| 31 | + conn: AsyncConnection, region: Region, grand_graph_id: int, lang: Language |
| 32 | +) -> NiceGrandGraph: |
| 33 | + raw_grand_graph = await raw.get_grand_graph_entity(conn, grand_graph_id) |
| 34 | + |
| 35 | + mstGrandGraph = raw_grand_graph.mstGrandGraph |
| 36 | + |
| 37 | + items_map = {item.id: item for item in raw_grand_graph.mstItem} |
| 38 | + |
| 39 | + return NiceGrandGraph( |
| 40 | + id=mstGrandGraph.id, |
| 41 | + name=mstGrandGraph.name, |
| 42 | + nameShort=mstGrandGraph.nameShort, |
| 43 | + nameShortEnglish=mstGrandGraph.nameShortEnglish, |
| 44 | + classBoardBaseId=mstGrandGraph.classBoardBaseId, |
| 45 | + condSvtLv=mstGrandGraph.condSvtLv, |
| 46 | + condSkillLv=mstGrandGraph.condSkillLv, |
| 47 | + condType=COND_TYPE_NAME[mstGrandGraph.condType], |
| 48 | + condTargetId=mstGrandGraph.condTargetId, |
| 49 | + condNum=mstGrandGraph.condNum, |
| 50 | + removeItems=get_nice_item_amount( |
| 51 | + [ |
| 52 | + get_nice_item_from_raw(region, items_map[itemId], lang) |
| 53 | + for itemId in mstGrandGraph.removeItemIds |
| 54 | + ], |
| 55 | + mstGrandGraph.removeItemNums, |
| 56 | + ), |
| 57 | + details=[ |
| 58 | + get_nice_grand_graph_detail(detail) |
| 59 | + for detail in raw_grand_graph.mstGrandGraphDetail |
| 60 | + if detail.grandGraphId == mstGrandGraph.id |
| 61 | + ], |
| 62 | + ) |
| 63 | + |
| 64 | + |
| 65 | +async def get_all_nice_grand_graphs( |
| 66 | + conn: AsyncConnection, |
| 67 | + region: Region, |
| 68 | + mstGrandGraphs: list[MstGrandGraph], |
| 69 | + lang: Language, |
| 70 | +) -> list[NiceGrandGraph]: # pragma: no cover |
| 71 | + return [ |
| 72 | + await get_nice_grand_graph(conn, region, mstGrandGraph.id, lang) |
| 73 | + for mstGrandGraph in mstGrandGraphs |
| 74 | + ] |
0 commit comments