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

class gachapy.objects.Banner(name: str, id: str, items: List[gachapy.objects.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

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]

add_item(item: gachapy.objects.Item) bool[source]

Adds an item to the banner

itemItem

item to add to the banner

None

pull() gachapy.objects.Item[source]

Returns a random item out of a banner randomized by weight

Item

the random item from the pull

remove_item(item: gachapy.objects.Item) bool[source]

Removes the first occurence of an item from the banner

itemItem

item to remove from the banner

bool

True if item is found in banner, False if otherwise

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

namestring

name of the item

idstring

description of the item Invariant: must be unique

idint

rarity of the item where the higher the number, the higher the rarity Invariant: must be >= 1

change_rarity(rarity: float) bool[source]

Changes the rarity of the Item

rarityfloat

new rarity of the item Precondition: rarity must be >= 1

bool

True if the rarity successfully updated, false otherwise

class gachapy.objects.Player(name: str, id: str, items: List[gachapy.objects.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

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: gachapy.objects.Item) None[source]

Adds an item to the player’s inventory

itemItem

item to add to player inventory

None

change_money(amount: float) bool[source]

Adds or removes money from player

amountfloat

the amount to add or remove (positive if add, negative if remove) Precondition: if amount removed, leftover amount must be nonnegative

bool

True if the amount was able to be added or removed from account (does not create a negative money value), False otherwise

get_net_worth() float[source]

Returns the net worth of the player, calculated by the sum of the rarities of all of the items they own

float

the net worth of the player

remove_item(item: gachapy.objects.Item) bool[source]

Removes an item from the player’s inventory

itemItem

item to add to player inventory

bool

True if item is found in inventory, False if not