Merge pull request '[chuni] Auto stock tickets at login' (#170) from daydensteve/artemis:chuni_ticket_stock into develop

Reviewed-on: Hay1tsme/artemis#170
This commit is contained in:
Hay1tsme 2024-09-13 18:12:32 +00:00
commit 7ebd9bfb8a
4 changed files with 46 additions and 13 deletions

View File

@ -80,12 +80,14 @@ The importer for Chunithm will import: Events, Music, Charge Items and Avatar Ac
Config file is located in `config/chuni.yaml`. Config file is located in `config/chuni.yaml`.
| Option | Info | | Option | Info |
|------------------|----------------------------------------------------------------------------------------------------------------| |------------------|---------------------------------------------------------------------------------------------------------------------|
| `news_msg` | If this is set, the news at the top of the main screen will be displayed (up to Chunithm Paradise Lost) | | `news_msg` | If this is set, the news at the top of the main screen will be displayed (up to Chunithm Paradise Lost) |
| `name` | If this is set, all players that are not on a team will use this one by default. | | `name` | If this is set, all players that are not on a team will use this one by default. |
| `use_login_bonus`| This is used to enable the login bonuses | | `use_login_bonus`| This is used to enable the login bonuses |
| `crypto` | This option is used to enable the TLS Encryption | | `stock_tickets` | If this is set, specifies tickets to auto-stock at login. Format is a comma-delimited list of IDs. Defaults to None |
| `stock_count` | Ignored if stock_tickets is not specified. Number to stock of each ticket. Defaults to 99 |
| `crypto` | This option is used to enable the TLS Encryption |
If you would like to use network encryption, add the keys to the `keys` section under `crypto`, where the key If you would like to use network encryption, add the keys to the `keys` section under `crypto`, where the key

View File

@ -8,7 +8,11 @@ team:
mods: mods:
use_login_bonus: True use_login_bonus: True
# stock_tickets allows specified ticket IDs to be auto-stocked at login. Format is a comma-delimited string of ticket IDs
# note: quanity is not refreshed on "continue" after set - only on subsequent login
stock_tickets:
stock_count: 99
version: version:
11: 11:
rom: 2.00.00 rom: 2.00.00

View File

@ -24,20 +24,35 @@ class ChuniBase:
async def handle_game_login_api_request(self, data: Dict) -> Dict: async def handle_game_login_api_request(self, data: Dict) -> Dict:
""" """
Handles the login bonus logic, required for the game because Handles the login bonus and ticket stock logic, required for the game
getUserLoginBonus gets called after getUserItem and therefore the because getUserLoginBonus gets called after getUserItem; therefore the
items needs to be inserted in the database before they get requested. items needs to be inserted in the database before they get requested.
Adds a bonusCount after a user logged in after 24 hours, makes sure - Adds a stock for each specified ticket (itemKind 5)
loginBonus 30 gets looped, only show the login banner every 24 hours, - Adds a bonusCount after a user logged in after 24 hours, makes sure
adds the bonus to items (itemKind 6) loginBonus 30 gets looped, only show the login banner every 24 hours,
adds the bonus to items (itemKind 6)
""" """
user_id = data["userId"]
# If we want to make certain tickets always available, stock them now
if self.game_cfg.mods.stock_tickets:
for ticket in self.game_cfg.mods.stock_tickets.split(","):
await self.data.item.put_item(
user_id,
{
"itemId": ticket.strip(),
"itemKind": 5,
"stock": self.game_cfg.mods.stock_count,
"isValid": True,
},
)
# ignore the login bonus if disabled in config # ignore the login bonus if disabled in config
if not self.game_cfg.mods.use_login_bonus: if not self.game_cfg.mods.use_login_bonus:
return {"returnCode": 1} return {"returnCode": 1}
user_id = data["userId"]
login_bonus_presets = await self.data.static.get_login_bonus_presets(self.version) login_bonus_presets = await self.data.static.get_login_bonus_presets(self.version)
for preset in login_bonus_presets: for preset in login_bonus_presets:

View File

@ -53,6 +53,18 @@ class ChuniModsConfig:
self.__config, "chuni", "mods", "use_login_bonus", default=True self.__config, "chuni", "mods", "use_login_bonus", default=True
) )
@property
def stock_tickets(self) -> str:
return CoreConfig.get_config_field(
self.__config, "chuni", "mods", "stock_tickets", default=None
)
@property
def stock_count(self) -> int:
return CoreConfig.get_config_field(
self.__config, "chuni", "mods", "stock_count", default=99
)
class ChuniVersionConfig: class ChuniVersionConfig:
def __init__(self, parent_config: "ChuniConfig") -> None: def __init__(self, parent_config: "ChuniConfig") -> None: