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, Item] = {}, banners: Dict[str, Banner] = {}, players: Dict[str, 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

Fields

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') Banner | None[source]

Adds a new banner to the gacha game

Parameters

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

Returns

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) Item | None[source]

Adds a new item to the gacha game

Parameters

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

Returns

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] = []) Player | None[source]

Adds a new player to the gacha game

Parameters

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

Returns

Optional[Player]

the Player object representing the new player or None if a player with the specified id already exists

banners: Dict[str, Banner][source]

The list of banners that are available for the gacha

create_random_banner(name: str, id: str, num_items: int, price: float = -1, key: str = '1 / R') Banner | None[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

Parameters

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

Returns

Optional[Banner]

the banner created or None if a banner with the name specified already exists

find_banner_by_id(banner_id: str) Banner | None[source]

Returns the Banner object with the given id or None if not found

Parameters

banner_idstr

the id of the banner

Returns

Optional[Banner]

the banner object with the given id or None if not found

find_banner_by_name(banner_name: str) Banner | None[source]

Returns the Banner object with the given name or None if not found DEPRICATED: consider using find_banner_by_id

Parameters

banner_namestr

the name of the banner

Returns

Optional[Banner]

the banner object with the given name or None if not found

find_item_by_id(item_id: str) Item | None[source]

Returns the Item object with the given id or None if not found

Parameters

item_idstr

the id of the item

Returns

Optional[Item]

the item object with the given id or None if not found

find_item_by_name(item_name: str) Item | None[source]

Returns the Item object with the given name or None if not found DEPRICATED: consider using find_item_by_id

Parameters

item_namestr

the name of the item

Returns

Optional[Item]

the item object with the given name or None if not found

find_player_by_id(player_id: str) Player | None[source]

Returns the Player object with the given id or None if not found

Parameters

player_idstr

the id of the player

Returns

Optional[player]

the player object with the given id or None if not found

find_player_by_name(player_name: str) Player | None[source]

Returns the Player object with the given name or None if not found DEPRICATED: consider using find_player_by_id

Parameters

player_namestr

the name of the player

Returns

Optional[player]

the player object with the given name or None if not found

items: Dict[str, Item][source]

The list of items that are in the item pool for the gacha

players: Dict[str, Player][source]

The list of players enrolled in the gacha

pull(player_id: str, banner_id: str) Item | None[source]

Pulls and returns an item from the specified banner for the specified player

Parameters

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

Returns

Optional[Item]

the item if the pull is successful or None if the player does not have enough money

Raises

PullError if player or banner are not valid

remove_all_banners() None[source]

Removes all of the banners in the game

Returns

None

remove_banner(banner_id: str) Banner | None[source]

Removes the specified banner from the gacha game

Parameters

banner_idstr

the id of the banner to remove

Returns

Optional[Banner]

the removed banner or None if banner does not exist

remove_item(item_id: str) Item | None[source]

Removes the specified item from the gacha game WARNING: Will also remove from banners and players if found, costly operation

Parameters

item_idstr

the name of the item to remove

Returns

Optional[Item]

the removed item or None if item does not exist

remove_player(player_id: str) Player | None[source]

Removes the specified player from the gacha game

Parameters

player_idstr

the id of the player to remove

Returns

Optional[Player]

the removed player or None if player does not exist

top_items(num_items: int) List[Item][source]

Returns the top specified number of items in the game sorted by rarity

Parameters

num_itemsint

the number of items to return Precondition: must be >= 1

Returns

List[Item]

the list of top items

top_players(num_players: int) List[Player][source]

Returns the top specified number of players in the game sorted by net worth

Parameters

num_playersint

the number of players to return Precondition: must be >= 1

Returns

List[Player]

the list of top players

gachapy.controller.DEFAULT_KEY = '1 / R'[source]

The default key function converting rarity to drop rate (1 / rarity)

exception gachapy.controller.PullError[source]

An exception thrown when pulling from a banner