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