gachapy.controller
The controller used for all high level management of the gacha game. Instances of this class should be created for each instance of a gacha game you would like to run. These instances can then be used to access and manage the Item, Banner, and Player objects in the game directly. Once accessed, the objects can then be modified directly using class methods (see objects.py for more info).
This object operates as the Controller of a gachapy game
Author: Jacob Kerr, 2021
- class gachapy.controller.Controller(items: Dict[str, gachapy.objects.Item] = {}, banners: Dict[str, gachapy.objects.Banner] = {}, players: Dict[str, gachapy.objects.Player] = {})[source]
A controller used to control an instance of a gacha game. Used to perform all actions needed in a game and manage game information in the form of gachapy objects
- itemsDict[str,Item]
the list of items that are in the item pool for the gacha
- bannersDict[str,Banner]
the list of banners that are available for the gacha
- playersDict[str,Player]
the list of players enrolled in the gacha
- add_new_banner(name: str, id: str, items_str: List[str], price: float, key: str = '1 / R') Optional[gachapy.objects.Banner] [source]
Adds a new banner to the gacha game
- namestr
the name of the new banner
- idstr
the id of the new banner Precondition: must be unique
- items_strList[str]
the list of the ids of the items in the banner
- pricefloat
the price of pulling from the banner
- keystr
function that takes in rarity and returns the drop rate of the item, written in KeyLang
- Optional[Banner]
the Banner object representing the new banner or None if a banner with the specified id already exists
- add_new_item(name: str, id: str, rarity: float) Optional[gachapy.objects.Item] [source]
Adds a new item to the gacha game
- namestr
the name of the new item
- idstr
the id of the new item Precondition: must be unique
- rarityfloat
rarity of the item where the higher the number, the higher the rarity Precondition: must be >= 1
- Optional[Item]
the Item object representing the new item or None if an item with the specified id already exists
- add_new_player(name: str, id: str, start_money: float, items_str: List[str] = []) Optional[gachapy.objects.Player] [source]
Adds a new player to the gacha game
- namestr
the name of the new player
- idstr
the id of the new player
- start_moneyfloat
the amount of money the new player will start with
- items_strList[str]
the list of the ids of the items the player has
- Optional[Player]
the Player object representing the new player or None if a player with the specified id already exists
- create_random_banner(name: str, id: str, num_items: int, price: float = - 1, key: str = '1 / R') Optional[gachapy.objects.Banner] [source]
- Creates a random banner with the given name and number of items
The price is automatically determined by the average of the rarities of the items selected if a price is not specified
- namestr
the name of the random banner
- idstr
the id of the random banner Precondition: must be unique
- num_itemsint
the number of items in the banner
- pricefloat
the price of the banner
- keystr
function that takes in rarity and returns the drop rate of the item, written in KeyLang
- Optional[Banner]
the banner created or None if a banner with the name specified already exists
- find_banner_by_id(banner_id: str) Optional[gachapy.objects.Banner] [source]
Returns the Banner object with the given id or None if not found
- banner_idstr
the id of the banner
- Optional[Banner]
the banner object with the given id or None if not found
- find_banner_by_name(banner_name: str) Optional[gachapy.objects.Banner] [source]
Returns the Banner object with the given name or None if not found DEPRICATED: consider using find_banner_by_id
- banner_namestr
the name of the banner
- Optional[Banner]
the banner object with the given name or None if not found
- find_item_by_id(item_id: str) Optional[gachapy.objects.Item] [source]
Returns the Item object with the given id or None if not found
- item_idstr
the id of the item
- Optional[Item]
the item object with the given id or None if not found
- find_item_by_name(item_name: str) Optional[gachapy.objects.Item] [source]
Returns the Item object with the given name or None if not found DEPRICATED: consider using find_item_by_id
- item_namestr
the name of the item
- Optional[Item]
the item object with the given name or None if not found
- find_player_by_id(player_id: str) Optional[gachapy.objects.Player] [source]
Returns the Player object with the given id or None if not found
- player_idstr
the id of the player
- Optional[player]
the player object with the given id or None if not found
- find_player_by_name(player_name: str) Optional[gachapy.objects.Player] [source]
Returns the Player object with the given name or None if not found DEPRICATED: consider using find_player_by_id
- player_namestr
the name of the player
- Optional[player]
the player object with the given name or None if not found
- pull(player_id: str, banner_id: str) Optional[gachapy.objects.Item] [source]
Pulls and returns an item from the specified banner for the specified player
- player_idstr
the id of the selected player Preconditon: must be a valid id
- banner_idstr
the id of the selected banner Preconditon: must be a valid id
- Optional[Item]
the item if the pull is successful or None if the player does not have enough money
PullError if player or banner are not valid
- remove_banner(banner_id: str) Optional[gachapy.objects.Banner] [source]
Removes the specified banner from the gacha game
- banner_idstr
the id of the banner to remove
- Optional[Banner]
the removed banner or None if banner does not exist
- remove_item(item_id: str) Optional[gachapy.objects.Item] [source]
Removes the specified item from the gacha game WARNING: Will also remove from banners and players if found, costly operation
- item_idstr
the name of the item to remove
- Optional[Item]
the removed item or None if item does not exist
- remove_player(player_id: str) Optional[gachapy.objects.Player] [source]
Removes the specified player from the gacha game
- player_idstr
the id of the player to remove
- Optional[Player]
the removed player or None if player does not exist
- top_items(num_items: int) List[gachapy.objects.Item] [source]
Returns the top specified number of items in the game sorted by rarity
- num_itemsint
the number of items to return Precondition: must be >= 1
- List[Item]
the list of top items
- top_players(num_players: int) List[gachapy.objects.Player] [source]
Returns the top specified number of players in the game sorted by net worth
- num_playersint
the number of players to return Precondition: must be >= 1
- List[Player]
the list of top players