gachapy.objects
Objects used for low level management and data storage of the gacha game. These objects store information about items, banners, and players in an easy to use format. It is recommended to use a Controller found in gachapy.controller for easy storage and access of these objects unless you know what you’re doing (i.e. threading, etc.)
These objects operate as the Model of a gachapy game
Author: Jacob Kerr, 2021
Module Contents
Classes
A representation of an item in the gacha game. |
|
A representation of a banner in the gacha game. |
|
A representation of a player in the gacha game. |
Functions
|
The function used to sort items in a list of items |
|
Returns the random weights of the items for the random function |
- class gachapy.objects.Item(name: str, id: str, rarity: float)[source]
A representation of an item in the gacha game. An item is something that players can collect and pull from banners. Each item must be unique
Fields
- namestring
the name of the item
- idstring
the id of the item Invariant: must be unique
- rarityint
rarity of the item where the higher the number, the higher the rarity Invariant: must be >= 1
- rarity: int[source]
Rarity of the item where the higher the number, the higher the rarity Invariant: must be >= 1
- class gachapy.objects.Banner(name: str, id: str, items: List[Item], price: float, key: str)[source]
A representation of a banner in the gacha game. A Banner is where players can choose to spend money in order to obtain a random item from the specific item pool presented in the Banner. Each Banner (should) contain different items and have different prices than other banners to distinguish their offerings
Fields
- namestr
name of the banner
- idstr
id of the banner Invariant: must be unique
- itemsList[Item]
the list of 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
- _weightsList[float]
list of drop weights for items Invariant: weights[i] corresponds to items[i]
- key: str[source]
Function that takes in rarity and returns the drop rate of the item, written in keylang
- _weights: List[float][source]
List of drop weights for items Invariant: weights[i” corresponds to items[i]
- add_item(item: Item) bool[source]
Adds an item to the banner
Parameters
- itemItem
item to add to the banner
Returns
None
- remove_item(item: Item) bool[source]
Removes the first occurence of an item from the banner
Parameters
- itemItem
item to remove from the banner
Returns
- bool
True if item is found in banner, False if otherwise
- class gachapy.objects.Player(name: str, id: str, items: List[Item], money: float)[source]
A representation of a player in the gacha game. A Player is someone who can use money to purchase pulls from banners, receive items from banners, and collect items. Each Player is unique and may own different items from each other
Fields
- namestr
the name of the player
- idstr
the id of the player Invariant: must be unique
- itemsList[Item]
the list of items that the player owns
- moneyfloat
the amount of money that the player owns
- add_item(item: Item) None[source]
Adds an item to the player’s inventory
Parameters
- itemItem
item to add to player inventory
Returns
None
- remove_item(item: Item) bool[source]
Removes an item from the player’s inventory
Parameters
- itemItem
item to add to player inventory
Returns
- bool
True if item is found in inventory, False if not
- change_money(amount: float) bool[source]
Adds or removes money from player
Parameters
- amountfloat
the amount to add or remove (positive if add, negative if remove) Precondition: if amount removed, leftover amount must be nonnegative
Returns
- bool
True if the amount was able to be added or removed from account (does not create a negative money value), False otherwise
- gachapy.objects._sort_item_key(item: Item) float[source]
The function used to sort items in a list of items
Parameters
- itemItem
the item to extract the key from
Returns
- float
the key of the item
- gachapy.objects._get_random_weights(items, key: str) List[float][source]
Returns the random weights of the items for the random function
Parameters
- itemsList[Item]
list of items to find weights of
- keystr
function that takes in rarity and returns the drop rate of the item, written in KeyLang
Returns
- List[float]
the list of weights of the items