From ecb2e9ec75035f0733e59491f9939980b1a7d203 Mon Sep 17 00:00:00 2001 From: Kevin Trocolli Date: Fri, 28 Jun 2024 23:55:23 -0400 Subject: [PATCH] mai2: properly add present items --- titles/mai2/base.py | 1 - titles/mai2/dx.py | 16 +++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/titles/mai2/base.py b/titles/mai2/base.py index 16b2039..b3c6a1d 100644 --- a/titles/mai2/base.py +++ b/titles/mai2/base.py @@ -490,7 +490,6 @@ class Mai2Base: pres_id += present['itemId'] items.append({"itemId": pres_id, "itemKind": 4, "stock": present['stock'], "isValid": True}) self.logger.info(f"Give user {data['userId']} {present['stock']}x item {present['itemId']} (kind {present['itemKind']}) as present") - await self.data.item.put_item(data["userId"], present['itemKind'], present['itemId'], present['stock'], True) return { "userId": data.get("userId", 0), "length": len(items), "userPresentList": items} diff --git a/titles/mai2/dx.py b/titles/mai2/dx.py index 3b28f30..7a067d7 100644 --- a/titles/mai2/dx.py +++ b/titles/mai2/dx.py @@ -196,10 +196,17 @@ class Mai2DX(Mai2Base): if "userItemList" in upsert and len(upsert["userItemList"]) > 0: for item in upsert["userItemList"]: + if item["itemKind"] == 4: + item_id = item["itemId"] % 1000000 + item_kind = item["itemId"] // 1000000 + else: + item_id = item["itemId"] + item_kind = item["itemKind"] + await self.data.item.put_item( user_id, - int(item["itemKind"]), - item["itemId"], + item_kind, + item_id, item["stock"], item["isValid"], ) @@ -325,8 +332,8 @@ class Mai2DX(Mai2Base): } async def handle_get_user_item_api_request(self, data: Dict) -> Dict: - kind = int(data["nextIndex"] / 10000000000) - next_idx = int(data["nextIndex"] % 10000000000) + kind = data["nextIndex"] // 10000000000 + next_idx = data["nextIndex"] % 10000000000 items: List[Dict[str, Any]] = [] if kind == 4: # presents @@ -348,7 +355,6 @@ class Mai2DX(Mai2Base): pres_id += present['itemId'] items.append({"itemId": pres_id, "itemKind": 4, "stock": present['stock'], "isValid": True}) self.logger.info(f"Give user {data['userId']} {present['stock']}x item {present['itemId']} (kind {present['itemKind']}) as present") - await self.data.item.put_item(data["userId"], present['itemKind'], present['itemId'], present['stock'], True) else: user_item_list = await self.data.item.get_items(data["userId"], kind)