forked from Dniel97/artemis
Let battle_event follow game version (#19)
Reviewed-on: Dniel97/artemis#19 Co-authored-by: Hoe <kwangaho@gmail.com> Co-committed-by: Hoe <kwangaho@gmail.com>
This commit is contained in:
parent
3ce2111f7f
commit
85e84eff67
@ -21,15 +21,21 @@ stamp:
|
||||
- "touhou_remilia_scarlet"
|
||||
- "touhou_flandre_scarlet"
|
||||
- "touhou_sakuya_izayoi"
|
||||
170:
|
||||
- "touhou_remilia_scarlet"
|
||||
- "touhou_flandre_scarlet"
|
||||
- "touhou_sakuya_izayoi"
|
||||
|
||||
timetrial:
|
||||
enable: True
|
||||
enabled_timetrial:
|
||||
150: "touhou_remilia_scarlet"
|
||||
170: "touhou_remilia_scarlet"
|
||||
|
||||
battle_event:
|
||||
enabled: True
|
||||
enabled_battle_event: "touhou_1st"
|
||||
enable: True
|
||||
enabled_battle_event:
|
||||
170: "touhou_1st"
|
||||
|
||||
round_event:
|
||||
enable: True
|
||||
|
@ -155,17 +155,24 @@ class IDACTBattleGiftConfig:
|
||||
@property
|
||||
def enable(self) -> bool:
|
||||
return CoreConfig.get_config_field(
|
||||
self.__config, "idac", "battle_gift", "enable", default=True
|
||||
self.__config, "idac", "battle_event", "enable", default=True
|
||||
)
|
||||
|
||||
@property
|
||||
def enabled_battle_gift(self) -> str:
|
||||
def enabled_battle_event(self) -> Dict:
|
||||
"""
|
||||
In the form of:
|
||||
<version as int>: <battle_event name>
|
||||
|
||||
f.e.:
|
||||
170: "touhou_1st"
|
||||
"""
|
||||
return CoreConfig.get_config_field(
|
||||
self.__config,
|
||||
"idac",
|
||||
"battle_gift",
|
||||
"enabled_battle_gift",
|
||||
default="touhou_1st",
|
||||
"battle_event",
|
||||
"enabled_battle_event",
|
||||
default={},
|
||||
)
|
||||
|
||||
class IDACRoundConfig:
|
||||
@ -205,5 +212,5 @@ class IDACConfig(dict):
|
||||
self.timerelease = IDACTimereleaseConfig(self)
|
||||
self.stamp = IDACStampConfig(self)
|
||||
self.timetrial = IDACTimetrialConfig(self)
|
||||
self.battle_gift = IDACTBattleGiftConfig(self)
|
||||
self.battle_event = IDACTBattleGiftConfig(self)
|
||||
self.round_event = IDACRoundConfig(self)
|
||||
|
@ -2,7 +2,7 @@
|
||||
"battle_gift_event_id": 2,
|
||||
"event_nm": "東方Projectコラボ",
|
||||
"start_dt": "2024-04-01",
|
||||
"end_dt": "2024-06-03",
|
||||
"end_dt": "2029-01-01",
|
||||
"mode_id": 1,
|
||||
"delivery_type": 1,
|
||||
"gift_data": [
|
||||
|
@ -83,9 +83,13 @@ class IDACSeason2(IDACBase):
|
||||
asyncio.create_task(self._load_round_event())
|
||||
|
||||
# load the user configured battle gifts (only one)
|
||||
self.battle_gift_event = None
|
||||
if self.game_config.battle_gift.enable:
|
||||
battle_gift = self.game_config.battle_gift.enabled_battle_gift
|
||||
self.battle_gift_event = {}
|
||||
self.battle_gift_event_id = {}
|
||||
if self.game_config.battle_event.enable:
|
||||
enabled_battle_event = self.game_config.battle_event.enabled_battle_event
|
||||
if isinstance(enabled_battle_event, Dict):
|
||||
for game_ver in enabled_battle_event.keys():
|
||||
battle_gift = enabled_battle_event[game_ver]
|
||||
if battle_gift is not None:
|
||||
if not os.path.exists(
|
||||
f"./titles/idac/data/battle_gift/{battle_gift}.json"
|
||||
@ -99,7 +103,12 @@ class IDACSeason2(IDACBase):
|
||||
f"./titles/idac/data/battle_gift/{battle_gift}.json",
|
||||
encoding="UTF-8",
|
||||
) as f:
|
||||
self.battle_gift_event = self._fix_dates(json.load(f))
|
||||
self.battle_gift_event[game_ver] = self._fix_dates(json.load(f))
|
||||
|
||||
# required for saving
|
||||
self.battle_gift_event_id[game_ver] = self.battle_gift_event.get(
|
||||
game_ver
|
||||
).get("battle_gift_event_id")
|
||||
|
||||
async def _load_round_event(self):
|
||||
self.round_event_id = 0
|
||||
@ -319,13 +328,14 @@ class IDACSeason2(IDACBase):
|
||||
}
|
||||
|
||||
battle_gift_event = []
|
||||
if self.battle_gift_event:
|
||||
if ver_str in self.battle_gift_event:
|
||||
battle_gift_event_data = self.battle_gift_event.get(ver_str, {})
|
||||
# check if battle gift event time is valid
|
||||
start_dt = self.battle_gift_event.get("start_dt", 0)
|
||||
end_dt = self.battle_gift_event.get("end_dt", 0)
|
||||
start_dt = battle_gift_event_data.get("start_dt", 0)
|
||||
end_dt = battle_gift_event_data.get("end_dt", 0)
|
||||
|
||||
if start_dt < int(datetime.now().timestamp()) < end_dt:
|
||||
battle_gift_event = [self.battle_gift_event]
|
||||
battle_gift_event = [battle_gift_event_data]
|
||||
|
||||
return {
|
||||
"status_code": "0",
|
||||
@ -1075,8 +1085,7 @@ class IDACSeason2(IDACBase):
|
||||
round_info.append(tmp)
|
||||
return round_info
|
||||
|
||||
def _choose_gift_id(self) -> Dict:
|
||||
gift_data = self.battle_gift_event["gift_data"]
|
||||
def _choose_gift_id(self, gift_data: Dict) -> Dict:
|
||||
# calculate the total_rate based on the first_distribution_rate
|
||||
total_rate = sum(gift["first_distribution_rate"] for gift in gift_data)
|
||||
|
||||
@ -1347,11 +1356,12 @@ class IDACSeason2(IDACBase):
|
||||
"point": timetrial["point"],
|
||||
}
|
||||
|
||||
battle_gift_data = {}
|
||||
# check if the battle gift event is active
|
||||
if self.battle_gift_event:
|
||||
if ver_str in self.battle_gift_event_id:
|
||||
# get the users battle gifts, for the current active battle gift event
|
||||
battle_gifts = await self.data.item.get_battle_gifts(
|
||||
user_id, self.battle_gift_event.get("battle_gift_event_id")
|
||||
user_id, self.battle_gift_event_id[ver_str]
|
||||
)
|
||||
|
||||
if battle_gifts:
|
||||
@ -1371,15 +1381,14 @@ class IDACSeason2(IDACBase):
|
||||
]
|
||||
else:
|
||||
# get a random gift from the active battle gift event
|
||||
gift_id = self._choose_gift_id()["gift_id"]
|
||||
gift_data = self.battle_gift_event.get(ver_str, {}).get("gift_data", {})
|
||||
gift_id = self._choose_gift_id(gift_data).get("gift_id")
|
||||
|
||||
# save the battle_gift inside the database
|
||||
await self.data.item.put_battle_gift(
|
||||
user_id,
|
||||
{
|
||||
"battle_gift_event_id": self.battle_gift_event.get(
|
||||
"battle_gift_event_id"
|
||||
),
|
||||
"battle_gift_event_id": self.battle_gift_event_id[ver_str],
|
||||
"gift_id": gift_id,
|
||||
"gift_status": 1, # aquired
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user